@markgrafhq/markgraf-embed 0.1.10 → 0.1.12
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 +16 -16
- package/package.json +1 -1
package/dist/markgraf-embed.js
CHANGED
|
@@ -1,18 +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})+'"'},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=
|
|
4
|
-
`)(" "),n=(()=>{const r=
|
|
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?
|
|
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?
|
|
10
|
-
`)),f=t._3&&!u._3?
|
|
11
|
-
`||n==="\r");return(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>r(f=>t(
|
|
12
|
-
`:_==="t"?" ":_==="r"?"\r":_))))})))})(),
|
|
13
|
-
`);return(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>
|
|
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
|
-
`||
|
|
1
|
+
var bv=(function(yu){"use strict";function Ca(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 kn(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const Le=t=>e=>t,M=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}},v1={map:M},Sa=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()},Ga=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},b1=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"),v=(t,e)=>({tag:t,_1:e}),T=v("Nothing"),Xt=t=>v("Just",t),Pa=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;g()},Da=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;g()},Pt=(t,e)=>({tag:t,_1:e}),L1=t=>Pt("Right",t),k1={map:t=>e=>{if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right")return Pt("Right",t(e._1));g()}},Ia={apply:t=>e=>{if(t.tag==="Left")return Pt("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right")return Pt("Right",t._1(e._1))}g()},Functor0:()=>k1},E1={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Pt("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}g()},Apply0:()=>Ia},C1={pure:L1,Apply0:()=>Ia},Qa={Applicative0:()=>C1,Bind1:()=>E1},S1=t=>t,G1={map:t=>e=>t(e)},Aa={apply:t=>e=>t(e),Functor0:()=>G1},P1={bind:t=>e=>e(t),Apply0:()=>Aa},D1={pure:S1,Apply0:()=>Aa},Hn={Applicative0:()=>D1,Bind1:()=>P1},I1=function(t){return function(){return t}},Q1={apply:t=>e=>()=>{const n=t(),r=e();return Nu.pure(n(r))()},Functor0:()=>A1},Nu={pure:I1,Apply0:()=>Q1},A1={map:t=>e=>()=>{const n=e();return t(n)}},Kr=(t,e)=>({tag:t,_1:e}),Ra=t=>Kr("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:()=>Hn},F1=function(t){return function(e){return function(){return t(e())}}},B1=function(t){return function(){return t}},z1={map:F1},W1={apply:t=>e=>()=>{const n=t(),r=e();return Fa.pure(n(r))()},Functor0:()=>z1},Fa={pure:B1,Apply0:()=>W1},O1=(function(t){return function(e){return function(n){return function(){return t(e,n)}}}})(function(t,e){return e.push(t)}),M1=(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}},H1=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()}},ti=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=>Sa)(o))(u)})(t.pure())},$1=t=>{const e=Ju(t);return n=>{const r=e(n);return i=>o=>r(o)(i)}},zt={foldr:ti,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}),En=t=>e=>b(t,e),Yi=t=>t._2,Vi=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,Y1=Tu,ei=Tu,wu=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}}},fn={eq:ei},V1={eq:Y1},Jr={eq:X1};var vu=function(t){return function(e){return function(n){return function(r){return function(i){return r<i?t:r===i?e:n}}}}};const U1=vu,j1=vu,C={compare:vu(ye)(Ge)(xe),Eq0:()=>fn},ut={compare:j1(ye)(Ge)(xe),Eq0:()=>V1},it={compare:U1(ye)(Ge)(xe),Eq0:()=>Jr},Z1=function(t){return t},K1=(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)}}}}}})(),td=t=>t,or={traverse:t=>{const e=t.Apply0();return K1(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>or.traverse(t)(td),Functor0:()=>v1,Foldable1:()=>zt},It=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 ed=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},nd=function(t,e){for(var n=[],r=0,i=0;i<t;i++)n[r++]=e;return n};const rd=typeof Array.prototype.fill=="function"?ed:nd,Ct=(function(){function t(i,o){this.head=i,this.tail=o}var e={};function n(i){return function(o){return new t(i,o)}}function r(i){for(var o=[],u=0,s=i;s!==e;)o[u++]=s.head,s=s.tail;return o}return function(i,o){return r(i(n)(e)(o))}})(),Rt=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},Ba=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},ur=function(t,e,n,r){for(var i=0,o=r.length;i<o;i++)if(n(r[i]))return t(i);return e},za=function(t,e,n,r){for(var i=r.length-1;i>=0;i--)if(n(r[i]))return t(i);return e},Wa=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)},Oa=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)},Ne=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},st=function(t,e){return e.filter(t)},id=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},od=(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},Be=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},Ma=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},kt=t=>e=>od(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),ud=t=>e=>kt(n=>r=>t.compare(e(n))(e(r))),Wt=t=>e=>(()=>{const n=O1(e);return()=>{const r=[...t];return n(r)(),r}})()(),ni=t=>{if(t.length===0)return t.length-1|0,T;const e=t.length-1|0;return e>=0&&e<t.length?v("Just",{init:bt(0,t.length-1|0,t),last:t[e]}):T},sd=t=>e=>n=>t>=0&&t<n.length?$n(Xt,T,t,e(n[t]),n):T,sr=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=v("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()},Tr=t=>e=>{const n=kt(r=>i=>t(r._2)(i._2))(At(En)(e));return 0<n.length?M(Yi)(ud(it)(Vi)((()=>{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=M1(i=>i>=0&&i<e.length?v("Just",e[i]):T,{value:0});return H1(r)(i=>()=>{const o=[];o.push(i),q1(t(i))(r)(o)(),n.push(o)})(),n},Vt=t=>e=>{const n=ur(Xt,T,t,e);return n.tag==="Just"?v("Just",e[n._1]):T},qa=t=>e=>st(t,e),ze=t=>e=>n=>{const r=ur(Xt,T,i=>t.eq(i)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},Ha=t=>e=>Tt(e)(t),xt=t=>Ha(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];g()}),$a=isFinite;function cd(t,e,n,r){var i=parseFloat(t);return e(i)?n(i):r}const Xn=Math.abs,gd=Math.acos,ar=function(t){return function(e){return Math.atan2(t,e)}},Ui=Math.ceil,tn=Math.cos,ji=Math.exp,ln=Math.floor,Xa=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,He=Math.sin,ke=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}}}})(Xt)(T)(10),Ya=dd(Xt)(T),de=t=>{if(!$a(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()},qt=(t,e,n)=>({tag:t,_1:e,_2:n}),Ht=qt("Nil"),$t={foldr:t=>e=>{const n=$t.foldl(i=>o=>t(o)(i))(e),r=(i=>o=>{let u=i,s=o,a=!0,c;for(;a;){const f=u,d=s;if(d.tag==="Nil"){a=!1,c=f;continue}if(d.tag==="Cons"){u=qt("Cons",d._1,f),s=d._2;continue}g()}return c})(Ht);return i=>n(r(i))},foldl:t=>e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=t(s)(a._1),i=a._2;continue}g()}return u},foldMap:t=>{const e=t.mempty;return n=>$t.foldl(r=>{const i=t.Semigroup0().append(r);return o=>i(n(o))})(e)}},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(Pa)(pd)(Vi)(Yi)},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()},$e={unfoldr:yd(Pa)(xd)(Vi)(Yi),Unfoldable10:()=>md},Mt=(t,e,n,r,i,o,u)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u}),Xe=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Zi=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),Va=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),Q=Mt("Leaf"),hn=Xe("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()},We=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?Mt("Node",1,1,t,e,Q,Q):r.tag==="Node"&&r._1>1?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;g()})()?se(r._5._3,r._5._4,se(t,e,n,r._5._5),se(r._3,r._4,r._5._6,r._6)):se(r._3,r._4,se(t,e,n,r._5),r._6):se(t,e,n,r);if(n.tag==="Node")return r.tag==="Node"?r._1>(n._1+1|0)?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;g()})()?se(r._5._3,r._5._4,se(t,e,n,r._5._5),se(r._3,r._4,r._5._6,r._6)):se(r._3,r._4,se(t,e,n,r._5),r._6):n._1>(r._1+1|0)?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?se(n._6._3,n._6._4,se(n._3,n._4,n._5,n._6._5),se(t,e,n._6._6,r)):se(n._3,n._4,n._5,se(t,e,n._6,r)):se(t,e,n,r):r.tag==="Leaf"&&n._1>1?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?se(n._6._3,n._6._4,se(n._3,n._4,n._5,n._6._5),se(t,e,n._6._6,r)):se(n._3,n._4,n._5,se(t,e,n._6,r)):se(t,e,n,r);g()},wr=(t,e,n)=>{if(n.tag==="Leaf")return Zi(T,Q,Q);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const i=wr(t,e,n._5);return Zi(i._1,i._2,We(n._3,n._4,i._3,n._6))}if(r==="GT"){const i=wr(t,e,n._6);return Zi(i._1,We(n._3,n._4,n._5,i._2),i._3)}if(r==="EQ")return Zi(v("Just",n._4),n._5,n._6)}g()},Ua=(t,e,n,r)=>{if(r.tag==="Leaf")return Va(t,e,n);if(r.tag==="Node"){const i=Ua(r._3,r._4,r._5,r._6);return Va(i._1,i._2,We(t,e,n,i._3))}g()},ri=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=Ua(t._3,t._4,t._5,t._6);return We(n._1,n._2,n._3,e)}g()},Cn=(t,e,n)=>{if(e.tag==="Leaf")return Q;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=wr(t,n._3,e);return ri(Cn(t,r._2,n._5),Cn(t,r._3,n._6))}g()},Ki=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return Q;if(r.tag==="Node"){const i=wr(t,r._3,n),o=Ki(t,e,i._2,r._5),u=Ki(t,e,i._3,r._6);if(i._1.tag==="Just")return We(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return ri(o,u)}g()},Ee=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const i=wr(t,r._3,n),o=Ee(t,e,i._2,r._5),u=Ee(t,e,i._3,r._6);if(i._1.tag==="Just")return We(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return We(r._3,r._4,o,u)}g()},Nd=t=>e=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node"){const i=e(r._3)(r._4);if(i.tag==="Just")return We(r._3,i._1,n(r._5),n(r._6));if(i.tag==="Nothing")return ri(n(r._5),n(r._6))}g()};return n},pn=(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=Xe("IterEmit",h._3,h._4,_),f=h._5;continue}c=Xe("IterEmit",h._3,h._4,Xe("IterNode",h._6,_)),f=h._5;continue}g()}return l})(u._2)(u._1);continue}g()}return o})((t,e,n)=>v("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,Q,Q);if(o.tag==="Node"){const u=t.compare(n)(o._3);if(u==="LT")return We(o._3,o._4,i(o._5),o._6);if(u==="GT")return We(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,Q,Q);if(i.tag==="Node"){const o=t.compare(e)(i._3);if(o==="LT")return We(i._3,i._4,r(i._5),i._6);if(o==="GT")return We(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))(Q),ii=t=>e=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node"){const i=t.compare(e)(r._3);if(i==="LT")return We(r._3,r._4,n(r._5),r._6);if(i==="GT")return We(r._3,r._4,r._5,n(r._6));if(i==="EQ")return ri(r._5,r._6)}g()};return n},ja=t=>{const e=t.compare;return n=>r=>i=>{const o=wr(e,r,i),u=n(o._1);if(u.tag==="Nothing")return ri(o._2,o._3);if(u.tag==="Just")return We(r,u._1,o._2,o._3);g()}},oe=function(t){return function(e){return t+e|0}},vr=function(t){return function(e){return t+e}},Vn=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},wd={append:te},vd={mempty:"",Semigroup0:()=>Td},bd={mempty:[],Semigroup0:()=>wd},Ld=null;function Za(t,e,n){return t==null?e:n(t)}function vv(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),oi=(t,e)=>({tag:t,_1:e}),ui=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()},si=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()},Ka=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 Dd(t){return function(){return t.height}}function Id(t){return function(e){return function(){t.width=e}}}function Qd(t){return function(e){return function(){t.height=e}}}function ku(t){return function(e){return function(){t.lineWidth=e}}}function Ad(t){return function(e){return function(){t.fillStyle=e}}}function Rd(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 Fd(t){return function(e){return function(){t.globalCompositeOperation=e}}}function Bd(t){return function(e){return function(){t.globalAlpha=e}}}function tc(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 ai(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function ec(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function nc(t){return function(){t.closePath()}}function Wd(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function Od(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function to(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 Md(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function qd(t){return function(e){return function(){t.textAlign=e}}}function Hd(t){return function(e){return function(){t.textBaseline=e}}}function $d(t){return function(e){return function(){t.font=e}}}function Xd(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function cr(t){return function(){t.save()}}function gr(t){return function(){t.restore()}}function ci(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function Yd(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const rc=t=>t,Du=t=>t,Iu=t=>t,Qu=t=>t,eo=t=>t,Vd=eo("BaselineTop"),Ud=eo("BaselineMiddle"),jd=eo("BaselineAlphabetic"),Zd=eo("BaselineBottom"),Kd=Qu("AlignLeft"),tl=Qu("AlignRight"),el=Qu("AlignCenter"),Au=Iu("BevelJoin"),no=Iu("RoundJoin"),Ru=Iu("MiterJoin"),Fu=Du("Round"),Bu=Du("Square"),zu=Du("Butt"),nl=rc("SourceOver"),rl=rc("Difference"),il=t=>e=>Hd(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=>qd(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()})()),ro=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()},ic=t=>e=>Fd(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()})()),Oe={foldr:t=>e=>{const n=$t.foldr(t)(e);return r=>n((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,qt("Cons",o._3,i(o._6,u)));g()};return i(r,Ht)})())}},ul=t=>{const e={append:(()=>{const n=t.compare;return r=>i=>Ee(n,Le,r,i)})()};return{mempty:Q,Semigroup0:()=>e}},gi=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},fr=function(t){return t.join("")},Un=function(t){return t.split("")},io=function(t){return t},jn=function(t){return t.length},oc=function(t){return function(e){return e.substr(0,t)}},fi=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(jn(t))(e);return n.before===t?v("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}},_r=t=>BigInt(t),dl=t=>Number(t),oo=t=>e=>t+e,uo=t=>e=>t*e,Ou=t=>e=>t-e,uc=0n,so=1n,sc=t=>e=>t^e,_i=t=>e=>t&e,Mu=t=>e=>t<<e,qu=t=>e=>t>>e,ll=t=>e=>t==e,hl=t=>e=>t===e?0:t>e?1:-1,pl={eq:ll},ac={compare:t=>e=>{const n=hl(t)(e);return n===1?xe:n===0?Ge:ye},Eq0:()=>pl},ml=fl(Xt)(T),yl=_l(Xt)(T),cc=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=ut.compare(e._1)(n._1);return r==="LT"?ye:r==="GT"?xe:ut.compare(e._2)(n._2)},Eq0:()=>t}})(),xl=t=>e=>Xn(t._1-e._1)+Xn(t._2-e._2),dr=t=>t,ao=t=>t,le=ao("North"),he=ao("South"),Sn=ao("East"),Gn=ao("West"),Zn=dr("Rectangle"),Nl=dr("Cylinder"),Jl=dr("Parallelogram"),Tl=dr("Diamond"),wl=dr("Ellipse"),vl=dr("Document"),bl=dr("Cloud"),gc=t=>t,fc=J(vr)(0),Ll=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},mn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},di=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},_c=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=v("Just",o._4);continue}}g()}return i},dc=t=>{const e={top:0,bottom:0,left:0,right:0},n=t.shape==="Cloud"?{...e,top:t.h*.38}:t.shape==="Cylinder"?{...e,bottom:5}:t.shape==="Document"?{...e,bottom:t.h*.05}:e;return[{x:t.x-n.left,y:t.y-n.top},{x:t.x+t.w+n.right,y:t.y+t.h+n.bottom}]},br=t=>e=>{const n=Je(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,c=s.x-u.x;return ke(c*c+a*a)})()}),t,bt(1,t.length,t)),r=fc(M(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,p=f,m=d,y=Rt(x=>T,x=>N=>v("Just",{head:x,tail:N}),h);if(y.tag==="Nothing"){const x=t.length-1|0;if(x>=0&&x<t.length){l=!1,_=t[x];continue}l=!1,_=m;continue}if(y.tag==="Just"){if(p<=y._1.head.len){const x=y._1.head.len<=0?0:p/y._1.head.len;l=!1,_={x:y._1.head.a.x+(y._1.head.b.x-y._1.head.a.x)*x,y:y._1.head.a.y+(y._1.head.b.y-y._1.head.a.y)*x};continue}c=y._1.tail,f=p-y._1.head.len,d=m;continue}g()}return _};return 0<t.length?v("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=di(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}},li=t=>fc(Je(e=>n=>{const r=n.y-e.y,i=n.x-e.x;return ke(i*i+r*r)},t,bt(1,t.length,t))),El=t=>e=>n=>r=>i=>{const o=0<t.length?v("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?v("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 w=c.y-n.y;return(l<0?-l:l)+(w<0?-w:w)})(),h=u.x-e.x,p=2*(()=>{const w=u.y-e.y;return(h<0?-h:h)+(w<0?-w:w)})(),m=p+li(t)+_,y=m<=1e-4?1:1-_/m,x=m<=1e-4?0:p/m;if(d<=x){const w=x<=1e-4?1:d/x;return{x:e.x+(u.x-e.x)*w,y:e.y+(u.y-e.y)*w}}if(d>=y){const w=y>=1?0:(d-y)/(1-y);return{x:c.x+(n.x-c.x)*w,y:c.y+(n.y-c.y)*w}}const N=br(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=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return e(r._5,qt("Cons",r._4,e(r._6,i)));g()},n=Rt(r=>T,r=>i=>v("Just",{head:r,tail:i}),Tt(Ct($t.foldr,e(t.nodes,Ht)))(dc));if(n.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(n.tag==="Just"){const r=J(i=>o=>({minX:di(i.minX)(o.x),minY:di(i.minY)(o.y),maxX:mn(i.maxX)(o.x),maxY:mn(i.maxY)(o.y)}))({minX:n._1.head.x,minY:n._1.head.y,maxX:n._1.head.x,maxY:n._1.head.y})(n._1.tail);return{x:r.minX,y:r.minY,w:r.maxX-r.minX,h:r.maxY-r.minY}}g()},Hu={scale:1,tx:0,ty:0},Ye=t=>{const e=Rt(n=>T,n=>r=>v("Just",{head:n,tail:r}),[...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Tt(Ct($t.foldr,n(t.nodes,Ht)))(dc)})(),...Fe((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Ct($t.foldr,n(t.edges,Ht))})()),...Fe((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Ct($t.foldr,n(t.chipExtras,Ht))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:di(r.minX)(i.x),minY:di(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,_=Rt(h=>T,h=>p=>v("Just",{head:h,tail:p}),d);if(_.tag==="Nothing"){a=!1,c=l;continue}if(_.tag==="Just"){const h=_c(_._1.head)(f.interiors);if(h.tag==="Nothing"){a=!1,c=l;continue}if(h.tag==="Just"){o=h._1,u=_._1.tail,s=(()=>{const p=kl(Ye(h._1.layout))((()=>{const m=_c(_._1.head)(f.layout.nodes);if(m.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:Zn};if(m.tag==="Just")return m._1;g()})());return{scale:l.scale*p.scale,tx:l.scale*p.tx+l.tx,ty:l.scale*p.ty+l.ty}})();continue}}g()}return c})(t)(e)(Hu),lc=t=>t,hc=(t,e)=>({tag:t,_1:e}),co=(t,e)=>({tag:t,_1:e}),$u=(t,e)=>({tag:t,_1:e}),Gl=$u("First"),Pl=lc("Forward"),Dl=lc("Backward"),Il=co("ExitNode"),pc=Kt(C)(zt),Ql=t=>ti(e=>n=>({nodes:Ee(C.compare,Le,e.nodes,n.nodes),edges:Ee(C.compare,Le,e.edges,n.edges)}))({nodes:Q,edges:Q})(t.keyframes),Al=t=>e=>({entering:{nodes:Cn(C.compare,e.nodes,t.nodes),edges:Cn(C.compare,e.edges,t.edges)},leaving:{nodes:Cn(C.compare,t.nodes,e.nodes),edges:Cn(C.compare,t.edges,e.edges)},surviving:{nodes:Ki(C.compare,Le,t.nodes,e.nodes),edges:Ki(C.compare,Le,t.edges,e.edges)}}),go=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Lr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},hi=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=v("Just",o._4);continue}}g()}return i},Xu=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Rl=J(t=>e=>K(C)(e)()(t))(Q),Fl=J(t=>e=>K(C)(e)()(t))(Q),Bl=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),mc=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=v("Just",o._4);continue}}g()}return i},yc=Kt(C)(zt),pi=t=>{const e=Rt(n=>T,n=>r=>v("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:go(r.minX)(i.x),minY:go(r.minY)(i.y),maxX:Lr(r.maxX)(i.x),maxY:Lr(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=Rt(n=>T,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return T;if(e.tag==="Just")return v("Just",pi(t));g()},Wl=t=>e=>n=>Rl(Tt(Ct(Oe.foldr,n))(r=>{const i=hi(r)(t);if(i.tag==="Just")return st(o=>!Xu(o)(e),[i._1.source,i._1.target]);if(i.tag==="Nothing")return[];g()})),Ol=t=>t.kind.tag==="SendToken"?v("Just",b(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):T,Ml=t=>t.tag==="DataFlow"?xt(Ol)(t._1.events):[],ql=t=>e=>Fl(xt(n=>Xu(n._2.source)(e)||Xu(n._2.target)(e)?v("Just",n._1):T)(Bl(t))),Hl=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?v("Just",pi([t[0]])):v("Just",pi([t[0],t[e]])):T:0<t.length?v("Just",pi([t[0]])):T},fo=t=>{const e=Rt(n=>T,n=>r=>v("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:go(r.minX)(i.x),minY:go(r.minY)(i.y),maxX:Lr(r.maxX)(i.x+i.w),maxY:Lr(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()},xc=t=>e=>n=>{if(n.tag==="Leaf")return Ye(t);const r=ql(e)(n),i=[...xt(o=>{const u=mc(o)(t.nodes);return u.tag==="Just"?v("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):T})(Ct(Oe.foldr,Ee(C.compare,Le,n,Wl(e)(n)(r)))),...xt(o=>{const u=hi(o)(t.edges);return u.tag==="Just"?v("Just",pi(u._1)):T})(Ct(Oe.foldr,r)),...xt(o=>{const u=hi(o)(t.chipExtras);if(u.tag==="Just")return zl(u._1);if(u.tag==="Nothing")return T;g()})(Ct(Oe.foldr,r))];return i.length===0?Ye(t):fo(i)},mi=t=>e=>n=>{const r=[...xt(i=>i)([(()=>{const i=hi(n)(t.chipExtras);if(i.tag==="Just")return Hl(i._1);if(i.tag==="Nothing")return T;g()})()]),...(()=>{const i=hi(n)(e);if(i.tag==="Just")return xt(o=>{const u=mc(o)(t.nodes);return u.tag==="Just"?v("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?xc(t)(e)(Q):fo(r)},Yu=t=>e=>{const n=Ye(t),r=n.w/Lr(1e-4)(e.zoom),i=n.h/Lr(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-i/2,w:r,h:i}},$l=t=>Ee(C.compare,Le,yc(M(e=>b(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),yc(Tt(t.scenes)(Ml))),Vu=t=>t,Xl=t=>t,lr=Vu("Linear"),Yl=Vu("EaseInOutQuad"),Vl=Vu("SpringBouncy"),yi=t=>e=>n=>{const r=ke(1-e*e),i=t*r;return 1-ji(-e*t*n)*(tn(i*n)+e/r*He(i*n))},Ul=t=>{const e=ut.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ut.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Uu=t=>e=>(()=>{if(t==="Linear")return Xl;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)*ji(-6*n);if(t==="SpringBouncy")return yi(6)(.7);g()})()(Ul(e)),Nc=t=>t,ju=t=>t,_o=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},xi=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jc=t=>e=>{const n=ut.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"),Ni=Nc("LinearLerp"),Tc=Nc("LogLerp"),eh=t=>e=>n=>{const r=n.center.y-e.center.y,i=n.center.x-e.center.x,o=ke(i*i+r*r),u=n.zoom-e.zoom,s=u<0?-u:u;return _o(t.minTransition)(t.maxTransition)(xi(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:Wt(t)(e)})([]),wc=t=>e=>{const n={x:0,y:0},r=0<t.length?t[0].pos:n,i=za(Xt,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=_o(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/xi(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:ji((()=>{const r=Xa(xi(1e-6)(t.zoom));return r+(Xa(xi(1e-6)(e.zoom))-r)*n})())}),ih=t=>e=>n=>{const r=Uu(n.easing)(_o(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)=>Jc(eh(t)(u.toCam)(s.toCam))(u.endT-u.startT),o=J(u=>s=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:v("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:Wt(u.acc)(u.pending._1),pending:v("Just",s)}:{acc:Wt(Wt(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:Ni}),pending:v("Just",s)};g()})({acc:[],pending:T})(r);if(o.pending.tag==="Nothing")return o.acc;if(o.pending.tag==="Just")return Wt(o.acc)(o.pending._1);g()},uh=t=>e=>{const n=r=>{const i=za(Xt,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?v("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:Ni};if(i.kind==="Move")return{startT:i.startT,endT:i.endT,fromCam:i.fromCam,toCam:i.toCam,easing:lr,interp:Ni};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=ur(Xt,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:Ni};g()})(e)},sh={padding:24,easing:lr,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:Jc(o.w/r)(o.h/i)},ah=J(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?v("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})()})()})()?Wt((()=>{const i=t.length-1|0;return i<1?[]:bt(0,i,t)})())({...r._1,endT:e.endT}):Wt(t)(e)})([]),Ji=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:xi(r)(_o(t.minZoom)(t.maxZoom)(Ku(e)(n)(t.padding)))}),ch=t=>e=>n=>r=>{const i=kt(s=>a=>it.compare(a.priority)(s.priority)),o=Ji(t)(e)(Ye(e))(0),u=st(s=>s>=0&&s<=n,nh(kt(ut.compare)([0,n,...Tt(r)(s=>[s.startT,s.endT]),...Tt(r)(s=>{if(s.pathFollow.tag==="Nothing")return[];if(s.pathFollow.tag==="Just")return M(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(st(d=>d.startT<=a&&a<d.endT,r)));if(0<c.length)return v("Just",{kind:th,startT:s._1,endT:s._2,fromCam:{center:wc(c[0].samples)(s._1),zoom:c[0].zoom},toCam:{center:wc(c[0].samples)(s._2),zoom:c[0].zoom},easing:lr});const f=M(d=>d.bbox)(st(d=>d.priority===J(jl)(0)(M(l=>l.priority)(st(l=>l.startT<=a&&a<l.endT,r))),st(d=>d.startT<=a&&a<d.endT,r)));return f.length===0?v("Just",{kind:Kl,startT:s._1,endT:s._2,fromCam:o,toCam:o,easing:t.easing}):v("Just",{kind:Zl,startT:s._1,endT:s._2,fromCam:Ji(t)(e)(fo(f))(Be(d=>d.priority>=1,st(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),toCam:Ji(t)(e)(fo(f))(Be(d=>d.priority>=1,st(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),easing:t.easing})})(Je(En,u,bt(1,u.length,u))))))},vc=t=>e=>n=>r=>{const i=Vt(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=Ji(t)(e)(Ye(e))(0);return 0<n.length?n[0].fromCam:u}g()};function Pn(t){return t.charCodeAt(0)}function bc(t){return String.fromCharCode(t)}const Kn=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)}},gh=function(t){return t.trim()},ho=function(t){return function(e){return e.join(t)}};var fh=typeof Array.from=="function",_h=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",dh=typeof String.prototype.fromCodePoint=="function",lh=typeof String.prototype.codePointAt=="function";const hh=function(t){return lh?function(e){return e.codePointAt(0)}:t},ph=function(t){return dh?String.fromCodePoint:t},mh=function(t){return function(e){return _h?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)}},yh=function(t){return function(e){return fh?function(n){return Array.from(n,e)}:t}},po=t=>{const e=jn(t);if(e===0)return T;if(e===1)return v("Just",{head:Pn(gi(0)(t)),tail:""});const n=Pn(gi(1)(t)),r=Pn(gi(0)(t));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?v("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:fi(2)(t)}):v("Just",{head:r,tail:fi(1)(t)})},xh=t=>{const e=po(t);return e.tag==="Just"?v("Just",b(e._1.head,e._1.tail)):T},Nh=t=>$e.unfoldr(xh)(t),Lc=hh(t=>{const e=Pn(gi(0)(t));if(55296<=e&&e<=56319&&jn(t)>1){const n=Pn(gi(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),mo=yh(Nh)(Lc),ts=t=>io(t>=0&&t<=65535?bc(t):t<0?"\0":"\uFFFF"),Jh=ph(t=>t<=65535?ts(t):ts(kn(t-65536|0,1024)+55296|0)+ts(Vn(t-65536|0)(1024)+56320|0)),kc=t=>e=>{if(t<1)return"";const n=po(e);return n.tag==="Just"?Jh(n._1.head)+kc(t-1|0)(n._1.tail):e},me=mh(kc),Th=t=>e=>e===""?T:v("Just",Lc(e)),kr=(t,e,n)=>({tag:t,_1:e,_2:n}),wh=()=>({tag:"ExtendFromSource"}),Er=(t,e)=>({tag:t,_1:e}),es=t=>t,yo=(t,e)=>({tag:t,_1:e}),ns=yo("NotYet"),Ec=yo("Consumed"),vh=es("FromSource"),Cc=es("FromTarget"),Sc=es("FromBoth"),xo=Er("Hidden"),bh=Er("Visible"),rs=wh(),No=kr("Retracted"),Lh=kr("Extended"),Gc=t=>t,is=(t,e)=>({tag:t,_1:e}),Cr=(t,e,n)=>({tag:t,_1:e,_2:n}),Pc=t=>t,hr=(t,e)=>({tag:t,_1:e}),Sr=(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}),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=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=v("Just",o._4);continue}}g()}return i},yn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Dc=Kt(C)(zt),os=wu(ei),wi=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=v("Just",o._4);continue}}g()}return i},Jo=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},vi=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=v("Just",o._4);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=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Qc=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=v("Just",o._4);continue}}g()}return i},Gr=(()=>{const t=$e.unfoldr(e=>{if(e.tag==="Nil")return T;if(e.tag==="Cons")return v("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._3,n(r._6,i)));g()};return n(e,Ht)})())})(),kh=J(t=>e=>K(C)(e)()(t))(Q),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=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},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=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Eh=hr("NoKeyframes"),Ch=t=>hr("DuplicateEventId",t),Sh=t=>hr("UnknownEvent",t),Ac=Pc("PlopIn"),Gh=Pc("PlopOut"),Ph=Gc("DiveIn"),Dh=Gc("DiveOut"),Ih=t=>e=>n=>r=>{const i=Ti(r.edge)(e.edges),o=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return li(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}},Qh=t=>e=>Dc(xt(n=>{if(n.kind.tag==="SendToken")return v("Just",b(n.id,{pre:(()=>{const r=n.when;return(()=>{const i=n.kind._1.from;return Be(o=>{if(o.kind.tag==="SendToken")return(r.tag==="First"?!1:r.tag==="After"&&r._1===o.id)&&o.kind._1.to===i;if(o.kind.tag==="FillNodeWithoutTransition")return!1;g()},e)})()?0:t.tokenHold})(),post:(()=>{const r=n.id;return(()=>{const i=n.kind._1.to;return Be(o=>{if(o.kind.tag==="SendToken")return(o.when.tag==="First"?!1:o.when.tag==="After"&&o.when._1===r)&&o.kind._1.from===i;if(o.kind.tag==="FillNodeWithoutTransition")return!1;g()},e)})()?0:t.tokenHold})()}));if(n.kind.tag==="FillNodeWithoutTransition")return T;g()})(e)),Ah=t=>{if(t.event.kind.tag==="SendToken")return v("Just",{startT:t.startT,endT:t.endT,target:Sr("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 v("Just",{startT:t.startT,endT:t.endT,target:Sr("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},Rh=t=>e=>n=>r=>{const i=Vt(o=>os(o.path)(e)&&(Xn(o.endT-n)<1e-4||Xn(o.startT-r)<1e-4))(t.segments);if(i.tag==="Just")return v("Just",i._1);if(i.tag==="Nothing")return Vt(o=>os(o.path)(e))(t.segments);g()},Fh=t=>e=>n=>xt(r=>{const i=xt(o=>vi(o)(t.nodes))(Ct(Oe.foldr,(()=>{if(r.scene.tag==="Structural")return Ee(C.compare,Le,(()=>{const o=wi(r.scene._1.from)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()})(),(()=>{const o=wi(r.scene._1.to)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()})());if(r.scene.tag==="DataFlow"){const o=wi(r.scene._1.keyframe)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()}if(r.scene.tag==="EnterNode"||r.scene.tag==="ExitNode")return Q;g()})()));return i.length===0?T:v("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})}),Bh=t=>e=>n=>{const r=Ti(n)(t);if(r.tag==="Nothing")return Cc;if(r.tag==="Just"){const i=Ic(r._1.target)(e);return Ic(r._1.source)(e)?i?Sc:vh:Cc}g()},zh={pre:0,post:0},Wh=t=>e=>n=>r=>i=>{const o=Qc(i.event.id)(n),u=(()=>{if(o.tag==="Nothing")return zh;if(o.tag==="Just")return o._1;g()})(),s=(()=>{if(i.event.when.tag==="First")return 0;if(i.event.when.tag==="At")return i.event.when._1;if(i.event.when.tag==="After"){const c=i.event.when._1,f=Vt(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.endT;g()}if(i.event.when.tag==="With"){const c=i.event.when._1,f=Vt(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.startT}g()})(),a=(()=>{if(i.event.kind.tag==="SendToken")return Ih(t)(e)(u)(i.event.kind._1);if(i.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return Wt(r)({startT:s,endT:s+a.duration,event:i.event,holdPre:a.holdPre,holdPost:a.holdPost})},Rc=t=>e=>n=>J(Wh(t)(e)(Qh(t)(n)))([])(At(r=>i=>({event:i}))(n)),Oh=t=>e=>{const n=vi(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},Mh=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()},Fc={id:"",nodes:Q,edges:Q},Hh=t=>e=>Al((()=>{const n=wi(e.from)(t);if(n.tag==="Nothing")return Fc;if(n.tag==="Just")return n._1;g()})())((()=>{const n=wi(e.to)(t);if(n.tag==="Nothing")return Fc;if(n.tag==="Just")return n._1;g()})()),$h=t=>e=>{const n=vi(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:Q};if(n.tag==="Just")return n._1;g()},as=t=>e=>n=>r=>{const i=Ti(r)(n.edges);if(i.tag==="Just")return t<=0?e:yn(e)(li(i._1)/t);if(i.tag==="Nothing")return e;g()},Bc=t=>e=>n=>r=>i=>{const o=t.plop,u=Hh(n)(i),s=M(_=>({startT:0,endT:0+as(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Sr("EdgeWindow",_,is("Extend",rs))}))(Gr(u.entering.edges)),a=M(_=>({startT:0,endT:o,target:Sr("NodeWindow",_,Ac)}))(Gr(u.entering.nodes)),c=J(yn)(0)(M(_=>as(t.edgeSpeed)(t.minEdgeDuration)(e)(_))(Gr(u.leaving.edges))),f=_=>Be(h=>{const p=Ti(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;g()},Gr(u.leaving.edges))?c:0,d=M(_=>({startT:f(_),endT:f(_)+t.plop,target:Sr("NodeWindow",_,Gh)}))(Gr(u.leaving.nodes)),l=M(_=>({startT:0,endT:as(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Sr("EdgeWindow",_,is("Retract",Bh(r)(u.leaving.nodes)(_)))}))(Gr(u.leaving.edges));return{duration:(()=>{const _=kt(ut.compare)([...M(p=>p.endT)(l),...M(p=>p.endT)(d),...M(p=>p.endT)(a),...M(p=>p.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=>M((()=>{const u=i.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())(Bc(t)(e)(n)(r)(o).windows),Yh=t=>xt(e=>Ct(ti,e).length>1?v("Just",(()=>{const n=Rt(r=>T,r=>i=>v("Just",{head:r,tail:i}),Ct(ti,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):T)(ad(ei)(kt(C.compare)(t))),Vh=t=>{const e=M(r=>r.id)(t),n=kh(e);return[...M(Ch)(Yh(e)),...M(Sh)(st(r=>!us(r)(n),Tt(t)(qh)))]},Uh=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 v("Just",(()=>{const o={pre:i.target._7,post:i.target._8};if(t.tokenZoomFloor<=0)return{startT:i.startT,endT:i.endT,bbox:mi(e)(n)(i.target._2),priority:1,pathFollow:T};const u=Ti(i.target._2)(e.edges);if(u.tag==="Just"){const s=vi(i.target._4)(e.nodes);if(s.tag==="Just"){const a=vi(i.target._5)(e.nodes);if(a.tag==="Just"){const c=a._1;return{startT:i.startT,endT:i.endT,bbox:mi(e)(n)(i.target._2),priority:1,pathFollow:v("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 M(_=>{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)}})(It(0,32))})(),zoom:r})}}if(a.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:mi(e)(n)(i.target._2),priority:1,pathFollow:T};g()}if(s.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:mi(e)(n)(i.target._2),priority:1,pathFollow:T};g()}if(u.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:mi(e)(n)(i.target._2),priority:1,pathFollow:T};g()})());if(i.target.tag==="FillWindow")return v("Just",{startT:i.startT,endT:i.endT,bbox:xc(e)(n)(Mt("Node",1,1,i.target._2,void 0,Q,Q)),priority:1,pathFollow:T});g()})},jh=t=>e=>n=>r=>i=>ch(t)(i.layout)(r.endT)([...Fh(i.layout)(n)(e)(st(o=>o.startT>=i.startT&&o.endT<=i.endT,r.spans)),...Uh(t)(i.layout)(n)(i.windows)]),Zh=t=>{const e=Dc(M(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[hr("ScheduleCycle",[...Ct(Oe.foldr,i),o])];if(us(o)(r))return[];const u=Qc(o)(e);if(u.tag==="Nothing")return[];if(u.tag==="Just")return Tt(u._1)(n(K(C)(o)()(r))(K(C)(o)()(i)));g()};return Tt(t)(r=>n(Q)(Q)(r.id))},Kh={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:.5,hatchHold:.4,tokenReadSecPerChar:.06,nodeEasing:Vl,edgeEasing:Yl,tokenEasing:lr,diveDur:1.2,retreatDur:1.2},t0=t=>e=>n=>r=>M((()=>{const i=n.startT;return o=>({...o,startT:o.startT+i,endT:o.endT+i})})())(xt(Ah)(Rc(t)(e)(r.events))),e0=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 t0(t)(e)(i)(i.scene._1);if(i.scene.tag==="EnterNode")return[];if(i.scene.tag==="ExitNode")return[];g()},n0=t=>e=>n=>{const r=Rc(t)(e)(n.events);return r.length===0?t.gap:J(yn)(0)(M(i=>i.endT)(r))+t.gap},r0=t=>e=>n=>r=>i=>{if(i.tag==="Structural")return Bc(t)(e)(n)(r)(i._1).duration;if(i.tag==="DataFlow")return n0(t)(e)(i._1);if(i.tag==="EnterNode"||i.tag==="ExitNode")return 0;g()},zc=t=>e=>n=>r=>i=>o=>{const u=Sl(e)(r),s=n.layout,a=pc(M(p=>b(p.id,p))(i.keyframes)),c=0<i.keyframes.length?v("Just",i.keyframes[0]):T,f=(()=>{if(c.tag==="Just")return c._1.id;if(c.tag==="Nothing")return"";g()})(),d=$l(i),l=p=>({segments:p.runSpans.length===0?p.segments:Wt(p.segments)({startT:p.runStart,endT:p.t,path:r,layout:s,placement:u,windows:p.runWindows,spans:p.runSpans,keyframes:a,initialKeyframe:f,edgeEndpoints:d}),spans:p.spans,windows:p.windows,dives:p.dives}),_=J(p=>m=>{if(m.tag==="EnterNode"){const w=l(p),k=p.t+t.diveDur,L=Wt(r)(m._1),E=zc(t)(e)($h(n)(m._1))(L)(Oh(i)(m._1))(k),B=E.endT+t.retreatDur;return{...p,t:B,runStart:B,runSpans:[],runWindows:[],segments:[...w.segments,...E.segments],spans:[...w.spans,...E.spans],windows:[...w.windows,...E.windows],dives:[...w.dives,{startT:p.t,endT:k,node:m._1,parentPath:r,childPath:L,direction:Ph},...E.dives,{startT:E.endT,endT:B,node:m._1,parentPath:r,childPath:L,direction:Dh}]}}if(m.tag==="ExitNode")return p;const y=p.t+r0(t)(s)(a)(d)(m),x={startT:p.t,endT:y,scene:m},N=e0(t)(s)(a)(d)(x);return{...p,t:y,runSpans:Wt(p.runSpans)(x),runWindows:[...p.runWindows,...N],spans:Wt(p.spans)(x),windows:[...p.windows,...N]}})({t:o,runStart:o,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(i.scenes),h=l(_);return{endT:_.t,spans:h.spans,windows:kt(p=>m=>ut.compare(p.startT)(m.startT))(h.windows),segments:h.segments,dives:h.dives}},i0=t=>e=>n=>n.endT<=t||n.startT>=e?T:v("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))}},o0=t=>e=>n=>n.placement.scale===1&&n.placement.tx===0&&n.placement.ty===0?Zu(n.placement)(Ji(t)(n.layout)(Ye(n.layout))(0)):cs(t)(e)(n),u0=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=Vt(a=>os(a.path)(u))(r.segments);if(s.tag==="Just"){const a=o0(t)(e)(o._1),c=cs(t)(e)(s._1);if(i.direction==="DiveIn")return v("Just",{startT:i.startT,endT:i.endT,fromCam:a,toCam:c,easing:lr,interp:Tc});if(i.direction==="DiveOut")return v("Just",{startT:i.startT,endT:i.endT,fromCam:c,toCam:a,easing:lr,interp:Tc});g()}if(s.tag==="Nothing")return T;g()}if(o.tag==="Nothing")return T;g()})(r.dives),s0=t=>e=>{if(e.tag==="Structural")return xt(n=>n)([ss(e._1.from)(t)?T:v("Just",hr("UnknownKeyframe",e._1.from)),ss(e._1.to)(t)?T:v("Just",hr("UnknownKeyframe",e._1.to))]);if(e.tag==="DataFlow")return[...xt(n=>n)([ss(e._1.keyframe)(t)?T:v("Just",hr("UnknownKeyframe",e._1.keyframe))]),...Vh(e._1.events),...Zh(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()},a0=t=>e=>{const n=Tt(e)(s0(t));return n.length===0?Pt("Right",void 0):Pt("Left",n)},c0=t=>e=>n=>r=>kt(i=>o=>ut.compare(i.startT)(o.startT))(Tt(r.segments)(i=>i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0?xt(i0(i.startT)(i.endT))(M(Mh(i.placement))(jh(t)(n)(i.edgeEndpoints)(r)(i))):[(()=>{const o=cs(t)(e)(i);return{startT:i.startT,endT:i.endT,fromCam:o,toCam:o,easing:lr,interp:Ni}})()])),g0=t=>e=>n=>r=>{if(0<n.keyframes.length){const i=n.keyframes[0],o=pc(M(s=>b(s.id,s))(n.keyframes)),u=a0(o)(n.scenes);return(()=>{if(u.tag==="Left"){const s=u._1;return a=>Pt("Left",s)}if(u.tag==="Right"){const s=u._1;return a=>a(s)}g()})()(()=>{const s=zc(e)(r)(r)([])(n)(0);return Pt("Right",{totalDuration:s.endT,windows:s.windows,spans:s.spans,keyframes:o,initialKeyframe:i.id,timing:e,layout:r.layout,cameraSpans:[...c0(t)(r.layout)(o)(s),...u0(t)(r.layout)(o)(s)],cameraConfig:t,levelTree:r,segments:s.segments,dives:s.dives,seed:n.seed})})}return Pt("Left",[Eh])},gs=t=>e=>Math.imul(t,e),Pr=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=Pr(n);return{prng:r.prng,value:t+r.value*(e-t)}},fs=t=>e=>J(n=>r=>gs(n^r)(-2048144789))(e)(M(Pn)(Un(t))),_s=t=>t,en=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},To=wu(ei),f0=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Wc=Kt(C)(zt),Oc=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=v("Just",o._4);continue}}g()}return i},Mc=zt.foldMap(ul(C)),qc=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},_0=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=v("Just",o._4);continue}}g()}return i},Dr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},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=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},l0=Kt(C)(zt),h0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},p0=Kt(C)(zt),m0=_s("Backdrop"),Hc=_s("FlyThrough"),wo=_s("Active"),$c=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*ji(-(c-a)/s))},y0=t=>e=>n=>r=>{const i=Ye(t),o=i.w/en(1e-4)(e.zoom)/2,u=i.h/en(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=Vt(i=>To(i.path)(e)&&n>=i.startT&&n<i.endT)(t.segments);if(r.tag==="Just")return v("Just",r._1);if(r.tag==="Nothing")return Vt(i=>To(i.path)(e))(t.segments);g()},x0=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:Hu,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:Q}),N0=t=>M(e=>e<1?[]:bt(0,e,t))(It(0,t.length-1|0)),J0=t=>J(e=>n=>(e*31|0)+Pn(n)|0)(7)(Un(t)),Xc=t=>e=>n=>({...n,state:{...n.state,nodes:Wc(M(r=>b(r._1,t(r._1)(r._2)))(f0(n.state.nodes))),edges:(()=>{const r=i=>{if(i.tag==="Leaf")return Q;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=Oc(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.nodes;g()},hs=t=>e=>{const n=Oc(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.edges;g()},ps=t=>e=>{if(e<t.startT)return Cr("AtKeyframe",t.initialKeyframe);const n=Vt(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Cr("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Cr("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return Cr("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;return r>=0&&r<t.spans.length?Cr("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()})()):Cr("AtKeyframe",t.initialKeyframe)}g()},T0=J(t=>e=>{const n=ni(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?Wt(n._1.init)({...n._1.last,endT:en(n._1.last.endT)(e.endT),windows:Wt(n._1.last.windows)(e)}):Wt(t)({endT:e.endT,windows:[e]})})([]),w0=t=>e=>n=>Mc(r=>Mc(i=>i.target.tag==="FillWindow"?i.startT<=n?Mt("Node",1,1,i.target._2,void 0,Q,Q):Q:i.target.tag==="TokenWindow"&&i.startT+(i.endT-i.startT)*.25<=n?Mt("Node",1,1,i.target._4,void 0,Q,Q):Q)(r.windows))(st(r=>n<=r.endT+t,T0(kt(r=>i=>ut.compare(r.startT)(i.startT))(st(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),v0=t=>e=>n=>Be(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),b0=t=>e=>n=>Be(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),L0=t=>e=>n=>Be(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),k0=t=>e=>n=>Be(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),E0=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()},Yc=t=>e=>n=>Vt(r=>n(r)&&e>=r.startT&&e<r.endT)(t),C0=t=>{const e=qc(0)(1)(t/.2),n=qc(0)(1)((1-t)/.2);return e*e*(3-2*e)*n*n*(3-2*n)},S0=t=>e=>{if(e.tag==="Travelling"){const n=_0(e._1.edge)(t.edges);if(n.tag==="Just"){const r=br(n._1)(e._1.progress);return r.tag==="Just"?v("Just",{dot:r._1,weight:C0(e._1.progress)}):T}if(n.tag==="Nothing")return T;g()}return T},G0={segment:{startT:0,endT:0,path:[],layout:{nodes:Q,edges:Q,chipExtras:Q},placement:Hu,windows:[],spans:[],keyframes:Q,initialKeyframe:"",edgeEndpoints:Q},state:{nodes:Q,edges:Q,tokens:Q,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",visited:Q,nodeFadeAlpha:Q,nodeInvert:Q},bgAlpha:1,role:wo},vo=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:G0},P0=t=>e=>{const n=ps(t)(e);if(n.tag==="AtKeyframe")return ls(t)(n._1);if(n.tag==="InTransition")return Ee(C.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 Ee(C.compare,Le,hs(t)(n._1),hs(t)(n._2));g()},I0=t=>e=>{const n=t.w/en(1e-4)(e.zoom),r=t.h/en(1e-4)(e.zoom);return{...e,center:{x:n>=t.w?t.x+t.w/2:$c(t.x+n/2)(t.x+t.w-n/2)(e.center.x),y:r>=t.h?t.y+t.h/2:$c(t.y+r/2)(t.y+t.h-r/2)(e.center.y)}}},Q0=t=>I0((()=>{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}})()),A0=t=>e=>{const n=t.endT-t.startT;return n<=0?1:en(0)(Dr(1)((e-t.startT)/n))},Vc=t=>e=>n=>en(0)(Dr(1)((n-ae(0)(.3)(t+J0(e)|0).value)/en(1e-4)(.7))),Uc=t=>e=>n=>Xc(r=>i=>i.tag==="Hidden"?xo:Er("PloppingOut",r===e?en(0)(Dr(1)((n-.45)/en(1e-4)(.55))):Vc(t)(r)(n)))(r=>r.tag==="Retracted"?No:kr("Retracting",Sc,n)),jc=t=>e=>Xc(n=>r=>r.tag==="Hidden"?xo:Er("PloppingIn",Vc(t)(n)(e)))(n=>n.tag==="Retracted"?No:kr("Extending",rs,e)),bo=t=>e=>{const n=t.endT-t.startT;return n<=0?1:en(0)(Dr(1)((e-t.startT)/n))},R0=t=>e=>n=>r=>i=>{const o=Yc(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 kr("Retracting",s._1,u);if(s.tag==="Extend")return kr("Extending",s._1,u);g()}if(o.tag==="Nothing")return k0(e)(n)(i)||v0(e)(n)(i)?No:d0(i)(r)?Lh:No;g()},F0=t=>e=>n=>{const r=D0(e)(n);return l0(M(i=>b(i,R0(t)(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Mt("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return Ct(Oe.foldr,i(e.layout.edges))})()))},B0=t=>e=>n=>r=>{const i=Yc(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:Ac;if(u==="PlopIn")return Er("PloppingIn",o);if(u==="PlopOut")return Er("PloppingOut",o);g()}if(i.tag==="Nothing")return L0(t)(e)(r)||b0(t)(e)(r)?xo:h0(r)(n)?bh:xo;g()},z0=t=>e=>n=>{const r=P0(e)(n);return Wc(M(i=>b(i,B0(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Mt("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return Ct(Oe.foldr,i(e.layout.nodes))})()))},W0=t=>e=>n=>e.target.tag==="TokenWindow"?b(e.target._1,n<e.startT?ns:n>=e.endT?Ec: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?Ec:yo("Filling",{node:e.target._2,progress:bo(e)(n),labels:e.target._3})):b("",ns),O0=t=>e=>n=>p0(M(r=>W0(t)(r)(n))(st(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),Ir=t=>e=>n=>({nodes:z0()(e)(n),edges:F0(t)(e)(n),tokens:O0(t)(e.windows)(n),camera:vc(t.cameraConfig)(e.layout)(t.cameraSpans)(n),frameTitle:E0(e)(n),visited:w0(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:Q,nodeInvert:Q}),M0=t=>e=>n=>Ba(T,Da,r=>r.direction==="DiveIn"&&To(r.parentPath)(e.path)&&n>=r.startT-.7&&n<r.startT?v("Just",{node:r.node,phase:(n-(r.startT-.7))/.7}):T,t.dives),q0=t=>e=>n=>r=>{const i=M0(t)(e)(n);if(i.tag==="Just"){const o=He(3.141592653589793*i._1.phase*3);return{...r,state:{...r.state,nodeInvert:Mt("Node",1,1,i._1.node,1*o*o,Q,Q)}}}if(i.tag==="Nothing")return r;g()},Zc=t=>e=>xt(n=>{const r=Vt(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 v("Just",{bgAlpha:1,role:m0,segment:i._1,state:{...Ir(t)(i._1)(r._1.startT-1e-4),nodeFadeAlpha:Mt("Node",1,1,r._1.node,0,Q,Q)}});if(i.tag==="Nothing")return T;g()}if(r.tag==="Nothing")return T;g()})(N0(e)),Kc=t=>e=>{const n=st(i=>e>=i.startT&&e<i.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:x0(t)},H0=t=>e=>n=>{const r=A0(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=en(0)(Dr(1)(r/.6)),s=en(0)(Dr(1)((r-.4)/.6)),a=(()=>{if(n.direction==="DiveIn")return Uc(t.seed)(n.node)(u);if(n.direction==="DiveOut")return jc(t.seed)(s);g()})(),c=(()=>{if(n.direction==="DiveIn")return jc(t.seed)(s);if(n.direction==="DiveOut")return Uc(t.seed)(n.node)(u);g()})();return[...Zc(t)(n.parentPath),...(()=>{if(i.tag==="Just"){if(o.tag==="Just")return[a({segment:i._1,state:Ir(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:Ir(t)(o._1)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),bgAlpha:1,role:wo})];if(o.tag==="Nothing")return[a({segment:i._1,state:Ir(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=Kc(t)(e);return{segment:f,state:Ir(t)(f)(e),bgAlpha:1,role:wo}})()];g()})()]},$0=t=>e=>{const n=xt(S0(t))((()=>{const r=(i,o)=>{if(i.tag==="Leaf")return o;if(i.tag==="Node")return r(i._5,qt("Cons",i._4,r(i._6,o)));g()};return Ct($t.foldr,r(e.tokens,Ht))})());return 0<n.length?v("Just",n[0]):T},X0=t=>e=>{const n=$0(t)(e);if(n.tag==="Nothing")return e.camera;if(n.tag==="Just")return y0(t)(e.camera)(n._1.dot)(n._1.weight);g()},Y0=t=>e=>t.placement.scale===1&&t.placement.tx===0&&t.placement.ty===0?X0(t.layout)(e):e.camera,V0=t=>e=>Vt(n=>e>=n.startT&&e<n.endT)(t.dives),U0=t=>e=>{const n=Kc(t)(e),r=Ir(t)(n)(e),i=t.dives.length!==0,o=vc(t.cameraConfig)(t.layout)(t.cameraSpans)(e),u=Q0(n)(Y0(n)({...r,camera:o})),s=q0(t)(n)(e)({bgAlpha:1,role:wo,segment:n,state:{...r,camera:u}}),a=Zc(t)(n.path),c=V0(t)(e);if(c.tag==="Just")return{levels:H0(t)(e)(c._1),camera:o,rootLayout:t.layout,hasDives:i,diving:!0};if(c.tag==="Nothing")return{levels:Wt(a)(s),camera:u,rootLayout:t.layout,hasDives:i,diving:!1};g()},tg=t=>t,eg=tg("RunText"),j0=tg("RunCode"),ng=t=>e=>n=>e.length===0?n:Wt(n)({style:t,text:fr(e)}),Z0=t=>({style:(()=>{if(t.style==="RunText")return j0;if(t.style==="RunCode")return eg;g()})(),buf:[],runs:ng(t.style)(t.buf)(t.runs)}),K0=t=>e=>0<e.length?{...t,buf:Wt(t.buf)(e[0])}:{...t,buf:Wt(t.buf)("\\")},tp=t=>e=>{let n=t,r=e,i=!0,o;for(;i;){const u=n,s=Rt(a=>T,a=>c=>v("Just",{head:a,tail:c}),r);if(s.tag==="Nothing"){i=!1,o=u;continue}if(s.tag==="Just"){if(s._1.head==="\\"){n=K0(u)(s._1.tail),r=bt(1,s._1.tail.length,s._1.tail);continue}if(s._1.head==="`"){n=Z0(u),r=s._1.tail;continue}n={...u,buf:Wt(u.buf)(s._1.head)},r=s._1.tail;continue}g()}return o},rg=t=>{const e=tp({style:eg,buf:[],runs:[]})(Un(t));return ng(e.style)(e.buf)(e.runs)};let ms=null;function ep(){return ms||(typeof document>"u"?null:(ms=document.createElement("canvas").getContext("2d"),ms))}const ig=new Map,np=t=>e=>n=>r=>()=>{const i=`${n} ${e}px ${t}|${r}`,o=ig.get(i);if(o!==void 0)return o;const u=ep();if(!u)return r.length*e*.62;u.font=`${n} ${e}px ${t}`;const s=u.measureText(r).width;return ig.set(i,s),s},rp=or.traverse(Nu),ip=J(vr)(0),Qr=(()=>{const t=Kn(`\r
|
|
3
|
+
`)(" "),e=Kn(`
|
|
4
|
+
`)(" "),n=(()=>{const r=Kn("\r")(" "),i=(()=>{const o=Kn(" ")(" ");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),og=t=>e=>{const n=rp(r=>{const i=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;g()})();return np(i.family)(i.size)(i.weight)(Qr(r.text))})(rg(Qr(e)));return()=>{const r=n();return ip(r)}},ug={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"}},op=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ar=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},up=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},sp=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ap=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=v("Just",o._4);continue}}g()}return i},sg=t=>fr(Ne(sr(e=>e===" ")(Ne(sr(e=>e===" ")(Un(t)).rest)).rest)),cp=t=>J(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?v("Just",n._1):e)(T)(At(En)(t)),ys=t=>e=>{if(t<=0)return[e];if(jn(e)<=t)return[e];const n=Un(e),r=t<1?[]:bt(0,t,n),i=cp(r);if(i.tag==="Just"){const o=sg(oc(!(i._1>=0&&i._1<r.length)||r[i._1]===" "?i._1:i._1+1|0)(e)),u=sg(fi(i._1+1|0)(e));return u===""?[o]:[o,...ys(t)(u)]}if(i.tag==="Nothing"){const o=oc(t)(e),u=fi(t)(e);return u===""?[o]:[o,...ys(t)(u)]}g()},gp={cellW:7,cellH:3,maxLineWidth:20},fp=t=>e=>{const n=M(o=>b((()=>{if(o.label.tag==="Just")return o.label._1;if(o.label.tag==="Nothing")return o.id;g()})(),o))(e.nodes),r=Ar(1)(kn((up(t.maxLineWidth)(J(o=>u=>Ar(o)(jn(u._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),i=(r*t.cellW|0)-1|0;return{...e,nodes:M(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=>Ar(c)(jn(f)))(0)(u),a=o._2.shape==="Cylinder"?Ar(1)(kn((s+2|0)+t.cellW|0,t.cellW)):r;return{...o._2,size:b(rt(s>i?kn((s+2|0)+t.cellW|0,t.cellW):a),rt(Ar(1)(kn(u.length+t.cellH|0,t.cellH))+(o._2.shape==="Cylinder"||o._2.shape==="Document"?1:0)|0))}})(n)}},_p=t=>e=>n=>({...n,nodes:M(r=>{const i=ap(r.id)(e);if(i.tag==="Nothing")return r;if(i.tag==="Just")return{...r,size:b(sp(r.size._1)(rt(Ar(1)(de(Ui(r.shape==="Cylinder"?(i._1+0)/t:(i._1+32)/t))))),r.size._2)};g()})(n.nodes)}),dp=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},lp=t=>{const e=t.length;return(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(a>=e){u=!1,s=c;continue}const f=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const y=_,x=h;if(y>=e){p=!1,m=x;continue}if(a>=0&&a<t.length){if(y>=0&&y<t.length){_=y+1|0,h=(()=>{const N=t[a].position,w=t[a].size,k=t[y].position,L=t[y].size;return N._1<k._1+L._1&&k._1<N._1+w._1&&N._2<k._2+L._2&&k._2<N._2+w._2})()?x+1|0:x;continue}_=y+1|0,h=x;continue}p=!1,m=x}return m};i=a+1|0,o=f(a+1|0)(c)}return s})(0)(0)},ag=t=>J(e=>n=>e+xl(n.start)(n.end))(0)(t.segments),hp=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+ag(i))(0)(e),maxEdgeLength:J(r=>i=>dp(r)(ag(i)))(0)(e),nodeOverlapCount:lp(t),constraintViolations:n,jumpCount:J(r=>i=>r+i.jumps.length|0)(0)(e)}),xs=t=>t,Ut=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=v("Just",o._4);continue}}g()}return i},Ns=xs("LEFT"),pp=xs("RIGHT"),cg=xs("UNDEFINED"),mp={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},yp={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:()=>mp},xp=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},Np={x:0,y:0},Ve=t=>e=>n=>{const r=Ut(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()},bi=t=>e=>n=>{const r=Ut(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()},Jp=t=>J(e=>n=>Ve(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),Tp=t=>{const e=J(n=>r=>{const i=Ut(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()})(Q)(t.cNodeOrder);return J(n=>r=>Ve(r)(i=>({...i,constraints:(()=>{const o=Ut(r)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})()}))(n))(t)(t.cNodeOrder)},wp=t=>e=>Ve(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}})),vp=t=>{const e=J(n=>r=>bi(r)(i=>({...i,outDegree:i.outDegreeReal}))(n))(t)(t.cGroupOrder);return J(n=>r=>Ve(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder)},an={left:!1,right:!1,up:!1,down:!1},bp={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},Js=t=>J(e=>n=>{const r=Ut(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const i=J(u=>s=>{const a=Ut(s)(e.cNodes);if(a.tag==="Nothing")return u;if(a.tag==="Just"){if(u.tag==="Nothing")return v("Just",s);if(u.tag==="Just"){const c=Ut(u._1)(e.cNodes);if(c.tag==="Nothing")return v("Just",s);if(c.tag==="Just")return a._1.hitbox.x<c._1.hitbox.x?v("Just",s):v("Just",u._1)}}g()})(T)(r._1.cNodes),o=bi(n)(u=>({...u,reference:i}))(e);if(i.tag==="Nothing")return o;if(i.tag==="Just"){const u=Ut(i._1)(o.cNodes);if(u.tag==="Nothing")return o;if(u.tag==="Just"){const s=u._1;return J(a=>c=>Ve(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),Ue=t=>Js({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return Q;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 Q;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)})()}),gg=t=>{const e=J(n=>r=>bi(r)(i=>({...i,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return J(n=>r=>{const i=Ut(r)(n.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just"){if(i._1.cGroup.tag==="Nothing")return n;if(i._1.cGroup.tag==="Just"){const o=i._1.cGroup._1;return J(u=>s=>{const a=Ut(s)(u.cNodes);if(a.tag==="Nothing")return u;if(a.tag==="Just")return a._1.cGroup.tag==="Just"&&a._1.cGroup._1!==o?bi(a._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(bi(o)(c=>ze(Jr)(s)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,s]})(u)):u;g()})(n)(i._1.constraints)}}g()})(e)(e.cNodeOrder)},Lo=t=>{const e=Tp(t.cGraph);return{...t,cGraph:gg(J(n=>r=>Ve(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},Lp=t=>e=>J(n=>r=>{if(t==="LEFT"||t==="UP"){const o=r._2;return Ve(r._1)(u=>({...u,constraints:[...u.constraints,o]}))(n)}const i=r._1;return Ve(r._2)(o=>({...o,constraints:[...o.constraints,i]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),cn=t=>{const e={...t,cGraph:Lp(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return Q;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:gg((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);g()})())}},kp=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?cn(r):e==="RIGHT"?cn({...r,cGraph:Ue(r.cGraph)}):e==="UP"?cn({...r,cGraph:xn(r.cGraph)}):e==="DOWN"?cn({...r,cGraph:Ue(xn(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?Lo({...r,cGraph:Ue(r.cGraph)}):e==="UP"?cn({...r,cGraph:xn(r.cGraph)}):e==="DOWN"?cn({...r,cGraph:Ue(xn(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?Lo({...r,cGraph:Ue(r.cGraph)}):e==="UP"?cn({...r,cGraph:xn(Ue(r.cGraph))}):e==="DOWN"?cn({...r,cGraph:Ue(xn(Ue(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?cn({...r,cGraph:xn(r.cGraph)}):e==="RIGHT"?cn({...r,cGraph:Ue(xn(r.cGraph))}):e==="DOWN"?Lo({...r,cGraph:Ue(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?cn({...r,cGraph:xn(Ue(r.cGraph))}):e==="RIGHT"?cn({...r,cGraph:Ue(xn(Ue(r.cGraph)))}):e==="UP"?Lo({...r,cGraph:Ue(r.cGraph)}):r;g()},fg=t=>e=>e.finished||!xp(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:kp(e.direction)(t)(e),Ep=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?fg(Ns)(t):t,n={...e,cGraph:vp(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},_g=t=>e=>n=>{const r=Ut(t)(n.cNodes),i=Ut(e)(n.cGroups);return r.tag==="Just"&&i.tag==="Just"?(()=>{if(r._1.cGroup.tag==="Nothing")return!1;if(r._1.cGroup.tag==="Just")return!0;g()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:K(it)(t)({...r._1,cGroup:v("Just",e)})(n.cNodes),cGroups:K(it)(e)({...i._1,cNodes:ze(Jr)(t)(i._1.cNodes)?i._1.cNodes:[...i._1.cNodes,t],reference:(()=>{if(i._1.reference.tag==="Nothing")return v("Just",t);if(i._1.reference.tag==="Just")return v("Just",i._1.reference._1);g()})()})(n.cGroups)}:n},dg=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:K(it)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:T,cGroupOffset:Np,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:an})(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=>_g(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)}},Cp=t=>J(e=>n=>{const r=Ut(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?Ts({master:T,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),Sp=t=>({cGraph:Jp(Cp(Js(t))),direction:cg,compactionAlgorithm:T,constraintAlgorithm:T,spacingsHandler:bp,lockFun:T,finished:!1}),lg=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Gp=t=>e=>{const n=ut.compare(t._1)(e._1);return n==="LT"?ye:n==="GT"?xe:it.compare(t._2)(e._2)},Pp=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),hg=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=v("Just",o._4);continue}}g()}return i},pg=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",mg=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),yg=lg(0)(4.5),Dp=lg(0)(4.5),ko=t=>e=>Gp(b(t.hitbox.x+t.hitbox.width/2,t.id))(b(e.hitbox.x+e.hitbox.width/2,e.id)),Ip=t=>e=>{const n=ur(Xt,T,r=>ko(t)(r)==="LT",e);if(n.tag==="Just"){const r=Wa(Xt,T,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return Wt(e)(t);g()},xg=t=>e=>{const n=st(i=>ko(i)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?v("Just",n[r]):T},Qp=t=>e=>{const n=Ip(e)(t.intervals),r=Vt(o=>ko(e)(o)==="LT")(n),i=K(it)(e.id)((()=>{const o=xg(e)(n);return o.tag==="Just"?v("Just",o._1.id):T})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return K(it)(r._1.id)(v("Just",e.id))(i);if(r.tag==="Nothing")return i;g()})()}},Ap=t=>e=>{const n=ut.compare(t.low?t.node.hitbox.y:t.node.hitbox.y+t.node.hitbox.height)(e.low?e.node.hitbox.y:e.node.hitbox.y+e.node.hitbox.height);return n==="EQ"?t.low?t.low&&!e.low?xe:Ge:e.low?ye:Ge:n},Rp=t=>J(e=>n=>Ve(n.id)(r=>({...r,constraints:[]}))(e))(t)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),ws=t=>e=>J(n=>r=>{const i=Ut(r._1)(n.cNodes);if(i.tag==="Just")return Ve(r._1)(o=>({...o,constraints:[...o.constraints,...r._2]}))(n);if(i.tag==="Nothing")return n;g()})(e)(Pp(t)),Ng=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}},Jg=t=>e=>n=>J(r=>i=>n(i)?Ve(i.id)(Ng(t))(r):r)(e)(xt(r=>Ut(r)(e.cNodes))(e.cNodeOrder)),Fp=t=>e=>{const n=(r,i,o)=>{const u=Ve(o)(Ng(t))(r);return i.length<=1?u:J(s=>a=>a===o?s:Ve(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=>Ut(r)(e.cGroups))(e.cGroupOrder))},Bp=t=>e=>{const n=xg(e)(t.intervals),r=Vt(o=>ko(e)(o)==="LT")(t.intervals),i=n.tag==="Just"&&(()=>{const o=hg(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=hg(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:st(o=>o.id!==e.id,t.intervals)}},zp=t=>e=>e.low?Qp(t)(e.node):Bp(t)(e.node),vs=t=>e=>J(zp)({intervals:[],cand:Q,constraints:Q})(kt(Ap)(Tt(st(t,xt(n=>Ut(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,Wp=t=>{const e=ws(vs(pg)(Jg(Dp)(t)(pg)))(t),n=ws(vs(mg)(Jg(yg)(e)(mg)))(e);return ws(vs(r=>!0)(Fp(yg)(n)))(n)},Op=t=>Wp(Rp(t.cGraph)),Eo=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Tg=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bs=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:Xn(e._1-n._1),height:Xn(e._2-n._2)},ignoreSpacing:an,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:T}),Mp=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:Tg(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Tg(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()})()}},qp=t=>e=>Xn(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,Hp=t=>e=>Xn(t.hitbox.x-e.hitbox.x)<=1e-4?ut.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?ye:xe,wg=(t,e)=>({tag:t,_1:e}),Ls=Kt(C)(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=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=v("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=C.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 C.compare(n._2._1)(r._2._1);g()},Eq0:()=>t};return J(n=>r=>K(e)(r)()(n))(Q)})(),Dn=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=v("Just",o._4);continue}}g()}return i},$p=J(t=>e=>K(yp)(e)()(t))(Q),ks=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=cc.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=v("Just",o._4);continue}}g()}return i},Xp=t=>e=>{const n=Ls(M(o=>b(o.id,o))(t)),r=xt(o=>Co(o)(n))(e),i=it.compare((()=>{const o=vg(M(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(M(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{...an,left:!0,right:!1};if(i==="GT")return{...an,left:!1,right:!0};if(i==="EQ")return an;g()},Yp=t=>xt(e=>{if(e.direction==="V")return v("Just",{start:e.start,end:e.end});if(e.direction==="H")return T;g()})(t.segments),So=t=>e=>n=>r=>{if(r.tag==="Just"){const i=Dn(n)(e);if(i.tag==="Just"){const o=Vt(u=>u.id===r._1)(i._1);if(o.tag==="Just")return o._1.side;if(o.tag==="Nothing")return t;g()}if(i.tag==="Nothing")return t;g()}if(r.tag==="Nothing")return t;g()},Vp=t=>e=>n=>{const r=dg({origin:v("Just",wg("SegmentOrigin",n)),kind:v("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=Ut(n.potentialGroupParents[0])(i.cNodes);if(o.tag==="Just"){if(o._1.cGroup.tag==="Just")return _g(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:v("Just",r.id),nodes:[r.id]})(i).graph})(),edgeToCs:J(o=>u=>vt(C)(te)(u)([r.id])(o))(e.edgeToCs)(n.representedEdges),lockMap:K(it)(r.id)(Xp(t)(n.representedEdges))(e.lockMap)}},Up=t=>e=>n=>{const r=Rt(i=>T,i=>o=>v("Just",{head:i,tail:o}),kt(Hp)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const i=J(o=>u=>qp(o.survivor)(u)?{...o,survivor:Mp(o.survivor)(u)}:{survivor:u,merged:[...o.merged,o.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return J(Vp(t))(n)([...i.merged,i.survivor])}g()},jp=t=>({cGraph:{cNodes:Q,cNodeOrder:[],cGroups:Q,cGroupOrder:[],supportedDirections:$p([cg,Ns,pp]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:Q,edgeToCs:Q,lockMap:Q}),Zp=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}},Kp=t=>e=>n=>J(r=>i=>{const o=dg({origin:v("Just",wg("NodeOrigin",i.node)),kind:T,hitbox:Zp(i)})(r.cGraph),u=Dn(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:v("Just",o.id),nodes:[o.id]})(o.graph).graph,nodeToC:K(C)(i.node)(o.id)(r.nodeToC),lockMap:K(it)(o.id)((()=>{const a=s._1-s._2|0;return a<0?{...an,left:!0}:a>0?{...an,right:!0}:an})())(r.lockMap)}})(n)(e),tm=t=>J(e=>n=>vt(C)(r=>i=>b(r._1+i._1|0,r._2+i._2|0))(n.to.node)(b(1,0))(vt(C)(r=>i=>b(r._1+i._1|0,r._2+i._2|0))(n.from.node)(b(0,1))(e)))(Q)(t),em=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?K(C)(n.origin._1._1)(n.hitbox.x)(e):e)(Q)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),nm=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)(Q)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),rm=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(cc)(o)(r)(i))(e)(n.origin._1._1.affectedBends)}return e})(Q)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),bg=t=>{const e=Ls(M(n=>b(n.id,n))(t.edges));return xt(n=>{const r=Co(n.edge)(e);if(r.tag==="Just")return n.reversed?v("Just",{edgeId:n.edge,src:r._1.to.node,tgt:r._1.from.node,srcSide:So(Sn)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:So(Gn)(t.ports)(r._1.from.node)(r._1.from.port),path:n}):v("Just",{edgeId:n.edge,src:r._1.from.node,tgt:r._1.to.node,srcSide:So(Sn)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:So(Gn)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return T;g()})(t.paths)},im=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=Dn(r.tgt)(t.nodeToC),o=(()=>{if(i.tag==="Just")return Ut(i._1)(t.cGraph.cNodes);if(i.tag==="Nothing")return T;g()})(),u=Dn(r.src)(t.nodeToC),s=(()=>{if(u.tag==="Just")return Ut(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 v("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=>p=>{if(s.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(p.cGroup.tag==="Just")return _(p.hitbox.x)&&p.cGroup._1!==s._1.cGroup._1?v("Just",h(p.cGroup._1)(s._1.cGroup._1)):T;if(p.cGroup.tag==="Nothing")return T;g()}if(s._1.cGroup.tag==="Nothing")return T;g()}if(s.tag==="Nothing")return T;g()},f=xt(_=>Ut(_)(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=>p=>({srcGroup:h,tgtGroup:p,delta:1,weight:100})))(f)}return[]})(),l=(()=>{if(s.tag==="Just"&&r.tgtSide==="East"){const _=s._1;return xt(c(h=>h>_.hitbox.x)(h=>p=>({srcGroup:p,tgtGroup:h,delta:1,weight:100})))(f)}return[]})();if(a.tag==="Nothing")return[];if(a.tag==="Just")return[a._1,...d,...l];g()});return{sameEdgeVerticalSegments:r=>i=>r.origin.tag==="Just"&&r.origin._1.tag==="SegmentOrigin"&&i.origin.tag==="Just"&&i.origin._1.tag==="SegmentOrigin"&&(()=>{const o=i.origin._1._1;return Be(u=>ze(fn)(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}},om=t=>e=>{const n=rt(4),r=em(t),i=nm(t),o=Ls(M(s=>b(s.id,b(s.from.node,s.to.node)))(e.edges)),u=rm(t);return{nodes:M(s=>{const a=Dn(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:M(s=>{const a=Co(s.edge)(o),c=(()=>{if(a.tag==="Nothing")return s.segments;if(a.tag==="Just"){const f=Dn(a._1._1)(i),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})(),l=Dn(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,p=s.reversed?d:_,m=s.segments.length;return y=>x=>{if(x.direction==="V"){const N=(()=>{if(y===0)return h;if(y===(m-1|0))return p;const w=ks(x.start)(u);if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._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=ks(x.start)(u);if(N.tag==="Nothing")return x.start._1+0;if(N.tag==="Just")return x.start._1+N._1;g()})(),x.start._2),end:b((()=>{if(y===(m-1|0))return x.end._1+p;const N=ks(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)}},um=t=>e=>n=>r=>i=>o=>{const u=bs(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})()]}},Lg=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...bs(o.nextId)(r.start)(b(r.start._1,i.down?n.y:n.y+n.height))(v("Just",e))(t.edgeId),aPort:v("Just",{node:t.src,side:i.side}),ignoreSpacing:i.down?{...an,down:!0}:{...an,up:!0}}]}),Go=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...bs(o.nextId)(r.end)(b(r.end._1,i.down?n.y:n.y+n.height))(v("Just",e))(t.edgeId),aPort:v("Just",{node:t.tgt,side:i.side}),ignoreSpacing:i.down?{...an,down:!0}:{...an,up:!0}}]}),sm=t=>e=>n=>{if(n.src===n.tgt)return e;const r=Dn(n.src)(t.nodeToC),i=Dn(n.tgt)(t.nodeToC),o=(()=>{if(r.tag==="Just"){const f=Ut(r._1)(t.cGraph.cNodes);return f.tag==="Just"?v("Just",f._1.hitbox):T}if(r.tag==="Nothing")return T;g()})(),u=(()=>{if(i.tag==="Just"){const f=Ut(i._1)(t.cGraph.cNodes);return f.tag==="Just"?v("Just",f._1.hitbox):T}if(i.tag==="Nothing")return T;g()})(),s=Yp(n.path),a=J(um(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 Lg(n)(r._1)(o._1)(s[0])({side:le,down:!0})(a);if(n.srcSide==="South")return Lg(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},am=t=>e=>n=>Up(t)(J(sm(n))({nextId:0,segments:[]})(e).segments)(n),cm=t=>am(t.edges)(bg(t))(Kp(tm(t.edges))(t.nodes)(jp())),In=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},Es=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Cs=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=v("Just",o._4);continue}}g()}return i},gm=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fm=t=>{const e=t.Eq0();return n=>r=>{const i=s=>{let a=s,c=!0,f;for(;c;){const d=a,l=Rt(_=>T,_=>h=>v("Just",{head:_,tail:h}),d.queue);if(l.tag==="Nothing"){c=!1,f=d;continue}if(l.tag==="Just"){const _=l._1.head;if((p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=!1;continue}if(N.tag==="Node"){const w=t.compare(_)(N._3);if(w==="LT"){m=N._5;continue}if(w==="GT"){m=N._6;continue}if(w==="EQ"){y=!1,x=!0;continue}}g()}return x})(d.removedNodes)){a={...d,queue:l._1.tail};continue}const h=Vt(p=>!In(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 y=(x=>{let N=x,w=!0,k;for(;w;){const L=N;if(L.tag==="Leaf"){w=!1,k=T;continue}if(L.tag==="Node"){const E=t.compare(p)(L._3);if(E==="LT"){N=L._5;continue}if(E==="GT"){N=L._6;continue}if(E==="EQ"){w=!1,k=v("Just",L._4);continue}}g()}return k})(d.degree);if(y.tag==="Nothing")return-1;if(y.tag==="Just")return y._1-1|0;g()})())(d.degree),removedNodes:K(t)(_)()(d.removedNodes),removedEdges:K(it)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:_,neighbour:p,viaSrc:e.eq(h._1.src)(_)}],queue:l._1.tail};if((()=>{const y=(N=>{let w=N,k=!0,L;for(;k;){const E=w;if(E.tag==="Leaf"){k=!1,L=T;continue}if(E.tag==="Node"){const B=t.compare(p)(E._3);if(B==="LT"){w=E._5;continue}if(B==="GT"){w=E._6;continue}if(B==="EQ"){k=!1,L=v("Just",E._4);continue}}g()}return L})(m.degree),x=N=>{let w=N,k=!0,L;for(;k;){const E=w;if(E.tag==="Leaf"){k=!1,L=!1;continue}if(E.tag==="Node"){const B=t.compare(p)(E._3);if(B==="LT"){w=E._5;continue}if(B==="GT"){w=E._6;continue}if(B==="EQ"){k=!1,L=!0;continue}}g()}return L};return(()=>{if(y.tag==="Nothing")return!1;if(y.tag==="Just")return y._1===1;g()})()&&!x(m.removedNodes)})()){a={...m,queue:[...m.queue,p]};continue}a=m;continue}}g()}return f},o=J(s=>a=>vt(t)(oe)(a.src)(1)(vt(t)(oe)(a.tgt)(1)(s)))(Q)(r),u=i({degree:o,removedNodes:Q,removedEdges:Q,record:[],queue:st(s=>{const a=(c=>{let f=c,d=!0,l;for(;d;){const _=f;if(_.tag==="Leaf"){d=!1,l=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=v("Just",_._4);continue}}g()}return l})(o);if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1===1;g()},n)});return{coreNodes:st(s=>!(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=!1;continue}if(l.tag==="Node"){const _=t.compare(s)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=!0;continue}}g()}return d})(u.removedNodes),n),coreEdges:st(s=>!In(s.eid)(u.removedEdges),r),removed:u.record}}},_m=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=v("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)(Ne(e)),Ss=t=>{const e=t.Eq0();return n=>r=>i=>{const o={...i,treeNode:K(t)(r)()(i.treeNode)};return J(u=>s=>{if(In(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=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(f)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=s.tgt;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?s.src:(()=>{const f=s.tgt,d=_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(f)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=s.src;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(In(s.eid)(a.treeEdge)){if((d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=!1;continue}if(p.tag==="Node"){const m=t.compare(c)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=!0;continue}}g()}return h})(a.treeNode))return{...u,st:a};const f=Ss(t)(n)(c)(a);return{count:u.count+f.count|0,st:f.st}}if((()=>{const f=l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=!1;continue}if(m.tag==="Node"){const y=t.compare(c)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=!0;continue}}g()}return p},d=s.tgt;return!f(a.treeNode)&&(()=>{const l=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const w=t.compare(d)(N._3);if(w==="LT"){m=N._5;continue}if(w==="GT"){m=N._6;continue}if(w==="EQ"){y=!1,x=v("Just",N._4);continue}}g()}return x})(a.layer),_=s.src,h=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const w=t.compare(_)(N._3);if(w==="LT"){m=N._5;continue}if(w==="GT"){m=N._6;continue}if(w==="EQ"){y=!1,x=v("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=Ss(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})(st(u=>(e.eq(u.src)(r)||e.eq(u.tgt)(r))&&!In(u.eid)(o.edgeVisited),n))}},Po=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 y=t.compare(i)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=v("Just",m._4);continue}}g()}return p})(e.poID),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})(),s=r.tgt,a=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=T;continue}if(m.tag==="Node"){const y=t.compare(s)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=v("Just",m._4);continue}}g()}return p})(e.poID),c=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})(),f=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=T;continue}if(m.tag==="Node"){const y=t.compare(n)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=v("Just",m._4);continue}}g()}return p})(e.poID),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return(()=>{const l=r.src,_=(h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=T;continue}if(x.tag==="Node"){const N=t.compare(l)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=v("Just",x._4);continue}}g()}return y})(e.lowestPoID);return(()=>{if(_.tag==="Nothing")return 0<=d;if(_.tag==="Just")return _._1<=d;g()})()&&(()=>{const h=r.tgt;return d<=u&&(()=>{const p=(m=>{let y=m,x=!0,N;for(;x;){const w=y;if(w.tag==="Leaf"){x=!1,N=T;continue}if(w.tag==="Node"){const k=t.compare(h)(w._3);if(k==="LT"){y=w._5;continue}if(k==="GT"){y=w._6;continue}if(k==="EQ"){x=!1,N=v("Just",w._4);continue}}g()}return N})(e.lowestPoID);return(()=>{if(p.tag==="Nothing")return 0<=d;if(p.tag==="Just")return p._1<=d;g()})()&&d<=c})()})()})()?u>=c:u<c},dm=t=>{const e=Kt(t)(zt);return n=>({layer:e(M(r=>b(r,0))(n)),treeNode:Q,treeEdge:Q,poID:Q,lowestPoID:Q,cutvalue:Q,postOrder:1,edgeVisited:Q})},lm=t=>e=>n=>J(r=>i=>{if((()=>{const f=i.src,d=h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=!1;continue}if(x.tag==="Node"){const N=t.compare(f)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=!0;continue}}g()}return y},l=i.tgt,_=h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=!1;continue}if(x.tag==="Node"){const N=t.compare(l)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=!0;continue}}g()}return y};return d(n.treeNode)===_(n.treeNode)})())return r;const o=i.tgt,u=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=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,_=v("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 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,_=v("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:v("Just",i),slack:c}:r})({edge:T,slack:1e9})(e).edge,hm=t=>{const e=Kt(t)(zt);return n=>r=>{const i=J(o=>u=>Es(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=v("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(M(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=v("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))}},kg=t=>{const e=t.Eq0();return n=>r=>i=>{const o=J(s=>a=>{const c=kg(t)(n)(e.eq(a.src)(r)?a.tgt:a.src)({...s.st,edgeVisited:K(it)(a.eid)()(s.st.edgeVisited)});return{lowest:Es(s.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:i})(st(s=>In(s.eid)(i.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!In(s.eid)(i.edgeVisited),n)),u=Es(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}}}},Eg=t=>{const e=kg(t);return n=>r=>i=>0<n.length?e(r)(n[0])({...i,edgeVisited:Q,postOrder:1,poID:Q,lowestPoID:Q}).st:i},pm=t=>{const e=t.Eq0();return n=>r=>i=>st(o=>In(o.eid)(r.treeEdge)&&(e.eq(o.src)(i)||e.eq(o.tgt)(i)),n)},mm=t=>e=>Vt(n=>{const r=Cs(n.eid)(e.cutvalue);return In(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),Cg=t=>{const e=Ss(t);return n=>r=>i=>{const o=0<n.length?v("Just",n[0]):T;if(o.tag==="Nothing")return i;if(o.tag==="Just"){const u=e(r)(o._1)({...i,edgeVisited:Q,treeNode:Q,treeEdge:Q});if(u.count>=n.length)return u.st;const s=lm(t)(r)(u.st);if(s.tag==="Nothing")return u.st;if(s.tag==="Just"){const a=s._1.tgt,c=(h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=T;continue}if(x.tag==="Node"){const N=t.compare(a)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=v("Just",x._4);continue}}g()}return y})(u.st.layer),f=s._1.src,d=(h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=T;continue}if(x.tag==="Node"){const N=t.compare(f)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=v("Just",x._4);continue}}g()}return y})(u.st.layer),l=(()=>{if(c.tag==="Nothing"){if(d.tag==="Nothing")return-s._1.delta;if(d.tag==="Just")return-d._1-s._1.delta|0;g()}if(c.tag==="Just"){if(d.tag==="Nothing")return(c._1-0|0)-s._1.delta|0;if(d.tag==="Just")return(c._1-d._1|0)-s._1.delta|0}g()})(),_=(()=>{const h=s._1.tgt;return(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=!1;continue}if(N.tag==="Node"){const w=t.compare(h)(N._3);if(w==="LT"){m=N._5;continue}if(w==="GT"){m=N._6;continue}if(w==="EQ"){y=!1,x=!0;continue}}g()}return x})(u.st.treeNode)})()?-l:l;return Cg(t)(n)(r)({...u.st,layer:J(h=>p=>(m=>{let y=m,x=!0,N;for(;x;){const w=y;if(w.tag==="Leaf"){x=!1,N=!1;continue}if(w.tag==="Node"){const k=t.compare(p)(w._3);if(k==="LT"){y=w._5;continue}if(k==="GT"){y=w._6;continue}if(k==="EQ"){x=!1,N=!0;continue}}g()}return N})(u.st.treeNode)?K(t)(p)((()=>{const m=(y=>{let x=y,N=!0,w;for(;N;){const k=x;if(k.tag==="Leaf"){N=!1,w=T;continue}if(k.tag==="Node"){const L=t.compare(p)(k._3);if(L==="LT"){x=k._5;continue}if(L==="GT"){x=k._6;continue}if(L==="EQ"){N=!1,w=v("Just",k._4);continue}}g()}return w})(u.st.layer);if(m.tag==="Nothing")return 0+_|0;if(m.tag==="Just")return m._1+_|0;g()})())(h):h)(u.st.layer)(n)})}}g()}},ym=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 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=v("Just",p._4);continue}}g()}return h})(r.layer),a=o.src,c=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=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=v("Just",p._4);continue}}g()}return h})(r.layer),f=(()=>{if(s.tag==="Nothing"){if(c.tag==="Nothing")return-o.delta;if(c.tag==="Just")return-c._1-o.delta|0;g()}if(s.tag==="Just"){if(c.tag==="Nothing")return(s._1-0|0)-o.delta|0;if(c.tag==="Just")return(s._1-c._1|0)-o.delta|0}g()})();if(f<i.slack)return{edge:v("Just",o),slack:f}}return i})({edge:T,slack:1e9})(e).edge,xm=t=>{const e=t.Eq0();return n=>r=>i=>o=>{const u=o.tgt,s=o.src;return J(a=>c=>{if((()=>{const f=Cs(c.eid)(r.cutvalue);if(f.tag==="Just")return!0;if(f.tag==="Nothing")return!1;g()})()){const f=Cs(c.eid)(r.cutvalue),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return e.eq(s)(c.src)||e.eq(u)(c.tgt)?a-(d-c.weight):a+(d-c.weight)}return e.eq(i)(s)?e.eq(c.src)(i)?a+c.weight:a-c.weight:e.eq(c.src)(i)?a-c.weight:a+c.weight})(o.weight)(st(a=>a.eid!==o.eid&&(e.eq(a.src)(i)||e.eq(a.tgt)(i)),n))}},Nm=t=>{const e=xm(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 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,_=v("Just",h._4);continue}}g()}return _})(a);if(c.tag==="Just")return K(t)(u)(st(f=>f.eid!==s.eid,c._1))(a);if(c.tag==="Nothing")return a;g()};return(u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=(m=>{let y=m,x=!0,N;for(;x;){const w=y;if(w.tag==="Leaf"){x=!1,N=T;continue}if(w.tag==="Node"){const k=t.compare(_)(w._3);if(k==="LT"){y=w._5;continue}if(k==="GT"){y=w._6;continue}if(k==="EQ"){x=!1,N=v("Just",w._4);continue}}g()}return N})(l.unknown),p=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;g()})();if(p.length===1){const m=t.Eq0().eq(p[0].src)(_)?p[0].tgt:p[0].src;a={unknown:o(_,p[0],o(m,p[0],l.unknown)),cutvalue:K(it)(p[0].eid)(e(n)(l)(_)(p[0]))(l.cutvalue)},c=m;continue}f=!1,d=l}return d})(r)(i)}},Sg=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:c=>f=>c.delta===f.delta&&c.eid===f.eid&&n.eq(c.src)(f.src)&&e.eq(c.tgt)(f.tgt)&&c.weight===f.weight},i={compare:c=>f=>{const d=it.compare(c.delta)(f.delta);if(d==="LT"||d==="GT"||d!=="EQ")return d;const l=it.compare(c.eid)(f.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const _=t.compare(c.src)(f.src);if(_==="LT"||_==="GT"||_!=="EQ")return _;const h=t.compare(c.tgt)(f.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const p=ut.compare(c.weight)(f.weight);return p==="LT"||p==="GT"||p!=="EQ"?p:Ge},Eq0:()=>r},o=J(c=>f=>K(i)(f)()(c))(Q),u=pm(t),s=Kt(t)(zt),a=Nm(t);return c=>f=>d=>{const l={unknown:s(M(_=>b(_,Ct(Oe.foldr,o(u(f)(d)(_)))))(c)),cutvalue:Q};return{...d,cutvalue:J(a(f))(l)(st(_=>{const h=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const w=t.compare(_)(N._3);if(w==="LT"){m=N._5;continue}if(w==="GT"){m=N._6;continue}if(w==="EQ"){y=!1,x=v("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}}},Jm=t=>{const e=Eg(t),n=Sg(t);return r=>i=>o=>u=>s=>{const a={...s,treeEdge:K(it)(u.eid)()(ii(it)(o.eid)(s.treeEdge))},c=u.tgt,f=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const w=t.compare(c)(N._3);if(w==="LT"){m=N._5;continue}if(w==="GT"){m=N._6;continue}if(w==="EQ"){y=!1,x=v("Just",N._4);continue}}g()}return x})(a.layer),d=u.src,l=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const w=t.compare(d)(N._3);if(w==="LT"){m=N._5;continue}if(w==="GT"){m=N._6;continue}if(w==="EQ"){y=!1,x=v("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(p=>m=>Po(t)(a)(m)(o)?p:K(t)(m)((()=>{const y=(x=>{let N=x,w=!0,k;for(;w;){const L=N;if(L.tag==="Leaf"){w=!1,k=T;continue}if(L.tag==="Node"){const E=t.compare(m)(L._3);if(E==="LT"){N=L._5;continue}if(E==="GT"){N=L._6;continue}if(E==="EQ"){w=!1,k=v("Just",L._4);continue}}g()}return k})(a.layer);if(y.tag==="Nothing")return 0+h|0;if(y.tag==="Just")return y._1+h|0;g()})())(p))(a.layer)(r)}))}},Tm=t=>{const e=Jm(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=mm(i)(_);if(h.tag==="Nothing"){f=!1,d=_;continue}if(h.tag==="Just"){const p=ym(t)(i)(h._1)(_);if(p.tag==="Nothing"){f=!1,d=_;continue}if(p.tag==="Just"){a=l-1|0,c=e(r)(i)(h._1)(p._1)(_);continue}}g()}return d})(n)(o)},wm=t=>{const e=Sg(t),n=Eg(t),r=Cg(t);return i=>o=>u=>e(i)(o)(n(i)(o)(r(i)(o)(u)))},Gg=t=>e=>J(n=>r=>vt(t)(te)(e(r))([r])(n))(Q),vm=t=>{const e=Kt(t)(zt);return n=>r=>i=>{const o=a=>c=>f=>d=>{let l=a,_=c,h=f,p=d,m=!0,y;for(;m;){const x=l,N=_,w=h,k=p,L=Rt(E=>T,E=>B=>v("Just",{head:E,tail:B}),w);if(L.tag==="Nothing"){m=!1,y=k;continue}if(L.tag==="Just"){const E=L._1.head,B=(S=>{let P=S,V=!0,U;for(;V;){const O=P;if(O.tag==="Leaf"){V=!1,U=T;continue}if(O.tag==="Node"){const z=t.compare(E)(O._3);if(z==="LT"){P=O._5;continue}if(z==="GT"){P=O._6;continue}if(z==="EQ"){V=!1,U=v("Just",O._4);continue}}g()}return U})(k.layer),X=(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})(),et=J(S=>P=>{const V=P.tgt,U=(z=>{let F=z,G=!0,D;for(;G;){const I=F;if(I.tag==="Leaf"){G=!1,D=T;continue}if(I.tag==="Node"){const A=t.compare(V)(I._3);if(A==="LT"){F=I._5;continue}if(A==="GT"){F=I._6;continue}if(A==="EQ"){G=!1,D=v("Just",I._4);continue}}g()}return D})(S.incident),O=(()=>{if(U.tag==="Nothing")return-1;if(U.tag==="Just")return U._1-1|0;g()})();return{st:{...S.st,layer:K(t)(P.tgt)(gm((()=>{const z=P.tgt,F=(G=>{let D=G,I=!0,A;for(;I;){const H=D;if(H.tag==="Leaf"){I=!1,A=T;continue}if(H.tag==="Node"){const $=t.compare(z)(H._3);if($==="LT"){D=H._5;continue}if($==="GT"){D=H._6;continue}if($==="EQ"){I=!1,A=v("Just",H._4);continue}}g()}return A})(S.st.layer);if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;g()})())(X+P.delta|0))(S.st.layer)},incident:K(t)(P.tgt)(O)(S.incident),queue:O===0?[...S.queue,P.tgt]:S.queue}})({st:k,incident:N,queue:L._1.tail})((()=>{const S=(P=>{let V=P,U=!0,O;for(;U;){const z=V;if(z.tag==="Leaf"){U=!1,O=T;continue}if(z.tag==="Node"){const F=t.compare(E)(z._3);if(F==="LT"){V=z._5;continue}if(F==="GT"){V=z._6;continue}if(F==="EQ"){U=!1,O=v("Just",z._4);continue}}g()}return O})(x);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})());l=x,_=et.incident,h=et.queue,p=et.st;continue}g()}return y},u=Gg(t)(a=>a.tgt)(r),s=e(M(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 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,_=v("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(Gg(t)(a=>a.src)(r))(s)(st(a=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=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,_=v("Just",h._4);continue}}g()}return _})(s);if(c.tag==="Nothing")return!0;if(c.tag==="Just")return c._1===0;g()},n))(i)}},bm=t=>{const e=dm(t),n=vm(t),r=wm(t),i=Tm(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}},Pg=t=>{const e=hm(t),n=bm(t),r=fm(t);return i=>o=>{if(i.length===0)return Q;if(i.length<40)return e(i)(n(i)(o));const u=r(i)(o);return e(i)(_m(t)(u.removed)(n(u.coreNodes)(u.coreEdges)))}},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=v("Just",o._4);continue}}g()}return i},Gs=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Lm=Pg(it),Li=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}),km=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=rt((()=>{const i=Dg(n.cGroup._1)(t);if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})());return Ve(n.id)(i=>({...i,hitbox:{...i.hitbox,x:r+i.cGroupOffset.x}}))(e)}g()},Em=t=>e=>({...e,cGraph:J(km(t))(e.cGraph)((()=>{const n=e.cGraph;return xt(r=>Ut(r)(n.cNodes))(n.cNodeOrder)})())}),Cm=t=>e=>n=>r=>i=>{const o=de(Ui(e.cGroupOffset.x-t.cGroupOffset.x));return Li({src:i.nextNodeId,tgt:r,delta:Gs(0)(-o),weight:1})(Li({src:i.nextNodeId,tgt:n,delta:Gs(0)(o),weight:1})({...i,nodes:[...i.nodes,i.nextNodeId],nextNodeId:i.nextNodeId+1|0}))},Sm=t=>e=>n=>r=>i=>o=>u=>{const s=Gs(0)(de(Ui(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)?Cm(n)(r)(i)(o)(u):Li({src:i,tgt:o,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(u)},Gm=t=>e=>n=>r=>i=>{const o=Ut(i)(e.cGraph.cNodes);if(o.tag==="Nothing")return r;if(o.tag==="Just")return(n.cGroup.tag==="Nothing"?o._1.cGroup.tag==="Nothing":n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"&&n.cGroup._1===o._1.cGroup._1)?r:n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"?Sm(t)(e)(n)(o._1)(n.cGroup._1)(o._1.cGroup._1)(r):r;g()},Pm=t=>e=>n=>r=>J(Gm(t)(e)(r))(n)(r.constraints),Dm=t=>e=>Li({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),Im=t=>{const e=J(i=>o=>vt(it)(oe)(o.tgt)(1)(i))(Q)(t.edges),n=st(i=>{const o=Dg(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=>Li({src:r,tgt:o,delta:1,weight:0})(i))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},Qm=t=>e=>{const n=Im(J(Dm)(J(Pm(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return xt(i=>Ut(i)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},Am=t=>e=>{const n=Qm(t)(e);return Em(Lm(n.nodes)(n.edges))(e)},Ig=t=>t,ee=Ig("H"),ne=Ig("V"),Rm=t=>b(t._2,t._1),Qg=t=>({...t,position:b(t.position._2,t.position._1),size:b(t.size._2,t.size._1)}),Fm=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:M(Fm)(t.segments),bends:M(Rm)(t.bends)}),Bm=t=>({nodes:M(Qg)(t.nodes),edges:t.edges,paths:M(Ag)(t.paths),ports:t.ports}),zm=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}}),Wm=t=>e=>Am(e),Om=t=>e=>{const n=Bm(e),r=cm(n),i=im(r)(bg(n)),o=om(fg(Ns)(Ep({...Sp(r.cGraph),compactionAlgorithm:v("Just",Wm()(i)),constraintAlgorithm:v("Just",Op),spacingsHandler:zm(i)})).cGraph)({nodes:n.nodes,edges:n.edges,paths:n.paths});return{nodes:M(Qg)(o.nodes),edges:M(Ag)(o.edges)}},Rg=t=>t,Rr=Kt(it)(zt),Dt=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=v("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=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},lt=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Fr=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=v("Just",o._4);continue}}g()}return i},Mm=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?ye:n==="GT"?xe:it.compare(t._2)(e._2)},Br=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},qm=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Hm=t=>t,Bg=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=v("Just",o._4);continue}}g()}return i},$m=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=v("Just",o._4);continue}}g()}return i},Do=Rg("Regular"),Io=Rg("Critical"),zg=t=>e=>{const n=J(u=>s=>K(C)(s.node)(s)(u))(Q)(e),r=1.25*rt(4),i=(u,s,a)=>(c=>f=>d=>{let l=c,_=f,h=d,p=!0,m;for(;p;){const y=l,x=_,N=h;if(N.critical){p=!1,m=N;continue}const w=Rt(L=>T,L=>E=>v("Just",{head:L,tail:E}),y),k=Rt(L=>T,L=>E=>v("Just",{head:L,tail:E}),x);if(w.tag==="Just"&&k.tag==="Just"){const L=w._1.head>k._1.head-u&&w._1.head<k._1.head+u?{...N,critical:!0}:w._1.head>k._1.head-r&&w._1.head<k._1.head+r?{...N,conflicts:N.conflicts+1|0}:N;if(L.critical){p=!1,m=L;continue}if(w._1.head<=k._1.head){l=w._1.tail,_=x,h=L;continue}l=y,_=k._1.tail,h=L;continue}p=!1,m=N}return m})(s)(a)({conflicts:0,critical:!1}),o=(u,s,a)=>{if(lt(J(lt)(-1e18)(s.incoming))(J(lt)(-1e18)(s.outgoing))-dt(J(dt)(1e18)(s.incoming))(J(dt)(1e18)(s.outgoing))<.001||lt(J(lt)(-1e18)(a.incoming))(J(lt)(-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:Io}]:[],...f.critical?[{src:s.id,tgt:a.id,weight:1,kind:Io}]:[]];const d=dt(J(dt)(1e18)(s.incoming))(J(dt)(1e18)(s.outgoing)),l=lt(J(lt)(-1e18)(s.incoming))(J(lt)(-1e18)(s.outgoing)),_=dt(J(dt)(1e18)(a.incoming))(J(dt)(1e18)(a.outgoing)),h=lt(J(lt)(-1e18)(a.incoming))(J(lt)(-1e18)(a.outgoing)),p=(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,m=(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 p<m?[{src:s.id,tgt:a.id,weight:m-p|0,kind:Do}]:p>m?[{src:a.id,tgt:s.id,weight:p-m|0,kind:Do}]:p>0?[{src:s.id,tgt:a.id,weight:0,kind:Do},{src:a.id,tgt:s.id,weight:0,kind:Do}]:[]};return J(u=>s=>J(a=>c=>K(C)(c._1)(c._2)(a))(u)((()=>{const a=J(S=>P=>{const V=P.edge.from.node+"|"+(()=>{if(P.edge.from.port.tag==="Just")return P.edge.from.port._1;if(P.edge.from.port.tag==="Nothing")return"_auto_"+P.edge.id;g()})(),U=Bg(V)(S.entries);if(U.tag==="Nothing")return{...S,entries:K(C)(V)({id:0,members:[P.edge.id],incoming:[P.fromPos._1],outgoing:[P.toPos._1],slot:0,mark:0,splitBy:T,splitPartner:T})(S.entries),order:[...S.order,V]};if(U.tag==="Just")return{...S,entries:K(C)(V)({...U._1,members:[...U._1.members,P.edge.id],incoming:[...sr(O=>O<P.fromPos._1)(U._1.incoming).init,P.fromPos._1,...sr(O=>O<=P.fromPos._1)(U._1.incoming).rest],outgoing:[...sr(O=>O<P.toPos._1)(U._1.outgoing).init,P.toPos._1,...sr(O=>O<=P.toPos._1)(U._1.outgoing).rest]})(S.entries)};g()})({entries:Q,order:[]})(s._2),c=At(S=>P=>({...P,id:S}))(xt(S=>Bg(S)(a.entries))(a.order));if(c.length===0)return[];const f=J(S=>P=>S.prev.tag==="Just"&&P-S.prev._1<1e-9?S:{prev:v("Just",P),out:[...S.out,P]})({prev:T,out:[]})(kt(ut.compare)([...Tt(c)(S=>S.incoming),...Tt(c)(S=>S.outgoing)])).out,d=f.length<2?.2*r:.2*J(S=>P=>{if(S.prev.tag==="Nothing")return{prev:v("Just",P),mn:S.mn};if(S.prev.tag==="Just")return{prev:v("Just",P),mn:dt(S.mn)(P-S.prev._1)};g()})({prev:T,mn:1e18})(f).mn,l={segments:c,deps:(()=>{const S=c.length;return Tt(Tt(It(0,S-2|0))(P=>Tt(It(P+1|0,S-1|0))(V=>[b(P,V)])))(P=>P._1>=0&&P._1<c.length?P._2>=0&&P._2<c.length?o(d,c[P._1],c[P._2]):[]:[])})()},_=st(S=>{if(S.kind==="Critical")return!0;if(S.kind==="Regular")return!1;g()},l.deps),h=(()=>{if(_.length<2)return l;const S=Rr((()=>{const z=l.segments;return M(F=>b(F.id,F.mark))((()=>{const F=z.length,G=I=>{let A=I,H=!0,$;for(;H;){const Y=A,q=Vt(W=>{const tt=Dt(W)(Y.inWeight);if(tt.tag==="Nothing")return!0;if(tt.tag==="Just")return tt._1===0;g()})(Y.remaining);if(q.tag==="Nothing"){H=!1,$=Y;continue}if(q.tag==="Just"){const W=q._1;A={...Y,inWeight:J(tt=>j=>vt(it)(oe)(j.tgt)(-j.weight)(tt))(Y.inWeight)((()=>{const tt=Dt(W)(Y.depsBySrc);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),marks:K(it)(W)(Y.nextSource)(Y.marks),nextSource:Y.nextSource+1|0,outWeight:J(tt=>j=>vt(it)(oe)(j.src)(-j.weight)(tt))(Y.outWeight)((()=>{const tt=Dt(W)(Y.depsByTgt);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),remaining:st(tt=>tt!==W,Y.remaining)};continue}g()}return $},D=I=>{let A=I,H=!0,$;for(;H;){const Y=A,q=Vt(W=>{const tt=Dt(W)(Y.outWeight);if(tt.tag==="Nothing")return!0;if(tt.tag==="Just")return tt._1===0;g()})(Y.remaining);if(q.tag==="Nothing"){H=!1,$=Y;continue}if(q.tag==="Just"){const W=q._1;A={...Y,inWeight:J(tt=>j=>vt(it)(oe)(j.tgt)(-j.weight)(tt))(Y.inWeight)((()=>{const tt=Dt(W)(Y.depsBySrc);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),marks:K(it)(W)(Y.nextSink)(Y.marks),nextSink:Y.nextSink-1|0,outWeight:J(tt=>j=>vt(it)(oe)(j.src)(-j.weight)(tt))(Y.outWeight)((()=>{const tt=Dt(W)(Y.depsByTgt);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),remaining:st(tt=>tt!==W,Y.remaining)};continue}g()}return $};return(I=>{let A=I,H=!0,$;for(;H;){const Y=G(D(A));if(Y.remaining.length===0){H=!1,$=M(q=>{const W=Dt(q.id)(Y.marks),tt=(()=>{if(W.tag==="Nothing")return q.id;if(W.tag==="Just")return W._1;g()})();return{...q,mark:tt<F?(tt+F|0)+1|0:tt}})(z);continue}A=(()=>{const q=tt=>{const j=Dt(tt)(Y.outWeight),gt=Dt(tt)(Y.inWeight);return(()=>{if(j.tag==="Nothing")return 0;if(j.tag==="Just")return j._1;g()})()-(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()|0},W=kt(tt=>j=>it.compare(q(j))(q(tt)))(Y.remaining);if(0<W.length){const tt=W[0];return{...Y,inWeight:J(j=>gt=>vt(it)(oe)(gt.tgt)(-gt.weight)(j))(Y.inWeight)((()=>{const j=Dt(tt)(Y.depsBySrc);if(j.tag==="Nothing")return[];if(j.tag==="Just")return j._1;g()})()),marks:K(it)(tt)(Y.nextSource)(Y.marks),nextSource:Y.nextSource+1|0,outWeight:J(j=>gt=>vt(it)(oe)(gt.src)(-gt.weight)(j))(Y.outWeight)((()=>{const j=Dt(tt)(Y.depsByTgt);if(j.tag==="Nothing")return[];if(j.tag==="Just")return j._1;g()})()),remaining:st(j=>j!==tt,Y.remaining)}}return Y})()}return $})({remaining:M(I=>I.id)(z),marks:Q,inWeight:J(I=>A=>vt(it)(oe)(A.tgt)(A.weight)(I))(Q)(_),outWeight:J(I=>A=>vt(it)(oe)(A.src)(A.weight)(I))(Q)(_),depsBySrc:J(I=>A=>vt(it)(te)(A.src)([A])(I))(Q)(_),depsByTgt:J(I=>A=>vt(it)(te)(A.tgt)([A])(I))(Q)(_),nextSink:F-1|0,nextSource:F+1|0})})())})()),P=st(z=>{const F=Dt(z.src)(S),G=Dt(z.tgt)(S);return(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;g()})()>(()=>{if(G.tag==="Nothing")return 0;if(G.tag==="Just")return G._1;g()})()},_);if(P.length===0)return l;const V=J(z=>F=>{if(ze(Jr)(F.src)(z.decisions)||ze(Jr)(F.tgt)(z.decisions))return z;const G=Dt(F.src)(z.segMap),D=Dt(F.tgt)(z.segMap);if(G.tag==="Just"&&D.tag==="Just"){const I=(G._1.incoming.length+G._1.outgoing.length|0)>2&&(D._1.incoming.length+D._1.outgoing.length|0)<=2,A=I?D._1:G._1;return{decisions:[...z.decisions,A.id],segMap:K(it)(A.id)({...A,splitBy:v("Just",I?G._1.id:D._1.id)})(z.segMap)}}return z})({decisions:[],segMap:Rr(M(z=>b(z.id,z))(l.segments))})(P),U=V.segMap,O=J(z=>F=>{const G=dt(J(dt)(1e18)(F.incoming))(J(dt)(1e18)(F.outgoing)),D=lt(J(lt)(-1e18)(F.incoming))(J(lt)(-1e18)(F.outgoing)),I=st(q=>q.a.startPosition<=D&&q.a.endPosition>=G,At(q=>W=>({i:q,a:W}))(z.freeAreas));if(I.length===0){const q={...F,incoming:kt(ut.compare)(F.incoming),outgoing:kt(ut.compare)([(G+D)/2]),splitPartner:v("Just",z.nextId)},W={id:z.nextId,incoming:kt(ut.compare)([(G+D)/2]),mark:0,members:F.members,outgoing:kt(ut.compare)(F.outgoing),slot:0,splitBy:T,splitPartner:v("Just",F.id)};return{segMap:K(it)(W.id)(W)(K(it)(q.id)(q)(z.segMap)),freeAreas:z.freeAreas,nextId:z.nextId+1|0}}const A=0<I.length?v("Just",I[0]):T,H=(()=>{if(A.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(A.tag==="Just"){if(I.length===1)return A._1;const q=M(W=>({c:W,rating:(()=>{const tt=(W.a.startPosition+W.a.endPosition)/2,j=[tt],gt=[tt],_t=J((()=>{const yt=z.segMap;return St=>Ft=>{const pt=Dt(Ft.tgt)(yt);if(pt.tag==="Nothing")return St;if(pt.tag==="Just"){const Bt=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),Jt=lt(J(lt)(-1e18)(pt._1.incoming))(J(lt)(-1e18)(pt._1.outgoing)),mt=dt(J(dt)(1e18)(F.incoming))(J(dt)(1e18)(j)),ct=(()=>{const Et=lt(J(lt)(-1e18)(F.incoming))(J(lt)(-1e18)(j)),Qt=J(Yt=>_e=>_e>Jt?Yt:_e>=Bt?Yt+1|0:Yt)(0)(j)+J(Yt=>_e=>_e>Et?Yt:_e>=mt?Yt+1|0:Yt)(0)(pt._1.incoming)|0,Ze=dt(J(dt)(1e18)(F.incoming))(J(dt)(1e18)(j)),qe=lt(J(lt)(-1e18)(F.incoming))(J(lt)(-1e18)(j)),Ke=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),qn=lt(J(lt)(-1e18)(pt._1.incoming))(J(lt)(-1e18)(pt._1.outgoing)),dn=J(Yt=>_e=>_e>qe?Yt:_e>=Ze?Yt+1|0:Yt)(0)(pt._1.outgoing)+J(Yt=>_e=>_e>qn?Yt:_e>=Ke?Yt+1|0:Yt)(0)(F.incoming)|0;return Qt===dn?Qt>0?{...St,deps:St.deps+2|0,crossings:St.crossings+Qt|0}:St:{...St,deps:St.deps+1|0,crossings:St.crossings+Br(Qt)(dn)|0}})(),Z=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),nt=lt(J(lt)(-1e18)(pt._1.incoming))(J(lt)(-1e18)(pt._1.outgoing)),ht=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(F.outgoing)),ft=lt(J(lt)(-1e18)(gt))(J(lt)(-1e18)(F.outgoing)),Nt=J(Et=>Qt=>Qt>nt?Et:Qt>=Z?Et+1|0:Et)(0)(F.outgoing)+J(Et=>Qt=>Qt>ft?Et:Qt>=ht?Et+1|0:Et)(0)(pt._1.incoming)|0,wt=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(F.outgoing)),Zt=lt(J(lt)(-1e18)(gt))(J(lt)(-1e18)(F.outgoing)),Se=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),sn=lt(J(lt)(-1e18)(pt._1.incoming))(J(lt)(-1e18)(pt._1.outgoing)),Re=J(Et=>Qt=>Qt>Zt?Et:Qt>=wt?Et+1|0:Et)(0)(pt._1.outgoing)+J(Et=>Qt=>Qt>sn?Et:Qt>=Se?Et+1|0:Et)(0)(gt)|0;return Nt===Re?Nt>0?{...ct,deps:ct.deps+2|0,crossings:ct.crossings+Nt|0}:ct:{...ct,deps:ct.deps+1|0,crossings:ct.crossings+Br(Nt)(Re)|0}}g()}})())(J((()=>{const yt=z.segMap;return St=>Ft=>{const pt=Dt(Ft.src)(yt);if(pt.tag==="Nothing")return St;if(pt.tag==="Just"){const Bt=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),Jt=lt(J(lt)(-1e18)(pt._1.incoming))(J(lt)(-1e18)(pt._1.outgoing)),mt=dt(J(dt)(1e18)(F.incoming))(J(dt)(1e18)(j)),ct=(()=>{const Et=lt(J(lt)(-1e18)(F.incoming))(J(lt)(-1e18)(j)),Qt=J(Yt=>_e=>_e>Jt?Yt:_e>=Bt?Yt+1|0:Yt)(0)(j)+J(Yt=>_e=>_e>Et?Yt:_e>=mt?Yt+1|0:Yt)(0)(pt._1.incoming)|0,Ze=dt(J(dt)(1e18)(F.incoming))(J(dt)(1e18)(j)),qe=lt(J(lt)(-1e18)(F.incoming))(J(lt)(-1e18)(j)),Ke=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),qn=lt(J(lt)(-1e18)(pt._1.incoming))(J(lt)(-1e18)(pt._1.outgoing)),dn=J(Yt=>_e=>_e>qe?Yt:_e>=Ze?Yt+1|0:Yt)(0)(pt._1.outgoing)+J(Yt=>_e=>_e>qn?Yt:_e>=Ke?Yt+1|0:Yt)(0)(F.incoming)|0;return Qt===dn?Qt>0?{...St,deps:St.deps+2|0,crossings:St.crossings+Qt|0}:St:{...St,deps:St.deps+1|0,crossings:St.crossings+Br(Qt)(dn)|0}})(),Z=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),nt=lt(J(lt)(-1e18)(pt._1.incoming))(J(lt)(-1e18)(pt._1.outgoing)),ht=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(F.outgoing)),ft=lt(J(lt)(-1e18)(gt))(J(lt)(-1e18)(F.outgoing)),Nt=J(Et=>Qt=>Qt>nt?Et:Qt>=Z?Et+1|0:Et)(0)(F.outgoing)+J(Et=>Qt=>Qt>ft?Et:Qt>=ht?Et+1|0:Et)(0)(pt._1.incoming)|0,wt=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(F.outgoing)),Zt=lt(J(lt)(-1e18)(gt))(J(lt)(-1e18)(F.outgoing)),Se=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),sn=lt(J(lt)(-1e18)(pt._1.incoming))(J(lt)(-1e18)(pt._1.outgoing)),Re=J(Et=>Qt=>Qt>Zt?Et:Qt>=wt?Et+1|0:Et)(0)(pt._1.outgoing)+J(Et=>Qt=>Qt>sn?Et:Qt>=Se?Et+1|0:Et)(0)(gt)|0;return Nt===Re?Nt>0?{...ct,deps:ct.deps+2|0,crossings:ct.crossings+Nt|0}:ct:{...ct,deps:ct.deps+1|0,crossings:ct.crossings+Br(Nt)(Re)|0}}g()}})())({crossings:0,deps:0})(st(yt=>yt.tgt===F.id,l.deps)))(st(yt=>yt.src===F.id,l.deps)),at=(()=>{if(F.splitBy.tag==="Just")return Dt(F.splitBy._1)(z.segMap);if(F.splitBy.tag==="Nothing")return T;g()})();if(at.tag==="Just")return{..._t,deps:_t.deps+2|0,crossings:(()=>{const yt=dt(J(dt)(1e18)(at._1.incoming))(J(dt)(1e18)(at._1.outgoing)),St=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(F.outgoing)),Ft=lt(J(lt)(-1e18)(at._1.incoming))(J(lt)(-1e18)(at._1.outgoing)),pt=lt(J(lt)(-1e18)(gt))(J(lt)(-1e18)(F.outgoing)),Bt=dt(J(dt)(1e18)(F.incoming))(J(dt)(1e18)(j));return _t.crossings+(()=>{const Jt=dt(J(dt)(1e18)(at._1.incoming))(J(dt)(1e18)(at._1.outgoing)),mt=lt(J(lt)(-1e18)(F.incoming))(J(lt)(-1e18)(j)),ct=lt(J(lt)(-1e18)(at._1.incoming))(J(lt)(-1e18)(at._1.outgoing));return((J(Z=>nt=>nt>Ft?Z:nt>=yt?Z+1|0:Z)(0)(j)+J(Z=>nt=>nt>mt?Z:nt>=Bt?Z+1|0:Z)(0)(at._1.incoming)|0)+J(Z=>nt=>nt>pt?Z:nt>=St?Z+1|0:Z)(0)(at._1.outgoing)|0)+J(Z=>nt=>nt>ct?Z:nt>=Jt?Z+1|0:Z)(0)(gt)|0})()|0})()};if(at.tag==="Nothing")return _t;g()})()}))(I);return J(W=>tt=>tt.rating.crossings<W.rating.crossings||!(tt.rating.crossings>W.rating.crossings)&&(tt.rating.deps<W.rating.deps||!(tt.rating.deps>W.rating.deps)&&tt.c.a.size>W.c.a.size)?tt:W)(0<q.length?q[0]:{c:A._1,rating:{crossings:1e6,deps:1e6}})(q).c}g()})(),$={...F,incoming:kt(ut.compare)(F.incoming),outgoing:kt(ut.compare)([(H.a.startPosition+H.a.endPosition)/2]),splitPartner:v("Just",z.nextId)},Y={id:z.nextId,incoming:kt(ut.compare)([(H.a.startPosition+H.a.endPosition)/2]),mark:0,members:F.members,outgoing:kt(ut.compare)(F.outgoing),slot:0,splitBy:T,splitPartner:v("Just",F.id)};return{segMap:K(it)(Y.id)(Y)(K(it)($.id)($)(z.segMap)),freeAreas:(()=>{if(H.i>=0&&H.i<z.freeAreas.length){const q=Oa(Xt,T,H.i,z.freeAreas),W=(()=>{if(q.tag==="Nothing")return z.freeAreas;if(q.tag==="Just")return q._1;g()})();if(z.freeAreas[H.i].size/2<d)return W;const tt=(z.freeAreas[H.i].startPosition+z.freeAreas[H.i].endPosition)/2,j=tt-d,gt=tt+d;return[...H.i<1?[]:bt(0,H.i,W),...z.freeAreas[H.i].startPosition<=j?[{startPosition:z.freeAreas[H.i].startPosition,endPosition:j,size:j-z.freeAreas[H.i].startPosition}]:[],...gt<=z.freeAreas[H.i].endPosition?[{startPosition:gt,endPosition:z.freeAreas[H.i].endPosition,size:z.freeAreas[H.i].endPosition-gt}]:[],...H.i<1?W:bt(H.i,W.length,W)]}return z.freeAreas})(),nextId:z.nextId+1|0}})({segMap:U,freeAreas:(()=>{const z=kt(ut.compare)([...Tt(l.segments)(F=>F.incoming),...Tt(l.segments)(F=>F.outgoing)]);return xt(Hm)(Je(F=>G=>G-F>=2*d?v("Just",{startPosition:F+d,endPosition:G-d,size:G-F-2*d}):T,z,bt(1,z.length,z)))})(),nextId:l.segments.length})(kt(z=>F=>ut.compare(lt(J(lt)(-1e18)(z.incoming))(J(lt)(-1e18)(z.outgoing))-dt(J(dt)(1e18)(z.incoming))(J(dt)(1e18)(z.outgoing)))(lt(J(lt)(-1e18)(F.incoming))(J(lt)(-1e18)(F.outgoing))-dt(J(dt)(1e18)(F.incoming))(J(dt)(1e18)(F.outgoing))))(xt(z=>Dt(z)(U))(V.decisions)));return{segments:(()=>{const z=(F,G)=>{if(F.tag==="Leaf")return G;if(F.tag==="Node")return z(F._5,qt("Cons",F._4,z(F._6,G)));g()};return Ct($t.foldr,z(O.segMap,Ht))})(),deps:(()=>{const z=O.segMap,F=(I,A)=>{if(I.tag==="Leaf")return A;if(I.tag==="Node")return F(I._5,qt("Cons",I._4,F(I._6,A)));g()},G=Ct($t.foldr,F(z,Ht)),D=G.length;return[...Tt(Tt(It(0,D-2|0))(I=>Tt(It(I+1|0,D-1|0))(A=>[b(I,A)])))(I=>I._1>=0&&I._1<G.length?I._2>=0&&I._2<G.length?G[I._1].splitPartner.tag!=="Nothing"&&G[I._1].splitPartner.tag==="Just"&&G[I._1].splitPartner._1===G[I._2].id||G[I._2].splitPartner.tag!=="Nothing"&&G[I._2].splitPartner.tag==="Just"&&G[I._2].splitPartner._1===G[I._1].id?[]:o(d,G[I._1],G[I._2]):[]:[]),...Tt(G)(I=>I.splitBy.tag==="Just"&&I.splitPartner.tag==="Just"&&(()=>{const A=Dt(I.splitPartner._1)(z);if(A.tag==="Nothing")return!1;if(A.tag==="Just")return!0;g()})()&&(()=>{const A=Dt(I.splitBy._1)(z);if(A.tag==="Nothing")return!1;if(A.tag==="Just")return!0;g()})()?[{src:I.id,tgt:I.splitBy._1,weight:1,kind:Io},{src:I.splitBy._1,tgt:I.splitPartner._1,weight:1,kind:Io}]:[])]})()}})(),p=h.segments,m=p.length,y=S=>{let P=S,V=!0,U;for(;V;){const O=P,z=Vt(F=>{const G=Dt(F)(O.inWeight);if(G.tag==="Nothing")return!0;if(G.tag==="Just")return G._1===0;g()})(O.remaining);if(z.tag==="Nothing"){V=!1,U=O;continue}if(z.tag==="Just"){const F=z._1;P={...O,inWeight:J(G=>D=>vt(it)(oe)(D.tgt)(-D.weight)(G))(O.inWeight)((()=>{const G=Dt(F)(O.depsBySrc);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()),marks:K(it)(F)(O.nextSource)(O.marks),nextSource:O.nextSource+1|0,outWeight:J(G=>D=>vt(it)(oe)(D.src)(-D.weight)(G))(O.outWeight)((()=>{const G=Dt(F)(O.depsByTgt);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()),remaining:st(G=>G!==F,O.remaining)};continue}g()}return U},x=S=>{let P=S,V=!0,U;for(;V;){const O=P,z=Vt(F=>{const G=Dt(F)(O.outWeight);if(G.tag==="Nothing")return!0;if(G.tag==="Just")return G._1===0;g()})(O.remaining);if(z.tag==="Nothing"){V=!1,U=O;continue}if(z.tag==="Just"){const F=z._1;P={...O,inWeight:J(G=>D=>vt(it)(oe)(D.tgt)(-D.weight)(G))(O.inWeight)((()=>{const G=Dt(F)(O.depsBySrc);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()),marks:K(it)(F)(O.nextSink)(O.marks),nextSink:O.nextSink-1|0,outWeight:J(G=>D=>vt(it)(oe)(D.src)(-D.weight)(G))(O.outWeight)((()=>{const G=Dt(F)(O.depsByTgt);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()),remaining:st(G=>G!==F,O.remaining)};continue}g()}return U},N=(S=>{let P=S,V=!0,U;for(;V;){const O=y(x(P));if(O.remaining.length===0){V=!1,U=M(z=>{const F=Dt(z.id)(O.marks),G=(()=>{if(F.tag==="Nothing")return z.id;if(F.tag==="Just")return F._1;g()})();return{...z,mark:G<m?(G+m|0)+1|0:G}})(p);continue}P=(()=>{const z=G=>{const D=Dt(G)(O.outWeight),I=Dt(G)(O.inWeight);return(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;g()})()-(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;g()})()|0},F=kt(G=>D=>it.compare(z(D))(z(G)))(O.remaining);if(0<F.length){const G=F[0];return{...O,inWeight:J(D=>I=>vt(it)(oe)(I.tgt)(-I.weight)(D))(O.inWeight)((()=>{const D=Dt(G)(O.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),marks:K(it)(G)(O.nextSource)(O.marks),nextSource:O.nextSource+1|0,outWeight:J(D=>I=>vt(it)(oe)(I.src)(-I.weight)(D))(O.outWeight)((()=>{const D=Dt(G)(O.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),remaining:st(D=>D!==G,O.remaining)}}return O})()}return U})({remaining:M(S=>S.id)(p),marks:Q,inWeight:J(S=>P=>vt(it)(oe)(P.tgt)(P.weight)(S))(Q)(h.deps),outWeight:J(S=>P=>vt(it)(oe)(P.src)(P.weight)(S))(Q)(h.deps),depsBySrc:J(S=>P=>vt(it)(te)(P.src)([P])(S))(Q)(h.deps),depsByTgt:J(S=>P=>vt(it)(te)(P.tgt)([P])(S))(Q)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),w=(()=>{const S=(()=>{const U=Rr(M(O=>b(O.id,O.mark))(N));return{segments:N,deps:xt(O=>(()=>{if(O.kind==="Critical")return!0;if(O.kind==="Regular")return!1;g()})()?v("Just",O):(()=>{const z=Dt(O.src)(U),F=Dt(O.tgt)(U);return(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})()>(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;g()})()})()?O.weight===0?T:v("Just",{src:O.tgt,tgt:O.src,weight:O.weight,kind:O.kind}):v("Just",O))(h.deps)}})(),P=J(U=>O=>vt(it)(oe)(O.tgt)(1)(U))(Q)(S.deps),V=(U=>{let O=U,z=!0,F;for(;z;){const G=O,D=Rt(I=>T,I=>A=>v("Just",{head:I,tail:A}),G.queue);if(D.tag==="Nothing"){z=!1,F=G;continue}if(D.tag==="Just"){O=J((()=>{const I=Dt(D._1.head)(G.slots),A=(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;g()})();return H=>$=>{const Y=Dt($)(H.inDegree),q=(()=>{if(Y.tag==="Nothing")return-1;if(Y.tag==="Just")return Y._1-1|0;g()})();return{...H,slots:K(it)($)(Fg((()=>{const W=Dt($)(H.slots);if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})())(A+1|0))(H.slots),inDegree:K(it)($)(q)(H.inDegree),queue:q===0?[...H.queue,$]:H.queue}}})())({...G,queue:D._1.tail})((()=>{const I=Dt(D._1.head)(G.adj);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})());continue}g()}return F})({slots:Rr(M(U=>b(U.id,0))(S.segments)),inDegree:P,adj:J(U=>O=>vt(it)(te)(O.src)([O.tgt])(U))(Q)(S.deps),queue:M(U=>U.id)(st(U=>{const O=Dt(U.id)(P);if(O.tag==="Nothing")return!0;if(O.tag==="Just")return O._1===0;g()},S.segments))});return kt(U=>O=>it.compare(U.slot)(O.slot))(M(U=>({...U,slot:(()=>{const O=Dt(U.id)(V.slots);if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;g()})()}))(S.segments))})(),k=1+J(S=>P=>Fg(S)(P.slot))(0)(w)|0,L=Tt(w)(S=>S.members),E=st(S=>ze(fn)(S.edge.id)(L),t),B=J(lt)(-1e18)(M(S=>S.fromPos._2)(E)),X=J(dt)(1e18)(M(S=>S.toPos._2)(E));if(B>X){const S=Rr(M(P=>b(P.id,P))(w));return Fe(M(P=>M(V=>b(V,{slot:P.slot,slotCount:k,gapTop:X,gapBottom:B,partner:(()=>{if(P.splitPartner.tag==="Just"){const U=Dt(P.splitPartner._1)(S);if(U.tag==="Just")return v("Just",{slot:U._1.slot,splitX:0<U._1.incoming.length?U._1.incoming[0]:0});if(U.tag==="Nothing")return T;g()}if(P.splitPartner.tag==="Nothing")return T;g()})()}))(P.members))(st(P=>{if(P.splitPartner.tag==="Just"){const V=Dt(P.splitPartner._1)(S);return!(V.tag==="Just"&&(()=>{if(V._1.splitBy.tag==="Nothing")return!1;if(V._1.splitBy.tag==="Just")return!0;g()})())}if(P.splitPartner.tag==="Nothing")return!0;g()},w)))}const et=Rr(M(S=>b(S.id,S))(w));return Fe(M(S=>M(P=>b(P,{slot:S.slot,slotCount:k,gapTop:B,gapBottom:X,partner:(()=>{if(S.splitPartner.tag==="Just"){const V=Dt(S.splitPartner._1)(et);if(V.tag==="Just")return v("Just",{slot:V._1.slot,splitX:0<V._1.incoming.length?V._1.incoming[0]:0});if(V.tag==="Nothing")return T;g()}if(S.splitPartner.tag==="Nothing")return T;g()})()}))(S.members))(st(S=>{if(S.splitPartner.tag==="Just"){const P=Dt(S.splitPartner._1)(et);return!(P.tag==="Just"&&(()=>{if(P._1.splitBy.tag==="Nothing")return!1;if(P._1.splitBy.tag==="Just")return!0;g()})())}if(S.splitPartner.tag==="Nothing")return!0;g()},w)))})()))(Q)(qm(J(u=>s=>{const a=Fr(s.edge.from.node)(n);if(a.tag==="Just"){const c=Fr(s.edge.to.node)(n);return c.tag==="Just"&&a._1.layer!==c._1.layer?vt(it)(te)(Br(a._1.layer)(c._1.layer))([s])(u):u}return u})(Q)((()=>{const u=s=>b((()=>{const a=Fr(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=Fr(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return kt(s=>a=>Mm(u(s))(u(a)))(t)})())))},Xm=t=>e=>{const n=zg(t)(e),r=J(i=>o=>K(C)(o.node)(o)(i))(Q)(e);return J(i=>o=>{const u=Fr(o.edge.from.node)(r);if(u.tag==="Just"){const s=Fr(o.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=$m(o.edge.id)(n);if(a.tag==="Just")return K(it)(Br(u._1.layer)(s._1.layer))(a._1.slotCount)(i)}return i}return i})(Q)(t)},Wg=zt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),ce=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ge=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ki=t=>e=>n=>r=>Wg(i=>n>=i.x&&n<i.x+i.w&&e>i.y&&t<i.y+i.h)(r),Qo=t=>e=>n=>r=>ki(ce(e)(n))(ge(e)(n))(r)(t),Ao=rt(4),Ym=Ha(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()}),Ei=qa(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})())}),Vm=t=>e=>n=>{const r=Rt(i=>T,i=>o=>v("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=ni(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()},Ci=t=>{const e=r=>i=>{const o=Rt(u=>T,u=>s=>v("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=Rt(r=>T,r=>i=>v("Just",{head:r,tail:i}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);g()},Si=t=>e=>n=>r=>Wg(i=>n>=i.y&&n<i.y+i.h&&e>i.x&&t<i.x+i.w)(r),Gi=t=>e=>n=>r=>Si(ce(e)(n))(ge(e)(n))(r)(t),Um=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?v("Just",e[n]):T;if(c.tag==="Just"){const f=n+1|0,d=f>=0&&f<e.length?v("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")&&!Qo(t)(ce(c._1.start._2)(d._1.end._2))(ge(c._1.start._2)(d._1.end._2))(c._1.start._1)?v("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")&&!Gi(t)(ce(c._1.start._1)(d._1.end._1))(ge(c._1.start._1)(d._1.end._1))(c._1.start._2)?v("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()},jm=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=Um(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)},Zm=t=>e=>n=>r=>{const i=(l,_,h)=>!Qo(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)=>!Gi(t)(ce(_)(h))(ge(_)(h))(l),d=n>=0&&n<e.length?v("Just",e[n]):T;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<e.length?v("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)?v("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)?v("Just",[...s,{start:d._1.start,end:_._1.end,direction:ee},...u]):T,p=(!c||d._1.direction==="V")&&(!a||_._1.direction==="H")&&i(d._1.start._1,d._1.start._2,_._1.end._2)&&f(_._1.end._2,d._1.start._1,_._1.end._1)?v("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,m=(!c||d._1.direction==="H")&&(!a||_._1.direction==="V")&&f(d._1.start._2,d._1.start._1,_._1.end._1)&&i(_._1.end._1,d._1.start._2,_._1.end._2)?v("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=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?y:h}if(_.tag==="Nothing")return T;g()}if(d.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+2|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=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r,s=Ci(Ei(jm(t)(Km(t)(u))));if(s.length<u.length){r=s;continue}i=!1,o=s}return o};return n=>e(Ci(Ei(n)))},e2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=kt(c=>f=>ut.compare(c.x)(f.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=kt(a=>c=>ut.compare(c.x)(a.x))(M(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},n2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=kt(c=>f=>ut.compare(c.y)(f.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=kt(a=>c=>ut.compare(c.y)(a.y))(M(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},r2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=kt(c=>f=>ut.compare(f.x)(c.x))(M(c=>({...c,x:c.x+c.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=kt(a=>c=>ut.compare(a.x)(c.x))(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=st(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=kt(c=>f=>ut.compare(f.y)(c.y))(M(c=>({...c,y:c.y+c.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=kt(a=>c=>ut.compare(a.y)(c.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},Og=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(!ki(o)(u)(r)(t))return r;if(!ki(o)(u)(i)(t))return i;const s=(r+i)/2;return ki(o)(u)(s)(t)?Og(a=>ki(o)(u)(a)(t))(s)(1):s},o2=t=>e=>n=>r=>i=>{const o=ce(e)(n),u=ge(e)(n);if(!Si(o)(u)(r)(t))return r;if(!Si(o)(u)(i)(t))return i;const s=(r+i)/2;return Si(o)(u)(s)(t)?Og(a=>Si(o)(u)(a)(t))(s)(1):s},u2=t=>e=>n=>r=>{const i=ce(e)(n),o=ge(e)(n),u=st(c=>r>=c.x&&r<c.x+c.w&&c.y+c.h>i&&c.y<o,t),s=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},s2=t=>e=>n=>r=>{const i=ce(e)(n),o=ge(e)(n),u=st(c=>r>=c.y&&r<c.y+c.h&&c.x+c.w>i&&c.x<o,t),s=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},a2=t=>e=>n=>r=>i=>o=>u=>{const s=(()=>{if(r==="South")return b(i._1,i._2+4);if(r==="North")return b(i._1,i._2-4);if(r==="East")return b(i._1+4,i._2);if(r==="West")return b(i._1-4,i._2);g()})(),a=(()=>{if(o==="South")return b(u._1,u._2+4);if(o==="North")return b(u._1,u._2-4);if(o==="East")return b(u._1+4,u._2);if(o==="West")return b(u._1-4,u._2);g()})(),c=(k,L,E)=>!Qo(e)(ce(L)(E))(ge(L)(E))(k),f=(k,L,E)=>!Qo(n)(ce(L)(E))(ge(L)(E))(k),d=(k,L,E,B)=>t.tag==="Just"&&!Gi(n)(ce(k)(L))(ge(k)(L))(t._1)?t._1:o2(e)(k)(L)(E)(B),l=(k,L,E,B)=>{if(k===E){const et=u2(e)(L)(B)(k),S=n2(e)(k)(L)(B),P=i2(e)(k)(L)(B);return[{start:b(k,L),end:b(k,S),direction:ne},{start:b(k,S),end:b(et,S),direction:ee},{start:b(et,S),end:b(et,P),direction:ne},{start:b(et,P),end:b(E,P),direction:ee},{start:b(E,P),end:b(E,B),direction:ne}]}const X=d(k,E,L,B);return[{start:b(k,L),end:b(k,X),direction:ne},{start:b(k,X),end:b(E,X),direction:ee},{start:b(E,X),end:b(E,B),direction:ne}]},_=(k,L,E,B)=>{if(L===B){const et=s2(e)(k)(E)(L),S=e2(e)(L)(k)(E),P=r2(e)(L)(k)(E);return[{start:b(k,L),end:b(S,L),direction:ee},{start:b(S,L),end:b(S,et),direction:ne},{start:b(S,et),end:b(P,et),direction:ee},{start:b(P,et),end:b(P,B),direction:ne},{start:b(P,B),end:b(E,B),direction:ee}]}const X=Mg(e)(L)(B)(k)(E);return[{start:b(k,L),end:b(X,L),direction:ee},{start:b(X,L),end:b(X,B),direction:ne},{start:b(X,B),end:b(E,B),direction:ee}]},h=(k,L,E)=>!Gi(e)(ce(L)(E))(ge(L)(E))(k),p=(k,L,E)=>!Gi(n)(ce(L)(E))(ge(L)(E))(k),m=(k,L,E,B)=>{if(p(L,k,E)&&f(E,L,B))return[{start:b(k,L),end:b(E,L),direction:ee},{start:b(E,L),end:b(E,B),direction:ne}];const X=Mg(e)(L)(B)(k)(E);return[{start:b(k,L),end:b(X,L),direction:ee},{start:b(X,L),end:b(X,B),direction:ne},{start:b(X,B),end:b(E,B),direction:ee}]},y=(k,L,E,B)=>{if(f(k,L,B)&&p(B,k,E))return[{start:b(k,L),end:b(k,B),direction:ne},{start:b(k,B),end:b(E,B),direction:ee}];const X=d(k,E,L,B);return[{start:b(k,L),end:b(k,X),direction:ne},{start:b(k,X),end:b(E,X),direction:ee},{start:b(E,X),end:b(E,B),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"?m(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="West"){if(o==="East")return s._2===a._2&&h(s._2,s._1,a._1)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:ee}]:_(s._1,s._2,a._1,a._2);if(o==="North"||o==="South")return m(s._1,s._2,a._1,a._2)}return l(s._1,s._2,a._1,a._2)})(),N=(()=>{if(r==="South"||r==="North")return ne;if(r==="East"||r==="West")return ee;g()})(),w={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}]:Vm({start:b(i._1,i._2),end:b(s._1,s._2),direction:N})(x)(w)},c2=M(t=>({x:t.position._1*Ao-2,y:t.position._2*Ao-2,w:t.size._1*Ao+4,h:t.size._2*Ao+4})),Ps=Kt(C)(zt),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=v("Just",o._4);continue}}g()}return i},Ds=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=v("Just",o._4);continue}}g()}return i},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=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=v("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=v("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=v("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=v("Just",o._4);continue}}g()}return i},qg=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()},Hg=t=>e=>J(n=>r=>vt(t)(te)(e(r))([r])(n))(Q),$g=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},Xg=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,i=e.length;return i===0?Q:Ps(i===1?M(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=Hg(C)(_=>_.to.node)(t),u=Hg(C)(_=>_.from.node)(t),s=J(_=>h=>K(C)(h.node)(h)(_))(Q)(e),a=(_,h,p)=>{const m=Qn(_)(s);if(m.tag==="Nothing")return b(0,0);if(m.tag==="Just"){const y=Qn(_)(n);if(y.tag==="Nothing"){const x=rt(4);if(p==="South")return b(m._1.position._1*x+m._1.size._1*x/2,(m._1.position._2+m._1.size._2)*x);if(p==="North")return b(m._1.position._1*x+m._1.size._1*x/2,m._1.position._2*x);if(p==="East")return b((m._1.position._1+m._1.size._1)*x,m._1.position._2*x+m._1.size._2*x/2);if(p==="West")return b(m._1.position._1*x,m._1.position._2*x+m._1.size._2*x/2);g()}if(y.tag==="Just"){const x=Vt(N=>N.id===h)(y._1);if(x.tag==="Nothing"){const N=rt(4);if(p==="South")return b(m._1.position._1*N+m._1.size._1*N/2,(m._1.position._2+m._1.size._2)*N);if(p==="North")return b(m._1.position._1*N+m._1.size._1*N/2,m._1.position._2*N);if(p==="East")return b((m._1.position._1+m._1.size._1)*N,m._1.position._2*N+m._1.size._2*N/2);if(p==="West")return b(m._1.position._1*N,m._1.position._2*N+m._1.size._2*N/2);g()}if(x.tag==="Just"){const N=rt(4);if(x._1.side==="North")return b(m._1.position._1*N+rt(x._1.offset)*N,m._1.position._2*N);if(x._1.side==="South")return b(m._1.position._1*N+rt(x._1.offset)*N,(m._1.position._2+m._1.size._2)*N);if(x._1.side==="East")return b((m._1.position._1+m._1.size._1)*N,m._1.position._2*N+rt(x._1.offset)*N);if(x._1.side==="West")return b(m._1.position._1*N,m._1.position._2*N+rt(x._1.offset)*N)}}}g()},c=Ps(Tt(r)(_=>{if(_.nodes.length<=2)return[];const h=rt(4);if(1<_.nodes.length){const p=Qn(_.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 M(y=>b(y,m))(Je(y=>x=>_.edgeId+":"+y+"->"+x,_.nodes,bt(1,_.nodes.length,_.nodes)))}g()}return[]})),f=_=>{const h=Qn(_.from.node)(s),p=Qn(_.to.node)(s);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,y=p._1,x=kt(N=>w=>it.compare(N.score)(w.score))(M(N=>{const w=N._1,k=N._2;return{from:w,to:k,score:(()=>{const L=(et,S,P,V,U)=>{const O=Is(et)(S),z=Is(et)(P);return O.lo<z.hi&&z.lo<O.hi&&(w==="South"?k==="North"&&U._2>V._2:w==="North"?k==="South"&&U._2<V._2:w==="East"?k==="West"&&U._1>V._1:w==="West"&&k==="East"&&U._1<V._1)?0:$g(w)(k)(V)(U)},E=qg(w)(m),B=qg(k)(y),X=$g(w)(k)(E)(B);return(()=>{if(X>0){if(w==="South")return k==="North"?L(he,m,y,E,B)*10|0:X*10|0;if(w==="North")return k==="South"?L(le,m,y,E,B)*10|0:X*10|0;if(w==="East")return k==="West"?L(Sn,m,y,E,B)*10|0:X*10|0;if(w==="West"&&k==="East")return L(Gn,m,y,E,B)*10|0}return X*10|0})()+(w==="South"?k==="North"?0:15:w==="North"?k==="South"?0:15:w==="East"?k==="West"?5:15:w==="West"&&k==="East"?5:15)|0})()}})([b(he,le),b(Sn,le),b(Gn,le),b(he,Sn),b(he,Gn),b(le,he),b(le,Sn),b(le,Gn),b(Sn,he),b(Gn,he),b(Sn,Gn),b(Gn,Sn)]));if(0<x.length)return{from:x[0].from,to:x[0].to}}return{from:he,to:le}},d=Ps(M(_=>b(_.id,f(_)))(t)),l=(_,h,p,m,y,x)=>{const N=rt(4),w=Qn(h)(s);if(w.tag==="Nothing")return b(0,0);if(w.tag==="Just"){const k=g2(b(p,_))(i);if(k.tag==="Just"){const L=w._1.position._1*N+k._1,E=rt(4);if(_==="South")return b(L,(w._1.position._2+w._1.size._2)*E);if(_==="North")return b(L,w._1.position._2*E);if(_==="East")return b((w._1.position._1+w._1.size._1)*E,L);if(_==="West")return b(w._1.position._1*E,L);g()}if(k.tag==="Nothing"){const L=Is(_)(w._1),E=(L.lo+L.hi)/2,B=Ds(p)(Xg(L)(M(S=>S.id)(kt(S=>P=>ut.compare(y(_)(S))(y(_)(P)))(st(S=>{const P=Ds(S.id)(d);if(P.tag==="Just"){const V=x(P._1);return V==="North"?_==="North":V==="South"?_==="South":V==="East"?_==="East":V==="West"&&_==="West"}if(P.tag==="Nothing")return!0;g()},(()=>{const S=Qn(h)(m);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()))))),X=(()=>{if(B.tag==="Nothing")return E;if(B.tag==="Just")return B._1;g()})(),et=rt(4);if(_==="South")return b(X,(w._1.position._2+w._1.size._2)*et);if(_==="North")return b(X,w._1.position._2*et);if(_==="East")return b((w._1.position._1+w._1.size._1)*et,X);if(_==="West")return b(w._1.position._1*et,X)}}g()};return M(_=>{const h=Ds(_.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()})(M(_=>{if(_.from.port.tag==="Just"&&_.to.port.tag==="Just")return{edge:_,fromPos:a(_.from.node,_.from.port._1,he),toPos:a(_.to.node,_.to.port._1,le),fromSide:he,toSide:le};const h=f(_);return{edge:_,fromPos:l(h.from,_.from.node,_.id,u,p=>m=>{const y=Qn(m.to.node)(s);if(y.tag==="Nothing")return 0;if(y.tag==="Just"){const x=rt(4);if(p==="South"||p==="North")return y._1.position._1*x+y._1.size._1*x/2;if(p==="East"||p==="West")return y._1.position._2*x+y._1.size._2*x/2}g()},p=>p.from),toPos:l(h.to,_.to.node,_.id,o,p=>m=>{const y=Qn(m.from.node)(s);if(y.tag==="Nothing")return 0;if(y.tag==="Just"){const x=rt(4);if(p==="South"||p==="North")return y._1.position._1*x+y._1.size._1*x/2;if(p==="East"||p==="West")return y._1.position._2*x+y._1.size._2*x/2}g()},p=>p.to),fromSide:h.from,toSide:h.to}})(t))},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=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=v("Just",o._4);continue}}g()}return i},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=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=v("Just",o._4);continue}}g()}return i},f2=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Qs=t=>e=>t.gapTop+1*rt(4)+rt(e)*2.5*rt(4),_2=t=>e=>{const n=Vg(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return v("Just",{slot1Y:Qs(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Qs(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return T;g()}if(n.tag==="Nothing")return T;g()},d2=t=>e=>{const n=J(r=>i=>K(C)(i.node)(i)(r))(Q)(e);return Fe(At(r=>i=>{const o=zr(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),p=l+_*rt(c-s|0)/h,m=l+_*rt((c+1|0)+s|0)/h,y=d-f*2.5*rt(s+1|0),x=[{start:b(d,p),end:b(y,p),direction:ee},{start:b(y,p),end:b(y,m),direction:ne},{start:b(y,m),end:b(d,m),direction:ee}];return{edge:a.id,segments:x,bends:Je(N=>w=>N.end,x,bt(1,3,x)),bendType:[],jumps:[],reversed:!1}})(i.edges)}g()})(M(r=>({node:r._1,edges:r._2}))(f2(J(r=>i=>vt(C)(te)(i.from.node)([i])(r))(Q)(t)))))},l2=t=>e=>{const n=J(o=>u=>K(C)(u.node)(u)(o))(Q)(e),r=o=>{const u=zr(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.position._1;g()},i=o=>{const u=zr(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.layer;g()};return kt(o=>u=>{const s=it.compare(i(o.edge.from.node))(i(u.edge.from.node));if(s==="EQ"){const a=ut.compare(r(o.edge.from.node))(r(u.edge.from.node));return a==="EQ"?ut.compare(r(o.edge.to.node))(r(u.edge.to.node)):a}return s})(t)},Pe=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}},h2=t=>t.from.node===t.to.node,p2=t=>e=>n=>r=>{const i=t2(n)(a2(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}},m2=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}},y2=t=>e=>n=>{const r=zr(t.edge.from.node)(n);if(r.tag==="Just"){const o=zr(t.edge.to.node)(n);return o.tag==="Just"?st(u=>!(u.h===Pe(r._1).h&&u.w===Pe(r._1).w&&u.x===Pe(r._1).x&&u.y===Pe(r._1).y)&&!(u.h===Pe(o._1).h&&u.w===Pe(o._1).w&&u.x===Pe(o._1).x&&u.y===Pe(o._1).y),e):st(u=>!(u.h===Pe(r._1).h&&u.w===Pe(r._1).w&&u.x===Pe(r._1).x&&u.y===Pe(r._1).y),e)}const i=zr(t.edge.to.node)(n);return i.tag==="Just"?st(o=>!(o.h===Pe(i._1).h&&o.w===Pe(i._1).w&&o.x===Pe(i._1).x&&o.y===Pe(i._1).y),e):st(o=>!0,e)},x2=t=>e=>{const n=Vg(e.edge.id)(t);if(n.tag==="Just")return v("Just",Qs(n._1)(n._1.slot));if(n.tag==="Nothing")return T;g()},N2=t=>e=>n=>r=>i=>{const o=J(c=>f=>K(C)(f.node)(f)(c))(Q)(e),u=c2(e),s=Yg(st(c=>c.from.node!==c.to.node,t))(e)(n)(r)(i),a=zg(s)(e);return[...d2(st(h2,t))(e),...J(c=>f=>{const d=y2(f)(u)(o),l=[...d,...c.edgeObstacles],_=_2(a)(f),h=(()=>{if(_.tag==="Just")return m2(_._1)(d)(l)(f);if(_.tag==="Nothing")return p2(x2(a)(f))(d)(l)(f);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...Ym(h.segments)]}})({results:[],edgeObstacles:[]})(l2(s)(e)).results]},tr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},er=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},J2=t=>e=>n=>{if(t.start._1!==e.start._1)return T;const r=er(tr(t.start._2)(t.end._2))(tr(e.start._2)(e.end._2)),i=tr(er(t.start._2)(t.end._2))(er(e.start._2)(e.end._2));return r<i?v("Just",{position:b(t.start._1,(r+i)/2),crossingEdge:n}):T},T2=t=>e=>n=>{if(t.start._2!==e.start._2)return T;const r=er(tr(t.start._1)(t.end._1))(tr(e.start._1)(e.end._1)),i=tr(er(t.start._1)(t.end._1))(er(e.start._1)(e.end._1));return r<i?v("Just",{position:b((r+i)/2,t.start._2),crossingEdge:n}):T},w2=t=>e=>n=>{if(t.direction==="H")return T2(t)(e)(n);if(t.direction==="V")return J2(t)(e)(n);g()},v2=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=>w2(o)(s)(u.edge))(st(s=>s.direction==="H"?o.direction==="H":s.direction==="V"&&o.direction==="V",u.segments))))},b2=t=>e=>n=>e.start._1>tr(t.start._1)(t.end._1)&&e.start._1<er(t.start._1)(t.end._1)&&t.start._2>tr(e.start._2)(e.end._2)&&t.start._2<er(e.start._2)(e.end._2)?v("Just",{position:b(e.start._1,t.start._2),crossingEdge:n}):T,L2=t=>e=>Tt(st(n=>n.direction==="H",t.segments))(n=>Tt(e)(r=>xt(i=>b2(n)(i)(r.edge))(st(i=>i.direction==="V",r.segments)))),k2=t=>e=>n=>[...L2(e)(st(r=>r.edge!==e.edge,n)),...v2(t)(e)(n)],Ug=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=v("Just",o._4);continue}}g()}return i},jg=t=>me(3)(t)==="$d:",E2=t=>e=>n=>J(r=>i=>{const o=Ug(i.from.node)(t),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})(),s=Ug(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=M(l=>"$d:"+c+":"+ie(l))(It(1,a-1|0)),d=[i.from.node,...f,i.to.node];return{...r,layers:J(l=>_=>{const h=_._2,p=sd(u+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;g()})(r.layers)(Je(En,It(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),Ro=(()=>{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 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}})(),C2=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=Ro.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=v("Just",o._4);continue}}g()}return i},S2=Kt(C)(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=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=v("Just",o._4);continue}}g()}return i},G2=Kt(Ro)(zt),Zg=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Wr=t=>e=>n=>r=>{const i=C2(b(e,n))(t);if(i.tag==="Nothing")return r;if(i.tag==="Just")return i._1;g()},Kg=t=>e=>n=>{const r=S2(Fe(M(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=>Ee(Ro.compare,Le,G2(M(c=>b(b(c._1,u),c._2))(Zg(Xg({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()})()})(M(c=>c.id)(kt(c=>f=>it.compare(i(u,c))(i(u,f)))(a._2)))))),s))(Q)(Zg(J(s=>a=>a.from.node===a.to.node?s:u==="South"?vt(C)(te)(a.from.node)([a])(s):u==="North"?vt(C)(te)(a.to.node)([a])(s):s)(Q)(e)));return Ee(Ro.compare,Le,o(le),o(he))},tf=t=>t,ef=t=>t,nf=t=>t,P2=J(t=>e=>K(C)(e)()(t))(Q),D2=(()=>{const t=$e.unfoldr(e=>{if(e.tag==="Nil")return T;if(e.tag==="Cons")return v("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._3,n(r._6,i)));g()};return n(e,Ht)})())})(),ot=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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=v("Just",o._4);continue}}g()}return i},nn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Nn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jn=Kt(C)(zt),Rs=ja(C),Fs=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),I2=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Q2=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=v("Just",o._4);continue}}g()}return i},rf=nf("VDown"),of=nf("VUp"),A2=ef("ForwardPhase"),R2=ef("StackPhase"),uf=tf("HRight"),sf=tf("HLeft"),af=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},F2=t=>e=>n=>{const r=J(u=>s=>vt(C)(oe)(s.tgt)(1)(u))(Q)(t),i=D2(P2([...M(u=>u.src)(t),...M(u=>u.tgt)(t),...(()=>{const u=(s,a)=>{if(s.tag==="Leaf")return a;if(s.tag==="Node")return u(s._5,qt("Cons",s._4,u(s._6,a)));g()};return Ct($t.foldr,u(e,Ht))})()])),o=J(u=>s=>vt(C)(te)(s.src)([{target:s.tgt,sep:s.sep}])(u))(Q)(t);return(u=>s=>a=>{let c=u,f=s,d=a,l=!0,_;for(;l;){const h=c,p=f,m=d,y=Rt(x=>T,x=>N=>v("Just",{head:x,tail:N}),h);if(y.tag==="Nothing"){l=!1,_=m;continue}if(y.tag==="Just"){const x=ot(y._1.head)(m),N=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})(),w=J(k=>L=>{const E=ot(L.target)(k.result),B=N+L.sep,X=ot(L.target)(k.indeg),et=(()=>{if(X.tag==="Nothing")return-1;if(X.tag==="Just")return X._1-1|0;g()})();return{newQueue:et===0?[...k.newQueue,L.target]:k.newQueue,result:K(C)(L.target)((()=>{if(E.tag==="Nothing")return B;if(E.tag==="Just"){if(n==="VDown")return nn(E._1)(B);if(n==="VUp")return Nn(E._1)(B)}g()})())(k.result),indeg:K(C)(L.target)(et)(k.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const k=ot(y._1.head)(o);if(k.tag==="Nothing")return[];if(k.tag==="Just")return k._1;g()})());c=[...y._1.tail,...w.newQueue],f=w.indeg,d=w.result;continue}g()}return _})(st(u=>{const s=ot(u)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;g()},i))(r)(J(u=>s=>K(C)(s)(0)(u))(Q)(i))},B2=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,qt("Cons",o._4,e(o._6,u)));g()},n=Ct($t.foldr,e(t,Ht)),r=J(nn)(999999)(n);if(r===0||n.length===0)return t;const i=o=>{if(o.tag==="Leaf")return Q;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)},cf=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,qt("Cons",o._4,e(o._6,u)));g()},n=e(t,Ht),r=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l.tag==="Nil"){c=!1,f=d;continue}if(l.tag==="Cons"){s=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=nn(d)(l._1),a=l._2;continue}g()}return f};return r(-999999)(n)-i(999999)(n)},Pi=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]),z2=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>{const d=(G,D,I)=>{const A=G.from.node===D?G.from.port:G.to.node===D?G.to.port:T;if(A.tag==="Just"){const H=ot(D)(i);if(H.tag==="Just"){const $=Vt(Y=>Y.id===A._1)(H._1);if($.tag==="Just"){const Y=rt($._1.offset)*rt(4);return I==="North"||I==="South"?Y:0}if($.tag==="Nothing"){const Y=ot(D)(r),q=Wr(u)(G.id)(I)((()=>{if(Y.tag==="Nothing")return .5;if(Y.tag==="Just")return Y._1._1/2;g()})());return I==="North"||I==="South"?q:0}g()}if(H.tag==="Nothing"){const $=ot(D)(r),Y=Wr(u)(G.id)(I)((()=>{if($.tag==="Nothing")return .5;if($.tag==="Just")return $._1._1/2;g()})());return I==="North"||I==="South"?Y:0}g()}if(A.tag==="Nothing"){const H=ot(D)(r),$=Wr(u)(G.id)(I)((()=>{if(H.tag==="Nothing")return .5;if(H.tag==="Just")return H._1._1/2;g()})());return I==="North"||I==="South"?$:0}g()},l=(G,D)=>{if(G.from.node===D){if(f==="HRight")return he;if(f==="HLeft")return le;g()}if(f==="HRight")return le;if(f==="HLeft")return he;g()},_=(G,D,I)=>J(A=>H=>K(C)(H)((()=>{const $=ot(H)(A);if($.tag==="Nothing")return 0+D;if($.tag==="Just")return $._1+D;g()})())(A))(I)(Pi(a)(G)),h=(()=>{if(f==="HRight")return n;if(f==="HLeft")return Ne(n);g()})(),p=G=>{const D=ot(G)(r);if(D.tag==="Nothing")return 1;if(D.tag==="Just")return D._1._1;g()},m=Jn(Fe(At(G=>D=>M(I=>b(I,G))(D))(n))),y=(G,D)=>me(3)(G)==="$d:"&&me(3)(D)==="$d:"||me(3)(G)==="$d:"||me(3)(D)==="$d:"?10:rt(t.nodeGap),x=J(G=>D=>Rs(I=>v("Just",[...(()=>{if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})(),D]))(D.to.node)(G))(Q)(o),N=J(G=>D=>Rs(I=>v("Just",[...(()=>{if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})(),D]))(D.from.node)(G))(Q)(o),w=Fe(n),k=J(G=>D=>{const I=ot(D)(a.root),A=(()=>{if(I.tag==="Nothing")return D;if(I.tag==="Just")return I._1;g()})();return D===A?G:Rs(H=>v("Just",(()=>{if(H.tag==="Nothing")return!0;if(H.tag==="Just")return H._1;g()})()&&me(3)(D)==="$d:"))(A)(G)})(Jn(M(G=>b(G,!0))(Tr(C.compare)((()=>{const G=(D,I)=>{if(D.tag==="Leaf")return I;if(D.tag==="Node")return G(D._5,qt("Cons",D._4,G(D._6,I)));g()};return Ct($t.foldr,G(a.root,Ht))})()))))(w),L=(G,D)=>{const I=G.free,A=ot(I)(a.root),H=(()=>{if(A.tag==="Nothing")return I;if(A.tag==="Just")return A._1;g()})(),$=ot(H)(k),Y=(()=>{if($.tag==="Nothing")return!0;if($.tag==="Just")return $._1;g()})();return J(q=>W=>{if(q.edge.tag==="Just")return q;if(q.edge.tag==="Nothing"){if((()=>{const at=ot(H)(D.su);return!Y&&(()=>{const yt=ot(W.from.node)(m);return W.from.node!==W.to.node&&(()=>{const St=ot(W.to.node)(m);return(()=>{if(yt.tag==="Nothing")return-1;if(yt.tag==="Just")return yt._1;g()})()===(()=>{if(St.tag==="Nothing")return-1;if(St.tag==="Just")return St._1;g()})()})()})()||(()=>{if(at.tag==="Nothing")return!1;if(at.tag==="Just")return at._1;g()})()})())return q;const tt=W.from.node===I?W.to.node:W.from.node,j=ot(tt)(a.root),gt=(()=>{if(j.tag==="Nothing")return tt;if(j.tag==="Just")return j._1;g()})(),_t=gt!==H;return _t&&(()=>{const at=ot(gt)(D.blockFinished);if(at.tag==="Nothing")return!1;if(at.tag==="Just")return at._1;g()})()?{...q,edge:v("Just",W),hasEdges:!0}:{...q,hasEdges:q.hasEdges||_t}}g()})({edge:T,hasEdges:!1})((()=>{if(G.isRoot){if(f==="HRight"){const q=ot(I)(x);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;g()}if(f==="HLeft"){const q=ot(I)(N);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}g()}if(f==="HRight"){const q=ot(I)(N);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;g()}if(f==="HLeft"){const q=ot(I)(x);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}g()})())},E=(G,D,I,A)=>{const H=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),$={free:D,isRoot:I},Y=L($,A);if(Y.edge.tag==="Nothing")return Y.hasEdges?{thresh:H,state:{...A,queue:[...A.queue,$]}}:{thresh:H,state:A};if(Y.edge.tag==="Just"){const q=Y.edge._1.from.node===D?Y.edge._1.to.node:Y.edge._1.from.node;return{thresh:(()=>{const W=ot((()=>{const _t=ot(q)(a.root);if(_t.tag==="Nothing")return q;if(_t.tag==="Just")return _t._1;g()})())(A.x),tt=ot(q)(s),j=ot(D)(s),gt=(()=>{if(W.tag==="Just")return W._1;if(W.tag==="Nothing")return T;g()})();return(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()+(()=>{if(tt.tag==="Nothing")return 0;if(tt.tag==="Just")return tt._1;g()})()+d(Y.edge._1,q,(()=>{if(I){if(f==="HRight")return he;if(f==="HLeft")return le;g()}if(f==="HRight")return le;if(f==="HLeft")return he;g()})())-(()=>{if(j.tag==="Nothing")return 0;if(j.tag==="Just")return j._1;g()})()-d(Y.edge._1,D,(()=>{if(I){if(f==="HRight")return le;if(f==="HLeft")return he;g()}if(f==="HRight")return he;if(f==="HLeft")return le;g()})())})(),state:{...A,su:K(C)((()=>{const W=ot(Y.edge._1.from.node)(a.root);if(W.tag==="Nothing")return Y.edge._1.from.node;if(W.tag==="Just")return W._1;g()})())(!0)(K(C)((()=>{const W=ot(Y.edge._1.to.node)(a.root);if(W.tag==="Nothing")return Y.edge._1.to.node;if(W.tag==="Just")return W._1;g()})())(!0)(A.su))}}}g()},B=(G,D,I,A)=>{const H=D===G,$=ot(D)(a.align),Y=(()=>{if($.tag==="Nothing")return D===G;if($.tag==="Just")return $._1===G;g()})();if(!(H||Y))return{thresh:I,state:A};const q=(()=>{if(c==="VDown")return H&&I<=-1e18;if(c==="VUp")return H&&I>=1e18;g()})()?E(G,D,!0,A):{thresh:I,state:A};return(()=>{if(c==="VDown")return q.thresh<=-1e18&&Y;if(c==="VUp")return q.thresh>=1e18&&Y;g()})()?E(G,D,!1,q.state):q},X=G=>D=>I=>{const A=ot(I)(e.nodeIndex),H=(()=>{if(A.tag==="Nothing")return 0;if(A.tag==="Just")return A._1;g()})(),$=Vt(j=>ze(fn)(I)(j))(h),Y=(()=>{if($.tag==="Nothing")return[];if($.tag==="Just")return $._1;g()})(),q=Y.length;if((()=>{if(c==="VDown")return H<=0;if(c==="VUp")return H>=(q-1|0);g()})()){const j=B(G,I,D.thresh,D.st);return{...D,st:j.state,thresh:j.thresh}}const W=(()=>{if(c==="VDown")return H-1|0;if(c==="VUp")return H+1|0;g()})(),tt=W>=0&&W<Y.length?v("Just",Y[W]):T;if(tt.tag==="Nothing")return D;if(tt.tag==="Just"){const j=ot(tt._1)(a.root),gt=(()=>{if(j.tag==="Nothing")return tt._1;if(j.tag==="Just")return j._1;g()})(),_t=B(G,I,D.thresh,et(gt)(D.st)),at=(()=>{const Zt=ot(G)(_t.state.sink);if(Zt.tag==="Nothing")return G===G;if(Zt.tag==="Just")return Zt._1===G;g()})()?{..._t.state,sink:K(C)(G)((()=>{const Zt=ot(gt)(_t.state.sink);if(Zt.tag==="Nothing")return gt;if(Zt.tag==="Just")return Zt._1;g()})())(_t.state.sink)}:_t.state,yt=ot(gt)(at.sink),St=(()=>{if(yt.tag==="Nothing")return gt;if(yt.tag==="Just")return yt._1;g()})(),Ft=ot(G)(at.sink),pt=(()=>{if(Ft.tag==="Nothing")return G;if(Ft.tag==="Just")return Ft._1;g()})();if(pt===St){const Zt=ot(gt)(at.x),Se=(()=>{if(Zt.tag==="Just")return Zt._1;if(Zt.tag==="Nothing")return T;g()})(),sn=(()=>{if(Se.tag==="Nothing")return 0;if(Se.tag==="Just")return Se._1;g()})(),Re=ot(G)(at.x),Et=(()=>{if(Re.tag==="Just")return Re._1;if(Re.tag==="Nothing")return T;g()})(),Qt=(()=>{if(Et.tag==="Nothing")return 0;if(Et.tag==="Just")return Et._1;g()})(),Ze=y(I,tt._1),qe=ot(tt._1)(s),Ke=ot(I)(s),qn=(()=>{if(qe.tag==="Nothing")return 0;if(qe.tag==="Just")return qe._1;g()})()-(()=>{if(Ke.tag==="Nothing")return 0;if(Ke.tag==="Just")return Ke._1;g()})();if(c==="VDown"){const dn=Nn(sn+qn+p(tt._1)+Ze)(_t.thresh);return{st:{...at,x:K(C)(G)(v("Just",D.initial?dn:Nn(Qt)(dn)))(at.x)},initial:!1,thresh:_t.thresh}}if(c==="VUp"){const dn=nn(sn+qn-Ze-p(I))(_t.thresh);return{st:{...at,x:K(C)(G)(v("Just",D.initial?dn:nn(Qt)(dn)))(at.x)},initial:!1,thresh:_t.thresh}}g()}const Bt=ot(gt)(at.x),Jt=(()=>{if(Bt.tag==="Just")return Bt._1;if(Bt.tag==="Nothing")return T;g()})(),mt=(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})(),ct=ot(G)(at.x),Z=(()=>{if(ct.tag==="Just")return ct._1;if(ct.tag==="Nothing")return T;g()})(),nt=(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})(),ht=rt(t.nodeGap),ft=ot(I)(s),Nt=ot(tt._1)(s),wt=(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;g()})()-(()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1;g()})();return{st:{...at,classEdges:[...at.classEdges,{src:pt,tgt:St,sep:(()=>{if(c==="VDown")return nt+wt-mt-p(tt._1)-ht;if(c==="VUp")return nt+wt+p(I)+ht-mt;g()})()}]},initial:D.initial,thresh:_t.thresh}}g()},et=G=>D=>{const I=ot(G)(D.x),A=(()=>{if(I.tag==="Just")return I._1;if(I.tag==="Nothing")return T;g()})();if(A.tag==="Just")return D;if(A.tag==="Nothing"){const H=J(X(G))({st:{...D,x:K(C)(G)(v("Just",0))(D.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})()})(Pi(a)(G));return{...H.st,blockFinished:K(C)(G)(!0)(H.st.blockFinished)}}g()},S=J(G=>D=>J(I=>A=>{const H=ot(A)(a.root),$=(()=>{if(H.tag==="Nothing")return A;if(H.tag==="Just")return H._1;g()})();return $===A?et($)(I):I})(G)((()=>{if(c==="VDown")return D;if(c==="VUp")return Ne(D);g()})()))({x:Jn(M(G=>b(G,T))(w)),sink:Jn(M(G=>b(G,G))(w)),classEdges:[],su:Q,blockFinished:Q,queue:[]})(h),P=F2(S.classEdges)(S.sink)(c),V=(G,D,I,A)=>{const H=ot(D)(A),$=ot(D)(s);return(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})()+(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;g()})()+d(G,D,I)},U=Jn(M(G=>b(G,!0))(Tr(C.compare)((()=>{const G=(D,I)=>{if(D.tag==="Leaf")return I;if(D.tag==="Node")return G(D._5,qt("Cons",D._4,G(D._6,I)));g()};return Ct($t.foldr,G(a.root,Ht))})()))),O=G=>D=>I=>{const A=L(I,{su:D.su,blockFinished:U}),H={phase:G,ppFree:I.free,ppIsRoot:I.isRoot,edgeId:T,delta:0,avail:0,shift:0,freeSu:(()=>{const $=ot((()=>{const Y=ot(I.free)(a.root);if(Y.tag==="Nothing")return I.free;if(Y.tag==="Just")return Y._1;g()})())(D.su);if($.tag==="Nothing")return!1;if($.tag==="Just")return $._1;g()})(),hasEdges:A.hasEdges,candCount:(()=>{if(I.isRoot){if(f==="HRight"){const $=ot(I.free)(x);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length;g()}if(f==="HLeft"){const $=ot(I.free)(N);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length}g()}if(f==="HRight"){const $=ot(I.free)(N);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length;g()}if(f==="HLeft"){const $=ot(I.free)(x);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length}g()})()};if(A.edge.tag==="Nothing")return{...D,stack:[...D.stack,I],trace:[...D.trace,H],x:D.x};if(A.edge.tag==="Just"){const $=A.edge._1.from.node===I.free?b(A.edge._1.from.node,A.edge._1.to.node):b(A.edge._1.to.node,A.edge._1.from.node),Y=V(A.edge._1,$._1,l(A.edge._1,$._1),D.x)-V(A.edge._1,$._2,l(A.edge._1,$._2),D.x),q=ot($._1)(a.root),W=(()=>{if(q.tag==="Nothing")return $._1;if(q.tag==="Just")return q._1;g()})(),tt={...H,edgeId:v("Just",A.edge._1.id),delta:Y};if(Y>0&&Y<1e300){const j=J(at=>yt=>{const St=ot(yt)(m),Ft=(()=>{if(St.tag==="Nothing")return-1;if(St.tag==="Just")return St._1;g()})();if(Ft>=0&&Ft<n.length){const Jt=n[Ft],mt=ot(yt)(e.nodeIndex),ct=(()=>{if(mt.tag==="Nothing")return-2;if(mt.tag==="Just")return mt._1-1|0;g()})();return ct>=0&&ct<Jt.length?nn(at)((()=>{const Z=ot(yt)(D.x),nt=ot(yt)(s),ht=ot(Jt[ct])(D.x),ft=ot(Jt[ct])(s);return(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;g()})()-((()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;g()})()+p(Jt[ct])+y(yt,Jt[ct]))})()):at}const pt=ot(yt)(e.nodeIndex),Bt=(()=>{if(pt.tag==="Nothing")return-2;if(pt.tag==="Just")return pt._1-1|0;g()})();return Bt>=0&&Bt<0?nn(at)((()=>{const Jt=ot(yt)(D.x),mt=ot(yt)(s),ct=ot([][Bt])(D.x),Z=ot([][Bt])(s);return(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})()+(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()-((()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()+p([][Bt])+y(yt,[][Bt]))})()):at})(Y)(Pi(a)(W)),gt=j>0?-j:0,_t={...D,x:j>0?_(W,gt,D.x):D.x,trace:[...D.trace,{...tt,avail:j,shift:gt}]};return j>0?_t:{..._t,stack:[..._t.stack,I]}}if(Y<0&&-Y<1e300){const j=J(at=>yt=>{const St=ot(yt)(m),Ft=(()=>{if(St.tag==="Nothing")return-1;if(St.tag==="Just")return St._1;g()})();if(Ft>=0&&Ft<n.length){const Jt=n[Ft],mt=ot(yt)(e.nodeIndex),ct=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1+1|0;g()})();return ct>=0&&ct<Jt.length?nn(at)((()=>{const Z=ot(Jt[ct])(D.x),nt=ot(Jt[ct])(s),ht=ot(yt)(D.x),ft=ot(yt)(s);return(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;g()})()-((()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;g()})()+p(yt)+y(yt,Jt[ct]))})()):at}const pt=ot(yt)(e.nodeIndex),Bt=(()=>{if(pt.tag==="Nothing")return 0;if(pt.tag==="Just")return pt._1+1|0;g()})();return Bt>=0&&Bt<0?nn(at)((()=>{const Jt=ot([][Bt])(D.x),mt=ot([][Bt])(s),ct=ot(yt)(D.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(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()+p(yt)+y(yt,[][Bt]))})()):at})(-Y)(Pi(a)(W)),gt=j>0?j:0,_t={...D,x:j>0?_(W,gt,D.x):D.x,trace:[...D.trace,{...tt,avail:j,shift:gt}]};return j>0?_t:{..._t,stack:[..._t.stack,I]}}return{...D,stack:[...D.stack,I],trace:[...D.trace,tt],x:D.x}}g()},z=J(O(A2))({x:Jn(M(G=>b(G,(()=>{const D=ot(G)(a.root),I=(()=>{if(D.tag==="Nothing")return G;if(D.tag==="Just")return D._1;g()})(),A=ot(I)(S.x),H=ot((()=>{const Y=ot(I)(S.sink);if(Y.tag==="Nothing")return I;if(Y.tag==="Just")return Y._1;g()})())(P),$=(()=>{if(A.tag==="Just")return A._1;if(A.tag==="Nothing")return T;g()})();return(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;g()})()+(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})()})()))(w)),su:S.su,stack:[],trace:[]})(S.queue),F=J(O(R2))({...z,stack:[]})(Ne(z.stack));return{x:F.x,queue:S.queue,trace:F.trace}},W2=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>z2(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 p=Vt(m=>m.id===_._1)(h._1);if(p.tag==="Just"){const m=rt(p._1.offset)*rt(4);return f==="North"||f==="South"?m:0}if(p.tag==="Nothing"){const m=Wr(i)(a.id)(f)(l);return f==="North"||f==="South"?m:0}g()}if(h.tag==="Nothing"){const p=Wr(i)(a.id)(f)(l);return f==="North"||f==="South"?p:0}g()}if(_.tag==="Nothing"){const h=Wr(i)(a.id)(f)(l);return f==="North"||f==="South"?h:0}g()},s=a=>c=>f=>d=>{let l=a,_=c,h=f,p=d,m=!0,y;for(;m;){const x=l,N=_,w=h,k=Rt(L=>T,L=>E=>v("Just",{head:L,tail:E}),p);if(k.tag==="Nothing"){m=!1,y=x;continue}if(k.tag==="Just"){const L=k._1.head,E=Vt(X=>X.from.node===w&&X.to.node===L||X.from.node===L&&X.to.node===w)(r),B=(()=>{if(E.tag==="Nothing")return N+0;if(E.tag==="Just")return N+(u(E._1,w,E._1.from.node===w?he:le)-u(E._1,L,E._1.from.node===L?he:le));g()})();l=K(C)(L)(B)(x),_=B,h=L,p=k._1.tail;continue}g()}return y};return J(a=>c=>{const f=Rt(_=>T,_=>h=>v("Just",{head:_,tail:h}),Pi(t)(c)),d=(()=>{if(f.tag==="Nothing")return K(C)(c)(0)(Q);if(f.tag==="Just")return s(K(C)(f._1.head)(0)(Q))(0)(f._1.head)(f._1.tail);g()})(),l=J(_=>h=>Nn(_)(-h._2))(0)(Fs(d));return J(_=>h=>K(C)(h._1)(h._2+l)(_))(a)(Fs(d))})(Q)(Tr(C.compare)((()=>{const a=(c,f)=>{if(c.tag==="Leaf")return f;if(c.tag==="Node")return a(c._5,qt("Cons",c._4,a(c._6,f)));g()};return Ct($t.foldr,a(t.root,Ht))})()))},M2=t=>e=>{const n=(i,o,u)=>me(3)(o)==="$d:"&&Ma(jg,(()=>{const s=ot(o)(t.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;g()})()),r=i=>o=>u=>s=>a=>c=>f=>{let d=i,l=o,_=s,h=c,p=f,m=!0,y;for(;m;){const x=d,N=l,w=_,k=h,L=p,E=N.length;if(L>=E){m=!1,y=x;continue}const B=L>=0&&L<N.length?v("Just",N[L]):T,X=(()=>{if(B.tag==="Nothing")return"";if(B.tag==="Just")return B._1;g()})(),et=n(t,X);if(L===(E-1|0)||et){const S=(()=>{if(et){const P=ot(X)(t.preds),V=(()=>{if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})();if(0<V.length){const U=w-1|0,O=ot(V[0])(t.nodeIndex);if(O.tag==="Nothing")return U;if(O.tag==="Just")return O._1;g()}}return w-1|0})();d=J(P=>V=>{if(V>=0&&V<N.length){const U=N[V];return n(t,U)?P:J(O=>z=>{const F=ot(z)(t.nodeIndex),G=(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;g()})();return G<k||G>S?K(C)(z+"\u2192"+U)()(O):O})(P)((()=>{const O=ot(U)(t.preds);if(O.tag==="Nothing")return[];if(O.tag==="Just")return O._1;g()})())}return n(t,"")?P:J(U=>O=>{const z=ot(O)(t.nodeIndex),F=(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})();return F<k||F>S?K(C)(O+"\u2192")()(U):U})(P)((()=>{const U=ot("")(t.preds);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;g()})())})(x)(It(0,L)),l=N,_=w,h=S,p=L+1|0;continue}d=x,l=N,_=w,h=k,p=L+1|0}return y};return e.length<3?Q: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)})(Q)(It(1,e.length-2|0))},q2=t=>e=>n=>r=>i=>{const o=Fe(e),u=J(s=>a=>{const c=J(f=>d=>{const l=(()=>{if(i==="HRight"){const m=ot(d)(t.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()}if(i==="HLeft"){const m=ot(d)(t.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}g()})(),_=l.length;if(_===0)return f;const h=kn(_-1|0,2),p=kn(_,2);return J(m=>y=>{if((()=>{const x=ot(d)(m.align);if(x.tag==="Nothing")return d!==d;if(x.tag==="Just")return x._1!==d;g()})())return m;if(y>=0&&y<l.length){const x=ot(l[y])(t.nodeIndex),N=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})();if(!(af(l[y]+"\u2192"+d)(n)||af(d+"\u2192"+l[y])(n))&&(()=>{if(r==="VDown")return m.r<N;if(r==="VUp")return m.r>N;g()})()){const w=ot(l[y])(m.root),k=(()=>{if(w.tag==="Nothing")return l[y];if(w.tag==="Just")return w._1;g()})();return{root:K(C)(d)(k)(m.root),align:K(C)(l[y])(d)(K(C)(d)(k)(m.align)),r:N}}}return m})(f)((()=>{if(r==="VDown")return It(h,p);if(r==="VUp")return Ne(It(h,p));g()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;g()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return Ne(a);g()})());return{root:c.root,align:c.align}})({root:Jn(M(s=>b(s,s))(o)),align:Jn(M(s=>b(s,s))(o))})((()=>{if(i==="HRight")return e;if(i==="HLeft")return Ne(e);g()})());return{root:u.root,align:u.align}},Fo=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>{const f=q2(e)(n)(s)(a)(c),d=O2(f)(i)(r)(o)(u)(c);return Nd()(l=>_=>v("Just",(()=>{const h=ot(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;g()})()))(W2(t)(e)(n)(r)(i)(o)(u)(d)(f)(a)(c))},gf=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=It(0,e.length-1|0);return n<1?[]:bt(0,n,i)})()))(e),H2=t=>e=>n=>r=>i=>o=>u=>{const s=I2(0)(e.length-1|0),a=rt(t.layerGap),c=u(rd(s,a)),f=Xm(Yg(i)(c)(r)(o)(Q))(c);return M(d=>{const l=Q2(d)(f);return l.tag==="Just"&&l._1>0?Nn(a)(2+rt(l._1-1|0)*2.5):a})(It(0,s-1|0))},ff=t=>e=>n=>r=>Ma(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),$2=t=>e=>n=>r=>{const i=kt(o=>u=>ut.compare(o.w)(u.w))(M(o=>({l:o,w:cf(o)}))(st(ff()(e)(n),r)));return 0<i.length?v("Just",i[0].l):T},X2=t=>e=>{const n=Jn(Fe(M(At(i=>o=>b(o,i)))(t))),r=i=>kt(o=>u=>it.compare((()=>{const s=ot(o)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})())((()=>{const s=ot(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(i);return{preds:(()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Mt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(J(o=>u=>vt(C)(te)(u.to.node)([u.from.node])(o))(Q)(e))})(),succs:(()=>{const i=o=>{if(o.tag==="Leaf")return Q;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(C)(te)(u.from.node)([u.to.node])(o))(Q)(e))})(),nodeIndex:n}},Y2=t=>e=>{const n=kt(d=>l=>ut.compare(d.w)(l.w))(At(d=>l=>({i:d,l,w:cf(l)}))(e)),r=0<n.length?v("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?v("Just",e[i]):T,u=(()=>{if(o.tag==="Just")return(d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const y=_,x=h;if(x.tag==="Nil"){p=!1,m=y;continue}if(x.tag==="Cons"){_=nn(y)(x._1),h=x._2;continue}g()}return m})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,qt("Cons",l._4,d(l._6,_)));g()};return d(o._1,Ht)})());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?v("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 Q;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=>Vn(d)(2)===0?u-(_=>h=>{let p=_,m=h,y=!0,x;for(;y;){const N=p,w=m;if(w.tag==="Nil"){y=!1,x=N;continue}if(w.tag==="Cons"){p=nn(N)(w._1),m=w._2;continue}g()}return x})(999999)((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,qt("Cons",h._4,_(h._6,p)));g()};return _(l,Ht)})()):c-s(l))(e));return B2(J(d=>l=>{const _=kt(ut.compare)(xt(ot(l))(f));return K(C)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(Q)(Tr(C.compare)(Fe(M(d=>{const l=_=>{if(_.tag==="Leaf")return Q;if(_.tag==="Node")return Mt("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));g()};return Ct(Oe.foldr,l(d))})(f)))))},V2=t=>e=>n=>r=>i=>o=>{const u=X2(e)(i),s=M2(u)(e),a={nodeGap:t.nodeGap*4|0},c=Ee(C.compare,Le,Jn(M(_=>b(_,b(1,1)))(st(jg,Fe(e)))),(()=>{const _=h=>{if(h.tag==="Leaf")return Q;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=[Fo(a)(u)(e)(c)(r)(i)(o)(s)(rf)(uf),Fo(a)(u)(e)(c)(r)(i)(o)(s)(of)(uf),Fo(a)(u)(e)(c)(r)(i)(o)(s)(rf)(sf),Fo(a)(u)(e)(c)(r)(i)(o)(s)(of)(sf)],d=Y2(c)(f);if(ff()(e)(c)(d))return d;const l=$2()(e)(c)(f);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return f[0];g()},U2=t=>e=>n=>r=>{const i=Ba(T,Da,o=>o.node===e?v("Just",o.position):T,t);if(i.tag==="Nothing")return t;if(i.tag==="Just"){const o=i._1;return M(u=>u.node===n?{...u,position:b(o._1+r._1,o._2+r._2)}:u)(t)}g()},j2=t=>e=>n=>r=>{const i=st(u=>ze(fn)(u.node)(e),t),o=(()=>{if(n==="Vertical"){if(r==="Start")return J(u=>s=>nn(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=>nn(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 M(u=>{if(ze(fn)(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)},Z2=t=>e=>J(n=>r=>r.tag==="AlignGroup"?j2(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?U2(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),K2=t=>e=>n=>r=>i=>o=>u=>s=>{const a=M(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=V2(t)(n)(r)(i)(o)(s),f=gf(H2(t)(n)(r)(i)(o)(u)(d=>{const l=gf(d)(a);return Fe(At(_=>h=>At(p=>m=>({node:m,position:b((()=>{const y=ot(m)(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)(m)==="$d:"?b(0,1):b(1,1),x=ot(m)(r);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;g()})(),layer:_,order:p}))(h))(n))}))(a);return Z2(e)(Fe(At(d=>l=>At(_=>h=>({node:h,position:b((()=>{const p=ot(h)(c);return(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})()/rt(4)})(),d>=0&&d<f.length?f[d]:0),size:(()=>{const p=me(3)(h)==="$d:"?b(0,1):b(1,1),m=ot(h)(r);if(m.tag==="Nothing")return p;if(m.tag==="Just")return m._1;g()})(),layer:d,order:_}))(l))(n)))},Bs=Mu(so)(_r(32)),_f=Mu(so)(_r(31)),Di=(()=>{const t=ml("25214903917");if(t.tag==="Nothing")return uc;if(t.tag==="Just")return t._1;g()})(),Ii=Ou(Mu(so)(_r(48)))(so),ty=t=>{const e=yl(t);return _i(sc((()=>{if(e.tag==="Nothing")return uc;if(e.tag==="Just")return e._1;g()})())(Di))(Ii)},zs=_r(11),Bo=t=>e=>{const n=_i(oo(uo(e)(Di))(zs))(Ii);return b((()=>{const r=Ya(dl(qu(n)(_r(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},ey=t=>{const e=Bo(26)(t),n=Bo(27)(e._2);return b((rt(e._1)*bu(2)(27)+rt(n._1))/bu(2)(53),n._2)},ny=t=>e=>{const n=J(r=>i=>{const o=ey(r.finalR);return{rs:[...r.rs,o._1],finalR:o._2}})({rs:[],finalR:t})(e);return b(M(r=>r.x)(kt(r=>i=>ut.compare(r.k)(i.k))(Je(r=>i=>({x:r,k:i}),e,n.rs))),n.finalR)},ry=t=>{const e=_i(oo(uo(t)(Di))(zs))(Ii),n=_i(oo(uo(e)(Di))(zs))(Ii);return b(oo(uo((()=>{const r=qu(e)(_r(16));return ac.compare(r)(_f)!=="LT"?Ou(r)(Bs):r})())(Bs))((()=>{const r=qu(n)(_r(16));return ac.compare(r)(_f)!=="LT"?Ou(r)(Bs):r})()),n)},Qi=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=v("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=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Ws=Kt(C)(zt),Or=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=v("Just",o._4);continue}}g()}return i},Wo=Kt(C)(zt),iy=wu(ei),oy=J(vr)(0),uy=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},df=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},sy=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const i=$n(Xt,T,t,n[e],n);if(i.tag==="Just")return $n(Xt,T,e,r,i._1);if(i.tag==="Nothing")return T;g()}}return T},ay=t=>e=>n=>r=>i=>Ws(J(o=>u=>{const s=kt(a=>c=>it.compare((()=>{const f=Qi(a.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})())((()=>{const f=Qi(c.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})()))(st(a=>zo(a.to.node)(n),st(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),cy=t=>e=>n=>r=>i=>Ws(J(o=>u=>{const s=kt(c=>f=>{const d=it.compare((()=>{const l=Or(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=Or(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=Qi(c.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})())((()=>{const l=Qi(f.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})()):d})(st(c=>zo(c.from.node)(n),st(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),Os=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=Or(s.from.node)(r),c=Or(s.to.node)(i);if(a.tag==="Just"&&c.tag==="Just")return v("Just",b(a._1,c._1));const f=Or(s.from.node)(i),d=Or(s.to.node)(r);return f.tag==="Just"&&d.tag==="Just"?v("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)(It(a+1|0,u-1|0)))(0)(It(0,u-2|0))},gy=t=>e=>n=>r=>{const i=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l>=(d.length-1|0)){c=!1,f=d;continue}if(l>=0&&l<d.length){const _=l+1|0;if(_>=0&&_<d.length){const h=d[l],p=d[_];if(Be(N=>N.before===h&&N.after===p,r)){s=d,a=l+1|0;continue}const m=$n(Xt,T,l,p,d),y=(()=>{if(m.tag==="Just")return $n(Xt,T,l+1|0,h,m._1);if(m.tag==="Nothing")return T;g()})(),x=(()=>{if(y.tag==="Nothing")return d;if(y.tag==="Just")return y._1;g()})();if(Os(e)(x)(n)<Os(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(iy(f)(c)){s=!1,a=c;continue}u=f}return a})(t)},Oo=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+Os(i)(t[o])(e)|0}return n})(0)(It(0,t.length-2|0)),fy=(()=>{const t=e=>{if(e.length<7){const o=u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=_-1|0;if(h>=0&&h<l.length){if(_>=0&&_<l.length&&_>0&&l[h].key>l[_].key){const p=sy(_-1|0)(_)(l);if(p.tag==="Just"){a=p._1,c=_-1|0;continue}if(p.tag==="Nothing"){f=!1,d=l;continue}g()}f=!1,d=l;continue}f=!1,d=l}return d};return J(u=>s=>o(u)(s))(e)(It(1,e.length-1|0))}const n=kn(e.length,2),r=t(bt(0,n,e)),i=t(bt(n,e.length,e));return(o=>u=>s=>{let a=o,c=u,f=s,d=!0,l;for(;d;){const _=a,h=c,p=f;if(h>=0&&h<r.length){if(p>=0&&p<i.length){if(r[h].key>i[p].key){a=Wt(_)(i[p]),c=h,f=p+1|0;continue}a=Wt(_)(r[h]),c=h+1|0,f=p;continue}d=!1,l=[..._,...h<1?r:bt(h,r.length,r)];continue}d=!1,l=[..._,...p<1?i:bt(p,i.length,i)]}return l})([])(0)(0)};return t})(),_y=t=>e=>n=>{const r=xt(c=>c.tag==="OrderConstraint"?v("Just",{before:c._1.before,after:c._1.after}):T)(t.constraints),i=c=>J(f=>d=>{const l=d.after,_=d.before,h=ur(Xt,T,m=>m===_,f),p=ur(Xt,T,m=>m===l,f);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=Oa(Xt,T,h._1,f),y=(()=>{if(m.tag==="Nothing")return f;if(m.tag==="Just")return m._1;g()})(),x=Wa(Xt,T,p._1,_,y);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;g()}return f})(c)(r),o=Ws(At(c=>f=>b(f.id,c))(n)),u=(c,f,d)=>{const l=c.length;return J(_=>h=>{const p=f?h-1|0:h+1|0,m=p>=0&&p<_._1.length?v("Just",_._1[p]):T;if(m.tag==="Just"){const y=h>=0&&h<_._1.length?v("Just",_._1[h]):T;if(y.tag==="Just"){const x=Wo(At(E=>B=>b(B,E))(m._1)),N=Wo(At(E=>B=>b(B,E))(y._1)),w=f?ay(m._1)(x)(N)(n)(o):cy(m._1)(x)(N)(n)(o),k=J(E=>B=>{const X=xt(S=>Qi(S.id)(w))(st(f?S=>S.to.node===B._2&&zo(S.from.node)(x):S=>S.from.node===B._2&&zo(S.to.node)(x),n));if(X.length===0)return{...E,items:[...E.items,{n:B._2,key:T,origIdx:B._1}]};const et=Bo(24)(E.r);return{items:[...E.items,{n:B._2,key:v("Just",(oy(X)+(rt(et._1)*4172325152040912e-24-.03500000014901161))/rt(X.length)),origIdx:B._1}],r:et._2}})({items:[],r:_._2})(At(En)(y._1)),L=$n(Xt,T,h,gy(i(M(E=>E.n)(fy((()=>{const E=k.items,B=X=>et=>{let S=X,P=et,V=!0,U;for(;V;){const O=S,z=P;if(O>=0&&O<E.length){if(E[O].key.tag==="Just"){V=!1,U=E[O].key._1;continue}if(E[O].key.tag==="Nothing"){S=O+1|0,P=z;continue}g()}V=!1,U=z}return U};return(X=>et=>S=>{let P=X,V=et,U=S,O=!0,z;for(;O;){const F=P,G=V,D=U;if(F>=0&&F<E.length){if(E[F].key.tag==="Just"){P=F+1|0,V=E[F].key._1,U=[...D,{n:E[F].n,key:E[F].key._1,origIdx:E[F].origIdx}];continue}if(E[F].key.tag==="Nothing"){const I=(G+B(F+1|0)(G+1))/2;P=F+1|0,V=I,U=[...D,{n:E[F].n,key:I,origIdx:E[F].origIdx}];continue}g()}O=!1,z=D}return z})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(L.tag==="Just")return b(L._1,k.r);if(L.tag==="Nothing")return b(_._1,_._2);g()}if(y.tag==="Nothing")return b(_._1,_._2);g()}if(m.tag==="Nothing")return b(_._1,_._2);g()})(b(c,d))(f?It(1,l-1|0):Ne(It(0,l-2|0)))},s=J(c=>f=>K(C)(f.from.node)()(K(C)(f.to.node)()(c)))(Q)(n),a=J(c=>f=>{if(c.result.crossings===0)return c;const d=x=>N=>w=>k=>{let L=x,E=N,B=w,X=k,et=!0,S;for(;et;){const P=L,V=E,U=B,O=X;if(U===0){et=!1,S={layout:P,crossings:0,random:O};continue}const z=u(P,V,O),F=Oo(z._1)(n);if(F<U){L=z._1,E=!V,B=F,X=z._2;continue}et=!1,S={layout:P,crossings:U,random:z._2}}return S},l=Bo(1)(c.result.random),_=l._1!==0,h=t.modelOrder.tag==="Leaf",p=(c.firstTry||c.secondTry)&&!h?c.firstTry:_,m=(()=>{if(!h){const k=u(e,p,l._2);return d(k._1)(!p)(Oo(k._1)(n))(k._2)}const x=p?0:uy(0)(e.length-1|0),N=x>=0&&x<e.length?v("Just",e[x]):T;if(N.tag==="Just"&&N._1.length>1){const k=st(L=>df(L)(s),N._1);if(k.length>1){const L=ny(l._2)(k),E=L._1,B=$n(Xt,T,x,i(J(X=>et=>df(et)(s)?X.idx>=0&&X.idx<E.length?{idx:X.idx+1|0,result:[...X.result,E[X.idx]]}:{idx:X.idx,result:[...X.result,et]}:{idx:X.idx,result:[...X.result,et]})({idx:0,result:[]})(N._1).result),e);if(B.tag==="Just"){const X=u(B._1,p,L._2);return d(X._1)(!p)(Oo(X._1)(n))(X._2)}}}const w=u(e,p,l._2);return d(w._1)(!p)(Oo(w._1)(n))(w._2)})(),y=c.secondTry?!1:c.secondTry;return c.firstTry?{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:c.firstTry,secondTry:y}})({result:{layout:e,crossings:1e9,random:_i(sc(ry(ty(1))._1)(Di))(Ii)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(It(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:a.layout},dy=t=>t,lf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},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=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=v("Just",o._4);continue}}g()}return i},Mr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Ai=(()=>{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"?ye:r==="GT"?xe:C.compare(e._2)(n._2)},Eq0:()=>t}})(),ly=Kt(C)(zt),hy=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=Ai.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},py=dy("Greedy"),Ms=t=>e=>n=>J(r=>i=>{if(i.from.node===i.to.node)return r;if(i.from.node===e&&!lf(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(C)(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()})()&&!ze(fn)(i.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,i.to.node]}:{...r,inDeg:s}}if(i.to.node===e&&!lf(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(C)(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()})()&&!ze(fn)(i.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,i.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:st(r=>r!==e,n.remaining)})(t),my=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})(Q),hf=t=>e=>n=>{const r=De(e)(t),i=De(n)(t);return r.tag==="Just"&&i.tag==="Just"&&r._1>i._1},pf=t=>e=>n=>r=>{if(Mr(n)(r.visited)||Mr(n)(r.visiting))return r;const i=J(yy(t)(e)(n))({...r,visiting:K(C)(n)()(r.visiting)})((()=>{const o=De(n)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})());return{...i,visiting:ii(C)(n)(i.visiting),visited:K(C)(n)()(i.visited)}},yy=t=>e=>n=>r=>i=>hf(t)(n)(i)?{...r,backEdges:K(Ai)(b(n,i))()(r.backEdges)}:Mr(i)(r.visiting)?{...r,backEdges:K(Ai)(b(n,i))()(r.backEdges)}:Mr(i)(r.visited)?r:pf(t)(e)(i)(r),xy=t=>e=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,y=Rt(x=>T,x=>N=>v("Just",{head:x,tail:N}),m.sinks);if(y.tag==="Just"){_=Ms(n)(y._1.head)({...m,sinks:y._1.tail,marks:K(C)(y._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(y.tag==="Nothing"){const x=Rt(N=>T,N=>w=>v("Just",{head:N,tail:w}),m.sources);if(x.tag==="Just"){_=Ms(n)(x._1.head)({...m,sources:x._1.tail,marks:K(C)(x._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(x.tag==="Nothing"){const N=k=>{const L=De(k)(m.outDeg),E=De(k)(m.inDeg);return(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;g()})()-(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;g()})()|0},w=kt(k=>L=>{const E=it.compare(N(L))(N(k));return E==="EQ"?it.compare((()=>{const B=De(k)(e);if(B.tag==="Nothing")return 1e6;if(B.tag==="Just")return B._1;g()})())((()=>{const B=De(L)(e);if(B.tag==="Nothing")return 1e6;if(B.tag==="Just")return B._1;g()})()):E})(m.remaining);if(0<w.length){const k=w[0];_=Ms(n)(k)({...m,remaining:st(L=>L!==k,m.remaining),marks:K(C)(k)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}g()}return p},i=Tr(C.compare)([...M(l=>l.from.node)(n),...M(l=>l.to.node)(n)]),o=st(l=>l.from.node!==l.to.node,n),u=J(l=>_=>vt(C)(oe)(_.to.node)(1)(l))(Q)(o),s=J(l=>_=>vt(C)(oe)(_.from.node)(1)(l))(Q)(o),a=st(l=>{const _=De(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),c=st(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(C)(_)(h._1+f|0)(l):l})(r({remaining:st(l=>!ze(fn)(l)(a)&&!ze(fn)(l)(c),i),marks:Q,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(hf(t)(_.from.node)(_.to.node))return K(Ai)(b(_.from.node,_.to.node))()(l);const h=De(_.from.node)(d),p=De(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?K(Ai)(b(_.from.node,_.to.node))()(l):l})(Q)(n)},Ny=J(t=>e=>vt(C)(te)(e.from.node)([e.to.node])(t))(Q),Jy=t=>e=>{const n=Ny(e),r=Tr(C.compare)([...M(o=>o.from.node)(e),...M(o=>o.to.node)(e)]),i=J(o=>u=>K(C)(u.to.node)()(o))(Q)(e);return J(o=>u=>pf(t)(n)(u)(o))({visiting:Q,visited:Q,backEdges:Q})([...st(o=>!Mr(o)(i),r),...st(o=>Mr(o)(i),r)]).backEdges},Ty=t=>e=>n=>r=>{const i=ly(At(s=>a=>b(a,s))(e)),o=my(n),u=(()=>{if(t==="DepthFirst")return Jy(o)(r);if(t==="Greedy")return xy(o)(i)(r);g()})();return{edges:M(s=>hy(b(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},mf=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},wy=J(t=>e=>K(C)(e)()(t))(Q),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}}g()}return i},vy=Pg(C),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=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=v("Just",o._4);continue}}g()}return i},yf=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},qs=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=v("Just",o._4);continue}}g()}return i},by=Kt(it)(zt),Ly=t=>e=>Ee(C.compare,Le,t,e),xf=At(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),ky=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=mf(f)(d._1),s=d._2;continue}g()}return c};return(e.base+r(0)((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,qt("Cons",o._4,i(o._6,u)));g()};return i(n,Ht)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=i=>{if(i.tag==="Leaf")return Q;if(i.tag==="Node")return 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,Ey=t=>e=>{const n=wy(t);return vy(t)(xf(st(r=>Mo(r.src)(n)&&Mo(r.tgt)(n),e)))},Cy=t=>e=>{const n=J(i=>o=>vt(C)(te)(o.tgt)([o.src])(vt(C)(te)(o.src)([o.tgt])(i)))(Q)(e),r=i=>o=>u=>{let s=i,a=o,c=u,f=!0,d;for(;f;){const l=s,_=a,h=c,p=Rt(m=>T,m=>y=>v("Just",{head:m,tail:y}),l);if(p.tag==="Nothing"){f=!1,d={nodes:h};continue}if(p.tag==="Just"){if(Mo(p._1.head)(_)){s=p._1.tail,a=_,c=h;continue}s=[...p._1.tail,...(()=>{const m=Tn(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()})()],a=K(C)(p._1.head)()(_),c=[...h,p._1.head];continue}g()}return d};return J(i=>o=>{if(Mo(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:Q,components:[]})(t).components},Sy=t=>e=>n=>{const r=J(o=>u=>vt(C)(oe)(u.tgt)(1)(o))(Q)(e),i=J(o=>u=>vt(C)(oe)(u.src)(1)(o))(Q)(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:yf(x.mIn)((()=>{const w=Tn(u)(d),k=Tn(N.src)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;g()})()-(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;g()})()|0})())}:N.src===u?{...x,mOut:yf(x.mOut)((()=>{const w=Tn(N.tgt)(d),k=Tn(u)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;g()})()-(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;g()})()|0})())}:x)({mIn:1e9,mOut:1e9})(e),_=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(_<0||h<0)return o;const p=(f-_|0)+1|0,m=(f+h|0)-1|0;if(m<p)return o;const y=J(x=>N=>{const w=qs(N)(o.filling),k=(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;g()})();return k<x.bestFill?{best:N,bestFill:k}:x})({best:f,bestFill:(()=>{const x=qs(f)(o.filling);if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})()})(It(p,m));return y.best===f?o:{layers:K(C)(u)(y.best)(o.layers),filling:K(it)(f)((()=>{const x=qs(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:by(M(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)))(It(0,J(o=>u=>mf(o)((()=>{const s=Tn(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(0)(t))))})(t).layers},Gy=t=>e=>Sy(t)(xf(e))(J(Ly)(Q)(ky(M(n=>Ey(n)(e))(Cy(t)(e))))),Py=t=>t,pr=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=v("Just",o._4);continue}}g()}return i},qo=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Nf=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Dy=Py("NetworkSimplex"),Iy=t=>e=>J(n=>r=>{const i=J(qo)(0)(xt(o=>pr(o)(n))(r));return J(o=>u=>K(C)(u)(i)(o))(n)(r)})(e)(t),Qy=t=>e=>({layers:M(n=>st(r=>{const i=pr(r)(e);return i.tag==="Nothing"?!1:i.tag==="Just"&&i._1===n},t))(It(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=qo(a)(c._1),o=c._2;continue}g()}return s})(0)((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return n(e,Ht)})()))),nodeLayer:e}),Ay=t=>e=>n=>{const r=J(i=>o=>K(C)(o)(!0)(i))(Q)(e);return J(i=>o=>K(C)(o._1)(o._2)(i))(Gy(e)(xt(i=>i.from.node===i.to.node||(()=>{const o=pr(i.from.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()||(()=>{const o=pr(i.to.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()?T:v("Just",{src:i.from.node,tgt:i.to.node}))(t)))(Nf(n))},Ry=t=>e=>n=>r=>{const i=s=>a=>{const c=pr(a)(s);if(c.tag==="Just")return s;if(c.tag==="Nothing"){const f=st(l=>l!==a,(()=>{const l=pr(a)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;g()})()),d=J(i)(s)(f);return K(C)(a)(1+J(qo)(0)(xt(l=>pr(l)(d))(f))|0)(d)}g()},o=J(i)(Q)(n),u=(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=qo(_)(h._1),f=h._2;continue}g()}return l})(1)((()=>{const s=(a,c)=>{if(a.tag==="Leaf")return c;if(a.tag==="Node")return s(a._5,qt("Cons",a._4,s(a._6,c)));g()};return s(o,Ht)})());return J(s=>a=>K(C)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return Q;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)})())(Nf(r))},Fy=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})(Q),By=J(t=>e=>vt(C)(te)(e.to.node)([e.from.node])(t))(Q),zy=J(t=>e=>vt(C)(te)(e.from.node)([e.to.node])(t))(Q),Wy=t=>e=>n=>r=>{const i=zy(n),o=By(n),u=Fy(e);return Qy(r)(Iy(xt(s=>s.tag==="SameLayer"?v("Just",s._1.nodes):T)(e))((()=>{if(t==="LongestPath")return Ry(i)(o)(r)(u);if(t==="NetworkSimplex")return Ay(n)(r)(u);g()})()))},Oy=Kt(C)(zt),My=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=v("Just",o._4);continue}}g()}return i},Jf=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=v("Just",o._4);continue}}g()}return i},Tf=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ri=Kt(C)(zt),qy=Kt(C)(zt),wf=(()=>{const t=M(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>Ne(t(e))})(),Hy=t=>e=>n=>r=>{const i=Oy(M(u=>b(u.edge,u))(r)),o=u=>0<u.nodes.length&&(()=>{const s=My(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return M(u=>{if(u.nodes.length<=2){const f=Jf(u.edgeId)(i);if(f.tag==="Just"){const d=o(u),l=Ci(Ei(d?wf(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=>Jf(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=Ci(Ei(a?wf(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)},$y={layers:[],edges:[],chains:[]},Xy={nodeGap:3,layerGap:2,iterations:8,layerer:Dy,cycleBreaker:py,compactPostRouting:!0},Yy=t=>({pos:b(0,0),size:b(J(e=>n=>Tf(e)(n.position._1+n.size._1))(0)(t),J(e=>n=>Tf(e)(n.position._2+n.size._2))(0)(t))}),Vy=t=>e=>n=>{const r=Ri(M(c=>b(c.id,c.ports))(e.nodes)),i=st(c=>me(3)(c.node)!=="$d:",n.placements),o=Hy(n.withDummies.chains)(n.acyclic.reversedEdges)(qy(M(c=>b(c.id,b(c.from.node,c.to.node)))(e.edges)))(N2(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(Kg(n.ordered)(st(c=>c.from.node!==c.to.node,n.withDummies.edges))((()=>{const c=f=>{if(f.tag==="Leaf")return Q;if(f.tag==="Node")return 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(Ri(M(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=M(c=>{const f=Ci(Ei(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:k2(c)(f)(s)}))(s);return{nodes:u.nodes,edges:a,boundingBox:Yy(u.nodes),metrics:hp(u.nodes)(a)(0)}},Uy=t=>e=>n=>{const r=Ri(M(o=>b(o.id,o.size))(e.nodes)),i={...n,placements:K2({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(Ri(M(o=>b(o.id,o.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(Kg(n.ordered)(n.withDummies.edges)((()=>{const o=u=>{if(u.tag==="Leaf")return Q;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:Vy(t)(e)(i)}},jy=t=>e=>n=>Uy(t)(e)({...n,ordered:_y({iterations:t.iterations,constraints:e.constraints,modelOrder:Ri(At(r=>i=>b(i.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),Zy=t=>e=>n=>jy(t)(e)({...n,withDummies:E2(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),Ky=t=>e=>{const n=M(i=>i.id)(e.nodes),r=Ty(t.cycleBreaker)(n)(e.constraints)(e.edges);return Zy(t)(e)({acyclic:r,layered:Wy(t.layerer)(e.constraints)(r.edges)(n),withDummies:$y,ordered:[],placements:[]})},Ho=t=>t,tx=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Hs=Ho("TopSide"),$s=Ho("BottomSide"),Xs=Ho("LeftSide"),Ys=Ho("RightSide"),ex=t=>{const e=ut.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ut.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},vf=t=>e=>n=>{const r=tx(t.h*.12)(t.w*.2),i=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*ke(ex((()=>{const o=(n-(t.x+i))/i;return 1-o*o})()))},nr=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=Zn,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=Zn,o=d,u=l,s=_}return c},bf=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?Hs:c<=s&&c<=o?$s:s<=o?Xs:Ys},Vs=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=v("Just",o._4);continue}}g()}return i},Fi=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=v("Just",o._4);continue}}g()}return i},nx=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),$o=Kt(C)(zt),rx=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},ix=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},ox=J(t=>e=>K(C)(e)()(t))(Q),ux=J(t=>e=>K(C)(e)()(t))(Q),Xo=or.traverse(Nu),Yo=Kt(C)(zt),sx=t=>e=>Ee(C.compare,Le,t,e),ax=J(t=>e=>K(C)(e)()(t))(Q),cx=Kt(C)(zt),gx=t=>e=>Ee(C.compare,Le,t,e),fx=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=v("Just",o._4);continue}}g()}return i},Lf=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},_x=t=>e=>({...e,edges:$o(M(n=>b(n._1,(()=>{const r=Vs(n._1)(t);if(r.tag==="Nothing")return n._2;if(r.tag==="Just"){const i=Fi(r._1._2)(e.nodes),o=Fi(r._1._1)(e.nodes),u=(()=>{if(o.tag==="Nothing")return n._2;if(o.tag==="Just"){const s=Rt(a=>T,a=>c=>v("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=bf(a)(s._1.head);return[(()=>{if(c==="TopSide")return{...s._1.head,y:nr(o._1.shape)(a)(Hs)(s._1.head.x)};if(c==="BottomSide")return{...s._1.head,y:nr(o._1.shape)(a)($s)(s._1.head.x)};if(c==="LeftSide")return{...s._1.head,x:nr(o._1.shape)(a)(Xs)(s._1.head.y)};if(c==="RightSide")return{...s._1.head,x:nr(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=ni(u);if(s.tag==="Nothing")return u;if(s.tag==="Just")return Wt(s._1.init)((()=>{const a={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},c=bf(a)(s._1.last);if(c==="TopSide")return{...s._1.last,y:nr(i._1.shape)(a)(Hs)(s._1.last.x)};if(c==="BottomSide")return{...s._1.last,y:nr(i._1.shape)(a)($s)(s._1.last.x)};if(c==="LeftSide")return{...s._1.last,x:nr(i._1.shape)(a)(Xs)(s._1.last.y)};if(c==="RightSide")return{...s._1.last,x:nr(i._1.shape)(a)(Ys)(s._1.last.y)};g()})())}}g()})()))(nx(e.edges)))}),dx=t=>e=>n=>{const r=Vt(i=>i.id===n)(t.graph.edges);if(r.tag==="Just")return v("Just",r._1);if(r.tag==="Nothing")return Vs(n)(e);g()},lx=t=>e=>n=>r=>({x:r.position._1*t,y:r.position._2*t,w:r.size._1*t,h:r.size._2*t,label:(()=>{const i=Fi(r.node)(e);if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return r.node;g()})(),shape:(()=>{const i=Fi(r.node)(n);if(i.tag==="Nothing")return Zn;if(i.tag==="Just")return i._1;g()})()}),hx=t=>({id:t,size:b(1,1),ports:[],label:v("Just",t),shape:Zn}),px=t=>e=>n=>r=>b(r.node,lx(t)(e)(n)(r)),kf=t=>{const e=lo(`
|
|
6
|
+
`)(t);return e.length===0?[""]:e},Ef=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,qt("Cons",n._4,e(n._6,r)));g()};return Ct($t.foldr,e(t.interiors,Ht))},mx=t=>$o(xt(e=>v("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"?v("Just",n.kind._1):T)(e._1.events):[]))),Cf=t=>{const e=Ql(t),n=st(i=>rx(i.id)(e.nodes),t.graph.nodes),r=st(i=>ix(i.id)(e.edges),t.graph.edges);return{nodes:[...n,...M(hx)(Ct(Oe.foldr,Cn(C.compare,e.nodes,ox(M(i=>i.id)(n)))))],edges:[...r,...xt(dx(t)(mx(t)))(Ct(Oe.foldr,Cn(C.compare,e.edges,ux(M(i=>i.id)(r)))))],constraints:t.graph.constraints}},yx=t=>{const e=Xo(n=>{const r=og(ug)((()=>{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)}})(Cf(t).nodes);return()=>{const n=e();return Yo(n)}},Sf=t=>{const e=yx(t);return()=>{const n=e(),r=Xo(Sf)(Ef(t))();return J(sx)(n)(r)}},xx=t=>e=>{const n=Rt(r=>T,r=>i=>v("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},...M(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];g()},Nx=t=>e=>b(e.edge,xx(t)(e)),Jx=t=>e=>n=>r=>({nodes:Yo(M(px(rt(4)*t)(e)(n))(r.nodes)),edges:$o(M(Nx(t))(r.edges)),chipExtras:Q}),Tx=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(C)(u)()(o))(r)(i.kind._1.labels);if(i.kind.tag==="FillNodeWithoutTransition")return J(o=>u=>K(C)(u)()(o))(r)(i.kind._1.labels);g()})(e)(n._1.events);if(n.tag==="EnterNode"||n.tag==="ExitNode")return e;g()})(Q)(t.scenes),wx=t=>{const e=Xo(n=>{const r=og(ug)(n);return()=>{const i=r();return b(n,{labelW:i,charCount:jn(Qr(n)),lineCount:1})}})(Ct(Oe.foldr,ax(Tt(Ct(Oe.foldr,Tx(t)))(kf))));return()=>{const n=e();return cx(n)}},Gf=t=>{const e=wx(t);return()=>{const n=e(),r=Xo(Gf)(Ef(t))();return J(gx)(n)(r)}},vx=rt(4)*8,bx=t=>e=>{const n=_p(vx)(t)(fp(gp)(Cf(e)));return _x($o(M(r=>b(r.id,b(r.from.node,r.to.node)))(n.edges)))(Jx(8)(Yo(M(r=>b(r.id,(()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;g()})()))(n.nodes)))(Yo(M(r=>b(r.id,r.shape))(n.nodes)))(Ky(Xy)(n).result))},Lx=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()}),kx=t=>e=>n=>{const r=i=>{const o=xt(u=>{const s=fx(u)(t);return s.tag==="Just"?v("Just",{w:s._1.labelW+28,h:rt(op(1)(s._1.lineCount))*13.2+12}):T})(Tt(i)(kf));return o.length===0?T:v("Just",{w:J(Lf)(0)(M(u=>u.w)(o)),h:J(Lf)(0)(M(u=>u.h)(o))})};return J(i=>o=>{if(o.kind.tag==="SendToken"){const u=Vs(o.kind._1.edge)(n.edges),s=r(o.kind._1.labels);if(s.tag==="Just"&&u.tag==="Just"){const a=s._1;return vt(C)(te)(o.kind._1.edge)(M(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=Fi(o.kind._1.node)(n.nodes),s=r(o.kind._1.labels);return s.tag==="Just"&&u.tag==="Just"?vt(C)(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()})(Q)(Lx(e))},Pf=t=>e=>n=>({layout:(()=>{const r=bx(t)(n);return{...r,chipExtras:kx(e)(n)(r)}})(),interiors:(()=>{const r=Pf(t)(e),i=o=>{if(o.tag==="Leaf")return Q;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)})()}),Df=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=v("Just",o._4);continue}}g()}return i},Us=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=Df(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(C)(s._3)({x:c.x+f*r,y:c.y+d*r,vx:f,vy:d})(i(u,s._5))})(),s._6);g()},o=i(Q,e);return{springs:o,applied:(()=>{const u=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return u((()=>{const c=u(s,a._5),f=Df(a._3)(o);if(f.tag==="Just")return K(C)(a._3)({...a._4,x:f._1.x,y:f._1.y})(c);if(f.tag==="Nothing")return K(C)(a._3)(a._4)(c);g()})(),a._6);g()};return u(Q,e)})()}};(function(){var t={},e="Pure",n="Throw",r="Catch",i="Sync",o="Async",u="Bind",s="Bracket",a="Fork",c="Sequential",f="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",y="Finalized",x="Forked";function N(A,H,$,Y){this.tag=A,this._1=H,this._2=$,this._3=Y}function w(A){var H=function($,Y,q){return new N(A,$,Y,q)};return H.tag=A,H}function k(A){return new N(e,void 0)}function L(A){try{A()}catch(H){setTimeout(function(){throw H},0)}}function E(A,H,$){try{return H($())}catch(Y){return A(Y)}}function B(A,H,$){try{return H($)()}catch(Y){return $(A(Y))(),k}}var X=(function(){var A=1024,H=0,$=0,Y=new Array(A),q=!1;function W(){var tt;for(q=!0;H!==0;)H--,tt=Y[$],Y[$]=void 0,$=($+1)%A,tt();q=!1}return{isDraining:function(){return q},enqueue:function(tt){var j;H===A&&(j=q,W(),q=j),Y[($+H)%A]=tt,H++,q||W()}}})();function et(A){var H={},$=0,Y=0;return{register:function(q){var W=$++;q.onComplete({rethrow:!0,handler:function(tt){return function(){Y--,delete H[W]}}})(),H[W]=q,Y++},isEmpty:function(){return Y===0},killAll:function(q,W){return function(){if(Y===0)return W();var tt=0,j={};function gt(at){j[at]=H[at].kill(q,function(yt){return function(){delete j[at],tt--,A.isLeft(yt)&&A.fromLeft(yt)&&setTimeout(function(){throw A.fromLeft(yt)},0),tt===0&&W()}})()}for(var _t in H)H.hasOwnProperty(_t)&&(tt++,gt(_t));return H={},$=0,Y=0,function(at){return new N(i,function(){for(var yt in j)j.hasOwnProperty(yt)&&j[yt]()})}}}}}var S=0,P=1,V=2,U=3,O=4,z=5,F=6;function G(A,H,$){var Y=0,q=S,W=$,tt=null,j=null,gt=null,_t=null,at=null,yt=0,St=0,Ft=null,pt=!0;function Bt(Z){for(var nt,ht,ft;;)switch(nt=null,ht=null,ft=null,q){case V:q=P;try{W=gt(W),_t===null?gt=null:(gt=_t._1,_t=_t._2)}catch(wt){q=z,tt=A.left(wt),W=null}break;case U:A.isLeft(W)?(q=z,tt=W,W=null):gt===null?q=z:(q=V,W=A.fromRight(W));break;case P:switch(W.tag){case u:gt&&(_t=new N(_,gt,_t)),gt=W._2,q=P,W=W._1;break;case e:gt===null?(q=z,W=A.right(W._1)):(q=V,W=W._1);break;case i:q=U,W=E(A.left,A.right,W._1);break;case o:q=O,W=B(A.left,W._1,function(wt){return function(){Y===Z&&(Y++,X.enqueue(function(){Y===Z+1&&(q=U,W=wt,Bt(Y))}))}});return;case n:q=z,tt=A.left(W._1),W=null;break;case r:gt===null?at=new N(_,W,at,j):at=new N(_,W,new N(_,new N(h,gt,_t),at,j),j),gt=null,_t=null,q=P,W=W._1;break;case s:yt++,gt===null?at=new N(_,W,at,j):at=new N(_,W,new N(_,new N(h,gt,_t),at,j),j),gt=null,_t=null,q=P,W=W._1;break;case a:q=U,nt=G(A,H,W._2),H&&H.register(nt),W._1&&nt.run(),W=A.right(nt);break;case c:q=P,W=I(A,H,W._1);break}break;case z:if(gt=null,_t=null,at===null)q=F,W=j||tt||W;else switch(nt=at._3,ft=at._1,at=at._2,ft.tag){case r:j&&j!==nt&&yt===0?q=z:tt&&(q=P,W=ft._2(A.fromLeft(tt)),tt=null);break;case h:j&&j!==nt&&yt===0||tt?q=z:(gt=ft._1,_t=ft._2,q=V,W=A.fromRight(W));break;case s:yt--,tt===null&&(ht=A.fromRight(W),at=new N(_,new N(p,ft._2,ht),at,nt),(j===nt||yt>0)&&(q=P,W=ft._3(ht)));break;case p:at=new N(_,new N(y,W,tt),at,j),q=P,j&&j!==nt&&yt===0?W=ft._1.killed(A.fromLeft(j))(ft._2):tt?W=ft._1.failed(A.fromLeft(tt))(ft._2):W=ft._1.completed(A.fromRight(W))(ft._2),tt=null,yt++;break;case m:yt++,at=new N(_,new N(y,W,tt),at,j),q=P,W=ft._1;break;case y:yt--,q=z,W=ft._1,tt=ft._2;break}break;case F:for(var Nt in Ft)Ft.hasOwnProperty(Nt)&&(pt=pt&&Ft[Nt].rethrow,L(Ft[Nt].handler(W)));Ft=null,j&&tt?setTimeout(function(){throw A.fromLeft(tt)},0):A.isLeft(W)&&pt&&setTimeout(function(){if(pt)throw A.fromLeft(W)},0);return;case S:q=P;break;case O:return}}function Jt(Z){return function(){if(q===F)return pt=pt&&Z.rethrow,Z.handler(W)(),function(){};var nt=St++;return Ft=Ft||{},Ft[nt]=Z,function(){Ft!==null&&delete Ft[nt]}}}function mt(Z,nt){return function(){if(q===F)return nt(A.right(void 0))(),function(){};var ht=Jt({rethrow:!1,handler:function(){return nt(A.right(void 0))}})();switch(q){case S:j=A.left(Z),q=F,W=j,Bt(Y);break;case O:j===null&&(j=A.left(Z)),yt===0&&(q===O&&(at=new N(_,new N(m,W(Z)),at,j)),q=z,W=null,tt=null,Bt(++Y));break;default:j===null&&(j=A.left(Z)),yt===0&&(q=z,W=null,tt=null)}return ht}}function ct(Z){return function(){var nt=Jt({rethrow:!1,handler:Z})();return q===S&&Bt(Y),nt}}return{kill:mt,join:ct,onComplete:Jt,isSuspended:function(){return q===S},run:function(){q===S&&(X.isDraining()?Bt(Y):X.enqueue(function(){Bt(Y)}))}}}function D(A,H,$,Y){var q=0,W={},tt=0,j={},gt=new Error("[ParAff] Early exit"),_t=null,at=t;function yt(Jt,mt,ct){var Z=mt,nt=null,ht=null,ft=0,Nt={},wt,Zt;t:for(;;)switch(wt=null,Z.tag){case x:if(Z._3===t&&(wt=W[Z._1],Nt[ft++]=wt.kill(Jt,function(Se){return function(){ft--,ft===0&&ct(Se)()}})),nt===null)break t;Z=nt._2,ht===null?nt=null:(nt=ht._1,ht=ht._2);break;case f:Z=Z._2;break;case d:case l:nt&&(ht=new N(_,nt,ht)),nt=Z,Z=Z._1;break}if(ft===0)ct(A.right(void 0))();else for(Zt=0,wt=ft;Zt<wt;Zt++)Nt[Zt]=Nt[Zt]();return Nt}function St(Jt,mt,ct){var Z,nt,ht,ft,Nt,wt;for(A.isLeft(Jt)?(Z=Jt,nt=null):(nt=Jt,Z=null);;){if(ht=null,ft=null,Nt=null,wt=null,_t!==null)return;if(mt===null){Y(Z||nt)();return}if(mt._3!==t)return;switch(mt.tag){case f:Z===null?(mt._3=A.right(mt._1(A.fromRight(nt))),nt=mt._3):mt._3=Z;break;case d:if(ht=mt._1._3,ft=mt._2._3,Z){if(mt._3=Z,Nt=!0,wt=tt++,j[wt]=yt(gt,Z===ht?mt._2:mt._1,function(){return function(){delete j[wt],Nt?Nt=!1:ct===null?St(Z,null,null):St(Z,ct._1,ct._2)}}),Nt){Nt=!1;return}}else{if(ht===t||ft===t)return;nt=A.right(A.fromRight(ht)(A.fromRight(ft))),mt._3=nt}break;case l:if(ht=mt._1._3,ft=mt._2._3,ht===t&&A.isLeft(ft)||ft===t&&A.isLeft(ht))return;if(ht!==t&&A.isLeft(ht)&&ft!==t&&A.isLeft(ft))Z=nt===ht?ft:ht,nt=null,mt._3=Z;else if(mt._3=nt,Nt=!0,wt=tt++,j[wt]=yt(gt,nt===ht?mt._2:mt._1,function(){return function(){delete j[wt],Nt?Nt=!1:ct===null?St(nt,null,null):St(nt,ct._1,ct._2)}}),Nt){Nt=!1;return}break}ct===null?mt=null:(mt=ct._1,ct=ct._2)}}function Ft(Jt){return function(mt){return function(){delete W[Jt._1],Jt._3=mt,St(mt,Jt._2._1,Jt._2._2)}}}function pt(){var Jt=P,mt=$,ct=null,Z=null,nt,ht;t:for(;;)switch(nt=null,ht=null,Jt){case P:switch(mt.tag){case f:ct&&(Z=new N(_,ct,Z)),ct=new N(f,mt._1,t,t),mt=mt._2;break;case d:ct&&(Z=new N(_,ct,Z)),ct=new N(d,t,mt._2,t),mt=mt._1;break;case l:ct&&(Z=new N(_,ct,Z)),ct=new N(l,t,mt._2,t),mt=mt._1;break;default:ht=q++,Jt=z,nt=mt,mt=new N(x,ht,new N(_,ct,Z),t),nt=G(A,H,nt),nt.onComplete({rethrow:!1,handler:Ft(mt)})(),W[ht]=nt,H&&H.register(nt)}break;case z:if(ct===null)break t;ct._1===t?(ct._1=mt,Jt=P,mt=ct._2,ct._2=t):(ct._2=mt,mt=ct,Z===null?ct=null:(ct=Z._1,Z=Z._2))}for(at=mt,ht=0;ht<q;ht++)W[ht].run()}function Bt(Jt,mt){_t=A.left(Jt);var ct;for(var Z in j)if(j.hasOwnProperty(Z)){ct=j[Z];for(Z in ct)ct.hasOwnProperty(Z)&&ct[Z]()}j=null;var nt=yt(Jt,at,mt);return function(ht){return new N(o,function(ft){return function(){for(var Nt in nt)nt.hasOwnProperty(Nt)&&nt[Nt]();return k}})}}return pt(),function(Jt){return new N(o,function(mt){return function(){return Bt(Jt,mt)}})}}function I(A,H,$){return new N(o,function(Y){return function(){return D(A,H,$,Y)}})}return N.EMPTY=t,N.Pure=w(e),N.Throw=w(n),N.Catch=w(r),N.Sync=w(i),N.Async=w(o),N.Bind=w(u),N.Bracket=w(s),N.Fork=w(a),N.Seq=w(c),N.ParMap=w(f),N.ParApply=w(d),N.ParAlt=w(l),N.Fiber=G,N.Supervisor=et,N.Scheduler=X,N.nonCanceler=k,N})();let If=null;function Ex(){return If||(typeof document>"u"?null:If=document.createElement("canvas").getContext("2d"))}const js=new Map;function Qf(t,e,n,r,i,o){const u=`${n} ${e}px ${t}`,s=u+"|"+r;if(js.has(s))return js.get(s);const a=Ex();if(!a)return o;a.font=u;const c=i(a.measureText(r)),f=typeof document<"u"?document.fonts:null;if(!f||f.check(u))js.set(s,c);else if(f&&f.load)try{f.load(u)}catch{}return c}const Cx=(t,e,n,r)=>Qf(t,e,n,r,i=>i.width,-1),Sx=(t,e,n,r)=>Qf(t,e,n,r,i=>({ascent:i.actualBoundingBoxAscent,descent:i.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),Af=t=>e=>{const n=Cx(t.family,t.size,t.weight,Qr(e));return n<0?rt(mo(e).length)*t.size*.62:n},Rf=t=>e=>{const n=Sx(t.family,t.size,t.weight,Qr(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},Ff=t=>t,Bf=t=>t,Vo=t=>t,zf=t=>t,Gx=t=>t,Wf=t=>t,Of=t=>t,Px=Of("BaselineTop"),qr=Of("BaselineMiddle"),Zs=Wf("AlignLeft"),Uo=Wf("AlignCenter"),Te=Gx("RoundJoin"),_n=zf("ButtCap"),An=zf("RoundCap"),Dx=Vo("LayerPolyOut"),Ix=Vo("LayerPolyIn"),Qx=Vo("LayerNodeMask"),Ax=Vo("LayerOverlay"),jo=Bf("NonZero"),Rx=Bf("EvenOdd"),Mf=Ff("Normal"),Zo=Ff("Difference"),re={r:255,g:255,b:255,a:255},Rn={r:26,g:26,b:26,a:255},Fx=t=>t,qf=t=>t,Bx=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},rn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Hf=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()},zx=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},Wx=qf("FlatLevel"),Ox=qf("NestedLevel"),$f=Fx("GenieSilhouette"),Mx=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const i=Pr(t);return{prng:i.prng,yLift:i.value*n.yJitter*r}},qx=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const i=Pr(t);return{prng:i.prng,dx:(i.value*2-1)*n.xJitter*r}},Xf=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,i=ke(r*r+n*n),o=(t.r*t.r-e.r*e.r+i*i)/(2*i),u=ke(Bx(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},Hx=t=>e=>{const n=rn(e)(rn(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]},$x=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=Pr(t);return{prng:u.prng,r:i*(1+u.value*o.rJitter)}},Yf=t=>{const e=rn(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]},Xx=t=>e=>n=>{const r=Pr(t),i=e.length;return i===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const o=Hf(0)(i-1|0)(de(ln(r.value*rt(n))));return o>=0&&o<e.length?e[o]:-1})()}},Yx=t=>e=>{const n=Pr(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const i=Hf(0)(r-1|0)(de(ln(n.value*rt(r))));return i>=0&&i<e.length?e[i]:-1})()}},Vf=t=>{const e=rn(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]},Uf=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],jf={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},Vx=t=>{const e=rn(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]},Zf=t=>{const e=rn(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]},Kf=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?It(1,u-2|0):[],a=s.length,c=kn(a+1|0,2),f=c<1?[]:bt(0,c,s),d=Yx(t.seed)((()=>{const m=a-c|0;return m<1?s:bt(m,s.length,s)})()),l=d.idx,_=Xx(d.prng)(st(m=>m!==l,f))(Ks(1)(f.length-(ze(Jr)(l)(f)?1:0)|0)),h=_.idx,p=u>=2?i/(rt(u)-1):0;return J(m=>y=>{const x=y===h,N=y===l,w=y===0||y===(u-1|0),k=$x(m.prng)(w)(N)(x)(r)(t),L=Mx(k.prng)(w)(t)(e.h),E=qx(L.prng)(w)(t)(p);return{prng:E.prng,circles:Wt(m.circles)({cx:e.x+zx(k.r)(e.w-k.r)((u>=2?r+rt(y)/(rt(u)-1)*i+E.dx:r+0*i+E.dx)+(N?t.heroShift*p:x?-1*t.smallShift*p:0)),cy:n-L.yLift,r:k.r})}})({prng:_.prng,circles:[]})(It(0,u-1|0)).circles},t_=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?Xf(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?Xf(i)(t[o]):{x:i.cx+i.r,y:e}})()}))(t)},e_=t=>{const e=rn(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]},Ux=t=>e=>n=>{const r=ar(e.y-t.cy)(e.x-t.cx),i=ar(n.y-t.cy)(n.x-t.cx),o=i>r?i-r:i+6.283185307179586-r,u=Ks(1)(de(Ui(o/1.5707963267948966))),s=o/rt(u),a=1.3333333333333333*_d(s/4);return Tt(It(0,u-1|0))(c=>{const f=r+rt(c+1|0)*s,d=t.cx+t.r*tn(f),l=t.cy+t.r*He(f),_=r+rt(c)*s;return[4,t.cx+t.r*tn(_)-a*t.r*He(_),t.cy+t.r*He(_)+a*t.r*tn(_),d+a*t.r*He(f),l-a*t.r*tn(f),d,l]})},n_=t=>e=>{const n=t.h*.38,r=t_(Kf(jf)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),i=rn(e)(rn(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...Tt(r)(o=>Ux(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]:Hx(t)(e)},r_=t=>e=>n=>r=>i=>o=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(i)(o);if(e==="Cylinder"){const u=Zf(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=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==="Diamond"){const u=e_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="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=Uf(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=n_(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)},jx=t=>()=>t.clip("evenodd"),Zx=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=ut.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=Rd(t)(n);if(i!==n)return o(),e.stroke.value=n}},Kx=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}},Bi=t=>e=>n=>{const r=e.fill;return()=>{const i=r.value,o=Ad(t)(n);if(i!==n)return o(),e.fill.value=n}},Ko=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=ec(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=ai(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=ci(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=Yd(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=nc(t),a=r(o+1|0);return()=>(s(),a())}return()=>{}},i=tc(t);return()=>(i(),r(0)())},tN=t=>e=>n=>r=>i=>o=>{const u=ta(o)(ta(r/2)(i/2)),s=ec(t)(e+u)(n);return()=>(s(),ai(t)(e+r-u)(n)(),ci(t)({cpx:e+r,cpy:n,x:e+r,y:n+u})(),ai(t)(e+r)(n+i-u)(),ci(t)({cpx:e+r,cpy:n+i,x:e+r-u,y:n+i})(),ai(t)(e+u)(n+i)(),ci(t)({cpx:e,cpy:n+i,x:e,y:n+i-u})(),ai(t)(e)(n+u)(),ci(t)({cpx:e,cpy:n,x:e+u,y:n})(),nc(t)())},eN=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),nN=t=>e=>{const n=Od(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=eN();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0}}}},rN={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},iN=t=>ie(t.weight)+" "+Ga(t.size)+"px "+t.family,wn=t=>{const e=Ga(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+")"},oN=t=>e=>n=>r=>{const i=Bi(t)(n)(wn(r));return()=>(i(),Wd(t)({x:0,y:0,width:e.width,height:e.height})())},uN=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",Zx(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:wn(n.bgColor),dotCss:wn(n.dotColor),tile:n.tile,dotR:n.dotRadius})())},sN=t=>e=>n=>r=>{const i=Bi(t)(e)(wn(r));return()=>(i(),Ko(t)(n)(),Gu(t)())},aN=t=>e=>n=>r=>i=>{const o=Bi(t)(e)(wn(r));return()=>(o(),ea(t)(e)(wn(i.color))(),ku(t)(i.width)(),ro(t)((()=>{if(i.lineJoin==="RoundJoin")return no;if(i.lineJoin==="BevelJoin")return Au;if(i.lineJoin==="MiterJoin")return Ru;g()})())(),Wu(t)((()=>{if(i.lineCap==="ButtCap")return zu;if(i.lineCap==="RoundCap")return Fu;if(i.lineCap==="SquareCap")return Bu;g()})())(),Ko(t)(n)(),Gu(t)(),Su(t)())},cN=t=>e=>n=>r=>i=>o=>{const u=tc(t);return()=>{if(u(),tN(t)(n.x)(n.y)(n.w)(n.h)(r)(),i.tag==="Just"?(Bi(t)(e)(wn(i._1.color))(),Gu(t)()):i.tag==="Nothing"||g(),o.tag==="Just")return ea(t)(e)(wn(o._1.color))(),ku(t)(o._1.width)(),ro(t)((()=>{if(o._1.lineJoin==="RoundJoin")return no;if(o._1.lineJoin==="BevelJoin")return Au;if(o._1.lineJoin==="MiterJoin")return Ru;g()})())(),Wu(t)((()=>{if(o._1.lineCap==="ButtCap")return zu;if(o._1.lineCap==="RoundCap")return Fu;if(o._1.lineCap==="SquareCap")return Bu;g()})())(),Su(t)();o.tag!=="Nothing"&&g()}},gN=t=>e=>n=>r=>{const i=ea(t)(e)(wn(r.color));return()=>(i(),ku(t)(r.width)(),ro(t)((()=>{if(r.lineJoin==="RoundJoin")return no;if(r.lineJoin==="BevelJoin")return Au;if(r.lineJoin==="MiterJoin")return Ru;g()})())(),Wu(t)((()=>{if(r.lineCap==="ButtCap")return zu;if(r.lineCap==="RoundCap")return Fu;if(r.lineCap==="SquareCap")return Bu;g()})())(),Ko(t)(n)(),Su(t)())},i_=t=>e=>n=>{const r=Bi(t)(e)(wn(n.color));return()=>(r(),Kx(t)(e)(iN(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()})())(),Xd(t)(n.content)(n.x)(n.y)())},o_={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>rN},fN={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>o_},_N=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(),to(t)({scaleX:r,scaleY:r})(),ro(t)(no)())},dN={pure:t=>e=>()=>t,Apply0:()=>o_},lN={Applicative0:()=>dN,Bind1:()=>fN},u_={fillPath:t=>e=>n=>{const r=sN(n.ctx)(n.styleCache)(t)(e.color),i=n.maskDepth;return()=>{if(i.value===0)return r()}},strokePath:t=>e=>n=>{const r=gN(n.ctx)(n.styleCache)(t)(e),i=n.maskDepth;return()=>{if(i.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const i=aN(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=cN(i.ctx)(i.styleCache)(t)(e)(n)(r),u=i.maskDepth;return()=>{if(u.value===0)return o()}},drawText:t=>e=>{const n=i_(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=cr(n.ctx),i=n.maskDepth;return()=>{if(i.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Md(n.ctx)(t)(),i_(n.ctx)(n.styleCache)(e)(),gr(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=cr(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})(),to(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=gr(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=cr(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})(),to(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=gr(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=cr(n.ctx),i=n.maskDepth;return()=>{if(i.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Ko(n.ctx)(t)(),e==="NonZero")return zd(n.ctx)();if(e==="EvenOdd")return jx(n.ctx)();g()}}},popClip:t=>{const e=gr(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=cr(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 ic(e.ctx)(nl)();if(t==="Difference")return ic(e.ctx)(rl)();g()}}},popBlend:t=>{const e=gr(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=cr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Bd(e.ctx)(t)()}},popAlpha:t=>{const e=gr(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=_N(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=oN(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=uN(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=Rf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>$f,Monad0:()=>lN},hN=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Hr=t=>e=>n=>{const r=hN(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},s_=t=>{const e=ut.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ut.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},tu=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:yi(8)(.6)(s_(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:yi(8)(.6)(s_(1-t._1))};g()};function pN(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function mN(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:pN(i,o)}}return n}function yN(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 a_(t,e){if(e.length===0)return[];const n=mN(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]=yN(n,e,o*r/t);return i}function xN(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 NN(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 xN(r,e)}const c_=t=>e=>n=>{const r=a_(t,e),i=a_(t,n),o=NN(r,i);return{from:r,to:o}};function g_(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 JN(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 TN(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 wN(t){return t<0?0:t>1?1:t}const f_=t=>e=>n=>r=>{const i=e.length;if(i===0)return[];const o=g_(e),u=g_(n),s=JN(o,u),a=new Array(i);let c=1/0,f=-1/0;for(let _=0;_<i;_++){const h=e[_],p=(h.x-o.x)*s.x+(h.y-o.y)*s.y;a[_]=p,p<c&&(c=p),p>f&&(f=p)}const d=f-c;let l=new Array(i);for(let _=0;_<i;_++){const h=e[_],p=n[_];if(p===void 0){l[_]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(a[_]-c)/d),y=Math.max(1e-4,1-m),x=wN((t-m)/y),N=x*x*(3-2*x);l[_]={x:h.x+(p.x-h.x)*N,y:h.y+(p.y-h.y)*N}}for(let _=0;_<r.smoothPasses;_++)l=TN(.5,l);return l},vn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},__=J(vr)(0),d_=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},vN=J(t=>e=>t+e.len)(0),na=t=>{const e=Rt(n=>T,n=>r=>v("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()},bN=t=>e=>{const n=vn(e)(vn(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]},LN=t=>{const e=Rt(n=>T,n=>r=>v("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()},kN=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return Zf(e);if(t.shape==="Parallelogram")return Vf(e);if(t.shape==="Diamond")return e_(e);if(t.shape==="Ellipse")return Yf(e);if(t.shape==="Document")return Uf(e);if(t.shape==="Cloud")return n_(e)(7);if(t.shape==="Rectangle")return bN(e)(7);g()},pe=t=>e=>n=>M(r=>{const i=rt(r)/rt(n);return{x:t.x+(e.x-t.x)*i,y:t.y+(e.y-t.y)*i}})(It(0,n-1|0)),EN=t=>{const e=rn(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)]},$r=t=>e=>{const n=vn(t)(vn(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}},ra=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return ke(r*r+n*n)},CN=t=>Je(e=>n=>({a:e,b:n,len:ra(e)(n)}),t,bt(1,t.length,t)),SN=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?v("Just",e[n]):T,i=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];g()})(),o=0<e.length?v("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(It(1,s-2|0))(a=>{const c=a+1|0,f=c>=0&&c<e.length?v("Just",e[c]):T,d=a>=0&&a<e.length?v("Just",e[a]):T,l=a-1|0,_=l>=0&&l<e.length?v("Just",e[l]):T;if(_.tag==="Just"&&d.tag==="Just"&&f.tag==="Just"){const h=d._1,p=ra(h)(f._1),m=ra(_._1)(h),y=vn(t)(p/2),x=vn(t)(m/2),N=p>0?y/p:0,w=h.x+(f._1.x-h.x)*N,k=h.y+(f._1.y-h.y)*N,L=m>0?x/m:0,E=h.x+(_._1.x-h.x)*L,B=h.y+(_._1.y-h.y)*L;return M(X=>{const et=rt(X)/rt(10),S=1-et;return{x:S*S*E+2*S*et*h.x+et*et*w,y:S*S*B+2*S*et*h.y+et*et*k}})(It(0,10))}return[]}),...i]},GN=t=>e=>n=>r=>i=>M(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}})(It(0,i-1|0)),PN=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),...GN({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=>M(n=>{const r=6.283185307179586*rt(n)/rt(64);return{x:t.x+e*tn(r),y:t.y+e*He(r)}})(It(0,63)),eu=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]},DN=t=>{const e=t.y+t.h/2,n=rn(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:__(M(n=>n.x)(t))/rt(e),y:__(M(n=>n.y)(t))/rt(e)}},nu=t=>e=>n=>r=>i=>M(o=>{const u=n+(r-n)*(rt(o)/rt(i));return{x:t.x+e*tn(u),y:t.y+e*He(u)}})(It(0,i-1|0)),p_=t=>e=>{const n=vn(t)(vn(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),...nu({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),...nu({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),...nu({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),...nu({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},ru=t=>e=>n=>r=>i=>o=>M(u=>{const s=r+(i-r)*(rt(u)/rt(o));return{x:t.x+e*tn(s),y:t.y+n*He(s)}})(It(0,o-1|0)),IN=t=>{const e=t.h*.38;return[...Tt(t_(Kf(jf)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=ar(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),i=ar(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return ru({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)]},QN=t=>{const e=vn(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[...ru({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),...ru({x:o,y:i})(n)(e)(0)(3.141592653589793)(24),...pe({x:t.x,y:i})({x:t.x,y:r})(12)]},mr=t=>e=>e.shape==="Cylinder"?QN(e):e.shape==="Parallelogram"?EN(e):e.shape==="Diamond"?DN(e):e.shape==="Ellipse"?p_(rn(e.w)(e.h)/2)(e):e.shape==="Document"?PN(e):e.shape==="Cloud"?IN(e):p_(t)(e),AN=t=>{const e=vn(t.h*.075)(t.w*.075),n=t.w/2;return ru({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},RN=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})()})()?Wt(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,FN=t=>e=>n=>{const r=Rt(i=>T,i=>o=>v("Just",{head:i,tail:o}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const i=CN(t),o=vN(i),u=d_(0)(o)(e*o),s=d_(0)(o)(n*o);return s<=u?[]:RN(i)(u)(s)}g()},BN=t=>e=>n=>r=>{const i=r.x-n.x,o=r.y-n.y,u=e.x-t.x,s=e.y-t.y,a=n.x-t.x,c=n.y-t.y,f=u*o-s*i,d=(a*o-c*i)/f,l=(a*s-c*u)/f;return(f<0?-f<1e-9:f<1e-9)?T:d>=0&&d<=1&&l>=0&&l<=1?v("Just",d):T},zN=t=>e=>n=>{const r=kt(i=>o=>ut.compare(i.t)(o.t))(xt(i=>{const o=BN(e)(n)(i._1)(i._2);return o.tag==="Just"?v("Just",{t:o._1,p:{x:e.x+(n.x-e.x)*o._1,y:e.y+(n.y-e.y)*o._1}}):T})(Je(En,t,[...bt(1,t.length,t),...bt(0,1,t)])));return 0<r.length?v("Just",r[0].p):T},m_=t=>e=>{const n=ni(e);if(n.tag==="Nothing")return e;if(n.tag==="Just"){const r=n._1.init.length-1|0;if(r>=0&&r<n._1.init.length){const i=zN(t)(n._1.init[r])(n._1.last);if(i.tag==="Just")return Wt(n._1.init)(i._1);if(i.tag==="Nothing")return e;g()}return e}g()},ia=t=>t,Fn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},yr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},WN=$1(Fa)(zt),ON=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},MN=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},y_=ia("SegMove"),qN=ia("SegLine"),HN=ia("SegQuad"),x_={offset:.4,passes:1,rMax:1.5},N_=t=>de(ln(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)},Bn=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},zi=(()=>{const t=J(e=>n=>((e*31|0)+de(ln(n.x*100))|0)+de(ln(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?v("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:y_,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:qN,m:o,c:o,p:s,len:ke(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:HN,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:ke(a*a+c*c)*1.05}),r=s,n=i+5|0;continue}if(u._1===5){e.push({kind:y_,m:o,c:o,p:o,len:0}),n=i+1|0;continue}n=t.length;continue}g()}return e},XN=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?v("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=ke(s*s+u*u);return a<=1e-4?e:Wt((()=>{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},YN=t=>e=>n=>Ne(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*tn(u.value),y:i.y+o.value*He(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 Bn(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 Bn(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 Bn(t)(e.p);if(e.kind==="SegQuad")return iu(t)(e.c)(e.p);g()},J_=t=>e=>{const n=$N(e),r=J(s=>a=>s+a.len)(0)(n)*Fn(0)(yr(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)/Fn(n[s].len)(1e-4))()}u=n.length}return i},T_={offset:1.5,passes:2,rMax:14,overshoot:2.5},w_=t=>e=>n=>r=>{const i=r.y-n.y,o=n.y-e.y,u=r.x-n.x,s=ke(u*u+i*i),a=n.x-e.x,c=ke(a*a+o*o),f=yr(t.rMax*(gd(c>0&&s>0?Fn(-1)(yr(1)((a*u+o*i)/(c*s))):1)/3.141592653589793))(.4*yr(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?v("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=w_(t)(e[c])(e[s])(e[a]);Bn(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&&Bn(r)(e[o])(),r},jN=t=>e=>n=>r=>i=>{if(i.length<4)return v_(t)(i);const o=0<i.length?v("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=Vn(Vn(e)(s)+s|0)(s),c=_=>{const h=Vn(_+s|0)(s);return h>=0&&h<i.length?i[h]:u},f=M(_=>w_(t)(c((a+_|0)-1|0))(c(a+_|0))(c((a+_|0)+1|0)))(It(0,s-1|0)),d=[],l=0<f.length?v("Just",f[0]):T;if(l.tag==="Just")if(ou(d)(l._1.outP)(),WN((()=>{const _=Rt(h=>T,h=>p=>v("Just",p),f);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})())(_=>{const h=Bn(d)(_.inP);return()=>(h(),iu(d)(_.curr)(_.outP)())})(),n)Bn(d)(l._1.inP)(),iu(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const _=f.length-1|0;_>=0&&_<f.length?Bn(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}})())():Bn(d)(l._1.inP)()}else l.tag==="Nothing"||g();return d},Xr=t=>e=>n=>r=>{const i=ON(1)(r.length-1|0),o=ae(0)(rt(i))(fs("shape")(e)),u=MN(i-1|0)(de(ln(o.value))),s=o.prng;return M(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),_=YN(t.offset)(l.prng)(r);return{path:n?jN(t)(u)(d)(f.value)(_):v_(t)(_),alpha:l.value}})(It(0,t.passes-1|0))},ZN=t=>e=>n=>Xr(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=Fn(0)(yr(1)(n)),i=e.h/rt(4),o=Fn(6)(i*1.4);return xt(u=>u)(M(u=>{if(r<Fn(0)(rt(u)/rt(4)-.05))return T;const s=fs(ie(u))(t),a=Fn(0)(rt(u)/rt(4)-.05),c=Vn(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 v("Just",{path:J_(Fn(0)(yr(1)((r-a)/Fn(1e-4)(yr(1)(rt(u+1|0)/rt(4)+.05)-a))))((()=>{const _={rMax:2,offset:.6,passes:1},h=Ne(J(m=>y=>{const x=ae(-i*.08)(i*.08)(m.prng);return{prng:x.prng,out:[{x:f+(d-f)*(rt(y)/rt(4)),y:l+x.value},...m.out]}})({prng:s,out:[]})(It(0,4)).out),p=h.length<2?[]:Xr(_)(s)(!1)(h);return 0<p.length?p[0].path:[]})()),width:o,alpha:1})})(It(0,3)))},oa=(t,e,n)=>({tag:t,_1:e,_2:n}),b_=t=>t,ua=(t,e,n)=>({tag:t,_1:e,_2:n}),uu=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},L_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Wi=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},k_=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=v("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=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=v("Just",o._4);continue}}g()}return i},Ie=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),xr=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=v("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()},E_=Kt(C)(zt),eJ=ja(C),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=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},sa=b_("LabelsShown"),rJ=b_("LabelsHidden"),C_=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))))))},on=t=>{const e=t.Apply0();return n=>J(r=>i=>e.apply(e.Functor0().map(o=>Sa)(r))(n(i)))(t.pure())},S_=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?v("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?v("Just",t[d]):T,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return u;g()})(),h=c_(128)(mr(4)($r(2)(e)))(l_(f)(6)),p=f.x-s.x,m=2*(()=>{const V=f.y-s.y;return(p<0?-p:p)+(V<0?-V:V)})(),y=_.x-u.x,x=2*(()=>{const V=_.y-u.y;return(y<0?-y:y)+(V<0?-V:V)})(),N=m+li(t)+x,w=N<=1e-4?1:1-x/N,k=N<=1e-4?0:m/N,L=w-k,E=c_(128)(l_(_)(6))(mr(4)($r(2)(n))),B={maxDelay:.4,smoothPasses:2},X=br(t)(uu(0)(1)(L<=1e-4?0:(a-k)/L)),et=(()=>{if(X.tag==="Just")return X._1;if(X.tag==="Nothing")return f;g()})(),S=(()=>{if(w>=1)return 0;const V=(a-w)/(1-w),U=V<0?0:V>1?1:V;return U*U*(3-2*U)})(),P=(()=>{if(k<=1e-4)return 1;const V=a/k,U=V<0?0:V>1?1:V;return U*U*(3-2*U)})();return a<k?ua("PolyShape",f_(P)(h.from)(h.to)(B)):a>=w?ua("PolyShape",f_(S)(E.from)(E.to)(B)):ua("CircleShape",et,6)},G_=t=>e=>n=>r=>i=>o=>{const u=S_(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(Wi)(0)(M(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?L_((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=k_(i)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just"){const u=iJ(o._1)(r.obstacles);return{acc:K(C)(i)(u)(r.acc),obstacles:Wt(r.obstacles)(u)}}g()})({acc:Q,obstacles:n})(t).acc,aa=(()=>{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:Rn,nodeFill:re,nodeStroke:Rn,text:Rn,edge:Rn,arrowFill:Rn,tokenOutsideFill:Rn,tokenOutsideStroke:re,tokenInside:re,tokenInsideStroke:re,tokenInsideBlend:Zo,tokenInsideAlpha:1,chipPillFill:Rn,chipPillText:re,chipHairline:{r:26,g:26,b:26,a:90},trailDot:Rn,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:Rn,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:re,tokenOutsideStroke:re,tokenInside:re,tokenInsideStroke:re,tokenInsideBlend:Zo,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:Zo,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()}})(),ca=t=>e=>Tt(Ie(t.nodes))(n=>{const r=fe(n._1)(e.nodes);return r.tag==="Just"&&tu(r._1).alpha>0?kN(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,...ca(e)(n)],sJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=or.traverse(r);return o=>u=>{const s=Un(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?io(s[c]):" "))(l=>r.pure({x:f,w:d-f,up:l.ascent-a,down:l.descent+a})))))(It(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 M(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])},ga=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?v("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?v("Just",t[d]):T,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return u;g()})(),h=f.x-s.x,p=2*(()=>{const B=f.y-s.y;return(h<0?-h:h)+(B<0?-B:B)})(),m=_.x-u.x,y=2*(()=>{const B=_.y-u.y;return(m<0?-m:m)+(B<0?-B:B)})(),x=p+li(t)+y,N=x<=1e-4?1:1-y/x,w=x<=1e-4?0:p/x,k=N-w,L=br(t)(uu(0)(1)(k<=1e-4?0:(a-w)/k)),E=(()=>{if(L.tag==="Just")return L._1;if(L.tag==="Nothing")return f;g()})();return a<w?oa("InsideRect",$r(2)(e)):a>=N?oa("InsideRect",$r(2)(n)):oa("InsideBall",E,6)},gJ={offset:.8,passes:2,rMax:5},fJ=t=>{const e=t.Monad0().Applicative0(),n=on(e);return r=>i=>o=>u=>{const s={color:u,width:1,lineJoin:Te,lineCap:_n},a={color:o,flat:!0},c=f=>t.drawRoundedRect({x:f.x,y:f.y,w:f.w,h:f.h})(4)(v("Just",a))(v("Just",s));return n(f=>{if(f._2.tag==="Travelling"){const d=xr(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 Ne(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(eu(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($r(2)(d._1));if(d.tag==="Nothing")return e.pure();g()}return e.pure()})(Ie(i.tokens))}},P_=t=>e=>n=>r=>t.strokePath((()=>{const i=Rt(o=>T,o=>u=>v("Just",{head:o,tail:u}),M(o=>o.pt)(id(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+tn(l)*d+f.value*n,y:e.y+He(l)*d+f.value*n}}},{prng:137,pt:{x:e.x,y:e.y}},It(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:An}),_J=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=on(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:An}))(()=>r)))(KN(N_(u)+7777|0)(u)(s))},D_=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=e.Applicative0(),o=on(i),u=t.popClip,s=on(i),a=or.traverse(i),c=sJ(t),f=_J(t),d=t.popTransform;return l=>_=>h=>p=>m=>y=>x=>{const N=F=>n.bind(t.pushAlpha(F.alpha))(()=>n.bind(t.strokePath(F.path)({color:_.nodeStroke,width:2,lineJoin:Te,lineCap:An}))(()=>r)),w={family:_.fontFamily,size:_.wobble?15:11,weight:_.wobble?800:500},k=lo(`
|
|
8
|
+
`)(y.label===""?m:y.label),L=k.length===0?[""]:k,E=w.size*1.2,B=y.shape==="Cylinder"?t.strokePath(Vx({x:y.x,y:y.y,w:y.w,h:y.h}))({color:_.nodeStroke,width:1.25,lineJoin:Te,lineCap:_n}):i.pure(),X=(y.shape==="Cylinder"?(y.y+(y.y+y.h+5-2*rn(y.h*.075)(y.w*.075)))/2:(y.y+y.y+y.h)/2)-rt(L.length)*E/2+E/2,et=x.tag==="PloppingOut"&&_.wobble?x._1:-1,S=et>=0,P=tu(x),V=S?{alpha:1,scale:1}:P,U=y.x+y.w/2,O=y.y+y.h/2,z=n.bind(t.pushAlpha(V.alpha*h))(()=>n.bind(t.pushTransform({tx:U*(1-V.scale),ty:O*(1-V.scale),sx:V.scale,sy:V.scale}))(()=>{const F={x:y.x,y:y.y,w:y.w,h:y.h},G={color:_.nodeStroke,width:_.wobble?2:1.25,lineJoin:Te,lineCap:_.wobble?An:_n};return n.bind((()=>{if(_.wobble){if(y.shape==="Rectangle")return o(N)(ZN(T_)(N_(F))(F));const D=mr(7)(y);return n.bind(o(N)((()=>{const I=zi(D);return D.length<4?[]:Xr(x_)(I)(!0)(D)})()))(()=>s(I=>o(N)((()=>{const A=zi(I);return I.length<2?[]:Xr(x_)(A)(!1)(I)})()))(y.shape==="Cylinder"?[AN(y)]:[]))}return n.bind(r_(t)(y.shape)(F)(7)(v("Just",{color:_.nodeFill,flat:!1}))(v("Just",G)))(()=>B)})())(()=>n.bind((()=>{if(p.tag==="Just"&&_.wobble&&!S){const D=p._1;return n.bind(a(c(w))(L))(I=>{const A=kt(Z=>nt=>ut.compare(Z.x)(nt.x)),H=de(ln(y.x*7919+y.y*3001))*-1640531535|0,$=ae(5)(7.5)(H),Y=ae(0)($.value)($.prng),q=-(1+2*ae(-1)(1)(Y.prng).value*3.141592653589793/180),W=(Z,nt,ht,ft,Nt)=>A(xt(wt=>wt)([q*nt+Z>=ft&&q*nt+Z<=Nt?v("Just",{x:nt,y:q*nt+Z}):T,q*ht+Z>=ft&&q*ht+Z<=Nt?v("Just",{x:ht,y:q*ht+Z}):T,(()=>{const wt=(ft-Z)/q;return wt>=nt&&wt<=ht?v("Just",{x:wt,y:ft}):T})(),(()=>{const wt=(Nt-Z)/q;return wt>=nt&&wt<=ht?v("Just",{x:wt,y:Nt}):T})()])),tt=$.value,j=Vn(D.frameHash)(3),gt=j===0?{r:200,g:35,b:30,a:220}:j===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},_t=y.x+y.w/2,at=Fe(At(Z=>nt=>At((()=>{const ht=X+rt(Z)*E,ft=_t-J(Nt=>wt=>Nt+wt.w)(0)(nt)/2;return Nt=>wt=>{const Zt=w.size*.1,Se=Nt-1|0,sn=Se>=0&&Se<nt.length&&Nt>0?(nt[Se].x+nt[Se].w+wt.x)/2:wt.x-Zt;return{x:ft+sn-1,y:ht-wt.up-1,w:Wi(0)((()=>{const Re=Nt+1|0;return Re>=0&&Re<nt.length&&Nt<(nt.length-1|0)?(wt.x+wt.w+nt[Re].x)/2-sn:wt.x+wt.w+Zt-sn})())+2,h:wt.up+wt.down+2}}})())(nt))(I)),yt=y.y+4,St=y.x+y.w-4,Ft=y.x+4,pt=yt-q*Ft+Y.value,Bt=y.y+y.h-4,Jt=Tt(Tt(At(Z=>nt=>{const ht=(nt.from.x+nt.to.x)/2,ft=(nt.from.y+nt.to.y)/2,Nt=ae(-1)(1)(H+(911*(Z+1|0)|0)|0),wt=ae(-3)(5)(Nt.prng),Zt=Nt.value*3.141592653589793/180,Se=tn(Zt),sn=He(Zt),Re=Et=>({x:ht+(Et.x-ht)*Se-(Et.y-ft)*sn,y:ft+(Et.x-ht)*sn+(Et.y-ft)*Se});return{from:(()=>{const Et=Re(nt.from),Qt=Et.y-ft,Ze=Et.x-ht,qe=ke(Ze*Ze+Qt*Qt),Ke=qe<1e-4?1:(qe+wt.value)/qe;return{x:ht+Ze*Ke,y:ft+Qt*Ke}})(),to:(()=>{const Et=Re(nt.to),Qt=ae(-3)(5)(wt.prng).value,Ze=Et.y-ft,qe=Et.x-ht,Ke=ke(qe*qe+Ze*Ze),qn=Ke<1e-4?1:(Ke+Qt)/Ke;return{x:ht+qe*qn,y:ft+Ze*qn}})()}})(xt(Z=>{const nt=W(pt+rt(Z)*tt,Ft,St,yt,Bt);return nt.length===2?v("Just",{from:nt[0],to:nt[1]}):T})(It(0,su(1)(de(ln((Bt-q*St-pt)/tt)))))))(Z=>st(nt=>nt.to.x-nt.from.x>1,J(nt=>ht=>Tt(nt)(ft=>{const Nt=W(ft.from.y-q*ft.from.x,ht.x,ht.x+ht.w,ht.y,ht.y+ht.h);return Nt.length===2?Nt[0].x>ft.from.x+.001&&Nt[1].x<ft.to.x-.001?[{from:ft.from,to:Nt[0]},{from:Nt[1],to:ft.to}]:Nt[0].x<=ft.from.x+.001&&Nt[1].x<ft.to.x-.001?[{from:Nt[1],to:ft.to}]:Nt[0].x>ft.from.x+.001&&Nt[1].x>=ft.to.x-.001?[{from:ft.from,to:Nt[0]}]:[]:[ft]}))([Z])(at))))(Z=>(()=>{const nt=Z.to.x-Z.from.x;return ke(2)*(nt>=0?nt:-nt)<=28})()?[Z]:[{from:Z.from,to:{x:Z.from.x+(Z.to.x-Z.from.x)*.495,y:Z.from.y+(Z.to.y-Z.from.y)*.495}},{from:{x:Z.from.x+(Z.to.x-Z.from.x)*.505,y:Z.from.y+(Z.to.y-Z.from.y)*.505},to:Z.to}]),mt=Jt.length,ct=Z=>Wi(0)(L_(1)(D.t*rt(mt)-rt(Z)));return n.bind(t.pushClip(na(mr(7)(y)))(jo))(()=>n.bind(o(Z=>{const nt=Z._1,ht=ae(1.4)(1.9)(H+(1303*(nt+1|0)|0)|0),ft=ae(.35)(.8)(ht.prng),Nt=o(wt=>n.bind(t.pushAlpha(wt.alpha*ft.value))(()=>n.bind(t.strokePath(J_(ct(nt))(wt.path))({color:gt,width:ht.value,lineJoin:Te,lineCap:An}))(()=>r)))(Xr({...T_,rMax:0,offset:.5})(H+(53*(nt+1|0)|0)|0)(!1)([Z._2.from,Z._2.to]));return ct(nt)>0?Nt:i.pure()})(At(En)(Jt)))(()=>u))})}return i.pure()})())(()=>n.bind((()=>{if(l==="LabelsShown")return o(D=>t.drawText({x:y.x+y.w/2,y:X+rt(D._1)*E,content:D._2,font:w,color:_.text,align:Uo,baseline:qr}))(At(En)(L));if(l==="LabelsHidden")return i.pure();g()})())(()=>n.bind((()=>{const D=f(_)(F)(et);return S?D:i.pure()})())(()=>n.bind(d)(()=>r)))))}));return V.alpha*h>0?z:i.pure()}},dJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=D_(t),o=t.popAlpha,u=on(n);return s=>a=>c=>{const f={...s,nodeFill:s.text,text:s.nodeFill,nodeStroke:s.nodeFill};return u(d=>{const l=fe(d._1)(c.nodes),_=fe(d._1)(a.nodes),h=(()=>{if(_.tag==="Just"&&l.tag==="Just"){const p=l._1,m=_._1;return r.bind(t.pushAlpha(d._2))(()=>r.bind(i(sa)(f)(1)(T)(d._1)(m)(p))(()=>o))}return n.pure()})();return d._2>0?h:n.pure()})(Ie(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 m=(1-d)/_;return m<0?0:m>1?1:m}if(l>1e-4&&d<l){const m=d/l;return m<0?0:m>1?1:m}return 1})(),p=S_(a)(c)(f)(d)(l)(_);if(p.tag==="CircleShape")return o?P_(t)(p._1)(p._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(eu(p._1)(p._2))({color:u,flat:!0})({color:s,width:1,lineJoin:Te,lineCap:_n});if(p.tag==="PolyShape"&&o&&p._1.length>=3)return r.bind(t.pushAlpha(h))(()=>r.bind(P_(t)(h_(p._1))(6)({r:200,g:35,b:30,a:220}))(()=>i));if(p.tag==="PolyShape")return o?n.pure():p._1.length>=3?t.fillStrokePath(na(p._1))({color:u,flat:!0})({color:s,width:1,lineJoin:Te,lineCap:_n}):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,p)=>e.bind(t.pushAlpha(p))(()=>e.bind(t.fillStrokePath(eu(h)(6))({color:r,flat:!0})({color:i,width:1,lineJoin:Te,lineCap:_n}))(()=>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=on(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 _=xr(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 Ne(_._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(na(mr(4)($r(2)(d._1))))({color:a,flat:!0})({color:c,width:1,lineJoin:Te,lineCap:_n});if(d.tag==="Nothing")return r.pure();g()}return r.pure()})(Ie(s.tokens))},Q_=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=on(c),d=t.popAlpha;return l=>_=>h=>p=>{const m=_.wobble?e(!0)(h)(p)(_.tokenInside)(_.tokenInsideStroke):r.bind(t.insideTokenStyle(l))(y=>{if(y==="GenieSilhouette")return i(!1)(h)(p)(_.tokenInside)(_.tokenInsideStroke);if(y==="ConvexAbsorb")return o(h)(p)(_.tokenInside)(_.tokenInsideStroke);g()});if(_.tokenInsideBlend==="Difference")return r.bind(t.pushLayer(Ix))(()=>r.bind(t.pushBlend(Zo))(()=>r.bind(t.pushClip(ca(h)(p))(jo))(()=>r.bind(m)(()=>r.bind(u)(()=>r.bind(s)(()=>r.bind(a)(()=>r.bind(t.pushLayer(Qx))(()=>r.bind(f(y=>{const x=fe(y._1)(p.nodes);return x.tag==="Just"&&tu(x._1).alpha>0?r_(t)(y._2.shape)({x:y._2.x,y:y._2.y,w:y._2.w,h:y._2.h})(7)(v("Just",{color:re,flat:!1}))(T):c.pure()})(Ie(h.nodes)))(()=>a)))))))));if(_.tokenInsideBlend==="Normal")return r.bind(t.pushClip(ca(h)(p))(jo))(()=>r.bind(t.pushAlpha(_.tokenInsideAlpha))(()=>r.bind(m)(()=>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(Dx))(()=>e.bind(t.pushClip(uJ(s)(a)(c))(Rx))(()=>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=on(r);return o=>u=>s=>a=>c=>f=>{const d=mo(f).length,l=rt(d+1|0),_=m=>{const y=(s*l-rt(m))/1.5,x=y<0?0:y>1?1:y;return x*x*(3-2*x)},h=(m=>{let y=m,x=!0,N;for(;x;){const w=y;if(w>=d){x=!1,N=w;continue}if(_(w)>=1){y=w+1|0;continue}x=!1,N=w}return N})(0),p=h>=d?[]:sr(m=>_(m)>0)(It(h,d-1|0)).init;return n.bind((()=>{const m=t.drawText({x:a,y:c,content:me(h)(f),font:o,color:u,align:Zs,baseline:qr});return h>0?m:r.pure()})())(()=>i(m=>n.bind(t.measureText(o)(me(m)(f)))(y=>{const x=_(m);return t.drawText({x:a+y,y:c-(1-x)*10,content:me(1)(fi(jn(me(m)(f)))(f)),font:o,color:{...u,a:de(ln(x*rt(u.a)))},align:Zs,baseline:qr})}))(p))}},cu=t=>e=>n=>r=>{const i=M(_=>rt(su(1)(mo(_).length)))(r),o=Wi(1)(J(vr)(0)(i)),u=Hr(e)(n)(t),s=u*o,a=su(1)(r.length),c=(_=>h=>p=>{let m=_,y=h,x=p,N=!0,w;for(;N;){const k=m,L=y,E=Rt(B=>T,B=>X=>v("Just",{head:B,tail:X}),x);if(E.tag==="Nothing"){N=!1,w=su(0)(a-1|0);continue}if(E.tag==="Just"){if(L+E._1.head>=s){N=!1,w=k;continue}m=k+1|0,y=L+E._1.head,x=E._1.tail;continue}g()}return w})(0)(0)(i),f=J(vr)(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)(M(Z1)(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=or.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>E_(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(v("Just",b(a._1,f))));if(c.tag==="Nothing")return i.pure(T);g()}return i.pure(T)})(Ie(s.tokens)))},xJ=t=>{const e=t.Monad0();return n=>r=>i=>o=>u=>s=>a=>{const c=G_(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)(ga)).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=or.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>E_(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=xr(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 Ne(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(v("Just",b(a._1,l))))}return i.pure(T)})(Ie(s.tokens)))},fa=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 Q;if(f.tag==="Node")return Mt("Node",f._1,f._2,f._3,void 0,c(f._5),c(f._6));g()};return kt(C.compare)(Ct(Oe.foldr,c(s)))})())(s)([...xt(c=>{const f=fe(c._1)(u.nodes);return f.tag==="Just"&&tu(f._1).alpha>0?v("Just",{x:c._2.x,y:c._2.y,w:c._2.w,h:c._2.h}):T})(Ie(o.nodes)),...(()=>{const c=(f,d)=>{if(f.tag==="Leaf")return d;if(f.tag==="Node")return c(f._5,qt("Cons",f._4,c(f._6,d)));g()};return Ct($t.foldr,c(a,Ht))})()]))))},R_=t=>e=>n=>{const r=yi(6)(.55)(uu(0)(1)((1-t)/.06)),i=t>.94,o=i&&n>1e-4,u=yi(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=C_(t);return r=>i=>o=>u=>s=>{const a=R_(u)(0)(0),c={family:r.fontFamily,size:11,weight:500},f=cu(u)(0)(0)(Tt(s)(ga));return e.bind(t.measureText(c)(f.line))(d=>{const l=o.x+o.w/2,_=d+28,h=o.y-25.2-14,p=l-_/2,m=[1,l,h+25.2,2,l,o.y],y={x:l,y:h+12.6};return n(a)(l-_/2)(h+25.2)(y)(e.bind(t.drawRoundedRect({x:l-_/2,y:h+1.5,w:_,h:25.2})(6)(v("Just",{color:r.chipShadow,flat:!0}))(T))(()=>e.bind(t.drawRoundedRect({x:p,y:h,w:_,h:25.2})(6)(v("Just",{color:r.chip,flat:!0}))(v("Just",{color:r.chipHairline,width:1,lineJoin:Te,lineCap:_n})))(()=>e.bind(t.strokePath(m)({color:r.chipHairline,width:1,lineJoin:Te,lineCap:_n}))(()=>t.drawText({x:l,y:y.y,content:f.line,font:c,color:r.chipText,align:Uo,baseline:qr})))))})}},TJ=t=>{const e=C_(t),n=t.Monad0(),r=n.Bind1(),i=on(n.Applicative0()),o=pJ(t);return u=>s=>a=>c=>f=>d=>l=>_=>h=>{const p=cu(f)(d)(l)(Tt(_)(ga)),m=p.line,y=p.phaseInLabel/.45,x=y<0?0:y>1?1:y,N=h.w,w=h.y,k=h.x,L=k+14,E=h.h,B=w+E/2;return e(R_(f)(d)(l))(k)(w+E)({x:k+N/2,y:B})(r.bind(i(X=>t.fillPath(eu(X)(1.5))({color:u.trailDot,flat:!0}))(aJ(h)(G_(s)(a)(c)(f)(d)(l))))(()=>r.bind(t.drawRoundedRect({x:k,y:w,w:N,h:E})(3)(v("Just",{color:u.chipPillFill,flat:!0}))(T))(()=>o({family:u.fontFamily,size:11,weight:500})(u.chipPillText)(x)(L)(B)(m))))}},_a=t=>{const e=TJ(t),n=t.Monad0(),r=n.Applicative0(),i=JJ(t),o=n.Bind1(),u=on(r),s=t.popLayer;return a=>c=>f=>d=>o.bind(t.pushLayer(Ax))(()=>o.bind(u(l=>{if(l._2.tag==="Travelling"){if(l._2._1.labels.length!==0){const _=fe(l._2._1.target)(c.nodes),h=fe(l._2._1.source)(c.nodes),p=xr(l._2._1.edge)(c.edges),m=k_(l._1)(d);if(m.tag==="Just"&&p.tag==="Just"&&h.tag==="Just"&&_.tag==="Just")return e(a)((()=>{if(l._2._1.direction==="Forward")return p._1;if(l._2._1.direction==="Backward")return Ne(p._1);g()})())(h._1)(_._1)(l._2._1.progress)(l._2._1.holdPre)(l._2._1.holdPost)(l._2._1.labels)(m._1)}return r.pure()}if(l._2.tag==="Filling"&&l._2._1.labels.length!==0){const _=fe(l._2._1.node)(c.nodes);if(_.tag==="Just")return i(a)(c)(_._1)(l._2._1.progress)(l._2._1.labels);if(_.tag==="Nothing")return r.pure();g()}return r.pure()})(Ie(f.tokens)))(()=>s))},F_=t=>{const e=fa(t),n=_a(t);return r=>i=>o=>t.Monad0().Bind1().bind(e(i)(o))(u=>n(r)(i)(o)(u))},wJ=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?v("Just",u[s]):T,c=i.length-1|0,f=c>=0&&c<i.length?v("Just",i[c]):T;if(f.tag==="Just"&&a.tag==="Just"){const d=ae(.78)(1.18)(zi(i)+19|0),l=ae(.4)(.62)(d.prng),_=r.wobble?8.75*l.value:4.375,h=ae(.4)(.62)(l.prng),p=r.wobble?8.75*h.value:4.375,m=f._1.y-a._1.y,y=f._1.x-a._1.x,x=ke(y*y+m*m),N=m/x,w=-N,k=y/x,L=f._1.x+k*.875,E=f._1.y+N*.875,B=r.wobble?8.75*d.value:8.75,X=L-k*B,et=E-N*B,S=X+w*_,P=et+k*_,V=[1,L,E,2,X+w*4.375,et+k*4.375,2,X-w*4.375,et-k*4.375,5],U=X-w*p,O=et-k*p,z={color:r.arrowFill,width:2,lineJoin:Te,lineCap:An};return x<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,S,P,2,L,E])(z))(()=>t.strokePath([1,U,O,2,L,E])(z)):t.fillPath(V)({color:r.arrowFill,flat:!0})}return n.pure()}},vJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=on(n),o=t.popAlpha,u=wJ(t);return s=>a=>c=>f=>{const d=SN(8)(c);if(f.hi<=f.lo)return n.pure();const l=FN(d)(f.lo)(f.hi);if(l.length===0)return n.pure();const _={color:s.edge,width:s.wobble?2:.9375,lineJoin:Te,lineCap:An},h=s.wobble?ae(-10)(4)(zi(l)).value:0,p=s.wobble?XN(h)(l):l;return r.bind(s.wobble?i(m=>r.bind(t.pushAlpha(m.alpha))(()=>r.bind(t.strokePath(m.path)(_))(()=>o)))((()=>{const m=zi(l);return p.length<2?[]:Xr(gJ)(m)(!1)(p)})()):t.strokePath(LN(l))(_))(()=>{const m=u(s)(p);return f.hi>=.999?m:n.pure()})}},B_=t=>{const e=vJ(t),n=t.Monad0().Applicative0(),r=on(n);return i=>o=>u=>{const s=a=>{const c=Vt(f=>a.x>=f._2.x-1&&a.x<=f._2.x+f._2.w+1&&a.y>=f._2.y-1&&a.y<=f._2.y+f._2.h+1)(Ie(o.nodes));return c.tag==="Just"?v("Just",c._1._2):T};return r(a=>{const c=xr(a._1)(u.edges);if(c.tag==="Just")return e(i)(a._1)((()=>{const f=(()=>{if(0<a._2.length){const l=s(a._2[0]);if(l.tag==="Just")return Ne(m_(mr(7)(l._1))(Ne(a._2)))}return a._2})(),d=f.length-1|0;if(d>=0&&d<f.length){const l=s(f[d]);if(l.tag==="Just")return m_(mr(7)(l._1))(f)}return f})())((()=>{if(c._1.tag==="Retracted")return{lo:0,hi:0};if(c._1.tag==="Extended")return{lo:0,hi:1};if(c._1.tag==="Extending")return{lo:0,hi:c._1._2};if(c._1.tag==="Retracting"){if(c._1._1==="FromSource")return{lo:c._1._2,hi:1};if(c._1._1==="FromTarget")return{lo:0,hi:1-c._1._2};if(c._1._1==="FromBoth")return{lo:c._1._2/2,hi:1-c._1._2/2}}g()})());if(c.tag==="Nothing")return n.pure();g()})(Ie(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!Be(a=>0<a._2.length&&a._2[0].x>=s.x&&a._2[0].x<=s.x+s.w&&a._2[0].y>=s.y&&a._2[0].y<=s.y+s.h,Ie(t.edges))}g()},r=J(o=>u=>(o*31|0)+Pn(u)|0)(5381)(Un(e.frameTitle)),i=o=>{const u=fe(o)(t.nodes);if(u.tag==="Nothing")return!1;if(u.tag==="Just"){const s=u._1;return!Be(a=>{const c=a._2.length-1|0;return c>=0&&c<a._2.length&&a._2[c].x>=s.x&&a._2[c].x<=s.x+s.w&&a._2[c].y>=s.y&&a._2[c].y<=s.y+s.h},Ie(t.edges))}g()};return J(o=>u=>{const s=u._2;return eJ(a=>{if(a.tag==="Nothing")return v("Just",s);if(a.tag==="Just")return v("Just",{t:Wi(a._1.t)(s.t),angle:s.t>=a._1.t?s.angle:a._1.angle,bigCircle:a._1.bigCircle||s.bigCircle,frameHash:a._1.frameHash});g()})(u._1)(o)})(Q)(Tt(Ie(e.tokens))(o=>{if(o._2.tag==="Filling"){const u=o._2._1.node;return[b(u,{t:1,angle:(()=>{const s=xt(a=>(()=>{const c=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})()?v("Just",a._2):T)(Ie(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?ar(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=xr(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?ar(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=xr(o._2._1.edge)(t.edges);if(u.tag==="Just")return 1<u._1.length&&0<u._1.length?ar(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)+Pn(n)|0)(5381)(Un(t.frameTitle)),z_=t=>{const e=D_(t),n=t.Monad0().Applicative0(),r=on(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"?v("Just",l._1):l.tag==="Nothing"&&nJ(f._1)(s.visited)?v("Just",{t:1,angle:0,bigCircle:!1,frameHash:a}):T})())(f._1)(f._2)(d._1);if(d.tag==="Nothing")return n.pure();g()})(Ie(u.nodes))}},W_=t=>t,O_=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=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},q_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},da=t=>e=>{const n=ut.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=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=v("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=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=v("Just",o._4);continue}}g()}return i},SJ=t=>e=>{const n=He(t.angle),r=tn(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],Yr=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}},Ce=t=>e=>n=>r=>({x:(e-n)*tn(t.angle),y:(e+n)*He(t.angle)-r}),Nr=t=>{const e=Rt(n=>T,n=>r=>v("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 Ne(i);g()})();if(0<o.length){const s=br(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=br(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()},DJ=t=>{const e=Rt(n=>T,n=>r=>v("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()},IJ=t=>{const e=Rt(n=>T,n=>r=>v("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:q_(r.minX)(i.x),minY:q_(r.minY)(i.y),maxX:da(r.maxX)(i.x),maxY:da(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()},QJ=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:_n};return e.bind(t.fillStrokePath(Nr([o.ground.d,o.ground.c,o.top.c,o.top.d]))({color:Yr(.66)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(Nr([o.ground.b,o.ground.c,o.top.c,o.top.b]))({color:Yr(.82)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(Nr([o.top.a,o.top.b,o.top.c,o.top.d]))({color:Yr(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:qr}))))}},AJ=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>o=>{const u={color:r.tokenOutsideStroke,width:1,lineJoin:Te,lineCap:_n},s=o.x-5.5,a=o.x+5.5,c=o.y-5.5,f=o.y+5.5,d=i+11,l=Ce(n)(s)(c)(d),_=Ce(n)(a)(c)(d),h=Ce(n)(a)(f)(d),p=Ce(n)(s)(f)(d),m=Ce(n)(a)(f)(i),y=Ce(n)(a)(c)(i);return e.bind(t.fillStrokePath(Nr([Ce(n)(s)(f)(i),m,h,p]))({color:Yr(.66)(r.tokenOutsideFill),flat:!0})(u))(()=>e.bind(t.fillStrokePath(Nr([y,m,h,_]))({color:Yr(.82)(r.tokenOutsideFill),flat:!0})(u))(()=>t.fillStrokePath(Nr([l,_,h,p]))({color:Yr(1)(r.tokenOutsideFill),flat:!0})(u)))}},RJ=t=>{const e=AJ(t);return n=>r=>i=>o=>{if(o.tag==="Travelling"){const u=EJ(o._1.edge)(i.edges);return u.tag==="Just"?v("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 v("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}},FJ={angle:.5235987755982988,boxHeight:26,transparentBg:!0},BJ=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:Ce(t)(e.x)(e.y)(0),b:Ce(t)(r)(e.y)(0),c:Ce(t)(r)(n)(0),d:Ce(t)(e.x)(n)(0)},top:{a:Ce(t)(e.x)(e.y)(t.boxHeight),b:Ce(t)(r)(e.y)(t.boxHeight),c:Ce(t)(r)(n)(t.boxHeight),d:Ce(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},H_=t=>e=>M(n=>({np:n,box:BJ(t)(n)}))((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Ct($t.foldr,n(e.nodes,Ht))})()),zJ=t=>e=>[...Tt(H_(t)(e))(GJ),...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Tt(Ct($t.foldr,n(e.edges,Ht)))(M(r=>Ce(t)(r.x)(r.y)(0)))})()],WJ=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=da(1e-4)(ke(n*n+e*e)),i=e/r,o=n/r,u=t.to.y-i*7,s=t.to.x-o*7;return Nr([t.to,{x:s-i*3,y:u+o*3},{x:s+i*3,y:u-o*3}])},OJ=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>i=>o=>u=>s=>{const a=Ce(r)(s.x)(s.y)(0),c=Ce(r)(u.x)(u.y)(0);return e.Bind1().bind(t.strokePath(DJ([c,a]))({color:i.edge,width:1.5,lineJoin:Te,lineCap:An}))(()=>{const f=t.fillPath(WJ({from:c,to:a}))({color:i.arrowFill,flat:!0});return o?f:n.pure()})}},MJ=t=>{const e=OJ(t);return n=>r=>i=>{const o=Je(En,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)}},qJ=t=>{const e=QJ(t),n=RJ(t),r=MJ(t),i=t.Monad0(),o=I_(t),u=Ju(i.Applicative0())(zt);return s=>a=>c=>f=>{const d=aa(a),l=[...(()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,qt("Cons",h._4,_(h._6,p)));g()};return Tt(Ct($t.foldr,_(c.edges,Ht)))(r(s)(d))})(),...M(_=>({depth:_.box.depth,draw:e(s)(d)(_)}))(H_(s)(c)),...xt(n(s)(d)(c))((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,qt("Cons",h._4,_(h._6,p)));g()};return Ct($t.foldr,_(f.tokens,Ht))})())];return i.Bind1().bind(o(d)(s.transparentBg)(1)(IJ(zJ(s)(c))))(()=>u(_=>_.draw)(kt(_=>h=>ut.compare(_.depth)(h.depth))(l)))}},$_=(t,e)=>({tag:t,_1:e}),HJ=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=v("Just",o._4);continue}}g()}return i},$J=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},XJ=$_("ResolvedLabels"),YJ=t=>{const e=Vt(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return vo(t);g()},VJ=t=>e=>n=>{const r=n.frameTitle===""?0:40,i=Yu(e)(n.camera);return(()=>{if(t.outputAspect.tag==="Nothing")return W_;if(t.outputAspect.tag==="Just")return O_(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=HJ(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)(v("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}))(v("Just",{color:{r:0,g:0,b:0,a:255},width:1*o,lineJoin:Te,lineCap:An})))(()=>t.drawText({x:l,y:c+f/2,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:Uo,baseline:qr}))})}},ZJ=t=>{const e=F_(t),n=_a(t),r=t.Monad0(),i=r.Bind1(),o=I_(t),u=r.Applicative0(),s=B_(t),a=z_(t)(sa),c=dJ(t),f=A_(t),d=Q_(t),l=jJ(t);return _=>h=>p=>m=>y=>x=>N=>{const w=aa(_.theme),k=(()=>{if(N.tag==="ResolvedLabels")return e(w)(y)(x);if(N.tag==="SpringLabels")return n(w)(y)(x)(N._1);g()})();return i.bind(o(w)(_.transparentBg)(h)(m))(()=>i.bind((()=>{const L=i.bind(s(w)(y)(x))(()=>i.bind(a(w)(y)(x))(()=>i.bind(c(w)(y)(x))(()=>i.bind(f(w)(m)(y)(x))(()=>i.bind(d(Wx)(w)(y)(x))(()=>k)))));return p?L:u.pure()})())(()=>i.bind(_.watermark===""?t.Monad0().Applicative0().pure():t.drawText({x:m.vx+6,y:m.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:Zs,baseline:Px}))(()=>l(x.frameTitle)(m))))}},KJ=t=>{const e=t.Monad0(),n=F_(t),r=_a(t),i=e.Bind1(),o=B_(t),u=z_(t),s=A_(t),a=t.popTransform,c=Q_(t),f=t.popBakedTransform,d=t.popClip,l=t.popAlpha;return _=>h=>p=>m=>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},w=aa(_.theme),k=y.segment.layout,L=Ye(k),E={vx:L.x-1e3,vy:L.y-1e3,vw:L.w+2e3,vh:L.h+2e3},B=11*y.segment.placement.scale*h>=5?sa:rJ,X=(()=>{if(B==="LabelsHidden")return e.Applicative0().pure();if(B==="LabelsShown")return p.tag==="Leaf"?n(w)(k)(x):r(w)(k)(x)(p);g()})(),et=UJ(m)((()=>{const S=y.segment.path.length-1|0;return S>=0&&S<y.segment.path.length?v("Just",y.segment.path[S]):T})());return i.bind(t.pushAlpha(y.bgAlpha))(()=>i.bind(t.pushClip(et)(jo))(()=>i.bind(t.pushTransform(N))(()=>i.bind(o(w)(k)(x))(()=>i.bind(u(B)(w)(k)(x))(()=>i.bind(s(w)(E)(k)(x))(()=>i.bind(a)(()=>i.bind(t.pushBakedTransform(N))(()=>i.bind(c(Ox)(w)(k)(x))(()=>i.bind(f)(()=>i.bind(t.pushTransform(N))(()=>i.bind(X)(()=>i.bind(a)(()=>i.bind(d)(()=>l))))))))))))))}},tT=t=>e=>{const n=Yu(t)(e);return{vx:n.x,vy:n.y,vw:n.w,vh:n.h}},Vr=t=>e=>e.diving||e.levels.length>1?(()=>{if(t.outputAspect.tag==="Nothing")return W_;if(t.outputAspect.tag==="Just")return O_(t.outputAspect._1);g()})()(tT(e.rootLayout)(e.camera)):VJ(t)(e.rootLayout)({...vo(e).state,camera:e.camera}),X_=t=>{const e=qJ(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({...FJ,transparentBg:s.transparentBg})(s.theme)(vo(c).segment.layout)(vo(c).state);const f=Vr(s)(c),d=_=>h=>{if(h.length===0)return r.pure();const p=Rt(m=>T,m=>y=>v("Just",{head:m,tail:y}),h);if(p.tag==="Nothing")return r.pure();if(p.tag==="Just"){const m=p._1.head,y=p._1.tail;return i.bind((()=>{const x=o(s)(c.camera.zoom)(m.role==="Active"?a:Q)(_)(m);return c.diving||m.role==="Active"?x:r.pure()})())(()=>d(m)(y))}g()},l=Rt(_=>T,_=>h=>v("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)(YJ(c).state)(_.length===0&&a.tag!=="Leaf"?$_("SpringLabels",a):XJ))(()=>d(h)(_))}g()}},Y_=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},eT=fa(u_),V_=X_(u_),U_=t=>{const e=t.vx+t.vw-4,n=t.vy+t.vh-4,r=t.vx+4,i=t.vy+4,o=u=>{if(u.tag==="Leaf")return Q;if(u.tag==="Node")return 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:v("Just",r.width/r.height)},a=nN(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)(),_=Us(o)(U_(Vr(s)(i))(l))(u);return V_(s)(_.applied)(i)(c)(),_.springs}const d=Us(o)(U_(Vr(s)(i))(Q))(u);return V_(s)(d.applied)(i)(c)(),d.springs}},rT=t=>t,iT=(t=>t)("Light"),oT=rT("TransparentBackground"),rr=t=>"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")",bn=si(oi("Fixed",ui(0)(20)(4))),uT=t=>"translate("+bn(t.tx)+","+bn(t.ty)+") scale("+bn(t.sx)+","+bn(t.sy)+")",Lt=si(oi("Fixed",ui(0)(20)(2))),la=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,i=r>=0&&r<t.length?v("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(Lt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Lt((()=>{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(Lt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Lt((()=>{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(Lt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Lt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Lt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Lt((()=>{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(Lt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Lt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Lt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Lt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Lt((()=>{const o=r+5|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Lt((()=>{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)}}},ha=(()=>{const t=Kn("&")("&"),e=Kn("<")("<"),n=(()=>{const r=Kn(">")(">"),i=(()=>{const o=Kn('"')(""");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),aT=t=>{if(t.style==="RunText")return"<tspan>"+ha(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+ha(t.text)+"</tspan>";g()},Qe=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?v("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()}},j_={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:()=>j_},fT={pure:t=>e=>()=>t,Apply0:()=>j_},_T={Applicative0:()=>fT,Bind1:()=>gT},dT=t=>e=>'<defs><pattern id="'+t+'" x="0" y="0" width="'+Lt(e.tile)+'" height="'+Lt(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+Lt(e.tile)+'" height="'+Lt(e.tile)+'" fill="'+rr(e.bgColor)+'" fill-opacity="'+Lt(rt(e.bgColor.a)/255)+'"/>')+'<circle cx="'+Lt(e.tile/2)+'" cy="'+Lt(e.tile/2)+'" r="'+Lt(e.dotRadius)+'" fill="'+rr(e.dotColor)+'"/></pattern></defs><rect x="'+Lt(e.viewport.vx)+'" y="'+Lt(e.viewport.vy)+'" width="'+Lt(e.viewport.vw)+'" height="'+Lt(e.viewport.vh)+'" fill="url(#'+t+')"/>',Z_=t=>e=>'<path d="'+la(t)+'" fill="'+rr(e)+'" fill-opacity="'+Lt(rt(e.a)/255)+'"/>',lT=t=>e=>n=>r=>'<rect x="'+Lt(t.x)+'" y="'+Lt(t.y)+'" width="'+Lt(t.w)+'" height="'+Lt(t.h)+'" rx="'+Lt(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+rr(n._1.color)+'" fill-opacity="'+Lt(rt(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';g()})()+(()=>{if(r.tag==="Just")return' stroke="'+rr(r._1.color)+'" stroke-opacity="'+Lt(rt(r._1.color.a)/255)+'" stroke-width="'+Lt(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()})()+"/>",K_=t=>e=>'<path d="'+la(t)+'" fill="none" stroke="'+rr(e.color)+'" stroke-opacity="'+Lt(rt(e.color.a)/255)+'" stroke-width="'+Lt(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()})()+'"/>',t1=t=>{const e=rg(Qr(t.content));return'<text x="'+Lt(t.x)+'" y="'+Lt(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="'+rr(t.color)+'" fill-opacity="'+Lt(rt(t.color.a)/255)+'" font-size="'+Lt(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"?ha(e[0].text):ho("")(M(aT)(e)))+"</text>"},hT=t=>"matrix("+bn(t.a)+" "+bn(t.b)+" "+bn(t.c)+" "+bn(t.d)+" "+bn(t.e)+" "+bn(t.f)+")",e1={fillPath:t=>e=>n=>{const r=gu(n)(t);return()=>{const i=r();return Qe(Z_(i)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=gu(n)(t);return()=>{const i=r(),o=n.bake.value;return Qe(K_(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 Qe(Z_(o)(e.color)+K_(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 Qe(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"?v("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 Qe(t1((()=>{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=>Qe((()=>{const n='transform="'+hT(t)+'"';return(n===""?"<g>":"<g "+n+">")+t1(e)+"</g>"})()),pushTransform:t=>Qe((()=>{const e='transform="'+uT(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:Qe("</g>"),pushBakedTransform:t=>e=>{const n=e.bake;return()=>{n.value=v("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 Qe((()=>{const s='clip-path="url(#'+u+')"';return'<defs><clipPath id="'+u+'"><path d="'+la(o)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";g()})()+"/></clipPath></defs>"+(s===""?"<g>":"<g "+s+">")})())(n)()}},popClip:Qe("</g>"),pushBlend:t=>Qe((()=>{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:Qe("</g>"),pushAlpha:t=>Qe((()=>{const e='opacity="'+Lt(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:Qe("</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=>Qe('<rect x="'+Lt(e.viewport.vx)+'" y="'+Lt(e.viewport.vy)+'" width="'+Lt(e.viewport.vw)+'" height="'+Lt(e.viewport.vh)+'" fill="'+rr(t)+'" opacity="'+Lt(rt(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,Qe(dT("bg-dots-"+ie(r))(t))(e)()}},measureText:t=>e=>n=>{const r=Af(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Rf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>$f,Monad0:()=>_T},pT=X_(e1),mT=fa(e1),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=Vr(o)(i);return{viewBox:Lt(u.vx)+" "+Lt(u.vy)+" "+Lt(u.vw)+" "+Lt(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=Us(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:Vr(u)(r),bake:l})():Q})())(o);return{parts:yT(t)(s.applied)(e)(n)(r),springs:s.springs}},Oi=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(i=>n(i._1)(i._2)),Apply0:()=>n1(t)}),n1=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=Oi(t);return i=>o=>r.bind(i)(u=>r.bind(o)(s=>Mi(t).pure(u(s))))})(),Functor0:()=>n}},Mi=t=>({pure:e=>n=>t.Applicative0().pure(b(e,n)),Apply0:()=>n1(t)}),NT=t=>{const e={Applicative0:()=>Mi(t),Bind1:()=>Oi(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},pa=(t,e)=>({tag:t,_1:e}),zn=(t,e)=>({tag:t,_1:e}),we=NT(Hn),Ot=Oi(Hn),Ae=we.state(t=>b(t,t)),ue=Mi(Hn),Wn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},r1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},fu=Ju(ue)(zt),On=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},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=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=v("Just",o._4);continue}}g()}return i},TT=(()=>{const t=$e.unfoldr(e=>{if(e.tag==="Nil")return T;if(e.tag==="Cons")return v("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._3,n(r._6,i)));g()};return n(e,Ht)})())})(),wT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},_u=t=>e=>n=>J(r=>i=>t.Bind1().bind(r)(o=>e(o)(i)))(t.Applicative0().pure(n)),vT=J(t=>e=>K(C)(e)()(t))(Q),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(C)(a._1)()(s),i=a._2;continue}g()}return u})(Q);return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._3,n(r._6,i)));g()};return n(e,Ht)})())})(),LT=zn("Exit"),kT=t=>pa("Par",t),i1=t=>pa("Seq",t),ET=t=>e=>n=>{const r=ur(Xt,T,i=>i._1===t,n);if(r.tag==="Just"){const i=$n(Xt,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 Wt(n)(b(t,e));g()},CT=t=>e=>M(n=>n._1===t?b(n._1,{...n._2,label:v("Just",e)}):b(n._1,n._2)),ve=t=>we.state(e=>b(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:v("Just",{msg:t,line:e.currentLine,column:e.currentColumn})};g()})())),ST=t=>Ot.bind(we.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>Ot.bind(Ae)(e=>{if(e.error.tag==="Just")return ue.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!Wn(t.op._1.id)(e.currNodes))return ve("cannot enter node "+t.op._1.id+": does not exist");if(!r1(t.op._1.id)(e.interiorOf))return ve("cannot enter node "+t.op._1.id+": it has no `inside` block");if(ze(fn)(t.op._1.id)(e.enterStack))return ve("cannot enter node "+t.op._1.id+": already entered");const n=t.op._1;return we.state(r=>b(void 0,{...r,enterStack:Wt(r.enterStack)(n.id),scenes:Wt(r.scenes)(co("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=ni(e.enterStack);if(n.tag==="Nothing")return ve("`exit` without a matching `enter`");if(n.tag==="Just"){const r=n._1.init;return we.state(i=>b(void 0,{...i,enterStack:r,scenes:Wt(i.scenes)(Il)}))}g()}return ue.pure()}g()})),GT=t=>Ot.bind(Ae)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ie(e.kfCounter);if(Be(i=>i.id===n,e.keyframes))return ve("duplicate frame name "+n);const r={...e,keyframes:Wt(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges}),kfCounter:e.kfCounter+1|0,currentKf:v("Just",n)};return we.state(i=>b(void 0,r))}),PT=fu(t=>Ot.bind(Ae)(e=>{if(e.error.tag==="Just")return ue.pure();if(e.error.tag==="Nothing")return r1(t.node)(e.interiorOf)?ve("node "+t.node+" has more than one `inside` block"):we.state(n=>b(void 0,{...n,interiorOf:K(C)(t.node)(t.doc)(n.interiorOf)}));g()})),DT=t=>e=>{const n=e.from+"->"+e.to,r=e.newFrom+"->"+e.newTo,i=Pt("Left","cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist"),o=On(n)(t.currEdges)?Pt("Right",void 0):i;return(()=>{if(o.tag==="Left"){const u=o._1;return s=>Pt("Left",u)}if(o.tag==="Right"){const u=o._1;return s=>s(u)}g()})()(()=>{const u="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newFrom;if(!Wn(e.newFrom)(t.currNodes))return Pt("Left",u);const s="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo;if(!Wn(e.newTo)(t.currNodes))return Pt("Left",s);const a="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists";return n!==r&&On(r)(t.currEdges)?Pt("Left",a):Pt("Right",{nextCurrEdges:K(C)(r)()(ii(C)(n)(t.currEdges)),newId:r,newEdge:{id:r,from:{node:e.newFrom,port:T},to:{node:e.newTo,port:T}}})})},o1={graphNodes:[],graphEdges:Q,currNodes:Q,currEdges:Q,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:T,currentLine:0,currentColumn:0,error:T,enterStack:[],interiorOf:Q},u1=t=>e=>Ot.bind(Ae)(n=>{const r="ev-"+ie(n.eventCounter);return Ot.bind((()=>{const i={...n,eventCounter:n.eventCounter+1|0};return we.state(o=>b(void 0,i))})())(()=>ue.pure({events:[{id:r,kind:e,when:t}],firstId:v("Just",r),lastId:v("Just",r)}))}),IT=t=>e=>{if(e.tag==="Token"){const n=e._1;return Ot.bind(Ae)(r=>{const i=!Wn(n.from)(r.currNodes),o=!Wn(n.to)(r.currNodes);if(i||o)return Ot.bind(ve(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 On(s)(r.currEdges)?u1(t)(hc("SendToken",{from:n.from,to:n.to,edge:s,direction:Pl,labels:n.labels})):On(u)(r.currEdges)?u1(t)(hc("SendToken",{from:n.from,to:n.to,edge:u,direction:Dl,labels:n.labels})):Ot.bind(ve("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})},QT=t=>e=>{if(0<t.length){const n=t[0];return Ot.bind(we.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>ve(e))}return ve(e)},AT=t=>xt(e=>JT(e)(t.graphEdges))(Ct(ti,TT(t.currEdges))),RT=t=>e=>{const n=st(i=>i.from.node===e.id||i.to.node===e.id,AT(t)),r=_u(Qa)(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(!On(u)(t.currEdges))return Pt("Left",c);const f="via "+o.from+" "+o.to+": no edge "+e.id+"\u2192"+o.to;if(!On(s)(t.currEdges))return Pt("Left",f);const d="via "+o.from+" "+o.to+": would create "+o.from+"\u2192"+o.to+" but it already exists";return On(a)(t.currEdges)||wT(a)(i.synthesized)?Pt("Left",d):Pt("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:Q,synthesized:Q})(e.via);return(()=>{if(r.tag==="Left"){const i=r._1;return o=>Pt("Left",i)}if(r.tag==="Right"){const i=r._1;return o=>o(i)}g()})()(i=>{const o=i.consumed,u=st(s=>!On(s.id)(o),n);return u.length===0?Pt("Right",{nextCurrEdges:Ee(C.compare,Le,Cn(C.compare,t.currEdges,vT(M(s=>s.id)(n))),bT((()=>{const s=a=>{if(a.tag==="Leaf")return Q;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}):Pt("Left","cannot delete node "+e.id+": still connected ("+ho(", ")(M(s=>s.from.node+"\u2192"+s.to.node)(u))+"). Use -edge to drop them or `via a b` to merge "+e.id+"'s endpoints.")})},s1=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq")return Tt(t._1)(s1);g()},FT=Ot.bind(Ae)(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?ve("entered node "+t.enterStack[e]+" was never exited"):ue.pure()}g()}),BT=t=>({nodes:M(Yi)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,qt("Cons",n._4,e(n._6,r)));g()};return Ct($t.foldr,e(t.graphEdges,Ht))})(),constraints:[]}),zT=t=>{if(t.tag==="AddNode"){const e=t._1;return we.state(n=>b(void 0,{...n,graphNodes:ET(e.id)({id:e.id,size:b(1,1),ports:[],label:v("Just",e.label),shape:e.shape})(n.graphNodes),currNodes:K(C)(e.id)()(n.currNodes)}))}if(t.tag==="DelNode"){const e=t._1;return Ot.bind(Ae)(n=>{if(!Wn(e.id)(n.currNodes))return ve("cannot delete node "+e.id+": does not exist");const r=RT(n)(e);if(r.tag==="Left")return ve(r._1);if(r.tag==="Right"){const i=r._1;return we.state(o=>b(void 0,{...o,currNodes:ii(C)(e.id)(o.currNodes),currEdges:i.nextCurrEdges,graphEdges:Ee(C.compare,Le,i.synthesized,o.graphEdges)}))}g()})}if(t.tag==="ModNode"){const e=t._1;return Ot.bind(Ae)(n=>{if(!Wn(e.id)(n.currNodes))return ve("cannot modify node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=e.label._1;return we.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 Ot.bind(Ae)(n=>{const r=!Wn(e.from)(n.currNodes),i=!Wn(e.to)(n.currNodes);if(r||i)return ve("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 we.state(u=>b(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 Ot.bind(Ae)(n=>{const r=e.from+"->"+e.to;return On(r)(n.currEdges)?we.state(i=>b(void 0,{...i,currEdges:ii(C)(r)(i.currEdges)})):ve("cannot delete edge "+e.from+"\u2192"+e.to+": does not exist")})}if(t.tag==="RepointEdge"){const e=t._1;return Ot.bind(Ae)(n=>{const r=DT(n)(e);if(r.tag==="Left")return ve(r._1);if(r.tag==="Right"){const i=r._1;return we.state(o=>b(void 0,{...o,currEdges:i.nextCurrEdges,graphEdges:K(C)(i.newId)(i.newEdge)(o.graphEdges)}))}g()})}return ue.pure()},WT=t=>Ot.bind(we.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>zT(t.op)),OT=t=>e=>Ot.bind(fu(WT)(e))(()=>Ot.bind(Ae)(n=>{const r=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ie(n.kfCounter);if(Be(o=>o.id===r,n.keyframes))return ve("duplicate frame name "+r);const i={...n,keyframes:Wt(n.keyframes)({id:r,nodes:n.currNodes,edges:n.currEdges}),kfCounter:n.kfCounter+1|0,currentKf:v("Just",r),scenes:(()=>{if(n.currentKf.tag==="Nothing")return n.scenes;if(n.currentKf.tag==="Just")return Wt(n.scenes)(co("Structural",{from:n.currentKf._1,to:r,focus:T}));g()})()};return we.state(o=>b(void 0,i))})),MT=t=>e=>{const n=Rt(r=>T,r=>i=>v("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 Ot.bind(qi(t)(n._1.head))(i=>Ot.bind(_u({Applicative0:()=>Mi(Hn),Bind1:()=>Oi(Hn)})(o=>u=>Ot.bind(qi((()=>{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 v("Just",o.firstId._1);if(o.firstId.tag==="Nothing")return s.firstId;g()})(),lastId:(()=>{if(s.lastId.tag==="Just")return v("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return o.lastId;g()})()})))(i)(r))(o=>ue.pure(o)))}g()},qT=t=>e=>{const n=Rt(r=>T,r=>i=>v("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 Ot.bind(qi(t)(n._1.head))(i=>Ot.bind(HT((()=>{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 v("Just",i.lastId._1);if(i.lastId.tag==="Nothing")return o.lastId;g()})()})))}g()},qi=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return Ot.bind(we.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>IT(t)(n.op))}if(e.tag==="Seq")return MT(t)(e._1);if(e.tag==="Par")return qT(t)(e._1);g()},HT=t=>_u({Applicative0:()=>Mi(Hn),Bind1:()=>Oi(Hn)})(e=>n=>Ot.bind(qi(t)(n))(r=>ue.pure({events:[...e.events,...r.events],firstId:(()=>{if(e.firstId.tag==="Just")return v("Just",e.firstId._1);if(e.firstId.tag==="Nothing")return r.firstId;g()})(),lastId:(()=>{if(r.lastId.tag==="Just")return v("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;g()})()})))({events:[],firstId:T,lastId:T}),$T=t=>Ot.bind(Ae)(e=>{if(e.currentKf.tag==="Nothing")return ve("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return Ot.bind(qi(Gl)(t))(r=>Ot.bind(Ae)(i=>{const o={...i,scenes:Wt(i.scenes)(co("DataFlow",{keyframe:n,events:r.events,focus:T}))};return we.state(u=>b(void 0,o))}))}g()}),XT=t=>Ot.bind(Ae)(e=>{if(e.error.tag==="Just")return ue.pure();if(e.error.tag==="Nothing"){const n=s1(t.ops),r=st(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=st(u=>u.op.tag==="Enter"||u.op.tag==="Exit",n),o=st(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?QT(i)("`enter`/`exit` cannot be mixed with flow tokens in the same frame"):Ot.bind((()=>{const u=OT(t.name)(r);return r.length!==0?u:ue.pure()})())(()=>Ot.bind((()=>{const u=GT(t.name);return r.length===0&&o.length!==0?u:ue.pure()})())(()=>Ot.bind((()=>{const u=$T(t.ops);return o.length!==0?u:ue.pure()})())(()=>fu(ST)(i))))}g()}),a1=t=>Ot.bind(PT(t.interiors))(()=>Ot.bind(fu(XT)(t.frames))(()=>Ot.bind(FT)(()=>Ot.bind(Ae)(e=>{if(e.error.tag==="Just")return ue.pure(Pt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=YT(t.interiors);if(n.tag==="Left")return ue.pure(Pt("Left",n._1));if(n.tag==="Right")return ue.pure(Pt("Right",{seed:t.seed,graph:BT(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1}))}g()})))),YT=t=>{const e=_u(Qa)(n=>r=>{const i=a1(r.doc)(o1)._1;return(()=>{if(i.tag==="Left"){const o=i._1;return u=>Pt("Left",o)}if(i.tag==="Right"){const o=i._1;return u=>u(o)}g()})()(o=>Pt("Right",K(C)(r.node)(o)(n)))})(Q)(t);if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right")return Pt("Right",e._1);g()},Ur=(t,e)=>({tag:"ParseError",_1:t,_2:e}),R=(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)}},c1={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(R(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:()=>c1},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(Ra)(c._1);continue}if(c.tag==="Stop"){s=!1,a=e.Applicative0().pure(Kr("Done",b(c._2,c._1)));continue}g()}return a};return t.tailRecM(i)(o=>r(n,VT,UT,(u,s)=>du("Stop",u,Pt("Left",s)),(u,s)=>du("Stop",u,Pt("Right",s))))}},g1=(t,e,n,r,i)=>i(t,t._2),tw={index:0,line:1,column:1},ew=(t=>{const e=KT(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(Vi)(e(R(n,tw,!1))(r))})(R1),f1={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?R(a._1,a._2,!0):a;return e(d,r,i,o,(l,_)=>r(h=>u(d._3&&!l._3?R(l._1,l._2,!0):l,c(_))))}))),Functor0:()=>c1},_1={pure:t=>(e,n,r,i,o)=>o(e,t),Apply0:()=>f1},nw={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?R(a._1,a._2,!0):a,r,i,o,u)))),Apply0:()=>f1},rw={Applicative0:()=>_1,Bind1:()=>nw},lu=t=>(e,n,r,i,o)=>n(u=>g1(e,n,r,i,(s,a)=>n(c=>i(e._3&&!s._3?R(s._1,s._2,!0):s,Ur(t,a))))),iw={empty:lu("No alternative"),Alt0:()=>ZT},ow={Applicative0:()=>_1,Plus1:()=>iw},un=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return i=>t.tailRecM(o=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(Ra)(i))(r.pure(Kr("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return Kr("Loop",qt("Cons",u._1,o));if(u.tag==="Done")return Kr("Done",(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=qt("Cons",h._1,_),f=h._2;continue}g()}return l})(Ht)(o));g()})())))(Ht)})({tailRecM:t=>e=>(n,r,i,o,u)=>{const s=(a,c,f)=>t(c)(a,r,i,o,(d,l)=>{const _=a._3&&!d._3?R(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:()=>rw})(ow),Gt=t=>e=>{const n=lu("Expected "+e);return(r,i,o,u,s)=>{const a=r._1,c=r._2;return i(f=>t(R(a,c,!1),i,o,(d,l)=>{const _=d._3;return i(h=>_?u(d,l):n(r,i,o,u,s))},s))}},ma=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(R(d._1,d._2,u),l):o(e,void 0))};return n(d=>n(l=>t(R(s,a,!1),n,r,(_,h)=>f(R(_._1,_._2,!1),h),(_,h)=>n(p=>n(m=>lu("Negated parser succeeded")(_,n,r,f,(y,x)=>n(N=>o(_._3&&!y._3?R(y._1,y._2,!0):y,x))))))))})},uw=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return v("Just",n);if(r.tag==="Just")return v("Just",(i,o,u,s,a)=>{const c=i._1,f=i._2;return o(d=>n(R(c,f,!1),o,u,(l,_)=>{const h=l._3;return o(p=>h?s(l,_):r._1(i,o,u,s,a))},a))});g()})(T);return n=>{const r=e(n);if(r.tag==="Nothing")return lu("No alternative");if(r.tag==="Just")return r._1;g()}},sw=t=>e=>n=>(r,i,o,u,s)=>i(a=>i(c=>i(f=>i(d=>t(r,i,o,u,(l,_)=>i(h=>i(p=>{const m=r._3&&!l._3?R(l._1,l._2,!0):l;return n(m,i,o,u,(y,x)=>i(N=>{const w=m._3&&!y._3?R(y._1,y._2,!0):y;return i(k=>i(L=>{const E=r._3&&!w._3?R(w._1,w._2,!0):w;return e(E,i,o,u,(B,X)=>i(et=>s(E._3&&!B._3?R(B._1,B._2,!0):B,x)))}))}))}))))))),ya=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=Th()(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)-Vn(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},aw=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===""?ya(a)(d._1.head)(f):ya(a)(d._1.head)(d._1.tail),i=d._1.tail,o=f;continue}g()}return s},jt=t=>(e,n,r,i,o)=>{const u=po(e._1);if(u.tag==="Nothing")return i(e,Ur("Unexpected EOF",e._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return i(e,Ur("Expected Char",e._2));if(u._1.head>=0&&u._1.head<=65535){const s=bc(u._1.head);return t(s)?o(R(u._1.tail,ya(e._2)(u._1.head)(u._1.tail),!0),s):i(e,Ur("Predicate unsatisfied",e._2))}}g()},xa=(t,e,n,r,i)=>t._1===""?i(R(t._1,t._2,!0),void 0):r(t,Ur("Expected EOF",t._2)),cw=t=>(e,n,r,i,o)=>{const u=t(e._1);if(u.tag==="Left")return i(e,Ur(u._1,e._2));if(u.tag==="Right")return o(R(u._1.remainder,aw(e._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);g()},jr=t=>cw(e=>{const n=al(t)(e);return n.tag==="Just"?Pt("Right",{value:t,consumed:t,remainder:n._1}):Pt("Left","Expected "+b1(t))}),gw=jt(t=>!0),d1=(t,e)=>({tag:t,_1:e}),fw=Kt(C)(zt),_w=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=v("Just",o._4);continue}}g()}return i},l1=uw(zt),h1=(()=>{const t=jt(e=>e===" "||e===" "||e===`
|
|
9
|
+
`||e==="\r");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?R(s._1,s._2,!0):s,void 0))))})(),Na=(t,e,n,r,i)=>e(o=>jr("#")(t,e,n,r,(u,s)=>e(a=>{const c=un(jt(d=>d!==`
|
|
10
|
+
`)),f=t._3&&!u._3?R(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>i(f._3&&!l._3?R(l._1,l._2,!0):l,void 0))))}))),dw=Gt((()=>{const t=Gt(jt(n=>n==="}"))("'}'"),e=jt(n=>n===`
|
|
11
|
+
`||n==="\r");return(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>r(f=>t(R(s,a,!1),r,i,(d,l)=>r(_=>{const h=n._1,p=n._2;return r(m=>r(y=>Na(R(h,p,!1),r,i,(x,N)=>{const w=x._3;return r(k=>{if(w)return o(x,N);const L=n._1,E=n._2;return r(B=>r(X=>e(R(L,E,!1),r,i,(et,S)=>{const P=et._3;return r(V=>P?o(et,S):xa(n,r,i,o,u))},(et,S)=>r(P=>u(et,void 0)))))})},(x,N)=>r(w=>u(x,void 0)))))}),(d,l)=>r(_=>u(R(s,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),je=(()=>{const t=un((e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>h1(R(u,s,!1),n,r,(c,f)=>{const d=c._3;return n(l=>d?i(c,f):Na(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?R(s._1,s._2,!0):s,void 0))))})(),gn=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>je(t._3&&!c._3?R(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>h1(R(s,a,!1),e,n,(f,d)=>{const l=f._3;return e(_=>l?r(f,d):Na(t,e,n,r,u))},u))}),p1=(()=>{const t=Gt(jt(e=>e==="|"))("'|'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=un(jt(l=>l!=="|")),d=e._3&&!s._3?R(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(p=>{const m=Gt(Gt(jt(x=>x==="|"))("'|'"))("closing '|'"),y=d._3&&!_._3?R(_._1,_._2,!0):_;return n(x=>m(y,n,r,i,(N,w)=>n(k=>o(y._3&&!N._3?R(N._1,N._2,!0):N,fr(Ct($t.foldr,h))))))})))})))})(),hu=jt(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),Me=(()=>{const t=un(jt(e=>e===" "||e===" "));return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?R(s._1,s._2,!0):s,void 0))))})(),lw=(()=>{const t=Gt(jt(e=>e==="\\"))("'\\\\'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=e._3&&!s._3?R(s._1,s._2,!0):s;return n(d=>gw(f,n,r,i,(l,_)=>n(h=>o(f._3&&!l._3?R(l._1,l._2,!0):l,_==="n"?`
|
|
12
|
+
`:_==="t"?" ":_==="r"?"\r":_))))})))})(),hw=(()=>{const t=jt(e=>e!=='"'&&e!=="\\"&&e!==`
|
|
13
|
+
`);return(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>lw(R(u,s,!1),n,r,(c,f)=>n(d=>t(e,n,r,i,o)),o))}})(),Ja=(()=>{const t=Gt(jt(e=>e==='"'))(`'"'`);return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=un(hw),d=e._3&&!s._3?R(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(p=>{const m=Gt(Gt(jt(x=>x==='"'))(`'"'`))(`closing '"' (unterminated string)`),y=d._3&&!_._3?R(_._1,_._2,!0):_;return n(x=>m(y,n,r,i,(N,w)=>n(k=>o(y._3&&!N._3?R(N._1,N._2,!0):N,fr(Ct($t.foldr,h))))))})))})))})(),pw=(()=>{const t=Gt(jt(e=>e===":"))("':'");return(e,n,r,i,o)=>n(u=>Me(e,n,r,i,(s,a)=>n(c=>Gt((f,d,l,_,h)=>{const p=f._1,m=f._2;return d(y=>{const x=(N,w)=>{const k=N._3;return d(L=>{if(k)return _(N,w);const E=f._1,B=f._2;return d(X=>p1(R(E,B,!1),d,l,(et,S)=>{const P=et._3;return d(V=>P?_(et,S):Ja(f,d,l,_,h))},h))})};return d(N=>t(R(p,m,!1),d,l,x,(w,k)=>d(L=>d(E=>Me(w,d,l,x,(B,X)=>d(et=>{const S=un(jt(V=>V!==`
|
|
14
|
+
`&&V!=="\r"&&V!=="#"&&V!=="}")),P=w._3&&!B._3?R(B._1,B._2,!0):B;return d(V=>S(P,d,l,x,(U,O)=>d(z=>h(P._3&&!U._3?R(U._1,U._2,!0):U,gh(fr(Ct($t.foldr,O)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(e._3&&!s._3?R(s._1,s._2,!0):s,n,r,i,o))))})(),mw=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>p1(R(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):Ja(t,e,n,r,i))},i))},Hi=jt(t=>t>="0"&&t<="9"),be=(()=>{const t=Gt(jt(e=>e==="_"))("'_'");return(e,n,r,i,o)=>n(u=>{const s=(f,d)=>n(l=>{const _=un((()=>{const p=Gt(jt(y=>y==="_"))("'_'"),m=Gt(jt(y=>y==="-"))("'-'");return(y,x,N,w,k)=>{const L=y._1,E=y._2;return x(B=>hu(R(L,E,!1),x,N,(X,et)=>{const S=X._3;return x(P=>{if(S)return w(X,et);const V=y._1,U=y._2;return x(O=>Hi(R(V,U,!1),x,N,(z,F)=>{const G=z._3;return x(D=>{if(G)return w(z,F);const I=y._1,A=y._2;return x(H=>p(R(I,A,!1),x,N,($,Y)=>{const q=$._3;return x(W=>q?w($,Y):m(y,x,N,w,k))},k))})},k))})},k))}})()),h=e._3&&!f._3?R(f._1,f._2,!0):f;return n(p=>_(h,n,r,i,(m,y)=>n(x=>o(h._3&&!m._3?R(m._1,m._2,!0):m,io(d)+fr(Ct($t.foldr,y))))))}),a=e._1,c=e._2;return n(f=>hu(R(a,c,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?i(d,l):t(e,n,r,i,s))},s))})})(),yw=Gt((t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>Ja(R(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)"),m1=(t,e,n,r,i)=>e(o=>Me(t,e,n,r,(u,s)=>e(a=>{const c=Gt(be)("attribute key"),f=t._3&&!u._3?R(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=f._3&&!l._3?R(l._1,l._2,!0):l;return e(m=>Me(p,e,n,r,(y,x)=>e(N=>{const w=Gt(Gt(jt(L=>L===":"))("':'"))("':'"),k=p._3&&!y._3?R(y._1,y._2,!0):y;return e(L=>w(k,e,n,r,(E,B)=>e(X=>{const et=k._3&&!E._3?R(E._1,E._2,!0):E;return e(S=>Me(et,e,n,r,(P,V)=>e(U=>{const O=Gt(be)("attribute value"),z=et._3&&!P._3?R(P._1,P._2,!0):P;return e(F=>O(z,e,n,r,(G,D)=>e(I=>{const A=z._3&&!G._3?R(G._1,G._2,!0):G;return e(H=>Me(A,e,n,r,($,Y)=>e(q=>i(A._3&&!$._3?R($._1,$._2,!0):$,b(_,D)))))})))})))})))})))})))}))),xw=(t,e,n,r,i)=>e(o=>be(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?R(u._1,u._2,!0):u;return e(f=>Me(c,e,n,r,(d,l)=>e(_=>{const h=Gt((m,y,x,N,w)=>{const k=m._1,L=m._2;return y(E=>jr("->")(R(k,L,!1),y,x,(B,X)=>{const et=B._3;return y(S=>et?N(B,X):jr("<-")(m,y,x,N,w))},w))})("'->' or '<-'"),p=c._3&&!d._3?R(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?R(y._1,y._2,!0):y;return e(k=>Me(w,e,n,r,(L,E)=>e(B=>{const X=Gt(be)("target node identifier"),et=w._3&&!L._3?R(L._1,L._2,!0):L;return e(S=>X(et,e,n,r,(P,V)=>e(U=>{const O=un((F,G,D,I,A)=>{const H=F._3;return G($=>G(Y=>Me(F,G,D,(q,W)=>I(R(q._1,q._2,H),W),(q,W)=>G(tt=>G(j=>{const gt=F._3&&!q._3?R(q._1,q._2,!0):q;return mw(gt,G,D,(_t,at)=>I(R(_t._1,_t._2,H),at),(_t,at)=>G(yt=>A(gt._3&&!_t._3?R(_t._1,_t._2,!0):_t,at)))})))))}),z=et._3&&!P._3?R(P._1,P._2,!0):P;return e(F=>O(z,e,n,r,(G,D)=>e(I=>(()=>{if(x==="<-"){const H=zn("Token",{from:V,to:s,labels:M(gc)(Ct($t.foldr,D))});return($,Y,q,W,tt)=>tt($,H)}const A=zn("Token",{from:s,to:V,labels:M(gc)(Ct($t.foldr,D))});return(H,$,Y,q,W)=>W(H,A)})()(z._3&&!G._3?R(G._1,G._2,!0):G,e,n,r,i))))})))})))})))})))}))),Nw=(t,e,n,r,i)=>e(o=>Hi(t,e,n,r,(u,s)=>e(a=>{const c=un(Hi),f=t._3&&!u._3?R(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=ld(io(s)+fr(Ct($t.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(y,x,N,w,k)=>k(y,m)}if(p.tag==="Nothing")return(m,y,x,N,w)=>w(m,0);g()})()(f._3&&!l._3?R(l._1,l._2,!0):l,e,n,r,i)})))}))),$i=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>jr(t)(e,n,r,(a,c)=>i(R(a._1,a._2,u),c),(a,c)=>n(f=>{const d=ma((()=>{const _=Gt(jt(p=>p==="_"))("'_'"),h=Gt(jt(p=>p==="-"))("'-'");return(p,m,y,x,N)=>{const w=p._1,k=p._2;return m(L=>hu(R(w,k,!1),m,y,(E,B)=>{const X=E._3;return m(et=>{if(X)return x(E,B);const S=p._1,P=p._2;return m(V=>Hi(R(S,P,!1),m,y,(U,O)=>{const z=U._3;return m(F=>{if(z)return x(U,O);const G=p._1,D=p._2;return m(I=>_(R(G,D,!1),m,y,(A,H)=>{const $=A._3;return m(Y=>$?x(A,H):h(p,m,y,x,N))},N))})},N))})},N))}})()),l=e._3&&!a._3?R(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(R(h._1,h._2,u),p),(h,p)=>n(m=>{const y=l._3&&!h._3?R(h._1,h._2,!0):h;return n(x=>je(y,n,r,(N,w)=>i(R(N._1,N._2,u),w),(N,w)=>n(k=>o(y._3&&!N._3?R(N._1,N._2,!0):N,t))))})))})))},Jw=(t,e,n,r,i)=>e(o=>gn(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?R(u._1,u._2,!0):u;return e(f=>$i("via")(c,e,n,r,(d,l)=>e(_=>{const h=c._3&&!d._3?R(d._1,d._2,!0):d;return e(p=>be(h,e,n,r,(m,y)=>e(x=>{const N=h._3&&!m._3?R(m._1,m._2,!0):m;return e(w=>gn(N,e,n,r,(k,L)=>e(E=>{const B=N._3&&!k._3?R(k._1,k._2,!0):k;return e(X=>be(B,e,n,r,(et,S)=>e(P=>i(B._3&&!et._3?R(et._1,et._2,!0):et,{from:y,to:S}))))})))})))})))}))),ir=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>jr(t)(e,n,r,(a,c)=>i(R(a._1,a._2,u),c),(a,c)=>n(f=>{const d=ma((()=>{const _=Gt(jt(p=>p==="_"))("'_'"),h=Gt(jt(p=>p==="-"))("'-'");return(p,m,y,x,N)=>{const w=p._1,k=p._2;return m(L=>hu(R(w,k,!1),m,y,(E,B)=>{const X=E._3;return m(et=>{if(X)return x(E,B);const S=p._1,P=p._2;return m(V=>Hi(R(S,P,!1),m,y,(U,O)=>{const z=U._3;return m(F=>{if(z)return x(U,O);const G=p._1,D=p._2;return m(I=>_(R(G,D,!1),m,y,(A,H)=>{const $=A._3;return m(Y=>$?x(A,H):h(p,m,y,x,N))},N))})},N))})},N))}})()),l=e._3&&!a._3?R(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(R(h._1,h._2,u),p),(h,p)=>n(m=>o(l._3&&!h._3?R(h._1,h._2,!0):h,void 0))))})))},Tw=(t,e,n,r,i)=>e(o=>ir("+edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?R(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),p=c._3&&!d._3?R(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?R(y._1,y._2,!0):y;return e(k=>gn(w,e,n,r,(L,E)=>e(B=>{const X=Gt(be)("target node identifier"),et=w._3&&!L._3?R(L._1,L._2,!0):L;return e(S=>X(et,e,n,r,(P,V)=>e(U=>i(et._3&&!P._3?R(P._1,P._2,!0):P,zn("AddEdge",{from:x,to:V})))))})))})))})))}))),ww=(t,e,n,r,i)=>e(o=>ir("-edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?R(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),p=c._3&&!d._3?R(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?R(y._1,y._2,!0):y;return e(k=>gn(w,e,n,r,(L,E)=>e(B=>{const X=Gt(be)("target node identifier"),et=w._3&&!L._3?R(L._1,L._2,!0):L;return e(S=>X(et,e,n,r,(P,V)=>e(U=>i(et._3&&!P._3?R(P._1,P._2,!0):P,zn("DelEdge",{from:x,to:V})))))})))})))})))}))),vw=(t,e,n,r,i)=>e(o=>ir("-node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?R(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),p=c._3&&!d._3?R(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=un((L,E,B,X,et)=>{const S=L._3;return Jw(L,E,B,(P,V)=>X(R(P._1,P._2,S),V),et)}),k=p._3&&!y._3?R(y._1,y._2,!0):y;return e(L=>w(k,e,n,r,(E,B)=>e(X=>i(k._3&&!E._3?R(E._1,E._2,!0):E,zn("DelNode",{id:x,via:Ct($t.foldr,B)})))))})))})))}))),bw=(t,e,n,r,i)=>e(o=>ir("enter")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?R(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),p=c._3&&!d._3?R(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>i(p._3&&!y._3?R(y._1,y._2,!0):y,zn("Enter",{id:x})))))})))}))),Lw=(t,e,n,r,i)=>e(o=>ir("exit")(t,e,n,r,(u,s)=>e(a=>i(t._3&&!u._3?R(u._1,u._2,!0):u,LT)))),kw=(t,e,n,r,i)=>e(o=>ir("~edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?R(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),p=c._3&&!d._3?R(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?R(y._1,y._2,!0):y;return e(k=>gn(w,e,n,r,(L,E)=>e(B=>{const X=Gt(be)("target node identifier"),et=w._3&&!L._3?R(L._1,L._2,!0):L;return e(S=>X(et,e,n,r,(P,V)=>e(U=>{const O=et._3&&!P._3?R(P._1,P._2,!0):P;return e(z=>je(O,e,n,r,(F,G)=>e(D=>{const I=Gt(jr("->"))("'->'"),A=O._3&&!F._3?R(F._1,F._2,!0):F;return e(H=>I(A,e,n,r,($,Y)=>e(q=>{const W=A._3&&!$._3?R($._1,$._2,!0):$;return e(tt=>je(W,e,n,r,(j,gt)=>e(_t=>{const at=Gt(be)("new source node identifier"),yt=W._3&&!j._3?R(j._1,j._2,!0):j;return e(St=>at(yt,e,n,r,(Ft,pt)=>e(Bt=>{const Jt=yt._3&&!Ft._3?R(Ft._1,Ft._2,!0):Ft;return e(mt=>gn(Jt,e,n,r,(ct,Z)=>e(nt=>{const ht=Gt(be)("new target node identifier"),ft=Jt._3&&!ct._3?R(ct._1,ct._2,!0):ct;return e(Nt=>ht(ft,e,n,r,(wt,Zt)=>e(Se=>i(ft._3&&!wt._3?R(wt._1,wt._2,!0):wt,zn("RepointEdge",{from:x,to:V,newFrom:pt,newTo:Zt})))))})))})))})))})))})))})))})))})))})))}))),Ew=(t,e,n,r,i)=>e(o=>ir("seed")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?R(u._1,u._2,!0):u;return e(f=>Me(c,e,n,r,(d,l)=>e(_=>{const h=Gt(Nw)("integer (seed value)"),p=c._3&&!d._3?R(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?R(y._1,y._2,!0):y;return e(k=>je(w,e,n,r,(L,E)=>e(B=>i(w._3&&!L._3?R(L._1,L._2,!0):L,x))))})))})))}))),Xi=sw((()=>{const t=Gt(jt(e=>e==="{"))("'{'");return(e,n,r,i,o)=>n(u=>n(s=>t(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?R(a._1,a._2,!0):a;return je(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?R(_._1,_._2,!0):_,h)))})))))})())(Gt((()=>{const t=Gt(jt(e=>e==="}"))("'}'");return(e,n,r,i,o)=>n(u=>n(s=>je(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?R(a._1,a._2,!0):a;return t(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?R(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),Cw=Xi((t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>(()=>{if(f.tag==="Nothing")return(l,_,h,p,m)=>m(l,Q);if(f.tag==="Just"){const l=f._1,_=un((()=>{const h=Gt(jt(p=>p===","))("','");return(p,m,y,x,N)=>{const w=p._3;return m(k=>m(L=>m(E=>m(B=>m(X=>m(et=>Me(p,m,y,(S,P)=>x(R(S._1,S._2,w),P),(S,P)=>m(V=>m(U=>{const O=p._3&&!S._3?R(S._1,S._2,!0):S;return h(O,m,y,(z,F)=>x(R(z._1,z._2,w),F),(z,F)=>m(G=>{const D=O._3&&!z._3?R(z._1,z._2,!0):z;return m(I=>m(A=>{const H=p._3&&!D._3?R(D._1,D._2,!0):D;return Me(H,m,y,($,Y)=>x(R($._1,$._2,w),Y),($,Y)=>m(q=>{const W=H._3&&!$._3?R($._1,$._2,!0):$;return m(tt=>m(j=>{const gt=p._3&&!W._3?R(W._1,W._2,!0):W;return m1(gt,m,y,(_t,at)=>x(R(_t._1,_t._2,w),at),(_t,at)=>m(yt=>N(gt._3&&!_t._3?R(_t._1,_t._2,!0):_t,at)))}))}))}))}))})))))))))}})());return(h,p,m,y,x)=>p(N=>_(h,p,m,y,(w,k)=>p(L=>x(h._3&&!w._3?R(w._1,w._2,!0):w,fw([l,...Ct($t.foldr,k)])))))}g()})()(t._3&&!c._3?R(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>e(f=>m1(R(s,a,!1),e,n,(d,l)=>e(_=>u(t,T)),(d,l)=>e(_=>u(d,v("Just",l))))))})),Sw=(t,e,n,r,i)=>e(o=>ir("+node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?R(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),p=c._3&&!d._3?R(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?R(y._1,y._2,!0):y;return e(k=>e(L=>Me(w,e,n,r,(E,B)=>e(X=>{const et=jt(P=>P===`
|
|
15
|
+
`||P==="\r"||P==="#"||P==="}"||P==="{"),S=w._3&&!E._3?R(E._1,E._2,!0):E;return e(P=>{const V=(z,F)=>e(G=>(F?((D,I,A,H,$)=>$(D,"")):pw)(S._3&&!z._3?R(z._1,z._2,!0):z,e,n,r,(D,I)=>e(A=>{const H=w._3&&!D._3?R(D._1,D._2,!0):D;return e($=>{const Y=(tt,j)=>e(gt=>i(H._3&&!tt._3?R(tt._1,tt._2,!0):tt,zn("AddNode",{id:x,label:I,shape:(()=>{const _t=_w("shape")(j);if(_t.tag==="Just")return _t._1==="rectangle"||_t._1==="rect"?Zn:_t._1==="cylinder"||_t._1==="cyl"?Nl:_t._1==="parallelogram"?Jl:_t._1==="diamond"?Tl:_t._1==="ellipse"?wl:_t._1==="document"||_t._1==="doc"?vl:_t._1==="cloud"?bl:Zn;if(_t.tag==="Nothing")return Zn;g()})()}))),q=H._1,W=H._2;return e(tt=>{const j=(gt,_t)=>{const at=gt._3;return e(yt=>at?r(gt,_t):Y(H,Q))};return e(gt=>e(_t=>Me(R(q,W,!1),e,n,(at,yt)=>j(R(at._1,at._2,!1),yt),(at,yt)=>e(St=>e(Ft=>Cw(at,e,n,(pt,Bt)=>j(R(pt._1,pt._2,!1),Bt),(pt,Bt)=>e(Jt=>Y(at._3&&!pt._3?R(pt._1,pt._2,!0):pt,Bt))))))))})})}))),U=S._1,O=S._2;return e(z=>{const F=(G,D)=>{const I=G._3;return e(A=>I?r(G,D):V(S,!1))};return e(G=>e(D=>e(I=>xa(R(U,O,!1),e,n,(A,H)=>{const $=A._3;return e(Y=>$?F(R(U,O,!1),H):e(q=>et(R(U,O,!1),e,n,(W,tt)=>F(R(U,O,!1),tt),(W,tt)=>e(j=>e(gt=>V(R(U,O,!1),!0))))))},(A,H)=>e($=>e(Y=>V(R(U,O,!1),!0)))))))})})}))))})))})))}))),Gw=(t,e,n,r,i)=>e(o=>g1(t,e,n,r,(u,s)=>e(a=>{const c=Gt(l1([Sw,vw,kw,Tw,ww,bw,Lw,xw]))("statement (+node, -node, +edge, -edge, ~edge, enter, exit, or 'a -> b')"),f=t._3&&!u._3?R(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>i(f._3&&!l._3?R(l._1,l._2,!0):l,pa("Leaf",{op:_,line:s.line,column:s.column})))))}))),Pw=(t,e,n,r,i)=>e(o=>$i("seq")(t,e,n,r,(u,s)=>e(a=>Xi(Ta(i1))(t._3&&!u._3?R(u._1,u._2,!0):u,e,n,r,i)))),Dw=(t,e,n,r,i)=>e(o=>$i("par")(t,e,n,r,(u,s)=>e(a=>Xi(Ta(kT))(t._3&&!u._3?R(u._1,u._2,!0):u,e,n,r,i)))),Ta=t=>{const e=un(Iw());return(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,c)=>r(f=>u(n._3&&!a._3?R(a._1,a._2,!0):a,t(Ct($t.foldr,c))))))},Iw=Ca(()=>{const t=ma(Gt(jt(e=>e==="}"))("'}'"));return(e,n,r,i,o)=>n(u=>{const s=e._3;return n(a=>n(c=>je(e,n,r,(f,d)=>i(R(f._1,f._2,s),d),(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?R(f._1,f._2,!0):f;return t(h,n,r,(p,m)=>i(R(p._1,p._2,s),m),(p,m)=>n(y=>{const x=h._3&&!p._3?R(p._1,p._2,!0):p;return n(N=>{const w=l1([(L,E,B,X,et)=>{const S=L._3;return Dw(L,E,B,(P,V)=>X(R(P._1,P._2,S),V),et)},(L,E,B,X,et)=>{const S=L._3;return Pw(L,E,B,(P,V)=>X(R(P._1,P._2,S),V),et)},Gw]),k=e._3&&!x._3?R(x._1,x._2,!0):x;return n(L=>w(k,n,r,i,(E,B)=>n(X=>{const et=k._3&&!E._3?R(E._1,E._2,!0):E;return n(S=>Me(et,n,r,i,(P,V)=>n(U=>{const O=et._3&&!P._3?R(P._1,P._2,!0):P;return n(z=>dw(O,n,r,i,(F,G)=>n(D=>o(O._3&&!F._3?R(F._1,F._2,!0):F,B))))})))})))})}))})))))})}),Qw=(t,e,n,r,i)=>e(o=>$i("frame")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?R(u._1,u._2,!0):u;return e(f=>yw(c,e,n,r,(d,l)=>e(_=>{const h=c._3&&!d._3?R(d._1,d._2,!0):d;return e(p=>je(h,e,n,r,(m,y)=>e(x=>{const N=Xi(Ta(i1)),w=h._3&&!m._3?R(m._1,m._2,!0):m;return e(k=>N(w,e,n,r,(L,E)=>e(B=>{const X=w._3&&!L._3?R(L._1,L._2,!0):L;return e(et=>je(X,e,n,r,(S,P)=>e(V=>i(X._3&&!S._3?R(S._1,S._2,!0):S,{name:v("Just",l),ops:E}))))})))})))})))}))),Aw=(t,e,n,r,i)=>e(o=>$i("inside")(t,e,n,r,(u,s)=>e(a=>{const c=Gt(be)("node identifier"),f=t._3&&!u._3?R(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=f._3&&!l._3?R(l._1,l._2,!0):l;return e(m=>je(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?R(y._1,y._2,!0):y;return e(k=>Xi(y1)(w,e,n,r,(L,E)=>e(B=>{const X=w._3&&!L._3?R(L._1,L._2,!0):L;return e(et=>je(X,e,n,r,(S,P)=>e(V=>i(X._3&&!S._3?R(S._1,S._2,!0):S,{node:_,doc:E}))))})))})))})))}))),y1=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>{const l=un(Rw()),_=t._3&&!c._3?R(c._1,c._2,!0):c;return e(h=>l(_,e,n,r,(p,m)=>e(y=>{const x=Ct($t.foldr,m);return i(_._3&&!p._3?R(p._1,p._2,!0):p,{seed:(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})(),frames:xt(N=>{if(N.tag==="TopFrame")return v("Just",N._1);if(N.tag==="TopInside")return T;g()})(x),interiors:xt(N=>{if(N.tag==="TopInside")return v("Just",N._1);if(N.tag==="TopFrame")return T;g()})(x)})})))}),s=t._1,a=t._2;return e(c=>e(f=>Ew(R(s,a,!1),e,n,(d,l)=>{const _=d._3;return e(h=>_?r(d,l):u(t,T))},(d,l)=>e(_=>u(d,v("Just",l))))))}),Rw=Ca(()=>jT.defer(t=>(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>n(c=>Aw(R(u,s,!1),n,r,(f,d)=>n(l=>n(_=>Qw(e,n,r,i,(h,p)=>n(m=>o(h,d1("TopFrame",p)))))),(f,d)=>n(l=>o(f,d1("TopInside",d))))))})),Fw=(()=>{const t=Gt((e,n,r,i,o)=>n(u=>n(s=>je(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?R(a._1,a._2,!0):a;return xa(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?R(_._1,_._2,!0):_,h)))}))))))("'frame', 'inside', or end of input");return(e,n,r,i,o)=>n(u=>n(s=>n(a=>n(c=>je(e,n,r,i,(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?R(f._1,f._2,!0):f;return y1(h,n,r,i,(p,m)=>n(y=>{const x=h._3&&!p._3?R(p._1,p._2,!0):p;return n(N=>n(w=>{const k=e._3&&!x._3?R(x._1,x._2,!0):x;return t(k,n,r,i,(L,E)=>n(B=>o(k._3&&!L._3?R(L._1,L._2,!0):L,m)))}))}))})))))))})(),Bw=t=>{const e=ew(t)(Fw);if(e.tag==="Left")return Pt("Left",{msg:e._1._1,line:e._1._2.line,column:e._1._2.column});if(e.tag==="Right")return Pt("Right",e._1);g()},zw=t=>{const e=Bw(t);if(e.tag==="Left")return Pt("Left",e._1.msg);if(e.tag==="Right")return Pt("Right",e._1);g()};function wa(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 Zr(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function Ww(t){return function(e){return function(){return e.getAttribute(t)}}}const Ow=t=>{const e=Ww(t);return n=>{const r=e(n);return()=>{const i=r();return Za(i,T,Xt)}}};function Mw(t){return function(e){return function(){e.textContent=t}}}function qw(t){return function(){return function(e){return t(e)()}}}function Hw(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const $w=function(){return window};function Xw(t){return function(e){return function(){e.value=t}}}function Yw(t){return function(){return t.valueAsNumber}}function Vw(t){return function(){return t.value}}function Uw(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const jw=t=>t,Zw=t=>()=>t.clientWidth||0,Kw=()=>window.devicePixelRatio||1,va=(t,e)=>{e.innerHTML=t},ba=(t,e,n)=>{t.style.setProperty(e,n)},tv=(t,e)=>t.querySelector(`[data-mg="${e}"]`),ev=t=>e=>t===e,nv=t=>t,rv=(t,e,n)=>({tag:t,_1:e,_2:n}),iv=zt.foldMap(vd),x1=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ov=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},uv=rv("AutoSize"),sv=nv("CanvasRenderer"),av=t=>e=>{const n=t-e*rt(de(ln(t/e)));return e<=0?0:n<0?n+e:n},cv=t=>J(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),gv=t=>{const e=Ow("data-markgraf-titles")(t);return()=>{const n=e();return n.tag==="Nothing"||!(n.tag==="Just"&&n._1==="false")}},fv=`
|
|
16
16
|
<canvas data-mg="stage" tabindex="0"></canvas>
|
|
17
17
|
<div data-mg="play-overlay" aria-hidden="true"></div>
|
|
18
18
|
<div data-mg="bar">
|
|
@@ -29,4 +29,4 @@ var vw=(function(yu){"use strict";function ka(t){let e=0,n;return()=>{if(e===2)r
|
|
|
29
29
|
<option value="2">2\xD7</option>
|
|
30
30
|
</select>
|
|
31
31
|
</div>
|
|
32
|
-
`,
|
|
32
|
+
`,Mn=t=>e=>n=>()=>{const r=tv(t,e),i=Za(r,T,Xt);if(i.tag==="Just")return n(i._1)();i.tag!=="Nothing"&&g()},_v=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=iv(i=>'<span class="mg-tick" style="left:'+si(oi("Fixed",ui(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 Mn(t)("ticks")(i=>()=>va(r,i))},dv=t=>e=>n=>Mn(t)("scrub")(r=>{const i=wa(T,Xt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return n<=0?()=>{}:Xw(ie(de(Yn(e/n*1e3))))(i._1);g()}),La=t=>e=>n=>{const r=qw(i=>n);return()=>{const i=r();return Hw(t)(i)(!1)(e)()}},N1=()=>Sd()/1e3,ka=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)},_=Yu(u.layout)(l),h=()=>{const N=N1(),w=a.value;return a.value=N,w===0?0:N-w},p=U0(u)(x1(c)(u.totalDuration)),m=o?p:{...p,levels:M(N=>({...N,state:{...N.state,frameTitle:""}}))(p.levels)},y=u.dives.length===0&&(_.w+48)*1.0909090909090908<=1100&&(_.h+48)*1.0909090909090908<=1400,x=y?{...m,camera:l,levels:M(N=>({...N,state:{...N.state,camera:l}}))(m.levels)}:m;if(e==="CanvasRenderer")return()=>{const N=h(),w=jw(t),k=Vr({padding:8,outputAspect:T})(x),L=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){if(y)return{w:k.vw*1.0909090909090908,h:k.vh*1.0909090909090908};const F=Zw(t)();return{w:F,h:k.vw<=0?F:F*k.vh/k.vw}}g()})(),E=Kw(),B=L.w*E,X=L.h*E,et=Pd(w)(),S=Dd(w)(),P=Id(w)(B);et!==B&&P();const V=Qd(w)(X);if(S!==X&&V(),ba(t,"height",ie(de(Yn(L.h)))+"px"),n.tag==="FixedSize")ba(t,"width",ie(de(Yn(L.w)))+"px");else if(n.tag==="AutoSize"){const F=ie(de(Yn(L.w)))+"px";y&&ba(t,"width",F)}else g();const U=Gd(w)();cr(U)(),to(U)({scaleX:E,scaleY:E})();const O=s.value,z=nT(r)(i)(U)({width:L.w,height:L.h})(x)(N)(O)();return s.value=z,gr(U)()};if(e==="SvgRenderer")return()=>{const N=h(),w=s.value,k=xT((()=>{if(n.tag==="AutoSize")return T;if(n.tag==="FixedSize")return n._1<=0||n._2<=0?T:v("Just",n._1/n._2);g()})())(r)(i)(x)(N)(w);return s.value=k.springs,Zr("viewBox")(k.parts.viewBox)(t)(),Zr("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(Zr("width")(ie(de(Yn(n._1))))(t)(),Zr("height")(ie(de(Yn(n._2))))(t)()):n.tag==="AutoSize"||g(),va(k.parts.body,t)};g()},J1=t=>{const e=zw(t);if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right"){const n=a1(e._1)(o1)._1;if(n.tag==="Left")return Pt("Left",n._1.msg);if(n.tag==="Right")return Pt("Right",n._1)}g()},lv=t=>{const e=J1(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return Ld;g()},Ea=t=>e=>{const n=Vt(r=>r.startT<=e&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return n._1.scene._1.to;if(n._1.scene.tag==="DataFlow")return n._1.scene._1.keyframe;if(n._1.scene.tag==="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()},hv=t=>e=>Mn(t)("speed")(n=>{const r=wa(T,Xt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return La("change")(n)((()=>{const i=Vw(r._1);return()=>{const o=i(),u=cd(o,$a,Xt,T);if(u.tag==="Just")return e(u._1)();u.tag!=="Nothing"&&g()}})());g()}),pv=t=>e=>n=>Mn(t)("scrub")(r=>{const i=wa(T,Xt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return La("input")(r)((()=>{const o=Yw(i._1);return()=>{const u=o();return n.pause(),n.seek(u/1e3*e.totalDuration)()}})());g()}),mv=t=>e=>n=>{const r=_v(t)(e);return()=>{r(),Mn(t)("play")(i=>Zr("data-mg-playing")("1")(i))(),hv(t)(n.setSpeed)(),Mn(t)("play")(i=>La("click")(i)(n.toggle))(),pv(t)(e)(n)(),n.subscribe(i=>{const o=dv(t)(i.time)(e.totalDuration);return()=>(o(),Mn(t)("time")(u=>Mw(si(oi("Fixed",ui(0)(20)(2)))(i.time)+" / "+si(oi("Fixed",ui(0)(20)(2)))(e.totalDuration))(u))(),Mn(t)("play")(u=>Zr("data-mg-playing")(i.playing?"1":"0")(u))())})()}},yv={...sh,tokenZoomFloor:1,minZoom:1.6,maxZoom:3.2},xv=t=>e=>{const n=Sf(t);return()=>{const r=n(),i=Gf(t)(),o=g0(yv)(Kh)(t)(Pf(r)(i)(t));if(o.tag==="Left")return Ka("[markgraf] precompute failed")();if(o.tag==="Right")return e(o._1)();g()}},Nv=t=>e=>n=>r=>i=>o=>u=>()=>{let s=1,a=!0,c=!1,f=0,d=0;const l={value:Q},_={value:0};let h=!1,p=[];ka(t)(n)(r)(i)(o)(u)(e)(l)(_)(0)();const m=L=>()=>{const E=p,B=a,X={time:L,keyframe:Ea(e)(L),playing:B};return cv(et=>et(X))(E)()},y=()=>(a=!1,m(f)()),x=()=>{if(!h&&(c=!1,a)){const L=N1(),E=d;d=L;const B=s,X=f,et=av(E===0?X+0*B:X+(L-E)*B)(e.totalDuration+.8);return f=et,ka(t)(n)(r)(i)(o)(u)(e)(l)(_)(et)(),m(et)(),N()}},N=()=>{if(!h&&!c){c=!0;const L=$w();Uw(x)(L)()}},w=()=>(d=0,a=!0,N()),k=()=>(a||w(),m(f)());return w(),{play:k,pause:y,toggle:()=>a?y():k(),seek:L=>{const E=ov(0)(x1(e.totalDuration)(L));return()=>(f=E,d=0,ka(t)(n)(r)(i)(o)(u)(e)(l)(_)(E)(),m(E)())},setSpeed:L=>()=>s=L,currentTime:()=>f,currentKeyframe:()=>{const L=f;return Ea(e)(L)},isPlaying:()=>a,duration:e.totalDuration,subscribe:L=>()=>{p=Wt(p)(L);const E=f,B=a;L({time:E,keyframe:Ea(e)(E),playing:B})();const X=qa(et=>!ev(et)(L));return()=>{p=X(p)}},destroy:()=>h=!0}},T1=t=>e=>{const n=J1(e);if(n.tag==="Left")return Ka("[markgraf] parse failed: "+n._1);if(n.tag==="Right")return xv(n._1)(r=>{const i=gv(t);return()=>{const o=i();return va(fv,t),Mn(t)("stage")(u=>{const s=Nv(u)(r)(sv)(uv)(iT)(oT)(o);return()=>{const a=s();return mv(t)(r)(a)()}})()}});g()},Jv=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",Tv=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)},wv=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=Jv(t),n=t.dataset.markgrafPaused==="true";t.textContent="",T1(t)(e)(),n?pu(t)&&t.querySelector('[data-mg="play"]').click():Ln===null?Ln=t:pu(t)&&t.querySelector('[data-mg="play"]').click(),Tv(t)},mu=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(wv)},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=lv(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>T1(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})({});
|