@markgrafhq/markgraf-embed 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/markgraf-embed.js +14 -14
- package/package.json +1 -1
package/dist/markgraf-embed.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
`:return"\\n";case"\r":return"\\r";case" ":return"\\t";case"\v":return"\\v"}var o=r+1,i=o<t&&e[o]>="0"&&e[o]<="9"?"\\&":"";return"\\"+n.charCodeAt(0).toString(10)+i})+'"'},ko=e=>e,Re=ko("LT"),Ie=ko("GT"),Ve=ko("EQ"),k=(e,t)=>({tag:e,_1:t}),T=k("Nothing"),Kt=e=>k("Just",e),gu=e=>{if(e.tag==="Nothing")return!0;if(e.tag==="Just")return!1;c()},uc=e=>{if(e.tag==="Nothing")return!1;if(e.tag==="Just")return!0;c()},Lt=(e,t)=>({tag:e,_1:t}),sc=e=>Lt("Right",e),ac={map:e=>t=>{if(t.tag==="Left")return Lt("Left",t._1);if(t.tag==="Right")return Lt("Right",e(t._1));c()}},_u={apply:e=>t=>{if(e.tag==="Left")return Lt("Left",e._1);if(e.tag==="Right"){if(t.tag==="Left")return Lt("Left",t._1);if(t.tag==="Right")return Lt("Right",e._1(t._1))}c()},Functor0:()=>ac},cc={bind:e=>{if(e.tag==="Left"){const t=e._1;return n=>Lt("Left",t)}if(e.tag==="Right"){const t=e._1;return n=>n(t)}c()},Apply0:()=>_u},fc={pure:sc,Apply0:()=>_u},gc={Applicative0:()=>fc,Bind1:()=>cc},he=e=>t=>e,$=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}},_c={map:$},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}}},dc=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())},zt={foldr:jn,foldl:y,foldMap:e=>{const t=e.mempty;return n=>zt.foldr(r=>o=>e.Semigroup0().append(n(r))(o))(t)}},lu=isFinite;function lc(e,t,n,r){var o=parseFloat(e);return t(o)?n(o):r}const hu=Math.abs,hc=Math.ceil,bo=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,pc=function(e){return function(t){return function(n){return(n|0)===n?e(n):t}}},_t=function(e){return e},mc=(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=pc(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;c()},Ut=function(e){return function(t){return e+t|0}},er=function(e){return function(t){return e+t}},Po=function(e){return function(t){if(t===0)return 0;var n=Math.abs(t);return(e%n+n)%n}},yc=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)}},Jc={append:yc},Nc={mempty:"",Semigroup0:()=>Jc};function xc(e,t,n){return e==null?t:n(e)}var Go=function(e){return function(t){return e===t}};const vc=Go,Tc=Go,Do=Go,wc=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}}},Ye={eq:Do},Lc={eq:Tc},Wo={eq:vc};var Mo=function(e){return function(t){return function(n){return function(r){return function(o){return r<o?e:r===o?t:n}}}}};const Ec=Mo,kc=Mo,E={compare:Mo(Re)(Ve)(Ie),Eq0:()=>Ye},ht={compare:kc(Re)(Ve)(Ie),Eq0:()=>Lc},it={compare:Ec(Re)(Ve)(Ie),Eq0:()=>Wo};function Ro(e){return function(t){return function(n){return e.apply(n,[t])}}}const bc=Ro(Number.prototype.toPrecision),Cc=Ro(Number.prototype.toFixed),Sc=Ro(Number.prototype.toExponential),Io=(e,t)=>({tag:e,_1:t}),zo=e=>t=>n=>{const r=it.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),i=it.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;c()},Bo=e=>{if(e.tag==="Precision")return bc(e._1);if(e.tag==="Fixed")return Cc(e._1);if(e.tag==="Exponential")return Sc(e._1);c()},Nu=function(e){return function(){console.log(e)}},x=(e,t)=>({tag:"Tuple",_1:e,_2:t}),Sn=e=>t=>x(e,t),Ao=e=>e._2,Dr=e=>e._1;function Pc(){return Date.now()}function Gc(e){return function(){return e.getContext("2d")}}function Dc(e){return function(){return e.width}}function Wc(e){return function(){return e.height}}function Mc(e){return function(t){return function(){e.width=t}}}function Rc(e){return function(t){return function(){e.height=t}}}function Qo(e){return function(t){return function(){e.lineWidth=t}}}function Ic(e){return function(t){return function(){e.fillStyle=t}}}function zc(e){return function(t){return function(){e.strokeStyle=t}}}function qo(e){return function(t){return function(){e.lineCap=t}}}function Ho(e){return function(t){return function(){e.lineJoin=t}}}function Bc(e){return function(t){return function(){e.globalCompositeOperation=t}}}function Ac(e){return function(t){return function(){e.globalAlpha=t}}}function xu(e){return function(){e.beginPath()}}function Vo(e){return function(){e.stroke()}}function Yo(e){return function(){e.fill()}}function Qc(e){return function(){e.clip()}}function qc(e){return function(t){return function(n){return function(){e.lineTo(t,n)}}}}function Hc(e){return function(t){return function(n){return function(){e.moveTo(t,n)}}}}function Vc(e){return function(){e.closePath()}}function Yc(e){return function(t){return function(){e.fillRect(t.x,t.y,t.width,t.height)}}}function Fc(e){return function(t){return function(){e.clearRect(t.x,t.y,t.width,t.height)}}}function Fo(e){return function(t){return function(){e.scale(t.scaleX,t.scaleY)}}}function vu(e){return function(t){return function(){e.translate(t.translateX,t.translateY)}}}function $c(e){return function(t){return function(){e.textAlign=t}}}function Oc(e){return function(t){return function(){e.textBaseline=t}}}function Xc(e){return function(t){return function(){e.font=t}}}function Uc(e){return function(t){return function(n){return function(r){return function(){e.fillText(t,n,r)}}}}}function nr(e){return function(){e.save()}}function rr(e){return function(){e.restore()}}function Kc(e){return function(t){return function(){e.quadraticCurveTo(t.cpx,t.cpy,t.x,t.y)}}}function Zc(e){return function(t){return function(){e.bezierCurveTo(t.cp1x,t.cp1y,t.cp2x,t.cp2y,t.x,t.y)}}}const Tu=e=>e,$o=e=>e,Oo=e=>e,Xo=e=>e,Wr=e=>e,jc=Wr("BaselineTop"),tf=Wr("BaselineMiddle"),ef=Wr("BaselineAlphabetic"),nf=Wr("BaselineBottom"),rf=Xo("AlignLeft"),of=Xo("AlignRight"),uf=Xo("AlignCenter"),Uo=Oo("BevelJoin"),Mr=Oo("RoundJoin"),Ko=Oo("MiterJoin"),Zo=$o("Round"),jo=$o("Square"),ti=$o("Butt"),sf=Tu("SourceOver"),af=Tu("Difference"),cf=e=>t=>Oc(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()})()),ff=e=>t=>$c(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()})()),Rr=e=>t=>{if(t==="BevelJoin")return Ho(e)("bevel");if(t==="RoundJoin")return Ho(e)("round");if(t==="MiterJoin")return Ho(e)("miter");c()},ei=e=>t=>{if(t==="Round")return qo(e)("round");if(t==="Square")return qo(e)("square");if(t==="Butt")return qo(e)("butt");c()},wu=e=>t=>Bc(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()})()),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,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}},gf=e=>e,_f={map:e=>t=>e(t)},Lu={apply:e=>t=>e(t),Functor0:()=>_f},df={bind:e=>t=>t(e),Apply0:()=>Lu},lf={pure:gf,Apply0:()=>Lu},rn={Applicative0:()=>lf,Bind1:()=>df},hf=function(e){return function(){return e}},pf={apply:e=>t=>()=>{const n=e(),r=t();return Eu.pure(n(r))()},Functor0:()=>mf},Eu={pure:hf,Apply0:()=>pf},mf={map:e=>t=>()=>{const n=t();return e(n)}},or=(e,t)=>({tag:e,_1:t}),ku=e=>or("Loop",e),yf={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}c()}return i};return n=>t(e(n))},Monad0:()=>rn},Jf=(function(e){return function(t){return function(n){return function(){return e(t,n)}}}})(function(e,t){return t.push(e)}),Nf=(e,t)=>({tag:"Iterator",_1:e,_2:t}),xf=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}},vf=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}c()}},Dt=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}},bu=function(e){return e},Tf=(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 f(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)(f(g,l)))(f(l,d))}}return f(0,a.length)}}}}}})(),wf=e=>e,Ir={traverse:e=>{const t=e.Apply0();return Tf(t.apply)(t.Functor0().map)(e.pure)},sequence:e=>Ir.traverse(e)(wf),Functor0:()=>_c,Foldable1:()=>zt},Ht=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 Lf=function(e,t){if(e<1)return[];var n=new Array(e);return n.fill(t)},Ef=function(e,t){for(var n=[],r=0,o=0;o<e;o++)n[r++]=t;return n};const kf=typeof Array.prototype.fill=="function"?Lf:Ef,wt=(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))}})(),Vt=function(e,t,n){return n.length===0?e({}):t(n[0])(n.slice(1))},bf=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},ir=function(e,t,n,r){for(var o=0,i=r.length;o<i;o++)if(n(r[o]))return e(o);return t},Cf=function(e,t,n,r){for(var o=r.length-1;o>=0;o--)if(n(r[o]))return e(o);return t},Sf=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)},Cu=function(e,t,n,r){if(n<0||n>=r.length)return t;var o=r.slice();return o.splice(n,1),e(o)},ur=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},ct=function(e,t){return t.filter(e)},Pf=(function(){function e(t,n,r,o,i,u){var s,a,f,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,f=s,g=i;a<s&&f<u;)d=o[a],l=o[f],_=n(t(d)(l)),_>0?(r[g++]=l,++f):(r[g++]=d,++a);for(;a<s;)r[g++]=o[a++];for(;f<u;)r[g++]=o[f++]}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)}})(),Wt=function(e,t,n){return n.slice(e,t)},pe=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},Su=function(e,t){for(var n=t.length,r=0;r<n;r++)if(!e(t[r]))return!1;return!0},xt=e=>t=>Pf(e,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;c()},t),Gf=e=>t=>xt(n=>r=>e.compare(t(n))(t(r))),me=e=>t=>(()=>{const n=Jf(t);return()=>{const r=[...e];return n(r)(),r}})()(),Df=e=>{if(e.length===0)return e.length-1|0,T;const t=e.length-1|0;return t>=0&&t<e.length?k("Just",{init:Wt(0,e.length-1|0,e),last:e[t]}):T},Wf=e=>t=>n=>e>=0&&e<n.length?ur(Kt,T,e,t(n[e]),n):T,_n=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=k("Just",s);continue}i=!1,u=T}return u})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:t}:{init:Wt(0,n._1,t),rest:Wt(n._1,t.length,t)};if(n.tag==="Nothing")return{init:t,rest:[]};c()},Pn=e=>t=>{const n=xt(r=>o=>e(r._2)(o._2))(Dt(Sn)(t));return 0<n.length?$(Ao)(Gf(it)(Dr)((()=>{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;c()})())(o._2);(i==="LT"||i==="GT"||i!=="EQ")&&r.push(o)}return r})())):[]},Mf=e=>t=>{const n=[],r=Nf(o=>o>=0&&o<t.length?k("Just",t[o]):T,{value:0});return vf(r)(o=>()=>{const i=[];i.push(o),xf(e(o))(r)(i)(),n.push(i)})(),n},fe=e=>t=>{const n=ir(Kt,T,e,t);return n.tag==="Just"?k("Just",t[n._1]):T},Rf=e=>t=>ct(e,t),ze=e=>t=>n=>{const r=ir(Kt,T,o=>e.eq(o)(t),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;c()},Pu=e=>t=>St(t)(e),bt=e=>Pu(t=>{const n=e(t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];c()}),It=(e,t,n)=>({tag:e,_1:t,_2:n}),Bt=It("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,f;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,f=g;continue}if(d.tag==="Cons"){u=It("Cons",d._1,g),s=d._2;continue}c()}return f})(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}c()}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)}},If=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 f=r(a);if(e(f))return u;s=t(f)}}}}}}},zf=e=>{if(e.tag==="Just")return e._1;c()},Bf={unfoldr1:If(gu)(zf)(Dr)(Ao)},Af=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 f=t(a);u.push(n(f)),s=r(f)}}}}}}},Qf=e=>{if(e.tag==="Just")return e._1;c()},Pe={unfoldr:Af(gu)(Qf)(Dr)(Ao),Unfoldable10:()=>Bf},$t=(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}),zr=(e,t,n)=>({tag:"Split",_1:e,_2:t,_3:n}),Gu=(e,t,n)=>({tag:"SplitLast",_1:e,_2:t,_3:n}),q=$t("Leaf"),dn=Ge("IterLeaf"),Zt=(e,t,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return $t("Node",1,1,e,t,n,r);if(r.tag==="Node")return $t("Node",1+r._1|0,1+r._2|0,e,t,n,r);c()}if(n.tag==="Node"){if(r.tag==="Leaf")return $t("Node",1+n._1|0,1+n._2|0,e,t,n,r);if(r.tag==="Node")return $t("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,e,t,n,r)}c()},ge=(e,t,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?$t("Node",1,1,e,t,q,q):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()})()?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;c()})()?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;c()})()?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;c()})()?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);c()},Gn=(e,t,n)=>{if(n.tag==="Leaf")return zr(T,q,q);if(n.tag==="Node"){const r=e(t)(n._3);if(r==="LT"){const o=Gn(e,t,n._5);return zr(o._1,o._2,ge(n._3,n._4,o._3,n._6))}if(r==="GT"){const o=Gn(e,t,n._6);return zr(o._1,ge(n._3,n._4,n._5,o._2),o._3)}if(r==="EQ")return zr(k("Just",n._4),n._5,n._6)}c()},Du=(e,t,n,r)=>{if(r.tag==="Leaf")return Gu(e,t,n);if(r.tag==="Node"){const o=Du(r._3,r._4,r._5,r._6);return Gu(o._1,o._2,ge(e,t,n,o._3))}c()},Dn=(e,t)=>{if(e.tag==="Leaf")return t;if(e.tag==="Node"){const n=Du(e._3,e._4,e._5,e._6);return ge(n._1,n._2,n._3,t)}c()},Fe=(e,t,n)=>{if(t.tag==="Leaf")return q;if(n.tag==="Leaf")return t;if(n.tag==="Node"){const r=Gn(e,n._3,t);return Dn(Fe(e,r._2,n._5),Fe(e,r._3,n._6))}c()},Br=(e,t,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return q;if(r.tag==="Node"){const o=Gn(e,r._3,n),i=Br(e,t,o._2,r._5),u=Br(e,t,o._3,r._6);if(o._1.tag==="Just")return ge(r._3,t(o._1._1)(r._4),i,u);if(o._1.tag==="Nothing")return Dn(i,u)}c()},ye=(e,t,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const o=Gn(e,r._3,n),i=ye(e,t,o._2,r._5),u=ye(e,t,o._3,r._6);if(o._1.tag==="Just")return ge(r._3,t(o._1._1)(r._4),i,u);if(o._1.tag==="Nothing")return ge(r._3,r._4,i,u)}c()},qf=e=>t=>n=>{const r=o=>{if(o.tag==="Leaf")return q;if(o.tag==="Node"){const i=e.compare(n)(o._3);if(i==="LT")return ge(o._3,o._4,r(o._5),o._6);if(i==="GT")return ge(o._3,o._4,o._5,r(o._6));if(i==="EQ"){const u=t(o._4);if(u.tag==="Nothing")return Dn(o._5,o._6);if(u.tag==="Just")return $t("Node",o._1,o._2,o._3,u._1,o._5,o._6)}}c()};return r},Hf=e=>t=>{const n=r=>{if(r.tag==="Leaf")return q;if(r.tag==="Node"){const o=t(r._3)(r._4);if(o.tag==="Just")return ge(r._3,o._1,n(r._5),n(r._6));if(o.tag==="Nothing")return Dn(n(r._5),n(r._6))}c()};return n},ln=(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 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=Ge("IterEmit",h._3,h._4,_),g=h._5;continue}f=Ge("IterEmit",h._3,h._4,Ge("IterNode",h._6,_)),g=h._5;continue}c()}return l})(u._2)(u._1);continue}c()}return i})((e,t,n)=>k("Just",x(x(e,t),n)))(e=>T),vt=e=>t=>n=>r=>{const o=i=>{if(i.tag==="Leaf")return $t("Node",1,1,n,r,q,q);if(i.tag==="Node"){const u=e.compare(n)(i._3);if(u==="LT")return ge(i._3,i._4,o(i._5),i._6);if(u==="GT")return ge(i._3,i._4,i._5,o(i._6));if(u==="EQ")return $t("Node",i._1,i._2,n,t(i._4)(r),i._5,i._6)}c()};return o},Z=e=>t=>n=>{const r=o=>{if(o.tag==="Leaf")return $t("Node",1,1,t,n,q,q);if(o.tag==="Node"){const i=e.compare(t)(o._3);if(i==="LT")return ge(o._3,o._4,r(o._5),o._6);if(i==="GT")return ge(o._3,o._4,o._5,r(o._6));if(i==="EQ")return $t("Node",o._1,o._2,t,n,o._5,o._6)}c()};return r},jt=e=>t=>t.foldl(n=>r=>Z(e)(r._1)(r._2)(n))(q),sr=e=>t=>{const n=r=>{if(r.tag==="Leaf")return q;if(r.tag==="Node"){const o=e.compare(t)(r._3);if(o==="LT")return ge(r._3,r._4,n(r._5),r._6);if(o==="GT")return ge(r._3,r._4,r._5,n(r._6));if(o==="EQ")return Dn(r._5,r._6)}c()};return n},Vf=e=>{const t=e.compare;return n=>r=>o=>{const i=Gn(t,r,o),u=n(i._1);if(u.tag==="Nothing")return Dn(i._2,i._3);if(u.tag==="Just")return ge(r,u._1,i._2,i._3);c()}},we={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,It("Cons",i._3,o(i._6,u)));c()};return o(r,Bt)})())}},Ar=e=>e,Yf=e=>e,Ff=Ar("Linear"),$f=Ar("EaseInOutQuad"),Of=Ar("EaseOutExpo"),Xf=Ar("SpringBouncy"),ar=e=>t=>n=>{const r=Cn(1-t*t),o=e*r;return 1-pu(-t*e*n)*(bo(o*n)+t/r*So(o*n))},Uf=e=>{const t=ht.compare(0)(e),n=(()=>{if(t==="LT")return e;if(t==="EQ"||t==="GT")return 0;c()})(),r=ht.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;c()},ni=e=>t=>(()=>{if(e==="Linear")return Yf;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);c()})()(Uf(t)),Wu=y(er)(0),Kf=e=>t=>n=>{const r=ht.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),i=ht.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;c()},Mu=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Ru=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Iu=e=>t=>{const n=pe(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,f=s.x-u.x;return Cn(f*f+a*a)})()}),e,Wt(1,e.length,e)),r=Wu($(u=>u.len)(n)),o=Kf(0)(r)(t*r),i=u=>s=>a=>{let f=u,g=s,d=a,l=!0,_;for(;l;){const h=f,p=g,m=d,J=Vt(N=>T,N=>v=>k("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,_=m;continue}if(J.tag==="Just"){if(p<=J._1.head.len){const N=J._1.head.len<=0?0:p/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}f=J._1.tail,g=p-J._1.head.len,d=m;continue}c()}return _};return 0<e.length?k("Just",i(n)(o)(e[0])):T},ri=e=>Wu(pe(t=>n=>{const r=n.y-t.y,o=n.x-t.x;return Cn(o*o+r*r)},e,Wt(1,e.length,e))),un=e=>{const t=Vt(n=>T,n=>r=>k("Just",{head:n,tail:r}),[...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._4,n(r._6,o)));c()};return St(wt(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,It("Cons",r._4,n(r._6,o)));c()};return wt(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,It("Cons",r._4,n(r._6,o)));c()};return wt(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:Mu(r.minX)(o.x),minY:Mu(r.minY)(o.y),maxX:Ru(r.maxX)(o.x),maxY:Ru(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}}c()},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.")}},Wn=function(e){return e.join("")},zu=function(e){return e.split("")},oi=function(e){return e},hn=function(e){return e.length},Bu=function(e){return function(t){return t.substr(0,e)}},fr=function(e){return function(t){return t.substring(e)}},Zf=function(e){return function(t){return{before:t.substring(0,e),after:t.substring(e)}}},jf=e=>t=>{const n=Zf(hn(e))(t);return n.before===e?k("Just",n.after):T},tg=e=>t=>n=>{try{var r=BigInt(n);return e(r)}catch{return t}},eg=e=>t=>n=>{try{var r=BigInt(n);return e(r)}catch{return t}},pn=e=>BigInt(e),ng=e=>Number(e),Qr=e=>t=>e+t,qr=e=>t=>e*t,ii=e=>t=>e-t,Au=0n,Hr=1n,Qu=e=>t=>e^t,gr=e=>t=>e&t,ui=e=>t=>e<<t,si=e=>t=>e>>t,rg=e=>t=>e==t,og=e=>t=>e===t?0:e>t?1:-1,ig={eq:rg},qu={compare:e=>t=>{const n=og(e)(t);return n===1?Ie:n===0?Ve:Re},Eq0:()=>ig},ug=tg(Kt)(T),sg=eg(Kt)(T),ag=e=>t=>hu(e._1-t._1)+hu(e._2-t._2),Vr=e=>e,ue=Vr("North"),se=Vr("South"),mn=Vr("East"),yn=Vr("West"),Hu=e=>e,Vu=(e,t)=>({tag:e,_1:t}),Yu=(e,t)=>({tag:e,_1:t}),ai=(e,t)=>({tag:e,_1:t}),cg=ai("First"),fg=Hu("Forward"),gg=Hu("Backward"),_g=jt(E)(zt),dg=e=>jn(t=>n=>({nodes:ye(E.compare,he,t.nodes,n.nodes),edges:ye(E.compare,he,t.edges,n.edges)}))({nodes:q,edges:q})(e.keyframes),lg=e=>t=>({entering:{nodes:Fe(E.compare,t.nodes,e.nodes),edges:Fe(E.compare,t.edges,e.edges)},leaving:{nodes:Fe(E.compare,e.nodes,t.nodes),edges:Fe(E.compare,e.edges,t.edges)},surviving:{nodes:Br(E.compare,he,e.nodes,t.nodes),edges:Br(E.compare,he,e.edges,t.edges)}}),Fu=e=>e,ci=e=>t=>n=>{const r=ht.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),i=ht.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;c()},Jn=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Mn=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}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=E.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}}c()}return o},hg=y(e=>t=>Z(E)(t)()(e))(q),pg=y(e=>t=>Z(E)(t)()(e))(q),mg=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),$u=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Ou=jt(E)(zt),yg=Fu("Hold"),Jg=Fu("Gap"),Ng=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))},xg=y(e=>t=>{const n=e.length-1|0;return n>=0&&n<e.length&&e[n]===t?e:me(e)(t)})([]),gi=e=>{const t=Vt(n=>T,n=>r=>k("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:Mn(r.minX)(o.x),minY:Mn(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}}c()},Xu=e=>{const t=Vt(n=>T,n=>r=>k("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return T;if(t.tag==="Just")return k("Just",gi(e));c()},vg=e=>t=>n=>hg(St(wt(we.foldr,n))(r=>{const o=Rn(r)(e);if(o.tag==="Just")return ct(i=>!fi(i)(t),[o._1.source,o._1.target]);if(o.tag==="Nothing")return[];c()})),Tg=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}},wg=e=>t=>n=>r=>{const o=(u,s)=>Mn(Ng(e)(u.toCam)(s.toCam))(u.endT-u.startT),i=y(u=>s=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:k("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})()})()})()||o(u.pending._1,s)<=0?{acc:me(u.acc)(u.pending._1),pending:k("Just",s)}:{acc:me(me(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:k("Just",s)};c()})({acc:[],pending:T})(r);if(i.pending.tag==="Nothing")return i.acc;if(i.pending.tag==="Just")return me(i.acc)(i.pending._1);c()},Lg=e=>e.kind.tag==="SendToken"?k("Just",x(e.kind._1.edge,{source:e.kind._1.from,target:e.kind._1.to})):T,Eg=e=>e.tag==="DataFlow"?bt(Lg)(e._1.events):[],kg=e=>t=>pg(bt(n=>fi(n._2.source)(t)||fi(n._2.target)(t)?k("Just",n._1):T)(mg(e))),bg=e=>t=>{const n=r=>{const o=Cf(Kt,T,i=>i.kind==="Hold",r<1?[]:Wt(0,r,t));if(o.tag==="Just")return o._1>=0&&o._1<t.length?k("Just",t[o._1].cam):T;if(o.tag==="Nothing")return T;c()};return Dt(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;c()})(),toCam:(()=>{const i=n(r),u=(()=>{if(i.tag==="Nothing")return e;if(i.tag==="Just")return i._1;c()})(),s=r+1|0,a=ir(Kt,T,f=>f.kind==="Hold",s<1?t:Wt(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)},Uu={padding:24,easing:Of,minZoom:.5,maxZoom:2.5,panSpeed:700,zoomSpeed:1.5,minTransition:.3,maxTransition:1.4},Cg=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:Mn(i.w/r)(i.h/o)},_i=e=>{const t=Vt(n=>T,n=>r=>k("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:Mn(r.minX)(o.x),minY:Mn(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}}c()},Ku=e=>t=>n=>{if(n.tag==="Leaf")return un(e);const r=kg(t)(n),o=[...bt(i=>{const u=$u(i)(e.nodes);return u.tag==="Just"?k("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):T})(wt(we.foldr,ye(E.compare,he,n,vg(t)(n)(r)))),...bt(i=>{const u=Rn(i)(e.edges);return u.tag==="Just"?k("Just",gi(u._1)):T})(wt(we.foldr,r)),...bt(i=>{const u=Rn(i)(e.chipExtras);if(u.tag==="Just")return Xu(u._1);if(u.tag==="Nothing")return T;c()})(wt(we.foldr,r))];return o.length===0?un(e):_i(o)},Sg=e=>t=>n=>r=>{const o=[...bt(i=>i)([(()=>{const i=Rn(n)(e.edges);return i.tag==="Just"?k("Just",gi(i._1)):T})(),(()=>{const i=Rn(n)(e.chipExtras);if(i.tag==="Just")return Xu(i._1);if(i.tag==="Nothing")return T;c()})()]),...(()=>{const i=Rn(n)(t);if(i.tag==="Just")return bt(u=>{const s=$u(u)(e.nodes);return s.tag==="Just"?k("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[];c()})()];return o.length===0?Ku(e)(t)(r):_i(o)},Pg=y(e=>t=>{const n=e.length-1|0,r=n>=0&&n<e.length?k("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})()})()})()?me((()=>{const o=e.length-1|0;return o<1?[]:Wt(0,o,e)})())({...r._1,endT:t.endT}):me(e)(t)})([]),Zu=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}},Gg=e=>ye(E.compare,he,Ou($(t=>x(t.id,{source:t.from.node,target:t.to.node}))(e.graph.edges)),Ou(St(e.scenes)(Eg))),di=e=>t=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:ci(e.minZoom)(e.maxZoom)(Cg(t)(n)(e.padding))}),Dg=e=>t=>n=>r=>{const o=di(e)(t)(un(t)),i=ct(u=>u>=0&&u<=n,xg(xt(ht.compare)([0,n,...St(r)(u=>[u.startT,u.endT])])));return wg(e)(t)(o)(Pg(bg(o)(bt(u=>{const s=(u._1+u._2)/2;if(u._2<=u._1)return T;const a=bt(f=>f.startT<=s&&s<f.endT?k("Just",f.bbox):T)(r);return a.length===0?k("Just",{kind:Jg,startT:u._1,endT:u._2,cam:o}):k("Just",{kind:yg,startT:u._1,endT:u._2,cam:di(e)(t)(_i(a))})})(pe(Sn,i,Wt(1,i.length,i))))))},Wg=e=>t=>n=>r=>{const o=fe(i=>r>=i.startT&&r<i.endT)(n);if(o.tag==="Just")return Tg(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}c()};function _r(e){return e.charCodeAt(0)}function ju(e){return String.fromCharCode(e)}const Yr=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)}},Mg=function(e){return e.trim()},Rg=function(e){return function(t){return t.join(e)}};var Ig=typeof Array.from=="function",zg=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",Bg=typeof String.prototype.fromCodePoint=="function",Ag=typeof String.prototype.codePointAt=="function";const Qg=function(e){return Ag?function(t){return t.codePointAt(0)}:e},qg=function(e){return Bg?String.fromCodePoint:e},Hg=function(e){return function(t){return zg?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)}},Vg=function(e){return function(t){return Ig?function(n){return Array.from(n,t)}:e}},Fr=e=>{const t=hn(e);if(t===0)return T;if(t===1)return k("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?k("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:fr(2)(e)}):k("Just",{head:r,tail:fr(1)(e)})},Yg=e=>{const t=Fr(e);return t.tag==="Just"?k("Just",x(t._1.head,t._1.tail)):T},Fg=e=>Pe.unfoldr(Yg)(e),ts=Qg(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=Vg(Fg)(ts),pi=e=>oi(e>=0&&e<=65535?ju(e):e<0?"\0":"\uFFFF"),$g=qg(e=>e<=65535?pi(e):pi(bn(e-65536|0,1024)+55296|0)+pi(Po(e-65536|0)(1024)+56320|0)),es=e=>t=>{if(e<1)return"";const n=Fr(t);return n.tag==="Just"?$g(n._1.head)+es(e-1|0)(n._1.tail):t},oe=Hg(es),Og=e=>t=>t===""?T:k("Just",ts(t)),$r=(e,t,n)=>({tag:e,_1:t,_2:n}),Xg=()=>({tag:"ExtendFromSource"}),Or=(e,t)=>({tag:e,_1:t}),mi=e=>e,Xr=(e,t)=>({tag:e,_1:t}),yi=Xr("NotYet"),ns=Xr("Consumed"),Ug=mi("FromSource"),rs=mi("FromTarget"),Kg=mi("FromBoth"),os=Or("Hidden"),Zg=Or("Visible"),is=Xg(),us=$r("Retracted"),jg=$r("Extended"),Ji=(e,t)=>({tag:e,_1:t}),In=(e,t,n)=>({tag:e,_1:t,_2:n}),ss=e=>e,Nn=(e,t)=>({tag:e,_1:t}),zn=(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}),as=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Ur=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},sn=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},cs=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},fs=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=E.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}}c()}return o},Bn=(()=>{const e=Pe.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return k("Just",x(t._1,t._2));c()});return t=>e((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._3,n(r._6,o)));c()};return n(t,Bt)})())})(),t_=y(e=>t=>Z(E)(t)()(e))(q),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=E.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}}c()}return o},e_=jt(E)(zt),n_=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}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=E.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}}c()}return o},r_=Nn("NoKeyframes"),o_=e=>Nn("DuplicateEventId",e),i_=e=>Nn("UnknownEvent",e),gs=ss("PlopIn"),u_=ss("PlopOut"),s_=e=>t=>bt(n=>{if(n.target.tag==="NodeWindow"||n.target.tag==="EdgeWindow")return T;if(n.target.tag==="TokenWindow")return k("Just",{startT:n.startT,endT:n.endT,bbox:Sg(e)(t)(n.target._2)(q)});if(n.target.tag==="FillWindow")return k("Just",{startT:n.startT,endT:n.endT,bbox:Ku(e)(t)($t("Node",1,1,n.target._2,void 0,q,q))});c()}),a_=e=>t=>n=>r=>o=>{const i=_t(y(f=>g=>f+hi(g).length|0)(0)(n.labels))*e.tokenReadSecPerChar,u=f=>{const g=as(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=Ur(n.edge)(t.edges),a=(()=>{if(s.tag==="Just"){const f=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return _e(s._1);c()})(),g=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return _e(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)})()+ri(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:sn(e.minTokenDuration)(sn(a)(i)/sn(.05)(1-r-o))},c_=e=>{if(e.event.kind.tag==="SendToken")return k("Just",{startT:e.startT,endT:e.endT,target:zn("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 k("Just",{startT:e.startT,endT:e.endT,target:zn("FillWindow",e.event.id,e.event.kind._1.node,e.event.kind._1.labels)});c()},f_=e=>t=>n=>bt(r=>{const o=bt(i=>as(i)(e.nodes))(wt(we.foldr,(()=>{if(r.scene.tag==="Structural")return ye(E.compare,he,(()=>{const i=dr(r.scene._1.from)(n);if(i.tag==="Nothing")return q;if(i.tag==="Just")return i._1.nodes;c()})(),(()=>{const i=dr(r.scene._1.to)(n);if(i.tag==="Nothing")return q;if(i.tag==="Just")return i._1.nodes;c()})());if(r.scene.tag==="DataFlow"){const i=dr(r.scene._1.keyframe)(n);if(i.tag==="Nothing")return q;if(i.tag==="Just")return i._1.nodes}c()})()));return o.length===0?T:k("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const i=y(u=>s=>({minX:cs(u.minX)(s.x),minY:cs(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})(Wt(1,o.length,o));return{x:i.minX,y:i.minY,w:i.maxX-i.minX,h:i.maxY-i.minY}})()})}),g_=e=>t=>n=>{const r=Ur(n)(e);if(r.tag==="Nothing")return rs;if(r.tag==="Just"){const o=fs(r._1.target)(t);return fs(r._1.source)(t)?o?Kg:Ug:rs}c()},__=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=fe(s=>s.event.id===i)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.endT;c()}if(r.event.when.tag==="With"){const i=r.event.when._1,u=fe(s=>s.event.id===i)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.startT}c()})();return me(n)({startT:o,endT:(()=>{if(r.event.kind.tag==="SendToken")return o+a_(e)(t)(r.event.kind._1)(r.holdPre)(r.holdPost);if(r.event.kind.tag==="FillNodeWithoutTransition")return o+e.plop;c()})(),event:r.event,holdPre:r.holdPre,holdPost:r.holdPost})},vi=e=>t=>{if(t<0)return In("AtKeyframe",e.initialKeyframe);if(t>=e.totalDuration){const r=e.spans.length-1|0;return r>=0&&r<e.spans.length?In("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()})()):In("AtKeyframe",e.initialKeyframe)}const n=fe(r=>t>=r.startT&&t<r.endT)(e.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return In("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return In("AtKeyframe",n._1.scene._1.keyframe);c()}if(n.tag==="Nothing")return In("AtKeyframe",e.initialKeyframe);c()},d_=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()},_s={id:"",nodes:q,edges:q},l_=e=>t=>lg((()=>{const n=dr(t.from)(e);if(n.tag==="Nothing")return _s;if(n.tag==="Just")return n._1;c()})())((()=>{const n=dr(t.to)(e);if(n.tag==="Nothing")return _s;if(n.tag==="Just")return n._1;c()})()),Ti=e=>t=>n=>r=>{const o=Ur(r)(n.edges);if(o.tag==="Just")return e<=0?t:sn(t)(ri(o._1)/e);if(o.tag==="Nothing")return t;c()},ds=e=>t=>n=>r=>o=>{const i=e.plop,u=l_(n)(o),s=$(_=>({startT:0,endT:0+Ti(e.edgeSpeed)(e.minEdgeDuration)(t)(_),target:zn("EdgeWindow",_,Ji("Extend",is))}))(Bn(u.entering.edges)),a=$(_=>({startT:0,endT:i,target:zn("NodeWindow",_,gs)}))(Bn(u.entering.nodes)),f=y(sn)(0)($(_=>Ti(e.edgeSpeed)(e.minEdgeDuration)(t)(_))(Bn(u.leaving.edges))),g=_=>on(h=>{const p=Ur(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;c()},Bn(u.leaving.edges))?f:0,d=$(_=>({startT:g(_),endT:g(_)+e.plop,target:zn("NodeWindow",_,u_)}))(Bn(u.leaving.nodes)),l=$(_=>({startT:0,endT:Ti(e.edgeSpeed)(e.minEdgeDuration)(t)(_),target:zn("EdgeWindow",_,Ji("Retract",g_(r)(u.leaving.nodes)(_)))}))(Bn(u.leaving.edges));return{duration:(()=>{const _=xt(ht.compare)([...$(p=>p.endT)(l),...$(p=>p.endT)(d),...$(p=>p.endT)(a),...$(p=>p.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+e.gap:e.gap})(),windows:[...l,...d,...a,...s]}},h_=e=>t=>n=>r=>o=>i=>$((()=>{const u=o.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())(ds(e)(t)(n)(r)(i).windows),p_=e=>bt(t=>wt(jn,t).length>1?k("Just",(()=>{const n=Vt(r=>T,r=>o=>k("Just",{head:r,tail:o}),wt(jn,t));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";c()})()):T)(Mf(Do)(xt(E.compare)(e))),m_=e=>{const t=$(r=>r.id)(e),n=t_(t);return[...$(o_)(p_(t)),...$(i_)(ct(r=>!Ni(r)(n),St(e)(d_)))]},y_=e=>{const t=e_($(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=>o=>i=>{if(Ni(i)(o))return[Nn("ScheduleCycle",[...wt(we.foldr,o),i])];if(Ni(i)(r))return[];const u=n_(i)(t);if(u.tag==="Nothing")return[];if(u.tag==="Just")return St(u._1)(n(Z(E)(i)()(r))(Z(E)(i)()(o)));c()};return St(e)(r=>n(q)(q)(r.id))},J_={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:100,minTokenDuration:1.4,tokenReadSecPerChar:.06,nodeEasing:Xf,edgeEasing:$f,tokenEasing:Ff},N_=e=>t=>{if(t.tag==="Structural")return bt(n=>n)([xi(t._1.from)(e)?T:k("Just",Nn("UnknownKeyframe",t._1.from)),xi(t._1.to)(e)?T:k("Just",Nn("UnknownKeyframe",t._1.to))]);if(t.tag==="DataFlow")return[...bt(n=>n)([xi(t._1.keyframe)(e)?T:k("Just",Nn("UnknownKeyframe",t._1.keyframe))]),...m_(t._1.events),...y_(t._1.events)];c()},x_=e=>t=>{const n=St(t)(N_(e));return n.length===0?Lt("Right",void 0):Lt("Left",n)},ls=e=>t=>n=>y(__(e)(t))([])(Dt(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)),v_=e=>t=>n=>{const r=ls(e)(t)(n.events);return r.length===0?e.gap:y(sn)(0)($(o=>o.endT)(r))+e.gap},T_=e=>t=>n=>r=>o=>{if(o.tag==="Structural")return ds(e)(t)(n)(r)(o._1).duration;if(o.tag==="DataFlow")return v_(e)(t)(o._1);c()},w_=e=>t=>n=>r=>o=>y(i=>u=>{const s=T_(e)(t)(n)(r)(u);return{acc:me(i.acc)({startT:i.t,endT:i.t+s,scene:u}),t:i.t+s}})({acc:[],t:0})(o).acc,L_=e=>t=>n=>r=>$((()=>{const o=n.startT;return i=>({...i,startT:i.startT+o,endT:i.endT+o})})())(bt(c_)(ls(e)(t)(r.events))),E_=e=>t=>n=>r=>o=>{if(o.scene.tag==="Structural")return h_(e)(t)(n)(r)(o)(o.scene._1);if(o.scene.tag==="DataFlow")return L_(e)(t)(o)(o.scene._1);c()},k_=e=>t=>n=>{const r=0<t.keyframes.length?k("Just",t.keyframes[0]):T;if(r.tag==="Nothing")return Lt("Left",[r_]);if(r.tag==="Just"){const o=r._1,i=_g($(a=>x(a.id,a))(t.keyframes)),u=Gg(t),s=x_(i)(t.scenes);return(()=>{if(s.tag==="Left"){const a=s._1;return f=>Lt("Left",a)}if(s.tag==="Right"){const a=s._1;return f=>f(a)}c()})()(()=>{const a=w_(e)(n)(i)(u)(t.scenes),f=a.length-1|0,g=f>=0&&f<a.length?a[f].endT:0,d=xt(l=>_=>ht.compare(l.startT)(_.startT))(St(a)(E_(e)(n)(i)(u)));return Lt("Right",{totalDuration:g,windows:d,spans:a,keyframes:i,initialKeyframe:o.id,timing:e,layout:n,cameraSpans:Dg(Uu)(n)(g)([...f_(n)(u)(i)(a),...s_(n)(u)(d)]),cameraConfig:Uu})})}c()},lr=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},hs=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Kr=e=>t=>n=>{const r=ht.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),i=ht.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;c()},b_=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},C_=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},S_=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=E.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}}c()}return o},P_=jt(E)(zt),G_=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=E.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}}c()}return o},D_=jt(E)(zt),W_=jt(E)(zt),M_=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}}},wi=e=>t=>{const n=hs(t)(e.keyframes);if(n.tag==="Nothing")return q;if(n.tag==="Just")return n._1.nodes;c()},Li=e=>t=>{const n=hs(t)(e.keyframes);if(n.tag==="Nothing")return q;if(n.tag==="Just")return n._1.edges;c()},R_=e=>t=>n=>on(r=>r.endT<=t&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,e),I_=e=>t=>n=>on(r=>r.endT<=t&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,e),z_=e=>t=>n=>on(r=>r.startT>t&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,e),B_=e=>t=>n=>on(r=>r.startT>t&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,e),A_=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;c()},ps=e=>t=>n=>fe(r=>n(r)&&t>=r.startT&&t<r.endT)(e),Q_=e=>{const t=Kr(0)(1)(e/.2),n=Kr(0)(1)((1-e)/.2);return t*t*(3-2*t)*n*n*(3-2*n)},q_=e=>t=>{if(t.tag==="Travelling"){const n=b_(t._1.edge)(e.edges);if(n.tag==="Just"){const r=Iu(n._1)(t._1.progress);return r.tag==="Just"?k("Just",{dot:r._1,weight:Q_(t._1.progress)}):T}if(n.tag==="Nothing")return T;c()}return T},H_=e=>t=>{const n=vi(e)(t);if(n.tag==="AtKeyframe")return wi(e)(n._1);if(n.tag==="InTransition")return ye(E.compare,he,wi(e)(n._1),wi(e)(n._2));c()},V_=e=>t=>{const n=vi(e)(t);if(n.tag==="AtKeyframe")return Li(e)(n._1);if(n.tag==="InTransition")return ye(E.compare,he,Li(e)(n._1),Li(e)(n._2));c()},Y_=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:Kr(n.x+o/2)(n.x+n.w-o/2)(t.center.x),y:r>=n.h?n.y+n.h/2:Kr(n.y+r/2)(n.y+n.h-r/2)(t.center.y)}}},Zr=e=>t=>{const n=e.endT-e.startT;return n<=0?1:lr(0)(C_(1)((t-e.startT)/n))},F_=e=>t=>n=>r=>{const o=ps(e.windows)(t)(i=>i.target.tag==="EdgeWindow"&&i.target._1===r);if(o.tag==="Just"){const i=ni(e.timing.edgeEasing)(Zr(o._1)(t)),u=o._1.target.tag==="EdgeWindow"?o._1.target._2:Ji("Extend",is);if(u.tag==="Retract")return $r("Retracting",u._1,i);if(u.tag==="Extend")return $r("Extending",u._1,i);c()}if(o.tag==="Nothing")return B_(e.windows)(t)(r)||R_(e.windows)(t)(r)?us:S_(r)(n)?jg:us;c()},$_=e=>t=>{const n=V_(e)(t);return P_($(r=>x(r,F_(e)(t)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return q;if(o.tag==="Node")return $t("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));c()};return wt(we.foldr,r(e.layout.edges))})()))},O_=e=>t=>n=>r=>{const o=ps(e.windows)(t)(i=>i.target.tag==="NodeWindow"&&i.target._1===r);if(o.tag==="Just"){const i=Zr(o._1)(t),u=o._1.target.tag==="NodeWindow"?o._1.target._2:gs;if(u==="PlopIn")return Or("PloppingIn",i);if(u==="PlopOut")return Or("PloppingOut",i);c()}if(o.tag==="Nothing")return z_(e.windows)(t)(r)||I_(e.windows)(t)(r)?os:G_(r)(n)?Zg:os;c()},X_=e=>t=>{const n=H_(e)(t);return D_($(r=>x(r,O_(e)(t)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return q;if(o.tag==="Node")return $t("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));c()};return wt(we.foldr,r(e.layout.nodes))})()))},U_=e=>t=>n=>t.target.tag==="TokenWindow"?x(t.target._1,n<t.startT?yi:n>=t.endT?ns:Xr("Travelling",{edge:t.target._2,direction:t.target._3,progress:ni(e.timing.tokenEasing)(Zr(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?ns:Xr("Filling",{node:t.target._2,progress:Zr(t)(n),labels:t.target._3})):x("",yi),K_=e=>t=>W_($(n=>U_(e)(n)(t))(ct(n=>n.target.tag==="TokenWindow"||n.target.tag==="FillWindow",e.windows))),Z_=e=>t=>{const n=bt(q_(e))((()=>{const r=(o,i)=>{if(o.tag==="Leaf")return i;if(o.tag==="Node")return r(o._5,It("Cons",o._4,r(o._6,i)));c()};return wt(qt.foldr,r(t.tokens,Bt))})());return 0<n.length?k("Just",n[0]):T},j_=e=>t=>{const n=Z_(e)(t);if(n.tag==="Nothing")return t.camera;if(n.tag==="Just")return M_(e)(t.camera)(n._1.dot)(n._1.weight);c()},t1=e=>t=>{const n={nodes:X_(e)(t),edges:$_(e)(t),tokens:K_(e)(t),camera:Wg(e.cameraConfig)(e.layout)(e.cameraSpans)(t),frameTitle:A_(e)(t)};return{...n,camera:Y_(e.layout)(j_(e.layout)(n))}};let Ei=null;function e1(){return Ei||(typeof document>"u"?null:(Ei=document.createElement("canvas").getContext("2d"),Ei))}const ms=new Map,n1=e=>t=>n=>r=>()=>{const o=`${n} ${t}px ${e}|${r}`,i=ms.get(o);if(i!==void 0)return i;const u=e1();if(!u)return r.length*t*.62;u.font=`${n} ${t}px ${e}`;const s=u.measureText(r).width;return ms.set(o,s),s},ys=(()=>{const e=Yr(`\r
|
|
3
|
-
`)(" "),t=
|
|
4
|
-
`)(" "),n=(()=>{const r=
|
|
5
|
-
`)(i._1))(ki(o)),s=y(a=>f=>hr(a)(hn(f)))(0)(u);return{...i._2,size:x(_t(s>o?bn((s+2|0)+e.cellW|0,e.cellW):r),_t(hr(1)(bn(u.length+e.cellH|0,e.cellH))))}})(n)}},c1=e=>t=>n=>({...n,nodes:$(r=>{const o=i1(r.id)(t);if(o.tag==="Nothing")return r;if(o.tag==="Just")return{...r,size:x(o1(r.size._1)(_t(hr(1)(tr(hc((o._1+32)/e))))),r.size._2)};c()})(n.nodes)}),f1=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},g1=e=>{const t=e.length;return(n=>r=>{let o=n,i=r,u=!0,s;for(;u;){const a=o,f=i;if(a>=t){u=!1,s=f;continue}const g=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const J=_,N=h;if(J>=t){p=!1,m=N;continue}if(a>=0&&a<e.length){if(J>=0&&J<e.length){_=J+1|0,h=(()=>{const v=e[a].position,w=e[a].size,b=e[J].position,L=e[J].size;return v._1<b._1+L._1&&b._1<v._1+w._1&&v._2<b._2+L._2&&b._2<v._2+w._2})()?N+1|0:N;continue}_=J+1|0,h=N;continue}p=!1,m=N}return m};o=a+1|0,i=g(a+1|0)(f)}return s})(0)(0)},Ns=e=>y(t=>n=>t+ag(n.start)(n.end))(0)(e.segments),_1=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+Ns(o))(0)(t),maxEdgeLength:y(r=>o=>f1(r)(Ns(o)))(0)(t),nodeOverlapCount:g1(e),constraintViolations:n,jumpCount:y(r=>o=>r+o.jumps.length|0)(0)(t)}),xs=e=>e,An=jt(it)(zt),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=it.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},vs=e=>t=>{const n=it.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},ot=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},ut=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},$e=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},d1=e=>t=>{const n=it.compare(e._1)(t._1);return n==="LT"?Re:n==="GT"?Ie:it.compare(e._2)(t._2)},Qn=e=>t=>{const n=it.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},l1=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),h1=e=>e,jr=xs("Regular"),to=xs("Critical"),Ts=e=>t=>{const n=y(u=>s=>Z(E)(s.node)(s)(u))(q)(t),r=1.25*_t(4),o=(u,s,a)=>(f=>g=>d=>{let l=f,_=g,h=d,p=!0,m;for(;p;){const J=l,N=_,v=h;if(v.critical){p=!1,m=v;continue}const w=Vt(L=>T,L=>S=>k("Just",{head:L,tail:S}),J),b=Vt(L=>T,L=>S=>k("Just",{head:L,tail:S}),N);if(w.tag==="Just"&&b.tag==="Just"){const L=w._1.head>b._1.head-u&&w._1.head<b._1.head+u?{...v,critical:!0}:w._1.head>b._1.head-r&&w._1.head<b._1.head+r?{...v,conflicts:v.conflicts+1|0}:v;if(L.critical){p=!1,m=L;continue}if(w._1.head<=b._1.head){l=w._1.tail,_=N,h=L;continue}l=J,_=b._1.tail,h=L;continue}p=!1,m=v}return m})(s)(a)({conflicts:0,critical:!1}),i=(u,s,a)=>{if(ut(y(ut)(-1e18)(s.incoming))(y(ut)(-1e18)(s.outgoing))-ot(y(ot)(1e18)(s.incoming))(y(ot)(1e18)(s.outgoing))<.001||ut(y(ut)(-1e18)(a.incoming))(y(ut)(-1e18)(a.outgoing))-ot(y(ot)(1e18)(a.incoming))(y(ot)(1e18)(a.outgoing))<.001)return[];const f=o(u,s.outgoing,a.incoming),g=o(u,a.outgoing,s.incoming);if(f.critical||g.critical)return[...f.critical?[{src:a.id,tgt:s.id,weight:1,kind:to}]:[],...g.critical?[{src:s.id,tgt:a.id,weight:1,kind:to}]:[]];const d=ot(y(ot)(1e18)(s.incoming))(y(ot)(1e18)(s.outgoing)),l=ut(y(ut)(-1e18)(s.incoming))(y(ut)(-1e18)(s.outgoing)),_=ot(y(ot)(1e18)(a.incoming))(y(ot)(1e18)(a.outgoing)),h=ut(y(ut)(-1e18)(a.incoming))(y(ut)(-1e18)(a.outgoing)),p=(1*f.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,m=(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 p<m?[{src:s.id,tgt:a.id,weight:m-p|0,kind:jr}]:p>m?[{src:a.id,tgt:s.id,weight:p-m|0,kind:jr}]:p>0?[{src:s.id,tgt:a.id,weight:0,kind:jr},{src:a.id,tgt:s.id,weight:0,kind:jr}]:[]};return y(u=>s=>y(a=>f=>Z(E)(f._1)(f._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;c()})(),K=$e(et)(G.entries);if(K.tag==="Nothing")return{...G,entries:Z(E)(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(E)(et)({...K._1,members:[...K._1.members,P.edge.id],incoming:[..._n(A=>A<P.fromPos._1)(K._1.incoming).init,P.fromPos._1,..._n(A=>A<=P.fromPos._1)(K._1.incoming).rest],outgoing:[..._n(A=>A<P.toPos._1)(K._1.outgoing).init,P.toPos._1,..._n(A=>A<=P.toPos._1)(K._1.outgoing).rest]})(G.entries)};c()})({entries:q,order:[]})(s._2),f=Dt(G=>P=>({...P,id:G}))(bt(G=>$e(G)(a.entries))(a.order));if(f.length===0)return[];const g=y(G=>P=>G.prev.tag==="Just"&&P-G.prev._1<1e-9?G:{prev:k("Just",P),out:[...G.out,P]})({prev:T,out:[]})(xt(ht.compare)([...St(f)(G=>G.incoming),...St(f)(G=>G.outgoing)])).out,d=g.length<2?.2*r:.2*y(G=>P=>{if(G.prev.tag==="Nothing")return{prev:k("Just",P),mn:G.mn};if(G.prev.tag==="Just")return{prev:k("Just",P),mn:ot(G.mn)(P-G.prev._1)};c()})({prev:T,mn:1e18})(g).mn,l={segments:f,deps:(()=>{const G=f.length;return St(St(Ht(0,G-2|0))(P=>St(Ht(P+1|0,G-1|0))(et=>[x(P,et)])))(P=>P._1>=0&&P._1<f.length?P._2>=0&&P._2<f.length?i(d,f[P._1],f[P._2]):[]:[])})()},_=ct(G=>{if(G.kind==="Critical")return!0;if(G.kind==="Regular")return!1;c()},l.deps),h=(()=>{if(_.length<2)return l;const G=An((()=>{const H=l.segments;return $(R=>x(R.id,R.mark))((()=>{const R=H.length,C=W=>{let M=W,Y=!0,X;for(;Y;){const V=M,Q=fe(I=>{const U=Nt(I)(V.inWeight);if(U.tag==="Nothing")return!0;if(U.tag==="Just")return U._1===0;c()})(V.remaining);if(Q.tag==="Nothing"){Y=!1,X=V;continue}if(Q.tag==="Just"){const I=Q._1;M={...V,inWeight:y(U=>O=>vt(it)(Ut)(O.tgt)(-O.weight)(U))(V.inWeight)((()=>{const U=Nt(I)(V.depsBySrc);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),marks:Z(it)(I)(V.nextSource)(V.marks),nextSource:V.nextSource+1|0,outWeight:y(U=>O=>vt(it)(Ut)(O.src)(-O.weight)(U))(V.outWeight)((()=>{const U=Nt(I)(V.depsByTgt);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),remaining:ct(U=>U!==I,V.remaining)};continue}c()}return X},D=W=>{let M=W,Y=!0,X;for(;Y;){const V=M,Q=fe(I=>{const U=Nt(I)(V.outWeight);if(U.tag==="Nothing")return!0;if(U.tag==="Just")return U._1===0;c()})(V.remaining);if(Q.tag==="Nothing"){Y=!1,X=V;continue}if(Q.tag==="Just"){const I=Q._1;M={...V,inWeight:y(U=>O=>vt(it)(Ut)(O.tgt)(-O.weight)(U))(V.inWeight)((()=>{const U=Nt(I)(V.depsBySrc);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),marks:Z(it)(I)(V.nextSink)(V.marks),nextSink:V.nextSink-1|0,outWeight:y(U=>O=>vt(it)(Ut)(O.src)(-O.weight)(U))(V.outWeight)((()=>{const U=Nt(I)(V.depsByTgt);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),remaining:ct(U=>U!==I,V.remaining)};continue}c()}return X};return(W=>{let M=W,Y=!0,X;for(;Y;){const V=C(D(M));if(V.remaining.length===0){Y=!1,X=$(Q=>{const I=Nt(Q.id)(V.marks),U=(()=>{if(I.tag==="Nothing")return Q.id;if(I.tag==="Just")return I._1;c()})();return{...Q,mark:U<R?(U+R|0)+1|0:U}})(H);continue}M=(()=>{const Q=U=>{const O=Nt(U)(V.outWeight),gt=Nt(U)(V.inWeight);return(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;c()})()-(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;c()})()|0},I=xt(U=>O=>it.compare(Q(O))(Q(U)))(V.remaining);if(0<I.length){const U=I[0];return{...V,inWeight:y(O=>gt=>vt(it)(Ut)(gt.tgt)(-gt.weight)(O))(V.inWeight)((()=>{const O=Nt(U)(V.depsBySrc);if(O.tag==="Nothing")return[];if(O.tag==="Just")return O._1;c()})()),marks:Z(it)(U)(V.nextSource)(V.marks),nextSource:V.nextSource+1|0,outWeight:y(O=>gt=>vt(it)(Ut)(gt.src)(-gt.weight)(O))(V.outWeight)((()=>{const O=Nt(U)(V.depsByTgt);if(O.tag==="Nothing")return[];if(O.tag==="Just")return O._1;c()})()),remaining:ct(O=>O!==U,V.remaining)}}return V})()}return X})({remaining:$(W=>W.id)(H),marks:q,inWeight:y(W=>M=>vt(it)(Ut)(M.tgt)(M.weight)(W))(q)(_),outWeight:y(W=>M=>vt(it)(Ut)(M.src)(M.weight)(W))(q)(_),depsBySrc:y(W=>M=>vt(it)(ie)(M.src)([M])(W))(q)(_),depsByTgt:y(W=>M=>vt(it)(ie)(M.tgt)([M])(W))(q)(_),nextSink:R-1|0,nextSource:R+1|0})})())})()),P=ct(H=>{const R=Nt(H.src)(G),C=Nt(H.tgt)(G);return(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._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(H=>R=>{if(ze(Wo)(R.src)(H.decisions)||ze(Wo)(R.tgt)(H.decisions))return H;const C=Nt(R.src)(H.segMap),D=Nt(R.tgt)(H.segMap);if(C.tag==="Just"&&D.tag==="Just"){const W=(C._1.incoming.length+C._1.outgoing.length|0)>2&&(D._1.incoming.length+D._1.outgoing.length|0)<=2,M=W?D._1:C._1;return{decisions:[...H.decisions,M.id],segMap:Z(it)(M.id)({...M,splitBy:k("Just",W?C._1.id:D._1.id)})(H.segMap)}}return H})({decisions:[],segMap:An($(H=>x(H.id,H))(l.segments))})(P),K=et.segMap,A=y(H=>R=>{const C=ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(R.outgoing)),D=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(R.outgoing)),W=ct(Q=>Q.a.startPosition<=D&&Q.a.endPosition>=C,Dt(Q=>I=>({i:Q,a:I}))(H.freeAreas));if(W.length===0){const Q={...R,incoming:xt(ht.compare)(R.incoming),outgoing:xt(ht.compare)([(C+D)/2]),splitPartner:k("Just",H.nextId)},I={id:H.nextId,incoming:xt(ht.compare)([(C+D)/2]),mark:0,members:R.members,outgoing:xt(ht.compare)(R.outgoing),slot:0,splitBy:T,splitPartner:k("Just",R.id)};return{segMap:Z(it)(I.id)(I)(Z(it)(Q.id)(Q)(H.segMap)),freeAreas:H.freeAreas,nextId:H.nextId+1|0}}const M=0<W.length?k("Just",W[0]):T,Y=(()=>{if(M.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(M.tag==="Just"){if(W.length===1)return M._1;const Q=$(I=>({c:I,rating:(()=>{const U=(I.a.startPosition+I.a.endPosition)/2,O=[U],gt=[U],pt=y((()=>{const lt=H.segMap;return Tt=>Gt=>{const dt=Nt(Gt.tgt)(lt);if(dt.tag==="Nothing")return Tt;if(dt.tag==="Just"){const Mt=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),mt=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),ft=ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(O)),rt=(()=>{const kt=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(O)),Pt=y(Rt=>re=>re>mt?Rt:re>=Mt?Rt+1|0:Rt)(0)(O)+y(Rt=>re=>re>kt?Rt:re>=ft?Rt+1|0:Rt)(0)(dt._1.incoming)|0,Kn=ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(O)),En=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(O)),kn=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),Zn=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),Me=y(Rt=>re=>re>En?Rt:re>=Kn?Rt+1|0:Rt)(0)(dt._1.outgoing)+y(Rt=>re=>re>Zn?Rt:re>=kn?Rt+1|0:Rt)(0)(R.incoming)|0;return Pt===Me?Pt>0?{...Tt,deps:Tt.deps+2|0,crossings:Tt.crossings+Pt|0}:Tt:{...Tt,deps:Tt.deps+1|0,crossings:Tt.crossings+Qn(Pt)(Me)|0}})(),nt=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),st=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),yt=ot(y(ot)(1e18)(gt))(y(ot)(1e18)(R.outgoing)),Jt=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),Ct=y(kt=>Pt=>Pt>st?kt:Pt>=nt?kt+1|0:kt)(0)(R.outgoing)+y(kt=>Pt=>Pt>Jt?kt:Pt>=yt?kt+1|0:kt)(0)(dt._1.incoming)|0,Qt=ot(y(ot)(1e18)(gt))(y(ot)(1e18)(R.outgoing)),ne=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),He=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),Un=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),nn=y(kt=>Pt=>Pt>ne?kt:Pt>=Qt?kt+1|0:kt)(0)(dt._1.outgoing)+y(kt=>Pt=>Pt>Un?kt:Pt>=He?kt+1|0:kt)(0)(gt)|0;return Ct===nn?Ct>0?{...rt,deps:rt.deps+2|0,crossings:rt.crossings+Ct|0}:rt:{...rt,deps:rt.deps+1|0,crossings:rt.crossings+Qn(Ct)(nn)|0}}c()}})())(y((()=>{const lt=H.segMap;return Tt=>Gt=>{const dt=Nt(Gt.src)(lt);if(dt.tag==="Nothing")return Tt;if(dt.tag==="Just"){const Mt=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),mt=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),ft=ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(O)),rt=(()=>{const kt=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(O)),Pt=y(Rt=>re=>re>mt?Rt:re>=Mt?Rt+1|0:Rt)(0)(O)+y(Rt=>re=>re>kt?Rt:re>=ft?Rt+1|0:Rt)(0)(dt._1.incoming)|0,Kn=ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(O)),En=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(O)),kn=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),Zn=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),Me=y(Rt=>re=>re>En?Rt:re>=Kn?Rt+1|0:Rt)(0)(dt._1.outgoing)+y(Rt=>re=>re>Zn?Rt:re>=kn?Rt+1|0:Rt)(0)(R.incoming)|0;return Pt===Me?Pt>0?{...Tt,deps:Tt.deps+2|0,crossings:Tt.crossings+Pt|0}:Tt:{...Tt,deps:Tt.deps+1|0,crossings:Tt.crossings+Qn(Pt)(Me)|0}})(),nt=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),st=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),yt=ot(y(ot)(1e18)(gt))(y(ot)(1e18)(R.outgoing)),Jt=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),Ct=y(kt=>Pt=>Pt>st?kt:Pt>=nt?kt+1|0:kt)(0)(R.outgoing)+y(kt=>Pt=>Pt>Jt?kt:Pt>=yt?kt+1|0:kt)(0)(dt._1.incoming)|0,Qt=ot(y(ot)(1e18)(gt))(y(ot)(1e18)(R.outgoing)),ne=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),He=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),Un=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),nn=y(kt=>Pt=>Pt>ne?kt:Pt>=Qt?kt+1|0:kt)(0)(dt._1.outgoing)+y(kt=>Pt=>Pt>Un?kt:Pt>=He?kt+1|0:kt)(0)(gt)|0;return Ct===nn?Ct>0?{...rt,deps:rt.deps+2|0,crossings:rt.crossings+Ct|0}:rt:{...rt,deps:rt.deps+1|0,crossings:rt.crossings+Qn(Ct)(nn)|0}}c()}})())({crossings:0,deps:0})(ct(lt=>lt.tgt===R.id,l.deps)))(ct(lt=>lt.src===R.id,l.deps)),at=(()=>{if(R.splitBy.tag==="Just")return Nt(R.splitBy._1)(H.segMap);if(R.splitBy.tag==="Nothing")return T;c()})();if(at.tag==="Just")return{...pt,deps:pt.deps+2|0,crossings:(()=>{const lt=ot(y(ot)(1e18)(at._1.incoming))(y(ot)(1e18)(at._1.outgoing)),Tt=ot(y(ot)(1e18)(gt))(y(ot)(1e18)(R.outgoing)),Gt=ut(y(ut)(-1e18)(at._1.incoming))(y(ut)(-1e18)(at._1.outgoing)),dt=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),Mt=ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(O));return pt.crossings+(()=>{const mt=ot(y(ot)(1e18)(at._1.incoming))(y(ot)(1e18)(at._1.outgoing)),ft=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(O)),rt=ut(y(ut)(-1e18)(at._1.incoming))(y(ut)(-1e18)(at._1.outgoing));return((y(nt=>st=>st>Gt?nt:st>=lt?nt+1|0:nt)(0)(O)+y(nt=>st=>st>ft?nt:st>=Mt?nt+1|0:nt)(0)(at._1.incoming)|0)+y(nt=>st=>st>dt?nt:st>=Tt?nt+1|0:nt)(0)(at._1.outgoing)|0)+y(nt=>st=>st>rt?nt:st>=mt?nt+1|0:nt)(0)(gt)|0})()|0})()};if(at.tag==="Nothing")return pt;c()})()}))(W);return y(I=>U=>U.rating.crossings<I.rating.crossings||!(U.rating.crossings>I.rating.crossings)&&(U.rating.deps<I.rating.deps||!(U.rating.deps>I.rating.deps)&&U.c.a.size>I.c.a.size)?U:I)(0<Q.length?Q[0]:{c:M._1,rating:{crossings:1e6,deps:1e6}})(Q).c}c()})(),X={...R,incoming:xt(ht.compare)(R.incoming),outgoing:xt(ht.compare)([(Y.a.startPosition+Y.a.endPosition)/2]),splitPartner:k("Just",H.nextId)},V={id:H.nextId,incoming:xt(ht.compare)([(Y.a.startPosition+Y.a.endPosition)/2]),mark:0,members:R.members,outgoing:xt(ht.compare)(R.outgoing),slot:0,splitBy:T,splitPartner:k("Just",R.id)};return{segMap:Z(it)(V.id)(V)(Z(it)(X.id)(X)(H.segMap)),freeAreas:(()=>{if(Y.i>=0&&Y.i<H.freeAreas.length){const Q=Cu(Kt,T,Y.i,H.freeAreas),I=(()=>{if(Q.tag==="Nothing")return H.freeAreas;if(Q.tag==="Just")return Q._1;c()})();if(H.freeAreas[Y.i].size/2<d)return I;const U=(H.freeAreas[Y.i].startPosition+H.freeAreas[Y.i].endPosition)/2,O=U-d,gt=U+d;return[...Y.i<1?[]:Wt(0,Y.i,I),...H.freeAreas[Y.i].startPosition<=O?[{startPosition:H.freeAreas[Y.i].startPosition,endPosition:O,size:O-H.freeAreas[Y.i].startPosition}]:[],...gt<=H.freeAreas[Y.i].endPosition?[{startPosition:gt,endPosition:H.freeAreas[Y.i].endPosition,size:H.freeAreas[Y.i].endPosition-gt}]:[],...Y.i<1?I:Wt(Y.i,I.length,I)]}return H.freeAreas})(),nextId:H.nextId+1|0}})({segMap:K,freeAreas:(()=>{const H=xt(ht.compare)([...St(l.segments)(R=>R.incoming),...St(l.segments)(R=>R.outgoing)]);return bt(h1)(pe(R=>C=>C-R>=2*d?k("Just",{startPosition:R+d,endPosition:C-d,size:C-R-2*d}):T,H,Wt(1,H.length,H)))})(),nextId:l.segments.length})(xt(H=>R=>ht.compare(ut(y(ut)(-1e18)(H.incoming))(y(ut)(-1e18)(H.outgoing))-ot(y(ot)(1e18)(H.incoming))(y(ot)(1e18)(H.outgoing)))(ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(R.outgoing))-ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(R.outgoing))))(bt(H=>Nt(H)(K))(et.decisions)));return{segments:(()=>{const H=(R,C)=>{if(R.tag==="Leaf")return C;if(R.tag==="Node")return H(R._5,It("Cons",R._4,H(R._6,C)));c()};return wt(qt.foldr,H(A.segMap,Bt))})(),deps:(()=>{const H=A.segMap,R=(W,M)=>{if(W.tag==="Leaf")return M;if(W.tag==="Node")return R(W._5,It("Cons",W._4,R(W._6,M)));c()},C=wt(qt.foldr,R(H,Bt)),D=C.length;return[...St(St(Ht(0,D-2|0))(W=>St(Ht(W+1|0,D-1|0))(M=>[x(W,M)])))(W=>W._1>=0&&W._1<C.length?W._2>=0&&W._2<C.length?C[W._1].splitPartner.tag!=="Nothing"&&C[W._1].splitPartner.tag==="Just"&&C[W._1].splitPartner._1===C[W._2].id||C[W._2].splitPartner.tag!=="Nothing"&&C[W._2].splitPartner.tag==="Just"&&C[W._2].splitPartner._1===C[W._1].id?[]:i(d,C[W._1],C[W._2]):[]:[]),...St(C)(W=>W.splitBy.tag==="Just"&&W.splitPartner.tag==="Just"&&(()=>{const M=Nt(W.splitPartner._1)(H);if(M.tag==="Nothing")return!1;if(M.tag==="Just")return!0;c()})()&&(()=>{const M=Nt(W.splitBy._1)(H);if(M.tag==="Nothing")return!1;if(M.tag==="Just")return!0;c()})()?[{src:W.id,tgt:W.splitBy._1,weight:1,kind:to},{src:W.splitBy._1,tgt:W.splitPartner._1,weight:1,kind:to}]:[])]})()}})(),p=h.segments,m=p.length,J=G=>{let P=G,et=!0,K;for(;et;){const A=P,H=fe(R=>{const C=Nt(R)(A.inWeight);if(C.tag==="Nothing")return!0;if(C.tag==="Just")return C._1===0;c()})(A.remaining);if(H.tag==="Nothing"){et=!1,K=A;continue}if(H.tag==="Just"){const R=H._1;P={...A,inWeight:y(C=>D=>vt(it)(Ut)(D.tgt)(-D.weight)(C))(A.inWeight)((()=>{const C=Nt(R)(A.depsBySrc);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),marks:Z(it)(R)(A.nextSource)(A.marks),nextSource:A.nextSource+1|0,outWeight:y(C=>D=>vt(it)(Ut)(D.src)(-D.weight)(C))(A.outWeight)((()=>{const C=Nt(R)(A.depsByTgt);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),remaining:ct(C=>C!==R,A.remaining)};continue}c()}return K},N=G=>{let P=G,et=!0,K;for(;et;){const A=P,H=fe(R=>{const C=Nt(R)(A.outWeight);if(C.tag==="Nothing")return!0;if(C.tag==="Just")return C._1===0;c()})(A.remaining);if(H.tag==="Nothing"){et=!1,K=A;continue}if(H.tag==="Just"){const R=H._1;P={...A,inWeight:y(C=>D=>vt(it)(Ut)(D.tgt)(-D.weight)(C))(A.inWeight)((()=>{const C=Nt(R)(A.depsBySrc);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),marks:Z(it)(R)(A.nextSink)(A.marks),nextSink:A.nextSink-1|0,outWeight:y(C=>D=>vt(it)(Ut)(D.src)(-D.weight)(C))(A.outWeight)((()=>{const C=Nt(R)(A.depsByTgt);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),remaining:ct(C=>C!==R,A.remaining)};continue}c()}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=$(H=>{const R=Nt(H.id)(A.marks),C=(()=>{if(R.tag==="Nothing")return H.id;if(R.tag==="Just")return R._1;c()})();return{...H,mark:C<m?(C+m|0)+1|0:C}})(p);continue}P=(()=>{const H=C=>{const D=Nt(C)(A.outWeight),W=Nt(C)(A.inWeight);return(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;c()})()-(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;c()})()|0},R=xt(C=>D=>it.compare(H(D))(H(C)))(A.remaining);if(0<R.length){const C=R[0];return{...A,inWeight:y(D=>W=>vt(it)(Ut)(W.tgt)(-W.weight)(D))(A.inWeight)((()=>{const D=Nt(C)(A.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})()),marks:Z(it)(C)(A.nextSource)(A.marks),nextSource:A.nextSource+1|0,outWeight:y(D=>W=>vt(it)(Ut)(W.src)(-W.weight)(D))(A.outWeight)((()=>{const D=Nt(C)(A.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})()),remaining:ct(D=>D!==C,A.remaining)}}return A})()}return K})({remaining:$(G=>G.id)(p),marks:q,inWeight:y(G=>P=>vt(it)(Ut)(P.tgt)(P.weight)(G))(q)(h.deps),outWeight:y(G=>P=>vt(it)(Ut)(P.src)(P.weight)(G))(q)(h.deps),depsBySrc:y(G=>P=>vt(it)(ie)(P.src)([P])(G))(q)(h.deps),depsByTgt:y(G=>P=>vt(it)(ie)(P.tgt)([P])(G))(q)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),w=(()=>{const G=(()=>{const K=An($(A=>x(A.id,A.mark))(v));return{segments:v,deps:bt(A=>(()=>{if(A.kind==="Critical")return!0;if(A.kind==="Regular")return!1;c()})()?k("Just",A):(()=>{const H=Nt(A.src)(K),R=Nt(A.tgt)(K);return(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;c()})()>(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;c()})()})()?A.weight===0?T:k("Just",{src:A.tgt,tgt:A.src,weight:A.weight,kind:A.kind}):k("Just",A))(h.deps)}})(),P=y(K=>A=>vt(it)(Ut)(A.tgt)(1)(K))(q)(G.deps),et=(K=>{let A=K,H=!0,R;for(;H;){const C=A,D=Vt(W=>T,W=>M=>k("Just",{head:W,tail:M}),C.queue);if(D.tag==="Nothing"){H=!1,R=C;continue}if(D.tag==="Just"){A=y((()=>{const W=Nt(D._1.head)(C.slots),M=(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;c()})();return Y=>X=>{const V=Nt(X)(Y.inDegree),Q=(()=>{if(V.tag==="Nothing")return-1;if(V.tag==="Just")return V._1-1|0;c()})();return{...Y,slots:Z(it)(X)(vs((()=>{const I=Nt(X)(Y.slots);if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;c()})())(M+1|0))(Y.slots),inDegree:Z(it)(X)(Q)(Y.inDegree),queue:Q===0?[...Y.queue,X]:Y.queue}}})())({...C,queue:D._1.tail})((()=>{const W=Nt(D._1.head)(C.adj);if(W.tag==="Nothing")return[];if(W.tag==="Just")return W._1;c()})());continue}c()}return R})({slots:An($(K=>x(K.id,0))(G.segments)),inDegree:P,adj:y(K=>A=>vt(it)(ie)(A.src)([A.tgt])(K))(q)(G.deps),queue:$(K=>K.id)(ct(K=>{const A=Nt(K.id)(P);if(A.tag==="Nothing")return!0;if(A.tag==="Just")return A._1===0;c()},G.segments))});return xt(K=>A=>it.compare(K.slot)(A.slot))($(K=>({...K,slot:(()=>{const A=Nt(K.id)(et.slots);if(A.tag==="Nothing")return 0;if(A.tag==="Just")return A._1;c()})()}))(G.segments))})(),b=1+y(G=>P=>vs(G)(P.slot))(0)(w)|0,L=St(w)(G=>G.members),S=ct(G=>ze(Ye)(G.edge.id)(L),e),z=y(ut)(-1e18)($(G=>G.fromPos._2)(S)),F=y(ot)(1e18)($(G=>G.toPos._2)(S));if(z>F){const G=An($(P=>x(P.id,P))(w));return Ne($(P=>$(et=>x(et,{slot:P.slot,slotCount:b,gapTop:F,gapBottom:z,partner:(()=>{if(P.splitPartner.tag==="Just"){const K=Nt(P.splitPartner._1)(G);if(K.tag==="Just")return k("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))(ct(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;c()})())}if(P.splitPartner.tag==="Nothing")return!0;c()},w)))}const j=An($(G=>x(G.id,G))(w));return Ne($(G=>$(P=>x(P,{slot:G.slot,slotCount:b,gapTop:z,gapBottom:F,partner:(()=>{if(G.splitPartner.tag==="Just"){const et=Nt(G.splitPartner._1)(j);if(et.tag==="Just")return k("Just",{slot:et._1.slot,splitX:0<et._1.incoming.length?et._1.incoming[0]:0});if(et.tag==="Nothing")return T;c()}if(G.splitPartner.tag==="Nothing")return T;c()})()}))(G.members))(ct(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;c()})())}if(G.splitPartner.tag==="Nothing")return!0;c()},w)))})()))(q)(l1(y(u=>s=>{const a=$e(s.edge.from.node)(n);if(a.tag==="Just"){const f=$e(s.edge.to.node)(n);return f.tag==="Just"&&a._1.layer!==f._1.layer?vt(it)(ie)(Qn(a._1.layer)(f._1.layer))([s])(u):u}return u})(q)((()=>{const u=s=>x((()=>{const a=$e(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=$e(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return xt(s=>a=>d1(u(s))(u(a)))(e)})())))},p1=e=>t=>{const n=Ts(e)(t),r=y(o=>i=>Z(E)(i.node)(i)(o))(q)(t);return y(o=>i=>{const u=$e(i.edge.from.node)(r);if(u.tag==="Just"){const s=$e(i.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=$e(i.edge.id)(n);if(a.tag==="Just")return Z(it)(Qn(u._1.layer)(s._1.layer))(a._1.slotCount)(o)}return o}return o})(q)(e)},ws=e=>e,Ot=ws("H"),Xt=ws("V"),Ls=zt.foldMap((()=>{const e={append:t=>n=>t||n};return{mempty:!1,Semigroup0:()=>e}})()),te=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},ee=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},pr=e=>t=>n=>r=>Ls(o=>n>=o.x&&n<o.x+o.w&&t>o.y&&e<o.y+o.h)(r),eo=e=>t=>n=>r=>pr(te(t)(n))(ee(t)(n))(r)(e),no=_t(4),m1=Pu(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}]}c()}),Es=Rf(e=>!(e.start._1===e.end._1&&e.start._2===e.end._2)),y1=e=>t=>n=>{const r=Vt(o=>T,o=>i=>k("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=Df(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?[]:Wt(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]}c()},bi=e=>{const t=r=>o=>{const i=Vt(u=>T,u=>s=>k("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;c()})()?t({start:r.start,end:i._1.head.end,direction:r.direction})(i._1.tail):[r,...t(i._1.head)(i._1.tail)];c()},n=Vt(r=>T,r=>o=>k("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return t(n._1.head)(n._1.tail);c()},mr=e=>t=>n=>r=>Ls(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),J1=e=>t=>n=>r=>{const o=n+2|0,i=o<1?t:Wt(o,t.length,t),u=n<1?[]:Wt(0,n,t),s=(n+1|0)===(r-1|0),a=n===0,f=n>=0&&n<t.length?k("Just",t[n]):T;if(f.tag==="Just"){const g=n+1|0,d=g>=0&&g<t.length?k("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")&&!eo(e)(te(f._1.start._2)(d._1.end._2))(ee(f._1.start._2)(d._1.end._2))(f._1.start._1)?k("Just",[...u,{start:f._1.start,end:d._1.end,direction:Xt},...i]):T,_=f._1.start._2===d._1.end._2&&(!a||f._1.direction==="H")&&(!s||d._1.direction==="H")&&!yr(e)(te(f._1.start._1)(d._1.end._1))(ee(f._1.start._1)(d._1.end._1))(f._1.start._2)?k("Just",[...u,{start:f._1.start,end:d._1.end,direction:Ot},...i]):T;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return T;c()}if(f.tag==="Nothing")return T;c()},N1=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=J1(e)(t)(s)(n);if(a.tag==="Just"){i=!1,u=a._1;continue}if(a.tag==="Nothing"){o=s+1|0;continue}c()}return u})(0)},x1=e=>t=>n=>r=>{const o=(l,_,h)=>!eo(e)(te(_)(h))(ee(_)(h))(l),i=n+3|0,u=i<1?t:Wt(i,t.length,t),s=n<1?[]:Wt(0,n,t),a=(n+2|0)===(r-1|0),f=n===0,g=(l,_,h)=>!yr(e)(te(_)(h))(ee(_)(h))(l),d=n>=0&&n<t.length?k("Just",t[n]):T;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<t.length?k("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")&&o(d._1.start._1,d._1.start._2,_._1.end._2)?k("Just",[...s,{start:d._1.start,end:_._1.end,direction:Xt},...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)?k("Just",[...s,{start:d._1.start,end:_._1.end,direction:Ot},...u]):T,p=(!f||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)?k("Just",[...s,{start:d._1.start,end:x(d._1.start._1,_._1.end._2),direction:Xt},{start:x(d._1.start._1,_._1.end._2),end:_._1.end,direction:Ot},...u]):T,m=(!f||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)?k("Just",[...s,{start:d._1.start,end:x(_._1.end._1,d._1.start._2),direction:Ot},{start:x(_._1.end._1,d._1.start._2),end:_._1.end,direction:Xt},...u]):T,J=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?J:h}if(_.tag==="Nothing")return T;c()}if(d.tag==="Nothing")return T;c()},v1=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=x1(e)(t)(s)(n);if(a.tag==="Just"){i=!1,u=a._1;continue}if(a.tag==="Nothing"){o=s+1|0;continue}c()}return u})(0)},T1=e=>{const t=n=>{let r=n,o=!0,i;for(;o;){const u=r,s=bi(Es(N1(e)(v1(e)(u))));if(s.length<u.length){r=s;continue}o=!1,i=s}return i};return n=>t(bi(Es(n)))},w1=e=>t=>n=>r=>{const o=te(n)(r),i=ee(n)(r),u=ct(a=>t>=a.y&&t<a.y+a.h&&a.x+a.w>o&&a.x<i,e);if(r>n){const a=xt(f=>g=>ht.compare(f.x)(g.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=xt(a=>f=>ht.compare(f.x)(a.x))($(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},L1=e=>t=>n=>r=>{const o=te(n)(r),i=ee(n)(r),u=ct(a=>t>=a.x&&t<a.x+a.w&&a.y+a.h>o&&a.y<i,e);if(r>n){const a=xt(f=>g=>ht.compare(f.y)(g.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=xt(a=>f=>ht.compare(f.y)(a.y))($(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},E1=e=>t=>n=>r=>{const o=te(n)(r),i=ee(n)(r),u=ct(a=>t>=a.y&&t<a.y+a.h&&a.x+a.w>o&&a.x<i,e);if(r>n){const a=xt(f=>g=>ht.compare(g.x)(f.x))($(f=>({...f,x:f.x+f.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=xt(a=>f=>ht.compare(a.x)(f.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},k1=e=>t=>n=>r=>{const o=te(n)(r),i=ee(n)(r),u=ct(a=>t>=a.x&&t<a.x+a.w&&a.y+a.h>o&&a.y<i,e);if(r>n){const a=xt(f=>g=>ht.compare(g.y)(f.y))($(f=>({...f,y:f.y+f.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=xt(a=>f=>ht.compare(a.y)(f.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},ks=e=>t=>n=>{let r=e,o=t,i=n,u=!0,s;for(;u;){const a=r,f=o,g=i;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,o=f,i=g+1}return s},bs=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)?ks(a=>pr(i)(u)(a)(e))(s)(1):s},b1=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)?ks(a=>mr(i)(u)(a)(e))(s)(1):s},C1=e=>t=>n=>r=>{const o=te(t)(n),i=ee(t)(n),u=ct(f=>r>=f.x&&r<f.x+f.w&&f.y+f.h>o&&f.y<i,e),s=y(f=>g=>ee(f)(g.x+g.w+4))(r+4)(u),a=y(f=>g=>te(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},S1=e=>t=>n=>r=>{const o=te(t)(n),i=ee(t)(n),u=ct(f=>r>=f.y&&r<f.y+f.h&&f.x+f.w>o&&f.x<i,e),s=y(f=>g=>ee(f)(g.y+g.h+4))(r+4)(u),a=y(f=>g=>te(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},P1=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);c()})(),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);c()})(),f=(b,L,S)=>!eo(t)(te(L)(S))(ee(L)(S))(b),g=(b,L,S)=>!eo(n)(te(L)(S))(ee(L)(S))(b),d=(b,L,S,z)=>e.tag==="Just"&&!yr(n)(te(b)(L))(ee(b)(L))(e._1)?e._1:b1(t)(b)(L)(S)(z),l=(b,L,S,z)=>{if(b===S){const j=C1(t)(L)(z)(b),G=L1(t)(b)(L)(z),P=k1(t)(b)(L)(z);return[{start:x(b,L),end:x(b,G),direction:Xt},{start:x(b,G),end:x(j,G),direction:Ot},{start:x(j,G),end:x(j,P),direction:Xt},{start:x(j,P),end:x(S,P),direction:Ot},{start:x(S,P),end:x(S,z),direction:Xt}]}const F=d(b,S,L,z);return[{start:x(b,L),end:x(b,F),direction:Xt},{start:x(b,F),end:x(S,F),direction:Ot},{start:x(S,F),end:x(S,z),direction:Xt}]},_=(b,L,S,z)=>{if(L===z){const j=S1(t)(b)(S)(L),G=w1(t)(L)(b)(S),P=E1(t)(L)(b)(S);return[{start:x(b,L),end:x(G,L),direction:Ot},{start:x(G,L),end:x(G,j),direction:Xt},{start:x(G,j),end:x(P,j),direction:Ot},{start:x(P,j),end:x(P,z),direction:Xt},{start:x(P,z),end:x(S,z),direction:Ot}]}const F=bs(t)(L)(z)(b)(S);return[{start:x(b,L),end:x(F,L),direction:Ot},{start:x(F,L),end:x(F,z),direction:Xt},{start:x(F,z),end:x(S,z),direction:Ot}]},h=(b,L,S)=>!yr(t)(te(L)(S))(ee(L)(S))(b),p=(b,L,S)=>!yr(n)(te(L)(S))(ee(L)(S))(b),m=(b,L,S,z)=>{if(p(L,b,S)&&g(S,L,z))return[{start:x(b,L),end:x(S,L),direction:Ot},{start:x(S,L),end:x(S,z),direction:Xt}];const F=bs(t)(L)(z)(b)(S);return[{start:x(b,L),end:x(F,L),direction:Ot},{start:x(F,L),end:x(F,z),direction:Xt},{start:x(F,z),end:x(S,z),direction:Ot}]},J=(b,L,S,z)=>{if(g(b,L,z)&&p(z,b,S))return[{start:x(b,L),end:x(b,z),direction:Xt},{start:x(b,z),end:x(S,z),direction:Ot}];const F=d(b,S,L,z);return[{start:x(b,L),end:x(b,F),direction:Xt},{start:x(b,F),end:x(S,F),direction:Ot},{start:x(S,F),end:x(S,z),direction:Xt}]},N=(()=>{if(r==="South")return i==="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:Xt}]: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&&f(s._1,s._2,a._2)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Xt}]: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:Ot}]:_(s._1,s._2,a._1,a._2):i==="North"||i==="South"?m(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:Ot}]:_(s._1,s._2,a._1,a._2);if(i==="North"||i==="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 Xt;if(r==="East"||r==="West")return Ot;c()})(),w={start:x(a._1,a._2),end:x(u._1,u._2),direction:(()=>{if(i==="South"||i==="North")return Xt;if(i==="East"||i==="West")return Ot;c()})()};return s._1===a._1&&s._2===a._2?[{start:x(o._1,o._2),end:x(u._1,u._2),direction:v}]:y1({start:x(o._1,o._2),end:x(s._1,s._2),direction:v})(N)(w)},G1=$(e=>({x:e.position._1*no-2,y:e.position._2*no-2,w:e.size._1*no+4,h:e.size._2*no+4})),Cs=jt(E)(zt),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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},D1=jt(E)(zt),Ss=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},W1=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=E.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=k("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=k("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=k("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=k("Just",i._4);continue}}c()}return o},M1=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Ps=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);c()},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};c()},Gs=e=>t=>y(n=>r=>vt(e)(ie)(t(r))([r])(n))(q),Ds=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;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()})(),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;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: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?q:Cs(o===1?$(i=>x(i,r))(t):Dt(i=>u=>x(u,e.lo+_t(i+1|0)*n/_t(o+1|0)))(t))},Ms=e=>t=>n=>r=>o=>{const i=Gs(E)(_=>_.to.node)(e),u=Gs(E)(_=>_.from.node)(e),s=y(_=>h=>Z(E)(h.node)(h)(_))(q)(t),a=(_,h,p)=>{const m=Oe(_)(s);if(m.tag==="Nothing")return x(0,0);if(m.tag==="Just"){const J=Oe(_)(n);if(J.tag==="Nothing"){const N=_t(4);if(p==="South")return x(m._1.position._1*N+m._1.size._1*N/2,(m._1.position._2+m._1.size._2)*N);if(p==="North")return x(m._1.position._1*N+m._1.size._1*N/2,m._1.position._2*N);if(p==="East")return x((m._1.position._1+m._1.size._1)*N,m._1.position._2*N+m._1.size._2*N/2);if(p==="West")return x(m._1.position._1*N,m._1.position._2*N+m._1.size._2*N/2);c()}if(J.tag==="Just"){const N=fe(v=>v.id===h)(J._1);if(N.tag==="Nothing"){const v=_t(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(N.tag==="Just"){const v=_t(4);if(N._1.side==="North")return x(m._1.position._1*v+_t(N._1.offset)*v,m._1.position._2*v);if(N._1.side==="South")return x(m._1.position._1*v+_t(N._1.offset)*v,(m._1.position._2+m._1.size._2)*v);if(N._1.side==="East")return x((m._1.position._1+m._1.size._1)*v,m._1.position._2*v+_t(N._1.offset)*v);if(N._1.side==="West")return x(m._1.position._1*v,m._1.position._2*v+_t(N._1.offset)*v)}}}c()},f=D1(St(r)(_=>{if(_.nodes.length<=2)return[];const h=_t(4);if(1<_.nodes.length){const p=Oe(_.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 $(J=>x(J,m))(pe(J=>N=>_.edgeId+":"+J+"->"+N,_.nodes,Wt(1,_.nodes.length,_.nodes)))}c()}return[]})),g=_=>{const h=Oe(_.from.node)(s),p=Oe(_.to.node)(s);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,J=p._1,N=xt(v=>w=>it.compare(v.score)(w.score))($(v=>{const w=v._1,b=v._2;return{from:w,to:b,score:(()=>{const L=(j,G,P,et,K)=>{const A=Ci(j)(G),H=Ci(j)(P);return A.lo<H.hi&&H.lo<A.hi&&(w==="South"?b==="North"&&K._2>et._2:w==="North"?b==="South"&&K._2<et._2:w==="East"?b==="West"&&K._1>et._1:w==="West"&&b==="East"&&K._1<et._1)?0:Ds(w)(b)(et)(K)},S=Ps(w)(m),z=Ps(b)(J),F=Ds(w)(b)(S)(z);return(()=>{if(F>0){if(w==="South")return b==="North"?L(se,m,J,S,z)*10|0:F*10|0;if(w==="North")return b==="South"?L(ue,m,J,S,z)*10|0:F*10|0;if(w==="East")return b==="West"?L(mn,m,J,S,z)*10|0:F*10|0;if(w==="West"&&b==="East")return L(yn,m,J,S,z)*10|0}return F*10|0})()+(w==="South"?b==="North"?0:15:w==="North"?b==="South"?0:15:w==="East"?b==="West"?5:15:w==="West"&&b==="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=Cs($(_=>x(_.id,g(_)))(e)),l=(_,h,p,m,J,N)=>{const v=_t(4),w=Oe(h)(s);if(w.tag==="Nothing")return x(0,0);if(w.tag==="Just"){const b=W1(x(p,_))(o);if(b.tag==="Just"){const L=w._1.position._1*v+b._1,S=_t(4);if(_==="South")return x(L,(w._1.position._2+w._1.size._2)*S);if(_==="North")return x(L,w._1.position._2*S);if(_==="East")return x((w._1.position._1+w._1.size._1)*S,L);if(_==="West")return x(w._1.position._1*S,L);c()}if(b.tag==="Nothing"){const L=Ci(_)(w._1),S=(L.lo+L.hi)/2,z=Ss(p)(Ws(L)($(G=>G.id)(xt(G=>P=>ht.compare(J(_)(G))(J(_)(P)))(ct(G=>{const P=Ss(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;c()},(()=>{const G=Oe(h)(m);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()))))),F=(()=>{if(z.tag==="Nothing")return S;if(z.tag==="Just")return z._1;c()})(),j=_t(4);if(_==="South")return x(F,(w._1.position._2+w._1.size._2)*j);if(_==="North")return x(F,w._1.position._2*j);if(_==="East")return x((w._1.position._1+w._1.size._1)*j,F);if(_==="West")return x(w._1.position._1*j,F)}}c()};return $(_=>{const h=M1(_.edge.id)(f);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};c()})($(_=>{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,p=>m=>{const J=Oe(m.to.node)(s);if(J.tag==="Nothing")return 0;if(J.tag==="Just"){const N=_t(4);if(p==="South"||p==="North")return J._1.position._1*N+J._1.size._1*N/2;if(p==="East"||p==="West")return J._1.position._2*N+J._1.size._2*N/2}c()},p=>p.from),toPos:l(h.to,_.to.node,_.id,i,p=>m=>{const J=Oe(m.from.node)(s);if(J.tag==="Nothing")return 0;if(J.tag==="Just"){const N=_t(4);if(p==="South"||p==="North")return J._1.position._1*N+J._1.size._1*N/2;if(p==="East"||p==="West")return J._1.position._2*N+J._1.size._2*N/2}c()},p=>p.to),fromSide:h.from,toSide:h.to}})(e))},Rs=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},R1=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),Si=e=>t=>e.gapTop+1*_t(4)+_t(t)*2.5*_t(4),I1=e=>t=>{const n=Rs(t.edge.id)(e);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return k("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;c()}if(n.tag==="Nothing")return T;c()},z1=e=>t=>{const n=y(r=>o=>Z(E)(o.node)(o)(r))(q)(t);return Ne(Dt(r=>o=>{const i=qn(o.node)(n);if(i.tag==="Nothing")return[];if(i.tag==="Just"){const u=i._1;return Dt(s=>a=>{const f=o.edges.length,g=_t(4),d=u.position._1*g,l=u.position._2*g,_=u.size._2*g,h=_t((2*f|0)+1|0),p=l+_*_t(f-s|0)/h,m=l+_*_t((f+1|0)+s|0)/h,J=d-g*2.5*_t(s+1|0),N=[{start:x(d,p),end:x(J,p),direction:Ot},{start:x(J,p),end:x(J,m),direction:Xt},{start:x(J,m),end:x(d,m),direction:Ot}];return{edge:a.id,segments:N,bends:pe(v=>w=>v.end,N,Wt(1,3,N)),bendType:[],jumps:[],reversed:!1}})(o.edges)}c()})($(r=>({node:r._1,edges:r._2}))(R1(y(r=>o=>vt(E)(ie)(o.from.node)([o])(r))(q)(e)))))},B1=e=>t=>{const n=y(i=>u=>Z(E)(u.node)(u)(i))(q)(t),r=i=>{const u=qn(i)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.position._1;c()},o=i=>{const u=qn(i)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.layer;c()};return xt(i=>u=>{const s=it.compare(o(i.edge.from.node))(o(u.edge.from.node));if(s==="EQ"){const a=ht.compare(r(i.edge.from.node))(r(u.edge.from.node));return a==="EQ"?ht.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}},A1=e=>e.from.node===e.to.node,Q1=e=>t=>n=>r=>{const o=T1(n)(P1(e)(t)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:o,bends:pe(i=>u=>i.end,o,Wt(1,o.length,o)),bendType:[],jumps:[],reversed:!1}},q1=e=>t=>n=>r=>{const o=[{start:x(r.fromPos._1,r.fromPos._2),end:x(r.fromPos._1,e.slot1Y),direction:Xt},{start:x(r.fromPos._1,e.slot1Y),end:x(e.splitX,e.slot1Y),direction:Ot},{start:x(e.splitX,e.slot1Y),end:x(e.splitX,e.slot2Y),direction:Xt},{start:x(e.splitX,e.slot2Y),end:x(r.toPos._1,e.slot2Y),direction:Ot},{start:x(r.toPos._1,e.slot2Y),end:x(r.toPos._1,r.toPos._2),direction:Xt}];return{edge:r.edge.id,segments:o,bends:pe(i=>u=>i.end,o,Wt(1,5,o)),bendType:[],jumps:[],reversed:!1}},H1=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"?ct(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):ct(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"?ct(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):ct(i=>!0,t)},V1=e=>t=>{const n=Rs(t.edge.id)(e);if(n.tag==="Just")return k("Just",Si(n._1)(n._1.slot));if(n.tag==="Nothing")return T;c()},Y1=e=>t=>n=>r=>o=>{const i=y(f=>g=>Z(E)(g.node)(g)(f))(q)(t),u=G1(t),s=Ms(ct(f=>f.from.node!==f.to.node,e))(t)(n)(r)(o),a=Ts(s)(t);return[...z1(ct(A1,e))(t),...y(f=>g=>{const d=H1(g)(u)(i),l=[...d,...f.edgeObstacles],_=I1(a)(g),h=(()=>{if(_.tag==="Just")return q1(_._1)(d)(l)(g);if(_.tag==="Nothing")return Q1(V1(a)(g))(d)(l)(g);c()})();return{results:[...f.results,h],edgeObstacles:[...f.edgeObstacles,...m1(h.segments)]}})({results:[],edgeObstacles:[]})(B1(s)(t)).results]},an=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},cn=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},F1=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?k("Just",{position:x(e.start._1,(r+o)/2),crossingEdge:n}):T},$1=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?k("Just",{position:x((r+o)/2,e.start._2),crossingEdge:n}):T},O1=e=>t=>n=>{if(e.direction==="H")return $1(e)(t)(n);if(e.direction==="V")return F1(e)(t)(n);c()},X1=e=>t=>n=>{const r=e+1|0,o=r<1?n:Wt(r,n.length,n);return St(t.segments)(i=>St(o)(u=>bt(s=>O1(i)(s)(u.edge))(ct(s=>s.direction==="H"?i.direction==="H":s.direction==="V"&&i.direction==="V",u.segments))))},U1=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)?k("Just",{position:x(t.start._1,e.start._2),crossingEdge:n}):T,K1=e=>t=>St(ct(n=>n.direction==="H",e.segments))(n=>St(t)(r=>bt(o=>U1(n)(o)(r.edge))(ct(o=>o.direction==="V",r.segments)))),Z1=e=>t=>n=>[...K1(t)(ct(r=>r.edge!==t.edge,n)),...X1(e)(t)(n)],ro=(()=>{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=E.compare(t._1)(n._1);if(r==="LT")return Re;if(r==="GT")return Ie;if(t._2==="North")return n._2==="North"?Ve:Re;if(n._2==="North")return Ie;if(t._2==="South")return n._2==="South"?Ve:Re;if(n._2==="South")return Ie;if(t._2==="East")return n._2==="East"?Ve:Re;if(n._2==="East")return Ie;if(t._2==="West"&&n._2==="West")return Ve;c()},Eq0:()=>e}})(),j1=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=ro.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},td=jt(E)(zt),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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},ed=jt(ro)(zt),Is=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),Hn=e=>t=>n=>r=>{const o=j1(x(t,n))(e);if(o.tag==="Nothing")return r;if(o.tag==="Just")return o._1;c()},zs=e=>t=>n=>{const r=td(Ne($(u=>Dt(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;c()}if(u==="North"){const a=Pi(s.from.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()}return 0},i=u=>y(s=>a=>ye(ro.compare,he,ed($(f=>x(x(f._1,u),f._2))(Is(Ws({lo:0,hi:(()=>{const f=Pi(a._1)(n);if(f.tag==="Just")return f._1._1;if(f.tag==="Nothing")return oe(3)(a._1)==="$d:"?0:1;c()})()})($(f=>f.id)(xt(f=>g=>it.compare(o(u,f))(o(u,g)))(a._2)))))),s))(q)(Is(y(s=>a=>a.from.node===a.to.node?s:u==="South"?vt(E)(ie)(a.from.node)([a])(s):u==="North"?vt(E)(ie)(a.to.node)([a])(s):s)(q)(t)));return ye(ro.compare,he,i(ue),i(se))},Bs=e=>e,As=e=>e,Qs=e=>e,nd=y(e=>t=>Z(E)(t)()(e))(q),rd=(()=>{const e=Pe.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return k("Just",x(t._1,t._2));c()});return t=>e((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._3,n(r._6,o)));c()};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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Le=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Be=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},be=jt(E)(zt),Gi=Vf(E),Jr=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),qs=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=E.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}}c()}return o},od=e=>t=>{const n=it.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},id=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=it.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Hs=Qs("VDown"),Vs=Qs("VUp"),ud=As("ForwardPhase"),sd=As("StackPhase"),Ys=Bs("HRight"),Fs=Bs("HLeft"),ad=e=>t=>n=>{const r=y(u=>s=>vt(E)(Ut)(s.tgt)(1)(u))(q)(e),o=rd(nd([...$(u=>u.src)(e),...$(u=>u.tgt)(e),...(()=>{const u=(s,a)=>{if(s.tag==="Leaf")return a;if(s.tag==="Node")return u(s._5,It("Cons",s._4,u(s._6,a)));c()};return wt(qt.foldr,u(t,Bt))})()])),i=y(u=>s=>vt(E)(ie)(s.src)([{target:s.tgt,sep:s.sep}])(u))(q)(e);return(u=>s=>a=>{let f=u,g=s,d=a,l=!0,_;for(;l;){const h=f,p=g,m=d,J=Vt(N=>T,N=>v=>k("Just",{head:N,tail:v}),h);if(J.tag==="Nothing"){l=!1,_=m;continue}if(J.tag==="Just"){const N=tt(J._1.head)(m),v=(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})(),w=y(b=>L=>{const S=tt(L.target)(b.result),z=v+L.sep,F=tt(L.target)(b.indeg),j=(()=>{if(F.tag==="Nothing")return-1;if(F.tag==="Just")return F._1-1|0;c()})();return{newQueue:j===0?[...b.newQueue,L.target]:b.newQueue,result:Z(E)(L.target)((()=>{if(S.tag==="Nothing")return z;if(S.tag==="Just"){if(n==="VDown")return Le(S._1)(z);if(n==="VUp")return Be(S._1)(z)}c()})())(b.result),indeg:Z(E)(L.target)(j)(b.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const b=tt(J._1.head)(i);if(b.tag==="Nothing")return[];if(b.tag==="Just")return b._1;c()})());f=[...J._1.tail,...w.newQueue],g=w.indeg,d=w.result;continue}c()}return _})(ct(u=>{const s=tt(u)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;c()},o))(q)(y(u=>s=>Z(E)(s)(0)(u))(q)(o))},cd=e=>{const t=(i,u)=>{if(i.tag==="Leaf")return u;if(i.tag==="Node")return t(i._5,It("Cons",i._4,t(i._6,u)));c()},n=wt(qt.foldr,t(e,Bt)),r=y(Le)(999999)(n);if(r===0||n.length===0)return e;const o=i=>{if(i.tag==="Leaf")return q;if(i.tag==="Node")return $t("Node",i._1,i._2,i._3,i._4-r,o(i._5),o(i._6));c()};return o(e)},fd=e=>t=>{const n=(o,i,u)=>oe(3)(i)==="$d:"&&Su(s=>oe(3)(s)==="$d:",(()=>{const s=tt(i)(e.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;c()})()),r=o=>i=>u=>s=>a=>f=>g=>{let d=o,l=i,_=s,h=f,p=g,m=!0,J;for(;m;){const N=d,v=l,w=_,b=h,L=p,S=v.length;if(L>=S){m=!1,J=N;continue}const z=L>=0&&L<v.length?k("Just",v[L]):T,F=(()=>{if(z.tag==="Nothing")return"";if(z.tag==="Just")return z._1;c()})(),j=n(e,F);if(L===(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;c()})();if(0<et.length){const K=w-1|0,A=tt(et[0])(e.nodeIndex);if(A.tag==="Nothing")return K;if(A.tag==="Just")return A._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(A=>H=>{const R=tt(H)(e.nodeIndex),C=(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;c()})();return C<b||C>G?Z(E)(H+"\u2192"+K)()(A):A})(P)((()=>{const A=tt(K)(e.preds);if(A.tag==="Nothing")return[];if(A.tag==="Just")return A._1;c()})())}return n(e,"")?P:y(K=>A=>{const H=tt(A)(e.nodeIndex),R=(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;c()})();return R<b||R>G?Z(E)(A+"\u2192")()(K):K})(P)((()=>{const K=tt("")(e.preds);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;c()})())})(N)(Ht(0,L)),l=v,_=w,h=G,p=L+1|0;continue}d=N,l=v,_=w,h=b,p=L+1|0}return J};return t.length<3?q: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)})(q)(Ht(1,t.length-2|0))},$s=e=>{const t=(i,u)=>{if(i.tag==="Leaf")return u;if(i.tag==="Node")return t(i._5,It("Cons",i._4,t(i._6,u)));c()},n=t(e,Bt),r=i=>u=>{let s=i,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=Be(d)(l._1),a=l._2;continue}c()}return g},o=i=>u=>{let s=i,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)-o(999999)(n)},Nr=e=>t=>(n=>r=>{let o=n,i=r,u=!0,s;for(;u;){const a=o,f=i;if(a===t){u=!1,s=f;continue}o=(()=>{const g=tt(a)(e.align);if(g.tag==="Nothing")return t;if(g.tag==="Just")return g._1;c()})(),i=[...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]),gd=e=>t=>n=>r=>o=>i=>u=>s=>a=>f=>g=>{const d=(C,D,W)=>{const M=C.from.node===D?C.from.port:C.to.node===D?C.to.port:T;if(M.tag==="Just"){const Y=tt(D)(o);if(Y.tag==="Just"){const X=fe(V=>V.id===M._1)(Y._1);if(X.tag==="Just"){const V=_t(X._1.offset)*_t(4);return W==="North"||W==="South"?V:0}if(X.tag==="Nothing"){const V=tt(D)(r),Q=Hn(u)(C.id)(W)((()=>{if(V.tag==="Nothing")return .5;if(V.tag==="Just")return V._1._1/2;c()})());return W==="North"||W==="South"?Q:0}c()}if(Y.tag==="Nothing"){const X=tt(D)(r),V=Hn(u)(C.id)(W)((()=>{if(X.tag==="Nothing")return .5;if(X.tag==="Just")return X._1._1/2;c()})());return W==="North"||W==="South"?V:0}c()}if(M.tag==="Nothing"){const Y=tt(D)(r),X=Hn(u)(C.id)(W)((()=>{if(Y.tag==="Nothing")return .5;if(Y.tag==="Just")return Y._1._1/2;c()})());return W==="North"||W==="South"?X:0}c()},l=(C,D)=>{if(C.from.node===D){if(g==="HRight")return se;if(g==="HLeft")return ue;c()}if(g==="HRight")return ue;if(g==="HLeft")return se;c()},_=(C,D,W)=>y(M=>Y=>Z(E)(Y)((()=>{const X=tt(Y)(M);if(X.tag==="Nothing")return 0+D;if(X.tag==="Just")return X._1+D;c()})())(M))(W)(Nr(a)(C)),h=(()=>{if(g==="HRight")return n;if(g==="HLeft")return _e(n);c()})(),p=C=>{const D=tt(C)(r);if(D.tag==="Nothing")return 1;if(D.tag==="Just")return D._1._1;c()},m=be(Ne(Dt(C=>D=>$(W=>x(W,C))(D))(n))),J=(C,D)=>oe(3)(C)==="$d:"&&oe(3)(D)==="$d:"||oe(3)(C)==="$d:"||oe(3)(D)==="$d:"?10:_t(e.nodeGap),N=y(C=>D=>Gi(W=>k("Just",[...(()=>{if(W.tag==="Nothing")return[];if(W.tag==="Just")return W._1;c()})(),D]))(D.to.node)(C))(q)(i),v=y(C=>D=>Gi(W=>k("Just",[...(()=>{if(W.tag==="Nothing")return[];if(W.tag==="Just")return W._1;c()})(),D]))(D.from.node)(C))(q)(i),w=Ne(n),b=y(C=>D=>{const W=tt(D)(a.root),M=(()=>{if(W.tag==="Nothing")return D;if(W.tag==="Just")return W._1;c()})();return D===M?C:Gi(Y=>k("Just",(()=>{if(Y.tag==="Nothing")return!0;if(Y.tag==="Just")return Y._1;c()})()&&oe(3)(D)==="$d:"))(M)(C)})(be($(C=>x(C,!0))(Pn(E.compare)((()=>{const C=(D,W)=>{if(D.tag==="Leaf")return W;if(D.tag==="Node")return C(D._5,It("Cons",D._4,C(D._6,W)));c()};return wt(qt.foldr,C(a.root,Bt))})()))))(w),L=(C,D)=>{const W=C.free,M=tt(W)(a.root),Y=(()=>{if(M.tag==="Nothing")return W;if(M.tag==="Just")return M._1;c()})(),X=tt(Y)(b),V=(()=>{if(X.tag==="Nothing")return!0;if(X.tag==="Just")return X._1;c()})();return y(Q=>I=>{if(Q.edge.tag==="Just")return Q;if(Q.edge.tag==="Nothing"){if((()=>{const at=tt(Y)(D.su);return!V&&(()=>{const lt=tt(I.from.node)(m);return I.from.node!==I.to.node&&(()=>{const Tt=tt(I.to.node)(m);return(()=>{if(lt.tag==="Nothing")return-1;if(lt.tag==="Just")return lt._1;c()})()===(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._1;c()})()})()})()||(()=>{if(at.tag==="Nothing")return!1;if(at.tag==="Just")return at._1;c()})()})())return Q;const U=I.from.node===W?I.to.node:I.from.node,O=tt(U)(a.root),gt=(()=>{if(O.tag==="Nothing")return U;if(O.tag==="Just")return O._1;c()})(),pt=gt!==Y;return pt&&(()=>{const at=tt(gt)(D.blockFinished);if(at.tag==="Nothing")return!1;if(at.tag==="Just")return at._1;c()})()?{...Q,edge:k("Just",I),hasEdges:!0}:{...Q,hasEdges:Q.hasEdges||pt}}c()})({edge:T,hasEdges:!1})((()=>{if(C.isRoot){if(g==="HRight"){const Q=tt(W)(N);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()}if(g==="HLeft"){const Q=tt(W)(v);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1}c()}if(g==="HRight"){const Q=tt(W)(v);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()}if(g==="HLeft"){const Q=tt(W)(N);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1}c()})())},S=(C,D,W,M)=>{const Y=(()=>{if(f==="VDown")return-1e18;if(f==="VUp")return 1e18;c()})(),X={free:D,isRoot:W},V=L(X,M);if(V.edge.tag==="Nothing")return V.hasEdges?{thresh:Y,state:{...M,queue:[...M.queue,X]}}:{thresh:Y,state:M};if(V.edge.tag==="Just"){const Q=V.edge._1.from.node===D?V.edge._1.to.node:V.edge._1.from.node;return{thresh:(()=>{const I=tt((()=>{const pt=tt(Q)(a.root);if(pt.tag==="Nothing")return Q;if(pt.tag==="Just")return pt._1;c()})())(M.x),U=tt(Q)(s),O=tt(D)(s),gt=(()=>{if(I.tag==="Just")return I._1;if(I.tag==="Nothing")return T;c()})();return(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;c()})()+(()=>{if(U.tag==="Nothing")return 0;if(U.tag==="Just")return U._1;c()})()+d(V.edge._1,Q,(()=>{if(W){if(g==="HRight")return se;if(g==="HLeft")return ue;c()}if(g==="HRight")return ue;if(g==="HLeft")return se;c()})())-(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;c()})()-d(V.edge._1,D,(()=>{if(W){if(g==="HRight")return ue;if(g==="HLeft")return se;c()}if(g==="HRight")return se;if(g==="HLeft")return ue;c()})())})(),state:{...M,su:Z(E)((()=>{const I=tt(V.edge._1.from.node)(a.root);if(I.tag==="Nothing")return V.edge._1.from.node;if(I.tag==="Just")return I._1;c()})())(!0)(Z(E)((()=>{const I=tt(V.edge._1.to.node)(a.root);if(I.tag==="Nothing")return V.edge._1.to.node;if(I.tag==="Just")return I._1;c()})())(!0)(M.su))}}}c()},z=(C,D,W,M)=>{const Y=D===C,X=tt(D)(a.align),V=(()=>{if(X.tag==="Nothing")return D===C;if(X.tag==="Just")return X._1===C;c()})();if(!(Y||V))return{thresh:W,state:M};const Q=(()=>{if(f==="VDown")return Y&&W<=-1e18;if(f==="VUp")return Y&&W>=1e18;c()})()?S(C,D,!0,M):{thresh:W,state:M};return(()=>{if(f==="VDown")return Q.thresh<=-1e18&&V;if(f==="VUp")return Q.thresh>=1e18&&V;c()})()?S(C,D,!1,Q.state):Q},F=C=>D=>W=>{const M=tt(W)(t.nodeIndex),Y=(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;c()})(),X=fe(O=>ze(Ye)(W)(O))(h),V=(()=>{if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;c()})(),Q=V.length;if((()=>{if(f==="VDown")return Y<=0;if(f==="VUp")return Y>=(Q-1|0);c()})()){const O=z(C,W,D.thresh,D.st);return{...D,st:O.state,thresh:O.thresh}}const I=(()=>{if(f==="VDown")return Y-1|0;if(f==="VUp")return Y+1|0;c()})(),U=I>=0&&I<V.length?k("Just",V[I]):T;if(U.tag==="Nothing")return D;if(U.tag==="Just"){const O=tt(U._1)(a.root),gt=(()=>{if(O.tag==="Nothing")return U._1;if(O.tag==="Just")return O._1;c()})(),pt=z(C,W,D.thresh,j(gt)(D.st)),at=(()=>{const ne=tt(C)(pt.state.sink);if(ne.tag==="Nothing")return C===C;if(ne.tag==="Just")return ne._1===C;c()})()?{...pt.state,sink:Z(E)(C)((()=>{const ne=tt(gt)(pt.state.sink);if(ne.tag==="Nothing")return gt;if(ne.tag==="Just")return ne._1;c()})())(pt.state.sink)}:pt.state,lt=tt(gt)(at.sink),Tt=(()=>{if(lt.tag==="Nothing")return gt;if(lt.tag==="Just")return lt._1;c()})(),Gt=tt(C)(at.sink),dt=(()=>{if(Gt.tag==="Nothing")return C;if(Gt.tag==="Just")return Gt._1;c()})();if(dt===Tt){const ne=tt(gt)(at.x),He=(()=>{if(ne.tag==="Just")return ne._1;if(ne.tag==="Nothing")return T;c()})(),Un=(()=>{if(He.tag==="Nothing")return 0;if(He.tag==="Just")return He._1;c()})(),nn=tt(C)(at.x),kt=(()=>{if(nn.tag==="Just")return nn._1;if(nn.tag==="Nothing")return T;c()})(),Pt=(()=>{if(kt.tag==="Nothing")return 0;if(kt.tag==="Just")return kt._1;c()})(),Kn=J(W,U._1),En=tt(U._1)(s),kn=tt(W)(s),Zn=(()=>{if(En.tag==="Nothing")return 0;if(En.tag==="Just")return En._1;c()})()-(()=>{if(kn.tag==="Nothing")return 0;if(kn.tag==="Just")return kn._1;c()})();if(f==="VDown"){const Me=Be(Un+Zn+p(U._1)+Kn)(pt.thresh);return{st:{...at,x:Z(E)(C)(k("Just",D.initial?Me:Be(Pt)(Me)))(at.x)},initial:!1,thresh:pt.thresh}}if(f==="VUp"){const Me=Le(Un+Zn-Kn-p(W))(pt.thresh);return{st:{...at,x:Z(E)(C)(k("Just",D.initial?Me:Le(Pt)(Me)))(at.x)},initial:!1,thresh:pt.thresh}}c()}const Mt=tt(gt)(at.x),mt=(()=>{if(Mt.tag==="Just")return Mt._1;if(Mt.tag==="Nothing")return T;c()})(),ft=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})(),rt=tt(C)(at.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=_t(e.nodeGap),Jt=tt(W)(s),Ct=tt(U._1)(s),Qt=(()=>{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:{...at,classEdges:[...at.classEdges,{src:dt,tgt:Tt,sep:(()=>{if(f==="VDown")return st+Qt-ft-p(U._1)-yt;if(f==="VUp")return st+Qt+p(W)+yt-ft;c()})()}]},initial:D.initial,thresh:pt.thresh}}c()},j=C=>D=>{const W=tt(C)(D.x),M=(()=>{if(W.tag==="Just")return W._1;if(W.tag==="Nothing")return T;c()})();if(M.tag==="Just")return D;if(M.tag==="Nothing"){const Y=y(F(C))({st:{...D,x:Z(E)(C)(k("Just",0))(D.x)},initial:!0,thresh:(()=>{if(f==="VDown")return-1e18;if(f==="VUp")return 1e18;c()})()})(Nr(a)(C));return{...Y.st,blockFinished:Z(E)(C)(!0)(Y.st.blockFinished)}}c()},G=y(C=>D=>y(W=>M=>{const Y=tt(M)(a.root),X=(()=>{if(Y.tag==="Nothing")return M;if(Y.tag==="Just")return Y._1;c()})();return X===M?j(X)(W):W})(C)((()=>{if(f==="VDown")return D;if(f==="VUp")return _e(D);c()})()))({x:be($(C=>x(C,T))(w)),sink:be($(C=>x(C,C))(w)),classEdges:[],su:q,blockFinished:q,queue:[]})(h),P=ad(G.classEdges)(G.sink)(f),et=(C,D,W,M)=>{const Y=tt(D)(M),X=tt(D)(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,D,W)},K=be($(C=>x(C,!0))(Pn(E.compare)((()=>{const C=(D,W)=>{if(D.tag==="Leaf")return W;if(D.tag==="Node")return C(D._5,It("Cons",D._4,C(D._6,W)));c()};return wt(qt.foldr,C(a.root,Bt))})()))),A=C=>D=>W=>{const M=L(W,{su:D.su,blockFinished:K}),Y={phase:C,ppFree:W.free,ppIsRoot:W.isRoot,edgeId:T,delta:0,avail:0,shift:0,freeSu:(()=>{const X=tt((()=>{const V=tt(W.free)(a.root);if(V.tag==="Nothing")return W.free;if(V.tag==="Just")return V._1;c()})())(D.su);if(X.tag==="Nothing")return!1;if(X.tag==="Just")return X._1;c()})(),hasEdges:M.hasEdges,candCount:(()=>{if(W.isRoot){if(g==="HRight"){const X=tt(W.free)(N);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length;c()}if(g==="HLeft"){const X=tt(W.free)(v);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length}c()}if(g==="HRight"){const X=tt(W.free)(v);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length;c()}if(g==="HLeft"){const X=tt(W.free)(N);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length}c()})()};if(M.edge.tag==="Nothing")return{...D,stack:[...D.stack,W],trace:[...D.trace,Y],x:D.x};if(M.edge.tag==="Just"){const X=M.edge._1.from.node===W.free?x(M.edge._1.from.node,M.edge._1.to.node):x(M.edge._1.to.node,M.edge._1.from.node),V=et(M.edge._1,X._1,l(M.edge._1,X._1),D.x)-et(M.edge._1,X._2,l(M.edge._1,X._2),D.x),Q=tt(X._1)(a.root),I=(()=>{if(Q.tag==="Nothing")return X._1;if(Q.tag==="Just")return Q._1;c()})(),U={...Y,edgeId:k("Just",M.edge._1.id),delta:V};if(V>0&&V<1e300){const O=y(at=>lt=>{const Tt=tt(lt)(m),Gt=(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._1;c()})();if(Gt>=0&&Gt<n.length){const mt=n[Gt],ft=tt(lt)(t.nodeIndex),rt=(()=>{if(ft.tag==="Nothing")return-2;if(ft.tag==="Just")return ft._1-1|0;c()})();return rt>=0&&rt<mt.length?Le(at)((()=>{const nt=tt(lt)(D.x),st=tt(lt)(s),yt=tt(mt[rt])(D.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])+J(lt,mt[rt]))})()):at}const dt=tt(lt)(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(at)((()=>{const mt=tt(lt)(D.x),ft=tt(lt)(s),rt=tt([][Mt])(D.x),nt=tt([][Mt])(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})()+(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._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])+J(lt,[][Mt]))})()):at})(V)(Nr(a)(I)),gt=O>0?-O:0,pt={...D,x:O>0?_(I,gt,D.x):D.x,trace:[...D.trace,{...U,avail:O,shift:gt}]};return O>0?pt:{...pt,stack:[...pt.stack,W]}}if(V<0&&-V<1e300){const O=y(at=>lt=>{const Tt=tt(lt)(m),Gt=(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._1;c()})();if(Gt>=0&&Gt<n.length){const mt=n[Gt],ft=tt(lt)(t.nodeIndex),rt=(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1+1|0;c()})();return rt>=0&&rt<mt.length?Le(at)((()=>{const nt=tt(mt[rt])(D.x),st=tt(mt[rt])(s),yt=tt(lt)(D.x),Jt=tt(lt)(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(lt)+J(lt,mt[rt]))})()):at}const dt=tt(lt)(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(at)((()=>{const mt=tt([][Mt])(D.x),ft=tt([][Mt])(s),rt=tt(lt)(D.x),nt=tt(lt)(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})()+(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._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(lt)+J(lt,[][Mt]))})()):at})(-V)(Nr(a)(I)),gt=O>0?O:0,pt={...D,x:O>0?_(I,gt,D.x):D.x,trace:[...D.trace,{...U,avail:O,shift:gt}]};return O>0?pt:{...pt,stack:[...pt.stack,W]}}return{...D,stack:[...D.stack,W],trace:[...D.trace,U],x:D.x}}c()},H=y(A(ud))({x:be($(C=>x(C,(()=>{const D=tt(C)(a.root),W=(()=>{if(D.tag==="Nothing")return C;if(D.tag==="Just")return D._1;c()})(),M=tt(W)(G.x),Y=tt((()=>{const V=tt(W)(G.sink);if(V.tag==="Nothing")return W;if(V.tag==="Just")return V._1;c()})())(P),X=(()=>{if(M.tag==="Just")return M._1;if(M.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:G.su,stack:[],trace:[]})(G.queue),R=y(A(sd))({...H,stack:[]})(_e(H.stack));return{x:R.x,queue:G.queue,trace:R.trace}},_d=e=>t=>n=>r=>o=>i=>u=>s=>a=>f=>g=>gd(e)(t)(n)(r)(o)(i)(u)(s)(a)(f)(g).x,dd=e=>t=>n=>r=>o=>i=>{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=fe(m=>m.id===_._1)(h._1);if(p.tag==="Just"){const m=_t(p._1.offset)*_t(4);return g==="North"||g==="South"?m:0}if(p.tag==="Nothing"){const m=Hn(o)(a.id)(g)(l);return g==="North"||g==="South"?m:0}c()}if(h.tag==="Nothing"){const p=Hn(o)(a.id)(g)(l);return g==="North"||g==="South"?p:0}c()}if(_.tag==="Nothing"){const h=Hn(o)(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,J;for(;m;){const N=l,v=_,w=h,b=Vt(L=>T,L=>S=>k("Just",{head:L,tail:S}),p);if(b.tag==="Nothing"){m=!1,J=N;continue}if(b.tag==="Just"){const L=b._1.head,S=fe(F=>F.from.node===w&&F.to.node===L||F.from.node===L&&F.to.node===w)(r),z=(()=>{if(S.tag==="Nothing")return v+0;if(S.tag==="Just")return v+(u(S._1,w,S._1.from.node===w?se:ue)-u(S._1,L,S._1.from.node===L?se:ue));c()})();l=Z(E)(L)(z)(N),_=z,h=L,p=b._1.tail;continue}c()}return J};return y(a=>f=>{const g=Vt(_=>T,_=>h=>k("Just",{head:_,tail:h}),Nr(e)(f)),d=(()=>{if(g.tag==="Nothing")return Z(E)(f)(0)(q);if(g.tag==="Just")return s(Z(E)(g._1.head)(0)(q))(0)(g._1.head)(g._1.tail);c()})(),l=y(_=>h=>Be(_)(-h._2))(0)(Jr(d));return y(_=>h=>Z(E)(h._1)(h._2+l)(_))(a)(Jr(d))})(q)(Pn(E.compare)((()=>{const a=(f,g)=>{if(f.tag==="Leaf")return g;if(f.tag==="Node")return a(f._5,It("Cons",f._4,a(f._6,g)));c()};return wt(qt.foldr,a(e.root,Bt))})()))},ld=e=>t=>n=>r=>o=>{const i=Ne(t),u=y(s=>a=>{const f=y(g=>d=>{const l=(()=>{if(o==="HRight"){const m=tt(d)(e.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;c()}if(o==="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=bn(_-1|0,2),p=bn(_,2);return y(m=>J=>{if((()=>{const N=tt(d)(m.align);if(N.tag==="Nothing")return d!==d;if(N.tag==="Just")return N._1!==d;c()})())return m;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;c()})();if(!(qs(l[J]+"\u2192"+d)(n)||qs(d+"\u2192"+l[J])(n))&&(()=>{if(r==="VDown")return m.r<v;if(r==="VUp")return m.r>v;c()})()){const w=tt(l[J])(m.root),b=(()=>{if(w.tag==="Nothing")return l[J];if(w.tag==="Just")return w._1;c()})();return{root:Z(E)(d)(b)(m.root),align:Z(E)(l[J])(d)(Z(E)(d)(b)(m.align)),r:v}}}return m})(g)((()=>{if(r==="VDown")return Ht(h,p);if(r==="VUp")return _e(Ht(h,p));c()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;c()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return _e(a);c()})());return{root:f.root,align:f.align}})({root:be($(s=>x(s,s))(i)),align:be($(s=>x(s,s))(i))})((()=>{if(o==="HRight")return t;if(o==="HLeft")return _e(t);c()})());return{root:u.root,align:u.align}},oo=e=>t=>n=>r=>o=>i=>u=>s=>a=>f=>{const g=ld(t)(n)(s)(a)(f),d=dd(g)(o)(r)(i)(u)(f);return Hf()(l=>_=>k("Just",(()=>{const h=tt(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;c()})()))(_d(e)(t)(n)(r)(o)(i)(u)(d)(g)(a)(f))},Os=e=>t=>Dt(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=Ht(0,t.length-1|0);return n<1?[]:Wt(0,n,o)})()))(t),hd=e=>t=>n=>r=>o=>i=>u=>{const s=od(0)(t.length-1|0),a=_t(e.layerGap),f=u(kf(s,a)),g=p1(Ms(o)(f)(r)(i)(q))(f);return $(d=>{const l=id(d)(g);return l.tag==="Just"&&l._1>0?Be(a)(2+_t(l._1-1|0)*2.5):a})(Ht(0,s-1|0))},Xs=e=>t=>n=>r=>Su(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;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>i.pos&&g+1e-4>i.pos?{ok:!0,pos:g}:{ok:!1,pos:i.pos}})({ok:!0,pos:-1e18})(o).ok,t),pd=e=>t=>n=>r=>{const o=xt(i=>u=>ht.compare(i.w)(u.w))($(i=>({l:i,w:$s(i)}))(ct(Xs()(t)(n),r)));return 0<o.length?k("Just",o[0].l):T},md=e=>t=>{const n=be(Ne($(Dt(o=>i=>x(i,o)))(e))),r=o=>xt(i=>u=>it.compare((()=>{const s=tt(i)(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()})()))(o);return{preds:(()=>{const o=i=>{if(i.tag==="Leaf")return q;if(i.tag==="Node")return $t("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));c()};return o(y(i=>u=>vt(E)(ie)(u.to.node)([u.from.node])(i))(q)(t))})(),succs:(()=>{const o=i=>{if(i.tag==="Leaf")return q;if(i.tag==="Node")return $t("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));c()};return o(y(i=>u=>vt(E)(ie)(u.from.node)([u.to.node])(i))(q)(t))})(),nodeIndex:n}},yd=e=>t=>{const n=xt(d=>l=>ht.compare(d.w)(l.w))(Dt(d=>l=>({i:d,l,w:$s(l)}))(t)),r=0<n.length?k("Just",n[0]):T,o=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;c()})(),i=o>=0&&o<t.length?k("Just",t[o]):T,u=(()=>{if(i.tag==="Just")return(d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const J=_,N=h;if(N.tag==="Nil"){p=!1,m=J;continue}if(N.tag==="Cons"){_=Le(J)(N._1),h=N._2;continue}c()}return m})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,It("Cons",l._4,d(l._6,_)));c()};return d(i._1,Bt)})());if(i.tag==="Nothing")return 0;c()})(),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;c()})()))(-999999)(Jr(d)),a=o>=0&&o<t.length?k("Just",t[o]):T,f=(()=>{if(a.tag==="Just")return s(a._1);if(a.tag==="Nothing")return 0;c()})(),g=pe(d=>l=>{const _=h=>{if(h.tag==="Leaf")return q;if(h.tag==="Node")return $t("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));c()};return _(d)},t,Dt(d=>l=>Po(d)(2)===0?u-(_=>h=>{let p=_,m=h,J=!0,N;for(;J;){const v=p,w=m;if(w.tag==="Nil"){J=!1,N=v;continue}if(w.tag==="Cons"){p=Le(v)(w._1),m=w._2;continue}c()}return N})(999999)((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,It("Cons",h._4,_(h._6,p)));c()};return _(l,Bt)})()):f-s(l))(t));return cd(y(d=>l=>{const _=xt(ht.compare)(bt(tt(l))(g));return Z(E)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(q)(Pn(E.compare)(Ne($(d=>{const l=_=>{if(_.tag==="Leaf")return q;if(_.tag==="Node")return $t("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));c()};return wt(we.foldr,l(d))})(g)))))},Jd=e=>t=>n=>r=>o=>i=>{const u=md(t)(o),s=fd(u)(t),a={nodeGap:e.nodeGap*4|0},f=ye(E.compare,he,be($(_=>x(_,x(0,1)))(ct(_=>oe(3)(_)==="$d:",Ne(t)))),(()=>{const _=h=>{if(h.tag==="Leaf")return q;if(h.tag==="Node")return $t("Node",h._1,h._2,h._3,x(h._4._1*_t(4),h._4._2),_(h._5),_(h._6));c()};return _(n)})()),g=[oo(a)(u)(t)(f)(r)(o)(i)(s)(Hs)(Ys),oo(a)(u)(t)(f)(r)(o)(i)(s)(Vs)(Ys),oo(a)(u)(t)(f)(r)(o)(i)(s)(Hs)(Fs),oo(a)(u)(t)(f)(r)(o)(i)(s)(Vs)(Fs)],d=yd(f)(g);if(Xs()(t)(f)(d))return d;const l=pd()(t)(f)(g);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return g[0];c()},Nd=e=>t=>n=>r=>{const o=bf(T,uc,i=>i.node===t?k("Just",i.position):T,e);if(o.tag==="Nothing")return e;if(o.tag==="Just"){const i=o._1;return $(u=>u.node===n?{...u,position:x(i._1+r._1,i._2+r._2)}:u)(e)}c()},xd=e=>t=>n=>r=>{const o=ct(u=>ze(Ye)(u.node)(t),e),i=(()=>{if(n==="Vertical"){if(r==="Start")return y(u=>s=>Le(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)}c()}if(n==="Horizontal"){if(r==="Start")return y(u=>s=>Le(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)}}c()})();return $(u=>{if(ze(Ye)(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)};c()}return u})(e)},vd=e=>t=>y(n=>r=>{if(r.tag==="Lock"){const o=r._1.node,i=r._1.position;return $(u=>u.node===o?{...u,position:i}:u)(n)}return r.tag==="AlignGroup"?xd(n)($(bu)(r._1.nodes))(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?Nd(n)(r._1.anchor)(r._1.target)(r._1.offset):n})(t)(e),Td=e=>t=>n=>r=>o=>i=>u=>s=>{const a=be($(_=>x(_._1,_._2))(Jr(r))),f=$($(bu))(n),g=$(_=>y(h=>p=>Be(h)((()=>{const m=tt(p)(a);if(m.tag==="Nothing")return 1;if(m.tag==="Just")return m._1._2;c()})()))(1)(_))(f),d=Jd(e)(f)(a)(be($(_=>x(_._1,_._2))(Jr(o))))(i)(s),l=Os(hd(e)(n)(r)(o)(i)(u)(_=>{const h=Os(_)(g);return Ne(Dt(p=>m=>Dt(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;c()})()/_t(4)})(),p>=0&&p<h.length?h[p]:0),size:(()=>{const v=oe(3)(N)==="$d:"?x(0,1):x(1,1),w=tt(N)(a);if(w.tag==="Nothing")return v;if(w.tag==="Just")return w._1;c()})(),layer:p,order:J}))(m))(f))}))(g);return vd(t)(Ne(Dt(_=>h=>Dt(p=>m=>({node:m,position:x((()=>{const J=tt(m)(d);return(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;c()})()/_t(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const J=oe(3)(m)==="$d:"?x(0,1):x(1,1),N=tt(m)(a);if(N.tag==="Nothing")return J;if(N.tag==="Just")return N._1;c()})(),layer:_,order:p}))(h))(f)))},Di=ui(Hr)(pn(32)),Us=ui(Hr)(pn(31)),xr=(()=>{const e=ug("25214903917");if(e.tag==="Nothing")return Au;if(e.tag==="Just")return e._1;c()})(),vr=ii(ui(Hr)(pn(48)))(Hr),wd=e=>{const t=sg(e);return gr(Qu((()=>{if(t.tag==="Nothing")return Au;if(t.tag==="Just")return t._1;c()})())(xr))(vr)},Wi=pn(11),io=e=>t=>{const n=gr(Qr(qr(t)(xr))(Wi))(vr);return x((()=>{const r=Ju(ng(si(n)(pn(48-e|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;c()})(),n)},Ld=e=>{const t=io(26)(e),n=io(27)(t._2);return x((_t(t._1)*Co(2)(27)+_t(n._1))/Co(2)(53),n._2)},Ed=e=>t=>{const n=y(r=>o=>{const i=Ld(r.finalR);return{rs:[...r.rs,i._1],finalR:i._2}})({rs:[],finalR:e})(t);return x($(r=>r.x)(xt(r=>o=>ht.compare(r.k)(o.k))(pe(r=>o=>({x:r,k:o}),t,n.rs))),n.finalR)},kd=e=>{const t=gr(Qr(qr(e)(xr))(Wi))(vr),n=gr(Qr(qr(t)(xr))(Wi))(vr);return x(Qr(qr((()=>{const r=si(t)(pn(16));return qu.compare(r)(Us)!=="LT"?ii(r)(Di):r})())(Di))((()=>{const r=si(n)(pn(16));return qu.compare(r)(Us)!=="LT"?ii(r)(Di):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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},uo=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=E.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}}c()}return o},Mi=jt(E)(zt),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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},so=jt(E)(zt),bd=wc(Do),Cd=y(er)(0),Sd=e=>t=>{const n=it.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Ks=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=E.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}}c()}return o},Pd=e=>t=>n=>r=>o=>Mi(y(i=>u=>{const s=xt(a=>f=>it.compare((()=>{const g=Tr(a.id)(o);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;c()})())((()=>{const g=Tr(f.id)(o);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;c()})()))(ct(a=>uo(a.to.node)(n),ct(a=>a.from.node===u,r)));return{ranks:[...i.ranks,...Dt(a=>f=>x(f.id,_t((i.rankSum+a|0)+1|0)))(s)],rankSum:i.rankSum+s.length|0}})({ranks:[],rankSum:0})(e).ranks),Gd=e=>t=>n=>r=>o=>Mi(y(i=>u=>{const s=xt(f=>g=>{const d=it.compare((()=>{const l=Ae(g.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Ae(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})());return d==="EQ"?it.compare((()=>{const l=Tr(f.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Tr(g.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})()):d})(ct(f=>uo(f.from.node)(n),ct(f=>f.to.node===u,r))),a=s.length;return{ranks:[...i.ranks,...Dt(f=>g=>x(g.id,_t((i.rankSum+a|0)-f|0)))(s)],rankSum:i.rankSum+a|0}})({ranks:[],rankSum:0})(e).ranks),Ri=e=>t=>n=>{const r=so(Dt(s=>a=>x(a,s))(e)),o=so(Dt(s=>a=>x(a,s))(t)),i=bt(s=>{const a=Ae(s.from.node)(r),f=Ae(s.to.node)(o);if(a.tag==="Just"&&f.tag==="Just")return k("Just",x(a._1,f._1));const g=Ae(s.from.node)(o),d=Ae(s.to.node)(r);return g.tag==="Just"&&d.tag==="Just"?k("Just",x(d._1,g._1)):T})(n),u=i.length;return y(s=>a=>y(f=>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?f+1|0:f)(s)(Ht(a+1|0,u-1|0)))(0)(Ht(0,u-2|0))},Dd=e=>t=>n=>r=>o=>{const i=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?k("Just",l[_]):T,p=_+1|0;if(p>=0&&p<l.length&&h.tag==="Just"){const m=h._1,J=l[p];if(on(b=>b.before===m&&b.after===J,o)){a=l,f=_+1|0;continue}if((()=>{const b=Ae(m)(e),L=Ae(J)(e);return b.tag==="Just"&&L.tag==="Just"&&b._1<L._1})()){a=l,f=_+1|0;continue}const N=ur(Kt,T,_,J,l),v=(()=>{if(N.tag==="Just")return ur(Kt,T,_+1|0,m,N._1);if(N.tag==="Nothing")return T;c()})(),w=(()=>{if(v.tag==="Nothing")return l;if(v.tag==="Just")return v._1;c()})();if(Ri(n)(w)(r)<Ri(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=i(g)(0);if(bd(d)(g)){a=!1,f=g;continue}s=d}return f})(t)},ao=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)(Ht(0,e.length-2|0)),Wd=e=>t=>n=>{const r=bt(f=>f.tag==="OrderConstraint"?k("Just",{before:f._1.before,after:f._1.after}):T)(e.constraints),o=f=>y(g=>d=>{const l=d.after,_=d.before,h=ir(Kt,T,m=>m===_,g),p=ir(Kt,T,m=>m===l,g);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=Cu(Kt,T,h._1,g),J=(()=>{if(m.tag==="Nothing")return g;if(m.tag==="Just")return m._1;c()})(),N=Sf(Kt,T,p._1,_,J);if(N.tag==="Nothing")return J;if(N.tag==="Just")return N._1;c()}return g})(f)(r),i=Mi(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?k("Just",_._1[p]):T;if(m.tag==="Just"){const J=h>=0&&h<_._1.length?k("Just",_._1[h]):T;if(J.tag==="Just"){const N=so(Dt(S=>z=>x(z,S))(m._1)),v=so(Dt(S=>z=>x(z,S))(J._1)),w=g?Pd(m._1)(N)(v)(n)(i):Gd(m._1)(N)(v)(n)(i),b=y(S=>z=>{const F=bt(G=>Tr(G.id)(w))(ct(g?G=>G.to.node===z._2&&uo(G.from.node)(N):G=>G.from.node===z._2&&uo(G.to.node)(N),n));if(F.length===0)return{...S,items:[...S.items,{n:z._2,key:T,origIdx:z._1}]};const j=io(24)(S.r);return{items:[...S.items,{n:z._2,key:k("Just",(Cd(F)+(_t(j._1)*4172325152040912e-24-.03500000014901161))/_t(F.length)),origIdx:z._1}],r:j._2}})({items:[],r:_._2})(Dt(Sn)(J._1)),L=ur(Kt,T,h,Dd(e.modelOrder)(o($(S=>S.n)(xt(S=>z=>{const F=Ae(S.n)(e.modelOrder),j=Ae(z.n)(e.modelOrder);if(F.tag==="Just"&&j.tag==="Just"){const G=it.compare(F._1)(j._1);return G==="EQ"?ht.compare(S.key)(z.key):G}return ht.compare(S.key)(z.key)})((()=>{const S=b.items,z=F=>j=>{let G=F,P=j,et=!0,K;for(;et;){const A=G,H=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=H;continue}c()}et=!1,K=H}return K};return(F=>j=>G=>{let P=F,et=j,K=G,A=!0,H;for(;A;){const R=P,C=et,D=K;if(R>=0&&R<S.length){if(S[R].key.tag==="Just"){P=R+1|0,et=S[R].key._1,K=[...D,{n:S[R].n,key:S[R].key._1,origIdx:S[R].origIdx}];continue}if(S[R].key.tag==="Nothing"){const W=(C+z(R+1|0)(C+1))/2;P=R+1|0,et=W,K=[...D,{n:S[R].n,key:W,origIdx:S[R].origIdx}];continue}c()}A=!1,H=D}return H})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(L.tag==="Just")return x(L._1,b.r);if(L.tag==="Nothing")return x(_._1,_._2);c()}if(J.tag==="Nothing")return x(_._1,_._2);c()}if(m.tag==="Nothing")return x(_._1,_._2);c()})(x(f,d))(g?Ht(1,l-1|0):_e(Ht(0,l-2|0)))},s=y(f=>g=>Z(E)(g.from.node)()(Z(E)(g.to.node)()(f)))(q)(n),a=y(f=>g=>{if(f.result.crossings===0)return f;const d=N=>v=>w=>b=>{let L=N,S=v,z=w,F=b,j=!0,G;for(;j;){const P=L,et=S,K=z,A=F;if(K===0){j=!1,G={layout:P,crossings:0,random:A};continue}const H=u(P,et,A),R=ao(H._1)(n);if(R<K){L=H._1,S=!et,z=R,F=H._2;continue}j=!1,G={layout:P,crossings:K,random:H._2}}return G},l=io(1)(f.result.random),_=l._1!==0,h=e.modelOrder.tag==="Leaf",p=(f.firstTry||f.secondTry)&&!h?f.firstTry:_,m=(()=>{if(!h){const b=u(t,p,l._2);return d(b._1)(!p)(ao(b._1)(n))(b._2)}const N=p?0:Sd(0)(t.length-1|0),v=N>=0&&N<t.length?k("Just",t[N]):T;if(v.tag==="Just"&&v._1.length>1){const b=ct(L=>Ks(L)(s),v._1);if(b.length>1){const L=Ed(l._2)(b),S=L._1,z=ur(Kt,T,N,o(y(F=>j=>Ks(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(z.tag==="Just"){const F=u(z._1,p,L._2);return d(F._1)(!p)(ao(F._1)(n))(F._2)}}}const w=u(t,p,l._2);return d(w._1)(!p)(ao(w._1)(n))(w._2)})(),J=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:J}})({result:{layout:t,crossings:1e9,random:gr(Qu(kd(wd(1))._1)(xr))(vr)},firstTry:e.modelOrder.tag!=="Leaf",secondTry:!1})(Ht(1,e.iterations)).result;return t.length<=0||e.iterations<=0?t:a.layout},Md=e=>e,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=E.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}}c()}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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Vn=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=E.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}}c()}return o},wr=(()=>{const e={eq:t=>n=>t._1===n._1&&t._2===n._2};return{compare:t=>n=>{const r=E.compare(t._1)(n._1);return r==="LT"?Re:r==="GT"?Ie:E.compare(t._2)(n._2)},Eq0:()=>e}})(),Rd=jt(E)(zt),Id=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=wr.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}}c()}return o},zd=Md("Greedy"),Ii=e=>t=>n=>y(r=>o=>{if(o.from.node===o.to.node)return r;if(o.from.node===t&&!Zs(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;c()})(),s=Z(E)(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;c()})()&&!ze(Ye)(o.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,o.to.node]}:{...r,inDeg:s}}if(o.to.node===t&&!Zs(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;c()})(),s=Z(E)(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;c()})()&&!ze(Ye)(o.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,o.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:ct(r=>r!==t,n.remaining)})(e),Bd=y(e=>t=>{if(t.tag==="LayerConstraint"){if(t._1.pin.tag==="SpecificLayer")return Z(E)(t._1.node)(t._1.pin._1)(e);if(t._1.pin.tag==="FirstLayer")return Z(E)(t._1.node)(0)(e);if(t._1.pin.tag==="LastLayer")return Z(E)(t._1.node)(99999)(e)}return e})(q),js=e=>t=>n=>{const r=le(t)(e),o=le(n)(e);return r.tag==="Just"&&o.tag==="Just"&&r._1>o._1},ta=e=>t=>n=>r=>{if(Vn(n)(r.visited)||Vn(n)(r.visiting))return r;const o=y(Ad(e)(t)(n))({...r,visiting:Z(E)(n)()(r.visiting)})((()=>{const i=le(n)(t);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;c()})());return{...o,visiting:sr(E)(n)(o.visiting),visited:Z(E)(n)()(o.visited)}},Ad=e=>t=>n=>r=>o=>js(e)(n)(o)?{...r,backEdges:Z(wr)(x(n,o))()(r.backEdges)}:Vn(o)(r.visiting)?{...r,backEdges:Z(wr)(x(n,o))()(r.backEdges)}:Vn(o)(r.visited)?r:ta(e)(t)(o)(r),Qd=e=>t=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,J=Vt(N=>T,N=>v=>k("Just",{head:N,tail:v}),m.sinks);if(J.tag==="Just"){_=Ii(n)(J._1.head)({...m,sinks:J._1.tail,marks:Z(E)(J._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(J.tag==="Nothing"){const N=Vt(v=>T,v=>w=>k("Just",{head:v,tail:w}),m.sources);if(N.tag==="Just"){_=Ii(n)(N._1.head)({...m,sources:N._1.tail,marks:Z(E)(N._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(N.tag==="Nothing"){const v=b=>{const L=le(b)(m.outDeg),S=le(b)(m.inDeg);return(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;c()})()-(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;c()})()|0},w=xt(b=>L=>{const S=it.compare(v(L))(v(b));return S==="EQ"?it.compare((()=>{const z=le(b)(t);if(z.tag==="Nothing")return 1e6;if(z.tag==="Just")return z._1;c()})())((()=>{const z=le(L)(t);if(z.tag==="Nothing")return 1e6;if(z.tag==="Just")return z._1;c()})()):S})(m.remaining);if(0<w.length){const b=w[0];_=Ii(n)(b)({...m,remaining:ct(L=>L!==b,m.remaining),marks:Z(E)(b)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}c()}return p},o=Pn(E.compare)([...$(l=>l.from.node)(n),...$(l=>l.to.node)(n)]),i=ct(l=>l.from.node!==l.to.node,n),u=y(l=>_=>vt(E)(Ut)(_.to.node)(1)(l))(q)(i),s=y(l=>_=>vt(E)(Ut)(_.from.node)(1)(l))(q)(i),a=ct(l=>{const _=le(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;c()},o),f=ct(l=>{const _=le(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;c()},o),g=o.length+1|0,d=y(l=>_=>{const h=le(_)(l);return h.tag==="Just"&&h._1<0?Z(E)(_)(h._1+g|0)(l):l})(r({remaining:ct(l=>!ze(Ye)(l)(a)&&!ze(Ye)(l)(f),o),marks:q,inDeg:u,outDeg:s,sources:a,sinks:f,nextLeft:1,nextRight:-1}).marks)(o);return y(l=>_=>{if(_.from.node===_.to.node)return l;if(js(e)(_.from.node)(_.to.node))return Z(wr)(x(_.from.node,_.to.node))()(l);const h=le(_.from.node)(d),p=le(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?Z(wr)(x(_.from.node,_.to.node))()(l):l})(q)(n)},qd=y(e=>t=>vt(E)(ie)(t.from.node)([t.to.node])(e))(q),Hd=e=>t=>{const n=qd(t),r=Pn(E.compare)([...$(i=>i.from.node)(t),...$(i=>i.to.node)(t)]),o=y(i=>u=>Z(E)(u.to.node)()(i))(q)(t);return y(i=>u=>ta(e)(n)(u)(i))({visiting:q,visited:q,backEdges:q})([...ct(i=>!Vn(i)(o),r),...ct(i=>Vn(i)(o),r)]).backEdges},Vd=e=>t=>n=>r=>{const o=Rd(Dt(s=>a=>x(a,s))(t)),i=Bd(n),u=(()=>{if(e==="DepthFirst")return Hd(i)(r);if(e==="Greedy")return Qd(i)(o)(r);c()})();return{edges:$(s=>Id(x(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},ea=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Yd=e=>t=>n=>y(r=>o=>{const i=ea(o.from.node)(e),u=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;c()})(),s=ea(o.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,o],chains:[...r.chains,{edgeId:o.id,nodes:[o.from.node,o.to.node]}]};const f=o.id,g=$(l=>"$d:"+f+":"+Te(l))(Ht(1,a-1|0)),d=[o.from.node,...g,o.to.node];return{...r,layers:y(l=>_=>{const h=_._2,p=Wf(u+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;c()})(r.layers)(pe(Sn,Ht(1,a-1|0),g)),edges:[...r.edges,...pe(l=>_=>({id:f+":"+l+"->"+_,from:{node:l,port:o.from.port},to:{node:_,port:o.to.port}}),d,Wt(1,d.length,d))],chains:[...r.chains,{edgeId:o.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(t),zi=e=>t=>{const n=it.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},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=E.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}}c()}return o},Yt=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Lr=e=>t=>{const n=it.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},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=it.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}}c()}return o},co=jt(E)(zt),Yn=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=it.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Fd=(()=>{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=it.compare(n.delta)(r.delta);if(o==="LT"||o==="GT"||o!=="EQ")return o;const i=it.compare(n.eid)(r.eid);if(i==="LT"||i==="GT"||i!=="EQ")return i;const u=E.compare(n.src)(r.src);if(u==="LT"||u==="GT"||u!=="EQ")return u;const s=E.compare(n.tgt)(r.tgt);if(s==="LT"||s==="GT"||s!=="EQ")return s;const a=it.compare(n.weight)(r.weight);return a==="LT"||a==="GT"||a!=="EQ"?a:Ve},Eq0:()=>e};return y(n=>r=>Z(t)(r)()(n))(q)})(),$d=y(e=>t=>Z(E)(t)()(e))(q),Od=jt(it)(zt),Xd=e=>t=>ye(E.compare,he,e,t),Ud=e=>y(t=>n=>({base:(()=>{const r=o=>i=>{let u=o,s=i,a=!0,f;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,f=g;continue}if(d.tag==="Cons"){u=zi(g)(d._1),s=d._2;continue}c()}return f};return(t.base+r(0)((()=>{const o=(i,u)=>{if(i.tag==="Leaf")return u;if(i.tag==="Node")return o(i._5,It("Cons",i._4,o(i._6,u)));c()};return o(n,Bt)})())|0)+1|0})(),result:[...t.result,(()=>{if(t.base===0)return n;const r=o=>{if(o.tag==="Leaf")return q;if(o.tag==="Node")return $t("Node",o._1,o._2,o._3,o._4+t.base|0,r(o._5),r(o._6));c()};return r(n)})()]}))({base:0,result:[]})(e).result,Kd=e=>t=>{const n=i=>{let u=i,s=!0,a;for(;s;){const f=u,g=Vt(d=>T,d=>l=>k("Just",{head:d,tail:l}),f.queue);if(g.tag==="Nothing"){s=!1,a=f;continue}if(g.tag==="Just"){if(ae(g._1.head)(f.removedNodes)){u={...f,queue:g._1.tail};continue}const d=fe(l=>!ae(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(E)(l)((()=>{const h=Yt(l)(f.degree);if(h.tag==="Nothing")return-1;if(h.tag==="Just")return h._1-1|0;c()})())(f.degree),removedNodes:Z(E)(g._1.head)()(f.removedNodes),removedEdges:Z(E)(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=Yt(l)(_.degree);return(()=>{if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1===1;c()})()&&!ae(l)(_.removedNodes)})()){u={..._,queue:[..._.queue,l]};continue}u=_;continue}}c()}return a},r=y(i=>u=>vt(E)(Ut)(u.src)(1)(vt(E)(Ut)(u.tgt)(1)(i)))(q)(t),o=n({degree:r,removedNodes:q,removedEdges:q,record:[],queue:ct(i=>{const u=Yt(i)(r);if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1===1;c()},e)});return{coreNodes:ct(i=>!ae(i)(o.removedNodes),e),coreEdges:ct(i=>!ae(i.src+"\u2192"+i.tgt)(o.removedEdges),t),removed:o.record}},Zd=e=>t=>y(n=>r=>{const o=Yt(r.neighbour)(n),i=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;c()})();return Z(E)(r.node)(r.viaSrc?i-1|0:i+1|0)(n)})(t)(_e(e)),na=e=>t=>n=>{const r=y(i=>u=>{const s=na(e)(u.src===t?u.tgt:u.src)({...i.st,edgeVisited:Z(it)(u.eid)()(i.st.edgeVisited)});return{lowest:Lr(i.lowest)(s.lowest),st:s.st}})({lowest:1e9,st:n})(ct(i=>xn(i.eid)(n.treeEdge)&&(i.src===t||i.tgt===t)&&!xn(i.eid)(n.edgeVisited),e)),o=Lr(r.lowest)(r.st.postOrder);return{lowest:o,st:{...r.st,poID:Z(E)(t)(r.st.postOrder)(r.st.poID),lowestPoID:Z(E)(t)(o)(r.st.lowestPoID),postOrder:r.st.postOrder+1|0}}},ra=e=>t=>n=>na(t)(0<e.length?e[0]:"")({...n,edgeVisited:q,postOrder:1,poID:q,lowestPoID:q}).st,oa=e=>t=>{const n=y(r=>o=>Lr(r)((()=>{const i=Yt(o)(t);if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;c()})()))(1e9)(e);return co($(r=>x(r,(()=>{const o=Yt(r)(t);if(o.tag==="Nothing")return-n;if(o.tag==="Just")return o._1-n|0;c()})()))(e))},Bi=e=>t=>{const n=Yt(t)(e.poID);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;c()},ia=e=>t=>{const n=Yt(t)(e.lowestPoID);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;c()},jd=e=>t=>fe(n=>{const r=Yn(n.eid)(t.cutvalue);return xn(n.eid)(t.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<0;c()})()})(e),xe=e=>t=>{const n=Yt(t)(e.layer);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;c()},tl=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:k("Just",r),slack:o}:n})({edge:T,slack:1e9})(e).edge,Ai=e=>t=>n=>{const r={...n,treeNode:Z(E)(t)()(n.treeNode)};return y(o=>i=>{if(xn(i.eid)(o.st.edgeVisited))return o;const u={...o.st,edgeVisited:Z(it)(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(it)(i.eid)()(u.treeEdge)});return{count:o.count+a.count|0,st:a.st}}return{...o,st:u}})({count:1,st:r})(ct(o=>(o.src===t||o.tgt===t)&&!xn(o.eid)(r.edgeVisited),e))},fo=e=>t=>n=>{const r=Bi(e)(n.src),o=Bi(e)(n.tgt),i=Bi(e)(t);return ia(e)(n.src)<=i&&i<=r&&ia(e)(n.tgt)<=i&&i<=o?r>=o:r<o},el=e=>t=>({layer:co($(n=>x(n,0))(e)),treeNode:q,treeEdge:q,poID:q,lowestPoID:q,cutvalue:q,postOrder:1,edgeVisited:q}),nl=e=>t=>n=>ct(r=>xn(r.eid)(t.treeEdge)&&(r.src===n||r.tgt===n),e),rl=e=>t=>n=>{let r=e,o=t,i=n,u=!0,s;for(;u;){const a=r,f=o,g=i,d=Ai(f)(0<a.length?a[0]:"")({...g,edgeVisited:q,treeNode:q,treeEdge:q});if(d.count>=a.length){u=!1,s=d.st;continue}const l=tl(f)(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=f,i={...d.st,layer:y(p=>m=>ae(m)(d.st.treeNode)?Z(E)(m)(xe(d.st)(m)+h|0)(p):p)(d.st.layer)(a)};continue}c()}return s},ol=e=>t=>n=>y(r=>o=>{if(fo(n)(o.src)(t)&&!fo(n)(o.tgt)(t)){const i=(xe(n)(o.tgt)-xe(n)(o.src)|0)-o.delta|0;if(i<r.slack)return{edge:k("Just",o),slack:i}}return r})({edge:T,slack:1e9})(e).edge,il=e=>t=>{const n=y(o=>i=>vt(E)(ie)(i.tgt)([i.src])(vt(E)(ie)(i.src)([i.tgt])(o)))(q)(t),r=o=>i=>u=>{let s=o,a=i,f=u,g=!0,d;for(;g;){const l=s,_=a,h=f,p=Vt(m=>T,m=>J=>k("Just",{head:m,tail:J}),l);if(p.tag==="Nothing"){g=!1,d={nodes:h};continue}if(p.tag==="Just"){if(ae(p._1.head)(_)){s=p._1.tail,a=_,f=h;continue}s=[...p._1.tail,...(()=>{const m=Yt(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;c()})()],a=Z(E)(p._1.head)()(_),f=[...h,p._1.head];continue}c()}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(E)(a)()(s))(o.visited)(u.nodes),components:[...o.components,u.nodes]}})({visited:q,components:[]})(e).components},ul=e=>t=>n=>r=>{const o=r.tgt,i=r.src;return y(u=>s=>{if((()=>{const a=Yn(s.eid)(t.cutvalue);if(a.tag==="Just")return!0;if(a.tag==="Nothing")return!1;c()})()){const a=Yn(s.eid)(t.cutvalue),f=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()})();return i===s.src||o===s.tgt?u-(f-s.weight|0)|0:u+(f-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)(ct(u=>u.eid!==r.eid&&(u.src===n||u.tgt===n),e))},sl=e=>t=>n=>(r=>o=>{let i=r,u=o,s=!0,a;for(;s;){const f=i,g=u,d=Yt(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;i={unknown:(()=>{const h=Yt(_)(f.unknown),p=(()=>{if(h.tag==="Just")return Z(E)(_)(ct(J=>J.eid!==l[0].eid,h._1))(f.unknown);if(h.tag==="Nothing")return f.unknown;c()})(),m=Yt(g)(p);if(m.tag==="Just")return Z(E)(g)(ct(J=>J.eid!==l[0].eid,m._1))(p);if(m.tag==="Nothing")return p;c()})(),cutvalue:Z(it)(l[0].eid)(ul(e)(f)(g)(l[0]))(f.cutvalue)},u=_;continue}s=!1,a=f}return a})(t)(n),ua=e=>t=>n=>{const r={unknown:co($(o=>x(o,wt(we.foldr,Fd(nl(t)(n)(o)))))(e)),cutvalue:q};return{...n,cutvalue:y(sl(t))(r)(ct(o=>{const i=Yt(o)(r.unknown);if(i.tag==="Nothing")return!1;if(i.tag==="Just")return i._1.length===1;c()},e)).cutvalue}},al=e=>t=>n=>r=>o=>{const i={...o,treeEdge:Z(it)(r.eid)()(sr(it)(n.eid)(o.treeEdge))},u=(xe(i)(r.tgt)-xe(i)(r.src)|0)-r.delta|0,s=fo(i)(r.tgt)(n)?-u:u;return ua(e)(t)(ra(e)(t)({...i,layer:y(a=>f=>fo(i)(f)(n)?a:Z(E)(f)(xe(i)(f)+s|0)(a))(i.layer)(e)}))},cl=e=>t=>n=>r=>(o=>i=>{let u=o,s=i,a=!0,f;for(;a;){const g=u,d=s;if(g===0){a=!1,f=d;continue}const l=jd(n)(d);if(l.tag==="Nothing"){a=!1,f=d;continue}if(l.tag==="Just"){const _=ol(n)(l._1)(d);if(_.tag==="Nothing"){a=!1,f=d;continue}if(_.tag==="Just"){u=g-1|0,s=al(t)(n)(l._1)(_._1)(d);continue}}c()}return f})(e)(r),fl=e=>t=>n=>ua(e)(t)(ra(e)(t)(rl(e)(t)(n))),sa=e=>y(t=>n=>vt(E)(ie)(e(n))([n])(t))(q),gl=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,J=d,N=l,v=_,w=Vt(b=>T,b=>L=>k("Just",{head:b,tail:L}),N);if(w.tag==="Nothing"){h=!1,p=v;continue}if(w.tag==="Just"){const b=xe(v)(w._1.head),L=y(S=>z=>{const F=Yt(z.tgt)(S.incident),j=(()=>{if(F.tag==="Nothing")return-1;if(F.tag==="Just")return F._1-1|0;c()})();return{st:{...S.st,layer:Z(E)(z.tgt)(zi(xe(S.st)(z.tgt))(b+z.delta|0))(S.st.layer)},incident:Z(E)(z.tgt)(j)(S.incident),queue:j===0?[...S.queue,z.tgt]:S.queue}})({st:v,incident:J,queue:w._1.tail})((()=>{const S=Yt(w._1.head)(m);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;c()})());g=m,d=L.incident,l=L.queue,_=L.st;continue}c()}return p},o=sa(u=>u.tgt)(t),i=co($(u=>x(u,(()=>{const s=Yt(u)(o);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.length;c()})()))(e));return r(sa(u=>u.src)(t))(i)(ct(u=>{const s=Yt(u)(i);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;c()},e))(n)},aa=e=>t=>{const n=Dt(o=>i=>({src:i.src,tgt:i.tgt,delta:1,weight:1,eid:o}))(t),r=gl(e)(n)(el(e)(n));return n.length===0?r.layer:cl(4*e.length|0)(e)(n)(fl(e)(n)(r)).layer},_l=e=>t=>{const n=$d(e),r=ct(i=>ae(i.src)(n)&&ae(i.tgt)(n),t);if(e.length<40)return oa(e)(aa(e)(r));const o=Kd(e)(r);return oa(e)(Zd(o.removed)(aa(o.coreNodes)(o.coreEdges)))},dl=e=>t=>n=>{const r=y(i=>u=>vt(E)(Ut)(u.tgt)(1)(i))(q)(t),o=y(i=>u=>vt(E)(Ut)(u.src)(1)(i))(q)(t);return y(i=>u=>{const s=Yt(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})();if((()=>{const N=Yt(u)(o);return(()=>{if(N.tag==="Nothing")return a!==0;if(N.tag==="Just")return a!==N._1;c()})()||a===0})())return i;const f=Yt(u)(i.layers),g=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;c()})(),d=i.layers,l=y(N=>v=>v.tgt===u?{...N,mIn:Lr(N.mIn)((()=>{const w=Yt(u)(d),b=Yt(v.src)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;c()})()|0})())}:v.src===u?{...N,mOut:Lr(N.mOut)((()=>{const w=Yt(v.tgt)(d),b=Yt(u)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;c()})()|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 p=(g-_|0)+1|0,m=(g+h|0)-1|0;if(m<p)return i;const J=y(N=>v=>{const w=Yn(v)(i.filling),b=(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})();return b<N.bestFill?{best:v,bestFill:b}:N})({best:g,bestFill:(()=>{const N=Yn(g)(i.filling);if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})()})(Ht(p,m));return J.best===g?i:{layers:Z(E)(u)(J.best)(i.layers),filling:Z(it)(g)((()=>{const N=Yn(g)(i.filling);if(N.tag==="Nothing")return-1;if(N.tag==="Just")return N._1-1|0;c()})())(Z(it)(J.best)(J.bestFill+1|0)(i.filling))}})({layers:n,filling:Od($(i=>x(i,y(u=>s=>(()=>{const a=Yt(s)(n);return a.tag==="Nothing"?!1:a.tag==="Just"&&a._1===i})()?u+1|0:u)(0)(e)))(Ht(0,y(i=>u=>zi(i)((()=>{const s=Yt(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(0)(e))))})(e).layers},ll=e=>t=>dl(e)(Dt(n=>r=>({src:r.src,tgt:r.tgt,delta:1,weight:1,eid:n}))(t))(y(Xd)(q)(Ud($(n=>_l(n)(t))(il(e)(t))))),hl=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},go=e=>t=>{const n=it.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},ca=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),pl=hl("NetworkSimplex"),ml=e=>t=>y(n=>r=>{const o=y(go)(0)(bt(i=>vn(i)(n))(r));return y(i=>u=>Z(E)(u)(o)(i))(n)(r)})(t)(e),yl=e=>t=>({layers:$(n=>ct(r=>{const o=vn(r)(t);return o.tag==="Nothing"?!1:o.tag==="Just"&&o._1===n},e))(Ht(0,(n=>r=>{let o=n,i=r,u=!0,s;for(;u;){const a=o,f=i;if(f.tag==="Nil"){u=!1,s=a;continue}if(f.tag==="Cons"){o=go(a)(f._1),i=f._2;continue}c()}return s})(0)((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._4,n(r._6,o)));c()};return n(t,Bt)})()))),nodeLayer:t}),Jl=e=>t=>n=>{const r=y(o=>i=>Z(E)(i)(!0)(o))(q)(t);return y(o=>i=>Z(E)(i._1)(i._2)(o))(ll(t)(bt(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;c()})()||(()=>{const i=vn(o.to.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;c()})()?T:k("Just",{src:o.from.node,tgt:o.to.node}))(e)))(ca(n))},Nl=e=>t=>n=>r=>{const o=s=>a=>{const f=vn(a)(s);if(f.tag==="Just")return s;if(f.tag==="Nothing"){const g=ct(l=>l!==a,(()=>{const l=vn(a)(e);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;c()})()),d=y(o)(s)(g);return Z(E)(a)(1+y(go)(0)(bt(l=>vn(l)(d))(g))|0)(d)}c()},i=y(o)(q)(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=go(_)(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,It("Cons",a._4,s(a._6,f)));c()};return s(i,Bt)})());return y(s=>a=>Z(E)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return q;if(a.tag==="Node")return $t("Node",a._1,a._2,a._3,u-a._4|0,s(a._5),s(a._6));c()};return s(i)})())(ca(r))},xl=y(e=>t=>{if(t.tag==="LayerConstraint"){if(t._1.pin.tag==="SpecificLayer")return Z(E)(t._1.node)(t._1.pin._1)(e);if(t._1.pin.tag==="FirstLayer")return Z(E)(t._1.node)(0)(e)}return e})(q),vl=y(e=>t=>vt(E)(ie)(t.to.node)([t.from.node])(e))(q),Tl=y(e=>t=>vt(E)(ie)(t.from.node)([t.to.node])(e))(q),wl=e=>t=>n=>r=>{const o=Tl(n),i=vl(n),u=xl(t);return yl(r)(ml(bt(s=>s.tag==="SameLayer"?k("Just",s._1.nodes):T)(t))((()=>{if(e==="LongestPath")return Nl(o)(i)(r)(u);if(e==="NetworkSimplex")return Jl(n)(r)(u);c()})()))},Ll=jt(E)(zt),El=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},fa=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},ga=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Er=jt(E)(zt),kl=jt(E)(zt),_a=(()=>{const e=$(t=>({start:t.end,end:t.start,direction:t.direction}));return t=>_e(e(t))})(),bl=e=>t=>n=>r=>{const o=Ll($(u=>x(u.edge,u))(r)),i=u=>0<u.nodes.length&&(()=>{const s=El(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return $(u=>{if(u.nodes.length<=2){const g=fa(u.edgeId)(o);if(g.tag==="Just"){const d=i(u);return{...g._1,edge:u.edgeId,segments:d?_a(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(bt(g=>fa(g)(o))(pe(g=>d=>u.edgeId+":"+g+"->"+d,u.nodes,Wt(1,u.nodes.length,u.nodes))))(g=>g.segments),a=i(u),f=bi(a?_a(s):s);return{edge:u.edgeId,segments:f,bends:pe(g=>d=>g.end,f,Wt(1,f.length,f)),bendType:[],jumps:[],reversed:a}})(e)},Cl={layers:[],edges:[],chains:[]},Sl={nodeGap:3,layerGap:2,iterations:8,layerer:pl,cycleBreaker:zd},Pl=e=>({pos:x(0,0),size:x(y(t=>n=>ga(t)(n.position._1+n.size._1))(0)(e),y(t=>n=>ga(t)(n.position._2+n.size._2))(0)(e))}),Gl=e=>t=>{const n=ct(i=>oe(3)(i.node)!=="$d:",t.placements),r=bl(t.withDummies.chains)(t.acyclic.reversedEdges)(kl($(i=>x(i.id,x(i.from.node,i.to.node)))(e.edges)))(Y1(t.withDummies.edges)(t.placements)(Er($(i=>x(i.id,i.ports))(e.nodes)))(t.withDummies.chains)(zs(t.ordered)(ct(i=>i.from.node!==i.to.node,t.withDummies.edges))((()=>{const i=u=>{if(u.tag==="Leaf")return q;if(u.tag==="Node")return $t("Node",u._1,u._2,u._3,x(u._4._1*4,u._4._2),i(u._5),i(u._6));c()};return i(Er($(u=>x(u.id,u.size))(e.nodes)))})()))),o=Dt(i=>u=>({...u,jumps:Z1(i)(u)(r)}))(r);return{nodes:n,edges:o,boundingBox:Pl(n),metrics:_1(n)(o)(0)}},Dl=e=>t=>n=>{const r=Er($(i=>x(i.id,i.size))(t.nodes)),o={...n,placements:Td({nodeGap:e.nodeGap,layerGap:e.layerGap})(t.constraints)(n.ordered)(r)(Er($(i=>x(i.id,i.ports))(t.nodes)))(n.withDummies.edges)(n.withDummies.chains)(zs(n.ordered)(n.withDummies.edges)((()=>{const i=u=>{if(u.tag==="Leaf")return q;if(u.tag==="Node")return $t("Node",u._1,u._2,u._3,x(u._4._1*4,u._4._2),i(u._5),i(u._6));c()};return i(r)})()))};return{pipeline:o,result:Gl(t)(o)}},Wl=e=>t=>n=>Dl(e)(t)({...n,ordered:Wd({iterations:e.iterations,constraints:t.constraints,modelOrder:Er(Dt(r=>o=>x(o.id,r))(t.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),Ml=e=>t=>n=>Wl(e)(t)({...n,withDummies:Yd(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),Rl=e=>t=>{const n=$(o=>o.id)(t.nodes),r=Vd(e.cycleBreaker)(n)(t.constraints)(t.edges);return Ml(e)(t)({acyclic:r,layered:wl(e.layerer)(t.constraints)(r.edges)(n),withDummies:Cl,ordered:[],placements:[]})},Il=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},zl=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},da=jt(E)(zt),Bl=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=E.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}}c()}return o},Al=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=E.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}}c()}return o},Ql=y(e=>t=>Z(E)(t)()(e))(q),ql=y(e=>t=>Z(E)(t)()(e))(q),Hl=Ir.traverse(Eu),Qi=jt(E)(zt),Vl=e=>t=>n=>{const r=fe(o=>o.id===n)(e.graph.edges);if(r.tag==="Just")return k("Just",r._1);if(r.tag==="Nothing")return Il(n)(t);c()},Yl=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=zl(n.node)(t);if(r.tag==="Just")return r._1;if(r.tag==="Nothing")return n.node;c()})()}),Fl=e=>({id:e,size:x(1,1),ports:[],label:k("Just",e)}),$l=e=>t=>n=>x(n.node,Yl(e)(t)(n)),Ol=e=>da(bt(t=>k("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"?bt(n=>n.kind.tag==="SendToken"?k("Just",n.kind._1):T)(t._1.events):[]))),la=e=>{const t=dg(e),n=ct(o=>Bl(o.id)(t.nodes),e.graph.nodes),r=ct(o=>Al(o.id)(t.edges),e.graph.edges);return{nodes:[...n,...$(Fl)(wt(we.foldr,Fe(E.compare,t.nodes,Ql($(o=>o.id)(n)))))],edges:[...r,...bt(Vl(e)(Ol(e)))(wt(we.foldr,Fe(E.compare,t.edges,ql($(o=>o.id)(r)))))],constraints:e.graph.constraints}},Xl=e=>{const t=Hl(n=>{const r=n1("Ilisarniq, ui-sans-serif, system-ui, sans-serif")(11)("500")(ys((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;c()})()));return()=>{const o=r();return x(n.id,o)}})(la(e).nodes);return()=>{const n=t();return Qi(n)}},Ul=e=>t=>{const n=Vt(r=>T,r=>o=>k("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},...$(r=>({x:r.end._1*e,y:r.end._2*e}))([n._1.head,...n._1.tail])];c()},Kl=e=>t=>x(t.edge,Ul(e)(t)),Zl=e=>t=>n=>({nodes:Qi($($l(_t(4)*e)(t))(n.nodes)),edges:da($(Kl(e))(n.edges)),chipExtras:q}),jl=_t(4)*8,t0=e=>t=>{const n=c1(jl)(e)(a1(s1)(la(t)));return Zl(8)(Qi($(r=>x(r.id,(()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;c()})()))(n.nodes)))(Rl(Sl)(n).result)};(function(){var e={},t="Pure",n="Throw",r="Catch",o="Sync",i="Async",u="Bind",s="Bracket",a="Fork",f="Sequential",g="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",J="Finalized",N="Forked";function v(M,Y,X,V){this.tag=M,this._1=Y,this._2=X,this._3=V}function w(M){var Y=function(X,V,Q){return new v(M,X,V,Q)};return Y.tag=M,Y}function b(M){return new v(t,void 0)}function L(M){try{M()}catch(Y){setTimeout(function(){throw Y},0)}}function S(M,Y,X){try{return Y(X())}catch(V){return M(V)}}function z(M,Y,X){try{return Y(X)()}catch(V){return X(M(V))(),b}}var F=(function(){var M=1024,Y=0,X=0,V=new Array(M),Q=!1;function I(){var U;for(Q=!0;Y!==0;)Y--,U=V[X],V[X]=void 0,X=(X+1)%M,U();Q=!1}return{isDraining:function(){return Q},enqueue:function(U){var O;Y===M&&(O=Q,I(),Q=O),V[(X+Y)%M]=U,Y++,Q||I()}}})();function j(M){var Y={},X=0,V=0;return{register:function(Q){var I=X++;Q.onComplete({rethrow:!0,handler:function(U){return function(){V--,delete Y[I]}}})(),Y[I]=Q,V++},isEmpty:function(){return V===0},killAll:function(Q,I){return function(){if(V===0)return I();var U=0,O={};function gt(at){O[at]=Y[at].kill(Q,function(lt){return function(){delete O[at],U--,M.isLeft(lt)&&M.fromLeft(lt)&&setTimeout(function(){throw M.fromLeft(lt)},0),U===0&&I()}})()}for(var pt in Y)Y.hasOwnProperty(pt)&&(U++,gt(pt));return Y={},X=0,V=0,function(at){return new v(o,function(){for(var lt in O)O.hasOwnProperty(lt)&&O[lt]()})}}}}}var G=0,P=1,et=2,K=3,A=4,H=5,R=6;function C(M,Y,X){var V=0,Q=G,I=X,U=null,O=null,gt=null,pt=null,at=null,lt=0,Tt=0,Gt=null,dt=!0;function Mt(nt){for(var st,yt,Jt;;)switch(st=null,yt=null,Jt=null,Q){case et:Q=P;try{I=gt(I),pt===null?gt=null:(gt=pt._1,pt=pt._2)}catch(Qt){Q=H,U=M.left(Qt),I=null}break;case K:M.isLeft(I)?(Q=H,U=I,I=null):gt===null?Q=H:(Q=et,I=M.fromRight(I));break;case P:switch(I.tag){case u:gt&&(pt=new v(_,gt,pt)),gt=I._2,Q=P,I=I._1;break;case t:gt===null?(Q=H,I=M.right(I._1)):(Q=et,I=I._1);break;case o:Q=K,I=S(M.left,M.right,I._1);break;case i:Q=A,I=z(M.left,I._1,function(Qt){return function(){V===nt&&(V++,F.enqueue(function(){V===nt+1&&(Q=K,I=Qt,Mt(V))}))}});return;case n:Q=H,U=M.left(I._1),I=null;break;case r:gt===null?at=new v(_,I,at,O):at=new v(_,I,new v(_,new v(h,gt,pt),at,O),O),gt=null,pt=null,Q=P,I=I._1;break;case s:lt++,gt===null?at=new v(_,I,at,O):at=new v(_,I,new v(_,new v(h,gt,pt),at,O),O),gt=null,pt=null,Q=P,I=I._1;break;case a:Q=K,st=C(M,Y,I._2),Y&&Y.register(st),I._1&&st.run(),I=M.right(st);break;case f:Q=P,I=W(M,Y,I._1);break}break;case H:if(gt=null,pt=null,at===null)Q=R,I=O||U||I;else switch(st=at._3,Jt=at._1,at=at._2,Jt.tag){case r:O&&O!==st&<===0?Q=H:U&&(Q=P,I=Jt._2(M.fromLeft(U)),U=null);break;case h:O&&O!==st&<===0||U?Q=H:(gt=Jt._1,pt=Jt._2,Q=et,I=M.fromRight(I));break;case s:lt--,U===null&&(yt=M.fromRight(I),at=new v(_,new v(p,Jt._2,yt),at,st),(O===st||lt>0)&&(Q=P,I=Jt._3(yt)));break;case p:at=new v(_,new v(J,I,U),at,O),Q=P,O&&O!==st&<===0?I=Jt._1.killed(M.fromLeft(O))(Jt._2):U?I=Jt._1.failed(M.fromLeft(U))(Jt._2):I=Jt._1.completed(M.fromRight(I))(Jt._2),U=null,lt++;break;case m:lt++,at=new v(_,new v(J,I,U),at,O),Q=P,I=Jt._1;break;case J:lt--,Q=H,I=Jt._1,U=Jt._2;break}break;case R:for(var Ct in Gt)Gt.hasOwnProperty(Ct)&&(dt=dt&&Gt[Ct].rethrow,L(Gt[Ct].handler(I)));Gt=null,O&&U?setTimeout(function(){throw M.fromLeft(U)},0):M.isLeft(I)&&dt&&setTimeout(function(){if(dt)throw M.fromLeft(I)},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(I)(),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(M.right(void 0))(),function(){};var yt=mt({rethrow:!1,handler:function(){return st(M.right(void 0))}})();switch(Q){case G:O=M.left(nt),Q=R,I=O,Mt(V);break;case A:O===null&&(O=M.left(nt)),lt===0&&(Q===A&&(at=new v(_,new v(m,I(nt)),at,O)),Q=H,I=null,U=null,Mt(++V));break;default:O===null&&(O=M.left(nt)),lt===0&&(Q=H,I=null,U=null)}return yt}}function rt(nt){return function(){var st=mt({rethrow:!1,handler:nt})();return Q===G&&Mt(V),st}}return{kill:ft,join:rt,onComplete:mt,isSuspended:function(){return Q===G},run:function(){Q===G&&(F.isDraining()?Mt(V):F.enqueue(function(){Mt(V)}))}}}function D(M,Y,X,V){var Q=0,I={},U=0,O={},gt=new Error("[ParAff] Early exit"),pt=null,at=e;function lt(mt,ft,rt){var nt=ft,st=null,yt=null,Jt=0,Ct={},Qt,ne;t:for(;;)switch(Qt=null,nt.tag){case N:if(nt._3===e&&(Qt=I[nt._1],Ct[Jt++]=Qt.kill(mt,function(He){return function(){Jt--,Jt===0&&rt(He)()}})),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(M.right(void 0))();else for(ne=0,Qt=Jt;ne<Qt;ne++)Ct[ne]=Ct[ne]();return Ct}function Tt(mt,ft,rt){var nt,st,yt,Jt,Ct,Qt;for(M.isLeft(mt)?(nt=mt,st=null):(st=mt,nt=null);;){if(yt=null,Jt=null,Ct=null,Qt=null,pt!==null)return;if(ft===null){V(nt||st)();return}if(ft._3!==e)return;switch(ft.tag){case g:nt===null?(ft._3=M.right(ft._1(M.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,Ct=!0,Qt=U++,O[Qt]=lt(gt,nt===yt?ft._2:ft._1,function(){return function(){delete O[Qt],Ct?Ct=!1:rt===null?Tt(nt,null,null):Tt(nt,rt._1,rt._2)}}),Ct){Ct=!1;return}}else{if(yt===e||Jt===e)return;st=M.right(M.fromRight(yt)(M.fromRight(Jt))),ft._3=st}break;case l:if(yt=ft._1._3,Jt=ft._2._3,yt===e&&M.isLeft(Jt)||Jt===e&&M.isLeft(yt))return;if(yt!==e&&M.isLeft(yt)&&Jt!==e&&M.isLeft(Jt))nt=st===yt?Jt:yt,st=null,ft._3=nt;else if(ft._3=st,Ct=!0,Qt=U++,O[Qt]=lt(gt,st===yt?ft._2:ft._1,function(){return function(){delete O[Qt],Ct?Ct=!1:rt===null?Tt(st,null,null):Tt(st,rt._1,rt._2)}}),Ct){Ct=!1;return}break}rt===null?ft=null:(ft=rt._1,rt=rt._2)}}function Gt(mt){return function(ft){return function(){delete I[mt._1],mt._3=ft,Tt(ft,mt._2._1,mt._2._2)}}}function dt(){var mt=P,ft=X,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=H,st=ft,ft=new v(N,yt,new v(_,rt,nt),e),st=C(M,Y,st),st.onComplete({rethrow:!1,handler:Gt(ft)})(),I[yt]=st,Y&&Y.register(st)}break;case H: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(at=ft,yt=0;yt<Q;yt++)I[yt].run()}function Mt(mt,ft){pt=M.left(mt);var rt;for(var nt in O)if(O.hasOwnProperty(nt)){rt=O[nt];for(nt in rt)rt.hasOwnProperty(nt)&&rt[nt]()}O=null;var st=lt(mt,at,ft);return function(yt){return new v(i,function(Jt){return function(){for(var Ct in st)st.hasOwnProperty(Ct)&&st[Ct]();return b}})}}return dt(),function(mt){return new v(i,function(ft){return function(){return Mt(mt,ft)}})}}function W(M,Y,X){return new v(i,function(V){return function(){return D(M,Y,X,V)}})}return v.EMPTY=e,v.Pure=w(t),v.Throw=w(n),v.Catch=w(r),v.Sync=w(o),v.Async=w(i),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=F,v.nonCanceler=b,v})();let qi=null;function e0(){return qi||(typeof document>"u"?null:(qi=document.createElement("canvas").getContext("2d"),qi))}const ha=new Map,n0=e=>t=>n=>r=>{const o=`${n} ${t}px ${e}|${r}`,i=ha.get(o);if(i!==void 0)return i;const u=e0();if(!u)return r.length*t*.62;u.font=`${n} ${t}px ${e}`;const s=u.measureText(r).width;return ha.set(o,s),s},r0=e=>()=>e.clip("evenodd"),o0=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()},i0=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()}},u0=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Hi=e=>t=>n=>{const r=t.stroke;return()=>{const o=r.value,i=zc(e)(n);if(o!==n)return i(),t.stroke.value=n}},s0=e=>t=>n=>{const r=t.font;return()=>{const o=r.value,i=Xc(e)(n);if(o!==n)return i(),t.font.value=n}},kr=e=>t=>n=>{const r=t.fill;return()=>{const o=r.value,i=Ic(e)(n);if(o!==n)return i(),t.fill.value=n}},_o=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=Hc(e)((()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})())((()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()),a=r(i+3|0);return()=>(s(),a())}if(u===2){const s=qc(e)((()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})())((()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()),a=r(i+3|0);return()=>(s(),a())}if(u===3){const s=Kc(e)({cpx:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),cpy:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})(),x:(()=>{const f=i+3|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+4|0;return f>=0&&f<t.length?t[f]:0})()}),a=r(i+5|0);return()=>(s(),a())}if(u===4){const s=Zc(e)({cp1x:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),cp1y:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})(),cp2x:(()=>{const f=i+3|0;return f>=0&&f<t.length?t[f]:0})(),cp2y:(()=>{const f=i+4|0;return f>=0&&f<t.length?t[f]:0})(),x:(()=>{const f=i+5|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+6|0;return f>=0&&f<t.length?t[f]:0})()}),a=r(i+7|0);return()=>(s(),a())}if(u===5){const s=Vc(e),a=r(i+1|0);return()=>(s(),a())}return()=>{}},o=xu(e);return()=>(o(),r(0)())},a0=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),c0=e=>t=>{const n=Fc(e)({x:0,y:0,width:t.width,height:t.height});return()=>{n();const r=a0();return{ctx:e,surface:t,styleCache:r,maskDepth:{value:0}}}},f0={map:e=>t=>n=>{const r=t(n);return()=>{const o=r();return e(o)}}},g0=e=>Te(e.weight)+" "+fu(e.size)+"px Ilisarniq, ui-sans-serif, system-ui, sans-serif",Qe=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+")"},_0=e=>t=>n=>r=>{const o=kr(e)(n)(Qe(r));return()=>(o(),Yc(e)({x:0,y:0,width:t.width,height:t.height})())},d0=e=>t=>n=>{const r=t.font;return()=>(r.value="",t.fill.value="",t.stroke.value="",o0(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})())},l0=e=>t=>n=>r=>{const o=kr(e)(t)(Qe(r));return()=>(o(),_o(e)(n)(),Yo(e)())},h0=e=>t=>n=>r=>o=>{const i=kr(e)(t)(Qe(r));return()=>(i(),Hi(e)(t)(Qe(o.color))(),Qo(e)(o.width)(),Rr(e)((()=>{if(o.lineJoin==="RoundJoin")return Mr;if(o.lineJoin==="BevelJoin")return Uo;if(o.lineJoin==="MiterJoin")return Ko;c()})())(),ei(e)((()=>{if(o.lineCap==="ButtCap")return ti;if(o.lineCap==="RoundCap")return Zo;if(o.lineCap==="SquareCap")return jo;c()})())(),_o(e)(n)(),Yo(e)(),Vo(e)())},p0=e=>t=>n=>r=>o=>i=>{const u=xu(e);return()=>{if(u(),i0(e)(n.x)(n.y)(n.w)(n.h)(r)(),o.tag==="Just"?(kr(e)(t)(Qe(o._1.color))(),Yo(e)()):o.tag==="Nothing"||c(),i.tag==="Just")return Hi(e)(t)(Qe(i._1.color))(),Qo(e)(i._1.width)(),Rr(e)((()=>{if(i._1.lineJoin==="RoundJoin")return Mr;if(i._1.lineJoin==="BevelJoin")return Uo;if(i._1.lineJoin==="MiterJoin")return Ko;c()})())(),ei(e)((()=>{if(i._1.lineCap==="ButtCap")return ti;if(i._1.lineCap==="RoundCap")return Zo;if(i._1.lineCap==="SquareCap")return jo;c()})())(),Vo(e)();i.tag!=="Nothing"&&c()}},m0=e=>t=>n=>r=>{const o=Hi(e)(t)(Qe(r.color));return()=>(o(),Qo(e)(r.width)(),Rr(e)((()=>{if(r.lineJoin==="RoundJoin")return Mr;if(r.lineJoin==="BevelJoin")return Uo;if(r.lineJoin==="MiterJoin")return Ko;c()})())(),ei(e)((()=>{if(r.lineCap==="ButtCap")return ti;if(r.lineCap==="RoundCap")return Zo;if(r.lineCap==="SquareCap")return jo;c()})())(),_o(e)(n)(),Vo(e)())},y0=e=>t=>n=>{const r=kr(e)(t)(Qe(n.color));return()=>(r(),s0(e)(t)(g0(n.font))(),ff(e)((()=>{if(n.align==="AlignLeft")return rf;if(n.align==="AlignCenter")return uf;if(n.align==="AlignRight")return of;c()})())(),cf(e)((()=>{if(n.baseline==="BaselineTop")return jc;if(n.baseline==="BaselineMiddle")return tf;if(n.baseline==="BaselineAlphabetic")return ef;if(n.baseline==="BaselineBottom")return nf;c()})())(),Uc(e)(n.content)(n.x)(n.y)())},pa={apply:e=>t=>n=>{const r=e(n),o=t(n);return()=>{const i=r(),u=o();return i(u)}},Functor0:()=>f0},J0={bind:e=>t=>n=>{const r=e(n);return()=>{const o=r();return t(o)(n)()}},Apply0:()=>pa},N0=e=>t=>n=>{const r=u0(t.width/n.vw)(t.height/n.vh),o=vu(e)({translateX:(t.width-n.vw*r)/2-n.vx*r,translateY:(t.height-n.vh*r)/2-n.vy*r});return()=>(o(),Fo(e)({scaleX:r,scaleY:r})(),Rr(e)(Mr)())},x0={pure:e=>t=>()=>e,Apply0:()=>pa},v0={Applicative0:()=>x0,Bind1:()=>J0},T0={fillPath:e=>t=>n=>{const r=l0(n.ctx)(n.styleCache)(e)(t.color),o=n.maskDepth;return()=>{if(o.value===0)return r()}},strokePath:e=>t=>n=>{const r=m0(n.ctx)(n.styleCache)(e)(t),o=n.maskDepth;return()=>{if(o.value===0)return r()}},fillStrokePath:e=>t=>n=>r=>{const o=h0(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=p0(o.ctx)(o.styleCache)(e)(t)(n)(r),u=o.maskDepth;return()=>{if(u.value===0)return i()}},drawText:e=>t=>{const n=y0(t.ctx)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},pushTransform:e=>t=>{const n=nr(t.ctx),r=t.maskDepth;return()=>{if(r.value===0)return n(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="",vu(t.ctx)({translateX:e.tx,translateY:e.ty})(),Fo(t.ctx)({scaleX:e.sx,scaleY:e.sy})()}},popTransform:e=>{const t=rr(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=nr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",_o(n.ctx)(e)(),t==="NonZero")return Qc(n.ctx)();if(t==="EvenOdd")return r0(n.ctx)();c()}}},popClip:e=>{const t=rr(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=nr(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 wu(t.ctx)(sf)();if(e==="Difference")return wu(t.ctx)(af)();c()}}},popBlend:e=>{const t=rr(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=nr(t.ctx),r=t.maskDepth;return()=>{if(r.value===0)return n(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="",Ac(t.ctx)(e)()}},popAlpha:e=>{const t=rr(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=N0(t.ctx)(t.surface)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:e=>t=>{const n=_0(t.ctx)(t.surface)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:e=>t=>{const n=d0(t.ctx)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},measureText:e=>t=>n=>{const r=n0(e.family)(e.size)(e.weight)(ys(t));return()=>r},Monad0:()=>v0};function w0(e,t){const n=t.x-e.x,r=t.y-e.y;return Math.sqrt(n*n+r*r)}function L0(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:w0(o,i)}}return n}function E0(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 ma(e,t){if(t.length===0)return[];const n=L0(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]=E0(n,t,i*r/e);return o}function k0(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 b0(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},f=t[(s+i)%n]||{x:0,y:0},g=a.x-f.x,d=a.y-f.y;u+=g*g+d*d}u<o&&(o=u,r=i)}return k0(r,t)}const ya=e=>t=>n=>{const r=ma(e,t),o=ma(e,n),i=b0(r,o);return{from:r,to:i}};function Ja(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 C0(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 S0(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 P0(e){return e<0?0:e>1?1:e}const Na=e=>t=>n=>r=>{const o=t.length;if(o===0)return[];const i=Ja(t),u=Ja(n),s=C0(i,u),a=new Array(o);let f=1/0,g=-1/0;for(let _=0;_<o;_++){const h=t[_],p=(h.x-i.x)*s.x+(h.y-i.y)*s.y;a[_]=p,p<f&&(f=p),p>g&&(g=p)}const d=g-f;let l=new Array(o);for(let _=0;_<o;_++){const h=t[_],p=n[_];if(p===void 0){l[_]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(a[_]-f)/d),J=Math.max(1e-4,1-m),N=P0((e-m)/J),v=N*N*(3-2*N);l[_]={x:h.x+(p.x-h.x)*v,y:h.y+(p.y-h.y)*v}}for(let _=0;_<r.smoothPasses;_++)l=S0(.5,l);return l},G0=e=>e,xa=e=>e,lo=e=>e,va=e=>e,D0=e=>e,Ta=e=>e,wa=e=>e,La=wa("BaselineTop"),ho=wa("BaselineMiddle"),Vi=Ta("AlignLeft"),Yi=Ta("AlignCenter"),Xe=D0("RoundJoin"),fn=va("ButtCap"),W0=va("RoundCap"),M0=lo("LayerPolyOut"),R0=lo("LayerPolyIn"),I0=lo("LayerNodeMask"),z0=lo("LayerOverlay"),Ea=xa("NonZero"),B0=xa("EvenOdd"),A0=G0("Difference"),Fn={r:255,g:255,b:255,a:255},Ue={r:26,g:26,b:26,a:255},Fi=(e,t,n)=>({tag:e,_1:t,_2:n}),Ke=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},br=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},ka=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Tn=e=>t=>n=>{const r=ht.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),i=ht.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;c()},Ee=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Ze=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),$i=e=>t=>{const n=it.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},ba=jt(E)(zt),Ca=y(er)(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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Sa=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())},Q0=e=>({x:e.x,y:e.y,w:e.w,h:e.h}),q0=y(e=>t=>e+t.len)(0),H0=e=>{const t=Vt(n=>T,n=>r=>k("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(Wt(1,e.length,e))(n=>[2,n.x,n.y]),5];c()},V0=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(br)(0)($(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}},Y0={r:26,g:26,b:26,a:255},F0={r:214,g:211,b:209,a:255},Pa=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]},$0=e=>t=>n=>y(r=>o=>{const i=ka(o)(t);if(i.tag==="Nothing")return r;if(i.tag==="Just"){const u=V0(i._1)(r.obstacles);return{acc:Z(E)(o)(u)(r.acc),obstacles:me(r.obstacles)(u)}}c()})({acc:q,obstacles:n})(e).acc,O0=e=>{const t=Vt(n=>T,n=>r=>k("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()},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))};c()},Ga=e=>t=>St(Ze(e.nodes))(n=>{const r=Ee(n._1)(t.nodes);return r.tag==="Just"&&mo(r._1).alpha>0?Pa(n._2)(7):[]}),X0=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,...Ga(t)(n)],yo=e=>t=>n=>$(r=>{const o=_t(r)/_t(n);return{x:e.x+(t.x-e.x)*o,y:e.y+(t.y-e.y)*o}})(Ht(0,n-1|0)),U0=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 $(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])},Da=e=>{const t=li(`
|
|
6
|
-
`)(e);return t.length===0?[""]:t},
|
|
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(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)(k("Just",{color:Fn,flat:!1}))(k("Just",{color:Ue,width:1.25,lineJoin:Xe,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:Yi,baseline:ho}))(Dt(Sn)(d)))(()=>r.bind(i)(()=>u)))));return _.alpha>0?m:n.pure()}},Z0=e=>{const t=K0(e),n=e.Monad0().Applicative0(),r=je(n);return o=>i=>r(u=>{const s=Ee(u._1)(i.nodes);if(s.tag==="Just")return t(u._1)(u._2)(s._1);if(s.tag==="Nothing")return n.pure();c()})(Ze(o.nodes))},Xi=e=>t=>{const n=t.y-e.y,r=t.x-e.x;return Cn(r*r+n*n)},j0=e=>pe(t=>n=>({a:t,b:n,len:Xi(t)(n)}),e,Wt(1,e.length,e)),th=e=>t=>{const n=t.length-1|0,r=n>=0&&n<t.length?k("Just",t[n]):T,o=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];c()})(),i=0<t.length?k("Just",t[0]):T,u=(()=>{if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return{x:0,y:0};c()})(),s=t.length;return s<3?t:[u,...St(Ht(1,s-2|0))(a=>{const f=a+1|0,g=f>=0&&f<t.length?k("Just",t[f]):T,d=a>=0&&a<t.length?k("Just",t[a]):T,l=a-1|0,_=l>=0&&l<t.length?k("Just",t[l]):T;if(_.tag==="Just"&&d.tag==="Just"&&g.tag==="Just"){const h=d._1,p=Xi(h)(g._1),m=Xi(_._1)(h),J=Ke(e)(p/2),N=Ke(e)(m/2),v=p>0?J/p:0,w=h.x+(g._1.x-h.x)*v,b=h.y+(g._1.y-h.y)*v,L=m>0?N/m:0,S=h.x+(_._1.x-h.x)*L,z=h.y+(_._1.y-h.y)*L;return $(F=>{const j=_t(F)/_t(10),G=1-j;return{x:G*G*S+2*G*j*h.x+j*j*w,y:G*G*z+2*G*j*h.y+j*j*b}})(Ht(0,10))}return[]}),...o]},eh=e=>{const t=e.Monad0(),n=t.Bind1(),r=t.Applicative0(),o=je(r);return i=>u=>s=>a=>f=>g=>{const d=hi(g).length,l=_t(d+1|0),_=m=>{const J=(s*l-_t(m))/1.5,N=J<0?0:J>1?1:J;return N*N*(3-2*N)},h=(m=>{let J=m,N=!0,v;for(;N;){const w=J;if(w>=d){N=!1,v=w;continue}if(_(w)>=1){J=w+1|0;continue}N=!1,v=w}return v})(0),p=h>=d?[]:_n(m=>_(m)>0)(Ht(h,d-1|0)).init;return n.bind((()=>{const m=e.drawText({x:a,y:f,content:oe(h)(g),font:i,color:u,align:Vi,baseline:ho});return h>0?m:r.pure()})())(()=>o(m=>n.bind(e.measureText(i)(oe(m)(g)))(J=>{const N=_(m);return e.drawText({x:a+J,y:f-(1-N)*10,content:oe(1)(fr(hn(oe(m)(g)))(g)),font:i,color:{...u,a:tr(mu(N*_t(u.a)))},align:Vi,baseline:ho})}))(p))}},Jo=e=>t=>n=>r=>{const o=$(h=>_t($i(1)(hi(h).length)))(r),i=br(1)(y(er)(0)(o)),u=br(.05)(1-t-n),s=e<t?0:e>1-n?1:(e-t)/u,a=s*i,f=$i(1)(r.length),g=(h=>p=>m=>{let J=h,N=p,v=m,w=!0,b;for(;w;){const L=J,S=N,z=Vt(F=>T,F=>j=>k("Just",{head:F,tail:j}),v);if(z.tag==="Nothing"){w=!1,b=$i(0)(f-1|0);continue}if(z.tag==="Just"){if(S+z._1.head>=a){w=!1,b=L;continue}J=L+1|0,N=S+z._1.head,v=z._1.tail;continue}c()}return b})(0)(0)(o),d=y(er)(0)(g<1?[]:Wt(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 p=(s-l)/(h-l);return p<0?0:p>1?1:p})()}}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})()}},nh=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})})},rh=e=>{const t=e.Monad0(),n=t.Bind1(),r=nh(e),o=t.Applicative0(),i=Ir.traverse(o);return u=>s=>n.Apply0().Functor0().map(a=>ba(bt(f=>f)(a)))(i(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=>o.pure(k("Just",x(a._1,g))));if(f.tag==="Nothing")return o.pure(T);c()}return o.pure(T)})(Ze(s.tokens)))},Wa=e=>t=>$(n=>{const r=6.283185307179586*_t(n)/_t(64);return{x:e.x+t*bo(r),y:e.y+t*So(r)}})(Ht(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]},oh=e=>{const t=e.Monad0().Bind1(),n=e.popAlpha;return r=>o=>i=>u=>s=>a=>f=>{const g={x:i.x+i.w/2,y:i.y+i.h/2},d=br(.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(Ui(p)(6))({color:r,flat:!0})({color:o,width:1,lineJoin:Xe,lineCap:fn}))(()=>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)})())}},ih={r:255,g:235,b:130,a:255},uh=e=>{const t=e.length;return t===0?{x:0,y:0}:{x:Ca($(n=>n.x)(e))/_t(t),y:Ca($(n=>n.y)(e))/_t(t)}},Ma=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,f=o&&n<=1e-4;return{popScale:a?u:i?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(i){const g=(1-e)/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}return 1})()}},sh=e=>{const t=e.Monad0().Bind1(),n=Sa(e);return r=>o=>i=>u=>{const s=Ma(i)(0)(0),a={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500},f=Jo(i)(0)(0)(u);return t.bind(e.measureText(a)(f.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,p=l-_/2,m=[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)(k("Just",{color:F0,flat:!0}))(T))(()=>t.bind(e.drawRoundedRect({x:p,y:h,w:_,h:25.2})(6)(k("Just",{color:ih,flat:!0}))(k("Just",{color:d,width:1,lineJoin:Xe,lineCap:fn})))(()=>t.bind(e.strokePath(m)({color:d,width:1,lineJoin:Xe,lineCap:fn}))(()=>e.drawText({x:l,y:J.y,content:f.line,font:a,color:Ue,align:Yi,baseline:ho})))))})}},Ra={r:0,g:0,b:0,a:0},ah=e=>t=>e.backgroundDots({viewport:{vx:t.x,vy:t.y,vw:t.w,vh:t.h},bgColor:Ra,dotColor:Y0,tile:1.6,dotRadius:.25}),ch={r:214,g:211,b:209,a:255},Ia={r:255,g:255,b:255,a:255},fh=e=>{const t=e.Monad0().Bind1();return n=>r=>n?t.bind(e.clearBackground(Ra))(()=>e.setViewport(r)):t.bind(e.setViewport(r))(()=>e.backgroundDots({viewport:r,bgColor:Ia,dotColor:ch,tile:12,dotRadius:.7}))},gh=e=>{const t=e.Monad0(),n=t.Applicative0(),r=t.Bind1(),o=e.popClip,i=e.popTransform,u=e.popAlpha;return s=>a=>f=>{const g=mo(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)(k("Just",{color:Ia,flat:!0}))(T))(()=>r.bind((()=>{const p=r.bind(e.pushClip(Pa(d)(7))(Ea))(()=>r.bind(ah(e)(d))(()=>o));return s?p:n.pure()})())(()=>r.bind(e.drawRoundedRect({x:d.x,y:d.y,w:d.w,h:d.h})(7)(T)(k("Just",{color:Ue,width:1.25,lineJoin:Xe,lineCap:fn})))(()=>r.bind(i)(()=>u))))));return g.alpha>0?h:n.pure()}},_h=e=>{const t=gh(e),n=e.Monad0().Applicative0(),r=je(n);return o=>i=>u=>r(s=>{const a=Ee(s._1)(u.nodes);if(a.tag==="Just")return t(o)(s._2)(a._1);if(a.tag==="Nothing")return n.pure();c()})(Ze(i.nodes))},dh=e=>{const t=e.Monad0().Applicative0();return n=>{const r=n.length-1|0,o=r<1?[]:Wt(0,r,n),i=o.length-1|0,u=i>=0&&i<o.length?k("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,f=n[s].x-u._1.x,g=Cn(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,J=h-_*8.75,N=[1,h,p,2,J+l*4.375,m+_*4.375,2,J-l*4.375,m-_*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=>$(i=>{const u=n+(r-n)*(_t(i)/_t(o));return{x:e.x+t*bo(u),y:e.y+t*So(u)}})(Ht(0,o-1|0)),za=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)]},lh=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,f={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-f.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const _=r.points[g].y-f.y;return _<0?-_<1e-4:_<1e-4})()})()?me(r.points)(s):[...r.points,f,s]:[f,s];return o.len<=0||i<=t||r.pos>=n?{...r,pos:i}:{pos:i,points:d}})({pos:0,points:[]})(e).points,hh=e=>t=>n=>{const r=Vt(o=>T,o=>i=>k("Just",{head:o,tail:i}),e);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const o=j0(e),i=q0(o),u=Tn(0)(i)(t*i),s=Tn(0)(i)(n*i);return s<=u?[]:lh(o)(u)(s)}c()},ph=e=>{const t=e.Monad0(),n=t.Applicative0(),r=dh(e);return o=>i=>u=>{const s=th(8)(i);if(u.hi<=u.lo)return n.pure();const a=hh(s)(u.lo)(u.hi);return a.length===0?n.pure():t.Bind1().bind(e.strokePath(O0(a))({color:Ue,width:.9375,lineJoin:Xe,lineCap:W0}))(()=>r(a))}},mh=e=>{const t=ph(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}}c()})());if(s.tag==="Nothing")return n.pure();c()})(Ze(o.edges))},Ba=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?k("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?k("Just",e[g]):T,l=(()=>{if(d.tag==="Just")return d._1;if(d.tag==="Nothing")return u;c()})(),_=ya(128)(za(5)(Oi(2)(t)))(Wa(f)(6)),h=br(.05)(1-o-i),p=r<o?0:r>1-i?1:(r-o)/h,m=f.x-s.x,J=2*(()=>{const K=f.y-s.y;return(m<0?-m:m)+(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)})(),w=J+ri(e)+v,b=w<=1e-4?1:1-v/w,L=w<=1e-4?0:J/w,S=b-L,z=ya(128)(Wa(l)(6))(za(5)(Oi(2)(n))),F={maxDelay:.4,smoothPasses:2},j=Iu(e)(Tn(0)(1)(S<=1e-4?0:(p-L)/S)),G=(()=>{if(j.tag==="Just")return j._1;if(j.tag==="Nothing")return f;c()})(),P=(()=>{if(b>=1)return 0;const K=(p-b)/(1-b),A=K<0?0:K>1?1:K;return A*A*(3-2*A)})(),et=(()=>{if(L<=1e-4)return 1;const K=p/L,A=K<0?0:K>1?1:K;return A*A*(3-2*A)})();return p<L?Fi("PolyShape",Na(et)(_.from)(_.to)(F)):p>=b?Fi("PolyShape",Na(P)(z.from)(z.to)(F)):Fi("CircleShape",G,6)},yh=e=>t=>n=>r=>o=>i=>u=>s=>a=>{const f=Ba(r)(o)(i)(u)(s)(a);if(f.tag==="CircleShape")return e.fillStrokePath(Ui(f._1)(f._2))({color:t,flat:!0})({color:n,width:1,lineJoin:Xe,lineCap:fn});if(f.tag==="PolyShape")return f._1.length>=3?e.fillStrokePath(H0(f._1))({color:t,flat:!0})({color:n,width:1,lineJoin:Xe,lineCap:fn}):e.Monad0().Applicative0().pure();c()},Aa=e=>{const t=oh(e),n=e.Monad0().Applicative0(),r=je(n);return o=>i=>u=>s=>r(a=>{if(a._2.tag==="Travelling"){const f=Ee(a._2._1.target)(o.nodes),g=Ee(a._2._1.source)(o.nodes);if(g.tag==="Just"&&f.tag==="Just"){const d=po(a._2._1.edge)(o.edges);if(d.tag==="Just")return yh(e)(u)(s)((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return _e(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)(o.nodes);if(f.tag==="Just")return e.drawRoundedRect((()=>{const g=Oi(2)(f._1);return{x:g.x,y:g.y,w:g.w,h:g.h}})())(5)(k("Just",{color:u,flat:!0}))(k("Just",{color:s,width:1,lineJoin:Xe,lineCap:fn}));if(f.tag==="Nothing")return n.pure();c()}return n.pure()})(Ze(i.tokens))},Jh=e=>{const t=e.Monad0(),n=t.Bind1(),r=Aa(e),o=e.popClip,i=e.popBlend,u=e.popLayer,s=t.Applicative0(),a=je(s);return f=>g=>n.bind(e.pushLayer(R0))(()=>n.bind(e.pushBlend(A0))(()=>n.bind(e.pushClip(Ga(f)(g))(Ea))(()=>n.bind(r(f)(g)(Fn)(Fn))(()=>n.bind(o)(()=>n.bind(i)(()=>n.bind(u)(()=>n.bind(e.pushLayer(I0))(()=>n.bind(a(d=>{const l=Ee(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)(k("Just",{color:Fn,flat:!1}))(T):s.pure()})(Ze(f.nodes)))(()=>u)))))))))},Nh=e=>{const t=e.Monad0().Bind1(),n=Aa(e),r=e.popClip,o=e.popLayer;return i=>u=>s=>t.bind(e.pushLayer(M0))(()=>t.bind(e.pushClip(X0(i)(u)(s))(B0))(()=>t.bind(n(u)(s)(Ue)(Fn))(()=>t.bind(r)(()=>o))))},Qa=e=>t=>n=>r=>o=>i=>{const u=Ba(e)(t)(n)(r)(o)(i);if(u.tag==="PolyShape")return uh(u._1);if(u.tag==="CircleShape")return u._1;c()},xh=e=>{const t=Sa(e),n=e.Monad0(),r=n.Bind1(),o=je(n.Applicative0()),i=eh(e);return u=>s=>a=>f=>g=>d=>l=>_=>{const h=Jo(f)(g)(d)(St(l)(Da)),p=h.line,m=h.phaseInLabel/.45,J=m<0?0:m>1?1:m,N=_.w,v=_.y,w=_.x,b=w+14,L=_.h,S=v+L/2;return t(Ma(f)(g)(d))(w)(v+L)({x:w+N/2,y:S})(r.bind(o(z=>e.fillPath(Ui(z)(1.5))({color:Ue,flat:!0}))(U0(_)(Qa(u)(s)(a)(f)(g)(d))))(()=>r.bind(e.drawRoundedRect({x:w,y:v,w:N,h:L})(3)(k("Just",{color:Ue,flat:!0}))(T))(()=>i({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Fn)(J)(b)(S)(p))))}},vh=e=>{const t=xh(e),n=e.Monad0(),r=n.Applicative0(),o=sh(e),i=n.Bind1(),u=je(r),s=e.popLayer;return a=>f=>g=>i.bind(e.pushLayer(z0))(()=>i.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=po(d._2._1.edge)(a.edges),p=ka(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 _e(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 o(a)(l._1)(d._2._1.progress)(d._2._1.labels);if(l.tag==="Nothing")return r.pure();c()}return r.pure()})(Ze(f.tokens)))(()=>s))},Th=e=>{const t=e.Monad0();return n=>r=>o=>i=>u=>s=>a=>{const f=Qa(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)(St(a)(Da)).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}))}},wh=e=>{const t=e.Monad0(),n=t.Bind1(),r=Th(e),o=t.Applicative0(),i=Ir.traverse(o);return u=>s=>n.Apply0().Functor0().map(a=>ba(bt(f=>f)(a)))(i(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=po(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 _e(d._1);c()})())(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(l=>o.pure(k("Just",x(a._1,l))))}return o.pure(T)})(Ze(s.tokens)))},Lh=e=>{const t=e.Monad0(),n=t.Bind1(),r=wh(e),o=rh(e);return i=>u=>n.bind(r(i)(u))(s=>n.bind(o(i)(u))(a=>t.Applicative0().pure($0((()=>{const f=g=>{if(g.tag==="Leaf")return q;if(g.tag==="Node")return $t("Node",g._1,g._2,g._3,void 0,f(g._5),f(g._6));c()};return xt(E.compare)(wt(we.foldr,f(s)))})())(s)([...$(Q0)((()=>{const f=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return f(g._5,It("Cons",g._4,f(g._6,d)));c()};return wt(qt.foldr,f(i.nodes,Bt))})()),...(()=>{const f=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return f(g._5,It("Cons",g._4,f(g._6,d)));c()};return wt(qt.foldr,f(a,Bt))})()]))))},Eh=e=>{const t=Lh(e),n=vh(e);return r=>o=>e.Monad0().Bind1().bind(t(r)(o))(i=>n(r)(o)(i))},kh=e=>t=>n=>{const r=Zu(t)(n.camera);return{vx:r.x-e.padding,vy:r.y-e.padding,vw:r.w+2*e.padding,vh:r.h+2*e.padding}},bh=(e=>{const t=e.Monad0().Bind1(),n=fh(e),r=mh(e),o=_h(e),i=Z0(e),u=Nh(e),s=Jh(e),a=Eh(e);return f=>g=>d=>{const l=kh(f)(g)(d);return t.bind(n(f.transparentBg)(l))(()=>t.bind(r(g)(d))(()=>t.bind(o(f.halftoneShadows)(g)(d))(()=>t.bind(i(g)(d))(()=>t.bind(u(l)(g)(d))(()=>t.bind(s(g)(d))(()=>t.bind(a(g)(d))(()=>t.bind(f.watermark===""?e.Monad0().Applicative0().pure():e.drawText({x:l.vx+6,y:l.vy+6,content:f.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:Vi,baseline:La}))(()=>d.frameTitle===""?e.Monad0().Applicative0().pure():e.drawText({x:l.vx+l.vw/2,y:l.vy+12,content:d.frameTitle,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:13,weight:600},color:{r:80,g:80,b:80,a:255},align:Yi,baseline:La})))))))))}})(T0),Ch=e=>t=>n=>r=>{const o=c0(e)(t);return()=>{const i=o();return bh({padding:24,transparentBg:!1,halftoneShadows:!0,watermark:""})(n)(r)(i)()}},Cr=e=>({bind:t=>n=>r=>e.Bind1().bind(t(r))(o=>n(o._1)(o._2)),Apply0:()=>qa(e)}),qa=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=Cr(e);return o=>i=>r.bind(o)(u=>r.bind(i)(s=>Sr(e).pure(u(s))))})(),Functor0:()=>n}},Sr=e=>({pure:t=>n=>e.Applicative0().pure(x(t,n)),Apply0:()=>qa(e)}),Sh=e=>{const t={Applicative0:()=>Sr(e),Bind1:()=>Cr(e)};return{state:n=>r=>e.Applicative0().pure(n(r)),Monad0:()=>t}},Ki=(e,t)=>({tag:e,_1:t}),wn=(e,t)=>({tag:e,_1:t}),ve=Sh(rn),At=Cr(rn),ke=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=E.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}}c()}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=E.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}}c()}return o},ce=Sr(rn),Ph=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=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Gh=(()=>{const e=Pe.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return k("Just",x(t._1,t._2));c()});return t=>e((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._3,n(r._6,o)));c()};return n(t,Bt)})())})(),Dh=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=E.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}}c()}return o},Zi=e=>t=>n=>y(r=>o=>e.Bind1().bind(r)(i=>t(i)(o)))(e.Applicative0().pure(n)),Wh=y(e=>t=>Z(E)(t)()(e))(q),Mh=(()=>{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(E)(a._1)()(s),o=a._2;continue}c()}return u})(q);return t=>e((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._3,n(r._6,o)));c()};return n(t,Bt)})())})(),Ha=dc(ce)(zt),Rh=e=>Ki("Par",e),Va=e=>Ki("Seq",e),De=e=>ve.state(t=>x(void 0,(()=>{if(t.error.tag==="Just")return t;if(t.error.tag==="Nothing")return{...t,error:k("Just",{msg:e,line:t.currentLine,column:t.currentColumn})};c()})())),Ih=e=>At.bind(ke)(t=>{const n=e.tag==="Just"&&e._1!==""?e._1:"kf-"+Te(t.kfCounter);if(on(o=>o.id===n,t.keyframes))return De("duplicate frame name "+n);const r={...t,keyframes:me(t.keyframes)({id:n,nodes:t.currNodes,edges:t.currEdges}),kfCounter:t.kfCounter+1|0,currentKf:k("Just",n)};return ve.state(o=>x(void 0,r))}),zh=e=>t=>{const n=t.from+"->"+t.to,r=t.newFrom+"->"+t.newTo,o=Lt("Left","cannot repoint "+t.from+"\u2192"+t.to+": edge does not exist"),i=tn(n)(e.currEdges)?Lt("Right",void 0):o;return(()=>{if(i.tag==="Left"){const u=i._1;return s=>Lt("Left",u)}if(i.tag==="Right"){const u=i._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(!gn(t.newFrom)(e.currNodes))return Lt("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 Lt("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)?Lt("Left",a):Lt("Right",{nextCurrEdges:Z(E)(r)()(sr(E)(n)(e.currEdges)),newId:r,newEdge:{id:r,from:{node:t.newFrom,port:T},to:{node:t.newTo,port:T}}})})},Bh={graphNodes:q,graphEdges:q,currNodes:q,currEdges:q,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:T,currentLine:0,currentColumn:0,error:T},Ya=e=>t=>At.bind(ke)(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:k("Just",r),lastId:k("Just",r)}))}),Ah=e=>t=>{if(t.tag==="Token"){const n=t._1;return At.bind(ke)(r=>{const o=!gn(n.from)(r.currNodes),i=!gn(n.to)(r.currNodes);if(o||i)return At.bind(De(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)?Ya(e)(Vu("SendToken",{from:n.from,to:n.to,edge:s,direction:fg,labels:n.labels})):tn(u)(r.currEdges)?Ya(e)(Vu("SendToken",{from:n.from,to:n.to,edge:u,direction:gg,labels:n.labels})):At.bind(De("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})},Qh=e=>bt(t=>Ph(t)(e.graphEdges))(wt(jn,Gh(e.currEdges))),qh=e=>t=>{const n=ct(o=>o.from.node===t.id||o.to.node===t.id,Qh(e)),r=Zi(gc)(o=>i=>{const u=i.from+"->"+t.id,s=t.id+"->"+i.to,a=i.from+"->"+i.to,f="via "+i.from+" "+i.to+": no edge "+i.from+"\u2192"+t.id;if(!tn(u)(e.currEdges))return Lt("Left",f);const g="via "+i.from+" "+i.to+": no edge "+t.id+"\u2192"+i.to;if(!tn(s)(e.currEdges))return Lt("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)||Dh(a)(o.synthesized)?Lt("Left",d):Lt("Right",{consumed:Z(E)(u)()(Z(E)(s)()(o.consumed)),synthesized:Z(E)(a)({id:a,from:{node:i.from,port:T},to:{node:i.to,port:T}})(o.synthesized)})})({consumed:q,synthesized:q})(t.via);return(()=>{if(r.tag==="Left"){const o=r._1;return i=>Lt("Left",o)}if(r.tag==="Right"){const o=r._1;return i=>i(o)}c()})()(o=>{const i=o.consumed,u=ct(s=>!tn(s.id)(i),n);return u.length===0?Lt("Right",{nextCurrEdges:ye(E.compare,he,Fe(E.compare,e.currEdges,Wh($(s=>s.id)(n))),Mh((()=>{const s=a=>{if(a.tag==="Leaf")return q;if(a.tag==="Node")return $t("Node",a._1,a._2,a._3,void 0,s(a._5),s(a._6));c()};return s(o.synthesized)})())),synthesized:o.synthesized}):Lt("Left","cannot delete node "+t.id+": still connected ("+Rg(", ")($(s=>s.from.node+"\u2192"+s.to.node)(u))+"). Use -edge to drop them or `via a b` to merge "+t.id+"'s endpoints.")})},Fa=e=>{if(e.tag==="Leaf")return[e._1];if(e.tag==="Par"||e.tag==="Seq")return St(e._1)(Fa);c()},Hh=e=>({nodes:(()=>{const t=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return t(n._5,It("Cons",n._4,t(n._6,r)));c()};return wt(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,It("Cons",n._4,t(n._6,r)));c()};return wt(qt.foldr,t(e.graphEdges,Bt))})(),constraints:[]}),Vh=e=>{if(e.tag==="AddNode"){const t=e._1;return ve.state(n=>x(void 0,{...n,graphNodes:Z(E)(t.id)({id:t.id,size:x(1,1),ports:[],label:k("Just",t.label)})(n.graphNodes),currNodes:Z(E)(t.id)()(n.currNodes)}))}if(e.tag==="DelNode"){const t=e._1;return At.bind(ke)(n=>{if(!gn(t.id)(n.currNodes))return De("cannot delete node "+t.id+": does not exist");const r=qh(n)(t);if(r.tag==="Left")return De(r._1);if(r.tag==="Right"){const o=r._1;return ve.state(i=>x(void 0,{...i,currNodes:sr(E)(t.id)(i.currNodes),currEdges:o.nextCurrEdges,graphEdges:ye(E.compare,he,o.synthesized,i.graphEdges)}))}c()})}if(e.tag==="ModNode"){const t=e._1;return At.bind(ke)(n=>{if(!gn(t.id)(n.currNodes))return De("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:qf(E)(i=>k("Just",{...i,label:k("Just",r)}))(t.id)(o.graphNodes)}))}if(t.label.tag==="Nothing")return ce.pure();c()})}if(e.tag==="AddEdge"){const t=e._1;return At.bind(ke)(n=>{const r=!gn(t.from)(n.currNodes),o=!gn(t.to)(n.currNodes);if(r||o)return De("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(E)(i)({id:i,from:{node:t.from,port:T},to:{node:t.to,port:T}})(u.graphEdges),currEdges:Z(E)(i)()(u.currEdges)}))})}if(e.tag==="DelEdge"){const t=e._1;return At.bind(ke)(n=>{const r=t.from+"->"+t.to;return tn(r)(n.currEdges)?ve.state(o=>x(void 0,{...o,currEdges:sr(E)(r)(o.currEdges)})):De("cannot delete edge "+t.from+"\u2192"+t.to+": does not exist")})}if(e.tag==="RepointEdge"){const t=e._1;return At.bind(ke)(n=>{const r=zh(n)(t);if(r.tag==="Left")return De(r._1);if(r.tag==="Right"){const o=r._1;return ve.state(i=>x(void 0,{...i,currEdges:o.nextCurrEdges,graphEdges:Z(E)(o.newId)(o.newEdge)(i.graphEdges)}))}c()})}return ce.pure()},Yh=e=>At.bind(ve.state(t=>x(void 0,{...t,currentLine:e.line,currentColumn:e.column})))(()=>Vh(e.op)),Fh=e=>t=>At.bind(Ha(Yh)(t))(()=>At.bind(ke)(n=>{const r=e.tag==="Just"&&e._1!==""?e._1:"kf-"+Te(n.kfCounter);if(on(i=>i.id===r,n.keyframes))return De("duplicate frame name "+r);const o={...n,keyframes:me(n.keyframes)({id:r,nodes:n.currNodes,edges:n.currEdges}),kfCounter:n.kfCounter+1|0,currentKf:k("Just",r),scenes:(()=>{if(n.currentKf.tag==="Nothing")return n.scenes;if(n.currentKf.tag==="Just")return me(n.scenes)(Yu("Structural",{from:n.currentKf._1,to:r,focus:T}));c()})()};return ve.state(i=>x(void 0,o))})),$h=e=>t=>{const n=Vt(r=>T,r=>o=>k("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(Pr(e)(n._1.head))(o=>At.bind(Zi({Applicative0:()=>Sr(rn),Bind1:()=>Cr(rn)})(i=>u=>At.bind(Pr((()=>{if(i.lastId.tag==="Just")return ai("After",i.lastId._1);if(i.lastId.tag==="Nothing")return e;c()})())(u))(s=>ce.pure({events:[...i.events,...s.events],firstId:(()=>{if(i.firstId.tag==="Just")return k("Just",i.firstId._1);if(i.firstId.tag==="Nothing")return s.firstId;c()})(),lastId:(()=>{if(s.lastId.tag==="Just")return k("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return i.lastId;c()})()})))(o)(r))(i=>ce.pure(i)))}c()},Oh=e=>t=>{const n=Vt(r=>T,r=>o=>k("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(Pr(e)(n._1.head))(o=>At.bind(Xh((()=>{if(o.firstId.tag==="Just")return ai("With",o.firstId._1);if(o.firstId.tag==="Nothing")return e;c()})())(r))(i=>ce.pure({events:[...o.events,...i.events],firstId:o.firstId,lastId:(()=>{if(o.lastId.tag==="Just")return k("Just",o.lastId._1);if(o.lastId.tag==="Nothing")return i.lastId;c()})()})))}c()},Pr=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})))(()=>Ah(e)(n.op))}if(t.tag==="Seq")return $h(e)(t._1);if(t.tag==="Par")return Oh(e)(t._1);c()},Xh=e=>Zi({Applicative0:()=>Sr(rn),Bind1:()=>Cr(rn)})(t=>n=>At.bind(Pr(e)(n))(r=>ce.pure({events:[...t.events,...r.events],firstId:(()=>{if(t.firstId.tag==="Just")return k("Just",t.firstId._1);if(t.firstId.tag==="Nothing")return r.firstId;c()})(),lastId:(()=>{if(r.lastId.tag==="Just")return k("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return t.lastId;c()})()})))({events:[],firstId:T,lastId:T}),Uh=e=>At.bind(ke)(t=>{if(t.currentKf.tag==="Nothing")return De("flow ops before any structural frame");if(t.currentKf.tag==="Just"){const n=t.currentKf._1;return At.bind(Pr(cg)(e))(r=>At.bind(ke)(o=>{const i={...o,scenes:me(o.scenes)(Yu("DataFlow",{keyframe:n,events:r.events,focus:T}))};return ve.state(u=>x(void 0,i))}))}c()}),Kh=e=>At.bind(ke)(t=>{if(t.error.tag==="Just")return ce.pure();if(t.error.tag==="Nothing"){const n=Fa(e.ops),r=ct(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=ct(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=Fh(e.name)(r);return r.length!==0?i:ce.pure()})())(()=>At.bind((()=>{const i=Ih(e.name);return r.length===0&&o.length!==0?i:ce.pure()})())(()=>{const i=Uh(e.ops);return o.length!==0?i:ce.pure()}))}c()}),Zh=e=>At.bind(Ha(Kh)(e.frames))(()=>At.bind(ke)(t=>ce.pure((()=>{if(t.error.tag==="Just")return Lt("Left",t.error._1);if(t.error.tag==="Nothing")return Lt("Right",{seed:e.seed,graph:Hh(t),keyframes:t.keyframes,scenes:t.scenes});c()})())))(Bh)._1,$n=(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}),jh=e=>xo("More",e),tp=e=>xo("Lift",e),$a={map:e=>t=>(n,r,o,i,u)=>r(s=>t(n,r,o,i,(a,f)=>r(g=>u(a,e(f)))))},ep={alt:e=>t=>(n,r,o,i,u)=>{const s=n._1,a=n._2;return r(f=>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:()=>$a},np=e=>{const t=e.Monad0();return n=>r=>{const o=i=>{let u=i,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(o)(i=>r(n,jh,tp,(u,s)=>xo("Stop",u,Lt("Left",s)),(u,s)=>xo("Stop",u,Lt("Right",s))))}},Oa=(e,t,n,r,o)=>o(e,e._2),rp={index:0,line:1,column:1},op=(e=>{const t=np(e);return n=>r=>e.Monad0().Bind1().Apply0().Functor0().map(Dr)(t(B(n,rp,!1))(r))})(yf),Xa={apply:e=>t=>(n,r,o,i,u)=>r(s=>e(n,r,o,i,(a,f)=>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,f(_))))}))),Functor0:()=>$a},Ua={pure:e=>(t,n,r,o,i)=>i(t,e),Apply0:()=>Xa},ip={bind:e=>t=>(n,r,o,i,u)=>r(s=>e(n,r,o,i,(a,f)=>r(g=>t(f)(n._3&&!a._3?B(a._1,a._2,!0):a,r,o,i,u)))),Apply0:()=>Xa},up={Applicative0:()=>Ua,Bind1:()=>ip},vo=e=>(t,n,r,o,i)=>n(u=>Oa(t,n,r,o,(s,a)=>n(f=>o(t._3&&!s._3?B(s._1,s._2,!0):s,$n(e,a))))),sp={empty:vo("No alternative"),Alt0:()=>ep},ap={Applicative0:()=>Ua,Plus1:()=>sp},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(ku)(o))(r.pure(or("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return or("Loop",It("Cons",u._1,i));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=It("Cons",h._1,_),g=h._2;continue}c()}return l})(Bt)(i));c()})())))(Bt)})({tailRecM:e=>t=>(n,r,o,i,u)=>{const s=(a,f,g)=>e(f)(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);c()});return s(n,t,30)},Monad0:()=>up})(ap),Et=e=>t=>{const n=vo("Expected "+t);return(r,o,i,u,s)=>{const a=r._1,f=r._2;return o(g=>e(B(a,f,!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(f=>{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(p=>n(m=>vo("Negated parser succeeded")(_,n,r,g,(J,N)=>n(v=>i(_._3&&!J._3?B(J._1,J._2,!0):J,N))))))))})},cp=e=>{const t=e.foldr(n=>r=>{if(r.tag==="Nothing")return k("Just",n);if(r.tag==="Just")return k("Just",(o,i,u,s,a)=>{const f=o._1,g=o._2;return i(d=>n(B(f,g,!1),i,u,(l,_)=>{const h=l._3;return i(p=>h?s(l,_):r._1(o,i,u,s,a))},a))});c()})(T);return n=>{const r=t(n);if(r.tag==="Nothing")return vo("No alternative");if(r.tag==="Just")return r._1;c()}},fp=e=>t=>n=>(r,o,i,u,s)=>o(a=>o(f=>o(g=>o(d=>e(r,o,i,u,(l,_)=>o(h=>o(p=>{const m=r._3&&!l._3?B(l._1,l._2,!0):l;return n(m,o,i,u,(J,N)=>o(v=>{const w=m._3&&!J._3?B(J._1,J._2,!0):J;return o(b=>o(L=>{const S=r._3&&!w._3?B(w._1,w._2,!0):w;return t(S,o,i,u,(z,F)=>o(j=>s(S._3&&!z._3?B(z._1,z._2,!0):z,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=Og()(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)-Po(e.column-1|0)(8)|0}:{index:e.index+1|0,line:e.line,column:e.column+1|0}},gp=e=>t=>n=>{let r=e,o=t,i=n,u=!0,s;for(;u;){const a=r,f=o,g=i,d=Fr(f);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}c()}return s},Ft=e=>(t,n,r,o,i)=>{const u=Fr(t._1);if(u.tag==="Nothing")return o(t,$n("Unexpected EOF",t._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return o(t,$n("Expected Char",t._2));if(u._1.head>=0&&u._1.head<=65535){const s=ju(u._1.head);return e(s)?i(B(u._1.tail,tu(t._2)(u._1.head)(u._1.tail),!0),s):o(t,$n("Predicate unsatisfied",t._2))}}c()},Ka=(e,t,n,r,o)=>e._1===""?o(B(e._1,e._2,!0),void 0):r(e,$n("Expected EOF",e._2)),_p=e=>(t,n,r,o,i)=>{const u=e(t._1);if(u.tag==="Left")return o(t,$n(u._1,t._2));if(u.tag==="Right")return i(B(u._1.remainder,gp(t._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);c()},On=e=>_p(t=>{const n=jf(e)(t);return n.tag==="Just"?Lt("Right",{value:e,consumed:e,remainder:n._1}):Lt("Left","Expected "+ic(e))}),dp=Ft(e=>!0),Za=cp(zt),ja=(()=>{const e=Ft(t=>t===" "||t===" "||t===`
|
|
8
|
-
`||t==="\r");return(t,n,r,o,i)=>n(u=>e(t,n,r,o,(s,a)=>n(
|
|
9
|
-
`)),g=e._3&&!u._3?B(u._1,u._2,!0):u;return t(d=>
|
|
10
|
-
`||n==="\r");return(n,r,o,i,u)=>{const s=n._1,a=n._2;return r(
|
|
11
|
-
`:_==="t"?" ":_==="r"?"\r":_))))})))})(),
|
|
12
|
-
`);return(t,n,r,o,i)=>{const u=t._1,s=t._2;return n(a=>
|
|
13
|
-
`&&et!=="\r"&&et!=="#"&&et!=="}")),P=w._3&&!z._3?B(z._1,z._2,!0):z;return d(et=>G(P,d,l,N,(K,A)=>d(H=>h(P._3&&!K._3?B(K._1,K._2,!0):K,Mg(Wn(wt(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))))})(),yp=(e,t,n,r,o)=>{const i=e._1,u=e._2;return t(s=>tc(B(i,u,!1),t,n,(a,f)=>{const g=a._3;return t(d=>g?r(a,f):nu(e,t,n,r,o))},o))},Gr=Ft(e=>e>="0"&&e<="9"),Je=(()=>{const e=Et(Ft(t=>t==="_"))("'_'");return(t,n,r,o,i)=>n(u=>{const s=(g,d)=>n(l=>{const _=Ce((()=>{const p=Et(Ft(J=>J==="_"))("'_'"),m=Et(Ft(J=>J==="-"))("'-'");return(J,N,v,w,b)=>{const L=J._1,S=J._2;return N(z=>To(B(L,S,!1),N,v,(F,j)=>{const G=F._3;return N(P=>{if(G)return w(F,j);const et=J._1,K=J._2;return N(A=>Gr(B(et,K,!1),N,v,(H,R)=>{const C=H._3;return N(D=>{if(C)return w(H,R);const W=J._1,M=J._2;return N(Y=>p(B(W,M,!1),N,v,(X,V)=>{const Q=X._3;return N(I=>Q?w(X,V):m(J,N,v,w,b))},b))})},b))})},b))}})()),h=t._3&&!g._3?B(g._1,g._2,!0):g;return n(p=>_(h,n,r,o,(m,J)=>n(N=>i(h._3&&!m._3?B(m._1,m._2,!0):m,oi(d)+Wn(wt(qt.foldr,J))))))}),a=t._1,f=t._2;return n(g=>To(B(a,f,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?o(d,l):e(t,n,r,o,s))},s))})})(),Jp=Et((e,t,n,r,o)=>{const i=e._1,u=e._2;return t(s=>nu(B(i,u,!1),t,n,(a,f)=>{const g=a._3;return t(d=>g?r(a,f):Je(e,t,n,r,o))},o))})("frame name (identifier or quoted string)"),Np=(e,t,n,r,o)=>t(i=>Je(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>Ln(f,t,n,r,(d,l)=>t(_=>{const h=Et((m,J,N,v,w)=>{const b=m._1,L=m._2;return J(S=>On("->")(B(b,L,!1),J,N,(z,F)=>{const j=z._3;return J(G=>j?v(z,F):On("<-")(m,J,N,v,w))},w))})("'->' or '<-'"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=p._3&&!J._3?B(J._1,J._2,!0):J;return t(b=>Ln(w,t,n,r,(L,S)=>t(z=>{const F=Et(Je)("target node identifier"),j=w._3&&!L._3?B(L._1,L._2,!0):L;return t(G=>F(j,t,n,r,(P,et)=>t(K=>{const A=Ce((R,C,D,W,M)=>{const Y=R._3;return C(X=>C(V=>Ln(R,C,D,(Q,I)=>W(B(Q._1,Q._2,Y),I),(Q,I)=>C(U=>C(O=>{const gt=R._3&&!Q._3?B(Q._1,Q._2,!0):Q;return yp(gt,C,D,(pt,at)=>W(B(pt._1,pt._2,Y),at),(pt,at)=>C(lt=>M(gt._3&&!pt._3?B(pt._1,pt._2,!0):pt,at)))})))))}),H=j._3&&!P._3?B(P._1,P._2,!0):P;return t(R=>A(H,t,n,r,(C,D)=>t(W=>(()=>{if(N==="<-"){const Y=wn("Token",{from:et,to:s,labels:wt(qt.foldr,D)});return(X,V,Q,I,U)=>U(X,Y)}const M=wn("Token",{from:s,to:et,labels:wt(qt.foldr,D)});return(Y,X,V,Q,I)=>I(Y,M)})()(H._3&&!C._3?B(C._1,C._2,!0):C,t,n,r,o))))})))})))})))})))}))),xp=(e,t,n,r,o)=>t(i=>Gr(e,t,n,r,(u,s)=>t(a=>{const f=Ce(Gr),g=e._3&&!u._3?B(u._1,u._2,!0):u;return t(d=>f(g,t,n,r,(l,_)=>t(h=>{const p=mc(oi(s)+Wn(wt(qt.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(J,N,v,w,b)=>b(J,m)}if(p.tag==="Nothing")return(m,J,N,v,w)=>w(m,0);c()})()(g._3&&!l._3?B(l._1,l._2,!0):l,t,n,r,o)})))}))),wo=e=>(t,n,r,o,i)=>{const u=t._3;return n(s=>On(e)(t,n,r,(a,f)=>o(B(a._1,a._2,u),f),(a,f)=>n(g=>{const d=ji((()=>{const _=Et(Ft(p=>p==="_"))("'_'"),h=Et(Ft(p=>p==="-"))("'-'");return(p,m,J,N,v)=>{const w=p._1,b=p._2;return m(L=>To(B(w,b,!1),m,J,(S,z)=>{const F=S._3;return m(j=>{if(F)return N(S,z);const G=p._1,P=p._2;return m(et=>Gr(B(G,P,!1),m,J,(K,A)=>{const H=K._3;return m(R=>{if(H)return N(K,A);const C=p._1,D=p._2;return m(W=>_(B(C,D,!1),m,J,(M,Y)=>{const X=M._3;return m(V=>X?N(M,Y):h(p,m,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,p)=>o(B(h._1,h._2,u),p),(h,p)=>n(m=>{const J=l._3&&!h._3?B(h._1,h._2,!0):h;return n(N=>Se(J,n,r,(v,w)=>o(B(v._1,v._2,u),w),(v,w)=>n(b=>i(J._3&&!v._3?B(v._1,v._2,!0):v,e))))})))})))},vp=(e,t,n,r,o)=>t(i=>We(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>wo("via")(f,t,n,r,(d,l)=>t(_=>{const h=f._3&&!d._3?B(d._1,d._2,!0):d;return t(p=>Je(h,t,n,r,(m,J)=>t(N=>{const v=h._3&&!m._3?B(m._1,m._2,!0):m;return t(w=>We(v,t,n,r,(b,L)=>t(S=>{const z=v._3&&!b._3?B(b._1,b._2,!0):b;return t(F=>Je(z,t,n,r,(j,G)=>t(P=>o(z._3&&!j._3?B(j._1,j._2,!0):j,{from:J,to:G}))))})))})))})))}))),Xn=e=>(t,n,r,o,i)=>{const u=t._3;return n(s=>On(e)(t,n,r,(a,f)=>o(B(a._1,a._2,u),f),(a,f)=>n(g=>{const d=ji((()=>{const _=Et(Ft(p=>p==="_"))("'_'"),h=Et(Ft(p=>p==="-"))("'-'");return(p,m,J,N,v)=>{const w=p._1,b=p._2;return m(L=>To(B(w,b,!1),m,J,(S,z)=>{const F=S._3;return m(j=>{if(F)return N(S,z);const G=p._1,P=p._2;return m(et=>Gr(B(G,P,!1),m,J,(K,A)=>{const H=K._3;return m(R=>{if(H)return N(K,A);const C=p._1,D=p._2;return m(W=>_(B(C,D,!1),m,J,(M,Y)=>{const X=M._3;return m(V=>X?N(M,Y):h(p,m,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,p)=>o(B(h._1,h._2,u),p),(h,p)=>n(m=>i(l._3&&!h._3?B(h._1,h._2,!0):h,void 0))))})))},Tp=(e,t,n,r,o)=>t(i=>Xn("+edge")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>We(f,t,n,r,(d,l)=>t(_=>{const h=Et(Je)("source node identifier"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=p._3&&!J._3?B(J._1,J._2,!0):J;return t(b=>We(w,t,n,r,(L,S)=>t(z=>{const F=Et(Je)("target node identifier"),j=w._3&&!L._3?B(L._1,L._2,!0):L;return t(G=>F(j,t,n,r,(P,et)=>t(K=>o(j._3&&!P._3?B(P._1,P._2,!0):P,wn("AddEdge",{from:N,to:et})))))})))})))})))}))),wp=(e,t,n,r,o)=>t(i=>Xn("+node")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>We(f,t,n,r,(d,l)=>t(_=>{const h=Et(Je)("node identifier"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=p._3&&!J._3?B(J._1,J._2,!0):J;return t(b=>mp(w,t,n,r,(L,S)=>t(z=>o(w._3&&!L._3?B(L._1,L._2,!0):L,wn("AddNode",{id:N,label:S})))))})))})))}))),Lp=(e,t,n,r,o)=>t(i=>Xn("-edge")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>We(f,t,n,r,(d,l)=>t(_=>{const h=Et(Je)("source node identifier"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=p._3&&!J._3?B(J._1,J._2,!0):J;return t(b=>We(w,t,n,r,(L,S)=>t(z=>{const F=Et(Je)("target node identifier"),j=w._3&&!L._3?B(L._1,L._2,!0):L;return t(G=>F(j,t,n,r,(P,et)=>t(K=>o(j._3&&!P._3?B(P._1,P._2,!0):P,wn("DelEdge",{from:N,to:et})))))})))})))})))}))),Ep=(e,t,n,r,o)=>t(i=>Xn("-node")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>We(f,t,n,r,(d,l)=>t(_=>{const h=Et(Je)("node identifier"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=Ce((L,S,z,F,j)=>{const G=L._3;return vp(L,S,z,(P,et)=>F(B(P._1,P._2,G),et),j)}),b=p._3&&!J._3?B(J._1,J._2,!0):J;return t(L=>w(b,t,n,r,(S,z)=>t(F=>o(b._3&&!S._3?B(S._1,S._2,!0):S,wn("DelNode",{id:N,via:wt(qt.foldr,z)})))))})))})))}))),kp=(e,t,n,r,o)=>t(i=>Xn("~edge")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>We(f,t,n,r,(d,l)=>t(_=>{const h=Et(Je)("source node identifier"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=p._3&&!J._3?B(J._1,J._2,!0):J;return t(b=>We(w,t,n,r,(L,S)=>t(z=>{const F=Et(Je)("target node identifier"),j=w._3&&!L._3?B(L._1,L._2,!0):L;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(H=>Se(A,t,n,r,(R,C)=>t(D=>{const W=Et(On("->"))("'->'"),M=A._3&&!R._3?B(R._1,R._2,!0):R;return t(Y=>W(M,t,n,r,(X,V)=>t(Q=>{const I=M._3&&!X._3?B(X._1,X._2,!0):X;return t(U=>Se(I,t,n,r,(O,gt)=>t(pt=>{const at=Et(Je)("new source node identifier"),lt=I._3&&!O._3?B(O._1,O._2,!0):O;return t(Tt=>at(lt,t,n,r,(Gt,dt)=>t(Mt=>{const mt=lt._3&&!Gt._3?B(Gt._1,Gt._2,!0):Gt;return t(ft=>We(mt,t,n,r,(rt,nt)=>t(st=>{const yt=Et(Je)("new target node identifier"),Jt=mt._3&&!rt._3?B(rt._1,rt._2,!0):rt;return t(Ct=>yt(Jt,t,n,r,(Qt,ne)=>t(He=>o(Jt._3&&!Qt._3?B(Qt._1,Qt._2,!0):Qt,wn("RepointEdge",{from:N,to:et,newFrom:dt,newTo:ne})))))})))})))})))})))})))})))})))})))})))}))),bp=(e,t,n,r,o)=>t(i=>Oa(e,t,n,r,(u,s)=>t(a=>{const f=Et(Za([wp,Ep,kp,Tp,Lp,Np]))("statement (+node, -node, +edge, -edge, ~edge, or 'a -> b')"),g=e._3&&!u._3?B(u._1,u._2,!0):u;return t(d=>f(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})))))}))),Cp=(e,t,n,r,o)=>t(i=>Xn("seed")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>Ln(f,t,n,r,(d,l)=>t(_=>{const h=Et(xp)("integer (seed value)"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=p._3&&!J._3?B(J._1,J._2,!0):J;return t(b=>Se(w,t,n,r,(L,S)=>t(z=>o(w._3&&!L._3?B(L._1,L._2,!0):L,N))))})))})))}))),ru=fp((()=>{const e=Et(Ft(t=>t==="{"))("'{'");return(t,n,r,o,i)=>n(u=>n(s=>e(t,n,r,o,(a,f)=>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(p=>i(l._3&&!_._3?B(_._1,_._2,!0):_,h)))})))))})())(Et((()=>{const e=Et(Ft(t=>t==="}"))("'}'");return(t,n,r,o,i)=>n(u=>n(s=>Se(t,n,r,o,(a,f)=>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(p=>i(l._3&&!_._3?B(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),Sp=(e,t,n,r,o)=>t(i=>wo("seq")(e,t,n,r,(u,s)=>t(a=>ru(ou(Va))(e._3&&!u._3?B(u._1,u._2,!0):u,t,n,r,o)))),Pp=(e,t,n,r,o)=>t(i=>wo("par")(e,t,n,r,(u,s)=>t(a=>ru(ou(Rh))(e._3&&!u._3?B(u._1,u._2,!0):u,t,n,r,o)))),ou=e=>{const t=Ce(Gp());return(n,r,o,i,u)=>r(s=>t(n,r,o,i,(a,f)=>r(g=>u(n._3&&!a._3?B(a._1,a._2,!0):a,e(wt(qt.foldr,f))))))},Gp=oc(()=>{const e=ji(Et(Ft(t=>t==="}"))("'}'"));return(t,n,r,o,i)=>n(u=>{const s=t._3;return n(a=>n(f=>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,(p,m)=>o(B(p._1,p._2,s),m),(p,m)=>n(J=>{const N=h._3&&!p._3?B(p._1,p._2,!0):p;return n(v=>{const w=Za([(L,S,z,F,j)=>{const G=L._3;return Pp(L,S,z,(P,et)=>F(B(P._1,P._2,G),et),j)},(L,S,z,F,j)=>{const G=L._3;return Sp(L,S,z,(P,et)=>F(B(P._1,P._2,G),et),j)},bp]),b=t._3&&!N._3?B(N._1,N._2,!0):N;return n(L=>w(b,n,r,o,(S,z)=>n(F=>{const j=b._3&&!S._3?B(S._1,S._2,!0):S;return n(G=>Ln(j,n,r,o,(P,et)=>n(K=>{const A=j._3&&!P._3?B(P._1,P._2,!0):P;return n(H=>lp(A,n,r,o,(R,C)=>n(D=>i(A._3&&!R._3?B(R._1,R._2,!0):R,z))))})))})))})}))})))))})}),Dp=(e,t,n,r,o)=>t(i=>wo("frame")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>Jp(f,t,n,r,(d,l)=>t(_=>{const h=f._3&&!d._3?B(d._1,d._2,!0):d;return t(p=>Se(h,t,n,r,(m,J)=>t(N=>{const v=ru(ou(Va)),w=h._3&&!m._3?B(m._1,m._2,!0):m;return t(b=>v(w,t,n,r,(L,S)=>t(z=>{const F=w._3&&!L._3?B(L._1,L._2,!0):L;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:k("Just",l),ops:S}))))})))})))})))}))),Wp=(e,t,n,r,o)=>t(i=>Se(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>{const d=(h,p)=>t(m=>{const J=Ce(Dp),N=f._3&&!h._3?B(h._1,h._2,!0):h;return t(v=>J(N,t,n,r,(w,b)=>t(L=>{const S=N._3&&!w._3?B(w._1,w._2,!0):w;return t(z=>Se(S,t,n,r,(F,j)=>t(G=>{const P=Et(Ka)("'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,H)=>t(R=>o(et._3&&!A._3?B(A._1,A._2,!0):A,{seed:(()=>{if(p.tag==="Just")return p._1;if(p.tag==="Nothing")return 0;c()})(),frames:wt(qt.foldr,b)}))))})))})))}),l=f._1,_=f._2;return t(h=>t(p=>Cp(B(l,_,!1),t,n,(m,J)=>{const N=m._3;return t(v=>N?r(m,J):d(f,T))},(m,J)=>t(N=>d(m,k("Just",J))))))})}))),Mp=e=>{const t=op(e)(Wp);if(t.tag==="Left")return Lt("Left",{msg:t._1._1,line:t._1._2.line,column:t._1._2.column});if(t.tag==="Right")return Lt("Right",t._1);c()},Rp=e=>{const t=Mp(e);if(t.tag==="Left")return Lt("Left",t._1.msg);if(t.tag==="Right")return Lt("Right",t._1);c()};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 Ip(e){return function(t){return function(){t.textContent=e}}}function zp(e){return function(){return function(t){return e(t)()}}}function Bp(e){return function(t){return function(n){return function(r){return function(){return r.addEventListener(e,t,n)}}}}}const Ap=function(){return window};function Qp(e){return function(t){return function(){t.value=e}}}function qp(e){return function(){return e.valueAsNumber}}function Hp(e){return function(){return e.value}}function Vp(e){return function(t){return function(){return t.requestAnimationFrame(e)}}}const Yp=e=>e,Fp=e=>()=>e.clientWidth||0,$p=()=>window.devicePixelRatio||1,ec=(e,t)=>{t.innerHTML=e},Op=(e,t,n)=>{e.style.setProperty(t,n)},Xp=(e,t)=>e.querySelector(`[data-mg="${t}"]`),Up=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Kp=zt.foldMap(Nc),Zp=e=>t=>{const n=e-t*_t(tr(mu(e/t)));return t<=0?0:n<0?n+t:n},jp=`
|
|
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=`
|
|
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 fm=(function(Eo){"use strict";function oc(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=
|
|
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})({});
|