@markgrafhq/markgraf-embed 0.1.5 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/markgraf-embed.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
var
|
|
2
|
-
`:return"\\n";case"\r":return"\\r";case" ":return"\\t";case"\v":return"\\v"}var i=r+1,o=i<e&&t[i]>="0"&&t[i]<="9"?"\\&":"";return"\\"+n.charCodeAt(0).toString(10)+o})+'"'},Vi=t=>t,me=Vi("LT"),Ne=Vi("GT"),we=Vi("EQ"),L=(t,e)=>({tag:t,_1:e}),T=L("Nothing"),jt=t=>L("Just",t),Mu=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;c()},Nf=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;c()},Et=(t,e)=>({tag:t,_1:e}),yf=t=>Et("Right",t),Jf={map:t=>e=>{if(e.tag==="Left")return Et("Left",e._1);if(e.tag==="Right")return Et("Right",t(e._1));c()}},$u={apply:t=>e=>{if(t.tag==="Left")return Et("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Et("Left",e._1);if(e.tag==="Right")return Et("Right",t._1(e._1))}c()},Functor0:()=>Jf},xf={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Et("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}c()},Apply0:()=>$u},Tf={pure:yf,Apply0:()=>$u},vf={Applicative0:()=>Tf,Bind1:()=>xf},wf=t=>t,Lf={map:t=>e=>t(e)},zu={apply:t=>e=>t(e),Functor0:()=>Lf},bf={bind:t=>e=>e(t),Apply0:()=>zu},Ef={pure:wf,Apply0:()=>zu},dn={Applicative0:()=>Ef,Bind1:()=>bf},kf=function(t){return function(){return t}},Gf={apply:t=>e=>()=>{const n=t(),r=e();return Ui.pure(n(r))()},Functor0:()=>Cf},Ui={pure:kf,Apply0:()=>Gf},Cf={map:t=>e=>()=>{const n=e();return t(n)}},fr=(t,e)=>({tag:t,_1:e}),Ou=t=>fr("Loop",t),Sf={tailRecM:t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="Loop"){r=t(u._1);continue}if(u.tag==="Done"){i=!1,o=u._1;continue}c()}return o};return n=>e(t(n))},Monad0:()=>dn},Qf=(function(t){return function(e){return function(n){return function(){return t(e,n)}}}})(function(t,e){return e.push(t)}),Pf=(t,e)=>({tag:"Iterator",_1:t,_2:e}),Df=t=>e=>n=>()=>{let r=!1;const i=e._2;for(;!r;){const o=i.value,u=e._1(o);if(u.tag==="Just"&&t(u._1)){n.push(u._1),e._2.value;const s=e._2.value;e._2.value=s+1|0;continue}r=!0}},Af=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const i=r.value,o=r.value;r.value=o+1|0;const u=t._1(i);if(u.tag==="Just"){e(u._1)();continue}if(u.tag==="Nothing"){n=!0;continue}c()}},gr=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=i-1;o>=0;o--)r=t(n[o])(r);return r}}},J=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=0;o<i;o++)r=t(r)(n[o]);return r}}},If=t=>{const e=t.Apply0();return n=>r=>n.foldr(i=>{const o=r(i);return u=>e.apply(e.Functor0().map(s=>Fu)(o))(u)})(t.pure())},Dt={foldr:gr,foldl:J,foldMap:t=>{const e=t.mempty;return n=>Dt.foldr(r=>i=>t.Semigroup0().append(n(r))(i))(e)}},w=(t,e)=>({tag:"Tuple",_1:t,_2:e}),Bn=t=>e=>w(t,e),Yr=t=>t._2,Xr=t=>t._1,At=function(t){return function(e){for(var n=e.length,r=Array(n),i=0;i<n;i++)r[i]=t(i)(e[i]);return r}};var Yi=function(t){return function(e){return t===e}};const Rf=Yi,Ff=Yi,Xi=Yi,Bf=function(t){return function(e){return function(n){if(e.length!==n.length)return!1;for(var r=0;r<e.length;r++)if(!t(e[r])(n[r]))return!1;return!0}}},ze={eq:Xi},Mf={eq:Ff},_r={eq:Rf};var Ki=function(t){return function(e){return function(n){return function(r){return function(i){return r<i?t:r===i?e:n}}}}};const $f=Ki,zf=Ki,C={compare:Ki(me)(we)(Ne),Eq0:()=>ze},dt={compare:zf(me)(we)(Ne),Eq0:()=>Mf},nt={compare:$f(me)(we)(Ne),Eq0:()=>_r},qu=function(t){return t},Of=(function(){function t(i){return[i]}function e(i){return function(o){return[i,o]}}function n(i){return function(o){return function(u){return[i,o,u]}}}function r(i){return function(o){return i.concat(o)}}return function(i){return function(o){return function(u){return function(s){return function(a){function f(g,d){switch(d-g){case 0:return u([]);case 1:return o(t)(s(a[g]));case 2:return i(o(e)(s(a[g])))(s(a[g+1]));case 3:return i(i(o(n)(s(a[g])))(s(a[g+1])))(s(a[g+2]));default:var l=g+Math.floor((d-g)/4)*2;return i(o(r)(f(g,l)))(f(l,d))}}return f(0,a.length)}}}}}})(),qf=t=>t,dr={traverse:t=>{const e=t.Apply0();return Of(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>dr.traverse(t)(qf),Functor0:()=>pf,Foldable1:()=>Dt},Ht=function(t,e){for(var n=t>e?-1:1,r=new Array(n*(e-t)+1),i=t,o=0;i!==e;)r[o++]=i,i+=n;return r[o]=i,r};var Hf=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},Wf=function(t,e){for(var n=[],r=0,i=0;i<t;i++)n[r++]=e;return n};const Vf=typeof Array.prototype.fill=="function"?Hf:Wf,bt=(function(){function t(i,o){this.head=i,this.tail=o}var e={};function n(i){return function(o){return new t(i,o)}}function r(i){for(var o=[],u=0,s=i;s!==e;)o[u++]=s.head,s=s.tail;return o}return function(i,o){return r(i(n)(e)(o))}})(),Bt=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},Uf=function(t,e,n,r){for(var i=0;i<r.length;i++){var o=n(r[i]);if(e(o))return o}return t},Mn=function(t,e,n,r){for(var i=0,o=r.length;i<o;i++)if(n(r[i]))return t(i);return e},Yf=function(t,e,n,r){for(var i=r.length-1;i>=0;i--)if(n(r[i]))return t(i);return e},Xf=function(t,e,n,r,i){if(n<0||n>i.length)return e;var o=i.slice();return o.splice(n,0,r),t(o)},Hu=function(t,e,n,r){if(n<0||n>=r.length)return e;var i=r.slice();return i.splice(n,1),t(i)},$n=function(t,e,n,r,i){if(n<0||n>=i.length)return e;var o=i.slice();return o[n]=r,t(o)},de=function(t){return t.slice().reverse()},Le=function(t){if(t.length<=1e4)return Array.prototype.concat.apply([],t);for(var e=[],n=0,r=t.length;n<r;n++)for(var i=t[n],o=0,u=i.length;o<u;o++)e.push(i[o]);return e},ct=function(t,e){return e.filter(t)},Kf=(function(){function t(e,n,r,i,o,u){var s,a,f,g,d,l,_;for(s=o+(u-o>>1),s-o>1&&t(e,n,i,r,o,s),u-s>1&&t(e,n,i,r,s,u),a=o,f=s,g=o;a<s&&f<u;)d=i[a],l=i[f],_=n(e(d)(l)),_>0?(r[g++]=l,++f):(r[g++]=d,++a);for(;a<s;)r[g++]=i[a++];for(;f<u;)r[g++]=i[f++]}return function(e,n,r){var i;return r.length<2?r:(i=r.slice(0),t(e,n,i,r.slice(0),0,r.length),i)}})(),It=function(t,e,n){return n.slice(t,e)},ye=function(t,e,n){for(var r=e.length<n.length?e.length:n.length,i=new Array(r),o=0;o<r;o++)i[o]=t(e[o])(n[o]);return i},Ze=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},Wu=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},vt=t=>e=>Kf(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;c()},e),jf=t=>e=>vt(n=>r=>t.compare(e(n))(e(r))),oe=t=>e=>(()=>{const n=Qf(e);return()=>{const r=[...t];return n(r)(),r}})()(),Vu=t=>{if(t.length===0)return t.length-1|0,T;const e=t.length-1|0;return e>=0&&e<t.length?L("Just",{init:It(0,t.length-1|0,t),last:t[e]}):T},Zf=t=>e=>n=>t>=0&&t<n.length?$n(jt,T,t,e(n[t]),n):T,Tn=t=>e=>{const n=(r=>{let i=r,o=!0,u;for(;o;){const s=i;if(s>=0&&s<e.length){if(t(e[s])){i=s+1|0;continue}o=!1,u=L("Just",s);continue}o=!1,u=T}return u})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:It(0,n._1,e),rest:It(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};c()},zn=t=>e=>{const n=vt(r=>i=>t(r._2)(i._2))(At(Bn)(e));return 0<n.length?O(Yr)(jf(nt)(Xr)((()=>{const r=[n[0]];for(const i of n){const o=t((()=>{const u=r.length-1|0;if(u>=0&&u<r.length)return r[u]._2;c()})())(i._2);(o==="LT"||o==="GT"||o!=="EQ")&&r.push(i)}return r})())):[]},tg=t=>e=>{const n=[],r=Pf(i=>i>=0&&i<e.length?L("Just",e[i]):T,{value:0});return Af(r)(i=>()=>{const o=[];o.push(i),Df(t(i))(r)(o)(),n.push(o)})(),n},ge=t=>e=>{const n=Mn(jt,T,t,e);return n.tag==="Just"?L("Just",e[n._1]):T},Uu=t=>e=>ct(t,e),ke=t=>e=>n=>{const r=Mn(jt,T,i=>t.eq(i)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;c()},Yu=t=>e=>St(e)(t),xt=t=>Yu(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];c()}),Xu=isFinite;function eg(t,e,n,r){var i=parseFloat(t);return e(i)?n(i):r}const On=Math.abs,ji=Math.ceil,Zi=Math.cos,Ku=Math.exp,ju=Math.floor,to=function(t){return function(e){return Math.pow(t,e)}},Zu=Math.round,eo=Math.sin,qn=Math.sqrt,ng=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},ot=function(t){return t},rg=(function(t){return function(e){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var i=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(o){if(i.test(o)){var u=parseInt(o,n);return(u|0)===u?t(u):e}else return e}}}})(jt)(T)(10),ts=ng(jt)(T),vn=t=>{if(!Xu(t))return 0;if(t>=ot(2147483647))return 2147483647;if(t<=ot(-2147483648))return-2147483648;const e=ts(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;c()},Mt=(t,e,n)=>({tag:t,_1:e,_2:n}),qt=Mt("Nil"),Wt={foldr:t=>e=>{const n=Wt.foldl(i=>o=>t(o)(i))(e),r=(i=>o=>{let u=i,s=o,a=!0,f;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,f=g;continue}if(d.tag==="Cons"){u=Mt("Cons",d._1,g),s=d._2;continue}c()}return f})(qt);return i=>n(r(i))},foldl:t=>e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=t(s)(a._1),i=a._2;continue}c()}return u},foldMap:t=>{const e=t.mempty;return n=>Wt.foldl(r=>{const i=t.Semigroup0().append(r);return o=>i(n(o))})(e)}},ig=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);u.push(n(a));var f=r(a);if(t(f))return u;s=e(f)}}}}}}},og=t=>{if(t.tag==="Just")return t._1;c()},ug={unfoldr1:ig(Mu)(og)(Xr)(Yr)},sg=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);if(t(a))return u;var f=e(a);u.push(n(f)),s=r(f)}}}}}}},ag=t=>{if(t.tag==="Just")return t._1;c()},Re={unfoldr:sg(Mu)(ag)(Xr)(Yr),Unfoldable10:()=>ug},$t=(t,e,n,r,i,o,u)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u}),Fe=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Kr=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),es=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),M=$t("Leaf"),wn=Fe("IterLeaf"),te=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return $t("Node",1,1,t,e,n,r);if(r.tag==="Node")return $t("Node",1+r._1|0,1+r._2|0,t,e,n,r);c()}if(n.tag==="Node"){if(r.tag==="Leaf")return $t("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return $t("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,t,e,n,r)}c()},Je=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?$t("Node",1,1,t,e,M,M):r.tag==="Node"&&r._1>1?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;c()})()?te(r._5._3,r._5._4,te(t,e,n,r._5._5),te(r._3,r._4,r._5._6,r._6)):te(r._3,r._4,te(t,e,n,r._5),r._6):te(t,e,n,r);if(n.tag==="Node")return r.tag==="Node"?r._1>(n._1+1|0)?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;c()})()?te(r._5._3,r._5._4,te(t,e,n,r._5._5),te(r._3,r._4,r._5._6,r._6)):te(r._3,r._4,te(t,e,n,r._5),r._6):n._1>(r._1+1|0)?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;c()})()?te(n._6._3,n._6._4,te(n._3,n._4,n._5,n._6._5),te(t,e,n._6._6,r)):te(n._3,n._4,n._5,te(t,e,n._6,r)):te(t,e,n,r):r.tag==="Leaf"&&n._1>1?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;c()})()?te(n._6._3,n._6._4,te(n._3,n._4,n._5,n._6._5),te(t,e,n._6._6,r)):te(n._3,n._4,n._5,te(t,e,n._6,r)):te(t,e,n,r);c()},Hn=(t,e,n)=>{if(n.tag==="Leaf")return Kr(T,M,M);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const i=Hn(t,e,n._5);return Kr(i._1,i._2,Je(n._3,n._4,i._3,n._6))}if(r==="GT"){const i=Hn(t,e,n._6);return Kr(i._1,Je(n._3,n._4,n._5,i._2),i._3)}if(r==="EQ")return Kr(L("Just",n._4),n._5,n._6)}c()},ns=(t,e,n,r)=>{if(r.tag==="Leaf")return es(t,e,n);if(r.tag==="Node"){const i=ns(r._3,r._4,r._5,r._6);return es(i._1,i._2,Je(t,e,n,i._3))}c()},lr=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=ns(t._3,t._4,t._5,t._6);return Je(n._1,n._2,n._3,e)}c()},tn=(t,e,n)=>{if(e.tag==="Leaf")return M;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=Hn(t,n._3,e);return lr(tn(t,r._2,n._5),tn(t,r._3,n._6))}c()},jr=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return M;if(r.tag==="Node"){const i=Hn(t,r._3,n),o=jr(t,e,i._2,r._5),u=jr(t,e,i._3,r._6);if(i._1.tag==="Just")return Je(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return lr(o,u)}c()},xe=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const i=Hn(t,r._3,n),o=xe(t,e,i._2,r._5),u=xe(t,e,i._3,r._6);if(i._1.tag==="Just")return Je(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return Je(r._3,r._4,o,u)}c()},cg=t=>e=>{const n=r=>{if(r.tag==="Leaf")return M;if(r.tag==="Node"){const i=e(r._3)(r._4);if(i.tag==="Just")return Je(r._3,i._1,n(r._5),n(r._6));if(i.tag==="Nothing")return lr(n(r._5),n(r._6))}c()};return n},Ln=(t=>e=>n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="IterLeaf"){i=!1,o=e();continue}if(u.tag==="IterEmit"){i=!1,o=t(u._1,u._2,u._3);continue}if(u.tag==="IterNode"){r=(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Leaf"){d=!1,l=_;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){f=Fe("IterEmit",h._3,h._4,_),g=h._5;continue}f=Fe("IterEmit",h._3,h._4,Fe("IterNode",h._6,_)),g=h._5;continue}c()}return l})(u._2)(u._1);continue}c()}return o})((t,e,n)=>L("Just",w(w(t,e),n)))(t=>T),Tt=t=>e=>n=>r=>{const i=o=>{if(o.tag==="Leaf")return $t("Node",1,1,n,r,M,M);if(o.tag==="Node"){const u=t.compare(n)(o._3);if(u==="LT")return Je(o._3,o._4,i(o._5),o._6);if(u==="GT")return Je(o._3,o._4,o._5,i(o._6));if(u==="EQ")return $t("Node",o._1,o._2,n,e(o._4)(r),o._5,o._6)}c()};return i},K=t=>e=>n=>{const r=i=>{if(i.tag==="Leaf")return $t("Node",1,1,e,n,M,M);if(i.tag==="Node"){const o=t.compare(e)(i._3);if(o==="LT")return Je(i._3,i._4,r(i._5),i._6);if(o==="GT")return Je(i._3,i._4,i._5,r(i._6));if(o==="EQ")return $t("Node",i._1,i._2,e,n,i._5,i._6)}c()};return r},Vt=t=>e=>e.foldl(n=>r=>K(t)(r._1)(r._2)(n))(M),hr=t=>e=>{const n=r=>{if(r.tag==="Leaf")return M;if(r.tag==="Node"){const i=t.compare(e)(r._3);if(i==="LT")return Je(r._3,r._4,n(r._5),r._6);if(i==="GT")return Je(r._3,r._4,r._5,n(r._6));if(i==="EQ")return lr(r._5,r._6)}c()};return n},fg=t=>{const e=t.compare;return n=>r=>i=>{const o=Hn(e,r,i),u=n(o._1);if(u.tag==="Nothing")return lr(o._2,o._3);if(u.tag==="Just")return Je(r,u._1,o._2,o._3);c()}},Zt=function(t){return function(e){return t+e|0}},Wn=function(t){return function(e){return t+e}},no=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},gg=function(t){return function(e){return t+e}},ue=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},_g={append:gg},dg={mempty:"",Semigroup0:()=>_g},lg=null;function hg(t,e,n){return t==null?e:n(t)}function R2(t){return t}function ro(t){return function(e){return function(n){return t.apply(n,[e])}}}const pg=ro(Number.prototype.toPrecision),mg=ro(Number.prototype.toFixed),Ng=ro(Number.prototype.toExponential),pr=(t,e)=>({tag:t,_1:e}),mr=t=>e=>n=>{const r=nt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),o=nt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;c()},Nr=t=>{if(t.tag==="Precision")return pg(t._1);if(t.tag==="Fixed")return mg(t._1);if(t.tag==="Exponential")return Ng(t._1);c()},rs=function(t){return function(){console.log(t)}};function is(){return Date.now()}function yg(t){return function(){return t.getContext("2d")}}function Jg(t){return function(){return t.width}}function xg(t){return function(){return t.height}}function Tg(t){return function(e){return function(){t.width=e}}}function vg(t){return function(e){return function(){t.height=e}}}function io(t){return function(e){return function(){t.lineWidth=e}}}function wg(t){return function(e){return function(){t.fillStyle=e}}}function Lg(t){return function(e){return function(){t.strokeStyle=e}}}function oo(t){return function(e){return function(){t.lineCap=e}}}function uo(t){return function(e){return function(){t.lineJoin=e}}}function bg(t){return function(e){return function(){t.globalCompositeOperation=e}}}function Eg(t){return function(e){return function(){t.globalAlpha=e}}}function os(t){return function(){t.beginPath()}}function so(t){return function(){t.stroke()}}function ao(t){return function(){t.fill()}}function kg(t){return function(){t.clip()}}function Gg(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function Cg(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function Sg(t){return function(){t.closePath()}}function Qg(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function Pg(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function co(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function us(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function Dg(t){return function(e){return function(){t.textAlign=e}}}function Ag(t){return function(e){return function(){t.textBaseline=e}}}function Ig(t){return function(e){return function(){t.font=e}}}function Rg(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function yr(t){return function(){t.save()}}function Jr(t){return function(){t.restore()}}function Fg(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function Bg(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const ss=t=>t,fo=t=>t,go=t=>t,_o=t=>t,Zr=t=>t,Mg=Zr("BaselineTop"),$g=Zr("BaselineMiddle"),zg=Zr("BaselineAlphabetic"),Og=Zr("BaselineBottom"),qg=_o("AlignLeft"),Hg=_o("AlignRight"),Wg=_o("AlignCenter"),lo=go("BevelJoin"),ti=go("RoundJoin"),ho=go("MiterJoin"),po=fo("Round"),mo=fo("Square"),No=fo("Butt"),Vg=ss("SourceOver"),Ug=ss("Difference"),Yg=t=>e=>Ag(t)((()=>{if(e==="BaselineTop")return"top";if(e==="BaselineHanging")return"hanging";if(e==="BaselineMiddle")return"middle";if(e==="BaselineAlphabetic")return"alphabetic";if(e==="BaselineIdeographic")return"ideographic";if(e==="BaselineBottom")return"bottom";c()})()),Xg=t=>e=>Dg(t)((()=>{if(e==="AlignLeft")return"left";if(e==="AlignRight")return"right";if(e==="AlignCenter")return"center";if(e==="AlignStart")return"start";if(e==="AlignEnd")return"end";c()})()),ei=t=>e=>{if(e==="BevelJoin")return uo(t)("bevel");if(e==="RoundJoin")return uo(t)("round");if(e==="MiterJoin")return uo(t)("miter");c()},yo=t=>e=>{if(e==="Round")return oo(t)("round");if(e==="Square")return oo(t)("square");if(e==="Butt")return oo(t)("butt");c()},as=t=>e=>bg(t)((()=>{if(e==="SourceOver")return"source-over";if(e==="SourceIn")return"source-in";if(e==="SourceOut")return"source-out";if(e==="SourceAtop")return"source-atop";if(e==="DestinationOver")return"destination-over";if(e==="DestinationIn")return"destination-in";if(e==="DestinationOut")return"destination-out";if(e==="DestinationAtop")return"destination-atop";if(e==="Lighter")return"lighter";if(e==="Copy")return"copy";if(e==="Xor")return"xor";if(e==="Multiply")return"multiply";if(e==="Screen")return"screen";if(e==="Overlay")return"overlay";if(e==="Darken")return"darken";if(e==="Lighten")return"lighten";if(e==="ColorDodge")return"color-dodge";if(e==="ColorBurn")return"color-burn";if(e==="HardLight")return"hard-light";if(e==="SoftLight")return"soft-light";if(e==="Difference")return"difference";if(e==="Exclusion")return"exclusion";if(e==="Hue")return"hue";if(e==="Saturation")return"saturation";if(e==="Color")return"color";if(e==="Luminosity")return"luminosity";c()})()),Ge={foldr:t=>e=>{const n=Wt.foldr(t)(e);return r=>n((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,Mt("Cons",o._3,i(o._6,u)));c()};return i(r,qt)})())}},ni=t=>t,Kg=t=>t,jg=ni("Linear"),Zg=ni("EaseInOutQuad"),t_=ni("EaseOutExpo"),e_=ni("SpringBouncy"),xr=t=>e=>n=>{const r=qn(1-e*e),i=t*r;return 1-Ku(-e*t*n)*(Zi(i*n)+e/r*eo(i*n))},n_=t=>{const e=dt.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;c()})(),r=dt.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;c()},Jo=t=>e=>(()=>{if(t==="Linear")return Kg;if(t==="EaseInQuad")return n=>n*n;if(t==="EaseOutQuad")return n=>1-(1-n)*(1-n);if(t==="EaseInOutQuad")return n=>n<.5?2*n*n:1-2*(1-n)*(1-n);if(t==="EaseInCubic")return n=>n*n*n;if(t==="EaseOutCubic")return n=>1-(1-n)*(1-n)*(1-n);if(t==="EaseInOutCubic")return n=>n<.5?4*n*n*n:1-(-2*n+2)*(-2*n+2)*(-2*n+2)/2;if(t==="EaseOutExpo")return n=>n>=1?1:1-to(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*Ku(-6*n);if(t==="SpringBouncy")return xr(6)(.7);c()})()(n_(e)),cs=J(Wn)(0),r_=t=>e=>n=>{const r=dt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),o=dt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;c()},fs=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},gs=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},_s=t=>e=>{const n=ye(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,f=s.x-u.x;return qn(f*f+a*a)})()}),t,It(1,t.length,t)),r=cs(O(u=>u.len)(n)),i=r_(0)(r)(e*r),o=u=>s=>a=>{let f=u,g=s,d=a,l=!0,_;for(;l;){const h=f,p=g,m=d,N=Bt(y=>T,y=>x=>L("Just",{head:y,tail:x}),h);if(N.tag==="Nothing"){const y=t.length-1|0;if(y>=0&&y<t.length){l=!1,_=t[y];continue}l=!1,_=m;continue}if(N.tag==="Just"){if(p<=N._1.head.len){const y=N._1.head.len<=0?0:p/N._1.head.len;l=!1,_={x:N._1.head.a.x+(N._1.head.b.x-N._1.head.a.x)*y,y:N._1.head.a.y+(N._1.head.b.y-N._1.head.a.y)*y};continue}f=N._1.tail,g=p-N._1.head.len,d=m;continue}c()}return _};return 0<t.length?L("Just",o(n)(i)(t[0])):T},xo=t=>cs(ye(e=>n=>{const r=n.y-e.y,i=n.x-e.x;return qn(i*i+r*r)},t,It(1,t.length,t))),ln=t=>{const e=Bt(n=>T,n=>r=>L("Just",{head:n,tail:r}),[...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._4,n(r._6,i)));c()};return St(bt(Wt.foldr,n(t.nodes,qt)))(r=>[{x:r.x,y:r.y},{x:r.x+r.w,y:r.y+r.h}])})(),...Le((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._4,n(r._6,i)));c()};return bt(Wt.foldr,n(t.edges,qt))})()),...Le((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._4,n(r._6,i)));c()};return bt(Wt.foldr,n(t.chipExtras,qt))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:fs(r.minX)(i.x),minY:fs(r.minY)(i.y),maxX:gs(r.maxX)(i.x),maxY:gs(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},Tr=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},bn=function(t){return t.join("")},To=function(t){return t.split("")},vo=function(t){return t},En=function(t){return t.length},ds=function(t){return function(e){return e.substr(0,t)}},vr=function(t){return function(e){return e.substring(t)}},i_=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},o_=t=>e=>{const n=i_(En(t))(e);return n.before===t?L("Just",n.after):T},u_=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},s_=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},kn=t=>BigInt(t),a_=t=>Number(t),ri=t=>e=>t+e,ii=t=>e=>t*e,wo=t=>e=>t-e,ls=0n,oi=1n,hs=t=>e=>t^e,wr=t=>e=>t&e,Lo=t=>e=>t<<e,bo=t=>e=>t>>e,c_=t=>e=>t==e,f_=t=>e=>t===e?0:t>e?1:-1,g_={eq:c_},ps={compare:t=>e=>{const n=f_(t)(e);return n===1?Ne:n===0?we:me},Eq0:()=>g_},__=u_(jt)(T),d_=s_(jt)(T),l_=t=>e=>On(t._1-e._1)+On(t._2-e._2),ui=t=>t,se=ui("North"),ae=ui("South"),Oe=ui("East"),Gn=ui("West"),ms=t=>t,Ns=(t,e)=>({tag:t,_1:e}),ys=(t,e)=>({tag:t,_1:e}),Eo=(t,e)=>({tag:t,_1:e}),h_=Eo("First"),p_=ms("Forward"),m_=ms("Backward"),N_=Vt(C)(Dt),y_=t=>gr(e=>n=>({nodes:xe(C.compare,pe,e.nodes,n.nodes),edges:xe(C.compare,pe,e.edges,n.edges)}))({nodes:M,edges:M})(t.keyframes),J_=t=>e=>({entering:{nodes:tn(C.compare,e.nodes,t.nodes),edges:tn(C.compare,e.edges,t.edges)},leaving:{nodes:tn(C.compare,t.nodes,e.nodes),edges:tn(C.compare,t.edges,e.edges)},surviving:{nodes:jr(C.compare,pe,t.nodes,e.nodes),edges:jr(C.compare,pe,t.edges,e.edges)}}),Js=t=>t,ko=t=>e=>n=>{const r=dt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),o=dt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;c()},Cn=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Vn=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Un=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Go=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},x_=J(t=>e=>K(C)(e)()(t))(M),T_=J(t=>e=>K(C)(e)()(t))(M),v_=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),xs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Ts=Vt(C)(Dt),w_=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},L_=Js("Hold"),b_=Js("Gap"),E_=t=>e=>n=>{const r=n.center.y-e.center.y,i=n.center.x-e.center.x,o=qn(i*i+r*r),u=n.zoom-e.zoom,s=u<0?-u:u;return ko(t.minTransition)(t.maxTransition)(Cn(t.panSpeed<=0?t.minTransition:o/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:s/t.zoomSpeed))},k_=J(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:oe(t)(e)})([]),Co=t=>{const e=Bt(n=>T,n=>r=>L("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:Vn(r.minX)(i.x),minY:Vn(r.minY)(i.y),maxX:Cn(r.maxX)(i.x),maxY:Cn(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},vs=t=>{const e=Bt(n=>T,n=>r=>L("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return T;if(e.tag==="Just")return L("Just",Co(t));c()},G_=t=>e=>n=>x_(St(bt(Ge.foldr,n))(r=>{const i=Un(r)(t);if(i.tag==="Just")return ct(o=>!Go(o)(e),[i._1.source,i._1.target]);if(i.tag==="Nothing")return[];c()})),C_=t=>e=>n=>{const r=Jo(t.easing)(ko(0)(1)(n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT)));return{center:{x:n.fromCam.center.x+(n.toCam.center.x-n.fromCam.center.x)*r,y:n.fromCam.center.y+(n.toCam.center.y-n.fromCam.center.y)*r},zoom:n.fromCam.zoom+(n.toCam.zoom-n.fromCam.zoom)*r}},S_=t=>e=>n=>r=>{const i=(u,s)=>Vn(E_(t)(u.toCam)(s.toCam))(u.endT-u.startT),o=J(u=>s=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:L("Just",s)};if(u.pending.tag==="Just")return!(s.fromCam.zoom===s.toCam.zoom&&s.fromCam.center.x===s.toCam.center.x&&s.fromCam.center.y===s.toCam.center.y)||(()=>{const a=u.pending._1.toCam.center.x-s.toCam.center.x;return(a<0?-a<8:a<8)&&(()=>{const f=u.pending._1.toCam.center.y-s.toCam.center.y;return(f<0?-f<8:f<8)&&(()=>{const g=u.pending._1.toCam.zoom-s.toCam.zoom;return g<0?-g<.08:g<.08})()})()})()||i(u.pending._1,s)<=0?{acc:oe(u.acc)(u.pending._1),pending:L("Just",s)}:{acc:oe(oe(u.acc)({...u.pending._1,endT:s.startT-i(u.pending._1,s)}))({startT:s.startT-i(u.pending._1,s),endT:s.startT,fromCam:u.pending._1.toCam,toCam:s.toCam}),pending:L("Just",s)};c()})({acc:[],pending:T})(r);if(o.pending.tag==="Nothing")return o.acc;if(o.pending.tag==="Just")return oe(o.acc)(o.pending._1);c()},Q_=t=>t.kind.tag==="SendToken"?L("Just",w(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):T,P_=t=>t.tag==="DataFlow"?xt(Q_)(t._1.events):[],D_=t=>e=>T_(xt(n=>Go(n._2.source)(e)||Go(n._2.target)(e)?L("Just",n._1):T)(v_(t))),A_=t=>e=>{const n=r=>{const i=Yf(jt,T,o=>o.kind==="Hold",r<1?[]:It(0,r,e));if(i.tag==="Just")return i._1>=0&&i._1<e.length?L("Just",e[i._1].cam):T;if(i.tag==="Nothing")return T;c()};return At(r=>i=>{if(i.kind==="Hold")return{startT:i.startT,endT:i.endT,fromCam:i.cam,toCam:i.cam};if(i.kind==="Gap")return{startT:i.startT,endT:i.endT,fromCam:(()=>{const o=n(r);if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;c()})(),toCam:(()=>{const o=n(r),u=(()=>{if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;c()})(),s=r+1|0,a=Mn(jt,T,f=>f.kind==="Hold",s<1?e:It(s,e.length,e));if(a.tag==="Just"){const f=(r+1|0)+a._1|0;return f>=0&&f<e.length?e[f].cam:u}if(a.tag==="Nothing")return u;c()})()};c()})(e)},ws={padding:24,easing:t_,minZoom:.9,maxZoom:2.5,panSpeed:700,zoomSpeed:1.5,minTransition:.3,maxTransition:1.4},I_=t=>e=>n=>{const r=e.w+n*2,i=e.h+n*2,o=ln(t);return r<=0||i<=0||o.w<=0||o.h<=0?1:Vn(o.w/r)(o.h/i)},So=t=>{const e=Bt(n=>T,n=>r=>L("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:Vn(r.minX)(i.x),minY:Vn(r.minY)(i.y),maxX:Cn(r.maxX)(i.x+i.w),maxY:Cn(r.maxY)(i.y+i.h)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x+e._1.head.w,maxY:e._1.head.y+e._1.head.h})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},Ls=t=>e=>n=>{if(n.tag==="Leaf")return ln(t);const r=D_(e)(n),i=[...xt(o=>{const u=xs(o)(t.nodes);return u.tag==="Just"?L("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):T})(bt(Ge.foldr,xe(C.compare,pe,n,G_(e)(n)(r)))),...xt(o=>{const u=Un(o)(t.edges);return u.tag==="Just"?L("Just",Co(u._1)):T})(bt(Ge.foldr,r)),...xt(o=>{const u=Un(o)(t.chipExtras);if(u.tag==="Just")return vs(u._1);if(u.tag==="Nothing")return T;c()})(bt(Ge.foldr,r))];return i.length===0?ln(t):So(i)},R_=t=>e=>n=>r=>{const i=[...xt(o=>o)([(()=>{const o=Un(n)(t.edges);return o.tag==="Just"?L("Just",Co(o._1)):T})(),(()=>{const o=Un(n)(t.chipExtras);if(o.tag==="Just")return vs(o._1);if(o.tag==="Nothing")return T;c()})()]),...(()=>{const o=Un(n)(e);if(o.tag==="Just")return xt(u=>{const s=xs(u)(t.nodes);return s.tag==="Just"?L("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):T})([o._1.source,o._1.target]);if(o.tag==="Nothing")return[];c()})()];return i.length===0?Ls(t)(e)(r):So(i)},F_=J(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?L("Just",t[n]):T;return r.tag==="Just"&&r._1.fromCam.zoom===r._1.toCam.zoom&&r._1.fromCam.center.x===r._1.toCam.center.x&&r._1.fromCam.center.y===r._1.toCam.center.y&&e.fromCam.zoom===e.toCam.zoom&&e.fromCam.center.x===e.toCam.center.x&&e.fromCam.center.y===e.toCam.center.y&&(()=>{const i=r._1.toCam.center.x-e.toCam.center.x;return(i<0?-i<8:i<8)&&(()=>{const o=r._1.toCam.center.y-e.toCam.center.y;return(o<0?-o<8:o<8)&&(()=>{const u=r._1.toCam.zoom-e.toCam.zoom;return u<0?-u<.08:u<.08})()})()})()?oe((()=>{const i=t.length-1|0;return i<1?[]:It(0,i,t)})())({...r._1,endT:e.endT}):oe(t)(e)})([]),bs=t=>e=>{const n=ln(t),r=n.w/Cn(1e-4)(e.zoom),i=n.h/Cn(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-i/2,w:r,h:i}},B_=t=>xe(C.compare,pe,Ts(O(e=>w(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),Ts(St(t.scenes)(P_))),Qo=t=>e=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:ko(t.minZoom)(t.maxZoom)(I_(e)(n)(t.padding))}),M_=t=>e=>n=>r=>{const i=Qo(t)(e)(ln(e)),o=ct(u=>u>=0&&u<=n,k_(vt(dt.compare)([0,n,...St(r)(u=>[u.startT,u.endT])])));return S_(t)(e)(i)(F_(A_(i)(xt(u=>{const s=(u._1+u._2)/2;if(u._2<=u._1)return T;const a=J(w_)(0)(O(g=>g.priority)(ct(g=>g.startT<=s&&s<g.endT,r))),f=O(g=>g.bbox)(ct(g=>g.priority===a,ct(g=>g.startT<=s&&s<g.endT,r)));return f.length===0?L("Just",{kind:b_,startT:u._1,endT:u._2,cam:i}):L("Just",{kind:L_,startT:u._1,endT:u._2,cam:Qo(t)(e)(So(f))})})(ye(Bn,o,It(1,o.length,o))))))},$_=t=>e=>n=>r=>{const i=ge(o=>r>=o.startT&&r<o.endT)(n);if(i.tag==="Just")return C_(t)(r)(i._1);if(i.tag==="Nothing"){const o=n.length-1|0;if(o>=0&&o<n.length&&r>=n[o].endT)return n[o].toCam;const u=Qo(t)(e)(ln(e));return 0<n.length?n[0].fromCam:u}c()};function Lr(t){return t.charCodeAt(0)}function Es(t){return String.fromCharCode(t)}const hn=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},Po=function(t){return function(e){return e.split(t)}},z_=function(t){return t.trim()},si=function(t){return function(e){return e.join(t)}};var O_=typeof Array.from=="function",q_=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",H_=typeof String.prototype.fromCodePoint=="function",W_=typeof String.prototype.codePointAt=="function";const V_=function(t){return W_?function(e){return e.codePointAt(0)}:t},U_=function(t){return H_?String.fromCodePoint:t},Y_=function(t){return function(e){return q_?function(n){for(var r="",i=n[Symbol.iterator](),o=0;o<e;++o){var u=i.next();if(u.done)return r;r+=u.value}return r}:t(e)}},X_=function(t){return function(e){return O_?function(n){return Array.from(n,e)}:t}},ai=t=>{const e=En(t);if(e===0)return T;if(e===1)return L("Just",{head:Lr(Tr(0)(t)),tail:""});const n=Lr(Tr(1)(t)),r=Lr(Tr(0)(t));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?L("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:vr(2)(t)}):L("Just",{head:r,tail:vr(1)(t)})},K_=t=>{const e=ai(t);return e.tag==="Just"?L("Just",w(e._1.head,e._1.tail)):T},j_=t=>Re.unfoldr(K_)(t),ks=V_(t=>{const e=Lr(Tr(0)(t));if(55296<=e&&e<=56319&&En(t)>1){const n=Lr(Tr(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),Do=X_(j_)(ks),Ao=t=>vo(t>=0&&t<=65535?Es(t):t<0?"\0":"\uFFFF"),Z_=U_(t=>t<=65535?Ao(t):Ao(Fn(t-65536|0,1024)+55296|0)+Ao(no(t-65536|0)(1024)+56320|0)),Gs=t=>e=>{if(t<1)return"";const n=ai(e);return n.tag==="Just"?Z_(n._1.head)+Gs(t-1|0)(n._1.tail):e},ce=Y_(Gs),t1=t=>e=>e===""?T:L("Just",ks(e)),ci=(t,e,n)=>({tag:t,_1:e,_2:n}),e1=()=>({tag:"ExtendFromSource"}),fi=(t,e)=>({tag:t,_1:e}),Io=t=>t,gi=(t,e)=>({tag:t,_1:e}),Ro=gi("NotYet"),Cs=gi("Consumed"),n1=Io("FromSource"),Ss=Io("FromTarget"),r1=Io("FromBoth"),Qs=fi("Hidden"),i1=fi("Visible"),Ps=e1(),Ds=ci("Retracted"),o1=ci("Extended"),Fo=(t,e)=>({tag:t,_1:e}),Yn=(t,e,n)=>({tag:t,_1:e,_2:n}),As=t=>t,Sn=(t,e)=>({tag:t,_1:e}),Xn=(t,e,n,r,i,o,u,s,a)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u,_7:s,_8:a}),Is=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},_i=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},pn=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},br=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Rs=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Fs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Kn=(()=>{const t=Re.unfoldr(e=>{if(e.tag==="Nil")return T;if(e.tag==="Cons")return L("Just",w(e._1,e._2));c()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._3,n(r._6,i)));c()};return n(e,qt)})())})(),u1=J(t=>e=>K(C)(e)()(t))(M),Bo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},s1=Vt(C)(Dt),a1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Mo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},c1=Sn("NoKeyframes"),f1=t=>Sn("DuplicateEventId",t),g1=t=>Sn("UnknownEvent",t),Bs=As("PlopIn"),_1=As("PlopOut"),d1=t=>e=>xt(n=>{if(n.target.tag==="NodeWindow"||n.target.tag==="EdgeWindow")return T;if(n.target.tag==="TokenWindow")return L("Just",{startT:n.startT,endT:n.endT,bbox:R_(t)(e)(n.target._2)(M),priority:1});if(n.target.tag==="FillWindow")return L("Just",{startT:n.startT,endT:n.endT,bbox:Ls(t)(e)($t("Node",1,1,n.target._2,void 0,M,M)),priority:1});c()}),l1=t=>e=>n=>r=>i=>{const o=ot(J(f=>g=>f+Do(g).length|0)(0)(n.labels))*t.tokenReadSecPerChar,u=f=>{const g=Is(f)(e.nodes);if(g.tag==="Just")return{x:g._1.x+g._1.w/2,y:g._1.y+g._1.h/2};if(g.tag==="Nothing")return{x:0,y:0};c()},s=_i(n.edge)(e.edges),a=(()=>{if(s.tag==="Just"){const f=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return de(s._1);c()})(),g=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return de(s._1);c()})(),d=u(n.from),l=g.length-1|0;return(2*(()=>{const _=0<f.length?f[0]:u(n.from),h=_.x-d.x,p=_.y-d.y;return(h<0?-h:h)+(p<0?-p:p)})()+xo(s._1)+2*(()=>{const _=l>=0&&l<g.length?g[l]:u(n.to),h=u(n.to),p=h.x-_.x,m=h.y-_.y;return(p<0?-p:p)+(m<0?-m:m)})())/t.tokenSpeed}if(s.tag==="Nothing")return 0/t.tokenSpeed;c()})();return t.tokenSpeed<=0?t.minTokenDuration:pn(t.minTokenDuration)(pn(a)(o)/pn(.05)(1-r-i))},h1=t=>{if(t.event.kind.tag==="SendToken")return L("Just",{startT:t.startT,endT:t.endT,target:Xn("TokenWindow",t.event.id,t.event.kind._1.edge,t.event.kind._1.direction,t.event.kind._1.from,t.event.kind._1.to,t.event.kind._1.labels,t.holdPre,t.holdPost)});if(t.event.kind.tag==="FillNodeWithoutTransition")return L("Just",{startT:t.startT,endT:t.endT,target:Xn("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});c()},p1=t=>e=>n=>xt(r=>{const i=xt(o=>Is(o)(t.nodes))(bt(Ge.foldr,(()=>{if(r.scene.tag==="Structural")return xe(C.compare,pe,(()=>{const o=br(r.scene._1.from)(n);if(o.tag==="Nothing")return M;if(o.tag==="Just")return o._1.nodes;c()})(),(()=>{const o=br(r.scene._1.to)(n);if(o.tag==="Nothing")return M;if(o.tag==="Just")return o._1.nodes;c()})());if(r.scene.tag==="DataFlow"){const o=br(r.scene._1.keyframe)(n);if(o.tag==="Nothing")return M;if(o.tag==="Just")return o._1.nodes}c()})()));return i.length===0?T:L("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const o=J(u=>s=>({minX:Rs(u.minX)(s.x),minY:Rs(u.minY)(s.y),maxX:pn(u.maxX)(s.x+s.w),maxY:pn(u.maxY)(s.y+s.h)}))(0<i.length?{minX:i[0].x,minY:i[0].y,maxX:i[0].x+i[0].w,maxY:i[0].y+i[0].h}:{minX:0,minY:0,maxX:0,maxY:0})(It(1,i.length,i));return{x:o.minX,y:o.minY,w:o.maxX-o.minX,h:o.maxY-o.minY}})(),priority:0})}),m1=t=>e=>n=>{const r=_i(n)(t);if(r.tag==="Nothing")return Ss;if(r.tag==="Just"){const i=Fs(r._1.target)(e);return Fs(r._1.source)(e)?i?r1:n1:Ss}c()},N1=t=>e=>n=>r=>{const i=(()=>{if(r.event.when.tag==="First")return 0;if(r.event.when.tag==="At")return r.event.when._1;if(r.event.when.tag==="After"){const o=r.event.when._1,u=ge(s=>s.event.id===o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.endT;c()}if(r.event.when.tag==="With"){const o=r.event.when._1,u=ge(s=>s.event.id===o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.startT}c()})();return oe(n)({startT:i,endT:(()=>{if(r.event.kind.tag==="SendToken")return i+l1(t)(e)(r.event.kind._1)(r.holdPre)(r.holdPost);if(r.event.kind.tag==="FillNodeWithoutTransition")return i+t.plop;c()})(),event:r.event,holdPre:r.holdPre,holdPost:r.holdPost})},$o=t=>e=>{if(e<0)return Yn("AtKeyframe",t.initialKeyframe);if(e>=t.totalDuration){const r=t.spans.length-1|0;return r>=0&&r<t.spans.length?Yn("AtKeyframe",(()=>{if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;c()})()):Yn("AtKeyframe",t.initialKeyframe)}const n=ge(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Yn("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Yn("AtKeyframe",n._1.scene._1.keyframe);c()}if(n.tag==="Nothing")return Yn("AtKeyframe",t.initialKeyframe);c()},y1=t=>{if(t.when.tag==="First")return[];if(t.when.tag==="At")return[];if(t.when.tag==="After")return[t.when._1];if(t.when.tag==="With")return[t.when._1];c()},Ms={id:"",nodes:M,edges:M},J1=t=>e=>J_((()=>{const n=br(e.from)(t);if(n.tag==="Nothing")return Ms;if(n.tag==="Just")return n._1;c()})())((()=>{const n=br(e.to)(t);if(n.tag==="Nothing")return Ms;if(n.tag==="Just")return n._1;c()})()),zo=t=>e=>n=>r=>{const i=_i(r)(n.edges);if(i.tag==="Just")return t<=0?e:pn(e)(xo(i._1)/t);if(i.tag==="Nothing")return e;c()},$s=t=>e=>n=>r=>i=>{const o=t.plop,u=J1(n)(i),s=O(_=>({startT:0,endT:0+zo(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Xn("EdgeWindow",_,Fo("Extend",Ps))}))(Kn(u.entering.edges)),a=O(_=>({startT:0,endT:o,target:Xn("NodeWindow",_,Bs)}))(Kn(u.entering.nodes)),f=J(pn)(0)(O(_=>zo(t.edgeSpeed)(t.minEdgeDuration)(e)(_))(Kn(u.leaving.edges))),g=_=>Ze(h=>{const p=_i(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;c()},Kn(u.leaving.edges))?f:0,d=O(_=>({startT:g(_),endT:g(_)+t.plop,target:Xn("NodeWindow",_,_1)}))(Kn(u.leaving.nodes)),l=O(_=>({startT:0,endT:zo(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Xn("EdgeWindow",_,Fo("Retract",m1(r)(u.leaving.nodes)(_)))}))(Kn(u.leaving.edges));return{duration:(()=>{const _=vt(dt.compare)([...O(p=>p.endT)(l),...O(p=>p.endT)(d),...O(p=>p.endT)(a),...O(p=>p.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+t.gap:t.gap})(),windows:[...l,...d,...a,...s]}},x1=t=>e=>n=>r=>i=>o=>O((()=>{const u=i.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())($s(t)(e)(n)(r)(o).windows),T1=t=>xt(e=>bt(gr,e).length>1?L("Just",(()=>{const n=Bt(r=>T,r=>i=>L("Just",{head:r,tail:i}),bt(gr,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";c()})()):T)(tg(Xi)(vt(C.compare)(t))),v1=t=>{const e=O(r=>r.id)(t),n=u1(e);return[...O(f1)(T1(e)),...O(g1)(ct(r=>!Bo(r)(n),St(t)(y1)))]},w1=t=>{const e=s1(O(r=>w(r.id,(()=>{if(r.when.tag==="First")return[];if(r.when.tag==="At")return[];if(r.when.tag==="After")return[r.when._1];if(r.when.tag==="With")return[r.when._1];c()})()))(t)),n=r=>i=>o=>{if(Bo(o)(i))return[Sn("ScheduleCycle",[...bt(Ge.foldr,i),o])];if(Bo(o)(r))return[];const u=a1(o)(e);if(u.tag==="Nothing")return[];if(u.tag==="Just")return St(u._1)(n(K(C)(o)()(r))(K(C)(o)()(i)));c()};return St(t)(r=>n(M)(M)(r.id))},L1={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:100,minTokenDuration:1.4,tokenReadSecPerChar:.06,nodeEasing:e_,edgeEasing:Zg,tokenEasing:jg},b1=t=>e=>{if(e.tag==="Structural")return xt(n=>n)([Mo(e._1.from)(t)?T:L("Just",Sn("UnknownKeyframe",e._1.from)),Mo(e._1.to)(t)?T:L("Just",Sn("UnknownKeyframe",e._1.to))]);if(e.tag==="DataFlow")return[...xt(n=>n)([Mo(e._1.keyframe)(t)?T:L("Just",Sn("UnknownKeyframe",e._1.keyframe))]),...v1(e._1.events),...w1(e._1.events)];c()},E1=t=>e=>{const n=St(e)(b1(t));return n.length===0?Et("Right",void 0):Et("Left",n)},zs=t=>e=>n=>J(N1(t)(e))([])(At(r=>i=>({event:i,holdPre:i.kind.tag==="SendToken"?(()=>{const o=r-1|0;return o>=0&&o<n.length&&n[o].kind.tag==="SendToken"&&n[o].kind._1.to===i.kind._1.from})()?0:.18:0,holdPost:i.kind.tag==="SendToken"?(()=>{const o=r+1|0;return o>=0&&o<n.length&&n[o].kind.tag==="SendToken"&&n[o].kind._1.from===i.kind._1.to})()?0:.18:0}))(n)),k1=t=>e=>n=>{const r=zs(t)(e)(n.events);return r.length===0?t.gap:J(pn)(0)(O(i=>i.endT)(r))+t.gap},G1=t=>e=>n=>r=>i=>{if(i.tag==="Structural")return $s(t)(e)(n)(r)(i._1).duration;if(i.tag==="DataFlow")return k1(t)(e)(i._1);c()},C1=t=>e=>n=>r=>i=>J(o=>u=>{const s=G1(t)(e)(n)(r)(u);return{acc:oe(o.acc)({startT:o.t,endT:o.t+s,scene:u}),t:o.t+s}})({acc:[],t:0})(i).acc,S1=t=>e=>n=>r=>O((()=>{const i=n.startT;return o=>({...o,startT:o.startT+i,endT:o.endT+i})})())(xt(h1)(zs(t)(e)(r.events))),Q1=t=>e=>n=>r=>i=>{if(i.scene.tag==="Structural")return x1(t)(e)(n)(r)(i)(i.scene._1);if(i.scene.tag==="DataFlow")return S1(t)(e)(i)(i.scene._1);c()},P1=t=>e=>n=>{const r=0<e.keyframes.length?L("Just",e.keyframes[0]):T;if(r.tag==="Nothing")return Et("Left",[c1]);if(r.tag==="Just"){const i=r._1,o=N_(O(a=>w(a.id,a))(e.keyframes)),u=B_(e),s=E1(o)(e.scenes);return(()=>{if(s.tag==="Left"){const a=s._1;return f=>Et("Left",a)}if(s.tag==="Right"){const a=s._1;return f=>f(a)}c()})()(()=>{const a=C1(t)(n)(o)(u)(e.scenes),f=a.length-1|0,g=f>=0&&f<a.length?a[f].endT:0,d=vt(l=>_=>dt.compare(l.startT)(_.startT))(St(a)(Q1(t)(n)(o)(u)));return Et("Right",{totalDuration:g,windows:d,spans:a,keyframes:o,initialKeyframe:i.id,timing:t,layout:n,cameraSpans:M_(ws)(n)(g)([...p1(n)(u)(o)(a),...d1(n)(u)(d)]),cameraConfig:ws})})}c()},Er=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Os=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},di=t=>e=>n=>{const r=dt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),o=dt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;c()},D1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},A1=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},I1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},R1=Vt(C)(Dt),F1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},B1=Vt(C)(Dt),M1=Vt(C)(Dt),$1=t=>e=>n=>r=>{const i=ln(t),o=i.w/Er(1e-4)(e.zoom)/2,u=i.h/Er(1e-4)(e.zoom)/2,s=n.y-e.center.y,a=n.x-e.center.x;return{...e,center:{x:o<=1e-4?e.center.x+0*r*.35:a<0?e.center.x+a/(1+-a/o)*r*.35:e.center.x+a/(1+a/o)*r*.35,y:u<=1e-4?e.center.y+0*r*.35:s<0?e.center.y+s/(1+-s/u)*r*.35:e.center.y+s/(1+s/u)*r*.35}}},Oo=t=>e=>{const n=Os(e)(t.keyframes);if(n.tag==="Nothing")return M;if(n.tag==="Just")return n._1.nodes;c()},qo=t=>e=>{const n=Os(e)(t.keyframes);if(n.tag==="Nothing")return M;if(n.tag==="Just")return n._1.edges;c()},z1=t=>e=>n=>Ze(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),O1=t=>e=>n=>Ze(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),q1=t=>e=>n=>Ze(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),H1=t=>e=>n=>Ze(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),W1=t=>e=>{const n=$o(t)(e);if(n.tag==="AtKeyframe")return ce(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return ce(3)(n._2)==="kf-"?"":n._2;c()},qs=t=>e=>n=>ge(r=>n(r)&&e>=r.startT&&e<r.endT)(t),V1=t=>{const e=di(0)(1)(t/.2),n=di(0)(1)((1-t)/.2);return e*e*(3-2*e)*n*n*(3-2*n)},U1=t=>e=>{if(e.tag==="Travelling"){const n=D1(e._1.edge)(t.edges);if(n.tag==="Just"){const r=_s(n._1)(e._1.progress);return r.tag==="Just"?L("Just",{dot:r._1,weight:V1(e._1.progress)}):T}if(n.tag==="Nothing")return T;c()}return T},Y1=t=>e=>{const n=$o(t)(e);if(n.tag==="AtKeyframe")return Oo(t)(n._1);if(n.tag==="InTransition")return xe(C.compare,pe,Oo(t)(n._1),Oo(t)(n._2));c()},X1=t=>e=>{const n=$o(t)(e);if(n.tag==="AtKeyframe")return qo(t)(n._1);if(n.tag==="InTransition")return xe(C.compare,pe,qo(t)(n._1),qo(t)(n._2));c()},K1=t=>e=>{const n=ln(t),r=n.h/Er(1e-4)(e.zoom),i=n.w/Er(1e-4)(e.zoom);return{...e,center:{x:i>=n.w?n.x+n.w/2:di(n.x+i/2)(n.x+n.w-i/2)(e.center.x),y:r>=n.h?n.y+n.h/2:di(n.y+r/2)(n.y+n.h-r/2)(e.center.y)}}},li=t=>e=>{const n=t.endT-t.startT;return n<=0?1:Er(0)(A1(1)((e-t.startT)/n))},j1=t=>e=>n=>r=>{const i=qs(t.windows)(e)(o=>o.target.tag==="EdgeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=Jo(t.timing.edgeEasing)(li(i._1)(e)),u=i._1.target.tag==="EdgeWindow"?i._1.target._2:Fo("Extend",Ps);if(u.tag==="Retract")return ci("Retracting",u._1,o);if(u.tag==="Extend")return ci("Extending",u._1,o);c()}if(i.tag==="Nothing")return H1(t.windows)(e)(r)||z1(t.windows)(e)(r)?Ds:I1(r)(n)?o1:Ds;c()},Z1=t=>e=>{const n=X1(t)(e);return R1(O(r=>w(r,j1(t)(e)(n)(r)))((()=>{const r=i=>{if(i.tag==="Leaf")return M;if(i.tag==="Node")return $t("Node",i._1,i._2,i._3,void 0,r(i._5),r(i._6));c()};return bt(Ge.foldr,r(t.layout.edges))})()))},td=t=>e=>n=>r=>{const i=qs(t.windows)(e)(o=>o.target.tag==="NodeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=li(i._1)(e),u=i._1.target.tag==="NodeWindow"?i._1.target._2:Bs;if(u==="PlopIn")return fi("PloppingIn",o);if(u==="PlopOut")return fi("PloppingOut",o);c()}if(i.tag==="Nothing")return q1(t.windows)(e)(r)||O1(t.windows)(e)(r)?Qs:F1(r)(n)?i1:Qs;c()},ed=t=>e=>{const n=Y1(t)(e);return B1(O(r=>w(r,td(t)(e)(n)(r)))((()=>{const r=i=>{if(i.tag==="Leaf")return M;if(i.tag==="Node")return $t("Node",i._1,i._2,i._3,void 0,r(i._5),r(i._6));c()};return bt(Ge.foldr,r(t.layout.nodes))})()))},nd=t=>e=>n=>e.target.tag==="TokenWindow"?w(e.target._1,n<e.startT?Ro:n>=e.endT?Cs:gi("Travelling",{edge:e.target._2,direction:e.target._3,progress:Jo(t.timing.tokenEasing)(li(e)(n)),labels:e.target._6,source:e.target._4,target:e.target._5,holdPre:e.target._7,holdPost:e.target._8})):e.target.tag==="FillWindow"?w(e.target._1,n<e.startT?Ro:n>=e.endT?Cs:gi("Filling",{node:e.target._2,progress:li(e)(n),labels:e.target._3})):w("",Ro),rd=t=>e=>M1(O(n=>nd(t)(n)(e))(ct(n=>n.target.tag==="TokenWindow"||n.target.tag==="FillWindow",t.windows))),id=t=>e=>{const n=xt(U1(t))((()=>{const r=(i,o)=>{if(i.tag==="Leaf")return o;if(i.tag==="Node")return r(i._5,Mt("Cons",i._4,r(i._6,o)));c()};return bt(Wt.foldr,r(e.tokens,qt))})());return 0<n.length?L("Just",n[0]):T},od=t=>e=>{const n=id(t)(e);if(n.tag==="Nothing")return e.camera;if(n.tag==="Just")return $1(t)(e.camera)(n._1.dot)(n._1.weight);c()},ud=t=>e=>{const n={nodes:ed(t)(e),edges:Z1(t)(e),tokens:rd(t)(e),camera:$_(t.cameraConfig)(t.layout)(t.cameraSpans)(e),frameTitle:W1(t)(e)};return{...n,camera:K1(t.layout)(od(t.layout)(n))}},Hs=t=>t,Ws=Hs("RunText"),sd=Hs("RunCode"),Vs=t=>e=>n=>e.length===0?n:oe(n)({style:t,text:bn(e)}),ad=t=>({style:(()=>{if(t.style==="RunText")return sd;if(t.style==="RunCode")return Ws;c()})(),buf:[],runs:Vs(t.style)(t.buf)(t.runs)}),cd=t=>e=>0<e.length?{...t,buf:oe(t.buf)(e[0])}:{...t,buf:oe(t.buf)("\\")},fd=t=>e=>{let n=t,r=e,i=!0,o;for(;i;){const u=n,s=Bt(a=>T,a=>f=>L("Just",{head:a,tail:f}),r);if(s.tag==="Nothing"){i=!1,o=u;continue}if(s.tag==="Just"){if(s._1.head==="\\"){n=cd(u)(s._1.tail),r=It(1,s._1.tail.length,s._1.tail);continue}if(s._1.head==="`"){n=ad(u),r=s._1.tail;continue}n={...u,buf:oe(u.buf)(s._1.head)},r=s._1.tail;continue}c()}return o},Us=t=>{const e=fd({style:Ws,buf:[],runs:[]})(To(t));return Vs(e.style)(e.buf)(e.runs)};let Ho=null;function gd(){return Ho||(typeof document>"u"?null:(Ho=document.createElement("canvas").getContext("2d"),Ho))}const Ys=new Map,_d=t=>e=>n=>r=>()=>{const i=`${n} ${e}px ${t}|${r}`,o=Ys.get(i);if(o!==void 0)return o;const u=gd();if(!u)return r.length*e*.62;u.font=`${n} ${e}px ${t}`;const s=u.measureText(r).width;return Ys.set(i,s),s},dd=dr.traverse(Ui),ld=J(Wn)(0),kr=(()=>{const t=hn(`\r
|
|
3
|
-
`)(" "),e=
|
|
4
|
-
`)(" "),n=(()=>{const r=
|
|
5
|
-
`)(o._1))(Wo(i)),s=J(a=>f=>Gr(a)(En(f)))(0)(u);return{...o._2,size:w(ot(s>i?Fn((s+2|0)+t.cellW|0,t.cellW):r),ot(Gr(1)(Fn(u.length+t.cellH|0,t.cellH))))}})(n)}},vd=t=>e=>n=>({...n,nodes:O(r=>{const i=yd(r.id)(e);if(i.tag==="Nothing")return r;if(i.tag==="Just")return{...r,size:w(Nd(r.size._1)(ot(Gr(1)(vn(ji((i._1+32)/t))))),r.size._2)};c()})(n.nodes)}),wd=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ld=t=>{const e=t.length;return(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,f=o;if(a>=e){u=!1,s=f;continue}const g=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const N=_,y=h;if(N>=e){p=!1,m=y;continue}if(a>=0&&a<t.length){if(N>=0&&N<t.length){_=N+1|0,h=(()=>{const x=t[a].position,v=t[a].size,b=t[N].position,E=t[N].size;return x._1<b._1+E._1&&b._1<x._1+v._1&&x._2<b._2+E._2&&b._2<x._2+v._2})()?y+1|0:y;continue}_=N+1|0,h=y;continue}p=!1,m=y}return m};i=a+1|0,o=g(a+1|0)(f)}return s})(0)(0)},Ks=t=>J(e=>n=>e+l_(n.start)(n.end))(0)(t.segments),bd=t=>e=>n=>({crossingCount:J(r=>i=>r+i.jumps.length|0)(0)(e),bendCount:J(r=>i=>r+i.bends.length|0)(0)(e),totalEdgeLength:J(r=>i=>r+Ks(i))(0)(e),maxEdgeLength:J(r=>i=>wd(r)(Ks(i)))(0)(e),nodeOverlapCount:Ld(t),constraintViolations:n,jumpCount:J(r=>i=>r+i.jumps.length|0)(0)(e)}),Vo=t=>t,Yt=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Uo=Vo("LEFT"),Ed=Vo("RIGHT"),js=Vo("UNDEFINED"),kd={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},Gd={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?we:me;if(e==="LEFT")return Ne;if(t==="RIGHT")return e==="RIGHT"?we:me;if(e==="RIGHT")return Ne;if(t==="UP")return e==="UP"?we:me;if(e==="UP")return Ne;if(t==="DOWN")return e==="DOWN"?we:me;if(e==="DOWN")return Ne;if(t==="UNDEFINED"&&e==="UNDEFINED")return we;c()},Eq0:()=>kd},Cd=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){if(t==="LEFT"){if(o._3==="LEFT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="LEFT"){n=o._6;continue}if(t==="RIGHT"){if(o._3==="RIGHT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="RIGHT"){n=o._6;continue}if(t==="UP"){if(o._3==="UP"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="UP"){n=o._6;continue}if(t==="DOWN"){if(o._3==="DOWN"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="DOWN"){n=o._6;continue}if(t==="UNDEFINED"&&o._3==="UNDEFINED"){r=!1,i=!0;continue}}c()}return i},Sd={x:0,y:0},qe=t=>e=>n=>{const r=Yt(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:K(nt)(t)(e(r._1))(n.cNodes)};c()},Cr=t=>e=>n=>{const r=Yt(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:K(nt)(t)(e(r._1))(n.cGroups)};c()},Qd=t=>J(e=>n=>qe(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),Pd=t=>{const e=J(n=>r=>{const i=Yt(r)(t.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just")return J(o=>u=>Tt(nt)(ue)(u)([r])(o))(n)(i._1.constraints);c()})(M)(t.cNodeOrder);return J(n=>r=>qe(r)(i=>({...i,constraints:(()=>{const o=Yt(r)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;c()})()}))(n))(t)(t.cNodeOrder)},Dd=t=>{const e=J(n=>r=>Cr(r)(i=>({...i,outDegree:i.outDegreeReal}))(n))(t)(t.cGroupOrder);return J(n=>r=>qe(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder)},Ad={left:!1,right:!1,up:!1,down:!1},Id={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},Yo=t=>J(e=>n=>{const r=Yt(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const i=J(u=>s=>{const a=Yt(s)(e.cNodes);if(a.tag==="Nothing")return u;if(a.tag==="Just"){if(u.tag==="Nothing")return L("Just",s);if(u.tag==="Just"){const f=Yt(u._1)(e.cNodes);if(f.tag==="Nothing")return L("Just",s);if(f.tag==="Just")return a._1.hitbox.x<f._1.hitbox.x?L("Just",s):L("Just",u._1)}}c()})(T)(r._1.cNodes),o=Cr(n)(u=>({...u,reference:i}))(e);if(i.tag==="Nothing")return o;if(i.tag==="Just"){const u=Yt(i._1)(o.cNodes);if(u.tag==="Nothing")return o;if(u.tag==="Just"){const s=u._1;return J(a=>f=>qe(f)(g=>({...g,cGroupOffset:{x:g.hitbox.x-s.hitbox.x,y:g.hitbox.y-s.hitbox.y}}))(a))(o)(r._1.cNodes)}}}c()})(t)(t.cGroupOrder),be=t=>Yo({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return M;if(n.tag==="Node")return $t("Node",n._1,n._2,n._3,{...n._4,hitbox:{...n._4.hitbox,x:-n._4.hitbox.x-n._4.hitbox.width}},e(n._5),e(n._6));c()};return e(t.cNodes)})()}),He=t=>Yo({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return M;if(n.tag==="Node")return $t("Node",n._1,n._2,n._3,{...n._4,hitbox:{x:n._4.hitbox.y,y:n._4.hitbox.x,width:n._4.hitbox.height,height:n._4.hitbox.width},cGroupOffset:{x:n._4.cGroupOffset.y,y:n._4.cGroupOffset.x}},e(n._5),e(n._6));c()};return e(t.cNodes)})()}),Zs=t=>{const e=J(n=>r=>Cr(r)(i=>({...i,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return J(n=>r=>{const i=Yt(r)(n.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just"){if(i._1.cGroup.tag==="Nothing")return n;if(i._1.cGroup.tag==="Just"){const o=i._1.cGroup._1;return J(u=>s=>{const a=Yt(s)(u.cNodes);if(a.tag==="Nothing")return u;if(a.tag==="Just")return a._1.cGroup.tag==="Just"&&a._1.cGroup._1!==o?Cr(a._1.cGroup._1)(f=>({...f,outDegree:f.outDegree+1|0,outDegreeReal:f.outDegreeReal+1|0}))(Cr(o)(f=>ke(_r)(s)(f.incomingConstraints)?f:{...f,incomingConstraints:[...f.incomingConstraints,s]})(u)):u;c()})(n)(i._1.constraints)}}c()})(e)(e.cNodeOrder)},hi=t=>{const e=Pd(t.cGraph);return{...t,cGraph:Zs(J(n=>r=>qe(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},Rd=t=>e=>J(n=>r=>{if(t==="LEFT"||t==="UP"){const o=r._2;return qe(r._1)(u=>({...u,constraints:[...u.constraints,o]}))(n)}const i=r._1;return qe(r._2)(o=>({...o,constraints:[...o.constraints,i]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),Pe=t=>{const e={...t,cGraph:Rd(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return M;if(r.tag==="Node")return $t("Node",r._1,r._2,r._3,{...r._4,constraints:[]},n(r._5),n(r._6));c()};return n(t.cGraph.cNodes)})()})};return{...e,cGraph:Zs((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);c()})())}},Fd=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?Pe(r):e==="RIGHT"?Pe({...r,cGraph:be(r.cGraph)}):e==="UP"?Pe({...r,cGraph:He(r.cGraph)}):e==="DOWN"?Pe({...r,cGraph:be(He(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?hi({...r,cGraph:be(r.cGraph)}):e==="UP"?Pe({...r,cGraph:He(r.cGraph)}):e==="DOWN"?Pe({...r,cGraph:be(He(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?hi({...r,cGraph:be(r.cGraph)}):e==="UP"?Pe({...r,cGraph:He(be(r.cGraph))}):e==="DOWN"?Pe({...r,cGraph:be(He(be(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?Pe({...r,cGraph:He(r.cGraph)}):e==="RIGHT"?Pe({...r,cGraph:be(He(r.cGraph))}):e==="DOWN"?hi({...r,cGraph:be(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?Pe({...r,cGraph:He(be(r.cGraph))}):e==="RIGHT"?Pe({...r,cGraph:be(He(be(r.cGraph)))}):e==="UP"?hi({...r,cGraph:be(r.cGraph)}):r;c()},ta=t=>e=>e.finished||!Cd(t)(e.cGraph.supportedDirections)||(t==="LEFT"?e.direction==="LEFT":t==="RIGHT"?e.direction==="RIGHT":t==="UP"?e.direction==="UP":t==="DOWN"?e.direction==="DOWN":t==="UNDEFINED"&&e.direction==="UNDEFINED")?e:Fd(e.direction)(t)(e),Bd=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?ta(Uo)(t):t,n={...e,cGraph:Dd(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);c()},ea=t=>e=>n=>{const r=Yt(t)(n.cNodes),i=Yt(e)(n.cGroups);return r.tag==="Just"&&i.tag==="Just"?(()=>{if(r._1.cGroup.tag==="Nothing")return!1;if(r._1.cGroup.tag==="Just")return!0;c()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:K(nt)(t)({...r._1,cGroup:L("Just",e)})(n.cNodes),cGroups:K(nt)(e)({...i._1,cNodes:ke(_r)(t)(i._1.cNodes)?i._1.cNodes:[...i._1.cNodes,t],reference:(()=>{if(i._1.reference.tag==="Nothing")return L("Just",t);if(i._1.reference.tag==="Just")return L("Just",i._1.reference._1);c()})()})(n.cGroups)}:n},na=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:K(nt)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:T,cGroupOffset:Sd,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),Xo=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:J(r=>i=>ea(i)(n)(r))({...e,cGroups:K(nt)(n)({id:n,master:t.master,cNodes:[],startPos:-1e308,incomingConstraints:[],outDegree:0,outDegreeReal:0,reference:T,delta:0,deltaNormalized:0})(e.cGroups),cGroupOrder:[...e.cGroupOrder,n],nextCGroupId:n+1|0})(t.nodes)}},Md=t=>J(e=>n=>{const r=Yt(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?Xo({master:T,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),$d=t=>({cGraph:Qd(Md(Yo(t))),direction:js,compactionAlgorithm:T,constraintAlgorithm:T,spacingsHandler:Id,lockFun:T,finished:!1}),pi=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},ra=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},zd=t=>e=>n=>r=>i=>({id:t,representedEdges:[i],affectedBends:[e,n],hitbox:{x:pi(e._1)(n._1),y:pi(e._2)(n._2),width:On(e._1-n._1),height:On(e._2-n._2)},ignoreSpacing:Ad,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];c()})(),aPort:T}),Od=t=>e=>{const n=pi(t.hitbox.x)(e.hitbox.x),r=pi(t.hitbox.y)(e.hitbox.y);return{...t,representedEdges:[...t.representedEdges,...e.representedEdges],affectedBends:[...t.affectedBends,...e.affectedBends],potentialGroupParents:[...t.potentialGroupParents,...e.potentialGroupParents],hitbox:{x:n,y:r,width:ra(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:ra(t.hitbox.y+t.hitbox.height)(e.hitbox.y+e.hitbox.height)-r},ignoreSpacing:{left:t.ignoreSpacing.left||e.ignoreSpacing.left,right:t.ignoreSpacing.right||e.ignoreSpacing.right,up:t.ignoreSpacing.up||e.ignoreSpacing.up,down:t.ignoreSpacing.down||e.ignoreSpacing.down},aPort:(()=>{if(t.aPort.tag==="Just")return t.aPort;if(t.aPort.tag==="Nothing")return e.aPort;c()})()}},qd=t=>e=>On(t.hitbox.x-e.hitbox.x)<=1e-4&&e.hitbox.y-(t.hitbox.y+t.hitbox.height)<=1e-4&&t.hitbox.y-(e.hitbox.y+e.hitbox.height)<=1e-4,Hd=t=>e=>On(t.hitbox.x-e.hitbox.x)<=1e-4?dt.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?me:Ne,ia=(t,e)=>({tag:t,_1:e}),en=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Wd=J(t=>e=>K(Gd)(e)()(t))(M),oa=Vt(C)(Dt),Ko=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Vd=t=>xt(e=>{if(e.direction==="V")return L("Just",{start:e.start,end:e.end});if(e.direction==="H")return T;c()})(t.segments),ua=t=>e=>n=>{if(n.tag==="Just"){const r=en(e)(t);if(r.tag==="Just"){const i=ge(o=>o.id===n._1)(r._1);if(i.tag==="Just")return i._1.side;if(i.tag==="Nothing")return Oe;c()}if(r.tag==="Nothing")return Oe;c()}if(n.tag==="Nothing")return Oe;c()},Ud=t=>e=>{const n=na({origin:L("Just",ia("SegmentOrigin",e)),kind:L("Just","vs"),hitbox:e.hitbox})(t.cGraph);return{...t,cGraph:(()=>{if(0<e.potentialGroupParents.length){const r=Yt(e.potentialGroupParents[0])(n.graph.cNodes);if(r.tag==="Just"){if(r._1.cGroup.tag==="Just")return ea(n.id)(r._1.cGroup._1)(n.graph);if(r._1.cGroup.tag==="Nothing")return n.graph;c()}if(r.tag==="Nothing")return n.graph;c()}return Xo({master:L("Just",n.id),nodes:[n.id]})(n.graph).graph})(),edgeToCs:J(r=>i=>Tt(C)(ue)(i)([n.id])(r))(t.edgeToCs)(e.representedEdges)}},Yd=t=>e=>{const n=Bt(r=>T,r=>i=>L("Just",{head:r,tail:i}),vt(Hd)(t));if(n.tag==="Nothing")return e;if(n.tag==="Just"){const r=J(i=>o=>qd(i.survivor)(o)?{...i,survivor:Od(i.survivor)(o)}:{survivor:o,merged:[...i.merged,i.survivor]})({survivor:n._1.head,merged:[]})(n._1.tail);return J(Ud)(e)([...r.merged,r.survivor])}c()},Xd=t=>({cGraph:{cNodes:M,cNodeOrder:[],cGroups:M,cGroupOrder:[],supportedDirections:Wd([js,Uo,Ed]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:M,edgeToCs:M}),Kd=t=>e=>J(n=>r=>{const i=na({origin:L("Just",ia("NodeOrigin",r.node)),kind:T,hitbox:{x:r.position._1,y:r.position._2,width:r.size._1,height:r.size._2}})(n.cGraph);return{...n,cGraph:Xo({master:L("Just",i.id),nodes:[i.id]})(i.graph).graph,nodeToC:K(C)(r.node)(i.id)(n.nodeToC)}})(e)(t),jd=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?K(C)(n.origin._1._1)(n.hitbox.x)(e):e)(M)(xt(e=>Yt(e)(t.cNodes))(t.cNodeOrder)),Zd=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?K(C)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(M)(xt(e=>Yt(e)(t.cNodes))(t.cNodeOrder)),tl=t=>J(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return J(i=>o=>K(C)(o)(r)(i))(e)(n.origin._1._1.representedEdges)}return e})(M)(xt(e=>Yt(e)(t.cNodes))(t.cNodeOrder)),sa=t=>{const e=oa(O(n=>w(n.id,n))(t.edges));return xt(n=>{const r=Ko(n.edge)(e);if(r.tag==="Just")return L("Just",{edgeId:n.edge,src:r._1.from.node,tgt:r._1.to.node,srcSide:ua(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:ua(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return T;c()})(t.paths)},el=t=>e=>{const n=xt(r=>{if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return T;const i=en(r.src)(t.nodeToC);if(i.tag==="Just"){const o=en(r.tgt)(t.nodeToC);if(o.tag==="Just"){const u=Yt(i._1)(t.cGraph.cNodes);if(u.tag==="Just"){const s=Yt(o._1)(t.cGraph.cNodes);if(s.tag==="Just"){if(u._1.cGroup.tag==="Just"){if(s._1.cGroup.tag==="Just")return L("Just",{srcGroup:u._1.cGroup._1,tgtGroup:s._1.cGroup._1,delta:0,weight:100});if(s._1.cGroup.tag==="Nothing")return T;c()}if(u._1.cGroup.tag==="Nothing")return T;c()}if(s.tag==="Nothing")return T;c()}if(u.tag==="Nothing")return T;c()}if(o.tag==="Nothing")return T;c()}if(i.tag==="Nothing")return T;c()})(e);return{sameEdgeVerticalSegments:r=>i=>r.origin.tag==="Just"&&r.origin._1.tag==="SegmentOrigin"&&i.origin.tag==="Just"&&i.origin._1.tag==="SegmentOrigin"&&(()=>{const o=i.origin._1._1;return Ze(u=>ke(ze)(u)(o.representedEdges),r.origin._1._1.representedEdges)})(),vsLNodePair:r=>i=>r.origin.tag==="Just"&&i.origin.tag==="Just"&&(r.origin._1.tag==="SegmentOrigin"?i.origin._1.tag==="NodeOrigin":r.origin._1.tag==="NodeOrigin"&&i.origin._1.tag==="SegmentOrigin"),edgeLengthEdges:r=>n}},nl=t=>e=>n=>r=>i=>o=>{const u=o._1===0,s=zd(i.nextId)(o._2.start)(o._2.end)(u&&(t.srcSide==="North"||t.srcSide==="South")?en(t.src)(M):T)(t.edgeId),a=(()=>{if(u){if(t.srcSide==="North")return{...s,aPort:L("Just",{node:t.src,side:se})};if(t.srcSide==="South")return{...s,aPort:L("Just",{node:t.src,side:ae})};if(e.tag==="Nothing")return s;if(e.tag==="Just")return s.hitbox.y>=e._1.y&&s.hitbox.y+s.hitbox.height<=e._1.y+e._1.height?{...s,ignoreSpacing:{...s.ignoreSpacing,up:!0,down:!0}}:s;c()}return s})();return{nextId:i.nextId+1|0,segments:[...i.segments,(()=>{if(o._1===r){if(n.tag==="Nothing")return a;if(n.tag==="Just")return a.hitbox.y>=n._1.y&&a.hitbox.y+a.hitbox.height<=n._1.y+n._1.height?{...a,ignoreSpacing:{...a.ignoreSpacing,up:!0,down:!0}}:a;c()}return a})()]}},rl=t=>e=>n=>{const r=Vd(n.path);return J(nl(n)((()=>{const i=en(n.src)(t.nodeToC);if(i.tag==="Just"){const o=Yt(i._1)(t.cGraph.cNodes);return o.tag==="Just"?L("Just",o._1.hitbox):T}if(i.tag==="Nothing")return T;c()})())((()=>{const i=en(n.tgt)(t.nodeToC);if(i.tag==="Just"){const o=Yt(i._1)(t.cGraph.cNodes);return o.tag==="Just"?L("Just",o._1.hitbox):T}if(i.tag==="Nothing")return T;c()})())(r.length-1|0))(e)(At(i=>o=>w(i,o))(r))},il=t=>e=>Yd(J(rl(e))({nextId:0,segments:[]})(t).segments)(e),ol=t=>il(sa(t))(Kd(t.nodes)(Xd())),ul=t=>e=>{const n=jd(t),r=Zd(t),i=oa(O(u=>w(u.id,w(u.from.node,u.to.node)))(e.edges)),o=tl(t);return{nodes:O(u=>{const s=en(u.node)(n);if(s.tag==="Just")return{...u,position:w(s._1,u.position._2)};if(s.tag==="Nothing")return u;c()})(e.nodes),edges:O(u=>({...u,bends:(()=>{const s=u.edge;return O(a=>{const f=Ko(s)(o);if(f.tag==="Just")return w(a._1+f._1,a._2);if(f.tag==="Nothing")return a;c()})(u.bends)})(),segments:(()=>{const s=Ko(u.edge)(i);if(s.tag==="Nothing")return u.segments;if(s.tag==="Just"){const a=en(s._1._1)(r),f=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()})()*ot(4),g=en(s._1._2)(r),d=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;c()})()*ot(4),l=Bt(_=>T,_=>h=>L("Just",{head:_,tail:h}),u.segments);if(l.tag==="Nothing")return u.segments;if(l.tag==="Just"){const _={...l._1.head,start:w(l._1.head.start._1+f,l._1.head.start._2)},h=Vu(l._1.tail);if(h.tag==="Nothing")return[{..._,end:w(_.end._1+d,_.end._2)}];if(h.tag==="Just")return[_,...oe(h._1.init)({...h._1.last,end:w(h._1.last.end._1+d,h._1.last.end._2)})]}}c()})()}))(e.paths)}},nn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},jo=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Zo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},sl=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},al=t=>{const e=t.Eq0();return n=>r=>{const i=s=>{let a=s,f=!0,g;for(;f;){const d=a,l=Bt(_=>T,_=>h=>L("Just",{head:_,tail:h}),d.queue);if(l.tag==="Nothing"){f=!1,g=d;continue}if(l.tag==="Just"){const _=l._1.head;if((p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=!1;continue}if(x.tag==="Node"){const v=t.compare(_)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=!0;continue}}c()}return y})(d.removedNodes)){a={...d,queue:l._1.tail};continue}const h=ge(p=>!nn(p.eid)(d.removedEdges)&&(e.eq(p.src)(_)||e.eq(p.tgt)(_)))(r);if(h.tag==="Nothing"){a={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const p=e.eq(h._1.src)(_)?h._1.tgt:h._1.src,m={...d,degree:K(t)(p)((()=>{const N=(y=>{let x=y,v=!0,b;for(;v;){const E=x;if(E.tag==="Leaf"){v=!1,b=T;continue}if(E.tag==="Node"){const k=t.compare(p)(E._3);if(k==="LT"){x=E._5;continue}if(k==="GT"){x=E._6;continue}if(k==="EQ"){v=!1,b=L("Just",E._4);continue}}c()}return b})(d.degree);if(N.tag==="Nothing")return-1;if(N.tag==="Just")return N._1-1|0;c()})())(d.degree),removedNodes:K(t)(_)()(d.removedNodes),removedEdges:K(nt)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:_,neighbour:p,viaSrc:e.eq(h._1.src)(_)}],queue:l._1.tail};if((()=>{const N=(x=>{let v=x,b=!0,E;for(;b;){const k=v;if(k.tag==="Leaf"){b=!1,E=T;continue}if(k.tag==="Node"){const F=t.compare(p)(k._3);if(F==="LT"){v=k._5;continue}if(F==="GT"){v=k._6;continue}if(F==="EQ"){b=!1,E=L("Just",k._4);continue}}c()}return E})(m.degree),y=x=>{let v=x,b=!0,E;for(;b;){const k=v;if(k.tag==="Leaf"){b=!1,E=!1;continue}if(k.tag==="Node"){const F=t.compare(p)(k._3);if(F==="LT"){v=k._5;continue}if(F==="GT"){v=k._6;continue}if(F==="EQ"){b=!1,E=!0;continue}}c()}return E};return(()=>{if(N.tag==="Nothing")return!1;if(N.tag==="Just")return N._1===1;c()})()&&!y(m.removedNodes)})()){a={...m,queue:[...m.queue,p]};continue}a=m;continue}}c()}return g},o=J(s=>a=>Tt(t)(Zt)(a.src)(1)(Tt(t)(Zt)(a.tgt)(1)(s)))(M)(r),u=i({degree:o,removedNodes:M,removedEdges:M,record:[],queue:ct(s=>{const a=(f=>{let g=f,d=!0,l;for(;d;){const _=g;if(_.tag==="Leaf"){d=!1,l=T;continue}if(_.tag==="Node"){const h=t.compare(s)(_._3);if(h==="LT"){g=_._5;continue}if(h==="GT"){g=_._6;continue}if(h==="EQ"){d=!1,l=L("Just",_._4);continue}}c()}return l})(o);if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1===1;c()},n)});return{coreNodes:ct(s=>!(a=>{let f=a,g=!0,d;for(;g;){const l=f;if(l.tag==="Leaf"){g=!1,d=!1;continue}if(l.tag==="Node"){const _=t.compare(s)(l._3);if(_==="LT"){f=l._5;continue}if(_==="GT"){f=l._6;continue}if(_==="EQ"){g=!1,d=!0;continue}}c()}return d})(u.removedNodes),n),coreEdges:ct(s=>!nn(s.eid)(u.removedEdges),r),removed:u.record}}},cl=t=>e=>n=>J(r=>i=>{const o=i.neighbour,u=(()=>{const s=(a=>{let f=a,g=!0,d;for(;g;){const l=f;if(l.tag==="Leaf"){g=!1,d=T;continue}if(l.tag==="Node"){const _=t.compare(o)(l._3);if(_==="LT"){f=l._5;continue}if(_==="GT"){f=l._6;continue}if(_==="EQ"){g=!1,d=L("Just",l._4);continue}}c()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})();return K(t)(i.node)(i.viaSrc?u-1|0:u+1|0)(r)})(n)(de(e)),tu=t=>{const e=t.Eq0();return n=>r=>i=>{const o={...i,treeNode:K(t)(r)()(i.treeNode)};return J(u=>s=>{if(nn(s.eid)(u.st.edgeVisited))return u;const a={...u.st,edgeVisited:K(nt)(s.eid)()(u.st.edgeVisited)},f=e.eq(s.src)((()=>{const g=s.src,d=_=>{let h=_,p=!0,m;for(;p;){const N=h;if(N.tag==="Leaf"){p=!1,m=!1;continue}if(N.tag==="Node"){const y=t.compare(g)(N._3);if(y==="LT"){h=N._5;continue}if(y==="GT"){h=N._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}c()}return m},l=s.tgt;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const N=h;if(N.tag==="Leaf"){p=!1,m=!1;continue}if(N.tag==="Node"){const y=t.compare(l)(N._3);if(y==="LT"){h=N._5;continue}if(y==="GT"){h=N._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}c()}return m})(a.treeNode)})()?s.src:(()=>{const g=s.tgt,d=_=>{let h=_,p=!0,m;for(;p;){const N=h;if(N.tag==="Leaf"){p=!1,m=!1;continue}if(N.tag==="Node"){const y=t.compare(g)(N._3);if(y==="LT"){h=N._5;continue}if(y==="GT"){h=N._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}c()}return m},l=s.src;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const N=h;if(N.tag==="Leaf"){p=!1,m=!1;continue}if(N.tag==="Node"){const y=t.compare(l)(N._3);if(y==="LT"){h=N._5;continue}if(y==="GT"){h=N._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}c()}return m})(a.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(nn(s.eid)(a.treeEdge)){if((d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=!1;continue}if(p.tag==="Node"){const m=t.compare(f)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=!0;continue}}c()}return h})(a.treeNode))return{...u,st:a};const g=tu(t)(n)(f)(a);return{count:u.count+g.count|0,st:g.st}}if((()=>{const g=l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=!1;continue}if(m.tag==="Node"){const N=t.compare(f)(m._3);if(N==="LT"){_=m._5;continue}if(N==="GT"){_=m._6;continue}if(N==="EQ"){h=!1,p=!0;continue}}c()}return p},d=s.tgt;return!g(a.treeNode)&&(()=>{const l=(p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=T;continue}if(x.tag==="Node"){const v=t.compare(d)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=L("Just",x._4);continue}}c()}return y})(a.layer),_=s.src,h=(p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=T;continue}if(x.tag==="Node"){const v=t.compare(_)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=L("Just",x._4);continue}}c()}return y})(a.layer);if(l.tag==="Nothing"){if(h.tag==="Nothing")return s.delta===0;if(h.tag==="Just")return s.delta===-h._1;c()}if(l.tag==="Just"){if(h.tag==="Nothing")return s.delta===(l._1-0|0);if(h.tag==="Just")return s.delta===(l._1-h._1|0)}c()})()})()){const g=tu(t)(n)(f)({...a,treeEdge:K(nt)(s.eid)()(a.treeEdge)});return{count:u.count+g.count|0,st:g.st}}return{...u,st:a}})({count:1,st:o})(ct(u=>(e.eq(u.src)(r)||e.eq(u.tgt)(r))&&!nn(u.eid)(o.edgeVisited),n))}},mi=t=>e=>n=>r=>{const i=r.src,o=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=T;continue}if(m.tag==="Node"){const N=t.compare(i)(m._3);if(N==="LT"){_=m._5;continue}if(N==="GT"){_=m._6;continue}if(N==="EQ"){h=!1,p=L("Just",m._4);continue}}c()}return p})(e.poID),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;c()})(),s=r.tgt,a=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=T;continue}if(m.tag==="Node"){const N=t.compare(s)(m._3);if(N==="LT"){_=m._5;continue}if(N==="GT"){_=m._6;continue}if(N==="EQ"){h=!1,p=L("Just",m._4);continue}}c()}return p})(e.poID),f=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()})(),g=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=T;continue}if(m.tag==="Node"){const N=t.compare(n)(m._3);if(N==="LT"){_=m._5;continue}if(N==="GT"){_=m._6;continue}if(N==="EQ"){h=!1,p=L("Just",m._4);continue}}c()}return p})(e.poID),d=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;c()})();return(()=>{const l=r.src,_=(h=>{let p=h,m=!0,N;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,N=T;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,N=L("Just",y._4);continue}}c()}return N})(e.lowestPoID);return(()=>{if(_.tag==="Nothing")return 0<=d;if(_.tag==="Just")return _._1<=d;c()})()&&(()=>{const h=r.tgt;return d<=u&&(()=>{const p=(m=>{let N=m,y=!0,x;for(;y;){const v=N;if(v.tag==="Leaf"){y=!1,x=T;continue}if(v.tag==="Node"){const b=t.compare(h)(v._3);if(b==="LT"){N=v._5;continue}if(b==="GT"){N=v._6;continue}if(b==="EQ"){y=!1,x=L("Just",v._4);continue}}c()}return x})(e.lowestPoID);return(()=>{if(p.tag==="Nothing")return 0<=d;if(p.tag==="Just")return p._1<=d;c()})()&&d<=f})()})()})()?u>=f:u<f},fl=t=>{const e=Vt(t)(Dt);return n=>({layer:e(O(r=>w(r,0))(n)),treeNode:M,treeEdge:M,poID:M,lowestPoID:M,cutvalue:M,postOrder:1,edgeVisited:M})},gl=t=>e=>n=>J(r=>i=>{if((()=>{const g=i.src,d=h=>{let p=h,m=!0,N;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,N=!1;continue}if(y.tag==="Node"){const x=t.compare(g)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,N=!0;continue}}c()}return N},l=i.tgt,_=h=>{let p=h,m=!0,N;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,N=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,N=!0;continue}}c()}return N};return d(n.treeNode)===_(n.treeNode)})())return r;const o=i.tgt,u=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const p=t.compare(o)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=L("Just",h._4);continue}}c()}return _})(n.layer),s=i.src,a=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const p=t.compare(s)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=L("Just",h._4);continue}}c()}return _})(n.layer),f=(()=>{if(u.tag==="Nothing"){if(a.tag==="Nothing")return-i.delta;if(a.tag==="Just")return-a._1-i.delta|0;c()}if(u.tag==="Just"){if(a.tag==="Nothing")return(u._1-0|0)-i.delta|0;if(a.tag==="Just")return(u._1-a._1|0)-i.delta|0}c()})();return f<r.slack?{edge:L("Just",i),slack:f}:r})({edge:T,slack:1e9})(e).edge,_l=t=>{const e=Vt(t)(Dt);return n=>r=>{const i=J(o=>u=>jo(o)((()=>{const s=(a=>{let f=a,g=!0,d;for(;g;){const l=f;if(l.tag==="Leaf"){g=!1,d=T;continue}if(l.tag==="Node"){const _=t.compare(u)(l._3);if(_==="LT"){f=l._5;continue}if(_==="GT"){f=l._6;continue}if(_==="EQ"){g=!1,d=L("Just",l._4);continue}}c()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(1e9)(n);return e(O(o=>w(o,(()=>{const u=(s=>{let a=s,f=!0,g;for(;f;){const d=a;if(d.tag==="Leaf"){f=!1,g=T;continue}if(d.tag==="Node"){const l=t.compare(o)(d._3);if(l==="LT"){a=d._5;continue}if(l==="GT"){a=d._6;continue}if(l==="EQ"){f=!1,g=L("Just",d._4);continue}}c()}return g})(r);if(u.tag==="Nothing")return-i;if(u.tag==="Just")return u._1-i|0;c()})()))(n))}},aa=t=>{const e=t.Eq0();return n=>r=>i=>{const o=J(s=>a=>{const f=aa(t)(n)(e.eq(a.src)(r)?a.tgt:a.src)({...s.st,edgeVisited:K(nt)(a.eid)()(s.st.edgeVisited)});return{lowest:jo(s.lowest)(f.lowest),st:f.st}})({lowest:1e9,st:i})(ct(s=>nn(s.eid)(i.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!nn(s.eid)(i.edgeVisited),n)),u=jo(o.lowest)(o.st.postOrder);return{lowest:u,st:{...o.st,poID:K(t)(r)(o.st.postOrder)(o.st.poID),lowestPoID:K(t)(r)(u)(o.st.lowestPoID),postOrder:o.st.postOrder+1|0}}}},ca=t=>{const e=aa(t);return n=>r=>i=>0<n.length?e(r)(n[0])({...i,edgeVisited:M,postOrder:1,poID:M,lowestPoID:M}).st:i},dl=t=>{const e=t.Eq0();return n=>r=>i=>ct(o=>nn(o.eid)(r.treeEdge)&&(e.eq(o.src)(i)||e.eq(o.tgt)(i)),n)},ll=t=>e=>ge(n=>{const r=Zo(n.eid)(e.cutvalue);return nn(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;c()})()})(t),fa=t=>{const e=tu(t);return n=>r=>i=>{const o=0<n.length?L("Just",n[0]):T;if(o.tag==="Nothing")return i;if(o.tag==="Just"){const u=e(r)(o._1)({...i,edgeVisited:M,treeNode:M,treeEdge:M});if(u.count>=n.length)return u.st;const s=gl(t)(r)(u.st);if(s.tag==="Nothing")return u.st;if(s.tag==="Just"){const a=s._1.tgt,f=(h=>{let p=h,m=!0,N;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,N=T;continue}if(y.tag==="Node"){const x=t.compare(a)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,N=L("Just",y._4);continue}}c()}return N})(u.st.layer),g=s._1.src,d=(h=>{let p=h,m=!0,N;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,N=T;continue}if(y.tag==="Node"){const x=t.compare(g)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,N=L("Just",y._4);continue}}c()}return N})(u.st.layer),l=(()=>{if(f.tag==="Nothing"){if(d.tag==="Nothing")return-s._1.delta;if(d.tag==="Just")return-d._1-s._1.delta|0;c()}if(f.tag==="Just"){if(d.tag==="Nothing")return(f._1-0|0)-s._1.delta|0;if(d.tag==="Just")return(f._1-d._1|0)-s._1.delta|0}c()})(),_=(()=>{const h=s._1.tgt;return(p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=!1;continue}if(x.tag==="Node"){const v=t.compare(h)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=!0;continue}}c()}return y})(u.st.treeNode)})()?-l:l;return fa(t)(n)(r)({...u.st,layer:J(h=>p=>(m=>{let N=m,y=!0,x;for(;y;){const v=N;if(v.tag==="Leaf"){y=!1,x=!1;continue}if(v.tag==="Node"){const b=t.compare(p)(v._3);if(b==="LT"){N=v._5;continue}if(b==="GT"){N=v._6;continue}if(b==="EQ"){y=!1,x=!0;continue}}c()}return x})(u.st.treeNode)?K(t)(p)((()=>{const m=(N=>{let y=N,x=!0,v;for(;x;){const b=y;if(b.tag==="Leaf"){x=!1,v=T;continue}if(b.tag==="Node"){const E=t.compare(p)(b._3);if(E==="LT"){y=b._5;continue}if(E==="GT"){y=b._6;continue}if(E==="EQ"){x=!1,v=L("Just",b._4);continue}}c()}return v})(u.st.layer);if(m.tag==="Nothing")return 0+_|0;if(m.tag==="Just")return m._1+_|0;c()})())(h):h)(u.st.layer)(n)})}}c()}},hl=t=>e=>n=>r=>J(i=>o=>{if(mi(t)(r)(o.src)(n)&&!mi(t)(r)(o.tgt)(n)){const u=o.tgt,s=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=T;continue}if(p.tag==="Node"){const m=t.compare(u)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=L("Just",p._4);continue}}c()}return h})(r.layer),a=o.src,f=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=T;continue}if(p.tag==="Node"){const m=t.compare(a)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=L("Just",p._4);continue}}c()}return h})(r.layer),g=(()=>{if(s.tag==="Nothing"){if(f.tag==="Nothing")return-o.delta;if(f.tag==="Just")return-f._1-o.delta|0;c()}if(s.tag==="Just"){if(f.tag==="Nothing")return(s._1-0|0)-o.delta|0;if(f.tag==="Just")return(s._1-f._1|0)-o.delta|0}c()})();if(g<i.slack)return{edge:L("Just",o),slack:g}}return i})({edge:T,slack:1e9})(e).edge,pl=t=>{const e=t.Eq0();return n=>r=>i=>o=>{const u=o.tgt,s=o.src;return J(a=>f=>{if((()=>{const g=Zo(f.eid)(r.cutvalue);if(g.tag==="Just")return!0;if(g.tag==="Nothing")return!1;c()})()){const g=Zo(f.eid)(r.cutvalue),d=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;c()})();return e.eq(s)(f.src)||e.eq(u)(f.tgt)?a-(d-f.weight):a+(d-f.weight)}return e.eq(i)(s)?e.eq(f.src)(i)?a+f.weight:a-f.weight:e.eq(f.src)(i)?a-f.weight:a+f.weight})(o.weight)(ct(a=>a.eid!==o.eid&&(e.eq(a.src)(i)||e.eq(a.tgt)(i)),n))}},ml=t=>{const e=pl(t);return n=>r=>i=>{const o=(u,s,a)=>{const f=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const p=t.compare(u)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=L("Just",h._4);continue}}c()}return _})(a);if(f.tag==="Just")return K(t)(u)(ct(g=>g.eid!==s.eid,f._1))(a);if(f.tag==="Nothing")return a;c()};return(u=>s=>{let a=u,f=s,g=!0,d;for(;g;){const l=a,_=f,h=(m=>{let N=m,y=!0,x;for(;y;){const v=N;if(v.tag==="Leaf"){y=!1,x=T;continue}if(v.tag==="Node"){const b=t.compare(_)(v._3);if(b==="LT"){N=v._5;continue}if(b==="GT"){N=v._6;continue}if(b==="EQ"){y=!1,x=L("Just",v._4);continue}}c()}return x})(l.unknown),p=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;c()})();if(p.length===1){const m=t.Eq0().eq(p[0].src)(_)?p[0].tgt:p[0].src;a={unknown:o(_,p[0],o(m,p[0],l.unknown)),cutvalue:K(nt)(p[0].eid)(e(n)(l)(_)(p[0]))(l.cutvalue)},f=m;continue}g=!1,d=l}return d})(r)(i)}},ga=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:f=>g=>f.delta===g.delta&&f.eid===g.eid&&n.eq(f.src)(g.src)&&e.eq(f.tgt)(g.tgt)&&f.weight===g.weight},i={compare:f=>g=>{const d=nt.compare(f.delta)(g.delta);if(d==="LT"||d==="GT"||d!=="EQ")return d;const l=nt.compare(f.eid)(g.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const _=t.compare(f.src)(g.src);if(_==="LT"||_==="GT"||_!=="EQ")return _;const h=t.compare(f.tgt)(g.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const p=dt.compare(f.weight)(g.weight);return p==="LT"||p==="GT"||p!=="EQ"?p:we},Eq0:()=>r},o=J(f=>g=>K(i)(g)()(f))(M),u=dl(t),s=Vt(t)(Dt),a=ml(t);return f=>g=>d=>{const l={unknown:s(O(_=>w(_,bt(Ge.foldr,o(u(g)(d)(_)))))(f)),cutvalue:M};return{...d,cutvalue:J(a(g))(l)(ct(_=>{const h=(p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=T;continue}if(x.tag==="Node"){const v=t.compare(_)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=L("Just",x._4);continue}}c()}return y})(l.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;c()},f)).cutvalue}}},Nl=t=>{const e=ca(t),n=ga(t);return r=>i=>o=>u=>s=>{const a={...s,treeEdge:K(nt)(u.eid)()(hr(nt)(o.eid)(s.treeEdge))},f=u.tgt,g=(p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=T;continue}if(x.tag==="Node"){const v=t.compare(f)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=L("Just",x._4);continue}}c()}return y})(a.layer),d=u.src,l=(p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=T;continue}if(x.tag==="Node"){const v=t.compare(d)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=L("Just",x._4);continue}}c()}return y})(a.layer),_=(()=>{if(g.tag==="Nothing"){if(l.tag==="Nothing")return-u.delta;if(l.tag==="Just")return-l._1-u.delta|0;c()}if(g.tag==="Just"){if(l.tag==="Nothing")return(g._1-0|0)-u.delta|0;if(l.tag==="Just")return(g._1-l._1|0)-u.delta|0}c()})(),h=mi(t)(a)(u.tgt)(o)?-_:_;return n(r)(i)(e(r)(i)({...a,layer:J(p=>m=>mi(t)(a)(m)(o)?p:K(t)(m)((()=>{const N=(y=>{let x=y,v=!0,b;for(;v;){const E=x;if(E.tag==="Leaf"){v=!1,b=T;continue}if(E.tag==="Node"){const k=t.compare(m)(E._3);if(k==="LT"){x=E._5;continue}if(k==="GT"){x=E._6;continue}if(k==="EQ"){v=!1,b=L("Just",E._4);continue}}c()}return b})(a.layer);if(N.tag==="Nothing")return 0+h|0;if(N.tag==="Just")return N._1+h|0;c()})())(p))(a.layer)(r)}))}},yl=t=>{const e=Nl(t);return n=>r=>i=>o=>(u=>s=>{let a=u,f=s,g=!0,d;for(;g;){const l=a,_=f;if(l===0){g=!1,d=_;continue}const h=ll(i)(_);if(h.tag==="Nothing"){g=!1,d=_;continue}if(h.tag==="Just"){const p=hl(t)(i)(h._1)(_);if(p.tag==="Nothing"){g=!1,d=_;continue}if(p.tag==="Just"){a=l-1|0,f=e(r)(i)(h._1)(p._1)(_);continue}}c()}return d})(n)(o)},Jl=t=>{const e=ga(t),n=ca(t),r=fa(t);return i=>o=>u=>e(i)(o)(n(i)(o)(r(i)(o)(u)))},_a=t=>e=>J(n=>r=>Tt(t)(ue)(e(r))([r])(n))(M),xl=t=>{const e=Vt(t)(Dt);return n=>r=>i=>{const o=a=>f=>g=>d=>{let l=a,_=f,h=g,p=d,m=!0,N;for(;m;){const y=l,x=_,v=h,b=p,E=Bt(k=>T,k=>F=>L("Just",{head:k,tail:F}),v);if(E.tag==="Nothing"){m=!1,N=b;continue}if(E.tag==="Just"){const k=E._1.head,F=(Q=>{let S=Q,Z=!0,V;for(;Z;){const R=S;if(R.tag==="Leaf"){Z=!1,V=T;continue}if(R.tag==="Node"){const $=t.compare(k)(R._3);if($==="LT"){S=R._5;continue}if($==="GT"){S=R._6;continue}if($==="EQ"){Z=!1,V=L("Just",R._4);continue}}c()}return V})(b.layer),U=(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;c()})(),tt=J(Q=>S=>{const Z=S.tgt,V=($=>{let I=$,G=!0,D;for(;G;){const P=I;if(P.tag==="Leaf"){G=!1,D=T;continue}if(P.tag==="Node"){const A=t.compare(Z)(P._3);if(A==="LT"){I=P._5;continue}if(A==="GT"){I=P._6;continue}if(A==="EQ"){G=!1,D=L("Just",P._4);continue}}c()}return D})(Q.incident),R=(()=>{if(V.tag==="Nothing")return-1;if(V.tag==="Just")return V._1-1|0;c()})();return{st:{...Q.st,layer:K(t)(S.tgt)(sl((()=>{const $=S.tgt,I=(G=>{let D=G,P=!0,A;for(;P;){const H=D;if(H.tag==="Leaf"){P=!1,A=T;continue}if(H.tag==="Node"){const Y=t.compare($)(H._3);if(Y==="LT"){D=H._5;continue}if(Y==="GT"){D=H._6;continue}if(Y==="EQ"){P=!1,A=L("Just",H._4);continue}}c()}return A})(Q.st.layer);if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;c()})())(U+S.delta|0))(Q.st.layer)},incident:K(t)(S.tgt)(R)(Q.incident),queue:R===0?[...Q.queue,S.tgt]:Q.queue}})({st:b,incident:x,queue:E._1.tail})((()=>{const Q=(S=>{let Z=S,V=!0,R;for(;V;){const $=Z;if($.tag==="Leaf"){V=!1,R=T;continue}if($.tag==="Node"){const I=t.compare(k)($._3);if(I==="LT"){Z=$._5;continue}if(I==="GT"){Z=$._6;continue}if(I==="EQ"){V=!1,R=L("Just",$._4);continue}}c()}return R})(y);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()})());l=y,_=tt.incident,h=tt.queue,p=tt.st;continue}c()}return N},u=_a(t)(a=>a.tgt)(r),s=e(O(a=>w(a,(()=>{const f=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=L("Just",h._4);continue}}c()}return _})(u);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.length;c()})()))(n));return o(_a(t)(a=>a.src)(r))(s)(ct(a=>{const f=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=L("Just",h._4);continue}}c()}return _})(s);if(f.tag==="Nothing")return!0;if(f.tag==="Just")return f._1===0;c()},n))(i)}},Tl=t=>{const e=fl(t),n=xl(t),r=Jl(t),i=yl(t);return o=>u=>{const s=n(o)(u)(e(o));return u.length===0?s.layer:i(4*o.length|0)(o)(u)(r(o)(u)(s)).layer}},da=t=>{const e=_l(t),n=Tl(t),r=al(t);return i=>o=>{if(i.length===0)return M;if(i.length<40)return e(i)(n(i)(o));const u=r(i)(o);return e(i)(cl(t)(u.removed)(n(u.coreNodes)(u.coreEdges)))}},la=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},eu=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},vl=da(nt),Sr=t=>e=>({...e,edges:[...e.edges,{src:t.src,tgt:t.tgt,delta:t.delta,weight:t.weight,eid:e.nextEid}],nextEid:e.nextEid+1|0}),wl=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=ot((()=>{const i=la(n.cGroup._1)(t);if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;c()})());return qe(n.id)(i=>({...i,hitbox:{...i.hitbox,x:r+i.cGroupOffset.x}}))(e)}c()},Ll=t=>e=>({...e,cGraph:J(wl(t))(e.cGraph)((()=>{const n=e.cGraph;return xt(r=>Yt(r)(n.cNodes))(n.cNodeOrder)})())}),bl=t=>e=>n=>r=>i=>{const o=vn(ji(e.cGroupOffset.x-t.cGroupOffset.x));return Sr({src:i.nextNodeId,tgt:r,delta:eu(0)(-o),weight:1})(Sr({src:i.nextNodeId,tgt:n,delta:eu(0)(o),weight:1})({...i,nodes:[...i.nodes,i.nextNodeId],nextNodeId:i.nextNodeId+1|0}))},El=t=>e=>n=>r=>i=>o=>u=>{const s=eu(0)(vn(ji(n.cGroupOffset.x+n.hitbox.width+(e.direction==="LEFT"||e.direction==="RIGHT"?e.spacingsHandler.horizontalSpacing(n)(r):e.spacingsHandler.verticalSpacing(n)(r))-r.cGroupOffset.x)));return t.sameEdgeVerticalSegments(n)(r)?bl(n)(r)(i)(o)(u):Sr({src:i,tgt:o,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(u)},kl=t=>e=>n=>r=>i=>{const o=Yt(i)(e.cGraph.cNodes);if(o.tag==="Nothing")return r;if(o.tag==="Just")return(n.cGroup.tag==="Nothing"?o._1.cGroup.tag==="Nothing":n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"&&n.cGroup._1===o._1.cGroup._1)?r:n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"?El(t)(e)(n)(o._1)(n.cGroup._1)(o._1.cGroup._1)(r):r;c()},Gl=t=>e=>n=>r=>J(kl(t)(e)(r))(n)(r.constraints),Cl=t=>e=>Sr({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),Sl=t=>{const e=J(i=>o=>Tt(nt)(Zt)(o.tgt)(1)(i))(M)(t.edges),n=ct(i=>{const o=la(i)(e);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return o._1===0;c()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return J(i=>o=>Sr({src:r,tgt:o,delta:1,weight:0})(i))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},Ql=t=>e=>{const n=Sl(J(Cl)(J(Gl(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return xt(i=>Yt(i)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},Pl=t=>e=>{const n=Ql(t)(e);return Ll(vl(n.nodes)(n.edges))(e)},Dl=t=>e=>n=>r=>e.id===r.id||e.cGroup.tag==="Just"&&r.cGroup.tag==="Just"&&e.cGroup._1===r.cGroup._1||!(r.hitbox.x>e.hitbox.x||e.hitbox.x===r.hitbox.x&&e.hitbox.width<r.hitbox.width)||(()=>{const i=t.direction==="LEFT"||t.direction==="RIGHT"?t.spacingsHandler.verticalSpacing(e)(r):t.spacingsHandler.horizontalSpacing(e)(r);return!(r.hitbox.y+r.hitbox.height+i-e.hitbox.y>1e-4&&e.hitbox.y+e.hitbox.height+i-r.hitbox.y>1e-4)})()?n:qe(e.id)(i=>({...i,constraints:[...i.constraints,r.id]}))(n),Al=t=>e=>n=>r=>J(Dl(t)(r))(n)(e),Il=t=>{const e=J(r=>i=>qe(i.id)(o=>({...o,constraints:[]}))(r))(t.cGraph)((()=>{const r=t.cGraph;return xt(i=>Yt(i)(r.cNodes))(r.cNodeOrder)})()),n=xt(r=>Yt(r)(e.cNodes))(e.cNodeOrder);return J(Al(t)(n))(e)(n)},ha=t=>t,Xt=ha("H"),Kt=ha("V"),Rl=t=>w(t._2,t._1),pa=t=>({...t,position:w(t.position._2,t.position._1),size:w(t.size._2,t.size._1)}),Fl=t=>({start:w(t.start._2,t.start._1),end:w(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return Kt;if(t.direction==="V")return Xt;c()})()}),ma=t=>({...t,segments:O(Fl)(t.segments),bends:O(Rl)(t.bends)}),Bl=t=>({nodes:O(pa)(t.nodes),edges:t.edges,paths:O(ma)(t.paths),ports:t.ports}),Ml={horizontalSpacing:t=>e=>1,verticalSpacing:t=>e=>1},$l=t=>e=>Pl(e),zl=t=>e=>{const n=Bl(e),r=ol(n),i=ul(ta(Uo)(Bd({...$d(r.cGraph),compactionAlgorithm:L("Just",$l()(el(r)(sa(n)))),constraintAlgorithm:L("Just",Il),spacingsHandler:Ml})).cGraph)({nodes:n.nodes,edges:n.edges,paths:n.paths});return{nodes:O(pa)(i.nodes),edges:O(ma)(i.edges)}},Na=t=>t,jn=Vt(nt)(Dt),wt=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},ya=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},ut=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},st=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},rn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Ol=t=>e=>{const n=nt.compare(t._1)(e._1);return n==="LT"?me:n==="GT"?Ne:nt.compare(t._2)(e._2)},Zn=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},ql=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),Hl=t=>t,Ni=Na("Regular"),yi=Na("Critical"),Ja=t=>e=>{const n=J(u=>s=>K(C)(s.node)(s)(u))(M)(e),r=1.25*ot(4),i=(u,s,a)=>(f=>g=>d=>{let l=f,_=g,h=d,p=!0,m;for(;p;){const N=l,y=_,x=h;if(x.critical){p=!1,m=x;continue}const v=Bt(E=>T,E=>k=>L("Just",{head:E,tail:k}),N),b=Bt(E=>T,E=>k=>L("Just",{head:E,tail:k}),y);if(v.tag==="Just"&&b.tag==="Just"){const E=v._1.head>b._1.head-u&&v._1.head<b._1.head+u?{...x,critical:!0}:v._1.head>b._1.head-r&&v._1.head<b._1.head+r?{...x,conflicts:x.conflicts+1|0}:x;if(E.critical){p=!1,m=E;continue}if(v._1.head<=b._1.head){l=v._1.tail,_=y,h=E;continue}l=N,_=b._1.tail,h=E;continue}p=!1,m=x}return m})(s)(a)({conflicts:0,critical:!1}),o=(u,s,a)=>{if(st(J(st)(-1e18)(s.incoming))(J(st)(-1e18)(s.outgoing))-ut(J(ut)(1e18)(s.incoming))(J(ut)(1e18)(s.outgoing))<.001||st(J(st)(-1e18)(a.incoming))(J(st)(-1e18)(a.outgoing))-ut(J(ut)(1e18)(a.incoming))(J(ut)(1e18)(a.outgoing))<.001)return[];const f=i(u,s.outgoing,a.incoming),g=i(u,a.outgoing,s.incoming);if(f.critical||g.critical)return[...f.critical?[{src:a.id,tgt:s.id,weight:1,kind:yi}]:[],...g.critical?[{src:s.id,tgt:a.id,weight:1,kind:yi}]:[]];const d=ut(J(ut)(1e18)(s.incoming))(J(ut)(1e18)(s.outgoing)),l=st(J(st)(-1e18)(s.incoming))(J(st)(-1e18)(s.outgoing)),_=ut(J(ut)(1e18)(a.incoming))(J(ut)(1e18)(a.outgoing)),h=st(J(st)(-1e18)(a.incoming))(J(st)(-1e18)(a.outgoing)),p=(1*f.conflicts|0)+(16*(J(N=>y=>y>h?N:y>=_?N+1|0:N)(0)(s.outgoing)+J(N=>y=>y>l?N:y>=d?N+1|0:N)(0)(a.incoming)|0)|0)|0,m=(1*g.conflicts|0)+(16*(J(N=>y=>y>l?N:y>=d?N+1|0:N)(0)(a.outgoing)+J(N=>y=>y>h?N:y>=_?N+1|0:N)(0)(s.incoming)|0)|0)|0;return p<m?[{src:s.id,tgt:a.id,weight:m-p|0,kind:Ni}]:p>m?[{src:a.id,tgt:s.id,weight:p-m|0,kind:Ni}]:p>0?[{src:s.id,tgt:a.id,weight:0,kind:Ni},{src:a.id,tgt:s.id,weight:0,kind:Ni}]:[]};return J(u=>s=>J(a=>f=>K(C)(f._1)(f._2)(a))(u)((()=>{const a=J(Q=>S=>{const Z=S.edge.from.node+"|"+(()=>{if(S.edge.from.port.tag==="Just")return S.edge.from.port._1;if(S.edge.from.port.tag==="Nothing")return"_auto_"+S.edge.id;c()})(),V=rn(Z)(Q.entries);if(V.tag==="Nothing")return{...Q,entries:K(C)(Z)({id:0,members:[S.edge.id],incoming:[S.fromPos._1],outgoing:[S.toPos._1],slot:0,mark:0,splitBy:T,splitPartner:T})(Q.entries),order:[...Q.order,Z]};if(V.tag==="Just")return{...Q,entries:K(C)(Z)({...V._1,members:[...V._1.members,S.edge.id],incoming:[...Tn(R=>R<S.fromPos._1)(V._1.incoming).init,S.fromPos._1,...Tn(R=>R<=S.fromPos._1)(V._1.incoming).rest],outgoing:[...Tn(R=>R<S.toPos._1)(V._1.outgoing).init,S.toPos._1,...Tn(R=>R<=S.toPos._1)(V._1.outgoing).rest]})(Q.entries)};c()})({entries:M,order:[]})(s._2),f=At(Q=>S=>({...S,id:Q}))(xt(Q=>rn(Q)(a.entries))(a.order));if(f.length===0)return[];const g=J(Q=>S=>Q.prev.tag==="Just"&&S-Q.prev._1<1e-9?Q:{prev:L("Just",S),out:[...Q.out,S]})({prev:T,out:[]})(vt(dt.compare)([...St(f)(Q=>Q.incoming),...St(f)(Q=>Q.outgoing)])).out,d=g.length<2?.2*r:.2*J(Q=>S=>{if(Q.prev.tag==="Nothing")return{prev:L("Just",S),mn:Q.mn};if(Q.prev.tag==="Just")return{prev:L("Just",S),mn:ut(Q.mn)(S-Q.prev._1)};c()})({prev:T,mn:1e18})(g).mn,l={segments:f,deps:(()=>{const Q=f.length;return St(St(Ht(0,Q-2|0))(S=>St(Ht(S+1|0,Q-1|0))(Z=>[w(S,Z)])))(S=>S._1>=0&&S._1<f.length?S._2>=0&&S._2<f.length?o(d,f[S._1],f[S._2]):[]:[])})()},_=ct(Q=>{if(Q.kind==="Critical")return!0;if(Q.kind==="Regular")return!1;c()},l.deps),h=(()=>{if(_.length<2)return l;const Q=jn((()=>{const $=l.segments;return O(I=>w(I.id,I.mark))((()=>{const I=$.length,G=P=>{let A=P,H=!0,Y;for(;H;){const W=A,q=ge(B=>{const j=wt(B)(W.inWeight);if(j.tag==="Nothing")return!0;if(j.tag==="Just")return j._1===0;c()})(W.remaining);if(q.tag==="Nothing"){H=!1,Y=W;continue}if(q.tag==="Just"){const B=q._1;A={...W,inWeight:J(j=>X=>Tt(nt)(Zt)(X.tgt)(-X.weight)(j))(W.inWeight)((()=>{const j=wt(B)(W.depsBySrc);if(j.tag==="Nothing")return[];if(j.tag==="Just")return j._1;c()})()),marks:K(nt)(B)(W.nextSource)(W.marks),nextSource:W.nextSource+1|0,outWeight:J(j=>X=>Tt(nt)(Zt)(X.src)(-X.weight)(j))(W.outWeight)((()=>{const j=wt(B)(W.depsByTgt);if(j.tag==="Nothing")return[];if(j.tag==="Just")return j._1;c()})()),remaining:ct(j=>j!==B,W.remaining)};continue}c()}return Y},D=P=>{let A=P,H=!0,Y;for(;H;){const W=A,q=ge(B=>{const j=wt(B)(W.outWeight);if(j.tag==="Nothing")return!0;if(j.tag==="Just")return j._1===0;c()})(W.remaining);if(q.tag==="Nothing"){H=!1,Y=W;continue}if(q.tag==="Just"){const B=q._1;A={...W,inWeight:J(j=>X=>Tt(nt)(Zt)(X.tgt)(-X.weight)(j))(W.inWeight)((()=>{const j=wt(B)(W.depsBySrc);if(j.tag==="Nothing")return[];if(j.tag==="Just")return j._1;c()})()),marks:K(nt)(B)(W.nextSink)(W.marks),nextSink:W.nextSink-1|0,outWeight:J(j=>X=>Tt(nt)(Zt)(X.src)(-X.weight)(j))(W.outWeight)((()=>{const j=wt(B)(W.depsByTgt);if(j.tag==="Nothing")return[];if(j.tag==="Just")return j._1;c()})()),remaining:ct(j=>j!==B,W.remaining)};continue}c()}return Y};return(P=>{let A=P,H=!0,Y;for(;H;){const W=G(D(A));if(W.remaining.length===0){H=!1,Y=O(q=>{const B=wt(q.id)(W.marks),j=(()=>{if(B.tag==="Nothing")return q.id;if(B.tag==="Just")return B._1;c()})();return{...q,mark:j<I?(j+I|0)+1|0:j}})($);continue}A=(()=>{const q=j=>{const X=wt(j)(W.outWeight),_t=wt(j)(W.inWeight);return(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;c()})()-(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;c()})()|0},B=vt(j=>X=>nt.compare(q(X))(q(j)))(W.remaining);if(0<B.length){const j=B[0];return{...W,inWeight:J(X=>_t=>Tt(nt)(Zt)(_t.tgt)(-_t.weight)(X))(W.inWeight)((()=>{const X=wt(j)(W.depsBySrc);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;c()})()),marks:K(nt)(j)(W.nextSource)(W.marks),nextSource:W.nextSource+1|0,outWeight:J(X=>_t=>Tt(nt)(Zt)(_t.src)(-_t.weight)(X))(W.outWeight)((()=>{const X=wt(j)(W.depsByTgt);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;c()})()),remaining:ct(X=>X!==j,W.remaining)}}return W})()}return Y})({remaining:O(P=>P.id)($),marks:M,inWeight:J(P=>A=>Tt(nt)(Zt)(A.tgt)(A.weight)(P))(M)(_),outWeight:J(P=>A=>Tt(nt)(Zt)(A.src)(A.weight)(P))(M)(_),depsBySrc:J(P=>A=>Tt(nt)(ue)(A.src)([A])(P))(M)(_),depsByTgt:J(P=>A=>Tt(nt)(ue)(A.tgt)([A])(P))(M)(_),nextSink:I-1|0,nextSource:I+1|0})})())})()),S=ct($=>{const I=wt($.src)(Q),G=wt($.tgt)(Q);return(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;c()})()>(()=>{if(G.tag==="Nothing")return 0;if(G.tag==="Just")return G._1;c()})()},_);if(S.length===0)return l;const Z=J($=>I=>{if(ke(_r)(I.src)($.decisions)||ke(_r)(I.tgt)($.decisions))return $;const G=wt(I.src)($.segMap),D=wt(I.tgt)($.segMap);if(G.tag==="Just"&&D.tag==="Just"){const P=(G._1.incoming.length+G._1.outgoing.length|0)>2&&(D._1.incoming.length+D._1.outgoing.length|0)<=2,A=P?D._1:G._1;return{decisions:[...$.decisions,A.id],segMap:K(nt)(A.id)({...A,splitBy:L("Just",P?G._1.id:D._1.id)})($.segMap)}}return $})({decisions:[],segMap:jn(O($=>w($.id,$))(l.segments))})(S),V=Z.segMap,R=J($=>I=>{const G=ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(I.outgoing)),D=st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(I.outgoing)),P=ct(q=>q.a.startPosition<=D&&q.a.endPosition>=G,At(q=>B=>({i:q,a:B}))($.freeAreas));if(P.length===0){const q={...I,incoming:vt(dt.compare)(I.incoming),outgoing:vt(dt.compare)([(G+D)/2]),splitPartner:L("Just",$.nextId)},B={id:$.nextId,incoming:vt(dt.compare)([(G+D)/2]),mark:0,members:I.members,outgoing:vt(dt.compare)(I.outgoing),slot:0,splitBy:T,splitPartner:L("Just",I.id)};return{segMap:K(nt)(B.id)(B)(K(nt)(q.id)(q)($.segMap)),freeAreas:$.freeAreas,nextId:$.nextId+1|0}}const A=0<P.length?L("Just",P[0]):T,H=(()=>{if(A.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(A.tag==="Just"){if(P.length===1)return A._1;const q=O(B=>({c:B,rating:(()=>{const j=(B.a.startPosition+B.a.endPosition)/2,X=[j],_t=[j],pt=J((()=>{const ht=$.segMap;return Lt=>Pt=>{const lt=wt(Pt.tgt)(ht);if(lt.tag==="Nothing")return Lt;if(lt.tag==="Just"){const Rt=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),mt=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),gt=ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(X)),it=(()=>{const Gt=st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(X)),Qt=J(Ft=>ie=>ie>mt?Ft:ie>=Rt?Ft+1|0:Ft)(0)(X)+J(Ft=>ie=>ie>Gt?Ft:ie>=gt?Ft+1|0:Ft)(0)(lt._1.incoming)|0,ar=ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(X)),In=st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(X)),Rn=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),cr=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),$e=J(Ft=>ie=>ie>In?Ft:ie>=ar?Ft+1|0:Ft)(0)(lt._1.outgoing)+J(Ft=>ie=>ie>cr?Ft:ie>=Rn?Ft+1|0:Ft)(0)(I.incoming)|0;return Qt===$e?Qt>0?{...Lt,deps:Lt.deps+2|0,crossings:Lt.crossings+Qt|0}:Lt:{...Lt,deps:Lt.deps+1|0,crossings:Lt.crossings+Zn(Qt)($e)|0}})(),rt=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),at=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),Nt=ut(J(ut)(1e18)(_t))(J(ut)(1e18)(I.outgoing)),yt=st(J(st)(-1e18)(_t))(J(st)(-1e18)(I.outgoing)),Ct=J(Gt=>Qt=>Qt>at?Gt:Qt>=rt?Gt+1|0:Gt)(0)(I.outgoing)+J(Gt=>Qt=>Qt>yt?Gt:Qt>=Nt?Gt+1|0:Gt)(0)(lt._1.incoming)|0,Ot=ut(J(ut)(1e18)(_t))(J(ut)(1e18)(I.outgoing)),re=st(J(st)(-1e18)(_t))(J(st)(-1e18)(I.outgoing)),je=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),sr=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),_n=J(Gt=>Qt=>Qt>re?Gt:Qt>=Ot?Gt+1|0:Gt)(0)(lt._1.outgoing)+J(Gt=>Qt=>Qt>sr?Gt:Qt>=je?Gt+1|0:Gt)(0)(_t)|0;return Ct===_n?Ct>0?{...it,deps:it.deps+2|0,crossings:it.crossings+Ct|0}:it:{...it,deps:it.deps+1|0,crossings:it.crossings+Zn(Ct)(_n)|0}}c()}})())(J((()=>{const ht=$.segMap;return Lt=>Pt=>{const lt=wt(Pt.src)(ht);if(lt.tag==="Nothing")return Lt;if(lt.tag==="Just"){const Rt=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),mt=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),gt=ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(X)),it=(()=>{const Gt=st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(X)),Qt=J(Ft=>ie=>ie>mt?Ft:ie>=Rt?Ft+1|0:Ft)(0)(X)+J(Ft=>ie=>ie>Gt?Ft:ie>=gt?Ft+1|0:Ft)(0)(lt._1.incoming)|0,ar=ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(X)),In=st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(X)),Rn=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),cr=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),$e=J(Ft=>ie=>ie>In?Ft:ie>=ar?Ft+1|0:Ft)(0)(lt._1.outgoing)+J(Ft=>ie=>ie>cr?Ft:ie>=Rn?Ft+1|0:Ft)(0)(I.incoming)|0;return Qt===$e?Qt>0?{...Lt,deps:Lt.deps+2|0,crossings:Lt.crossings+Qt|0}:Lt:{...Lt,deps:Lt.deps+1|0,crossings:Lt.crossings+Zn(Qt)($e)|0}})(),rt=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),at=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),Nt=ut(J(ut)(1e18)(_t))(J(ut)(1e18)(I.outgoing)),yt=st(J(st)(-1e18)(_t))(J(st)(-1e18)(I.outgoing)),Ct=J(Gt=>Qt=>Qt>at?Gt:Qt>=rt?Gt+1|0:Gt)(0)(I.outgoing)+J(Gt=>Qt=>Qt>yt?Gt:Qt>=Nt?Gt+1|0:Gt)(0)(lt._1.incoming)|0,Ot=ut(J(ut)(1e18)(_t))(J(ut)(1e18)(I.outgoing)),re=st(J(st)(-1e18)(_t))(J(st)(-1e18)(I.outgoing)),je=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),sr=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),_n=J(Gt=>Qt=>Qt>re?Gt:Qt>=Ot?Gt+1|0:Gt)(0)(lt._1.outgoing)+J(Gt=>Qt=>Qt>sr?Gt:Qt>=je?Gt+1|0:Gt)(0)(_t)|0;return Ct===_n?Ct>0?{...it,deps:it.deps+2|0,crossings:it.crossings+Ct|0}:it:{...it,deps:it.deps+1|0,crossings:it.crossings+Zn(Ct)(_n)|0}}c()}})())({crossings:0,deps:0})(ct(ht=>ht.tgt===I.id,l.deps)))(ct(ht=>ht.src===I.id,l.deps)),ft=(()=>{if(I.splitBy.tag==="Just")return wt(I.splitBy._1)($.segMap);if(I.splitBy.tag==="Nothing")return T;c()})();if(ft.tag==="Just")return{...pt,deps:pt.deps+2|0,crossings:(()=>{const ht=ut(J(ut)(1e18)(ft._1.incoming))(J(ut)(1e18)(ft._1.outgoing)),Lt=ut(J(ut)(1e18)(_t))(J(ut)(1e18)(I.outgoing)),Pt=st(J(st)(-1e18)(ft._1.incoming))(J(st)(-1e18)(ft._1.outgoing)),lt=st(J(st)(-1e18)(_t))(J(st)(-1e18)(I.outgoing)),Rt=ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(X));return pt.crossings+(()=>{const mt=ut(J(ut)(1e18)(ft._1.incoming))(J(ut)(1e18)(ft._1.outgoing)),gt=st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(X)),it=st(J(st)(-1e18)(ft._1.incoming))(J(st)(-1e18)(ft._1.outgoing));return((J(rt=>at=>at>Pt?rt:at>=ht?rt+1|0:rt)(0)(X)+J(rt=>at=>at>gt?rt:at>=Rt?rt+1|0:rt)(0)(ft._1.incoming)|0)+J(rt=>at=>at>lt?rt:at>=Lt?rt+1|0:rt)(0)(ft._1.outgoing)|0)+J(rt=>at=>at>it?rt:at>=mt?rt+1|0:rt)(0)(_t)|0})()|0})()};if(ft.tag==="Nothing")return pt;c()})()}))(P);return J(B=>j=>j.rating.crossings<B.rating.crossings||!(j.rating.crossings>B.rating.crossings)&&(j.rating.deps<B.rating.deps||!(j.rating.deps>B.rating.deps)&&j.c.a.size>B.c.a.size)?j:B)(0<q.length?q[0]:{c:A._1,rating:{crossings:1e6,deps:1e6}})(q).c}c()})(),Y={...I,incoming:vt(dt.compare)(I.incoming),outgoing:vt(dt.compare)([(H.a.startPosition+H.a.endPosition)/2]),splitPartner:L("Just",$.nextId)},W={id:$.nextId,incoming:vt(dt.compare)([(H.a.startPosition+H.a.endPosition)/2]),mark:0,members:I.members,outgoing:vt(dt.compare)(I.outgoing),slot:0,splitBy:T,splitPartner:L("Just",I.id)};return{segMap:K(nt)(W.id)(W)(K(nt)(Y.id)(Y)($.segMap)),freeAreas:(()=>{if(H.i>=0&&H.i<$.freeAreas.length){const q=Hu(jt,T,H.i,$.freeAreas),B=(()=>{if(q.tag==="Nothing")return $.freeAreas;if(q.tag==="Just")return q._1;c()})();if($.freeAreas[H.i].size/2<d)return B;const j=($.freeAreas[H.i].startPosition+$.freeAreas[H.i].endPosition)/2,X=j-d,_t=j+d;return[...H.i<1?[]:It(0,H.i,B),...$.freeAreas[H.i].startPosition<=X?[{startPosition:$.freeAreas[H.i].startPosition,endPosition:X,size:X-$.freeAreas[H.i].startPosition}]:[],..._t<=$.freeAreas[H.i].endPosition?[{startPosition:_t,endPosition:$.freeAreas[H.i].endPosition,size:$.freeAreas[H.i].endPosition-_t}]:[],...H.i<1?B:It(H.i,B.length,B)]}return $.freeAreas})(),nextId:$.nextId+1|0}})({segMap:V,freeAreas:(()=>{const $=vt(dt.compare)([...St(l.segments)(I=>I.incoming),...St(l.segments)(I=>I.outgoing)]);return xt(Hl)(ye(I=>G=>G-I>=2*d?L("Just",{startPosition:I+d,endPosition:G-d,size:G-I-2*d}):T,$,It(1,$.length,$)))})(),nextId:l.segments.length})(vt($=>I=>dt.compare(st(J(st)(-1e18)($.incoming))(J(st)(-1e18)($.outgoing))-ut(J(ut)(1e18)($.incoming))(J(ut)(1e18)($.outgoing)))(st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(I.outgoing))-ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(I.outgoing))))(xt($=>wt($)(V))(Z.decisions)));return{segments:(()=>{const $=(I,G)=>{if(I.tag==="Leaf")return G;if(I.tag==="Node")return $(I._5,Mt("Cons",I._4,$(I._6,G)));c()};return bt(Wt.foldr,$(R.segMap,qt))})(),deps:(()=>{const $=R.segMap,I=(P,A)=>{if(P.tag==="Leaf")return A;if(P.tag==="Node")return I(P._5,Mt("Cons",P._4,I(P._6,A)));c()},G=bt(Wt.foldr,I($,qt)),D=G.length;return[...St(St(Ht(0,D-2|0))(P=>St(Ht(P+1|0,D-1|0))(A=>[w(P,A)])))(P=>P._1>=0&&P._1<G.length?P._2>=0&&P._2<G.length?G[P._1].splitPartner.tag!=="Nothing"&&G[P._1].splitPartner.tag==="Just"&&G[P._1].splitPartner._1===G[P._2].id||G[P._2].splitPartner.tag!=="Nothing"&&G[P._2].splitPartner.tag==="Just"&&G[P._2].splitPartner._1===G[P._1].id?[]:o(d,G[P._1],G[P._2]):[]:[]),...St(G)(P=>P.splitBy.tag==="Just"&&P.splitPartner.tag==="Just"&&(()=>{const A=wt(P.splitPartner._1)($);if(A.tag==="Nothing")return!1;if(A.tag==="Just")return!0;c()})()&&(()=>{const A=wt(P.splitBy._1)($);if(A.tag==="Nothing")return!1;if(A.tag==="Just")return!0;c()})()?[{src:P.id,tgt:P.splitBy._1,weight:1,kind:yi},{src:P.splitBy._1,tgt:P.splitPartner._1,weight:1,kind:yi}]:[])]})()}})(),p=h.segments,m=p.length,N=Q=>{let S=Q,Z=!0,V;for(;Z;){const R=S,$=ge(I=>{const G=wt(I)(R.inWeight);if(G.tag==="Nothing")return!0;if(G.tag==="Just")return G._1===0;c()})(R.remaining);if($.tag==="Nothing"){Z=!1,V=R;continue}if($.tag==="Just"){const I=$._1;S={...R,inWeight:J(G=>D=>Tt(nt)(Zt)(D.tgt)(-D.weight)(G))(R.inWeight)((()=>{const G=wt(I)(R.depsBySrc);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()),marks:K(nt)(I)(R.nextSource)(R.marks),nextSource:R.nextSource+1|0,outWeight:J(G=>D=>Tt(nt)(Zt)(D.src)(-D.weight)(G))(R.outWeight)((()=>{const G=wt(I)(R.depsByTgt);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()),remaining:ct(G=>G!==I,R.remaining)};continue}c()}return V},y=Q=>{let S=Q,Z=!0,V;for(;Z;){const R=S,$=ge(I=>{const G=wt(I)(R.outWeight);if(G.tag==="Nothing")return!0;if(G.tag==="Just")return G._1===0;c()})(R.remaining);if($.tag==="Nothing"){Z=!1,V=R;continue}if($.tag==="Just"){const I=$._1;S={...R,inWeight:J(G=>D=>Tt(nt)(Zt)(D.tgt)(-D.weight)(G))(R.inWeight)((()=>{const G=wt(I)(R.depsBySrc);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()),marks:K(nt)(I)(R.nextSink)(R.marks),nextSink:R.nextSink-1|0,outWeight:J(G=>D=>Tt(nt)(Zt)(D.src)(-D.weight)(G))(R.outWeight)((()=>{const G=wt(I)(R.depsByTgt);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()),remaining:ct(G=>G!==I,R.remaining)};continue}c()}return V},x=(Q=>{let S=Q,Z=!0,V;for(;Z;){const R=N(y(S));if(R.remaining.length===0){Z=!1,V=O($=>{const I=wt($.id)(R.marks),G=(()=>{if(I.tag==="Nothing")return $.id;if(I.tag==="Just")return I._1;c()})();return{...$,mark:G<m?(G+m|0)+1|0:G}})(p);continue}S=(()=>{const $=G=>{const D=wt(G)(R.outWeight),P=wt(G)(R.inWeight);return(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;c()})()-(()=>{if(P.tag==="Nothing")return 0;if(P.tag==="Just")return P._1;c()})()|0},I=vt(G=>D=>nt.compare($(D))($(G)))(R.remaining);if(0<I.length){const G=I[0];return{...R,inWeight:J(D=>P=>Tt(nt)(Zt)(P.tgt)(-P.weight)(D))(R.inWeight)((()=>{const D=wt(G)(R.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})()),marks:K(nt)(G)(R.nextSource)(R.marks),nextSource:R.nextSource+1|0,outWeight:J(D=>P=>Tt(nt)(Zt)(P.src)(-P.weight)(D))(R.outWeight)((()=>{const D=wt(G)(R.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})()),remaining:ct(D=>D!==G,R.remaining)}}return R})()}return V})({remaining:O(Q=>Q.id)(p),marks:M,inWeight:J(Q=>S=>Tt(nt)(Zt)(S.tgt)(S.weight)(Q))(M)(h.deps),outWeight:J(Q=>S=>Tt(nt)(Zt)(S.src)(S.weight)(Q))(M)(h.deps),depsBySrc:J(Q=>S=>Tt(nt)(ue)(S.src)([S])(Q))(M)(h.deps),depsByTgt:J(Q=>S=>Tt(nt)(ue)(S.tgt)([S])(Q))(M)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),v=(()=>{const Q=(()=>{const V=jn(O(R=>w(R.id,R.mark))(x));return{segments:x,deps:xt(R=>(()=>{if(R.kind==="Critical")return!0;if(R.kind==="Regular")return!1;c()})()?L("Just",R):(()=>{const $=wt(R.src)(V),I=wt(R.tgt)(V);return(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;c()})()>(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;c()})()})()?R.weight===0?T:L("Just",{src:R.tgt,tgt:R.src,weight:R.weight,kind:R.kind}):L("Just",R))(h.deps)}})(),S=J(V=>R=>Tt(nt)(Zt)(R.tgt)(1)(V))(M)(Q.deps),Z=(V=>{let R=V,$=!0,I;for(;$;){const G=R,D=Bt(P=>T,P=>A=>L("Just",{head:P,tail:A}),G.queue);if(D.tag==="Nothing"){$=!1,I=G;continue}if(D.tag==="Just"){R=J((()=>{const P=wt(D._1.head)(G.slots),A=(()=>{if(P.tag==="Nothing")return 0;if(P.tag==="Just")return P._1;c()})();return H=>Y=>{const W=wt(Y)(H.inDegree),q=(()=>{if(W.tag==="Nothing")return-1;if(W.tag==="Just")return W._1-1|0;c()})();return{...H,slots:K(nt)(Y)(ya((()=>{const B=wt(Y)(H.slots);if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;c()})())(A+1|0))(H.slots),inDegree:K(nt)(Y)(q)(H.inDegree),queue:q===0?[...H.queue,Y]:H.queue}}})())({...G,queue:D._1.tail})((()=>{const P=wt(D._1.head)(G.adj);if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;c()})());continue}c()}return I})({slots:jn(O(V=>w(V.id,0))(Q.segments)),inDegree:S,adj:J(V=>R=>Tt(nt)(ue)(R.src)([R.tgt])(V))(M)(Q.deps),queue:O(V=>V.id)(ct(V=>{const R=wt(V.id)(S);if(R.tag==="Nothing")return!0;if(R.tag==="Just")return R._1===0;c()},Q.segments))});return vt(V=>R=>nt.compare(V.slot)(R.slot))(O(V=>({...V,slot:(()=>{const R=wt(V.id)(Z.slots);if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;c()})()}))(Q.segments))})(),b=1+J(Q=>S=>ya(Q)(S.slot))(0)(v)|0,E=St(v)(Q=>Q.members),k=ct(Q=>ke(ze)(Q.edge.id)(E),t),F=J(st)(-1e18)(O(Q=>Q.fromPos._2)(k)),U=J(ut)(1e18)(O(Q=>Q.toPos._2)(k));if(F>U){const Q=jn(O(S=>w(S.id,S))(v));return Le(O(S=>O(Z=>w(Z,{slot:S.slot,slotCount:b,gapTop:U,gapBottom:F,partner:(()=>{if(S.splitPartner.tag==="Just"){const V=wt(S.splitPartner._1)(Q);if(V.tag==="Just")return L("Just",{slot:V._1.slot,splitX:0<V._1.incoming.length?V._1.incoming[0]:0});if(V.tag==="Nothing")return T;c()}if(S.splitPartner.tag==="Nothing")return T;c()})()}))(S.members))(ct(S=>{if(S.splitPartner.tag==="Just"){const Z=wt(S.splitPartner._1)(Q);return!(Z.tag==="Just"&&(()=>{if(Z._1.splitBy.tag==="Nothing")return!1;if(Z._1.splitBy.tag==="Just")return!0;c()})())}if(S.splitPartner.tag==="Nothing")return!0;c()},v)))}const tt=jn(O(Q=>w(Q.id,Q))(v));return Le(O(Q=>O(S=>w(S,{slot:Q.slot,slotCount:b,gapTop:F,gapBottom:U,partner:(()=>{if(Q.splitPartner.tag==="Just"){const Z=wt(Q.splitPartner._1)(tt);if(Z.tag==="Just")return L("Just",{slot:Z._1.slot,splitX:0<Z._1.incoming.length?Z._1.incoming[0]:0});if(Z.tag==="Nothing")return T;c()}if(Q.splitPartner.tag==="Nothing")return T;c()})()}))(Q.members))(ct(Q=>{if(Q.splitPartner.tag==="Just"){const S=wt(Q.splitPartner._1)(tt);return!(S.tag==="Just"&&(()=>{if(S._1.splitBy.tag==="Nothing")return!1;if(S._1.splitBy.tag==="Just")return!0;c()})())}if(Q.splitPartner.tag==="Nothing")return!0;c()},v)))})()))(M)(ql(J(u=>s=>{const a=rn(s.edge.from.node)(n);if(a.tag==="Just"){const f=rn(s.edge.to.node)(n);return f.tag==="Just"&&a._1.layer!==f._1.layer?Tt(nt)(ue)(Zn(a._1.layer)(f._1.layer))([s])(u):u}return u})(M)((()=>{const u=s=>w((()=>{const a=rn(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=rn(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return vt(s=>a=>Ol(u(s))(u(a)))(t)})())))},Wl=t=>e=>{const n=Ja(t)(e),r=J(i=>o=>K(C)(o.node)(o)(i))(M)(e);return J(i=>o=>{const u=rn(o.edge.from.node)(r);if(u.tag==="Just"){const s=rn(o.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=rn(o.edge.id)(n);if(a.tag==="Just")return K(nt)(Zn(u._1.layer)(s._1.layer))(a._1.slotCount)(i)}return i}return i})(M)(t)},xa=Dt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),ee=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},ne=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Qr=t=>e=>n=>r=>xa(i=>n>=i.x&&n<i.x+i.w&&e>i.y&&t<i.y+i.h)(r),Ji=t=>e=>n=>r=>Qr(ee(e)(n))(ne(e)(n))(r)(t),xi=ot(4),Vl=Yu(t=>{if(t.direction==="H"){const e=ee(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:ne(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=ee(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:ne(t.start._2)(t.end._2)-e}]}c()}),Ta=Uu(t=>!(t.start._1===t.end._1&&t.start._2===t.end._2)),Ul=t=>e=>n=>{const r=Bt(i=>T,i=>o=>L("Just",{head:i,tail:o}),e);if(r.tag==="Nothing")return[{start:t.start,end:n.end,direction:t.direction}];if(r.tag==="Just"){const i=(r._1.head.direction==="H"?t.direction==="H":r._1.head.direction==="V"&&t.direction==="V")?[{start:t.start,end:r._1.head.end,direction:t.direction}]:[t,r._1.head],o=Vu(r._1.tail);if(o.tag==="Nothing"){const u=i.length-1|0;return u>=0&&u<i.length&&(i[u].direction==="H"?n.direction==="H":i[u].direction==="V"&&n.direction==="V")?[...(()=>{const s=i.length-1|0;return s<1?[]:It(0,s,i)})(),{start:i[u].start,end:n.end,direction:n.direction}]:[...i,n]}if(o.tag==="Just")return(o._1.last.direction==="H"?n.direction==="H":o._1.last.direction==="V"&&n.direction==="V")?[...i,...o._1.init,{start:o._1.last.start,end:n.end,direction:n.direction}]:[...i,...r._1.tail,n]}c()},nu=t=>{const e=r=>i=>{const o=Bt(u=>T,u=>s=>L("Just",{head:u,tail:s}),i);if(o.tag==="Nothing")return[r];if(o.tag==="Just")return(r.direction==="H"?o._1.head.direction==="H":r.direction==="V"&&o._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==o._1.head.end._1-o._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==o._1.head.end._2-o._1.head.start._2>=0;c()})()?e({start:r.start,end:o._1.head.end,direction:r.direction})(o._1.tail):[r,...e(o._1.head)(o._1.tail)];c()},n=Bt(r=>T,r=>i=>L("Just",{head:r,tail:i}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);c()},Pr=t=>e=>n=>r=>xa(i=>n>=i.y&&n<i.y+i.h&&e>i.x&&t<i.x+i.w)(r),Dr=t=>e=>n=>r=>Pr(ee(e)(n))(ne(e)(n))(r)(t),Yl=t=>e=>n=>r=>{const i=n+2|0,o=i<1?e:It(i,e.length,e),u=n<1?[]:It(0,n,e),s=(n+1|0)===(r-1|0),a=n===0,f=n>=0&&n<e.length?L("Just",e[n]):T;if(f.tag==="Just"){const g=n+1|0,d=g>=0&&g<e.length?L("Just",e[g]):T;if(d.tag==="Just"){const l=f._1.start._1===d._1.end._1&&(!a||f._1.direction==="V")&&(!s||d._1.direction==="V")&&!Ji(t)(ee(f._1.start._2)(d._1.end._2))(ne(f._1.start._2)(d._1.end._2))(f._1.start._1)?L("Just",[...u,{start:f._1.start,end:d._1.end,direction:Kt},...o]):T,_=f._1.start._2===d._1.end._2&&(!a||f._1.direction==="H")&&(!s||d._1.direction==="H")&&!Dr(t)(ee(f._1.start._1)(d._1.end._1))(ne(f._1.start._1)(d._1.end._1))(f._1.start._2)?L("Just",[...u,{start:f._1.start,end:d._1.end,direction:Xt},...o]):T;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return T;c()}if(f.tag==="Nothing")return T;c()},Xl=t=>e=>{const n=e.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+1|0)>=n){o=!1,u=e;continue}const a=Yl(t)(e)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}c()}return u})(0)},Kl=t=>e=>n=>r=>{const i=(l,_,h)=>!Ji(t)(ee(_)(h))(ne(_)(h))(l),o=n+3|0,u=o<1?e:It(o,e.length,e),s=n<1?[]:It(0,n,e),a=(n+2|0)===(r-1|0),f=n===0,g=(l,_,h)=>!Dr(t)(ee(_)(h))(ne(_)(h))(l),d=n>=0&&n<e.length?L("Just",e[n]):T;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<e.length?L("Just",e[l]):T;if(_.tag==="Just"){const h=d._1.start._1===_._1.end._1&&(!f||d._1.direction==="V")&&(!a||_._1.direction==="V")&&i(d._1.start._1,d._1.start._2,_._1.end._2)?L("Just",[...s,{start:d._1.start,end:_._1.end,direction:Kt},...u]):d._1.start._2===_._1.end._2&&(!f||d._1.direction==="H")&&(!a||_._1.direction==="H")&&g(d._1.start._2,d._1.start._1,_._1.end._1)?L("Just",[...s,{start:d._1.start,end:_._1.end,direction:Xt},...u]):T,p=(!f||d._1.direction==="V")&&(!a||_._1.direction==="H")&&i(d._1.start._1,d._1.start._2,_._1.end._2)&&g(_._1.end._2,d._1.start._1,_._1.end._1)?L("Just",[...s,{start:d._1.start,end:w(d._1.start._1,_._1.end._2),direction:Kt},{start:w(d._1.start._1,_._1.end._2),end:_._1.end,direction:Xt},...u]):T,m=(!f||d._1.direction==="H")&&(!a||_._1.direction==="V")&&g(d._1.start._2,d._1.start._1,_._1.end._1)&&i(_._1.end._1,d._1.start._2,_._1.end._2)?L("Just",[...s,{start:d._1.start,end:w(_._1.end._1,d._1.start._2),direction:Xt},{start:w(_._1.end._1,d._1.start._2),end:_._1.end,direction:Kt},...u]):T,N=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?N:h}if(_.tag==="Nothing")return T;c()}if(d.tag==="Nothing")return T;c()},jl=t=>e=>{const n=e.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+2|0)>=n){o=!1,u=e;continue}const a=Kl(t)(e)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}c()}return u})(0)},Zl=t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r,s=nu(Ta(Xl(t)(jl(t)(u))));if(s.length<u.length){r=s;continue}i=!1,o=s}return o};return n=>e(nu(Ta(n)))},th=t=>e=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=ct(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=vt(f=>g=>dt.compare(f.x)(g.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=vt(a=>f=>dt.compare(f.x)(a.x))(O(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},eh=t=>e=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=ct(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=vt(f=>g=>dt.compare(f.y)(g.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=vt(a=>f=>dt.compare(f.y)(a.y))(O(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},nh=t=>e=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=ct(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=vt(f=>g=>dt.compare(g.x)(f.x))(O(f=>({...f,x:f.x+f.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=vt(a=>f=>dt.compare(a.x)(f.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},rh=t=>e=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=ct(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=vt(f=>g=>dt.compare(g.y)(f.y))(O(f=>({...f,y:f.y+f.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=vt(a=>f=>dt.compare(a.y)(f.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},va=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,f=i,g=o;if(g>100){u=!1,s=f;continue}if(!a(f+g)){u=!1,s=f+g;continue}if(!a(f-g)){u=!1,s=f-g;continue}r=a,i=f,o=g+1}return s},wa=t=>e=>n=>r=>i=>{const o=ee(e)(n),u=ne(e)(n);if(!Qr(o)(u)(r)(t))return r;if(!Qr(o)(u)(i)(t))return i;const s=(r+i)/2;return Qr(o)(u)(s)(t)?va(a=>Qr(o)(u)(a)(t))(s)(1):s},ih=t=>e=>n=>r=>i=>{const o=ee(e)(n),u=ne(e)(n);if(!Pr(o)(u)(r)(t))return r;if(!Pr(o)(u)(i)(t))return i;const s=(r+i)/2;return Pr(o)(u)(s)(t)?va(a=>Pr(o)(u)(a)(t))(s)(1):s},oh=t=>e=>n=>r=>{const i=ee(e)(n),o=ne(e)(n),u=ct(f=>r>=f.x&&r<f.x+f.w&&f.y+f.h>i&&f.y<o,t),s=J(f=>g=>ne(f)(g.x+g.w+4))(r+4)(u),a=J(f=>g=>ee(f)(g.x-4))(r-4)(u);return(()=>{const f=s-r,g=a-r;return(f<0?-f:f)<=(g<0?-g:g)})()?s:a},uh=t=>e=>n=>r=>{const i=ee(e)(n),o=ne(e)(n),u=ct(f=>r>=f.y&&r<f.y+f.h&&f.x+f.w>i&&f.x<o,t),s=J(f=>g=>ne(f)(g.y+g.h+4))(r+4)(u),a=J(f=>g=>ee(f)(g.y-4))(r-4)(u);return(()=>{const f=s-r,g=a-r;return(f<0?-f:f)<=(g<0?-g:g)})()?s:a},sh=t=>e=>n=>r=>i=>o=>u=>{const s=(()=>{if(r==="South")return w(i._1,i._2+4);if(r==="North")return w(i._1,i._2-4);if(r==="East")return w(i._1+4,i._2);if(r==="West")return w(i._1-4,i._2);c()})(),a=(()=>{if(o==="South")return w(u._1,u._2+4);if(o==="North")return w(u._1,u._2-4);if(o==="East")return w(u._1+4,u._2);if(o==="West")return w(u._1-4,u._2);c()})(),f=(b,E,k)=>!Ji(e)(ee(E)(k))(ne(E)(k))(b),g=(b,E,k)=>!Ji(n)(ee(E)(k))(ne(E)(k))(b),d=(b,E,k,F)=>t.tag==="Just"&&!Dr(n)(ee(b)(E))(ne(b)(E))(t._1)?t._1:ih(e)(b)(E)(k)(F),l=(b,E,k,F)=>{if(b===k){const tt=oh(e)(E)(F)(b),Q=eh(e)(b)(E)(F),S=rh(e)(b)(E)(F);return[{start:w(b,E),end:w(b,Q),direction:Kt},{start:w(b,Q),end:w(tt,Q),direction:Xt},{start:w(tt,Q),end:w(tt,S),direction:Kt},{start:w(tt,S),end:w(k,S),direction:Xt},{start:w(k,S),end:w(k,F),direction:Kt}]}const U=d(b,k,E,F);return[{start:w(b,E),end:w(b,U),direction:Kt},{start:w(b,U),end:w(k,U),direction:Xt},{start:w(k,U),end:w(k,F),direction:Kt}]},_=(b,E,k,F)=>{if(E===F){const tt=uh(e)(b)(k)(E),Q=th(e)(E)(b)(k),S=nh(e)(E)(b)(k);return[{start:w(b,E),end:w(Q,E),direction:Xt},{start:w(Q,E),end:w(Q,tt),direction:Kt},{start:w(Q,tt),end:w(S,tt),direction:Xt},{start:w(S,tt),end:w(S,F),direction:Kt},{start:w(S,F),end:w(k,F),direction:Xt}]}const U=wa(e)(E)(F)(b)(k);return[{start:w(b,E),end:w(U,E),direction:Xt},{start:w(U,E),end:w(U,F),direction:Kt},{start:w(U,F),end:w(k,F),direction:Xt}]},h=(b,E,k)=>!Dr(e)(ee(E)(k))(ne(E)(k))(b),p=(b,E,k)=>!Dr(n)(ee(E)(k))(ne(E)(k))(b),m=(b,E,k,F)=>{if(p(E,b,k)&&g(k,E,F))return[{start:w(b,E),end:w(k,E),direction:Xt},{start:w(k,E),end:w(k,F),direction:Kt}];const U=wa(e)(E)(F)(b)(k);return[{start:w(b,E),end:w(U,E),direction:Xt},{start:w(U,E),end:w(U,F),direction:Kt},{start:w(U,F),end:w(k,F),direction:Xt}]},N=(b,E,k,F)=>{if(g(b,E,F)&&p(F,b,k))return[{start:w(b,E),end:w(b,F),direction:Kt},{start:w(b,F),end:w(k,F),direction:Xt}];const U=d(b,k,E,F);return[{start:w(b,E),end:w(b,U),direction:Kt},{start:w(b,U),end:w(k,U),direction:Xt},{start:w(k,U),end:w(k,F),direction:Kt}]},y=(()=>{if(r==="South")return o==="North"?s._1===a._1&&f(s._1,s._2,a._2)?[{start:w(s._1,s._2),end:w(a._1,a._2),direction:Kt}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?N(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="North")return o==="South"?s._1===a._1&&f(s._1,s._2,a._2)?[{start:w(s._1,s._2),end:w(a._1,a._2),direction:Kt}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?N(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="East")return o==="West"?s._2===a._2&&h(s._2,s._1,a._1)?[{start:w(s._1,s._2),end:w(a._1,a._2),direction:Xt}]:_(s._1,s._2,a._1,a._2):o==="North"||o==="South"?m(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="West"){if(o==="East")return s._2===a._2&&h(s._2,s._1,a._1)?[{start:w(s._1,s._2),end:w(a._1,a._2),direction:Xt}]:_(s._1,s._2,a._1,a._2);if(o==="North"||o==="South")return m(s._1,s._2,a._1,a._2)}return l(s._1,s._2,a._1,a._2)})(),x=(()=>{if(r==="South"||r==="North")return Kt;if(r==="East"||r==="West")return Xt;c()})(),v={start:w(a._1,a._2),end:w(u._1,u._2),direction:(()=>{if(o==="South"||o==="North")return Kt;if(o==="East"||o==="West")return Xt;c()})()};return s._1===a._1&&s._2===a._2?[{start:w(i._1,i._2),end:w(u._1,u._2),direction:x}]:Ul({start:w(i._1,i._2),end:w(s._1,s._2),direction:x})(y)(v)},ah=O(t=>({x:t.position._1*xi-2,y:t.position._2*xi-2,w:t.size._1*xi+4,h:t.size._2*xi+4})),La=Vt(C)(Dt),on=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},ch=Vt(C)(Dt),ba=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},fh=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t._1)(o._3._1);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(t._2==="North"){if(o._3._2==="North"){r=!1,i=L("Just",o._4);continue}n=o._5;continue}if(o._3._2==="North"){n=o._6;continue}if(t._2==="South"){if(o._3._2==="South"){r=!1,i=L("Just",o._4);continue}n=o._5;continue}if(o._3._2==="South"){n=o._6;continue}if(t._2==="East"){if(o._3._2==="East"){r=!1,i=L("Just",o._4);continue}n=o._5;continue}if(o._3._2==="East"){n=o._6;continue}if(t._2==="West"&&o._3._2==="West"){r=!1,i=L("Just",o._4);continue}}c()}return i},gh=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Ea=t=>e=>{const n=e.position._1+e.size._1,r=e.position._2*2+e.size._2,i=e.position._1*2+e.size._1,o=e.position._2+e.size._2;if(t==="South")return w(i,o*2);if(t==="North")return w(i,e.position._2*2);if(t==="East")return w(n*2,r);if(t==="West")return w(e.position._1*2,r);c()},ru=t=>e=>{const n=ot(4);if(t==="South")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="North")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="East")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};if(t==="West")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};c()},ka=t=>e=>J(n=>r=>Tt(t)(ue)(e(r))([r])(n))(M),Ga=t=>e=>n=>r=>{const i=(t==="South"||t==="North")&&(e==="East"||e==="West")&&(()=>{if(t==="South")return r._2>n._2;if(t==="North")return r._2<n._2;if(t==="East")return r._2>n._2;if(t==="West")return r._2<n._2;c()})()&&(()=>{if(e==="East")return n._1>r._1;if(e==="West"||e==="North")return n._1<r._1;if(e==="South")return n._1>r._1;c()})(),o=(t==="East"||t==="West")&&(e==="North"||e==="South")&&(()=>{if(t==="South")return r._1>n._1;if(t==="North")return r._1<n._1;if(t==="East")return r._1>n._1;if(t==="West")return r._1<n._1;c()})()&&(()=>{if(e==="East")return n._2>r._2;if(e==="West"||e==="North")return n._2<r._2;if(e==="South")return n._2>r._2;c()})();return(t==="South"?e==="North"&&n._1===r._1&&r._2>n._2:t==="North"?e==="South"&&n._1===r._1&&r._2<n._2:t==="East"?e==="West"&&n._2===r._2&&r._1>n._1:t==="West"&&e==="East"&&n._2===r._2&&r._1<n._1)?0:i||o?1:2},Ca=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,i=e.length;return i===0?M:La(i===1?O(o=>w(o,r))(e):At(o=>u=>w(u,t.lo+ot(o+1|0)*n/ot(i+1|0)))(e))},Sa=t=>e=>n=>r=>i=>{const o=ka(C)(_=>_.to.node)(t),u=ka(C)(_=>_.from.node)(t),s=J(_=>h=>K(C)(h.node)(h)(_))(M)(e),a=(_,h,p)=>{const m=on(_)(s);if(m.tag==="Nothing")return w(0,0);if(m.tag==="Just"){const N=on(_)(n);if(N.tag==="Nothing"){const y=ot(4);if(p==="South")return w(m._1.position._1*y+m._1.size._1*y/2,(m._1.position._2+m._1.size._2)*y);if(p==="North")return w(m._1.position._1*y+m._1.size._1*y/2,m._1.position._2*y);if(p==="East")return w((m._1.position._1+m._1.size._1)*y,m._1.position._2*y+m._1.size._2*y/2);if(p==="West")return w(m._1.position._1*y,m._1.position._2*y+m._1.size._2*y/2);c()}if(N.tag==="Just"){const y=ge(x=>x.id===h)(N._1);if(y.tag==="Nothing"){const x=ot(4);if(p==="South")return w(m._1.position._1*x+m._1.size._1*x/2,(m._1.position._2+m._1.size._2)*x);if(p==="North")return w(m._1.position._1*x+m._1.size._1*x/2,m._1.position._2*x);if(p==="East")return w((m._1.position._1+m._1.size._1)*x,m._1.position._2*x+m._1.size._2*x/2);if(p==="West")return w(m._1.position._1*x,m._1.position._2*x+m._1.size._2*x/2);c()}if(y.tag==="Just"){const x=ot(4);if(y._1.side==="North")return w(m._1.position._1*x+ot(y._1.offset)*x,m._1.position._2*x);if(y._1.side==="South")return w(m._1.position._1*x+ot(y._1.offset)*x,(m._1.position._2+m._1.size._2)*x);if(y._1.side==="East")return w((m._1.position._1+m._1.size._1)*x,m._1.position._2*x+ot(y._1.offset)*x);if(y._1.side==="West")return w(m._1.position._1*x,m._1.position._2*x+ot(y._1.offset)*x)}}}c()},f=ch(St(r)(_=>{if(_.nodes.length<=2)return[];const h=ot(4);if(1<_.nodes.length){const p=on(_.nodes[1])(s);if(p.tag==="Nothing")return[];if(p.tag==="Just"){const m=p._1.position._1*h+p._1.size._1*h/2;return O(N=>w(N,m))(ye(N=>y=>_.edgeId+":"+N+"->"+y,_.nodes,It(1,_.nodes.length,_.nodes)))}c()}return[]})),g=_=>{const h=on(_.from.node)(s),p=on(_.to.node)(s);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,N=p._1,y=vt(x=>v=>nt.compare(x.score)(v.score))(O(x=>{const v=x._1,b=x._2;return{from:v,to:b,score:(()=>{const E=(tt,Q,S,Z,V)=>{const R=ru(tt)(Q),$=ru(tt)(S);return R.lo<$.hi&&$.lo<R.hi&&(v==="South"?b==="North"&&V._2>Z._2:v==="North"?b==="South"&&V._2<Z._2:v==="East"?b==="West"&&V._1>Z._1:v==="West"&&b==="East"&&V._1<Z._1)?0:Ga(v)(b)(Z)(V)},k=Ea(v)(m),F=Ea(b)(N),U=Ga(v)(b)(k)(F);return(()=>{if(U>0){if(v==="South")return b==="North"?E(ae,m,N,k,F)*10|0:U*10|0;if(v==="North")return b==="South"?E(se,m,N,k,F)*10|0:U*10|0;if(v==="East")return b==="West"?E(Oe,m,N,k,F)*10|0:U*10|0;if(v==="West"&&b==="East")return E(Gn,m,N,k,F)*10|0}return U*10|0})()+(v==="South"?b==="North"?0:15:v==="North"?b==="South"?0:15:v==="East"?b==="West"?5:15:v==="West"&&b==="East"?5:15)|0})()}})([w(ae,se),w(Oe,se),w(Gn,se),w(ae,Oe),w(ae,Gn),w(se,ae),w(se,Oe),w(se,Gn),w(Oe,ae),w(Gn,ae),w(Oe,Gn),w(Gn,Oe)]));if(0<y.length)return{from:y[0].from,to:y[0].to}}return{from:ae,to:se}},d=La(O(_=>w(_.id,g(_)))(t)),l=(_,h,p,m,N,y)=>{const x=ot(4),v=on(h)(s);if(v.tag==="Nothing")return w(0,0);if(v.tag==="Just"){const b=fh(w(p,_))(i);if(b.tag==="Just"){const E=v._1.position._1*x+b._1,k=ot(4);if(_==="South")return w(E,(v._1.position._2+v._1.size._2)*k);if(_==="North")return w(E,v._1.position._2*k);if(_==="East")return w((v._1.position._1+v._1.size._1)*k,E);if(_==="West")return w(v._1.position._1*k,E);c()}if(b.tag==="Nothing"){const E=ru(_)(v._1),k=(E.lo+E.hi)/2,F=ba(p)(Ca(E)(O(Q=>Q.id)(vt(Q=>S=>dt.compare(N(_)(Q))(N(_)(S)))(ct(Q=>{const S=ba(Q.id)(d);if(S.tag==="Just"){const Z=y(S._1);return Z==="North"?_==="North":Z==="South"?_==="South":Z==="East"?_==="East":Z==="West"&&_==="West"}if(S.tag==="Nothing")return!0;c()},(()=>{const Q=on(h)(m);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()})()))))),U=(()=>{if(F.tag==="Nothing")return k;if(F.tag==="Just")return F._1;c()})(),tt=ot(4);if(_==="South")return w(U,(v._1.position._2+v._1.size._2)*tt);if(_==="North")return w(U,v._1.position._2*tt);if(_==="East")return w((v._1.position._1+v._1.size._1)*tt,U);if(_==="West")return w(v._1.position._1*tt,U)}}c()};return O(_=>{const h=gh(_.edge.id)(f);if(h.tag==="Nothing")return _;if(h.tag==="Just")return{..._,fromPos:ce(3)(_.edge.from.node)==="$d:"?w(h._1,_.fromPos._2):_.fromPos,toPos:ce(3)(_.edge.to.node)==="$d:"?w(h._1,_.toPos._2):_.toPos};c()})(O(_=>{if(_.from.port.tag==="Just"&&_.to.port.tag==="Just")return{edge:_,fromPos:a(_.from.node,_.from.port._1,ae),toPos:a(_.to.node,_.to.port._1,se),fromSide:ae,toSide:se};const h=g(_);return{edge:_,fromPos:l(h.from,_.from.node,_.id,u,p=>m=>{const N=on(m.to.node)(s);if(N.tag==="Nothing")return 0;if(N.tag==="Just"){const y=ot(4);if(p==="South"||p==="North")return N._1.position._1*y+N._1.size._1*y/2;if(p==="East"||p==="West")return N._1.position._2*y+N._1.size._2*y/2}c()},p=>p.from),toPos:l(h.to,_.to.node,_.id,o,p=>m=>{const N=on(m.from.node)(s);if(N.tag==="Nothing")return 0;if(N.tag==="Just"){const y=ot(4);if(p==="South"||p==="North")return N._1.position._1*y+N._1.size._1*y/2;if(p==="East"||p==="West")return N._1.position._2*y+N._1.size._2*y/2}c()},p=>p.to),fromSide:h.from,toSide:h.to}})(t))},Qa=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},tr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},_h=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),iu=t=>e=>t.gapTop+1*ot(4)+ot(e)*2.5*ot(4),dh=t=>e=>{const n=Qa(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return L("Just",{slot1Y:iu(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:iu(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return T;c()}if(n.tag==="Nothing")return T;c()},lh=t=>e=>{const n=J(r=>i=>K(C)(i.node)(i)(r))(M)(e);return Le(At(r=>i=>{const o=tr(i.node)(n);if(o.tag==="Nothing")return[];if(o.tag==="Just"){const u=o._1;return At(s=>a=>{const f=i.edges.length,g=ot(4),d=u.position._1*g,l=u.position._2*g,_=u.size._2*g,h=ot((2*f|0)+1|0),p=l+_*ot(f-s|0)/h,m=l+_*ot((f+1|0)+s|0)/h,N=d-g*2.5*ot(s+1|0),y=[{start:w(d,p),end:w(N,p),direction:Xt},{start:w(N,p),end:w(N,m),direction:Kt},{start:w(N,m),end:w(d,m),direction:Xt}];return{edge:a.id,segments:y,bends:ye(x=>v=>x.end,y,It(1,3,y)),bendType:[],jumps:[],reversed:!1}})(i.edges)}c()})(O(r=>({node:r._1,edges:r._2}))(_h(J(r=>i=>Tt(C)(ue)(i.from.node)([i])(r))(M)(t)))))},hh=t=>e=>{const n=J(o=>u=>K(C)(u.node)(u)(o))(M)(e),r=o=>{const u=tr(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.position._1;c()},i=o=>{const u=tr(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.layer;c()};return vt(o=>u=>{const s=nt.compare(i(o.edge.from.node))(i(u.edge.from.node));if(s==="EQ"){const a=dt.compare(r(o.edge.from.node))(r(u.edge.from.node));return a==="EQ"?dt.compare(r(o.edge.to.node))(r(u.edge.to.node)):a}return s})(t)},le=t=>{const e=ot(4);return{x:t.position._1*e-2,y:t.position._2*e-2,w:t.size._1*e+4,h:t.size._2*e+4}},ph=t=>t.from.node===t.to.node,mh=t=>e=>n=>r=>{const i=Zl(n)(sh(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:i,bends:ye(o=>u=>o.end,i,It(1,i.length,i)),bendType:[],jumps:[],reversed:!1}},Nh=t=>e=>n=>r=>{const i=[{start:w(r.fromPos._1,r.fromPos._2),end:w(r.fromPos._1,t.slot1Y),direction:Kt},{start:w(r.fromPos._1,t.slot1Y),end:w(t.splitX,t.slot1Y),direction:Xt},{start:w(t.splitX,t.slot1Y),end:w(t.splitX,t.slot2Y),direction:Kt},{start:w(t.splitX,t.slot2Y),end:w(r.toPos._1,t.slot2Y),direction:Xt},{start:w(r.toPos._1,t.slot2Y),end:w(r.toPos._1,r.toPos._2),direction:Kt}];return{edge:r.edge.id,segments:i,bends:ye(o=>u=>o.end,i,It(1,5,i)),bendType:[],jumps:[],reversed:!1}},yh=t=>e=>n=>{const r=tr(t.edge.from.node)(n);if(r.tag==="Just"){const o=tr(t.edge.to.node)(n);return o.tag==="Just"?ct(u=>!(u.h===le(r._1).h&&u.w===le(r._1).w&&u.x===le(r._1).x&&u.y===le(r._1).y)&&!(u.h===le(o._1).h&&u.w===le(o._1).w&&u.x===le(o._1).x&&u.y===le(o._1).y),e):ct(u=>!(u.h===le(r._1).h&&u.w===le(r._1).w&&u.x===le(r._1).x&&u.y===le(r._1).y),e)}const i=tr(t.edge.to.node)(n);return i.tag==="Just"?ct(o=>!(o.h===le(i._1).h&&o.w===le(i._1).w&&o.x===le(i._1).x&&o.y===le(i._1).y),e):ct(o=>!0,e)},Jh=t=>e=>{const n=Qa(e.edge.id)(t);if(n.tag==="Just")return L("Just",iu(n._1)(n._1.slot));if(n.tag==="Nothing")return T;c()},xh=t=>e=>n=>r=>i=>{const o=J(f=>g=>K(C)(g.node)(g)(f))(M)(e),u=ah(e),s=Sa(ct(f=>f.from.node!==f.to.node,t))(e)(n)(r)(i),a=Ja(s)(e);return[...lh(ct(ph,t))(e),...J(f=>g=>{const d=yh(g)(u)(o),l=[...d,...f.edgeObstacles],_=dh(a)(g),h=(()=>{if(_.tag==="Just")return Nh(_._1)(d)(l)(g);if(_.tag==="Nothing")return mh(Jh(a)(g))(d)(l)(g);c()})();return{results:[...f.results,h],edgeObstacles:[...f.edgeObstacles,...Vl(h.segments)]}})({results:[],edgeObstacles:[]})(hh(s)(e)).results]},mn=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Nn=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Th=t=>e=>n=>{if(t.start._1!==e.start._1)return T;const r=Nn(mn(t.start._2)(t.end._2))(mn(e.start._2)(e.end._2)),i=mn(Nn(t.start._2)(t.end._2))(Nn(e.start._2)(e.end._2));return r<i?L("Just",{position:w(t.start._1,(r+i)/2),crossingEdge:n}):T},vh=t=>e=>n=>{if(t.start._2!==e.start._2)return T;const r=Nn(mn(t.start._1)(t.end._1))(mn(e.start._1)(e.end._1)),i=mn(Nn(t.start._1)(t.end._1))(Nn(e.start._1)(e.end._1));return r<i?L("Just",{position:w((r+i)/2,t.start._2),crossingEdge:n}):T},wh=t=>e=>n=>{if(t.direction==="H")return vh(t)(e)(n);if(t.direction==="V")return Th(t)(e)(n);c()},Lh=t=>e=>n=>{const r=t+1|0,i=r<1?n:It(r,n.length,n);return St(e.segments)(o=>St(i)(u=>xt(s=>wh(o)(s)(u.edge))(ct(s=>s.direction==="H"?o.direction==="H":s.direction==="V"&&o.direction==="V",u.segments))))},bh=t=>e=>n=>e.start._1>mn(t.start._1)(t.end._1)&&e.start._1<Nn(t.start._1)(t.end._1)&&t.start._2>mn(e.start._2)(e.end._2)&&t.start._2<Nn(e.start._2)(e.end._2)?L("Just",{position:w(e.start._1,t.start._2),crossingEdge:n}):T,Eh=t=>e=>St(ct(n=>n.direction==="H",t.segments))(n=>St(e)(r=>xt(i=>bh(n)(i)(r.edge))(ct(i=>i.direction==="V",r.segments)))),kh=t=>e=>n=>[...Eh(e)(ct(r=>r.edge!==e.edge,n)),...Lh(t)(e)(n)],Ti=(()=>{const t={eq:e=>n=>e._1===n._1&&(e._2==="North"?n._2==="North":e._2==="South"?n._2==="South":e._2==="East"?n._2==="East":e._2==="West"&&n._2==="West")};return{compare:e=>n=>{const r=C.compare(e._1)(n._1);if(r==="LT")return me;if(r==="GT")return Ne;if(e._2==="North")return n._2==="North"?we:me;if(n._2==="North")return Ne;if(e._2==="South")return n._2==="South"?we:me;if(n._2==="South")return Ne;if(e._2==="East")return n._2==="East"?we:me;if(n._2==="East")return Ne;if(e._2==="West"&&n._2==="West")return we;c()},Eq0:()=>t}})(),Gh=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=Ti.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Ch=Vt(C)(Dt),ou=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Sh=Vt(Ti)(Dt),Pa=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),er=t=>e=>n=>r=>{const i=Gh(w(e,n))(t);if(i.tag==="Nothing")return r;if(i.tag==="Just")return i._1;c()},Da=t=>e=>n=>{const r=Ch(Le(O(u=>At(s=>a=>w(a,s))(u))(t))),i=(u,s)=>{if(u==="South"){const a=ou(s.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()}if(u==="North"){const a=ou(s.from.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()}return 0},o=u=>J(s=>a=>xe(Ti.compare,pe,Sh(O(f=>w(w(f._1,u),f._2))(Pa(Ca({lo:0,hi:(()=>{const f=ou(a._1)(n);if(f.tag==="Just")return f._1._1;if(f.tag==="Nothing")return ce(3)(a._1)==="$d:"?0:1;c()})()})(O(f=>f.id)(vt(f=>g=>nt.compare(i(u,f))(i(u,g)))(a._2)))))),s))(M)(Pa(J(s=>a=>a.from.node===a.to.node?s:u==="South"?Tt(C)(ue)(a.from.node)([a])(s):u==="North"?Tt(C)(ue)(a.to.node)([a])(s):s)(M)(e)));return xe(Ti.compare,pe,o(se),o(ae))},Aa=t=>t,Ia=t=>t,Ra=t=>t,Qh=J(t=>e=>K(C)(e)()(t))(M),Ph=(()=>{const t=Re.unfoldr(e=>{if(e.tag==="Nil")return T;if(e.tag==="Cons")return L("Just",w(e._1,e._2));c()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._3,n(r._6,i)));c()};return n(e,qt)})())})(),et=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Ce=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},We=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},De=Vt(C)(Dt),uu=fg(C),Ar=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),Fa=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Dh=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ah=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Ba=Ra("VDown"),Ma=Ra("VUp"),Ih=Ia("ForwardPhase"),Rh=Ia("StackPhase"),$a=Aa("HRight"),za=Aa("HLeft"),Fh=t=>e=>n=>{const r=J(u=>s=>Tt(C)(Zt)(s.tgt)(1)(u))(M)(t),i=Ph(Qh([...O(u=>u.src)(t),...O(u=>u.tgt)(t),...(()=>{const u=(s,a)=>{if(s.tag==="Leaf")return a;if(s.tag==="Node")return u(s._5,Mt("Cons",s._4,u(s._6,a)));c()};return bt(Wt.foldr,u(e,qt))})()])),o=J(u=>s=>Tt(C)(ue)(s.src)([{target:s.tgt,sep:s.sep}])(u))(M)(t);return(u=>s=>a=>{let f=u,g=s,d=a,l=!0,_;for(;l;){const h=f,p=g,m=d,N=Bt(y=>T,y=>x=>L("Just",{head:y,tail:x}),h);if(N.tag==="Nothing"){l=!1,_=m;continue}if(N.tag==="Just"){const y=et(N._1.head)(m),x=(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;c()})(),v=J(b=>E=>{const k=et(E.target)(b.result),F=x+E.sep,U=et(E.target)(b.indeg),tt=(()=>{if(U.tag==="Nothing")return-1;if(U.tag==="Just")return U._1-1|0;c()})();return{newQueue:tt===0?[...b.newQueue,E.target]:b.newQueue,result:K(C)(E.target)((()=>{if(k.tag==="Nothing")return F;if(k.tag==="Just"){if(n==="VDown")return Ce(k._1)(F);if(n==="VUp")return We(k._1)(F)}c()})())(b.result),indeg:K(C)(E.target)(tt)(b.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const b=et(N._1.head)(o);if(b.tag==="Nothing")return[];if(b.tag==="Just")return b._1;c()})());f=[...N._1.tail,...v.newQueue],g=v.indeg,d=v.result;continue}c()}return _})(ct(u=>{const s=et(u)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;c()},i))(M)(J(u=>s=>K(C)(s)(0)(u))(M)(i))},Bh=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,Mt("Cons",o._4,e(o._6,u)));c()},n=bt(Wt.foldr,e(t,qt)),r=J(Ce)(999999)(n);if(r===0||n.length===0)return t;const i=o=>{if(o.tag==="Leaf")return M;if(o.tag==="Node")return $t("Node",o._1,o._2,o._3,o._4-r,i(o._5),i(o._6));c()};return i(t)},Mh=t=>e=>{const n=(i,o,u)=>ce(3)(o)==="$d:"&&Wu(s=>ce(3)(s)==="$d:",(()=>{const s=et(o)(t.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;c()})()),r=i=>o=>u=>s=>a=>f=>g=>{let d=i,l=o,_=s,h=f,p=g,m=!0,N;for(;m;){const y=d,x=l,v=_,b=h,E=p,k=x.length;if(E>=k){m=!1,N=y;continue}const F=E>=0&&E<x.length?L("Just",x[E]):T,U=(()=>{if(F.tag==="Nothing")return"";if(F.tag==="Just")return F._1;c()})(),tt=n(t,U);if(E===(k-1|0)||tt){const Q=(()=>{if(tt){const S=et(U)(t.preds),Z=(()=>{if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;c()})();if(0<Z.length){const V=v-1|0,R=et(Z[0])(t.nodeIndex);if(R.tag==="Nothing")return V;if(R.tag==="Just")return R._1;c()}}return v-1|0})();d=J(S=>Z=>{if(Z>=0&&Z<x.length){const V=x[Z];return n(t,V)?S:J(R=>$=>{const I=et($)(t.nodeIndex),G=(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;c()})();return G<b||G>Q?K(C)($+"\u2192"+V)()(R):R})(S)((()=>{const R=et(V)(t.preds);if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;c()})())}return n(t,"")?S:J(V=>R=>{const $=et(R)(t.nodeIndex),I=(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;c()})();return I<b||I>Q?K(C)(R+"\u2192")()(V):V})(S)((()=>{const V=et("")(t.preds);if(V.tag==="Nothing")return[];if(V.tag==="Just")return V._1;c()})())})(y)(Ht(0,E)),l=x,_=v,h=Q,p=E+1|0;continue}d=y,l=x,_=v,h=b,p=E+1|0}return N};return e.length<3?M:J(i=>o=>{if(o>=0&&o<e.length){const u=e[o];return r(i)((()=>{const s=o+1|0;return s>=0&&s<e.length?e[s]:[]})())(u)(u.length)(o)(0)(0)}return r(i)((()=>{const u=o+1|0;return u>=0&&u<e.length?e[u]:[]})())([])(0)(o)(0)(0)})(M)(Ht(1,e.length-2|0))},Oa=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,Mt("Cons",o._4,e(o._6,u)));c()},n=e(t,qt),r=o=>u=>{let s=o,a=u,f=!0,g;for(;f;){const d=s,l=a;if(l.tag==="Nil"){f=!1,g=d;continue}if(l.tag==="Cons"){s=We(d)(l._1),a=l._2;continue}c()}return g},i=o=>u=>{let s=o,a=u,f=!0,g;for(;f;){const d=s,l=a;if(l.tag==="Nil"){f=!1,g=d;continue}if(l.tag==="Cons"){s=Ce(d)(l._1),a=l._2;continue}c()}return g};return r(-999999)(n)-i(999999)(n)},Ir=t=>e=>(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,f=o;if(a===e){u=!1,s=f;continue}i=(()=>{const g=et(a)(t.align);if(g.tag==="Nothing")return e;if(g.tag==="Just")return g._1;c()})(),o=[...f,a]}return s})((()=>{const n=et(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;c()})())([e]),$h=t=>e=>n=>r=>i=>o=>u=>s=>a=>f=>g=>{const d=(G,D,P)=>{const A=G.from.node===D?G.from.port:G.to.node===D?G.to.port:T;if(A.tag==="Just"){const H=et(D)(i);if(H.tag==="Just"){const Y=ge(W=>W.id===A._1)(H._1);if(Y.tag==="Just"){const W=ot(Y._1.offset)*ot(4);return P==="North"||P==="South"?W:0}if(Y.tag==="Nothing"){const W=et(D)(r),q=er(u)(G.id)(P)((()=>{if(W.tag==="Nothing")return .5;if(W.tag==="Just")return W._1._1/2;c()})());return P==="North"||P==="South"?q:0}c()}if(H.tag==="Nothing"){const Y=et(D)(r),W=er(u)(G.id)(P)((()=>{if(Y.tag==="Nothing")return .5;if(Y.tag==="Just")return Y._1._1/2;c()})());return P==="North"||P==="South"?W:0}c()}if(A.tag==="Nothing"){const H=et(D)(r),Y=er(u)(G.id)(P)((()=>{if(H.tag==="Nothing")return .5;if(H.tag==="Just")return H._1._1/2;c()})());return P==="North"||P==="South"?Y:0}c()},l=(G,D)=>{if(G.from.node===D){if(g==="HRight")return ae;if(g==="HLeft")return se;c()}if(g==="HRight")return se;if(g==="HLeft")return ae;c()},_=(G,D,P)=>J(A=>H=>K(C)(H)((()=>{const Y=et(H)(A);if(Y.tag==="Nothing")return 0+D;if(Y.tag==="Just")return Y._1+D;c()})())(A))(P)(Ir(a)(G)),h=(()=>{if(g==="HRight")return n;if(g==="HLeft")return de(n);c()})(),p=G=>{const D=et(G)(r);if(D.tag==="Nothing")return 1;if(D.tag==="Just")return D._1._1;c()},m=De(Le(At(G=>D=>O(P=>w(P,G))(D))(n))),N=(G,D)=>ce(3)(G)==="$d:"&&ce(3)(D)==="$d:"||ce(3)(G)==="$d:"||ce(3)(D)==="$d:"?10:ot(t.nodeGap),y=J(G=>D=>uu(P=>L("Just",[...(()=>{if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;c()})(),D]))(D.to.node)(G))(M)(o),x=J(G=>D=>uu(P=>L("Just",[...(()=>{if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;c()})(),D]))(D.from.node)(G))(M)(o),v=Le(n),b=J(G=>D=>{const P=et(D)(a.root),A=(()=>{if(P.tag==="Nothing")return D;if(P.tag==="Just")return P._1;c()})();return D===A?G:uu(H=>L("Just",(()=>{if(H.tag==="Nothing")return!0;if(H.tag==="Just")return H._1;c()})()&&ce(3)(D)==="$d:"))(A)(G)})(De(O(G=>w(G,!0))(zn(C.compare)((()=>{const G=(D,P)=>{if(D.tag==="Leaf")return P;if(D.tag==="Node")return G(D._5,Mt("Cons",D._4,G(D._6,P)));c()};return bt(Wt.foldr,G(a.root,qt))})()))))(v),E=(G,D)=>{const P=G.free,A=et(P)(a.root),H=(()=>{if(A.tag==="Nothing")return P;if(A.tag==="Just")return A._1;c()})(),Y=et(H)(b),W=(()=>{if(Y.tag==="Nothing")return!0;if(Y.tag==="Just")return Y._1;c()})();return J(q=>B=>{if(q.edge.tag==="Just")return q;if(q.edge.tag==="Nothing"){if((()=>{const ft=et(H)(D.su);return!W&&(()=>{const ht=et(B.from.node)(m);return B.from.node!==B.to.node&&(()=>{const Lt=et(B.to.node)(m);return(()=>{if(ht.tag==="Nothing")return-1;if(ht.tag==="Just")return ht._1;c()})()===(()=>{if(Lt.tag==="Nothing")return-1;if(Lt.tag==="Just")return Lt._1;c()})()})()})()||(()=>{if(ft.tag==="Nothing")return!1;if(ft.tag==="Just")return ft._1;c()})()})())return q;const j=B.from.node===P?B.to.node:B.from.node,X=et(j)(a.root),_t=(()=>{if(X.tag==="Nothing")return j;if(X.tag==="Just")return X._1;c()})(),pt=_t!==H;return pt&&(()=>{const ft=et(_t)(D.blockFinished);if(ft.tag==="Nothing")return!1;if(ft.tag==="Just")return ft._1;c()})()?{...q,edge:L("Just",B),hasEdges:!0}:{...q,hasEdges:q.hasEdges||pt}}c()})({edge:T,hasEdges:!1})((()=>{if(G.isRoot){if(g==="HRight"){const q=et(P)(y);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;c()}if(g==="HLeft"){const q=et(P)(x);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}c()}if(g==="HRight"){const q=et(P)(x);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;c()}if(g==="HLeft"){const q=et(P)(y);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}c()})())},k=(G,D,P,A)=>{const H=(()=>{if(f==="VDown")return-1e18;if(f==="VUp")return 1e18;c()})(),Y={free:D,isRoot:P},W=E(Y,A);if(W.edge.tag==="Nothing")return W.hasEdges?{thresh:H,state:{...A,queue:[...A.queue,Y]}}:{thresh:H,state:A};if(W.edge.tag==="Just"){const q=W.edge._1.from.node===D?W.edge._1.to.node:W.edge._1.from.node;return{thresh:(()=>{const B=et((()=>{const pt=et(q)(a.root);if(pt.tag==="Nothing")return q;if(pt.tag==="Just")return pt._1;c()})())(A.x),j=et(q)(s),X=et(D)(s),_t=(()=>{if(B.tag==="Just")return B._1;if(B.tag==="Nothing")return T;c()})();return(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;c()})()+(()=>{if(j.tag==="Nothing")return 0;if(j.tag==="Just")return j._1;c()})()+d(W.edge._1,q,(()=>{if(P){if(g==="HRight")return ae;if(g==="HLeft")return se;c()}if(g==="HRight")return se;if(g==="HLeft")return ae;c()})())-(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;c()})()-d(W.edge._1,D,(()=>{if(P){if(g==="HRight")return se;if(g==="HLeft")return ae;c()}if(g==="HRight")return ae;if(g==="HLeft")return se;c()})())})(),state:{...A,su:K(C)((()=>{const B=et(W.edge._1.from.node)(a.root);if(B.tag==="Nothing")return W.edge._1.from.node;if(B.tag==="Just")return B._1;c()})())(!0)(K(C)((()=>{const B=et(W.edge._1.to.node)(a.root);if(B.tag==="Nothing")return W.edge._1.to.node;if(B.tag==="Just")return B._1;c()})())(!0)(A.su))}}}c()},F=(G,D,P,A)=>{const H=D===G,Y=et(D)(a.align),W=(()=>{if(Y.tag==="Nothing")return D===G;if(Y.tag==="Just")return Y._1===G;c()})();if(!(H||W))return{thresh:P,state:A};const q=(()=>{if(f==="VDown")return H&&P<=-1e18;if(f==="VUp")return H&&P>=1e18;c()})()?k(G,D,!0,A):{thresh:P,state:A};return(()=>{if(f==="VDown")return q.thresh<=-1e18&&W;if(f==="VUp")return q.thresh>=1e18&&W;c()})()?k(G,D,!1,q.state):q},U=G=>D=>P=>{const A=et(P)(e.nodeIndex),H=(()=>{if(A.tag==="Nothing")return 0;if(A.tag==="Just")return A._1;c()})(),Y=ge(X=>ke(ze)(P)(X))(h),W=(()=>{if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1;c()})(),q=W.length;if((()=>{if(f==="VDown")return H<=0;if(f==="VUp")return H>=(q-1|0);c()})()){const X=F(G,P,D.thresh,D.st);return{...D,st:X.state,thresh:X.thresh}}const B=(()=>{if(f==="VDown")return H-1|0;if(f==="VUp")return H+1|0;c()})(),j=B>=0&&B<W.length?L("Just",W[B]):T;if(j.tag==="Nothing")return D;if(j.tag==="Just"){const X=et(j._1)(a.root),_t=(()=>{if(X.tag==="Nothing")return j._1;if(X.tag==="Just")return X._1;c()})(),pt=F(G,P,D.thresh,tt(_t)(D.st)),ft=(()=>{const re=et(G)(pt.state.sink);if(re.tag==="Nothing")return G===G;if(re.tag==="Just")return re._1===G;c()})()?{...pt.state,sink:K(C)(G)((()=>{const re=et(_t)(pt.state.sink);if(re.tag==="Nothing")return _t;if(re.tag==="Just")return re._1;c()})())(pt.state.sink)}:pt.state,ht=et(_t)(ft.sink),Lt=(()=>{if(ht.tag==="Nothing")return _t;if(ht.tag==="Just")return ht._1;c()})(),Pt=et(G)(ft.sink),lt=(()=>{if(Pt.tag==="Nothing")return G;if(Pt.tag==="Just")return Pt._1;c()})();if(lt===Lt){const re=et(_t)(ft.x),je=(()=>{if(re.tag==="Just")return re._1;if(re.tag==="Nothing")return T;c()})(),sr=(()=>{if(je.tag==="Nothing")return 0;if(je.tag==="Just")return je._1;c()})(),_n=et(G)(ft.x),Gt=(()=>{if(_n.tag==="Just")return _n._1;if(_n.tag==="Nothing")return T;c()})(),Qt=(()=>{if(Gt.tag==="Nothing")return 0;if(Gt.tag==="Just")return Gt._1;c()})(),ar=N(P,j._1),In=et(j._1)(s),Rn=et(P)(s),cr=(()=>{if(In.tag==="Nothing")return 0;if(In.tag==="Just")return In._1;c()})()-(()=>{if(Rn.tag==="Nothing")return 0;if(Rn.tag==="Just")return Rn._1;c()})();if(f==="VDown"){const $e=We(sr+cr+p(j._1)+ar)(pt.thresh);return{st:{...ft,x:K(C)(G)(L("Just",D.initial?$e:We(Qt)($e)))(ft.x)},initial:!1,thresh:pt.thresh}}if(f==="VUp"){const $e=Ce(sr+cr-ar-p(P))(pt.thresh);return{st:{...ft,x:K(C)(G)(L("Just",D.initial?$e:Ce(Qt)($e)))(ft.x)},initial:!1,thresh:pt.thresh}}c()}const Rt=et(_t)(ft.x),mt=(()=>{if(Rt.tag==="Just")return Rt._1;if(Rt.tag==="Nothing")return T;c()})(),gt=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})(),it=et(G)(ft.x),rt=(()=>{if(it.tag==="Just")return it._1;if(it.tag==="Nothing")return T;c()})(),at=(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})(),Nt=ot(t.nodeGap),yt=et(P)(s),Ct=et(j._1)(s),Ot=(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()-(()=>{if(Ct.tag==="Nothing")return 0;if(Ct.tag==="Just")return Ct._1;c()})();return{st:{...ft,classEdges:[...ft.classEdges,{src:lt,tgt:Lt,sep:(()=>{if(f==="VDown")return at+Ot-gt-p(j._1)-Nt;if(f==="VUp")return at+Ot+p(P)+Nt-gt;c()})()}]},initial:D.initial,thresh:pt.thresh}}c()},tt=G=>D=>{const P=et(G)(D.x),A=(()=>{if(P.tag==="Just")return P._1;if(P.tag==="Nothing")return T;c()})();if(A.tag==="Just")return D;if(A.tag==="Nothing"){const H=J(U(G))({st:{...D,x:K(C)(G)(L("Just",0))(D.x)},initial:!0,thresh:(()=>{if(f==="VDown")return-1e18;if(f==="VUp")return 1e18;c()})()})(Ir(a)(G));return{...H.st,blockFinished:K(C)(G)(!0)(H.st.blockFinished)}}c()},Q=J(G=>D=>J(P=>A=>{const H=et(A)(a.root),Y=(()=>{if(H.tag==="Nothing")return A;if(H.tag==="Just")return H._1;c()})();return Y===A?tt(Y)(P):P})(G)((()=>{if(f==="VDown")return D;if(f==="VUp")return de(D);c()})()))({x:De(O(G=>w(G,T))(v)),sink:De(O(G=>w(G,G))(v)),classEdges:[],su:M,blockFinished:M,queue:[]})(h),S=Fh(Q.classEdges)(Q.sink)(f),Z=(G,D,P,A)=>{const H=et(D)(A),Y=et(D)(s);return(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;c()})()+(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;c()})()+d(G,D,P)},V=De(O(G=>w(G,!0))(zn(C.compare)((()=>{const G=(D,P)=>{if(D.tag==="Leaf")return P;if(D.tag==="Node")return G(D._5,Mt("Cons",D._4,G(D._6,P)));c()};return bt(Wt.foldr,G(a.root,qt))})()))),R=G=>D=>P=>{const A=E(P,{su:D.su,blockFinished:V}),H={phase:G,ppFree:P.free,ppIsRoot:P.isRoot,edgeId:T,delta:0,avail:0,shift:0,freeSu:(()=>{const Y=et((()=>{const W=et(P.free)(a.root);if(W.tag==="Nothing")return P.free;if(W.tag==="Just")return W._1;c()})())(D.su);if(Y.tag==="Nothing")return!1;if(Y.tag==="Just")return Y._1;c()})(),hasEdges:A.hasEdges,candCount:(()=>{if(P.isRoot){if(g==="HRight"){const Y=et(P.free)(y);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length;c()}if(g==="HLeft"){const Y=et(P.free)(x);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length}c()}if(g==="HRight"){const Y=et(P.free)(x);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length;c()}if(g==="HLeft"){const Y=et(P.free)(y);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length}c()})()};if(A.edge.tag==="Nothing")return{...D,stack:[...D.stack,P],trace:[...D.trace,H],x:D.x};if(A.edge.tag==="Just"){const Y=A.edge._1.from.node===P.free?w(A.edge._1.from.node,A.edge._1.to.node):w(A.edge._1.to.node,A.edge._1.from.node),W=Z(A.edge._1,Y._1,l(A.edge._1,Y._1),D.x)-Z(A.edge._1,Y._2,l(A.edge._1,Y._2),D.x),q=et(Y._1)(a.root),B=(()=>{if(q.tag==="Nothing")return Y._1;if(q.tag==="Just")return q._1;c()})(),j={...H,edgeId:L("Just",A.edge._1.id),delta:W};if(W>0&&W<1e300){const X=J(ft=>ht=>{const Lt=et(ht)(m),Pt=(()=>{if(Lt.tag==="Nothing")return-1;if(Lt.tag==="Just")return Lt._1;c()})();if(Pt>=0&&Pt<n.length){const mt=n[Pt],gt=et(ht)(e.nodeIndex),it=(()=>{if(gt.tag==="Nothing")return-2;if(gt.tag==="Just")return gt._1-1|0;c()})();return it>=0&&it<mt.length?Ce(ft)((()=>{const rt=et(ht)(D.x),at=et(ht)(s),Nt=et(mt[it])(D.x),yt=et(mt[it])(s);return(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+(()=>{if(at.tag==="Nothing")return 0;if(at.tag==="Just")return at._1;c()})()-((()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1;c()})()+(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+p(mt[it])+N(ht,mt[it]))})()):ft}const lt=et(ht)(e.nodeIndex),Rt=(()=>{if(lt.tag==="Nothing")return-2;if(lt.tag==="Just")return lt._1-1|0;c()})();return Rt>=0&&Rt<0?Ce(ft)((()=>{const mt=et(ht)(D.x),gt=et(ht)(s),it=et([][Rt])(D.x),rt=et([][Rt])(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})()+(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;c()})()-((()=>{if(it.tag==="Nothing")return 0;if(it.tag==="Just")return it._1;c()})()+(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+p([][Rt])+N(ht,[][Rt]))})()):ft})(W)(Ir(a)(B)),_t=X>0?-X:0,pt={...D,x:X>0?_(B,_t,D.x):D.x,trace:[...D.trace,{...j,avail:X,shift:_t}]};return X>0?pt:{...pt,stack:[...pt.stack,P]}}if(W<0&&-W<1e300){const X=J(ft=>ht=>{const Lt=et(ht)(m),Pt=(()=>{if(Lt.tag==="Nothing")return-1;if(Lt.tag==="Just")return Lt._1;c()})();if(Pt>=0&&Pt<n.length){const mt=n[Pt],gt=et(ht)(e.nodeIndex),it=(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1+1|0;c()})();return it>=0&&it<mt.length?Ce(ft)((()=>{const rt=et(mt[it])(D.x),at=et(mt[it])(s),Nt=et(ht)(D.x),yt=et(ht)(s);return(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+(()=>{if(at.tag==="Nothing")return 0;if(at.tag==="Just")return at._1;c()})()-((()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1;c()})()+(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+p(ht)+N(ht,mt[it]))})()):ft}const lt=et(ht)(e.nodeIndex),Rt=(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1+1|0;c()})();return Rt>=0&&Rt<0?Ce(ft)((()=>{const mt=et([][Rt])(D.x),gt=et([][Rt])(s),it=et(ht)(D.x),rt=et(ht)(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})()+(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;c()})()-((()=>{if(it.tag==="Nothing")return 0;if(it.tag==="Just")return it._1;c()})()+(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+p(ht)+N(ht,[][Rt]))})()):ft})(-W)(Ir(a)(B)),_t=X>0?X:0,pt={...D,x:X>0?_(B,_t,D.x):D.x,trace:[...D.trace,{...j,avail:X,shift:_t}]};return X>0?pt:{...pt,stack:[...pt.stack,P]}}return{...D,stack:[...D.stack,P],trace:[...D.trace,j],x:D.x}}c()},$=J(R(Ih))({x:De(O(G=>w(G,(()=>{const D=et(G)(a.root),P=(()=>{if(D.tag==="Nothing")return G;if(D.tag==="Just")return D._1;c()})(),A=et(P)(Q.x),H=et((()=>{const W=et(P)(Q.sink);if(W.tag==="Nothing")return P;if(W.tag==="Just")return W._1;c()})())(S),Y=(()=>{if(A.tag==="Just")return A._1;if(A.tag==="Nothing")return T;c()})();return(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;c()})()+(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;c()})()})()))(v)),su:Q.su,stack:[],trace:[]})(Q.queue),I=J(R(Rh))({...$,stack:[]})(de($.stack));return{x:I.x,queue:Q.queue,trace:I.trace}},zh=t=>e=>n=>r=>i=>o=>u=>s=>a=>f=>g=>$h(t)(e)(n)(r)(i)(o)(u)(s)(a)(f)(g).x,Oh=t=>e=>n=>r=>i=>o=>{const u=(a,f,g)=>{const d=et(f)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;c()})(),_=a.from.node===f?a.from.port:a.to.node===f?a.to.port:T;if(_.tag==="Just"){const h=et(f)(e);if(h.tag==="Just"){const p=ge(m=>m.id===_._1)(h._1);if(p.tag==="Just"){const m=ot(p._1.offset)*ot(4);return g==="North"||g==="South"?m:0}if(p.tag==="Nothing"){const m=er(i)(a.id)(g)(l);return g==="North"||g==="South"?m:0}c()}if(h.tag==="Nothing"){const p=er(i)(a.id)(g)(l);return g==="North"||g==="South"?p:0}c()}if(_.tag==="Nothing"){const h=er(i)(a.id)(g)(l);return g==="North"||g==="South"?h:0}c()},s=a=>f=>g=>d=>{let l=a,_=f,h=g,p=d,m=!0,N;for(;m;){const y=l,x=_,v=h,b=Bt(E=>T,E=>k=>L("Just",{head:E,tail:k}),p);if(b.tag==="Nothing"){m=!1,N=y;continue}if(b.tag==="Just"){const E=b._1.head,k=ge(U=>U.from.node===v&&U.to.node===E||U.from.node===E&&U.to.node===v)(r),F=(()=>{if(k.tag==="Nothing")return x+0;if(k.tag==="Just")return x+(u(k._1,v,k._1.from.node===v?ae:se)-u(k._1,E,k._1.from.node===E?ae:se));c()})();l=K(C)(E)(F)(y),_=F,h=E,p=b._1.tail;continue}c()}return N};return J(a=>f=>{const g=Bt(_=>T,_=>h=>L("Just",{head:_,tail:h}),Ir(t)(f)),d=(()=>{if(g.tag==="Nothing")return K(C)(f)(0)(M);if(g.tag==="Just")return s(K(C)(g._1.head)(0)(M))(0)(g._1.head)(g._1.tail);c()})(),l=J(_=>h=>We(_)(-h._2))(0)(Ar(d));return J(_=>h=>K(C)(h._1)(h._2+l)(_))(a)(Ar(d))})(M)(zn(C.compare)((()=>{const a=(f,g)=>{if(f.tag==="Leaf")return g;if(f.tag==="Node")return a(f._5,Mt("Cons",f._4,a(f._6,g)));c()};return bt(Wt.foldr,a(t.root,qt))})()))},qh=t=>e=>n=>r=>i=>{const o=Le(e),u=J(s=>a=>{const f=J(g=>d=>{const l=(()=>{if(i==="HRight"){const m=et(d)(t.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;c()}if(i==="HLeft"){const m=et(d)(t.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}c()})(),_=l.length;if(_===0)return g;const h=Fn(_-1|0,2),p=Fn(_,2);return J(m=>N=>{if((()=>{const y=et(d)(m.align);if(y.tag==="Nothing")return d!==d;if(y.tag==="Just")return y._1!==d;c()})())return m;if(N>=0&&N<l.length){const y=et(l[N])(t.nodeIndex),x=(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;c()})();if(!(Fa(l[N]+"\u2192"+d)(n)||Fa(d+"\u2192"+l[N])(n))&&(()=>{if(r==="VDown")return m.r<x;if(r==="VUp")return m.r>x;c()})()){const v=et(l[N])(m.root),b=(()=>{if(v.tag==="Nothing")return l[N];if(v.tag==="Just")return v._1;c()})();return{root:K(C)(d)(b)(m.root),align:K(C)(l[N])(d)(K(C)(d)(b)(m.align)),r:x}}}return m})(g)((()=>{if(r==="VDown")return Ht(h,p);if(r==="VUp")return de(Ht(h,p));c()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;c()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return de(a);c()})());return{root:f.root,align:f.align}})({root:De(O(s=>w(s,s))(o)),align:De(O(s=>w(s,s))(o))})((()=>{if(i==="HRight")return e;if(i==="HLeft")return de(e);c()})());return{root:u.root,align:u.align}},vi=t=>e=>n=>r=>i=>o=>u=>s=>a=>f=>{const g=qh(e)(n)(s)(a)(f),d=Oh(g)(i)(r)(o)(u)(f);return cg()(l=>_=>L("Just",(()=>{const h=et(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;c()})()))(zh(t)(e)(n)(r)(i)(o)(u)(d)(g)(a)(f))},qa=t=>e=>At(n=>r=>J(i=>o=>o>=0&&o<e.length?o>=0&&o<t.length?i+e[o]+t[o]:i+e[o]+0:o>=0&&o<t.length?i+1+t[o]:i+1)(0)((()=>{const i=Ht(0,e.length-1|0);return n<1?[]:It(0,n,i)})()))(e),Hh=t=>e=>n=>r=>i=>o=>u=>{const s=Dh(0)(e.length-1|0),a=ot(t.layerGap),f=u(Vf(s,a)),g=Wl(Sa(i)(f)(r)(o)(M))(f);return O(d=>{const l=Ah(d)(g);return l.tag==="Just"&&l._1>0?We(a)(2+ot(l._1-1|0)*2.5):a})(Ht(0,s-1|0))},Ha=t=>e=>n=>r=>Wu(i=>J(o=>u=>{if(!o.ok)return o;const s=et(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})(),f=et(u)(n),g=(()=>{if(f.tag==="Nothing")return a+1;if(f.tag==="Just")return a+f._1._1;c()})();return a+1e-4>o.pos&&g+1e-4>o.pos?{ok:!0,pos:g}:{ok:!1,pos:o.pos}})({ok:!0,pos:-1e18})(i).ok,e),Wh=t=>e=>n=>r=>{const i=vt(o=>u=>dt.compare(o.w)(u.w))(O(o=>({l:o,w:Oa(o)}))(ct(Ha()(e)(n),r)));return 0<i.length?L("Just",i[0].l):T},Vh=t=>e=>{const n=De(Le(O(At(i=>o=>w(o,i)))(t))),r=i=>vt(o=>u=>nt.compare((()=>{const s=et(o)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})())((()=>{const s=et(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(i);return{preds:(()=>{const i=o=>{if(o.tag==="Leaf")return M;if(o.tag==="Node")return $t("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));c()};return i(J(o=>u=>Tt(C)(ue)(u.to.node)([u.from.node])(o))(M)(e))})(),succs:(()=>{const i=o=>{if(o.tag==="Leaf")return M;if(o.tag==="Node")return $t("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));c()};return i(J(o=>u=>Tt(C)(ue)(u.from.node)([u.to.node])(o))(M)(e))})(),nodeIndex:n}},Uh=t=>e=>{const n=vt(d=>l=>dt.compare(d.w)(l.w))(At(d=>l=>({i:d,l,w:Oa(l)}))(e)),r=0<n.length?L("Just",n[0]):T,i=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;c()})(),o=i>=0&&i<e.length?L("Just",e[i]):T,u=(()=>{if(o.tag==="Just")return(d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const N=_,y=h;if(y.tag==="Nil"){p=!1,m=N;continue}if(y.tag==="Cons"){_=Ce(N)(y._1),h=y._2;continue}c()}return m})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,Mt("Cons",l._4,d(l._6,_)));c()};return d(o._1,qt)})());if(o.tag==="Nothing")return 0;c()})(),s=d=>J(l=>_=>We(l)((()=>{const h=et(_._1)(t);if(h.tag==="Nothing")return _._2+1;if(h.tag==="Just")return _._2+h._1._1;c()})()))(-999999)(Ar(d)),a=i>=0&&i<e.length?L("Just",e[i]):T,f=(()=>{if(a.tag==="Just")return s(a._1);if(a.tag==="Nothing")return 0;c()})(),g=ye(d=>l=>{const _=h=>{if(h.tag==="Leaf")return M;if(h.tag==="Node")return $t("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));c()};return _(d)},e,At(d=>l=>no(d)(2)===0?u-(_=>h=>{let p=_,m=h,N=!0,y;for(;N;){const x=p,v=m;if(v.tag==="Nil"){N=!1,y=x;continue}if(v.tag==="Cons"){p=Ce(x)(v._1),m=v._2;continue}c()}return y})(999999)((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,Mt("Cons",h._4,_(h._6,p)));c()};return _(l,qt)})()):f-s(l))(e));return Bh(J(d=>l=>{const _=vt(dt.compare)(xt(et(l))(g));return K(C)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(M)(zn(C.compare)(Le(O(d=>{const l=_=>{if(_.tag==="Leaf")return M;if(_.tag==="Node")return $t("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));c()};return bt(Ge.foldr,l(d))})(g)))))},Yh=t=>e=>n=>r=>i=>o=>{const u=Vh(e)(i),s=Mh(u)(e),a={nodeGap:t.nodeGap*4|0},f=xe(C.compare,pe,De(O(_=>w(_,w(0,1)))(ct(_=>ce(3)(_)==="$d:",Le(e)))),(()=>{const _=h=>{if(h.tag==="Leaf")return M;if(h.tag==="Node")return $t("Node",h._1,h._2,h._3,w(h._4._1*ot(4),h._4._2),_(h._5),_(h._6));c()};return _(n)})()),g=[vi(a)(u)(e)(f)(r)(i)(o)(s)(Ba)($a),vi(a)(u)(e)(f)(r)(i)(o)(s)(Ma)($a),vi(a)(u)(e)(f)(r)(i)(o)(s)(Ba)(za),vi(a)(u)(e)(f)(r)(i)(o)(s)(Ma)(za)],d=Uh(f)(g);if(Ha()(e)(f)(d))return d;const l=Wh()(e)(f)(g);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return g[0];c()},Xh=t=>e=>n=>r=>{const i=Uf(T,Nf,o=>o.node===e?L("Just",o.position):T,t);if(i.tag==="Nothing")return t;if(i.tag==="Just"){const o=i._1;return O(u=>u.node===n?{...u,position:w(o._1+r._1,o._2+r._2)}:u)(t)}c()},Kh=t=>e=>n=>r=>{const i=ct(u=>ke(ze)(u.node)(e),t),o=(()=>{if(n==="Vertical"){if(r==="Start")return J(u=>s=>Ce(u)(s.position._1))(99999)(i);if(r==="End")return J(u=>s=>We(u)(s.position._1))(0)(i);if(r==="Center"){const u=J(s=>a=>s+a.position._1)(0)(i);return i.length===0?0:u/ot(i.length)}c()}if(n==="Horizontal"){if(r==="Start")return J(u=>s=>Ce(u)(s.position._2))(99999)(i);if(r==="End")return J(u=>s=>We(u)(s.position._2))(0)(i);if(r==="Center"){const u=J(s=>a=>s+a.position._2)(0)(i);return i.length===0?0:u/ot(i.length)}}c()})();return O(u=>{if(ke(ze)(u.node)(e)){if(n==="Vertical")return{...u,position:w(o,u.position._2)};if(n==="Horizontal")return{...u,position:w(u.position._1,o)};c()}return u})(t)},jh=t=>e=>J(n=>r=>{if(r.tag==="Lock"){const i=r._1.node,o=r._1.position;return O(u=>u.node===i?{...u,position:o}:u)(n)}return r.tag==="AlignGroup"?Kh(n)(O(qu)(r._1.nodes))(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?Xh(n)(r._1.anchor)(r._1.target)(r._1.offset):n})(e)(t),Zh=t=>e=>n=>r=>i=>o=>u=>s=>{const a=De(O(_=>w(_._1,_._2))(Ar(r))),f=O(O(qu))(n),g=O(_=>J(h=>p=>We(h)((()=>{const m=et(p)(a);if(m.tag==="Nothing")return 1;if(m.tag==="Just")return m._1._2;c()})()))(1)(_))(f),d=Yh(t)(f)(a)(De(O(_=>w(_._1,_._2))(Ar(i))))(o)(s),l=qa(Hh(t)(n)(r)(i)(o)(u)(_=>{const h=qa(_)(g);return Le(At(p=>m=>At(N=>y=>({node:y,position:w((()=>{const x=et(y)(d);return(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;c()})()/ot(4)})(),p>=0&&p<h.length?h[p]:0),size:(()=>{const x=ce(3)(y)==="$d:"?w(0,1):w(1,1),v=et(y)(a);if(v.tag==="Nothing")return x;if(v.tag==="Just")return v._1;c()})(),layer:p,order:N}))(m))(f))}))(g);return jh(e)(Le(At(_=>h=>At(p=>m=>({node:m,position:w((()=>{const N=et(m)(d);return(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})()/ot(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const N=ce(3)(m)==="$d:"?w(0,1):w(1,1),y=et(m)(a);if(y.tag==="Nothing")return N;if(y.tag==="Just")return y._1;c()})(),layer:_,order:p}))(h))(f)))},su=Lo(oi)(kn(32)),Wa=Lo(oi)(kn(31)),Rr=(()=>{const t=__("25214903917");if(t.tag==="Nothing")return ls;if(t.tag==="Just")return t._1;c()})(),Fr=wo(Lo(oi)(kn(48)))(oi),t0=t=>{const e=d_(t);return wr(hs((()=>{if(e.tag==="Nothing")return ls;if(e.tag==="Just")return e._1;c()})())(Rr))(Fr)},au=kn(11),wi=t=>e=>{const n=wr(ri(ii(e)(Rr))(au))(Fr);return w((()=>{const r=ts(a_(bo(n)(kn(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;c()})(),n)},e0=t=>{const e=wi(26)(t),n=wi(27)(e._2);return w((ot(e._1)*to(2)(27)+ot(n._1))/to(2)(53),n._2)},n0=t=>e=>{const n=J(r=>i=>{const o=e0(r.finalR);return{rs:[...r.rs,o._1],finalR:o._2}})({rs:[],finalR:t})(e);return w(O(r=>r.x)(vt(r=>i=>dt.compare(r.k)(i.k))(ye(r=>i=>({x:r,k:i}),e,n.rs))),n.finalR)},r0=t=>{const e=wr(ri(ii(t)(Rr))(au))(Fr),n=wr(ri(ii(e)(Rr))(au))(Fr);return w(ri(ii((()=>{const r=bo(e)(kn(16));return ps.compare(r)(Wa)!=="LT"?wo(r)(su):r})())(su))((()=>{const r=bo(n)(kn(16));return ps.compare(r)(Wa)!=="LT"?wo(r)(su):r})()),n)},Br=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Li=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},cu=Vt(C)(Dt),Ve=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},bi=Vt(C)(Dt),i0=Bf(Xi),o0=J(Wn)(0),u0=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Va=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},s0=t=>e=>n=>r=>i=>cu(J(o=>u=>{const s=vt(a=>f=>nt.compare((()=>{const g=Br(a.id)(i);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;c()})())((()=>{const g=Br(f.id)(i);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;c()})()))(ct(a=>Li(a.to.node)(n),ct(a=>a.from.node===u,r)));return{ranks:[...o.ranks,...At(a=>f=>w(f.id,ot((o.rankSum+a|0)+1|0)))(s)],rankSum:o.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),a0=t=>e=>n=>r=>i=>cu(J(o=>u=>{const s=vt(f=>g=>{const d=nt.compare((()=>{const l=Ve(g.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Ve(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})());return d==="EQ"?nt.compare((()=>{const l=Br(f.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Br(g.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})()):d})(ct(f=>Li(f.from.node)(n),ct(f=>f.to.node===u,r))),a=s.length;return{ranks:[...o.ranks,...At(f=>g=>w(g.id,ot((o.rankSum+a|0)-f|0)))(s)],rankSum:o.rankSum+a|0}})({ranks:[],rankSum:0})(t).ranks),fu=t=>e=>n=>{const r=bi(At(s=>a=>w(a,s))(t)),i=bi(At(s=>a=>w(a,s))(e)),o=xt(s=>{const a=Ve(s.from.node)(r),f=Ve(s.to.node)(i);if(a.tag==="Just"&&f.tag==="Just")return L("Just",w(a._1,f._1));const g=Ve(s.from.node)(i),d=Ve(s.to.node)(r);return g.tag==="Just"&&d.tag==="Just"?L("Just",w(d._1,g._1)):T})(n),u=o.length;return J(s=>a=>J(f=>g=>a>=0&&a<o.length&&g>=0&&g<o.length&&((o[a]._1-o[g]._1|0)*(o[a]._2-o[g]._2|0)|0)<0?f+1|0:f)(s)(Ht(a+1|0,u-1|0)))(0)(Ht(0,u-2|0))},c0=t=>e=>n=>r=>i=>{const o=u=>s=>{let a=u,f=s,g=!0,d;for(;g;){const l=a,_=f;if(_>=(l.length-1|0)){g=!1,d=l;continue}const h=_>=0&&_<l.length?L("Just",l[_]):T,p=_+1|0;if(p>=0&&p<l.length&&h.tag==="Just"){const m=h._1,N=l[p];if(Ze(b=>b.before===m&&b.after===N,i)){a=l,f=_+1|0;continue}if((()=>{const b=Ve(m)(t),E=Ve(N)(t);return b.tag==="Just"&&E.tag==="Just"&&b._1<E._1})()){a=l,f=_+1|0;continue}const y=$n(jt,T,_,N,l),x=(()=>{if(y.tag==="Just")return $n(jt,T,_+1|0,m,y._1);if(y.tag==="Nothing")return T;c()})(),v=(()=>{if(x.tag==="Nothing")return l;if(x.tag==="Just")return x._1;c()})();if(fu(n)(v)(r)<fu(n)(l)(r)){a=v,f=_+1|0;continue}a=l,f=_+1|0;continue}g=!1,d=l}return d};return(u=>{let s=u,a=!0,f;for(;a;){const g=s,d=o(g)(0);if(i0(d)(g)){a=!1,f=g;continue}s=d}return f})(e)},Ei=t=>e=>J(n=>r=>{if(r>=0&&r<t.length){const i=t[r],o=r+1|0;if(o>=0&&o<t.length)return n+fu(i)(t[o])(e)|0}return n})(0)(Ht(0,t.length-2|0)),f0=t=>e=>n=>{const r=xt(f=>f.tag==="OrderConstraint"?L("Just",{before:f._1.before,after:f._1.after}):T)(t.constraints),i=f=>J(g=>d=>{const l=d.after,_=d.before,h=Mn(jt,T,m=>m===_,g),p=Mn(jt,T,m=>m===l,g);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=Hu(jt,T,h._1,g),N=(()=>{if(m.tag==="Nothing")return g;if(m.tag==="Just")return m._1;c()})(),y=Xf(jt,T,p._1,_,N);if(y.tag==="Nothing")return N;if(y.tag==="Just")return y._1;c()}return g})(f)(r),o=cu(At(f=>g=>w(g.id,f))(n)),u=(f,g,d)=>{const l=f.length;return J(_=>h=>{const p=g?h-1|0:h+1|0,m=p>=0&&p<_._1.length?L("Just",_._1[p]):T;if(m.tag==="Just"){const N=h>=0&&h<_._1.length?L("Just",_._1[h]):T;if(N.tag==="Just"){const y=bi(At(k=>F=>w(F,k))(m._1)),x=bi(At(k=>F=>w(F,k))(N._1)),v=g?s0(m._1)(y)(x)(n)(o):a0(m._1)(y)(x)(n)(o),b=J(k=>F=>{const U=xt(Q=>Br(Q.id)(v))(ct(g?Q=>Q.to.node===F._2&&Li(Q.from.node)(y):Q=>Q.from.node===F._2&&Li(Q.to.node)(y),n));if(U.length===0)return{...k,items:[...k.items,{n:F._2,key:T,origIdx:F._1}]};const tt=wi(24)(k.r);return{items:[...k.items,{n:F._2,key:L("Just",(o0(U)+(ot(tt._1)*4172325152040912e-24-.03500000014901161))/ot(U.length)),origIdx:F._1}],r:tt._2}})({items:[],r:_._2})(At(Bn)(N._1)),E=$n(jt,T,h,c0(t.modelOrder)(i(O(k=>k.n)(vt(k=>F=>{const U=Ve(k.n)(t.modelOrder),tt=Ve(F.n)(t.modelOrder);if(U.tag==="Just"&&tt.tag==="Just"){const Q=nt.compare(U._1)(tt._1);return Q==="EQ"?dt.compare(k.key)(F.key):Q}return dt.compare(k.key)(F.key)})((()=>{const k=b.items,F=U=>tt=>{let Q=U,S=tt,Z=!0,V;for(;Z;){const R=Q,$=S;if(R>=0&&R<k.length){if(k[R].key.tag==="Just"){Z=!1,V=k[R].key._1;continue}if(k[R].key.tag==="Nothing"){Q=R+1|0,S=$;continue}c()}Z=!1,V=$}return V};return(U=>tt=>Q=>{let S=U,Z=tt,V=Q,R=!0,$;for(;R;){const I=S,G=Z,D=V;if(I>=0&&I<k.length){if(k[I].key.tag==="Just"){S=I+1|0,Z=k[I].key._1,V=[...D,{n:k[I].n,key:k[I].key._1,origIdx:k[I].origIdx}];continue}if(k[I].key.tag==="Nothing"){const P=(G+F(I+1|0)(G+1))/2;S=I+1|0,Z=P,V=[...D,{n:k[I].n,key:P,origIdx:k[I].origIdx}];continue}c()}R=!1,$=D}return $})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(E.tag==="Just")return w(E._1,b.r);if(E.tag==="Nothing")return w(_._1,_._2);c()}if(N.tag==="Nothing")return w(_._1,_._2);c()}if(m.tag==="Nothing")return w(_._1,_._2);c()})(w(f,d))(g?Ht(1,l-1|0):de(Ht(0,l-2|0)))},s=J(f=>g=>K(C)(g.from.node)()(K(C)(g.to.node)()(f)))(M)(n),a=J(f=>g=>{if(f.result.crossings===0)return f;const d=y=>x=>v=>b=>{let E=y,k=x,F=v,U=b,tt=!0,Q;for(;tt;){const S=E,Z=k,V=F,R=U;if(V===0){tt=!1,Q={layout:S,crossings:0,random:R};continue}const $=u(S,Z,R),I=Ei($._1)(n);if(I<V){E=$._1,k=!Z,F=I,U=$._2;continue}tt=!1,Q={layout:S,crossings:V,random:$._2}}return Q},l=wi(1)(f.result.random),_=l._1!==0,h=t.modelOrder.tag==="Leaf",p=(f.firstTry||f.secondTry)&&!h?f.firstTry:_,m=(()=>{if(!h){const b=u(e,p,l._2);return d(b._1)(!p)(Ei(b._1)(n))(b._2)}const y=p?0:u0(0)(e.length-1|0),x=y>=0&&y<e.length?L("Just",e[y]):T;if(x.tag==="Just"&&x._1.length>1){const b=ct(E=>Va(E)(s),x._1);if(b.length>1){const E=n0(l._2)(b),k=E._1,F=$n(jt,T,y,i(J(U=>tt=>Va(tt)(s)?U.idx>=0&&U.idx<k.length?{idx:U.idx+1|0,result:[...U.result,k[U.idx]]}:{idx:U.idx,result:[...U.result,tt]}:{idx:U.idx,result:[...U.result,tt]})({idx:0,result:[]})(x._1).result),e);if(F.tag==="Just"){const U=u(F._1,p,E._2);return d(U._1)(!p)(Ei(U._1)(n))(U._2)}}}const v=u(e,p,l._2);return d(v._1)(!p)(Ei(v._1)(n))(v._2)})(),N=f.secondTry?!1:f.secondTry;return f.firstTry?{result:m.crossings<f.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...f.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<f.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...f.result,random:m.random},firstTry:f.firstTry,secondTry:N}})({result:{layout:e,crossings:1e9,random:wr(hs(r0(t0(1))._1)(Rr))(Fr)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Ht(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:a.layout},g0=t=>t,Ua=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},he=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},nr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Mr=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=C.compare(e._1)(n._1);return r==="LT"?me:r==="GT"?Ne:C.compare(e._2)(n._2)},Eq0:()=>t}})(),_0=Vt(C)(Dt),d0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=Mr.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},l0=g0("Greedy"),gu=t=>e=>n=>J(r=>i=>{if(i.from.node===i.to.node)return r;if(i.from.node===e&&!Ua(i.to.node)(r.marks)){const o=he(i.to.node)(r.inDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;c()})(),s=K(C)(i.to.node)(u)(r.inDeg);return(()=>{const a=he(i.to.node)(r.outDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;c()})()&&!ke(ze)(i.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,i.to.node]}:{...r,inDeg:s}}if(i.to.node===e&&!Ua(i.from.node)(r.marks)){const o=he(i.from.node)(r.outDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;c()})(),s=K(C)(i.from.node)(u)(r.outDeg);return(()=>{const a=he(i.from.node)(r.inDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;c()})()&&!ke(ze)(i.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,i.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:ct(r=>r!==e,n.remaining)})(t),h0=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return K(C)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return K(C)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return K(C)(e._1.node)(99999)(t)}return t})(M),Ya=t=>e=>n=>{const r=he(e)(t),i=he(n)(t);return r.tag==="Just"&&i.tag==="Just"&&r._1>i._1},Xa=t=>e=>n=>r=>{if(nr(n)(r.visited)||nr(n)(r.visiting))return r;const i=J(p0(t)(e)(n))({...r,visiting:K(C)(n)()(r.visiting)})((()=>{const o=he(n)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;c()})());return{...i,visiting:hr(C)(n)(i.visiting),visited:K(C)(n)()(i.visited)}},p0=t=>e=>n=>r=>i=>Ya(t)(n)(i)?{...r,backEdges:K(Mr)(w(n,i))()(r.backEdges)}:nr(i)(r.visiting)?{...r,backEdges:K(Mr)(w(n,i))()(r.backEdges)}:nr(i)(r.visited)?r:Xa(t)(e)(i)(r),m0=t=>e=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,N=Bt(y=>T,y=>x=>L("Just",{head:y,tail:x}),m.sinks);if(N.tag==="Just"){_=gu(n)(N._1.head)({...m,sinks:N._1.tail,marks:K(C)(N._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(N.tag==="Nothing"){const y=Bt(x=>T,x=>v=>L("Just",{head:x,tail:v}),m.sources);if(y.tag==="Just"){_=gu(n)(y._1.head)({...m,sources:y._1.tail,marks:K(C)(y._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(y.tag==="Nothing"){const x=b=>{const E=he(b)(m.outDeg),k=he(b)(m.inDeg);return(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;c()})()-(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;c()})()|0},v=vt(b=>E=>{const k=nt.compare(x(E))(x(b));return k==="EQ"?nt.compare((()=>{const F=he(b)(e);if(F.tag==="Nothing")return 1e6;if(F.tag==="Just")return F._1;c()})())((()=>{const F=he(E)(e);if(F.tag==="Nothing")return 1e6;if(F.tag==="Just")return F._1;c()})()):k})(m.remaining);if(0<v.length){const b=v[0];_=gu(n)(b)({...m,remaining:ct(E=>E!==b,m.remaining),marks:K(C)(b)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}c()}return p},i=zn(C.compare)([...O(l=>l.from.node)(n),...O(l=>l.to.node)(n)]),o=ct(l=>l.from.node!==l.to.node,n),u=J(l=>_=>Tt(C)(Zt)(_.to.node)(1)(l))(M)(o),s=J(l=>_=>Tt(C)(Zt)(_.from.node)(1)(l))(M)(o),a=ct(l=>{const _=he(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;c()},i),f=ct(l=>{const _=he(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;c()},i),g=i.length+1|0,d=J(l=>_=>{const h=he(_)(l);return h.tag==="Just"&&h._1<0?K(C)(_)(h._1+g|0)(l):l})(r({remaining:ct(l=>!ke(ze)(l)(a)&&!ke(ze)(l)(f),i),marks:M,inDeg:u,outDeg:s,sources:a,sinks:f,nextLeft:1,nextRight:-1}).marks)(i);return J(l=>_=>{if(_.from.node===_.to.node)return l;if(Ya(t)(_.from.node)(_.to.node))return K(Mr)(w(_.from.node,_.to.node))()(l);const h=he(_.from.node)(d),p=he(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?K(Mr)(w(_.from.node,_.to.node))()(l):l})(M)(n)},N0=J(t=>e=>Tt(C)(ue)(e.from.node)([e.to.node])(t))(M),y0=t=>e=>{const n=N0(e),r=zn(C.compare)([...O(o=>o.from.node)(e),...O(o=>o.to.node)(e)]),i=J(o=>u=>K(C)(u.to.node)()(o))(M)(e);return J(o=>u=>Xa(t)(n)(u)(o))({visiting:M,visited:M,backEdges:M})([...ct(o=>!nr(o)(i),r),...ct(o=>nr(o)(i),r)]).backEdges},J0=t=>e=>n=>r=>{const i=_0(At(s=>a=>w(a,s))(e)),o=h0(n),u=(()=>{if(t==="DepthFirst")return y0(o)(r);if(t==="Greedy")return m0(o)(i)(r);c()})();return{edges:O(s=>d0(w(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},Ka=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},x0=t=>e=>n=>J(r=>i=>{const o=Ka(i.from.node)(t),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;c()})(),s=Ka(i.to.node)(t),a=(()=>{if(s.tag==="Nothing")return-u;if(s.tag==="Just")return s._1-u|0;c()})();if(a<=1)return{...r,edges:[...r.edges,i],chains:[...r.chains,{edgeId:i.id,nodes:[i.from.node,i.to.node]}]};const f=i.id,g=O(l=>"$d:"+f+":"+fe(l))(Ht(1,a-1|0)),d=[i.from.node,...g,i.to.node];return{...r,layers:J(l=>_=>{const h=_._2,p=Zf(u+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;c()})(r.layers)(ye(Bn,Ht(1,a-1|0),g)),edges:[...r.edges,...ye(l=>_=>({id:f+":"+l+"->"+_,from:{node:l,port:i.from.port},to:{node:_,port:i.to.port}}),d,It(1,d.length,d))],chains:[...r.chains,{edgeId:i.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),ja=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},T0=J(t=>e=>K(C)(e)()(t))(M),ki=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},v0=da(C),Ue=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Za=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},_u=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},w0=Vt(nt)(Dt),L0=t=>e=>xe(C.compare,pe,t,e),tc=At(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),b0=t=>J(e=>n=>({base:(()=>{const r=i=>o=>{let u=i,s=o,a=!0,f;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,f=g;continue}if(d.tag==="Cons"){u=ja(g)(d._1),s=d._2;continue}c()}return f};return(e.base+r(0)((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,Mt("Cons",o._4,i(o._6,u)));c()};return i(n,qt)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=i=>{if(i.tag==="Leaf")return M;if(i.tag==="Node")return $t("Node",i._1,i._2,i._3,i._4+e.base|0,r(i._5),r(i._6));c()};return r(n)})()]}))({base:0,result:[]})(t).result,E0=t=>e=>{const n=T0(t);return v0(t)(tc(ct(r=>ki(r.src)(n)&&ki(r.tgt)(n),e)))},k0=t=>e=>{const n=J(i=>o=>Tt(C)(ue)(o.tgt)([o.src])(Tt(C)(ue)(o.src)([o.tgt])(i)))(M)(e),r=i=>o=>u=>{let s=i,a=o,f=u,g=!0,d;for(;g;){const l=s,_=a,h=f,p=Bt(m=>T,m=>N=>L("Just",{head:m,tail:N}),l);if(p.tag==="Nothing"){g=!1,d={nodes:h};continue}if(p.tag==="Just"){if(ki(p._1.head)(_)){s=p._1.tail,a=_,f=h;continue}s=[...p._1.tail,...(()=>{const m=Ue(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;c()})()],a=K(C)(p._1.head)()(_),f=[...h,p._1.head];continue}c()}return d};return J(i=>o=>{if(ki(o)(i.visited))return i;const u=r([o])(i.visited)([]);return{...i,visited:J(s=>a=>K(C)(a)()(s))(i.visited)(u.nodes),components:[...i.components,u.nodes]}})({visited:M,components:[]})(t).components},G0=t=>e=>n=>{const r=J(o=>u=>Tt(C)(Zt)(u.tgt)(1)(o))(M)(e),i=J(o=>u=>Tt(C)(Zt)(u.src)(1)(o))(M)(e);return J(o=>u=>{const s=Ue(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})();if((()=>{const y=Ue(u)(i);return(()=>{if(y.tag==="Nothing")return a!==0;if(y.tag==="Just")return a!==y._1;c()})()||a===0})())return o;const f=Ue(u)(o.layers),g=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;c()})(),d=o.layers,l=J(y=>x=>x.tgt===u?{...y,mIn:Za(y.mIn)((()=>{const v=Ue(u)(d),b=Ue(x.src)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;c()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;c()})()|0})())}:x.src===u?{...y,mOut:Za(y.mOut)((()=>{const v=Ue(x.tgt)(d),b=Ue(u)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;c()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;c()})()|0})())}:y)({mIn:1e9,mOut:1e9})(e),_=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(_<0||h<0)return o;const p=(g-_|0)+1|0,m=(g+h|0)-1|0;if(m<p)return o;const N=J(y=>x=>{const v=_u(x)(o.filling),b=(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;c()})();return b<y.bestFill?{best:x,bestFill:b}:y})({best:g,bestFill:(()=>{const y=_u(g)(o.filling);if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;c()})()})(Ht(p,m));return N.best===g?o:{layers:K(C)(u)(N.best)(o.layers),filling:K(nt)(g)((()=>{const y=_u(g)(o.filling);if(y.tag==="Nothing")return-1;if(y.tag==="Just")return y._1-1|0;c()})())(K(nt)(N.best)(N.bestFill+1|0)(o.filling))}})({layers:n,filling:w0(O(o=>w(o,J(u=>s=>(()=>{const a=Ue(s)(n);return a.tag==="Nothing"?!1:a.tag==="Just"&&a._1===o})()?u+1|0:u)(0)(t)))(Ht(0,J(o=>u=>ja(o)((()=>{const s=Ue(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(0)(t))))})(t).layers},C0=t=>e=>G0(t)(tc(e))(J(L0)(M)(b0(O(n=>E0(n)(e))(k0(t)(e))))),S0=t=>t,Qn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Gi=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},ec=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),Q0=S0("NetworkSimplex"),P0=t=>e=>J(n=>r=>{const i=J(Gi)(0)(xt(o=>Qn(o)(n))(r));return J(o=>u=>K(C)(u)(i)(o))(n)(r)})(e)(t),D0=t=>e=>({layers:O(n=>ct(r=>{const i=Qn(r)(e);return i.tag==="Nothing"?!1:i.tag==="Just"&&i._1===n},t))(Ht(0,(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,f=o;if(f.tag==="Nil"){u=!1,s=a;continue}if(f.tag==="Cons"){i=Gi(a)(f._1),o=f._2;continue}c()}return s})(0)((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._4,n(r._6,i)));c()};return n(e,qt)})()))),nodeLayer:e}),A0=t=>e=>n=>{const r=J(i=>o=>K(C)(o)(!0)(i))(M)(e);return J(i=>o=>K(C)(o._1)(o._2)(i))(C0(e)(xt(i=>i.from.node===i.to.node||(()=>{const o=Qn(i.from.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;c()})()||(()=>{const o=Qn(i.to.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;c()})()?T:L("Just",{src:i.from.node,tgt:i.to.node}))(t)))(ec(n))},I0=t=>e=>n=>r=>{const i=s=>a=>{const f=Qn(a)(s);if(f.tag==="Just")return s;if(f.tag==="Nothing"){const g=ct(l=>l!==a,(()=>{const l=Qn(a)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;c()})()),d=J(i)(s)(g);return K(C)(a)(1+J(Gi)(0)(xt(l=>Qn(l)(d))(g))|0)(d)}c()},o=J(i)(M)(n),u=(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){f=Gi(_)(h._1),g=h._2;continue}c()}return l})(1)((()=>{const s=(a,f)=>{if(a.tag==="Leaf")return f;if(a.tag==="Node")return s(a._5,Mt("Cons",a._4,s(a._6,f)));c()};return s(o,qt)})());return J(s=>a=>K(C)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return M;if(a.tag==="Node")return $t("Node",a._1,a._2,a._3,u-a._4|0,s(a._5),s(a._6));c()};return s(o)})())(ec(r))},R0=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return K(C)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return K(C)(e._1.node)(0)(t)}return t})(M),F0=J(t=>e=>Tt(C)(ue)(e.to.node)([e.from.node])(t))(M),B0=J(t=>e=>Tt(C)(ue)(e.from.node)([e.to.node])(t))(M),M0=t=>e=>n=>r=>{const i=B0(n),o=F0(n),u=R0(e);return D0(r)(P0(xt(s=>s.tag==="SameLayer"?L("Just",s._1.nodes):T)(e))((()=>{if(t==="LongestPath")return I0(i)(o)(r)(u);if(t==="NetworkSimplex")return A0(n)(r)(u);c()})()))},$0=Vt(C)(Dt),z0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},nc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},rc=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},$r=Vt(C)(Dt),O0=Vt(C)(Dt),ic=(()=>{const t=O(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>de(t(e))})(),q0=t=>e=>n=>r=>{const i=$0(O(u=>w(u.edge,u))(r)),o=u=>0<u.nodes.length&&(()=>{const s=z0(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return O(u=>{if(u.nodes.length<=2){const g=nc(u.edgeId)(i);if(g.tag==="Just"){const d=o(u);return{...g._1,edge:u.edgeId,segments:d?ic(g._1.segments):g._1.segments,reversed:d}}if(g.tag==="Nothing")return{edge:u.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};c()}const s=St(xt(g=>nc(g)(i))(ye(g=>d=>u.edgeId+":"+g+"->"+d,u.nodes,It(1,u.nodes.length,u.nodes))))(g=>g.segments),a=o(u),f=nu(a?ic(s):s);return{edge:u.edgeId,segments:f,bends:ye(g=>d=>g.end,f,It(1,f.length,f)),bendType:[],jumps:[],reversed:a}})(t)},H0={layers:[],edges:[],chains:[]},W0={nodeGap:3,layerGap:2,iterations:8,layerer:Q0,cycleBreaker:l0,compactPostRouting:!0},V0=t=>({pos:w(0,0),size:w(J(e=>n=>rc(e)(n.position._1+n.size._1))(0)(t),J(e=>n=>rc(e)(n.position._2+n.size._2))(0)(t))}),U0=t=>e=>n=>{const r=$r(O(f=>w(f.id,f.ports))(e.nodes)),i=ct(f=>ce(3)(f.node)!=="$d:",n.placements),o=q0(n.withDummies.chains)(n.acyclic.reversedEdges)(O0(O(f=>w(f.id,w(f.from.node,f.to.node)))(e.edges)))(xh(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(Da(n.ordered)(ct(f=>f.from.node!==f.to.node,n.withDummies.edges))((()=>{const f=g=>{if(g.tag==="Leaf")return M;if(g.tag==="Node")return $t("Node",g._1,g._2,g._3,w(g._4._1*4,g._4._2),f(g._5),f(g._6));c()};return f($r(O(g=>w(g.id,g.size))(e.nodes)))})()))),u=t.compactPostRouting?zl()({nodes:i,edges:e.edges,paths:o,ports:r}):{nodes:i,edges:o},s=u.edges,a=At(f=>g=>({...g,jumps:kh(f)(g)(s)}))(s);return{nodes:u.nodes,edges:a,boundingBox:V0(u.nodes),metrics:bd(u.nodes)(a)(0)}},Y0=t=>e=>n=>{const r=$r(O(o=>w(o.id,o.size))(e.nodes)),i={...n,placements:Zh({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)($r(O(o=>w(o.id,o.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(Da(n.ordered)(n.withDummies.edges)((()=>{const o=u=>{if(u.tag==="Leaf")return M;if(u.tag==="Node")return $t("Node",u._1,u._2,u._3,w(u._4._1*4,u._4._2),o(u._5),o(u._6));c()};return o(r)})()))};return{pipeline:i,result:U0(t)(e)(i)}},X0=t=>e=>n=>Y0(t)(e)({...n,ordered:f0({iterations:t.iterations,constraints:e.constraints,modelOrder:$r(At(r=>i=>w(i.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),K0=t=>e=>n=>X0(t)(e)({...n,withDummies:x0(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),j0=t=>e=>{const n=O(i=>i.id)(e.nodes),r=J0(t.cycleBreaker)(n)(e.constraints)(e.edges);return K0(t)(e)({acyclic:r,layered:M0(t.layerer)(e.constraints)(r.edges)(n),withDummies:H0,ordered:[],placements:[]})},Z0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},tp=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},oc=Vt(C)(Dt),ep=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},np=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},rp=J(t=>e=>K(C)(e)()(t))(M),ip=J(t=>e=>K(C)(e)()(t))(M),op=dr.traverse(Ui),du=Vt(C)(Dt),up=t=>e=>n=>{const r=ge(i=>i.id===n)(t.graph.edges);if(r.tag==="Just")return L("Just",r._1);if(r.tag==="Nothing")return Z0(n)(e);c()},sp=t=>e=>n=>({x:n.position._1*t,y:n.position._2*t,w:n.size._1*t,h:n.size._2*t,label:(()=>{const r=tp(n.node)(e);if(r.tag==="Just")return r._1;if(r.tag==="Nothing")return n.node;c()})()}),ap=t=>({id:t,size:w(1,1),ports:[],label:L("Just",t)}),cp=t=>e=>n=>w(n.node,sp(t)(e)(n)),fp=t=>oc(xt(e=>L("Just",w(e.edge,{id:e.edge,from:{node:e.from,port:T},to:{node:e.to,port:T}})))(St(t.scenes)(e=>e.tag==="DataFlow"?xt(n=>n.kind.tag==="SendToken"?L("Just",n.kind._1):T)(e._1.events):[]))),uc=t=>{const e=y_(t),n=ct(i=>ep(i.id)(e.nodes),t.graph.nodes),r=ct(i=>np(i.id)(e.edges),t.graph.edges);return{nodes:[...n,...O(ap)(bt(Ge.foldr,tn(C.compare,e.nodes,rp(O(i=>i.id)(n)))))],edges:[...r,...xt(up(t)(fp(t)))(bt(Ge.foldr,tn(C.compare,e.edges,ip(O(i=>i.id)(r)))))],constraints:t.graph.constraints}},gp=t=>{const e=op(n=>{const r=hd(pd)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;c()})());return()=>{const i=r();return w(n.id,i)}})(uc(t).nodes);return()=>{const n=e();return du(n)}},_p=t=>e=>{const n=Bt(r=>T,r=>i=>L("Just",{head:r,tail:i}),e.segments);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{x:n._1.head.start._1*t,y:n._1.head.start._2*t},...O(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];c()},dp=t=>e=>w(e.edge,_p(t)(e)),lp=t=>e=>n=>({nodes:du(O(cp(ot(4)*t)(e))(n.nodes)),edges:oc(O(dp(t))(n.edges)),chipExtras:M}),hp=ot(4)*8,pp=t=>e=>{const n=vd(hp)(t)(Td(xd)(uc(e)));return lp(8)(du(O(r=>w(r.id,(()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;c()})()))(n.nodes)))(j0(W0)(n).result)},sc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},mp=t=>e=>n=>{const r=t<.05?t:.05,i=(u,s)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return i((()=>{const a=sc(s._3)(n),f=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return{x:s._4.x,y:s._4.y,vx:0,vy:0};c()})(),g=f.vx+(180*(s._4.x-f.x)-22*f.vx)*r,d=f.vy+(180*(s._4.y-f.y)-22*f.vy)*r;return K(C)(s._3)({x:f.x+g*r,y:f.y+d*r,vx:g,vy:d})(i(u,s._5))})(),s._6);c()},o=i(M,e);return{springs:o,applied:(()=>{const u=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return u((()=>{const f=u(s,a._5),g=sc(a._3)(o);if(g.tag==="Just")return K(C)(a._3)({...a._4,x:g._1.x,y:g._1.y})(f);if(g.tag==="Nothing")return K(C)(a._3)(a._4)(f);c()})(),a._6);c()};return u(M,e)})()}};(function(){var t={},e="Pure",n="Throw",r="Catch",i="Sync",o="Async",u="Bind",s="Bracket",a="Fork",f="Sequential",g="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",N="Finalized",y="Forked";function x(A,H,Y,W){this.tag=A,this._1=H,this._2=Y,this._3=W}function v(A){var H=function(Y,W,q){return new x(A,Y,W,q)};return H.tag=A,H}function b(A){return new x(e,void 0)}function E(A){try{A()}catch(H){setTimeout(function(){throw H},0)}}function k(A,H,Y){try{return H(Y())}catch(W){return A(W)}}function F(A,H,Y){try{return H(Y)()}catch(W){return Y(A(W))(),b}}var U=(function(){var A=1024,H=0,Y=0,W=new Array(A),q=!1;function B(){var j;for(q=!0;H!==0;)H--,j=W[Y],W[Y]=void 0,Y=(Y+1)%A,j();q=!1}return{isDraining:function(){return q},enqueue:function(j){var X;H===A&&(X=q,B(),q=X),W[(Y+H)%A]=j,H++,q||B()}}})();function tt(A){var H={},Y=0,W=0;return{register:function(q){var B=Y++;q.onComplete({rethrow:!0,handler:function(j){return function(){W--,delete H[B]}}})(),H[B]=q,W++},isEmpty:function(){return W===0},killAll:function(q,B){return function(){if(W===0)return B();var j=0,X={};function _t(ft){X[ft]=H[ft].kill(q,function(ht){return function(){delete X[ft],j--,A.isLeft(ht)&&A.fromLeft(ht)&&setTimeout(function(){throw A.fromLeft(ht)},0),j===0&&B()}})()}for(var pt in H)H.hasOwnProperty(pt)&&(j++,_t(pt));return H={},Y=0,W=0,function(ft){return new x(i,function(){for(var ht in X)X.hasOwnProperty(ht)&&X[ht]()})}}}}}var Q=0,S=1,Z=2,V=3,R=4,$=5,I=6;function G(A,H,Y){var W=0,q=Q,B=Y,j=null,X=null,_t=null,pt=null,ft=null,ht=0,Lt=0,Pt=null,lt=!0;function Rt(rt){for(var at,Nt,yt;;)switch(at=null,Nt=null,yt=null,q){case Z:q=S;try{B=_t(B),pt===null?_t=null:(_t=pt._1,pt=pt._2)}catch(Ot){q=$,j=A.left(Ot),B=null}break;case V:A.isLeft(B)?(q=$,j=B,B=null):_t===null?q=$:(q=Z,B=A.fromRight(B));break;case S:switch(B.tag){case u:_t&&(pt=new x(_,_t,pt)),_t=B._2,q=S,B=B._1;break;case e:_t===null?(q=$,B=A.right(B._1)):(q=Z,B=B._1);break;case i:q=V,B=k(A.left,A.right,B._1);break;case o:q=R,B=F(A.left,B._1,function(Ot){return function(){W===rt&&(W++,U.enqueue(function(){W===rt+1&&(q=V,B=Ot,Rt(W))}))}});return;case n:q=$,j=A.left(B._1),B=null;break;case r:_t===null?ft=new x(_,B,ft,X):ft=new x(_,B,new x(_,new x(h,_t,pt),ft,X),X),_t=null,pt=null,q=S,B=B._1;break;case s:ht++,_t===null?ft=new x(_,B,ft,X):ft=new x(_,B,new x(_,new x(h,_t,pt),ft,X),X),_t=null,pt=null,q=S,B=B._1;break;case a:q=V,at=G(A,H,B._2),H&&H.register(at),B._1&&at.run(),B=A.right(at);break;case f:q=S,B=P(A,H,B._1);break}break;case $:if(_t=null,pt=null,ft===null)q=I,B=X||j||B;else switch(at=ft._3,yt=ft._1,ft=ft._2,yt.tag){case r:X&&X!==at&&ht===0?q=$:j&&(q=S,B=yt._2(A.fromLeft(j)),j=null);break;case h:X&&X!==at&&ht===0||j?q=$:(_t=yt._1,pt=yt._2,q=Z,B=A.fromRight(B));break;case s:ht--,j===null&&(Nt=A.fromRight(B),ft=new x(_,new x(p,yt._2,Nt),ft,at),(X===at||ht>0)&&(q=S,B=yt._3(Nt)));break;case p:ft=new x(_,new x(N,B,j),ft,X),q=S,X&&X!==at&&ht===0?B=yt._1.killed(A.fromLeft(X))(yt._2):j?B=yt._1.failed(A.fromLeft(j))(yt._2):B=yt._1.completed(A.fromRight(B))(yt._2),j=null,ht++;break;case m:ht++,ft=new x(_,new x(N,B,j),ft,X),q=S,B=yt._1;break;case N:ht--,q=$,B=yt._1,j=yt._2;break}break;case I:for(var Ct in Pt)Pt.hasOwnProperty(Ct)&&(lt=lt&&Pt[Ct].rethrow,E(Pt[Ct].handler(B)));Pt=null,X&&j?setTimeout(function(){throw A.fromLeft(j)},0):A.isLeft(B)&<&&setTimeout(function(){if(lt)throw A.fromLeft(B)},0);return;case Q:q=S;break;case R:return}}function mt(rt){return function(){if(q===I)return lt=lt&&rt.rethrow,rt.handler(B)(),function(){};var at=Lt++;return Pt=Pt||{},Pt[at]=rt,function(){Pt!==null&&delete Pt[at]}}}function gt(rt,at){return function(){if(q===I)return at(A.right(void 0))(),function(){};var Nt=mt({rethrow:!1,handler:function(){return at(A.right(void 0))}})();switch(q){case Q:X=A.left(rt),q=I,B=X,Rt(W);break;case R:X===null&&(X=A.left(rt)),ht===0&&(q===R&&(ft=new x(_,new x(m,B(rt)),ft,X)),q=$,B=null,j=null,Rt(++W));break;default:X===null&&(X=A.left(rt)),ht===0&&(q=$,B=null,j=null)}return Nt}}function it(rt){return function(){var at=mt({rethrow:!1,handler:rt})();return q===Q&&Rt(W),at}}return{kill:gt,join:it,onComplete:mt,isSuspended:function(){return q===Q},run:function(){q===Q&&(U.isDraining()?Rt(W):U.enqueue(function(){Rt(W)}))}}}function D(A,H,Y,W){var q=0,B={},j=0,X={},_t=new Error("[ParAff] Early exit"),pt=null,ft=t;function ht(mt,gt,it){var rt=gt,at=null,Nt=null,yt=0,Ct={},Ot,re;t:for(;;)switch(Ot=null,rt.tag){case y:if(rt._3===t&&(Ot=B[rt._1],Ct[yt++]=Ot.kill(mt,function(je){return function(){yt--,yt===0&&it(je)()}})),at===null)break t;rt=at._2,Nt===null?at=null:(at=Nt._1,Nt=Nt._2);break;case g:rt=rt._2;break;case d:case l:at&&(Nt=new x(_,at,Nt)),at=rt,rt=rt._1;break}if(yt===0)it(A.right(void 0))();else for(re=0,Ot=yt;re<Ot;re++)Ct[re]=Ct[re]();return Ct}function Lt(mt,gt,it){var rt,at,Nt,yt,Ct,Ot;for(A.isLeft(mt)?(rt=mt,at=null):(at=mt,rt=null);;){if(Nt=null,yt=null,Ct=null,Ot=null,pt!==null)return;if(gt===null){W(rt||at)();return}if(gt._3!==t)return;switch(gt.tag){case g:rt===null?(gt._3=A.right(gt._1(A.fromRight(at))),at=gt._3):gt._3=rt;break;case d:if(Nt=gt._1._3,yt=gt._2._3,rt){if(gt._3=rt,Ct=!0,Ot=j++,X[Ot]=ht(_t,rt===Nt?gt._2:gt._1,function(){return function(){delete X[Ot],Ct?Ct=!1:it===null?Lt(rt,null,null):Lt(rt,it._1,it._2)}}),Ct){Ct=!1;return}}else{if(Nt===t||yt===t)return;at=A.right(A.fromRight(Nt)(A.fromRight(yt))),gt._3=at}break;case l:if(Nt=gt._1._3,yt=gt._2._3,Nt===t&&A.isLeft(yt)||yt===t&&A.isLeft(Nt))return;if(Nt!==t&&A.isLeft(Nt)&&yt!==t&&A.isLeft(yt))rt=at===Nt?yt:Nt,at=null,gt._3=rt;else if(gt._3=at,Ct=!0,Ot=j++,X[Ot]=ht(_t,at===Nt?gt._2:gt._1,function(){return function(){delete X[Ot],Ct?Ct=!1:it===null?Lt(at,null,null):Lt(at,it._1,it._2)}}),Ct){Ct=!1;return}break}it===null?gt=null:(gt=it._1,it=it._2)}}function Pt(mt){return function(gt){return function(){delete B[mt._1],mt._3=gt,Lt(gt,mt._2._1,mt._2._2)}}}function lt(){var mt=S,gt=Y,it=null,rt=null,at,Nt;t:for(;;)switch(at=null,Nt=null,mt){case S:switch(gt.tag){case g:it&&(rt=new x(_,it,rt)),it=new x(g,gt._1,t,t),gt=gt._2;break;case d:it&&(rt=new x(_,it,rt)),it=new x(d,t,gt._2,t),gt=gt._1;break;case l:it&&(rt=new x(_,it,rt)),it=new x(l,t,gt._2,t),gt=gt._1;break;default:Nt=q++,mt=$,at=gt,gt=new x(y,Nt,new x(_,it,rt),t),at=G(A,H,at),at.onComplete({rethrow:!1,handler:Pt(gt)})(),B[Nt]=at,H&&H.register(at)}break;case $:if(it===null)break t;it._1===t?(it._1=gt,mt=S,gt=it._2,it._2=t):(it._2=gt,gt=it,rt===null?it=null:(it=rt._1,rt=rt._2))}for(ft=gt,Nt=0;Nt<q;Nt++)B[Nt].run()}function Rt(mt,gt){pt=A.left(mt);var it;for(var rt in X)if(X.hasOwnProperty(rt)){it=X[rt];for(rt in it)it.hasOwnProperty(rt)&&it[rt]()}X=null;var at=ht(mt,ft,gt);return function(Nt){return new x(o,function(yt){return function(){for(var Ct in at)at.hasOwnProperty(Ct)&&at[Ct]();return b}})}}return lt(),function(mt){return new x(o,function(gt){return function(){return Rt(mt,gt)}})}}function P(A,H,Y){return new x(o,function(W){return function(){return D(A,H,Y,W)}})}return x.EMPTY=t,x.Pure=v(e),x.Throw=v(n),x.Catch=v(r),x.Sync=v(i),x.Async=v(o),x.Bind=v(u),x.Bracket=v(s),x.Fork=v(a),x.Seq=v(f),x.ParMap=v(g),x.ParApply=v(d),x.ParAlt=v(l),x.Fiber=G,x.Supervisor=tt,x.Scheduler=U,x.nonCanceler=b,x})();let lu=null;function Np(){return lu||(typeof document>"u"?null:(lu=document.createElement("canvas").getContext("2d"),lu))}const ac=new Map,cc=t=>e=>n=>r=>{const i=`${n} ${e}px ${t}|${r}`,o=ac.get(i);if(o!==void 0)return o;const u=Np();if(!u)return r.length*e*.62;u.font=`${n} ${e}px ${t}`;const s=u.measureText(r).width;return ac.set(i,s),s},yp=t=>()=>t.clip("evenodd"),Jp=t=>e=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(e.tile,.001))),r=Math.max(2,Math.round(e.tile*n)),i=document.createElement("canvas");i.width=r,i.height=r;const o=i.getContext("2d");o.scale(n,n),o.fillStyle=e.bgCss,o.fillRect(0,0,e.tile,e.tile),o.fillStyle=e.dotCss,o.beginPath(),o.arc(e.tile/2,e.tile/2,e.dotR,0,2*Math.PI),o.fill();const u=t.createPattern(i,"repeat");u&&typeof u.setTransform=="function"&&u.setTransform(new DOMMatrix().scaleSelf(1/n,1/n)),t.save(),t.fillStyle=u,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},xp=t=>e=>n=>r=>i=>o=>()=>{if(typeof t.roundRect=="function")t.roundRect(e,n,r,i,o);else{const u=Math.min(o,r/2,i/2);t.moveTo(e+u,n),t.lineTo(e+r-u,n),t.quadraticCurveTo(e+r,n,e+r,n+u),t.lineTo(e+r,n+i-u),t.quadraticCurveTo(e+r,n+i,e+r-u,n+i),t.lineTo(e+u,n+i),t.quadraticCurveTo(e,n+i,e,n+i-u),t.lineTo(e,n+u),t.quadraticCurveTo(e,n,e+u,n),t.closePath()}},Tp=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},hu=t=>e=>n=>{const r=e.stroke;return()=>{const i=r.value,o=Lg(t)(n);if(i!==n)return o(),e.stroke.value=n}},vp=t=>e=>n=>{const r=e.font;return()=>{const i=r.value,o=Ig(t)(n);if(i!==n)return o(),e.font.value=n}},zr=t=>e=>n=>{const r=e.fill;return()=>{const i=r.value,o=wg(t)(n);if(i!==n)return o(),e.fill.value=n}},Ci=t=>e=>{const n=e.length,r=o=>{if(o>=n)return()=>{};const u=o>=0&&o<e.length?e[o]:0;if(u===1){const s=Cg(t)((()=>{const f=o+1|0;return f>=0&&f<e.length?e[f]:0})())((()=>{const f=o+2|0;return f>=0&&f<e.length?e[f]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===2){const s=Gg(t)((()=>{const f=o+1|0;return f>=0&&f<e.length?e[f]:0})())((()=>{const f=o+2|0;return f>=0&&f<e.length?e[f]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===3){const s=Fg(t)({cpx:(()=>{const f=o+1|0;return f>=0&&f<e.length?e[f]:0})(),cpy:(()=>{const f=o+2|0;return f>=0&&f<e.length?e[f]:0})(),x:(()=>{const f=o+3|0;return f>=0&&f<e.length?e[f]:0})(),y:(()=>{const f=o+4|0;return f>=0&&f<e.length?e[f]:0})()}),a=r(o+5|0);return()=>(s(),a())}if(u===4){const s=Bg(t)({cp1x:(()=>{const f=o+1|0;return f>=0&&f<e.length?e[f]:0})(),cp1y:(()=>{const f=o+2|0;return f>=0&&f<e.length?e[f]:0})(),cp2x:(()=>{const f=o+3|0;return f>=0&&f<e.length?e[f]:0})(),cp2y:(()=>{const f=o+4|0;return f>=0&&f<e.length?e[f]:0})(),x:(()=>{const f=o+5|0;return f>=0&&f<e.length?e[f]:0})(),y:(()=>{const f=o+6|0;return f>=0&&f<e.length?e[f]:0})()}),a=r(o+7|0);return()=>(s(),a())}if(u===5){const s=Sg(t),a=r(o+1|0);return()=>(s(),a())}return()=>{}},i=os(t);return()=>(i(),r(0)())},wp=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),Lp=t=>e=>{const n=Pg(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=wp();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0}}}},bp={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},Ep=t=>fe(t.weight)+" "+Bu(t.size)+"px Ilisarniq, ui-sans-serif, system-ui, sans-serif",Ye=t=>{const e=Bu(ot(t.a)/255);return t.a>=255?"rgb("+fe(t.r)+","+fe(t.g)+","+fe(t.b)+")":"rgba("+fe(t.r)+","+fe(t.g)+","+fe(t.b)+","+e+")"},kp=t=>e=>n=>r=>{const i=zr(t)(n)(Ye(r));return()=>(i(),Qg(t)({x:0,y:0,width:e.width,height:e.height})())},Gp=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",Jp(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:Ye(n.bgColor),dotCss:Ye(n.dotColor),tile:n.tile,dotR:n.dotRadius})())},Cp=t=>e=>n=>r=>{const i=zr(t)(e)(Ye(r));return()=>(i(),Ci(t)(n)(),ao(t)())},Sp=t=>e=>n=>r=>i=>{const o=zr(t)(e)(Ye(r));return()=>(o(),hu(t)(e)(Ye(i.color))(),io(t)(i.width)(),ei(t)((()=>{if(i.lineJoin==="RoundJoin")return ti;if(i.lineJoin==="BevelJoin")return lo;if(i.lineJoin==="MiterJoin")return ho;c()})())(),yo(t)((()=>{if(i.lineCap==="ButtCap")return No;if(i.lineCap==="RoundCap")return po;if(i.lineCap==="SquareCap")return mo;c()})())(),Ci(t)(n)(),ao(t)(),so(t)())},Qp=t=>e=>n=>r=>i=>o=>{const u=os(t);return()=>{if(u(),xp(t)(n.x)(n.y)(n.w)(n.h)(r)(),i.tag==="Just"?(zr(t)(e)(Ye(i._1.color))(),ao(t)()):i.tag==="Nothing"||c(),o.tag==="Just")return hu(t)(e)(Ye(o._1.color))(),io(t)(o._1.width)(),ei(t)((()=>{if(o._1.lineJoin==="RoundJoin")return ti;if(o._1.lineJoin==="BevelJoin")return lo;if(o._1.lineJoin==="MiterJoin")return ho;c()})())(),yo(t)((()=>{if(o._1.lineCap==="ButtCap")return No;if(o._1.lineCap==="RoundCap")return po;if(o._1.lineCap==="SquareCap")return mo;c()})())(),so(t)();o.tag!=="Nothing"&&c()}},Pp=t=>e=>n=>r=>{const i=hu(t)(e)(Ye(r.color));return()=>(i(),io(t)(r.width)(),ei(t)((()=>{if(r.lineJoin==="RoundJoin")return ti;if(r.lineJoin==="BevelJoin")return lo;if(r.lineJoin==="MiterJoin")return ho;c()})())(),yo(t)((()=>{if(r.lineCap==="ButtCap")return No;if(r.lineCap==="RoundCap")return po;if(r.lineCap==="SquareCap")return mo;c()})())(),Ci(t)(n)(),so(t)())},Dp=t=>e=>n=>{const r=zr(t)(e)(Ye(n.color));return()=>(r(),vp(t)(e)(Ep(n.font))(),Xg(t)((()=>{if(n.align==="AlignLeft")return qg;if(n.align==="AlignCenter")return Wg;if(n.align==="AlignRight")return Hg;c()})())(),Yg(t)((()=>{if(n.baseline==="BaselineTop")return Mg;if(n.baseline==="BaselineMiddle")return $g;if(n.baseline==="BaselineAlphabetic")return zg;if(n.baseline==="BaselineBottom")return Og;c()})())(),Rg(t)(n.content)(n.x)(n.y)())},fc={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>bp},Ap={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>fc},Ip=t=>e=>n=>{const r=Tp(e.width/n.vw)(e.height/n.vh),i=us(t)({translateX:(e.width-n.vw*r)/2-n.vx*r,translateY:(e.height-n.vh*r)/2-n.vy*r});return()=>(i(),co(t)({scaleX:r,scaleY:r})(),ei(t)(ti)())},Rp={pure:t=>e=>()=>t,Apply0:()=>fc},Fp={Applicative0:()=>Rp,Bind1:()=>Ap},gc={fillPath:t=>e=>n=>{const r=Cp(n.ctx)(n.styleCache)(t)(e.color),i=n.maskDepth;return()=>{if(i.value===0)return r()}},strokePath:t=>e=>n=>{const r=Pp(n.ctx)(n.styleCache)(t)(e),i=n.maskDepth;return()=>{if(i.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const i=Sp(r.ctx)(r.styleCache)(t)(e.color)(n),o=r.maskDepth;return()=>{if(o.value===0)return i()}},drawRoundedRect:t=>e=>n=>r=>i=>{const o=Qp(i.ctx)(i.styleCache)(t)(e)(n)(r),u=i.maskDepth;return()=>{if(u.value===0)return o()}},drawText:t=>e=>{const n=Dp(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},pushTransform:t=>e=>{const n=yr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",us(e.ctx)({translateX:t.tx,translateY:t.ty})(),co(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushClip:t=>e=>n=>{const r=yr(n.ctx),i=n.maskDepth;return()=>{if(i.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Ci(n.ctx)(t)(),e==="NonZero")return kg(n.ctx)();if(e==="EvenOdd")return yp(n.ctx)();c()}}},popClip:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBlend:t=>e=>{const n=yr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){if(n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",t==="Normal")return as(e.ctx)(Vg)();if(t==="Difference")return as(e.ctx)(Ug)();c()}}},popBlend:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushAlpha:t=>e=>{const n=yr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Eg(e.ctx)(t)()}},popAlpha:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushLayer:t=>e=>{if(t==="LayerNodeMask"){const n=e.maskDepth;return()=>{const r=n.value;n.value=r+1|0}}return()=>{}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;if(n>0)return t.maskDepth.value=r}},setViewport:t=>e=>{const n=Ip(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=kp(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=Gp(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=cc(t.family)(t.size)(t.weight)(kr(e));return()=>r},Monad0:()=>Fp};function Bp(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function Mp(t){const e=t.length,n=new Array(e);for(let r=0;r<e;r++){const i=t[r],o=t[(r+1)%e];n[r]={a:i,b:o,len:Bp(i,o)}}return n}function $p(t,e,n){let r=0;for(let i=0;i<t.length;i++){const o=t[i],u=r,s=u+o.len;if(n<=s){const a=o.len>1e-6?(n-u)/o.len:0;return{x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a}}r=s}return e.length>0?e[e.length-1]:{x:0,y:0}}function _c(t,e){if(e.length===0)return[];const n=Mp(e);let r=0;for(let o=0;o<n.length;o++)r+=n[o].len;const i=new Array(t);for(let o=0;o<t;o++)i[o]=$p(n,e,o*r/t);return i}function zp(t,e){const n=e.length;if(n===0)return e;const r=(t%n+n)%n|0,i=new Array(n);for(let o=0;o<n;o++)i[o]=e[(o+r)%n];return i}function Op(t,e){const n=e.length;if(n===0)return e;let r=0,i=1/0;for(let o=0;o<n;o++){let u=0;for(let s=0;s<n;s++){const a=t[s]||{x:0,y:0},f=e[(s+o)%n]||{x:0,y:0},g=a.x-f.x,d=a.y-f.y;u+=g*g+d*d}u<i&&(i=u,r=o)}return zp(r,e)}const dc=t=>e=>n=>{const r=_c(t,e),i=_c(t,n),o=Op(r,i);return{from:r,to:o}};function lc(t){const e=t.length;if(e===0)return{x:0,y:0};let n=0,r=0;for(let i=0;i<e;i++)n+=t[i].x,r+=t[i].y;return{x:n/e,y:r/e}}function qp(t,e){const n=e.x-t.x,r=e.y-t.y,i=Math.sqrt(n*n+r*r);return i<=1e-4?{x:1,y:0}:{x:n/i,y:r/i}}function Hp(t,e){const n=e.length;if(n===0)return e;const r=new Array(n);for(let i=0;i<n;i++){const o=e[((i-1)%n+n)%n],u=e[((i+1)%n+n)%n],s=e[i];r[i]={x:s.x+((o.x+u.x)/2-s.x)*t,y:s.y+((o.y+u.y)/2-s.y)*t}}return r}function Wp(t){return t<0?0:t>1?1:t}const hc=t=>e=>n=>r=>{const i=e.length;if(i===0)return[];const o=lc(e),u=lc(n),s=qp(o,u),a=new Array(i);let f=1/0,g=-1/0;for(let _=0;_<i;_++){const h=e[_],p=(h.x-o.x)*s.x+(h.y-o.y)*s.y;a[_]=p,p<f&&(f=p),p>g&&(g=p)}const d=g-f;let l=new Array(i);for(let _=0;_<i;_++){const h=e[_],p=n[_];if(p===void 0){l[_]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(a[_]-f)/d),N=Math.max(1e-4,1-m),y=Wp((t-m)/N),x=y*y*(3-2*y);l[_]={x:h.x+(p.x-h.x)*x,y:h.y+(p.y-h.y)*x}}for(let _=0;_<r.smoothPasses;_++)l=Hp(.5,l);return l},Vp=t=>t,pc=t=>t,Si=t=>t,mc=t=>t,Up=t=>t,Nc=t=>t,yc=t=>t,Jc=yc("BaselineTop"),Or=yc("BaselineMiddle"),Qi=Nc("AlignLeft"),pu=Nc("AlignCenter"),Xe=Up("RoundJoin"),yn=mc("ButtCap"),xc=mc("RoundCap"),Yp=Si("LayerPolyOut"),Xp=Si("LayerPolyIn"),Kp=Si("LayerNodeMask"),jp=Si("LayerOverlay"),Tc=pc("NonZero"),Zp=pc("EvenOdd"),tm=Vp("Difference"),rr={r:255,g:255,b:255,a:255},un={r:26,g:26,b:26,a:255},mu=(t,e,n)=>({tag:t,_1:e,_2:n}),sn=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},qr=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},vc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Pn=t=>e=>n=>{const r=dt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),o=dt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;c()},Se=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},an=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),Nu=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},wc=Vt(C)(Dt),Lc=J(Wn)(0),Pi=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},bc=t=>{const e=t.Monad0().Bind1(),n=t.popTransform,r=t.popAlpha;return i=>o=>u=>s=>a=>e.bind(t.pushAlpha(i.fadeAlpha))(()=>e.bind(t.pushTransform({tx:o*(1-i.popScale),ty:u*(1-i.popScale),sx:i.popScale,sy:i.popScale}))(()=>e.bind(t.pushTransform({tx:0,ty:s.y*(1-i.flipY),sx:1,sy:i.flipY}))(()=>e.bind(a)(()=>e.bind(n)(()=>e.bind(n)(()=>r))))))},cn=t=>{const e=t.Apply0();return n=>J(r=>i=>e.apply(e.Functor0().map(o=>Fu)(r))(n(i)))(t.pure())},em=t=>({x:t.x,y:t.y,w:t.w,h:t.h}),nm=J(t=>e=>t+e.len)(0),rm=t=>{const e=Bt(n=>T,n=>r=>L("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(It(1,t.length,t))(n=>[2,n.x,n.y]),5];c()},im=t=>e=>{const n=t.y+t.h-6,r=t.y+6,i=t.x+14,o=t.x+t.w-14,u=J(qr)(0)(O(s=>i-10<s.x+s.w+12&&o+10>s.x-12&&r-10<s.y+s.h+12&&n+10>s.y-12?sn((s.x+s.w+12-(i-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+u*.7071067811865476,y:t.y-u*.7071067811865476}},om={r:26,g:26,b:26,a:255},um={r:214,g:211,b:209,a:255},Ec=t=>e=>{const n=sn(e)(sn(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},sm=t=>e=>n=>J(r=>i=>{const o=vc(i)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just"){const u=im(o._1)(r.obstacles);return{acc:K(C)(i)(u)(r.acc),obstacles:oe(r.obstacles)(u)}}c()})({acc:M,obstacles:n})(t).acc,am=t=>{const e=Bt(n=>T,n=>r=>L("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(e._1.tail)(n=>[2,n.x,n.y])];c()},Di=t=>{if(t.tag==="Hidden")return{alpha:0,scale:0};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:t._1>0?1:0,scale:xr(8)(.6)(Pn(0)(1)(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:xr(8)(.6)(Pn(0)(1)(1-t._1))};c()},kc=t=>e=>St(an(t.nodes))(n=>{const r=Se(n._1)(e.nodes);return r.tag==="Just"&&Di(r._1).alpha>0?Ec(n._2)(7):[]}),cm=t=>e=>n=>[1,t.vx,t.vy,2,t.vx+t.vw,t.vy,2,t.vx+t.vw,t.vy+t.vh,2,t.vx,t.vy+t.vh,5,...kc(e)(n)],Ai=t=>e=>n=>O(r=>{const i=ot(r)/ot(n);return{x:t.x+(e.x-t.x)*i,y:t.y+(e.y-t.y)*i}})(Ht(0,n-1|0)),fm=t=>e=>{const n=i=>(i.x-e.x)*(i.x-e.x)+(i.y-e.y)*(i.y-e.y),r=J(i=>o=>n(o)<n(i)?o:i)({x:t.x,y:t.y})([{x:t.x,y:t.y},{x:t.x+t.w,y:t.y},{x:t.x,y:t.y+t.h},{x:t.x+t.w,y:t.y+t.h}]);return O(i=>{const o=ot(i)/5;return{x:r.x+(e.x-r.x)*o,y:r.y+(e.y-r.y)*o}})([1,2,3,4])},Gc=t=>{const e=Po(`
|
|
6
|
-
`)(t);return e.length===0?[""]:e},yu=t=>e=>{const n=sn(t)(sn(e.w/2)(e.h/2));return{...e,x:e.x+n,y:e.y+n,w:e.w-2*n,h:e.h-2*n}},gm=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=cn(n),o=t.popTransform,u=t.popAlpha;return s=>a=>f=>{const g=Po(`
|
|
7
|
-
`)(a.label===""?s:a.label),d=g.length===0?[""]:g,l=a.y+a.h/2-ot(d.length)*13.2/2+6.6,_=Di(f),h=a.x+a.w/2,p=a.y+a.h/2,m=r.bind(t.pushAlpha(_.alpha))(()=>r.bind(t.pushTransform({tx:h*(1-_.scale),ty:p*(1-_.scale),sx:_.scale,sy:_.scale}))(()=>r.bind(t.drawRoundedRect({x:a.x,y:a.y,w:a.w,h:a.h})(7)(L("Just",{color:rr,flat:!1}))(L("Just",{color:un,width:1.25,lineJoin:Xe,lineCap:yn})))(()=>r.bind(i(N=>t.drawText({x:a.x+a.w/2,y:l+ot(N._1)*13.2,content:N._2,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500},color:un,align:pu,baseline:Or}))(At(Bn)(d)))(()=>r.bind(o)(()=>u)))));return _.alpha>0?m:n.pure()}},Cc=t=>{const e=gm(t),n=t.Monad0().Applicative0(),r=cn(n);return i=>o=>r(u=>{const s=Se(u._1)(o.nodes);if(s.tag==="Just")return e(u._1)(u._2)(s._1);if(s.tag==="Nothing")return n.pure();c()})(an(i.nodes))},Ju=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return qn(r*r+n*n)},_m=t=>ye(e=>n=>({a:e,b:n,len:Ju(e)(n)}),t,It(1,t.length,t)),dm=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?L("Just",e[n]):T,i=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];c()})(),o=0<e.length?L("Just",e[0]):T,u=(()=>{if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return{x:0,y:0};c()})(),s=e.length;return s<3?e:[u,...St(Ht(1,s-2|0))(a=>{const f=a+1|0,g=f>=0&&f<e.length?L("Just",e[f]):T,d=a>=0&&a<e.length?L("Just",e[a]):T,l=a-1|0,_=l>=0&&l<e.length?L("Just",e[l]):T;if(_.tag==="Just"&&d.tag==="Just"&&g.tag==="Just"){const h=d._1,p=Ju(h)(g._1),m=Ju(_._1)(h),N=sn(t)(p/2),y=sn(t)(m/2),x=p>0?N/p:0,v=h.x+(g._1.x-h.x)*x,b=h.y+(g._1.y-h.y)*x,E=m>0?y/m:0,k=h.x+(_._1.x-h.x)*E,F=h.y+(_._1.y-h.y)*E;return O(U=>{const tt=ot(U)/ot(10),Q=1-tt;return{x:Q*Q*k+2*Q*tt*h.x+tt*tt*v,y:Q*Q*F+2*Q*tt*h.y+tt*tt*b}})(Ht(0,10))}return[]}),...i]},lm=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=cn(r);return o=>u=>s=>a=>f=>g=>{const d=Do(g).length,l=ot(d+1|0),_=m=>{const N=(s*l-ot(m))/1.5,y=N<0?0:N>1?1:N;return y*y*(3-2*y)},h=(m=>{let N=m,y=!0,x;for(;y;){const v=N;if(v>=d){y=!1,x=v;continue}if(_(v)>=1){N=v+1|0;continue}y=!1,x=v}return x})(0),p=h>=d?[]:Tn(m=>_(m)>0)(Ht(h,d-1|0)).init;return n.bind((()=>{const m=t.drawText({x:a,y:f,content:ce(h)(g),font:o,color:u,align:Qi,baseline:Or});return h>0?m:r.pure()})())(()=>i(m=>n.bind(t.measureText(o)(ce(m)(g)))(N=>{const y=_(m);return t.drawText({x:a+N,y:f-(1-y)*10,content:ce(1)(vr(En(ce(m)(g)))(g)),font:o,color:{...u,a:vn(ju(y*ot(u.a)))},align:Qi,baseline:Or})}))(p))}},Ii=t=>e=>n=>r=>{const i=O(h=>ot(Nu(1)(Do(h).length)))(r),o=qr(1)(J(Wn)(0)(i)),u=qr(.05)(1-e-n),s=t<e?0:t>1-n?1:(t-e)/u,a=s*o,f=Nu(1)(r.length),g=(h=>p=>m=>{let N=h,y=p,x=m,v=!0,b;for(;v;){const E=N,k=y,F=Bt(U=>T,U=>tt=>L("Just",{head:U,tail:tt}),x);if(F.tag==="Nothing"){v=!1,b=Nu(0)(f-1|0);continue}if(F.tag==="Just"){if(k+F._1.head>=a){v=!1,b=E;continue}N=E+1|0,y=k+F._1.head,x=F._1.tail;continue}c()}return b})(0)(0)(i),d=J(Wn)(0)(g<1?[]:It(0,g,i)),l=d/o;if(g>=0&&g<i.length){const h=(d+i[g])/o;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(h<=l)return 1;const p=(s-l)/(h-l);return p<0?0:p>1?1:p})()}}const _=(d+1)/o;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(_<=l)return 1;const h=(s-l)/(_-l);return h<0?0:h>1?1:h})()}},hm=t=>{const e=t.Monad0();return n=>r=>i=>e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Ii(r)(0)(0)(i).line))(o=>{const u=o+28;return e.Applicative0().pure({x:n.x+n.w/2-u/2,y:n.y-25.2-14,w:u,h:25.2})})},pm=t=>{const e=t.Monad0(),n=e.Bind1(),r=hm(t),i=e.Applicative0(),o=dr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>wc(xt(f=>f)(a)))(o(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const f=Se(a._2._1.node)(u.nodes);if(f.tag==="Just")return n.bind(r(f._1)(a._2._1.progress)(a._2._1.labels))(g=>i.pure(L("Just",w(a._1,g))));if(f.tag==="Nothing")return i.pure(T);c()}return i.pure(T)})(an(s.tokens)))},Sc=t=>e=>O(n=>{const r=6.283185307179586*ot(n)/ot(64);return{x:t.x+e*Zi(r),y:t.y+e*eo(r)}})(Ht(0,63)),xu=t=>e=>{const n=.5522847498*e;return[1,t.x+e,t.y,4,t.x+e,t.y+n,t.x+n,t.y+e,t.x,t.y+e,4,t.x-n,t.y+e,t.x-e,t.y+n,t.x-e,t.y,4,t.x-e,t.y-n,t.x-n,t.y-e,t.x,t.y-e,4,t.x+n,t.y-e,t.x+e,t.y-n,t.x+e,t.y,5]},mm=t=>{const e=t.Monad0().Bind1(),n=t.popAlpha;return r=>i=>o=>u=>s=>a=>f=>{const g={x:o.x+o.w/2,y:o.y+o.h/2},d=qr(.05)(1-a-f),l=s<a?0:s>1-f?1:(s-a)/d,_={x:u.x+u.w/2,y:u.y+u.h/2},h=(p,m)=>e.bind(t.pushAlpha(m))(()=>e.bind(t.fillStrokePath(xu(p)(6))({color:r,flat:!0})({color:i,width:1,lineJoin:Xe,lineCap:yn}))(()=>n));return l<.5?h(g,(()=>{const p=l*2;return 1-(p<0?0:p>1?1:p)*(p<0?0:p>1?1:p)*(p<0?3:p>1?1:3-2*p)})()):h(_,(()=>{const p=(l-.5)*2;return(p<0?0:p>1?1:p)*(p<0?0:p>1?1:p)*(p<0?3:p>1?1:3-2*p)})())}},Nm={r:255,g:235,b:130,a:255},ym=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:Lc(O(n=>n.x)(t))/ot(e),y:Lc(O(n=>n.y)(t))/ot(e)}},Qc=t=>e=>n=>{const r=xr(6)(.55)(Pn(0)(1)((1-t)/.06)),i=t>.94,o=i&&n>1e-4,u=xr(6)(.55)(Pn(0)(1)(t/.06)),s=t<.06,a=s&&e>1e-4,f=i&&n<=1e-4;return{popScale:a?u:o?r:1,flipY:s&&e<=1e-4?u:f?r:1,fadeAlpha:(()=>{if(a){const g=t/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}if(o){const g=(1-t)/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}return 1})()}},Jm=t=>{const e=t.Monad0().Bind1(),n=bc(t);return r=>i=>o=>u=>{const s=Qc(o)(0)(0),a={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500},f=Ii(o)(0)(0)(u);return e.bind(t.measureText(a)(f.line))(g=>{const d={r:26,g:26,b:26,a:90},l=i.x+i.w/2,_=g+28,h=i.y-25.2-14,p=l-_/2,m=[1,l,h+25.2,2,l,i.y],N={x:l,y:h+12.6};return n(s)(l-_/2)(h+25.2)(N)(e.bind(t.drawRoundedRect({x:l-_/2,y:h+1.5,w:_,h:25.2})(6)(L("Just",{color:um,flat:!0}))(T))(()=>e.bind(t.drawRoundedRect({x:p,y:h,w:_,h:25.2})(6)(L("Just",{color:Nm,flat:!0}))(L("Just",{color:d,width:1,lineJoin:Xe,lineCap:yn})))(()=>e.bind(t.strokePath(m)({color:d,width:1,lineJoin:Xe,lineCap:yn}))(()=>t.drawText({x:l,y:N.y,content:f.line,font:a,color:un,align:pu,baseline:Or})))))})}},Pc={r:0,g:0,b:0,a:0},xm=t=>e=>t.backgroundDots({viewport:{vx:e.x,vy:e.y,vw:e.w,vh:e.h},bgColor:Pc,dotColor:om,tile:1.6,dotRadius:.25}),Tm={r:214,g:211,b:209,a:255},Dc={r:255,g:255,b:255,a:255},Ac=t=>{const e=t.Monad0().Bind1();return n=>r=>n?e.bind(t.clearBackground(Pc))(()=>t.setViewport(r)):e.bind(t.setViewport(r))(()=>t.backgroundDots({viewport:r,bgColor:Dc,dotColor:Tm,tile:12,dotRadius:.7}))},vm=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=t.popClip,o=t.popTransform,u=t.popAlpha;return s=>a=>f=>{const g=Di(f),d={...a,y:a.y+5},l=d.x+d.w/2,_=d.y+d.h/2,h=r.bind(t.pushAlpha(g.alpha))(()=>r.bind(t.pushTransform({tx:l*(1-g.scale),ty:_*(1-g.scale),sx:g.scale,sy:g.scale}))(()=>r.bind(t.drawRoundedRect({x:d.x,y:d.y,w:d.w,h:d.h})(7)(L("Just",{color:Dc,flat:!0}))(T))(()=>r.bind((()=>{const p=r.bind(t.pushClip(Ec(d)(7))(Tc))(()=>r.bind(xm(t)(d))(()=>i));return s?p:n.pure()})())(()=>r.bind(t.drawRoundedRect({x:d.x,y:d.y,w:d.w,h:d.h})(7)(T)(L("Just",{color:un,width:1.25,lineJoin:Xe,lineCap:yn})))(()=>r.bind(o)(()=>u))))));return g.alpha>0?h:n.pure()}},Ic=t=>{const e=vm(t),n=t.Monad0().Applicative0(),r=cn(n);return i=>o=>u=>r(s=>{const a=Se(s._1)(u.nodes);if(a.tag==="Just")return e(i)(s._2)(a._1);if(a.tag==="Nothing")return n.pure();c()})(an(o.nodes))},wm=t=>{const e=t.Monad0().Applicative0();return n=>{const r=n.length-1|0,i=r<1?[]:It(0,r,n),o=i.length-1|0,u=o>=0&&o<i.length?L("Just",i[o]):T,s=n.length-1|0;if(s>=0&&s<n.length&&u.tag==="Just"){const a=n[s].y-u._1.y,f=n[s].x-u._1.x,g=qn(f*f+a*a),d=a/g,l=-d,_=f/g,h=n[s].x+_*.875,p=n[s].y+d*.875,m=p-d*8.75,N=h-_*8.75,y=[1,h,p,2,N+l*4.375,m+_*4.375,2,N-l*4.375,m-_*4.375,5];return g<=1e-4?e.pure():t.fillPath(y)({color:un,flat:!0})}return e.pure()}},Ri=t=>e=>n=>r=>i=>O(o=>{const u=n+(r-n)*(ot(o)/ot(i));return{x:t.x+e*Zi(u),y:t.y+e*eo(u)}})(Ht(0,i-1|0)),Rc=t=>e=>{const n=sn(t)(sn(e.w/2)(e.h/2));return[...Ai({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...Ri({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...Ai({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...Ri({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...Ai({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...Ri({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...Ai({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...Ri({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},Lm=t=>e=>n=>J(r=>i=>{const o=r.pos+i.len,u=n<o?(n-r.pos)/i.len:1,s={x:i.a.x+(i.b.x-i.a.x)*u,y:i.a.y+(i.b.y-i.a.y)*u},a=e>r.pos?(e-r.pos)/i.len:0,f={x:i.a.x+(i.b.x-i.a.x)*a,y:i.a.y+(i.b.y-i.a.y)*a},g=r.points.length-1|0,d=g>=0&&g<r.points.length?(()=>{const l=r.points[g].x-f.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const _=r.points[g].y-f.y;return _<0?-_<1e-4:_<1e-4})()})()?oe(r.points)(s):[...r.points,f,s]:[f,s];return i.len<=0||o<=e||r.pos>=n?{...r,pos:o}:{pos:o,points:d}})({pos:0,points:[]})(t).points,bm=t=>e=>n=>{const r=Bt(i=>T,i=>o=>L("Just",{head:i,tail:o}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const i=_m(t),o=nm(i),u=Pn(0)(o)(e*o),s=Pn(0)(o)(n*o);return s<=u?[]:Lm(i)(u)(s)}c()},Em=t=>{const e=t.Monad0(),n=e.Applicative0(),r=wm(t);return i=>o=>u=>{const s=dm(8)(o);if(u.hi<=u.lo)return n.pure();const a=bm(s)(u.lo)(u.hi);return a.length===0?n.pure():e.Bind1().bind(t.strokePath(am(a))({color:un,width:.9375,lineJoin:Xe,lineCap:xc}))(()=>r(a))}},Fc=t=>{const e=Em(t),n=t.Monad0().Applicative0(),r=cn(n);return i=>o=>r(u=>{const s=Pi(u._1)(o.edges);if(s.tag==="Just")return e(u._1)(u._2)((()=>{if(s._1.tag==="Retracted")return{lo:0,hi:0};if(s._1.tag==="Extended")return{lo:0,hi:1};if(s._1.tag==="Extending")return{lo:0,hi:s._1._2};if(s._1.tag==="Retracting"){if(s._1._1==="FromSource")return{lo:s._1._2,hi:1};if(s._1._1==="FromTarget")return{lo:0,hi:1-s._1._2};if(s._1._1==="FromBoth")return{lo:s._1._2/2,hi:1-s._1._2/2}}c()})());if(s.tag==="Nothing")return n.pure();c()})(an(i.edges))},Bc=t=>e=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},a=0<t.length?L("Just",t[0]):T,f=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return s;c()})(),g=t.length-1|0,d=g>=0&&g<t.length?L("Just",t[g]):T,l=(()=>{if(d.tag==="Just")return d._1;if(d.tag==="Nothing")return u;c()})(),_=dc(128)(Rc(5)(yu(2)(e)))(Sc(f)(6)),h=qr(.05)(1-i-o),p=r<i?0:r>1-o?1:(r-i)/h,m=f.x-s.x,N=2*(()=>{const V=f.y-s.y;return(m<0?-m:m)+(V<0?-V:V)})(),y=l.x-u.x,x=2*(()=>{const V=l.y-u.y;return(y<0?-y:y)+(V<0?-V:V)})(),v=N+xo(t)+x,b=v<=1e-4?1:1-x/v,E=v<=1e-4?0:N/v,k=b-E,F=dc(128)(Sc(l)(6))(Rc(5)(yu(2)(n))),U={maxDelay:.4,smoothPasses:2},tt=_s(t)(Pn(0)(1)(k<=1e-4?0:(p-E)/k)),Q=(()=>{if(tt.tag==="Just")return tt._1;if(tt.tag==="Nothing")return f;c()})(),S=(()=>{if(b>=1)return 0;const V=(p-b)/(1-b),R=V<0?0:V>1?1:V;return R*R*(3-2*R)})(),Z=(()=>{if(E<=1e-4)return 1;const V=p/E,R=V<0?0:V>1?1:V;return R*R*(3-2*R)})();return p<E?mu("PolyShape",hc(Z)(_.from)(_.to)(U)):p>=b?mu("PolyShape",hc(S)(F.from)(F.to)(U)):mu("CircleShape",Q,6)},km=t=>e=>n=>r=>i=>o=>u=>s=>a=>{const f=Bc(r)(i)(o)(u)(s)(a);if(f.tag==="CircleShape")return t.fillStrokePath(xu(f._1)(f._2))({color:e,flat:!0})({color:n,width:1,lineJoin:Xe,lineCap:yn});if(f.tag==="PolyShape")return f._1.length>=3?t.fillStrokePath(rm(f._1))({color:e,flat:!0})({color:n,width:1,lineJoin:Xe,lineCap:yn}):t.Monad0().Applicative0().pure();c()},Mc=t=>{const e=mm(t),n=t.Monad0().Applicative0(),r=cn(n);return i=>o=>u=>s=>r(a=>{if(a._2.tag==="Travelling"){const f=Se(a._2._1.target)(i.nodes),g=Se(a._2._1.source)(i.nodes);if(g.tag==="Just"&&f.tag==="Just"){const d=Pi(a._2._1.edge)(i.edges);if(d.tag==="Just")return km(t)(u)(s)((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return de(d._1);c()})())(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);if(d.tag==="Nothing")return e(u)(s)(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);c()}return n.pure()}if(a._2.tag==="Filling"){const f=Se(a._2._1.node)(i.nodes);if(f.tag==="Just")return t.drawRoundedRect((()=>{const g=yu(2)(f._1);return{x:g.x,y:g.y,w:g.w,h:g.h}})())(5)(L("Just",{color:u,flat:!0}))(L("Just",{color:s,width:1,lineJoin:Xe,lineCap:yn}));if(f.tag==="Nothing")return n.pure();c()}return n.pure()})(an(o.tokens))},$c=t=>{const e=t.Monad0(),n=e.Bind1(),r=Mc(t),i=t.popClip,o=t.popBlend,u=t.popLayer,s=e.Applicative0(),a=cn(s);return f=>g=>n.bind(t.pushLayer(Xp))(()=>n.bind(t.pushBlend(tm))(()=>n.bind(t.pushClip(kc(f)(g))(Tc))(()=>n.bind(r(f)(g)(rr)(rr))(()=>n.bind(i)(()=>n.bind(o)(()=>n.bind(u)(()=>n.bind(t.pushLayer(Kp))(()=>n.bind(a(d=>{const l=Se(d._1)(g.nodes);return l.tag==="Just"&&Di(l._1).alpha>0?t.drawRoundedRect({x:d._2.x,y:d._2.y,w:d._2.w,h:d._2.h})(7)(L("Just",{color:rr,flat:!1}))(T):s.pure()})(an(f.nodes)))(()=>u)))))))))},zc=t=>{const e=t.Monad0().Bind1(),n=Mc(t),r=t.popClip,i=t.popLayer;return o=>u=>s=>e.bind(t.pushLayer(Yp))(()=>e.bind(t.pushClip(cm(o)(u)(s))(Zp))(()=>e.bind(n(u)(s)(un)(rr))(()=>e.bind(r)(()=>i))))},Oc=t=>e=>n=>r=>i=>o=>{const u=Bc(t)(e)(n)(r)(i)(o);if(u.tag==="PolyShape")return ym(u._1);if(u.tag==="CircleShape")return u._1;c()},Gm=t=>{const e=bc(t),n=t.Monad0(),r=n.Bind1(),i=cn(n.Applicative0()),o=lm(t);return u=>s=>a=>f=>g=>d=>l=>_=>{const h=Ii(f)(g)(d)(St(l)(Gc)),p=h.line,m=h.phaseInLabel/.45,N=m<0?0:m>1?1:m,y=_.w,x=_.y,v=_.x,b=v+14,E=_.h,k=x+E/2;return e(Qc(f)(g)(d))(v)(x+E)({x:v+y/2,y:k})(r.bind(i(F=>t.fillPath(xu(F)(1.5))({color:un,flat:!0}))(fm(_)(Oc(u)(s)(a)(f)(g)(d))))(()=>r.bind(t.drawRoundedRect({x:v,y:x,w:y,h:E})(3)(L("Just",{color:un,flat:!0}))(T))(()=>o({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(rr)(N)(b)(k)(p))))}},qc=t=>{const e=Gm(t),n=t.Monad0(),r=n.Applicative0(),i=Jm(t),o=n.Bind1(),u=cn(r),s=t.popLayer;return a=>f=>g=>o.bind(t.pushLayer(jp))(()=>o.bind(u(d=>{if(d._2.tag==="Travelling"){if(d._2._1.labels.length!==0){const l=Se(d._2._1.target)(a.nodes),_=Se(d._2._1.source)(a.nodes),h=Pi(d._2._1.edge)(a.edges),p=vc(d._1)(g);if(p.tag==="Just"&&h.tag==="Just"&&_.tag==="Just"&&l.tag==="Just")return e((()=>{if(d._2._1.direction==="Forward")return h._1;if(d._2._1.direction==="Backward")return de(h._1);c()})())(_._1)(l._1)(d._2._1.progress)(d._2._1.holdPre)(d._2._1.holdPost)(d._2._1.labels)(p._1)}return r.pure()}if(d._2.tag==="Filling"&&d._2._1.labels.length!==0){const l=Se(d._2._1.node)(a.nodes);if(l.tag==="Just")return i(a)(l._1)(d._2._1.progress)(d._2._1.labels);if(l.tag==="Nothing")return r.pure();c()}return r.pure()})(an(f.tokens)))(()=>s))},Cm=t=>{const e=t.Monad0();return n=>r=>i=>o=>u=>s=>a=>{const f=Oc(n)(r)(i)(o)(u)(s);return e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Ii(o)(u)(s)(St(a)(Gc)).line))(g=>e.Applicative0().pure({x:f.x+14+g/2-g/2-14,y:f.y-6-8-6.6-6,w:g+28,h:25.2}))}},Sm=t=>{const e=t.Monad0(),n=e.Bind1(),r=Cm(t),i=e.Applicative0(),o=dr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>wc(xt(f=>f)(a)))(o(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const f=Se(a._2._1.target)(u.nodes),g=Se(a._2._1.source)(u.nodes),d=Pi(a._2._1.edge)(u.edges);if(d.tag==="Just"&&g.tag==="Just"&&f.tag==="Just")return n.bind(r((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return de(d._1);c()})())(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(l=>i.pure(L("Just",w(a._1,l))))}return i.pure(T)})(an(s.tokens)))},Hc=t=>{const e=t.Monad0(),n=e.Bind1(),r=Sm(t),i=pm(t);return o=>u=>n.bind(r(o)(u))(s=>n.bind(i(o)(u))(a=>e.Applicative0().pure(sm((()=>{const f=g=>{if(g.tag==="Leaf")return M;if(g.tag==="Node")return $t("Node",g._1,g._2,g._3,void 0,f(g._5),f(g._6));c()};return vt(C.compare)(bt(Ge.foldr,f(s)))})())(s)([...O(em)((()=>{const f=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return f(g._5,Mt("Cons",g._4,f(g._6,d)));c()};return bt(Wt.foldr,f(o.nodes,qt))})()),...(()=>{const f=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return f(g._5,Mt("Cons",g._4,f(g._6,d)));c()};return bt(Wt.foldr,f(a,qt))})()]))))},Qm=t=>{const e=Hc(t),n=qc(t);return r=>i=>t.Monad0().Bind1().bind(e(r)(i))(o=>n(r)(i)(o))},Fi=t=>e=>n=>{const r=bs(e)(n.camera);return{vx:r.x-t.padding,vy:r.y-t.padding-40,vw:r.w+2*t.padding,vh:r.h+2*t.padding+40}},Wc=t=>{const e=t.Monad0(),n=e.Bind1();return r=>i=>{if(r==="")return e.Applicative0().pure();const o=i.vh/720,u=15*o,s={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:600};return n.bind(t.measureText(s)(r))(a=>{const f=i.vy+12*o,g=u+6*o*2,d=a+11*o*2,l=i.vx+i.vw/2;return n.bind(t.drawRoundedRect({x:l-d/2,y:f,w:d,h:g})(g/2)(L("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}))(L("Just",{color:{r:0,g:0,b:0,a:255},width:1*o,lineJoin:Xe,lineCap:xc})))(()=>t.drawText({x:l,y:f+g/2,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:pu,baseline:Or}))})}},Pm=t=>{const e=t.Monad0().Bind1(),n=Ac(t),r=Fc(t),i=Ic(t),o=Cc(t),u=zc(t),s=$c(t),a=Qm(t),f=Wc(t);return g=>d=>l=>{const _=Fi(g)(d)(l);return e.bind(n(g.transparentBg)(_))(()=>e.bind(r(d)(l))(()=>e.bind(i(g.halftoneShadows)(d)(l))(()=>e.bind(o(d)(l))(()=>e.bind(u(_)(d)(l))(()=>e.bind(s(d)(l))(()=>e.bind(a(d)(l))(()=>e.bind(g.watermark===""?t.Monad0().Applicative0().pure():t.drawText({x:_.vx+6,y:_.vy+6,content:g.watermark,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:Qi,baseline:Jc}))(()=>f(l.frameTitle)(_)))))))))}},Dm=t=>{const e=t.Monad0().Bind1(),n=Ac(t),r=Fc(t),i=Ic(t),o=Cc(t),u=zc(t),s=$c(t),a=qc(t),f=Wc(t);return g=>d=>l=>_=>{const h=Fi(g)(d)(l);return e.bind(n(g.transparentBg)(h))(()=>e.bind(r(d)(l))(()=>e.bind(i(g.halftoneShadows)(d)(l))(()=>e.bind(o(d)(l))(()=>e.bind(u(h)(d)(l))(()=>e.bind(s(d)(l))(()=>e.bind(a(d)(l)(_))(()=>e.bind(g.watermark===""?t.Monad0().Applicative0().pure():t.drawText({x:h.vx+6,y:h.vy+6,content:g.watermark,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:Qi,baseline:Jc}))(()=>f(l.frameTitle)(h)))))))))}},Vc=t=>e=>n=>{const r=dt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),o=dt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;c()},Am=Hc(gc),Im=Dm(gc),Rm=t=>{const e=t.vx+t.vw-4,n=t.vy+t.vh-4,r=t.vx+4,i=t.vy+4,o=u=>{if(u.tag==="Leaf")return M;if(u.tag==="Node")return $t("Node",u._1,u._2,u._3,{...u._4,x:Vc(r)(e-u._4.w)(u._4.x),y:Vc(i)(n-u._4.h)(u._4.y)},o(u._5),o(u._6));c()};return o},Fm=t=>e=>n=>r=>i=>o=>{const u={padding:24,transparentBg:!1,halftoneShadows:!0,watermark:""},s=Lp(t)(e);return()=>{const a=s(),f=Am(n)(r)(a)(),g=mp(i)(Rm(Fi(u)(n)(r))(f))(o);return Im(u)(n)(r)(g.applied)(a)(),g.springs}},Jn=t=>"rgb("+fe(t.r)+","+fe(t.g)+","+fe(t.b)+")",Bi=Nr(pr("Fixed",mr(0)(20)(4))),Bm=t=>"translate("+Bi(t.tx)+","+Bi(t.ty)+") scale("+Bi(t.sx)+","+Bi(t.sy)+")",Jt=Nr(pr("Fixed",mr(0)(20)(2))),Tu=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,i=r>=0&&r<t.length?L("Just",t[r]):T;if(i.tag==="Nothing"){n=t.length;continue}if(i.tag==="Just"){if(i._1===1){e.push("M"),e.push(Jt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===2){e.push("L"),e.push(Jt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===3){e.push("Q"),e.push(Jt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),n=r+5|0;continue}if(i._1===4){e.push("C"),e.push(Jt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+5|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+6|0;return o>=0&&o<t.length?t[o]:0})())),n=r+7|0;continue}if(i._1===5){e.push("Z"),n=r+1|0;continue}n=t.length;continue}c()}return si(" ")(e)},Mm={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},vu=(()=>{const t=hn("&")("&"),e=hn("<")("<"),n=(()=>{const r=hn(">")(">"),i=(()=>{const o=hn('"')(""");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),$m=t=>{if(t.style==="RunText")return"<tspan>"+vu(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'Ioskeley Mono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+vu(t.text)+"</tspan>";c()},Te=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},Uc={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>Mm},zm={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>Uc},Om={pure:t=>e=>()=>t,Apply0:()=>Uc},qm={Applicative0:()=>Om,Bind1:()=>zm},Hm=t=>e=>'<defs><pattern id="'+t+'" x="0" y="0" width="'+Jt(e.tile)+'" height="'+Jt(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+Jt(e.tile)+'" height="'+Jt(e.tile)+'" fill="'+Jn(e.bgColor)+'" fill-opacity="'+Jt(ot(e.bgColor.a)/255)+'"/>')+'<circle cx="'+Jt(e.tile/2)+'" cy="'+Jt(e.tile/2)+'" r="'+Jt(e.dotRadius)+'" fill="'+Jn(e.dotColor)+'"/></pattern></defs><rect x="'+Jt(e.viewport.vx)+'" y="'+Jt(e.viewport.vy)+'" width="'+Jt(e.viewport.vw)+'" height="'+Jt(e.viewport.vh)+'" fill="url(#'+t+')"/>',Yc=t=>e=>'<path d="'+Tu(t)+'" fill="'+Jn(e)+'" fill-opacity="'+Jt(ot(e.a)/255)+'"/>',Wm=t=>e=>n=>r=>'<rect x="'+Jt(t.x)+'" y="'+Jt(t.y)+'" width="'+Jt(t.w)+'" height="'+Jt(t.h)+'" rx="'+Jt(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+Jn(n._1.color)+'" fill-opacity="'+Jt(ot(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';c()})()+(()=>{if(r.tag==="Just")return' stroke="'+Jn(r._1.color)+'" stroke-opacity="'+Jt(ot(r._1.color.a)/255)+'" stroke-width="'+Jt(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";c()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";c()})()+'"';if(r.tag==="Nothing")return"";c()})()+"/>",Xc=t=>e=>'<path d="'+Tu(t)+'" fill="none" stroke="'+Jn(e.color)+'" stroke-opacity="'+Jt(ot(e.color.a)/255)+'" stroke-width="'+Jt(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";c()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";c()})()+'"/>',Vm=t=>{const e=Us(kr(t.content));return'<text x="'+Jt(t.x)+'" y="'+Jt(t.y)+'"'+(()=>{if(t.baseline==="BaselineTop")return' dy="0.8em"';if(t.baseline==="BaselineMiddle")return' dy="0.32em"';if(t.baseline==="BaselineAlphabetic"||t.baseline==="BaselineBottom")return"";c()})()+' fill="'+Jn(t.color)+'" fill-opacity="'+Jt(ot(t.color.a)/255)+'" font-size="'+Jt(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+fe(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";c()})()+'">'+(e.length===1&&e[0].style==="RunText"?vu(e[0].text):si("")(O($m)(e)))+"</text>"},Um=Pm({fillPath:t=>e=>Te(Yc(t)(e.color)),strokePath:t=>e=>Te(Xc(t)(e)),fillStrokePath:t=>e=>n=>Te(Yc(t)(e.color)+Xc(t)(n)),drawRoundedRect:t=>e=>n=>r=>Te(Wm(t)(e)(n)(r)),drawText:t=>Te(Vm(t)),pushTransform:t=>Te((()=>{const e='transform="'+Bm(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:Te("</g>"),pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const i=r.value;n.clipCounter.value=i+1|0;const o="clip"+fe(i);return Te((()=>{const u='clip-path="url(#'+o+')"';return'<defs><clipPath id="'+o+'"><path d="'+Tu(t)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";c()})()+"/></clipPath></defs>"+(u===""?"<g>":"<g "+u+">")})())(n)()}},popClip:Te("</g>"),pushBlend:t=>Te((()=>{const e=(()=>{if(t==="Normal")return'style="mix-blend-mode: normal"';if(t==="Difference")return'style="mix-blend-mode: difference"';c()})();return e===""?"<g>":"<g "+e+">"})()),popBlend:Te("</g>"),pushAlpha:t=>Te((()=>{const e='opacity="'+Jt(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:Te("</g>"),pushLayer:t=>e=>{const n=(()=>{if(t==="LayerNodeMask"){const r=e.maskDepth;return()=>{const i=r.value;e.maskDepth.value=i+1|0}}return()=>{}})();return()=>{n(),e.out.push("<g>")}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;n>0&&(t.maskDepth.value=r),t.out.push("</g>")}},setViewport:t=>e=>()=>{},clearBackground:t=>e=>Te('<rect x="'+Jt(e.viewport.vx)+'" y="'+Jt(e.viewport.vy)+'" width="'+Jt(e.viewport.vw)+'" height="'+Jt(e.viewport.vh)+'" fill="'+Jn(t)+'" opacity="'+Jt(ot(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,Te(Hm("bg-dots-"+fe(r))(t))(e)()}},measureText:t=>e=>n=>{const r=cc(t.family)(t.size)(t.weight)(kr(e));return()=>r},Monad0:()=>qm}),Ym=t=>e=>{const n={padding:24,transparentBg:!1,halftoneShadows:!0,watermark:""},r=Fi(n)(t)(e);return{viewBox:Jt(r.vx)+" "+Jt(r.vy)+" "+Jt(r.vw)+" "+Jt(r.vh),body:(()=>{const i=[],o={value:0},u={value:0},s={value:0};return Um(n)(t)(e)({out:i,maskDepth:o,clipCounter:u,patternCounter:s,viewport:r})(),si("")(i)})()}},Hr=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(i=>n(i._1)(i._2)),Apply0:()=>Kc(t)}),Kc=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>i=>o=>e.map(u=>w(r(u._1),u._2))(i(o))};return{apply:(()=>{const r=Hr(t);return i=>o=>r.bind(i)(u=>r.bind(o)(s=>Wr(t).pure(u(s))))})(),Functor0:()=>n}},Wr=t=>({pure:e=>n=>t.Applicative0().pure(w(e,n)),Apply0:()=>Kc(t)}),Xm=t=>{const e={Applicative0:()=>Wr(t),Bind1:()=>Hr(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},wu=(t,e)=>({tag:t,_1:e}),Dn=(t,e)=>({tag:t,_1:e}),Ee=Xm(dn),zt=Hr(dn),Qe=Ee.state(t=>w(t,t)),fn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},xn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},_e=Wr(dn),Km=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},jm=(()=>{const t=Re.unfoldr(e=>{if(e.tag==="Nil")return T;if(e.tag==="Cons")return L("Just",w(e._1,e._2));c()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._3,n(r._6,i)));c()};return n(e,qt)})())})(),Zm=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Lu=t=>e=>n=>J(r=>i=>t.Bind1().bind(r)(o=>e(o)(i)))(t.Applicative0().pure(n)),tN=J(t=>e=>K(C)(e)()(t))(M),eN=(()=>{const t=(e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=K(C)(a._1)()(s),i=a._2;continue}c()}return u})(M);return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._3,n(r._6,i)));c()};return n(e,qt)})())})(),jc=If(_e)(Dt),nN=t=>wu("Par",t),Zc=t=>wu("Seq",t),rN=t=>e=>n=>{const r=Mn(jt,T,i=>i._1===t,n);if(r.tag==="Just"){const i=$n(jt,T,r._1,w(t,e),n);if(i.tag==="Nothing")return n;if(i.tag==="Just")return i._1;c()}if(r.tag==="Nothing")return oe(n)(w(t,e));c()},iN=t=>e=>O(n=>n._1===t?w(n._1,{...n._2,label:L("Just",e)}):w(n._1,n._2)),Be=t=>Ee.state(e=>w(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:L("Just",{msg:t,line:e.currentLine,column:e.currentColumn})};c()})())),oN=t=>zt.bind(Qe)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+fe(e.kfCounter);if(Ze(i=>i.id===n,e.keyframes))return Be("duplicate frame name "+n);const r={...e,keyframes:oe(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges}),kfCounter:e.kfCounter+1|0,currentKf:L("Just",n)};return Ee.state(i=>w(void 0,r))}),uN=t=>e=>{const n=e.from+"->"+e.to,r=e.newFrom+"->"+e.newTo,i=Et("Left","cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist"),o=fn(n)(t.currEdges)?Et("Right",void 0):i;return(()=>{if(o.tag==="Left"){const u=o._1;return s=>Et("Left",u)}if(o.tag==="Right"){const u=o._1;return s=>s(u)}c()})()(()=>{const u="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newFrom;if(!xn(e.newFrom)(t.currNodes))return Et("Left",u);const s="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo;if(!xn(e.newTo)(t.currNodes))return Et("Left",s);const a="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists";return n!==r&&fn(r)(t.currEdges)?Et("Left",a):Et("Right",{nextCurrEdges:K(C)(r)()(hr(C)(n)(t.currEdges)),newId:r,newEdge:{id:r,from:{node:e.newFrom,port:T},to:{node:e.newTo,port:T}}})})},sN={graphNodes:[],graphEdges:M,currNodes:M,currEdges:M,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:T,currentLine:0,currentColumn:0,error:T},tf=t=>e=>zt.bind(Qe)(n=>{const r="ev-"+fe(n.eventCounter);return zt.bind((()=>{const i={...n,eventCounter:n.eventCounter+1|0};return Ee.state(o=>w(void 0,i))})())(()=>_e.pure({events:[{id:r,kind:e,when:t}],firstId:L("Just",r),lastId:L("Just",r)}))}),aN=t=>e=>{if(e.tag==="Token"){const n=e._1;return zt.bind(Qe)(r=>{const i=!xn(n.from)(r.currNodes),o=!xn(n.to)(r.currNodes);if(i||o)return zt.bind(Be(i?o?"token references unknown node: "+n.from+", "+n.to:"token references unknown node: "+n.from:o?"token references unknown node: "+n.to:"token references unknown node: "))(()=>_e.pure({events:[],firstId:T,lastId:T}));const u=n.to+"->"+n.from,s=n.from+"->"+n.to;return fn(s)(r.currEdges)?tf(t)(Ns("SendToken",{from:n.from,to:n.to,edge:s,direction:p_,labels:n.labels})):fn(u)(r.currEdges)?tf(t)(Ns("SendToken",{from:n.from,to:n.to,edge:u,direction:m_,labels:n.labels})):zt.bind(Be("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>_e.pure({events:[],firstId:T,lastId:T}))})}return _e.pure({events:[],firstId:T,lastId:T})},cN=t=>xt(e=>Km(e)(t.graphEdges))(bt(gr,jm(t.currEdges))),fN=t=>e=>{const n=ct(i=>i.from.node===e.id||i.to.node===e.id,cN(t)),r=Lu(vf)(i=>o=>{const u=o.from+"->"+e.id,s=e.id+"->"+o.to,a=o.from+"->"+o.to,f="via "+o.from+" "+o.to+": no edge "+o.from+"\u2192"+e.id;if(!fn(u)(t.currEdges))return Et("Left",f);const g="via "+o.from+" "+o.to+": no edge "+e.id+"\u2192"+o.to;if(!fn(s)(t.currEdges))return Et("Left",g);const d="via "+o.from+" "+o.to+": would create "+o.from+"\u2192"+o.to+" but it already exists";return fn(a)(t.currEdges)||Zm(a)(i.synthesized)?Et("Left",d):Et("Right",{consumed:K(C)(u)()(K(C)(s)()(i.consumed)),synthesized:K(C)(a)({id:a,from:{node:o.from,port:T},to:{node:o.to,port:T}})(i.synthesized)})})({consumed:M,synthesized:M})(e.via);return(()=>{if(r.tag==="Left"){const i=r._1;return o=>Et("Left",i)}if(r.tag==="Right"){const i=r._1;return o=>o(i)}c()})()(i=>{const o=i.consumed,u=ct(s=>!fn(s.id)(o),n);return u.length===0?Et("Right",{nextCurrEdges:xe(C.compare,pe,tn(C.compare,t.currEdges,tN(O(s=>s.id)(n))),eN((()=>{const s=a=>{if(a.tag==="Leaf")return M;if(a.tag==="Node")return $t("Node",a._1,a._2,a._3,void 0,s(a._5),s(a._6));c()};return s(i.synthesized)})())),synthesized:i.synthesized}):Et("Left","cannot delete node "+e.id+": still connected ("+si(", ")(O(s=>s.from.node+"\u2192"+s.to.node)(u))+"). Use -edge to drop them or `via a b` to merge "+e.id+"'s endpoints.")})},ef=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq")return St(t._1)(ef);c()},gN=t=>({nodes:O(Yr)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Mt("Cons",n._4,e(n._6,r)));c()};return bt(Wt.foldr,e(t.graphEdges,qt))})(),constraints:[]}),_N=t=>{if(t.tag==="AddNode"){const e=t._1;return Ee.state(n=>w(void 0,{...n,graphNodes:rN(e.id)({id:e.id,size:w(1,1),ports:[],label:L("Just",e.label)})(n.graphNodes),currNodes:K(C)(e.id)()(n.currNodes)}))}if(t.tag==="DelNode"){const e=t._1;return zt.bind(Qe)(n=>{if(!xn(e.id)(n.currNodes))return Be("cannot delete node "+e.id+": does not exist");const r=fN(n)(e);if(r.tag==="Left")return Be(r._1);if(r.tag==="Right"){const i=r._1;return Ee.state(o=>w(void 0,{...o,currNodes:hr(C)(e.id)(o.currNodes),currEdges:i.nextCurrEdges,graphEdges:xe(C.compare,pe,i.synthesized,o.graphEdges)}))}c()})}if(t.tag==="ModNode"){const e=t._1;return zt.bind(Qe)(n=>{if(!xn(e.id)(n.currNodes))return Be("cannot modify node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=e.label._1;return Ee.state(i=>w(void 0,{...i,graphNodes:iN(e.id)(r)(i.graphNodes)}))}if(e.label.tag==="Nothing")return _e.pure();c()})}if(t.tag==="AddEdge"){const e=t._1;return zt.bind(Qe)(n=>{const r=!xn(e.from)(n.currNodes),i=!xn(e.to)(n.currNodes);if(r||i)return Be("cannot add edge "+e.from+"\u2192"+e.to+": unknown node "+(r?i?e.from+", "+e.to:e.from:i?e.to:""));const o=e.from+"->"+e.to;return Ee.state(u=>w(void 0,{...u,graphEdges:K(C)(o)({id:o,from:{node:e.from,port:T},to:{node:e.to,port:T}})(u.graphEdges),currEdges:K(C)(o)()(u.currEdges)}))})}if(t.tag==="DelEdge"){const e=t._1;return zt.bind(Qe)(n=>{const r=e.from+"->"+e.to;return fn(r)(n.currEdges)?Ee.state(i=>w(void 0,{...i,currEdges:hr(C)(r)(i.currEdges)})):Be("cannot delete edge "+e.from+"\u2192"+e.to+": does not exist")})}if(t.tag==="RepointEdge"){const e=t._1;return zt.bind(Qe)(n=>{const r=uN(n)(e);if(r.tag==="Left")return Be(r._1);if(r.tag==="Right"){const i=r._1;return Ee.state(o=>w(void 0,{...o,currEdges:i.nextCurrEdges,graphEdges:K(C)(i.newId)(i.newEdge)(o.graphEdges)}))}c()})}return _e.pure()},dN=t=>zt.bind(Ee.state(e=>w(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>_N(t.op)),lN=t=>e=>zt.bind(jc(dN)(e))(()=>zt.bind(Qe)(n=>{const r=t.tag==="Just"&&t._1!==""?t._1:"kf-"+fe(n.kfCounter);if(Ze(o=>o.id===r,n.keyframes))return Be("duplicate frame name "+r);const i={...n,keyframes:oe(n.keyframes)({id:r,nodes:n.currNodes,edges:n.currEdges}),kfCounter:n.kfCounter+1|0,currentKf:L("Just",r),scenes:(()=>{if(n.currentKf.tag==="Nothing")return n.scenes;if(n.currentKf.tag==="Just")return oe(n.scenes)(ys("Structural",{from:n.currentKf._1,to:r,focus:T}));c()})()};return Ee.state(o=>w(void 0,i))})),hN=t=>e=>{const n=Bt(r=>T,r=>i=>L("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return _e.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return zt.bind(Vr(t)(n._1.head))(i=>zt.bind(Lu({Applicative0:()=>Wr(dn),Bind1:()=>Hr(dn)})(o=>u=>zt.bind(Vr((()=>{if(o.lastId.tag==="Just")return Eo("After",o.lastId._1);if(o.lastId.tag==="Nothing")return t;c()})())(u))(s=>_e.pure({events:[...o.events,...s.events],firstId:(()=>{if(o.firstId.tag==="Just")return L("Just",o.firstId._1);if(o.firstId.tag==="Nothing")return s.firstId;c()})(),lastId:(()=>{if(s.lastId.tag==="Just")return L("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return o.lastId;c()})()})))(i)(r))(o=>_e.pure(o)))}c()},pN=t=>e=>{const n=Bt(r=>T,r=>i=>L("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return _e.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return zt.bind(Vr(t)(n._1.head))(i=>zt.bind(mN((()=>{if(i.firstId.tag==="Just")return Eo("With",i.firstId._1);if(i.firstId.tag==="Nothing")return t;c()})())(r))(o=>_e.pure({events:[...i.events,...o.events],firstId:i.firstId,lastId:(()=>{if(i.lastId.tag==="Just")return L("Just",i.lastId._1);if(i.lastId.tag==="Nothing")return o.lastId;c()})()})))}c()},Vr=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return zt.bind(Ee.state(r=>w(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>aN(t)(n.op))}if(e.tag==="Seq")return hN(t)(e._1);if(e.tag==="Par")return pN(t)(e._1);c()},mN=t=>Lu({Applicative0:()=>Wr(dn),Bind1:()=>Hr(dn)})(e=>n=>zt.bind(Vr(t)(n))(r=>_e.pure({events:[...e.events,...r.events],firstId:(()=>{if(e.firstId.tag==="Just")return L("Just",e.firstId._1);if(e.firstId.tag==="Nothing")return r.firstId;c()})(),lastId:(()=>{if(r.lastId.tag==="Just")return L("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;c()})()})))({events:[],firstId:T,lastId:T}),NN=t=>zt.bind(Qe)(e=>{if(e.currentKf.tag==="Nothing")return Be("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return zt.bind(Vr(h_)(t))(r=>zt.bind(Qe)(i=>{const o={...i,scenes:oe(i.scenes)(ys("DataFlow",{keyframe:n,events:r.events,focus:T}))};return Ee.state(u=>w(void 0,o))}))}c()}),yN=t=>zt.bind(Qe)(e=>{if(e.error.tag==="Just")return _e.pure();if(e.error.tag==="Nothing"){const n=ef(t.ops),r=ct(o=>o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge",n),i=ct(o=>!(o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge"),n);return zt.bind((()=>{const o=lN(t.name)(r);return r.length!==0?o:_e.pure()})())(()=>zt.bind((()=>{const o=oN(t.name);return r.length===0&&i.length!==0?o:_e.pure()})())(()=>{const o=NN(t.ops);return i.length!==0?o:_e.pure()}))}c()}),JN=t=>zt.bind(jc(yN)(t.frames))(()=>zt.bind(Qe)(e=>_e.pure((()=>{if(e.error.tag==="Just")return Et("Left",e.error._1);if(e.error.tag==="Nothing")return Et("Right",{seed:t.seed,graph:gN(e),keyframes:e.keyframes,scenes:e.scenes});c()})())))(sN)._1,ir=(t,e)=>({tag:"ParseError",_1:t,_2:e}),z=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),Mi=(t,e,n)=>({tag:t,_1:e,_2:n}),xN=t=>Mi("More",t),TN=t=>Mi("Lift",t),nf={map:t=>e=>(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,f)=>r(g=>u(a,t(f)))))},vN={alt:t=>e=>(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(f=>t(z(s,a,!1),r,i,(g,d)=>{const l=g._3;return r(_=>l?o(g,d):e(n,r,i,o,u))},u))},Functor0:()=>nf},wN=t=>{const e=t.Monad0();return n=>r=>{const i=o=>{let u=o,s=!0,a;for(;s;){const f=u();if(f.tag==="More"){u=f._1;continue}if(f.tag==="Lift"){s=!1,a=e.Bind1().Apply0().Functor0().map(Ou)(f._1);continue}if(f.tag==="Stop"){s=!1,a=e.Applicative0().pure(fr("Done",w(f._2,f._1)));continue}c()}return a};return t.tailRecM(i)(o=>r(n,xN,TN,(u,s)=>Mi("Stop",u,Et("Left",s)),(u,s)=>Mi("Stop",u,Et("Right",s))))}},rf=(t,e,n,r,i)=>i(t,t._2),LN={index:0,line:1,column:1},bN=(t=>{const e=wN(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(Xr)(e(z(n,LN,!1))(r))})(Sf),of={apply:t=>e=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,f)=>r(g=>{const d=n._3&&!a._3?z(a._1,a._2,!0):a;return e(d,r,i,o,(l,_)=>r(h=>u(d._3&&!l._3?z(l._1,l._2,!0):l,f(_))))}))),Functor0:()=>nf},uf={pure:t=>(e,n,r,i,o)=>o(e,t),Apply0:()=>of},EN={bind:t=>e=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,f)=>r(g=>e(f)(n._3&&!a._3?z(a._1,a._2,!0):a,r,i,o,u)))),Apply0:()=>of},kN={Applicative0:()=>uf,Bind1:()=>EN},$i=t=>(e,n,r,i,o)=>n(u=>rf(e,n,r,i,(s,a)=>n(f=>i(e._3&&!s._3?z(s._1,s._2,!0):s,ir(t,a))))),GN={empty:$i("No alternative"),Alt0:()=>vN},CN={Applicative0:()=>uf,Plus1:()=>GN},Ae=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return i=>t.tailRecM(o=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(Ou)(i))(r.pure(fr("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return fr("Loop",Mt("Cons",u._1,o));if(u.tag==="Done")return fr("Done",(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){f=Mt("Cons",h._1,_),g=h._2;continue}c()}return l})(qt)(o));c()})())))(qt)})({tailRecM:t=>e=>(n,r,i,o,u)=>{const s=(a,f,g)=>t(f)(a,r,i,o,(d,l)=>{const _=a._3&&!d._3?z(d._1,d._2,!0):d;if(l.tag==="Loop")return g===0?r(h=>s(_,l._1,30)):s(_,l._1,g-1|0);if(l.tag==="Done")return u(_,l._1);c()});return s(n,e,30)},Monad0:()=>kN})(CN),kt=t=>e=>{const n=$i("Expected "+e);return(r,i,o,u,s)=>{const a=r._1,f=r._2;return i(g=>t(z(a,f,!1),i,o,(d,l)=>{const _=d._3;return i(h=>_?u(d,l):n(r,i,o,u,s))},s))}},bu=t=>(e,n,r,i,o)=>{const u=e._3,s=e._1,a=e._2;return n(f=>{const g=(d,l)=>{const _=d._3;return n(h=>_?i(z(d._1,d._2,u),l):o(e,void 0))};return n(d=>n(l=>t(z(s,a,!1),n,r,(_,h)=>g(z(_._1,_._2,!1),h),(_,h)=>n(p=>n(m=>$i("Negated parser succeeded")(_,n,r,g,(N,y)=>n(x=>o(_._3&&!N._3?z(N._1,N._2,!0):N,y))))))))})},SN=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return L("Just",n);if(r.tag==="Just")return L("Just",(i,o,u,s,a)=>{const f=i._1,g=i._2;return o(d=>n(z(f,g,!1),o,u,(l,_)=>{const h=l._3;return o(p=>h?s(l,_):r._1(i,o,u,s,a))},a))});c()})(T);return n=>{const r=e(n);if(r.tag==="Nothing")return $i("No alternative");if(r.tag==="Just")return r._1;c()}},QN=t=>e=>n=>(r,i,o,u,s)=>i(a=>i(f=>i(g=>i(d=>t(r,i,o,u,(l,_)=>i(h=>i(p=>{const m=r._3&&!l._3?z(l._1,l._2,!0):l;return n(m,i,o,u,(N,y)=>i(x=>{const v=m._3&&!N._3?z(N._1,N._2,!0):N;return i(b=>i(E=>{const k=r._3&&!v._3?z(v._1,v._2,!0):v;return e(k,i,o,u,(F,U)=>i(tt=>s(k._3&&!F._3?z(F._1,F._2,!0):F,y)))}))}))}))))))),Eu=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=t1()(n);return r.tag==="Just"&&r._1===10?{index:t.index+1|0,line:t.line,column:t.column}:{index:t.index+1|0,line:t.line+1|0,column:1}}return e===9?{index:t.index+1|0,line:t.line,column:(t.column+8|0)-no(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},PN=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,f=i,g=o,d=ai(f);if(d.tag==="Nothing"){u=!1,s=a;continue}if(d.tag==="Just"){r=d._1.tail===""?Eu(a)(d._1.head)(g):Eu(a)(d._1.head)(d._1.tail),i=d._1.tail,o=g;continue}c()}return s},Ut=t=>(e,n,r,i,o)=>{const u=ai(e._1);if(u.tag==="Nothing")return i(e,ir("Unexpected EOF",e._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return i(e,ir("Expected Char",e._2));if(u._1.head>=0&&u._1.head<=65535){const s=Es(u._1.head);return t(s)?o(z(u._1.tail,Eu(e._2)(u._1.head)(u._1.tail),!0),s):i(e,ir("Predicate unsatisfied",e._2))}}c()},sf=(t,e,n,r,i)=>t._1===""?i(z(t._1,t._2,!0),void 0):r(t,ir("Expected EOF",t._2)),DN=t=>(e,n,r,i,o)=>{const u=t(e._1);if(u.tag==="Left")return i(e,ir(u._1,e._2));if(u.tag==="Right")return o(z(u._1.remainder,PN(e._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);c()},or=t=>DN(e=>{const n=o_(t)(e);return n.tag==="Just"?Et("Right",{value:t,consumed:t,remainder:n._1}):Et("Left","Expected "+mf(t))}),AN=Ut(t=>!0),af=SN(Dt),cf=(()=>{const t=Ut(e=>e===" "||e===" "||e===`
|
|
8
|
-
`||e==="\r");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(f=>o(e._3&&!s._3?z(s._1,s._2,!0):s,void 0))))})(),ku=(t,e,n,r,i)=>e(o=>or("#")(t,e,n,r,(u,s)=>e(a=>{const f=Ae(Ut(d=>d!==`
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
`&&Z!=="\r"&&Z!=="#"&&Z!=="}")),S=v._3&&!F._3?z(F._1,F._2,!0):F;return d(Z=>Q(S,d,l,y,(V,R)=>d($=>h(S._3&&!V._3?z(V._1,V._2,!0):V,z_(bn(bt(Wt.foldr,R)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(e._3&&!s._3?z(s._1,s._2,!0):s,n,r,i,o))))})(),MN=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>ff(z(o,u,!1),e,n,(a,f)=>{const g=a._3;return e(d=>g?r(a,f):Gu(t,e,n,r,i))},i))},Ur=Ut(t=>t>="0"&&t<="9"),ve=(()=>{const t=kt(Ut(e=>e==="_"))("'_'");return(e,n,r,i,o)=>n(u=>{const s=(g,d)=>n(l=>{const _=Ae((()=>{const p=kt(Ut(N=>N==="_"))("'_'"),m=kt(Ut(N=>N==="-"))("'-'");return(N,y,x,v,b)=>{const E=N._1,k=N._2;return y(F=>zi(z(E,k,!1),y,x,(U,tt)=>{const Q=U._3;return y(S=>{if(Q)return v(U,tt);const Z=N._1,V=N._2;return y(R=>Ur(z(Z,V,!1),y,x,($,I)=>{const G=$._3;return y(D=>{if(G)return v($,I);const P=N._1,A=N._2;return y(H=>p(z(P,A,!1),y,x,(Y,W)=>{const q=Y._3;return y(B=>q?v(Y,W):m(N,y,x,v,b))},b))})},b))})},b))}})()),h=e._3&&!g._3?z(g._1,g._2,!0):g;return n(p=>_(h,n,r,i,(m,N)=>n(y=>o(h._3&&!m._3?z(m._1,m._2,!0):m,vo(d)+bn(bt(Wt.foldr,N))))))}),a=e._1,f=e._2;return n(g=>zi(z(a,f,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?i(d,l):t(e,n,r,i,s))},s))})})(),$N=kt((t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>Gu(z(o,u,!1),e,n,(a,f)=>{const g=a._3;return e(d=>g?r(a,f):ve(t,e,n,r,i))},i))})("frame name (identifier or quoted string)"),zN=(t,e,n,r,i)=>e(o=>ve(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>An(f,e,n,r,(d,l)=>e(_=>{const h=kt((m,N,y,x,v)=>{const b=m._1,E=m._2;return N(k=>or("->")(z(b,E,!1),N,y,(F,U)=>{const tt=F._3;return N(Q=>tt?x(F,U):or("<-")(m,N,y,x,v))},v))})("'->' or '<-'"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=p._3&&!N._3?z(N._1,N._2,!0):N;return e(b=>An(v,e,n,r,(E,k)=>e(F=>{const U=kt(ve)("target node identifier"),tt=v._3&&!E._3?z(E._1,E._2,!0):E;return e(Q=>U(tt,e,n,r,(S,Z)=>e(V=>{const R=Ae((I,G,D,P,A)=>{const H=I._3;return G(Y=>G(W=>An(I,G,D,(q,B)=>P(z(q._1,q._2,H),B),(q,B)=>G(j=>G(X=>{const _t=I._3&&!q._3?z(q._1,q._2,!0):q;return MN(_t,G,D,(pt,ft)=>P(z(pt._1,pt._2,H),ft),(pt,ft)=>G(ht=>A(_t._3&&!pt._3?z(pt._1,pt._2,!0):pt,ft)))})))))}),$=tt._3&&!S._3?z(S._1,S._2,!0):S;return e(I=>R($,e,n,r,(G,D)=>e(P=>(()=>{if(y==="<-"){const H=Dn("Token",{from:Z,to:s,labels:bt(Wt.foldr,D)});return(Y,W,q,B,j)=>j(Y,H)}const A=Dn("Token",{from:s,to:Z,labels:bt(Wt.foldr,D)});return(H,Y,W,q,B)=>B(H,A)})()($._3&&!G._3?z(G._1,G._2,!0):G,e,n,r,i))))})))})))})))})))}))),ON=(t,e,n,r,i)=>e(o=>Ur(t,e,n,r,(u,s)=>e(a=>{const f=Ae(Ur),g=t._3&&!u._3?z(u._1,u._2,!0):u;return e(d=>f(g,e,n,r,(l,_)=>e(h=>{const p=rg(vo(s)+bn(bt(Wt.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(N,y,x,v,b)=>b(N,m)}if(p.tag==="Nothing")return(m,N,y,x,v)=>v(m,0);c()})()(g._3&&!l._3?z(l._1,l._2,!0):l,e,n,r,i)})))}))),Oi=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>or(t)(e,n,r,(a,f)=>i(z(a._1,a._2,u),f),(a,f)=>n(g=>{const d=bu((()=>{const _=kt(Ut(p=>p==="_"))("'_'"),h=kt(Ut(p=>p==="-"))("'-'");return(p,m,N,y,x)=>{const v=p._1,b=p._2;return m(E=>zi(z(v,b,!1),m,N,(k,F)=>{const U=k._3;return m(tt=>{if(U)return y(k,F);const Q=p._1,S=p._2;return m(Z=>Ur(z(Q,S,!1),m,N,(V,R)=>{const $=V._3;return m(I=>{if($)return y(V,R);const G=p._1,D=p._2;return m(P=>_(z(G,D,!1),m,N,(A,H)=>{const Y=A._3;return m(W=>Y?y(A,H):h(p,m,N,y,x))},x))})},x))})},x))}})()),l=e._3&&!a._3?z(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(z(h._1,h._2,u),p),(h,p)=>n(m=>{const N=l._3&&!h._3?z(h._1,h._2,!0):h;return n(y=>Ie(N,n,r,(x,v)=>i(z(x._1,x._2,u),v),(x,v)=>n(b=>o(N._3&&!x._3?z(x._1,x._2,!0):x,t))))})))})))},qN=(t,e,n,r,i)=>e(o=>Me(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>Oi("via")(f,e,n,r,(d,l)=>e(_=>{const h=f._3&&!d._3?z(d._1,d._2,!0):d;return e(p=>ve(h,e,n,r,(m,N)=>e(y=>{const x=h._3&&!m._3?z(m._1,m._2,!0):m;return e(v=>Me(x,e,n,r,(b,E)=>e(k=>{const F=x._3&&!b._3?z(b._1,b._2,!0):b;return e(U=>ve(F,e,n,r,(tt,Q)=>e(S=>i(F._3&&!tt._3?z(tt._1,tt._2,!0):tt,{from:N,to:Q}))))})))})))})))}))),ur=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>or(t)(e,n,r,(a,f)=>i(z(a._1,a._2,u),f),(a,f)=>n(g=>{const d=bu((()=>{const _=kt(Ut(p=>p==="_"))("'_'"),h=kt(Ut(p=>p==="-"))("'-'");return(p,m,N,y,x)=>{const v=p._1,b=p._2;return m(E=>zi(z(v,b,!1),m,N,(k,F)=>{const U=k._3;return m(tt=>{if(U)return y(k,F);const Q=p._1,S=p._2;return m(Z=>Ur(z(Q,S,!1),m,N,(V,R)=>{const $=V._3;return m(I=>{if($)return y(V,R);const G=p._1,D=p._2;return m(P=>_(z(G,D,!1),m,N,(A,H)=>{const Y=A._3;return m(W=>Y?y(A,H):h(p,m,N,y,x))},x))})},x))})},x))}})()),l=e._3&&!a._3?z(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(z(h._1,h._2,u),p),(h,p)=>n(m=>o(l._3&&!h._3?z(h._1,h._2,!0):h,void 0))))})))},HN=(t,e,n,r,i)=>e(o=>ur("+edge")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>Me(f,e,n,r,(d,l)=>e(_=>{const h=kt(ve)("source node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=p._3&&!N._3?z(N._1,N._2,!0):N;return e(b=>Me(v,e,n,r,(E,k)=>e(F=>{const U=kt(ve)("target node identifier"),tt=v._3&&!E._3?z(E._1,E._2,!0):E;return e(Q=>U(tt,e,n,r,(S,Z)=>e(V=>i(tt._3&&!S._3?z(S._1,S._2,!0):S,Dn("AddEdge",{from:y,to:Z})))))})))})))})))}))),WN=(t,e,n,r,i)=>e(o=>ur("+node")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>Me(f,e,n,r,(d,l)=>e(_=>{const h=kt(ve)("node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=p._3&&!N._3?z(N._1,N._2,!0):N;return e(b=>BN(v,e,n,r,(E,k)=>e(F=>i(v._3&&!E._3?z(E._1,E._2,!0):E,Dn("AddNode",{id:y,label:k})))))})))})))}))),VN=(t,e,n,r,i)=>e(o=>ur("-edge")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>Me(f,e,n,r,(d,l)=>e(_=>{const h=kt(ve)("source node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=p._3&&!N._3?z(N._1,N._2,!0):N;return e(b=>Me(v,e,n,r,(E,k)=>e(F=>{const U=kt(ve)("target node identifier"),tt=v._3&&!E._3?z(E._1,E._2,!0):E;return e(Q=>U(tt,e,n,r,(S,Z)=>e(V=>i(tt._3&&!S._3?z(S._1,S._2,!0):S,Dn("DelEdge",{from:y,to:Z})))))})))})))})))}))),UN=(t,e,n,r,i)=>e(o=>ur("-node")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>Me(f,e,n,r,(d,l)=>e(_=>{const h=kt(ve)("node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=Ae((E,k,F,U,tt)=>{const Q=E._3;return qN(E,k,F,(S,Z)=>U(z(S._1,S._2,Q),Z),tt)}),b=p._3&&!N._3?z(N._1,N._2,!0):N;return e(E=>v(b,e,n,r,(k,F)=>e(U=>i(b._3&&!k._3?z(k._1,k._2,!0):k,Dn("DelNode",{id:y,via:bt(Wt.foldr,F)})))))})))})))}))),YN=(t,e,n,r,i)=>e(o=>ur("~edge")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>Me(f,e,n,r,(d,l)=>e(_=>{const h=kt(ve)("source node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=p._3&&!N._3?z(N._1,N._2,!0):N;return e(b=>Me(v,e,n,r,(E,k)=>e(F=>{const U=kt(ve)("target node identifier"),tt=v._3&&!E._3?z(E._1,E._2,!0):E;return e(Q=>U(tt,e,n,r,(S,Z)=>e(V=>{const R=tt._3&&!S._3?z(S._1,S._2,!0):S;return e($=>Ie(R,e,n,r,(I,G)=>e(D=>{const P=kt(or("->"))("'->'"),A=R._3&&!I._3?z(I._1,I._2,!0):I;return e(H=>P(A,e,n,r,(Y,W)=>e(q=>{const B=A._3&&!Y._3?z(Y._1,Y._2,!0):Y;return e(j=>Ie(B,e,n,r,(X,_t)=>e(pt=>{const ft=kt(ve)("new source node identifier"),ht=B._3&&!X._3?z(X._1,X._2,!0):X;return e(Lt=>ft(ht,e,n,r,(Pt,lt)=>e(Rt=>{const mt=ht._3&&!Pt._3?z(Pt._1,Pt._2,!0):Pt;return e(gt=>Me(mt,e,n,r,(it,rt)=>e(at=>{const Nt=kt(ve)("new target node identifier"),yt=mt._3&&!it._3?z(it._1,it._2,!0):it;return e(Ct=>Nt(yt,e,n,r,(Ot,re)=>e(je=>i(yt._3&&!Ot._3?z(Ot._1,Ot._2,!0):Ot,Dn("RepointEdge",{from:y,to:Z,newFrom:lt,newTo:re})))))})))})))})))})))})))})))})))})))})))}))),XN=(t,e,n,r,i)=>e(o=>rf(t,e,n,r,(u,s)=>e(a=>{const f=kt(af([WN,UN,YN,HN,VN,zN]))("statement (+node, -node, +edge, -edge, ~edge, or 'a -> b')"),g=t._3&&!u._3?z(u._1,u._2,!0):u;return e(d=>f(g,e,n,r,(l,_)=>e(h=>i(g._3&&!l._3?z(l._1,l._2,!0):l,wu("Leaf",{op:_,line:s.line,column:s.column})))))}))),KN=(t,e,n,r,i)=>e(o=>ur("seed")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>An(f,e,n,r,(d,l)=>e(_=>{const h=kt(ON)("integer (seed value)"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=p._3&&!N._3?z(N._1,N._2,!0):N;return e(b=>Ie(v,e,n,r,(E,k)=>e(F=>i(v._3&&!E._3?z(E._1,E._2,!0):E,y))))})))})))}))),Cu=QN((()=>{const t=kt(Ut(e=>e==="{"))("'{'");return(e,n,r,i,o)=>n(u=>n(s=>t(e,n,r,i,(a,f)=>n(g=>n(d=>{const l=e._3&&!a._3?z(a._1,a._2,!0):a;return Ie(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?z(_._1,_._2,!0):_,h)))})))))})())(kt((()=>{const t=kt(Ut(e=>e==="}"))("'}'");return(e,n,r,i,o)=>n(u=>n(s=>Ie(e,n,r,i,(a,f)=>n(g=>n(d=>{const l=e._3&&!a._3?z(a._1,a._2,!0):a;return t(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?z(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),jN=(t,e,n,r,i)=>e(o=>Oi("seq")(t,e,n,r,(u,s)=>e(a=>Cu(Su(Zc))(t._3&&!u._3?z(u._1,u._2,!0):u,e,n,r,i)))),ZN=(t,e,n,r,i)=>e(o=>Oi("par")(t,e,n,r,(u,s)=>e(a=>Cu(Su(nN))(t._3&&!u._3?z(u._1,u._2,!0):u,e,n,r,i)))),Su=t=>{const e=Ae(t2());return(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,f)=>r(g=>u(n._3&&!a._3?z(a._1,a._2,!0):a,t(bt(Wt.foldr,f))))))},t2=hf(()=>{const t=bu(kt(Ut(e=>e==="}"))("'}'"));return(e,n,r,i,o)=>n(u=>{const s=e._3;return n(a=>n(f=>Ie(e,n,r,(g,d)=>i(z(g._1,g._2,s),d),(g,d)=>n(l=>n(_=>{const h=e._3&&!g._3?z(g._1,g._2,!0):g;return t(h,n,r,(p,m)=>i(z(p._1,p._2,s),m),(p,m)=>n(N=>{const y=h._3&&!p._3?z(p._1,p._2,!0):p;return n(x=>{const v=af([(E,k,F,U,tt)=>{const Q=E._3;return ZN(E,k,F,(S,Z)=>U(z(S._1,S._2,Q),Z),tt)},(E,k,F,U,tt)=>{const Q=E._3;return jN(E,k,F,(S,Z)=>U(z(S._1,S._2,Q),Z),tt)},XN]),b=e._3&&!y._3?z(y._1,y._2,!0):y;return n(E=>v(b,n,r,i,(k,F)=>n(U=>{const tt=b._3&&!k._3?z(k._1,k._2,!0):k;return n(Q=>An(tt,n,r,i,(S,Z)=>n(V=>{const R=tt._3&&!S._3?z(S._1,S._2,!0):S;return n($=>IN(R,n,r,i,(I,G)=>n(D=>o(R._3&&!I._3?z(I._1,I._2,!0):I,F))))})))})))})}))})))))})}),e2=(t,e,n,r,i)=>e(o=>Oi("frame")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>$N(f,e,n,r,(d,l)=>e(_=>{const h=f._3&&!d._3?z(d._1,d._2,!0):d;return e(p=>Ie(h,e,n,r,(m,N)=>e(y=>{const x=Cu(Su(Zc)),v=h._3&&!m._3?z(m._1,m._2,!0):m;return e(b=>x(v,e,n,r,(E,k)=>e(F=>{const U=v._3&&!E._3?z(E._1,E._2,!0):E;return e(tt=>Ie(U,e,n,r,(Q,S)=>e(Z=>i(U._3&&!Q._3?z(Q._1,Q._2,!0):Q,{name:L("Just",l),ops:k}))))})))})))})))}))),n2=(t,e,n,r,i)=>e(o=>Ie(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>{const d=(h,p)=>e(m=>{const N=Ae(e2),y=f._3&&!h._3?z(h._1,h._2,!0):h;return e(x=>N(y,e,n,r,(v,b)=>e(E=>{const k=y._3&&!v._3?z(v._1,v._2,!0):v;return e(F=>Ie(k,e,n,r,(U,tt)=>e(Q=>{const S=kt(sf)("'frame' or end of input"),Z=k._3&&!U._3?z(U._1,U._2,!0):U;return e(V=>S(Z,e,n,r,(R,$)=>e(I=>i(Z._3&&!R._3?z(R._1,R._2,!0):R,{seed:(()=>{if(p.tag==="Just")return p._1;if(p.tag==="Nothing")return 0;c()})(),frames:bt(Wt.foldr,b)}))))})))})))}),l=f._1,_=f._2;return e(h=>e(p=>KN(z(l,_,!1),e,n,(m,N)=>{const y=m._3;return e(x=>y?r(m,N):d(f,T))},(m,N)=>e(y=>d(m,L("Just",N))))))})}))),r2=t=>{const e=bN(t)(n2);if(e.tag==="Left")return Et("Left",{msg:e._1._1,line:e._1._2.line,column:e._1._2.column});if(e.tag==="Right")return Et("Right",e._1);c()},i2=t=>{const e=r2(t);if(e.tag==="Left")return Et("Left",e._1.msg);if(e.tag==="Right")return Et("Right",e._1);c()};function Qu(t,e,n,r){if(typeof window<"u"){var i=window[n];if(i!=null&&r instanceof i)return e(r)}for(var o=r;o!=null;){var u=Object.getPrototypeOf(o),s=u.constructor.name;if(s===n)return e(r);if(s==="Object")return t;o=u}return t}function qi(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function o2(t){return function(e){return function(){e.textContent=t}}}function u2(t){return function(){return function(e){return t(e)()}}}function s2(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const a2=function(){return window};function c2(t){return function(e){return function(){e.value=t}}}function f2(t){return function(){return t.valueAsNumber}}function g2(t){return function(){return t.value}}function _2(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const d2=t=>t,l2=t=>()=>t.clientWidth||0,h2=()=>window.devicePixelRatio||1,Pu=(t,e)=>{e.innerHTML=t},p2=(t,e,n)=>{t.style.setProperty(e,n)},m2=(t,e)=>t.querySelector(`[data-mg="${e}"]`),N2=t=>e=>t===e,y2=t=>t,J2=Dt.foldMap(dg),gf=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},x2=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},T2=y2("CanvasRenderer"),v2=t=>e=>{const n=t-e*ot(vn(ju(t/e)));return e<=0?0:n<0?n+e:n},w2=t=>e=>{const n=gp(t);return()=>{const r=n(),i=P1(L1)(t)(pp(r)(t));if(i.tag==="Left")return rs("[markgraf] precompute failed")();if(i.tag==="Right")return e(i._1)();c()}},L2=t=>J(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),b2=`
|
|
1
|
+
var vw=(function(yu){"use strict";function ka(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 En(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const Le=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}},b1={map:O},Ea=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}},ie=function(t){return t.toString()},Ca=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},L1=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})+'"'},xu=t=>t,ye=xu("LT"),xe=xu("GT"),Ge=xu("EQ"),w=(t,e)=>({tag:t,_1:e}),T=w("Nothing"),Yt=t=>w("Just",t),Sa=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;g()},Ga=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;g()},Gt=(t,e)=>({tag:t,_1:e}),k1=t=>Gt("Right",t),E1={map:t=>e=>{if(e.tag==="Left")return Gt("Left",e._1);if(e.tag==="Right")return Gt("Right",t(e._1));g()}},Pa={apply:t=>e=>{if(t.tag==="Left")return Gt("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Gt("Left",e._1);if(e.tag==="Right")return Gt("Right",t._1(e._1))}g()},Functor0:()=>E1},C1={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Gt("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}g()},Apply0:()=>Pa},S1={pure:k1,Apply0:()=>Pa},Ia={Applicative0:()=>S1,Bind1:()=>C1},G1=t=>t,P1={map:t=>e=>t(e)},Da={apply:t=>e=>t(e),Functor0:()=>P1},I1={bind:t=>e=>e(t),Apply0:()=>Da},D1={pure:G1,Apply0:()=>Da},Mn={Applicative0:()=>D1,Bind1:()=>I1},A1=function(t){return function(){return t}},B1={apply:t=>e=>()=>{const n=t(),r=e();return Nu.pure(n(r))()},Functor0:()=>F1},Nu={pure:A1,Apply0:()=>B1},F1={map:t=>e=>()=>{const n=e();return t(n)}},Zr=(t,e)=>({tag:t,_1:e}),Aa=t=>Zr("Loop",t),R1={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:()=>Mn},Q1=function(t){return function(e){return function(){return t(e())}}},z1=function(t){return function(){return t}},W1={map:Q1},M1={apply:t=>e=>()=>{const n=t(),r=e();return Ba.pure(n(r))()},Functor0:()=>W1},Ba={pure:z1,Apply0:()=>M1},H1=(function(t){return function(e){return function(n){return function(){return t(e,n)}}}})(function(t,e){return e.push(t)}),O1=(t,e)=>({tag:"Iterator",_1:t,_2:e}),q1=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}},$1=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()}},Kr=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=i-1;o>=0;o--)r=t(n[o])(r);return r}}},J=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=0;o<i;o++)r=t(r)(n[o]);return r}}},Ju=t=>{const e=t.Apply0();return n=>r=>n.foldr(i=>{const o=r(i);return u=>e.apply(e.Functor0().map(s=>Ea)(o))(u)})(t.pure())},Y1=t=>{const e=Ju(t);return n=>{const r=e(n);return i=>o=>r(o)(i)}},zt={foldr:Kr,foldl:J,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}),Hn=t=>e=>b(t,e),$i=t=>t._2,Yi=t=>t._1,At=function(t){return function(e){for(var n=e.length,r=Array(n),i=0;i<n;i++)r[i]=t(i)(e[i]);return r}};var Tu=function(t){return function(e){return t===e}};const X1=Tu,V1=Tu,ti=Tu,vu=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}}},gn={eq:ti},U1={eq:V1},xr={eq:X1};var wu=function(t){return function(e){return function(n){return function(r){return function(i){return r<i?t:r===i?e:n}}}}};const j1=wu,Z1=wu,P={compare:wu(ye)(Ge)(xe),Eq0:()=>gn},st={compare:Z1(ye)(Ge)(xe),Eq0:()=>U1},it={compare:j1(ye)(Ge)(xe),Eq0:()=>xr},K1=function(t){return t},td=(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)}}}}}})(),ed=t=>t,ir={traverse:t=>{const e=t.Apply0();return td(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>ir.traverse(t)(ed),Functor0:()=>b1,Foldable1:()=>zt},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 nd=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},rd=function(t,e){for(var n=[],r=0,i=0;i<t;i++)n[r++]=e;return n};const id=typeof Array.prototype.fill=="function"?nd:rd,kt=(function(){function t(i,o){this.head=i,this.tail=o}var e={};function n(i){return function(o){return new t(i,o)}}function r(i){for(var o=[],u=0,s=i;s!==e;)o[u++]=s.head,s=s.tail;return o}return function(i,o){return r(i(n)(e)(o))}})(),Bt=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},Fa=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},On=function(t,e,n,r){for(var i=0,o=r.length;i<o;i++)if(n(r[i]))return t(i);return e},Ra=function(t,e,n,r){for(var i=r.length-1;i>=0;i--)if(n(r[i]))return t(i);return e},Qa=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)},qn=function(t,e,n,r,i){if(n<0||n>=i.length)return e;var o=i.slice();return o[n]=r,t(o)},ke=function(t){return t.slice().reverse()},Fe=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)},od=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},ud=(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)},Je=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},Re=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},Wa=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Lt=t=>e=>ud(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),sd=t=>e=>Lt(n=>r=>t.compare(e(n))(e(r))),Ft=t=>e=>(()=>{const n=H1(e);return()=>{const r=[...t];return n(r)(),r}})()(),Xi=t=>{if(t.length===0)return t.length-1|0,T;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]}):T},Ma=t=>e=>n=>t>=0&&t<n.length?qn(Yt,T,t,e(n[t]),n):T,or=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=T}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()},Nr=t=>e=>{const n=Lt(r=>i=>t(r._2)(i._2))(At(Hn)(e));return 0<n.length?O($i)(sd(it)(Yi)((()=>{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})())):[]},ad=t=>e=>{const n=[],r=O1(i=>i>=0&&i<e.length?w("Just",e[i]):T,{value:0});return $1(r)(i=>()=>{const o=[];o.push(i),q1(t(i))(r)(o)(),n.push(o)})(),n},Xt=t=>e=>{const n=On(Yt,T,t,e);return n.tag==="Just"?w("Just",e[n._1]):T},Ha=t=>e=>at(t,e),Qe=t=>e=>n=>{const r=On(Yt,T,i=>t.eq(i)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},Oa=t=>e=>Tt(e)(t),xt=t=>Oa(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];g()}),qa=isFinite;function cd(t,e,n,r){var i=parseFloat(t);return e(i)?n(i):r}const $n=Math.abs,gd=Math.acos,ur=function(t){return function(e){return Math.atan2(t,e)}},Vi=Math.ceil,Ke=Math.cos,Ui=Math.exp,dn=Math.floor,$a=Math.log,fd=function(t){return function(e){return Math.min(t,e)}},bu=function(t){return function(e){return Math.pow(t,e)}},Yn=Math.round,Oe=Math.sin,Ee=Math.sqrt,_d=Math.tan,dd=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},rt=function(t){return t},ld=(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}}}})(Yt)(T)(10),Ya=dd(Yt)(T),de=t=>{if(!qa(t))return 0;if(t>=rt(2147483647))return 2147483647;if(t<=rt(-2147483648))return-2147483648;const e=Ya(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;g()},Ot=(t,e,n)=>({tag:t,_1:e,_2:n}),qt=Ot("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=Ot("Cons",d._1,f),s=d._2;continue}g()}return c})(qt);return i=>n(r(i))},foldl:t=>e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=t(s)(a._1),i=a._2;continue}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)}},hd=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)}}}}}}},pd=t=>{if(t.tag==="Just")return t._1;g()},md={unfoldr1:hd(Sa)(pd)(Yi)($i)},yd=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)}}}}}}},xd=t=>{if(t.tag==="Just")return t._1;g()},qe={unfoldr:yd(Sa)(xd)(Yi)($i),Unfoldable10:()=>md},Mt=(t,e,n,r,i,o,u)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u}),$e=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),ji=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),Xa=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),A=Mt("Leaf"),ln=$e("IterLeaf"),se=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return Mt("Node",1,1,t,e,n,r);if(r.tag==="Node")return Mt("Node",1+r._1|0,1+r._2|0,t,e,n,r);g()}if(n.tag==="Node"){if(r.tag==="Leaf")return Mt("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return Mt("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"?Mt("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()})()?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()},Jr=(t,e,n)=>{if(n.tag==="Leaf")return ji(T,A,A);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const i=Jr(t,e,n._5);return ji(i._1,i._2,ze(n._3,n._4,i._3,n._6))}if(r==="GT"){const i=Jr(t,e,n._6);return ji(i._1,ze(n._3,n._4,n._5,i._2),i._3)}if(r==="EQ")return ji(w("Just",n._4),n._5,n._6)}g()},Va=(t,e,n,r)=>{if(r.tag==="Leaf")return Xa(t,e,n);if(r.tag==="Node"){const i=Va(r._3,r._4,r._5,r._6);return Xa(i._1,i._2,ze(t,e,n,i._3))}g()},ei=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=Va(t._3,t._4,t._5,t._6);return ze(n._1,n._2,n._3,e)}g()},Cn=(t,e,n)=>{if(e.tag==="Leaf")return A;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=Jr(t,n._3,e);return ei(Cn(t,r._2,n._5),Cn(t,r._3,n._6))}g()},Zi=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return A;if(r.tag==="Node"){const i=Jr(t,r._3,n),o=Zi(t,e,i._2,r._5),u=Zi(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 ei(o,u)}g()},Ce=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const i=Jr(t,r._3,n),o=Ce(t,e,i._2,r._5),u=Ce(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()},Nd=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 ze(r._3,i._1,n(r._5),n(r._6));if(i.tag==="Nothing")return ei(n(r._5),n(r._6))}g()};return n},hn=(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=$e("IterEmit",h._3,h._4,_),f=h._5;continue}c=$e("IterEmit",h._3,h._4,$e("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=>T),vt=t=>e=>n=>r=>{const i=o=>{if(o.tag==="Leaf")return Mt("Node",1,1,n,r,A,A);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 Mt("Node",o._1,o._2,n,e(o._4)(r),o._5,o._6)}g()};return i},K=t=>e=>n=>{const r=i=>{if(i.tag==="Leaf")return Mt("Node",1,1,e,n,A,A);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 Mt("Node",i._1,i._2,e,n,i._5,i._6)}g()};return r},Kt=t=>e=>e.foldl(n=>r=>K(t)(r._1)(r._2)(n))(A),ni=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 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 ei(r._5,r._6)}g()};return n},Ua=t=>{const e=t.compare;return n=>r=>i=>{const o=Jr(e,r,i),u=n(o._1);if(u.tag==="Nothing")return ei(o._2,o._3);if(u.tag==="Just")return ze(r,u._1,o._2,o._3);g()}},oe=function(t){return function(e){return t+e|0}},Tr=function(t){return function(e){return t+e}},Xn=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},Jd=function(t){return function(e){return t+e}},te=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},Td={append:Jd},vd={append:te},wd={mempty:"",Semigroup0:()=>Td},bd={mempty:[],Semigroup0:()=>vd},Ld=null;function ja(t,e,n){return t==null?e:n(t)}function Tw(t){return t}function Lu(t){return function(e){return function(n){return t.apply(n,[e])}}}const kd=Lu(Number.prototype.toPrecision),Ed=Lu(Number.prototype.toFixed),Cd=Lu(Number.prototype.toExponential),ri=(t,e)=>({tag:t,_1:e}),ii=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()},oi=t=>{if(t.tag==="Precision")return kd(t._1);if(t.tag==="Fixed")return Ed(t._1);if(t.tag==="Exponential")return Cd(t._1);g()},Za=function(t){return function(){console.log(t)}};function Sd(){return Date.now()}function Gd(t){return function(){return t.getContext("2d")}}function Pd(t){return function(){return t.width}}function Id(t){return function(){return t.height}}function Dd(t){return function(e){return function(){t.width=e}}}function Ad(t){return function(e){return function(){t.height=e}}}function ku(t){return function(e){return function(){t.lineWidth=e}}}function Bd(t){return function(e){return function(){t.fillStyle=e}}}function Fd(t){return function(e){return function(){t.strokeStyle=e}}}function Eu(t){return function(e){return function(){t.lineCap=e}}}function Cu(t){return function(e){return function(){t.lineJoin=e}}}function Rd(t){return function(e){return function(){t.globalCompositeOperation=e}}}function Qd(t){return function(e){return function(){t.globalAlpha=e}}}function Ka(t){return function(){t.beginPath()}}function Su(t){return function(){t.stroke()}}function Gu(t){return function(){t.fill()}}function zd(t){return function(){t.clip()}}function ui(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function tc(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function ec(t){return function(){t.closePath()}}function Wd(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function Md(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function Ki(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function Pu(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function Hd(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function Od(t){return function(e){return function(){t.textAlign=e}}}function qd(t){return function(e){return function(){t.textBaseline=e}}}function $d(t){return function(e){return function(){t.font=e}}}function Yd(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function sr(t){return function(){t.save()}}function ar(t){return function(){t.restore()}}function si(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function Xd(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const nc=t=>t,Iu=t=>t,Du=t=>t,Au=t=>t,to=t=>t,Vd=to("BaselineTop"),Ud=to("BaselineMiddle"),jd=to("BaselineAlphabetic"),Zd=to("BaselineBottom"),Kd=Au("AlignLeft"),tl=Au("AlignRight"),el=Au("AlignCenter"),Bu=Du("BevelJoin"),eo=Du("RoundJoin"),Fu=Du("MiterJoin"),Ru=Iu("Round"),Qu=Iu("Square"),zu=Iu("Butt"),nl=nc("SourceOver"),rl=nc("Difference"),il=t=>e=>qd(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()})()),ol=t=>e=>Od(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()})()),no=t=>e=>{if(e==="BevelJoin")return Cu(t)("bevel");if(e==="RoundJoin")return Cu(t)("round");if(e==="MiterJoin")return Cu(t)("miter");g()},Wu=t=>e=>{if(e==="Round")return Eu(t)("round");if(e==="Square")return Eu(t)("square");if(e==="Butt")return Eu(t)("butt");g()},rc=t=>e=>Rd(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()})()),We={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,Ot("Cons",o._3,i(o._6,u)));g()};return i(r,qt)})())}},ul=t=>{const e={append:(()=>{const n=t.compare;return r=>i=>Ce(n,Le,r,i)})()};return{mempty:A,Semigroup0:()=>e}},ai=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},cr=function(t){return t.join("")},Vn=function(t){return t.split("")},ro=function(t){return t},Un=function(t){return t.length},ic=function(t){return function(e){return e.substr(0,t)}},ci=function(t){return function(e){return e.substring(t)}},sl=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},al=t=>e=>{const n=sl(Un(t))(e);return n.before===t?w("Just",n.after):T},cl=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},gl=function(t){return t()},fl=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},_l=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},gr=t=>BigInt(t),dl=t=>Number(t),io=t=>e=>t+e,oo=t=>e=>t*e,Mu=t=>e=>t-e,oc=0n,uo=1n,uc=t=>e=>t^e,gi=t=>e=>t&e,Hu=t=>e=>t<<e,Ou=t=>e=>t>>e,ll=t=>e=>t==e,hl=t=>e=>t===e?0:t>e?1:-1,pl={eq:ll},sc={compare:t=>e=>{const n=hl(t)(e);return n===1?xe:n===0?Ge:ye},Eq0:()=>pl},ml=fl(Yt)(T),yl=_l(Yt)(T),ac=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=st.compare(e._1)(n._1);return r==="LT"?ye:r==="GT"?xe:st.compare(e._2)(n._2)},Eq0:()=>t}})(),xl=t=>e=>$n(t._1-e._1)+$n(t._2-e._2),fr=t=>t,so=t=>t,le=so("North"),he=so("South"),pn=so("East"),_r=so("West"),jn=fr("Rectangle"),Nl=fr("Cylinder"),Jl=fr("Parallelogram"),Tl=fr("Diamond"),vl=fr("Ellipse"),wl=fr("Document"),bl=fr("Cloud"),cc=t=>t,gc=J(Tr)(0),Ll=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},mn=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fi=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},fc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},vr=t=>e=>{const n=Je(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,c=s.x-u.x;return Ee(c*c+a*a)})()}),t,bt(1,t.length,t)),r=gc(O(u=>u.len)(n)),i=Ll(0)(r)(e*r),o=u=>s=>a=>{let c=u,f=s,d=a,l=!0,_;for(;l;){const h=c,m=f,p=d,y=Bt(x=>T,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,_=p;continue}if(y.tag==="Just"){if(m<=y._1.head.len){const x=y._1.head.len<=0?0:m/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=m-y._1.head.len,d=p;continue}g()}return _};return 0<t.length?w("Just",o(n)(i)(t[0])):T},kl=t=>e=>{const n=mn(1)(t.w),r=mn(1)(t.h),i=mn(1)(e.w-8),o=mn(1)(e.h-8),u=fi(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}},_i=t=>gc(Je(e=>n=>{const r=n.y-e.y,i=n.x-e.x;return Ee(i*i+r*r)},t,bt(1,t.length,t))),El=t=>e=>n=>r=>i=>{const o=0<t.length?w("Just",t[0]):T,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]):T,c=(()=>{if(a.tag==="Nothing")return n;if(a.tag==="Just")return a._1;g()})(),f=mn(.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,m=2*(()=>{const v=u.y-e.y;return(h<0?-h:h)+(v<0?-v:v)})(),p=m+_i(t)+_,y=p<=1e-4?1:1-_/p,x=p<=1e-4?0:m/p;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=vr(t)((d-x)/mn(1e-4)(y-x));if(N.tag==="Nothing")return u;if(N.tag==="Just")return N._1;g()},Cl=t=>{const e=Bt(n=>T,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,Ot("Cons",r._4,n(r._6,i)));g()};return Tt(kt($t.foldr,n(t.nodes,qt)))(r=>[{x:r.x,y:r.y},{x:r.x+r.w,y:r.y+r.h}])})());if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:fi(r.minX)(i.x),minY:fi(r.minY)(i.y),maxX:mn(r.maxX)(i.x),maxY:mn(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()},qu={scale:1,tx:0,ty:0},Ye=t=>{const e=Bt(n=>T,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,Ot("Cons",r._4,n(r._6,i)));g()};return Tt(kt($t.foldr,n(t.nodes,qt)))(r=>[{x:r.x,y:r.y},{x:r.x+r.w,y:r.y+r.h}])})(),...Fe((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._4,n(r._6,i)));g()};return kt($t.foldr,n(t.edges,qt))})()),...Fe((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._4,n(r._6,i)));g()};return kt($t.foldr,n(t.chipExtras,qt))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:fi(r.minX)(i.x),minY:fi(r.minY)(i.y),maxX:mn(r.maxX)(i.x),maxY:mn(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()},Sl=t=>e=>(n=>r=>i=>{let o=n,u=r,s=i,a=!0,c;for(;a;){const f=o,d=u,l=s,_=Bt(h=>T,h=>m=>w("Just",{head:h,tail:m}),d);if(_.tag==="Nothing"){a=!1,c=l;continue}if(_.tag==="Just"){const h=fc(_._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 m=kl(Ye(h._1.layout))((()=>{const p=fc(_._1.head)(f.layout.nodes);if(p.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:jn};if(p.tag==="Just")return p._1;g()})());return{scale:l.scale*m.scale,tx:l.scale*m.tx+l.tx,ty:l.scale*m.ty+l.ty}})();continue}}g()}return c})(t)(e)(qu),_c=t=>t,dc=(t,e)=>({tag:t,_1:e}),ao=(t,e)=>({tag:t,_1:e}),$u=(t,e)=>({tag:t,_1:e}),Gl=$u("First"),Pl=_c("Forward"),Il=_c("Backward"),Dl=ao("ExitNode"),lc=Kt(P)(zt),Al=t=>Kr(e=>n=>({nodes:Ce(P.compare,Le,e.nodes,n.nodes),edges:Ce(P.compare,Le,e.edges,n.edges)}))({nodes:A,edges:A})(t.keyframes),Bl=t=>e=>({entering:{nodes:Cn(P.compare,e.nodes,t.nodes),edges:Cn(P.compare,e.edges,t.edges)},leaving:{nodes:Cn(P.compare,t.nodes,e.nodes),edges:Cn(P.compare,t.edges,e.edges)},surviving:{nodes:Zi(P.compare,Le,t.nodes,e.nodes),edges:Zi(P.compare,Le,t.edges,e.edges)}}),co=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},wr=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},di=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Yu=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=P.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},Fl=J(t=>e=>K(P)(e)()(t))(A),Rl=J(t=>e=>K(P)(e)()(t))(A),Ql=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),hc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},pc=Kt(P)(zt),li=t=>{const e=Bt(n=>T,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=J(r=>i=>({minX:co(r.minX)(i.x),minY:co(r.minY)(i.y),maxX:wr(r.maxX)(i.x),maxY:wr(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()},zl=t=>{const e=Bt(n=>T,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return T;if(e.tag==="Just")return w("Just",li(t));g()},Wl=t=>e=>n=>Fl(Tt(kt(We.foldr,n))(r=>{const i=di(r)(t);if(i.tag==="Just")return at(o=>!Yu(o)(e),[i._1.source,i._1.target]);if(i.tag==="Nothing")return[];g()})),Ml=t=>t.kind.tag==="SendToken"?w("Just",b(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):T,Hl=t=>t.tag==="DataFlow"?xt(Ml)(t._1.events):[],Ol=t=>e=>Rl(xt(n=>Yu(n._2.source)(e)||Yu(n._2.target)(e)?w("Just",n._1):T)(Ql(t))),ql=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",li([t[0]])):w("Just",li([t[0],t[e]])):T:0<t.length?w("Just",li([t[0]])):T},go=t=>{const e=Bt(n=>T,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=J(r=>i=>({minX:co(r.minX)(i.x),minY:co(r.minY)(i.y),maxX:wr(r.maxX)(i.x+i.w),maxY:wr(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()},mc=t=>e=>n=>{if(n.tag==="Leaf")return Ye(t);const r=Ol(e)(n),i=[...xt(o=>{const u=hc(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}):T})(kt(We.foldr,Ce(P.compare,Le,n,Wl(e)(n)(r)))),...xt(o=>{const u=di(o)(t.edges);return u.tag==="Just"?w("Just",li(u._1)):T})(kt(We.foldr,r)),...xt(o=>{const u=di(o)(t.chipExtras);if(u.tag==="Just")return zl(u._1);if(u.tag==="Nothing")return T;g()})(kt(We.foldr,r))];return i.length===0?Ye(t):go(i)},hi=t=>e=>n=>{const r=[...xt(i=>i)([(()=>{const i=di(n)(t.chipExtras);if(i.tag==="Just")return ql(i._1);if(i.tag==="Nothing")return T;g()})()]),...(()=>{const i=di(n)(e);if(i.tag==="Just")return xt(o=>{const u=hc(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}):T})([i._1.source,i._1.target]);if(i.tag==="Nothing")return[];g()})()];return r.length===0?mc(t)(e)(A):go(r)},Xu=t=>e=>{const n=Ye(t),r=n.w/wr(1e-4)(e.zoom),i=n.h/wr(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-i/2,w:r,h:i}},$l=t=>Ce(P.compare,Le,pc(O(e=>b(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),pc(Tt(t.scenes)(Hl))),Vu=t=>t,Yl=t=>t,dr=Vu("Linear"),Xl=Vu("EaseInOutQuad"),Vl=Vu("SpringBouncy"),pi=t=>e=>n=>{const r=Ee(1-e*e),i=t*r;return 1-Ui(-e*t*n)*(Ke(i*n)+e/r*Oe(i*n))},Ul=t=>{const e=st.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=st.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Uu=t=>e=>(()=>{if(t==="Linear")return Yl;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)*Ui(-6*n);if(t==="SpringBouncy")return pi(6)(.7);g()})()(Ul(e)),yc=t=>t,ju=t=>t,fo=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},mi=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},xc=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},jl=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Zl=ju("Hold"),Kl=ju("Gap"),th=ju("Move"),yi=yc("LinearLerp"),Nc=yc("LogLerp"),eh=t=>e=>n=>{const r=n.center.y-e.center.y,i=n.center.x-e.center.x,o=Ee(i*i+r*r),u=n.zoom-e.zoom,s=u<0?-u:u;return fo(t.minTransition)(t.maxTransition)(mi(t.panSpeed<=0?t.minTransition:o/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:s/t.zoomSpeed))},nh=J(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:Ft(t)(e)})([]),Jc=t=>e=>{const n={x:0,y:0},r=0<t.length?t[0].pos:n,i=Ra(Yt,T,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=fo(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()},Zu=t=>e=>({center:{x:e.center.x*t.scale+t.tx,y:e.center.y*t.scale+t.ty},zoom:e.zoom/mi(1e-6)(t.scale)}),rh=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:Ui((()=>{const r=$a(mi(1e-6)(t.zoom));return r+($a(mi(1e-6)(e.zoom))-r)*n})())}),ih=t=>e=>n=>{const r=Uu(n.easing)(fo(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 rh(n.fromCam)(n.toCam)(r);g()},oh=t=>e=>n=>r=>{const i=(u,s)=>xc(eh(t)(u.toCam)(s.toCam))(u.endT-u.startT),o=J(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:Ft(u.acc)(u.pending._1),pending:w("Just",s)}:{acc:Ft(Ft(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:yi}),pending:w("Just",s)};g()})({acc:[],pending:T})(r);if(o.pending.tag==="Nothing")return o.acc;if(o.pending.tag==="Just")return Ft(o.acc)(o.pending._1);g()},uh=t=>e=>{const n=r=>{const i=Ra(Yt,T,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):T;if(i.tag==="Nothing")return T;g()};return At(r=>i=>{if(i.kind==="Hold")return{startT:i.startT,endT:i.endT,fromCam:i.fromCam,toCam:i.toCam,easing:i.easing,interp:yi};if(i.kind==="Move")return{startT:i.startT,endT:i.endT,fromCam:i.fromCam,toCam:i.toCam,easing:dr,interp:yi};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=On(Yt,T,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:yi};g()})(e)},sh={padding:24,easing:dr,minZoom:.9,maxZoom:2.5,tokenZoomFloor:0,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:16},Ku=t=>e=>n=>{const r=e.w+n*2,i=e.h+n*2,o=Ye(t);return r<=0||i<=0||o.w<=0||o.h<=0?1:xc(o.w/r)(o.h/i)},ah=J(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?w("Just",t[n]):T;return r.tag==="Just"&&r._1.fromCam.zoom===r._1.toCam.zoom&&r._1.fromCam.center.x===r._1.toCam.center.x&&r._1.fromCam.center.y===r._1.toCam.center.y&&e.fromCam.zoom===e.toCam.zoom&&e.fromCam.center.x===e.toCam.center.x&&e.fromCam.center.y===e.toCam.center.y&&(()=>{const i=r._1.toCam.center.x-e.toCam.center.x;return(i<0?-i<8:i<8)&&(()=>{const o=r._1.toCam.center.y-e.toCam.center.y;return(o<0?-o<8:o<8)&&(()=>{const u=r._1.toCam.zoom-e.toCam.zoom;return u<0?-u<.08:u<.08})()})()})()?Ft((()=>{const i=t.length-1|0;return i<1?[]:bt(0,i,t)})())({...r._1,endT:e.endT}):Ft(t)(e)})([]),xi=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:mi(r)(fo(t.minZoom)(t.maxZoom)(Ku(e)(n)(t.padding)))}),ch=t=>e=>n=>r=>{const i=Lt(s=>a=>it.compare(a.priority)(s.priority)),o=xi(t)(e)(Ye(e))(0),u=at(s=>s>=0&&s<=n,nh(Lt(st.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 O(a=>a.t)(s.pathFollow._1.samples);g()})])));return oh(t)(e)(o)(ah(uh(o)(xt(s=>{const a=(s._1+s._2)/2;if(s._2<=s._1)return T;const c=xt(d=>d.pathFollow)(i(at(d=>d.startT<=a&&a<d.endT,r)));if(0<c.length)return w("Just",{kind:th,startT:s._1,endT:s._2,fromCam:{center:Jc(c[0].samples)(s._1),zoom:c[0].zoom},toCam:{center:Jc(c[0].samples)(s._2),zoom:c[0].zoom},easing:dr});const f=O(d=>d.bbox)(at(d=>d.priority===J(jl)(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:Kl,startT:s._1,endT:s._2,fromCam:o,toCam:o,easing:t.easing}):w("Just",{kind:Zl,startT:s._1,endT:s._2,fromCam:xi(t)(e)(go(f))(Re(d=>d.priority>=1,at(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),toCam:xi(t)(e)(go(f))(Re(d=>d.priority>=1,at(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),easing:t.easing})})(Je(Hn,u,bt(1,u.length,u))))))},Tc=t=>e=>n=>r=>{const i=Xt(o=>r>=o.startT&&r<o.endT)(n);if(i.tag==="Just")return ih()(r)(i._1);if(i.tag==="Nothing"){const o=n.length-1|0;if(o>=0&&o<n.length&&r>=n[o].endT)return n[o].toCam;const u=xi(t)(e)(Ye(e))(0);return 0<n.length?n[0].fromCam:u}g()},_o=t=>e=>{const n=Xt(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==="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==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return"";g()}return""}g()},gh=t=>e=>{if(e==="")return T;const n=Xt(r=>{if(r.scene.tag==="Structural")return r.scene._1.to===e;if(r.scene.tag==="DataFlow")return r.scene._1.keyframe===e;if(r.scene.tag==="EnterNode"||r.scene.tag==="ExitNode")return e==="";g()})(t.spans);if(n.tag==="Just")return w("Just",n._1.startT);if(n.tag==="Nothing")return T;g()};function Sn(t){return t.charCodeAt(0)}function vc(t){return String.fromCharCode(t)}const Zn=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},lo=function(t){return function(e){return e.split(t)}},fh=function(t){return t.trim()},ho=function(t){return function(e){return e.join(t)}};var _h=typeof Array.from=="function",dh=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",lh=typeof String.prototype.fromCodePoint=="function",hh=typeof String.prototype.codePointAt=="function";const ph=function(t){return hh?function(e){return e.codePointAt(0)}:t},mh=function(t){return lh?String.fromCodePoint:t},yh=function(t){return function(e){return dh?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)}},xh=function(t){return function(e){return _h?function(n){return Array.from(n,e)}:t}},po=t=>{const e=Un(t);if(e===0)return T;if(e===1)return w("Just",{head:Sn(ai(0)(t)),tail:""});const n=Sn(ai(1)(t)),r=Sn(ai(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:ci(2)(t)}):w("Just",{head:r,tail:ci(1)(t)})},Nh=t=>{const e=po(t);return e.tag==="Just"?w("Just",b(e._1.head,e._1.tail)):T},Jh=t=>qe.unfoldr(Nh)(t),wc=ph(t=>{const e=Sn(ai(0)(t));if(55296<=e&&e<=56319&&Un(t)>1){const n=Sn(ai(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),mo=xh(Jh)(wc),ts=t=>ro(t>=0&&t<=65535?vc(t):t<0?"\0":"\uFFFF"),Th=mh(t=>t<=65535?ts(t):ts(En(t-65536|0,1024)+55296|0)+ts(Xn(t-65536|0)(1024)+56320|0)),bc=t=>e=>{if(t<1)return"";const n=po(e);return n.tag==="Just"?Th(n._1.head)+bc(t-1|0)(n._1.tail):e},me=yh(bc),vh=t=>e=>e===""?T:w("Just",wc(e)),br=(t,e,n)=>({tag:t,_1:e,_2:n}),wh=()=>({tag:"ExtendFromSource"}),Lr=(t,e)=>({tag:t,_1:e}),es=t=>t,yo=(t,e)=>({tag:t,_1:e}),ns=yo("NotYet"),Lc=yo("Consumed"),bh=es("FromSource"),kc=es("FromTarget"),Ec=es("FromBoth"),xo=Lr("Hidden"),Lh=Lr("Visible"),rs=wh(),No=br("Retracted"),kh=br("Extended"),Cc=t=>t,is=(t,e)=>({tag:t,_1:e}),kr=(t,e,n)=>({tag:t,_1:e,_2:n}),Sc=t=>t,lr=(t,e)=>({tag:t,_1:e}),Er=(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}),Ni=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Gc=Kt(P)(zt),os=vu(ti),Ji=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Jo=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ti=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Pc=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=P.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},Ic=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Cr=(()=>{const t=qe.unfoldr(e=>{if(e.tag==="Nil")return T;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,Ot("Cons",r._3,n(r._6,i)));g()};return n(e,qt)})())})(),Eh=J(t=>e=>K(P)(e)()(t))(A),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=P.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},ss=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=P.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},Ch=lr("NoKeyframes"),Sh=t=>lr("DuplicateEventId",t),Gh=t=>lr("UnknownEvent",t),Dc=Sc("PlopIn"),Ph=Sc("PlopOut"),Ih=Cc("DiveIn"),Dh=Cc("DiveOut"),Ah=t=>e=>n=>r=>{const i=Ni(r.edge)(e.edges),o=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return _i(i._1);g()})(),u=yn(t.minTokenDuration)(yn(rt(J(s=>a=>s+mo(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}},Bh=t=>e=>Gc(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 Re(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 Re(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 T;g()})(e)),Fh=t=>{if(t.event.kind.tag==="SendToken")return w("Just",{startT:t.startT,endT:t.endT,target:Er("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:Er("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},Rh=t=>e=>n=>r=>{const i=Xt(o=>os(o.path)(e)&&($n(o.endT-n)<1e-4||$n(o.startT-r)<1e-4))(t.segments);if(i.tag==="Just")return w("Just",i._1);if(i.tag==="Nothing")return Xt(o=>os(o.path)(e))(t.segments);g()},Qh=t=>e=>n=>xt(r=>{const i=xt(o=>Ti(o)(t.nodes))(kt(We.foldr,(()=>{if(r.scene.tag==="Structural")return Ce(P.compare,Le,(()=>{const o=Ji(r.scene._1.from)(n);if(o.tag==="Nothing")return A;if(o.tag==="Just")return o._1.nodes;g()})(),(()=>{const o=Ji(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=Ji(r.scene._1.keyframe)(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?T:w("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const o=J(u=>s=>({minX:Jo(u.minX)(s.x),minY:Jo(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:T})}),zh=t=>e=>n=>{const r=Ni(n)(t);if(r.tag==="Nothing")return kc;if(r.tag==="Just"){const i=Pc(r._1.target)(e);return Pc(r._1.source)(e)?i?Ec:bh:kc}g()},Wh={pre:0,post:0},Mh=t=>e=>n=>r=>i=>{const o=Ic(i.event.id)(n),u=(()=>{if(o.tag==="Nothing")return Wh;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=Xt(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=Xt(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 Ah(t)(e)(u)(i.event.kind._1);if(i.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return Ft(r)({startT:s,endT:s+a.duration,event:i.event,holdPre:a.holdPre,holdPost:a.holdPost})},Ac=t=>e=>n=>J(Mh(t)(e)(Bh(t)(n)))([])(At(r=>i=>({event:i}))(n)),Hh=t=>e=>{const n=Ti(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},Oh=t=>e=>({...e,fromCam:Zu(t)(e.fromCam),toCam:Zu(t)(e.toCam)}),qh=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()},Bc={id:"",nodes:A,edges:A},$h=t=>e=>Bl((()=>{const n=Ji(e.from)(t);if(n.tag==="Nothing")return Bc;if(n.tag==="Just")return n._1;g()})())((()=>{const n=Ji(e.to)(t);if(n.tag==="Nothing")return Bc;if(n.tag==="Just")return n._1;g()})()),Yh=t=>e=>{const n=Ti(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:A};if(n.tag==="Just")return n._1;g()},as=t=>e=>n=>r=>{const i=Ni(r)(n.edges);if(i.tag==="Just")return t<=0?e:yn(e)(_i(i._1)/t);if(i.tag==="Nothing")return e;g()},Fc=t=>e=>n=>r=>i=>{const o=t.plop,u=$h(n)(i),s=O(_=>({startT:0,endT:0+as(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Er("EdgeWindow",_,is("Extend",rs))}))(Cr(u.entering.edges)),a=O(_=>({startT:0,endT:o,target:Er("NodeWindow",_,Dc)}))(Cr(u.entering.nodes)),c=J(yn)(0)(O(_=>as(t.edgeSpeed)(t.minEdgeDuration)(e)(_))(Cr(u.leaving.edges))),f=_=>Re(h=>{const m=Ni(h)(r);if(m.tag==="Just")return m._1.source===_||m._1.target===_;if(m.tag==="Nothing")return!1;g()},Cr(u.leaving.edges))?c:0,d=O(_=>({startT:f(_),endT:f(_)+t.plop,target:Er("NodeWindow",_,Ph)}))(Cr(u.leaving.nodes)),l=O(_=>({startT:0,endT:as(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Er("EdgeWindow",_,is("Retract",zh(r)(u.leaving.nodes)(_)))}))(Cr(u.leaving.edges));return{duration:(()=>{const _=Lt(st.compare)([...O(m=>m.endT)(l),...O(m=>m.endT)(d),...O(m=>m.endT)(a),...O(m=>m.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+t.gap:t.gap})(),windows:[...l,...d,...a,...s]}},Xh=t=>e=>n=>r=>i=>o=>O((()=>{const u=i.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())(Fc(t)(e)(n)(r)(o).windows),Vh=t=>xt(e=>kt(Kr,e).length>1?w("Just",(()=>{const n=Bt(r=>T,r=>i=>w("Just",{head:r,tail:i}),kt(Kr,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):T)(ad(ti)(Lt(P.compare)(t))),Uh=t=>{const e=O(r=>r.id)(t),n=Eh(e);return[...O(Sh)(Vh(e)),...O(Gh)(at(r=>!us(r)(n),Tt(t)(qh)))]},jh=t=>e=>n=>{const r=yn(t.minZoom)(t.tokenZoomFloor);return xt(i=>{if(i.target.tag==="NodeWindow"||i.target.tag==="EdgeWindow")return T;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:hi(e)(n)(i.target._2),priority:1,pathFollow:T};const u=Ni(i.target._2)(e.edges);if(u.tag==="Just"){const s=Ti(i.target._4)(e.nodes);if(s.tag==="Just"){const a=Ti(i.target._5)(e.nodes);if(a.tag==="Just"){const c=a._1;return{startT:i.startT,endT:i.endT,bbox:hi(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 O(_=>{const h=f+rt(_)/rt(32)*d;return{t:h,pos:El(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:hi(e)(n)(i.target._2),priority:1,pathFollow:T};g()}if(s.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:hi(e)(n)(i.target._2),priority:1,pathFollow:T};g()}if(u.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:hi(e)(n)(i.target._2),priority:1,pathFollow:T};g()})());if(i.target.tag==="FillWindow")return w("Just",{startT:i.startT,endT:i.endT,bbox:mc(e)(n)(Mt("Node",1,1,i.target._2,void 0,A,A)),priority:1,pathFollow:T});g()})},Zh=t=>e=>n=>r=>i=>ch(t)(i.layout)(r.endT)([...Qh(i.layout)(n)(e)(at(o=>o.startT>=i.startT&&o.endT<=i.endT,r.spans)),...jh(t)(i.layout)(n)(i.windows)]),Kh=t=>{const e=Gc(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(us(o)(i))return[lr("ScheduleCycle",[...kt(We.foldr,i),o])];if(us(o)(r))return[];const u=Ic(o)(e);if(u.tag==="Nothing")return[];if(u.tag==="Just")return Tt(u._1)(n(K(P)(o)()(r))(K(P)(o)()(i)));g()};return Tt(t)(r=>n(A)(A)(r.id))},t0={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:.5,hatchHold:.4,tokenReadSecPerChar:.06,nodeEasing:Vl,edgeEasing:Xl,tokenEasing:dr,diveDur:1.2,retreatDur:1.2},e0=t=>e=>n=>r=>O((()=>{const i=n.startT;return o=>({...o,startT:o.startT+i,endT:o.endT+i})})())(xt(Fh)(Ac(t)(e)(r.events))),n0=t=>e=>n=>r=>i=>{if(i.scene.tag==="Structural")return Xh(t)(e)(n)(r)(i)(i.scene._1);if(i.scene.tag==="DataFlow")return e0(t)(e)(i)(i.scene._1);if(i.scene.tag==="EnterNode")return[];if(i.scene.tag==="ExitNode")return[];g()},r0=t=>e=>n=>{const r=Ac(t)(e)(n.events);return r.length===0?t.gap:J(yn)(0)(O(i=>i.endT)(r))+t.gap},i0=t=>e=>n=>r=>i=>{if(i.tag==="Structural")return Fc(t)(e)(n)(r)(i._1).duration;if(i.tag==="DataFlow")return r0(t)(e)(i._1);if(i.tag==="EnterNode"||i.tag==="ExitNode")return 0;g()},Rc=t=>e=>n=>r=>i=>o=>{const u=Sl(e)(r),s=n.layout,a=lc(O(m=>b(m.id,m))(i.keyframes)),c=0<i.keyframes.length?w("Just",i.keyframes[0]):T,f=(()=>{if(c.tag==="Just")return c._1.id;if(c.tag==="Nothing")return"";g()})(),d=$l(i),l=m=>({segments:m.runSpans.length===0?m.segments:Ft(m.segments)({startT:m.runStart,endT:m.t,path:r,layout:s,placement:u,windows:m.runWindows,spans:m.runSpans,keyframes:a,initialKeyframe:f,edgeEndpoints:d}),spans:m.spans,windows:m.windows,dives:m.dives}),_=J(m=>p=>{if(p.tag==="EnterNode"){const v=l(m),L=m.t+t.diveDur,k=Ft(r)(p._1),E=Rc(t)(e)(Yh(n)(p._1))(k)(Hh(i)(p._1))(L),Q=E.endT+t.retreatDur;return{...m,t:Q,runStart:Q,runSpans:[],runWindows:[],segments:[...v.segments,...E.segments],spans:[...v.spans,...E.spans],windows:[...v.windows,...E.windows],dives:[...v.dives,{startT:m.t,endT:L,node:p._1,parentPath:r,childPath:k,direction:Ih},...E.dives,{startT:E.endT,endT:Q,node:p._1,parentPath:r,childPath:k,direction:Dh}]}}if(p.tag==="ExitNode")return m;const y=m.t+i0(t)(s)(a)(d)(p),x={startT:m.t,endT:y,scene:p},N=n0(t)(s)(a)(d)(x);return{...m,t:y,runSpans:Ft(m.runSpans)(x),runWindows:[...m.runWindows,...N],spans:Ft(m.spans)(x),windows:[...m.windows,...N]}})({t:o,runStart:o,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(i.scenes),h=l(_);return{endT:_.t,spans:h.spans,windows:Lt(m=>p=>st.compare(m.startT)(p.startT))(h.windows),segments:h.segments,dives:h.dives}},o0=t=>e=>n=>n.endT<=t||n.startT>=e?T:w("Just",{...n,startT:yn(t)(n.startT),endT:Jo(e)(n.endT)}),cs=t=>e=>n=>{const r=Ye(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:Jo(Ku(e)(i)(t.padding*n.placement.scale))(40/(11*n.placement.scale))}},u0=t=>e=>n=>n.placement.scale===1&&n.placement.tx===0&&n.placement.ty===0?Zu(n.placement)(xi(t)(n.layout)(Ye(n.layout))(0)):cs(t)(e)(n),s0=t=>e=>n=>r=>xt(i=>{const o=Rh(r)(i.parentPath)(i.startT)(i.endT);if(o.tag==="Just"){const u=i.childPath,s=Xt(a=>os(a.path)(u))(r.segments);if(s.tag==="Just"){const a=u0(t)(e)(o._1),c=cs(t)(e)(s._1);if(i.direction==="DiveIn")return w("Just",{startT:i.startT,endT:i.endT,fromCam:a,toCam:c,easing:dr,interp:Nc});if(i.direction==="DiveOut")return w("Just",{startT:i.startT,endT:i.endT,fromCam:c,toCam:a,easing:dr,interp:Nc});g()}if(s.tag==="Nothing")return T;g()}if(o.tag==="Nothing")return T;g()})(r.dives),a0=t=>e=>{if(e.tag==="Structural")return xt(n=>n)([ss(e._1.from)(t)?T:w("Just",lr("UnknownKeyframe",e._1.from)),ss(e._1.to)(t)?T:w("Just",lr("UnknownKeyframe",e._1.to))]);if(e.tag==="DataFlow")return[...xt(n=>n)([ss(e._1.keyframe)(t)?T:w("Just",lr("UnknownKeyframe",e._1.keyframe))]),...Uh(e._1.events),...Kh(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()},c0=t=>e=>{const n=Tt(e)(a0(t));return n.length===0?Gt("Right",void 0):Gt("Left",n)},g0=t=>e=>n=>r=>Lt(i=>o=>st.compare(i.startT)(o.startT))(Tt(r.segments)(i=>i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0?xt(o0(i.startT)(i.endT))(O(Oh(i.placement))(Zh(t)(n)(i.edgeEndpoints)(r)(i))):[(()=>{const o=cs(t)(e)(i);return{startT:i.startT,endT:i.endT,fromCam:o,toCam:o,easing:dr,interp:yi}})()])),f0=t=>e=>n=>r=>{if(0<n.keyframes.length){const i=n.keyframes[0],o=lc(O(s=>b(s.id,s))(n.keyframes)),u=c0(o)(n.scenes);return(()=>{if(u.tag==="Left"){const s=u._1;return a=>Gt("Left",s)}if(u.tag==="Right"){const s=u._1;return a=>a(s)}g()})()(()=>{const s=Rc(e)(r)(r)([])(n)(0);return Gt("Right",{totalDuration:s.endT,windows:s.windows,spans:s.spans,keyframes:o,initialKeyframe:i.id,timing:e,layout:r.layout,cameraSpans:[...g0(t)(r.layout)(o)(s),...s0(t)(r.layout)(o)(s)],cameraConfig:t,levelTree:r,segments:s.segments,dives:s.dives,seed:n.seed})})}return Gt("Left",[Ch])},gs=t=>e=>Math.imul(t,e),Sr=t=>{const e=t+1831565813|0,n=gs(e^e>>>15)(e|1),r=n^(n+gs(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=Sr(n);return{prng:r.prng,value:t+r.value*(e-t)}},fs=t=>e=>J(n=>r=>gs(n^r)(-2048144789))(e)(O(Sn)(Vn(t))),_s=t=>t,tn=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},To=vu(ti),_0=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),Qc=Kt(P)(zt),zc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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=zt.foldMap(ul(P)),Mc=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},d0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Gr=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},l0=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=P.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},h0=Kt(P)(zt),p0=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=P.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},m0=Kt(P)(zt),y0=_s("Backdrop"),Hc=_s("FlyThrough"),vo=_s("Active"),Oc=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*Ui(-(c-a)/s))},x0=t=>e=>n=>r=>{const i=Ye(t),o=i.w/tn(1e-4)(e.zoom)/2,u=i.h/tn(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}}},ds=t=>e=>n=>{const r=Xt(i=>To(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 Xt(i=>To(i.path)(e))(t.segments);g()},N0=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:qu,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:A}),J0=t=>O(e=>e<1?[]:bt(0,e,t))(Dt(0,t.length-1|0)),T0=t=>J(e=>n=>(e*31|0)+Sn(n)|0)(7)(Vn(t)),qc=t=>e=>n=>({...n,state:{...n.state,nodes:Qc(O(r=>b(r._1,t(r._1)(r._2)))(_0(n.state.nodes))),edges:(()=>{const r=i=>{if(i.tag==="Leaf")return A;if(i.tag==="Node")return Mt("Node",i._1,i._2,i._3,e(i._4),r(i._5),r(i._6));g()};return r(n.state.edges)})()}}),ls=t=>e=>{const n=zc(e)(t.keyframes);if(n.tag==="Nothing")return A;if(n.tag==="Just")return n._1.nodes;g()},hs=t=>e=>{const n=zc(e)(t.keyframes);if(n.tag==="Nothing")return A;if(n.tag==="Just")return n._1.edges;g()},ps=t=>e=>{if(e<t.startT)return kr("AtKeyframe",t.initialKeyframe);const n=Xt(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return kr("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return kr("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return kr("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;return r>=0&&r<t.spans.length?kr("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==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return t.initialKeyframe;g()})()):kr("AtKeyframe",t.initialKeyframe)}g()},v0=J(t=>e=>{const n=Xi(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?Ft(n._1.init)({...n._1.last,endT:tn(n._1.last.endT)(e.endT),windows:Ft(n._1.last.windows)(e)}):Ft(t)({endT:e.endT,windows:[e]})})([]),w0=t=>e=>n=>Wc(r=>Wc(i=>i.target.tag==="FillWindow"?i.startT<=n?Mt("Node",1,1,i.target._2,void 0,A,A):A:i.target.tag==="TokenWindow"&&i.startT+(i.endT-i.startT)*.25<=n?Mt("Node",1,1,i.target._4,void 0,A,A):A)(r.windows))(at(r=>n<=r.endT+t,v0(Lt(r=>i=>st.compare(r.startT)(i.startT))(at(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),b0=t=>e=>n=>Re(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),L0=t=>e=>n=>Re(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),k0=t=>e=>n=>Re(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),E0=t=>e=>n=>Re(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),C0=t=>e=>{const n=ps(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()},$c=t=>e=>n=>Xt(r=>n(r)&&e>=r.startT&&e<r.endT)(t),S0=t=>{const e=Mc(0)(1)(t/.2),n=Mc(0)(1)((1-t)/.2);return e*e*(3-2*e)*n*n*(3-2*n)},G0=t=>e=>{if(e.tag==="Travelling"){const n=d0(e._1.edge)(t.edges);if(n.tag==="Just"){const r=vr(n._1)(e._1.progress);return r.tag==="Just"?w("Just",{dot:r._1,weight:S0(e._1.progress)}):T}if(n.tag==="Nothing")return T;g()}return T},P0={segment:{startT:0,endT:0,path:[],layout:{nodes:A,edges:A,chipExtras:A},placement:qu,windows:[],spans:[],keyframes:A,initialKeyframe:"",edgeEndpoints:A},state:{nodes:A,edges:A,tokens:A,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",visited:A,nodeFadeAlpha:A,nodeInvert:A},bgAlpha:1,role:vo},wo=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:P0},I0=t=>e=>{const n=ps(t)(e);if(n.tag==="AtKeyframe")return ls(t)(n._1);if(n.tag==="InTransition")return Ce(P.compare,Le,ls(t)(n._1),ls(t)(n._2));g()},D0=t=>e=>{const n=ps(t)(e);if(n.tag==="AtKeyframe")return hs(t)(n._1);if(n.tag==="InTransition")return Ce(P.compare,Le,hs(t)(n._1),hs(t)(n._2));g()},A0=t=>e=>{const n=t.w/tn(1e-4)(e.zoom),r=t.h/tn(1e-4)(e.zoom);return{...e,center:{x:n>=t.w?t.x+t.w/2:Oc(t.x+n/2)(t.x+t.w-n/2)(e.center.x),y:r>=t.h?t.y+t.h/2:Oc(t.y+r/2)(t.y+t.h-r/2)(e.center.y)}}},B0=t=>A0((()=>{const e=Ye(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}})()),F0=t=>e=>{const n=t.endT-t.startT;return n<=0?1:tn(0)(Gr(1)((e-t.startT)/n))},Yc=t=>e=>n=>tn(0)(Gr(1)((n-ae(0)(.3)(t+T0(e)|0).value)/tn(1e-4)(.7))),Xc=t=>e=>n=>qc(r=>i=>i.tag==="Hidden"?xo:Lr("PloppingOut",r===e?tn(0)(Gr(1)((n-.45)/tn(1e-4)(.55))):Yc(t)(r)(n)))(r=>r.tag==="Retracted"?No:br("Retracting",Ec,n)),Vc=t=>e=>qc(n=>r=>r.tag==="Hidden"?xo:Lr("PloppingIn",Yc(t)(n)(e)))(n=>n.tag==="Retracted"?No:br("Extending",rs,e)),bo=t=>e=>{const n=t.endT-t.startT;return n<=0?1:tn(0)(Gr(1)((e-t.startT)/n))},R0=t=>e=>n=>r=>i=>{const o=$c(e)(n)(u=>u.target.tag==="EdgeWindow"&&u.target._1===i);if(o.tag==="Just"){const u=Uu(t.timing.edgeEasing)(bo(o._1)(n)),s=o._1.target.tag==="EdgeWindow"?o._1.target._2:is("Extend",rs);if(s.tag==="Retract")return br("Retracting",s._1,u);if(s.tag==="Extend")return br("Extending",s._1,u);g()}if(o.tag==="Nothing")return E0(e)(n)(i)||b0(e)(n)(i)?No:l0(i)(r)?kh:No;g()},Q0=t=>e=>n=>{const r=D0(e)(n);return h0(O(i=>b(i,R0(t)(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return A;if(o.tag==="Node")return Mt("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return kt(We.foldr,i(e.layout.edges))})()))},z0=t=>e=>n=>r=>{const i=$c(t)(e)(o=>o.target.tag==="NodeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=bo(i._1)(e),u=i._1.target.tag==="NodeWindow"?i._1.target._2:Dc;if(u==="PlopIn")return Lr("PloppingIn",o);if(u==="PlopOut")return Lr("PloppingOut",o);g()}if(i.tag==="Nothing")return k0(t)(e)(r)||L0(t)(e)(r)?xo:p0(r)(n)?Lh:xo;g()},W0=t=>e=>n=>{const r=I0(e)(n);return Qc(O(i=>b(i,z0(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return A;if(o.tag==="Node")return Mt("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return kt(We.foldr,i(e.layout.nodes))})()))},M0=t=>e=>n=>e.target.tag==="TokenWindow"?b(e.target._1,n<e.startT?ns:n>=e.endT?Lc:yo("Travelling",{edge:e.target._2,direction:e.target._3,progress:Uu(t.timing.tokenEasing)(bo(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?ns:n>=e.endT?Lc:yo("Filling",{node:e.target._2,progress:bo(e)(n),labels:e.target._3})):b("",ns),H0=t=>e=>n=>m0(O(r=>M0(t)(r)(n))(at(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),Pr=t=>e=>n=>({nodes:W0()(e)(n),edges:Q0(t)(e)(n),tokens:H0(t)(e.windows)(n),camera:Tc(t.cameraConfig)(e.layout)(t.cameraSpans)(n),frameTitle:C0(e)(n),visited:w0(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:A,nodeInvert:A}),O0=t=>e=>n=>Fa(T,Ga,r=>r.direction==="DiveIn"&&To(r.parentPath)(e.path)&&n>=r.startT-.7&&n<r.startT?w("Just",{node:r.node,phase:(n-(r.startT-.7))/.7}):T,t.dives),q0=t=>e=>n=>r=>{const i=O0(t)(e)(n);if(i.tag==="Just"){const o=Oe(3.141592653589793*i._1.phase*3);return{...r,state:{...r.state,nodeInvert:Mt("Node",1,1,i._1.node,1*o*o,A,A)}}}if(i.tag==="Nothing")return r;g()},Uc=t=>e=>xt(n=>{const r=Xt(i=>i.direction==="DiveIn"&&To(i.childPath)((()=>{const o=n.length+1|0;return o<1?[]:bt(0,o,e)})()))(t.dives);if(r.tag==="Just"){const i=ds(t)(n)(r._1.startT-1e-4);if(i.tag==="Just")return w("Just",{bgAlpha:1,role:y0,segment:i._1,state:{...Pr(t)(i._1)(r._1.startT-1e-4),nodeFadeAlpha:Mt("Node",1,1,r._1.node,0,A,A)}});if(i.tag==="Nothing")return T;g()}if(r.tag==="Nothing")return T;g()})(J0(e)),jc=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]:N0(t)},$0=t=>e=>n=>{const r=F0(n)(e),i=ds(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),o=ds(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),u=tn(0)(Gr(1)(r/.6)),s=tn(0)(Gr(1)((r-.4)/.6)),a=(()=>{if(n.direction==="DiveIn")return Xc(t.seed)(n.node)(u);if(n.direction==="DiveOut")return Vc(t.seed)(s);g()})(),c=(()=>{if(n.direction==="DiveIn")return Vc(t.seed)(s);if(n.direction==="DiveOut")return Xc(t.seed)(n.node)(u);g()})();return[...Uc(t)(n.parentPath),...(()=>{if(i.tag==="Just"){if(o.tag==="Just")return[a({segment:i._1,state:Pr(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:Hc}),c({segment:o._1,state:Pr(t)(o._1)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),bgAlpha:1,role:vo})];if(o.tag==="Nothing")return[a({segment:i._1,state:Pr(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:Hc})];g()}if(i.tag==="Nothing")return[(()=>{const f=jc(t)(e);return{segment:f,state:Pr(t)(f)(e),bgAlpha:1,role:vo}})()];g()})()]},Y0=t=>e=>{const n=xt(G0(t))((()=>{const r=(i,o)=>{if(i.tag==="Leaf")return o;if(i.tag==="Node")return r(i._5,Ot("Cons",i._4,r(i._6,o)));g()};return kt($t.foldr,r(e.tokens,qt))})());return 0<n.length?w("Just",n[0]):T},X0=t=>e=>{const n=Y0(t)(e);if(n.tag==="Nothing")return e.camera;if(n.tag==="Just")return x0(t)(e.camera)(n._1.dot)(n._1.weight);g()},V0=t=>e=>t.placement.scale===1&&t.placement.tx===0&&t.placement.ty===0?X0(t.layout)(e):e.camera,U0=t=>e=>Xt(n=>e>=n.startT&&e<n.endT)(t.dives),j0=t=>e=>{const n=jc(t)(e),r=Pr(t)(n)(e),i=t.dives.length!==0,o=Tc(t.cameraConfig)(t.layout)(t.cameraSpans)(e),u=B0(n)(V0(n)({...r,camera:o})),s=q0(t)(n)(e)({bgAlpha:1,role:vo,segment:n,state:{...r,camera:u}}),a=Uc(t)(n.path),c=U0(t)(e);if(c.tag==="Just")return{levels:$0(t)(e)(c._1),camera:o,rootLayout:t.layout,hasDives:i,diving:!0};if(c.tag==="Nothing")return{levels:Ft(a)(s),camera:u,rootLayout:t.layout,hasDives:i,diving:!1};g()},Zc=t=>t,Kc=Zc("RunText"),Z0=Zc("RunCode"),tg=t=>e=>n=>e.length===0?n:Ft(n)({style:t,text:cr(e)}),K0=t=>({style:(()=>{if(t.style==="RunText")return Z0;if(t.style==="RunCode")return Kc;g()})(),buf:[],runs:tg(t.style)(t.buf)(t.runs)}),tp=t=>e=>0<e.length?{...t,buf:Ft(t.buf)(e[0])}:{...t,buf:Ft(t.buf)("\\")},ep=t=>e=>{let n=t,r=e,i=!0,o;for(;i;){const u=n,s=Bt(a=>T,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=tp(u)(s._1.tail),r=bt(1,s._1.tail.length,s._1.tail);continue}if(s._1.head==="`"){n=K0(u),r=s._1.tail;continue}n={...u,buf:Ft(u.buf)(s._1.head)},r=s._1.tail;continue}g()}return o},eg=t=>{const e=ep({style:Kc,buf:[],runs:[]})(Vn(t));return tg(e.style)(e.buf)(e.runs)};let ms=null;function np(){return ms||(typeof document>"u"?null:(ms=document.createElement("canvas").getContext("2d"),ms))}const ng=new Map,rp=t=>e=>n=>r=>()=>{const i=`${n} ${e}px ${t}|${r}`,o=ng.get(i);if(o!==void 0)return o;const u=np();if(!u)return r.length*e*.62;u.font=`${n} ${e}px ${t}`;const s=u.measureText(r).width;return ng.set(i,s),s},ip=ir.traverse(Nu),op=J(Tr)(0),Ir=(()=>{const t=Zn(`\r
|
|
3
|
+
`)(" "),e=Zn(`
|
|
4
|
+
`)(" "),n=(()=>{const r=Zn("\r")(" "),i=(()=>{const o=Zn(" ")(" ");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),rg=t=>e=>{const n=ip(r=>{const i=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;g()})();return rp(i.family)(i.size)(i.weight)(Ir(r.text))})(eg(Ir(e)));return()=>{const r=n();return op(r)}},ig={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"}},up=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Dr=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},sp=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ap=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},cp=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},og=t=>cr(ke(or(e=>e===" ")(ke(or(e=>e===" ")(Vn(t)).rest)).rest)),gp=t=>J(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?w("Just",n._1):e)(T)(At(Hn)(t)),ys=t=>e=>{if(t<=0)return[e];if(Un(e)<=t)return[e];const n=Vn(e),r=t<1?[]:bt(0,t,n),i=gp(r);if(i.tag==="Just"){const o=og(ic(!(i._1>=0&&i._1<r.length)||r[i._1]===" "?i._1:i._1+1|0)(e)),u=og(ci(i._1+1|0)(e));return u===""?[o]:[o,...ys(t)(u)]}if(i.tag==="Nothing"){const o=ic(t)(e),u=ci(t)(e);return u===""?[o]:[o,...ys(t)(u)]}g()},fp={cellW:7,cellH:3,maxLineWidth:20},_p=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=Dr(1)(En((sp(t.maxLineWidth)(J(o=>u=>Dr(o)(Un(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=Tt(lo(`
|
|
5
|
+
`)(o._1))(ys(i)),s=J(c=>f=>Dr(c)(Un(f)))(0)(u),a=o._2.shape==="Cylinder"?Dr(1)(En((s+2|0)+t.cellW|0,t.cellW)):r;return{...o._2,size:b(rt(s>i?En((s+2|0)+t.cellW|0,t.cellW):a),rt(Dr(1)(En(u.length+t.cellH|0,t.cellH))+(o._2.shape==="Cylinder"?1:0)|0))}})(n)}},dp=t=>e=>n=>({...n,nodes:O(r=>{const i=cp(r.id)(e);if(i.tag==="Nothing")return r;if(i.tag==="Just")return{...r,size:b(ap(r.size._1)(rt(Dr(1)(de(Vi(r.shape==="Cylinder"?(i._1+0)/t:(i._1+32)/t))))),r.size._2)};g()})(n.nodes)}),lp=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},hp=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,m=!0,p;for(;m;){const y=_,x=h;if(y>=e){m=!1,p=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,L=t[y].position,k=t[y].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})()?x+1|0:x;continue}_=y+1|0,h=x;continue}m=!1,p=x}return p};i=a+1|0,o=f(a+1|0)(c)}return s})(0)(0)},ug=t=>J(e=>n=>e+xl(n.start)(n.end))(0)(t.segments),pp=t=>e=>n=>({crossingCount:J(r=>i=>r+i.jumps.length|0)(0)(e),bendCount:J(r=>i=>r+i.bends.length|0)(0)(e),totalEdgeLength:J(r=>i=>r+ug(i))(0)(e),maxEdgeLength:J(r=>i=>lp(r)(ug(i)))(0)(e),nodeOverlapCount:hp(t),constraintViolations:n,jumpCount:J(r=>i=>r+i.jumps.length|0)(0)(e)}),xs=t=>t,jt=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=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},Ns=xs("LEFT"),mp=xs("RIGHT"),sg=xs("UNDEFINED"),yp={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},xp={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?Ge:ye;if(e==="LEFT")return xe;if(t==="RIGHT")return e==="RIGHT"?Ge:ye;if(e==="RIGHT")return xe;if(t==="UP")return e==="UP"?Ge:ye;if(e==="UP")return xe;if(t==="DOWN")return e==="DOWN"?Ge:ye;if(e==="DOWN")return xe;if(t==="UNDEFINED"&&e==="UNDEFINED")return Ge;g()},Eq0:()=>yp},Np=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){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},Jp={x:0,y:0},Xe=t=>e=>n=>{const r=jt(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:K(it)(t)(e(r._1))(n.cNodes)};g()},vi=t=>e=>n=>{const r=jt(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:K(it)(t)(e(r._1))(n.cGroups)};g()},Tp=t=>J(e=>n=>Xe(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),vp=t=>{const e=J(n=>r=>{const i=jt(r)(t.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just")return J(o=>u=>vt(it)(te)(u)([r])(o))(n)(i._1.constraints);g()})(A)(t.cNodeOrder);return J(n=>r=>Xe(r)(i=>({...i,constraints:(()=>{const o=jt(r)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})()}))(n))(t)(t.cNodeOrder)},wp=t=>e=>Xe(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}})),bp=t=>{const e=J(n=>r=>vi(r)(i=>({...i,outDegree:i.outDegreeReal}))(n))(t)(t.cGroupOrder);return J(n=>r=>Xe(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder)},sn={left:!1,right:!1,up:!1,down:!1},Lp={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},Js=t=>J(e=>n=>{const r=jt(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const i=J(u=>s=>{const a=jt(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=jt(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()})(T)(r._1.cNodes),o=vi(n)(u=>({...u,reference:i}))(e);if(i.tag==="Nothing")return o;if(i.tag==="Just"){const u=jt(i._1)(o.cNodes);if(u.tag==="Nothing")return o;if(u.tag==="Just"){const s=u._1;return J(a=>c=>Xe(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),Ve=t=>Js({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return A;if(n.tag==="Node")return Mt("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)})()}),xn=t=>Js({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return A;if(n.tag==="Node")return Mt("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)})()}),ag=t=>{const e=J(n=>r=>vi(r)(i=>({...i,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return J(n=>r=>{const i=jt(r)(n.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just"){if(i._1.cGroup.tag==="Nothing")return n;if(i._1.cGroup.tag==="Just"){const o=i._1.cGroup._1;return J(u=>s=>{const a=jt(s)(u.cNodes);if(a.tag==="Nothing")return u;if(a.tag==="Just")return a._1.cGroup.tag==="Just"&&a._1.cGroup._1!==o?vi(a._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(vi(o)(c=>Qe(xr)(s)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,s]})(u)):u;g()})(n)(i._1.constraints)}}g()})(e)(e.cNodeOrder)},Lo=t=>{const e=vp(t.cGraph);return{...t,cGraph:ag(J(n=>r=>Xe(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},kp=t=>e=>J(n=>r=>{if(t==="LEFT"||t==="UP"){const o=r._2;return Xe(r._1)(u=>({...u,constraints:[...u.constraints,o]}))(n)}const i=r._1;return Xe(r._2)(o=>({...o,constraints:[...o.constraints,i]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),an=t=>{const e={...t,cGraph:kp(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return A;if(r.tag==="Node")return Mt("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:ag((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);g()})())}},Ep=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?an(r):e==="RIGHT"?an({...r,cGraph:Ve(r.cGraph)}):e==="UP"?an({...r,cGraph:xn(r.cGraph)}):e==="DOWN"?an({...r,cGraph:Ve(xn(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?Lo({...r,cGraph:Ve(r.cGraph)}):e==="UP"?an({...r,cGraph:xn(r.cGraph)}):e==="DOWN"?an({...r,cGraph:Ve(xn(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?Lo({...r,cGraph:Ve(r.cGraph)}):e==="UP"?an({...r,cGraph:xn(Ve(r.cGraph))}):e==="DOWN"?an({...r,cGraph:Ve(xn(Ve(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?an({...r,cGraph:xn(r.cGraph)}):e==="RIGHT"?an({...r,cGraph:Ve(xn(r.cGraph))}):e==="DOWN"?Lo({...r,cGraph:Ve(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?an({...r,cGraph:xn(Ve(r.cGraph))}):e==="RIGHT"?an({...r,cGraph:Ve(xn(Ve(r.cGraph)))}):e==="UP"?Lo({...r,cGraph:Ve(r.cGraph)}):r;g()},cg=t=>e=>e.finished||!Np(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:Ep(e.direction)(t)(e),Cp=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?cg(Ns)(t):t,n={...e,cGraph:bp(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},gg=t=>e=>n=>{const r=jt(t)(n.cNodes),i=jt(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:K(it)(t)({...r._1,cGroup:w("Just",e)})(n.cNodes),cGroups:K(it)(e)({...i._1,cNodes:Qe(xr)(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},fg=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:K(it)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:T,cGroupOffset:Jp,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:sn})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),Ts=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:J(r=>i=>gg(i)(n)(r))({...e,cGroups:K(it)(n)({id:n,master:t.master,cNodes:[],startPos:-1e308,incomingConstraints:[],outDegree:0,outDegreeReal:0,reference:T,delta:0,deltaNormalized:0})(e.cGroups),cGroupOrder:[...e.cGroupOrder,n],nextCGroupId:n+1|0})(t.nodes)}},Sp=t=>J(e=>n=>{const r=jt(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?Ts({master:T,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),Gp=t=>({cGraph:Tp(Sp(Js(t))),direction:sg,compactionAlgorithm:T,constraintAlgorithm:T,spacingsHandler:Lp,lockFun:T,finished:!1}),_g=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Pp=t=>e=>{const n=st.compare(t._1)(e._1);return n==="LT"?ye:n==="GT"?xe:it.compare(t._2)(e._2)},Ip=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),dg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=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},lg=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",hg=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),pg=rt(4),mg=_g(0)(pg/2-.5),Dp=_g(0)(pg/2-.5),ko=t=>e=>Pp(b(t.hitbox.x+t.hitbox.width/2,t.id))(b(e.hitbox.x+e.hitbox.width/2,e.id)),Ap=t=>e=>{const n=On(Yt,T,r=>ko(t)(r)==="LT",e);if(n.tag==="Just"){const r=Qa(Yt,T,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return Ft(e)(t);g()},yg=t=>e=>{const n=at(i=>ko(i)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?w("Just",n[r]):T},Bp=t=>e=>{const n=Ap(e)(t.intervals),r=Xt(o=>ko(e)(o)==="LT")(n),i=K(it)(e.id)((()=>{const o=yg(e)(n);return o.tag==="Just"?w("Just",o._1.id):T})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return K(it)(r._1.id)(w("Just",e.id))(i);if(r.tag==="Nothing")return i;g()})()}},Fp=t=>e=>{const n=st.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?xe:Ge:e.low?ye:Ge:n},Rp=t=>J(e=>n=>Xe(n.id)(r=>({...r,constraints:[]}))(e))(t)(xt(e=>jt(e)(t.cNodes))(t.cNodeOrder)),Qp=t=>e=>J(n=>r=>{const i=jt(r._1)(n.cNodes);if(i.tag==="Just")return Xe(r._1)(o=>({...o,constraints:[...o.constraints,...r._2]}))(n);if(i.tag==="Nothing")return n;g()})(e)(Ip(t)),xg=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}},Ng=t=>e=>n=>J(r=>i=>n(i)?Xe(i.id)(xg(t))(r):r)(e)(xt(r=>jt(r)(e.cNodes))(e.cNodeOrder)),zp=t=>e=>{const n=(r,i,o)=>{const u=Xe(o)(xg(t))(r);return i.length<=1?u:J(s=>a=>a===o?s:Xe(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 J(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=>jt(r)(e.cGroups))(e.cGroupOrder))},Wp=t=>e=>{const n=yg(e)(t.intervals),r=Xt(o=>ko(e)(o)==="LT")(t.intervals),i=n.tag==="Just"&&(()=>{const o=dg(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)(te)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const o=dg(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)(te)(e.id)([r._1.id])(i):i,intervals:at(o=>o.id!==e.id,t.intervals)}},Mp=t=>e=>e.low?Bp(t)(e.node):Wp(t)(e.node),vs=t=>e=>Qp(J(Mp)({intervals:[],cand:A,constraints:A})(Lt(Fp)(Tt(at(t,xt(n=>jt(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints)(e),Hp=t=>vs(e=>!0)(zp(mg)(vs(hg)(Ng(mg)(vs(lg)(Ng(Dp)(t)(lg)))(hg)))),Op=t=>Hp(Rp(t.cGraph)),Eo=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Jg=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ws=t=>e=>n=>r=>i=>({id:t,representedEdges:[i],affectedBends:[e,n],hitbox:{x:Eo(e._1)(n._1),y:Eo(e._2)(n._2),width:$n(e._1-n._1),height:$n(e._2-n._2)},ignoreSpacing:sn,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:T}),qp=t=>e=>{const n=Eo(t.hitbox.x)(e.hitbox.x),r=Eo(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:Jg(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Jg(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()})()}},$p=t=>e=>$n(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,Yp=t=>e=>$n(t.hitbox.x-e.hitbox.x)<=1e-4?st.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?ye:xe,Tg=(t,e)=>({tag:t,_1:e}),bs=Kt(P)(zt),Co=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},vg=(()=>{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=P.compare(n._1)(r._1);if(i==="LT")return ye;if(i==="GT")return xe;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?Ge:ye;if(r._2.tag==="Nothing")return xe;if(n._2.tag==="Just"&&r._2.tag==="Just")return P.compare(n._2._1)(r._2._1);g()},Eq0:()=>t};return J(n=>r=>K(e)(r)()(n))(A)})(),Gn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Xp=J(t=>e=>K(xp)(e)()(t))(A),Ls=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=ac.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},Vp=t=>e=>{const n=bs(O(o=>b(o.id,o))(t)),r=xt(o=>Co(o)(n))(e),i=it.compare((()=>{const o=vg(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=vg(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{...sn,left:!0,right:!1};if(i==="GT")return{...sn,left:!1,right:!0};if(i==="EQ")return sn;g()},Up=t=>xt(e=>{if(e.direction==="V")return w("Just",{start:e.start,end:e.end});if(e.direction==="H")return T;g()})(t.segments),So=t=>e=>n=>{if(n.tag==="Just"){const r=Gn(e)(t);if(r.tag==="Just"){const i=Xt(o=>o.id===n._1)(r._1);if(i.tag==="Just")return i._1.side;if(i.tag==="Nothing")return pn;g()}if(r.tag==="Nothing")return pn;g()}if(n.tag==="Nothing")return pn;g()},jp=t=>e=>n=>{const r=fg({origin:w("Just",Tg("SegmentOrigin",n)),kind:w("Just","vs"),hitbox:n.hitbox})(e.cGraph),i=wp(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const o=jt(n.potentialGroupParents[0])(i.cNodes);if(o.tag==="Just"){if(o._1.cGroup.tag==="Just")return gg(r.id)(o._1.cGroup._1)(i);if(o._1.cGroup.tag==="Nothing")return i;g()}if(o.tag==="Nothing")return i;g()}return Ts({master:w("Just",r.id),nodes:[r.id]})(i).graph})(),edgeToCs:J(o=>u=>vt(P)(te)(u)([r.id])(o))(e.edgeToCs)(n.representedEdges),lockMap:K(it)(r.id)(Vp(t)(n.representedEdges))(e.lockMap)}},Zp=t=>e=>n=>{const r=Bt(i=>T,i=>o=>w("Just",{head:i,tail:o}),Lt(Yp)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const i=J(o=>u=>$p(o.survivor)(u)?{...o,survivor:qp(o.survivor)(u)}:{survivor:u,merged:[...o.merged,o.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return J(jp(t))(n)([...i.merged,i.survivor])}g()},Kp=t=>({cGraph:{cNodes:A,cNodeOrder:[],cGroups:A,cGroupOrder:[],supportedDirections:Xp([sg,Ns,mp]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:A,edgeToCs:A,lockMap:A}),tm=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}},em=t=>e=>n=>J(r=>i=>{const o=fg({origin:w("Just",Tg("NodeOrigin",i.node)),kind:T,hitbox:tm(i)})(r.cGraph),u=Gn(i.node)(t),s=(()=>{if(u.tag==="Nothing")return b(0,0);if(u.tag==="Just")return u._1;g()})();return{...r,cGraph:Ts({master:w("Just",o.id),nodes:[o.id]})(o.graph).graph,nodeToC:K(P)(i.node)(o.id)(r.nodeToC),lockMap:K(it)(o.id)((()=>{const a=s._1-s._2|0;return a<0?{...sn,left:!0}:a>0?{...sn,right:!0}:sn})())(r.lockMap)}})(n)(e),nm=t=>J(e=>n=>vt(P)(r=>i=>b(r._1+i._1|0,r._2+i._2|0))(n.to.node)(b(1,0))(vt(P)(r=>i=>b(r._1+i._1|0,r._2+i._2|0))(n.from.node)(b(0,1))(e)))(A)(t),rm=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?K(P)(n.origin._1._1)(n.hitbox.x)(e):e)(A)(xt(e=>jt(e)(t.cNodes))(t.cNodeOrder)),im=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?K(P)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(A)(xt(e=>jt(e)(t.cNodes))(t.cNodeOrder)),om=t=>J(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return J(i=>o=>K(ac)(o)(r)(i))(e)(n.origin._1._1.affectedBends)}return e})(A)(xt(e=>jt(e)(t.cNodes))(t.cNodeOrder)),wg=t=>{const e=bs(O(n=>b(n.id,n))(t.edges));return xt(n=>{const r=Co(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:So(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:So(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:So(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:So(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return T;g()})(t.paths)},um=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=Gn(r.tgt)(t.nodeToC),o=(()=>{if(i.tag==="Just")return jt(i._1)(t.cGraph.cNodes);if(i.tag==="Nothing")return T;g()})(),u=Gn(r.src)(t.nodeToC),s=(()=>{if(u.tag==="Just")return jt(u._1)(t.cGraph.cNodes);if(u.tag==="Nothing")return T;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 T;g()}if(s._1.cGroup.tag==="Nothing")return T;g()}if(o.tag==="Nothing")return T;g()}if(s.tag==="Nothing")return T;g()})(),c=_=>h=>m=>{if(s.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(m.cGroup.tag==="Just")return _(m.hitbox.x)&&m.cGroup._1!==s._1.cGroup._1?w("Just",h(m.cGroup._1)(s._1.cGroup._1)):T;if(m.cGroup.tag==="Nothing")return T;g()}if(s._1.cGroup.tag==="Nothing")return T;g()}if(s.tag==="Nothing")return T;g()},f=xt(_=>jt(_)(t.cGraph.cNodes))((()=>{const _=Co(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=>m=>({srcGroup:h,tgtGroup:m,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=>m=>({srcGroup:m,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 Re(u=>Qe(gn)(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}},sm=t=>e=>{const n=rt(4),r=rm(t),i=im(t),o=bs(O(s=>b(s.id,b(s.from.node,s.to.node)))(e.edges)),u=om(t);return{nodes:O(s=>{const a=Gn(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=Co(s.edge)(o),c=(()=>{if(a.tag==="Nothing")return s.segments;if(a.tag==="Just"){const f=Gn(a._1._1)(i),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})(),l=Gn(a._1._2)(i),_=(()=>{if(l.tag==="Nothing")return 0;if(l.tag==="Just")return l._1;g()})();return At((()=>{const h=s.reversed?_:d,m=s.reversed?d:_,p=s.segments.length;return y=>x=>{if(x.direction==="V"){const N=(()=>{if(y===0)return h;if(y===(p-1|0))return m;const v=Ls(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=Ls(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===(p-1|0))return x.end._1+m;const N=Ls(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:Je(f=>d=>f.end,c,bt(1,c.length,c))}})(e.paths)}},am=t=>e=>n=>r=>i=>o=>{const u=ws(i.nextId)(o._2.start)(o._2.end)(T)(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})()]}},bg=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...ws(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?{...sn,down:!0}:{...sn,up:!0}}]}),Go=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...ws(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?{...sn,down:!0}:{...sn,up:!0}}]}),cm=t=>e=>n=>{const r=Gn(n.src)(t.nodeToC),i=Gn(n.tgt)(t.nodeToC),o=(()=>{if(r.tag==="Just"){const f=jt(r._1)(t.cGraph.cNodes);return f.tag==="Just"?w("Just",f._1.hitbox):T}if(r.tag==="Nothing")return T;g()})(),u=(()=>{if(i.tag==="Just"){const f=jt(i._1)(t.cGraph.cNodes);return f.tag==="Just"?w("Just",f._1.hitbox):T}if(i.tag==="Nothing")return T;g()})(),s=Up(n.path),a=J(am(n)(o)(u)(s.length-1|0))(e)(At(f=>d=>b(f,d))(s));if(0<s.length){const f=(()=>{if(r.tag==="Just"&&o.tag==="Just"){if(n.srcSide==="North")return bg(n)(r._1)(o._1)(s[0])({side:le,down:!0})(a);if(n.srcSide==="South")return bg(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 Go(n)(i._1)(u._1)(s[d])({side:le,down:!0})(f);if(n.tgtSide==="South")return Go(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 Go(n)(i._1)(u._1)(s[c])({side:le,down:!0})(a);if(n.tgtSide==="South")return Go(n)(i._1)(u._1)(s[c])({side:he,down:!1})(a)}return a},gm=t=>e=>n=>Zp(t)(J(cm(n))({nextId:0,segments:[]})(e).segments)(n),fm=t=>gm(t.edges)(wg(t))(em(nm(t.edges))(t.nodes)(Kp())),Pn=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},ks=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Es=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=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},_m=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},dm=t=>{const e=t.Eq0();return n=>r=>{const i=s=>{let a=s,c=!0,f;for(;c;){const d=a,l=Bt(_=>T,_=>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((m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=!1;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=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=Xt(m=>!Pn(m.eid)(d.removedEdges)&&(e.eq(m.src)(_)||e.eq(m.tgt)(_)))(r);if(h.tag==="Nothing"){a={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const m=e.eq(h._1.src)(_)?h._1.tgt:h._1.src,p={...d,degree:K(t)(m)((()=>{const y=(x=>{let N=x,v=!0,L;for(;v;){const k=N;if(k.tag==="Leaf"){v=!1,L=T;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})(d.degree);if(y.tag==="Nothing")return-1;if(y.tag==="Just")return y._1-1|0;g()})())(d.degree),removedNodes:K(t)(_)()(d.removedNodes),removedEdges:K(it)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:_,neighbour:m,viaSrc:e.eq(h._1.src)(_)}],queue:l._1.tail};if((()=>{const y=(N=>{let v=N,L=!0,k;for(;L;){const E=v;if(E.tag==="Leaf"){L=!1,k=T;continue}if(E.tag==="Node"){const Q=t.compare(m)(E._3);if(Q==="LT"){v=E._5;continue}if(Q==="GT"){v=E._6;continue}if(Q==="EQ"){L=!1,k=w("Just",E._4);continue}}g()}return k})(p.degree),x=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 Q=t.compare(m)(E._3);if(Q==="LT"){v=E._5;continue}if(Q==="GT"){v=E._6;continue}if(Q==="EQ"){L=!1,k=!0;continue}}g()}return k};return(()=>{if(y.tag==="Nothing")return!1;if(y.tag==="Just")return y._1===1;g()})()&&!x(p.removedNodes)})()){a={...p,queue:[...p.queue,m]};continue}a=p;continue}}g()}return f},o=J(s=>a=>vt(t)(oe)(a.src)(1)(vt(t)(oe)(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=T;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=>!Pn(s.eid)(u.removedEdges),r),removed:u.record}}},lm=t=>e=>n=>J(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=T;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 K(t)(i.node)(i.viaSrc?u-1|0:u+1|0)(r)})(n)(ke(e)),Cs=t=>{const e=t.Eq0();return n=>r=>i=>{const o={...i,treeNode:K(t)(r)()(i.treeNode)};return J(u=>s=>{if(Pn(s.eid)(u.st.edgeVisited))return u;const a={...u.st,edgeVisited:K(it)(s.eid)()(u.st.edgeVisited)},c=e.eq(s.src)((()=>{const f=s.src,d=_=>{let h=_,m=!0,p;for(;m;){const y=h;if(y.tag==="Leaf"){m=!1,p=!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"){m=!1,p=!0;continue}}g()}return p},l=s.tgt;return d(a.treeNode)&&!(_=>{let h=_,m=!0,p;for(;m;){const y=h;if(y.tag==="Leaf"){m=!1,p=!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"){m=!1,p=!0;continue}}g()}return p})(a.treeNode)})()?s.src:(()=>{const f=s.tgt,d=_=>{let h=_,m=!0,p;for(;m;){const y=h;if(y.tag==="Leaf"){m=!1,p=!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"){m=!1,p=!0;continue}}g()}return p},l=s.src;return d(a.treeNode)&&!(_=>{let h=_,m=!0,p;for(;m;){const y=h;if(y.tag==="Leaf"){m=!1,p=!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"){m=!1,p=!0;continue}}g()}return p})(a.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(Pn(s.eid)(a.treeEdge)){if((d=>{let l=d,_=!0,h;for(;_;){const m=l;if(m.tag==="Leaf"){_=!1,h=!1;continue}if(m.tag==="Node"){const p=t.compare(c)(m._3);if(p==="LT"){l=m._5;continue}if(p==="GT"){l=m._6;continue}if(p==="EQ"){_=!1,h=!0;continue}}g()}return h})(a.treeNode))return{...u,st:a};const f=Cs(t)(n)(c)(a);return{count:u.count+f.count|0,st:f.st}}if((()=>{const f=l=>{let _=l,h=!0,m;for(;h;){const p=_;if(p.tag==="Leaf"){h=!1,m=!1;continue}if(p.tag==="Node"){const y=t.compare(c)(p._3);if(y==="LT"){_=p._5;continue}if(y==="GT"){_=p._6;continue}if(y==="EQ"){h=!1,m=!0;continue}}g()}return m},d=s.tgt;return!f(a.treeNode)&&(()=>{const l=(m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const v=t.compare(d)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){y=!1,x=w("Just",N._4);continue}}g()}return x})(a.layer),_=s.src,h=(m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=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=Cs(t)(n)(c)({...a,treeEdge:K(it)(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))&&!Pn(u.eid)(o.edgeVisited),n))}},Po=t=>e=>n=>r=>{const i=r.src,o=(l=>{let _=l,h=!0,m;for(;h;){const p=_;if(p.tag==="Leaf"){h=!1,m=T;continue}if(p.tag==="Node"){const y=t.compare(i)(p._3);if(y==="LT"){_=p._5;continue}if(y==="GT"){_=p._6;continue}if(y==="EQ"){h=!1,m=w("Just",p._4);continue}}g()}return m})(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,m;for(;h;){const p=_;if(p.tag==="Leaf"){h=!1,m=T;continue}if(p.tag==="Node"){const y=t.compare(s)(p._3);if(y==="LT"){_=p._5;continue}if(y==="GT"){_=p._6;continue}if(y==="EQ"){h=!1,m=w("Just",p._4);continue}}g()}return m})(e.poID),c=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})(),f=(l=>{let _=l,h=!0,m;for(;h;){const p=_;if(p.tag==="Leaf"){h=!1,m=T;continue}if(p.tag==="Node"){const y=t.compare(n)(p._3);if(y==="LT"){_=p._5;continue}if(y==="GT"){_=p._6;continue}if(y==="EQ"){h=!1,m=w("Just",p._4);continue}}g()}return m})(e.poID),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return(()=>{const l=r.src,_=(h=>{let m=h,p=!0,y;for(;p;){const x=m;if(x.tag==="Leaf"){p=!1,y=T;continue}if(x.tag==="Node"){const N=t.compare(l)(x._3);if(N==="LT"){m=x._5;continue}if(N==="GT"){m=x._6;continue}if(N==="EQ"){p=!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 m=(p=>{let y=p,x=!0,N;for(;x;){const v=y;if(v.tag==="Leaf"){x=!1,N=T;continue}if(v.tag==="Node"){const L=t.compare(h)(v._3);if(L==="LT"){y=v._5;continue}if(L==="GT"){y=v._6;continue}if(L==="EQ"){x=!1,N=w("Just",v._4);continue}}g()}return N})(e.lowestPoID);return(()=>{if(m.tag==="Nothing")return 0<=d;if(m.tag==="Just")return m._1<=d;g()})()&&d<=c})()})()})()?u>=c:u<c},hm=t=>{const e=Kt(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})},pm=t=>e=>n=>J(r=>i=>{if((()=>{const f=i.src,d=h=>{let m=h,p=!0,y;for(;p;){const x=m;if(x.tag==="Leaf"){p=!1,y=!1;continue}if(x.tag==="Node"){const N=t.compare(f)(x._3);if(N==="LT"){m=x._5;continue}if(N==="GT"){m=x._6;continue}if(N==="EQ"){p=!1,y=!0;continue}}g()}return y},l=i.tgt,_=h=>{let m=h,p=!0,y;for(;p;){const x=m;if(x.tag==="Leaf"){p=!1,y=!1;continue}if(x.tag==="Node"){const N=t.compare(l)(x._3);if(N==="LT"){m=x._5;continue}if(N==="GT"){m=x._6;continue}if(N==="EQ"){p=!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,_=T;continue}if(h.tag==="Node"){const m=t.compare(o)(h._3);if(m==="LT"){d=h._5;continue}if(m==="GT"){d=h._6;continue}if(m==="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,_=T;continue}if(h.tag==="Node"){const m=t.compare(s)(h._3);if(m==="LT"){d=h._5;continue}if(m==="GT"){d=h._6;continue}if(m==="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:T,slack:1e9})(e).edge,mm=t=>{const e=Kt(t)(zt);return n=>r=>{const i=J(o=>u=>ks(o)((()=>{const s=(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=T;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=T;continue}if(d.tag==="Node"){const l=t.compare(o)(d._3);if(l==="LT"){a=d._5;continue}if(l==="GT"){a=d._6;continue}if(l==="EQ"){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))}},Lg=t=>{const e=t.Eq0();return n=>r=>i=>{const o=J(s=>a=>{const c=Lg(t)(n)(e.eq(a.src)(r)?a.tgt:a.src)({...s.st,edgeVisited:K(it)(a.eid)()(s.st.edgeVisited)});return{lowest:ks(s.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:i})(at(s=>Pn(s.eid)(i.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!Pn(s.eid)(i.edgeVisited),n)),u=ks(o.lowest)(o.st.postOrder);return{lowest:u,st:{...o.st,poID:K(t)(r)(o.st.postOrder)(o.st.poID),lowestPoID:K(t)(r)(u)(o.st.lowestPoID),postOrder:o.st.postOrder+1|0}}}},kg=t=>{const e=Lg(t);return n=>r=>i=>0<n.length?e(r)(n[0])({...i,edgeVisited:A,postOrder:1,poID:A,lowestPoID:A}).st:i},ym=t=>{const e=t.Eq0();return n=>r=>i=>at(o=>Pn(o.eid)(r.treeEdge)&&(e.eq(o.src)(i)||e.eq(o.tgt)(i)),n)},xm=t=>e=>Xt(n=>{const r=Es(n.eid)(e.cutvalue);return Pn(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),Eg=t=>{const e=Cs(t);return n=>r=>i=>{const o=0<n.length?w("Just",n[0]):T;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=pm(t)(r)(u.st);if(s.tag==="Nothing")return u.st;if(s.tag==="Just"){const a=s._1.tgt,c=(h=>{let m=h,p=!0,y;for(;p;){const x=m;if(x.tag==="Leaf"){p=!1,y=T;continue}if(x.tag==="Node"){const N=t.compare(a)(x._3);if(N==="LT"){m=x._5;continue}if(N==="GT"){m=x._6;continue}if(N==="EQ"){p=!1,y=w("Just",x._4);continue}}g()}return y})(u.st.layer),f=s._1.src,d=(h=>{let m=h,p=!0,y;for(;p;){const x=m;if(x.tag==="Leaf"){p=!1,y=T;continue}if(x.tag==="Node"){const N=t.compare(f)(x._3);if(N==="LT"){m=x._5;continue}if(N==="GT"){m=x._6;continue}if(N==="EQ"){p=!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(m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=!1;continue}if(N.tag==="Node"){const v=t.compare(h)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){y=!1,x=!0;continue}}g()}return x})(u.st.treeNode)})()?-l:l;return Eg(t)(n)(r)({...u.st,layer:J(h=>m=>(p=>{let y=p,x=!0,N;for(;x;){const v=y;if(v.tag==="Leaf"){x=!1,N=!1;continue}if(v.tag==="Node"){const L=t.compare(m)(v._3);if(L==="LT"){y=v._5;continue}if(L==="GT"){y=v._6;continue}if(L==="EQ"){x=!1,N=!0;continue}}g()}return N})(u.st.treeNode)?K(t)(m)((()=>{const p=(y=>{let x=y,N=!0,v;for(;N;){const L=x;if(L.tag==="Leaf"){N=!1,v=T;continue}if(L.tag==="Node"){const k=t.compare(m)(L._3);if(k==="LT"){x=L._5;continue}if(k==="GT"){x=L._6;continue}if(k==="EQ"){N=!1,v=w("Just",L._4);continue}}g()}return v})(u.st.layer);if(p.tag==="Nothing")return 0+_|0;if(p.tag==="Just")return p._1+_|0;g()})())(h):h)(u.st.layer)(n)})}}g()}},Nm=t=>e=>n=>r=>J(i=>o=>{if(Po(t)(r)(o.src)(n)&&!Po(t)(r)(o.tgt)(n)){const u=o.tgt,s=(d=>{let l=d,_=!0,h;for(;_;){const m=l;if(m.tag==="Leaf"){_=!1,h=T;continue}if(m.tag==="Node"){const p=t.compare(u)(m._3);if(p==="LT"){l=m._5;continue}if(p==="GT"){l=m._6;continue}if(p==="EQ"){_=!1,h=w("Just",m._4);continue}}g()}return h})(r.layer),a=o.src,c=(d=>{let l=d,_=!0,h;for(;_;){const m=l;if(m.tag==="Leaf"){_=!1,h=T;continue}if(m.tag==="Node"){const p=t.compare(a)(m._3);if(p==="LT"){l=m._5;continue}if(p==="GT"){l=m._6;continue}if(p==="EQ"){_=!1,h=w("Just",m._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:T,slack:1e9})(e).edge,Jm=t=>{const e=t.Eq0();return n=>r=>i=>o=>{const u=o.tgt,s=o.src;return J(a=>c=>{if((()=>{const f=Es(c.eid)(r.cutvalue);if(f.tag==="Just")return!0;if(f.tag==="Nothing")return!1;g()})()){const f=Es(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))}},Tm=t=>{const e=Jm(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,_=T;continue}if(h.tag==="Node"){const m=t.compare(u)(h._3);if(m==="LT"){d=h._5;continue}if(m==="GT"){d=h._6;continue}if(m==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(a);if(c.tag==="Just")return K(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=(p=>{let y=p,x=!0,N;for(;x;){const v=y;if(v.tag==="Leaf"){x=!1,N=T;continue}if(v.tag==="Node"){const L=t.compare(_)(v._3);if(L==="LT"){y=v._5;continue}if(L==="GT"){y=v._6;continue}if(L==="EQ"){x=!1,N=w("Just",v._4);continue}}g()}return N})(l.unknown),m=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;g()})();if(m.length===1){const p=t.Eq0().eq(m[0].src)(_)?m[0].tgt:m[0].src;a={unknown:o(_,m[0],o(p,m[0],l.unknown)),cutvalue:K(it)(m[0].eid)(e(n)(l)(_)(m[0]))(l.cutvalue)},c=p;continue}f=!1,d=l}return d})(r)(i)}},Cg=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 m=st.compare(c.weight)(f.weight);return m==="LT"||m==="GT"||m!=="EQ"?m:Ge},Eq0:()=>r},o=J(c=>f=>K(i)(f)()(c))(A),u=ym(t),s=Kt(t)(zt),a=Tm(t);return c=>f=>d=>{const l={unknown:s(O(_=>b(_,kt(We.foldr,o(u(f)(d)(_)))))(c)),cutvalue:A};return{...d,cutvalue:J(a(f))(l)(at(_=>{const h=(m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=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}}},vm=t=>{const e=kg(t),n=Cg(t);return r=>i=>o=>u=>s=>{const a={...s,treeEdge:K(it)(u.eid)()(ni(it)(o.eid)(s.treeEdge))},c=u.tgt,f=(m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const v=t.compare(c)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){y=!1,x=w("Just",N._4);continue}}g()}return x})(a.layer),d=u.src,l=(m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const v=t.compare(d)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=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=Po(t)(a)(u.tgt)(o)?_:-_;return n(r)(i)(e(r)(i)({...a,layer:J(m=>p=>Po(t)(a)(p)(o)?m:K(t)(p)((()=>{const y=(x=>{let N=x,v=!0,L;for(;v;){const k=N;if(k.tag==="Leaf"){v=!1,L=T;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})(a.layer);if(y.tag==="Nothing")return 0+h|0;if(y.tag==="Just")return y._1+h|0;g()})())(m))(a.layer)(r)}))}},wm=t=>{const e=vm(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=xm(i)(_);if(h.tag==="Nothing"){f=!1,d=_;continue}if(h.tag==="Just"){const m=Nm(t)(i)(h._1)(_);if(m.tag==="Nothing"){f=!1,d=_;continue}if(m.tag==="Just"){a=l-1|0,c=e(r)(i)(h._1)(m._1)(_);continue}}g()}return d})(n)(o)},bm=t=>{const e=Cg(t),n=kg(t),r=Eg(t);return i=>o=>u=>e(i)(o)(n(i)(o)(r(i)(o)(u)))},Sg=t=>e=>J(n=>r=>vt(t)(te)(e(r))([r])(n))(A),Lm=t=>{const e=Kt(t)(zt);return n=>r=>i=>{const o=a=>c=>f=>d=>{let l=a,_=c,h=f,m=d,p=!0,y;for(;p;){const x=l,N=_,v=h,L=m,k=Bt(E=>T,E=>Q=>w("Just",{head:E,tail:Q}),v);if(k.tag==="Nothing"){p=!1,y=L;continue}if(k.tag==="Just"){const E=k._1.head,Q=(S=>{let C=S,U=!0,Y;for(;U;){const W=C;if(W.tag==="Leaf"){U=!1,Y=T;continue}if(W.tag==="Node"){const z=t.compare(E)(W._3);if(z==="LT"){C=W._5;continue}if(z==="GT"){C=W._6;continue}if(z==="EQ"){U=!1,Y=w("Just",W._4);continue}}g()}return Y})(L.layer),H=(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;g()})(),j=J(S=>C=>{const U=C.tgt,Y=(z=>{let R=z,G=!0,I;for(;G;){const D=R;if(D.tag==="Leaf"){G=!1,I=T;continue}if(D.tag==="Node"){const B=t.compare(U)(D._3);if(B==="LT"){R=D._5;continue}if(B==="GT"){R=D._6;continue}if(B==="EQ"){G=!1,I=w("Just",D._4);continue}}g()}return I})(S.incident),W=(()=>{if(Y.tag==="Nothing")return-1;if(Y.tag==="Just")return Y._1-1|0;g()})();return{st:{...S.st,layer:K(t)(C.tgt)(_m((()=>{const z=C.tgt,R=(G=>{let I=G,D=!0,B;for(;D;){const q=I;if(q.tag==="Leaf"){D=!1,B=T;continue}if(q.tag==="Node"){const V=t.compare(z)(q._3);if(V==="LT"){I=q._5;continue}if(V==="GT"){I=q._6;continue}if(V==="EQ"){D=!1,B=w("Just",q._4);continue}}g()}return B})(S.st.layer);if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})())(H+C.delta|0))(S.st.layer)},incident:K(t)(C.tgt)(W)(S.incident),queue:W===0?[...S.queue,C.tgt]:S.queue}})({st:L,incident:N,queue:k._1.tail})((()=>{const S=(C=>{let U=C,Y=!0,W;for(;Y;){const z=U;if(z.tag==="Leaf"){Y=!1,W=T;continue}if(z.tag==="Node"){const R=t.compare(E)(z._3);if(R==="LT"){U=z._5;continue}if(R==="GT"){U=z._6;continue}if(R==="EQ"){Y=!1,W=w("Just",z._4);continue}}g()}return W})(x);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})());l=x,_=j.incident,h=j.queue,m=j.st;continue}g()}return y},u=Sg(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,_=T;continue}if(h.tag==="Node"){const m=t.compare(a)(h._3);if(m==="LT"){d=h._5;continue}if(m==="GT"){d=h._6;continue}if(m==="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(Sg(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,_=T;continue}if(h.tag==="Node"){const m=t.compare(a)(h._3);if(m==="LT"){d=h._5;continue}if(m==="GT"){d=h._6;continue}if(m==="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)}},km=t=>{const e=hm(t),n=Lm(t),r=bm(t),i=wm(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}},Gg=t=>{const e=mm(t),n=km(t),r=dm(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)(lm(t)(u.removed)(n(u.coreNodes)(u.coreEdges)))}},Pg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=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},Ss=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Em=Gg(it),wi=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}),Cm=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=rt((()=>{const i=Pg(n.cGroup._1)(t);if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})());return Xe(n.id)(i=>({...i,hitbox:{...i.hitbox,x:r+i.cGroupOffset.x}}))(e)}g()},Sm=t=>e=>({...e,cGraph:J(Cm(t))(e.cGraph)((()=>{const n=e.cGraph;return xt(r=>jt(r)(n.cNodes))(n.cNodeOrder)})())}),Gm=t=>e=>n=>r=>i=>{const o=de(Vi(e.cGroupOffset.x-t.cGroupOffset.x));return wi({src:i.nextNodeId,tgt:r,delta:Ss(0)(-o),weight:1})(wi({src:i.nextNodeId,tgt:n,delta:Ss(0)(o),weight:1})({...i,nodes:[...i.nodes,i.nextNodeId],nextNodeId:i.nextNodeId+1|0}))},Pm=t=>e=>n=>r=>i=>o=>u=>{const s=Ss(0)(de(Vi(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)?Gm(n)(r)(i)(o)(u):wi({src:i,tgt:o,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(u)},Im=t=>e=>n=>r=>i=>{const o=jt(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"?Pm(t)(e)(n)(o._1)(n.cGroup._1)(o._1.cGroup._1)(r):r;g()},Dm=t=>e=>n=>r=>J(Im(t)(e)(r))(n)(r.constraints),Am=t=>e=>wi({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),Bm=t=>{const e=J(i=>o=>vt(it)(oe)(o.tgt)(1)(i))(A)(t.edges),n=at(i=>{const o=Pg(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 J(i=>o=>wi({src:r,tgt:o,delta:1,weight:0})(i))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},Fm=t=>e=>{const n=Bm(J(Am)(J(Dm(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return xt(i=>jt(i)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},Rm=t=>e=>{const n=Fm(t)(e);return Sm(Em(n.nodes)(n.edges))(e)},Ig=t=>t,ee=Ig("H"),ne=Ig("V"),Qm=t=>b(t._2,t._1),Dg=t=>({...t,position:b(t.position._2,t.position._1),size:b(t.size._2,t.size._1)}),zm=t=>({start:b(t.start._2,t.start._1),end:b(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return ne;if(t.direction==="V")return ee;g()})()}),Ag=t=>({...t,segments:O(zm)(t.segments),bends:O(Qm)(t.bends)}),Wm=t=>({nodes:O(Dg)(t.nodes),edges:t.edges,paths:O(Ag)(t.paths),ports:t.ports}),Mm=t=>({horizontalSpacing:e=>n=>{if(t.sameEdgeVerticalSegments(e)(n)||e.ignoreSpacing.right||n.ignoreSpacing.left)return 0;const r=n.kind.tag==="Nothing"?!1:n.kind.tag==="Just"&&n.kind._1==="vs";return e.kind.tag!=="Nothing"&&e.kind.tag==="Just"&&e.kind._1==="vs"?r?10:4:r?4:8},verticalSpacing:e=>n=>{if(t.sameEdgeVerticalSegments(e)(n))return 1;if(e.hitbox.y<=n.hitbox.y?e.ignoreSpacing.down||n.ignoreSpacing.up:e.ignoreSpacing.up||n.ignoreSpacing.down)return 0;const r=n.kind.tag==="Nothing"?!1:n.kind.tag==="Just"&&n.kind._1==="vs";return e.kind.tag!=="Nothing"&&e.kind.tag==="Just"&&e.kind._1==="vs"?r?10:4:r?4:8}}),Hm=t=>e=>Rm(e),Om=t=>e=>{const n=Wm(e),r=fm(n),i=um(r)(wg(n)),o=sm(cg(Ns)(Cp({...Gp(r.cGraph),compactionAlgorithm:w("Just",Hm()(i)),constraintAlgorithm:w("Just",Op),spacingsHandler:Mm(i)})).cGraph)({nodes:n.nodes,edges:n.edges,paths:n.paths});return{nodes:O(Dg)(o.nodes),edges:O(Ag)(o.edges)}},Bg=t=>t,Ar=Kt(it)(zt),Pt=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=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},Fg=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=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ht=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Br=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},qm=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?ye:n==="GT"?xe:it.compare(t._2)(e._2)},Fr=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},$m=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),Ym=t=>t,Rg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Xm=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Io=Bg("Regular"),Do=Bg("Critical"),Qg=t=>e=>{const n=J(u=>s=>K(P)(s.node)(s)(u))(A)(e),r=1.25*rt(4),i=(u,s,a)=>(c=>f=>d=>{let l=c,_=f,h=d,m=!0,p;for(;m;){const y=l,x=_,N=h;if(N.critical){m=!1,p=N;continue}const v=Bt(k=>T,k=>E=>w("Just",{head:k,tail:E}),y),L=Bt(k=>T,k=>E=>w("Just",{head:k,tail:E}),x);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){m=!1,p=k;continue}if(v._1.head<=L._1.head){l=v._1.tail,_=x,h=k;continue}l=y,_=L._1.tail,h=k;continue}m=!1,p=N}return p})(s)(a)({conflicts:0,critical:!1}),o=(u,s,a)=>{if(ht(J(ht)(-1e18)(s.incoming))(J(ht)(-1e18)(s.outgoing))-dt(J(dt)(1e18)(s.incoming))(J(dt)(1e18)(s.outgoing))<.001||ht(J(ht)(-1e18)(a.incoming))(J(ht)(-1e18)(a.outgoing))-dt(J(dt)(1e18)(a.incoming))(J(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:Do}]:[],...f.critical?[{src:s.id,tgt:a.id,weight:1,kind:Do}]:[]];const d=dt(J(dt)(1e18)(s.incoming))(J(dt)(1e18)(s.outgoing)),l=ht(J(ht)(-1e18)(s.incoming))(J(ht)(-1e18)(s.outgoing)),_=dt(J(dt)(1e18)(a.incoming))(J(dt)(1e18)(a.outgoing)),h=ht(J(ht)(-1e18)(a.incoming))(J(ht)(-1e18)(a.outgoing)),m=(1*c.conflicts|0)+(16*(J(y=>x=>x>h?y:x>=_?y+1|0:y)(0)(s.outgoing)+J(y=>x=>x>l?y:x>=d?y+1|0:y)(0)(a.incoming)|0)|0)|0,p=(1*f.conflicts|0)+(16*(J(y=>x=>x>l?y:x>=d?y+1|0:y)(0)(a.outgoing)+J(y=>x=>x>h?y:x>=_?y+1|0:y)(0)(s.incoming)|0)|0)|0;return m<p?[{src:s.id,tgt:a.id,weight:p-m|0,kind:Io}]:m>p?[{src:a.id,tgt:s.id,weight:m-p|0,kind:Io}]:m>0?[{src:s.id,tgt:a.id,weight:0,kind:Io},{src:a.id,tgt:s.id,weight:0,kind:Io}]:[]};return J(u=>s=>J(a=>c=>K(P)(c._1)(c._2)(a))(u)((()=>{const a=J(S=>C=>{const U=C.edge.from.node+"|"+(()=>{if(C.edge.from.port.tag==="Just")return C.edge.from.port._1;if(C.edge.from.port.tag==="Nothing")return"_auto_"+C.edge.id;g()})(),Y=Rg(U)(S.entries);if(Y.tag==="Nothing")return{...S,entries:K(P)(U)({id:0,members:[C.edge.id],incoming:[C.fromPos._1],outgoing:[C.toPos._1],slot:0,mark:0,splitBy:T,splitPartner:T})(S.entries),order:[...S.order,U]};if(Y.tag==="Just")return{...S,entries:K(P)(U)({...Y._1,members:[...Y._1.members,C.edge.id],incoming:[...or(W=>W<C.fromPos._1)(Y._1.incoming).init,C.fromPos._1,...or(W=>W<=C.fromPos._1)(Y._1.incoming).rest],outgoing:[...or(W=>W<C.toPos._1)(Y._1.outgoing).init,C.toPos._1,...or(W=>W<=C.toPos._1)(Y._1.outgoing).rest]})(S.entries)};g()})({entries:A,order:[]})(s._2),c=At(S=>C=>({...C,id:S}))(xt(S=>Rg(S)(a.entries))(a.order));if(c.length===0)return[];const f=J(S=>C=>S.prev.tag==="Just"&&C-S.prev._1<1e-9?S:{prev:w("Just",C),out:[...S.out,C]})({prev:T,out:[]})(Lt(st.compare)([...Tt(c)(S=>S.incoming),...Tt(c)(S=>S.outgoing)])).out,d=f.length<2?.2*r:.2*J(S=>C=>{if(S.prev.tag==="Nothing")return{prev:w("Just",C),mn:S.mn};if(S.prev.tag==="Just")return{prev:w("Just",C),mn:dt(S.mn)(C-S.prev._1)};g()})({prev:T,mn:1e18})(f).mn,l={segments:c,deps:(()=>{const S=c.length;return Tt(Tt(Dt(0,S-2|0))(C=>Tt(Dt(C+1|0,S-1|0))(U=>[b(C,U)])))(C=>C._1>=0&&C._1<c.length?C._2>=0&&C._2<c.length?o(d,c[C._1],c[C._2]):[]:[])})()},_=at(S=>{if(S.kind==="Critical")return!0;if(S.kind==="Regular")return!1;g()},l.deps),h=(()=>{if(_.length<2)return l;const S=Ar((()=>{const z=l.segments;return O(R=>b(R.id,R.mark))((()=>{const R=z.length,G=D=>{let B=D,q=!0,V;for(;q;){const $=B,X=Xt(M=>{const et=Pt(M)($.inWeight);if(et.tag==="Nothing")return!0;if(et.tag==="Just")return et._1===0;g()})($.remaining);if(X.tag==="Nothing"){q=!1,V=$;continue}if(X.tag==="Just"){const M=X._1;B={...$,inWeight:J(et=>tt=>vt(it)(oe)(tt.tgt)(-tt.weight)(et))($.inWeight)((()=>{const et=Pt(M)($.depsBySrc);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;g()})()),marks:K(it)(M)($.nextSource)($.marks),nextSource:$.nextSource+1|0,outWeight:J(et=>tt=>vt(it)(oe)(tt.src)(-tt.weight)(et))($.outWeight)((()=>{const et=Pt(M)($.depsByTgt);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;g()})()),remaining:at(et=>et!==M,$.remaining)};continue}g()}return V},I=D=>{let B=D,q=!0,V;for(;q;){const $=B,X=Xt(M=>{const et=Pt(M)($.outWeight);if(et.tag==="Nothing")return!0;if(et.tag==="Just")return et._1===0;g()})($.remaining);if(X.tag==="Nothing"){q=!1,V=$;continue}if(X.tag==="Just"){const M=X._1;B={...$,inWeight:J(et=>tt=>vt(it)(oe)(tt.tgt)(-tt.weight)(et))($.inWeight)((()=>{const et=Pt(M)($.depsBySrc);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;g()})()),marks:K(it)(M)($.nextSink)($.marks),nextSink:$.nextSink-1|0,outWeight:J(et=>tt=>vt(it)(oe)(tt.src)(-tt.weight)(et))($.outWeight)((()=>{const et=Pt(M)($.depsByTgt);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;g()})()),remaining:at(et=>et!==M,$.remaining)};continue}g()}return V};return(D=>{let B=D,q=!0,V;for(;q;){const $=G(I(B));if($.remaining.length===0){q=!1,V=O(X=>{const M=Pt(X.id)($.marks),et=(()=>{if(M.tag==="Nothing")return X.id;if(M.tag==="Just")return M._1;g()})();return{...X,mark:et<R?(et+R|0)+1|0:et}})(z);continue}B=(()=>{const X=et=>{const tt=Pt(et)($.outWeight),gt=Pt(et)($.inWeight);return(()=>{if(tt.tag==="Nothing")return 0;if(tt.tag==="Just")return tt._1;g()})()-(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()|0},M=Lt(et=>tt=>it.compare(X(tt))(X(et)))($.remaining);if(0<M.length){const et=M[0];return{...$,inWeight:J(tt=>gt=>vt(it)(oe)(gt.tgt)(-gt.weight)(tt))($.inWeight)((()=>{const tt=Pt(et)($.depsBySrc);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),marks:K(it)(et)($.nextSource)($.marks),nextSource:$.nextSource+1|0,outWeight:J(tt=>gt=>vt(it)(oe)(gt.src)(-gt.weight)(tt))($.outWeight)((()=>{const tt=Pt(et)($.depsByTgt);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),remaining:at(tt=>tt!==et,$.remaining)}}return $})()}return V})({remaining:O(D=>D.id)(z),marks:A,inWeight:J(D=>B=>vt(it)(oe)(B.tgt)(B.weight)(D))(A)(_),outWeight:J(D=>B=>vt(it)(oe)(B.src)(B.weight)(D))(A)(_),depsBySrc:J(D=>B=>vt(it)(te)(B.src)([B])(D))(A)(_),depsByTgt:J(D=>B=>vt(it)(te)(B.tgt)([B])(D))(A)(_),nextSink:R-1|0,nextSource:R+1|0})})())})()),C=at(z=>{const R=Pt(z.src)(S),G=Pt(z.tgt)(S);return(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})()>(()=>{if(G.tag==="Nothing")return 0;if(G.tag==="Just")return G._1;g()})()},_);if(C.length===0)return l;const U=J(z=>R=>{if(Qe(xr)(R.src)(z.decisions)||Qe(xr)(R.tgt)(z.decisions))return z;const G=Pt(R.src)(z.segMap),I=Pt(R.tgt)(z.segMap);if(G.tag==="Just"&&I.tag==="Just"){const D=(G._1.incoming.length+G._1.outgoing.length|0)>2&&(I._1.incoming.length+I._1.outgoing.length|0)<=2,B=D?I._1:G._1;return{decisions:[...z.decisions,B.id],segMap:K(it)(B.id)({...B,splitBy:w("Just",D?G._1.id:I._1.id)})(z.segMap)}}return z})({decisions:[],segMap:Ar(O(z=>b(z.id,z))(l.segments))})(C),Y=U.segMap,W=J(z=>R=>{const G=dt(J(dt)(1e18)(R.incoming))(J(dt)(1e18)(R.outgoing)),I=ht(J(ht)(-1e18)(R.incoming))(J(ht)(-1e18)(R.outgoing)),D=at(X=>X.a.startPosition<=I&&X.a.endPosition>=G,At(X=>M=>({i:X,a:M}))(z.freeAreas));if(D.length===0){const X={...R,incoming:Lt(st.compare)(R.incoming),outgoing:Lt(st.compare)([(G+I)/2]),splitPartner:w("Just",z.nextId)},M={id:z.nextId,incoming:Lt(st.compare)([(G+I)/2]),mark:0,members:R.members,outgoing:Lt(st.compare)(R.outgoing),slot:0,splitBy:T,splitPartner:w("Just",R.id)};return{segMap:K(it)(M.id)(M)(K(it)(X.id)(X)(z.segMap)),freeAreas:z.freeAreas,nextId:z.nextId+1|0}}const B=0<D.length?w("Just",D[0]):T,q=(()=>{if(B.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(B.tag==="Just"){if(D.length===1)return B._1;const X=O(M=>({c:M,rating:(()=>{const et=(M.a.startPosition+M.a.endPosition)/2,tt=[et],gt=[et],_t=J((()=>{const yt=z.segMap;return Et=>Rt=>{const pt=Pt(Rt.tgt)(yt);if(pt.tag==="Nothing")return Et;if(pt.tag==="Just"){const Qt=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),Jt=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),mt=dt(J(dt)(1e18)(R.incoming))(J(dt)(1e18)(tt)),nt=(()=>{const St=ht(J(ht)(-1e18)(R.incoming))(J(ht)(-1e18)(tt)),It=J(Ut=>_e=>_e>Jt?Ut:_e>=Qt?Ut+1|0:Ut)(0)(tt)+J(Ut=>_e=>_e>St?Ut:_e>=mt?Ut+1|0:Ut)(0)(pt._1.incoming)|0,je=dt(J(dt)(1e18)(R.incoming))(J(dt)(1e18)(tt)),Ze=ht(J(ht)(-1e18)(R.incoming))(J(ht)(-1e18)(tt)),kn=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),jr=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),_n=J(Ut=>_e=>_e>Ze?Ut:_e>=je?Ut+1|0:Ut)(0)(pt._1.outgoing)+J(Ut=>_e=>_e>jr?Ut:_e>=kn?Ut+1|0:Ut)(0)(R.incoming)|0;return It===_n?It>0?{...Et,deps:Et.deps+2|0,crossings:Et.crossings+It|0}:Et:{...Et,deps:Et.deps+1|0,crossings:Et.crossings+Fr(It)(_n)|0}})(),Z=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),ut=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),ft=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(R.outgoing)),lt=ht(J(ht)(-1e18)(gt))(J(ht)(-1e18)(R.outgoing)),Nt=J(St=>It=>It>ut?St:It>=Z?St+1|0:St)(0)(R.outgoing)+J(St=>It=>It>lt?St:It>=ft?St+1|0:St)(0)(pt._1.incoming)|0,Ht=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(R.outgoing)),Vt=ht(J(ht)(-1e18)(gt))(J(ht)(-1e18)(R.outgoing)),Pe=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),un=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),Ne=J(St=>It=>It>Vt?St:It>=Ht?St+1|0:St)(0)(pt._1.outgoing)+J(St=>It=>It>un?St:It>=Pe?St+1|0:St)(0)(gt)|0;return Nt===Ne?Nt>0?{...nt,deps:nt.deps+2|0,crossings:nt.crossings+Nt|0}:nt:{...nt,deps:nt.deps+1|0,crossings:nt.crossings+Fr(Nt)(Ne)|0}}g()}})())(J((()=>{const yt=z.segMap;return Et=>Rt=>{const pt=Pt(Rt.src)(yt);if(pt.tag==="Nothing")return Et;if(pt.tag==="Just"){const Qt=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),Jt=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),mt=dt(J(dt)(1e18)(R.incoming))(J(dt)(1e18)(tt)),nt=(()=>{const St=ht(J(ht)(-1e18)(R.incoming))(J(ht)(-1e18)(tt)),It=J(Ut=>_e=>_e>Jt?Ut:_e>=Qt?Ut+1|0:Ut)(0)(tt)+J(Ut=>_e=>_e>St?Ut:_e>=mt?Ut+1|0:Ut)(0)(pt._1.incoming)|0,je=dt(J(dt)(1e18)(R.incoming))(J(dt)(1e18)(tt)),Ze=ht(J(ht)(-1e18)(R.incoming))(J(ht)(-1e18)(tt)),kn=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),jr=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),_n=J(Ut=>_e=>_e>Ze?Ut:_e>=je?Ut+1|0:Ut)(0)(pt._1.outgoing)+J(Ut=>_e=>_e>jr?Ut:_e>=kn?Ut+1|0:Ut)(0)(R.incoming)|0;return It===_n?It>0?{...Et,deps:Et.deps+2|0,crossings:Et.crossings+It|0}:Et:{...Et,deps:Et.deps+1|0,crossings:Et.crossings+Fr(It)(_n)|0}})(),Z=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),ut=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),ft=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(R.outgoing)),lt=ht(J(ht)(-1e18)(gt))(J(ht)(-1e18)(R.outgoing)),Nt=J(St=>It=>It>ut?St:It>=Z?St+1|0:St)(0)(R.outgoing)+J(St=>It=>It>lt?St:It>=ft?St+1|0:St)(0)(pt._1.incoming)|0,Ht=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(R.outgoing)),Vt=ht(J(ht)(-1e18)(gt))(J(ht)(-1e18)(R.outgoing)),Pe=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),un=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),Ne=J(St=>It=>It>Vt?St:It>=Ht?St+1|0:St)(0)(pt._1.outgoing)+J(St=>It=>It>un?St:It>=Pe?St+1|0:St)(0)(gt)|0;return Nt===Ne?Nt>0?{...nt,deps:nt.deps+2|0,crossings:nt.crossings+Nt|0}:nt:{...nt,deps:nt.deps+1|0,crossings:nt.crossings+Fr(Nt)(Ne)|0}}g()}})())({crossings:0,deps:0})(at(yt=>yt.tgt===R.id,l.deps)))(at(yt=>yt.src===R.id,l.deps)),ct=(()=>{if(R.splitBy.tag==="Just")return Pt(R.splitBy._1)(z.segMap);if(R.splitBy.tag==="Nothing")return T;g()})();if(ct.tag==="Just")return{..._t,deps:_t.deps+2|0,crossings:(()=>{const yt=dt(J(dt)(1e18)(ct._1.incoming))(J(dt)(1e18)(ct._1.outgoing)),Et=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(R.outgoing)),Rt=ht(J(ht)(-1e18)(ct._1.incoming))(J(ht)(-1e18)(ct._1.outgoing)),pt=ht(J(ht)(-1e18)(gt))(J(ht)(-1e18)(R.outgoing)),Qt=dt(J(dt)(1e18)(R.incoming))(J(dt)(1e18)(tt));return _t.crossings+(()=>{const Jt=dt(J(dt)(1e18)(ct._1.incoming))(J(dt)(1e18)(ct._1.outgoing)),mt=ht(J(ht)(-1e18)(R.incoming))(J(ht)(-1e18)(tt)),nt=ht(J(ht)(-1e18)(ct._1.incoming))(J(ht)(-1e18)(ct._1.outgoing));return((J(Z=>ut=>ut>Rt?Z:ut>=yt?Z+1|0:Z)(0)(tt)+J(Z=>ut=>ut>mt?Z:ut>=Qt?Z+1|0:Z)(0)(ct._1.incoming)|0)+J(Z=>ut=>ut>pt?Z:ut>=Et?Z+1|0:Z)(0)(ct._1.outgoing)|0)+J(Z=>ut=>ut>nt?Z:ut>=Jt?Z+1|0:Z)(0)(gt)|0})()|0})()};if(ct.tag==="Nothing")return _t;g()})()}))(D);return J(M=>et=>et.rating.crossings<M.rating.crossings||!(et.rating.crossings>M.rating.crossings)&&(et.rating.deps<M.rating.deps||!(et.rating.deps>M.rating.deps)&&et.c.a.size>M.c.a.size)?et:M)(0<X.length?X[0]:{c:B._1,rating:{crossings:1e6,deps:1e6}})(X).c}g()})(),V={...R,incoming:Lt(st.compare)(R.incoming),outgoing:Lt(st.compare)([(q.a.startPosition+q.a.endPosition)/2]),splitPartner:w("Just",z.nextId)},$={id:z.nextId,incoming:Lt(st.compare)([(q.a.startPosition+q.a.endPosition)/2]),mark:0,members:R.members,outgoing:Lt(st.compare)(R.outgoing),slot:0,splitBy:T,splitPartner:w("Just",R.id)};return{segMap:K(it)($.id)($)(K(it)(V.id)(V)(z.segMap)),freeAreas:(()=>{if(q.i>=0&&q.i<z.freeAreas.length){const X=za(Yt,T,q.i,z.freeAreas),M=(()=>{if(X.tag==="Nothing")return z.freeAreas;if(X.tag==="Just")return X._1;g()})();if(z.freeAreas[q.i].size/2<d)return M;const et=(z.freeAreas[q.i].startPosition+z.freeAreas[q.i].endPosition)/2,tt=et-d,gt=et+d;return[...q.i<1?[]:bt(0,q.i,M),...z.freeAreas[q.i].startPosition<=tt?[{startPosition:z.freeAreas[q.i].startPosition,endPosition:tt,size:tt-z.freeAreas[q.i].startPosition}]:[],...gt<=z.freeAreas[q.i].endPosition?[{startPosition:gt,endPosition:z.freeAreas[q.i].endPosition,size:z.freeAreas[q.i].endPosition-gt}]:[],...q.i<1?M:bt(q.i,M.length,M)]}return z.freeAreas})(),nextId:z.nextId+1|0}})({segMap:Y,freeAreas:(()=>{const z=Lt(st.compare)([...Tt(l.segments)(R=>R.incoming),...Tt(l.segments)(R=>R.outgoing)]);return xt(Ym)(Je(R=>G=>G-R>=2*d?w("Just",{startPosition:R+d,endPosition:G-d,size:G-R-2*d}):T,z,bt(1,z.length,z)))})(),nextId:l.segments.length})(Lt(z=>R=>st.compare(ht(J(ht)(-1e18)(z.incoming))(J(ht)(-1e18)(z.outgoing))-dt(J(dt)(1e18)(z.incoming))(J(dt)(1e18)(z.outgoing)))(ht(J(ht)(-1e18)(R.incoming))(J(ht)(-1e18)(R.outgoing))-dt(J(dt)(1e18)(R.incoming))(J(dt)(1e18)(R.outgoing))))(xt(z=>Pt(z)(Y))(U.decisions)));return{segments:(()=>{const z=(R,G)=>{if(R.tag==="Leaf")return G;if(R.tag==="Node")return z(R._5,Ot("Cons",R._4,z(R._6,G)));g()};return kt($t.foldr,z(W.segMap,qt))})(),deps:(()=>{const z=W.segMap,R=(D,B)=>{if(D.tag==="Leaf")return B;if(D.tag==="Node")return R(D._5,Ot("Cons",D._4,R(D._6,B)));g()},G=kt($t.foldr,R(z,qt)),I=G.length;return[...Tt(Tt(Dt(0,I-2|0))(D=>Tt(Dt(D+1|0,I-1|0))(B=>[b(D,B)])))(D=>D._1>=0&&D._1<G.length?D._2>=0&&D._2<G.length?G[D._1].splitPartner.tag!=="Nothing"&&G[D._1].splitPartner.tag==="Just"&&G[D._1].splitPartner._1===G[D._2].id||G[D._2].splitPartner.tag!=="Nothing"&&G[D._2].splitPartner.tag==="Just"&&G[D._2].splitPartner._1===G[D._1].id?[]:o(d,G[D._1],G[D._2]):[]:[]),...Tt(G)(D=>D.splitBy.tag==="Just"&&D.splitPartner.tag==="Just"&&(()=>{const B=Pt(D.splitPartner._1)(z);if(B.tag==="Nothing")return!1;if(B.tag==="Just")return!0;g()})()&&(()=>{const B=Pt(D.splitBy._1)(z);if(B.tag==="Nothing")return!1;if(B.tag==="Just")return!0;g()})()?[{src:D.id,tgt:D.splitBy._1,weight:1,kind:Do},{src:D.splitBy._1,tgt:D.splitPartner._1,weight:1,kind:Do}]:[])]})()}})(),m=h.segments,p=m.length,y=S=>{let C=S,U=!0,Y;for(;U;){const W=C,z=Xt(R=>{const G=Pt(R)(W.inWeight);if(G.tag==="Nothing")return!0;if(G.tag==="Just")return G._1===0;g()})(W.remaining);if(z.tag==="Nothing"){U=!1,Y=W;continue}if(z.tag==="Just"){const R=z._1;C={...W,inWeight:J(G=>I=>vt(it)(oe)(I.tgt)(-I.weight)(G))(W.inWeight)((()=>{const G=Pt(R)(W.depsBySrc);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()),marks:K(it)(R)(W.nextSource)(W.marks),nextSource:W.nextSource+1|0,outWeight:J(G=>I=>vt(it)(oe)(I.src)(-I.weight)(G))(W.outWeight)((()=>{const G=Pt(R)(W.depsByTgt);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()),remaining:at(G=>G!==R,W.remaining)};continue}g()}return Y},x=S=>{let C=S,U=!0,Y;for(;U;){const W=C,z=Xt(R=>{const G=Pt(R)(W.outWeight);if(G.tag==="Nothing")return!0;if(G.tag==="Just")return G._1===0;g()})(W.remaining);if(z.tag==="Nothing"){U=!1,Y=W;continue}if(z.tag==="Just"){const R=z._1;C={...W,inWeight:J(G=>I=>vt(it)(oe)(I.tgt)(-I.weight)(G))(W.inWeight)((()=>{const G=Pt(R)(W.depsBySrc);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()),marks:K(it)(R)(W.nextSink)(W.marks),nextSink:W.nextSink-1|0,outWeight:J(G=>I=>vt(it)(oe)(I.src)(-I.weight)(G))(W.outWeight)((()=>{const G=Pt(R)(W.depsByTgt);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()),remaining:at(G=>G!==R,W.remaining)};continue}g()}return Y},N=(S=>{let C=S,U=!0,Y;for(;U;){const W=y(x(C));if(W.remaining.length===0){U=!1,Y=O(z=>{const R=Pt(z.id)(W.marks),G=(()=>{if(R.tag==="Nothing")return z.id;if(R.tag==="Just")return R._1;g()})();return{...z,mark:G<p?(G+p|0)+1|0:G}})(m);continue}C=(()=>{const z=G=>{const I=Pt(G)(W.outWeight),D=Pt(G)(W.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},R=Lt(G=>I=>it.compare(z(I))(z(G)))(W.remaining);if(0<R.length){const G=R[0];return{...W,inWeight:J(I=>D=>vt(it)(oe)(D.tgt)(-D.weight)(I))(W.inWeight)((()=>{const I=Pt(G)(W.depsBySrc);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})()),marks:K(it)(G)(W.nextSource)(W.marks),nextSource:W.nextSource+1|0,outWeight:J(I=>D=>vt(it)(oe)(D.src)(-D.weight)(I))(W.outWeight)((()=>{const I=Pt(G)(W.depsByTgt);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})()),remaining:at(I=>I!==G,W.remaining)}}return W})()}return Y})({remaining:O(S=>S.id)(m),marks:A,inWeight:J(S=>C=>vt(it)(oe)(C.tgt)(C.weight)(S))(A)(h.deps),outWeight:J(S=>C=>vt(it)(oe)(C.src)(C.weight)(S))(A)(h.deps),depsBySrc:J(S=>C=>vt(it)(te)(C.src)([C])(S))(A)(h.deps),depsByTgt:J(S=>C=>vt(it)(te)(C.tgt)([C])(S))(A)(h.deps),nextSink:p-1|0,nextSource:p+1|0}),v=(()=>{const S=(()=>{const Y=Ar(O(W=>b(W.id,W.mark))(N));return{segments:N,deps:xt(W=>(()=>{if(W.kind==="Critical")return!0;if(W.kind==="Regular")return!1;g()})()?w("Just",W):(()=>{const z=Pt(W.src)(Y),R=Pt(W.tgt)(Y);return(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})()>(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})()})()?W.weight===0?T:w("Just",{src:W.tgt,tgt:W.src,weight:W.weight,kind:W.kind}):w("Just",W))(h.deps)}})(),C=J(Y=>W=>vt(it)(oe)(W.tgt)(1)(Y))(A)(S.deps),U=(Y=>{let W=Y,z=!0,R;for(;z;){const G=W,I=Bt(D=>T,D=>B=>w("Just",{head:D,tail:B}),G.queue);if(I.tag==="Nothing"){z=!1,R=G;continue}if(I.tag==="Just"){W=J((()=>{const D=Pt(I._1.head)(G.slots),B=(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;g()})();return q=>V=>{const $=Pt(V)(q.inDegree),X=(()=>{if($.tag==="Nothing")return-1;if($.tag==="Just")return $._1-1|0;g()})();return{...q,slots:K(it)(V)(Fg((()=>{const M=Pt(V)(q.slots);if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})())(B+1|0))(q.slots),inDegree:K(it)(V)(X)(q.inDegree),queue:X===0?[...q.queue,V]:q.queue}}})())({...G,queue:I._1.tail})((()=>{const D=Pt(I._1.head)(G.adj);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})());continue}g()}return R})({slots:Ar(O(Y=>b(Y.id,0))(S.segments)),inDegree:C,adj:J(Y=>W=>vt(it)(te)(W.src)([W.tgt])(Y))(A)(S.deps),queue:O(Y=>Y.id)(at(Y=>{const W=Pt(Y.id)(C);if(W.tag==="Nothing")return!0;if(W.tag==="Just")return W._1===0;g()},S.segments))});return Lt(Y=>W=>it.compare(Y.slot)(W.slot))(O(Y=>({...Y,slot:(()=>{const W=Pt(Y.id)(U.slots);if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})()}))(S.segments))})(),L=1+J(S=>C=>Fg(S)(C.slot))(0)(v)|0,k=Tt(v)(S=>S.members),E=at(S=>Qe(gn)(S.edge.id)(k),t),Q=J(ht)(-1e18)(O(S=>S.fromPos._2)(E)),H=J(dt)(1e18)(O(S=>S.toPos._2)(E));if(Q>H){const S=Ar(O(C=>b(C.id,C))(v));return Fe(O(C=>O(U=>b(U,{slot:C.slot,slotCount:L,gapTop:H,gapBottom:Q,partner:(()=>{if(C.splitPartner.tag==="Just"){const Y=Pt(C.splitPartner._1)(S);if(Y.tag==="Just")return w("Just",{slot:Y._1.slot,splitX:0<Y._1.incoming.length?Y._1.incoming[0]:0});if(Y.tag==="Nothing")return T;g()}if(C.splitPartner.tag==="Nothing")return T;g()})()}))(C.members))(at(C=>{if(C.splitPartner.tag==="Just"){const U=Pt(C.splitPartner._1)(S);return!(U.tag==="Just"&&(()=>{if(U._1.splitBy.tag==="Nothing")return!1;if(U._1.splitBy.tag==="Just")return!0;g()})())}if(C.splitPartner.tag==="Nothing")return!0;g()},v)))}const j=Ar(O(S=>b(S.id,S))(v));return Fe(O(S=>O(C=>b(C,{slot:S.slot,slotCount:L,gapTop:Q,gapBottom:H,partner:(()=>{if(S.splitPartner.tag==="Just"){const U=Pt(S.splitPartner._1)(j);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 T;g()}if(S.splitPartner.tag==="Nothing")return T;g()})()}))(S.members))(at(S=>{if(S.splitPartner.tag==="Just"){const C=Pt(S.splitPartner._1)(j);return!(C.tag==="Just"&&(()=>{if(C._1.splitBy.tag==="Nothing")return!1;if(C._1.splitBy.tag==="Just")return!0;g()})())}if(S.splitPartner.tag==="Nothing")return!0;g()},v)))})()))(A)($m(J(u=>s=>{const a=Br(s.edge.from.node)(n);if(a.tag==="Just"){const c=Br(s.edge.to.node)(n);return c.tag==="Just"&&a._1.layer!==c._1.layer?vt(it)(te)(Fr(a._1.layer)(c._1.layer))([s])(u):u}return u})(A)((()=>{const u=s=>b((()=>{const a=Br(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=Br(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return Lt(s=>a=>qm(u(s))(u(a)))(t)})())))},Vm=t=>e=>{const n=Qg(t)(e),r=J(i=>o=>K(P)(o.node)(o)(i))(A)(e);return J(i=>o=>{const u=Br(o.edge.from.node)(r);if(u.tag==="Just"){const s=Br(o.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=Xm(o.edge.id)(n);if(a.tag==="Just")return K(it)(Fr(u._1.layer)(s._1.layer))(a._1.slotCount)(i)}return i}return i})(A)(t)},zg=zt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),ce=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ge=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bi=t=>e=>n=>r=>zg(i=>n>=i.x&&n<i.x+i.w&&e>i.y&&t<i.y+i.h)(r),Ao=t=>e=>n=>r=>bi(ce(e)(n))(ge(e)(n))(r)(t),Bo=rt(4),Um=Oa(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()}),Li=Ha(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})())}),jm=t=>e=>n=>{const r=Bt(i=>T,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=Xi(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()},ki=t=>{const e=r=>i=>{const o=Bt(u=>T,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=Bt(r=>T,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()},Ei=t=>e=>n=>r=>zg(i=>n>=i.y&&n<i.y+i.h&&e>i.x&&t<i.x+i.w)(r),Ci=t=>e=>n=>r=>Ei(ce(e)(n))(ge(e)(n))(r)(t),Zm=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]):T;if(c.tag==="Just"){const f=n+1|0,d=f>=0&&f<e.length?w("Just",e[f]):T;if(d.tag==="Just"){const l=c._1.start._1===d._1.end._1&&(!a||c._1.direction==="V")&&(!s||d._1.direction==="V")&&!Ao(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:ne},...o]):T,_=c._1.start._2===d._1.end._2&&(!a||c._1.direction==="H")&&(!s||d._1.direction==="H")&&!Ci(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:ee},...o]):T;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return T;g()}if(c.tag==="Nothing")return T;g()},Km=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=Zm(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)},t2=t=>e=>n=>r=>{const i=(l,_,h)=>!Ao(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)=>!Ci(t)(ce(_)(h))(ge(_)(h))(l),d=n>=0&&n<e.length?w("Just",e[n]):T;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<e.length?w("Just",e[l]):T;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:ne},...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:ee},...u]):T,m=(!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:ne},{start:b(d._1.start._1,_._1.end._2),end:_._1.end,direction:ee},...u]):T,p=(!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:ee},{start:b(_._1.end._1,d._1.start._2),end:_._1.end,direction:ne},...u]):T,y=m.tag==="Nothing"?p:m;return h.tag==="Nothing"?y:h}if(_.tag==="Nothing")return T;g()}if(d.tag==="Nothing")return T;g()},e2=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=t2(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)},n2=t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r,s=ki(Li(Km(t)(e2(t)(u))));if(s.length<u.length){r=s;continue}i=!1,o=s}return o};return n=>e(ki(Li(n)))},r2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(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=Lt(c=>f=>st.compare(c.x)(f.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=Lt(a=>c=>st.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},i2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(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=Lt(c=>f=>st.compare(c.y)(f.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=Lt(a=>c=>st.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},o2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(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=Lt(c=>f=>st.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=Lt(a=>c=>st.compare(a.x)(c.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},u2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(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=Lt(c=>f=>st.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=Lt(a=>c=>st.compare(a.y)(c.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},Wg=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},Mg=t=>e=>n=>r=>i=>{const o=ce(e)(n),u=ge(e)(n);if(!bi(o)(u)(r)(t))return r;if(!bi(o)(u)(i)(t))return i;const s=(r+i)/2;return bi(o)(u)(s)(t)?Wg(a=>bi(o)(u)(a)(t))(s)(1):s},s2=t=>e=>n=>r=>i=>{const o=ce(e)(n),u=ge(e)(n);if(!Ei(o)(u)(r)(t))return r;if(!Ei(o)(u)(i)(t))return i;const s=(r+i)/2;return Ei(o)(u)(s)(t)?Wg(a=>Ei(o)(u)(a)(t))(s)(1):s},a2=t=>e=>n=>r=>{const i=ce(e)(n),o=ge(e)(n),u=at(c=>r>=c.x&&r<c.x+c.w&&c.y+c.h>i&&c.y<o,t),s=J(c=>f=>ge(c)(f.x+f.w+4))(r+4)(u),a=J(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},c2=t=>e=>n=>r=>{const i=ce(e)(n),o=ge(e)(n),u=at(c=>r>=c.y&&r<c.y+c.h&&c.x+c.w>i&&c.x<o,t),s=J(c=>f=>ge(c)(f.y+f.h+4))(r+4)(u),a=J(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},g2=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)=>!Ao(e)(ce(k)(E))(ge(k)(E))(L),f=(L,k,E)=>!Ao(n)(ce(k)(E))(ge(k)(E))(L),d=(L,k,E,Q)=>t.tag==="Just"&&!Ci(n)(ce(L)(k))(ge(L)(k))(t._1)?t._1:s2(e)(L)(k)(E)(Q),l=(L,k,E,Q)=>{if(L===E){const j=a2(e)(k)(Q)(L),S=i2(e)(L)(k)(Q),C=u2(e)(L)(k)(Q);return[{start:b(L,k),end:b(L,S),direction:ne},{start:b(L,S),end:b(j,S),direction:ee},{start:b(j,S),end:b(j,C),direction:ne},{start:b(j,C),end:b(E,C),direction:ee},{start:b(E,C),end:b(E,Q),direction:ne}]}const H=d(L,E,k,Q);return[{start:b(L,k),end:b(L,H),direction:ne},{start:b(L,H),end:b(E,H),direction:ee},{start:b(E,H),end:b(E,Q),direction:ne}]},_=(L,k,E,Q)=>{if(k===Q){const j=c2(e)(L)(E)(k),S=r2(e)(k)(L)(E),C=o2(e)(k)(L)(E);return[{start:b(L,k),end:b(S,k),direction:ee},{start:b(S,k),end:b(S,j),direction:ne},{start:b(S,j),end:b(C,j),direction:ee},{start:b(C,j),end:b(C,Q),direction:ne},{start:b(C,Q),end:b(E,Q),direction:ee}]}const H=Mg(e)(k)(Q)(L)(E);return[{start:b(L,k),end:b(H,k),direction:ee},{start:b(H,k),end:b(H,Q),direction:ne},{start:b(H,Q),end:b(E,Q),direction:ee}]},h=(L,k,E)=>!Ci(e)(ce(k)(E))(ge(k)(E))(L),m=(L,k,E)=>!Ci(n)(ce(k)(E))(ge(k)(E))(L),p=(L,k,E,Q)=>{if(m(k,L,E)&&f(E,k,Q))return[{start:b(L,k),end:b(E,k),direction:ee},{start:b(E,k),end:b(E,Q),direction:ne}];const H=Mg(e)(k)(Q)(L)(E);return[{start:b(L,k),end:b(H,k),direction:ee},{start:b(H,k),end:b(H,Q),direction:ne},{start:b(H,Q),end:b(E,Q),direction:ee}]},y=(L,k,E,Q)=>{if(f(L,k,Q)&&m(Q,L,E))return[{start:b(L,k),end:b(L,Q),direction:ne},{start:b(L,Q),end:b(E,Q),direction:ee}];const H=d(L,E,k,Q);return[{start:b(L,k),end:b(L,H),direction:ne},{start:b(L,H),end:b(E,H),direction:ee},{start:b(E,H),end:b(E,Q),direction:ne}]},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:ne}]: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:ne}]: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:ee}]:_(s._1,s._2,a._1,a._2):o==="North"||o==="South"?p(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:ee}]:_(s._1,s._2,a._1,a._2);if(o==="North"||o==="South")return p(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 ne;if(r==="East"||r==="West")return ee;g()})(),v={start:b(a._1,a._2),end:b(u._1,u._2),direction:(()=>{if(o==="South"||o==="North")return ne;if(o==="East"||o==="West")return ee;g()})()};return s._1===a._1&&s._2===a._2?[{start:b(i._1,i._2),end:b(u._1,u._2),direction:N}]:jm({start:b(i._1,i._2),end:b(s._1,s._2),direction:N})(x)(v)},f2=O(t=>({x:t.position._1*Bo-2,y:t.position._2*Bo-2,w:t.size._1*Bo+4,h:t.size._2*Bo+4})),Gs=Kt(P)(zt),In=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Ps=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},_2=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Hg=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()},Is=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()},Og=t=>e=>J(n=>r=>vt(t)(te)(e(r))([r])(n))(A),qg=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},$g=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,i=e.length;return i===0?A:Gs(i===1?O(o=>b(o,r))(e):At(o=>u=>b(u,t.lo+rt(o+1|0)*n/rt(i+1|0)))(e))},Yg=t=>e=>n=>r=>i=>{const o=Og(P)(_=>_.to.node)(t),u=Og(P)(_=>_.from.node)(t),s=J(_=>h=>K(P)(h.node)(h)(_))(A)(e),a=(_,h,m)=>{const p=In(_)(s);if(p.tag==="Nothing")return b(0,0);if(p.tag==="Just"){const y=In(_)(n);if(y.tag==="Nothing"){const x=rt(4);if(m==="South")return b(p._1.position._1*x+p._1.size._1*x/2,(p._1.position._2+p._1.size._2)*x);if(m==="North")return b(p._1.position._1*x+p._1.size._1*x/2,p._1.position._2*x);if(m==="East")return b((p._1.position._1+p._1.size._1)*x,p._1.position._2*x+p._1.size._2*x/2);if(m==="West")return b(p._1.position._1*x,p._1.position._2*x+p._1.size._2*x/2);g()}if(y.tag==="Just"){const x=Xt(N=>N.id===h)(y._1);if(x.tag==="Nothing"){const N=rt(4);if(m==="South")return b(p._1.position._1*N+p._1.size._1*N/2,(p._1.position._2+p._1.size._2)*N);if(m==="North")return b(p._1.position._1*N+p._1.size._1*N/2,p._1.position._2*N);if(m==="East")return b((p._1.position._1+p._1.size._1)*N,p._1.position._2*N+p._1.size._2*N/2);if(m==="West")return b(p._1.position._1*N,p._1.position._2*N+p._1.size._2*N/2);g()}if(x.tag==="Just"){const N=rt(4);if(x._1.side==="North")return b(p._1.position._1*N+rt(x._1.offset)*N,p._1.position._2*N);if(x._1.side==="South")return b(p._1.position._1*N+rt(x._1.offset)*N,(p._1.position._2+p._1.size._2)*N);if(x._1.side==="East")return b((p._1.position._1+p._1.size._1)*N,p._1.position._2*N+rt(x._1.offset)*N);if(x._1.side==="West")return b(p._1.position._1*N,p._1.position._2*N+rt(x._1.offset)*N)}}}g()},c=Gs(Tt(r)(_=>{if(_.nodes.length<=2)return[];const h=rt(4);if(1<_.nodes.length){const m=In(_.nodes[1])(s);if(m.tag==="Nothing")return[];if(m.tag==="Just"){const p=m._1.position._1*h+m._1.size._1*h/2;return O(y=>b(y,p))(Je(y=>x=>_.edgeId+":"+y+"->"+x,_.nodes,bt(1,_.nodes.length,_.nodes)))}g()}return[]})),f=_=>{const h=In(_.from.node)(s),m=In(_.to.node)(s);if(h.tag==="Just"&&m.tag==="Just"){const p=h._1,y=m._1,x=Lt(N=>v=>it.compare(N.score)(v.score))(O(N=>{const v=N._1,L=N._2;return{from:v,to:L,score:(()=>{const k=(j,S,C,U,Y)=>{const W=Is(j)(S),z=Is(j)(C);return W.lo<z.hi&&z.lo<W.hi&&(v==="South"?L==="North"&&Y._2>U._2:v==="North"?L==="South"&&Y._2<U._2:v==="East"?L==="West"&&Y._1>U._1:v==="West"&&L==="East"&&Y._1<U._1)?0:qg(v)(L)(U)(Y)},E=Hg(v)(p),Q=Hg(L)(y),H=qg(v)(L)(E)(Q);return(()=>{if(H>0){if(v==="South")return L==="North"?k(he,p,y,E,Q)*10|0:H*10|0;if(v==="North")return L==="South"?k(le,p,y,E,Q)*10|0:H*10|0;if(v==="East")return L==="West"?k(pn,p,y,E,Q)*10|0:H*10|0;if(v==="West"&&L==="East")return k(_r,p,y,E,Q)*10|0}return H*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(_r,le),b(he,pn),b(he,_r),b(le,he),b(le,pn),b(le,_r),b(pn,he),b(_r,he),b(pn,_r),b(_r,pn)]));if(0<x.length)return{from:x[0].from,to:x[0].to}}return{from:he,to:le}},d=Gs(O(_=>b(_.id,f(_)))(t)),l=(_,h,m,p,y,x)=>{const N=rt(4),v=In(h)(s);if(v.tag==="Nothing")return b(0,0);if(v.tag==="Just"){const L=_2(b(m,_))(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=Is(_)(v._1),E=(k.lo+k.hi)/2,Q=Ps(m)($g(k)(O(S=>S.id)(Lt(S=>C=>st.compare(y(_)(S))(y(_)(C)))(at(S=>{const C=Ps(S.id)(d);if(C.tag==="Just"){const U=x(C._1);return U==="North"?_==="North":U==="South"?_==="South":U==="East"?_==="East":U==="West"&&_==="West"}if(C.tag==="Nothing")return!0;g()},(()=>{const S=In(h)(p);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()))))),H=(()=>{if(Q.tag==="Nothing")return E;if(Q.tag==="Just")return Q._1;g()})(),j=rt(4);if(_==="South")return b(H,(v._1.position._2+v._1.size._2)*j);if(_==="North")return b(H,v._1.position._2*j);if(_==="East")return b((v._1.position._1+v._1.size._1)*j,H);if(_==="West")return b(v._1.position._1*j,H)}}g()};return O(_=>{const h=Ps(_.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()})(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,m=>p=>{const y=In(p.to.node)(s);if(y.tag==="Nothing")return 0;if(y.tag==="Just"){const x=rt(4);if(m==="South"||m==="North")return y._1.position._1*x+y._1.size._1*x/2;if(m==="East"||m==="West")return y._1.position._2*x+y._1.size._2*x/2}g()},m=>m.from),toPos:l(h.to,_.to.node,_.id,o,m=>p=>{const y=In(p.from.node)(s);if(y.tag==="Nothing")return 0;if(y.tag==="Just"){const x=rt(4);if(m==="South"||m==="North")return y._1.position._1*x+y._1.size._1*x/2;if(m==="East"||m==="West")return y._1.position._2*x+y._1.size._2*x/2}g()},m=>m.to),fromSide:h.from,toSide:h.to}})(t))},Xg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},d2=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),Ds=t=>e=>t.gapTop+1*rt(4)+rt(e)*2.5*rt(4),l2=t=>e=>{const n=Xg(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return w("Just",{slot1Y:Ds(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Ds(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return T;g()}if(n.tag==="Nothing")return T;g()},h2=t=>e=>{const n=J(r=>i=>K(P)(i.node)(i)(r))(A)(e);return Fe(At(r=>i=>{const o=Rr(i.node)(n);if(o.tag==="Nothing")return[];if(o.tag==="Just"){const u=o._1;return At(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),m=l+_*rt(c-s|0)/h,p=l+_*rt((c+1|0)+s|0)/h,y=d-f*2.5*rt(s+1|0),x=[{start:b(d,m),end:b(y,m),direction:ee},{start:b(y,m),end:b(y,p),direction:ne},{start:b(y,p),end:b(d,p),direction:ee}];return{edge:a.id,segments:x,bends:Je(N=>v=>N.end,x,bt(1,3,x)),bendType:[],jumps:[],reversed:!1}})(i.edges)}g()})(O(r=>({node:r._1,edges:r._2}))(d2(J(r=>i=>vt(P)(te)(i.from.node)([i])(r))(A)(t)))))},p2=t=>e=>{const n=J(o=>u=>K(P)(u.node)(u)(o))(A)(e),r=o=>{const u=Rr(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.position._1;g()},i=o=>{const u=Rr(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=st.compare(r(o.edge.from.node))(r(u.edge.from.node));return a==="EQ"?st.compare(r(o.edge.to.node))(r(u.edge.to.node)):a}return s})(t)},Ie=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}},m2=t=>t.from.node===t.to.node,y2=t=>e=>n=>r=>{const i=n2(n)(g2(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:i,bends:Je(o=>u=>o.end,i,bt(1,i.length,i)),bendType:[],jumps:[],reversed:!1}},x2=t=>e=>n=>r=>{const i=[{start:b(r.fromPos._1,r.fromPos._2),end:b(r.fromPos._1,t.slot1Y),direction:ne},{start:b(r.fromPos._1,t.slot1Y),end:b(t.splitX,t.slot1Y),direction:ee},{start:b(t.splitX,t.slot1Y),end:b(t.splitX,t.slot2Y),direction:ne},{start:b(t.splitX,t.slot2Y),end:b(r.toPos._1,t.slot2Y),direction:ee},{start:b(r.toPos._1,t.slot2Y),end:b(r.toPos._1,r.toPos._2),direction:ne}];return{edge:r.edge.id,segments:i,bends:Je(o=>u=>o.end,i,bt(1,5,i)),bendType:[],jumps:[],reversed:!1}},N2=t=>e=>n=>{const r=Rr(t.edge.from.node)(n);if(r.tag==="Just"){const o=Rr(t.edge.to.node)(n);return o.tag==="Just"?at(u=>!(u.h===Ie(r._1).h&&u.w===Ie(r._1).w&&u.x===Ie(r._1).x&&u.y===Ie(r._1).y)&&!(u.h===Ie(o._1).h&&u.w===Ie(o._1).w&&u.x===Ie(o._1).x&&u.y===Ie(o._1).y),e):at(u=>!(u.h===Ie(r._1).h&&u.w===Ie(r._1).w&&u.x===Ie(r._1).x&&u.y===Ie(r._1).y),e)}const i=Rr(t.edge.to.node)(n);return i.tag==="Just"?at(o=>!(o.h===Ie(i._1).h&&o.w===Ie(i._1).w&&o.x===Ie(i._1).x&&o.y===Ie(i._1).y),e):at(o=>!0,e)},J2=t=>e=>{const n=Xg(e.edge.id)(t);if(n.tag==="Just")return w("Just",Ds(n._1)(n._1.slot));if(n.tag==="Nothing")return T;g()},T2=t=>e=>n=>r=>i=>{const o=J(c=>f=>K(P)(f.node)(f)(c))(A)(e),u=f2(e),s=Yg(at(c=>c.from.node!==c.to.node,t))(e)(n)(r)(i),a=Qg(s)(e);return[...h2(at(m2,t))(e),...J(c=>f=>{const d=N2(f)(u)(o),l=[...d,...c.edgeObstacles],_=l2(a)(f),h=(()=>{if(_.tag==="Just")return x2(_._1)(d)(l)(f);if(_.tag==="Nothing")return y2(J2(a)(f))(d)(l)(f);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...Um(h.segments)]}})({results:[],edgeObstacles:[]})(p2(s)(e)).results]},Kn=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},tr=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},v2=t=>e=>n=>{if(t.start._1!==e.start._1)return T;const r=tr(Kn(t.start._2)(t.end._2))(Kn(e.start._2)(e.end._2)),i=Kn(tr(t.start._2)(t.end._2))(tr(e.start._2)(e.end._2));return r<i?w("Just",{position:b(t.start._1,(r+i)/2),crossingEdge:n}):T},w2=t=>e=>n=>{if(t.start._2!==e.start._2)return T;const r=tr(Kn(t.start._1)(t.end._1))(Kn(e.start._1)(e.end._1)),i=Kn(tr(t.start._1)(t.end._1))(tr(e.start._1)(e.end._1));return r<i?w("Just",{position:b((r+i)/2,t.start._2),crossingEdge:n}):T},b2=t=>e=>n=>{if(t.direction==="H")return w2(t)(e)(n);if(t.direction==="V")return v2(t)(e)(n);g()},L2=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=>xt(s=>b2(o)(s)(u.edge))(at(s=>s.direction==="H"?o.direction==="H":s.direction==="V"&&o.direction==="V",u.segments))))},k2=t=>e=>n=>e.start._1>Kn(t.start._1)(t.end._1)&&e.start._1<tr(t.start._1)(t.end._1)&&t.start._2>Kn(e.start._2)(e.end._2)&&t.start._2<tr(e.start._2)(e.end._2)?w("Just",{position:b(e.start._1,t.start._2),crossingEdge:n}):T,E2=t=>e=>Tt(at(n=>n.direction==="H",t.segments))(n=>Tt(e)(r=>xt(i=>k2(n)(i)(r.edge))(at(i=>i.direction==="V",r.segments)))),C2=t=>e=>n=>[...E2(e)(at(r=>r.edge!==e.edge,n)),...L2(t)(e)(n)],Vg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Ug=t=>me(3)(t)==="$d:",S2=t=>e=>n=>J(r=>i=>{const o=Vg(i.from.node)(t),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})(),s=Vg(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+":"+ie(l))(Dt(1,a-1|0)),d=[i.from.node,...f,i.to.node];return{...r,layers:J(l=>_=>{const h=_._2,m=Ma(u+_._1|0)(p=>[...p,h])(l);if(m.tag==="Nothing")return l;if(m.tag==="Just")return m._1;g()})(r.layers)(Je(Hn,Dt(1,a-1|0),f)),edges:[...r.edges,...Je(l=>_=>({id:c+":"+l+"->"+_,from:{node:l,port:i.from.port},to:{node:_,port:i.to.port}}),d,bt(1,d.length,d))],chains:[...r.chains,{edgeId:i.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),Fo=(()=>{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=P.compare(e._1)(n._1);if(r==="LT")return ye;if(r==="GT")return xe;if(e._2==="North")return n._2==="North"?Ge:ye;if(n._2==="North")return xe;if(e._2==="South")return n._2==="South"?Ge:ye;if(n._2==="South")return xe;if(e._2==="East")return n._2==="East"?Ge:ye;if(n._2==="East")return xe;if(e._2==="West"&&n._2==="West")return Ge;g()},Eq0:()=>t}})(),G2=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=Fo.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},P2=Kt(P)(zt),As=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},I2=Kt(Fo)(zt),jg=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),Qr=t=>e=>n=>r=>{const i=G2(b(e,n))(t);if(i.tag==="Nothing")return r;if(i.tag==="Just")return i._1;g()},Zg=t=>e=>n=>{const r=P2(Fe(O(u=>At(s=>a=>b(a,s))(u))(t))),i=(u,s)=>{if(u==="South"){const a=As(s.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()}if(u==="North"){const a=As(s.from.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()}return 0},o=u=>J(s=>a=>Ce(Fo.compare,Le,I2(O(c=>b(b(c._1,u),c._2))(jg($g({lo:0,hi:(()=>{const c=As(a._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return me(3)(a._1)==="$d:"?0:1;g()})()})(O(c=>c.id)(Lt(c=>f=>it.compare(i(u,c))(i(u,f)))(a._2)))))),s))(A)(jg(J(s=>a=>a.from.node===a.to.node?s:u==="South"?vt(P)(te)(a.from.node)([a])(s):u==="North"?vt(P)(te)(a.to.node)([a])(s):s)(A)(e)));return Ce(Fo.compare,Le,o(le),o(he))},Kg=t=>t,tf=t=>t,ef=t=>t,D2=J(t=>e=>K(P)(e)()(t))(A),A2=(()=>{const t=qe.unfoldr(e=>{if(e.tag==="Nil")return T;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,Ot("Cons",r._3,n(r._6,i)));g()};return n(e,qt)})())})(),ot=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},en=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Nn=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jn=Kt(P)(zt),Bs=Ua(P),Fs=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),B2=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},F2=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=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},nf=ef("VDown"),rf=ef("VUp"),R2=tf("ForwardPhase"),Q2=tf("StackPhase"),of=Kg("HRight"),uf=Kg("HLeft"),sf=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=P.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},z2=t=>e=>n=>{const r=J(u=>s=>vt(P)(oe)(s.tgt)(1)(u))(A)(t),i=A2(D2([...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,Ot("Cons",s._4,u(s._6,a)));g()};return kt($t.foldr,u(e,qt))})()])),o=J(u=>s=>vt(P)(te)(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,m=f,p=d,y=Bt(x=>T,x=>N=>w("Just",{head:x,tail:N}),h);if(y.tag==="Nothing"){l=!1,_=p;continue}if(y.tag==="Just"){const x=ot(y._1.head)(p),N=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})(),v=J(L=>k=>{const E=ot(k.target)(L.result),Q=N+k.sep,H=ot(k.target)(L.indeg),j=(()=>{if(H.tag==="Nothing")return-1;if(H.tag==="Just")return H._1-1|0;g()})();return{newQueue:j===0?[...L.newQueue,k.target]:L.newQueue,result:K(P)(k.target)((()=>{if(E.tag==="Nothing")return Q;if(E.tag==="Just"){if(n==="VDown")return en(E._1)(Q);if(n==="VUp")return Nn(E._1)(Q)}g()})())(L.result),indeg:K(P)(k.target)(j)(L.indeg)}})({newQueue:[],result:p,indeg:m})((()=>{const L=ot(y._1.head)(o);if(L.tag==="Nothing")return[];if(L.tag==="Just")return L._1;g()})());c=[...y._1.tail,...v.newQueue],f=v.indeg,d=v.result;continue}g()}return _})(at(u=>{const s=ot(u)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;g()},i))(r)(J(u=>s=>K(P)(s)(0)(u))(A)(i))},W2=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,Ot("Cons",o._4,e(o._6,u)));g()},n=kt($t.foldr,e(t,qt)),r=J(en)(999999)(n);if(r===0||n.length===0)return t;const i=o=>{if(o.tag==="Leaf")return A;if(o.tag==="Node")return Mt("Node",o._1,o._2,o._3,o._4-r,i(o._5),i(o._6));g()};return i(t)},af=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,Ot("Cons",o._4,e(o._6,u)));g()},n=e(t,qt),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=Nn(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=en(d)(l._1),a=l._2;continue}g()}return f};return r(-999999)(n)-i(999999)(n)},Si=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]),M2=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>{const d=(G,I,D)=>{const B=G.from.node===I?G.from.port:G.to.node===I?G.to.port:T;if(B.tag==="Just"){const q=ot(I)(i);if(q.tag==="Just"){const V=Xt($=>$.id===B._1)(q._1);if(V.tag==="Just"){const $=rt(V._1.offset)*rt(4);return D==="North"||D==="South"?$:0}if(V.tag==="Nothing"){const $=ot(I)(r),X=Qr(u)(G.id)(D)((()=>{if($.tag==="Nothing")return .5;if($.tag==="Just")return $._1._1/2;g()})());return D==="North"||D==="South"?X:0}g()}if(q.tag==="Nothing"){const V=ot(I)(r),$=Qr(u)(G.id)(D)((()=>{if(V.tag==="Nothing")return .5;if(V.tag==="Just")return V._1._1/2;g()})());return D==="North"||D==="South"?$:0}g()}if(B.tag==="Nothing"){const q=ot(I)(r),V=Qr(u)(G.id)(D)((()=>{if(q.tag==="Nothing")return .5;if(q.tag==="Just")return q._1._1/2;g()})());return D==="North"||D==="South"?V:0}g()},l=(G,I)=>{if(G.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()},_=(G,I,D)=>J(B=>q=>K(P)(q)((()=>{const V=ot(q)(B);if(V.tag==="Nothing")return 0+I;if(V.tag==="Just")return V._1+I;g()})())(B))(D)(Si(a)(G)),h=(()=>{if(f==="HRight")return n;if(f==="HLeft")return ke(n);g()})(),m=G=>{const I=ot(G)(r);if(I.tag==="Nothing")return 1;if(I.tag==="Just")return I._1._1;g()},p=Jn(Fe(At(G=>I=>O(D=>b(D,G))(I))(n))),y=(G,I)=>me(3)(G)==="$d:"&&me(3)(I)==="$d:"||me(3)(G)==="$d:"||me(3)(I)==="$d:"?10:rt(t.nodeGap),x=J(G=>I=>Bs(D=>w("Just",[...(()=>{if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})(),I]))(I.to.node)(G))(A)(o),N=J(G=>I=>Bs(D=>w("Just",[...(()=>{if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})(),I]))(I.from.node)(G))(A)(o),v=Fe(n),L=J(G=>I=>{const D=ot(I)(a.root),B=(()=>{if(D.tag==="Nothing")return I;if(D.tag==="Just")return D._1;g()})();return I===B?G:Bs(q=>w("Just",(()=>{if(q.tag==="Nothing")return!0;if(q.tag==="Just")return q._1;g()})()&&me(3)(I)==="$d:"))(B)(G)})(Jn(O(G=>b(G,!0))(Nr(P.compare)((()=>{const G=(I,D)=>{if(I.tag==="Leaf")return D;if(I.tag==="Node")return G(I._5,Ot("Cons",I._4,G(I._6,D)));g()};return kt($t.foldr,G(a.root,qt))})()))))(v),k=(G,I)=>{const D=G.free,B=ot(D)(a.root),q=(()=>{if(B.tag==="Nothing")return D;if(B.tag==="Just")return B._1;g()})(),V=ot(q)(L),$=(()=>{if(V.tag==="Nothing")return!0;if(V.tag==="Just")return V._1;g()})();return J(X=>M=>{if(X.edge.tag==="Just")return X;if(X.edge.tag==="Nothing"){if((()=>{const ct=ot(q)(I.su);return!$&&(()=>{const yt=ot(M.from.node)(p);return M.from.node!==M.to.node&&(()=>{const Et=ot(M.to.node)(p);return(()=>{if(yt.tag==="Nothing")return-1;if(yt.tag==="Just")return yt._1;g()})()===(()=>{if(Et.tag==="Nothing")return-1;if(Et.tag==="Just")return Et._1;g()})()})()})()||(()=>{if(ct.tag==="Nothing")return!1;if(ct.tag==="Just")return ct._1;g()})()})())return X;const et=M.from.node===D?M.to.node:M.from.node,tt=ot(et)(a.root),gt=(()=>{if(tt.tag==="Nothing")return et;if(tt.tag==="Just")return tt._1;g()})(),_t=gt!==q;return _t&&(()=>{const ct=ot(gt)(I.blockFinished);if(ct.tag==="Nothing")return!1;if(ct.tag==="Just")return ct._1;g()})()?{...X,edge:w("Just",M),hasEdges:!0}:{...X,hasEdges:X.hasEdges||_t}}g()})({edge:T,hasEdges:!1})((()=>{if(G.isRoot){if(f==="HRight"){const X=ot(D)(x);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()}if(f==="HLeft"){const X=ot(D)(N);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1}g()}if(f==="HRight"){const X=ot(D)(N);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()}if(f==="HLeft"){const X=ot(D)(x);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1}g()})())},E=(G,I,D,B)=>{const q=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),V={free:I,isRoot:D},$=k(V,B);if($.edge.tag==="Nothing")return $.hasEdges?{thresh:q,state:{...B,queue:[...B.queue,V]}}:{thresh:q,state:B};if($.edge.tag==="Just"){const X=$.edge._1.from.node===I?$.edge._1.to.node:$.edge._1.from.node;return{thresh:(()=>{const M=ot((()=>{const _t=ot(X)(a.root);if(_t.tag==="Nothing")return X;if(_t.tag==="Just")return _t._1;g()})())(B.x),et=ot(X)(s),tt=ot(I)(s),gt=(()=>{if(M.tag==="Just")return M._1;if(M.tag==="Nothing")return T;g()})();return(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()+(()=>{if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1;g()})()+d($.edge._1,X,(()=>{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(tt.tag==="Nothing")return 0;if(tt.tag==="Just")return tt._1;g()})()-d($.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:{...B,su:K(P)((()=>{const M=ot($.edge._1.from.node)(a.root);if(M.tag==="Nothing")return $.edge._1.from.node;if(M.tag==="Just")return M._1;g()})())(!0)(K(P)((()=>{const M=ot($.edge._1.to.node)(a.root);if(M.tag==="Nothing")return $.edge._1.to.node;if(M.tag==="Just")return M._1;g()})())(!0)(B.su))}}}g()},Q=(G,I,D,B)=>{const q=I===G,V=ot(I)(a.align),$=(()=>{if(V.tag==="Nothing")return I===G;if(V.tag==="Just")return V._1===G;g()})();if(!(q||$))return{thresh:D,state:B};const X=(()=>{if(c==="VDown")return q&&D<=-1e18;if(c==="VUp")return q&&D>=1e18;g()})()?E(G,I,!0,B):{thresh:D,state:B};return(()=>{if(c==="VDown")return X.thresh<=-1e18&&$;if(c==="VUp")return X.thresh>=1e18&&$;g()})()?E(G,I,!1,X.state):X},H=G=>I=>D=>{const B=ot(D)(e.nodeIndex),q=(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})(),V=Xt(tt=>Qe(gn)(D)(tt))(h),$=(()=>{if(V.tag==="Nothing")return[];if(V.tag==="Just")return V._1;g()})(),X=$.length;if((()=>{if(c==="VDown")return q<=0;if(c==="VUp")return q>=(X-1|0);g()})()){const tt=Q(G,D,I.thresh,I.st);return{...I,st:tt.state,thresh:tt.thresh}}const M=(()=>{if(c==="VDown")return q-1|0;if(c==="VUp")return q+1|0;g()})(),et=M>=0&&M<$.length?w("Just",$[M]):T;if(et.tag==="Nothing")return I;if(et.tag==="Just"){const tt=ot(et._1)(a.root),gt=(()=>{if(tt.tag==="Nothing")return et._1;if(tt.tag==="Just")return tt._1;g()})(),_t=Q(G,D,I.thresh,j(gt)(I.st)),ct=(()=>{const Vt=ot(G)(_t.state.sink);if(Vt.tag==="Nothing")return G===G;if(Vt.tag==="Just")return Vt._1===G;g()})()?{..._t.state,sink:K(P)(G)((()=>{const Vt=ot(gt)(_t.state.sink);if(Vt.tag==="Nothing")return gt;if(Vt.tag==="Just")return Vt._1;g()})())(_t.state.sink)}:_t.state,yt=ot(gt)(ct.sink),Et=(()=>{if(yt.tag==="Nothing")return gt;if(yt.tag==="Just")return yt._1;g()})(),Rt=ot(G)(ct.sink),pt=(()=>{if(Rt.tag==="Nothing")return G;if(Rt.tag==="Just")return Rt._1;g()})();if(pt===Et){const Vt=ot(gt)(ct.x),Pe=(()=>{if(Vt.tag==="Just")return Vt._1;if(Vt.tag==="Nothing")return T;g()})(),un=(()=>{if(Pe.tag==="Nothing")return 0;if(Pe.tag==="Just")return Pe._1;g()})(),Ne=ot(G)(ct.x),St=(()=>{if(Ne.tag==="Just")return Ne._1;if(Ne.tag==="Nothing")return T;g()})(),It=(()=>{if(St.tag==="Nothing")return 0;if(St.tag==="Just")return St._1;g()})(),je=y(D,et._1),Ze=ot(et._1)(s),kn=ot(D)(s),jr=(()=>{if(Ze.tag==="Nothing")return 0;if(Ze.tag==="Just")return Ze._1;g()})()-(()=>{if(kn.tag==="Nothing")return 0;if(kn.tag==="Just")return kn._1;g()})();if(c==="VDown"){const _n=Nn(un+jr+m(et._1)+je)(_t.thresh);return{st:{...ct,x:K(P)(G)(w("Just",I.initial?_n:Nn(It)(_n)))(ct.x)},initial:!1,thresh:_t.thresh}}if(c==="VUp"){const _n=en(un+jr-je-m(D))(_t.thresh);return{st:{...ct,x:K(P)(G)(w("Just",I.initial?_n:en(It)(_n)))(ct.x)},initial:!1,thresh:_t.thresh}}g()}const Qt=ot(gt)(ct.x),Jt=(()=>{if(Qt.tag==="Just")return Qt._1;if(Qt.tag==="Nothing")return T;g()})(),mt=(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})(),nt=ot(G)(ct.x),Z=(()=>{if(nt.tag==="Just")return nt._1;if(nt.tag==="Nothing")return T;g()})(),ut=(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})(),ft=rt(t.nodeGap),lt=ot(D)(s),Nt=ot(et._1)(s),Ht=(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()-(()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1;g()})();return{st:{...ct,classEdges:[...ct.classEdges,{src:pt,tgt:Et,sep:(()=>{if(c==="VDown")return ut+Ht-mt-m(et._1)-ft;if(c==="VUp")return ut+Ht+m(D)+ft-mt;g()})()}]},initial:I.initial,thresh:_t.thresh}}g()},j=G=>I=>{const D=ot(G)(I.x),B=(()=>{if(D.tag==="Just")return D._1;if(D.tag==="Nothing")return T;g()})();if(B.tag==="Just")return I;if(B.tag==="Nothing"){const q=J(H(G))({st:{...I,x:K(P)(G)(w("Just",0))(I.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})()})(Si(a)(G));return{...q.st,blockFinished:K(P)(G)(!0)(q.st.blockFinished)}}g()},S=J(G=>I=>J(D=>B=>{const q=ot(B)(a.root),V=(()=>{if(q.tag==="Nothing")return B;if(q.tag==="Just")return q._1;g()})();return V===B?j(V)(D):D})(G)((()=>{if(c==="VDown")return I;if(c==="VUp")return ke(I);g()})()))({x:Jn(O(G=>b(G,T))(v)),sink:Jn(O(G=>b(G,G))(v)),classEdges:[],su:A,blockFinished:A,queue:[]})(h),C=z2(S.classEdges)(S.sink)(c),U=(G,I,D,B)=>{const q=ot(I)(B),V=ot(I)(s);return(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;g()})()+(()=>{if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1;g()})()+d(G,I,D)},Y=Jn(O(G=>b(G,!0))(Nr(P.compare)((()=>{const G=(I,D)=>{if(I.tag==="Leaf")return D;if(I.tag==="Node")return G(I._5,Ot("Cons",I._4,G(I._6,D)));g()};return kt($t.foldr,G(a.root,qt))})()))),W=G=>I=>D=>{const B=k(D,{su:I.su,blockFinished:Y}),q={phase:G,ppFree:D.free,ppIsRoot:D.isRoot,edgeId:T,delta:0,avail:0,shift:0,freeSu:(()=>{const V=ot((()=>{const $=ot(D.free)(a.root);if($.tag==="Nothing")return D.free;if($.tag==="Just")return $._1;g()})())(I.su);if(V.tag==="Nothing")return!1;if(V.tag==="Just")return V._1;g()})(),hasEdges:B.hasEdges,candCount:(()=>{if(D.isRoot){if(f==="HRight"){const V=ot(D.free)(x);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length;g()}if(f==="HLeft"){const V=ot(D.free)(N);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length}g()}if(f==="HRight"){const V=ot(D.free)(N);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length;g()}if(f==="HLeft"){const V=ot(D.free)(x);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length}g()})()};if(B.edge.tag==="Nothing")return{...I,stack:[...I.stack,D],trace:[...I.trace,q],x:I.x};if(B.edge.tag==="Just"){const V=B.edge._1.from.node===D.free?b(B.edge._1.from.node,B.edge._1.to.node):b(B.edge._1.to.node,B.edge._1.from.node),$=U(B.edge._1,V._1,l(B.edge._1,V._1),I.x)-U(B.edge._1,V._2,l(B.edge._1,V._2),I.x),X=ot(V._1)(a.root),M=(()=>{if(X.tag==="Nothing")return V._1;if(X.tag==="Just")return X._1;g()})(),et={...q,edgeId:w("Just",B.edge._1.id),delta:$};if($>0&&$<1e300){const tt=J(ct=>yt=>{const Et=ot(yt)(p),Rt=(()=>{if(Et.tag==="Nothing")return-1;if(Et.tag==="Just")return Et._1;g()})();if(Rt>=0&&Rt<n.length){const Jt=n[Rt],mt=ot(yt)(e.nodeIndex),nt=(()=>{if(mt.tag==="Nothing")return-2;if(mt.tag==="Just")return mt._1-1|0;g()})();return nt>=0&&nt<Jt.length?en(ct)((()=>{const Z=ot(yt)(I.x),ut=ot(yt)(s),ft=ot(Jt[nt])(I.x),lt=ot(Jt[nt])(s);return(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()+(()=>{if(ut.tag==="Nothing")return 0;if(ut.tag==="Just")return ut._1;g()})()-((()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;g()})()+(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()+m(Jt[nt])+y(yt,Jt[nt]))})()):ct}const pt=ot(yt)(e.nodeIndex),Qt=(()=>{if(pt.tag==="Nothing")return-2;if(pt.tag==="Just")return pt._1-1|0;g()})();return Qt>=0&&Qt<0?en(ct)((()=>{const Jt=ot(yt)(I.x),mt=ot(yt)(s),nt=ot([][Qt])(I.x),Z=ot([][Qt])(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(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;g()})()+(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()+m([][Qt])+y(yt,[][Qt]))})()):ct})($)(Si(a)(M)),gt=tt>0?-tt:0,_t={...I,x:tt>0?_(M,gt,I.x):I.x,trace:[...I.trace,{...et,avail:tt,shift:gt}]};return tt>0?_t:{..._t,stack:[..._t.stack,D]}}if($<0&&-$<1e300){const tt=J(ct=>yt=>{const Et=ot(yt)(p),Rt=(()=>{if(Et.tag==="Nothing")return-1;if(Et.tag==="Just")return Et._1;g()})();if(Rt>=0&&Rt<n.length){const Jt=n[Rt],mt=ot(yt)(e.nodeIndex),nt=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1+1|0;g()})();return nt>=0&&nt<Jt.length?en(ct)((()=>{const Z=ot(Jt[nt])(I.x),ut=ot(Jt[nt])(s),ft=ot(yt)(I.x),lt=ot(yt)(s);return(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()+(()=>{if(ut.tag==="Nothing")return 0;if(ut.tag==="Just")return ut._1;g()})()-((()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;g()})()+(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()+m(yt)+y(yt,Jt[nt]))})()):ct}const pt=ot(yt)(e.nodeIndex),Qt=(()=>{if(pt.tag==="Nothing")return 0;if(pt.tag==="Just")return pt._1+1|0;g()})();return Qt>=0&&Qt<0?en(ct)((()=>{const Jt=ot([][Qt])(I.x),mt=ot([][Qt])(s),nt=ot(yt)(I.x),Z=ot(yt)(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(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;g()})()+(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()+m(yt)+y(yt,[][Qt]))})()):ct})(-$)(Si(a)(M)),gt=tt>0?tt:0,_t={...I,x:tt>0?_(M,gt,I.x):I.x,trace:[...I.trace,{...et,avail:tt,shift:gt}]};return tt>0?_t:{..._t,stack:[..._t.stack,D]}}return{...I,stack:[...I.stack,D],trace:[...I.trace,et],x:I.x}}g()},z=J(W(R2))({x:Jn(O(G=>b(G,(()=>{const I=ot(G)(a.root),D=(()=>{if(I.tag==="Nothing")return G;if(I.tag==="Just")return I._1;g()})(),B=ot(D)(S.x),q=ot((()=>{const $=ot(D)(S.sink);if($.tag==="Nothing")return D;if($.tag==="Just")return $._1;g()})())(C),V=(()=>{if(B.tag==="Just")return B._1;if(B.tag==="Nothing")return T;g()})();return(()=>{if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1;g()})()+(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;g()})()})()))(v)),su:S.su,stack:[],trace:[]})(S.queue),R=J(W(Q2))({...z,stack:[]})(ke(z.stack));return{x:R.x,queue:S.queue,trace:R.trace}},H2=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>M2(t)(e)(n)(r)(i)(o)(u)(s)(a)(c)(f).x,O2=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:T;if(_.tag==="Just"){const h=ot(c)(e);if(h.tag==="Just"){const m=Xt(p=>p.id===_._1)(h._1);if(m.tag==="Just"){const p=rt(m._1.offset)*rt(4);return f==="North"||f==="South"?p:0}if(m.tag==="Nothing"){const p=Qr(i)(a.id)(f)(l);return f==="North"||f==="South"?p:0}g()}if(h.tag==="Nothing"){const m=Qr(i)(a.id)(f)(l);return f==="North"||f==="South"?m:0}g()}if(_.tag==="Nothing"){const h=Qr(i)(a.id)(f)(l);return f==="North"||f==="South"?h:0}g()},s=a=>c=>f=>d=>{let l=a,_=c,h=f,m=d,p=!0,y;for(;p;){const x=l,N=_,v=h,L=Bt(k=>T,k=>E=>w("Just",{head:k,tail:E}),m);if(L.tag==="Nothing"){p=!1,y=x;continue}if(L.tag==="Just"){const k=L._1.head,E=Xt(H=>H.from.node===v&&H.to.node===k||H.from.node===k&&H.to.node===v)(r),Q=(()=>{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=K(P)(k)(Q)(x),_=Q,h=k,m=L._1.tail;continue}g()}return y};return J(a=>c=>{const f=Bt(_=>T,_=>h=>w("Just",{head:_,tail:h}),Si(t)(c)),d=(()=>{if(f.tag==="Nothing")return K(P)(c)(0)(A);if(f.tag==="Just")return s(K(P)(f._1.head)(0)(A))(0)(f._1.head)(f._1.tail);g()})(),l=J(_=>h=>Nn(_)(-h._2))(0)(Fs(d));return J(_=>h=>K(P)(h._1)(h._2+l)(_))(a)(Fs(d))})(A)(Nr(P.compare)((()=>{const a=(c,f)=>{if(c.tag==="Leaf")return f;if(c.tag==="Node")return a(c._5,Ot("Cons",c._4,a(c._6,f)));g()};return kt($t.foldr,a(t.root,qt))})()))},q2=t=>e=>{const n=(i,o,u)=>me(3)(o)==="$d:"&&Wa(Ug,(()=>{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,m=f,p=!0,y;for(;p;){const x=d,N=l,v=_,L=h,k=m,E=N.length;if(k>=E){p=!1,y=x;continue}const Q=k>=0&&k<N.length?w("Just",N[k]):T,H=(()=>{if(Q.tag==="Nothing")return"";if(Q.tag==="Just")return Q._1;g()})(),j=n(t,H);if(k===(E-1|0)||j){const S=(()=>{if(j){const C=ot(H)(t.preds),U=(()=>{if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;g()})();if(0<U.length){const Y=v-1|0,W=ot(U[0])(t.nodeIndex);if(W.tag==="Nothing")return Y;if(W.tag==="Just")return W._1;g()}}return v-1|0})();d=J(C=>U=>{if(U>=0&&U<N.length){const Y=N[U];return n(t,Y)?C:J(W=>z=>{const R=ot(z)(t.nodeIndex),G=(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})();return G<L||G>S?K(P)(z+"\u2192"+Y)()(W):W})(C)((()=>{const W=ot(Y)(t.preds);if(W.tag==="Nothing")return[];if(W.tag==="Just")return W._1;g()})())}return n(t,"")?C:J(Y=>W=>{const z=ot(W)(t.nodeIndex),R=(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})();return R<L||R>S?K(P)(W+"\u2192")()(Y):Y})(C)((()=>{const Y=ot("")(t.preds);if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1;g()})())})(x)(Dt(0,k)),l=N,_=v,h=S,m=k+1|0;continue}d=x,l=N,_=v,h=L,m=k+1|0}return y};return e.length<3?A:J(i=>o=>{if(o>=0&&o<e.length){const u=e[o];return r(i)((()=>{const s=o+1|0;return s>=0&&s<e.length?e[s]:[]})())(u)(u.length)(o)(0)(0)}return r(i)((()=>{const u=o+1|0;return u>=0&&u<e.length?e[u]:[]})())([])(0)(o)(0)(0)})(A)(Dt(1,e.length-2|0))},$2=t=>e=>n=>r=>i=>{const o=Fe(e),u=J(s=>a=>{const c=J(f=>d=>{const l=(()=>{if(i==="HRight"){const p=ot(d)(t.preds);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;g()}if(i==="HLeft"){const p=ot(d)(t.succs);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1}g()})(),_=l.length;if(_===0)return f;const h=En(_-1|0,2),m=En(_,2);return J(p=>y=>{if((()=>{const x=ot(d)(p.align);if(x.tag==="Nothing")return d!==d;if(x.tag==="Just")return x._1!==d;g()})())return p;if(y>=0&&y<l.length){const x=ot(l[y])(t.nodeIndex),N=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})();if(!(sf(l[y]+"\u2192"+d)(n)||sf(d+"\u2192"+l[y])(n))&&(()=>{if(r==="VDown")return p.r<N;if(r==="VUp")return p.r>N;g()})()){const v=ot(l[y])(p.root),L=(()=>{if(v.tag==="Nothing")return l[y];if(v.tag==="Just")return v._1;g()})();return{root:K(P)(d)(L)(p.root),align:K(P)(l[y])(d)(K(P)(d)(L)(p.align)),r:N}}}return p})(f)((()=>{if(r==="VDown")return Dt(h,m);if(r==="VUp")return ke(Dt(h,m));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 ke(a);g()})());return{root:c.root,align:c.align}})({root:Jn(O(s=>b(s,s))(o)),align:Jn(O(s=>b(s,s))(o))})((()=>{if(i==="HRight")return e;if(i==="HLeft")return ke(e);g()})());return{root:u.root,align:u.align}},Ro=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>{const f=$2(e)(n)(s)(a)(c),d=O2(f)(i)(r)(o)(u)(c);return Nd()(l=>_=>w("Just",(()=>{const h=ot(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;g()})()))(H2(t)(e)(n)(r)(i)(o)(u)(d)(f)(a)(c))},cf=t=>e=>At(n=>r=>J(i=>o=>o>=0&&o<e.length?o>=0&&o<t.length?i+e[o]+t[o]:i+e[o]+0:o>=0&&o<t.length?i+1+t[o]:i+1)(0)((()=>{const i=Dt(0,e.length-1|0);return n<1?[]:bt(0,n,i)})()))(e),Y2=t=>e=>n=>r=>i=>o=>u=>{const s=B2(0)(e.length-1|0),a=rt(t.layerGap),c=u(id(s,a)),f=Vm(Yg(i)(c)(r)(o)(A))(c);return O(d=>{const l=F2(d)(f);return l.tag==="Just"&&l._1>0?Nn(a)(2+rt(l._1-1|0)*2.5):a})(Dt(0,s-1|0))},gf=t=>e=>n=>r=>Wa(i=>J(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),X2=t=>e=>n=>r=>{const i=Lt(o=>u=>st.compare(o.w)(u.w))(O(o=>({l:o,w:af(o)}))(at(gf()(e)(n),r)));return 0<i.length?w("Just",i[0].l):T},V2=t=>e=>{const n=Jn(Fe(O(At(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 A;if(o.tag==="Node")return Mt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(J(o=>u=>vt(P)(te)(u.to.node)([u.from.node])(o))(A)(e))})(),succs:(()=>{const i=o=>{if(o.tag==="Leaf")return A;if(o.tag==="Node")return Mt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(J(o=>u=>vt(P)(te)(u.from.node)([u.to.node])(o))(A)(e))})(),nodeIndex:n}},U2=t=>e=>{const n=Lt(d=>l=>st.compare(d.w)(l.w))(At(d=>l=>({i:d,l,w:af(l)}))(e)),r=0<n.length?w("Just",n[0]):T,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]):T,u=(()=>{if(o.tag==="Just")return(d=>l=>{let _=d,h=l,m=!0,p;for(;m;){const y=_,x=h;if(x.tag==="Nil"){m=!1,p=y;continue}if(x.tag==="Cons"){_=en(y)(x._1),h=x._2;continue}g()}return p})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,Ot("Cons",l._4,d(l._6,_)));g()};return d(o._1,qt)})());if(o.tag==="Nothing")return 0;g()})(),s=d=>J(l=>_=>Nn(l)((()=>{const h=ot(_._1)(t);if(h.tag==="Nothing")return _._2+1;if(h.tag==="Just")return _._2+h._1._1;g()})()))(-999999)(Fs(d)),a=i>=0&&i<e.length?w("Just",e[i]):T,c=(()=>{if(a.tag==="Just")return s(a._1);if(a.tag==="Nothing")return 0;g()})(),f=Je(d=>l=>{const _=h=>{if(h.tag==="Leaf")return A;if(h.tag==="Node")return Mt("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));g()};return _(d)},e,At(d=>l=>Xn(d)(2)===0?u-(_=>h=>{let m=_,p=h,y=!0,x;for(;y;){const N=m,v=p;if(v.tag==="Nil"){y=!1,x=N;continue}if(v.tag==="Cons"){m=en(N)(v._1),p=v._2;continue}g()}return x})(999999)((()=>{const _=(h,m)=>{if(h.tag==="Leaf")return m;if(h.tag==="Node")return _(h._5,Ot("Cons",h._4,_(h._6,m)));g()};return _(l,qt)})()):c-s(l))(e));return W2(J(d=>l=>{const _=Lt(st.compare)(xt(ot(l))(f));return K(P)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(A)(Nr(P.compare)(Fe(O(d=>{const l=_=>{if(_.tag==="Leaf")return A;if(_.tag==="Node")return Mt("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));g()};return kt(We.foldr,l(d))})(f)))))},j2=t=>e=>n=>r=>i=>o=>{const u=V2(e)(i),s=q2(u)(e),a={nodeGap:t.nodeGap*4|0},c=Ce(P.compare,Le,Jn(O(_=>b(_,b(1,1)))(at(Ug,Fe(e)))),(()=>{const _=h=>{if(h.tag==="Leaf")return A;if(h.tag==="Node")return Mt("Node",h._1,h._2,h._3,b(h._4._1*rt(4),h._4._2),_(h._5),_(h._6));g()};return _(n)})()),f=[Ro(a)(u)(e)(c)(r)(i)(o)(s)(nf)(of),Ro(a)(u)(e)(c)(r)(i)(o)(s)(rf)(of),Ro(a)(u)(e)(c)(r)(i)(o)(s)(nf)(uf),Ro(a)(u)(e)(c)(r)(i)(o)(s)(rf)(uf)],d=U2(c)(f);if(gf()(e)(c)(d))return d;const l=X2()(e)(c)(f);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return f[0];g()},Z2=t=>e=>n=>r=>{const i=Fa(T,Ga,o=>o.node===e?w("Just",o.position):T,t);if(i.tag==="Nothing")return t;if(i.tag==="Just"){const o=i._1;return O(u=>u.node===n?{...u,position:b(o._1+r._1,o._2+r._2)}:u)(t)}g()},K2=t=>e=>n=>r=>{const i=at(u=>Qe(gn)(u.node)(e),t),o=(()=>{if(n==="Vertical"){if(r==="Start")return J(u=>s=>en(u)(s.position._1))(99999)(i);if(r==="End")return J(u=>s=>Nn(u)(s.position._1))(0)(i);if(r==="Center"){const u=J(s=>a=>s+a.position._1)(0)(i);return i.length===0?0:u/rt(i.length)}g()}if(n==="Horizontal"){if(r==="Start")return J(u=>s=>en(u)(s.position._2))(99999)(i);if(r==="End")return J(u=>s=>Nn(u)(s.position._2))(0)(i);if(r==="Center"){const u=J(s=>a=>s+a.position._2)(0)(i);return i.length===0?0:u/rt(i.length)}}g()})();return O(u=>{if(Qe(gn)(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)},ty=t=>e=>J(n=>r=>r.tag==="AlignGroup"?K2(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?Z2(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),ey=t=>e=>n=>r=>i=>o=>u=>s=>{const a=O(d=>J(l=>_=>Nn(l)((()=>{const h=ot(_)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;g()})()))(1)(d))(n),c=j2(t)(n)(r)(i)(o)(s),f=cf(Y2(t)(n)(r)(i)(o)(u)(d=>{const l=cf(d)(a);return Fe(At(_=>h=>At(m=>p=>({node:p,position:b((()=>{const y=ot(p)(c);return(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;g()})()/rt(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const y=me(3)(p)==="$d:"?b(0,1):b(1,1),x=ot(p)(r);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;g()})(),layer:_,order:m}))(h))(n))}))(a);return ty(e)(Fe(At(d=>l=>At(_=>h=>({node:h,position:b((()=>{const m=ot(h)(c);return(()=>{if(m.tag==="Nothing")return 0;if(m.tag==="Just")return m._1;g()})()/rt(4)})(),d>=0&&d<f.length?f[d]:0),size:(()=>{const m=me(3)(h)==="$d:"?b(0,1):b(1,1),p=ot(h)(r);if(p.tag==="Nothing")return m;if(p.tag==="Just")return p._1;g()})(),layer:d,order:_}))(l))(n)))},Rs=Hu(uo)(gr(32)),ff=Hu(uo)(gr(31)),Gi=(()=>{const t=ml("25214903917");if(t.tag==="Nothing")return oc;if(t.tag==="Just")return t._1;g()})(),Pi=Mu(Hu(uo)(gr(48)))(uo),ny=t=>{const e=yl(t);return gi(uc((()=>{if(e.tag==="Nothing")return oc;if(e.tag==="Just")return e._1;g()})())(Gi))(Pi)},Qs=gr(11),Qo=t=>e=>{const n=gi(io(oo(e)(Gi))(Qs))(Pi);return b((()=>{const r=Ya(dl(Ou(n)(gr(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},ry=t=>{const e=Qo(26)(t),n=Qo(27)(e._2);return b((rt(e._1)*bu(2)(27)+rt(n._1))/bu(2)(53),n._2)},iy=t=>e=>{const n=J(r=>i=>{const o=ry(r.finalR);return{rs:[...r.rs,o._1],finalR:o._2}})({rs:[],finalR:t})(e);return b(O(r=>r.x)(Lt(r=>i=>st.compare(r.k)(i.k))(Je(r=>i=>({x:r,k:i}),e,n.rs))),n.finalR)},oy=t=>{const e=gi(io(oo(t)(Gi))(Qs))(Pi),n=gi(io(oo(e)(Gi))(Qs))(Pi);return b(io(oo((()=>{const r=Ou(e)(gr(16));return sc.compare(r)(ff)!=="LT"?Mu(r)(Rs):r})())(Rs))((()=>{const r=Ou(n)(gr(16));return sc.compare(r)(ff)!=="LT"?Mu(r)(Rs):r})()),n)},Ii=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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=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=P.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},zs=Kt(P)(zt),zr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Wo=Kt(P)(zt),uy=vu(ti),sy=J(Tr)(0),ay=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},_f=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=P.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},cy=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const i=qn(Yt,T,t,n[e],n);if(i.tag==="Just")return qn(Yt,T,e,r,i._1);if(i.tag==="Nothing")return T;g()}}return T},gy=t=>e=>n=>r=>i=>zs(J(o=>u=>{const s=Lt(a=>c=>it.compare((()=>{const f=Ii(a.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})())((()=>{const f=Ii(c.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})()))(at(a=>zo(a.to.node)(n),at(a=>a.from.node===u,r)));return{ranks:[...o.ranks,...At(a=>c=>b(c.id,rt((o.rankSum+a|0)+1|0)))(s)],rankSum:o.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),fy=t=>e=>n=>r=>i=>zs(J(o=>u=>{const s=Lt(c=>f=>{const d=it.compare((()=>{const l=zr(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=zr(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=Ii(c.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})())((()=>{const l=Ii(f.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})()):d})(at(c=>zo(c.from.node)(n),at(c=>c.to.node===u,r))),a=s.length;return{ranks:[...o.ranks,...At(c=>f=>b(f.id,rt((o.rankSum+a|0)-c|0)))(s)],rankSum:o.rankSum+a|0}})({ranks:[],rankSum:0})(t).ranks),Ws=t=>e=>n=>{const r=Wo(At(s=>a=>b(a,s))(t)),i=Wo(At(s=>a=>b(a,s))(e)),o=xt(s=>{const a=zr(s.from.node)(r),c=zr(s.to.node)(i);if(a.tag==="Just"&&c.tag==="Just")return w("Just",b(a._1,c._1));const f=zr(s.from.node)(i),d=zr(s.to.node)(r);return f.tag==="Just"&&d.tag==="Just"?w("Just",b(d._1,f._1)):T})(n),u=o.length;return J(s=>a=>J(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))},_y=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],m=d[_];if(Re(N=>N.before===h&&N.after===m,r)){s=d,a=l+1|0;continue}const p=qn(Yt,T,l,m,d),y=(()=>{if(p.tag==="Just")return qn(Yt,T,l+1|0,h,p._1);if(p.tag==="Nothing")return T;g()})(),x=(()=>{if(y.tag==="Nothing")return d;if(y.tag==="Just")return y._1;g()})();if(Ws(e)(x)(n)<Ws(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(uy(f)(c)){s=!1,a=c;continue}u=f}return a})(t)},Mo=t=>e=>J(n=>r=>{if(r>=0&&r<t.length){const i=t[r],o=r+1|0;if(o>=0&&o<t.length)return n+Ws(i)(t[o])(e)|0}return n})(0)(Dt(0,t.length-2|0)),dy=(()=>{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 m=cy(_-1|0)(_)(l);if(m.tag==="Just"){a=m._1,c=_-1|0;continue}if(m.tag==="Nothing"){f=!1,d=l;continue}g()}f=!1,d=l;continue}f=!1,d=l}return d};return J(u=>s=>o(u)(s))(e)(Dt(1,e.length-1|0))}const n=En(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,m=f;if(h>=0&&h<r.length){if(m>=0&&m<i.length){if(r[h].key>i[m].key){a=Ft(_)(i[m]),c=h,f=m+1|0;continue}a=Ft(_)(r[h]),c=h+1|0,f=m;continue}d=!1,l=[..._,...h<1?r:bt(h,r.length,r)];continue}d=!1,l=[..._,...m<1?i:bt(m,i.length,i)]}return l})([])(0)(0)};return t})(),ly=t=>e=>n=>{const r=xt(c=>c.tag==="OrderConstraint"?w("Just",{before:c._1.before,after:c._1.after}):T)(t.constraints),i=c=>J(f=>d=>{const l=d.after,_=d.before,h=On(Yt,T,p=>p===_,f),m=On(Yt,T,p=>p===l,f);if(h.tag==="Just"&&m.tag==="Just"&&h._1>m._1){const p=za(Yt,T,h._1,f),y=(()=>{if(p.tag==="Nothing")return f;if(p.tag==="Just")return p._1;g()})(),x=Qa(Yt,T,m._1,_,y);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;g()}return f})(c)(r),o=zs(At(c=>f=>b(f.id,c))(n)),u=(c,f,d)=>{const l=c.length;return J(_=>h=>{const m=f?h-1|0:h+1|0,p=m>=0&&m<_._1.length?w("Just",_._1[m]):T;if(p.tag==="Just"){const y=h>=0&&h<_._1.length?w("Just",_._1[h]):T;if(y.tag==="Just"){const x=Wo(At(E=>Q=>b(Q,E))(p._1)),N=Wo(At(E=>Q=>b(Q,E))(y._1)),v=f?gy(p._1)(x)(N)(n)(o):fy(p._1)(x)(N)(n)(o),L=J(E=>Q=>{const H=xt(S=>Ii(S.id)(v))(at(f?S=>S.to.node===Q._2&&zo(S.from.node)(x):S=>S.from.node===Q._2&&zo(S.to.node)(x),n));if(H.length===0)return{...E,items:[...E.items,{n:Q._2,key:T,origIdx:Q._1}]};const j=Qo(24)(E.r);return{items:[...E.items,{n:Q._2,key:w("Just",(sy(H)+(rt(j._1)*4172325152040912e-24-.03500000014901161))/rt(H.length)),origIdx:Q._1}],r:j._2}})({items:[],r:_._2})(At(Hn)(y._1)),k=qn(Yt,T,h,_y(i(O(E=>E.n)(dy((()=>{const E=L.items,Q=H=>j=>{let S=H,C=j,U=!0,Y;for(;U;){const W=S,z=C;if(W>=0&&W<E.length){if(E[W].key.tag==="Just"){U=!1,Y=E[W].key._1;continue}if(E[W].key.tag==="Nothing"){S=W+1|0,C=z;continue}g()}U=!1,Y=z}return Y};return(H=>j=>S=>{let C=H,U=j,Y=S,W=!0,z;for(;W;){const R=C,G=U,I=Y;if(R>=0&&R<E.length){if(E[R].key.tag==="Just"){C=R+1|0,U=E[R].key._1,Y=[...I,{n:E[R].n,key:E[R].key._1,origIdx:E[R].origIdx}];continue}if(E[R].key.tag==="Nothing"){const D=(G+Q(R+1|0)(G+1))/2;C=R+1|0,U=D,Y=[...I,{n:E[R].n,key:D,origIdx:E[R].origIdx}];continue}g()}W=!1,z=I}return z})(0)(-1)([])})()))))(p._1)(n)(r),_._1);if(k.tag==="Just")return b(k._1,L.r);if(k.tag==="Nothing")return b(_._1,_._2);g()}if(y.tag==="Nothing")return b(_._1,_._2);g()}if(p.tag==="Nothing")return b(_._1,_._2);g()})(b(c,d))(f?Dt(1,l-1|0):ke(Dt(0,l-2|0)))},s=J(c=>f=>K(P)(f.from.node)()(K(P)(f.to.node)()(c)))(A)(n),a=J(c=>f=>{if(c.result.crossings===0)return c;const d=x=>N=>v=>L=>{let k=x,E=N,Q=v,H=L,j=!0,S;for(;j;){const C=k,U=E,Y=Q,W=H;if(Y===0){j=!1,S={layout:C,crossings:0,random:W};continue}const z=u(C,U,W),R=Mo(z._1)(n);if(R<Y){k=z._1,E=!U,Q=R,H=z._2;continue}j=!1,S={layout:C,crossings:Y,random:z._2}}return S},l=Qo(1)(c.result.random),_=l._1!==0,h=t.modelOrder.tag==="Leaf",m=(c.firstTry||c.secondTry)&&!h?c.firstTry:_,p=(()=>{if(!h){const L=u(e,m,l._2);return d(L._1)(!m)(Mo(L._1)(n))(L._2)}const x=m?0:ay(0)(e.length-1|0),N=x>=0&&x<e.length?w("Just",e[x]):T;if(N.tag==="Just"&&N._1.length>1){const L=at(k=>_f(k)(s),N._1);if(L.length>1){const k=iy(l._2)(L),E=k._1,Q=qn(Yt,T,x,i(J(H=>j=>_f(j)(s)?H.idx>=0&&H.idx<E.length?{idx:H.idx+1|0,result:[...H.result,E[H.idx]]}:{idx:H.idx,result:[...H.result,j]}:{idx:H.idx,result:[...H.result,j]})({idx:0,result:[]})(N._1).result),e);if(Q.tag==="Just"){const H=u(Q._1,m,k._2);return d(H._1)(!m)(Mo(H._1)(n))(H._2)}}}const v=u(e,m,l._2);return d(v._1)(!m)(Mo(v._1)(n))(v._2)})(),y=c.secondTry?!1:c.secondTry;return c.firstTry?{result:p.crossings<c.result.crossings?{layout:p.layout,crossings:p.crossings,random:p.random}:{...c.result,random:p.random},firstTry:!1,secondTry:!0}:{result:p.crossings<c.result.crossings?{layout:p.layout,crossings:p.crossings,random:p.random}:{...c.result,random:p.random},firstTry:c.firstTry,secondTry:y}})({result:{layout:e,crossings:1e9,random:gi(uc(oy(ny(1))._1)(Gi))(Pi)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Dt(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:a.layout},hy=t=>t,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=P.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},De=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Wr=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=P.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},Di=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=P.compare(e._1)(n._1);return r==="LT"?ye:r==="GT"?xe:P.compare(e._2)(n._2)},Eq0:()=>t}})(),py=Kt(P)(zt),my=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=Di.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=hy("Greedy"),Ms=t=>e=>n=>J(r=>i=>{if(i.from.node===i.to.node)return r;if(i.from.node===e&&!df(i.to.node)(r.marks)){const o=De(i.to.node)(r.inDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;g()})(),s=K(P)(i.to.node)(u)(r.inDeg);return(()=>{const a=De(i.to.node)(r.outDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!Qe(gn)(i.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,i.to.node]}:{...r,inDeg:s}}if(i.to.node===e&&!df(i.from.node)(r.marks)){const o=De(i.from.node)(r.outDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;g()})(),s=K(P)(i.from.node)(u)(r.outDeg);return(()=>{const a=De(i.from.node)(r.inDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!Qe(gn)(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),xy=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return K(P)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return K(P)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return K(P)(e._1.node)(99999)(t)}return t})(A),lf=t=>e=>n=>{const r=De(e)(t),i=De(n)(t);return r.tag==="Just"&&i.tag==="Just"&&r._1>i._1},hf=t=>e=>n=>r=>{if(Wr(n)(r.visited)||Wr(n)(r.visiting))return r;const i=J(Ny(t)(e)(n))({...r,visiting:K(P)(n)()(r.visiting)})((()=>{const o=De(n)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})());return{...i,visiting:ni(P)(n)(i.visiting),visited:K(P)(n)()(i.visited)}},Ny=t=>e=>n=>r=>i=>lf(t)(n)(i)?{...r,backEdges:K(Di)(b(n,i))()(r.backEdges)}:Wr(i)(r.visiting)?{...r,backEdges:K(Di)(b(n,i))()(r.backEdges)}:Wr(i)(r.visited)?r:hf(t)(e)(i)(r),Jy=t=>e=>n=>{const r=l=>{let _=l,h=!0,m;for(;h;){const p=_,y=Bt(x=>T,x=>N=>w("Just",{head:x,tail:N}),p.sinks);if(y.tag==="Just"){_=Ms(n)(y._1.head)({...p,sinks:y._1.tail,marks:K(P)(y._1.head)(p.nextRight)(p.marks),nextRight:p.nextRight-1|0});continue}if(y.tag==="Nothing"){const x=Bt(N=>T,N=>v=>w("Just",{head:N,tail:v}),p.sources);if(x.tag==="Just"){_=Ms(n)(x._1.head)({...p,sources:x._1.tail,marks:K(P)(x._1.head)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}if(x.tag==="Nothing"){const N=L=>{const k=De(L)(p.outDeg),E=De(L)(p.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 Q=De(L)(e);if(Q.tag==="Nothing")return 1e6;if(Q.tag==="Just")return Q._1;g()})())((()=>{const Q=De(k)(e);if(Q.tag==="Nothing")return 1e6;if(Q.tag==="Just")return Q._1;g()})()):E})(p.remaining);if(0<v.length){const L=v[0];_=Ms(n)(L)({...p,remaining:at(k=>k!==L,p.remaining),marks:K(P)(L)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}h=!1,m=p;continue}}g()}return m},i=Nr(P.compare)([...O(l=>l.from.node)(n),...O(l=>l.to.node)(n)]),o=at(l=>l.from.node!==l.to.node,n),u=J(l=>_=>vt(P)(oe)(_.to.node)(1)(l))(A)(o),s=J(l=>_=>vt(P)(oe)(_.from.node)(1)(l))(A)(o),a=at(l=>{const _=De(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),c=at(l=>{const _=De(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),f=i.length+1|0,d=J(l=>_=>{const h=De(_)(l);return h.tag==="Just"&&h._1<0?K(P)(_)(h._1+f|0)(l):l})(r({remaining:at(l=>!Qe(gn)(l)(a)&&!Qe(gn)(l)(c),i),marks:A,inDeg:u,outDeg:s,sources:a,sinks:c,nextLeft:1,nextRight:-1}).marks)(i);return J(l=>_=>{if(_.from.node===_.to.node)return l;if(lf(t)(_.from.node)(_.to.node))return K(Di)(b(_.from.node,_.to.node))()(l);const h=De(_.from.node)(d),m=De(_.to.node)(d);return h.tag==="Just"&&m.tag==="Just"&&h._1>m._1?K(Di)(b(_.from.node,_.to.node))()(l):l})(A)(n)},Ty=J(t=>e=>vt(P)(te)(e.from.node)([e.to.node])(t))(A),vy=t=>e=>{const n=Ty(e),r=Nr(P.compare)([...O(o=>o.from.node)(e),...O(o=>o.to.node)(e)]),i=J(o=>u=>K(P)(u.to.node)()(o))(A)(e);return J(o=>u=>hf(t)(n)(u)(o))({visiting:A,visited:A,backEdges:A})([...at(o=>!Wr(o)(i),r),...at(o=>Wr(o)(i),r)]).backEdges},wy=t=>e=>n=>r=>{const i=py(At(s=>a=>b(a,s))(e)),o=xy(n),u=(()=>{if(t==="DepthFirst")return vy(o)(r);if(t==="Greedy")return Jy(o)(i)(r);g()})();return{edges:O(s=>my(b(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},pf=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},by=J(t=>e=>K(P)(e)()(t))(A),Ho=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=P.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},Ly=Gg(P),Tn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},mf=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Hs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=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},ky=Kt(it)(zt),Ey=t=>e=>Ce(P.compare,Le,t,e),yf=At(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),Cy=t=>J(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=pf(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,Ot("Cons",o._4,i(o._6,u)));g()};return i(n,qt)})())|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 Mt("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,Sy=t=>e=>{const n=by(t);return Ly(t)(yf(at(r=>Ho(r.src)(n)&&Ho(r.tgt)(n),e)))},Gy=t=>e=>{const n=J(i=>o=>vt(P)(te)(o.tgt)([o.src])(vt(P)(te)(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,m=Bt(p=>T,p=>y=>w("Just",{head:p,tail:y}),l);if(m.tag==="Nothing"){f=!1,d={nodes:h};continue}if(m.tag==="Just"){if(Ho(m._1.head)(_)){s=m._1.tail,a=_,c=h;continue}s=[...m._1.tail,...(()=>{const p=Tn(m._1.head)(n);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;g()})()],a=K(P)(m._1.head)()(_),c=[...h,m._1.head];continue}g()}return d};return J(i=>o=>{if(Ho(o)(i.visited))return i;const u=r([o])(i.visited)([]);return{...i,visited:J(s=>a=>K(P)(a)()(s))(i.visited)(u.nodes),components:[...i.components,u.nodes]}})({visited:A,components:[]})(t).components},Py=t=>e=>n=>{const r=J(o=>u=>vt(P)(oe)(u.tgt)(1)(o))(A)(e),i=J(o=>u=>vt(P)(oe)(u.src)(1)(o))(A)(e);return J(o=>u=>{const s=Tn(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})();if((()=>{const x=Tn(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=Tn(u)(o.layers),f=(()=>{if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1;g()})(),d=o.layers,l=J(x=>N=>N.tgt===u?{...x,mIn:mf(x.mIn)((()=>{const v=Tn(u)(d),L=Tn(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?{...x,mOut:mf(x.mOut)((()=>{const v=Tn(N.tgt)(d),L=Tn(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})())}: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 m=(f-_|0)+1|0,p=(f+h|0)-1|0;if(p<m)return o;const y=J(x=>N=>{const v=Hs(N)(o.filling),L=(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})();return L<x.bestFill?{best:N,bestFill:L}:x})({best:f,bestFill:(()=>{const x=Hs(f)(o.filling);if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})()})(Dt(m,p));return y.best===f?o:{layers:K(P)(u)(y.best)(o.layers),filling:K(it)(f)((()=>{const x=Hs(f)(o.filling);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;g()})())(K(it)(y.best)(y.bestFill+1|0)(o.filling))}})({layers:n,filling:ky(O(o=>b(o,J(u=>s=>(()=>{const a=Tn(s)(n);return a.tag==="Nothing"?!1:a.tag==="Just"&&a._1===o})()?u+1|0:u)(0)(t)))(Dt(0,J(o=>u=>pf(o)((()=>{const s=Tn(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(0)(t))))})(t).layers},Iy=t=>e=>Py(t)(yf(e))(J(Ey)(A)(Cy(O(n=>Sy(n)(e))(Gy(t)(e))))),Dy=t=>t,hr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},xf=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),Ay=Dy("NetworkSimplex"),By=t=>e=>J(n=>r=>{const i=J(Oo)(0)(xt(o=>hr(o)(n))(r));return J(o=>u=>K(P)(u)(i)(o))(n)(r)})(e)(t),Fy=t=>e=>({layers:O(n=>at(r=>{const i=hr(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=Oo(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,Ot("Cons",r._4,n(r._6,i)));g()};return n(e,qt)})()))),nodeLayer:e}),Ry=t=>e=>n=>{const r=J(i=>o=>K(P)(o)(!0)(i))(A)(e);return J(i=>o=>K(P)(o._1)(o._2)(i))(Iy(e)(xt(i=>i.from.node===i.to.node||(()=>{const o=hr(i.from.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()||(()=>{const o=hr(i.to.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()?T:w("Just",{src:i.from.node,tgt:i.to.node}))(t)))(xf(n))},Qy=t=>e=>n=>r=>{const i=s=>a=>{const c=hr(a)(s);if(c.tag==="Just")return s;if(c.tag==="Nothing"){const f=at(l=>l!==a,(()=>{const l=hr(a)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;g()})()),d=J(i)(s)(f);return K(P)(a)(1+J(Oo)(0)(xt(l=>hr(l)(d))(f))|0)(d)}g()},o=J(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=Oo(_)(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,Ot("Cons",a._4,s(a._6,c)));g()};return s(o,qt)})());return J(s=>a=>K(P)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return A;if(a.tag==="Node")return Mt("Node",a._1,a._2,a._3,u-a._4|0,s(a._5),s(a._6));g()};return s(o)})())(xf(r))},zy=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return K(P)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return K(P)(e._1.node)(0)(t)}return t})(A),Wy=J(t=>e=>vt(P)(te)(e.to.node)([e.from.node])(t))(A),My=J(t=>e=>vt(P)(te)(e.from.node)([e.to.node])(t))(A),Hy=t=>e=>n=>r=>{const i=My(n),o=Wy(n),u=zy(e);return Fy(r)(By(xt(s=>s.tag==="SameLayer"?w("Just",s._1.nodes):T)(e))((()=>{if(t==="LongestPath")return Qy(i)(o)(r)(u);if(t==="NetworkSimplex")return Ry(n)(r)(u);g()})()))},Oy=Kt(P)(zt),qy=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Jf=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ai=Kt(P)(zt),$y=Kt(P)(zt),Tf=(()=>{const t=O(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>ke(t(e))})(),Yy=t=>e=>n=>r=>{const i=Oy(O(u=>b(u.edge,u))(r)),o=u=>0<u.nodes.length&&(()=>{const s=qy(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return O(u=>{if(u.nodes.length<=2){const f=Nf(u.edgeId)(i);if(f.tag==="Just"){const d=o(u),l=ki(Li(d?Tf(f._1.segments):f._1.segments));return{...f._1,edge:u.edgeId,segments:l,bends:Je(_=>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(xt(f=>Nf(f)(i))(Je(f=>d=>u.edgeId+":"+f+"->"+d,u.nodes,bt(1,u.nodes.length,u.nodes))))(f=>f.segments),a=o(u),c=ki(Li(a?Tf(s):s));return{edge:u.edgeId,segments:c,bends:Je(f=>d=>f.end,c,bt(1,c.length,c)),bendType:[],jumps:[],reversed:a}})(t)},Xy={layers:[],edges:[],chains:[]},Vy={nodeGap:3,layerGap:2,iterations:8,layerer:Ay,cycleBreaker:yy,compactPostRouting:!1},Uy=t=>({pos:b(0,0),size:b(J(e=>n=>Jf(e)(n.position._1+n.size._1))(0)(t),J(e=>n=>Jf(e)(n.position._2+n.size._2))(0)(t))}),jy=t=>e=>n=>{const r=Ai(O(c=>b(c.id,c.ports))(e.nodes)),i=at(c=>me(3)(c.node)!=="$d:",n.placements),o=Yy(n.withDummies.chains)(n.acyclic.reversedEdges)($y(O(c=>b(c.id,b(c.from.node,c.to.node)))(e.edges)))(T2(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(Zg(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 Mt("Node",f._1,f._2,f._3,b(f._4._1*4,f._4._2),c(f._5),c(f._6));g()};return c(Ai(O(f=>b(f.id,f.size))(e.nodes)))})()))),u=t.compactPostRouting?Om()({nodes:i,edges:e.edges,paths:o,ports:r}):{nodes:i,edges:o},s=O(c=>{const f=ki(Li(c.segments));return{...c,segments:f,bends:Je(d=>l=>d.end,f,bt(1,f.length,f))}})(u.edges),a=At(c=>f=>({...f,jumps:C2(c)(f)(s)}))(s);return{nodes:u.nodes,edges:a,boundingBox:Uy(u.nodes),metrics:pp(u.nodes)(a)(0)}},Zy=t=>e=>n=>{const r=Ai(O(o=>b(o.id,o.size))(e.nodes)),i={...n,placements:ey({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(Ai(O(o=>b(o.id,o.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(Zg(n.ordered)(n.withDummies.edges)((()=>{const o=u=>{if(u.tag==="Leaf")return A;if(u.tag==="Node")return Mt("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:jy(t)(e)(i)}},Ky=t=>e=>n=>Zy(t)(e)({...n,ordered:ly({iterations:t.iterations,constraints:e.constraints,modelOrder:Ai(At(r=>i=>b(i.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),tx=t=>e=>n=>Ky(t)(e)({...n,withDummies:S2(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),ex=t=>e=>{const n=O(i=>i.id)(e.nodes),r=wy(t.cycleBreaker)(n)(e.constraints)(e.edges);return tx(t)(e)({acyclic:r,layered:Hy(t.layerer)(e.constraints)(r.edges)(n),withDummies:Xy,ordered:[],placements:[]})},qo=t=>t,nx=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Os=qo("TopSide"),qs=qo("BottomSide"),$s=qo("LeftSide"),Ys=qo("RightSide"),rx=t=>{const e=st.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=st.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},vf=t=>e=>n=>{const r=nx(t.h*.12)(t.w*.2),i=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*Ee(rx((()=>{const o=(n-(t.x+i))/i;return 1-o*o})()))},er=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=jn,o=d,u=l,s=_;continue}if(f==="Cylinder"){if(l==="TopSide"){a=!1,c=vf(d)(-1)(_);continue}if(l==="BottomSide"){a=!1,c=vf(d)(1)(_);continue}if(l==="LeftSide"){a=!1,c=d.x;continue}if(l==="RightSide"){a=!1,c=d.x+d.w;continue}}i=jn,o=d,u=l,s=_}return c},wf=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?Os:c<=s&&c<=o?qs:s<=o?$s:Ys},Xs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Bi=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),$o=Kt(P)(zt),ox=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=P.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=>{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=P.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},sx=J(t=>e=>K(P)(e)()(t))(A),ax=J(t=>e=>K(P)(e)()(t))(A),Yo=ir.traverse(Nu),Xo=Kt(P)(zt),cx=t=>e=>Ce(P.compare,Le,t,e),gx=J(t=>e=>K(P)(e)()(t))(A),fx=Kt(P)(zt),_x=t=>e=>Ce(P.compare,Le,t,e),dx=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},bf=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},lx=t=>e=>({...e,edges:$o(O(n=>b(n._1,(()=>{const r=Xs(n._1)(t);if(r.tag==="Nothing")return n._2;if(r.tag==="Just"){const i=Bi(r._1._2)(e.nodes),o=Bi(r._1._1)(e.nodes),u=(()=>{if(o.tag==="Nothing")return n._2;if(o.tag==="Just"){const s=Bt(a=>T,a=>c=>w("Just",{head:a,tail:c}),n._2);if(s.tag==="Nothing")return n._2;if(s.tag==="Just"){const a={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},c=wf(a)(s._1.head);return[(()=>{if(c==="TopSide")return{...s._1.head,y:er(o._1.shape)(a)(Os)(s._1.head.x)};if(c==="BottomSide")return{...s._1.head,y:er(o._1.shape)(a)(qs)(s._1.head.x)};if(c==="LeftSide")return{...s._1.head,x:er(o._1.shape)(a)($s)(s._1.head.y)};if(c==="RightSide")return{...s._1.head,x:er(o._1.shape)(a)(Ys)(s._1.head.y)};g()})(),...s._1.tail]}}g()})();if(i.tag==="Nothing")return u;if(i.tag==="Just"){const s=Xi(u);if(s.tag==="Nothing")return u;if(s.tag==="Just")return Ft(s._1.init)((()=>{const a={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},c=wf(a)(s._1.last);if(c==="TopSide")return{...s._1.last,y:er(i._1.shape)(a)(Os)(s._1.last.x)};if(c==="BottomSide")return{...s._1.last,y:er(i._1.shape)(a)(qs)(s._1.last.x)};if(c==="LeftSide")return{...s._1.last,x:er(i._1.shape)(a)($s)(s._1.last.y)};if(c==="RightSide")return{...s._1.last,x:er(i._1.shape)(a)(Ys)(s._1.last.y)};g()})())}}g()})()))(ix(e.edges)))}),hx=t=>e=>n=>{const r=Xt(i=>i.id===n)(t.graph.edges);if(r.tag==="Just")return w("Just",r._1);if(r.tag==="Nothing")return Xs(n)(e);g()},px=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=Bi(r.node)(e);if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return r.node;g()})(),shape:(()=>{const i=Bi(r.node)(n);if(i.tag==="Nothing")return jn;if(i.tag==="Just")return i._1;g()})()}),mx=t=>({id:t,size:b(1,1),ports:[],label:w("Just",t),shape:jn}),yx=t=>e=>n=>r=>b(r.node,px(t)(e)(n)(r)),Lf=t=>{const e=lo(`
|
|
6
|
+
`)(t);return e.length===0?[""]:e},kf=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Ot("Cons",n._4,e(n._6,r)));g()};return kt($t.foldr,e(t.interiors,qt))},xx=t=>$o(xt(e=>w("Just",b(e.edge,{id:e.edge,from:{node:e.from,port:T},to:{node:e.to,port:T}})))(Tt(t.scenes)(e=>e.tag==="DataFlow"?xt(n=>n.kind.tag==="SendToken"?w("Just",n.kind._1):T)(e._1.events):[]))),Ef=t=>{const e=Al(t),n=at(i=>ox(i.id)(e.nodes),t.graph.nodes),r=at(i=>ux(i.id)(e.edges),t.graph.edges);return{nodes:[...n,...O(mx)(kt(We.foldr,Cn(P.compare,e.nodes,sx(O(i=>i.id)(n)))))],edges:[...r,...xt(hx(t)(xx(t)))(kt(We.foldr,Cn(P.compare,e.edges,ax(O(i=>i.id)(r)))))],constraints:t.graph.constraints}},Nx=t=>{const e=Yo(n=>{const r=rg(ig)((()=>{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)}})(Ef(t).nodes);return()=>{const n=e();return Xo(n)}},Cf=t=>{const e=Nx(t);return()=>{const n=e(),r=Yo(Cf)(kf(t))();return J(cx)(n)(r)}},Jx=t=>e=>{const n=Bt(r=>T,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()},Tx=t=>e=>b(e.edge,Jx(t)(e)),vx=t=>e=>n=>r=>({nodes:Xo(O(yx(rt(4)*t)(e)(n))(r.nodes)),edges:$o(O(Tx(t))(r.edges)),chipExtras:A}),wx=t=>J(e=>n=>{if(n.tag==="Structural")return e;if(n.tag==="DataFlow")return J(r=>i=>{if(i.kind.tag==="SendToken")return J(o=>u=>K(P)(u)()(o))(r)(i.kind._1.labels);if(i.kind.tag==="FillNodeWithoutTransition")return J(o=>u=>K(P)(u)()(o))(r)(i.kind._1.labels);g()})(e)(n._1.events);if(n.tag==="EnterNode"||n.tag==="ExitNode")return e;g()})(A)(t.scenes),bx=t=>{const e=Yo(n=>{const r=rg(ig)(n);return()=>{const i=r();return b(n,{labelW:i,charCount:Un(Ir(n)),lineCount:1})}})(kt(We.foldr,gx(Tt(kt(We.foldr,wx(t)))(Lf))));return()=>{const n=e();return fx(n)}},Sf=t=>{const e=bx(t);return()=>{const n=e(),r=Yo(Sf)(kf(t))();return J(_x)(n)(r)}},Lx=rt(4)*8,kx=t=>e=>{const n=dp(Lx)(t)(_p(fp)(Ef(e)));return lx($o(O(r=>b(r.id,b(r.from.node,r.to.node)))(n.edges)))(vx(8)(Xo(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)))(Xo(O(r=>b(r.id,r.shape))(n.nodes)))(ex(Vy)(n).result))},Ex=t=>Tt(t.scenes)(e=>{if(e.tag==="Structural")return[];if(e.tag==="DataFlow")return e._1.events;if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()}),Cx=t=>e=>n=>{const r=i=>{const o=xt(u=>{const s=dx(u)(t);return s.tag==="Just"?w("Just",{w:s._1.labelW+28,h:rt(up(1)(s._1.lineCount))*13.2+12}):T})(Tt(i)(Lf));return o.length===0?T:w("Just",{w:J(bf)(0)(O(u=>u.w)(o)),h:J(bf)(0)(O(u=>u.h)(o))})};return J(i=>o=>{if(o.kind.tag==="SendToken"){const u=Xs(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(P)(te)(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=Bi(o.kind._1.node)(n.nodes),s=r(o.kind._1.labels);return s.tag==="Just"&&u.tag==="Just"?vt(P)(te)("__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)(Ex(e))},Gf=t=>e=>n=>({layout:(()=>{const r=kx(t)(n);return{...r,chipExtras:Cx(e)(n)(r)}})(),interiors:(()=>{const r=Gf(t)(e),i=o=>{if(o.tag==="Leaf")return A;if(o.tag==="Node")return Mt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(n.interiors)})()}),Pf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},Vs=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=Pf(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 K(P)(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=Pf(a._3)(o);if(f.tag==="Just")return K(P)(a._3)({...a._4,x:f._1.x,y:f._1.y})(c);if(f.tag==="Nothing")return K(P)(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",m="Release",p="Finalizer",y="Finalized",x="Forked";function N(B,q,V,$){this.tag=B,this._1=q,this._2=V,this._3=$}function v(B){var q=function(V,$,X){return new N(B,V,$,X)};return q.tag=B,q}function L(B){return new N(e,void 0)}function k(B){try{B()}catch(q){setTimeout(function(){throw q},0)}}function E(B,q,V){try{return q(V())}catch($){return B($)}}function Q(B,q,V){try{return q(V)()}catch($){return V(B($))(),L}}var H=(function(){var B=1024,q=0,V=0,$=new Array(B),X=!1;function M(){var et;for(X=!0;q!==0;)q--,et=$[V],$[V]=void 0,V=(V+1)%B,et();X=!1}return{isDraining:function(){return X},enqueue:function(et){var tt;q===B&&(tt=X,M(),X=tt),$[(V+q)%B]=et,q++,X||M()}}})();function j(B){var q={},V=0,$=0;return{register:function(X){var M=V++;X.onComplete({rethrow:!0,handler:function(et){return function(){$--,delete q[M]}}})(),q[M]=X,$++},isEmpty:function(){return $===0},killAll:function(X,M){return function(){if($===0)return M();var et=0,tt={};function gt(ct){tt[ct]=q[ct].kill(X,function(yt){return function(){delete tt[ct],et--,B.isLeft(yt)&&B.fromLeft(yt)&&setTimeout(function(){throw B.fromLeft(yt)},0),et===0&&M()}})()}for(var _t in q)q.hasOwnProperty(_t)&&(et++,gt(_t));return q={},V=0,$=0,function(ct){return new N(i,function(){for(var yt in tt)tt.hasOwnProperty(yt)&&tt[yt]()})}}}}}var S=0,C=1,U=2,Y=3,W=4,z=5,R=6;function G(B,q,V){var $=0,X=S,M=V,et=null,tt=null,gt=null,_t=null,ct=null,yt=0,Et=0,Rt=null,pt=!0;function Qt(Z){for(var ut,ft,lt;;)switch(ut=null,ft=null,lt=null,X){case U:X=C;try{M=gt(M),_t===null?gt=null:(gt=_t._1,_t=_t._2)}catch(Ht){X=z,et=B.left(Ht),M=null}break;case Y:B.isLeft(M)?(X=z,et=M,M=null):gt===null?X=z:(X=U,M=B.fromRight(M));break;case C:switch(M.tag){case u:gt&&(_t=new N(_,gt,_t)),gt=M._2,X=C,M=M._1;break;case e:gt===null?(X=z,M=B.right(M._1)):(X=U,M=M._1);break;case i:X=Y,M=E(B.left,B.right,M._1);break;case o:X=W,M=Q(B.left,M._1,function(Ht){return function(){$===Z&&($++,H.enqueue(function(){$===Z+1&&(X=Y,M=Ht,Qt($))}))}});return;case n:X=z,et=B.left(M._1),M=null;break;case r:gt===null?ct=new N(_,M,ct,tt):ct=new N(_,M,new N(_,new N(h,gt,_t),ct,tt),tt),gt=null,_t=null,X=C,M=M._1;break;case s:yt++,gt===null?ct=new N(_,M,ct,tt):ct=new N(_,M,new N(_,new N(h,gt,_t),ct,tt),tt),gt=null,_t=null,X=C,M=M._1;break;case a:X=Y,ut=G(B,q,M._2),q&&q.register(ut),M._1&&ut.run(),M=B.right(ut);break;case c:X=C,M=D(B,q,M._1);break}break;case z:if(gt=null,_t=null,ct===null)X=R,M=tt||et||M;else switch(ut=ct._3,lt=ct._1,ct=ct._2,lt.tag){case r:tt&&tt!==ut&&yt===0?X=z:et&&(X=C,M=lt._2(B.fromLeft(et)),et=null);break;case h:tt&&tt!==ut&&yt===0||et?X=z:(gt=lt._1,_t=lt._2,X=U,M=B.fromRight(M));break;case s:yt--,et===null&&(ft=B.fromRight(M),ct=new N(_,new N(m,lt._2,ft),ct,ut),(tt===ut||yt>0)&&(X=C,M=lt._3(ft)));break;case m:ct=new N(_,new N(y,M,et),ct,tt),X=C,tt&&tt!==ut&&yt===0?M=lt._1.killed(B.fromLeft(tt))(lt._2):et?M=lt._1.failed(B.fromLeft(et))(lt._2):M=lt._1.completed(B.fromRight(M))(lt._2),et=null,yt++;break;case p:yt++,ct=new N(_,new N(y,M,et),ct,tt),X=C,M=lt._1;break;case y:yt--,X=z,M=lt._1,et=lt._2;break}break;case R:for(var Nt in Rt)Rt.hasOwnProperty(Nt)&&(pt=pt&&Rt[Nt].rethrow,k(Rt[Nt].handler(M)));Rt=null,tt&&et?setTimeout(function(){throw B.fromLeft(et)},0):B.isLeft(M)&&pt&&setTimeout(function(){if(pt)throw B.fromLeft(M)},0);return;case S:X=C;break;case W:return}}function Jt(Z){return function(){if(X===R)return pt=pt&&Z.rethrow,Z.handler(M)(),function(){};var ut=Et++;return Rt=Rt||{},Rt[ut]=Z,function(){Rt!==null&&delete Rt[ut]}}}function mt(Z,ut){return function(){if(X===R)return ut(B.right(void 0))(),function(){};var ft=Jt({rethrow:!1,handler:function(){return ut(B.right(void 0))}})();switch(X){case S:tt=B.left(Z),X=R,M=tt,Qt($);break;case W:tt===null&&(tt=B.left(Z)),yt===0&&(X===W&&(ct=new N(_,new N(p,M(Z)),ct,tt)),X=z,M=null,et=null,Qt(++$));break;default:tt===null&&(tt=B.left(Z)),yt===0&&(X=z,M=null,et=null)}return ft}}function nt(Z){return function(){var ut=Jt({rethrow:!1,handler:Z})();return X===S&&Qt($),ut}}return{kill:mt,join:nt,onComplete:Jt,isSuspended:function(){return X===S},run:function(){X===S&&(H.isDraining()?Qt($):H.enqueue(function(){Qt($)}))}}}function I(B,q,V,$){var X=0,M={},et=0,tt={},gt=new Error("[ParAff] Early exit"),_t=null,ct=t;function yt(Jt,mt,nt){var Z=mt,ut=null,ft=null,lt=0,Nt={},Ht,Vt;t:for(;;)switch(Ht=null,Z.tag){case x:if(Z._3===t&&(Ht=M[Z._1],Nt[lt++]=Ht.kill(Jt,function(Pe){return function(){lt--,lt===0&&nt(Pe)()}})),ut===null)break t;Z=ut._2,ft===null?ut=null:(ut=ft._1,ft=ft._2);break;case f:Z=Z._2;break;case d:case l:ut&&(ft=new N(_,ut,ft)),ut=Z,Z=Z._1;break}if(lt===0)nt(B.right(void 0))();else for(Vt=0,Ht=lt;Vt<Ht;Vt++)Nt[Vt]=Nt[Vt]();return Nt}function Et(Jt,mt,nt){var Z,ut,ft,lt,Nt,Ht;for(B.isLeft(Jt)?(Z=Jt,ut=null):(ut=Jt,Z=null);;){if(ft=null,lt=null,Nt=null,Ht=null,_t!==null)return;if(mt===null){$(Z||ut)();return}if(mt._3!==t)return;switch(mt.tag){case f:Z===null?(mt._3=B.right(mt._1(B.fromRight(ut))),ut=mt._3):mt._3=Z;break;case d:if(ft=mt._1._3,lt=mt._2._3,Z){if(mt._3=Z,Nt=!0,Ht=et++,tt[Ht]=yt(gt,Z===ft?mt._2:mt._1,function(){return function(){delete tt[Ht],Nt?Nt=!1:nt===null?Et(Z,null,null):Et(Z,nt._1,nt._2)}}),Nt){Nt=!1;return}}else{if(ft===t||lt===t)return;ut=B.right(B.fromRight(ft)(B.fromRight(lt))),mt._3=ut}break;case l:if(ft=mt._1._3,lt=mt._2._3,ft===t&&B.isLeft(lt)||lt===t&&B.isLeft(ft))return;if(ft!==t&&B.isLeft(ft)&<!==t&&B.isLeft(lt))Z=ut===ft?lt:ft,ut=null,mt._3=Z;else if(mt._3=ut,Nt=!0,Ht=et++,tt[Ht]=yt(gt,ut===ft?mt._2:mt._1,function(){return function(){delete tt[Ht],Nt?Nt=!1:nt===null?Et(ut,null,null):Et(ut,nt._1,nt._2)}}),Nt){Nt=!1;return}break}nt===null?mt=null:(mt=nt._1,nt=nt._2)}}function Rt(Jt){return function(mt){return function(){delete M[Jt._1],Jt._3=mt,Et(mt,Jt._2._1,Jt._2._2)}}}function pt(){var Jt=C,mt=V,nt=null,Z=null,ut,ft;t:for(;;)switch(ut=null,ft=null,Jt){case C:switch(mt.tag){case f:nt&&(Z=new N(_,nt,Z)),nt=new N(f,mt._1,t,t),mt=mt._2;break;case d:nt&&(Z=new N(_,nt,Z)),nt=new N(d,t,mt._2,t),mt=mt._1;break;case l:nt&&(Z=new N(_,nt,Z)),nt=new N(l,t,mt._2,t),mt=mt._1;break;default:ft=X++,Jt=z,ut=mt,mt=new N(x,ft,new N(_,nt,Z),t),ut=G(B,q,ut),ut.onComplete({rethrow:!1,handler:Rt(mt)})(),M[ft]=ut,q&&q.register(ut)}break;case z:if(nt===null)break t;nt._1===t?(nt._1=mt,Jt=C,mt=nt._2,nt._2=t):(nt._2=mt,mt=nt,Z===null?nt=null:(nt=Z._1,Z=Z._2))}for(ct=mt,ft=0;ft<X;ft++)M[ft].run()}function Qt(Jt,mt){_t=B.left(Jt);var nt;for(var Z in tt)if(tt.hasOwnProperty(Z)){nt=tt[Z];for(Z in nt)nt.hasOwnProperty(Z)&&nt[Z]()}tt=null;var ut=yt(Jt,ct,mt);return function(ft){return new N(o,function(lt){return function(){for(var Nt in ut)ut.hasOwnProperty(Nt)&&ut[Nt]();return L}})}}return pt(),function(Jt){return new N(o,function(mt){return function(){return Qt(Jt,mt)}})}}function D(B,q,V){return new N(o,function($){return function(){return I(B,q,V,$)}})}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=G,N.Supervisor=j,N.Scheduler=H,N.nonCanceler=L,N})();let If=null;function Sx(){return If||(typeof document>"u"?null:If=document.createElement("canvas").getContext("2d"))}const Us=new Map;function Df(t,e,n,r,i,o){const u=`${n} ${e}px ${t}`,s=u+"|"+r;if(Us.has(s))return Us.get(s);const a=Sx();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))Us.set(s,c);else if(f&&f.load)try{f.load(u)}catch{}return c}const Gx=(t,e,n,r)=>Df(t,e,n,r,i=>i.width,-1),Px=(t,e,n,r)=>Df(t,e,n,r,i=>({ascent:i.actualBoundingBoxAscent,descent:i.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),Af=t=>e=>{const n=Gx(t.family,t.size,t.weight,Ir(e));return n<0?rt(mo(e).length)*t.size*.62:n},Bf=t=>e=>{const n=Px(t.family,t.size,t.weight,Ir(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},Ff=t=>t,Rf=t=>t,Vo=t=>t,Qf=t=>t,Ix=t=>t,zf=t=>t,Wf=t=>t,Dx=Wf("BaselineTop"),Mr=Wf("BaselineMiddle"),js=zf("AlignLeft"),Uo=zf("AlignCenter"),Te=Ix("RoundJoin"),fn=Qf("ButtCap"),Dn=Qf("RoundCap"),Ax=Vo("LayerPolyOut"),Bx=Vo("LayerPolyIn"),Fx=Vo("LayerNodeMask"),Rx=Vo("LayerOverlay"),Zs=Rf("NonZero"),Qx=Rf("EvenOdd"),Mf=Ff("Normal"),jo=Ff("Difference"),re={r:255,g:255,b:255,a:255},An={r:26,g:26,b:26,a:255},zx=t=>t,Hf=t=>t,Wx=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},nn=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Of=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()},Ks=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Mx=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},Hx=Hf("FlatLevel"),Ox=Hf("NestedLevel"),qf=zx("GenieSilhouette"),qx=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const i=Sr(t);return{prng:i.prng,yLift:i.value*n.yJitter*r}},$x=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const i=Sr(t);return{prng:i.prng,dx:(i.value*2-1)*n.xJitter*r}},$f=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,i=Ee(r*r+n*n),o=(t.r*t.r-e.r*e.r+i*i)/(2*i),u=Ee(Wx(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},Yx=t=>e=>{const n=nn(e)(nn(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]},Xx=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=Sr(t);return{prng:u.prng,r:i*(1+u.value*o.rJitter)}},Yf=t=>{const e=nn(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]},Vx=t=>e=>n=>{const r=Sr(t),i=e.length;return i===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const o=Of(0)(i-1|0)(de(dn(r.value*rt(n))));return o>=0&&o<e.length?e[o]:-1})()}},Ux=t=>e=>{const n=Sr(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const i=Of(0)(r-1|0)(de(dn(n.value*rt(r))));return i>=0&&i<e.length?e[i]:-1})()}},Xf=t=>{const e=nn(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]},Vf=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],Uf={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},jx=t=>{const e=nn(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]},jf=t=>{const e=nn(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]},Zf=t=>e=>{const n=e.y+e.h,r=fd(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=Ks(t.minN)(i<=0||o<=0?t.minN:de(Yn(i/o))+1|0),s=u>=3?Dt(1,u-2|0):[],a=s.length,c=En(a+1|0,2),f=c<1?[]:bt(0,c,s),d=Ux(t.seed)((()=>{const p=a-c|0;return p<1?s:bt(p,s.length,s)})()),l=d.idx,_=Vx(d.prng)(at(p=>p!==l,f))(Ks(1)(f.length-(Qe(xr)(l)(f)?1:0)|0)),h=_.idx,m=u>=2?i/(rt(u)-1):0;return J(p=>y=>{const x=y===h,N=y===l,v=y===0||y===(u-1|0),L=Xx(p.prng)(v)(N)(x)(r)(t),k=qx(L.prng)(v)(t)(e.h),E=$x(k.prng)(v)(t)(m);return{prng:E.prng,circles:Ft(p.circles)({cx:e.x+Mx(L.r)(e.w-L.r)((u>=2?r+rt(y)/(rt(u)-1)*i+E.dx:r+0*i+E.dx)+(N?t.heroShift*m:x?-1*t.smallShift*m:0)),cy:n-k.yLift,r:L.r})}})({prng:_.prng,circles:[]})(Dt(0,u-1|0)).circles},Kf=t=>e=>{const n=t.length;return At(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?$f(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?$f(i)(t[o]):{x:i.cx+i.r,y:e}})()}))(t)},t_=t=>{const e=nn(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]},Zx=t=>e=>n=>{const r=ur(e.y-t.cy)(e.x-t.cx),i=ur(n.y-t.cy)(n.x-t.cx),o=i>r?i-r:i+6.283185307179586-r,u=Ks(1)(de(Vi(o/1.5707963267948966))),s=o/rt(u),a=1.3333333333333333*_d(s/4);return Tt(Dt(0,u-1|0))(c=>{const f=r+rt(c+1|0)*s,d=t.cx+t.r*Ke(f),l=t.cy+t.r*Oe(f),_=r+rt(c)*s;return[4,t.cx+t.r*Ke(_)-a*t.r*Oe(_),t.cy+t.r*Oe(_)+a*t.r*Ke(_),d+a*t.r*Oe(f),l-a*t.r*Ke(f),d,l]})},e_=t=>e=>{const n=t.h*.38,r=Kf(Zf(Uf)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),i=nn(e)(nn(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...Tt(r)(o=>Zx(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]:Yx(t)(e)},n_=t=>e=>n=>r=>i=>o=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(i)(o);if(e==="Cylinder"){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==="Parallelogram"){const u=Xf(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=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==="Ellipse"){const u=Yf(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=Vf(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=e_(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)},Kx=t=>()=>t.clip("evenodd"),tN=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()},ta=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ea=t=>e=>n=>{const r=e.stroke;return()=>{const i=r.value,o=Fd(t)(n);if(i!==n)return o(),e.stroke.value=n}},eN=t=>e=>n=>{const r=e.font;return()=>{const i=r.value,o=$d(t)(n);if(i!==n)return o(),e.font.value=n}},Fi=t=>e=>n=>{const r=e.fill;return()=>{const i=r.value,o=Bd(t)(n);if(i!==n)return o(),e.fill.value=n}},Zo=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=tc(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=ui(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=si(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=Xd(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=ec(t),a=r(o+1|0);return()=>(s(),a())}return()=>{}},i=Ka(t);return()=>(i(),r(0)())},nN=t=>e=>n=>r=>i=>o=>{const u=ta(o)(ta(r/2)(i/2)),s=tc(t)(e+u)(n);return()=>(s(),ui(t)(e+r-u)(n)(),si(t)({cpx:e+r,cpy:n,x:e+r,y:n+u})(),ui(t)(e+r)(n+i-u)(),si(t)({cpx:e+r,cpy:n+i,x:e+r-u,y:n+i})(),ui(t)(e+u)(n+i)(),si(t)({cpx:e,cpy:n+i,x:e,y:n+i-u})(),ui(t)(e)(n+u)(),si(t)({cpx:e,cpy:n,x:e+u,y:n})(),ec(t)())},rN=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),iN=t=>e=>{const n=Md(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=rN();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0}}}},oN={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},uN=t=>ie(t.weight)+" "+Ca(t.size)+"px "+t.family,vn=t=>{const e=Ca(rt(t.a)/255);return t.a>=255?"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")":"rgba("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+","+e+")"},sN=t=>e=>n=>r=>{const i=Fi(t)(n)(vn(r));return()=>(i(),Wd(t)({x:0,y:0,width:e.width,height:e.height})())},aN=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",tN(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:vn(n.bgColor),dotCss:vn(n.dotColor),tile:n.tile,dotR:n.dotRadius})())},cN=t=>e=>n=>r=>{const i=Fi(t)(e)(vn(r));return()=>(i(),Zo(t)(n)(),Gu(t)())},gN=t=>e=>n=>r=>i=>{const o=Fi(t)(e)(vn(r));return()=>(o(),ea(t)(e)(vn(i.color))(),ku(t)(i.width)(),no(t)((()=>{if(i.lineJoin==="RoundJoin")return eo;if(i.lineJoin==="BevelJoin")return Bu;if(i.lineJoin==="MiterJoin")return Fu;g()})())(),Wu(t)((()=>{if(i.lineCap==="ButtCap")return zu;if(i.lineCap==="RoundCap")return Ru;if(i.lineCap==="SquareCap")return Qu;g()})())(),Zo(t)(n)(),Gu(t)(),Su(t)())},fN=t=>e=>n=>r=>i=>o=>{const u=Ka(t);return()=>{if(u(),nN(t)(n.x)(n.y)(n.w)(n.h)(r)(),i.tag==="Just"?(Fi(t)(e)(vn(i._1.color))(),Gu(t)()):i.tag==="Nothing"||g(),o.tag==="Just")return ea(t)(e)(vn(o._1.color))(),ku(t)(o._1.width)(),no(t)((()=>{if(o._1.lineJoin==="RoundJoin")return eo;if(o._1.lineJoin==="BevelJoin")return Bu;if(o._1.lineJoin==="MiterJoin")return Fu;g()})())(),Wu(t)((()=>{if(o._1.lineCap==="ButtCap")return zu;if(o._1.lineCap==="RoundCap")return Ru;if(o._1.lineCap==="SquareCap")return Qu;g()})())(),Su(t)();o.tag!=="Nothing"&&g()}},_N=t=>e=>n=>r=>{const i=ea(t)(e)(vn(r.color));return()=>(i(),ku(t)(r.width)(),no(t)((()=>{if(r.lineJoin==="RoundJoin")return eo;if(r.lineJoin==="BevelJoin")return Bu;if(r.lineJoin==="MiterJoin")return Fu;g()})())(),Wu(t)((()=>{if(r.lineCap==="ButtCap")return zu;if(r.lineCap==="RoundCap")return Ru;if(r.lineCap==="SquareCap")return Qu;g()})())(),Zo(t)(n)(),Su(t)())},r_=t=>e=>n=>{const r=Fi(t)(e)(vn(n.color));return()=>(r(),eN(t)(e)(uN(n.font))(),ol(t)((()=>{if(n.align==="AlignLeft")return Kd;if(n.align==="AlignCenter")return el;if(n.align==="AlignRight")return tl;g()})())(),il(t)((()=>{if(n.baseline==="BaselineTop")return Vd;if(n.baseline==="BaselineMiddle")return Ud;if(n.baseline==="BaselineAlphabetic")return jd;if(n.baseline==="BaselineBottom")return Zd;g()})())(),Yd(t)(n.content)(n.x)(n.y)())},i_={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>oN},dN={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>i_},lN=t=>e=>n=>{const r=ta(e.width/n.vw)(e.height/n.vh),i=Pu(t)({translateX:(e.width-n.vw*r)/2-n.vx*r,translateY:(e.height-n.vh*r)/2-n.vy*r});return()=>(i(),Ki(t)({scaleX:r,scaleY:r})(),no(t)(eo)())},hN={pure:t=>e=>()=>t,Apply0:()=>i_},pN={Applicative0:()=>hN,Bind1:()=>dN},o_={fillPath:t=>e=>n=>{const r=cN(n.ctx)(n.styleCache)(t)(e.color),i=n.maskDepth;return()=>{if(i.value===0)return r()}},strokePath:t=>e=>n=>{const r=_N(n.ctx)(n.styleCache)(t)(e),i=n.maskDepth;return()=>{if(i.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const i=gN(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=fN(i.ctx)(i.styleCache)(t)(e)(n)(r),u=i.maskDepth;return()=>{if(u.value===0)return o()}},drawText:t=>e=>{const n=r_(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=sr(n.ctx),i=n.maskDepth;return()=>{if(i.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Hd(n.ctx)(t)(),r_(n.ctx)(n.styleCache)(e)(),ar(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=sr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Pu(e.ctx)({translateX:t.tx,translateY:t.ty})(),Ki(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=ar(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=sr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Pu(e.ctx)({translateX:t.tx,translateY:t.ty})(),Ki(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=ar(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=sr(n.ctx),i=n.maskDepth;return()=>{if(i.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Zo(n.ctx)(t)(),e==="NonZero")return zd(n.ctx)();if(e==="EvenOdd")return Kx(n.ctx)();g()}}},popClip:t=>{const e=ar(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=sr(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 rc(e.ctx)(nl)();if(t==="Difference")return rc(e.ctx)(rl)();g()}}},popBlend:t=>{const e=ar(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=sr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Qd(e.ctx)(t)()}},popAlpha:t=>{const e=ar(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=lN(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=sN(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=aN(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=Af(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Bf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>qf,Monad0:()=>pN},mN=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Hr=t=>e=>n=>{const r=mN(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},u_=t=>{const e=st.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=st.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Ko=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:pi(8)(.6)(u_(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:pi(8)(.6)(u_(1-t._1))};g()};function yN(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function xN(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:yN(i,o)}}return n}function NN(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 s_(t,e){if(e.length===0)return[];const n=xN(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]=NN(n,e,o*r/t);return i}function JN(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 TN(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 JN(r,e)}const a_=t=>e=>n=>{const r=s_(t,e),i=s_(t,n),o=TN(r,i);return{from:r,to:o}};function c_(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 vN(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 wN(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 g_=t=>e=>n=>r=>{const i=e.length;if(i===0)return[];const o=c_(e),u=c_(n),s=vN(o,u),a=new Array(i);let c=1/0,f=-1/0;for(let _=0;_<i;_++){const h=e[_],m=(h.x-o.x)*s.x+(h.y-o.y)*s.y;a[_]=m,m<c&&(c=m),m>f&&(f=m)}const d=f-c;let l=new Array(i);for(let _=0;_<i;_++){const h=e[_],m=n[_];if(m===void 0){l[_]=h;continue}const p=d<=1e-4?0:r.maxDelay*(1-(a[_]-c)/d),y=Math.max(1e-4,1-p),x=bN((t-p)/y),N=x*x*(3-2*x);l[_]={x:h.x+(m.x-h.x)*N,y:h.y+(m.y-h.y)*N}}for(let _=0;_<r.smoothPasses;_++)l=wN(.5,l);return l},wn=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},f_=J(Tr)(0),__=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},LN=J(t=>e=>t+e.len)(0),d_=t=>{const e=Bt(n=>T,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()},kN=t=>e=>{const n=wn(e)(wn(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]},EN=t=>{const e=Bt(n=>T,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()},CN=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return jf(e);if(t.shape==="Parallelogram")return Xf(e);if(t.shape==="Diamond")return t_(e);if(t.shape==="Ellipse")return Yf(e);if(t.shape==="Document")return Vf(e);if(t.shape==="Cloud")return e_(e)(7);if(t.shape==="Rectangle")return kN(e)(7);g()},pe=t=>e=>n=>O(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)),SN=t=>{const e=nn(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)]},Or=t=>e=>{const n=wn(t)(wn(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}},na=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return Ee(r*r+n*n)},GN=t=>Je(e=>n=>({a:e,b:n,len:na(e)(n)}),t,bt(1,t.length,t)),PN=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?w("Just",e[n]):T,i=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];g()})(),o=0<e.length?w("Just",e[0]):T,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]):T,d=a>=0&&a<e.length?w("Just",e[a]):T,l=a-1|0,_=l>=0&&l<e.length?w("Just",e[l]):T;if(_.tag==="Just"&&d.tag==="Just"&&f.tag==="Just"){const h=d._1,m=na(h)(f._1),p=na(_._1)(h),y=wn(t)(m/2),x=wn(t)(p/2),N=m>0?y/m:0,v=h.x+(f._1.x-h.x)*N,L=h.y+(f._1.y-h.y)*N,k=p>0?x/p:0,E=h.x+(_._1.x-h.x)*k,Q=h.y+(_._1.y-h.y)*k;return O(H=>{const j=rt(H)/rt(10),S=1-j;return{x:S*S*E+2*S*j*h.x+j*j*v,y:S*S*Q+2*S*j*h.y+j*j*L}})(Dt(0,10))}return[]}),...i]},IN=t=>e=>n=>r=>i=>O(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)),DN=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),...IN({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)],l_=t=>e=>O(n=>{const r=6.283185307179586*rt(n)/rt(64);return{x:t.x+e*Ke(r),y:t.y+e*Oe(r)}})(Dt(0,63)),tu=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]},AN=t=>{const e=t.y+t.h/2,n=nn(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)]},h_=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:f_(O(n=>n.x)(t))/rt(e),y:f_(O(n=>n.y)(t))/rt(e)}},eu=t=>e=>n=>r=>i=>O(o=>{const u=n+(r-n)*(rt(o)/rt(i));return{x:t.x+e*Ke(u),y:t.y+e*Oe(u)}})(Dt(0,i-1|0)),p_=t=>e=>{const n=wn(t)(wn(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),...eu({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),...eu({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),...eu({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),...eu({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},nu=t=>e=>n=>r=>i=>o=>O(u=>{const s=r+(i-r)*(rt(u)/rt(o));return{x:t.x+e*Ke(s),y:t.y+n*Oe(s)}})(Dt(0,o-1|0)),BN=t=>{const e=t.h*.38;return[...Tt(Kf(Zf(Uf)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=ur(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),i=ur(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return nu({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)]},FN=t=>{const e=wn(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[...nu({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),...nu({x:o,y:i})(n)(e)(0)(3.141592653589793)(24),...pe({x:t.x,y:i})({x:t.x,y:r})(12)]},ru=t=>e=>e.shape==="Cylinder"?FN(e):e.shape==="Parallelogram"?SN(e):e.shape==="Diamond"?AN(e):e.shape==="Ellipse"?p_(nn(e.w)(e.h)/2)(e):e.shape==="Document"?DN(e):e.shape==="Cloud"?BN(e):p_(t)(e),RN=t=>{const e=wn(t.h*.075)(t.w*.075),n=t.w/2;return nu({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},QN=t=>e=>n=>J(r=>i=>{const o=r.pos+i.len,u=n<o?(n-r.pos)/i.len:1,s={x:i.a.x+(i.b.x-i.a.x)*u,y:i.a.y+(i.b.y-i.a.y)*u},a=e>r.pos?(e-r.pos)/i.len:0,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})()})()?Ft(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=Bt(i=>T,i=>o=>w("Just",{head:i,tail:o}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const i=GN(t),o=LN(i),u=__(0)(o)(e*o),s=__(0)(o)(n*o);return s<=u?[]:QN(i)(u)(s)}g()},ra=t=>t,Bn=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},pr=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},WN=Y1(Ba)(zt),MN=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},HN=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},m_=ra("SegMove"),ON=ra("SegLine"),qN=ra("SegQuad"),y_={offset:.4,passes:1,rMax:1.5},x_=t=>de(dn(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,iu=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},ou=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},Fn=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},Ri=(()=>{const t=J(e=>n=>((e*31|0)+de(dn(n.x*100))|0)+de(dn(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),$N=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]):T;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:m_,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:ON,m:o,c:o,p:s,len:Ee(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:qN,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:Ee(a*a+c*c)*1.05}),r=s,n=i+5|0;continue}if(u._1===5){e.push({kind:m_,m:o,c:o,p:o,len:0}),n=i+1|0;continue}n=t.length;continue}g()}return e},YN=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]):T})(),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=Ee(s*s+u*u);return a<=1e-4?e:Ft((()=>{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},XN=t=>e=>n=>ke(J(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*Ke(u.value),y:i.y+o.value*Oe(u.value)},...r.out]}})({prng:e,out:[]})(n).out),VN=t=>e=>n=>{if(e.kind==="SegMove")return ou(t)(e.p);if(e.kind==="SegLine")return Fn(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 Fn(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});g()},UN=t=>e=>{if(e.kind==="SegMove")return ou(t)(e.p);if(e.kind==="SegLine")return Fn(t)(e.p);if(e.kind==="SegQuad")return iu(t)(e.c)(e.p);g()},N_=t=>e=>{const n=$N(e),r=J(s=>a=>s+a.len)(0)(n)*Bn(0)(pr(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];UN(i)(c)(),o=a+c.len,u=s+1|0;continue}if(a>=r){u=n.length;continue}VN(i)(n[s])((r-a)/Bn(n[s].len)(1e-4))()}u=n.length}return i},J_={offset:1.5,passes:2,rMax:14,overshoot:2.5},T_=t=>e=>n=>r=>{const i=r.y-n.y,o=n.y-e.y,u=r.x-n.x,s=Ee(u*u+i*i),a=n.x-e.x,c=Ee(a*a+o*o),f=pr(t.rMax*(gd(c>0&&s>0?Bn(-1)(pr(1)((a*u+o*i)/(c*s))):1)/3.141592653589793))(.4*pr(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}},v_=t=>e=>{const n=e.length,r=[],i=0<e.length?w("Just",e[0]):T;if(i.tag==="Just"?ou(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=T_(t)(e[c])(e[s])(e[a]);Fn(r)(f.inP)(),iu(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&&Fn(r)(e[o])(),r},jN=t=>e=>n=>r=>i=>{if(i.length<4)return v_(t)(i);const o=0<i.length?w("Just",i[0]):T,u=(()=>{if(o.tag==="Nothing")return{x:0,y:0};if(o.tag==="Just")return o._1;g()})(),s=i.length-1|0,a=Xn(Xn(e)(s)+s|0)(s),c=_=>{const h=Xn(_+s|0)(s);return h>=0&&h<i.length?i[h]:u},f=O(_=>T_(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]):T;if(l.tag==="Just")if(ou(d)(l._1.outP)(),WN((()=>{const _=Bt(h=>T,h=>m=>w("Just",m),f);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})())(_=>{const h=Fn(d)(_.inP);return()=>(h(),iu(d)(_.curr)(_.outP)())})(),n)Fn(d)(l._1.inP)(),iu(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const _=f.length-1|0;_>=0&&_<f.length?Fn(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}})())():Fn(d)(l._1.inP)()}else l.tag==="Nothing"||g();return d},qr=t=>e=>n=>r=>{const i=MN(1)(r.length-1|0),o=ae(0)(rt(i))(fs("shape")(e)),u=HN(i-1|0)(de(dn(o.value))),s=o.prng;return O(a=>{const c=ae(0)(1)(fs(ie(a))(s)),f=ae(-.18)(.3)(c.prng),d=c.value<.7,l=ae(.5)(.85)(f.prng),_=XN(t.offset)(l.prng)(r);return{path:n?jN(t)(u)(d)(f.value)(_):v_(t)(_),alpha:l.value}})(Dt(0,t.passes-1|0))},ZN=t=>e=>n=>qr(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}]),KN=t=>e=>n=>{const r=Bn(0)(pr(1)(n)),i=e.h/rt(4),o=Bn(6)(i*1.4);return xt(u=>u)(O(u=>{if(r<Bn(0)(rt(u)/rt(4)-.05))return T;const s=fs(ie(u))(t),a=Bn(0)(rt(u)/rt(4)-.05),c=Xn(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:N_(Bn(0)(pr(1)((r-a)/Bn(1e-4)(pr(1)(rt(u+1|0)/rt(4)+.05)-a))))((()=>{const _={rMax:2,offset:.6,passes:1},h=ke(J(p=>y=>{const x=ae(-i*.08)(i*.08)(p.prng);return{prng:x.prng,out:[{x:f+(d-f)*(rt(y)/rt(4)),y:l+x.value},...p.out]}})({prng:s,out:[]})(Dt(0,4)).out),m=h.length<2?[]:qr(_)(s)(!1)(h);return 0<m.length?m[0].path:[]})()),width:o,alpha:1})})(Dt(0,3)))},ia=(t,e,n)=>({tag:t,_1:e,_2:n}),w_=t=>t,oa=(t,e,n)=>({tag:t,_1:e,_2:n}),uu=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},b_=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Qi=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},L_=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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=T;continue}if(o.tag==="Node"){const u=P.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},Me=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),mr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},tJ=zt.foldMap(bd),su=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},k_=Kt(P)(zt),eJ=Ua(P),nJ=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=P.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},ua=w_("LabelsShown"),rJ=w_("LabelsHidden"),E_=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))))))},rn=t=>{const e=t.Apply0();return n=>J(r=>i=>e.apply(e.Functor0().map(o=>Ea)(r))(n(i)))(t.pure())},C_=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=Hr(i)(o)(r),c=0<t.length?w("Just",t[0]):T,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]):T,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return u;g()})(),h=a_(128)(ru(4)(Or(2)(e)))(l_(f)(6)),m=f.x-s.x,p=2*(()=>{const U=f.y-s.y;return(m<0?-m:m)+(U<0?-U:U)})(),y=_.x-u.x,x=2*(()=>{const U=_.y-u.y;return(y<0?-y:y)+(U<0?-U:U)})(),N=p+_i(t)+x,v=N<=1e-4?1:1-x/N,L=N<=1e-4?0:p/N,k=v-L,E=a_(128)(l_(_)(6))(ru(4)(Or(2)(n))),Q={maxDelay:.4,smoothPasses:2},H=vr(t)(uu(0)(1)(k<=1e-4?0:(a-L)/k)),j=(()=>{if(H.tag==="Just")return H._1;if(H.tag==="Nothing")return f;g()})(),S=(()=>{if(v>=1)return 0;const U=(a-v)/(1-v),Y=U<0?0:U>1?1:U;return Y*Y*(3-2*Y)})(),C=(()=>{if(L<=1e-4)return 1;const U=a/L,Y=U<0?0:U>1?1:U;return Y*Y*(3-2*Y)})();return a<L?oa("PolyShape",g_(C)(h.from)(h.to)(Q)):a>=v?oa("PolyShape",g_(S)(E.from)(E.to)(Q)):oa("CircleShape",j,6)},S_=t=>e=>n=>r=>i=>o=>{const u=C_(t)(e)(n)(r)(i)(o);if(u.tag==="PolyShape")return h_(u._1);if(u.tag==="CircleShape")return u._1;g()},iJ=t=>e=>{const n=t.y+t.h-6,r=t.y+6,i=t.x+14,o=t.x+t.w-14,u=J(Qi)(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?b_((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}},oJ=t=>e=>n=>J(r=>i=>{const o=L_(i)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just"){const u=iJ(o._1)(r.obstacles);return{acc:K(P)(i)(u)(r.acc),obstacles:Ft(r.obstacles)(u)}}g()})({acc:A,obstacles:n})(t).acc,sa=(()=>{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:An,nodeFill:re,nodeStroke:An,text:An,edge:An,arrowFill:An,tokenOutsideFill:An,tokenOutsideStroke:re,tokenInside:re,tokenInsideStroke:re,tokenInsideBlend:jo,tokenInsideAlpha:1,chipPillFill:An,chipPillText:re,chipHairline:{r:26,g:26,b:26,a:90},trailDot:An,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:An,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:re,tokenOutsideStroke:re,tokenInside:re,tokenInsideStroke:re,tokenInsideBlend:jo,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:re,chip:re,chipShadow:{r:0,g:0,b:0,a:120},chipText:i,nodeFill:i,nodeStroke:re,text:re,edge:re,arrowFill:re,tokenOutsideFill:re,tokenOutsideStroke:re,tokenInside:re,tokenInsideStroke:re,tokenInsideBlend:Mf,tokenInsideAlpha:.35,chipPillFill:re,chipPillText:i,chipHairline:{r:255,g:255,b:255,a:120},trailDot:re,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:Mf,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:re,tokenInside:re,tokenInsideStroke:re,tokenInsideBlend:jo,tokenInsideAlpha:1,chipPillFill:u,chipPillText:re,chipHairline:{r:60,g:66,b:78,a:90},trailDot:u,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};g()}})(),aa=t=>e=>Tt(Me(t.nodes))(n=>{const r=fe(n._1)(e.nodes);return r.tag==="Just"&&Ko(r._1).alpha>0?CN(n._2):[]}),uJ=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,...aa(e)(n)],sJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=ir.traverse(r);return o=>u=>{const s=Vn(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?ro(s[c]):" "))(l=>r.pure({x:f,w:d-f,up:l.ascent-a,down:l.descent+a})))))(Dt(0,s.length-1|0))}},aJ=t=>e=>{const n=i=>(i.x-e.x)*(i.x-e.x)+(i.y-e.y)*(i.y-e.y),r=J(i=>o=>n(o)<n(i)?o:i)({x:t.x,y:t.y})([{x:t.x,y:t.y},{x:t.x+t.w,y:t.y},{x:t.x,y:t.y+t.h},{x:t.x+t.w,y:t.y+t.h}]);return O(i=>{const o=rt(i)/5;return{x:r.x+(e.x-r.x)*o,y:r.y+(e.y-r.y)*o}})([1,2,3,4])},ca=t=>{const e=lo(`
|
|
7
|
+
`)(t);return e.length===0?[""]:e},cJ=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=Hr(i)(o)(r),c=0<t.length?w("Just",t[0]):T,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]):T,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return u;g()})(),h=f.x-s.x,m=2*(()=>{const Q=f.y-s.y;return(h<0?-h:h)+(Q<0?-Q:Q)})(),p=_.x-u.x,y=2*(()=>{const Q=_.y-u.y;return(p<0?-p:p)+(Q<0?-Q:Q)})(),x=m+_i(t)+y,N=x<=1e-4?1:1-y/x,v=x<=1e-4?0:m/x,L=N-v,k=vr(t)(uu(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?ia("InsideRect",Or(2)(e)):a>=N?ia("InsideRect",Or(2)(n)):ia("InsideBall",E,6)},gJ={offset:.8,passes:2,rMax:5},fJ=t=>{const e=t.Monad0().Applicative0(),n=rn(e);return r=>i=>o=>u=>{const s={color:u,width:1,lineJoin:Te,lineCap:fn},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=mr(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=cJ((()=>{if(f._2._1.direction==="Forward")return d._1;if(f._2._1.direction==="Backward")return ke(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(tu(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(Or(2)(d._1));if(d.tag==="Nothing")return e.pure();g()}return e.pure()})(Me(i.tokens))}},G_=t=>e=>n=>r=>t.strokePath((()=>{const i=Bt(o=>T,o=>u=>w("Just",{head:o,tail:u}),O(o=>o.pt)(od(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+Ke(l)*d+f.value*n,y:e.y+Oe(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,...tJ(o=>[2,o.x,o.y])(i._1.tail)];if(i.tag==="Nothing")return[];g()})())({color:r,width:5.5,lineJoin:Te,lineCap:Dn}),_J=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=rn(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:Te,lineCap:Dn}))(()=>r)))(KN(x_(u)+7777|0)(u)(s))},P_=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=e.Applicative0(),o=rn(i),u=rn(i),s=ir.traverse(i),a=sJ(t),c=_J(t),f=t.popTransform;return d=>l=>_=>h=>m=>p=>y=>{const x=z=>n.bind(t.pushAlpha(z.alpha))(()=>n.bind(t.strokePath(z.path)({color:l.nodeStroke,width:2,lineJoin:Te,lineCap:Dn}))(()=>r)),N={family:l.fontFamily,size:l.wobble?15:11,weight:l.wobble?800:500},v=lo(`
|
|
8
|
+
`)(p.label===""?m:p.label),L=v.length===0?[""]:v,k=N.size*1.2,E=p.shape==="Cylinder"?t.strokePath(jx({x:p.x,y:p.y,w:p.w,h:p.h}))({color:l.nodeStroke,width:1.25,lineJoin:Te,lineCap:fn}):i.pure(),Q=(p.shape==="Cylinder"?(p.y+(p.y+p.h+5-2*nn(p.h*.075)(p.w*.075)))/2:(p.y+p.y+p.h)/2)-rt(L.length)*k/2+k/2,H=y.tag==="PloppingOut"&&l.wobble?y._1:-1,j=H>=0,S=Ko(y),C=j?{alpha:1,scale:1}:S,U=p.x+p.w/2,Y=p.y+p.h/2,W=n.bind(t.pushAlpha(C.alpha*_))(()=>n.bind(t.pushTransform({tx:U*(1-C.scale),ty:Y*(1-C.scale),sx:C.scale,sy:C.scale}))(()=>{const z={x:p.x,y:p.y,w:p.w,h:p.h},R={color:l.nodeStroke,width:l.wobble?2:1.25,lineJoin:Te,lineCap:l.wobble?Dn:fn};return n.bind((()=>{if(l.wobble){if(p.shape==="Rectangle")return o(x)(ZN(J_)(x_(z))(z));const G=ru(7)(p);return n.bind(o(x)((()=>{const I=Ri(G);return G.length<4?[]:qr(y_)(I)(!0)(G)})()))(()=>u(I=>o(x)((()=>{const D=Ri(I);return I.length<2?[]:qr(y_)(D)(!1)(I)})()))(p.shape==="Cylinder"?[RN(p)]:[]))}return n.bind(n_(t)(p.shape)(z)(7)(w("Just",{color:l.nodeFill,flat:!1}))(w("Just",R)))(()=>E)})())(()=>n.bind((()=>{if(h.tag==="Just"&&l.wobble&&!j){const G=h._1;return n.bind(s(a(N))(L))(I=>{const D=Lt(nt=>Z=>st.compare(nt.x)(Z.x)),B=de(dn(p.x*7919+p.y*3001))*-1640531535|0,q=ae(5)(7.5)(B),V=ae(0)(q.value)(q.prng),$=-(1+2*ae(-1)(1)(V.prng).value*3.141592653589793/180),X=(nt,Z,ut,ft,lt)=>D(xt(Nt=>Nt)([$*Z+nt>=ft&&$*Z+nt<=lt?w("Just",{x:Z,y:$*Z+nt}):T,$*ut+nt>=ft&&$*ut+nt<=lt?w("Just",{x:ut,y:$*ut+nt}):T,(()=>{const Nt=(ft-nt)/$;return Nt>=Z&&Nt<=ut?w("Just",{x:Nt,y:ft}):T})(),(()=>{const Nt=(lt-nt)/$;return Nt>=Z&&Nt<=ut?w("Just",{x:Nt,y:lt}):T})()])),M=q.value,et=Xn(G.frameHash)(3),tt=et===0?{r:200,g:35,b:30,a:220}:et===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},gt=p.x+p.w/2,_t=Fe(At(nt=>Z=>At((()=>{const ut=Q+rt(nt)*k,ft=gt-J(lt=>Nt=>lt+Nt.w)(0)(Z)/2;return lt=>Nt=>{const Ht=N.size*.1,Vt=lt-1|0,Pe=Vt>=0&&Vt<Z.length&<>0?(Z[Vt].x+Z[Vt].w+Nt.x)/2:Nt.x-Ht;return{x:ft+Pe-1,y:ut-Nt.up-1,w:Qi(0)((()=>{const un=lt+1|0;return un>=0&&un<Z.length&<<(Z.length-1|0)?(Nt.x+Nt.w+Z[un].x)/2-Pe:Nt.x+Nt.w+Ht-Pe})())+2,h:Nt.up+Nt.down+2}}})())(Z))(I)),ct=p.y+4,yt=p.x+p.w-4,Et=p.x+4,Rt=ct-$*Et+V.value,pt=p.y+p.h-4,Qt=Tt(Tt(At(nt=>Z=>{const ut=(Z.from.x+Z.to.x)/2,ft=(Z.from.y+Z.to.y)/2,lt=ae(-1)(1)(B+(911*(nt+1|0)|0)|0),Nt=ae(-3)(5)(lt.prng),Ht=lt.value*3.141592653589793/180,Vt=Ke(Ht),Pe=Oe(Ht),un=Ne=>({x:ut+(Ne.x-ut)*Vt-(Ne.y-ft)*Pe,y:ft+(Ne.x-ut)*Pe+(Ne.y-ft)*Vt});return{from:(()=>{const Ne=un(Z.from),St=Ne.y-ft,It=Ne.x-ut,je=Ee(It*It+St*St),Ze=je<1e-4?1:(je+Nt.value)/je;return{x:ut+It*Ze,y:ft+St*Ze}})(),to:(()=>{const Ne=un(Z.to),St=ae(-3)(5)(Nt.prng).value,It=Ne.y-ft,je=Ne.x-ut,Ze=Ee(je*je+It*It),kn=Ze<1e-4?1:(Ze+St)/Ze;return{x:ut+je*kn,y:ft+It*kn}})()}})(xt(nt=>{const Z=X(Rt+rt(nt)*M,Et,yt,ct,pt);return Z.length===2?w("Just",{from:Z[0],to:Z[1]}):T})(Dt(0,su(1)(de(dn((pt-$*yt-Rt)/M)))))))(nt=>at(Z=>Z.to.x-Z.from.x>1,J(Z=>ut=>Tt(Z)(ft=>{const lt=X(ft.from.y-$*ft.from.x,ut.x,ut.x+ut.w,ut.y,ut.y+ut.h);return lt.length===2?lt[0].x>ft.from.x+.001&<[1].x<ft.to.x-.001?[{from:ft.from,to:lt[0]},{from:lt[1],to:ft.to}]:lt[0].x<=ft.from.x+.001&<[1].x<ft.to.x-.001?[{from:lt[1],to:ft.to}]:lt[0].x>ft.from.x+.001&<[1].x>=ft.to.x-.001?[{from:ft.from,to:lt[0]}]:[]:[ft]}))([nt])(_t))))(nt=>(()=>{const Z=nt.to.x-nt.from.x;return Ee(2)*(Z>=0?Z:-Z)<=28})()?[nt]:[{from:nt.from,to:{x:nt.from.x+(nt.to.x-nt.from.x)*.495,y:nt.from.y+(nt.to.y-nt.from.y)*.495}},{from:{x:nt.from.x+(nt.to.x-nt.from.x)*.505,y:nt.from.y+(nt.to.y-nt.from.y)*.505},to:nt.to}]),Jt=Qt.length,mt=nt=>Qi(0)(b_(1)(G.t*rt(Jt)-rt(nt)));return o(nt=>{const Z=nt._1,ut=ae(1.4)(1.9)(B+(1303*(Z+1|0)|0)|0),ft=ae(.35)(.8)(ut.prng),lt=o(Nt=>n.bind(t.pushAlpha(Nt.alpha*ft.value))(()=>n.bind(t.strokePath(N_(mt(Z))(Nt.path))({color:tt,width:ut.value,lineJoin:Te,lineCap:Dn}))(()=>r)))(qr({...J_,rMax:0,offset:.5})(B+(53*(Z+1|0)|0)|0)(!1)([nt._2.from,nt._2.to]));return mt(Z)>0?lt:i.pure()})(At(Hn)(Qt))})}return i.pure()})())(()=>n.bind((()=>{if(d==="LabelsShown")return o(G=>t.drawText({x:p.x+p.w/2,y:Q+rt(G._1)*k,content:G._2,font:N,color:l.text,align:Uo,baseline:Mr}))(At(Hn)(L));if(d==="LabelsHidden")return i.pure();g()})())(()=>n.bind((()=>{const G=c(l)(z)(H);return j?G:i.pure()})())(()=>n.bind(f)(()=>r)))))}));return C.alpha*_>0?W:i.pure()}},dJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=P_(t),o=t.popAlpha,u=rn(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 m=l._1,p=_._1;return r.bind(t.pushAlpha(d._2))(()=>r.bind(i(ua)(f)(1)(T)(d._1)(p)(m))(()=>o))}return n.pure()})();return d._2>0?h:n.pure()})(Me(c.nodeInvert))}},I_=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 p=(1-d)/_;return p<0?0:p>1?1:p}if(l>1e-4&&d<l){const p=d/l;return p<0?0:p>1?1:p}return 1})(),m=C_(a)(c)(f)(d)(l)(_);if(m.tag==="CircleShape")return o?G_(t)(m._1)(m._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(tu(m._1)(m._2))({color:u,flat:!0})({color:s,width:1,lineJoin:Te,lineCap:fn});if(m.tag==="PolyShape"&&o&&m._1.length>=3)return r.bind(t.pushAlpha(h))(()=>r.bind(G_(t)(h_(m._1))(6)({r:200,g:35,b:30,a:220}))(()=>i));if(m.tag==="PolyShape")return o?n.pure():m._1.length>=3?t.fillStrokePath(d_(m._1))({color:u,flat:!0})({color:s,width:1,lineJoin:Te,lineCap:fn}):n.pure();g()}},hJ=t=>{const e=t.Monad0().Bind1(),n=t.popAlpha;return r=>i=>o=>u=>s=>a=>c=>{const f=Hr(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,m)=>e.bind(t.pushAlpha(m))(()=>e.bind(t.fillStrokePath(tu(h)(6))({color:r,flat:!0})({color:i,width:1,lineJoin:Te,lineCap:fn}))(()=>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)})())}},au=t=>{const e=lJ(t),n=hJ(t),r=t.Monad0().Applicative0(),i=rn(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 _=mr(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 ke(_._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(d_(ru(4)(Or(2)(d._1))))({color:a,flat:!0})({color:c,width:1,lineJoin:Te,lineCap:fn});if(d.tag==="Nothing")return r.pure();g()}return r.pure()})(Me(s.tokens))},D_=t=>{const e=au(t),n=t.Monad0(),r=n.Bind1(),i=au(t),o=fJ(t),u=t.popClip,s=t.popBlend,a=t.popLayer,c=n.Applicative0(),f=rn(c),d=t.popAlpha;return l=>_=>h=>m=>{const p=_.wobble?e(!0)(h)(m)(_.tokenInside)(_.tokenInsideStroke):r.bind(t.insideTokenStyle(l))(y=>{if(y==="GenieSilhouette")return i(!1)(h)(m)(_.tokenInside)(_.tokenInsideStroke);if(y==="ConvexAbsorb")return o(h)(m)(_.tokenInside)(_.tokenInsideStroke);g()});if(_.tokenInsideBlend==="Difference")return r.bind(t.pushLayer(Bx))(()=>r.bind(t.pushBlend(jo))(()=>r.bind(t.pushClip(aa(h)(m))(Zs))(()=>r.bind(p)(()=>r.bind(u)(()=>r.bind(s)(()=>r.bind(a)(()=>r.bind(t.pushLayer(Fx))(()=>r.bind(f(y=>{const x=fe(y._1)(m.nodes);return x.tag==="Just"&&Ko(x._1).alpha>0?n_(t)(y._2.shape)({x:y._2.x,y:y._2.y,w:y._2.w,h:y._2.h})(7)(w("Just",{color:re,flat:!1}))(T):c.pure()})(Me(h.nodes)))(()=>a)))))))));if(_.tokenInsideBlend==="Normal")return r.bind(t.pushClip(aa(h)(m))(Zs))(()=>r.bind(t.pushAlpha(_.tokenInsideAlpha))(()=>r.bind(p)(()=>r.bind(d)(()=>u))));g()}},A_=t=>{const e=t.Monad0().Bind1(),n=au(t),r=au(t),i=t.popClip,o=t.popLayer;return u=>s=>a=>c=>e.bind(t.pushLayer(Ax))(()=>e.bind(t.pushClip(uJ(s)(a)(c))(Qx))(()=>e.bind(u.wobble?n(!0)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke):r(!1)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke))(()=>e.bind(i)(()=>o))))},pJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=rn(r);return o=>u=>s=>a=>c=>f=>{const d=mo(f).length,l=rt(d+1|0),_=p=>{const y=(s*l-rt(p))/1.5,x=y<0?0:y>1?1:y;return x*x*(3-2*x)},h=(p=>{let y=p,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),m=h>=d?[]:or(p=>_(p)>0)(Dt(h,d-1|0)).init;return n.bind((()=>{const p=t.drawText({x:a,y:c,content:me(h)(f),font:o,color:u,align:js,baseline:Mr});return h>0?p:r.pure()})())(()=>i(p=>n.bind(t.measureText(o)(me(p)(f)))(y=>{const x=_(p);return t.drawText({x:a+y,y:c-(1-x)*10,content:me(1)(ci(Un(me(p)(f)))(f)),font:o,color:{...u,a:de(dn(x*rt(u.a)))},align:js,baseline:Mr})}))(m))}},cu=t=>e=>n=>r=>{const i=O(_=>rt(su(1)(mo(_).length)))(r),o=Qi(1)(J(Tr)(0)(i)),u=Hr(e)(n)(t),s=u*o,a=su(1)(r.length),c=(_=>h=>m=>{let p=_,y=h,x=m,N=!0,v;for(;N;){const L=p,k=y,E=Bt(Q=>T,Q=>H=>w("Just",{head:Q,tail:H}),x);if(E.tag==="Nothing"){N=!1,v=su(0)(a-1|0);continue}if(E.tag==="Just"){if(k+E._1.head>=s){N=!1,v=L;continue}p=L+1|0,y=k+E._1.head,x=E._1.tail;continue}g()}return v})(0)(0)(i),f=J(Tr)(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:_})()}},mJ=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})(cu(r)(0)(0)(O(K1)(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})})},yJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=mJ(t),i=e.Applicative0(),o=ir.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>k_(xt(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(T);g()}return i.pure(T)})(Me(s.tokens)))},xJ=t=>{const e=t.Monad0();return n=>r=>i=>o=>u=>s=>a=>{const c=S_(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})(cu(o)(u)(s)(Tt(a)(ca)).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}))}},NJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=xJ(t),i=e.Applicative0(),o=ir.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>k_(xt(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=mr(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 ke(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(T)})(Me(s.tokens)))},ga=t=>{const e=t.Monad0(),n=e.Bind1(),r=NJ(t),i=yJ(t);return o=>u=>n.bind(r(o)(u))(s=>n.bind(i(o)(u))(a=>e.Applicative0().pure(oJ((()=>{const c=f=>{if(f.tag==="Leaf")return A;if(f.tag==="Node")return Mt("Node",f._1,f._2,f._3,void 0,c(f._5),c(f._6));g()};return Lt(P.compare)(kt(We.foldr,c(s)))})())(s)([...xt(c=>{const f=fe(c._1)(u.nodes);return f.tag==="Just"&&Ko(f._1).alpha>0?w("Just",{x:c._2.x,y:c._2.y,w:c._2.w,h:c._2.h}):T})(Me(o.nodes)),...(()=>{const c=(f,d)=>{if(f.tag==="Leaf")return d;if(f.tag==="Node")return c(f._5,Ot("Cons",f._4,c(f._6,d)));g()};return kt($t.foldr,c(a,qt))})()]))))},B_=t=>e=>n=>{const r=pi(6)(.55)(uu(0)(1)((1-t)/.06)),i=t>.94,o=i&&n>1e-4,u=pi(6)(.55)(uu(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})()}},JJ=t=>{const e=t.Monad0().Bind1(),n=E_(t);return r=>i=>o=>u=>s=>{const a=B_(u)(0)(0),c={family:r.fontFamily,size:11,weight:500},f=cu(u)(0)(0)(Tt(s)(ca));return e.bind(t.measureText(c)(f.line))(d=>{const l=o.x+o.w/2,_=d+28,h=o.y-25.2-14,m=l-_/2,p=[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}))(T))(()=>e.bind(t.drawRoundedRect({x:m,y:h,w:_,h:25.2})(6)(w("Just",{color:r.chip,flat:!0}))(w("Just",{color:r.chipHairline,width:1,lineJoin:Te,lineCap:fn})))(()=>e.bind(t.strokePath(p)({color:r.chipHairline,width:1,lineJoin:Te,lineCap:fn}))(()=>t.drawText({x:l,y:y.y,content:f.line,font:c,color:r.chipText,align:Uo,baseline:Mr})))))})}},TJ=t=>{const e=E_(t),n=t.Monad0(),r=n.Bind1(),i=rn(n.Applicative0()),o=pJ(t);return u=>s=>a=>c=>f=>d=>l=>_=>h=>{const m=cu(f)(d)(l)(Tt(_)(ca)),p=m.line,y=m.phaseInLabel/.45,x=y<0?0:y>1?1:y,N=h.w,v=h.y,L=h.x,k=L+14,E=h.h,Q=v+E/2;return e(B_(f)(d)(l))(L)(v+E)({x:L+N/2,y:Q})(r.bind(i(H=>t.fillPath(tu(H)(1.5))({color:u.trailDot,flat:!0}))(aJ(h)(S_(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}))(T))(()=>o({family:u.fontFamily,size:11,weight:500})(u.chipPillText)(x)(k)(Q)(p))))}},fa=t=>{const e=TJ(t),n=t.Monad0(),r=n.Applicative0(),i=JJ(t),o=n.Bind1(),u=rn(r),s=t.popLayer;return a=>c=>f=>d=>o.bind(t.pushLayer(Rx))(()=>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),m=mr(l._2._1.edge)(c.edges),p=L_(l._1)(d);if(p.tag==="Just"&&m.tag==="Just"&&h.tag==="Just"&&_.tag==="Just")return e(a)((()=>{if(l._2._1.direction==="Forward")return m._1;if(l._2._1.direction==="Backward")return ke(m._1);g()})())(h._1)(_._1)(l._2._1.progress)(l._2._1.holdPre)(l._2._1.holdPost)(l._2._1.labels)(p._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()})(Me(f.tokens)))(()=>s))},F_=t=>{const e=ga(t),n=fa(t);return r=>i=>o=>t.Monad0().Bind1().bind(e(i)(o))(u=>n(r)(i)(o)(u))},vJ=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]):T,c=i.length-1|0,f=c>=0&&c<i.length?w("Just",i[c]):T;if(f.tag==="Just"&&a.tag==="Just"){const d=ae(.78)(1.18)(Ri(i)+19|0),l=ae(.4)(.62)(d.prng),_=r.wobble?8.75*l.value:4.375,h=ae(.4)(.62)(l.prng),m=r.wobble?8.75*h.value:4.375,p=f._1.y-a._1.y,y=f._1.x-a._1.x,x=Ee(y*y+p*p),N=p/x,v=-N,L=y/x,k=f._1.x+L*.875,E=f._1.y+N*.875,Q=r.wobble?8.75*d.value:8.75,H=k-L*Q,j=E-N*Q,S=H+v*_,C=j+L*_,U=[1,k,E,2,H+v*4.375,j+L*4.375,2,H-v*4.375,j-L*4.375,5],Y=H-v*m,W=j-L*m,z={color:r.arrowFill,width:2,lineJoin:Te,lineCap:Dn};return x<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,S,C,2,k,E])(z))(()=>t.strokePath([1,Y,W,2,k,E])(z)):t.fillPath(U)({color:r.arrowFill,flat:!0})}return n.pure()}},wJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=rn(n),o=t.popAlpha,u=vJ(t);return s=>a=>c=>f=>{const d=PN(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:Te,lineCap:Dn},h=s.wobble?ae(-10)(4)(Ri(l)).value:0,m=s.wobble?YN(h)(l):l;return r.bind(s.wobble?i(p=>r.bind(t.pushAlpha(p.alpha))(()=>r.bind(t.strokePath(p.path)(_))(()=>o)))((()=>{const p=Ri(l);return m.length<2?[]:qr(gJ)(p)(!1)(m)})()):t.strokePath(EN(l))(_))(()=>{const p=u(s)(m);return f.hi>=.999?p:n.pure()})}},R_=t=>{const e=wJ(t),n=t.Monad0().Applicative0(),r=rn(n);return i=>o=>u=>r(s=>{const a=mr(s._1)(u.edges);if(a.tag==="Just")return e(i)(s._1)(s._2)((()=>{if(a._1.tag==="Retracted")return{lo:0,hi:0};if(a._1.tag==="Extended")return{lo:0,hi:1};if(a._1.tag==="Extending")return{lo:0,hi:a._1._2};if(a._1.tag==="Retracting"){if(a._1._1==="FromSource")return{lo:a._1._2,hi:1};if(a._1._1==="FromTarget")return{lo:0,hi:1-a._1._2};if(a._1._1==="FromBoth")return{lo:a._1._2/2,hi:1-a._1._2/2}}g()})());if(a.tag==="Nothing")return n.pure();g()})(Me(o.edges))},bJ=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!Re(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,Me(t.edges))}g()},r=J(o=>u=>(o*31|0)+Sn(u)|0)(5381)(Vn(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!Re(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},Me(t.edges))}g()};return J(o=>u=>{const s=u._2;return eJ(a=>{if(a.tag==="Nothing")return w("Just",s);if(a.tag==="Just")return w("Just",{t:Qi(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)(Tt(Me(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=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):T)(Me(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?ur(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=mr(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?ur(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=mr(o._2._1.edge)(t.edges);if(u.tag==="Just")return 1<u._1.length&&0<u._1.length?ur(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[]}))},LJ=t=>J(e=>n=>(e*31|0)+Sn(n)|0)(5381)(Vn(t.frameTitle)),Q_=t=>{const e=P_(t),n=t.Monad0().Applicative0(),r=rn(n);return i=>o=>u=>s=>{const a=LJ(s),c=bJ(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"&&nJ(f._1)(s.visited)?w("Just",{t:1,angle:0,bigCircle:!1,frameHash:a}):T})())(f._1)(f._2)(d._1);if(d.tag==="Nothing")return n.pure();g()})(Me(u.nodes))}},z_=t=>t,W_=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},kJ=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()},M_=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},H_=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},_a=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},EJ=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},CJ=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},SJ=t=>e=>{const n=Oe(t.angle),r=Ke(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},GJ=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],$r=t=>e=>{const n=r=>kJ(0)(255)(de(Yn(rt(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},Se=t=>e=>n=>r=>({x:(e-n)*Ke(t.angle),y:(e+n)*Oe(t.angle)-r}),yr=t=>{const e=Bt(n=>T,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()},PJ=t=>e=>n=>r=>i=>{const o=(()=>{if(t==="Forward")return i;if(t==="Backward")return ke(i);g()})();if(0<o.length){const s=vr(o)(M_(0)(1)(Hr(n)(r)(e)));if(s.tag==="Nothing")return o[0];if(s.tag==="Just")return s._1;g()}const u=vr(o)(M_(0)(1)(Hr(n)(r)(e)));if(u.tag==="Nothing")return{x:0,y:0};if(u.tag==="Just")return u._1;g()},IJ=t=>{const e=Bt(n=>T,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()},DJ=t=>{const e=Bt(n=>T,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=J(r=>i=>({minX:H_(r.minX)(i.x),minY:H_(r.minY)(i.y),maxX:_a(r.maxX)(i.x),maxY:_a(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()},AJ=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>{const o=i.box,u=i.np,s={color:r.nodeStroke,width:1,lineJoin:Te,lineCap:fn};return e.bind(t.fillStrokePath(yr([o.ground.d,o.ground.c,o.top.c,o.top.d]))({color:$r(.66)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(yr([o.ground.b,o.ground.c,o.top.c,o.top.b]))({color:$r(.82)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(yr([o.top.a,o.top.b,o.top.c,o.top.d]))({color:$r(1)(r.nodeFill),flat:!0})(s))(()=>t.drawTextAffine(SJ(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:Uo,baseline:Mr}))))}},BJ=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>o=>{const u={color:r.tokenOutsideStroke,width:1,lineJoin:Te,lineCap:fn},s=o.x-5.5,a=o.x+5.5,c=o.y-5.5,f=o.y+5.5,d=i+11,l=Se(n)(s)(c)(d),_=Se(n)(a)(c)(d),h=Se(n)(a)(f)(d),m=Se(n)(s)(f)(d),p=Se(n)(a)(f)(i),y=Se(n)(a)(c)(i);return e.bind(t.fillStrokePath(yr([Se(n)(s)(f)(i),p,h,m]))({color:$r(.66)(r.tokenOutsideFill),flat:!0})(u))(()=>e.bind(t.fillStrokePath(yr([y,p,h,_]))({color:$r(.82)(r.tokenOutsideFill),flat:!0})(u))(()=>t.fillStrokePath(yr([l,_,h,m]))({color:$r(1)(r.tokenOutsideFill),flat:!0})(u)))}},FJ=t=>{const e=BJ(t);return n=>r=>i=>o=>{if(o.tag==="Travelling"){const u=EJ(o._1.edge)(i.edges);return u.tag==="Just"?w("Just",(()=>{const s=PJ(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)}})()):T}if(o.tag==="Filling"){const u=CJ(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 T}},RJ={angle:.5235987755982988,boxHeight:26,transparentBg:!0},QJ=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:Se(t)(e.x)(e.y)(0),b:Se(t)(r)(e.y)(0),c:Se(t)(r)(n)(0),d:Se(t)(e.x)(n)(0)},top:{a:Se(t)(e.x)(e.y)(t.boxHeight),b:Se(t)(r)(e.y)(t.boxHeight),c:Se(t)(r)(n)(t.boxHeight),d:Se(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},O_=t=>e=>O(n=>({np:n,box:QJ(t)(n)}))((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._4,n(r._6,i)));g()};return kt($t.foldr,n(e.nodes,qt))})()),zJ=t=>e=>[...Tt(O_(t)(e))(GJ),...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._4,n(r._6,i)));g()};return Tt(kt($t.foldr,n(e.edges,qt)))(O(r=>Se(t)(r.x)(r.y)(0)))})()],WJ=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=_a(1e-4)(Ee(n*n+e*e)),i=e/r,o=n/r,u=t.to.y-i*7,s=t.to.x-o*7;return yr([t.to,{x:s-i*3,y:u+o*3},{x:s+i*3,y:u-o*3}])},MJ=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>i=>o=>u=>s=>{const a=Se(r)(s.x)(s.y)(0),c=Se(r)(u.x)(u.y)(0);return e.Bind1().bind(t.strokePath(IJ([c,a]))({color:i.edge,width:1.5,lineJoin:Te,lineCap:Dn}))(()=>{const f=t.fillPath(WJ({from:c,to:a}))({color:i.arrowFill,flat:!0});return o?f:n.pure()})}},HJ=t=>{const e=MJ(t);return n=>r=>i=>{const o=Je(Hn,i,bt(1,i.length,i)),u=o.length-1|0;return At(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)}},OJ=t=>{const e=AJ(t),n=FJ(t),r=HJ(t),i=t.Monad0(),o=I_(t),u=Ju(i.Applicative0())(zt);return s=>a=>c=>f=>{const d=sa(a),l=[...(()=>{const _=(h,m)=>{if(h.tag==="Leaf")return m;if(h.tag==="Node")return _(h._5,Ot("Cons",h._4,_(h._6,m)));g()};return Tt(kt($t.foldr,_(c.edges,qt)))(r(s)(d))})(),...O(_=>({depth:_.box.depth,draw:e(s)(d)(_)}))(O_(s)(c)),...xt(n(s)(d)(c))((()=>{const _=(h,m)=>{if(h.tag==="Leaf")return m;if(h.tag==="Node")return _(h._5,Ot("Cons",h._4,_(h._6,m)));g()};return kt($t.foldr,_(f.tokens,qt))})())];return i.Bind1().bind(o(d)(s.transparentBg)(1)(DJ(zJ(s)(c))))(()=>u(_=>_.draw)(Lt(_=>h=>st.compare(_.depth)(h.depth))(l)))}},q_=(t,e)=>({tag:t,_1:e}),qJ=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},YJ=q_("ResolvedLabels"),XJ=t=>{const e=Xt(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return wo(t);g()},VJ=t=>e=>n=>{const r=n.frameTitle===""?0:40,i=Xu(e)(n.camera);return(()=>{if(t.outputAspect.tag==="Nothing")return z_;if(t.outputAspect.tag==="Just")return W_(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})},UJ=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=qJ(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()},jJ=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:Te,lineCap:Dn})))(()=>t.drawText({x:l,y:c+f/2,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:Uo,baseline:Mr}))})}},ZJ=t=>{const e=F_(t),n=fa(t),r=t.Monad0(),i=r.Bind1(),o=I_(t),u=r.Applicative0(),s=R_(t),a=Q_(t)(ua),c=dJ(t),f=A_(t),d=D_(t),l=jJ(t);return _=>h=>m=>p=>y=>x=>N=>{const v=sa(_.theme),L=(()=>{if(N.tag==="ResolvedLabels")return e(v)(y)(x);if(N.tag==="SpringLabels")return n(v)(y)(x)(N._1);g()})();return i.bind(o(v)(_.transparentBg)(h)(p))(()=>i.bind((()=>{const k=i.bind(s(v)(y)(x))(()=>i.bind(a(v)(y)(x))(()=>i.bind(c(v)(y)(x))(()=>i.bind(f(v)(p)(y)(x))(()=>i.bind(d(Hx)(v)(y)(x))(()=>L)))));return m?k:u.pure()})())(()=>i.bind(_.watermark===""?t.Monad0().Applicative0().pure():t.drawText({x:p.vx+6,y:p.vy+6,content:_.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:js,baseline:Dx}))(()=>l(x.frameTitle)(p))))}},KJ=t=>{const e=t.Monad0(),n=F_(t),r=fa(t),i=e.Bind1(),o=R_(t),u=Q_(t),s=A_(t),a=t.popTransform,c=D_(t),f=t.popBakedTransform,d=t.popClip,l=t.popAlpha;return _=>h=>m=>p=>y=>{const x=y.state,N={tx:y.segment.placement.tx,ty:y.segment.placement.ty,sx:y.segment.placement.scale,sy:y.segment.placement.scale},v=sa(_.theme),L=y.segment.layout,k=Ye(L),E={vx:k.x-1e3,vy:k.y-1e3,vw:k.w+2e3,vh:k.h+2e3},Q=11*y.segment.placement.scale*h>=5?ua:rJ,H=(()=>{if(Q==="LabelsHidden")return e.Applicative0().pure();if(Q==="LabelsShown")return m.tag==="Leaf"?n(v)(L)(x):r(v)(L)(x)(m);g()})(),j=UJ(p)((()=>{const S=y.segment.path.length-1|0;return S>=0&&S<y.segment.path.length?w("Just",y.segment.path[S]):T})());return i.bind(t.pushAlpha(y.bgAlpha))(()=>i.bind(t.pushClip(j)(Zs))(()=>i.bind(t.pushTransform(N))(()=>i.bind(o(v)(L)(x))(()=>i.bind(u(Q)(v)(L)(x))(()=>i.bind(s(v)(E)(L)(x))(()=>i.bind(a)(()=>i.bind(t.pushBakedTransform(N))(()=>i.bind(c(Ox)(v)(L)(x))(()=>i.bind(f)(()=>i.bind(t.pushTransform(N))(()=>i.bind(H)(()=>i.bind(a)(()=>i.bind(d)(()=>l))))))))))))))}},tT=t=>e=>{const n=Xu(t)(e);return{vx:n.x,vy:n.y,vw:n.w,vh:n.h}},Yr=t=>e=>e.diving||e.levels.length>1?(()=>{if(t.outputAspect.tag==="Nothing")return z_;if(t.outputAspect.tag==="Just")return W_(t.outputAspect._1);g()})()(tT(e.rootLayout)(e.camera)):VJ(t)(e.rootLayout)({...wo(e).state,camera:e.camera}),$_=t=>{const e=OJ(t),n=t.Monad0(),r=n.Applicative0(),i=n.Bind1(),o=KJ(t),u=ZJ(t);return s=>a=>c=>{if(s.theme==="Isometric")return e({...RJ,transparentBg:s.transparentBg})(s.theme)(wo(c).segment.layout)(wo(c).state);const f=Yr(s)(c),d=_=>h=>{if(h.length===0)return r.pure();const m=Bt(p=>T,p=>y=>w("Just",{head:p,tail:y}),h);if(m.tag==="Nothing")return r.pure();if(m.tag==="Just"){const p=m._1.head,y=m._1.tail;return i.bind((()=>{const x=o(s)(c.camera.zoom)(p.role==="Active"?a:A)(_)(p);return c.diving||p.role==="Active"?x:r.pure()})())(()=>d(p)(y))}g()},l=Bt(_=>T,_=>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/$J(1)(Ye(c.rootLayout).w):1)(h.role==="Active"||h.role==="FlyThrough")(f)(h.segment.layout)(XJ(c).state)(_.length===0&&a.tag!=="Leaf"?q_("SpringLabels",a):YJ))(()=>d(h)(_))}g()}},Y_=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},eT=ga(o_),X_=$_(o_),V_=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 A;if(u.tag==="Node")return Mt("Node",u._1,u._2,u._3,{...u._4,x:Y_(r)(e-u._4.w)(u._4.x),y:Y_(i)(n-u._4.h)(u._4.y)},o(u._5),o(u._6));g()};return o},nT=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?T:w("Just",r.width/r.height)},a=iN(n)(r);return()=>{const c=a(),f=i.levels.length-1|0;if(f>=0&&f<i.levels.length){const l=eT(i.levels[f].segment.layout)(i.levels[f].state)(c)(),_=Vs(o)(V_(Yr(s)(i))(l))(u);return X_(s)(_.applied)(i)(c)(),_.springs}const d=Vs(o)(V_(Yr(s)(i))(A))(u);return X_(s)(d.applied)(i)(c)(),d.springs}},rT=t=>t,iT=(t=>t)("Light"),oT=rT("TransparentBackground"),nr=t=>"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")",bn=oi(ri("Fixed",ii(0)(20)(4))),uT=t=>"translate("+bn(t.tx)+","+bn(t.ty)+") scale("+bn(t.sx)+","+bn(t.sy)+")",wt=oi(ri("Fixed",ii(0)(20)(2))),da=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,i=r>=0&&r<t.length?w("Just",t[r]):T;if(i.tag==="Nothing"){n=t.length;continue}if(i.tag==="Just"){if(i._1===1){e.push("M"),e.push(wt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{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(wt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{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(wt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{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(wt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+5|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{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 ho(" ")(e)},sT={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},la=(()=>{const t=Zn("&")("&"),e=Zn("<")("<"),n=(()=>{const r=Zn(">")(">"),i=(()=>{const o=Zn('"')(""");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),aT=t=>{if(t.style==="RunText")return"<tspan>"+la(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+la(t.text)+"</tspan>";g()},Ae=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},cT=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]):T;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},gu=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return cT(r._1)(e);g()}},U_={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>sT},gT={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>U_},fT={pure:t=>e=>()=>t,Apply0:()=>U_},_T={Applicative0:()=>fT,Bind1:()=>gT},dT=t=>e=>'<defs><pattern id="'+t+'" x="0" y="0" width="'+wt(e.tile)+'" height="'+wt(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+wt(e.tile)+'" height="'+wt(e.tile)+'" fill="'+nr(e.bgColor)+'" fill-opacity="'+wt(rt(e.bgColor.a)/255)+'"/>')+'<circle cx="'+wt(e.tile/2)+'" cy="'+wt(e.tile/2)+'" r="'+wt(e.dotRadius)+'" fill="'+nr(e.dotColor)+'"/></pattern></defs><rect x="'+wt(e.viewport.vx)+'" y="'+wt(e.viewport.vy)+'" width="'+wt(e.viewport.vw)+'" height="'+wt(e.viewport.vh)+'" fill="url(#'+t+')"/>',j_=t=>e=>'<path d="'+da(t)+'" fill="'+nr(e)+'" fill-opacity="'+wt(rt(e.a)/255)+'"/>',lT=t=>e=>n=>r=>'<rect x="'+wt(t.x)+'" y="'+wt(t.y)+'" width="'+wt(t.w)+'" height="'+wt(t.h)+'" rx="'+wt(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+nr(n._1.color)+'" fill-opacity="'+wt(rt(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';g()})()+(()=>{if(r.tag==="Just")return' stroke="'+nr(r._1.color)+'" stroke-opacity="'+wt(rt(r._1.color.a)/255)+'" stroke-width="'+wt(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()})()+"/>",Z_=t=>e=>'<path d="'+da(t)+'" fill="none" stroke="'+nr(e.color)+'" stroke-opacity="'+wt(rt(e.color.a)/255)+'" stroke-width="'+wt(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()})()+'"/>',K_=t=>{const e=eg(Ir(t.content));return'<text x="'+wt(t.x)+'" y="'+wt(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="'+nr(t.color)+'" fill-opacity="'+wt(rt(t.color.a)/255)+'" font-size="'+wt(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+ie(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"?la(e[0].text):ho("")(O(aT)(e)))+"</text>"},hT=t=>"matrix("+bn(t.a)+" "+bn(t.b)+" "+bn(t.c)+" "+bn(t.d)+" "+bn(t.e)+" "+bn(t.f)+")",t1={fillPath:t=>e=>n=>{const r=gu(n)(t);return()=>{const i=r();return Ae(j_(i)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=gu(n)(t);return()=>{const i=r(),o=n.bake.value;return Ae(Z_(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=gu(r)(t);return()=>{const o=i(),u=r.bake.value;return Ae(j_(o)(e.color)+Z_(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(lT((()=>{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()})()):T))(i)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return Ae(K_((()=>{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="'+hT(t)+'"';return(n===""?"<g>":"<g "+n+">")+K_(e)+"</g>"})()),pushTransform:t=>Ae((()=>{const e='transform="'+uT(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=T}},pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const i=r.value;n.clipCounter.value=i+1|0;const o=gu(n)(t)(),u="clip"+ie(i);return Ae((()=>{const s='clip-path="url(#'+u+')"';return'<defs><clipPath id="'+u+'"><path d="'+da(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="'+wt(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="'+wt(e.viewport.vx)+'" y="'+wt(e.viewport.vy)+'" width="'+wt(e.viewport.vw)+'" height="'+wt(e.viewport.vh)+'" fill="'+nr(t)+'" opacity="'+wt(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(dT("bg-dots-"+ie(r))(t))(e)()}},measureText:t=>e=>n=>{const r=Af(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Bf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>qf,Monad0:()=>_T},pT=$_(t1),mT=ga(t1),yT=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=Yr(o)(i);return{viewBox:wt(u.vx)+" "+wt(u.vy)+" "+wt(u.vw)+" "+wt(u.vh),body:(()=>{const s=[],a={value:0},c={value:0},f={value:0},d={value:T};return pT(o)(e)(i)({out:s,maskDepth:a,clipCounter:c,patternCounter:f,viewport:u,bake:d})(),ho("")(s)})(),vx:u.vx,vy:u.vy,vw:u.vw,vh:u.vh}},xT=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=Vs(i)((()=>{const a=[],c={value:0},f={value:0},d={value:0},l={value:T},_=r.levels.length-1|0;return _>=0&&_<r.levels.length?mT(r.levels[_].segment.layout)(r.levels[_].state)({out:a,maskDepth:c,clipCounter:f,patternCounter:d,viewport:Yr(u)(r),bake:l})():A})())(o);return{parts:yT(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:()=>e1(t)}),e1=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=>Wi(t).pure(u(s))))})(),Functor0:()=>n}},Wi=t=>({pure:e=>n=>t.Applicative0().pure(b(e,n)),Apply0:()=>e1(t)}),NT=t=>{const e={Applicative0:()=>Wi(t),Bind1:()=>zi(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},ha=(t,e)=>({tag:t,_1:e}),Rn=(t,e)=>({tag:t,_1:e}),ve=NT(Mn),Wt=zi(Mn),Be=ve.state(t=>b(t,t)),ue=Wi(Mn),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=P.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},n1=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=P.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},fu=Ju(ue)(zt),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=P.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},JT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},TT=(()=>{const t=qe.unfoldr(e=>{if(e.tag==="Nil")return T;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,Ot("Cons",r._3,n(r._6,i)));g()};return n(e,qt)})())})(),vT=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=P.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},_u=t=>e=>n=>J(r=>i=>t.Bind1().bind(r)(o=>e(o)(i)))(t.Applicative0().pure(n)),wT=J(t=>e=>K(P)(e)()(t))(A),bT=(()=>{const t=(e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=K(P)(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,Ot("Cons",r._3,n(r._6,i)));g()};return n(e,qt)})())})(),LT=Rn("Exit"),kT=t=>ha("Par",t),r1=t=>ha("Seq",t),ET=t=>e=>n=>{const r=On(Yt,T,i=>i._1===t,n);if(r.tag==="Just"){const i=qn(Yt,T,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 Ft(n)(b(t,e));g()},CT=t=>e=>O(n=>n._1===t?b(n._1,{...n._2,label:w("Just",e)}):b(n._1,n._2)),we=t=>ve.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()})())),ST=t=>Wt.bind(ve.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>Wt.bind(Be)(e=>{if(e.error.tag==="Just")return ue.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!Qn(t.op._1.id)(e.currNodes))return we("cannot enter node "+t.op._1.id+": does not exist");if(!n1(t.op._1.id)(e.interiorOf))return we("cannot enter node "+t.op._1.id+": it has no `inside` block");if(Qe(gn)(t.op._1.id)(e.enterStack))return we("cannot enter node "+t.op._1.id+": already entered");const n=t.op._1;return ve.state(r=>b(void 0,{...r,enterStack:Ft(r.enterStack)(n.id),scenes:Ft(r.scenes)(ao("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=Xi(e.enterStack);if(n.tag==="Nothing")return we("`exit` without a matching `enter`");if(n.tag==="Just"){const r=n._1.init;return ve.state(i=>b(void 0,{...i,enterStack:r,scenes:Ft(i.scenes)(Dl)}))}g()}return ue.pure()}g()})),GT=t=>Wt.bind(Be)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ie(e.kfCounter);if(Re(i=>i.id===n,e.keyframes))return we("duplicate frame name "+n);const r={...e,keyframes:Ft(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges}),kfCounter:e.kfCounter+1|0,currentKf:w("Just",n)};return ve.state(i=>b(void 0,r))}),PT=fu(t=>Wt.bind(Be)(e=>{if(e.error.tag==="Just")return ue.pure();if(e.error.tag==="Nothing")return n1(t.node)(e.interiorOf)?we("node "+t.node+" has more than one `inside` block"):ve.state(n=>b(void 0,{...n,interiorOf:K(P)(t.node)(t.doc)(n.interiorOf)}));g()})),IT=t=>e=>{const n=e.from+"->"+e.to,r=e.newFrom+"->"+e.newTo,i=Gt("Left","cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist"),o=zn(n)(t.currEdges)?Gt("Right",void 0):i;return(()=>{if(o.tag==="Left"){const u=o._1;return s=>Gt("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(!Qn(e.newFrom)(t.currNodes))return Gt("Left",u);const s="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo;if(!Qn(e.newTo)(t.currNodes))return Gt("Left",s);const a="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists";return n!==r&&zn(r)(t.currEdges)?Gt("Left",a):Gt("Right",{nextCurrEdges:K(P)(r)()(ni(P)(n)(t.currEdges)),newId:r,newEdge:{id:r,from:{node:e.newFrom,port:T},to:{node:e.newTo,port:T}}})})},i1={graphNodes:[],graphEdges:A,currNodes:A,currEdges:A,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:T,currentLine:0,currentColumn:0,error:T,enterStack:[],interiorOf:A},o1=t=>e=>Wt.bind(Be)(n=>{const r="ev-"+ie(n.eventCounter);return Wt.bind((()=>{const i={...n,eventCounter:n.eventCounter+1|0};return ve.state(o=>b(void 0,i))})())(()=>ue.pure({events:[{id:r,kind:e,when:t}],firstId:w("Just",r),lastId:w("Just",r)}))}),DT=t=>e=>{if(e.tag==="Token"){const n=e._1;return Wt.bind(Be)(r=>{const i=!Qn(n.from)(r.currNodes),o=!Qn(n.to)(r.currNodes);if(i||o)return Wt.bind(we(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: "))(()=>ue.pure({events:[],firstId:T,lastId:T}));const u=n.to+"->"+n.from,s=n.from+"->"+n.to;return zn(s)(r.currEdges)?o1(t)(dc("SendToken",{from:n.from,to:n.to,edge:s,direction:Pl,labels:n.labels})):zn(u)(r.currEdges)?o1(t)(dc("SendToken",{from:n.from,to:n.to,edge:u,direction:Il,labels:n.labels})):Wt.bind(we("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>ue.pure({events:[],firstId:T,lastId:T}))})}return ue.pure({events:[],firstId:T,lastId:T})},AT=t=>e=>{if(0<t.length){const n=t[0];return Wt.bind(ve.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>we(e))}return we(e)},BT=t=>xt(e=>JT(e)(t.graphEdges))(kt(Kr,TT(t.currEdges))),FT=t=>e=>{const n=at(i=>i.from.node===e.id||i.to.node===e.id,BT(t)),r=_u(Ia)(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(!zn(u)(t.currEdges))return Gt("Left",c);const f="via "+o.from+" "+o.to+": no edge "+e.id+"\u2192"+o.to;if(!zn(s)(t.currEdges))return Gt("Left",f);const d="via "+o.from+" "+o.to+": would create "+o.from+"\u2192"+o.to+" but it already exists";return zn(a)(t.currEdges)||vT(a)(i.synthesized)?Gt("Left",d):Gt("Right",{consumed:K(P)(u)()(K(P)(s)()(i.consumed)),synthesized:K(P)(a)({id:a,from:{node:o.from,port:T},to:{node:o.to,port:T}})(i.synthesized)})})({consumed:A,synthesized:A})(e.via);return(()=>{if(r.tag==="Left"){const i=r._1;return o=>Gt("Left",i)}if(r.tag==="Right"){const i=r._1;return o=>o(i)}g()})()(i=>{const o=i.consumed,u=at(s=>!zn(s.id)(o),n);return u.length===0?Gt("Right",{nextCurrEdges:Ce(P.compare,Le,Cn(P.compare,t.currEdges,wT(O(s=>s.id)(n))),bT((()=>{const s=a=>{if(a.tag==="Leaf")return A;if(a.tag==="Node")return Mt("Node",a._1,a._2,a._3,void 0,s(a._5),s(a._6));g()};return s(i.synthesized)})())),synthesized:i.synthesized}):Gt("Left","cannot delete node "+e.id+": still connected ("+ho(", ")(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.")})},u1=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq")return Tt(t._1)(u1);g()},RT=Wt.bind(Be)(t=>{if(t.error.tag==="Just")return ue.pure();if(t.error.tag==="Nothing"){const e=t.enterStack.length-1|0;return e>=0&&e<t.enterStack.length?we("entered node "+t.enterStack[e]+" was never exited"):ue.pure()}g()}),QT=t=>({nodes:O($i)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Ot("Cons",n._4,e(n._6,r)));g()};return kt($t.foldr,e(t.graphEdges,qt))})(),constraints:[]}),zT=t=>{if(t.tag==="AddNode"){const e=t._1;return ve.state(n=>b(void 0,{...n,graphNodes:ET(e.id)({id:e.id,size:b(1,1),ports:[],label:w("Just",e.label),shape:e.shape})(n.graphNodes),currNodes:K(P)(e.id)()(n.currNodes)}))}if(t.tag==="DelNode"){const e=t._1;return Wt.bind(Be)(n=>{if(!Qn(e.id)(n.currNodes))return we("cannot delete node "+e.id+": does not exist");const r=FT(n)(e);if(r.tag==="Left")return we(r._1);if(r.tag==="Right"){const i=r._1;return ve.state(o=>b(void 0,{...o,currNodes:ni(P)(e.id)(o.currNodes),currEdges:i.nextCurrEdges,graphEdges:Ce(P.compare,Le,i.synthesized,o.graphEdges)}))}g()})}if(t.tag==="ModNode"){const e=t._1;return Wt.bind(Be)(n=>{if(!Qn(e.id)(n.currNodes))return we("cannot modify node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=e.label._1;return ve.state(i=>b(void 0,{...i,graphNodes:CT(e.id)(r)(i.graphNodes)}))}if(e.label.tag==="Nothing")return ue.pure();g()})}if(t.tag==="AddEdge"){const e=t._1;return Wt.bind(Be)(n=>{const r=!Qn(e.from)(n.currNodes),i=!Qn(e.to)(n.currNodes);if(r||i)return we("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 ve.state(u=>b(void 0,{...u,graphEdges:K(P)(o)({id:o,from:{node:e.from,port:T},to:{node:e.to,port:T}})(u.graphEdges),currEdges:K(P)(o)()(u.currEdges)}))})}if(t.tag==="DelEdge"){const e=t._1;return Wt.bind(Be)(n=>{const r=e.from+"->"+e.to;return zn(r)(n.currEdges)?ve.state(i=>b(void 0,{...i,currEdges:ni(P)(r)(i.currEdges)})):we("cannot delete edge "+e.from+"\u2192"+e.to+": does not exist")})}if(t.tag==="RepointEdge"){const e=t._1;return Wt.bind(Be)(n=>{const r=IT(n)(e);if(r.tag==="Left")return we(r._1);if(r.tag==="Right"){const i=r._1;return ve.state(o=>b(void 0,{...o,currEdges:i.nextCurrEdges,graphEdges:K(P)(i.newId)(i.newEdge)(o.graphEdges)}))}g()})}return ue.pure()},WT=t=>Wt.bind(ve.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>zT(t.op)),MT=t=>e=>Wt.bind(fu(WT)(e))(()=>Wt.bind(Be)(n=>{const r=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ie(n.kfCounter);if(Re(o=>o.id===r,n.keyframes))return we("duplicate frame name "+r);const i={...n,keyframes:Ft(n.keyframes)({id:r,nodes:n.currNodes,edges:n.currEdges}),kfCounter:n.kfCounter+1|0,currentKf:w("Just",r),scenes:(()=>{if(n.currentKf.tag==="Nothing")return n.scenes;if(n.currentKf.tag==="Just")return Ft(n.scenes)(ao("Structural",{from:n.currentKf._1,to:r,focus:T}));g()})()};return ve.state(o=>b(void 0,i))})),HT=t=>e=>{const n=Bt(r=>T,r=>i=>w("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return ue.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return Wt.bind(Mi(t)(n._1.head))(i=>Wt.bind(_u({Applicative0:()=>Wi(Mn),Bind1:()=>zi(Mn)})(o=>u=>Wt.bind(Mi((()=>{if(o.lastId.tag==="Just")return $u("After",o.lastId._1);if(o.lastId.tag==="Nothing")return t;g()})())(u))(s=>ue.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=>ue.pure(o)))}g()},OT=t=>e=>{const n=Bt(r=>T,r=>i=>w("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return ue.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return Wt.bind(Mi(t)(n._1.head))(i=>Wt.bind(qT((()=>{if(i.firstId.tag==="Just")return $u("With",i.firstId._1);if(i.firstId.tag==="Nothing")return t;g()})())(r))(o=>ue.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()},Mi=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return Wt.bind(ve.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>DT(t)(n.op))}if(e.tag==="Seq")return HT(t)(e._1);if(e.tag==="Par")return OT(t)(e._1);g()},qT=t=>_u({Applicative0:()=>Wi(Mn),Bind1:()=>zi(Mn)})(e=>n=>Wt.bind(Mi(t)(n))(r=>ue.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:T,lastId:T}),$T=t=>Wt.bind(Be)(e=>{if(e.currentKf.tag==="Nothing")return we("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return Wt.bind(Mi(Gl)(t))(r=>Wt.bind(Be)(i=>{const o={...i,scenes:Ft(i.scenes)(ao("DataFlow",{keyframe:n,events:r.events,focus:T}))};return ve.state(u=>b(void 0,o))}))}g()}),YT=t=>Wt.bind(Be)(e=>{if(e.error.tag==="Just")return ue.pure();if(e.error.tag==="Nothing"){const n=u1(t.ops),r=at(u=>u.op.tag==="AddNode"||u.op.tag==="DelNode"||u.op.tag==="ModNode"||u.op.tag==="AddEdge"||u.op.tag==="DelEdge"||u.op.tag==="RepointEdge",n),i=at(u=>u.op.tag==="Enter"||u.op.tag==="Exit",n),o=at(u=>!(u.op.tag==="AddNode"||u.op.tag==="DelNode"||u.op.tag==="ModNode"||u.op.tag==="AddEdge"||u.op.tag==="DelEdge"||u.op.tag==="RepointEdge")&&!(u.op.tag==="Enter"||u.op.tag==="Exit"),n);return i.length!==0&&o.length!==0?AT(i)("`enter`/`exit` cannot be mixed with flow tokens in the same frame"):Wt.bind((()=>{const u=MT(t.name)(r);return r.length!==0?u:ue.pure()})())(()=>Wt.bind((()=>{const u=GT(t.name);return r.length===0&&o.length!==0?u:ue.pure()})())(()=>Wt.bind((()=>{const u=$T(t.ops);return o.length!==0?u:ue.pure()})())(()=>fu(ST)(i))))}g()}),s1=t=>Wt.bind(PT(t.interiors))(()=>Wt.bind(fu(YT)(t.frames))(()=>Wt.bind(RT)(()=>Wt.bind(Be)(e=>{if(e.error.tag==="Just")return ue.pure(Gt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=XT(t.interiors);if(n.tag==="Left")return ue.pure(Gt("Left",n._1));if(n.tag==="Right")return ue.pure(Gt("Right",{seed:t.seed,graph:QT(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1}))}g()})))),XT=t=>{const e=_u(Ia)(n=>r=>{const i=s1(r.doc)(i1)._1;return(()=>{if(i.tag==="Left"){const o=i._1;return u=>Gt("Left",o)}if(i.tag==="Right"){const o=i._1;return u=>u(o)}g()})()(o=>Gt("Right",K(P)(r.node)(o)(n)))})(A)(t);if(e.tag==="Left")return Gt("Left",e._1);if(e.tag==="Right")return Gt("Right",e._1);g()},Xr=(t,e)=>({tag:"ParseError",_1:t,_2:e}),F=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),du=(t,e,n)=>({tag:t,_1:e,_2:n}),VT=t=>du("More",t),UT=t=>du("Lift",t),jT={defer:t=>{const e=cl(t);return(n,r,i,o,u)=>gl(e)(n,r,i,o,u)}},a1={map:t=>e=>(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,c)=>r(f=>u(a,t(c)))))},ZT={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:()=>a1},KT=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(Aa)(c._1);continue}if(c.tag==="Stop"){s=!1,a=e.Applicative0().pure(Zr("Done",b(c._2,c._1)));continue}g()}return a};return t.tailRecM(i)(o=>r(n,VT,UT,(u,s)=>du("Stop",u,Gt("Left",s)),(u,s)=>du("Stop",u,Gt("Right",s))))}},c1=(t,e,n,r,i)=>i(t,t._2),tv={index:0,line:1,column:1},ev=(t=>{const e=KT(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(Yi)(e(F(n,tv,!1))(r))})(R1),g1={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:()=>a1},f1={pure:t=>(e,n,r,i,o)=>o(e,t),Apply0:()=>g1},nv={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:()=>g1},rv={Applicative0:()=>f1,Bind1:()=>nv},lu=t=>(e,n,r,i,o)=>n(u=>c1(e,n,r,i,(s,a)=>n(c=>i(e._3&&!s._3?F(s._1,s._2,!0):s,Xr(t,a))))),iv={empty:lu("No alternative"),Alt0:()=>ZT},ov={Applicative0:()=>f1,Plus1:()=>iv},on=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return i=>t.tailRecM(o=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(Aa)(i))(r.pure(Zr("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return Zr("Loop",Ot("Cons",u._1,o));if(u.tag==="Done")return Zr("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=Ot("Cons",h._1,_),f=h._2;continue}g()}return l})(qt)(o));g()})())))(qt)})({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:()=>rv})(ov),Ct=t=>e=>{const n=lu("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))}},pa=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(m=>n(p=>lu("Negated parser succeeded")(_,n,r,f,(y,x)=>n(N=>o(_._3&&!y._3?F(y._1,y._2,!0):y,x))))))))})},uv=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(m=>h?s(l,_):r._1(i,o,u,s,a))},a))});g()})(T);return n=>{const r=e(n);if(r.tag==="Nothing")return lu("No alternative");if(r.tag==="Just")return r._1;g()}},sv=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(m=>{const p=r._3&&!l._3?F(l._1,l._2,!0):l;return n(p,i,o,u,(y,x)=>i(N=>{const v=p._3&&!y._3?F(y._1,y._2,!0):y;return i(L=>i(k=>{const E=r._3&&!v._3?F(v._1,v._2,!0):v;return e(E,i,o,u,(Q,H)=>i(j=>s(E._3&&!Q._3?F(Q._1,Q._2,!0):Q,x)))}))}))}))))))),ma=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=vh()(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)-Xn(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},av=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,c=i,f=o,d=po(c);if(d.tag==="Nothing"){u=!1,s=a;continue}if(d.tag==="Just"){r=d._1.tail===""?ma(a)(d._1.head)(f):ma(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=po(e._1);if(u.tag==="Nothing")return i(e,Xr("Unexpected EOF",e._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return i(e,Xr("Expected Char",e._2));if(u._1.head>=0&&u._1.head<=65535){const s=vc(u._1.head);return t(s)?o(F(u._1.tail,ma(e._2)(u._1.head)(u._1.tail),!0),s):i(e,Xr("Predicate unsatisfied",e._2))}}g()},ya=(t,e,n,r,i)=>t._1===""?i(F(t._1,t._2,!0),void 0):r(t,Xr("Expected EOF",t._2)),cv=t=>(e,n,r,i,o)=>{const u=t(e._1);if(u.tag==="Left")return i(e,Xr(u._1,e._2));if(u.tag==="Right")return o(F(u._1.remainder,av(e._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);g()},Vr=t=>cv(e=>{const n=al(t)(e);return n.tag==="Just"?Gt("Right",{value:t,consumed:t,remainder:n._1}):Gt("Left","Expected "+L1(t))}),gv=Zt(t=>!0),_1=(t,e)=>({tag:t,_1:e}),fv=Kt(P)(zt),_v=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=P.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},d1=uv(zt),l1=(()=>{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))))})(),xa=(t,e,n,r,i)=>e(o=>Vr("#")(t,e,n,r,(u,s)=>e(a=>{const c=on(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))))}))),dv=Ct((()=>{const t=Ct(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,m=n._2;return r(p=>r(y=>xa(F(h,m,!1),r,i,(x,N)=>{const v=x._3;return r(L=>{if(v)return o(x,N);const k=n._1,E=n._2;return r(Q=>r(H=>e(F(k,E,!1),r,i,(j,S)=>{const C=j._3;return r(U=>C?o(j,S):ya(n,r,i,o,u))},(j,S)=>r(C=>u(j,void 0)))))})},(x,N)=>r(v=>u(x,void 0)))))}),(d,l)=>r(_=>u(F(s,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),Ue=(()=>{const t=on((e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>l1(F(u,s,!1),n,r,(c,f)=>{const d=c._3;return n(l=>d?i(c,f):xa(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))))})(),cn=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>Ue(t._3&&!c._3?F(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>l1(F(s,a,!1),e,n,(f,d)=>{const l=f._3;return e(_=>l?r(f,d):xa(t,e,n,r,u))},u))}),h1=(()=>{const t=Ct(Zt(e=>e==="|"))("'|'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=on(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(m=>{const p=Ct(Ct(Zt(x=>x==="|"))("'|'"))("closing '|'"),y=d._3&&!_._3?F(_._1,_._2,!0):_;return n(x=>p(y,n,r,i,(N,v)=>n(L=>o(y._3&&!N._3?F(N._1,N._2,!0):N,cr(kt($t.foldr,h))))))})))})))})(),hu=Zt(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),He=(()=>{const t=on(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))))})(),lv=(()=>{const t=Ct(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=>gv(f,n,r,i,(l,_)=>n(h=>o(f._3&&!l._3?F(l._1,l._2,!0):l,_==="n"?`
|
|
12
|
+
`:_==="t"?" ":_==="r"?"\r":_))))})))})(),hv=(()=>{const t=Zt(e=>e!=='"'&&e!=="\\"&&e!==`
|
|
13
|
+
`);return(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>lv(F(u,s,!1),n,r,(c,f)=>n(d=>t(e,n,r,i,o)),o))}})(),Na=(()=>{const t=Ct(Zt(e=>e==='"'))(`'"'`);return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=on(hv),d=e._3&&!s._3?F(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(m=>{const p=Ct(Ct(Zt(x=>x==='"'))(`'"'`))(`closing '"' (unterminated string)`),y=d._3&&!_._3?F(_._1,_._2,!0):_;return n(x=>p(y,n,r,i,(N,v)=>n(L=>o(y._3&&!N._3?F(N._1,N._2,!0):N,cr(kt($t.foldr,h))))))})))})))})(),pv=(()=>{const t=Ct(Zt(e=>e===":"))("':'");return(e,n,r,i,o)=>n(u=>He(e,n,r,i,(s,a)=>n(c=>Ct((f,d,l,_,h)=>{const m=f._1,p=f._2;return d(y=>{const x=(N,v)=>{const L=N._3;return d(k=>{if(L)return _(N,v);const E=f._1,Q=f._2;return d(H=>h1(F(E,Q,!1),d,l,(j,S)=>{const C=j._3;return d(U=>C?_(j,S):Na(f,d,l,_,h))},h))})};return d(N=>t(F(m,p,!1),d,l,x,(v,L)=>d(k=>d(E=>He(v,d,l,x,(Q,H)=>d(j=>{const S=on(Zt(U=>U!==`
|
|
14
|
+
`&&U!=="\r"&&U!=="#"&&U!=="}")),C=v._3&&!Q._3?F(Q._1,Q._2,!0):Q;return d(U=>S(C,d,l,x,(Y,W)=>d(z=>h(C._3&&!Y._3?F(Y._1,Y._2,!0):Y,fh(cr(kt($t.foldr,W)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(e._3&&!s._3?F(s._1,s._2,!0):s,n,r,i,o))))})(),mv=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>h1(F(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):Na(t,e,n,r,i))},i))},Hi=Zt(t=>t>="0"&&t<="9"),be=(()=>{const t=Ct(Zt(e=>e==="_"))("'_'");return(e,n,r,i,o)=>n(u=>{const s=(f,d)=>n(l=>{const _=on((()=>{const m=Ct(Zt(y=>y==="_"))("'_'"),p=Ct(Zt(y=>y==="-"))("'-'");return(y,x,N,v,L)=>{const k=y._1,E=y._2;return x(Q=>hu(F(k,E,!1),x,N,(H,j)=>{const S=H._3;return x(C=>{if(S)return v(H,j);const U=y._1,Y=y._2;return x(W=>Hi(F(U,Y,!1),x,N,(z,R)=>{const G=z._3;return x(I=>{if(G)return v(z,R);const D=y._1,B=y._2;return x(q=>m(F(D,B,!1),x,N,(V,$)=>{const X=V._3;return x(M=>X?v(V,$):p(y,x,N,v,L))},L))})},L))})},L))}})()),h=e._3&&!f._3?F(f._1,f._2,!0):f;return n(m=>_(h,n,r,i,(p,y)=>n(x=>o(h._3&&!p._3?F(p._1,p._2,!0):p,ro(d)+cr(kt($t.foldr,y))))))}),a=e._1,c=e._2;return n(f=>hu(F(a,c,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?i(d,l):t(e,n,r,i,s))},s))})})(),yv=Ct((t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>Na(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)"),p1=(t,e,n,r,i)=>e(o=>He(t,e,n,r,(u,s)=>e(a=>{const c=Ct(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 m=f._3&&!l._3?F(l._1,l._2,!0):l;return e(p=>He(m,e,n,r,(y,x)=>e(N=>{const v=Ct(Ct(Zt(k=>k===":"))("':'"))("':'"),L=m._3&&!y._3?F(y._1,y._2,!0):y;return e(k=>v(L,e,n,r,(E,Q)=>e(H=>{const j=L._3&&!E._3?F(E._1,E._2,!0):E;return e(S=>He(j,e,n,r,(C,U)=>e(Y=>{const W=Ct(be)("attribute value"),z=j._3&&!C._3?F(C._1,C._2,!0):C;return e(R=>W(z,e,n,r,(G,I)=>e(D=>{const B=z._3&&!G._3?F(G._1,G._2,!0):G;return e(q=>He(B,e,n,r,(V,$)=>e(X=>i(B._3&&!V._3?F(V._1,V._2,!0):V,b(_,I)))))})))})))})))})))})))}))),xv=(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=>He(c,e,n,r,(d,l)=>e(_=>{const h=Ct((p,y,x,N,v)=>{const L=p._1,k=p._2;return y(E=>Vr("->")(F(L,k,!1),y,x,(Q,H)=>{const j=Q._3;return y(S=>j?N(Q,H):Vr("<-")(p,y,x,N,v))},v))})("'->' or '<-'"),m=c._3&&!d._3?F(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>He(v,e,n,r,(k,E)=>e(Q=>{const H=Ct(be)("target node identifier"),j=v._3&&!k._3?F(k._1,k._2,!0):k;return e(S=>H(j,e,n,r,(C,U)=>e(Y=>{const W=on((R,G,I,D,B)=>{const q=R._3;return G(V=>G($=>He(R,G,I,(X,M)=>D(F(X._1,X._2,q),M),(X,M)=>G(et=>G(tt=>{const gt=R._3&&!X._3?F(X._1,X._2,!0):X;return mv(gt,G,I,(_t,ct)=>D(F(_t._1,_t._2,q),ct),(_t,ct)=>G(yt=>B(gt._3&&!_t._3?F(_t._1,_t._2,!0):_t,ct)))})))))}),z=j._3&&!C._3?F(C._1,C._2,!0):C;return e(R=>W(z,e,n,r,(G,I)=>e(D=>(()=>{if(x==="<-"){const q=Rn("Token",{from:U,to:s,labels:O(cc)(kt($t.foldr,I))});return(V,$,X,M,et)=>et(V,q)}const B=Rn("Token",{from:s,to:U,labels:O(cc)(kt($t.foldr,I))});return(q,V,$,X,M)=>M(q,B)})()(z._3&&!G._3?F(G._1,G._2,!0):G,e,n,r,i))))})))})))})))})))}))),Nv=(t,e,n,r,i)=>e(o=>Hi(t,e,n,r,(u,s)=>e(a=>{const c=on(Hi),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const m=ld(ro(s)+cr(kt($t.foldr,_)));return(()=>{if(m.tag==="Just"){const p=m._1;return(y,x,N,v,L)=>L(y,p)}if(m.tag==="Nothing")return(p,y,x,N,v)=>v(p,0);g()})()(f._3&&!l._3?F(l._1,l._2,!0):l,e,n,r,i)})))}))),Oi=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>Vr(t)(e,n,r,(a,c)=>i(F(a._1,a._2,u),c),(a,c)=>n(f=>{const d=pa((()=>{const _=Ct(Zt(m=>m==="_"))("'_'"),h=Ct(Zt(m=>m==="-"))("'-'");return(m,p,y,x,N)=>{const v=m._1,L=m._2;return p(k=>hu(F(v,L,!1),p,y,(E,Q)=>{const H=E._3;return p(j=>{if(H)return x(E,Q);const S=m._1,C=m._2;return p(U=>Hi(F(S,C,!1),p,y,(Y,W)=>{const z=Y._3;return p(R=>{if(z)return x(Y,W);const G=m._1,I=m._2;return p(D=>_(F(G,I,!1),p,y,(B,q)=>{const V=B._3;return p($=>V?x(B,q):h(m,p,y,x,N))},N))})},N))})},N))}})()),l=e._3&&!a._3?F(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,m)=>i(F(h._1,h._2,u),m),(h,m)=>n(p=>{const y=l._3&&!h._3?F(h._1,h._2,!0):h;return n(x=>Ue(y,n,r,(N,v)=>i(F(N._1,N._2,u),v),(N,v)=>n(L=>o(y._3&&!N._3?F(N._1,N._2,!0):N,t))))})))})))},Jv=(t,e,n,r,i)=>e(o=>cn(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>Oi("via")(c,e,n,r,(d,l)=>e(_=>{const h=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>be(h,e,n,r,(p,y)=>e(x=>{const N=h._3&&!p._3?F(p._1,p._2,!0):p;return e(v=>cn(N,e,n,r,(L,k)=>e(E=>{const Q=N._3&&!L._3?F(L._1,L._2,!0):L;return e(H=>be(Q,e,n,r,(j,S)=>e(C=>i(Q._3&&!j._3?F(j._1,j._2,!0):j,{from:y,to:S}))))})))})))})))}))),rr=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>Vr(t)(e,n,r,(a,c)=>i(F(a._1,a._2,u),c),(a,c)=>n(f=>{const d=pa((()=>{const _=Ct(Zt(m=>m==="_"))("'_'"),h=Ct(Zt(m=>m==="-"))("'-'");return(m,p,y,x,N)=>{const v=m._1,L=m._2;return p(k=>hu(F(v,L,!1),p,y,(E,Q)=>{const H=E._3;return p(j=>{if(H)return x(E,Q);const S=m._1,C=m._2;return p(U=>Hi(F(S,C,!1),p,y,(Y,W)=>{const z=Y._3;return p(R=>{if(z)return x(Y,W);const G=m._1,I=m._2;return p(D=>_(F(G,I,!1),p,y,(B,q)=>{const V=B._3;return p($=>V?x(B,q):h(m,p,y,x,N))},N))})},N))})},N))}})()),l=e._3&&!a._3?F(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,m)=>i(F(h._1,h._2,u),m),(h,m)=>n(p=>o(l._3&&!h._3?F(h._1,h._2,!0):h,void 0))))})))},Tv=(t,e,n,r,i)=>e(o=>rr("+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=>cn(c,e,n,r,(d,l)=>e(_=>{const h=Ct(be)("source node identifier"),m=c._3&&!d._3?F(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>cn(v,e,n,r,(k,E)=>e(Q=>{const H=Ct(be)("target node identifier"),j=v._3&&!k._3?F(k._1,k._2,!0):k;return e(S=>H(j,e,n,r,(C,U)=>e(Y=>i(j._3&&!C._3?F(C._1,C._2,!0):C,Rn("AddEdge",{from:x,to:U})))))})))})))})))}))),vv=(t,e,n,r,i)=>e(o=>rr("-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=>cn(c,e,n,r,(d,l)=>e(_=>{const h=Ct(be)("source node identifier"),m=c._3&&!d._3?F(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>cn(v,e,n,r,(k,E)=>e(Q=>{const H=Ct(be)("target node identifier"),j=v._3&&!k._3?F(k._1,k._2,!0):k;return e(S=>H(j,e,n,r,(C,U)=>e(Y=>i(j._3&&!C._3?F(C._1,C._2,!0):C,Rn("DelEdge",{from:x,to:U})))))})))})))})))}))),wv=(t,e,n,r,i)=>e(o=>rr("-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=>cn(c,e,n,r,(d,l)=>e(_=>{const h=Ct(be)("node identifier"),m=c._3&&!d._3?F(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=on((k,E,Q,H,j)=>{const S=k._3;return Jv(k,E,Q,(C,U)=>H(F(C._1,C._2,S),U),j)}),L=m._3&&!y._3?F(y._1,y._2,!0):y;return e(k=>v(L,e,n,r,(E,Q)=>e(H=>i(L._3&&!E._3?F(E._1,E._2,!0):E,Rn("DelNode",{id:x,via:kt($t.foldr,Q)})))))})))})))}))),bv=(t,e,n,r,i)=>e(o=>rr("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=>cn(c,e,n,r,(d,l)=>e(_=>{const h=Ct(be)("node identifier"),m=c._3&&!d._3?F(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>i(m._3&&!y._3?F(y._1,y._2,!0):y,Rn("Enter",{id:x})))))})))}))),Lv=(t,e,n,r,i)=>e(o=>rr("exit")(t,e,n,r,(u,s)=>e(a=>i(t._3&&!u._3?F(u._1,u._2,!0):u,LT)))),kv=(t,e,n,r,i)=>e(o=>rr("~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=>cn(c,e,n,r,(d,l)=>e(_=>{const h=Ct(be)("source node identifier"),m=c._3&&!d._3?F(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>cn(v,e,n,r,(k,E)=>e(Q=>{const H=Ct(be)("target node identifier"),j=v._3&&!k._3?F(k._1,k._2,!0):k;return e(S=>H(j,e,n,r,(C,U)=>e(Y=>{const W=j._3&&!C._3?F(C._1,C._2,!0):C;return e(z=>Ue(W,e,n,r,(R,G)=>e(I=>{const D=Ct(Vr("->"))("'->'"),B=W._3&&!R._3?F(R._1,R._2,!0):R;return e(q=>D(B,e,n,r,(V,$)=>e(X=>{const M=B._3&&!V._3?F(V._1,V._2,!0):V;return e(et=>Ue(M,e,n,r,(tt,gt)=>e(_t=>{const ct=Ct(be)("new source node identifier"),yt=M._3&&!tt._3?F(tt._1,tt._2,!0):tt;return e(Et=>ct(yt,e,n,r,(Rt,pt)=>e(Qt=>{const Jt=yt._3&&!Rt._3?F(Rt._1,Rt._2,!0):Rt;return e(mt=>cn(Jt,e,n,r,(nt,Z)=>e(ut=>{const ft=Ct(be)("new target node identifier"),lt=Jt._3&&!nt._3?F(nt._1,nt._2,!0):nt;return e(Nt=>ft(lt,e,n,r,(Ht,Vt)=>e(Pe=>i(lt._3&&!Ht._3?F(Ht._1,Ht._2,!0):Ht,Rn("RepointEdge",{from:x,to:U,newFrom:pt,newTo:Vt})))))})))})))})))})))})))})))})))})))})))}))),Ev=(t,e,n,r,i)=>e(o=>rr("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=>He(c,e,n,r,(d,l)=>e(_=>{const h=Ct(Nv)("integer (seed value)"),m=c._3&&!d._3?F(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>Ue(v,e,n,r,(k,E)=>e(Q=>i(v._3&&!k._3?F(k._1,k._2,!0):k,x))))})))})))}))),qi=sv((()=>{const t=Ct(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 Ue(l,n,r,i,(_,h)=>n(m=>o(l._3&&!_._3?F(_._1,_._2,!0):_,h)))})))))})())(Ct((()=>{const t=Ct(Zt(e=>e==="}"))("'}'");return(e,n,r,i,o)=>n(u=>n(s=>Ue(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(m=>o(l._3&&!_._3?F(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),Cv=qi((t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>(()=>{if(f.tag==="Nothing")return(l,_,h,m,p)=>p(l,A);if(f.tag==="Just"){const l=f._1,_=on((()=>{const h=Ct(Zt(m=>m===","))("','");return(m,p,y,x,N)=>{const v=m._3;return p(L=>p(k=>p(E=>p(Q=>p(H=>p(j=>He(m,p,y,(S,C)=>x(F(S._1,S._2,v),C),(S,C)=>p(U=>p(Y=>{const W=m._3&&!S._3?F(S._1,S._2,!0):S;return h(W,p,y,(z,R)=>x(F(z._1,z._2,v),R),(z,R)=>p(G=>{const I=W._3&&!z._3?F(z._1,z._2,!0):z;return p(D=>p(B=>{const q=m._3&&!I._3?F(I._1,I._2,!0):I;return He(q,p,y,(V,$)=>x(F(V._1,V._2,v),$),(V,$)=>p(X=>{const M=q._3&&!V._3?F(V._1,V._2,!0):V;return p(et=>p(tt=>{const gt=m._3&&!M._3?F(M._1,M._2,!0):M;return p1(gt,p,y,(_t,ct)=>x(F(_t._1,_t._2,v),ct),(_t,ct)=>p(yt=>N(gt._3&&!_t._3?F(_t._1,_t._2,!0):_t,ct)))}))}))}))}))})))))))))}})());return(h,m,p,y,x)=>m(N=>_(h,m,p,y,(v,L)=>m(k=>x(h._3&&!v._3?F(v._1,v._2,!0):v,fv([l,...kt($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=>p1(F(s,a,!1),e,n,(d,l)=>e(_=>u(t,T)),(d,l)=>e(_=>u(d,w("Just",l))))))})),Sv=(t,e,n,r,i)=>e(o=>rr("+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=>cn(c,e,n,r,(d,l)=>e(_=>{const h=Ct(be)("node identifier"),m=c._3&&!d._3?F(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>e(k=>He(v,e,n,r,(E,Q)=>e(H=>{const j=Zt(C=>C===`
|
|
15
|
+
`||C==="\r"||C==="#"||C==="}"||C==="{"),S=v._3&&!E._3?F(E._1,E._2,!0):E;return e(C=>{const U=(z,R)=>e(G=>(R?((I,D,B,q,V)=>V(I,"")):pv)(S._3&&!z._3?F(z._1,z._2,!0):z,e,n,r,(I,D)=>e(B=>{const q=v._3&&!I._3?F(I._1,I._2,!0):I;return e(V=>{const $=(et,tt)=>e(gt=>i(q._3&&!et._3?F(et._1,et._2,!0):et,Rn("AddNode",{id:x,label:D,shape:(()=>{const _t=_v("shape")(tt);if(_t.tag==="Just")return _t._1==="rectangle"||_t._1==="rect"?jn:_t._1==="cylinder"||_t._1==="cyl"?Nl:_t._1==="parallelogram"?Jl:_t._1==="diamond"?Tl:_t._1==="ellipse"?vl:_t._1==="document"||_t._1==="doc"?wl:_t._1==="cloud"?bl:jn;if(_t.tag==="Nothing")return jn;g()})()}))),X=q._1,M=q._2;return e(et=>{const tt=(gt,_t)=>{const ct=gt._3;return e(yt=>ct?r(gt,_t):$(q,A))};return e(gt=>e(_t=>He(F(X,M,!1),e,n,(ct,yt)=>tt(F(ct._1,ct._2,!1),yt),(ct,yt)=>e(Et=>e(Rt=>Cv(ct,e,n,(pt,Qt)=>tt(F(pt._1,pt._2,!1),Qt),(pt,Qt)=>e(Jt=>$(ct._3&&!pt._3?F(pt._1,pt._2,!0):pt,Qt))))))))})})}))),Y=S._1,W=S._2;return e(z=>{const R=(G,I)=>{const D=G._3;return e(B=>D?r(G,I):U(S,!1))};return e(G=>e(I=>e(D=>ya(F(Y,W,!1),e,n,(B,q)=>{const V=B._3;return e($=>V?R(F(Y,W,!1),q):e(X=>j(F(Y,W,!1),e,n,(M,et)=>R(F(Y,W,!1),et),(M,et)=>e(tt=>e(gt=>U(F(Y,W,!1),!0))))))},(B,q)=>e(V=>e($=>U(F(Y,W,!1),!0)))))))})})}))))})))})))}))),Gv=(t,e,n,r,i)=>e(o=>c1(t,e,n,r,(u,s)=>e(a=>{const c=Ct(d1([Sv,wv,kv,Tv,vv,bv,Lv,xv]))("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,ha("Leaf",{op:_,line:s.line,column:s.column})))))}))),Pv=(t,e,n,r,i)=>e(o=>Oi("seq")(t,e,n,r,(u,s)=>e(a=>qi(Ja(r1))(t._3&&!u._3?F(u._1,u._2,!0):u,e,n,r,i)))),Iv=(t,e,n,r,i)=>e(o=>Oi("par")(t,e,n,r,(u,s)=>e(a=>qi(Ja(kT))(t._3&&!u._3?F(u._1,u._2,!0):u,e,n,r,i)))),Ja=t=>{const e=on(Dv());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(kt($t.foldr,c))))))},Dv=ka(()=>{const t=pa(Ct(Zt(e=>e==="}"))("'}'"));return(e,n,r,i,o)=>n(u=>{const s=e._3;return n(a=>n(c=>Ue(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,(m,p)=>i(F(m._1,m._2,s),p),(m,p)=>n(y=>{const x=h._3&&!m._3?F(m._1,m._2,!0):m;return n(N=>{const v=d1([(k,E,Q,H,j)=>{const S=k._3;return Iv(k,E,Q,(C,U)=>H(F(C._1,C._2,S),U),j)},(k,E,Q,H,j)=>{const S=k._3;return Pv(k,E,Q,(C,U)=>H(F(C._1,C._2,S),U),j)},Gv]),L=e._3&&!x._3?F(x._1,x._2,!0):x;return n(k=>v(L,n,r,i,(E,Q)=>n(H=>{const j=L._3&&!E._3?F(E._1,E._2,!0):E;return n(S=>He(j,n,r,i,(C,U)=>n(Y=>{const W=j._3&&!C._3?F(C._1,C._2,!0):C;return n(z=>dv(W,n,r,i,(R,G)=>n(I=>o(W._3&&!R._3?F(R._1,R._2,!0):R,Q))))})))})))})}))})))))})}),Av=(t,e,n,r,i)=>e(o=>Oi("frame")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>yv(c,e,n,r,(d,l)=>e(_=>{const h=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>Ue(h,e,n,r,(p,y)=>e(x=>{const N=qi(Ja(r1)),v=h._3&&!p._3?F(p._1,p._2,!0):p;return e(L=>N(v,e,n,r,(k,E)=>e(Q=>{const H=v._3&&!k._3?F(k._1,k._2,!0):k;return e(j=>Ue(H,e,n,r,(S,C)=>e(U=>i(H._3&&!S._3?F(S._1,S._2,!0):S,{name:w("Just",l),ops:E}))))})))})))})))}))),Bv=(t,e,n,r,i)=>e(o=>Oi("inside")(t,e,n,r,(u,s)=>e(a=>{const c=Ct(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 m=f._3&&!l._3?F(l._1,l._2,!0):l;return e(p=>Ue(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>qi(m1)(v,e,n,r,(k,E)=>e(Q=>{const H=v._3&&!k._3?F(k._1,k._2,!0):k;return e(j=>Ue(H,e,n,r,(S,C)=>e(U=>i(H._3&&!S._3?F(S._1,S._2,!0):S,{node:_,doc:E}))))})))})))})))}))),m1=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>{const l=on(Fv()),_=t._3&&!c._3?F(c._1,c._2,!0):c;return e(h=>l(_,e,n,r,(m,p)=>e(y=>{const x=kt($t.foldr,p);return i(_._3&&!m._3?F(m._1,m._2,!0):m,{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 T;g()})(x),interiors:xt(N=>{if(N.tag==="TopInside")return w("Just",N._1);if(N.tag==="TopFrame")return T;g()})(x)})})))}),s=t._1,a=t._2;return e(c=>e(f=>Ev(F(s,a,!1),e,n,(d,l)=>{const _=d._3;return e(h=>_?r(d,l):u(t,T))},(d,l)=>e(_=>u(d,w("Just",l))))))}),Fv=ka(()=>jT.defer(t=>(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>n(c=>Bv(F(u,s,!1),n,r,(f,d)=>n(l=>n(_=>Av(e,n,r,i,(h,m)=>n(p=>o(h,_1("TopFrame",m)))))),(f,d)=>n(l=>o(f,_1("TopInside",d))))))})),Rv=(()=>{const t=Ct((e,n,r,i,o)=>n(u=>n(s=>Ue(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?F(a._1,a._2,!0):a;return ya(l,n,r,i,(_,h)=>n(m=>o(l._3&&!_._3?F(_._1,_._2,!0):_,h)))}))))))("'frame', 'inside', or end of input");return(e,n,r,i,o)=>n(u=>n(s=>n(a=>n(c=>Ue(e,n,r,i,(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?F(f._1,f._2,!0):f;return m1(h,n,r,i,(m,p)=>n(y=>{const x=h._3&&!m._3?F(m._1,m._2,!0):m;return n(N=>n(v=>{const L=e._3&&!x._3?F(x._1,x._2,!0):x;return t(L,n,r,i,(k,E)=>n(Q=>o(L._3&&!k._3?F(k._1,k._2,!0):k,p)))}))}))})))))))})(),Qv=t=>{const e=ev(t)(Rv);if(e.tag==="Left")return Gt("Left",{msg:e._1._1,line:e._1._2.line,column:e._1._2.column});if(e.tag==="Right")return Gt("Right",e._1);g()},zv=t=>{const e=Qv(t);if(e.tag==="Left")return Gt("Left",e._1.msg);if(e.tag==="Right")return Gt("Right",e._1);g()};function Ta(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 Ur(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function Wv(t){return function(e){return function(){return e.getAttribute(t)}}}const Mv=t=>{const e=Wv(t);return n=>{const r=e(n);return()=>{const i=r();return ja(i,T,Yt)}}};function Hv(t){return function(e){return function(){e.textContent=t}}}function Ov(t){return function(){return function(e){return t(e)()}}}function qv(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const $v=function(){return window};function Yv(t){return function(e){return function(){e.value=t}}}function Xv(t){return function(){return t.valueAsNumber}}function Vv(t){return function(){return t.value}}function Uv(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const jv=t=>t,Zv=t=>()=>t.clientWidth||0,Kv=()=>window.devicePixelRatio||1,va=(t,e)=>{e.innerHTML=t},wa=(t,e,n)=>{t.style.setProperty(e,n)},tw=(t,e)=>t.querySelector(`[data-mg="${e}"]`),y1=t=>e=>t===e,ew=t=>t,nw=(t,e,n)=>({tag:t,_1:e,_2:n}),rw=zt.foldMap(wd),x1=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},iw=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ow=nw("AutoSize"),uw=ew("CanvasRenderer"),sw=t=>e=>{const n=t-e*rt(de(dn(t/e)));return e<=0?0:n<0?n+e:n},N1=t=>J(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),aw=t=>{const e=Mv("data-markgraf-titles")(t);return()=>{const n=e();return n.tag==="Nothing"||!(n.tag==="Just"&&n._1==="false")}},cw=`
|
|
14
16
|
<canvas data-mg="stage" tabindex="0"></canvas>
|
|
15
17
|
<div data-mg="play-overlay" aria-hidden="true"></div>
|
|
16
18
|
<div data-mg="bar">
|
|
@@ -27,4 +29,4 @@ var F2=(function(Wi){"use strict";function hf(t){let e=0,n;return()=>{if(e===2)r
|
|
|
27
29
|
<option value="2">2\xD7</option>
|
|
28
30
|
</select>
|
|
29
31
|
</div>
|
|
30
|
-
`,
|
|
32
|
+
`,Wn=t=>e=>n=>()=>{const r=tw(t,e),i=ja(r,T,Yt);if(i.tag==="Just")return n(i._1)();i.tag!=="Nothing"&&g()},gw=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=rw(i=>'<span class="mg-tick" style="left:'+oi(ri("Fixed",ii(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==="EnterNode"||i.scene.tag==="ExitNode")return"";g()})()+'"></span>')(e.spans);return Wn(t)("ticks")(i=>()=>va(r,i))},fw=t=>e=>n=>Wn(t)("scrub")(r=>{const i=Ta(T,Yt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return n<=0?()=>{}:Yv(ie(de(Yn(e/n*1e3))))(i._1);g()}),ba=t=>e=>n=>{const r=Ov(i=>n);return()=>{const i=r();return qv(t)(i)(!1)(e)()}},J1=()=>Sd()/1e3,La=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>{const f=Ye(u.layout),d=Cl(u.layout),l={center:{x:d.x+d.w/2,y:f.y+f.h/2},zoom:Ku(u.layout)(f)(0)},_=Xu(u.layout)(l),h=()=>{const N=J1(),v=a.value;return a.value=N,v===0?0:N-v},m=j0(u)(x1(c)(u.totalDuration)),p=o?m:{...m,levels:O(N=>({...N,state:{...N.state,frameTitle:""}}))(m.levels)},y=u.dives.length===0&&(_.w+48)*1.0909090909090908<=1100&&(_.h+48)*1.0909090909090908<=1400,x=y?{...p,camera:l,levels:O(N=>({...N,state:{...N.state,camera:l}}))(p.levels)}:p;if(e==="CanvasRenderer")return()=>{const N=h(),v=jv(t),L=Yr({padding:8,outputAspect:T})(x),k=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){if(y)return{w:L.vw*1.0909090909090908,h:L.vh*1.0909090909090908};const R=Zv(t)();return{w:R,h:L.vw<=0?R:R*L.vh/L.vw}}g()})(),E=Kv(),Q=k.w*E,H=k.h*E,j=Pd(v)(),S=Id(v)(),C=Dd(v)(Q);j!==Q&&C();const U=Ad(v)(H);if(S!==H&&U(),wa(t,"height",ie(de(Yn(k.h)))+"px"),n.tag==="FixedSize")wa(t,"width",ie(de(Yn(k.w)))+"px");else if(n.tag==="AutoSize"){const R=ie(de(Yn(k.w)))+"px";y&&wa(t,"width",R)}else g();const Y=Gd(v)();sr(Y)(),Ki(Y)({scaleX:E,scaleY:E})();const W=s.value,z=nT(r)(i)(Y)({width:k.w,height:k.h})(x)(N)(W)();return s.value=z,ar(Y)()};if(e==="SvgRenderer")return()=>{const N=h(),v=s.value,L=xT((()=>{if(n.tag==="AutoSize")return T;if(n.tag==="FixedSize")return n._1<=0||n._2<=0?T:w("Just",n._1/n._2);g()})())(r)(i)(x)(N)(v);return s.value=L.springs,Ur("viewBox")(L.parts.viewBox)(t)(),Ur("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(Ur("width")(ie(de(Yn(n._1))))(t)(),Ur("height")(ie(de(Yn(n._2))))(t)()):n.tag==="AutoSize"||g(),va(L.parts.body,t)};g()},T1=t=>{const e=zv(t);if(e.tag==="Left")return Gt("Left",e._1);if(e.tag==="Right"){const n=s1(e._1)(i1)._1;if(n.tag==="Left")return Gt("Left",n._1.msg);if(n.tag==="Right")return Gt("Right",n._1)}g()},_w=t=>{const e=T1(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return Ld;g()},dw=t=>e=>Wn(t)("speed")(n=>{const r=Ta(T,Yt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return ba("change")(n)((()=>{const i=Vv(r._1);return()=>{const o=i(),u=cd(o,qa,Yt,T);if(u.tag==="Just")return e(u._1)();u.tag!=="Nothing"&&g()}})());g()}),lw=t=>e=>n=>Wn(t)("scrub")(r=>{const i=Ta(T,Yt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return ba("input")(r)((()=>{const o=Xv(i._1);return()=>{const u=o();return n.pause(),n.seek(u/1e3*e.totalDuration)()}})());g()}),hw=t=>e=>n=>{const r=gw(t)(e);return()=>{r(),Wn(t)("play")(i=>Ur("data-mg-playing")("1")(i))(),dw(t)(n.setSpeed)(),Wn(t)("play")(i=>ba("click")(i)(n.toggle))(),lw(t)(e)(n)(),n.subscribe(i=>{const o=fw(t)(i.time)(e.totalDuration);return()=>(o(),Wn(t)("time")(u=>Hv(oi(ri("Fixed",ii(0)(20)(2)))(i.time)+" / "+oi(ri("Fixed",ii(0)(20)(2)))(e.totalDuration))(u))(),Wn(t)("play")(u=>Ur("data-mg-playing")(i.playing?"1":"0")(u))())})()}},pw={...sh,tokenZoomFloor:1,minZoom:1.6,maxZoom:3.2},mw=t=>e=>{const n=Cf(t);return()=>{const r=n(),i=Sf(t)(),o=f0(pw)(t0)(t)(Gf(r)(i)(t));if(o.tag==="Left")return Za("[markgraf] precompute failed")();if(o.tag==="Right")return e(o._1)();g()}},yw=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,m=[],p=[],y="";La(t)(n)(r)(i)(o)(u)(e)(l)(_)(0)();const x=H=>()=>{const j=m,S=a,C=_o(e)(H);if(C!==""&&C!==y){const U=p,Y=Xt(W=>W.label===C)(U);Y.tag==="Just"?N1(W=>W)(Y._1.fns)():Y.tag==="Nothing"||g(),y=C}return N1(U=>U({time:H,keyframe:C,playing:S}))(j)()},N=()=>(a=!1,x(f)()),v=H=>{const j=iw(0)(x1(e.totalDuration)(H));return()=>(f=j,d=0,La(t)(n)(r)(i)(o)(u)(e)(l)(_)(j)(),x(j)())},L=()=>{if(!h&&(c=!1,a)){const H=J1(),j=d;d=H;const S=s,C=f,U=sw(j===0?C+0*S:C+(H-j)*S)(e.totalDuration+.8);return f=U,La(t)(n)(r)(i)(o)(u)(e)(l)(_)(U)(),x(U)(),k()}},k=()=>{if(!h&&!c){c=!0;const H=$v();Uv(L)(H)()}},E=()=>(d=0,a=!0,k()),Q=()=>(a||E(),x(f)());return E(),{play:Q,pause:N,toggle:()=>a?N():Q(),seek:H=>v(H),setSpeed:H=>()=>s=H,currentTime:()=>f,currentKeyframe:()=>{const H=f;return _o(e)(H)},isPlaying:()=>a,duration:e.totalDuration,subscribe:H=>()=>{m=Ft(m)(H);const j=f,S=a;H({time:j,keyframe:_o(e)(j),playing:S})();const C=Ha(U=>!y1(U)(H));return()=>{m=C(m)}},onFrame:H=>j=>H===""?()=>()=>{}:()=>{const S=p;p=(()=>{const Y=On(Yt,T,W=>W.label===H,S);if(Y.tag==="Just"){const W=Ma(Y._1)(z=>({...z,fns:Ft(z.fns)(j)}))(S);if(W.tag==="Nothing")return S;if(W.tag==="Just")return W._1;g()}if(Y.tag==="Nothing")return Ft(S)({label:H,fns:[j]});g()})();const C=f;_o(e)(C)===H&&j();const U=xt(Y=>{const W=at(z=>!y1(z)(j),Y.fns);return W.length===0?T:w("Just",{...Y,fns:W})});return()=>{p=U(p)}},seekFrame:H=>{const j=gh(e)(H);if(j.tag==="Just")return v(j._1);if(j.tag==="Nothing")return()=>{};g()},destroy:()=>h=!0}},v1=t=>e=>{const n=T1(e);if(n.tag==="Left")return Za("[markgraf] parse failed: "+n._1);if(n.tag==="Right")return mw(n._1)(r=>{const i=aw(t);return()=>{const o=i();return va(cw,t),Wn(t)("stage")(u=>{const s=yw(u)(r)(uw)(ow)(iT)(oT)(o);return()=>{const a=s();return hw(t)(r)(a)()}})()}});g()},xw=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 Ln=null;const pu=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",Nw=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{pu(t)?(Ln&&Ln!==t&&pu(Ln)&&Ln.querySelector('[data-mg="play"]').click(),Ln=t):Ln===t&&(Ln=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},Jw=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=xw(t),n=t.dataset.markgrafPaused==="true";t.textContent="",v1(t)(e)(),n?pu(t)&&t.querySelector('[data-mg="play"]').click():Ln===null?Ln=t:pu(t)&&t.querySelector('[data-mg="play"]').click(),Nw(t)},mu=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(Jw)},w1=()=>{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||Ln||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=_w(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>v1(e)(n)(),mountAll:mu,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{mu(),w1()}):(mu(),w1())}return yu.mountAll=mu,Object.defineProperty(yu,Symbol.toStringTag,{value:"Module"}),yu})({});
|