@markgrafhq/markgraf-embed 0.1.16 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,18 @@
1
- var Hv=(function(ku){"use strict";function Aa(t){let e=0,n;return()=>{if(e===2)return n;if(e===1)throw new Error("Binding demanded before initialized");return e=1,n=t(),e=2,n}}function g(){throw new Error("Failed pattern match")}function Cn(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const ke=t=>e=>t,z=function(t){return function(e){for(var n=e.length,r=new Array(n),i=0;i<n;i++)r[i]=t(e[i]);return r}},P1={map:z},Ma=t=>t,Tt=typeof Array.prototype.flatMap=="function"?function(t){return function(e){return t.flatMap(e)}}:function(t){return function(e){for(var n=[],r=t.length,i=0;i<r;i++)for(var o=e(t[i]),u=o.length,s=0;s<u;s++)n.push(o[s]);return n}},oe=function(t){return t.toString()},Oa=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},I1=function(t){var e=t.length;return'"'+t.replace(/[\0-\x1F\x7F"\\]/g,function(n,r){switch(n){case'"':case"\\":return"\\"+n;case"\x07":return"\\a";case"\b":return"\\b";case"\f":return"\\f";case`
2
- `:return"\\n";case"\r":return"\\r";case" ":return"\\t";case"\v":return"\\v"}var i=r+1,o=i<e&&t[i]>="0"&&t[i]<="9"?"\\&":"";return"\\"+n.charCodeAt(0).toString(10)+o})+'"'},Lu=t=>t,Ne=Lu("LT"),Je=Lu("GT"),Ge=Lu("EQ"),w=(t,e)=>({tag:t,_1:e}),J=w("Nothing"),Xt=t=>w("Just",t),Ra=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;g()},Ba=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;g()},Pt=(t,e)=>({tag:t,_1:e}),D1=t=>Pt("Right",t),Q1={map:t=>e=>{if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right")return Pt("Right",t(e._1));g()}},Wa={apply:t=>e=>{if(t.tag==="Left")return Pt("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right")return Pt("Right",t._1(e._1))}g()},Functor0:()=>Q1},F1={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Pt("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}g()},Apply0:()=>Wa},A1={pure:D1,Apply0:()=>Wa},za={Applicative0:()=>A1,Bind1:()=>F1},M1=t=>t,O1={map:t=>e=>t(e)},qa={apply:t=>e=>t(e),Functor0:()=>O1},R1={bind:t=>e=>e(t),Apply0:()=>qa},B1={pure:M1,Apply0:()=>qa},Xn={Applicative0:()=>B1,Bind1:()=>R1},W1=function(t){return function(){return t}},z1={apply:t=>e=>()=>{const n=t(),r=e();return Eu.pure(n(r))()},Functor0:()=>q1},Eu={pure:W1,Apply0:()=>z1},q1={map:t=>e=>()=>{const n=e();return t(n)}},ui=(t,e)=>({tag:t,_1:e}),Ha=t=>ui("Loop",t),H1={tailRecM:t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="Loop"){r=t(u._1);continue}if(u.tag==="Done"){i=!1,o=u._1;continue}g()}return o};return n=>e(t(n))},Monad0:()=>Xn},$1=function(t){return function(e){return function(){return t(e())}}},X1=function(t){return function(){return t}},Y1={map:$1},V1={apply:t=>e=>()=>{const n=t(),r=e();return $a.pure(n(r))()},Functor0:()=>Y1},$a={pure:X1,Apply0:()=>V1},U1=(function(t){return function(e){return function(n){return function(){return t(e,n)}}}})(function(t,e){return e.push(t)}),Z1=(t,e)=>({tag:"Iterator",_1:t,_2:e}),K1=t=>e=>n=>()=>{let r=!1;const i=e._2;for(;!r;){const o=i.value,u=e._1(o);if(u.tag==="Just"&&t(u._1)){n.push(u._1),e._2.value;const s=e._2.value;e._2.value=s+1|0;continue}r=!0}},j1=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const i=r.value,o=r.value;r.value=o+1|0;const u=t._1(i);if(u.tag==="Just"){e(u._1)();continue}if(u.tag==="Nothing"){n=!0;continue}g()}},si=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=i-1;o>=0;o--)r=t(n[o])(r);return r}}},T=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=0;o<i;o++)r=t(r)(n[o]);return r}}},Cu=t=>{const e=t.Apply0();return n=>r=>n.foldr(i=>{const o=r(i);return u=>e.apply(e.Functor0().map(s=>Ma)(o))(u)})(t.pure())},td=t=>{const e=Cu(t);return n=>{const r=e(n);return i=>o=>r(o)(i)}},Wt={foldr:si,foldl:T,foldMap:t=>{const e=t.mempty;return n=>Wt.foldr(r=>i=>t.Semigroup0().append(n(r))(i))(e)}},b=(t,e)=>({tag:"Tuple",_1:t,_2:e}),Sn=t=>e=>b(t,e),ro=t=>t._2,io=t=>t._1,Ft=function(t){return function(e){for(var n=e.length,r=Array(n),i=0;i<n;i++)r[i]=t(i)(e[i]);return r}};var Su=function(t){return function(e){return t===e}};const ed=Su,nd=Su,ai=Su,Gu=function(t){return function(e){return function(n){if(e.length!==n.length)return!1;for(var r=0;r<e.length;r++)if(!t(e[r])(n[r]))return!1;return!0}}},_n={eq:ai},rd={eq:nd},Er={eq:ed};var Pu=function(t){return function(e){return function(n){return function(r){return function(i){return r<i?t:r===i?e:n}}}}};const id=Pu,od=Pu,C={compare:Pu(Ne)(Ge)(Je),Eq0:()=>_n},ut={compare:od(Ne)(Ge)(Je),Eq0:()=>rd},it={compare:id(Ne)(Ge)(Je),Eq0:()=>Er},ud=function(t){return t},sd=(function(){function t(i){return[i]}function e(i){return function(o){return[i,o]}}function n(i){return function(o){return function(u){return[i,o,u]}}}function r(i){return function(o){return i.concat(o)}}return function(i){return function(o){return function(u){return function(s){return function(a){function c(f,d){switch(d-f){case 0:return u([]);case 1:return o(t)(s(a[f]));case 2:return i(o(e)(s(a[f])))(s(a[f+1]));case 3:return i(i(o(n)(s(a[f])))(s(a[f+1])))(s(a[f+2]));default:var l=f+Math.floor((d-f)/4)*2;return i(o(r)(c(f,l)))(c(l,d))}}return c(0,a.length)}}}}}})(),ad=t=>t,ar={traverse:t=>{const e=t.Apply0();return sd(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>ar.traverse(t)(ad),Functor0:()=>P1,Foldable1:()=>Wt},Dt=function(t,e){for(var n=t>e?-1:1,r=new Array(n*(e-t)+1),i=t,o=0;i!==e;)r[o++]=i,i+=n;return r[o]=i,r};var cd=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},gd=function(t,e){for(var n=[],r=0,i=0;i<t;i++)n[r++]=e;return n};const fd=typeof Array.prototype.fill=="function"?cd:gd,Ct=(function(){function t(i,o){this.head=i,this.tail=o}var e={};function n(i){return function(o){return new t(i,o)}}function r(i){for(var o=[],u=0,s=i;s!==e;)o[u++]=s.head,s=s.tail;return o}return function(i,o){return r(i(n)(e)(o))}})(),At=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},Xa=function(t,e,n,r){for(var i=0;i<r.length;i++){var o=n(r[i]);if(e(o))return o}return t},cr=function(t,e,n,r){for(var i=0,o=r.length;i<o;i++)if(n(r[i]))return t(i);return e},Ya=function(t,e,n,r){for(var i=r.length-1;i>=0;i--)if(n(r[i]))return t(i);return e},Va=function(t,e,n,r,i){if(n<0||n>i.length)return e;var o=i.slice();return o.splice(n,0,r),t(o)},Ua=function(t,e,n,r){if(n<0||n>=r.length)return e;var i=r.slice();return i.splice(n,1),t(i)},Yn=function(t,e,n,r,i){if(n<0||n>=i.length)return e;var o=i.slice();return o[n]=r,t(o)},Te=function(t){return t.slice().reverse()},Re=function(t){if(t.length<=1e4)return Array.prototype.concat.apply([],t);for(var e=[],n=0,r=t.length;n<r;n++)for(var i=t[n],o=0,u=i.length;o<u;o++)e.push(i[o]);return e},st=function(t,e){return e.filter(t)},_d=function(t,e,n){for(var r=n.length,i=e,o=new Array(r),u=0;u<r;u++)i=t(i)(n[u]),o[u]=i;return o},dd=(function(){function t(e,n,r,i,o,u){var s,a,c,f,d,l,_;for(s=o+(u-o>>1),s-o>1&&t(e,n,i,r,o,s),u-s>1&&t(e,n,i,r,s,u),a=o,c=s,f=o;a<s&&c<u;)d=i[a],l=i[c],_=n(e(d)(l)),_>0?(r[f++]=l,++c):(r[f++]=d,++a);for(;a<s;)r[f++]=i[a++];for(;c<u;)r[f++]=i[c++]}return function(e,n,r){var i;return r.length<2?r:(i=r.slice(0),t(e,n,i,r.slice(0),0,r.length),i)}})(),bt=function(t,e,n){return n.slice(t,e)},we=function(t,e,n){for(var r=e.length<n.length?e.length:n.length,i=new Array(r),o=0;o<r;o++)i[o]=t(e[o])(n[o]);return i},Be=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},Za=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Lt=t=>e=>dd(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),ld=t=>e=>Lt(n=>r=>t.compare(e(n))(e(r))),Ot=t=>e=>(()=>{const n=U1(e);return()=>{const r=[...t];return n(r)(),r}})()(),Cr=t=>{if(t.length===0)return t.length-1|0,J;const e=t.length-1|0;return e>=0&&e<t.length?w("Just",{init:bt(0,t.length-1|0,t),last:t[e]}):J},hd=t=>e=>n=>t>=0&&t<n.length?Yn(Xt,J,t,e(n[t]),n):J,gr=t=>e=>{const n=(r=>{let i=r,o=!0,u;for(;o;){const s=i;if(s>=0&&s<e.length){if(t(e[s])){i=s+1|0;continue}o=!1,u=w("Just",s);continue}o=!1,u=J}return u})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:bt(0,n._1,e),rest:bt(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};g()},Sr=t=>e=>{const n=Lt(r=>i=>t(r._2)(i._2))(Ft(Sn)(e));return 0<n.length?z(ro)(ld(it)(io)((()=>{const r=[n[0]];for(const i of n){const o=t((()=>{const u=r.length-1|0;if(u>=0&&u<r.length)return r[u]._2;g()})())(i._2);(o==="LT"||o==="GT"||o!=="EQ")&&r.push(i)}return r})())):[]},pd=t=>e=>{const n=[],r=Z1(i=>i>=0&&i<e.length?w("Just",e[i]):J,{value:0});return j1(r)(i=>()=>{const o=[];o.push(i),K1(t(i))(r)(o)(),n.push(o)})(),n},Vt=t=>e=>{const n=cr(Xt,J,t,e);return n.tag==="Just"?w("Just",e[n._1]):J},Ka=t=>e=>st(t,e),We=t=>e=>n=>{const r=cr(Xt,J,i=>t.eq(i)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},ja=t=>e=>Tt(e)(t),yt=t=>ja(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];g()}),tc=isFinite;function md(t,e,n,r){var i=parseFloat(t);return e(i)?n(i):r}const Vn=Math.abs,xd=Math.acos,fr=function(t){return function(e){return Math.atan2(t,e)}},oo=Math.ceil,nn=Math.cos,uo=Math.exp,hn=Math.floor,ec=Math.log,yd=function(t){return function(e){return Math.min(t,e)}},Iu=function(t){return function(e){return Math.pow(t,e)}},Un=Math.round,$e=Math.sin,Le=Math.sqrt,Nd=Math.tan,Jd=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},rt=function(t){return t},Td=(function(t){return function(e){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var i=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(o){if(i.test(o)){var u=parseInt(o,n);return(u|0)===u?t(u):e}else return e}}}})(Xt)(J)(10),nc=Jd(Xt)(J),de=t=>{if(!tc(t))return 0;if(t>=rt(2147483647))return 2147483647;if(t<=rt(-2147483648))return-2147483648;const e=nc(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;g()},qt=(t,e,n)=>({tag:t,_1:e,_2:n}),Ht=qt("Nil"),$t={foldr:t=>e=>{const n=$t.foldl(i=>o=>t(o)(i))(e),r=(i=>o=>{let u=i,s=o,a=!0,c;for(;a;){const f=u,d=s;if(d.tag==="Nil"){a=!1,c=f;continue}if(d.tag==="Cons"){u=qt("Cons",d._1,f),s=d._2;continue}g()}return c})(Ht);return i=>n(r(i))},foldl:t=>e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=t(s)(a._1),i=a._2;continue}g()}return u},foldMap:t=>{const e=t.mempty;return n=>$t.foldl(r=>{const i=t.Semigroup0().append(r);return o=>i(n(o))})(e)}},wd=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);u.push(n(a));var c=r(a);if(t(c))return u;s=e(c)}}}}}}},vd=t=>{if(t.tag==="Just")return t._1;g()},bd={unfoldr1:wd(Ra)(vd)(io)(ro)},kd=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);if(t(a))return u;var c=e(a);u.push(n(c)),s=r(c)}}}}}}},Ld=t=>{if(t.tag==="Just")return t._1;g()},Xe={unfoldr:kd(Ra)(Ld)(io)(ro),Unfoldable10:()=>bd},zt=(t,e,n,r,i,o,u)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u}),Ye=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),so=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),rc=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),Q=zt("Leaf"),pn=Ye("IterLeaf"),se=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return zt("Node",1,1,t,e,n,r);if(r.tag==="Node")return zt("Node",1+r._1|0,1+r._2|0,t,e,n,r);g()}if(n.tag==="Node"){if(r.tag==="Leaf")return zt("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return zt("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,t,e,n,r)}g()},ze=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?zt("Node",1,1,t,e,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;g()})()?se(r._5._3,r._5._4,se(t,e,n,r._5._5),se(r._3,r._4,r._5._6,r._6)):se(r._3,r._4,se(t,e,n,r._5),r._6):se(t,e,n,r);if(n.tag==="Node")return r.tag==="Node"?r._1>(n._1+1|0)?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;g()})()?se(r._5._3,r._5._4,se(t,e,n,r._5._5),se(r._3,r._4,r._5._6,r._6)):se(r._3,r._4,se(t,e,n,r._5),r._6):n._1>(r._1+1|0)?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?se(n._6._3,n._6._4,se(n._3,n._4,n._5,n._6._5),se(t,e,n._6._6,r)):se(n._3,n._4,n._5,se(t,e,n._6,r)):se(t,e,n,r):r.tag==="Leaf"&&n._1>1?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?se(n._6._3,n._6._4,se(n._3,n._4,n._5,n._6._5),se(t,e,n._6._6,r)):se(n._3,n._4,n._5,se(t,e,n._6,r)):se(t,e,n,r);g()},Gr=(t,e,n)=>{if(n.tag==="Leaf")return so(J,Q,Q);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const i=Gr(t,e,n._5);return so(i._1,i._2,ze(n._3,n._4,i._3,n._6))}if(r==="GT"){const i=Gr(t,e,n._6);return so(i._1,ze(n._3,n._4,n._5,i._2),i._3)}if(r==="EQ")return so(w("Just",n._4),n._5,n._6)}g()},ic=(t,e,n,r)=>{if(r.tag==="Leaf")return rc(t,e,n);if(r.tag==="Node"){const i=ic(r._3,r._4,r._5,r._6);return rc(i._1,i._2,ze(t,e,n,i._3))}g()},ci=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=ic(t._3,t._4,t._5,t._6);return ze(n._1,n._2,n._3,e)}g()},Gn=(t,e,n)=>{if(e.tag==="Leaf")return Q;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=Gr(t,n._3,e);return ci(Gn(t,r._2,n._5),Gn(t,r._3,n._6))}g()},ao=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return Q;if(r.tag==="Node"){const i=Gr(t,r._3,n),o=ao(t,e,i._2,r._5),u=ao(t,e,i._3,r._6);if(i._1.tag==="Just")return ze(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return ci(o,u)}g()},Ee=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const i=Gr(t,r._3,n),o=Ee(t,e,i._2,r._5),u=Ee(t,e,i._3,r._6);if(i._1.tag==="Just")return ze(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return ze(r._3,r._4,o,u)}g()},Ed=t=>e=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node"){const i=e(r._3)(r._4);if(i.tag==="Just")return ze(r._3,i._1,n(r._5),n(r._6));if(i.tag==="Nothing")return ci(n(r._5),n(r._6))}g()};return n},mn=(t=>e=>n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="IterLeaf"){i=!1,o=e();continue}if(u.tag==="IterEmit"){i=!1,o=t(u._1,u._2,u._3);continue}if(u.tag==="IterNode"){r=(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Leaf"){d=!1,l=_;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){c=Ye("IterEmit",h._3,h._4,_),f=h._5;continue}c=Ye("IterEmit",h._3,h._4,Ye("IterNode",h._6,_)),f=h._5;continue}g()}return l})(u._2)(u._1);continue}g()}return o})((t,e,n)=>w("Just",b(b(t,e),n)))(t=>J),vt=t=>e=>n=>r=>{const i=o=>{if(o.tag==="Leaf")return zt("Node",1,1,n,r,Q,Q);if(o.tag==="Node"){const u=t.compare(n)(o._3);if(u==="LT")return ze(o._3,o._4,i(o._5),o._6);if(u==="GT")return ze(o._3,o._4,o._5,i(o._6));if(u==="EQ")return zt("Node",o._1,o._2,n,e(o._4)(r),o._5,o._6)}g()};return i},j=t=>e=>n=>{const r=i=>{if(i.tag==="Leaf")return zt("Node",1,1,e,n,Q,Q);if(i.tag==="Node"){const o=t.compare(e)(i._3);if(o==="LT")return ze(i._3,i._4,r(i._5),i._6);if(o==="GT")return ze(i._3,i._4,i._5,r(i._6));if(o==="EQ")return zt("Node",i._1,i._2,e,n,i._5,i._6)}g()};return r},jt=t=>e=>e.foldl(n=>r=>j(t)(r._1)(r._2)(n))(Q),gi=t=>e=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node"){const i=t.compare(e)(r._3);if(i==="LT")return ze(r._3,r._4,n(r._5),r._6);if(i==="GT")return ze(r._3,r._4,r._5,n(r._6));if(i==="EQ")return ci(r._5,r._6)}g()};return n},oc=t=>{const e=t.compare;return n=>r=>i=>{const o=Gr(e,r,i),u=n(o._1);if(u.tag==="Nothing")return ci(o._2,o._3);if(u.tag==="Just")return ze(r,u._1,o._2,o._3);g()}},ue=function(t){return function(e){return t+e|0}},Pr=function(t){return function(e){return t+e}},Zn=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},Cd=function(t){return function(e){return t+e}},ee=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},Sd={append:Cd},Gd={append:ee},Pd={mempty:"",Semigroup0:()=>Sd},Id={mempty:[],Semigroup0:()=>Gd},Dd=null;function uc(t,e,n){return t==null?e:n(t)}function qv(t){return t}function Du(t){return function(e){return function(n){return t.apply(n,[e])}}}const Qd=Du(Number.prototype.toPrecision),Fd=Du(Number.prototype.toFixed),Ad=Du(Number.prototype.toExponential),fi=(t,e)=>({tag:t,_1:e}),_i=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},di=t=>{if(t.tag==="Precision")return Qd(t._1);if(t.tag==="Fixed")return Fd(t._1);if(t.tag==="Exponential")return Ad(t._1);g()},sc=function(t){return function(){console.log(t)}};function Md(){return Date.now()}function Od(t){return function(){return t.getContext("2d")}}function Rd(t){return function(){return t.width}}function Bd(t){return function(){return t.height}}function Wd(t){return function(e){return function(){t.width=e}}}function zd(t){return function(e){return function(){t.height=e}}}function Qu(t){return function(e){return function(){t.lineWidth=e}}}function qd(t){return function(e){return function(){t.fillStyle=e}}}function Hd(t){return function(e){return function(){t.strokeStyle=e}}}function Fu(t){return function(e){return function(){t.lineCap=e}}}function Au(t){return function(e){return function(){t.lineJoin=e}}}function $d(t){return function(e){return function(){t.globalCompositeOperation=e}}}function Xd(t){return function(e){return function(){t.globalAlpha=e}}}function ac(t){return function(){t.beginPath()}}function Mu(t){return function(){t.stroke()}}function Ou(t){return function(){t.fill()}}function Yd(t){return function(){t.clip()}}function li(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function cc(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function gc(t){return function(){t.closePath()}}function Vd(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function Ud(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function co(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function Ru(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function Zd(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function Kd(t){return function(e){return function(){t.textAlign=e}}}function jd(t){return function(e){return function(){t.textBaseline=e}}}function tl(t){return function(e){return function(){t.font=e}}}function el(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function _r(t){return function(){t.save()}}function dr(t){return function(){t.restore()}}function hi(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function nl(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const fc=t=>t,Bu=t=>t,Wu=t=>t,zu=t=>t,go=t=>t,rl=go("BaselineTop"),il=go("BaselineMiddle"),ol=go("BaselineAlphabetic"),ul=go("BaselineBottom"),sl=zu("AlignLeft"),al=zu("AlignRight"),cl=zu("AlignCenter"),qu=Wu("BevelJoin"),fo=Wu("RoundJoin"),Hu=Wu("MiterJoin"),$u=Bu("Round"),Xu=Bu("Square"),Yu=Bu("Butt"),gl=fc("SourceOver"),fl=fc("Difference"),_l=t=>e=>jd(t)((()=>{if(e==="BaselineTop")return"top";if(e==="BaselineHanging")return"hanging";if(e==="BaselineMiddle")return"middle";if(e==="BaselineAlphabetic")return"alphabetic";if(e==="BaselineIdeographic")return"ideographic";if(e==="BaselineBottom")return"bottom";g()})()),dl=t=>e=>Kd(t)((()=>{if(e==="AlignLeft")return"left";if(e==="AlignRight")return"right";if(e==="AlignCenter")return"center";if(e==="AlignStart")return"start";if(e==="AlignEnd")return"end";g()})()),_o=t=>e=>{if(e==="BevelJoin")return Au(t)("bevel");if(e==="RoundJoin")return Au(t)("round");if(e==="MiterJoin")return Au(t)("miter");g()},Vu=t=>e=>{if(e==="Round")return Fu(t)("round");if(e==="Square")return Fu(t)("square");if(e==="Butt")return Fu(t)("butt");g()},_c=t=>e=>$d(t)((()=>{if(e==="SourceOver")return"source-over";if(e==="SourceIn")return"source-in";if(e==="SourceOut")return"source-out";if(e==="SourceAtop")return"source-atop";if(e==="DestinationOver")return"destination-over";if(e==="DestinationIn")return"destination-in";if(e==="DestinationOut")return"destination-out";if(e==="DestinationAtop")return"destination-atop";if(e==="Lighter")return"lighter";if(e==="Copy")return"copy";if(e==="Xor")return"xor";if(e==="Multiply")return"multiply";if(e==="Screen")return"screen";if(e==="Overlay")return"overlay";if(e==="Darken")return"darken";if(e==="Lighten")return"lighten";if(e==="ColorDodge")return"color-dodge";if(e==="ColorBurn")return"color-burn";if(e==="HardLight")return"hard-light";if(e==="SoftLight")return"soft-light";if(e==="Difference")return"difference";if(e==="Exclusion")return"exclusion";if(e==="Hue")return"hue";if(e==="Saturation")return"saturation";if(e==="Color")return"color";if(e==="Luminosity")return"luminosity";g()})()),qe={foldr:t=>e=>{const n=$t.foldr(t)(e);return r=>n((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,qt("Cons",o._3,i(o._6,u)));g()};return i(r,Ht)})())}},ll=t=>{const e={append:(()=>{const n=t.compare;return r=>i=>Ee(n,ke,r,i)})()};return{mempty:Q,Semigroup0:()=>e}},pi=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},lr=function(t){return t.join("")},Kn=function(t){return t.split("")},lo=function(t){return t},jn=function(t){return t.length},dc=function(t){return function(e){return e.substr(0,t)}},mi=function(t){return function(e){return e.substring(t)}},hl=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},pl=t=>e=>{const n=hl(jn(t))(e);return n.before===t?w("Just",n.after):J},ml=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},xl=function(t){return t()},yl=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},Nl=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},hr=t=>BigInt(t),Jl=t=>Number(t),ho=t=>e=>t+e,po=t=>e=>t*e,Uu=t=>e=>t-e,lc=0n,mo=1n,hc=t=>e=>t^e,xi=t=>e=>t&e,Zu=t=>e=>t<<e,Ku=t=>e=>t>>e,Tl=t=>e=>t==e,wl=t=>e=>t===e?0:t>e?1:-1,vl={eq:Tl},pc={compare:t=>e=>{const n=wl(t)(e);return n===1?Je:n===0?Ge:Ne},Eq0:()=>vl},bl=yl(Xt)(J),kl=Nl(Xt)(J),mc=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=ut.compare(e._1)(n._1);return r==="LT"?Ne:r==="GT"?Je:ut.compare(e._2)(n._2)},Eq0:()=>t}})(),Ll=t=>e=>Vn(t._1-e._1)+Vn(t._2-e._2),pr=t=>t,xo=t=>t,le=xo("North"),he=xo("South"),Pn=xo("East"),In=xo("West"),tr=pr("Rectangle"),El=pr("Cylinder"),Cl=pr("Parallelogram"),Sl=pr("Diamond"),Gl=pr("Ellipse"),Pl=pr("Document"),Il=pr("Cloud"),xc=t=>t,yc=T(Pr)(0),Dl=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},xn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},yi=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Nc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Jc=t=>{const e={top:0,bottom:0,left:0,right:0},n=t.shape==="Cloud"?{...e,top:t.h*.38}:t.shape==="Cylinder"?{...e,bottom:5}:t.shape==="Document"?{...e,bottom:t.h*.05}:e;return[{x:t.x-n.left,y:t.y-n.top},{x:t.x+t.w+n.right,y:t.y+t.h+n.bottom}]},mr=t=>e=>{const n=we(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,c=s.x-u.x;return Le(c*c+a*a)})()}),t,bt(1,t.length,t)),r=yc(z(u=>u.len)(n)),i=Dl(0)(r)(e*r),o=u=>s=>a=>{let c=u,f=s,d=a,l=!0,_;for(;l;){const h=c,p=f,m=d,x=At(y=>J,y=>N=>w("Just",{head:y,tail:N}),h);if(x.tag==="Nothing"){const y=t.length-1|0;if(y>=0&&y<t.length){l=!1,_=t[y];continue}l=!1,_=m;continue}if(x.tag==="Just"){if(p<=x._1.head.len){const y=x._1.head.len<=0?0:p/x._1.head.len;l=!1,_={x:x._1.head.a.x+(x._1.head.b.x-x._1.head.a.x)*y,y:x._1.head.a.y+(x._1.head.b.y-x._1.head.a.y)*y};continue}c=x._1.tail,f=p-x._1.head.len,d=m;continue}g()}return _};return 0<t.length?w("Just",o(n)(i)(t[0])):J},Ql=t=>e=>{const n=xn(1)(t.w),r=xn(1)(t.h),i=xn(1)(e.w-8),o=xn(1)(e.h-8),u=yi(i/n)(o/r);return{scale:u,tx:e.x+4+(i-n*u)/2-t.x*u,ty:e.y+4+(o-r*u)/2-t.y*u}},Ni=t=>yc(we(e=>n=>{const r=n.y-e.y,i=n.x-e.x;return Le(i*i+r*r)},t,bt(1,t.length,t))),Fl=t=>e=>n=>r=>i=>{const o=0<t.length?w("Just",t[0]):J,u=(()=>{if(o.tag==="Nothing")return e;if(o.tag==="Just")return o._1;g()})(),s=t.length-1|0,a=s>=0&&s<t.length?w("Just",t[s]):J,c=(()=>{if(a.tag==="Nothing")return n;if(a.tag==="Just")return a._1;g()})(),f=xn(.05)(1-i.pre-i.post),d=r<i.pre?0:r>1-i.post?1:(r-i.pre)/f,l=c.x-n.x,_=2*(()=>{const v=c.y-n.y;return(l<0?-l:l)+(v<0?-v:v)})(),h=u.x-e.x,p=2*(()=>{const v=u.y-e.y;return(h<0?-h:h)+(v<0?-v:v)})(),m=p+Ni(t)+_,x=m<=1e-4?1:1-_/m,y=m<=1e-4?0:p/m;if(d<=y){const v=y<=1e-4?1:d/y;return{x:e.x+(u.x-e.x)*v,y:e.y+(u.y-e.y)*v}}if(d>=x){const v=x>=1?0:(d-x)/(1-x);return{x:c.x+(n.x-c.x)*v,y:c.y+(n.y-c.y)*v}}const N=mr(t)((d-y)/xn(1e-4)(x-y));if(N.tag==="Nothing")return u;if(N.tag==="Just")return N._1;g()},Al=t=>{const e=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return e(r._5,qt("Cons",r._4,e(r._6,i)));g()},n=At(r=>J,r=>i=>w("Just",{head:r,tail:i}),Tt(Ct($t.foldr,e(t.nodes,Ht)))(Jc));if(n.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(n.tag==="Just"){const r=T(i=>o=>({minX:yi(i.minX)(o.x),minY:yi(i.minY)(o.y),maxX:xn(i.maxX)(o.x),maxY:xn(i.maxY)(o.y)}))({minX:n._1.head.x,minY:n._1.head.y,maxX:n._1.head.x,maxY:n._1.head.y})(n._1.tail);return{x:r.minX,y:r.minY,w:r.maxX-r.minX,h:r.maxY-r.minY}}g()},ju={scale:1,tx:0,ty:0},Ve=t=>{const e=At(n=>J,n=>r=>w("Just",{head:n,tail:r}),[...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Tt(Ct($t.foldr,n(t.nodes,Ht)))(Jc)})(),...Re((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Ct($t.foldr,n(t.edges,Ht))})()),...Re((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Ct($t.foldr,n(t.chipExtras,Ht))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=T(r=>i=>({minX:yi(r.minX)(i.x),minY:yi(r.minY)(i.y),maxX:xn(r.maxX)(i.x),maxY:xn(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},Ml=t=>e=>(n=>r=>i=>{let o=n,u=r,s=i,a=!0,c;for(;a;){const f=o,d=u,l=s,_=At(h=>J,h=>p=>w("Just",{head:h,tail:p}),d);if(_.tag==="Nothing"){a=!1,c=l;continue}if(_.tag==="Just"){const h=Nc(_._1.head)(f.interiors);if(h.tag==="Nothing"){a=!1,c=l;continue}if(h.tag==="Just"){o=h._1,u=_._1.tail,s=(()=>{const p=Ql(Ve(h._1.layout))((()=>{const m=Nc(_._1.head)(f.layout.nodes);if(m.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:tr};if(m.tag==="Just")return m._1;g()})());return{scale:l.scale*p.scale,tx:l.scale*p.tx+l.tx,ty:l.scale*p.ty+l.ty}})();continue}}g()}return c})(t)(e)(ju),Tc=t=>t,wc=(t,e)=>({tag:t,_1:e}),ts=t=>t,Ji=(t,e)=>({tag:t,_1:e}),es=(t,e)=>({tag:t,_1:e}),Ti=ts("Animated"),Ol=ts("StaticStill"),Rl=ts("TitleCard"),Bl=es("First"),Wl=Tc("Forward"),zl=Tc("Backward"),ql=Ji("ExitNode"),vc=jt(C)(Wt),Hl=t=>si(e=>n=>({nodes:Ee(C.compare,ke,e.nodes,n.nodes),edges:Ee(C.compare,ke,e.edges,n.edges)}))({nodes:Q,edges:Q})(t.keyframes),$l=t=>e=>({entering:{nodes:Gn(C.compare,e.nodes,t.nodes),edges:Gn(C.compare,e.edges,t.edges)},leaving:{nodes:Gn(C.compare,t.nodes,e.nodes),edges:Gn(C.compare,t.edges,e.edges)},surviving:{nodes:ao(C.compare,ke,t.nodes,e.nodes),edges:ao(C.compare,ke,t.edges,e.edges)}}),yo=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ir=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},wi=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},ns=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Xl=T(t=>e=>j(C)(e)()(t))(Q),Yl=T(t=>e=>j(C)(e)()(t))(Q),Vl=(()=>{const t=Xe.unfoldr(mn);return e=>t(Ye("IterNode",e,pn))})(),bc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},kc=jt(C)(Wt),vi=t=>{const e=At(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=T(r=>i=>({minX:yo(r.minX)(i.x),minY:yo(r.minY)(i.y),maxX:Ir(r.maxX)(i.x),maxY:Ir(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},Ul=t=>{const e=At(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return J;if(e.tag==="Just")return w("Just",vi(t));g()},Zl=t=>e=>n=>Xl(Tt(Ct(qe.foldr,n))(r=>{const i=wi(r)(t);if(i.tag==="Just")return st(o=>!ns(o)(e),[i._1.source,i._1.target]);if(i.tag==="Nothing")return[];g()})),Kl=t=>t.kind.tag==="SendToken"?w("Just",b(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):J,jl=t=>t.tag==="DataFlow"?yt(Kl)(t._1.events):[],th=t=>e=>Yl(yt(n=>ns(n._2.source)(e)||ns(n._2.target)(e)?w("Just",n._1):J)(Vl(t))),eh=t=>{const e=t.length-1|0;return e>=0&&e<t.length?0<t.length?t[0].x===t[e].x&&t[0].y===t[e].y?w("Just",vi([t[0]])):w("Just",vi([t[0],t[e]])):J:0<t.length?w("Just",vi([t[0]])):J},No=t=>{const e=At(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=T(r=>i=>({minX:yo(r.minX)(i.x),minY:yo(r.minY)(i.y),maxX:Ir(r.maxX)(i.x+i.w),maxY:Ir(r.maxY)(i.y+i.h)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x+e._1.head.w,maxY:e._1.head.y+e._1.head.h})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},Lc=t=>e=>n=>{if(n.tag==="Leaf")return Ve(t);const r=th(e)(n),i=[...yt(o=>{const u=bc(o)(t.nodes);return u.tag==="Just"?w("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):J})(Ct(qe.foldr,Ee(C.compare,ke,n,Zl(e)(n)(r)))),...yt(o=>{const u=wi(o)(t.edges);return u.tag==="Just"?w("Just",vi(u._1)):J})(Ct(qe.foldr,r)),...yt(o=>{const u=wi(o)(t.chipExtras);if(u.tag==="Just")return Ul(u._1);if(u.tag==="Nothing")return J;g()})(Ct(qe.foldr,r))];return i.length===0?Ve(t):No(i)},bi=t=>e=>n=>{const r=[...yt(i=>i)([(()=>{const i=wi(n)(t.chipExtras);if(i.tag==="Just")return eh(i._1);if(i.tag==="Nothing")return J;g()})()]),...(()=>{const i=wi(n)(e);if(i.tag==="Just")return yt(o=>{const u=bc(o)(t.nodes);return u.tag==="Just"?w("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):J})([i._1.source,i._1.target]);if(i.tag==="Nothing")return[];g()})()];return r.length===0?Lc(t)(e)(Q):No(r)},rs=t=>e=>{const n=Ve(t),r=n.w/Ir(1e-4)(e.zoom),i=n.h/Ir(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-i/2,w:r,h:i}},nh=t=>Ee(C.compare,ke,kc(z(e=>b(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),kc(Tt(t.scenes)(jl))),is=t=>t,rh=t=>t,xr=is("Linear"),ih=is("EaseInOutQuad"),oh=is("SpringBouncy"),ki=t=>e=>n=>{const r=Le(1-e*e),i=t*r;return 1-uo(-e*t*n)*(nn(i*n)+e/r*$e(i*n))},uh=t=>{const e=ut.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ut.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},os=t=>e=>(()=>{if(t==="Linear")return rh;if(t==="EaseInQuad")return n=>n*n;if(t==="EaseOutQuad")return n=>1-(1-n)*(1-n);if(t==="EaseInOutQuad")return n=>n<.5?2*n*n:1-2*(1-n)*(1-n);if(t==="EaseInCubic")return n=>n*n*n;if(t==="EaseOutCubic")return n=>1-(1-n)*(1-n)*(1-n);if(t==="EaseInOutCubic")return n=>n<.5?4*n*n*n:1-(-2*n+2)*(-2*n+2)*(-2*n+2)/2;if(t==="EaseOutExpo")return n=>n>=1?1:1-Iu(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*uo(-6*n);if(t==="SpringBouncy")return ki(6)(.7);g()})()(uh(e)),Ec=t=>t,us=t=>t,Jo=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},Li=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Cc=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},sh=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ah=us("Hold"),ch=us("Gap"),gh=us("Move"),Ei=Ec("LinearLerp"),Sc=Ec("LogLerp"),fh=t=>e=>n=>{const r=n.center.y-e.center.y,i=n.center.x-e.center.x,o=Le(i*i+r*r),u=n.zoom-e.zoom,s=u<0?-u:u;return Jo(t.minTransition)(t.maxTransition)(Li(t.panSpeed<=0?t.minTransition:o/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:s/t.zoomSpeed))},_h=T(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:Ot(t)(e)})([]),Gc=t=>e=>{const n={x:0,y:0},r=0<t.length?t[0].pos:n,i=Ya(Xt,J,o=>o.t<=e,t);if(i.tag==="Nothing")return r;if(i.tag==="Just"){const o=i._1+1|0;if(o>=0&&o<t.length){if(i._1>=0&&i._1<t.length){const u=Jo(0)(1)(t[o].t<=t[i._1].t?0:(e-t[i._1].t)/(t[o].t-t[i._1].t));return{x:t[i._1].pos.x+(t[o].pos.x-t[i._1].pos.x)*u,y:t[i._1].pos.y+(t[o].pos.y-t[i._1].pos.y)*u}}return n}return i._1>=0&&i._1<t.length?t[i._1].pos:n}g()},ss=t=>e=>({center:{x:e.center.x*t.scale+t.tx,y:e.center.y*t.scale+t.ty},zoom:e.zoom/Li(1e-6)(t.scale)}),dh=t=>e=>n=>({center:{x:t.center.x+(e.center.x-t.center.x)*n,y:t.center.y+(e.center.y-t.center.y)*n},zoom:uo((()=>{const r=ec(Li(1e-6)(t.zoom));return r+(ec(Li(1e-6)(e.zoom))-r)*n})())}),lh=t=>e=>n=>{const r=os(n.easing)(Jo(0)(1)(n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT)));if(n.interp==="LinearLerp")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};if(n.interp==="LogLerp")return dh(n.fromCam)(n.toCam)(r);g()},hh=t=>e=>n=>r=>{const i=(u,s)=>Cc(fh(t)(u.toCam)(s.toCam))(u.endT-u.startT),o=T(u=>s=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:w("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 f=u.pending._1.toCam.zoom-s.toCam.zoom;return f<0?-f<.08:f<.08})()})()})()||i(u.pending._1,s)<=0?{acc:Ot(u.acc)(u.pending._1),pending:w("Just",s)}:{acc:Ot(Ot(u.acc)({...u.pending._1,endT:s.startT-i(u.pending._1,s)}))({startT:s.startT-i(u.pending._1,s),endT:s.startT,fromCam:u.pending._1.toCam,toCam:s.toCam,easing:s.easing,interp:Ei}),pending:w("Just",s)};g()})({acc:[],pending:J})(r);if(o.pending.tag==="Nothing")return o.acc;if(o.pending.tag==="Just")return Ot(o.acc)(o.pending._1);g()},ph=t=>e=>{const n=r=>{const i=Ya(Xt,J,o=>o.kind==="Hold"||o.kind==="Move",r<1?[]:bt(0,r,e));if(i.tag==="Just")return i._1>=0&&i._1<e.length?w("Just",e[i._1].toCam):J;if(i.tag==="Nothing")return J;g()};return Ft(r=>i=>{if(i.kind==="Hold")return{startT:i.startT,endT:i.endT,fromCam:i.fromCam,toCam:i.toCam,easing:i.easing,interp:Ei};if(i.kind==="Move")return{startT:i.startT,endT:i.endT,fromCam:i.fromCam,toCam:i.toCam,easing:xr,interp:Ei};if(i.kind==="Gap")return{startT:i.startT,endT:i.endT,fromCam:(()=>{const o=n(r);if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;g()})(),toCam:(()=>{const o=n(r),u=(()=>{if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;g()})(),s=r+1|0,a=cr(Xt,J,c=>c.kind==="Hold"||c.kind==="Move",s<1?e:bt(s,e.length,e));if(a.tag==="Just"){const c=(r+1|0)+a._1|0;return c>=0&&c<e.length?e[c].fromCam:u}if(a.tag==="Nothing")return u;g()})(),easing:i.easing,interp:Ei};g()})(e)},mh={padding:24,easing:xr,minZoom:.9,maxZoom:2.5,tokenZoomFloor:0,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:16},as=t=>e=>n=>{const r=e.w+n*2,i=e.h+n*2,o=Ve(t);return r<=0||i<=0||o.w<=0||o.h<=0?1:Cc(o.w/r)(o.h/i)},xh=T(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?w("Just",t[n]):J;return r.tag==="Just"&&r._1.fromCam.zoom===r._1.toCam.zoom&&r._1.fromCam.center.x===r._1.toCam.center.x&&r._1.fromCam.center.y===r._1.toCam.center.y&&e.fromCam.zoom===e.toCam.zoom&&e.fromCam.center.x===e.toCam.center.x&&e.fromCam.center.y===e.toCam.center.y&&(()=>{const i=r._1.toCam.center.x-e.toCam.center.x;return(i<0?-i<8:i<8)&&(()=>{const o=r._1.toCam.center.y-e.toCam.center.y;return(o<0?-o<8:o<8)&&(()=>{const u=r._1.toCam.zoom-e.toCam.zoom;return u<0?-u<.08:u<.08})()})()})()?Ot((()=>{const i=t.length-1|0;return i<1?[]:bt(0,i,t)})())({...r._1,endT:e.endT}):Ot(t)(e)})([]),Ci=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:Li(r)(Jo(t.minZoom)(t.maxZoom)(as(e)(n)(t.padding)))}),yh=t=>e=>n=>r=>{const i=Lt(s=>a=>it.compare(a.priority)(s.priority)),o=Ci(t)(e)(Ve(e))(0),u=st(s=>s>=0&&s<=n,_h(Lt(ut.compare)([0,n,...Tt(r)(s=>[s.startT,s.endT]),...Tt(r)(s=>{if(s.pathFollow.tag==="Nothing")return[];if(s.pathFollow.tag==="Just")return z(a=>a.t)(s.pathFollow._1.samples);g()})])));return hh(t)(e)(o)(xh(ph(o)(yt(s=>{const a=(s._1+s._2)/2;if(s._2<=s._1)return J;const c=yt(d=>d.pathFollow)(i(st(d=>d.startT<=a&&a<d.endT,r)));if(0<c.length)return w("Just",{kind:gh,startT:s._1,endT:s._2,fromCam:{center:Gc(c[0].samples)(s._1),zoom:c[0].zoom},toCam:{center:Gc(c[0].samples)(s._2),zoom:c[0].zoom},easing:xr});const f=z(d=>d.bbox)(st(d=>d.priority===T(sh)(0)(z(l=>l.priority)(st(l=>l.startT<=a&&a<l.endT,r))),st(d=>d.startT<=a&&a<d.endT,r)));return f.length===0?w("Just",{kind:ch,startT:s._1,endT:s._2,fromCam:o,toCam:o,easing:t.easing}):w("Just",{kind:ah,startT:s._1,endT:s._2,fromCam:Ci(t)(e)(No(f))(Be(d=>d.priority>=1,st(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),toCam:Ci(t)(e)(No(f))(Be(d=>d.priority>=1,st(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),easing:t.easing})})(we(Sn,u,bt(1,u.length,u))))))},Pc=t=>e=>n=>r=>{const i=Vt(o=>r>=o.startT&&r<o.endT)(n);if(i.tag==="Just")return lh()(r)(i._1);if(i.tag==="Nothing"){const o=n.length-1|0;if(o>=0&&o<n.length&&r>=n[o].endT)return n[o].toCam;const u=Ci(t)(e)(Ve(e))(0);return 0<n.length?n[0].fromCam:u}g()};function Dn(t){return t.charCodeAt(0)}function Ic(t){return String.fromCharCode(t)}const er=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},To=function(t){return function(e){return e.split(t)}},Nh=function(t){return t.trim()},wo=function(t){return function(e){return e.join(t)}};var Jh=typeof Array.from=="function",Th=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",wh=typeof String.prototype.fromCodePoint=="function",vh=typeof String.prototype.codePointAt=="function";const bh=function(t){return vh?function(e){return e.codePointAt(0)}:t},kh=function(t){return wh?String.fromCodePoint:t},Lh=function(t){return function(e){return Th?function(n){for(var r="",i=n[Symbol.iterator](),o=0;o<e;++o){var u=i.next();if(u.done)return r;r+=u.value}return r}:t(e)}},Eh=function(t){return function(e){return Jh?function(n){return Array.from(n,e)}:t}},vo=t=>{const e=jn(t);if(e===0)return J;if(e===1)return w("Just",{head:Dn(pi(0)(t)),tail:""});const n=Dn(pi(1)(t)),r=Dn(pi(0)(t));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?w("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:mi(2)(t)}):w("Just",{head:r,tail:mi(1)(t)})},Ch=t=>{const e=vo(t);return e.tag==="Just"?w("Just",b(e._1.head,e._1.tail)):J},Sh=t=>Xe.unfoldr(Ch)(t),Dc=bh(t=>{const e=Dn(pi(0)(t));if(55296<=e&&e<=56319&&jn(t)>1){const n=Dn(pi(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),bo=Eh(Sh)(Dc),cs=t=>lo(t>=0&&t<=65535?Ic(t):t<0?"\0":"\uFFFF"),Gh=kh(t=>t<=65535?cs(t):cs(Cn(t-65536|0,1024)+55296|0)+cs(Zn(t-65536|0)(1024)+56320|0)),Qc=t=>e=>{if(t<1)return"";const n=vo(e);return n.tag==="Just"?Gh(n._1.head)+Qc(t-1|0)(n._1.tail):e},me=Lh(Qc),Ph=t=>e=>e===""?J:w("Just",Dc(e)),Dr=(t,e,n)=>({tag:t,_1:e,_2:n}),Ih=()=>({tag:"ExtendFromSource"}),Qr=(t,e)=>({tag:t,_1:e}),gs=t=>t,ko=(t,e)=>({tag:t,_1:e}),fs=ko("NotYet"),Fc=ko("Consumed"),Dh=gs("FromSource"),Ac=gs("FromTarget"),Mc=gs("FromBoth"),Lo=Qr("Hidden"),Qh=Qr("Visible"),_s=Ih(),Eo=Dr("Retracted"),Fh=Dr("Extended"),Oc=t=>t,ds=(t,e)=>({tag:t,_1:e}),yr=(t,e,n)=>({tag:t,_1:e,_2:n}),Rc=t=>t,nr=(t,e)=>({tag:t,_1:e}),Fr=(t,e,n,r,i,o,u,s,a)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u,_7:s,_8:a}),Si=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},yn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Bc=jt(C)(Wt),ls=Gu(ai),Ar=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Co=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Gi=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Wc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},zc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Mr=(()=>{const t=Xe.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return w("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._3,n(r._6,i)));g()};return n(e,Ht)})())})(),Ah=T(t=>e=>j(C)(e)()(t))(Q),hs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},So=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Mh=nr("NoKeyframes"),Oh=t=>nr("DuplicateEventId",t),Rh=t=>nr("UnknownEvent",t),qc=Rc("PlopIn"),Bh=Rc("PlopOut"),Wh=Oc("DiveIn"),zh=Oc("DiveOut"),qh=t=>e=>n=>r=>{const i=Si(r.edge)(e.edges),o=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return Ni(i._1);g()})(),u=yn(t.minTokenDuration)(yn(rt(T(s=>a=>s+bo(a).length|0)(0)(r.labels))*t.tokenReadSecPerChar)(t.tokenSpeed<=0?0:o/t.tokenSpeed))+n.pre+n.post;return{duration:u,holdPre:u<=0?0:n.pre/u,holdPost:u<=0?0:n.post/u}},Hh=t=>e=>Bc(yt(n=>{if(n.kind.tag==="SendToken")return w("Just",b(n.id,{pre:(()=>{const r=n.when;return(()=>{const i=n.kind._1.from;return Be(o=>{if(o.kind.tag==="SendToken")return(r.tag==="First"?!1:r.tag==="After"&&r._1===o.id)&&o.kind._1.to===i;if(o.kind.tag==="FillNodeWithoutTransition")return!1;g()},e)})()?0:t.tokenHold})(),post:(()=>{const r=n.id;return(()=>{const i=n.kind._1.to;return Be(o=>{if(o.kind.tag==="SendToken")return(o.when.tag==="First"?!1:o.when.tag==="After"&&o.when._1===r)&&o.kind._1.from===i;if(o.kind.tag==="FillNodeWithoutTransition")return!1;g()},e)})()?0:t.tokenHold})()}));if(n.kind.tag==="FillNodeWithoutTransition")return J;g()})(e)),$h=t=>{if(t.event.kind.tag==="SendToken")return w("Just",{startT:t.startT,endT:t.endT,target:Fr("TokenWindow",t.event.id,t.event.kind._1.edge,t.event.kind._1.direction,t.event.kind._1.from,t.event.kind._1.to,t.event.kind._1.labels,t.holdPre,t.holdPost)});if(t.event.kind.tag==="FillNodeWithoutTransition")return w("Just",{startT:t.startT,endT:t.endT,target:Fr("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},Xh=t=>e=>n=>r=>{const i=Vt(o=>ls(o.path)(e)&&(Vn(o.endT-n)<1e-4||Vn(o.startT-r)<1e-4))(t.segments);if(i.tag==="Just")return w("Just",i._1);if(i.tag==="Nothing")return Vt(o=>ls(o.path)(e))(t.segments);g()},Yh=t=>e=>n=>yt(r=>{const i=yt(o=>Gi(o)(t.nodes))(Ct(qe.foldr,(()=>{if(r.scene.tag==="Structural")return Ee(C.compare,ke,(()=>{const o=Ar(r.scene._1.from)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()})(),(()=>{const o=Ar(r.scene._1.to)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()})());if(r.scene.tag==="DataFlow"){const o=Ar(r.scene._1.keyframe)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()}if(r.scene.tag==="Hold"){const o=Ar(r.scene._1)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()}if(r.scene.tag==="EnterNode"||r.scene.tag==="ExitNode")return Q;g()})()));return i.length===0?J:w("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const o=T(u=>s=>({minX:Co(u.minX)(s.x),minY:Co(u.minY)(s.y),maxX:yn(u.maxX)(s.x+s.w),maxY:yn(u.maxY)(s.y+s.h)}))(0<i.length?{minX:i[0].x,minY:i[0].y,maxX:i[0].x+i[0].w,maxY:i[0].y+i[0].h}:{minX:0,minY:0,maxX:0,maxY:0})(bt(1,i.length,i));return{x:o.minX,y:o.minY,w:o.maxX-o.minX,h:o.maxY-o.minY}})(),priority:0,pathFollow:J})}),Vh=t=>e=>n=>{const r=Si(n)(t);if(r.tag==="Nothing")return Ac;if(r.tag==="Just"){const i=Wc(r._1.target)(e);return Wc(r._1.source)(e)?i?Mc:Dh:Ac}g()},Uh={pre:0,post:0},Zh=t=>e=>n=>r=>i=>{const o=zc(i.event.id)(n),u=(()=>{if(o.tag==="Nothing")return Uh;if(o.tag==="Just")return o._1;g()})(),s=(()=>{if(i.event.when.tag==="First")return 0;if(i.event.when.tag==="At")return i.event.when._1;if(i.event.when.tag==="After"){const c=i.event.when._1,f=Vt(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.endT;g()}if(i.event.when.tag==="With"){const c=i.event.when._1,f=Vt(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.startT}g()})(),a=(()=>{if(i.event.kind.tag==="SendToken")return qh(t)(e)(u)(i.event.kind._1);if(i.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return Ot(r)({startT:s,endT:s+a.duration,event:i.event,holdPre:a.holdPre,holdPost:a.holdPost})},Hc=t=>e=>n=>T(Zh(t)(e)(Hh(t)(n)))([])(Ft(r=>i=>({event:i}))(n)),Kh=t=>e=>{const n=Gi(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},jh=t=>e=>({...e,fromCam:ss(t)(e.fromCam),toCam:ss(t)(e.toCam)}),t0=t=>{if(t.when.tag==="First")return[];if(t.when.tag==="At")return[];if(t.when.tag==="After")return[t.when._1];if(t.when.tag==="With")return[t.when._1];g()},$c={id:"",nodes:Q,edges:Q,kind:Ti},e0=t=>e=>$l((()=>{const n=Ar(e.from)(t);if(n.tag==="Nothing")return $c;if(n.tag==="Just")return n._1;g()})())((()=>{const n=Ar(e.to)(t);if(n.tag==="Nothing")return $c;if(n.tag==="Just")return n._1;g()})()),n0=t=>e=>{const n=Gi(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:Q};if(n.tag==="Just")return n._1;g()},ps=t=>e=>n=>r=>{const i=Si(r)(n.edges);if(i.tag==="Just")return t<=0?e:yn(e)(Ni(i._1)/t);if(i.tag==="Nothing")return e;g()},Xc=t=>e=>n=>r=>i=>{const o=t.plop,u=e0(n)(i),s=z(_=>({startT:0,endT:0+ps(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Fr("EdgeWindow",_,ds("Extend",_s))}))(Mr(u.entering.edges)),a=z(_=>({startT:0,endT:o,target:Fr("NodeWindow",_,qc)}))(Mr(u.entering.nodes)),c=T(yn)(0)(z(_=>ps(t.edgeSpeed)(t.minEdgeDuration)(e)(_))(Mr(u.leaving.edges))),f=_=>Be(h=>{const p=Si(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;g()},Mr(u.leaving.edges))?c:0,d=z(_=>({startT:f(_),endT:f(_)+t.plop,target:Fr("NodeWindow",_,Bh)}))(Mr(u.leaving.nodes)),l=z(_=>({startT:0,endT:ps(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Fr("EdgeWindow",_,ds("Retract",Vh(r)(u.leaving.nodes)(_)))}))(Mr(u.leaving.edges));return{duration:(()=>{const _=Lt(ut.compare)([...z(p=>p.endT)(l),...z(p=>p.endT)(d),...z(p=>p.endT)(a),...z(p=>p.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+t.gap:t.gap})(),windows:[...l,...d,...a,...s]}},r0=t=>e=>n=>r=>i=>o=>z((()=>{const u=i.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())(Xc(t)(e)(n)(r)(o).windows),i0=t=>yt(e=>Ct(si,e).length>1?w("Just",(()=>{const n=At(r=>J,r=>i=>w("Just",{head:r,tail:i}),Ct(si,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):J)(pd(ai)(Lt(C.compare)(t))),o0=t=>{const e=z(r=>r.id)(t),n=Ah(e);return[...z(Oh)(i0(e)),...z(Rh)(st(r=>!hs(r)(n),Tt(t)(t0)))]},u0=t=>e=>n=>{const r=yn(t.minZoom)(t.tokenZoomFloor);return yt(i=>{if(i.target.tag==="NodeWindow"||i.target.tag==="EdgeWindow")return J;if(i.target.tag==="TokenWindow")return w("Just",(()=>{const o={pre:i.target._7,post:i.target._8};if(t.tokenZoomFloor<=0)return{startT:i.startT,endT:i.endT,bbox:bi(e)(n)(i.target._2),priority:1,pathFollow:J};const u=Si(i.target._2)(e.edges);if(u.tag==="Just"){const s=Gi(i.target._4)(e.nodes);if(s.tag==="Just"){const a=Gi(i.target._5)(e.nodes);if(a.tag==="Just"){const c=a._1;return{startT:i.startT,endT:i.endT,bbox:bi(e)(n)(i.target._2),priority:1,pathFollow:w("Just",{samples:(()=>{const f=i.startT+o.pre*(i.endT-i.startT),d=yn(1e-4)(i.endT-o.post*(i.endT-i.startT)-f),l=i.endT-i.startT;return z(_=>{const h=f+rt(_)/rt(32)*d;return{t:h,pos:Fl(u._1)({x:s._1.x+s._1.w/2,y:s._1.y+s._1.h/2})({x:c.x+c.w/2,y:c.y+c.h/2})(l<=0?0:(h-i.startT)/l)(o)}})(Dt(0,32))})(),zoom:r})}}if(a.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:bi(e)(n)(i.target._2),priority:1,pathFollow:J};g()}if(s.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:bi(e)(n)(i.target._2),priority:1,pathFollow:J};g()}if(u.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:bi(e)(n)(i.target._2),priority:1,pathFollow:J};g()})());if(i.target.tag==="FillWindow")return w("Just",{startT:i.startT,endT:i.endT,bbox:Lc(e)(n)(zt("Node",1,1,i.target._2,void 0,Q,Q)),priority:1,pathFollow:J});g()})},s0=t=>e=>n=>r=>i=>yh(t)(i.layout)(r.endT)([...Yh(i.layout)(n)(e)(st(o=>o.startT>=i.startT&&o.endT<=i.endT,r.spans)),...u0(t)(i.layout)(n)(i.windows)]),a0=t=>{const e=Bc(z(r=>b(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];g()})()))(t)),n=r=>i=>o=>{if(hs(o)(i))return[nr("ScheduleCycle",[...Ct(qe.foldr,i),o])];if(hs(o)(r))return[];const u=zc(o)(e);if(u.tag==="Nothing")return[];if(u.tag==="Just")return Tt(u._1)(n(j(C)(o)()(r))(j(C)(o)()(i)));g()};return Tt(t)(r=>n(Q)(Q)(r.id))},c0={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:.5,stillHold:1.8,hatchHold:.4,tokenReadSecPerChar:.06,nodeEasing:oh,edgeEasing:ih,tokenEasing:xr,diveDur:1.2,retreatDur:1.2},g0=t=>e=>n=>r=>z((()=>{const i=n.startT;return o=>({...o,startT:o.startT+i,endT:o.endT+i})})())(yt($h)(Hc(t)(e)(r.events))),f0=t=>e=>n=>r=>i=>{if(i.scene.tag==="Structural")return r0(t)(e)(n)(r)(i)(i.scene._1);if(i.scene.tag==="Hold")return[];if(i.scene.tag==="DataFlow")return g0(t)(e)(i)(i.scene._1);if(i.scene.tag==="EnterNode")return[];if(i.scene.tag==="ExitNode")return[];g()},_0=t=>e=>n=>{const r=Hc(t)(e)(n.events);return r.length===0?t.gap:T(yn)(0)(z(i=>i.endT)(r))+t.gap},d0=t=>e=>n=>r=>i=>{if(i.tag==="Structural")return Xc(t)(e)(n)(r)(i._1).duration;if(i.tag==="Hold")return t.stillHold;if(i.tag==="DataFlow")return _0(t)(e)(i._1);if(i.tag==="EnterNode"||i.tag==="ExitNode")return 0;g()},Yc=t=>e=>n=>r=>i=>o=>{const u=Ml(e)(r),s=n.layout,a=vc(z(p=>b(p.id,p))(i.keyframes)),c=0<i.keyframes.length?w("Just",i.keyframes[0]):J,f=(()=>{if(c.tag==="Just")return c._1.id;if(c.tag==="Nothing")return"";g()})(),d=nh(i),l=p=>({segments:p.runSpans.length===0?p.segments:Ot(p.segments)({startT:p.runStart,endT:p.t,path:r,layout:s,placement:u,windows:p.runWindows,spans:p.runSpans,keyframes:a,initialKeyframe:f,edgeEndpoints:d}),spans:p.spans,windows:p.windows,dives:p.dives}),_=T(p=>m=>{if(m.tag==="EnterNode"){const v=l(p),L=p.t+t.diveDur,k=Ot(r)(m._1),E=Yc(t)(e)(n0(n)(m._1))(k)(Kh(i)(m._1))(L),O=E.endT+t.retreatDur;return{...p,t:O,runStart:O,runSpans:[],runWindows:[],segments:[...v.segments,...E.segments],spans:[...v.spans,...E.spans],windows:[...v.windows,...E.windows],dives:[...v.dives,{startT:p.t,endT:L,node:m._1,parentPath:r,childPath:k,direction:Wh},...E.dives,{startT:E.endT,endT:O,node:m._1,parentPath:r,childPath:k,direction:zh}]}}if(m.tag==="ExitNode")return p;const x=p.t+d0(t)(s)(a)(d)(m),y={startT:p.t,endT:x,scene:m},N=f0(t)(s)(a)(d)(y);return{...p,t:x,runSpans:Ot(p.runSpans)(y),runWindows:[...p.runWindows,...N],spans:Ot(p.spans)(y),windows:[...p.windows,...N]}})({t:o,runStart:o,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(i.scenes),h=l(_);return{endT:_.t,spans:h.spans,windows:Lt(p=>m=>ut.compare(p.startT)(m.startT))(h.windows),segments:h.segments,dives:h.dives}},l0=t=>e=>n=>n.endT<=t||n.startT>=e?J:w("Just",{...n,startT:yn(t)(n.startT),endT:Co(e)(n.endT)}),ms=t=>e=>n=>{const r=Ve(n.layout),i={x:r.x*n.placement.scale+n.placement.tx,y:r.y*n.placement.scale+n.placement.ty,w:r.w*n.placement.scale,h:r.h*n.placement.scale};return{center:{x:i.x+i.w/2,y:i.y+i.h/2},zoom:Co(as(e)(i)(t.padding*n.placement.scale))(40/(11*n.placement.scale))}},h0=t=>e=>n=>n.placement.scale===1&&n.placement.tx===0&&n.placement.ty===0?ss(n.placement)(Ci(t)(n.layout)(Ve(n.layout))(0)):ms(t)(e)(n),p0=t=>e=>n=>r=>yt(i=>{const o=Xh(r)(i.parentPath)(i.startT)(i.endT);if(o.tag==="Just"){const u=i.childPath,s=Vt(a=>ls(a.path)(u))(r.segments);if(s.tag==="Just"){const a=h0(t)(e)(o._1),c=ms(t)(e)(s._1);if(i.direction==="DiveIn")return w("Just",{startT:i.startT,endT:i.endT,fromCam:a,toCam:c,easing:xr,interp:Sc});if(i.direction==="DiveOut")return w("Just",{startT:i.startT,endT:i.endT,fromCam:c,toCam:a,easing:xr,interp:Sc});g()}if(s.tag==="Nothing")return J;g()}if(o.tag==="Nothing")return J;g()})(r.dives),m0=t=>e=>{if(e.tag==="Structural")return yt(n=>n)([So(e._1.from)(t)?J:w("Just",nr("UnknownKeyframe",e._1.from)),So(e._1.to)(t)?J:w("Just",nr("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return yt(n=>n)([So(e._1)(t)?J:w("Just",nr("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...yt(n=>n)([So(e._1.keyframe)(t)?J:w("Just",nr("UnknownKeyframe",e._1.keyframe))]),...o0(e._1.events),...a0(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()},x0=t=>e=>{const n=Tt(e)(m0(t));return n.length===0?Pt("Right",void 0):Pt("Left",n)},y0=t=>e=>n=>r=>Lt(i=>o=>ut.compare(i.startT)(o.startT))(Tt(r.segments)(i=>i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0?yt(l0(i.startT)(i.endT))(z(jh(i.placement))(s0(t)(n)(i.edgeEndpoints)(r)(i))):[(()=>{const o=ms(t)(e)(i);return{startT:i.startT,endT:i.endT,fromCam:o,toCam:o,easing:xr,interp:Ei}})()])),N0=t=>e=>n=>r=>{if(0<n.keyframes.length){const i=n.keyframes[0],o=vc(z(s=>b(s.id,s))(n.keyframes)),u=x0(o)(n.scenes);return(()=>{if(u.tag==="Left"){const s=u._1;return a=>Pt("Left",s)}if(u.tag==="Right"){const s=u._1;return a=>a(s)}g()})()(()=>{const s=Yc(e)(r)(r)([])(n)(0);return Pt("Right",{totalDuration:s.endT,windows:s.windows,spans:s.spans,keyframes:o,initialKeyframe:i.id,timing:e,layout:r.layout,cameraSpans:[...y0(t)(r.layout)(o)(s),...p0(t)(r.layout)(o)(s)],cameraConfig:t,levelTree:r,segments:s.segments,dives:s.dives,seed:n.seed})})}return Pt("Left",[Mh])},xs=t=>e=>Math.imul(t,e),Or=t=>{const e=t+1831565813|0,n=xs(e^e>>>15)(e|1),r=n^(n+xs(n^n>>>7)(n|61)|0),i=r^r>>>14;return{prng:i,value:i<0?(rt(i)+4294967296)/4294967296:rt(i)/4294967296}},ae=t=>e=>n=>{const r=Or(n);return{prng:r.prng,value:t+r.value*(e-t)}},ys=t=>e=>T(n=>r=>xs(n^r)(-2048144789))(e)(z(Dn)(Kn(t))),Ns=t=>t,rn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Go=Gu(ai),J0=(()=>{const t=Xe.unfoldr(mn);return e=>t(Ye("IterNode",e,pn))})(),Vc=jt(C)(Wt),Js=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Uc=Wt.foldMap(ll(C)),Zc=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},T0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Rr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},w0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},v0=jt(C)(Wt),b0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},k0=jt(C)(Wt),L0=Ns("Backdrop"),Kc=Ns("FlyThrough"),Po=Ns("Active"),jc=t=>e=>n=>{const r=(t+e)/2,i=n-r,o=i<0?-1:1,u=(e-t)/2,s=u*.15,a=u-s,c=i<0?-i:i;return e<=t?(t+e)/2:c<=a?n:r+o*(u-s*uo(-(c-a)/s))},E0=t=>e=>n=>r=>{const i=Ve(t),o=i.w/rn(1e-4)(e.zoom)/2,u=i.h/rn(1e-4)(e.zoom)/2,s=n.y-e.center.y,a=n.x-e.center.x;return{...e,center:{x:o<=1e-4?e.center.x+0*r*.35:a<0?e.center.x+a/(1+-a/o)*r*.35:e.center.x+a/(1+a/o)*r*.35,y:u<=1e-4?e.center.y+0*r*.35:s<0?e.center.y+s/(1+-s/u)*r*.35:e.center.y+s/(1+s/u)*r*.35}}},Ts=t=>e=>n=>{const r=Vt(i=>Go(i.path)(e)&&n>=i.startT&&n<i.endT)(t.segments);if(r.tag==="Just")return w("Just",r._1);if(r.tag==="Nothing")return Vt(i=>Go(i.path)(e))(t.segments);g()},C0=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:ju,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:Q}),S0=t=>z(e=>e<1?[]:bt(0,e,t))(Dt(0,t.length-1|0)),G0=t=>T(e=>n=>(e*31|0)+Dn(n)|0)(7)(Kn(t)),tg=t=>e=>n=>({...n,state:{...n.state,nodes:Vc(z(r=>b(r._1,t(r._1)(r._2)))(J0(n.state.nodes))),edges:(()=>{const r=i=>{if(i.tag==="Leaf")return Q;if(i.tag==="Node")return zt("Node",i._1,i._2,i._3,e(i._4),r(i._5),r(i._6));g()};return r(n.state.edges)})()}}),ws=t=>e=>{const n=Js(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.nodes;g()},vs=t=>e=>{const n=Js(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.edges;g()},Io=t=>e=>{if(e<t.startT)return yr("AtKeyframe",t.initialKeyframe);const n=Vt(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return yr("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return yr("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return yr("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return yr("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;return r>=0&&r<t.spans.length?yr("AtKeyframe",(()=>{if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="Hold")return t.spans[r].scene._1;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return t.initialKeyframe;g()})()):yr("AtKeyframe",t.initialKeyframe)}g()},P0=T(t=>e=>{const n=Cr(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?Ot(n._1.init)({...n._1.last,endT:rn(n._1.last.endT)(e.endT),windows:Ot(n._1.last.windows)(e)}):Ot(t)({endT:e.endT,windows:[e]})})([]),I0=t=>e=>n=>Uc(r=>Uc(i=>i.target.tag==="FillWindow"?i.startT<=n?zt("Node",1,1,i.target._2,void 0,Q,Q):Q:i.target.tag==="TokenWindow"&&i.startT+(i.endT-i.startT)*.25<=n?zt("Node",1,1,i.target._4,void 0,Q,Q):Q)(r.windows))(st(r=>n<=r.endT+t,P0(Lt(r=>i=>ut.compare(r.startT)(i.startT))(st(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),D0=t=>e=>n=>Be(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),Q0=t=>e=>n=>Be(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),F0=t=>e=>n=>Be(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),A0=t=>e=>n=>Be(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),M0=t=>e=>{const n=Io(t)(e);if(n.tag==="AtKeyframe")return me(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return me(3)(n._2)==="kf-"?"":n._2;g()},O0=t=>e=>{const n=Io(t)(e),r=Js((()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;g()})())(t.keyframes);if(r.tag==="Just")return r._1.kind;if(r.tag==="Nothing")return Ti;g()},eg=t=>e=>n=>Vt(r=>n(r)&&e>=r.startT&&e<r.endT)(t),R0=t=>{const e=Zc(0)(1)(t/.2),n=Zc(0)(1)((1-t)/.2);return e*e*(3-2*e)*n*n*(3-2*n)},B0=t=>e=>{if(e.tag==="Travelling"){const n=T0(e._1.edge)(t.edges);if(n.tag==="Just"){const r=mr(n._1)(e._1.progress);return r.tag==="Just"?w("Just",{dot:r._1,weight:R0(e._1.progress)}):J}if(n.tag==="Nothing")return J;g()}return J},W0={segment:{startT:0,endT:0,path:[],layout:{nodes:Q,edges:Q,chipExtras:Q,edgeLabels:Q},placement:ju,windows:[],spans:[],keyframes:Q,initialKeyframe:"",edgeEndpoints:Q},state:{nodes:Q,edges:Q,tokens:Q,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:Ti,visited:Q,nodeFadeAlpha:Q,nodeInvert:Q},bgAlpha:1,role:Po},Do=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:W0},z0=t=>e=>{const n=Io(t)(e);if(n.tag==="AtKeyframe")return ws(t)(n._1);if(n.tag==="InTransition")return Ee(C.compare,ke,ws(t)(n._1),ws(t)(n._2));g()},q0=t=>e=>{const n=Io(t)(e);if(n.tag==="AtKeyframe")return vs(t)(n._1);if(n.tag==="InTransition")return Ee(C.compare,ke,vs(t)(n._1),vs(t)(n._2));g()},H0=t=>e=>{const n=t.w/rn(1e-4)(e.zoom),r=t.h/rn(1e-4)(e.zoom);return{...e,center:{x:n>=t.w?t.x+t.w/2:jc(t.x+n/2)(t.x+t.w-n/2)(e.center.x),y:r>=t.h?t.y+t.h/2:jc(t.y+r/2)(t.y+t.h-r/2)(e.center.y)}}},$0=t=>H0((()=>{const e=Ve(t.layout),n=e.x*t.placement.scale+t.placement.tx,r=e.y*t.placement.scale+t.placement.ty;return{x:n,y:r,w:(e.x+e.w)*t.placement.scale+t.placement.tx-n,h:(e.y+e.h)*t.placement.scale+t.placement.ty-r}})()),X0=t=>e=>{const n=t.endT-t.startT;return n<=0?1:rn(0)(Rr(1)((e-t.startT)/n))},ng=t=>e=>n=>rn(0)(Rr(1)((n-ae(0)(.3)(t+G0(e)|0).value)/rn(1e-4)(.7))),rg=t=>e=>n=>tg(r=>i=>i.tag==="Hidden"?Lo:Qr("PloppingOut",r===e?rn(0)(Rr(1)((n-.45)/rn(1e-4)(.55))):ng(t)(r)(n)))(r=>r.tag==="Retracted"?Eo:Dr("Retracting",Mc,n)),ig=t=>e=>tg(n=>r=>r.tag==="Hidden"?Lo:Qr("PloppingIn",ng(t)(n)(e)))(n=>n.tag==="Retracted"?Eo:Dr("Extending",_s,e)),Qo=t=>e=>{const n=t.endT-t.startT;return n<=0?1:rn(0)(Rr(1)((e-t.startT)/n))},Y0=t=>e=>n=>r=>i=>{const o=eg(e)(n)(u=>u.target.tag==="EdgeWindow"&&u.target._1===i);if(o.tag==="Just"){const u=os(t.timing.edgeEasing)(Qo(o._1)(n)),s=o._1.target.tag==="EdgeWindow"?o._1.target._2:ds("Extend",_s);if(s.tag==="Retract")return Dr("Retracting",s._1,u);if(s.tag==="Extend")return Dr("Extending",s._1,u);g()}if(o.tag==="Nothing")return A0(e)(n)(i)||D0(e)(n)(i)?Eo:w0(i)(r)?Fh:Eo;g()},V0=t=>e=>n=>{const r=q0(e)(n);return v0(z(i=>b(i,Y0(t)(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return zt("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return Ct(qe.foldr,i(e.layout.edges))})()))},U0=t=>e=>n=>r=>{const i=eg(t)(e)(o=>o.target.tag==="NodeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=Qo(i._1)(e),u=i._1.target.tag==="NodeWindow"?i._1.target._2:qc;if(u==="PlopIn")return Qr("PloppingIn",o);if(u==="PlopOut")return Qr("PloppingOut",o);g()}if(i.tag==="Nothing")return F0(t)(e)(r)||Q0(t)(e)(r)?Lo:b0(r)(n)?Qh:Lo;g()},Z0=t=>e=>n=>{const r=z0(e)(n);return Vc(z(i=>b(i,U0(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return zt("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return Ct(qe.foldr,i(e.layout.nodes))})()))},K0=t=>e=>n=>e.target.tag==="TokenWindow"?b(e.target._1,n<e.startT?fs:n>=e.endT?Fc:ko("Travelling",{edge:e.target._2,direction:e.target._3,progress:os(t.timing.tokenEasing)(Qo(e)(n)),labels:e.target._6,source:e.target._4,target:e.target._5,holdPre:e.target._7,holdPost:e.target._8})):e.target.tag==="FillWindow"?b(e.target._1,n<e.startT?fs:n>=e.endT?Fc:ko("Filling",{node:e.target._2,progress:Qo(e)(n),labels:e.target._3})):b("",fs),j0=t=>e=>n=>k0(z(r=>K0(t)(r)(n))(st(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),Br=t=>e=>n=>({nodes:Z0()(e)(n),edges:V0(t)(e)(n),tokens:j0(t)(e.windows)(n),camera:Pc(t.cameraConfig)(e.layout)(t.cameraSpans)(n),frameTitle:M0(e)(n),staticKind:O0(e)(n),visited:I0(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:Q,nodeInvert:Q}),tp=t=>e=>n=>Xa(J,Ba,r=>r.direction==="DiveIn"&&Go(r.parentPath)(e.path)&&n>=r.startT-.7&&n<r.startT?w("Just",{node:r.node,phase:(n-(r.startT-.7))/.7}):J,t.dives),ep=t=>e=>n=>r=>{const i=tp(t)(e)(n);if(i.tag==="Just"){const o=$e(3.141592653589793*i._1.phase*3);return{...r,state:{...r.state,nodeInvert:zt("Node",1,1,i._1.node,1*o*o,Q,Q)}}}if(i.tag==="Nothing")return r;g()},og=t=>e=>yt(n=>{const r=Vt(i=>i.direction==="DiveIn"&&Go(i.childPath)((()=>{const o=n.length+1|0;return o<1?[]:bt(0,o,e)})()))(t.dives);if(r.tag==="Just"){const i=Ts(t)(n)(r._1.startT-1e-4);if(i.tag==="Just")return w("Just",{bgAlpha:1,role:L0,segment:i._1,state:{...Br(t)(i._1)(r._1.startT-1e-4),nodeFadeAlpha:zt("Node",1,1,r._1.node,0,Q,Q)}});if(i.tag==="Nothing")return J;g()}if(r.tag==="Nothing")return J;g()})(S0(e)),ug=t=>e=>{const n=st(i=>e>=i.startT&&e<i.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:C0(t)},np=t=>e=>n=>{const r=X0(n)(e),i=Ts(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),o=Ts(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),u=rn(0)(Rr(1)(r/.6)),s=rn(0)(Rr(1)((r-.4)/.6)),a=(()=>{if(n.direction==="DiveIn")return rg(t.seed)(n.node)(u);if(n.direction==="DiveOut")return ig(t.seed)(s);g()})(),c=(()=>{if(n.direction==="DiveIn")return ig(t.seed)(s);if(n.direction==="DiveOut")return rg(t.seed)(n.node)(u);g()})();return[...og(t)(n.parentPath),...(()=>{if(i.tag==="Just"){if(o.tag==="Just")return[a({segment:i._1,state:Br(t)(i._1)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),bgAlpha:1,role:Kc}),c({segment:o._1,state:Br(t)(o._1)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),bgAlpha:1,role:Po})];if(o.tag==="Nothing")return[a({segment:i._1,state:Br(t)(i._1)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),bgAlpha:1,role:Kc})];g()}if(i.tag==="Nothing")return[(()=>{const f=ug(t)(e);return{segment:f,state:Br(t)(f)(e),bgAlpha:1,role:Po}})()];g()})()]},rp=t=>e=>{const n=yt(B0(t))((()=>{const r=(i,o)=>{if(i.tag==="Leaf")return o;if(i.tag==="Node")return r(i._5,qt("Cons",i._4,r(i._6,o)));g()};return Ct($t.foldr,r(e.tokens,Ht))})());return 0<n.length?w("Just",n[0]):J},ip=t=>e=>{const n=rp(t)(e);if(n.tag==="Nothing")return e.camera;if(n.tag==="Just")return E0(t)(e.camera)(n._1.dot)(n._1.weight);g()},op=t=>e=>t.placement.scale===1&&t.placement.tx===0&&t.placement.ty===0?ip(t.layout)(e):e.camera,up=t=>e=>Vt(n=>e>=n.startT&&e<n.endT)(t.dives),sp=t=>e=>{const n=ug(t)(e),r=Br(t)(n)(e),i=t.dives.length!==0,o=Pc(t.cameraConfig)(t.layout)(t.cameraSpans)(e),u=$0(n)(op(n)({...r,camera:o})),s=ep(t)(n)(e)({bgAlpha:1,role:Po,segment:n,state:{...r,camera:u}}),a=og(t)(n.path),c=up(t)(e);if(c.tag==="Just")return{levels:np(t)(e)(c._1),camera:o,rootLayout:t.layout,hasDives:i,diving:!0};if(c.tag==="Nothing")return{levels:Ot(a)(s),camera:u,rootLayout:t.layout,hasDives:i,diving:!1};g()},sg=t=>t,ag=sg("RunText"),ap=sg("RunCode"),cg=t=>e=>n=>e.length===0?n:Ot(n)({style:t,text:lr(e)}),cp=t=>({style:(()=>{if(t.style==="RunText")return ap;if(t.style==="RunCode")return ag;g()})(),buf:[],runs:cg(t.style)(t.buf)(t.runs)}),gp=t=>e=>0<e.length?{...t,buf:Ot(t.buf)(e[0])}:{...t,buf:Ot(t.buf)("\\")},fp=t=>e=>{let n=t,r=e,i=!0,o;for(;i;){const u=n,s=At(a=>J,a=>c=>w("Just",{head:a,tail:c}),r);if(s.tag==="Nothing"){i=!1,o=u;continue}if(s.tag==="Just"){if(s._1.head==="\\"){n=gp(u)(s._1.tail),r=bt(1,s._1.tail.length,s._1.tail);continue}if(s._1.head==="`"){n=cp(u),r=s._1.tail;continue}n={...u,buf:Ot(u.buf)(s._1.head)},r=s._1.tail;continue}g()}return o},gg=t=>{const e=fp({style:ag,buf:[],runs:[]})(Kn(t));return cg(e.style)(e.buf)(e.runs)};let bs=null;function _p(){return bs||(typeof document>"u"?null:(bs=document.createElement("canvas").getContext("2d"),bs))}const fg=new Map,dp=t=>e=>n=>r=>()=>{const i=`${n} ${e}px ${t}|${r}`,o=fg.get(i);if(o!==void 0)return o;const u=_p();if(!u)return r.length*e*.62;u.font=`${n} ${e}px ${t}`;const s=u.measureText(r).width;return fg.set(i,s),s},lp=ar.traverse(Eu),hp=T(Pr)(0),Wr=(()=>{const t=er(`\r
3
- `)(" "),e=er(`
4
- `)(" "),n=(()=>{const r=er("\r")(" "),i=(()=>{const o=er(" ")(" ");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),_g=t=>e=>{const n=lp(r=>{const i=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;g()})();return dp(i.family)(i.size)(i.weight)(Wr(r.text))})(gg(Wr(e)));return()=>{const r=n();return hp(r)}},dg={text:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:"500"},code:{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:"400"}},pp=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},zr=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},mp=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},xp=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},yp=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},lg=t=>lr(Te(gr(e=>e===" ")(Te(gr(e=>e===" ")(Kn(t)).rest)).rest)),Np=t=>T(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?w("Just",n._1):e)(J)(Ft(Sn)(t)),ks=t=>e=>{if(t<=0)return[e];if(jn(e)<=t)return[e];const n=Kn(e),r=t<1?[]:bt(0,t,n),i=Np(r);if(i.tag==="Just"){const o=lg(dc(!(i._1>=0&&i._1<r.length)||r[i._1]===" "?i._1:i._1+1|0)(e)),u=lg(mi(i._1+1|0)(e));return u===""?[o]:[o,...ks(t)(u)]}if(i.tag==="Nothing"){const o=dc(t)(e),u=mi(t)(e);return u===""?[o]:[o,...ks(t)(u)]}g()},Jp={cellW:7,cellH:3,maxLineWidth:20},Tp=t=>e=>{const n=z(o=>b((()=>{if(o.label.tag==="Just")return o.label._1;if(o.label.tag==="Nothing")return o.id;g()})(),o))(e.nodes),r=zr(1)(Cn((mp(t.maxLineWidth)(T(o=>u=>zr(o)(jn(u._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),i=(r*t.cellW|0)-1|0;return{...e,nodes:z(o=>{if(!(o._2.size._1===1&&o._2.size._2===1))return o._2;const u=Tt(To(`
5
- `)(o._1))(ks(i)),s=T(c=>f=>zr(c)(jn(f)))(0)(u),a=o._2.shape==="Cylinder"?zr(1)(Cn((s+2|0)+t.cellW|0,t.cellW)):r;return{...o._2,size:b(rt(s>i?Cn((s+2|0)+t.cellW|0,t.cellW):a),rt(zr(1)(Cn(u.length+t.cellH|0,t.cellH))+(o._2.shape==="Cylinder"||o._2.shape==="Document"?1:0)|0))}})(n)}},wp=t=>e=>n=>({...n,nodes:z(r=>{const i=yp(r.id)(e);if(i.tag==="Nothing")return r;if(i.tag==="Just")return{...r,size:b(xp(r.size._1)(rt(zr(1)(de(oo(r.shape==="Cylinder"?(i._1+0)/t:(i._1+32)/t))))),r.size._2)};g()})(n.nodes)}),vp=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bp=t=>{const e=t.length;return(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(a>=e){u=!1,s=c;continue}const f=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const x=_,y=h;if(x>=e){p=!1,m=y;continue}if(a>=0&&a<t.length){if(x>=0&&x<t.length){_=x+1|0,h=(()=>{const N=t[a].position,v=t[a].size,L=t[x].position,k=t[x].size;return N._1<L._1+k._1&&L._1<N._1+v._1&&N._2<L._2+k._2&&L._2<N._2+v._2})()?y+1|0:y;continue}_=x+1|0,h=y;continue}p=!1,m=y}return m};i=a+1|0,o=f(a+1|0)(c)}return s})(0)(0)},hg=t=>T(e=>n=>e+Ll(n.start)(n.end))(0)(t.segments),kp=t=>e=>n=>({crossingCount:T(r=>i=>r+i.jumps.length|0)(0)(e),bendCount:T(r=>i=>r+i.bends.length|0)(0)(e),totalEdgeLength:T(r=>i=>r+hg(i))(0)(e),maxEdgeLength:T(r=>i=>vp(r)(hg(i)))(0)(e),nodeOverlapCount:bp(t),constraintViolations:n,jumpCount:T(r=>i=>r+i.jumps.length|0)(0)(e)}),Ls=t=>t,Ut=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=it.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Es=Ls("LEFT"),Lp=Ls("RIGHT"),pg=Ls("UNDEFINED"),Ep={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},Cp={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?Ge:Ne;if(e==="LEFT")return Je;if(t==="RIGHT")return e==="RIGHT"?Ge:Ne;if(e==="RIGHT")return Je;if(t==="UP")return e==="UP"?Ge:Ne;if(e==="UP")return Je;if(t==="DOWN")return e==="DOWN"?Ge:Ne;if(e==="DOWN")return Je;if(t==="UNDEFINED"&&e==="UNDEFINED")return Ge;g()},Eq0:()=>Ep},Sp=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){if(t==="LEFT"){if(o._3==="LEFT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="LEFT"){n=o._6;continue}if(t==="RIGHT"){if(o._3==="RIGHT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="RIGHT"){n=o._6;continue}if(t==="UP"){if(o._3==="UP"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="UP"){n=o._6;continue}if(t==="DOWN"){if(o._3==="DOWN"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="DOWN"){n=o._6;continue}if(t==="UNDEFINED"&&o._3==="UNDEFINED"){r=!1,i=!0;continue}}g()}return i},Gp={x:0,y:0},Ue=t=>e=>n=>{const r=Ut(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:j(it)(t)(e(r._1))(n.cNodes)};g()},Pi=t=>e=>n=>{const r=Ut(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:j(it)(t)(e(r._1))(n.cGroups)};g()},Pp=t=>T(e=>n=>Ue(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),Ip=t=>{const e=T(n=>r=>{const i=Ut(r)(t.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just")return T(o=>u=>vt(it)(ee)(u)([r])(o))(n)(i._1.constraints);g()})(Q)(t.cNodeOrder);return T(n=>r=>Ue(r)(i=>({...i,constraints:(()=>{const o=Ut(r)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})()}))(n))(t)(t.cNodeOrder)},Dp=t=>e=>Ue(t)(n=>({...n,ignoreSpacing:{left:n.ignoreSpacing.left||e.left,right:n.ignoreSpacing.right||e.right,up:n.ignoreSpacing.up||e.up,down:n.ignoreSpacing.down||e.down}})),Qp=t=>{const e=T(n=>r=>Pi(r)(i=>({...i,outDegree:i.outDegreeReal}))(n))(t)(t.cGroupOrder);return T(n=>r=>Ue(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder)},cn={left:!1,right:!1,up:!1,down:!1},Fp={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},Cs=t=>T(e=>n=>{const r=Ut(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const i=T(u=>s=>{const a=Ut(s)(e.cNodes);if(a.tag==="Nothing")return u;if(a.tag==="Just"){if(u.tag==="Nothing")return w("Just",s);if(u.tag==="Just"){const c=Ut(u._1)(e.cNodes);if(c.tag==="Nothing")return w("Just",s);if(c.tag==="Just")return a._1.hitbox.x<c._1.hitbox.x?w("Just",s):w("Just",u._1)}}g()})(J)(r._1.cNodes),o=Pi(n)(u=>({...u,reference:i}))(e);if(i.tag==="Nothing")return o;if(i.tag==="Just"){const u=Ut(i._1)(o.cNodes);if(u.tag==="Nothing")return o;if(u.tag==="Just"){const s=u._1;return T(a=>c=>Ue(c)(f=>({...f,cGroupOffset:{x:f.hitbox.x-s.hitbox.x,y:f.hitbox.y-s.hitbox.y}}))(a))(o)(r._1.cNodes)}}}g()})(t)(t.cGroupOrder),Ze=t=>Cs({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return Q;if(n.tag==="Node")return zt("Node",n._1,n._2,n._3,{...n._4,hitbox:{...n._4.hitbox,x:-n._4.hitbox.x-n._4.hitbox.width}},e(n._5),e(n._6));g()};return e(t.cNodes)})()}),Nn=t=>Cs({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return Q;if(n.tag==="Node")return zt("Node",n._1,n._2,n._3,{...n._4,hitbox:{x:n._4.hitbox.y,y:n._4.hitbox.x,width:n._4.hitbox.height,height:n._4.hitbox.width},cGroupOffset:{x:n._4.cGroupOffset.y,y:n._4.cGroupOffset.x}},e(n._5),e(n._6));g()};return e(t.cNodes)})()}),mg=t=>{const e=T(n=>r=>Pi(r)(i=>({...i,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return T(n=>r=>{const i=Ut(r)(n.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just"){if(i._1.cGroup.tag==="Nothing")return n;if(i._1.cGroup.tag==="Just"){const o=i._1.cGroup._1;return T(u=>s=>{const a=Ut(s)(u.cNodes);if(a.tag==="Nothing")return u;if(a.tag==="Just")return a._1.cGroup.tag==="Just"&&a._1.cGroup._1!==o?Pi(a._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(Pi(o)(c=>We(Er)(s)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,s]})(u)):u;g()})(n)(i._1.constraints)}}g()})(e)(e.cNodeOrder)},Fo=t=>{const e=Ip(t.cGraph);return{...t,cGraph:mg(T(n=>r=>Ue(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},Ap=t=>e=>T(n=>r=>{if(t==="LEFT"||t==="UP"){const o=r._2;return Ue(r._1)(u=>({...u,constraints:[...u.constraints,o]}))(n)}const i=r._1;return Ue(r._2)(o=>({...o,constraints:[...o.constraints,i]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),gn=t=>{const e={...t,cGraph:Ap(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node")return zt("Node",r._1,r._2,r._3,{...r._4,constraints:[]},n(r._5),n(r._6));g()};return n(t.cGraph.cNodes)})()})};return{...e,cGraph:mg((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);g()})())}},Mp=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?gn(r):e==="RIGHT"?gn({...r,cGraph:Ze(r.cGraph)}):e==="UP"?gn({...r,cGraph:Nn(r.cGraph)}):e==="DOWN"?gn({...r,cGraph:Ze(Nn(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?Fo({...r,cGraph:Ze(r.cGraph)}):e==="UP"?gn({...r,cGraph:Nn(r.cGraph)}):e==="DOWN"?gn({...r,cGraph:Ze(Nn(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?Fo({...r,cGraph:Ze(r.cGraph)}):e==="UP"?gn({...r,cGraph:Nn(Ze(r.cGraph))}):e==="DOWN"?gn({...r,cGraph:Ze(Nn(Ze(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?gn({...r,cGraph:Nn(r.cGraph)}):e==="RIGHT"?gn({...r,cGraph:Ze(Nn(r.cGraph))}):e==="DOWN"?Fo({...r,cGraph:Ze(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?gn({...r,cGraph:Nn(Ze(r.cGraph))}):e==="RIGHT"?gn({...r,cGraph:Ze(Nn(Ze(r.cGraph)))}):e==="UP"?Fo({...r,cGraph:Ze(r.cGraph)}):r;g()},xg=t=>e=>e.finished||!Sp(t)(e.cGraph.supportedDirections)||(t==="LEFT"?e.direction==="LEFT":t==="RIGHT"?e.direction==="RIGHT":t==="UP"?e.direction==="UP":t==="DOWN"?e.direction==="DOWN":t==="UNDEFINED"&&e.direction==="UNDEFINED")?e:Mp(e.direction)(t)(e),Op=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?xg(Es)(t):t,n={...e,cGraph:Qp(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},yg=t=>e=>n=>{const r=Ut(t)(n.cNodes),i=Ut(e)(n.cGroups);return r.tag==="Just"&&i.tag==="Just"?(()=>{if(r._1.cGroup.tag==="Nothing")return!1;if(r._1.cGroup.tag==="Just")return!0;g()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:j(it)(t)({...r._1,cGroup:w("Just",e)})(n.cNodes),cGroups:j(it)(e)({...i._1,cNodes:We(Er)(t)(i._1.cNodes)?i._1.cNodes:[...i._1.cNodes,t],reference:(()=>{if(i._1.reference.tag==="Nothing")return w("Just",t);if(i._1.reference.tag==="Just")return w("Just",i._1.reference._1);g()})()})(n.cGroups)}:n},Ng=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:j(it)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:J,cGroupOffset:Gp,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:cn})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),Ss=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:T(r=>i=>yg(i)(n)(r))({...e,cGroups:j(it)(n)({id:n,master:t.master,cNodes:[],startPos:-1e308,incomingConstraints:[],outDegree:0,outDegreeReal:0,reference:J,delta:0,deltaNormalized:0})(e.cGroups),cGroupOrder:[...e.cGroupOrder,n],nextCGroupId:n+1|0})(t.nodes)}},Rp=t=>T(e=>n=>{const r=Ut(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?Ss({master:J,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),Bp=t=>({cGraph:Pp(Rp(Cs(t))),direction:pg,compactionAlgorithm:J,constraintAlgorithm:J,spacingsHandler:Fp,lockFun:J,finished:!1}),Wp=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},zp=t=>e=>{const n=ut.compare(t._1)(e._1);return n==="LT"?Ne:n==="GT"?Je:it.compare(t._2)(e._2)},qp=(()=>{const t=Xe.unfoldr(mn);return e=>t(Ye("IterNode",e,pn))})(),Jg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=it.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Tg=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",wg=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),Ao=t=>e=>zp(b(t.hitbox.x+t.hitbox.width/2,t.id))(b(e.hitbox.x+e.hitbox.width/2,e.id)),Hp=t=>e=>{const n=cr(Xt,J,r=>Ao(t)(r)==="LT",e);if(n.tag==="Just"){const r=Va(Xt,J,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return Ot(e)(t);g()},vg=t=>e=>{const n=st(i=>Ao(i)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?w("Just",n[r]):J},$p=t=>e=>{const n=Hp(e)(t.intervals),r=Vt(o=>Ao(e)(o)==="LT")(n),i=j(it)(e.id)((()=>{const o=vg(e)(n);return o.tag==="Just"?w("Just",o._1.id):J})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return j(it)(r._1.id)(w("Just",e.id))(i);if(r.tag==="Nothing")return i;g()})()}},Xp=t=>e=>{const n=ut.compare(t.low?t.node.hitbox.y:t.node.hitbox.y+t.node.hitbox.height)(e.low?e.node.hitbox.y:e.node.hitbox.y+e.node.hitbox.height);return n==="EQ"?t.low?t.low&&!e.low?Je:Ge:e.low?Ne:Ge:n},Yp=t=>T(e=>n=>Ue(n.id)(r=>({...r,constraints:[]}))(e))(t)(yt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),Gs=t=>e=>T(n=>r=>{const i=Ut(r._1)(n.cNodes);if(i.tag==="Just")return Ue(r._1)(o=>({...o,constraints:[...o.constraints,...r._2]}))(n);if(i.tag==="Nothing")return n;g()})(e)(qp(t)),bg=t=>e=>e.kind.tag!=="Nothing"&&e.kind.tag==="Just"&&e.kind._1==="vs"?e.ignoreSpacing.up?e.ignoreSpacing.down?e:{...e,hitbox:{...e.hitbox,height:e.hitbox.height+t+.01}}:{...e,hitbox:{...e.hitbox,y:e.hitbox.y-t-.01,height:e.hitbox.height+t+.01}}:{...e,hitbox:{...e.hitbox,y:e.hitbox.y-t,height:e.hitbox.height+2*t}},kg=t=>e=>n=>T(r=>i=>n(i)?Ue(i.id)(bg(t))(r):r)(e)(yt(r=>Ut(r)(e.cNodes))(e.cNodeOrder)),Vp=t=>e=>{const n=(r,i,o)=>{const u=Ue(o)(bg(t))(r);return i.length<=1?u:T(s=>a=>a===o?s:Ue(a)(c=>c.ignoreSpacing.up?{...c,hitbox:{...c.hitbox,y:c.hitbox.y+t+.01,height:c.hitbox.height-t-.01}}:c.ignoreSpacing.down?{...c,hitbox:{...c.hitbox,height:c.hitbox.height-t-.01}}:c)(s))(u)(i)};return T(r=>i=>{if(i.master.tag==="Nothing")return 0<i.cNodes.length?n(r,i.cNodes,i.cNodes[0]):r;if(i.master.tag==="Just")return n(r,i.cNodes,i.master._1);g()})(e)(yt(r=>Ut(r)(e.cGroups))(e.cGroupOrder))},Up=t=>e=>{const n=vg(e)(t.intervals),r=Vt(o=>Ao(e)(o)==="LT")(t.intervals),i=n.tag==="Just"&&(()=>{const o=Jg(e.id)(t.cand);return(o.tag==="Nothing"?!1:o.tag==="Just"&&(o._1.tag==="Nothing"?!1:o._1.tag==="Just"&&o._1._1===n._1.id))&&n._1.cGroup.tag==="Just"&&e.cGroup.tag==="Just"&&n._1.cGroup._1!==e.cGroup._1})()?vt(it)(ee)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const o=Jg(r._1.id)(t.cand);return(o.tag==="Nothing"?!1:o.tag==="Just"&&(o._1.tag==="Nothing"?!1:o._1.tag==="Just"&&o._1._1===e.id))&&e.cGroup.tag==="Just"&&r._1.cGroup.tag==="Just"&&e.cGroup._1!==r._1.cGroup._1})()?vt(it)(ee)(e.id)([r._1.id])(i):i,intervals:st(o=>o.id!==e.id,t.intervals)}},Zp=t=>e=>e.low?$p(t)(e.node):Up(t)(e.node),Ps=t=>e=>T(Zp)({intervals:[],cand:Q,constraints:Q})(Lt(Xp)(Tt(st(t,yt(n=>Ut(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,Kp=t=>e=>{const n=Wp(0)(t/2-.5),r=Gs(Ps(Tg)(kg(n)(e)(Tg)))(e),i=Gs(Ps(wg)(kg(n)(r)(wg)))(r);return Gs(Ps(o=>!0)(Vp(n)(i)))(i)},jp=t=>e=>Kp(t)(Yp(e.cGraph)),Mo=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Lg=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Is=t=>e=>n=>r=>i=>({id:t,representedEdges:[i],affectedBends:[e,n],hitbox:{x:Mo(e._1)(n._1),y:Mo(e._2)(n._2),width:Vn(e._1-n._1),height:Vn(e._2-n._2)},ignoreSpacing:cn,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:J}),tm=t=>e=>{const n=Mo(t.hitbox.x)(e.hitbox.x),r=Mo(t.hitbox.y)(e.hitbox.y);return{...t,representedEdges:[...t.representedEdges,...e.representedEdges],affectedBends:[...t.affectedBends,...e.affectedBends],potentialGroupParents:[...t.potentialGroupParents,...e.potentialGroupParents],hitbox:{x:n,y:r,width:Lg(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Lg(t.hitbox.y+t.hitbox.height)(e.hitbox.y+e.hitbox.height)-r},ignoreSpacing:{left:t.ignoreSpacing.left||e.ignoreSpacing.left,right:t.ignoreSpacing.right||e.ignoreSpacing.right,up:t.ignoreSpacing.up||e.ignoreSpacing.up,down:t.ignoreSpacing.down||e.ignoreSpacing.down},aPort:(()=>{if(t.aPort.tag==="Just")return t.aPort;if(t.aPort.tag==="Nothing")return e.aPort;g()})()}},em=t=>e=>Vn(t.hitbox.x-e.hitbox.x)<=1e-4&&e.hitbox.y-(t.hitbox.y+t.hitbox.height)<=1e-4&&t.hitbox.y-(e.hitbox.y+e.hitbox.height)<=1e-4,nm=t=>e=>Vn(t.hitbox.x-e.hitbox.x)<=1e-4?ut.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?Ne:Je,Eg=(t,e)=>({tag:t,_1:e}),Ds=jt(C)(Wt),Oo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Cg=(()=>{const t={eq:n=>r=>n._1===r._1&&(n._2.tag==="Nothing"?r._2.tag==="Nothing":n._2.tag==="Just"&&r._2.tag==="Just"&&n._2._1===r._2._1)},e={compare:n=>r=>{const i=C.compare(n._1)(r._1);if(i==="LT")return Ne;if(i==="GT")return Je;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?Ge:Ne;if(r._2.tag==="Nothing")return Je;if(n._2.tag==="Just"&&r._2.tag==="Just")return C.compare(n._2._1)(r._2._1);g()},Eq0:()=>t};return T(n=>r=>j(e)(r)()(n))(Q)})(),Qn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},rm=T(t=>e=>j(Cp)(e)()(t))(Q),Qs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=mc.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},im=t=>e=>{const n=Ds(z(o=>b(o.id,o))(t)),r=yt(o=>Oo(o)(n))(e),i=it.compare((()=>{const o=Cg(z(u=>b(u.from.node,u.from.port))(r));if(o.tag==="Leaf")return 0;if(o.tag==="Node")return o._2;g()})())((()=>{const o=Cg(z(u=>b(u.to.node,u.to.port))(r));if(o.tag==="Leaf")return 0;if(o.tag==="Node")return o._2;g()})());if(i==="LT")return{...cn,left:!0,right:!1};if(i==="GT")return{...cn,left:!1,right:!0};if(i==="EQ")return cn;g()},om=t=>yt(e=>{if(e.direction==="V")return w("Just",{start:e.start,end:e.end});if(e.direction==="H")return J;g()})(t.segments),Ro=t=>e=>n=>r=>{if(r.tag==="Just"){const i=Qn(n)(e);if(i.tag==="Just"){const o=Vt(u=>u.id===r._1)(i._1);if(o.tag==="Just")return o._1.side;if(o.tag==="Nothing")return t;g()}if(i.tag==="Nothing")return t;g()}if(r.tag==="Nothing")return t;g()},um=t=>e=>n=>{const r=Ng({origin:w("Just",Eg("SegmentOrigin",n)),kind:w("Just","vs"),hitbox:n.hitbox})(e.cGraph),i=Dp(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const o=Ut(n.potentialGroupParents[0])(i.cNodes);if(o.tag==="Just"){if(o._1.cGroup.tag==="Just")return yg(r.id)(o._1.cGroup._1)(i);if(o._1.cGroup.tag==="Nothing")return i;g()}if(o.tag==="Nothing")return i;g()}return Ss({master:w("Just",r.id),nodes:[r.id]})(i).graph})(),edgeToCs:T(o=>u=>vt(C)(ee)(u)([r.id])(o))(e.edgeToCs)(n.representedEdges),lockMap:j(it)(r.id)(im(t)(n.representedEdges))(e.lockMap)}},sm=t=>e=>n=>{const r=At(i=>J,i=>o=>w("Just",{head:i,tail:o}),Lt(nm)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const i=T(o=>u=>em(o.survivor)(u)?{...o,survivor:tm(o.survivor)(u)}:{survivor:u,merged:[...o.merged,o.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return T(um(t))(n)([...i.merged,i.survivor])}g()},am=t=>({cGraph:{cNodes:Q,cNodeOrder:[],cGroups:Q,cGroupOrder:[],supportedDirections:rm([pg,Es,Lp]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:Q,edgeToCs:Q,lockMap:Q}),cm=t=>{const e=rt(4);return{x:t.position._1*e,y:t.position._2*e,width:t.size._1*e,height:t.size._2*e}},gm=t=>e=>n=>T(r=>i=>{const o=Ng({origin:w("Just",Eg("NodeOrigin",i.node)),kind:J,hitbox:cm(i)})(r.cGraph),u=Qn(i.node)(t),s=(()=>{if(u.tag==="Nothing")return b(0,0);if(u.tag==="Just")return u._1;g()})();return{...r,cGraph:Ss({master:w("Just",o.id),nodes:[o.id]})(o.graph).graph,nodeToC:j(C)(i.node)(o.id)(r.nodeToC),lockMap:j(it)(o.id)((()=>{const a=s._1-s._2|0;return a<0?{...cn,left:!0}:a>0?{...cn,right:!0}:cn})())(r.lockMap)}})(n)(e),fm=t=>T(e=>n=>vt(C)(r=>i=>b(r._1+i._1|0,r._2+i._2|0))(n.to.node)(b(1,0))(vt(C)(r=>i=>b(r._1+i._1|0,r._2+i._2|0))(n.from.node)(b(0,1))(e)))(Q)(t),_m=t=>T(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?j(C)(n.origin._1._1)(n.hitbox.x)(e):e)(Q)(yt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),dm=t=>T(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?j(C)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(Q)(yt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),lm=t=>T(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return T(i=>o=>j(mc)(o)(r)(i))(e)(n.origin._1._1.affectedBends)}return e})(Q)(yt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),Sg=t=>{const e=Ds(z(n=>b(n.id,n))(t.edges));return yt(n=>{const r=Oo(n.edge)(e);if(r.tag==="Just")return n.reversed?w("Just",{edgeId:n.edge,src:r._1.to.node,tgt:r._1.from.node,srcSide:Ro(Pn)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:Ro(In)(t.ports)(r._1.from.node)(r._1.from.port),path:n}):w("Just",{edgeId:n.edge,src:r._1.from.node,tgt:r._1.to.node,srcSide:Ro(Pn)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:Ro(In)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return J;g()})(t.paths)},hm=t=>e=>{const n=Tt(e)(r=>{if(r.src===r.tgt)return[];if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return[];const i=Qn(r.tgt)(t.nodeToC),o=(()=>{if(i.tag==="Just")return Ut(i._1)(t.cGraph.cNodes);if(i.tag==="Nothing")return J;g()})(),u=Qn(r.src)(t.nodeToC),s=(()=>{if(u.tag==="Just")return Ut(u._1)(t.cGraph.cNodes);if(u.tag==="Nothing")return J;g()})(),a=(()=>{if(s.tag==="Just"){if(o.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(o._1.cGroup.tag==="Just")return w("Just",{srcGroup:s._1.cGroup._1,tgtGroup:o._1.cGroup._1,delta:0,weight:100});if(o._1.cGroup.tag==="Nothing")return J;g()}if(s._1.cGroup.tag==="Nothing")return J;g()}if(o.tag==="Nothing")return J;g()}if(s.tag==="Nothing")return J;g()})(),c=_=>h=>p=>{if(s.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(p.cGroup.tag==="Just")return _(p.hitbox.x)&&p.cGroup._1!==s._1.cGroup._1?w("Just",h(p.cGroup._1)(s._1.cGroup._1)):J;if(p.cGroup.tag==="Nothing")return J;g()}if(s._1.cGroup.tag==="Nothing")return J;g()}if(s.tag==="Nothing")return J;g()},f=yt(_=>Ut(_)(t.cGraph.cNodes))((()=>{const _=Oo(r.edgeId)(t.edgeToCs);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})()),d=(()=>{if(s.tag==="Just"&&r.srcSide==="West"){const _=s._1;return yt(c(h=>h<_.hitbox.x)(h=>p=>({srcGroup:h,tgtGroup:p,delta:1,weight:100})))(f)}return[]})(),l=(()=>{if(s.tag==="Just"&&r.tgtSide==="East"){const _=s._1;return yt(c(h=>h>_.hitbox.x)(h=>p=>({srcGroup:p,tgtGroup:h,delta:1,weight:100})))(f)}return[]})();if(a.tag==="Nothing")return[];if(a.tag==="Just")return[a._1,...d,...l];g()});return{sameEdgeVerticalSegments:r=>i=>r.origin.tag==="Just"&&r.origin._1.tag==="SegmentOrigin"&&i.origin.tag==="Just"&&i.origin._1.tag==="SegmentOrigin"&&(()=>{const o=i.origin._1._1;return Be(u=>We(_n)(u)(o.representedEdges),r.origin._1._1.representedEdges)})(),vsLNodePair:r=>i=>r.origin.tag==="Just"&&i.origin.tag==="Just"&&(r.origin._1.tag==="SegmentOrigin"?i.origin._1.tag==="NodeOrigin":r.origin._1.tag==="NodeOrigin"&&i.origin._1.tag==="SegmentOrigin"),edgeLengthEdges:r=>n}},pm=t=>e=>{const n=rt(4),r=_m(t),i=dm(t),o=Ds(z(s=>b(s.id,b(s.from.node,s.to.node)))(e.edges)),u=lm(t);return{nodes:z(s=>{const a=Qn(s.node)(r);if(a.tag==="Just")return{...s,position:b(a._1/n,s.position._2)};if(a.tag==="Nothing")return s;g()})(e.nodes),edges:z(s=>{const a=Oo(s.edge)(o),c=(()=>{if(a.tag==="Nothing")return s.segments;if(a.tag==="Just"){const f=Qn(a._1._1)(i),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})(),l=Qn(a._1._2)(i),_=(()=>{if(l.tag==="Nothing")return 0;if(l.tag==="Just")return l._1;g()})();return Ft((()=>{const h=s.reversed?_:d,p=s.reversed?d:_,m=s.segments.length;return x=>y=>{if(y.direction==="V"){const N=(()=>{if(x===0)return h;if(x===(m-1|0))return p;const v=Qs(y.start)(u);if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})();return{...y,start:b(y.start._1+N,y.start._2),end:b(y.end._1+N,y.end._2)}}if(y.direction==="H")return{...y,start:b((()=>{if(x===0)return y.start._1+h;const N=Qs(y.start)(u);if(N.tag==="Nothing")return y.start._1+0;if(N.tag==="Just")return y.start._1+N._1;g()})(),y.start._2),end:b((()=>{if(x===(m-1|0))return y.end._1+p;const N=Qs(y.end)(u);if(N.tag==="Nothing")return y.end._1+0;if(N.tag==="Just")return y.end._1+N._1;g()})(),y.end._2)};g()}})())(s.segments)}g()})();return{...s,segments:c,bends:we(f=>d=>f.end,c,bt(1,c.length,c))}})(e.paths)}},mm=t=>e=>n=>r=>i=>o=>{const u=Is(i.nextId)(o._2.start)(o._2.end)(J)(t.edgeId),s=(()=>{if(o._1===0){if(e.tag==="Nothing")return u;if(e.tag==="Just")return{...u,ignoreSpacing:o._2.end._2<e._1.y?{...u.ignoreSpacing,down:!0}:o._2.end._2>e._1.y+e._1.height?{...u.ignoreSpacing,up:!0}:{...u.ignoreSpacing,up:!0,down:!0}};g()}return u})();return{nextId:i.nextId+1|0,segments:[...i.segments,(()=>{if(o._1===r){if(n.tag==="Nothing")return s;if(n.tag==="Just")return{...s,ignoreSpacing:o._2.start._2<n._1.y?{...s.ignoreSpacing,down:!0}:o._2.start._2>n._1.y+n._1.height?{...s.ignoreSpacing,up:!0}:{...s.ignoreSpacing,up:!0,down:!0}};g()}return s})()]}},Gg=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...Is(o.nextId)(r.start)(b(r.start._1,i.down?n.y:n.y+n.height))(w("Just",e))(t.edgeId),aPort:w("Just",{node:t.src,side:i.side}),ignoreSpacing:i.down?{...cn,down:!0}:{...cn,up:!0}}]}),Bo=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...Is(o.nextId)(r.end)(b(r.end._1,i.down?n.y:n.y+n.height))(w("Just",e))(t.edgeId),aPort:w("Just",{node:t.tgt,side:i.side}),ignoreSpacing:i.down?{...cn,down:!0}:{...cn,up:!0}}]}),xm=t=>e=>n=>{if(n.src===n.tgt)return e;const r=Qn(n.src)(t.nodeToC),i=Qn(n.tgt)(t.nodeToC),o=(()=>{if(r.tag==="Just"){const f=Ut(r._1)(t.cGraph.cNodes);return f.tag==="Just"?w("Just",f._1.hitbox):J}if(r.tag==="Nothing")return J;g()})(),u=(()=>{if(i.tag==="Just"){const f=Ut(i._1)(t.cGraph.cNodes);return f.tag==="Just"?w("Just",f._1.hitbox):J}if(i.tag==="Nothing")return J;g()})(),s=om(n.path),a=T(mm(n)(o)(u)(s.length-1|0))(e)(Ft(f=>d=>b(f,d))(s));if(0<s.length){const f=(()=>{if(r.tag==="Just"&&o.tag==="Just"){if(n.srcSide==="North")return Gg(n)(r._1)(o._1)(s[0])({side:le,down:!0})(a);if(n.srcSide==="South")return Gg(n)(r._1)(o._1)(s[0])({side:he,down:!1})(a)}return a})(),d=s.length-1|0;if(d>=0&&d<s.length&&i.tag==="Just"&&u.tag==="Just"){if(n.tgtSide==="North")return Bo(n)(i._1)(u._1)(s[d])({side:le,down:!0})(f);if(n.tgtSide==="South")return Bo(n)(i._1)(u._1)(s[d])({side:he,down:!1})(f)}return f}const c=s.length-1|0;if(c>=0&&c<s.length&&i.tag==="Just"&&u.tag==="Just"){if(n.tgtSide==="North")return Bo(n)(i._1)(u._1)(s[c])({side:le,down:!0})(a);if(n.tgtSide==="South")return Bo(n)(i._1)(u._1)(s[c])({side:he,down:!1})(a)}return a},ym=t=>e=>n=>sm(t)(T(xm(n))({nextId:0,segments:[]})(e).segments)(n),Nm=t=>ym(t.edges)(Sg(t))(gm(fm(t.edges))(t.nodes)(am())),Fn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=it.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Fs=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},As=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=it.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Jm=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Tm=t=>{const e=t.Eq0();return n=>r=>{const i=s=>{let a=s,c=!0,f;for(;c;){const d=a,l=At(_=>J,_=>h=>w("Just",{head:_,tail:h}),d.queue);if(l.tag==="Nothing"){c=!1,f=d;continue}if(l.tag==="Just"){const _=l._1.head;if((p=>{let m=p,x=!0,y;for(;x;){const N=m;if(N.tag==="Leaf"){x=!1,y=!1;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){x=!1,y=!0;continue}}g()}return y})(d.removedNodes)){a={...d,queue:l._1.tail};continue}const h=Vt(p=>!Fn(p.eid)(d.removedEdges)&&(e.eq(p.src)(_)||e.eq(p.tgt)(_)))(r);if(h.tag==="Nothing"){a={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const p=e.eq(h._1.src)(_)?h._1.tgt:h._1.src,m={...d,degree:j(t)(p)((()=>{const x=(y=>{let N=y,v=!0,L;for(;v;){const k=N;if(k.tag==="Leaf"){v=!1,L=J;continue}if(k.tag==="Node"){const E=t.compare(p)(k._3);if(E==="LT"){N=k._5;continue}if(E==="GT"){N=k._6;continue}if(E==="EQ"){v=!1,L=w("Just",k._4);continue}}g()}return L})(d.degree);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;g()})())(d.degree),removedNodes:j(t)(_)()(d.removedNodes),removedEdges:j(it)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:_,neighbour:p,viaSrc:e.eq(h._1.src)(_)}],queue:l._1.tail};if((()=>{const x=(N=>{let v=N,L=!0,k;for(;L;){const E=v;if(E.tag==="Leaf"){L=!1,k=J;continue}if(E.tag==="Node"){const O=t.compare(p)(E._3);if(O==="LT"){v=E._5;continue}if(O==="GT"){v=E._6;continue}if(O==="EQ"){L=!1,k=w("Just",E._4);continue}}g()}return k})(m.degree),y=N=>{let v=N,L=!0,k;for(;L;){const E=v;if(E.tag==="Leaf"){L=!1,k=!1;continue}if(E.tag==="Node"){const O=t.compare(p)(E._3);if(O==="LT"){v=E._5;continue}if(O==="GT"){v=E._6;continue}if(O==="EQ"){L=!1,k=!0;continue}}g()}return k};return(()=>{if(x.tag==="Nothing")return!1;if(x.tag==="Just")return x._1===1;g()})()&&!y(m.removedNodes)})()){a={...m,queue:[...m.queue,p]};continue}a=m;continue}}g()}return f},o=T(s=>a=>vt(t)(ue)(a.src)(1)(vt(t)(ue)(a.tgt)(1)(s)))(Q)(r),u=i({degree:o,removedNodes:Q,removedEdges:Q,record:[],queue:st(s=>{const a=(c=>{let f=c,d=!0,l;for(;d;){const _=f;if(_.tag==="Leaf"){d=!1,l=J;continue}if(_.tag==="Node"){const h=t.compare(s)(_._3);if(h==="LT"){f=_._5;continue}if(h==="GT"){f=_._6;continue}if(h==="EQ"){d=!1,l=w("Just",_._4);continue}}g()}return l})(o);if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1===1;g()},n)});return{coreNodes:st(s=>!(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=!1;continue}if(l.tag==="Node"){const _=t.compare(s)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=!0;continue}}g()}return d})(u.removedNodes),n),coreEdges:st(s=>!Fn(s.eid)(u.removedEdges),r),removed:u.record}}},wm=t=>e=>n=>T(r=>i=>{const o=i.neighbour,u=(()=>{const s=(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=J;continue}if(l.tag==="Node"){const _=t.compare(o)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=w("Just",l._4);continue}}g()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})();return j(t)(i.node)(i.viaSrc?u-1|0:u+1|0)(r)})(n)(Te(e)),Ms=t=>{const e=t.Eq0();return n=>r=>i=>{const o={...i,treeNode:j(t)(r)()(i.treeNode)};return T(u=>s=>{if(Fn(s.eid)(u.st.edgeVisited))return u;const a={...u.st,edgeVisited:j(it)(s.eid)()(u.st.edgeVisited)},c=e.eq(s.src)((()=>{const f=s.src,d=_=>{let h=_,p=!0,m;for(;p;){const x=h;if(x.tag==="Leaf"){p=!1,m=!1;continue}if(x.tag==="Node"){const y=t.compare(f)(x._3);if(y==="LT"){h=x._5;continue}if(y==="GT"){h=x._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}g()}return m},l=s.tgt;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const x=h;if(x.tag==="Leaf"){p=!1,m=!1;continue}if(x.tag==="Node"){const y=t.compare(l)(x._3);if(y==="LT"){h=x._5;continue}if(y==="GT"){h=x._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?s.src:(()=>{const f=s.tgt,d=_=>{let h=_,p=!0,m;for(;p;){const x=h;if(x.tag==="Leaf"){p=!1,m=!1;continue}if(x.tag==="Node"){const y=t.compare(f)(x._3);if(y==="LT"){h=x._5;continue}if(y==="GT"){h=x._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}g()}return m},l=s.src;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const x=h;if(x.tag==="Leaf"){p=!1,m=!1;continue}if(x.tag==="Node"){const y=t.compare(l)(x._3);if(y==="LT"){h=x._5;continue}if(y==="GT"){h=x._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(Fn(s.eid)(a.treeEdge)){if((d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=!1;continue}if(p.tag==="Node"){const m=t.compare(c)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=!0;continue}}g()}return h})(a.treeNode))return{...u,st:a};const f=Ms(t)(n)(c)(a);return{count:u.count+f.count|0,st:f.st}}if((()=>{const f=l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=!1;continue}if(m.tag==="Node"){const x=t.compare(c)(m._3);if(x==="LT"){_=m._5;continue}if(x==="GT"){_=m._6;continue}if(x==="EQ"){h=!1,p=!0;continue}}g()}return p},d=s.tgt;return!f(a.treeNode)&&(()=>{const l=(p=>{let m=p,x=!0,y;for(;x;){const N=m;if(N.tag==="Leaf"){x=!1,y=J;continue}if(N.tag==="Node"){const v=t.compare(d)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){x=!1,y=w("Just",N._4);continue}}g()}return y})(a.layer),_=s.src,h=(p=>{let m=p,x=!0,y;for(;x;){const N=m;if(N.tag==="Leaf"){x=!1,y=J;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){x=!1,y=w("Just",N._4);continue}}g()}return y})(a.layer);if(l.tag==="Nothing"){if(h.tag==="Nothing")return s.delta===0;if(h.tag==="Just")return s.delta===-h._1;g()}if(l.tag==="Just"){if(h.tag==="Nothing")return s.delta===(l._1-0|0);if(h.tag==="Just")return s.delta===(l._1-h._1|0)}g()})()})()){const f=Ms(t)(n)(c)({...a,treeEdge:j(it)(s.eid)()(a.treeEdge)});return{count:u.count+f.count|0,st:f.st}}return{...u,st:a}})({count:1,st:o})(st(u=>(e.eq(u.src)(r)||e.eq(u.tgt)(r))&&!Fn(u.eid)(o.edgeVisited),n))}},Wo=t=>e=>n=>r=>{const i=r.src,o=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const x=t.compare(i)(m._3);if(x==="LT"){_=m._5;continue}if(x==="GT"){_=m._6;continue}if(x==="EQ"){h=!1,p=w("Just",m._4);continue}}g()}return p})(e.poID),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})(),s=r.tgt,a=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const x=t.compare(s)(m._3);if(x==="LT"){_=m._5;continue}if(x==="GT"){_=m._6;continue}if(x==="EQ"){h=!1,p=w("Just",m._4);continue}}g()}return p})(e.poID),c=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})(),f=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const x=t.compare(n)(m._3);if(x==="LT"){_=m._5;continue}if(x==="GT"){_=m._6;continue}if(x==="EQ"){h=!1,p=w("Just",m._4);continue}}g()}return p})(e.poID),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return(()=>{const l=r.src,_=(h=>{let p=h,m=!0,x;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,x=J;continue}if(y.tag==="Node"){const N=t.compare(l)(y._3);if(N==="LT"){p=y._5;continue}if(N==="GT"){p=y._6;continue}if(N==="EQ"){m=!1,x=w("Just",y._4);continue}}g()}return x})(e.lowestPoID);return(()=>{if(_.tag==="Nothing")return 0<=d;if(_.tag==="Just")return _._1<=d;g()})()&&(()=>{const h=r.tgt;return d<=u&&(()=>{const p=(m=>{let x=m,y=!0,N;for(;y;){const v=x;if(v.tag==="Leaf"){y=!1,N=J;continue}if(v.tag==="Node"){const L=t.compare(h)(v._3);if(L==="LT"){x=v._5;continue}if(L==="GT"){x=v._6;continue}if(L==="EQ"){y=!1,N=w("Just",v._4);continue}}g()}return N})(e.lowestPoID);return(()=>{if(p.tag==="Nothing")return 0<=d;if(p.tag==="Just")return p._1<=d;g()})()&&d<=c})()})()})()?u>=c:u<c},vm=t=>{const e=jt(t)(Wt);return n=>({layer:e(z(r=>b(r,0))(n)),treeNode:Q,treeEdge:Q,poID:Q,lowestPoID:Q,cutvalue:Q,postOrder:1,edgeVisited:Q})},bm=t=>e=>n=>T(r=>i=>{if((()=>{const f=i.src,d=h=>{let p=h,m=!0,x;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,x=!1;continue}if(y.tag==="Node"){const N=t.compare(f)(y._3);if(N==="LT"){p=y._5;continue}if(N==="GT"){p=y._6;continue}if(N==="EQ"){m=!1,x=!0;continue}}g()}return x},l=i.tgt,_=h=>{let p=h,m=!0,x;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,x=!1;continue}if(y.tag==="Node"){const N=t.compare(l)(y._3);if(N==="LT"){p=y._5;continue}if(N==="GT"){p=y._6;continue}if(N==="EQ"){m=!1,x=!0;continue}}g()}return x};return d(n.treeNode)===_(n.treeNode)})())return r;const o=i.tgt,u=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(o)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(n.layer),s=i.src,a=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(s)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(n.layer),c=(()=>{if(u.tag==="Nothing"){if(a.tag==="Nothing")return-i.delta;if(a.tag==="Just")return-a._1-i.delta|0;g()}if(u.tag==="Just"){if(a.tag==="Nothing")return(u._1-0|0)-i.delta|0;if(a.tag==="Just")return(u._1-a._1|0)-i.delta|0}g()})();return c<r.slack?{edge:w("Just",i),slack:c}:r})({edge:J,slack:1e9})(e).edge,km=t=>{const e=jt(t)(Wt);return n=>r=>{const i=T(o=>u=>Fs(o)((()=>{const s=(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=J;continue}if(l.tag==="Node"){const _=t.compare(u)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=w("Just",l._4);continue}}g()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(1e9)(n);return e(z(o=>b(o,(()=>{const u=(s=>{let a=s,c=!0,f;for(;c;){const d=a;if(d.tag==="Leaf"){c=!1,f=J;continue}if(d.tag==="Node"){const l=t.compare(o)(d._3);if(l==="LT"){a=d._5;continue}if(l==="GT"){a=d._6;continue}if(l==="EQ"){c=!1,f=w("Just",d._4);continue}}g()}return f})(r);if(u.tag==="Nothing")return-i;if(u.tag==="Just")return u._1-i|0;g()})()))(n))}},Pg=t=>{const e=t.Eq0();return n=>r=>i=>{const o=T(s=>a=>{const c=Pg(t)(n)(e.eq(a.src)(r)?a.tgt:a.src)({...s.st,edgeVisited:j(it)(a.eid)()(s.st.edgeVisited)});return{lowest:Fs(s.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:i})(st(s=>Fn(s.eid)(i.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!Fn(s.eid)(i.edgeVisited),n)),u=Fs(o.lowest)(o.st.postOrder);return{lowest:u,st:{...o.st,poID:j(t)(r)(o.st.postOrder)(o.st.poID),lowestPoID:j(t)(r)(u)(o.st.lowestPoID),postOrder:o.st.postOrder+1|0}}}},Ig=t=>{const e=Pg(t);return n=>r=>i=>0<n.length?e(r)(n[0])({...i,edgeVisited:Q,postOrder:1,poID:Q,lowestPoID:Q}).st:i},Lm=t=>{const e=t.Eq0();return n=>r=>i=>st(o=>Fn(o.eid)(r.treeEdge)&&(e.eq(o.src)(i)||e.eq(o.tgt)(i)),n)},Em=t=>e=>Vt(n=>{const r=As(n.eid)(e.cutvalue);return Fn(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),Dg=t=>{const e=Ms(t);return n=>r=>i=>{const o=0<n.length?w("Just",n[0]):J;if(o.tag==="Nothing")return i;if(o.tag==="Just"){const u=e(r)(o._1)({...i,edgeVisited:Q,treeNode:Q,treeEdge:Q});if(u.count>=n.length)return u.st;const s=bm(t)(r)(u.st);if(s.tag==="Nothing")return u.st;if(s.tag==="Just"){const a=s._1.tgt,c=(h=>{let p=h,m=!0,x;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,x=J;continue}if(y.tag==="Node"){const N=t.compare(a)(y._3);if(N==="LT"){p=y._5;continue}if(N==="GT"){p=y._6;continue}if(N==="EQ"){m=!1,x=w("Just",y._4);continue}}g()}return x})(u.st.layer),f=s._1.src,d=(h=>{let p=h,m=!0,x;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,x=J;continue}if(y.tag==="Node"){const N=t.compare(f)(y._3);if(N==="LT"){p=y._5;continue}if(N==="GT"){p=y._6;continue}if(N==="EQ"){m=!1,x=w("Just",y._4);continue}}g()}return x})(u.st.layer),l=(()=>{if(c.tag==="Nothing"){if(d.tag==="Nothing")return-s._1.delta;if(d.tag==="Just")return-d._1-s._1.delta|0;g()}if(c.tag==="Just"){if(d.tag==="Nothing")return(c._1-0|0)-s._1.delta|0;if(d.tag==="Just")return(c._1-d._1|0)-s._1.delta|0}g()})(),_=(()=>{const h=s._1.tgt;return(p=>{let m=p,x=!0,y;for(;x;){const N=m;if(N.tag==="Leaf"){x=!1,y=!1;continue}if(N.tag==="Node"){const v=t.compare(h)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){x=!1,y=!0;continue}}g()}return y})(u.st.treeNode)})()?-l:l;return Dg(t)(n)(r)({...u.st,layer:T(h=>p=>(m=>{let x=m,y=!0,N;for(;y;){const v=x;if(v.tag==="Leaf"){y=!1,N=!1;continue}if(v.tag==="Node"){const L=t.compare(p)(v._3);if(L==="LT"){x=v._5;continue}if(L==="GT"){x=v._6;continue}if(L==="EQ"){y=!1,N=!0;continue}}g()}return N})(u.st.treeNode)?j(t)(p)((()=>{const m=(x=>{let y=x,N=!0,v;for(;N;){const L=y;if(L.tag==="Leaf"){N=!1,v=J;continue}if(L.tag==="Node"){const k=t.compare(p)(L._3);if(k==="LT"){y=L._5;continue}if(k==="GT"){y=L._6;continue}if(k==="EQ"){N=!1,v=w("Just",L._4);continue}}g()}return v})(u.st.layer);if(m.tag==="Nothing")return 0+_|0;if(m.tag==="Just")return m._1+_|0;g()})())(h):h)(u.st.layer)(n)})}}g()}},Cm=t=>e=>n=>r=>T(i=>o=>{if(Wo(t)(r)(o.src)(n)&&!Wo(t)(r)(o.tgt)(n)){const u=o.tgt,s=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=J;continue}if(p.tag==="Node"){const m=t.compare(u)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=w("Just",p._4);continue}}g()}return h})(r.layer),a=o.src,c=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=J;continue}if(p.tag==="Node"){const m=t.compare(a)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=w("Just",p._4);continue}}g()}return h})(r.layer),f=(()=>{if(s.tag==="Nothing"){if(c.tag==="Nothing")return-o.delta;if(c.tag==="Just")return-c._1-o.delta|0;g()}if(s.tag==="Just"){if(c.tag==="Nothing")return(s._1-0|0)-o.delta|0;if(c.tag==="Just")return(s._1-c._1|0)-o.delta|0}g()})();if(f<i.slack)return{edge:w("Just",o),slack:f}}return i})({edge:J,slack:1e9})(e).edge,Sm=t=>{const e=t.Eq0();return n=>r=>i=>o=>{const u=o.tgt,s=o.src;return T(a=>c=>{if((()=>{const f=As(c.eid)(r.cutvalue);if(f.tag==="Just")return!0;if(f.tag==="Nothing")return!1;g()})()){const f=As(c.eid)(r.cutvalue),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return e.eq(s)(c.src)||e.eq(u)(c.tgt)?a-(d-c.weight):a+(d-c.weight)}return e.eq(i)(s)?e.eq(c.src)(i)?a+c.weight:a-c.weight:e.eq(c.src)(i)?a-c.weight:a+c.weight})(o.weight)(st(a=>a.eid!==o.eid&&(e.eq(a.src)(i)||e.eq(a.tgt)(i)),n))}},Gm=t=>{const e=Sm(t);return n=>r=>i=>{const o=(u,s,a)=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(u)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(a);if(c.tag==="Just")return j(t)(u)(st(f=>f.eid!==s.eid,c._1))(a);if(c.tag==="Nothing")return a;g()};return(u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=(m=>{let x=m,y=!0,N;for(;y;){const v=x;if(v.tag==="Leaf"){y=!1,N=J;continue}if(v.tag==="Node"){const L=t.compare(_)(v._3);if(L==="LT"){x=v._5;continue}if(L==="GT"){x=v._6;continue}if(L==="EQ"){y=!1,N=w("Just",v._4);continue}}g()}return N})(l.unknown),p=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;g()})();if(p.length===1){const m=t.Eq0().eq(p[0].src)(_)?p[0].tgt:p[0].src;a={unknown:o(_,p[0],o(m,p[0],l.unknown)),cutvalue:j(it)(p[0].eid)(e(n)(l)(_)(p[0]))(l.cutvalue)},c=m;continue}f=!1,d=l}return d})(r)(i)}},Qg=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:c=>f=>c.delta===f.delta&&c.eid===f.eid&&n.eq(c.src)(f.src)&&e.eq(c.tgt)(f.tgt)&&c.weight===f.weight},i={compare:c=>f=>{const d=it.compare(c.delta)(f.delta);if(d==="LT"||d==="GT"||d!=="EQ")return d;const l=it.compare(c.eid)(f.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const _=t.compare(c.src)(f.src);if(_==="LT"||_==="GT"||_!=="EQ")return _;const h=t.compare(c.tgt)(f.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const p=ut.compare(c.weight)(f.weight);return p==="LT"||p==="GT"||p!=="EQ"?p:Ge},Eq0:()=>r},o=T(c=>f=>j(i)(f)()(c))(Q),u=Lm(t),s=jt(t)(Wt),a=Gm(t);return c=>f=>d=>{const l={unknown:s(z(_=>b(_,Ct(qe.foldr,o(u(f)(d)(_)))))(c)),cutvalue:Q};return{...d,cutvalue:T(a(f))(l)(st(_=>{const h=(p=>{let m=p,x=!0,y;for(;x;){const N=m;if(N.tag==="Leaf"){x=!1,y=J;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){x=!1,y=w("Just",N._4);continue}}g()}return y})(l.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;g()},c)).cutvalue}}},Pm=t=>{const e=Ig(t),n=Qg(t);return r=>i=>o=>u=>s=>{const a={...s,treeEdge:j(it)(u.eid)()(gi(it)(o.eid)(s.treeEdge))},c=u.tgt,f=(p=>{let m=p,x=!0,y;for(;x;){const N=m;if(N.tag==="Leaf"){x=!1,y=J;continue}if(N.tag==="Node"){const v=t.compare(c)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){x=!1,y=w("Just",N._4);continue}}g()}return y})(a.layer),d=u.src,l=(p=>{let m=p,x=!0,y;for(;x;){const N=m;if(N.tag==="Leaf"){x=!1,y=J;continue}if(N.tag==="Node"){const v=t.compare(d)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){x=!1,y=w("Just",N._4);continue}}g()}return y})(a.layer),_=(()=>{if(f.tag==="Nothing"){if(l.tag==="Nothing")return-u.delta;if(l.tag==="Just")return-l._1-u.delta|0;g()}if(f.tag==="Just"){if(l.tag==="Nothing")return(f._1-0|0)-u.delta|0;if(l.tag==="Just")return(f._1-l._1|0)-u.delta|0}g()})(),h=Wo(t)(a)(u.tgt)(o)?_:-_;return n(r)(i)(e(r)(i)({...a,layer:T(p=>m=>Wo(t)(a)(m)(o)?p:j(t)(m)((()=>{const x=(y=>{let N=y,v=!0,L;for(;v;){const k=N;if(k.tag==="Leaf"){v=!1,L=J;continue}if(k.tag==="Node"){const E=t.compare(m)(k._3);if(E==="LT"){N=k._5;continue}if(E==="GT"){N=k._6;continue}if(E==="EQ"){v=!1,L=w("Just",k._4);continue}}g()}return L})(a.layer);if(x.tag==="Nothing")return 0+h|0;if(x.tag==="Just")return x._1+h|0;g()})())(p))(a.layer)(r)}))}},Im=t=>{const e=Pm(t);return n=>r=>i=>o=>(u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c;if(l===0){f=!1,d=_;continue}const h=Em(i)(_);if(h.tag==="Nothing"){f=!1,d=_;continue}if(h.tag==="Just"){const p=Cm(t)(i)(h._1)(_);if(p.tag==="Nothing"){f=!1,d=_;continue}if(p.tag==="Just"){a=l-1|0,c=e(r)(i)(h._1)(p._1)(_);continue}}g()}return d})(n)(o)},Dm=t=>{const e=Qg(t),n=Ig(t),r=Dg(t);return i=>o=>u=>e(i)(o)(n(i)(o)(r(i)(o)(u)))},Fg=t=>e=>T(n=>r=>vt(t)(ee)(e(r))([r])(n))(Q),Qm=t=>{const e=jt(t)(Wt);return n=>r=>i=>{const o=a=>c=>f=>d=>{let l=a,_=c,h=f,p=d,m=!0,x;for(;m;){const y=l,N=_,v=h,L=p,k=At(E=>J,E=>O=>w("Just",{head:E,tail:O}),v);if(k.tag==="Nothing"){m=!1,x=L;continue}if(k.tag==="Just"){const E=k._1.head,O=(G=>{let P=G,V=!0,U;for(;V;){const B=P;if(B.tag==="Leaf"){V=!1,U=J;continue}if(B.tag==="Node"){const R=t.compare(E)(B._3);if(R==="LT"){P=B._5;continue}if(R==="GT"){P=B._6;continue}if(R==="EQ"){V=!1,U=w("Just",B._4);continue}}g()}return U})(L.layer),Y=(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;g()})(),et=T(G=>P=>{const V=P.tgt,U=(R=>{let M=R,S=!0,I;for(;S;){const D=M;if(D.tag==="Leaf"){S=!1,I=J;continue}if(D.tag==="Node"){const A=t.compare(V)(D._3);if(A==="LT"){M=D._5;continue}if(A==="GT"){M=D._6;continue}if(A==="EQ"){S=!1,I=w("Just",D._4);continue}}g()}return I})(G.incident),B=(()=>{if(U.tag==="Nothing")return-1;if(U.tag==="Just")return U._1-1|0;g()})();return{st:{...G.st,layer:j(t)(P.tgt)(Jm((()=>{const R=P.tgt,M=(S=>{let I=S,D=!0,A;for(;D;){const H=I;if(H.tag==="Leaf"){D=!1,A=J;continue}if(H.tag==="Node"){const $=t.compare(R)(H._3);if($==="LT"){I=H._5;continue}if($==="GT"){I=H._6;continue}if($==="EQ"){D=!1,A=w("Just",H._4);continue}}g()}return A})(G.st.layer);if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})())(Y+P.delta|0))(G.st.layer)},incident:j(t)(P.tgt)(B)(G.incident),queue:B===0?[...G.queue,P.tgt]:G.queue}})({st:L,incident:N,queue:k._1.tail})((()=>{const G=(P=>{let V=P,U=!0,B;for(;U;){const R=V;if(R.tag==="Leaf"){U=!1,B=J;continue}if(R.tag==="Node"){const M=t.compare(E)(R._3);if(M==="LT"){V=R._5;continue}if(M==="GT"){V=R._6;continue}if(M==="EQ"){U=!1,B=w("Just",R._4);continue}}g()}return B})(y);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})());l=y,_=et.incident,h=et.queue,p=et.st;continue}g()}return x},u=Fg(t)(a=>a.tgt)(r),s=e(z(a=>b(a,(()=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(u);if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1.length;g()})()))(n));return o(Fg(t)(a=>a.src)(r))(s)(st(a=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(s);if(c.tag==="Nothing")return!0;if(c.tag==="Just")return c._1===0;g()},n))(i)}},Fm=t=>{const e=vm(t),n=Qm(t),r=Dm(t),i=Im(t);return o=>u=>{const s=n(o)(u)(e(o));return u.length===0?s.layer:i(4*o.length|0)(o)(u)(r(o)(u)(s)).layer}},Ag=t=>{const e=km(t),n=Fm(t),r=Tm(t);return i=>o=>{if(i.length===0)return Q;if(i.length<40)return e(i)(n(i)(o));const u=r(i)(o);return e(i)(wm(t)(u.removed)(n(u.coreNodes)(u.coreEdges)))}},Mg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=it.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Os=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Am=Ag(it),Ii=t=>e=>({...e,edges:[...e.edges,{src:t.src,tgt:t.tgt,delta:t.delta,weight:t.weight,eid:e.nextEid}],nextEid:e.nextEid+1|0}),Mm=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=rt((()=>{const i=Mg(n.cGroup._1)(t);if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})());return Ue(n.id)(i=>({...i,hitbox:{...i.hitbox,x:r+i.cGroupOffset.x}}))(e)}g()},Om=t=>e=>({...e,cGraph:T(Mm(t))(e.cGraph)((()=>{const n=e.cGraph;return yt(r=>Ut(r)(n.cNodes))(n.cNodeOrder)})())}),Rm=t=>e=>n=>r=>i=>{const o=de(oo(e.cGroupOffset.x-t.cGroupOffset.x));return Ii({src:i.nextNodeId,tgt:r,delta:Os(0)(-o),weight:1})(Ii({src:i.nextNodeId,tgt:n,delta:Os(0)(o),weight:1})({...i,nodes:[...i.nodes,i.nextNodeId],nextNodeId:i.nextNodeId+1|0}))},Bm=t=>e=>n=>r=>i=>o=>u=>{const s=Os(0)(de(oo(n.cGroupOffset.x+n.hitbox.width+(e.direction==="LEFT"||e.direction==="RIGHT"?e.spacingsHandler.horizontalSpacing(n)(r):e.spacingsHandler.verticalSpacing(n)(r))-r.cGroupOffset.x)));return t.sameEdgeVerticalSegments(n)(r)?Rm(n)(r)(i)(o)(u):Ii({src:i,tgt:o,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(u)},Wm=t=>e=>n=>r=>i=>{const o=Ut(i)(e.cGraph.cNodes);if(o.tag==="Nothing")return r;if(o.tag==="Just")return(n.cGroup.tag==="Nothing"?o._1.cGroup.tag==="Nothing":n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"&&n.cGroup._1===o._1.cGroup._1)?r:n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"?Bm(t)(e)(n)(o._1)(n.cGroup._1)(o._1.cGroup._1)(r):r;g()},zm=t=>e=>n=>r=>T(Wm(t)(e)(r))(n)(r.constraints),qm=t=>e=>Ii({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),Hm=t=>{const e=T(i=>o=>vt(it)(ue)(o.tgt)(1)(i))(Q)(t.edges),n=st(i=>{const o=Mg(i)(e);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return o._1===0;g()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return T(i=>o=>Ii({src:r,tgt:o,delta:1,weight:0})(i))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},$m=t=>e=>{const n=Hm(T(qm)(T(zm(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return yt(i=>Ut(i)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},Xm=t=>e=>{const n=$m(t)(e);return Om(Am(n.nodes)(n.edges))(e)},Og=t=>t,ne=Og("H"),re=Og("V"),Ym=t=>b(t._2,t._1),Rg=t=>({...t,position:b(t.position._2,t.position._1),size:b(t.size._2,t.size._1)}),Vm=t=>({start:b(t.start._2,t.start._1),end:b(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return re;if(t.direction==="V")return ne;g()})()}),Bg=t=>({...t,segments:z(Vm)(t.segments),bends:z(Ym)(t.bends)}),Um=t=>({nodes:z(Rg)(t.nodes),edges:t.edges,paths:z(Bg)(t.paths),ports:t.ports}),Zm={nodeNode:8,edgeNode:4,edgeEdge:10},Km=t=>e=>({horizontalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r)||n.ignoreSpacing.right||r.ignoreSpacing.left)return 0;const i=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?i?t.edgeEdge:t.edgeNode:i?t.edgeNode:t.nodeNode},verticalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r))return 1;if(n.hitbox.y<=r.hitbox.y?n.ignoreSpacing.down||r.ignoreSpacing.up:n.ignoreSpacing.up||r.ignoreSpacing.down)return 0;const i=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?i?t.edgeEdge:t.edgeNode:i?t.edgeNode:t.nodeNode}}),jm=t=>e=>Xm(e),tx=t=>e=>n=>{const r=Um(n),i=Nm(r),o=hm(i)(Sg(r)),u=pm(xg(Es)(Op({...Bp(i.cGraph),compactionAlgorithm:w("Just",jm()(o)),constraintAlgorithm:w("Just",jp(e.edgeEdge)),spacingsHandler:Km(e)(o)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:z(Rg)(u.nodes),edges:z(Bg)(u.edges)}},Wg=t=>t,qr=jt(it)(Wt),It=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=it.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},zg=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},dt=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},lt=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Hr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},ex=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?Ne:n==="GT"?Je:it.compare(t._2)(e._2)},$r=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},nx=(()=>{const t=Xe.unfoldr(mn);return e=>t(Ye("IterNode",e,pn))})(),rx=t=>t,qg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},ix=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},zo=Wg("Regular"),qo=Wg("Critical"),Hg=t=>e=>{const n=T(u=>s=>j(C)(s.node)(s)(u))(Q)(e),r=1.25*rt(4),i=(u,s,a)=>(c=>f=>d=>{let l=c,_=f,h=d,p=!0,m;for(;p;){const x=l,y=_,N=h;if(N.critical){p=!1,m=N;continue}const v=At(k=>J,k=>E=>w("Just",{head:k,tail:E}),x),L=At(k=>J,k=>E=>w("Just",{head:k,tail:E}),y);if(v.tag==="Just"&&L.tag==="Just"){const k=v._1.head>L._1.head-u&&v._1.head<L._1.head+u?{...N,critical:!0}:v._1.head>L._1.head-r&&v._1.head<L._1.head+r?{...N,conflicts:N.conflicts+1|0}:N;if(k.critical){p=!1,m=k;continue}if(v._1.head<=L._1.head){l=v._1.tail,_=y,h=k;continue}l=x,_=L._1.tail,h=k;continue}p=!1,m=N}return m})(s)(a)({conflicts:0,critical:!1}),o=(u,s,a)=>{if(lt(T(lt)(-1e18)(s.incoming))(T(lt)(-1e18)(s.outgoing))-dt(T(dt)(1e18)(s.incoming))(T(dt)(1e18)(s.outgoing))<.001||lt(T(lt)(-1e18)(a.incoming))(T(lt)(-1e18)(a.outgoing))-dt(T(dt)(1e18)(a.incoming))(T(dt)(1e18)(a.outgoing))<.001)return[];const c=i(u,s.outgoing,a.incoming),f=i(u,a.outgoing,s.incoming);if(c.critical||f.critical)return[...c.critical?[{src:a.id,tgt:s.id,weight:1,kind:qo}]:[],...f.critical?[{src:s.id,tgt:a.id,weight:1,kind:qo}]:[]];const d=dt(T(dt)(1e18)(s.incoming))(T(dt)(1e18)(s.outgoing)),l=lt(T(lt)(-1e18)(s.incoming))(T(lt)(-1e18)(s.outgoing)),_=dt(T(dt)(1e18)(a.incoming))(T(dt)(1e18)(a.outgoing)),h=lt(T(lt)(-1e18)(a.incoming))(T(lt)(-1e18)(a.outgoing)),p=(1*c.conflicts|0)+(16*(T(x=>y=>y>h?x:y>=_?x+1|0:x)(0)(s.outgoing)+T(x=>y=>y>l?x:y>=d?x+1|0:x)(0)(a.incoming)|0)|0)|0,m=(1*f.conflicts|0)+(16*(T(x=>y=>y>l?x:y>=d?x+1|0:x)(0)(a.outgoing)+T(x=>y=>y>h?x:y>=_?x+1|0:x)(0)(s.incoming)|0)|0)|0;return p<m?[{src:s.id,tgt:a.id,weight:m-p|0,kind:zo}]:p>m?[{src:a.id,tgt:s.id,weight:p-m|0,kind:zo}]:p>0?[{src:s.id,tgt:a.id,weight:0,kind:zo},{src:a.id,tgt:s.id,weight:0,kind:zo}]:[]};return T(u=>s=>T(a=>c=>j(C)(c._1)(c._2)(a))(u)((()=>{const a=T(G=>P=>{const V=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;g()})(),U=qg(V)(G.entries);if(U.tag==="Nothing")return{...G,entries:j(C)(V)({id:0,members:[P.edge.id],incoming:[P.fromPos._1],outgoing:[P.toPos._1],slot:0,mark:0,splitBy:J,splitPartner:J})(G.entries),order:[...G.order,V]};if(U.tag==="Just")return{...G,entries:j(C)(V)({...U._1,members:[...U._1.members,P.edge.id],incoming:[...gr(B=>B<P.fromPos._1)(U._1.incoming).init,P.fromPos._1,...gr(B=>B<=P.fromPos._1)(U._1.incoming).rest],outgoing:[...gr(B=>B<P.toPos._1)(U._1.outgoing).init,P.toPos._1,...gr(B=>B<=P.toPos._1)(U._1.outgoing).rest]})(G.entries)};g()})({entries:Q,order:[]})(s._2),c=Ft(G=>P=>({...P,id:G}))(yt(G=>qg(G)(a.entries))(a.order));if(c.length===0)return[];const f=T(G=>P=>G.prev.tag==="Just"&&P-G.prev._1<1e-9?G:{prev:w("Just",P),out:[...G.out,P]})({prev:J,out:[]})(Lt(ut.compare)([...Tt(c)(G=>G.incoming),...Tt(c)(G=>G.outgoing)])).out,d=f.length<2?.2*r:.2*T(G=>P=>{if(G.prev.tag==="Nothing")return{prev:w("Just",P),mn:G.mn};if(G.prev.tag==="Just")return{prev:w("Just",P),mn:dt(G.mn)(P-G.prev._1)};g()})({prev:J,mn:1e18})(f).mn,l={segments:c,deps:(()=>{const G=c.length;return Tt(Tt(Dt(0,G-2|0))(P=>Tt(Dt(P+1|0,G-1|0))(V=>[b(P,V)])))(P=>P._1>=0&&P._1<c.length?P._2>=0&&P._2<c.length?o(d,c[P._1],c[P._2]):[]:[])})()},_=st(G=>{if(G.kind==="Critical")return!0;if(G.kind==="Regular")return!1;g()},l.deps),h=(()=>{if(_.length<2)return l;const G=qr((()=>{const R=l.segments;return z(M=>b(M.id,M.mark))((()=>{const M=R.length,S=D=>{let A=D,H=!0,$;for(;H;){const X=A,q=Vt(W=>{const tt=It(W)(X.inWeight);if(tt.tag==="Nothing")return!0;if(tt.tag==="Just")return tt._1===0;g()})(X.remaining);if(q.tag==="Nothing"){H=!1,$=X;continue}if(q.tag==="Just"){const W=q._1;A={...X,inWeight:T(tt=>Z=>vt(it)(ue)(Z.tgt)(-Z.weight)(tt))(X.inWeight)((()=>{const tt=It(W)(X.depsBySrc);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),marks:j(it)(W)(X.nextSource)(X.marks),nextSource:X.nextSource+1|0,outWeight:T(tt=>Z=>vt(it)(ue)(Z.src)(-Z.weight)(tt))(X.outWeight)((()=>{const tt=It(W)(X.depsByTgt);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),remaining:st(tt=>tt!==W,X.remaining)};continue}g()}return $},I=D=>{let A=D,H=!0,$;for(;H;){const X=A,q=Vt(W=>{const tt=It(W)(X.outWeight);if(tt.tag==="Nothing")return!0;if(tt.tag==="Just")return tt._1===0;g()})(X.remaining);if(q.tag==="Nothing"){H=!1,$=X;continue}if(q.tag==="Just"){const W=q._1;A={...X,inWeight:T(tt=>Z=>vt(it)(ue)(Z.tgt)(-Z.weight)(tt))(X.inWeight)((()=>{const tt=It(W)(X.depsBySrc);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),marks:j(it)(W)(X.nextSink)(X.marks),nextSink:X.nextSink-1|0,outWeight:T(tt=>Z=>vt(it)(ue)(Z.src)(-Z.weight)(tt))(X.outWeight)((()=>{const tt=It(W)(X.depsByTgt);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),remaining:st(tt=>tt!==W,X.remaining)};continue}g()}return $};return(D=>{let A=D,H=!0,$;for(;H;){const X=S(I(A));if(X.remaining.length===0){H=!1,$=z(q=>{const W=It(q.id)(X.marks),tt=(()=>{if(W.tag==="Nothing")return q.id;if(W.tag==="Just")return W._1;g()})();return{...q,mark:tt<M?(tt+M|0)+1|0:tt}})(R);continue}A=(()=>{const q=tt=>{const Z=It(tt)(X.outWeight),ct=It(tt)(X.inWeight);return(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()-(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()|0},W=Lt(tt=>Z=>it.compare(q(Z))(q(tt)))(X.remaining);if(0<W.length){const tt=W[0];return{...X,inWeight:T(Z=>ct=>vt(it)(ue)(ct.tgt)(-ct.weight)(Z))(X.inWeight)((()=>{const Z=It(tt)(X.depsBySrc);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;g()})()),marks:j(it)(tt)(X.nextSource)(X.marks),nextSource:X.nextSource+1|0,outWeight:T(Z=>ct=>vt(it)(ue)(ct.src)(-ct.weight)(Z))(X.outWeight)((()=>{const Z=It(tt)(X.depsByTgt);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;g()})()),remaining:st(Z=>Z!==tt,X.remaining)}}return X})()}return $})({remaining:z(D=>D.id)(R),marks:Q,inWeight:T(D=>A=>vt(it)(ue)(A.tgt)(A.weight)(D))(Q)(_),outWeight:T(D=>A=>vt(it)(ue)(A.src)(A.weight)(D))(Q)(_),depsBySrc:T(D=>A=>vt(it)(ee)(A.src)([A])(D))(Q)(_),depsByTgt:T(D=>A=>vt(it)(ee)(A.tgt)([A])(D))(Q)(_),nextSink:M-1|0,nextSource:M+1|0})})())})()),P=st(R=>{const M=It(R.src)(G),S=It(R.tgt)(G);return(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()>(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;g()})()},_);if(P.length===0)return l;const V=T(R=>M=>{if(We(Er)(M.src)(R.decisions)||We(Er)(M.tgt)(R.decisions))return R;const S=It(M.src)(R.segMap),I=It(M.tgt)(R.segMap);if(S.tag==="Just"&&I.tag==="Just"){const D=(S._1.incoming.length+S._1.outgoing.length|0)>2&&(I._1.incoming.length+I._1.outgoing.length|0)<=2,A=D?I._1:S._1;return{decisions:[...R.decisions,A.id],segMap:j(it)(A.id)({...A,splitBy:w("Just",D?S._1.id:I._1.id)})(R.segMap)}}return R})({decisions:[],segMap:qr(z(R=>b(R.id,R))(l.segments))})(P),U=V.segMap,B=T(R=>M=>{const S=dt(T(dt)(1e18)(M.incoming))(T(dt)(1e18)(M.outgoing)),I=lt(T(lt)(-1e18)(M.incoming))(T(lt)(-1e18)(M.outgoing)),D=st(q=>q.a.startPosition<=I&&q.a.endPosition>=S,Ft(q=>W=>({i:q,a:W}))(R.freeAreas));if(D.length===0){const q={...M,incoming:Lt(ut.compare)(M.incoming),outgoing:Lt(ut.compare)([(S+I)/2]),splitPartner:w("Just",R.nextId)},W={id:R.nextId,incoming:Lt(ut.compare)([(S+I)/2]),mark:0,members:M.members,outgoing:Lt(ut.compare)(M.outgoing),slot:0,splitBy:J,splitPartner:w("Just",M.id)};return{segMap:j(it)(W.id)(W)(j(it)(q.id)(q)(R.segMap)),freeAreas:R.freeAreas,nextId:R.nextId+1|0}}const A=0<D.length?w("Just",D[0]):J,H=(()=>{if(A.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(A.tag==="Just"){if(D.length===1)return A._1;const q=z(W=>({c:W,rating:(()=>{const tt=(W.a.startPosition+W.a.endPosition)/2,Z=[tt],ct=[tt],ft=T((()=>{const xt=R.segMap;return St=>Rt=>{const pt=It(Rt.tgt)(xt);if(pt.tag==="Nothing")return St;if(pt.tag==="Just"){const Bt=dt(T(dt)(1e18)(pt._1.incoming))(T(dt)(1e18)(pt._1.outgoing)),Jt=lt(T(lt)(-1e18)(pt._1.incoming))(T(lt)(-1e18)(pt._1.outgoing)),mt=dt(T(dt)(1e18)(M.incoming))(T(dt)(1e18)(Z)),gt=(()=>{const Et=lt(T(lt)(-1e18)(M.incoming))(T(lt)(-1e18)(Z)),Qt=T(Yt=>_e=>_e>Jt?Yt:_e>=Bt?Yt+1|0:Yt)(0)(Z)+T(Yt=>_e=>_e>Et?Yt:_e>=mt?Yt+1|0:Yt)(0)(pt._1.incoming)|0,tn=dt(T(dt)(1e18)(M.incoming))(T(dt)(1e18)(Z)),He=lt(T(lt)(-1e18)(M.incoming))(T(lt)(-1e18)(Z)),en=dt(T(dt)(1e18)(pt._1.incoming))(T(dt)(1e18)(pt._1.outgoing)),$n=lt(T(lt)(-1e18)(pt._1.incoming))(T(lt)(-1e18)(pt._1.outgoing)),ln=T(Yt=>_e=>_e>He?Yt:_e>=tn?Yt+1|0:Yt)(0)(pt._1.outgoing)+T(Yt=>_e=>_e>$n?Yt:_e>=en?Yt+1|0:Yt)(0)(M.incoming)|0;return Qt===ln?Qt>0?{...St,deps:St.deps+2|0,crossings:St.crossings+Qt|0}:St:{...St,deps:St.deps+1|0,crossings:St.crossings+$r(Qt)(ln)|0}})(),K=dt(T(dt)(1e18)(pt._1.incoming))(T(dt)(1e18)(pt._1.outgoing)),nt=lt(T(lt)(-1e18)(pt._1.incoming))(T(lt)(-1e18)(pt._1.outgoing)),ht=dt(T(dt)(1e18)(ct))(T(dt)(1e18)(M.outgoing)),_t=lt(T(lt)(-1e18)(ct))(T(lt)(-1e18)(M.outgoing)),Nt=T(Et=>Qt=>Qt>nt?Et:Qt>=K?Et+1|0:Et)(0)(M.outgoing)+T(Et=>Qt=>Qt>_t?Et:Qt>=ht?Et+1|0:Et)(0)(pt._1.incoming)|0,wt=dt(T(dt)(1e18)(ct))(T(dt)(1e18)(M.outgoing)),Kt=lt(T(lt)(-1e18)(ct))(T(lt)(-1e18)(M.outgoing)),Se=dt(T(dt)(1e18)(pt._1.incoming))(T(dt)(1e18)(pt._1.outgoing)),an=lt(T(lt)(-1e18)(pt._1.incoming))(T(lt)(-1e18)(pt._1.outgoing)),Oe=T(Et=>Qt=>Qt>Kt?Et:Qt>=wt?Et+1|0:Et)(0)(pt._1.outgoing)+T(Et=>Qt=>Qt>an?Et:Qt>=Se?Et+1|0:Et)(0)(ct)|0;return Nt===Oe?Nt>0?{...gt,deps:gt.deps+2|0,crossings:gt.crossings+Nt|0}:gt:{...gt,deps:gt.deps+1|0,crossings:gt.crossings+$r(Nt)(Oe)|0}}g()}})())(T((()=>{const xt=R.segMap;return St=>Rt=>{const pt=It(Rt.src)(xt);if(pt.tag==="Nothing")return St;if(pt.tag==="Just"){const Bt=dt(T(dt)(1e18)(pt._1.incoming))(T(dt)(1e18)(pt._1.outgoing)),Jt=lt(T(lt)(-1e18)(pt._1.incoming))(T(lt)(-1e18)(pt._1.outgoing)),mt=dt(T(dt)(1e18)(M.incoming))(T(dt)(1e18)(Z)),gt=(()=>{const Et=lt(T(lt)(-1e18)(M.incoming))(T(lt)(-1e18)(Z)),Qt=T(Yt=>_e=>_e>Jt?Yt:_e>=Bt?Yt+1|0:Yt)(0)(Z)+T(Yt=>_e=>_e>Et?Yt:_e>=mt?Yt+1|0:Yt)(0)(pt._1.incoming)|0,tn=dt(T(dt)(1e18)(M.incoming))(T(dt)(1e18)(Z)),He=lt(T(lt)(-1e18)(M.incoming))(T(lt)(-1e18)(Z)),en=dt(T(dt)(1e18)(pt._1.incoming))(T(dt)(1e18)(pt._1.outgoing)),$n=lt(T(lt)(-1e18)(pt._1.incoming))(T(lt)(-1e18)(pt._1.outgoing)),ln=T(Yt=>_e=>_e>He?Yt:_e>=tn?Yt+1|0:Yt)(0)(pt._1.outgoing)+T(Yt=>_e=>_e>$n?Yt:_e>=en?Yt+1|0:Yt)(0)(M.incoming)|0;return Qt===ln?Qt>0?{...St,deps:St.deps+2|0,crossings:St.crossings+Qt|0}:St:{...St,deps:St.deps+1|0,crossings:St.crossings+$r(Qt)(ln)|0}})(),K=dt(T(dt)(1e18)(pt._1.incoming))(T(dt)(1e18)(pt._1.outgoing)),nt=lt(T(lt)(-1e18)(pt._1.incoming))(T(lt)(-1e18)(pt._1.outgoing)),ht=dt(T(dt)(1e18)(ct))(T(dt)(1e18)(M.outgoing)),_t=lt(T(lt)(-1e18)(ct))(T(lt)(-1e18)(M.outgoing)),Nt=T(Et=>Qt=>Qt>nt?Et:Qt>=K?Et+1|0:Et)(0)(M.outgoing)+T(Et=>Qt=>Qt>_t?Et:Qt>=ht?Et+1|0:Et)(0)(pt._1.incoming)|0,wt=dt(T(dt)(1e18)(ct))(T(dt)(1e18)(M.outgoing)),Kt=lt(T(lt)(-1e18)(ct))(T(lt)(-1e18)(M.outgoing)),Se=dt(T(dt)(1e18)(pt._1.incoming))(T(dt)(1e18)(pt._1.outgoing)),an=lt(T(lt)(-1e18)(pt._1.incoming))(T(lt)(-1e18)(pt._1.outgoing)),Oe=T(Et=>Qt=>Qt>Kt?Et:Qt>=wt?Et+1|0:Et)(0)(pt._1.outgoing)+T(Et=>Qt=>Qt>an?Et:Qt>=Se?Et+1|0:Et)(0)(ct)|0;return Nt===Oe?Nt>0?{...gt,deps:gt.deps+2|0,crossings:gt.crossings+Nt|0}:gt:{...gt,deps:gt.deps+1|0,crossings:gt.crossings+$r(Nt)(Oe)|0}}g()}})())({crossings:0,deps:0})(st(xt=>xt.tgt===M.id,l.deps)))(st(xt=>xt.src===M.id,l.deps)),at=(()=>{if(M.splitBy.tag==="Just")return It(M.splitBy._1)(R.segMap);if(M.splitBy.tag==="Nothing")return J;g()})();if(at.tag==="Just")return{...ft,deps:ft.deps+2|0,crossings:(()=>{const xt=dt(T(dt)(1e18)(at._1.incoming))(T(dt)(1e18)(at._1.outgoing)),St=dt(T(dt)(1e18)(ct))(T(dt)(1e18)(M.outgoing)),Rt=lt(T(lt)(-1e18)(at._1.incoming))(T(lt)(-1e18)(at._1.outgoing)),pt=lt(T(lt)(-1e18)(ct))(T(lt)(-1e18)(M.outgoing)),Bt=dt(T(dt)(1e18)(M.incoming))(T(dt)(1e18)(Z));return ft.crossings+(()=>{const Jt=dt(T(dt)(1e18)(at._1.incoming))(T(dt)(1e18)(at._1.outgoing)),mt=lt(T(lt)(-1e18)(M.incoming))(T(lt)(-1e18)(Z)),gt=lt(T(lt)(-1e18)(at._1.incoming))(T(lt)(-1e18)(at._1.outgoing));return((T(K=>nt=>nt>Rt?K:nt>=xt?K+1|0:K)(0)(Z)+T(K=>nt=>nt>mt?K:nt>=Bt?K+1|0:K)(0)(at._1.incoming)|0)+T(K=>nt=>nt>pt?K:nt>=St?K+1|0:K)(0)(at._1.outgoing)|0)+T(K=>nt=>nt>gt?K:nt>=Jt?K+1|0:K)(0)(ct)|0})()|0})()};if(at.tag==="Nothing")return ft;g()})()}))(D);return T(W=>tt=>tt.rating.crossings<W.rating.crossings||!(tt.rating.crossings>W.rating.crossings)&&(tt.rating.deps<W.rating.deps||!(tt.rating.deps>W.rating.deps)&&tt.c.a.size>W.c.a.size)?tt:W)(0<q.length?q[0]:{c:A._1,rating:{crossings:1e6,deps:1e6}})(q).c}g()})(),$={...M,incoming:Lt(ut.compare)(M.incoming),outgoing:Lt(ut.compare)([(H.a.startPosition+H.a.endPosition)/2]),splitPartner:w("Just",R.nextId)},X={id:R.nextId,incoming:Lt(ut.compare)([(H.a.startPosition+H.a.endPosition)/2]),mark:0,members:M.members,outgoing:Lt(ut.compare)(M.outgoing),slot:0,splitBy:J,splitPartner:w("Just",M.id)};return{segMap:j(it)(X.id)(X)(j(it)($.id)($)(R.segMap)),freeAreas:(()=>{if(H.i>=0&&H.i<R.freeAreas.length){const q=Ua(Xt,J,H.i,R.freeAreas),W=(()=>{if(q.tag==="Nothing")return R.freeAreas;if(q.tag==="Just")return q._1;g()})();if(R.freeAreas[H.i].size/2<d)return W;const tt=(R.freeAreas[H.i].startPosition+R.freeAreas[H.i].endPosition)/2,Z=tt-d,ct=tt+d;return[...H.i<1?[]:bt(0,H.i,W),...R.freeAreas[H.i].startPosition<=Z?[{startPosition:R.freeAreas[H.i].startPosition,endPosition:Z,size:Z-R.freeAreas[H.i].startPosition}]:[],...ct<=R.freeAreas[H.i].endPosition?[{startPosition:ct,endPosition:R.freeAreas[H.i].endPosition,size:R.freeAreas[H.i].endPosition-ct}]:[],...H.i<1?W:bt(H.i,W.length,W)]}return R.freeAreas})(),nextId:R.nextId+1|0}})({segMap:U,freeAreas:(()=>{const R=Lt(ut.compare)([...Tt(l.segments)(M=>M.incoming),...Tt(l.segments)(M=>M.outgoing)]);return yt(rx)(we(M=>S=>S-M>=2*d?w("Just",{startPosition:M+d,endPosition:S-d,size:S-M-2*d}):J,R,bt(1,R.length,R)))})(),nextId:l.segments.length})(Lt(R=>M=>ut.compare(lt(T(lt)(-1e18)(R.incoming))(T(lt)(-1e18)(R.outgoing))-dt(T(dt)(1e18)(R.incoming))(T(dt)(1e18)(R.outgoing)))(lt(T(lt)(-1e18)(M.incoming))(T(lt)(-1e18)(M.outgoing))-dt(T(dt)(1e18)(M.incoming))(T(dt)(1e18)(M.outgoing))))(yt(R=>It(R)(U))(V.decisions)));return{segments:(()=>{const R=(M,S)=>{if(M.tag==="Leaf")return S;if(M.tag==="Node")return R(M._5,qt("Cons",M._4,R(M._6,S)));g()};return Ct($t.foldr,R(B.segMap,Ht))})(),deps:(()=>{const R=B.segMap,M=(D,A)=>{if(D.tag==="Leaf")return A;if(D.tag==="Node")return M(D._5,qt("Cons",D._4,M(D._6,A)));g()},S=Ct($t.foldr,M(R,Ht)),I=S.length;return[...Tt(Tt(Dt(0,I-2|0))(D=>Tt(Dt(D+1|0,I-1|0))(A=>[b(D,A)])))(D=>D._1>=0&&D._1<S.length?D._2>=0&&D._2<S.length?S[D._1].splitPartner.tag!=="Nothing"&&S[D._1].splitPartner.tag==="Just"&&S[D._1].splitPartner._1===S[D._2].id||S[D._2].splitPartner.tag!=="Nothing"&&S[D._2].splitPartner.tag==="Just"&&S[D._2].splitPartner._1===S[D._1].id?[]:o(d,S[D._1],S[D._2]):[]:[]),...Tt(S)(D=>D.splitBy.tag==="Just"&&D.splitPartner.tag==="Just"&&(()=>{const A=It(D.splitPartner._1)(R);if(A.tag==="Nothing")return!1;if(A.tag==="Just")return!0;g()})()&&(()=>{const A=It(D.splitBy._1)(R);if(A.tag==="Nothing")return!1;if(A.tag==="Just")return!0;g()})()?[{src:D.id,tgt:D.splitBy._1,weight:1,kind:qo},{src:D.splitBy._1,tgt:D.splitPartner._1,weight:1,kind:qo}]:[])]})()}})(),p=h.segments,m=p.length,x=G=>{let P=G,V=!0,U;for(;V;){const B=P,R=Vt(M=>{const S=It(M)(B.inWeight);if(S.tag==="Nothing")return!0;if(S.tag==="Just")return S._1===0;g()})(B.remaining);if(R.tag==="Nothing"){V=!1,U=B;continue}if(R.tag==="Just"){const M=R._1;P={...B,inWeight:T(S=>I=>vt(it)(ue)(I.tgt)(-I.weight)(S))(B.inWeight)((()=>{const S=It(M)(B.depsBySrc);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()),marks:j(it)(M)(B.nextSource)(B.marks),nextSource:B.nextSource+1|0,outWeight:T(S=>I=>vt(it)(ue)(I.src)(-I.weight)(S))(B.outWeight)((()=>{const S=It(M)(B.depsByTgt);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()),remaining:st(S=>S!==M,B.remaining)};continue}g()}return U},y=G=>{let P=G,V=!0,U;for(;V;){const B=P,R=Vt(M=>{const S=It(M)(B.outWeight);if(S.tag==="Nothing")return!0;if(S.tag==="Just")return S._1===0;g()})(B.remaining);if(R.tag==="Nothing"){V=!1,U=B;continue}if(R.tag==="Just"){const M=R._1;P={...B,inWeight:T(S=>I=>vt(it)(ue)(I.tgt)(-I.weight)(S))(B.inWeight)((()=>{const S=It(M)(B.depsBySrc);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()),marks:j(it)(M)(B.nextSink)(B.marks),nextSink:B.nextSink-1|0,outWeight:T(S=>I=>vt(it)(ue)(I.src)(-I.weight)(S))(B.outWeight)((()=>{const S=It(M)(B.depsByTgt);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()),remaining:st(S=>S!==M,B.remaining)};continue}g()}return U},N=(G=>{let P=G,V=!0,U;for(;V;){const B=x(y(P));if(B.remaining.length===0){V=!1,U=z(R=>{const M=It(R.id)(B.marks),S=(()=>{if(M.tag==="Nothing")return R.id;if(M.tag==="Just")return M._1;g()})();return{...R,mark:S<m?(S+m|0)+1|0:S}})(p);continue}P=(()=>{const R=S=>{const I=It(S)(B.outWeight),D=It(S)(B.inWeight);return(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;g()})()-(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;g()})()|0},M=Lt(S=>I=>it.compare(R(I))(R(S)))(B.remaining);if(0<M.length){const S=M[0];return{...B,inWeight:T(I=>D=>vt(it)(ue)(D.tgt)(-D.weight)(I))(B.inWeight)((()=>{const I=It(S)(B.depsBySrc);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})()),marks:j(it)(S)(B.nextSource)(B.marks),nextSource:B.nextSource+1|0,outWeight:T(I=>D=>vt(it)(ue)(D.src)(-D.weight)(I))(B.outWeight)((()=>{const I=It(S)(B.depsByTgt);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})()),remaining:st(I=>I!==S,B.remaining)}}return B})()}return U})({remaining:z(G=>G.id)(p),marks:Q,inWeight:T(G=>P=>vt(it)(ue)(P.tgt)(P.weight)(G))(Q)(h.deps),outWeight:T(G=>P=>vt(it)(ue)(P.src)(P.weight)(G))(Q)(h.deps),depsBySrc:T(G=>P=>vt(it)(ee)(P.src)([P])(G))(Q)(h.deps),depsByTgt:T(G=>P=>vt(it)(ee)(P.tgt)([P])(G))(Q)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),v=(()=>{const G=(()=>{const U=qr(z(B=>b(B.id,B.mark))(N));return{segments:N,deps:yt(B=>(()=>{if(B.kind==="Critical")return!0;if(B.kind==="Regular")return!1;g()})()?w("Just",B):(()=>{const R=It(B.src)(U),M=It(B.tgt)(U);return(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})()>(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()})()?B.weight===0?J:w("Just",{src:B.tgt,tgt:B.src,weight:B.weight,kind:B.kind}):w("Just",B))(h.deps)}})(),P=T(U=>B=>vt(it)(ue)(B.tgt)(1)(U))(Q)(G.deps),V=(U=>{let B=U,R=!0,M;for(;R;){const S=B,I=At(D=>J,D=>A=>w("Just",{head:D,tail:A}),S.queue);if(I.tag==="Nothing"){R=!1,M=S;continue}if(I.tag==="Just"){B=T((()=>{const D=It(I._1.head)(S.slots),A=(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;g()})();return H=>$=>{const X=It($)(H.inDegree),q=(()=>{if(X.tag==="Nothing")return-1;if(X.tag==="Just")return X._1-1|0;g()})();return{...H,slots:j(it)($)(zg((()=>{const W=It($)(H.slots);if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})())(A+1|0))(H.slots),inDegree:j(it)($)(q)(H.inDegree),queue:q===0?[...H.queue,$]:H.queue}}})())({...S,queue:I._1.tail})((()=>{const D=It(I._1.head)(S.adj);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})());continue}g()}return M})({slots:qr(z(U=>b(U.id,0))(G.segments)),inDegree:P,adj:T(U=>B=>vt(it)(ee)(B.src)([B.tgt])(U))(Q)(G.deps),queue:z(U=>U.id)(st(U=>{const B=It(U.id)(P);if(B.tag==="Nothing")return!0;if(B.tag==="Just")return B._1===0;g()},G.segments))});return Lt(U=>B=>it.compare(U.slot)(B.slot))(z(U=>({...U,slot:(()=>{const B=It(U.id)(V.slots);if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})()}))(G.segments))})(),L=1+T(G=>P=>zg(G)(P.slot))(0)(v)|0,k=Tt(v)(G=>G.members),E=st(G=>We(_n)(G.edge.id)(k),t),O=T(lt)(-1e18)(z(G=>G.fromPos._2)(E)),Y=T(dt)(1e18)(z(G=>G.toPos._2)(E));if(O>Y){const G=qr(z(P=>b(P.id,P))(v));return Re(z(P=>z(V=>b(V,{slot:P.slot,slotCount:L,gapTop:Y,gapBottom:O,partner:(()=>{if(P.splitPartner.tag==="Just"){const U=It(P.splitPartner._1)(G);if(U.tag==="Just")return w("Just",{slot:U._1.slot,splitX:0<U._1.incoming.length?U._1.incoming[0]:0});if(U.tag==="Nothing")return J;g()}if(P.splitPartner.tag==="Nothing")return J;g()})()}))(P.members))(st(P=>{if(P.splitPartner.tag==="Just"){const V=It(P.splitPartner._1)(G);return!(V.tag==="Just"&&(()=>{if(V._1.splitBy.tag==="Nothing")return!1;if(V._1.splitBy.tag==="Just")return!0;g()})())}if(P.splitPartner.tag==="Nothing")return!0;g()},v)))}const et=qr(z(G=>b(G.id,G))(v));return Re(z(G=>z(P=>b(P,{slot:G.slot,slotCount:L,gapTop:O,gapBottom:Y,partner:(()=>{if(G.splitPartner.tag==="Just"){const V=It(G.splitPartner._1)(et);if(V.tag==="Just")return w("Just",{slot:V._1.slot,splitX:0<V._1.incoming.length?V._1.incoming[0]:0});if(V.tag==="Nothing")return J;g()}if(G.splitPartner.tag==="Nothing")return J;g()})()}))(G.members))(st(G=>{if(G.splitPartner.tag==="Just"){const P=It(G.splitPartner._1)(et);return!(P.tag==="Just"&&(()=>{if(P._1.splitBy.tag==="Nothing")return!1;if(P._1.splitBy.tag==="Just")return!0;g()})())}if(G.splitPartner.tag==="Nothing")return!0;g()},v)))})()))(Q)(nx(T(u=>s=>{const a=Hr(s.edge.from.node)(n);if(a.tag==="Just"){const c=Hr(s.edge.to.node)(n);return c.tag==="Just"&&a._1.layer!==c._1.layer?vt(it)(ee)($r(a._1.layer)(c._1.layer))([s])(u):u}return u})(Q)((()=>{const u=s=>b((()=>{const a=Hr(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=Hr(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return Lt(s=>a=>ex(u(s))(u(a)))(t)})())))},ox=t=>e=>{const n=Hg(t)(e),r=T(i=>o=>j(C)(o.node)(o)(i))(Q)(e);return T(i=>o=>{const u=Hr(o.edge.from.node)(r);if(u.tag==="Just"){const s=Hr(o.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=ix(o.edge.id)(n);if(a.tag==="Just")return j(it)($r(u._1.layer)(s._1.layer))(a._1.slotCount)(i)}return i}return i})(Q)(t)},$g=Wt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),ce=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ge=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Di=t=>e=>n=>r=>$g(i=>n>=i.x&&n<i.x+i.w&&e>i.y&&t<i.y+i.h)(r),Ho=t=>e=>n=>r=>Di(ce(e)(n))(ge(e)(n))(r)(t),$o=rt(4),ux=ja(t=>{if(t.direction==="H"){const e=ce(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:ge(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=ce(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:ge(t.start._2)(t.end._2)-e}]}g()}),Qi=Ka(t=>{const e=t.start._1-t.end._1;return!((e<0?-e<1e-6:e<1e-6)&&(()=>{const n=t.start._2-t.end._2;return n<0?-n<1e-6:n<1e-6})())}),sx=t=>e=>n=>{const r=At(i=>J,i=>o=>w("Just",{head:i,tail:o}),e);if(r.tag==="Nothing")return[{start:t.start,end:n.end,direction:t.direction}];if(r.tag==="Just"){const i=(r._1.head.direction==="H"?t.direction==="H":r._1.head.direction==="V"&&t.direction==="V")?[{start:t.start,end:r._1.head.end,direction:t.direction}]:[t,r._1.head],o=Cr(r._1.tail);if(o.tag==="Nothing"){const u=i.length-1|0;return u>=0&&u<i.length&&(i[u].direction==="H"?n.direction==="H":i[u].direction==="V"&&n.direction==="V")?[...(()=>{const s=i.length-1|0;return s<1?[]:bt(0,s,i)})(),{start:i[u].start,end:n.end,direction:n.direction}]:[...i,n]}if(o.tag==="Just")return(o._1.last.direction==="H"?n.direction==="H":o._1.last.direction==="V"&&n.direction==="V")?[...i,...o._1.init,{start:o._1.last.start,end:n.end,direction:n.direction}]:[...i,...r._1.tail,n]}g()},Fi=t=>{const e=r=>i=>{const o=At(u=>J,u=>s=>w("Just",{head:u,tail:s}),i);if(o.tag==="Nothing")return[r];if(o.tag==="Just")return(r.direction==="H"?o._1.head.direction==="H":r.direction==="V"&&o._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==o._1.head.end._1-o._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==o._1.head.end._2-o._1.head.start._2>=0;g()})()?e({start:r.start,end:o._1.head.end,direction:r.direction})(o._1.tail):[r,...e(o._1.head)(o._1.tail)];g()},n=At(r=>J,r=>i=>w("Just",{head:r,tail:i}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);g()},Ai=t=>e=>n=>r=>$g(i=>n>=i.y&&n<i.y+i.h&&e>i.x&&t<i.x+i.w)(r),Mi=t=>e=>n=>r=>Ai(ce(e)(n))(ge(e)(n))(r)(t),ax=t=>e=>n=>r=>{const i=n+2|0,o=i<1?e:bt(i,e.length,e),u=n<1?[]:bt(0,n,e),s=(n+1|0)===(r-1|0),a=n===0,c=n>=0&&n<e.length?w("Just",e[n]):J;if(c.tag==="Just"){const f=n+1|0,d=f>=0&&f<e.length?w("Just",e[f]):J;if(d.tag==="Just"){const l=c._1.start._1===d._1.end._1&&(!a||c._1.direction==="V")&&(!s||d._1.direction==="V")&&!Ho(t)(ce(c._1.start._2)(d._1.end._2))(ge(c._1.start._2)(d._1.end._2))(c._1.start._1)?w("Just",[...u,{start:c._1.start,end:d._1.end,direction:re},...o]):J,_=c._1.start._2===d._1.end._2&&(!a||c._1.direction==="H")&&(!s||d._1.direction==="H")&&!Mi(t)(ce(c._1.start._1)(d._1.end._1))(ge(c._1.start._1)(d._1.end._1))(c._1.start._2)?w("Just",[...u,{start:c._1.start,end:d._1.end,direction:ne},...o]):J;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return J;g()}if(c.tag==="Nothing")return J;g()},cx=t=>e=>{const n=e.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+1|0)>=n){o=!1,u=e;continue}const a=ax(t)(e)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}g()}return u})(0)},gx=t=>e=>n=>r=>{const i=(l,_,h)=>!Ho(t)(ce(_)(h))(ge(_)(h))(l),o=n+3|0,u=o<1?e:bt(o,e.length,e),s=n<1?[]:bt(0,n,e),a=(n+2|0)===(r-1|0),c=n===0,f=(l,_,h)=>!Mi(t)(ce(_)(h))(ge(_)(h))(l),d=n>=0&&n<e.length?w("Just",e[n]):J;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<e.length?w("Just",e[l]):J;if(_.tag==="Just"){const h=d._1.start._1===_._1.end._1&&(!c||d._1.direction==="V")&&(!a||_._1.direction==="V")&&i(d._1.start._1,d._1.start._2,_._1.end._2)?w("Just",[...s,{start:d._1.start,end:_._1.end,direction:re},...u]):d._1.start._2===_._1.end._2&&(!c||d._1.direction==="H")&&(!a||_._1.direction==="H")&&f(d._1.start._2,d._1.start._1,_._1.end._1)?w("Just",[...s,{start:d._1.start,end:_._1.end,direction:ne},...u]):J,p=(!c||d._1.direction==="V")&&(!a||_._1.direction==="H")&&i(d._1.start._1,d._1.start._2,_._1.end._2)&&f(_._1.end._2,d._1.start._1,_._1.end._1)?w("Just",[...s,{start:d._1.start,end:b(d._1.start._1,_._1.end._2),direction:re},{start:b(d._1.start._1,_._1.end._2),end:_._1.end,direction:ne},...u]):J,m=(!c||d._1.direction==="H")&&(!a||_._1.direction==="V")&&f(d._1.start._2,d._1.start._1,_._1.end._1)&&i(_._1.end._1,d._1.start._2,_._1.end._2)?w("Just",[...s,{start:d._1.start,end:b(_._1.end._1,d._1.start._2),direction:ne},{start:b(_._1.end._1,d._1.start._2),end:_._1.end,direction:re},...u]):J,x=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?x:h}if(_.tag==="Nothing")return J;g()}if(d.tag==="Nothing")return J;g()},fx=t=>e=>{const n=e.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+2|0)>=n){o=!1,u=e;continue}const a=gx(t)(e)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}g()}return u})(0)},_x=t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r,s=Fi(Qi(cx(t)(fx(t)(u))));if(s.length<u.length){r=s;continue}i=!1,o=s}return o};return n=>e(Fi(Qi(n)))},dx=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=Lt(c=>f=>ut.compare(c.x)(f.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=Lt(a=>c=>ut.compare(c.x)(a.x))(z(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},lx=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=Lt(c=>f=>ut.compare(c.y)(f.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=Lt(a=>c=>ut.compare(c.y)(a.y))(z(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},hx=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=Lt(c=>f=>ut.compare(f.x)(c.x))(z(c=>({...c,x:c.x+c.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=Lt(a=>c=>ut.compare(a.x)(c.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},px=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=Lt(c=>f=>ut.compare(f.y)(c.y))(z(c=>({...c,y:c.y+c.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=Lt(a=>c=>ut.compare(a.y)(c.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},Xg=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,c=i,f=o;if(f>100){u=!1,s=c;continue}if(!a(c+f)){u=!1,s=c+f;continue}if(!a(c-f)){u=!1,s=c-f;continue}r=a,i=c,o=f+1}return s},Yg=t=>e=>n=>r=>i=>{const o=ce(e)(n),u=ge(e)(n);if(!Di(o)(u)(r)(t))return r;if(!Di(o)(u)(i)(t))return i;const s=(r+i)/2;return Di(o)(u)(s)(t)?Xg(a=>Di(o)(u)(a)(t))(s)(1):s},mx=t=>e=>n=>r=>i=>{const o=ce(e)(n),u=ge(e)(n);if(!Ai(o)(u)(r)(t))return r;if(!Ai(o)(u)(i)(t))return i;const s=(r+i)/2;return Ai(o)(u)(s)(t)?Xg(a=>Ai(o)(u)(a)(t))(s)(1):s},xx=t=>e=>n=>r=>{const i=ce(e)(n),o=ge(e)(n),u=st(c=>r>=c.x&&r<c.x+c.w&&c.y+c.h>i&&c.y<o,t),s=T(c=>f=>ge(c)(f.x+f.w+4))(r+4)(u),a=T(c=>f=>ce(c)(f.x-4))(r-4)(u);return(()=>{const c=s-r,f=a-r;return(c<0?-c:c)<=(f<0?-f:f)})()?s:a},yx=t=>e=>n=>r=>{const i=ce(e)(n),o=ge(e)(n),u=st(c=>r>=c.y&&r<c.y+c.h&&c.x+c.w>i&&c.x<o,t),s=T(c=>f=>ge(c)(f.y+f.h+4))(r+4)(u),a=T(c=>f=>ce(c)(f.y-4))(r-4)(u);return(()=>{const c=s-r,f=a-r;return(c<0?-c:c)<=(f<0?-f:f)})()?s:a},Nx=t=>e=>n=>r=>i=>o=>u=>{const s=(()=>{if(r==="South")return b(i._1,i._2+4);if(r==="North")return b(i._1,i._2-4);if(r==="East")return b(i._1+4,i._2);if(r==="West")return b(i._1-4,i._2);g()})(),a=(()=>{if(o==="South")return b(u._1,u._2+4);if(o==="North")return b(u._1,u._2-4);if(o==="East")return b(u._1+4,u._2);if(o==="West")return b(u._1-4,u._2);g()})(),c=(L,k,E)=>!Ho(e)(ce(k)(E))(ge(k)(E))(L),f=(L,k,E)=>!Ho(n)(ce(k)(E))(ge(k)(E))(L),d=(L,k,E,O)=>t.tag==="Just"&&!Mi(n)(ce(L)(k))(ge(L)(k))(t._1)?t._1:mx(e)(L)(k)(E)(O),l=(L,k,E,O)=>{if(L===E){const et=xx(e)(k)(O)(L),G=lx(e)(L)(k)(O),P=px(e)(L)(k)(O);return[{start:b(L,k),end:b(L,G),direction:re},{start:b(L,G),end:b(et,G),direction:ne},{start:b(et,G),end:b(et,P),direction:re},{start:b(et,P),end:b(E,P),direction:ne},{start:b(E,P),end:b(E,O),direction:re}]}const Y=d(L,E,k,O);return[{start:b(L,k),end:b(L,Y),direction:re},{start:b(L,Y),end:b(E,Y),direction:ne},{start:b(E,Y),end:b(E,O),direction:re}]},_=(L,k,E,O)=>{if(k===O){const et=yx(e)(L)(E)(k),G=dx(e)(k)(L)(E),P=hx(e)(k)(L)(E);return[{start:b(L,k),end:b(G,k),direction:ne},{start:b(G,k),end:b(G,et),direction:re},{start:b(G,et),end:b(P,et),direction:ne},{start:b(P,et),end:b(P,O),direction:re},{start:b(P,O),end:b(E,O),direction:ne}]}const Y=Yg(e)(k)(O)(L)(E);return[{start:b(L,k),end:b(Y,k),direction:ne},{start:b(Y,k),end:b(Y,O),direction:re},{start:b(Y,O),end:b(E,O),direction:ne}]},h=(L,k,E)=>!Mi(e)(ce(k)(E))(ge(k)(E))(L),p=(L,k,E)=>!Mi(n)(ce(k)(E))(ge(k)(E))(L),m=(L,k,E,O)=>{if(p(k,L,E)&&f(E,k,O))return[{start:b(L,k),end:b(E,k),direction:ne},{start:b(E,k),end:b(E,O),direction:re}];const Y=Yg(e)(k)(O)(L)(E);return[{start:b(L,k),end:b(Y,k),direction:ne},{start:b(Y,k),end:b(Y,O),direction:re},{start:b(Y,O),end:b(E,O),direction:ne}]},x=(L,k,E,O)=>{if(f(L,k,O)&&p(O,L,E))return[{start:b(L,k),end:b(L,O),direction:re},{start:b(L,O),end:b(E,O),direction:ne}];const Y=d(L,E,k,O);return[{start:b(L,k),end:b(L,Y),direction:re},{start:b(L,Y),end:b(E,Y),direction:ne},{start:b(E,Y),end:b(E,O),direction:re}]},y=(()=>{if(r==="South")return o==="North"?s._1===a._1&&c(s._1,s._2,a._2)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:re}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?x(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="North")return o==="South"?s._1===a._1&&c(s._1,s._2,a._2)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:re}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?x(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="East")return o==="West"?s._2===a._2&&h(s._2,s._1,a._1)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:ne}]:_(s._1,s._2,a._1,a._2):o==="North"||o==="South"?m(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="West"){if(o==="East")return s._2===a._2&&h(s._2,s._1,a._1)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:ne}]:_(s._1,s._2,a._1,a._2);if(o==="North"||o==="South")return m(s._1,s._2,a._1,a._2)}return l(s._1,s._2,a._1,a._2)})(),N=(()=>{if(r==="South"||r==="North")return re;if(r==="East"||r==="West")return ne;g()})(),v={start:b(a._1,a._2),end:b(u._1,u._2),direction:(()=>{if(o==="South"||o==="North")return re;if(o==="East"||o==="West")return ne;g()})()};return s._1===a._1&&s._2===a._2?[{start:b(i._1,i._2),end:b(u._1,u._2),direction:N}]:sx({start:b(i._1,i._2),end:b(s._1,s._2),direction:N})(y)(v)},Jx=z(t=>({x:t.position._1*$o-2,y:t.position._2*$o-2,w:t.size._1*$o+4,h:t.size._2*$o+4})),Rs=jt(C)(Wt),An=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Bs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Tx=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t._1)(o._3._1);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(t._2==="North"){if(o._3._2==="North"){r=!1,i=w("Just",o._4);continue}n=o._5;continue}if(o._3._2==="North"){n=o._6;continue}if(t._2==="South"){if(o._3._2==="South"){r=!1,i=w("Just",o._4);continue}n=o._5;continue}if(o._3._2==="South"){n=o._6;continue}if(t._2==="East"){if(o._3._2==="East"){r=!1,i=w("Just",o._4);continue}n=o._5;continue}if(o._3._2==="East"){n=o._6;continue}if(t._2==="West"&&o._3._2==="West"){r=!1,i=w("Just",o._4);continue}}g()}return i},Vg=t=>e=>{const n=e.position._1+e.size._1,r=e.position._2*2+e.size._2,i=e.position._1*2+e.size._1,o=e.position._2+e.size._2;if(t==="South")return b(i,o*2);if(t==="North")return b(i,e.position._2*2);if(t==="East")return b(n*2,r);if(t==="West")return b(e.position._1*2,r);g()},Ws=t=>e=>{const n=rt(4);if(t==="South")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="North")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="East")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};if(t==="West")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};g()},Ug=t=>e=>T(n=>r=>vt(t)(ee)(e(r))([r])(n))(Q),Zg=t=>e=>n=>r=>{const i=(t==="South"||t==="North")&&(e==="East"||e==="West")&&(()=>{if(t==="South")return r._2>n._2;if(t==="North")return r._2<n._2;if(t==="East")return r._2>n._2;if(t==="West")return r._2<n._2;g()})()&&(()=>{if(e==="East")return n._1>r._1;if(e==="West"||e==="North")return n._1<r._1;if(e==="South")return n._1>r._1;g()})(),o=(t==="East"||t==="West")&&(e==="North"||e==="South")&&(()=>{if(t==="South")return r._1>n._1;if(t==="North")return r._1<n._1;if(t==="East")return r._1>n._1;if(t==="West")return r._1<n._1;g()})()&&(()=>{if(e==="East")return n._2>r._2;if(e==="West"||e==="North")return n._2<r._2;if(e==="South")return n._2>r._2;g()})();return(t==="South"?e==="North"&&n._1===r._1&&r._2>n._2:t==="North"?e==="South"&&n._1===r._1&&r._2<n._2:t==="East"?e==="West"&&n._2===r._2&&r._1>n._1:t==="West"&&e==="East"&&n._2===r._2&&r._1<n._1)?0:i||o?1:2},Kg=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,i=e.length;return i===0?Q:Rs(i===1?z(o=>b(o,r))(e):Ft(o=>u=>b(u,t.lo+rt(o+1|0)*n/rt(i+1|0)))(e))},jg=t=>e=>n=>r=>i=>{const o=Ug(C)(_=>_.to.node)(t),u=Ug(C)(_=>_.from.node)(t),s=T(_=>h=>j(C)(h.node)(h)(_))(Q)(e),a=(_,h,p)=>{const m=An(_)(s);if(m.tag==="Nothing")return b(0,0);if(m.tag==="Just"){const x=An(_)(n);if(x.tag==="Nothing"){const y=rt(4);if(p==="South")return b(m._1.position._1*y+m._1.size._1*y/2,(m._1.position._2+m._1.size._2)*y);if(p==="North")return b(m._1.position._1*y+m._1.size._1*y/2,m._1.position._2*y);if(p==="East")return b((m._1.position._1+m._1.size._1)*y,m._1.position._2*y+m._1.size._2*y/2);if(p==="West")return b(m._1.position._1*y,m._1.position._2*y+m._1.size._2*y/2);g()}if(x.tag==="Just"){const y=Vt(N=>N.id===h)(x._1);if(y.tag==="Nothing"){const N=rt(4);if(p==="South")return b(m._1.position._1*N+m._1.size._1*N/2,(m._1.position._2+m._1.size._2)*N);if(p==="North")return b(m._1.position._1*N+m._1.size._1*N/2,m._1.position._2*N);if(p==="East")return b((m._1.position._1+m._1.size._1)*N,m._1.position._2*N+m._1.size._2*N/2);if(p==="West")return b(m._1.position._1*N,m._1.position._2*N+m._1.size._2*N/2);g()}if(y.tag==="Just"){const N=rt(4);if(y._1.side==="North")return b(m._1.position._1*N+rt(y._1.offset)*N,m._1.position._2*N);if(y._1.side==="South")return b(m._1.position._1*N+rt(y._1.offset)*N,(m._1.position._2+m._1.size._2)*N);if(y._1.side==="East")return b((m._1.position._1+m._1.size._1)*N,m._1.position._2*N+rt(y._1.offset)*N);if(y._1.side==="West")return b(m._1.position._1*N,m._1.position._2*N+rt(y._1.offset)*N)}}}g()},c=Rs(Tt(r)(_=>{if(_.nodes.length<=2)return[];const h=rt(4);if(1<_.nodes.length){const p=An(_.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 z(x=>b(x,m))(we(x=>y=>_.edgeId+":"+x+"->"+y,_.nodes,bt(1,_.nodes.length,_.nodes)))}g()}return[]})),f=_=>{const h=An(_.from.node)(s),p=An(_.to.node)(s);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,x=p._1,y=Lt(N=>v=>it.compare(N.score)(v.score))(z(N=>{const v=N._1,L=N._2;return{from:v,to:L,score:(()=>{const k=(et,G,P,V,U)=>{const B=Ws(et)(G),R=Ws(et)(P);return B.lo<R.hi&&R.lo<B.hi&&(v==="South"?L==="North"&&U._2>V._2:v==="North"?L==="South"&&U._2<V._2:v==="East"?L==="West"&&U._1>V._1:v==="West"&&L==="East"&&U._1<V._1)?0:Zg(v)(L)(V)(U)},E=Vg(v)(m),O=Vg(L)(x),Y=Zg(v)(L)(E)(O);return(()=>{if(Y>0){if(v==="South")return L==="North"?k(he,m,x,E,O)*10|0:Y*10|0;if(v==="North")return L==="South"?k(le,m,x,E,O)*10|0:Y*10|0;if(v==="East")return L==="West"?k(Pn,m,x,E,O)*10|0:Y*10|0;if(v==="West"&&L==="East")return k(In,m,x,E,O)*10|0}return Y*10|0})()+(v==="South"?L==="North"?0:15:v==="North"?L==="South"?0:15:v==="East"?L==="West"?5:15:v==="West"&&L==="East"?5:15)|0})()}})([b(he,le),b(Pn,le),b(In,le),b(he,Pn),b(he,In),b(le,he),b(le,Pn),b(le,In),b(Pn,he),b(In,he),b(Pn,In),b(In,Pn)]));if(0<y.length)return{from:y[0].from,to:y[0].to}}return{from:he,to:le}},d=Rs(z(_=>b(_.id,f(_)))(t)),l=(_,h,p,m,x,y)=>{const N=rt(4),v=An(h)(s);if(v.tag==="Nothing")return b(0,0);if(v.tag==="Just"){const L=Tx(b(p,_))(i);if(L.tag==="Just"){const k=v._1.position._1*N+L._1,E=rt(4);if(_==="South")return b(k,(v._1.position._2+v._1.size._2)*E);if(_==="North")return b(k,v._1.position._2*E);if(_==="East")return b((v._1.position._1+v._1.size._1)*E,k);if(_==="West")return b(v._1.position._1*E,k);g()}if(L.tag==="Nothing"){const k=Ws(_)(v._1),E=(k.lo+k.hi)/2,O=Bs(p)(Kg(k)(z(G=>G.id)(Lt(G=>P=>ut.compare(x(_)(G))(x(_)(P)))(st(G=>{const P=Bs(G.id)(d);if(P.tag==="Just"){const V=y(P._1);return V==="North"?_==="North":V==="South"?_==="South":V==="East"?_==="East":V==="West"&&_==="West"}if(P.tag==="Nothing")return!0;g()},(()=>{const G=An(h)(m);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()))))),Y=(()=>{if(O.tag==="Nothing")return E;if(O.tag==="Just")return O._1;g()})(),et=rt(4);if(_==="South")return b(Y,(v._1.position._2+v._1.size._2)*et);if(_==="North")return b(Y,v._1.position._2*et);if(_==="East")return b((v._1.position._1+v._1.size._1)*et,Y);if(_==="West")return b(v._1.position._1*et,Y)}}g()};return z(_=>{const h=Bs(_.edge.id)(c);if(h.tag==="Nothing")return _;if(h.tag==="Just")return{..._,fromPos:me(3)(_.edge.from.node)==="$d:"?b(h._1,_.fromPos._2):_.fromPos,toPos:me(3)(_.edge.to.node)==="$d:"?b(h._1,_.toPos._2):_.toPos};g()})(z(_=>{if(_.from.port.tag==="Just"&&_.to.port.tag==="Just")return{edge:_,fromPos:a(_.from.node,_.from.port._1,he),toPos:a(_.to.node,_.to.port._1,le),fromSide:he,toSide:le};const h=f(_);return{edge:_,fromPos:l(h.from,_.from.node,_.id,u,p=>m=>{const x=An(m.to.node)(s);if(x.tag==="Nothing")return 0;if(x.tag==="Just"){const y=rt(4);if(p==="South"||p==="North")return x._1.position._1*y+x._1.size._1*y/2;if(p==="East"||p==="West")return x._1.position._2*y+x._1.size._2*y/2}g()},p=>p.from),toPos:l(h.to,_.to.node,_.id,o,p=>m=>{const x=An(m.from.node)(s);if(x.tag==="Nothing")return 0;if(x.tag==="Just"){const y=rt(4);if(p==="South"||p==="North")return x._1.position._1*y+x._1.size._1*y/2;if(p==="East"||p==="West")return x._1.position._2*y+x._1.size._2*y/2}g()},p=>p.to),fromSide:h.from,toSide:h.to}})(t))},tf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Xr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},wx=(()=>{const t=Xe.unfoldr(mn);return e=>t(Ye("IterNode",e,pn))})(),zs=t=>e=>t.gapTop+1*rt(4)+rt(e)*2.5*rt(4),vx=t=>e=>{const n=tf(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return w("Just",{slot1Y:zs(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:zs(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return J;g()}if(n.tag==="Nothing")return J;g()},bx=t=>e=>{const n=T(r=>i=>j(C)(i.node)(i)(r))(Q)(e);return Re(Ft(r=>i=>{const o=Xr(i.node)(n);if(o.tag==="Nothing")return[];if(o.tag==="Just"){const u=o._1;return Ft(s=>a=>{const c=i.edges.length,f=rt(4),d=u.position._1*f,l=u.position._2*f,_=u.size._2*f,h=rt((2*c|0)+1|0),p=l+_*rt(c-s|0)/h,m=l+_*rt((c+1|0)+s|0)/h,x=d-f*2.5*rt(s+1|0),y=[{start:b(d,p),end:b(x,p),direction:ne},{start:b(x,p),end:b(x,m),direction:re},{start:b(x,m),end:b(d,m),direction:ne}];return{edge:a.id,segments:y,bends:we(N=>v=>N.end,y,bt(1,3,y)),bendType:[],jumps:[],reversed:!1}})(i.edges)}g()})(z(r=>({node:r._1,edges:r._2}))(wx(T(r=>i=>vt(C)(ee)(i.from.node)([i])(r))(Q)(t)))))},kx=t=>e=>{const n=T(o=>u=>j(C)(u.node)(u)(o))(Q)(e),r=o=>{const u=Xr(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.position._1;g()},i=o=>{const u=Xr(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.layer;g()};return Lt(o=>u=>{const s=it.compare(i(o.edge.from.node))(i(u.edge.from.node));if(s==="EQ"){const a=ut.compare(r(o.edge.from.node))(r(u.edge.from.node));return a==="EQ"?ut.compare(r(o.edge.to.node))(r(u.edge.to.node)):a}return s})(t)},De=t=>{const e=rt(4);return{x:t.position._1*e-2,y:t.position._2*e-2,w:t.size._1*e+4,h:t.size._2*e+4}},Lx=t=>t.from.node===t.to.node,Ex=t=>e=>n=>r=>{const i=_x(n)(Nx(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:i,bends:we(o=>u=>o.end,i,bt(1,i.length,i)),bendType:[],jumps:[],reversed:!1}},Cx=t=>e=>n=>r=>{const i=[{start:b(r.fromPos._1,r.fromPos._2),end:b(r.fromPos._1,t.slot1Y),direction:re},{start:b(r.fromPos._1,t.slot1Y),end:b(t.splitX,t.slot1Y),direction:ne},{start:b(t.splitX,t.slot1Y),end:b(t.splitX,t.slot2Y),direction:re},{start:b(t.splitX,t.slot2Y),end:b(r.toPos._1,t.slot2Y),direction:ne},{start:b(r.toPos._1,t.slot2Y),end:b(r.toPos._1,r.toPos._2),direction:re}];return{edge:r.edge.id,segments:i,bends:we(o=>u=>o.end,i,bt(1,5,i)),bendType:[],jumps:[],reversed:!1}},Sx=t=>e=>n=>{const r=Xr(t.edge.from.node)(n);if(r.tag==="Just"){const o=Xr(t.edge.to.node)(n);return o.tag==="Just"?st(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(o._1).h&&u.w===De(o._1).w&&u.x===De(o._1).x&&u.y===De(o._1).y),e):st(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),e)}const i=Xr(t.edge.to.node)(n);return i.tag==="Just"?st(o=>!(o.h===De(i._1).h&&o.w===De(i._1).w&&o.x===De(i._1).x&&o.y===De(i._1).y),e):st(o=>!0,e)},Gx=t=>e=>{const n=tf(e.edge.id)(t);if(n.tag==="Just")return w("Just",zs(n._1)(n._1.slot));if(n.tag==="Nothing")return J;g()},Px=t=>e=>n=>r=>i=>{const o=T(c=>f=>j(C)(f.node)(f)(c))(Q)(e),u=Jx(e),s=jg(st(c=>c.from.node!==c.to.node,t))(e)(n)(r)(i),a=Hg(s)(e);return[...bx(st(Lx,t))(e),...T(c=>f=>{const d=Sx(f)(u)(o),l=[...d,...c.edgeObstacles],_=vx(a)(f),h=(()=>{if(_.tag==="Just")return Cx(_._1)(d)(l)(f);if(_.tag==="Nothing")return Ex(Gx(a)(f))(d)(l)(f);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...ux(h.segments)]}})({results:[],edgeObstacles:[]})(kx(s)(e)).results]},rr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ir=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ix=t=>e=>n=>{if(t.start._1!==e.start._1)return J;const r=ir(rr(t.start._2)(t.end._2))(rr(e.start._2)(e.end._2)),i=rr(ir(t.start._2)(t.end._2))(ir(e.start._2)(e.end._2));return r<i?w("Just",{position:b(t.start._1,(r+i)/2),crossingEdge:n}):J},Dx=t=>e=>n=>{if(t.start._2!==e.start._2)return J;const r=ir(rr(t.start._1)(t.end._1))(rr(e.start._1)(e.end._1)),i=rr(ir(t.start._1)(t.end._1))(ir(e.start._1)(e.end._1));return r<i?w("Just",{position:b((r+i)/2,t.start._2),crossingEdge:n}):J},Qx=t=>e=>n=>{if(t.direction==="H")return Dx(t)(e)(n);if(t.direction==="V")return Ix(t)(e)(n);g()},Fx=t=>e=>n=>{const r=t+1|0,i=r<1?n:bt(r,n.length,n);return Tt(e.segments)(o=>Tt(i)(u=>yt(s=>Qx(o)(s)(u.edge))(st(s=>s.direction==="H"?o.direction==="H":s.direction==="V"&&o.direction==="V",u.segments))))},Ax=t=>e=>n=>e.start._1>rr(t.start._1)(t.end._1)&&e.start._1<ir(t.start._1)(t.end._1)&&t.start._2>rr(e.start._2)(e.end._2)&&t.start._2<ir(e.start._2)(e.end._2)?w("Just",{position:b(e.start._1,t.start._2),crossingEdge:n}):J,Mx=t=>e=>Tt(st(n=>n.direction==="H",t.segments))(n=>Tt(e)(r=>yt(i=>Ax(n)(i)(r.edge))(st(i=>i.direction==="V",r.segments)))),Ox=t=>e=>n=>[...Mx(e)(st(r=>r.edge!==e.edge,n)),...Fx(t)(e)(n)],ef=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},nf=t=>me(3)(t)==="$d:",Rx=t=>e=>n=>T(r=>i=>{const o=ef(i.from.node)(t),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})(),s=ef(i.to.node)(t),a=(()=>{if(s.tag==="Nothing")return-u;if(s.tag==="Just")return s._1-u|0;g()})();if(a<=1)return{...r,edges:[...r.edges,i],chains:[...r.chains,{edgeId:i.id,nodes:[i.from.node,i.to.node]}]};const c=i.id,f=z(l=>"$d:"+c+":"+oe(l))(Dt(1,a-1|0)),d=[i.from.node,...f,i.to.node];return{...r,layers:T(l=>_=>{const h=_._2,p=hd(u+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;g()})(r.layers)(we(Sn,Dt(1,a-1|0),f)),edges:[...r.edges,...we(l=>_=>({id:c+":"+l+"->"+_,from:{node:l,port:i.from.port},to:{node:_,port:i.to.port},label:J}),d,bt(1,d.length,d))],chains:[...r.chains,{edgeId:i.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),Xo=(()=>{const t={eq:e=>n=>e._1===n._1&&(e._2==="North"?n._2==="North":e._2==="South"?n._2==="South":e._2==="East"?n._2==="East":e._2==="West"&&n._2==="West")};return{compare:e=>n=>{const r=C.compare(e._1)(n._1);if(r==="LT")return Ne;if(r==="GT")return Je;if(e._2==="North")return n._2==="North"?Ge:Ne;if(n._2==="North")return Je;if(e._2==="South")return n._2==="South"?Ge:Ne;if(n._2==="South")return Je;if(e._2==="East")return n._2==="East"?Ge:Ne;if(n._2==="East")return Je;if(e._2==="West"&&n._2==="West")return Ge;g()},Eq0:()=>t}})(),Bx=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=Xo.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Wx=jt(C)(Wt),qs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},zx=jt(Xo)(Wt),rf=(()=>{const t=Xe.unfoldr(mn);return e=>t(Ye("IterNode",e,pn))})(),Yr=t=>e=>n=>r=>{const i=Bx(b(e,n))(t);if(i.tag==="Nothing")return r;if(i.tag==="Just")return i._1;g()},of=t=>e=>n=>{const r=Wx(Re(z(u=>Ft(s=>a=>b(a,s))(u))(t))),i=(u,s)=>{if(u==="South"){const a=qs(s.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()}if(u==="North"){const a=qs(s.from.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()}return 0},o=u=>T(s=>a=>Ee(Xo.compare,ke,zx(z(c=>b(b(c._1,u),c._2))(rf(Kg({lo:0,hi:(()=>{const c=qs(a._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return me(3)(a._1)==="$d:"?0:1;g()})()})(z(c=>c.id)(Lt(c=>f=>it.compare(i(u,c))(i(u,f)))(a._2)))))),s))(Q)(rf(T(s=>a=>a.from.node===a.to.node?s:u==="South"?vt(C)(ee)(a.from.node)([a])(s):u==="North"?vt(C)(ee)(a.to.node)([a])(s):s)(Q)(e)));return Ee(Xo.compare,ke,o(le),o(he))},uf=t=>t,sf=t=>t,af=t=>t,qx=T(t=>e=>j(C)(e)()(t))(Q),Hx=(()=>{const t=Xe.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return w("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._3,n(r._6,i)));g()};return n(e,Ht)})())})(),ot=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},on=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Jn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Tn=jt(C)(Wt),Hs=oc(C),$s=(()=>{const t=Xe.unfoldr(mn);return e=>t(Ye("IterNode",e,pn))})(),$x=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Xx=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=it.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},cf=af("VDown"),gf=af("VUp"),Yx=sf("ForwardPhase"),Vx=sf("StackPhase"),ff=uf("HRight"),_f=uf("HLeft"),df=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Ux=t=>e=>n=>{const r=T(u=>s=>vt(C)(ue)(s.tgt)(1)(u))(Q)(t),i=Hx(qx([...z(u=>u.src)(t),...z(u=>u.tgt)(t),...(()=>{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)));g()};return Ct($t.foldr,u(e,Ht))})()])),o=T(u=>s=>vt(C)(ee)(s.src)([{target:s.tgt,sep:s.sep}])(u))(Q)(t);return(u=>s=>a=>{let c=u,f=s,d=a,l=!0,_;for(;l;){const h=c,p=f,m=d,x=At(y=>J,y=>N=>w("Just",{head:y,tail:N}),h);if(x.tag==="Nothing"){l=!1,_=m;continue}if(x.tag==="Just"){const y=ot(x._1.head)(m),N=(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;g()})(),v=T(L=>k=>{const E=ot(k.target)(L.result),O=N+k.sep,Y=ot(k.target)(L.indeg),et=(()=>{if(Y.tag==="Nothing")return-1;if(Y.tag==="Just")return Y._1-1|0;g()})();return{newQueue:et===0?[...L.newQueue,k.target]:L.newQueue,result:j(C)(k.target)((()=>{if(E.tag==="Nothing")return O;if(E.tag==="Just"){if(n==="VDown")return on(E._1)(O);if(n==="VUp")return Jn(E._1)(O)}g()})())(L.result),indeg:j(C)(k.target)(et)(L.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const L=ot(x._1.head)(o);if(L.tag==="Nothing")return[];if(L.tag==="Just")return L._1;g()})());c=[...x._1.tail,...v.newQueue],f=v.indeg,d=v.result;continue}g()}return _})(st(u=>{const s=ot(u)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;g()},i))(r)(T(u=>s=>j(C)(s)(0)(u))(Q)(i))},Zx=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,qt("Cons",o._4,e(o._6,u)));g()},n=Ct($t.foldr,e(t,Ht)),r=T(on)(999999)(n);if(r===0||n.length===0)return t;const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return zt("Node",o._1,o._2,o._3,o._4-r,i(o._5),i(o._6));g()};return i(t)},lf=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,qt("Cons",o._4,e(o._6,u)));g()},n=e(t,Ht),r=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l.tag==="Nil"){c=!1,f=d;continue}if(l.tag==="Cons"){s=Jn(d)(l._1),a=l._2;continue}g()}return f},i=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l.tag==="Nil"){c=!1,f=d;continue}if(l.tag==="Cons"){s=on(d)(l._1),a=l._2;continue}g()}return f};return r(-999999)(n)-i(999999)(n)},Oi=t=>e=>(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(a===e){u=!1,s=c;continue}i=(()=>{const f=ot(a)(t.align);if(f.tag==="Nothing")return e;if(f.tag==="Just")return f._1;g()})(),o=[...c,a]}return s})((()=>{const n=ot(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;g()})())([e]),Kx=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>{const d=(S,I,D)=>{const A=S.from.node===I?S.from.port:S.to.node===I?S.to.port:J;if(A.tag==="Just"){const H=ot(I)(i);if(H.tag==="Just"){const $=Vt(X=>X.id===A._1)(H._1);if($.tag==="Just"){const X=rt($._1.offset)*rt(4);return D==="North"||D==="South"?X:0}if($.tag==="Nothing"){const X=ot(I)(r),q=Yr(u)(S.id)(D)((()=>{if(X.tag==="Nothing")return .5;if(X.tag==="Just")return X._1._1/2;g()})());return D==="North"||D==="South"?q:0}g()}if(H.tag==="Nothing"){const $=ot(I)(r),X=Yr(u)(S.id)(D)((()=>{if($.tag==="Nothing")return .5;if($.tag==="Just")return $._1._1/2;g()})());return D==="North"||D==="South"?X:0}g()}if(A.tag==="Nothing"){const H=ot(I)(r),$=Yr(u)(S.id)(D)((()=>{if(H.tag==="Nothing")return .5;if(H.tag==="Just")return H._1._1/2;g()})());return D==="North"||D==="South"?$:0}g()},l=(S,I)=>{if(S.from.node===I){if(f==="HRight")return he;if(f==="HLeft")return le;g()}if(f==="HRight")return le;if(f==="HLeft")return he;g()},_=(S,I,D)=>T(A=>H=>j(C)(H)((()=>{const $=ot(H)(A);if($.tag==="Nothing")return 0+I;if($.tag==="Just")return $._1+I;g()})())(A))(D)(Oi(a)(S)),h=(()=>{if(f==="HRight")return n;if(f==="HLeft")return Te(n);g()})(),p=S=>{const I=ot(S)(r);if(I.tag==="Nothing")return 1;if(I.tag==="Just")return I._1._1;g()},m=Tn(Re(Ft(S=>I=>z(D=>b(D,S))(I))(n))),x=(S,I)=>me(3)(S)==="$d:"&&me(3)(I)==="$d:"||me(3)(S)==="$d:"||me(3)(I)==="$d:"?10:rt(t.nodeGap),y=T(S=>I=>Hs(D=>w("Just",[...(()=>{if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})(),I]))(I.to.node)(S))(Q)(o),N=T(S=>I=>Hs(D=>w("Just",[...(()=>{if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})(),I]))(I.from.node)(S))(Q)(o),v=Re(n),L=T(S=>I=>{const D=ot(I)(a.root),A=(()=>{if(D.tag==="Nothing")return I;if(D.tag==="Just")return D._1;g()})();return I===A?S:Hs(H=>w("Just",(()=>{if(H.tag==="Nothing")return!0;if(H.tag==="Just")return H._1;g()})()&&me(3)(I)==="$d:"))(A)(S)})(Tn(z(S=>b(S,!0))(Sr(C.compare)((()=>{const S=(I,D)=>{if(I.tag==="Leaf")return D;if(I.tag==="Node")return S(I._5,qt("Cons",I._4,S(I._6,D)));g()};return Ct($t.foldr,S(a.root,Ht))})()))))(v),k=(S,I)=>{const D=S.free,A=ot(D)(a.root),H=(()=>{if(A.tag==="Nothing")return D;if(A.tag==="Just")return A._1;g()})(),$=ot(H)(L),X=(()=>{if($.tag==="Nothing")return!0;if($.tag==="Just")return $._1;g()})();return T(q=>W=>{if(q.edge.tag==="Just")return q;if(q.edge.tag==="Nothing"){if((()=>{const at=ot(H)(I.su);return!X&&(()=>{const xt=ot(W.from.node)(m);return W.from.node!==W.to.node&&(()=>{const St=ot(W.to.node)(m);return(()=>{if(xt.tag==="Nothing")return-1;if(xt.tag==="Just")return xt._1;g()})()===(()=>{if(St.tag==="Nothing")return-1;if(St.tag==="Just")return St._1;g()})()})()})()||(()=>{if(at.tag==="Nothing")return!1;if(at.tag==="Just")return at._1;g()})()})())return q;const tt=W.from.node===D?W.to.node:W.from.node,Z=ot(tt)(a.root),ct=(()=>{if(Z.tag==="Nothing")return tt;if(Z.tag==="Just")return Z._1;g()})(),ft=ct!==H;return ft&&(()=>{const at=ot(ct)(I.blockFinished);if(at.tag==="Nothing")return!1;if(at.tag==="Just")return at._1;g()})()?{...q,edge:w("Just",W),hasEdges:!0}:{...q,hasEdges:q.hasEdges||ft}}g()})({edge:J,hasEdges:!1})((()=>{if(S.isRoot){if(f==="HRight"){const q=ot(D)(y);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;g()}if(f==="HLeft"){const q=ot(D)(N);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}g()}if(f==="HRight"){const q=ot(D)(N);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;g()}if(f==="HLeft"){const q=ot(D)(y);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}g()})())},E=(S,I,D,A)=>{const H=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),$={free:I,isRoot:D},X=k($,A);if(X.edge.tag==="Nothing")return X.hasEdges?{thresh:H,state:{...A,queue:[...A.queue,$]}}:{thresh:H,state:A};if(X.edge.tag==="Just"){const q=X.edge._1.from.node===I?X.edge._1.to.node:X.edge._1.from.node;return{thresh:(()=>{const W=ot((()=>{const ft=ot(q)(a.root);if(ft.tag==="Nothing")return q;if(ft.tag==="Just")return ft._1;g()})())(A.x),tt=ot(q)(s),Z=ot(I)(s),ct=(()=>{if(W.tag==="Just")return W._1;if(W.tag==="Nothing")return J;g()})();return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+(()=>{if(tt.tag==="Nothing")return 0;if(tt.tag==="Just")return tt._1;g()})()+d(X.edge._1,q,(()=>{if(D){if(f==="HRight")return he;if(f==="HLeft")return le;g()}if(f==="HRight")return le;if(f==="HLeft")return he;g()})())-(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()-d(X.edge._1,I,(()=>{if(D){if(f==="HRight")return le;if(f==="HLeft")return he;g()}if(f==="HRight")return he;if(f==="HLeft")return le;g()})())})(),state:{...A,su:j(C)((()=>{const W=ot(X.edge._1.from.node)(a.root);if(W.tag==="Nothing")return X.edge._1.from.node;if(W.tag==="Just")return W._1;g()})())(!0)(j(C)((()=>{const W=ot(X.edge._1.to.node)(a.root);if(W.tag==="Nothing")return X.edge._1.to.node;if(W.tag==="Just")return W._1;g()})())(!0)(A.su))}}}g()},O=(S,I,D,A)=>{const H=I===S,$=ot(I)(a.align),X=(()=>{if($.tag==="Nothing")return I===S;if($.tag==="Just")return $._1===S;g()})();if(!(H||X))return{thresh:D,state:A};const q=(()=>{if(c==="VDown")return H&&D<=-1e18;if(c==="VUp")return H&&D>=1e18;g()})()?E(S,I,!0,A):{thresh:D,state:A};return(()=>{if(c==="VDown")return q.thresh<=-1e18&&X;if(c==="VUp")return q.thresh>=1e18&&X;g()})()?E(S,I,!1,q.state):q},Y=S=>I=>D=>{const A=ot(D)(e.nodeIndex),H=(()=>{if(A.tag==="Nothing")return 0;if(A.tag==="Just")return A._1;g()})(),$=Vt(Z=>We(_n)(D)(Z))(h),X=(()=>{if($.tag==="Nothing")return[];if($.tag==="Just")return $._1;g()})(),q=X.length;if((()=>{if(c==="VDown")return H<=0;if(c==="VUp")return H>=(q-1|0);g()})()){const Z=O(S,D,I.thresh,I.st);return{...I,st:Z.state,thresh:Z.thresh}}const W=(()=>{if(c==="VDown")return H-1|0;if(c==="VUp")return H+1|0;g()})(),tt=W>=0&&W<X.length?w("Just",X[W]):J;if(tt.tag==="Nothing")return I;if(tt.tag==="Just"){const Z=ot(tt._1)(a.root),ct=(()=>{if(Z.tag==="Nothing")return tt._1;if(Z.tag==="Just")return Z._1;g()})(),ft=O(S,D,I.thresh,et(ct)(I.st)),at=(()=>{const Kt=ot(S)(ft.state.sink);if(Kt.tag==="Nothing")return S===S;if(Kt.tag==="Just")return Kt._1===S;g()})()?{...ft.state,sink:j(C)(S)((()=>{const Kt=ot(ct)(ft.state.sink);if(Kt.tag==="Nothing")return ct;if(Kt.tag==="Just")return Kt._1;g()})())(ft.state.sink)}:ft.state,xt=ot(ct)(at.sink),St=(()=>{if(xt.tag==="Nothing")return ct;if(xt.tag==="Just")return xt._1;g()})(),Rt=ot(S)(at.sink),pt=(()=>{if(Rt.tag==="Nothing")return S;if(Rt.tag==="Just")return Rt._1;g()})();if(pt===St){const Kt=ot(ct)(at.x),Se=(()=>{if(Kt.tag==="Just")return Kt._1;if(Kt.tag==="Nothing")return J;g()})(),an=(()=>{if(Se.tag==="Nothing")return 0;if(Se.tag==="Just")return Se._1;g()})(),Oe=ot(S)(at.x),Et=(()=>{if(Oe.tag==="Just")return Oe._1;if(Oe.tag==="Nothing")return J;g()})(),Qt=(()=>{if(Et.tag==="Nothing")return 0;if(Et.tag==="Just")return Et._1;g()})(),tn=x(D,tt._1),He=ot(tt._1)(s),en=ot(D)(s),$n=(()=>{if(He.tag==="Nothing")return 0;if(He.tag==="Just")return He._1;g()})()-(()=>{if(en.tag==="Nothing")return 0;if(en.tag==="Just")return en._1;g()})();if(c==="VDown"){const ln=Jn(an+$n+p(tt._1)+tn)(ft.thresh);return{st:{...at,x:j(C)(S)(w("Just",I.initial?ln:Jn(Qt)(ln)))(at.x)},initial:!1,thresh:ft.thresh}}if(c==="VUp"){const ln=on(an+$n-tn-p(D))(ft.thresh);return{st:{...at,x:j(C)(S)(w("Just",I.initial?ln:on(Qt)(ln)))(at.x)},initial:!1,thresh:ft.thresh}}g()}const Bt=ot(ct)(at.x),Jt=(()=>{if(Bt.tag==="Just")return Bt._1;if(Bt.tag==="Nothing")return J;g()})(),mt=(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})(),gt=ot(S)(at.x),K=(()=>{if(gt.tag==="Just")return gt._1;if(gt.tag==="Nothing")return J;g()})(),nt=(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})(),ht=rt(t.nodeGap),_t=ot(D)(s),Nt=ot(tt._1)(s),wt=(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;g()})()-(()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1;g()})();return{st:{...at,classEdges:[...at.classEdges,{src:pt,tgt:St,sep:(()=>{if(c==="VDown")return nt+wt-mt-p(tt._1)-ht;if(c==="VUp")return nt+wt+p(D)+ht-mt;g()})()}]},initial:I.initial,thresh:ft.thresh}}g()},et=S=>I=>{const D=ot(S)(I.x),A=(()=>{if(D.tag==="Just")return D._1;if(D.tag==="Nothing")return J;g()})();if(A.tag==="Just")return I;if(A.tag==="Nothing"){const H=T(Y(S))({st:{...I,x:j(C)(S)(w("Just",0))(I.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})()})(Oi(a)(S));return{...H.st,blockFinished:j(C)(S)(!0)(H.st.blockFinished)}}g()},G=T(S=>I=>T(D=>A=>{const H=ot(A)(a.root),$=(()=>{if(H.tag==="Nothing")return A;if(H.tag==="Just")return H._1;g()})();return $===A?et($)(D):D})(S)((()=>{if(c==="VDown")return I;if(c==="VUp")return Te(I);g()})()))({x:Tn(z(S=>b(S,J))(v)),sink:Tn(z(S=>b(S,S))(v)),classEdges:[],su:Q,blockFinished:Q,queue:[]})(h),P=Ux(G.classEdges)(G.sink)(c),V=(S,I,D,A)=>{const H=ot(I)(A),$=ot(I)(s);return(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})()+(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;g()})()+d(S,I,D)},U=Tn(z(S=>b(S,!0))(Sr(C.compare)((()=>{const S=(I,D)=>{if(I.tag==="Leaf")return D;if(I.tag==="Node")return S(I._5,qt("Cons",I._4,S(I._6,D)));g()};return Ct($t.foldr,S(a.root,Ht))})()))),B=S=>I=>D=>{const A=k(D,{su:I.su,blockFinished:U}),H={phase:S,ppFree:D.free,ppIsRoot:D.isRoot,edgeId:J,delta:0,avail:0,shift:0,freeSu:(()=>{const $=ot((()=>{const X=ot(D.free)(a.root);if(X.tag==="Nothing")return D.free;if(X.tag==="Just")return X._1;g()})())(I.su);if($.tag==="Nothing")return!1;if($.tag==="Just")return $._1;g()})(),hasEdges:A.hasEdges,candCount:(()=>{if(D.isRoot){if(f==="HRight"){const $=ot(D.free)(y);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length;g()}if(f==="HLeft"){const $=ot(D.free)(N);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length}g()}if(f==="HRight"){const $=ot(D.free)(N);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length;g()}if(f==="HLeft"){const $=ot(D.free)(y);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length}g()})()};if(A.edge.tag==="Nothing")return{...I,stack:[...I.stack,D],trace:[...I.trace,H],x:I.x};if(A.edge.tag==="Just"){const $=A.edge._1.from.node===D.free?b(A.edge._1.from.node,A.edge._1.to.node):b(A.edge._1.to.node,A.edge._1.from.node),X=V(A.edge._1,$._1,l(A.edge._1,$._1),I.x)-V(A.edge._1,$._2,l(A.edge._1,$._2),I.x),q=ot($._1)(a.root),W=(()=>{if(q.tag==="Nothing")return $._1;if(q.tag==="Just")return q._1;g()})(),tt={...H,edgeId:w("Just",A.edge._1.id),delta:X};if(X>0&&X<1e300){const Z=T(at=>xt=>{const St=ot(xt)(m),Rt=(()=>{if(St.tag==="Nothing")return-1;if(St.tag==="Just")return St._1;g()})();if(Rt>=0&&Rt<n.length){const Jt=n[Rt],mt=ot(xt)(e.nodeIndex),gt=(()=>{if(mt.tag==="Nothing")return-2;if(mt.tag==="Just")return mt._1-1|0;g()})();return gt>=0&&gt<Jt.length?on(at)((()=>{const K=ot(xt)(I.x),nt=ot(xt)(s),ht=ot(Jt[gt])(I.x),_t=ot(Jt[gt])(s);return(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;g()})()-((()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;g()})()+p(Jt[gt])+x(xt,Jt[gt]))})()):at}const pt=ot(xt)(e.nodeIndex),Bt=(()=>{if(pt.tag==="Nothing")return-2;if(pt.tag==="Just")return pt._1-1|0;g()})();return Bt>=0&&Bt<0?on(at)((()=>{const Jt=ot(xt)(I.x),mt=ot(xt)(s),gt=ot([][Bt])(I.x),K=ot([][Bt])(s);return(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})()+(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()-((()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()+(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+p([][Bt])+x(xt,[][Bt]))})()):at})(X)(Oi(a)(W)),ct=Z>0?-Z:0,ft={...I,x:Z>0?_(W,ct,I.x):I.x,trace:[...I.trace,{...tt,avail:Z,shift:ct}]};return Z>0?ft:{...ft,stack:[...ft.stack,D]}}if(X<0&&-X<1e300){const Z=T(at=>xt=>{const St=ot(xt)(m),Rt=(()=>{if(St.tag==="Nothing")return-1;if(St.tag==="Just")return St._1;g()})();if(Rt>=0&&Rt<n.length){const Jt=n[Rt],mt=ot(xt)(e.nodeIndex),gt=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1+1|0;g()})();return gt>=0&&gt<Jt.length?on(at)((()=>{const K=ot(Jt[gt])(I.x),nt=ot(Jt[gt])(s),ht=ot(xt)(I.x),_t=ot(xt)(s);return(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;g()})()-((()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;g()})()+p(xt)+x(xt,Jt[gt]))})()):at}const pt=ot(xt)(e.nodeIndex),Bt=(()=>{if(pt.tag==="Nothing")return 0;if(pt.tag==="Just")return pt._1+1|0;g()})();return Bt>=0&&Bt<0?on(at)((()=>{const Jt=ot([][Bt])(I.x),mt=ot([][Bt])(s),gt=ot(xt)(I.x),K=ot(xt)(s);return(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})()+(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()-((()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()+(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+p(xt)+x(xt,[][Bt]))})()):at})(-X)(Oi(a)(W)),ct=Z>0?Z:0,ft={...I,x:Z>0?_(W,ct,I.x):I.x,trace:[...I.trace,{...tt,avail:Z,shift:ct}]};return Z>0?ft:{...ft,stack:[...ft.stack,D]}}return{...I,stack:[...I.stack,D],trace:[...I.trace,tt],x:I.x}}g()},R=T(B(Yx))({x:Tn(z(S=>b(S,(()=>{const I=ot(S)(a.root),D=(()=>{if(I.tag==="Nothing")return S;if(I.tag==="Just")return I._1;g()})(),A=ot(D)(G.x),H=ot((()=>{const X=ot(D)(G.sink);if(X.tag==="Nothing")return D;if(X.tag==="Just")return X._1;g()})())(P),$=(()=>{if(A.tag==="Just")return A._1;if(A.tag==="Nothing")return J;g()})();return(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;g()})()+(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})()})()))(v)),su:G.su,stack:[],trace:[]})(G.queue),M=T(B(Vx))({...R,stack:[]})(Te(R.stack));return{x:M.x,queue:G.queue,trace:M.trace}},jx=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>Kx(t)(e)(n)(r)(i)(o)(u)(s)(a)(c)(f).x,ty=t=>e=>n=>r=>i=>o=>{const u=(a,c,f)=>{const d=ot(c)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;g()})(),_=a.from.node===c?a.from.port:a.to.node===c?a.to.port:J;if(_.tag==="Just"){const h=ot(c)(e);if(h.tag==="Just"){const p=Vt(m=>m.id===_._1)(h._1);if(p.tag==="Just"){const m=rt(p._1.offset)*rt(4);return f==="North"||f==="South"?m:0}if(p.tag==="Nothing"){const m=Yr(i)(a.id)(f)(l);return f==="North"||f==="South"?m:0}g()}if(h.tag==="Nothing"){const p=Yr(i)(a.id)(f)(l);return f==="North"||f==="South"?p:0}g()}if(_.tag==="Nothing"){const h=Yr(i)(a.id)(f)(l);return f==="North"||f==="South"?h:0}g()},s=a=>c=>f=>d=>{let l=a,_=c,h=f,p=d,m=!0,x;for(;m;){const y=l,N=_,v=h,L=At(k=>J,k=>E=>w("Just",{head:k,tail:E}),p);if(L.tag==="Nothing"){m=!1,x=y;continue}if(L.tag==="Just"){const k=L._1.head,E=Vt(Y=>Y.from.node===v&&Y.to.node===k||Y.from.node===k&&Y.to.node===v)(r),O=(()=>{if(E.tag==="Nothing")return N+0;if(E.tag==="Just")return N+(u(E._1,v,E._1.from.node===v?he:le)-u(E._1,k,E._1.from.node===k?he:le));g()})();l=j(C)(k)(O)(y),_=O,h=k,p=L._1.tail;continue}g()}return x};return T(a=>c=>{const f=At(_=>J,_=>h=>w("Just",{head:_,tail:h}),Oi(t)(c)),d=(()=>{if(f.tag==="Nothing")return j(C)(c)(0)(Q);if(f.tag==="Just")return s(j(C)(f._1.head)(0)(Q))(0)(f._1.head)(f._1.tail);g()})(),l=T(_=>h=>Jn(_)(-h._2))(0)($s(d));return T(_=>h=>j(C)(h._1)(h._2+l)(_))(a)($s(d))})(Q)(Sr(C.compare)((()=>{const a=(c,f)=>{if(c.tag==="Leaf")return f;if(c.tag==="Node")return a(c._5,qt("Cons",c._4,a(c._6,f)));g()};return Ct($t.foldr,a(t.root,Ht))})()))},ey=t=>e=>{const n=(i,o,u)=>me(3)(o)==="$d:"&&Za(nf,(()=>{const s=ot(o)(t.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;g()})()),r=i=>o=>u=>s=>a=>c=>f=>{let d=i,l=o,_=s,h=c,p=f,m=!0,x;for(;m;){const y=d,N=l,v=_,L=h,k=p,E=N.length;if(k>=E){m=!1,x=y;continue}const O=k>=0&&k<N.length?w("Just",N[k]):J,Y=(()=>{if(O.tag==="Nothing")return"";if(O.tag==="Just")return O._1;g()})(),et=n(t,Y);if(k===(E-1|0)||et){const G=(()=>{if(et){const P=ot(Y)(t.preds),V=(()=>{if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})();if(0<V.length){const U=v-1|0,B=ot(V[0])(t.nodeIndex);if(B.tag==="Nothing")return U;if(B.tag==="Just")return B._1;g()}}return v-1|0})();d=T(P=>V=>{if(V>=0&&V<N.length){const U=N[V];return n(t,U)?P:T(B=>R=>{const M=ot(R)(t.nodeIndex),S=(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})();return S<L||S>G?j(C)(R+"\u2192"+U)()(B):B})(P)((()=>{const B=ot(U)(t.preds);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;g()})())}return n(t,"")?P:T(U=>B=>{const R=ot(B)(t.nodeIndex),M=(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})();return M<L||M>G?j(C)(B+"\u2192")()(U):U})(P)((()=>{const U=ot("")(t.preds);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;g()})())})(y)(Dt(0,k)),l=N,_=v,h=G,p=k+1|0;continue}d=y,l=N,_=v,h=L,p=k+1|0}return x};return e.length<3?Q:T(i=>o=>{if(o>=0&&o<e.length){const u=e[o];return r(i)((()=>{const s=o+1|0;return s>=0&&s<e.length?e[s]:[]})())(u)(u.length)(o)(0)(0)}return r(i)((()=>{const u=o+1|0;return u>=0&&u<e.length?e[u]:[]})())([])(0)(o)(0)(0)})(Q)(Dt(1,e.length-2|0))},ny=t=>e=>n=>r=>i=>{const o=Re(e),u=T(s=>a=>{const c=T(f=>d=>{const l=(()=>{if(i==="HRight"){const m=ot(d)(t.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()}if(i==="HLeft"){const m=ot(d)(t.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}g()})(),_=l.length;if(_===0)return f;const h=Cn(_-1|0,2),p=Cn(_,2);return T(m=>x=>{if((()=>{const y=ot(d)(m.align);if(y.tag==="Nothing")return d!==d;if(y.tag==="Just")return y._1!==d;g()})())return m;if(x>=0&&x<l.length){const y=ot(l[x])(t.nodeIndex),N=(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;g()})();if(!(df(l[x]+"\u2192"+d)(n)||df(d+"\u2192"+l[x])(n))&&(()=>{if(r==="VDown")return m.r<N;if(r==="VUp")return m.r>N;g()})()){const v=ot(l[x])(m.root),L=(()=>{if(v.tag==="Nothing")return l[x];if(v.tag==="Just")return v._1;g()})();return{root:j(C)(d)(L)(m.root),align:j(C)(l[x])(d)(j(C)(d)(L)(m.align)),r:N}}}return m})(f)((()=>{if(r==="VDown")return Dt(h,p);if(r==="VUp")return Te(Dt(h,p));g()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;g()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return Te(a);g()})());return{root:c.root,align:c.align}})({root:Tn(z(s=>b(s,s))(o)),align:Tn(z(s=>b(s,s))(o))})((()=>{if(i==="HRight")return e;if(i==="HLeft")return Te(e);g()})());return{root:u.root,align:u.align}},Yo=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>{const f=ny(e)(n)(s)(a)(c),d=ty(f)(i)(r)(o)(u)(c);return Ed()(l=>_=>w("Just",(()=>{const h=ot(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;g()})()))(jx(t)(e)(n)(r)(i)(o)(u)(d)(f)(a)(c))},hf=t=>e=>Ft(n=>r=>T(i=>o=>o>=0&&o<e.length?o>=0&&o<t.length?i+e[o]+t[o]:i+e[o]+0:o>=0&&o<t.length?i+1+t[o]:i+1)(0)((()=>{const i=Dt(0,e.length-1|0);return n<1?[]:bt(0,n,i)})()))(e),ry=t=>e=>n=>r=>i=>o=>u=>{const s=$x(0)(e.length-1|0),a=rt(t.layerGap),c=u(fd(s,a)),f=ox(jg(i)(c)(r)(o)(Q))(c);return z(d=>{const l=Xx(d)(f);return l.tag==="Just"&&l._1>0?Jn(a)(2+rt(l._1-1|0)*2.5):a})(Dt(0,s-1|0))},pf=t=>e=>n=>r=>Za(i=>T(o=>u=>{if(!o.ok)return o;const s=ot(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})(),c=ot(u)(n),f=(()=>{if(c.tag==="Nothing")return a+1;if(c.tag==="Just")return a+c._1._1;g()})();return a+1e-4>o.pos&&f+1e-4>o.pos?{ok:!0,pos:f}:{ok:!1,pos:o.pos}})({ok:!0,pos:-1e18})(i).ok,e),iy=t=>e=>n=>r=>{const i=Lt(o=>u=>ut.compare(o.w)(u.w))(z(o=>({l:o,w:lf(o)}))(st(pf()(e)(n),r)));return 0<i.length?w("Just",i[0].l):J},oy=t=>e=>{const n=Tn(Re(z(Ft(i=>o=>b(o,i)))(t))),r=i=>Lt(o=>u=>it.compare((()=>{const s=ot(o)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})())((()=>{const s=ot(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(i);return{preds:(()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return zt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(T(o=>u=>vt(C)(ee)(u.to.node)([u.from.node])(o))(Q)(e))})(),succs:(()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return zt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(T(o=>u=>vt(C)(ee)(u.from.node)([u.to.node])(o))(Q)(e))})(),nodeIndex:n}},uy=t=>e=>{const n=Lt(d=>l=>ut.compare(d.w)(l.w))(Ft(d=>l=>({i:d,l,w:lf(l)}))(e)),r=0<n.length?w("Just",n[0]):J,i=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;g()})(),o=i>=0&&i<e.length?w("Just",e[i]):J,u=(()=>{if(o.tag==="Just")return(d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const x=_,y=h;if(y.tag==="Nil"){p=!1,m=x;continue}if(y.tag==="Cons"){_=on(x)(y._1),h=y._2;continue}g()}return m})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,qt("Cons",l._4,d(l._6,_)));g()};return d(o._1,Ht)})());if(o.tag==="Nothing")return 0;g()})(),s=d=>T(l=>_=>Jn(l)((()=>{const h=ot(_._1)(t);if(h.tag==="Nothing")return _._2+1;if(h.tag==="Just")return _._2+h._1._1;g()})()))(-999999)($s(d)),a=i>=0&&i<e.length?w("Just",e[i]):J,c=(()=>{if(a.tag==="Just")return s(a._1);if(a.tag==="Nothing")return 0;g()})(),f=we(d=>l=>{const _=h=>{if(h.tag==="Leaf")return Q;if(h.tag==="Node")return zt("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));g()};return _(d)},e,Ft(d=>l=>Zn(d)(2)===0?u-(_=>h=>{let p=_,m=h,x=!0,y;for(;x;){const N=p,v=m;if(v.tag==="Nil"){x=!1,y=N;continue}if(v.tag==="Cons"){p=on(N)(v._1),m=v._2;continue}g()}return y})(999999)((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,qt("Cons",h._4,_(h._6,p)));g()};return _(l,Ht)})()):c-s(l))(e));return Zx(T(d=>l=>{const _=Lt(ut.compare)(yt(ot(l))(f));return j(C)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(Q)(Sr(C.compare)(Re(z(d=>{const l=_=>{if(_.tag==="Leaf")return Q;if(_.tag==="Node")return zt("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));g()};return Ct(qe.foldr,l(d))})(f)))))},sy=t=>e=>n=>r=>i=>o=>{const u=oy(e)(i),s=ey(u)(e),a={nodeGap:t.nodeGap*4|0},c=Ee(C.compare,ke,Tn(z(_=>b(_,b(1,1)))(st(nf,Re(e)))),(()=>{const _=h=>{if(h.tag==="Leaf")return Q;if(h.tag==="Node")return zt("Node",h._1,h._2,h._3,b(h._4._1*rt(4),h._4._2),_(h._5),_(h._6));g()};return _(n)})()),f=[Yo(a)(u)(e)(c)(r)(i)(o)(s)(cf)(ff),Yo(a)(u)(e)(c)(r)(i)(o)(s)(gf)(ff),Yo(a)(u)(e)(c)(r)(i)(o)(s)(cf)(_f),Yo(a)(u)(e)(c)(r)(i)(o)(s)(gf)(_f)],d=uy(c)(f);if(pf()(e)(c)(d))return d;const l=iy()(e)(c)(f);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return f[0];g()},ay=t=>e=>n=>r=>{const i=Xa(J,Ba,o=>o.node===e?w("Just",o.position):J,t);if(i.tag==="Nothing")return t;if(i.tag==="Just"){const o=i._1;return z(u=>u.node===n?{...u,position:b(o._1+r._1,o._2+r._2)}:u)(t)}g()},cy=t=>e=>n=>r=>{const i=st(u=>We(_n)(u.node)(e),t),o=(()=>{if(n==="Vertical"){if(r==="Start")return T(u=>s=>on(u)(s.position._1))(99999)(i);if(r==="End")return T(u=>s=>Jn(u)(s.position._1))(0)(i);if(r==="Center"){const u=T(s=>a=>s+a.position._1)(0)(i);return i.length===0?0:u/rt(i.length)}g()}if(n==="Horizontal"){if(r==="Start")return T(u=>s=>on(u)(s.position._2))(99999)(i);if(r==="End")return T(u=>s=>Jn(u)(s.position._2))(0)(i);if(r==="Center"){const u=T(s=>a=>s+a.position._2)(0)(i);return i.length===0?0:u/rt(i.length)}}g()})();return z(u=>{if(We(_n)(u.node)(e)){if(n==="Vertical")return{...u,position:b(o,u.position._2)};if(n==="Horizontal")return{...u,position:b(u.position._1,o)};g()}return u})(t)},gy=t=>e=>T(n=>r=>r.tag==="AlignGroup"?cy(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?ay(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),fy=t=>e=>n=>r=>i=>o=>u=>s=>{const a=z(d=>T(l=>_=>Jn(l)((()=>{const h=ot(_)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;g()})()))(1)(d))(n),c=sy(t)(n)(r)(i)(o)(s),f=hf(ry(t)(n)(r)(i)(o)(u)(d=>{const l=hf(d)(a);return Re(Ft(_=>h=>Ft(p=>m=>({node:m,position:b((()=>{const x=ot(m)(c);return(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})()/rt(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const x=me(3)(m)==="$d:"?b(0,1):b(1,1),y=ot(m)(r);if(y.tag==="Nothing")return x;if(y.tag==="Just")return y._1;g()})(),layer:_,order:p}))(h))(n))}))(a);return gy(e)(Re(Ft(d=>l=>Ft(_=>h=>({node:h,position:b((()=>{const p=ot(h)(c);return(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})()/rt(4)})(),d>=0&&d<f.length?f[d]:0),size:(()=>{const p=me(3)(h)==="$d:"?b(0,1):b(1,1),m=ot(h)(r);if(m.tag==="Nothing")return p;if(m.tag==="Just")return m._1;g()})(),layer:d,order:_}))(l))(n)))},Xs=Zu(mo)(hr(32)),mf=Zu(mo)(hr(31)),Ri=(()=>{const t=bl("25214903917");if(t.tag==="Nothing")return lc;if(t.tag==="Just")return t._1;g()})(),Bi=Uu(Zu(mo)(hr(48)))(mo),_y=t=>{const e=kl(t);return xi(hc((()=>{if(e.tag==="Nothing")return lc;if(e.tag==="Just")return e._1;g()})())(Ri))(Bi)},Ys=hr(11),Vo=t=>e=>{const n=xi(ho(po(e)(Ri))(Ys))(Bi);return b((()=>{const r=nc(Jl(Ku(n)(hr(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},dy=t=>{const e=Vo(26)(t),n=Vo(27)(e._2);return b((rt(e._1)*Iu(2)(27)+rt(n._1))/Iu(2)(53),n._2)},ly=t=>e=>{const n=T(r=>i=>{const o=dy(r.finalR);return{rs:[...r.rs,o._1],finalR:o._2}})({rs:[],finalR:t})(e);return b(z(r=>r.x)(Lt(r=>i=>ut.compare(r.k)(i.k))(we(r=>i=>({x:r,k:i}),e,n.rs))),n.finalR)},hy=t=>{const e=xi(ho(po(t)(Ri))(Ys))(Bi),n=xi(ho(po(e)(Ri))(Ys))(Bi);return b(ho(po((()=>{const r=Ku(e)(hr(16));return pc.compare(r)(mf)!=="LT"?Uu(r)(Xs):r})())(Xs))((()=>{const r=Ku(n)(hr(16));return pc.compare(r)(mf)!=="LT"?Uu(r)(Xs):r})()),n)},Wi=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Uo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Vs=jt(C)(Wt),Vr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Zo=jt(C)(Wt),py=Gu(ai),my=T(Pr)(0),xy=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},xf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},yy=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const i=Yn(Xt,J,t,n[e],n);if(i.tag==="Just")return Yn(Xt,J,e,r,i._1);if(i.tag==="Nothing")return J;g()}}return J},Ny=t=>e=>n=>r=>i=>Vs(T(o=>u=>{const s=Lt(a=>c=>it.compare((()=>{const f=Wi(a.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})())((()=>{const f=Wi(c.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})()))(st(a=>Uo(a.to.node)(n),st(a=>a.from.node===u,r)));return{ranks:[...o.ranks,...Ft(a=>c=>b(c.id,rt((o.rankSum+a|0)+1|0)))(s)],rankSum:o.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),Jy=t=>e=>n=>r=>i=>Vs(T(o=>u=>{const s=Lt(c=>f=>{const d=it.compare((()=>{const l=Vr(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=Vr(c.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})());return d==="EQ"?it.compare((()=>{const l=Wi(c.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})())((()=>{const l=Wi(f.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})()):d})(st(c=>Uo(c.from.node)(n),st(c=>c.to.node===u,r))),a=s.length;return{ranks:[...o.ranks,...Ft(c=>f=>b(f.id,rt((o.rankSum+a|0)-c|0)))(s)],rankSum:o.rankSum+a|0}})({ranks:[],rankSum:0})(t).ranks),Us=t=>e=>n=>{const r=Zo(Ft(s=>a=>b(a,s))(t)),i=Zo(Ft(s=>a=>b(a,s))(e)),o=yt(s=>{const a=Vr(s.from.node)(r),c=Vr(s.to.node)(i);if(a.tag==="Just"&&c.tag==="Just")return w("Just",b(a._1,c._1));const f=Vr(s.from.node)(i),d=Vr(s.to.node)(r);return f.tag==="Just"&&d.tag==="Just"?w("Just",b(d._1,f._1)):J})(n),u=o.length;return T(s=>a=>T(c=>f=>a>=0&&a<o.length&&f>=0&&f<o.length&&((o[a]._1-o[f]._1|0)*(o[a]._2-o[f]._2|0)|0)<0?c+1|0:c)(s)(Dt(a+1|0,u-1|0)))(0)(Dt(0,u-2|0))},Ty=t=>e=>n=>r=>{const i=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l>=(d.length-1|0)){c=!1,f=d;continue}if(l>=0&&l<d.length){const _=l+1|0;if(_>=0&&_<d.length){const h=d[l],p=d[_];if(Be(N=>N.before===h&&N.after===p,r)){s=d,a=l+1|0;continue}const m=Yn(Xt,J,l,p,d),x=(()=>{if(m.tag==="Just")return Yn(Xt,J,l+1|0,h,m._1);if(m.tag==="Nothing")return J;g()})(),y=(()=>{if(x.tag==="Nothing")return d;if(x.tag==="Just")return x._1;g()})();if(Us(e)(y)(n)<Us(e)(d)(n)){s=y,a=l+1|0;continue}s=d,a=l+1|0;continue}c=!1,f=d;continue}c=!1,f=d}return f};return(o=>{let u=o,s=!0,a;for(;s;){const c=u,f=i(c)(0);if(py(f)(c)){s=!1,a=c;continue}u=f}return a})(t)},Ko=t=>e=>T(n=>r=>{if(r>=0&&r<t.length){const i=t[r],o=r+1|0;if(o>=0&&o<t.length)return n+Us(i)(t[o])(e)|0}return n})(0)(Dt(0,t.length-2|0)),wy=(()=>{const t=e=>{if(e.length<7){const o=u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=_-1|0;if(h>=0&&h<l.length){if(_>=0&&_<l.length&&_>0&&l[h].key>l[_].key){const p=yy(_-1|0)(_)(l);if(p.tag==="Just"){a=p._1,c=_-1|0;continue}if(p.tag==="Nothing"){f=!1,d=l;continue}g()}f=!1,d=l;continue}f=!1,d=l}return d};return T(u=>s=>o(u)(s))(e)(Dt(1,e.length-1|0))}const n=Cn(e.length,2),r=t(bt(0,n,e)),i=t(bt(n,e.length,e));return(o=>u=>s=>{let a=o,c=u,f=s,d=!0,l;for(;d;){const _=a,h=c,p=f;if(h>=0&&h<r.length){if(p>=0&&p<i.length){if(r[h].key>i[p].key){a=Ot(_)(i[p]),c=h,f=p+1|0;continue}a=Ot(_)(r[h]),c=h+1|0,f=p;continue}d=!1,l=[..._,...h<1?r:bt(h,r.length,r)];continue}d=!1,l=[..._,...p<1?i:bt(p,i.length,i)]}return l})([])(0)(0)};return t})(),vy=t=>e=>n=>{const r=yt(c=>c.tag==="OrderConstraint"?w("Just",{before:c._1.before,after:c._1.after}):J)(t.constraints),i=c=>T(f=>d=>{const l=d.after,_=d.before,h=cr(Xt,J,m=>m===_,f),p=cr(Xt,J,m=>m===l,f);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=Ua(Xt,J,h._1,f),x=(()=>{if(m.tag==="Nothing")return f;if(m.tag==="Just")return m._1;g()})(),y=Va(Xt,J,p._1,_,x);if(y.tag==="Nothing")return x;if(y.tag==="Just")return y._1;g()}return f})(c)(r),o=Vs(Ft(c=>f=>b(f.id,c))(n)),u=(c,f,d)=>{const l=c.length;return T(_=>h=>{const p=f?h-1|0:h+1|0,m=p>=0&&p<_._1.length?w("Just",_._1[p]):J;if(m.tag==="Just"){const x=h>=0&&h<_._1.length?w("Just",_._1[h]):J;if(x.tag==="Just"){const y=Zo(Ft(E=>O=>b(O,E))(m._1)),N=Zo(Ft(E=>O=>b(O,E))(x._1)),v=f?Ny(m._1)(y)(N)(n)(o):Jy(m._1)(y)(N)(n)(o),L=T(E=>O=>{const Y=yt(G=>Wi(G.id)(v))(st(f?G=>G.to.node===O._2&&Uo(G.from.node)(y):G=>G.from.node===O._2&&Uo(G.to.node)(y),n));if(Y.length===0)return{...E,items:[...E.items,{n:O._2,key:J,origIdx:O._1}]};const et=Vo(24)(E.r);return{items:[...E.items,{n:O._2,key:w("Just",(my(Y)+(rt(et._1)*4172325152040912e-24-.03500000014901161))/rt(Y.length)),origIdx:O._1}],r:et._2}})({items:[],r:_._2})(Ft(Sn)(x._1)),k=Yn(Xt,J,h,Ty(i(z(E=>E.n)(wy((()=>{const E=L.items,O=Y=>et=>{let G=Y,P=et,V=!0,U;for(;V;){const B=G,R=P;if(B>=0&&B<E.length){if(E[B].key.tag==="Just"){V=!1,U=E[B].key._1;continue}if(E[B].key.tag==="Nothing"){G=B+1|0,P=R;continue}g()}V=!1,U=R}return U};return(Y=>et=>G=>{let P=Y,V=et,U=G,B=!0,R;for(;B;){const M=P,S=V,I=U;if(M>=0&&M<E.length){if(E[M].key.tag==="Just"){P=M+1|0,V=E[M].key._1,U=[...I,{n:E[M].n,key:E[M].key._1,origIdx:E[M].origIdx}];continue}if(E[M].key.tag==="Nothing"){const D=(S+O(M+1|0)(S+1))/2;P=M+1|0,V=D,U=[...I,{n:E[M].n,key:D,origIdx:E[M].origIdx}];continue}g()}B=!1,R=I}return R})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(k.tag==="Just")return b(k._1,L.r);if(k.tag==="Nothing")return b(_._1,_._2);g()}if(x.tag==="Nothing")return b(_._1,_._2);g()}if(m.tag==="Nothing")return b(_._1,_._2);g()})(b(c,d))(f?Dt(1,l-1|0):Te(Dt(0,l-2|0)))},s=T(c=>f=>j(C)(f.from.node)()(j(C)(f.to.node)()(c)))(Q)(n),a=T(c=>f=>{if(c.result.crossings===0)return c;const d=y=>N=>v=>L=>{let k=y,E=N,O=v,Y=L,et=!0,G;for(;et;){const P=k,V=E,U=O,B=Y;if(U===0){et=!1,G={layout:P,crossings:0,random:B};continue}const R=u(P,V,B),M=Ko(R._1)(n);if(M<U){k=R._1,E=!V,O=M,Y=R._2;continue}et=!1,G={layout:P,crossings:U,random:R._2}}return G},l=Vo(1)(c.result.random),_=l._1!==0,h=t.modelOrder.tag==="Leaf",p=(c.firstTry||c.secondTry)&&!h?c.firstTry:_,m=(()=>{if(!h){const L=u(e,p,l._2);return d(L._1)(!p)(Ko(L._1)(n))(L._2)}const y=p?0:xy(0)(e.length-1|0),N=y>=0&&y<e.length?w("Just",e[y]):J;if(N.tag==="Just"&&N._1.length>1){const L=st(k=>xf(k)(s),N._1);if(L.length>1){const k=ly(l._2)(L),E=k._1,O=Yn(Xt,J,y,i(T(Y=>et=>xf(et)(s)?Y.idx>=0&&Y.idx<E.length?{idx:Y.idx+1|0,result:[...Y.result,E[Y.idx]]}:{idx:Y.idx,result:[...Y.result,et]}:{idx:Y.idx,result:[...Y.result,et]})({idx:0,result:[]})(N._1).result),e);if(O.tag==="Just"){const Y=u(O._1,p,k._2);return d(Y._1)(!p)(Ko(Y._1)(n))(Y._2)}}}const v=u(e,p,l._2);return d(v._1)(!p)(Ko(v._1)(n))(v._2)})(),x=c.secondTry?!1:c.secondTry;return c.firstTry?{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:c.firstTry,secondTry:x}})({result:{layout:e,crossings:1e9,random:xi(hc(hy(_y(1))._1)(Ri))(Bi)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Dt(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:a.layout},by=t=>t,yf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Qe=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Ur=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},zi=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=C.compare(e._1)(n._1);return r==="LT"?Ne:r==="GT"?Je:C.compare(e._2)(n._2)},Eq0:()=>t}})(),ky=jt(C)(Wt),Ly=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=zi.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Ey=by("Greedy"),Zs=t=>e=>n=>T(r=>i=>{if(i.from.node===i.to.node)return r;if(i.from.node===e&&!yf(i.to.node)(r.marks)){const o=Qe(i.to.node)(r.inDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;g()})(),s=j(C)(i.to.node)(u)(r.inDeg);return(()=>{const a=Qe(i.to.node)(r.outDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!We(_n)(i.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,i.to.node]}:{...r,inDeg:s}}if(i.to.node===e&&!yf(i.from.node)(r.marks)){const o=Qe(i.from.node)(r.outDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;g()})(),s=j(C)(i.from.node)(u)(r.outDeg);return(()=>{const a=Qe(i.from.node)(r.inDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!We(_n)(i.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,i.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:st(r=>r!==e,n.remaining)})(t),Cy=T(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return j(C)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return j(C)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return j(C)(e._1.node)(99999)(t)}return t})(Q),Nf=t=>e=>n=>{const r=Qe(e)(t),i=Qe(n)(t);return r.tag==="Just"&&i.tag==="Just"&&r._1>i._1},Jf=t=>e=>n=>r=>{if(Ur(n)(r.visited)||Ur(n)(r.visiting))return r;const i=T(Sy(t)(e)(n))({...r,visiting:j(C)(n)()(r.visiting)})((()=>{const o=Qe(n)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})());return{...i,visiting:gi(C)(n)(i.visiting),visited:j(C)(n)()(i.visited)}},Sy=t=>e=>n=>r=>i=>Nf(t)(n)(i)?{...r,backEdges:j(zi)(b(n,i))()(r.backEdges)}:Ur(i)(r.visiting)?{...r,backEdges:j(zi)(b(n,i))()(r.backEdges)}:Ur(i)(r.visited)?r:Jf(t)(e)(i)(r),Gy=t=>e=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,x=At(y=>J,y=>N=>w("Just",{head:y,tail:N}),m.sinks);if(x.tag==="Just"){_=Zs(n)(x._1.head)({...m,sinks:x._1.tail,marks:j(C)(x._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(x.tag==="Nothing"){const y=At(N=>J,N=>v=>w("Just",{head:N,tail:v}),m.sources);if(y.tag==="Just"){_=Zs(n)(y._1.head)({...m,sources:y._1.tail,marks:j(C)(y._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(y.tag==="Nothing"){const N=L=>{const k=Qe(L)(m.outDeg),E=Qe(L)(m.inDeg);return(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;g()})()-(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;g()})()|0},v=Lt(L=>k=>{const E=it.compare(N(k))(N(L));return E==="EQ"?it.compare((()=>{const O=Qe(L)(e);if(O.tag==="Nothing")return 1e6;if(O.tag==="Just")return O._1;g()})())((()=>{const O=Qe(k)(e);if(O.tag==="Nothing")return 1e6;if(O.tag==="Just")return O._1;g()})()):E})(m.remaining);if(0<v.length){const L=v[0];_=Zs(n)(L)({...m,remaining:st(k=>k!==L,m.remaining),marks:j(C)(L)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}g()}return p},i=Sr(C.compare)([...z(l=>l.from.node)(n),...z(l=>l.to.node)(n)]),o=st(l=>l.from.node!==l.to.node,n),u=T(l=>_=>vt(C)(ue)(_.to.node)(1)(l))(Q)(o),s=T(l=>_=>vt(C)(ue)(_.from.node)(1)(l))(Q)(o),a=st(l=>{const _=Qe(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),c=st(l=>{const _=Qe(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),f=i.length+1|0,d=T(l=>_=>{const h=Qe(_)(l);return h.tag==="Just"&&h._1<0?j(C)(_)(h._1+f|0)(l):l})(r({remaining:st(l=>!We(_n)(l)(a)&&!We(_n)(l)(c),i),marks:Q,inDeg:u,outDeg:s,sources:a,sinks:c,nextLeft:1,nextRight:-1}).marks)(i);return T(l=>_=>{if(_.from.node===_.to.node)return l;if(Nf(t)(_.from.node)(_.to.node))return j(zi)(b(_.from.node,_.to.node))()(l);const h=Qe(_.from.node)(d),p=Qe(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?j(zi)(b(_.from.node,_.to.node))()(l):l})(Q)(n)},Py=T(t=>e=>vt(C)(ee)(e.from.node)([e.to.node])(t))(Q),Iy=t=>e=>{const n=Py(e),r=Sr(C.compare)([...z(o=>o.from.node)(e),...z(o=>o.to.node)(e)]),i=T(o=>u=>j(C)(u.to.node)()(o))(Q)(e);return T(o=>u=>Jf(t)(n)(u)(o))({visiting:Q,visited:Q,backEdges:Q})([...st(o=>!Ur(o)(i),r),...st(o=>Ur(o)(i),r)]).backEdges},Dy=t=>e=>n=>r=>{const i=ky(Ft(s=>a=>b(a,s))(e)),o=Cy(n),u=(()=>{if(t==="DepthFirst")return Iy(o)(r);if(t==="Greedy")return Gy(o)(i)(r);g()})();return{edges:z(s=>Ly(b(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},Tf=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Qy=T(t=>e=>j(C)(e)()(t))(Q),jo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Fy=Ag(C),wn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},wf=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ks=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=it.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Ay=jt(it)(Wt),My=t=>e=>Ee(C.compare,ke,t,e),vf=Ft(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),Oy=t=>T(e=>n=>({base:(()=>{const r=i=>o=>{let u=i,s=o,a=!0,c;for(;a;){const f=u,d=s;if(d.tag==="Nil"){a=!1,c=f;continue}if(d.tag==="Cons"){u=Tf(f)(d._1),s=d._2;continue}g()}return c};return(e.base+r(0)((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,qt("Cons",o._4,i(o._6,u)));g()};return i(n,Ht)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=i=>{if(i.tag==="Leaf")return Q;if(i.tag==="Node")return zt("Node",i._1,i._2,i._3,i._4+e.base|0,r(i._5),r(i._6));g()};return r(n)})()]}))({base:0,result:[]})(t).result,Ry=t=>e=>{const n=Qy(t);return Fy(t)(vf(st(r=>jo(r.src)(n)&&jo(r.tgt)(n),e)))},By=t=>e=>{const n=T(i=>o=>vt(C)(ee)(o.tgt)([o.src])(vt(C)(ee)(o.src)([o.tgt])(i)))(Q)(e),r=i=>o=>u=>{let s=i,a=o,c=u,f=!0,d;for(;f;){const l=s,_=a,h=c,p=At(m=>J,m=>x=>w("Just",{head:m,tail:x}),l);if(p.tag==="Nothing"){f=!1,d={nodes:h};continue}if(p.tag==="Just"){if(jo(p._1.head)(_)){s=p._1.tail,a=_,c=h;continue}s=[...p._1.tail,...(()=>{const m=wn(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()})()],a=j(C)(p._1.head)()(_),c=[...h,p._1.head];continue}g()}return d};return T(i=>o=>{if(jo(o)(i.visited))return i;const u=r([o])(i.visited)([]);return{...i,visited:T(s=>a=>j(C)(a)()(s))(i.visited)(u.nodes),components:[...i.components,u.nodes]}})({visited:Q,components:[]})(t).components},Wy=t=>e=>n=>{const r=T(o=>u=>vt(C)(ue)(u.tgt)(1)(o))(Q)(e),i=T(o=>u=>vt(C)(ue)(u.src)(1)(o))(Q)(e);return T(o=>u=>{const s=wn(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})();if((()=>{const y=wn(u)(i);return(()=>{if(y.tag==="Nothing")return a!==0;if(y.tag==="Just")return a!==y._1;g()})()||a===0})())return o;const c=wn(u)(o.layers),f=(()=>{if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1;g()})(),d=o.layers,l=T(y=>N=>N.tgt===u?{...y,mIn:wf(y.mIn)((()=>{const v=wn(u)(d),L=wn(N.src)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})()-(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;g()})()|0})())}:N.src===u?{...y,mOut:wf(y.mOut)((()=>{const v=wn(N.tgt)(d),L=wn(u)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})()-(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;g()})()|0})())}:y)({mIn:1e9,mOut:1e9})(e),_=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(_<0||h<0)return o;const p=(f-_|0)+1|0,m=(f+h|0)-1|0;if(m<p)return o;const x=T(y=>N=>{const v=Ks(N)(o.filling),L=(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})();return L<y.bestFill?{best:N,bestFill:L}:y})({best:f,bestFill:(()=>{const y=Ks(f)(o.filling);if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;g()})()})(Dt(p,m));return x.best===f?o:{layers:j(C)(u)(x.best)(o.layers),filling:j(it)(f)((()=>{const y=Ks(f)(o.filling);if(y.tag==="Nothing")return-1;if(y.tag==="Just")return y._1-1|0;g()})())(j(it)(x.best)(x.bestFill+1|0)(o.filling))}})({layers:n,filling:Ay(z(o=>b(o,T(u=>s=>(()=>{const a=wn(s)(n);return a.tag==="Nothing"?!1:a.tag==="Just"&&a._1===o})()?u+1|0:u)(0)(t)))(Dt(0,T(o=>u=>Tf(o)((()=>{const s=wn(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(0)(t))))})(t).layers},zy=t=>e=>Wy(t)(vf(e))(T(My)(Q)(Oy(z(n=>Ry(n)(e))(By(t)(e))))),qy=t=>t,Nr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},tu=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bf=(()=>{const t=Xe.unfoldr(mn);return e=>t(Ye("IterNode",e,pn))})(),Hy=qy("NetworkSimplex"),$y=t=>e=>T(n=>r=>{const i=T(tu)(0)(yt(o=>Nr(o)(n))(r));return T(o=>u=>j(C)(u)(i)(o))(n)(r)})(e)(t),Xy=t=>e=>({layers:z(n=>st(r=>{const i=Nr(r)(e);return i.tag==="Nothing"?!1:i.tag==="Just"&&i._1===n},t))(Dt(0,(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(c.tag==="Nil"){u=!1,s=a;continue}if(c.tag==="Cons"){i=tu(a)(c._1),o=c._2;continue}g()}return s})(0)((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return n(e,Ht)})()))),nodeLayer:e}),Yy=t=>e=>n=>{const r=T(i=>o=>j(C)(o)(!0)(i))(Q)(e);return T(i=>o=>j(C)(o._1)(o._2)(i))(zy(e)(yt(i=>i.from.node===i.to.node||(()=>{const o=Nr(i.from.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()||(()=>{const o=Nr(i.to.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()?J:w("Just",{src:i.from.node,tgt:i.to.node}))(t)))(bf(n))},Vy=t=>e=>n=>r=>{const i=s=>a=>{const c=Nr(a)(s);if(c.tag==="Just")return s;if(c.tag==="Nothing"){const f=st(l=>l!==a,(()=>{const l=Nr(a)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;g()})()),d=T(i)(s)(f);return j(C)(a)(1+T(tu)(0)(yt(l=>Nr(l)(d))(f))|0)(d)}g()},o=T(i)(Q)(n),u=(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=tu(_)(h._1),f=h._2;continue}g()}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)));g()};return s(o,Ht)})());return T(s=>a=>j(C)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return Q;if(a.tag==="Node")return zt("Node",a._1,a._2,a._3,u-a._4|0,s(a._5),s(a._6));g()};return s(o)})())(bf(r))},Uy=T(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return j(C)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return j(C)(e._1.node)(0)(t)}return t})(Q),Zy=T(t=>e=>vt(C)(ee)(e.to.node)([e.from.node])(t))(Q),Ky=T(t=>e=>vt(C)(ee)(e.from.node)([e.to.node])(t))(Q),jy=t=>e=>n=>r=>{const i=Ky(n),o=Zy(n),u=Uy(e);return Xy(r)($y(yt(s=>s.tag==="SameLayer"?w("Just",s._1.nodes):J)(e))((()=>{if(t==="LongestPath")return Vy(i)(o)(r)(u);if(t==="NetworkSimplex")return Yy(n)(r)(u);g()})()))},t2=jt(C)(Wt),e2=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},kf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Lf=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},qi=jt(C)(Wt),n2=jt(C)(Wt),Ef=(()=>{const t=z(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>Te(t(e))})(),r2=t=>e=>n=>r=>{const i=t2(z(u=>b(u.edge,u))(r)),o=u=>0<u.nodes.length&&(()=>{const s=e2(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return z(u=>{if(u.nodes.length<=2){const f=kf(u.edgeId)(i);if(f.tag==="Just"){const d=o(u),l=Fi(Qi(d?Ef(f._1.segments):f._1.segments));return{...f._1,edge:u.edgeId,segments:l,bends:we(_=>h=>_.end,l,bt(1,l.length,l)),reversed:d}}if(f.tag==="Nothing")return{edge:u.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};g()}const s=Tt(yt(f=>kf(f)(i))(we(f=>d=>u.edgeId+":"+f+"->"+d,u.nodes,bt(1,u.nodes.length,u.nodes))))(f=>f.segments),a=o(u),c=Fi(Qi(a?Ef(s):s));return{edge:u.edgeId,segments:c,bends:we(f=>d=>f.end,c,bt(1,c.length,c)),bendType:[],jumps:[],reversed:a}})(t)},i2={layers:[],edges:[],chains:[]},o2={nodeGap:3,layerGap:2,iterations:8,layerer:Hy,cycleBreaker:Ey,compactPostRouting:!0,compactionSpacings:Zm},u2=t=>({pos:b(0,0),size:b(T(e=>n=>Lf(e)(n.position._1+n.size._1))(0)(t),T(e=>n=>Lf(e)(n.position._2+n.size._2))(0)(t))}),s2=t=>e=>n=>{const r=qi(z(c=>b(c.id,c.ports))(e.nodes)),i=st(c=>me(3)(c.node)!=="$d:",n.placements),o=r2(n.withDummies.chains)(n.acyclic.reversedEdges)(n2(z(c=>b(c.id,b(c.from.node,c.to.node)))(e.edges)))(Px(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(of(n.ordered)(st(c=>c.from.node!==c.to.node,n.withDummies.edges))((()=>{const c=f=>{if(f.tag==="Leaf")return Q;if(f.tag==="Node")return zt("Node",f._1,f._2,f._3,b(f._4._1*4,f._4._2),c(f._5),c(f._6));g()};return c(qi(z(f=>b(f.id,f.size))(e.nodes)))})()))),u=t.compactPostRouting?tx()(t.compactionSpacings)({nodes:i,edges:e.edges,paths:o,ports:r}):{nodes:i,edges:o},s=z(c=>{const f=Fi(Qi(c.segments));return{...c,segments:f,bends:we(d=>l=>d.end,f,bt(1,f.length,f))}})(u.edges),a=Ft(c=>f=>({...f,jumps:Ox(c)(f)(s)}))(s);return{nodes:u.nodes,edges:a,boundingBox:u2(u.nodes),metrics:kp(u.nodes)(a)(0)}},a2=t=>e=>n=>{const r=qi(z(o=>b(o.id,o.size))(e.nodes)),i={...n,placements:fy({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(qi(z(o=>b(o.id,o.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(of(n.ordered)(n.withDummies.edges)((()=>{const o=u=>{if(u.tag==="Leaf")return Q;if(u.tag==="Node")return zt("Node",u._1,u._2,u._3,b(u._4._1*4,u._4._2),o(u._5),o(u._6));g()};return o(r)})()))};return{pipeline:i,result:s2(t)(e)(i)}},c2=t=>e=>n=>a2(t)(e)({...n,ordered:vy({iterations:t.iterations,constraints:e.constraints,modelOrder:qi(Ft(r=>i=>b(i.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),g2=t=>e=>n=>c2(t)(e)({...n,withDummies:Rx(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),f2=t=>e=>{const n=z(i=>i.id)(e.nodes),r=Dy(t.cycleBreaker)(n)(e.constraints)(e.edges);return g2(t)(e)({acyclic:r,layered:jy(t.layerer)(e.constraints)(r.edges)(n),withDummies:i2,ordered:[],placements:[]})},eu=t=>t,_2=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Jr=eu("TopSide"),Tr=eu("BottomSide"),wr=eu("LeftSide"),vr=eu("RightSide"),d2=t=>{const e=ut.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ut.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Cf=t=>e=>n=>{const r=_2(t.h*.12)(t.w*.2),i=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*Le(d2((()=>{const o=(n-(t.x+i))/i;return 1-o*o})()))},Fe=t=>e=>n=>r=>{let i=t,o=e,u=n,s=r,a=!0,c;for(;a;){const f=i,d=o,l=u,_=s;if(f==="Rectangle"){if(l==="TopSide"){a=!1,c=d.y;continue}if(l==="BottomSide"){a=!1,c=d.y+d.h;continue}if(l==="LeftSide"){a=!1,c=d.x;continue}if(l==="RightSide"){a=!1,c=d.x+d.w;continue}i=tr,o=d,u=l,s=_;continue}if(f==="Cylinder"){if(l==="TopSide"){a=!1,c=Cf(d)(-1)(_);continue}if(l==="BottomSide"){a=!1,c=Cf(d)(1)(_);continue}if(l==="LeftSide"){a=!1,c=d.x;continue}if(l==="RightSide"){a=!1,c=d.x+d.w;continue}}i=tr,o=d,u=l,s=_}return c},Sf=t=>e=>{const n=e.y-t.y,r=n<0?-n:n,i=e.x-(t.x+t.w),o=i<0?-i:i,u=e.x-t.x,s=u<0?-u:u,a=e.y-(t.y+t.h),c=a<0?-a:a;return r<=c&&r<=s&&r<=o?Jr:c<=s&&c<=o?Tr:s<=o?wr:vr},l2=(()=>{const t=Xe.unfoldr(mn);return e=>t(Ye("IterNode",e,pn))})(),js=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Hi=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},$i=jt(C)(Wt),h2=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},p2=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},m2=T(t=>e=>j(C)(e)()(t))(Q),x2=T(t=>e=>j(C)(e)()(t))(Q),nu=ar.traverse(Eu),ru=jt(C)(Wt),y2=t=>e=>Ee(C.compare,ke,t,e),N2=T(t=>e=>j(C)(e)()(t))(Q),J2=jt(C)(Wt),T2=t=>e=>Ee(C.compare,ke,t,e),w2=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Gf=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},v2=t=>e=>({...e,edges:$i(z(n=>b(n._1,(()=>{const r=js(n._1)(t);if(r.tag==="Nothing")return n._2;if(r.tag==="Just"){const i=Hi(r._1._2)(e.nodes),o=Hi(r._1._1)(e.nodes),u=(()=>{if(o.tag==="Nothing")return n._2;if(o.tag==="Just"){const s=At(a=>J,a=>c=>w("Just",{head:a,tail:c}),n._2);if(s.tag==="Nothing")return n._2;if(s.tag==="Just")return[(()=>{const a=At(l=>J,l=>_=>w("Just",{head:l,tail:_}),s._1.tail),c=a.tag==="Just"?w("Just",a._1.head):J,f={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},d=(()=>{if(c.tag==="Just"){if((c._1.x>s._1.head.x?c._1.x-s._1.head.x<.5:s._1.head.x-c._1.x<.5)&&s._1.head.x>=f.x-.5&&s._1.head.x<=f.x+f.w+.5)return c._1.y>=f.y+f.h?w("Just",Tr):c._1.y<=f.y?w("Just",Jr):J;if((c._1.y>s._1.head.y?c._1.y-s._1.head.y<.5:s._1.head.y-c._1.y<.5)&&s._1.head.y>=f.y-.5&&s._1.head.y<=f.y+f.h+.5){if(c._1.x>=f.x+f.w)return w("Just",vr);if(c._1.x<=f.x)return w("Just",wr)}return J}if(c.tag==="Nothing")return J;g()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...s._1.head,y:Fe(o._1.shape)(f)(Jr)(s._1.head.x)};if(d._1==="BottomSide")return{...s._1.head,y:Fe(o._1.shape)(f)(Tr)(s._1.head.x)};if(d._1==="LeftSide")return{...s._1.head,x:Fe(o._1.shape)(f)(wr)(s._1.head.y)};if(d._1==="RightSide")return{...s._1.head,x:Fe(o._1.shape)(f)(vr)(s._1.head.y)};g()}if(d.tag==="Nothing"){const l={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},_=Sf(l)(s._1.head);if(_==="TopSide")return{...s._1.head,y:Fe(o._1.shape)(l)(Jr)(s._1.head.x)};if(_==="BottomSide")return{...s._1.head,y:Fe(o._1.shape)(l)(Tr)(s._1.head.x)};if(_==="LeftSide")return{...s._1.head,x:Fe(o._1.shape)(l)(wr)(s._1.head.y)};if(_==="RightSide")return{...s._1.head,x:Fe(o._1.shape)(l)(vr)(s._1.head.y)}}g()})(),...s._1.tail]}g()})();if(i.tag==="Nothing")return u;if(i.tag==="Just"){const s=Cr(u);if(s.tag==="Nothing")return u;if(s.tag==="Just")return Ot(s._1.init)((()=>{const a=Cr(s._1.init),c=a.tag==="Just"?w("Just",a._1.last):J,f={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},d=(()=>{if(c.tag==="Just"){if((c._1.x>s._1.last.x?c._1.x-s._1.last.x<.5:s._1.last.x-c._1.x<.5)&&s._1.last.x>=f.x-.5&&s._1.last.x<=f.x+f.w+.5)return c._1.y>=f.y+f.h?w("Just",Tr):c._1.y<=f.y?w("Just",Jr):J;if((c._1.y>s._1.last.y?c._1.y-s._1.last.y<.5:s._1.last.y-c._1.y<.5)&&s._1.last.y>=f.y-.5&&s._1.last.y<=f.y+f.h+.5){if(c._1.x>=f.x+f.w)return w("Just",vr);if(c._1.x<=f.x)return w("Just",wr)}return J}if(c.tag==="Nothing")return J;g()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...s._1.last,y:Fe(i._1.shape)(f)(Jr)(s._1.last.x)};if(d._1==="BottomSide")return{...s._1.last,y:Fe(i._1.shape)(f)(Tr)(s._1.last.x)};if(d._1==="LeftSide")return{...s._1.last,x:Fe(i._1.shape)(f)(wr)(s._1.last.y)};if(d._1==="RightSide")return{...s._1.last,x:Fe(i._1.shape)(f)(vr)(s._1.last.y)};g()}if(d.tag==="Nothing"){const l={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},_=Sf(l)(s._1.last);if(_==="TopSide")return{...s._1.last,y:Fe(i._1.shape)(l)(Jr)(s._1.last.x)};if(_==="BottomSide")return{...s._1.last,y:Fe(i._1.shape)(l)(Tr)(s._1.last.x)};if(_==="LeftSide")return{...s._1.last,x:Fe(i._1.shape)(l)(wr)(s._1.last.y)};if(_==="RightSide")return{...s._1.last,x:Fe(i._1.shape)(l)(vr)(s._1.last.y)}}g()})())}}g()})()))(l2(e.edges)))}),b2=t=>e=>n=>{const r=Vt(i=>i.id===n)(t.graph.edges);if(r.tag==="Just")return w("Just",r._1);if(r.tag==="Nothing")return js(n)(e);g()},k2=t=>e=>n=>r=>({x:r.position._1*t,y:r.position._2*t,w:r.size._1*t,h:r.size._2*t,label:(()=>{const i=Hi(r.node)(e);if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return r.node;g()})(),shape:(()=>{const i=Hi(r.node)(n);if(i.tag==="Nothing")return tr;if(i.tag==="Just")return i._1;g()})()}),L2=t=>({id:t,size:b(1,1),ports:[],label:w("Just",t),shape:tr}),E2=t=>e=>n=>r=>b(r.node,k2(t)(e)(n)(r)),Pf=t=>{const e=To(`
6
- `)(t);return e.length===0?[""]:e},If=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,qt("Cons",n._4,e(n._6,r)));g()};return Ct($t.foldr,e(t.interiors,Ht))},C2=t=>$i(yt(e=>w("Just",b(e.edge,{id:e.edge,from:{node:e.from,port:J},to:{node:e.to,port:J},label:J})))(Tt(t.scenes)(e=>e.tag==="DataFlow"?yt(n=>n.kind.tag==="SendToken"?w("Just",n.kind._1):J)(e._1.events):[]))),Df=t=>{const e=Hl(t),n=st(i=>h2(i.id)(e.nodes),t.graph.nodes),r=st(i=>p2(i.id)(e.edges),t.graph.edges);return{nodes:[...n,...z(L2)(Ct(qe.foldr,Gn(C.compare,e.nodes,m2(z(i=>i.id)(n)))))],edges:[...r,...yt(b2(t)(C2(t)))(Ct(qe.foldr,Gn(C.compare,e.edges,x2(z(i=>i.id)(r)))))],constraints:t.graph.constraints}},S2=t=>{const e=nu(n=>{const r=_g(dg)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})());return()=>{const i=r();return b(n.id,i)}})(Df(t).nodes);return()=>{const n=e();return ru(n)}},Qf=t=>{const e=S2(t);return()=>{const n=e(),r=nu(Qf)(If(t))();return T(y2)(n)(r)}},G2=t=>e=>{const n=At(r=>J,r=>i=>w("Just",{head:r,tail:i}),e.segments);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{x:n._1.head.start._1*t,y:n._1.head.start._2*t},...z(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];g()},P2=t=>e=>b(e.edge,G2(t)(e)),I2=t=>e=>n=>r=>({nodes:ru(z(E2(rt(4)*t)(e)(n))(r.nodes)),edges:$i(z(P2(t))(r.edges)),chipExtras:Q,edgeLabels:Q}),D2=t=>T(e=>n=>{if(n.tag==="Structural")return e;if(n.tag==="DataFlow")return T(r=>i=>{if(i.kind.tag==="SendToken")return T(o=>u=>j(C)(u)()(o))(r)(i.kind._1.labels);if(i.kind.tag==="FillNodeWithoutTransition")return T(o=>u=>j(C)(u)()(o))(r)(i.kind._1.labels);g()})(e)(n._1.events);if(n.tag==="Hold"||n.tag==="EnterNode"||n.tag==="ExitNode")return e;g()})(Q)(t.scenes),Q2=t=>{const e=nu(n=>{const r=_g(dg)(n);return()=>{const i=r();return b(n,{labelW:i,charCount:jn(Wr(n)),lineCount:1})}})(Ct(qe.foldr,N2(Tt(Ct(qe.foldr,D2(t)))(Pf))));return()=>{const n=e();return J2(n)}},Ff=t=>{const e=Q2(t);return()=>{const n=e(),r=nu(Ff)(If(t))();return T(T2)(n)(r)}},F2=rt(4)*8,A2=t=>e=>{const n=wp(F2)(t)(Tp(Jp)(Df(e)));return{...v2($i(z(r=>b(r.id,b(r.from.node,r.to.node)))(n.edges)))(I2(8)(ru(z(r=>b(r.id,(()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;g()})()))(n.nodes)))(ru(z(r=>b(r.id,r.shape))(n.nodes)))(f2(o2)(n).result)),edgeLabels:$i(yt(r=>r.label.tag==="Just"?w("Just",b(r.id,r.label._1)):J)(n.edges))}},M2=t=>Tt(t.scenes)(e=>{if(e.tag==="Structural")return[];if(e.tag==="DataFlow")return e._1.events;if(e.tag==="Hold")return[];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()}),O2=t=>e=>n=>{const r=i=>{const o=yt(u=>{const s=w2(u)(t);return s.tag==="Just"?w("Just",{w:s._1.labelW+28,h:rt(pp(1)(s._1.lineCount))*13.2+12}):J})(Tt(i)(Pf));return o.length===0?J:w("Just",{w:T(Gf)(0)(z(u=>u.w)(o)),h:T(Gf)(0)(z(u=>u.h)(o))})};return T(i=>o=>{if(o.kind.tag==="SendToken"){const u=js(o.kind._1.edge)(n.edges),s=r(o.kind._1.labels);if(s.tag==="Just"&&u.tag==="Just"){const a=s._1;return vt(C)(ee)(o.kind._1.edge)(z(c=>({x:c.x+14+a.w,y:c.y-6-8-a.h}))(u._1))(i)}return i}if(o.kind.tag==="FillNodeWithoutTransition"){const u=Hi(o.kind._1.node)(n.nodes),s=r(o.kind._1.labels);return s.tag==="Just"&&u.tag==="Just"?vt(C)(ee)("__fill__:"+o.kind._1.node)((()=>{const a=u._1.y-s._1.h-14,c=u._1.x+u._1.w/2,f=c-s._1.w/2,d=c+s._1.w/2,l=u._1.y-14;return[{x:f,y:a},{x:d,y:a},{x:f,y:l},{x:d,y:l}]})())(i):i}g()})(Q)(M2(e))},Af=t=>e=>n=>({layout:(()=>{const r=A2(t)(n);return{...r,chipExtras:O2(e)(n)(r)}})(),interiors:(()=>{const r=Af(t)(e),i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return zt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(n.interiors)})()}),Mf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},ta=t=>e=>n=>{const r=t<.05?t:.05,i=(u,s)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return i((()=>{const a=Mf(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};g()})(),f=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 j(C)(s._3)({x:c.x+f*r,y:c.y+d*r,vx:f,vy:d})(i(u,s._5))})(),s._6);g()},o=i(Q,e);return{springs:o,applied:(()=>{const u=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return u((()=>{const c=u(s,a._5),f=Mf(a._3)(o);if(f.tag==="Just")return j(C)(a._3)({...a._4,x:f._1.x,y:f._1.y})(c);if(f.tag==="Nothing")return j(C)(a._3)(a._4)(c);g()})(),a._6);g()};return u(Q,e)})()}};(function(){var t={},e="Pure",n="Throw",r="Catch",i="Sync",o="Async",u="Bind",s="Bracket",a="Fork",c="Sequential",f="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",x="Finalized",y="Forked";function N(A,H,$,X){this.tag=A,this._1=H,this._2=$,this._3=X}function v(A){var H=function($,X,q){return new N(A,$,X,q)};return H.tag=A,H}function L(A){return new N(e,void 0)}function k(A){try{A()}catch(H){setTimeout(function(){throw H},0)}}function E(A,H,$){try{return H($())}catch(X){return A(X)}}function O(A,H,$){try{return H($)()}catch(X){return $(A(X))(),L}}var Y=(function(){var A=1024,H=0,$=0,X=new Array(A),q=!1;function W(){var tt;for(q=!0;H!==0;)H--,tt=X[$],X[$]=void 0,$=($+1)%A,tt();q=!1}return{isDraining:function(){return q},enqueue:function(tt){var Z;H===A&&(Z=q,W(),q=Z),X[($+H)%A]=tt,H++,q||W()}}})();function et(A){var H={},$=0,X=0;return{register:function(q){var W=$++;q.onComplete({rethrow:!0,handler:function(tt){return function(){X--,delete H[W]}}})(),H[W]=q,X++},isEmpty:function(){return X===0},killAll:function(q,W){return function(){if(X===0)return W();var tt=0,Z={};function ct(at){Z[at]=H[at].kill(q,function(xt){return function(){delete Z[at],tt--,A.isLeft(xt)&&A.fromLeft(xt)&&setTimeout(function(){throw A.fromLeft(xt)},0),tt===0&&W()}})()}for(var ft in H)H.hasOwnProperty(ft)&&(tt++,ct(ft));return H={},$=0,X=0,function(at){return new N(i,function(){for(var xt in Z)Z.hasOwnProperty(xt)&&Z[xt]()})}}}}}var G=0,P=1,V=2,U=3,B=4,R=5,M=6;function S(A,H,$){var X=0,q=G,W=$,tt=null,Z=null,ct=null,ft=null,at=null,xt=0,St=0,Rt=null,pt=!0;function Bt(K){for(var nt,ht,_t;;)switch(nt=null,ht=null,_t=null,q){case V:q=P;try{W=ct(W),ft===null?ct=null:(ct=ft._1,ft=ft._2)}catch(wt){q=R,tt=A.left(wt),W=null}break;case U:A.isLeft(W)?(q=R,tt=W,W=null):ct===null?q=R:(q=V,W=A.fromRight(W));break;case P:switch(W.tag){case u:ct&&(ft=new N(_,ct,ft)),ct=W._2,q=P,W=W._1;break;case e:ct===null?(q=R,W=A.right(W._1)):(q=V,W=W._1);break;case i:q=U,W=E(A.left,A.right,W._1);break;case o:q=B,W=O(A.left,W._1,function(wt){return function(){X===K&&(X++,Y.enqueue(function(){X===K+1&&(q=U,W=wt,Bt(X))}))}});return;case n:q=R,tt=A.left(W._1),W=null;break;case r:ct===null?at=new N(_,W,at,Z):at=new N(_,W,new N(_,new N(h,ct,ft),at,Z),Z),ct=null,ft=null,q=P,W=W._1;break;case s:xt++,ct===null?at=new N(_,W,at,Z):at=new N(_,W,new N(_,new N(h,ct,ft),at,Z),Z),ct=null,ft=null,q=P,W=W._1;break;case a:q=U,nt=S(A,H,W._2),H&&H.register(nt),W._1&&nt.run(),W=A.right(nt);break;case c:q=P,W=D(A,H,W._1);break}break;case R:if(ct=null,ft=null,at===null)q=M,W=Z||tt||W;else switch(nt=at._3,_t=at._1,at=at._2,_t.tag){case r:Z&&Z!==nt&&xt===0?q=R:tt&&(q=P,W=_t._2(A.fromLeft(tt)),tt=null);break;case h:Z&&Z!==nt&&xt===0||tt?q=R:(ct=_t._1,ft=_t._2,q=V,W=A.fromRight(W));break;case s:xt--,tt===null&&(ht=A.fromRight(W),at=new N(_,new N(p,_t._2,ht),at,nt),(Z===nt||xt>0)&&(q=P,W=_t._3(ht)));break;case p:at=new N(_,new N(x,W,tt),at,Z),q=P,Z&&Z!==nt&&xt===0?W=_t._1.killed(A.fromLeft(Z))(_t._2):tt?W=_t._1.failed(A.fromLeft(tt))(_t._2):W=_t._1.completed(A.fromRight(W))(_t._2),tt=null,xt++;break;case m:xt++,at=new N(_,new N(x,W,tt),at,Z),q=P,W=_t._1;break;case x:xt--,q=R,W=_t._1,tt=_t._2;break}break;case M:for(var Nt in Rt)Rt.hasOwnProperty(Nt)&&(pt=pt&&Rt[Nt].rethrow,k(Rt[Nt].handler(W)));Rt=null,Z&&tt?setTimeout(function(){throw A.fromLeft(tt)},0):A.isLeft(W)&&pt&&setTimeout(function(){if(pt)throw A.fromLeft(W)},0);return;case G:q=P;break;case B:return}}function Jt(K){return function(){if(q===M)return pt=pt&&K.rethrow,K.handler(W)(),function(){};var nt=St++;return Rt=Rt||{},Rt[nt]=K,function(){Rt!==null&&delete Rt[nt]}}}function mt(K,nt){return function(){if(q===M)return nt(A.right(void 0))(),function(){};var ht=Jt({rethrow:!1,handler:function(){return nt(A.right(void 0))}})();switch(q){case G:Z=A.left(K),q=M,W=Z,Bt(X);break;case B:Z===null&&(Z=A.left(K)),xt===0&&(q===B&&(at=new N(_,new N(m,W(K)),at,Z)),q=R,W=null,tt=null,Bt(++X));break;default:Z===null&&(Z=A.left(K)),xt===0&&(q=R,W=null,tt=null)}return ht}}function gt(K){return function(){var nt=Jt({rethrow:!1,handler:K})();return q===G&&Bt(X),nt}}return{kill:mt,join:gt,onComplete:Jt,isSuspended:function(){return q===G},run:function(){q===G&&(Y.isDraining()?Bt(X):Y.enqueue(function(){Bt(X)}))}}}function I(A,H,$,X){var q=0,W={},tt=0,Z={},ct=new Error("[ParAff] Early exit"),ft=null,at=t;function xt(Jt,mt,gt){var K=mt,nt=null,ht=null,_t=0,Nt={},wt,Kt;t:for(;;)switch(wt=null,K.tag){case y:if(K._3===t&&(wt=W[K._1],Nt[_t++]=wt.kill(Jt,function(Se){return function(){_t--,_t===0&&gt(Se)()}})),nt===null)break t;K=nt._2,ht===null?nt=null:(nt=ht._1,ht=ht._2);break;case f:K=K._2;break;case d:case l:nt&&(ht=new N(_,nt,ht)),nt=K,K=K._1;break}if(_t===0)gt(A.right(void 0))();else for(Kt=0,wt=_t;Kt<wt;Kt++)Nt[Kt]=Nt[Kt]();return Nt}function St(Jt,mt,gt){var K,nt,ht,_t,Nt,wt;for(A.isLeft(Jt)?(K=Jt,nt=null):(nt=Jt,K=null);;){if(ht=null,_t=null,Nt=null,wt=null,ft!==null)return;if(mt===null){X(K||nt)();return}if(mt._3!==t)return;switch(mt.tag){case f:K===null?(mt._3=A.right(mt._1(A.fromRight(nt))),nt=mt._3):mt._3=K;break;case d:if(ht=mt._1._3,_t=mt._2._3,K){if(mt._3=K,Nt=!0,wt=tt++,Z[wt]=xt(ct,K===ht?mt._2:mt._1,function(){return function(){delete Z[wt],Nt?Nt=!1:gt===null?St(K,null,null):St(K,gt._1,gt._2)}}),Nt){Nt=!1;return}}else{if(ht===t||_t===t)return;nt=A.right(A.fromRight(ht)(A.fromRight(_t))),mt._3=nt}break;case l:if(ht=mt._1._3,_t=mt._2._3,ht===t&&A.isLeft(_t)||_t===t&&A.isLeft(ht))return;if(ht!==t&&A.isLeft(ht)&&_t!==t&&A.isLeft(_t))K=nt===ht?_t:ht,nt=null,mt._3=K;else if(mt._3=nt,Nt=!0,wt=tt++,Z[wt]=xt(ct,nt===ht?mt._2:mt._1,function(){return function(){delete Z[wt],Nt?Nt=!1:gt===null?St(nt,null,null):St(nt,gt._1,gt._2)}}),Nt){Nt=!1;return}break}gt===null?mt=null:(mt=gt._1,gt=gt._2)}}function Rt(Jt){return function(mt){return function(){delete W[Jt._1],Jt._3=mt,St(mt,Jt._2._1,Jt._2._2)}}}function pt(){var Jt=P,mt=$,gt=null,K=null,nt,ht;t:for(;;)switch(nt=null,ht=null,Jt){case P:switch(mt.tag){case f:gt&&(K=new N(_,gt,K)),gt=new N(f,mt._1,t,t),mt=mt._2;break;case d:gt&&(K=new N(_,gt,K)),gt=new N(d,t,mt._2,t),mt=mt._1;break;case l:gt&&(K=new N(_,gt,K)),gt=new N(l,t,mt._2,t),mt=mt._1;break;default:ht=q++,Jt=R,nt=mt,mt=new N(y,ht,new N(_,gt,K),t),nt=S(A,H,nt),nt.onComplete({rethrow:!1,handler:Rt(mt)})(),W[ht]=nt,H&&H.register(nt)}break;case R:if(gt===null)break t;gt._1===t?(gt._1=mt,Jt=P,mt=gt._2,gt._2=t):(gt._2=mt,mt=gt,K===null?gt=null:(gt=K._1,K=K._2))}for(at=mt,ht=0;ht<q;ht++)W[ht].run()}function Bt(Jt,mt){ft=A.left(Jt);var gt;for(var K in Z)if(Z.hasOwnProperty(K)){gt=Z[K];for(K in gt)gt.hasOwnProperty(K)&&gt[K]()}Z=null;var nt=xt(Jt,at,mt);return function(ht){return new N(o,function(_t){return function(){for(var Nt in nt)nt.hasOwnProperty(Nt)&&nt[Nt]();return L}})}}return pt(),function(Jt){return new N(o,function(mt){return function(){return Bt(Jt,mt)}})}}function D(A,H,$){return new N(o,function(X){return function(){return I(A,H,$,X)}})}return N.EMPTY=t,N.Pure=v(e),N.Throw=v(n),N.Catch=v(r),N.Sync=v(i),N.Async=v(o),N.Bind=v(u),N.Bracket=v(s),N.Fork=v(a),N.Seq=v(c),N.ParMap=v(f),N.ParApply=v(d),N.ParAlt=v(l),N.Fiber=S,N.Supervisor=et,N.Scheduler=Y,N.nonCanceler=L,N})();let Of=null;function R2(){return Of||(typeof document>"u"?null:Of=document.createElement("canvas").getContext("2d"))}const ea=new Map;function Rf(t,e,n,r,i,o){const u=`${n} ${e}px ${t}`,s=u+"|"+r;if(ea.has(s))return ea.get(s);const a=R2();if(!a)return o;a.font=u;const c=i(a.measureText(r)),f=typeof document<"u"?document.fonts:null;if(!f||f.check(u))ea.set(s,c);else if(f&&f.load)try{f.load(u)}catch{}return c}const B2=(t,e,n,r)=>Rf(t,e,n,r,i=>i.width,-1),W2=(t,e,n,r)=>Rf(t,e,n,r,i=>({ascent:i.actualBoundingBoxAscent,descent:i.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),Bf=t=>e=>{const n=B2(t.family,t.size,t.weight,Wr(e));return n<0?rt(bo(e).length)*t.size*.62:n},Wf=t=>e=>{const n=W2(t.family,t.size,t.weight,Wr(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},zf=t=>t,qf=t=>t,iu=t=>t,Hf=t=>t,z2=t=>t,$f=t=>t,Xf=t=>t,q2=Xf("BaselineTop"),or=Xf("BaselineMiddle"),na=$f("AlignLeft"),Zr=$f("AlignCenter"),ve=z2("RoundJoin"),dn=Hf("ButtCap"),vn=Hf("RoundCap"),H2=iu("LayerPolyOut"),$2=iu("LayerPolyIn"),X2=iu("LayerNodeMask"),Y2=iu("LayerOverlay"),ou=qf("NonZero"),V2=qf("EvenOdd"),Yf=zf("Normal"),uu=zf("Difference"),ie={r:255,g:255,b:255,a:255},Mn={r:26,g:26,b:26,a:255},U2=t=>t,Vf=t=>t,Z2=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},un=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Uf=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},ra=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},K2=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},j2=Vf("FlatLevel"),tN=Vf("NestedLevel"),Zf=U2("GenieSilhouette"),eN=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const i=Or(t);return{prng:i.prng,yLift:i.value*n.yJitter*r}},nN=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const i=Or(t);return{prng:i.prng,dx:(i.value*2-1)*n.xJitter*r}},Kf=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,i=Le(r*r+n*n),o=(t.r*t.r-e.r*e.r+i*i)/(2*i),u=Le(Z2(0)(t.r*t.r-o*o)),s=t.cx+o*r/i,a=t.cy+o*n/i,c={x:s-u*n/i,y:a+u*r/i},f={x:s+u*n/i,y:a-u*r/i};return i===0||i>t.r+e.r?{x:(t.cx+e.cx)/2,y:t.cy}:c.y<f.y?c:f},rN=t=>e=>{const n=un(e)(un(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},iN=t=>e=>n=>r=>i=>o=>{if(e)return{prng:t,r:i};if(n)return{prng:t,r:i*(1+o.rJitter)};if(r)return{prng:t,r:i*o.smallScale};const u=Or(t);return{prng:u.prng,r:i*(1+u.value*o.rJitter)}},jf=t=>{const e=un(t.w)(t.h)/2;return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,4,t.x+t.w-e+.5522847498307936*e,t.y,t.x+t.w,t.y+e-.5522847498307936*e,t.x+t.w,t.y+e,4,t.x+t.w,t.y+e+.5522847498307936*e,t.x+t.w-e+.5522847498307936*e,t.y+t.h,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,4,t.x+e-.5522847498307936*e,t.y+t.h,t.x,t.y+e+.5522847498307936*e,t.x,t.y+e,4,t.x,t.y+e-.5522847498307936*e,t.x+e-.5522847498307936*e,t.y,t.x+e,t.y,5]},oN=t=>e=>n=>{const r=Or(t),i=e.length;return i===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const o=Uf(0)(i-1|0)(de(hn(r.value*rt(n))));return o>=0&&o<e.length?e[o]:-1})()}},uN=t=>e=>{const n=Or(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const i=Uf(0)(r-1|0)(de(hn(n.value*rt(r))));return i>=0&&i<e.length?e[i]:-1})()}},t_=t=>{const e=un(t.w*.18)(t.h*.6);return[1,t.x+e,t.y,2,t.x+t.w,t.y,2,t.x+t.w-e,t.y+t.h,2,t.x,t.y+t.h,5]},e_=t=>[1,t.x,t.y,2,t.x+t.w,t.y,2,t.x+t.w,t.y+t.h*.85,4,t.x+t.w*.66,t.y+t.h*1.05,t.x+t.w*.34,t.y+t.h*.65,t.x,t.y+t.h*.85,5],n_={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},sN=t=>{const e=un(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,i=t.x+n;return[1,t.x,r,4,t.x,r+.5522847498*e,i-.5522847498*n,r+e,i,r+e,4,i+.5522847498*n,r+e,t.x+t.w,r+.5522847498*e,t.x+t.w,r]},r_=t=>{const e=un(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+t.h+5,i=t.y+e,o=r-e,u=t.x+n;return[1,t.x,i,4,t.x,i-.5522847498*e,u-.5522847498*n,t.y,u,t.y,4,u+.5522847498*n,t.y,t.x+t.w,i-.5522847498*e,t.x+t.w,i,2,t.x+t.w,o,4,t.x+t.w,o+.5522847498*e,u+.5522847498*n,r,u,r,4,u-.5522847498*n,r,t.x,o+.5522847498*e,t.x,o,5]},i_=t=>e=>{const n=e.y+e.h,r=yd(t.rBase*e.h)(e.w/(2*(1+(rt(t.minN)-1)*t.stepRatio))),i=e.w-2*r,o=2*r*t.stepRatio,u=ra(t.minN)(i<=0||o<=0?t.minN:de(Un(i/o))+1|0),s=u>=3?Dt(1,u-2|0):[],a=s.length,c=Cn(a+1|0,2),f=c<1?[]:bt(0,c,s),d=uN(t.seed)((()=>{const m=a-c|0;return m<1?s:bt(m,s.length,s)})()),l=d.idx,_=oN(d.prng)(st(m=>m!==l,f))(ra(1)(f.length-(We(Er)(l)(f)?1:0)|0)),h=_.idx,p=u>=2?i/(rt(u)-1):0;return T(m=>x=>{const y=x===h,N=x===l,v=x===0||x===(u-1|0),L=iN(m.prng)(v)(N)(y)(r)(t),k=eN(L.prng)(v)(t)(e.h),E=nN(k.prng)(v)(t)(p);return{prng:E.prng,circles:Ot(m.circles)({cx:e.x+K2(L.r)(e.w-L.r)((u>=2?r+rt(x)/(rt(u)-1)*i+E.dx:r+0*i+E.dx)+(N?t.heroShift*p:y?-1*t.smallShift*p:0)),cy:n-k.yLift,r:L.r})}})({prng:_.prng,circles:[]})(Dt(0,u-1|0)).circles},o_=t=>e=>{const n=t.length;return Ft(r=>i=>({c:i,p1:(()=>{if(r===0)return{x:i.cx-i.r,y:e};const o=r-1|0;return o>=0&&o<t.length?Kf(t[o])(i):{x:i.cx-i.r,y:e}})(),p2:(()=>{if(r===(n-1|0))return{x:i.cx+i.r,y:e};const o=r+1|0;return o>=0&&o<t.length?Kf(i)(t[o]):{x:i.cx+i.r,y:e}})()}))(t)},u_=t=>{const e=un(t.h*.4)(t.w*.2);return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,2,t.x+t.w,t.y+t.h/2,2,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,2,t.x,t.y+t.h/2,5]},aN=t=>e=>n=>{const r=fr(e.y-t.cy)(e.x-t.cx),i=fr(n.y-t.cy)(n.x-t.cx),o=i>r?i-r:i+6.283185307179586-r,u=ra(1)(de(oo(o/1.5707963267948966))),s=o/rt(u),a=1.3333333333333333*Nd(s/4);return Tt(Dt(0,u-1|0))(c=>{const f=r+rt(c+1|0)*s,d=t.cx+t.r*nn(f),l=t.cy+t.r*$e(f),_=r+rt(c)*s;return[4,t.cx+t.r*nn(_)-a*t.r*$e(_),t.cy+t.r*$e(_)+a*t.r*nn(_),d+a*t.r*$e(f),l-a*t.r*nn(f),d,l]})},s_=t=>e=>{const n=t.h*.38,r=o_(i_(n_)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),i=un(e)(un(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...Tt(r)(o=>aN(o.c)(o.p1)(o.p2)),2,t.x+t.w,t.y+t.h-i,3,t.x+t.w,t.y+t.h,t.x+t.w-i,t.y+t.h,2,t.x+i,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-i,2,r[0].p1.x,r[0].p1.y,5]:rN(t)(e)},a_=t=>e=>n=>r=>i=>o=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(i)(o);if(e==="Cylinder"){const u=r_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Parallelogram"){const u=t_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Diamond"){const u=u_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Ellipse"){const u=jf(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Document"){const u=e_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Cloud"){const u=s_(n)(r);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}return t.drawRoundedRect(n)(r)(i)(o)},cN=t=>()=>t.clip("evenodd"),gN=t=>e=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(e.tile,.001))),r=Math.max(2,Math.round(e.tile*n)),i=document.createElement("canvas");i.width=r,i.height=r;const o=i.getContext("2d");o.scale(n,n),o.fillStyle=e.bgCss,o.fillRect(0,0,e.tile,e.tile),o.fillStyle=e.dotCss,o.beginPath(),o.arc(e.tile/2,e.tile/2,e.dotR,0,2*Math.PI),o.fill();const u=t.createPattern(i,"repeat");u&&typeof u.setTransform=="function"&&u.setTransform(new DOMMatrix().scaleSelf(1/n,1/n)),t.save(),t.fillStyle=u,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},ia=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},oa=t=>e=>n=>{const r=e.stroke;return()=>{const i=r.value,o=Hd(t)(n);if(i!==n)return o(),e.stroke.value=n}},fN=t=>e=>n=>{const r=e.font;return()=>{const i=r.value,o=tl(t)(n);if(i!==n)return o(),e.font.value=n}},Xi=t=>e=>n=>{const r=e.fill;return()=>{const i=r.value,o=qd(t)(n);if(i!==n)return o(),e.fill.value=n}},su=t=>e=>{const n=e.length,r=o=>{if(o>=n)return()=>{};const u=o>=0&&o<e.length?e[o]:0;if(u===1){const s=cc(t)((()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===2){const s=li(t)((()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===3){const s=hi(t)({cpx:(()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})(),cpy:(()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=o+3|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=o+4|0;return c>=0&&c<e.length?e[c]:0})()}),a=r(o+5|0);return()=>(s(),a())}if(u===4){const s=nl(t)({cp1x:(()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})(),cp1y:(()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})(),cp2x:(()=>{const c=o+3|0;return c>=0&&c<e.length?e[c]:0})(),cp2y:(()=>{const c=o+4|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=o+5|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=o+6|0;return c>=0&&c<e.length?e[c]:0})()}),a=r(o+7|0);return()=>(s(),a())}if(u===5){const s=gc(t),a=r(o+1|0);return()=>(s(),a())}return()=>{}},i=ac(t);return()=>(i(),r(0)())},_N=t=>e=>n=>r=>i=>o=>{const u=ia(o)(ia(r/2)(i/2)),s=cc(t)(e+u)(n);return()=>(s(),li(t)(e+r-u)(n)(),hi(t)({cpx:e+r,cpy:n,x:e+r,y:n+u})(),li(t)(e+r)(n+i-u)(),hi(t)({cpx:e+r,cpy:n+i,x:e+r-u,y:n+i})(),li(t)(e+u)(n+i)(),hi(t)({cpx:e,cpy:n+i,x:e,y:n+i-u})(),li(t)(e)(n+u)(),hi(t)({cpx:e,cpy:n,x:e+u,y:n})(),gc(t)())},dN=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),lN=t=>e=>{const n=Ud(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=dN();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0}}}},hN={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},pN=t=>oe(t.weight)+" "+Oa(t.size)+"px "+t.family,bn=t=>{const e=Oa(rt(t.a)/255);return t.a>=255?"rgb("+oe(t.r)+","+oe(t.g)+","+oe(t.b)+")":"rgba("+oe(t.r)+","+oe(t.g)+","+oe(t.b)+","+e+")"},mN=t=>e=>n=>r=>{const i=Xi(t)(n)(bn(r));return()=>(i(),Vd(t)({x:0,y:0,width:e.width,height:e.height})())},xN=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",gN(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:bn(n.bgColor),dotCss:bn(n.dotColor),tile:n.tile,dotR:n.dotRadius})())},yN=t=>e=>n=>r=>{const i=Xi(t)(e)(bn(r));return()=>(i(),su(t)(n)(),Ou(t)())},NN=t=>e=>n=>r=>i=>{const o=Xi(t)(e)(bn(r));return()=>(o(),oa(t)(e)(bn(i.color))(),Qu(t)(i.width)(),_o(t)((()=>{if(i.lineJoin==="RoundJoin")return fo;if(i.lineJoin==="BevelJoin")return qu;if(i.lineJoin==="MiterJoin")return Hu;g()})())(),Vu(t)((()=>{if(i.lineCap==="ButtCap")return Yu;if(i.lineCap==="RoundCap")return $u;if(i.lineCap==="SquareCap")return Xu;g()})())(),su(t)(n)(),Ou(t)(),Mu(t)())},JN=t=>e=>n=>r=>i=>o=>{const u=ac(t);return()=>{if(u(),_N(t)(n.x)(n.y)(n.w)(n.h)(r)(),i.tag==="Just"?(Xi(t)(e)(bn(i._1.color))(),Ou(t)()):i.tag==="Nothing"||g(),o.tag==="Just")return oa(t)(e)(bn(o._1.color))(),Qu(t)(o._1.width)(),_o(t)((()=>{if(o._1.lineJoin==="RoundJoin")return fo;if(o._1.lineJoin==="BevelJoin")return qu;if(o._1.lineJoin==="MiterJoin")return Hu;g()})())(),Vu(t)((()=>{if(o._1.lineCap==="ButtCap")return Yu;if(o._1.lineCap==="RoundCap")return $u;if(o._1.lineCap==="SquareCap")return Xu;g()})())(),Mu(t)();o.tag!=="Nothing"&&g()}},TN=t=>e=>n=>r=>{const i=oa(t)(e)(bn(r.color));return()=>(i(),Qu(t)(r.width)(),_o(t)((()=>{if(r.lineJoin==="RoundJoin")return fo;if(r.lineJoin==="BevelJoin")return qu;if(r.lineJoin==="MiterJoin")return Hu;g()})())(),Vu(t)((()=>{if(r.lineCap==="ButtCap")return Yu;if(r.lineCap==="RoundCap")return $u;if(r.lineCap==="SquareCap")return Xu;g()})())(),su(t)(n)(),Mu(t)())},c_=t=>e=>n=>{const r=Xi(t)(e)(bn(n.color));return()=>(r(),fN(t)(e)(pN(n.font))(),dl(t)((()=>{if(n.align==="AlignLeft")return sl;if(n.align==="AlignCenter")return cl;if(n.align==="AlignRight")return al;g()})())(),_l(t)((()=>{if(n.baseline==="BaselineTop")return rl;if(n.baseline==="BaselineMiddle")return il;if(n.baseline==="BaselineAlphabetic")return ol;if(n.baseline==="BaselineBottom")return ul;g()})())(),el(t)(n.content)(n.x)(n.y)())},g_={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>hN},wN={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>g_},vN=t=>e=>n=>{const r=ia(e.width/n.vw)(e.height/n.vh),i=Ru(t)({translateX:(e.width-n.vw*r)/2-n.vx*r,translateY:(e.height-n.vh*r)/2-n.vy*r});return()=>(i(),co(t)({scaleX:r,scaleY:r})(),_o(t)(fo)())},bN={pure:t=>e=>()=>t,Apply0:()=>g_},kN={Applicative0:()=>bN,Bind1:()=>wN},f_={fillPath:t=>e=>n=>{const r=yN(n.ctx)(n.styleCache)(t)(e.color),i=n.maskDepth;return()=>{if(i.value===0)return r()}},strokePath:t=>e=>n=>{const r=TN(n.ctx)(n.styleCache)(t)(e),i=n.maskDepth;return()=>{if(i.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const i=NN(r.ctx)(r.styleCache)(t)(e.color)(n),o=r.maskDepth;return()=>{if(o.value===0)return i()}},drawRoundedRect:t=>e=>n=>r=>i=>{const o=JN(i.ctx)(i.styleCache)(t)(e)(n)(r),u=i.maskDepth;return()=>{if(u.value===0)return o()}},drawText:t=>e=>{const n=c_(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=_r(n.ctx),i=n.maskDepth;return()=>{if(i.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Zd(n.ctx)(t)(),c_(n.ctx)(n.styleCache)(e)(),dr(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=_r(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Ru(e.ctx)({translateX:t.tx,translateY:t.ty})(),co(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBakedTransform:t=>e=>{const n=_r(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Ru(e.ctx)({translateX:t.tx,translateY:t.ty})(),co(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushClip:t=>e=>n=>{const r=_r(n.ctx),i=n.maskDepth;return()=>{if(i.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",su(n.ctx)(t)(),e==="NonZero")return Yd(n.ctx)();if(e==="EvenOdd")return cN(n.ctx)();g()}}},popClip:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBlend:t=>e=>{const n=_r(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){if(n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",t==="Normal")return _c(e.ctx)(gl)();if(t==="Difference")return _c(e.ctx)(fl)();g()}}},popBlend:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushAlpha:t=>e=>{const n=_r(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Xd(e.ctx)(t)()}},popAlpha:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushLayer:t=>e=>{if(t==="LayerNodeMask"){const n=e.maskDepth;return()=>{const r=n.value;n.value=r+1|0}}return()=>{}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;if(n>0)return t.maskDepth.value=r}},setViewport:t=>e=>{const n=vN(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=mN(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=xN(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=Bf(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Wf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Zf,Monad0:()=>kN},LN=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Kr=t=>e=>n=>{const r=LN(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},__=t=>{const e=ut.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ut.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},au=t=>{if(t.tag==="Hidden")return{alpha:0,scale:0};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:t._1>0?1:0,scale:ki(8)(.6)(__(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:ki(8)(.6)(__(1-t._1))};g()};function EN(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function CN(t){const e=t.length,n=new Array(e);for(let r=0;r<e;r++){const i=t[r],o=t[(r+1)%e];n[r]={a:i,b:o,len:EN(i,o)}}return n}function SN(t,e,n){let r=0;for(let i=0;i<t.length;i++){const o=t[i],u=r,s=u+o.len;if(n<=s){const a=o.len>1e-6?(n-u)/o.len:0;return{x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a}}r=s}return e.length>0?e[e.length-1]:{x:0,y:0}}function d_(t,e){if(e.length===0)return[];const n=CN(e);let r=0;for(let o=0;o<n.length;o++)r+=n[o].len;const i=new Array(t);for(let o=0;o<t;o++)i[o]=SN(n,e,o*r/t);return i}function GN(t,e){const n=e.length;if(n===0)return e;const r=(t%n+n)%n|0,i=new Array(n);for(let o=0;o<n;o++)i[o]=e[(o+r)%n];return i}function PN(t,e){const n=e.length;if(n===0)return e;let r=0,i=1/0;for(let o=0;o<n;o++){let u=0;for(let s=0;s<n;s++){const a=t[s]||{x:0,y:0},c=e[(s+o)%n]||{x:0,y:0},f=a.x-c.x,d=a.y-c.y;u+=f*f+d*d}u<i&&(i=u,r=o)}return GN(r,e)}const l_=t=>e=>n=>{const r=d_(t,e),i=d_(t,n),o=PN(r,i);return{from:r,to:o}};function h_(t){const e=t.length;if(e===0)return{x:0,y:0};let n=0,r=0;for(let i=0;i<e;i++)n+=t[i].x,r+=t[i].y;return{x:n/e,y:r/e}}function IN(t,e){const n=e.x-t.x,r=e.y-t.y,i=Math.sqrt(n*n+r*r);return i<=1e-4?{x:1,y:0}:{x:n/i,y:r/i}}function DN(t,e){const n=e.length;if(n===0)return e;const r=new Array(n);for(let i=0;i<n;i++){const o=e[((i-1)%n+n)%n],u=e[((i+1)%n+n)%n],s=e[i];r[i]={x:s.x+((o.x+u.x)/2-s.x)*t,y:s.y+((o.y+u.y)/2-s.y)*t}}return r}function QN(t){return t<0?0:t>1?1:t}const p_=t=>e=>n=>r=>{const i=e.length;if(i===0)return[];const o=h_(e),u=h_(n),s=IN(o,u),a=new Array(i);let c=1/0,f=-1/0;for(let _=0;_<i;_++){const h=e[_],p=(h.x-o.x)*s.x+(h.y-o.y)*s.y;a[_]=p,p<c&&(c=p),p>f&&(f=p)}const d=f-c;let l=new Array(i);for(let _=0;_<i;_++){const h=e[_],p=n[_];if(p===void 0){l[_]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(a[_]-c)/d),x=Math.max(1e-4,1-m),y=QN((t-m)/x),N=y*y*(3-2*y);l[_]={x:h.x+(p.x-h.x)*N,y:h.y+(p.y-h.y)*N}}for(let _=0;_<r.smoothPasses;_++)l=DN(.5,l);return l},kn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},m_=T(Pr)(0),x_=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},FN=T(t=>e=>t+e.len)(0),ua=t=>{const e=At(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Tt(bt(1,t.length,t))(n=>[2,n.x,n.y]),5];g()},AN=t=>e=>{const n=kn(e)(kn(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},MN=t=>{const e=At(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Tt(e._1.tail)(n=>[2,n.x,n.y])];g()},ON=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return r_(e);if(t.shape==="Parallelogram")return t_(e);if(t.shape==="Diamond")return u_(e);if(t.shape==="Ellipse")return jf(e);if(t.shape==="Document")return e_(e);if(t.shape==="Cloud")return s_(e)(7);if(t.shape==="Rectangle")return AN(e)(7);g()},pe=t=>e=>n=>z(r=>{const i=rt(r)/rt(n);return{x:t.x+(e.x-t.x)*i,y:t.y+(e.y-t.y)*i}})(Dt(0,n-1|0)),RN=t=>{const e=un(t.w*.18)(t.h*.6);return[...pe({x:t.x+e,y:t.y})({x:t.x+t.w,y:t.y})(16),...pe({x:t.x+t.w,y:t.y})({x:t.x+t.w-e,y:t.y+t.h})(16),...pe({x:t.x+t.w-e,y:t.y+t.h})({x:t.x,y:t.y+t.h})(16),...pe({x:t.x,y:t.y+t.h})({x:t.x+e,y:t.y})(16)]},jr=t=>e=>{const n=kn(t)(kn(e.w/2)(e.h/2));return{...e,x:e.x+n,y:e.y+n,w:e.w-2*n,h:e.h-2*n}},sa=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return Le(r*r+n*n)},BN=t=>we(e=>n=>({a:e,b:n,len:sa(e)(n)}),t,bt(1,t.length,t)),WN=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?w("Just",e[n]):J,i=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];g()})(),o=0<e.length?w("Just",e[0]):J,u=(()=>{if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return{x:0,y:0};g()})(),s=e.length;return s<3?e:[u,...Tt(Dt(1,s-2|0))(a=>{const c=a+1|0,f=c>=0&&c<e.length?w("Just",e[c]):J,d=a>=0&&a<e.length?w("Just",e[a]):J,l=a-1|0,_=l>=0&&l<e.length?w("Just",e[l]):J;if(_.tag==="Just"&&d.tag==="Just"&&f.tag==="Just"){const h=d._1,p=sa(h)(f._1),m=sa(_._1)(h),x=kn(t)(p/2),y=kn(t)(m/2),N=p>0?x/p:0,v=h.x+(f._1.x-h.x)*N,L=h.y+(f._1.y-h.y)*N,k=m>0?y/m:0,E=h.x+(_._1.x-h.x)*k,O=h.y+(_._1.y-h.y)*k;return z(Y=>{const et=rt(Y)/rt(10),G=1-et;return{x:G*G*E+2*G*et*h.x+et*et*v,y:G*G*O+2*G*et*h.y+et*et*L}})(Dt(0,10))}return[]}),...i]},zN=t=>e=>n=>r=>i=>z(o=>{const u=rt(o)/rt(i),s=1-u,a=u*u*u,c=3*s*u*u,f=3*s*s*u,d=s*s*s;return{x:d*t.x+f*e.x+c*n.x+a*r.x,y:d*t.y+f*e.y+c*n.y+a*r.y}})(Dt(0,i-1|0)),qN=t=>[...pe({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...pe({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...zN({x:t.x+t.w,y:t.y+t.h*.85})({x:t.x+t.w*.66,y:t.y+t.h*1.05})({x:t.x+t.w*.34,y:t.y+t.h*.65})({x:t.x,y:t.y+t.h*.85})(32),...pe({x:t.x,y:t.y+t.h*.85})({x:t.x,y:t.y})(12)],y_=t=>e=>z(n=>{const r=6.283185307179586*rt(n)/rt(64);return{x:t.x+e*nn(r),y:t.y+e*$e(r)}})(Dt(0,63)),cu=t=>e=>{const n=.5522847498*e;return[1,t.x+e,t.y,4,t.x+e,t.y+n,t.x+n,t.y+e,t.x,t.y+e,4,t.x-n,t.y+e,t.x-e,t.y+n,t.x-e,t.y,4,t.x-e,t.y-n,t.x-n,t.y-e,t.x,t.y-e,4,t.x+n,t.y-e,t.x+e,t.y-n,t.x+e,t.y,5]},HN=t=>{const e=t.y+t.h/2,n=un(t.h*.4)(t.w*.2);return[...pe({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...pe({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...pe({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...pe({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...pe({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...pe({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},N_=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:m_(z(n=>n.x)(t))/rt(e),y:m_(z(n=>n.y)(t))/rt(e)}},gu=t=>e=>n=>r=>i=>z(o=>{const u=n+(r-n)*(rt(o)/rt(i));return{x:t.x+e*nn(u),y:t.y+e*$e(u)}})(Dt(0,i-1|0)),J_=t=>e=>{const n=kn(t)(kn(e.w/2)(e.h/2));return[...pe({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...gu({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...pe({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...gu({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...pe({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...gu({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...pe({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...gu({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},fu=t=>e=>n=>r=>i=>o=>z(u=>{const s=r+(i-r)*(rt(u)/rt(o));return{x:t.x+e*nn(s),y:t.y+n*$e(s)}})(Dt(0,o-1|0)),$N=t=>{const e=t.h*.38;return[...Tt(o_(i_(n_)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=fr(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),i=fr(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return fu({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(i)(r>i?r:r+6.283185307179586)(16)}),...pe({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...pe({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...pe({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},XN=t=>{const e=kn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,i=t.y+t.h+5-e-2,o=t.x+n;return[...fu({x:o,y:r})(n)(e)(3.141592653589793)(6.283185307179586)(24),...pe({x:t.x+t.w,y:r})({x:t.x+t.w,y:i})(12),...fu({x:o,y:i})(n)(e)(0)(3.141592653589793)(24),...pe({x:t.x,y:i})({x:t.x,y:r})(12)]},br=t=>e=>e.shape==="Cylinder"?XN(e):e.shape==="Parallelogram"?RN(e):e.shape==="Diamond"?HN(e):e.shape==="Ellipse"?J_(un(e.w)(e.h)/2)(e):e.shape==="Document"?qN(e):e.shape==="Cloud"?$N(e):J_(t)(e),YN=t=>{const e=kn(t.h*.075)(t.w*.075),n=t.w/2;return fu({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},VN=t=>e=>n=>T(r=>i=>{const o=r.pos+i.len,u=n<o?(n-r.pos)/i.len:1,s={x:i.a.x+(i.b.x-i.a.x)*u,y:i.a.y+(i.b.y-i.a.y)*u},a=e>r.pos?(e-r.pos)/i.len:0,c={x:i.a.x+(i.b.x-i.a.x)*a,y:i.a.y+(i.b.y-i.a.y)*a},f=r.points.length-1|0,d=f>=0&&f<r.points.length?(()=>{const l=r.points[f].x-c.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const _=r.points[f].y-c.y;return _<0?-_<1e-4:_<1e-4})()})()?Ot(r.points)(s):[...r.points,c,s]:[c,s];return i.len<=0||o<=e||r.pos>=n?{...r,pos:o}:{pos:o,points:d}})({pos:0,points:[]})(t).points,UN=t=>e=>n=>{const r=At(i=>J,i=>o=>w("Just",{head:i,tail:o}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const i=BN(t),o=FN(i),u=x_(0)(o)(e*o),s=x_(0)(o)(n*o);return s<=u?[]:VN(i)(u)(s)}g()},ZN=t=>e=>n=>r=>{const i=r.x-n.x,o=r.y-n.y,u=e.x-t.x,s=e.y-t.y,a=n.x-t.x,c=n.y-t.y,f=u*o-s*i,d=(a*o-c*i)/f,l=(a*s-c*u)/f;return(f<0?-f<1e-9:f<1e-9)?J:d>=0&&d<=1&&l>=0&&l<=1?w("Just",d):J},KN=t=>e=>n=>{const r=Lt(i=>o=>ut.compare(i.t)(o.t))(yt(i=>{const o=ZN(e)(n)(i._1)(i._2);return o.tag==="Just"?w("Just",{t:o._1,p:{x:e.x+(n.x-e.x)*o._1,y:e.y+(n.y-e.y)*o._1}}):J})(we(Sn,t,[...bt(1,t.length,t),...bt(0,1,t)])));return 0<r.length?w("Just",r[0].p):J},T_=t=>e=>{const n=Cr(e);if(n.tag==="Nothing")return e;if(n.tag==="Just"){const r=n._1.init.length-1|0;if(r>=0&&r<n._1.init.length){const i=KN(t)(n._1.init[r])(n._1.last);if(i.tag==="Just")return Ot(n._1.init)(i._1);if(i.tag==="Nothing")return e;g()}return e}g()},aa=t=>t,On=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},kr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},jN=td($a)(Wt),tJ=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},eJ=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},w_=aa("SegMove"),nJ=aa("SegLine"),rJ=aa("SegQuad"),v_={offset:.4,passes:1,rMax:1.5},b_=t=>de(hn(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,_u=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},du=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},Rn=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},Yi=(()=>{const t=T(e=>n=>((e*31|0)+de(hn(n.x*100))|0)+de(hn(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),iJ=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const i=n,o=r,u=i>=0&&i<t.length?w("Just",t[i]):J;if(u.tag==="Nothing"){n=t.length;continue}if(u.tag==="Just"){if(u._1===1){const s={x:(()=>{const a=i+1|0;return a>=0&&a<t.length?t[a]:0})(),y:(()=>{const a=i+2|0;return a>=0&&a<t.length?t[a]:0})()};e.push({kind:w_,m:o,c:o,p:s,len:0}),r=s,n=i+3|0;continue}if(u._1===2){const s={x:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()},a=s.x-o.x,c=s.y-o.y;e.push({kind:nJ,m:o,c:o,p:s,len:Le(a*a+c*c)}),r=s,n=i+3|0;continue}if(u._1===3){const s={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=s.x-o.x,c=s.y-o.y;e.push({kind:rJ,m:o,c:{x:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()},p:s,len:Le(a*a+c*c)*1.05}),r=s,n=i+5|0;continue}if(u._1===5){e.push({kind:w_,m:o,c:o,p:o,len:0}),n=i+1|0;continue}n=t.length;continue}g()}return e},oJ=t=>e=>{const n=e.length-1|0,r=n<1?[]:bt(0,n,e),i=(()=>{const u=r.length-1|0;return u>=0&&u<r.length?w("Just",r[u]):J})(),o=e.length-1|0;if(o>=0&&o<e.length&&i.tag==="Just"){const u=e[o].y-i._1.y,s=e[o].x-i._1.x,a=Le(s*s+u*u);return a<=1e-4?e:Ot((()=>{const c=e.length-1|0;return c<1?[]:bt(0,c,e)})())({x:e[o].x+s/a*t,y:e[o].y+u/a*t})}return e},uJ=t=>e=>n=>Te(T(r=>i=>{const o=ae(0)(t)(r.prng),u=ae(0)(6.283185307179586)(o.prng);return{prng:u.prng,out:[{x:i.x+o.value*nn(u.value),y:i.y+o.value*$e(u.value)},...r.out]}})({prng:e,out:[]})(n).out),sJ=t=>e=>n=>{if(e.kind==="SegMove")return du(t)(e.p);if(e.kind==="SegLine")return Rn(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});if(e.kind==="SegQuad")return Rn(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});g()},aJ=t=>e=>{if(e.kind==="SegMove")return du(t)(e.p);if(e.kind==="SegLine")return Rn(t)(e.p);if(e.kind==="SegQuad")return _u(t)(e.c)(e.p);g()},k_=t=>e=>{const n=iJ(e),r=T(s=>a=>s+a.len)(0)(n)*On(0)(kr(1)(t)),i=[];let o=0,u=0;for(;u<n.length;){const s=u,a=o;if(s>=0&&s<n.length){if(a+n[s].len<=r){const c=n[s];aJ(i)(c)(),o=a+c.len,u=s+1|0;continue}if(a>=r){u=n.length;continue}sJ(i)(n[s])((r-a)/On(n[s].len)(1e-4))()}u=n.length}return i},L_={offset:1.5,passes:2,rMax:14,overshoot:2.5},E_=t=>e=>n=>r=>{const i=r.y-n.y,o=n.y-e.y,u=r.x-n.x,s=Le(u*u+i*i),a=n.x-e.x,c=Le(a*a+o*o),f=kr(t.rMax*(xd(c>0&&s>0?On(-1)(kr(1)((a*u+o*i)/(c*s))):1)/3.141592653589793))(.4*kr(c)(s));return{inP:c>0?{x:n.x-a/c*f,y:n.y-o/c*f}:n,curr:n,outP:s>0?{x:n.x+u/s*f,y:n.y+i/s*f}:n}},C_=t=>e=>{const n=e.length,r=[],i=0<e.length?w("Just",e[0]):J;if(i.tag==="Just"?du(r)(i._1)():i.tag==="Nothing"||g(),n>=3){let u=1;for(;u<=(n-2|0);){const s=u,a=s+1|0;if(a>=0&&a<e.length){if(s>=0&&s<e.length){const c=s-1|0;if(c>=0&&c<e.length){const f=E_(t)(e[c])(e[s])(e[a]);Rn(r)(f.inP)(),_u(r)(f.curr)(f.outP)()}}u=s+1|0;continue}u=s+1|0}}const o=e.length-1|0;return o>=0&&o<e.length&&n>=2&&Rn(r)(e[o])(),r},cJ=t=>e=>n=>r=>i=>{if(i.length<4)return C_(t)(i);const o=0<i.length?w("Just",i[0]):J,u=(()=>{if(o.tag==="Nothing")return{x:0,y:0};if(o.tag==="Just")return o._1;g()})(),s=i.length-1|0,a=Zn(Zn(e)(s)+s|0)(s),c=_=>{const h=Zn(_+s|0)(s);return h>=0&&h<i.length?i[h]:u},f=z(_=>E_(t)(c((a+_|0)-1|0))(c(a+_|0))(c((a+_|0)+1|0)))(Dt(0,s-1|0)),d=[],l=0<f.length?w("Just",f[0]):J;if(l.tag==="Just")if(du(d)(l._1.outP)(),jN((()=>{const _=At(h=>J,h=>p=>w("Just",p),f);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})())(_=>{const h=Rn(d)(_.inP);return()=>(h(),_u(d)(_.curr)(_.outP)())})(),n)Rn(d)(l._1.inP)(),_u(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const _=f.length-1|0;_>=0&&_<f.length?Rn(d)((()=>{const h=1-r;return{x:f[_].outP.x+(l._1.inP.x-f[_].outP.x)*h,y:f[_].outP.y+(l._1.inP.y-f[_].outP.y)*h}})())():Rn(d)(l._1.inP)()}else l.tag==="Nothing"||g();return d},ti=t=>e=>n=>r=>{const i=tJ(1)(r.length-1|0),o=ae(0)(rt(i))(ys("shape")(e)),u=eJ(i-1|0)(de(hn(o.value))),s=o.prng;return z(a=>{const c=ae(0)(1)(ys(oe(a))(s)),f=ae(-.18)(.3)(c.prng),d=c.value<.7,l=ae(.5)(.85)(f.prng),_=uJ(t.offset)(l.prng)(r);return{path:n?cJ(t)(u)(d)(f.value)(_):C_(t)(_),alpha:l.value}})(Dt(0,t.passes-1|0))},gJ=t=>e=>n=>ti(t)(e)(!0)([{x:n.x,y:n.y},{x:n.x+n.w,y:n.y},{x:n.x+n.w,y:n.y+n.h},{x:n.x,y:n.y+n.h},{x:n.x,y:n.y}]),fJ=t=>e=>n=>{const r=On(0)(kr(1)(n)),i=e.h/rt(4),o=On(6)(i*1.4);return yt(u=>u)(z(u=>{if(r<On(0)(rt(u)/rt(4)-.05))return J;const s=ys(oe(u))(t),a=On(0)(rt(u)/rt(4)-.05),c=Zn(u)(2)===0,f=c?e.x-2:e.x+e.w+2,d=c?e.x+e.w+2:e.x-2,l=e.y+(rt(u)+.5)*i;return w("Just",{path:k_(On(0)(kr(1)((r-a)/On(1e-4)(kr(1)(rt(u+1|0)/rt(4)+.05)-a))))((()=>{const _={rMax:2,offset:.6,passes:1},h=Te(T(m=>x=>{const y=ae(-i*.08)(i*.08)(m.prng);return{prng:y.prng,out:[{x:f+(d-f)*(rt(x)/rt(4)),y:l+y.value},...m.out]}})({prng:s,out:[]})(Dt(0,4)).out),p=h.length<2?[]:ti(_)(s)(!1)(h);return 0<p.length?p[0].path:[]})()),width:o,alpha:1})})(Dt(0,3)))},ca=(t,e,n)=>({tag:t,_1:e,_2:n}),S_=t=>t,ga=(t,e,n)=>({tag:t,_1:e,_2:n}),lu=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},G_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Vi=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},P_=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},fe=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Pe=(()=>{const t=Xe.unfoldr(mn);return e=>t(Ye("IterNode",e,pn))})(),Bn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},_J=Wt.foldMap(Id),hu=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},I_=jt(C)(Wt),dJ=oc(C),lJ=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},fa=S_("LabelsShown"),hJ=S_("LabelsHidden"),D_=t=>{const e=t.Monad0().Bind1(),n=t.popTransform,r=t.popAlpha;return i=>o=>u=>s=>a=>e.bind(t.pushAlpha(i.fadeAlpha))(()=>e.bind(t.pushTransform({tx:o*(1-i.popScale),ty:u*(1-i.popScale),sx:i.popScale,sy:i.popScale}))(()=>e.bind(t.pushTransform({tx:0,ty:s.y*(1-i.flipY),sx:1,sy:i.flipY}))(()=>e.bind(a)(()=>e.bind(n)(()=>e.bind(n)(()=>r))))))},Ke=t=>{const e=t.Apply0();return n=>T(r=>i=>e.apply(e.Functor0().map(o=>Ma)(r))(n(i)))(t.pure())},Q_=t=>e=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},a=Kr(i)(o)(r),c=0<t.length?w("Just",t[0]):J,f=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return s;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?w("Just",t[d]):J,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return u;g()})(),h=l_(128)(br(4)(jr(2)(e)))(y_(f)(6)),p=f.x-s.x,m=2*(()=>{const V=f.y-s.y;return(p<0?-p:p)+(V<0?-V:V)})(),x=_.x-u.x,y=2*(()=>{const V=_.y-u.y;return(x<0?-x:x)+(V<0?-V:V)})(),N=m+Ni(t)+y,v=N<=1e-4?1:1-y/N,L=N<=1e-4?0:m/N,k=v-L,E=l_(128)(y_(_)(6))(br(4)(jr(2)(n))),O={maxDelay:.4,smoothPasses:2},Y=mr(t)(lu(0)(1)(k<=1e-4?0:(a-L)/k)),et=(()=>{if(Y.tag==="Just")return Y._1;if(Y.tag==="Nothing")return f;g()})(),G=(()=>{if(v>=1)return 0;const V=(a-v)/(1-v),U=V<0?0:V>1?1:V;return U*U*(3-2*U)})(),P=(()=>{if(L<=1e-4)return 1;const V=a/L,U=V<0?0:V>1?1:V;return U*U*(3-2*U)})();return a<L?ga("PolyShape",p_(P)(h.from)(h.to)(O)):a>=v?ga("PolyShape",p_(G)(E.from)(E.to)(O)):ga("CircleShape",et,6)},F_=t=>e=>n=>r=>i=>o=>{const u=Q_(t)(e)(n)(r)(i)(o);if(u.tag==="PolyShape")return N_(u._1);if(u.tag==="CircleShape")return u._1;g()},pJ=t=>e=>{const n=t.y+t.h-6,r=t.y+6,i=t.x+14,o=t.x+t.w-14,u=T(Vi)(0)(z(s=>i-10<s.x+s.w+12&&o+10>s.x-12&&r-10<s.y+s.h+12&&n+10>s.y-12?G_((s.x+s.w+12-(i-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+u*.7071067811865476,y:t.y-u*.7071067811865476}},mJ=t=>e=>n=>T(r=>i=>{const o=P_(i)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just"){const u=pJ(o._1)(r.obstacles);return{acc:j(C)(i)(u)(r.acc),obstacles:Ot(r.obstacles)(u)}}g()})({acc:Q,obstacles:n})(t).acc,_a=(()=>{const t={r:24,g:24,b:27,a:255},e={r:244,g:244,b:245,a:255},n={r:248,g:249,b:246,a:255},r={r:26,g:26,b:26,a:255},i={r:28,g:101,b:192,a:255},o={r:247,g:248,b:250,a:255},u={r:42,g:48,b:60,a:255},s={r:120,g:130,b:146,a:255};return a=>{if(a==="Light")return{bg:{r:255,g:255,b:255,a:255},bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:211,b:209,a:255},shadowFill:{r:255,g:255,b:255,a:255},shadowDot:{r:26,g:26,b:26,a:255},chip:{r:255,g:235,b:130,a:255},chipShadow:{r:214,g:211,b:209,a:255},chipText:Mn,nodeFill:ie,nodeStroke:Mn,text:Mn,edge:Mn,arrowFill:Mn,tokenOutsideFill:Mn,tokenOutsideStroke:ie,tokenInside:ie,tokenInsideStroke:ie,tokenInsideBlend:uu,tokenInsideAlpha:1,chipPillFill:Mn,chipPillText:ie,chipHairline:{r:26,g:26,b:26,a:90},trailDot:Mn,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Dark")return{bg:t,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:63,g:63,b:70,a:255},shadowFill:t,shadowDot:e,chip:{r:234,g:179,b:8,a:255},chipShadow:{r:0,g:0,b:0,a:120},chipText:t,nodeFill:Mn,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:ie,tokenOutsideStroke:ie,tokenInside:ie,tokenInsideStroke:ie,tokenInsideBlend:uu,tokenInsideAlpha:1,chipPillFill:e,chipPillText:t,chipHairline:{r:244,g:244,b:245,a:120},trailDot:e,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Blueprint")return{bg:i,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:90,g:160,b:230,a:255},shadowFill:i,shadowDot:ie,chip:ie,chipShadow:{r:0,g:0,b:0,a:120},chipText:i,nodeFill:i,nodeStroke:ie,text:ie,edge:ie,arrowFill:ie,tokenOutsideFill:ie,tokenOutsideStroke:ie,tokenInside:ie,tokenInsideStroke:ie,tokenInsideBlend:Yf,tokenInsideAlpha:.35,chipPillFill:ie,chipPillText:i,chipHairline:{r:255,g:255,b:255,a:120},trailDot:ie,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Whiteboard")return{bg:n,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:0,g:0,b:0,a:0},shadowFill:n,shadowDot:r,chip:{r:217,g:74,b:56,a:255},chipShadow:{r:26,g:26,b:26,a:60},chipText:n,nodeFill:n,nodeStroke:r,text:r,edge:r,arrowFill:r,tokenOutsideFill:r,tokenOutsideStroke:n,tokenInside:n,tokenInsideStroke:n,tokenInsideBlend:Yf,tokenInsideAlpha:1,chipPillFill:r,chipPillText:n,chipHairline:{r:26,g:26,b:26,a:90},trailDot:r,wobble:!0,fontFamily:"Supermarker, Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Isometric")return{bg:o,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:218,b:224,a:255},shadowFill:o,shadowDot:u,chip:{r:255,g:235,b:130,a:255},chipShadow:{r:100,g:110,b:125,a:90},chipText:u,nodeFill:{r:236,g:239,b:244,a:255},nodeStroke:u,text:u,edge:s,arrowFill:s,tokenOutsideFill:u,tokenOutsideStroke:ie,tokenInside:ie,tokenInsideStroke:ie,tokenInsideBlend:uu,tokenInsideAlpha:1,chipPillFill:u,chipPillText:ie,chipHairline:{r:60,g:66,b:78,a:90},trailDot:u,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};g()}})(),da=t=>e=>Tt(Pe(t.nodes))(n=>{const r=fe(n._1)(e.nodes);return r.tag==="Just"&&au(r._1).alpha>0?ON(n._2):[]}),xJ=t=>e=>n=>[1,t.vx,t.vy,2,t.vx+t.vw,t.vy,2,t.vx+t.vw,t.vy+t.vh,2,t.vx,t.vy+t.vh,5,...da(e)(n)],yJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=ar.traverse(r);return o=>u=>{const s=Kn(u),a=.32*o.size;return i(c=>n.bind(c===0?r.pure(0):t.measureText(o)(me(c)(u)))(f=>n.bind(t.measureText(o)(me(c+1|0)(u)))(d=>n.bind(t.measureInk(o)(c>=0&&c<s.length?lo(s[c]):" "))(l=>r.pure({x:f,w:d-f,up:l.ascent-a,down:l.descent+a})))))(Dt(0,s.length-1|0))}},NJ=t=>e=>{const n=i=>(i.x-e.x)*(i.x-e.x)+(i.y-e.y)*(i.y-e.y),r=T(i=>o=>n(o)<n(i)?o:i)({x:t.x,y:t.y})([{x:t.x,y:t.y},{x:t.x+t.w,y:t.y},{x:t.x,y:t.y+t.h},{x:t.x+t.w,y:t.y+t.h}]);return z(i=>{const o=rt(i)/5;return{x:r.x+(e.x-r.x)*o,y:r.y+(e.y-r.y)*o}})([1,2,3,4])},la=t=>{const e=To(`
7
- `)(t);return e.length===0?[""]:e},JJ=t=>e=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},a=Kr(i)(o)(r),c=0<t.length?w("Just",t[0]):J,f=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return s;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?w("Just",t[d]):J,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return u;g()})(),h=f.x-s.x,p=2*(()=>{const O=f.y-s.y;return(h<0?-h:h)+(O<0?-O:O)})(),m=_.x-u.x,x=2*(()=>{const O=_.y-u.y;return(m<0?-m:m)+(O<0?-O:O)})(),y=p+Ni(t)+x,N=y<=1e-4?1:1-x/y,v=y<=1e-4?0:p/y,L=N-v,k=mr(t)(lu(0)(1)(L<=1e-4?0:(a-v)/L)),E=(()=>{if(k.tag==="Just")return k._1;if(k.tag==="Nothing")return f;g()})();return a<v?ca("InsideRect",jr(2)(e)):a>=N?ca("InsideRect",jr(2)(n)):ca("InsideBall",E,6)},TJ={offset:.8,passes:2,rMax:5},wJ=t=>{const e=t.Monad0().Applicative0(),n=Ke(e);return r=>i=>o=>u=>{const s={color:u,width:1,lineJoin:ve,lineCap:dn},a={color:o,flat:!0},c=f=>t.drawRoundedRect({x:f.x,y:f.y,w:f.w,h:f.h})(4)(w("Just",a))(w("Just",s));return n(f=>{if(f._2.tag==="Travelling"){const d=Bn(f._2._1.edge)(r.edges),l=fe(f._2._1.target)(r.nodes),_=fe(f._2._1.source)(r.nodes);if(_.tag==="Just"&&l.tag==="Just"&&d.tag==="Just"){const h=JJ((()=>{if(f._2._1.direction==="Forward")return d._1;if(f._2._1.direction==="Backward")return Te(d._1);g()})())(_._1)(l._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);if(h.tag==="InsideRect")return c(h._1);if(h.tag==="InsideBall")return t.fillStrokePath(cu(h._1)(h._2))(a)(s);g()}return e.pure()}if(f._2.tag==="Filling"){const d=fe(f._2._1.node)(r.nodes);if(d.tag==="Just")return c(jr(2)(d._1));if(d.tag==="Nothing")return e.pure();g()}return e.pure()})(Pe(i.tokens))}},A_=t=>e=>n=>r=>t.strokePath((()=>{const i=At(o=>J,o=>u=>w("Just",{head:o,tail:u}),z(o=>o.pt)(_d(o=>u=>{const s=rt(u)/rt(72),a=ae(-.18)(.18)(o.prng),c=ae(-.1)(.1)(a.prng),f=ae(-.07)(.07)(c.prng),d=n*(.05+.55*s)*(1+c.value),l=s*28.274333882308138+a.value;return{prng:f.prng,pt:{x:e.x+nn(l)*d+f.value*n,y:e.y+$e(l)*d+f.value*n}}},{prng:137,pt:{x:e.x,y:e.y}},Dt(0,72))));if(i.tag==="Just")return[1,i._1.head.x,i._1.head.y,..._J(o=>[2,o.x,o.y])(i._1.tail)];if(i.tag==="Nothing")return[];g()})())({color:r,width:5.5,lineJoin:ve,lineCap:vn}),vJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=Ke(e.Applicative0());return o=>u=>s=>i(a=>n.bind(t.pushAlpha(a.alpha))(()=>n.bind(t.strokePath(a.path)({color:o.nodeFill,width:a.width,lineJoin:ve,lineCap:vn}))(()=>r)))(fJ(b_(u)+7777|0)(u)(s))},M_=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=e.Applicative0(),o=Ke(i),u=t.popClip,s=Ke(i),a=ar.traverse(i),c=yJ(t),f=vJ(t),d=t.popTransform;return l=>_=>h=>p=>m=>x=>y=>{const N=M=>n.bind(t.pushAlpha(M.alpha))(()=>n.bind(t.strokePath(M.path)({color:_.nodeStroke,width:2,lineJoin:ve,lineCap:vn}))(()=>r)),v={family:_.fontFamily,size:_.wobble?15:11,weight:_.wobble?800:500},L=To(`
8
- `)(x.label===""?m:x.label),k=L.length===0?[""]:L,E=v.size*1.2,O=x.shape==="Cylinder"?t.strokePath(sN({x:x.x,y:x.y,w:x.w,h:x.h}))({color:_.nodeStroke,width:1.25,lineJoin:ve,lineCap:dn}):i.pure(),Y=(x.shape==="Cylinder"?(x.y+(x.y+x.h+5-2*un(x.h*.075)(x.w*.075)))/2:(x.y+x.y+x.h)/2)-rt(k.length)*E/2+E/2,et=y.tag==="PloppingOut"&&_.wobble?y._1:-1,G=et>=0,P=au(y),V=G?{alpha:1,scale:1}:P,U=x.x+x.w/2,B=x.y+x.h/2,R=n.bind(t.pushAlpha(V.alpha*h))(()=>n.bind(t.pushTransform({tx:U*(1-V.scale),ty:B*(1-V.scale),sx:V.scale,sy:V.scale}))(()=>{const M={x:x.x,y:x.y,w:x.w,h:x.h},S={color:_.nodeStroke,width:_.wobble?2:1.25,lineJoin:ve,lineCap:_.wobble?vn:dn};return n.bind((()=>{if(_.wobble){if(x.shape==="Rectangle")return o(N)(gJ(L_)(b_(M))(M));const I=br(7)(x);return n.bind(o(N)((()=>{const D=Yi(I);return I.length<4?[]:ti(v_)(D)(!0)(I)})()))(()=>s(D=>o(N)((()=>{const A=Yi(D);return D.length<2?[]:ti(v_)(A)(!1)(D)})()))(x.shape==="Cylinder"?[YN(x)]:[]))}return n.bind(a_(t)(x.shape)(M)(7)(w("Just",{color:_.nodeFill,flat:!1}))(w("Just",S)))(()=>O)})())(()=>n.bind((()=>{if(p.tag==="Just"&&_.wobble&&!G){const I=p._1;return n.bind(a(c(v))(k))(D=>{const A=Lt(K=>nt=>ut.compare(K.x)(nt.x)),H=de(hn(x.x*7919+x.y*3001))*-1640531535|0,$=ae(5)(7.5)(H),X=ae(0)($.value)($.prng),q=-(1+2*ae(-1)(1)(X.prng).value*3.141592653589793/180),W=(K,nt,ht,_t,Nt)=>A(yt(wt=>wt)([q*nt+K>=_t&&q*nt+K<=Nt?w("Just",{x:nt,y:q*nt+K}):J,q*ht+K>=_t&&q*ht+K<=Nt?w("Just",{x:ht,y:q*ht+K}):J,(()=>{const wt=(_t-K)/q;return wt>=nt&&wt<=ht?w("Just",{x:wt,y:_t}):J})(),(()=>{const wt=(Nt-K)/q;return wt>=nt&&wt<=ht?w("Just",{x:wt,y:Nt}):J})()])),tt=$.value,Z=Zn(I.frameHash)(3),ct=Z===0?{r:200,g:35,b:30,a:220}:Z===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},ft=x.x+x.w/2,at=Re(Ft(K=>nt=>Ft((()=>{const ht=Y+rt(K)*E,_t=ft-T(Nt=>wt=>Nt+wt.w)(0)(nt)/2;return Nt=>wt=>{const Kt=v.size*.1,Se=Nt-1|0,an=Se>=0&&Se<nt.length&&Nt>0?(nt[Se].x+nt[Se].w+wt.x)/2:wt.x-Kt;return{x:_t+an-1,y:ht-wt.up-1,w:Vi(0)((()=>{const Oe=Nt+1|0;return Oe>=0&&Oe<nt.length&&Nt<(nt.length-1|0)?(wt.x+wt.w+nt[Oe].x)/2-an:wt.x+wt.w+Kt-an})())+2,h:wt.up+wt.down+2}}})())(nt))(D)),xt=x.y+4,St=x.x+x.w-4,Rt=x.x+4,pt=xt-q*Rt+X.value,Bt=x.y+x.h-4,Jt=Tt(Tt(Ft(K=>nt=>{const ht=(nt.from.x+nt.to.x)/2,_t=(nt.from.y+nt.to.y)/2,Nt=ae(-1)(1)(H+(911*(K+1|0)|0)|0),wt=ae(-3)(5)(Nt.prng),Kt=Nt.value*3.141592653589793/180,Se=nn(Kt),an=$e(Kt),Oe=Et=>({x:ht+(Et.x-ht)*Se-(Et.y-_t)*an,y:_t+(Et.x-ht)*an+(Et.y-_t)*Se});return{from:(()=>{const Et=Oe(nt.from),Qt=Et.y-_t,tn=Et.x-ht,He=Le(tn*tn+Qt*Qt),en=He<1e-4?1:(He+wt.value)/He;return{x:ht+tn*en,y:_t+Qt*en}})(),to:(()=>{const Et=Oe(nt.to),Qt=ae(-3)(5)(wt.prng).value,tn=Et.y-_t,He=Et.x-ht,en=Le(He*He+tn*tn),$n=en<1e-4?1:(en+Qt)/en;return{x:ht+He*$n,y:_t+tn*$n}})()}})(yt(K=>{const nt=W(pt+rt(K)*tt,Rt,St,xt,Bt);return nt.length===2?w("Just",{from:nt[0],to:nt[1]}):J})(Dt(0,hu(1)(de(hn((Bt-q*St-pt)/tt)))))))(K=>st(nt=>nt.to.x-nt.from.x>1,T(nt=>ht=>Tt(nt)(_t=>{const Nt=W(_t.from.y-q*_t.from.x,ht.x,ht.x+ht.w,ht.y,ht.y+ht.h);return Nt.length===2?Nt[0].x>_t.from.x+.001&&Nt[1].x<_t.to.x-.001?[{from:_t.from,to:Nt[0]},{from:Nt[1],to:_t.to}]:Nt[0].x<=_t.from.x+.001&&Nt[1].x<_t.to.x-.001?[{from:Nt[1],to:_t.to}]:Nt[0].x>_t.from.x+.001&&Nt[1].x>=_t.to.x-.001?[{from:_t.from,to:Nt[0]}]:[]:[_t]}))([K])(at))))(K=>(()=>{const nt=K.to.x-K.from.x;return Le(2)*(nt>=0?nt:-nt)<=28})()?[K]:[{from:K.from,to:{x:K.from.x+(K.to.x-K.from.x)*.495,y:K.from.y+(K.to.y-K.from.y)*.495}},{from:{x:K.from.x+(K.to.x-K.from.x)*.505,y:K.from.y+(K.to.y-K.from.y)*.505},to:K.to}]),mt=Jt.length,gt=K=>Vi(0)(G_(1)(I.t*rt(mt)-rt(K)));return n.bind(t.pushClip(ua(br(7)(x)))(ou))(()=>n.bind(o(K=>{const nt=K._1,ht=ae(1.4)(1.9)(H+(1303*(nt+1|0)|0)|0),_t=ae(.35)(.8)(ht.prng),Nt=o(wt=>n.bind(t.pushAlpha(wt.alpha*_t.value))(()=>n.bind(t.strokePath(k_(gt(nt))(wt.path))({color:ct,width:ht.value,lineJoin:ve,lineCap:vn}))(()=>r)))(ti({...L_,rMax:0,offset:.5})(H+(53*(nt+1|0)|0)|0)(!1)([K._2.from,K._2.to]));return gt(nt)>0?Nt:i.pure()})(Ft(Sn)(Jt)))(()=>u))})}return i.pure()})())(()=>n.bind((()=>{if(l==="LabelsShown")return o(I=>t.drawText({x:x.x+x.w/2,y:Y+rt(I._1)*E,content:I._2,font:v,color:_.text,align:Zr,baseline:or}))(Ft(Sn)(k));if(l==="LabelsHidden")return i.pure();g()})())(()=>n.bind((()=>{const I=f(_)(M)(et);return G?I:i.pure()})())(()=>n.bind(d)(()=>r)))))}));return V.alpha*h>0?R:i.pure()}},bJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=M_(t),o=t.popAlpha,u=Ke(n);return s=>a=>c=>{const f={...s,nodeFill:s.text,text:s.nodeFill,nodeStroke:s.nodeFill};return u(d=>{const l=fe(d._1)(c.nodes),_=fe(d._1)(a.nodes),h=(()=>{if(_.tag==="Just"&&l.tag==="Just"){const p=l._1,m=_._1;return r.bind(t.pushAlpha(d._2))(()=>r.bind(i(fa)(f)(1)(J)(d._1)(m)(p))(()=>o))}return n.pure()})();return d._2>0?h:n.pure()})(Pe(c.nodeInvert))}},kJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=Ke(n);return o=>u=>s=>{const a={family:o.fontFamily,size:11,weight:500};return i(c=>{if(c._2===""||(()=>{const l=Bn(c._1)(s.edges);return l.tag==="Nothing"||!(l.tag==="Just"&&l._1.tag==="Extended")})())return n.pure();const f=Bn(c._1)(u.edges),d=(()=>{if(f.tag==="Just")return mr(f._1)(.5);if(f.tag==="Nothing")return J;g()})();if(d.tag==="Nothing")return n.pure();if(d.tag==="Just"){const l=d._1;return r.bind(t.measureText(a)(c._2))(_=>{const h=_+12;return r.bind(t.drawRoundedRect({x:l.x-h/2,y:l.y-8.5,w:h,h:17})(3)(w("Just",{color:o.chipPillFill,flat:!0}))(J))(()=>t.drawText({x:l.x,y:l.y,content:c._2,font:a,color:o.chipPillText,align:Zr,baseline:or}))})}g()})(Pe(u.edgeLabels))}},O_=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>o=>r?e.bind(t.clearBackground(n.bgTransparent))(()=>t.setViewport(o)):n.wobble?e.bind(t.setViewport(o))(()=>t.clearBackground(n.bg)):e.bind(t.setViewport(o))(()=>t.backgroundDots({viewport:o,bgColor:n.bg,dotColor:n.bgDot,tile:12*i,dotRadius:.7*i}))},LJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=t.popAlpha;return o=>u=>s=>a=>c=>f=>d=>l=>_=>{const h=(()=>{if(_>1e-4&&d>1-_){const m=(1-d)/_;return m<0?0:m>1?1:m}if(l>1e-4&&d<l){const m=d/l;return m<0?0:m>1?1:m}return 1})(),p=Q_(a)(c)(f)(d)(l)(_);if(p.tag==="CircleShape")return o?A_(t)(p._1)(p._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(cu(p._1)(p._2))({color:u,flat:!0})({color:s,width:1,lineJoin:ve,lineCap:dn});if(p.tag==="PolyShape"&&o&&p._1.length>=3)return r.bind(t.pushAlpha(h))(()=>r.bind(A_(t)(N_(p._1))(6)({r:200,g:35,b:30,a:220}))(()=>i));if(p.tag==="PolyShape")return o?n.pure():p._1.length>=3?t.fillStrokePath(ua(p._1))({color:u,flat:!0})({color:s,width:1,lineJoin:ve,lineCap:dn}):n.pure();g()}},EJ=t=>{const e=t.Monad0().Bind1(),n=t.popAlpha;return r=>i=>o=>u=>s=>a=>c=>{const f=Kr(a)(c)(s),d={x:o.x+o.w/2,y:o.y+o.h/2},l={x:u.x+u.w/2,y:u.y+u.h/2},_=(h,p)=>e.bind(t.pushAlpha(p))(()=>e.bind(t.fillStrokePath(cu(h)(6))({color:r,flat:!0})({color:i,width:1,lineJoin:ve,lineCap:dn}))(()=>n));return f<.5?_(d,(()=>{const h=f*2;return 1-(h<0?0:h>1?1:h)*(h<0?0:h>1?1:h)*(h<0?3:h>1?1:3-2*h)})()):_(l,(()=>{const h=(f-.5)*2;return(h<0?0:h>1?1:h)*(h<0?0:h>1?1:h)*(h<0?3:h>1?1:3-2*h)})())}},pu=t=>{const e=LJ(t),n=EJ(t),r=t.Monad0().Applicative0(),i=Ke(r);return o=>u=>s=>a=>c=>i(f=>{if(f._2.tag==="Travelling"){const d=fe(f._2._1.target)(u.nodes),l=fe(f._2._1.source)(u.nodes);if(l.tag==="Just"&&d.tag==="Just"){const _=Bn(f._2._1.edge)(u.edges);if(_.tag==="Just")return e(o)(a)(c)((()=>{if(f._2._1.direction==="Forward")return _._1;if(f._2._1.direction==="Backward")return Te(_._1);g()})())(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);if(_.tag==="Nothing")return n(a)(c)(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);g()}return r.pure()}if(f._2.tag==="Filling"){if(o)return r.pure();const d=fe(f._2._1.node)(u.nodes);if(d.tag==="Just")return t.fillStrokePath(ua(br(4)(jr(2)(d._1))))({color:a,flat:!0})({color:c,width:1,lineJoin:ve,lineCap:dn});if(d.tag==="Nothing")return r.pure();g()}return r.pure()})(Pe(s.tokens))},R_=t=>{const e=pu(t),n=t.Monad0(),r=n.Bind1(),i=pu(t),o=wJ(t),u=t.popClip,s=t.popBlend,a=t.popLayer,c=n.Applicative0(),f=Ke(c),d=t.popAlpha;return l=>_=>h=>p=>{const m=_.wobble?e(!0)(h)(p)(_.tokenInside)(_.tokenInsideStroke):r.bind(t.insideTokenStyle(l))(x=>{if(x==="GenieSilhouette")return i(!1)(h)(p)(_.tokenInside)(_.tokenInsideStroke);if(x==="ConvexAbsorb")return o(h)(p)(_.tokenInside)(_.tokenInsideStroke);g()});if(_.tokenInsideBlend==="Difference")return r.bind(t.pushLayer($2))(()=>r.bind(t.pushBlend(uu))(()=>r.bind(t.pushClip(da(h)(p))(ou))(()=>r.bind(m)(()=>r.bind(u)(()=>r.bind(s)(()=>r.bind(a)(()=>r.bind(t.pushLayer(X2))(()=>r.bind(f(x=>{const y=fe(x._1)(p.nodes);return y.tag==="Just"&&au(y._1).alpha>0?a_(t)(x._2.shape)({x:x._2.x,y:x._2.y,w:x._2.w,h:x._2.h})(7)(w("Just",{color:ie,flat:!1}))(J):c.pure()})(Pe(h.nodes)))(()=>a)))))))));if(_.tokenInsideBlend==="Normal")return r.bind(t.pushClip(da(h)(p))(ou))(()=>r.bind(t.pushAlpha(_.tokenInsideAlpha))(()=>r.bind(m)(()=>r.bind(d)(()=>u))));g()}},B_=t=>{const e=t.Monad0().Bind1(),n=pu(t),r=pu(t),i=t.popClip,o=t.popLayer;return u=>s=>a=>c=>e.bind(t.pushLayer(H2))(()=>e.bind(t.pushClip(xJ(s)(a)(c))(V2))(()=>e.bind(u.wobble?n(!0)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke):r(!1)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke))(()=>e.bind(i)(()=>o))))},CJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=Ke(r);return o=>u=>s=>a=>c=>f=>{const d=bo(f).length,l=rt(d+1|0),_=m=>{const x=(s*l-rt(m))/1.5,y=x<0?0:x>1?1:x;return y*y*(3-2*y)},h=(m=>{let x=m,y=!0,N;for(;y;){const v=x;if(v>=d){y=!1,N=v;continue}if(_(v)>=1){x=v+1|0;continue}y=!1,N=v}return N})(0),p=h>=d?[]:gr(m=>_(m)>0)(Dt(h,d-1|0)).init;return n.bind((()=>{const m=t.drawText({x:a,y:c,content:me(h)(f),font:o,color:u,align:na,baseline:or});return h>0?m:r.pure()})())(()=>i(m=>n.bind(t.measureText(o)(me(m)(f)))(x=>{const y=_(m);return t.drawText({x:a+x,y:c-(1-y)*10,content:me(1)(mi(jn(me(m)(f)))(f)),font:o,color:{...u,a:de(hn(y*rt(u.a)))},align:na,baseline:or})}))(p))}},mu=t=>e=>n=>r=>{const i=z(_=>rt(hu(1)(bo(_).length)))(r),o=Vi(1)(T(Pr)(0)(i)),u=Kr(e)(n)(t),s=u*o,a=hu(1)(r.length),c=(_=>h=>p=>{let m=_,x=h,y=p,N=!0,v;for(;N;){const L=m,k=x,E=At(O=>J,O=>Y=>w("Just",{head:O,tail:Y}),y);if(E.tag==="Nothing"){N=!1,v=hu(0)(a-1|0);continue}if(E.tag==="Just"){if(k+E._1.head>=s){N=!1,v=L;continue}m=L+1|0,x=k+E._1.head,y=E._1.tail;continue}g()}return v})(0)(0)(i),f=T(Pr)(0)(c<1?[]:bt(0,c,i)),d=f/o;if(c>=0&&c<i.length){const _=(f+i[c])/o;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(_<=d)return 1;const h=(u-d)/(_-d);return h<0?0:h>1?1:h})()}}const l=(f+1)/o;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(l<=d)return 1;const _=(u-d)/(l-d);return _<0?0:_>1?1:_})()}},SJ=t=>{const e=t.Monad0();return n=>r=>i=>e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(mu(r)(0)(0)(z(ud)(i)).line))(o=>{const u=o+28;return e.Applicative0().pure({x:n.x+n.w/2-u/2,y:n.y-25.2-14,w:u,h:25.2})})},GJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=SJ(t),i=e.Applicative0(),o=ar.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>I_(yt(c=>c)(a)))(o(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const c=fe(a._2._1.node)(u.nodes);if(c.tag==="Just")return n.bind(r(c._1)(a._2._1.progress)(a._2._1.labels))(f=>i.pure(w("Just",b(a._1,f))));if(c.tag==="Nothing")return i.pure(J);g()}return i.pure(J)})(Pe(s.tokens)))},PJ=t=>{const e=t.Monad0();return n=>r=>i=>o=>u=>s=>a=>{const c=F_(n)(r)(i)(o)(u)(s);return e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(mu(o)(u)(s)(Tt(a)(la)).line))(f=>e.Applicative0().pure({x:c.x+14+f/2-f/2-14,y:c.y-6-8-6.6-6,w:f+28,h:25.2}))}},IJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=PJ(t),i=e.Applicative0(),o=ar.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>I_(yt(c=>c)(a)))(o(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const c=fe(a._2._1.target)(u.nodes),f=fe(a._2._1.source)(u.nodes),d=Bn(a._2._1.edge)(u.edges);if(d.tag==="Just"&&f.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 Te(d._1);g()})())(f._1)(c._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(l=>i.pure(w("Just",b(a._1,l))))}return i.pure(J)})(Pe(s.tokens)))},ha=t=>{const e=t.Monad0(),n=e.Bind1(),r=IJ(t),i=GJ(t);return o=>u=>n.bind(r(o)(u))(s=>n.bind(i(o)(u))(a=>e.Applicative0().pure(mJ((()=>{const c=f=>{if(f.tag==="Leaf")return Q;if(f.tag==="Node")return zt("Node",f._1,f._2,f._3,void 0,c(f._5),c(f._6));g()};return Lt(C.compare)(Ct(qe.foldr,c(s)))})())(s)([...yt(c=>{const f=fe(c._1)(u.nodes);return f.tag==="Just"&&au(f._1).alpha>0?w("Just",{x:c._2.x,y:c._2.y,w:c._2.w,h:c._2.h}):J})(Pe(o.nodes)),...(()=>{const c=(f,d)=>{if(f.tag==="Leaf")return d;if(f.tag==="Node")return c(f._5,qt("Cons",f._4,c(f._6,d)));g()};return Ct($t.foldr,c(a,Ht))})()]))))},W_=t=>e=>n=>{const r=ki(6)(.55)(lu(0)(1)((1-t)/.06)),i=t>.94,o=i&&n>1e-4,u=ki(6)(.55)(lu(0)(1)(t/.06)),s=t<.06,a=s&&e>1e-4,c=i&&n<=1e-4;return{popScale:a?u:o?r:1,flipY:s&&e<=1e-4?u:c?r:1,fadeAlpha:(()=>{if(a){const f=t/.06;return f<0?.55:f>1?1:.55+.44999999999999996*f}if(o){const f=(1-t)/.06;return f<0?.55:f>1?1:.55+.44999999999999996*f}return 1})()}},DJ=t=>{const e=t.Monad0().Bind1(),n=D_(t);return r=>i=>o=>u=>s=>{const a=W_(u)(0)(0),c={family:r.fontFamily,size:11,weight:500},f=mu(u)(0)(0)(Tt(s)(la));return e.bind(t.measureText(c)(f.line))(d=>{const l=o.x+o.w/2,_=d+28,h=o.y-25.2-14,p=l-_/2,m=[1,l,h+25.2,2,l,o.y],x={x:l,y:h+12.6};return n(a)(l-_/2)(h+25.2)(x)(e.bind(t.drawRoundedRect({x:l-_/2,y:h+1.5,w:_,h:25.2})(6)(w("Just",{color:r.chipShadow,flat:!0}))(J))(()=>e.bind(t.drawRoundedRect({x:p,y:h,w:_,h:25.2})(6)(w("Just",{color:r.chip,flat:!0}))(w("Just",{color:r.chipHairline,width:1,lineJoin:ve,lineCap:dn})))(()=>e.bind(t.strokePath(m)({color:r.chipHairline,width:1,lineJoin:ve,lineCap:dn}))(()=>t.drawText({x:l,y:x.y,content:f.line,font:c,color:r.chipText,align:Zr,baseline:or})))))})}},QJ=t=>{const e=D_(t),n=t.Monad0(),r=n.Bind1(),i=Ke(n.Applicative0()),o=CJ(t);return u=>s=>a=>c=>f=>d=>l=>_=>h=>{const p=mu(f)(d)(l)(Tt(_)(la)),m=p.line,x=p.phaseInLabel/.45,y=x<0?0:x>1?1:x,N=h.w,v=h.y,L=h.x,k=L+14,E=h.h,O=v+E/2;return e(W_(f)(d)(l))(L)(v+E)({x:L+N/2,y:O})(r.bind(i(Y=>t.fillPath(cu(Y)(1.5))({color:u.trailDot,flat:!0}))(NJ(h)(F_(s)(a)(c)(f)(d)(l))))(()=>r.bind(t.drawRoundedRect({x:L,y:v,w:N,h:E})(3)(w("Just",{color:u.chipPillFill,flat:!0}))(J))(()=>o({family:u.fontFamily,size:11,weight:500})(u.chipPillText)(y)(k)(O)(m))))}},pa=t=>{const e=QJ(t),n=t.Monad0(),r=n.Applicative0(),i=DJ(t),o=n.Bind1(),u=Ke(r),s=t.popLayer;return a=>c=>f=>d=>o.bind(t.pushLayer(Y2))(()=>o.bind(u(l=>{if(l._2.tag==="Travelling"){if(l._2._1.labels.length!==0){const _=fe(l._2._1.target)(c.nodes),h=fe(l._2._1.source)(c.nodes),p=Bn(l._2._1.edge)(c.edges),m=P_(l._1)(d);if(m.tag==="Just"&&p.tag==="Just"&&h.tag==="Just"&&_.tag==="Just")return e(a)((()=>{if(l._2._1.direction==="Forward")return p._1;if(l._2._1.direction==="Backward")return Te(p._1);g()})())(h._1)(_._1)(l._2._1.progress)(l._2._1.holdPre)(l._2._1.holdPost)(l._2._1.labels)(m._1)}return r.pure()}if(l._2.tag==="Filling"&&l._2._1.labels.length!==0){const _=fe(l._2._1.node)(c.nodes);if(_.tag==="Just")return i(a)(c)(_._1)(l._2._1.progress)(l._2._1.labels);if(_.tag==="Nothing")return r.pure();g()}return r.pure()})(Pe(f.tokens)))(()=>s))},z_=t=>{const e=ha(t),n=pa(t);return r=>i=>o=>t.Monad0().Bind1().bind(e(i)(o))(u=>n(r)(i)(o)(u))},FJ=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>i=>{const o=i.length-1|0,u=o<1?[]:bt(0,o,i),s=u.length-1|0,a=s>=0&&s<u.length?w("Just",u[s]):J,c=i.length-1|0,f=c>=0&&c<i.length?w("Just",i[c]):J;if(f.tag==="Just"&&a.tag==="Just"){const d=ae(.78)(1.18)(Yi(i)+19|0),l=ae(.4)(.62)(d.prng),_=r.wobble?8.75*l.value:4.375,h=ae(.4)(.62)(l.prng),p=r.wobble?8.75*h.value:4.375,m=f._1.y-a._1.y,x=f._1.x-a._1.x,y=Le(x*x+m*m),N=m/y,v=-N,L=x/y,k=f._1.x+L*.875,E=f._1.y+N*.875,O=r.wobble?8.75*d.value:8.75,Y=k-L*O,et=E-N*O,G=Y+v*_,P=et+L*_,V=[1,k,E,2,Y+v*4.375,et+L*4.375,2,Y-v*4.375,et-L*4.375,5],U=Y-v*p,B=et-L*p,R={color:r.arrowFill,width:2,lineJoin:ve,lineCap:vn};return y<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,G,P,2,k,E])(R))(()=>t.strokePath([1,U,B,2,k,E])(R)):t.fillPath(V)({color:r.arrowFill,flat:!0})}return n.pure()}},AJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=Ke(n),o=t.popAlpha,u=FJ(t);return s=>a=>c=>f=>{const d=WN(8)(c);if(f.hi<=f.lo)return n.pure();const l=UN(d)(f.lo)(f.hi);if(l.length===0)return n.pure();const _={color:s.edge,width:s.wobble?2:.9375,lineJoin:ve,lineCap:vn},h=s.wobble?ae(-10)(4)(Yi(l)).value:0,p=s.wobble?oJ(h)(l):l;return r.bind(s.wobble?i(m=>r.bind(t.pushAlpha(m.alpha))(()=>r.bind(t.strokePath(m.path)(_))(()=>o)))((()=>{const m=Yi(l);return p.length<2?[]:ti(TJ)(m)(!1)(p)})()):t.strokePath(MN(l))(_))(()=>{const m=u(s)(p);return f.hi>=.999?m:n.pure()})}},q_=t=>{const e=AJ(t),n=t.Monad0().Applicative0(),r=Ke(n);return i=>o=>u=>{const s=a=>{const c=Vt(f=>a.x>=f._2.x-1&&a.x<=f._2.x+f._2.w+1&&a.y>=f._2.y-1&&a.y<=f._2.y+f._2.h+1)(Pe(o.nodes));return c.tag==="Just"?w("Just",c._1._2):J};return r(a=>{const c=Bn(a._1)(u.edges);if(c.tag==="Just")return e(i)(a._1)((()=>{const f=(()=>{if(0<a._2.length){const l=s(a._2[0]);if(l.tag==="Just")return Te(T_(br(7)(l._1))(Te(a._2)))}return a._2})(),d=f.length-1|0;if(d>=0&&d<f.length){const l=s(f[d]);if(l.tag==="Just")return T_(br(7)(l._1))(f)}return f})())((()=>{if(c._1.tag==="Retracted")return{lo:0,hi:0};if(c._1.tag==="Extended")return{lo:0,hi:1};if(c._1.tag==="Extending")return{lo:0,hi:c._1._2};if(c._1.tag==="Retracting"){if(c._1._1==="FromSource")return{lo:c._1._2,hi:1};if(c._1._1==="FromTarget")return{lo:0,hi:1-c._1._2};if(c._1._1==="FromBoth")return{lo:c._1._2/2,hi:1-c._1._2/2}}g()})());if(c.tag==="Nothing")return n.pure();g()})(Pe(o.edges))}},MJ=t=>e=>{const n=o=>{const u=fe(o)(t.nodes);if(u.tag==="Nothing")return!1;if(u.tag==="Just"){const s=u._1;return!Be(a=>0<a._2.length&&a._2[0].x>=s.x&&a._2[0].x<=s.x+s.w&&a._2[0].y>=s.y&&a._2[0].y<=s.y+s.h,Pe(t.edges))}g()},r=T(o=>u=>(o*31|0)+Dn(u)|0)(5381)(Kn(e.frameTitle)),i=o=>{const u=fe(o)(t.nodes);if(u.tag==="Nothing")return!1;if(u.tag==="Just"){const s=u._1;return!Be(a=>{const c=a._2.length-1|0;return c>=0&&c<a._2.length&&a._2[c].x>=s.x&&a._2[c].x<=s.x+s.w&&a._2[c].y>=s.y&&a._2[c].y<=s.y+s.h},Pe(t.edges))}g()};return T(o=>u=>{const s=u._2;return dJ(a=>{if(a.tag==="Nothing")return w("Just",s);if(a.tag==="Just")return w("Just",{t:Vi(a._1.t)(s.t),angle:s.t>=a._1.t?s.angle:a._1.angle,bigCircle:a._1.bigCircle||s.bigCircle,frameHash:a._1.frameHash});g()})(u._1)(o)})(Q)(Tt(Pe(e.tokens))(o=>{if(o._2.tag==="Filling"){const u=o._2._1.node;return[b(u,{t:1,angle:(()=>{const s=yt(a=>(()=>{const c=fe(u)(t.nodes),f=a._2.length-1|0;return f>=0&&f<a._2.length&&c.tag==="Just"&&a._2[f].x>=c._1.x&&a._2[f].x<=c._1.x+c._1.w&&a._2[f].y>=c._1.y&&a._2[f].y<=c._1.y+c._1.h})()?w("Just",a._2):J)(Pe(t.edges));if(0<s.length){const a=s[0].length-1|0,c=a<1?[]:bt(0,a,s[0]),f=c.length-1|0;if(f>=0&&f<c.length){const d=s[0].length-1|0;return d>=0&&d<s[0].length?fr(s[0][d].y-c[f].y)(s[0][d].x-c[f].x):0}s[0].length-1|0}return 0})(),bigCircle:n(u)||i(u),frameHash:r})]}if(o._2.tag==="Travelling"){if(o._2._1.progress>=.75)return[b(o._2._1.target,{t:(o._2._1.progress-.75)/.25,angle:(()=>{const u=Bn(o._2._1.edge)(t.edges);if(u.tag==="Just"){const s=u._1.length-1|0,a=s<1?[]:bt(0,s,u._1),c=a.length-1|0;if(c>=0&&c<a.length){const f=u._1.length-1|0;return f>=0&&f<u._1.length?fr(u._1[f].y-a[c].y)(u._1[f].x-a[c].x):0}return u._1.length-1|0,0}if(u.tag==="Nothing")return 0;g()})(),bigCircle:n(o._2._1.target)||i(o._2._1.target),frameHash:r})];if(o._2._1.progress<.25)return[b(o._2._1.source,{t:o._2._1.progress/.25,angle:(()=>{const u=Bn(o._2._1.edge)(t.edges);if(u.tag==="Just")return 1<u._1.length&&0<u._1.length?fr(u._1[1].y-u._1[0].y)(u._1[1].x-u._1[0].x):0;if(u.tag==="Nothing")return 0;g()})(),bigCircle:n(o._2._1.source)||i(o._2._1.source),frameHash:r})]}return[]}))},OJ=t=>T(e=>n=>(e*31|0)+Dn(n)|0)(5381)(Kn(t.frameTitle)),H_=t=>{const e=M_(t),n=t.Monad0().Applicative0(),r=Ke(n);return i=>o=>u=>s=>{const a=OJ(s),c=MJ(u)(s);return r(f=>{const d=fe(f._1)(s.nodes);if(d.tag==="Just")return e(i)(o)((()=>{const l=fe(f._1)(s.nodeFadeAlpha);if(l.tag==="Nothing")return 1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=fe(f._1)(c);return l.tag==="Just"?w("Just",l._1):l.tag==="Nothing"&&lJ(f._1)(s.visited)?w("Just",{t:1,angle:0,bigCircle:!1,frameHash:a}):J})())(f._1)(f._2)(d._1);if(d.tag==="Nothing")return n.pure();g()})(Pe(u.nodes))}},$_=t=>t,X_=t=>e=>{const n=e.vw/e.vh,r=e.vh*t,i={...e,vx:e.vx-(r-e.vw)/2,vw:r},o=e.vw/t,u={...e,vy:e.vy-(o-e.vh)/2,vh:o};return t<=0||e.vw<=0||e.vh<=0?e:t>n?i:t<n?u:e},RJ=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},Y_=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},V_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ma=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},BJ=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},WJ=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},zJ=t=>e=>{const n=$e(t.angle),r=nn(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},qJ=t=>[t.box.ground.a,t.box.ground.b,t.box.ground.c,t.box.ground.d,t.box.top.a,t.box.top.b,t.box.top.c,t.box.top.d],ei=t=>e=>{const n=r=>RJ(0)(255)(de(Un(rt(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},Ce=t=>e=>n=>r=>({x:(e-n)*nn(t.angle),y:(e+n)*$e(t.angle)-r}),Lr=t=>{const e=At(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Tt(e._1.tail)(n=>[2,n.x,n.y]),5];g()},HJ=t=>e=>n=>r=>i=>{const o=(()=>{if(t==="Forward")return i;if(t==="Backward")return Te(i);g()})();if(0<o.length){const s=mr(o)(Y_(0)(1)(Kr(n)(r)(e)));if(s.tag==="Nothing")return o[0];if(s.tag==="Just")return s._1;g()}const u=mr(o)(Y_(0)(1)(Kr(n)(r)(e)));if(u.tag==="Nothing")return{x:0,y:0};if(u.tag==="Just")return u._1;g()},$J=t=>{const e=At(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Tt(e._1.tail)(n=>[2,n.x,n.y])];g()},XJ=t=>{const e=At(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{vx:0,vy:0,vw:0,vh:0};if(e.tag==="Just"){const n=T(r=>i=>({minX:V_(r.minX)(i.x),minY:V_(r.minY)(i.y),maxX:ma(r.maxX)(i.x),maxY:ma(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{vx:n.minX-40,vy:n.minY-40,vw:n.maxX-n.minX+80,vh:n.maxY-n.minY+80}}g()},YJ=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>{const o=i.box,u=i.np,s={color:r.nodeStroke,width:1,lineJoin:ve,lineCap:dn};return e.bind(t.fillStrokePath(Lr([o.ground.d,o.ground.c,o.top.c,o.top.d]))({color:ei(.66)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(Lr([o.ground.b,o.ground.c,o.top.c,o.top.b]))({color:ei(.82)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(Lr([o.top.a,o.top.b,o.top.c,o.top.d]))({color:ei(1)(r.nodeFill),flat:!0})(s))(()=>t.drawTextAffine(zJ(n)(u.y+u.h))({x:u.x+u.w/2,y:0,content:u.label,font:{family:r.fontFamily,size:11,weight:600},color:r.text,align:Zr,baseline:or}))))}},VJ=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>o=>{const u={color:r.tokenOutsideStroke,width:1,lineJoin:ve,lineCap:dn},s=o.x-5.5,a=o.x+5.5,c=o.y-5.5,f=o.y+5.5,d=i+11,l=Ce(n)(s)(c)(d),_=Ce(n)(a)(c)(d),h=Ce(n)(a)(f)(d),p=Ce(n)(s)(f)(d),m=Ce(n)(a)(f)(i),x=Ce(n)(a)(c)(i);return e.bind(t.fillStrokePath(Lr([Ce(n)(s)(f)(i),m,h,p]))({color:ei(.66)(r.tokenOutsideFill),flat:!0})(u))(()=>e.bind(t.fillStrokePath(Lr([x,m,h,_]))({color:ei(.82)(r.tokenOutsideFill),flat:!0})(u))(()=>t.fillStrokePath(Lr([l,_,h,p]))({color:ei(1)(r.tokenOutsideFill),flat:!0})(u)))}},UJ=t=>{const e=VJ(t);return n=>r=>i=>o=>{if(o.tag==="Travelling"){const u=BJ(o._1.edge)(i.edges);return u.tag==="Just"?w("Just",(()=>{const s=HJ(o._1.direction)(o._1.progress)(o._1.holdPre)(o._1.holdPost)(u._1);return{depth:s.x+s.y,draw:e(n)(r)(0)(s)}})()):J}if(o.tag==="Filling"){const u=WJ(o._1.node)(i.nodes);if(u.tag==="Just")return w("Just",(()=>{const s={x:u._1.x+u._1.w/2,y:u._1.y+u._1.h/2};return{depth:s.x+s.y,draw:e(n)(r)(n.boxHeight)(s)}})())}return J}},ZJ={angle:.5235987755982988,boxHeight:26,transparentBg:!0},KJ=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:Ce(t)(e.x)(e.y)(0),b:Ce(t)(r)(e.y)(0),c:Ce(t)(r)(n)(0),d:Ce(t)(e.x)(n)(0)},top:{a:Ce(t)(e.x)(e.y)(t.boxHeight),b:Ce(t)(r)(e.y)(t.boxHeight),c:Ce(t)(r)(n)(t.boxHeight),d:Ce(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},U_=t=>e=>z(n=>({np:n,box:KJ(t)(n)}))((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Ct($t.foldr,n(e.nodes,Ht))})()),jJ=t=>e=>[...Tt(U_(t)(e))(qJ),...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Tt(Ct($t.foldr,n(e.edges,Ht)))(z(r=>Ce(t)(r.x)(r.y)(0)))})()],tT=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=ma(1e-4)(Le(n*n+e*e)),i=e/r,o=n/r,u=t.to.y-i*7,s=t.to.x-o*7;return Lr([t.to,{x:s-i*3,y:u+o*3},{x:s+i*3,y:u-o*3}])},eT=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>i=>o=>u=>s=>{const a=Ce(r)(s.x)(s.y)(0),c=Ce(r)(u.x)(u.y)(0);return e.Bind1().bind(t.strokePath($J([c,a]))({color:i.edge,width:1.5,lineJoin:ve,lineCap:vn}))(()=>{const f=t.fillPath(tT({from:c,to:a}))({color:i.arrowFill,flat:!0});return o?f:n.pure()})}},nT=t=>{const e=eT(t);return n=>r=>i=>{const o=we(Sn,i,bt(1,i.length,i)),u=o.length-1|0;return Ft(s=>a=>({depth:(a._1.x+a._1.y+a._2.x+a._2.y)/2,draw:e(n)(r)(s===u)(a._1)(a._2)}))(o)}},rT=t=>{const e=YJ(t),n=UJ(t),r=nT(t),i=t.Monad0(),o=O_(t),u=Cu(i.Applicative0())(Wt);return s=>a=>c=>f=>{const d=_a(a),l=[...(()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,qt("Cons",h._4,_(h._6,p)));g()};return Tt(Ct($t.foldr,_(c.edges,Ht)))(r(s)(d))})(),...z(_=>({depth:_.box.depth,draw:e(s)(d)(_)}))(U_(s)(c)),...yt(n(s)(d)(c))((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,qt("Cons",h._4,_(h._6,p)));g()};return Ct($t.foldr,_(f.tokens,Ht))})())];return i.Bind1().bind(o(d)(s.transparentBg)(1)(XJ(jJ(s)(c))))(()=>u(_=>_.draw)(Lt(_=>h=>ut.compare(_.depth)(h.depth))(l)))}},Z_=(t,e)=>({tag:t,_1:e}),iT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},oT=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},uT=Z_("ResolvedLabels"),sT=t=>{const e=Vt(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return Do(t);g()},aT=t=>e=>n=>{const r=n.frameTitle===""?0:40,i=rs(e)(n.camera);return(()=>{if(t.outputAspect.tag==="Nothing")return $_;if(t.outputAspect.tag==="Just")return X_(t.outputAspect._1);g()})()({vx:i.x-t.padding,vy:i.y-t.padding-r,vw:i.w+2*t.padding,vh:i.h+2*t.padding+r})},cT=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=iT(e._1)(t.segment.layout.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1.x*t.segment.placement.scale+t.segment.placement.tx,i=n._1.y*t.segment.placement.scale+t.segment.placement.ty,o=n._1.w*t.segment.placement.scale,u=n._1.h*t.segment.placement.scale;return[1,r,i,2,r+o,i,2,r+o,i+u,2,r,i+u,5]}}g()},gT=t=>{const e=t.Monad0(),n=e.Bind1();return r=>i=>{if(r==="")return e.Applicative0().pure();const o=i.vh/720,u=56*o,s={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:700};return n.bind(t.measureText(s)(r))(a=>{const c=u+16*o*2,f=a+28*o*2,d=i.vy+i.vh/2,l=i.vx+i.vw/2;return n.bind(t.drawRoundedRect({x:l-f/2,y:d-c/2,w:f,h:c})(16*o)(w("Just",{color:{r:255,g:255,b:255,a:235},flat:!0}))(w("Just",{color:{r:0,g:0,b:0,a:255},width:1.5*o,lineJoin:ve,lineCap:vn})))(()=>t.drawText({x:l,y:d,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:Zr,baseline:or}))})}},fT=t=>{const e=t.Monad0(),n=e.Bind1();return r=>i=>{if(r==="")return e.Applicative0().pure();const o=i.vh/720,u=15*o,s={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:600};return n.bind(t.measureText(s)(r))(a=>{const c=i.vy+12*o,f=u+6*o*2,d=a+11*o*2,l=i.vx+i.vw/2;return n.bind(t.drawRoundedRect({x:l-d/2,y:c,w:d,h:f})(f/2)(w("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}))(w("Just",{color:{r:0,g:0,b:0,a:255},width:1*o,lineJoin:ve,lineCap:vn})))(()=>t.drawText({x:l,y:c+f/2,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:Zr,baseline:or}))})}},_T=t=>{const e=z_(t),n=pa(t),r=t.Monad0(),i=r.Bind1(),o=O_(t),u=r.Applicative0(),s=q_(t),a=H_(t)(fa),c=bJ(t),f=B_(t),d=R_(t),l=kJ(t),_=gT(t),h=fT(t);return p=>m=>x=>y=>N=>v=>L=>{const k=_a(p.theme),E=(()=>{if(L.tag==="ResolvedLabels")return e(k)(N)(v);if(L.tag==="SpringLabels")return n(k)(N)(v)(L._1);g()})();return i.bind(o(k)(p.transparentBg)(m)(y))(()=>i.bind((()=>{const O=i.bind(s(k)(N)(v))(()=>i.bind(a(k)(N)(v))(()=>i.bind(c(k)(N)(v))(()=>i.bind(f(k)(y)(N)(v))(()=>i.bind(d(j2)(k)(N)(v))(()=>i.bind(E)(()=>{const Y=l(k)(N)(v);return v.staticKind!=="Animated"?Y:u.pure()}))))));return x?O:u.pure()})())(()=>i.bind(p.watermark===""?t.Monad0().Applicative0().pure():t.drawText({x:y.vx+6,y:y.vy+6,content:p.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:na,baseline:q2}))(()=>v.staticKind==="TitleCard"?_(v.frameTitle)(y):h(v.frameTitle)(y))))}},dT=t=>{const e=t.Monad0(),n=z_(t),r=pa(t),i=e.Bind1(),o=q_(t),u=H_(t),s=B_(t),a=t.popTransform,c=R_(t),f=t.popBakedTransform,d=t.popClip,l=t.popAlpha;return _=>h=>p=>m=>x=>{const y=x.state,N={tx:x.segment.placement.tx,ty:x.segment.placement.ty,sx:x.segment.placement.scale,sy:x.segment.placement.scale},v=_a(_.theme),L=x.segment.layout,k=Ve(L),E={vx:k.x-1e3,vy:k.y-1e3,vw:k.w+2e3,vh:k.h+2e3},O=11*x.segment.placement.scale*h>=5?fa:hJ,Y=(()=>{if(O==="LabelsHidden")return e.Applicative0().pure();if(O==="LabelsShown")return p.tag==="Leaf"?n(v)(L)(y):r(v)(L)(y)(p);g()})(),et=cT(m)((()=>{const G=x.segment.path.length-1|0;return G>=0&&G<x.segment.path.length?w("Just",x.segment.path[G]):J})());return i.bind(t.pushAlpha(x.bgAlpha))(()=>i.bind(t.pushClip(et)(ou))(()=>i.bind(t.pushTransform(N))(()=>i.bind(o(v)(L)(y))(()=>i.bind(u(O)(v)(L)(y))(()=>i.bind(s(v)(E)(L)(y))(()=>i.bind(a)(()=>i.bind(t.pushBakedTransform(N))(()=>i.bind(c(tN)(v)(L)(y))(()=>i.bind(f)(()=>i.bind(t.pushTransform(N))(()=>i.bind(Y)(()=>i.bind(a)(()=>i.bind(d)(()=>l))))))))))))))}},lT=t=>e=>{const n=rs(t)(e);return{vx:n.x,vy:n.y,vw:n.w,vh:n.h}},ni=t=>e=>e.diving||e.levels.length>1?(()=>{if(t.outputAspect.tag==="Nothing")return $_;if(t.outputAspect.tag==="Just")return X_(t.outputAspect._1);g()})()(lT(e.rootLayout)(e.camera)):aT(t)(e.rootLayout)({...Do(e).state,camera:e.camera}),K_=t=>{const e=rT(t),n=t.Monad0(),r=n.Applicative0(),i=n.Bind1(),o=dT(t),u=_T(t);return s=>a=>c=>{if(s.theme==="Isometric")return e({...ZJ,transparentBg:s.transparentBg})(s.theme)(Do(c).segment.layout)(Do(c).state);const f=ni(s)(c),d=_=>h=>{if(h.length===0)return r.pure();const p=At(m=>J,m=>x=>w("Just",{head:m,tail:x}),h);if(p.tag==="Nothing")return r.pure();if(p.tag==="Just"){const m=p._1.head,x=p._1.tail;return i.bind((()=>{const y=o(s)(c.camera.zoom)(m.role==="Active"?a:Q)(_)(m);return c.diving||m.role==="Active"?y:r.pure()})())(()=>d(m)(x))}g()},l=At(_=>J,_=>h=>w("Just",{head:_,tail:h}),c.levels);if(l.tag==="Nothing")return r.pure();if(l.tag==="Just"){const _=l._1.tail,h=l._1.head;return i.bind(u(s)(c.hasDives?f.vw/oT(1)(Ve(c.rootLayout).w):1)(h.role==="Active"||h.role==="FlyThrough")(f)(h.segment.layout)(sT(c).state)(_.length===0&&a.tag!=="Leaf"?Z_("SpringLabels",a):uT))(()=>d(h)(_))}g()}},j_=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},hT=ha(f_),t1=K_(f_),e1=t=>{const e=t.vx+t.vw-4,n=t.vy+t.vh-4,r=t.vx+4,i=t.vy+4,o=u=>{if(u.tag==="Leaf")return Q;if(u.tag==="Node")return zt("Node",u._1,u._2,u._3,{...u._4,x:j_(r)(e-u._4.w)(u._4.x),y:j_(i)(n-u._4.h)(u._4.y)},o(u._5),o(u._6));g()};return o},pT=t=>e=>n=>r=>i=>o=>u=>{const s={padding:8,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?J:w("Just",r.width/r.height)},a=lN(n)(r);return()=>{const c=a(),f=i.levels.length-1|0;if(f>=0&&f<i.levels.length){const l=hT(i.levels[f].segment.layout)(i.levels[f].state)(c)(),_=ta(o)(e1(ni(s)(i))(l))(u);return t1(s)(_.applied)(i)(c)(),_.springs}const d=ta(o)(e1(ni(s)(i))(Q))(u);return t1(s)(d.applied)(i)(c)(),d.springs}},mT=t=>t,Ui=t=>t,xa=Ui("Light"),xT=Ui("Dark"),yT=Ui("Blueprint"),NT=Ui("Whiteboard"),JT=Ui("Isometric"),TT=mT("TransparentBackground"),ur=t=>"rgb("+oe(t.r)+","+oe(t.g)+","+oe(t.b)+")",Ln=di(fi("Fixed",_i(0)(20)(4))),wT=t=>"translate("+Ln(t.tx)+","+Ln(t.ty)+") scale("+Ln(t.sx)+","+Ln(t.sy)+")",kt=di(fi("Fixed",_i(0)(20)(2))),ya=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,i=r>=0&&r<t.length?w("Just",t[r]):J;if(i.tag==="Nothing"){n=t.length;continue}if(i.tag==="Just"){if(i._1===1){e.push("M"),e.push(kt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===2){e.push("L"),e.push(kt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===3){e.push("Q"),e.push(kt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),n=r+5|0;continue}if(i._1===4){e.push("C"),e.push(kt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+5|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+6|0;return o>=0&&o<t.length?t[o]:0})())),n=r+7|0;continue}if(i._1===5){e.push("Z"),n=r+1|0;continue}n=t.length;continue}g()}return wo(" ")(e)},vT={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},Na=(()=>{const t=er("&")("&amp;"),e=er("<")("&lt;"),n=(()=>{const r=er(">")("&gt;"),i=(()=>{const o=er('"')("&quot;");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),bT=t=>{if(t.style==="RunText")return"<tspan>"+Na(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+Na(t.text)+"</tspan>";g()},Ae=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},kT=t=>e=>{const n=[];let r=0;const i=o=>{const u=o>=0&&o<e.length?t.sx*e[o]+t.tx:t.sx*0+t.tx;return()=>{n.push(u),n.push((()=>{const s=o+1|0;return s>=0&&s<e.length?t.sy*e[s]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const o=r,u=o>=0&&o<e.length?w("Just",e[o]):J;if(u.tag==="Nothing"){r=e.length;continue}if(u.tag==="Just"){if(u._1===1){n.push(u._1),i(o+1|0)(),r=o+3|0;continue}if(u._1===2){n.push(u._1),i(o+1|0)(),r=o+3|0;continue}if(u._1===3){n.push(u._1),i(o+1|0)(),i(o+3|0)(),r=o+5|0;continue}if(u._1===4){n.push(u._1),i(o+1|0)(),i(o+3|0)(),i(o+5|0)(),r=o+7|0;continue}if(u._1===5){n.push(u._1),r=o+1|0;continue}r=e.length;continue}g()}return n},xu=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return kT(r._1)(e);g()}},n1={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>vT},LT={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>n1},ET={pure:t=>e=>()=>t,Apply0:()=>n1},CT={Applicative0:()=>ET,Bind1:()=>LT},ST=t=>e=>'<defs><pattern id="'+t+'" x="0" y="0" width="'+kt(e.tile)+'" height="'+kt(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+kt(e.tile)+'" height="'+kt(e.tile)+'" fill="'+ur(e.bgColor)+'" fill-opacity="'+kt(rt(e.bgColor.a)/255)+'"/>')+'<circle cx="'+kt(e.tile/2)+'" cy="'+kt(e.tile/2)+'" r="'+kt(e.dotRadius)+'" fill="'+ur(e.dotColor)+'"/></pattern></defs><rect x="'+kt(e.viewport.vx)+'" y="'+kt(e.viewport.vy)+'" width="'+kt(e.viewport.vw)+'" height="'+kt(e.viewport.vh)+'" fill="url(#'+t+')"/>',r1=t=>e=>'<path d="'+ya(t)+'" fill="'+ur(e)+'" fill-opacity="'+kt(rt(e.a)/255)+'"/>',GT=t=>e=>n=>r=>'<rect x="'+kt(t.x)+'" y="'+kt(t.y)+'" width="'+kt(t.w)+'" height="'+kt(t.h)+'" rx="'+kt(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+ur(n._1.color)+'" fill-opacity="'+kt(rt(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';g()})()+(()=>{if(r.tag==="Just")return' stroke="'+ur(r._1.color)+'" stroke-opacity="'+kt(rt(r._1.color.a)/255)+'" stroke-width="'+kt(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";g()})()+'"';if(r.tag==="Nothing")return"";g()})()+"/>",i1=t=>e=>'<path d="'+ya(t)+'" fill="none" stroke="'+ur(e.color)+'" stroke-opacity="'+kt(rt(e.color.a)/255)+'" stroke-width="'+kt(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";g()})()+'"/>',o1=t=>{const e=gg(Wr(t.content));return'<text x="'+kt(t.x)+'" y="'+kt(t.y)+'"'+(()=>{if(t.baseline==="BaselineTop")return' dy="0.8em"';if(t.baseline==="BaselineMiddle")return' dy="0.32em"';if(t.baseline==="BaselineAlphabetic"||t.baseline==="BaselineBottom")return"";g()})()+' fill="'+ur(t.color)+'" fill-opacity="'+kt(rt(t.color.a)/255)+'" font-size="'+kt(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+oe(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";g()})()+'">'+(e.length===1&&e[0].style==="RunText"?Na(e[0].text):wo("")(z(bT)(e)))+"</text>"},PT=t=>"matrix("+Ln(t.a)+" "+Ln(t.b)+" "+Ln(t.c)+" "+Ln(t.d)+" "+Ln(t.e)+" "+Ln(t.f)+")",u1={fillPath:t=>e=>n=>{const r=xu(n)(t);return()=>{const i=r();return Ae(r1(i)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=xu(n)(t);return()=>{const i=r(),o=n.bake.value;return Ae(i1(i)((()=>{if(o.tag==="Nothing")return e;if(o.tag==="Just")return{...e,width:o._1.sx*e.width};g()})()))(n)()}},fillStrokePath:t=>e=>n=>r=>{const i=xu(r)(t);return()=>{const o=i(),u=r.bake.value;return Ae(r1(o)(e.color)+i1(o)((()=>{if(u.tag==="Nothing")return n;if(u.tag==="Just")return{...n,width:u._1.sx*n.width};g()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>i=>{const o=i.bake;return()=>{const u=o.value;return Ae(GT((()=>{if(u.tag==="Nothing")return t;if(u.tag==="Just")return{x:u._1.sx*t.x+u._1.tx,y:u._1.sy*t.y+u._1.ty,w:u._1.sx*t.w,h:u._1.sy*t.h};g()})())((()=>{if(u.tag==="Nothing")return e;if(u.tag==="Just")return u._1.sx*e;g()})())(n)(r.tag==="Just"?w("Just",(()=>{if(u.tag==="Nothing")return r._1;if(u.tag==="Just")return{...r._1,width:u._1.sx*r._1.width};g()})()):J))(i)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return Ae(o1((()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return{...t,x:r._1.sx*t.x+r._1.tx,y:r._1.sy*t.y+r._1.ty,font:{...t.font,size:r._1.sx*t.font.size}};g()})()))(e)()}},drawTextAffine:t=>e=>Ae((()=>{const n='transform="'+PT(t)+'"';return(n===""?"<g>":"<g "+n+">")+o1(e)+"</g>"})()),pushTransform:t=>Ae((()=>{const e='transform="'+wT(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:Ae("</g>"),pushBakedTransform:t=>e=>{const n=e.bake;return()=>{n.value=w("Just",t)}},popBakedTransform:t=>{const e=t.bake;return()=>{e.value=J}},pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const i=r.value;n.clipCounter.value=i+1|0;const o=xu(n)(t)(),u="clip"+oe(i);return Ae((()=>{const s='clip-path="url(#'+u+')"';return'<defs><clipPath id="'+u+'"><path d="'+ya(o)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";g()})()+"/></clipPath></defs>"+(s===""?"<g>":"<g "+s+">")})())(n)()}},popClip:Ae("</g>"),pushBlend:t=>Ae((()=>{const e=(()=>{if(t==="Normal")return'style="mix-blend-mode: normal"';if(t==="Difference")return'style="mix-blend-mode: difference"';g()})();return e===""?"<g>":"<g "+e+">"})()),popBlend:Ae("</g>"),pushAlpha:t=>Ae((()=>{const e='opacity="'+kt(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:Ae("</g>"),pushLayer:t=>e=>{const n=(()=>{if(t==="LayerNodeMask"){const r=e.maskDepth;return()=>{const i=r.value;e.maskDepth.value=i+1|0}}return()=>{}})();return()=>{n(),e.out.push("<g>")}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;n>0&&(t.maskDepth.value=r),t.out.push("</g>")}},setViewport:t=>e=>()=>{},clearBackground:t=>e=>Ae('<rect x="'+kt(e.viewport.vx)+'" y="'+kt(e.viewport.vy)+'" width="'+kt(e.viewport.vw)+'" height="'+kt(e.viewport.vh)+'" fill="'+ur(t)+'" opacity="'+kt(rt(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,Ae(ST("bg-dots-"+oe(r))(t))(e)()}},measureText:t=>e=>n=>{const r=Bf(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Wf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Zf,Monad0:()=>CT},IT=K_(u1),DT=ha(u1),QT=t=>e=>n=>r=>i=>{const o={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:n,outputAspect:t},u=ni(o)(i);return{viewBox:kt(u.vx)+" "+kt(u.vy)+" "+kt(u.vw)+" "+kt(u.vh),body:(()=>{const s=[],a={value:0},c={value:0},f={value:0},d={value:J};return IT(o)(e)(i)({out:s,maskDepth:a,clipCounter:c,patternCounter:f,viewport:u,bake:d})(),wo("")(s)})(),vx:u.vx,vy:u.vy,vw:u.vw,vh:u.vh}},FT=t=>e=>n=>r=>i=>o=>{const u={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;g()})(),outputAspect:t},s=ta(i)((()=>{const a=[],c={value:0},f={value:0},d={value:0},l={value:J},_=r.levels.length-1|0;return _>=0&&_<r.levels.length?DT(r.levels[_].segment.layout)(r.levels[_].state)({out:a,maskDepth:c,clipCounter:f,patternCounter:d,viewport:ni(u)(r),bake:l})():Q})())(o);return{parts:QT(t)(s.applied)(e)(n)(r),springs:s.springs}},Zi=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(i=>n(i._1)(i._2)),Apply0:()=>s1(t)}),s1=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>i=>o=>e.map(u=>b(r(u._1),u._2))(i(o))};return{apply:(()=>{const r=Zi(t);return i=>o=>r.bind(i)(u=>r.bind(o)(s=>Ki(t).pure(u(s))))})(),Functor0:()=>n}},Ki=t=>({pure:e=>n=>t.Applicative0().pure(b(e,n)),Apply0:()=>s1(t)}),AT=t=>{const e={Applicative0:()=>Ki(t),Bind1:()=>Zi(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},Ja=(t,e)=>({tag:t,_1:e}),Ta=t=>t,Wn=(t,e)=>({tag:t,_1:e}),xe=AT(Xn),Mt=Zi(Xn),Ie=xe.state(t=>b(t,t)),te=Ki(Xn),zn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},a1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},yu=Cu(te)(Wt),qn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},MT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},OT=(()=>{const t=Xe.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return w("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._3,n(r._6,i)));g()};return n(e,Ht)})())})(),RT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Nu=t=>e=>n=>T(r=>i=>t.Bind1().bind(r)(o=>e(o)(i)))(t.Applicative0().pure(n)),BT=T(t=>e=>j(C)(e)()(t))(Q),WT=(()=>{const t=(e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=j(C)(a._1)()(s),i=a._2;continue}g()}return u})(Q);return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._3,n(r._6,i)));g()};return n(e,Ht)})())})(),zT=Wn("Exit"),qT=Ta("AnimatedKeyframe"),HT=Ta("Still"),$T=Ta("Title"),XT=t=>Ja("Par",t),c1=t=>Ja("Seq",t),YT=t=>e=>n=>{const r=cr(Xt,J,i=>i._1===t,n);if(r.tag==="Just"){const i=Yn(Xt,J,r._1,b(t,e),n);if(i.tag==="Nothing")return n;if(i.tag==="Just")return i._1;g()}if(r.tag==="Nothing")return Ot(n)(b(t,e));g()},VT=t=>e=>z(n=>n._1===t?b(n._1,{...n._2,label:w("Just",e)}):b(n._1,n._2)),ye=t=>xe.state(e=>b(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:w("Just",{msg:t,line:e.currentLine,column:e.currentColumn})};g()})())),UT=t=>Mt.bind(xe.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>Mt.bind(Ie)(e=>{if(e.error.tag==="Just")return te.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!zn(t.op._1.id)(e.currNodes))return ye("cannot enter node "+t.op._1.id+": does not exist");if(!a1(t.op._1.id)(e.interiorOf))return ye("cannot enter node "+t.op._1.id+": it has no `inside` block");if(We(_n)(t.op._1.id)(e.enterStack))return ye("cannot enter node "+t.op._1.id+": already entered");const n=t.op._1;return xe.state(r=>b(void 0,{...r,enterStack:Ot(r.enterStack)(n.id),scenes:Ot(r.scenes)(Ji("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=Cr(e.enterStack);if(n.tag==="Nothing")return ye("`exit` without a matching `enter`");if(n.tag==="Just"){const r=n._1.init;return xe.state(i=>b(void 0,{...i,enterStack:r,scenes:Ot(i.scenes)(ql)}))}g()}return te.pure()}g()})),ZT=t=>Mt.bind(Ie)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+oe(e.kfCounter);if(Be(i=>i.id===n,e.keyframes))return ye("duplicate frame name "+n);const r={...e,keyframes:Ot(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges,kind:Ti}),kfCounter:e.kfCounter+1|0,currentKf:w("Just",n)};return xe.state(i=>b(void 0,r))}),KT=yu(t=>Mt.bind(Ie)(e=>{if(e.error.tag==="Just")return te.pure();if(e.error.tag==="Nothing")return a1(t.node)(e.interiorOf)?ye("node "+t.node+" has more than one `inside` block"):xe.state(n=>b(void 0,{...n,interiorOf:j(C)(t.node)(t.doc)(n.interiorOf)}));g()})),jT=t=>e=>{const n=e.from+"->"+e.to,r=e.newFrom+"->"+e.newTo,i=Pt("Left","cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist"),o=qn(n)(t.currEdges)?Pt("Right",void 0):i;return(()=>{if(o.tag==="Left"){const u=o._1;return s=>Pt("Left",u)}if(o.tag==="Right"){const u=o._1;return s=>s(u)}g()})()(()=>{const u="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newFrom;if(!zn(e.newFrom)(t.currNodes))return Pt("Left",u);const s="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo;if(!zn(e.newTo)(t.currNodes))return Pt("Left",s);const a="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists";return n!==r&&qn(r)(t.currEdges)?Pt("Left",a):Pt("Right",{nextCurrEdges:j(C)(r)()(gi(C)(n)(t.currEdges)),newId:r,newEdge:{id:r,from:{node:e.newFrom,port:J},to:{node:e.newTo,port:J},label:J}})})},g1={graphNodes:[],graphEdges:Q,currNodes:Q,currEdges:Q,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:J,currentLine:0,currentColumn:0,error:J,enterStack:[],interiorOf:Q},tw=Mt.bind(Ie)(t=>{if(t.error.tag==="Just")return te.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return xe.state(n=>b(void 0,{...n,scenes:Ot(n.scenes)(Ji("Hold",e))}))}if(t.currentKf.tag==="Nothing")return te.pure()}g()}),f1=t=>e=>Mt.bind(Ie)(n=>{const r="ev-"+oe(n.eventCounter);return Mt.bind((()=>{const i={...n,eventCounter:n.eventCounter+1|0};return xe.state(o=>b(void 0,i))})())(()=>te.pure({events:[{id:r,kind:e,when:t}],firstId:w("Just",r),lastId:w("Just",r)}))}),ew=t=>e=>{if(e.tag==="Token"){const n=e._1;return Mt.bind(Ie)(r=>{const i=!zn(n.from)(r.currNodes),o=!zn(n.to)(r.currNodes);if(i||o)return Mt.bind(ye(i?o?"token references unknown node: "+n.from+", "+n.to:"token references unknown node: "+n.from:o?"token references unknown node: "+n.to:"token references unknown node: "))(()=>te.pure({events:[],firstId:J,lastId:J}));const u=n.to+"->"+n.from,s=n.from+"->"+n.to;return qn(s)(r.currEdges)?f1(t)(wc("SendToken",{from:n.from,to:n.to,edge:s,direction:Wl,labels:n.labels})):qn(u)(r.currEdges)?f1(t)(wc("SendToken",{from:n.from,to:n.to,edge:u,direction:zl,labels:n.labels})):Mt.bind(ye("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>te.pure({events:[],firstId:J,lastId:J}))})}return te.pure({events:[],firstId:J,lastId:J})},nw=t=>e=>{if(0<t.length){const n=t[0];return Mt.bind(xe.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>ye(e))}return ye(e)},rw=t=>yt(e=>MT(e)(t.graphEdges))(Ct(si,OT(t.currEdges))),iw=t=>e=>{const n=st(i=>i.from.node===e.id||i.to.node===e.id,rw(t)),r=Nu(za)(i=>o=>{const u=o.from+"->"+e.id,s=e.id+"->"+o.to,a=o.from+"->"+o.to,c="via "+o.from+" "+o.to+": no edge "+o.from+"\u2192"+e.id;if(!qn(u)(t.currEdges))return Pt("Left",c);const f="via "+o.from+" "+o.to+": no edge "+e.id+"\u2192"+o.to;if(!qn(s)(t.currEdges))return Pt("Left",f);const d="via "+o.from+" "+o.to+": would create "+o.from+"\u2192"+o.to+" but it already exists";return qn(a)(t.currEdges)||RT(a)(i.synthesized)?Pt("Left",d):Pt("Right",{consumed:j(C)(u)()(j(C)(s)()(i.consumed)),synthesized:j(C)(a)({id:a,from:{node:o.from,port:J},to:{node:o.to,port:J},label:J})(i.synthesized)})})({consumed:Q,synthesized:Q})(e.via);return(()=>{if(r.tag==="Left"){const i=r._1;return o=>Pt("Left",i)}if(r.tag==="Right"){const i=r._1;return o=>o(i)}g()})()(i=>{const o=i.consumed,u=st(s=>!qn(s.id)(o),n);return u.length===0?Pt("Right",{nextCurrEdges:Ee(C.compare,ke,Gn(C.compare,t.currEdges,BT(z(s=>s.id)(n))),WT((()=>{const s=a=>{if(a.tag==="Leaf")return Q;if(a.tag==="Node")return zt("Node",a._1,a._2,a._3,void 0,s(a._5),s(a._6));g()};return s(i.synthesized)})())),synthesized:i.synthesized}):Pt("Left","cannot delete node "+e.id+": still connected ("+wo(", ")(z(s=>s.from.node+"\u2192"+s.to.node)(u))+"). Use -edge to drop them or `via a b` to merge "+e.id+"'s endpoints.")})},wa=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq")return Tt(t._1)(wa);g()},ow=Mt.bind(Ie)(t=>{if(t.error.tag==="Just")return te.pure();if(t.error.tag==="Nothing"){const e=t.enterStack.length-1|0;return e>=0&&e<t.enterStack.length?ye("entered node "+t.enterStack[e]+" was never exited"):te.pure()}g()}),uw=t=>({nodes:z(ro)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,qt("Cons",n._4,e(n._6,r)));g()};return Ct($t.foldr,e(t.graphEdges,Ht))})(),constraints:[]}),sw=t=>{if(t.tag==="AddNode"){const e=t._1;return xe.state(n=>b(void 0,{...n,graphNodes:YT(e.id)({id:e.id,size:b(1,1),ports:[],label:w("Just",e.label),shape:e.shape})(n.graphNodes),currNodes:j(C)(e.id)()(n.currNodes)}))}if(t.tag==="DelNode"){const e=t._1;return Mt.bind(Ie)(n=>{if(!zn(e.id)(n.currNodes))return ye("cannot delete node "+e.id+": does not exist");const r=iw(n)(e);if(r.tag==="Left")return ye(r._1);if(r.tag==="Right"){const i=r._1;return xe.state(o=>b(void 0,{...o,currNodes:gi(C)(e.id)(o.currNodes),currEdges:i.nextCurrEdges,graphEdges:Ee(C.compare,ke,i.synthesized,o.graphEdges)}))}g()})}if(t.tag==="ModNode"){const e=t._1;return Mt.bind(Ie)(n=>{if(!zn(e.id)(n.currNodes))return ye("cannot modify node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=e.label._1;return xe.state(i=>b(void 0,{...i,graphNodes:VT(e.id)(r)(i.graphNodes)}))}if(e.label.tag==="Nothing")return te.pure();g()})}if(t.tag==="AddEdge"){const e=t._1;return Mt.bind(Ie)(n=>{const r=!zn(e.from)(n.currNodes),i=!zn(e.to)(n.currNodes);if(r||i)return ye("cannot add edge "+e.from+"\u2192"+e.to+": unknown node "+(r?i?e.from+", "+e.to:e.from:i?e.to:""));const o=e.from+"->"+e.to;return xe.state(u=>b(void 0,{...u,graphEdges:j(C)(o)({id:o,from:{node:e.from,port:J},to:{node:e.to,port:J},label:e.label})(u.graphEdges),currEdges:j(C)(o)()(u.currEdges)}))})}if(t.tag==="DelEdge"){const e=t._1;return Mt.bind(Ie)(n=>{const r=e.from+"->"+e.to;return qn(r)(n.currEdges)?xe.state(i=>b(void 0,{...i,currEdges:gi(C)(r)(i.currEdges)})):ye("cannot delete edge "+e.from+"\u2192"+e.to+": does not exist")})}if(t.tag==="RepointEdge"){const e=t._1;return Mt.bind(Ie)(n=>{const r=jT(n)(e);if(r.tag==="Left")return ye(r._1);if(r.tag==="Right"){const i=r._1;return xe.state(o=>b(void 0,{...o,currEdges:i.nextCurrEdges,graphEdges:j(C)(i.newId)(i.newEdge)(o.graphEdges)}))}g()})}return te.pure()},aw=t=>Mt.bind(xe.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>sw(t.op)),_1=t=>e=>n=>Mt.bind(yu(aw)(n))(()=>Mt.bind(Ie)(r=>{const i=e.tag==="Just"&&e._1!==""?e._1:"kf-"+oe(r.kfCounter);if(Be(u=>u.id===i,r.keyframes))return ye("duplicate frame name "+i);const o={...r,keyframes:Ot(r.keyframes)({id:i,nodes:r.currNodes,edges:r.currEdges,kind:t}),kfCounter:r.kfCounter+1|0,currentKf:w("Just",i),scenes:(()=>{if(r.currentKf.tag==="Nothing")return r.scenes;if(r.currentKf.tag==="Just")return Ot(r.scenes)(Ji("Structural",{from:r.currentKf._1,to:i,focus:J}));g()})()};return xe.state(u=>b(void 0,o))})),d1=t=>e=>{const n=wa(e.ops),r=st(o=>o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge",n),i=st(o=>!(o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge"),n);if(0<i.length){const o=i[0];return Mt.bind(xe.state(u=>b(void 0,{...u,currentLine:o.line,currentColumn:o.column})))(()=>ye("still/title blocks hold a static snapshot; they cannot contain tokens (a -> b) or enter/exit"))}return t==="TitleCard"&&r.length===0?ye(e.name.tag==="Just"&&e.name._1!==""?'title "'+e.name._1+'" has an empty body; give it nodes/edges to title, or use a still':"title has an empty body; give it nodes/edges to title, or use a still"):Mt.bind(_1(t)(e.name)(r))(()=>tw)},cw=t=>e=>{const n=At(r=>J,r=>i=>w("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return te.pure({events:[],firstId:J,lastId:J});if(n.tag==="Just"){const r=n._1.tail;return Mt.bind(ji(t)(n._1.head))(i=>Mt.bind(Nu({Applicative0:()=>Ki(Xn),Bind1:()=>Zi(Xn)})(o=>u=>Mt.bind(ji((()=>{if(o.lastId.tag==="Just")return es("After",o.lastId._1);if(o.lastId.tag==="Nothing")return t;g()})())(u))(s=>te.pure({events:[...o.events,...s.events],firstId:(()=>{if(o.firstId.tag==="Just")return w("Just",o.firstId._1);if(o.firstId.tag==="Nothing")return s.firstId;g()})(),lastId:(()=>{if(s.lastId.tag==="Just")return w("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return o.lastId;g()})()})))(i)(r))(o=>te.pure(o)))}g()},gw=t=>e=>{const n=At(r=>J,r=>i=>w("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return te.pure({events:[],firstId:J,lastId:J});if(n.tag==="Just"){const r=n._1.tail;return Mt.bind(ji(t)(n._1.head))(i=>Mt.bind(fw((()=>{if(i.firstId.tag==="Just")return es("With",i.firstId._1);if(i.firstId.tag==="Nothing")return t;g()})())(r))(o=>te.pure({events:[...i.events,...o.events],firstId:i.firstId,lastId:(()=>{if(i.lastId.tag==="Just")return w("Just",i.lastId._1);if(i.lastId.tag==="Nothing")return o.lastId;g()})()})))}g()},ji=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return Mt.bind(xe.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>ew(t)(n.op))}if(e.tag==="Seq")return cw(t)(e._1);if(e.tag==="Par")return gw(t)(e._1);g()},fw=t=>Nu({Applicative0:()=>Ki(Xn),Bind1:()=>Zi(Xn)})(e=>n=>Mt.bind(ji(t)(n))(r=>te.pure({events:[...e.events,...r.events],firstId:(()=>{if(e.firstId.tag==="Just")return w("Just",e.firstId._1);if(e.firstId.tag==="Nothing")return r.firstId;g()})(),lastId:(()=>{if(r.lastId.tag==="Just")return w("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;g()})()})))({events:[],firstId:J,lastId:J}),_w=t=>Mt.bind(Ie)(e=>{if(e.currentKf.tag==="Nothing")return ye("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return Mt.bind(ji(Bl)(t))(r=>Mt.bind(Ie)(i=>{const o={...i,scenes:Ot(i.scenes)(Ji("DataFlow",{keyframe:n,events:r.events,focus:J}))};return xe.state(u=>b(void 0,o))}))}g()}),dw=t=>{const e=wa(t.ops),n=st(o=>o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge",e),r=st(o=>o.op.tag==="Enter"||o.op.tag==="Exit",e),i=st(o=>!(o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge")&&!(o.op.tag==="Enter"||o.op.tag==="Exit"),e);return r.length!==0&&i.length!==0?nw(r)("`enter`/`exit` cannot be mixed with flow tokens in the same frame"):Mt.bind((()=>{const o=_1(Ti)(t.name)(n);return n.length!==0?o:te.pure()})())(()=>Mt.bind((()=>{const o=ZT(t.name);return n.length===0&&i.length!==0?o:te.pure()})())(()=>Mt.bind((()=>{const o=_w(t.ops);return i.length!==0?o:te.pure()})())(()=>yu(UT)(r))))},lw=t=>Mt.bind(Ie)(e=>{if(e.error.tag==="Just")return te.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return dw(t);if(t.kind==="Still")return d1(Ol)(t);if(t.kind==="Title")return d1(Rl)(t)}g()}),l1=t=>Mt.bind(KT(t.interiors))(()=>Mt.bind(yu(lw)(t.frames))(()=>Mt.bind(ow)(()=>Mt.bind(Ie)(e=>{if(e.error.tag==="Just")return te.pure(Pt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=hw(t.interiors);if(n.tag==="Left")return te.pure(Pt("Left",n._1));if(n.tag==="Right")return te.pure(Pt("Right",{seed:t.seed,graph:uw(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1}))}g()})))),hw=t=>{const e=Nu(za)(n=>r=>{const i=l1(r.doc)(g1)._1;return(()=>{if(i.tag==="Left"){const o=i._1;return u=>Pt("Left",o)}if(i.tag==="Right"){const o=i._1;return u=>u(o)}g()})()(o=>Pt("Right",j(C)(r.node)(o)(n)))})(Q)(t);if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right")return Pt("Right",e._1);g()},ri=(t,e)=>({tag:"ParseError",_1:t,_2:e}),F=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),Ju=(t,e,n)=>({tag:t,_1:e,_2:n}),pw=t=>Ju("More",t),mw=t=>Ju("Lift",t),xw={defer:t=>{const e=ml(t);return(n,r,i,o,u)=>xl(e)(n,r,i,o,u)}},h1={map:t=>e=>(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,c)=>r(f=>u(a,t(c)))))},yw={alt:t=>e=>(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>t(F(s,a,!1),r,i,(f,d)=>{const l=f._3;return r(_=>l?o(f,d):e(n,r,i,o,u))},u))},Functor0:()=>h1},Nw=t=>{const e=t.Monad0();return n=>r=>{const i=o=>{let u=o,s=!0,a;for(;s;){const c=u();if(c.tag==="More"){u=c._1;continue}if(c.tag==="Lift"){s=!1,a=e.Bind1().Apply0().Functor0().map(Ha)(c._1);continue}if(c.tag==="Stop"){s=!1,a=e.Applicative0().pure(ui("Done",b(c._2,c._1)));continue}g()}return a};return t.tailRecM(i)(o=>r(n,pw,mw,(u,s)=>Ju("Stop",u,Pt("Left",s)),(u,s)=>Ju("Stop",u,Pt("Right",s))))}},p1=(t,e,n,r,i)=>i(t,t._2),Jw={index:0,line:1,column:1},Tw=(t=>{const e=Nw(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(io)(e(F(n,Jw,!1))(r))})(H1),m1={apply:t=>e=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,c)=>r(f=>{const d=n._3&&!a._3?F(a._1,a._2,!0):a;return e(d,r,i,o,(l,_)=>r(h=>u(d._3&&!l._3?F(l._1,l._2,!0):l,c(_))))}))),Functor0:()=>h1},x1={pure:t=>(e,n,r,i,o)=>o(e,t),Apply0:()=>m1},ww={bind:t=>e=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,c)=>r(f=>e(c)(n._3&&!a._3?F(a._1,a._2,!0):a,r,i,o,u)))),Apply0:()=>m1},vw={Applicative0:()=>x1,Bind1:()=>ww},Tu=t=>(e,n,r,i,o)=>n(u=>p1(e,n,r,i,(s,a)=>n(c=>i(e._3&&!s._3?F(s._1,s._2,!0):s,ri(t,a))))),bw={empty:Tu("No alternative"),Alt0:()=>yw},kw={Applicative0:()=>x1,Plus1:()=>bw},sn=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return i=>t.tailRecM(o=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(Ha)(i))(r.pure(ui("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return ui("Loop",qt("Cons",u._1,o));if(u.tag==="Done")return ui("Done",(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=qt("Cons",h._1,_),f=h._2;continue}g()}return l})(Ht)(o));g()})())))(Ht)})({tailRecM:t=>e=>(n,r,i,o,u)=>{const s=(a,c,f)=>t(c)(a,r,i,o,(d,l)=>{const _=a._3&&!d._3?F(d._1,d._2,!0):d;if(l.tag==="Loop")return f===0?r(h=>s(_,l._1,30)):s(_,l._1,f-1|0);if(l.tag==="Done")return u(_,l._1);g()});return s(n,e,30)},Monad0:()=>vw})(kw),Gt=t=>e=>{const n=Tu("Expected "+e);return(r,i,o,u,s)=>{const a=r._1,c=r._2;return i(f=>t(F(a,c,!1),i,o,(d,l)=>{const _=d._3;return i(h=>_?u(d,l):n(r,i,o,u,s))},s))}},va=t=>(e,n,r,i,o)=>{const u=e._3,s=e._1,a=e._2;return n(c=>{const f=(d,l)=>{const _=d._3;return n(h=>_?i(F(d._1,d._2,u),l):o(e,void 0))};return n(d=>n(l=>t(F(s,a,!1),n,r,(_,h)=>f(F(_._1,_._2,!1),h),(_,h)=>n(p=>n(m=>Tu("Negated parser succeeded")(_,n,r,f,(x,y)=>n(N=>o(_._3&&!x._3?F(x._1,x._2,!0):x,y))))))))})},Lw=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return w("Just",n);if(r.tag==="Just")return w("Just",(i,o,u,s,a)=>{const c=i._1,f=i._2;return o(d=>n(F(c,f,!1),o,u,(l,_)=>{const h=l._3;return o(p=>h?s(l,_):r._1(i,o,u,s,a))},a))});g()})(J);return n=>{const r=e(n);if(r.tag==="Nothing")return Tu("No alternative");if(r.tag==="Just")return r._1;g()}},Ew=t=>e=>n=>(r,i,o,u,s)=>i(a=>i(c=>i(f=>i(d=>t(r,i,o,u,(l,_)=>i(h=>i(p=>{const m=r._3&&!l._3?F(l._1,l._2,!0):l;return n(m,i,o,u,(x,y)=>i(N=>{const v=m._3&&!x._3?F(x._1,x._2,!0):x;return i(L=>i(k=>{const E=r._3&&!v._3?F(v._1,v._2,!0):v;return e(E,i,o,u,(O,Y)=>i(et=>s(E._3&&!O._3?F(O._1,O._2,!0):O,y)))}))}))}))))))),ba=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=Ph()(n);return r.tag==="Just"&&r._1===10?{index:t.index+1|0,line:t.line,column:t.column}:{index:t.index+1|0,line:t.line+1|0,column:1}}return e===9?{index:t.index+1|0,line:t.line,column:(t.column+8|0)-Zn(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},Cw=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,c=i,f=o,d=vo(c);if(d.tag==="Nothing"){u=!1,s=a;continue}if(d.tag==="Just"){r=d._1.tail===""?ba(a)(d._1.head)(f):ba(a)(d._1.head)(d._1.tail),i=d._1.tail,o=f;continue}g()}return s},Zt=t=>(e,n,r,i,o)=>{const u=vo(e._1);if(u.tag==="Nothing")return i(e,ri("Unexpected EOF",e._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return i(e,ri("Expected Char",e._2));if(u._1.head>=0&&u._1.head<=65535){const s=Ic(u._1.head);return t(s)?o(F(u._1.tail,ba(e._2)(u._1.head)(u._1.tail),!0),s):i(e,ri("Predicate unsatisfied",e._2))}}g()},ka=(t,e,n,r,i)=>t._1===""?i(F(t._1,t._2,!0),void 0):r(t,ri("Expected EOF",t._2)),Sw=t=>(e,n,r,i,o)=>{const u=t(e._1);if(u.tag==="Left")return i(e,ri(u._1,e._2));if(u.tag==="Right")return o(F(u._1.remainder,Cw(e._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);g()},ii=t=>Sw(e=>{const n=pl(t)(e);return n.tag==="Just"?Pt("Right",{value:t,consumed:t,remainder:n._1}):Pt("Left","Expected "+I1(t))}),Gw=Zt(t=>!0),y1=(t,e)=>({tag:t,_1:e}),Pw=jt(C)(Wt),Iw=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},N1=Lw(Wt),J1=(()=>{const t=Zt(e=>e===" "||e===" "||e===`
9
- `||e==="\r");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?F(s._1,s._2,!0):s,void 0))))})(),La=(t,e,n,r,i)=>e(o=>ii("#")(t,e,n,r,(u,s)=>e(a=>{const c=sn(Zt(d=>d!==`
10
- `)),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>i(f._3&&!l._3?F(l._1,l._2,!0):l,void 0))))}))),Dw=Gt((()=>{const t=Gt(Zt(n=>n==="}"))("'}'"),e=Zt(n=>n===`
11
- `||n==="\r");return(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>r(f=>t(F(s,a,!1),r,i,(d,l)=>r(_=>{const h=n._1,p=n._2;return r(m=>r(x=>La(F(h,p,!1),r,i,(y,N)=>{const v=y._3;return r(L=>{if(v)return o(y,N);const k=n._1,E=n._2;return r(O=>r(Y=>e(F(k,E,!1),r,i,(et,G)=>{const P=et._3;return r(V=>P?o(et,G):ka(n,r,i,o,u))},(et,G)=>r(P=>u(et,void 0)))))})},(y,N)=>r(v=>u(y,void 0)))))}),(d,l)=>r(_=>u(F(s,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),je=(()=>{const t=sn((e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>J1(F(u,s,!1),n,r,(c,f)=>{const d=c._3;return n(l=>d?i(c,f):La(e,n,r,i,o))},o))});return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?F(s._1,s._2,!0):s,void 0))))})(),fn=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>je(t._3&&!c._3?F(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>J1(F(s,a,!1),e,n,(f,d)=>{const l=f._3;return e(_=>l?r(f,d):La(t,e,n,r,u))},u))}),T1=(()=>{const t=Gt(Zt(e=>e==="|"))("'|'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=sn(Zt(l=>l!=="|")),d=e._3&&!s._3?F(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(p=>{const m=Gt(Gt(Zt(y=>y==="|"))("'|'"))("closing '|'"),x=d._3&&!_._3?F(_._1,_._2,!0):_;return n(y=>m(x,n,r,i,(N,v)=>n(L=>o(x._3&&!N._3?F(N._1,N._2,!0):N,lr(Ct($t.foldr,h))))))})))})))})(),wu=Zt(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),Me=(()=>{const t=sn(Zt(e=>e===" "||e===" "));return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?F(s._1,s._2,!0):s,void 0))))})(),Qw=(()=>{const t=Gt(Zt(e=>e==="\\"))("'\\\\'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=e._3&&!s._3?F(s._1,s._2,!0):s;return n(d=>Gw(f,n,r,i,(l,_)=>n(h=>o(f._3&&!l._3?F(l._1,l._2,!0):l,_==="n"?`
12
- `:_==="t"?" ":_==="r"?"\r":_))))})))})(),Fw=(()=>{const t=Zt(e=>e!=='"'&&e!=="\\"&&e!==`
13
- `);return(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>Qw(F(u,s,!1),n,r,(c,f)=>n(d=>t(e,n,r,i,o)),o))}})(),Ea=(()=>{const t=Gt(Zt(e=>e==='"'))(`'"'`);return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=sn(Fw),d=e._3&&!s._3?F(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(p=>{const m=Gt(Gt(Zt(y=>y==='"'))(`'"'`))(`closing '"' (unterminated string)`),x=d._3&&!_._3?F(_._1,_._2,!0):_;return n(y=>m(x,n,r,i,(N,v)=>n(L=>o(x._3&&!N._3?F(N._1,N._2,!0):N,lr(Ct($t.foldr,h))))))})))})))})(),Aw=(()=>{const t=Gt(Zt(e=>e===":"))("':'");return(e,n,r,i,o)=>n(u=>Me(e,n,r,i,(s,a)=>n(c=>Gt((f,d,l,_,h)=>{const p=f._1,m=f._2;return d(x=>{const y=(N,v)=>{const L=N._3;return d(k=>{if(L)return _(N,v);const E=f._1,O=f._2;return d(Y=>T1(F(E,O,!1),d,l,(et,G)=>{const P=et._3;return d(V=>P?_(et,G):Ea(f,d,l,_,h))},h))})};return d(N=>t(F(p,m,!1),d,l,y,(v,L)=>d(k=>d(E=>Me(v,d,l,y,(O,Y)=>d(et=>{const G=sn(Zt(V=>V!==`
14
- `&&V!=="\r"&&V!=="#"&&V!=="}")),P=v._3&&!O._3?F(O._1,O._2,!0):O;return d(V=>G(P,d,l,y,(U,B)=>d(R=>h(P._3&&!U._3?F(U._1,U._2,!0):U,Nh(lr(Ct($t.foldr,B)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(e._3&&!s._3?F(s._1,s._2,!0):s,n,r,i,o))))})(),w1=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>T1(F(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):Ea(t,e,n,r,i))},i))},to=Zt(t=>t>="0"&&t<="9"),be=(()=>{const t=Gt(Zt(e=>e==="_"))("'_'");return(e,n,r,i,o)=>n(u=>{const s=(f,d)=>n(l=>{const _=sn((()=>{const p=Gt(Zt(x=>x==="_"))("'_'"),m=Gt(Zt(x=>x==="-"))("'-'");return(x,y,N,v,L)=>{const k=x._1,E=x._2;return y(O=>wu(F(k,E,!1),y,N,(Y,et)=>{const G=Y._3;return y(P=>{if(G)return v(Y,et);const V=x._1,U=x._2;return y(B=>to(F(V,U,!1),y,N,(R,M)=>{const S=R._3;return y(I=>{if(S)return v(R,M);const D=x._1,A=x._2;return y(H=>p(F(D,A,!1),y,N,($,X)=>{const q=$._3;return y(W=>q?v($,X):m(x,y,N,v,L))},L))})},L))})},L))}})()),h=e._3&&!f._3?F(f._1,f._2,!0):f;return n(p=>_(h,n,r,i,(m,x)=>n(y=>o(h._3&&!m._3?F(m._1,m._2,!0):m,lo(d)+lr(Ct($t.foldr,x))))))}),a=e._1,c=e._2;return n(f=>wu(F(a,c,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?i(d,l):t(e,n,r,i,s))},s))})})(),Mw=Gt((t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>Ea(F(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):be(t,e,n,r,i))},i))})("frame name (identifier or quoted string)"),v1=(t,e,n,r,i)=>e(o=>Me(t,e,n,r,(u,s)=>e(a=>{const c=Gt(be)("attribute key"),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=f._3&&!l._3?F(l._1,l._2,!0):l;return e(m=>Me(p,e,n,r,(x,y)=>e(N=>{const v=Gt(Gt(Zt(k=>k===":"))("':'"))("':'"),L=p._3&&!x._3?F(x._1,x._2,!0):x;return e(k=>v(L,e,n,r,(E,O)=>e(Y=>{const et=L._3&&!E._3?F(E._1,E._2,!0):E;return e(G=>Me(et,e,n,r,(P,V)=>e(U=>{const B=Gt(be)("attribute value"),R=et._3&&!P._3?F(P._1,P._2,!0):P;return e(M=>B(R,e,n,r,(S,I)=>e(D=>{const A=R._3&&!S._3?F(S._1,S._2,!0):S;return e(H=>Me(A,e,n,r,($,X)=>e(q=>i(A._3&&!$._3?F($._1,$._2,!0):$,b(_,I)))))})))})))})))})))})))}))),Ow=(t,e,n,r,i)=>e(o=>be(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>Me(c,e,n,r,(d,l)=>e(_=>{const h=Gt((m,x,y,N,v)=>{const L=m._1,k=m._2;return x(E=>ii("->")(F(L,k,!1),x,y,(O,Y)=>{const et=O._3;return x(G=>et?N(O,Y):ii("<-")(m,x,y,N,v))},v))})("'->' or '<-'"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(x,y)=>e(N=>{const v=p._3&&!x._3?F(x._1,x._2,!0):x;return e(L=>Me(v,e,n,r,(k,E)=>e(O=>{const Y=Gt(be)("target node identifier"),et=v._3&&!k._3?F(k._1,k._2,!0):k;return e(G=>Y(et,e,n,r,(P,V)=>e(U=>{const B=sn((M,S,I,D,A)=>{const H=M._3;return S($=>S(X=>Me(M,S,I,(q,W)=>D(F(q._1,q._2,H),W),(q,W)=>S(tt=>S(Z=>{const ct=M._3&&!q._3?F(q._1,q._2,!0):q;return w1(ct,S,I,(ft,at)=>D(F(ft._1,ft._2,H),at),(ft,at)=>S(xt=>A(ct._3&&!ft._3?F(ft._1,ft._2,!0):ft,at)))})))))}),R=et._3&&!P._3?F(P._1,P._2,!0):P;return e(M=>B(R,e,n,r,(S,I)=>e(D=>(()=>{if(y==="<-"){const H=Wn("Token",{from:V,to:s,labels:z(xc)(Ct($t.foldr,I))});return($,X,q,W,tt)=>tt($,H)}const A=Wn("Token",{from:s,to:V,labels:z(xc)(Ct($t.foldr,I))});return(H,$,X,q,W)=>W(H,A)})()(R._3&&!S._3?F(S._1,S._2,!0):S,e,n,r,i))))})))})))})))})))}))),Rw=(t,e,n,r,i)=>e(o=>to(t,e,n,r,(u,s)=>e(a=>{const c=sn(to),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=Td(lo(s)+lr(Ct($t.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(x,y,N,v,L)=>L(x,m)}if(p.tag==="Nothing")return(m,x,y,N,v)=>v(m,0);g()})()(f._3&&!l._3?F(l._1,l._2,!0):l,e,n,r,i)})))}))),eo=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>ii(t)(e,n,r,(a,c)=>i(F(a._1,a._2,u),c),(a,c)=>n(f=>{const d=va((()=>{const _=Gt(Zt(p=>p==="_"))("'_'"),h=Gt(Zt(p=>p==="-"))("'-'");return(p,m,x,y,N)=>{const v=p._1,L=p._2;return m(k=>wu(F(v,L,!1),m,x,(E,O)=>{const Y=E._3;return m(et=>{if(Y)return y(E,O);const G=p._1,P=p._2;return m(V=>to(F(G,P,!1),m,x,(U,B)=>{const R=U._3;return m(M=>{if(R)return y(U,B);const S=p._1,I=p._2;return m(D=>_(F(S,I,!1),m,x,(A,H)=>{const $=A._3;return m(X=>$?y(A,H):h(p,m,x,y,N))},N))})},N))})},N))}})()),l=e._3&&!a._3?F(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(F(h._1,h._2,u),p),(h,p)=>n(m=>{const x=l._3&&!h._3?F(h._1,h._2,!0):h;return n(y=>je(x,n,r,(N,v)=>i(F(N._1,N._2,u),v),(N,v)=>n(L=>o(x._3&&!N._3?F(N._1,N._2,!0):N,t))))})))})))},Bw=(t,e,n,r,i)=>e(o=>fn(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>eo("via")(c,e,n,r,(d,l)=>e(_=>{const h=c._3&&!d._3?F(d._1,d._2,!0):d;return e(p=>be(h,e,n,r,(m,x)=>e(y=>{const N=h._3&&!m._3?F(m._1,m._2,!0):m;return e(v=>fn(N,e,n,r,(L,k)=>e(E=>{const O=N._3&&!L._3?F(L._1,L._2,!0):L;return e(Y=>be(O,e,n,r,(et,G)=>e(P=>i(O._3&&!et._3?F(et._1,et._2,!0):et,{from:x,to:G}))))})))})))})))}))),sr=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>ii(t)(e,n,r,(a,c)=>i(F(a._1,a._2,u),c),(a,c)=>n(f=>{const d=va((()=>{const _=Gt(Zt(p=>p==="_"))("'_'"),h=Gt(Zt(p=>p==="-"))("'-'");return(p,m,x,y,N)=>{const v=p._1,L=p._2;return m(k=>wu(F(v,L,!1),m,x,(E,O)=>{const Y=E._3;return m(et=>{if(Y)return y(E,O);const G=p._1,P=p._2;return m(V=>to(F(G,P,!1),m,x,(U,B)=>{const R=U._3;return m(M=>{if(R)return y(U,B);const S=p._1,I=p._2;return m(D=>_(F(S,I,!1),m,x,(A,H)=>{const $=A._3;return m(X=>$?y(A,H):h(p,m,x,y,N))},N))})},N))})},N))}})()),l=e._3&&!a._3?F(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(F(h._1,h._2,u),p),(h,p)=>n(m=>o(l._3&&!h._3?F(h._1,h._2,!0):h,void 0))))})))},Ww=(t,e,n,r,i)=>e(o=>sr("+edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(x,y)=>e(N=>{const v=p._3&&!x._3?F(x._1,x._2,!0):x;return e(L=>fn(v,e,n,r,(k,E)=>e(O=>{const Y=Gt(be)("target node identifier"),et=v._3&&!k._3?F(k._1,k._2,!0):k;return e(G=>Y(et,e,n,r,(P,V)=>e(U=>{const B=et._3&&!P._3?F(P._1,P._2,!0):P;return e(R=>{const M=(D,A)=>e(H=>i(B._3&&!D._3?F(D._1,D._2,!0):D,Wn("AddEdge",{from:y,to:V,label:A.tag==="Just"?w("Just",A._1):J}))),S=B._1,I=B._2;return e(D=>e(A=>{const H=($,X)=>{const q=$._3;return e(W=>q?r($,X):M(B,J))};return e($=>e(X=>Me(F(S,I,!1),e,n,(q,W)=>H(F(q._1,q._2,!1),W),(q,W)=>e(tt=>e(Z=>w1(q,e,n,(ct,ft)=>H(F(ct._1,ct._2,!1),ft),(ct,ft)=>e(at=>{const xt=q._3&&!ct._3?F(ct._1,ct._2,!0):ct;return e(St=>M(xt,w("Just",ft)))})))))))}))})})))})))})))})))}))),zw=(t,e,n,r,i)=>e(o=>sr("-edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(x,y)=>e(N=>{const v=p._3&&!x._3?F(x._1,x._2,!0):x;return e(L=>fn(v,e,n,r,(k,E)=>e(O=>{const Y=Gt(be)("target node identifier"),et=v._3&&!k._3?F(k._1,k._2,!0):k;return e(G=>Y(et,e,n,r,(P,V)=>e(U=>i(et._3&&!P._3?F(P._1,P._2,!0):P,Wn("DelEdge",{from:y,to:V})))))})))})))})))}))),qw=(t,e,n,r,i)=>e(o=>sr("-node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(x,y)=>e(N=>{const v=sn((k,E,O,Y,et)=>{const G=k._3;return Bw(k,E,O,(P,V)=>Y(F(P._1,P._2,G),V),et)}),L=p._3&&!x._3?F(x._1,x._2,!0):x;return e(k=>v(L,e,n,r,(E,O)=>e(Y=>i(L._3&&!E._3?F(E._1,E._2,!0):E,Wn("DelNode",{id:y,via:Ct($t.foldr,O)})))))})))})))}))),Hw=(t,e,n,r,i)=>e(o=>sr("enter")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(x,y)=>e(N=>i(p._3&&!x._3?F(x._1,x._2,!0):x,Wn("Enter",{id:y})))))})))}))),$w=(t,e,n,r,i)=>e(o=>sr("exit")(t,e,n,r,(u,s)=>e(a=>i(t._3&&!u._3?F(u._1,u._2,!0):u,zT)))),Xw=(t,e,n,r,i)=>e(o=>sr("~edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(x,y)=>e(N=>{const v=p._3&&!x._3?F(x._1,x._2,!0):x;return e(L=>fn(v,e,n,r,(k,E)=>e(O=>{const Y=Gt(be)("target node identifier"),et=v._3&&!k._3?F(k._1,k._2,!0):k;return e(G=>Y(et,e,n,r,(P,V)=>e(U=>{const B=et._3&&!P._3?F(P._1,P._2,!0):P;return e(R=>je(B,e,n,r,(M,S)=>e(I=>{const D=Gt(ii("->"))("'->'"),A=B._3&&!M._3?F(M._1,M._2,!0):M;return e(H=>D(A,e,n,r,($,X)=>e(q=>{const W=A._3&&!$._3?F($._1,$._2,!0):$;return e(tt=>je(W,e,n,r,(Z,ct)=>e(ft=>{const at=Gt(be)("new source node identifier"),xt=W._3&&!Z._3?F(Z._1,Z._2,!0):Z;return e(St=>at(xt,e,n,r,(Rt,pt)=>e(Bt=>{const Jt=xt._3&&!Rt._3?F(Rt._1,Rt._2,!0):Rt;return e(mt=>fn(Jt,e,n,r,(gt,K)=>e(nt=>{const ht=Gt(be)("new target node identifier"),_t=Jt._3&&!gt._3?F(gt._1,gt._2,!0):gt;return e(Nt=>ht(_t,e,n,r,(wt,Kt)=>e(Se=>i(_t._3&&!wt._3?F(wt._1,wt._2,!0):wt,Wn("RepointEdge",{from:y,to:V,newFrom:pt,newTo:Kt})))))})))})))})))})))})))})))})))})))})))}))),Yw=(t,e,n,r,i)=>e(o=>sr("seed")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>Me(c,e,n,r,(d,l)=>e(_=>{const h=Gt(Rw)("integer (seed value)"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(x,y)=>e(N=>{const v=p._3&&!x._3?F(x._1,x._2,!0):x;return e(L=>je(v,e,n,r,(k,E)=>e(O=>i(v._3&&!k._3?F(k._1,k._2,!0):k,y))))})))})))}))),no=Ew((()=>{const t=Gt(Zt(e=>e==="{"))("'{'");return(e,n,r,i,o)=>n(u=>n(s=>t(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?F(a._1,a._2,!0):a;return je(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?F(_._1,_._2,!0):_,h)))})))))})())(Gt((()=>{const t=Gt(Zt(e=>e==="}"))("'}'");return(e,n,r,i,o)=>n(u=>n(s=>je(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?F(a._1,a._2,!0):a;return t(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?F(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),Vw=no((t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>(()=>{if(f.tag==="Nothing")return(l,_,h,p,m)=>m(l,Q);if(f.tag==="Just"){const l=f._1,_=sn((()=>{const h=Gt(Zt(p=>p===","))("','");return(p,m,x,y,N)=>{const v=p._3;return m(L=>m(k=>m(E=>m(O=>m(Y=>m(et=>Me(p,m,x,(G,P)=>y(F(G._1,G._2,v),P),(G,P)=>m(V=>m(U=>{const B=p._3&&!G._3?F(G._1,G._2,!0):G;return h(B,m,x,(R,M)=>y(F(R._1,R._2,v),M),(R,M)=>m(S=>{const I=B._3&&!R._3?F(R._1,R._2,!0):R;return m(D=>m(A=>{const H=p._3&&!I._3?F(I._1,I._2,!0):I;return Me(H,m,x,($,X)=>y(F($._1,$._2,v),X),($,X)=>m(q=>{const W=H._3&&!$._3?F($._1,$._2,!0):$;return m(tt=>m(Z=>{const ct=p._3&&!W._3?F(W._1,W._2,!0):W;return v1(ct,m,x,(ft,at)=>y(F(ft._1,ft._2,v),at),(ft,at)=>m(xt=>N(ct._3&&!ft._3?F(ft._1,ft._2,!0):ft,at)))}))}))}))}))})))))))))}})());return(h,p,m,x,y)=>p(N=>_(h,p,m,x,(v,L)=>p(k=>y(h._3&&!v._3?F(v._1,v._2,!0):v,Pw([l,...Ct($t.foldr,L)])))))}g()})()(t._3&&!c._3?F(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>e(f=>v1(F(s,a,!1),e,n,(d,l)=>e(_=>u(t,J)),(d,l)=>e(_=>u(d,w("Just",l))))))})),Uw=(t,e,n,r,i)=>e(o=>sr("+node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(x,y)=>e(N=>{const v=p._3&&!x._3?F(x._1,x._2,!0):x;return e(L=>e(k=>Me(v,e,n,r,(E,O)=>e(Y=>{const et=Zt(P=>P===`
15
- `||P==="\r"||P==="#"||P==="}"||P==="{"),G=v._3&&!E._3?F(E._1,E._2,!0):E;return e(P=>{const V=(R,M)=>e(S=>(M?((I,D,A,H,$)=>$(I,"")):Aw)(G._3&&!R._3?F(R._1,R._2,!0):R,e,n,r,(I,D)=>e(A=>{const H=v._3&&!I._3?F(I._1,I._2,!0):I;return e($=>{const X=(tt,Z)=>e(ct=>i(H._3&&!tt._3?F(tt._1,tt._2,!0):tt,Wn("AddNode",{id:y,label:D,shape:(()=>{const ft=Iw("shape")(Z);if(ft.tag==="Just")return ft._1==="rectangle"||ft._1==="rect"?tr:ft._1==="cylinder"||ft._1==="cyl"?El:ft._1==="parallelogram"?Cl:ft._1==="diamond"?Sl:ft._1==="ellipse"?Gl:ft._1==="document"||ft._1==="doc"?Pl:ft._1==="cloud"?Il:tr;if(ft.tag==="Nothing")return tr;g()})()}))),q=H._1,W=H._2;return e(tt=>{const Z=(ct,ft)=>{const at=ct._3;return e(xt=>at?r(ct,ft):X(H,Q))};return e(ct=>e(ft=>Me(F(q,W,!1),e,n,(at,xt)=>Z(F(at._1,at._2,!1),xt),(at,xt)=>e(St=>e(Rt=>Vw(at,e,n,(pt,Bt)=>Z(F(pt._1,pt._2,!1),Bt),(pt,Bt)=>e(Jt=>X(at._3&&!pt._3?F(pt._1,pt._2,!0):pt,Bt))))))))})})}))),U=G._1,B=G._2;return e(R=>{const M=(S,I)=>{const D=S._3;return e(A=>D?r(S,I):V(G,!1))};return e(S=>e(I=>e(D=>ka(F(U,B,!1),e,n,(A,H)=>{const $=A._3;return e(X=>$?M(F(U,B,!1),H):e(q=>et(F(U,B,!1),e,n,(W,tt)=>M(F(U,B,!1),tt),(W,tt)=>e(Z=>e(ct=>V(F(U,B,!1),!0))))))},(A,H)=>e($=>e(X=>V(F(U,B,!1),!0)))))))})})}))))})))})))}))),Zw=(t,e,n,r,i)=>e(o=>p1(t,e,n,r,(u,s)=>e(a=>{const c=Gt(N1([Uw,qw,Xw,Ww,zw,Hw,$w,Ow]))("statement (+node, -node, +edge, -edge, ~edge, enter, exit, or 'a -> b')"),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>i(f._3&&!l._3?F(l._1,l._2,!0):l,Ja("Leaf",{op:_,line:s.line,column:s.column})))))}))),Kw=(t,e,n,r,i)=>e(o=>eo("seq")(t,e,n,r,(u,s)=>e(a=>no(Ca(c1))(t._3&&!u._3?F(u._1,u._2,!0):u,e,n,r,i)))),jw=(t,e,n,r,i)=>e(o=>eo("par")(t,e,n,r,(u,s)=>e(a=>no(Ca(XT))(t._3&&!u._3?F(u._1,u._2,!0):u,e,n,r,i)))),Ca=t=>{const e=sn(tv());return(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,c)=>r(f=>u(n._3&&!a._3?F(a._1,a._2,!0):a,t(Ct($t.foldr,c))))))},tv=Aa(()=>{const t=va(Gt(Zt(e=>e==="}"))("'}'"));return(e,n,r,i,o)=>n(u=>{const s=e._3;return n(a=>n(c=>je(e,n,r,(f,d)=>i(F(f._1,f._2,s),d),(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?F(f._1,f._2,!0):f;return t(h,n,r,(p,m)=>i(F(p._1,p._2,s),m),(p,m)=>n(x=>{const y=h._3&&!p._3?F(p._1,p._2,!0):p;return n(N=>{const v=N1([(k,E,O,Y,et)=>{const G=k._3;return jw(k,E,O,(P,V)=>Y(F(P._1,P._2,G),V),et)},(k,E,O,Y,et)=>{const G=k._3;return Kw(k,E,O,(P,V)=>Y(F(P._1,P._2,G),V),et)},Zw]),L=e._3&&!y._3?F(y._1,y._2,!0):y;return n(k=>v(L,n,r,i,(E,O)=>n(Y=>{const et=L._3&&!E._3?F(E._1,E._2,!0):E;return n(G=>Me(et,n,r,i,(P,V)=>n(U=>{const B=et._3&&!P._3?F(P._1,P._2,!0):P;return n(R=>Dw(B,n,r,i,(M,S)=>n(I=>o(B._3&&!M._3?F(M._1,M._2,!0):M,O))))})))})))})}))})))))})}),Sa=t=>e=>(n,r,i,o,u)=>r(s=>eo(t)(n,r,i,o,(a,c)=>r(f=>{const d=n._3&&!a._3?F(a._1,a._2,!0):a;return r(l=>Mw(d,r,i,o,(_,h)=>r(p=>{const m=d._3&&!_._3?F(_._1,_._2,!0):_;return r(x=>je(m,r,i,o,(y,N)=>r(v=>{const L=no(Ca(c1)),k=m._3&&!y._3?F(y._1,y._2,!0):y;return r(E=>L(k,r,i,o,(O,Y)=>r(et=>{const G=k._3&&!O._3?F(O._1,O._2,!0):O;return r(P=>je(G,r,i,o,(V,U)=>r(B=>u(G._3&&!V._3?F(V._1,V._2,!0):V,{name:w("Just",h),ops:Y,kind:e}))))})))})))})))}))),ev=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>Sa("keyframe")(qT)(F(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>{if(f)return r(a,c);const l=t._1,_=t._2;return e(h=>Sa("still")(HT)(F(l,_,!1),e,n,(p,m)=>{const x=p._3;return e(y=>x?r(p,m):Sa("title")($T)(t,e,n,r,i))},i))})},i))},nv=(t,e,n,r,i)=>e(o=>eo("inside")(t,e,n,r,(u,s)=>e(a=>{const c=Gt(be)("node identifier"),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=f._3&&!l._3?F(l._1,l._2,!0):l;return e(m=>je(p,e,n,r,(x,y)=>e(N=>{const v=p._3&&!x._3?F(x._1,x._2,!0):x;return e(L=>no(b1)(v,e,n,r,(k,E)=>e(O=>{const Y=v._3&&!k._3?F(k._1,k._2,!0):k;return e(et=>je(Y,e,n,r,(G,P)=>e(V=>i(Y._3&&!G._3?F(G._1,G._2,!0):G,{node:_,doc:E}))))})))})))})))}))),b1=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>{const l=sn(rv()),_=t._3&&!c._3?F(c._1,c._2,!0):c;return e(h=>l(_,e,n,r,(p,m)=>e(x=>{const y=Ct($t.foldr,m);return i(_._3&&!p._3?F(p._1,p._2,!0):p,{seed:(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})(),frames:yt(N=>{if(N.tag==="TopFrame")return w("Just",N._1);if(N.tag==="TopInside")return J;g()})(y),interiors:yt(N=>{if(N.tag==="TopInside")return w("Just",N._1);if(N.tag==="TopFrame")return J;g()})(y)})})))}),s=t._1,a=t._2;return e(c=>e(f=>Yw(F(s,a,!1),e,n,(d,l)=>{const _=d._3;return e(h=>_?r(d,l):u(t,J))},(d,l)=>e(_=>u(d,w("Just",l))))))}),rv=Aa(()=>xw.defer(t=>(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>n(c=>nv(F(u,s,!1),n,r,(f,d)=>n(l=>n(_=>ev(e,n,r,i,(h,p)=>n(m=>o(h,y1("TopFrame",p)))))),(f,d)=>n(l=>o(f,y1("TopInside",d))))))})),iv=(()=>{const t=Gt((e,n,r,i,o)=>n(u=>n(s=>je(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?F(a._1,a._2,!0):a;return ka(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?F(_._1,_._2,!0):_,h)))}))))))("'keyframe', 'still', 'title', 'inside', or end of input");return(e,n,r,i,o)=>n(u=>n(s=>n(a=>n(c=>je(e,n,r,i,(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?F(f._1,f._2,!0):f;return b1(h,n,r,i,(p,m)=>n(x=>{const y=h._3&&!p._3?F(p._1,p._2,!0):p;return n(N=>n(v=>{const L=e._3&&!y._3?F(y._1,y._2,!0):y;return t(L,n,r,i,(k,E)=>n(O=>o(L._3&&!k._3?F(k._1,k._2,!0):k,m)))}))}))})))))))})(),ov=t=>{const e=Tw(t)(iv);if(e.tag==="Left")return Pt("Left",{msg:e._1._1,line:e._1._2.line,column:e._1._2.column});if(e.tag==="Right")return Pt("Right",e._1);g()},uv=t=>{const e=ov(t);if(e.tag==="Left")return Pt("Left",e._1.msg);if(e.tag==="Right")return Pt("Right",e._1);g()};function Ga(t,e,n,r){if(typeof window<"u"){var i=window[n];if(i!=null&&r instanceof i)return e(r)}for(var o=r;o!=null;){var u=Object.getPrototypeOf(o),s=u.constructor.name;if(s===n)return e(r);if(s==="Object")return t;o=u}return t}function oi(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function sv(t){return function(e){return function(){return e.getAttribute(t)}}}const k1=t=>{const e=sv(t);return n=>{const r=e(n);return()=>{const i=r();return uc(i,J,Xt)}}};function av(t){return function(e){return function(){e.textContent=t}}}function cv(t){return function(){return function(e){return t(e)()}}}function gv(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const fv=function(){return window};function _v(t){return function(e){return function(){e.value=t}}}function dv(t){return function(){return t.valueAsNumber}}function lv(t){return function(){return t.value}}function hv(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const pv=t=>t,mv=t=>()=>t.clientWidth||0,xv=()=>window.devicePixelRatio||1,Pa=(t,e)=>{e.innerHTML=t},Ia=(t,e,n)=>{t.style.setProperty(e,n)},yv=(t,e)=>t.querySelector(`[data-mg="${e}"]`),Nv=t=>e=>t===e,Jv=t=>t,Tv=(t,e,n)=>({tag:t,_1:e,_2:n}),wv=Wt.foldMap(Pd),L1=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},vv=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bv=Tv("AutoSize"),kv=Jv("CanvasRenderer"),Lv=t=>e=>{const n=t-e*rt(de(hn(t/e)));return e<=0?0:n<0?n+e:n},Ev=t=>T(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),Cv=t=>{const e=k1("data-markgraf-titles")(t);return()=>{const n=e();return n.tag==="Nothing"||!(n.tag==="Just"&&n._1==="false")}},Sv=t=>{const e=k1("data-markgraf-theme")(t);return()=>{const n=e();if(n.tag==="Just")return n._1==="light"?xa:n._1==="dark"?xT:n._1==="blueprint"?yT:n._1==="whiteboard"?NT:n._1==="isometric"?JT:xa;if(n.tag==="Nothing")return xa;g()}},Gv=`
1
+ var $v=(function(Su){"use strict";function Qa(t){let e=0,n;return()=>{if(e===2)return n;if(e===1)throw new Error("Binding demanded before initialized");return e=1,n=t(),e=2,n}}function g(){throw new Error("Failed pattern match")}function Gn(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const Ee=t=>e=>t,O=function(t){return function(e){for(var n=e.length,r=new Array(n),i=0;i<n;i++)r[i]=t(e[i]);return r}},C1={map:O},Ra=t=>t,wt=typeof Array.prototype.flatMap=="function"?function(t){return function(e){return t.flatMap(e)}}:function(t){return function(e){for(var n=[],r=t.length,i=0;i<r;i++)for(var o=e(t[i]),u=o.length,s=0;s<u;s++)n.push(o[s]);return n}},ee=function(t){return t.toString()},Ma=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},S1=function(t){var e=t.length;return'"'+t.replace(/[\0-\x1F\x7F"\\]/g,function(n,r){switch(n){case'"':case"\\":return"\\"+n;case"\x07":return"\\a";case"\b":return"\\b";case"\f":return"\\f";case`
2
+ `:return"\\n";case"\r":return"\\r";case" ":return"\\t";case"\v":return"\\v"}var i=r+1,o=i<e&&t[i]>="0"&&t[i]<="9"?"\\&":"";return"\\"+n.charCodeAt(0).toString(10)+o})+'"'},Gu=t=>t,Je=Gu("LT"),Te=Gu("GT"),De=Gu("EQ"),w=(t,e)=>({tag:t,_1:e}),J=w("Nothing"),Ut=t=>w("Just",t),za=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;g()},Ha=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;g()},Dt=(t,e)=>({tag:t,_1:e}),G1=t=>Dt("Right",t),P1={map:t=>e=>{if(e.tag==="Left")return Dt("Left",e._1);if(e.tag==="Right")return Dt("Right",t(e._1));g()}},Wa={apply:t=>e=>{if(t.tag==="Left")return Dt("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Dt("Left",e._1);if(e.tag==="Right")return Dt("Right",t._1(e._1))}g()},Functor0:()=>P1},D1={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Dt("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}g()},Apply0:()=>Wa},I1={pure:G1,Apply0:()=>Wa},Oa={Applicative0:()=>I1,Bind1:()=>D1},A1=t=>t,F1={map:t=>e=>t(e)},Ya={apply:t=>e=>t(e),Functor0:()=>F1},B1={bind:t=>e=>e(t),Apply0:()=>Ya},Q1={pure:A1,Apply0:()=>Ya},qn={Applicative0:()=>Q1,Bind1:()=>B1},R1=function(t){return function(){return t}},M1={apply:t=>e=>()=>{const n=t(),r=e();return Pu.pure(n(r))()},Functor0:()=>z1},Pu={pure:R1,Apply0:()=>M1},z1={map:t=>e=>()=>{const n=e();return t(n)}},ri=(t,e)=>({tag:t,_1:e}),$a=t=>ri("Loop",t),H1={tailRecM:t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="Loop"){r=t(u._1);continue}if(u.tag==="Done"){i=!1,o=u._1;continue}g()}return o};return n=>e(t(n))},Monad0:()=>qn},W1=function(t){return function(e){return function(){return t(e())}}},O1=function(t){return function(){return t}},Y1={map:W1},$1={apply:t=>e=>()=>{const n=t(),r=e();return qa.pure(n(r))()},Functor0:()=>Y1},qa={pure:O1,Apply0:()=>$1},q1=(function(t){return function(e){return function(n){return function(){return t(e,n)}}}})(function(t,e){return e.push(t)}),X1=(t,e)=>({tag:"Iterator",_1:t,_2:e}),V1=t=>e=>n=>()=>{let r=!1;const i=e._2;for(;!r;){const o=i.value,u=e._1(o);if(u.tag==="Just"&&t(u._1)){n.push(u._1),e._2.value;const s=e._2.value;e._2.value=s+1|0;continue}r=!0}},U1=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const i=r.value,o=r.value;r.value=o+1|0;const u=t._1(i);if(u.tag==="Just"){e(u._1)();continue}if(u.tag==="Nothing"){n=!0;continue}g()}},ii=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=i-1;o>=0;o--)r=t(n[o])(r);return r}}},T=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=0;o<i;o++)r=t(r)(n[o]);return r}}},Du=t=>{const e=t.Apply0();return n=>r=>n.foldr(i=>{const o=r(i);return u=>e.apply(e.Functor0().map(s=>Ra)(o))(u)})(t.pure())},Xa=t=>{const e=Du(t);return n=>{const r=e(n);return i=>o=>r(o)(i)}},zt={foldr:ii,foldl:T,foldMap:t=>{const e=t.mempty;return n=>zt.foldr(r=>i=>t.Semigroup0().append(n(r))(i))(e)}},b=(t,e)=>({tag:"Tuple",_1:t,_2:e}),Pn=t=>e=>b(t,e),no=t=>t._2,ro=t=>t._1,Bt=function(t){return function(e){for(var n=e.length,r=Array(n),i=0;i<n;i++)r[i]=t(i)(e[i]);return r}};var Iu=function(t){return function(e){return t===e}};const K1=Iu,Z1=Iu,oi=Iu,Au=function(t){return function(e){return function(n){if(e.length!==n.length)return!1;for(var r=0;r<e.length;r++)if(!t(e[r])(n[r]))return!1;return!0}}},dn={eq:oi},j1={eq:Z1},Er={eq:K1};var Fu=function(t){return function(e){return function(n){return function(r){return function(i){return r<i?t:r===i?e:n}}}}};const td=Fu,ed=Fu,S={compare:Fu(Je)(De)(Te),Eq0:()=>dn},it={compare:ed(Je)(De)(Te),Eq0:()=>j1},nt={compare:td(Je)(De)(Te),Eq0:()=>Er},nd=function(t){return t},rd=(function(){function t(i){return[i]}function e(i){return function(o){return[i,o]}}function n(i){return function(o){return function(u){return[i,o,u]}}}function r(i){return function(o){return i.concat(o)}}return function(i){return function(o){return function(u){return function(s){return function(a){function c(f,d){switch(d-f){case 0:return u([]);case 1:return o(t)(s(a[f]));case 2:return i(o(e)(s(a[f])))(s(a[f+1]));case 3:return i(i(o(n)(s(a[f])))(s(a[f+1])))(s(a[f+2]));default:var l=f+Math.floor((d-f)/4)*2;return i(o(r)(c(f,l)))(c(l,d))}}return c(0,a.length)}}}}}})(),id=t=>t,cr={traverse:t=>{const e=t.Apply0();return rd(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>cr.traverse(t)(id),Functor0:()=>C1,Foldable1:()=>zt},Ft=function(t,e){for(var n=t>e?-1:1,r=new Array(n*(e-t)+1),i=t,o=0;i!==e;)r[o++]=i,i+=n;return r[o]=i,r};var od=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},ud=function(t,e){for(var n=[],r=0,i=0;i<t;i++)n[r++]=e;return n};const sd=typeof Array.prototype.fill=="function"?od:ud,Ct=(function(){function t(i,o){this.head=i,this.tail=o}var e={};function n(i){return function(o){return new t(i,o)}}function r(i){for(var o=[],u=0,s=i;s!==e;)o[u++]=s.head,s=s.tail;return o}return function(i,o){return r(i(n)(e)(o))}})(),Qt=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},Va=function(t,e,n,r){for(var i=0;i<r.length;i++){var o=n(r[i]);if(e(o))return o}return t},gr=function(t,e,n,r){for(var i=0,o=r.length;i<o;i++)if(n(r[i]))return t(i);return e},Ua=function(t,e,n,r){for(var i=r.length-1;i>=0;i--)if(n(r[i]))return t(i);return e},Ka=function(t,e,n,r,i){if(n<0||n>i.length)return e;var o=i.slice();return o.splice(n,0,r),t(o)},Za=function(t,e,n,r){if(n<0||n>=r.length)return e;var i=r.slice();return i.splice(n,1),t(i)},Xn=function(t,e,n,r,i){if(n<0||n>=i.length)return e;var o=i.slice();return o[n]=r,t(o)},we=function(t){return t.slice().reverse()},We=function(t){if(t.length<=1e4)return Array.prototype.concat.apply([],t);for(var e=[],n=0,r=t.length;n<r;n++)for(var i=t[n],o=0,u=i.length;o<u;o++)e.push(i[o]);return e},at=function(t,e){return e.filter(t)},ad=function(t,e,n){for(var r=n.length,i=e,o=new Array(r),u=0;u<r;u++)i=t(i)(n[u]),o[u]=i;return o},cd=(function(){function t(e,n,r,i,o,u){var s,a,c,f,d,l,_;for(s=o+(u-o>>1),s-o>1&&t(e,n,i,r,o,s),u-s>1&&t(e,n,i,r,s,u),a=o,c=s,f=o;a<s&&c<u;)d=i[a],l=i[c],_=n(e(d)(l)),_>0?(r[f++]=l,++c):(r[f++]=d,++a);for(;a<s;)r[f++]=i[a++];for(;c<u;)r[f++]=i[c++]}return function(e,n,r){var i;return r.length<2?r:(i=r.slice(0),t(e,n,i,r.slice(0),0,r.length),i)}})(),Lt=function(t,e,n){return n.slice(t,e)},ve=function(t,e,n){for(var r=e.length<n.length?e.length:n.length,i=new Array(r),o=0;o<r;o++)i[o]=t(e[o])(n[o]);return i},Oe=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},ja=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Et=t=>e=>cd(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),gd=t=>e=>Et(n=>r=>t.compare(e(n))(e(r))),Rt=t=>e=>(()=>{const n=q1(e);return()=>{const r=[...t];return n(r)(),r}})()(),fr=t=>{if(t.length===0)return t.length-1|0,J;const e=t.length-1|0;return e>=0&&e<t.length?w("Just",{init:Lt(0,t.length-1|0,t),last:t[e]}):J},fd=t=>e=>n=>t>=0&&t<n.length?Xn(Ut,J,t,e(n[t]),n):J,_r=t=>e=>{const n=(r=>{let i=r,o=!0,u;for(;o;){const s=i;if(s>=0&&s<e.length){if(t(e[s])){i=s+1|0;continue}o=!1,u=w("Just",s);continue}o=!1,u=J}return u})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:Lt(0,n._1,e),rest:Lt(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};g()},Cr=t=>e=>{const n=Et(r=>i=>t(r._2)(i._2))(Bt(Pn)(e));return 0<n.length?O(no)(gd(nt)(ro)((()=>{const r=[n[0]];for(const i of n){const o=t((()=>{const u=r.length-1|0;if(u>=0&&u<r.length)return r[u]._2;g()})())(i._2);(o==="LT"||o==="GT"||o!=="EQ")&&r.push(i)}return r})())):[]},_d=t=>e=>{const n=[],r=X1(i=>i>=0&&i<e.length?w("Just",e[i]):J,{value:0});return U1(r)(i=>()=>{const o=[];o.push(i),V1(t(i))(r)(o)(),n.push(o)})(),n},Kt=t=>e=>{const n=gr(Ut,J,t,e);return n.tag==="Just"?w("Just",e[n._1]):J},tc=t=>e=>at(t,e),Ye=t=>e=>n=>{const r=gr(Ut,J,i=>t.eq(i)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},ec=t=>e=>wt(e)(t),xt=t=>ec(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];g()}),nc=isFinite;function dd(t,e,n,r){var i=parseFloat(t);return e(i)?n(i):r}const Vn=Math.abs,ld=Math.acos,dr=function(t){return function(e){return Math.atan2(t,e)}},io=Math.ceil,rn=Math.cos,oo=Math.exp,mn=Math.floor,rc=Math.log,hd=function(t){return function(e){return Math.min(t,e)}},Bu=function(t){return function(e){return Math.pow(t,e)}},Dn=Math.round,Ve=Math.sin,Ce=Math.sqrt,pd=Math.tan,md=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},et=function(t){return t},yd=(function(t){return function(e){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var i=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(o){if(i.test(o)){var u=parseInt(o,n);return(u|0)===u?t(u):e}else return e}}}})(Ut)(J)(10),ic=md(Ut)(J),ce=t=>{if(!nc(t))return 0;if(t>=et(2147483647))return 2147483647;if(t<=et(-2147483648))return-2147483648;const e=ic(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;g()},$t=(t,e,n)=>({tag:t,_1:e,_2:n}),Xt=$t("Nil"),Vt={foldr:t=>e=>{const n=Vt.foldl(i=>o=>t(o)(i))(e),r=(i=>o=>{let u=i,s=o,a=!0,c;for(;a;){const f=u,d=s;if(d.tag==="Nil"){a=!1,c=f;continue}if(d.tag==="Cons"){u=$t("Cons",d._1,f),s=d._2;continue}g()}return c})(Xt);return i=>n(r(i))},foldl:t=>e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=t(s)(a._1),i=a._2;continue}g()}return u},foldMap:t=>{const e=t.mempty;return n=>Vt.foldl(r=>{const i=t.Semigroup0().append(r);return o=>i(n(o))})(e)}},xd=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);u.push(n(a));var c=r(a);if(t(c))return u;s=e(c)}}}}}}},Nd=t=>{if(t.tag==="Just")return t._1;g()},Jd={unfoldr1:xd(za)(Nd)(ro)(no)},Td=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);if(t(a))return u;var c=e(a);u.push(n(c)),s=r(c)}}}}}}},wd=t=>{if(t.tag==="Just")return t._1;g()},Ue={unfoldr:Td(za)(wd)(ro)(no),Unfoldable10:()=>Jd},Yt=(t,e,n,r,i,o,u)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u}),Ke=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),uo=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),oc=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),A=Yt("Leaf"),yn=Ke("IterLeaf"),ge=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return Yt("Node",1,1,t,e,n,r);if(r.tag==="Node")return Yt("Node",1+r._1|0,1+r._2|0,t,e,n,r);g()}if(n.tag==="Node"){if(r.tag==="Leaf")return Yt("Node",1+n._1|0,1+n._2|0,t,e,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,t,e,n,r)}g()},$e=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?Yt("Node",1,1,t,e,A,A):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;g()})()?ge(r._5._3,r._5._4,ge(t,e,n,r._5._5),ge(r._3,r._4,r._5._6,r._6)):ge(r._3,r._4,ge(t,e,n,r._5),r._6):ge(t,e,n,r);if(n.tag==="Node")return r.tag==="Node"?r._1>(n._1+1|0)?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;g()})()?ge(r._5._3,r._5._4,ge(t,e,n,r._5._5),ge(r._3,r._4,r._5._6,r._6)):ge(r._3,r._4,ge(t,e,n,r._5),r._6):n._1>(r._1+1|0)?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?ge(n._6._3,n._6._4,ge(n._3,n._4,n._5,n._6._5),ge(t,e,n._6._6,r)):ge(n._3,n._4,n._5,ge(t,e,n._6,r)):ge(t,e,n,r):r.tag==="Leaf"&&n._1>1?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?ge(n._6._3,n._6._4,ge(n._3,n._4,n._5,n._6._5),ge(t,e,n._6._6,r)):ge(n._3,n._4,n._5,ge(t,e,n._6,r)):ge(t,e,n,r);g()},Sr=(t,e,n)=>{if(n.tag==="Leaf")return uo(J,A,A);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const i=Sr(t,e,n._5);return uo(i._1,i._2,$e(n._3,n._4,i._3,n._6))}if(r==="GT"){const i=Sr(t,e,n._6);return uo(i._1,$e(n._3,n._4,n._5,i._2),i._3)}if(r==="EQ")return uo(w("Just",n._4),n._5,n._6)}g()},uc=(t,e,n,r)=>{if(r.tag==="Leaf")return oc(t,e,n);if(r.tag==="Node"){const i=uc(r._3,r._4,r._5,r._6);return oc(i._1,i._2,$e(t,e,n,i._3))}g()},ui=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=uc(t._3,t._4,t._5,t._6);return $e(n._1,n._2,n._3,e)}g()},In=(t,e,n)=>{if(e.tag==="Leaf")return A;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=Sr(t,n._3,e);return ui(In(t,r._2,n._5),In(t,r._3,n._6))}g()},so=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return A;if(r.tag==="Node"){const i=Sr(t,r._3,n),o=so(t,e,i._2,r._5),u=so(t,e,i._3,r._6);if(i._1.tag==="Just")return $e(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return ui(o,u)}g()},Se=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const i=Sr(t,r._3,n),o=Se(t,e,i._2,r._5),u=Se(t,e,i._3,r._6);if(i._1.tag==="Just")return $e(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return $e(r._3,r._4,o,u)}g()},vd=t=>e=>{const n=r=>{if(r.tag==="Leaf")return A;if(r.tag==="Node"){const i=e(r._3)(r._4);if(i.tag==="Just")return $e(r._3,i._1,n(r._5),n(r._6));if(i.tag==="Nothing")return ui(n(r._5),n(r._6))}g()};return n},xn=(t=>e=>n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="IterLeaf"){i=!1,o=e();continue}if(u.tag==="IterEmit"){i=!1,o=t(u._1,u._2,u._3);continue}if(u.tag==="IterNode"){r=(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Leaf"){d=!1,l=_;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){c=Ke("IterEmit",h._3,h._4,_),f=h._5;continue}c=Ke("IterEmit",h._3,h._4,Ke("IterNode",h._6,_)),f=h._5;continue}g()}return l})(u._2)(u._1);continue}g()}return o})((t,e,n)=>w("Just",b(b(t,e),n)))(t=>J),bt=t=>e=>n=>r=>{const i=o=>{if(o.tag==="Leaf")return Yt("Node",1,1,n,r,A,A);if(o.tag==="Node"){const u=t.compare(n)(o._3);if(u==="LT")return $e(o._3,o._4,i(o._5),o._6);if(u==="GT")return $e(o._3,o._4,o._5,i(o._6));if(u==="EQ")return Yt("Node",o._1,o._2,n,e(o._4)(r),o._5,o._6)}g()};return i},tt=t=>e=>n=>{const r=i=>{if(i.tag==="Leaf")return Yt("Node",1,1,e,n,A,A);if(i.tag==="Node"){const o=t.compare(e)(i._3);if(o==="LT")return $e(i._3,i._4,r(i._5),i._6);if(o==="GT")return $e(i._3,i._4,i._5,r(i._6));if(o==="EQ")return Yt("Node",i._1,i._2,e,n,i._5,i._6)}g()};return r},te=t=>e=>e.foldl(n=>r=>tt(t)(r._1)(r._2)(n))(A),si=t=>e=>{const n=r=>{if(r.tag==="Leaf")return A;if(r.tag==="Node"){const i=t.compare(e)(r._3);if(i==="LT")return $e(r._3,r._4,n(r._5),r._6);if(i==="GT")return $e(r._3,r._4,r._5,n(r._6));if(i==="EQ")return ui(r._5,r._6)}g()};return n},sc=t=>{const e=t.compare;return n=>r=>i=>{const o=Sr(e,r,i),u=n(o._1);if(u.tag==="Nothing")return ui(o._2,o._3);if(u.tag==="Just")return $e(r,u._1,o._2,o._3);g()}},se=function(t){return function(e){return t+e|0}},Gr=function(t){return function(e){return t+e}},Un=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},bd=function(t){return function(e){return t+e}},re=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},kd={append:bd},Ld={append:re},Ed={mempty:"",Semigroup0:()=>kd},Cd={mempty:[],Semigroup0:()=>Ld},Sd=null;function ac(t,e,n){return t==null?e:n(t)}function Yv(t){return t}function Qu(t){return function(e){return function(n){return t.apply(n,[e])}}}const Gd=Qu(Number.prototype.toPrecision),Pd=Qu(Number.prototype.toFixed),Dd=Qu(Number.prototype.toExponential),ai=(t,e)=>({tag:t,_1:e}),ci=t=>e=>n=>{const r=nt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=nt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},gi=t=>{if(t.tag==="Precision")return Gd(t._1);if(t.tag==="Fixed")return Pd(t._1);if(t.tag==="Exponential")return Dd(t._1);g()},cc=function(t){return function(){console.log(t)}};function Id(){return Date.now()}function Ad(t){return function(){return t.getContext("2d")}}function Fd(t){return function(){return t.width}}function Bd(t){return function(){return t.height}}function Qd(t){return function(e){return function(){t.width=e}}}function Rd(t){return function(e){return function(){t.height=e}}}function Ru(t){return function(e){return function(){t.lineWidth=e}}}function Md(t){return function(e){return function(){t.fillStyle=e}}}function zd(t){return function(e){return function(){t.strokeStyle=e}}}function Mu(t){return function(e){return function(){t.lineCap=e}}}function zu(t){return function(e){return function(){t.lineJoin=e}}}function Hd(t){return function(e){return function(){t.globalCompositeOperation=e}}}function Wd(t){return function(e){return function(){t.globalAlpha=e}}}function gc(t){return function(){t.beginPath()}}function Hu(t){return function(){t.stroke()}}function Wu(t){return function(){t.fill()}}function Od(t){return function(){t.clip()}}function fi(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function fc(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function _c(t){return function(){t.closePath()}}function Yd(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function $d(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function ao(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function Ou(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function qd(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function Xd(t){return function(e){return function(){t.textAlign=e}}}function Vd(t){return function(e){return function(){t.textBaseline=e}}}function Ud(t){return function(e){return function(){t.font=e}}}function Kd(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function Kn(t){return function(){t.save()}}function Zn(t){return function(){t.restore()}}function _i(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function Zd(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const dc=t=>t,Yu=t=>t,$u=t=>t,qu=t=>t,co=t=>t,jd=co("BaselineTop"),tl=co("BaselineMiddle"),el=co("BaselineAlphabetic"),nl=co("BaselineBottom"),rl=qu("AlignLeft"),il=qu("AlignRight"),ol=qu("AlignCenter"),Xu=$u("BevelJoin"),go=$u("RoundJoin"),Vu=$u("MiterJoin"),Uu=Yu("Round"),Ku=Yu("Square"),Zu=Yu("Butt"),ul=dc("SourceOver"),sl=dc("Difference"),al=t=>e=>Vd(t)((()=>{if(e==="BaselineTop")return"top";if(e==="BaselineHanging")return"hanging";if(e==="BaselineMiddle")return"middle";if(e==="BaselineAlphabetic")return"alphabetic";if(e==="BaselineIdeographic")return"ideographic";if(e==="BaselineBottom")return"bottom";g()})()),cl=t=>e=>Xd(t)((()=>{if(e==="AlignLeft")return"left";if(e==="AlignRight")return"right";if(e==="AlignCenter")return"center";if(e==="AlignStart")return"start";if(e==="AlignEnd")return"end";g()})()),fo=t=>e=>{if(e==="BevelJoin")return zu(t)("bevel");if(e==="RoundJoin")return zu(t)("round");if(e==="MiterJoin")return zu(t)("miter");g()},ju=t=>e=>{if(e==="Round")return Mu(t)("round");if(e==="Square")return Mu(t)("square");if(e==="Butt")return Mu(t)("butt");g()},lc=t=>e=>Hd(t)((()=>{if(e==="SourceOver")return"source-over";if(e==="SourceIn")return"source-in";if(e==="SourceOut")return"source-out";if(e==="SourceAtop")return"source-atop";if(e==="DestinationOver")return"destination-over";if(e==="DestinationIn")return"destination-in";if(e==="DestinationOut")return"destination-out";if(e==="DestinationAtop")return"destination-atop";if(e==="Lighter")return"lighter";if(e==="Copy")return"copy";if(e==="Xor")return"xor";if(e==="Multiply")return"multiply";if(e==="Screen")return"screen";if(e==="Overlay")return"overlay";if(e==="Darken")return"darken";if(e==="Lighten")return"lighten";if(e==="ColorDodge")return"color-dodge";if(e==="ColorBurn")return"color-burn";if(e==="HardLight")return"hard-light";if(e==="SoftLight")return"soft-light";if(e==="Difference")return"difference";if(e==="Exclusion")return"exclusion";if(e==="Hue")return"hue";if(e==="Saturation")return"saturation";if(e==="Color")return"color";if(e==="Luminosity")return"luminosity";g()})()),Qe={foldr:t=>e=>{const n=Vt.foldr(t)(e);return r=>n((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,$t("Cons",o._3,i(o._6,u)));g()};return i(r,Xt)})())}},gl=t=>{const e={append:(()=>{const n=t.compare;return r=>i=>Se(n,Ee,r,i)})()};return{mempty:A,Semigroup0:()=>e}},di=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},lr=function(t){return t.join("")},hr=function(t){return t.split("")},_o=function(t){return t},jn=function(t){return t.length},hc=function(t){return function(e){return e.substr(0,t)}},li=function(t){return function(e){return e.substring(t)}},fl=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},_l=t=>e=>{const n=fl(jn(t))(e);return n.before===t?w("Just",n.after):J},dl=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},ll=function(t){return t()},hl=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},pl=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},pr=t=>BigInt(t),ml=t=>Number(t),lo=t=>e=>t+e,ho=t=>e=>t*e,ts=t=>e=>t-e,pc=0n,po=1n,mc=t=>e=>t^e,hi=t=>e=>t&e,es=t=>e=>t<<e,ns=t=>e=>t>>e,yl=t=>e=>t==e,xl=t=>e=>t===e?0:t>e?1:-1,Nl={eq:yl},yc={compare:t=>e=>{const n=xl(t)(e);return n===1?Te:n===0?De:Je},Eq0:()=>Nl},Jl=hl(Ut)(J),Tl=pl(Ut)(J),xc=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=it.compare(e._1)(n._1);return r==="LT"?Je:r==="GT"?Te:it.compare(e._2)(n._2)},Eq0:()=>t}})(),wl=t=>e=>Vn(t._1-e._1)+Vn(t._2-e._2),mr=t=>t,mo=t=>t,le=mo("North"),he=mo("South"),An=mo("East"),Fn=mo("West"),tr=mr("Rectangle"),vl=mr("Cylinder"),bl=mr("Parallelogram"),kl=mr("Diamond"),Ll=mr("Ellipse"),El=mr("Document"),Cl=mr("Cloud"),Nc=t=>t,Jc=T(Gr)(0),Sl=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},ln=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Pr=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Tc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},wc=t=>{const e={top:0,bottom:0,left:0,right:0},n=t.shape==="Cloud"?{...e,top:t.h*.38}:t.shape==="Cylinder"?{...e,bottom:5}:t.shape==="Document"?{...e,bottom:t.h*.05}:e;return[{x:t.x-n.left,y:t.y-n.top},{x:t.x+t.w+n.right,y:t.y+t.h+n.bottom}]},yr=t=>e=>{const n=ve(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,c=s.x-u.x;return Ce(c*c+a*a)})()}),t,Lt(1,t.length,t)),r=Jc(O(u=>u.len)(n)),i=Sl(0)(r)(e*r),o=u=>s=>a=>{let c=u,f=s,d=a,l=!0,_;for(;l;){const h=c,p=f,m=d,y=Qt(x=>J,x=>N=>w("Just",{head:x,tail:N}),h);if(y.tag==="Nothing"){const x=t.length-1|0;if(x>=0&&x<t.length){l=!1,_=t[x];continue}l=!1,_=m;continue}if(y.tag==="Just"){if(p<=y._1.head.len){const x=y._1.head.len<=0?0:p/y._1.head.len;l=!1,_={x:y._1.head.a.x+(y._1.head.b.x-y._1.head.a.x)*x,y:y._1.head.a.y+(y._1.head.b.y-y._1.head.a.y)*x};continue}c=y._1.tail,f=p-y._1.head.len,d=m;continue}g()}return _};return 0<t.length?w("Just",o(n)(i)(t[0])):J},pi=t=>Jc(ve(e=>n=>{const r=n.y-e.y,i=n.x-e.x;return Ce(i*i+r*r)},t,Lt(1,t.length,t))),Gl=t=>e=>n=>r=>i=>{const o=0<t.length?w("Just",t[0]):J,u=(()=>{if(o.tag==="Nothing")return e;if(o.tag==="Just")return o._1;g()})(),s=t.length-1|0,a=s>=0&&s<t.length?w("Just",t[s]):J,c=(()=>{if(a.tag==="Nothing")return n;if(a.tag==="Just")return a._1;g()})(),f=ln(.05)(1-i.pre-i.post),d=r<i.pre?0:r>1-i.post?1:(r-i.pre)/f,l=c.x-n.x,_=2*(()=>{const v=c.y-n.y;return(l<0?-l:l)+(v<0?-v:v)})(),h=u.x-e.x,p=2*(()=>{const v=u.y-e.y;return(h<0?-h:h)+(v<0?-v:v)})(),m=p+pi(t)+_,y=m<=1e-4?1:1-_/m,x=m<=1e-4?0:p/m;if(d<=x){const v=x<=1e-4?1:d/x;return{x:e.x+(u.x-e.x)*v,y:e.y+(u.y-e.y)*v}}if(d>=y){const v=y>=1?0:(d-y)/(1-y);return{x:c.x+(n.x-c.x)*v,y:c.y+(n.y-c.y)*v}}const N=yr(t)((d-x)/ln(1e-4)(y-x));if(N.tag==="Nothing")return u;if(N.tag==="Just")return N._1;g()},Pl=t=>{const e=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return e(r._5,$t("Cons",r._4,e(r._6,i)));g()},n=Qt(r=>J,r=>i=>w("Just",{head:r,tail:i}),wt(Ct(Vt.foldr,e(t.nodes,Xt)))(wc));if(n.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(n.tag==="Just"){const r=T(i=>o=>({minX:Pr(i.minX)(o.x),minY:Pr(i.minY)(o.y),maxX:ln(i.maxX)(o.x),maxY:ln(i.maxY)(o.y)}))({minX:n._1.head.x,minY:n._1.head.y,maxX:n._1.head.x,maxY:n._1.head.y})(n._1.tail);return{x:r.minX,y:r.minY,w:r.maxX-r.minX,h:r.maxY-r.minY}}g()},Dl=t=>e=>{const n=ln(4)(.15*Pr(e.w)(e.h)),r=ln(1)(t.w),i=ln(1)(t.h),o=ln(1)(e.w-2*n),u=ln(1)(e.h-2*n),s=Pr(o/r)(u/i);return{scale:s,tx:e.x+n+(o-r*s)/2-t.x*s,ty:e.y+n+(u-i*s)/2-t.y*s}},rs={scale:1,tx:0,ty:0},qe=t=>{const e=Qt(n=>J,n=>r=>w("Just",{head:n,tail:r}),[...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,$t("Cons",r._4,n(r._6,i)));g()};return wt(Ct(Vt.foldr,n(t.nodes,Xt)))(wc)})(),...We((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,$t("Cons",r._4,n(r._6,i)));g()};return Ct(Vt.foldr,n(t.edges,Xt))})()),...We((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,$t("Cons",r._4,n(r._6,i)));g()};return Ct(Vt.foldr,n(t.chipExtras,Xt))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=T(r=>i=>({minX:Pr(r.minX)(i.x),minY:Pr(r.minY)(i.y),maxX:ln(r.maxX)(i.x),maxY:ln(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},Il=t=>e=>(n=>r=>i=>{let o=n,u=r,s=i,a=!0,c;for(;a;){const f=o,d=u,l=s,_=Qt(h=>J,h=>p=>w("Just",{head:h,tail:p}),d);if(_.tag==="Nothing"){a=!1,c=l;continue}if(_.tag==="Just"){const h=Tc(_._1.head)(f.interiors);if(h.tag==="Nothing"){a=!1,c=l;continue}if(h.tag==="Just"){o=h._1,u=_._1.tail,s=(()=>{const p=Dl(qe(h._1.layout))((()=>{const m=Tc(_._1.head)(f.layout.nodes);if(m.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:tr};if(m.tag==="Just")return m._1;g()})());return{scale:l.scale*p.scale,tx:l.scale*p.tx+l.tx,ty:l.scale*p.ty+l.ty}})();continue}}g()}return c})(t)(e)(rs),vc=t=>t,bc=(t,e)=>({tag:t,_1:e}),is=t=>t,mi=(t,e)=>({tag:t,_1:e}),os=(t,e)=>({tag:t,_1:e}),yi=is("Animated"),Al=is("StaticStill"),Fl=is("TitleCard"),Bl=os("First"),Ql=vc("Forward"),Rl=vc("Backward"),Ml=mi("ExitNode"),kc=te(S)(zt),zl=t=>ii(e=>n=>({nodes:Se(S.compare,Ee,e.nodes,n.nodes),edges:Se(S.compare,Ee,e.edges,n.edges)}))({nodes:A,edges:A})(t.keyframes),Hl=t=>e=>({entering:{nodes:In(S.compare,e.nodes,t.nodes),edges:In(S.compare,e.edges,t.edges)},leaving:{nodes:In(S.compare,t.nodes,e.nodes),edges:In(S.compare,t.edges,e.edges)},surviving:{nodes:so(S.compare,Ee,t.nodes,e.nodes),edges:so(S.compare,Ee,t.edges,e.edges)}}),yo=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Dr=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},xi=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},us=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Wl=T(t=>e=>tt(S)(e)()(t))(A),Ol=T(t=>e=>tt(S)(e)()(t))(A),Yl=(()=>{const t=Ue.unfoldr(xn);return e=>t(Ke("IterNode",e,yn))})(),Lc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Ec=te(S)(zt),Ni=t=>{const e=Qt(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=T(r=>i=>({minX:yo(r.minX)(i.x),minY:yo(r.minY)(i.y),maxX:Dr(r.maxX)(i.x),maxY:Dr(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},$l=t=>{const e=Qt(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return J;if(e.tag==="Just")return w("Just",Ni(t));g()},ql=t=>e=>n=>Wl(wt(Ct(Qe.foldr,n))(r=>{const i=xi(r)(t);if(i.tag==="Just")return at(o=>!us(o)(e),[i._1.source,i._1.target]);if(i.tag==="Nothing")return[];g()})),Xl=t=>t.kind.tag==="SendToken"?w("Just",b(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):J,Vl=t=>t.tag==="DataFlow"?xt(Xl)(t._1.events):[],Ul=t=>e=>Ol(xt(n=>us(n._2.source)(e)||us(n._2.target)(e)?w("Just",n._1):J)(Yl(t))),Kl=t=>{const e=t.length-1|0;return e>=0&&e<t.length?0<t.length?t[0].x===t[e].x&&t[0].y===t[e].y?w("Just",Ni([t[0]])):w("Just",Ni([t[0],t[e]])):J:0<t.length?w("Just",Ni([t[0]])):J},xo=t=>{const e=Qt(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=T(r=>i=>({minX:yo(r.minX)(i.x),minY:yo(r.minY)(i.y),maxX:Dr(r.maxX)(i.x+i.w),maxY:Dr(r.maxY)(i.y+i.h)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x+e._1.head.w,maxY:e._1.head.y+e._1.head.h})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},Cc=t=>e=>n=>{if(n.tag==="Leaf")return qe(t);const r=Ul(e)(n),i=[...xt(o=>{const u=Lc(o)(t.nodes);return u.tag==="Just"?w("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):J})(Ct(Qe.foldr,Se(S.compare,Ee,n,ql(e)(n)(r)))),...xt(o=>{const u=xi(o)(t.edges);return u.tag==="Just"?w("Just",Ni(u._1)):J})(Ct(Qe.foldr,r)),...xt(o=>{const u=xi(o)(t.chipExtras);if(u.tag==="Just")return $l(u._1);if(u.tag==="Nothing")return J;g()})(Ct(Qe.foldr,r))];return i.length===0?qe(t):xo(i)},Ji=t=>e=>n=>{const r=[...xt(i=>i)([(()=>{const i=xi(n)(t.chipExtras);if(i.tag==="Just")return Kl(i._1);if(i.tag==="Nothing")return J;g()})()]),...(()=>{const i=xi(n)(e);if(i.tag==="Just")return xt(o=>{const u=Lc(o)(t.nodes);return u.tag==="Just"?w("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):J})([i._1.source,i._1.target]);if(i.tag==="Nothing")return[];g()})()];return r.length===0?Cc(t)(e)(A):xo(r)},Sc=t=>e=>{const n=qe(t),r=n.w/Dr(1e-4)(e.zoom),i=n.h/Dr(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-i/2,w:r,h:i}},Zl=t=>Se(S.compare,Ee,Ec(O(e=>b(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),Ec(wt(t.scenes)(Vl))),No=t=>t,jl=t=>t,Ti=No("Linear"),th=No("EaseInOutQuad"),Jo=No("EaseInOutCubic"),eh=No("SpringBouncy"),wi=t=>e=>n=>{const r=Ce(1-e*e),i=t*r;return 1-oo(-e*t*n)*(rn(i*n)+e/r*Ve(i*n))},nh=t=>{const e=it.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=it.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},vi=t=>e=>(()=>{if(t==="Linear")return jl;if(t==="EaseInQuad")return n=>n*n;if(t==="EaseOutQuad")return n=>1-(1-n)*(1-n);if(t==="EaseInOutQuad")return n=>n<.5?2*n*n:1-2*(1-n)*(1-n);if(t==="EaseInCubic")return n=>n*n*n;if(t==="EaseOutCubic")return n=>1-(1-n)*(1-n)*(1-n);if(t==="EaseInOutCubic")return n=>n<.5?4*n*n*n:1-(-2*n+2)*(-2*n+2)*(-2*n+2)/2;if(t==="EaseOutExpo")return n=>n>=1?1:1-Bu(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*oo(-6*n);if(t==="SpringBouncy")return wi(6)(.7);g()})()(nh(e)),Gc=t=>t,ss=t=>t,To=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},bi=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Pc=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},rh=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ih=ss("Hold"),oh=ss("Gap"),uh=ss("Move"),ki=Gc("LinearLerp"),Dc=Gc("LogLerp"),sh=t=>e=>n=>{const r=n.center.y-e.center.y,i=n.center.x-e.center.x,o=Ce(i*i+r*r),u=n.zoom-e.zoom,s=u<0?-u:u;return To(t.minTransition)(t.maxTransition)(bi(t.panSpeed<=0?t.minTransition:o/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:s/t.zoomSpeed))},ah=T(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:Rt(t)(e)})([]),Ic=t=>e=>{const n={x:0,y:0},r=0<t.length?t[0].pos:n,i=Ua(Ut,J,o=>o.t<=e,t);if(i.tag==="Nothing")return r;if(i.tag==="Just"){const o=i._1+1|0;if(o>=0&&o<t.length){if(i._1>=0&&i._1<t.length){const u=To(0)(1)(t[o].t<=t[i._1].t?0:(e-t[i._1].t)/(t[o].t-t[i._1].t));return{x:t[i._1].pos.x+(t[o].pos.x-t[i._1].pos.x)*u,y:t[i._1].pos.y+(t[o].pos.y-t[i._1].pos.y)*u}}return n}return i._1>=0&&i._1<t.length?t[i._1].pos:n}g()},as=t=>e=>({center:{x:e.center.x*t.scale+t.tx,y:e.center.y*t.scale+t.ty},zoom:e.zoom/bi(1e-6)(t.scale)}),ch=t=>e=>n=>({center:{x:t.center.x+(e.center.x-t.center.x)*n,y:t.center.y+(e.center.y-t.center.y)*n},zoom:oo((()=>{const r=rc(bi(1e-6)(t.zoom));return r+(rc(bi(1e-6)(e.zoom))-r)*n})())}),gh=t=>e=>n=>{const r=vi(n.easing)(To(0)(1)(n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT)));if(n.interp==="LinearLerp")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};if(n.interp==="LogLerp")return ch(n.fromCam)(n.toCam)(r);g()},fh=t=>e=>n=>r=>{const i=(u,s)=>Pc(sh(t)(u.toCam)(s.toCam))(u.endT-u.startT),o=T(u=>s=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:w("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 f=u.pending._1.toCam.zoom-s.toCam.zoom;return f<0?-f<.08:f<.08})()})()})()||i(u.pending._1,s)<=0?{acc:Rt(u.acc)(u.pending._1),pending:w("Just",s)}:{acc:Rt(Rt(u.acc)({...u.pending._1,endT:s.startT-i(u.pending._1,s)}))({startT:s.startT-i(u.pending._1,s),endT:s.startT,fromCam:u.pending._1.toCam,toCam:s.toCam,easing:s.easing,interp:ki}),pending:w("Just",s)};g()})({acc:[],pending:J})(r);if(o.pending.tag==="Nothing")return o.acc;if(o.pending.tag==="Just")return Rt(o.acc)(o.pending._1);g()},_h=t=>e=>{const n=r=>{const i=Ua(Ut,J,o=>o.kind==="Hold"||o.kind==="Move",r<1?[]:Lt(0,r,e));if(i.tag==="Just")return i._1>=0&&i._1<e.length?w("Just",e[i._1].toCam):J;if(i.tag==="Nothing")return J;g()};return Bt(r=>i=>{if(i.kind==="Hold")return{startT:i.startT,endT:i.endT,fromCam:i.fromCam,toCam:i.toCam,easing:i.easing,interp:ki};if(i.kind==="Move")return{startT:i.startT,endT:i.endT,fromCam:i.fromCam,toCam:i.toCam,easing:Ti,interp:ki};if(i.kind==="Gap")return{startT:i.startT,endT:i.endT,fromCam:(()=>{const o=n(r);if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;g()})(),toCam:(()=>{const o=n(r),u=(()=>{if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;g()})(),s=r+1|0,a=gr(Ut,J,c=>c.kind==="Hold"||c.kind==="Move",s<1?e:Lt(s,e.length,e));if(a.tag==="Just"){const c=(r+1|0)+a._1|0;return c>=0&&c<e.length?e[c].fromCam:u}if(a.tag==="Nothing")return u;g()})(),easing:i.easing,interp:ki};g()})(e)},dh={padding:24,easing:Ti,minZoom:.9,maxZoom:2.5,tokenZoomFloor:0,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:16},cs=t=>e=>n=>{const r=e.w+n*2,i=e.h+n*2,o=qe(t);return r<=0||i<=0||o.w<=0||o.h<=0?1:Pc(o.w/r)(o.h/i)},lh=T(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?w("Just",t[n]):J;return r.tag==="Just"&&r._1.fromCam.zoom===r._1.toCam.zoom&&r._1.fromCam.center.x===r._1.toCam.center.x&&r._1.fromCam.center.y===r._1.toCam.center.y&&e.fromCam.zoom===e.toCam.zoom&&e.fromCam.center.x===e.toCam.center.x&&e.fromCam.center.y===e.toCam.center.y&&(()=>{const i=r._1.toCam.center.x-e.toCam.center.x;return(i<0?-i<8:i<8)&&(()=>{const o=r._1.toCam.center.y-e.toCam.center.y;return(o<0?-o<8:o<8)&&(()=>{const u=r._1.toCam.zoom-e.toCam.zoom;return u<0?-u<.08:u<.08})()})()})()?Rt((()=>{const i=t.length-1|0;return i<1?[]:Lt(0,i,t)})())({...r._1,endT:e.endT}):Rt(t)(e)})([]),Li=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:bi(r)(To(t.minZoom)(t.maxZoom)(cs(e)(n)(t.padding)))}),hh=t=>e=>n=>r=>{const i=Et(s=>a=>nt.compare(a.priority)(s.priority)),o=Li(t)(e)(qe(e))(0),u=at(s=>s>=0&&s<=n,ah(Et(it.compare)([0,n,...wt(r)(s=>[s.startT,s.endT]),...wt(r)(s=>{if(s.pathFollow.tag==="Nothing")return[];if(s.pathFollow.tag==="Just")return O(a=>a.t)(s.pathFollow._1.samples);g()})])));return fh(t)(e)(o)(lh(_h(o)(xt(s=>{const a=(s._1+s._2)/2;if(s._2<=s._1)return J;const c=xt(d=>d.pathFollow)(i(at(d=>d.startT<=a&&a<d.endT,r)));if(0<c.length)return w("Just",{kind:uh,startT:s._1,endT:s._2,fromCam:{center:Ic(c[0].samples)(s._1),zoom:c[0].zoom},toCam:{center:Ic(c[0].samples)(s._2),zoom:c[0].zoom},easing:Ti});const f=O(d=>d.bbox)(at(d=>d.priority===T(rh)(0)(O(l=>l.priority)(at(l=>l.startT<=a&&a<l.endT,r))),at(d=>d.startT<=a&&a<d.endT,r)));return f.length===0?w("Just",{kind:oh,startT:s._1,endT:s._2,fromCam:o,toCam:o,easing:t.easing}):w("Just",{kind:ih,startT:s._1,endT:s._2,fromCam:Li(t)(e)(xo(f))(Oe(d=>d.priority>=1,at(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),toCam:Li(t)(e)(xo(f))(Oe(d=>d.priority>=1,at(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),easing:t.easing})})(ve(Pn,u,Lt(1,u.length,u))))))},Ac=t=>e=>n=>r=>{const i=Kt(o=>r>=o.startT&&r<o.endT)(n);if(i.tag==="Just")return gh()(r)(i._1);if(i.tag==="Nothing"){const o=n.length-1|0;if(o>=0&&o<n.length&&r>=n[o].endT)return n[o].toCam;const u=Li(t)(e)(qe(e))(0);return 0<n.length?n[0].fromCam:u}g()};function er(t){return t.charCodeAt(0)}function Fc(t){return String.fromCharCode(t)}const nr=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},wo=function(t){return function(e){return e.split(t)}},ph=function(t){return t.trim()},vo=function(t){return function(e){return e.join(t)}};var mh=typeof Array.from=="function",yh=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",xh=typeof String.prototype.fromCodePoint=="function",Nh=typeof String.prototype.codePointAt=="function";const Jh=function(t){return Nh?function(e){return e.codePointAt(0)}:t},Th=function(t){return xh?String.fromCodePoint:t},wh=function(t){return function(e){return yh?function(n){for(var r="",i=n[Symbol.iterator](),o=0;o<e;++o){var u=i.next();if(u.done)return r;r+=u.value}return r}:t(e)}},vh=function(t){return function(e){return mh?function(n){return Array.from(n,e)}:t}},bo=t=>{const e=jn(t);if(e===0)return J;if(e===1)return w("Just",{head:er(di(0)(t)),tail:""});const n=er(di(1)(t)),r=er(di(0)(t));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?w("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:li(2)(t)}):w("Just",{head:r,tail:li(1)(t)})},bh=t=>{const e=bo(t);return e.tag==="Just"?w("Just",b(e._1.head,e._1.tail)):J},kh=t=>Ue.unfoldr(bh)(t),Bc=Jh(t=>{const e=er(di(0)(t));if(55296<=e&&e<=56319&&jn(t)>1){const n=er(di(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),ko=vh(kh)(Bc),gs=t=>_o(t>=0&&t<=65535?Fc(t):t<0?"\0":"\uFFFF"),Lh=Th(t=>t<=65535?gs(t):gs(Gn(t-65536|0,1024)+55296|0)+gs(Un(t-65536|0)(1024)+56320|0)),Qc=t=>e=>{if(t<1)return"";const n=bo(e);return n.tag==="Just"?Lh(n._1.head)+Qc(t-1|0)(n._1.tail):e},ye=wh(Qc),Eh=t=>e=>e===""?J:w("Just",Bc(e)),Lo=(t,e,n)=>({tag:t,_1:e,_2:n}),Ch=()=>({tag:"ExtendFromSource"}),Eo=(t,e)=>({tag:t,_1:e}),fs=t=>t,Co=(t,e)=>({tag:t,_1:e}),_s=Co("NotYet"),Rc=Co("Consumed"),Sh=fs("FromSource"),Mc=fs("FromTarget"),Gh=fs("FromBoth"),zc=Eo("Hidden"),Ph=Eo("Visible"),Hc=Ch(),Wc=Lo("Retracted"),Dh=Lo("Extended"),Oc=t=>t,ds=(t,e)=>({tag:t,_1:e}),xr=(t,e,n)=>({tag:t,_1:e,_2:n}),Yc=t=>t,rr=(t,e)=>({tag:t,_1:e}),Ir=(t,e,n,r,i,o,u,s,a)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u,_7:s,_8:a}),Ei=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Nn=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},$c=te(S)(zt),ls=Au(oi),Ar=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},So=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ci=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},qc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Xc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Fr=(()=>{const t=Ue.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return w("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,$t("Cons",r._3,n(r._6,i)));g()};return n(e,Xt)})())})(),Ih=T(t=>e=>tt(S)(e)()(t))(A),hs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Go=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Ah=rr("NoKeyframes"),Fh=t=>rr("DuplicateEventId",t),Bh=t=>rr("UnknownEvent",t),Vc=Yc("PlopIn"),Qh=Yc("PlopOut"),Rh=Oc("DiveIn"),Mh=Oc("DiveOut"),zh=t=>e=>n=>r=>{const i=Ei(r.edge)(e.edges),o=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return pi(i._1);g()})(),u=Nn(t.minTokenDuration)(Nn(et(T(s=>a=>s+ko(a).length|0)(0)(r.labels))*t.tokenReadSecPerChar)(t.tokenSpeed<=0?0:o/t.tokenSpeed))+n.pre+n.post;return{duration:u,holdPre:u<=0?0:n.pre/u,holdPost:u<=0?0:n.post/u}},Hh=t=>e=>$c(xt(n=>{if(n.kind.tag==="SendToken")return w("Just",b(n.id,{pre:(()=>{const r=n.when;return(()=>{const i=n.kind._1.from;return Oe(o=>{if(o.kind.tag==="SendToken")return(r.tag==="First"?!1:r.tag==="After"&&r._1===o.id)&&o.kind._1.to===i;if(o.kind.tag==="FillNodeWithoutTransition")return!1;g()},e)})()?0:t.tokenHold})(),post:(()=>{const r=n.id;return(()=>{const i=n.kind._1.to;return Oe(o=>{if(o.kind.tag==="SendToken")return(o.when.tag==="First"?!1:o.when.tag==="After"&&o.when._1===r)&&o.kind._1.from===i;if(o.kind.tag==="FillNodeWithoutTransition")return!1;g()},e)})()?0:t.tokenHold})()}));if(n.kind.tag==="FillNodeWithoutTransition")return J;g()})(e)),Wh=t=>{if(t.event.kind.tag==="SendToken")return w("Just",{startT:t.startT,endT:t.endT,target:Ir("TokenWindow",t.event.id,t.event.kind._1.edge,t.event.kind._1.direction,t.event.kind._1.from,t.event.kind._1.to,t.event.kind._1.labels,t.holdPre,t.holdPost)});if(t.event.kind.tag==="FillNodeWithoutTransition")return w("Just",{startT:t.startT,endT:t.endT,target:Ir("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},Oh=t=>e=>n=>r=>{const i=Kt(o=>ls(o.path)(e)&&(Vn(o.endT-n)<1e-4||Vn(o.startT-r)<1e-4))(t.segments);if(i.tag==="Just")return w("Just",i._1);if(i.tag==="Nothing")return Kt(o=>ls(o.path)(e))(t.segments);g()},Yh=t=>e=>n=>xt(r=>{const i=xt(o=>Ci(o)(t.nodes))(Ct(Qe.foldr,(()=>{if(r.scene.tag==="Structural")return Se(S.compare,Ee,(()=>{const o=Ar(r.scene._1.from)(n);if(o.tag==="Nothing")return A;if(o.tag==="Just")return o._1.nodes;g()})(),(()=>{const o=Ar(r.scene._1.to)(n);if(o.tag==="Nothing")return A;if(o.tag==="Just")return o._1.nodes;g()})());if(r.scene.tag==="DataFlow"){const o=Ar(r.scene._1.keyframe)(n);if(o.tag==="Nothing")return A;if(o.tag==="Just")return o._1.nodes;g()}if(r.scene.tag==="Hold"){const o=Ar(r.scene._1)(n);if(o.tag==="Nothing")return A;if(o.tag==="Just")return o._1.nodes;g()}if(r.scene.tag==="EnterNode"||r.scene.tag==="ExitNode")return A;g()})()));return i.length===0?J:w("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const o=T(u=>s=>({minX:So(u.minX)(s.x),minY:So(u.minY)(s.y),maxX:Nn(u.maxX)(s.x+s.w),maxY:Nn(u.maxY)(s.y+s.h)}))(0<i.length?{minX:i[0].x,minY:i[0].y,maxX:i[0].x+i[0].w,maxY:i[0].y+i[0].h}:{minX:0,minY:0,maxX:0,maxY:0})(Lt(1,i.length,i));return{x:o.minX,y:o.minY,w:o.maxX-o.minX,h:o.maxY-o.minY}})(),priority:0,pathFollow:J})}),$h=t=>e=>n=>{const r=Ei(n)(t);if(r.tag==="Nothing")return Mc;if(r.tag==="Just"){const i=qc(r._1.target)(e);return qc(r._1.source)(e)?i?Gh:Sh:Mc}g()},qh={pre:0,post:0},Xh=t=>e=>n=>r=>i=>{const o=Xc(i.event.id)(n),u=(()=>{if(o.tag==="Nothing")return qh;if(o.tag==="Just")return o._1;g()})(),s=(()=>{if(i.event.when.tag==="First")return 0;if(i.event.when.tag==="At")return i.event.when._1;if(i.event.when.tag==="After"){const c=i.event.when._1,f=Kt(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.endT;g()}if(i.event.when.tag==="With"){const c=i.event.when._1,f=Kt(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.startT}g()})(),a=(()=>{if(i.event.kind.tag==="SendToken")return zh(t)(e)(u)(i.event.kind._1);if(i.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return Rt(r)({startT:s,endT:s+a.duration,event:i.event,holdPre:a.holdPre,holdPost:a.holdPost})},Uc=t=>e=>n=>T(Xh(t)(e)(Hh(t)(n)))([])(Bt(r=>i=>({event:i}))(n)),Vh=t=>e=>{const n=Ci(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},Uh=t=>e=>({...e,fromCam:as(t)(e.fromCam),toCam:as(t)(e.toCam)}),Kh=t=>{if(t.when.tag==="First")return[];if(t.when.tag==="At")return[];if(t.when.tag==="After")return[t.when._1];if(t.when.tag==="With")return[t.when._1];g()},Kc={id:"",nodes:A,edges:A,kind:yi},Zh=t=>e=>Hl((()=>{const n=Ar(e.from)(t);if(n.tag==="Nothing")return Kc;if(n.tag==="Just")return n._1;g()})())((()=>{const n=Ar(e.to)(t);if(n.tag==="Nothing")return Kc;if(n.tag==="Just")return n._1;g()})()),jh=t=>e=>{const n=Ci(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:A};if(n.tag==="Just")return n._1;g()},ps=t=>e=>n=>r=>{const i=Ei(r)(n.edges);if(i.tag==="Just")return t<=0?e:Nn(e)(pi(i._1)/t);if(i.tag==="Nothing")return e;g()},Zc=t=>e=>n=>r=>i=>{const o=t.plop,u=Zh(n)(i),s=O(_=>({startT:0,endT:0+ps(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Ir("EdgeWindow",_,ds("Extend",Hc))}))(Fr(u.entering.edges)),a=O(_=>({startT:0,endT:o,target:Ir("NodeWindow",_,Vc)}))(Fr(u.entering.nodes)),c=T(Nn)(0)(O(_=>ps(t.edgeSpeed)(t.minEdgeDuration)(e)(_))(Fr(u.leaving.edges))),f=_=>Oe(h=>{const p=Ei(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;g()},Fr(u.leaving.edges))?c:0,d=O(_=>({startT:f(_),endT:f(_)+t.plop,target:Ir("NodeWindow",_,Qh)}))(Fr(u.leaving.nodes)),l=O(_=>({startT:0,endT:ps(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Ir("EdgeWindow",_,ds("Retract",$h(r)(u.leaving.nodes)(_)))}))(Fr(u.leaving.edges));return{duration:(()=>{const _=Et(it.compare)([...O(p=>p.endT)(l),...O(p=>p.endT)(d),...O(p=>p.endT)(a),...O(p=>p.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+t.gap:t.gap})(),windows:[...l,...d,...a,...s]}},t0=t=>e=>n=>r=>i=>o=>O((()=>{const u=i.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())(Zc(t)(e)(n)(r)(o).windows),e0=t=>xt(e=>Ct(ii,e).length>1?w("Just",(()=>{const n=Qt(r=>J,r=>i=>w("Just",{head:r,tail:i}),Ct(ii,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):J)(_d(oi)(Et(S.compare)(t))),n0=t=>{const e=O(r=>r.id)(t),n=Ih(e);return[...O(Fh)(e0(e)),...O(Bh)(at(r=>!hs(r)(n),wt(t)(Kh)))]},r0=t=>e=>n=>{const r=Nn(t.minZoom)(t.tokenZoomFloor);return xt(i=>{if(i.target.tag==="NodeWindow"||i.target.tag==="EdgeWindow")return J;if(i.target.tag==="TokenWindow")return w("Just",(()=>{const o={pre:i.target._7,post:i.target._8};if(t.tokenZoomFloor<=0)return{startT:i.startT,endT:i.endT,bbox:Ji(e)(n)(i.target._2),priority:1,pathFollow:J};const u=Ei(i.target._2)(e.edges);if(u.tag==="Just"){const s=Ci(i.target._4)(e.nodes);if(s.tag==="Just"){const a=Ci(i.target._5)(e.nodes);if(a.tag==="Just"){const c=a._1;return{startT:i.startT,endT:i.endT,bbox:Ji(e)(n)(i.target._2),priority:1,pathFollow:w("Just",{samples:(()=>{const f=i.startT+o.pre*(i.endT-i.startT),d=Nn(1e-4)(i.endT-o.post*(i.endT-i.startT)-f),l=i.endT-i.startT;return O(_=>{const h=f+et(_)/et(32)*d;return{t:h,pos:Gl(u._1)({x:s._1.x+s._1.w/2,y:s._1.y+s._1.h/2})({x:c.x+c.w/2,y:c.y+c.h/2})(l<=0?0:(h-i.startT)/l)(o)}})(Ft(0,32))})(),zoom:r})}}if(a.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:Ji(e)(n)(i.target._2),priority:1,pathFollow:J};g()}if(s.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:Ji(e)(n)(i.target._2),priority:1,pathFollow:J};g()}if(u.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:Ji(e)(n)(i.target._2),priority:1,pathFollow:J};g()})());if(i.target.tag==="FillWindow")return w("Just",{startT:i.startT,endT:i.endT,bbox:Cc(e)(n)(Yt("Node",1,1,i.target._2,void 0,A,A)),priority:1,pathFollow:J});g()})},i0=t=>e=>n=>r=>i=>hh(t)(i.layout)(r.endT)([...Yh(i.layout)(n)(e)(at(o=>o.startT>=i.startT&&o.endT<=i.endT,r.spans)),...r0(t)(i.layout)(n)(i.windows)]),o0=t=>{const e=$c(O(r=>b(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];g()})()))(t)),n=r=>i=>o=>{if(hs(o)(i))return[rr("ScheduleCycle",[...Ct(Qe.foldr,i),o])];if(hs(o)(r))return[];const u=Xc(o)(e);if(u.tag==="Nothing")return[];if(u.tag==="Just")return wt(u._1)(n(tt(S)(o)()(r))(tt(S)(o)()(i)));g()};return wt(t)(r=>n(A)(A)(r.id))},u0={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:.5,stillHold:1.8,hatchHold:.4,tokenReadSecPerChar:.06,nodeEasing:eh,edgeEasing:th,tokenEasing:Ti,diveDur:1.2,retreatDur:1.2},s0=t=>e=>n=>r=>O((()=>{const i=n.startT;return o=>({...o,startT:o.startT+i,endT:o.endT+i})})())(xt(Wh)(Uc(t)(e)(r.events))),a0=t=>e=>n=>r=>i=>{if(i.scene.tag==="Structural")return t0(t)(e)(n)(r)(i)(i.scene._1);if(i.scene.tag==="Hold")return[];if(i.scene.tag==="DataFlow")return s0(t)(e)(i)(i.scene._1);if(i.scene.tag==="EnterNode")return[];if(i.scene.tag==="ExitNode")return[];g()},c0=t=>e=>n=>{const r=Uc(t)(e)(n.events);return r.length===0?t.gap:T(Nn)(0)(O(i=>i.endT)(r))+t.gap},g0=t=>e=>n=>r=>i=>{if(i.tag==="Structural")return Zc(t)(e)(n)(r)(i._1).duration;if(i.tag==="Hold")return t.stillHold;if(i.tag==="DataFlow")return c0(t)(e)(i._1);if(i.tag==="EnterNode"||i.tag==="ExitNode")return 0;g()},jc=t=>e=>n=>r=>i=>o=>{const u=Il(e)(r),s=n.layout,a=kc(O(p=>b(p.id,p))(i.keyframes)),c=0<i.keyframes.length?w("Just",i.keyframes[0]):J,f=(()=>{if(c.tag==="Just")return c._1.id;if(c.tag==="Nothing")return"";g()})(),d=Zl(i),l=p=>({segments:p.runSpans.length===0?p.segments:Rt(p.segments)({startT:p.runStart,endT:p.t,path:r,layout:s,placement:u,windows:p.runWindows,spans:p.runSpans,keyframes:a,initialKeyframe:f,edgeEndpoints:d}),spans:p.spans,windows:p.windows,dives:p.dives}),_=T(p=>m=>{if(m.tag==="EnterNode"){const v=l(p),k=p.t+t.diveDur,L=Rt(r)(m._1),E=jc(t)(e)(jh(n)(m._1))(L)(Vh(i)(m._1))(k),B=E.endT+t.retreatDur;return{...p,t:B,runStart:B,runSpans:[],runWindows:[],segments:[...v.segments,...E.segments],spans:[...v.spans,...E.spans],windows:[...v.windows,...E.windows],dives:[...v.dives,{startT:p.t,endT:k,node:m._1,parentPath:r,childPath:L,direction:Rh},...E.dives,{startT:E.endT,endT:B,node:m._1,parentPath:r,childPath:L,direction:Mh}]}}if(m.tag==="ExitNode")return p;const y=p.t+g0(t)(s)(a)(d)(m),x={startT:p.t,endT:y,scene:m},N=a0(t)(s)(a)(d)(x);return{...p,t:y,runSpans:Rt(p.runSpans)(x),runWindows:[...p.runWindows,...N],spans:Rt(p.spans)(x),windows:[...p.windows,...N]}})({t:o,runStart:o,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(i.scenes),h=l(_);return{endT:_.t,spans:h.spans,windows:Et(p=>m=>it.compare(p.startT)(m.startT))(h.windows),segments:h.segments,dives:h.dives}},f0=t=>e=>n=>n.endT<=t||n.startT>=e?J:w("Just",{...n,startT:Nn(t)(n.startT),endT:So(e)(n.endT)}),ms=t=>e=>n=>{const r=qe(n.layout),i={x:r.x*n.placement.scale+n.placement.tx,y:r.y*n.placement.scale+n.placement.ty,w:r.w*n.placement.scale,h:r.h*n.placement.scale},o=40/(11*n.placement.scale),u=cs(e)(i)(t.padding*n.placement.scale);return{center:{x:i.x+i.w/2,y:i.y+i.h/2},zoom:(()=>{if(n.layout.nodes.tag==="Leaf")return!0;if(n.layout.nodes.tag==="Node")return n.layout.nodes._2<=1;g()})()?So(u)(o):u}},_0=t=>e=>n=>n.placement.scale===1&&n.placement.tx===0&&n.placement.ty===0?as(n.placement)(Li(t)(n.layout)(qe(n.layout))(0)):ms(t)(e)(n),d0=t=>e=>n=>r=>xt(i=>{const o=Oh(r)(i.parentPath)(i.startT)(i.endT);if(o.tag==="Just"){const u=i.childPath,s=Kt(a=>ls(a.path)(u))(r.segments);if(s.tag==="Just"){const a=_0(t)(e)(o._1),c=ms(t)(e)(s._1);if(i.direction==="DiveIn")return w("Just",{startT:i.startT,endT:i.endT,fromCam:a,toCam:c,easing:Jo,interp:Dc});if(i.direction==="DiveOut")return w("Just",{startT:i.startT,endT:i.endT,fromCam:c,toCam:a,easing:Jo,interp:Dc});g()}if(s.tag==="Nothing")return J;g()}if(o.tag==="Nothing")return J;g()})(r.dives),l0=t=>e=>{if(e.tag==="Structural")return xt(n=>n)([Go(e._1.from)(t)?J:w("Just",rr("UnknownKeyframe",e._1.from)),Go(e._1.to)(t)?J:w("Just",rr("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return xt(n=>n)([Go(e._1)(t)?J:w("Just",rr("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...xt(n=>n)([Go(e._1.keyframe)(t)?J:w("Just",rr("UnknownKeyframe",e._1.keyframe))]),...n0(e._1.events),...o0(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()},h0=t=>e=>{const n=wt(e)(l0(t));return n.length===0?Dt("Right",void 0):Dt("Left",n)},p0=t=>e=>n=>r=>Et(i=>o=>it.compare(i.startT)(o.startT))(wt(r.segments)(i=>i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0?xt(f0(i.startT)(i.endT))(O(Uh(i.placement))(i0(t)(n)(i.edgeEndpoints)(r)(i))):[(()=>{const o=ms(t)(e)(i);return{startT:i.startT,endT:i.endT,fromCam:o,toCam:o,easing:Ti,interp:ki}})()])),m0=t=>e=>n=>r=>{if(0<n.keyframes.length){const i=n.keyframes[0],o=kc(O(s=>b(s.id,s))(n.keyframes)),u=h0(o)(n.scenes);return(()=>{if(u.tag==="Left"){const s=u._1;return a=>Dt("Left",s)}if(u.tag==="Right"){const s=u._1;return a=>a(s)}g()})()(()=>{const s=jc(e)(r)(r)([])(n)(0);return Dt("Right",{totalDuration:s.endT,windows:s.windows,spans:s.spans,keyframes:o,initialKeyframe:i.id,timing:e,layout:r.layout,cameraSpans:[...d0(t)(r.layout)(o)(s),...p0(t)(r.layout)(o)(s)],cameraConfig:t,levelTree:r,segments:s.segments,dives:s.dives,seed:n.seed})})}return Dt("Left",[Ah])},ys=t=>t,tg=te(S)(zt),hn=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Si={eq:Au(oi)},xs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},eg=zt.foldMap(gl(S)),Ns=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},y0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},x0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},N0=(()=>{const t=Ue.unfoldr(xn);return e=>t(Ke("IterNode",e,yn))})(),Br=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},J0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},T0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},w0=te(S)(zt),v0=te(S)(zt),ng=ys("Backdrop"),b0=ys("FlyThrough"),Po=ys("Active"),k0=t=>e=>n=>({...n,state:{...n.state,edgeFadeAlpha:tg(O(r=>b(r,e))(t))}}),rg=t=>e=>n=>{const r=(t+e)/2,i=n-r,o=i<0?-1:1,u=(e-t)/2,s=u*.15,a=u-s,c=i<0?-i:i;return e<=t?(t+e)/2:c<=a?n:r+o*(u-s*oo(-(c-a)/s))},L0=t=>e=>n=>r=>{const i=qe(t),o=i.w/hn(1e-4)(e.zoom)/2,u=i.h/hn(1e-4)(e.zoom)/2,s=n.y-e.center.y,a=n.x-e.center.x;return{...e,center:{x:o<=1e-4?e.center.x+0*r*.35:a<0?e.center.x+a/(1+-a/o)*r*.35:e.center.x+a/(1+a/o)*r*.35,y:u<=1e-4?e.center.y+0*r*.35:s<0?e.center.y+s/(1+-s/u)*r*.35:e.center.y+s/(1+s/u)*r*.35}}},Do=t=>e=>n=>{const r=Kt(i=>Si.eq(i.path)(e)&&n>=i.startT&&n<i.endT)(t.segments);if(r.tag==="Just")return w("Just",r._1);if(r.tag==="Nothing")return Kt(i=>Si.eq(i.path)(e))(t.segments);g()},E0=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:rs,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:A}),C0=t=>O(e=>e<1?[]:Lt(0,e,t))(Ft(0,t.length-1|0)),Js=t=>e=>{const n=xs(e)(t.keyframes);if(n.tag==="Nothing")return A;if(n.tag==="Just")return n._1.nodes;g()},Ts=t=>e=>{const n=xs(e)(t.keyframes);if(n.tag==="Nothing")return A;if(n.tag==="Just")return n._1.edges;g()},Io=t=>e=>{if(e<t.startT)return xr("AtKeyframe",t.initialKeyframe);const n=Kt(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return xr("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return xr("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return xr("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return xr("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;return r>=0&&r<t.spans.length?xr("AtKeyframe",(()=>{if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="Hold")return t.spans[r].scene._1;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return t.initialKeyframe;g()})()):xr("AtKeyframe",t.initialKeyframe)}g()},S0=T(t=>e=>{const n=fr(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?Rt(n._1.init)({...n._1.last,endT:hn(n._1.last.endT)(e.endT),windows:Rt(n._1.last.windows)(e)}):Rt(t)({endT:e.endT,windows:[e]})})([]),G0=t=>e=>n=>eg(r=>eg(i=>i.target.tag==="FillWindow"?i.startT<=n?Yt("Node",1,1,i.target._2,void 0,A,A):A:i.target.tag==="TokenWindow"&&i.startT+(i.endT-i.startT)*.25<=n?Yt("Node",1,1,i.target._4,void 0,A,A):A)(r.windows))(at(r=>n<=r.endT+t,S0(Et(r=>i=>it.compare(r.startT)(i.startT))(at(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),P0=t=>e=>n=>Oe(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),D0=t=>e=>n=>Oe(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),I0=t=>e=>n=>Oe(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),A0=t=>e=>n=>Oe(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),F0=t=>e=>{const n=Io(t)(e);if(n.tag==="AtKeyframe")return ye(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return ye(3)(n._2)==="kf-"?"":n._2;g()},B0=t=>e=>{const n=Io(t)(e),r=xs((()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;g()})())(t.keyframes);if(r.tag==="Just")return r._1.kind;if(r.tag==="Nothing")return yi;g()},ig=t=>e=>n=>Kt(r=>n(r)&&e>=r.startT&&e<r.endT)(t),Q0=t=>{const e=Ns(0)(1)(t/.2),n=Ns(0)(1)((1-t)/.2);return e*e*(3-2*e)*n*n*(3-2*n)},R0=t=>e=>{if(e.tag==="Travelling"){const n=y0(e._1.edge)(t.edges);if(n.tag==="Just"){const r=yr(n._1)(e._1.progress);return r.tag==="Just"?w("Just",{dot:r._1,weight:Q0(e._1.progress)}):J}if(n.tag==="Nothing")return J;g()}return J},M0={segment:{startT:0,endT:0,path:[],layout:{nodes:A,edges:A,chipExtras:A,edgeLabels:A},placement:rs,windows:[],spans:[],keyframes:A,initialKeyframe:"",edgeEndpoints:A},state:{nodes:A,edges:A,tokens:A,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:yi,visited:A,nodeFadeAlpha:A,nodeLabelFadeAlpha:A,edgeFadeAlpha:A,nodeInvert:A},bgAlpha:1,blur:0,minis:[],role:Po},Ao=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:M0},z0=t=>e=>{const n=x0(e)(t.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1,i=o=>o.x>=r.x-1&&o.x<=r.x+r.w+1&&o.y>=r.y-1&&o.y<=r.y+r.h+1;return xt(o=>(()=>{if(0<o._2.length){const s=o._2.length-1|0;return i(o._2[0])||s>=0&&s<o._2.length&&i(o._2[s])}const u=o._2.length-1|0;return u>=0&&u<o._2.length&&i(o._2[u])})()?w("Just",o._1):J)(N0(t.edges))}g()},H0=t=>e=>{const n=Io(t)(e);if(n.tag==="AtKeyframe")return Js(t)(n._1);if(n.tag==="InTransition")return Se(S.compare,Ee,Js(t)(n._1),Js(t)(n._2));g()},W0=t=>e=>{const n=Io(t)(e);if(n.tag==="AtKeyframe")return Ts(t)(n._1);if(n.tag==="InTransition")return Se(S.compare,Ee,Ts(t)(n._1),Ts(t)(n._2));g()},O0=t=>e=>{const n=t.w/hn(1e-4)(e.zoom),r=t.h/hn(1e-4)(e.zoom);return{...e,center:{x:n>=t.w?t.x+t.w/2:rg(t.x+n/2)(t.x+t.w-n/2)(e.center.x),y:r>=t.h?t.y+t.h/2:rg(t.y+r/2)(t.y+t.h-r/2)(e.center.y)}}},Y0=t=>O0((()=>{const e=qe(t.layout),n=e.x*t.placement.scale+t.placement.tx,r=e.y*t.placement.scale+t.placement.ty;return{x:n,y:r,w:(e.x+e.w)*t.placement.scale+t.placement.tx-n,h:(e.y+e.h)*t.placement.scale+t.placement.ty-r}})()),$0=t=>e=>{const n=t.endT-t.startT;return n<=0?1:hn(0)(Br(1)((e-t.startT)/n))},Fo=t=>e=>{const n=t.endT-t.startT;return n<=0?1:hn(0)(Br(1)((e-t.startT)/n))},q0=t=>e=>n=>r=>i=>{const o=ig(e)(n)(u=>u.target.tag==="EdgeWindow"&&u.target._1===i);if(o.tag==="Just"){const u=vi(t.timing.edgeEasing)(Fo(o._1)(n)),s=o._1.target.tag==="EdgeWindow"?o._1.target._2:ds("Extend",Hc);if(s.tag==="Retract")return Lo("Retracting",s._1,u);if(s.tag==="Extend")return Lo("Extending",s._1,u);g()}if(o.tag==="Nothing")return A0(e)(n)(i)||P0(e)(n)(i)?Wc:J0(i)(r)?Dh:Wc;g()},X0=t=>e=>n=>{const r=W0(e)(n);return tg(O(i=>b(i,q0(t)(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return A;if(o.tag==="Node")return Yt("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return Ct(Qe.foldr,i(e.layout.edges))})()))},V0=t=>e=>n=>r=>{const i=ig(t)(e)(o=>o.target.tag==="NodeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=Fo(i._1)(e),u=i._1.target.tag==="NodeWindow"?i._1.target._2:Vc;if(u==="PlopIn")return Eo("PloppingIn",o);if(u==="PlopOut")return Eo("PloppingOut",o);g()}if(i.tag==="Nothing")return I0(t)(e)(r)||D0(t)(e)(r)?zc:T0(r)(n)?Ph:zc;g()},U0=t=>e=>n=>{const r=H0(e)(n);return w0(O(i=>b(i,V0(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return A;if(o.tag==="Node")return Yt("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return Ct(Qe.foldr,i(e.layout.nodes))})()))},K0=t=>e=>n=>e.target.tag==="TokenWindow"?b(e.target._1,n<e.startT?_s:n>=e.endT?Rc:Co("Travelling",{edge:e.target._2,direction:e.target._3,progress:vi(t.timing.tokenEasing)(Fo(e)(n)),labels:e.target._6,source:e.target._4,target:e.target._5,holdPre:e.target._7,holdPost:e.target._8})):e.target.tag==="FillWindow"?b(e.target._1,n<e.startT?_s:n>=e.endT?Rc:Co("Filling",{node:e.target._2,progress:Fo(e)(n),labels:e.target._3})):b("",_s),Z0=t=>e=>n=>v0(O(r=>K0(t)(r)(n))(at(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),j0=t=>e=>n=>({nodes:U0()(e)(n),edges:X0(t)(e)(n),tokens:Z0(t)(e.windows)(n),camera:Ac(t.cameraConfig)(e.layout)(t.cameraSpans)(n),frameTitle:F0(e)(n),staticKind:B0(e)(n),visited:G0(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:A,nodeLabelFadeAlpha:A,edgeFadeAlpha:A,nodeInvert:A}),Qr=t=>e=>n=>r=>({segment:n,state:j0(t)(n)(e),bgAlpha:1,blur:0,minis:tp(t)(e)(n),role:r}),tp=t=>e=>n=>xt(r=>{const i=Do(t)(Rt(n.path)(r))(e);if(i.tag==="Just")return w("Just",{...Qr(t)(Ns(i._1.startT)(i._1.endT-1e-4)(e))(i._1)(ng),bgAlpha:0});if(i.tag==="Nothing")return J;g()})((()=>{const r=i=>{if(i.tag==="Leaf")return A;if(i.tag==="Node")return Yt("Node",i._1,i._2,i._3,void 0,r(i._5),r(i._6));g()};return Ct(Qe.foldr,r(n.layout.nodes))})()),ep=t=>e=>n=>Va(J,Ha,r=>r.direction==="DiveIn"&&Si.eq(r.parentPath)(e.path)&&n>=r.startT-.7&&n<r.startT?w("Just",{node:r.node,phase:(n-(r.startT-.7))/.7}):J,t.dives),np=t=>e=>n=>r=>{const i=ep(t)(e)(n);if(i.tag==="Just"){const o=Ve(3.141592653589793*i._1.phase*3);return{...r,state:{...r.state,nodeInvert:Yt("Node",1,1,i._1.node,1*o*o,A,A)}}}if(i.tag==="Nothing")return r;g()},og=t=>e=>xt(n=>{const r=Kt(i=>i.direction==="DiveIn"&&Si.eq(i.childPath)((()=>{const o=n.length+1|0;return o<1?[]:Lt(0,o,e)})()))(t.dives);if(r.tag==="Just"){const i=Do(t)(n)(r._1.startT-1e-4);if(i.tag==="Just")return w("Just",(()=>{const o=Qr(t)(r._1.startT-1e-4)(i._1)(ng);return{...o,state:{...o.state,nodeFadeAlpha:Yt("Node",1,1,r._1.node,0,A,A)}}})());if(i.tag==="Nothing")return J;g()}if(r.tag==="Nothing")return J;g()})(C0(e)),ug=t=>e=>{const n=at(i=>e>=i.startT&&e<i.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:E0(t)},rp=t=>e=>n=>{const r=$0(n)(e),i=Do(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),o=Do(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),u=(()=>{if(n.direction==="DiveIn")return vi(Jo)(r);if(n.direction==="DiveOut")return 1-vi(Jo)(r);g()})(),s=1-hn(0)(Br(1)((u-.55)/.3)),a=1-hn(0)(Br(1)((u-.1)/.25)),c=1-hn(0)(Br(1)((u-.8)/.2)),f=l=>{const _=Qr(t)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})())(l)(b0);return{...k0(z0(l.layout)(n.node))(a)({..._,state:{..._.state,nodeFadeAlpha:Yt("Node",1,1,n.node,s,A,A),nodeLabelFadeAlpha:Yt("Node",1,1,n.node,a,A,A)}}),minis:at(h=>!Si.eq(h.segment.path)(n.childPath),_.minis),bgAlpha:c}},d=0+1*hn(0)(Br(1)((u-.1)/.5));return[...og(t)(n.parentPath),...(()=>{if(i.tag==="Just"){if(o.tag==="Just")return[f(i._1),{...Qr(t)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})())(o._1)(Po),bgAlpha:d}];if(o.tag==="Nothing")return[f(i._1)];g()}if(i.tag==="Nothing")return[Qr(t)(e)(ug(t)(e))(Po)];g()})()]},ip=t=>e=>{const n=xt(R0(t))((()=>{const r=(i,o)=>{if(i.tag==="Leaf")return o;if(i.tag==="Node")return r(i._5,$t("Cons",i._4,r(i._6,o)));g()};return Ct(Vt.foldr,r(e.tokens,Xt))})());return 0<n.length?w("Just",n[0]):J},op=t=>e=>{const n=ip(t)(e);if(n.tag==="Nothing")return e.camera;if(n.tag==="Just")return L0(t)(e.camera)(n._1.dot)(n._1.weight);g()},up=t=>e=>t.placement.scale===1&&t.placement.tx===0&&t.placement.ty===0?op(t.layout)(e):e.camera,sp=t=>e=>Kt(n=>e>=n.startT&&e<n.endT)(t.dives),ap=t=>e=>{const n=ug(t)(e),r=Qr(t)(e)(n)(Po),i=t.dives.length!==0,o=Ac(t.cameraConfig)(t.layout)(t.cameraSpans)(e),u=Y0(n)(up(n)({...r.state,camera:o})),s=np(t)(n)(e)({...r,state:{...r.state,camera:u}}),a=og(t)(n.path),c=sp(t)(e);if(c.tag==="Just")return{levels:rp(t)(e)(c._1),camera:o,rootLayout:t.layout,hasDives:i,diving:!0};if(c.tag==="Nothing")return{levels:Rt(a)(s),camera:u,rootLayout:t.layout,hasDives:i,diving:!1};g()},sg=t=>t,ag=sg("RunText"),cp=sg("RunCode"),cg=t=>e=>n=>e.length===0?n:Rt(n)({style:t,text:lr(e)}),gp=t=>({style:(()=>{if(t.style==="RunText")return cp;if(t.style==="RunCode")return ag;g()})(),buf:[],runs:cg(t.style)(t.buf)(t.runs)}),fp=t=>e=>0<e.length?{...t,buf:Rt(t.buf)(e[0])}:{...t,buf:Rt(t.buf)("\\")},_p=t=>e=>{let n=t,r=e,i=!0,o;for(;i;){const u=n,s=Qt(a=>J,a=>c=>w("Just",{head:a,tail:c}),r);if(s.tag==="Nothing"){i=!1,o=u;continue}if(s.tag==="Just"){if(s._1.head==="\\"){n=fp(u)(s._1.tail),r=Lt(1,s._1.tail.length,s._1.tail);continue}if(s._1.head==="`"){n=gp(u),r=s._1.tail;continue}n={...u,buf:Rt(u.buf)(s._1.head)},r=s._1.tail;continue}g()}return o},gg=t=>{const e=_p({style:ag,buf:[],runs:[]})(hr(t));return cg(e.style)(e.buf)(e.runs)};let ws=null;function dp(){return ws||(typeof document>"u"?null:(ws=document.createElement("canvas").getContext("2d"),ws))}const fg=new Map,lp=t=>e=>n=>r=>()=>{const i=`${n} ${e}px ${t}|${r}`,o=fg.get(i);if(o!==void 0)return o;const u=dp();if(!u)return r.length*e*.62;u.font=`${n} ${e}px ${t}`;const s=u.measureText(r).width;return fg.set(i,s),s},hp=cr.traverse(Pu),pp=T(Gr)(0),Rr=(()=>{const t=nr(`\r
3
+ `)(" "),e=nr(`
4
+ `)(" "),n=(()=>{const r=nr("\r")(" "),i=(()=>{const o=nr(" ")(" ");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),_g=t=>e=>{const n=hp(r=>{const i=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;g()})();return lp(i.family)(i.size)(i.weight)(Rr(r.text))})(gg(Rr(e)));return()=>{const r=n();return pp(r)}},dg={text:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:"500"},code:{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:"400"}},mp=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Mr=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},yp=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},xp=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Np=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},lg=t=>lr(we(_r(e=>e===" ")(we(_r(e=>e===" ")(hr(t)).rest)).rest)),Jp=t=>T(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?w("Just",n._1):e)(J)(Bt(Pn)(t)),vs=t=>e=>{if(t<=0)return[e];if(jn(e)<=t)return[e];const n=hr(e),r=t<1?[]:Lt(0,t,n),i=Jp(r);if(i.tag==="Just"){const o=lg(hc(!(i._1>=0&&i._1<r.length)||r[i._1]===" "?i._1:i._1+1|0)(e)),u=lg(li(i._1+1|0)(e));return u===""?[o]:[o,...vs(t)(u)]}if(i.tag==="Nothing"){const o=hc(t)(e),u=li(t)(e);return u===""?[o]:[o,...vs(t)(u)]}g()},Tp={cellW:7,cellH:3,maxLineWidth:20},wp=t=>e=>{const n=O(o=>b((()=>{if(o.label.tag==="Just")return o.label._1;if(o.label.tag==="Nothing")return o.id;g()})(),o))(e.nodes),r=Mr(1)(Gn((yp(t.maxLineWidth)(T(o=>u=>Mr(o)(jn(u._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),i=(r*t.cellW|0)-1|0;return{...e,nodes:O(o=>{if(!(o._2.size._1===1&&o._2.size._2===1))return o._2;const u=wt(wo(`
5
+ `)(o._1))(vs(i)),s=T(c=>f=>Mr(c)(jn(f)))(0)(u),a=o._2.shape==="Cylinder"?Mr(1)(Gn((s+2|0)+t.cellW|0,t.cellW)):r;return{...o._2,size:b(et(s>i?Gn((s+2|0)+t.cellW|0,t.cellW):a),et(Mr(1)(Gn(u.length+t.cellH|0,t.cellH))+(o._2.shape==="Cylinder"||o._2.shape==="Document"?1:0)|0))}})(n)}},vp=t=>e=>n=>({...n,nodes:O(r=>{const i=Np(r.id)(e);if(i.tag==="Nothing")return r;if(i.tag==="Just")return{...r,size:b(xp(r.size._1)(et(Mr(1)(ce(io(r.shape==="Cylinder"?(i._1+0)/t:(i._1+32)/t))))),r.size._2)};g()})(n.nodes)}),bp=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},kp=t=>{const e=t.length;return(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(a>=e){u=!1,s=c;continue}const f=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const y=_,x=h;if(y>=e){p=!1,m=x;continue}if(a>=0&&a<t.length){if(y>=0&&y<t.length){_=y+1|0,h=(()=>{const N=t[a].position,v=t[a].size,k=t[y].position,L=t[y].size;return N._1<k._1+L._1&&k._1<N._1+v._1&&N._2<k._2+L._2&&k._2<N._2+v._2})()?x+1|0:x;continue}_=y+1|0,h=x;continue}p=!1,m=x}return m};i=a+1|0,o=f(a+1|0)(c)}return s})(0)(0)},hg=t=>T(e=>n=>e+wl(n.start)(n.end))(0)(t.segments),Lp=t=>e=>n=>({crossingCount:T(r=>i=>r+i.jumps.length|0)(0)(e),bendCount:T(r=>i=>r+i.bends.length|0)(0)(e),totalEdgeLength:T(r=>i=>r+hg(i))(0)(e),maxEdgeLength:T(r=>i=>bp(r)(hg(i)))(0)(e),nodeOverlapCount:kp(t),constraintViolations:n,jumpCount:T(r=>i=>r+i.jumps.length|0)(0)(e)}),bs=t=>t,Zt=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},ks=bs("LEFT"),Ep=bs("RIGHT"),pg=bs("UNDEFINED"),Cp={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},Sp={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?De:Je;if(e==="LEFT")return Te;if(t==="RIGHT")return e==="RIGHT"?De:Je;if(e==="RIGHT")return Te;if(t==="UP")return e==="UP"?De:Je;if(e==="UP")return Te;if(t==="DOWN")return e==="DOWN"?De:Je;if(e==="DOWN")return Te;if(t==="UNDEFINED"&&e==="UNDEFINED")return De;g()},Eq0:()=>Cp},Gp=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){if(t==="LEFT"){if(o._3==="LEFT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="LEFT"){n=o._6;continue}if(t==="RIGHT"){if(o._3==="RIGHT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="RIGHT"){n=o._6;continue}if(t==="UP"){if(o._3==="UP"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="UP"){n=o._6;continue}if(t==="DOWN"){if(o._3==="DOWN"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="DOWN"){n=o._6;continue}if(t==="UNDEFINED"&&o._3==="UNDEFINED"){r=!1,i=!0;continue}}g()}return i},Pp={x:0,y:0},Ze=t=>e=>n=>{const r=Zt(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:tt(nt)(t)(e(r._1))(n.cNodes)};g()},Gi=t=>e=>n=>{const r=Zt(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:tt(nt)(t)(e(r._1))(n.cGroups)};g()},Dp=t=>T(e=>n=>Ze(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),Ip=t=>{const e=T(n=>r=>{const i=Zt(r)(t.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just")return T(o=>u=>bt(nt)(re)(u)([r])(o))(n)(i._1.constraints);g()})(A)(t.cNodeOrder);return T(n=>r=>Ze(r)(i=>({...i,constraints:(()=>{const o=Zt(r)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})()}))(n))(t)(t.cNodeOrder)},Ap=t=>e=>Ze(t)(n=>({...n,ignoreSpacing:{left:n.ignoreSpacing.left||e.left,right:n.ignoreSpacing.right||e.right,up:n.ignoreSpacing.up||e.up,down:n.ignoreSpacing.down||e.down}})),Fp=t=>{const e=T(n=>r=>Gi(r)(i=>({...i,outDegree:i.outDegreeReal}))(n))(t)(t.cGroupOrder);return T(n=>r=>Ze(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder)},cn={left:!1,right:!1,up:!1,down:!1},Bp={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},Ls=t=>T(e=>n=>{const r=Zt(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const i=T(u=>s=>{const a=Zt(s)(e.cNodes);if(a.tag==="Nothing")return u;if(a.tag==="Just"){if(u.tag==="Nothing")return w("Just",s);if(u.tag==="Just"){const c=Zt(u._1)(e.cNodes);if(c.tag==="Nothing")return w("Just",s);if(c.tag==="Just")return a._1.hitbox.x<c._1.hitbox.x?w("Just",s):w("Just",u._1)}}g()})(J)(r._1.cNodes),o=Gi(n)(u=>({...u,reference:i}))(e);if(i.tag==="Nothing")return o;if(i.tag==="Just"){const u=Zt(i._1)(o.cNodes);if(u.tag==="Nothing")return o;if(u.tag==="Just"){const s=u._1;return T(a=>c=>Ze(c)(f=>({...f,cGroupOffset:{x:f.hitbox.x-s.hitbox.x,y:f.hitbox.y-s.hitbox.y}}))(a))(o)(r._1.cNodes)}}}g()})(t)(t.cGroupOrder),je=t=>Ls({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return A;if(n.tag==="Node")return Yt("Node",n._1,n._2,n._3,{...n._4,hitbox:{...n._4.hitbox,x:-n._4.hitbox.x-n._4.hitbox.width}},e(n._5),e(n._6));g()};return e(t.cNodes)})()}),Jn=t=>Ls({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return A;if(n.tag==="Node")return Yt("Node",n._1,n._2,n._3,{...n._4,hitbox:{x:n._4.hitbox.y,y:n._4.hitbox.x,width:n._4.hitbox.height,height:n._4.hitbox.width},cGroupOffset:{x:n._4.cGroupOffset.y,y:n._4.cGroupOffset.x}},e(n._5),e(n._6));g()};return e(t.cNodes)})()}),mg=t=>{const e=T(n=>r=>Gi(r)(i=>({...i,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return T(n=>r=>{const i=Zt(r)(n.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just"){if(i._1.cGroup.tag==="Nothing")return n;if(i._1.cGroup.tag==="Just"){const o=i._1.cGroup._1;return T(u=>s=>{const a=Zt(s)(u.cNodes);if(a.tag==="Nothing")return u;if(a.tag==="Just")return a._1.cGroup.tag==="Just"&&a._1.cGroup._1!==o?Gi(a._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(Gi(o)(c=>Ye(Er)(s)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,s]})(u)):u;g()})(n)(i._1.constraints)}}g()})(e)(e.cNodeOrder)},Bo=t=>{const e=Ip(t.cGraph);return{...t,cGraph:mg(T(n=>r=>Ze(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},Qp=t=>e=>T(n=>r=>{if(t==="LEFT"||t==="UP"){const o=r._2;return Ze(r._1)(u=>({...u,constraints:[...u.constraints,o]}))(n)}const i=r._1;return Ze(r._2)(o=>({...o,constraints:[...o.constraints,i]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),gn=t=>{const e={...t,cGraph:Qp(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return A;if(r.tag==="Node")return Yt("Node",r._1,r._2,r._3,{...r._4,constraints:[]},n(r._5),n(r._6));g()};return n(t.cGraph.cNodes)})()})};return{...e,cGraph:mg((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);g()})())}},Rp=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?gn(r):e==="RIGHT"?gn({...r,cGraph:je(r.cGraph)}):e==="UP"?gn({...r,cGraph:Jn(r.cGraph)}):e==="DOWN"?gn({...r,cGraph:je(Jn(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?Bo({...r,cGraph:je(r.cGraph)}):e==="UP"?gn({...r,cGraph:Jn(r.cGraph)}):e==="DOWN"?gn({...r,cGraph:je(Jn(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?Bo({...r,cGraph:je(r.cGraph)}):e==="UP"?gn({...r,cGraph:Jn(je(r.cGraph))}):e==="DOWN"?gn({...r,cGraph:je(Jn(je(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?gn({...r,cGraph:Jn(r.cGraph)}):e==="RIGHT"?gn({...r,cGraph:je(Jn(r.cGraph))}):e==="DOWN"?Bo({...r,cGraph:je(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?gn({...r,cGraph:Jn(je(r.cGraph))}):e==="RIGHT"?gn({...r,cGraph:je(Jn(je(r.cGraph)))}):e==="UP"?Bo({...r,cGraph:je(r.cGraph)}):r;g()},yg=t=>e=>e.finished||!Gp(t)(e.cGraph.supportedDirections)||(t==="LEFT"?e.direction==="LEFT":t==="RIGHT"?e.direction==="RIGHT":t==="UP"?e.direction==="UP":t==="DOWN"?e.direction==="DOWN":t==="UNDEFINED"&&e.direction==="UNDEFINED")?e:Rp(e.direction)(t)(e),Mp=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?yg(ks)(t):t,n={...e,cGraph:Fp(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},xg=t=>e=>n=>{const r=Zt(t)(n.cNodes),i=Zt(e)(n.cGroups);return r.tag==="Just"&&i.tag==="Just"?(()=>{if(r._1.cGroup.tag==="Nothing")return!1;if(r._1.cGroup.tag==="Just")return!0;g()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:tt(nt)(t)({...r._1,cGroup:w("Just",e)})(n.cNodes),cGroups:tt(nt)(e)({...i._1,cNodes:Ye(Er)(t)(i._1.cNodes)?i._1.cNodes:[...i._1.cNodes,t],reference:(()=>{if(i._1.reference.tag==="Nothing")return w("Just",t);if(i._1.reference.tag==="Just")return w("Just",i._1.reference._1);g()})()})(n.cGroups)}:n},Ng=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:tt(nt)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:J,cGroupOffset:Pp,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:cn})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),Es=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:T(r=>i=>xg(i)(n)(r))({...e,cGroups:tt(nt)(n)({id:n,master:t.master,cNodes:[],startPos:-1e308,incomingConstraints:[],outDegree:0,outDegreeReal:0,reference:J,delta:0,deltaNormalized:0})(e.cGroups),cGroupOrder:[...e.cGroupOrder,n],nextCGroupId:n+1|0})(t.nodes)}},zp=t=>T(e=>n=>{const r=Zt(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?Es({master:J,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),Hp=t=>({cGraph:Dp(zp(Ls(t))),direction:pg,compactionAlgorithm:J,constraintAlgorithm:J,spacingsHandler:Bp,lockFun:J,finished:!1}),Wp=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Op=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?Je:n==="GT"?Te:nt.compare(t._2)(e._2)},Yp=(()=>{const t=Ue.unfoldr(xn);return e=>t(Ke("IterNode",e,yn))})(),Jg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Tg=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",wg=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),Qo=t=>e=>Op(b(t.hitbox.x+t.hitbox.width/2,t.id))(b(e.hitbox.x+e.hitbox.width/2,e.id)),$p=t=>e=>{const n=gr(Ut,J,r=>Qo(t)(r)==="LT",e);if(n.tag==="Just"){const r=Ka(Ut,J,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return Rt(e)(t);g()},vg=t=>e=>{const n=at(i=>Qo(i)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?w("Just",n[r]):J},qp=t=>e=>{const n=$p(e)(t.intervals),r=Kt(o=>Qo(e)(o)==="LT")(n),i=tt(nt)(e.id)((()=>{const o=vg(e)(n);return o.tag==="Just"?w("Just",o._1.id):J})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return tt(nt)(r._1.id)(w("Just",e.id))(i);if(r.tag==="Nothing")return i;g()})()}},Xp=t=>e=>{const n=it.compare(t.low?t.node.hitbox.y:t.node.hitbox.y+t.node.hitbox.height)(e.low?e.node.hitbox.y:e.node.hitbox.y+e.node.hitbox.height);return n==="EQ"?t.low?t.low&&!e.low?Te:De:e.low?Je:De:n},Vp=t=>T(e=>n=>Ze(n.id)(r=>({...r,constraints:[]}))(e))(t)(xt(e=>Zt(e)(t.cNodes))(t.cNodeOrder)),Cs=t=>e=>T(n=>r=>{const i=Zt(r._1)(n.cNodes);if(i.tag==="Just")return Ze(r._1)(o=>({...o,constraints:[...o.constraints,...r._2]}))(n);if(i.tag==="Nothing")return n;g()})(e)(Yp(t)),bg=t=>e=>e.kind.tag!=="Nothing"&&e.kind.tag==="Just"&&e.kind._1==="vs"?e.ignoreSpacing.up?e.ignoreSpacing.down?e:{...e,hitbox:{...e.hitbox,height:e.hitbox.height+t+.01}}:{...e,hitbox:{...e.hitbox,y:e.hitbox.y-t-.01,height:e.hitbox.height+t+.01}}:{...e,hitbox:{...e.hitbox,y:e.hitbox.y-t,height:e.hitbox.height+2*t}},kg=t=>e=>n=>T(r=>i=>n(i)?Ze(i.id)(bg(t))(r):r)(e)(xt(r=>Zt(r)(e.cNodes))(e.cNodeOrder)),Up=t=>e=>{const n=(r,i,o)=>{const u=Ze(o)(bg(t))(r);return i.length<=1?u:T(s=>a=>a===o?s:Ze(a)(c=>c.ignoreSpacing.up?{...c,hitbox:{...c.hitbox,y:c.hitbox.y+t+.01,height:c.hitbox.height-t-.01}}:c.ignoreSpacing.down?{...c,hitbox:{...c.hitbox,height:c.hitbox.height-t-.01}}:c)(s))(u)(i)};return T(r=>i=>{if(i.master.tag==="Nothing")return 0<i.cNodes.length?n(r,i.cNodes,i.cNodes[0]):r;if(i.master.tag==="Just")return n(r,i.cNodes,i.master._1);g()})(e)(xt(r=>Zt(r)(e.cGroups))(e.cGroupOrder))},Kp=t=>e=>{const n=vg(e)(t.intervals),r=Kt(o=>Qo(e)(o)==="LT")(t.intervals),i=n.tag==="Just"&&(()=>{const o=Jg(e.id)(t.cand);return(o.tag==="Nothing"?!1:o.tag==="Just"&&(o._1.tag==="Nothing"?!1:o._1.tag==="Just"&&o._1._1===n._1.id))&&n._1.cGroup.tag==="Just"&&e.cGroup.tag==="Just"&&n._1.cGroup._1!==e.cGroup._1})()?bt(nt)(re)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const o=Jg(r._1.id)(t.cand);return(o.tag==="Nothing"?!1:o.tag==="Just"&&(o._1.tag==="Nothing"?!1:o._1.tag==="Just"&&o._1._1===e.id))&&e.cGroup.tag==="Just"&&r._1.cGroup.tag==="Just"&&e.cGroup._1!==r._1.cGroup._1})()?bt(nt)(re)(e.id)([r._1.id])(i):i,intervals:at(o=>o.id!==e.id,t.intervals)}},Zp=t=>e=>e.low?qp(t)(e.node):Kp(t)(e.node),Ss=t=>e=>T(Zp)({intervals:[],cand:A,constraints:A})(Et(Xp)(wt(at(t,xt(n=>Zt(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,jp=t=>e=>{const n=Wp(0)(t/2-.5),r=Cs(Ss(Tg)(kg(n)(e)(Tg)))(e),i=Cs(Ss(wg)(kg(n)(r)(wg)))(r);return Cs(Ss(o=>!0)(Up(n)(i)))(i)},tm=t=>e=>jp(t)(Vp(e.cGraph)),Ro=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Lg=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Gs=t=>e=>n=>r=>i=>({id:t,representedEdges:[i],affectedBends:[e,n],hitbox:{x:Ro(e._1)(n._1),y:Ro(e._2)(n._2),width:Vn(e._1-n._1),height:Vn(e._2-n._2)},ignoreSpacing:cn,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:J}),em=t=>e=>{const n=Ro(t.hitbox.x)(e.hitbox.x),r=Ro(t.hitbox.y)(e.hitbox.y);return{...t,representedEdges:[...t.representedEdges,...e.representedEdges],affectedBends:[...t.affectedBends,...e.affectedBends],potentialGroupParents:[...t.potentialGroupParents,...e.potentialGroupParents],hitbox:{x:n,y:r,width:Lg(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Lg(t.hitbox.y+t.hitbox.height)(e.hitbox.y+e.hitbox.height)-r},ignoreSpacing:{left:t.ignoreSpacing.left||e.ignoreSpacing.left,right:t.ignoreSpacing.right||e.ignoreSpacing.right,up:t.ignoreSpacing.up||e.ignoreSpacing.up,down:t.ignoreSpacing.down||e.ignoreSpacing.down},aPort:(()=>{if(t.aPort.tag==="Just")return t.aPort;if(t.aPort.tag==="Nothing")return e.aPort;g()})()}},nm=t=>e=>Vn(t.hitbox.x-e.hitbox.x)<=1e-4&&e.hitbox.y-(t.hitbox.y+t.hitbox.height)<=1e-4&&t.hitbox.y-(e.hitbox.y+e.hitbox.height)<=1e-4,rm=t=>e=>Vn(t.hitbox.x-e.hitbox.x)<=1e-4?it.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?Je:Te,Eg=(t,e)=>({tag:t,_1:e}),Ps=te(S)(zt),Mo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Cg=(()=>{const t={eq:n=>r=>n._1===r._1&&(n._2.tag==="Nothing"?r._2.tag==="Nothing":n._2.tag==="Just"&&r._2.tag==="Just"&&n._2._1===r._2._1)},e={compare:n=>r=>{const i=S.compare(n._1)(r._1);if(i==="LT")return Je;if(i==="GT")return Te;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?De:Je;if(r._2.tag==="Nothing")return Te;if(n._2.tag==="Just"&&r._2.tag==="Just")return S.compare(n._2._1)(r._2._1);g()},Eq0:()=>t};return T(n=>r=>tt(e)(r)()(n))(A)})(),Bn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},im=T(t=>e=>tt(Sp)(e)()(t))(A),Ds=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=xc.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},om=t=>e=>{const n=Ps(O(o=>b(o.id,o))(t)),r=xt(o=>Mo(o)(n))(e),i=nt.compare((()=>{const o=Cg(O(u=>b(u.from.node,u.from.port))(r));if(o.tag==="Leaf")return 0;if(o.tag==="Node")return o._2;g()})())((()=>{const o=Cg(O(u=>b(u.to.node,u.to.port))(r));if(o.tag==="Leaf")return 0;if(o.tag==="Node")return o._2;g()})());if(i==="LT")return{...cn,left:!0,right:!1};if(i==="GT")return{...cn,left:!1,right:!0};if(i==="EQ")return cn;g()},um=t=>xt(e=>{if(e.direction==="V")return w("Just",{start:e.start,end:e.end});if(e.direction==="H")return J;g()})(t.segments),zo=t=>e=>n=>r=>{if(r.tag==="Just"){const i=Bn(n)(e);if(i.tag==="Just"){const o=Kt(u=>u.id===r._1)(i._1);if(o.tag==="Just")return o._1.side;if(o.tag==="Nothing")return t;g()}if(i.tag==="Nothing")return t;g()}if(r.tag==="Nothing")return t;g()},sm=t=>e=>n=>{const r=Ng({origin:w("Just",Eg("SegmentOrigin",n)),kind:w("Just","vs"),hitbox:n.hitbox})(e.cGraph),i=Ap(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const o=Zt(n.potentialGroupParents[0])(i.cNodes);if(o.tag==="Just"){if(o._1.cGroup.tag==="Just")return xg(r.id)(o._1.cGroup._1)(i);if(o._1.cGroup.tag==="Nothing")return i;g()}if(o.tag==="Nothing")return i;g()}return Es({master:w("Just",r.id),nodes:[r.id]})(i).graph})(),edgeToCs:T(o=>u=>bt(S)(re)(u)([r.id])(o))(e.edgeToCs)(n.representedEdges),lockMap:tt(nt)(r.id)(om(t)(n.representedEdges))(e.lockMap)}},am=t=>e=>n=>{const r=Qt(i=>J,i=>o=>w("Just",{head:i,tail:o}),Et(rm)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const i=T(o=>u=>nm(o.survivor)(u)?{...o,survivor:em(o.survivor)(u)}:{survivor:u,merged:[...o.merged,o.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return T(sm(t))(n)([...i.merged,i.survivor])}g()},cm=t=>({cGraph:{cNodes:A,cNodeOrder:[],cGroups:A,cGroupOrder:[],supportedDirections:im([pg,ks,Ep]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:A,edgeToCs:A,lockMap:A}),gm=t=>{const e=et(4);return{x:t.position._1*e,y:t.position._2*e,width:t.size._1*e,height:t.size._2*e}},fm=t=>e=>n=>T(r=>i=>{const o=Ng({origin:w("Just",Eg("NodeOrigin",i.node)),kind:J,hitbox:gm(i)})(r.cGraph),u=Bn(i.node)(t),s=(()=>{if(u.tag==="Nothing")return b(0,0);if(u.tag==="Just")return u._1;g()})();return{...r,cGraph:Es({master:w("Just",o.id),nodes:[o.id]})(o.graph).graph,nodeToC:tt(S)(i.node)(o.id)(r.nodeToC),lockMap:tt(nt)(o.id)((()=>{const a=s._1-s._2|0;return a<0?{...cn,left:!0}:a>0?{...cn,right:!0}:cn})())(r.lockMap)}})(n)(e),_m=t=>T(e=>n=>bt(S)(r=>i=>b(r._1+i._1|0,r._2+i._2|0))(n.to.node)(b(1,0))(bt(S)(r=>i=>b(r._1+i._1|0,r._2+i._2|0))(n.from.node)(b(0,1))(e)))(A)(t),dm=t=>T(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?tt(S)(n.origin._1._1)(n.hitbox.x)(e):e)(A)(xt(e=>Zt(e)(t.cNodes))(t.cNodeOrder)),lm=t=>T(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?tt(S)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(A)(xt(e=>Zt(e)(t.cNodes))(t.cNodeOrder)),hm=t=>T(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return T(i=>o=>tt(xc)(o)(r)(i))(e)(n.origin._1._1.affectedBends)}return e})(A)(xt(e=>Zt(e)(t.cNodes))(t.cNodeOrder)),Sg=t=>{const e=Ps(O(n=>b(n.id,n))(t.edges));return xt(n=>{const r=Mo(n.edge)(e);if(r.tag==="Just")return n.reversed?w("Just",{edgeId:n.edge,src:r._1.to.node,tgt:r._1.from.node,srcSide:zo(An)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:zo(Fn)(t.ports)(r._1.from.node)(r._1.from.port),path:n}):w("Just",{edgeId:n.edge,src:r._1.from.node,tgt:r._1.to.node,srcSide:zo(An)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:zo(Fn)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return J;g()})(t.paths)},pm=t=>e=>{const n=wt(e)(r=>{if(r.src===r.tgt)return[];if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return[];const i=Bn(r.tgt)(t.nodeToC),o=(()=>{if(i.tag==="Just")return Zt(i._1)(t.cGraph.cNodes);if(i.tag==="Nothing")return J;g()})(),u=Bn(r.src)(t.nodeToC),s=(()=>{if(u.tag==="Just")return Zt(u._1)(t.cGraph.cNodes);if(u.tag==="Nothing")return J;g()})(),a=(()=>{if(s.tag==="Just"){if(o.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(o._1.cGroup.tag==="Just")return w("Just",{srcGroup:s._1.cGroup._1,tgtGroup:o._1.cGroup._1,delta:0,weight:100});if(o._1.cGroup.tag==="Nothing")return J;g()}if(s._1.cGroup.tag==="Nothing")return J;g()}if(o.tag==="Nothing")return J;g()}if(s.tag==="Nothing")return J;g()})(),c=_=>h=>p=>{if(s.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(p.cGroup.tag==="Just")return _(p.hitbox.x)&&p.cGroup._1!==s._1.cGroup._1?w("Just",h(p.cGroup._1)(s._1.cGroup._1)):J;if(p.cGroup.tag==="Nothing")return J;g()}if(s._1.cGroup.tag==="Nothing")return J;g()}if(s.tag==="Nothing")return J;g()},f=xt(_=>Zt(_)(t.cGraph.cNodes))((()=>{const _=Mo(r.edgeId)(t.edgeToCs);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})()),d=(()=>{if(s.tag==="Just"&&r.srcSide==="West"){const _=s._1;return xt(c(h=>h<_.hitbox.x)(h=>p=>({srcGroup:h,tgtGroup:p,delta:1,weight:100})))(f)}return[]})(),l=(()=>{if(s.tag==="Just"&&r.tgtSide==="East"){const _=s._1;return xt(c(h=>h>_.hitbox.x)(h=>p=>({srcGroup:p,tgtGroup:h,delta:1,weight:100})))(f)}return[]})();if(a.tag==="Nothing")return[];if(a.tag==="Just")return[a._1,...d,...l];g()});return{sameEdgeVerticalSegments:r=>i=>r.origin.tag==="Just"&&r.origin._1.tag==="SegmentOrigin"&&i.origin.tag==="Just"&&i.origin._1.tag==="SegmentOrigin"&&(()=>{const o=i.origin._1._1;return Oe(u=>Ye(dn)(u)(o.representedEdges),r.origin._1._1.representedEdges)})(),vsLNodePair:r=>i=>r.origin.tag==="Just"&&i.origin.tag==="Just"&&(r.origin._1.tag==="SegmentOrigin"?i.origin._1.tag==="NodeOrigin":r.origin._1.tag==="NodeOrigin"&&i.origin._1.tag==="SegmentOrigin"),edgeLengthEdges:r=>n}},mm=t=>e=>{const n=et(4),r=dm(t),i=lm(t),o=Ps(O(s=>b(s.id,b(s.from.node,s.to.node)))(e.edges)),u=hm(t);return{nodes:O(s=>{const a=Bn(s.node)(r);if(a.tag==="Just")return{...s,position:b(a._1/n,s.position._2)};if(a.tag==="Nothing")return s;g()})(e.nodes),edges:O(s=>{const a=Mo(s.edge)(o),c=(()=>{if(a.tag==="Nothing")return s.segments;if(a.tag==="Just"){const f=Bn(a._1._1)(i),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})(),l=Bn(a._1._2)(i),_=(()=>{if(l.tag==="Nothing")return 0;if(l.tag==="Just")return l._1;g()})();return Bt((()=>{const h=s.reversed?_:d,p=s.reversed?d:_,m=s.segments.length;return y=>x=>{if(x.direction==="V"){const N=(()=>{if(y===0)return h;if(y===(m-1|0))return p;const v=Ds(x.start)(u);if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})();return{...x,start:b(x.start._1+N,x.start._2),end:b(x.end._1+N,x.end._2)}}if(x.direction==="H")return{...x,start:b((()=>{if(y===0)return x.start._1+h;const N=Ds(x.start)(u);if(N.tag==="Nothing")return x.start._1+0;if(N.tag==="Just")return x.start._1+N._1;g()})(),x.start._2),end:b((()=>{if(y===(m-1|0))return x.end._1+p;const N=Ds(x.end)(u);if(N.tag==="Nothing")return x.end._1+0;if(N.tag==="Just")return x.end._1+N._1;g()})(),x.end._2)};g()}})())(s.segments)}g()})();return{...s,segments:c,bends:ve(f=>d=>f.end,c,Lt(1,c.length,c))}})(e.paths)}},ym=t=>e=>n=>r=>i=>o=>{const u=Gs(i.nextId)(o._2.start)(o._2.end)(J)(t.edgeId),s=(()=>{if(o._1===0){if(e.tag==="Nothing")return u;if(e.tag==="Just")return{...u,ignoreSpacing:o._2.end._2<e._1.y?{...u.ignoreSpacing,down:!0}:o._2.end._2>e._1.y+e._1.height?{...u.ignoreSpacing,up:!0}:{...u.ignoreSpacing,up:!0,down:!0}};g()}return u})();return{nextId:i.nextId+1|0,segments:[...i.segments,(()=>{if(o._1===r){if(n.tag==="Nothing")return s;if(n.tag==="Just")return{...s,ignoreSpacing:o._2.start._2<n._1.y?{...s.ignoreSpacing,down:!0}:o._2.start._2>n._1.y+n._1.height?{...s.ignoreSpacing,up:!0}:{...s.ignoreSpacing,up:!0,down:!0}};g()}return s})()]}},Gg=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...Gs(o.nextId)(r.start)(b(r.start._1,i.down?n.y:n.y+n.height))(w("Just",e))(t.edgeId),aPort:w("Just",{node:t.src,side:i.side}),ignoreSpacing:i.down?{...cn,down:!0}:{...cn,up:!0}}]}),Ho=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...Gs(o.nextId)(r.end)(b(r.end._1,i.down?n.y:n.y+n.height))(w("Just",e))(t.edgeId),aPort:w("Just",{node:t.tgt,side:i.side}),ignoreSpacing:i.down?{...cn,down:!0}:{...cn,up:!0}}]}),xm=t=>e=>n=>{if(n.src===n.tgt)return e;const r=Bn(n.src)(t.nodeToC),i=Bn(n.tgt)(t.nodeToC),o=(()=>{if(r.tag==="Just"){const f=Zt(r._1)(t.cGraph.cNodes);return f.tag==="Just"?w("Just",f._1.hitbox):J}if(r.tag==="Nothing")return J;g()})(),u=(()=>{if(i.tag==="Just"){const f=Zt(i._1)(t.cGraph.cNodes);return f.tag==="Just"?w("Just",f._1.hitbox):J}if(i.tag==="Nothing")return J;g()})(),s=um(n.path),a=T(ym(n)(o)(u)(s.length-1|0))(e)(Bt(f=>d=>b(f,d))(s));if(0<s.length){const f=(()=>{if(r.tag==="Just"&&o.tag==="Just"){if(n.srcSide==="North")return Gg(n)(r._1)(o._1)(s[0])({side:le,down:!0})(a);if(n.srcSide==="South")return Gg(n)(r._1)(o._1)(s[0])({side:he,down:!1})(a)}return a})(),d=s.length-1|0;if(d>=0&&d<s.length&&i.tag==="Just"&&u.tag==="Just"){if(n.tgtSide==="North")return Ho(n)(i._1)(u._1)(s[d])({side:le,down:!0})(f);if(n.tgtSide==="South")return Ho(n)(i._1)(u._1)(s[d])({side:he,down:!1})(f)}return f}const c=s.length-1|0;if(c>=0&&c<s.length&&i.tag==="Just"&&u.tag==="Just"){if(n.tgtSide==="North")return Ho(n)(i._1)(u._1)(s[c])({side:le,down:!0})(a);if(n.tgtSide==="South")return Ho(n)(i._1)(u._1)(s[c])({side:he,down:!1})(a)}return a},Nm=t=>e=>n=>am(t)(T(xm(n))({nextId:0,segments:[]})(e).segments)(n),Jm=t=>Nm(t.edges)(Sg(t))(fm(_m(t.edges))(t.nodes)(cm())),Qn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Is=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},As=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Tm=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},wm=t=>{const e=t.Eq0();return n=>r=>{const i=s=>{let a=s,c=!0,f;for(;c;){const d=a,l=Qt(_=>J,_=>h=>w("Just",{head:_,tail:h}),d.queue);if(l.tag==="Nothing"){c=!1,f=d;continue}if(l.tag==="Just"){const _=l._1.head;if((p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=!1;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=!0;continue}}g()}return x})(d.removedNodes)){a={...d,queue:l._1.tail};continue}const h=Kt(p=>!Qn(p.eid)(d.removedEdges)&&(e.eq(p.src)(_)||e.eq(p.tgt)(_)))(r);if(h.tag==="Nothing"){a={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const p=e.eq(h._1.src)(_)?h._1.tgt:h._1.src,m={...d,degree:tt(t)(p)((()=>{const y=(x=>{let N=x,v=!0,k;for(;v;){const L=N;if(L.tag==="Leaf"){v=!1,k=J;continue}if(L.tag==="Node"){const E=t.compare(p)(L._3);if(E==="LT"){N=L._5;continue}if(E==="GT"){N=L._6;continue}if(E==="EQ"){v=!1,k=w("Just",L._4);continue}}g()}return k})(d.degree);if(y.tag==="Nothing")return-1;if(y.tag==="Just")return y._1-1|0;g()})())(d.degree),removedNodes:tt(t)(_)()(d.removedNodes),removedEdges:tt(nt)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:_,neighbour:p,viaSrc:e.eq(h._1.src)(_)}],queue:l._1.tail};if((()=>{const y=(N=>{let v=N,k=!0,L;for(;k;){const E=v;if(E.tag==="Leaf"){k=!1,L=J;continue}if(E.tag==="Node"){const B=t.compare(p)(E._3);if(B==="LT"){v=E._5;continue}if(B==="GT"){v=E._6;continue}if(B==="EQ"){k=!1,L=w("Just",E._4);continue}}g()}return L})(m.degree),x=N=>{let v=N,k=!0,L;for(;k;){const E=v;if(E.tag==="Leaf"){k=!1,L=!1;continue}if(E.tag==="Node"){const B=t.compare(p)(E._3);if(B==="LT"){v=E._5;continue}if(B==="GT"){v=E._6;continue}if(B==="EQ"){k=!1,L=!0;continue}}g()}return L};return(()=>{if(y.tag==="Nothing")return!1;if(y.tag==="Just")return y._1===1;g()})()&&!x(m.removedNodes)})()){a={...m,queue:[...m.queue,p]};continue}a=m;continue}}g()}return f},o=T(s=>a=>bt(t)(se)(a.src)(1)(bt(t)(se)(a.tgt)(1)(s)))(A)(r),u=i({degree:o,removedNodes:A,removedEdges:A,record:[],queue:at(s=>{const a=(c=>{let f=c,d=!0,l;for(;d;){const _=f;if(_.tag==="Leaf"){d=!1,l=J;continue}if(_.tag==="Node"){const h=t.compare(s)(_._3);if(h==="LT"){f=_._5;continue}if(h==="GT"){f=_._6;continue}if(h==="EQ"){d=!1,l=w("Just",_._4);continue}}g()}return l})(o);if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1===1;g()},n)});return{coreNodes:at(s=>!(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=!1;continue}if(l.tag==="Node"){const _=t.compare(s)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=!0;continue}}g()}return d})(u.removedNodes),n),coreEdges:at(s=>!Qn(s.eid)(u.removedEdges),r),removed:u.record}}},vm=t=>e=>n=>T(r=>i=>{const o=i.neighbour,u=(()=>{const s=(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=J;continue}if(l.tag==="Node"){const _=t.compare(o)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=w("Just",l._4);continue}}g()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})();return tt(t)(i.node)(i.viaSrc?u-1|0:u+1|0)(r)})(n)(we(e)),Fs=t=>{const e=t.Eq0();return n=>r=>i=>{const o={...i,treeNode:tt(t)(r)()(i.treeNode)};return T(u=>s=>{if(Qn(s.eid)(u.st.edgeVisited))return u;const a={...u.st,edgeVisited:tt(nt)(s.eid)()(u.st.edgeVisited)},c=e.eq(s.src)((()=>{const f=s.src,d=_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(f)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=s.tgt;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?s.src:(()=>{const f=s.tgt,d=_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(f)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=s.src;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(Qn(s.eid)(a.treeEdge)){if((d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=!1;continue}if(p.tag==="Node"){const m=t.compare(c)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=!0;continue}}g()}return h})(a.treeNode))return{...u,st:a};const f=Fs(t)(n)(c)(a);return{count:u.count+f.count|0,st:f.st}}if((()=>{const f=l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=!1;continue}if(m.tag==="Node"){const y=t.compare(c)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=!0;continue}}g()}return p},d=s.tgt;return!f(a.treeNode)&&(()=>{const l=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=J;continue}if(N.tag==="Node"){const v=t.compare(d)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=w("Just",N._4);continue}}g()}return x})(a.layer),_=s.src,h=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=J;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=w("Just",N._4);continue}}g()}return x})(a.layer);if(l.tag==="Nothing"){if(h.tag==="Nothing")return s.delta===0;if(h.tag==="Just")return s.delta===-h._1;g()}if(l.tag==="Just"){if(h.tag==="Nothing")return s.delta===(l._1-0|0);if(h.tag==="Just")return s.delta===(l._1-h._1|0)}g()})()})()){const f=Fs(t)(n)(c)({...a,treeEdge:tt(nt)(s.eid)()(a.treeEdge)});return{count:u.count+f.count|0,st:f.st}}return{...u,st:a}})({count:1,st:o})(at(u=>(e.eq(u.src)(r)||e.eq(u.tgt)(r))&&!Qn(u.eid)(o.edgeVisited),n))}},Wo=t=>e=>n=>r=>{const i=r.src,o=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const y=t.compare(i)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=w("Just",m._4);continue}}g()}return p})(e.poID),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})(),s=r.tgt,a=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const y=t.compare(s)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=w("Just",m._4);continue}}g()}return p})(e.poID),c=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})(),f=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const y=t.compare(n)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=w("Just",m._4);continue}}g()}return p})(e.poID),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return(()=>{const l=r.src,_=(h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=J;continue}if(x.tag==="Node"){const N=t.compare(l)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=w("Just",x._4);continue}}g()}return y})(e.lowestPoID);return(()=>{if(_.tag==="Nothing")return 0<=d;if(_.tag==="Just")return _._1<=d;g()})()&&(()=>{const h=r.tgt;return d<=u&&(()=>{const p=(m=>{let y=m,x=!0,N;for(;x;){const v=y;if(v.tag==="Leaf"){x=!1,N=J;continue}if(v.tag==="Node"){const k=t.compare(h)(v._3);if(k==="LT"){y=v._5;continue}if(k==="GT"){y=v._6;continue}if(k==="EQ"){x=!1,N=w("Just",v._4);continue}}g()}return N})(e.lowestPoID);return(()=>{if(p.tag==="Nothing")return 0<=d;if(p.tag==="Just")return p._1<=d;g()})()&&d<=c})()})()})()?u>=c:u<c},bm=t=>{const e=te(t)(zt);return n=>({layer:e(O(r=>b(r,0))(n)),treeNode:A,treeEdge:A,poID:A,lowestPoID:A,cutvalue:A,postOrder:1,edgeVisited:A})},km=t=>e=>n=>T(r=>i=>{if((()=>{const f=i.src,d=h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=!1;continue}if(x.tag==="Node"){const N=t.compare(f)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=!0;continue}}g()}return y},l=i.tgt,_=h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=!1;continue}if(x.tag==="Node"){const N=t.compare(l)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=!0;continue}}g()}return y};return d(n.treeNode)===_(n.treeNode)})())return r;const o=i.tgt,u=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(o)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(n.layer),s=i.src,a=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(s)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(n.layer),c=(()=>{if(u.tag==="Nothing"){if(a.tag==="Nothing")return-i.delta;if(a.tag==="Just")return-a._1-i.delta|0;g()}if(u.tag==="Just"){if(a.tag==="Nothing")return(u._1-0|0)-i.delta|0;if(a.tag==="Just")return(u._1-a._1|0)-i.delta|0}g()})();return c<r.slack?{edge:w("Just",i),slack:c}:r})({edge:J,slack:1e9})(e).edge,Lm=t=>{const e=te(t)(zt);return n=>r=>{const i=T(o=>u=>Is(o)((()=>{const s=(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=J;continue}if(l.tag==="Node"){const _=t.compare(u)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=w("Just",l._4);continue}}g()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(1e9)(n);return e(O(o=>b(o,(()=>{const u=(s=>{let a=s,c=!0,f;for(;c;){const d=a;if(d.tag==="Leaf"){c=!1,f=J;continue}if(d.tag==="Node"){const l=t.compare(o)(d._3);if(l==="LT"){a=d._5;continue}if(l==="GT"){a=d._6;continue}if(l==="EQ"){c=!1,f=w("Just",d._4);continue}}g()}return f})(r);if(u.tag==="Nothing")return-i;if(u.tag==="Just")return u._1-i|0;g()})()))(n))}},Pg=t=>{const e=t.Eq0();return n=>r=>i=>{const o=T(s=>a=>{const c=Pg(t)(n)(e.eq(a.src)(r)?a.tgt:a.src)({...s.st,edgeVisited:tt(nt)(a.eid)()(s.st.edgeVisited)});return{lowest:Is(s.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:i})(at(s=>Qn(s.eid)(i.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!Qn(s.eid)(i.edgeVisited),n)),u=Is(o.lowest)(o.st.postOrder);return{lowest:u,st:{...o.st,poID:tt(t)(r)(o.st.postOrder)(o.st.poID),lowestPoID:tt(t)(r)(u)(o.st.lowestPoID),postOrder:o.st.postOrder+1|0}}}},Dg=t=>{const e=Pg(t);return n=>r=>i=>0<n.length?e(r)(n[0])({...i,edgeVisited:A,postOrder:1,poID:A,lowestPoID:A}).st:i},Em=t=>{const e=t.Eq0();return n=>r=>i=>at(o=>Qn(o.eid)(r.treeEdge)&&(e.eq(o.src)(i)||e.eq(o.tgt)(i)),n)},Cm=t=>e=>Kt(n=>{const r=As(n.eid)(e.cutvalue);return Qn(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),Ig=t=>{const e=Fs(t);return n=>r=>i=>{const o=0<n.length?w("Just",n[0]):J;if(o.tag==="Nothing")return i;if(o.tag==="Just"){const u=e(r)(o._1)({...i,edgeVisited:A,treeNode:A,treeEdge:A});if(u.count>=n.length)return u.st;const s=km(t)(r)(u.st);if(s.tag==="Nothing")return u.st;if(s.tag==="Just"){const a=s._1.tgt,c=(h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=J;continue}if(x.tag==="Node"){const N=t.compare(a)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=w("Just",x._4);continue}}g()}return y})(u.st.layer),f=s._1.src,d=(h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=J;continue}if(x.tag==="Node"){const N=t.compare(f)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=w("Just",x._4);continue}}g()}return y})(u.st.layer),l=(()=>{if(c.tag==="Nothing"){if(d.tag==="Nothing")return-s._1.delta;if(d.tag==="Just")return-d._1-s._1.delta|0;g()}if(c.tag==="Just"){if(d.tag==="Nothing")return(c._1-0|0)-s._1.delta|0;if(d.tag==="Just")return(c._1-d._1|0)-s._1.delta|0}g()})(),_=(()=>{const h=s._1.tgt;return(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=!1;continue}if(N.tag==="Node"){const v=t.compare(h)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=!0;continue}}g()}return x})(u.st.treeNode)})()?-l:l;return Ig(t)(n)(r)({...u.st,layer:T(h=>p=>(m=>{let y=m,x=!0,N;for(;x;){const v=y;if(v.tag==="Leaf"){x=!1,N=!1;continue}if(v.tag==="Node"){const k=t.compare(p)(v._3);if(k==="LT"){y=v._5;continue}if(k==="GT"){y=v._6;continue}if(k==="EQ"){x=!1,N=!0;continue}}g()}return N})(u.st.treeNode)?tt(t)(p)((()=>{const m=(y=>{let x=y,N=!0,v;for(;N;){const k=x;if(k.tag==="Leaf"){N=!1,v=J;continue}if(k.tag==="Node"){const L=t.compare(p)(k._3);if(L==="LT"){x=k._5;continue}if(L==="GT"){x=k._6;continue}if(L==="EQ"){N=!1,v=w("Just",k._4);continue}}g()}return v})(u.st.layer);if(m.tag==="Nothing")return 0+_|0;if(m.tag==="Just")return m._1+_|0;g()})())(h):h)(u.st.layer)(n)})}}g()}},Sm=t=>e=>n=>r=>T(i=>o=>{if(Wo(t)(r)(o.src)(n)&&!Wo(t)(r)(o.tgt)(n)){const u=o.tgt,s=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=J;continue}if(p.tag==="Node"){const m=t.compare(u)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=w("Just",p._4);continue}}g()}return h})(r.layer),a=o.src,c=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=J;continue}if(p.tag==="Node"){const m=t.compare(a)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=w("Just",p._4);continue}}g()}return h})(r.layer),f=(()=>{if(s.tag==="Nothing"){if(c.tag==="Nothing")return-o.delta;if(c.tag==="Just")return-c._1-o.delta|0;g()}if(s.tag==="Just"){if(c.tag==="Nothing")return(s._1-0|0)-o.delta|0;if(c.tag==="Just")return(s._1-c._1|0)-o.delta|0}g()})();if(f<i.slack)return{edge:w("Just",o),slack:f}}return i})({edge:J,slack:1e9})(e).edge,Gm=t=>{const e=t.Eq0();return n=>r=>i=>o=>{const u=o.tgt,s=o.src;return T(a=>c=>{if((()=>{const f=As(c.eid)(r.cutvalue);if(f.tag==="Just")return!0;if(f.tag==="Nothing")return!1;g()})()){const f=As(c.eid)(r.cutvalue),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return e.eq(s)(c.src)||e.eq(u)(c.tgt)?a-(d-c.weight):a+(d-c.weight)}return e.eq(i)(s)?e.eq(c.src)(i)?a+c.weight:a-c.weight:e.eq(c.src)(i)?a-c.weight:a+c.weight})(o.weight)(at(a=>a.eid!==o.eid&&(e.eq(a.src)(i)||e.eq(a.tgt)(i)),n))}},Pm=t=>{const e=Gm(t);return n=>r=>i=>{const o=(u,s,a)=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(u)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(a);if(c.tag==="Just")return tt(t)(u)(at(f=>f.eid!==s.eid,c._1))(a);if(c.tag==="Nothing")return a;g()};return(u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=(m=>{let y=m,x=!0,N;for(;x;){const v=y;if(v.tag==="Leaf"){x=!1,N=J;continue}if(v.tag==="Node"){const k=t.compare(_)(v._3);if(k==="LT"){y=v._5;continue}if(k==="GT"){y=v._6;continue}if(k==="EQ"){x=!1,N=w("Just",v._4);continue}}g()}return N})(l.unknown),p=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;g()})();if(p.length===1){const m=t.Eq0().eq(p[0].src)(_)?p[0].tgt:p[0].src;a={unknown:o(_,p[0],o(m,p[0],l.unknown)),cutvalue:tt(nt)(p[0].eid)(e(n)(l)(_)(p[0]))(l.cutvalue)},c=m;continue}f=!1,d=l}return d})(r)(i)}},Ag=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:c=>f=>c.delta===f.delta&&c.eid===f.eid&&n.eq(c.src)(f.src)&&e.eq(c.tgt)(f.tgt)&&c.weight===f.weight},i={compare:c=>f=>{const d=nt.compare(c.delta)(f.delta);if(d==="LT"||d==="GT"||d!=="EQ")return d;const l=nt.compare(c.eid)(f.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const _=t.compare(c.src)(f.src);if(_==="LT"||_==="GT"||_!=="EQ")return _;const h=t.compare(c.tgt)(f.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const p=it.compare(c.weight)(f.weight);return p==="LT"||p==="GT"||p!=="EQ"?p:De},Eq0:()=>r},o=T(c=>f=>tt(i)(f)()(c))(A),u=Em(t),s=te(t)(zt),a=Pm(t);return c=>f=>d=>{const l={unknown:s(O(_=>b(_,Ct(Qe.foldr,o(u(f)(d)(_)))))(c)),cutvalue:A};return{...d,cutvalue:T(a(f))(l)(at(_=>{const h=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=J;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=w("Just",N._4);continue}}g()}return x})(l.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;g()},c)).cutvalue}}},Dm=t=>{const e=Dg(t),n=Ag(t);return r=>i=>o=>u=>s=>{const a={...s,treeEdge:tt(nt)(u.eid)()(si(nt)(o.eid)(s.treeEdge))},c=u.tgt,f=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=J;continue}if(N.tag==="Node"){const v=t.compare(c)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=w("Just",N._4);continue}}g()}return x})(a.layer),d=u.src,l=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=J;continue}if(N.tag==="Node"){const v=t.compare(d)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=w("Just",N._4);continue}}g()}return x})(a.layer),_=(()=>{if(f.tag==="Nothing"){if(l.tag==="Nothing")return-u.delta;if(l.tag==="Just")return-l._1-u.delta|0;g()}if(f.tag==="Just"){if(l.tag==="Nothing")return(f._1-0|0)-u.delta|0;if(l.tag==="Just")return(f._1-l._1|0)-u.delta|0}g()})(),h=Wo(t)(a)(u.tgt)(o)?_:-_;return n(r)(i)(e(r)(i)({...a,layer:T(p=>m=>Wo(t)(a)(m)(o)?p:tt(t)(m)((()=>{const y=(x=>{let N=x,v=!0,k;for(;v;){const L=N;if(L.tag==="Leaf"){v=!1,k=J;continue}if(L.tag==="Node"){const E=t.compare(m)(L._3);if(E==="LT"){N=L._5;continue}if(E==="GT"){N=L._6;continue}if(E==="EQ"){v=!1,k=w("Just",L._4);continue}}g()}return k})(a.layer);if(y.tag==="Nothing")return 0+h|0;if(y.tag==="Just")return y._1+h|0;g()})())(p))(a.layer)(r)}))}},Im=t=>{const e=Dm(t);return n=>r=>i=>o=>(u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c;if(l===0){f=!1,d=_;continue}const h=Cm(i)(_);if(h.tag==="Nothing"){f=!1,d=_;continue}if(h.tag==="Just"){const p=Sm(t)(i)(h._1)(_);if(p.tag==="Nothing"){f=!1,d=_;continue}if(p.tag==="Just"){a=l-1|0,c=e(r)(i)(h._1)(p._1)(_);continue}}g()}return d})(n)(o)},Am=t=>{const e=Ag(t),n=Dg(t),r=Ig(t);return i=>o=>u=>e(i)(o)(n(i)(o)(r(i)(o)(u)))},Fg=t=>e=>T(n=>r=>bt(t)(re)(e(r))([r])(n))(A),Fm=t=>{const e=te(t)(zt);return n=>r=>i=>{const o=a=>c=>f=>d=>{let l=a,_=c,h=f,p=d,m=!0,y;for(;m;){const x=l,N=_,v=h,k=p,L=Qt(E=>J,E=>B=>w("Just",{head:E,tail:B}),v);if(L.tag==="Nothing"){m=!1,y=k;continue}if(L.tag==="Just"){const E=L._1.head,B=(G=>{let P=G,V=!0,U;for(;V;){const M=P;if(M.tag==="Leaf"){V=!1,U=J;continue}if(M.tag==="Node"){const H=t.compare(E)(M._3);if(H==="LT"){P=M._5;continue}if(H==="GT"){P=M._6;continue}if(H==="EQ"){V=!1,U=w("Just",M._4);continue}}g()}return U})(k.layer),q=(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})(),j=T(G=>P=>{const V=P.tgt,U=(H=>{let R=H,C=!0,D;for(;C;){const F=R;if(F.tag==="Leaf"){C=!1,D=J;continue}if(F.tag==="Node"){const I=t.compare(V)(F._3);if(I==="LT"){R=F._5;continue}if(I==="GT"){R=F._6;continue}if(I==="EQ"){C=!1,D=w("Just",F._4);continue}}g()}return D})(G.incident),M=(()=>{if(U.tag==="Nothing")return-1;if(U.tag==="Just")return U._1-1|0;g()})();return{st:{...G.st,layer:tt(t)(P.tgt)(Tm((()=>{const H=P.tgt,R=(C=>{let D=C,F=!0,I;for(;F;){const z=D;if(z.tag==="Leaf"){F=!1,I=J;continue}if(z.tag==="Node"){const $=t.compare(H)(z._3);if($==="LT"){D=z._5;continue}if($==="GT"){D=z._6;continue}if($==="EQ"){F=!1,I=w("Just",z._4);continue}}g()}return I})(G.st.layer);if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})())(q+P.delta|0))(G.st.layer)},incident:tt(t)(P.tgt)(M)(G.incident),queue:M===0?[...G.queue,P.tgt]:G.queue}})({st:k,incident:N,queue:L._1.tail})((()=>{const G=(P=>{let V=P,U=!0,M;for(;U;){const H=V;if(H.tag==="Leaf"){U=!1,M=J;continue}if(H.tag==="Node"){const R=t.compare(E)(H._3);if(R==="LT"){V=H._5;continue}if(R==="GT"){V=H._6;continue}if(R==="EQ"){U=!1,M=w("Just",H._4);continue}}g()}return M})(x);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})());l=x,_=j.incident,h=j.queue,p=j.st;continue}g()}return y},u=Fg(t)(a=>a.tgt)(r),s=e(O(a=>b(a,(()=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(u);if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1.length;g()})()))(n));return o(Fg(t)(a=>a.src)(r))(s)(at(a=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(s);if(c.tag==="Nothing")return!0;if(c.tag==="Just")return c._1===0;g()},n))(i)}},Bm=t=>{const e=bm(t),n=Fm(t),r=Am(t),i=Im(t);return o=>u=>{const s=n(o)(u)(e(o));return u.length===0?s.layer:i(4*o.length|0)(o)(u)(r(o)(u)(s)).layer}},Bg=t=>{const e=Lm(t),n=Bm(t),r=wm(t);return i=>o=>{if(i.length===0)return A;if(i.length<40)return e(i)(n(i)(o));const u=r(i)(o);return e(i)(vm(t)(u.removed)(n(u.coreNodes)(u.coreEdges)))}},Qg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Bs=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Qm=Bg(nt),Pi=t=>e=>({...e,edges:[...e.edges,{src:t.src,tgt:t.tgt,delta:t.delta,weight:t.weight,eid:e.nextEid}],nextEid:e.nextEid+1|0}),Rm=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=et((()=>{const i=Qg(n.cGroup._1)(t);if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})());return Ze(n.id)(i=>({...i,hitbox:{...i.hitbox,x:r+i.cGroupOffset.x}}))(e)}g()},Mm=t=>e=>({...e,cGraph:T(Rm(t))(e.cGraph)((()=>{const n=e.cGraph;return xt(r=>Zt(r)(n.cNodes))(n.cNodeOrder)})())}),zm=t=>e=>n=>r=>i=>{const o=ce(io(e.cGroupOffset.x-t.cGroupOffset.x));return Pi({src:i.nextNodeId,tgt:r,delta:Bs(0)(-o),weight:1})(Pi({src:i.nextNodeId,tgt:n,delta:Bs(0)(o),weight:1})({...i,nodes:[...i.nodes,i.nextNodeId],nextNodeId:i.nextNodeId+1|0}))},Hm=t=>e=>n=>r=>i=>o=>u=>{const s=Bs(0)(ce(io(n.cGroupOffset.x+n.hitbox.width+(e.direction==="LEFT"||e.direction==="RIGHT"?e.spacingsHandler.horizontalSpacing(n)(r):e.spacingsHandler.verticalSpacing(n)(r))-r.cGroupOffset.x)));return t.sameEdgeVerticalSegments(n)(r)?zm(n)(r)(i)(o)(u):Pi({src:i,tgt:o,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(u)},Wm=t=>e=>n=>r=>i=>{const o=Zt(i)(e.cGraph.cNodes);if(o.tag==="Nothing")return r;if(o.tag==="Just")return(n.cGroup.tag==="Nothing"?o._1.cGroup.tag==="Nothing":n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"&&n.cGroup._1===o._1.cGroup._1)?r:n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"?Hm(t)(e)(n)(o._1)(n.cGroup._1)(o._1.cGroup._1)(r):r;g()},Om=t=>e=>n=>r=>T(Wm(t)(e)(r))(n)(r.constraints),Ym=t=>e=>Pi({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),$m=t=>{const e=T(i=>o=>bt(nt)(se)(o.tgt)(1)(i))(A)(t.edges),n=at(i=>{const o=Qg(i)(e);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return o._1===0;g()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return T(i=>o=>Pi({src:r,tgt:o,delta:1,weight:0})(i))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},qm=t=>e=>{const n=$m(T(Ym)(T(Om(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return xt(i=>Zt(i)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},Xm=t=>e=>{const n=qm(t)(e);return Mm(Qm(n.nodes)(n.edges))(e)},Rg=t=>t,ie=Rg("H"),oe=Rg("V"),Vm=t=>b(t._2,t._1),Mg=t=>({...t,position:b(t.position._2,t.position._1),size:b(t.size._2,t.size._1)}),Um=t=>({start:b(t.start._2,t.start._1),end:b(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return oe;if(t.direction==="V")return ie;g()})()}),zg=t=>({...t,segments:O(Um)(t.segments),bends:O(Vm)(t.bends)}),Km=t=>({nodes:O(Mg)(t.nodes),edges:t.edges,paths:O(zg)(t.paths),ports:t.ports}),Zm={nodeNode:8,edgeNode:4,edgeEdge:10},jm=t=>e=>({horizontalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r)||n.ignoreSpacing.right||r.ignoreSpacing.left)return 0;const i=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?i?t.edgeEdge:t.edgeNode:i?t.edgeNode:t.nodeNode},verticalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r))return 1;if(n.hitbox.y<=r.hitbox.y?n.ignoreSpacing.down||r.ignoreSpacing.up:n.ignoreSpacing.up||r.ignoreSpacing.down)return 0;const i=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?i?t.edgeEdge:t.edgeNode:i?t.edgeNode:t.nodeNode}}),ty=t=>e=>Xm(e),ey=t=>e=>n=>{const r=Km(n),i=Jm(r),o=pm(i)(Sg(r)),u=mm(yg(ks)(Mp({...Hp(i.cGraph),compactionAlgorithm:w("Just",ty()(o)),constraintAlgorithm:w("Just",tm(e.edgeEdge)),spacingsHandler:jm(e)(o)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:O(Mg)(u.nodes),edges:O(zg)(u.edges)}},Hg=t=>t,zr=te(nt)(zt),It=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Wg=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},lt=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ht=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Hr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},ny=t=>e=>{const n=nt.compare(t._1)(e._1);return n==="LT"?Je:n==="GT"?Te:nt.compare(t._2)(e._2)},Wr=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ry=(()=>{const t=Ue.unfoldr(xn);return e=>t(Ke("IterNode",e,yn))})(),iy=t=>t,Og=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},oy=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Oo=Hg("Regular"),Yo=Hg("Critical"),Yg=t=>e=>{const n=T(u=>s=>tt(S)(s.node)(s)(u))(A)(e),r=1.25*et(4),i=(u,s,a)=>(c=>f=>d=>{let l=c,_=f,h=d,p=!0,m;for(;p;){const y=l,x=_,N=h;if(N.critical){p=!1,m=N;continue}const v=Qt(L=>J,L=>E=>w("Just",{head:L,tail:E}),y),k=Qt(L=>J,L=>E=>w("Just",{head:L,tail:E}),x);if(v.tag==="Just"&&k.tag==="Just"){const L=v._1.head>k._1.head-u&&v._1.head<k._1.head+u?{...N,critical:!0}:v._1.head>k._1.head-r&&v._1.head<k._1.head+r?{...N,conflicts:N.conflicts+1|0}:N;if(L.critical){p=!1,m=L;continue}if(v._1.head<=k._1.head){l=v._1.tail,_=x,h=L;continue}l=y,_=k._1.tail,h=L;continue}p=!1,m=N}return m})(s)(a)({conflicts:0,critical:!1}),o=(u,s,a)=>{if(ht(T(ht)(-1e18)(s.incoming))(T(ht)(-1e18)(s.outgoing))-lt(T(lt)(1e18)(s.incoming))(T(lt)(1e18)(s.outgoing))<.001||ht(T(ht)(-1e18)(a.incoming))(T(ht)(-1e18)(a.outgoing))-lt(T(lt)(1e18)(a.incoming))(T(lt)(1e18)(a.outgoing))<.001)return[];const c=i(u,s.outgoing,a.incoming),f=i(u,a.outgoing,s.incoming);if(c.critical||f.critical)return[...c.critical?[{src:a.id,tgt:s.id,weight:1,kind:Yo}]:[],...f.critical?[{src:s.id,tgt:a.id,weight:1,kind:Yo}]:[]];const d=lt(T(lt)(1e18)(s.incoming))(T(lt)(1e18)(s.outgoing)),l=ht(T(ht)(-1e18)(s.incoming))(T(ht)(-1e18)(s.outgoing)),_=lt(T(lt)(1e18)(a.incoming))(T(lt)(1e18)(a.outgoing)),h=ht(T(ht)(-1e18)(a.incoming))(T(ht)(-1e18)(a.outgoing)),p=(1*c.conflicts|0)+(16*(T(y=>x=>x>h?y:x>=_?y+1|0:y)(0)(s.outgoing)+T(y=>x=>x>l?y:x>=d?y+1|0:y)(0)(a.incoming)|0)|0)|0,m=(1*f.conflicts|0)+(16*(T(y=>x=>x>l?y:x>=d?y+1|0:y)(0)(a.outgoing)+T(y=>x=>x>h?y:x>=_?y+1|0:y)(0)(s.incoming)|0)|0)|0;return p<m?[{src:s.id,tgt:a.id,weight:m-p|0,kind:Oo}]:p>m?[{src:a.id,tgt:s.id,weight:p-m|0,kind:Oo}]:p>0?[{src:s.id,tgt:a.id,weight:0,kind:Oo},{src:a.id,tgt:s.id,weight:0,kind:Oo}]:[]};return T(u=>s=>T(a=>c=>tt(S)(c._1)(c._2)(a))(u)((()=>{const a=T(G=>P=>{const V=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;g()})(),U=Og(V)(G.entries);if(U.tag==="Nothing")return{...G,entries:tt(S)(V)({id:0,members:[P.edge.id],incoming:[P.fromPos._1],outgoing:[P.toPos._1],slot:0,mark:0,splitBy:J,splitPartner:J})(G.entries),order:[...G.order,V]};if(U.tag==="Just")return{...G,entries:tt(S)(V)({...U._1,members:[...U._1.members,P.edge.id],incoming:[..._r(M=>M<P.fromPos._1)(U._1.incoming).init,P.fromPos._1,..._r(M=>M<=P.fromPos._1)(U._1.incoming).rest],outgoing:[..._r(M=>M<P.toPos._1)(U._1.outgoing).init,P.toPos._1,..._r(M=>M<=P.toPos._1)(U._1.outgoing).rest]})(G.entries)};g()})({entries:A,order:[]})(s._2),c=Bt(G=>P=>({...P,id:G}))(xt(G=>Og(G)(a.entries))(a.order));if(c.length===0)return[];const f=T(G=>P=>G.prev.tag==="Just"&&P-G.prev._1<1e-9?G:{prev:w("Just",P),out:[...G.out,P]})({prev:J,out:[]})(Et(it.compare)([...wt(c)(G=>G.incoming),...wt(c)(G=>G.outgoing)])).out,d=f.length<2?.2*r:.2*T(G=>P=>{if(G.prev.tag==="Nothing")return{prev:w("Just",P),mn:G.mn};if(G.prev.tag==="Just")return{prev:w("Just",P),mn:lt(G.mn)(P-G.prev._1)};g()})({prev:J,mn:1e18})(f).mn,l={segments:c,deps:(()=>{const G=c.length;return wt(wt(Ft(0,G-2|0))(P=>wt(Ft(P+1|0,G-1|0))(V=>[b(P,V)])))(P=>P._1>=0&&P._1<c.length?P._2>=0&&P._2<c.length?o(d,c[P._1],c[P._2]):[]:[])})()},_=at(G=>{if(G.kind==="Critical")return!0;if(G.kind==="Regular")return!1;g()},l.deps),h=(()=>{if(_.length<2)return l;const G=zr((()=>{const H=l.segments;return O(R=>b(R.id,R.mark))((()=>{const R=H.length,C=F=>{let I=F,z=!0,$;for(;z;){const X=I,Y=Kt(W=>{const K=It(W)(X.inWeight);if(K.tag==="Nothing")return!0;if(K.tag==="Just")return K._1===0;g()})(X.remaining);if(Y.tag==="Nothing"){z=!1,$=X;continue}if(Y.tag==="Just"){const W=Y._1;I={...X,inWeight:T(K=>Z=>bt(nt)(se)(Z.tgt)(-Z.weight)(K))(X.inWeight)((()=>{const K=It(W)(X.depsBySrc);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),marks:tt(nt)(W)(X.nextSource)(X.marks),nextSource:X.nextSource+1|0,outWeight:T(K=>Z=>bt(nt)(se)(Z.src)(-Z.weight)(K))(X.outWeight)((()=>{const K=It(W)(X.depsByTgt);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),remaining:at(K=>K!==W,X.remaining)};continue}g()}return $},D=F=>{let I=F,z=!0,$;for(;z;){const X=I,Y=Kt(W=>{const K=It(W)(X.outWeight);if(K.tag==="Nothing")return!0;if(K.tag==="Just")return K._1===0;g()})(X.remaining);if(Y.tag==="Nothing"){z=!1,$=X;continue}if(Y.tag==="Just"){const W=Y._1;I={...X,inWeight:T(K=>Z=>bt(nt)(se)(Z.tgt)(-Z.weight)(K))(X.inWeight)((()=>{const K=It(W)(X.depsBySrc);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),marks:tt(nt)(W)(X.nextSink)(X.marks),nextSink:X.nextSink-1|0,outWeight:T(K=>Z=>bt(nt)(se)(Z.src)(-Z.weight)(K))(X.outWeight)((()=>{const K=It(W)(X.depsByTgt);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),remaining:at(K=>K!==W,X.remaining)};continue}g()}return $};return(F=>{let I=F,z=!0,$;for(;z;){const X=C(D(I));if(X.remaining.length===0){z=!1,$=O(Y=>{const W=It(Y.id)(X.marks),K=(()=>{if(W.tag==="Nothing")return Y.id;if(W.tag==="Just")return W._1;g()})();return{...Y,mark:K<R?(K+R|0)+1|0:K}})(H);continue}I=(()=>{const Y=K=>{const Z=It(K)(X.outWeight),ct=It(K)(X.inWeight);return(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()-(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()|0},W=Et(K=>Z=>nt.compare(Y(Z))(Y(K)))(X.remaining);if(0<W.length){const K=W[0];return{...X,inWeight:T(Z=>ct=>bt(nt)(se)(ct.tgt)(-ct.weight)(Z))(X.inWeight)((()=>{const Z=It(K)(X.depsBySrc);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;g()})()),marks:tt(nt)(K)(X.nextSource)(X.marks),nextSource:X.nextSource+1|0,outWeight:T(Z=>ct=>bt(nt)(se)(ct.src)(-ct.weight)(Z))(X.outWeight)((()=>{const Z=It(K)(X.depsByTgt);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;g()})()),remaining:at(Z=>Z!==K,X.remaining)}}return X})()}return $})({remaining:O(F=>F.id)(H),marks:A,inWeight:T(F=>I=>bt(nt)(se)(I.tgt)(I.weight)(F))(A)(_),outWeight:T(F=>I=>bt(nt)(se)(I.src)(I.weight)(F))(A)(_),depsBySrc:T(F=>I=>bt(nt)(re)(I.src)([I])(F))(A)(_),depsByTgt:T(F=>I=>bt(nt)(re)(I.tgt)([I])(F))(A)(_),nextSink:R-1|0,nextSource:R+1|0})})())})()),P=at(H=>{const R=It(H.src)(G),C=It(H.tgt)(G);return(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})()>(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;g()})()},_);if(P.length===0)return l;const V=T(H=>R=>{if(Ye(Er)(R.src)(H.decisions)||Ye(Er)(R.tgt)(H.decisions))return H;const C=It(R.src)(H.segMap),D=It(R.tgt)(H.segMap);if(C.tag==="Just"&&D.tag==="Just"){const F=(C._1.incoming.length+C._1.outgoing.length|0)>2&&(D._1.incoming.length+D._1.outgoing.length|0)<=2,I=F?D._1:C._1;return{decisions:[...H.decisions,I.id],segMap:tt(nt)(I.id)({...I,splitBy:w("Just",F?C._1.id:D._1.id)})(H.segMap)}}return H})({decisions:[],segMap:zr(O(H=>b(H.id,H))(l.segments))})(P),U=V.segMap,M=T(H=>R=>{const C=lt(T(lt)(1e18)(R.incoming))(T(lt)(1e18)(R.outgoing)),D=ht(T(ht)(-1e18)(R.incoming))(T(ht)(-1e18)(R.outgoing)),F=at(Y=>Y.a.startPosition<=D&&Y.a.endPosition>=C,Bt(Y=>W=>({i:Y,a:W}))(H.freeAreas));if(F.length===0){const Y={...R,incoming:Et(it.compare)(R.incoming),outgoing:Et(it.compare)([(C+D)/2]),splitPartner:w("Just",H.nextId)},W={id:H.nextId,incoming:Et(it.compare)([(C+D)/2]),mark:0,members:R.members,outgoing:Et(it.compare)(R.outgoing),slot:0,splitBy:J,splitPartner:w("Just",R.id)};return{segMap:tt(nt)(W.id)(W)(tt(nt)(Y.id)(Y)(H.segMap)),freeAreas:H.freeAreas,nextId:H.nextId+1|0}}const I=0<F.length?w("Just",F[0]):J,z=(()=>{if(I.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(I.tag==="Just"){if(F.length===1)return I._1;const Y=O(W=>({c:W,rating:(()=>{const K=(W.a.startPosition+W.a.endPosition)/2,Z=[K],ct=[K],_t=T((()=>{const yt=H.segMap;return St=>Ht=>{const pt=It(Ht.tgt)(yt);if(pt.tag==="Nothing")return St;if(pt.tag==="Just"){const Wt=lt(T(lt)(1e18)(pt._1.incoming))(T(lt)(1e18)(pt._1.outgoing)),Tt=ht(T(ht)(-1e18)(pt._1.incoming))(T(ht)(-1e18)(pt._1.outgoing)),mt=lt(T(lt)(1e18)(R.incoming))(T(lt)(1e18)(Z)),ft=(()=>{const Pt=ht(T(ht)(-1e18)(R.incoming))(T(ht)(-1e18)(Z)),At=T(qt=>de=>de>Tt?qt:de>=Wt?qt+1|0:qt)(0)(Z)+T(qt=>de=>de>Pt?qt:de>=mt?qt+1|0:qt)(0)(pt._1.incoming)|0,Be=lt(T(lt)(1e18)(R.incoming))(T(lt)(1e18)(Z)),an=ht(T(ht)(-1e18)(R.incoming))(T(ht)(-1e18)(Z)),Xe=lt(T(lt)(1e18)(pt._1.incoming))(T(lt)(1e18)(pt._1.outgoing)),nn=ht(T(ht)(-1e18)(pt._1.incoming))(T(ht)(-1e18)(pt._1.outgoing)),Pe=T(qt=>de=>de>an?qt:de>=Be?qt+1|0:qt)(0)(pt._1.outgoing)+T(qt=>de=>de>nn?qt:de>=Xe?qt+1|0:qt)(0)(R.incoming)|0;return At===Pe?At>0?{...St,deps:St.deps+2|0,crossings:St.crossings+At|0}:St:{...St,deps:St.deps+1|0,crossings:St.crossings+Wr(At)(Pe)|0}})(),ot=lt(T(lt)(1e18)(pt._1.incoming))(T(lt)(1e18)(pt._1.outgoing)),dt=ht(T(ht)(-1e18)(pt._1.incoming))(T(ht)(-1e18)(pt._1.outgoing)),ut=lt(T(lt)(1e18)(ct))(T(lt)(1e18)(R.outgoing)),st=ht(T(ht)(-1e18)(ct))(T(ht)(-1e18)(R.outgoing)),Nt=T(Pt=>At=>At>dt?Pt:At>=ot?Pt+1|0:Pt)(0)(R.outgoing)+T(Pt=>At=>At>st?Pt:At>=ut?Pt+1|0:Pt)(0)(pt._1.incoming)|0,Jt=lt(T(lt)(1e18)(ct))(T(lt)(1e18)(R.outgoing)),kt=ht(T(ht)(-1e18)(ct))(T(ht)(-1e18)(R.outgoing)),Ot=lt(T(lt)(1e18)(pt._1.incoming))(T(lt)(1e18)(pt._1.outgoing)),_n=ht(T(ht)(-1e18)(pt._1.incoming))(T(ht)(-1e18)(pt._1.outgoing)),Fe=T(Pt=>At=>At>kt?Pt:At>=Jt?Pt+1|0:Pt)(0)(pt._1.outgoing)+T(Pt=>At=>At>_n?Pt:At>=Ot?Pt+1|0:Pt)(0)(ct)|0;return Nt===Fe?Nt>0?{...ft,deps:ft.deps+2|0,crossings:ft.crossings+Nt|0}:ft:{...ft,deps:ft.deps+1|0,crossings:ft.crossings+Wr(Nt)(Fe)|0}}g()}})())(T((()=>{const yt=H.segMap;return St=>Ht=>{const pt=It(Ht.src)(yt);if(pt.tag==="Nothing")return St;if(pt.tag==="Just"){const Wt=lt(T(lt)(1e18)(pt._1.incoming))(T(lt)(1e18)(pt._1.outgoing)),Tt=ht(T(ht)(-1e18)(pt._1.incoming))(T(ht)(-1e18)(pt._1.outgoing)),mt=lt(T(lt)(1e18)(R.incoming))(T(lt)(1e18)(Z)),ft=(()=>{const Pt=ht(T(ht)(-1e18)(R.incoming))(T(ht)(-1e18)(Z)),At=T(qt=>de=>de>Tt?qt:de>=Wt?qt+1|0:qt)(0)(Z)+T(qt=>de=>de>Pt?qt:de>=mt?qt+1|0:qt)(0)(pt._1.incoming)|0,Be=lt(T(lt)(1e18)(R.incoming))(T(lt)(1e18)(Z)),an=ht(T(ht)(-1e18)(R.incoming))(T(ht)(-1e18)(Z)),Xe=lt(T(lt)(1e18)(pt._1.incoming))(T(lt)(1e18)(pt._1.outgoing)),nn=ht(T(ht)(-1e18)(pt._1.incoming))(T(ht)(-1e18)(pt._1.outgoing)),Pe=T(qt=>de=>de>an?qt:de>=Be?qt+1|0:qt)(0)(pt._1.outgoing)+T(qt=>de=>de>nn?qt:de>=Xe?qt+1|0:qt)(0)(R.incoming)|0;return At===Pe?At>0?{...St,deps:St.deps+2|0,crossings:St.crossings+At|0}:St:{...St,deps:St.deps+1|0,crossings:St.crossings+Wr(At)(Pe)|0}})(),ot=lt(T(lt)(1e18)(pt._1.incoming))(T(lt)(1e18)(pt._1.outgoing)),dt=ht(T(ht)(-1e18)(pt._1.incoming))(T(ht)(-1e18)(pt._1.outgoing)),ut=lt(T(lt)(1e18)(ct))(T(lt)(1e18)(R.outgoing)),st=ht(T(ht)(-1e18)(ct))(T(ht)(-1e18)(R.outgoing)),Nt=T(Pt=>At=>At>dt?Pt:At>=ot?Pt+1|0:Pt)(0)(R.outgoing)+T(Pt=>At=>At>st?Pt:At>=ut?Pt+1|0:Pt)(0)(pt._1.incoming)|0,Jt=lt(T(lt)(1e18)(ct))(T(lt)(1e18)(R.outgoing)),kt=ht(T(ht)(-1e18)(ct))(T(ht)(-1e18)(R.outgoing)),Ot=lt(T(lt)(1e18)(pt._1.incoming))(T(lt)(1e18)(pt._1.outgoing)),_n=ht(T(ht)(-1e18)(pt._1.incoming))(T(ht)(-1e18)(pt._1.outgoing)),Fe=T(Pt=>At=>At>kt?Pt:At>=Jt?Pt+1|0:Pt)(0)(pt._1.outgoing)+T(Pt=>At=>At>_n?Pt:At>=Ot?Pt+1|0:Pt)(0)(ct)|0;return Nt===Fe?Nt>0?{...ft,deps:ft.deps+2|0,crossings:ft.crossings+Nt|0}:ft:{...ft,deps:ft.deps+1|0,crossings:ft.crossings+Wr(Nt)(Fe)|0}}g()}})())({crossings:0,deps:0})(at(yt=>yt.tgt===R.id,l.deps)))(at(yt=>yt.src===R.id,l.deps)),gt=(()=>{if(R.splitBy.tag==="Just")return It(R.splitBy._1)(H.segMap);if(R.splitBy.tag==="Nothing")return J;g()})();if(gt.tag==="Just")return{..._t,deps:_t.deps+2|0,crossings:(()=>{const yt=lt(T(lt)(1e18)(gt._1.incoming))(T(lt)(1e18)(gt._1.outgoing)),St=lt(T(lt)(1e18)(ct))(T(lt)(1e18)(R.outgoing)),Ht=ht(T(ht)(-1e18)(gt._1.incoming))(T(ht)(-1e18)(gt._1.outgoing)),pt=ht(T(ht)(-1e18)(ct))(T(ht)(-1e18)(R.outgoing)),Wt=lt(T(lt)(1e18)(R.incoming))(T(lt)(1e18)(Z));return _t.crossings+(()=>{const Tt=lt(T(lt)(1e18)(gt._1.incoming))(T(lt)(1e18)(gt._1.outgoing)),mt=ht(T(ht)(-1e18)(R.incoming))(T(ht)(-1e18)(Z)),ft=ht(T(ht)(-1e18)(gt._1.incoming))(T(ht)(-1e18)(gt._1.outgoing));return((T(ot=>dt=>dt>Ht?ot:dt>=yt?ot+1|0:ot)(0)(Z)+T(ot=>dt=>dt>mt?ot:dt>=Wt?ot+1|0:ot)(0)(gt._1.incoming)|0)+T(ot=>dt=>dt>pt?ot:dt>=St?ot+1|0:ot)(0)(gt._1.outgoing)|0)+T(ot=>dt=>dt>ft?ot:dt>=Tt?ot+1|0:ot)(0)(ct)|0})()|0})()};if(gt.tag==="Nothing")return _t;g()})()}))(F);return T(W=>K=>K.rating.crossings<W.rating.crossings||!(K.rating.crossings>W.rating.crossings)&&(K.rating.deps<W.rating.deps||!(K.rating.deps>W.rating.deps)&&K.c.a.size>W.c.a.size)?K:W)(0<Y.length?Y[0]:{c:I._1,rating:{crossings:1e6,deps:1e6}})(Y).c}g()})(),$={...R,incoming:Et(it.compare)(R.incoming),outgoing:Et(it.compare)([(z.a.startPosition+z.a.endPosition)/2]),splitPartner:w("Just",H.nextId)},X={id:H.nextId,incoming:Et(it.compare)([(z.a.startPosition+z.a.endPosition)/2]),mark:0,members:R.members,outgoing:Et(it.compare)(R.outgoing),slot:0,splitBy:J,splitPartner:w("Just",R.id)};return{segMap:tt(nt)(X.id)(X)(tt(nt)($.id)($)(H.segMap)),freeAreas:(()=>{if(z.i>=0&&z.i<H.freeAreas.length){const Y=Za(Ut,J,z.i,H.freeAreas),W=(()=>{if(Y.tag==="Nothing")return H.freeAreas;if(Y.tag==="Just")return Y._1;g()})();if(H.freeAreas[z.i].size/2<d)return W;const K=(H.freeAreas[z.i].startPosition+H.freeAreas[z.i].endPosition)/2,Z=K-d,ct=K+d;return[...z.i<1?[]:Lt(0,z.i,W),...H.freeAreas[z.i].startPosition<=Z?[{startPosition:H.freeAreas[z.i].startPosition,endPosition:Z,size:Z-H.freeAreas[z.i].startPosition}]:[],...ct<=H.freeAreas[z.i].endPosition?[{startPosition:ct,endPosition:H.freeAreas[z.i].endPosition,size:H.freeAreas[z.i].endPosition-ct}]:[],...z.i<1?W:Lt(z.i,W.length,W)]}return H.freeAreas})(),nextId:H.nextId+1|0}})({segMap:U,freeAreas:(()=>{const H=Et(it.compare)([...wt(l.segments)(R=>R.incoming),...wt(l.segments)(R=>R.outgoing)]);return xt(iy)(ve(R=>C=>C-R>=2*d?w("Just",{startPosition:R+d,endPosition:C-d,size:C-R-2*d}):J,H,Lt(1,H.length,H)))})(),nextId:l.segments.length})(Et(H=>R=>it.compare(ht(T(ht)(-1e18)(H.incoming))(T(ht)(-1e18)(H.outgoing))-lt(T(lt)(1e18)(H.incoming))(T(lt)(1e18)(H.outgoing)))(ht(T(ht)(-1e18)(R.incoming))(T(ht)(-1e18)(R.outgoing))-lt(T(lt)(1e18)(R.incoming))(T(lt)(1e18)(R.outgoing))))(xt(H=>It(H)(U))(V.decisions)));return{segments:(()=>{const H=(R,C)=>{if(R.tag==="Leaf")return C;if(R.tag==="Node")return H(R._5,$t("Cons",R._4,H(R._6,C)));g()};return Ct(Vt.foldr,H(M.segMap,Xt))})(),deps:(()=>{const H=M.segMap,R=(F,I)=>{if(F.tag==="Leaf")return I;if(F.tag==="Node")return R(F._5,$t("Cons",F._4,R(F._6,I)));g()},C=Ct(Vt.foldr,R(H,Xt)),D=C.length;return[...wt(wt(Ft(0,D-2|0))(F=>wt(Ft(F+1|0,D-1|0))(I=>[b(F,I)])))(F=>F._1>=0&&F._1<C.length?F._2>=0&&F._2<C.length?C[F._1].splitPartner.tag!=="Nothing"&&C[F._1].splitPartner.tag==="Just"&&C[F._1].splitPartner._1===C[F._2].id||C[F._2].splitPartner.tag!=="Nothing"&&C[F._2].splitPartner.tag==="Just"&&C[F._2].splitPartner._1===C[F._1].id?[]:o(d,C[F._1],C[F._2]):[]:[]),...wt(C)(F=>F.splitBy.tag==="Just"&&F.splitPartner.tag==="Just"&&(()=>{const I=It(F.splitPartner._1)(H);if(I.tag==="Nothing")return!1;if(I.tag==="Just")return!0;g()})()&&(()=>{const I=It(F.splitBy._1)(H);if(I.tag==="Nothing")return!1;if(I.tag==="Just")return!0;g()})()?[{src:F.id,tgt:F.splitBy._1,weight:1,kind:Yo},{src:F.splitBy._1,tgt:F.splitPartner._1,weight:1,kind:Yo}]:[])]})()}})(),p=h.segments,m=p.length,y=G=>{let P=G,V=!0,U;for(;V;){const M=P,H=Kt(R=>{const C=It(R)(M.inWeight);if(C.tag==="Nothing")return!0;if(C.tag==="Just")return C._1===0;g()})(M.remaining);if(H.tag==="Nothing"){V=!1,U=M;continue}if(H.tag==="Just"){const R=H._1;P={...M,inWeight:T(C=>D=>bt(nt)(se)(D.tgt)(-D.weight)(C))(M.inWeight)((()=>{const C=It(R)(M.depsBySrc);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;g()})()),marks:tt(nt)(R)(M.nextSource)(M.marks),nextSource:M.nextSource+1|0,outWeight:T(C=>D=>bt(nt)(se)(D.src)(-D.weight)(C))(M.outWeight)((()=>{const C=It(R)(M.depsByTgt);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;g()})()),remaining:at(C=>C!==R,M.remaining)};continue}g()}return U},x=G=>{let P=G,V=!0,U;for(;V;){const M=P,H=Kt(R=>{const C=It(R)(M.outWeight);if(C.tag==="Nothing")return!0;if(C.tag==="Just")return C._1===0;g()})(M.remaining);if(H.tag==="Nothing"){V=!1,U=M;continue}if(H.tag==="Just"){const R=H._1;P={...M,inWeight:T(C=>D=>bt(nt)(se)(D.tgt)(-D.weight)(C))(M.inWeight)((()=>{const C=It(R)(M.depsBySrc);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;g()})()),marks:tt(nt)(R)(M.nextSink)(M.marks),nextSink:M.nextSink-1|0,outWeight:T(C=>D=>bt(nt)(se)(D.src)(-D.weight)(C))(M.outWeight)((()=>{const C=It(R)(M.depsByTgt);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;g()})()),remaining:at(C=>C!==R,M.remaining)};continue}g()}return U},N=(G=>{let P=G,V=!0,U;for(;V;){const M=y(x(P));if(M.remaining.length===0){V=!1,U=O(H=>{const R=It(H.id)(M.marks),C=(()=>{if(R.tag==="Nothing")return H.id;if(R.tag==="Just")return R._1;g()})();return{...H,mark:C<m?(C+m|0)+1|0:C}})(p);continue}P=(()=>{const H=C=>{const D=It(C)(M.outWeight),F=It(C)(M.inWeight);return(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;g()})()-(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;g()})()|0},R=Et(C=>D=>nt.compare(H(D))(H(C)))(M.remaining);if(0<R.length){const C=R[0];return{...M,inWeight:T(D=>F=>bt(nt)(se)(F.tgt)(-F.weight)(D))(M.inWeight)((()=>{const D=It(C)(M.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),marks:tt(nt)(C)(M.nextSource)(M.marks),nextSource:M.nextSource+1|0,outWeight:T(D=>F=>bt(nt)(se)(F.src)(-F.weight)(D))(M.outWeight)((()=>{const D=It(C)(M.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),remaining:at(D=>D!==C,M.remaining)}}return M})()}return U})({remaining:O(G=>G.id)(p),marks:A,inWeight:T(G=>P=>bt(nt)(se)(P.tgt)(P.weight)(G))(A)(h.deps),outWeight:T(G=>P=>bt(nt)(se)(P.src)(P.weight)(G))(A)(h.deps),depsBySrc:T(G=>P=>bt(nt)(re)(P.src)([P])(G))(A)(h.deps),depsByTgt:T(G=>P=>bt(nt)(re)(P.tgt)([P])(G))(A)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),v=(()=>{const G=(()=>{const U=zr(O(M=>b(M.id,M.mark))(N));return{segments:N,deps:xt(M=>(()=>{if(M.kind==="Critical")return!0;if(M.kind==="Regular")return!1;g()})()?w("Just",M):(()=>{const H=It(M.src)(U),R=It(M.tgt)(U);return(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})()>(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})()})()?M.weight===0?J:w("Just",{src:M.tgt,tgt:M.src,weight:M.weight,kind:M.kind}):w("Just",M))(h.deps)}})(),P=T(U=>M=>bt(nt)(se)(M.tgt)(1)(U))(A)(G.deps),V=(U=>{let M=U,H=!0,R;for(;H;){const C=M,D=Qt(F=>J,F=>I=>w("Just",{head:F,tail:I}),C.queue);if(D.tag==="Nothing"){H=!1,R=C;continue}if(D.tag==="Just"){M=T((()=>{const F=It(D._1.head)(C.slots),I=(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;g()})();return z=>$=>{const X=It($)(z.inDegree),Y=(()=>{if(X.tag==="Nothing")return-1;if(X.tag==="Just")return X._1-1|0;g()})();return{...z,slots:tt(nt)($)(Wg((()=>{const W=It($)(z.slots);if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})())(I+1|0))(z.slots),inDegree:tt(nt)($)(Y)(z.inDegree),queue:Y===0?[...z.queue,$]:z.queue}}})())({...C,queue:D._1.tail})((()=>{const F=It(D._1.head)(C.adj);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})());continue}g()}return R})({slots:zr(O(U=>b(U.id,0))(G.segments)),inDegree:P,adj:T(U=>M=>bt(nt)(re)(M.src)([M.tgt])(U))(A)(G.deps),queue:O(U=>U.id)(at(U=>{const M=It(U.id)(P);if(M.tag==="Nothing")return!0;if(M.tag==="Just")return M._1===0;g()},G.segments))});return Et(U=>M=>nt.compare(U.slot)(M.slot))(O(U=>({...U,slot:(()=>{const M=It(U.id)(V.slots);if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()}))(G.segments))})(),k=1+T(G=>P=>Wg(G)(P.slot))(0)(v)|0,L=wt(v)(G=>G.members),E=at(G=>Ye(dn)(G.edge.id)(L),t),B=T(ht)(-1e18)(O(G=>G.fromPos._2)(E)),q=T(lt)(1e18)(O(G=>G.toPos._2)(E));if(B>q){const G=zr(O(P=>b(P.id,P))(v));return We(O(P=>O(V=>b(V,{slot:P.slot,slotCount:k,gapTop:q,gapBottom:B,partner:(()=>{if(P.splitPartner.tag==="Just"){const U=It(P.splitPartner._1)(G);if(U.tag==="Just")return w("Just",{slot:U._1.slot,splitX:0<U._1.incoming.length?U._1.incoming[0]:0});if(U.tag==="Nothing")return J;g()}if(P.splitPartner.tag==="Nothing")return J;g()})()}))(P.members))(at(P=>{if(P.splitPartner.tag==="Just"){const V=It(P.splitPartner._1)(G);return!(V.tag==="Just"&&(()=>{if(V._1.splitBy.tag==="Nothing")return!1;if(V._1.splitBy.tag==="Just")return!0;g()})())}if(P.splitPartner.tag==="Nothing")return!0;g()},v)))}const j=zr(O(G=>b(G.id,G))(v));return We(O(G=>O(P=>b(P,{slot:G.slot,slotCount:k,gapTop:B,gapBottom:q,partner:(()=>{if(G.splitPartner.tag==="Just"){const V=It(G.splitPartner._1)(j);if(V.tag==="Just")return w("Just",{slot:V._1.slot,splitX:0<V._1.incoming.length?V._1.incoming[0]:0});if(V.tag==="Nothing")return J;g()}if(G.splitPartner.tag==="Nothing")return J;g()})()}))(G.members))(at(G=>{if(G.splitPartner.tag==="Just"){const P=It(G.splitPartner._1)(j);return!(P.tag==="Just"&&(()=>{if(P._1.splitBy.tag==="Nothing")return!1;if(P._1.splitBy.tag==="Just")return!0;g()})())}if(G.splitPartner.tag==="Nothing")return!0;g()},v)))})()))(A)(ry(T(u=>s=>{const a=Hr(s.edge.from.node)(n);if(a.tag==="Just"){const c=Hr(s.edge.to.node)(n);return c.tag==="Just"&&a._1.layer!==c._1.layer?bt(nt)(re)(Wr(a._1.layer)(c._1.layer))([s])(u):u}return u})(A)((()=>{const u=s=>b((()=>{const a=Hr(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=Hr(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return Et(s=>a=>ny(u(s))(u(a)))(t)})())))},uy=t=>e=>{const n=Yg(t)(e),r=T(i=>o=>tt(S)(o.node)(o)(i))(A)(e);return T(i=>o=>{const u=Hr(o.edge.from.node)(r);if(u.tag==="Just"){const s=Hr(o.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=oy(o.edge.id)(n);if(a.tag==="Just")return tt(nt)(Wr(u._1.layer)(s._1.layer))(a._1.slotCount)(i)}return i}return i})(A)(t)},$g=zt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),fe=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},_e=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Di=t=>e=>n=>r=>$g(i=>n>=i.x&&n<i.x+i.w&&e>i.y&&t<i.y+i.h)(r),$o=t=>e=>n=>r=>Di(fe(e)(n))(_e(e)(n))(r)(t),qo=et(4),sy=ec(t=>{if(t.direction==="H"){const e=fe(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:_e(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=fe(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:_e(t.start._2)(t.end._2)-e}]}g()}),Ii=tc(t=>{const e=t.start._1-t.end._1;return!((e<0?-e<1e-6:e<1e-6)&&(()=>{const n=t.start._2-t.end._2;return n<0?-n<1e-6:n<1e-6})())}),ay=t=>e=>n=>{const r=Qt(i=>J,i=>o=>w("Just",{head:i,tail:o}),e);if(r.tag==="Nothing")return[{start:t.start,end:n.end,direction:t.direction}];if(r.tag==="Just"){const i=(r._1.head.direction==="H"?t.direction==="H":r._1.head.direction==="V"&&t.direction==="V")?[{start:t.start,end:r._1.head.end,direction:t.direction}]:[t,r._1.head],o=fr(r._1.tail);if(o.tag==="Nothing"){const u=i.length-1|0;return u>=0&&u<i.length&&(i[u].direction==="H"?n.direction==="H":i[u].direction==="V"&&n.direction==="V")?[...(()=>{const s=i.length-1|0;return s<1?[]:Lt(0,s,i)})(),{start:i[u].start,end:n.end,direction:n.direction}]:[...i,n]}if(o.tag==="Just")return(o._1.last.direction==="H"?n.direction==="H":o._1.last.direction==="V"&&n.direction==="V")?[...i,...o._1.init,{start:o._1.last.start,end:n.end,direction:n.direction}]:[...i,...r._1.tail,n]}g()},Ai=t=>{const e=r=>i=>{const o=Qt(u=>J,u=>s=>w("Just",{head:u,tail:s}),i);if(o.tag==="Nothing")return[r];if(o.tag==="Just")return(r.direction==="H"?o._1.head.direction==="H":r.direction==="V"&&o._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==o._1.head.end._1-o._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==o._1.head.end._2-o._1.head.start._2>=0;g()})()?e({start:r.start,end:o._1.head.end,direction:r.direction})(o._1.tail):[r,...e(o._1.head)(o._1.tail)];g()},n=Qt(r=>J,r=>i=>w("Just",{head:r,tail:i}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);g()},Fi=t=>e=>n=>r=>$g(i=>n>=i.y&&n<i.y+i.h&&e>i.x&&t<i.x+i.w)(r),Bi=t=>e=>n=>r=>Fi(fe(e)(n))(_e(e)(n))(r)(t),cy=t=>e=>n=>r=>{const i=n+2|0,o=i<1?e:Lt(i,e.length,e),u=n<1?[]:Lt(0,n,e),s=(n+1|0)===(r-1|0),a=n===0,c=n>=0&&n<e.length?w("Just",e[n]):J;if(c.tag==="Just"){const f=n+1|0,d=f>=0&&f<e.length?w("Just",e[f]):J;if(d.tag==="Just"){const l=c._1.start._1===d._1.end._1&&(!a||c._1.direction==="V")&&(!s||d._1.direction==="V")&&!$o(t)(fe(c._1.start._2)(d._1.end._2))(_e(c._1.start._2)(d._1.end._2))(c._1.start._1)?w("Just",[...u,{start:c._1.start,end:d._1.end,direction:oe},...o]):J,_=c._1.start._2===d._1.end._2&&(!a||c._1.direction==="H")&&(!s||d._1.direction==="H")&&!Bi(t)(fe(c._1.start._1)(d._1.end._1))(_e(c._1.start._1)(d._1.end._1))(c._1.start._2)?w("Just",[...u,{start:c._1.start,end:d._1.end,direction:ie},...o]):J;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return J;g()}if(c.tag==="Nothing")return J;g()},gy=t=>e=>{const n=e.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+1|0)>=n){o=!1,u=e;continue}const a=cy(t)(e)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}g()}return u})(0)},fy=t=>e=>n=>r=>{const i=(l,_,h)=>!$o(t)(fe(_)(h))(_e(_)(h))(l),o=n+3|0,u=o<1?e:Lt(o,e.length,e),s=n<1?[]:Lt(0,n,e),a=(n+2|0)===(r-1|0),c=n===0,f=(l,_,h)=>!Bi(t)(fe(_)(h))(_e(_)(h))(l),d=n>=0&&n<e.length?w("Just",e[n]):J;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<e.length?w("Just",e[l]):J;if(_.tag==="Just"){const h=d._1.start._1===_._1.end._1&&(!c||d._1.direction==="V")&&(!a||_._1.direction==="V")&&i(d._1.start._1,d._1.start._2,_._1.end._2)?w("Just",[...s,{start:d._1.start,end:_._1.end,direction:oe},...u]):d._1.start._2===_._1.end._2&&(!c||d._1.direction==="H")&&(!a||_._1.direction==="H")&&f(d._1.start._2,d._1.start._1,_._1.end._1)?w("Just",[...s,{start:d._1.start,end:_._1.end,direction:ie},...u]):J,p=(!c||d._1.direction==="V")&&(!a||_._1.direction==="H")&&i(d._1.start._1,d._1.start._2,_._1.end._2)&&f(_._1.end._2,d._1.start._1,_._1.end._1)?w("Just",[...s,{start:d._1.start,end:b(d._1.start._1,_._1.end._2),direction:oe},{start:b(d._1.start._1,_._1.end._2),end:_._1.end,direction:ie},...u]):J,m=(!c||d._1.direction==="H")&&(!a||_._1.direction==="V")&&f(d._1.start._2,d._1.start._1,_._1.end._1)&&i(_._1.end._1,d._1.start._2,_._1.end._2)?w("Just",[...s,{start:d._1.start,end:b(_._1.end._1,d._1.start._2),direction:ie},{start:b(_._1.end._1,d._1.start._2),end:_._1.end,direction:oe},...u]):J,y=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?y:h}if(_.tag==="Nothing")return J;g()}if(d.tag==="Nothing")return J;g()},_y=t=>e=>{const n=e.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+2|0)>=n){o=!1,u=e;continue}const a=fy(t)(e)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}g()}return u})(0)},dy=t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r,s=Ai(Ii(gy(t)(_y(t)(u))));if(s.length<u.length){r=s;continue}i=!1,o=s}return o};return n=>e(Ai(Ii(n)))},ly=t=>e=>n=>r=>{const i=fe(n)(r),o=_e(n)(r),u=at(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=Et(c=>f=>it.compare(c.x)(f.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=Et(a=>c=>it.compare(c.x)(a.x))(O(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},hy=t=>e=>n=>r=>{const i=fe(n)(r),o=_e(n)(r),u=at(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=Et(c=>f=>it.compare(c.y)(f.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=Et(a=>c=>it.compare(c.y)(a.y))(O(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},py=t=>e=>n=>r=>{const i=fe(n)(r),o=_e(n)(r),u=at(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=Et(c=>f=>it.compare(f.x)(c.x))(O(c=>({...c,x:c.x+c.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=Et(a=>c=>it.compare(a.x)(c.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},my=t=>e=>n=>r=>{const i=fe(n)(r),o=_e(n)(r),u=at(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=Et(c=>f=>it.compare(f.y)(c.y))(O(c=>({...c,y:c.y+c.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=Et(a=>c=>it.compare(a.y)(c.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},qg=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,c=i,f=o;if(f>100){u=!1,s=c;continue}if(!a(c+f)){u=!1,s=c+f;continue}if(!a(c-f)){u=!1,s=c-f;continue}r=a,i=c,o=f+1}return s},Xg=t=>e=>n=>r=>i=>{const o=fe(e)(n),u=_e(e)(n);if(!Di(o)(u)(r)(t))return r;if(!Di(o)(u)(i)(t))return i;const s=(r+i)/2;return Di(o)(u)(s)(t)?qg(a=>Di(o)(u)(a)(t))(s)(1):s},yy=t=>e=>n=>r=>i=>{const o=fe(e)(n),u=_e(e)(n);if(!Fi(o)(u)(r)(t))return r;if(!Fi(o)(u)(i)(t))return i;const s=(r+i)/2;return Fi(o)(u)(s)(t)?qg(a=>Fi(o)(u)(a)(t))(s)(1):s},xy=t=>e=>n=>r=>{const i=fe(e)(n),o=_e(e)(n),u=at(c=>r>=c.x&&r<c.x+c.w&&c.y+c.h>i&&c.y<o,t),s=T(c=>f=>_e(c)(f.x+f.w+4))(r+4)(u),a=T(c=>f=>fe(c)(f.x-4))(r-4)(u);return(()=>{const c=s-r,f=a-r;return(c<0?-c:c)<=(f<0?-f:f)})()?s:a},Ny=t=>e=>n=>r=>{const i=fe(e)(n),o=_e(e)(n),u=at(c=>r>=c.y&&r<c.y+c.h&&c.x+c.w>i&&c.x<o,t),s=T(c=>f=>_e(c)(f.y+f.h+4))(r+4)(u),a=T(c=>f=>fe(c)(f.y-4))(r-4)(u);return(()=>{const c=s-r,f=a-r;return(c<0?-c:c)<=(f<0?-f:f)})()?s:a},Jy=t=>e=>n=>r=>i=>o=>u=>{const s=(()=>{if(r==="South")return b(i._1,i._2+4);if(r==="North")return b(i._1,i._2-4);if(r==="East")return b(i._1+4,i._2);if(r==="West")return b(i._1-4,i._2);g()})(),a=(()=>{if(o==="South")return b(u._1,u._2+4);if(o==="North")return b(u._1,u._2-4);if(o==="East")return b(u._1+4,u._2);if(o==="West")return b(u._1-4,u._2);g()})(),c=(k,L,E)=>!$o(e)(fe(L)(E))(_e(L)(E))(k),f=(k,L,E)=>!$o(n)(fe(L)(E))(_e(L)(E))(k),d=(k,L,E,B)=>t.tag==="Just"&&!Bi(n)(fe(k)(L))(_e(k)(L))(t._1)?t._1:yy(e)(k)(L)(E)(B),l=(k,L,E,B)=>{if(k===E){const j=xy(e)(L)(B)(k),G=hy(e)(k)(L)(B),P=my(e)(k)(L)(B);return[{start:b(k,L),end:b(k,G),direction:oe},{start:b(k,G),end:b(j,G),direction:ie},{start:b(j,G),end:b(j,P),direction:oe},{start:b(j,P),end:b(E,P),direction:ie},{start:b(E,P),end:b(E,B),direction:oe}]}const q=d(k,E,L,B);return[{start:b(k,L),end:b(k,q),direction:oe},{start:b(k,q),end:b(E,q),direction:ie},{start:b(E,q),end:b(E,B),direction:oe}]},_=(k,L,E,B)=>{if(L===B){const j=Ny(e)(k)(E)(L),G=ly(e)(L)(k)(E),P=py(e)(L)(k)(E);return[{start:b(k,L),end:b(G,L),direction:ie},{start:b(G,L),end:b(G,j),direction:oe},{start:b(G,j),end:b(P,j),direction:ie},{start:b(P,j),end:b(P,B),direction:oe},{start:b(P,B),end:b(E,B),direction:ie}]}const q=Xg(e)(L)(B)(k)(E);return[{start:b(k,L),end:b(q,L),direction:ie},{start:b(q,L),end:b(q,B),direction:oe},{start:b(q,B),end:b(E,B),direction:ie}]},h=(k,L,E)=>!Bi(e)(fe(L)(E))(_e(L)(E))(k),p=(k,L,E)=>!Bi(n)(fe(L)(E))(_e(L)(E))(k),m=(k,L,E,B)=>{if(p(L,k,E)&&f(E,L,B))return[{start:b(k,L),end:b(E,L),direction:ie},{start:b(E,L),end:b(E,B),direction:oe}];const q=Xg(e)(L)(B)(k)(E);return[{start:b(k,L),end:b(q,L),direction:ie},{start:b(q,L),end:b(q,B),direction:oe},{start:b(q,B),end:b(E,B),direction:ie}]},y=(k,L,E,B)=>{if(f(k,L,B)&&p(B,k,E))return[{start:b(k,L),end:b(k,B),direction:oe},{start:b(k,B),end:b(E,B),direction:ie}];const q=d(k,E,L,B);return[{start:b(k,L),end:b(k,q),direction:oe},{start:b(k,q),end:b(E,q),direction:ie},{start:b(E,q),end:b(E,B),direction:oe}]},x=(()=>{if(r==="South")return o==="North"?s._1===a._1&&c(s._1,s._2,a._2)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:oe}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?y(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="North")return o==="South"?s._1===a._1&&c(s._1,s._2,a._2)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:oe}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?y(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="East")return o==="West"?s._2===a._2&&h(s._2,s._1,a._1)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:ie}]:_(s._1,s._2,a._1,a._2):o==="North"||o==="South"?m(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="West"){if(o==="East")return s._2===a._2&&h(s._2,s._1,a._1)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:ie}]:_(s._1,s._2,a._1,a._2);if(o==="North"||o==="South")return m(s._1,s._2,a._1,a._2)}return l(s._1,s._2,a._1,a._2)})(),N=(()=>{if(r==="South"||r==="North")return oe;if(r==="East"||r==="West")return ie;g()})(),v={start:b(a._1,a._2),end:b(u._1,u._2),direction:(()=>{if(o==="South"||o==="North")return oe;if(o==="East"||o==="West")return ie;g()})()};return s._1===a._1&&s._2===a._2?[{start:b(i._1,i._2),end:b(u._1,u._2),direction:N}]:ay({start:b(i._1,i._2),end:b(s._1,s._2),direction:N})(x)(v)},Ty=O(t=>({x:t.position._1*qo-2,y:t.position._2*qo-2,w:t.size._1*qo+4,h:t.size._2*qo+4})),Qs=te(S)(zt),Rn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Rs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},wy=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t._1)(o._3._1);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(t._2==="North"){if(o._3._2==="North"){r=!1,i=w("Just",o._4);continue}n=o._5;continue}if(o._3._2==="North"){n=o._6;continue}if(t._2==="South"){if(o._3._2==="South"){r=!1,i=w("Just",o._4);continue}n=o._5;continue}if(o._3._2==="South"){n=o._6;continue}if(t._2==="East"){if(o._3._2==="East"){r=!1,i=w("Just",o._4);continue}n=o._5;continue}if(o._3._2==="East"){n=o._6;continue}if(t._2==="West"&&o._3._2==="West"){r=!1,i=w("Just",o._4);continue}}g()}return i},Vg=t=>e=>{const n=e.position._1+e.size._1,r=e.position._2*2+e.size._2,i=e.position._1*2+e.size._1,o=e.position._2+e.size._2;if(t==="South")return b(i,o*2);if(t==="North")return b(i,e.position._2*2);if(t==="East")return b(n*2,r);if(t==="West")return b(e.position._1*2,r);g()},Ms=t=>e=>{const n=et(4);if(t==="South")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="North")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="East")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};if(t==="West")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};g()},Ug=t=>e=>T(n=>r=>bt(t)(re)(e(r))([r])(n))(A),Kg=t=>e=>n=>r=>{const i=(t==="South"||t==="North")&&(e==="East"||e==="West")&&(()=>{if(t==="South")return r._2>n._2;if(t==="North")return r._2<n._2;if(t==="East")return r._2>n._2;if(t==="West")return r._2<n._2;g()})()&&(()=>{if(e==="East")return n._1>r._1;if(e==="West"||e==="North")return n._1<r._1;if(e==="South")return n._1>r._1;g()})(),o=(t==="East"||t==="West")&&(e==="North"||e==="South")&&(()=>{if(t==="South")return r._1>n._1;if(t==="North")return r._1<n._1;if(t==="East")return r._1>n._1;if(t==="West")return r._1<n._1;g()})()&&(()=>{if(e==="East")return n._2>r._2;if(e==="West"||e==="North")return n._2<r._2;if(e==="South")return n._2>r._2;g()})();return(t==="South"?e==="North"&&n._1===r._1&&r._2>n._2:t==="North"?e==="South"&&n._1===r._1&&r._2<n._2:t==="East"?e==="West"&&n._2===r._2&&r._1>n._1:t==="West"&&e==="East"&&n._2===r._2&&r._1<n._1)?0:i||o?1:2},Zg=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,i=e.length;return i===0?A:Qs(i===1?O(o=>b(o,r))(e):Bt(o=>u=>b(u,t.lo+et(o+1|0)*n/et(i+1|0)))(e))},jg=t=>e=>n=>r=>i=>{const o=Ug(S)(_=>_.to.node)(t),u=Ug(S)(_=>_.from.node)(t),s=T(_=>h=>tt(S)(h.node)(h)(_))(A)(e),a=(_,h,p)=>{const m=Rn(_)(s);if(m.tag==="Nothing")return b(0,0);if(m.tag==="Just"){const y=Rn(_)(n);if(y.tag==="Nothing"){const x=et(4);if(p==="South")return b(m._1.position._1*x+m._1.size._1*x/2,(m._1.position._2+m._1.size._2)*x);if(p==="North")return b(m._1.position._1*x+m._1.size._1*x/2,m._1.position._2*x);if(p==="East")return b((m._1.position._1+m._1.size._1)*x,m._1.position._2*x+m._1.size._2*x/2);if(p==="West")return b(m._1.position._1*x,m._1.position._2*x+m._1.size._2*x/2);g()}if(y.tag==="Just"){const x=Kt(N=>N.id===h)(y._1);if(x.tag==="Nothing"){const N=et(4);if(p==="South")return b(m._1.position._1*N+m._1.size._1*N/2,(m._1.position._2+m._1.size._2)*N);if(p==="North")return b(m._1.position._1*N+m._1.size._1*N/2,m._1.position._2*N);if(p==="East")return b((m._1.position._1+m._1.size._1)*N,m._1.position._2*N+m._1.size._2*N/2);if(p==="West")return b(m._1.position._1*N,m._1.position._2*N+m._1.size._2*N/2);g()}if(x.tag==="Just"){const N=et(4);if(x._1.side==="North")return b(m._1.position._1*N+et(x._1.offset)*N,m._1.position._2*N);if(x._1.side==="South")return b(m._1.position._1*N+et(x._1.offset)*N,(m._1.position._2+m._1.size._2)*N);if(x._1.side==="East")return b((m._1.position._1+m._1.size._1)*N,m._1.position._2*N+et(x._1.offset)*N);if(x._1.side==="West")return b(m._1.position._1*N,m._1.position._2*N+et(x._1.offset)*N)}}}g()},c=Qs(wt(r)(_=>{if(_.nodes.length<=2)return[];const h=et(4);if(1<_.nodes.length){const p=Rn(_.nodes[1])(s);if(p.tag==="Nothing")return[];if(p.tag==="Just"){const m=p._1.position._1*h+p._1.size._1*h/2;return O(y=>b(y,m))(ve(y=>x=>_.edgeId+":"+y+"->"+x,_.nodes,Lt(1,_.nodes.length,_.nodes)))}g()}return[]})),f=_=>{const h=Rn(_.from.node)(s),p=Rn(_.to.node)(s);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,y=p._1,x=Et(N=>v=>nt.compare(N.score)(v.score))(O(N=>{const v=N._1,k=N._2;return{from:v,to:k,score:(()=>{const L=(j,G,P,V,U)=>{const M=Ms(j)(G),H=Ms(j)(P);return M.lo<H.hi&&H.lo<M.hi&&(v==="South"?k==="North"&&U._2>V._2:v==="North"?k==="South"&&U._2<V._2:v==="East"?k==="West"&&U._1>V._1:v==="West"&&k==="East"&&U._1<V._1)?0:Kg(v)(k)(V)(U)},E=Vg(v)(m),B=Vg(k)(y),q=Kg(v)(k)(E)(B);return(()=>{if(q>0){if(v==="South")return k==="North"?L(he,m,y,E,B)*10|0:q*10|0;if(v==="North")return k==="South"?L(le,m,y,E,B)*10|0:q*10|0;if(v==="East")return k==="West"?L(An,m,y,E,B)*10|0:q*10|0;if(v==="West"&&k==="East")return L(Fn,m,y,E,B)*10|0}return q*10|0})()+(v==="South"?k==="North"?0:15:v==="North"?k==="South"?0:15:v==="East"?k==="West"?5:15:v==="West"&&k==="East"?5:15)|0})()}})([b(he,le),b(An,le),b(Fn,le),b(he,An),b(he,Fn),b(le,he),b(le,An),b(le,Fn),b(An,he),b(Fn,he),b(An,Fn),b(Fn,An)]));if(0<x.length)return{from:x[0].from,to:x[0].to}}return{from:he,to:le}},d=Qs(O(_=>b(_.id,f(_)))(t)),l=(_,h,p,m,y,x)=>{const N=et(4),v=Rn(h)(s);if(v.tag==="Nothing")return b(0,0);if(v.tag==="Just"){const k=wy(b(p,_))(i);if(k.tag==="Just"){const L=v._1.position._1*N+k._1,E=et(4);if(_==="South")return b(L,(v._1.position._2+v._1.size._2)*E);if(_==="North")return b(L,v._1.position._2*E);if(_==="East")return b((v._1.position._1+v._1.size._1)*E,L);if(_==="West")return b(v._1.position._1*E,L);g()}if(k.tag==="Nothing"){const L=Ms(_)(v._1),E=(L.lo+L.hi)/2,B=Rs(p)(Zg(L)(O(G=>G.id)(Et(G=>P=>it.compare(y(_)(G))(y(_)(P)))(at(G=>{const P=Rs(G.id)(d);if(P.tag==="Just"){const V=x(P._1);return V==="North"?_==="North":V==="South"?_==="South":V==="East"?_==="East":V==="West"&&_==="West"}if(P.tag==="Nothing")return!0;g()},(()=>{const G=Rn(h)(m);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()))))),q=(()=>{if(B.tag==="Nothing")return E;if(B.tag==="Just")return B._1;g()})(),j=et(4);if(_==="South")return b(q,(v._1.position._2+v._1.size._2)*j);if(_==="North")return b(q,v._1.position._2*j);if(_==="East")return b((v._1.position._1+v._1.size._1)*j,q);if(_==="West")return b(v._1.position._1*j,q)}}g()};return O(_=>{const h=Rs(_.edge.id)(c);if(h.tag==="Nothing")return _;if(h.tag==="Just")return{..._,fromPos:ye(3)(_.edge.from.node)==="$d:"?b(h._1,_.fromPos._2):_.fromPos,toPos:ye(3)(_.edge.to.node)==="$d:"?b(h._1,_.toPos._2):_.toPos};g()})(O(_=>{if(_.from.port.tag==="Just"&&_.to.port.tag==="Just")return{edge:_,fromPos:a(_.from.node,_.from.port._1,he),toPos:a(_.to.node,_.to.port._1,le),fromSide:he,toSide:le};const h=f(_);return{edge:_,fromPos:l(h.from,_.from.node,_.id,u,p=>m=>{const y=Rn(m.to.node)(s);if(y.tag==="Nothing")return 0;if(y.tag==="Just"){const x=et(4);if(p==="South"||p==="North")return y._1.position._1*x+y._1.size._1*x/2;if(p==="East"||p==="West")return y._1.position._2*x+y._1.size._2*x/2}g()},p=>p.from),toPos:l(h.to,_.to.node,_.id,o,p=>m=>{const y=Rn(m.from.node)(s);if(y.tag==="Nothing")return 0;if(y.tag==="Just"){const x=et(4);if(p==="South"||p==="North")return y._1.position._1*x+y._1.size._1*x/2;if(p==="East"||p==="West")return y._1.position._2*x+y._1.size._2*x/2}g()},p=>p.to),fromSide:h.from,toSide:h.to}})(t))},tf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Or=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},vy=(()=>{const t=Ue.unfoldr(xn);return e=>t(Ke("IterNode",e,yn))})(),zs=t=>e=>t.gapTop+1*et(4)+et(e)*2.5*et(4),by=t=>e=>{const n=tf(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return w("Just",{slot1Y:zs(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:zs(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return J;g()}if(n.tag==="Nothing")return J;g()},ky=t=>e=>{const n=T(r=>i=>tt(S)(i.node)(i)(r))(A)(e);return We(Bt(r=>i=>{const o=Or(i.node)(n);if(o.tag==="Nothing")return[];if(o.tag==="Just"){const u=o._1;return Bt(s=>a=>{const c=i.edges.length,f=et(4),d=u.position._1*f,l=u.position._2*f,_=u.size._2*f,h=et((2*c|0)+1|0),p=l+_*et(c-s|0)/h,m=l+_*et((c+1|0)+s|0)/h,y=d-f*2.5*et(s+1|0),x=[{start:b(d,p),end:b(y,p),direction:ie},{start:b(y,p),end:b(y,m),direction:oe},{start:b(y,m),end:b(d,m),direction:ie}];return{edge:a.id,segments:x,bends:ve(N=>v=>N.end,x,Lt(1,3,x)),bendType:[],jumps:[],reversed:!1}})(i.edges)}g()})(O(r=>({node:r._1,edges:r._2}))(vy(T(r=>i=>bt(S)(re)(i.from.node)([i])(r))(A)(t)))))},Ly=t=>e=>{const n=T(o=>u=>tt(S)(u.node)(u)(o))(A)(e),r=o=>{const u=Or(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.position._1;g()},i=o=>{const u=Or(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.layer;g()};return Et(o=>u=>{const s=nt.compare(i(o.edge.from.node))(i(u.edge.from.node));if(s==="EQ"){const a=it.compare(r(o.edge.from.node))(r(u.edge.from.node));return a==="EQ"?it.compare(r(o.edge.to.node))(r(u.edge.to.node)):a}return s})(t)},Re=t=>{const e=et(4);return{x:t.position._1*e-2,y:t.position._2*e-2,w:t.size._1*e+4,h:t.size._2*e+4}},Ey=t=>t.from.node===t.to.node,Cy=t=>e=>n=>r=>{const i=dy(n)(Jy(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:i,bends:ve(o=>u=>o.end,i,Lt(1,i.length,i)),bendType:[],jumps:[],reversed:!1}},Sy=t=>e=>n=>r=>{const i=[{start:b(r.fromPos._1,r.fromPos._2),end:b(r.fromPos._1,t.slot1Y),direction:oe},{start:b(r.fromPos._1,t.slot1Y),end:b(t.splitX,t.slot1Y),direction:ie},{start:b(t.splitX,t.slot1Y),end:b(t.splitX,t.slot2Y),direction:oe},{start:b(t.splitX,t.slot2Y),end:b(r.toPos._1,t.slot2Y),direction:ie},{start:b(r.toPos._1,t.slot2Y),end:b(r.toPos._1,r.toPos._2),direction:oe}];return{edge:r.edge.id,segments:i,bends:ve(o=>u=>o.end,i,Lt(1,5,i)),bendType:[],jumps:[],reversed:!1}},Gy=t=>e=>n=>{const r=Or(t.edge.from.node)(n);if(r.tag==="Just"){const o=Or(t.edge.to.node)(n);return o.tag==="Just"?at(u=>!(u.h===Re(r._1).h&&u.w===Re(r._1).w&&u.x===Re(r._1).x&&u.y===Re(r._1).y)&&!(u.h===Re(o._1).h&&u.w===Re(o._1).w&&u.x===Re(o._1).x&&u.y===Re(o._1).y),e):at(u=>!(u.h===Re(r._1).h&&u.w===Re(r._1).w&&u.x===Re(r._1).x&&u.y===Re(r._1).y),e)}const i=Or(t.edge.to.node)(n);return i.tag==="Just"?at(o=>!(o.h===Re(i._1).h&&o.w===Re(i._1).w&&o.x===Re(i._1).x&&o.y===Re(i._1).y),e):at(o=>!0,e)},Py=t=>e=>{const n=tf(e.edge.id)(t);if(n.tag==="Just")return w("Just",zs(n._1)(n._1.slot));if(n.tag==="Nothing")return J;g()},Dy=t=>e=>n=>r=>i=>{const o=T(c=>f=>tt(S)(f.node)(f)(c))(A)(e),u=Ty(e),s=jg(at(c=>c.from.node!==c.to.node,t))(e)(n)(r)(i),a=Yg(s)(e);return[...ky(at(Ey,t))(e),...T(c=>f=>{const d=Gy(f)(u)(o),l=[...d,...c.edgeObstacles],_=by(a)(f),h=(()=>{if(_.tag==="Just")return Sy(_._1)(d)(l)(f);if(_.tag==="Nothing")return Cy(Py(a)(f))(d)(l)(f);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...sy(h.segments)]}})({results:[],edgeObstacles:[]})(Ly(s)(e)).results]},ir=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},or=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Iy=t=>e=>n=>{if(t.start._1!==e.start._1)return J;const r=or(ir(t.start._2)(t.end._2))(ir(e.start._2)(e.end._2)),i=ir(or(t.start._2)(t.end._2))(or(e.start._2)(e.end._2));return r<i?w("Just",{position:b(t.start._1,(r+i)/2),crossingEdge:n}):J},Ay=t=>e=>n=>{if(t.start._2!==e.start._2)return J;const r=or(ir(t.start._1)(t.end._1))(ir(e.start._1)(e.end._1)),i=ir(or(t.start._1)(t.end._1))(or(e.start._1)(e.end._1));return r<i?w("Just",{position:b((r+i)/2,t.start._2),crossingEdge:n}):J},Fy=t=>e=>n=>{if(t.direction==="H")return Ay(t)(e)(n);if(t.direction==="V")return Iy(t)(e)(n);g()},By=t=>e=>n=>{const r=t+1|0,i=r<1?n:Lt(r,n.length,n);return wt(e.segments)(o=>wt(i)(u=>xt(s=>Fy(o)(s)(u.edge))(at(s=>s.direction==="H"?o.direction==="H":s.direction==="V"&&o.direction==="V",u.segments))))},Qy=t=>e=>n=>e.start._1>ir(t.start._1)(t.end._1)&&e.start._1<or(t.start._1)(t.end._1)&&t.start._2>ir(e.start._2)(e.end._2)&&t.start._2<or(e.start._2)(e.end._2)?w("Just",{position:b(e.start._1,t.start._2),crossingEdge:n}):J,Ry=t=>e=>wt(at(n=>n.direction==="H",t.segments))(n=>wt(e)(r=>xt(i=>Qy(n)(i)(r.edge))(at(i=>i.direction==="V",r.segments)))),My=t=>e=>n=>[...Ry(e)(at(r=>r.edge!==e.edge,n)),...By(t)(e)(n)],ef=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},nf=t=>ye(3)(t)==="$d:",zy=t=>e=>n=>T(r=>i=>{const o=ef(i.from.node)(t),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})(),s=ef(i.to.node)(t),a=(()=>{if(s.tag==="Nothing")return-u;if(s.tag==="Just")return s._1-u|0;g()})();if(a<=1)return{...r,edges:[...r.edges,i],chains:[...r.chains,{edgeId:i.id,nodes:[i.from.node,i.to.node]}]};const c=i.id,f=O(l=>"$d:"+c+":"+ee(l))(Ft(1,a-1|0)),d=[i.from.node,...f,i.to.node];return{...r,layers:T(l=>_=>{const h=_._2,p=fd(u+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;g()})(r.layers)(ve(Pn,Ft(1,a-1|0),f)),edges:[...r.edges,...ve(l=>_=>({id:c+":"+l+"->"+_,from:{node:l,port:i.from.port},to:{node:_,port:i.to.port},label:J}),d,Lt(1,d.length,d))],chains:[...r.chains,{edgeId:i.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),Xo=(()=>{const t={eq:e=>n=>e._1===n._1&&(e._2==="North"?n._2==="North":e._2==="South"?n._2==="South":e._2==="East"?n._2==="East":e._2==="West"&&n._2==="West")};return{compare:e=>n=>{const r=S.compare(e._1)(n._1);if(r==="LT")return Je;if(r==="GT")return Te;if(e._2==="North")return n._2==="North"?De:Je;if(n._2==="North")return Te;if(e._2==="South")return n._2==="South"?De:Je;if(n._2==="South")return Te;if(e._2==="East")return n._2==="East"?De:Je;if(n._2==="East")return Te;if(e._2==="West"&&n._2==="West")return De;g()},Eq0:()=>t}})(),Hy=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=Xo.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Wy=te(S)(zt),Hs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Oy=te(Xo)(zt),rf=(()=>{const t=Ue.unfoldr(xn);return e=>t(Ke("IterNode",e,yn))})(),Yr=t=>e=>n=>r=>{const i=Hy(b(e,n))(t);if(i.tag==="Nothing")return r;if(i.tag==="Just")return i._1;g()},of=t=>e=>n=>{const r=Wy(We(O(u=>Bt(s=>a=>b(a,s))(u))(t))),i=(u,s)=>{if(u==="South"){const a=Hs(s.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()}if(u==="North"){const a=Hs(s.from.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()}return 0},o=u=>T(s=>a=>Se(Xo.compare,Ee,Oy(O(c=>b(b(c._1,u),c._2))(rf(Zg({lo:0,hi:(()=>{const c=Hs(a._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return ye(3)(a._1)==="$d:"?0:1;g()})()})(O(c=>c.id)(Et(c=>f=>nt.compare(i(u,c))(i(u,f)))(a._2)))))),s))(A)(rf(T(s=>a=>a.from.node===a.to.node?s:u==="South"?bt(S)(re)(a.from.node)([a])(s):u==="North"?bt(S)(re)(a.to.node)([a])(s):s)(A)(e)));return Se(Xo.compare,Ee,o(le),o(he))},uf=t=>t,sf=t=>t,af=t=>t,Yy=T(t=>e=>tt(S)(e)()(t))(A),$y=(()=>{const t=Ue.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return w("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,$t("Cons",r._3,n(r._6,i)));g()};return n(e,Xt)})())})(),rt=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},on=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Tn=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},wn=te(S)(zt),Ws=sc(S),Os=(()=>{const t=Ue.unfoldr(xn);return e=>t(Ke("IterNode",e,yn))})(),qy=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Xy=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},cf=af("VDown"),gf=af("VUp"),Vy=sf("ForwardPhase"),Uy=sf("StackPhase"),ff=uf("HRight"),_f=uf("HLeft"),df=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Ky=t=>e=>n=>{const r=T(u=>s=>bt(S)(se)(s.tgt)(1)(u))(A)(t),i=$y(Yy([...O(u=>u.src)(t),...O(u=>u.tgt)(t),...(()=>{const u=(s,a)=>{if(s.tag==="Leaf")return a;if(s.tag==="Node")return u(s._5,$t("Cons",s._4,u(s._6,a)));g()};return Ct(Vt.foldr,u(e,Xt))})()])),o=T(u=>s=>bt(S)(re)(s.src)([{target:s.tgt,sep:s.sep}])(u))(A)(t);return(u=>s=>a=>{let c=u,f=s,d=a,l=!0,_;for(;l;){const h=c,p=f,m=d,y=Qt(x=>J,x=>N=>w("Just",{head:x,tail:N}),h);if(y.tag==="Nothing"){l=!1,_=m;continue}if(y.tag==="Just"){const x=rt(y._1.head)(m),N=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})(),v=T(k=>L=>{const E=rt(L.target)(k.result),B=N+L.sep,q=rt(L.target)(k.indeg),j=(()=>{if(q.tag==="Nothing")return-1;if(q.tag==="Just")return q._1-1|0;g()})();return{newQueue:j===0?[...k.newQueue,L.target]:k.newQueue,result:tt(S)(L.target)((()=>{if(E.tag==="Nothing")return B;if(E.tag==="Just"){if(n==="VDown")return on(E._1)(B);if(n==="VUp")return Tn(E._1)(B)}g()})())(k.result),indeg:tt(S)(L.target)(j)(k.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const k=rt(y._1.head)(o);if(k.tag==="Nothing")return[];if(k.tag==="Just")return k._1;g()})());c=[...y._1.tail,...v.newQueue],f=v.indeg,d=v.result;continue}g()}return _})(at(u=>{const s=rt(u)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;g()},i))(r)(T(u=>s=>tt(S)(s)(0)(u))(A)(i))},Zy=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,$t("Cons",o._4,e(o._6,u)));g()},n=Ct(Vt.foldr,e(t,Xt)),r=T(on)(999999)(n);if(r===0||n.length===0)return t;const i=o=>{if(o.tag==="Leaf")return A;if(o.tag==="Node")return Yt("Node",o._1,o._2,o._3,o._4-r,i(o._5),i(o._6));g()};return i(t)},lf=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,$t("Cons",o._4,e(o._6,u)));g()},n=e(t,Xt),r=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l.tag==="Nil"){c=!1,f=d;continue}if(l.tag==="Cons"){s=Tn(d)(l._1),a=l._2;continue}g()}return f},i=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l.tag==="Nil"){c=!1,f=d;continue}if(l.tag==="Cons"){s=on(d)(l._1),a=l._2;continue}g()}return f};return r(-999999)(n)-i(999999)(n)},Qi=t=>e=>(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(a===e){u=!1,s=c;continue}i=(()=>{const f=rt(a)(t.align);if(f.tag==="Nothing")return e;if(f.tag==="Just")return f._1;g()})(),o=[...c,a]}return s})((()=>{const n=rt(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;g()})())([e]),jy=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>{const d=(C,D,F)=>{const I=C.from.node===D?C.from.port:C.to.node===D?C.to.port:J;if(I.tag==="Just"){const z=rt(D)(i);if(z.tag==="Just"){const $=Kt(X=>X.id===I._1)(z._1);if($.tag==="Just"){const X=et($._1.offset)*et(4);return F==="North"||F==="South"?X:0}if($.tag==="Nothing"){const X=rt(D)(r),Y=Yr(u)(C.id)(F)((()=>{if(X.tag==="Nothing")return .5;if(X.tag==="Just")return X._1._1/2;g()})());return F==="North"||F==="South"?Y:0}g()}if(z.tag==="Nothing"){const $=rt(D)(r),X=Yr(u)(C.id)(F)((()=>{if($.tag==="Nothing")return .5;if($.tag==="Just")return $._1._1/2;g()})());return F==="North"||F==="South"?X:0}g()}if(I.tag==="Nothing"){const z=rt(D)(r),$=Yr(u)(C.id)(F)((()=>{if(z.tag==="Nothing")return .5;if(z.tag==="Just")return z._1._1/2;g()})());return F==="North"||F==="South"?$:0}g()},l=(C,D)=>{if(C.from.node===D){if(f==="HRight")return he;if(f==="HLeft")return le;g()}if(f==="HRight")return le;if(f==="HLeft")return he;g()},_=(C,D,F)=>T(I=>z=>tt(S)(z)((()=>{const $=rt(z)(I);if($.tag==="Nothing")return 0+D;if($.tag==="Just")return $._1+D;g()})())(I))(F)(Qi(a)(C)),h=(()=>{if(f==="HRight")return n;if(f==="HLeft")return we(n);g()})(),p=C=>{const D=rt(C)(r);if(D.tag==="Nothing")return 1;if(D.tag==="Just")return D._1._1;g()},m=wn(We(Bt(C=>D=>O(F=>b(F,C))(D))(n))),y=(C,D)=>ye(3)(C)==="$d:"&&ye(3)(D)==="$d:"||ye(3)(C)==="$d:"||ye(3)(D)==="$d:"?10:et(t.nodeGap),x=T(C=>D=>Ws(F=>w("Just",[...(()=>{if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})(),D]))(D.to.node)(C))(A)(o),N=T(C=>D=>Ws(F=>w("Just",[...(()=>{if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})(),D]))(D.from.node)(C))(A)(o),v=We(n),k=T(C=>D=>{const F=rt(D)(a.root),I=(()=>{if(F.tag==="Nothing")return D;if(F.tag==="Just")return F._1;g()})();return D===I?C:Ws(z=>w("Just",(()=>{if(z.tag==="Nothing")return!0;if(z.tag==="Just")return z._1;g()})()&&ye(3)(D)==="$d:"))(I)(C)})(wn(O(C=>b(C,!0))(Cr(S.compare)((()=>{const C=(D,F)=>{if(D.tag==="Leaf")return F;if(D.tag==="Node")return C(D._5,$t("Cons",D._4,C(D._6,F)));g()};return Ct(Vt.foldr,C(a.root,Xt))})()))))(v),L=(C,D)=>{const F=C.free,I=rt(F)(a.root),z=(()=>{if(I.tag==="Nothing")return F;if(I.tag==="Just")return I._1;g()})(),$=rt(z)(k),X=(()=>{if($.tag==="Nothing")return!0;if($.tag==="Just")return $._1;g()})();return T(Y=>W=>{if(Y.edge.tag==="Just")return Y;if(Y.edge.tag==="Nothing"){if((()=>{const gt=rt(z)(D.su);return!X&&(()=>{const yt=rt(W.from.node)(m);return W.from.node!==W.to.node&&(()=>{const St=rt(W.to.node)(m);return(()=>{if(yt.tag==="Nothing")return-1;if(yt.tag==="Just")return yt._1;g()})()===(()=>{if(St.tag==="Nothing")return-1;if(St.tag==="Just")return St._1;g()})()})()})()||(()=>{if(gt.tag==="Nothing")return!1;if(gt.tag==="Just")return gt._1;g()})()})())return Y;const K=W.from.node===F?W.to.node:W.from.node,Z=rt(K)(a.root),ct=(()=>{if(Z.tag==="Nothing")return K;if(Z.tag==="Just")return Z._1;g()})(),_t=ct!==z;return _t&&(()=>{const gt=rt(ct)(D.blockFinished);if(gt.tag==="Nothing")return!1;if(gt.tag==="Just")return gt._1;g()})()?{...Y,edge:w("Just",W),hasEdges:!0}:{...Y,hasEdges:Y.hasEdges||_t}}g()})({edge:J,hasEdges:!1})((()=>{if(C.isRoot){if(f==="HRight"){const Y=rt(F)(x);if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1;g()}if(f==="HLeft"){const Y=rt(F)(N);if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1}g()}if(f==="HRight"){const Y=rt(F)(N);if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1;g()}if(f==="HLeft"){const Y=rt(F)(x);if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1}g()})())},E=(C,D,F,I)=>{const z=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),$={free:D,isRoot:F},X=L($,I);if(X.edge.tag==="Nothing")return X.hasEdges?{thresh:z,state:{...I,queue:[...I.queue,$]}}:{thresh:z,state:I};if(X.edge.tag==="Just"){const Y=X.edge._1.from.node===D?X.edge._1.to.node:X.edge._1.from.node;return{thresh:(()=>{const W=rt((()=>{const _t=rt(Y)(a.root);if(_t.tag==="Nothing")return Y;if(_t.tag==="Just")return _t._1;g()})())(I.x),K=rt(Y)(s),Z=rt(D)(s),ct=(()=>{if(W.tag==="Just")return W._1;if(W.tag==="Nothing")return J;g()})();return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+d(X.edge._1,Y,(()=>{if(F){if(f==="HRight")return he;if(f==="HLeft")return le;g()}if(f==="HRight")return le;if(f==="HLeft")return he;g()})())-(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()-d(X.edge._1,D,(()=>{if(F){if(f==="HRight")return le;if(f==="HLeft")return he;g()}if(f==="HRight")return he;if(f==="HLeft")return le;g()})())})(),state:{...I,su:tt(S)((()=>{const W=rt(X.edge._1.from.node)(a.root);if(W.tag==="Nothing")return X.edge._1.from.node;if(W.tag==="Just")return W._1;g()})())(!0)(tt(S)((()=>{const W=rt(X.edge._1.to.node)(a.root);if(W.tag==="Nothing")return X.edge._1.to.node;if(W.tag==="Just")return W._1;g()})())(!0)(I.su))}}}g()},B=(C,D,F,I)=>{const z=D===C,$=rt(D)(a.align),X=(()=>{if($.tag==="Nothing")return D===C;if($.tag==="Just")return $._1===C;g()})();if(!(z||X))return{thresh:F,state:I};const Y=(()=>{if(c==="VDown")return z&&F<=-1e18;if(c==="VUp")return z&&F>=1e18;g()})()?E(C,D,!0,I):{thresh:F,state:I};return(()=>{if(c==="VDown")return Y.thresh<=-1e18&&X;if(c==="VUp")return Y.thresh>=1e18&&X;g()})()?E(C,D,!1,Y.state):Y},q=C=>D=>F=>{const I=rt(F)(e.nodeIndex),z=(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;g()})(),$=Kt(Z=>Ye(dn)(F)(Z))(h),X=(()=>{if($.tag==="Nothing")return[];if($.tag==="Just")return $._1;g()})(),Y=X.length;if((()=>{if(c==="VDown")return z<=0;if(c==="VUp")return z>=(Y-1|0);g()})()){const Z=B(C,F,D.thresh,D.st);return{...D,st:Z.state,thresh:Z.thresh}}const W=(()=>{if(c==="VDown")return z-1|0;if(c==="VUp")return z+1|0;g()})(),K=W>=0&&W<X.length?w("Just",X[W]):J;if(K.tag==="Nothing")return D;if(K.tag==="Just"){const Z=rt(K._1)(a.root),ct=(()=>{if(Z.tag==="Nothing")return K._1;if(Z.tag==="Just")return Z._1;g()})(),_t=B(C,F,D.thresh,j(ct)(D.st)),gt=(()=>{const kt=rt(C)(_t.state.sink);if(kt.tag==="Nothing")return C===C;if(kt.tag==="Just")return kt._1===C;g()})()?{..._t.state,sink:tt(S)(C)((()=>{const kt=rt(ct)(_t.state.sink);if(kt.tag==="Nothing")return ct;if(kt.tag==="Just")return kt._1;g()})())(_t.state.sink)}:_t.state,yt=rt(ct)(gt.sink),St=(()=>{if(yt.tag==="Nothing")return ct;if(yt.tag==="Just")return yt._1;g()})(),Ht=rt(C)(gt.sink),pt=(()=>{if(Ht.tag==="Nothing")return C;if(Ht.tag==="Just")return Ht._1;g()})();if(pt===St){const kt=rt(ct)(gt.x),Ot=(()=>{if(kt.tag==="Just")return kt._1;if(kt.tag==="Nothing")return J;g()})(),_n=(()=>{if(Ot.tag==="Nothing")return 0;if(Ot.tag==="Just")return Ot._1;g()})(),Fe=rt(C)(gt.x),Pt=(()=>{if(Fe.tag==="Just")return Fe._1;if(Fe.tag==="Nothing")return J;g()})(),At=(()=>{if(Pt.tag==="Nothing")return 0;if(Pt.tag==="Just")return Pt._1;g()})(),Be=y(F,K._1),an=rt(K._1)(s),Xe=rt(F)(s),nn=(()=>{if(an.tag==="Nothing")return 0;if(an.tag==="Just")return an._1;g()})()-(()=>{if(Xe.tag==="Nothing")return 0;if(Xe.tag==="Just")return Xe._1;g()})();if(c==="VDown"){const Pe=Tn(_n+nn+p(K._1)+Be)(_t.thresh);return{st:{...gt,x:tt(S)(C)(w("Just",D.initial?Pe:Tn(At)(Pe)))(gt.x)},initial:!1,thresh:_t.thresh}}if(c==="VUp"){const Pe=on(_n+nn-Be-p(F))(_t.thresh);return{st:{...gt,x:tt(S)(C)(w("Just",D.initial?Pe:on(At)(Pe)))(gt.x)},initial:!1,thresh:_t.thresh}}g()}const Wt=rt(ct)(gt.x),Tt=(()=>{if(Wt.tag==="Just")return Wt._1;if(Wt.tag==="Nothing")return J;g()})(),mt=(()=>{if(Tt.tag==="Nothing")return 0;if(Tt.tag==="Just")return Tt._1;g()})(),ft=rt(C)(gt.x),ot=(()=>{if(ft.tag==="Just")return ft._1;if(ft.tag==="Nothing")return J;g()})(),dt=(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;g()})(),ut=et(t.nodeGap),st=rt(F)(s),Nt=rt(K._1)(s),Jt=(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;g()})()-(()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1;g()})();return{st:{...gt,classEdges:[...gt.classEdges,{src:pt,tgt:St,sep:(()=>{if(c==="VDown")return dt+Jt-mt-p(K._1)-ut;if(c==="VUp")return dt+Jt+p(F)+ut-mt;g()})()}]},initial:D.initial,thresh:_t.thresh}}g()},j=C=>D=>{const F=rt(C)(D.x),I=(()=>{if(F.tag==="Just")return F._1;if(F.tag==="Nothing")return J;g()})();if(I.tag==="Just")return D;if(I.tag==="Nothing"){const z=T(q(C))({st:{...D,x:tt(S)(C)(w("Just",0))(D.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})()})(Qi(a)(C));return{...z.st,blockFinished:tt(S)(C)(!0)(z.st.blockFinished)}}g()},G=T(C=>D=>T(F=>I=>{const z=rt(I)(a.root),$=(()=>{if(z.tag==="Nothing")return I;if(z.tag==="Just")return z._1;g()})();return $===I?j($)(F):F})(C)((()=>{if(c==="VDown")return D;if(c==="VUp")return we(D);g()})()))({x:wn(O(C=>b(C,J))(v)),sink:wn(O(C=>b(C,C))(v)),classEdges:[],su:A,blockFinished:A,queue:[]})(h),P=Ky(G.classEdges)(G.sink)(c),V=(C,D,F,I)=>{const z=rt(D)(I),$=rt(D)(s);return(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})()+(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;g()})()+d(C,D,F)},U=wn(O(C=>b(C,!0))(Cr(S.compare)((()=>{const C=(D,F)=>{if(D.tag==="Leaf")return F;if(D.tag==="Node")return C(D._5,$t("Cons",D._4,C(D._6,F)));g()};return Ct(Vt.foldr,C(a.root,Xt))})()))),M=C=>D=>F=>{const I=L(F,{su:D.su,blockFinished:U}),z={phase:C,ppFree:F.free,ppIsRoot:F.isRoot,edgeId:J,delta:0,avail:0,shift:0,freeSu:(()=>{const $=rt((()=>{const X=rt(F.free)(a.root);if(X.tag==="Nothing")return F.free;if(X.tag==="Just")return X._1;g()})())(D.su);if($.tag==="Nothing")return!1;if($.tag==="Just")return $._1;g()})(),hasEdges:I.hasEdges,candCount:(()=>{if(F.isRoot){if(f==="HRight"){const $=rt(F.free)(x);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length;g()}if(f==="HLeft"){const $=rt(F.free)(N);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length}g()}if(f==="HRight"){const $=rt(F.free)(N);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length;g()}if(f==="HLeft"){const $=rt(F.free)(x);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length}g()})()};if(I.edge.tag==="Nothing")return{...D,stack:[...D.stack,F],trace:[...D.trace,z],x:D.x};if(I.edge.tag==="Just"){const $=I.edge._1.from.node===F.free?b(I.edge._1.from.node,I.edge._1.to.node):b(I.edge._1.to.node,I.edge._1.from.node),X=V(I.edge._1,$._1,l(I.edge._1,$._1),D.x)-V(I.edge._1,$._2,l(I.edge._1,$._2),D.x),Y=rt($._1)(a.root),W=(()=>{if(Y.tag==="Nothing")return $._1;if(Y.tag==="Just")return Y._1;g()})(),K={...z,edgeId:w("Just",I.edge._1.id),delta:X};if(X>0&&X<1e300){const Z=T(gt=>yt=>{const St=rt(yt)(m),Ht=(()=>{if(St.tag==="Nothing")return-1;if(St.tag==="Just")return St._1;g()})();if(Ht>=0&&Ht<n.length){const Tt=n[Ht],mt=rt(yt)(e.nodeIndex),ft=(()=>{if(mt.tag==="Nothing")return-2;if(mt.tag==="Just")return mt._1-1|0;g()})();return ft>=0&&ft<Tt.length?on(gt)((()=>{const ot=rt(yt)(D.x),dt=rt(yt)(s),ut=rt(Tt[ft])(D.x),st=rt(Tt[ft])(s);return(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;g()})()+(()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1;g()})()-((()=>{if(ut.tag==="Nothing")return 0;if(ut.tag==="Just")return ut._1;g()})()+(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;g()})()+p(Tt[ft])+y(yt,Tt[ft]))})()):gt}const pt=rt(yt)(e.nodeIndex),Wt=(()=>{if(pt.tag==="Nothing")return-2;if(pt.tag==="Just")return pt._1-1|0;g()})();return Wt>=0&&Wt<0?on(gt)((()=>{const Tt=rt(yt)(D.x),mt=rt(yt)(s),ft=rt([][Wt])(D.x),ot=rt([][Wt])(s);return(()=>{if(Tt.tag==="Nothing")return 0;if(Tt.tag==="Just")return Tt._1;g()})()+(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()-((()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;g()})()+(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;g()})()+p([][Wt])+y(yt,[][Wt]))})()):gt})(X)(Qi(a)(W)),ct=Z>0?-Z:0,_t={...D,x:Z>0?_(W,ct,D.x):D.x,trace:[...D.trace,{...K,avail:Z,shift:ct}]};return Z>0?_t:{..._t,stack:[..._t.stack,F]}}if(X<0&&-X<1e300){const Z=T(gt=>yt=>{const St=rt(yt)(m),Ht=(()=>{if(St.tag==="Nothing")return-1;if(St.tag==="Just")return St._1;g()})();if(Ht>=0&&Ht<n.length){const Tt=n[Ht],mt=rt(yt)(e.nodeIndex),ft=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1+1|0;g()})();return ft>=0&&ft<Tt.length?on(gt)((()=>{const ot=rt(Tt[ft])(D.x),dt=rt(Tt[ft])(s),ut=rt(yt)(D.x),st=rt(yt)(s);return(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;g()})()+(()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1;g()})()-((()=>{if(ut.tag==="Nothing")return 0;if(ut.tag==="Just")return ut._1;g()})()+(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;g()})()+p(yt)+y(yt,Tt[ft]))})()):gt}const pt=rt(yt)(e.nodeIndex),Wt=(()=>{if(pt.tag==="Nothing")return 0;if(pt.tag==="Just")return pt._1+1|0;g()})();return Wt>=0&&Wt<0?on(gt)((()=>{const Tt=rt([][Wt])(D.x),mt=rt([][Wt])(s),ft=rt(yt)(D.x),ot=rt(yt)(s);return(()=>{if(Tt.tag==="Nothing")return 0;if(Tt.tag==="Just")return Tt._1;g()})()+(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()-((()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;g()})()+(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;g()})()+p(yt)+y(yt,[][Wt]))})()):gt})(-X)(Qi(a)(W)),ct=Z>0?Z:0,_t={...D,x:Z>0?_(W,ct,D.x):D.x,trace:[...D.trace,{...K,avail:Z,shift:ct}]};return Z>0?_t:{..._t,stack:[..._t.stack,F]}}return{...D,stack:[...D.stack,F],trace:[...D.trace,K],x:D.x}}g()},H=T(M(Vy))({x:wn(O(C=>b(C,(()=>{const D=rt(C)(a.root),F=(()=>{if(D.tag==="Nothing")return C;if(D.tag==="Just")return D._1;g()})(),I=rt(F)(G.x),z=rt((()=>{const X=rt(F)(G.sink);if(X.tag==="Nothing")return F;if(X.tag==="Just")return X._1;g()})())(P),$=(()=>{if(I.tag==="Just")return I._1;if(I.tag==="Nothing")return J;g()})();return(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;g()})()+(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})()})()))(v)),su:G.su,stack:[],trace:[]})(G.queue),R=T(M(Uy))({...H,stack:[]})(we(H.stack));return{x:R.x,queue:G.queue,trace:R.trace}},t2=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>jy(t)(e)(n)(r)(i)(o)(u)(s)(a)(c)(f).x,e2=t=>e=>n=>r=>i=>o=>{const u=(a,c,f)=>{const d=rt(c)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;g()})(),_=a.from.node===c?a.from.port:a.to.node===c?a.to.port:J;if(_.tag==="Just"){const h=rt(c)(e);if(h.tag==="Just"){const p=Kt(m=>m.id===_._1)(h._1);if(p.tag==="Just"){const m=et(p._1.offset)*et(4);return f==="North"||f==="South"?m:0}if(p.tag==="Nothing"){const m=Yr(i)(a.id)(f)(l);return f==="North"||f==="South"?m:0}g()}if(h.tag==="Nothing"){const p=Yr(i)(a.id)(f)(l);return f==="North"||f==="South"?p:0}g()}if(_.tag==="Nothing"){const h=Yr(i)(a.id)(f)(l);return f==="North"||f==="South"?h:0}g()},s=a=>c=>f=>d=>{let l=a,_=c,h=f,p=d,m=!0,y;for(;m;){const x=l,N=_,v=h,k=Qt(L=>J,L=>E=>w("Just",{head:L,tail:E}),p);if(k.tag==="Nothing"){m=!1,y=x;continue}if(k.tag==="Just"){const L=k._1.head,E=Kt(q=>q.from.node===v&&q.to.node===L||q.from.node===L&&q.to.node===v)(r),B=(()=>{if(E.tag==="Nothing")return N+0;if(E.tag==="Just")return N+(u(E._1,v,E._1.from.node===v?he:le)-u(E._1,L,E._1.from.node===L?he:le));g()})();l=tt(S)(L)(B)(x),_=B,h=L,p=k._1.tail;continue}g()}return y};return T(a=>c=>{const f=Qt(_=>J,_=>h=>w("Just",{head:_,tail:h}),Qi(t)(c)),d=(()=>{if(f.tag==="Nothing")return tt(S)(c)(0)(A);if(f.tag==="Just")return s(tt(S)(f._1.head)(0)(A))(0)(f._1.head)(f._1.tail);g()})(),l=T(_=>h=>Tn(_)(-h._2))(0)(Os(d));return T(_=>h=>tt(S)(h._1)(h._2+l)(_))(a)(Os(d))})(A)(Cr(S.compare)((()=>{const a=(c,f)=>{if(c.tag==="Leaf")return f;if(c.tag==="Node")return a(c._5,$t("Cons",c._4,a(c._6,f)));g()};return Ct(Vt.foldr,a(t.root,Xt))})()))},n2=t=>e=>{const n=(i,o,u)=>ye(3)(o)==="$d:"&&ja(nf,(()=>{const s=rt(o)(t.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;g()})()),r=i=>o=>u=>s=>a=>c=>f=>{let d=i,l=o,_=s,h=c,p=f,m=!0,y;for(;m;){const x=d,N=l,v=_,k=h,L=p,E=N.length;if(L>=E){m=!1,y=x;continue}const B=L>=0&&L<N.length?w("Just",N[L]):J,q=(()=>{if(B.tag==="Nothing")return"";if(B.tag==="Just")return B._1;g()})(),j=n(t,q);if(L===(E-1|0)||j){const G=(()=>{if(j){const P=rt(q)(t.preds),V=(()=>{if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})();if(0<V.length){const U=v-1|0,M=rt(V[0])(t.nodeIndex);if(M.tag==="Nothing")return U;if(M.tag==="Just")return M._1;g()}}return v-1|0})();d=T(P=>V=>{if(V>=0&&V<N.length){const U=N[V];return n(t,U)?P:T(M=>H=>{const R=rt(H)(t.nodeIndex),C=(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})();return C<k||C>G?tt(S)(H+"\u2192"+U)()(M):M})(P)((()=>{const M=rt(U)(t.preds);if(M.tag==="Nothing")return[];if(M.tag==="Just")return M._1;g()})())}return n(t,"")?P:T(U=>M=>{const H=rt(M)(t.nodeIndex),R=(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})();return R<k||R>G?tt(S)(M+"\u2192")()(U):U})(P)((()=>{const U=rt("")(t.preds);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;g()})())})(x)(Ft(0,L)),l=N,_=v,h=G,p=L+1|0;continue}d=x,l=N,_=v,h=k,p=L+1|0}return y};return e.length<3?A:T(i=>o=>{if(o>=0&&o<e.length){const u=e[o];return r(i)((()=>{const s=o+1|0;return s>=0&&s<e.length?e[s]:[]})())(u)(u.length)(o)(0)(0)}return r(i)((()=>{const u=o+1|0;return u>=0&&u<e.length?e[u]:[]})())([])(0)(o)(0)(0)})(A)(Ft(1,e.length-2|0))},r2=t=>e=>n=>r=>i=>{const o=We(e),u=T(s=>a=>{const c=T(f=>d=>{const l=(()=>{if(i==="HRight"){const m=rt(d)(t.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()}if(i==="HLeft"){const m=rt(d)(t.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}g()})(),_=l.length;if(_===0)return f;const h=Gn(_-1|0,2),p=Gn(_,2);return T(m=>y=>{if((()=>{const x=rt(d)(m.align);if(x.tag==="Nothing")return d!==d;if(x.tag==="Just")return x._1!==d;g()})())return m;if(y>=0&&y<l.length){const x=rt(l[y])(t.nodeIndex),N=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})();if(!(df(l[y]+"\u2192"+d)(n)||df(d+"\u2192"+l[y])(n))&&(()=>{if(r==="VDown")return m.r<N;if(r==="VUp")return m.r>N;g()})()){const v=rt(l[y])(m.root),k=(()=>{if(v.tag==="Nothing")return l[y];if(v.tag==="Just")return v._1;g()})();return{root:tt(S)(d)(k)(m.root),align:tt(S)(l[y])(d)(tt(S)(d)(k)(m.align)),r:N}}}return m})(f)((()=>{if(r==="VDown")return Ft(h,p);if(r==="VUp")return we(Ft(h,p));g()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;g()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return we(a);g()})());return{root:c.root,align:c.align}})({root:wn(O(s=>b(s,s))(o)),align:wn(O(s=>b(s,s))(o))})((()=>{if(i==="HRight")return e;if(i==="HLeft")return we(e);g()})());return{root:u.root,align:u.align}},Vo=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>{const f=r2(e)(n)(s)(a)(c),d=e2(f)(i)(r)(o)(u)(c);return vd()(l=>_=>w("Just",(()=>{const h=rt(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;g()})()))(t2(t)(e)(n)(r)(i)(o)(u)(d)(f)(a)(c))},hf=t=>e=>Bt(n=>r=>T(i=>o=>o>=0&&o<e.length?o>=0&&o<t.length?i+e[o]+t[o]:i+e[o]+0:o>=0&&o<t.length?i+1+t[o]:i+1)(0)((()=>{const i=Ft(0,e.length-1|0);return n<1?[]:Lt(0,n,i)})()))(e),i2=t=>e=>n=>r=>i=>o=>u=>{const s=qy(0)(e.length-1|0),a=et(t.layerGap),c=u(sd(s,a)),f=uy(jg(i)(c)(r)(o)(A))(c);return O(d=>{const l=Xy(d)(f);return l.tag==="Just"&&l._1>0?Tn(a)(2+et(l._1-1|0)*2.5):a})(Ft(0,s-1|0))},pf=t=>e=>n=>r=>ja(i=>T(o=>u=>{if(!o.ok)return o;const s=rt(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})(),c=rt(u)(n),f=(()=>{if(c.tag==="Nothing")return a+1;if(c.tag==="Just")return a+c._1._1;g()})();return a+1e-4>o.pos&&f+1e-4>o.pos?{ok:!0,pos:f}:{ok:!1,pos:o.pos}})({ok:!0,pos:-1e18})(i).ok,e),o2=t=>e=>n=>r=>{const i=Et(o=>u=>it.compare(o.w)(u.w))(O(o=>({l:o,w:lf(o)}))(at(pf()(e)(n),r)));return 0<i.length?w("Just",i[0].l):J},u2=t=>e=>{const n=wn(We(O(Bt(i=>o=>b(o,i)))(t))),r=i=>Et(o=>u=>nt.compare((()=>{const s=rt(o)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})())((()=>{const s=rt(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(i);return{preds:(()=>{const i=o=>{if(o.tag==="Leaf")return A;if(o.tag==="Node")return Yt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(T(o=>u=>bt(S)(re)(u.to.node)([u.from.node])(o))(A)(e))})(),succs:(()=>{const i=o=>{if(o.tag==="Leaf")return A;if(o.tag==="Node")return Yt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(T(o=>u=>bt(S)(re)(u.from.node)([u.to.node])(o))(A)(e))})(),nodeIndex:n}},s2=t=>e=>{const n=Et(d=>l=>it.compare(d.w)(l.w))(Bt(d=>l=>({i:d,l,w:lf(l)}))(e)),r=0<n.length?w("Just",n[0]):J,i=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;g()})(),o=i>=0&&i<e.length?w("Just",e[i]):J,u=(()=>{if(o.tag==="Just")return(d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const y=_,x=h;if(x.tag==="Nil"){p=!1,m=y;continue}if(x.tag==="Cons"){_=on(y)(x._1),h=x._2;continue}g()}return m})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,$t("Cons",l._4,d(l._6,_)));g()};return d(o._1,Xt)})());if(o.tag==="Nothing")return 0;g()})(),s=d=>T(l=>_=>Tn(l)((()=>{const h=rt(_._1)(t);if(h.tag==="Nothing")return _._2+1;if(h.tag==="Just")return _._2+h._1._1;g()})()))(-999999)(Os(d)),a=i>=0&&i<e.length?w("Just",e[i]):J,c=(()=>{if(a.tag==="Just")return s(a._1);if(a.tag==="Nothing")return 0;g()})(),f=ve(d=>l=>{const _=h=>{if(h.tag==="Leaf")return A;if(h.tag==="Node")return Yt("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));g()};return _(d)},e,Bt(d=>l=>Un(d)(2)===0?u-(_=>h=>{let p=_,m=h,y=!0,x;for(;y;){const N=p,v=m;if(v.tag==="Nil"){y=!1,x=N;continue}if(v.tag==="Cons"){p=on(N)(v._1),m=v._2;continue}g()}return x})(999999)((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,$t("Cons",h._4,_(h._6,p)));g()};return _(l,Xt)})()):c-s(l))(e));return Zy(T(d=>l=>{const _=Et(it.compare)(xt(rt(l))(f));return tt(S)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(A)(Cr(S.compare)(We(O(d=>{const l=_=>{if(_.tag==="Leaf")return A;if(_.tag==="Node")return Yt("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));g()};return Ct(Qe.foldr,l(d))})(f)))))},a2=t=>e=>n=>r=>i=>o=>{const u=u2(e)(i),s=n2(u)(e),a={nodeGap:t.nodeGap*4|0},c=Se(S.compare,Ee,wn(O(_=>b(_,b(1,1)))(at(nf,We(e)))),(()=>{const _=h=>{if(h.tag==="Leaf")return A;if(h.tag==="Node")return Yt("Node",h._1,h._2,h._3,b(h._4._1*et(4),h._4._2),_(h._5),_(h._6));g()};return _(n)})()),f=[Vo(a)(u)(e)(c)(r)(i)(o)(s)(cf)(ff),Vo(a)(u)(e)(c)(r)(i)(o)(s)(gf)(ff),Vo(a)(u)(e)(c)(r)(i)(o)(s)(cf)(_f),Vo(a)(u)(e)(c)(r)(i)(o)(s)(gf)(_f)],d=s2(c)(f);if(pf()(e)(c)(d))return d;const l=o2()(e)(c)(f);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return f[0];g()},c2=t=>e=>n=>r=>{const i=Va(J,Ha,o=>o.node===e?w("Just",o.position):J,t);if(i.tag==="Nothing")return t;if(i.tag==="Just"){const o=i._1;return O(u=>u.node===n?{...u,position:b(o._1+r._1,o._2+r._2)}:u)(t)}g()},g2=t=>e=>n=>r=>{const i=at(u=>Ye(dn)(u.node)(e),t),o=(()=>{if(n==="Vertical"){if(r==="Start")return T(u=>s=>on(u)(s.position._1))(99999)(i);if(r==="End")return T(u=>s=>Tn(u)(s.position._1))(0)(i);if(r==="Center"){const u=T(s=>a=>s+a.position._1)(0)(i);return i.length===0?0:u/et(i.length)}g()}if(n==="Horizontal"){if(r==="Start")return T(u=>s=>on(u)(s.position._2))(99999)(i);if(r==="End")return T(u=>s=>Tn(u)(s.position._2))(0)(i);if(r==="Center"){const u=T(s=>a=>s+a.position._2)(0)(i);return i.length===0?0:u/et(i.length)}}g()})();return O(u=>{if(Ye(dn)(u.node)(e)){if(n==="Vertical")return{...u,position:b(o,u.position._2)};if(n==="Horizontal")return{...u,position:b(u.position._1,o)};g()}return u})(t)},f2=t=>e=>T(n=>r=>r.tag==="AlignGroup"?g2(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?c2(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),_2=t=>e=>n=>r=>i=>o=>u=>s=>{const a=O(d=>T(l=>_=>Tn(l)((()=>{const h=rt(_)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;g()})()))(1)(d))(n),c=a2(t)(n)(r)(i)(o)(s),f=hf(i2(t)(n)(r)(i)(o)(u)(d=>{const l=hf(d)(a);return We(Bt(_=>h=>Bt(p=>m=>({node:m,position:b((()=>{const y=rt(m)(c);return(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;g()})()/et(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const y=ye(3)(m)==="$d:"?b(0,1):b(1,1),x=rt(m)(r);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;g()})(),layer:_,order:p}))(h))(n))}))(a);return f2(e)(We(Bt(d=>l=>Bt(_=>h=>({node:h,position:b((()=>{const p=rt(h)(c);return(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})()/et(4)})(),d>=0&&d<f.length?f[d]:0),size:(()=>{const p=ye(3)(h)==="$d:"?b(0,1):b(1,1),m=rt(h)(r);if(m.tag==="Nothing")return p;if(m.tag==="Just")return m._1;g()})(),layer:d,order:_}))(l))(n)))},Ys=es(po)(pr(32)),mf=es(po)(pr(31)),Ri=(()=>{const t=Jl("25214903917");if(t.tag==="Nothing")return pc;if(t.tag==="Just")return t._1;g()})(),Mi=ts(es(po)(pr(48)))(po),d2=t=>{const e=Tl(t);return hi(mc((()=>{if(e.tag==="Nothing")return pc;if(e.tag==="Just")return e._1;g()})())(Ri))(Mi)},$s=pr(11),Uo=t=>e=>{const n=hi(lo(ho(e)(Ri))($s))(Mi);return b((()=>{const r=ic(ml(ns(n)(pr(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},l2=t=>{const e=Uo(26)(t),n=Uo(27)(e._2);return b((et(e._1)*Bu(2)(27)+et(n._1))/Bu(2)(53),n._2)},h2=t=>e=>{const n=T(r=>i=>{const o=l2(r.finalR);return{rs:[...r.rs,o._1],finalR:o._2}})({rs:[],finalR:t})(e);return b(O(r=>r.x)(Et(r=>i=>it.compare(r.k)(i.k))(ve(r=>i=>({x:r,k:i}),e,n.rs))),n.finalR)},p2=t=>{const e=hi(lo(ho(t)(Ri))($s))(Mi),n=hi(lo(ho(e)(Ri))($s))(Mi);return b(lo(ho((()=>{const r=ns(e)(pr(16));return yc.compare(r)(mf)!=="LT"?ts(r)(Ys):r})())(Ys))((()=>{const r=ns(n)(pr(16));return yc.compare(r)(mf)!=="LT"?ts(r)(Ys):r})()),n)},zi=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Ko=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},qs=te(S)(zt),$r=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Zo=te(S)(zt),m2=Au(oi),y2=T(Gr)(0),x2=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},yf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},N2=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const i=Xn(Ut,J,t,n[e],n);if(i.tag==="Just")return Xn(Ut,J,e,r,i._1);if(i.tag==="Nothing")return J;g()}}return J},J2=t=>e=>n=>r=>i=>qs(T(o=>u=>{const s=Et(a=>c=>nt.compare((()=>{const f=zi(a.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})())((()=>{const f=zi(c.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})()))(at(a=>Ko(a.to.node)(n),at(a=>a.from.node===u,r)));return{ranks:[...o.ranks,...Bt(a=>c=>b(c.id,et((o.rankSum+a|0)+1|0)))(s)],rankSum:o.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),T2=t=>e=>n=>r=>i=>qs(T(o=>u=>{const s=Et(c=>f=>{const d=nt.compare((()=>{const l=$r(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=$r(c.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})());return d==="EQ"?nt.compare((()=>{const l=zi(c.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})())((()=>{const l=zi(f.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})()):d})(at(c=>Ko(c.from.node)(n),at(c=>c.to.node===u,r))),a=s.length;return{ranks:[...o.ranks,...Bt(c=>f=>b(f.id,et((o.rankSum+a|0)-c|0)))(s)],rankSum:o.rankSum+a|0}})({ranks:[],rankSum:0})(t).ranks),Xs=t=>e=>n=>{const r=Zo(Bt(s=>a=>b(a,s))(t)),i=Zo(Bt(s=>a=>b(a,s))(e)),o=xt(s=>{const a=$r(s.from.node)(r),c=$r(s.to.node)(i);if(a.tag==="Just"&&c.tag==="Just")return w("Just",b(a._1,c._1));const f=$r(s.from.node)(i),d=$r(s.to.node)(r);return f.tag==="Just"&&d.tag==="Just"?w("Just",b(d._1,f._1)):J})(n),u=o.length;return T(s=>a=>T(c=>f=>a>=0&&a<o.length&&f>=0&&f<o.length&&((o[a]._1-o[f]._1|0)*(o[a]._2-o[f]._2|0)|0)<0?c+1|0:c)(s)(Ft(a+1|0,u-1|0)))(0)(Ft(0,u-2|0))},w2=t=>e=>n=>r=>{const i=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l>=(d.length-1|0)){c=!1,f=d;continue}if(l>=0&&l<d.length){const _=l+1|0;if(_>=0&&_<d.length){const h=d[l],p=d[_];if(Oe(N=>N.before===h&&N.after===p,r)){s=d,a=l+1|0;continue}const m=Xn(Ut,J,l,p,d),y=(()=>{if(m.tag==="Just")return Xn(Ut,J,l+1|0,h,m._1);if(m.tag==="Nothing")return J;g()})(),x=(()=>{if(y.tag==="Nothing")return d;if(y.tag==="Just")return y._1;g()})();if(Xs(e)(x)(n)<Xs(e)(d)(n)){s=x,a=l+1|0;continue}s=d,a=l+1|0;continue}c=!1,f=d;continue}c=!1,f=d}return f};return(o=>{let u=o,s=!0,a;for(;s;){const c=u,f=i(c)(0);if(m2(f)(c)){s=!1,a=c;continue}u=f}return a})(t)},jo=t=>e=>T(n=>r=>{if(r>=0&&r<t.length){const i=t[r],o=r+1|0;if(o>=0&&o<t.length)return n+Xs(i)(t[o])(e)|0}return n})(0)(Ft(0,t.length-2|0)),v2=(()=>{const t=e=>{if(e.length<7){const o=u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=_-1|0;if(h>=0&&h<l.length){if(_>=0&&_<l.length&&_>0&&l[h].key>l[_].key){const p=N2(_-1|0)(_)(l);if(p.tag==="Just"){a=p._1,c=_-1|0;continue}if(p.tag==="Nothing"){f=!1,d=l;continue}g()}f=!1,d=l;continue}f=!1,d=l}return d};return T(u=>s=>o(u)(s))(e)(Ft(1,e.length-1|0))}const n=Gn(e.length,2),r=t(Lt(0,n,e)),i=t(Lt(n,e.length,e));return(o=>u=>s=>{let a=o,c=u,f=s,d=!0,l;for(;d;){const _=a,h=c,p=f;if(h>=0&&h<r.length){if(p>=0&&p<i.length){if(r[h].key>i[p].key){a=Rt(_)(i[p]),c=h,f=p+1|0;continue}a=Rt(_)(r[h]),c=h+1|0,f=p;continue}d=!1,l=[..._,...h<1?r:Lt(h,r.length,r)];continue}d=!1,l=[..._,...p<1?i:Lt(p,i.length,i)]}return l})([])(0)(0)};return t})(),b2=t=>e=>n=>{const r=xt(c=>c.tag==="OrderConstraint"?w("Just",{before:c._1.before,after:c._1.after}):J)(t.constraints),i=c=>T(f=>d=>{const l=d.after,_=d.before,h=gr(Ut,J,m=>m===_,f),p=gr(Ut,J,m=>m===l,f);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=Za(Ut,J,h._1,f),y=(()=>{if(m.tag==="Nothing")return f;if(m.tag==="Just")return m._1;g()})(),x=Ka(Ut,J,p._1,_,y);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;g()}return f})(c)(r),o=qs(Bt(c=>f=>b(f.id,c))(n)),u=(c,f,d)=>{const l=c.length;return T(_=>h=>{const p=f?h-1|0:h+1|0,m=p>=0&&p<_._1.length?w("Just",_._1[p]):J;if(m.tag==="Just"){const y=h>=0&&h<_._1.length?w("Just",_._1[h]):J;if(y.tag==="Just"){const x=Zo(Bt(E=>B=>b(B,E))(m._1)),N=Zo(Bt(E=>B=>b(B,E))(y._1)),v=f?J2(m._1)(x)(N)(n)(o):T2(m._1)(x)(N)(n)(o),k=T(E=>B=>{const q=xt(G=>zi(G.id)(v))(at(f?G=>G.to.node===B._2&&Ko(G.from.node)(x):G=>G.from.node===B._2&&Ko(G.to.node)(x),n));if(q.length===0)return{...E,items:[...E.items,{n:B._2,key:J,origIdx:B._1}]};const j=Uo(24)(E.r);return{items:[...E.items,{n:B._2,key:w("Just",(y2(q)+(et(j._1)*4172325152040912e-24-.03500000014901161))/et(q.length)),origIdx:B._1}],r:j._2}})({items:[],r:_._2})(Bt(Pn)(y._1)),L=Xn(Ut,J,h,w2(i(O(E=>E.n)(v2((()=>{const E=k.items,B=q=>j=>{let G=q,P=j,V=!0,U;for(;V;){const M=G,H=P;if(M>=0&&M<E.length){if(E[M].key.tag==="Just"){V=!1,U=E[M].key._1;continue}if(E[M].key.tag==="Nothing"){G=M+1|0,P=H;continue}g()}V=!1,U=H}return U};return(q=>j=>G=>{let P=q,V=j,U=G,M=!0,H;for(;M;){const R=P,C=V,D=U;if(R>=0&&R<E.length){if(E[R].key.tag==="Just"){P=R+1|0,V=E[R].key._1,U=[...D,{n:E[R].n,key:E[R].key._1,origIdx:E[R].origIdx}];continue}if(E[R].key.tag==="Nothing"){const F=(C+B(R+1|0)(C+1))/2;P=R+1|0,V=F,U=[...D,{n:E[R].n,key:F,origIdx:E[R].origIdx}];continue}g()}M=!1,H=D}return H})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(L.tag==="Just")return b(L._1,k.r);if(L.tag==="Nothing")return b(_._1,_._2);g()}if(y.tag==="Nothing")return b(_._1,_._2);g()}if(m.tag==="Nothing")return b(_._1,_._2);g()})(b(c,d))(f?Ft(1,l-1|0):we(Ft(0,l-2|0)))},s=T(c=>f=>tt(S)(f.from.node)()(tt(S)(f.to.node)()(c)))(A)(n),a=T(c=>f=>{if(c.result.crossings===0)return c;const d=x=>N=>v=>k=>{let L=x,E=N,B=v,q=k,j=!0,G;for(;j;){const P=L,V=E,U=B,M=q;if(U===0){j=!1,G={layout:P,crossings:0,random:M};continue}const H=u(P,V,M),R=jo(H._1)(n);if(R<U){L=H._1,E=!V,B=R,q=H._2;continue}j=!1,G={layout:P,crossings:U,random:H._2}}return G},l=Uo(1)(c.result.random),_=l._1!==0,h=t.modelOrder.tag==="Leaf",p=(c.firstTry||c.secondTry)&&!h?c.firstTry:_,m=(()=>{if(!h){const k=u(e,p,l._2);return d(k._1)(!p)(jo(k._1)(n))(k._2)}const x=p?0:x2(0)(e.length-1|0),N=x>=0&&x<e.length?w("Just",e[x]):J;if(N.tag==="Just"&&N._1.length>1){const k=at(L=>yf(L)(s),N._1);if(k.length>1){const L=h2(l._2)(k),E=L._1,B=Xn(Ut,J,x,i(T(q=>j=>yf(j)(s)?q.idx>=0&&q.idx<E.length?{idx:q.idx+1|0,result:[...q.result,E[q.idx]]}:{idx:q.idx,result:[...q.result,j]}:{idx:q.idx,result:[...q.result,j]})({idx:0,result:[]})(N._1).result),e);if(B.tag==="Just"){const q=u(B._1,p,L._2);return d(q._1)(!p)(jo(q._1)(n))(q._2)}}}const v=u(e,p,l._2);return d(v._1)(!p)(jo(v._1)(n))(v._2)})(),y=c.secondTry?!1:c.secondTry;return c.firstTry?{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:c.firstTry,secondTry:y}})({result:{layout:e,crossings:1e9,random:hi(mc(p2(d2(1))._1)(Ri))(Mi)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Ft(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:a.layout},k2=t=>t,xf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Me=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},qr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Hi=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=S.compare(e._1)(n._1);return r==="LT"?Je:r==="GT"?Te:S.compare(e._2)(n._2)},Eq0:()=>t}})(),L2=te(S)(zt),E2=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=Hi.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},C2=k2("Greedy"),Vs=t=>e=>n=>T(r=>i=>{if(i.from.node===i.to.node)return r;if(i.from.node===e&&!xf(i.to.node)(r.marks)){const o=Me(i.to.node)(r.inDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;g()})(),s=tt(S)(i.to.node)(u)(r.inDeg);return(()=>{const a=Me(i.to.node)(r.outDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!Ye(dn)(i.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,i.to.node]}:{...r,inDeg:s}}if(i.to.node===e&&!xf(i.from.node)(r.marks)){const o=Me(i.from.node)(r.outDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;g()})(),s=tt(S)(i.from.node)(u)(r.outDeg);return(()=>{const a=Me(i.from.node)(r.inDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!Ye(dn)(i.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,i.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:at(r=>r!==e,n.remaining)})(t),S2=T(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return tt(S)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return tt(S)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return tt(S)(e._1.node)(99999)(t)}return t})(A),Nf=t=>e=>n=>{const r=Me(e)(t),i=Me(n)(t);return r.tag==="Just"&&i.tag==="Just"&&r._1>i._1},Jf=t=>e=>n=>r=>{if(qr(n)(r.visited)||qr(n)(r.visiting))return r;const i=T(G2(t)(e)(n))({...r,visiting:tt(S)(n)()(r.visiting)})((()=>{const o=Me(n)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})());return{...i,visiting:si(S)(n)(i.visiting),visited:tt(S)(n)()(i.visited)}},G2=t=>e=>n=>r=>i=>Nf(t)(n)(i)?{...r,backEdges:tt(Hi)(b(n,i))()(r.backEdges)}:qr(i)(r.visiting)?{...r,backEdges:tt(Hi)(b(n,i))()(r.backEdges)}:qr(i)(r.visited)?r:Jf(t)(e)(i)(r),P2=t=>e=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,y=Qt(x=>J,x=>N=>w("Just",{head:x,tail:N}),m.sinks);if(y.tag==="Just"){_=Vs(n)(y._1.head)({...m,sinks:y._1.tail,marks:tt(S)(y._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(y.tag==="Nothing"){const x=Qt(N=>J,N=>v=>w("Just",{head:N,tail:v}),m.sources);if(x.tag==="Just"){_=Vs(n)(x._1.head)({...m,sources:x._1.tail,marks:tt(S)(x._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(x.tag==="Nothing"){const N=k=>{const L=Me(k)(m.outDeg),E=Me(k)(m.inDeg);return(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;g()})()-(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;g()})()|0},v=Et(k=>L=>{const E=nt.compare(N(L))(N(k));return E==="EQ"?nt.compare((()=>{const B=Me(k)(e);if(B.tag==="Nothing")return 1e6;if(B.tag==="Just")return B._1;g()})())((()=>{const B=Me(L)(e);if(B.tag==="Nothing")return 1e6;if(B.tag==="Just")return B._1;g()})()):E})(m.remaining);if(0<v.length){const k=v[0];_=Vs(n)(k)({...m,remaining:at(L=>L!==k,m.remaining),marks:tt(S)(k)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}g()}return p},i=Cr(S.compare)([...O(l=>l.from.node)(n),...O(l=>l.to.node)(n)]),o=at(l=>l.from.node!==l.to.node,n),u=T(l=>_=>bt(S)(se)(_.to.node)(1)(l))(A)(o),s=T(l=>_=>bt(S)(se)(_.from.node)(1)(l))(A)(o),a=at(l=>{const _=Me(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),c=at(l=>{const _=Me(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),f=i.length+1|0,d=T(l=>_=>{const h=Me(_)(l);return h.tag==="Just"&&h._1<0?tt(S)(_)(h._1+f|0)(l):l})(r({remaining:at(l=>!Ye(dn)(l)(a)&&!Ye(dn)(l)(c),i),marks:A,inDeg:u,outDeg:s,sources:a,sinks:c,nextLeft:1,nextRight:-1}).marks)(i);return T(l=>_=>{if(_.from.node===_.to.node)return l;if(Nf(t)(_.from.node)(_.to.node))return tt(Hi)(b(_.from.node,_.to.node))()(l);const h=Me(_.from.node)(d),p=Me(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?tt(Hi)(b(_.from.node,_.to.node))()(l):l})(A)(n)},D2=T(t=>e=>bt(S)(re)(e.from.node)([e.to.node])(t))(A),I2=t=>e=>{const n=D2(e),r=Cr(S.compare)([...O(o=>o.from.node)(e),...O(o=>o.to.node)(e)]),i=T(o=>u=>tt(S)(u.to.node)()(o))(A)(e);return T(o=>u=>Jf(t)(n)(u)(o))({visiting:A,visited:A,backEdges:A})([...at(o=>!qr(o)(i),r),...at(o=>qr(o)(i),r)]).backEdges},A2=t=>e=>n=>r=>{const i=L2(Bt(s=>a=>b(a,s))(e)),o=S2(n),u=(()=>{if(t==="DepthFirst")return I2(o)(r);if(t==="Greedy")return P2(o)(i)(r);g()})();return{edges:O(s=>E2(b(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},Tf=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},F2=T(t=>e=>tt(S)(e)()(t))(A),tu=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},B2=Bg(S),vn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},wf=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Us=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Q2=te(nt)(zt),R2=t=>e=>Se(S.compare,Ee,t,e),vf=Bt(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),M2=t=>T(e=>n=>({base:(()=>{const r=i=>o=>{let u=i,s=o,a=!0,c;for(;a;){const f=u,d=s;if(d.tag==="Nil"){a=!1,c=f;continue}if(d.tag==="Cons"){u=Tf(f)(d._1),s=d._2;continue}g()}return c};return(e.base+r(0)((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,$t("Cons",o._4,i(o._6,u)));g()};return i(n,Xt)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=i=>{if(i.tag==="Leaf")return A;if(i.tag==="Node")return Yt("Node",i._1,i._2,i._3,i._4+e.base|0,r(i._5),r(i._6));g()};return r(n)})()]}))({base:0,result:[]})(t).result,z2=t=>e=>{const n=F2(t);return B2(t)(vf(at(r=>tu(r.src)(n)&&tu(r.tgt)(n),e)))},H2=t=>e=>{const n=T(i=>o=>bt(S)(re)(o.tgt)([o.src])(bt(S)(re)(o.src)([o.tgt])(i)))(A)(e),r=i=>o=>u=>{let s=i,a=o,c=u,f=!0,d;for(;f;){const l=s,_=a,h=c,p=Qt(m=>J,m=>y=>w("Just",{head:m,tail:y}),l);if(p.tag==="Nothing"){f=!1,d={nodes:h};continue}if(p.tag==="Just"){if(tu(p._1.head)(_)){s=p._1.tail,a=_,c=h;continue}s=[...p._1.tail,...(()=>{const m=vn(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()})()],a=tt(S)(p._1.head)()(_),c=[...h,p._1.head];continue}g()}return d};return T(i=>o=>{if(tu(o)(i.visited))return i;const u=r([o])(i.visited)([]);return{...i,visited:T(s=>a=>tt(S)(a)()(s))(i.visited)(u.nodes),components:[...i.components,u.nodes]}})({visited:A,components:[]})(t).components},W2=t=>e=>n=>{const r=T(o=>u=>bt(S)(se)(u.tgt)(1)(o))(A)(e),i=T(o=>u=>bt(S)(se)(u.src)(1)(o))(A)(e);return T(o=>u=>{const s=vn(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})();if((()=>{const x=vn(u)(i);return(()=>{if(x.tag==="Nothing")return a!==0;if(x.tag==="Just")return a!==x._1;g()})()||a===0})())return o;const c=vn(u)(o.layers),f=(()=>{if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1;g()})(),d=o.layers,l=T(x=>N=>N.tgt===u?{...x,mIn:wf(x.mIn)((()=>{const v=vn(u)(d),k=vn(N.src)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})()-(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;g()})()|0})())}:N.src===u?{...x,mOut:wf(x.mOut)((()=>{const v=vn(N.tgt)(d),k=vn(u)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})()-(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;g()})()|0})())}:x)({mIn:1e9,mOut:1e9})(e),_=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(_<0||h<0)return o;const p=(f-_|0)+1|0,m=(f+h|0)-1|0;if(m<p)return o;const y=T(x=>N=>{const v=Us(N)(o.filling),k=(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})();return k<x.bestFill?{best:N,bestFill:k}:x})({best:f,bestFill:(()=>{const x=Us(f)(o.filling);if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})()})(Ft(p,m));return y.best===f?o:{layers:tt(S)(u)(y.best)(o.layers),filling:tt(nt)(f)((()=>{const x=Us(f)(o.filling);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;g()})())(tt(nt)(y.best)(y.bestFill+1|0)(o.filling))}})({layers:n,filling:Q2(O(o=>b(o,T(u=>s=>(()=>{const a=vn(s)(n);return a.tag==="Nothing"?!1:a.tag==="Just"&&a._1===o})()?u+1|0:u)(0)(t)))(Ft(0,T(o=>u=>Tf(o)((()=>{const s=vn(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(0)(t))))})(t).layers},O2=t=>e=>W2(t)(vf(e))(T(R2)(A)(M2(O(n=>z2(n)(e))(H2(t)(e))))),Y2=t=>t,Nr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},eu=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bf=(()=>{const t=Ue.unfoldr(xn);return e=>t(Ke("IterNode",e,yn))})(),$2=Y2("NetworkSimplex"),q2=t=>e=>T(n=>r=>{const i=T(eu)(0)(xt(o=>Nr(o)(n))(r));return T(o=>u=>tt(S)(u)(i)(o))(n)(r)})(e)(t),X2=t=>e=>({layers:O(n=>at(r=>{const i=Nr(r)(e);return i.tag==="Nothing"?!1:i.tag==="Just"&&i._1===n},t))(Ft(0,(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(c.tag==="Nil"){u=!1,s=a;continue}if(c.tag==="Cons"){i=eu(a)(c._1),o=c._2;continue}g()}return s})(0)((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,$t("Cons",r._4,n(r._6,i)));g()};return n(e,Xt)})()))),nodeLayer:e}),V2=t=>e=>n=>{const r=T(i=>o=>tt(S)(o)(!0)(i))(A)(e);return T(i=>o=>tt(S)(o._1)(o._2)(i))(O2(e)(xt(i=>i.from.node===i.to.node||(()=>{const o=Nr(i.from.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()||(()=>{const o=Nr(i.to.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()?J:w("Just",{src:i.from.node,tgt:i.to.node}))(t)))(bf(n))},U2=t=>e=>n=>r=>{const i=s=>a=>{const c=Nr(a)(s);if(c.tag==="Just")return s;if(c.tag==="Nothing"){const f=at(l=>l!==a,(()=>{const l=Nr(a)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;g()})()),d=T(i)(s)(f);return tt(S)(a)(1+T(eu)(0)(xt(l=>Nr(l)(d))(f))|0)(d)}g()},o=T(i)(A)(n),u=(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=eu(_)(h._1),f=h._2;continue}g()}return l})(1)((()=>{const s=(a,c)=>{if(a.tag==="Leaf")return c;if(a.tag==="Node")return s(a._5,$t("Cons",a._4,s(a._6,c)));g()};return s(o,Xt)})());return T(s=>a=>tt(S)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return A;if(a.tag==="Node")return Yt("Node",a._1,a._2,a._3,u-a._4|0,s(a._5),s(a._6));g()};return s(o)})())(bf(r))},K2=T(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return tt(S)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return tt(S)(e._1.node)(0)(t)}return t})(A),Z2=T(t=>e=>bt(S)(re)(e.to.node)([e.from.node])(t))(A),j2=T(t=>e=>bt(S)(re)(e.from.node)([e.to.node])(t))(A),tx=t=>e=>n=>r=>{const i=j2(n),o=Z2(n),u=K2(e);return X2(r)(q2(xt(s=>s.tag==="SameLayer"?w("Just",s._1.nodes):J)(e))((()=>{if(t==="LongestPath")return U2(i)(o)(r)(u);if(t==="NetworkSimplex")return V2(n)(r)(u);g()})()))},ex=te(S)(zt),nx=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},kf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Lf=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Wi=te(S)(zt),rx=te(S)(zt),Ef=(()=>{const t=O(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>we(t(e))})(),ix=t=>e=>n=>r=>{const i=ex(O(u=>b(u.edge,u))(r)),o=u=>0<u.nodes.length&&(()=>{const s=nx(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return O(u=>{if(u.nodes.length<=2){const f=kf(u.edgeId)(i);if(f.tag==="Just"){const d=o(u),l=Ai(Ii(d?Ef(f._1.segments):f._1.segments));return{...f._1,edge:u.edgeId,segments:l,bends:ve(_=>h=>_.end,l,Lt(1,l.length,l)),reversed:d}}if(f.tag==="Nothing")return{edge:u.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};g()}const s=wt(xt(f=>kf(f)(i))(ve(f=>d=>u.edgeId+":"+f+"->"+d,u.nodes,Lt(1,u.nodes.length,u.nodes))))(f=>f.segments),a=o(u),c=Ai(Ii(a?Ef(s):s));return{edge:u.edgeId,segments:c,bends:ve(f=>d=>f.end,c,Lt(1,c.length,c)),bendType:[],jumps:[],reversed:a}})(t)},ox={layers:[],edges:[],chains:[]},ux={nodeGap:3,layerGap:2,iterations:8,layerer:$2,cycleBreaker:C2,compactPostRouting:!0,compactionSpacings:Zm},sx=t=>({pos:b(0,0),size:b(T(e=>n=>Lf(e)(n.position._1+n.size._1))(0)(t),T(e=>n=>Lf(e)(n.position._2+n.size._2))(0)(t))}),ax=t=>e=>n=>{const r=Wi(O(c=>b(c.id,c.ports))(e.nodes)),i=at(c=>ye(3)(c.node)!=="$d:",n.placements),o=ix(n.withDummies.chains)(n.acyclic.reversedEdges)(rx(O(c=>b(c.id,b(c.from.node,c.to.node)))(e.edges)))(Dy(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(of(n.ordered)(at(c=>c.from.node!==c.to.node,n.withDummies.edges))((()=>{const c=f=>{if(f.tag==="Leaf")return A;if(f.tag==="Node")return Yt("Node",f._1,f._2,f._3,b(f._4._1*4,f._4._2),c(f._5),c(f._6));g()};return c(Wi(O(f=>b(f.id,f.size))(e.nodes)))})()))),u=t.compactPostRouting?ey()(t.compactionSpacings)({nodes:i,edges:e.edges,paths:o,ports:r}):{nodes:i,edges:o},s=O(c=>{const f=Ai(Ii(c.segments));return{...c,segments:f,bends:ve(d=>l=>d.end,f,Lt(1,f.length,f))}})(u.edges),a=Bt(c=>f=>({...f,jumps:My(c)(f)(s)}))(s);return{nodes:u.nodes,edges:a,boundingBox:sx(u.nodes),metrics:Lp(u.nodes)(a)(0)}},cx=t=>e=>n=>{const r=Wi(O(o=>b(o.id,o.size))(e.nodes)),i={...n,placements:_2({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(Wi(O(o=>b(o.id,o.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(of(n.ordered)(n.withDummies.edges)((()=>{const o=u=>{if(u.tag==="Leaf")return A;if(u.tag==="Node")return Yt("Node",u._1,u._2,u._3,b(u._4._1*4,u._4._2),o(u._5),o(u._6));g()};return o(r)})()))};return{pipeline:i,result:ax(t)(e)(i)}},gx=t=>e=>n=>cx(t)(e)({...n,ordered:b2({iterations:t.iterations,constraints:e.constraints,modelOrder:Wi(Bt(r=>i=>b(i.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),fx=t=>e=>n=>gx(t)(e)({...n,withDummies:zy(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),_x=t=>e=>{const n=O(i=>i.id)(e.nodes),r=A2(t.cycleBreaker)(n)(e.constraints)(e.edges);return fx(t)(e)({acyclic:r,layered:tx(t.layerer)(e.constraints)(r.edges)(n),withDummies:ox,ordered:[],placements:[]})},nu=t=>t,dx=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Jr=nu("TopSide"),Tr=nu("BottomSide"),wr=nu("LeftSide"),vr=nu("RightSide"),lx=t=>{const e=it.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=it.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Cf=t=>e=>n=>{const r=dx(t.h*.12)(t.w*.2),i=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*Ce(lx((()=>{const o=(n-(t.x+i))/i;return 1-o*o})()))},ze=t=>e=>n=>r=>{let i=t,o=e,u=n,s=r,a=!0,c;for(;a;){const f=i,d=o,l=u,_=s;if(f==="Rectangle"){if(l==="TopSide"){a=!1,c=d.y;continue}if(l==="BottomSide"){a=!1,c=d.y+d.h;continue}if(l==="LeftSide"){a=!1,c=d.x;continue}if(l==="RightSide"){a=!1,c=d.x+d.w;continue}i=tr,o=d,u=l,s=_;continue}if(f==="Cylinder"){if(l==="TopSide"){a=!1,c=Cf(d)(-1)(_);continue}if(l==="BottomSide"){a=!1,c=Cf(d)(1)(_);continue}if(l==="LeftSide"){a=!1,c=d.x;continue}if(l==="RightSide"){a=!1,c=d.x+d.w;continue}}i=tr,o=d,u=l,s=_}return c},Sf=t=>e=>{const n=e.y-t.y,r=n<0?-n:n,i=e.x-(t.x+t.w),o=i<0?-i:i,u=e.x-t.x,s=u<0?-u:u,a=e.y-(t.y+t.h),c=a<0?-a:a;return r<=c&&r<=s&&r<=o?Jr:c<=s&&c<=o?Tr:s<=o?wr:vr},hx=(()=>{const t=Ue.unfoldr(xn);return e=>t(Ke("IterNode",e,yn))})(),Ks=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Oi=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Yi=te(S)(zt),px=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},mx=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},yx=T(t=>e=>tt(S)(e)()(t))(A),xx=T(t=>e=>tt(S)(e)()(t))(A),ru=cr.traverse(Pu),iu=te(S)(zt),Nx=t=>e=>Se(S.compare,Ee,t,e),Jx=T(t=>e=>tt(S)(e)()(t))(A),Tx=te(S)(zt),wx=t=>e=>Se(S.compare,Ee,t,e),vx=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Gf=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bx=t=>e=>({...e,edges:Yi(O(n=>b(n._1,(()=>{const r=Ks(n._1)(t);if(r.tag==="Nothing")return n._2;if(r.tag==="Just"){const i=Oi(r._1._2)(e.nodes),o=Oi(r._1._1)(e.nodes),u=(()=>{if(o.tag==="Nothing")return n._2;if(o.tag==="Just"){const s=Qt(a=>J,a=>c=>w("Just",{head:a,tail:c}),n._2);if(s.tag==="Nothing")return n._2;if(s.tag==="Just")return[(()=>{const a=Qt(l=>J,l=>_=>w("Just",{head:l,tail:_}),s._1.tail),c=a.tag==="Just"?w("Just",a._1.head):J,f={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},d=(()=>{if(c.tag==="Just"){if((c._1.x>s._1.head.x?c._1.x-s._1.head.x<.5:s._1.head.x-c._1.x<.5)&&s._1.head.x>=f.x-.5&&s._1.head.x<=f.x+f.w+.5)return c._1.y>=f.y+f.h?w("Just",Tr):c._1.y<=f.y?w("Just",Jr):J;if((c._1.y>s._1.head.y?c._1.y-s._1.head.y<.5:s._1.head.y-c._1.y<.5)&&s._1.head.y>=f.y-.5&&s._1.head.y<=f.y+f.h+.5){if(c._1.x>=f.x+f.w)return w("Just",vr);if(c._1.x<=f.x)return w("Just",wr)}return J}if(c.tag==="Nothing")return J;g()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...s._1.head,y:ze(o._1.shape)(f)(Jr)(s._1.head.x)};if(d._1==="BottomSide")return{...s._1.head,y:ze(o._1.shape)(f)(Tr)(s._1.head.x)};if(d._1==="LeftSide")return{...s._1.head,x:ze(o._1.shape)(f)(wr)(s._1.head.y)};if(d._1==="RightSide")return{...s._1.head,x:ze(o._1.shape)(f)(vr)(s._1.head.y)};g()}if(d.tag==="Nothing"){const l={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},_=Sf(l)(s._1.head);if(_==="TopSide")return{...s._1.head,y:ze(o._1.shape)(l)(Jr)(s._1.head.x)};if(_==="BottomSide")return{...s._1.head,y:ze(o._1.shape)(l)(Tr)(s._1.head.x)};if(_==="LeftSide")return{...s._1.head,x:ze(o._1.shape)(l)(wr)(s._1.head.y)};if(_==="RightSide")return{...s._1.head,x:ze(o._1.shape)(l)(vr)(s._1.head.y)}}g()})(),...s._1.tail]}g()})();if(i.tag==="Nothing")return u;if(i.tag==="Just"){const s=fr(u);if(s.tag==="Nothing")return u;if(s.tag==="Just")return Rt(s._1.init)((()=>{const a=fr(s._1.init),c=a.tag==="Just"?w("Just",a._1.last):J,f={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},d=(()=>{if(c.tag==="Just"){if((c._1.x>s._1.last.x?c._1.x-s._1.last.x<.5:s._1.last.x-c._1.x<.5)&&s._1.last.x>=f.x-.5&&s._1.last.x<=f.x+f.w+.5)return c._1.y>=f.y+f.h?w("Just",Tr):c._1.y<=f.y?w("Just",Jr):J;if((c._1.y>s._1.last.y?c._1.y-s._1.last.y<.5:s._1.last.y-c._1.y<.5)&&s._1.last.y>=f.y-.5&&s._1.last.y<=f.y+f.h+.5){if(c._1.x>=f.x+f.w)return w("Just",vr);if(c._1.x<=f.x)return w("Just",wr)}return J}if(c.tag==="Nothing")return J;g()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...s._1.last,y:ze(i._1.shape)(f)(Jr)(s._1.last.x)};if(d._1==="BottomSide")return{...s._1.last,y:ze(i._1.shape)(f)(Tr)(s._1.last.x)};if(d._1==="LeftSide")return{...s._1.last,x:ze(i._1.shape)(f)(wr)(s._1.last.y)};if(d._1==="RightSide")return{...s._1.last,x:ze(i._1.shape)(f)(vr)(s._1.last.y)};g()}if(d.tag==="Nothing"){const l={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},_=Sf(l)(s._1.last);if(_==="TopSide")return{...s._1.last,y:ze(i._1.shape)(l)(Jr)(s._1.last.x)};if(_==="BottomSide")return{...s._1.last,y:ze(i._1.shape)(l)(Tr)(s._1.last.x)};if(_==="LeftSide")return{...s._1.last,x:ze(i._1.shape)(l)(wr)(s._1.last.y)};if(_==="RightSide")return{...s._1.last,x:ze(i._1.shape)(l)(vr)(s._1.last.y)}}g()})())}}g()})()))(hx(e.edges)))}),kx=t=>e=>n=>{const r=Kt(i=>i.id===n)(t.graph.edges);if(r.tag==="Just")return w("Just",r._1);if(r.tag==="Nothing")return Ks(n)(e);g()},Lx=t=>e=>n=>r=>({x:r.position._1*t,y:r.position._2*t,w:r.size._1*t,h:r.size._2*t,label:(()=>{const i=Oi(r.node)(e);if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return r.node;g()})(),shape:(()=>{const i=Oi(r.node)(n);if(i.tag==="Nothing")return tr;if(i.tag==="Just")return i._1;g()})()}),Ex=t=>({id:t,size:b(1,1),ports:[],label:w("Just",t),shape:tr}),Cx=t=>e=>n=>r=>b(r.node,Lx(t)(e)(n)(r)),Pf=t=>{const e=wo(`
6
+ `)(t);return e.length===0?[""]:e},Df=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,$t("Cons",n._4,e(n._6,r)));g()};return Ct(Vt.foldr,e(t.interiors,Xt))},Sx=t=>Yi(xt(e=>w("Just",b(e.edge,{id:e.edge,from:{node:e.from,port:J},to:{node:e.to,port:J},label:J})))(wt(t.scenes)(e=>e.tag==="DataFlow"?xt(n=>n.kind.tag==="SendToken"?w("Just",n.kind._1):J)(e._1.events):[]))),If=t=>{const e=zl(t),n=at(i=>px(i.id)(e.nodes),t.graph.nodes),r=at(i=>mx(i.id)(e.edges),t.graph.edges);return{nodes:[...n,...O(Ex)(Ct(Qe.foldr,In(S.compare,e.nodes,yx(O(i=>i.id)(n)))))],edges:[...r,...xt(kx(t)(Sx(t)))(Ct(Qe.foldr,In(S.compare,e.edges,xx(O(i=>i.id)(r)))))],constraints:t.graph.constraints}},Gx=t=>{const e=ru(n=>{const r=_g(dg)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})());return()=>{const i=r();return b(n.id,i)}})(If(t).nodes);return()=>{const n=e();return iu(n)}},Af=t=>{const e=Gx(t);return()=>{const n=e(),r=ru(Af)(Df(t))();return T(Nx)(n)(r)}},Px=t=>e=>{const n=Qt(r=>J,r=>i=>w("Just",{head:r,tail:i}),e.segments);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{x:n._1.head.start._1*t,y:n._1.head.start._2*t},...O(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];g()},Dx=t=>e=>b(e.edge,Px(t)(e)),Ix=t=>e=>n=>r=>({nodes:iu(O(Cx(et(4)*t)(e)(n))(r.nodes)),edges:Yi(O(Dx(t))(r.edges)),chipExtras:A,edgeLabels:A}),Ax=t=>T(e=>n=>{if(n.tag==="Structural")return e;if(n.tag==="DataFlow")return T(r=>i=>{if(i.kind.tag==="SendToken")return T(o=>u=>tt(S)(u)()(o))(r)(i.kind._1.labels);if(i.kind.tag==="FillNodeWithoutTransition")return T(o=>u=>tt(S)(u)()(o))(r)(i.kind._1.labels);g()})(e)(n._1.events);if(n.tag==="Hold"||n.tag==="EnterNode"||n.tag==="ExitNode")return e;g()})(A)(t.scenes),Fx=t=>{const e=ru(n=>{const r=_g(dg)(n);return()=>{const i=r();return b(n,{labelW:i,charCount:jn(Rr(n)),lineCount:1})}})(Ct(Qe.foldr,Jx(wt(Ct(Qe.foldr,Ax(t)))(Pf))));return()=>{const n=e();return Tx(n)}},Ff=t=>{const e=Fx(t);return()=>{const n=e(),r=ru(Ff)(Df(t))();return T(wx)(n)(r)}},Bx=et(4)*8,Qx=t=>e=>{const n=vp(Bx)(t)(wp(Tp)(If(e)));return{...bx(Yi(O(r=>b(r.id,b(r.from.node,r.to.node)))(n.edges)))(Ix(8)(iu(O(r=>b(r.id,(()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;g()})()))(n.nodes)))(iu(O(r=>b(r.id,r.shape))(n.nodes)))(_x(ux)(n).result)),edgeLabels:Yi(xt(r=>r.label.tag==="Just"?w("Just",b(r.id,r.label._1)):J)(n.edges))}},Rx=t=>wt(t.scenes)(e=>{if(e.tag==="Structural")return[];if(e.tag==="DataFlow")return e._1.events;if(e.tag==="Hold")return[];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()}),Mx=t=>e=>n=>{const r=i=>{const o=xt(u=>{const s=vx(u)(t);return s.tag==="Just"?w("Just",{w:s._1.labelW+28,h:et(mp(1)(s._1.lineCount))*13.2+12}):J})(wt(i)(Pf));return o.length===0?J:w("Just",{w:T(Gf)(0)(O(u=>u.w)(o)),h:T(Gf)(0)(O(u=>u.h)(o))})};return T(i=>o=>{if(o.kind.tag==="SendToken"){const u=Ks(o.kind._1.edge)(n.edges),s=r(o.kind._1.labels);if(s.tag==="Just"&&u.tag==="Just"){const a=s._1;return bt(S)(re)(o.kind._1.edge)(O(c=>({x:c.x+14+a.w,y:c.y-6-8-a.h}))(u._1))(i)}return i}if(o.kind.tag==="FillNodeWithoutTransition"){const u=Oi(o.kind._1.node)(n.nodes),s=r(o.kind._1.labels);return s.tag==="Just"&&u.tag==="Just"?bt(S)(re)("__fill__:"+o.kind._1.node)((()=>{const a=u._1.y-s._1.h-14,c=u._1.x+u._1.w/2,f=c-s._1.w/2,d=c+s._1.w/2,l=u._1.y-14;return[{x:f,y:a},{x:d,y:a},{x:f,y:l},{x:d,y:l}]})())(i):i}g()})(A)(Rx(e))},Bf=t=>e=>n=>({layout:(()=>{const r=Qx(t)(n);return{...r,chipExtras:Mx(e)(n)(r)}})(),interiors:(()=>{const r=Bf(t)(e),i=o=>{if(o.tag==="Leaf")return A;if(o.tag==="Node")return Yt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(n.interiors)})()}),Qf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Zs=t=>e=>n=>{const r=t<.05?t:.05,i=(u,s)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return i((()=>{const a=Qf(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};g()})(),f=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 tt(S)(s._3)({x:c.x+f*r,y:c.y+d*r,vx:f,vy:d})(i(u,s._5))})(),s._6);g()},o=i(A,e);return{springs:o,applied:(()=>{const u=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return u((()=>{const c=u(s,a._5),f=Qf(a._3)(o);if(f.tag==="Just")return tt(S)(a._3)({...a._4,x:f._1.x,y:f._1.y})(c);if(f.tag==="Nothing")return tt(S)(a._3)(a._4)(c);g()})(),a._6);g()};return u(A,e)})()}};(function(){var t={},e="Pure",n="Throw",r="Catch",i="Sync",o="Async",u="Bind",s="Bracket",a="Fork",c="Sequential",f="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",y="Finalized",x="Forked";function N(I,z,$,X){this.tag=I,this._1=z,this._2=$,this._3=X}function v(I){var z=function($,X,Y){return new N(I,$,X,Y)};return z.tag=I,z}function k(I){return new N(e,void 0)}function L(I){try{I()}catch(z){setTimeout(function(){throw z},0)}}function E(I,z,$){try{return z($())}catch(X){return I(X)}}function B(I,z,$){try{return z($)()}catch(X){return $(I(X))(),k}}var q=(function(){var I=1024,z=0,$=0,X=new Array(I),Y=!1;function W(){var K;for(Y=!0;z!==0;)z--,K=X[$],X[$]=void 0,$=($+1)%I,K();Y=!1}return{isDraining:function(){return Y},enqueue:function(K){var Z;z===I&&(Z=Y,W(),Y=Z),X[($+z)%I]=K,z++,Y||W()}}})();function j(I){var z={},$=0,X=0;return{register:function(Y){var W=$++;Y.onComplete({rethrow:!0,handler:function(K){return function(){X--,delete z[W]}}})(),z[W]=Y,X++},isEmpty:function(){return X===0},killAll:function(Y,W){return function(){if(X===0)return W();var K=0,Z={};function ct(gt){Z[gt]=z[gt].kill(Y,function(yt){return function(){delete Z[gt],K--,I.isLeft(yt)&&I.fromLeft(yt)&&setTimeout(function(){throw I.fromLeft(yt)},0),K===0&&W()}})()}for(var _t in z)z.hasOwnProperty(_t)&&(K++,ct(_t));return z={},$=0,X=0,function(gt){return new N(i,function(){for(var yt in Z)Z.hasOwnProperty(yt)&&Z[yt]()})}}}}}var G=0,P=1,V=2,U=3,M=4,H=5,R=6;function C(I,z,$){var X=0,Y=G,W=$,K=null,Z=null,ct=null,_t=null,gt=null,yt=0,St=0,Ht=null,pt=!0;function Wt(ot){for(var dt,ut,st;;)switch(dt=null,ut=null,st=null,Y){case V:Y=P;try{W=ct(W),_t===null?ct=null:(ct=_t._1,_t=_t._2)}catch(Jt){Y=H,K=I.left(Jt),W=null}break;case U:I.isLeft(W)?(Y=H,K=W,W=null):ct===null?Y=H:(Y=V,W=I.fromRight(W));break;case P:switch(W.tag){case u:ct&&(_t=new N(_,ct,_t)),ct=W._2,Y=P,W=W._1;break;case e:ct===null?(Y=H,W=I.right(W._1)):(Y=V,W=W._1);break;case i:Y=U,W=E(I.left,I.right,W._1);break;case o:Y=M,W=B(I.left,W._1,function(Jt){return function(){X===ot&&(X++,q.enqueue(function(){X===ot+1&&(Y=U,W=Jt,Wt(X))}))}});return;case n:Y=H,K=I.left(W._1),W=null;break;case r:ct===null?gt=new N(_,W,gt,Z):gt=new N(_,W,new N(_,new N(h,ct,_t),gt,Z),Z),ct=null,_t=null,Y=P,W=W._1;break;case s:yt++,ct===null?gt=new N(_,W,gt,Z):gt=new N(_,W,new N(_,new N(h,ct,_t),gt,Z),Z),ct=null,_t=null,Y=P,W=W._1;break;case a:Y=U,dt=C(I,z,W._2),z&&z.register(dt),W._1&&dt.run(),W=I.right(dt);break;case c:Y=P,W=F(I,z,W._1);break}break;case H:if(ct=null,_t=null,gt===null)Y=R,W=Z||K||W;else switch(dt=gt._3,st=gt._1,gt=gt._2,st.tag){case r:Z&&Z!==dt&&yt===0?Y=H:K&&(Y=P,W=st._2(I.fromLeft(K)),K=null);break;case h:Z&&Z!==dt&&yt===0||K?Y=H:(ct=st._1,_t=st._2,Y=V,W=I.fromRight(W));break;case s:yt--,K===null&&(ut=I.fromRight(W),gt=new N(_,new N(p,st._2,ut),gt,dt),(Z===dt||yt>0)&&(Y=P,W=st._3(ut)));break;case p:gt=new N(_,new N(y,W,K),gt,Z),Y=P,Z&&Z!==dt&&yt===0?W=st._1.killed(I.fromLeft(Z))(st._2):K?W=st._1.failed(I.fromLeft(K))(st._2):W=st._1.completed(I.fromRight(W))(st._2),K=null,yt++;break;case m:yt++,gt=new N(_,new N(y,W,K),gt,Z),Y=P,W=st._1;break;case y:yt--,Y=H,W=st._1,K=st._2;break}break;case R:for(var Nt in Ht)Ht.hasOwnProperty(Nt)&&(pt=pt&&Ht[Nt].rethrow,L(Ht[Nt].handler(W)));Ht=null,Z&&K?setTimeout(function(){throw I.fromLeft(K)},0):I.isLeft(W)&&pt&&setTimeout(function(){if(pt)throw I.fromLeft(W)},0);return;case G:Y=P;break;case M:return}}function Tt(ot){return function(){if(Y===R)return pt=pt&&ot.rethrow,ot.handler(W)(),function(){};var dt=St++;return Ht=Ht||{},Ht[dt]=ot,function(){Ht!==null&&delete Ht[dt]}}}function mt(ot,dt){return function(){if(Y===R)return dt(I.right(void 0))(),function(){};var ut=Tt({rethrow:!1,handler:function(){return dt(I.right(void 0))}})();switch(Y){case G:Z=I.left(ot),Y=R,W=Z,Wt(X);break;case M:Z===null&&(Z=I.left(ot)),yt===0&&(Y===M&&(gt=new N(_,new N(m,W(ot)),gt,Z)),Y=H,W=null,K=null,Wt(++X));break;default:Z===null&&(Z=I.left(ot)),yt===0&&(Y=H,W=null,K=null)}return ut}}function ft(ot){return function(){var dt=Tt({rethrow:!1,handler:ot})();return Y===G&&Wt(X),dt}}return{kill:mt,join:ft,onComplete:Tt,isSuspended:function(){return Y===G},run:function(){Y===G&&(q.isDraining()?Wt(X):q.enqueue(function(){Wt(X)}))}}}function D(I,z,$,X){var Y=0,W={},K=0,Z={},ct=new Error("[ParAff] Early exit"),_t=null,gt=t;function yt(Tt,mt,ft){var ot=mt,dt=null,ut=null,st=0,Nt={},Jt,kt;t:for(;;)switch(Jt=null,ot.tag){case x:if(ot._3===t&&(Jt=W[ot._1],Nt[st++]=Jt.kill(Tt,function(Ot){return function(){st--,st===0&&ft(Ot)()}})),dt===null)break t;ot=dt._2,ut===null?dt=null:(dt=ut._1,ut=ut._2);break;case f:ot=ot._2;break;case d:case l:dt&&(ut=new N(_,dt,ut)),dt=ot,ot=ot._1;break}if(st===0)ft(I.right(void 0))();else for(kt=0,Jt=st;kt<Jt;kt++)Nt[kt]=Nt[kt]();return Nt}function St(Tt,mt,ft){var ot,dt,ut,st,Nt,Jt;for(I.isLeft(Tt)?(ot=Tt,dt=null):(dt=Tt,ot=null);;){if(ut=null,st=null,Nt=null,Jt=null,_t!==null)return;if(mt===null){X(ot||dt)();return}if(mt._3!==t)return;switch(mt.tag){case f:ot===null?(mt._3=I.right(mt._1(I.fromRight(dt))),dt=mt._3):mt._3=ot;break;case d:if(ut=mt._1._3,st=mt._2._3,ot){if(mt._3=ot,Nt=!0,Jt=K++,Z[Jt]=yt(ct,ot===ut?mt._2:mt._1,function(){return function(){delete Z[Jt],Nt?Nt=!1:ft===null?St(ot,null,null):St(ot,ft._1,ft._2)}}),Nt){Nt=!1;return}}else{if(ut===t||st===t)return;dt=I.right(I.fromRight(ut)(I.fromRight(st))),mt._3=dt}break;case l:if(ut=mt._1._3,st=mt._2._3,ut===t&&I.isLeft(st)||st===t&&I.isLeft(ut))return;if(ut!==t&&I.isLeft(ut)&&st!==t&&I.isLeft(st))ot=dt===ut?st:ut,dt=null,mt._3=ot;else if(mt._3=dt,Nt=!0,Jt=K++,Z[Jt]=yt(ct,dt===ut?mt._2:mt._1,function(){return function(){delete Z[Jt],Nt?Nt=!1:ft===null?St(dt,null,null):St(dt,ft._1,ft._2)}}),Nt){Nt=!1;return}break}ft===null?mt=null:(mt=ft._1,ft=ft._2)}}function Ht(Tt){return function(mt){return function(){delete W[Tt._1],Tt._3=mt,St(mt,Tt._2._1,Tt._2._2)}}}function pt(){var Tt=P,mt=$,ft=null,ot=null,dt,ut;t:for(;;)switch(dt=null,ut=null,Tt){case P:switch(mt.tag){case f:ft&&(ot=new N(_,ft,ot)),ft=new N(f,mt._1,t,t),mt=mt._2;break;case d:ft&&(ot=new N(_,ft,ot)),ft=new N(d,t,mt._2,t),mt=mt._1;break;case l:ft&&(ot=new N(_,ft,ot)),ft=new N(l,t,mt._2,t),mt=mt._1;break;default:ut=Y++,Tt=H,dt=mt,mt=new N(x,ut,new N(_,ft,ot),t),dt=C(I,z,dt),dt.onComplete({rethrow:!1,handler:Ht(mt)})(),W[ut]=dt,z&&z.register(dt)}break;case H:if(ft===null)break t;ft._1===t?(ft._1=mt,Tt=P,mt=ft._2,ft._2=t):(ft._2=mt,mt=ft,ot===null?ft=null:(ft=ot._1,ot=ot._2))}for(gt=mt,ut=0;ut<Y;ut++)W[ut].run()}function Wt(Tt,mt){_t=I.left(Tt);var ft;for(var ot in Z)if(Z.hasOwnProperty(ot)){ft=Z[ot];for(ot in ft)ft.hasOwnProperty(ot)&&ft[ot]()}Z=null;var dt=yt(Tt,gt,mt);return function(ut){return new N(o,function(st){return function(){for(var Nt in dt)dt.hasOwnProperty(Nt)&&dt[Nt]();return k}})}}return pt(),function(Tt){return new N(o,function(mt){return function(){return Wt(Tt,mt)}})}}function F(I,z,$){return new N(o,function(X){return function(){return D(I,z,$,X)}})}return N.EMPTY=t,N.Pure=v(e),N.Throw=v(n),N.Catch=v(r),N.Sync=v(i),N.Async=v(o),N.Bind=v(u),N.Bracket=v(s),N.Fork=v(a),N.Seq=v(c),N.ParMap=v(f),N.ParApply=v(d),N.ParAlt=v(l),N.Fiber=C,N.Supervisor=j,N.Scheduler=q,N.nonCanceler=k,N})();let Rf=null;function zx(){return Rf||(typeof document>"u"?null:Rf=document.createElement("canvas").getContext("2d"))}const js=new Map;function Mf(t,e,n,r,i,o){const u=`${n} ${e}px ${t}`,s=u+"|"+r;if(js.has(s))return js.get(s);const a=zx();if(!a)return o;a.font=u;const c=i(a.measureText(r)),f=typeof document<"u"?document.fonts:null;if(!f||f.check(u))js.set(s,c);else if(f&&f.load)try{f.load(u)}catch{}return c}const Hx=(t,e,n,r)=>Mf(t,e,n,r,i=>i.width,-1),Wx=(t,e,n,r)=>Mf(t,e,n,r,i=>({ascent:i.actualBoundingBoxAscent,descent:i.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),zf=t=>e=>{const n=Hx(t.family,t.size,t.weight,Rr(e));return n<0?et(ko(e).length)*t.size*.62:n},Hf=t=>e=>{const n=Wx(t.family,t.size,t.weight,Rr(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},Wf=t=>t,Of=t=>t,ou=t=>t,Yf=t=>t,Ox=t=>t,$f=t=>t,qf=t=>t,Yx=qf("BaselineTop"),ur=qf("BaselineMiddle"),ta=$f("AlignLeft"),Xr=$f("AlignCenter"),be=Ox("RoundJoin"),pn=Yf("ButtCap"),bn=Yf("RoundCap"),$x=ou("LayerPolyOut"),qx=ou("LayerPolyIn"),Xx=ou("LayerNodeMask"),Vx=ou("LayerOverlay"),uu=Of("NonZero"),Ux=Of("EvenOdd"),Xf=Wf("Normal"),su=Wf("Difference"),ue={r:255,g:255,b:255,a:255},Mn={r:26,g:26,b:26,a:255},ea=t=>e=>Math.imul(t,e),Vr=t=>{const e=t+1831565813|0,n=ea(e^e>>>15)(e|1),r=n^(n+ea(n^n>>>7)(n|61)|0),i=r^r>>>14;return{prng:i,value:i<0?(et(i)+4294967296)/4294967296:et(i)/4294967296}},pe=t=>e=>n=>{const r=Vr(n);return{prng:r.prng,value:t+r.value*(e-t)}},na=t=>e=>T(n=>r=>ea(n^r)(-2048144789))(e)(O(er)(hr(t))),Kx=t=>t,Vf=t=>t,Zx=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},un=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Uf=t=>e=>n=>{const r=nt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=nt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},ra=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},jx=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},tN=Vf("FlatLevel"),eN=Vf("NestedLevel"),Kf=Kx("GenieSilhouette"),nN=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const i=Vr(t);return{prng:i.prng,yLift:i.value*n.yJitter*r}},rN=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const i=Vr(t);return{prng:i.prng,dx:(i.value*2-1)*n.xJitter*r}},Zf=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,i=Ce(r*r+n*n),o=(t.r*t.r-e.r*e.r+i*i)/(2*i),u=Ce(Zx(0)(t.r*t.r-o*o)),s=t.cx+o*r/i,a=t.cy+o*n/i,c={x:s-u*n/i,y:a+u*r/i},f={x:s+u*n/i,y:a-u*r/i};return i===0||i>t.r+e.r?{x:(t.cx+e.cx)/2,y:t.cy}:c.y<f.y?c:f},iN=t=>e=>{const n=un(e)(un(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},oN=t=>e=>n=>r=>i=>o=>{if(e)return{prng:t,r:i};if(n)return{prng:t,r:i*(1+o.rJitter)};if(r)return{prng:t,r:i*o.smallScale};const u=Vr(t);return{prng:u.prng,r:i*(1+u.value*o.rJitter)}},jf=t=>{const e=un(t.w)(t.h)/2;return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,4,t.x+t.w-e+.5522847498307936*e,t.y,t.x+t.w,t.y+e-.5522847498307936*e,t.x+t.w,t.y+e,4,t.x+t.w,t.y+e+.5522847498307936*e,t.x+t.w-e+.5522847498307936*e,t.y+t.h,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,4,t.x+e-.5522847498307936*e,t.y+t.h,t.x,t.y+e+.5522847498307936*e,t.x,t.y+e,4,t.x,t.y+e-.5522847498307936*e,t.x+e-.5522847498307936*e,t.y,t.x+e,t.y,5]},uN=t=>e=>n=>{const r=Vr(t),i=e.length;return i===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const o=Uf(0)(i-1|0)(ce(mn(r.value*et(n))));return o>=0&&o<e.length?e[o]:-1})()}},sN=t=>e=>{const n=Vr(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const i=Uf(0)(r-1|0)(ce(mn(n.value*et(r))));return i>=0&&i<e.length?e[i]:-1})()}},t_=t=>{const e=un(t.w*.18)(t.h*.6);return[1,t.x+e,t.y,2,t.x+t.w,t.y,2,t.x+t.w-e,t.y+t.h,2,t.x,t.y+t.h,5]},e_=t=>[1,t.x,t.y,2,t.x+t.w,t.y,2,t.x+t.w,t.y+t.h*.85,4,t.x+t.w*.66,t.y+t.h*1.05,t.x+t.w*.34,t.y+t.h*.65,t.x,t.y+t.h*.85,5],n_={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},aN=t=>{const e=un(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,i=t.x+n;return[1,t.x,r,4,t.x,r+.5522847498*e,i-.5522847498*n,r+e,i,r+e,4,i+.5522847498*n,r+e,t.x+t.w,r+.5522847498*e,t.x+t.w,r]},r_=t=>{const e=un(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+t.h+5,i=t.y+e,o=r-e,u=t.x+n;return[1,t.x,i,4,t.x,i-.5522847498*e,u-.5522847498*n,t.y,u,t.y,4,u+.5522847498*n,t.y,t.x+t.w,i-.5522847498*e,t.x+t.w,i,2,t.x+t.w,o,4,t.x+t.w,o+.5522847498*e,u+.5522847498*n,r,u,r,4,u-.5522847498*n,r,t.x,o+.5522847498*e,t.x,o,5]},i_=t=>e=>{const n=e.y+e.h,r=hd(t.rBase*e.h)(e.w/(2*(1+(et(t.minN)-1)*t.stepRatio))),i=e.w-2*r,o=2*r*t.stepRatio,u=ra(t.minN)(i<=0||o<=0?t.minN:ce(Dn(i/o))+1|0),s=u>=3?Ft(1,u-2|0):[],a=s.length,c=Gn(a+1|0,2),f=c<1?[]:Lt(0,c,s),d=sN(t.seed)((()=>{const m=a-c|0;return m<1?s:Lt(m,s.length,s)})()),l=d.idx,_=uN(d.prng)(at(m=>m!==l,f))(ra(1)(f.length-(Ye(Er)(l)(f)?1:0)|0)),h=_.idx,p=u>=2?i/(et(u)-1):0;return T(m=>y=>{const x=y===h,N=y===l,v=y===0||y===(u-1|0),k=oN(m.prng)(v)(N)(x)(r)(t),L=nN(k.prng)(v)(t)(e.h),E=rN(L.prng)(v)(t)(p);return{prng:E.prng,circles:Rt(m.circles)({cx:e.x+jx(k.r)(e.w-k.r)((u>=2?r+et(y)/(et(u)-1)*i+E.dx:r+0*i+E.dx)+(N?t.heroShift*p:x?-1*t.smallShift*p:0)),cy:n-L.yLift,r:k.r})}})({prng:_.prng,circles:[]})(Ft(0,u-1|0)).circles},o_=t=>e=>{const n=t.length;return Bt(r=>i=>({c:i,p1:(()=>{if(r===0)return{x:i.cx-i.r,y:e};const o=r-1|0;return o>=0&&o<t.length?Zf(t[o])(i):{x:i.cx-i.r,y:e}})(),p2:(()=>{if(r===(n-1|0))return{x:i.cx+i.r,y:e};const o=r+1|0;return o>=0&&o<t.length?Zf(i)(t[o]):{x:i.cx+i.r,y:e}})()}))(t)},u_=t=>{const e=un(t.h*.4)(t.w*.2);return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,2,t.x+t.w,t.y+t.h/2,2,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,2,t.x,t.y+t.h/2,5]},cN=t=>e=>n=>{const r=dr(e.y-t.cy)(e.x-t.cx),i=dr(n.y-t.cy)(n.x-t.cx),o=i>r?i-r:i+6.283185307179586-r,u=ra(1)(ce(io(o/1.5707963267948966))),s=o/et(u),a=1.3333333333333333*pd(s/4);return wt(Ft(0,u-1|0))(c=>{const f=r+et(c+1|0)*s,d=t.cx+t.r*rn(f),l=t.cy+t.r*Ve(f),_=r+et(c)*s;return[4,t.cx+t.r*rn(_)-a*t.r*Ve(_),t.cy+t.r*Ve(_)+a*t.r*rn(_),d+a*t.r*Ve(f),l-a*t.r*rn(f),d,l]})},s_=t=>e=>{const n=t.h*.38,r=o_(i_(n_)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),i=un(e)(un(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...wt(r)(o=>cN(o.c)(o.p1)(o.p2)),2,t.x+t.w,t.y+t.h-i,3,t.x+t.w,t.y+t.h,t.x+t.w-i,t.y+t.h,2,t.x+i,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-i,2,r[0].p1.x,r[0].p1.y,5]:iN(t)(e)},ia=t=>e=>n=>r=>i=>o=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(i)(o);if(e==="Cylinder"){const u=r_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Parallelogram"){const u=t_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Diamond"){const u=u_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Ellipse"){const u=jf(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Document"){const u=e_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Cloud"){const u=s_(n)(r);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}return t.drawRoundedRect(n)(r)(i)(o)},gN=t=>()=>t.clip("evenodd"),fN=t=>e=>()=>{t.filter=`blur(${e}px)`},_N=t=>e=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(e.tile,.001))),r=Math.max(2,Math.round(e.tile*n)),i=document.createElement("canvas");i.width=r,i.height=r;const o=i.getContext("2d");o.scale(n,n),o.fillStyle=e.bgCss,o.fillRect(0,0,e.tile,e.tile),o.fillStyle=e.dotCss,o.beginPath(),o.arc(e.tile/2,e.tile/2,e.dotR,0,2*Math.PI),o.fill();const u=t.createPattern(i,"repeat");u&&typeof u.setTransform=="function"&&u.setTransform(new DOMMatrix().translateSelf(e.ox,e.oy).scaleSelf(1/n,1/n)),t.save(),t.fillStyle=u,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},oa=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ua=t=>e=>n=>{const r=e.stroke;return()=>{const i=r.value,o=zd(t)(n);if(i!==n)return o(),e.stroke.value=n}},dN=t=>e=>n=>{const r=e.font;return()=>{const i=r.value,o=Ud(t)(n);if(i!==n)return o(),e.font.value=n}},$i=t=>e=>n=>{const r=e.fill;return()=>{const i=r.value,o=Md(t)(n);if(i!==n)return o(),e.fill.value=n}},au=t=>e=>{const n=e.length,r=o=>{if(o>=n)return()=>{};const u=o>=0&&o<e.length?e[o]:0;if(u===1){const s=fc(t)((()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===2){const s=fi(t)((()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===3){const s=_i(t)({cpx:(()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})(),cpy:(()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=o+3|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=o+4|0;return c>=0&&c<e.length?e[c]:0})()}),a=r(o+5|0);return()=>(s(),a())}if(u===4){const s=Zd(t)({cp1x:(()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})(),cp1y:(()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})(),cp2x:(()=>{const c=o+3|0;return c>=0&&c<e.length?e[c]:0})(),cp2y:(()=>{const c=o+4|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=o+5|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=o+6|0;return c>=0&&c<e.length?e[c]:0})()}),a=r(o+7|0);return()=>(s(),a())}if(u===5){const s=_c(t),a=r(o+1|0);return()=>(s(),a())}return()=>{}},i=gc(t);return()=>(i(),r(0)())},lN=t=>e=>n=>r=>i=>o=>{const u=oa(o)(oa(r/2)(i/2)),s=fc(t)(e+u)(n);return()=>(s(),fi(t)(e+r-u)(n)(),_i(t)({cpx:e+r,cpy:n,x:e+r,y:n+u})(),fi(t)(e+r)(n+i-u)(),_i(t)({cpx:e+r,cpy:n+i,x:e+r-u,y:n+i})(),fi(t)(e+u)(n+i)(),_i(t)({cpx:e,cpy:n+i,x:e,y:n+i-u})(),fi(t)(e)(n+u)(),_i(t)({cpx:e,cpy:n,x:e+u,y:n})(),_c(t)())},hN=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),pN=t=>e=>{const n=$d(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=hN();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0},groupAlpha:{value:1},alphaSaves:{value:[]}}}},mN={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},yN=t=>ee(t.weight)+" "+Ma(t.size)+"px "+t.family,kn=t=>{const e=Ma(et(t.a)/255);return t.a>=255?"rgb("+ee(t.r)+","+ee(t.g)+","+ee(t.b)+")":"rgba("+ee(t.r)+","+ee(t.g)+","+ee(t.b)+","+e+")"},xN=t=>e=>n=>r=>{const i=$i(t)(n)(kn(r));return()=>(i(),Yd(t)({x:0,y:0,width:e.width,height:e.height})())},NN=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",_N(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:kn(n.bgColor),dotCss:kn(n.dotColor),tile:n.tile,dotR:n.dotRadius,ox:n.origin.x,oy:n.origin.y})())},JN=t=>e=>n=>r=>{const i=$i(t)(e)(kn(r));return()=>(i(),au(t)(n)(),Wu(t)())},TN=t=>e=>n=>r=>i=>{const o=$i(t)(e)(kn(r));return()=>(o(),ua(t)(e)(kn(i.color))(),Ru(t)(i.width)(),fo(t)((()=>{if(i.lineJoin==="RoundJoin")return go;if(i.lineJoin==="BevelJoin")return Xu;if(i.lineJoin==="MiterJoin")return Vu;g()})())(),ju(t)((()=>{if(i.lineCap==="ButtCap")return Zu;if(i.lineCap==="RoundCap")return Uu;if(i.lineCap==="SquareCap")return Ku;g()})())(),au(t)(n)(),Wu(t)(),Hu(t)())},wN=t=>e=>n=>r=>i=>o=>{const u=gc(t);return()=>{if(u(),lN(t)(n.x)(n.y)(n.w)(n.h)(r)(),i.tag==="Just"?($i(t)(e)(kn(i._1.color))(),Wu(t)()):i.tag==="Nothing"||g(),o.tag==="Just")return ua(t)(e)(kn(o._1.color))(),Ru(t)(o._1.width)(),fo(t)((()=>{if(o._1.lineJoin==="RoundJoin")return go;if(o._1.lineJoin==="BevelJoin")return Xu;if(o._1.lineJoin==="MiterJoin")return Vu;g()})())(),ju(t)((()=>{if(o._1.lineCap==="ButtCap")return Zu;if(o._1.lineCap==="RoundCap")return Uu;if(o._1.lineCap==="SquareCap")return Ku;g()})())(),Hu(t)();o.tag!=="Nothing"&&g()}},vN=t=>e=>n=>r=>{const i=ua(t)(e)(kn(r.color));return()=>(i(),Ru(t)(r.width)(),fo(t)((()=>{if(r.lineJoin==="RoundJoin")return go;if(r.lineJoin==="BevelJoin")return Xu;if(r.lineJoin==="MiterJoin")return Vu;g()})())(),ju(t)((()=>{if(r.lineCap==="ButtCap")return Zu;if(r.lineCap==="RoundCap")return Uu;if(r.lineCap==="SquareCap")return Ku;g()})())(),au(t)(n)(),Hu(t)())},a_=t=>e=>n=>{const r=$i(t)(e)(kn(n.color));return()=>(r(),dN(t)(e)(yN(n.font))(),cl(t)((()=>{if(n.align==="AlignLeft")return rl;if(n.align==="AlignCenter")return ol;if(n.align==="AlignRight")return il;g()})())(),al(t)((()=>{if(n.baseline==="BaselineTop")return jd;if(n.baseline==="BaselineMiddle")return tl;if(n.baseline==="BaselineAlphabetic")return el;if(n.baseline==="BaselineBottom")return nl;g()})())(),Kd(t)(n.content)(n.x)(n.y)())},c_={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>mN},bN={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>c_},kN=t=>e=>n=>{const r=oa(e.width/n.vw)(e.height/n.vh),i=Ou(t)({translateX:(e.width-n.vw*r)/2-n.vx*r,translateY:(e.height-n.vh*r)/2-n.vy*r});return()=>(i(),ao(t)({scaleX:r,scaleY:r})(),fo(t)(go)())},LN={pure:t=>e=>()=>t,Apply0:()=>c_},EN={Applicative0:()=>LN,Bind1:()=>bN},g_={fillPath:t=>e=>n=>{const r=JN(n.ctx)(n.styleCache)(t)(e.color),i=n.maskDepth;return()=>{if(i.value===0)return r()}},strokePath:t=>e=>n=>{const r=vN(n.ctx)(n.styleCache)(t)(e),i=n.maskDepth;return()=>{if(i.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const i=TN(r.ctx)(r.styleCache)(t)(e.color)(n),o=r.maskDepth;return()=>{if(o.value===0)return i()}},drawRoundedRect:t=>e=>n=>r=>i=>{const o=wN(i.ctx)(i.styleCache)(t)(e)(n)(r),u=i.maskDepth;return()=>{if(u.value===0)return o()}},drawText:t=>e=>{const n=a_(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=Kn(n.ctx),i=n.maskDepth;return()=>{if(i.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",qd(n.ctx)(t)(),a_(n.ctx)(n.styleCache)(e)(),Zn(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=Kn(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Ou(e.ctx)({translateX:t.tx,translateY:t.ty})(),ao(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=Zn(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBakedTransform:t=>e=>{const n=Kn(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Ou(e.ctx)({translateX:t.tx,translateY:t.ty})(),ao(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=Zn(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushClip:t=>e=>n=>{const r=Kn(n.ctx),i=n.maskDepth;return()=>{if(i.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",au(n.ctx)(t)(),e==="NonZero")return Od(n.ctx)();if(e==="EvenOdd")return gN(n.ctx)();g()}}},popClip:t=>{const e=Zn(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBlend:t=>e=>{const n=Kn(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){if(n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",t==="Normal")return lc(e.ctx)(ul)();if(t==="Difference")return lc(e.ctx)(sl)();g()}}},popBlend:t=>{const e=Zn(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushAlpha:t=>e=>{const n=Kn(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="";const i=e.groupAlpha.value,o=e.alphaSaves.value;e.alphaSaves.value=[...o,i];const u=i*t;return e.groupAlpha.value=u,Wd(e.ctx)(u)()}}},popAlpha:t=>{const e=Zn(t.ctx),n=t.maskDepth;return()=>{if(n.value===0){e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="";const r=t.alphaSaves.value,i=fr(r);if(i.tag==="Just")return t.alphaSaves.value=i._1.init,t.groupAlpha.value=i._1.last;if(i.tag==="Nothing")return t.groupAlpha.value=1;g()}}},pushBlur:t=>e=>{const n=Kn(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="";const i=fN(e.ctx)(t);if(t>=.01)return i()}}},popBlur:t=>{const e=Zn(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushLayer:t=>e=>{if(t==="LayerNodeMask"){const n=e.maskDepth;return()=>{const r=n.value;n.value=r+1|0}}return()=>{}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;if(n>0)return t.maskDepth.value=r}},setViewport:t=>e=>{const n=kN(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=xN(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=NN(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=zf(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Hf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Kf,Monad0:()=>EN},CN=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ur=t=>e=>n=>{const r=CN(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},f_=t=>{const e=it.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=it.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},cu=t=>{if(t.tag==="Hidden")return{alpha:0,scale:0};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:t._1>0?1:0,scale:wi(8)(.6)(f_(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:wi(8)(.6)(f_(1-t._1))};g()};function SN(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function GN(t){const e=t.length,n=new Array(e);for(let r=0;r<e;r++){const i=t[r],o=t[(r+1)%e];n[r]={a:i,b:o,len:SN(i,o)}}return n}function PN(t,e,n){let r=0;for(let i=0;i<t.length;i++){const o=t[i],u=r,s=u+o.len;if(n<=s){const a=o.len>1e-6?(n-u)/o.len:0;return{x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a}}r=s}return e.length>0?e[e.length-1]:{x:0,y:0}}function __(t,e){if(e.length===0)return[];const n=GN(e);let r=0;for(let o=0;o<n.length;o++)r+=n[o].len;const i=new Array(t);for(let o=0;o<t;o++)i[o]=PN(n,e,o*r/t);return i}function DN(t,e){const n=e.length;if(n===0)return e;const r=(t%n+n)%n|0,i=new Array(n);for(let o=0;o<n;o++)i[o]=e[(o+r)%n];return i}function IN(t,e){const n=e.length;if(n===0)return e;let r=0,i=1/0;for(let o=0;o<n;o++){let u=0;for(let s=0;s<n;s++){const a=t[s]||{x:0,y:0},c=e[(s+o)%n]||{x:0,y:0},f=a.x-c.x,d=a.y-c.y;u+=f*f+d*d}u<i&&(i=u,r=o)}return DN(r,e)}const d_=t=>e=>n=>{const r=__(t,e),i=__(t,n),o=IN(r,i);return{from:r,to:o}};function l_(t){const e=t.length;if(e===0)return{x:0,y:0};let n=0,r=0;for(let i=0;i<e;i++)n+=t[i].x,r+=t[i].y;return{x:n/e,y:r/e}}function AN(t,e){const n=e.x-t.x,r=e.y-t.y,i=Math.sqrt(n*n+r*r);return i<=1e-4?{x:1,y:0}:{x:n/i,y:r/i}}function FN(t,e){const n=e.length;if(n===0)return e;const r=new Array(n);for(let i=0;i<n;i++){const o=e[((i-1)%n+n)%n],u=e[((i+1)%n+n)%n],s=e[i];r[i]={x:s.x+((o.x+u.x)/2-s.x)*t,y:s.y+((o.y+u.y)/2-s.y)*t}}return r}function BN(t){return t<0?0:t>1?1:t}const h_=t=>e=>n=>r=>{const i=e.length;if(i===0)return[];const o=l_(e),u=l_(n),s=AN(o,u),a=new Array(i);let c=1/0,f=-1/0;for(let _=0;_<i;_++){const h=e[_],p=(h.x-o.x)*s.x+(h.y-o.y)*s.y;a[_]=p,p<c&&(c=p),p>f&&(f=p)}const d=f-c;let l=new Array(i);for(let _=0;_<i;_++){const h=e[_],p=n[_];if(p===void 0){l[_]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(a[_]-c)/d),y=Math.max(1e-4,1-m),x=BN((t-m)/y),N=x*x*(3-2*x);l[_]={x:h.x+(p.x-h.x)*N,y:h.y+(p.y-h.y)*N}}for(let _=0;_<r.smoothPasses;_++)l=FN(.5,l);return l},Ln=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},p_=T(Gr)(0),m_=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},QN=T(t=>e=>t+e.len)(0),sa=t=>{const e=Qt(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...wt(Lt(1,t.length,t))(n=>[2,n.x,n.y]),5];g()},RN=t=>e=>{const n=Ln(e)(Ln(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},MN=t=>{const e=Qt(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...wt(e._1.tail)(n=>[2,n.x,n.y])];g()},zN=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return r_(e);if(t.shape==="Parallelogram")return t_(e);if(t.shape==="Diamond")return u_(e);if(t.shape==="Ellipse")return jf(e);if(t.shape==="Document")return e_(e);if(t.shape==="Cloud")return s_(e)(7);if(t.shape==="Rectangle")return RN(e)(7);g()},me=t=>e=>n=>O(r=>{const i=et(r)/et(n);return{x:t.x+(e.x-t.x)*i,y:t.y+(e.y-t.y)*i}})(Ft(0,n-1|0)),HN=t=>{const e=un(t.w*.18)(t.h*.6);return[...me({x:t.x+e,y:t.y})({x:t.x+t.w,y:t.y})(16),...me({x:t.x+t.w,y:t.y})({x:t.x+t.w-e,y:t.y+t.h})(16),...me({x:t.x+t.w-e,y:t.y+t.h})({x:t.x,y:t.y+t.h})(16),...me({x:t.x,y:t.y+t.h})({x:t.x+e,y:t.y})(16)]},Kr=t=>e=>{const n=Ln(t)(Ln(e.w/2)(e.h/2));return{...e,x:e.x+n,y:e.y+n,w:e.w-2*n,h:e.h-2*n}},aa=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return Ce(r*r+n*n)},WN=t=>ve(e=>n=>({a:e,b:n,len:aa(e)(n)}),t,Lt(1,t.length,t)),ON=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?w("Just",e[n]):J,i=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];g()})(),o=0<e.length?w("Just",e[0]):J,u=(()=>{if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return{x:0,y:0};g()})(),s=e.length;return s<3?e:[u,...wt(Ft(1,s-2|0))(a=>{const c=a+1|0,f=c>=0&&c<e.length?w("Just",e[c]):J,d=a>=0&&a<e.length?w("Just",e[a]):J,l=a-1|0,_=l>=0&&l<e.length?w("Just",e[l]):J;if(_.tag==="Just"&&d.tag==="Just"&&f.tag==="Just"){const h=d._1,p=aa(h)(f._1),m=aa(_._1)(h),y=Ln(t)(p/2),x=Ln(t)(m/2),N=p>0?y/p:0,v=h.x+(f._1.x-h.x)*N,k=h.y+(f._1.y-h.y)*N,L=m>0?x/m:0,E=h.x+(_._1.x-h.x)*L,B=h.y+(_._1.y-h.y)*L;return O(q=>{const j=et(q)/et(10),G=1-j;return{x:G*G*E+2*G*j*h.x+j*j*v,y:G*G*B+2*G*j*h.y+j*j*k}})(Ft(0,10))}return[]}),...i]},YN=t=>e=>n=>r=>i=>O(o=>{const u=et(o)/et(i),s=1-u,a=u*u*u,c=3*s*u*u,f=3*s*s*u,d=s*s*s;return{x:d*t.x+f*e.x+c*n.x+a*r.x,y:d*t.y+f*e.y+c*n.y+a*r.y}})(Ft(0,i-1|0)),$N=t=>[...me({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...me({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...YN({x:t.x+t.w,y:t.y+t.h*.85})({x:t.x+t.w*.66,y:t.y+t.h*1.05})({x:t.x+t.w*.34,y:t.y+t.h*.65})({x:t.x,y:t.y+t.h*.85})(32),...me({x:t.x,y:t.y+t.h*.85})({x:t.x,y:t.y})(12)],y_=t=>e=>O(n=>{const r=6.283185307179586*et(n)/et(64);return{x:t.x+e*rn(r),y:t.y+e*Ve(r)}})(Ft(0,63)),gu=t=>e=>{const n=.5522847498*e;return[1,t.x+e,t.y,4,t.x+e,t.y+n,t.x+n,t.y+e,t.x,t.y+e,4,t.x-n,t.y+e,t.x-e,t.y+n,t.x-e,t.y,4,t.x-e,t.y-n,t.x-n,t.y-e,t.x,t.y-e,4,t.x+n,t.y-e,t.x+e,t.y-n,t.x+e,t.y,5]},qN=t=>{const e=t.y+t.h/2,n=un(t.h*.4)(t.w*.2);return[...me({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...me({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...me({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...me({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...me({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...me({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},x_=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:p_(O(n=>n.x)(t))/et(e),y:p_(O(n=>n.y)(t))/et(e)}},fu=t=>e=>n=>r=>i=>O(o=>{const u=n+(r-n)*(et(o)/et(i));return{x:t.x+e*rn(u),y:t.y+e*Ve(u)}})(Ft(0,i-1|0)),N_=t=>e=>{const n=Ln(t)(Ln(e.w/2)(e.h/2));return[...me({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...fu({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...me({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...fu({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...me({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...fu({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...me({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...fu({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},_u=t=>e=>n=>r=>i=>o=>O(u=>{const s=r+(i-r)*(et(u)/et(o));return{x:t.x+e*rn(s),y:t.y+n*Ve(s)}})(Ft(0,o-1|0)),XN=t=>{const e=t.h*.38;return[...wt(o_(i_(n_)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=dr(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),i=dr(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return _u({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(i)(r>i?r:r+6.283185307179586)(16)}),...me({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...me({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...me({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},VN=t=>{const e=Ln(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,i=t.y+t.h+5-e-2,o=t.x+n;return[..._u({x:o,y:r})(n)(e)(3.141592653589793)(6.283185307179586)(24),...me({x:t.x+t.w,y:r})({x:t.x+t.w,y:i})(12),..._u({x:o,y:i})(n)(e)(0)(3.141592653589793)(24),...me({x:t.x,y:i})({x:t.x,y:r})(12)]},br=t=>e=>e.shape==="Cylinder"?VN(e):e.shape==="Parallelogram"?HN(e):e.shape==="Diamond"?qN(e):e.shape==="Ellipse"?N_(un(e.w)(e.h)/2)(e):e.shape==="Document"?$N(e):e.shape==="Cloud"?XN(e):N_(t)(e),UN=t=>{const e=Ln(t.h*.075)(t.w*.075),n=t.w/2;return _u({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},KN=t=>e=>n=>T(r=>i=>{const o=r.pos+i.len,u=n<o?(n-r.pos)/i.len:1,s={x:i.a.x+(i.b.x-i.a.x)*u,y:i.a.y+(i.b.y-i.a.y)*u},a=e>r.pos?(e-r.pos)/i.len:0,c={x:i.a.x+(i.b.x-i.a.x)*a,y:i.a.y+(i.b.y-i.a.y)*a},f=r.points.length-1|0,d=f>=0&&f<r.points.length?(()=>{const l=r.points[f].x-c.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const _=r.points[f].y-c.y;return _<0?-_<1e-4:_<1e-4})()})()?Rt(r.points)(s):[...r.points,c,s]:[c,s];return i.len<=0||o<=e||r.pos>=n?{...r,pos:o}:{pos:o,points:d}})({pos:0,points:[]})(t).points,ZN=t=>e=>n=>{const r=Qt(i=>J,i=>o=>w("Just",{head:i,tail:o}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const i=WN(t),o=QN(i),u=m_(0)(o)(e*o),s=m_(0)(o)(n*o);return s<=u?[]:KN(i)(u)(s)}g()},jN=t=>e=>n=>r=>{const i=r.x-n.x,o=r.y-n.y,u=e.x-t.x,s=e.y-t.y,a=n.x-t.x,c=n.y-t.y,f=u*o-s*i,d=(a*o-c*i)/f,l=(a*s-c*u)/f;return(f<0?-f<1e-9:f<1e-9)?J:d>=0&&d<=1&&l>=0&&l<=1?w("Just",d):J},tJ=t=>e=>n=>{const r=Et(i=>o=>it.compare(i.t)(o.t))(xt(i=>{const o=jN(e)(n)(i._1)(i._2);return o.tag==="Just"?w("Just",{t:o._1,p:{x:e.x+(n.x-e.x)*o._1,y:e.y+(n.y-e.y)*o._1}}):J})(ve(Pn,t,[...Lt(1,t.length,t),...Lt(0,1,t)])));return 0<r.length?w("Just",r[0].p):J},J_=t=>e=>{const n=fr(e);if(n.tag==="Nothing")return e;if(n.tag==="Just"){const r=n._1.init.length-1|0;if(r>=0&&r<n._1.init.length){const i=tJ(t)(n._1.init[r])(n._1.last);if(i.tag==="Just")return Rt(n._1.init)(i._1);if(i.tag==="Nothing")return e;g()}return e}g()},ca=t=>t,zn=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},kr=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},eJ=Xa(qa)(zt),nJ=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},rJ=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},T_=ca("SegMove"),iJ=ca("SegLine"),oJ=ca("SegQuad"),w_={offset:.4,passes:1,rMax:1.5},v_=t=>ce(mn(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,du=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},lu=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},Hn=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},qi=(()=>{const t=T(e=>n=>((e*31|0)+ce(mn(n.x*100))|0)+ce(mn(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),uJ=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const i=n,o=r,u=i>=0&&i<t.length?w("Just",t[i]):J;if(u.tag==="Nothing"){n=t.length;continue}if(u.tag==="Just"){if(u._1===1){const s={x:(()=>{const a=i+1|0;return a>=0&&a<t.length?t[a]:0})(),y:(()=>{const a=i+2|0;return a>=0&&a<t.length?t[a]:0})()};e.push({kind:T_,m:o,c:o,p:s,len:0}),r=s,n=i+3|0;continue}if(u._1===2){const s={x:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()},a=s.x-o.x,c=s.y-o.y;e.push({kind:iJ,m:o,c:o,p:s,len:Ce(a*a+c*c)}),r=s,n=i+3|0;continue}if(u._1===3){const s={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=s.x-o.x,c=s.y-o.y;e.push({kind:oJ,m:o,c:{x:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()},p:s,len:Ce(a*a+c*c)*1.05}),r=s,n=i+5|0;continue}if(u._1===5){e.push({kind:T_,m:o,c:o,p:o,len:0}),n=i+1|0;continue}n=t.length;continue}g()}return e},sJ=t=>e=>{const n=e.length-1|0,r=n<1?[]:Lt(0,n,e),i=(()=>{const u=r.length-1|0;return u>=0&&u<r.length?w("Just",r[u]):J})(),o=e.length-1|0;if(o>=0&&o<e.length&&i.tag==="Just"){const u=e[o].y-i._1.y,s=e[o].x-i._1.x,a=Ce(s*s+u*u);return a<=1e-4?e:Rt((()=>{const c=e.length-1|0;return c<1?[]:Lt(0,c,e)})())({x:e[o].x+s/a*t,y:e[o].y+u/a*t})}return e},aJ=t=>e=>n=>we(T(r=>i=>{const o=pe(0)(t)(r.prng),u=pe(0)(6.283185307179586)(o.prng);return{prng:u.prng,out:[{x:i.x+o.value*rn(u.value),y:i.y+o.value*Ve(u.value)},...r.out]}})({prng:e,out:[]})(n).out),cJ=t=>e=>n=>{if(e.kind==="SegMove")return lu(t)(e.p);if(e.kind==="SegLine")return Hn(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});if(e.kind==="SegQuad")return Hn(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});g()},gJ=t=>e=>{if(e.kind==="SegMove")return lu(t)(e.p);if(e.kind==="SegLine")return Hn(t)(e.p);if(e.kind==="SegQuad")return du(t)(e.c)(e.p);g()},b_=t=>e=>{const n=uJ(e),r=T(s=>a=>s+a.len)(0)(n)*zn(0)(kr(1)(t)),i=[];let o=0,u=0;for(;u<n.length;){const s=u,a=o;if(s>=0&&s<n.length){if(a+n[s].len<=r){const c=n[s];gJ(i)(c)(),o=a+c.len,u=s+1|0;continue}if(a>=r){u=n.length;continue}cJ(i)(n[s])((r-a)/zn(n[s].len)(1e-4))()}u=n.length}return i},k_={offset:1.5,passes:2,rMax:14,overshoot:2.5},L_=t=>e=>n=>r=>{const i=r.y-n.y,o=n.y-e.y,u=r.x-n.x,s=Ce(u*u+i*i),a=n.x-e.x,c=Ce(a*a+o*o),f=kr(t.rMax*(ld(c>0&&s>0?zn(-1)(kr(1)((a*u+o*i)/(c*s))):1)/3.141592653589793))(.4*kr(c)(s));return{inP:c>0?{x:n.x-a/c*f,y:n.y-o/c*f}:n,curr:n,outP:s>0?{x:n.x+u/s*f,y:n.y+i/s*f}:n}},E_=t=>e=>{const n=e.length,r=[],i=0<e.length?w("Just",e[0]):J;if(i.tag==="Just"?lu(r)(i._1)():i.tag==="Nothing"||g(),n>=3){let u=1;for(;u<=(n-2|0);){const s=u,a=s+1|0;if(a>=0&&a<e.length){if(s>=0&&s<e.length){const c=s-1|0;if(c>=0&&c<e.length){const f=L_(t)(e[c])(e[s])(e[a]);Hn(r)(f.inP)(),du(r)(f.curr)(f.outP)()}}u=s+1|0;continue}u=s+1|0}}const o=e.length-1|0;return o>=0&&o<e.length&&n>=2&&Hn(r)(e[o])(),r},fJ=t=>e=>n=>r=>i=>{if(i.length<4)return E_(t)(i);const o=0<i.length?w("Just",i[0]):J,u=(()=>{if(o.tag==="Nothing")return{x:0,y:0};if(o.tag==="Just")return o._1;g()})(),s=i.length-1|0,a=Un(Un(e)(s)+s|0)(s),c=_=>{const h=Un(_+s|0)(s);return h>=0&&h<i.length?i[h]:u},f=O(_=>L_(t)(c((a+_|0)-1|0))(c(a+_|0))(c((a+_|0)+1|0)))(Ft(0,s-1|0)),d=[],l=0<f.length?w("Just",f[0]):J;if(l.tag==="Just")if(lu(d)(l._1.outP)(),eJ((()=>{const _=Qt(h=>J,h=>p=>w("Just",p),f);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})())(_=>{const h=Hn(d)(_.inP);return()=>(h(),du(d)(_.curr)(_.outP)())})(),n)Hn(d)(l._1.inP)(),du(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const _=f.length-1|0;_>=0&&_<f.length?Hn(d)((()=>{const h=1-r;return{x:f[_].outP.x+(l._1.inP.x-f[_].outP.x)*h,y:f[_].outP.y+(l._1.inP.y-f[_].outP.y)*h}})())():Hn(d)(l._1.inP)()}else l.tag==="Nothing"||g();return d},Zr=t=>e=>n=>r=>{const i=nJ(1)(r.length-1|0),o=pe(0)(et(i))(na("shape")(e)),u=rJ(i-1|0)(ce(mn(o.value))),s=o.prng;return O(a=>{const c=pe(0)(1)(na(ee(a))(s)),f=pe(-.18)(.3)(c.prng),d=c.value<.7,l=pe(.5)(.85)(f.prng),_=aJ(t.offset)(l.prng)(r);return{path:n?fJ(t)(u)(d)(f.value)(_):E_(t)(_),alpha:l.value}})(Ft(0,t.passes-1|0))},_J=t=>e=>n=>Zr(t)(e)(!0)([{x:n.x,y:n.y},{x:n.x+n.w,y:n.y},{x:n.x+n.w,y:n.y+n.h},{x:n.x,y:n.y+n.h},{x:n.x,y:n.y}]),dJ=t=>e=>n=>{const r=zn(0)(kr(1)(n)),i=e.h/et(4),o=zn(6)(i*1.4);return xt(u=>u)(O(u=>{if(r<zn(0)(et(u)/et(4)-.05))return J;const s=na(ee(u))(t),a=zn(0)(et(u)/et(4)-.05),c=Un(u)(2)===0,f=c?e.x-2:e.x+e.w+2,d=c?e.x+e.w+2:e.x-2,l=e.y+(et(u)+.5)*i;return w("Just",{path:b_(zn(0)(kr(1)((r-a)/zn(1e-4)(kr(1)(et(u+1|0)/et(4)+.05)-a))))((()=>{const _={rMax:2,offset:.6,passes:1},h=we(T(m=>y=>{const x=pe(-i*.08)(i*.08)(m.prng);return{prng:x.prng,out:[{x:f+(d-f)*(et(y)/et(4)),y:l+x.value},...m.out]}})({prng:s,out:[]})(Ft(0,4)).out),p=h.length<2?[]:Zr(_)(s)(!1)(h);return 0<p.length?p[0].path:[]})()),width:o,alpha:1})})(Ft(0,3)))},ga=(t,e,n)=>({tag:t,_1:e,_2:n}),C_=t=>t,fa=(t,e,n)=>({tag:t,_1:e,_2:n}),hu=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},S_=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Xi=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},G_=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},ae=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Ie=(()=>{const t=Ue.unfoldr(xn);return e=>t(Ke("IterNode",e,yn))})(),En=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},lJ=zt.foldMap(Cd),pu=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},P_=te(S)(zt),hJ=sc(S),pJ=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},_a=C_("LabelsShown"),mJ=C_("LabelsHidden"),D_=t=>{const e=t.Monad0().Bind1(),n=t.popTransform,r=t.popAlpha;return i=>o=>u=>s=>a=>e.bind(t.pushAlpha(i.fadeAlpha))(()=>e.bind(t.pushTransform({tx:o*(1-i.popScale),ty:u*(1-i.popScale),sx:i.popScale,sy:i.popScale}))(()=>e.bind(t.pushTransform({tx:0,ty:s.y*(1-i.flipY),sx:1,sy:i.flipY}))(()=>e.bind(a)(()=>e.bind(n)(()=>e.bind(n)(()=>r))))))},tn=t=>{const e=t.Apply0();return n=>T(r=>i=>e.apply(e.Functor0().map(o=>Ra)(r))(n(i)))(t.pure())},I_=t=>e=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},a=Ur(i)(o)(r),c=0<t.length?w("Just",t[0]):J,f=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return s;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?w("Just",t[d]):J,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return u;g()})(),h=d_(128)(br(4)(Kr(2)(e)))(y_(f)(6)),p=f.x-s.x,m=2*(()=>{const V=f.y-s.y;return(p<0?-p:p)+(V<0?-V:V)})(),y=_.x-u.x,x=2*(()=>{const V=_.y-u.y;return(y<0?-y:y)+(V<0?-V:V)})(),N=m+pi(t)+x,v=N<=1e-4?1:1-x/N,k=N<=1e-4?0:m/N,L=v-k,E=d_(128)(y_(_)(6))(br(4)(Kr(2)(n))),B={maxDelay:.4,smoothPasses:2},q=yr(t)(hu(0)(1)(L<=1e-4?0:(a-k)/L)),j=(()=>{if(q.tag==="Just")return q._1;if(q.tag==="Nothing")return f;g()})(),G=(()=>{if(v>=1)return 0;const V=(a-v)/(1-v),U=V<0?0:V>1?1:V;return U*U*(3-2*U)})(),P=(()=>{if(k<=1e-4)return 1;const V=a/k,U=V<0?0:V>1?1:V;return U*U*(3-2*U)})();return a<k?fa("PolyShape",h_(P)(h.from)(h.to)(B)):a>=v?fa("PolyShape",h_(G)(E.from)(E.to)(B)):fa("CircleShape",j,6)},A_=t=>e=>n=>r=>i=>o=>{const u=I_(t)(e)(n)(r)(i)(o);if(u.tag==="PolyShape")return x_(u._1);if(u.tag==="CircleShape")return u._1;g()},yJ=t=>e=>{const n=t.y+t.h-6,r=t.y+6,i=t.x+14,o=t.x+t.w-14,u=T(Xi)(0)(O(s=>i-10<s.x+s.w+12&&o+10>s.x-12&&r-10<s.y+s.h+12&&n+10>s.y-12?S_((s.x+s.w+12-(i-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+u*.7071067811865476,y:t.y-u*.7071067811865476}},xJ=t=>e=>n=>T(r=>i=>{const o=G_(i)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just"){const u=yJ(o._1)(r.obstacles);return{acc:tt(S)(i)(u)(r.acc),obstacles:Rt(r.obstacles)(u)}}g()})({acc:A,obstacles:n})(t).acc,da=(()=>{const t={r:24,g:24,b:27,a:255},e={r:244,g:244,b:245,a:255},n={r:248,g:249,b:246,a:255},r={r:26,g:26,b:26,a:255},i={r:28,g:101,b:192,a:255},o={r:247,g:248,b:250,a:255},u={r:42,g:48,b:60,a:255},s={r:120,g:130,b:146,a:255};return a=>{if(a==="Light")return{bg:{r:255,g:255,b:255,a:255},bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:211,b:209,a:255},shadowFill:{r:255,g:255,b:255,a:255},shadowDot:{r:26,g:26,b:26,a:255},chip:{r:255,g:235,b:130,a:255},chipShadow:{r:214,g:211,b:209,a:255},chipText:Mn,nodeFill:ue,nodeStroke:Mn,text:Mn,edge:Mn,arrowFill:Mn,tokenOutsideFill:Mn,tokenOutsideStroke:ue,tokenInside:ue,tokenInsideStroke:ue,tokenInsideBlend:su,tokenInsideAlpha:1,chipPillFill:Mn,chipPillText:ue,chipHairline:{r:26,g:26,b:26,a:90},trailDot:Mn,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Dark")return{bg:t,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:63,g:63,b:70,a:255},shadowFill:t,shadowDot:e,chip:{r:234,g:179,b:8,a:255},chipShadow:{r:0,g:0,b:0,a:120},chipText:t,nodeFill:Mn,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:ue,tokenOutsideStroke:ue,tokenInside:ue,tokenInsideStroke:ue,tokenInsideBlend:su,tokenInsideAlpha:1,chipPillFill:e,chipPillText:t,chipHairline:{r:244,g:244,b:245,a:120},trailDot:e,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Blueprint")return{bg:i,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:90,g:160,b:230,a:255},shadowFill:i,shadowDot:ue,chip:ue,chipShadow:{r:0,g:0,b:0,a:120},chipText:i,nodeFill:i,nodeStroke:ue,text:ue,edge:ue,arrowFill:ue,tokenOutsideFill:ue,tokenOutsideStroke:ue,tokenInside:ue,tokenInsideStroke:ue,tokenInsideBlend:Xf,tokenInsideAlpha:.35,chipPillFill:ue,chipPillText:i,chipHairline:{r:255,g:255,b:255,a:120},trailDot:ue,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Whiteboard")return{bg:n,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:0,g:0,b:0,a:0},shadowFill:n,shadowDot:r,chip:{r:217,g:74,b:56,a:255},chipShadow:{r:26,g:26,b:26,a:60},chipText:n,nodeFill:n,nodeStroke:r,text:r,edge:r,arrowFill:r,tokenOutsideFill:r,tokenOutsideStroke:n,tokenInside:n,tokenInsideStroke:n,tokenInsideBlend:Xf,tokenInsideAlpha:1,chipPillFill:r,chipPillText:n,chipHairline:{r:26,g:26,b:26,a:90},trailDot:r,wobble:!0,fontFamily:"Supermarker, Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Isometric")return{bg:o,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:218,b:224,a:255},shadowFill:o,shadowDot:u,chip:{r:255,g:235,b:130,a:255},chipShadow:{r:100,g:110,b:125,a:90},chipText:u,nodeFill:{r:236,g:239,b:244,a:255},nodeStroke:u,text:u,edge:s,arrowFill:s,tokenOutsideFill:u,tokenOutsideStroke:ue,tokenInside:ue,tokenInsideStroke:ue,tokenInsideBlend:su,tokenInsideAlpha:1,chipPillFill:u,chipPillText:ue,chipHairline:{r:60,g:66,b:78,a:90},trailDot:u,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};g()}})(),la=t=>e=>wt(Ie(t.nodes))(n=>{const r=ae(n._1)(e.nodes);return r.tag==="Just"&&cu(r._1).alpha>0?zN(n._2):[]}),NJ=t=>e=>n=>[1,t.vx,t.vy,2,t.vx+t.vw,t.vy,2,t.vx+t.vw,t.vy+t.vh,2,t.vx,t.vy+t.vh,5,...la(e)(n)],JJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=cr.traverse(r);return o=>u=>{const s=hr(u),a=.32*o.size;return i(c=>n.bind(c===0?r.pure(0):t.measureText(o)(ye(c)(u)))(f=>n.bind(t.measureText(o)(ye(c+1|0)(u)))(d=>n.bind(t.measureInk(o)(c>=0&&c<s.length?_o(s[c]):" "))(l=>r.pure({x:f,w:d-f,up:l.ascent-a,down:l.descent+a})))))(Ft(0,s.length-1|0))}},TJ=t=>e=>{const n=i=>(i.x-e.x)*(i.x-e.x)+(i.y-e.y)*(i.y-e.y),r=T(i=>o=>n(o)<n(i)?o:i)({x:t.x,y:t.y})([{x:t.x,y:t.y},{x:t.x+t.w,y:t.y},{x:t.x,y:t.y+t.h},{x:t.x+t.w,y:t.y+t.h}]);return O(i=>{const o=et(i)/5;return{x:r.x+(e.x-r.x)*o,y:r.y+(e.y-r.y)*o}})([1,2,3,4])},ha=t=>{const e=wo(`
7
+ `)(t);return e.length===0?[""]:e},wJ=t=>e=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},a=Ur(i)(o)(r),c=0<t.length?w("Just",t[0]):J,f=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return s;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?w("Just",t[d]):J,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return u;g()})(),h=f.x-s.x,p=2*(()=>{const B=f.y-s.y;return(h<0?-h:h)+(B<0?-B:B)})(),m=_.x-u.x,y=2*(()=>{const B=_.y-u.y;return(m<0?-m:m)+(B<0?-B:B)})(),x=p+pi(t)+y,N=x<=1e-4?1:1-y/x,v=x<=1e-4?0:p/x,k=N-v,L=yr(t)(hu(0)(1)(k<=1e-4?0:(a-v)/k)),E=(()=>{if(L.tag==="Just")return L._1;if(L.tag==="Nothing")return f;g()})();return a<v?ga("InsideRect",Kr(2)(e)):a>=N?ga("InsideRect",Kr(2)(n)):ga("InsideBall",E,6)},vJ={offset:.8,passes:2,rMax:5},bJ=t=>{const e=t.Monad0().Applicative0(),n=tn(e);return r=>i=>o=>u=>{const s={color:u,width:1,lineJoin:be,lineCap:pn},a={color:o,flat:!0},c=f=>t.drawRoundedRect({x:f.x,y:f.y,w:f.w,h:f.h})(4)(w("Just",a))(w("Just",s));return n(f=>{if(f._2.tag==="Travelling"){const d=En(f._2._1.edge)(r.edges),l=ae(f._2._1.target)(r.nodes),_=ae(f._2._1.source)(r.nodes);if(_.tag==="Just"&&l.tag==="Just"&&d.tag==="Just"){const h=wJ((()=>{if(f._2._1.direction==="Forward")return d._1;if(f._2._1.direction==="Backward")return we(d._1);g()})())(_._1)(l._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);if(h.tag==="InsideRect")return c(h._1);if(h.tag==="InsideBall")return t.fillStrokePath(gu(h._1)(h._2))(a)(s);g()}return e.pure()}if(f._2.tag==="Filling"){const d=ae(f._2._1.node)(r.nodes);if(d.tag==="Just")return c(Kr(2)(d._1));if(d.tag==="Nothing")return e.pure();g()}return e.pure()})(Ie(i.tokens))}},F_=t=>e=>n=>r=>t.strokePath((()=>{const i=Qt(o=>J,o=>u=>w("Just",{head:o,tail:u}),O(o=>o.pt)(ad(o=>u=>{const s=et(u)/et(72),a=pe(-.18)(.18)(o.prng),c=pe(-.1)(.1)(a.prng),f=pe(-.07)(.07)(c.prng),d=n*(.05+.55*s)*(1+c.value),l=s*28.274333882308138+a.value;return{prng:f.prng,pt:{x:e.x+rn(l)*d+f.value*n,y:e.y+Ve(l)*d+f.value*n}}},{prng:137,pt:{x:e.x,y:e.y}},Ft(0,72))));if(i.tag==="Just")return[1,i._1.head.x,i._1.head.y,...lJ(o=>[2,o.x,o.y])(i._1.tail)];if(i.tag==="Nothing")return[];g()})())({color:r,width:5.5,lineJoin:be,lineCap:bn}),kJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=tn(e.Applicative0());return o=>u=>s=>i(a=>n.bind(t.pushAlpha(a.alpha))(()=>n.bind(t.strokePath(a.path)({color:o.nodeFill,width:a.width,lineJoin:be,lineCap:bn}))(()=>r)))(dJ(v_(u)+7777|0)(u)(s))},B_=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=e.Applicative0(),o=tn(i),u=t.popClip,s=tn(i),a=cr.traverse(i),c=JJ(t),f=kJ(t),d=t.popTransform;return l=>_=>h=>p=>m=>y=>x=>N=>v=>{const k=D=>n.bind(t.pushAlpha(D.alpha))(()=>n.bind(t.strokePath(D.path)({color:h.nodeStroke,width:2,lineJoin:be,lineCap:bn}))(()=>r)),L={family:h.fontFamily,size:h.wobble?15:11,weight:h.wobble?800:500},E=wo(`
8
+ `)(N.label===""?x:N.label),B=E.length===0?[""]:E,q=L.size*1.2,j=N.shape==="Cylinder"?t.strokePath(aN({x:N.x,y:N.y,w:N.w,h:N.h}))({color:h.nodeStroke,width:1.25,lineJoin:be,lineCap:pn}):i.pure(),G=(N.shape==="Cylinder"?(N.y+(N.y+N.h+5-2*un(N.h*.075)(N.w*.075)))/2:(N.y+N.y+N.h)/2)-et(B.length)*q/2+q/2,P=v.tag==="PloppingOut"&&h.wobble?v._1:-1,V=P>=0,U=cu(v),M=V?{alpha:1,scale:1}:U,H=N.x+N.w/2,R=N.y+N.h/2,C=n.bind(t.pushAlpha(M.alpha*p))(()=>n.bind(t.pushTransform({tx:H*(1-M.scale),ty:R*(1-M.scale),sx:M.scale,sy:M.scale}))(()=>{const D={x:N.x,y:N.y,w:N.w,h:N.h},F={color:h.nodeStroke,width:h.wobble?2:1.25*_,lineJoin:be,lineCap:h.wobble?bn:pn};return n.bind((()=>{if(h.wobble){if(N.shape==="Rectangle")return o(k)(_J(k_)(v_(D))(D));const I=br(7)(N);return n.bind(o(k)((()=>{const z=qi(I);return I.length<4?[]:Zr(w_)(z)(!0)(I)})()))(()=>s(z=>o(k)((()=>{const $=qi(z);return z.length<2?[]:Zr(w_)($)(!1)(z)})()))(N.shape==="Cylinder"?[UN(N)]:[]))}return n.bind(ia(t)(N.shape)(D)(7)(w("Just",{color:h.nodeFill,flat:!1}))(w("Just",F)))(()=>j)})())(()=>n.bind((()=>{if(y.tag==="Just"&&h.wobble&&!V){const I=y._1;return n.bind(a(c(L))(B))(z=>{const $=Et(ut=>st=>it.compare(ut.x)(st.x)),X=ce(mn(N.x*7919+N.y*3001))*-1640531535|0,Y=pe(5)(7.5)(X),W=pe(0)(Y.value)(Y.prng),K=-(1+2*pe(-1)(1)(W.prng).value*3.141592653589793/180),Z=(ut,st,Nt,Jt,kt)=>$(xt(Ot=>Ot)([K*st+ut>=Jt&&K*st+ut<=kt?w("Just",{x:st,y:K*st+ut}):J,K*Nt+ut>=Jt&&K*Nt+ut<=kt?w("Just",{x:Nt,y:K*Nt+ut}):J,(()=>{const Ot=(Jt-ut)/K;return Ot>=st&&Ot<=Nt?w("Just",{x:Ot,y:Jt}):J})(),(()=>{const Ot=(kt-ut)/K;return Ot>=st&&Ot<=Nt?w("Just",{x:Ot,y:kt}):J})()])),ct=Y.value,_t=Un(I.frameHash)(3),gt=_t===0?{r:200,g:35,b:30,a:220}:_t===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},yt=N.x+N.w/2,St=We(Bt(ut=>st=>Bt((()=>{const Nt=G+et(ut)*q,Jt=yt-T(kt=>Ot=>kt+Ot.w)(0)(st)/2;return kt=>Ot=>{const _n=L.size*.1,Fe=kt-1|0,Pt=Fe>=0&&Fe<st.length&&kt>0?(st[Fe].x+st[Fe].w+Ot.x)/2:Ot.x-_n;return{x:Jt+Pt-1,y:Nt-Ot.up-1,w:Xi(0)((()=>{const At=kt+1|0;return At>=0&&At<st.length&&kt<(st.length-1|0)?(Ot.x+Ot.w+st[At].x)/2-Pt:Ot.x+Ot.w+_n-Pt})())+2,h:Ot.up+Ot.down+2}}})())(st))(z)),Ht=N.y+4,pt=N.x+N.w-4,Wt=N.x+4,Tt=Ht-K*Wt+W.value,mt=N.y+N.h-4,ft=wt(wt(Bt(ut=>st=>{const Nt=(st.from.x+st.to.x)/2,Jt=(st.from.y+st.to.y)/2,kt=pe(-1)(1)(X+(911*(ut+1|0)|0)|0),Ot=pe(-3)(5)(kt.prng),_n=kt.value*3.141592653589793/180,Fe=rn(_n),Pt=Ve(_n),At=Be=>({x:Nt+(Be.x-Nt)*Fe-(Be.y-Jt)*Pt,y:Jt+(Be.x-Nt)*Pt+(Be.y-Jt)*Fe});return{from:(()=>{const Be=At(st.from),an=Be.y-Jt,Xe=Be.x-Nt,nn=Ce(Xe*Xe+an*an),Pe=nn<1e-4?1:(nn+Ot.value)/nn;return{x:Nt+Xe*Pe,y:Jt+an*Pe}})(),to:(()=>{const Be=At(st.to),an=pe(-3)(5)(Ot.prng).value,Xe=Be.y-Jt,nn=Be.x-Nt,Pe=Ce(nn*nn+Xe*Xe),qt=Pe<1e-4?1:(Pe+an)/Pe;return{x:Nt+nn*qt,y:Jt+Xe*qt}})()}})(xt(ut=>{const st=Z(Tt+et(ut)*ct,Wt,pt,Ht,mt);return st.length===2?w("Just",{from:st[0],to:st[1]}):J})(Ft(0,pu(1)(ce(mn((mt-K*pt-Tt)/ct)))))))(ut=>at(st=>st.to.x-st.from.x>1,T(st=>Nt=>wt(st)(Jt=>{const kt=Z(Jt.from.y-K*Jt.from.x,Nt.x,Nt.x+Nt.w,Nt.y,Nt.y+Nt.h);return kt.length===2?kt[0].x>Jt.from.x+.001&&kt[1].x<Jt.to.x-.001?[{from:Jt.from,to:kt[0]},{from:kt[1],to:Jt.to}]:kt[0].x<=Jt.from.x+.001&&kt[1].x<Jt.to.x-.001?[{from:kt[1],to:Jt.to}]:kt[0].x>Jt.from.x+.001&&kt[1].x>=Jt.to.x-.001?[{from:Jt.from,to:kt[0]}]:[]:[Jt]}))([ut])(St))))(ut=>(()=>{const st=ut.to.x-ut.from.x;return Ce(2)*(st>=0?st:-st)<=28})()?[ut]:[{from:ut.from,to:{x:ut.from.x+(ut.to.x-ut.from.x)*.495,y:ut.from.y+(ut.to.y-ut.from.y)*.495}},{from:{x:ut.from.x+(ut.to.x-ut.from.x)*.505,y:ut.from.y+(ut.to.y-ut.from.y)*.505},to:ut.to}]),ot=ft.length,dt=ut=>Xi(0)(S_(1)(I.t*et(ot)-et(ut)));return n.bind(t.pushClip(sa(br(7)(N)))(uu))(()=>n.bind(o(ut=>{const st=ut._1,Nt=pe(1.4)(1.9)(X+(1303*(st+1|0)|0)|0),Jt=pe(.35)(.8)(Nt.prng),kt=o(Ot=>n.bind(t.pushAlpha(Ot.alpha*Jt.value))(()=>n.bind(t.strokePath(b_(dt(st))(Ot.path))({color:gt,width:Nt.value,lineJoin:be,lineCap:bn}))(()=>r)))(Zr({...k_,rMax:0,offset:.5})(X+(53*(st+1|0)|0)|0)(!1)([ut._2.from,ut._2.to]));return dt(st)>0?kt:i.pure()})(Bt(Pn)(ft)))(()=>u))})}return i.pure()})())(()=>n.bind((()=>{if(l==="LabelsShown"){const I=n.bind(t.pushAlpha(m))(()=>n.bind(o(z=>t.drawText({x:N.x+N.w/2,y:G+et(z._1)*q,content:z._2,font:L,color:h.text,align:Xr,baseline:ur}))(Bt(Pn)(B)))(()=>r));return m>0?I:i.pure()}if(l==="LabelsHidden")return i.pure();g()})())(()=>n.bind((()=>{const I=f(h)(D)(P);return V?I:i.pure()})())(()=>n.bind(d)(()=>r)))))}));return M.alpha*p>0?C:i.pure()}},Q_=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=B_(t),o=t.popAlpha,u=tn(n);return s=>a=>c=>{const f={...s,nodeFill:s.text,text:s.nodeFill,nodeStroke:s.nodeFill};return u(d=>{const l=ae(d._1)(c.nodes),_=ae(d._1)(a.nodes),h=(()=>{if(_.tag==="Just"&&l.tag==="Just"){const p=l._1,m=_._1;return r.bind(t.pushAlpha(d._2))(()=>r.bind(i(_a)(1)(f)(1)(1)(J)(d._1)(m)(p))(()=>o))}return n.pure()})();return d._2>0?h:n.pure()})(Ie(c.nodeInvert))}},LJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=tn(n);return o=>u=>s=>{const a={family:o.fontFamily,size:11,weight:500};return i(c=>{if(c._2===""||(()=>{const l=En(c._1)(s.edges);return l.tag==="Nothing"||!(l.tag==="Just"&&l._1.tag==="Extended")})())return n.pure();const f=En(c._1)(u.edges),d=(()=>{if(f.tag==="Just")return yr(f._1)(.5);if(f.tag==="Nothing")return J;g()})();if(d.tag==="Nothing")return n.pure();if(d.tag==="Just"){const l=d._1;return r.bind(t.measureText(a)(c._2))(_=>{const h=_+12;return r.bind(t.drawRoundedRect({x:l.x-h/2,y:l.y-8.5,w:h,h:17})(3)(w("Just",{color:o.chipPillFill,flat:!0}))(J))(()=>t.drawText({x:l.x,y:l.y,content:c._2,font:a,color:o.chipPillText,align:Xr,baseline:ur}))})}g()})(Ie(u.edgeLabels))}},EJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=t.popAlpha;return o=>u=>s=>a=>c=>f=>d=>l=>_=>{const h=(()=>{if(_>1e-4&&d>1-_){const m=(1-d)/_;return m<0?0:m>1?1:m}if(l>1e-4&&d<l){const m=d/l;return m<0?0:m>1?1:m}return 1})(),p=I_(a)(c)(f)(d)(l)(_);if(p.tag==="CircleShape")return o?F_(t)(p._1)(p._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(gu(p._1)(p._2))({color:u,flat:!0})({color:s,width:1,lineJoin:be,lineCap:pn});if(p.tag==="PolyShape"&&o&&p._1.length>=3)return r.bind(t.pushAlpha(h))(()=>r.bind(F_(t)(x_(p._1))(6)({r:200,g:35,b:30,a:220}))(()=>i));if(p.tag==="PolyShape")return o?n.pure():p._1.length>=3?t.fillStrokePath(sa(p._1))({color:u,flat:!0})({color:s,width:1,lineJoin:be,lineCap:pn}):n.pure();g()}},CJ=t=>{const e=t.Monad0().Bind1(),n=t.popAlpha;return r=>i=>o=>u=>s=>a=>c=>{const f=Ur(a)(c)(s),d={x:o.x+o.w/2,y:o.y+o.h/2},l={x:u.x+u.w/2,y:u.y+u.h/2},_=(h,p)=>e.bind(t.pushAlpha(p))(()=>e.bind(t.fillStrokePath(gu(h)(6))({color:r,flat:!0})({color:i,width:1,lineJoin:be,lineCap:pn}))(()=>n));return f<.5?_(d,(()=>{const h=f*2;return 1-(h<0?0:h>1?1:h)*(h<0?0:h>1?1:h)*(h<0?3:h>1?1:3-2*h)})()):_(l,(()=>{const h=(f-.5)*2;return(h<0?0:h>1?1:h)*(h<0?0:h>1?1:h)*(h<0?3:h>1?1:3-2*h)})())}},mu=t=>{const e=EJ(t),n=CJ(t),r=t.Monad0().Applicative0(),i=tn(r);return o=>u=>s=>a=>c=>i(f=>{if(f._2.tag==="Travelling"){const d=ae(f._2._1.target)(u.nodes),l=ae(f._2._1.source)(u.nodes);if(l.tag==="Just"&&d.tag==="Just"){const _=En(f._2._1.edge)(u.edges);if(_.tag==="Just")return e(o)(a)(c)((()=>{if(f._2._1.direction==="Forward")return _._1;if(f._2._1.direction==="Backward")return we(_._1);g()})())(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);if(_.tag==="Nothing")return n(a)(c)(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);g()}return r.pure()}if(f._2.tag==="Filling"){if(o)return r.pure();const d=ae(f._2._1.node)(u.nodes);if(d.tag==="Just")return t.fillStrokePath(sa(br(4)(Kr(2)(d._1))))({color:a,flat:!0})({color:c,width:1,lineJoin:be,lineCap:pn});if(d.tag==="Nothing")return r.pure();g()}return r.pure()})(Ie(s.tokens))},R_=t=>{const e=mu(t),n=t.Monad0(),r=n.Bind1(),i=mu(t),o=bJ(t),u=t.popClip,s=t.popBlend,a=t.popLayer,c=n.Applicative0(),f=tn(c),d=t.popAlpha;return l=>_=>h=>p=>{const m=_.wobble?e(!0)(h)(p)(_.tokenInside)(_.tokenInsideStroke):r.bind(t.insideTokenStyle(l))(y=>{if(y==="GenieSilhouette")return i(!1)(h)(p)(_.tokenInside)(_.tokenInsideStroke);if(y==="ConvexAbsorb")return o(h)(p)(_.tokenInside)(_.tokenInsideStroke);g()});if(_.tokenInsideBlend==="Difference")return r.bind(t.pushLayer(qx))(()=>r.bind(t.pushBlend(su))(()=>r.bind(t.pushClip(la(h)(p))(uu))(()=>r.bind(m)(()=>r.bind(u)(()=>r.bind(s)(()=>r.bind(a)(()=>r.bind(t.pushLayer(Xx))(()=>r.bind(f(y=>{const x=ae(y._1)(p.nodes);return x.tag==="Just"&&cu(x._1).alpha>0?ia(t)(y._2.shape)({x:y._2.x,y:y._2.y,w:y._2.w,h:y._2.h})(7)(w("Just",{color:ue,flat:!1}))(J):c.pure()})(Ie(h.nodes)))(()=>a)))))))));if(_.tokenInsideBlend==="Normal")return r.bind(t.pushClip(la(h)(p))(uu))(()=>r.bind(t.pushAlpha(_.tokenInsideAlpha))(()=>r.bind(m)(()=>r.bind(d)(()=>u))));g()}},M_=t=>{const e=t.Monad0().Bind1(),n=mu(t),r=mu(t),i=t.popClip,o=t.popLayer;return u=>s=>a=>c=>e.bind(t.pushLayer($x))(()=>e.bind(t.pushClip(NJ(s)(a)(c))(Ux))(()=>e.bind(u.wobble?n(!0)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke):r(!1)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke))(()=>e.bind(i)(()=>o))))},SJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=tn(r);return o=>u=>s=>a=>c=>f=>{const d=ko(f).length,l=et(d+1|0),_=m=>{const y=(s*l-et(m))/1.5,x=y<0?0:y>1?1:y;return x*x*(3-2*x)},h=(m=>{let y=m,x=!0,N;for(;x;){const v=y;if(v>=d){x=!1,N=v;continue}if(_(v)>=1){y=v+1|0;continue}x=!1,N=v}return N})(0),p=h>=d?[]:_r(m=>_(m)>0)(Ft(h,d-1|0)).init;return n.bind((()=>{const m=t.drawText({x:a,y:c,content:ye(h)(f),font:o,color:u,align:ta,baseline:ur});return h>0?m:r.pure()})())(()=>i(m=>n.bind(t.measureText(o)(ye(m)(f)))(y=>{const x=_(m);return t.drawText({x:a+y,y:c-(1-x)*10,content:ye(1)(li(jn(ye(m)(f)))(f)),font:o,color:{...u,a:ce(mn(x*et(u.a)))},align:ta,baseline:ur})}))(p))}},yu=t=>e=>n=>r=>{const i=O(_=>et(pu(1)(ko(_).length)))(r),o=Xi(1)(T(Gr)(0)(i)),u=Ur(e)(n)(t),s=u*o,a=pu(1)(r.length),c=(_=>h=>p=>{let m=_,y=h,x=p,N=!0,v;for(;N;){const k=m,L=y,E=Qt(B=>J,B=>q=>w("Just",{head:B,tail:q}),x);if(E.tag==="Nothing"){N=!1,v=pu(0)(a-1|0);continue}if(E.tag==="Just"){if(L+E._1.head>=s){N=!1,v=k;continue}m=k+1|0,y=L+E._1.head,x=E._1.tail;continue}g()}return v})(0)(0)(i),f=T(Gr)(0)(c<1?[]:Lt(0,c,i)),d=f/o;if(c>=0&&c<i.length){const _=(f+i[c])/o;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(_<=d)return 1;const h=(u-d)/(_-d);return h<0?0:h>1?1:h})()}}const l=(f+1)/o;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(l<=d)return 1;const _=(u-d)/(l-d);return _<0?0:_>1?1:_})()}},GJ=t=>{const e=t.Monad0();return n=>r=>i=>e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(yu(r)(0)(0)(O(nd)(i)).line))(o=>{const u=o+28;return e.Applicative0().pure({x:n.x+n.w/2-u/2,y:n.y-25.2-14,w:u,h:25.2})})},PJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=GJ(t),i=e.Applicative0(),o=cr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>P_(xt(c=>c)(a)))(o(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const c=ae(a._2._1.node)(u.nodes);if(c.tag==="Just")return n.bind(r(c._1)(a._2._1.progress)(a._2._1.labels))(f=>i.pure(w("Just",b(a._1,f))));if(c.tag==="Nothing")return i.pure(J);g()}return i.pure(J)})(Ie(s.tokens)))},DJ=t=>{const e=t.Monad0();return n=>r=>i=>o=>u=>s=>a=>{const c=A_(n)(r)(i)(o)(u)(s);return e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(yu(o)(u)(s)(wt(a)(ha)).line))(f=>e.Applicative0().pure({x:c.x+14+f/2-f/2-14,y:c.y-6-8-6.6-6,w:f+28,h:25.2}))}},IJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=DJ(t),i=e.Applicative0(),o=cr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>P_(xt(c=>c)(a)))(o(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const c=ae(a._2._1.target)(u.nodes),f=ae(a._2._1.source)(u.nodes),d=En(a._2._1.edge)(u.edges);if(d.tag==="Just"&&f.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 we(d._1);g()})())(f._1)(c._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(l=>i.pure(w("Just",b(a._1,l))))}return i.pure(J)})(Ie(s.tokens)))},pa=t=>{const e=t.Monad0(),n=e.Bind1(),r=IJ(t),i=PJ(t);return o=>u=>n.bind(r(o)(u))(s=>n.bind(i(o)(u))(a=>e.Applicative0().pure(xJ((()=>{const c=f=>{if(f.tag==="Leaf")return A;if(f.tag==="Node")return Yt("Node",f._1,f._2,f._3,void 0,c(f._5),c(f._6));g()};return Et(S.compare)(Ct(Qe.foldr,c(s)))})())(s)([...xt(c=>{const f=ae(c._1)(u.nodes);return f.tag==="Just"&&cu(f._1).alpha>0?w("Just",{x:c._2.x,y:c._2.y,w:c._2.w,h:c._2.h}):J})(Ie(o.nodes)),...(()=>{const c=(f,d)=>{if(f.tag==="Leaf")return d;if(f.tag==="Node")return c(f._5,$t("Cons",f._4,c(f._6,d)));g()};return Ct(Vt.foldr,c(a,Xt))})()]))))},z_=t=>e=>n=>{const r=wi(6)(.55)(hu(0)(1)((1-t)/.06)),i=t>.94,o=i&&n>1e-4,u=wi(6)(.55)(hu(0)(1)(t/.06)),s=t<.06,a=s&&e>1e-4,c=i&&n<=1e-4;return{popScale:a?u:o?r:1,flipY:s&&e<=1e-4?u:c?r:1,fadeAlpha:(()=>{if(a){const f=t/.06;return f<0?.55:f>1?1:.55+.44999999999999996*f}if(o){const f=(1-t)/.06;return f<0?.55:f>1?1:.55+.44999999999999996*f}return 1})()}},AJ=t=>{const e=t.Monad0().Bind1(),n=D_(t);return r=>i=>o=>u=>s=>{const a=z_(u)(0)(0),c={family:r.fontFamily,size:11,weight:500},f=yu(u)(0)(0)(wt(s)(ha));return e.bind(t.measureText(c)(f.line))(d=>{const l=o.x+o.w/2,_=d+28,h=o.y-25.2-14,p=l-_/2,m=[1,l,h+25.2,2,l,o.y],y={x:l,y:h+12.6};return n(a)(l-_/2)(h+25.2)(y)(e.bind(t.drawRoundedRect({x:l-_/2,y:h+1.5,w:_,h:25.2})(6)(w("Just",{color:r.chipShadow,flat:!0}))(J))(()=>e.bind(t.drawRoundedRect({x:p,y:h,w:_,h:25.2})(6)(w("Just",{color:r.chip,flat:!0}))(w("Just",{color:r.chipHairline,width:1,lineJoin:be,lineCap:pn})))(()=>e.bind(t.strokePath(m)({color:r.chipHairline,width:1,lineJoin:be,lineCap:pn}))(()=>t.drawText({x:l,y:y.y,content:f.line,font:c,color:r.chipText,align:Xr,baseline:ur})))))})}},FJ=t=>{const e=D_(t),n=t.Monad0(),r=n.Bind1(),i=tn(n.Applicative0()),o=SJ(t);return u=>s=>a=>c=>f=>d=>l=>_=>h=>{const p=yu(f)(d)(l)(wt(_)(ha)),m=p.line,y=p.phaseInLabel/.45,x=y<0?0:y>1?1:y,N=h.w,v=h.y,k=h.x,L=k+14,E=h.h,B=v+E/2;return e(z_(f)(d)(l))(k)(v+E)({x:k+N/2,y:B})(r.bind(i(q=>t.fillPath(gu(q)(1.5))({color:u.trailDot,flat:!0}))(TJ(h)(A_(s)(a)(c)(f)(d)(l))))(()=>r.bind(t.drawRoundedRect({x:k,y:v,w:N,h:E})(3)(w("Just",{color:u.chipPillFill,flat:!0}))(J))(()=>o({family:u.fontFamily,size:11,weight:500})(u.chipPillText)(x)(L)(B)(m))))}},ma=t=>{const e=FJ(t),n=t.Monad0(),r=n.Applicative0(),i=AJ(t),o=n.Bind1(),u=tn(r),s=t.popLayer;return a=>c=>f=>d=>o.bind(t.pushLayer(Vx))(()=>o.bind(u(l=>{if(l._2.tag==="Travelling"){if(l._2._1.labels.length!==0){const _=ae(l._2._1.target)(c.nodes),h=ae(l._2._1.source)(c.nodes),p=En(l._2._1.edge)(c.edges),m=G_(l._1)(d);if(m.tag==="Just"&&p.tag==="Just"&&h.tag==="Just"&&_.tag==="Just")return e(a)((()=>{if(l._2._1.direction==="Forward")return p._1;if(l._2._1.direction==="Backward")return we(p._1);g()})())(h._1)(_._1)(l._2._1.progress)(l._2._1.holdPre)(l._2._1.holdPost)(l._2._1.labels)(m._1)}return r.pure()}if(l._2.tag==="Filling"&&l._2._1.labels.length!==0){const _=ae(l._2._1.node)(c.nodes);if(_.tag==="Just")return i(a)(c)(_._1)(l._2._1.progress)(l._2._1.labels);if(_.tag==="Nothing")return r.pure();g()}return r.pure()})(Ie(f.tokens)))(()=>s))},H_=t=>{const e=pa(t),n=ma(t);return r=>i=>o=>t.Monad0().Bind1().bind(e(i)(o))(u=>n(r)(i)(o)(u))},BJ=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>i=>{const o=i.length-1|0,u=o<1?[]:Lt(0,o,i),s=u.length-1|0,a=s>=0&&s<u.length?w("Just",u[s]):J,c=i.length-1|0,f=c>=0&&c<i.length?w("Just",i[c]):J;if(f.tag==="Just"&&a.tag==="Just"){const d=pe(.78)(1.18)(qi(i)+19|0),l=pe(.4)(.62)(d.prng),_=r.wobble?8.75*l.value:4.375,h=pe(.4)(.62)(l.prng),p=r.wobble?8.75*h.value:4.375,m=f._1.y-a._1.y,y=f._1.x-a._1.x,x=Ce(y*y+m*m),N=m/x,v=-N,k=y/x,L=f._1.x+k*.875,E=f._1.y+N*.875,B=r.wobble?8.75*d.value:8.75,q=L-k*B,j=E-N*B,G=q+v*_,P=j+k*_,V=[1,L,E,2,q+v*4.375,j+k*4.375,2,q-v*4.375,j-k*4.375,5],U=q-v*p,M=j-k*p,H={color:r.arrowFill,width:2,lineJoin:be,lineCap:bn};return x<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,G,P,2,L,E])(H))(()=>t.strokePath([1,U,M,2,L,E])(H)):t.fillPath(V)({color:r.arrowFill,flat:!0})}return n.pure()}},QJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=tn(n),o=t.popAlpha,u=BJ(t);return s=>a=>c=>f=>{const d=ON(8)(c);if(f.hi<=f.lo)return n.pure();const l=ZN(d)(f.lo)(f.hi);if(l.length===0)return n.pure();const _={color:s.edge,width:s.wobble?2:.9375,lineJoin:be,lineCap:bn},h=s.wobble?pe(-10)(4)(qi(l)).value:0,p=s.wobble?sJ(h)(l):l;return r.bind(s.wobble?i(m=>r.bind(t.pushAlpha(m.alpha))(()=>r.bind(t.strokePath(m.path)(_))(()=>o)))((()=>{const m=qi(l);return p.length<2?[]:Zr(vJ)(m)(!1)(p)})()):t.strokePath(MN(l))(_))(()=>{const m=u(s)(p);return f.hi>=.999?m:n.pure()})}},W_=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=QJ(t),o=t.popAlpha,u=tn(n);return s=>a=>c=>{const f=d=>{const l=Kt(_=>d.x>=_._2.x-1&&d.x<=_._2.x+_._2.w+1&&d.y>=_._2.y-1&&d.y<=_._2.y+_._2.h+1)(Ie(a.nodes));return l.tag==="Just"?w("Just",l._1._2):J};return u(d=>{const l=En(d._1)(c.edges);if(l.tag==="Just"){const _=l._1,h=En(d._1)(c.edgeFadeAlpha),p=(()=>{if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1;g()})(),m=r.bind(t.pushAlpha(p))(()=>r.bind(i(s)(d._1)((()=>{const y=(()=>{if(0<d._2.length){const N=f(d._2[0]);if(N.tag==="Just")return we(J_(br(7)(N._1))(we(d._2)))}return d._2})(),x=y.length-1|0;if(x>=0&&x<y.length){const N=f(y[x]);if(N.tag==="Just")return J_(br(7)(N._1))(y)}return y})())((()=>{if(_.tag==="Retracted")return{lo:0,hi:0};if(_.tag==="Extended")return{lo:0,hi:1};if(_.tag==="Extending")return{lo:0,hi:_._2};if(_.tag==="Retracting"){if(_._1==="FromSource")return{lo:_._2,hi:1};if(_._1==="FromTarget")return{lo:0,hi:1-_._2};if(_._1==="FromBoth")return{lo:_._2/2,hi:1-_._2/2}}g()})()))(()=>o));return p>0?m:n.pure()}if(l.tag==="Nothing")return n.pure();g()})(Ie(a.edges))}},RJ=t=>e=>{const n=o=>{const u=ae(o)(t.nodes);if(u.tag==="Nothing")return!1;if(u.tag==="Just"){const s=u._1;return!Oe(a=>0<a._2.length&&a._2[0].x>=s.x&&a._2[0].x<=s.x+s.w&&a._2[0].y>=s.y&&a._2[0].y<=s.y+s.h,Ie(t.edges))}g()},r=T(o=>u=>(o*31|0)+er(u)|0)(5381)(hr(e.frameTitle)),i=o=>{const u=ae(o)(t.nodes);if(u.tag==="Nothing")return!1;if(u.tag==="Just"){const s=u._1;return!Oe(a=>{const c=a._2.length-1|0;return c>=0&&c<a._2.length&&a._2[c].x>=s.x&&a._2[c].x<=s.x+s.w&&a._2[c].y>=s.y&&a._2[c].y<=s.y+s.h},Ie(t.edges))}g()};return T(o=>u=>{const s=u._2;return hJ(a=>{if(a.tag==="Nothing")return w("Just",s);if(a.tag==="Just")return w("Just",{t:Xi(a._1.t)(s.t),angle:s.t>=a._1.t?s.angle:a._1.angle,bigCircle:a._1.bigCircle||s.bigCircle,frameHash:a._1.frameHash});g()})(u._1)(o)})(A)(wt(Ie(e.tokens))(o=>{if(o._2.tag==="Filling"){const u=o._2._1.node;return[b(u,{t:1,angle:(()=>{const s=xt(a=>(()=>{const c=ae(u)(t.nodes),f=a._2.length-1|0;return f>=0&&f<a._2.length&&c.tag==="Just"&&a._2[f].x>=c._1.x&&a._2[f].x<=c._1.x+c._1.w&&a._2[f].y>=c._1.y&&a._2[f].y<=c._1.y+c._1.h})()?w("Just",a._2):J)(Ie(t.edges));if(0<s.length){const a=s[0].length-1|0,c=a<1?[]:Lt(0,a,s[0]),f=c.length-1|0;if(f>=0&&f<c.length){const d=s[0].length-1|0;return d>=0&&d<s[0].length?dr(s[0][d].y-c[f].y)(s[0][d].x-c[f].x):0}s[0].length-1|0}return 0})(),bigCircle:n(u)||i(u),frameHash:r})]}if(o._2.tag==="Travelling"){if(o._2._1.progress>=.75)return[b(o._2._1.target,{t:(o._2._1.progress-.75)/.25,angle:(()=>{const u=En(o._2._1.edge)(t.edges);if(u.tag==="Just"){const s=u._1.length-1|0,a=s<1?[]:Lt(0,s,u._1),c=a.length-1|0;if(c>=0&&c<a.length){const f=u._1.length-1|0;return f>=0&&f<u._1.length?dr(u._1[f].y-a[c].y)(u._1[f].x-a[c].x):0}return u._1.length-1|0,0}if(u.tag==="Nothing")return 0;g()})(),bigCircle:n(o._2._1.target)||i(o._2._1.target),frameHash:r})];if(o._2._1.progress<.25)return[b(o._2._1.source,{t:o._2._1.progress/.25,angle:(()=>{const u=En(o._2._1.edge)(t.edges);if(u.tag==="Just")return 1<u._1.length&&0<u._1.length?dr(u._1[1].y-u._1[0].y)(u._1[1].x-u._1[0].x):0;if(u.tag==="Nothing")return 0;g()})(),bigCircle:n(o._2._1.source)||i(o._2._1.source),frameHash:r})]}return[]}))},MJ=t=>T(e=>n=>(e*31|0)+er(n)|0)(5381)(hr(t.frameTitle)),O_=t=>{const e=B_(t),n=t.Monad0().Applicative0(),r=tn(n);return i=>o=>u=>s=>a=>{const c=MJ(a),f=RJ(s)(a);return r(d=>{const l=ae(d._1)(a.nodes);if(l.tag==="Just")return e(i)(o)(u)((()=>{const _=ae(d._1)(a.nodeFadeAlpha);if(_.tag==="Nothing")return 1;if(_.tag==="Just")return _._1;g()})())((()=>{const _=ae(d._1)(a.nodeLabelFadeAlpha);if(_.tag==="Nothing")return 1;if(_.tag==="Just")return _._1;g()})())((()=>{const _=ae(d._1)(f);return _.tag==="Just"?w("Just",_._1):_.tag==="Nothing"&&pJ(d._1)(a.visited)?w("Just",{t:1,angle:0,bigCircle:!1,frameHash:c}):J})())(d._1)(d._2)(l._1);if(l.tag==="Nothing")return n.pure();g()})(Ie(s.nodes))}},zJ=t=>t,HJ=t=>e=>{const n=e.vw/e.vh,r=e.vh*t,i={...e,vx:e.vx-(r-e.vw)/2,vw:r},o=e.vw/t,u={...e,vy:e.vy-(o-e.vh)/2,vh:o};return t<=0||e.vw<=0||e.vh<=0?e:t>n?i:t<n?u:e},WJ=t=>e=>n=>{const r=nt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=nt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},Y_=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},$_=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ya=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},OJ=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},YJ=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},$J=t=>e=>{const n=Ve(t.angle),r=rn(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},qJ=t=>[t.box.ground.a,t.box.ground.b,t.box.ground.c,t.box.ground.d,t.box.top.a,t.box.top.b,t.box.top.c,t.box.top.d],jr=t=>e=>{const n=r=>WJ(0)(255)(ce(Dn(et(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},Ge=t=>e=>n=>r=>({x:(e-n)*rn(t.angle),y:(e+n)*Ve(t.angle)-r}),Lr=t=>{const e=Qt(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...wt(e._1.tail)(n=>[2,n.x,n.y]),5];g()},XJ=t=>e=>n=>r=>i=>{const o=(()=>{if(t==="Forward")return i;if(t==="Backward")return we(i);g()})();if(0<o.length){const s=yr(o)(Y_(0)(1)(Ur(n)(r)(e)));if(s.tag==="Nothing")return o[0];if(s.tag==="Just")return s._1;g()}const u=yr(o)(Y_(0)(1)(Ur(n)(r)(e)));if(u.tag==="Nothing")return{x:0,y:0};if(u.tag==="Just")return u._1;g()},VJ=t=>{const e=Qt(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...wt(e._1.tail)(n=>[2,n.x,n.y])];g()},UJ=t=>{const e=Qt(n=>J,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{vx:0,vy:0,vw:0,vh:0};if(e.tag==="Just"){const n=T(r=>i=>({minX:$_(r.minX)(i.x),minY:$_(r.minY)(i.y),maxX:ya(r.maxX)(i.x),maxY:ya(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{vx:n.minX-40,vy:n.minY-40,vw:n.maxX-n.minX+80,vh:n.maxY-n.minY+80}}g()},KJ=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>{const o=i.box,u=i.np,s={color:r.nodeStroke,width:1,lineJoin:be,lineCap:pn};return e.bind(t.fillStrokePath(Lr([o.ground.d,o.ground.c,o.top.c,o.top.d]))({color:jr(.66)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(Lr([o.ground.b,o.ground.c,o.top.c,o.top.b]))({color:jr(.82)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(Lr([o.top.a,o.top.b,o.top.c,o.top.d]))({color:jr(1)(r.nodeFill),flat:!0})(s))(()=>t.drawTextAffine($J(n)(u.y+u.h))({x:u.x+u.w/2,y:0,content:u.label,font:{family:r.fontFamily,size:11,weight:600},color:r.text,align:Xr,baseline:ur}))))}},ZJ=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>o=>{const u={color:r.tokenOutsideStroke,width:1,lineJoin:be,lineCap:pn},s=o.x-5.5,a=o.x+5.5,c=o.y-5.5,f=o.y+5.5,d=i+11,l=Ge(n)(s)(c)(d),_=Ge(n)(a)(c)(d),h=Ge(n)(a)(f)(d),p=Ge(n)(s)(f)(d),m=Ge(n)(a)(f)(i),y=Ge(n)(a)(c)(i);return e.bind(t.fillStrokePath(Lr([Ge(n)(s)(f)(i),m,h,p]))({color:jr(.66)(r.tokenOutsideFill),flat:!0})(u))(()=>e.bind(t.fillStrokePath(Lr([y,m,h,_]))({color:jr(.82)(r.tokenOutsideFill),flat:!0})(u))(()=>t.fillStrokePath(Lr([l,_,h,p]))({color:jr(1)(r.tokenOutsideFill),flat:!0})(u)))}},jJ=t=>{const e=ZJ(t);return n=>r=>i=>o=>{if(o.tag==="Travelling"){const u=OJ(o._1.edge)(i.edges);return u.tag==="Just"?w("Just",(()=>{const s=XJ(o._1.direction)(o._1.progress)(o._1.holdPre)(o._1.holdPost)(u._1);return{depth:s.x+s.y,draw:e(n)(r)(0)(s)}})()):J}if(o.tag==="Filling"){const u=YJ(o._1.node)(i.nodes);if(u.tag==="Just")return w("Just",(()=>{const s={x:u._1.x+u._1.w/2,y:u._1.y+u._1.h/2};return{depth:s.x+s.y,draw:e(n)(r)(n.boxHeight)(s)}})())}return J}},tT={angle:.5235987755982988,boxHeight:26,transparentBg:!0},eT=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:Ge(t)(e.x)(e.y)(0),b:Ge(t)(r)(e.y)(0),c:Ge(t)(r)(n)(0),d:Ge(t)(e.x)(n)(0)},top:{a:Ge(t)(e.x)(e.y)(t.boxHeight),b:Ge(t)(r)(e.y)(t.boxHeight),c:Ge(t)(r)(n)(t.boxHeight),d:Ge(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},q_=t=>e=>O(n=>({np:n,box:eT(t)(n)}))((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,$t("Cons",r._4,n(r._6,i)));g()};return Ct(Vt.foldr,n(e.nodes,Xt))})()),nT=t=>e=>[...wt(q_(t)(e))(qJ),...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,$t("Cons",r._4,n(r._6,i)));g()};return wt(Ct(Vt.foldr,n(e.edges,Xt)))(O(r=>Ge(t)(r.x)(r.y)(0)))})()],rT=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=ya(1e-4)(Ce(n*n+e*e)),i=e/r,o=n/r,u=t.to.y-i*7,s=t.to.x-o*7;return Lr([t.to,{x:s-i*3,y:u+o*3},{x:s+i*3,y:u-o*3}])},iT=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>i=>o=>u=>s=>{const a=Ge(r)(s.x)(s.y)(0),c=Ge(r)(u.x)(u.y)(0);return e.Bind1().bind(t.strokePath(VJ([c,a]))({color:i.edge,width:1.5,lineJoin:be,lineCap:bn}))(()=>{const f=t.fillPath(rT({from:c,to:a}))({color:i.arrowFill,flat:!0});return o?f:n.pure()})}},oT=t=>{const e=iT(t);return n=>r=>i=>{const o=ve(Pn,i,Lt(1,i.length,i)),u=o.length-1|0;return Bt(s=>a=>({depth:(a._1.x+a._1.y+a._2.x+a._2.y)/2,draw:e(n)(r)(s===u)(a._1)(a._2)}))(o)}},uT=t=>{const e=KJ(t),n=jJ(t),r=oT(t),i=t.Monad0(),o=Du(i.Applicative0())(zt);return u=>s=>a=>c=>{const f=da(s),d=[...(()=>{const l=(_,h)=>{if(_.tag==="Leaf")return h;if(_.tag==="Node")return l(_._5,$t("Cons",_._4,l(_._6,h)));g()};return wt(Ct(Vt.foldr,l(a.edges,Xt)))(r(u)(f))})(),...O(l=>({depth:l.box.depth,draw:e(u)(f)(l)}))(q_(u)(a)),...xt(n(u)(f)(a))((()=>{const l=(_,h)=>{if(_.tag==="Leaf")return h;if(_.tag==="Node")return l(_._5,$t("Cons",_._4,l(_._6,h)));g()};return Ct(Vt.foldr,l(c.tokens,Xt))})())];return i.Bind1().bind((()=>{const l=UJ(nT(u)(a));return t.Monad0().Bind1().bind(t.clearBackground(u.transparentBg?f.bgTransparent:f.bg))(()=>t.setViewport(l))})())(()=>o(l=>l.draw)(Et(l=>_=>it.compare(l.depth)(_.depth))(d)))}},X_=(t,e)=>({tag:t,_1:e}),xu=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},sT=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},xa=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},aT=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},cT=X_("ResolvedLabels"),gT=t=>{const e=Kt(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return Ao(t);g()},Nu=t=>e=>{const n=xu(1)(qe(e.rootLayout).w),r=Sc(e.rootLayout)(e.camera),i=!e.diving&&e.levels.length===1?1:sT(0)(1)(r.w/n),o=Ao(e).state.frameTitle===""?0*i:40*i,u=t.padding*i;return(()=>{if(t.outputAspect.tag==="Nothing")return zJ;if(t.outputAspect.tag==="Just")return HJ(t.outputAspect._1);g()})()({vx:r.x-u,vy:r.y-u-o,vw:r.w+2*u,vh:r.h+2*u+o})},fT=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=xa(e._1)(t.segment.layout.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1.x*t.segment.placement.scale+t.segment.placement.tx,i=n._1.y*t.segment.placement.scale+t.segment.placement.ty,o=n._1.w*t.segment.placement.scale,u=n._1.h*t.segment.placement.scale;return[1,r,i,2,r+o,i,2,r+o,i+u,2,r,i+u,5]}}g()},_T=t=>{const e=t.Monad0(),n=e.Bind1();return r=>i=>{if(r==="")return e.Applicative0().pure();const o=i.vh/720,u=56*o;return n.bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:56,weight:700})(r))(s=>{const a=u+16*o*2,c=s*o+28*o*2,f=i.vy+i.vh/2,d=i.vx+i.vw/2;return n.bind(t.drawRoundedRect({x:d-c/2,y:f-a/2,w:c,h:a})(16*o)(w("Just",{color:{r:255,g:255,b:255,a:235},flat:!0}))(w("Just",{color:{r:0,g:0,b:0,a:255},width:1.5*o,lineJoin:be,lineCap:bn})))(()=>t.drawText({x:d,y:f,content:r,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:700},color:{r:28,g:30,b:36,a:255},align:Xr,baseline:ur}))})}},dT=t=>{const e=t.Monad0(),n=e.Bind1();return r=>i=>{if(r==="")return e.Applicative0().pure();const o=i.vh/720,u=15*o;return n.bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:15,weight:600})(r))(s=>{const a=i.vy+12*o,c=u+6*o*2,f=s*o+11*o*2,d=i.vx+i.vw/2;return n.bind(t.drawRoundedRect({x:d-f/2,y:a,w:f,h:c})(c/2)(w("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}))(w("Just",{color:{r:0,g:0,b:0,a:255},width:1*o,lineJoin:be,lineCap:bn})))(()=>t.drawText({x:d,y:a+c/2,content:r,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:600},color:{r:28,g:30,b:36,a:255},align:Xr,baseline:ur}))})}},lT=t=>{const e=H_(t),n=ma(t),r=t.Monad0(),i=r.Bind1(),o=r.Applicative0(),u=W_(t),s=O_(t)(_a)(1),a=Q_(t),c=M_(t),f=R_(t),d=LJ(t),l=t.popBlur,_=t.popAlpha,h=_T(t),p=dT(t);return m=>y=>x=>N=>v=>k=>L=>E=>{const B=da(m.theme),q=(()=>{if(E.tag==="ResolvedLabels")return e(B)(k)(L);if(E.tag==="SpringLabels")return n(B)(k)(L)(E._1);g()})();return i.bind(t.Monad0().Bind1().bind(t.clearBackground(m.transparentBg?B.bgTransparent:B.bg))(()=>t.setViewport(v)))(()=>i.bind((()=>{const j=i.bind((()=>{const G=t.pushAlpha(x);return x<1?G:o.pure()})())(()=>i.bind((()=>{const G=t.pushBlur(N);return N>0?G:o.pure()})())(()=>i.bind(u(B)(k)(L))(()=>i.bind(s(B)(k)(L))(()=>i.bind(a(B)(k)(L))(()=>i.bind(c(B)(v)(k)(L))(()=>i.bind(f(tN)(B)(k)(L))(()=>i.bind(q)(()=>i.bind((()=>{const G=d(B)(k)(L);return L.staticKind!=="Animated"?G:o.pure()})())(()=>i.bind(N>0?l:o.pure())(()=>x<1?_:o.pure()))))))))));return x>0?j:o.pure()})())(()=>i.bind(m.watermark===""?t.Monad0().Applicative0().pure():t.drawText({x:v.vx+6,y:v.vy+6,content:m.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:ta,baseline:Yx}))(()=>L.staticKind==="TitleCard"?h(L.frameTitle)(v):p(L.frameTitle)(v))))}},V_=t=>{const e=t.Monad0().Applicative0(),n=Xa(e)(zt);return r=>i=>o=>u=>n(u.minis)(s=>{const a=U_(t)(r)(i)(o)(A)(u)(s);return(()=>{const c=s.segment.path.length-1|0;return s.bgAlpha>0&&c>=0&&c<s.segment.path.length&&(()=>{const f=xa(s.segment.path[c])(u.state.nodes);if(f.tag==="Just")return f._1.tag==="Hidden"?!1:f._1.tag!=="PloppingOut";if(f.tag==="Nothing")return!1;g()})()})()?a:e.pure()})},U_=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=t.popTransform,o=H_(t),u=ma(t),s=W_(t),a=O_(t),c=Q_(t),f=M_(t),d=R_(t),l=t.popBakedTransform,_=t.popClip,h=t.popBlur,p=t.popAlpha;return m=>y=>x=>N=>v=>k=>{const L=k.blur>0,E=k.segment.placement,B=k.state,q={tx:E.tx,ty:E.ty,sx:E.scale,sy:E.scale},j=da(m.theme),G=k.segment.layout,P=qe(G),V={vx:P.x-1e3,vy:P.y-1e3,vw:P.w+2e3,vh:P.h+2e3},U=k.segment.path.length-1|0,M=U>=0&&U<k.segment.path.length?xa(k.segment.path[U])(v.segment.layout.nodes):J,H=k.segment.placement.scale*x,R=aT(8)(xu(1)(1/(1.25*xu(1e-6)(H)))),C=11*H>=5?_a:mJ,D=(()=>{if(M.tag==="Nothing")return n.pure();if(M.tag==="Just"){const z=M._1;return r.bind(t.pushTransform({tx:v.segment.placement.tx,ty:v.segment.placement.ty,sx:v.segment.placement.scale,sy:v.segment.placement.scale}))(()=>r.bind(ia(t)(z.shape)({x:z.x+1,y:z.y+1,w:z.w-2,h:z.h-2})(7)(w("Just",{color:j.bg,flat:!0}))(J))(()=>i))}g()})(),F=(()=>{if(C==="LabelsHidden")return n.pure();if(C==="LabelsShown")return N.tag==="Leaf"?o(j)(G)(B):u(j)(G)(B)(N);g()})(),I=fT(v)((()=>{const z=k.segment.path.length-1|0;return z>=0&&z<k.segment.path.length?w("Just",k.segment.path[z]):J})());return r.bind(t.pushAlpha(k.bgAlpha))(()=>r.bind((()=>{const z=t.pushBlur(k.blur*E.scale);return L?z:n.pure()})())(()=>r.bind(t.pushClip(I)(uu))(()=>r.bind(v.role==="Active"||v.role==="FlyThrough"?D:n.pure())(()=>r.bind(t.pushTransform(q))(()=>r.bind(s(j)(G)(B))(()=>r.bind(a(C)(R)(j)(G)(B))(()=>r.bind(c(j)(G)(B))(()=>r.bind(f(j)(V)(G)(B))(()=>r.bind(i)(()=>r.bind(t.pushBakedTransform(q))(()=>r.bind(d(eN)(j)(G)(B))(()=>r.bind(l)(()=>r.bind(t.pushTransform(q))(()=>r.bind(F)(()=>r.bind(i)(()=>r.bind(_)(()=>r.bind(V_(t)(m)(y)(x)(k))(()=>r.bind(L?h:n.pure())(()=>p)))))))))))))))))))}},K_=t=>{const e=uT(t),n=t.Monad0(),r=n.Applicative0(),i=n.Bind1(),o=U_(t),u=lT(t),s=V_(t);return a=>c=>f=>{if(a.theme==="Isometric")return e({...tT,transparentBg:a.transparentBg})(a.theme)(Ao(f).segment.layout)(Ao(f).state);const d=Nu(a)(f),l=m=>f.hasDives?d.vw/xu(1)(qe(f.rootLayout).w):1,_={tileScale:l(),viewport:d},h=m=>y=>{if(y.length===0)return r.pure();const x=Qt(N=>J,N=>v=>w("Just",{head:N,tail:v}),y);if(x.tag==="Nothing")return r.pure();if(x.tag==="Just"){const N=x._1.head,v=x._1.tail;return i.bind((()=>{const k=o(a)(_)(f.camera.zoom)(N.role==="Active"?c:A)(m)(N);return f.diving||N.role==="Active"?k:r.pure()})())(()=>h(N)(v))}g()},p=Qt(m=>J,m=>y=>w("Just",{head:m,tail:y}),f.levels);if(p.tag==="Nothing")return r.pure();if(p.tag==="Just"){const m=p._1.tail,y=p._1.head;return i.bind((()=>{const x=m.length===0;return u(a)(l())(y.role==="Active"||y.role==="FlyThrough"?y.bgAlpha:0)(y.blur)(d)(y.segment.layout)(gT(f).state)(x&&c.tag!=="Leaf"?X_("SpringLabels",c):cT)})())(()=>i.bind((()=>{const x=s(a)(_)(f.camera.zoom)(y);return y.role==="Active"||y.role==="FlyThrough"?x:r.pure()})())(()=>h(y)(m)))}g()}},hT=pa(g_),Z_=K_(g_),pT=t=>e=>n=>r=>i=>o=>u=>{const s={padding:24,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?J:w("Just",r.width/r.height)},a=pN(n)(r);return()=>{const c=a(),f=i.levels.length-1|0;if(f>=0&&f<i.levels.length){const l=hT(i.levels[f].segment.layout)(i.levels[f].state)(c)(),_=Zs(o)(l)(u);return Z_(s)(_.applied)(i)(c)(),_.springs}const d=Zs(o)(A)(u);return Z_(s)(d.applied)(i)(c)(),d.springs}},mT=t=>t,Vi=t=>t,Na=Vi("Light"),yT=Vi("Dark"),xT=Vi("Blueprint"),NT=Vi("Whiteboard"),JT=Vi("Isometric"),TT=mT("TransparentBackground"),sr=t=>"rgb("+ee(t.r)+","+ee(t.g)+","+ee(t.b)+")",Cn=gi(ai("Fixed",ci(0)(20)(4))),wT=t=>"translate("+Cn(t.tx)+","+Cn(t.ty)+") scale("+Cn(t.sx)+","+Cn(t.sy)+")",vt=gi(ai("Fixed",ci(0)(20)(2))),Ja=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,i=r>=0&&r<t.length?w("Just",t[r]):J;if(i.tag==="Nothing"){n=t.length;continue}if(i.tag==="Just"){if(i._1===1){e.push("M"),e.push(vt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===2){e.push("L"),e.push(vt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===3){e.push("Q"),e.push(vt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),n=r+5|0;continue}if(i._1===4){e.push("C"),e.push(vt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+5|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+6|0;return o>=0&&o<t.length?t[o]:0})())),n=r+7|0;continue}if(i._1===5){e.push("Z"),n=r+1|0;continue}n=t.length;continue}g()}return vo(" ")(e)},vT={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},Ta=(()=>{const t=nr("&")("&amp;"),e=nr("<")("&lt;"),n=(()=>{const r=nr(">")("&gt;"),i=(()=>{const o=nr('"')("&quot;");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),bT=t=>{if(t.style==="RunText")return"<tspan>"+Ta(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+Ta(t.text)+"</tspan>";g()},ke=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},kT=t=>e=>{const n=[];let r=0;const i=o=>{const u=o>=0&&o<e.length?t.sx*e[o]+t.tx:t.sx*0+t.tx;return()=>{n.push(u),n.push((()=>{const s=o+1|0;return s>=0&&s<e.length?t.sy*e[s]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const o=r,u=o>=0&&o<e.length?w("Just",e[o]):J;if(u.tag==="Nothing"){r=e.length;continue}if(u.tag==="Just"){if(u._1===1){n.push(u._1),i(o+1|0)(),r=o+3|0;continue}if(u._1===2){n.push(u._1),i(o+1|0)(),r=o+3|0;continue}if(u._1===3){n.push(u._1),i(o+1|0)(),i(o+3|0)(),r=o+5|0;continue}if(u._1===4){n.push(u._1),i(o+1|0)(),i(o+3|0)(),i(o+5|0)(),r=o+7|0;continue}if(u._1===5){n.push(u._1),r=o+1|0;continue}r=e.length;continue}g()}return n},Ju=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return kT(r._1)(e);g()}},j_={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>vT},LT={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>j_},ET={pure:t=>e=>()=>t,Apply0:()=>j_},CT={Applicative0:()=>ET,Bind1:()=>LT},ST=t=>e=>'<defs><pattern id="'+t+'" x="'+vt(e.origin.x)+'" y="'+vt(e.origin.y)+'" width="'+vt(e.tile)+'" height="'+vt(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+vt(e.tile)+'" height="'+vt(e.tile)+'" fill="'+sr(e.bgColor)+'" fill-opacity="'+vt(et(e.bgColor.a)/255)+'"/>')+'<circle cx="'+vt(e.tile/2)+'" cy="'+vt(e.tile/2)+'" r="'+vt(e.dotRadius)+'" fill="'+sr(e.dotColor)+'"/></pattern></defs><rect x="'+vt(e.viewport.vx)+'" y="'+vt(e.viewport.vy)+'" width="'+vt(e.viewport.vw)+'" height="'+vt(e.viewport.vh)+'" fill="url(#'+t+')"/>',t1=t=>e=>'<path d="'+Ja(t)+'" fill="'+sr(e)+'" fill-opacity="'+vt(et(e.a)/255)+'"/>',GT=t=>e=>n=>r=>'<rect x="'+vt(t.x)+'" y="'+vt(t.y)+'" width="'+vt(t.w)+'" height="'+vt(t.h)+'" rx="'+vt(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+sr(n._1.color)+'" fill-opacity="'+vt(et(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';g()})()+(()=>{if(r.tag==="Just")return' stroke="'+sr(r._1.color)+'" stroke-opacity="'+vt(et(r._1.color.a)/255)+'" stroke-width="'+vt(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";g()})()+'"';if(r.tag==="Nothing")return"";g()})()+"/>",e1=t=>e=>'<path d="'+Ja(t)+'" fill="none" stroke="'+sr(e.color)+'" stroke-opacity="'+vt(et(e.color.a)/255)+'" stroke-width="'+vt(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";g()})()+'"/>',n1=t=>{const e=gg(Rr(t.content));return'<text x="'+vt(t.x)+'" y="'+vt(t.y)+'"'+(()=>{if(t.baseline==="BaselineTop")return' dy="0.8em"';if(t.baseline==="BaselineMiddle")return' dy="0.32em"';if(t.baseline==="BaselineAlphabetic"||t.baseline==="BaselineBottom")return"";g()})()+' fill="'+sr(t.color)+'" fill-opacity="'+vt(et(t.color.a)/255)+'" font-size="'+vt(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+ee(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";g()})()+'">'+(e.length===1&&e[0].style==="RunText"?Ta(e[0].text):vo("")(O(bT)(e)))+"</text>"},PT=t=>"matrix("+Cn(t.a)+" "+Cn(t.b)+" "+Cn(t.c)+" "+Cn(t.d)+" "+Cn(t.e)+" "+Cn(t.f)+")",r1={fillPath:t=>e=>n=>{const r=Ju(n)(t);return()=>{const i=r();return ke(t1(i)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=Ju(n)(t);return()=>{const i=r(),o=n.bake.value;return ke(e1(i)((()=>{if(o.tag==="Nothing")return e;if(o.tag==="Just")return{...e,width:o._1.sx*e.width};g()})()))(n)()}},fillStrokePath:t=>e=>n=>r=>{const i=Ju(r)(t);return()=>{const o=i(),u=r.bake.value;return ke(t1(o)(e.color)+e1(o)((()=>{if(u.tag==="Nothing")return n;if(u.tag==="Just")return{...n,width:u._1.sx*n.width};g()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>i=>{const o=i.bake;return()=>{const u=o.value;return ke(GT((()=>{if(u.tag==="Nothing")return t;if(u.tag==="Just")return{x:u._1.sx*t.x+u._1.tx,y:u._1.sy*t.y+u._1.ty,w:u._1.sx*t.w,h:u._1.sy*t.h};g()})())((()=>{if(u.tag==="Nothing")return e;if(u.tag==="Just")return u._1.sx*e;g()})())(n)(r.tag==="Just"?w("Just",(()=>{if(u.tag==="Nothing")return r._1;if(u.tag==="Just")return{...r._1,width:u._1.sx*r._1.width};g()})()):J))(i)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return ke(n1((()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return{...t,x:r._1.sx*t.x+r._1.tx,y:r._1.sy*t.y+r._1.ty,font:{...t.font,size:r._1.sx*t.font.size}};g()})()))(e)()}},drawTextAffine:t=>e=>ke((()=>{const n='transform="'+PT(t)+'"';return(n===""?"<g>":"<g "+n+">")+n1(e)+"</g>"})()),pushTransform:t=>ke((()=>{const e='transform="'+wT(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:ke("</g>"),pushBakedTransform:t=>e=>{const n=e.bake;return()=>{n.value=w("Just",t)}},popBakedTransform:t=>{const e=t.bake;return()=>{e.value=J}},pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const i=r.value;n.clipCounter.value=i+1|0;const o=Ju(n)(t)(),u="clip"+ee(i);return ke((()=>{const s='clip-path="url(#'+u+')"';return'<defs><clipPath id="'+u+'"><path d="'+Ja(o)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";g()})()+"/></clipPath></defs>"+(s===""?"<g>":"<g "+s+">")})())(n)()}},popClip:ke("</g>"),pushBlend:t=>ke((()=>{const e=(()=>{if(t==="Normal")return'style="mix-blend-mode: normal"';if(t==="Difference")return'style="mix-blend-mode: difference"';g()})();return e===""?"<g>":"<g "+e+">"})()),popBlend:ke("</g>"),pushAlpha:t=>ke((()=>{const e='opacity="'+vt(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:ke("</g>"),pushBlur:t=>e=>{if(t<.01)return ke("<g>")(e);const n=e.patternCounter;return()=>{const r=n.value;e.patternCounter.value=r+1|0;const i="lvl-blur-"+ee(r);return ke((()=>{const o='filter="url(#'+i+')"';return'<defs><filter id="'+i+'" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="'+vt(t)+'"/></filter></defs>'+(o===""?"<g>":"<g "+o+">")})())(e)()}},popBlur:ke("</g>"),pushLayer:t=>e=>{const n=(()=>{if(t==="LayerNodeMask"){const r=e.maskDepth;return()=>{const i=r.value;e.maskDepth.value=i+1|0}}return()=>{}})();return()=>{n(),e.out.push("<g>")}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;n>0&&(t.maskDepth.value=r),t.out.push("</g>")}},setViewport:t=>e=>()=>{},clearBackground:t=>e=>ke('<rect x="'+vt(e.viewport.vx)+'" y="'+vt(e.viewport.vy)+'" width="'+vt(e.viewport.vw)+'" height="'+vt(e.viewport.vh)+'" fill="'+sr(t)+'" opacity="'+vt(et(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,ke(ST("bg-dots-"+ee(r))(t))(e)()}},measureText:t=>e=>n=>{const r=zf(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Hf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Kf,Monad0:()=>CT},DT=K_(r1),IT=pa(r1),AT=t=>e=>n=>r=>i=>{const o={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:n,outputAspect:t},u=Nu(o)(i);return{viewBox:vt(u.vx)+" "+vt(u.vy)+" "+vt(u.vw)+" "+vt(u.vh),body:(()=>{const s=[],a={value:0},c={value:0},f={value:0},d={value:J};return DT(o)(e)(i)({out:s,maskDepth:a,clipCounter:c,patternCounter:f,viewport:u,bake:d})(),vo("")(s)})(),vx:u.vx,vy:u.vy,vw:u.vw,vh:u.vh}},FT=t=>e=>n=>r=>i=>o=>{const u={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;g()})(),outputAspect:t},s=Zs(i)((()=>{const a=[],c={value:0},f={value:0},d={value:0},l={value:J},_=r.levels.length-1|0;return _>=0&&_<r.levels.length?IT(r.levels[_].segment.layout)(r.levels[_].state)({out:a,maskDepth:c,clipCounter:f,patternCounter:d,viewport:Nu(u)(r),bake:l})():A})())(o);return{parts:AT(t)(s.applied)(e)(n)(r),springs:s.springs}},Ui=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(i=>n(i._1)(i._2)),Apply0:()=>i1(t)}),i1=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>i=>o=>e.map(u=>b(r(u._1),u._2))(i(o))};return{apply:(()=>{const r=Ui(t);return i=>o=>r.bind(i)(u=>r.bind(o)(s=>Ki(t).pure(u(s))))})(),Functor0:()=>n}},Ki=t=>({pure:e=>n=>t.Applicative0().pure(b(e,n)),Apply0:()=>i1(t)}),BT=t=>{const e={Applicative0:()=>Ki(t),Bind1:()=>Ui(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},wa=(t,e)=>({tag:t,_1:e}),va=t=>t,Wn=(t,e)=>({tag:t,_1:e}),xe=BT(qn),Mt=Ui(qn),Ae=xe.state(t=>b(t,t)),ne=Ki(qn),On=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},o1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Tu=Du(ne)(zt),Yn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},QT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},RT=(()=>{const t=Ue.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return w("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,$t("Cons",r._3,n(r._6,i)));g()};return n(e,Xt)})())})(),MT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},wu=t=>e=>n=>T(r=>i=>t.Bind1().bind(r)(o=>e(o)(i)))(t.Applicative0().pure(n)),zT=T(t=>e=>tt(S)(e)()(t))(A),HT=(()=>{const t=(e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=tt(S)(a._1)()(s),i=a._2;continue}g()}return u})(A);return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,$t("Cons",r._3,n(r._6,i)));g()};return n(e,Xt)})())})(),WT=Wn("Exit"),OT=va("AnimatedKeyframe"),YT=va("Still"),$T=va("Title"),qT=t=>wa("Par",t),u1=t=>wa("Seq",t),XT=t=>e=>n=>{const r=gr(Ut,J,i=>i._1===t,n);if(r.tag==="Just"){const i=Xn(Ut,J,r._1,b(t,e),n);if(i.tag==="Nothing")return n;if(i.tag==="Just")return i._1;g()}if(r.tag==="Nothing")return Rt(n)(b(t,e));g()},VT=t=>e=>O(n=>n._1===t?b(n._1,{...n._2,label:w("Just",e)}):b(n._1,n._2)),Ne=t=>xe.state(e=>b(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:w("Just",{msg:t,line:e.currentLine,column:e.currentColumn})};g()})())),UT=t=>Mt.bind(xe.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>Mt.bind(Ae)(e=>{if(e.error.tag==="Just")return ne.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!On(t.op._1.id)(e.currNodes))return Ne("cannot enter node "+t.op._1.id+": does not exist");if(!o1(t.op._1.id)(e.interiorOf))return Ne("cannot enter node "+t.op._1.id+": it has no `inside` block");if(Ye(dn)(t.op._1.id)(e.enterStack))return Ne("cannot enter node "+t.op._1.id+": already entered");const n=t.op._1;return xe.state(r=>b(void 0,{...r,enterStack:Rt(r.enterStack)(n.id),scenes:Rt(r.scenes)(mi("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=fr(e.enterStack);if(n.tag==="Nothing")return Ne("`exit` without a matching `enter`");if(n.tag==="Just"){const r=n._1.init;return xe.state(i=>b(void 0,{...i,enterStack:r,scenes:Rt(i.scenes)(Ml)}))}g()}return ne.pure()}g()})),KT=t=>Mt.bind(Ae)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ee(e.kfCounter);if(Oe(i=>i.id===n,e.keyframes))return Ne("duplicate frame name "+n);const r={...e,keyframes:Rt(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges,kind:yi}),kfCounter:e.kfCounter+1|0,currentKf:w("Just",n)};return xe.state(i=>b(void 0,r))}),ZT=Tu(t=>Mt.bind(Ae)(e=>{if(e.error.tag==="Just")return ne.pure();if(e.error.tag==="Nothing")return o1(t.node)(e.interiorOf)?Ne("node "+t.node+" has more than one `inside` block"):xe.state(n=>b(void 0,{...n,interiorOf:tt(S)(t.node)(t.doc)(n.interiorOf)}));g()})),jT=t=>e=>{const n=e.from+"->"+e.to,r=e.newFrom+"->"+e.newTo,i=Dt("Left","cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist"),o=Yn(n)(t.currEdges)?Dt("Right",void 0):i;return(()=>{if(o.tag==="Left"){const u=o._1;return s=>Dt("Left",u)}if(o.tag==="Right"){const u=o._1;return s=>s(u)}g()})()(()=>{const u="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newFrom;if(!On(e.newFrom)(t.currNodes))return Dt("Left",u);const s="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo;if(!On(e.newTo)(t.currNodes))return Dt("Left",s);const a="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists";return n!==r&&Yn(r)(t.currEdges)?Dt("Left",a):Dt("Right",{nextCurrEdges:tt(S)(r)()(si(S)(n)(t.currEdges)),newId:r,newEdge:{id:r,from:{node:e.newFrom,port:J},to:{node:e.newTo,port:J},label:J}})})},s1={graphNodes:[],graphEdges:A,currNodes:A,currEdges:A,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:J,currentLine:0,currentColumn:0,error:J,enterStack:[],interiorOf:A},tw=Mt.bind(Ae)(t=>{if(t.error.tag==="Just")return ne.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return xe.state(n=>b(void 0,{...n,scenes:Rt(n.scenes)(mi("Hold",e))}))}if(t.currentKf.tag==="Nothing")return ne.pure()}g()}),a1=t=>e=>Mt.bind(Ae)(n=>{const r="ev-"+ee(n.eventCounter);return Mt.bind((()=>{const i={...n,eventCounter:n.eventCounter+1|0};return xe.state(o=>b(void 0,i))})())(()=>ne.pure({events:[{id:r,kind:e,when:t}],firstId:w("Just",r),lastId:w("Just",r)}))}),ew=t=>e=>{if(e.tag==="Token"){const n=e._1;return Mt.bind(Ae)(r=>{const i=!On(n.from)(r.currNodes),o=!On(n.to)(r.currNodes);if(i||o)return Mt.bind(Ne(i?o?"token references unknown node: "+n.from+", "+n.to:"token references unknown node: "+n.from:o?"token references unknown node: "+n.to:"token references unknown node: "))(()=>ne.pure({events:[],firstId:J,lastId:J}));const u=n.to+"->"+n.from,s=n.from+"->"+n.to;return Yn(s)(r.currEdges)?a1(t)(bc("SendToken",{from:n.from,to:n.to,edge:s,direction:Ql,labels:n.labels})):Yn(u)(r.currEdges)?a1(t)(bc("SendToken",{from:n.from,to:n.to,edge:u,direction:Rl,labels:n.labels})):Mt.bind(Ne("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>ne.pure({events:[],firstId:J,lastId:J}))})}return ne.pure({events:[],firstId:J,lastId:J})},nw=t=>e=>{if(0<t.length){const n=t[0];return Mt.bind(xe.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>Ne(e))}return Ne(e)},rw=t=>xt(e=>QT(e)(t.graphEdges))(Ct(ii,RT(t.currEdges))),iw=t=>e=>{const n=at(i=>i.from.node===e.id||i.to.node===e.id,rw(t)),r=wu(Oa)(i=>o=>{const u=o.from+"->"+e.id,s=e.id+"->"+o.to,a=o.from+"->"+o.to,c="via "+o.from+" "+o.to+": no edge "+o.from+"\u2192"+e.id;if(!Yn(u)(t.currEdges))return Dt("Left",c);const f="via "+o.from+" "+o.to+": no edge "+e.id+"\u2192"+o.to;if(!Yn(s)(t.currEdges))return Dt("Left",f);const d="via "+o.from+" "+o.to+": would create "+o.from+"\u2192"+o.to+" but it already exists";return Yn(a)(t.currEdges)||MT(a)(i.synthesized)?Dt("Left",d):Dt("Right",{consumed:tt(S)(u)()(tt(S)(s)()(i.consumed)),synthesized:tt(S)(a)({id:a,from:{node:o.from,port:J},to:{node:o.to,port:J},label:J})(i.synthesized)})})({consumed:A,synthesized:A})(e.via);return(()=>{if(r.tag==="Left"){const i=r._1;return o=>Dt("Left",i)}if(r.tag==="Right"){const i=r._1;return o=>o(i)}g()})()(i=>{const o=i.consumed,u=at(s=>!Yn(s.id)(o),n);return u.length===0?Dt("Right",{nextCurrEdges:Se(S.compare,Ee,In(S.compare,t.currEdges,zT(O(s=>s.id)(n))),HT((()=>{const s=a=>{if(a.tag==="Leaf")return A;if(a.tag==="Node")return Yt("Node",a._1,a._2,a._3,void 0,s(a._5),s(a._6));g()};return s(i.synthesized)})())),synthesized:i.synthesized}):Dt("Left","cannot delete node "+e.id+": still connected ("+vo(", ")(O(s=>s.from.node+"\u2192"+s.to.node)(u))+"). Use -edge to drop them or `via a b` to merge "+e.id+"'s endpoints.")})},ba=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq")return wt(t._1)(ba);g()},ow=Mt.bind(Ae)(t=>{if(t.error.tag==="Just")return ne.pure();if(t.error.tag==="Nothing"){const e=t.enterStack.length-1|0;return e>=0&&e<t.enterStack.length?Ne("entered node "+t.enterStack[e]+" was never exited"):ne.pure()}g()}),uw=t=>({nodes:O(no)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,$t("Cons",n._4,e(n._6,r)));g()};return Ct(Vt.foldr,e(t.graphEdges,Xt))})(),constraints:[]}),sw=t=>{if(t.tag==="AddNode"){const e=t._1;return xe.state(n=>b(void 0,{...n,graphNodes:XT(e.id)({id:e.id,size:b(1,1),ports:[],label:w("Just",e.label),shape:e.shape})(n.graphNodes),currNodes:tt(S)(e.id)()(n.currNodes)}))}if(t.tag==="DelNode"){const e=t._1;return Mt.bind(Ae)(n=>{if(!On(e.id)(n.currNodes))return Ne("cannot delete node "+e.id+": does not exist");const r=iw(n)(e);if(r.tag==="Left")return Ne(r._1);if(r.tag==="Right"){const i=r._1;return xe.state(o=>b(void 0,{...o,currNodes:si(S)(e.id)(o.currNodes),currEdges:i.nextCurrEdges,graphEdges:Se(S.compare,Ee,i.synthesized,o.graphEdges)}))}g()})}if(t.tag==="ModNode"){const e=t._1;return Mt.bind(Ae)(n=>{if(!On(e.id)(n.currNodes))return Ne("cannot modify node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=e.label._1;return xe.state(i=>b(void 0,{...i,graphNodes:VT(e.id)(r)(i.graphNodes)}))}if(e.label.tag==="Nothing")return ne.pure();g()})}if(t.tag==="AddEdge"){const e=t._1;return Mt.bind(Ae)(n=>{const r=!On(e.from)(n.currNodes),i=!On(e.to)(n.currNodes);if(r||i)return Ne("cannot add edge "+e.from+"\u2192"+e.to+": unknown node "+(r?i?e.from+", "+e.to:e.from:i?e.to:""));const o=e.from+"->"+e.to;return xe.state(u=>b(void 0,{...u,graphEdges:tt(S)(o)({id:o,from:{node:e.from,port:J},to:{node:e.to,port:J},label:e.label})(u.graphEdges),currEdges:tt(S)(o)()(u.currEdges)}))})}if(t.tag==="DelEdge"){const e=t._1;return Mt.bind(Ae)(n=>{const r=e.from+"->"+e.to;return Yn(r)(n.currEdges)?xe.state(i=>b(void 0,{...i,currEdges:si(S)(r)(i.currEdges)})):Ne("cannot delete edge "+e.from+"\u2192"+e.to+": does not exist")})}if(t.tag==="RepointEdge"){const e=t._1;return Mt.bind(Ae)(n=>{const r=jT(n)(e);if(r.tag==="Left")return Ne(r._1);if(r.tag==="Right"){const i=r._1;return xe.state(o=>b(void 0,{...o,currEdges:i.nextCurrEdges,graphEdges:tt(S)(i.newId)(i.newEdge)(o.graphEdges)}))}g()})}return ne.pure()},aw=t=>Mt.bind(xe.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>sw(t.op)),c1=t=>e=>n=>Mt.bind(Tu(aw)(n))(()=>Mt.bind(Ae)(r=>{const i=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ee(r.kfCounter);if(Oe(u=>u.id===i,r.keyframes))return Ne("duplicate frame name "+i);const o={...r,keyframes:Rt(r.keyframes)({id:i,nodes:r.currNodes,edges:r.currEdges,kind:t}),kfCounter:r.kfCounter+1|0,currentKf:w("Just",i),scenes:(()=>{if(r.currentKf.tag==="Nothing")return r.scenes;if(r.currentKf.tag==="Just")return Rt(r.scenes)(mi("Structural",{from:r.currentKf._1,to:i,focus:J}));g()})()};return xe.state(u=>b(void 0,o))})),g1=t=>e=>{const n=ba(e.ops),r=at(o=>o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge",n),i=at(o=>!(o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge"),n);if(0<i.length){const o=i[0];return Mt.bind(xe.state(u=>b(void 0,{...u,currentLine:o.line,currentColumn:o.column})))(()=>Ne("still/title blocks hold a static snapshot; they cannot contain tokens (a -> b) or enter/exit"))}return t==="TitleCard"&&r.length===0?Ne(e.name.tag==="Just"&&e.name._1!==""?'title "'+e.name._1+'" has an empty body; give it nodes/edges to title, or use a still':"title has an empty body; give it nodes/edges to title, or use a still"):Mt.bind(c1(t)(e.name)(r))(()=>tw)},cw=t=>e=>{const n=Qt(r=>J,r=>i=>w("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return ne.pure({events:[],firstId:J,lastId:J});if(n.tag==="Just"){const r=n._1.tail;return Mt.bind(Zi(t)(n._1.head))(i=>Mt.bind(wu({Applicative0:()=>Ki(qn),Bind1:()=>Ui(qn)})(o=>u=>Mt.bind(Zi((()=>{if(o.lastId.tag==="Just")return os("After",o.lastId._1);if(o.lastId.tag==="Nothing")return t;g()})())(u))(s=>ne.pure({events:[...o.events,...s.events],firstId:(()=>{if(o.firstId.tag==="Just")return w("Just",o.firstId._1);if(o.firstId.tag==="Nothing")return s.firstId;g()})(),lastId:(()=>{if(s.lastId.tag==="Just")return w("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return o.lastId;g()})()})))(i)(r))(o=>ne.pure(o)))}g()},gw=t=>e=>{const n=Qt(r=>J,r=>i=>w("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return ne.pure({events:[],firstId:J,lastId:J});if(n.tag==="Just"){const r=n._1.tail;return Mt.bind(Zi(t)(n._1.head))(i=>Mt.bind(fw((()=>{if(i.firstId.tag==="Just")return os("With",i.firstId._1);if(i.firstId.tag==="Nothing")return t;g()})())(r))(o=>ne.pure({events:[...i.events,...o.events],firstId:i.firstId,lastId:(()=>{if(i.lastId.tag==="Just")return w("Just",i.lastId._1);if(i.lastId.tag==="Nothing")return o.lastId;g()})()})))}g()},Zi=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return Mt.bind(xe.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>ew(t)(n.op))}if(e.tag==="Seq")return cw(t)(e._1);if(e.tag==="Par")return gw(t)(e._1);g()},fw=t=>wu({Applicative0:()=>Ki(qn),Bind1:()=>Ui(qn)})(e=>n=>Mt.bind(Zi(t)(n))(r=>ne.pure({events:[...e.events,...r.events],firstId:(()=>{if(e.firstId.tag==="Just")return w("Just",e.firstId._1);if(e.firstId.tag==="Nothing")return r.firstId;g()})(),lastId:(()=>{if(r.lastId.tag==="Just")return w("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;g()})()})))({events:[],firstId:J,lastId:J}),_w=t=>Mt.bind(Ae)(e=>{if(e.currentKf.tag==="Nothing")return Ne("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return Mt.bind(Zi(Bl)(t))(r=>Mt.bind(Ae)(i=>{const o={...i,scenes:Rt(i.scenes)(mi("DataFlow",{keyframe:n,events:r.events,focus:J}))};return xe.state(u=>b(void 0,o))}))}g()}),dw=t=>{const e=ba(t.ops),n=at(o=>o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge",e),r=at(o=>o.op.tag==="Enter"||o.op.tag==="Exit",e),i=at(o=>!(o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge")&&!(o.op.tag==="Enter"||o.op.tag==="Exit"),e);return r.length!==0&&i.length!==0?nw(r)("`enter`/`exit` cannot be mixed with flow tokens in the same frame"):Mt.bind((()=>{const o=c1(yi)(t.name)(n);return n.length!==0?o:ne.pure()})())(()=>Mt.bind((()=>{const o=KT(t.name);return n.length===0&&i.length!==0?o:ne.pure()})())(()=>Mt.bind((()=>{const o=_w(t.ops);return i.length!==0?o:ne.pure()})())(()=>Tu(UT)(r))))},lw=t=>Mt.bind(Ae)(e=>{if(e.error.tag==="Just")return ne.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return dw(t);if(t.kind==="Still")return g1(Al)(t);if(t.kind==="Title")return g1(Fl)(t)}g()}),f1=t=>Mt.bind(ZT(t.interiors))(()=>Mt.bind(Tu(lw)(t.frames))(()=>Mt.bind(ow)(()=>Mt.bind(Ae)(e=>{if(e.error.tag==="Just")return ne.pure(Dt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=hw(t.interiors);if(n.tag==="Left")return ne.pure(Dt("Left",n._1));if(n.tag==="Right")return ne.pure(Dt("Right",{seed:t.seed,graph:uw(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1}))}g()})))),hw=t=>{const e=wu(Oa)(n=>r=>{const i=f1(r.doc)(s1)._1;return(()=>{if(i.tag==="Left"){const o=i._1;return u=>Dt("Left",o)}if(i.tag==="Right"){const o=i._1;return u=>u(o)}g()})()(o=>Dt("Right",tt(S)(r.node)(o)(n)))})(A)(t);if(e.tag==="Left")return Dt("Left",e._1);if(e.tag==="Right")return Dt("Right",e._1);g()},ti=(t,e)=>({tag:"ParseError",_1:t,_2:e}),Q=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),vu=(t,e,n)=>({tag:t,_1:e,_2:n}),pw=t=>vu("More",t),mw=t=>vu("Lift",t),yw={defer:t=>{const e=dl(t);return(n,r,i,o,u)=>ll(e)(n,r,i,o,u)}},_1={map:t=>e=>(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,c)=>r(f=>u(a,t(c)))))},xw={alt:t=>e=>(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>t(Q(s,a,!1),r,i,(f,d)=>{const l=f._3;return r(_=>l?o(f,d):e(n,r,i,o,u))},u))},Functor0:()=>_1},Nw=t=>{const e=t.Monad0();return n=>r=>{const i=o=>{let u=o,s=!0,a;for(;s;){const c=u();if(c.tag==="More"){u=c._1;continue}if(c.tag==="Lift"){s=!1,a=e.Bind1().Apply0().Functor0().map($a)(c._1);continue}if(c.tag==="Stop"){s=!1,a=e.Applicative0().pure(ri("Done",b(c._2,c._1)));continue}g()}return a};return t.tailRecM(i)(o=>r(n,pw,mw,(u,s)=>vu("Stop",u,Dt("Left",s)),(u,s)=>vu("Stop",u,Dt("Right",s))))}},d1=(t,e,n,r,i)=>i(t,t._2),Jw={index:0,line:1,column:1},Tw=(t=>{const e=Nw(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(ro)(e(Q(n,Jw,!1))(r))})(H1),l1={apply:t=>e=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,c)=>r(f=>{const d=n._3&&!a._3?Q(a._1,a._2,!0):a;return e(d,r,i,o,(l,_)=>r(h=>u(d._3&&!l._3?Q(l._1,l._2,!0):l,c(_))))}))),Functor0:()=>_1},h1={pure:t=>(e,n,r,i,o)=>o(e,t),Apply0:()=>l1},ww={bind:t=>e=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,c)=>r(f=>e(c)(n._3&&!a._3?Q(a._1,a._2,!0):a,r,i,o,u)))),Apply0:()=>l1},vw={Applicative0:()=>h1,Bind1:()=>ww},bu=t=>(e,n,r,i,o)=>n(u=>d1(e,n,r,i,(s,a)=>n(c=>i(e._3&&!s._3?Q(s._1,s._2,!0):s,ti(t,a))))),bw={empty:bu("No alternative"),Alt0:()=>xw},kw={Applicative0:()=>h1,Plus1:()=>bw},sn=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return i=>t.tailRecM(o=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map($a)(i))(r.pure(ri("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return ri("Loop",$t("Cons",u._1,o));if(u.tag==="Done")return ri("Done",(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=$t("Cons",h._1,_),f=h._2;continue}g()}return l})(Xt)(o));g()})())))(Xt)})({tailRecM:t=>e=>(n,r,i,o,u)=>{const s=(a,c,f)=>t(c)(a,r,i,o,(d,l)=>{const _=a._3&&!d._3?Q(d._1,d._2,!0):d;if(l.tag==="Loop")return f===0?r(h=>s(_,l._1,30)):s(_,l._1,f-1|0);if(l.tag==="Done")return u(_,l._1);g()});return s(n,e,30)},Monad0:()=>vw})(kw),Gt=t=>e=>{const n=bu("Expected "+e);return(r,i,o,u,s)=>{const a=r._1,c=r._2;return i(f=>t(Q(a,c,!1),i,o,(d,l)=>{const _=d._3;return i(h=>_?u(d,l):n(r,i,o,u,s))},s))}},ka=t=>(e,n,r,i,o)=>{const u=e._3,s=e._1,a=e._2;return n(c=>{const f=(d,l)=>{const _=d._3;return n(h=>_?i(Q(d._1,d._2,u),l):o(e,void 0))};return n(d=>n(l=>t(Q(s,a,!1),n,r,(_,h)=>f(Q(_._1,_._2,!1),h),(_,h)=>n(p=>n(m=>bu("Negated parser succeeded")(_,n,r,f,(y,x)=>n(N=>o(_._3&&!y._3?Q(y._1,y._2,!0):y,x))))))))})},Lw=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return w("Just",n);if(r.tag==="Just")return w("Just",(i,o,u,s,a)=>{const c=i._1,f=i._2;return o(d=>n(Q(c,f,!1),o,u,(l,_)=>{const h=l._3;return o(p=>h?s(l,_):r._1(i,o,u,s,a))},a))});g()})(J);return n=>{const r=e(n);if(r.tag==="Nothing")return bu("No alternative");if(r.tag==="Just")return r._1;g()}},Ew=t=>e=>n=>(r,i,o,u,s)=>i(a=>i(c=>i(f=>i(d=>t(r,i,o,u,(l,_)=>i(h=>i(p=>{const m=r._3&&!l._3?Q(l._1,l._2,!0):l;return n(m,i,o,u,(y,x)=>i(N=>{const v=m._3&&!y._3?Q(y._1,y._2,!0):y;return i(k=>i(L=>{const E=r._3&&!v._3?Q(v._1,v._2,!0):v;return e(E,i,o,u,(B,q)=>i(j=>s(E._3&&!B._3?Q(B._1,B._2,!0):B,x)))}))}))}))))))),La=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=Eh()(n);return r.tag==="Just"&&r._1===10?{index:t.index+1|0,line:t.line,column:t.column}:{index:t.index+1|0,line:t.line+1|0,column:1}}return e===9?{index:t.index+1|0,line:t.line,column:(t.column+8|0)-Un(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},Cw=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,c=i,f=o,d=bo(c);if(d.tag==="Nothing"){u=!1,s=a;continue}if(d.tag==="Just"){r=d._1.tail===""?La(a)(d._1.head)(f):La(a)(d._1.head)(d._1.tail),i=d._1.tail,o=f;continue}g()}return s},jt=t=>(e,n,r,i,o)=>{const u=bo(e._1);if(u.tag==="Nothing")return i(e,ti("Unexpected EOF",e._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return i(e,ti("Expected Char",e._2));if(u._1.head>=0&&u._1.head<=65535){const s=Fc(u._1.head);return t(s)?o(Q(u._1.tail,La(e._2)(u._1.head)(u._1.tail),!0),s):i(e,ti("Predicate unsatisfied",e._2))}}g()},Ea=(t,e,n,r,i)=>t._1===""?i(Q(t._1,t._2,!0),void 0):r(t,ti("Expected EOF",t._2)),Sw=t=>(e,n,r,i,o)=>{const u=t(e._1);if(u.tag==="Left")return i(e,ti(u._1,e._2));if(u.tag==="Right")return o(Q(u._1.remainder,Cw(e._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);g()},ei=t=>Sw(e=>{const n=_l(t)(e);return n.tag==="Just"?Dt("Right",{value:t,consumed:t,remainder:n._1}):Dt("Left","Expected "+S1(t))}),Gw=jt(t=>!0),p1=(t,e)=>({tag:t,_1:e}),Pw=te(S)(zt),Dw=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=S.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},m1=Lw(zt),y1=(()=>{const t=jt(e=>e===" "||e===" "||e===`
9
+ `||e==="\r");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?Q(s._1,s._2,!0):s,void 0))))})(),Ca=(t,e,n,r,i)=>e(o=>ei("#")(t,e,n,r,(u,s)=>e(a=>{const c=sn(jt(d=>d!==`
10
+ `)),f=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>i(f._3&&!l._3?Q(l._1,l._2,!0):l,void 0))))}))),Iw=Gt((()=>{const t=Gt(jt(n=>n==="}"))("'}'"),e=jt(n=>n===`
11
+ `||n==="\r");return(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>r(f=>t(Q(s,a,!1),r,i,(d,l)=>r(_=>{const h=n._1,p=n._2;return r(m=>r(y=>Ca(Q(h,p,!1),r,i,(x,N)=>{const v=x._3;return r(k=>{if(v)return o(x,N);const L=n._1,E=n._2;return r(B=>r(q=>e(Q(L,E,!1),r,i,(j,G)=>{const P=j._3;return r(V=>P?o(j,G):Ea(n,r,i,o,u))},(j,G)=>r(P=>u(j,void 0)))))})},(x,N)=>r(v=>u(x,void 0)))))}),(d,l)=>r(_=>u(Q(s,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),en=(()=>{const t=sn((e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>y1(Q(u,s,!1),n,r,(c,f)=>{const d=c._3;return n(l=>d?i(c,f):Ca(e,n,r,i,o))},o))});return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?Q(s._1,s._2,!0):s,void 0))))})(),fn=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>en(t._3&&!c._3?Q(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>y1(Q(s,a,!1),e,n,(f,d)=>{const l=f._3;return e(_=>l?r(f,d):Ca(t,e,n,r,u))},u))}),x1=(()=>{const t=Gt(jt(e=>e==="|"))("'|'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=sn(jt(l=>l!=="|")),d=e._3&&!s._3?Q(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(p=>{const m=Gt(Gt(jt(x=>x==="|"))("'|'"))("closing '|'"),y=d._3&&!_._3?Q(_._1,_._2,!0):_;return n(x=>m(y,n,r,i,(N,v)=>n(k=>o(y._3&&!N._3?Q(N._1,N._2,!0):N,lr(Ct(Vt.foldr,h))))))})))})))})(),ku=jt(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),He=(()=>{const t=sn(jt(e=>e===" "||e===" "));return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?Q(s._1,s._2,!0):s,void 0))))})(),Aw=(()=>{const t=Gt(jt(e=>e==="\\"))("'\\\\'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=e._3&&!s._3?Q(s._1,s._2,!0):s;return n(d=>Gw(f,n,r,i,(l,_)=>n(h=>o(f._3&&!l._3?Q(l._1,l._2,!0):l,_==="n"?`
12
+ `:_==="t"?" ":_==="r"?"\r":_))))})))})(),Fw=(()=>{const t=jt(e=>e!=='"'&&e!=="\\"&&e!==`
13
+ `);return(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>Aw(Q(u,s,!1),n,r,(c,f)=>n(d=>t(e,n,r,i,o)),o))}})(),Sa=(()=>{const t=Gt(jt(e=>e==='"'))(`'"'`);return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=sn(Fw),d=e._3&&!s._3?Q(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(p=>{const m=Gt(Gt(jt(x=>x==='"'))(`'"'`))(`closing '"' (unterminated string)`),y=d._3&&!_._3?Q(_._1,_._2,!0):_;return n(x=>m(y,n,r,i,(N,v)=>n(k=>o(y._3&&!N._3?Q(N._1,N._2,!0):N,lr(Ct(Vt.foldr,h))))))})))})))})(),Bw=(()=>{const t=Gt(jt(e=>e===":"))("':'");return(e,n,r,i,o)=>n(u=>He(e,n,r,i,(s,a)=>n(c=>Gt((f,d,l,_,h)=>{const p=f._1,m=f._2;return d(y=>{const x=(N,v)=>{const k=N._3;return d(L=>{if(k)return _(N,v);const E=f._1,B=f._2;return d(q=>x1(Q(E,B,!1),d,l,(j,G)=>{const P=j._3;return d(V=>P?_(j,G):Sa(f,d,l,_,h))},h))})};return d(N=>t(Q(p,m,!1),d,l,x,(v,k)=>d(L=>d(E=>He(v,d,l,x,(B,q)=>d(j=>{const G=sn(jt(V=>V!==`
14
+ `&&V!=="\r"&&V!=="#"&&V!=="}")),P=v._3&&!B._3?Q(B._1,B._2,!0):B;return d(V=>G(P,d,l,x,(U,M)=>d(H=>h(P._3&&!U._3?Q(U._1,U._2,!0):U,ph(lr(Ct(Vt.foldr,M)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(e._3&&!s._3?Q(s._1,s._2,!0):s,n,r,i,o))))})(),N1=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>x1(Q(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):Sa(t,e,n,r,i))},i))},ji=jt(t=>t>="0"&&t<="9"),Le=(()=>{const t=Gt(jt(e=>e==="_"))("'_'");return(e,n,r,i,o)=>n(u=>{const s=(f,d)=>n(l=>{const _=sn((()=>{const p=Gt(jt(y=>y==="_"))("'_'"),m=Gt(jt(y=>y==="-"))("'-'");return(y,x,N,v,k)=>{const L=y._1,E=y._2;return x(B=>ku(Q(L,E,!1),x,N,(q,j)=>{const G=q._3;return x(P=>{if(G)return v(q,j);const V=y._1,U=y._2;return x(M=>ji(Q(V,U,!1),x,N,(H,R)=>{const C=H._3;return x(D=>{if(C)return v(H,R);const F=y._1,I=y._2;return x(z=>p(Q(F,I,!1),x,N,($,X)=>{const Y=$._3;return x(W=>Y?v($,X):m(y,x,N,v,k))},k))})},k))})},k))}})()),h=e._3&&!f._3?Q(f._1,f._2,!0):f;return n(p=>_(h,n,r,i,(m,y)=>n(x=>o(h._3&&!m._3?Q(m._1,m._2,!0):m,_o(d)+lr(Ct(Vt.foldr,y))))))}),a=e._1,c=e._2;return n(f=>ku(Q(a,c,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?i(d,l):t(e,n,r,i,s))},s))})})(),Qw=Gt((t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>Sa(Q(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):Le(t,e,n,r,i))},i))})("frame name (identifier or quoted string)"),J1=(t,e,n,r,i)=>e(o=>He(t,e,n,r,(u,s)=>e(a=>{const c=Gt(Le)("attribute key"),f=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=f._3&&!l._3?Q(l._1,l._2,!0):l;return e(m=>He(p,e,n,r,(y,x)=>e(N=>{const v=Gt(Gt(jt(L=>L===":"))("':'"))("':'"),k=p._3&&!y._3?Q(y._1,y._2,!0):y;return e(L=>v(k,e,n,r,(E,B)=>e(q=>{const j=k._3&&!E._3?Q(E._1,E._2,!0):E;return e(G=>He(j,e,n,r,(P,V)=>e(U=>{const M=Gt(Le)("attribute value"),H=j._3&&!P._3?Q(P._1,P._2,!0):P;return e(R=>M(H,e,n,r,(C,D)=>e(F=>{const I=H._3&&!C._3?Q(C._1,C._2,!0):C;return e(z=>He(I,e,n,r,($,X)=>e(Y=>i(I._3&&!$._3?Q($._1,$._2,!0):$,b(_,D)))))})))})))})))})))})))}))),Rw=(t,e,n,r,i)=>e(o=>Le(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(f=>He(c,e,n,r,(d,l)=>e(_=>{const h=Gt((m,y,x,N,v)=>{const k=m._1,L=m._2;return y(E=>ei("->")(Q(k,L,!1),y,x,(B,q)=>{const j=B._3;return y(G=>j?N(B,q):ei("<-")(m,y,x,N,v))},v))})("'->' or '<-'"),p=c._3&&!d._3?Q(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const v=p._3&&!y._3?Q(y._1,y._2,!0):y;return e(k=>He(v,e,n,r,(L,E)=>e(B=>{const q=Gt(Le)("target node identifier"),j=v._3&&!L._3?Q(L._1,L._2,!0):L;return e(G=>q(j,e,n,r,(P,V)=>e(U=>{const M=sn((R,C,D,F,I)=>{const z=R._3;return C($=>C(X=>He(R,C,D,(Y,W)=>F(Q(Y._1,Y._2,z),W),(Y,W)=>C(K=>C(Z=>{const ct=R._3&&!Y._3?Q(Y._1,Y._2,!0):Y;return N1(ct,C,D,(_t,gt)=>F(Q(_t._1,_t._2,z),gt),(_t,gt)=>C(yt=>I(ct._3&&!_t._3?Q(_t._1,_t._2,!0):_t,gt)))})))))}),H=j._3&&!P._3?Q(P._1,P._2,!0):P;return e(R=>M(H,e,n,r,(C,D)=>e(F=>(()=>{if(x==="<-"){const z=Wn("Token",{from:V,to:s,labels:O(Nc)(Ct(Vt.foldr,D))});return($,X,Y,W,K)=>K($,z)}const I=Wn("Token",{from:s,to:V,labels:O(Nc)(Ct(Vt.foldr,D))});return(z,$,X,Y,W)=>W(z,I)})()(H._3&&!C._3?Q(C._1,C._2,!0):C,e,n,r,i))))})))})))})))})))}))),Mw=(t,e,n,r,i)=>e(o=>ji(t,e,n,r,(u,s)=>e(a=>{const c=sn(ji),f=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=yd(_o(s)+lr(Ct(Vt.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(y,x,N,v,k)=>k(y,m)}if(p.tag==="Nothing")return(m,y,x,N,v)=>v(m,0);g()})()(f._3&&!l._3?Q(l._1,l._2,!0):l,e,n,r,i)})))}))),to=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>ei(t)(e,n,r,(a,c)=>i(Q(a._1,a._2,u),c),(a,c)=>n(f=>{const d=ka((()=>{const _=Gt(jt(p=>p==="_"))("'_'"),h=Gt(jt(p=>p==="-"))("'-'");return(p,m,y,x,N)=>{const v=p._1,k=p._2;return m(L=>ku(Q(v,k,!1),m,y,(E,B)=>{const q=E._3;return m(j=>{if(q)return x(E,B);const G=p._1,P=p._2;return m(V=>ji(Q(G,P,!1),m,y,(U,M)=>{const H=U._3;return m(R=>{if(H)return x(U,M);const C=p._1,D=p._2;return m(F=>_(Q(C,D,!1),m,y,(I,z)=>{const $=I._3;return m(X=>$?x(I,z):h(p,m,y,x,N))},N))})},N))})},N))}})()),l=e._3&&!a._3?Q(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(Q(h._1,h._2,u),p),(h,p)=>n(m=>{const y=l._3&&!h._3?Q(h._1,h._2,!0):h;return n(x=>en(y,n,r,(N,v)=>i(Q(N._1,N._2,u),v),(N,v)=>n(k=>o(y._3&&!N._3?Q(N._1,N._2,!0):N,t))))})))})))},zw=(t,e,n,r,i)=>e(o=>fn(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(f=>to("via")(c,e,n,r,(d,l)=>e(_=>{const h=c._3&&!d._3?Q(d._1,d._2,!0):d;return e(p=>Le(h,e,n,r,(m,y)=>e(x=>{const N=h._3&&!m._3?Q(m._1,m._2,!0):m;return e(v=>fn(N,e,n,r,(k,L)=>e(E=>{const B=N._3&&!k._3?Q(k._1,k._2,!0):k;return e(q=>Le(B,e,n,r,(j,G)=>e(P=>i(B._3&&!j._3?Q(j._1,j._2,!0):j,{from:y,to:G}))))})))})))})))}))),ar=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>ei(t)(e,n,r,(a,c)=>i(Q(a._1,a._2,u),c),(a,c)=>n(f=>{const d=ka((()=>{const _=Gt(jt(p=>p==="_"))("'_'"),h=Gt(jt(p=>p==="-"))("'-'");return(p,m,y,x,N)=>{const v=p._1,k=p._2;return m(L=>ku(Q(v,k,!1),m,y,(E,B)=>{const q=E._3;return m(j=>{if(q)return x(E,B);const G=p._1,P=p._2;return m(V=>ji(Q(G,P,!1),m,y,(U,M)=>{const H=U._3;return m(R=>{if(H)return x(U,M);const C=p._1,D=p._2;return m(F=>_(Q(C,D,!1),m,y,(I,z)=>{const $=I._3;return m(X=>$?x(I,z):h(p,m,y,x,N))},N))})},N))})},N))}})()),l=e._3&&!a._3?Q(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(Q(h._1,h._2,u),p),(h,p)=>n(m=>o(l._3&&!h._3?Q(h._1,h._2,!0):h,void 0))))})))},Hw=(t,e,n,r,i)=>e(o=>ar("+edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(Le)("source node identifier"),p=c._3&&!d._3?Q(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const v=p._3&&!y._3?Q(y._1,y._2,!0):y;return e(k=>fn(v,e,n,r,(L,E)=>e(B=>{const q=Gt(Le)("target node identifier"),j=v._3&&!L._3?Q(L._1,L._2,!0):L;return e(G=>q(j,e,n,r,(P,V)=>e(U=>{const M=j._3&&!P._3?Q(P._1,P._2,!0):P;return e(H=>{const R=(F,I)=>e(z=>i(M._3&&!F._3?Q(F._1,F._2,!0):F,Wn("AddEdge",{from:x,to:V,label:I.tag==="Just"?w("Just",I._1):J}))),C=M._1,D=M._2;return e(F=>e(I=>{const z=($,X)=>{const Y=$._3;return e(W=>Y?r($,X):R(M,J))};return e($=>e(X=>He(Q(C,D,!1),e,n,(Y,W)=>z(Q(Y._1,Y._2,!1),W),(Y,W)=>e(K=>e(Z=>N1(Y,e,n,(ct,_t)=>z(Q(ct._1,ct._2,!1),_t),(ct,_t)=>e(gt=>{const yt=Y._3&&!ct._3?Q(ct._1,ct._2,!0):ct;return e(St=>R(yt,w("Just",_t)))})))))))}))})})))})))})))})))}))),Ww=(t,e,n,r,i)=>e(o=>ar("-edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(Le)("source node identifier"),p=c._3&&!d._3?Q(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const v=p._3&&!y._3?Q(y._1,y._2,!0):y;return e(k=>fn(v,e,n,r,(L,E)=>e(B=>{const q=Gt(Le)("target node identifier"),j=v._3&&!L._3?Q(L._1,L._2,!0):L;return e(G=>q(j,e,n,r,(P,V)=>e(U=>i(j._3&&!P._3?Q(P._1,P._2,!0):P,Wn("DelEdge",{from:x,to:V})))))})))})))})))}))),Ow=(t,e,n,r,i)=>e(o=>ar("-node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(Le)("node identifier"),p=c._3&&!d._3?Q(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const v=sn((L,E,B,q,j)=>{const G=L._3;return zw(L,E,B,(P,V)=>q(Q(P._1,P._2,G),V),j)}),k=p._3&&!y._3?Q(y._1,y._2,!0):y;return e(L=>v(k,e,n,r,(E,B)=>e(q=>i(k._3&&!E._3?Q(E._1,E._2,!0):E,Wn("DelNode",{id:x,via:Ct(Vt.foldr,B)})))))})))})))}))),Yw=(t,e,n,r,i)=>e(o=>ar("enter")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(Le)("node identifier"),p=c._3&&!d._3?Q(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>i(p._3&&!y._3?Q(y._1,y._2,!0):y,Wn("Enter",{id:x})))))})))}))),$w=(t,e,n,r,i)=>e(o=>ar("exit")(t,e,n,r,(u,s)=>e(a=>i(t._3&&!u._3?Q(u._1,u._2,!0):u,WT)))),qw=(t,e,n,r,i)=>e(o=>ar("~edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(Le)("source node identifier"),p=c._3&&!d._3?Q(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const v=p._3&&!y._3?Q(y._1,y._2,!0):y;return e(k=>fn(v,e,n,r,(L,E)=>e(B=>{const q=Gt(Le)("target node identifier"),j=v._3&&!L._3?Q(L._1,L._2,!0):L;return e(G=>q(j,e,n,r,(P,V)=>e(U=>{const M=j._3&&!P._3?Q(P._1,P._2,!0):P;return e(H=>en(M,e,n,r,(R,C)=>e(D=>{const F=Gt(ei("->"))("'->'"),I=M._3&&!R._3?Q(R._1,R._2,!0):R;return e(z=>F(I,e,n,r,($,X)=>e(Y=>{const W=I._3&&!$._3?Q($._1,$._2,!0):$;return e(K=>en(W,e,n,r,(Z,ct)=>e(_t=>{const gt=Gt(Le)("new source node identifier"),yt=W._3&&!Z._3?Q(Z._1,Z._2,!0):Z;return e(St=>gt(yt,e,n,r,(Ht,pt)=>e(Wt=>{const Tt=yt._3&&!Ht._3?Q(Ht._1,Ht._2,!0):Ht;return e(mt=>fn(Tt,e,n,r,(ft,ot)=>e(dt=>{const ut=Gt(Le)("new target node identifier"),st=Tt._3&&!ft._3?Q(ft._1,ft._2,!0):ft;return e(Nt=>ut(st,e,n,r,(Jt,kt)=>e(Ot=>i(st._3&&!Jt._3?Q(Jt._1,Jt._2,!0):Jt,Wn("RepointEdge",{from:x,to:V,newFrom:pt,newTo:kt})))))})))})))})))})))})))})))})))})))})))}))),Xw=(t,e,n,r,i)=>e(o=>ar("seed")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(f=>He(c,e,n,r,(d,l)=>e(_=>{const h=Gt(Mw)("integer (seed value)"),p=c._3&&!d._3?Q(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const v=p._3&&!y._3?Q(y._1,y._2,!0):y;return e(k=>en(v,e,n,r,(L,E)=>e(B=>i(v._3&&!L._3?Q(L._1,L._2,!0):L,x))))})))})))}))),eo=Ew((()=>{const t=Gt(jt(e=>e==="{"))("'{'");return(e,n,r,i,o)=>n(u=>n(s=>t(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?Q(a._1,a._2,!0):a;return en(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?Q(_._1,_._2,!0):_,h)))})))))})())(Gt((()=>{const t=Gt(jt(e=>e==="}"))("'}'");return(e,n,r,i,o)=>n(u=>n(s=>en(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?Q(a._1,a._2,!0):a;return t(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?Q(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),Vw=eo((t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>(()=>{if(f.tag==="Nothing")return(l,_,h,p,m)=>m(l,A);if(f.tag==="Just"){const l=f._1,_=sn((()=>{const h=Gt(jt(p=>p===","))("','");return(p,m,y,x,N)=>{const v=p._3;return m(k=>m(L=>m(E=>m(B=>m(q=>m(j=>He(p,m,y,(G,P)=>x(Q(G._1,G._2,v),P),(G,P)=>m(V=>m(U=>{const M=p._3&&!G._3?Q(G._1,G._2,!0):G;return h(M,m,y,(H,R)=>x(Q(H._1,H._2,v),R),(H,R)=>m(C=>{const D=M._3&&!H._3?Q(H._1,H._2,!0):H;return m(F=>m(I=>{const z=p._3&&!D._3?Q(D._1,D._2,!0):D;return He(z,m,y,($,X)=>x(Q($._1,$._2,v),X),($,X)=>m(Y=>{const W=z._3&&!$._3?Q($._1,$._2,!0):$;return m(K=>m(Z=>{const ct=p._3&&!W._3?Q(W._1,W._2,!0):W;return J1(ct,m,y,(_t,gt)=>x(Q(_t._1,_t._2,v),gt),(_t,gt)=>m(yt=>N(ct._3&&!_t._3?Q(_t._1,_t._2,!0):_t,gt)))}))}))}))}))})))))))))}})());return(h,p,m,y,x)=>p(N=>_(h,p,m,y,(v,k)=>p(L=>x(h._3&&!v._3?Q(v._1,v._2,!0):v,Pw([l,...Ct(Vt.foldr,k)])))))}g()})()(t._3&&!c._3?Q(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>e(f=>J1(Q(s,a,!1),e,n,(d,l)=>e(_=>u(t,J)),(d,l)=>e(_=>u(d,w("Just",l))))))})),Uw=(t,e,n,r,i)=>e(o=>ar("+node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(Le)("node identifier"),p=c._3&&!d._3?Q(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const v=p._3&&!y._3?Q(y._1,y._2,!0):y;return e(k=>e(L=>He(v,e,n,r,(E,B)=>e(q=>{const j=jt(P=>P===`
15
+ `||P==="\r"||P==="#"||P==="}"||P==="{"),G=v._3&&!E._3?Q(E._1,E._2,!0):E;return e(P=>{const V=(H,R)=>e(C=>(R?((D,F,I,z,$)=>$(D,"")):Bw)(G._3&&!H._3?Q(H._1,H._2,!0):H,e,n,r,(D,F)=>e(I=>{const z=v._3&&!D._3?Q(D._1,D._2,!0):D;return e($=>{const X=(K,Z)=>e(ct=>i(z._3&&!K._3?Q(K._1,K._2,!0):K,Wn("AddNode",{id:x,label:F,shape:(()=>{const _t=Dw("shape")(Z);if(_t.tag==="Just")return _t._1==="rectangle"||_t._1==="rect"?tr:_t._1==="cylinder"||_t._1==="cyl"?vl:_t._1==="parallelogram"?bl:_t._1==="diamond"?kl:_t._1==="ellipse"?Ll:_t._1==="document"||_t._1==="doc"?El:_t._1==="cloud"?Cl:tr;if(_t.tag==="Nothing")return tr;g()})()}))),Y=z._1,W=z._2;return e(K=>{const Z=(ct,_t)=>{const gt=ct._3;return e(yt=>gt?r(ct,_t):X(z,A))};return e(ct=>e(_t=>He(Q(Y,W,!1),e,n,(gt,yt)=>Z(Q(gt._1,gt._2,!1),yt),(gt,yt)=>e(St=>e(Ht=>Vw(gt,e,n,(pt,Wt)=>Z(Q(pt._1,pt._2,!1),Wt),(pt,Wt)=>e(Tt=>X(gt._3&&!pt._3?Q(pt._1,pt._2,!0):pt,Wt))))))))})})}))),U=G._1,M=G._2;return e(H=>{const R=(C,D)=>{const F=C._3;return e(I=>F?r(C,D):V(G,!1))};return e(C=>e(D=>e(F=>Ea(Q(U,M,!1),e,n,(I,z)=>{const $=I._3;return e(X=>$?R(Q(U,M,!1),z):e(Y=>j(Q(U,M,!1),e,n,(W,K)=>R(Q(U,M,!1),K),(W,K)=>e(Z=>e(ct=>V(Q(U,M,!1),!0))))))},(I,z)=>e($=>e(X=>V(Q(U,M,!1),!0)))))))})})}))))})))})))}))),Kw=(t,e,n,r,i)=>e(o=>d1(t,e,n,r,(u,s)=>e(a=>{const c=Gt(m1([Uw,Ow,qw,Hw,Ww,Yw,$w,Rw]))("statement (+node, -node, +edge, -edge, ~edge, enter, exit, or 'a -> b')"),f=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>i(f._3&&!l._3?Q(l._1,l._2,!0):l,wa("Leaf",{op:_,line:s.line,column:s.column})))))}))),Zw=(t,e,n,r,i)=>e(o=>to("seq")(t,e,n,r,(u,s)=>e(a=>eo(Ga(u1))(t._3&&!u._3?Q(u._1,u._2,!0):u,e,n,r,i)))),jw=(t,e,n,r,i)=>e(o=>to("par")(t,e,n,r,(u,s)=>e(a=>eo(Ga(qT))(t._3&&!u._3?Q(u._1,u._2,!0):u,e,n,r,i)))),Ga=t=>{const e=sn(tv());return(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,c)=>r(f=>u(n._3&&!a._3?Q(a._1,a._2,!0):a,t(Ct(Vt.foldr,c))))))},tv=Qa(()=>{const t=ka(Gt(jt(e=>e==="}"))("'}'"));return(e,n,r,i,o)=>n(u=>{const s=e._3;return n(a=>n(c=>en(e,n,r,(f,d)=>i(Q(f._1,f._2,s),d),(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?Q(f._1,f._2,!0):f;return t(h,n,r,(p,m)=>i(Q(p._1,p._2,s),m),(p,m)=>n(y=>{const x=h._3&&!p._3?Q(p._1,p._2,!0):p;return n(N=>{const v=m1([(L,E,B,q,j)=>{const G=L._3;return jw(L,E,B,(P,V)=>q(Q(P._1,P._2,G),V),j)},(L,E,B,q,j)=>{const G=L._3;return Zw(L,E,B,(P,V)=>q(Q(P._1,P._2,G),V),j)},Kw]),k=e._3&&!x._3?Q(x._1,x._2,!0):x;return n(L=>v(k,n,r,i,(E,B)=>n(q=>{const j=k._3&&!E._3?Q(E._1,E._2,!0):E;return n(G=>He(j,n,r,i,(P,V)=>n(U=>{const M=j._3&&!P._3?Q(P._1,P._2,!0):P;return n(H=>Iw(M,n,r,i,(R,C)=>n(D=>o(M._3&&!R._3?Q(R._1,R._2,!0):R,B))))})))})))})}))})))))})}),Pa=t=>e=>(n,r,i,o,u)=>r(s=>to(t)(n,r,i,o,(a,c)=>r(f=>{const d=n._3&&!a._3?Q(a._1,a._2,!0):a;return r(l=>Qw(d,r,i,o,(_,h)=>r(p=>{const m=d._3&&!_._3?Q(_._1,_._2,!0):_;return r(y=>en(m,r,i,o,(x,N)=>r(v=>{const k=eo(Ga(u1)),L=m._3&&!x._3?Q(x._1,x._2,!0):x;return r(E=>k(L,r,i,o,(B,q)=>r(j=>{const G=L._3&&!B._3?Q(B._1,B._2,!0):B;return r(P=>en(G,r,i,o,(V,U)=>r(M=>u(G._3&&!V._3?Q(V._1,V._2,!0):V,{name:w("Just",h),ops:q,kind:e}))))})))})))})))}))),ev=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>Pa("keyframe")(OT)(Q(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>{if(f)return r(a,c);const l=t._1,_=t._2;return e(h=>Pa("still")(YT)(Q(l,_,!1),e,n,(p,m)=>{const y=p._3;return e(x=>y?r(p,m):Pa("title")($T)(t,e,n,r,i))},i))})},i))},nv=(t,e,n,r,i)=>e(o=>to("inside")(t,e,n,r,(u,s)=>e(a=>{const c=Gt(Le)("node identifier"),f=t._3&&!u._3?Q(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=f._3&&!l._3?Q(l._1,l._2,!0):l;return e(m=>en(p,e,n,r,(y,x)=>e(N=>{const v=p._3&&!y._3?Q(y._1,y._2,!0):y;return e(k=>eo(T1)(v,e,n,r,(L,E)=>e(B=>{const q=v._3&&!L._3?Q(L._1,L._2,!0):L;return e(j=>en(q,e,n,r,(G,P)=>e(V=>i(q._3&&!G._3?Q(G._1,G._2,!0):G,{node:_,doc:E}))))})))})))})))}))),T1=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>{const l=sn(rv()),_=t._3&&!c._3?Q(c._1,c._2,!0):c;return e(h=>l(_,e,n,r,(p,m)=>e(y=>{const x=Ct(Vt.foldr,m);return i(_._3&&!p._3?Q(p._1,p._2,!0):p,{seed:(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})(),frames:xt(N=>{if(N.tag==="TopFrame")return w("Just",N._1);if(N.tag==="TopInside")return J;g()})(x),interiors:xt(N=>{if(N.tag==="TopInside")return w("Just",N._1);if(N.tag==="TopFrame")return J;g()})(x)})})))}),s=t._1,a=t._2;return e(c=>e(f=>Xw(Q(s,a,!1),e,n,(d,l)=>{const _=d._3;return e(h=>_?r(d,l):u(t,J))},(d,l)=>e(_=>u(d,w("Just",l))))))}),rv=Qa(()=>yw.defer(t=>(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>n(c=>nv(Q(u,s,!1),n,r,(f,d)=>n(l=>n(_=>ev(e,n,r,i,(h,p)=>n(m=>o(h,p1("TopFrame",p)))))),(f,d)=>n(l=>o(f,p1("TopInside",d))))))})),iv=(()=>{const t=Gt((e,n,r,i,o)=>n(u=>n(s=>en(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?Q(a._1,a._2,!0):a;return Ea(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?Q(_._1,_._2,!0):_,h)))}))))))("'keyframe', 'still', 'title', 'inside', or end of input");return(e,n,r,i,o)=>n(u=>n(s=>n(a=>n(c=>en(e,n,r,i,(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?Q(f._1,f._2,!0):f;return T1(h,n,r,i,(p,m)=>n(y=>{const x=h._3&&!p._3?Q(p._1,p._2,!0):p;return n(N=>n(v=>{const k=e._3&&!x._3?Q(x._1,x._2,!0):x;return t(k,n,r,i,(L,E)=>n(B=>o(k._3&&!L._3?Q(L._1,L._2,!0):L,m)))}))}))})))))))})(),ov=t=>{const e=Tw(t)(iv);if(e.tag==="Left")return Dt("Left",{msg:e._1._1,line:e._1._2.line,column:e._1._2.column});if(e.tag==="Right")return Dt("Right",e._1);g()},uv=t=>{const e=ov(t);if(e.tag==="Left")return Dt("Left",e._1.msg);if(e.tag==="Right")return Dt("Right",e._1);g()};function Da(t,e,n,r){if(typeof window<"u"){var i=window[n];if(i!=null&&r instanceof i)return e(r)}for(var o=r;o!=null;){var u=Object.getPrototypeOf(o),s=u.constructor.name;if(s===n)return e(r);if(s==="Object")return t;o=u}return t}function ni(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function sv(t){return function(e){return function(){return e.getAttribute(t)}}}const w1=t=>{const e=sv(t);return n=>{const r=e(n);return()=>{const i=r();return ac(i,J,Ut)}}};function av(t){return function(e){return function(){e.textContent=t}}}function cv(t){return function(){return function(e){return t(e)()}}}function gv(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const fv=function(){return window};function _v(t){return function(e){return function(){e.value=t}}}function dv(t){return function(){return t.valueAsNumber}}function lv(t){return function(){return t.value}}function hv(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const pv=t=>t,mv=t=>()=>t.clientWidth||0,yv=t=>()=>t.clientHeight||0,xv=()=>window.devicePixelRatio||1,Ia=(t,e)=>{e.innerHTML=t},Lu=(t,e,n)=>{t.style.setProperty(e,n)},Nv=(t,e)=>t.querySelector(`[data-mg="${e}"]`),Jv=t=>e=>t===e,Tv=t=>t,wv=(t,e,n)=>({tag:t,_1:e,_2:n}),vv=zt.foldMap(Ed),v1=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},bv=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},kv=wv("AutoSize"),Lv=Tv("CanvasRenderer"),Ev=t=>e=>{const n=t-e*et(ce(mn(t/e)));return e<=0?0:n<0?n+e:n},Cv=t=>T(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),Sv=t=>{const e=w1("data-markgraf-titles")(t);return()=>{const n=e();return n.tag==="Nothing"||!(n.tag==="Just"&&n._1==="false")}},Gv=t=>{const e=w1("data-markgraf-theme")(t);return()=>{const n=e();if(n.tag==="Just")return n._1==="light"?Na:n._1==="dark"?yT:n._1==="blueprint"?xT:n._1==="whiteboard"?NT:n._1==="isometric"?JT:Na;if(n.tag==="Nothing")return Na;g()}},Pv=`
16
16
  <canvas data-mg="stage" tabindex="0"></canvas>
17
17
  <div data-mg="play-overlay" aria-hidden="true"></div>
18
18
  <div data-mg="bar">
@@ -29,4 +29,4 @@ var Hv=(function(ku){"use strict";function Aa(t){let e=0,n;return()=>{if(e===2)r
29
29
  <option value="2">2\xD7</option>
30
30
  </select>
31
31
  </div>
32
- `,Hn=t=>e=>n=>()=>{const r=yv(t,e),i=uc(r,J,Xt);if(i.tag==="Just")return n(i._1)();i.tag!=="Nothing"&&g()},Pv=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=wv(i=>'<span class="mg-tick" style="left:'+di(fi("Fixed",_i(0)(20)(2)))(100*i.startT/n)+'%" data-label="'+(()=>{if(i.scene.tag==="Structural")return i.scene._1.to;if(i.scene.tag==="DataFlow")return i.scene._1.keyframe;if(i.scene.tag==="Hold")return i.scene._1;if(i.scene.tag==="EnterNode"||i.scene.tag==="ExitNode")return"";g()})()+'"></span>')(e.spans);return Hn(t)("ticks")(i=>()=>Pa(r,i))},Iv=t=>e=>n=>Hn(t)("scrub")(r=>{const i=Ga(J,Xt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return n<=0?()=>{}:_v(oe(de(Un(e/n*1e3))))(i._1);g()}),Da=t=>e=>n=>{const r=cv(i=>n);return()=>{const i=r();return gv(t)(i)(!1)(e)()}},E1=()=>Md()/1e3,Qa=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>{const f=Ve(u.layout),d=Al(u.layout),l={center:{x:d.x+d.w/2,y:f.y+f.h/2},zoom:as(u.layout)(f)(0)},_=rs(u.layout)(l),h=()=>{const N=E1(),v=a.value;return a.value=N,v===0?0:N-v},p=sp(u)(L1(c)(u.totalDuration)),m=o?p:{...p,levels:z(N=>({...N,state:{...N.state,frameTitle:""}}))(p.levels)},x=u.dives.length===0&&(_.w+48)*1.0909090909090908<=1100&&(_.h+48)*1.0909090909090908<=1400,y=x?{...m,camera:l,levels:z(N=>({...N,state:{...N.state,camera:l}}))(m.levels)}:m;if(e==="CanvasRenderer")return()=>{const N=h(),v=pv(t),L=ni({padding:8,outputAspect:J})(y),k=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){if(x)return{w:L.vw*1.0909090909090908,h:L.vh*1.0909090909090908};const M=mv(t)();return{w:M,h:L.vw<=0?M:M*L.vh/L.vw}}g()})(),E=xv(),O=k.w*E,Y=k.h*E,et=Rd(v)(),G=Bd(v)(),P=Wd(v)(O);et!==O&&P();const V=zd(v)(Y);if(G!==Y&&V(),Ia(t,"height",oe(de(Un(k.h)))+"px"),n.tag==="FixedSize")Ia(t,"width",oe(de(Un(k.w)))+"px");else if(n.tag==="AutoSize"){const M=oe(de(Un(k.w)))+"px";x&&Ia(t,"width",M)}else g();const U=Od(v)();_r(U)(),co(U)({scaleX:E,scaleY:E})();const B=s.value,R=pT(r)(i)(U)({width:k.w,height:k.h})(y)(N)(B)();return s.value=R,dr(U)()};if(e==="SvgRenderer")return()=>{const N=h(),v=s.value,L=FT((()=>{if(n.tag==="AutoSize")return J;if(n.tag==="FixedSize")return n._1<=0||n._2<=0?J:w("Just",n._1/n._2);g()})())(r)(i)(y)(N)(v);return s.value=L.springs,oi("viewBox")(L.parts.viewBox)(t)(),oi("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(oi("width")(oe(de(Un(n._1))))(t)(),oi("height")(oe(de(Un(n._2))))(t)()):n.tag==="AutoSize"||g(),Pa(L.parts.body,t)};g()},C1=t=>{const e=uv(t);if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right"){const n=l1(e._1)(g1)._1;if(n.tag==="Left")return Pt("Left",n._1.msg);if(n.tag==="Right")return Pt("Right",n._1)}g()},Dv=t=>{const e=C1(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return Dd;g()},Fa=t=>e=>{const n=Vt(r=>r.startT<=e&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return n._1.scene._1.to;if(n._1.scene.tag==="DataFlow")return n._1.scene._1.keyframe;if(n._1.scene.tag==="Hold")return n._1.scene._1;if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return"";g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;if(r>=0&&r<t.spans.length){if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="Hold")return t.spans[r].scene._1;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return"";g()}return""}g()},Qv=t=>e=>Hn(t)("speed")(n=>{const r=Ga(J,Xt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return Da("change")(n)((()=>{const i=lv(r._1);return()=>{const o=i(),u=md(o,tc,Xt,J);if(u.tag==="Just")return e(u._1)();u.tag!=="Nothing"&&g()}})());g()}),Fv=t=>e=>n=>Hn(t)("scrub")(r=>{const i=Ga(J,Xt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return Da("input")(r)((()=>{const o=dv(i._1);return()=>{const u=o();return n.pause(),n.seek(u/1e3*e.totalDuration)()}})());g()}),Av=t=>e=>n=>{const r=Pv(t)(e);return()=>{r(),Hn(t)("play")(i=>oi("data-mg-playing")("1")(i))(),Qv(t)(n.setSpeed)(),Hn(t)("play")(i=>Da("click")(i)(n.toggle))(),Fv(t)(e)(n)(),n.subscribe(i=>{const o=Iv(t)(i.time)(e.totalDuration);return()=>(o(),Hn(t)("time")(u=>av(di(fi("Fixed",_i(0)(20)(2)))(i.time)+" / "+di(fi("Fixed",_i(0)(20)(2)))(e.totalDuration))(u))(),Hn(t)("play")(u=>oi("data-mg-playing")(i.playing?"1":"0")(u))())})()}},Mv={...mh,tokenZoomFloor:1,minZoom:1.6,maxZoom:3.2},Ov=t=>e=>{const n=Qf(t);return()=>{const r=n(),i=Ff(t)(),o=N0(Mv)(c0)(t)(Af(r)(i)(t));if(o.tag==="Left")return sc("[markgraf] precompute failed")();if(o.tag==="Right")return e(o._1)();g()}},Rv=t=>e=>n=>r=>i=>o=>u=>()=>{let s=1,a=!0,c=!1,f=0,d=0;const l={value:Q},_={value:0};let h=!1,p=[];Qa(t)(n)(r)(i)(o)(u)(e)(l)(_)(0)();const m=k=>()=>{const E=p,O=a,Y={time:k,keyframe:Fa(e)(k),playing:O};return Ev(et=>et(Y))(E)()},x=()=>(a=!1,m(f)()),y=()=>{if(!h&&(c=!1,a)){const k=E1(),E=d;d=k;const O=s,Y=f,et=Lv(E===0?Y+0*O:Y+(k-E)*O)(e.totalDuration+.8);return f=et,Qa(t)(n)(r)(i)(o)(u)(e)(l)(_)(et)(),m(et)(),N()}},N=()=>{if(!h&&!c){c=!0;const k=fv();hv(y)(k)()}},v=()=>(d=0,a=!0,N()),L=()=>(a||v(),m(f)());return v(),{play:L,pause:x,toggle:()=>a?x():L(),seek:k=>{const E=vv(0)(L1(e.totalDuration)(k));return()=>(f=E,d=0,Qa(t)(n)(r)(i)(o)(u)(e)(l)(_)(E)(),m(E)())},setSpeed:k=>()=>s=k,currentTime:()=>f,currentKeyframe:()=>{const k=f;return Fa(e)(k)},isPlaying:()=>a,duration:e.totalDuration,subscribe:k=>()=>{p=Ot(p)(k);const E=f,O=a;k({time:E,keyframe:Fa(e)(E),playing:O})();const Y=Ka(et=>!Nv(et)(k));return()=>{p=Y(p)}},destroy:()=>h=!0}},S1=t=>e=>{const n=C1(e);if(n.tag==="Left")return sc("[markgraf] parse failed: "+n._1);if(n.tag==="Right")return Ov(n._1)(r=>{const i=Cv(t);return()=>{const o=i(),u=Sv(t)();return Pa(Gv,t),Hn(t)("stage")(s=>{const a=Rv(s)(r)(kv)(bv)(u)(TT)(o);return()=>{const c=a();return Av(t)(r)(c)()}})()}});g()},Bv=t=>{const e=t.getAttribute("data-markgraf-src-b64");if(e)try{return decodeURIComponent(escape(atob(e)))}catch{return atob(e)}return t.getAttribute("data-markgraf-src")||t.textContent||""};let En=null;const vu=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",Wv=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{vu(t)?(En&&En!==t&&vu(En)&&En.querySelector('[data-mg="play"]').click(),En=t):En===t&&(En=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},zv=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=Bv(t),n=t.dataset.markgrafPaused==="true";t.textContent="",S1(t)(e)(),n?vu(t)&&t.querySelector('[data-mg="play"]').click():En===null?En=t:vu(t)&&t.querySelector('[data-mg="play"]').click(),Wv(t)},bu=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(zv)},G1=()=>{document.addEventListener("keydown",t=>{if(t.code!=="Space"&&t.key!==" ")return;const e=t.target,n=e&&e.closest?.("[data-markgraf]");if(!n){const i=e?.tagName,o=(e?.type||"").toLowerCase();if(e?.isContentEditable||i==="TEXTAREA"||i==="SELECT"||i==="INPUT"&&!["range","checkbox","radio","button","submit","reset"].includes(o))return}const r=n||En||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=Dv(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>S1(e)(n)(),mountAll:bu,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{bu(),G1()}):(bu(),G1())}return ku.mountAll=bu,Object.defineProperty(ku,Symbol.toStringTag,{value:"Module"}),ku})({});
32
+ `,$n=t=>e=>n=>()=>{const r=Nv(t,e),i=ac(r,J,Ut);if(i.tag==="Just")return n(i._1)();i.tag!=="Nothing"&&g()},Dv=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=vv(i=>'<span class="mg-tick" style="left:'+gi(ai("Fixed",ci(0)(20)(2)))(100*i.startT/n)+'%" data-label="'+(()=>{if(i.scene.tag==="Structural")return i.scene._1.to;if(i.scene.tag==="DataFlow")return i.scene._1.keyframe;if(i.scene.tag==="Hold")return i.scene._1;if(i.scene.tag==="EnterNode"||i.scene.tag==="ExitNode")return"";g()})()+'"></span>')(e.spans);return $n(t)("ticks")(i=>()=>Ia(r,i))},Iv=t=>e=>n=>$n(t)("scrub")(r=>{const i=Da(J,Ut,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return n<=0?()=>{}:_v(ee(ce(Dn(e/n*1e3))))(i._1);g()}),Aa=t=>e=>n=>{const r=cv(i=>n);return()=>{const i=r();return gv(t)(i)(!1)(e)()}},b1=()=>Id()/1e3,Fa=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>{const f=qe(u.layout),d=Pl(u.layout),l={center:{x:d.x+d.w/2,y:f.y+f.h/2},zoom:cs(u.layout)(f)(0)},_=Sc(u.layout)(l),h=()=>{const N=b1(),v=a.value;return a.value=N,v===0?0:N-v},p=ap(u)(v1(c)(u.totalDuration)),m=o?p:{...p,levels:O(N=>({...N,state:{...N.state,frameTitle:""}}))(p.levels)},y=u.dives.length===0&&(_.w+48)*1.0909090909090908<=1100&&(_.h+48)*1.0909090909090908<=1400,x=y?{...m,camera:l,levels:O(N=>({...N,state:{...N.state,camera:l}}))(m.levels)}:m;if(e==="CanvasRenderer")return()=>{const N=h(),v=pv(t),k=Nu({padding:8,outputAspect:J})(x),L=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){if(y)return{w:k.vw*1.0909090909090908,h:k.vh*1.0909090909090908};const R=mv(t)(),C=yv(t)();return{w:R,h:C<=0?k.vw<=0?R:R*k.vh/k.vw:C}}g()})(),E=xv(),B=L.w*E,q=L.h*E,j=Fd(v)(),G=Bd(v)(),P=Qd(v)(B);j!==B&&P();const V=Rd(v)(q);if(G!==q&&V(),n.tag==="FixedSize")Lu(t,"width",ee(ce(Dn(L.w)))+"px"),Lu(t,"height",ee(ce(Dn(L.h)))+"px");else if(n.tag==="AutoSize"){const R=ee(ce(Dn(L.w)))+"px";y&&(Lu(t,"width",R),Lu(t,"height",ee(ce(Dn(L.h)))+"px"))}else g();const U=Ad(v)();Kn(U)(),ao(U)({scaleX:E,scaleY:E})();const M=s.value,H=pT(r)(i)(U)({width:L.w,height:L.h})(x)(N)(M)();return s.value=H,Zn(U)()};if(e==="SvgRenderer")return()=>{const N=h(),v=s.value,k=FT((()=>{if(n.tag==="AutoSize")return J;if(n.tag==="FixedSize")return n._1<=0||n._2<=0?J:w("Just",n._1/n._2);g()})())(r)(i)(x)(N)(v);return s.value=k.springs,ni("viewBox")(k.parts.viewBox)(t)(),ni("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(ni("width")(ee(ce(Dn(n._1))))(t)(),ni("height")(ee(ce(Dn(n._2))))(t)()):n.tag==="AutoSize"||g(),Ia(k.parts.body,t)};g()},k1=t=>{const e=uv(t);if(e.tag==="Left")return Dt("Left",e._1);if(e.tag==="Right"){const n=f1(e._1)(s1)._1;if(n.tag==="Left")return Dt("Left",n._1.msg);if(n.tag==="Right")return Dt("Right",n._1)}g()},Av=t=>{const e=k1(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return Sd;g()},Ba=t=>e=>{const n=Kt(r=>r.startT<=e&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return n._1.scene._1.to;if(n._1.scene.tag==="DataFlow")return n._1.scene._1.keyframe;if(n._1.scene.tag==="Hold")return n._1.scene._1;if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return"";g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;if(r>=0&&r<t.spans.length){if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="Hold")return t.spans[r].scene._1;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return"";g()}return""}g()},Fv=t=>e=>$n(t)("speed")(n=>{const r=Da(J,Ut,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return Aa("change")(n)((()=>{const i=lv(r._1);return()=>{const o=i(),u=dd(o,nc,Ut,J);if(u.tag==="Just")return e(u._1)();u.tag!=="Nothing"&&g()}})());g()}),Bv=t=>e=>n=>$n(t)("scrub")(r=>{const i=Da(J,Ut,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return Aa("input")(r)((()=>{const o=dv(i._1);return()=>{const u=o();return n.pause(),n.seek(u/1e3*e.totalDuration)()}})());g()}),Qv=t=>e=>n=>{const r=Dv(t)(e);return()=>{r(),$n(t)("play")(i=>ni("data-mg-playing")("1")(i))(),Fv(t)(n.setSpeed)(),$n(t)("play")(i=>Aa("click")(i)(n.toggle))(),Bv(t)(e)(n)(),n.subscribe(i=>{const o=Iv(t)(i.time)(e.totalDuration);return()=>(o(),$n(t)("time")(u=>av(gi(ai("Fixed",ci(0)(20)(2)))(i.time)+" / "+gi(ai("Fixed",ci(0)(20)(2)))(e.totalDuration))(u))(),$n(t)("play")(u=>ni("data-mg-playing")(i.playing?"1":"0")(u))())})()}},Rv={...dh,tokenZoomFloor:1,minZoom:1.6,maxZoom:3.2},Mv=t=>e=>{const n=Af(t);return()=>{const r=n(),i=Ff(t)(),o=m0(Rv)(u0)(t)(Bf(r)(i)(t));if(o.tag==="Left")return cc("[markgraf] precompute failed")();if(o.tag==="Right")return e(o._1)();g()}},zv=t=>e=>n=>r=>i=>o=>u=>()=>{let s=1,a=!0,c=!1,f=0,d=0;const l={value:A},_={value:0};let h=!1,p=[];Fa(t)(n)(r)(i)(o)(u)(e)(l)(_)(0)();const m=L=>()=>{const E=p,B=a,q={time:L,keyframe:Ba(e)(L),playing:B};return Cv(j=>j(q))(E)()},y=()=>(a=!1,m(f)()),x=()=>{if(!h&&(c=!1,a)){const L=b1(),E=d;d=L;const B=s,q=f,j=Ev(E===0?q+0*B:q+(L-E)*B)(e.totalDuration+.8);return f=j,Fa(t)(n)(r)(i)(o)(u)(e)(l)(_)(j)(),m(j)(),N()}},N=()=>{if(!h&&!c){c=!0;const L=fv();hv(x)(L)()}},v=()=>(d=0,a=!0,N()),k=()=>(a||v(),m(f)());return v(),{play:k,pause:y,toggle:()=>a?y():k(),seek:L=>{const E=bv(0)(v1(e.totalDuration)(L));return()=>(f=E,d=0,Fa(t)(n)(r)(i)(o)(u)(e)(l)(_)(E)(),m(E)())},setSpeed:L=>()=>s=L,currentTime:()=>f,currentKeyframe:()=>{const L=f;return Ba(e)(L)},isPlaying:()=>a,duration:e.totalDuration,subscribe:L=>()=>{p=Rt(p)(L);const E=f,B=a;L({time:E,keyframe:Ba(e)(E),playing:B})();const q=tc(j=>!Jv(j)(L));return()=>{p=q(p)}},destroy:()=>h=!0}},L1=t=>e=>{const n=k1(e);if(n.tag==="Left")return cc("[markgraf] parse failed: "+n._1);if(n.tag==="Right")return Mv(n._1)(r=>{const i=Sv(t);return()=>{const o=i(),u=Gv(t)();return Ia(Pv,t),$n(t)("stage")(s=>{const a=zv(s)(r)(Lv)(kv)(u)(TT)(o);return()=>{const c=a();return Qv(t)(r)(c)()}})()}});g()},Hv=t=>{const e=t.getAttribute("data-markgraf-src-b64");if(e)try{return decodeURIComponent(escape(atob(e)))}catch{return atob(e)}return t.getAttribute("data-markgraf-src")||t.textContent||""};let Sn=null;const Eu=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",Wv=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{Eu(t)?(Sn&&Sn!==t&&Eu(Sn)&&Sn.querySelector('[data-mg="play"]').click(),Sn=t):Sn===t&&(Sn=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},Ov=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=Hv(t),n=t.dataset.markgrafPaused==="true";t.textContent="",L1(t)(e)(),n?Eu(t)&&t.querySelector('[data-mg="play"]').click():Sn===null?Sn=t:Eu(t)&&t.querySelector('[data-mg="play"]').click(),Wv(t)},Cu=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(Ov)},E1=()=>{document.addEventListener("keydown",t=>{if(t.code!=="Space"&&t.key!==" ")return;const e=t.target,n=e&&e.closest?.("[data-markgraf]");if(!n){const i=e?.tagName,o=(e?.type||"").toLowerCase();if(e?.isContentEditable||i==="TEXTAREA"||i==="SELECT"||i==="INPUT"&&!["range","checkbox","radio","button","submit","reset"].includes(o))return}const r=n||Sn||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=Av(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>L1(e)(n)(),mountAll:Cu,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{Cu(),E1()}):(Cu(),E1())}return Su.mountAll=Cu,Object.defineProperty(Su,Symbol.toStringTag,{value:"Module"}),Su})({});