@markgrafhq/markgraf-embed 0.1.14 → 0.1.15
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.css +12 -16
- package/dist/markgraf-embed.js +13 -13
- package/package.json +1 -1
package/dist/markgraf-embed.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
var Hv=(function(Tu){"use strict";function
|
|
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})+'"'},wu=t=>t,Ne=wu("LT"),Je=wu("GT"),Ge=wu("EQ"),v=(t,e)=>({tag:t,_1:e}),T=v("Nothing"),Xt=t=>v("Just",t),Ra=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;g()},Ba=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;g()},Pt=(t,e)=>({tag:t,_1:e}),D1=t=>Pt("Right",t),Q1={map:t=>e=>{if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right")return Pt("Right",t(e._1));g()}},za={apply:t=>e=>{if(t.tag==="Left")return Pt("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right")return Pt("Right",t._1(e._1))}g()},Functor0:()=>Q1},F1={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Pt("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}g()},Apply0:()=>za},A1={pure:D1,Apply0:()=>za},Wa={Applicative0:()=>A1,Bind1:()=>F1},M1=t=>t,O1={map:t=>e=>t(e)},qa={apply:t=>e=>t(e),Functor0:()=>O1},R1={bind:t=>e=>e(t),Apply0:()=>qa},B1={pure:M1,Apply0:()=>qa},$n={Applicative0:()=>B1,Bind1:()=>R1},z1=function(t){return function(){return t}},W1={apply:t=>e=>()=>{const n=t(),r=e();return vu.pure(n(r))()},Functor0:()=>q1},vu={pure:z1,Apply0:()=>W1},q1={map:t=>e=>()=>{const n=e();return t(n)}},ei=(t,e)=>({tag:t,_1:e}),Ha=t=>ei("Loop",t),H1={tailRecM:t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="Loop"){r=t(u._1);continue}if(u.tag==="Done"){i=!1,o=u._1;continue}g()}return o};return n=>e(t(n))},Monad0:()=>$n},$1=function(t){return function(e){return function(){return t(e())}}},X1=function(t){return function(){return t}},Y1={map:$1},V1={apply:t=>e=>()=>{const n=t(),r=e();return $a.pure(n(r))()},Functor0:()=>Y1},$a={pure:X1,Apply0:()=>V1},U1=(function(t){return function(e){return function(n){return function(){return t(e,n)}}}})(function(t,e){return e.push(t)}),Z1=(t,e)=>({tag:"Iterator",_1:t,_2:e}),K1=t=>e=>n=>()=>{let r=!1;const i=e._2;for(;!r;){const o=i.value,u=e._1(o);if(u.tag==="Just"&&t(u._1)){n.push(u._1),e._2.value;const s=e._2.value;e._2.value=s+1|0;continue}r=!0}},j1=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const i=r.value,o=r.value;r.value=o+1|0;const u=t._1(i);if(u.tag==="Just"){e(u._1)();continue}if(u.tag==="Nothing"){n=!0;continue}g()}},ni=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}}},bu=t=>{const e=t.Apply0();return n=>r=>n.foldr(i=>{const o=r(i);return u=>e.apply(e.Functor0().map(s=>Ma)(o))(u)})(t.pure())},td=t=>{const e=bu(t);return n=>{const r=e(n);return i=>o=>r(o)(i)}},zt={foldr:ni,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}),Cn=t=>e=>b(t,e),ji=t=>t._2,to=t=>t._1,Ft=function(t){return function(e){for(var n=e.length,r=Array(n),i=0;i<n;i++)r[i]=t(i)(e[i]);return r}};var ku=function(t){return function(e){return t===e}};const ed=ku,nd=ku,ri=ku,Lu=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:ri},rd={eq:nd},vr={eq:ed};var Eu=function(t){return function(e){return function(n){return function(r){return function(i){return r<i?t:r===i?e:n}}}}};const id=Eu,od=Eu,C={compare:Eu(Ne)(Ge)(Je),Eq0:()=>fn},ut={compare:od(Ne)(Ge)(Je),Eq0:()=>rd},it={compare:id(Ne)(Ge)(Je),Eq0:()=>vr},ud=function(t){return t},sd=(function(){function t(i){return[i]}function e(i){return function(o){return[i,o]}}function n(i){return function(o){return function(u){return[i,o,u]}}}function r(i){return function(o){return i.concat(o)}}return function(i){return function(o){return function(u){return function(s){return function(a){function c(f,d){switch(d-f){case 0:return u([]);case 1:return o(t)(s(a[f]));case 2:return i(o(e)(s(a[f])))(s(a[f+1]));case 3:return i(i(o(n)(s(a[f])))(s(a[f+1])))(s(a[f+2]));default:var l=f+Math.floor((d-f)/4)*2;return i(o(r)(c(f,l)))(c(l,d))}}return c(0,a.length)}}}}}})(),ad=t=>t,ar={traverse:t=>{const e=t.Apply0();return sd(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>ar.traverse(t)(ad),Functor0:()=>P1,Foldable1:()=>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 cd=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},gd=function(t,e){for(var n=[],r=0,i=0;i<t;i++)n[r++]=e;return n};const fd=typeof Array.prototype.fill=="function"?cd:gd,Ct=(function(){function t(i,o){this.head=i,this.tail=o}var e={};function n(i){return function(o){return new t(i,o)}}function r(i){for(var o=[],u=0,s=i;s!==e;)o[u++]=s.head,s=s.tail;return o}return function(i,o){return r(i(n)(e)(o))}})(),Mt=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},Xa=function(t,e,n,r){for(var i=0;i<r.length;i++){var o=n(r[i]);if(e(o))return o}return t},cr=function(t,e,n,r){for(var i=0,o=r.length;i<o;i++)if(n(r[i]))return t(i);return e},Ya=function(t,e,n,r){for(var i=r.length-1;i>=0;i--)if(n(r[i]))return t(i);return e},Va=function(t,e,n,r,i){if(n<0||n>i.length)return e;var o=i.slice();return o.splice(n,0,r),t(o)},Ua=function(t,e,n,r){if(n<0||n>=r.length)return e;var i=r.slice();return i.splice(n,1),t(i)},Xn=function(t,e,n,r,i){if(n<0||n>=i.length)return e;var o=i.slice();return o[n]=r,t(o)},Te=function(t){return t.slice().reverse()},Oe=function(t){if(t.length<=1e4)return Array.prototype.concat.apply([],t);for(var e=[],n=0,r=t.length;n<r;n++)for(var i=t[n],o=0,u=i.length;o<u;o++)e.push(i[o]);return e},st=function(t,e){return e.filter(t)},_d=function(t,e,n){for(var r=n.length,i=e,o=new Array(r),u=0;u<r;u++)i=t(i)(n[u]),o[u]=i;return o},dd=(function(){function t(e,n,r,i,o,u){var s,a,c,f,d,l,_;for(s=o+(u-o>>1),s-o>1&&t(e,n,i,r,o,s),u-s>1&&t(e,n,i,r,s,u),a=o,c=s,f=o;a<s&&c<u;)d=i[a],l=i[c],_=n(e(d)(l)),_>0?(r[f++]=l,++c):(r[f++]=d,++a);for(;a<s;)r[f++]=i[a++];for(;c<u;)r[f++]=i[c++]}return function(e,n,r){var i;return r.length<2?r:(i=r.slice(0),t(e,n,i,r.slice(0),0,r.length),i)}})(),bt=function(t,e,n){return n.slice(t,e)},we=function(t,e,n){for(var r=e.length<n.length?e.length:n.length,i=new Array(r),o=0;o<r;o++)i[o]=t(e[o])(n[o]);return i},Re=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},Za=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Lt=t=>e=>dd(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),ld=t=>e=>Lt(n=>r=>t.compare(e(n))(e(r))),Ot=t=>e=>(()=>{const n=U1(e);return()=>{const r=[...t];return n(r)(),r}})()(),ii=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},hd=t=>e=>n=>t>=0&&t<n.length?Xn(Xt,T,t,e(n[t]),n):T,gr=t=>e=>{const n=(r=>{let i=r,o=!0,u;for(;o;){const s=i;if(s>=0&&s<e.length){if(t(e[s])){i=s+1|0;continue}o=!1,u=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()},br=t=>e=>{const n=Lt(r=>i=>t(r._2)(i._2))(Ft(Cn)(e));return 0<n.length?W(ji)(ld(it)(to)((()=>{const r=[n[0]];for(const i of n){const o=t((()=>{const u=r.length-1|0;if(u>=0&&u<r.length)return r[u]._2;g()})())(i._2);(o==="LT"||o==="GT"||o!=="EQ")&&r.push(i)}return r})())):[]},pd=t=>e=>{const n=[],r=Z1(i=>i>=0&&i<e.length?v("Just",e[i]):T,{value:0});return j1(r)(i=>()=>{const o=[];o.push(i),K1(t(i))(r)(o)(),n.push(o)})(),n},Vt=t=>e=>{const n=cr(Xt,T,t,e);return n.tag==="Just"?v("Just",e[n._1]):T},Ka=t=>e=>st(t,e),Be=t=>e=>n=>{const r=cr(Xt,T,i=>t.eq(i)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},ja=t=>e=>Tt(e)(t),xt=t=>ja(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];g()}),tc=isFinite;function md(t,e,n,r){var i=parseFloat(t);return e(i)?n(i):r}const Yn=Math.abs,yd=Math.acos,fr=function(t){return function(e){return Math.atan2(t,e)}},eo=Math.ceil,en=Math.cos,no=Math.exp,ln=Math.floor,ec=Math.log,xd=function(t){return function(e){return Math.min(t,e)}},Cu=function(t){return function(e){return Math.pow(t,e)}},Vn=Math.round,He=Math.sin,Le=Math.sqrt,Nd=Math.tan,Jd=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},rt=function(t){return t},Td=(function(t){return function(e){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var i=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(o){if(i.test(o)){var u=parseInt(o,n);return(u|0)===u?t(u):e}else return e}}}})(Xt)(T)(10),nc=Jd(Xt)(T),de=t=>{if(!tc(t))return 0;if(t>=rt(2147483647))return 2147483647;if(t<=rt(-2147483648))return-2147483648;const e=nc(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;g()},qt=(t,e,n)=>({tag:t,_1:e,_2:n}),Ht=qt("Nil"),$t={foldr:t=>e=>{const n=$t.foldl(i=>o=>t(o)(i))(e),r=(i=>o=>{let u=i,s=o,a=!0,c;for(;a;){const f=u,d=s;if(d.tag==="Nil"){a=!1,c=f;continue}if(d.tag==="Cons"){u=qt("Cons",d._1,f),s=d._2;continue}g()}return c})(Ht);return i=>n(r(i))},foldl:t=>e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=t(s)(a._1),i=a._2;continue}g()}return u},foldMap:t=>{const e=t.mempty;return n=>$t.foldl(r=>{const i=t.Semigroup0().append(r);return o=>i(n(o))})(e)}},wd=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);u.push(n(a));var c=r(a);if(t(c))return u;s=e(c)}}}}}}},vd=t=>{if(t.tag==="Just")return t._1;g()},bd={unfoldr1:wd(Ra)(vd)(to)(ji)},kd=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);if(t(a))return u;var c=e(a);u.push(n(c)),s=r(c)}}}}}}},Ld=t=>{if(t.tag==="Just")return t._1;g()},$e={unfoldr:kd(Ra)(Ld)(to)(ji),Unfoldable10:()=>bd},Wt=(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}),ro=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),rc=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),Q=Wt("Leaf"),hn=Xe("IterLeaf"),se=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return Wt("Node",1,1,t,e,n,r);if(r.tag==="Node")return Wt("Node",1+r._1|0,1+r._2|0,t,e,n,r);g()}if(n.tag==="Node"){if(r.tag==="Leaf")return Wt("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return Wt("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"?Wt("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()},kr=(t,e,n)=>{if(n.tag==="Leaf")return ro(T,Q,Q);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const i=kr(t,e,n._5);return ro(i._1,i._2,ze(n._3,n._4,i._3,n._6))}if(r==="GT"){const i=kr(t,e,n._6);return ro(i._1,ze(n._3,n._4,n._5,i._2),i._3)}if(r==="EQ")return ro(v("Just",n._4),n._5,n._6)}g()},ic=(t,e,n,r)=>{if(r.tag==="Leaf")return rc(t,e,n);if(r.tag==="Node"){const i=ic(r._3,r._4,r._5,r._6);return rc(i._1,i._2,ze(t,e,n,i._3))}g()},oi=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=ic(t._3,t._4,t._5,t._6);return ze(n._1,n._2,n._3,e)}g()},Sn=(t,e,n)=>{if(e.tag==="Leaf")return Q;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=kr(t,n._3,e);return oi(Sn(t,r._2,n._5),Sn(t,r._3,n._6))}g()},io=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return Q;if(r.tag==="Node"){const i=kr(t,r._3,n),o=io(t,e,i._2,r._5),u=io(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 oi(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=kr(t,r._3,n),o=Ee(t,e,i._2,r._5),u=Ee(t,e,i._3,r._6);if(i._1.tag==="Just")return ze(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return ze(r._3,r._4,o,u)}g()},Ed=t=>e=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node"){const i=e(r._3)(r._4);if(i.tag==="Just")return ze(r._3,i._1,n(r._5),n(r._6));if(i.tag==="Nothing")return oi(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 Wt("Node",1,1,n,r,Q,Q);if(o.tag==="Node"){const u=t.compare(n)(o._3);if(u==="LT")return ze(o._3,o._4,i(o._5),o._6);if(u==="GT")return ze(o._3,o._4,o._5,i(o._6));if(u==="EQ")return Wt("Node",o._1,o._2,n,e(o._4)(r),o._5,o._6)}g()};return i},j=t=>e=>n=>{const r=i=>{if(i.tag==="Leaf")return Wt("Node",1,1,e,n,Q,Q);if(i.tag==="Node"){const o=t.compare(e)(i._3);if(o==="LT")return ze(i._3,i._4,r(i._5),i._6);if(o==="GT")return ze(i._3,i._4,i._5,r(i._6));if(o==="EQ")return Wt("Node",i._1,i._2,e,n,i._5,i._6)}g()};return r},jt=t=>e=>e.foldl(n=>r=>j(t)(r._1)(r._2)(n))(Q),ui=t=>e=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node"){const i=t.compare(e)(r._3);if(i==="LT")return ze(r._3,r._4,n(r._5),r._6);if(i==="GT")return ze(r._3,r._4,r._5,n(r._6));if(i==="EQ")return oi(r._5,r._6)}g()};return n},oc=t=>{const e=t.compare;return n=>r=>i=>{const o=kr(e,r,i),u=n(o._1);if(u.tag==="Nothing")return oi(o._2,o._3);if(u.tag==="Just")return ze(r,u._1,o._2,o._3);g()}},ue=function(t){return function(e){return t+e|0}},Lr=function(t){return function(e){return t+e}},Un=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},Cd=function(t){return function(e){return t+e}},ee=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},Sd={append:Cd},Gd={append:ee},Pd={mempty:"",Semigroup0:()=>Sd},Id={mempty:[],Semigroup0:()=>Gd},Dd=null;function uc(t,e,n){return t==null?e:n(t)}function qv(t){return t}function Su(t){return function(e){return function(n){return t.apply(n,[e])}}}const Qd=Su(Number.prototype.toPrecision),Fd=Su(Number.prototype.toFixed),Ad=Su(Number.prototype.toExponential),si=(t,e)=>({tag:t,_1:e}),ai=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()},ci=t=>{if(t.tag==="Precision")return Qd(t._1);if(t.tag==="Fixed")return Fd(t._1);if(t.tag==="Exponential")return Ad(t._1);g()},sc=function(t){return function(){console.log(t)}};function Md(){return Date.now()}function Od(t){return function(){return t.getContext("2d")}}function Rd(t){return function(){return t.width}}function Bd(t){return function(){return t.height}}function zd(t){return function(e){return function(){t.width=e}}}function Wd(t){return function(e){return function(){t.height=e}}}function Gu(t){return function(e){return function(){t.lineWidth=e}}}function qd(t){return function(e){return function(){t.fillStyle=e}}}function Hd(t){return function(e){return function(){t.strokeStyle=e}}}function Pu(t){return function(e){return function(){t.lineCap=e}}}function Iu(t){return function(e){return function(){t.lineJoin=e}}}function $d(t){return function(e){return function(){t.globalCompositeOperation=e}}}function Xd(t){return function(e){return function(){t.globalAlpha=e}}}function ac(t){return function(){t.beginPath()}}function Du(t){return function(){t.stroke()}}function Qu(t){return function(){t.fill()}}function Yd(t){return function(){t.clip()}}function gi(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function cc(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function gc(t){return function(){t.closePath()}}function Vd(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function Ud(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function oo(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function Fu(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function Zd(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function Kd(t){return function(e){return function(){t.textAlign=e}}}function jd(t){return function(e){return function(){t.textBaseline=e}}}function tl(t){return function(e){return function(){t.font=e}}}function el(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function _r(t){return function(){t.save()}}function dr(t){return function(){t.restore()}}function fi(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function nl(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const fc=t=>t,Au=t=>t,Mu=t=>t,Ou=t=>t,uo=t=>t,rl=uo("BaselineTop"),il=uo("BaselineMiddle"),ol=uo("BaselineAlphabetic"),ul=uo("BaselineBottom"),sl=Ou("AlignLeft"),al=Ou("AlignRight"),cl=Ou("AlignCenter"),Ru=Mu("BevelJoin"),so=Mu("RoundJoin"),Bu=Mu("MiterJoin"),zu=Au("Round"),Wu=Au("Square"),qu=Au("Butt"),gl=fc("SourceOver"),fl=fc("Difference"),_l=t=>e=>jd(t)((()=>{if(e==="BaselineTop")return"top";if(e==="BaselineHanging")return"hanging";if(e==="BaselineMiddle")return"middle";if(e==="BaselineAlphabetic")return"alphabetic";if(e==="BaselineIdeographic")return"ideographic";if(e==="BaselineBottom")return"bottom";g()})()),dl=t=>e=>Kd(t)((()=>{if(e==="AlignLeft")return"left";if(e==="AlignRight")return"right";if(e==="AlignCenter")return"center";if(e==="AlignStart")return"start";if(e==="AlignEnd")return"end";g()})()),ao=t=>e=>{if(e==="BevelJoin")return Iu(t)("bevel");if(e==="RoundJoin")return Iu(t)("round");if(e==="MiterJoin")return Iu(t)("miter");g()},Hu=t=>e=>{if(e==="Round")return Pu(t)("round");if(e==="Square")return Pu(t)("square");if(e==="Butt")return Pu(t)("butt");g()},_c=t=>e=>$d(t)((()=>{if(e==="SourceOver")return"source-over";if(e==="SourceIn")return"source-in";if(e==="SourceOut")return"source-out";if(e==="SourceAtop")return"source-atop";if(e==="DestinationOver")return"destination-over";if(e==="DestinationIn")return"destination-in";if(e==="DestinationOut")return"destination-out";if(e==="DestinationAtop")return"destination-atop";if(e==="Lighter")return"lighter";if(e==="Copy")return"copy";if(e==="Xor")return"xor";if(e==="Multiply")return"multiply";if(e==="Screen")return"screen";if(e==="Overlay")return"overlay";if(e==="Darken")return"darken";if(e==="Lighten")return"lighten";if(e==="ColorDodge")return"color-dodge";if(e==="ColorBurn")return"color-burn";if(e==="HardLight")return"hard-light";if(e==="SoftLight")return"soft-light";if(e==="Difference")return"difference";if(e==="Exclusion")return"exclusion";if(e==="Hue")return"hue";if(e==="Saturation")return"saturation";if(e==="Color")return"color";if(e==="Luminosity")return"luminosity";g()})()),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,qt("Cons",o._3,i(o._6,u)));g()};return i(r,Ht)})())}},ll=t=>{const e={append:(()=>{const n=t.compare;return r=>i=>Ee(n,ke,r,i)})()};return{mempty:Q,Semigroup0:()=>e}},_i=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},lr=function(t){return t.join("")},Zn=function(t){return t.split("")},co=function(t){return t},Kn=function(t){return t.length},dc=function(t){return function(e){return e.substr(0,t)}},di=function(t){return function(e){return e.substring(t)}},hl=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},pl=t=>e=>{const n=hl(Kn(t))(e);return n.before===t?v("Just",n.after):T},ml=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},yl=function(t){return t()},xl=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},Nl=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},hr=t=>BigInt(t),Jl=t=>Number(t),go=t=>e=>t+e,fo=t=>e=>t*e,$u=t=>e=>t-e,lc=0n,_o=1n,hc=t=>e=>t^e,li=t=>e=>t&e,Xu=t=>e=>t<<e,Yu=t=>e=>t>>e,Tl=t=>e=>t==e,wl=t=>e=>t===e?0:t>e?1:-1,vl={eq:Tl},pc={compare:t=>e=>{const n=wl(t)(e);return n===1?Je:n===0?Ge:Ne},Eq0:()=>vl},bl=xl(Xt)(T),kl=Nl(Xt)(T),mc=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=ut.compare(e._1)(n._1);return r==="LT"?Ne:r==="GT"?Je:ut.compare(e._2)(n._2)},Eq0:()=>t}})(),Ll=t=>e=>Yn(t._1-e._1)+Yn(t._2-e._2),pr=t=>t,lo=t=>t,le=lo("North"),he=lo("South"),Gn=lo("East"),Pn=lo("West"),jn=pr("Rectangle"),El=pr("Cylinder"),Cl=pr("Parallelogram"),Sl=pr("Diamond"),Gl=pr("Ellipse"),Pl=pr("Document"),Il=pr("Cloud"),yc=t=>t,xc=J(Lr)(0),Dl=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},mn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},hi=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Nc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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},Jc=t=>{const e={top:0,bottom:0,left:0,right:0},n=t.shape==="Cloud"?{...e,top:t.h*.38}:t.shape==="Cylinder"?{...e,bottom:5}:t.shape==="Document"?{...e,bottom:t.h*.05}:e;return[{x:t.x-n.left,y:t.y-n.top},{x:t.x+t.w+n.right,y:t.y+t.h+n.bottom}]},mr=t=>e=>{const n=we(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,c=s.x-u.x;return Le(c*c+a*a)})()}),t,bt(1,t.length,t)),r=xc(W(u=>u.len)(n)),i=Dl(0)(r)(e*r),o=u=>s=>a=>{let c=u,f=s,d=a,l=!0,_;for(;l;){const h=c,p=f,m=d,y=Mt(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},Ql=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=hi(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}},pi=t=>xc(we(e=>n=>{const r=n.y-e.y,i=n.x-e.x;return Le(i*i+r*r)},t,bt(1,t.length,t))),Fl=t=>e=>n=>r=>i=>{const o=0<t.length?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+pi(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=mr(t)((d-x)/mn(1e-4)(y-x));if(N.tag==="Nothing")return u;if(N.tag==="Just")return N._1;g()},Al=t=>{const e=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return e(r._5,qt("Cons",r._4,e(r._6,i)));g()},n=Mt(r=>T,r=>i=>v("Just",{head:r,tail:i}),Tt(Ct($t.foldr,e(t.nodes,Ht)))(Jc));if(n.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(n.tag==="Just"){const r=J(i=>o=>({minX:hi(i.minX)(o.x),minY:hi(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()},Vu={scale:1,tx:0,ty:0},Ye=t=>{const e=Mt(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)))(Jc)})(),...Oe((()=>{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))})()),...Oe((()=>{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:hi(r.minX)(i.x),minY:hi(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()},Ml=t=>e=>(n=>r=>i=>{let o=n,u=r,s=i,a=!0,c;for(;a;){const f=o,d=u,l=s,_=Mt(h=>T,h=>p=>v("Just",{head:h,tail:p}),d);if(_.tag==="Nothing"){a=!1,c=l;continue}if(_.tag==="Just"){const h=Nc(_._1.head)(f.interiors);if(h.tag==="Nothing"){a=!1,c=l;continue}if(h.tag==="Just"){o=h._1,u=_._1.tail,s=(()=>{const p=Ql(Ye(h._1.layout))((()=>{const m=Nc(_._1.head)(f.layout.nodes);if(m.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:jn};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)(Vu),Tc=t=>t,wc=(t,e)=>({tag:t,_1:e}),Uu=t=>t,mi=(t,e)=>({tag:t,_1:e}),Zu=(t,e)=>({tag:t,_1:e}),yi=Uu("Animated"),Ol=Uu("StaticStill"),Rl=Uu("TitleCard"),Bl=Zu("First"),zl=Tc("Forward"),Wl=Tc("Backward"),ql=mi("ExitNode"),vc=jt(C)(zt),Hl=t=>ni(e=>n=>({nodes:Ee(C.compare,ke,e.nodes,n.nodes),edges:Ee(C.compare,ke,e.edges,n.edges)}))({nodes:Q,edges:Q})(t.keyframes),$l=t=>e=>({entering:{nodes:Sn(C.compare,e.nodes,t.nodes),edges:Sn(C.compare,e.edges,t.edges)},leaving:{nodes:Sn(C.compare,t.nodes,e.nodes),edges:Sn(C.compare,t.edges,e.edges)},surviving:{nodes:io(C.compare,ke,t.nodes,e.nodes),edges:io(C.compare,ke,t.edges,e.edges)}}),ho=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()},xi=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},Ku=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Xl=J(t=>e=>j(C)(e)()(t))(Q),Yl=J(t=>e=>j(C)(e)()(t))(Q),Vl=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),bc=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},kc=jt(C)(zt),Ni=t=>{const e=Mt(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:ho(r.minX)(i.x),minY:ho(r.minY)(i.y),maxX:Er(r.maxX)(i.x),maxY:Er(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},Ul=t=>{const e=Mt(n=>T,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return T;if(e.tag==="Just")return v("Just",Ni(t));g()},Zl=t=>e=>n=>Xl(Tt(Ct(We.foldr,n))(r=>{const i=xi(r)(t);if(i.tag==="Just")return st(o=>!Ku(o)(e),[i._1.source,i._1.target]);if(i.tag==="Nothing")return[];g()})),Kl=t=>t.kind.tag==="SendToken"?v("Just",b(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):T,jl=t=>t.tag==="DataFlow"?xt(Kl)(t._1.events):[],th=t=>e=>Yl(xt(n=>Ku(n._2.source)(e)||Ku(n._2.target)(e)?v("Just",n._1):T)(Vl(t))),eh=t=>{const e=t.length-1|0;return e>=0&&e<t.length?0<t.length?t[0].x===t[e].x&&t[0].y===t[e].y?v("Just",Ni([t[0]])):v("Just",Ni([t[0],t[e]])):T:0<t.length?v("Just",Ni([t[0]])):T},po=t=>{const e=Mt(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:ho(r.minX)(i.x),minY:ho(r.minY)(i.y),maxX:Er(r.maxX)(i.x+i.w),maxY:Er(r.maxY)(i.y+i.h)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x+e._1.head.w,maxY:e._1.head.y+e._1.head.h})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},Lc=t=>e=>n=>{if(n.tag==="Leaf")return Ye(t);const r=th(e)(n),i=[...xt(o=>{const u=bc(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(We.foldr,Ee(C.compare,ke,n,Zl(e)(n)(r)))),...xt(o=>{const u=xi(o)(t.edges);return u.tag==="Just"?v("Just",Ni(u._1)):T})(Ct(We.foldr,r)),...xt(o=>{const u=xi(o)(t.chipExtras);if(u.tag==="Just")return Ul(u._1);if(u.tag==="Nothing")return T;g()})(Ct(We.foldr,r))];return i.length===0?Ye(t):po(i)},Ji=t=>e=>n=>{const r=[...xt(i=>i)([(()=>{const i=xi(n)(t.chipExtras);if(i.tag==="Just")return eh(i._1);if(i.tag==="Nothing")return T;g()})()]),...(()=>{const i=xi(n)(e);if(i.tag==="Just")return xt(o=>{const u=bc(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?Lc(t)(e)(Q):po(r)},ju=t=>e=>{const n=Ye(t),r=n.w/Er(1e-4)(e.zoom),i=n.h/Er(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-i/2,w:r,h:i}},nh=t=>Ee(C.compare,ke,kc(W(e=>b(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),kc(Tt(t.scenes)(jl))),ts=t=>t,rh=t=>t,yr=ts("Linear"),ih=ts("EaseInOutQuad"),oh=ts("SpringBouncy"),Ti=t=>e=>n=>{const r=Le(1-e*e),i=t*r;return 1-no(-e*t*n)*(en(i*n)+e/r*He(i*n))},uh=t=>{const e=ut.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ut.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},es=t=>e=>(()=>{if(t==="Linear")return rh;if(t==="EaseInQuad")return n=>n*n;if(t==="EaseOutQuad")return n=>1-(1-n)*(1-n);if(t==="EaseInOutQuad")return n=>n<.5?2*n*n:1-2*(1-n)*(1-n);if(t==="EaseInCubic")return n=>n*n*n;if(t==="EaseOutCubic")return n=>1-(1-n)*(1-n)*(1-n);if(t==="EaseInOutCubic")return n=>n<.5?4*n*n*n:1-(-2*n+2)*(-2*n+2)*(-2*n+2)/2;if(t==="EaseOutExpo")return n=>n>=1?1:1-Cu(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*no(-6*n);if(t==="SpringBouncy")return Ti(6)(.7);g()})()(uh(e)),Ec=t=>t,ns=t=>t,mo=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()},wi=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Cc=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},sh=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ah=ns("Hold"),ch=ns("Gap"),gh=ns("Move"),vi=Ec("LinearLerp"),Sc=Ec("LogLerp"),fh=t=>e=>n=>{const r=n.center.y-e.center.y,i=n.center.x-e.center.x,o=Le(i*i+r*r),u=n.zoom-e.zoom,s=u<0?-u:u;return mo(t.minTransition)(t.maxTransition)(wi(t.panSpeed<=0?t.minTransition:o/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:s/t.zoomSpeed))},_h=J(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:Ot(t)(e)})([]),Gc=t=>e=>{const n={x:0,y:0},r=0<t.length?t[0].pos:n,i=Ya(Xt,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=mo(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()},rs=t=>e=>({center:{x:e.center.x*t.scale+t.tx,y:e.center.y*t.scale+t.ty},zoom:e.zoom/wi(1e-6)(t.scale)}),dh=t=>e=>n=>({center:{x:t.center.x+(e.center.x-t.center.x)*n,y:t.center.y+(e.center.y-t.center.y)*n},zoom:no((()=>{const r=ec(wi(1e-6)(t.zoom));return r+(ec(wi(1e-6)(e.zoom))-r)*n})())}),lh=t=>e=>n=>{const r=es(n.easing)(mo(0)(1)(n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT)));if(n.interp==="LinearLerp")return{center:{x:n.fromCam.center.x+(n.toCam.center.x-n.fromCam.center.x)*r,y:n.fromCam.center.y+(n.toCam.center.y-n.fromCam.center.y)*r},zoom:n.fromCam.zoom+(n.toCam.zoom-n.fromCam.zoom)*r};if(n.interp==="LogLerp")return dh(n.fromCam)(n.toCam)(r);g()},hh=t=>e=>n=>r=>{const i=(u,s)=>Cc(fh(t)(u.toCam)(s.toCam))(u.endT-u.startT),o=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:Ot(u.acc)(u.pending._1),pending:v("Just",s)}:{acc:Ot(Ot(u.acc)({...u.pending._1,endT:s.startT-i(u.pending._1,s)}))({startT:s.startT-i(u.pending._1,s),endT:s.startT,fromCam:u.pending._1.toCam,toCam:s.toCam,easing:s.easing,interp:vi}),pending:v("Just",s)};g()})({acc:[],pending:T})(r);if(o.pending.tag==="Nothing")return o.acc;if(o.pending.tag==="Just")return Ot(o.acc)(o.pending._1);g()},ph=t=>e=>{const n=r=>{const i=Ya(Xt,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 Ft(r=>i=>{if(i.kind==="Hold")return{startT:i.startT,endT:i.endT,fromCam:i.fromCam,toCam:i.toCam,easing:i.easing,interp:vi};if(i.kind==="Move")return{startT:i.startT,endT:i.endT,fromCam:i.fromCam,toCam:i.toCam,easing:yr,interp:vi};if(i.kind==="Gap")return{startT:i.startT,endT:i.endT,fromCam:(()=>{const o=n(r);if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;g()})(),toCam:(()=>{const o=n(r),u=(()=>{if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;g()})(),s=r+1|0,a=cr(Xt,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:vi};g()})(e)},mh={padding:24,easing:yr,minZoom:.9,maxZoom:2.5,tokenZoomFloor:0,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:16},is=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:Cc(o.w/r)(o.h/i)},yh=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})()})()})()?Ot((()=>{const i=t.length-1|0;return i<1?[]:bt(0,i,t)})())({...r._1,endT:e.endT}):Ot(t)(e)})([]),bi=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:wi(r)(mo(t.minZoom)(t.maxZoom)(is(e)(n)(t.padding)))}),xh=t=>e=>n=>r=>{const i=Lt(s=>a=>it.compare(a.priority)(s.priority)),o=bi(t)(e)(Ye(e))(0),u=st(s=>s>=0&&s<=n,_h(Lt(ut.compare)([0,n,...Tt(r)(s=>[s.startT,s.endT]),...Tt(r)(s=>{if(s.pathFollow.tag==="Nothing")return[];if(s.pathFollow.tag==="Just")return W(a=>a.t)(s.pathFollow._1.samples);g()})])));return hh(t)(e)(o)(yh(ph(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:gh,startT:s._1,endT:s._2,fromCam:{center:Gc(c[0].samples)(s._1),zoom:c[0].zoom},toCam:{center:Gc(c[0].samples)(s._2),zoom:c[0].zoom},easing:yr});const f=W(d=>d.bbox)(st(d=>d.priority===J(sh)(0)(W(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:ch,startT:s._1,endT:s._2,fromCam:o,toCam:o,easing:t.easing}):v("Just",{kind:ah,startT:s._1,endT:s._2,fromCam:bi(t)(e)(po(f))(Re(d=>d.priority>=1,st(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),toCam:bi(t)(e)(po(f))(Re(d=>d.priority>=1,st(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),easing:t.easing})})(we(Cn,u,bt(1,u.length,u))))))},Pc=t=>e=>n=>r=>{const i=Vt(o=>r>=o.startT&&r<o.endT)(n);if(i.tag==="Just")return lh()(r)(i._1);if(i.tag==="Nothing"){const o=n.length-1|0;if(o>=0&&o<n.length&&r>=n[o].endT)return n[o].toCam;const u=bi(t)(e)(Ye(e))(0);return 0<n.length?n[0].fromCam:u}g()};function In(t){return t.charCodeAt(0)}function Ic(t){return String.fromCharCode(t)}const tr=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},yo=function(t){return function(e){return e.split(t)}},Nh=function(t){return t.trim()},xo=function(t){return function(e){return e.join(t)}};var Jh=typeof Array.from=="function",Th=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",wh=typeof String.prototype.fromCodePoint=="function",vh=typeof String.prototype.codePointAt=="function";const bh=function(t){return vh?function(e){return e.codePointAt(0)}:t},kh=function(t){return wh?String.fromCodePoint:t},Lh=function(t){return function(e){return Th?function(n){for(var r="",i=n[Symbol.iterator](),o=0;o<e;++o){var u=i.next();if(u.done)return r;r+=u.value}return r}:t(e)}},Eh=function(t){return function(e){return Jh?function(n){return Array.from(n,e)}:t}},No=t=>{const e=Kn(t);if(e===0)return T;if(e===1)return v("Just",{head:In(_i(0)(t)),tail:""});const n=In(_i(1)(t)),r=In(_i(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:di(2)(t)}):v("Just",{head:r,tail:di(1)(t)})},Ch=t=>{const e=No(t);return e.tag==="Just"?v("Just",b(e._1.head,e._1.tail)):T},Sh=t=>$e.unfoldr(Ch)(t),Dc=bh(t=>{const e=In(_i(0)(t));if(55296<=e&&e<=56319&&Kn(t)>1){const n=In(_i(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),Jo=Eh(Sh)(Dc),os=t=>co(t>=0&&t<=65535?Ic(t):t<0?"\0":"\uFFFF"),Gh=kh(t=>t<=65535?os(t):os(En(t-65536|0,1024)+55296|0)+os(Un(t-65536|0)(1024)+56320|0)),Qc=t=>e=>{if(t<1)return"";const n=No(e);return n.tag==="Just"?Gh(n._1.head)+Qc(t-1|0)(n._1.tail):e},me=Lh(Qc),Ph=t=>e=>e===""?T:v("Just",Dc(e)),Cr=(t,e,n)=>({tag:t,_1:e,_2:n}),Ih=()=>({tag:"ExtendFromSource"}),Sr=(t,e)=>({tag:t,_1:e}),us=t=>t,To=(t,e)=>({tag:t,_1:e}),ss=To("NotYet"),Fc=To("Consumed"),Dh=us("FromSource"),Ac=us("FromTarget"),Mc=us("FromBoth"),wo=Sr("Hidden"),Qh=Sr("Visible"),as=Ih(),vo=Cr("Retracted"),Fh=Cr("Extended"),Oc=t=>t,cs=(t,e)=>({tag:t,_1:e}),xr=(t,e,n)=>({tag:t,_1:e,_2:n}),Rc=t=>t,er=(t,e)=>({tag:t,_1:e}),Gr=(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}),ki=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()},Bc=jt(C)(zt),gs=Lu(ri),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},bo=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Li=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},zc=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},Wc=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},Ir=(()=>{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)})())})(),Ah=J(t=>e=>j(C)(e)()(t))(Q),fs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},ko=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Mh=er("NoKeyframes"),Oh=t=>er("DuplicateEventId",t),Rh=t=>er("UnknownEvent",t),qc=Rc("PlopIn"),Bh=Rc("PlopOut"),zh=Oc("DiveIn"),Wh=Oc("DiveOut"),qh=t=>e=>n=>r=>{const i=ki(r.edge)(e.edges),o=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return pi(i._1);g()})(),u=yn(t.minTokenDuration)(yn(rt(J(s=>a=>s+Jo(a).length|0)(0)(r.labels))*t.tokenReadSecPerChar)(t.tokenSpeed<=0?0:o/t.tokenSpeed))+n.pre+n.post;return{duration:u,holdPre:u<=0?0:n.pre/u,holdPost:u<=0?0:n.post/u}},Hh=t=>e=>Bc(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 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)),$h=t=>{if(t.event.kind.tag==="SendToken")return v("Just",{startT:t.startT,endT:t.endT,target:Gr("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:Gr("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},Xh=t=>e=>n=>r=>{const i=Vt(o=>gs(o.path)(e)&&(Yn(o.endT-n)<1e-4||Yn(o.startT-r)<1e-4))(t.segments);if(i.tag==="Just")return v("Just",i._1);if(i.tag==="Nothing")return Vt(o=>gs(o.path)(e))(t.segments);g()},Yh=t=>e=>n=>xt(r=>{const i=xt(o=>Li(o)(t.nodes))(Ct(We.foldr,(()=>{if(r.scene.tag==="Structural")return Ee(C.compare,ke,(()=>{const o=Pr(r.scene._1.from)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()})(),(()=>{const o=Pr(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=Pr(r.scene._1.keyframe)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()}if(r.scene.tag==="Hold"){const o=Pr(r.scene._1)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()}if(r.scene.tag==="EnterNode"||r.scene.tag==="ExitNode")return Q;g()})()));return i.length===0?T:v("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const o=J(u=>s=>({minX:bo(u.minX)(s.x),minY:bo(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})}),Vh=t=>e=>n=>{const r=ki(n)(t);if(r.tag==="Nothing")return Ac;if(r.tag==="Just"){const i=zc(r._1.target)(e);return zc(r._1.source)(e)?i?Mc:Dh:Ac}g()},Uh={pre:0,post:0},Zh=t=>e=>n=>r=>i=>{const o=Wc(i.event.id)(n),u=(()=>{if(o.tag==="Nothing")return Uh;if(o.tag==="Just")return o._1;g()})(),s=(()=>{if(i.event.when.tag==="First")return 0;if(i.event.when.tag==="At")return i.event.when._1;if(i.event.when.tag==="After"){const c=i.event.when._1,f=Vt(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.endT;g()}if(i.event.when.tag==="With"){const c=i.event.when._1,f=Vt(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.startT}g()})(),a=(()=>{if(i.event.kind.tag==="SendToken")return qh(t)(e)(u)(i.event.kind._1);if(i.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return Ot(r)({startT:s,endT:s+a.duration,event:i.event,holdPre:a.holdPre,holdPost:a.holdPost})},Hc=t=>e=>n=>J(Zh(t)(e)(Hh(t)(n)))([])(Ft(r=>i=>({event:i}))(n)),Kh=t=>e=>{const n=Li(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},jh=t=>e=>({...e,fromCam:rs(t)(e.fromCam),toCam:rs(t)(e.toCam)}),t0=t=>{if(t.when.tag==="First")return[];if(t.when.tag==="At")return[];if(t.when.tag==="After")return[t.when._1];if(t.when.tag==="With")return[t.when._1];g()},$c={id:"",nodes:Q,edges:Q,kind:yi},e0=t=>e=>$l((()=>{const n=Pr(e.from)(t);if(n.tag==="Nothing")return $c;if(n.tag==="Just")return n._1;g()})())((()=>{const n=Pr(e.to)(t);if(n.tag==="Nothing")return $c;if(n.tag==="Just")return n._1;g()})()),n0=t=>e=>{const n=Li(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:Q};if(n.tag==="Just")return n._1;g()},_s=t=>e=>n=>r=>{const i=ki(r)(n.edges);if(i.tag==="Just")return t<=0?e:yn(e)(pi(i._1)/t);if(i.tag==="Nothing")return e;g()},Xc=t=>e=>n=>r=>i=>{const o=t.plop,u=e0(n)(i),s=W(_=>({startT:0,endT:0+_s(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Gr("EdgeWindow",_,cs("Extend",as))}))(Ir(u.entering.edges)),a=W(_=>({startT:0,endT:o,target:Gr("NodeWindow",_,qc)}))(Ir(u.entering.nodes)),c=J(yn)(0)(W(_=>_s(t.edgeSpeed)(t.minEdgeDuration)(e)(_))(Ir(u.leaving.edges))),f=_=>Re(h=>{const p=ki(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;g()},Ir(u.leaving.edges))?c:0,d=W(_=>({startT:f(_),endT:f(_)+t.plop,target:Gr("NodeWindow",_,Bh)}))(Ir(u.leaving.nodes)),l=W(_=>({startT:0,endT:_s(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Gr("EdgeWindow",_,cs("Retract",Vh(r)(u.leaving.nodes)(_)))}))(Ir(u.leaving.edges));return{duration:(()=>{const _=Lt(ut.compare)([...W(p=>p.endT)(l),...W(p=>p.endT)(d),...W(p=>p.endT)(a),...W(p=>p.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+t.gap:t.gap})(),windows:[...l,...d,...a,...s]}},r0=t=>e=>n=>r=>i=>o=>W((()=>{const u=i.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())(Xc(t)(e)(n)(r)(o).windows),i0=t=>xt(e=>Ct(ni,e).length>1?v("Just",(()=>{const n=Mt(r=>T,r=>i=>v("Just",{head:r,tail:i}),Ct(ni,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):T)(pd(ri)(Lt(C.compare)(t))),o0=t=>{const e=W(r=>r.id)(t),n=Ah(e);return[...W(Oh)(i0(e)),...W(Rh)(st(r=>!fs(r)(n),Tt(t)(t0)))]},u0=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:Ji(e)(n)(i.target._2),priority:1,pathFollow:T};const u=ki(i.target._2)(e.edges);if(u.tag==="Just"){const s=Li(i.target._4)(e.nodes);if(s.tag==="Just"){const a=Li(i.target._5)(e.nodes);if(a.tag==="Just"){const c=a._1;return{startT:i.startT,endT:i.endT,bbox:Ji(e)(n)(i.target._2),priority:1,pathFollow: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 W(_=>{const h=f+rt(_)/rt(32)*d;return{t:h,pos:Fl(u._1)({x:s._1.x+s._1.w/2,y:s._1.y+s._1.h/2})({x:c.x+c.w/2,y:c.y+c.h/2})(l<=0?0:(h-i.startT)/l)(o)}})(Dt(0,32))})(),zoom:r})}}if(a.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:Ji(e)(n)(i.target._2),priority:1,pathFollow:T};g()}if(s.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:Ji(e)(n)(i.target._2),priority:1,pathFollow:T};g()}if(u.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:Ji(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:Lc(e)(n)(Wt("Node",1,1,i.target._2,void 0,Q,Q)),priority:1,pathFollow:T});g()})},s0=t=>e=>n=>r=>i=>xh(t)(i.layout)(r.endT)([...Yh(i.layout)(n)(e)(st(o=>o.startT>=i.startT&&o.endT<=i.endT,r.spans)),...u0(t)(i.layout)(n)(i.windows)]),a0=t=>{const e=Bc(W(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(fs(o)(i))return[er("ScheduleCycle",[...Ct(We.foldr,i),o])];if(fs(o)(r))return[];const u=Wc(o)(e);if(u.tag==="Nothing")return[];if(u.tag==="Just")return Tt(u._1)(n(j(C)(o)()(r))(j(C)(o)()(i)));g()};return Tt(t)(r=>n(Q)(Q)(r.id))},c0={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:.5,stillHold:1.8,hatchHold:.4,tokenReadSecPerChar:.06,nodeEasing:oh,edgeEasing:ih,tokenEasing:yr,diveDur:1.2,retreatDur:1.2},g0=t=>e=>n=>r=>W((()=>{const i=n.startT;return o=>({...o,startT:o.startT+i,endT:o.endT+i})})())(xt($h)(Hc(t)(e)(r.events))),f0=t=>e=>n=>r=>i=>{if(i.scene.tag==="Structural")return r0(t)(e)(n)(r)(i)(i.scene._1);if(i.scene.tag==="Hold")return[];if(i.scene.tag==="DataFlow")return g0(t)(e)(i)(i.scene._1);if(i.scene.tag==="EnterNode")return[];if(i.scene.tag==="ExitNode")return[];g()},_0=t=>e=>n=>{const r=Hc(t)(e)(n.events);return r.length===0?t.gap:J(yn)(0)(W(i=>i.endT)(r))+t.gap},d0=t=>e=>n=>r=>i=>{if(i.tag==="Structural")return Xc(t)(e)(n)(r)(i._1).duration;if(i.tag==="Hold")return t.stillHold;if(i.tag==="DataFlow")return _0(t)(e)(i._1);if(i.tag==="EnterNode"||i.tag==="ExitNode")return 0;g()},Yc=t=>e=>n=>r=>i=>o=>{const u=Ml(e)(r),s=n.layout,a=vc(W(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=nh(i),l=p=>({segments:p.runSpans.length===0?p.segments:Ot(p.segments)({startT:p.runStart,endT:p.t,path:r,layout:s,placement:u,windows:p.runWindows,spans:p.runSpans,keyframes:a,initialKeyframe:f,edgeEndpoints:d}),spans:p.spans,windows:p.windows,dives:p.dives}),_=J(p=>m=>{if(m.tag==="EnterNode"){const w=l(p),L=p.t+t.diveDur,k=Ot(r)(m._1),E=Yc(t)(e)(n0(n)(m._1))(k)(Kh(i)(m._1))(L),O=E.endT+t.retreatDur;return{...p,t:O,runStart:O,runSpans:[],runWindows:[],segments:[...w.segments,...E.segments],spans:[...w.spans,...E.spans],windows:[...w.windows,...E.windows],dives:[...w.dives,{startT:p.t,endT:L,node:m._1,parentPath:r,childPath:k,direction:zh},...E.dives,{startT:E.endT,endT:O,node:m._1,parentPath:r,childPath:k,direction:Wh}]}}if(m.tag==="ExitNode")return p;const y=p.t+d0(t)(s)(a)(d)(m),x={startT:p.t,endT:y,scene:m},N=f0(t)(s)(a)(d)(x);return{...p,t:y,runSpans:Ot(p.runSpans)(x),runWindows:[...p.runWindows,...N],spans:Ot(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:Lt(p=>m=>ut.compare(p.startT)(m.startT))(h.windows),segments:h.segments,dives:h.dives}},l0=t=>e=>n=>n.endT<=t||n.startT>=e?T:v("Just",{...n,startT:yn(t)(n.startT),endT:bo(e)(n.endT)}),ds=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:bo(is(e)(i)(t.padding*n.placement.scale))(40/(11*n.placement.scale))}},h0=t=>e=>n=>n.placement.scale===1&&n.placement.tx===0&&n.placement.ty===0?rs(n.placement)(bi(t)(n.layout)(Ye(n.layout))(0)):ds(t)(e)(n),p0=t=>e=>n=>r=>xt(i=>{const o=Xh(r)(i.parentPath)(i.startT)(i.endT);if(o.tag==="Just"){const u=i.childPath,s=Vt(a=>gs(a.path)(u))(r.segments);if(s.tag==="Just"){const a=h0(t)(e)(o._1),c=ds(t)(e)(s._1);if(i.direction==="DiveIn")return v("Just",{startT:i.startT,endT:i.endT,fromCam:a,toCam:c,easing:yr,interp:Sc});if(i.direction==="DiveOut")return v("Just",{startT:i.startT,endT:i.endT,fromCam:c,toCam:a,easing:yr,interp:Sc});g()}if(s.tag==="Nothing")return T;g()}if(o.tag==="Nothing")return T;g()})(r.dives),m0=t=>e=>{if(e.tag==="Structural")return xt(n=>n)([ko(e._1.from)(t)?T:v("Just",er("UnknownKeyframe",e._1.from)),ko(e._1.to)(t)?T:v("Just",er("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return xt(n=>n)([ko(e._1)(t)?T:v("Just",er("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...xt(n=>n)([ko(e._1.keyframe)(t)?T:v("Just",er("UnknownKeyframe",e._1.keyframe))]),...o0(e._1.events),...a0(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()},y0=t=>e=>{const n=Tt(e)(m0(t));return n.length===0?Pt("Right",void 0):Pt("Left",n)},x0=t=>e=>n=>r=>Lt(i=>o=>ut.compare(i.startT)(o.startT))(Tt(r.segments)(i=>i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0?xt(l0(i.startT)(i.endT))(W(jh(i.placement))(s0(t)(n)(i.edgeEndpoints)(r)(i))):[(()=>{const o=ds(t)(e)(i);return{startT:i.startT,endT:i.endT,fromCam:o,toCam:o,easing:yr,interp:vi}})()])),N0=t=>e=>n=>r=>{if(0<n.keyframes.length){const i=n.keyframes[0],o=vc(W(s=>b(s.id,s))(n.keyframes)),u=y0(o)(n.scenes);return(()=>{if(u.tag==="Left"){const s=u._1;return a=>Pt("Left",s)}if(u.tag==="Right"){const s=u._1;return a=>a(s)}g()})()(()=>{const s=Yc(e)(r)(r)([])(n)(0);return Pt("Right",{totalDuration:s.endT,windows:s.windows,spans:s.spans,keyframes:o,initialKeyframe:i.id,timing:e,layout:r.layout,cameraSpans:[...x0(t)(r.layout)(o)(s),...p0(t)(r.layout)(o)(s)],cameraConfig:t,levelTree:r,segments:s.segments,dives:s.dives,seed:n.seed})})}return Pt("Left",[Mh])},ls=t=>e=>Math.imul(t,e),Dr=t=>{const e=t+1831565813|0,n=ls(e^e>>>15)(e|1),r=n^(n+ls(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=Dr(n);return{prng:r.prng,value:t+r.value*(e-t)}},hs=t=>e=>J(n=>r=>ls(n^r)(-2048144789))(e)(W(In)(Zn(t))),ps=t=>t,nn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Lo=Lu(ri),J0=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Vc=jt(C)(zt),ms=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},Uc=zt.foldMap(ll(C)),Zc=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},T0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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},Qr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},w0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},v0=jt(C)(zt),b0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},k0=jt(C)(zt),L0=ps("Backdrop"),Kc=ps("FlyThrough"),Eo=ps("Active"),jc=t=>e=>n=>{const r=(t+e)/2,i=n-r,o=i<0?-1:1,u=(e-t)/2,s=u*.15,a=u-s,c=i<0?-i:i;return e<=t?(t+e)/2:c<=a?n:r+o*(u-s*no(-(c-a)/s))},E0=t=>e=>n=>r=>{const i=Ye(t),o=i.w/nn(1e-4)(e.zoom)/2,u=i.h/nn(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}}},ys=t=>e=>n=>{const r=Vt(i=>Lo(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=>Lo(i.path)(e))(t.segments);g()},C0=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:Vu,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:Q}),S0=t=>W(e=>e<1?[]:bt(0,e,t))(Dt(0,t.length-1|0)),G0=t=>J(e=>n=>(e*31|0)+In(n)|0)(7)(Zn(t)),tg=t=>e=>n=>({...n,state:{...n.state,nodes:Vc(W(r=>b(r._1,t(r._1)(r._2)))(J0(n.state.nodes))),edges:(()=>{const r=i=>{if(i.tag==="Leaf")return Q;if(i.tag==="Node")return Wt("Node",i._1,i._2,i._3,e(i._4),r(i._5),r(i._6));g()};return r(n.state.edges)})()}}),xs=t=>e=>{const n=ms(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.nodes;g()},Ns=t=>e=>{const n=ms(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.edges;g()},Co=t=>e=>{if(e<t.startT)return xr("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 xr("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return xr("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return xr("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return xr("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;return r>=0&&r<t.spans.length?xr("AtKeyframe",(()=>{if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="Hold")return t.spans[r].scene._1;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return t.initialKeyframe;g()})()):xr("AtKeyframe",t.initialKeyframe)}g()},P0=J(t=>e=>{const n=ii(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?Ot(n._1.init)({...n._1.last,endT:nn(n._1.last.endT)(e.endT),windows:Ot(n._1.last.windows)(e)}):Ot(t)({endT:e.endT,windows:[e]})})([]),I0=t=>e=>n=>Uc(r=>Uc(i=>i.target.tag==="FillWindow"?i.startT<=n?Wt("Node",1,1,i.target._2,void 0,Q,Q):Q:i.target.tag==="TokenWindow"&&i.startT+(i.endT-i.startT)*.25<=n?Wt("Node",1,1,i.target._4,void 0,Q,Q):Q)(r.windows))(st(r=>n<=r.endT+t,P0(Lt(r=>i=>ut.compare(r.startT)(i.startT))(st(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),D0=t=>e=>n=>Re(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),Q0=t=>e=>n=>Re(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),F0=t=>e=>n=>Re(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),A0=t=>e=>n=>Re(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),M0=t=>e=>{const n=Co(t)(e);if(n.tag==="AtKeyframe")return me(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return me(3)(n._2)==="kf-"?"":n._2;g()},O0=t=>e=>{const n=Co(t)(e),r=ms((()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;g()})())(t.keyframes);if(r.tag==="Just")return r._1.kind;if(r.tag==="Nothing")return yi;g()},eg=t=>e=>n=>Vt(r=>n(r)&&e>=r.startT&&e<r.endT)(t),R0=t=>{const e=Zc(0)(1)(t/.2),n=Zc(0)(1)((1-t)/.2);return e*e*(3-2*e)*n*n*(3-2*n)},B0=t=>e=>{if(e.tag==="Travelling"){const n=T0(e._1.edge)(t.edges);if(n.tag==="Just"){const r=mr(n._1)(e._1.progress);return r.tag==="Just"?v("Just",{dot:r._1,weight:R0(e._1.progress)}):T}if(n.tag==="Nothing")return T;g()}return T},z0={segment:{startT:0,endT:0,path:[],layout:{nodes:Q,edges:Q,chipExtras:Q,edgeLabels:Q},placement:Vu,windows:[],spans:[],keyframes:Q,initialKeyframe:"",edgeEndpoints:Q},state:{nodes:Q,edges:Q,tokens:Q,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:yi,visited:Q,nodeFadeAlpha:Q,nodeInvert:Q},bgAlpha:1,role:Eo},So=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:z0},W0=t=>e=>{const n=Co(t)(e);if(n.tag==="AtKeyframe")return xs(t)(n._1);if(n.tag==="InTransition")return Ee(C.compare,ke,xs(t)(n._1),xs(t)(n._2));g()},q0=t=>e=>{const n=Co(t)(e);if(n.tag==="AtKeyframe")return Ns(t)(n._1);if(n.tag==="InTransition")return Ee(C.compare,ke,Ns(t)(n._1),Ns(t)(n._2));g()},H0=t=>e=>{const n=t.w/nn(1e-4)(e.zoom),r=t.h/nn(1e-4)(e.zoom);return{...e,center:{x:n>=t.w?t.x+t.w/2:jc(t.x+n/2)(t.x+t.w-n/2)(e.center.x),y:r>=t.h?t.y+t.h/2:jc(t.y+r/2)(t.y+t.h-r/2)(e.center.y)}}},$0=t=>H0((()=>{const e=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}})()),X0=t=>e=>{const n=t.endT-t.startT;return n<=0?1:nn(0)(Qr(1)((e-t.startT)/n))},ng=t=>e=>n=>nn(0)(Qr(1)((n-ae(0)(.3)(t+G0(e)|0).value)/nn(1e-4)(.7))),rg=t=>e=>n=>tg(r=>i=>i.tag==="Hidden"?wo:Sr("PloppingOut",r===e?nn(0)(Qr(1)((n-.45)/nn(1e-4)(.55))):ng(t)(r)(n)))(r=>r.tag==="Retracted"?vo:Cr("Retracting",Mc,n)),ig=t=>e=>tg(n=>r=>r.tag==="Hidden"?wo:Sr("PloppingIn",ng(t)(n)(e)))(n=>n.tag==="Retracted"?vo:Cr("Extending",as,e)),Go=t=>e=>{const n=t.endT-t.startT;return n<=0?1:nn(0)(Qr(1)((e-t.startT)/n))},Y0=t=>e=>n=>r=>i=>{const o=eg(e)(n)(u=>u.target.tag==="EdgeWindow"&&u.target._1===i);if(o.tag==="Just"){const u=es(t.timing.edgeEasing)(Go(o._1)(n)),s=o._1.target.tag==="EdgeWindow"?o._1.target._2:cs("Extend",as);if(s.tag==="Retract")return Cr("Retracting",s._1,u);if(s.tag==="Extend")return Cr("Extending",s._1,u);g()}if(o.tag==="Nothing")return A0(e)(n)(i)||D0(e)(n)(i)?vo:w0(i)(r)?Fh:vo;g()},V0=t=>e=>n=>{const r=q0(e)(n);return v0(W(i=>b(i,Y0(t)(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Wt("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return Ct(We.foldr,i(e.layout.edges))})()))},U0=t=>e=>n=>r=>{const i=eg(t)(e)(o=>o.target.tag==="NodeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=Go(i._1)(e),u=i._1.target.tag==="NodeWindow"?i._1.target._2:qc;if(u==="PlopIn")return Sr("PloppingIn",o);if(u==="PlopOut")return Sr("PloppingOut",o);g()}if(i.tag==="Nothing")return F0(t)(e)(r)||Q0(t)(e)(r)?wo:b0(r)(n)?Qh:wo;g()},Z0=t=>e=>n=>{const r=W0(e)(n);return Vc(W(i=>b(i,U0(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Wt("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return Ct(We.foldr,i(e.layout.nodes))})()))},K0=t=>e=>n=>e.target.tag==="TokenWindow"?b(e.target._1,n<e.startT?ss:n>=e.endT?Fc:To("Travelling",{edge:e.target._2,direction:e.target._3,progress:es(t.timing.tokenEasing)(Go(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?ss:n>=e.endT?Fc:To("Filling",{node:e.target._2,progress:Go(e)(n),labels:e.target._3})):b("",ss),j0=t=>e=>n=>k0(W(r=>K0(t)(r)(n))(st(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),Fr=t=>e=>n=>({nodes:Z0()(e)(n),edges:V0(t)(e)(n),tokens:j0(t)(e.windows)(n),camera:Pc(t.cameraConfig)(e.layout)(t.cameraSpans)(n),frameTitle:M0(e)(n),staticKind:O0(e)(n),visited:I0(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:Q,nodeInvert:Q}),tp=t=>e=>n=>Xa(T,Ba,r=>r.direction==="DiveIn"&&Lo(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),ep=t=>e=>n=>r=>{const i=tp(t)(e)(n);if(i.tag==="Just"){const o=He(3.141592653589793*i._1.phase*3);return{...r,state:{...r.state,nodeInvert:Wt("Node",1,1,i._1.node,1*o*o,Q,Q)}}}if(i.tag==="Nothing")return r;g()},og=t=>e=>xt(n=>{const r=Vt(i=>i.direction==="DiveIn"&&Lo(i.childPath)((()=>{const o=n.length+1|0;return o<1?[]:bt(0,o,e)})()))(t.dives);if(r.tag==="Just"){const i=ys(t)(n)(r._1.startT-1e-4);if(i.tag==="Just")return v("Just",{bgAlpha:1,role:L0,segment:i._1,state:{...Fr(t)(i._1)(r._1.startT-1e-4),nodeFadeAlpha:Wt("Node",1,1,r._1.node,0,Q,Q)}});if(i.tag==="Nothing")return T;g()}if(r.tag==="Nothing")return T;g()})(S0(e)),ug=t=>e=>{const n=st(i=>e>=i.startT&&e<i.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:C0(t)},np=t=>e=>n=>{const r=X0(n)(e),i=ys(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),o=ys(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),u=nn(0)(Qr(1)(r/.6)),s=nn(0)(Qr(1)((r-.4)/.6)),a=(()=>{if(n.direction==="DiveIn")return rg(t.seed)(n.node)(u);if(n.direction==="DiveOut")return ig(t.seed)(s);g()})(),c=(()=>{if(n.direction==="DiveIn")return ig(t.seed)(s);if(n.direction==="DiveOut")return rg(t.seed)(n.node)(u);g()})();return[...og(t)(n.parentPath),...(()=>{if(i.tag==="Just"){if(o.tag==="Just")return[a({segment:i._1,state:Fr(t)(i._1)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),bgAlpha:1,role:Kc}),c({segment:o._1,state:Fr(t)(o._1)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),bgAlpha:1,role:Eo})];if(o.tag==="Nothing")return[a({segment:i._1,state:Fr(t)(i._1)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),bgAlpha:1,role:Kc})];g()}if(i.tag==="Nothing")return[(()=>{const f=ug(t)(e);return{segment:f,state:Fr(t)(f)(e),bgAlpha:1,role:Eo}})()];g()})()]},rp=t=>e=>{const n=xt(B0(t))((()=>{const r=(i,o)=>{if(i.tag==="Leaf")return o;if(i.tag==="Node")return r(i._5,qt("Cons",i._4,r(i._6,o)));g()};return Ct($t.foldr,r(e.tokens,Ht))})());return 0<n.length?v("Just",n[0]):T},ip=t=>e=>{const n=rp(t)(e);if(n.tag==="Nothing")return e.camera;if(n.tag==="Just")return E0(t)(e.camera)(n._1.dot)(n._1.weight);g()},op=t=>e=>t.placement.scale===1&&t.placement.tx===0&&t.placement.ty===0?ip(t.layout)(e):e.camera,up=t=>e=>Vt(n=>e>=n.startT&&e<n.endT)(t.dives),sp=t=>e=>{const n=ug(t)(e),r=Fr(t)(n)(e),i=t.dives.length!==0,o=Pc(t.cameraConfig)(t.layout)(t.cameraSpans)(e),u=$0(n)(op(n)({...r,camera:o})),s=ep(t)(n)(e)({bgAlpha:1,role:Eo,segment:n,state:{...r,camera:u}}),a=og(t)(n.path),c=up(t)(e);if(c.tag==="Just")return{levels:np(t)(e)(c._1),camera:o,rootLayout:t.layout,hasDives:i,diving:!0};if(c.tag==="Nothing")return{levels:Ot(a)(s),camera:u,rootLayout:t.layout,hasDives:i,diving:!1};g()},sg=t=>t,ag=sg("RunText"),ap=sg("RunCode"),cg=t=>e=>n=>e.length===0?n:Ot(n)({style:t,text:lr(e)}),cp=t=>({style:(()=>{if(t.style==="RunText")return ap;if(t.style==="RunCode")return ag;g()})(),buf:[],runs:cg(t.style)(t.buf)(t.runs)}),gp=t=>e=>0<e.length?{...t,buf:Ot(t.buf)(e[0])}:{...t,buf:Ot(t.buf)("\\")},fp=t=>e=>{let n=t,r=e,i=!0,o;for(;i;){const u=n,s=Mt(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=gp(u)(s._1.tail),r=bt(1,s._1.tail.length,s._1.tail);continue}if(s._1.head==="`"){n=cp(u),r=s._1.tail;continue}n={...u,buf:Ot(u.buf)(s._1.head)},r=s._1.tail;continue}g()}return o},gg=t=>{const e=fp({style:ag,buf:[],runs:[]})(Zn(t));return cg(e.style)(e.buf)(e.runs)};let Js=null;function _p(){return Js||(typeof document>"u"?null:(Js=document.createElement("canvas").getContext("2d"),Js))}const fg=new Map,dp=t=>e=>n=>r=>()=>{const i=`${n} ${e}px ${t}|${r}`,o=fg.get(i);if(o!==void 0)return o;const u=_p();if(!u)return r.length*e*.62;u.font=`${n} ${e}px ${t}`;const s=u.measureText(r).width;return fg.set(i,s),s},lp=ar.traverse(vu),hp=J(Lr)(0),Ar=(()=>{const t=tr(`\r
|
|
1
|
+
var Hv=(function(Tu){"use strict";function Ma(t){let e=0,n;return()=>{if(e===2)return n;if(e===1)throw new Error("Binding demanded before initialized");return e=1,n=t(),e=2,n}}function g(){throw new Error("Failed pattern match")}function En(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const ke=t=>e=>t,W=function(t){return function(e){for(var n=e.length,r=new Array(n),i=0;i<n;i++)r[i]=t(e[i]);return r}},P1={map:W},Oa=t=>t,Tt=typeof Array.prototype.flatMap=="function"?function(t){return function(e){return t.flatMap(e)}}:function(t){return function(e){for(var n=[],r=t.length,i=0;i<r;i++)for(var o=e(t[i]),u=o.length,s=0;s<u;s++)n.push(o[s]);return n}},oe=function(t){return t.toString()},Ra=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},D1=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})+'"'},wu=t=>t,xe=wu("LT"),Ne=wu("GT"),Ge=wu("EQ"),v=(t,e)=>({tag:t,_1:e}),T=v("Nothing"),Xt=t=>v("Just",t),Ba=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;g()},za=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;g()},Pt=(t,e)=>({tag:t,_1:e}),I1=t=>Pt("Right",t),Q1={map:t=>e=>{if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right")return Pt("Right",t(e._1));g()}},Wa={apply:t=>e=>{if(t.tag==="Left")return Pt("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right")return Pt("Right",t._1(e._1))}g()},Functor0:()=>Q1},F1={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Pt("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}g()},Apply0:()=>Wa},A1={pure:I1,Apply0:()=>Wa},qa={Applicative0:()=>A1,Bind1:()=>F1},M1=t=>t,O1={map:t=>e=>t(e)},Ha={apply:t=>e=>t(e),Functor0:()=>O1},R1={bind:t=>e=>e(t),Apply0:()=>Ha},B1={pure:M1,Apply0:()=>Ha},$n={Applicative0:()=>B1,Bind1:()=>R1},z1=function(t){return function(){return t}},W1={apply:t=>e=>()=>{const n=t(),r=e();return vu.pure(n(r))()},Functor0:()=>q1},vu={pure:z1,Apply0:()=>W1},q1={map:t=>e=>()=>{const n=e();return t(n)}},ei=(t,e)=>({tag:t,_1:e}),$a=t=>ei("Loop",t),H1={tailRecM:t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="Loop"){r=t(u._1);continue}if(u.tag==="Done"){i=!1,o=u._1;continue}g()}return o};return n=>e(t(n))},Monad0:()=>$n},$1=function(t){return function(e){return function(){return t(e())}}},X1=function(t){return function(){return t}},Y1={map:$1},V1={apply:t=>e=>()=>{const n=t(),r=e();return Xa.pure(n(r))()},Functor0:()=>Y1},Xa={pure:X1,Apply0:()=>V1},U1=(function(t){return function(e){return function(n){return function(){return t(e,n)}}}})(function(t,e){return e.push(t)}),Z1=(t,e)=>({tag:"Iterator",_1:t,_2:e}),K1=t=>e=>n=>()=>{let r=!1;const i=e._2;for(;!r;){const o=i.value,u=e._1(o);if(u.tag==="Just"&&t(u._1)){n.push(u._1),e._2.value;const s=e._2.value;e._2.value=s+1|0;continue}r=!0}},j1=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const i=r.value,o=r.value;r.value=o+1|0;const u=t._1(i);if(u.tag==="Just"){e(u._1)();continue}if(u.tag==="Nothing"){n=!0;continue}g()}},ni=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}}},bu=t=>{const e=t.Apply0();return n=>r=>n.foldr(i=>{const o=r(i);return u=>e.apply(e.Functor0().map(s=>Oa)(o))(u)})(t.pure())},td=t=>{const e=bu(t);return n=>{const r=e(n);return i=>o=>r(o)(i)}},zt={foldr:ni,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}),Cn=t=>e=>b(t,e),ji=t=>t._2,to=t=>t._1,Ft=function(t){return function(e){for(var n=e.length,r=Array(n),i=0;i<n;i++)r[i]=t(i)(e[i]);return r}};var ku=function(t){return function(e){return t===e}};const ed=ku,nd=ku,ri=ku,Lu=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:ri},rd={eq:nd},vr={eq:ed};var Eu=function(t){return function(e){return function(n){return function(r){return function(i){return r<i?t:r===i?e:n}}}}};const id=Eu,od=Eu,C={compare:Eu(xe)(Ge)(Ne),Eq0:()=>fn},ut={compare:od(xe)(Ge)(Ne),Eq0:()=>rd},it={compare:id(xe)(Ge)(Ne),Eq0:()=>vr},ud=function(t){return t},sd=(function(){function t(i){return[i]}function e(i){return function(o){return[i,o]}}function n(i){return function(o){return function(u){return[i,o,u]}}}function r(i){return function(o){return i.concat(o)}}return function(i){return function(o){return function(u){return function(s){return function(a){function c(f,d){switch(d-f){case 0:return u([]);case 1:return o(t)(s(a[f]));case 2:return i(o(e)(s(a[f])))(s(a[f+1]));case 3:return i(i(o(n)(s(a[f])))(s(a[f+1])))(s(a[f+2]));default:var l=f+Math.floor((d-f)/4)*2;return i(o(r)(c(f,l)))(c(l,d))}}return c(0,a.length)}}}}}})(),ad=t=>t,ar={traverse:t=>{const e=t.Apply0();return sd(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>ar.traverse(t)(ad),Functor0:()=>P1,Foldable1:()=>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 cd=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},gd=function(t,e){for(var n=[],r=0,i=0;i<t;i++)n[r++]=e;return n};const fd=typeof Array.prototype.fill=="function"?cd:gd,Ct=(function(){function t(i,o){this.head=i,this.tail=o}var e={};function n(i){return function(o){return new t(i,o)}}function r(i){for(var o=[],u=0,s=i;s!==e;)o[u++]=s.head,s=s.tail;return o}return function(i,o){return r(i(n)(e)(o))}})(),Mt=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},Ya=function(t,e,n,r){for(var i=0;i<r.length;i++){var o=n(r[i]);if(e(o))return o}return t},cr=function(t,e,n,r){for(var i=0,o=r.length;i<o;i++)if(n(r[i]))return t(i);return e},Va=function(t,e,n,r){for(var i=r.length-1;i>=0;i--)if(n(r[i]))return t(i);return e},Ua=function(t,e,n,r,i){if(n<0||n>i.length)return e;var o=i.slice();return o.splice(n,0,r),t(o)},Za=function(t,e,n,r){if(n<0||n>=r.length)return e;var i=r.slice();return i.splice(n,1),t(i)},Xn=function(t,e,n,r,i){if(n<0||n>=i.length)return e;var o=i.slice();return o[n]=r,t(o)},Je=function(t){return t.slice().reverse()},Oe=function(t){if(t.length<=1e4)return Array.prototype.concat.apply([],t);for(var e=[],n=0,r=t.length;n<r;n++)for(var i=t[n],o=0,u=i.length;o<u;o++)e.push(i[o]);return e},st=function(t,e){return e.filter(t)},_d=function(t,e,n){for(var r=n.length,i=e,o=new Array(r),u=0;u<r;u++)i=t(i)(n[u]),o[u]=i;return o},dd=(function(){function t(e,n,r,i,o,u){var s,a,c,f,d,l,_;for(s=o+(u-o>>1),s-o>1&&t(e,n,i,r,o,s),u-s>1&&t(e,n,i,r,s,u),a=o,c=s,f=o;a<s&&c<u;)d=i[a],l=i[c],_=n(e(d)(l)),_>0?(r[f++]=l,++c):(r[f++]=d,++a);for(;a<s;)r[f++]=i[a++];for(;c<u;)r[f++]=i[c++]}return function(e,n,r){var i;return r.length<2?r:(i=r.slice(0),t(e,n,i,r.slice(0),0,r.length),i)}})(),bt=function(t,e,n){return n.slice(t,e)},Te=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},Ka=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Lt=t=>e=>dd(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),ld=t=>e=>Lt(n=>r=>t.compare(e(n))(e(r))),Ot=t=>e=>(()=>{const n=U1(e);return()=>{const r=[...t];return n(r)(),r}})()(),ii=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},hd=t=>e=>n=>t>=0&&t<n.length?Xn(Xt,T,t,e(n[t]),n):T,gr=t=>e=>{const n=(r=>{let i=r,o=!0,u;for(;o;){const s=i;if(s>=0&&s<e.length){if(t(e[s])){i=s+1|0;continue}o=!1,u=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()},br=t=>e=>{const n=Lt(r=>i=>t(r._2)(i._2))(Ft(Cn)(e));return 0<n.length?W(ji)(ld(it)(to)((()=>{const r=[n[0]];for(const i of n){const o=t((()=>{const u=r.length-1|0;if(u>=0&&u<r.length)return r[u]._2;g()})())(i._2);(o==="LT"||o==="GT"||o!=="EQ")&&r.push(i)}return r})())):[]},pd=t=>e=>{const n=[],r=Z1(i=>i>=0&&i<e.length?v("Just",e[i]):T,{value:0});return j1(r)(i=>()=>{const o=[];o.push(i),K1(t(i))(r)(o)(),n.push(o)})(),n},Vt=t=>e=>{const n=cr(Xt,T,t,e);return n.tag==="Just"?v("Just",e[n._1]):T},ja=t=>e=>st(t,e),Be=t=>e=>n=>{const r=cr(Xt,T,i=>t.eq(i)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},tc=t=>e=>Tt(e)(t),xt=t=>tc(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];g()}),ec=isFinite;function md(t,e,n,r){var i=parseFloat(t);return e(i)?n(i):r}const Yn=Math.abs,yd=Math.acos,fr=function(t){return function(e){return Math.atan2(t,e)}},eo=Math.ceil,en=Math.cos,no=Math.exp,ln=Math.floor,nc=Math.log,xd=function(t){return function(e){return Math.min(t,e)}},Cu=function(t){return function(e){return Math.pow(t,e)}},Vn=Math.round,He=Math.sin,Le=Math.sqrt,Nd=Math.tan,Jd=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},rt=function(t){return t},Td=(function(t){return function(e){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var i=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(o){if(i.test(o)){var u=parseInt(o,n);return(u|0)===u?t(u):e}else return e}}}})(Xt)(T)(10),rc=Jd(Xt)(T),de=t=>{if(!ec(t))return 0;if(t>=rt(2147483647))return 2147483647;if(t<=rt(-2147483648))return-2147483648;const e=rc(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;g()},qt=(t,e,n)=>({tag:t,_1:e,_2:n}),Ht=qt("Nil"),$t={foldr:t=>e=>{const n=$t.foldl(i=>o=>t(o)(i))(e),r=(i=>o=>{let u=i,s=o,a=!0,c;for(;a;){const f=u,d=s;if(d.tag==="Nil"){a=!1,c=f;continue}if(d.tag==="Cons"){u=qt("Cons",d._1,f),s=d._2;continue}g()}return c})(Ht);return i=>n(r(i))},foldl:t=>e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=t(s)(a._1),i=a._2;continue}g()}return u},foldMap:t=>{const e=t.mempty;return n=>$t.foldl(r=>{const i=t.Semigroup0().append(r);return o=>i(n(o))})(e)}},wd=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);u.push(n(a));var c=r(a);if(t(c))return u;s=e(c)}}}}}}},vd=t=>{if(t.tag==="Just")return t._1;g()},bd={unfoldr1:wd(Ba)(vd)(to)(ji)},kd=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);if(t(a))return u;var c=e(a);u.push(n(c)),s=r(c)}}}}}}},Ld=t=>{if(t.tag==="Just")return t._1;g()},$e={unfoldr:kd(Ba)(Ld)(to)(ji),Unfoldable10:()=>bd},Wt=(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}),ro=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),ic=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),Q=Wt("Leaf"),hn=Xe("IterLeaf"),se=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return Wt("Node",1,1,t,e,n,r);if(r.tag==="Node")return Wt("Node",1+r._1|0,1+r._2|0,t,e,n,r);g()}if(n.tag==="Node"){if(r.tag==="Leaf")return Wt("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return Wt("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"?Wt("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()},kr=(t,e,n)=>{if(n.tag==="Leaf")return ro(T,Q,Q);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const i=kr(t,e,n._5);return ro(i._1,i._2,ze(n._3,n._4,i._3,n._6))}if(r==="GT"){const i=kr(t,e,n._6);return ro(i._1,ze(n._3,n._4,n._5,i._2),i._3)}if(r==="EQ")return ro(v("Just",n._4),n._5,n._6)}g()},oc=(t,e,n,r)=>{if(r.tag==="Leaf")return ic(t,e,n);if(r.tag==="Node"){const i=oc(r._3,r._4,r._5,r._6);return ic(i._1,i._2,ze(t,e,n,i._3))}g()},oi=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=oc(t._3,t._4,t._5,t._6);return ze(n._1,n._2,n._3,e)}g()},Sn=(t,e,n)=>{if(e.tag==="Leaf")return Q;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=kr(t,n._3,e);return oi(Sn(t,r._2,n._5),Sn(t,r._3,n._6))}g()},io=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return Q;if(r.tag==="Node"){const i=kr(t,r._3,n),o=io(t,e,i._2,r._5),u=io(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 oi(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=kr(t,r._3,n),o=Ee(t,e,i._2,r._5),u=Ee(t,e,i._3,r._6);if(i._1.tag==="Just")return ze(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return ze(r._3,r._4,o,u)}g()},Ed=t=>e=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node"){const i=e(r._3)(r._4);if(i.tag==="Just")return ze(r._3,i._1,n(r._5),n(r._6));if(i.tag==="Nothing")return oi(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 Wt("Node",1,1,n,r,Q,Q);if(o.tag==="Node"){const u=t.compare(n)(o._3);if(u==="LT")return ze(o._3,o._4,i(o._5),o._6);if(u==="GT")return ze(o._3,o._4,o._5,i(o._6));if(u==="EQ")return Wt("Node",o._1,o._2,n,e(o._4)(r),o._5,o._6)}g()};return i},j=t=>e=>n=>{const r=i=>{if(i.tag==="Leaf")return Wt("Node",1,1,e,n,Q,Q);if(i.tag==="Node"){const o=t.compare(e)(i._3);if(o==="LT")return ze(i._3,i._4,r(i._5),i._6);if(o==="GT")return ze(i._3,i._4,i._5,r(i._6));if(o==="EQ")return Wt("Node",i._1,i._2,e,n,i._5,i._6)}g()};return r},jt=t=>e=>e.foldl(n=>r=>j(t)(r._1)(r._2)(n))(Q),ui=t=>e=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node"){const i=t.compare(e)(r._3);if(i==="LT")return ze(r._3,r._4,n(r._5),r._6);if(i==="GT")return ze(r._3,r._4,r._5,n(r._6));if(i==="EQ")return oi(r._5,r._6)}g()};return n},uc=t=>{const e=t.compare;return n=>r=>i=>{const o=kr(e,r,i),u=n(o._1);if(u.tag==="Nothing")return oi(o._2,o._3);if(u.tag==="Just")return ze(r,u._1,o._2,o._3);g()}},ue=function(t){return function(e){return t+e|0}},Lr=function(t){return function(e){return t+e}},Un=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},Cd=function(t){return function(e){return t+e}},ee=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},Sd={append:Cd},Gd={append:ee},Pd={mempty:"",Semigroup0:()=>Sd},Dd={mempty:[],Semigroup0:()=>Gd},Id=null;function sc(t,e,n){return t==null?e:n(t)}function qv(t){return t}function Su(t){return function(e){return function(n){return t.apply(n,[e])}}}const Qd=Su(Number.prototype.toPrecision),Fd=Su(Number.prototype.toFixed),Ad=Su(Number.prototype.toExponential),si=(t,e)=>({tag:t,_1:e}),ai=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()},ci=t=>{if(t.tag==="Precision")return Qd(t._1);if(t.tag==="Fixed")return Fd(t._1);if(t.tag==="Exponential")return Ad(t._1);g()},ac=function(t){return function(){console.log(t)}};function Md(){return Date.now()}function Od(t){return function(){return t.getContext("2d")}}function Rd(t){return function(){return t.width}}function Bd(t){return function(){return t.height}}function zd(t){return function(e){return function(){t.width=e}}}function Wd(t){return function(e){return function(){t.height=e}}}function Gu(t){return function(e){return function(){t.lineWidth=e}}}function qd(t){return function(e){return function(){t.fillStyle=e}}}function Hd(t){return function(e){return function(){t.strokeStyle=e}}}function Pu(t){return function(e){return function(){t.lineCap=e}}}function Du(t){return function(e){return function(){t.lineJoin=e}}}function $d(t){return function(e){return function(){t.globalCompositeOperation=e}}}function Xd(t){return function(e){return function(){t.globalAlpha=e}}}function cc(t){return function(){t.beginPath()}}function Iu(t){return function(){t.stroke()}}function Qu(t){return function(){t.fill()}}function Yd(t){return function(){t.clip()}}function gi(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function gc(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function fc(t){return function(){t.closePath()}}function Vd(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function Ud(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function oo(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function Fu(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function Zd(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function Kd(t){return function(e){return function(){t.textAlign=e}}}function jd(t){return function(e){return function(){t.textBaseline=e}}}function tl(t){return function(e){return function(){t.font=e}}}function el(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function _r(t){return function(){t.save()}}function dr(t){return function(){t.restore()}}function fi(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function nl(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const _c=t=>t,Au=t=>t,Mu=t=>t,Ou=t=>t,uo=t=>t,rl=uo("BaselineTop"),il=uo("BaselineMiddle"),ol=uo("BaselineAlphabetic"),ul=uo("BaselineBottom"),sl=Ou("AlignLeft"),al=Ou("AlignRight"),cl=Ou("AlignCenter"),Ru=Mu("BevelJoin"),so=Mu("RoundJoin"),Bu=Mu("MiterJoin"),zu=Au("Round"),Wu=Au("Square"),qu=Au("Butt"),gl=_c("SourceOver"),fl=_c("Difference"),_l=t=>e=>jd(t)((()=>{if(e==="BaselineTop")return"top";if(e==="BaselineHanging")return"hanging";if(e==="BaselineMiddle")return"middle";if(e==="BaselineAlphabetic")return"alphabetic";if(e==="BaselineIdeographic")return"ideographic";if(e==="BaselineBottom")return"bottom";g()})()),dl=t=>e=>Kd(t)((()=>{if(e==="AlignLeft")return"left";if(e==="AlignRight")return"right";if(e==="AlignCenter")return"center";if(e==="AlignStart")return"start";if(e==="AlignEnd")return"end";g()})()),ao=t=>e=>{if(e==="BevelJoin")return Du(t)("bevel");if(e==="RoundJoin")return Du(t)("round");if(e==="MiterJoin")return Du(t)("miter");g()},Hu=t=>e=>{if(e==="Round")return Pu(t)("round");if(e==="Square")return Pu(t)("square");if(e==="Butt")return Pu(t)("butt");g()},dc=t=>e=>$d(t)((()=>{if(e==="SourceOver")return"source-over";if(e==="SourceIn")return"source-in";if(e==="SourceOut")return"source-out";if(e==="SourceAtop")return"source-atop";if(e==="DestinationOver")return"destination-over";if(e==="DestinationIn")return"destination-in";if(e==="DestinationOut")return"destination-out";if(e==="DestinationAtop")return"destination-atop";if(e==="Lighter")return"lighter";if(e==="Copy")return"copy";if(e==="Xor")return"xor";if(e==="Multiply")return"multiply";if(e==="Screen")return"screen";if(e==="Overlay")return"overlay";if(e==="Darken")return"darken";if(e==="Lighten")return"lighten";if(e==="ColorDodge")return"color-dodge";if(e==="ColorBurn")return"color-burn";if(e==="HardLight")return"hard-light";if(e==="SoftLight")return"soft-light";if(e==="Difference")return"difference";if(e==="Exclusion")return"exclusion";if(e==="Hue")return"hue";if(e==="Saturation")return"saturation";if(e==="Color")return"color";if(e==="Luminosity")return"luminosity";g()})()),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,qt("Cons",o._3,i(o._6,u)));g()};return i(r,Ht)})())}},ll=t=>{const e={append:(()=>{const n=t.compare;return r=>i=>Ee(n,ke,r,i)})()};return{mempty:Q,Semigroup0:()=>e}},_i=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},lr=function(t){return t.join("")},Zn=function(t){return t.split("")},co=function(t){return t},Kn=function(t){return t.length},lc=function(t){return function(e){return e.substr(0,t)}},di=function(t){return function(e){return e.substring(t)}},hl=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},pl=t=>e=>{const n=hl(Kn(t))(e);return n.before===t?v("Just",n.after):T},ml=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},yl=function(t){return t()},xl=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},Nl=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},hr=t=>BigInt(t),Jl=t=>Number(t),go=t=>e=>t+e,fo=t=>e=>t*e,$u=t=>e=>t-e,hc=0n,_o=1n,pc=t=>e=>t^e,li=t=>e=>t&e,Xu=t=>e=>t<<e,Yu=t=>e=>t>>e,Tl=t=>e=>t==e,wl=t=>e=>t===e?0:t>e?1:-1,vl={eq:Tl},mc={compare:t=>e=>{const n=wl(t)(e);return n===1?Ne:n===0?Ge:xe},Eq0:()=>vl},bl=xl(Xt)(T),kl=Nl(Xt)(T),yc=(()=>{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"?xe:r==="GT"?Ne:ut.compare(e._2)(n._2)},Eq0:()=>t}})(),Ll=t=>e=>Yn(t._1-e._1)+Yn(t._2-e._2),pr=t=>t,lo=t=>t,le=lo("North"),he=lo("South"),Gn=lo("East"),Pn=lo("West"),jn=pr("Rectangle"),El=pr("Cylinder"),Cl=pr("Parallelogram"),Sl=pr("Diamond"),Gl=pr("Ellipse"),Pl=pr("Document"),Dl=pr("Cloud"),xc=t=>t,Nc=J(Lr)(0),Il=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()},hi=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Jc=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},Tc=t=>{const e={top:0,bottom:0,left:0,right:0},n=t.shape==="Cloud"?{...e,top:t.h*.38}:t.shape==="Cylinder"?{...e,bottom:5}:t.shape==="Document"?{...e,bottom:t.h*.05}:e;return[{x:t.x-n.left,y:t.y-n.top},{x:t.x+t.w+n.right,y:t.y+t.h+n.bottom}]},mr=t=>e=>{const n=Te(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,c=s.x-u.x;return Le(c*c+a*a)})()}),t,bt(1,t.length,t)),r=Nc(W(u=>u.len)(n)),i=Il(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=Mt(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},Ql=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=hi(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}},pi=t=>Nc(Te(e=>n=>{const r=n.y-e.y,i=n.x-e.x;return Le(i*i+r*r)},t,bt(1,t.length,t))),Fl=t=>e=>n=>r=>i=>{const o=0<t.length?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+pi(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=mr(t)((d-x)/mn(1e-4)(y-x));if(N.tag==="Nothing")return u;if(N.tag==="Just")return N._1;g()},Al=t=>{const e=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return e(r._5,qt("Cons",r._4,e(r._6,i)));g()},n=Mt(r=>T,r=>i=>v("Just",{head:r,tail:i}),Tt(Ct($t.foldr,e(t.nodes,Ht)))(Tc));if(n.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(n.tag==="Just"){const r=J(i=>o=>({minX:hi(i.minX)(o.x),minY:hi(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()},Vu={scale:1,tx:0,ty:0},Ye=t=>{const e=Mt(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)))(Tc)})(),...Oe((()=>{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))})()),...Oe((()=>{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:hi(r.minX)(i.x),minY:hi(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()},Ml=t=>e=>(n=>r=>i=>{let o=n,u=r,s=i,a=!0,c;for(;a;){const f=o,d=u,l=s,_=Mt(h=>T,h=>p=>v("Just",{head:h,tail:p}),d);if(_.tag==="Nothing"){a=!1,c=l;continue}if(_.tag==="Just"){const h=Jc(_._1.head)(f.interiors);if(h.tag==="Nothing"){a=!1,c=l;continue}if(h.tag==="Just"){o=h._1,u=_._1.tail,s=(()=>{const p=Ql(Ye(h._1.layout))((()=>{const m=Jc(_._1.head)(f.layout.nodes);if(m.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:jn};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)(Vu),wc=t=>t,vc=(t,e)=>({tag:t,_1:e}),Uu=t=>t,mi=(t,e)=>({tag:t,_1:e}),Zu=(t,e)=>({tag:t,_1:e}),yi=Uu("Animated"),Ol=Uu("StaticStill"),Rl=Uu("TitleCard"),Bl=Zu("First"),zl=wc("Forward"),Wl=wc("Backward"),ql=mi("ExitNode"),bc=jt(C)(zt),Hl=t=>ni(e=>n=>({nodes:Ee(C.compare,ke,e.nodes,n.nodes),edges:Ee(C.compare,ke,e.edges,n.edges)}))({nodes:Q,edges:Q})(t.keyframes),$l=t=>e=>({entering:{nodes:Sn(C.compare,e.nodes,t.nodes),edges:Sn(C.compare,e.edges,t.edges)},leaving:{nodes:Sn(C.compare,t.nodes,e.nodes),edges:Sn(C.compare,t.edges,e.edges)},surviving:{nodes:io(C.compare,ke,t.nodes,e.nodes),edges:io(C.compare,ke,t.edges,e.edges)}}),ho=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()},xi=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},Ku=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Xl=J(t=>e=>j(C)(e)()(t))(Q),Yl=J(t=>e=>j(C)(e)()(t))(Q),Vl=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),kc=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},Lc=jt(C)(zt),Ni=t=>{const e=Mt(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:ho(r.minX)(i.x),minY:ho(r.minY)(i.y),maxX:Er(r.maxX)(i.x),maxY:Er(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},Ul=t=>{const e=Mt(n=>T,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return T;if(e.tag==="Just")return v("Just",Ni(t));g()},Zl=t=>e=>n=>Xl(Tt(Ct(We.foldr,n))(r=>{const i=xi(r)(t);if(i.tag==="Just")return st(o=>!Ku(o)(e),[i._1.source,i._1.target]);if(i.tag==="Nothing")return[];g()})),Kl=t=>t.kind.tag==="SendToken"?v("Just",b(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):T,jl=t=>t.tag==="DataFlow"?xt(Kl)(t._1.events):[],th=t=>e=>Yl(xt(n=>Ku(n._2.source)(e)||Ku(n._2.target)(e)?v("Just",n._1):T)(Vl(t))),eh=t=>{const e=t.length-1|0;return e>=0&&e<t.length?0<t.length?t[0].x===t[e].x&&t[0].y===t[e].y?v("Just",Ni([t[0]])):v("Just",Ni([t[0],t[e]])):T:0<t.length?v("Just",Ni([t[0]])):T},po=t=>{const e=Mt(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:ho(r.minX)(i.x),minY:ho(r.minY)(i.y),maxX:Er(r.maxX)(i.x+i.w),maxY:Er(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()},Ec=t=>e=>n=>{if(n.tag==="Leaf")return Ye(t);const r=th(e)(n),i=[...xt(o=>{const u=kc(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(We.foldr,Ee(C.compare,ke,n,Zl(e)(n)(r)))),...xt(o=>{const u=xi(o)(t.edges);return u.tag==="Just"?v("Just",Ni(u._1)):T})(Ct(We.foldr,r)),...xt(o=>{const u=xi(o)(t.chipExtras);if(u.tag==="Just")return Ul(u._1);if(u.tag==="Nothing")return T;g()})(Ct(We.foldr,r))];return i.length===0?Ye(t):po(i)},Ji=t=>e=>n=>{const r=[...xt(i=>i)([(()=>{const i=xi(n)(t.chipExtras);if(i.tag==="Just")return eh(i._1);if(i.tag==="Nothing")return T;g()})()]),...(()=>{const i=xi(n)(e);if(i.tag==="Just")return xt(o=>{const u=kc(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?Ec(t)(e)(Q):po(r)},ju=t=>e=>{const n=Ye(t),r=n.w/Er(1e-4)(e.zoom),i=n.h/Er(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-i/2,w:r,h:i}},nh=t=>Ee(C.compare,ke,Lc(W(e=>b(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),Lc(Tt(t.scenes)(jl))),ts=t=>t,rh=t=>t,yr=ts("Linear"),ih=ts("EaseInOutQuad"),oh=ts("SpringBouncy"),Ti=t=>e=>n=>{const r=Le(1-e*e),i=t*r;return 1-no(-e*t*n)*(en(i*n)+e/r*He(i*n))},uh=t=>{const e=ut.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ut.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},es=t=>e=>(()=>{if(t==="Linear")return rh;if(t==="EaseInQuad")return n=>n*n;if(t==="EaseOutQuad")return n=>1-(1-n)*(1-n);if(t==="EaseInOutQuad")return n=>n<.5?2*n*n:1-2*(1-n)*(1-n);if(t==="EaseInCubic")return n=>n*n*n;if(t==="EaseOutCubic")return n=>1-(1-n)*(1-n)*(1-n);if(t==="EaseInOutCubic")return n=>n<.5?4*n*n*n:1-(-2*n+2)*(-2*n+2)*(-2*n+2)/2;if(t==="EaseOutExpo")return n=>n>=1?1:1-Cu(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*no(-6*n);if(t==="SpringBouncy")return Ti(6)(.7);g()})()(uh(e)),Cc=t=>t,ns=t=>t,mo=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()},wi=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Sc=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},sh=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ah=ns("Hold"),ch=ns("Gap"),gh=ns("Move"),vi=Cc("LinearLerp"),Gc=Cc("LogLerp"),fh=t=>e=>n=>{const r=n.center.y-e.center.y,i=n.center.x-e.center.x,o=Le(i*i+r*r),u=n.zoom-e.zoom,s=u<0?-u:u;return mo(t.minTransition)(t.maxTransition)(wi(t.panSpeed<=0?t.minTransition:o/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:s/t.zoomSpeed))},_h=J(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:Ot(t)(e)})([]),Pc=t=>e=>{const n={x:0,y:0},r=0<t.length?t[0].pos:n,i=Va(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=mo(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()},rs=t=>e=>({center:{x:e.center.x*t.scale+t.tx,y:e.center.y*t.scale+t.ty},zoom:e.zoom/wi(1e-6)(t.scale)}),dh=t=>e=>n=>({center:{x:t.center.x+(e.center.x-t.center.x)*n,y:t.center.y+(e.center.y-t.center.y)*n},zoom:no((()=>{const r=nc(wi(1e-6)(t.zoom));return r+(nc(wi(1e-6)(e.zoom))-r)*n})())}),lh=t=>e=>n=>{const r=es(n.easing)(mo(0)(1)(n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT)));if(n.interp==="LinearLerp")return{center:{x:n.fromCam.center.x+(n.toCam.center.x-n.fromCam.center.x)*r,y:n.fromCam.center.y+(n.toCam.center.y-n.fromCam.center.y)*r},zoom:n.fromCam.zoom+(n.toCam.zoom-n.fromCam.zoom)*r};if(n.interp==="LogLerp")return dh(n.fromCam)(n.toCam)(r);g()},hh=t=>e=>n=>r=>{const i=(u,s)=>Sc(fh(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:Ot(u.acc)(u.pending._1),pending:v("Just",s)}:{acc:Ot(Ot(u.acc)({...u.pending._1,endT:s.startT-i(u.pending._1,s)}))({startT:s.startT-i(u.pending._1,s),endT:s.startT,fromCam:u.pending._1.toCam,toCam:s.toCam,easing:s.easing,interp:vi}),pending:v("Just",s)};g()})({acc:[],pending:T})(r);if(o.pending.tag==="Nothing")return o.acc;if(o.pending.tag==="Just")return Ot(o.acc)(o.pending._1);g()},ph=t=>e=>{const n=r=>{const i=Va(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 Ft(r=>i=>{if(i.kind==="Hold")return{startT:i.startT,endT:i.endT,fromCam:i.fromCam,toCam:i.toCam,easing:i.easing,interp:vi};if(i.kind==="Move")return{startT:i.startT,endT:i.endT,fromCam:i.fromCam,toCam:i.toCam,easing:yr,interp:vi};if(i.kind==="Gap")return{startT:i.startT,endT:i.endT,fromCam:(()=>{const o=n(r);if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;g()})(),toCam:(()=>{const o=n(r),u=(()=>{if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;g()})(),s=r+1|0,a=cr(Xt,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:vi};g()})(e)},mh={padding:24,easing:yr,minZoom:.9,maxZoom:2.5,tokenZoomFloor:0,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:16},is=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:Sc(o.w/r)(o.h/i)},yh=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})()})()})()?Ot((()=>{const i=t.length-1|0;return i<1?[]:bt(0,i,t)})())({...r._1,endT:e.endT}):Ot(t)(e)})([]),bi=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:wi(r)(mo(t.minZoom)(t.maxZoom)(is(e)(n)(t.padding)))}),xh=t=>e=>n=>r=>{const i=Lt(s=>a=>it.compare(a.priority)(s.priority)),o=bi(t)(e)(Ye(e))(0),u=st(s=>s>=0&&s<=n,_h(Lt(ut.compare)([0,n,...Tt(r)(s=>[s.startT,s.endT]),...Tt(r)(s=>{if(s.pathFollow.tag==="Nothing")return[];if(s.pathFollow.tag==="Just")return W(a=>a.t)(s.pathFollow._1.samples);g()})])));return hh(t)(e)(o)(yh(ph(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:gh,startT:s._1,endT:s._2,fromCam:{center:Pc(c[0].samples)(s._1),zoom:c[0].zoom},toCam:{center:Pc(c[0].samples)(s._2),zoom:c[0].zoom},easing:yr});const f=W(d=>d.bbox)(st(d=>d.priority===J(sh)(0)(W(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:ch,startT:s._1,endT:s._2,fromCam:o,toCam:o,easing:t.easing}):v("Just",{kind:ah,startT:s._1,endT:s._2,fromCam:bi(t)(e)(po(f))(Re(d=>d.priority>=1,st(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),toCam:bi(t)(e)(po(f))(Re(d=>d.priority>=1,st(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),easing:t.easing})})(Te(Cn,u,bt(1,u.length,u))))))},Dc=t=>e=>n=>r=>{const i=Vt(o=>r>=o.startT&&r<o.endT)(n);if(i.tag==="Just")return lh()(r)(i._1);if(i.tag==="Nothing"){const o=n.length-1|0;if(o>=0&&o<n.length&&r>=n[o].endT)return n[o].toCam;const u=bi(t)(e)(Ye(e))(0);return 0<n.length?n[0].fromCam:u}g()};function Dn(t){return t.charCodeAt(0)}function Ic(t){return String.fromCharCode(t)}const tr=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},yo=function(t){return function(e){return e.split(t)}},Nh=function(t){return t.trim()},xo=function(t){return function(e){return e.join(t)}};var Jh=typeof Array.from=="function",Th=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",wh=typeof String.prototype.fromCodePoint=="function",vh=typeof String.prototype.codePointAt=="function";const bh=function(t){return vh?function(e){return e.codePointAt(0)}:t},kh=function(t){return wh?String.fromCodePoint:t},Lh=function(t){return function(e){return Th?function(n){for(var r="",i=n[Symbol.iterator](),o=0;o<e;++o){var u=i.next();if(u.done)return r;r+=u.value}return r}:t(e)}},Eh=function(t){return function(e){return Jh?function(n){return Array.from(n,e)}:t}},No=t=>{const e=Kn(t);if(e===0)return T;if(e===1)return v("Just",{head:Dn(_i(0)(t)),tail:""});const n=Dn(_i(1)(t)),r=Dn(_i(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:di(2)(t)}):v("Just",{head:r,tail:di(1)(t)})},Ch=t=>{const e=No(t);return e.tag==="Just"?v("Just",b(e._1.head,e._1.tail)):T},Sh=t=>$e.unfoldr(Ch)(t),Qc=bh(t=>{const e=Dn(_i(0)(t));if(55296<=e&&e<=56319&&Kn(t)>1){const n=Dn(_i(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),Jo=Eh(Sh)(Qc),os=t=>co(t>=0&&t<=65535?Ic(t):t<0?"\0":"\uFFFF"),Gh=kh(t=>t<=65535?os(t):os(En(t-65536|0,1024)+55296|0)+os(Un(t-65536|0)(1024)+56320|0)),Fc=t=>e=>{if(t<1)return"";const n=No(e);return n.tag==="Just"?Gh(n._1.head)+Fc(t-1|0)(n._1.tail):e},me=Lh(Fc),Ph=t=>e=>e===""?T:v("Just",Qc(e)),Cr=(t,e,n)=>({tag:t,_1:e,_2:n}),Dh=()=>({tag:"ExtendFromSource"}),Sr=(t,e)=>({tag:t,_1:e}),us=t=>t,To=(t,e)=>({tag:t,_1:e}),ss=To("NotYet"),Ac=To("Consumed"),Ih=us("FromSource"),Mc=us("FromTarget"),Oc=us("FromBoth"),wo=Sr("Hidden"),Qh=Sr("Visible"),as=Dh(),vo=Cr("Retracted"),Fh=Cr("Extended"),Rc=t=>t,cs=(t,e)=>({tag:t,_1:e}),xr=(t,e,n)=>({tag:t,_1:e,_2:n}),Bc=t=>t,er=(t,e)=>({tag:t,_1:e}),Gr=(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}),ki=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()},zc=jt(C)(zt),gs=Lu(ri),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},bo=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Li=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},Wc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},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},Dr=(()=>{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)})())})(),Ah=J(t=>e=>j(C)(e)()(t))(Q),fs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},ko=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Mh=er("NoKeyframes"),Oh=t=>er("DuplicateEventId",t),Rh=t=>er("UnknownEvent",t),Hc=Bc("PlopIn"),Bh=Bc("PlopOut"),zh=Rc("DiveIn"),Wh=Rc("DiveOut"),qh=t=>e=>n=>r=>{const i=ki(r.edge)(e.edges),o=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return pi(i._1);g()})(),u=yn(t.minTokenDuration)(yn(rt(J(s=>a=>s+Jo(a).length|0)(0)(r.labels))*t.tokenReadSecPerChar)(t.tokenSpeed<=0?0:o/t.tokenSpeed))+n.pre+n.post;return{duration:u,holdPre:u<=0?0:n.pre/u,holdPost:u<=0?0:n.post/u}},Hh=t=>e=>zc(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 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)),$h=t=>{if(t.event.kind.tag==="SendToken")return v("Just",{startT:t.startT,endT:t.endT,target:Gr("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:Gr("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},Xh=t=>e=>n=>r=>{const i=Vt(o=>gs(o.path)(e)&&(Yn(o.endT-n)<1e-4||Yn(o.startT-r)<1e-4))(t.segments);if(i.tag==="Just")return v("Just",i._1);if(i.tag==="Nothing")return Vt(o=>gs(o.path)(e))(t.segments);g()},Yh=t=>e=>n=>xt(r=>{const i=xt(o=>Li(o)(t.nodes))(Ct(We.foldr,(()=>{if(r.scene.tag==="Structural")return Ee(C.compare,ke,(()=>{const o=Pr(r.scene._1.from)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()})(),(()=>{const o=Pr(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=Pr(r.scene._1.keyframe)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()}if(r.scene.tag==="Hold"){const o=Pr(r.scene._1)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()}if(r.scene.tag==="EnterNode"||r.scene.tag==="ExitNode")return Q;g()})()));return i.length===0?T:v("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const o=J(u=>s=>({minX:bo(u.minX)(s.x),minY:bo(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})}),Vh=t=>e=>n=>{const r=ki(n)(t);if(r.tag==="Nothing")return Mc;if(r.tag==="Just"){const i=Wc(r._1.target)(e);return Wc(r._1.source)(e)?i?Oc:Ih:Mc}g()},Uh={pre:0,post:0},Zh=t=>e=>n=>r=>i=>{const o=qc(i.event.id)(n),u=(()=>{if(o.tag==="Nothing")return Uh;if(o.tag==="Just")return o._1;g()})(),s=(()=>{if(i.event.when.tag==="First")return 0;if(i.event.when.tag==="At")return i.event.when._1;if(i.event.when.tag==="After"){const c=i.event.when._1,f=Vt(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.endT;g()}if(i.event.when.tag==="With"){const c=i.event.when._1,f=Vt(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.startT}g()})(),a=(()=>{if(i.event.kind.tag==="SendToken")return qh(t)(e)(u)(i.event.kind._1);if(i.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return Ot(r)({startT:s,endT:s+a.duration,event:i.event,holdPre:a.holdPre,holdPost:a.holdPost})},$c=t=>e=>n=>J(Zh(t)(e)(Hh(t)(n)))([])(Ft(r=>i=>({event:i}))(n)),Kh=t=>e=>{const n=Li(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},jh=t=>e=>({...e,fromCam:rs(t)(e.fromCam),toCam:rs(t)(e.toCam)}),t0=t=>{if(t.when.tag==="First")return[];if(t.when.tag==="At")return[];if(t.when.tag==="After")return[t.when._1];if(t.when.tag==="With")return[t.when._1];g()},Xc={id:"",nodes:Q,edges:Q,kind:yi},e0=t=>e=>$l((()=>{const n=Pr(e.from)(t);if(n.tag==="Nothing")return Xc;if(n.tag==="Just")return n._1;g()})())((()=>{const n=Pr(e.to)(t);if(n.tag==="Nothing")return Xc;if(n.tag==="Just")return n._1;g()})()),n0=t=>e=>{const n=Li(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:Q};if(n.tag==="Just")return n._1;g()},_s=t=>e=>n=>r=>{const i=ki(r)(n.edges);if(i.tag==="Just")return t<=0?e:yn(e)(pi(i._1)/t);if(i.tag==="Nothing")return e;g()},Yc=t=>e=>n=>r=>i=>{const o=t.plop,u=e0(n)(i),s=W(_=>({startT:0,endT:0+_s(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Gr("EdgeWindow",_,cs("Extend",as))}))(Dr(u.entering.edges)),a=W(_=>({startT:0,endT:o,target:Gr("NodeWindow",_,Hc)}))(Dr(u.entering.nodes)),c=J(yn)(0)(W(_=>_s(t.edgeSpeed)(t.minEdgeDuration)(e)(_))(Dr(u.leaving.edges))),f=_=>Re(h=>{const p=ki(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;g()},Dr(u.leaving.edges))?c:0,d=W(_=>({startT:f(_),endT:f(_)+t.plop,target:Gr("NodeWindow",_,Bh)}))(Dr(u.leaving.nodes)),l=W(_=>({startT:0,endT:_s(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Gr("EdgeWindow",_,cs("Retract",Vh(r)(u.leaving.nodes)(_)))}))(Dr(u.leaving.edges));return{duration:(()=>{const _=Lt(ut.compare)([...W(p=>p.endT)(l),...W(p=>p.endT)(d),...W(p=>p.endT)(a),...W(p=>p.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+t.gap:t.gap})(),windows:[...l,...d,...a,...s]}},r0=t=>e=>n=>r=>i=>o=>W((()=>{const u=i.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())(Yc(t)(e)(n)(r)(o).windows),i0=t=>xt(e=>Ct(ni,e).length>1?v("Just",(()=>{const n=Mt(r=>T,r=>i=>v("Just",{head:r,tail:i}),Ct(ni,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):T)(pd(ri)(Lt(C.compare)(t))),o0=t=>{const e=W(r=>r.id)(t),n=Ah(e);return[...W(Oh)(i0(e)),...W(Rh)(st(r=>!fs(r)(n),Tt(t)(t0)))]},u0=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:Ji(e)(n)(i.target._2),priority:1,pathFollow:T};const u=ki(i.target._2)(e.edges);if(u.tag==="Just"){const s=Li(i.target._4)(e.nodes);if(s.tag==="Just"){const a=Li(i.target._5)(e.nodes);if(a.tag==="Just"){const c=a._1;return{startT:i.startT,endT:i.endT,bbox:Ji(e)(n)(i.target._2),priority:1,pathFollow: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 W(_=>{const h=f+rt(_)/rt(32)*d;return{t:h,pos:Fl(u._1)({x:s._1.x+s._1.w/2,y:s._1.y+s._1.h/2})({x:c.x+c.w/2,y:c.y+c.h/2})(l<=0?0:(h-i.startT)/l)(o)}})(It(0,32))})(),zoom:r})}}if(a.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:Ji(e)(n)(i.target._2),priority:1,pathFollow:T};g()}if(s.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:Ji(e)(n)(i.target._2),priority:1,pathFollow:T};g()}if(u.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:Ji(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:Ec(e)(n)(Wt("Node",1,1,i.target._2,void 0,Q,Q)),priority:1,pathFollow:T});g()})},s0=t=>e=>n=>r=>i=>xh(t)(i.layout)(r.endT)([...Yh(i.layout)(n)(e)(st(o=>o.startT>=i.startT&&o.endT<=i.endT,r.spans)),...u0(t)(i.layout)(n)(i.windows)]),a0=t=>{const e=zc(W(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(fs(o)(i))return[er("ScheduleCycle",[...Ct(We.foldr,i),o])];if(fs(o)(r))return[];const u=qc(o)(e);if(u.tag==="Nothing")return[];if(u.tag==="Just")return Tt(u._1)(n(j(C)(o)()(r))(j(C)(o)()(i)));g()};return Tt(t)(r=>n(Q)(Q)(r.id))},c0={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:.5,stillHold:1.8,hatchHold:.4,tokenReadSecPerChar:.06,nodeEasing:oh,edgeEasing:ih,tokenEasing:yr,diveDur:1.2,retreatDur:1.2},g0=t=>e=>n=>r=>W((()=>{const i=n.startT;return o=>({...o,startT:o.startT+i,endT:o.endT+i})})())(xt($h)($c(t)(e)(r.events))),f0=t=>e=>n=>r=>i=>{if(i.scene.tag==="Structural")return r0(t)(e)(n)(r)(i)(i.scene._1);if(i.scene.tag==="Hold")return[];if(i.scene.tag==="DataFlow")return g0(t)(e)(i)(i.scene._1);if(i.scene.tag==="EnterNode")return[];if(i.scene.tag==="ExitNode")return[];g()},_0=t=>e=>n=>{const r=$c(t)(e)(n.events);return r.length===0?t.gap:J(yn)(0)(W(i=>i.endT)(r))+t.gap},d0=t=>e=>n=>r=>i=>{if(i.tag==="Structural")return Yc(t)(e)(n)(r)(i._1).duration;if(i.tag==="Hold")return t.stillHold;if(i.tag==="DataFlow")return _0(t)(e)(i._1);if(i.tag==="EnterNode"||i.tag==="ExitNode")return 0;g()},Vc=t=>e=>n=>r=>i=>o=>{const u=Ml(e)(r),s=n.layout,a=bc(W(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=nh(i),l=p=>({segments:p.runSpans.length===0?p.segments:Ot(p.segments)({startT:p.runStart,endT:p.t,path:r,layout:s,placement:u,windows:p.runWindows,spans:p.runSpans,keyframes:a,initialKeyframe:f,edgeEndpoints:d}),spans:p.spans,windows:p.windows,dives:p.dives}),_=J(p=>m=>{if(m.tag==="EnterNode"){const w=l(p),L=p.t+t.diveDur,k=Ot(r)(m._1),E=Vc(t)(e)(n0(n)(m._1))(k)(Kh(i)(m._1))(L),O=E.endT+t.retreatDur;return{...p,t:O,runStart:O,runSpans:[],runWindows:[],segments:[...w.segments,...E.segments],spans:[...w.spans,...E.spans],windows:[...w.windows,...E.windows],dives:[...w.dives,{startT:p.t,endT:L,node:m._1,parentPath:r,childPath:k,direction:zh},...E.dives,{startT:E.endT,endT:O,node:m._1,parentPath:r,childPath:k,direction:Wh}]}}if(m.tag==="ExitNode")return p;const y=p.t+d0(t)(s)(a)(d)(m),x={startT:p.t,endT:y,scene:m},N=f0(t)(s)(a)(d)(x);return{...p,t:y,runSpans:Ot(p.runSpans)(x),runWindows:[...p.runWindows,...N],spans:Ot(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:Lt(p=>m=>ut.compare(p.startT)(m.startT))(h.windows),segments:h.segments,dives:h.dives}},l0=t=>e=>n=>n.endT<=t||n.startT>=e?T:v("Just",{...n,startT:yn(t)(n.startT),endT:bo(e)(n.endT)}),ds=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:bo(is(e)(i)(t.padding*n.placement.scale))(40/(11*n.placement.scale))}},h0=t=>e=>n=>n.placement.scale===1&&n.placement.tx===0&&n.placement.ty===0?rs(n.placement)(bi(t)(n.layout)(Ye(n.layout))(0)):ds(t)(e)(n),p0=t=>e=>n=>r=>xt(i=>{const o=Xh(r)(i.parentPath)(i.startT)(i.endT);if(o.tag==="Just"){const u=i.childPath,s=Vt(a=>gs(a.path)(u))(r.segments);if(s.tag==="Just"){const a=h0(t)(e)(o._1),c=ds(t)(e)(s._1);if(i.direction==="DiveIn")return v("Just",{startT:i.startT,endT:i.endT,fromCam:a,toCam:c,easing:yr,interp:Gc});if(i.direction==="DiveOut")return v("Just",{startT:i.startT,endT:i.endT,fromCam:c,toCam:a,easing:yr,interp:Gc});g()}if(s.tag==="Nothing")return T;g()}if(o.tag==="Nothing")return T;g()})(r.dives),m0=t=>e=>{if(e.tag==="Structural")return xt(n=>n)([ko(e._1.from)(t)?T:v("Just",er("UnknownKeyframe",e._1.from)),ko(e._1.to)(t)?T:v("Just",er("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return xt(n=>n)([ko(e._1)(t)?T:v("Just",er("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...xt(n=>n)([ko(e._1.keyframe)(t)?T:v("Just",er("UnknownKeyframe",e._1.keyframe))]),...o0(e._1.events),...a0(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()},y0=t=>e=>{const n=Tt(e)(m0(t));return n.length===0?Pt("Right",void 0):Pt("Left",n)},x0=t=>e=>n=>r=>Lt(i=>o=>ut.compare(i.startT)(o.startT))(Tt(r.segments)(i=>i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0?xt(l0(i.startT)(i.endT))(W(jh(i.placement))(s0(t)(n)(i.edgeEndpoints)(r)(i))):[(()=>{const o=ds(t)(e)(i);return{startT:i.startT,endT:i.endT,fromCam:o,toCam:o,easing:yr,interp:vi}})()])),N0=t=>e=>n=>r=>{if(0<n.keyframes.length){const i=n.keyframes[0],o=bc(W(s=>b(s.id,s))(n.keyframes)),u=y0(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=Vc(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:[...x0(t)(r.layout)(o)(s),...p0(t)(r.layout)(o)(s)],cameraConfig:t,levelTree:r,segments:s.segments,dives:s.dives,seed:n.seed})})}return Pt("Left",[Mh])},ls=t=>e=>Math.imul(t,e),Ir=t=>{const e=t+1831565813|0,n=ls(e^e>>>15)(e|1),r=n^(n+ls(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=Ir(n);return{prng:r.prng,value:t+r.value*(e-t)}},hs=t=>e=>J(n=>r=>ls(n^r)(-2048144789))(e)(W(Dn)(Zn(t))),ps=t=>t,nn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Lo=Lu(ri),J0=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Uc=jt(C)(zt),ms=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},Zc=zt.foldMap(ll(C)),Kc=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},T0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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},Qr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},w0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},v0=jt(C)(zt),b0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},k0=jt(C)(zt),L0=ps("Backdrop"),jc=ps("FlyThrough"),Eo=ps("Active"),tg=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*no(-(c-a)/s))},E0=t=>e=>n=>r=>{const i=Ye(t),o=i.w/nn(1e-4)(e.zoom)/2,u=i.h/nn(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}}},ys=t=>e=>n=>{const r=Vt(i=>Lo(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=>Lo(i.path)(e))(t.segments);g()},C0=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:Vu,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:Q}),S0=t=>W(e=>e<1?[]:bt(0,e,t))(It(0,t.length-1|0)),G0=t=>J(e=>n=>(e*31|0)+Dn(n)|0)(7)(Zn(t)),eg=t=>e=>n=>({...n,state:{...n.state,nodes:Uc(W(r=>b(r._1,t(r._1)(r._2)))(J0(n.state.nodes))),edges:(()=>{const r=i=>{if(i.tag==="Leaf")return Q;if(i.tag==="Node")return Wt("Node",i._1,i._2,i._3,e(i._4),r(i._5),r(i._6));g()};return r(n.state.edges)})()}}),xs=t=>e=>{const n=ms(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.nodes;g()},Ns=t=>e=>{const n=ms(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.edges;g()},Co=t=>e=>{if(e<t.startT)return xr("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 xr("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return xr("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return xr("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return xr("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;return r>=0&&r<t.spans.length?xr("AtKeyframe",(()=>{if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="Hold")return t.spans[r].scene._1;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return t.initialKeyframe;g()})()):xr("AtKeyframe",t.initialKeyframe)}g()},P0=J(t=>e=>{const n=ii(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?Ot(n._1.init)({...n._1.last,endT:nn(n._1.last.endT)(e.endT),windows:Ot(n._1.last.windows)(e)}):Ot(t)({endT:e.endT,windows:[e]})})([]),D0=t=>e=>n=>Zc(r=>Zc(i=>i.target.tag==="FillWindow"?i.startT<=n?Wt("Node",1,1,i.target._2,void 0,Q,Q):Q:i.target.tag==="TokenWindow"&&i.startT+(i.endT-i.startT)*.25<=n?Wt("Node",1,1,i.target._4,void 0,Q,Q):Q)(r.windows))(st(r=>n<=r.endT+t,P0(Lt(r=>i=>ut.compare(r.startT)(i.startT))(st(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),I0=t=>e=>n=>Re(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),Q0=t=>e=>n=>Re(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),F0=t=>e=>n=>Re(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),A0=t=>e=>n=>Re(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),M0=t=>e=>{const n=Co(t)(e);if(n.tag==="AtKeyframe")return me(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return me(3)(n._2)==="kf-"?"":n._2;g()},O0=t=>e=>{const n=Co(t)(e),r=ms((()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;g()})())(t.keyframes);if(r.tag==="Just")return r._1.kind;if(r.tag==="Nothing")return yi;g()},ng=t=>e=>n=>Vt(r=>n(r)&&e>=r.startT&&e<r.endT)(t),R0=t=>{const e=Kc(0)(1)(t/.2),n=Kc(0)(1)((1-t)/.2);return e*e*(3-2*e)*n*n*(3-2*n)},B0=t=>e=>{if(e.tag==="Travelling"){const n=T0(e._1.edge)(t.edges);if(n.tag==="Just"){const r=mr(n._1)(e._1.progress);return r.tag==="Just"?v("Just",{dot:r._1,weight:R0(e._1.progress)}):T}if(n.tag==="Nothing")return T;g()}return T},z0={segment:{startT:0,endT:0,path:[],layout:{nodes:Q,edges:Q,chipExtras:Q,edgeLabels:Q},placement:Vu,windows:[],spans:[],keyframes:Q,initialKeyframe:"",edgeEndpoints:Q},state:{nodes:Q,edges:Q,tokens:Q,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:yi,visited:Q,nodeFadeAlpha:Q,nodeInvert:Q},bgAlpha:1,role:Eo},So=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:z0},W0=t=>e=>{const n=Co(t)(e);if(n.tag==="AtKeyframe")return xs(t)(n._1);if(n.tag==="InTransition")return Ee(C.compare,ke,xs(t)(n._1),xs(t)(n._2));g()},q0=t=>e=>{const n=Co(t)(e);if(n.tag==="AtKeyframe")return Ns(t)(n._1);if(n.tag==="InTransition")return Ee(C.compare,ke,Ns(t)(n._1),Ns(t)(n._2));g()},H0=t=>e=>{const n=t.w/nn(1e-4)(e.zoom),r=t.h/nn(1e-4)(e.zoom);return{...e,center:{x:n>=t.w?t.x+t.w/2:tg(t.x+n/2)(t.x+t.w-n/2)(e.center.x),y:r>=t.h?t.y+t.h/2:tg(t.y+r/2)(t.y+t.h-r/2)(e.center.y)}}},$0=t=>H0((()=>{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}})()),X0=t=>e=>{const n=t.endT-t.startT;return n<=0?1:nn(0)(Qr(1)((e-t.startT)/n))},rg=t=>e=>n=>nn(0)(Qr(1)((n-ae(0)(.3)(t+G0(e)|0).value)/nn(1e-4)(.7))),ig=t=>e=>n=>eg(r=>i=>i.tag==="Hidden"?wo:Sr("PloppingOut",r===e?nn(0)(Qr(1)((n-.45)/nn(1e-4)(.55))):rg(t)(r)(n)))(r=>r.tag==="Retracted"?vo:Cr("Retracting",Oc,n)),og=t=>e=>eg(n=>r=>r.tag==="Hidden"?wo:Sr("PloppingIn",rg(t)(n)(e)))(n=>n.tag==="Retracted"?vo:Cr("Extending",as,e)),Go=t=>e=>{const n=t.endT-t.startT;return n<=0?1:nn(0)(Qr(1)((e-t.startT)/n))},Y0=t=>e=>n=>r=>i=>{const o=ng(e)(n)(u=>u.target.tag==="EdgeWindow"&&u.target._1===i);if(o.tag==="Just"){const u=es(t.timing.edgeEasing)(Go(o._1)(n)),s=o._1.target.tag==="EdgeWindow"?o._1.target._2:cs("Extend",as);if(s.tag==="Retract")return Cr("Retracting",s._1,u);if(s.tag==="Extend")return Cr("Extending",s._1,u);g()}if(o.tag==="Nothing")return A0(e)(n)(i)||I0(e)(n)(i)?vo:w0(i)(r)?Fh:vo;g()},V0=t=>e=>n=>{const r=q0(e)(n);return v0(W(i=>b(i,Y0(t)(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Wt("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return Ct(We.foldr,i(e.layout.edges))})()))},U0=t=>e=>n=>r=>{const i=ng(t)(e)(o=>o.target.tag==="NodeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=Go(i._1)(e),u=i._1.target.tag==="NodeWindow"?i._1.target._2:Hc;if(u==="PlopIn")return Sr("PloppingIn",o);if(u==="PlopOut")return Sr("PloppingOut",o);g()}if(i.tag==="Nothing")return F0(t)(e)(r)||Q0(t)(e)(r)?wo:b0(r)(n)?Qh:wo;g()},Z0=t=>e=>n=>{const r=W0(e)(n);return Uc(W(i=>b(i,U0(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Wt("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return Ct(We.foldr,i(e.layout.nodes))})()))},K0=t=>e=>n=>e.target.tag==="TokenWindow"?b(e.target._1,n<e.startT?ss:n>=e.endT?Ac:To("Travelling",{edge:e.target._2,direction:e.target._3,progress:es(t.timing.tokenEasing)(Go(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?ss:n>=e.endT?Ac:To("Filling",{node:e.target._2,progress:Go(e)(n),labels:e.target._3})):b("",ss),j0=t=>e=>n=>k0(W(r=>K0(t)(r)(n))(st(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),Fr=t=>e=>n=>({nodes:Z0()(e)(n),edges:V0(t)(e)(n),tokens:j0(t)(e.windows)(n),camera:Dc(t.cameraConfig)(e.layout)(t.cameraSpans)(n),frameTitle:M0(e)(n),staticKind:O0(e)(n),visited:D0(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:Q,nodeInvert:Q}),tp=t=>e=>n=>Ya(T,za,r=>r.direction==="DiveIn"&&Lo(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),ep=t=>e=>n=>r=>{const i=tp(t)(e)(n);if(i.tag==="Just"){const o=He(3.141592653589793*i._1.phase*3);return{...r,state:{...r.state,nodeInvert:Wt("Node",1,1,i._1.node,1*o*o,Q,Q)}}}if(i.tag==="Nothing")return r;g()},ug=t=>e=>xt(n=>{const r=Vt(i=>i.direction==="DiveIn"&&Lo(i.childPath)((()=>{const o=n.length+1|0;return o<1?[]:bt(0,o,e)})()))(t.dives);if(r.tag==="Just"){const i=ys(t)(n)(r._1.startT-1e-4);if(i.tag==="Just")return v("Just",{bgAlpha:1,role:L0,segment:i._1,state:{...Fr(t)(i._1)(r._1.startT-1e-4),nodeFadeAlpha:Wt("Node",1,1,r._1.node,0,Q,Q)}});if(i.tag==="Nothing")return T;g()}if(r.tag==="Nothing")return T;g()})(S0(e)),sg=t=>e=>{const n=st(i=>e>=i.startT&&e<i.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:C0(t)},np=t=>e=>n=>{const r=X0(n)(e),i=ys(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),o=ys(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),u=nn(0)(Qr(1)(r/.6)),s=nn(0)(Qr(1)((r-.4)/.6)),a=(()=>{if(n.direction==="DiveIn")return ig(t.seed)(n.node)(u);if(n.direction==="DiveOut")return og(t.seed)(s);g()})(),c=(()=>{if(n.direction==="DiveIn")return og(t.seed)(s);if(n.direction==="DiveOut")return ig(t.seed)(n.node)(u);g()})();return[...ug(t)(n.parentPath),...(()=>{if(i.tag==="Just"){if(o.tag==="Just")return[a({segment:i._1,state:Fr(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:jc}),c({segment:o._1,state:Fr(t)(o._1)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),bgAlpha:1,role:Eo})];if(o.tag==="Nothing")return[a({segment:i._1,state:Fr(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:jc})];g()}if(i.tag==="Nothing")return[(()=>{const f=sg(t)(e);return{segment:f,state:Fr(t)(f)(e),bgAlpha:1,role:Eo}})()];g()})()]},rp=t=>e=>{const n=xt(B0(t))((()=>{const r=(i,o)=>{if(i.tag==="Leaf")return o;if(i.tag==="Node")return r(i._5,qt("Cons",i._4,r(i._6,o)));g()};return Ct($t.foldr,r(e.tokens,Ht))})());return 0<n.length?v("Just",n[0]):T},ip=t=>e=>{const n=rp(t)(e);if(n.tag==="Nothing")return e.camera;if(n.tag==="Just")return E0(t)(e.camera)(n._1.dot)(n._1.weight);g()},op=t=>e=>t.placement.scale===1&&t.placement.tx===0&&t.placement.ty===0?ip(t.layout)(e):e.camera,up=t=>e=>Vt(n=>e>=n.startT&&e<n.endT)(t.dives),sp=t=>e=>{const n=sg(t)(e),r=Fr(t)(n)(e),i=t.dives.length!==0,o=Dc(t.cameraConfig)(t.layout)(t.cameraSpans)(e),u=$0(n)(op(n)({...r,camera:o})),s=ep(t)(n)(e)({bgAlpha:1,role:Eo,segment:n,state:{...r,camera:u}}),a=ug(t)(n.path),c=up(t)(e);if(c.tag==="Just")return{levels:np(t)(e)(c._1),camera:o,rootLayout:t.layout,hasDives:i,diving:!0};if(c.tag==="Nothing")return{levels:Ot(a)(s),camera:u,rootLayout:t.layout,hasDives:i,diving:!1};g()},ag=t=>t,cg=ag("RunText"),ap=ag("RunCode"),gg=t=>e=>n=>e.length===0?n:Ot(n)({style:t,text:lr(e)}),cp=t=>({style:(()=>{if(t.style==="RunText")return ap;if(t.style==="RunCode")return cg;g()})(),buf:[],runs:gg(t.style)(t.buf)(t.runs)}),gp=t=>e=>0<e.length?{...t,buf:Ot(t.buf)(e[0])}:{...t,buf:Ot(t.buf)("\\")},fp=t=>e=>{let n=t,r=e,i=!0,o;for(;i;){const u=n,s=Mt(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=gp(u)(s._1.tail),r=bt(1,s._1.tail.length,s._1.tail);continue}if(s._1.head==="`"){n=cp(u),r=s._1.tail;continue}n={...u,buf:Ot(u.buf)(s._1.head)},r=s._1.tail;continue}g()}return o},fg=t=>{const e=fp({style:cg,buf:[],runs:[]})(Zn(t));return gg(e.style)(e.buf)(e.runs)};let Js=null;function _p(){return Js||(typeof document>"u"?null:(Js=document.createElement("canvas").getContext("2d"),Js))}const _g=new Map,dp=t=>e=>n=>r=>()=>{const i=`${n} ${e}px ${t}|${r}`,o=_g.get(i);if(o!==void 0)return o;const u=_p();if(!u)return r.length*e*.62;u.font=`${n} ${e}px ${t}`;const s=u.measureText(r).width;return _g.set(i,s),s},lp=ar.traverse(vu),hp=J(Lr)(0),Ar=(()=>{const t=tr(`\r
|
|
3
3
|
`)(" "),e=tr(`
|
|
4
|
-
`)(" "),n=(()=>{const r=tr("\r")(" "),i=(()=>{const o=tr(" ")(" ");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),
|
|
5
|
-
`)(o._1))(Ts(i)),s=J(c=>f=>Mr(c)(Kn(f)))(0)(u),a=o._2.shape==="Cylinder"?Mr(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(Mr(1)(En(u.length+t.cellH|0,t.cellH))+(o._2.shape==="Cylinder"||o._2.shape==="Document"?1:0)|0))}})(n)}},wp=t=>e=>n=>({...n,nodes:W(r=>{const i=xp(r.id)(e);if(i.tag==="Nothing")return r;if(i.tag==="Just")return{...r,size:b(yp(r.size._1)(rt(Mr(1)(de(eo(r.shape==="Cylinder"?(i._1+0)/t:(i._1+32)/t))))),r.size._2)};g()})(n.nodes)}),vp=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bp=t=>{const e=t.length;return(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(a>=e){u=!1,s=c;continue}const f=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const 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,L=t[y].position,k=t[y].size;return N._1<L._1+k._1&&L._1<N._1+w._1&&N._2<L._2+k._2&&L._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)},hg=t=>J(e=>n=>e+Ll(n.start)(n.end))(0)(t.segments),kp=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+hg(i))(0)(e),maxEdgeLength:J(r=>i=>vp(r)(hg(i)))(0)(e),nodeOverlapCount:bp(t),constraintViolations:n,jumpCount:J(r=>i=>r+i.jumps.length|0)(0)(e)}),ws=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},vs=ws("LEFT"),Lp=ws("RIGHT"),pg=ws("UNDEFINED"),Ep={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},Cp={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?Ge:Ne;if(e==="LEFT")return Je;if(t==="RIGHT")return e==="RIGHT"?Ge:Ne;if(e==="RIGHT")return Je;if(t==="UP")return e==="UP"?Ge:Ne;if(e==="UP")return Je;if(t==="DOWN")return e==="DOWN"?Ge:Ne;if(e==="DOWN")return Je;if(t==="UNDEFINED"&&e==="UNDEFINED")return Ge;g()},Eq0:()=>Ep},Sp=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){if(t==="LEFT"){if(o._3==="LEFT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="LEFT"){n=o._6;continue}if(t==="RIGHT"){if(o._3==="RIGHT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="RIGHT"){n=o._6;continue}if(t==="UP"){if(o._3==="UP"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="UP"){n=o._6;continue}if(t==="DOWN"){if(o._3==="DOWN"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="DOWN"){n=o._6;continue}if(t==="UNDEFINED"&&o._3==="UNDEFINED"){r=!1,i=!0;continue}}g()}return i},Gp={x:0,y:0},Ve=t=>e=>n=>{const r=Ut(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:j(it)(t)(e(r._1))(n.cNodes)};g()},Ei=t=>e=>n=>{const r=Ut(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:j(it)(t)(e(r._1))(n.cGroups)};g()},Pp=t=>J(e=>n=>Ve(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),Ip=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)(ee)(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)},Dp=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}})),Qp=t=>{const e=J(n=>r=>Ei(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},Fp={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},bs=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=Ei(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=>bs({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return Q;if(n.tag==="Node")return Wt("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=>bs({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return Q;if(n.tag==="Node")return Wt("Node",n._1,n._2,n._3,{...n._4,hitbox:{x:n._4.hitbox.y,y:n._4.hitbox.x,width:n._4.hitbox.height,height:n._4.hitbox.width},cGroupOffset:{x:n._4.cGroupOffset.y,y:n._4.cGroupOffset.x}},e(n._5),e(n._6));g()};return e(t.cNodes)})()}),mg=t=>{const e=J(n=>r=>Ei(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?Ei(a._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(Ei(o)(c=>Be(vr)(s)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,s]})(u)):u;g()})(n)(i._1.constraints)}}g()})(e)(e.cNodeOrder)},Po=t=>{const e=Ip(t.cGraph);return{...t,cGraph:mg(J(n=>r=>Ve(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},Ap=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:Ap(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node")return Wt("Node",r._1,r._2,r._3,{...r._4,constraints:[]},n(r._5),n(r._6));g()};return n(t.cGraph.cNodes)})()})};return{...e,cGraph:mg((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);g()})())}},Mp=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?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"?Po({...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"?Po({...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"?Po({...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"?Po({...r,cGraph:Ue(r.cGraph)}):r;g()},yg=t=>e=>e.finished||!Sp(t)(e.cGraph.supportedDirections)||(t==="LEFT"?e.direction==="LEFT":t==="RIGHT"?e.direction==="RIGHT":t==="UP"?e.direction==="UP":t==="DOWN"?e.direction==="DOWN":t==="UNDEFINED"&&e.direction==="UNDEFINED")?e:Mp(e.direction)(t)(e),Op=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?yg(vs)(t):t,n={...e,cGraph:Qp(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},xg=t=>e=>n=>{const r=Ut(t)(n.cNodes),i=Ut(e)(n.cGroups);return r.tag==="Just"&&i.tag==="Just"?(()=>{if(r._1.cGroup.tag==="Nothing")return!1;if(r._1.cGroup.tag==="Just")return!0;g()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:j(it)(t)({...r._1,cGroup:v("Just",e)})(n.cNodes),cGroups:j(it)(e)({...i._1,cNodes:Be(vr)(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},Ng=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:j(it)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:T,cGroupOffset:Gp,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:an})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),ks=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:J(r=>i=>xg(i)(n)(r))({...e,cGroups:j(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)}},Rp=t=>J(e=>n=>{const r=Ut(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?ks({master:T,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),Bp=t=>({cGraph:Pp(Rp(bs(t))),direction:pg,compactionAlgorithm:T,constraintAlgorithm:T,spacingsHandler:Fp,lockFun:T,finished:!1}),zp=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Wp=t=>e=>{const n=ut.compare(t._1)(e._1);return n==="LT"?Ne:n==="GT"?Je:it.compare(t._2)(e._2)},qp=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Jg=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},Tg=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",wg=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),Io=t=>e=>Wp(b(t.hitbox.x+t.hitbox.width/2,t.id))(b(e.hitbox.x+e.hitbox.width/2,e.id)),Hp=t=>e=>{const n=cr(Xt,T,r=>Io(t)(r)==="LT",e);if(n.tag==="Just"){const r=Va(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 Ot(e)(t);g()},vg=t=>e=>{const n=st(i=>Io(i)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?v("Just",n[r]):T},$p=t=>e=>{const n=Hp(e)(t.intervals),r=Vt(o=>Io(e)(o)==="LT")(n),i=j(it)(e.id)((()=>{const o=vg(e)(n);return o.tag==="Just"?v("Just",o._1.id):T})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return j(it)(r._1.id)(v("Just",e.id))(i);if(r.tag==="Nothing")return i;g()})()}},Xp=t=>e=>{const n=ut.compare(t.low?t.node.hitbox.y:t.node.hitbox.y+t.node.hitbox.height)(e.low?e.node.hitbox.y:e.node.hitbox.y+e.node.hitbox.height);return n==="EQ"?t.low?t.low&&!e.low?Je:Ge:e.low?Ne:Ge:n},Yp=t=>J(e=>n=>Ve(n.id)(r=>({...r,constraints:[]}))(e))(t)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),Ls=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)(qp(t)),bg=t=>e=>e.kind.tag!=="Nothing"&&e.kind.tag==="Just"&&e.kind._1==="vs"?e.ignoreSpacing.up?e.ignoreSpacing.down?e:{...e,hitbox:{...e.hitbox,height:e.hitbox.height+t+.01}}:{...e,hitbox:{...e.hitbox,y:e.hitbox.y-t-.01,height:e.hitbox.height+t+.01}}:{...e,hitbox:{...e.hitbox,y:e.hitbox.y-t,height:e.hitbox.height+2*t}},kg=t=>e=>n=>J(r=>i=>n(i)?Ve(i.id)(bg(t))(r):r)(e)(xt(r=>Ut(r)(e.cNodes))(e.cNodeOrder)),Vp=t=>e=>{const n=(r,i,o)=>{const u=Ve(o)(bg(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))},Up=t=>e=>{const n=vg(e)(t.intervals),r=Vt(o=>Io(e)(o)==="LT")(t.intervals),i=n.tag==="Just"&&(()=>{const o=Jg(e.id)(t.cand);return(o.tag==="Nothing"?!1:o.tag==="Just"&&(o._1.tag==="Nothing"?!1:o._1.tag==="Just"&&o._1._1===n._1.id))&&n._1.cGroup.tag==="Just"&&e.cGroup.tag==="Just"&&n._1.cGroup._1!==e.cGroup._1})()?vt(it)(ee)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const o=Jg(r._1.id)(t.cand);return(o.tag==="Nothing"?!1:o.tag==="Just"&&(o._1.tag==="Nothing"?!1:o._1.tag==="Just"&&o._1._1===e.id))&&e.cGroup.tag==="Just"&&r._1.cGroup.tag==="Just"&&e.cGroup._1!==r._1.cGroup._1})()?vt(it)(ee)(e.id)([r._1.id])(i):i,intervals:st(o=>o.id!==e.id,t.intervals)}},Zp=t=>e=>e.low?$p(t)(e.node):Up(t)(e.node),Es=t=>e=>J(Zp)({intervals:[],cand:Q,constraints:Q})(Lt(Xp)(Tt(st(t,xt(n=>Ut(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,Kp=t=>e=>{const n=zp(0)(t/2-.5),r=Ls(Es(Tg)(kg(n)(e)(Tg)))(e),i=Ls(Es(wg)(kg(n)(r)(wg)))(r);return Ls(Es(o=>!0)(Vp(n)(i)))(i)},jp=t=>e=>Kp(t)(Yp(e.cGraph)),Do=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Lg=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Cs=t=>e=>n=>r=>i=>({id:t,representedEdges:[i],affectedBends:[e,n],hitbox:{x:Do(e._1)(n._1),y:Do(e._2)(n._2),width:Yn(e._1-n._1),height:Yn(e._2-n._2)},ignoreSpacing:an,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:T}),tm=t=>e=>{const n=Do(t.hitbox.x)(e.hitbox.x),r=Do(t.hitbox.y)(e.hitbox.y);return{...t,representedEdges:[...t.representedEdges,...e.representedEdges],affectedBends:[...t.affectedBends,...e.affectedBends],potentialGroupParents:[...t.potentialGroupParents,...e.potentialGroupParents],hitbox:{x:n,y:r,width:Lg(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Lg(t.hitbox.y+t.hitbox.height)(e.hitbox.y+e.hitbox.height)-r},ignoreSpacing:{left:t.ignoreSpacing.left||e.ignoreSpacing.left,right:t.ignoreSpacing.right||e.ignoreSpacing.right,up:t.ignoreSpacing.up||e.ignoreSpacing.up,down:t.ignoreSpacing.down||e.ignoreSpacing.down},aPort:(()=>{if(t.aPort.tag==="Just")return t.aPort;if(t.aPort.tag==="Nothing")return e.aPort;g()})()}},em=t=>e=>Yn(t.hitbox.x-e.hitbox.x)<=1e-4&&e.hitbox.y-(t.hitbox.y+t.hitbox.height)<=1e-4&&t.hitbox.y-(e.hitbox.y+e.hitbox.height)<=1e-4,nm=t=>e=>Yn(t.hitbox.x-e.hitbox.x)<=1e-4?ut.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?Ne:Je,Eg=(t,e)=>({tag:t,_1:e}),Ss=jt(C)(zt),Qo=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},Cg=(()=>{const t={eq:n=>r=>n._1===r._1&&(n._2.tag==="Nothing"?r._2.tag==="Nothing":n._2.tag==="Just"&&r._2.tag==="Just"&&n._2._1===r._2._1)},e={compare:n=>r=>{const i=C.compare(n._1)(r._1);if(i==="LT")return Ne;if(i==="GT")return Je;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?Ge:Ne;if(r._2.tag==="Nothing")return Je;if(n._2.tag==="Just"&&r._2.tag==="Just")return C.compare(n._2._1)(r._2._1);g()},Eq0:()=>t};return J(n=>r=>j(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},rm=J(t=>e=>j(Cp)(e)()(t))(Q),Gs=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=mc.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=v("Just",o._4);continue}}g()}return i},im=t=>e=>{const n=Ss(W(o=>b(o.id,o))(t)),r=xt(o=>Qo(o)(n))(e),i=it.compare((()=>{const o=Cg(W(u=>b(u.from.node,u.from.port))(r));if(o.tag==="Leaf")return 0;if(o.tag==="Node")return o._2;g()})())((()=>{const o=Cg(W(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()},om=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),Fo=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()},um=t=>e=>n=>{const r=Ng({origin:v("Just",Eg("SegmentOrigin",n)),kind:v("Just","vs"),hitbox:n.hitbox})(e.cGraph),i=Dp(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const o=Ut(n.potentialGroupParents[0])(i.cNodes);if(o.tag==="Just"){if(o._1.cGroup.tag==="Just")return xg(r.id)(o._1.cGroup._1)(i);if(o._1.cGroup.tag==="Nothing")return i;g()}if(o.tag==="Nothing")return i;g()}return ks({master:v("Just",r.id),nodes:[r.id]})(i).graph})(),edgeToCs:J(o=>u=>vt(C)(ee)(u)([r.id])(o))(e.edgeToCs)(n.representedEdges),lockMap:j(it)(r.id)(im(t)(n.representedEdges))(e.lockMap)}},sm=t=>e=>n=>{const r=Mt(i=>T,i=>o=>v("Just",{head:i,tail:o}),Lt(nm)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const i=J(o=>u=>em(o.survivor)(u)?{...o,survivor:tm(o.survivor)(u)}:{survivor:u,merged:[...o.merged,o.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return J(um(t))(n)([...i.merged,i.survivor])}g()},am=t=>({cGraph:{cNodes:Q,cNodeOrder:[],cGroups:Q,cGroupOrder:[],supportedDirections:rm([pg,vs,Lp]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:Q,edgeToCs:Q,lockMap:Q}),cm=t=>{const e=rt(4);return{x:t.position._1*e,y:t.position._2*e,width:t.size._1*e,height:t.size._2*e}},gm=t=>e=>n=>J(r=>i=>{const o=Ng({origin:v("Just",Eg("NodeOrigin",i.node)),kind:T,hitbox:cm(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:ks({master:v("Just",o.id),nodes:[o.id]})(o.graph).graph,nodeToC:j(C)(i.node)(o.id)(r.nodeToC),lockMap:j(it)(o.id)((()=>{const a=s._1-s._2|0;return a<0?{...an,left:!0}:a>0?{...an,right:!0}:an})())(r.lockMap)}})(n)(e),fm=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),_m=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?j(C)(n.origin._1._1)(n.hitbox.x)(e):e)(Q)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),dm=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?j(C)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(Q)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),lm=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=>j(mc)(o)(r)(i))(e)(n.origin._1._1.affectedBends)}return e})(Q)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),Sg=t=>{const e=Ss(W(n=>b(n.id,n))(t.edges));return xt(n=>{const r=Qo(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:Fo(Gn)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:Fo(Pn)(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:Fo(Gn)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:Fo(Pn)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return T;g()})(t.paths)},hm=t=>e=>{const n=Tt(e)(r=>{if(r.src===r.tgt)return[];if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return[];const i=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 _=Qo(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 Re(u=>Be(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}},pm=t=>e=>{const n=rt(4),r=_m(t),i=dm(t),o=Ss(W(s=>b(s.id,b(s.from.node,s.to.node)))(e.edges)),u=lm(t);return{nodes:W(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:W(s=>{const a=Qo(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 Ft((()=>{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=Gs(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=Gs(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=Gs(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:we(f=>d=>f.end,c,bt(1,c.length,c))}})(e.paths)}},mm=t=>e=>n=>r=>i=>o=>{const u=Cs(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})()]}},Gg=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...Cs(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}}]}),Ao=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...Cs(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}}]}),ym=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=om(n.path),a=J(mm(n)(o)(u)(s.length-1|0))(e)(Ft(f=>d=>b(f,d))(s));if(0<s.length){const f=(()=>{if(r.tag==="Just"&&o.tag==="Just"){if(n.srcSide==="North")return Gg(n)(r._1)(o._1)(s[0])({side:le,down:!0})(a);if(n.srcSide==="South")return Gg(n)(r._1)(o._1)(s[0])({side:he,down:!1})(a)}return a})(),d=s.length-1|0;if(d>=0&&d<s.length&&i.tag==="Just"&&u.tag==="Just"){if(n.tgtSide==="North")return Ao(n)(i._1)(u._1)(s[d])({side:le,down:!0})(f);if(n.tgtSide==="South")return Ao(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 Ao(n)(i._1)(u._1)(s[c])({side:le,down:!0})(a);if(n.tgtSide==="South")return Ao(n)(i._1)(u._1)(s[c])({side:he,down:!1})(a)}return a},xm=t=>e=>n=>sm(t)(J(ym(n))({nextId:0,segments:[]})(e).segments)(n),Nm=t=>xm(t.edges)(Sg(t))(gm(fm(t.edges))(t.nodes)(am())),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=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},Ps=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Is=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=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},Jm=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Tm=t=>{const e=t.Eq0();return n=>r=>{const i=s=>{let a=s,c=!0,f;for(;c;){const d=a,l=Mt(_=>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=>!Qn(p.eid)(d.removedEdges)&&(e.eq(p.src)(_)||e.eq(p.tgt)(_)))(r);if(h.tag==="Nothing"){a={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const p=e.eq(h._1.src)(_)?h._1.tgt:h._1.src,m={...d,degree:j(t)(p)((()=>{const y=(x=>{let N=x,w=!0,L;for(;w;){const k=N;if(k.tag==="Leaf"){w=!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"){w=!1,L=v("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:j(t)(_)()(d.removedNodes),removedEdges:j(it)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:_,neighbour:p,viaSrc:e.eq(h._1.src)(_)}],queue:l._1.tail};if((()=>{const y=(N=>{let w=N,L=!0,k;for(;L;){const E=w;if(E.tag==="Leaf"){L=!1,k=T;continue}if(E.tag==="Node"){const O=t.compare(p)(E._3);if(O==="LT"){w=E._5;continue}if(O==="GT"){w=E._6;continue}if(O==="EQ"){L=!1,k=v("Just",E._4);continue}}g()}return k})(m.degree),x=N=>{let w=N,L=!0,k;for(;L;){const E=w;if(E.tag==="Leaf"){L=!1,k=!1;continue}if(E.tag==="Node"){const O=t.compare(p)(E._3);if(O==="LT"){w=E._5;continue}if(O==="GT"){w=E._6;continue}if(O==="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(m.removedNodes)})()){a={...m,queue:[...m.queue,p]};continue}a=m;continue}}g()}return f},o=J(s=>a=>vt(t)(ue)(a.src)(1)(vt(t)(ue)(a.tgt)(1)(s)))(Q)(r),u=i({degree:o,removedNodes:Q,removedEdges:Q,record:[],queue:st(s=>{const a=(c=>{let f=c,d=!0,l;for(;d;){const _=f;if(_.tag==="Leaf"){d=!1,l=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=>!Qn(s.eid)(u.removedEdges),r),removed:u.record}}},wm=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 j(t)(i.node)(i.viaSrc?u-1|0:u+1|0)(r)})(n)(Te(e)),Ds=t=>{const e=t.Eq0();return n=>r=>i=>{const o={...i,treeNode:j(t)(r)()(i.treeNode)};return J(u=>s=>{if(Qn(s.eid)(u.st.edgeVisited))return u;const a={...u.st,edgeVisited:j(it)(s.eid)()(u.st.edgeVisited)},c=e.eq(s.src)((()=>{const f=s.src,d=_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(f)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=s.tgt;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?s.src:(()=>{const f=s.tgt,d=_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(f)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=s.src;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(Qn(s.eid)(a.treeEdge)){if((d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=!1;continue}if(p.tag==="Node"){const m=t.compare(c)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=!0;continue}}g()}return h})(a.treeNode))return{...u,st:a};const f=Ds(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=Ds(t)(n)(c)({...a,treeEdge:j(it)(s.eid)()(a.treeEdge)});return{count:u.count+f.count|0,st:f.st}}return{...u,st:a}})({count:1,st:o})(st(u=>(e.eq(u.src)(r)||e.eq(u.tgt)(r))&&!Qn(u.eid)(o.edgeVisited),n))}},Mo=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 L=t.compare(h)(w._3);if(L==="LT"){y=w._5;continue}if(L==="GT"){y=w._6;continue}if(L==="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},vm=t=>{const e=jt(t)(zt);return n=>({layer:e(W(r=>b(r,0))(n)),treeNode:Q,treeEdge:Q,poID:Q,lowestPoID:Q,cutvalue:Q,postOrder:1,edgeVisited:Q})},bm=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,km=t=>{const e=jt(t)(zt);return n=>r=>{const i=J(o=>u=>Ps(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(W(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))}},Pg=t=>{const e=t.Eq0();return n=>r=>i=>{const o=J(s=>a=>{const c=Pg(t)(n)(e.eq(a.src)(r)?a.tgt:a.src)({...s.st,edgeVisited:j(it)(a.eid)()(s.st.edgeVisited)});return{lowest:Ps(s.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:i})(st(s=>Qn(s.eid)(i.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!Qn(s.eid)(i.edgeVisited),n)),u=Ps(o.lowest)(o.st.postOrder);return{lowest:u,st:{...o.st,poID:j(t)(r)(o.st.postOrder)(o.st.poID),lowestPoID:j(t)(r)(u)(o.st.lowestPoID),postOrder:o.st.postOrder+1|0}}}},Ig=t=>{const e=Pg(t);return n=>r=>i=>0<n.length?e(r)(n[0])({...i,edgeVisited:Q,postOrder:1,poID:Q,lowestPoID:Q}).st:i},Lm=t=>{const e=t.Eq0();return n=>r=>i=>st(o=>Qn(o.eid)(r.treeEdge)&&(e.eq(o.src)(i)||e.eq(o.tgt)(i)),n)},Em=t=>e=>Vt(n=>{const r=Is(n.eid)(e.cutvalue);return Qn(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),Dg=t=>{const e=Ds(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=bm(t)(r)(u.st);if(s.tag==="Nothing")return u.st;if(s.tag==="Just"){const a=s._1.tgt,c=(h=>{let p=h,m=!0,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 Dg(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 L=t.compare(p)(w._3);if(L==="LT"){y=w._5;continue}if(L==="GT"){y=w._6;continue}if(L==="EQ"){x=!1,N=!0;continue}}g()}return N})(u.st.treeNode)?j(t)(p)((()=>{const m=(y=>{let x=y,N=!0,w;for(;N;){const L=x;if(L.tag==="Leaf"){N=!1,w=T;continue}if(L.tag==="Node"){const k=t.compare(p)(L._3);if(k==="LT"){x=L._5;continue}if(k==="GT"){x=L._6;continue}if(k==="EQ"){N=!1,w=v("Just",L._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()}},Cm=t=>e=>n=>r=>J(i=>o=>{if(Mo(t)(r)(o.src)(n)&&!Mo(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,Sm=t=>{const e=t.Eq0();return n=>r=>i=>o=>{const u=o.tgt,s=o.src;return J(a=>c=>{if((()=>{const f=Is(c.eid)(r.cutvalue);if(f.tag==="Just")return!0;if(f.tag==="Nothing")return!1;g()})()){const f=Is(c.eid)(r.cutvalue),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return e.eq(s)(c.src)||e.eq(u)(c.tgt)?a-(d-c.weight):a+(d-c.weight)}return e.eq(i)(s)?e.eq(c.src)(i)?a+c.weight:a-c.weight:e.eq(c.src)(i)?a-c.weight:a+c.weight})(o.weight)(st(a=>a.eid!==o.eid&&(e.eq(a.src)(i)||e.eq(a.tgt)(i)),n))}},Gm=t=>{const e=Sm(t);return n=>r=>i=>{const o=(u,s,a)=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=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 j(t)(u)(st(f=>f.eid!==s.eid,c._1))(a);if(c.tag==="Nothing")return a;g()};return(u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=(m=>{let y=m,x=!0,N;for(;x;){const w=y;if(w.tag==="Leaf"){x=!1,N=T;continue}if(w.tag==="Node"){const L=t.compare(_)(w._3);if(L==="LT"){y=w._5;continue}if(L==="GT"){y=w._6;continue}if(L==="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:j(it)(p[0].eid)(e(n)(l)(_)(p[0]))(l.cutvalue)},c=m;continue}f=!1,d=l}return d})(r)(i)}},Qg=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:c=>f=>c.delta===f.delta&&c.eid===f.eid&&n.eq(c.src)(f.src)&&e.eq(c.tgt)(f.tgt)&&c.weight===f.weight},i={compare:c=>f=>{const d=it.compare(c.delta)(f.delta);if(d==="LT"||d==="GT"||d!=="EQ")return d;const l=it.compare(c.eid)(f.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const _=t.compare(c.src)(f.src);if(_==="LT"||_==="GT"||_!=="EQ")return _;const h=t.compare(c.tgt)(f.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const p=ut.compare(c.weight)(f.weight);return p==="LT"||p==="GT"||p!=="EQ"?p:Ge},Eq0:()=>r},o=J(c=>f=>j(i)(f)()(c))(Q),u=Lm(t),s=jt(t)(zt),a=Gm(t);return c=>f=>d=>{const l={unknown:s(W(_=>b(_,Ct(We.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}}},Pm=t=>{const e=Ig(t),n=Qg(t);return r=>i=>o=>u=>s=>{const a={...s,treeEdge:j(it)(u.eid)()(ui(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=Mo(t)(a)(u.tgt)(o)?_:-_;return n(r)(i)(e(r)(i)({...a,layer:J(p=>m=>Mo(t)(a)(m)(o)?p:j(t)(m)((()=>{const y=(x=>{let N=x,w=!0,L;for(;w;){const k=N;if(k.tag==="Leaf"){w=!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"){w=!1,L=v("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()})())(p))(a.layer)(r)}))}},Im=t=>{const e=Pm(t);return n=>r=>i=>o=>(u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c;if(l===0){f=!1,d=_;continue}const h=Em(i)(_);if(h.tag==="Nothing"){f=!1,d=_;continue}if(h.tag==="Just"){const p=Cm(t)(i)(h._1)(_);if(p.tag==="Nothing"){f=!1,d=_;continue}if(p.tag==="Just"){a=l-1|0,c=e(r)(i)(h._1)(p._1)(_);continue}}g()}return d})(n)(o)},Dm=t=>{const e=Qg(t),n=Ig(t),r=Dg(t);return i=>o=>u=>e(i)(o)(n(i)(o)(r(i)(o)(u)))},Fg=t=>e=>J(n=>r=>vt(t)(ee)(e(r))([r])(n))(Q),Qm=t=>{const e=jt(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,L=p,k=Mt(E=>T,E=>O=>v("Just",{head:E,tail:O}),w);if(k.tag==="Nothing"){m=!1,y=L;continue}if(k.tag==="Just"){const E=k._1.head,O=(G=>{let P=G,V=!0,U;for(;V;){const B=P;if(B.tag==="Leaf"){V=!1,U=T;continue}if(B.tag==="Node"){const R=t.compare(E)(B._3);if(R==="LT"){P=B._5;continue}if(R==="GT"){P=B._6;continue}if(R==="EQ"){V=!1,U=v("Just",B._4);continue}}g()}return U})(L.layer),Y=(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;g()})(),et=J(G=>P=>{const V=P.tgt,U=(R=>{let M=R,S=!0,I;for(;S;){const D=M;if(D.tag==="Leaf"){S=!1,I=T;continue}if(D.tag==="Node"){const A=t.compare(V)(D._3);if(A==="LT"){M=D._5;continue}if(A==="GT"){M=D._6;continue}if(A==="EQ"){S=!1,I=v("Just",D._4);continue}}g()}return I})(G.incident),B=(()=>{if(U.tag==="Nothing")return-1;if(U.tag==="Just")return U._1-1|0;g()})();return{st:{...G.st,layer:j(t)(P.tgt)(Jm((()=>{const R=P.tgt,M=(S=>{let I=S,D=!0,A;for(;D;){const H=I;if(H.tag==="Leaf"){D=!1,A=T;continue}if(H.tag==="Node"){const $=t.compare(R)(H._3);if($==="LT"){I=H._5;continue}if($==="GT"){I=H._6;continue}if($==="EQ"){D=!1,A=v("Just",H._4);continue}}g()}return A})(G.st.layer);if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})())(Y+P.delta|0))(G.st.layer)},incident:j(t)(P.tgt)(B)(G.incident),queue:B===0?[...G.queue,P.tgt]:G.queue}})({st:L,incident:N,queue:k._1.tail})((()=>{const G=(P=>{let V=P,U=!0,B;for(;U;){const R=V;if(R.tag==="Leaf"){U=!1,B=T;continue}if(R.tag==="Node"){const M=t.compare(E)(R._3);if(M==="LT"){V=R._5;continue}if(M==="GT"){V=R._6;continue}if(M==="EQ"){U=!1,B=v("Just",R._4);continue}}g()}return B})(x);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})());l=x,_=et.incident,h=et.queue,p=et.st;continue}g()}return y},u=Fg(t)(a=>a.tgt)(r),s=e(W(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(Fg(t)(a=>a.src)(r))(s)(st(a=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=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)}},Fm=t=>{const e=vm(t),n=Qm(t),r=Dm(t),i=Im(t);return o=>u=>{const s=n(o)(u)(e(o));return u.length===0?s.layer:i(4*o.length|0)(o)(u)(r(o)(u)(s)).layer}},Ag=t=>{const e=km(t),n=Fm(t),r=Tm(t);return i=>o=>{if(i.length===0)return Q;if(i.length<40)return e(i)(n(i)(o));const u=r(i)(o);return e(i)(wm(t)(u.removed)(n(u.coreNodes)(u.coreEdges)))}},Mg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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},Qs=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Am=Ag(it),Ci=t=>e=>({...e,edges:[...e.edges,{src:t.src,tgt:t.tgt,delta:t.delta,weight:t.weight,eid:e.nextEid}],nextEid:e.nextEid+1|0}),Mm=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=rt((()=>{const i=Mg(n.cGroup._1)(t);if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})());return Ve(n.id)(i=>({...i,hitbox:{...i.hitbox,x:r+i.cGroupOffset.x}}))(e)}g()},Om=t=>e=>({...e,cGraph:J(Mm(t))(e.cGraph)((()=>{const n=e.cGraph;return xt(r=>Ut(r)(n.cNodes))(n.cNodeOrder)})())}),Rm=t=>e=>n=>r=>i=>{const o=de(eo(e.cGroupOffset.x-t.cGroupOffset.x));return Ci({src:i.nextNodeId,tgt:r,delta:Qs(0)(-o),weight:1})(Ci({src:i.nextNodeId,tgt:n,delta:Qs(0)(o),weight:1})({...i,nodes:[...i.nodes,i.nextNodeId],nextNodeId:i.nextNodeId+1|0}))},Bm=t=>e=>n=>r=>i=>o=>u=>{const s=Qs(0)(de(eo(n.cGroupOffset.x+n.hitbox.width+(e.direction==="LEFT"||e.direction==="RIGHT"?e.spacingsHandler.horizontalSpacing(n)(r):e.spacingsHandler.verticalSpacing(n)(r))-r.cGroupOffset.x)));return t.sameEdgeVerticalSegments(n)(r)?Rm(n)(r)(i)(o)(u):Ci({src:i,tgt:o,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(u)},zm=t=>e=>n=>r=>i=>{const o=Ut(i)(e.cGraph.cNodes);if(o.tag==="Nothing")return r;if(o.tag==="Just")return(n.cGroup.tag==="Nothing"?o._1.cGroup.tag==="Nothing":n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"&&n.cGroup._1===o._1.cGroup._1)?r:n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"?Bm(t)(e)(n)(o._1)(n.cGroup._1)(o._1.cGroup._1)(r):r;g()},Wm=t=>e=>n=>r=>J(zm(t)(e)(r))(n)(r.constraints),qm=t=>e=>Ci({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),Hm=t=>{const e=J(i=>o=>vt(it)(ue)(o.tgt)(1)(i))(Q)(t.edges),n=st(i=>{const o=Mg(i)(e);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return o._1===0;g()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return J(i=>o=>Ci({src:r,tgt:o,delta:1,weight:0})(i))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},$m=t=>e=>{const n=Hm(J(qm)(J(Wm(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}},Xm=t=>e=>{const n=$m(t)(e);return Om(Am(n.nodes)(n.edges))(e)},Og=t=>t,ne=Og("H"),re=Og("V"),Ym=t=>b(t._2,t._1),Rg=t=>({...t,position:b(t.position._2,t.position._1),size:b(t.size._2,t.size._1)}),Vm=t=>({start:b(t.start._2,t.start._1),end:b(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return re;if(t.direction==="V")return ne;g()})()}),Bg=t=>({...t,segments:W(Vm)(t.segments),bends:W(Ym)(t.bends)}),Um=t=>({nodes:W(Rg)(t.nodes),edges:t.edges,paths:W(Bg)(t.paths),ports:t.ports}),Zm={nodeNode:8,edgeNode:4,edgeEdge:10},Km=t=>e=>({horizontalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r)||n.ignoreSpacing.right||r.ignoreSpacing.left)return 0;const i=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?i?t.edgeEdge:t.edgeNode:i?t.edgeNode:t.nodeNode},verticalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r))return 1;if(n.hitbox.y<=r.hitbox.y?n.ignoreSpacing.down||r.ignoreSpacing.up:n.ignoreSpacing.up||r.ignoreSpacing.down)return 0;const i=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?i?t.edgeEdge:t.edgeNode:i?t.edgeNode:t.nodeNode}}),jm=t=>e=>Xm(e),t2=t=>e=>n=>{const r=Um(n),i=Nm(r),o=hm(i)(Sg(r)),u=pm(yg(vs)(Op({...Bp(i.cGraph),compactionAlgorithm:v("Just",jm()(o)),constraintAlgorithm:v("Just",jp(e.edgeEdge)),spacingsHandler:Km(e)(o)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:W(Rg)(u.nodes),edges:W(Bg)(u.edges)}},zg=t=>t,Or=jt(it)(zt),It=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},Wg=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()},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=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},e2=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?Ne:n==="GT"?Je: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()},n2=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),r2=t=>t,qg=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},i2=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},Oo=zg("Regular"),Ro=zg("Critical"),Hg=t=>e=>{const n=J(u=>s=>j(C)(s.node)(s)(u))(Q)(e),r=1.25*rt(4),i=(u,s,a)=>(c=>f=>d=>{let l=c,_=f,h=d,p=!0,m;for(;p;){const y=l,x=_,N=h;if(N.critical){p=!1,m=N;continue}const w=Mt(k=>T,k=>E=>v("Just",{head:k,tail:E}),y),L=Mt(k=>T,k=>E=>v("Just",{head:k,tail:E}),x);if(w.tag==="Just"&&L.tag==="Just"){const k=w._1.head>L._1.head-u&&w._1.head<L._1.head+u?{...N,critical:!0}:w._1.head>L._1.head-r&&w._1.head<L._1.head+r?{...N,conflicts:N.conflicts+1|0}:N;if(k.critical){p=!1,m=k;continue}if(w._1.head<=L._1.head){l=w._1.tail,_=x,h=k;continue}l=y,_=L._1.tail,h=k;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:Ro}]:[],...f.critical?[{src:s.id,tgt:a.id,weight:1,kind:Ro}]:[]];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:Oo}]:p>m?[{src:a.id,tgt:s.id,weight:p-m|0,kind:Oo}]:p>0?[{src:s.id,tgt:a.id,weight:0,kind:Oo},{src:a.id,tgt:s.id,weight:0,kind:Oo}]:[]};return J(u=>s=>J(a=>c=>j(C)(c._1)(c._2)(a))(u)((()=>{const a=J(G=>P=>{const V=P.edge.from.node+"|"+(()=>{if(P.edge.from.port.tag==="Just")return P.edge.from.port._1;if(P.edge.from.port.tag==="Nothing")return"_auto_"+P.edge.id;g()})(),U=qg(V)(G.entries);if(U.tag==="Nothing")return{...G,entries:j(C)(V)({id:0,members:[P.edge.id],incoming:[P.fromPos._1],outgoing:[P.toPos._1],slot:0,mark:0,splitBy:T,splitPartner:T})(G.entries),order:[...G.order,V]};if(U.tag==="Just")return{...G,entries:j(C)(V)({...U._1,members:[...U._1.members,P.edge.id],incoming:[...gr(B=>B<P.fromPos._1)(U._1.incoming).init,P.fromPos._1,...gr(B=>B<=P.fromPos._1)(U._1.incoming).rest],outgoing:[...gr(B=>B<P.toPos._1)(U._1.outgoing).init,P.toPos._1,...gr(B=>B<=P.toPos._1)(U._1.outgoing).rest]})(G.entries)};g()})({entries:Q,order:[]})(s._2),c=Ft(G=>P=>({...P,id:G}))(xt(G=>qg(G)(a.entries))(a.order));if(c.length===0)return[];const f=J(G=>P=>G.prev.tag==="Just"&&P-G.prev._1<1e-9?G:{prev:v("Just",P),out:[...G.out,P]})({prev:T,out:[]})(Lt(ut.compare)([...Tt(c)(G=>G.incoming),...Tt(c)(G=>G.outgoing)])).out,d=f.length<2?.2*r:.2*J(G=>P=>{if(G.prev.tag==="Nothing")return{prev:v("Just",P),mn:G.mn};if(G.prev.tag==="Just")return{prev:v("Just",P),mn:dt(G.mn)(P-G.prev._1)};g()})({prev:T,mn:1e18})(f).mn,l={segments:c,deps:(()=>{const G=c.length;return Tt(Tt(Dt(0,G-2|0))(P=>Tt(Dt(P+1|0,G-1|0))(V=>[b(P,V)])))(P=>P._1>=0&&P._1<c.length?P._2>=0&&P._2<c.length?o(d,c[P._1],c[P._2]):[]:[])})()},_=st(G=>{if(G.kind==="Critical")return!0;if(G.kind==="Regular")return!1;g()},l.deps),h=(()=>{if(_.length<2)return l;const G=Or((()=>{const R=l.segments;return W(M=>b(M.id,M.mark))((()=>{const M=R.length,S=D=>{let A=D,H=!0,$;for(;H;){const X=A,q=Vt(z=>{const tt=It(z)(X.inWeight);if(tt.tag==="Nothing")return!0;if(tt.tag==="Just")return tt._1===0;g()})(X.remaining);if(q.tag==="Nothing"){H=!1,$=X;continue}if(q.tag==="Just"){const z=q._1;A={...X,inWeight:J(tt=>Z=>vt(it)(ue)(Z.tgt)(-Z.weight)(tt))(X.inWeight)((()=>{const tt=It(z)(X.depsBySrc);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),marks:j(it)(z)(X.nextSource)(X.marks),nextSource:X.nextSource+1|0,outWeight:J(tt=>Z=>vt(it)(ue)(Z.src)(-Z.weight)(tt))(X.outWeight)((()=>{const tt=It(z)(X.depsByTgt);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),remaining:st(tt=>tt!==z,X.remaining)};continue}g()}return $},I=D=>{let A=D,H=!0,$;for(;H;){const X=A,q=Vt(z=>{const tt=It(z)(X.outWeight);if(tt.tag==="Nothing")return!0;if(tt.tag==="Just")return tt._1===0;g()})(X.remaining);if(q.tag==="Nothing"){H=!1,$=X;continue}if(q.tag==="Just"){const z=q._1;A={...X,inWeight:J(tt=>Z=>vt(it)(ue)(Z.tgt)(-Z.weight)(tt))(X.inWeight)((()=>{const tt=It(z)(X.depsBySrc);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),marks:j(it)(z)(X.nextSink)(X.marks),nextSink:X.nextSink-1|0,outWeight:J(tt=>Z=>vt(it)(ue)(Z.src)(-Z.weight)(tt))(X.outWeight)((()=>{const tt=It(z)(X.depsByTgt);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),remaining:st(tt=>tt!==z,X.remaining)};continue}g()}return $};return(D=>{let A=D,H=!0,$;for(;H;){const X=S(I(A));if(X.remaining.length===0){H=!1,$=W(q=>{const z=It(q.id)(X.marks),tt=(()=>{if(z.tag==="Nothing")return q.id;if(z.tag==="Just")return z._1;g()})();return{...q,mark:tt<M?(tt+M|0)+1|0:tt}})(R);continue}A=(()=>{const q=tt=>{const Z=It(tt)(X.outWeight),ct=It(tt)(X.inWeight);return(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()-(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()|0},z=Lt(tt=>Z=>it.compare(q(Z))(q(tt)))(X.remaining);if(0<z.length){const tt=z[0];return{...X,inWeight:J(Z=>ct=>vt(it)(ue)(ct.tgt)(-ct.weight)(Z))(X.inWeight)((()=>{const Z=It(tt)(X.depsBySrc);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;g()})()),marks:j(it)(tt)(X.nextSource)(X.marks),nextSource:X.nextSource+1|0,outWeight:J(Z=>ct=>vt(it)(ue)(ct.src)(-ct.weight)(Z))(X.outWeight)((()=>{const Z=It(tt)(X.depsByTgt);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;g()})()),remaining:st(Z=>Z!==tt,X.remaining)}}return X})()}return $})({remaining:W(D=>D.id)(R),marks:Q,inWeight:J(D=>A=>vt(it)(ue)(A.tgt)(A.weight)(D))(Q)(_),outWeight:J(D=>A=>vt(it)(ue)(A.src)(A.weight)(D))(Q)(_),depsBySrc:J(D=>A=>vt(it)(ee)(A.src)([A])(D))(Q)(_),depsByTgt:J(D=>A=>vt(it)(ee)(A.tgt)([A])(D))(Q)(_),nextSink:M-1|0,nextSource:M+1|0})})())})()),P=st(R=>{const M=It(R.src)(G),S=It(R.tgt)(G);return(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()>(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;g()})()},_);if(P.length===0)return l;const V=J(R=>M=>{if(Be(vr)(M.src)(R.decisions)||Be(vr)(M.tgt)(R.decisions))return R;const S=It(M.src)(R.segMap),I=It(M.tgt)(R.segMap);if(S.tag==="Just"&&I.tag==="Just"){const D=(S._1.incoming.length+S._1.outgoing.length|0)>2&&(I._1.incoming.length+I._1.outgoing.length|0)<=2,A=D?I._1:S._1;return{decisions:[...R.decisions,A.id],segMap:j(it)(A.id)({...A,splitBy:v("Just",D?S._1.id:I._1.id)})(R.segMap)}}return R})({decisions:[],segMap:Or(W(R=>b(R.id,R))(l.segments))})(P),U=V.segMap,B=J(R=>M=>{const S=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(M.outgoing)),I=lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(M.outgoing)),D=st(q=>q.a.startPosition<=I&&q.a.endPosition>=S,Ft(q=>z=>({i:q,a:z}))(R.freeAreas));if(D.length===0){const q={...M,incoming:Lt(ut.compare)(M.incoming),outgoing:Lt(ut.compare)([(S+I)/2]),splitPartner:v("Just",R.nextId)},z={id:R.nextId,incoming:Lt(ut.compare)([(S+I)/2]),mark:0,members:M.members,outgoing:Lt(ut.compare)(M.outgoing),slot:0,splitBy:T,splitPartner:v("Just",M.id)};return{segMap:j(it)(z.id)(z)(j(it)(q.id)(q)(R.segMap)),freeAreas:R.freeAreas,nextId:R.nextId+1|0}}const A=0<D.length?v("Just",D[0]):T,H=(()=>{if(A.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(A.tag==="Just"){if(D.length===1)return A._1;const q=W(z=>({c:z,rating:(()=>{const tt=(z.a.startPosition+z.a.endPosition)/2,Z=[tt],ct=[tt],ft=J((()=>{const yt=R.segMap;return St=>Rt=>{const pt=It(Rt.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)(M.incoming))(J(dt)(1e18)(Z)),gt=(()=>{const Et=lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(Z)),Qt=J(Yt=>_e=>_e>Jt?Yt:_e>=Bt?Yt+1|0:Yt)(0)(Z)+J(Yt=>_e=>_e>Et?Yt:_e>=mt?Yt+1|0:Yt)(0)(pt._1.incoming)|0,je=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(Z)),qe=lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(Z)),tn=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),Hn=lt(J(lt)(-1e18)(pt._1.incoming))(J(lt)(-1e18)(pt._1.outgoing)),dn=J(Yt=>_e=>_e>qe?Yt:_e>=je?Yt+1|0:Yt)(0)(pt._1.outgoing)+J(Yt=>_e=>_e>Hn?Yt:_e>=tn?Yt+1|0:Yt)(0)(M.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}})(),K=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)(ct))(J(dt)(1e18)(M.outgoing)),_t=lt(J(lt)(-1e18)(ct))(J(lt)(-1e18)(M.outgoing)),Nt=J(Et=>Qt=>Qt>nt?Et:Qt>=K?Et+1|0:Et)(0)(M.outgoing)+J(Et=>Qt=>Qt>_t?Et:Qt>=ht?Et+1|0:Et)(0)(pt._1.incoming)|0,wt=dt(J(dt)(1e18)(ct))(J(dt)(1e18)(M.outgoing)),Kt=lt(J(lt)(-1e18)(ct))(J(lt)(-1e18)(M.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)),Me=J(Et=>Qt=>Qt>Kt?Et:Qt>=wt?Et+1|0:Et)(0)(pt._1.outgoing)+J(Et=>Qt=>Qt>sn?Et:Qt>=Se?Et+1|0:Et)(0)(ct)|0;return Nt===Me?Nt>0?{...gt,deps:gt.deps+2|0,crossings:gt.crossings+Nt|0}:gt:{...gt,deps:gt.deps+1|0,crossings:gt.crossings+Br(Nt)(Me)|0}}g()}})())(J((()=>{const yt=R.segMap;return St=>Rt=>{const pt=It(Rt.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)(M.incoming))(J(dt)(1e18)(Z)),gt=(()=>{const Et=lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(Z)),Qt=J(Yt=>_e=>_e>Jt?Yt:_e>=Bt?Yt+1|0:Yt)(0)(Z)+J(Yt=>_e=>_e>Et?Yt:_e>=mt?Yt+1|0:Yt)(0)(pt._1.incoming)|0,je=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(Z)),qe=lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(Z)),tn=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),Hn=lt(J(lt)(-1e18)(pt._1.incoming))(J(lt)(-1e18)(pt._1.outgoing)),dn=J(Yt=>_e=>_e>qe?Yt:_e>=je?Yt+1|0:Yt)(0)(pt._1.outgoing)+J(Yt=>_e=>_e>Hn?Yt:_e>=tn?Yt+1|0:Yt)(0)(M.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}})(),K=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)(ct))(J(dt)(1e18)(M.outgoing)),_t=lt(J(lt)(-1e18)(ct))(J(lt)(-1e18)(M.outgoing)),Nt=J(Et=>Qt=>Qt>nt?Et:Qt>=K?Et+1|0:Et)(0)(M.outgoing)+J(Et=>Qt=>Qt>_t?Et:Qt>=ht?Et+1|0:Et)(0)(pt._1.incoming)|0,wt=dt(J(dt)(1e18)(ct))(J(dt)(1e18)(M.outgoing)),Kt=lt(J(lt)(-1e18)(ct))(J(lt)(-1e18)(M.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)),Me=J(Et=>Qt=>Qt>Kt?Et:Qt>=wt?Et+1|0:Et)(0)(pt._1.outgoing)+J(Et=>Qt=>Qt>sn?Et:Qt>=Se?Et+1|0:Et)(0)(ct)|0;return Nt===Me?Nt>0?{...gt,deps:gt.deps+2|0,crossings:gt.crossings+Nt|0}:gt:{...gt,deps:gt.deps+1|0,crossings:gt.crossings+Br(Nt)(Me)|0}}g()}})())({crossings:0,deps:0})(st(yt=>yt.tgt===M.id,l.deps)))(st(yt=>yt.src===M.id,l.deps)),at=(()=>{if(M.splitBy.tag==="Just")return It(M.splitBy._1)(R.segMap);if(M.splitBy.tag==="Nothing")return T;g()})();if(at.tag==="Just")return{...ft,deps:ft.deps+2|0,crossings:(()=>{const yt=dt(J(dt)(1e18)(at._1.incoming))(J(dt)(1e18)(at._1.outgoing)),St=dt(J(dt)(1e18)(ct))(J(dt)(1e18)(M.outgoing)),Rt=lt(J(lt)(-1e18)(at._1.incoming))(J(lt)(-1e18)(at._1.outgoing)),pt=lt(J(lt)(-1e18)(ct))(J(lt)(-1e18)(M.outgoing)),Bt=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(Z));return ft.crossings+(()=>{const Jt=dt(J(dt)(1e18)(at._1.incoming))(J(dt)(1e18)(at._1.outgoing)),mt=lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(Z)),gt=lt(J(lt)(-1e18)(at._1.incoming))(J(lt)(-1e18)(at._1.outgoing));return((J(K=>nt=>nt>Rt?K:nt>=yt?K+1|0:K)(0)(Z)+J(K=>nt=>nt>mt?K:nt>=Bt?K+1|0:K)(0)(at._1.incoming)|0)+J(K=>nt=>nt>pt?K:nt>=St?K+1|0:K)(0)(at._1.outgoing)|0)+J(K=>nt=>nt>gt?K:nt>=Jt?K+1|0:K)(0)(ct)|0})()|0})()};if(at.tag==="Nothing")return ft;g()})()}))(D);return J(z=>tt=>tt.rating.crossings<z.rating.crossings||!(tt.rating.crossings>z.rating.crossings)&&(tt.rating.deps<z.rating.deps||!(tt.rating.deps>z.rating.deps)&&tt.c.a.size>z.c.a.size)?tt:z)(0<q.length?q[0]:{c:A._1,rating:{crossings:1e6,deps:1e6}})(q).c}g()})(),$={...M,incoming:Lt(ut.compare)(M.incoming),outgoing:Lt(ut.compare)([(H.a.startPosition+H.a.endPosition)/2]),splitPartner:v("Just",R.nextId)},X={id:R.nextId,incoming:Lt(ut.compare)([(H.a.startPosition+H.a.endPosition)/2]),mark:0,members:M.members,outgoing:Lt(ut.compare)(M.outgoing),slot:0,splitBy:T,splitPartner:v("Just",M.id)};return{segMap:j(it)(X.id)(X)(j(it)($.id)($)(R.segMap)),freeAreas:(()=>{if(H.i>=0&&H.i<R.freeAreas.length){const q=Ua(Xt,T,H.i,R.freeAreas),z=(()=>{if(q.tag==="Nothing")return R.freeAreas;if(q.tag==="Just")return q._1;g()})();if(R.freeAreas[H.i].size/2<d)return z;const tt=(R.freeAreas[H.i].startPosition+R.freeAreas[H.i].endPosition)/2,Z=tt-d,ct=tt+d;return[...H.i<1?[]:bt(0,H.i,z),...R.freeAreas[H.i].startPosition<=Z?[{startPosition:R.freeAreas[H.i].startPosition,endPosition:Z,size:Z-R.freeAreas[H.i].startPosition}]:[],...ct<=R.freeAreas[H.i].endPosition?[{startPosition:ct,endPosition:R.freeAreas[H.i].endPosition,size:R.freeAreas[H.i].endPosition-ct}]:[],...H.i<1?z:bt(H.i,z.length,z)]}return R.freeAreas})(),nextId:R.nextId+1|0}})({segMap:U,freeAreas:(()=>{const R=Lt(ut.compare)([...Tt(l.segments)(M=>M.incoming),...Tt(l.segments)(M=>M.outgoing)]);return xt(r2)(we(M=>S=>S-M>=2*d?v("Just",{startPosition:M+d,endPosition:S-d,size:S-M-2*d}):T,R,bt(1,R.length,R)))})(),nextId:l.segments.length})(Lt(R=>M=>ut.compare(lt(J(lt)(-1e18)(R.incoming))(J(lt)(-1e18)(R.outgoing))-dt(J(dt)(1e18)(R.incoming))(J(dt)(1e18)(R.outgoing)))(lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(M.outgoing))-dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(M.outgoing))))(xt(R=>It(R)(U))(V.decisions)));return{segments:(()=>{const R=(M,S)=>{if(M.tag==="Leaf")return S;if(M.tag==="Node")return R(M._5,qt("Cons",M._4,R(M._6,S)));g()};return Ct($t.foldr,R(B.segMap,Ht))})(),deps:(()=>{const R=B.segMap,M=(D,A)=>{if(D.tag==="Leaf")return A;if(D.tag==="Node")return M(D._5,qt("Cons",D._4,M(D._6,A)));g()},S=Ct($t.foldr,M(R,Ht)),I=S.length;return[...Tt(Tt(Dt(0,I-2|0))(D=>Tt(Dt(D+1|0,I-1|0))(A=>[b(D,A)])))(D=>D._1>=0&&D._1<S.length?D._2>=0&&D._2<S.length?S[D._1].splitPartner.tag!=="Nothing"&&S[D._1].splitPartner.tag==="Just"&&S[D._1].splitPartner._1===S[D._2].id||S[D._2].splitPartner.tag!=="Nothing"&&S[D._2].splitPartner.tag==="Just"&&S[D._2].splitPartner._1===S[D._1].id?[]:o(d,S[D._1],S[D._2]):[]:[]),...Tt(S)(D=>D.splitBy.tag==="Just"&&D.splitPartner.tag==="Just"&&(()=>{const A=It(D.splitPartner._1)(R);if(A.tag==="Nothing")return!1;if(A.tag==="Just")return!0;g()})()&&(()=>{const A=It(D.splitBy._1)(R);if(A.tag==="Nothing")return!1;if(A.tag==="Just")return!0;g()})()?[{src:D.id,tgt:D.splitBy._1,weight:1,kind:Ro},{src:D.splitBy._1,tgt:D.splitPartner._1,weight:1,kind:Ro}]:[])]})()}})(),p=h.segments,m=p.length,y=G=>{let P=G,V=!0,U;for(;V;){const B=P,R=Vt(M=>{const S=It(M)(B.inWeight);if(S.tag==="Nothing")return!0;if(S.tag==="Just")return S._1===0;g()})(B.remaining);if(R.tag==="Nothing"){V=!1,U=B;continue}if(R.tag==="Just"){const M=R._1;P={...B,inWeight:J(S=>I=>vt(it)(ue)(I.tgt)(-I.weight)(S))(B.inWeight)((()=>{const S=It(M)(B.depsBySrc);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()),marks:j(it)(M)(B.nextSource)(B.marks),nextSource:B.nextSource+1|0,outWeight:J(S=>I=>vt(it)(ue)(I.src)(-I.weight)(S))(B.outWeight)((()=>{const S=It(M)(B.depsByTgt);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()),remaining:st(S=>S!==M,B.remaining)};continue}g()}return U},x=G=>{let P=G,V=!0,U;for(;V;){const B=P,R=Vt(M=>{const S=It(M)(B.outWeight);if(S.tag==="Nothing")return!0;if(S.tag==="Just")return S._1===0;g()})(B.remaining);if(R.tag==="Nothing"){V=!1,U=B;continue}if(R.tag==="Just"){const M=R._1;P={...B,inWeight:J(S=>I=>vt(it)(ue)(I.tgt)(-I.weight)(S))(B.inWeight)((()=>{const S=It(M)(B.depsBySrc);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()),marks:j(it)(M)(B.nextSink)(B.marks),nextSink:B.nextSink-1|0,outWeight:J(S=>I=>vt(it)(ue)(I.src)(-I.weight)(S))(B.outWeight)((()=>{const S=It(M)(B.depsByTgt);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()),remaining:st(S=>S!==M,B.remaining)};continue}g()}return U},N=(G=>{let P=G,V=!0,U;for(;V;){const B=y(x(P));if(B.remaining.length===0){V=!1,U=W(R=>{const M=It(R.id)(B.marks),S=(()=>{if(M.tag==="Nothing")return R.id;if(M.tag==="Just")return M._1;g()})();return{...R,mark:S<m?(S+m|0)+1|0:S}})(p);continue}P=(()=>{const R=S=>{const I=It(S)(B.outWeight),D=It(S)(B.inWeight);return(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;g()})()-(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;g()})()|0},M=Lt(S=>I=>it.compare(R(I))(R(S)))(B.remaining);if(0<M.length){const S=M[0];return{...B,inWeight:J(I=>D=>vt(it)(ue)(D.tgt)(-D.weight)(I))(B.inWeight)((()=>{const I=It(S)(B.depsBySrc);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})()),marks:j(it)(S)(B.nextSource)(B.marks),nextSource:B.nextSource+1|0,outWeight:J(I=>D=>vt(it)(ue)(D.src)(-D.weight)(I))(B.outWeight)((()=>{const I=It(S)(B.depsByTgt);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})()),remaining:st(I=>I!==S,B.remaining)}}return B})()}return U})({remaining:W(G=>G.id)(p),marks:Q,inWeight:J(G=>P=>vt(it)(ue)(P.tgt)(P.weight)(G))(Q)(h.deps),outWeight:J(G=>P=>vt(it)(ue)(P.src)(P.weight)(G))(Q)(h.deps),depsBySrc:J(G=>P=>vt(it)(ee)(P.src)([P])(G))(Q)(h.deps),depsByTgt:J(G=>P=>vt(it)(ee)(P.tgt)([P])(G))(Q)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),w=(()=>{const G=(()=>{const U=Or(W(B=>b(B.id,B.mark))(N));return{segments:N,deps:xt(B=>(()=>{if(B.kind==="Critical")return!0;if(B.kind==="Regular")return!1;g()})()?v("Just",B):(()=>{const R=It(B.src)(U),M=It(B.tgt)(U);return(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})()>(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()})()?B.weight===0?T:v("Just",{src:B.tgt,tgt:B.src,weight:B.weight,kind:B.kind}):v("Just",B))(h.deps)}})(),P=J(U=>B=>vt(it)(ue)(B.tgt)(1)(U))(Q)(G.deps),V=(U=>{let B=U,R=!0,M;for(;R;){const S=B,I=Mt(D=>T,D=>A=>v("Just",{head:D,tail:A}),S.queue);if(I.tag==="Nothing"){R=!1,M=S;continue}if(I.tag==="Just"){B=J((()=>{const D=It(I._1.head)(S.slots),A=(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;g()})();return H=>$=>{const X=It($)(H.inDegree),q=(()=>{if(X.tag==="Nothing")return-1;if(X.tag==="Just")return X._1-1|0;g()})();return{...H,slots:j(it)($)(Wg((()=>{const z=It($)(H.slots);if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})())(A+1|0))(H.slots),inDegree:j(it)($)(q)(H.inDegree),queue:q===0?[...H.queue,$]:H.queue}}})())({...S,queue:I._1.tail})((()=>{const D=It(I._1.head)(S.adj);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})());continue}g()}return M})({slots:Or(W(U=>b(U.id,0))(G.segments)),inDegree:P,adj:J(U=>B=>vt(it)(ee)(B.src)([B.tgt])(U))(Q)(G.deps),queue:W(U=>U.id)(st(U=>{const B=It(U.id)(P);if(B.tag==="Nothing")return!0;if(B.tag==="Just")return B._1===0;g()},G.segments))});return Lt(U=>B=>it.compare(U.slot)(B.slot))(W(U=>({...U,slot:(()=>{const B=It(U.id)(V.slots);if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})()}))(G.segments))})(),L=1+J(G=>P=>Wg(G)(P.slot))(0)(w)|0,k=Tt(w)(G=>G.members),E=st(G=>Be(fn)(G.edge.id)(k),t),O=J(lt)(-1e18)(W(G=>G.fromPos._2)(E)),Y=J(dt)(1e18)(W(G=>G.toPos._2)(E));if(O>Y){const G=Or(W(P=>b(P.id,P))(w));return Oe(W(P=>W(V=>b(V,{slot:P.slot,slotCount:L,gapTop:Y,gapBottom:O,partner:(()=>{if(P.splitPartner.tag==="Just"){const U=It(P.splitPartner._1)(G);if(U.tag==="Just")return 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=It(P.splitPartner._1)(G);return!(V.tag==="Just"&&(()=>{if(V._1.splitBy.tag==="Nothing")return!1;if(V._1.splitBy.tag==="Just")return!0;g()})())}if(P.splitPartner.tag==="Nothing")return!0;g()},w)))}const et=Or(W(G=>b(G.id,G))(w));return Oe(W(G=>W(P=>b(P,{slot:G.slot,slotCount:L,gapTop:O,gapBottom:Y,partner:(()=>{if(G.splitPartner.tag==="Just"){const V=It(G.splitPartner._1)(et);if(V.tag==="Just")return 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(G.splitPartner.tag==="Nothing")return T;g()})()}))(G.members))(st(G=>{if(G.splitPartner.tag==="Just"){const P=It(G.splitPartner._1)(et);return!(P.tag==="Just"&&(()=>{if(P._1.splitBy.tag==="Nothing")return!1;if(P._1.splitBy.tag==="Just")return!0;g()})())}if(G.splitPartner.tag==="Nothing")return!0;g()},w)))})()))(Q)(n2(J(u=>s=>{const a=Rr(s.edge.from.node)(n);if(a.tag==="Just"){const c=Rr(s.edge.to.node)(n);return c.tag==="Just"&&a._1.layer!==c._1.layer?vt(it)(ee)(Br(a._1.layer)(c._1.layer))([s])(u):u}return u})(Q)((()=>{const u=s=>b((()=>{const a=Rr(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=Rr(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return Lt(s=>a=>e2(u(s))(u(a)))(t)})())))},o2=t=>e=>{const n=Hg(t)(e),r=J(i=>o=>j(C)(o.node)(o)(i))(Q)(e);return J(i=>o=>{const u=Rr(o.edge.from.node)(r);if(u.tag==="Just"){const s=Rr(o.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=i2(o.edge.id)(n);if(a.tag==="Just")return j(it)(Br(u._1.layer)(s._1.layer))(a._1.slotCount)(i)}return i}return i})(Q)(t)},$g=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()},Si=t=>e=>n=>r=>$g(i=>n>=i.x&&n<i.x+i.w&&e>i.y&&t<i.y+i.h)(r),Bo=t=>e=>n=>r=>Si(ce(e)(n))(ge(e)(n))(r)(t),zo=rt(4),u2=ja(t=>{if(t.direction==="H"){const e=ce(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:ge(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=ce(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:ge(t.start._2)(t.end._2)-e}]}g()}),Gi=Ka(t=>{const e=t.start._1-t.end._1;return!((e<0?-e<1e-6:e<1e-6)&&(()=>{const n=t.start._2-t.end._2;return n<0?-n<1e-6:n<1e-6})())}),s2=t=>e=>n=>{const r=Mt(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=ii(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()},Pi=t=>{const e=r=>i=>{const o=Mt(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=Mt(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()},Ii=t=>e=>n=>r=>$g(i=>n>=i.y&&n<i.y+i.h&&e>i.x&&t<i.x+i.w)(r),Di=t=>e=>n=>r=>Ii(ce(e)(n))(ge(e)(n))(r)(t),a2=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")&&!Bo(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:re},...o]):T,_=c._1.start._2===d._1.end._2&&(!a||c._1.direction==="H")&&(!s||d._1.direction==="H")&&!Di(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:ne},...o]):T;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return T;g()}if(c.tag==="Nothing")return T;g()},c2=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=a2(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)},g2=t=>e=>n=>r=>{const i=(l,_,h)=>!Bo(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)=>!Di(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:re},...u]):d._1.start._2===_._1.end._2&&(!c||d._1.direction==="H")&&(!a||_._1.direction==="H")&&f(d._1.start._2,d._1.start._1,_._1.end._1)?v("Just",[...s,{start:d._1.start,end:_._1.end,direction:ne},...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:re},{start:b(d._1.start._1,_._1.end._2),end:_._1.end,direction:ne},...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:ne},{start:b(_._1.end._1,d._1.start._2),end:_._1.end,direction:re},...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()},f2=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=g2(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)},_2=t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r,s=Pi(Gi(c2(t)(f2(t)(u))));if(s.length<u.length){r=s;continue}i=!1,o=s}return o};return n=>e(Pi(Gi(n)))},d2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=Lt(c=>f=>ut.compare(c.x)(f.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=Lt(a=>c=>ut.compare(c.x)(a.x))(W(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},l2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=Lt(c=>f=>ut.compare(c.y)(f.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=Lt(a=>c=>ut.compare(c.y)(a.y))(W(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},h2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=Lt(c=>f=>ut.compare(f.x)(c.x))(W(c=>({...c,x:c.x+c.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=Lt(a=>c=>ut.compare(a.x)(c.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},p2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=Lt(c=>f=>ut.compare(f.y)(c.y))(W(c=>({...c,y:c.y+c.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=Lt(a=>c=>ut.compare(a.y)(c.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},Xg=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,c=i,f=o;if(f>100){u=!1,s=c;continue}if(!a(c+f)){u=!1,s=c+f;continue}if(!a(c-f)){u=!1,s=c-f;continue}r=a,i=c,o=f+1}return s},Yg=t=>e=>n=>r=>i=>{const o=ce(e)(n),u=ge(e)(n);if(!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)?Xg(a=>Si(o)(u)(a)(t))(s)(1):s},m2=t=>e=>n=>r=>i=>{const o=ce(e)(n),u=ge(e)(n);if(!Ii(o)(u)(r)(t))return r;if(!Ii(o)(u)(i)(t))return i;const s=(r+i)/2;return Ii(o)(u)(s)(t)?Xg(a=>Ii(o)(u)(a)(t))(s)(1):s},y2=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},x2=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},N2=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)=>!Bo(e)(ce(k)(E))(ge(k)(E))(L),f=(L,k,E)=>!Bo(n)(ce(k)(E))(ge(k)(E))(L),d=(L,k,E,O)=>t.tag==="Just"&&!Di(n)(ce(L)(k))(ge(L)(k))(t._1)?t._1:m2(e)(L)(k)(E)(O),l=(L,k,E,O)=>{if(L===E){const et=y2(e)(k)(O)(L),G=l2(e)(L)(k)(O),P=p2(e)(L)(k)(O);return[{start:b(L,k),end:b(L,G),direction:re},{start:b(L,G),end:b(et,G),direction:ne},{start:b(et,G),end:b(et,P),direction:re},{start:b(et,P),end:b(E,P),direction:ne},{start:b(E,P),end:b(E,O),direction:re}]}const Y=d(L,E,k,O);return[{start:b(L,k),end:b(L,Y),direction:re},{start:b(L,Y),end:b(E,Y),direction:ne},{start:b(E,Y),end:b(E,O),direction:re}]},_=(L,k,E,O)=>{if(k===O){const et=x2(e)(L)(E)(k),G=d2(e)(k)(L)(E),P=h2(e)(k)(L)(E);return[{start:b(L,k),end:b(G,k),direction:ne},{start:b(G,k),end:b(G,et),direction:re},{start:b(G,et),end:b(P,et),direction:ne},{start:b(P,et),end:b(P,O),direction:re},{start:b(P,O),end:b(E,O),direction:ne}]}const Y=Yg(e)(k)(O)(L)(E);return[{start:b(L,k),end:b(Y,k),direction:ne},{start:b(Y,k),end:b(Y,O),direction:re},{start:b(Y,O),end:b(E,O),direction:ne}]},h=(L,k,E)=>!Di(e)(ce(k)(E))(ge(k)(E))(L),p=(L,k,E)=>!Di(n)(ce(k)(E))(ge(k)(E))(L),m=(L,k,E,O)=>{if(p(k,L,E)&&f(E,k,O))return[{start:b(L,k),end:b(E,k),direction:ne},{start:b(E,k),end:b(E,O),direction:re}];const Y=Yg(e)(k)(O)(L)(E);return[{start:b(L,k),end:b(Y,k),direction:ne},{start:b(Y,k),end:b(Y,O),direction:re},{start:b(Y,O),end:b(E,O),direction:ne}]},y=(L,k,E,O)=>{if(f(L,k,O)&&p(O,L,E))return[{start:b(L,k),end:b(L,O),direction:re},{start:b(L,O),end:b(E,O),direction:ne}];const Y=d(L,E,k,O);return[{start:b(L,k),end:b(L,Y),direction:re},{start:b(L,Y),end:b(E,Y),direction:ne},{start:b(E,Y),end:b(E,O),direction:re}]},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:re}]: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:re}]: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:ne}]:_(s._1,s._2,a._1,a._2):o==="North"||o==="South"?m(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="West"){if(o==="East")return s._2===a._2&&h(s._2,s._1,a._1)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:ne}]:_(s._1,s._2,a._1,a._2);if(o==="North"||o==="South")return m(s._1,s._2,a._1,a._2)}return l(s._1,s._2,a._1,a._2)})(),N=(()=>{if(r==="South"||r==="North")return re;if(r==="East"||r==="West")return ne;g()})(),w={start:b(a._1,a._2),end:b(u._1,u._2),direction:(()=>{if(o==="South"||o==="North")return re;if(o==="East"||o==="West")return ne;g()})()};return s._1===a._1&&s._2===a._2?[{start:b(i._1,i._2),end:b(u._1,u._2),direction:N}]:s2({start:b(i._1,i._2),end:b(s._1,s._2),direction:N})(x)(w)},J2=W(t=>({x:t.position._1*zo-2,y:t.position._2*zo-2,w:t.size._1*zo+4,h:t.size._2*zo+4})),Fs=jt(C)(zt),Fn=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},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},T2=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},Vg=t=>e=>{const n=e.position._1+e.size._1,r=e.position._2*2+e.size._2,i=e.position._1*2+e.size._1,o=e.position._2+e.size._2;if(t==="South")return b(i,o*2);if(t==="North")return b(i,e.position._2*2);if(t==="East")return b(n*2,r);if(t==="West")return b(e.position._1*2,r);g()},Ms=t=>e=>{const n=rt(4);if(t==="South")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="North")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="East")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};if(t==="West")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};g()},Ug=t=>e=>J(n=>r=>vt(t)(ee)(e(r))([r])(n))(Q),Zg=t=>e=>n=>r=>{const i=(t==="South"||t==="North")&&(e==="East"||e==="West")&&(()=>{if(t==="South")return r._2>n._2;if(t==="North")return r._2<n._2;if(t==="East")return r._2>n._2;if(t==="West")return r._2<n._2;g()})()&&(()=>{if(e==="East")return n._1>r._1;if(e==="West"||e==="North")return n._1<r._1;if(e==="South")return n._1>r._1;g()})(),o=(t==="East"||t==="West")&&(e==="North"||e==="South")&&(()=>{if(t==="South")return r._1>n._1;if(t==="North")return r._1<n._1;if(t==="East")return r._1>n._1;if(t==="West")return r._1<n._1;g()})()&&(()=>{if(e==="East")return n._2>r._2;if(e==="West"||e==="North")return n._2<r._2;if(e==="South")return n._2>r._2;g()})();return(t==="South"?e==="North"&&n._1===r._1&&r._2>n._2:t==="North"?e==="South"&&n._1===r._1&&r._2<n._2:t==="East"?e==="West"&&n._2===r._2&&r._1>n._1:t==="West"&&e==="East"&&n._2===r._2&&r._1<n._1)?0:i||o?1:2},Kg=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,i=e.length;return i===0?Q:Fs(i===1?W(o=>b(o,r))(e):Ft(o=>u=>b(u,t.lo+rt(o+1|0)*n/rt(i+1|0)))(e))},jg=t=>e=>n=>r=>i=>{const o=Ug(C)(_=>_.to.node)(t),u=Ug(C)(_=>_.from.node)(t),s=J(_=>h=>j(C)(h.node)(h)(_))(Q)(e),a=(_,h,p)=>{const m=Fn(_)(s);if(m.tag==="Nothing")return b(0,0);if(m.tag==="Just"){const y=Fn(_)(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=Fs(Tt(r)(_=>{if(_.nodes.length<=2)return[];const h=rt(4);if(1<_.nodes.length){const p=Fn(_.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 W(y=>b(y,m))(we(y=>x=>_.edgeId+":"+y+"->"+x,_.nodes,bt(1,_.nodes.length,_.nodes)))}g()}return[]})),f=_=>{const h=Fn(_.from.node)(s),p=Fn(_.to.node)(s);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,y=p._1,x=Lt(N=>w=>it.compare(N.score)(w.score))(W(N=>{const w=N._1,L=N._2;return{from:w,to:L,score:(()=>{const k=(et,G,P,V,U)=>{const B=Ms(et)(G),R=Ms(et)(P);return B.lo<R.hi&&R.lo<B.hi&&(w==="South"?L==="North"&&U._2>V._2:w==="North"?L==="South"&&U._2<V._2:w==="East"?L==="West"&&U._1>V._1:w==="West"&&L==="East"&&U._1<V._1)?0:Zg(w)(L)(V)(U)},E=Vg(w)(m),O=Vg(L)(y),Y=Zg(w)(L)(E)(O);return(()=>{if(Y>0){if(w==="South")return L==="North"?k(he,m,y,E,O)*10|0:Y*10|0;if(w==="North")return L==="South"?k(le,m,y,E,O)*10|0:Y*10|0;if(w==="East")return L==="West"?k(Gn,m,y,E,O)*10|0:Y*10|0;if(w==="West"&&L==="East")return k(Pn,m,y,E,O)*10|0}return Y*10|0})()+(w==="South"?L==="North"?0:15:w==="North"?L==="South"?0:15:w==="East"?L==="West"?5:15:w==="West"&&L==="East"?5:15)|0})()}})([b(he,le),b(Gn,le),b(Pn,le),b(he,Gn),b(he,Pn),b(le,he),b(le,Gn),b(le,Pn),b(Gn,he),b(Pn,he),b(Gn,Pn),b(Pn,Gn)]));if(0<x.length)return{from:x[0].from,to:x[0].to}}return{from:he,to:le}},d=Fs(W(_=>b(_.id,f(_)))(t)),l=(_,h,p,m,y,x)=>{const N=rt(4),w=Fn(h)(s);if(w.tag==="Nothing")return b(0,0);if(w.tag==="Just"){const L=T2(b(p,_))(i);if(L.tag==="Just"){const k=w._1.position._1*N+L._1,E=rt(4);if(_==="South")return b(k,(w._1.position._2+w._1.size._2)*E);if(_==="North")return b(k,w._1.position._2*E);if(_==="East")return b((w._1.position._1+w._1.size._1)*E,k);if(_==="West")return b(w._1.position._1*E,k);g()}if(L.tag==="Nothing"){const k=Ms(_)(w._1),E=(k.lo+k.hi)/2,O=As(p)(Kg(k)(W(G=>G.id)(Lt(G=>P=>ut.compare(y(_)(G))(y(_)(P)))(st(G=>{const P=As(G.id)(d);if(P.tag==="Just"){const V=x(P._1);return V==="North"?_==="North":V==="South"?_==="South":V==="East"?_==="East":V==="West"&&_==="West"}if(P.tag==="Nothing")return!0;g()},(()=>{const G=Fn(h)(m);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()))))),Y=(()=>{if(O.tag==="Nothing")return E;if(O.tag==="Just")return O._1;g()})(),et=rt(4);if(_==="South")return b(Y,(w._1.position._2+w._1.size._2)*et);if(_==="North")return b(Y,w._1.position._2*et);if(_==="East")return b((w._1.position._1+w._1.size._1)*et,Y);if(_==="West")return b(w._1.position._1*et,Y)}}g()};return W(_=>{const h=As(_.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()})(W(_=>{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=Fn(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=Fn(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))},tf=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},w2=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Os=t=>e=>t.gapTop+1*rt(4)+rt(e)*2.5*rt(4),v2=t=>e=>{const n=tf(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return v("Just",{slot1Y:Os(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Os(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return T;g()}if(n.tag==="Nothing")return T;g()},b2=t=>e=>{const n=J(r=>i=>j(C)(i.node)(i)(r))(Q)(e);return Oe(Ft(r=>i=>{const o=zr(i.node)(n);if(o.tag==="Nothing")return[];if(o.tag==="Just"){const u=o._1;return Ft(s=>a=>{const c=i.edges.length,f=rt(4),d=u.position._1*f,l=u.position._2*f,_=u.size._2*f,h=rt((2*c|0)+1|0),p=l+_*rt(c-s|0)/h,m=l+_*rt((c+1|0)+s|0)/h,y=d-f*2.5*rt(s+1|0),x=[{start:b(d,p),end:b(y,p),direction:ne},{start:b(y,p),end:b(y,m),direction:re},{start:b(y,m),end:b(d,m),direction:ne}];return{edge:a.id,segments:x,bends:we(N=>w=>N.end,x,bt(1,3,x)),bendType:[],jumps:[],reversed:!1}})(i.edges)}g()})(W(r=>({node:r._1,edges:r._2}))(w2(J(r=>i=>vt(C)(ee)(i.from.node)([i])(r))(Q)(t)))))},k2=t=>e=>{const n=J(o=>u=>j(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 Lt(o=>u=>{const s=it.compare(i(o.edge.from.node))(i(u.edge.from.node));if(s==="EQ"){const a=ut.compare(r(o.edge.from.node))(r(u.edge.from.node));return a==="EQ"?ut.compare(r(o.edge.to.node))(r(u.edge.to.node)):a}return s})(t)},De=t=>{const e=rt(4);return{x:t.position._1*e-2,y:t.position._2*e-2,w:t.size._1*e+4,h:t.size._2*e+4}},L2=t=>t.from.node===t.to.node,E2=t=>e=>n=>r=>{const i=_2(n)(N2(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:i,bends:we(o=>u=>o.end,i,bt(1,i.length,i)),bendType:[],jumps:[],reversed:!1}},C2=t=>e=>n=>r=>{const i=[{start:b(r.fromPos._1,r.fromPos._2),end:b(r.fromPos._1,t.slot1Y),direction:re},{start:b(r.fromPos._1,t.slot1Y),end:b(t.splitX,t.slot1Y),direction:ne},{start:b(t.splitX,t.slot1Y),end:b(t.splitX,t.slot2Y),direction:re},{start:b(t.splitX,t.slot2Y),end:b(r.toPos._1,t.slot2Y),direction:ne},{start:b(r.toPos._1,t.slot2Y),end:b(r.toPos._1,r.toPos._2),direction:re}];return{edge:r.edge.id,segments:i,bends:we(o=>u=>o.end,i,bt(1,5,i)),bendType:[],jumps:[],reversed:!1}},S2=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===De(r._1).h&&u.w===De(r._1).w&&u.x===De(r._1).x&&u.y===De(r._1).y)&&!(u.h===De(o._1).h&&u.w===De(o._1).w&&u.x===De(o._1).x&&u.y===De(o._1).y),e):st(u=>!(u.h===De(r._1).h&&u.w===De(r._1).w&&u.x===De(r._1).x&&u.y===De(r._1).y),e)}const i=zr(t.edge.to.node)(n);return i.tag==="Just"?st(o=>!(o.h===De(i._1).h&&o.w===De(i._1).w&&o.x===De(i._1).x&&o.y===De(i._1).y),e):st(o=>!0,e)},G2=t=>e=>{const n=tf(e.edge.id)(t);if(n.tag==="Just")return v("Just",Os(n._1)(n._1.slot));if(n.tag==="Nothing")return T;g()},P2=t=>e=>n=>r=>i=>{const o=J(c=>f=>j(C)(f.node)(f)(c))(Q)(e),u=J2(e),s=jg(st(c=>c.from.node!==c.to.node,t))(e)(n)(r)(i),a=Hg(s)(e);return[...b2(st(L2,t))(e),...J(c=>f=>{const d=S2(f)(u)(o),l=[...d,...c.edgeObstacles],_=v2(a)(f),h=(()=>{if(_.tag==="Just")return C2(_._1)(d)(l)(f);if(_.tag==="Nothing")return E2(G2(a)(f))(d)(l)(f);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...u2(h.segments)]}})({results:[],edgeObstacles:[]})(k2(s)(e)).results]},nr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},rr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},I2=t=>e=>n=>{if(t.start._1!==e.start._1)return T;const r=rr(nr(t.start._2)(t.end._2))(nr(e.start._2)(e.end._2)),i=nr(rr(t.start._2)(t.end._2))(rr(e.start._2)(e.end._2));return r<i?v("Just",{position:b(t.start._1,(r+i)/2),crossingEdge:n}):T},D2=t=>e=>n=>{if(t.start._2!==e.start._2)return T;const r=rr(nr(t.start._1)(t.end._1))(nr(e.start._1)(e.end._1)),i=nr(rr(t.start._1)(t.end._1))(rr(e.start._1)(e.end._1));return r<i?v("Just",{position:b((r+i)/2,t.start._2),crossingEdge:n}):T},Q2=t=>e=>n=>{if(t.direction==="H")return D2(t)(e)(n);if(t.direction==="V")return I2(t)(e)(n);g()},F2=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=>Q2(o)(s)(u.edge))(st(s=>s.direction==="H"?o.direction==="H":s.direction==="V"&&o.direction==="V",u.segments))))},A2=t=>e=>n=>e.start._1>nr(t.start._1)(t.end._1)&&e.start._1<rr(t.start._1)(t.end._1)&&t.start._2>nr(e.start._2)(e.end._2)&&t.start._2<rr(e.start._2)(e.end._2)?v("Just",{position:b(e.start._1,t.start._2),crossingEdge:n}):T,M2=t=>e=>Tt(st(n=>n.direction==="H",t.segments))(n=>Tt(e)(r=>xt(i=>A2(n)(i)(r.edge))(st(i=>i.direction==="V",r.segments)))),O2=t=>e=>n=>[...M2(e)(st(r=>r.edge!==e.edge,n)),...F2(t)(e)(n)],ef=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},nf=t=>me(3)(t)==="$d:",R2=t=>e=>n=>J(r=>i=>{const o=ef(i.from.node)(t),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})(),s=ef(i.to.node)(t),a=(()=>{if(s.tag==="Nothing")return-u;if(s.tag==="Just")return s._1-u|0;g()})();if(a<=1)return{...r,edges:[...r.edges,i],chains:[...r.chains,{edgeId:i.id,nodes:[i.from.node,i.to.node]}]};const c=i.id,f=W(l=>"$d:"+c+":"+oe(l))(Dt(1,a-1|0)),d=[i.from.node,...f,i.to.node];return{...r,layers:J(l=>_=>{const h=_._2,p=hd(u+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;g()})(r.layers)(we(Cn,Dt(1,a-1|0),f)),edges:[...r.edges,...we(l=>_=>({id:c+":"+l+"->"+_,from:{node:l,port:i.from.port},to:{node:_,port:i.to.port},label:T}),d,bt(1,d.length,d))],chains:[...r.chains,{edgeId:i.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),Wo=(()=>{const t={eq:e=>n=>e._1===n._1&&(e._2==="North"?n._2==="North":e._2==="South"?n._2==="South":e._2==="East"?n._2==="East":e._2==="West"&&n._2==="West")};return{compare:e=>n=>{const r=C.compare(e._1)(n._1);if(r==="LT")return Ne;if(r==="GT")return Je;if(e._2==="North")return n._2==="North"?Ge:Ne;if(n._2==="North")return Je;if(e._2==="South")return n._2==="South"?Ge:Ne;if(n._2==="South")return Je;if(e._2==="East")return n._2==="East"?Ge:Ne;if(n._2==="East")return Je;if(e._2==="West"&&n._2==="West")return Ge;g()},Eq0:()=>t}})(),B2=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=Wo.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},z2=jt(C)(zt),Rs=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},W2=jt(Wo)(zt),rf=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Wr=t=>e=>n=>r=>{const i=B2(b(e,n))(t);if(i.tag==="Nothing")return r;if(i.tag==="Just")return i._1;g()},of=t=>e=>n=>{const r=z2(Oe(W(u=>Ft(s=>a=>b(a,s))(u))(t))),i=(u,s)=>{if(u==="South"){const a=Rs(s.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()}if(u==="North"){const a=Rs(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(Wo.compare,ke,W2(W(c=>b(b(c._1,u),c._2))(rf(Kg({lo:0,hi:(()=>{const c=Rs(a._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return me(3)(a._1)==="$d:"?0:1;g()})()})(W(c=>c.id)(Lt(c=>f=>it.compare(i(u,c))(i(u,f)))(a._2)))))),s))(Q)(rf(J(s=>a=>a.from.node===a.to.node?s:u==="South"?vt(C)(ee)(a.from.node)([a])(s):u==="North"?vt(C)(ee)(a.to.node)([a])(s):s)(Q)(e)));return Ee(Wo.compare,ke,o(le),o(he))},uf=t=>t,sf=t=>t,af=t=>t,q2=J(t=>e=>j(C)(e)()(t))(Q),H2=(()=>{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},rn=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=jt(C)(zt),Bs=oc(C),zs=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),$2=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},X2=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},cf=af("VDown"),gf=af("VUp"),Y2=sf("ForwardPhase"),V2=sf("StackPhase"),ff=uf("HRight"),_f=uf("HLeft"),df=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},U2=t=>e=>n=>{const r=J(u=>s=>vt(C)(ue)(s.tgt)(1)(u))(Q)(t),i=H2(q2([...W(u=>u.src)(t),...W(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)(ee)(s.src)([{target:s.tgt,sep:s.sep}])(u))(Q)(t);return(u=>s=>a=>{let c=u,f=s,d=a,l=!0,_;for(;l;){const h=c,p=f,m=d,y=Mt(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(L=>k=>{const E=ot(k.target)(L.result),O=N+k.sep,Y=ot(k.target)(L.indeg),et=(()=>{if(Y.tag==="Nothing")return-1;if(Y.tag==="Just")return Y._1-1|0;g()})();return{newQueue:et===0?[...L.newQueue,k.target]:L.newQueue,result:j(C)(k.target)((()=>{if(E.tag==="Nothing")return O;if(E.tag==="Just"){if(n==="VDown")return rn(E._1)(O);if(n==="VUp")return Nn(E._1)(O)}g()})())(L.result),indeg:j(C)(k.target)(et)(L.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const L=ot(y._1.head)(o);if(L.tag==="Nothing")return[];if(L.tag==="Just")return L._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=>j(C)(s)(0)(u))(Q)(i))},Z2=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(rn)(999999)(n);if(r===0||n.length===0)return t;const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Wt("Node",o._1,o._2,o._3,o._4-r,i(o._5),i(o._6));g()};return i(t)},lf=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,qt("Cons",o._4,e(o._6,u)));g()},n=e(t,Ht),r=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l.tag==="Nil"){c=!1,f=d;continue}if(l.tag==="Cons"){s=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=rn(d)(l._1),a=l._2;continue}g()}return f};return r(-999999)(n)-i(999999)(n)},Qi=t=>e=>(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(a===e){u=!1,s=c;continue}i=(()=>{const f=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]),K2=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>{const d=(S,I,D)=>{const A=S.from.node===I?S.from.port:S.to.node===I?S.to.port:T;if(A.tag==="Just"){const H=ot(I)(i);if(H.tag==="Just"){const $=Vt(X=>X.id===A._1)(H._1);if($.tag==="Just"){const X=rt($._1.offset)*rt(4);return D==="North"||D==="South"?X:0}if($.tag==="Nothing"){const X=ot(I)(r),q=Wr(u)(S.id)(D)((()=>{if(X.tag==="Nothing")return .5;if(X.tag==="Just")return X._1._1/2;g()})());return D==="North"||D==="South"?q:0}g()}if(H.tag==="Nothing"){const $=ot(I)(r),X=Wr(u)(S.id)(D)((()=>{if($.tag==="Nothing")return .5;if($.tag==="Just")return $._1._1/2;g()})());return D==="North"||D==="South"?X:0}g()}if(A.tag==="Nothing"){const H=ot(I)(r),$=Wr(u)(S.id)(D)((()=>{if(H.tag==="Nothing")return .5;if(H.tag==="Just")return H._1._1/2;g()})());return D==="North"||D==="South"?$:0}g()},l=(S,I)=>{if(S.from.node===I){if(f==="HRight")return he;if(f==="HLeft")return le;g()}if(f==="HRight")return le;if(f==="HLeft")return he;g()},_=(S,I,D)=>J(A=>H=>j(C)(H)((()=>{const $=ot(H)(A);if($.tag==="Nothing")return 0+I;if($.tag==="Just")return $._1+I;g()})())(A))(D)(Qi(a)(S)),h=(()=>{if(f==="HRight")return n;if(f==="HLeft")return Te(n);g()})(),p=S=>{const I=ot(S)(r);if(I.tag==="Nothing")return 1;if(I.tag==="Just")return I._1._1;g()},m=Jn(Oe(Ft(S=>I=>W(D=>b(D,S))(I))(n))),y=(S,I)=>me(3)(S)==="$d:"&&me(3)(I)==="$d:"||me(3)(S)==="$d:"||me(3)(I)==="$d:"?10:rt(t.nodeGap),x=J(S=>I=>Bs(D=>v("Just",[...(()=>{if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})(),I]))(I.to.node)(S))(Q)(o),N=J(S=>I=>Bs(D=>v("Just",[...(()=>{if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})(),I]))(I.from.node)(S))(Q)(o),w=Oe(n),L=J(S=>I=>{const D=ot(I)(a.root),A=(()=>{if(D.tag==="Nothing")return I;if(D.tag==="Just")return D._1;g()})();return I===A?S:Bs(H=>v("Just",(()=>{if(H.tag==="Nothing")return!0;if(H.tag==="Just")return H._1;g()})()&&me(3)(I)==="$d:"))(A)(S)})(Jn(W(S=>b(S,!0))(br(C.compare)((()=>{const S=(I,D)=>{if(I.tag==="Leaf")return D;if(I.tag==="Node")return S(I._5,qt("Cons",I._4,S(I._6,D)));g()};return Ct($t.foldr,S(a.root,Ht))})()))))(w),k=(S,I)=>{const D=S.free,A=ot(D)(a.root),H=(()=>{if(A.tag==="Nothing")return D;if(A.tag==="Just")return A._1;g()})(),$=ot(H)(L),X=(()=>{if($.tag==="Nothing")return!0;if($.tag==="Just")return $._1;g()})();return J(q=>z=>{if(q.edge.tag==="Just")return q;if(q.edge.tag==="Nothing"){if((()=>{const at=ot(H)(I.su);return!X&&(()=>{const yt=ot(z.from.node)(m);return z.from.node!==z.to.node&&(()=>{const St=ot(z.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=z.from.node===D?z.to.node:z.from.node,Z=ot(tt)(a.root),ct=(()=>{if(Z.tag==="Nothing")return tt;if(Z.tag==="Just")return Z._1;g()})(),ft=ct!==H;return ft&&(()=>{const at=ot(ct)(I.blockFinished);if(at.tag==="Nothing")return!1;if(at.tag==="Just")return at._1;g()})()?{...q,edge:v("Just",z),hasEdges:!0}:{...q,hasEdges:q.hasEdges||ft}}g()})({edge:T,hasEdges:!1})((()=>{if(S.isRoot){if(f==="HRight"){const q=ot(D)(x);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;g()}if(f==="HLeft"){const q=ot(D)(N);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}g()}if(f==="HRight"){const q=ot(D)(N);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;g()}if(f==="HLeft"){const q=ot(D)(x);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}g()})())},E=(S,I,D,A)=>{const H=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),$={free:I,isRoot:D},X=k($,A);if(X.edge.tag==="Nothing")return X.hasEdges?{thresh:H,state:{...A,queue:[...A.queue,$]}}:{thresh:H,state:A};if(X.edge.tag==="Just"){const q=X.edge._1.from.node===I?X.edge._1.to.node:X.edge._1.from.node;return{thresh:(()=>{const z=ot((()=>{const ft=ot(q)(a.root);if(ft.tag==="Nothing")return q;if(ft.tag==="Just")return ft._1;g()})())(A.x),tt=ot(q)(s),Z=ot(I)(s),ct=(()=>{if(z.tag==="Just")return z._1;if(z.tag==="Nothing")return T;g()})();return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+(()=>{if(tt.tag==="Nothing")return 0;if(tt.tag==="Just")return tt._1;g()})()+d(X.edge._1,q,(()=>{if(D){if(f==="HRight")return he;if(f==="HLeft")return le;g()}if(f==="HRight")return le;if(f==="HLeft")return he;g()})())-(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()-d(X.edge._1,I,(()=>{if(D){if(f==="HRight")return le;if(f==="HLeft")return he;g()}if(f==="HRight")return he;if(f==="HLeft")return le;g()})())})(),state:{...A,su:j(C)((()=>{const z=ot(X.edge._1.from.node)(a.root);if(z.tag==="Nothing")return X.edge._1.from.node;if(z.tag==="Just")return z._1;g()})())(!0)(j(C)((()=>{const z=ot(X.edge._1.to.node)(a.root);if(z.tag==="Nothing")return X.edge._1.to.node;if(z.tag==="Just")return z._1;g()})())(!0)(A.su))}}}g()},O=(S,I,D,A)=>{const H=I===S,$=ot(I)(a.align),X=(()=>{if($.tag==="Nothing")return I===S;if($.tag==="Just")return $._1===S;g()})();if(!(H||X))return{thresh:D,state:A};const q=(()=>{if(c==="VDown")return H&&D<=-1e18;if(c==="VUp")return H&&D>=1e18;g()})()?E(S,I,!0,A):{thresh:D,state:A};return(()=>{if(c==="VDown")return q.thresh<=-1e18&&X;if(c==="VUp")return q.thresh>=1e18&&X;g()})()?E(S,I,!1,q.state):q},Y=S=>I=>D=>{const A=ot(D)(e.nodeIndex),H=(()=>{if(A.tag==="Nothing")return 0;if(A.tag==="Just")return A._1;g()})(),$=Vt(Z=>Be(fn)(D)(Z))(h),X=(()=>{if($.tag==="Nothing")return[];if($.tag==="Just")return $._1;g()})(),q=X.length;if((()=>{if(c==="VDown")return H<=0;if(c==="VUp")return H>=(q-1|0);g()})()){const Z=O(S,D,I.thresh,I.st);return{...I,st:Z.state,thresh:Z.thresh}}const z=(()=>{if(c==="VDown")return H-1|0;if(c==="VUp")return H+1|0;g()})(),tt=z>=0&&z<X.length?v("Just",X[z]):T;if(tt.tag==="Nothing")return I;if(tt.tag==="Just"){const Z=ot(tt._1)(a.root),ct=(()=>{if(Z.tag==="Nothing")return tt._1;if(Z.tag==="Just")return Z._1;g()})(),ft=O(S,D,I.thresh,et(ct)(I.st)),at=(()=>{const Kt=ot(S)(ft.state.sink);if(Kt.tag==="Nothing")return S===S;if(Kt.tag==="Just")return Kt._1===S;g()})()?{...ft.state,sink:j(C)(S)((()=>{const Kt=ot(ct)(ft.state.sink);if(Kt.tag==="Nothing")return ct;if(Kt.tag==="Just")return Kt._1;g()})())(ft.state.sink)}:ft.state,yt=ot(ct)(at.sink),St=(()=>{if(yt.tag==="Nothing")return ct;if(yt.tag==="Just")return yt._1;g()})(),Rt=ot(S)(at.sink),pt=(()=>{if(Rt.tag==="Nothing")return S;if(Rt.tag==="Just")return Rt._1;g()})();if(pt===St){const Kt=ot(ct)(at.x),Se=(()=>{if(Kt.tag==="Just")return Kt._1;if(Kt.tag==="Nothing")return T;g()})(),sn=(()=>{if(Se.tag==="Nothing")return 0;if(Se.tag==="Just")return Se._1;g()})(),Me=ot(S)(at.x),Et=(()=>{if(Me.tag==="Just")return Me._1;if(Me.tag==="Nothing")return T;g()})(),Qt=(()=>{if(Et.tag==="Nothing")return 0;if(Et.tag==="Just")return Et._1;g()})(),je=y(D,tt._1),qe=ot(tt._1)(s),tn=ot(D)(s),Hn=(()=>{if(qe.tag==="Nothing")return 0;if(qe.tag==="Just")return qe._1;g()})()-(()=>{if(tn.tag==="Nothing")return 0;if(tn.tag==="Just")return tn._1;g()})();if(c==="VDown"){const dn=Nn(sn+Hn+p(tt._1)+je)(ft.thresh);return{st:{...at,x:j(C)(S)(v("Just",I.initial?dn:Nn(Qt)(dn)))(at.x)},initial:!1,thresh:ft.thresh}}if(c==="VUp"){const dn=rn(sn+Hn-je-p(D))(ft.thresh);return{st:{...at,x:j(C)(S)(v("Just",I.initial?dn:rn(Qt)(dn)))(at.x)},initial:!1,thresh:ft.thresh}}g()}const Bt=ot(ct)(at.x),Jt=(()=>{if(Bt.tag==="Just")return Bt._1;if(Bt.tag==="Nothing")return T;g()})(),mt=(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})(),gt=ot(S)(at.x),K=(()=>{if(gt.tag==="Just")return gt._1;if(gt.tag==="Nothing")return T;g()})(),nt=(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})(),ht=rt(t.nodeGap),_t=ot(D)(s),Nt=ot(tt._1)(s),wt=(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;g()})()-(()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1;g()})();return{st:{...at,classEdges:[...at.classEdges,{src:pt,tgt:St,sep:(()=>{if(c==="VDown")return nt+wt-mt-p(tt._1)-ht;if(c==="VUp")return nt+wt+p(D)+ht-mt;g()})()}]},initial:I.initial,thresh:ft.thresh}}g()},et=S=>I=>{const D=ot(S)(I.x),A=(()=>{if(D.tag==="Just")return D._1;if(D.tag==="Nothing")return T;g()})();if(A.tag==="Just")return I;if(A.tag==="Nothing"){const H=J(Y(S))({st:{...I,x:j(C)(S)(v("Just",0))(I.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})()})(Qi(a)(S));return{...H.st,blockFinished:j(C)(S)(!0)(H.st.blockFinished)}}g()},G=J(S=>I=>J(D=>A=>{const H=ot(A)(a.root),$=(()=>{if(H.tag==="Nothing")return A;if(H.tag==="Just")return H._1;g()})();return $===A?et($)(D):D})(S)((()=>{if(c==="VDown")return I;if(c==="VUp")return Te(I);g()})()))({x:Jn(W(S=>b(S,T))(w)),sink:Jn(W(S=>b(S,S))(w)),classEdges:[],su:Q,blockFinished:Q,queue:[]})(h),P=U2(G.classEdges)(G.sink)(c),V=(S,I,D,A)=>{const H=ot(I)(A),$=ot(I)(s);return(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})()+(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;g()})()+d(S,I,D)},U=Jn(W(S=>b(S,!0))(br(C.compare)((()=>{const S=(I,D)=>{if(I.tag==="Leaf")return D;if(I.tag==="Node")return S(I._5,qt("Cons",I._4,S(I._6,D)));g()};return Ct($t.foldr,S(a.root,Ht))})()))),B=S=>I=>D=>{const A=k(D,{su:I.su,blockFinished:U}),H={phase:S,ppFree:D.free,ppIsRoot:D.isRoot,edgeId:T,delta:0,avail:0,shift:0,freeSu:(()=>{const $=ot((()=>{const X=ot(D.free)(a.root);if(X.tag==="Nothing")return D.free;if(X.tag==="Just")return X._1;g()})())(I.su);if($.tag==="Nothing")return!1;if($.tag==="Just")return $._1;g()})(),hasEdges:A.hasEdges,candCount:(()=>{if(D.isRoot){if(f==="HRight"){const $=ot(D.free)(x);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length;g()}if(f==="HLeft"){const $=ot(D.free)(N);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length}g()}if(f==="HRight"){const $=ot(D.free)(N);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length;g()}if(f==="HLeft"){const $=ot(D.free)(x);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1.length}g()})()};if(A.edge.tag==="Nothing")return{...I,stack:[...I.stack,D],trace:[...I.trace,H],x:I.x};if(A.edge.tag==="Just"){const $=A.edge._1.from.node===D.free?b(A.edge._1.from.node,A.edge._1.to.node):b(A.edge._1.to.node,A.edge._1.from.node),X=V(A.edge._1,$._1,l(A.edge._1,$._1),I.x)-V(A.edge._1,$._2,l(A.edge._1,$._2),I.x),q=ot($._1)(a.root),z=(()=>{if(q.tag==="Nothing")return $._1;if(q.tag==="Just")return q._1;g()})(),tt={...H,edgeId:v("Just",A.edge._1.id),delta:X};if(X>0&&X<1e300){const Z=J(at=>yt=>{const St=ot(yt)(m),Rt=(()=>{if(St.tag==="Nothing")return-1;if(St.tag==="Just")return St._1;g()})();if(Rt>=0&&Rt<n.length){const Jt=n[Rt],mt=ot(yt)(e.nodeIndex),gt=(()=>{if(mt.tag==="Nothing")return-2;if(mt.tag==="Just")return mt._1-1|0;g()})();return gt>=0&><Jt.length?rn(at)((()=>{const K=ot(yt)(I.x),nt=ot(yt)(s),ht=ot(Jt[gt])(I.x),_t=ot(Jt[gt])(s);return(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;g()})()-((()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;g()})()+p(Jt[gt])+y(yt,Jt[gt]))})()):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?rn(at)((()=>{const Jt=ot(yt)(I.x),mt=ot(yt)(s),gt=ot([][Bt])(I.x),K=ot([][Bt])(s);return(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})()+(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()-((()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()+(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+p([][Bt])+y(yt,[][Bt]))})()):at})(X)(Qi(a)(z)),ct=Z>0?-Z:0,ft={...I,x:Z>0?_(z,ct,I.x):I.x,trace:[...I.trace,{...tt,avail:Z,shift:ct}]};return Z>0?ft:{...ft,stack:[...ft.stack,D]}}if(X<0&&-X<1e300){const Z=J(at=>yt=>{const St=ot(yt)(m),Rt=(()=>{if(St.tag==="Nothing")return-1;if(St.tag==="Just")return St._1;g()})();if(Rt>=0&&Rt<n.length){const Jt=n[Rt],mt=ot(yt)(e.nodeIndex),gt=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1+1|0;g()})();return gt>=0&><Jt.length?rn(at)((()=>{const K=ot(Jt[gt])(I.x),nt=ot(Jt[gt])(s),ht=ot(yt)(I.x),_t=ot(yt)(s);return(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;g()})()-((()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;g()})()+p(yt)+y(yt,Jt[gt]))})()):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?rn(at)((()=>{const Jt=ot([][Bt])(I.x),mt=ot([][Bt])(s),gt=ot(yt)(I.x),K=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(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()+(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+p(yt)+y(yt,[][Bt]))})()):at})(-X)(Qi(a)(z)),ct=Z>0?Z:0,ft={...I,x:Z>0?_(z,ct,I.x):I.x,trace:[...I.trace,{...tt,avail:Z,shift:ct}]};return Z>0?ft:{...ft,stack:[...ft.stack,D]}}return{...I,stack:[...I.stack,D],trace:[...I.trace,tt],x:I.x}}g()},R=J(B(Y2))({x:Jn(W(S=>b(S,(()=>{const I=ot(S)(a.root),D=(()=>{if(I.tag==="Nothing")return S;if(I.tag==="Just")return I._1;g()})(),A=ot(D)(G.x),H=ot((()=>{const X=ot(D)(G.sink);if(X.tag==="Nothing")return D;if(X.tag==="Just")return X._1;g()})())(P),$=(()=>{if(A.tag==="Just")return A._1;if(A.tag==="Nothing")return 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:G.su,stack:[],trace:[]})(G.queue),M=J(B(V2))({...R,stack:[]})(Te(R.stack));return{x:M.x,queue:G.queue,trace:M.trace}},j2=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>K2(t)(e)(n)(r)(i)(o)(u)(s)(a)(c)(f).x,ty=t=>e=>n=>r=>i=>o=>{const u=(a,c,f)=>{const d=ot(c)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;g()})(),_=a.from.node===c?a.from.port:a.to.node===c?a.to.port: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,L=Mt(k=>T,k=>E=>v("Just",{head:k,tail:E}),p);if(L.tag==="Nothing"){m=!1,y=x;continue}if(L.tag==="Just"){const k=L._1.head,E=Vt(Y=>Y.from.node===w&&Y.to.node===k||Y.from.node===k&&Y.to.node===w)(r),O=(()=>{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,k,E._1.from.node===k?he:le));g()})();l=j(C)(k)(O)(x),_=O,h=k,p=L._1.tail;continue}g()}return y};return J(a=>c=>{const f=Mt(_=>T,_=>h=>v("Just",{head:_,tail:h}),Qi(t)(c)),d=(()=>{if(f.tag==="Nothing")return j(C)(c)(0)(Q);if(f.tag==="Just")return s(j(C)(f._1.head)(0)(Q))(0)(f._1.head)(f._1.tail);g()})(),l=J(_=>h=>Nn(_)(-h._2))(0)(zs(d));return J(_=>h=>j(C)(h._1)(h._2+l)(_))(a)(zs(d))})(Q)(br(C.compare)((()=>{const a=(c,f)=>{if(c.tag==="Leaf")return f;if(c.tag==="Node")return a(c._5,qt("Cons",c._4,a(c._6,f)));g()};return Ct($t.foldr,a(t.root,Ht))})()))},ey=t=>e=>{const n=(i,o,u)=>me(3)(o)==="$d:"&&Za(nf,(()=>{const s=ot(o)(t.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;g()})()),r=i=>o=>u=>s=>a=>c=>f=>{let d=i,l=o,_=s,h=c,p=f,m=!0,y;for(;m;){const x=d,N=l,w=_,L=h,k=p,E=N.length;if(k>=E){m=!1,y=x;continue}const O=k>=0&&k<N.length?v("Just",N[k]):T,Y=(()=>{if(O.tag==="Nothing")return"";if(O.tag==="Just")return O._1;g()})(),et=n(t,Y);if(k===(E-1|0)||et){const G=(()=>{if(et){const P=ot(Y)(t.preds),V=(()=>{if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})();if(0<V.length){const U=w-1|0,B=ot(V[0])(t.nodeIndex);if(B.tag==="Nothing")return U;if(B.tag==="Just")return B._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(B=>R=>{const M=ot(R)(t.nodeIndex),S=(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})();return S<L||S>G?j(C)(R+"\u2192"+U)()(B):B})(P)((()=>{const B=ot(U)(t.preds);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;g()})())}return n(t,"")?P:J(U=>B=>{const R=ot(B)(t.nodeIndex),M=(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})();return M<L||M>G?j(C)(B+"\u2192")()(U):U})(P)((()=>{const U=ot("")(t.preds);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;g()})())})(x)(Dt(0,k)),l=N,_=w,h=G,p=k+1|0;continue}d=x,l=N,_=w,h=L,p=k+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)(Dt(1,e.length-2|0))},ny=t=>e=>n=>r=>i=>{const o=Oe(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=En(_-1|0,2),p=En(_,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(!(df(l[y]+"\u2192"+d)(n)||df(d+"\u2192"+l[y])(n))&&(()=>{if(r==="VDown")return m.r<N;if(r==="VUp")return m.r>N;g()})()){const w=ot(l[y])(m.root),L=(()=>{if(w.tag==="Nothing")return l[y];if(w.tag==="Just")return w._1;g()})();return{root:j(C)(d)(L)(m.root),align:j(C)(l[y])(d)(j(C)(d)(L)(m.align)),r:N}}}return m})(f)((()=>{if(r==="VDown")return Dt(h,p);if(r==="VUp")return Te(Dt(h,p));g()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;g()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return Te(a);g()})());return{root:c.root,align:c.align}})({root:Jn(W(s=>b(s,s))(o)),align:Jn(W(s=>b(s,s))(o))})((()=>{if(i==="HRight")return e;if(i==="HLeft")return Te(e);g()})());return{root:u.root,align:u.align}},qo=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>{const f=ny(e)(n)(s)(a)(c),d=ty(f)(i)(r)(o)(u)(c);return Ed()(l=>_=>v("Just",(()=>{const h=ot(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;g()})()))(j2(t)(e)(n)(r)(i)(o)(u)(d)(f)(a)(c))},hf=t=>e=>Ft(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),ry=t=>e=>n=>r=>i=>o=>u=>{const s=$2(0)(e.length-1|0),a=rt(t.layerGap),c=u(fd(s,a)),f=o2(jg(i)(c)(r)(o)(Q))(c);return W(d=>{const l=X2(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))},pf=t=>e=>n=>r=>Za(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),iy=t=>e=>n=>r=>{const i=Lt(o=>u=>ut.compare(o.w)(u.w))(W(o=>({l:o,w:lf(o)}))(st(pf()(e)(n),r)));return 0<i.length?v("Just",i[0].l):T},oy=t=>e=>{const n=Jn(Oe(W(Ft(i=>o=>b(o,i)))(t))),r=i=>Lt(o=>u=>it.compare((()=>{const s=ot(o)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})())((()=>{const s=ot(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(i);return{preds:(()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Wt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(J(o=>u=>vt(C)(ee)(u.to.node)([u.from.node])(o))(Q)(e))})(),succs:(()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Wt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(J(o=>u=>vt(C)(ee)(u.from.node)([u.to.node])(o))(Q)(e))})(),nodeIndex:n}},uy=t=>e=>{const n=Lt(d=>l=>ut.compare(d.w)(l.w))(Ft(d=>l=>({i:d,l,w:lf(l)}))(e)),r=0<n.length?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"){_=rn(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)(zs(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=we(d=>l=>{const _=h=>{if(h.tag==="Leaf")return Q;if(h.tag==="Node")return Wt("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));g()};return _(d)},e,Ft(d=>l=>Un(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=rn(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 Z2(J(d=>l=>{const _=Lt(ut.compare)(xt(ot(l))(f));return j(C)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(Q)(br(C.compare)(Oe(W(d=>{const l=_=>{if(_.tag==="Leaf")return Q;if(_.tag==="Node")return Wt("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));g()};return Ct(We.foldr,l(d))})(f)))))},sy=t=>e=>n=>r=>i=>o=>{const u=oy(e)(i),s=ey(u)(e),a={nodeGap:t.nodeGap*4|0},c=Ee(C.compare,ke,Jn(W(_=>b(_,b(1,1)))(st(nf,Oe(e)))),(()=>{const _=h=>{if(h.tag==="Leaf")return Q;if(h.tag==="Node")return Wt("Node",h._1,h._2,h._3,b(h._4._1*rt(4),h._4._2),_(h._5),_(h._6));g()};return _(n)})()),f=[qo(a)(u)(e)(c)(r)(i)(o)(s)(cf)(ff),qo(a)(u)(e)(c)(r)(i)(o)(s)(gf)(ff),qo(a)(u)(e)(c)(r)(i)(o)(s)(cf)(_f),qo(a)(u)(e)(c)(r)(i)(o)(s)(gf)(_f)],d=uy(c)(f);if(pf()(e)(c)(d))return d;const l=iy()(e)(c)(f);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return f[0];g()},ay=t=>e=>n=>r=>{const i=Xa(T,Ba,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 W(u=>u.node===n?{...u,position:b(o._1+r._1,o._2+r._2)}:u)(t)}g()},cy=t=>e=>n=>r=>{const i=st(u=>Be(fn)(u.node)(e),t),o=(()=>{if(n==="Vertical"){if(r==="Start")return J(u=>s=>rn(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=>rn(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 W(u=>{if(Be(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)},gy=t=>e=>J(n=>r=>r.tag==="AlignGroup"?cy(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?ay(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),fy=t=>e=>n=>r=>i=>o=>u=>s=>{const a=W(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=sy(t)(n)(r)(i)(o)(s),f=hf(ry(t)(n)(r)(i)(o)(u)(d=>{const l=hf(d)(a);return Oe(Ft(_=>h=>Ft(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 gy(e)(Oe(Ft(d=>l=>Ft(_=>h=>({node:h,position:b((()=>{const p=ot(h)(c);return(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})()/rt(4)})(),d>=0&&d<f.length?f[d]:0),size:(()=>{const p=me(3)(h)==="$d:"?b(0,1):b(1,1),m=ot(h)(r);if(m.tag==="Nothing")return p;if(m.tag==="Just")return m._1;g()})(),layer:d,order:_}))(l))(n)))},Ws=Xu(_o)(hr(32)),mf=Xu(_o)(hr(31)),Fi=(()=>{const t=bl("25214903917");if(t.tag==="Nothing")return lc;if(t.tag==="Just")return t._1;g()})(),Ai=$u(Xu(_o)(hr(48)))(_o),_y=t=>{const e=kl(t);return li(hc((()=>{if(e.tag==="Nothing")return lc;if(e.tag==="Just")return e._1;g()})())(Fi))(Ai)},qs=hr(11),Ho=t=>e=>{const n=li(go(fo(e)(Fi))(qs))(Ai);return b((()=>{const r=nc(Jl(Yu(n)(hr(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},dy=t=>{const e=Ho(26)(t),n=Ho(27)(e._2);return b((rt(e._1)*Cu(2)(27)+rt(n._1))/Cu(2)(53),n._2)},ly=t=>e=>{const n=J(r=>i=>{const o=dy(r.finalR);return{rs:[...r.rs,o._1],finalR:o._2}})({rs:[],finalR:t})(e);return b(W(r=>r.x)(Lt(r=>i=>ut.compare(r.k)(i.k))(we(r=>i=>({x:r,k:i}),e,n.rs))),n.finalR)},hy=t=>{const e=li(go(fo(t)(Fi))(qs))(Ai),n=li(go(fo(e)(Fi))(qs))(Ai);return b(go(fo((()=>{const r=Yu(e)(hr(16));return pc.compare(r)(mf)!=="LT"?$u(r)(Ws):r})())(Ws))((()=>{const r=Yu(n)(hr(16));return pc.compare(r)(mf)!=="LT"?$u(r)(Ws):r})()),n)},Mi=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},$o=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},Hs=jt(C)(zt),qr=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},Xo=jt(C)(zt),py=Lu(ri),my=J(Lr)(0),yy=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},yf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=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},xy=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const i=Xn(Xt,T,t,n[e],n);if(i.tag==="Just")return Xn(Xt,T,e,r,i._1);if(i.tag==="Nothing")return T;g()}}return T},Ny=t=>e=>n=>r=>i=>Hs(J(o=>u=>{const s=Lt(a=>c=>it.compare((()=>{const f=Mi(a.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})())((()=>{const f=Mi(c.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})()))(st(a=>$o(a.to.node)(n),st(a=>a.from.node===u,r)));return{ranks:[...o.ranks,...Ft(a=>c=>b(c.id,rt((o.rankSum+a|0)+1|0)))(s)],rankSum:o.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),Jy=t=>e=>n=>r=>i=>Hs(J(o=>u=>{const s=Lt(c=>f=>{const d=it.compare((()=>{const l=qr(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=qr(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=Mi(c.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})())((()=>{const l=Mi(f.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})()):d})(st(c=>$o(c.from.node)(n),st(c=>c.to.node===u,r))),a=s.length;return{ranks:[...o.ranks,...Ft(c=>f=>b(f.id,rt((o.rankSum+a|0)-c|0)))(s)],rankSum:o.rankSum+a|0}})({ranks:[],rankSum:0})(t).ranks),$s=t=>e=>n=>{const r=Xo(Ft(s=>a=>b(a,s))(t)),i=Xo(Ft(s=>a=>b(a,s))(e)),o=xt(s=>{const a=qr(s.from.node)(r),c=qr(s.to.node)(i);if(a.tag==="Just"&&c.tag==="Just")return v("Just",b(a._1,c._1));const f=qr(s.from.node)(i),d=qr(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)(Dt(a+1|0,u-1|0)))(0)(Dt(0,u-2|0))},Ty=t=>e=>n=>r=>{const i=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l>=(d.length-1|0)){c=!1,f=d;continue}if(l>=0&&l<d.length){const _=l+1|0;if(_>=0&&_<d.length){const h=d[l],p=d[_];if(Re(N=>N.before===h&&N.after===p,r)){s=d,a=l+1|0;continue}const m=Xn(Xt,T,l,p,d),y=(()=>{if(m.tag==="Just")return Xn(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($s(e)(x)(n)<$s(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(py(f)(c)){s=!1,a=c;continue}u=f}return a})(t)},Yo=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+$s(i)(t[o])(e)|0}return n})(0)(Dt(0,t.length-2|0)),wy=(()=>{const t=e=>{if(e.length<7){const o=u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=_-1|0;if(h>=0&&h<l.length){if(_>=0&&_<l.length&&_>0&&l[h].key>l[_].key){const p=xy(_-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)(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,p=f;if(h>=0&&h<r.length){if(p>=0&&p<i.length){if(r[h].key>i[p].key){a=Ot(_)(i[p]),c=h,f=p+1|0;continue}a=Ot(_)(r[h]),c=h+1|0,f=p;continue}d=!1,l=[..._,...h<1?r:bt(h,r.length,r)];continue}d=!1,l=[..._,...p<1?i:bt(p,i.length,i)]}return l})([])(0)(0)};return t})(),vy=t=>e=>n=>{const r=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=cr(Xt,T,m=>m===_,f),p=cr(Xt,T,m=>m===l,f);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=Ua(Xt,T,h._1,f),y=(()=>{if(m.tag==="Nothing")return f;if(m.tag==="Just")return m._1;g()})(),x=Va(Xt,T,p._1,_,y);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;g()}return f})(c)(r),o=Hs(Ft(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=Xo(Ft(E=>O=>b(O,E))(m._1)),N=Xo(Ft(E=>O=>b(O,E))(y._1)),w=f?Ny(m._1)(x)(N)(n)(o):Jy(m._1)(x)(N)(n)(o),L=J(E=>O=>{const Y=xt(G=>Mi(G.id)(w))(st(f?G=>G.to.node===O._2&&$o(G.from.node)(x):G=>G.from.node===O._2&&$o(G.to.node)(x),n));if(Y.length===0)return{...E,items:[...E.items,{n:O._2,key:T,origIdx:O._1}]};const et=Ho(24)(E.r);return{items:[...E.items,{n:O._2,key:v("Just",(my(Y)+(rt(et._1)*4172325152040912e-24-.03500000014901161))/rt(Y.length)),origIdx:O._1}],r:et._2}})({items:[],r:_._2})(Ft(Cn)(y._1)),k=Xn(Xt,T,h,Ty(i(W(E=>E.n)(wy((()=>{const E=L.items,O=Y=>et=>{let G=Y,P=et,V=!0,U;for(;V;){const B=G,R=P;if(B>=0&&B<E.length){if(E[B].key.tag==="Just"){V=!1,U=E[B].key._1;continue}if(E[B].key.tag==="Nothing"){G=B+1|0,P=R;continue}g()}V=!1,U=R}return U};return(Y=>et=>G=>{let P=Y,V=et,U=G,B=!0,R;for(;B;){const M=P,S=V,I=U;if(M>=0&&M<E.length){if(E[M].key.tag==="Just"){P=M+1|0,V=E[M].key._1,U=[...I,{n:E[M].n,key:E[M].key._1,origIdx:E[M].origIdx}];continue}if(E[M].key.tag==="Nothing"){const D=(S+O(M+1|0)(S+1))/2;P=M+1|0,V=D,U=[...I,{n:E[M].n,key:D,origIdx:E[M].origIdx}];continue}g()}B=!1,R=I}return R})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(k.tag==="Just")return b(k._1,L.r);if(k.tag==="Nothing")return b(_._1,_._2);g()}if(y.tag==="Nothing")return b(_._1,_._2);g()}if(m.tag==="Nothing")return b(_._1,_._2);g()})(b(c,d))(f?Dt(1,l-1|0):Te(Dt(0,l-2|0)))},s=J(c=>f=>j(C)(f.from.node)()(j(C)(f.to.node)()(c)))(Q)(n),a=J(c=>f=>{if(c.result.crossings===0)return c;const d=x=>N=>w=>L=>{let k=x,E=N,O=w,Y=L,et=!0,G;for(;et;){const P=k,V=E,U=O,B=Y;if(U===0){et=!1,G={layout:P,crossings:0,random:B};continue}const R=u(P,V,B),M=Yo(R._1)(n);if(M<U){k=R._1,E=!V,O=M,Y=R._2;continue}et=!1,G={layout:P,crossings:U,random:R._2}}return G},l=Ho(1)(c.result.random),_=l._1!==0,h=t.modelOrder.tag==="Leaf",p=(c.firstTry||c.secondTry)&&!h?c.firstTry:_,m=(()=>{if(!h){const L=u(e,p,l._2);return d(L._1)(!p)(Yo(L._1)(n))(L._2)}const x=p?0:yy(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 L=st(k=>yf(k)(s),N._1);if(L.length>1){const k=ly(l._2)(L),E=k._1,O=Xn(Xt,T,x,i(J(Y=>et=>yf(et)(s)?Y.idx>=0&&Y.idx<E.length?{idx:Y.idx+1|0,result:[...Y.result,E[Y.idx]]}:{idx:Y.idx,result:[...Y.result,et]}:{idx:Y.idx,result:[...Y.result,et]})({idx:0,result:[]})(N._1).result),e);if(O.tag==="Just"){const Y=u(O._1,p,k._2);return d(Y._1)(!p)(Yo(Y._1)(n))(Y._2)}}}const w=u(e,p,l._2);return d(w._1)(!p)(Yo(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:li(hc(hy(_y(1))._1)(Fi))(Ai)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Dt(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:a.layout},by=t=>t,xf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Qe=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},Hr=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},Oi=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=C.compare(e._1)(n._1);return r==="LT"?Ne:r==="GT"?Je:C.compare(e._2)(n._2)},Eq0:()=>t}})(),ky=jt(C)(zt),Ly=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=Oi.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Ey=by("Greedy"),Xs=t=>e=>n=>J(r=>i=>{if(i.from.node===i.to.node)return r;if(i.from.node===e&&!xf(i.to.node)(r.marks)){const o=Qe(i.to.node)(r.inDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;g()})(),s=j(C)(i.to.node)(u)(r.inDeg);return(()=>{const a=Qe(i.to.node)(r.outDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!Be(fn)(i.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,i.to.node]}:{...r,inDeg:s}}if(i.to.node===e&&!xf(i.from.node)(r.marks)){const o=Qe(i.from.node)(r.outDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;g()})(),s=j(C)(i.from.node)(u)(r.outDeg);return(()=>{const a=Qe(i.from.node)(r.inDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!Be(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),Cy=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return j(C)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return j(C)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return j(C)(e._1.node)(99999)(t)}return t})(Q),Nf=t=>e=>n=>{const r=Qe(e)(t),i=Qe(n)(t);return r.tag==="Just"&&i.tag==="Just"&&r._1>i._1},Jf=t=>e=>n=>r=>{if(Hr(n)(r.visited)||Hr(n)(r.visiting))return r;const i=J(Sy(t)(e)(n))({...r,visiting:j(C)(n)()(r.visiting)})((()=>{const o=Qe(n)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})());return{...i,visiting:ui(C)(n)(i.visiting),visited:j(C)(n)()(i.visited)}},Sy=t=>e=>n=>r=>i=>Nf(t)(n)(i)?{...r,backEdges:j(Oi)(b(n,i))()(r.backEdges)}:Hr(i)(r.visiting)?{...r,backEdges:j(Oi)(b(n,i))()(r.backEdges)}:Hr(i)(r.visited)?r:Jf(t)(e)(i)(r),Gy=t=>e=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,y=Mt(x=>T,x=>N=>v("Just",{head:x,tail:N}),m.sinks);if(y.tag==="Just"){_=Xs(n)(y._1.head)({...m,sinks:y._1.tail,marks:j(C)(y._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(y.tag==="Nothing"){const x=Mt(N=>T,N=>w=>v("Just",{head:N,tail:w}),m.sources);if(x.tag==="Just"){_=Xs(n)(x._1.head)({...m,sources:x._1.tail,marks:j(C)(x._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(x.tag==="Nothing"){const N=L=>{const k=Qe(L)(m.outDeg),E=Qe(L)(m.inDeg);return(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;g()})()-(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;g()})()|0},w=Lt(L=>k=>{const E=it.compare(N(k))(N(L));return E==="EQ"?it.compare((()=>{const O=Qe(L)(e);if(O.tag==="Nothing")return 1e6;if(O.tag==="Just")return O._1;g()})())((()=>{const O=Qe(k)(e);if(O.tag==="Nothing")return 1e6;if(O.tag==="Just")return O._1;g()})()):E})(m.remaining);if(0<w.length){const L=w[0];_=Xs(n)(L)({...m,remaining:st(k=>k!==L,m.remaining),marks:j(C)(L)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}g()}return p},i=br(C.compare)([...W(l=>l.from.node)(n),...W(l=>l.to.node)(n)]),o=st(l=>l.from.node!==l.to.node,n),u=J(l=>_=>vt(C)(ue)(_.to.node)(1)(l))(Q)(o),s=J(l=>_=>vt(C)(ue)(_.from.node)(1)(l))(Q)(o),a=st(l=>{const _=Qe(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),c=st(l=>{const _=Qe(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),f=i.length+1|0,d=J(l=>_=>{const h=Qe(_)(l);return h.tag==="Just"&&h._1<0?j(C)(_)(h._1+f|0)(l):l})(r({remaining:st(l=>!Be(fn)(l)(a)&&!Be(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(Nf(t)(_.from.node)(_.to.node))return j(Oi)(b(_.from.node,_.to.node))()(l);const h=Qe(_.from.node)(d),p=Qe(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?j(Oi)(b(_.from.node,_.to.node))()(l):l})(Q)(n)},Py=J(t=>e=>vt(C)(ee)(e.from.node)([e.to.node])(t))(Q),Iy=t=>e=>{const n=Py(e),r=br(C.compare)([...W(o=>o.from.node)(e),...W(o=>o.to.node)(e)]),i=J(o=>u=>j(C)(u.to.node)()(o))(Q)(e);return J(o=>u=>Jf(t)(n)(u)(o))({visiting:Q,visited:Q,backEdges:Q})([...st(o=>!Hr(o)(i),r),...st(o=>Hr(o)(i),r)]).backEdges},Dy=t=>e=>n=>r=>{const i=ky(Ft(s=>a=>b(a,s))(e)),o=Cy(n),u=(()=>{if(t==="DepthFirst")return Iy(o)(r);if(t==="Greedy")return Gy(o)(i)(r);g()})();return{edges:W(s=>Ly(b(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},Tf=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Qy=J(t=>e=>j(C)(e)()(t))(Q),Vo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Fy=Ag(C),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},wf=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ys=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},Ay=jt(it)(zt),My=t=>e=>Ee(C.compare,ke,t,e),vf=Ft(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),Oy=t=>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=Tf(f)(d._1),s=d._2;continue}g()}return c};return(e.base+r(0)((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,qt("Cons",o._4,i(o._6,u)));g()};return i(n,Ht)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=i=>{if(i.tag==="Leaf")return Q;if(i.tag==="Node")return Wt("Node",i._1,i._2,i._3,i._4+e.base|0,r(i._5),r(i._6));g()};return r(n)})()]}))({base:0,result:[]})(t).result,Ry=t=>e=>{const n=Qy(t);return Fy(t)(vf(st(r=>Vo(r.src)(n)&&Vo(r.tgt)(n),e)))},By=t=>e=>{const n=J(i=>o=>vt(C)(ee)(o.tgt)([o.src])(vt(C)(ee)(o.src)([o.tgt])(i)))(Q)(e),r=i=>o=>u=>{let s=i,a=o,c=u,f=!0,d;for(;f;){const l=s,_=a,h=c,p=Mt(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(Vo(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=j(C)(p._1.head)()(_),c=[...h,p._1.head];continue}g()}return d};return J(i=>o=>{if(Vo(o)(i.visited))return i;const u=r([o])(i.visited)([]);return{...i,visited:J(s=>a=>j(C)(a)()(s))(i.visited)(u.nodes),components:[...i.components,u.nodes]}})({visited:Q,components:[]})(t).components},zy=t=>e=>n=>{const r=J(o=>u=>vt(C)(ue)(u.tgt)(1)(o))(Q)(e),i=J(o=>u=>vt(C)(ue)(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:wf(x.mIn)((()=>{const w=Tn(u)(d),L=Tn(N.src)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;g()})()-(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;g()})()|0})())}:N.src===u?{...x,mOut:wf(x.mOut)((()=>{const w=Tn(N.tgt)(d),L=Tn(u)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._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 p=(f-_|0)+1|0,m=(f+h|0)-1|0;if(m<p)return o;const y=J(x=>N=>{const w=Ys(N)(o.filling),L=(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;g()})();return L<x.bestFill?{best:N,bestFill:L}:x})({best:f,bestFill:(()=>{const x=Ys(f)(o.filling);if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})()})(Dt(p,m));return y.best===f?o:{layers:j(C)(u)(y.best)(o.layers),filling:j(it)(f)((()=>{const x=Ys(f)(o.filling);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;g()})())(j(it)(y.best)(y.bestFill+1|0)(o.filling))}})({layers:n,filling:Ay(W(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=>Tf(o)((()=>{const s=Tn(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(0)(t))))})(t).layers},Wy=t=>e=>zy(t)(vf(e))(J(My)(Q)(Oy(W(n=>Ry(n)(e))(By(t)(e))))),qy=t=>t,Nr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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},Uo=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bf=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Hy=qy("NetworkSimplex"),$y=t=>e=>J(n=>r=>{const i=J(Uo)(0)(xt(o=>Nr(o)(n))(r));return J(o=>u=>j(C)(u)(i)(o))(n)(r)})(e)(t),Xy=t=>e=>({layers:W(n=>st(r=>{const i=Nr(r)(e);return i.tag==="Nothing"?!1:i.tag==="Just"&&i._1===n},t))(Dt(0,(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(c.tag==="Nil"){u=!1,s=a;continue}if(c.tag==="Cons"){i=Uo(a)(c._1),o=c._2;continue}g()}return s})(0)((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return n(e,Ht)})()))),nodeLayer:e}),Yy=t=>e=>n=>{const r=J(i=>o=>j(C)(o)(!0)(i))(Q)(e);return J(i=>o=>j(C)(o._1)(o._2)(i))(Wy(e)(xt(i=>i.from.node===i.to.node||(()=>{const o=Nr(i.from.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()||(()=>{const o=Nr(i.to.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()?T:v("Just",{src:i.from.node,tgt:i.to.node}))(t)))(bf(n))},Vy=t=>e=>n=>r=>{const i=s=>a=>{const c=Nr(a)(s);if(c.tag==="Just")return s;if(c.tag==="Nothing"){const f=st(l=>l!==a,(()=>{const l=Nr(a)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;g()})()),d=J(i)(s)(f);return j(C)(a)(1+J(Uo)(0)(xt(l=>Nr(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=Uo(_)(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=>j(C)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return Q;if(a.tag==="Node")return Wt("Node",a._1,a._2,a._3,u-a._4|0,s(a._5),s(a._6));g()};return s(o)})())(bf(r))},Uy=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return j(C)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return j(C)(e._1.node)(0)(t)}return t})(Q),Zy=J(t=>e=>vt(C)(ee)(e.to.node)([e.from.node])(t))(Q),Ky=J(t=>e=>vt(C)(ee)(e.from.node)([e.to.node])(t))(Q),jy=t=>e=>n=>r=>{const i=Ky(n),o=Zy(n),u=Uy(e);return Xy(r)($y(xt(s=>s.tag==="SameLayer"?v("Just",s._1.nodes):T)(e))((()=>{if(t==="LongestPath")return Vy(i)(o)(r)(u);if(t==="NetworkSimplex")return Yy(n)(r)(u);g()})()))},tx=jt(C)(zt),ex=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},kf=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()},Ri=jt(C)(zt),nx=jt(C)(zt),Ef=(()=>{const t=W(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>Te(t(e))})(),rx=t=>e=>n=>r=>{const i=tx(W(u=>b(u.edge,u))(r)),o=u=>0<u.nodes.length&&(()=>{const s=ex(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return W(u=>{if(u.nodes.length<=2){const f=kf(u.edgeId)(i);if(f.tag==="Just"){const d=o(u),l=Pi(Gi(d?Ef(f._1.segments):f._1.segments));return{...f._1,edge:u.edgeId,segments:l,bends:we(_=>h=>_.end,l,bt(1,l.length,l)),reversed:d}}if(f.tag==="Nothing")return{edge:u.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};g()}const s=Tt(xt(f=>kf(f)(i))(we(f=>d=>u.edgeId+":"+f+"->"+d,u.nodes,bt(1,u.nodes.length,u.nodes))))(f=>f.segments),a=o(u),c=Pi(Gi(a?Ef(s):s));return{edge:u.edgeId,segments:c,bends:we(f=>d=>f.end,c,bt(1,c.length,c)),bendType:[],jumps:[],reversed:a}})(t)},ix={layers:[],edges:[],chains:[]},ox={nodeGap:3,layerGap:2,iterations:8,layerer:Hy,cycleBreaker:Ey,compactPostRouting:!0,compactionSpacings:Zm},ux=t=>({pos:b(0,0),size:b(J(e=>n=>Lf(e)(n.position._1+n.size._1))(0)(t),J(e=>n=>Lf(e)(n.position._2+n.size._2))(0)(t))}),sx=t=>e=>n=>{const r=Ri(W(c=>b(c.id,c.ports))(e.nodes)),i=st(c=>me(3)(c.node)!=="$d:",n.placements),o=rx(n.withDummies.chains)(n.acyclic.reversedEdges)(nx(W(c=>b(c.id,b(c.from.node,c.to.node)))(e.edges)))(P2(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(of(n.ordered)(st(c=>c.from.node!==c.to.node,n.withDummies.edges))((()=>{const c=f=>{if(f.tag==="Leaf")return Q;if(f.tag==="Node")return Wt("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(W(f=>b(f.id,f.size))(e.nodes)))})()))),u=t.compactPostRouting?t2()(t.compactionSpacings)({nodes:i,edges:e.edges,paths:o,ports:r}):{nodes:i,edges:o},s=W(c=>{const f=Pi(Gi(c.segments));return{...c,segments:f,bends:we(d=>l=>d.end,f,bt(1,f.length,f))}})(u.edges),a=Ft(c=>f=>({...f,jumps:O2(c)(f)(s)}))(s);return{nodes:u.nodes,edges:a,boundingBox:ux(u.nodes),metrics:kp(u.nodes)(a)(0)}},ax=t=>e=>n=>{const r=Ri(W(o=>b(o.id,o.size))(e.nodes)),i={...n,placements:fy({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(Ri(W(o=>b(o.id,o.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(of(n.ordered)(n.withDummies.edges)((()=>{const o=u=>{if(u.tag==="Leaf")return Q;if(u.tag==="Node")return Wt("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:sx(t)(e)(i)}},cx=t=>e=>n=>ax(t)(e)({...n,ordered:vy({iterations:t.iterations,constraints:e.constraints,modelOrder:Ri(Ft(r=>i=>b(i.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),gx=t=>e=>n=>cx(t)(e)({...n,withDummies:R2(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),fx=t=>e=>{const n=W(i=>i.id)(e.nodes),r=Dy(t.cycleBreaker)(n)(e.constraints)(e.edges);return gx(t)(e)({acyclic:r,layered:jy(t.layerer)(e.constraints)(r.edges)(n),withDummies:ix,ordered:[],placements:[]})},Zo=t=>t,_x=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Vs=Zo("TopSide"),Us=Zo("BottomSide"),Zs=Zo("LeftSide"),Ks=Zo("RightSide"),dx=t=>{const e=ut.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ut.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Cf=t=>e=>n=>{const r=_x(t.h*.12)(t.w*.2),i=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*Le(dx((()=>{const o=(n-(t.x+i))/i;return 1-o*o})()))},ir=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=Cf(d)(-1)(_);continue}if(l==="BottomSide"){a=!1,c=Cf(d)(1)(_);continue}if(l==="LeftSide"){a=!1,c=d.x;continue}if(l==="RightSide"){a=!1,c=d.x+d.w;continue}}i=jn,o=d,u=l,s=_}return c},Sf=t=>e=>{const n=e.y-t.y,r=n<0?-n:n,i=e.x-(t.x+t.w),o=i<0?-i:i,u=e.x-t.x,s=u<0?-u:u,a=e.y-(t.y+t.h),c=a<0?-a:a;return r<=c&&r<=s&&r<=o?Vs:c<=s&&c<=o?Us:s<=o?Zs:Ks},js=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},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=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},lx=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),zi=jt(C)(zt),hx=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},px=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=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},mx=J(t=>e=>j(C)(e)()(t))(Q),yx=J(t=>e=>j(C)(e)()(t))(Q),Ko=ar.traverse(vu),jo=jt(C)(zt),xx=t=>e=>Ee(C.compare,ke,t,e),Nx=J(t=>e=>j(C)(e)()(t))(Q),Jx=jt(C)(zt),Tx=t=>e=>Ee(C.compare,ke,t,e),wx=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},Gf=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},vx=t=>e=>({...e,edges:zi(W(n=>b(n._1,(()=>{const r=js(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=Mt(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=Sf(a)(s._1.head);return[(()=>{if(c==="TopSide")return{...s._1.head,y:ir(o._1.shape)(a)(Vs)(s._1.head.x)};if(c==="BottomSide")return{...s._1.head,y:ir(o._1.shape)(a)(Us)(s._1.head.x)};if(c==="LeftSide")return{...s._1.head,x:ir(o._1.shape)(a)(Zs)(s._1.head.y)};if(c==="RightSide")return{...s._1.head,x:ir(o._1.shape)(a)(Ks)(s._1.head.y)};g()})(),...s._1.tail]}}g()})();if(i.tag==="Nothing")return u;if(i.tag==="Just"){const s=ii(u);if(s.tag==="Nothing")return u;if(s.tag==="Just")return Ot(s._1.init)((()=>{const a={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},c=Sf(a)(s._1.last);if(c==="TopSide")return{...s._1.last,y:ir(i._1.shape)(a)(Vs)(s._1.last.x)};if(c==="BottomSide")return{...s._1.last,y:ir(i._1.shape)(a)(Us)(s._1.last.x)};if(c==="LeftSide")return{...s._1.last,x:ir(i._1.shape)(a)(Zs)(s._1.last.y)};if(c==="RightSide")return{...s._1.last,x:ir(i._1.shape)(a)(Ks)(s._1.last.y)};g()})())}}g()})()))(lx(e.edges)))}),bx=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 js(n)(e);g()},kx=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()})()}),Lx=t=>({id:t,size:b(1,1),ports:[],label:v("Just",t),shape:jn}),Ex=t=>e=>n=>r=>b(r.node,kx(t)(e)(n)(r)),Pf=t=>{const e=yo(`
|
|
6
|
-
`)(t);return e.length===0?[""]:e},If=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,qt("Cons",n._4,e(n._6,r)));g()};return Ct($t.foldr,e(t.interiors,Ht))},Cx=t=>zi(xt(e=>v("Just",b(e.edge,{id:e.edge,from:{node:e.from,port:T},to:{node:e.to,port:T},label:T})))(Tt(t.scenes)(e=>e.tag==="DataFlow"?xt(n=>n.kind.tag==="SendToken"?v("Just",n.kind._1):T)(e._1.events):[]))),Df=t=>{const e=Hl(t),n=st(i=>hx(i.id)(e.nodes),t.graph.nodes),r=st(i=>px(i.id)(e.edges),t.graph.edges);return{nodes:[...n,...W(Lx)(Ct(We.foldr,Sn(C.compare,e.nodes,mx(W(i=>i.id)(n)))))],edges:[...r,...xt(bx(t)(Cx(t)))(Ct(We.foldr,Sn(C.compare,e.edges,yx(W(i=>i.id)(r)))))],constraints:t.graph.constraints}},Sx=t=>{const e=Ko(n=>{const r=_g(dg)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})());return()=>{const i=r();return b(n.id,i)}})(Df(t).nodes);return()=>{const n=e();return jo(n)}},Qf=t=>{const e=Sx(t);return()=>{const n=e(),r=Ko(Qf)(If(t))();return J(xx)(n)(r)}},Gx=t=>e=>{const n=Mt(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},...W(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];g()},Px=t=>e=>b(e.edge,Gx(t)(e)),Ix=t=>e=>n=>r=>({nodes:jo(W(Ex(rt(4)*t)(e)(n))(r.nodes)),edges:zi(W(Px(t))(r.edges)),chipExtras:Q,edgeLabels:Q}),Dx=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=>j(C)(u)()(o))(r)(i.kind._1.labels);if(i.kind.tag==="FillNodeWithoutTransition")return J(o=>u=>j(C)(u)()(o))(r)(i.kind._1.labels);g()})(e)(n._1.events);if(n.tag==="Hold"||n.tag==="EnterNode"||n.tag==="ExitNode")return e;g()})(Q)(t.scenes),Qx=t=>{const e=Ko(n=>{const r=_g(dg)(n);return()=>{const i=r();return b(n,{labelW:i,charCount:Kn(Ar(n)),lineCount:1})}})(Ct(We.foldr,Nx(Tt(Ct(We.foldr,Dx(t)))(Pf))));return()=>{const n=e();return Jx(n)}},Ff=t=>{const e=Qx(t);return()=>{const n=e(),r=Ko(Ff)(If(t))();return J(Tx)(n)(r)}},Fx=rt(4)*8,Ax=t=>e=>{const n=wp(Fx)(t)(Tp(Jp)(Df(e)));return{...vx(zi(W(r=>b(r.id,b(r.from.node,r.to.node)))(n.edges)))(Ix(8)(jo(W(r=>b(r.id,(()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;g()})()))(n.nodes)))(jo(W(r=>b(r.id,r.shape))(n.nodes)))(fx(ox)(n).result)),edgeLabels:zi(xt(r=>r.label.tag==="Just"?v("Just",b(r.id,r.label._1)):T)(n.edges))}},Mx=t=>Tt(t.scenes)(e=>{if(e.tag==="Structural")return[];if(e.tag==="DataFlow")return e._1.events;if(e.tag==="Hold")return[];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()}),Ox=t=>e=>n=>{const r=i=>{const o=xt(u=>{const s=wx(u)(t);return s.tag==="Just"?v("Just",{w:s._1.labelW+28,h:rt(pp(1)(s._1.lineCount))*13.2+12}):T})(Tt(i)(Pf));return o.length===0?T:v("Just",{w:J(Gf)(0)(W(u=>u.w)(o)),h:J(Gf)(0)(W(u=>u.h)(o))})};return J(i=>o=>{if(o.kind.tag==="SendToken"){const u=js(o.kind._1.edge)(n.edges),s=r(o.kind._1.labels);if(s.tag==="Just"&&u.tag==="Just"){const a=s._1;return vt(C)(ee)(o.kind._1.edge)(W(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(C)(ee)("__fill__:"+o.kind._1.node)((()=>{const a=u._1.y-s._1.h-14,c=u._1.x+u._1.w/2,f=c-s._1.w/2,d=c+s._1.w/2,l=u._1.y-14;return[{x:f,y:a},{x:d,y:a},{x:f,y:l},{x:d,y:l}]})())(i):i}g()})(Q)(Mx(e))},Af=t=>e=>n=>({layout:(()=>{const r=Ax(t)(n);return{...r,chipExtras:Ox(e)(n)(r)}})(),interiors:(()=>{const r=Af(t)(e),i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Wt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(n.interiors)})()}),Mf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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},ta=t=>e=>n=>{const r=t<.05?t:.05,i=(u,s)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return i((()=>{const a=Mf(s._3)(n),c=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return{x:s._4.x,y:s._4.y,vx:0,vy:0};g()})(),f=c.vx+(180*(s._4.x-c.x)-22*c.vx)*r,d=c.vy+(180*(s._4.y-c.y)-22*c.vy)*r;return j(C)(s._3)({x:c.x+f*r,y:c.y+d*r,vx:f,vy:d})(i(u,s._5))})(),s._6);g()},o=i(Q,e);return{springs:o,applied:(()=>{const u=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return u((()=>{const c=u(s,a._5),f=Mf(a._3)(o);if(f.tag==="Just")return j(C)(a._3)({...a._4,x:f._1.x,y:f._1.y})(c);if(f.tag==="Nothing")return j(C)(a._3)(a._4)(c);g()})(),a._6);g()};return u(Q,e)})()}};(function(){var t={},e="Pure",n="Throw",r="Catch",i="Sync",o="Async",u="Bind",s="Bracket",a="Fork",c="Sequential",f="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",y="Finalized",x="Forked";function N(A,H,$,X){this.tag=A,this._1=H,this._2=$,this._3=X}function w(A){var H=function($,X,q){return new N(A,$,X,q)};return H.tag=A,H}function L(A){return new N(e,void 0)}function k(A){try{A()}catch(H){setTimeout(function(){throw H},0)}}function E(A,H,$){try{return H($())}catch(X){return A(X)}}function O(A,H,$){try{return H($)()}catch(X){return $(A(X))(),L}}var Y=(function(){var A=1024,H=0,$=0,X=new Array(A),q=!1;function z(){var tt;for(q=!0;H!==0;)H--,tt=X[$],X[$]=void 0,$=($+1)%A,tt();q=!1}return{isDraining:function(){return q},enqueue:function(tt){var Z;H===A&&(Z=q,z(),q=Z),X[($+H)%A]=tt,H++,q||z()}}})();function et(A){var H={},$=0,X=0;return{register:function(q){var z=$++;q.onComplete({rethrow:!0,handler:function(tt){return function(){X--,delete H[z]}}})(),H[z]=q,X++},isEmpty:function(){return X===0},killAll:function(q,z){return function(){if(X===0)return z();var tt=0,Z={};function ct(at){Z[at]=H[at].kill(q,function(yt){return function(){delete Z[at],tt--,A.isLeft(yt)&&A.fromLeft(yt)&&setTimeout(function(){throw A.fromLeft(yt)},0),tt===0&&z()}})()}for(var ft in H)H.hasOwnProperty(ft)&&(tt++,ct(ft));return H={},$=0,X=0,function(at){return new N(i,function(){for(var yt in Z)Z.hasOwnProperty(yt)&&Z[yt]()})}}}}}var G=0,P=1,V=2,U=3,B=4,R=5,M=6;function S(A,H,$){var X=0,q=G,z=$,tt=null,Z=null,ct=null,ft=null,at=null,yt=0,St=0,Rt=null,pt=!0;function Bt(K){for(var nt,ht,_t;;)switch(nt=null,ht=null,_t=null,q){case V:q=P;try{z=ct(z),ft===null?ct=null:(ct=ft._1,ft=ft._2)}catch(wt){q=R,tt=A.left(wt),z=null}break;case U:A.isLeft(z)?(q=R,tt=z,z=null):ct===null?q=R:(q=V,z=A.fromRight(z));break;case P:switch(z.tag){case u:ct&&(ft=new N(_,ct,ft)),ct=z._2,q=P,z=z._1;break;case e:ct===null?(q=R,z=A.right(z._1)):(q=V,z=z._1);break;case i:q=U,z=E(A.left,A.right,z._1);break;case o:q=B,z=O(A.left,z._1,function(wt){return function(){X===K&&(X++,Y.enqueue(function(){X===K+1&&(q=U,z=wt,Bt(X))}))}});return;case n:q=R,tt=A.left(z._1),z=null;break;case r:ct===null?at=new N(_,z,at,Z):at=new N(_,z,new N(_,new N(h,ct,ft),at,Z),Z),ct=null,ft=null,q=P,z=z._1;break;case s:yt++,ct===null?at=new N(_,z,at,Z):at=new N(_,z,new N(_,new N(h,ct,ft),at,Z),Z),ct=null,ft=null,q=P,z=z._1;break;case a:q=U,nt=S(A,H,z._2),H&&H.register(nt),z._1&&nt.run(),z=A.right(nt);break;case c:q=P,z=D(A,H,z._1);break}break;case R:if(ct=null,ft=null,at===null)q=M,z=Z||tt||z;else switch(nt=at._3,_t=at._1,at=at._2,_t.tag){case r:Z&&Z!==nt&&yt===0?q=R:tt&&(q=P,z=_t._2(A.fromLeft(tt)),tt=null);break;case h:Z&&Z!==nt&&yt===0||tt?q=R:(ct=_t._1,ft=_t._2,q=V,z=A.fromRight(z));break;case s:yt--,tt===null&&(ht=A.fromRight(z),at=new N(_,new N(p,_t._2,ht),at,nt),(Z===nt||yt>0)&&(q=P,z=_t._3(ht)));break;case p:at=new N(_,new N(y,z,tt),at,Z),q=P,Z&&Z!==nt&&yt===0?z=_t._1.killed(A.fromLeft(Z))(_t._2):tt?z=_t._1.failed(A.fromLeft(tt))(_t._2):z=_t._1.completed(A.fromRight(z))(_t._2),tt=null,yt++;break;case m:yt++,at=new N(_,new N(y,z,tt),at,Z),q=P,z=_t._1;break;case y:yt--,q=R,z=_t._1,tt=_t._2;break}break;case M:for(var Nt in Rt)Rt.hasOwnProperty(Nt)&&(pt=pt&&Rt[Nt].rethrow,k(Rt[Nt].handler(z)));Rt=null,Z&&tt?setTimeout(function(){throw A.fromLeft(tt)},0):A.isLeft(z)&&pt&&setTimeout(function(){if(pt)throw A.fromLeft(z)},0);return;case G:q=P;break;case B:return}}function Jt(K){return function(){if(q===M)return pt=pt&&K.rethrow,K.handler(z)(),function(){};var nt=St++;return Rt=Rt||{},Rt[nt]=K,function(){Rt!==null&&delete Rt[nt]}}}function mt(K,nt){return function(){if(q===M)return nt(A.right(void 0))(),function(){};var ht=Jt({rethrow:!1,handler:function(){return nt(A.right(void 0))}})();switch(q){case G:Z=A.left(K),q=M,z=Z,Bt(X);break;case B:Z===null&&(Z=A.left(K)),yt===0&&(q===B&&(at=new N(_,new N(m,z(K)),at,Z)),q=R,z=null,tt=null,Bt(++X));break;default:Z===null&&(Z=A.left(K)),yt===0&&(q=R,z=null,tt=null)}return ht}}function gt(K){return function(){var nt=Jt({rethrow:!1,handler:K})();return q===G&&Bt(X),nt}}return{kill:mt,join:gt,onComplete:Jt,isSuspended:function(){return q===G},run:function(){q===G&&(Y.isDraining()?Bt(X):Y.enqueue(function(){Bt(X)}))}}}function I(A,H,$,X){var q=0,z={},tt=0,Z={},ct=new Error("[ParAff] Early exit"),ft=null,at=t;function yt(Jt,mt,gt){var K=mt,nt=null,ht=null,_t=0,Nt={},wt,Kt;t:for(;;)switch(wt=null,K.tag){case x:if(K._3===t&&(wt=z[K._1],Nt[_t++]=wt.kill(Jt,function(Se){return function(){_t--,_t===0&>(Se)()}})),nt===null)break t;K=nt._2,ht===null?nt=null:(nt=ht._1,ht=ht._2);break;case f:K=K._2;break;case d:case l:nt&&(ht=new N(_,nt,ht)),nt=K,K=K._1;break}if(_t===0)gt(A.right(void 0))();else for(Kt=0,wt=_t;Kt<wt;Kt++)Nt[Kt]=Nt[Kt]();return Nt}function St(Jt,mt,gt){var K,nt,ht,_t,Nt,wt;for(A.isLeft(Jt)?(K=Jt,nt=null):(nt=Jt,K=null);;){if(ht=null,_t=null,Nt=null,wt=null,ft!==null)return;if(mt===null){X(K||nt)();return}if(mt._3!==t)return;switch(mt.tag){case f:K===null?(mt._3=A.right(mt._1(A.fromRight(nt))),nt=mt._3):mt._3=K;break;case d:if(ht=mt._1._3,_t=mt._2._3,K){if(mt._3=K,Nt=!0,wt=tt++,Z[wt]=yt(ct,K===ht?mt._2:mt._1,function(){return function(){delete Z[wt],Nt?Nt=!1:gt===null?St(K,null,null):St(K,gt._1,gt._2)}}),Nt){Nt=!1;return}}else{if(ht===t||_t===t)return;nt=A.right(A.fromRight(ht)(A.fromRight(_t))),mt._3=nt}break;case l:if(ht=mt._1._3,_t=mt._2._3,ht===t&&A.isLeft(_t)||_t===t&&A.isLeft(ht))return;if(ht!==t&&A.isLeft(ht)&&_t!==t&&A.isLeft(_t))K=nt===ht?_t:ht,nt=null,mt._3=K;else if(mt._3=nt,Nt=!0,wt=tt++,Z[wt]=yt(ct,nt===ht?mt._2:mt._1,function(){return function(){delete Z[wt],Nt?Nt=!1:gt===null?St(nt,null,null):St(nt,gt._1,gt._2)}}),Nt){Nt=!1;return}break}gt===null?mt=null:(mt=gt._1,gt=gt._2)}}function Rt(Jt){return function(mt){return function(){delete z[Jt._1],Jt._3=mt,St(mt,Jt._2._1,Jt._2._2)}}}function pt(){var Jt=P,mt=$,gt=null,K=null,nt,ht;t:for(;;)switch(nt=null,ht=null,Jt){case P:switch(mt.tag){case f:gt&&(K=new N(_,gt,K)),gt=new N(f,mt._1,t,t),mt=mt._2;break;case d:gt&&(K=new N(_,gt,K)),gt=new N(d,t,mt._2,t),mt=mt._1;break;case l:gt&&(K=new N(_,gt,K)),gt=new N(l,t,mt._2,t),mt=mt._1;break;default:ht=q++,Jt=R,nt=mt,mt=new N(x,ht,new N(_,gt,K),t),nt=S(A,H,nt),nt.onComplete({rethrow:!1,handler:Rt(mt)})(),z[ht]=nt,H&&H.register(nt)}break;case R:if(gt===null)break t;gt._1===t?(gt._1=mt,Jt=P,mt=gt._2,gt._2=t):(gt._2=mt,mt=gt,K===null?gt=null:(gt=K._1,K=K._2))}for(at=mt,ht=0;ht<q;ht++)z[ht].run()}function Bt(Jt,mt){ft=A.left(Jt);var gt;for(var K in Z)if(Z.hasOwnProperty(K)){gt=Z[K];for(K in gt)gt.hasOwnProperty(K)&>[K]()}Z=null;var nt=yt(Jt,at,mt);return function(ht){return new N(o,function(_t){return function(){for(var Nt in nt)nt.hasOwnProperty(Nt)&&nt[Nt]();return L}})}}return pt(),function(Jt){return new N(o,function(mt){return function(){return Bt(Jt,mt)}})}}function D(A,H,$){return new N(o,function(X){return function(){return I(A,H,$,X)}})}return N.EMPTY=t,N.Pure=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=S,N.Supervisor=et,N.Scheduler=Y,N.nonCanceler=L,N})();let Of=null;function Rx(){return Of||(typeof document>"u"?null:Of=document.createElement("canvas").getContext("2d"))}const ea=new Map;function Rf(t,e,n,r,i,o){const u=`${n} ${e}px ${t}`,s=u+"|"+r;if(ea.has(s))return ea.get(s);const a=Rx();if(!a)return o;a.font=u;const c=i(a.measureText(r)),f=typeof document<"u"?document.fonts:null;if(!f||f.check(u))ea.set(s,c);else if(f&&f.load)try{f.load(u)}catch{}return c}const Bx=(t,e,n,r)=>Rf(t,e,n,r,i=>i.width,-1),zx=(t,e,n,r)=>Rf(t,e,n,r,i=>({ascent:i.actualBoundingBoxAscent,descent:i.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),Bf=t=>e=>{const n=Bx(t.family,t.size,t.weight,Ar(e));return n<0?rt(Jo(e).length)*t.size*.62:n},zf=t=>e=>{const n=zx(t.family,t.size,t.weight,Ar(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},Wf=t=>t,qf=t=>t,tu=t=>t,Hf=t=>t,Wx=t=>t,$f=t=>t,Xf=t=>t,qx=Xf("BaselineTop"),or=Xf("BaselineMiddle"),na=$f("AlignLeft"),$r=$f("AlignCenter"),ve=Wx("RoundJoin"),_n=Hf("ButtCap"),wn=Hf("RoundCap"),Hx=tu("LayerPolyOut"),$x=tu("LayerPolyIn"),Xx=tu("LayerNodeMask"),Yx=tu("LayerOverlay"),eu=qf("NonZero"),Vx=qf("EvenOdd"),Yf=Wf("Normal"),nu=Wf("Difference"),ie={r:255,g:255,b:255,a:255},An={r:26,g:26,b:26,a:255},Ux=t=>t,Vf=t=>t,Zx=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},on=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Uf=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},ra=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Kx=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()},jx=Vf("FlatLevel"),tN=Vf("NestedLevel"),Zf=Ux("GenieSilhouette"),eN=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const i=Dr(t);return{prng:i.prng,yLift:i.value*n.yJitter*r}},nN=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const i=Dr(t);return{prng:i.prng,dx:(i.value*2-1)*n.xJitter*r}},Kf=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,i=Le(r*r+n*n),o=(t.r*t.r-e.r*e.r+i*i)/(2*i),u=Le(Zx(0)(t.r*t.r-o*o)),s=t.cx+o*r/i,a=t.cy+o*n/i,c={x:s-u*n/i,y:a+u*r/i},f={x:s+u*n/i,y:a-u*r/i};return i===0||i>t.r+e.r?{x:(t.cx+e.cx)/2,y:t.cy}:c.y<f.y?c:f},rN=t=>e=>{const n=on(e)(on(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},iN=t=>e=>n=>r=>i=>o=>{if(e)return{prng:t,r:i};if(n)return{prng:t,r:i*(1+o.rJitter)};if(r)return{prng:t,r:i*o.smallScale};const u=Dr(t);return{prng:u.prng,r:i*(1+u.value*o.rJitter)}},jf=t=>{const e=on(t.w)(t.h)/2;return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,4,t.x+t.w-e+.5522847498307936*e,t.y,t.x+t.w,t.y+e-.5522847498307936*e,t.x+t.w,t.y+e,4,t.x+t.w,t.y+e+.5522847498307936*e,t.x+t.w-e+.5522847498307936*e,t.y+t.h,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,4,t.x+e-.5522847498307936*e,t.y+t.h,t.x,t.y+e+.5522847498307936*e,t.x,t.y+e,4,t.x,t.y+e-.5522847498307936*e,t.x+e-.5522847498307936*e,t.y,t.x+e,t.y,5]},oN=t=>e=>n=>{const r=Dr(t),i=e.length;return i===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const o=Uf(0)(i-1|0)(de(ln(r.value*rt(n))));return o>=0&&o<e.length?e[o]:-1})()}},uN=t=>e=>{const n=Dr(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const i=Uf(0)(r-1|0)(de(ln(n.value*rt(r))));return i>=0&&i<e.length?e[i]:-1})()}},t_=t=>{const e=on(t.w*.18)(t.h*.6);return[1,t.x+e,t.y,2,t.x+t.w,t.y,2,t.x+t.w-e,t.y+t.h,2,t.x,t.y+t.h,5]},e_=t=>[1,t.x,t.y,2,t.x+t.w,t.y,2,t.x+t.w,t.y+t.h*.85,4,t.x+t.w*.66,t.y+t.h*1.05,t.x+t.w*.34,t.y+t.h*.65,t.x,t.y+t.h*.85,5],n_={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},sN=t=>{const e=on(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,i=t.x+n;return[1,t.x,r,4,t.x,r+.5522847498*e,i-.5522847498*n,r+e,i,r+e,4,i+.5522847498*n,r+e,t.x+t.w,r+.5522847498*e,t.x+t.w,r]},r_=t=>{const e=on(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+t.h+5,i=t.y+e,o=r-e,u=t.x+n;return[1,t.x,i,4,t.x,i-.5522847498*e,u-.5522847498*n,t.y,u,t.y,4,u+.5522847498*n,t.y,t.x+t.w,i-.5522847498*e,t.x+t.w,i,2,t.x+t.w,o,4,t.x+t.w,o+.5522847498*e,u+.5522847498*n,r,u,r,4,u-.5522847498*n,r,t.x,o+.5522847498*e,t.x,o,5]},i_=t=>e=>{const n=e.y+e.h,r=xd(t.rBase*e.h)(e.w/(2*(1+(rt(t.minN)-1)*t.stepRatio))),i=e.w-2*r,o=2*r*t.stepRatio,u=ra(t.minN)(i<=0||o<=0?t.minN:de(Vn(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=uN(t.seed)((()=>{const m=a-c|0;return m<1?s:bt(m,s.length,s)})()),l=d.idx,_=oN(d.prng)(st(m=>m!==l,f))(ra(1)(f.length-(Be(vr)(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),L=iN(m.prng)(w)(N)(x)(r)(t),k=eN(L.prng)(w)(t)(e.h),E=nN(k.prng)(w)(t)(p);return{prng:E.prng,circles:Ot(m.circles)({cx:e.x+Kx(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*p:x?-1*t.smallShift*p:0)),cy:n-k.yLift,r:L.r})}})({prng:_.prng,circles:[]})(Dt(0,u-1|0)).circles},o_=t=>e=>{const n=t.length;return Ft(r=>i=>({c:i,p1:(()=>{if(r===0)return{x:i.cx-i.r,y:e};const o=r-1|0;return o>=0&&o<t.length?Kf(t[o])(i):{x:i.cx-i.r,y:e}})(),p2:(()=>{if(r===(n-1|0))return{x:i.cx+i.r,y:e};const o=r+1|0;return o>=0&&o<t.length?Kf(i)(t[o]):{x:i.cx+i.r,y:e}})()}))(t)},u_=t=>{const e=on(t.h*.4)(t.w*.2);return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,2,t.x+t.w,t.y+t.h/2,2,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,2,t.x,t.y+t.h/2,5]},aN=t=>e=>n=>{const r=fr(e.y-t.cy)(e.x-t.cx),i=fr(n.y-t.cy)(n.x-t.cx),o=i>r?i-r:i+6.283185307179586-r,u=ra(1)(de(eo(o/1.5707963267948966))),s=o/rt(u),a=1.3333333333333333*Nd(s/4);return Tt(Dt(0,u-1|0))(c=>{const f=r+rt(c+1|0)*s,d=t.cx+t.r*en(f),l=t.cy+t.r*He(f),_=r+rt(c)*s;return[4,t.cx+t.r*en(_)-a*t.r*He(_),t.cy+t.r*He(_)+a*t.r*en(_),d+a*t.r*He(f),l-a*t.r*en(f),d,l]})},s_=t=>e=>{const n=t.h*.38,r=o_(i_(n_)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),i=on(e)(on(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...Tt(r)(o=>aN(o.c)(o.p1)(o.p2)),2,t.x+t.w,t.y+t.h-i,3,t.x+t.w,t.y+t.h,t.x+t.w-i,t.y+t.h,2,t.x+i,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-i,2,r[0].p1.x,r[0].p1.y,5]:rN(t)(e)},a_=t=>e=>n=>r=>i=>o=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(i)(o);if(e==="Cylinder"){const u=r_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Parallelogram"){const u=t_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Diamond"){const u=u_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Ellipse"){const u=jf(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Document"){const u=e_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Cloud"){const u=s_(n)(r);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}return t.drawRoundedRect(n)(r)(i)(o)},cN=t=>()=>t.clip("evenodd"),gN=t=>e=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(e.tile,.001))),r=Math.max(2,Math.round(e.tile*n)),i=document.createElement("canvas");i.width=r,i.height=r;const o=i.getContext("2d");o.scale(n,n),o.fillStyle=e.bgCss,o.fillRect(0,0,e.tile,e.tile),o.fillStyle=e.dotCss,o.beginPath(),o.arc(e.tile/2,e.tile/2,e.dotR,0,2*Math.PI),o.fill();const u=t.createPattern(i,"repeat");u&&typeof u.setTransform=="function"&&u.setTransform(new DOMMatrix().scaleSelf(1/n,1/n)),t.save(),t.fillStyle=u,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},ia=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},oa=t=>e=>n=>{const r=e.stroke;return()=>{const i=r.value,o=Hd(t)(n);if(i!==n)return o(),e.stroke.value=n}},fN=t=>e=>n=>{const r=e.font;return()=>{const i=r.value,o=tl(t)(n);if(i!==n)return o(),e.font.value=n}},Wi=t=>e=>n=>{const r=e.fill;return()=>{const i=r.value,o=qd(t)(n);if(i!==n)return o(),e.fill.value=n}},ru=t=>e=>{const n=e.length,r=o=>{if(o>=n)return()=>{};const u=o>=0&&o<e.length?e[o]:0;if(u===1){const s=cc(t)((()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===2){const s=gi(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=fi(t)({cpx:(()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})(),cpy:(()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=o+3|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=o+4|0;return c>=0&&c<e.length?e[c]:0})()}),a=r(o+5|0);return()=>(s(),a())}if(u===4){const s=nl(t)({cp1x:(()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})(),cp1y:(()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})(),cp2x:(()=>{const c=o+3|0;return c>=0&&c<e.length?e[c]:0})(),cp2y:(()=>{const c=o+4|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=o+5|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=o+6|0;return c>=0&&c<e.length?e[c]:0})()}),a=r(o+7|0);return()=>(s(),a())}if(u===5){const s=gc(t),a=r(o+1|0);return()=>(s(),a())}return()=>{}},i=ac(t);return()=>(i(),r(0)())},_N=t=>e=>n=>r=>i=>o=>{const u=ia(o)(ia(r/2)(i/2)),s=cc(t)(e+u)(n);return()=>(s(),gi(t)(e+r-u)(n)(),fi(t)({cpx:e+r,cpy:n,x:e+r,y:n+u})(),gi(t)(e+r)(n+i-u)(),fi(t)({cpx:e+r,cpy:n+i,x:e+r-u,y:n+i})(),gi(t)(e+u)(n+i)(),fi(t)({cpx:e,cpy:n+i,x:e,y:n+i-u})(),gi(t)(e)(n+u)(),fi(t)({cpx:e,cpy:n,x:e+u,y:n})(),gc(t)())},dN=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),lN=t=>e=>{const n=Ud(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=dN();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0}}}},hN={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},pN=t=>oe(t.weight)+" "+Oa(t.size)+"px "+t.family,vn=t=>{const e=Oa(rt(t.a)/255);return t.a>=255?"rgb("+oe(t.r)+","+oe(t.g)+","+oe(t.b)+")":"rgba("+oe(t.r)+","+oe(t.g)+","+oe(t.b)+","+e+")"},mN=t=>e=>n=>r=>{const i=Wi(t)(n)(vn(r));return()=>(i(),Vd(t)({x:0,y:0,width:e.width,height:e.height})())},yN=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",gN(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:vn(n.bgColor),dotCss:vn(n.dotColor),tile:n.tile,dotR:n.dotRadius})())},xN=t=>e=>n=>r=>{const i=Wi(t)(e)(vn(r));return()=>(i(),ru(t)(n)(),Qu(t)())},NN=t=>e=>n=>r=>i=>{const o=Wi(t)(e)(vn(r));return()=>(o(),oa(t)(e)(vn(i.color))(),Gu(t)(i.width)(),ao(t)((()=>{if(i.lineJoin==="RoundJoin")return so;if(i.lineJoin==="BevelJoin")return Ru;if(i.lineJoin==="MiterJoin")return Bu;g()})())(),Hu(t)((()=>{if(i.lineCap==="ButtCap")return qu;if(i.lineCap==="RoundCap")return zu;if(i.lineCap==="SquareCap")return Wu;g()})())(),ru(t)(n)(),Qu(t)(),Du(t)())},JN=t=>e=>n=>r=>i=>o=>{const u=ac(t);return()=>{if(u(),_N(t)(n.x)(n.y)(n.w)(n.h)(r)(),i.tag==="Just"?(Wi(t)(e)(vn(i._1.color))(),Qu(t)()):i.tag==="Nothing"||g(),o.tag==="Just")return oa(t)(e)(vn(o._1.color))(),Gu(t)(o._1.width)(),ao(t)((()=>{if(o._1.lineJoin==="RoundJoin")return so;if(o._1.lineJoin==="BevelJoin")return Ru;if(o._1.lineJoin==="MiterJoin")return Bu;g()})())(),Hu(t)((()=>{if(o._1.lineCap==="ButtCap")return qu;if(o._1.lineCap==="RoundCap")return zu;if(o._1.lineCap==="SquareCap")return Wu;g()})())(),Du(t)();o.tag!=="Nothing"&&g()}},TN=t=>e=>n=>r=>{const i=oa(t)(e)(vn(r.color));return()=>(i(),Gu(t)(r.width)(),ao(t)((()=>{if(r.lineJoin==="RoundJoin")return so;if(r.lineJoin==="BevelJoin")return Ru;if(r.lineJoin==="MiterJoin")return Bu;g()})())(),Hu(t)((()=>{if(r.lineCap==="ButtCap")return qu;if(r.lineCap==="RoundCap")return zu;if(r.lineCap==="SquareCap")return Wu;g()})())(),ru(t)(n)(),Du(t)())},c_=t=>e=>n=>{const r=Wi(t)(e)(vn(n.color));return()=>(r(),fN(t)(e)(pN(n.font))(),dl(t)((()=>{if(n.align==="AlignLeft")return sl;if(n.align==="AlignCenter")return cl;if(n.align==="AlignRight")return al;g()})())(),_l(t)((()=>{if(n.baseline==="BaselineTop")return rl;if(n.baseline==="BaselineMiddle")return il;if(n.baseline==="BaselineAlphabetic")return ol;if(n.baseline==="BaselineBottom")return ul;g()})())(),el(t)(n.content)(n.x)(n.y)())},g_={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>hN},wN={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>g_},vN=t=>e=>n=>{const r=ia(e.width/n.vw)(e.height/n.vh),i=Fu(t)({translateX:(e.width-n.vw*r)/2-n.vx*r,translateY:(e.height-n.vh*r)/2-n.vy*r});return()=>(i(),oo(t)({scaleX:r,scaleY:r})(),ao(t)(so)())},bN={pure:t=>e=>()=>t,Apply0:()=>g_},kN={Applicative0:()=>bN,Bind1:()=>wN},f_={fillPath:t=>e=>n=>{const r=xN(n.ctx)(n.styleCache)(t)(e.color),i=n.maskDepth;return()=>{if(i.value===0)return r()}},strokePath:t=>e=>n=>{const r=TN(n.ctx)(n.styleCache)(t)(e),i=n.maskDepth;return()=>{if(i.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const i=NN(r.ctx)(r.styleCache)(t)(e.color)(n),o=r.maskDepth;return()=>{if(o.value===0)return i()}},drawRoundedRect:t=>e=>n=>r=>i=>{const o=JN(i.ctx)(i.styleCache)(t)(e)(n)(r),u=i.maskDepth;return()=>{if(u.value===0)return o()}},drawText:t=>e=>{const n=c_(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=_r(n.ctx),i=n.maskDepth;return()=>{if(i.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Zd(n.ctx)(t)(),c_(n.ctx)(n.styleCache)(e)(),dr(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=_r(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Fu(e.ctx)({translateX:t.tx,translateY:t.ty})(),oo(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBakedTransform:t=>e=>{const n=_r(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Fu(e.ctx)({translateX:t.tx,translateY:t.ty})(),oo(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushClip:t=>e=>n=>{const r=_r(n.ctx),i=n.maskDepth;return()=>{if(i.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",ru(n.ctx)(t)(),e==="NonZero")return Yd(n.ctx)();if(e==="EvenOdd")return cN(n.ctx)();g()}}},popClip:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBlend:t=>e=>{const n=_r(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){if(n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",t==="Normal")return _c(e.ctx)(gl)();if(t==="Difference")return _c(e.ctx)(fl)();g()}}},popBlend:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushAlpha:t=>e=>{const n=_r(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Xd(e.ctx)(t)()}},popAlpha:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushLayer:t=>e=>{if(t==="LayerNodeMask"){const n=e.maskDepth;return()=>{const r=n.value;n.value=r+1|0}}return()=>{}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;if(n>0)return t.maskDepth.value=r}},setViewport:t=>e=>{const n=vN(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=mN(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=yN(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=Bf(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=zf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Zf,Monad0:()=>kN},LN=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Xr=t=>e=>n=>{const r=LN(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},__=t=>{const e=ut.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ut.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},iu=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:Ti(8)(.6)(__(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:Ti(8)(.6)(__(1-t._1))};g()};function EN(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function CN(t){const e=t.length,n=new Array(e);for(let r=0;r<e;r++){const i=t[r],o=t[(r+1)%e];n[r]={a:i,b:o,len:EN(i,o)}}return n}function SN(t,e,n){let r=0;for(let i=0;i<t.length;i++){const o=t[i],u=r,s=u+o.len;if(n<=s){const a=o.len>1e-6?(n-u)/o.len:0;return{x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a}}r=s}return e.length>0?e[e.length-1]:{x:0,y:0}}function d_(t,e){if(e.length===0)return[];const n=CN(e);let r=0;for(let o=0;o<n.length;o++)r+=n[o].len;const i=new Array(t);for(let o=0;o<t;o++)i[o]=SN(n,e,o*r/t);return i}function GN(t,e){const n=e.length;if(n===0)return e;const r=(t%n+n)%n|0,i=new Array(n);for(let o=0;o<n;o++)i[o]=e[(o+r)%n];return i}function PN(t,e){const n=e.length;if(n===0)return e;let r=0,i=1/0;for(let o=0;o<n;o++){let u=0;for(let s=0;s<n;s++){const a=t[s]||{x:0,y:0},c=e[(s+o)%n]||{x:0,y:0},f=a.x-c.x,d=a.y-c.y;u+=f*f+d*d}u<i&&(i=u,r=o)}return GN(r,e)}const l_=t=>e=>n=>{const r=d_(t,e),i=d_(t,n),o=PN(r,i);return{from:r,to:o}};function h_(t){const e=t.length;if(e===0)return{x:0,y:0};let n=0,r=0;for(let i=0;i<e;i++)n+=t[i].x,r+=t[i].y;return{x:n/e,y:r/e}}function IN(t,e){const n=e.x-t.x,r=e.y-t.y,i=Math.sqrt(n*n+r*r);return i<=1e-4?{x:1,y:0}:{x:n/i,y:r/i}}function DN(t,e){const n=e.length;if(n===0)return e;const r=new Array(n);for(let i=0;i<n;i++){const o=e[((i-1)%n+n)%n],u=e[((i+1)%n+n)%n],s=e[i];r[i]={x:s.x+((o.x+u.x)/2-s.x)*t,y:s.y+((o.y+u.y)/2-s.y)*t}}return r}function QN(t){return t<0?0:t>1?1:t}const p_=t=>e=>n=>r=>{const i=e.length;if(i===0)return[];const o=h_(e),u=h_(n),s=IN(o,u),a=new Array(i);let c=1/0,f=-1/0;for(let _=0;_<i;_++){const h=e[_],p=(h.x-o.x)*s.x+(h.y-o.y)*s.y;a[_]=p,p<c&&(c=p),p>f&&(f=p)}const d=f-c;let l=new Array(i);for(let _=0;_<i;_++){const h=e[_],p=n[_];if(p===void 0){l[_]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(a[_]-c)/d),y=Math.max(1e-4,1-m),x=QN((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=DN(.5,l);return l},bn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},m_=J(Lr)(0),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()},FN=J(t=>e=>t+e.len)(0),ua=t=>{const e=Mt(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()},AN=t=>e=>{const n=bn(e)(bn(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},MN=t=>{const e=Mt(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()},ON=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return r_(e);if(t.shape==="Parallelogram")return t_(e);if(t.shape==="Diamond")return u_(e);if(t.shape==="Ellipse")return jf(e);if(t.shape==="Document")return e_(e);if(t.shape==="Cloud")return s_(e)(7);if(t.shape==="Rectangle")return AN(e)(7);g()},pe=t=>e=>n=>W(r=>{const i=rt(r)/rt(n);return{x:t.x+(e.x-t.x)*i,y:t.y+(e.y-t.y)*i}})(Dt(0,n-1|0)),RN=t=>{const e=on(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)]},Yr=t=>e=>{const n=bn(t)(bn(e.w/2)(e.h/2));return{...e,x:e.x+n,y:e.y+n,w:e.w-2*n,h:e.h-2*n}},sa=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return Le(r*r+n*n)},BN=t=>we(e=>n=>({a:e,b:n,len:sa(e)(n)}),t,bt(1,t.length,t)),zN=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(Dt(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=sa(h)(f._1),m=sa(_._1)(h),y=bn(t)(p/2),x=bn(t)(m/2),N=p>0?y/p:0,w=h.x+(f._1.x-h.x)*N,L=h.y+(f._1.y-h.y)*N,k=m>0?x/m:0,E=h.x+(_._1.x-h.x)*k,O=h.y+(_._1.y-h.y)*k;return W(Y=>{const et=rt(Y)/rt(10),G=1-et;return{x:G*G*E+2*G*et*h.x+et*et*w,y:G*G*O+2*G*et*h.y+et*et*L}})(Dt(0,10))}return[]}),...i]},WN=t=>e=>n=>r=>i=>W(o=>{const u=rt(o)/rt(i),s=1-u,a=u*u*u,c=3*s*u*u,f=3*s*s*u,d=s*s*s;return{x:d*t.x+f*e.x+c*n.x+a*r.x,y:d*t.y+f*e.y+c*n.y+a*r.y}})(Dt(0,i-1|0)),qN=t=>[...pe({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...pe({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...WN({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)],x_=t=>e=>W(n=>{const r=6.283185307179586*rt(n)/rt(64);return{x:t.x+e*en(r),y:t.y+e*He(r)}})(Dt(0,63)),ou=t=>e=>{const n=.5522847498*e;return[1,t.x+e,t.y,4,t.x+e,t.y+n,t.x+n,t.y+e,t.x,t.y+e,4,t.x-n,t.y+e,t.x-e,t.y+n,t.x-e,t.y,4,t.x-e,t.y-n,t.x-n,t.y-e,t.x,t.y-e,4,t.x+n,t.y-e,t.x+e,t.y-n,t.x+e,t.y,5]},HN=t=>{const e=t.y+t.h/2,n=on(t.h*.4)(t.w*.2);return[...pe({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...pe({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...pe({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...pe({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...pe({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...pe({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},N_=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:m_(W(n=>n.x)(t))/rt(e),y:m_(W(n=>n.y)(t))/rt(e)}},uu=t=>e=>n=>r=>i=>W(o=>{const u=n+(r-n)*(rt(o)/rt(i));return{x:t.x+e*en(u),y:t.y+e*He(u)}})(Dt(0,i-1|0)),J_=t=>e=>{const n=bn(t)(bn(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),...uu({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),...uu({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),...uu({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),...uu({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},su=t=>e=>n=>r=>i=>o=>W(u=>{const s=r+(i-r)*(rt(u)/rt(o));return{x:t.x+e*en(s),y:t.y+n*He(s)}})(Dt(0,o-1|0)),$N=t=>{const e=t.h*.38;return[...Tt(o_(i_(n_)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=fr(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),i=fr(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return su({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(i)(r>i?r:r+6.283185307179586)(16)}),...pe({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...pe({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...pe({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},XN=t=>{const e=bn(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[...su({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),...su({x:o,y:i})(n)(e)(0)(3.141592653589793)(24),...pe({x:t.x,y:i})({x:t.x,y:r})(12)]},Jr=t=>e=>e.shape==="Cylinder"?XN(e):e.shape==="Parallelogram"?RN(e):e.shape==="Diamond"?HN(e):e.shape==="Ellipse"?J_(on(e.w)(e.h)/2)(e):e.shape==="Document"?qN(e):e.shape==="Cloud"?$N(e):J_(t)(e),YN=t=>{const e=bn(t.h*.075)(t.w*.075),n=t.w/2;return su({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},VN=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})()})()?Ot(r.points)(s):[...r.points,c,s]:[c,s];return i.len<=0||o<=e||r.pos>=n?{...r,pos:o}:{pos:o,points:d}})({pos:0,points:[]})(t).points,UN=t=>e=>n=>{const r=Mt(i=>T,i=>o=>v("Just",{head:i,tail:o}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const i=BN(t),o=FN(i),u=y_(0)(o)(e*o),s=y_(0)(o)(n*o);return s<=u?[]:VN(i)(u)(s)}g()},ZN=t=>e=>n=>r=>{const i=r.x-n.x,o=r.y-n.y,u=e.x-t.x,s=e.y-t.y,a=n.x-t.x,c=n.y-t.y,f=u*o-s*i,d=(a*o-c*i)/f,l=(a*s-c*u)/f;return(f<0?-f<1e-9:f<1e-9)?T:d>=0&&d<=1&&l>=0&&l<=1?v("Just",d):T},KN=t=>e=>n=>{const r=Lt(i=>o=>ut.compare(i.t)(o.t))(xt(i=>{const o=ZN(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})(we(Cn,t,[...bt(1,t.length,t),...bt(0,1,t)])));return 0<r.length?v("Just",r[0].p):T},T_=t=>e=>{const n=ii(e);if(n.tag==="Nothing")return e;if(n.tag==="Just"){const r=n._1.init.length-1|0;if(r>=0&&r<n._1.init.length){const i=KN(t)(n._1.init[r])(n._1.last);if(i.tag==="Just")return Ot(n._1.init)(i._1);if(i.tag==="Nothing")return e;g()}return e}g()},aa=t=>t,Mn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Tr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},jN=td($a)(zt),tJ=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},eJ=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},w_=aa("SegMove"),nJ=aa("SegLine"),rJ=aa("SegQuad"),v_={offset:.4,passes:1,rMax:1.5},b_=t=>de(ln(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,au=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},cu=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},On=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},qi=(()=>{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})(),iJ=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const i=n,o=r,u=i>=0&&i<t.length?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:w_,m:o,c:o,p:s,len:0}),r=s,n=i+3|0;continue}if(u._1===2){const s={x:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()},a=s.x-o.x,c=s.y-o.y;e.push({kind:nJ,m:o,c:o,p:s,len:Le(a*a+c*c)}),r=s,n=i+3|0;continue}if(u._1===3){const s={x:(()=>{const f=i+3|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+4|0;return f>=0&&f<t.length?t[f]:0})()},a=s.x-o.x,c=s.y-o.y;e.push({kind:rJ,m:o,c:{x:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()},p:s,len:Le(a*a+c*c)*1.05}),r=s,n=i+5|0;continue}if(u._1===5){e.push({kind:w_,m:o,c:o,p:o,len:0}),n=i+1|0;continue}n=t.length;continue}g()}return e},oJ=t=>e=>{const n=e.length-1|0,r=n<1?[]:bt(0,n,e),i=(()=>{const u=r.length-1|0;return u>=0&&u<r.length?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=Le(s*s+u*u);return a<=1e-4?e:Ot((()=>{const c=e.length-1|0;return c<1?[]:bt(0,c,e)})())({x:e[o].x+s/a*t,y:e[o].y+u/a*t})}return e},uJ=t=>e=>n=>Te(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*en(u.value),y:i.y+o.value*He(u.value)},...r.out]}})({prng:e,out:[]})(n).out),sJ=t=>e=>n=>{if(e.kind==="SegMove")return cu(t)(e.p);if(e.kind==="SegLine")return On(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 On(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});g()},aJ=t=>e=>{if(e.kind==="SegMove")return cu(t)(e.p);if(e.kind==="SegLine")return On(t)(e.p);if(e.kind==="SegQuad")return au(t)(e.c)(e.p);g()},k_=t=>e=>{const n=iJ(e),r=J(s=>a=>s+a.len)(0)(n)*Mn(0)(Tr(1)(t)),i=[];let o=0,u=0;for(;u<n.length;){const s=u,a=o;if(s>=0&&s<n.length){if(a+n[s].len<=r){const c=n[s];aJ(i)(c)(),o=a+c.len,u=s+1|0;continue}if(a>=r){u=n.length;continue}sJ(i)(n[s])((r-a)/Mn(n[s].len)(1e-4))()}u=n.length}return i},L_={offset:1.5,passes:2,rMax:14,overshoot:2.5},E_=t=>e=>n=>r=>{const i=r.y-n.y,o=n.y-e.y,u=r.x-n.x,s=Le(u*u+i*i),a=n.x-e.x,c=Le(a*a+o*o),f=Tr(t.rMax*(yd(c>0&&s>0?Mn(-1)(Tr(1)((a*u+o*i)/(c*s))):1)/3.141592653589793))(.4*Tr(c)(s));return{inP:c>0?{x:n.x-a/c*f,y:n.y-o/c*f}:n,curr:n,outP:s>0?{x:n.x+u/s*f,y:n.y+i/s*f}:n}},C_=t=>e=>{const n=e.length,r=[],i=0<e.length?v("Just",e[0]):T;if(i.tag==="Just"?cu(r)(i._1)():i.tag==="Nothing"||g(),n>=3){let u=1;for(;u<=(n-2|0);){const s=u,a=s+1|0;if(a>=0&&a<e.length){if(s>=0&&s<e.length){const c=s-1|0;if(c>=0&&c<e.length){const f=E_(t)(e[c])(e[s])(e[a]);On(r)(f.inP)(),au(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&&On(r)(e[o])(),r},cJ=t=>e=>n=>r=>i=>{if(i.length<4)return C_(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=Un(Un(e)(s)+s|0)(s),c=_=>{const h=Un(_+s|0)(s);return h>=0&&h<i.length?i[h]:u},f=W(_=>E_(t)(c((a+_|0)-1|0))(c(a+_|0))(c((a+_|0)+1|0)))(Dt(0,s-1|0)),d=[],l=0<f.length?v("Just",f[0]):T;if(l.tag==="Just")if(cu(d)(l._1.outP)(),jN((()=>{const _=Mt(h=>T,h=>p=>v("Just",p),f);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})())(_=>{const h=On(d)(_.inP);return()=>(h(),au(d)(_.curr)(_.outP)())})(),n)On(d)(l._1.inP)(),au(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const _=f.length-1|0;_>=0&&_<f.length?On(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}})())():On(d)(l._1.inP)()}else l.tag==="Nothing"||g();return d},Vr=t=>e=>n=>r=>{const i=tJ(1)(r.length-1|0),o=ae(0)(rt(i))(hs("shape")(e)),u=eJ(i-1|0)(de(ln(o.value))),s=o.prng;return W(a=>{const c=ae(0)(1)(hs(oe(a))(s)),f=ae(-.18)(.3)(c.prng),d=c.value<.7,l=ae(.5)(.85)(f.prng),_=uJ(t.offset)(l.prng)(r);return{path:n?cJ(t)(u)(d)(f.value)(_):C_(t)(_),alpha:l.value}})(Dt(0,t.passes-1|0))},gJ=t=>e=>n=>Vr(t)(e)(!0)([{x:n.x,y:n.y},{x:n.x+n.w,y:n.y},{x:n.x+n.w,y:n.y+n.h},{x:n.x,y:n.y+n.h},{x:n.x,y:n.y}]),fJ=t=>e=>n=>{const r=Mn(0)(Tr(1)(n)),i=e.h/rt(4),o=Mn(6)(i*1.4);return xt(u=>u)(W(u=>{if(r<Mn(0)(rt(u)/rt(4)-.05))return T;const s=hs(oe(u))(t),a=Mn(0)(rt(u)/rt(4)-.05),c=Un(u)(2)===0,f=c?e.x-2:e.x+e.w+2,d=c?e.x+e.w+2:e.x-2,l=e.y+(rt(u)+.5)*i;return v("Just",{path:k_(Mn(0)(Tr(1)((r-a)/Mn(1e-4)(Tr(1)(rt(u+1|0)/rt(4)+.05)-a))))((()=>{const _={rMax:2,offset:.6,passes:1},h=Te(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:[]})(Dt(0,4)).out),p=h.length<2?[]:Vr(_)(s)(!1)(h);return 0<p.length?p[0].path:[]})()),width:o,alpha:1})})(Dt(0,3)))},ca=(t,e,n)=>({tag:t,_1:e,_2:n}),S_=t=>t,ga=(t,e,n)=>({tag:t,_1:e,_2:n}),gu=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},G_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Hi=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},P_=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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},Pe=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Rn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=v("Just",o._4);continue}}g()}return i},_J=zt.foldMap(Id),fu=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},I_=jt(C)(zt),dJ=oc(C),lJ=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},fa=S_("LabelsShown"),hJ=S_("LabelsHidden"),D_=t=>{const e=t.Monad0().Bind1(),n=t.popTransform,r=t.popAlpha;return i=>o=>u=>s=>a=>e.bind(t.pushAlpha(i.fadeAlpha))(()=>e.bind(t.pushTransform({tx:o*(1-i.popScale),ty:u*(1-i.popScale),sx:i.popScale,sy:i.popScale}))(()=>e.bind(t.pushTransform({tx:0,ty:s.y*(1-i.flipY),sx:1,sy:i.flipY}))(()=>e.bind(a)(()=>e.bind(n)(()=>e.bind(n)(()=>r))))))},Ze=t=>{const e=t.Apply0();return n=>J(r=>i=>e.apply(e.Functor0().map(o=>Ma)(r))(n(i)))(t.pure())},Q_=t=>e=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},a=Xr(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=l_(128)(Jr(4)(Yr(2)(e)))(x_(f)(6)),p=f.x-s.x,m=2*(()=>{const V=f.y-s.y;return(p<0?-p:p)+(V<0?-V:V)})(),y=_.x-u.x,x=2*(()=>{const V=_.y-u.y;return(y<0?-y:y)+(V<0?-V:V)})(),N=m+pi(t)+x,w=N<=1e-4?1:1-x/N,L=N<=1e-4?0:m/N,k=w-L,E=l_(128)(x_(_)(6))(Jr(4)(Yr(2)(n))),O={maxDelay:.4,smoothPasses:2},Y=mr(t)(gu(0)(1)(k<=1e-4?0:(a-L)/k)),et=(()=>{if(Y.tag==="Just")return Y._1;if(Y.tag==="Nothing")return f;g()})(),G=(()=>{if(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(L<=1e-4)return 1;const V=a/L,U=V<0?0:V>1?1:V;return U*U*(3-2*U)})();return a<L?ga("PolyShape",p_(P)(h.from)(h.to)(O)):a>=w?ga("PolyShape",p_(G)(E.from)(E.to)(O)):ga("CircleShape",et,6)},F_=t=>e=>n=>r=>i=>o=>{const u=Q_(t)(e)(n)(r)(i)(o);if(u.tag==="PolyShape")return N_(u._1);if(u.tag==="CircleShape")return u._1;g()},pJ=t=>e=>{const n=t.y+t.h-6,r=t.y+6,i=t.x+14,o=t.x+t.w-14,u=J(Hi)(0)(W(s=>i-10<s.x+s.w+12&&o+10>s.x-12&&r-10<s.y+s.h+12&&n+10>s.y-12?G_((s.x+s.w+12-(i-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+u*.7071067811865476,y:t.y-u*.7071067811865476}},mJ=t=>e=>n=>J(r=>i=>{const o=P_(i)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just"){const u=pJ(o._1)(r.obstacles);return{acc:j(C)(i)(u)(r.acc),obstacles:Ot(r.obstacles)(u)}}g()})({acc:Q,obstacles:n})(t).acc,_a=(()=>{const t={r:24,g:24,b:27,a:255},e={r:244,g:244,b:245,a:255},n={r:248,g:249,b:246,a:255},r={r:26,g:26,b:26,a:255},i={r:28,g:101,b:192,a:255},o={r:247,g:248,b:250,a:255},u={r:42,g:48,b:60,a:255},s={r:120,g:130,b:146,a:255};return a=>{if(a==="Light")return{bg:{r:255,g:255,b:255,a:255},bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:211,b:209,a:255},shadowFill:{r:255,g:255,b:255,a:255},shadowDot:{r:26,g:26,b:26,a:255},chip:{r:255,g:235,b:130,a:255},chipShadow:{r:214,g:211,b:209,a:255},chipText:An,nodeFill:ie,nodeStroke:An,text:An,edge:An,arrowFill:An,tokenOutsideFill:An,tokenOutsideStroke:ie,tokenInside:ie,tokenInsideStroke:ie,tokenInsideBlend:nu,tokenInsideAlpha:1,chipPillFill:An,chipPillText:ie,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:ie,tokenOutsideStroke:ie,tokenInside:ie,tokenInsideStroke:ie,tokenInsideBlend:nu,tokenInsideAlpha:1,chipPillFill:e,chipPillText:t,chipHairline:{r:244,g:244,b:245,a:120},trailDot:e,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Blueprint")return{bg:i,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:90,g:160,b:230,a:255},shadowFill:i,shadowDot:ie,chip:ie,chipShadow:{r:0,g:0,b:0,a:120},chipText:i,nodeFill:i,nodeStroke:ie,text:ie,edge:ie,arrowFill:ie,tokenOutsideFill:ie,tokenOutsideStroke:ie,tokenInside:ie,tokenInsideStroke:ie,tokenInsideBlend:Yf,tokenInsideAlpha:.35,chipPillFill:ie,chipPillText:i,chipHairline:{r:255,g:255,b:255,a:120},trailDot:ie,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Whiteboard")return{bg:n,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:0,g:0,b:0,a:0},shadowFill:n,shadowDot:r,chip:{r:217,g:74,b:56,a:255},chipShadow:{r:26,g:26,b:26,a:60},chipText:n,nodeFill:n,nodeStroke:r,text:r,edge:r,arrowFill:r,tokenOutsideFill:r,tokenOutsideStroke:n,tokenInside:n,tokenInsideStroke:n,tokenInsideBlend:Yf,tokenInsideAlpha:1,chipPillFill:r,chipPillText:n,chipHairline:{r:26,g:26,b:26,a:90},trailDot:r,wobble:!0,fontFamily:"Supermarker, Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Isometric")return{bg:o,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:218,b:224,a:255},shadowFill:o,shadowDot:u,chip:{r:255,g:235,b:130,a:255},chipShadow:{r:100,g:110,b:125,a:90},chipText:u,nodeFill:{r:236,g:239,b:244,a:255},nodeStroke:u,text:u,edge:s,arrowFill:s,tokenOutsideFill:u,tokenOutsideStroke:ie,tokenInside:ie,tokenInsideStroke:ie,tokenInsideBlend:nu,tokenInsideAlpha:1,chipPillFill:u,chipPillText:ie,chipHairline:{r:60,g:66,b:78,a:90},trailDot:u,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};g()}})(),da=t=>e=>Tt(Pe(t.nodes))(n=>{const r=fe(n._1)(e.nodes);return r.tag==="Just"&&iu(r._1).alpha>0?ON(n._2):[]}),yJ=t=>e=>n=>[1,t.vx,t.vy,2,t.vx+t.vw,t.vy,2,t.vx+t.vw,t.vy+t.vh,2,t.vx,t.vy+t.vh,5,...da(e)(n)],xJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=ar.traverse(r);return o=>u=>{const s=Zn(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?co(s[c]):" "))(l=>r.pure({x:f,w:d-f,up:l.ascent-a,down:l.descent+a})))))(Dt(0,s.length-1|0))}},NJ=t=>e=>{const n=i=>(i.x-e.x)*(i.x-e.x)+(i.y-e.y)*(i.y-e.y),r=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 W(i=>{const o=rt(i)/5;return{x:r.x+(e.x-r.x)*o,y:r.y+(e.y-r.y)*o}})([1,2,3,4])},la=t=>{const e=yo(`
|
|
7
|
-
`)(t);return e.length===0?[""]:e},JJ=t=>e=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},a=Xr(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 O=f.y-s.y;return(h<0?-h:h)+(O<0?-O:O)})(),m=_.x-u.x,y=2*(()=>{const O=_.y-u.y;return(m<0?-m:m)+(O<0?-O:O)})(),x=p+pi(t)+y,N=x<=1e-4?1:1-y/x,w=x<=1e-4?0:p/x,L=N-w,k=mr(t)(gu(0)(1)(L<=1e-4?0:(a-w)/L)),E=(()=>{if(k.tag==="Just")return k._1;if(k.tag==="Nothing")return f;g()})();return a<w?ca("InsideRect",Yr(2)(e)):a>=N?ca("InsideRect",Yr(2)(n)):ca("InsideBall",E,6)},TJ={offset:.8,passes:2,rMax:5},wJ=t=>{const e=t.Monad0().Applicative0(),n=Ze(e);return r=>i=>o=>u=>{const s={color:u,width:1,lineJoin:
|
|
8
|
-
`)(y.label===""?m:y.label),k=L.length===0?[""]:L,E=w.size*1.2,O=y.shape==="Cylinder"?t.strokePath(sN({x:y.x,y:y.y,w:y.w,h:y.h}))({color:_.nodeStroke,width:1.25,lineJoin:ve,lineCap:_n}):i.pure(),Y=(y.shape==="Cylinder"?(y.y+(y.y+y.h+5-2*on(y.h*.075)(y.w*.075)))/2:(y.y+y.y+y.h)/2)-rt(k.length)*E/2+E/2,et=x.tag==="PloppingOut"&&_.wobble?x._1:-1,G=et>=0,P=iu(x),V=G?{alpha:1,scale:1}:P,U=y.x+y.w/2,B=y.y+y.h/2,R=n.bind(t.pushAlpha(V.alpha*h))(()=>n.bind(t.pushTransform({tx:U*(1-V.scale),ty:B*(1-V.scale),sx:V.scale,sy:V.scale}))(()=>{const M={x:y.x,y:y.y,w:y.w,h:y.h},S={color:_.nodeStroke,width:_.wobble?2:1.25,lineJoin:ve,lineCap:_.wobble?wn:_n};return n.bind((()=>{if(_.wobble){if(y.shape==="Rectangle")return o(N)(gJ(L_)(b_(M))(M));const I=Jr(7)(y);return n.bind(o(N)((()=>{const D=qi(I);return I.length<4?[]:Vr(v_)(D)(!0)(I)})()))(()=>s(D=>o(N)((()=>{const A=qi(D);return D.length<2?[]:Vr(v_)(A)(!1)(D)})()))(y.shape==="Cylinder"?[YN(y)]:[]))}return n.bind(a_(t)(y.shape)(M)(7)(v("Just",{color:_.nodeFill,flat:!1}))(v("Just",S)))(()=>O)})())(()=>n.bind((()=>{if(p.tag==="Just"&&_.wobble&&!G){const I=p._1;return n.bind(a(c(w))(k))(D=>{const A=Lt(K=>nt=>ut.compare(K.x)(nt.x)),H=de(ln(y.x*7919+y.y*3001))*-1640531535|0,$=ae(5)(7.5)(H),X=ae(0)($.value)($.prng),q=-(1+2*ae(-1)(1)(X.prng).value*3.141592653589793/180),z=(K,nt,ht,_t,Nt)=>A(xt(wt=>wt)([q*nt+K>=_t&&q*nt+K<=Nt?v("Just",{x:nt,y:q*nt+K}):T,q*ht+K>=_t&&q*ht+K<=Nt?v("Just",{x:ht,y:q*ht+K}):T,(()=>{const wt=(_t-K)/q;return wt>=nt&&wt<=ht?v("Just",{x:wt,y:_t}):T})(),(()=>{const wt=(Nt-K)/q;return wt>=nt&&wt<=ht?v("Just",{x:wt,y:Nt}):T})()])),tt=$.value,Z=Un(I.frameHash)(3),ct=Z===0?{r:200,g:35,b:30,a:220}:Z===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},ft=y.x+y.w/2,at=Oe(Ft(K=>nt=>Ft((()=>{const ht=Y+rt(K)*E,_t=ft-J(Nt=>wt=>Nt+wt.w)(0)(nt)/2;return Nt=>wt=>{const Kt=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-Kt;return{x:_t+sn-1,y:ht-wt.up-1,w:Hi(0)((()=>{const Me=Nt+1|0;return Me>=0&&Me<nt.length&&Nt<(nt.length-1|0)?(wt.x+wt.w+nt[Me].x)/2-sn:wt.x+wt.w+Kt-sn})())+2,h:wt.up+wt.down+2}}})())(nt))(D)),yt=y.y+4,St=y.x+y.w-4,Rt=y.x+4,pt=yt-q*Rt+X.value,Bt=y.y+y.h-4,Jt=Tt(Tt(Ft(K=>nt=>{const ht=(nt.from.x+nt.to.x)/2,_t=(nt.from.y+nt.to.y)/2,Nt=ae(-1)(1)(H+(911*(K+1|0)|0)|0),wt=ae(-3)(5)(Nt.prng),Kt=Nt.value*3.141592653589793/180,Se=en(Kt),sn=He(Kt),Me=Et=>({x:ht+(Et.x-ht)*Se-(Et.y-_t)*sn,y:_t+(Et.x-ht)*sn+(Et.y-_t)*Se});return{from:(()=>{const Et=Me(nt.from),Qt=Et.y-_t,je=Et.x-ht,qe=Le(je*je+Qt*Qt),tn=qe<1e-4?1:(qe+wt.value)/qe;return{x:ht+je*tn,y:_t+Qt*tn}})(),to:(()=>{const Et=Me(nt.to),Qt=ae(-3)(5)(wt.prng).value,je=Et.y-_t,qe=Et.x-ht,tn=Le(qe*qe+je*je),Hn=tn<1e-4?1:(tn+Qt)/tn;return{x:ht+qe*Hn,y:_t+je*Hn}})()}})(xt(K=>{const nt=z(pt+rt(K)*tt,Rt,St,yt,Bt);return nt.length===2?v("Just",{from:nt[0],to:nt[1]}):T})(Dt(0,fu(1)(de(ln((Bt-q*St-pt)/tt)))))))(K=>st(nt=>nt.to.x-nt.from.x>1,J(nt=>ht=>Tt(nt)(_t=>{const Nt=z(_t.from.y-q*_t.from.x,ht.x,ht.x+ht.w,ht.y,ht.y+ht.h);return Nt.length===2?Nt[0].x>_t.from.x+.001&&Nt[1].x<_t.to.x-.001?[{from:_t.from,to:Nt[0]},{from:Nt[1],to:_t.to}]:Nt[0].x<=_t.from.x+.001&&Nt[1].x<_t.to.x-.001?[{from:Nt[1],to:_t.to}]:Nt[0].x>_t.from.x+.001&&Nt[1].x>=_t.to.x-.001?[{from:_t.from,to:Nt[0]}]:[]:[_t]}))([K])(at))))(K=>(()=>{const nt=K.to.x-K.from.x;return Le(2)*(nt>=0?nt:-nt)<=28})()?[K]:[{from:K.from,to:{x:K.from.x+(K.to.x-K.from.x)*.495,y:K.from.y+(K.to.y-K.from.y)*.495}},{from:{x:K.from.x+(K.to.x-K.from.x)*.505,y:K.from.y+(K.to.y-K.from.y)*.505},to:K.to}]),mt=Jt.length,gt=K=>Hi(0)(G_(1)(I.t*rt(mt)-rt(K)));return n.bind(t.pushClip(ua(Jr(7)(y)))(eu))(()=>n.bind(o(K=>{const nt=K._1,ht=ae(1.4)(1.9)(H+(1303*(nt+1|0)|0)|0),_t=ae(.35)(.8)(ht.prng),Nt=o(wt=>n.bind(t.pushAlpha(wt.alpha*_t.value))(()=>n.bind(t.strokePath(k_(gt(nt))(wt.path))({color:ct,width:ht.value,lineJoin:ve,lineCap:wn}))(()=>r)))(Vr({...L_,rMax:0,offset:.5})(H+(53*(nt+1|0)|0)|0)(!1)([K._2.from,K._2.to]));return gt(nt)>0?Nt:i.pure()})(Ft(Cn)(Jt)))(()=>u))})}return i.pure()})())(()=>n.bind((()=>{if(l==="LabelsShown")return o(I=>t.drawText({x:y.x+y.w/2,y:Y+rt(I._1)*E,content:I._2,font:w,color:_.text,align:$r,baseline:or}))(Ft(Cn)(k));if(l==="LabelsHidden")return i.pure();g()})())(()=>n.bind((()=>{const I=f(_)(M)(et);return G?I:i.pure()})())(()=>n.bind(d)(()=>r)))))}));return V.alpha*h>0?R:i.pure()}},bJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=M_(t),o=t.popAlpha,u=Ze(n);return s=>a=>c=>{const f={...s,nodeFill:s.text,text:s.nodeFill,nodeStroke:s.nodeFill};return u(d=>{const l=fe(d._1)(c.nodes),_=fe(d._1)(a.nodes),h=(()=>{if(_.tag==="Just"&&l.tag==="Just"){const p=l._1,m=_._1;return r.bind(t.pushAlpha(d._2))(()=>r.bind(i(fa)(f)(1)(T)(d._1)(m)(p))(()=>o))}return n.pure()})();return d._2>0?h:n.pure()})(Pe(c.nodeInvert))}},kJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=Ze(n);return o=>u=>s=>{const a={family:o.fontFamily,size:11,weight:500};return i(c=>{if(c._2===""||(()=>{const l=Rn(c._1)(s.edges);return l.tag==="Nothing"||!(l.tag==="Just"&&l._1.tag==="Extended")})())return n.pure();const f=Rn(c._1)(u.edges),d=(()=>{if(f.tag==="Just")return mr(f._1)(.5);if(f.tag==="Nothing")return T;g()})();if(d.tag==="Nothing")return n.pure();if(d.tag==="Just"){const l=d._1;return r.bind(t.measureText(a)(c._2))(_=>{const h=_+12;return r.bind(t.drawRoundedRect({x:l.x-h/2,y:l.y-8.5,w:h,h:17})(3)(v("Just",{color:o.chipPillFill,flat:!0}))(T))(()=>t.drawText({x:l.x,y:l.y,content:c._2,font:a,color:o.chipPillText,align:$r,baseline:or}))})}g()})(Pe(u.edgeLabels))}},O_=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>o=>r?e.bind(t.clearBackground(n.bgTransparent))(()=>t.setViewport(o)):n.wobble?e.bind(t.setViewport(o))(()=>t.clearBackground(n.bg)):e.bind(t.setViewport(o))(()=>t.backgroundDots({viewport:o,bgColor:n.bg,dotColor:n.bgDot,tile:12*i,dotRadius:.7*i}))},LJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=t.popAlpha;return o=>u=>s=>a=>c=>f=>d=>l=>_=>{const h=(()=>{if(_>1e-4&&d>1-_){const m=(1-d)/_;return m<0?0:m>1?1:m}if(l>1e-4&&d<l){const m=d/l;return m<0?0:m>1?1:m}return 1})(),p=Q_(a)(c)(f)(d)(l)(_);if(p.tag==="CircleShape")return o?A_(t)(p._1)(p._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(ou(p._1)(p._2))({color:u,flat:!0})({color:s,width:1,lineJoin:ve,lineCap:_n});if(p.tag==="PolyShape"&&o&&p._1.length>=3)return r.bind(t.pushAlpha(h))(()=>r.bind(A_(t)(N_(p._1))(6)({r:200,g:35,b:30,a:220}))(()=>i));if(p.tag==="PolyShape")return o?n.pure():p._1.length>=3?t.fillStrokePath(ua(p._1))({color:u,flat:!0})({color:s,width:1,lineJoin:ve,lineCap:_n}):n.pure();g()}},EJ=t=>{const e=t.Monad0().Bind1(),n=t.popAlpha;return r=>i=>o=>u=>s=>a=>c=>{const f=Xr(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(ou(h)(6))({color:r,flat:!0})({color:i,width:1,lineJoin:ve,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)})())}},_u=t=>{const e=LJ(t),n=EJ(t),r=t.Monad0().Applicative0(),i=Ze(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 _=Rn(f._2._1.edge)(u.edges);if(_.tag==="Just")return e(o)(a)(c)((()=>{if(f._2._1.direction==="Forward")return _._1;if(f._2._1.direction==="Backward")return Te(_._1);g()})())(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);if(_.tag==="Nothing")return n(a)(c)(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);g()}return r.pure()}if(f._2.tag==="Filling"){if(o)return r.pure();const d=fe(f._2._1.node)(u.nodes);if(d.tag==="Just")return t.fillStrokePath(ua(Jr(4)(Yr(2)(d._1))))({color:a,flat:!0})({color:c,width:1,lineJoin:ve,lineCap:_n});if(d.tag==="Nothing")return r.pure();g()}return r.pure()})(Pe(s.tokens))},R_=t=>{const e=_u(t),n=t.Monad0(),r=n.Bind1(),i=_u(t),o=wJ(t),u=t.popClip,s=t.popBlend,a=t.popLayer,c=n.Applicative0(),f=Ze(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($x))(()=>r.bind(t.pushBlend(nu))(()=>r.bind(t.pushClip(da(h)(p))(eu))(()=>r.bind(m)(()=>r.bind(u)(()=>r.bind(s)(()=>r.bind(a)(()=>r.bind(t.pushLayer(Xx))(()=>r.bind(f(y=>{const x=fe(y._1)(p.nodes);return x.tag==="Just"&&iu(x._1).alpha>0?a_(t)(y._2.shape)({x:y._2.x,y:y._2.y,w:y._2.w,h:y._2.h})(7)(v("Just",{color:ie,flat:!1}))(T):c.pure()})(Pe(h.nodes)))(()=>a)))))))));if(_.tokenInsideBlend==="Normal")return r.bind(t.pushClip(da(h)(p))(eu))(()=>r.bind(t.pushAlpha(_.tokenInsideAlpha))(()=>r.bind(m)(()=>r.bind(d)(()=>u))));g()}},B_=t=>{const e=t.Monad0().Bind1(),n=_u(t),r=_u(t),i=t.popClip,o=t.popLayer;return u=>s=>a=>c=>e.bind(t.pushLayer(Hx))(()=>e.bind(t.pushClip(yJ(s)(a)(c))(Vx))(()=>e.bind(u.wobble?n(!0)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke):r(!1)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke))(()=>e.bind(i)(()=>o))))},CJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=Ze(r);return o=>u=>s=>a=>c=>f=>{const d=Jo(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?[]:gr(m=>_(m)>0)(Dt(h,d-1|0)).init;return n.bind((()=>{const m=t.drawText({x:a,y:c,content:me(h)(f),font:o,color:u,align:na,baseline:or});return h>0?m:r.pure()})())(()=>i(m=>n.bind(t.measureText(o)(me(m)(f)))(y=>{const x=_(m);return t.drawText({x:a+y,y:c-(1-x)*10,content:me(1)(di(Kn(me(m)(f)))(f)),font:o,color:{...u,a:de(ln(x*rt(u.a)))},align:na,baseline:or})}))(p))}},du=t=>e=>n=>r=>{const i=W(_=>rt(fu(1)(Jo(_).length)))(r),o=Hi(1)(J(Lr)(0)(i)),u=Xr(e)(n)(t),s=u*o,a=fu(1)(r.length),c=(_=>h=>p=>{let m=_,y=h,x=p,N=!0,w;for(;N;){const L=m,k=y,E=Mt(O=>T,O=>Y=>v("Just",{head:O,tail:Y}),x);if(E.tag==="Nothing"){N=!1,w=fu(0)(a-1|0);continue}if(E.tag==="Just"){if(k+E._1.head>=s){N=!1,w=L;continue}m=L+1|0,y=k+E._1.head,x=E._1.tail;continue}g()}return w})(0)(0)(i),f=J(Lr)(0)(c<1?[]:bt(0,c,i)),d=f/o;if(c>=0&&c<i.length){const _=(f+i[c])/o;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(_<=d)return 1;const h=(u-d)/(_-d);return h<0?0:h>1?1:h})()}}const l=(f+1)/o;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(l<=d)return 1;const _=(u-d)/(l-d);return _<0?0:_>1?1:_})()}},SJ=t=>{const e=t.Monad0();return n=>r=>i=>e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(du(r)(0)(0)(W(ud)(i)).line))(o=>{const u=o+28;return e.Applicative0().pure({x:n.x+n.w/2-u/2,y:n.y-25.2-14,w:u,h:25.2})})},GJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=SJ(t),i=e.Applicative0(),o=ar.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>I_(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)})(Pe(s.tokens)))},PJ=t=>{const e=t.Monad0();return n=>r=>i=>o=>u=>s=>a=>{const c=F_(n)(r)(i)(o)(u)(s);return e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(du(o)(u)(s)(Tt(a)(la)).line))(f=>e.Applicative0().pure({x:c.x+14+f/2-f/2-14,y:c.y-6-8-6.6-6,w:f+28,h:25.2}))}},IJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=PJ(t),i=e.Applicative0(),o=ar.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>I_(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=Rn(a._2._1.edge)(u.edges);if(d.tag==="Just"&&f.tag==="Just"&&c.tag==="Just")return n.bind(r((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return Te(d._1);g()})())(f._1)(c._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(l=>i.pure(v("Just",b(a._1,l))))}return i.pure(T)})(Pe(s.tokens)))},ha=t=>{const e=t.Monad0(),n=e.Bind1(),r=IJ(t),i=GJ(t);return o=>u=>n.bind(r(o)(u))(s=>n.bind(i(o)(u))(a=>e.Applicative0().pure(mJ((()=>{const c=f=>{if(f.tag==="Leaf")return Q;if(f.tag==="Node")return Wt("Node",f._1,f._2,f._3,void 0,c(f._5),c(f._6));g()};return Lt(C.compare)(Ct(We.foldr,c(s)))})())(s)([...xt(c=>{const f=fe(c._1)(u.nodes);return f.tag==="Just"&&iu(f._1).alpha>0?v("Just",{x:c._2.x,y:c._2.y,w:c._2.w,h:c._2.h}):T})(Pe(o.nodes)),...(()=>{const c=(f,d)=>{if(f.tag==="Leaf")return d;if(f.tag==="Node")return c(f._5,qt("Cons",f._4,c(f._6,d)));g()};return Ct($t.foldr,c(a,Ht))})()]))))},z_=t=>e=>n=>{const r=Ti(6)(.55)(gu(0)(1)((1-t)/.06)),i=t>.94,o=i&&n>1e-4,u=Ti(6)(.55)(gu(0)(1)(t/.06)),s=t<.06,a=s&&e>1e-4,c=i&&n<=1e-4;return{popScale:a?u:o?r:1,flipY:s&&e<=1e-4?u:c?r:1,fadeAlpha:(()=>{if(a){const f=t/.06;return f<0?.55:f>1?1:.55+.44999999999999996*f}if(o){const f=(1-t)/.06;return f<0?.55:f>1?1:.55+.44999999999999996*f}return 1})()}},DJ=t=>{const e=t.Monad0().Bind1(),n=D_(t);return r=>i=>o=>u=>s=>{const a=z_(u)(0)(0),c={family:r.fontFamily,size:11,weight:500},f=du(u)(0)(0)(Tt(s)(la));return e.bind(t.measureText(c)(f.line))(d=>{const l=o.x+o.w/2,_=d+28,h=o.y-25.2-14,p=l-_/2,m=[1,l,h+25.2,2,l,o.y],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:ve,lineCap:_n})))(()=>e.bind(t.strokePath(m)({color:r.chipHairline,width:1,lineJoin:ve,lineCap:_n}))(()=>t.drawText({x:l,y:y.y,content:f.line,font:c,color:r.chipText,align:$r,baseline:or})))))})}},QJ=t=>{const e=D_(t),n=t.Monad0(),r=n.Bind1(),i=Ze(n.Applicative0()),o=CJ(t);return u=>s=>a=>c=>f=>d=>l=>_=>h=>{const p=du(f)(d)(l)(Tt(_)(la)),m=p.line,y=p.phaseInLabel/.45,x=y<0?0:y>1?1:y,N=h.w,w=h.y,L=h.x,k=L+14,E=h.h,O=w+E/2;return e(z_(f)(d)(l))(L)(w+E)({x:L+N/2,y:O})(r.bind(i(Y=>t.fillPath(ou(Y)(1.5))({color:u.trailDot,flat:!0}))(NJ(h)(F_(s)(a)(c)(f)(d)(l))))(()=>r.bind(t.drawRoundedRect({x:L,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)(k)(O)(m))))}},pa=t=>{const e=QJ(t),n=t.Monad0(),r=n.Applicative0(),i=DJ(t),o=n.Bind1(),u=Ze(r),s=t.popLayer;return a=>c=>f=>d=>o.bind(t.pushLayer(Yx))(()=>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=Rn(l._2._1.edge)(c.edges),m=P_(l._1)(d);if(m.tag==="Just"&&p.tag==="Just"&&h.tag==="Just"&&_.tag==="Just")return e(a)((()=>{if(l._2._1.direction==="Forward")return p._1;if(l._2._1.direction==="Backward")return Te(p._1);g()})())(h._1)(_._1)(l._2._1.progress)(l._2._1.holdPre)(l._2._1.holdPost)(l._2._1.labels)(m._1)}return r.pure()}if(l._2.tag==="Filling"&&l._2._1.labels.length!==0){const _=fe(l._2._1.node)(c.nodes);if(_.tag==="Just")return i(a)(c)(_._1)(l._2._1.progress)(l._2._1.labels);if(_.tag==="Nothing")return r.pure();g()}return r.pure()})(Pe(f.tokens)))(()=>s))},W_=t=>{const e=ha(t),n=pa(t);return r=>i=>o=>t.Monad0().Bind1().bind(e(i)(o))(u=>n(r)(i)(o)(u))},FJ=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>i=>{const o=i.length-1|0,u=o<1?[]:bt(0,o,i),s=u.length-1|0,a=s>=0&&s<u.length?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)(qi(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=Le(y*y+m*m),N=m/x,w=-N,L=y/x,k=f._1.x+L*.875,E=f._1.y+N*.875,O=r.wobble?8.75*d.value:8.75,Y=k-L*O,et=E-N*O,G=Y+w*_,P=et+L*_,V=[1,k,E,2,Y+w*4.375,et+L*4.375,2,Y-w*4.375,et-L*4.375,5],U=Y-w*p,B=et-L*p,R={color:r.arrowFill,width:2,lineJoin:ve,lineCap:wn};return x<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,G,P,2,k,E])(R))(()=>t.strokePath([1,U,B,2,k,E])(R)):t.fillPath(V)({color:r.arrowFill,flat:!0})}return n.pure()}},AJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=Ze(n),o=t.popAlpha,u=FJ(t);return s=>a=>c=>f=>{const d=zN(8)(c);if(f.hi<=f.lo)return n.pure();const l=UN(d)(f.lo)(f.hi);if(l.length===0)return n.pure();const _={color:s.edge,width:s.wobble?2:.9375,lineJoin:ve,lineCap:wn},h=s.wobble?ae(-10)(4)(qi(l)).value:0,p=s.wobble?oJ(h)(l):l;return r.bind(s.wobble?i(m=>r.bind(t.pushAlpha(m.alpha))(()=>r.bind(t.strokePath(m.path)(_))(()=>o)))((()=>{const m=qi(l);return p.length<2?[]:Vr(TJ)(m)(!1)(p)})()):t.strokePath(MN(l))(_))(()=>{const m=u(s)(p);return f.hi>=.999?m:n.pure()})}},q_=t=>{const e=AJ(t),n=t.Monad0().Applicative0(),r=Ze(n);return i=>o=>u=>{const s=a=>{const c=Vt(f=>a.x>=f._2.x-1&&a.x<=f._2.x+f._2.w+1&&a.y>=f._2.y-1&&a.y<=f._2.y+f._2.h+1)(Pe(o.nodes));return c.tag==="Just"?v("Just",c._1._2):T};return r(a=>{const c=Rn(a._1)(u.edges);if(c.tag==="Just")return e(i)(a._1)((()=>{const f=(()=>{if(0<a._2.length){const l=s(a._2[0]);if(l.tag==="Just")return Te(T_(Jr(7)(l._1))(Te(a._2)))}return a._2})(),d=f.length-1|0;if(d>=0&&d<f.length){const l=s(f[d]);if(l.tag==="Just")return T_(Jr(7)(l._1))(f)}return f})())((()=>{if(c._1.tag==="Retracted")return{lo:0,hi:0};if(c._1.tag==="Extended")return{lo:0,hi:1};if(c._1.tag==="Extending")return{lo:0,hi:c._1._2};if(c._1.tag==="Retracting"){if(c._1._1==="FromSource")return{lo:c._1._2,hi:1};if(c._1._1==="FromTarget")return{lo:0,hi:1-c._1._2};if(c._1._1==="FromBoth")return{lo:c._1._2/2,hi:1-c._1._2/2}}g()})());if(c.tag==="Nothing")return n.pure();g()})(Pe(o.edges))}},MJ=t=>e=>{const n=o=>{const u=fe(o)(t.nodes);if(u.tag==="Nothing")return!1;if(u.tag==="Just"){const s=u._1;return!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,Pe(t.edges))}g()},r=J(o=>u=>(o*31|0)+In(u)|0)(5381)(Zn(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},Pe(t.edges))}g()};return J(o=>u=>{const s=u._2;return dJ(a=>{if(a.tag==="Nothing")return v("Just",s);if(a.tag==="Just")return v("Just",{t:Hi(a._1.t)(s.t),angle:s.t>=a._1.t?s.angle:a._1.angle,bigCircle:a._1.bigCircle||s.bigCircle,frameHash:a._1.frameHash});g()})(u._1)(o)})(Q)(Tt(Pe(e.tokens))(o=>{if(o._2.tag==="Filling"){const u=o._2._1.node;return[b(u,{t:1,angle:(()=>{const s=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)(Pe(t.edges));if(0<s.length){const a=s[0].length-1|0,c=a<1?[]:bt(0,a,s[0]),f=c.length-1|0;if(f>=0&&f<c.length){const d=s[0].length-1|0;return d>=0&&d<s[0].length?fr(s[0][d].y-c[f].y)(s[0][d].x-c[f].x):0}s[0].length-1|0}return 0})(),bigCircle:n(u)||i(u),frameHash:r})]}if(o._2.tag==="Travelling"){if(o._2._1.progress>=.75)return[b(o._2._1.target,{t:(o._2._1.progress-.75)/.25,angle:(()=>{const u=Rn(o._2._1.edge)(t.edges);if(u.tag==="Just"){const s=u._1.length-1|0,a=s<1?[]:bt(0,s,u._1),c=a.length-1|0;if(c>=0&&c<a.length){const f=u._1.length-1|0;return f>=0&&f<u._1.length?fr(u._1[f].y-a[c].y)(u._1[f].x-a[c].x):0}return u._1.length-1|0,0}if(u.tag==="Nothing")return 0;g()})(),bigCircle:n(o._2._1.target)||i(o._2._1.target),frameHash:r})];if(o._2._1.progress<.25)return[b(o._2._1.source,{t:o._2._1.progress/.25,angle:(()=>{const u=Rn(o._2._1.edge)(t.edges);if(u.tag==="Just")return 1<u._1.length&&0<u._1.length?fr(u._1[1].y-u._1[0].y)(u._1[1].x-u._1[0].x):0;if(u.tag==="Nothing")return 0;g()})(),bigCircle:n(o._2._1.source)||i(o._2._1.source),frameHash:r})]}return[]}))},OJ=t=>J(e=>n=>(e*31|0)+In(n)|0)(5381)(Zn(t.frameTitle)),H_=t=>{const e=M_(t),n=t.Monad0().Applicative0(),r=Ze(n);return i=>o=>u=>s=>{const a=OJ(s),c=MJ(u)(s);return r(f=>{const d=fe(f._1)(s.nodes);if(d.tag==="Just")return e(i)(o)((()=>{const l=fe(f._1)(s.nodeFadeAlpha);if(l.tag==="Nothing")return 1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=fe(f._1)(c);return l.tag==="Just"?v("Just",l._1):l.tag==="Nothing"&&lJ(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()})(Pe(u.nodes))}},$_=t=>t,X_=t=>e=>{const n=e.vw/e.vh,r=e.vh*t,i={...e,vx:e.vx-(r-e.vw)/2,vw:r},o=e.vw/t,u={...e,vy:e.vy-(o-e.vh)/2,vh:o};return t<=0||e.vw<=0||e.vh<=0?e:t>n?i:t<n?u:e},RJ=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},Y_=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},V_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ma=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},BJ=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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},zJ=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},WJ=t=>e=>{const n=He(t.angle),r=en(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},qJ=t=>[t.box.ground.a,t.box.ground.b,t.box.ground.c,t.box.ground.d,t.box.top.a,t.box.top.b,t.box.top.c,t.box.top.d],Ur=t=>e=>{const n=r=>RJ(0)(255)(de(Vn(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)*en(t.angle),y:(e+n)*He(t.angle)-r}),wr=t=>{const e=Mt(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()},HJ=t=>e=>n=>r=>i=>{const o=(()=>{if(t==="Forward")return i;if(t==="Backward")return Te(i);g()})();if(0<o.length){const s=mr(o)(Y_(0)(1)(Xr(n)(r)(e)));if(s.tag==="Nothing")return o[0];if(s.tag==="Just")return s._1;g()}const u=mr(o)(Y_(0)(1)(Xr(n)(r)(e)));if(u.tag==="Nothing")return{x:0,y:0};if(u.tag==="Just")return u._1;g()},$J=t=>{const e=Mt(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()},XJ=t=>{const e=Mt(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:V_(r.minX)(i.x),minY:V_(r.minY)(i.y),maxX:ma(r.maxX)(i.x),maxY:ma(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{vx:n.minX-40,vy:n.minY-40,vw:n.maxX-n.minX+80,vh:n.maxY-n.minY+80}}g()},YJ=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>{const o=i.box,u=i.np,s={color:r.nodeStroke,width:1,lineJoin:ve,lineCap:_n};return e.bind(t.fillStrokePath(wr([o.ground.d,o.ground.c,o.top.c,o.top.d]))({color:Ur(.66)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(wr([o.ground.b,o.ground.c,o.top.c,o.top.b]))({color:Ur(.82)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(wr([o.top.a,o.top.b,o.top.c,o.top.d]))({color:Ur(1)(r.nodeFill),flat:!0})(s))(()=>t.drawTextAffine(WJ(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:$r,baseline:or}))))}},VJ=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>o=>{const u={color:r.tokenOutsideStroke,width:1,lineJoin:ve,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(wr([Ce(n)(s)(f)(i),m,h,p]))({color:Ur(.66)(r.tokenOutsideFill),flat:!0})(u))(()=>e.bind(t.fillStrokePath(wr([y,m,h,_]))({color:Ur(.82)(r.tokenOutsideFill),flat:!0})(u))(()=>t.fillStrokePath(wr([l,_,h,p]))({color:Ur(1)(r.tokenOutsideFill),flat:!0})(u)))}},UJ=t=>{const e=VJ(t);return n=>r=>i=>o=>{if(o.tag==="Travelling"){const u=BJ(o._1.edge)(i.edges);return u.tag==="Just"?v("Just",(()=>{const s=HJ(o._1.direction)(o._1.progress)(o._1.holdPre)(o._1.holdPost)(u._1);return{depth:s.x+s.y,draw:e(n)(r)(0)(s)}})()):T}if(o.tag==="Filling"){const u=zJ(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}},ZJ={angle:.5235987755982988,boxHeight:26,transparentBg:!0},KJ=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:Ce(t)(e.x)(e.y)(0),b:Ce(t)(r)(e.y)(0),c:Ce(t)(r)(n)(0),d:Ce(t)(e.x)(n)(0)},top:{a:Ce(t)(e.x)(e.y)(t.boxHeight),b:Ce(t)(r)(e.y)(t.boxHeight),c:Ce(t)(r)(n)(t.boxHeight),d:Ce(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},U_=t=>e=>W(n=>({np:n,box:KJ(t)(n)}))((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Ct($t.foldr,n(e.nodes,Ht))})()),jJ=t=>e=>[...Tt(U_(t)(e))(qJ),...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Tt(Ct($t.foldr,n(e.edges,Ht)))(W(r=>Ce(t)(r.x)(r.y)(0)))})()],tT=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=ma(1e-4)(Le(n*n+e*e)),i=e/r,o=n/r,u=t.to.y-i*7,s=t.to.x-o*7;return wr([t.to,{x:s-i*3,y:u+o*3},{x:s+i*3,y:u-o*3}])},eT=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>i=>o=>u=>s=>{const a=Ce(r)(s.x)(s.y)(0),c=Ce(r)(u.x)(u.y)(0);return e.Bind1().bind(t.strokePath($J([c,a]))({color:i.edge,width:1.5,lineJoin:ve,lineCap:wn}))(()=>{const f=t.fillPath(tT({from:c,to:a}))({color:i.arrowFill,flat:!0});return o?f:n.pure()})}},nT=t=>{const e=eT(t);return n=>r=>i=>{const o=we(Cn,i,bt(1,i.length,i)),u=o.length-1|0;return Ft(s=>a=>({depth:(a._1.x+a._1.y+a._2.x+a._2.y)/2,draw:e(n)(r)(s===u)(a._1)(a._2)}))(o)}},rT=t=>{const e=YJ(t),n=UJ(t),r=nT(t),i=t.Monad0(),o=O_(t),u=bu(i.Applicative0())(zt);return s=>a=>c=>f=>{const d=_a(a),l=[...(()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,qt("Cons",h._4,_(h._6,p)));g()};return Tt(Ct($t.foldr,_(c.edges,Ht)))(r(s)(d))})(),...W(_=>({depth:_.box.depth,draw:e(s)(d)(_)}))(U_(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)(XJ(jJ(s)(c))))(()=>u(_=>_.draw)(Lt(_=>h=>ut.compare(_.depth)(h.depth))(l)))}},Z_=(t,e)=>({tag:t,_1:e}),iT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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},oT=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},uT=Z_("ResolvedLabels"),sT=t=>{const e=Vt(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return So(t);g()},aT=t=>e=>n=>{const r=n.frameTitle===""?0:40,i=ju(e)(n.camera);return(()=>{if(t.outputAspect.tag==="Nothing")return $_;if(t.outputAspect.tag==="Just")return X_(t.outputAspect._1);g()})()({vx:i.x-t.padding,vy:i.y-t.padding-r,vw:i.w+2*t.padding,vh:i.h+2*t.padding+r})},cT=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=iT(e._1)(t.segment.layout.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1.x*t.segment.placement.scale+t.segment.placement.tx,i=n._1.y*t.segment.placement.scale+t.segment.placement.ty,o=n._1.w*t.segment.placement.scale,u=n._1.h*t.segment.placement.scale;return[1,r,i,2,r+o,i,2,r+o,i+u,2,r,i+u,5]}}g()},gT=t=>{const e=t.Monad0(),n=e.Bind1();return r=>i=>{if(r==="")return e.Applicative0().pure();const o=i.vh/720,u=56*o,s={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:700};return n.bind(t.measureText(s)(r))(a=>{const c=u+16*o*2,f=a+28*o*2,d=i.vy+i.vh/2,l=i.vx+i.vw/2;return n.bind(t.drawRoundedRect({x:l-f/2,y:d-c/2,w:f,h:c})(16*o)(v("Just",{color:{r:255,g:255,b:255,a:235},flat:!0}))(v("Just",{color:{r:0,g:0,b:0,a:255},width:1.5*o,lineJoin:ve,lineCap:wn})))(()=>t.drawText({x:l,y:d,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:$r,baseline:or}))})}},fT=t=>{const e=t.Monad0(),n=e.Bind1();return r=>i=>{if(r==="")return e.Applicative0().pure();const o=i.vh/720,u=15*o,s={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:600};return n.bind(t.measureText(s)(r))(a=>{const c=i.vy+12*o,f=u+6*o*2,d=a+11*o*2,l=i.vx+i.vw/2;return n.bind(t.drawRoundedRect({x:l-d/2,y:c,w:d,h:f})(f/2)(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:ve,lineCap:wn})))(()=>t.drawText({x:l,y:c+f/2,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:$r,baseline:or}))})}},_T=t=>{const e=W_(t),n=pa(t),r=t.Monad0(),i=r.Bind1(),o=O_(t),u=r.Applicative0(),s=q_(t),a=H_(t)(fa),c=bJ(t),f=B_(t),d=R_(t),l=kJ(t),_=gT(t),h=fT(t);return p=>m=>y=>x=>N=>w=>L=>{const k=_a(p.theme),E=(()=>{if(L.tag==="ResolvedLabels")return e(k)(N)(w);if(L.tag==="SpringLabels")return n(k)(N)(w)(L._1);g()})();return i.bind(o(k)(p.transparentBg)(m)(x))(()=>i.bind((()=>{const O=i.bind(s(k)(N)(w))(()=>i.bind(a(k)(N)(w))(()=>i.bind(c(k)(N)(w))(()=>i.bind(f(k)(x)(N)(w))(()=>i.bind(d(jx)(k)(N)(w))(()=>i.bind(E)(()=>{const Y=l(k)(N)(w);return w.staticKind!=="Animated"?Y:u.pure()}))))));return y?O:u.pure()})())(()=>i.bind(p.watermark===""?t.Monad0().Applicative0().pure():t.drawText({x:x.vx+6,y:x.vy+6,content:p.watermark,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:na,baseline:qx}))(()=>w.staticKind==="TitleCard"?_(w.frameTitle)(x):h(w.frameTitle)(x))))}},dT=t=>{const e=t.Monad0(),n=W_(t),r=pa(t),i=e.Bind1(),o=q_(t),u=H_(t),s=B_(t),a=t.popTransform,c=R_(t),f=t.popBakedTransform,d=t.popClip,l=t.popAlpha;return _=>h=>p=>m=>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=_a(_.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},O=11*y.segment.placement.scale*h>=5?fa:hJ,Y=(()=>{if(O==="LabelsHidden")return e.Applicative0().pure();if(O==="LabelsShown")return p.tag==="Leaf"?n(w)(L)(x):r(w)(L)(x)(p);g()})(),et=cT(m)((()=>{const G=y.segment.path.length-1|0;return G>=0&&G<y.segment.path.length?v("Just",y.segment.path[G]):T})());return i.bind(t.pushAlpha(y.bgAlpha))(()=>i.bind(t.pushClip(et)(eu))(()=>i.bind(t.pushTransform(N))(()=>i.bind(o(w)(L)(x))(()=>i.bind(u(O)(w)(L)(x))(()=>i.bind(s(w)(E)(L)(x))(()=>i.bind(a)(()=>i.bind(t.pushBakedTransform(N))(()=>i.bind(c(tN)(w)(L)(x))(()=>i.bind(f)(()=>i.bind(t.pushTransform(N))(()=>i.bind(Y)(()=>i.bind(a)(()=>i.bind(d)(()=>l))))))))))))))}},lT=t=>e=>{const n=ju(t)(e);return{vx:n.x,vy:n.y,vw:n.w,vh:n.h}},Zr=t=>e=>e.diving||e.levels.length>1?(()=>{if(t.outputAspect.tag==="Nothing")return $_;if(t.outputAspect.tag==="Just")return X_(t.outputAspect._1);g()})()(lT(e.rootLayout)(e.camera)):aT(t)(e.rootLayout)({...So(e).state,camera:e.camera}),K_=t=>{const e=rT(t),n=t.Monad0(),r=n.Applicative0(),i=n.Bind1(),o=dT(t),u=_T(t);return s=>a=>c=>{if(s.theme==="Isometric")return e({...ZJ,transparentBg:s.transparentBg})(s.theme)(So(c).segment.layout)(So(c).state);const f=Zr(s)(c),d=_=>h=>{if(h.length===0)return r.pure();const p=Mt(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=Mt(_=>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/oT(1)(Ye(c.rootLayout).w):1)(h.role==="Active"||h.role==="FlyThrough")(f)(h.segment.layout)(sT(c).state)(_.length===0&&a.tag!=="Leaf"?Z_("SpringLabels",a):uT))(()=>d(h)(_))}g()}},j_=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},hT=ha(f_),t1=K_(f_),e1=t=>{const e=t.vx+t.vw-4,n=t.vy+t.vh-4,r=t.vx+4,i=t.vy+4,o=u=>{if(u.tag==="Leaf")return Q;if(u.tag==="Node")return Wt("Node",u._1,u._2,u._3,{...u._4,x:j_(r)(e-u._4.w)(u._4.x),y:j_(i)(n-u._4.h)(u._4.y)},o(u._5),o(u._6));g()};return o},pT=t=>e=>n=>r=>i=>o=>u=>{const s={padding:8,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?T:v("Just",r.width/r.height)},a=lN(n)(r);return()=>{const c=a(),f=i.levels.length-1|0;if(f>=0&&f<i.levels.length){const l=hT(i.levels[f].segment.layout)(i.levels[f].state)(c)(),_=ta(o)(e1(Zr(s)(i))(l))(u);return t1(s)(_.applied)(i)(c)(),_.springs}const d=ta(o)(e1(Zr(s)(i))(Q))(u);return t1(s)(d.applied)(i)(c)(),d.springs}},mT=t=>t,$i=t=>t,ya=$i("Light"),yT=$i("Dark"),xT=$i("Blueprint"),NT=$i("Whiteboard"),JT=$i("Isometric"),TT=mT("TransparentBackground"),ur=t=>"rgb("+oe(t.r)+","+oe(t.g)+","+oe(t.b)+")",kn=ci(si("Fixed",ai(0)(20)(4))),wT=t=>"translate("+kn(t.tx)+","+kn(t.ty)+") scale("+kn(t.sx)+","+kn(t.sy)+")",kt=ci(si("Fixed",ai(0)(20)(2))),xa=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(kt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===2){e.push("L"),e.push(kt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===3){e.push("Q"),e.push(kt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),n=r+5|0;continue}if(i._1===4){e.push("C"),e.push(kt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+5|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+6|0;return o>=0&&o<t.length?t[o]:0})())),n=r+7|0;continue}if(i._1===5){e.push("Z"),n=r+1|0;continue}n=t.length;continue}g()}return xo(" ")(e)},vT={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},Na=(()=>{const t=tr("&")("&"),e=tr("<")("<"),n=(()=>{const r=tr(">")(">"),i=(()=>{const o=tr('"')(""");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),bT=t=>{if(t.style==="RunText")return"<tspan>"+Na(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+Na(t.text)+"</tspan>";g()},Fe=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},kT=t=>e=>{const n=[];let r=0;const i=o=>{const u=o>=0&&o<e.length?t.sx*e[o]+t.tx:t.sx*0+t.tx;return()=>{n.push(u),n.push((()=>{const s=o+1|0;return s>=0&&s<e.length?t.sy*e[s]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const o=r,u=o>=0&&o<e.length?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},lu=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return kT(r._1)(e);g()}},n1={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>vT},LT={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>n1},ET={pure:t=>e=>()=>t,Apply0:()=>n1},CT={Applicative0:()=>ET,Bind1:()=>LT},ST=t=>e=>'<defs><pattern id="'+t+'" x="0" y="0" width="'+kt(e.tile)+'" height="'+kt(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+kt(e.tile)+'" height="'+kt(e.tile)+'" fill="'+ur(e.bgColor)+'" fill-opacity="'+kt(rt(e.bgColor.a)/255)+'"/>')+'<circle cx="'+kt(e.tile/2)+'" cy="'+kt(e.tile/2)+'" r="'+kt(e.dotRadius)+'" fill="'+ur(e.dotColor)+'"/></pattern></defs><rect x="'+kt(e.viewport.vx)+'" y="'+kt(e.viewport.vy)+'" width="'+kt(e.viewport.vw)+'" height="'+kt(e.viewport.vh)+'" fill="url(#'+t+')"/>',r1=t=>e=>'<path d="'+xa(t)+'" fill="'+ur(e)+'" fill-opacity="'+kt(rt(e.a)/255)+'"/>',GT=t=>e=>n=>r=>'<rect x="'+kt(t.x)+'" y="'+kt(t.y)+'" width="'+kt(t.w)+'" height="'+kt(t.h)+'" rx="'+kt(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+ur(n._1.color)+'" fill-opacity="'+kt(rt(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';g()})()+(()=>{if(r.tag==="Just")return' stroke="'+ur(r._1.color)+'" stroke-opacity="'+kt(rt(r._1.color.a)/255)+'" stroke-width="'+kt(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";g()})()+'"';if(r.tag==="Nothing")return"";g()})()+"/>",i1=t=>e=>'<path d="'+xa(t)+'" fill="none" stroke="'+ur(e.color)+'" stroke-opacity="'+kt(rt(e.color.a)/255)+'" stroke-width="'+kt(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";g()})()+'"/>',o1=t=>{const e=gg(Ar(t.content));return'<text x="'+kt(t.x)+'" y="'+kt(t.y)+'"'+(()=>{if(t.baseline==="BaselineTop")return' dy="0.8em"';if(t.baseline==="BaselineMiddle")return' dy="0.32em"';if(t.baseline==="BaselineAlphabetic"||t.baseline==="BaselineBottom")return"";g()})()+' fill="'+ur(t.color)+'" fill-opacity="'+kt(rt(t.color.a)/255)+'" font-size="'+kt(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+oe(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";g()})()+'">'+(e.length===1&&e[0].style==="RunText"?Na(e[0].text):xo("")(W(bT)(e)))+"</text>"},PT=t=>"matrix("+kn(t.a)+" "+kn(t.b)+" "+kn(t.c)+" "+kn(t.d)+" "+kn(t.e)+" "+kn(t.f)+")",u1={fillPath:t=>e=>n=>{const r=lu(n)(t);return()=>{const i=r();return Fe(r1(i)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=lu(n)(t);return()=>{const i=r(),o=n.bake.value;return Fe(i1(i)((()=>{if(o.tag==="Nothing")return e;if(o.tag==="Just")return{...e,width:o._1.sx*e.width};g()})()))(n)()}},fillStrokePath:t=>e=>n=>r=>{const i=lu(r)(t);return()=>{const o=i(),u=r.bake.value;return Fe(r1(o)(e.color)+i1(o)((()=>{if(u.tag==="Nothing")return n;if(u.tag==="Just")return{...n,width:u._1.sx*n.width};g()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>i=>{const o=i.bake;return()=>{const u=o.value;return Fe(GT((()=>{if(u.tag==="Nothing")return t;if(u.tag==="Just")return{x:u._1.sx*t.x+u._1.tx,y:u._1.sy*t.y+u._1.ty,w:u._1.sx*t.w,h:u._1.sy*t.h};g()})())((()=>{if(u.tag==="Nothing")return e;if(u.tag==="Just")return u._1.sx*e;g()})())(n)(r.tag==="Just"?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 Fe(o1((()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return{...t,x:r._1.sx*t.x+r._1.tx,y:r._1.sy*t.y+r._1.ty,font:{...t.font,size:r._1.sx*t.font.size}};g()})()))(e)()}},drawTextAffine:t=>e=>Fe((()=>{const n='transform="'+PT(t)+'"';return(n===""?"<g>":"<g "+n+">")+o1(e)+"</g>"})()),pushTransform:t=>Fe((()=>{const e='transform="'+wT(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:Fe("</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=lu(n)(t)(),u="clip"+oe(i);return Fe((()=>{const s='clip-path="url(#'+u+')"';return'<defs><clipPath id="'+u+'"><path d="'+xa(o)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";g()})()+"/></clipPath></defs>"+(s===""?"<g>":"<g "+s+">")})())(n)()}},popClip:Fe("</g>"),pushBlend:t=>Fe((()=>{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:Fe("</g>"),pushAlpha:t=>Fe((()=>{const e='opacity="'+kt(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:Fe("</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=>Fe('<rect x="'+kt(e.viewport.vx)+'" y="'+kt(e.viewport.vy)+'" width="'+kt(e.viewport.vw)+'" height="'+kt(e.viewport.vh)+'" fill="'+ur(t)+'" opacity="'+kt(rt(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,Fe(ST("bg-dots-"+oe(r))(t))(e)()}},measureText:t=>e=>n=>{const r=Bf(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=zf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Zf,Monad0:()=>CT},IT=K_(u1),DT=ha(u1),QT=t=>e=>n=>r=>i=>{const o={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:n,outputAspect:t},u=Zr(o)(i);return{viewBox:kt(u.vx)+" "+kt(u.vy)+" "+kt(u.vw)+" "+kt(u.vh),body:(()=>{const s=[],a={value:0},c={value:0},f={value:0},d={value:T};return IT(o)(e)(i)({out:s,maskDepth:a,clipCounter:c,patternCounter:f,viewport:u,bake:d})(),xo("")(s)})(),vx:u.vx,vy:u.vy,vw:u.vw,vh:u.vh}},FT=t=>e=>n=>r=>i=>o=>{const u={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;g()})(),outputAspect:t},s=ta(i)((()=>{const a=[],c={value:0},f={value:0},d={value:0},l={value:T},_=r.levels.length-1|0;return _>=0&&_<r.levels.length?DT(r.levels[_].segment.layout)(r.levels[_].state)({out:a,maskDepth:c,clipCounter:f,patternCounter:d,viewport:Zr(u)(r),bake:l})():Q})())(o);return{parts:QT(t)(s.applied)(e)(n)(r),springs:s.springs}},Xi=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(i=>n(i._1)(i._2)),Apply0:()=>s1(t)}),s1=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>i=>o=>e.map(u=>b(r(u._1),u._2))(i(o))};return{apply:(()=>{const r=Xi(t);return i=>o=>r.bind(i)(u=>r.bind(o)(s=>Yi(t).pure(u(s))))})(),Functor0:()=>n}},Yi=t=>({pure:e=>n=>t.Applicative0().pure(b(e,n)),Apply0:()=>s1(t)}),AT=t=>{const e={Applicative0:()=>Yi(t),Bind1:()=>Xi(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},Ja=(t,e)=>({tag:t,_1:e}),Ta=t=>t,Bn=(t,e)=>({tag:t,_1:e}),ye=AT($n),At=Xi($n),Ie=ye.state(t=>b(t,t)),te=Yi($n),zn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},a1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},hu=bu(te)(zt),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},MT=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},OT=(()=>{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)})())})(),RT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},pu=t=>e=>n=>J(r=>i=>t.Bind1().bind(r)(o=>e(o)(i)))(t.Applicative0().pure(n)),BT=J(t=>e=>j(C)(e)()(t))(Q),zT=(()=>{const t=(e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=j(C)(a._1)()(s),i=a._2;continue}g()}return u})(Q);return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._3,n(r._6,i)));g()};return n(e,Ht)})())})(),WT=Bn("Exit"),qT=Ta("AnimatedKeyframe"),HT=Ta("Still"),$T=Ta("Title"),XT=t=>Ja("Par",t),c1=t=>Ja("Seq",t),YT=t=>e=>n=>{const r=cr(Xt,T,i=>i._1===t,n);if(r.tag==="Just"){const i=Xn(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 Ot(n)(b(t,e));g()},VT=t=>e=>W(n=>n._1===t?b(n._1,{...n._2,label:v("Just",e)}):b(n._1,n._2)),xe=t=>ye.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()})())),UT=t=>At.bind(ye.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>At.bind(Ie)(e=>{if(e.error.tag==="Just")return te.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!zn(t.op._1.id)(e.currNodes))return xe("cannot enter node "+t.op._1.id+": does not exist");if(!a1(t.op._1.id)(e.interiorOf))return xe("cannot enter node "+t.op._1.id+": it has no `inside` block");if(Be(fn)(t.op._1.id)(e.enterStack))return xe("cannot enter node "+t.op._1.id+": already entered");const n=t.op._1;return ye.state(r=>b(void 0,{...r,enterStack:Ot(r.enterStack)(n.id),scenes:Ot(r.scenes)(mi("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=ii(e.enterStack);if(n.tag==="Nothing")return xe("`exit` without a matching `enter`");if(n.tag==="Just"){const r=n._1.init;return ye.state(i=>b(void 0,{...i,enterStack:r,scenes:Ot(i.scenes)(ql)}))}g()}return te.pure()}g()})),ZT=t=>At.bind(Ie)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+oe(e.kfCounter);if(Re(i=>i.id===n,e.keyframes))return xe("duplicate frame name "+n);const r={...e,keyframes:Ot(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges,kind:yi}),kfCounter:e.kfCounter+1|0,currentKf:v("Just",n)};return ye.state(i=>b(void 0,r))}),KT=hu(t=>At.bind(Ie)(e=>{if(e.error.tag==="Just")return te.pure();if(e.error.tag==="Nothing")return a1(t.node)(e.interiorOf)?xe("node "+t.node+" has more than one `inside` block"):ye.state(n=>b(void 0,{...n,interiorOf:j(C)(t.node)(t.doc)(n.interiorOf)}));g()})),jT=t=>e=>{const n=e.from+"->"+e.to,r=e.newFrom+"->"+e.newTo,i=Pt("Left","cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist"),o=Wn(n)(t.currEdges)?Pt("Right",void 0):i;return(()=>{if(o.tag==="Left"){const u=o._1;return s=>Pt("Left",u)}if(o.tag==="Right"){const u=o._1;return s=>s(u)}g()})()(()=>{const u="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newFrom;if(!zn(e.newFrom)(t.currNodes))return Pt("Left",u);const s="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo;if(!zn(e.newTo)(t.currNodes))return Pt("Left",s);const a="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists";return n!==r&&Wn(r)(t.currEdges)?Pt("Left",a):Pt("Right",{nextCurrEdges:j(C)(r)()(ui(C)(n)(t.currEdges)),newId:r,newEdge:{id:r,from:{node:e.newFrom,port:T},to:{node:e.newTo,port:T},label:T}})})},g1={graphNodes:[],graphEdges:Q,currNodes:Q,currEdges:Q,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:T,currentLine:0,currentColumn:0,error:T,enterStack:[],interiorOf:Q},tw=At.bind(Ie)(t=>{if(t.error.tag==="Just")return te.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return ye.state(n=>b(void 0,{...n,scenes:Ot(n.scenes)(mi("Hold",e))}))}if(t.currentKf.tag==="Nothing")return te.pure()}g()}),f1=t=>e=>At.bind(Ie)(n=>{const r="ev-"+oe(n.eventCounter);return At.bind((()=>{const i={...n,eventCounter:n.eventCounter+1|0};return ye.state(o=>b(void 0,i))})())(()=>te.pure({events:[{id:r,kind:e,when:t}],firstId:v("Just",r),lastId:v("Just",r)}))}),ew=t=>e=>{if(e.tag==="Token"){const n=e._1;return At.bind(Ie)(r=>{const i=!zn(n.from)(r.currNodes),o=!zn(n.to)(r.currNodes);if(i||o)return At.bind(xe(i?o?"token references unknown node: "+n.from+", "+n.to:"token references unknown node: "+n.from:o?"token references unknown node: "+n.to:"token references unknown node: "))(()=>te.pure({events:[],firstId:T,lastId:T}));const u=n.to+"->"+n.from,s=n.from+"->"+n.to;return Wn(s)(r.currEdges)?f1(t)(wc("SendToken",{from:n.from,to:n.to,edge:s,direction:zl,labels:n.labels})):Wn(u)(r.currEdges)?f1(t)(wc("SendToken",{from:n.from,to:n.to,edge:u,direction:Wl,labels:n.labels})):At.bind(xe("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>te.pure({events:[],firstId:T,lastId:T}))})}return te.pure({events:[],firstId:T,lastId:T})},nw=t=>e=>{if(0<t.length){const n=t[0];return At.bind(ye.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>xe(e))}return xe(e)},rw=t=>xt(e=>MT(e)(t.graphEdges))(Ct(ni,OT(t.currEdges))),iw=t=>e=>{const n=st(i=>i.from.node===e.id||i.to.node===e.id,rw(t)),r=pu(Wa)(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(!Wn(u)(t.currEdges))return Pt("Left",c);const f="via "+o.from+" "+o.to+": no edge "+e.id+"\u2192"+o.to;if(!Wn(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 Wn(a)(t.currEdges)||RT(a)(i.synthesized)?Pt("Left",d):Pt("Right",{consumed:j(C)(u)()(j(C)(s)()(i.consumed)),synthesized:j(C)(a)({id:a,from:{node:o.from,port:T},to:{node:o.to,port:T},label: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=>!Wn(s.id)(o),n);return u.length===0?Pt("Right",{nextCurrEdges:Ee(C.compare,ke,Sn(C.compare,t.currEdges,BT(W(s=>s.id)(n))),zT((()=>{const s=a=>{if(a.tag==="Leaf")return Q;if(a.tag==="Node")return Wt("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 ("+xo(", ")(W(s=>s.from.node+"\u2192"+s.to.node)(u))+"). Use -edge to drop them or `via a b` to merge "+e.id+"'s endpoints.")})},wa=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq")return Tt(t._1)(wa);g()},ow=At.bind(Ie)(t=>{if(t.error.tag==="Just")return te.pure();if(t.error.tag==="Nothing"){const e=t.enterStack.length-1|0;return e>=0&&e<t.enterStack.length?xe("entered node "+t.enterStack[e]+" was never exited"):te.pure()}g()}),uw=t=>({nodes:W(ji)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,qt("Cons",n._4,e(n._6,r)));g()};return Ct($t.foldr,e(t.graphEdges,Ht))})(),constraints:[]}),sw=t=>{if(t.tag==="AddNode"){const e=t._1;return ye.state(n=>b(void 0,{...n,graphNodes:YT(e.id)({id:e.id,size:b(1,1),ports:[],label:v("Just",e.label),shape:e.shape})(n.graphNodes),currNodes:j(C)(e.id)()(n.currNodes)}))}if(t.tag==="DelNode"){const e=t._1;return At.bind(Ie)(n=>{if(!zn(e.id)(n.currNodes))return xe("cannot delete node "+e.id+": does not exist");const r=iw(n)(e);if(r.tag==="Left")return xe(r._1);if(r.tag==="Right"){const i=r._1;return ye.state(o=>b(void 0,{...o,currNodes:ui(C)(e.id)(o.currNodes),currEdges:i.nextCurrEdges,graphEdges:Ee(C.compare,ke,i.synthesized,o.graphEdges)}))}g()})}if(t.tag==="ModNode"){const e=t._1;return At.bind(Ie)(n=>{if(!zn(e.id)(n.currNodes))return xe("cannot modify node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=e.label._1;return ye.state(i=>b(void 0,{...i,graphNodes:VT(e.id)(r)(i.graphNodes)}))}if(e.label.tag==="Nothing")return te.pure();g()})}if(t.tag==="AddEdge"){const e=t._1;return At.bind(Ie)(n=>{const r=!zn(e.from)(n.currNodes),i=!zn(e.to)(n.currNodes);if(r||i)return xe("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 ye.state(u=>b(void 0,{...u,graphEdges:j(C)(o)({id:o,from:{node:e.from,port:T},to:{node:e.to,port:T},label:e.label})(u.graphEdges),currEdges:j(C)(o)()(u.currEdges)}))})}if(t.tag==="DelEdge"){const e=t._1;return At.bind(Ie)(n=>{const r=e.from+"->"+e.to;return Wn(r)(n.currEdges)?ye.state(i=>b(void 0,{...i,currEdges:ui(C)(r)(i.currEdges)})):xe("cannot delete edge "+e.from+"\u2192"+e.to+": does not exist")})}if(t.tag==="RepointEdge"){const e=t._1;return At.bind(Ie)(n=>{const r=jT(n)(e);if(r.tag==="Left")return xe(r._1);if(r.tag==="Right"){const i=r._1;return ye.state(o=>b(void 0,{...o,currEdges:i.nextCurrEdges,graphEdges:j(C)(i.newId)(i.newEdge)(o.graphEdges)}))}g()})}return te.pure()},aw=t=>At.bind(ye.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>sw(t.op)),_1=t=>e=>n=>At.bind(hu(aw)(n))(()=>At.bind(Ie)(r=>{const i=e.tag==="Just"&&e._1!==""?e._1:"kf-"+oe(r.kfCounter);if(Re(u=>u.id===i,r.keyframes))return xe("duplicate frame name "+i);const o={...r,keyframes:Ot(r.keyframes)({id:i,nodes:r.currNodes,edges:r.currEdges,kind:t}),kfCounter:r.kfCounter+1|0,currentKf:v("Just",i),scenes:(()=>{if(r.currentKf.tag==="Nothing")return r.scenes;if(r.currentKf.tag==="Just")return Ot(r.scenes)(mi("Structural",{from:r.currentKf._1,to:i,focus:T}));g()})()};return ye.state(u=>b(void 0,o))})),d1=t=>e=>{const n=wa(e.ops),r=st(o=>o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge",n),i=st(o=>!(o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge"),n);if(0<i.length){const o=i[0];return At.bind(ye.state(u=>b(void 0,{...u,currentLine:o.line,currentColumn:o.column})))(()=>xe("still/title blocks hold a static snapshot; they cannot contain tokens (a -> b) or enter/exit"))}return t==="TitleCard"&&r.length===0?xe(e.name.tag==="Just"&&e.name._1!==""?'title "'+e.name._1+'" has an empty body; give it nodes/edges to title, or use a still':"title has an empty body; give it nodes/edges to title, or use a still"):At.bind(_1(t)(e.name)(r))(()=>tw)},cw=t=>e=>{const n=Mt(r=>T,r=>i=>v("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return te.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return At.bind(Vi(t)(n._1.head))(i=>At.bind(pu({Applicative0:()=>Yi($n),Bind1:()=>Xi($n)})(o=>u=>At.bind(Vi((()=>{if(o.lastId.tag==="Just")return Zu("After",o.lastId._1);if(o.lastId.tag==="Nothing")return t;g()})())(u))(s=>te.pure({events:[...o.events,...s.events],firstId:(()=>{if(o.firstId.tag==="Just")return 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=>te.pure(o)))}g()},gw=t=>e=>{const n=Mt(r=>T,r=>i=>v("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return te.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return At.bind(Vi(t)(n._1.head))(i=>At.bind(fw((()=>{if(i.firstId.tag==="Just")return Zu("With",i.firstId._1);if(i.firstId.tag==="Nothing")return t;g()})())(r))(o=>te.pure({events:[...i.events,...o.events],firstId:i.firstId,lastId:(()=>{if(i.lastId.tag==="Just")return v("Just",i.lastId._1);if(i.lastId.tag==="Nothing")return o.lastId;g()})()})))}g()},Vi=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return At.bind(ye.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>ew(t)(n.op))}if(e.tag==="Seq")return cw(t)(e._1);if(e.tag==="Par")return gw(t)(e._1);g()},fw=t=>pu({Applicative0:()=>Yi($n),Bind1:()=>Xi($n)})(e=>n=>At.bind(Vi(t)(n))(r=>te.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}),_w=t=>At.bind(Ie)(e=>{if(e.currentKf.tag==="Nothing")return xe("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return At.bind(Vi(Bl)(t))(r=>At.bind(Ie)(i=>{const o={...i,scenes:Ot(i.scenes)(mi("DataFlow",{keyframe:n,events:r.events,focus:T}))};return ye.state(u=>b(void 0,o))}))}g()}),dw=t=>{const e=wa(t.ops),n=st(o=>o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge",e),r=st(o=>o.op.tag==="Enter"||o.op.tag==="Exit",e),i=st(o=>!(o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge")&&!(o.op.tag==="Enter"||o.op.tag==="Exit"),e);return r.length!==0&&i.length!==0?nw(r)("`enter`/`exit` cannot be mixed with flow tokens in the same frame"):At.bind((()=>{const o=_1(yi)(t.name)(n);return n.length!==0?o:te.pure()})())(()=>At.bind((()=>{const o=ZT(t.name);return n.length===0&&i.length!==0?o:te.pure()})())(()=>At.bind((()=>{const o=_w(t.ops);return i.length!==0?o:te.pure()})())(()=>hu(UT)(r))))},lw=t=>At.bind(Ie)(e=>{if(e.error.tag==="Just")return te.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return dw(t);if(t.kind==="Still")return d1(Ol)(t);if(t.kind==="Title")return d1(Rl)(t)}g()}),l1=t=>At.bind(KT(t.interiors))(()=>At.bind(hu(lw)(t.frames))(()=>At.bind(ow)(()=>At.bind(Ie)(e=>{if(e.error.tag==="Just")return te.pure(Pt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=hw(t.interiors);if(n.tag==="Left")return te.pure(Pt("Left",n._1));if(n.tag==="Right")return te.pure(Pt("Right",{seed:t.seed,graph:uw(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1}))}g()})))),hw=t=>{const e=pu(Wa)(n=>r=>{const i=l1(r.doc)(g1)._1;return(()=>{if(i.tag==="Left"){const o=i._1;return u=>Pt("Left",o)}if(i.tag==="Right"){const o=i._1;return u=>u(o)}g()})()(o=>Pt("Right",j(C)(r.node)(o)(n)))})(Q)(t);if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right")return Pt("Right",e._1);g()},Kr=(t,e)=>({tag:"ParseError",_1:t,_2:e}),F=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),mu=(t,e,n)=>({tag:t,_1:e,_2:n}),pw=t=>mu("More",t),mw=t=>mu("Lift",t),yw={defer:t=>{const e=ml(t);return(n,r,i,o,u)=>yl(e)(n,r,i,o,u)}},h1={map:t=>e=>(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,c)=>r(f=>u(a,t(c)))))},xw={alt:t=>e=>(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>t(F(s,a,!1),r,i,(f,d)=>{const l=f._3;return r(_=>l?o(f,d):e(n,r,i,o,u))},u))},Functor0:()=>h1},Nw=t=>{const e=t.Monad0();return n=>r=>{const i=o=>{let u=o,s=!0,a;for(;s;){const c=u();if(c.tag==="More"){u=c._1;continue}if(c.tag==="Lift"){s=!1,a=e.Bind1().Apply0().Functor0().map(Ha)(c._1);continue}if(c.tag==="Stop"){s=!1,a=e.Applicative0().pure(ei("Done",b(c._2,c._1)));continue}g()}return a};return t.tailRecM(i)(o=>r(n,pw,mw,(u,s)=>mu("Stop",u,Pt("Left",s)),(u,s)=>mu("Stop",u,Pt("Right",s))))}},p1=(t,e,n,r,i)=>i(t,t._2),Jw={index:0,line:1,column:1},Tw=(t=>{const e=Nw(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(to)(e(F(n,Jw,!1))(r))})(H1),m1={apply:t=>e=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,c)=>r(f=>{const d=n._3&&!a._3?F(a._1,a._2,!0):a;return e(d,r,i,o,(l,_)=>r(h=>u(d._3&&!l._3?F(l._1,l._2,!0):l,c(_))))}))),Functor0:()=>h1},y1={pure:t=>(e,n,r,i,o)=>o(e,t),Apply0:()=>m1},ww={bind:t=>e=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,c)=>r(f=>e(c)(n._3&&!a._3?F(a._1,a._2,!0):a,r,i,o,u)))),Apply0:()=>m1},vw={Applicative0:()=>y1,Bind1:()=>ww},yu=t=>(e,n,r,i,o)=>n(u=>p1(e,n,r,i,(s,a)=>n(c=>i(e._3&&!s._3?F(s._1,s._2,!0):s,Kr(t,a))))),bw={empty:yu("No alternative"),Alt0:()=>xw},kw={Applicative0:()=>y1,Plus1:()=>bw},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(Ha)(i))(r.pure(ei("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return ei("Loop",qt("Cons",u._1,o));if(u.tag==="Done")return ei("Done",(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=qt("Cons",h._1,_),f=h._2;continue}g()}return l})(Ht)(o));g()})())))(Ht)})({tailRecM:t=>e=>(n,r,i,o,u)=>{const s=(a,c,f)=>t(c)(a,r,i,o,(d,l)=>{const _=a._3&&!d._3?F(d._1,d._2,!0):d;if(l.tag==="Loop")return f===0?r(h=>s(_,l._1,30)):s(_,l._1,f-1|0);if(l.tag==="Done")return u(_,l._1);g()});return s(n,e,30)},Monad0:()=>vw})(kw),Gt=t=>e=>{const n=yu("Expected "+e);return(r,i,o,u,s)=>{const a=r._1,c=r._2;return i(f=>t(F(a,c,!1),i,o,(d,l)=>{const _=d._3;return i(h=>_?u(d,l):n(r,i,o,u,s))},s))}},va=t=>(e,n,r,i,o)=>{const u=e._3,s=e._1,a=e._2;return n(c=>{const f=(d,l)=>{const _=d._3;return n(h=>_?i(F(d._1,d._2,u),l):o(e,void 0))};return n(d=>n(l=>t(F(s,a,!1),n,r,(_,h)=>f(F(_._1,_._2,!1),h),(_,h)=>n(p=>n(m=>yu("Negated parser succeeded")(_,n,r,f,(y,x)=>n(N=>o(_._3&&!y._3?F(y._1,y._2,!0):y,x))))))))})},Lw=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(F(c,f,!1),o,u,(l,_)=>{const h=l._3;return o(p=>h?s(l,_):r._1(i,o,u,s,a))},a))});g()})(T);return n=>{const r=e(n);if(r.tag==="Nothing")return yu("No alternative");if(r.tag==="Just")return r._1;g()}},Ew=t=>e=>n=>(r,i,o,u,s)=>i(a=>i(c=>i(f=>i(d=>t(r,i,o,u,(l,_)=>i(h=>i(p=>{const m=r._3&&!l._3?F(l._1,l._2,!0):l;return n(m,i,o,u,(y,x)=>i(N=>{const w=m._3&&!y._3?F(y._1,y._2,!0):y;return i(L=>i(k=>{const E=r._3&&!w._3?F(w._1,w._2,!0):w;return e(E,i,o,u,(O,Y)=>i(et=>s(E._3&&!O._3?F(O._1,O._2,!0):O,x)))}))}))}))))))),ba=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=Ph()(n);return r.tag==="Just"&&r._1===10?{index:t.index+1|0,line:t.line,column:t.column}:{index:t.index+1|0,line:t.line+1|0,column:1}}return e===9?{index:t.index+1|0,line:t.line,column:(t.column+8|0)-Un(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},Cw=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,c=i,f=o,d=No(c);if(d.tag==="Nothing"){u=!1,s=a;continue}if(d.tag==="Just"){r=d._1.tail===""?ba(a)(d._1.head)(f):ba(a)(d._1.head)(d._1.tail),i=d._1.tail,o=f;continue}g()}return s},Zt=t=>(e,n,r,i,o)=>{const u=No(e._1);if(u.tag==="Nothing")return i(e,Kr("Unexpected EOF",e._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return i(e,Kr("Expected Char",e._2));if(u._1.head>=0&&u._1.head<=65535){const s=Ic(u._1.head);return t(s)?o(F(u._1.tail,ba(e._2)(u._1.head)(u._1.tail),!0),s):i(e,Kr("Predicate unsatisfied",e._2))}}g()},ka=(t,e,n,r,i)=>t._1===""?i(F(t._1,t._2,!0),void 0):r(t,Kr("Expected EOF",t._2)),Sw=t=>(e,n,r,i,o)=>{const u=t(e._1);if(u.tag==="Left")return i(e,Kr(u._1,e._2));if(u.tag==="Right")return o(F(u._1.remainder,Cw(e._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);g()},jr=t=>Sw(e=>{const n=pl(t)(e);return n.tag==="Just"?Pt("Right",{value:t,consumed:t,remainder:n._1}):Pt("Left","Expected "+I1(t))}),Gw=Zt(t=>!0),x1=(t,e)=>({tag:t,_1:e}),Pw=jt(C)(zt),Iw=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},N1=Lw(zt),J1=(()=>{const t=Zt(e=>e===" "||e===" "||e===`
|
|
4
|
+
`)(" "),n=(()=>{const r=tr("\r")(" "),i=(()=>{const o=tr(" ")(" ");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),dg=t=>e=>{const n=lp(r=>{const i=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;g()})();return dp(i.family)(i.size)(i.weight)(Ar(r.text))})(fg(Ar(e)));return()=>{const r=n();return hp(r)}},lg={text:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:"500"},code:{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:"400"}},pp=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Mr=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},mp=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},yp=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},xp=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},hg=t=>lr(Je(gr(e=>e===" ")(Je(gr(e=>e===" ")(Zn(t)).rest)).rest)),Np=t=>J(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?v("Just",n._1):e)(T)(Ft(Cn)(t)),Ts=t=>e=>{if(t<=0)return[e];if(Kn(e)<=t)return[e];const n=Zn(e),r=t<1?[]:bt(0,t,n),i=Np(r);if(i.tag==="Just"){const o=hg(lc(!(i._1>=0&&i._1<r.length)||r[i._1]===" "?i._1:i._1+1|0)(e)),u=hg(di(i._1+1|0)(e));return u===""?[o]:[o,...Ts(t)(u)]}if(i.tag==="Nothing"){const o=lc(t)(e),u=di(t)(e);return u===""?[o]:[o,...Ts(t)(u)]}g()},Jp={cellW:7,cellH:3,maxLineWidth:20},Tp=t=>e=>{const n=W(o=>b((()=>{if(o.label.tag==="Just")return o.label._1;if(o.label.tag==="Nothing")return o.id;g()})(),o))(e.nodes),r=Mr(1)(En((mp(t.maxLineWidth)(J(o=>u=>Mr(o)(Kn(u._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),i=(r*t.cellW|0)-1|0;return{...e,nodes:W(o=>{if(!(o._2.size._1===1&&o._2.size._2===1))return o._2;const u=Tt(yo(`
|
|
5
|
+
`)(o._1))(Ts(i)),s=J(c=>f=>Mr(c)(Kn(f)))(0)(u),a=o._2.shape==="Cylinder"?Mr(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(Mr(1)(En(u.length+t.cellH|0,t.cellH))+(o._2.shape==="Cylinder"||o._2.shape==="Document"?1:0)|0))}})(n)}},wp=t=>e=>n=>({...n,nodes:W(r=>{const i=xp(r.id)(e);if(i.tag==="Nothing")return r;if(i.tag==="Just")return{...r,size:b(yp(r.size._1)(rt(Mr(1)(de(eo(r.shape==="Cylinder"?(i._1+0)/t:(i._1+32)/t))))),r.size._2)};g()})(n.nodes)}),vp=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bp=t=>{const e=t.length;return(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(a>=e){u=!1,s=c;continue}const f=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const 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,L=t[y].position,k=t[y].size;return N._1<L._1+k._1&&L._1<N._1+w._1&&N._2<L._2+k._2&&L._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)},pg=t=>J(e=>n=>e+Ll(n.start)(n.end))(0)(t.segments),kp=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+pg(i))(0)(e),maxEdgeLength:J(r=>i=>vp(r)(pg(i)))(0)(e),nodeOverlapCount:bp(t),constraintViolations:n,jumpCount:J(r=>i=>r+i.jumps.length|0)(0)(e)}),ws=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},vs=ws("LEFT"),Lp=ws("RIGHT"),mg=ws("UNDEFINED"),Ep={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},Cp={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?Ge:xe;if(e==="LEFT")return Ne;if(t==="RIGHT")return e==="RIGHT"?Ge:xe;if(e==="RIGHT")return Ne;if(t==="UP")return e==="UP"?Ge:xe;if(e==="UP")return Ne;if(t==="DOWN")return e==="DOWN"?Ge:xe;if(e==="DOWN")return Ne;if(t==="UNDEFINED"&&e==="UNDEFINED")return Ge;g()},Eq0:()=>Ep},Sp=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){if(t==="LEFT"){if(o._3==="LEFT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="LEFT"){n=o._6;continue}if(t==="RIGHT"){if(o._3==="RIGHT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="RIGHT"){n=o._6;continue}if(t==="UP"){if(o._3==="UP"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="UP"){n=o._6;continue}if(t==="DOWN"){if(o._3==="DOWN"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="DOWN"){n=o._6;continue}if(t==="UNDEFINED"&&o._3==="UNDEFINED"){r=!1,i=!0;continue}}g()}return i},Gp={x:0,y:0},Ve=t=>e=>n=>{const r=Ut(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:j(it)(t)(e(r._1))(n.cNodes)};g()},Ei=t=>e=>n=>{const r=Ut(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:j(it)(t)(e(r._1))(n.cGroups)};g()},Pp=t=>J(e=>n=>Ve(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),Dp=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)(ee)(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)},Ip=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}})),Qp=t=>{const e=J(n=>r=>Ei(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},Fp={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},bs=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=Ei(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=>bs({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return Q;if(n.tag==="Node")return Wt("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=>bs({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return Q;if(n.tag==="Node")return Wt("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)})()}),yg=t=>{const e=J(n=>r=>Ei(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?Ei(a._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(Ei(o)(c=>Be(vr)(s)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,s]})(u)):u;g()})(n)(i._1.constraints)}}g()})(e)(e.cNodeOrder)},Po=t=>{const e=Dp(t.cGraph);return{...t,cGraph:yg(J(n=>r=>Ve(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},Ap=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:Ap(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node")return Wt("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:yg((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);g()})())}},Mp=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?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"?Po({...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"?Po({...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"?Po({...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"?Po({...r,cGraph:Ue(r.cGraph)}):r;g()},xg=t=>e=>e.finished||!Sp(t)(e.cGraph.supportedDirections)||(t==="LEFT"?e.direction==="LEFT":t==="RIGHT"?e.direction==="RIGHT":t==="UP"?e.direction==="UP":t==="DOWN"?e.direction==="DOWN":t==="UNDEFINED"&&e.direction==="UNDEFINED")?e:Mp(e.direction)(t)(e),Op=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?xg(vs)(t):t,n={...e,cGraph:Qp(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},Ng=t=>e=>n=>{const r=Ut(t)(n.cNodes),i=Ut(e)(n.cGroups);return r.tag==="Just"&&i.tag==="Just"?(()=>{if(r._1.cGroup.tag==="Nothing")return!1;if(r._1.cGroup.tag==="Just")return!0;g()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:j(it)(t)({...r._1,cGroup:v("Just",e)})(n.cNodes),cGroups:j(it)(e)({...i._1,cNodes:Be(vr)(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},Jg=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:j(it)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:T,cGroupOffset:Gp,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:an})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),ks=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:J(r=>i=>Ng(i)(n)(r))({...e,cGroups:j(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)}},Rp=t=>J(e=>n=>{const r=Ut(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?ks({master:T,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),Bp=t=>({cGraph:Pp(Rp(bs(t))),direction:mg,compactionAlgorithm:T,constraintAlgorithm:T,spacingsHandler:Fp,lockFun:T,finished:!1}),zp=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Wp=t=>e=>{const n=ut.compare(t._1)(e._1);return n==="LT"?xe:n==="GT"?Ne:it.compare(t._2)(e._2)},qp=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Tg=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},wg=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",vg=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),Do=t=>e=>Wp(b(t.hitbox.x+t.hitbox.width/2,t.id))(b(e.hitbox.x+e.hitbox.width/2,e.id)),Hp=t=>e=>{const n=cr(Xt,T,r=>Do(t)(r)==="LT",e);if(n.tag==="Just"){const r=Ua(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 Ot(e)(t);g()},bg=t=>e=>{const n=st(i=>Do(i)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?v("Just",n[r]):T},$p=t=>e=>{const n=Hp(e)(t.intervals),r=Vt(o=>Do(e)(o)==="LT")(n),i=j(it)(e.id)((()=>{const o=bg(e)(n);return o.tag==="Just"?v("Just",o._1.id):T})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return j(it)(r._1.id)(v("Just",e.id))(i);if(r.tag==="Nothing")return i;g()})()}},Xp=t=>e=>{const n=ut.compare(t.low?t.node.hitbox.y:t.node.hitbox.y+t.node.hitbox.height)(e.low?e.node.hitbox.y:e.node.hitbox.y+e.node.hitbox.height);return n==="EQ"?t.low?t.low&&!e.low?Ne:Ge:e.low?xe:Ge:n},Yp=t=>J(e=>n=>Ve(n.id)(r=>({...r,constraints:[]}))(e))(t)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),Ls=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)(qp(t)),kg=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}},Lg=t=>e=>n=>J(r=>i=>n(i)?Ve(i.id)(kg(t))(r):r)(e)(xt(r=>Ut(r)(e.cNodes))(e.cNodeOrder)),Vp=t=>e=>{const n=(r,i,o)=>{const u=Ve(o)(kg(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))},Up=t=>e=>{const n=bg(e)(t.intervals),r=Vt(o=>Do(e)(o)==="LT")(t.intervals),i=n.tag==="Just"&&(()=>{const o=Tg(e.id)(t.cand);return(o.tag==="Nothing"?!1:o.tag==="Just"&&(o._1.tag==="Nothing"?!1:o._1.tag==="Just"&&o._1._1===n._1.id))&&n._1.cGroup.tag==="Just"&&e.cGroup.tag==="Just"&&n._1.cGroup._1!==e.cGroup._1})()?vt(it)(ee)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const o=Tg(r._1.id)(t.cand);return(o.tag==="Nothing"?!1:o.tag==="Just"&&(o._1.tag==="Nothing"?!1:o._1.tag==="Just"&&o._1._1===e.id))&&e.cGroup.tag==="Just"&&r._1.cGroup.tag==="Just"&&e.cGroup._1!==r._1.cGroup._1})()?vt(it)(ee)(e.id)([r._1.id])(i):i,intervals:st(o=>o.id!==e.id,t.intervals)}},Zp=t=>e=>e.low?$p(t)(e.node):Up(t)(e.node),Es=t=>e=>J(Zp)({intervals:[],cand:Q,constraints:Q})(Lt(Xp)(Tt(st(t,xt(n=>Ut(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,Kp=t=>e=>{const n=zp(0)(t/2-.5),r=Ls(Es(wg)(Lg(n)(e)(wg)))(e),i=Ls(Es(vg)(Lg(n)(r)(vg)))(r);return Ls(Es(o=>!0)(Vp(n)(i)))(i)},jp=t=>e=>Kp(t)(Yp(e.cGraph)),Io=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Eg=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Cs=t=>e=>n=>r=>i=>({id:t,representedEdges:[i],affectedBends:[e,n],hitbox:{x:Io(e._1)(n._1),y:Io(e._2)(n._2),width:Yn(e._1-n._1),height:Yn(e._2-n._2)},ignoreSpacing:an,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:T}),tm=t=>e=>{const n=Io(t.hitbox.x)(e.hitbox.x),r=Io(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:Eg(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Eg(t.hitbox.y+t.hitbox.height)(e.hitbox.y+e.hitbox.height)-r},ignoreSpacing:{left:t.ignoreSpacing.left||e.ignoreSpacing.left,right:t.ignoreSpacing.right||e.ignoreSpacing.right,up:t.ignoreSpacing.up||e.ignoreSpacing.up,down:t.ignoreSpacing.down||e.ignoreSpacing.down},aPort:(()=>{if(t.aPort.tag==="Just")return t.aPort;if(t.aPort.tag==="Nothing")return e.aPort;g()})()}},em=t=>e=>Yn(t.hitbox.x-e.hitbox.x)<=1e-4&&e.hitbox.y-(t.hitbox.y+t.hitbox.height)<=1e-4&&t.hitbox.y-(e.hitbox.y+e.hitbox.height)<=1e-4,nm=t=>e=>Yn(t.hitbox.x-e.hitbox.x)<=1e-4?ut.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?xe:Ne,Cg=(t,e)=>({tag:t,_1:e}),Ss=jt(C)(zt),Qo=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=(()=>{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 xe;if(i==="GT")return Ne;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?Ge:xe;if(r._2.tag==="Nothing")return Ne;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=>j(e)(r)()(n))(Q)})(),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=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},rm=J(t=>e=>j(Cp)(e)()(t))(Q),Gs=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=yc.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},im=t=>e=>{const n=Ss(W(o=>b(o.id,o))(t)),r=xt(o=>Qo(o)(n))(e),i=it.compare((()=>{const o=Sg(W(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=Sg(W(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()},om=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),Fo=t=>e=>n=>r=>{if(r.tag==="Just"){const i=In(n)(e);if(i.tag==="Just"){const o=Vt(u=>u.id===r._1)(i._1);if(o.tag==="Just")return o._1.side;if(o.tag==="Nothing")return t;g()}if(i.tag==="Nothing")return t;g()}if(r.tag==="Nothing")return t;g()},um=t=>e=>n=>{const r=Jg({origin:v("Just",Cg("SegmentOrigin",n)),kind:v("Just","vs"),hitbox:n.hitbox})(e.cGraph),i=Ip(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 Ng(r.id)(o._1.cGroup._1)(i);if(o._1.cGroup.tag==="Nothing")return i;g()}if(o.tag==="Nothing")return i;g()}return ks({master:v("Just",r.id),nodes:[r.id]})(i).graph})(),edgeToCs:J(o=>u=>vt(C)(ee)(u)([r.id])(o))(e.edgeToCs)(n.representedEdges),lockMap:j(it)(r.id)(im(t)(n.representedEdges))(e.lockMap)}},sm=t=>e=>n=>{const r=Mt(i=>T,i=>o=>v("Just",{head:i,tail:o}),Lt(nm)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const i=J(o=>u=>em(o.survivor)(u)?{...o,survivor:tm(o.survivor)(u)}:{survivor:u,merged:[...o.merged,o.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return J(um(t))(n)([...i.merged,i.survivor])}g()},am=t=>({cGraph:{cNodes:Q,cNodeOrder:[],cGroups:Q,cGroupOrder:[],supportedDirections:rm([mg,vs,Lp]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:Q,edgeToCs:Q,lockMap:Q}),cm=t=>{const e=rt(4);return{x:t.position._1*e,y:t.position._2*e,width:t.size._1*e,height:t.size._2*e}},gm=t=>e=>n=>J(r=>i=>{const o=Jg({origin:v("Just",Cg("NodeOrigin",i.node)),kind:T,hitbox:cm(i)})(r.cGraph),u=In(i.node)(t),s=(()=>{if(u.tag==="Nothing")return b(0,0);if(u.tag==="Just")return u._1;g()})();return{...r,cGraph:ks({master:v("Just",o.id),nodes:[o.id]})(o.graph).graph,nodeToC:j(C)(i.node)(o.id)(r.nodeToC),lockMap:j(it)(o.id)((()=>{const a=s._1-s._2|0;return a<0?{...an,left:!0}:a>0?{...an,right:!0}:an})())(r.lockMap)}})(n)(e),fm=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),_m=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?j(C)(n.origin._1._1)(n.hitbox.x)(e):e)(Q)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),dm=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?j(C)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(Q)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),lm=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=>j(yc)(o)(r)(i))(e)(n.origin._1._1.affectedBends)}return e})(Q)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),Gg=t=>{const e=Ss(W(n=>b(n.id,n))(t.edges));return xt(n=>{const r=Qo(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:Fo(Gn)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:Fo(Pn)(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:Fo(Gn)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:Fo(Pn)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return T;g()})(t.paths)},hm=t=>e=>{const n=Tt(e)(r=>{if(r.src===r.tgt)return[];if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return[];const i=In(r.tgt)(t.nodeToC),o=(()=>{if(i.tag==="Just")return Ut(i._1)(t.cGraph.cNodes);if(i.tag==="Nothing")return T;g()})(),u=In(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 _=Qo(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 Re(u=>Be(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}},pm=t=>e=>{const n=rt(4),r=_m(t),i=dm(t),o=Ss(W(s=>b(s.id,b(s.from.node,s.to.node)))(e.edges)),u=lm(t);return{nodes:W(s=>{const a=In(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:W(s=>{const a=Qo(s.edge)(o),c=(()=>{if(a.tag==="Nothing")return s.segments;if(a.tag==="Just"){const f=In(a._1._1)(i),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})(),l=In(a._1._2)(i),_=(()=>{if(l.tag==="Nothing")return 0;if(l.tag==="Just")return l._1;g()})();return Ft((()=>{const h=s.reversed?_:d,p=s.reversed?d:_,m=s.segments.length;return y=>x=>{if(x.direction==="V"){const N=(()=>{if(y===0)return h;if(y===(m-1|0))return p;const w=Gs(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=Gs(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=Gs(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:Te(f=>d=>f.end,c,bt(1,c.length,c))}})(e.paths)}},mm=t=>e=>n=>r=>i=>o=>{const u=Cs(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})()]}},Pg=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...Cs(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}}]}),Ao=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...Cs(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}}]}),ym=t=>e=>n=>{if(n.src===n.tgt)return e;const r=In(n.src)(t.nodeToC),i=In(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=om(n.path),a=J(mm(n)(o)(u)(s.length-1|0))(e)(Ft(f=>d=>b(f,d))(s));if(0<s.length){const f=(()=>{if(r.tag==="Just"&&o.tag==="Just"){if(n.srcSide==="North")return Pg(n)(r._1)(o._1)(s[0])({side:le,down:!0})(a);if(n.srcSide==="South")return Pg(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 Ao(n)(i._1)(u._1)(s[d])({side:le,down:!0})(f);if(n.tgtSide==="South")return Ao(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 Ao(n)(i._1)(u._1)(s[c])({side:le,down:!0})(a);if(n.tgtSide==="South")return Ao(n)(i._1)(u._1)(s[c])({side:he,down:!1})(a)}return a},xm=t=>e=>n=>sm(t)(J(ym(n))({nextId:0,segments:[]})(e).segments)(n),Nm=t=>xm(t.edges)(Gg(t))(gm(fm(t.edges))(t.nodes)(am())),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=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},Ps=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},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=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},Jm=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Tm=t=>{const e=t.Eq0();return n=>r=>{const i=s=>{let a=s,c=!0,f;for(;c;){const d=a,l=Mt(_=>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=>!Qn(p.eid)(d.removedEdges)&&(e.eq(p.src)(_)||e.eq(p.tgt)(_)))(r);if(h.tag==="Nothing"){a={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const p=e.eq(h._1.src)(_)?h._1.tgt:h._1.src,m={...d,degree:j(t)(p)((()=>{const y=(x=>{let N=x,w=!0,L;for(;w;){const k=N;if(k.tag==="Leaf"){w=!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"){w=!1,L=v("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:j(t)(_)()(d.removedNodes),removedEdges:j(it)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:_,neighbour:p,viaSrc:e.eq(h._1.src)(_)}],queue:l._1.tail};if((()=>{const y=(N=>{let w=N,L=!0,k;for(;L;){const E=w;if(E.tag==="Leaf"){L=!1,k=T;continue}if(E.tag==="Node"){const O=t.compare(p)(E._3);if(O==="LT"){w=E._5;continue}if(O==="GT"){w=E._6;continue}if(O==="EQ"){L=!1,k=v("Just",E._4);continue}}g()}return k})(m.degree),x=N=>{let w=N,L=!0,k;for(;L;){const E=w;if(E.tag==="Leaf"){L=!1,k=!1;continue}if(E.tag==="Node"){const O=t.compare(p)(E._3);if(O==="LT"){w=E._5;continue}if(O==="GT"){w=E._6;continue}if(O==="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(m.removedNodes)})()){a={...m,queue:[...m.queue,p]};continue}a=m;continue}}g()}return f},o=J(s=>a=>vt(t)(ue)(a.src)(1)(vt(t)(ue)(a.tgt)(1)(s)))(Q)(r),u=i({degree:o,removedNodes:Q,removedEdges:Q,record:[],queue:st(s=>{const a=(c=>{let f=c,d=!0,l;for(;d;){const _=f;if(_.tag==="Leaf"){d=!1,l=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=>!Qn(s.eid)(u.removedEdges),r),removed:u.record}}},wm=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 j(t)(i.node)(i.viaSrc?u-1|0:u+1|0)(r)})(n)(Je(e)),Is=t=>{const e=t.Eq0();return n=>r=>i=>{const o={...i,treeNode:j(t)(r)()(i.treeNode)};return J(u=>s=>{if(Qn(s.eid)(u.st.edgeVisited))return u;const a={...u.st,edgeVisited:j(it)(s.eid)()(u.st.edgeVisited)},c=e.eq(s.src)((()=>{const f=s.src,d=_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(f)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=s.tgt;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?s.src:(()=>{const f=s.tgt,d=_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(f)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=s.src;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(Qn(s.eid)(a.treeEdge)){if((d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=!1;continue}if(p.tag==="Node"){const m=t.compare(c)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=!0;continue}}g()}return h})(a.treeNode))return{...u,st:a};const f=Is(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=Is(t)(n)(c)({...a,treeEdge:j(it)(s.eid)()(a.treeEdge)});return{count:u.count+f.count|0,st:f.st}}return{...u,st:a}})({count:1,st:o})(st(u=>(e.eq(u.src)(r)||e.eq(u.tgt)(r))&&!Qn(u.eid)(o.edgeVisited),n))}},Mo=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 L=t.compare(h)(w._3);if(L==="LT"){y=w._5;continue}if(L==="GT"){y=w._6;continue}if(L==="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},vm=t=>{const e=jt(t)(zt);return n=>({layer:e(W(r=>b(r,0))(n)),treeNode:Q,treeEdge:Q,poID:Q,lowestPoID:Q,cutvalue:Q,postOrder:1,edgeVisited:Q})},bm=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,km=t=>{const e=jt(t)(zt);return n=>r=>{const i=J(o=>u=>Ps(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(W(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))}},Dg=t=>{const e=t.Eq0();return n=>r=>i=>{const o=J(s=>a=>{const c=Dg(t)(n)(e.eq(a.src)(r)?a.tgt:a.src)({...s.st,edgeVisited:j(it)(a.eid)()(s.st.edgeVisited)});return{lowest:Ps(s.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:i})(st(s=>Qn(s.eid)(i.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!Qn(s.eid)(i.edgeVisited),n)),u=Ps(o.lowest)(o.st.postOrder);return{lowest:u,st:{...o.st,poID:j(t)(r)(o.st.postOrder)(o.st.poID),lowestPoID:j(t)(r)(u)(o.st.lowestPoID),postOrder:o.st.postOrder+1|0}}}},Ig=t=>{const e=Dg(t);return n=>r=>i=>0<n.length?e(r)(n[0])({...i,edgeVisited:Q,postOrder:1,poID:Q,lowestPoID:Q}).st:i},Lm=t=>{const e=t.Eq0();return n=>r=>i=>st(o=>Qn(o.eid)(r.treeEdge)&&(e.eq(o.src)(i)||e.eq(o.tgt)(i)),n)},Em=t=>e=>Vt(n=>{const r=Ds(n.eid)(e.cutvalue);return Qn(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),Qg=t=>{const e=Is(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=bm(t)(r)(u.st);if(s.tag==="Nothing")return u.st;if(s.tag==="Just"){const a=s._1.tgt,c=(h=>{let p=h,m=!0,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 Qg(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 L=t.compare(p)(w._3);if(L==="LT"){y=w._5;continue}if(L==="GT"){y=w._6;continue}if(L==="EQ"){x=!1,N=!0;continue}}g()}return N})(u.st.treeNode)?j(t)(p)((()=>{const m=(y=>{let x=y,N=!0,w;for(;N;){const L=x;if(L.tag==="Leaf"){N=!1,w=T;continue}if(L.tag==="Node"){const k=t.compare(p)(L._3);if(k==="LT"){x=L._5;continue}if(k==="GT"){x=L._6;continue}if(k==="EQ"){N=!1,w=v("Just",L._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()}},Cm=t=>e=>n=>r=>J(i=>o=>{if(Mo(t)(r)(o.src)(n)&&!Mo(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,Sm=t=>{const e=t.Eq0();return n=>r=>i=>o=>{const u=o.tgt,s=o.src;return J(a=>c=>{if((()=>{const f=Ds(c.eid)(r.cutvalue);if(f.tag==="Just")return!0;if(f.tag==="Nothing")return!1;g()})()){const f=Ds(c.eid)(r.cutvalue),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return e.eq(s)(c.src)||e.eq(u)(c.tgt)?a-(d-c.weight):a+(d-c.weight)}return e.eq(i)(s)?e.eq(c.src)(i)?a+c.weight:a-c.weight:e.eq(c.src)(i)?a-c.weight:a+c.weight})(o.weight)(st(a=>a.eid!==o.eid&&(e.eq(a.src)(i)||e.eq(a.tgt)(i)),n))}},Gm=t=>{const e=Sm(t);return n=>r=>i=>{const o=(u,s,a)=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=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 j(t)(u)(st(f=>f.eid!==s.eid,c._1))(a);if(c.tag==="Nothing")return a;g()};return(u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=(m=>{let y=m,x=!0,N;for(;x;){const w=y;if(w.tag==="Leaf"){x=!1,N=T;continue}if(w.tag==="Node"){const L=t.compare(_)(w._3);if(L==="LT"){y=w._5;continue}if(L==="GT"){y=w._6;continue}if(L==="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:j(it)(p[0].eid)(e(n)(l)(_)(p[0]))(l.cutvalue)},c=m;continue}f=!1,d=l}return d})(r)(i)}},Fg=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=>j(i)(f)()(c))(Q),u=Lm(t),s=jt(t)(zt),a=Gm(t);return c=>f=>d=>{const l={unknown:s(W(_=>b(_,Ct(We.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}}},Pm=t=>{const e=Ig(t),n=Fg(t);return r=>i=>o=>u=>s=>{const a={...s,treeEdge:j(it)(u.eid)()(ui(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=Mo(t)(a)(u.tgt)(o)?_:-_;return n(r)(i)(e(r)(i)({...a,layer:J(p=>m=>Mo(t)(a)(m)(o)?p:j(t)(m)((()=>{const y=(x=>{let N=x,w=!0,L;for(;w;){const k=N;if(k.tag==="Leaf"){w=!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"){w=!1,L=v("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()})())(p))(a.layer)(r)}))}},Dm=t=>{const e=Pm(t);return n=>r=>i=>o=>(u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c;if(l===0){f=!1,d=_;continue}const h=Em(i)(_);if(h.tag==="Nothing"){f=!1,d=_;continue}if(h.tag==="Just"){const p=Cm(t)(i)(h._1)(_);if(p.tag==="Nothing"){f=!1,d=_;continue}if(p.tag==="Just"){a=l-1|0,c=e(r)(i)(h._1)(p._1)(_);continue}}g()}return d})(n)(o)},Im=t=>{const e=Fg(t),n=Ig(t),r=Qg(t);return i=>o=>u=>e(i)(o)(n(i)(o)(r(i)(o)(u)))},Ag=t=>e=>J(n=>r=>vt(t)(ee)(e(r))([r])(n))(Q),Qm=t=>{const e=jt(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,L=p,k=Mt(E=>T,E=>O=>v("Just",{head:E,tail:O}),w);if(k.tag==="Nothing"){m=!1,y=L;continue}if(k.tag==="Just"){const E=k._1.head,O=(G=>{let P=G,V=!0,U;for(;V;){const B=P;if(B.tag==="Leaf"){V=!1,U=T;continue}if(B.tag==="Node"){const R=t.compare(E)(B._3);if(R==="LT"){P=B._5;continue}if(R==="GT"){P=B._6;continue}if(R==="EQ"){V=!1,U=v("Just",B._4);continue}}g()}return U})(L.layer),Y=(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;g()})(),et=J(G=>P=>{const V=P.tgt,U=(R=>{let M=R,S=!0,D;for(;S;){const I=M;if(I.tag==="Leaf"){S=!1,D=T;continue}if(I.tag==="Node"){const A=t.compare(V)(I._3);if(A==="LT"){M=I._5;continue}if(A==="GT"){M=I._6;continue}if(A==="EQ"){S=!1,D=v("Just",I._4);continue}}g()}return D})(G.incident),B=(()=>{if(U.tag==="Nothing")return-1;if(U.tag==="Just")return U._1-1|0;g()})();return{st:{...G.st,layer:j(t)(P.tgt)(Jm((()=>{const R=P.tgt,M=(S=>{let D=S,I=!0,A;for(;I;){const H=D;if(H.tag==="Leaf"){I=!1,A=T;continue}if(H.tag==="Node"){const $=t.compare(R)(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})(G.st.layer);if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})())(Y+P.delta|0))(G.st.layer)},incident:j(t)(P.tgt)(B)(G.incident),queue:B===0?[...G.queue,P.tgt]:G.queue}})({st:L,incident:N,queue:k._1.tail})((()=>{const G=(P=>{let V=P,U=!0,B;for(;U;){const R=V;if(R.tag==="Leaf"){U=!1,B=T;continue}if(R.tag==="Node"){const M=t.compare(E)(R._3);if(M==="LT"){V=R._5;continue}if(M==="GT"){V=R._6;continue}if(M==="EQ"){U=!1,B=v("Just",R._4);continue}}g()}return B})(x);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})());l=x,_=et.incident,h=et.queue,p=et.st;continue}g()}return y},u=Ag(t)(a=>a.tgt)(r),s=e(W(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(Ag(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)}},Fm=t=>{const e=vm(t),n=Qm(t),r=Im(t),i=Dm(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}},Mg=t=>{const e=km(t),n=Fm(t),r=Tm(t);return i=>o=>{if(i.length===0)return Q;if(i.length<40)return e(i)(n(i)(o));const u=r(i)(o);return e(i)(wm(t)(u.removed)(n(u.coreNodes)(u.coreEdges)))}},Og=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},Qs=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Am=Mg(it),Ci=t=>e=>({...e,edges:[...e.edges,{src:t.src,tgt:t.tgt,delta:t.delta,weight:t.weight,eid:e.nextEid}],nextEid:e.nextEid+1|0}),Mm=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=rt((()=>{const i=Og(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()},Om=t=>e=>({...e,cGraph:J(Mm(t))(e.cGraph)((()=>{const n=e.cGraph;return xt(r=>Ut(r)(n.cNodes))(n.cNodeOrder)})())}),Rm=t=>e=>n=>r=>i=>{const o=de(eo(e.cGroupOffset.x-t.cGroupOffset.x));return Ci({src:i.nextNodeId,tgt:r,delta:Qs(0)(-o),weight:1})(Ci({src:i.nextNodeId,tgt:n,delta:Qs(0)(o),weight:1})({...i,nodes:[...i.nodes,i.nextNodeId],nextNodeId:i.nextNodeId+1|0}))},Bm=t=>e=>n=>r=>i=>o=>u=>{const s=Qs(0)(de(eo(n.cGroupOffset.x+n.hitbox.width+(e.direction==="LEFT"||e.direction==="RIGHT"?e.spacingsHandler.horizontalSpacing(n)(r):e.spacingsHandler.verticalSpacing(n)(r))-r.cGroupOffset.x)));return t.sameEdgeVerticalSegments(n)(r)?Rm(n)(r)(i)(o)(u):Ci({src:i,tgt:o,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(u)},zm=t=>e=>n=>r=>i=>{const o=Ut(i)(e.cGraph.cNodes);if(o.tag==="Nothing")return r;if(o.tag==="Just")return(n.cGroup.tag==="Nothing"?o._1.cGroup.tag==="Nothing":n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"&&n.cGroup._1===o._1.cGroup._1)?r:n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"?Bm(t)(e)(n)(o._1)(n.cGroup._1)(o._1.cGroup._1)(r):r;g()},Wm=t=>e=>n=>r=>J(zm(t)(e)(r))(n)(r.constraints),qm=t=>e=>Ci({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),Hm=t=>{const e=J(i=>o=>vt(it)(ue)(o.tgt)(1)(i))(Q)(t.edges),n=st(i=>{const o=Og(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=>Ci({src:r,tgt:o,delta:1,weight:0})(i))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},$m=t=>e=>{const n=Hm(J(qm)(J(Wm(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}},Xm=t=>e=>{const n=$m(t)(e);return Om(Am(n.nodes)(n.edges))(e)},Rg=t=>t,ne=Rg("H"),re=Rg("V"),Ym=t=>b(t._2,t._1),Bg=t=>({...t,position:b(t.position._2,t.position._1),size:b(t.size._2,t.size._1)}),Vm=t=>({start:b(t.start._2,t.start._1),end:b(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return re;if(t.direction==="V")return ne;g()})()}),zg=t=>({...t,segments:W(Vm)(t.segments),bends:W(Ym)(t.bends)}),Um=t=>({nodes:W(Bg)(t.nodes),edges:t.edges,paths:W(zg)(t.paths),ports:t.ports}),Zm={nodeNode:8,edgeNode:4,edgeEdge:10},Km=t=>e=>({horizontalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r)||n.ignoreSpacing.right||r.ignoreSpacing.left)return 0;const i=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?i?t.edgeEdge:t.edgeNode:i?t.edgeNode:t.nodeNode},verticalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r))return 1;if(n.hitbox.y<=r.hitbox.y?n.ignoreSpacing.down||r.ignoreSpacing.up:n.ignoreSpacing.up||r.ignoreSpacing.down)return 0;const i=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?i?t.edgeEdge:t.edgeNode:i?t.edgeNode:t.nodeNode}}),jm=t=>e=>Xm(e),t2=t=>e=>n=>{const r=Um(n),i=Nm(r),o=hm(i)(Gg(r)),u=pm(xg(vs)(Op({...Bp(i.cGraph),compactionAlgorithm:v("Just",jm()(o)),constraintAlgorithm:v("Just",jp(e.edgeEdge)),spacingsHandler:Km(e)(o)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:W(Bg)(u.nodes),edges:W(zg)(u.edges)}},Wg=t=>t,Or=jt(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},qg=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()},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=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},e2=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?xe:n==="GT"?Ne: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()},n2=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),r2=t=>t,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=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},i2=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},Oo=Wg("Regular"),Ro=Wg("Critical"),$g=t=>e=>{const n=J(u=>s=>j(C)(s.node)(s)(u))(Q)(e),r=1.25*rt(4),i=(u,s,a)=>(c=>f=>d=>{let l=c,_=f,h=d,p=!0,m;for(;p;){const y=l,x=_,N=h;if(N.critical){p=!1,m=N;continue}const w=Mt(k=>T,k=>E=>v("Just",{head:k,tail:E}),y),L=Mt(k=>T,k=>E=>v("Just",{head:k,tail:E}),x);if(w.tag==="Just"&&L.tag==="Just"){const k=w._1.head>L._1.head-u&&w._1.head<L._1.head+u?{...N,critical:!0}:w._1.head>L._1.head-r&&w._1.head<L._1.head+r?{...N,conflicts:N.conflicts+1|0}:N;if(k.critical){p=!1,m=k;continue}if(w._1.head<=L._1.head){l=w._1.tail,_=x,h=k;continue}l=y,_=L._1.tail,h=k;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:Ro}]:[],...f.critical?[{src:s.id,tgt:a.id,weight:1,kind:Ro}]:[]];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:Oo}]:p>m?[{src:a.id,tgt:s.id,weight:p-m|0,kind:Oo}]:p>0?[{src:s.id,tgt:a.id,weight:0,kind:Oo},{src:a.id,tgt:s.id,weight:0,kind:Oo}]:[]};return J(u=>s=>J(a=>c=>j(C)(c._1)(c._2)(a))(u)((()=>{const a=J(G=>P=>{const V=P.edge.from.node+"|"+(()=>{if(P.edge.from.port.tag==="Just")return P.edge.from.port._1;if(P.edge.from.port.tag==="Nothing")return"_auto_"+P.edge.id;g()})(),U=Hg(V)(G.entries);if(U.tag==="Nothing")return{...G,entries:j(C)(V)({id:0,members:[P.edge.id],incoming:[P.fromPos._1],outgoing:[P.toPos._1],slot:0,mark:0,splitBy:T,splitPartner:T})(G.entries),order:[...G.order,V]};if(U.tag==="Just")return{...G,entries:j(C)(V)({...U._1,members:[...U._1.members,P.edge.id],incoming:[...gr(B=>B<P.fromPos._1)(U._1.incoming).init,P.fromPos._1,...gr(B=>B<=P.fromPos._1)(U._1.incoming).rest],outgoing:[...gr(B=>B<P.toPos._1)(U._1.outgoing).init,P.toPos._1,...gr(B=>B<=P.toPos._1)(U._1.outgoing).rest]})(G.entries)};g()})({entries:Q,order:[]})(s._2),c=Ft(G=>P=>({...P,id:G}))(xt(G=>Hg(G)(a.entries))(a.order));if(c.length===0)return[];const f=J(G=>P=>G.prev.tag==="Just"&&P-G.prev._1<1e-9?G:{prev:v("Just",P),out:[...G.out,P]})({prev:T,out:[]})(Lt(ut.compare)([...Tt(c)(G=>G.incoming),...Tt(c)(G=>G.outgoing)])).out,d=f.length<2?.2*r:.2*J(G=>P=>{if(G.prev.tag==="Nothing")return{prev:v("Just",P),mn:G.mn};if(G.prev.tag==="Just")return{prev:v("Just",P),mn:dt(G.mn)(P-G.prev._1)};g()})({prev:T,mn:1e18})(f).mn,l={segments:c,deps:(()=>{const G=c.length;return Tt(Tt(It(0,G-2|0))(P=>Tt(It(P+1|0,G-1|0))(V=>[b(P,V)])))(P=>P._1>=0&&P._1<c.length?P._2>=0&&P._2<c.length?o(d,c[P._1],c[P._2]):[]:[])})()},_=st(G=>{if(G.kind==="Critical")return!0;if(G.kind==="Regular")return!1;g()},l.deps),h=(()=>{if(_.length<2)return l;const G=Or((()=>{const R=l.segments;return W(M=>b(M.id,M.mark))((()=>{const M=R.length,S=I=>{let A=I,H=!0,$;for(;H;){const X=A,q=Vt(z=>{const tt=Dt(z)(X.inWeight);if(tt.tag==="Nothing")return!0;if(tt.tag==="Just")return tt._1===0;g()})(X.remaining);if(q.tag==="Nothing"){H=!1,$=X;continue}if(q.tag==="Just"){const z=q._1;A={...X,inWeight:J(tt=>Z=>vt(it)(ue)(Z.tgt)(-Z.weight)(tt))(X.inWeight)((()=>{const tt=Dt(z)(X.depsBySrc);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),marks:j(it)(z)(X.nextSource)(X.marks),nextSource:X.nextSource+1|0,outWeight:J(tt=>Z=>vt(it)(ue)(Z.src)(-Z.weight)(tt))(X.outWeight)((()=>{const tt=Dt(z)(X.depsByTgt);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),remaining:st(tt=>tt!==z,X.remaining)};continue}g()}return $},D=I=>{let A=I,H=!0,$;for(;H;){const X=A,q=Vt(z=>{const tt=Dt(z)(X.outWeight);if(tt.tag==="Nothing")return!0;if(tt.tag==="Just")return tt._1===0;g()})(X.remaining);if(q.tag==="Nothing"){H=!1,$=X;continue}if(q.tag==="Just"){const z=q._1;A={...X,inWeight:J(tt=>Z=>vt(it)(ue)(Z.tgt)(-Z.weight)(tt))(X.inWeight)((()=>{const tt=Dt(z)(X.depsBySrc);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),marks:j(it)(z)(X.nextSink)(X.marks),nextSink:X.nextSink-1|0,outWeight:J(tt=>Z=>vt(it)(ue)(Z.src)(-Z.weight)(tt))(X.outWeight)((()=>{const tt=Dt(z)(X.depsByTgt);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),remaining:st(tt=>tt!==z,X.remaining)};continue}g()}return $};return(I=>{let A=I,H=!0,$;for(;H;){const X=S(D(A));if(X.remaining.length===0){H=!1,$=W(q=>{const z=Dt(q.id)(X.marks),tt=(()=>{if(z.tag==="Nothing")return q.id;if(z.tag==="Just")return z._1;g()})();return{...q,mark:tt<M?(tt+M|0)+1|0:tt}})(R);continue}A=(()=>{const q=tt=>{const Z=Dt(tt)(X.outWeight),ct=Dt(tt)(X.inWeight);return(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()-(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()|0},z=Lt(tt=>Z=>it.compare(q(Z))(q(tt)))(X.remaining);if(0<z.length){const tt=z[0];return{...X,inWeight:J(Z=>ct=>vt(it)(ue)(ct.tgt)(-ct.weight)(Z))(X.inWeight)((()=>{const Z=Dt(tt)(X.depsBySrc);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;g()})()),marks:j(it)(tt)(X.nextSource)(X.marks),nextSource:X.nextSource+1|0,outWeight:J(Z=>ct=>vt(it)(ue)(ct.src)(-ct.weight)(Z))(X.outWeight)((()=>{const Z=Dt(tt)(X.depsByTgt);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;g()})()),remaining:st(Z=>Z!==tt,X.remaining)}}return X})()}return $})({remaining:W(I=>I.id)(R),marks:Q,inWeight:J(I=>A=>vt(it)(ue)(A.tgt)(A.weight)(I))(Q)(_),outWeight:J(I=>A=>vt(it)(ue)(A.src)(A.weight)(I))(Q)(_),depsBySrc:J(I=>A=>vt(it)(ee)(A.src)([A])(I))(Q)(_),depsByTgt:J(I=>A=>vt(it)(ee)(A.tgt)([A])(I))(Q)(_),nextSink:M-1|0,nextSource:M+1|0})})())})()),P=st(R=>{const M=Dt(R.src)(G),S=Dt(R.tgt)(G);return(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()>(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;g()})()},_);if(P.length===0)return l;const V=J(R=>M=>{if(Be(vr)(M.src)(R.decisions)||Be(vr)(M.tgt)(R.decisions))return R;const S=Dt(M.src)(R.segMap),D=Dt(M.tgt)(R.segMap);if(S.tag==="Just"&&D.tag==="Just"){const I=(S._1.incoming.length+S._1.outgoing.length|0)>2&&(D._1.incoming.length+D._1.outgoing.length|0)<=2,A=I?D._1:S._1;return{decisions:[...R.decisions,A.id],segMap:j(it)(A.id)({...A,splitBy:v("Just",I?S._1.id:D._1.id)})(R.segMap)}}return R})({decisions:[],segMap:Or(W(R=>b(R.id,R))(l.segments))})(P),U=V.segMap,B=J(R=>M=>{const S=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(M.outgoing)),D=lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(M.outgoing)),I=st(q=>q.a.startPosition<=D&&q.a.endPosition>=S,Ft(q=>z=>({i:q,a:z}))(R.freeAreas));if(I.length===0){const q={...M,incoming:Lt(ut.compare)(M.incoming),outgoing:Lt(ut.compare)([(S+D)/2]),splitPartner:v("Just",R.nextId)},z={id:R.nextId,incoming:Lt(ut.compare)([(S+D)/2]),mark:0,members:M.members,outgoing:Lt(ut.compare)(M.outgoing),slot:0,splitBy:T,splitPartner:v("Just",M.id)};return{segMap:j(it)(z.id)(z)(j(it)(q.id)(q)(R.segMap)),freeAreas:R.freeAreas,nextId:R.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=W(z=>({c:z,rating:(()=>{const tt=(z.a.startPosition+z.a.endPosition)/2,Z=[tt],ct=[tt],ft=J((()=>{const yt=R.segMap;return St=>Rt=>{const pt=Dt(Rt.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)(M.incoming))(J(dt)(1e18)(Z)),gt=(()=>{const Et=lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(Z)),Qt=J(Yt=>_e=>_e>Jt?Yt:_e>=Bt?Yt+1|0:Yt)(0)(Z)+J(Yt=>_e=>_e>Et?Yt:_e>=mt?Yt+1|0:Yt)(0)(pt._1.incoming)|0,je=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(Z)),qe=lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(Z)),tn=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),Hn=lt(J(lt)(-1e18)(pt._1.incoming))(J(lt)(-1e18)(pt._1.outgoing)),dn=J(Yt=>_e=>_e>qe?Yt:_e>=je?Yt+1|0:Yt)(0)(pt._1.outgoing)+J(Yt=>_e=>_e>Hn?Yt:_e>=tn?Yt+1|0:Yt)(0)(M.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}})(),K=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)(ct))(J(dt)(1e18)(M.outgoing)),_t=lt(J(lt)(-1e18)(ct))(J(lt)(-1e18)(M.outgoing)),Nt=J(Et=>Qt=>Qt>nt?Et:Qt>=K?Et+1|0:Et)(0)(M.outgoing)+J(Et=>Qt=>Qt>_t?Et:Qt>=ht?Et+1|0:Et)(0)(pt._1.incoming)|0,wt=dt(J(dt)(1e18)(ct))(J(dt)(1e18)(M.outgoing)),Kt=lt(J(lt)(-1e18)(ct))(J(lt)(-1e18)(M.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)),Me=J(Et=>Qt=>Qt>Kt?Et:Qt>=wt?Et+1|0:Et)(0)(pt._1.outgoing)+J(Et=>Qt=>Qt>sn?Et:Qt>=Se?Et+1|0:Et)(0)(ct)|0;return Nt===Me?Nt>0?{...gt,deps:gt.deps+2|0,crossings:gt.crossings+Nt|0}:gt:{...gt,deps:gt.deps+1|0,crossings:gt.crossings+Br(Nt)(Me)|0}}g()}})())(J((()=>{const yt=R.segMap;return St=>Rt=>{const pt=Dt(Rt.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)(M.incoming))(J(dt)(1e18)(Z)),gt=(()=>{const Et=lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(Z)),Qt=J(Yt=>_e=>_e>Jt?Yt:_e>=Bt?Yt+1|0:Yt)(0)(Z)+J(Yt=>_e=>_e>Et?Yt:_e>=mt?Yt+1|0:Yt)(0)(pt._1.incoming)|0,je=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(Z)),qe=lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(Z)),tn=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),Hn=lt(J(lt)(-1e18)(pt._1.incoming))(J(lt)(-1e18)(pt._1.outgoing)),dn=J(Yt=>_e=>_e>qe?Yt:_e>=je?Yt+1|0:Yt)(0)(pt._1.outgoing)+J(Yt=>_e=>_e>Hn?Yt:_e>=tn?Yt+1|0:Yt)(0)(M.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}})(),K=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)(ct))(J(dt)(1e18)(M.outgoing)),_t=lt(J(lt)(-1e18)(ct))(J(lt)(-1e18)(M.outgoing)),Nt=J(Et=>Qt=>Qt>nt?Et:Qt>=K?Et+1|0:Et)(0)(M.outgoing)+J(Et=>Qt=>Qt>_t?Et:Qt>=ht?Et+1|0:Et)(0)(pt._1.incoming)|0,wt=dt(J(dt)(1e18)(ct))(J(dt)(1e18)(M.outgoing)),Kt=lt(J(lt)(-1e18)(ct))(J(lt)(-1e18)(M.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)),Me=J(Et=>Qt=>Qt>Kt?Et:Qt>=wt?Et+1|0:Et)(0)(pt._1.outgoing)+J(Et=>Qt=>Qt>sn?Et:Qt>=Se?Et+1|0:Et)(0)(ct)|0;return Nt===Me?Nt>0?{...gt,deps:gt.deps+2|0,crossings:gt.crossings+Nt|0}:gt:{...gt,deps:gt.deps+1|0,crossings:gt.crossings+Br(Nt)(Me)|0}}g()}})())({crossings:0,deps:0})(st(yt=>yt.tgt===M.id,l.deps)))(st(yt=>yt.src===M.id,l.deps)),at=(()=>{if(M.splitBy.tag==="Just")return Dt(M.splitBy._1)(R.segMap);if(M.splitBy.tag==="Nothing")return T;g()})();if(at.tag==="Just")return{...ft,deps:ft.deps+2|0,crossings:(()=>{const yt=dt(J(dt)(1e18)(at._1.incoming))(J(dt)(1e18)(at._1.outgoing)),St=dt(J(dt)(1e18)(ct))(J(dt)(1e18)(M.outgoing)),Rt=lt(J(lt)(-1e18)(at._1.incoming))(J(lt)(-1e18)(at._1.outgoing)),pt=lt(J(lt)(-1e18)(ct))(J(lt)(-1e18)(M.outgoing)),Bt=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(Z));return ft.crossings+(()=>{const Jt=dt(J(dt)(1e18)(at._1.incoming))(J(dt)(1e18)(at._1.outgoing)),mt=lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(Z)),gt=lt(J(lt)(-1e18)(at._1.incoming))(J(lt)(-1e18)(at._1.outgoing));return((J(K=>nt=>nt>Rt?K:nt>=yt?K+1|0:K)(0)(Z)+J(K=>nt=>nt>mt?K:nt>=Bt?K+1|0:K)(0)(at._1.incoming)|0)+J(K=>nt=>nt>pt?K:nt>=St?K+1|0:K)(0)(at._1.outgoing)|0)+J(K=>nt=>nt>gt?K:nt>=Jt?K+1|0:K)(0)(ct)|0})()|0})()};if(at.tag==="Nothing")return ft;g()})()}))(I);return J(z=>tt=>tt.rating.crossings<z.rating.crossings||!(tt.rating.crossings>z.rating.crossings)&&(tt.rating.deps<z.rating.deps||!(tt.rating.deps>z.rating.deps)&&tt.c.a.size>z.c.a.size)?tt:z)(0<q.length?q[0]:{c:A._1,rating:{crossings:1e6,deps:1e6}})(q).c}g()})(),$={...M,incoming:Lt(ut.compare)(M.incoming),outgoing:Lt(ut.compare)([(H.a.startPosition+H.a.endPosition)/2]),splitPartner:v("Just",R.nextId)},X={id:R.nextId,incoming:Lt(ut.compare)([(H.a.startPosition+H.a.endPosition)/2]),mark:0,members:M.members,outgoing:Lt(ut.compare)(M.outgoing),slot:0,splitBy:T,splitPartner:v("Just",M.id)};return{segMap:j(it)(X.id)(X)(j(it)($.id)($)(R.segMap)),freeAreas:(()=>{if(H.i>=0&&H.i<R.freeAreas.length){const q=Za(Xt,T,H.i,R.freeAreas),z=(()=>{if(q.tag==="Nothing")return R.freeAreas;if(q.tag==="Just")return q._1;g()})();if(R.freeAreas[H.i].size/2<d)return z;const tt=(R.freeAreas[H.i].startPosition+R.freeAreas[H.i].endPosition)/2,Z=tt-d,ct=tt+d;return[...H.i<1?[]:bt(0,H.i,z),...R.freeAreas[H.i].startPosition<=Z?[{startPosition:R.freeAreas[H.i].startPosition,endPosition:Z,size:Z-R.freeAreas[H.i].startPosition}]:[],...ct<=R.freeAreas[H.i].endPosition?[{startPosition:ct,endPosition:R.freeAreas[H.i].endPosition,size:R.freeAreas[H.i].endPosition-ct}]:[],...H.i<1?z:bt(H.i,z.length,z)]}return R.freeAreas})(),nextId:R.nextId+1|0}})({segMap:U,freeAreas:(()=>{const R=Lt(ut.compare)([...Tt(l.segments)(M=>M.incoming),...Tt(l.segments)(M=>M.outgoing)]);return xt(r2)(Te(M=>S=>S-M>=2*d?v("Just",{startPosition:M+d,endPosition:S-d,size:S-M-2*d}):T,R,bt(1,R.length,R)))})(),nextId:l.segments.length})(Lt(R=>M=>ut.compare(lt(J(lt)(-1e18)(R.incoming))(J(lt)(-1e18)(R.outgoing))-dt(J(dt)(1e18)(R.incoming))(J(dt)(1e18)(R.outgoing)))(lt(J(lt)(-1e18)(M.incoming))(J(lt)(-1e18)(M.outgoing))-dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(M.outgoing))))(xt(R=>Dt(R)(U))(V.decisions)));return{segments:(()=>{const R=(M,S)=>{if(M.tag==="Leaf")return S;if(M.tag==="Node")return R(M._5,qt("Cons",M._4,R(M._6,S)));g()};return Ct($t.foldr,R(B.segMap,Ht))})(),deps:(()=>{const R=B.segMap,M=(I,A)=>{if(I.tag==="Leaf")return A;if(I.tag==="Node")return M(I._5,qt("Cons",I._4,M(I._6,A)));g()},S=Ct($t.foldr,M(R,Ht)),D=S.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<S.length?I._2>=0&&I._2<S.length?S[I._1].splitPartner.tag!=="Nothing"&&S[I._1].splitPartner.tag==="Just"&&S[I._1].splitPartner._1===S[I._2].id||S[I._2].splitPartner.tag!=="Nothing"&&S[I._2].splitPartner.tag==="Just"&&S[I._2].splitPartner._1===S[I._1].id?[]:o(d,S[I._1],S[I._2]):[]:[]),...Tt(S)(I=>I.splitBy.tag==="Just"&&I.splitPartner.tag==="Just"&&(()=>{const A=Dt(I.splitPartner._1)(R);if(A.tag==="Nothing")return!1;if(A.tag==="Just")return!0;g()})()&&(()=>{const A=Dt(I.splitBy._1)(R);if(A.tag==="Nothing")return!1;if(A.tag==="Just")return!0;g()})()?[{src:I.id,tgt:I.splitBy._1,weight:1,kind:Ro},{src:I.splitBy._1,tgt:I.splitPartner._1,weight:1,kind:Ro}]:[])]})()}})(),p=h.segments,m=p.length,y=G=>{let P=G,V=!0,U;for(;V;){const B=P,R=Vt(M=>{const S=Dt(M)(B.inWeight);if(S.tag==="Nothing")return!0;if(S.tag==="Just")return S._1===0;g()})(B.remaining);if(R.tag==="Nothing"){V=!1,U=B;continue}if(R.tag==="Just"){const M=R._1;P={...B,inWeight:J(S=>D=>vt(it)(ue)(D.tgt)(-D.weight)(S))(B.inWeight)((()=>{const S=Dt(M)(B.depsBySrc);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()),marks:j(it)(M)(B.nextSource)(B.marks),nextSource:B.nextSource+1|0,outWeight:J(S=>D=>vt(it)(ue)(D.src)(-D.weight)(S))(B.outWeight)((()=>{const S=Dt(M)(B.depsByTgt);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()),remaining:st(S=>S!==M,B.remaining)};continue}g()}return U},x=G=>{let P=G,V=!0,U;for(;V;){const B=P,R=Vt(M=>{const S=Dt(M)(B.outWeight);if(S.tag==="Nothing")return!0;if(S.tag==="Just")return S._1===0;g()})(B.remaining);if(R.tag==="Nothing"){V=!1,U=B;continue}if(R.tag==="Just"){const M=R._1;P={...B,inWeight:J(S=>D=>vt(it)(ue)(D.tgt)(-D.weight)(S))(B.inWeight)((()=>{const S=Dt(M)(B.depsBySrc);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()),marks:j(it)(M)(B.nextSink)(B.marks),nextSink:B.nextSink-1|0,outWeight:J(S=>D=>vt(it)(ue)(D.src)(-D.weight)(S))(B.outWeight)((()=>{const S=Dt(M)(B.depsByTgt);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()),remaining:st(S=>S!==M,B.remaining)};continue}g()}return U},N=(G=>{let P=G,V=!0,U;for(;V;){const B=y(x(P));if(B.remaining.length===0){V=!1,U=W(R=>{const M=Dt(R.id)(B.marks),S=(()=>{if(M.tag==="Nothing")return R.id;if(M.tag==="Just")return M._1;g()})();return{...R,mark:S<m?(S+m|0)+1|0:S}})(p);continue}P=(()=>{const R=S=>{const D=Dt(S)(B.outWeight),I=Dt(S)(B.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},M=Lt(S=>D=>it.compare(R(D))(R(S)))(B.remaining);if(0<M.length){const S=M[0];return{...B,inWeight:J(D=>I=>vt(it)(ue)(I.tgt)(-I.weight)(D))(B.inWeight)((()=>{const D=Dt(S)(B.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),marks:j(it)(S)(B.nextSource)(B.marks),nextSource:B.nextSource+1|0,outWeight:J(D=>I=>vt(it)(ue)(I.src)(-I.weight)(D))(B.outWeight)((()=>{const D=Dt(S)(B.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),remaining:st(D=>D!==S,B.remaining)}}return B})()}return U})({remaining:W(G=>G.id)(p),marks:Q,inWeight:J(G=>P=>vt(it)(ue)(P.tgt)(P.weight)(G))(Q)(h.deps),outWeight:J(G=>P=>vt(it)(ue)(P.src)(P.weight)(G))(Q)(h.deps),depsBySrc:J(G=>P=>vt(it)(ee)(P.src)([P])(G))(Q)(h.deps),depsByTgt:J(G=>P=>vt(it)(ee)(P.tgt)([P])(G))(Q)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),w=(()=>{const G=(()=>{const U=Or(W(B=>b(B.id,B.mark))(N));return{segments:N,deps:xt(B=>(()=>{if(B.kind==="Critical")return!0;if(B.kind==="Regular")return!1;g()})()?v("Just",B):(()=>{const R=Dt(B.src)(U),M=Dt(B.tgt)(U);return(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})()>(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()})()?B.weight===0?T:v("Just",{src:B.tgt,tgt:B.src,weight:B.weight,kind:B.kind}):v("Just",B))(h.deps)}})(),P=J(U=>B=>vt(it)(ue)(B.tgt)(1)(U))(Q)(G.deps),V=(U=>{let B=U,R=!0,M;for(;R;){const S=B,D=Mt(I=>T,I=>A=>v("Just",{head:I,tail:A}),S.queue);if(D.tag==="Nothing"){R=!1,M=S;continue}if(D.tag==="Just"){B=J((()=>{const I=Dt(D._1.head)(S.slots),A=(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;g()})();return H=>$=>{const X=Dt($)(H.inDegree),q=(()=>{if(X.tag==="Nothing")return-1;if(X.tag==="Just")return X._1-1|0;g()})();return{...H,slots:j(it)($)(qg((()=>{const z=Dt($)(H.slots);if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})())(A+1|0))(H.slots),inDegree:j(it)($)(q)(H.inDegree),queue:q===0?[...H.queue,$]:H.queue}}})())({...S,queue:D._1.tail})((()=>{const I=Dt(D._1.head)(S.adj);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})());continue}g()}return M})({slots:Or(W(U=>b(U.id,0))(G.segments)),inDegree:P,adj:J(U=>B=>vt(it)(ee)(B.src)([B.tgt])(U))(Q)(G.deps),queue:W(U=>U.id)(st(U=>{const B=Dt(U.id)(P);if(B.tag==="Nothing")return!0;if(B.tag==="Just")return B._1===0;g()},G.segments))});return Lt(U=>B=>it.compare(U.slot)(B.slot))(W(U=>({...U,slot:(()=>{const B=Dt(U.id)(V.slots);if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})()}))(G.segments))})(),L=1+J(G=>P=>qg(G)(P.slot))(0)(w)|0,k=Tt(w)(G=>G.members),E=st(G=>Be(fn)(G.edge.id)(k),t),O=J(lt)(-1e18)(W(G=>G.fromPos._2)(E)),Y=J(dt)(1e18)(W(G=>G.toPos._2)(E));if(O>Y){const G=Or(W(P=>b(P.id,P))(w));return Oe(W(P=>W(V=>b(V,{slot:P.slot,slotCount:L,gapTop:Y,gapBottom:O,partner:(()=>{if(P.splitPartner.tag==="Just"){const U=Dt(P.splitPartner._1)(G);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)(G);return!(V.tag==="Just"&&(()=>{if(V._1.splitBy.tag==="Nothing")return!1;if(V._1.splitBy.tag==="Just")return!0;g()})())}if(P.splitPartner.tag==="Nothing")return!0;g()},w)))}const et=Or(W(G=>b(G.id,G))(w));return Oe(W(G=>W(P=>b(P,{slot:G.slot,slotCount:L,gapTop:O,gapBottom:Y,partner:(()=>{if(G.splitPartner.tag==="Just"){const V=Dt(G.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(G.splitPartner.tag==="Nothing")return T;g()})()}))(G.members))(st(G=>{if(G.splitPartner.tag==="Just"){const P=Dt(G.splitPartner._1)(et);return!(P.tag==="Just"&&(()=>{if(P._1.splitBy.tag==="Nothing")return!1;if(P._1.splitBy.tag==="Just")return!0;g()})())}if(G.splitPartner.tag==="Nothing")return!0;g()},w)))})()))(Q)(n2(J(u=>s=>{const a=Rr(s.edge.from.node)(n);if(a.tag==="Just"){const c=Rr(s.edge.to.node)(n);return c.tag==="Just"&&a._1.layer!==c._1.layer?vt(it)(ee)(Br(a._1.layer)(c._1.layer))([s])(u):u}return u})(Q)((()=>{const u=s=>b((()=>{const a=Rr(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=Rr(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return Lt(s=>a=>e2(u(s))(u(a)))(t)})())))},o2=t=>e=>{const n=$g(t)(e),r=J(i=>o=>j(C)(o.node)(o)(i))(Q)(e);return J(i=>o=>{const u=Rr(o.edge.from.node)(r);if(u.tag==="Just"){const s=Rr(o.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=i2(o.edge.id)(n);if(a.tag==="Just")return j(it)(Br(u._1.layer)(s._1.layer))(a._1.slotCount)(i)}return i}return i})(Q)(t)},Xg=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()},Si=t=>e=>n=>r=>Xg(i=>n>=i.x&&n<i.x+i.w&&e>i.y&&t<i.y+i.h)(r),Bo=t=>e=>n=>r=>Si(ce(e)(n))(ge(e)(n))(r)(t),zo=rt(4),u2=tc(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()}),Gi=ja(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})())}),s2=t=>e=>n=>{const r=Mt(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=ii(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()},Pi=t=>{const e=r=>i=>{const o=Mt(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=Mt(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()},Di=t=>e=>n=>r=>Xg(i=>n>=i.y&&n<i.y+i.h&&e>i.x&&t<i.x+i.w)(r),Ii=t=>e=>n=>r=>Di(ce(e)(n))(ge(e)(n))(r)(t),a2=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")&&!Bo(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:re},...o]):T,_=c._1.start._2===d._1.end._2&&(!a||c._1.direction==="H")&&(!s||d._1.direction==="H")&&!Ii(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:ne},...o]):T;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return T;g()}if(c.tag==="Nothing")return T;g()},c2=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=a2(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)},g2=t=>e=>n=>r=>{const i=(l,_,h)=>!Bo(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)=>!Ii(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:re},...u]):d._1.start._2===_._1.end._2&&(!c||d._1.direction==="H")&&(!a||_._1.direction==="H")&&f(d._1.start._2,d._1.start._1,_._1.end._1)?v("Just",[...s,{start:d._1.start,end:_._1.end,direction:ne},...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:re},{start:b(d._1.start._1,_._1.end._2),end:_._1.end,direction:ne},...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:ne},{start:b(_._1.end._1,d._1.start._2),end:_._1.end,direction:re},...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()},f2=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=g2(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)},_2=t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r,s=Pi(Gi(c2(t)(f2(t)(u))));if(s.length<u.length){r=s;continue}i=!1,o=s}return o};return n=>e(Pi(Gi(n)))},d2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=Lt(c=>f=>ut.compare(c.x)(f.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=Lt(a=>c=>ut.compare(c.x)(a.x))(W(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},l2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=Lt(c=>f=>ut.compare(c.y)(f.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=Lt(a=>c=>ut.compare(c.y)(a.y))(W(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},h2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=Lt(c=>f=>ut.compare(f.x)(c.x))(W(c=>({...c,x:c.x+c.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=Lt(a=>c=>ut.compare(a.x)(c.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},p2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=st(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=Lt(c=>f=>ut.compare(f.y)(c.y))(W(c=>({...c,y:c.y+c.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=Lt(a=>c=>ut.compare(a.y)(c.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},Yg=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},Vg=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)?Yg(a=>Si(o)(u)(a)(t))(s)(1):s},m2=t=>e=>n=>r=>i=>{const o=ce(e)(n),u=ge(e)(n);if(!Di(o)(u)(r)(t))return r;if(!Di(o)(u)(i)(t))return i;const s=(r+i)/2;return Di(o)(u)(s)(t)?Yg(a=>Di(o)(u)(a)(t))(s)(1):s},y2=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},x2=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},N2=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)=>!Bo(e)(ce(k)(E))(ge(k)(E))(L),f=(L,k,E)=>!Bo(n)(ce(k)(E))(ge(k)(E))(L),d=(L,k,E,O)=>t.tag==="Just"&&!Ii(n)(ce(L)(k))(ge(L)(k))(t._1)?t._1:m2(e)(L)(k)(E)(O),l=(L,k,E,O)=>{if(L===E){const et=y2(e)(k)(O)(L),G=l2(e)(L)(k)(O),P=p2(e)(L)(k)(O);return[{start:b(L,k),end:b(L,G),direction:re},{start:b(L,G),end:b(et,G),direction:ne},{start:b(et,G),end:b(et,P),direction:re},{start:b(et,P),end:b(E,P),direction:ne},{start:b(E,P),end:b(E,O),direction:re}]}const Y=d(L,E,k,O);return[{start:b(L,k),end:b(L,Y),direction:re},{start:b(L,Y),end:b(E,Y),direction:ne},{start:b(E,Y),end:b(E,O),direction:re}]},_=(L,k,E,O)=>{if(k===O){const et=x2(e)(L)(E)(k),G=d2(e)(k)(L)(E),P=h2(e)(k)(L)(E);return[{start:b(L,k),end:b(G,k),direction:ne},{start:b(G,k),end:b(G,et),direction:re},{start:b(G,et),end:b(P,et),direction:ne},{start:b(P,et),end:b(P,O),direction:re},{start:b(P,O),end:b(E,O),direction:ne}]}const Y=Vg(e)(k)(O)(L)(E);return[{start:b(L,k),end:b(Y,k),direction:ne},{start:b(Y,k),end:b(Y,O),direction:re},{start:b(Y,O),end:b(E,O),direction:ne}]},h=(L,k,E)=>!Ii(e)(ce(k)(E))(ge(k)(E))(L),p=(L,k,E)=>!Ii(n)(ce(k)(E))(ge(k)(E))(L),m=(L,k,E,O)=>{if(p(k,L,E)&&f(E,k,O))return[{start:b(L,k),end:b(E,k),direction:ne},{start:b(E,k),end:b(E,O),direction:re}];const Y=Vg(e)(k)(O)(L)(E);return[{start:b(L,k),end:b(Y,k),direction:ne},{start:b(Y,k),end:b(Y,O),direction:re},{start:b(Y,O),end:b(E,O),direction:ne}]},y=(L,k,E,O)=>{if(f(L,k,O)&&p(O,L,E))return[{start:b(L,k),end:b(L,O),direction:re},{start:b(L,O),end:b(E,O),direction:ne}];const Y=d(L,E,k,O);return[{start:b(L,k),end:b(L,Y),direction:re},{start:b(L,Y),end:b(E,Y),direction:ne},{start:b(E,Y),end:b(E,O),direction:re}]},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:re}]: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:re}]: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:ne}]:_(s._1,s._2,a._1,a._2):o==="North"||o==="South"?m(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="West"){if(o==="East")return s._2===a._2&&h(s._2,s._1,a._1)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:ne}]:_(s._1,s._2,a._1,a._2);if(o==="North"||o==="South")return m(s._1,s._2,a._1,a._2)}return l(s._1,s._2,a._1,a._2)})(),N=(()=>{if(r==="South"||r==="North")return re;if(r==="East"||r==="West")return ne;g()})(),w={start:b(a._1,a._2),end:b(u._1,u._2),direction:(()=>{if(o==="South"||o==="North")return re;if(o==="East"||o==="West")return ne;g()})()};return s._1===a._1&&s._2===a._2?[{start:b(i._1,i._2),end:b(u._1,u._2),direction:N}]:s2({start:b(i._1,i._2),end:b(s._1,s._2),direction:N})(x)(w)},J2=W(t=>({x:t.position._1*zo-2,y:t.position._2*zo-2,w:t.size._1*zo+4,h:t.size._2*zo+4})),Fs=jt(C)(zt),Fn=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},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},T2=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},Ug=t=>e=>{const n=e.position._1+e.size._1,r=e.position._2*2+e.size._2,i=e.position._1*2+e.size._1,o=e.position._2+e.size._2;if(t==="South")return b(i,o*2);if(t==="North")return b(i,e.position._2*2);if(t==="East")return b(n*2,r);if(t==="West")return b(e.position._1*2,r);g()},Ms=t=>e=>{const n=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()},Zg=t=>e=>J(n=>r=>vt(t)(ee)(e(r))([r])(n))(Q),Kg=t=>e=>n=>r=>{const i=(t==="South"||t==="North")&&(e==="East"||e==="West")&&(()=>{if(t==="South")return r._2>n._2;if(t==="North")return r._2<n._2;if(t==="East")return r._2>n._2;if(t==="West")return r._2<n._2;g()})()&&(()=>{if(e==="East")return n._1>r._1;if(e==="West"||e==="North")return n._1<r._1;if(e==="South")return n._1>r._1;g()})(),o=(t==="East"||t==="West")&&(e==="North"||e==="South")&&(()=>{if(t==="South")return r._1>n._1;if(t==="North")return r._1<n._1;if(t==="East")return r._1>n._1;if(t==="West")return r._1<n._1;g()})()&&(()=>{if(e==="East")return n._2>r._2;if(e==="West"||e==="North")return n._2<r._2;if(e==="South")return n._2>r._2;g()})();return(t==="South"?e==="North"&&n._1===r._1&&r._2>n._2:t==="North"?e==="South"&&n._1===r._1&&r._2<n._2:t==="East"?e==="West"&&n._2===r._2&&r._1>n._1:t==="West"&&e==="East"&&n._2===r._2&&r._1<n._1)?0:i||o?1:2},jg=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,i=e.length;return i===0?Q:Fs(i===1?W(o=>b(o,r))(e):Ft(o=>u=>b(u,t.lo+rt(o+1|0)*n/rt(i+1|0)))(e))},tf=t=>e=>n=>r=>i=>{const o=Zg(C)(_=>_.to.node)(t),u=Zg(C)(_=>_.from.node)(t),s=J(_=>h=>j(C)(h.node)(h)(_))(Q)(e),a=(_,h,p)=>{const m=Fn(_)(s);if(m.tag==="Nothing")return b(0,0);if(m.tag==="Just"){const y=Fn(_)(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=Fs(Tt(r)(_=>{if(_.nodes.length<=2)return[];const h=rt(4);if(1<_.nodes.length){const p=Fn(_.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 W(y=>b(y,m))(Te(y=>x=>_.edgeId+":"+y+"->"+x,_.nodes,bt(1,_.nodes.length,_.nodes)))}g()}return[]})),f=_=>{const h=Fn(_.from.node)(s),p=Fn(_.to.node)(s);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,y=p._1,x=Lt(N=>w=>it.compare(N.score)(w.score))(W(N=>{const w=N._1,L=N._2;return{from:w,to:L,score:(()=>{const k=(et,G,P,V,U)=>{const B=Ms(et)(G),R=Ms(et)(P);return B.lo<R.hi&&R.lo<B.hi&&(w==="South"?L==="North"&&U._2>V._2:w==="North"?L==="South"&&U._2<V._2:w==="East"?L==="West"&&U._1>V._1:w==="West"&&L==="East"&&U._1<V._1)?0:Kg(w)(L)(V)(U)},E=Ug(w)(m),O=Ug(L)(y),Y=Kg(w)(L)(E)(O);return(()=>{if(Y>0){if(w==="South")return L==="North"?k(he,m,y,E,O)*10|0:Y*10|0;if(w==="North")return L==="South"?k(le,m,y,E,O)*10|0:Y*10|0;if(w==="East")return L==="West"?k(Gn,m,y,E,O)*10|0:Y*10|0;if(w==="West"&&L==="East")return k(Pn,m,y,E,O)*10|0}return Y*10|0})()+(w==="South"?L==="North"?0:15:w==="North"?L==="South"?0:15:w==="East"?L==="West"?5:15:w==="West"&&L==="East"?5:15)|0})()}})([b(he,le),b(Gn,le),b(Pn,le),b(he,Gn),b(he,Pn),b(le,he),b(le,Gn),b(le,Pn),b(Gn,he),b(Pn,he),b(Gn,Pn),b(Pn,Gn)]));if(0<x.length)return{from:x[0].from,to:x[0].to}}return{from:he,to:le}},d=Fs(W(_=>b(_.id,f(_)))(t)),l=(_,h,p,m,y,x)=>{const N=rt(4),w=Fn(h)(s);if(w.tag==="Nothing")return b(0,0);if(w.tag==="Just"){const L=T2(b(p,_))(i);if(L.tag==="Just"){const k=w._1.position._1*N+L._1,E=rt(4);if(_==="South")return b(k,(w._1.position._2+w._1.size._2)*E);if(_==="North")return b(k,w._1.position._2*E);if(_==="East")return b((w._1.position._1+w._1.size._1)*E,k);if(_==="West")return b(w._1.position._1*E,k);g()}if(L.tag==="Nothing"){const k=Ms(_)(w._1),E=(k.lo+k.hi)/2,O=As(p)(jg(k)(W(G=>G.id)(Lt(G=>P=>ut.compare(y(_)(G))(y(_)(P)))(st(G=>{const P=As(G.id)(d);if(P.tag==="Just"){const V=x(P._1);return V==="North"?_==="North":V==="South"?_==="South":V==="East"?_==="East":V==="West"&&_==="West"}if(P.tag==="Nothing")return!0;g()},(()=>{const G=Fn(h)(m);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()))))),Y=(()=>{if(O.tag==="Nothing")return E;if(O.tag==="Just")return O._1;g()})(),et=rt(4);if(_==="South")return b(Y,(w._1.position._2+w._1.size._2)*et);if(_==="North")return b(Y,w._1.position._2*et);if(_==="East")return b((w._1.position._1+w._1.size._1)*et,Y);if(_==="West")return b(w._1.position._1*et,Y)}}g()};return W(_=>{const h=As(_.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()})(W(_=>{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=Fn(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=Fn(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))},ef=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},w2=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Os=t=>e=>t.gapTop+1*rt(4)+rt(e)*2.5*rt(4),v2=t=>e=>{const n=ef(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return v("Just",{slot1Y:Os(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Os(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return T;g()}if(n.tag==="Nothing")return T;g()},b2=t=>e=>{const n=J(r=>i=>j(C)(i.node)(i)(r))(Q)(e);return Oe(Ft(r=>i=>{const o=zr(i.node)(n);if(o.tag==="Nothing")return[];if(o.tag==="Just"){const u=o._1;return Ft(s=>a=>{const c=i.edges.length,f=rt(4),d=u.position._1*f,l=u.position._2*f,_=u.size._2*f,h=rt((2*c|0)+1|0),p=l+_*rt(c-s|0)/h,m=l+_*rt((c+1|0)+s|0)/h,y=d-f*2.5*rt(s+1|0),x=[{start:b(d,p),end:b(y,p),direction:ne},{start:b(y,p),end:b(y,m),direction:re},{start:b(y,m),end:b(d,m),direction:ne}];return{edge:a.id,segments:x,bends:Te(N=>w=>N.end,x,bt(1,3,x)),bendType:[],jumps:[],reversed:!1}})(i.edges)}g()})(W(r=>({node:r._1,edges:r._2}))(w2(J(r=>i=>vt(C)(ee)(i.from.node)([i])(r))(Q)(t)))))},k2=t=>e=>{const n=J(o=>u=>j(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 Lt(o=>u=>{const s=it.compare(i(o.edge.from.node))(i(u.edge.from.node));if(s==="EQ"){const a=ut.compare(r(o.edge.from.node))(r(u.edge.from.node));return a==="EQ"?ut.compare(r(o.edge.to.node))(r(u.edge.to.node)):a}return s})(t)},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}},L2=t=>t.from.node===t.to.node,E2=t=>e=>n=>r=>{const i=_2(n)(N2(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:i,bends:Te(o=>u=>o.end,i,bt(1,i.length,i)),bendType:[],jumps:[],reversed:!1}},C2=t=>e=>n=>r=>{const i=[{start:b(r.fromPos._1,r.fromPos._2),end:b(r.fromPos._1,t.slot1Y),direction:re},{start:b(r.fromPos._1,t.slot1Y),end:b(t.splitX,t.slot1Y),direction:ne},{start:b(t.splitX,t.slot1Y),end:b(t.splitX,t.slot2Y),direction:re},{start:b(t.splitX,t.slot2Y),end:b(r.toPos._1,t.slot2Y),direction:ne},{start:b(r.toPos._1,t.slot2Y),end:b(r.toPos._1,r.toPos._2),direction:re}];return{edge:r.edge.id,segments:i,bends:Te(o=>u=>o.end,i,bt(1,5,i)),bendType:[],jumps:[],reversed:!1}},S2=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===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):st(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=zr(t.edge.to.node)(n);return i.tag==="Just"?st(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):st(o=>!0,e)},G2=t=>e=>{const n=ef(e.edge.id)(t);if(n.tag==="Just")return v("Just",Os(n._1)(n._1.slot));if(n.tag==="Nothing")return T;g()},P2=t=>e=>n=>r=>i=>{const o=J(c=>f=>j(C)(f.node)(f)(c))(Q)(e),u=J2(e),s=tf(st(c=>c.from.node!==c.to.node,t))(e)(n)(r)(i),a=$g(s)(e);return[...b2(st(L2,t))(e),...J(c=>f=>{const d=S2(f)(u)(o),l=[...d,...c.edgeObstacles],_=v2(a)(f),h=(()=>{if(_.tag==="Just")return C2(_._1)(d)(l)(f);if(_.tag==="Nothing")return E2(G2(a)(f))(d)(l)(f);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...u2(h.segments)]}})({results:[],edgeObstacles:[]})(k2(s)(e)).results]},nr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},rr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},D2=t=>e=>n=>{if(t.start._1!==e.start._1)return T;const r=rr(nr(t.start._2)(t.end._2))(nr(e.start._2)(e.end._2)),i=nr(rr(t.start._2)(t.end._2))(rr(e.start._2)(e.end._2));return r<i?v("Just",{position:b(t.start._1,(r+i)/2),crossingEdge:n}):T},I2=t=>e=>n=>{if(t.start._2!==e.start._2)return T;const r=rr(nr(t.start._1)(t.end._1))(nr(e.start._1)(e.end._1)),i=nr(rr(t.start._1)(t.end._1))(rr(e.start._1)(e.end._1));return r<i?v("Just",{position:b((r+i)/2,t.start._2),crossingEdge:n}):T},Q2=t=>e=>n=>{if(t.direction==="H")return I2(t)(e)(n);if(t.direction==="V")return D2(t)(e)(n);g()},F2=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=>Q2(o)(s)(u.edge))(st(s=>s.direction==="H"?o.direction==="H":s.direction==="V"&&o.direction==="V",u.segments))))},A2=t=>e=>n=>e.start._1>nr(t.start._1)(t.end._1)&&e.start._1<rr(t.start._1)(t.end._1)&&t.start._2>nr(e.start._2)(e.end._2)&&t.start._2<rr(e.start._2)(e.end._2)?v("Just",{position:b(e.start._1,t.start._2),crossingEdge:n}):T,M2=t=>e=>Tt(st(n=>n.direction==="H",t.segments))(n=>Tt(e)(r=>xt(i=>A2(n)(i)(r.edge))(st(i=>i.direction==="V",r.segments)))),O2=t=>e=>n=>[...M2(e)(st(r=>r.edge!==e.edge,n)),...F2(t)(e)(n)],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=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},rf=t=>me(3)(t)==="$d:",R2=t=>e=>n=>J(r=>i=>{const o=nf(i.from.node)(t),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})(),s=nf(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=W(l=>"$d:"+c+":"+oe(l))(It(1,a-1|0)),d=[i.from.node,...f,i.to.node];return{...r,layers:J(l=>_=>{const h=_._2,p=hd(u+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;g()})(r.layers)(Te(Cn,It(1,a-1|0),f)),edges:[...r.edges,...Te(l=>_=>({id:c+":"+l+"->"+_,from:{node:l,port:i.from.port},to:{node:_,port:i.to.port},label:T}),d,bt(1,d.length,d))],chains:[...r.chains,{edgeId:i.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),Wo=(()=>{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 xe;if(r==="GT")return Ne;if(e._2==="North")return n._2==="North"?Ge:xe;if(n._2==="North")return Ne;if(e._2==="South")return n._2==="South"?Ge:xe;if(n._2==="South")return Ne;if(e._2==="East")return n._2==="East"?Ge:xe;if(n._2==="East")return Ne;if(e._2==="West"&&n._2==="West")return Ge;g()},Eq0:()=>t}})(),B2=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=Wo.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},z2=jt(C)(zt),Rs=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},W2=jt(Wo)(zt),of=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Wr=t=>e=>n=>r=>{const i=B2(b(e,n))(t);if(i.tag==="Nothing")return r;if(i.tag==="Just")return i._1;g()},uf=t=>e=>n=>{const r=z2(Oe(W(u=>Ft(s=>a=>b(a,s))(u))(t))),i=(u,s)=>{if(u==="South"){const a=Rs(s.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()}if(u==="North"){const a=Rs(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(Wo.compare,ke,W2(W(c=>b(b(c._1,u),c._2))(of(jg({lo:0,hi:(()=>{const c=Rs(a._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return me(3)(a._1)==="$d:"?0:1;g()})()})(W(c=>c.id)(Lt(c=>f=>it.compare(i(u,c))(i(u,f)))(a._2)))))),s))(Q)(of(J(s=>a=>a.from.node===a.to.node?s:u==="South"?vt(C)(ee)(a.from.node)([a])(s):u==="North"?vt(C)(ee)(a.to.node)([a])(s):s)(Q)(e)));return Ee(Wo.compare,ke,o(le),o(he))},sf=t=>t,af=t=>t,cf=t=>t,q2=J(t=>e=>j(C)(e)()(t))(Q),H2=(()=>{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},rn=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=jt(C)(zt),Bs=uc(C),zs=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),$2=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},X2=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},gf=cf("VDown"),ff=cf("VUp"),Y2=af("ForwardPhase"),V2=af("StackPhase"),_f=sf("HRight"),df=sf("HLeft"),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},U2=t=>e=>n=>{const r=J(u=>s=>vt(C)(ue)(s.tgt)(1)(u))(Q)(t),i=H2(q2([...W(u=>u.src)(t),...W(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)(ee)(s.src)([{target:s.tgt,sep:s.sep}])(u))(Q)(t);return(u=>s=>a=>{let c=u,f=s,d=a,l=!0,_;for(;l;){const h=c,p=f,m=d,y=Mt(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(L=>k=>{const E=ot(k.target)(L.result),O=N+k.sep,Y=ot(k.target)(L.indeg),et=(()=>{if(Y.tag==="Nothing")return-1;if(Y.tag==="Just")return Y._1-1|0;g()})();return{newQueue:et===0?[...L.newQueue,k.target]:L.newQueue,result:j(C)(k.target)((()=>{if(E.tag==="Nothing")return O;if(E.tag==="Just"){if(n==="VDown")return rn(E._1)(O);if(n==="VUp")return Nn(E._1)(O)}g()})())(L.result),indeg:j(C)(k.target)(et)(L.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const L=ot(y._1.head)(o);if(L.tag==="Nothing")return[];if(L.tag==="Just")return L._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=>j(C)(s)(0)(u))(Q)(i))},Z2=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(rn)(999999)(n);if(r===0||n.length===0)return t;const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Wt("Node",o._1,o._2,o._3,o._4-r,i(o._5),i(o._6));g()};return i(t)},hf=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=rn(d)(l._1),a=l._2;continue}g()}return f};return r(-999999)(n)-i(999999)(n)},Qi=t=>e=>(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(a===e){u=!1,s=c;continue}i=(()=>{const f=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]),K2=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>{const d=(S,D,I)=>{const A=S.from.node===D?S.from.port:S.to.node===D?S.to.port:T;if(A.tag==="Just"){const H=ot(D)(i);if(H.tag==="Just"){const $=Vt(X=>X.id===A._1)(H._1);if($.tag==="Just"){const X=rt($._1.offset)*rt(4);return I==="North"||I==="South"?X:0}if($.tag==="Nothing"){const X=ot(D)(r),q=Wr(u)(S.id)(I)((()=>{if(X.tag==="Nothing")return .5;if(X.tag==="Just")return X._1._1/2;g()})());return I==="North"||I==="South"?q:0}g()}if(H.tag==="Nothing"){const $=ot(D)(r),X=Wr(u)(S.id)(I)((()=>{if($.tag==="Nothing")return .5;if($.tag==="Just")return $._1._1/2;g()})());return I==="North"||I==="South"?X:0}g()}if(A.tag==="Nothing"){const H=ot(D)(r),$=Wr(u)(S.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=(S,D)=>{if(S.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()},_=(S,D,I)=>J(A=>H=>j(C)(H)((()=>{const $=ot(H)(A);if($.tag==="Nothing")return 0+D;if($.tag==="Just")return $._1+D;g()})())(A))(I)(Qi(a)(S)),h=(()=>{if(f==="HRight")return n;if(f==="HLeft")return Je(n);g()})(),p=S=>{const D=ot(S)(r);if(D.tag==="Nothing")return 1;if(D.tag==="Just")return D._1._1;g()},m=Jn(Oe(Ft(S=>D=>W(I=>b(I,S))(D))(n))),y=(S,D)=>me(3)(S)==="$d:"&&me(3)(D)==="$d:"||me(3)(S)==="$d:"||me(3)(D)==="$d:"?10:rt(t.nodeGap),x=J(S=>D=>Bs(I=>v("Just",[...(()=>{if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})(),D]))(D.to.node)(S))(Q)(o),N=J(S=>D=>Bs(I=>v("Just",[...(()=>{if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})(),D]))(D.from.node)(S))(Q)(o),w=Oe(n),L=J(S=>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?S:Bs(H=>v("Just",(()=>{if(H.tag==="Nothing")return!0;if(H.tag==="Just")return H._1;g()})()&&me(3)(D)==="$d:"))(A)(S)})(Jn(W(S=>b(S,!0))(br(C.compare)((()=>{const S=(D,I)=>{if(D.tag==="Leaf")return I;if(D.tag==="Node")return S(D._5,qt("Cons",D._4,S(D._6,I)));g()};return Ct($t.foldr,S(a.root,Ht))})()))))(w),k=(S,D)=>{const I=S.free,A=ot(I)(a.root),H=(()=>{if(A.tag==="Nothing")return I;if(A.tag==="Just")return A._1;g()})(),$=ot(H)(L),X=(()=>{if($.tag==="Nothing")return!0;if($.tag==="Just")return $._1;g()})();return J(q=>z=>{if(q.edge.tag==="Just")return q;if(q.edge.tag==="Nothing"){if((()=>{const at=ot(H)(D.su);return!X&&(()=>{const yt=ot(z.from.node)(m);return z.from.node!==z.to.node&&(()=>{const St=ot(z.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=z.from.node===I?z.to.node:z.from.node,Z=ot(tt)(a.root),ct=(()=>{if(Z.tag==="Nothing")return tt;if(Z.tag==="Just")return Z._1;g()})(),ft=ct!==H;return ft&&(()=>{const at=ot(ct)(D.blockFinished);if(at.tag==="Nothing")return!1;if(at.tag==="Just")return at._1;g()})()?{...q,edge:v("Just",z),hasEdges:!0}:{...q,hasEdges:q.hasEdges||ft}}g()})({edge:T,hasEdges:!1})((()=>{if(S.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=(S,D,I,A)=>{const H=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),$={free:D,isRoot:I},X=k($,A);if(X.edge.tag==="Nothing")return X.hasEdges?{thresh:H,state:{...A,queue:[...A.queue,$]}}:{thresh:H,state:A};if(X.edge.tag==="Just"){const q=X.edge._1.from.node===D?X.edge._1.to.node:X.edge._1.from.node;return{thresh:(()=>{const z=ot((()=>{const ft=ot(q)(a.root);if(ft.tag==="Nothing")return q;if(ft.tag==="Just")return ft._1;g()})())(A.x),tt=ot(q)(s),Z=ot(D)(s),ct=(()=>{if(z.tag==="Just")return z._1;if(z.tag==="Nothing")return T;g()})();return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+(()=>{if(tt.tag==="Nothing")return 0;if(tt.tag==="Just")return tt._1;g()})()+d(X.edge._1,q,(()=>{if(I){if(f==="HRight")return he;if(f==="HLeft")return le;g()}if(f==="HRight")return le;if(f==="HLeft")return he;g()})())-(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;g()})()-d(X.edge._1,D,(()=>{if(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:j(C)((()=>{const z=ot(X.edge._1.from.node)(a.root);if(z.tag==="Nothing")return X.edge._1.from.node;if(z.tag==="Just")return z._1;g()})())(!0)(j(C)((()=>{const z=ot(X.edge._1.to.node)(a.root);if(z.tag==="Nothing")return X.edge._1.to.node;if(z.tag==="Just")return z._1;g()})())(!0)(A.su))}}}g()},O=(S,D,I,A)=>{const H=D===S,$=ot(D)(a.align),X=(()=>{if($.tag==="Nothing")return D===S;if($.tag==="Just")return $._1===S;g()})();if(!(H||X))return{thresh:I,state:A};const q=(()=>{if(c==="VDown")return H&&I<=-1e18;if(c==="VUp")return H&&I>=1e18;g()})()?E(S,D,!0,A):{thresh:I,state:A};return(()=>{if(c==="VDown")return q.thresh<=-1e18&&X;if(c==="VUp")return q.thresh>=1e18&&X;g()})()?E(S,D,!1,q.state):q},Y=S=>D=>I=>{const A=ot(I)(e.nodeIndex),H=(()=>{if(A.tag==="Nothing")return 0;if(A.tag==="Just")return A._1;g()})(),$=Vt(Z=>Be(fn)(I)(Z))(h),X=(()=>{if($.tag==="Nothing")return[];if($.tag==="Just")return $._1;g()})(),q=X.length;if((()=>{if(c==="VDown")return H<=0;if(c==="VUp")return H>=(q-1|0);g()})()){const Z=O(S,I,D.thresh,D.st);return{...D,st:Z.state,thresh:Z.thresh}}const z=(()=>{if(c==="VDown")return H-1|0;if(c==="VUp")return H+1|0;g()})(),tt=z>=0&&z<X.length?v("Just",X[z]):T;if(tt.tag==="Nothing")return D;if(tt.tag==="Just"){const Z=ot(tt._1)(a.root),ct=(()=>{if(Z.tag==="Nothing")return tt._1;if(Z.tag==="Just")return Z._1;g()})(),ft=O(S,I,D.thresh,et(ct)(D.st)),at=(()=>{const Kt=ot(S)(ft.state.sink);if(Kt.tag==="Nothing")return S===S;if(Kt.tag==="Just")return Kt._1===S;g()})()?{...ft.state,sink:j(C)(S)((()=>{const Kt=ot(ct)(ft.state.sink);if(Kt.tag==="Nothing")return ct;if(Kt.tag==="Just")return Kt._1;g()})())(ft.state.sink)}:ft.state,yt=ot(ct)(at.sink),St=(()=>{if(yt.tag==="Nothing")return ct;if(yt.tag==="Just")return yt._1;g()})(),Rt=ot(S)(at.sink),pt=(()=>{if(Rt.tag==="Nothing")return S;if(Rt.tag==="Just")return Rt._1;g()})();if(pt===St){const Kt=ot(ct)(at.x),Se=(()=>{if(Kt.tag==="Just")return Kt._1;if(Kt.tag==="Nothing")return T;g()})(),sn=(()=>{if(Se.tag==="Nothing")return 0;if(Se.tag==="Just")return Se._1;g()})(),Me=ot(S)(at.x),Et=(()=>{if(Me.tag==="Just")return Me._1;if(Me.tag==="Nothing")return T;g()})(),Qt=(()=>{if(Et.tag==="Nothing")return 0;if(Et.tag==="Just")return Et._1;g()})(),je=y(I,tt._1),qe=ot(tt._1)(s),tn=ot(I)(s),Hn=(()=>{if(qe.tag==="Nothing")return 0;if(qe.tag==="Just")return qe._1;g()})()-(()=>{if(tn.tag==="Nothing")return 0;if(tn.tag==="Just")return tn._1;g()})();if(c==="VDown"){const dn=Nn(sn+Hn+p(tt._1)+je)(ft.thresh);return{st:{...at,x:j(C)(S)(v("Just",D.initial?dn:Nn(Qt)(dn)))(at.x)},initial:!1,thresh:ft.thresh}}if(c==="VUp"){const dn=rn(sn+Hn-je-p(I))(ft.thresh);return{st:{...at,x:j(C)(S)(v("Just",D.initial?dn:rn(Qt)(dn)))(at.x)},initial:!1,thresh:ft.thresh}}g()}const Bt=ot(ct)(at.x),Jt=(()=>{if(Bt.tag==="Just")return Bt._1;if(Bt.tag==="Nothing")return T;g()})(),mt=(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})(),gt=ot(S)(at.x),K=(()=>{if(gt.tag==="Just")return gt._1;if(gt.tag==="Nothing")return T;g()})(),nt=(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})(),ht=rt(t.nodeGap),_t=ot(I)(s),Nt=ot(tt._1)(s),wt=(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;g()})()-(()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1;g()})();return{st:{...at,classEdges:[...at.classEdges,{src:pt,tgt:St,sep:(()=>{if(c==="VDown")return nt+wt-mt-p(tt._1)-ht;if(c==="VUp")return nt+wt+p(I)+ht-mt;g()})()}]},initial:D.initial,thresh:ft.thresh}}g()},et=S=>D=>{const I=ot(S)(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(Y(S))({st:{...D,x:j(C)(S)(v("Just",0))(D.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})()})(Qi(a)(S));return{...H.st,blockFinished:j(C)(S)(!0)(H.st.blockFinished)}}g()},G=J(S=>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})(S)((()=>{if(c==="VDown")return D;if(c==="VUp")return Je(D);g()})()))({x:Jn(W(S=>b(S,T))(w)),sink:Jn(W(S=>b(S,S))(w)),classEdges:[],su:Q,blockFinished:Q,queue:[]})(h),P=U2(G.classEdges)(G.sink)(c),V=(S,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(S,D,I)},U=Jn(W(S=>b(S,!0))(br(C.compare)((()=>{const S=(D,I)=>{if(D.tag==="Leaf")return I;if(D.tag==="Node")return S(D._5,qt("Cons",D._4,S(D._6,I)));g()};return Ct($t.foldr,S(a.root,Ht))})()))),B=S=>D=>I=>{const A=k(I,{su:D.su,blockFinished:U}),H={phase:S,ppFree:I.free,ppIsRoot:I.isRoot,edgeId:T,delta:0,avail:0,shift:0,freeSu:(()=>{const $=ot((()=>{const X=ot(I.free)(a.root);if(X.tag==="Nothing")return I.free;if(X.tag==="Just")return X._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),X=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),z=(()=>{if(q.tag==="Nothing")return $._1;if(q.tag==="Just")return q._1;g()})(),tt={...H,edgeId:v("Just",A.edge._1.id),delta:X};if(X>0&&X<1e300){const Z=J(at=>yt=>{const St=ot(yt)(m),Rt=(()=>{if(St.tag==="Nothing")return-1;if(St.tag==="Just")return St._1;g()})();if(Rt>=0&&Rt<n.length){const Jt=n[Rt],mt=ot(yt)(e.nodeIndex),gt=(()=>{if(mt.tag==="Nothing")return-2;if(mt.tag==="Just")return mt._1-1|0;g()})();return gt>=0&><Jt.length?rn(at)((()=>{const K=ot(yt)(D.x),nt=ot(yt)(s),ht=ot(Jt[gt])(D.x),_t=ot(Jt[gt])(s);return(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;g()})()-((()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;g()})()+p(Jt[gt])+y(yt,Jt[gt]))})()):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?rn(at)((()=>{const Jt=ot(yt)(D.x),mt=ot(yt)(s),gt=ot([][Bt])(D.x),K=ot([][Bt])(s);return(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})()+(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()-((()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()+(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+p([][Bt])+y(yt,[][Bt]))})()):at})(X)(Qi(a)(z)),ct=Z>0?-Z:0,ft={...D,x:Z>0?_(z,ct,D.x):D.x,trace:[...D.trace,{...tt,avail:Z,shift:ct}]};return Z>0?ft:{...ft,stack:[...ft.stack,I]}}if(X<0&&-X<1e300){const Z=J(at=>yt=>{const St=ot(yt)(m),Rt=(()=>{if(St.tag==="Nothing")return-1;if(St.tag==="Just")return St._1;g()})();if(Rt>=0&&Rt<n.length){const Jt=n[Rt],mt=ot(yt)(e.nodeIndex),gt=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1+1|0;g()})();return gt>=0&><Jt.length?rn(at)((()=>{const K=ot(Jt[gt])(D.x),nt=ot(Jt[gt])(s),ht=ot(yt)(D.x),_t=ot(yt)(s);return(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;g()})()-((()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;g()})()+p(yt)+y(yt,Jt[gt]))})()):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?rn(at)((()=>{const Jt=ot([][Bt])(D.x),mt=ot([][Bt])(s),gt=ot(yt)(D.x),K=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(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()+(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+p(yt)+y(yt,[][Bt]))})()):at})(-X)(Qi(a)(z)),ct=Z>0?Z:0,ft={...D,x:Z>0?_(z,ct,D.x):D.x,trace:[...D.trace,{...tt,avail:Z,shift:ct}]};return Z>0?ft:{...ft,stack:[...ft.stack,I]}}return{...D,stack:[...D.stack,I],trace:[...D.trace,tt],x:D.x}}g()},R=J(B(Y2))({x:Jn(W(S=>b(S,(()=>{const D=ot(S)(a.root),I=(()=>{if(D.tag==="Nothing")return S;if(D.tag==="Just")return D._1;g()})(),A=ot(I)(G.x),H=ot((()=>{const X=ot(I)(G.sink);if(X.tag==="Nothing")return I;if(X.tag==="Just")return X._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:G.su,stack:[],trace:[]})(G.queue),M=J(B(V2))({...R,stack:[]})(Je(R.stack));return{x:M.x,queue:G.queue,trace:M.trace}},j2=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>K2(t)(e)(n)(r)(i)(o)(u)(s)(a)(c)(f).x,ty=t=>e=>n=>r=>i=>o=>{const u=(a,c,f)=>{const d=ot(c)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;g()})(),_=a.from.node===c?a.from.port:a.to.node===c?a.to.port: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,L=Mt(k=>T,k=>E=>v("Just",{head:k,tail:E}),p);if(L.tag==="Nothing"){m=!1,y=x;continue}if(L.tag==="Just"){const k=L._1.head,E=Vt(Y=>Y.from.node===w&&Y.to.node===k||Y.from.node===k&&Y.to.node===w)(r),O=(()=>{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,k,E._1.from.node===k?he:le));g()})();l=j(C)(k)(O)(x),_=O,h=k,p=L._1.tail;continue}g()}return y};return J(a=>c=>{const f=Mt(_=>T,_=>h=>v("Just",{head:_,tail:h}),Qi(t)(c)),d=(()=>{if(f.tag==="Nothing")return j(C)(c)(0)(Q);if(f.tag==="Just")return s(j(C)(f._1.head)(0)(Q))(0)(f._1.head)(f._1.tail);g()})(),l=J(_=>h=>Nn(_)(-h._2))(0)(zs(d));return J(_=>h=>j(C)(h._1)(h._2+l)(_))(a)(zs(d))})(Q)(br(C.compare)((()=>{const a=(c,f)=>{if(c.tag==="Leaf")return f;if(c.tag==="Node")return a(c._5,qt("Cons",c._4,a(c._6,f)));g()};return Ct($t.foldr,a(t.root,Ht))})()))},ey=t=>e=>{const n=(i,o,u)=>me(3)(o)==="$d:"&&Ka(rf,(()=>{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=_,L=h,k=p,E=N.length;if(k>=E){m=!1,y=x;continue}const O=k>=0&&k<N.length?v("Just",N[k]):T,Y=(()=>{if(O.tag==="Nothing")return"";if(O.tag==="Just")return O._1;g()})(),et=n(t,Y);if(k===(E-1|0)||et){const G=(()=>{if(et){const P=ot(Y)(t.preds),V=(()=>{if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})();if(0<V.length){const U=w-1|0,B=ot(V[0])(t.nodeIndex);if(B.tag==="Nothing")return U;if(B.tag==="Just")return B._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(B=>R=>{const M=ot(R)(t.nodeIndex),S=(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})();return S<L||S>G?j(C)(R+"\u2192"+U)()(B):B})(P)((()=>{const B=ot(U)(t.preds);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;g()})())}return n(t,"")?P:J(U=>B=>{const R=ot(B)(t.nodeIndex),M=(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})();return M<L||M>G?j(C)(B+"\u2192")()(U):U})(P)((()=>{const U=ot("")(t.preds);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;g()})())})(x)(It(0,k)),l=N,_=w,h=G,p=k+1|0;continue}d=x,l=N,_=w,h=L,p=k+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))},ny=t=>e=>n=>r=>i=>{const o=Oe(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=En(_-1|0,2),p=En(_,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(!(lf(l[y]+"\u2192"+d)(n)||lf(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),L=(()=>{if(w.tag==="Nothing")return l[y];if(w.tag==="Just")return w._1;g()})();return{root:j(C)(d)(L)(m.root),align:j(C)(l[y])(d)(j(C)(d)(L)(m.align)),r:N}}}return m})(f)((()=>{if(r==="VDown")return It(h,p);if(r==="VUp")return Je(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 Je(a);g()})());return{root:c.root,align:c.align}})({root:Jn(W(s=>b(s,s))(o)),align:Jn(W(s=>b(s,s))(o))})((()=>{if(i==="HRight")return e;if(i==="HLeft")return Je(e);g()})());return{root:u.root,align:u.align}},qo=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>{const f=ny(e)(n)(s)(a)(c),d=ty(f)(i)(r)(o)(u)(c);return Ed()(l=>_=>v("Just",(()=>{const h=ot(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;g()})()))(j2(t)(e)(n)(r)(i)(o)(u)(d)(f)(a)(c))},pf=t=>e=>Ft(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),ry=t=>e=>n=>r=>i=>o=>u=>{const s=$2(0)(e.length-1|0),a=rt(t.layerGap),c=u(fd(s,a)),f=o2(tf(i)(c)(r)(o)(Q))(c);return W(d=>{const l=X2(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))},mf=t=>e=>n=>r=>Ka(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),iy=t=>e=>n=>r=>{const i=Lt(o=>u=>ut.compare(o.w)(u.w))(W(o=>({l:o,w:hf(o)}))(st(mf()(e)(n),r)));return 0<i.length?v("Just",i[0].l):T},oy=t=>e=>{const n=Jn(Oe(W(Ft(i=>o=>b(o,i)))(t))),r=i=>Lt(o=>u=>it.compare((()=>{const s=ot(o)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})())((()=>{const s=ot(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(i);return{preds:(()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Wt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(J(o=>u=>vt(C)(ee)(u.to.node)([u.from.node])(o))(Q)(e))})(),succs:(()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Wt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(J(o=>u=>vt(C)(ee)(u.from.node)([u.to.node])(o))(Q)(e))})(),nodeIndex:n}},uy=t=>e=>{const n=Lt(d=>l=>ut.compare(d.w)(l.w))(Ft(d=>l=>({i:d,l,w:hf(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"){_=rn(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)(zs(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=Te(d=>l=>{const _=h=>{if(h.tag==="Leaf")return Q;if(h.tag==="Node")return Wt("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));g()};return _(d)},e,Ft(d=>l=>Un(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=rn(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 Z2(J(d=>l=>{const _=Lt(ut.compare)(xt(ot(l))(f));return j(C)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(Q)(br(C.compare)(Oe(W(d=>{const l=_=>{if(_.tag==="Leaf")return Q;if(_.tag==="Node")return Wt("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));g()};return Ct(We.foldr,l(d))})(f)))))},sy=t=>e=>n=>r=>i=>o=>{const u=oy(e)(i),s=ey(u)(e),a={nodeGap:t.nodeGap*4|0},c=Ee(C.compare,ke,Jn(W(_=>b(_,b(1,1)))(st(rf,Oe(e)))),(()=>{const _=h=>{if(h.tag==="Leaf")return Q;if(h.tag==="Node")return Wt("Node",h._1,h._2,h._3,b(h._4._1*rt(4),h._4._2),_(h._5),_(h._6));g()};return _(n)})()),f=[qo(a)(u)(e)(c)(r)(i)(o)(s)(gf)(_f),qo(a)(u)(e)(c)(r)(i)(o)(s)(ff)(_f),qo(a)(u)(e)(c)(r)(i)(o)(s)(gf)(df),qo(a)(u)(e)(c)(r)(i)(o)(s)(ff)(df)],d=uy(c)(f);if(mf()(e)(c)(d))return d;const l=iy()(e)(c)(f);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return f[0];g()},ay=t=>e=>n=>r=>{const i=Ya(T,za,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 W(u=>u.node===n?{...u,position:b(o._1+r._1,o._2+r._2)}:u)(t)}g()},cy=t=>e=>n=>r=>{const i=st(u=>Be(fn)(u.node)(e),t),o=(()=>{if(n==="Vertical"){if(r==="Start")return J(u=>s=>rn(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=>rn(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 W(u=>{if(Be(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)},gy=t=>e=>J(n=>r=>r.tag==="AlignGroup"?cy(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?ay(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),fy=t=>e=>n=>r=>i=>o=>u=>s=>{const a=W(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=sy(t)(n)(r)(i)(o)(s),f=pf(ry(t)(n)(r)(i)(o)(u)(d=>{const l=pf(d)(a);return Oe(Ft(_=>h=>Ft(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 gy(e)(Oe(Ft(d=>l=>Ft(_=>h=>({node:h,position:b((()=>{const p=ot(h)(c);return(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})()/rt(4)})(),d>=0&&d<f.length?f[d]:0),size:(()=>{const p=me(3)(h)==="$d:"?b(0,1):b(1,1),m=ot(h)(r);if(m.tag==="Nothing")return p;if(m.tag==="Just")return m._1;g()})(),layer:d,order:_}))(l))(n)))},Ws=Xu(_o)(hr(32)),yf=Xu(_o)(hr(31)),Fi=(()=>{const t=bl("25214903917");if(t.tag==="Nothing")return hc;if(t.tag==="Just")return t._1;g()})(),Ai=$u(Xu(_o)(hr(48)))(_o),_y=t=>{const e=kl(t);return li(pc((()=>{if(e.tag==="Nothing")return hc;if(e.tag==="Just")return e._1;g()})())(Fi))(Ai)},qs=hr(11),Ho=t=>e=>{const n=li(go(fo(e)(Fi))(qs))(Ai);return b((()=>{const r=rc(Jl(Yu(n)(hr(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},dy=t=>{const e=Ho(26)(t),n=Ho(27)(e._2);return b((rt(e._1)*Cu(2)(27)+rt(n._1))/Cu(2)(53),n._2)},ly=t=>e=>{const n=J(r=>i=>{const o=dy(r.finalR);return{rs:[...r.rs,o._1],finalR:o._2}})({rs:[],finalR:t})(e);return b(W(r=>r.x)(Lt(r=>i=>ut.compare(r.k)(i.k))(Te(r=>i=>({x:r,k:i}),e,n.rs))),n.finalR)},hy=t=>{const e=li(go(fo(t)(Fi))(qs))(Ai),n=li(go(fo(e)(Fi))(qs))(Ai);return b(go(fo((()=>{const r=Yu(e)(hr(16));return mc.compare(r)(yf)!=="LT"?$u(r)(Ws):r})())(Ws))((()=>{const r=Yu(n)(hr(16));return mc.compare(r)(yf)!=="LT"?$u(r)(Ws):r})()),n)},Mi=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},$o=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},Hs=jt(C)(zt),qr=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},Xo=jt(C)(zt),py=Lu(ri),my=J(Lr)(0),yy=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},xf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},xy=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const i=Xn(Xt,T,t,n[e],n);if(i.tag==="Just")return Xn(Xt,T,e,r,i._1);if(i.tag==="Nothing")return T;g()}}return T},Ny=t=>e=>n=>r=>i=>Hs(J(o=>u=>{const s=Lt(a=>c=>it.compare((()=>{const f=Mi(a.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})())((()=>{const f=Mi(c.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})()))(st(a=>$o(a.to.node)(n),st(a=>a.from.node===u,r)));return{ranks:[...o.ranks,...Ft(a=>c=>b(c.id,rt((o.rankSum+a|0)+1|0)))(s)],rankSum:o.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),Jy=t=>e=>n=>r=>i=>Hs(J(o=>u=>{const s=Lt(c=>f=>{const d=it.compare((()=>{const l=qr(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=qr(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=Mi(c.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})())((()=>{const l=Mi(f.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})()):d})(st(c=>$o(c.from.node)(n),st(c=>c.to.node===u,r))),a=s.length;return{ranks:[...o.ranks,...Ft(c=>f=>b(f.id,rt((o.rankSum+a|0)-c|0)))(s)],rankSum:o.rankSum+a|0}})({ranks:[],rankSum:0})(t).ranks),$s=t=>e=>n=>{const r=Xo(Ft(s=>a=>b(a,s))(t)),i=Xo(Ft(s=>a=>b(a,s))(e)),o=xt(s=>{const a=qr(s.from.node)(r),c=qr(s.to.node)(i);if(a.tag==="Just"&&c.tag==="Just")return v("Just",b(a._1,c._1));const f=qr(s.from.node)(i),d=qr(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))},Ty=t=>e=>n=>r=>{const i=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l>=(d.length-1|0)){c=!1,f=d;continue}if(l>=0&&l<d.length){const _=l+1|0;if(_>=0&&_<d.length){const h=d[l],p=d[_];if(Re(N=>N.before===h&&N.after===p,r)){s=d,a=l+1|0;continue}const m=Xn(Xt,T,l,p,d),y=(()=>{if(m.tag==="Just")return Xn(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($s(e)(x)(n)<$s(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(py(f)(c)){s=!1,a=c;continue}u=f}return a})(t)},Yo=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+$s(i)(t[o])(e)|0}return n})(0)(It(0,t.length-2|0)),wy=(()=>{const t=e=>{if(e.length<7){const o=u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=_-1|0;if(h>=0&&h<l.length){if(_>=0&&_<l.length&&_>0&&l[h].key>l[_].key){const p=xy(_-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=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,p=f;if(h>=0&&h<r.length){if(p>=0&&p<i.length){if(r[h].key>i[p].key){a=Ot(_)(i[p]),c=h,f=p+1|0;continue}a=Ot(_)(r[h]),c=h+1|0,f=p;continue}d=!1,l=[..._,...h<1?r:bt(h,r.length,r)];continue}d=!1,l=[..._,...p<1?i:bt(p,i.length,i)]}return l})([])(0)(0)};return t})(),vy=t=>e=>n=>{const r=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=cr(Xt,T,m=>m===_,f),p=cr(Xt,T,m=>m===l,f);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=Za(Xt,T,h._1,f),y=(()=>{if(m.tag==="Nothing")return f;if(m.tag==="Just")return m._1;g()})(),x=Ua(Xt,T,p._1,_,y);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;g()}return f})(c)(r),o=Hs(Ft(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=Xo(Ft(E=>O=>b(O,E))(m._1)),N=Xo(Ft(E=>O=>b(O,E))(y._1)),w=f?Ny(m._1)(x)(N)(n)(o):Jy(m._1)(x)(N)(n)(o),L=J(E=>O=>{const Y=xt(G=>Mi(G.id)(w))(st(f?G=>G.to.node===O._2&&$o(G.from.node)(x):G=>G.from.node===O._2&&$o(G.to.node)(x),n));if(Y.length===0)return{...E,items:[...E.items,{n:O._2,key:T,origIdx:O._1}]};const et=Ho(24)(E.r);return{items:[...E.items,{n:O._2,key:v("Just",(my(Y)+(rt(et._1)*4172325152040912e-24-.03500000014901161))/rt(Y.length)),origIdx:O._1}],r:et._2}})({items:[],r:_._2})(Ft(Cn)(y._1)),k=Xn(Xt,T,h,Ty(i(W(E=>E.n)(wy((()=>{const E=L.items,O=Y=>et=>{let G=Y,P=et,V=!0,U;for(;V;){const B=G,R=P;if(B>=0&&B<E.length){if(E[B].key.tag==="Just"){V=!1,U=E[B].key._1;continue}if(E[B].key.tag==="Nothing"){G=B+1|0,P=R;continue}g()}V=!1,U=R}return U};return(Y=>et=>G=>{let P=Y,V=et,U=G,B=!0,R;for(;B;){const M=P,S=V,D=U;if(M>=0&&M<E.length){if(E[M].key.tag==="Just"){P=M+1|0,V=E[M].key._1,U=[...D,{n:E[M].n,key:E[M].key._1,origIdx:E[M].origIdx}];continue}if(E[M].key.tag==="Nothing"){const I=(S+O(M+1|0)(S+1))/2;P=M+1|0,V=I,U=[...D,{n:E[M].n,key:I,origIdx:E[M].origIdx}];continue}g()}B=!1,R=D}return R})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(k.tag==="Just")return b(k._1,L.r);if(k.tag==="Nothing")return b(_._1,_._2);g()}if(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):Je(It(0,l-2|0)))},s=J(c=>f=>j(C)(f.from.node)()(j(C)(f.to.node)()(c)))(Q)(n),a=J(c=>f=>{if(c.result.crossings===0)return c;const d=x=>N=>w=>L=>{let k=x,E=N,O=w,Y=L,et=!0,G;for(;et;){const P=k,V=E,U=O,B=Y;if(U===0){et=!1,G={layout:P,crossings:0,random:B};continue}const R=u(P,V,B),M=Yo(R._1)(n);if(M<U){k=R._1,E=!V,O=M,Y=R._2;continue}et=!1,G={layout:P,crossings:U,random:R._2}}return G},l=Ho(1)(c.result.random),_=l._1!==0,h=t.modelOrder.tag==="Leaf",p=(c.firstTry||c.secondTry)&&!h?c.firstTry:_,m=(()=>{if(!h){const L=u(e,p,l._2);return d(L._1)(!p)(Yo(L._1)(n))(L._2)}const x=p?0:yy(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 L=st(k=>xf(k)(s),N._1);if(L.length>1){const k=ly(l._2)(L),E=k._1,O=Xn(Xt,T,x,i(J(Y=>et=>xf(et)(s)?Y.idx>=0&&Y.idx<E.length?{idx:Y.idx+1|0,result:[...Y.result,E[Y.idx]]}:{idx:Y.idx,result:[...Y.result,et]}:{idx:Y.idx,result:[...Y.result,et]})({idx:0,result:[]})(N._1).result),e);if(O.tag==="Just"){const Y=u(O._1,p,k._2);return d(Y._1)(!p)(Yo(Y._1)(n))(Y._2)}}}const w=u(e,p,l._2);return d(w._1)(!p)(Yo(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:li(pc(hy(_y(1))._1)(Fi))(Ai)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(It(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:a.layout},by=t=>t,Nf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Qe=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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},Hr=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},Oi=(()=>{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"?xe:r==="GT"?Ne:C.compare(e._2)(n._2)},Eq0:()=>t}})(),ky=jt(C)(zt),Ly=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=Oi.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Ey=by("Greedy"),Xs=t=>e=>n=>J(r=>i=>{if(i.from.node===i.to.node)return r;if(i.from.node===e&&!Nf(i.to.node)(r.marks)){const o=Qe(i.to.node)(r.inDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;g()})(),s=j(C)(i.to.node)(u)(r.inDeg);return(()=>{const a=Qe(i.to.node)(r.outDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!Be(fn)(i.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,i.to.node]}:{...r,inDeg:s}}if(i.to.node===e&&!Nf(i.from.node)(r.marks)){const o=Qe(i.from.node)(r.outDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;g()})(),s=j(C)(i.from.node)(u)(r.outDeg);return(()=>{const a=Qe(i.from.node)(r.inDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!Be(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),Cy=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return j(C)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return j(C)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return j(C)(e._1.node)(99999)(t)}return t})(Q),Jf=t=>e=>n=>{const r=Qe(e)(t),i=Qe(n)(t);return r.tag==="Just"&&i.tag==="Just"&&r._1>i._1},Tf=t=>e=>n=>r=>{if(Hr(n)(r.visited)||Hr(n)(r.visiting))return r;const i=J(Sy(t)(e)(n))({...r,visiting:j(C)(n)()(r.visiting)})((()=>{const o=Qe(n)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})());return{...i,visiting:ui(C)(n)(i.visiting),visited:j(C)(n)()(i.visited)}},Sy=t=>e=>n=>r=>i=>Jf(t)(n)(i)?{...r,backEdges:j(Oi)(b(n,i))()(r.backEdges)}:Hr(i)(r.visiting)?{...r,backEdges:j(Oi)(b(n,i))()(r.backEdges)}:Hr(i)(r.visited)?r:Tf(t)(e)(i)(r),Gy=t=>e=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,y=Mt(x=>T,x=>N=>v("Just",{head:x,tail:N}),m.sinks);if(y.tag==="Just"){_=Xs(n)(y._1.head)({...m,sinks:y._1.tail,marks:j(C)(y._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(y.tag==="Nothing"){const x=Mt(N=>T,N=>w=>v("Just",{head:N,tail:w}),m.sources);if(x.tag==="Just"){_=Xs(n)(x._1.head)({...m,sources:x._1.tail,marks:j(C)(x._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(x.tag==="Nothing"){const N=L=>{const k=Qe(L)(m.outDeg),E=Qe(L)(m.inDeg);return(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;g()})()-(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;g()})()|0},w=Lt(L=>k=>{const E=it.compare(N(k))(N(L));return E==="EQ"?it.compare((()=>{const O=Qe(L)(e);if(O.tag==="Nothing")return 1e6;if(O.tag==="Just")return O._1;g()})())((()=>{const O=Qe(k)(e);if(O.tag==="Nothing")return 1e6;if(O.tag==="Just")return O._1;g()})()):E})(m.remaining);if(0<w.length){const L=w[0];_=Xs(n)(L)({...m,remaining:st(k=>k!==L,m.remaining),marks:j(C)(L)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}g()}return p},i=br(C.compare)([...W(l=>l.from.node)(n),...W(l=>l.to.node)(n)]),o=st(l=>l.from.node!==l.to.node,n),u=J(l=>_=>vt(C)(ue)(_.to.node)(1)(l))(Q)(o),s=J(l=>_=>vt(C)(ue)(_.from.node)(1)(l))(Q)(o),a=st(l=>{const _=Qe(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),c=st(l=>{const _=Qe(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),f=i.length+1|0,d=J(l=>_=>{const h=Qe(_)(l);return h.tag==="Just"&&h._1<0?j(C)(_)(h._1+f|0)(l):l})(r({remaining:st(l=>!Be(fn)(l)(a)&&!Be(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(Jf(t)(_.from.node)(_.to.node))return j(Oi)(b(_.from.node,_.to.node))()(l);const h=Qe(_.from.node)(d),p=Qe(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?j(Oi)(b(_.from.node,_.to.node))()(l):l})(Q)(n)},Py=J(t=>e=>vt(C)(ee)(e.from.node)([e.to.node])(t))(Q),Dy=t=>e=>{const n=Py(e),r=br(C.compare)([...W(o=>o.from.node)(e),...W(o=>o.to.node)(e)]),i=J(o=>u=>j(C)(u.to.node)()(o))(Q)(e);return J(o=>u=>Tf(t)(n)(u)(o))({visiting:Q,visited:Q,backEdges:Q})([...st(o=>!Hr(o)(i),r),...st(o=>Hr(o)(i),r)]).backEdges},Iy=t=>e=>n=>r=>{const i=ky(Ft(s=>a=>b(a,s))(e)),o=Cy(n),u=(()=>{if(t==="DepthFirst")return Dy(o)(r);if(t==="Greedy")return Gy(o)(i)(r);g()})();return{edges:W(s=>Ly(b(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},wf=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Qy=J(t=>e=>j(C)(e)()(t))(Q),Vo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Fy=Mg(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},vf=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ys=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},Ay=jt(it)(zt),My=t=>e=>Ee(C.compare,ke,t,e),bf=Ft(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),Oy=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=wf(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 Wt("Node",i._1,i._2,i._3,i._4+e.base|0,r(i._5),r(i._6));g()};return r(n)})()]}))({base:0,result:[]})(t).result,Ry=t=>e=>{const n=Qy(t);return Fy(t)(bf(st(r=>Vo(r.src)(n)&&Vo(r.tgt)(n),e)))},By=t=>e=>{const n=J(i=>o=>vt(C)(ee)(o.tgt)([o.src])(vt(C)(ee)(o.src)([o.tgt])(i)))(Q)(e),r=i=>o=>u=>{let s=i,a=o,c=u,f=!0,d;for(;f;){const l=s,_=a,h=c,p=Mt(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(Vo(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=j(C)(p._1.head)()(_),c=[...h,p._1.head];continue}g()}return d};return J(i=>o=>{if(Vo(o)(i.visited))return i;const u=r([o])(i.visited)([]);return{...i,visited:J(s=>a=>j(C)(a)()(s))(i.visited)(u.nodes),components:[...i.components,u.nodes]}})({visited:Q,components:[]})(t).components},zy=t=>e=>n=>{const r=J(o=>u=>vt(C)(ue)(u.tgt)(1)(o))(Q)(e),i=J(o=>u=>vt(C)(ue)(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:vf(x.mIn)((()=>{const w=Tn(u)(d),L=Tn(N.src)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;g()})()-(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;g()})()|0})())}:N.src===u?{...x,mOut:vf(x.mOut)((()=>{const w=Tn(N.tgt)(d),L=Tn(u)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._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 p=(f-_|0)+1|0,m=(f+h|0)-1|0;if(m<p)return o;const y=J(x=>N=>{const w=Ys(N)(o.filling),L=(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;g()})();return L<x.bestFill?{best:N,bestFill:L}:x})({best:f,bestFill:(()=>{const x=Ys(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:j(C)(u)(y.best)(o.layers),filling:j(it)(f)((()=>{const x=Ys(f)(o.filling);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;g()})())(j(it)(y.best)(y.bestFill+1|0)(o.filling))}})({layers:n,filling:Ay(W(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=>wf(o)((()=>{const s=Tn(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(0)(t))))})(t).layers},Wy=t=>e=>zy(t)(bf(e))(J(My)(Q)(Oy(W(n=>Ry(n)(e))(By(t)(e))))),qy=t=>t,Nr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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},Uo=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},kf=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Hy=qy("NetworkSimplex"),$y=t=>e=>J(n=>r=>{const i=J(Uo)(0)(xt(o=>Nr(o)(n))(r));return J(o=>u=>j(C)(u)(i)(o))(n)(r)})(e)(t),Xy=t=>e=>({layers:W(n=>st(r=>{const i=Nr(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=Uo(a)(c._1),o=c._2;continue}g()}return s})(0)((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return n(e,Ht)})()))),nodeLayer:e}),Yy=t=>e=>n=>{const r=J(i=>o=>j(C)(o)(!0)(i))(Q)(e);return J(i=>o=>j(C)(o._1)(o._2)(i))(Wy(e)(xt(i=>i.from.node===i.to.node||(()=>{const o=Nr(i.from.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()||(()=>{const o=Nr(i.to.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()?T:v("Just",{src:i.from.node,tgt:i.to.node}))(t)))(kf(n))},Vy=t=>e=>n=>r=>{const i=s=>a=>{const c=Nr(a)(s);if(c.tag==="Just")return s;if(c.tag==="Nothing"){const f=st(l=>l!==a,(()=>{const l=Nr(a)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;g()})()),d=J(i)(s)(f);return j(C)(a)(1+J(Uo)(0)(xt(l=>Nr(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=Uo(_)(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=>j(C)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return Q;if(a.tag==="Node")return Wt("Node",a._1,a._2,a._3,u-a._4|0,s(a._5),s(a._6));g()};return s(o)})())(kf(r))},Uy=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return j(C)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return j(C)(e._1.node)(0)(t)}return t})(Q),Zy=J(t=>e=>vt(C)(ee)(e.to.node)([e.from.node])(t))(Q),Ky=J(t=>e=>vt(C)(ee)(e.from.node)([e.to.node])(t))(Q),jy=t=>e=>n=>r=>{const i=Ky(n),o=Zy(n),u=Uy(e);return Xy(r)($y(xt(s=>s.tag==="SameLayer"?v("Just",s._1.nodes):T)(e))((()=>{if(t==="LongestPath")return Vy(i)(o)(r)(u);if(t==="NetworkSimplex")return Yy(n)(r)(u);g()})()))},tx=jt(C)(zt),ex=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=>{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},Ef=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ri=jt(C)(zt),nx=jt(C)(zt),Cf=(()=>{const t=W(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>Je(t(e))})(),rx=t=>e=>n=>r=>{const i=tx(W(u=>b(u.edge,u))(r)),o=u=>0<u.nodes.length&&(()=>{const s=ex(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return W(u=>{if(u.nodes.length<=2){const f=Lf(u.edgeId)(i);if(f.tag==="Just"){const d=o(u),l=Pi(Gi(d?Cf(f._1.segments):f._1.segments));return{...f._1,edge:u.edgeId,segments:l,bends:Te(_=>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=>Lf(f)(i))(Te(f=>d=>u.edgeId+":"+f+"->"+d,u.nodes,bt(1,u.nodes.length,u.nodes))))(f=>f.segments),a=o(u),c=Pi(Gi(a?Cf(s):s));return{edge:u.edgeId,segments:c,bends:Te(f=>d=>f.end,c,bt(1,c.length,c)),bendType:[],jumps:[],reversed:a}})(t)},ix={layers:[],edges:[],chains:[]},ox={nodeGap:3,layerGap:2,iterations:8,layerer:Hy,cycleBreaker:Ey,compactPostRouting:!0,compactionSpacings:Zm},ux=t=>({pos:b(0,0),size:b(J(e=>n=>Ef(e)(n.position._1+n.size._1))(0)(t),J(e=>n=>Ef(e)(n.position._2+n.size._2))(0)(t))}),sx=t=>e=>n=>{const r=Ri(W(c=>b(c.id,c.ports))(e.nodes)),i=st(c=>me(3)(c.node)!=="$d:",n.placements),o=rx(n.withDummies.chains)(n.acyclic.reversedEdges)(nx(W(c=>b(c.id,b(c.from.node,c.to.node)))(e.edges)))(P2(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(uf(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 Wt("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(W(f=>b(f.id,f.size))(e.nodes)))})()))),u=t.compactPostRouting?t2()(t.compactionSpacings)({nodes:i,edges:e.edges,paths:o,ports:r}):{nodes:i,edges:o},s=W(c=>{const f=Pi(Gi(c.segments));return{...c,segments:f,bends:Te(d=>l=>d.end,f,bt(1,f.length,f))}})(u.edges),a=Ft(c=>f=>({...f,jumps:O2(c)(f)(s)}))(s);return{nodes:u.nodes,edges:a,boundingBox:ux(u.nodes),metrics:kp(u.nodes)(a)(0)}},ax=t=>e=>n=>{const r=Ri(W(o=>b(o.id,o.size))(e.nodes)),i={...n,placements:fy({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(Ri(W(o=>b(o.id,o.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(uf(n.ordered)(n.withDummies.edges)((()=>{const o=u=>{if(u.tag==="Leaf")return Q;if(u.tag==="Node")return Wt("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:sx(t)(e)(i)}},cx=t=>e=>n=>ax(t)(e)({...n,ordered:vy({iterations:t.iterations,constraints:e.constraints,modelOrder:Ri(Ft(r=>i=>b(i.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),gx=t=>e=>n=>cx(t)(e)({...n,withDummies:R2(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),fx=t=>e=>{const n=W(i=>i.id)(e.nodes),r=Iy(t.cycleBreaker)(n)(e.constraints)(e.edges);return gx(t)(e)({acyclic:r,layered:jy(t.layerer)(e.constraints)(r.edges)(n),withDummies:ix,ordered:[],placements:[]})},Zo=t=>t,_x=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Vs=Zo("TopSide"),Us=Zo("BottomSide"),Zs=Zo("LeftSide"),Ks=Zo("RightSide"),dx=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()},Sf=t=>e=>n=>{const r=_x(t.h*.12)(t.w*.2),i=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*Le(dx((()=>{const o=(n-(t.x+i))/i;return 1-o*o})()))},ir=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=Sf(d)(-1)(_);continue}if(l==="BottomSide"){a=!1,c=Sf(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},Gf=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?Vs:c<=s&&c<=o?Us:s<=o?Zs:Ks},js=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},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=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},lx=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),zi=jt(C)(zt),hx=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},px=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=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},mx=J(t=>e=>j(C)(e)()(t))(Q),yx=J(t=>e=>j(C)(e)()(t))(Q),Ko=ar.traverse(vu),jo=jt(C)(zt),xx=t=>e=>Ee(C.compare,ke,t,e),Nx=J(t=>e=>j(C)(e)()(t))(Q),Jx=jt(C)(zt),Tx=t=>e=>Ee(C.compare,ke,t,e),wx=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},Pf=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},vx=t=>e=>({...e,edges:zi(W(n=>b(n._1,(()=>{const r=js(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=Mt(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=Gf(a)(s._1.head);return[(()=>{if(c==="TopSide")return{...s._1.head,y:ir(o._1.shape)(a)(Vs)(s._1.head.x)};if(c==="BottomSide")return{...s._1.head,y:ir(o._1.shape)(a)(Us)(s._1.head.x)};if(c==="LeftSide")return{...s._1.head,x:ir(o._1.shape)(a)(Zs)(s._1.head.y)};if(c==="RightSide")return{...s._1.head,x:ir(o._1.shape)(a)(Ks)(s._1.head.y)};g()})(),...s._1.tail]}}g()})();if(i.tag==="Nothing")return u;if(i.tag==="Just"){const s=ii(u);if(s.tag==="Nothing")return u;if(s.tag==="Just")return Ot(s._1.init)((()=>{const a={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},c=Gf(a)(s._1.last);if(c==="TopSide")return{...s._1.last,y:ir(i._1.shape)(a)(Vs)(s._1.last.x)};if(c==="BottomSide")return{...s._1.last,y:ir(i._1.shape)(a)(Us)(s._1.last.x)};if(c==="LeftSide")return{...s._1.last,x:ir(i._1.shape)(a)(Zs)(s._1.last.y)};if(c==="RightSide")return{...s._1.last,x:ir(i._1.shape)(a)(Ks)(s._1.last.y)};g()})())}}g()})()))(lx(e.edges)))}),bx=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 js(n)(e);g()},kx=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()})()}),Lx=t=>({id:t,size:b(1,1),ports:[],label:v("Just",t),shape:jn}),Ex=t=>e=>n=>r=>b(r.node,kx(t)(e)(n)(r)),Df=t=>{const e=yo(`
|
|
6
|
+
`)(t);return e.length===0?[""]:e},If=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,qt("Cons",n._4,e(n._6,r)));g()};return Ct($t.foldr,e(t.interiors,Ht))},Cx=t=>zi(xt(e=>v("Just",b(e.edge,{id:e.edge,from:{node:e.from,port:T},to:{node:e.to,port:T},label:T})))(Tt(t.scenes)(e=>e.tag==="DataFlow"?xt(n=>n.kind.tag==="SendToken"?v("Just",n.kind._1):T)(e._1.events):[]))),Qf=t=>{const e=Hl(t),n=st(i=>hx(i.id)(e.nodes),t.graph.nodes),r=st(i=>px(i.id)(e.edges),t.graph.edges);return{nodes:[...n,...W(Lx)(Ct(We.foldr,Sn(C.compare,e.nodes,mx(W(i=>i.id)(n)))))],edges:[...r,...xt(bx(t)(Cx(t)))(Ct(We.foldr,Sn(C.compare,e.edges,yx(W(i=>i.id)(r)))))],constraints:t.graph.constraints}},Sx=t=>{const e=Ko(n=>{const r=dg(lg)((()=>{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)}})(Qf(t).nodes);return()=>{const n=e();return jo(n)}},Ff=t=>{const e=Sx(t);return()=>{const n=e(),r=Ko(Ff)(If(t))();return J(xx)(n)(r)}},Gx=t=>e=>{const n=Mt(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},...W(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];g()},Px=t=>e=>b(e.edge,Gx(t)(e)),Dx=t=>e=>n=>r=>({nodes:jo(W(Ex(rt(4)*t)(e)(n))(r.nodes)),edges:zi(W(Px(t))(r.edges)),chipExtras:Q,edgeLabels:Q}),Ix=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=>j(C)(u)()(o))(r)(i.kind._1.labels);if(i.kind.tag==="FillNodeWithoutTransition")return J(o=>u=>j(C)(u)()(o))(r)(i.kind._1.labels);g()})(e)(n._1.events);if(n.tag==="Hold"||n.tag==="EnterNode"||n.tag==="ExitNode")return e;g()})(Q)(t.scenes),Qx=t=>{const e=Ko(n=>{const r=dg(lg)(n);return()=>{const i=r();return b(n,{labelW:i,charCount:Kn(Ar(n)),lineCount:1})}})(Ct(We.foldr,Nx(Tt(Ct(We.foldr,Ix(t)))(Df))));return()=>{const n=e();return Jx(n)}},Af=t=>{const e=Qx(t);return()=>{const n=e(),r=Ko(Af)(If(t))();return J(Tx)(n)(r)}},Fx=rt(4)*8,Ax=t=>e=>{const n=wp(Fx)(t)(Tp(Jp)(Qf(e)));return{...vx(zi(W(r=>b(r.id,b(r.from.node,r.to.node)))(n.edges)))(Dx(8)(jo(W(r=>b(r.id,(()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;g()})()))(n.nodes)))(jo(W(r=>b(r.id,r.shape))(n.nodes)))(fx(ox)(n).result)),edgeLabels:zi(xt(r=>r.label.tag==="Just"?v("Just",b(r.id,r.label._1)):T)(n.edges))}},Mx=t=>Tt(t.scenes)(e=>{if(e.tag==="Structural")return[];if(e.tag==="DataFlow")return e._1.events;if(e.tag==="Hold")return[];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()}),Ox=t=>e=>n=>{const r=i=>{const o=xt(u=>{const s=wx(u)(t);return s.tag==="Just"?v("Just",{w:s._1.labelW+28,h:rt(pp(1)(s._1.lineCount))*13.2+12}):T})(Tt(i)(Df));return o.length===0?T:v("Just",{w:J(Pf)(0)(W(u=>u.w)(o)),h:J(Pf)(0)(W(u=>u.h)(o))})};return J(i=>o=>{if(o.kind.tag==="SendToken"){const u=js(o.kind._1.edge)(n.edges),s=r(o.kind._1.labels);if(s.tag==="Just"&&u.tag==="Just"){const a=s._1;return vt(C)(ee)(o.kind._1.edge)(W(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(C)(ee)("__fill__:"+o.kind._1.node)((()=>{const a=u._1.y-s._1.h-14,c=u._1.x+u._1.w/2,f=c-s._1.w/2,d=c+s._1.w/2,l=u._1.y-14;return[{x:f,y:a},{x:d,y:a},{x:f,y:l},{x:d,y:l}]})())(i):i}g()})(Q)(Mx(e))},Mf=t=>e=>n=>({layout:(()=>{const r=Ax(t)(n);return{...r,chipExtras:Ox(e)(n)(r)}})(),interiors:(()=>{const r=Mf(t)(e),i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return Wt("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(n.interiors)})()}),Of=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},ta=t=>e=>n=>{const r=t<.05?t:.05,i=(u,s)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return i((()=>{const a=Of(s._3)(n),c=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return{x:s._4.x,y:s._4.y,vx:0,vy:0};g()})(),f=c.vx+(180*(s._4.x-c.x)-22*c.vx)*r,d=c.vy+(180*(s._4.y-c.y)-22*c.vy)*r;return j(C)(s._3)({x:c.x+f*r,y:c.y+d*r,vx:f,vy:d})(i(u,s._5))})(),s._6);g()},o=i(Q,e);return{springs:o,applied:(()=>{const u=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return u((()=>{const c=u(s,a._5),f=Of(a._3)(o);if(f.tag==="Just")return j(C)(a._3)({...a._4,x:f._1.x,y:f._1.y})(c);if(f.tag==="Nothing")return j(C)(a._3)(a._4)(c);g()})(),a._6);g()};return u(Q,e)})()}};(function(){var t={},e="Pure",n="Throw",r="Catch",i="Sync",o="Async",u="Bind",s="Bracket",a="Fork",c="Sequential",f="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",y="Finalized",x="Forked";function N(A,H,$,X){this.tag=A,this._1=H,this._2=$,this._3=X}function w(A){var H=function($,X,q){return new N(A,$,X,q)};return H.tag=A,H}function L(A){return new N(e,void 0)}function k(A){try{A()}catch(H){setTimeout(function(){throw H},0)}}function E(A,H,$){try{return H($())}catch(X){return A(X)}}function O(A,H,$){try{return H($)()}catch(X){return $(A(X))(),L}}var Y=(function(){var A=1024,H=0,$=0,X=new Array(A),q=!1;function z(){var tt;for(q=!0;H!==0;)H--,tt=X[$],X[$]=void 0,$=($+1)%A,tt();q=!1}return{isDraining:function(){return q},enqueue:function(tt){var Z;H===A&&(Z=q,z(),q=Z),X[($+H)%A]=tt,H++,q||z()}}})();function et(A){var H={},$=0,X=0;return{register:function(q){var z=$++;q.onComplete({rethrow:!0,handler:function(tt){return function(){X--,delete H[z]}}})(),H[z]=q,X++},isEmpty:function(){return X===0},killAll:function(q,z){return function(){if(X===0)return z();var tt=0,Z={};function ct(at){Z[at]=H[at].kill(q,function(yt){return function(){delete Z[at],tt--,A.isLeft(yt)&&A.fromLeft(yt)&&setTimeout(function(){throw A.fromLeft(yt)},0),tt===0&&z()}})()}for(var ft in H)H.hasOwnProperty(ft)&&(tt++,ct(ft));return H={},$=0,X=0,function(at){return new N(i,function(){for(var yt in Z)Z.hasOwnProperty(yt)&&Z[yt]()})}}}}}var G=0,P=1,V=2,U=3,B=4,R=5,M=6;function S(A,H,$){var X=0,q=G,z=$,tt=null,Z=null,ct=null,ft=null,at=null,yt=0,St=0,Rt=null,pt=!0;function Bt(K){for(var nt,ht,_t;;)switch(nt=null,ht=null,_t=null,q){case V:q=P;try{z=ct(z),ft===null?ct=null:(ct=ft._1,ft=ft._2)}catch(wt){q=R,tt=A.left(wt),z=null}break;case U:A.isLeft(z)?(q=R,tt=z,z=null):ct===null?q=R:(q=V,z=A.fromRight(z));break;case P:switch(z.tag){case u:ct&&(ft=new N(_,ct,ft)),ct=z._2,q=P,z=z._1;break;case e:ct===null?(q=R,z=A.right(z._1)):(q=V,z=z._1);break;case i:q=U,z=E(A.left,A.right,z._1);break;case o:q=B,z=O(A.left,z._1,function(wt){return function(){X===K&&(X++,Y.enqueue(function(){X===K+1&&(q=U,z=wt,Bt(X))}))}});return;case n:q=R,tt=A.left(z._1),z=null;break;case r:ct===null?at=new N(_,z,at,Z):at=new N(_,z,new N(_,new N(h,ct,ft),at,Z),Z),ct=null,ft=null,q=P,z=z._1;break;case s:yt++,ct===null?at=new N(_,z,at,Z):at=new N(_,z,new N(_,new N(h,ct,ft),at,Z),Z),ct=null,ft=null,q=P,z=z._1;break;case a:q=U,nt=S(A,H,z._2),H&&H.register(nt),z._1&&nt.run(),z=A.right(nt);break;case c:q=P,z=I(A,H,z._1);break}break;case R:if(ct=null,ft=null,at===null)q=M,z=Z||tt||z;else switch(nt=at._3,_t=at._1,at=at._2,_t.tag){case r:Z&&Z!==nt&&yt===0?q=R:tt&&(q=P,z=_t._2(A.fromLeft(tt)),tt=null);break;case h:Z&&Z!==nt&&yt===0||tt?q=R:(ct=_t._1,ft=_t._2,q=V,z=A.fromRight(z));break;case s:yt--,tt===null&&(ht=A.fromRight(z),at=new N(_,new N(p,_t._2,ht),at,nt),(Z===nt||yt>0)&&(q=P,z=_t._3(ht)));break;case p:at=new N(_,new N(y,z,tt),at,Z),q=P,Z&&Z!==nt&&yt===0?z=_t._1.killed(A.fromLeft(Z))(_t._2):tt?z=_t._1.failed(A.fromLeft(tt))(_t._2):z=_t._1.completed(A.fromRight(z))(_t._2),tt=null,yt++;break;case m:yt++,at=new N(_,new N(y,z,tt),at,Z),q=P,z=_t._1;break;case y:yt--,q=R,z=_t._1,tt=_t._2;break}break;case M:for(var Nt in Rt)Rt.hasOwnProperty(Nt)&&(pt=pt&&Rt[Nt].rethrow,k(Rt[Nt].handler(z)));Rt=null,Z&&tt?setTimeout(function(){throw A.fromLeft(tt)},0):A.isLeft(z)&&pt&&setTimeout(function(){if(pt)throw A.fromLeft(z)},0);return;case G:q=P;break;case B:return}}function Jt(K){return function(){if(q===M)return pt=pt&&K.rethrow,K.handler(z)(),function(){};var nt=St++;return Rt=Rt||{},Rt[nt]=K,function(){Rt!==null&&delete Rt[nt]}}}function mt(K,nt){return function(){if(q===M)return nt(A.right(void 0))(),function(){};var ht=Jt({rethrow:!1,handler:function(){return nt(A.right(void 0))}})();switch(q){case G:Z=A.left(K),q=M,z=Z,Bt(X);break;case B:Z===null&&(Z=A.left(K)),yt===0&&(q===B&&(at=new N(_,new N(m,z(K)),at,Z)),q=R,z=null,tt=null,Bt(++X));break;default:Z===null&&(Z=A.left(K)),yt===0&&(q=R,z=null,tt=null)}return ht}}function gt(K){return function(){var nt=Jt({rethrow:!1,handler:K})();return q===G&&Bt(X),nt}}return{kill:mt,join:gt,onComplete:Jt,isSuspended:function(){return q===G},run:function(){q===G&&(Y.isDraining()?Bt(X):Y.enqueue(function(){Bt(X)}))}}}function D(A,H,$,X){var q=0,z={},tt=0,Z={},ct=new Error("[ParAff] Early exit"),ft=null,at=t;function yt(Jt,mt,gt){var K=mt,nt=null,ht=null,_t=0,Nt={},wt,Kt;t:for(;;)switch(wt=null,K.tag){case x:if(K._3===t&&(wt=z[K._1],Nt[_t++]=wt.kill(Jt,function(Se){return function(){_t--,_t===0&>(Se)()}})),nt===null)break t;K=nt._2,ht===null?nt=null:(nt=ht._1,ht=ht._2);break;case f:K=K._2;break;case d:case l:nt&&(ht=new N(_,nt,ht)),nt=K,K=K._1;break}if(_t===0)gt(A.right(void 0))();else for(Kt=0,wt=_t;Kt<wt;Kt++)Nt[Kt]=Nt[Kt]();return Nt}function St(Jt,mt,gt){var K,nt,ht,_t,Nt,wt;for(A.isLeft(Jt)?(K=Jt,nt=null):(nt=Jt,K=null);;){if(ht=null,_t=null,Nt=null,wt=null,ft!==null)return;if(mt===null){X(K||nt)();return}if(mt._3!==t)return;switch(mt.tag){case f:K===null?(mt._3=A.right(mt._1(A.fromRight(nt))),nt=mt._3):mt._3=K;break;case d:if(ht=mt._1._3,_t=mt._2._3,K){if(mt._3=K,Nt=!0,wt=tt++,Z[wt]=yt(ct,K===ht?mt._2:mt._1,function(){return function(){delete Z[wt],Nt?Nt=!1:gt===null?St(K,null,null):St(K,gt._1,gt._2)}}),Nt){Nt=!1;return}}else{if(ht===t||_t===t)return;nt=A.right(A.fromRight(ht)(A.fromRight(_t))),mt._3=nt}break;case l:if(ht=mt._1._3,_t=mt._2._3,ht===t&&A.isLeft(_t)||_t===t&&A.isLeft(ht))return;if(ht!==t&&A.isLeft(ht)&&_t!==t&&A.isLeft(_t))K=nt===ht?_t:ht,nt=null,mt._3=K;else if(mt._3=nt,Nt=!0,wt=tt++,Z[wt]=yt(ct,nt===ht?mt._2:mt._1,function(){return function(){delete Z[wt],Nt?Nt=!1:gt===null?St(nt,null,null):St(nt,gt._1,gt._2)}}),Nt){Nt=!1;return}break}gt===null?mt=null:(mt=gt._1,gt=gt._2)}}function Rt(Jt){return function(mt){return function(){delete z[Jt._1],Jt._3=mt,St(mt,Jt._2._1,Jt._2._2)}}}function pt(){var Jt=P,mt=$,gt=null,K=null,nt,ht;t:for(;;)switch(nt=null,ht=null,Jt){case P:switch(mt.tag){case f:gt&&(K=new N(_,gt,K)),gt=new N(f,mt._1,t,t),mt=mt._2;break;case d:gt&&(K=new N(_,gt,K)),gt=new N(d,t,mt._2,t),mt=mt._1;break;case l:gt&&(K=new N(_,gt,K)),gt=new N(l,t,mt._2,t),mt=mt._1;break;default:ht=q++,Jt=R,nt=mt,mt=new N(x,ht,new N(_,gt,K),t),nt=S(A,H,nt),nt.onComplete({rethrow:!1,handler:Rt(mt)})(),z[ht]=nt,H&&H.register(nt)}break;case R:if(gt===null)break t;gt._1===t?(gt._1=mt,Jt=P,mt=gt._2,gt._2=t):(gt._2=mt,mt=gt,K===null?gt=null:(gt=K._1,K=K._2))}for(at=mt,ht=0;ht<q;ht++)z[ht].run()}function Bt(Jt,mt){ft=A.left(Jt);var gt;for(var K in Z)if(Z.hasOwnProperty(K)){gt=Z[K];for(K in gt)gt.hasOwnProperty(K)&>[K]()}Z=null;var nt=yt(Jt,at,mt);return function(ht){return new N(o,function(_t){return function(){for(var Nt in nt)nt.hasOwnProperty(Nt)&&nt[Nt]();return L}})}}return pt(),function(Jt){return new N(o,function(mt){return function(){return Bt(Jt,mt)}})}}function I(A,H,$){return new N(o,function(X){return function(){return D(A,H,$,X)}})}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=S,N.Supervisor=et,N.Scheduler=Y,N.nonCanceler=L,N})();let Rf=null;function Rx(){return Rf||(typeof document>"u"?null:Rf=document.createElement("canvas").getContext("2d"))}const ea=new Map;function Bf(t,e,n,r,i,o){const u=`${n} ${e}px ${t}`,s=u+"|"+r;if(ea.has(s))return ea.get(s);const a=Rx();if(!a)return o;a.font=u;const c=i(a.measureText(r)),f=typeof document<"u"?document.fonts:null;if(!f||f.check(u))ea.set(s,c);else if(f&&f.load)try{f.load(u)}catch{}return c}const Bx=(t,e,n,r)=>Bf(t,e,n,r,i=>i.width,-1),zx=(t,e,n,r)=>Bf(t,e,n,r,i=>({ascent:i.actualBoundingBoxAscent,descent:i.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),zf=t=>e=>{const n=Bx(t.family,t.size,t.weight,Ar(e));return n<0?rt(Jo(e).length)*t.size*.62:n},Wf=t=>e=>{const n=zx(t.family,t.size,t.weight,Ar(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},qf=t=>t,Hf=t=>t,tu=t=>t,$f=t=>t,Wx=t=>t,Xf=t=>t,Yf=t=>t,qx=Yf("BaselineTop"),or=Yf("BaselineMiddle"),na=Xf("AlignLeft"),$r=Xf("AlignCenter"),we=Wx("RoundJoin"),_n=$f("ButtCap"),wn=$f("RoundCap"),Hx=tu("LayerPolyOut"),$x=tu("LayerPolyIn"),Xx=tu("LayerNodeMask"),Yx=tu("LayerOverlay"),eu=Hf("NonZero"),Vx=Hf("EvenOdd"),Vf=qf("Normal"),nu=qf("Difference"),ie={r:255,g:255,b:255,a:255},An={r:26,g:26,b:26,a:255},Ux=t=>t,Uf=t=>t,Zx=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},on=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Zf=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},ra=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Kx=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()},jx=Uf("FlatLevel"),tN=Uf("NestedLevel"),Kf=Ux("GenieSilhouette"),eN=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const i=Ir(t);return{prng:i.prng,yLift:i.value*n.yJitter*r}},nN=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const i=Ir(t);return{prng:i.prng,dx:(i.value*2-1)*n.xJitter*r}},jf=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,i=Le(r*r+n*n),o=(t.r*t.r-e.r*e.r+i*i)/(2*i),u=Le(Zx(0)(t.r*t.r-o*o)),s=t.cx+o*r/i,a=t.cy+o*n/i,c={x:s-u*n/i,y:a+u*r/i},f={x:s+u*n/i,y:a-u*r/i};return i===0||i>t.r+e.r?{x:(t.cx+e.cx)/2,y:t.cy}:c.y<f.y?c:f},rN=t=>e=>{const n=on(e)(on(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},iN=t=>e=>n=>r=>i=>o=>{if(e)return{prng:t,r:i};if(n)return{prng:t,r:i*(1+o.rJitter)};if(r)return{prng:t,r:i*o.smallScale};const u=Ir(t);return{prng:u.prng,r:i*(1+u.value*o.rJitter)}},t_=t=>{const e=on(t.w)(t.h)/2;return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,4,t.x+t.w-e+.5522847498307936*e,t.y,t.x+t.w,t.y+e-.5522847498307936*e,t.x+t.w,t.y+e,4,t.x+t.w,t.y+e+.5522847498307936*e,t.x+t.w-e+.5522847498307936*e,t.y+t.h,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,4,t.x+e-.5522847498307936*e,t.y+t.h,t.x,t.y+e+.5522847498307936*e,t.x,t.y+e,4,t.x,t.y+e-.5522847498307936*e,t.x+e-.5522847498307936*e,t.y,t.x+e,t.y,5]},oN=t=>e=>n=>{const r=Ir(t),i=e.length;return i===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const o=Zf(0)(i-1|0)(de(ln(r.value*rt(n))));return o>=0&&o<e.length?e[o]:-1})()}},uN=t=>e=>{const n=Ir(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const i=Zf(0)(r-1|0)(de(ln(n.value*rt(r))));return i>=0&&i<e.length?e[i]:-1})()}},e_=t=>{const e=on(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]},n_=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],r_={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},sN=t=>{const e=on(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]},i_=t=>{const e=on(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]},o_=t=>e=>{const n=e.y+e.h,r=xd(t.rBase*e.h)(e.w/(2*(1+(rt(t.minN)-1)*t.stepRatio))),i=e.w-2*r,o=2*r*t.stepRatio,u=ra(t.minN)(i<=0||o<=0?t.minN:de(Vn(i/o))+1|0),s=u>=3?It(1,u-2|0):[],a=s.length,c=En(a+1|0,2),f=c<1?[]:bt(0,c,s),d=uN(t.seed)((()=>{const m=a-c|0;return m<1?s:bt(m,s.length,s)})()),l=d.idx,_=oN(d.prng)(st(m=>m!==l,f))(ra(1)(f.length-(Be(vr)(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),L=iN(m.prng)(w)(N)(x)(r)(t),k=eN(L.prng)(w)(t)(e.h),E=nN(k.prng)(w)(t)(p);return{prng:E.prng,circles:Ot(m.circles)({cx:e.x+Kx(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*p:x?-1*t.smallShift*p:0)),cy:n-k.yLift,r:L.r})}})({prng:_.prng,circles:[]})(It(0,u-1|0)).circles},u_=t=>e=>{const n=t.length;return Ft(r=>i=>({c:i,p1:(()=>{if(r===0)return{x:i.cx-i.r,y:e};const o=r-1|0;return o>=0&&o<t.length?jf(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?jf(i)(t[o]):{x:i.cx+i.r,y:e}})()}))(t)},s_=t=>{const e=on(t.h*.4)(t.w*.2);return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,2,t.x+t.w,t.y+t.h/2,2,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,2,t.x,t.y+t.h/2,5]},aN=t=>e=>n=>{const r=fr(e.y-t.cy)(e.x-t.cx),i=fr(n.y-t.cy)(n.x-t.cx),o=i>r?i-r:i+6.283185307179586-r,u=ra(1)(de(eo(o/1.5707963267948966))),s=o/rt(u),a=1.3333333333333333*Nd(s/4);return Tt(It(0,u-1|0))(c=>{const f=r+rt(c+1|0)*s,d=t.cx+t.r*en(f),l=t.cy+t.r*He(f),_=r+rt(c)*s;return[4,t.cx+t.r*en(_)-a*t.r*He(_),t.cy+t.r*He(_)+a*t.r*en(_),d+a*t.r*He(f),l-a*t.r*en(f),d,l]})},a_=t=>e=>{const n=t.h*.38,r=u_(o_(r_)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),i=on(e)(on(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...Tt(r)(o=>aN(o.c)(o.p1)(o.p2)),2,t.x+t.w,t.y+t.h-i,3,t.x+t.w,t.y+t.h,t.x+t.w-i,t.y+t.h,2,t.x+i,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-i,2,r[0].p1.x,r[0].p1.y,5]:rN(t)(e)},c_=t=>e=>n=>r=>i=>o=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(i)(o);if(e==="Cylinder"){const u=i_(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=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==="Diamond"){const u=s_(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=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==="Document"){const u=n_(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=a_(n)(r);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}return t.drawRoundedRect(n)(r)(i)(o)},cN=t=>()=>t.clip("evenodd"),gN=t=>e=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(e.tile,.001))),r=Math.max(2,Math.round(e.tile*n)),i=document.createElement("canvas");i.width=r,i.height=r;const o=i.getContext("2d");o.scale(n,n),o.fillStyle=e.bgCss,o.fillRect(0,0,e.tile,e.tile),o.fillStyle=e.dotCss,o.beginPath(),o.arc(e.tile/2,e.tile/2,e.dotR,0,2*Math.PI),o.fill();const u=t.createPattern(i,"repeat");u&&typeof u.setTransform=="function"&&u.setTransform(new DOMMatrix().scaleSelf(1/n,1/n)),t.save(),t.fillStyle=u,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},ia=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},oa=t=>e=>n=>{const r=e.stroke;return()=>{const i=r.value,o=Hd(t)(n);if(i!==n)return o(),e.stroke.value=n}},fN=t=>e=>n=>{const r=e.font;return()=>{const i=r.value,o=tl(t)(n);if(i!==n)return o(),e.font.value=n}},Wi=t=>e=>n=>{const r=e.fill;return()=>{const i=r.value,o=qd(t)(n);if(i!==n)return o(),e.fill.value=n}},ru=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=gc(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=gi(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=fi(t)({cpx:(()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})(),cpy:(()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=o+3|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=o+4|0;return c>=0&&c<e.length?e[c]:0})()}),a=r(o+5|0);return()=>(s(),a())}if(u===4){const s=nl(t)({cp1x:(()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})(),cp1y:(()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})(),cp2x:(()=>{const c=o+3|0;return c>=0&&c<e.length?e[c]:0})(),cp2y:(()=>{const c=o+4|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=o+5|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=o+6|0;return c>=0&&c<e.length?e[c]:0})()}),a=r(o+7|0);return()=>(s(),a())}if(u===5){const s=fc(t),a=r(o+1|0);return()=>(s(),a())}return()=>{}},i=cc(t);return()=>(i(),r(0)())},_N=t=>e=>n=>r=>i=>o=>{const u=ia(o)(ia(r/2)(i/2)),s=gc(t)(e+u)(n);return()=>(s(),gi(t)(e+r-u)(n)(),fi(t)({cpx:e+r,cpy:n,x:e+r,y:n+u})(),gi(t)(e+r)(n+i-u)(),fi(t)({cpx:e+r,cpy:n+i,x:e+r-u,y:n+i})(),gi(t)(e+u)(n+i)(),fi(t)({cpx:e,cpy:n+i,x:e,y:n+i-u})(),gi(t)(e)(n+u)(),fi(t)({cpx:e,cpy:n,x:e+u,y:n})(),fc(t)())},dN=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),lN=t=>e=>{const n=Ud(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=dN();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0}}}},hN={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},pN=t=>oe(t.weight)+" "+Ra(t.size)+"px "+t.family,vn=t=>{const e=Ra(rt(t.a)/255);return t.a>=255?"rgb("+oe(t.r)+","+oe(t.g)+","+oe(t.b)+")":"rgba("+oe(t.r)+","+oe(t.g)+","+oe(t.b)+","+e+")"},mN=t=>e=>n=>r=>{const i=Wi(t)(n)(vn(r));return()=>(i(),Vd(t)({x:0,y:0,width:e.width,height:e.height})())},yN=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",gN(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:vn(n.bgColor),dotCss:vn(n.dotColor),tile:n.tile,dotR:n.dotRadius})())},xN=t=>e=>n=>r=>{const i=Wi(t)(e)(vn(r));return()=>(i(),ru(t)(n)(),Qu(t)())},NN=t=>e=>n=>r=>i=>{const o=Wi(t)(e)(vn(r));return()=>(o(),oa(t)(e)(vn(i.color))(),Gu(t)(i.width)(),ao(t)((()=>{if(i.lineJoin==="RoundJoin")return so;if(i.lineJoin==="BevelJoin")return Ru;if(i.lineJoin==="MiterJoin")return Bu;g()})())(),Hu(t)((()=>{if(i.lineCap==="ButtCap")return qu;if(i.lineCap==="RoundCap")return zu;if(i.lineCap==="SquareCap")return Wu;g()})())(),ru(t)(n)(),Qu(t)(),Iu(t)())},JN=t=>e=>n=>r=>i=>o=>{const u=cc(t);return()=>{if(u(),_N(t)(n.x)(n.y)(n.w)(n.h)(r)(),i.tag==="Just"?(Wi(t)(e)(vn(i._1.color))(),Qu(t)()):i.tag==="Nothing"||g(),o.tag==="Just")return oa(t)(e)(vn(o._1.color))(),Gu(t)(o._1.width)(),ao(t)((()=>{if(o._1.lineJoin==="RoundJoin")return so;if(o._1.lineJoin==="BevelJoin")return Ru;if(o._1.lineJoin==="MiterJoin")return Bu;g()})())(),Hu(t)((()=>{if(o._1.lineCap==="ButtCap")return qu;if(o._1.lineCap==="RoundCap")return zu;if(o._1.lineCap==="SquareCap")return Wu;g()})())(),Iu(t)();o.tag!=="Nothing"&&g()}},TN=t=>e=>n=>r=>{const i=oa(t)(e)(vn(r.color));return()=>(i(),Gu(t)(r.width)(),ao(t)((()=>{if(r.lineJoin==="RoundJoin")return so;if(r.lineJoin==="BevelJoin")return Ru;if(r.lineJoin==="MiterJoin")return Bu;g()})())(),Hu(t)((()=>{if(r.lineCap==="ButtCap")return qu;if(r.lineCap==="RoundCap")return zu;if(r.lineCap==="SquareCap")return Wu;g()})())(),ru(t)(n)(),Iu(t)())},g_=t=>e=>n=>{const r=Wi(t)(e)(vn(n.color));return()=>(r(),fN(t)(e)(pN(n.font))(),dl(t)((()=>{if(n.align==="AlignLeft")return sl;if(n.align==="AlignCenter")return cl;if(n.align==="AlignRight")return al;g()})())(),_l(t)((()=>{if(n.baseline==="BaselineTop")return rl;if(n.baseline==="BaselineMiddle")return il;if(n.baseline==="BaselineAlphabetic")return ol;if(n.baseline==="BaselineBottom")return ul;g()})())(),el(t)(n.content)(n.x)(n.y)())},f_={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>hN},wN={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>f_},vN=t=>e=>n=>{const r=ia(e.width/n.vw)(e.height/n.vh),i=Fu(t)({translateX:(e.width-n.vw*r)/2-n.vx*r,translateY:(e.height-n.vh*r)/2-n.vy*r});return()=>(i(),oo(t)({scaleX:r,scaleY:r})(),ao(t)(so)())},bN={pure:t=>e=>()=>t,Apply0:()=>f_},kN={Applicative0:()=>bN,Bind1:()=>wN},__={fillPath:t=>e=>n=>{const r=xN(n.ctx)(n.styleCache)(t)(e.color),i=n.maskDepth;return()=>{if(i.value===0)return r()}},strokePath:t=>e=>n=>{const r=TN(n.ctx)(n.styleCache)(t)(e),i=n.maskDepth;return()=>{if(i.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const i=NN(r.ctx)(r.styleCache)(t)(e.color)(n),o=r.maskDepth;return()=>{if(o.value===0)return i()}},drawRoundedRect:t=>e=>n=>r=>i=>{const o=JN(i.ctx)(i.styleCache)(t)(e)(n)(r),u=i.maskDepth;return()=>{if(u.value===0)return o()}},drawText:t=>e=>{const n=g_(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=_r(n.ctx),i=n.maskDepth;return()=>{if(i.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Zd(n.ctx)(t)(),g_(n.ctx)(n.styleCache)(e)(),dr(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=_r(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Fu(e.ctx)({translateX:t.tx,translateY:t.ty})(),oo(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBakedTransform:t=>e=>{const n=_r(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Fu(e.ctx)({translateX:t.tx,translateY:t.ty})(),oo(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushClip:t=>e=>n=>{const r=_r(n.ctx),i=n.maskDepth;return()=>{if(i.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",ru(n.ctx)(t)(),e==="NonZero")return Yd(n.ctx)();if(e==="EvenOdd")return cN(n.ctx)();g()}}},popClip:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBlend:t=>e=>{const n=_r(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){if(n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",t==="Normal")return dc(e.ctx)(gl)();if(t==="Difference")return dc(e.ctx)(fl)();g()}}},popBlend:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushAlpha:t=>e=>{const n=_r(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Xd(e.ctx)(t)()}},popAlpha:t=>{const e=dr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushLayer:t=>e=>{if(t==="LayerNodeMask"){const n=e.maskDepth;return()=>{const r=n.value;n.value=r+1|0}}return()=>{}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;if(n>0)return t.maskDepth.value=r}},setViewport:t=>e=>{const n=vN(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=mN(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=yN(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=zf(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Wf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Kf,Monad0:()=>kN},LN=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Xr=t=>e=>n=>{const r=LN(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},d_=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()},iu=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:Ti(8)(.6)(d_(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:Ti(8)(.6)(d_(1-t._1))};g()};function EN(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function CN(t){const e=t.length,n=new Array(e);for(let r=0;r<e;r++){const i=t[r],o=t[(r+1)%e];n[r]={a:i,b:o,len:EN(i,o)}}return n}function SN(t,e,n){let r=0;for(let i=0;i<t.length;i++){const o=t[i],u=r,s=u+o.len;if(n<=s){const a=o.len>1e-6?(n-u)/o.len:0;return{x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a}}r=s}return e.length>0?e[e.length-1]:{x:0,y:0}}function l_(t,e){if(e.length===0)return[];const n=CN(e);let r=0;for(let o=0;o<n.length;o++)r+=n[o].len;const i=new Array(t);for(let o=0;o<t;o++)i[o]=SN(n,e,o*r/t);return i}function GN(t,e){const n=e.length;if(n===0)return e;const r=(t%n+n)%n|0,i=new Array(n);for(let o=0;o<n;o++)i[o]=e[(o+r)%n];return i}function PN(t,e){const n=e.length;if(n===0)return e;let r=0,i=1/0;for(let o=0;o<n;o++){let u=0;for(let s=0;s<n;s++){const a=t[s]||{x:0,y:0},c=e[(s+o)%n]||{x:0,y:0},f=a.x-c.x,d=a.y-c.y;u+=f*f+d*d}u<i&&(i=u,r=o)}return GN(r,e)}const h_=t=>e=>n=>{const r=l_(t,e),i=l_(t,n),o=PN(r,i);return{from:r,to:o}};function p_(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 DN(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 IN(t,e){const n=e.length;if(n===0)return e;const r=new Array(n);for(let i=0;i<n;i++){const o=e[((i-1)%n+n)%n],u=e[((i+1)%n+n)%n],s=e[i];r[i]={x:s.x+((o.x+u.x)/2-s.x)*t,y:s.y+((o.y+u.y)/2-s.y)*t}}return r}function QN(t){return t<0?0:t>1?1:t}const m_=t=>e=>n=>r=>{const i=e.length;if(i===0)return[];const o=p_(e),u=p_(n),s=DN(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=QN((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=IN(.5,l);return l},bn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},y_=J(Lr)(0),x_=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},FN=J(t=>e=>t+e.len)(0),ua=t=>{const e=Mt(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()},AN=t=>e=>{const n=bn(e)(bn(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},MN=t=>{const e=Mt(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()},ON=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return i_(e);if(t.shape==="Parallelogram")return e_(e);if(t.shape==="Diamond")return s_(e);if(t.shape==="Ellipse")return t_(e);if(t.shape==="Document")return n_(e);if(t.shape==="Cloud")return a_(e)(7);if(t.shape==="Rectangle")return AN(e)(7);g()},pe=t=>e=>n=>W(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)),RN=t=>{const e=on(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)]},Yr=t=>e=>{const n=bn(t)(bn(e.w/2)(e.h/2));return{...e,x:e.x+n,y:e.y+n,w:e.w-2*n,h:e.h-2*n}},sa=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return Le(r*r+n*n)},BN=t=>Te(e=>n=>({a:e,b:n,len:sa(e)(n)}),t,bt(1,t.length,t)),zN=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=sa(h)(f._1),m=sa(_._1)(h),y=bn(t)(p/2),x=bn(t)(m/2),N=p>0?y/p:0,w=h.x+(f._1.x-h.x)*N,L=h.y+(f._1.y-h.y)*N,k=m>0?x/m:0,E=h.x+(_._1.x-h.x)*k,O=h.y+(_._1.y-h.y)*k;return W(Y=>{const et=rt(Y)/rt(10),G=1-et;return{x:G*G*E+2*G*et*h.x+et*et*w,y:G*G*O+2*G*et*h.y+et*et*L}})(It(0,10))}return[]}),...i]},WN=t=>e=>n=>r=>i=>W(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)),qN=t=>[...pe({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...pe({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...WN({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)],N_=t=>e=>W(n=>{const r=6.283185307179586*rt(n)/rt(64);return{x:t.x+e*en(r),y:t.y+e*He(r)}})(It(0,63)),ou=t=>e=>{const n=.5522847498*e;return[1,t.x+e,t.y,4,t.x+e,t.y+n,t.x+n,t.y+e,t.x,t.y+e,4,t.x-n,t.y+e,t.x-e,t.y+n,t.x-e,t.y,4,t.x-e,t.y-n,t.x-n,t.y-e,t.x,t.y-e,4,t.x+n,t.y-e,t.x+e,t.y-n,t.x+e,t.y,5]},HN=t=>{const e=t.y+t.h/2,n=on(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)]},J_=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:y_(W(n=>n.x)(t))/rt(e),y:y_(W(n=>n.y)(t))/rt(e)}},uu=t=>e=>n=>r=>i=>W(o=>{const u=n+(r-n)*(rt(o)/rt(i));return{x:t.x+e*en(u),y:t.y+e*He(u)}})(It(0,i-1|0)),T_=t=>e=>{const n=bn(t)(bn(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),...uu({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),...uu({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),...uu({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),...uu({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},su=t=>e=>n=>r=>i=>o=>W(u=>{const s=r+(i-r)*(rt(u)/rt(o));return{x:t.x+e*en(s),y:t.y+n*He(s)}})(It(0,o-1|0)),$N=t=>{const e=t.h*.38;return[...Tt(u_(o_(r_)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=fr(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),i=fr(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return su({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(i)(r>i?r:r+6.283185307179586)(16)}),...pe({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...pe({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...pe({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},XN=t=>{const e=bn(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[...su({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),...su({x:o,y:i})(n)(e)(0)(3.141592653589793)(24),...pe({x:t.x,y:i})({x:t.x,y:r})(12)]},Jr=t=>e=>e.shape==="Cylinder"?XN(e):e.shape==="Parallelogram"?RN(e):e.shape==="Diamond"?HN(e):e.shape==="Ellipse"?T_(on(e.w)(e.h)/2)(e):e.shape==="Document"?qN(e):e.shape==="Cloud"?$N(e):T_(t)(e),YN=t=>{const e=bn(t.h*.075)(t.w*.075),n=t.w/2;return su({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},VN=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})()})()?Ot(r.points)(s):[...r.points,c,s]:[c,s];return i.len<=0||o<=e||r.pos>=n?{...r,pos:o}:{pos:o,points:d}})({pos:0,points:[]})(t).points,UN=t=>e=>n=>{const r=Mt(i=>T,i=>o=>v("Just",{head:i,tail:o}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const i=BN(t),o=FN(i),u=x_(0)(o)(e*o),s=x_(0)(o)(n*o);return s<=u?[]:VN(i)(u)(s)}g()},ZN=t=>e=>n=>r=>{const i=r.x-n.x,o=r.y-n.y,u=e.x-t.x,s=e.y-t.y,a=n.x-t.x,c=n.y-t.y,f=u*o-s*i,d=(a*o-c*i)/f,l=(a*s-c*u)/f;return(f<0?-f<1e-9:f<1e-9)?T:d>=0&&d<=1&&l>=0&&l<=1?v("Just",d):T},KN=t=>e=>n=>{const r=Lt(i=>o=>ut.compare(i.t)(o.t))(xt(i=>{const o=ZN(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})(Te(Cn,t,[...bt(1,t.length,t),...bt(0,1,t)])));return 0<r.length?v("Just",r[0].p):T},w_=t=>e=>{const n=ii(e);if(n.tag==="Nothing")return e;if(n.tag==="Just"){const r=n._1.init.length-1|0;if(r>=0&&r<n._1.init.length){const i=KN(t)(n._1.init[r])(n._1.last);if(i.tag==="Just")return Ot(n._1.init)(i._1);if(i.tag==="Nothing")return e;g()}return e}g()},aa=t=>t,Mn=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Tr=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},jN=td(Xa)(zt),tJ=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},eJ=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},v_=aa("SegMove"),nJ=aa("SegLine"),rJ=aa("SegQuad"),b_={offset:.4,passes:1,rMax:1.5},k_=t=>de(ln(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,au=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},cu=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},On=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},qi=(()=>{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})(),iJ=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const i=n,o=r,u=i>=0&&i<t.length?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:v_,m:o,c:o,p:s,len:0}),r=s,n=i+3|0;continue}if(u._1===2){const s={x:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()},a=s.x-o.x,c=s.y-o.y;e.push({kind:nJ,m:o,c:o,p:s,len:Le(a*a+c*c)}),r=s,n=i+3|0;continue}if(u._1===3){const s={x:(()=>{const f=i+3|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+4|0;return f>=0&&f<t.length?t[f]:0})()},a=s.x-o.x,c=s.y-o.y;e.push({kind:rJ,m:o,c:{x:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()},p:s,len:Le(a*a+c*c)*1.05}),r=s,n=i+5|0;continue}if(u._1===5){e.push({kind:v_,m:o,c:o,p:o,len:0}),n=i+1|0;continue}n=t.length;continue}g()}return e},oJ=t=>e=>{const n=e.length-1|0,r=n<1?[]:bt(0,n,e),i=(()=>{const u=r.length-1|0;return u>=0&&u<r.length?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=Le(s*s+u*u);return a<=1e-4?e:Ot((()=>{const c=e.length-1|0;return c<1?[]:bt(0,c,e)})())({x:e[o].x+s/a*t,y:e[o].y+u/a*t})}return e},uJ=t=>e=>n=>Je(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*en(u.value),y:i.y+o.value*He(u.value)},...r.out]}})({prng:e,out:[]})(n).out),sJ=t=>e=>n=>{if(e.kind==="SegMove")return cu(t)(e.p);if(e.kind==="SegLine")return On(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 On(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});g()},aJ=t=>e=>{if(e.kind==="SegMove")return cu(t)(e.p);if(e.kind==="SegLine")return On(t)(e.p);if(e.kind==="SegQuad")return au(t)(e.c)(e.p);g()},L_=t=>e=>{const n=iJ(e),r=J(s=>a=>s+a.len)(0)(n)*Mn(0)(Tr(1)(t)),i=[];let o=0,u=0;for(;u<n.length;){const s=u,a=o;if(s>=0&&s<n.length){if(a+n[s].len<=r){const c=n[s];aJ(i)(c)(),o=a+c.len,u=s+1|0;continue}if(a>=r){u=n.length;continue}sJ(i)(n[s])((r-a)/Mn(n[s].len)(1e-4))()}u=n.length}return i},E_={offset:1.5,passes:2,rMax:14,overshoot:2.5},C_=t=>e=>n=>r=>{const i=r.y-n.y,o=n.y-e.y,u=r.x-n.x,s=Le(u*u+i*i),a=n.x-e.x,c=Le(a*a+o*o),f=Tr(t.rMax*(yd(c>0&&s>0?Mn(-1)(Tr(1)((a*u+o*i)/(c*s))):1)/3.141592653589793))(.4*Tr(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}},S_=t=>e=>{const n=e.length,r=[],i=0<e.length?v("Just",e[0]):T;if(i.tag==="Just"?cu(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=C_(t)(e[c])(e[s])(e[a]);On(r)(f.inP)(),au(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&&On(r)(e[o])(),r},cJ=t=>e=>n=>r=>i=>{if(i.length<4)return S_(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=Un(Un(e)(s)+s|0)(s),c=_=>{const h=Un(_+s|0)(s);return h>=0&&h<i.length?i[h]:u},f=W(_=>C_(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(cu(d)(l._1.outP)(),jN((()=>{const _=Mt(h=>T,h=>p=>v("Just",p),f);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})())(_=>{const h=On(d)(_.inP);return()=>(h(),au(d)(_.curr)(_.outP)())})(),n)On(d)(l._1.inP)(),au(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const _=f.length-1|0;_>=0&&_<f.length?On(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}})())():On(d)(l._1.inP)()}else l.tag==="Nothing"||g();return d},Vr=t=>e=>n=>r=>{const i=tJ(1)(r.length-1|0),o=ae(0)(rt(i))(hs("shape")(e)),u=eJ(i-1|0)(de(ln(o.value))),s=o.prng;return W(a=>{const c=ae(0)(1)(hs(oe(a))(s)),f=ae(-.18)(.3)(c.prng),d=c.value<.7,l=ae(.5)(.85)(f.prng),_=uJ(t.offset)(l.prng)(r);return{path:n?cJ(t)(u)(d)(f.value)(_):S_(t)(_),alpha:l.value}})(It(0,t.passes-1|0))},gJ=t=>e=>n=>Vr(t)(e)(!0)([{x:n.x,y:n.y},{x:n.x+n.w,y:n.y},{x:n.x+n.w,y:n.y+n.h},{x:n.x,y:n.y+n.h},{x:n.x,y:n.y}]),fJ=t=>e=>n=>{const r=Mn(0)(Tr(1)(n)),i=e.h/rt(4),o=Mn(6)(i*1.4);return xt(u=>u)(W(u=>{if(r<Mn(0)(rt(u)/rt(4)-.05))return T;const s=hs(oe(u))(t),a=Mn(0)(rt(u)/rt(4)-.05),c=Un(u)(2)===0,f=c?e.x-2:e.x+e.w+2,d=c?e.x+e.w+2:e.x-2,l=e.y+(rt(u)+.5)*i;return v("Just",{path:L_(Mn(0)(Tr(1)((r-a)/Mn(1e-4)(Tr(1)(rt(u+1|0)/rt(4)+.05)-a))))((()=>{const _={rMax:2,offset:.6,passes:1},h=Je(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?[]:Vr(_)(s)(!1)(h);return 0<p.length?p[0].path:[]})()),width:o,alpha:1})})(It(0,3)))},ca=(t,e,n)=>({tag:t,_1:e,_2:n}),G_=t=>t,ga=(t,e,n)=>({tag:t,_1:e,_2:n}),gu=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()},P_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Hi=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},D_=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},Pe=(()=>{const t=$e.unfoldr(pn);return e=>t(Xe("IterNode",e,hn))})(),Rn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=v("Just",o._4);continue}}g()}return i},_J=zt.foldMap(Dd),fu=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},I_=jt(C)(zt),dJ=uc(C),lJ=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},fa=G_("LabelsShown"),hJ=G_("LabelsHidden"),Q_=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))))))},Ze=t=>{const e=t.Apply0();return n=>J(r=>i=>e.apply(e.Functor0().map(o=>Oa)(r))(n(i)))(t.pure())},F_=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=Xr(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=h_(128)(Jr(4)(Yr(2)(e)))(N_(f)(6)),p=f.x-s.x,m=2*(()=>{const V=f.y-s.y;return(p<0?-p:p)+(V<0?-V:V)})(),y=_.x-u.x,x=2*(()=>{const V=_.y-u.y;return(y<0?-y:y)+(V<0?-V:V)})(),N=m+pi(t)+x,w=N<=1e-4?1:1-x/N,L=N<=1e-4?0:m/N,k=w-L,E=h_(128)(N_(_)(6))(Jr(4)(Yr(2)(n))),O={maxDelay:.4,smoothPasses:2},Y=mr(t)(gu(0)(1)(k<=1e-4?0:(a-L)/k)),et=(()=>{if(Y.tag==="Just")return Y._1;if(Y.tag==="Nothing")return f;g()})(),G=(()=>{if(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(L<=1e-4)return 1;const V=a/L,U=V<0?0:V>1?1:V;return U*U*(3-2*U)})();return a<L?ga("PolyShape",m_(P)(h.from)(h.to)(O)):a>=w?ga("PolyShape",m_(G)(E.from)(E.to)(O)):ga("CircleShape",et,6)},A_=t=>e=>n=>r=>i=>o=>{const u=F_(t)(e)(n)(r)(i)(o);if(u.tag==="PolyShape")return J_(u._1);if(u.tag==="CircleShape")return u._1;g()},pJ=t=>e=>{const n=t.y+t.h-6,r=t.y+6,i=t.x+14,o=t.x+t.w-14,u=J(Hi)(0)(W(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?P_((s.x+s.w+12-(i-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+u*.7071067811865476,y:t.y-u*.7071067811865476}},mJ=t=>e=>n=>J(r=>i=>{const o=D_(i)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just"){const u=pJ(o._1)(r.obstacles);return{acc:j(C)(i)(u)(r.acc),obstacles:Ot(r.obstacles)(u)}}g()})({acc:Q,obstacles:n})(t).acc,_a=(()=>{const t={r:24,g:24,b:27,a:255},e={r:244,g:244,b:245,a:255},n={r:248,g:249,b:246,a:255},r={r:26,g:26,b:26,a:255},i={r:28,g:101,b:192,a:255},o={r:247,g:248,b:250,a:255},u={r:42,g:48,b:60,a:255},s={r:120,g:130,b:146,a:255};return a=>{if(a==="Light")return{bg:{r:255,g:255,b:255,a:255},bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:211,b:209,a:255},shadowFill:{r:255,g:255,b:255,a:255},shadowDot:{r:26,g:26,b:26,a:255},chip:{r:255,g:235,b:130,a:255},chipShadow:{r:214,g:211,b:209,a:255},chipText:An,nodeFill:ie,nodeStroke:An,text:An,edge:An,arrowFill:An,tokenOutsideFill:An,tokenOutsideStroke:ie,tokenInside:ie,tokenInsideStroke:ie,tokenInsideBlend:nu,tokenInsideAlpha:1,chipPillFill:An,chipPillText:ie,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:ie,tokenOutsideStroke:ie,tokenInside:ie,tokenInsideStroke:ie,tokenInsideBlend:nu,tokenInsideAlpha:1,chipPillFill:e,chipPillText:t,chipHairline:{r:244,g:244,b:245,a:120},trailDot:e,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Blueprint")return{bg:i,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:90,g:160,b:230,a:255},shadowFill:i,shadowDot:ie,chip:ie,chipShadow:{r:0,g:0,b:0,a:120},chipText:i,nodeFill:i,nodeStroke:ie,text:ie,edge:ie,arrowFill:ie,tokenOutsideFill:ie,tokenOutsideStroke:ie,tokenInside:ie,tokenInsideStroke:ie,tokenInsideBlend:Vf,tokenInsideAlpha:.35,chipPillFill:ie,chipPillText:i,chipHairline:{r:255,g:255,b:255,a:120},trailDot:ie,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Whiteboard")return{bg:n,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:0,g:0,b:0,a:0},shadowFill:n,shadowDot:r,chip:{r:217,g:74,b:56,a:255},chipShadow:{r:26,g:26,b:26,a:60},chipText:n,nodeFill:n,nodeStroke:r,text:r,edge:r,arrowFill:r,tokenOutsideFill:r,tokenOutsideStroke:n,tokenInside:n,tokenInsideStroke:n,tokenInsideBlend:Vf,tokenInsideAlpha:1,chipPillFill:r,chipPillText:n,chipHairline:{r:26,g:26,b:26,a:90},trailDot:r,wobble:!0,fontFamily:"Supermarker, Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Isometric")return{bg:o,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:218,b:224,a:255},shadowFill:o,shadowDot:u,chip:{r:255,g:235,b:130,a:255},chipShadow:{r:100,g:110,b:125,a:90},chipText:u,nodeFill:{r:236,g:239,b:244,a:255},nodeStroke:u,text:u,edge:s,arrowFill:s,tokenOutsideFill:u,tokenOutsideStroke:ie,tokenInside:ie,tokenInsideStroke:ie,tokenInsideBlend:nu,tokenInsideAlpha:1,chipPillFill:u,chipPillText:ie,chipHairline:{r:60,g:66,b:78,a:90},trailDot:u,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};g()}})(),da=t=>e=>Tt(Pe(t.nodes))(n=>{const r=fe(n._1)(e.nodes);return r.tag==="Just"&&iu(r._1).alpha>0?ON(n._2):[]}),yJ=t=>e=>n=>[1,t.vx,t.vy,2,t.vx+t.vw,t.vy,2,t.vx+t.vw,t.vy+t.vh,2,t.vx,t.vy+t.vh,5,...da(e)(n)],xJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=ar.traverse(r);return o=>u=>{const s=Zn(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?co(s[c]):" "))(l=>r.pure({x:f,w:d-f,up:l.ascent-a,down:l.descent+a})))))(It(0,s.length-1|0))}},NJ=t=>e=>{const n=i=>(i.x-e.x)*(i.x-e.x)+(i.y-e.y)*(i.y-e.y),r=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 W(i=>{const o=rt(i)/5;return{x:r.x+(e.x-r.x)*o,y:r.y+(e.y-r.y)*o}})([1,2,3,4])},la=t=>{const e=yo(`
|
|
7
|
+
`)(t);return e.length===0?[""]:e},JJ=t=>e=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},a=Xr(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 O=f.y-s.y;return(h<0?-h:h)+(O<0?-O:O)})(),m=_.x-u.x,y=2*(()=>{const O=_.y-u.y;return(m<0?-m:m)+(O<0?-O:O)})(),x=p+pi(t)+y,N=x<=1e-4?1:1-y/x,w=x<=1e-4?0:p/x,L=N-w,k=mr(t)(gu(0)(1)(L<=1e-4?0:(a-w)/L)),E=(()=>{if(k.tag==="Just")return k._1;if(k.tag==="Nothing")return f;g()})();return a<w?ca("InsideRect",Yr(2)(e)):a>=N?ca("InsideRect",Yr(2)(n)):ca("InsideBall",E,6)},TJ={offset:.8,passes:2,rMax:5},wJ=t=>{const e=t.Monad0().Applicative0(),n=Ze(e);return r=>i=>o=>u=>{const s={color:u,width:1,lineJoin:we,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=Rn(f._2._1.edge)(r.edges),l=fe(f._2._1.target)(r.nodes),_=fe(f._2._1.source)(r.nodes);if(_.tag==="Just"&&l.tag==="Just"&&d.tag==="Just"){const h=JJ((()=>{if(f._2._1.direction==="Forward")return d._1;if(f._2._1.direction==="Backward")return Je(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(ou(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(Yr(2)(d._1));if(d.tag==="Nothing")return e.pure();g()}return e.pure()})(Pe(i.tokens))}},M_=t=>e=>n=>r=>t.strokePath((()=>{const i=Mt(o=>T,o=>u=>v("Just",{head:o,tail:u}),W(o=>o.pt)(_d(o=>u=>{const s=rt(u)/rt(72),a=ae(-.18)(.18)(o.prng),c=ae(-.1)(.1)(a.prng),f=ae(-.07)(.07)(c.prng),d=n*(.05+.55*s)*(1+c.value),l=s*28.274333882308138+a.value;return{prng:f.prng,pt:{x:e.x+en(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,..._J(o=>[2,o.x,o.y])(i._1.tail)];if(i.tag==="Nothing")return[];g()})())({color:r,width:5.5,lineJoin:we,lineCap:wn}),vJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=Ze(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:we,lineCap:wn}))(()=>r)))(fJ(k_(u)+7777|0)(u)(s))},O_=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=e.Applicative0(),o=Ze(i),u=t.popClip,s=Ze(i),a=ar.traverse(i),c=xJ(t),f=vJ(t),d=t.popTransform;return l=>_=>h=>p=>m=>y=>x=>{const N=M=>n.bind(t.pushAlpha(M.alpha))(()=>n.bind(t.strokePath(M.path)({color:_.nodeStroke,width:2,lineJoin:we,lineCap:wn}))(()=>r)),w={family:_.fontFamily,size:_.wobble?15:11,weight:_.wobble?800:500},L=yo(`
|
|
8
|
+
`)(y.label===""?m:y.label),k=L.length===0?[""]:L,E=w.size*1.2,O=y.shape==="Cylinder"?t.strokePath(sN({x:y.x,y:y.y,w:y.w,h:y.h}))({color:_.nodeStroke,width:1.25,lineJoin:we,lineCap:_n}):i.pure(),Y=(y.shape==="Cylinder"?(y.y+(y.y+y.h+5-2*on(y.h*.075)(y.w*.075)))/2:(y.y+y.y+y.h)/2)-rt(k.length)*E/2+E/2,et=x.tag==="PloppingOut"&&_.wobble?x._1:-1,G=et>=0,P=iu(x),V=G?{alpha:1,scale:1}:P,U=y.x+y.w/2,B=y.y+y.h/2,R=n.bind(t.pushAlpha(V.alpha*h))(()=>n.bind(t.pushTransform({tx:U*(1-V.scale),ty:B*(1-V.scale),sx:V.scale,sy:V.scale}))(()=>{const M={x:y.x,y:y.y,w:y.w,h:y.h},S={color:_.nodeStroke,width:_.wobble?2:1.25,lineJoin:we,lineCap:_.wobble?wn:_n};return n.bind((()=>{if(_.wobble){if(y.shape==="Rectangle")return o(N)(gJ(E_)(k_(M))(M));const D=Jr(7)(y);return n.bind(o(N)((()=>{const I=qi(D);return D.length<4?[]:Vr(b_)(I)(!0)(D)})()))(()=>s(I=>o(N)((()=>{const A=qi(I);return I.length<2?[]:Vr(b_)(A)(!1)(I)})()))(y.shape==="Cylinder"?[YN(y)]:[]))}return n.bind(c_(t)(y.shape)(M)(7)(v("Just",{color:_.nodeFill,flat:!1}))(v("Just",S)))(()=>O)})())(()=>n.bind((()=>{if(p.tag==="Just"&&_.wobble&&!G){const D=p._1;return n.bind(a(c(w))(k))(I=>{const A=Lt(K=>nt=>ut.compare(K.x)(nt.x)),H=de(ln(y.x*7919+y.y*3001))*-1640531535|0,$=ae(5)(7.5)(H),X=ae(0)($.value)($.prng),q=-(1+2*ae(-1)(1)(X.prng).value*3.141592653589793/180),z=(K,nt,ht,_t,Nt)=>A(xt(wt=>wt)([q*nt+K>=_t&&q*nt+K<=Nt?v("Just",{x:nt,y:q*nt+K}):T,q*ht+K>=_t&&q*ht+K<=Nt?v("Just",{x:ht,y:q*ht+K}):T,(()=>{const wt=(_t-K)/q;return wt>=nt&&wt<=ht?v("Just",{x:wt,y:_t}):T})(),(()=>{const wt=(Nt-K)/q;return wt>=nt&&wt<=ht?v("Just",{x:wt,y:Nt}):T})()])),tt=$.value,Z=Un(D.frameHash)(3),ct=Z===0?{r:200,g:35,b:30,a:220}:Z===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},ft=y.x+y.w/2,at=Oe(Ft(K=>nt=>Ft((()=>{const ht=Y+rt(K)*E,_t=ft-J(Nt=>wt=>Nt+wt.w)(0)(nt)/2;return Nt=>wt=>{const Kt=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-Kt;return{x:_t+sn-1,y:ht-wt.up-1,w:Hi(0)((()=>{const Me=Nt+1|0;return Me>=0&&Me<nt.length&&Nt<(nt.length-1|0)?(wt.x+wt.w+nt[Me].x)/2-sn:wt.x+wt.w+Kt-sn})())+2,h:wt.up+wt.down+2}}})())(nt))(I)),yt=y.y+4,St=y.x+y.w-4,Rt=y.x+4,pt=yt-q*Rt+X.value,Bt=y.y+y.h-4,Jt=Tt(Tt(Ft(K=>nt=>{const ht=(nt.from.x+nt.to.x)/2,_t=(nt.from.y+nt.to.y)/2,Nt=ae(-1)(1)(H+(911*(K+1|0)|0)|0),wt=ae(-3)(5)(Nt.prng),Kt=Nt.value*3.141592653589793/180,Se=en(Kt),sn=He(Kt),Me=Et=>({x:ht+(Et.x-ht)*Se-(Et.y-_t)*sn,y:_t+(Et.x-ht)*sn+(Et.y-_t)*Se});return{from:(()=>{const Et=Me(nt.from),Qt=Et.y-_t,je=Et.x-ht,qe=Le(je*je+Qt*Qt),tn=qe<1e-4?1:(qe+wt.value)/qe;return{x:ht+je*tn,y:_t+Qt*tn}})(),to:(()=>{const Et=Me(nt.to),Qt=ae(-3)(5)(wt.prng).value,je=Et.y-_t,qe=Et.x-ht,tn=Le(qe*qe+je*je),Hn=tn<1e-4?1:(tn+Qt)/tn;return{x:ht+qe*Hn,y:_t+je*Hn}})()}})(xt(K=>{const nt=z(pt+rt(K)*tt,Rt,St,yt,Bt);return nt.length===2?v("Just",{from:nt[0],to:nt[1]}):T})(It(0,fu(1)(de(ln((Bt-q*St-pt)/tt)))))))(K=>st(nt=>nt.to.x-nt.from.x>1,J(nt=>ht=>Tt(nt)(_t=>{const Nt=z(_t.from.y-q*_t.from.x,ht.x,ht.x+ht.w,ht.y,ht.y+ht.h);return Nt.length===2?Nt[0].x>_t.from.x+.001&&Nt[1].x<_t.to.x-.001?[{from:_t.from,to:Nt[0]},{from:Nt[1],to:_t.to}]:Nt[0].x<=_t.from.x+.001&&Nt[1].x<_t.to.x-.001?[{from:Nt[1],to:_t.to}]:Nt[0].x>_t.from.x+.001&&Nt[1].x>=_t.to.x-.001?[{from:_t.from,to:Nt[0]}]:[]:[_t]}))([K])(at))))(K=>(()=>{const nt=K.to.x-K.from.x;return Le(2)*(nt>=0?nt:-nt)<=28})()?[K]:[{from:K.from,to:{x:K.from.x+(K.to.x-K.from.x)*.495,y:K.from.y+(K.to.y-K.from.y)*.495}},{from:{x:K.from.x+(K.to.x-K.from.x)*.505,y:K.from.y+(K.to.y-K.from.y)*.505},to:K.to}]),mt=Jt.length,gt=K=>Hi(0)(P_(1)(D.t*rt(mt)-rt(K)));return n.bind(t.pushClip(ua(Jr(7)(y)))(eu))(()=>n.bind(o(K=>{const nt=K._1,ht=ae(1.4)(1.9)(H+(1303*(nt+1|0)|0)|0),_t=ae(.35)(.8)(ht.prng),Nt=o(wt=>n.bind(t.pushAlpha(wt.alpha*_t.value))(()=>n.bind(t.strokePath(L_(gt(nt))(wt.path))({color:ct,width:ht.value,lineJoin:we,lineCap:wn}))(()=>r)))(Vr({...E_,rMax:0,offset:.5})(H+(53*(nt+1|0)|0)|0)(!1)([K._2.from,K._2.to]));return gt(nt)>0?Nt:i.pure()})(Ft(Cn)(Jt)))(()=>u))})}return i.pure()})())(()=>n.bind((()=>{if(l==="LabelsShown")return o(D=>t.drawText({x:y.x+y.w/2,y:Y+rt(D._1)*E,content:D._2,font:w,color:_.text,align:$r,baseline:or}))(Ft(Cn)(k));if(l==="LabelsHidden")return i.pure();g()})())(()=>n.bind((()=>{const D=f(_)(M)(et);return G?D:i.pure()})())(()=>n.bind(d)(()=>r)))))}));return V.alpha*h>0?R:i.pure()}},bJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=O_(t),o=t.popAlpha,u=Ze(n);return s=>a=>c=>{const f={...s,nodeFill:s.text,text:s.nodeFill,nodeStroke:s.nodeFill};return u(d=>{const l=fe(d._1)(c.nodes),_=fe(d._1)(a.nodes),h=(()=>{if(_.tag==="Just"&&l.tag==="Just"){const p=l._1,m=_._1;return r.bind(t.pushAlpha(d._2))(()=>r.bind(i(fa)(f)(1)(T)(d._1)(m)(p))(()=>o))}return n.pure()})();return d._2>0?h:n.pure()})(Pe(c.nodeInvert))}},kJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=Ze(n);return o=>u=>s=>{const a={family:o.fontFamily,size:11,weight:500};return i(c=>{if(c._2===""||(()=>{const l=Rn(c._1)(s.edges);return l.tag==="Nothing"||!(l.tag==="Just"&&l._1.tag==="Extended")})())return n.pure();const f=Rn(c._1)(u.edges),d=(()=>{if(f.tag==="Just")return mr(f._1)(.5);if(f.tag==="Nothing")return T;g()})();if(d.tag==="Nothing")return n.pure();if(d.tag==="Just"){const l=d._1;return r.bind(t.measureText(a)(c._2))(_=>{const h=_+12;return r.bind(t.drawRoundedRect({x:l.x-h/2,y:l.y-8.5,w:h,h:17})(3)(v("Just",{color:o.chipPillFill,flat:!0}))(T))(()=>t.drawText({x:l.x,y:l.y,content:c._2,font:a,color:o.chipPillText,align:$r,baseline:or}))})}g()})(Pe(u.edgeLabels))}},R_=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=F_(a)(c)(f)(d)(l)(_);if(p.tag==="CircleShape")return o?M_(t)(p._1)(p._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(ou(p._1)(p._2))({color:u,flat:!0})({color:s,width:1,lineJoin:we,lineCap:_n});if(p.tag==="PolyShape"&&o&&p._1.length>=3)return r.bind(t.pushAlpha(h))(()=>r.bind(M_(t)(J_(p._1))(6)({r:200,g:35,b:30,a:220}))(()=>i));if(p.tag==="PolyShape")return o?n.pure():p._1.length>=3?t.fillStrokePath(ua(p._1))({color:u,flat:!0})({color:s,width:1,lineJoin:we,lineCap:_n}):n.pure();g()}},EJ=t=>{const e=t.Monad0().Bind1(),n=t.popAlpha;return r=>i=>o=>u=>s=>a=>c=>{const f=Xr(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(ou(h)(6))({color:r,flat:!0})({color:i,width:1,lineJoin:we,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)})())}},_u=t=>{const e=LJ(t),n=EJ(t),r=t.Monad0().Applicative0(),i=Ze(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 _=Rn(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 Je(_._1);g()})())(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);if(_.tag==="Nothing")return n(a)(c)(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);g()}return r.pure()}if(f._2.tag==="Filling"){if(o)return r.pure();const d=fe(f._2._1.node)(u.nodes);if(d.tag==="Just")return t.fillStrokePath(ua(Jr(4)(Yr(2)(d._1))))({color:a,flat:!0})({color:c,width:1,lineJoin:we,lineCap:_n});if(d.tag==="Nothing")return r.pure();g()}return r.pure()})(Pe(s.tokens))},B_=t=>{const e=_u(t),n=t.Monad0(),r=n.Bind1(),i=_u(t),o=wJ(t),u=t.popClip,s=t.popBlend,a=t.popLayer,c=n.Applicative0(),f=Ze(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($x))(()=>r.bind(t.pushBlend(nu))(()=>r.bind(t.pushClip(da(h)(p))(eu))(()=>r.bind(m)(()=>r.bind(u)(()=>r.bind(s)(()=>r.bind(a)(()=>r.bind(t.pushLayer(Xx))(()=>r.bind(f(y=>{const x=fe(y._1)(p.nodes);return x.tag==="Just"&&iu(x._1).alpha>0?c_(t)(y._2.shape)({x:y._2.x,y:y._2.y,w:y._2.w,h:y._2.h})(7)(v("Just",{color:ie,flat:!1}))(T):c.pure()})(Pe(h.nodes)))(()=>a)))))))));if(_.tokenInsideBlend==="Normal")return r.bind(t.pushClip(da(h)(p))(eu))(()=>r.bind(t.pushAlpha(_.tokenInsideAlpha))(()=>r.bind(m)(()=>r.bind(d)(()=>u))));g()}},z_=t=>{const e=t.Monad0().Bind1(),n=_u(t),r=_u(t),i=t.popClip,o=t.popLayer;return u=>s=>a=>c=>e.bind(t.pushLayer(Hx))(()=>e.bind(t.pushClip(yJ(s)(a)(c))(Vx))(()=>e.bind(u.wobble?n(!0)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke):r(!1)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke))(()=>e.bind(i)(()=>o))))},CJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=Ze(r);return o=>u=>s=>a=>c=>f=>{const d=Jo(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?[]:gr(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:na,baseline:or});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)(di(Kn(me(m)(f)))(f)),font:o,color:{...u,a:de(ln(x*rt(u.a)))},align:na,baseline:or})}))(p))}},du=t=>e=>n=>r=>{const i=W(_=>rt(fu(1)(Jo(_).length)))(r),o=Hi(1)(J(Lr)(0)(i)),u=Xr(e)(n)(t),s=u*o,a=fu(1)(r.length),c=(_=>h=>p=>{let m=_,y=h,x=p,N=!0,w;for(;N;){const L=m,k=y,E=Mt(O=>T,O=>Y=>v("Just",{head:O,tail:Y}),x);if(E.tag==="Nothing"){N=!1,w=fu(0)(a-1|0);continue}if(E.tag==="Just"){if(k+E._1.head>=s){N=!1,w=L;continue}m=L+1|0,y=k+E._1.head,x=E._1.tail;continue}g()}return w})(0)(0)(i),f=J(Lr)(0)(c<1?[]:bt(0,c,i)),d=f/o;if(c>=0&&c<i.length){const _=(f+i[c])/o;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(_<=d)return 1;const h=(u-d)/(_-d);return h<0?0:h>1?1:h})()}}const l=(f+1)/o;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(l<=d)return 1;const _=(u-d)/(l-d);return _<0?0:_>1?1:_})()}},SJ=t=>{const e=t.Monad0();return n=>r=>i=>e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(du(r)(0)(0)(W(ud)(i)).line))(o=>{const u=o+28;return e.Applicative0().pure({x:n.x+n.w/2-u/2,y:n.y-25.2-14,w:u,h:25.2})})},GJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=SJ(t),i=e.Applicative0(),o=ar.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>I_(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)})(Pe(s.tokens)))},PJ=t=>{const e=t.Monad0();return n=>r=>i=>o=>u=>s=>a=>{const c=A_(n)(r)(i)(o)(u)(s);return e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(du(o)(u)(s)(Tt(a)(la)).line))(f=>e.Applicative0().pure({x:c.x+14+f/2-f/2-14,y:c.y-6-8-6.6-6,w:f+28,h:25.2}))}},DJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=PJ(t),i=e.Applicative0(),o=ar.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>I_(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=Rn(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 Je(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)})(Pe(s.tokens)))},ha=t=>{const e=t.Monad0(),n=e.Bind1(),r=DJ(t),i=GJ(t);return o=>u=>n.bind(r(o)(u))(s=>n.bind(i(o)(u))(a=>e.Applicative0().pure(mJ((()=>{const c=f=>{if(f.tag==="Leaf")return Q;if(f.tag==="Node")return Wt("Node",f._1,f._2,f._3,void 0,c(f._5),c(f._6));g()};return Lt(C.compare)(Ct(We.foldr,c(s)))})())(s)([...xt(c=>{const f=fe(c._1)(u.nodes);return f.tag==="Just"&&iu(f._1).alpha>0?v("Just",{x:c._2.x,y:c._2.y,w:c._2.w,h:c._2.h}):T})(Pe(o.nodes)),...(()=>{const c=(f,d)=>{if(f.tag==="Leaf")return d;if(f.tag==="Node")return c(f._5,qt("Cons",f._4,c(f._6,d)));g()};return Ct($t.foldr,c(a,Ht))})()]))))},W_=t=>e=>n=>{const r=Ti(6)(.55)(gu(0)(1)((1-t)/.06)),i=t>.94,o=i&&n>1e-4,u=Ti(6)(.55)(gu(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})()}},IJ=t=>{const e=t.Monad0().Bind1(),n=Q_(t);return r=>i=>o=>u=>s=>{const a=W_(u)(0)(0),c={family:r.fontFamily,size:11,weight:500},f=du(u)(0)(0)(Tt(s)(la));return e.bind(t.measureText(c)(f.line))(d=>{const l=o.x+o.w/2,_=d+28,h=o.y-25.2-14,p=l-_/2,m=[1,l,h+25.2,2,l,o.y],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:we,lineCap:_n})))(()=>e.bind(t.strokePath(m)({color:r.chipHairline,width:1,lineJoin:we,lineCap:_n}))(()=>t.drawText({x:l,y:y.y,content:f.line,font:c,color:r.chipText,align:$r,baseline:or})))))})}},QJ=t=>{const e=Q_(t),n=t.Monad0(),r=n.Bind1(),i=Ze(n.Applicative0()),o=CJ(t);return u=>s=>a=>c=>f=>d=>l=>_=>h=>{const p=du(f)(d)(l)(Tt(_)(la)),m=p.line,y=p.phaseInLabel/.45,x=y<0?0:y>1?1:y,N=h.w,w=h.y,L=h.x,k=L+14,E=h.h,O=w+E/2;return e(W_(f)(d)(l))(L)(w+E)({x:L+N/2,y:O})(r.bind(i(Y=>t.fillPath(ou(Y)(1.5))({color:u.trailDot,flat:!0}))(NJ(h)(A_(s)(a)(c)(f)(d)(l))))(()=>r.bind(t.drawRoundedRect({x:L,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)(k)(O)(m))))}},pa=t=>{const e=QJ(t),n=t.Monad0(),r=n.Applicative0(),i=IJ(t),o=n.Bind1(),u=Ze(r),s=t.popLayer;return a=>c=>f=>d=>o.bind(t.pushLayer(Yx))(()=>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=Rn(l._2._1.edge)(c.edges),m=D_(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 Je(p._1);g()})())(h._1)(_._1)(l._2._1.progress)(l._2._1.holdPre)(l._2._1.holdPost)(l._2._1.labels)(m._1)}return r.pure()}if(l._2.tag==="Filling"&&l._2._1.labels.length!==0){const _=fe(l._2._1.node)(c.nodes);if(_.tag==="Just")return i(a)(c)(_._1)(l._2._1.progress)(l._2._1.labels);if(_.tag==="Nothing")return r.pure();g()}return r.pure()})(Pe(f.tokens)))(()=>s))},q_=t=>{const e=ha(t),n=pa(t);return r=>i=>o=>t.Monad0().Bind1().bind(e(i)(o))(u=>n(r)(i)(o)(u))},FJ=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>i=>{const o=i.length-1|0,u=o<1?[]:bt(0,o,i),s=u.length-1|0,a=s>=0&&s<u.length?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)(qi(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=Le(y*y+m*m),N=m/x,w=-N,L=y/x,k=f._1.x+L*.875,E=f._1.y+N*.875,O=r.wobble?8.75*d.value:8.75,Y=k-L*O,et=E-N*O,G=Y+w*_,P=et+L*_,V=[1,k,E,2,Y+w*4.375,et+L*4.375,2,Y-w*4.375,et-L*4.375,5],U=Y-w*p,B=et-L*p,R={color:r.arrowFill,width:2,lineJoin:we,lineCap:wn};return x<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,G,P,2,k,E])(R))(()=>t.strokePath([1,U,B,2,k,E])(R)):t.fillPath(V)({color:r.arrowFill,flat:!0})}return n.pure()}},AJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=Ze(n),o=t.popAlpha,u=FJ(t);return s=>a=>c=>f=>{const d=zN(8)(c);if(f.hi<=f.lo)return n.pure();const l=UN(d)(f.lo)(f.hi);if(l.length===0)return n.pure();const _={color:s.edge,width:s.wobble?2:.9375,lineJoin:we,lineCap:wn},h=s.wobble?ae(-10)(4)(qi(l)).value:0,p=s.wobble?oJ(h)(l):l;return r.bind(s.wobble?i(m=>r.bind(t.pushAlpha(m.alpha))(()=>r.bind(t.strokePath(m.path)(_))(()=>o)))((()=>{const m=qi(l);return p.length<2?[]:Vr(TJ)(m)(!1)(p)})()):t.strokePath(MN(l))(_))(()=>{const m=u(s)(p);return f.hi>=.999?m:n.pure()})}},H_=t=>{const e=AJ(t),n=t.Monad0().Applicative0(),r=Ze(n);return i=>o=>u=>{const s=a=>{const c=Vt(f=>a.x>=f._2.x-1&&a.x<=f._2.x+f._2.w+1&&a.y>=f._2.y-1&&a.y<=f._2.y+f._2.h+1)(Pe(o.nodes));return c.tag==="Just"?v("Just",c._1._2):T};return r(a=>{const c=Rn(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 Je(w_(Jr(7)(l._1))(Je(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 w_(Jr(7)(l._1))(f)}return f})())((()=>{if(c._1.tag==="Retracted")return{lo:0,hi:0};if(c._1.tag==="Extended")return{lo:0,hi:1};if(c._1.tag==="Extending")return{lo:0,hi:c._1._2};if(c._1.tag==="Retracting"){if(c._1._1==="FromSource")return{lo:c._1._2,hi:1};if(c._1._1==="FromTarget")return{lo:0,hi:1-c._1._2};if(c._1._1==="FromBoth")return{lo:c._1._2/2,hi:1-c._1._2/2}}g()})());if(c.tag==="Nothing")return n.pure();g()})(Pe(o.edges))}},MJ=t=>e=>{const n=o=>{const u=fe(o)(t.nodes);if(u.tag==="Nothing")return!1;if(u.tag==="Just"){const s=u._1;return!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,Pe(t.edges))}g()},r=J(o=>u=>(o*31|0)+Dn(u)|0)(5381)(Zn(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},Pe(t.edges))}g()};return J(o=>u=>{const s=u._2;return dJ(a=>{if(a.tag==="Nothing")return v("Just",s);if(a.tag==="Just")return v("Just",{t:Hi(a._1.t)(s.t),angle:s.t>=a._1.t?s.angle:a._1.angle,bigCircle:a._1.bigCircle||s.bigCircle,frameHash:a._1.frameHash});g()})(u._1)(o)})(Q)(Tt(Pe(e.tokens))(o=>{if(o._2.tag==="Filling"){const u=o._2._1.node;return[b(u,{t:1,angle:(()=>{const s=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)(Pe(t.edges));if(0<s.length){const a=s[0].length-1|0,c=a<1?[]:bt(0,a,s[0]),f=c.length-1|0;if(f>=0&&f<c.length){const d=s[0].length-1|0;return d>=0&&d<s[0].length?fr(s[0][d].y-c[f].y)(s[0][d].x-c[f].x):0}s[0].length-1|0}return 0})(),bigCircle:n(u)||i(u),frameHash:r})]}if(o._2.tag==="Travelling"){if(o._2._1.progress>=.75)return[b(o._2._1.target,{t:(o._2._1.progress-.75)/.25,angle:(()=>{const u=Rn(o._2._1.edge)(t.edges);if(u.tag==="Just"){const s=u._1.length-1|0,a=s<1?[]:bt(0,s,u._1),c=a.length-1|0;if(c>=0&&c<a.length){const f=u._1.length-1|0;return f>=0&&f<u._1.length?fr(u._1[f].y-a[c].y)(u._1[f].x-a[c].x):0}return u._1.length-1|0,0}if(u.tag==="Nothing")return 0;g()})(),bigCircle:n(o._2._1.target)||i(o._2._1.target),frameHash:r})];if(o._2._1.progress<.25)return[b(o._2._1.source,{t:o._2._1.progress/.25,angle:(()=>{const u=Rn(o._2._1.edge)(t.edges);if(u.tag==="Just")return 1<u._1.length&&0<u._1.length?fr(u._1[1].y-u._1[0].y)(u._1[1].x-u._1[0].x):0;if(u.tag==="Nothing")return 0;g()})(),bigCircle:n(o._2._1.source)||i(o._2._1.source),frameHash:r})]}return[]}))},OJ=t=>J(e=>n=>(e*31|0)+Dn(n)|0)(5381)(Zn(t.frameTitle)),$_=t=>{const e=O_(t),n=t.Monad0().Applicative0(),r=Ze(n);return i=>o=>u=>s=>{const a=OJ(s),c=MJ(u)(s);return r(f=>{const d=fe(f._1)(s.nodes);if(d.tag==="Just")return e(i)(o)((()=>{const l=fe(f._1)(s.nodeFadeAlpha);if(l.tag==="Nothing")return 1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=fe(f._1)(c);return l.tag==="Just"?v("Just",l._1):l.tag==="Nothing"&&lJ(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()})(Pe(u.nodes))}},X_=t=>t,Y_=t=>e=>{const n=e.vw/e.vh,r=e.vh*t,i={...e,vx:e.vx-(r-e.vw)/2,vw:r},o=e.vw/t,u={...e,vy:e.vy-(o-e.vh)/2,vh:o};return t<=0||e.vw<=0||e.vh<=0?e:t>n?i:t<n?u:e},RJ=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},V_=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()},U_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ma=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},BJ=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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},zJ=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},WJ=t=>e=>{const n=He(t.angle),r=en(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},qJ=t=>[t.box.ground.a,t.box.ground.b,t.box.ground.c,t.box.ground.d,t.box.top.a,t.box.top.b,t.box.top.c,t.box.top.d],Ur=t=>e=>{const n=r=>RJ(0)(255)(de(Vn(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)*en(t.angle),y:(e+n)*He(t.angle)-r}),wr=t=>{const e=Mt(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()},HJ=t=>e=>n=>r=>i=>{const o=(()=>{if(t==="Forward")return i;if(t==="Backward")return Je(i);g()})();if(0<o.length){const s=mr(o)(V_(0)(1)(Xr(n)(r)(e)));if(s.tag==="Nothing")return o[0];if(s.tag==="Just")return s._1;g()}const u=mr(o)(V_(0)(1)(Xr(n)(r)(e)));if(u.tag==="Nothing")return{x:0,y:0};if(u.tag==="Just")return u._1;g()},$J=t=>{const e=Mt(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()},XJ=t=>{const e=Mt(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:U_(r.minX)(i.x),minY:U_(r.minY)(i.y),maxX:ma(r.maxX)(i.x),maxY:ma(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{vx:n.minX-40,vy:n.minY-40,vw:n.maxX-n.minX+80,vh:n.maxY-n.minY+80}}g()},YJ=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>{const o=i.box,u=i.np,s={color:r.nodeStroke,width:1,lineJoin:we,lineCap:_n};return e.bind(t.fillStrokePath(wr([o.ground.d,o.ground.c,o.top.c,o.top.d]))({color:Ur(.66)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(wr([o.ground.b,o.ground.c,o.top.c,o.top.b]))({color:Ur(.82)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(wr([o.top.a,o.top.b,o.top.c,o.top.d]))({color:Ur(1)(r.nodeFill),flat:!0})(s))(()=>t.drawTextAffine(WJ(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:$r,baseline:or}))))}},VJ=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>o=>{const u={color:r.tokenOutsideStroke,width:1,lineJoin:we,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(wr([Ce(n)(s)(f)(i),m,h,p]))({color:Ur(.66)(r.tokenOutsideFill),flat:!0})(u))(()=>e.bind(t.fillStrokePath(wr([y,m,h,_]))({color:Ur(.82)(r.tokenOutsideFill),flat:!0})(u))(()=>t.fillStrokePath(wr([l,_,h,p]))({color:Ur(1)(r.tokenOutsideFill),flat:!0})(u)))}},UJ=t=>{const e=VJ(t);return n=>r=>i=>o=>{if(o.tag==="Travelling"){const u=BJ(o._1.edge)(i.edges);return u.tag==="Just"?v("Just",(()=>{const s=HJ(o._1.direction)(o._1.progress)(o._1.holdPre)(o._1.holdPost)(u._1);return{depth:s.x+s.y,draw:e(n)(r)(0)(s)}})()):T}if(o.tag==="Filling"){const u=zJ(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}},ZJ={angle:.5235987755982988,boxHeight:26,transparentBg:!0},KJ=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:Ce(t)(e.x)(e.y)(0),b:Ce(t)(r)(e.y)(0),c:Ce(t)(r)(n)(0),d:Ce(t)(e.x)(n)(0)},top:{a:Ce(t)(e.x)(e.y)(t.boxHeight),b:Ce(t)(r)(e.y)(t.boxHeight),c:Ce(t)(r)(n)(t.boxHeight),d:Ce(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},Z_=t=>e=>W(n=>({np:n,box:KJ(t)(n)}))((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Ct($t.foldr,n(e.nodes,Ht))})()),jJ=t=>e=>[...Tt(Z_(t)(e))(qJ),...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._4,n(r._6,i)));g()};return Tt(Ct($t.foldr,n(e.edges,Ht)))(W(r=>Ce(t)(r.x)(r.y)(0)))})()],tT=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=ma(1e-4)(Le(n*n+e*e)),i=e/r,o=n/r,u=t.to.y-i*7,s=t.to.x-o*7;return wr([t.to,{x:s-i*3,y:u+o*3},{x:s+i*3,y:u-o*3}])},eT=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>i=>o=>u=>s=>{const a=Ce(r)(s.x)(s.y)(0),c=Ce(r)(u.x)(u.y)(0);return e.Bind1().bind(t.strokePath($J([c,a]))({color:i.edge,width:1.5,lineJoin:we,lineCap:wn}))(()=>{const f=t.fillPath(tT({from:c,to:a}))({color:i.arrowFill,flat:!0});return o?f:n.pure()})}},nT=t=>{const e=eT(t);return n=>r=>i=>{const o=Te(Cn,i,bt(1,i.length,i)),u=o.length-1|0;return Ft(s=>a=>({depth:(a._1.x+a._1.y+a._2.x+a._2.y)/2,draw:e(n)(r)(s===u)(a._1)(a._2)}))(o)}},rT=t=>{const e=YJ(t),n=UJ(t),r=nT(t),i=t.Monad0(),o=R_(t),u=bu(i.Applicative0())(zt);return s=>a=>c=>f=>{const d=_a(a),l=[...(()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,qt("Cons",h._4,_(h._6,p)));g()};return Tt(Ct($t.foldr,_(c.edges,Ht)))(r(s)(d))})(),...W(_=>({depth:_.box.depth,draw:e(s)(d)(_)}))(Z_(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)(XJ(jJ(s)(c))))(()=>u(_=>_.draw)(Lt(_=>h=>ut.compare(_.depth)(h.depth))(l)))}},K_=(t,e)=>({tag:t,_1:e}),iT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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},oT=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},uT=K_("ResolvedLabels"),sT=t=>{const e=Vt(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return So(t);g()},aT=t=>e=>n=>{const r=n.frameTitle===""?0:40,i=ju(e)(n.camera);return(()=>{if(t.outputAspect.tag==="Nothing")return X_;if(t.outputAspect.tag==="Just")return Y_(t.outputAspect._1);g()})()({vx:i.x-t.padding,vy:i.y-t.padding-r,vw:i.w+2*t.padding,vh:i.h+2*t.padding+r})},cT=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=iT(e._1)(t.segment.layout.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1.x*t.segment.placement.scale+t.segment.placement.tx,i=n._1.y*t.segment.placement.scale+t.segment.placement.ty,o=n._1.w*t.segment.placement.scale,u=n._1.h*t.segment.placement.scale;return[1,r,i,2,r+o,i,2,r+o,i+u,2,r,i+u,5]}}g()},gT=t=>{const e=t.Monad0(),n=e.Bind1();return r=>i=>{if(r==="")return e.Applicative0().pure();const o=i.vh/720,u=56*o,s={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:700};return n.bind(t.measureText(s)(r))(a=>{const c=u+16*o*2,f=a+28*o*2,d=i.vy+i.vh/2,l=i.vx+i.vw/2;return n.bind(t.drawRoundedRect({x:l-f/2,y:d-c/2,w:f,h:c})(16*o)(v("Just",{color:{r:255,g:255,b:255,a:235},flat:!0}))(v("Just",{color:{r:0,g:0,b:0,a:255},width:1.5*o,lineJoin:we,lineCap:wn})))(()=>t.drawText({x:l,y:d,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:$r,baseline:or}))})}},fT=t=>{const e=t.Monad0(),n=e.Bind1();return r=>i=>{if(r==="")return e.Applicative0().pure();const o=i.vh/720,u=15*o,s={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:600};return n.bind(t.measureText(s)(r))(a=>{const c=i.vy+12*o,f=u+6*o*2,d=a+11*o*2,l=i.vx+i.vw/2;return n.bind(t.drawRoundedRect({x:l-d/2,y:c,w:d,h:f})(f/2)(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:we,lineCap:wn})))(()=>t.drawText({x:l,y:c+f/2,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:$r,baseline:or}))})}},_T=t=>{const e=q_(t),n=pa(t),r=t.Monad0(),i=r.Bind1(),o=R_(t),u=r.Applicative0(),s=H_(t),a=$_(t)(fa),c=bJ(t),f=z_(t),d=B_(t),l=kJ(t),_=gT(t),h=fT(t);return p=>m=>y=>x=>N=>w=>L=>{const k=_a(p.theme),E=(()=>{if(L.tag==="ResolvedLabels")return e(k)(N)(w);if(L.tag==="SpringLabels")return n(k)(N)(w)(L._1);g()})();return i.bind(o(k)(p.transparentBg)(m)(x))(()=>i.bind((()=>{const O=i.bind(s(k)(N)(w))(()=>i.bind(a(k)(N)(w))(()=>i.bind(c(k)(N)(w))(()=>i.bind(f(k)(x)(N)(w))(()=>i.bind(d(jx)(k)(N)(w))(()=>i.bind(E)(()=>{const Y=l(k)(N)(w);return w.staticKind!=="Animated"?Y:u.pure()}))))));return y?O:u.pure()})())(()=>i.bind(p.watermark===""?t.Monad0().Applicative0().pure():t.drawText({x:x.vx+6,y:x.vy+6,content:p.watermark,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:na,baseline:qx}))(()=>w.staticKind==="TitleCard"?_(w.frameTitle)(x):h(w.frameTitle)(x))))}},dT=t=>{const e=t.Monad0(),n=q_(t),r=pa(t),i=e.Bind1(),o=H_(t),u=$_(t),s=z_(t),a=t.popTransform,c=B_(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=_a(_.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},O=11*y.segment.placement.scale*h>=5?fa:hJ,Y=(()=>{if(O==="LabelsHidden")return e.Applicative0().pure();if(O==="LabelsShown")return p.tag==="Leaf"?n(w)(L)(x):r(w)(L)(x)(p);g()})(),et=cT(m)((()=>{const G=y.segment.path.length-1|0;return G>=0&&G<y.segment.path.length?v("Just",y.segment.path[G]):T})());return i.bind(t.pushAlpha(y.bgAlpha))(()=>i.bind(t.pushClip(et)(eu))(()=>i.bind(t.pushTransform(N))(()=>i.bind(o(w)(L)(x))(()=>i.bind(u(O)(w)(L)(x))(()=>i.bind(s(w)(E)(L)(x))(()=>i.bind(a)(()=>i.bind(t.pushBakedTransform(N))(()=>i.bind(c(tN)(w)(L)(x))(()=>i.bind(f)(()=>i.bind(t.pushTransform(N))(()=>i.bind(Y)(()=>i.bind(a)(()=>i.bind(d)(()=>l))))))))))))))}},lT=t=>e=>{const n=ju(t)(e);return{vx:n.x,vy:n.y,vw:n.w,vh:n.h}},Zr=t=>e=>e.diving||e.levels.length>1?(()=>{if(t.outputAspect.tag==="Nothing")return X_;if(t.outputAspect.tag==="Just")return Y_(t.outputAspect._1);g()})()(lT(e.rootLayout)(e.camera)):aT(t)(e.rootLayout)({...So(e).state,camera:e.camera}),j_=t=>{const e=rT(t),n=t.Monad0(),r=n.Applicative0(),i=n.Bind1(),o=dT(t),u=_T(t);return s=>a=>c=>{if(s.theme==="Isometric")return e({...ZJ,transparentBg:s.transparentBg})(s.theme)(So(c).segment.layout)(So(c).state);const f=Zr(s)(c),d=_=>h=>{if(h.length===0)return r.pure();const p=Mt(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=Mt(_=>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/oT(1)(Ye(c.rootLayout).w):1)(h.role==="Active"||h.role==="FlyThrough")(f)(h.segment.layout)(sT(c).state)(_.length===0&&a.tag!=="Leaf"?K_("SpringLabels",a):uT))(()=>d(h)(_))}g()}},t1=t=>e=>n=>{const r=ut.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=ut.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},hT=ha(__),e1=j_(__),n1=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 Wt("Node",u._1,u._2,u._3,{...u._4,x:t1(r)(e-u._4.w)(u._4.x),y:t1(i)(n-u._4.h)(u._4.y)},o(u._5),o(u._6));g()};return o},pT=t=>e=>n=>r=>i=>o=>u=>{const s={padding:8,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?T:v("Just",r.width/r.height)},a=lN(n)(r);return()=>{const c=a(),f=i.levels.length-1|0;if(f>=0&&f<i.levels.length){const l=hT(i.levels[f].segment.layout)(i.levels[f].state)(c)(),_=ta(o)(n1(Zr(s)(i))(l))(u);return e1(s)(_.applied)(i)(c)(),_.springs}const d=ta(o)(n1(Zr(s)(i))(Q))(u);return e1(s)(d.applied)(i)(c)(),d.springs}},mT=t=>t,$i=t=>t,ya=$i("Light"),yT=$i("Dark"),xT=$i("Blueprint"),NT=$i("Whiteboard"),JT=$i("Isometric"),TT=mT("TransparentBackground"),ur=t=>"rgb("+oe(t.r)+","+oe(t.g)+","+oe(t.b)+")",kn=ci(si("Fixed",ai(0)(20)(4))),wT=t=>"translate("+kn(t.tx)+","+kn(t.ty)+") scale("+kn(t.sx)+","+kn(t.sy)+")",kt=ci(si("Fixed",ai(0)(20)(2))),xa=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(kt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===2){e.push("L"),e.push(kt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===3){e.push("Q"),e.push(kt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),n=r+5|0;continue}if(i._1===4){e.push("C"),e.push(kt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+5|0;return o>=0&&o<t.length?t[o]:0})())),e.push(kt((()=>{const o=r+6|0;return o>=0&&o<t.length?t[o]:0})())),n=r+7|0;continue}if(i._1===5){e.push("Z"),n=r+1|0;continue}n=t.length;continue}g()}return xo(" ")(e)},vT={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},Na=(()=>{const t=tr("&")("&"),e=tr("<")("<"),n=(()=>{const r=tr(">")(">"),i=(()=>{const o=tr('"')(""");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),bT=t=>{if(t.style==="RunText")return"<tspan>"+Na(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+Na(t.text)+"</tspan>";g()},Fe=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},kT=t=>e=>{const n=[];let r=0;const i=o=>{const u=o>=0&&o<e.length?t.sx*e[o]+t.tx:t.sx*0+t.tx;return()=>{n.push(u),n.push((()=>{const s=o+1|0;return s>=0&&s<e.length?t.sy*e[s]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const o=r,u=o>=0&&o<e.length?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},lu=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return kT(r._1)(e);g()}},r1={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>vT},LT={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>r1},ET={pure:t=>e=>()=>t,Apply0:()=>r1},CT={Applicative0:()=>ET,Bind1:()=>LT},ST=t=>e=>'<defs><pattern id="'+t+'" x="0" y="0" width="'+kt(e.tile)+'" height="'+kt(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+kt(e.tile)+'" height="'+kt(e.tile)+'" fill="'+ur(e.bgColor)+'" fill-opacity="'+kt(rt(e.bgColor.a)/255)+'"/>')+'<circle cx="'+kt(e.tile/2)+'" cy="'+kt(e.tile/2)+'" r="'+kt(e.dotRadius)+'" fill="'+ur(e.dotColor)+'"/></pattern></defs><rect x="'+kt(e.viewport.vx)+'" y="'+kt(e.viewport.vy)+'" width="'+kt(e.viewport.vw)+'" height="'+kt(e.viewport.vh)+'" fill="url(#'+t+')"/>',i1=t=>e=>'<path d="'+xa(t)+'" fill="'+ur(e)+'" fill-opacity="'+kt(rt(e.a)/255)+'"/>',GT=t=>e=>n=>r=>'<rect x="'+kt(t.x)+'" y="'+kt(t.y)+'" width="'+kt(t.w)+'" height="'+kt(t.h)+'" rx="'+kt(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+ur(n._1.color)+'" fill-opacity="'+kt(rt(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';g()})()+(()=>{if(r.tag==="Just")return' stroke="'+ur(r._1.color)+'" stroke-opacity="'+kt(rt(r._1.color.a)/255)+'" stroke-width="'+kt(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";g()})()+'"';if(r.tag==="Nothing")return"";g()})()+"/>",o1=t=>e=>'<path d="'+xa(t)+'" fill="none" stroke="'+ur(e.color)+'" stroke-opacity="'+kt(rt(e.color.a)/255)+'" stroke-width="'+kt(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";g()})()+'"/>',u1=t=>{const e=fg(Ar(t.content));return'<text x="'+kt(t.x)+'" y="'+kt(t.y)+'"'+(()=>{if(t.baseline==="BaselineTop")return' dy="0.8em"';if(t.baseline==="BaselineMiddle")return' dy="0.32em"';if(t.baseline==="BaselineAlphabetic"||t.baseline==="BaselineBottom")return"";g()})()+' fill="'+ur(t.color)+'" fill-opacity="'+kt(rt(t.color.a)/255)+'" font-size="'+kt(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+oe(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";g()})()+'">'+(e.length===1&&e[0].style==="RunText"?Na(e[0].text):xo("")(W(bT)(e)))+"</text>"},PT=t=>"matrix("+kn(t.a)+" "+kn(t.b)+" "+kn(t.c)+" "+kn(t.d)+" "+kn(t.e)+" "+kn(t.f)+")",s1={fillPath:t=>e=>n=>{const r=lu(n)(t);return()=>{const i=r();return Fe(i1(i)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=lu(n)(t);return()=>{const i=r(),o=n.bake.value;return Fe(o1(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=lu(r)(t);return()=>{const o=i(),u=r.bake.value;return Fe(i1(o)(e.color)+o1(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 Fe(GT((()=>{if(u.tag==="Nothing")return t;if(u.tag==="Just")return{x:u._1.sx*t.x+u._1.tx,y:u._1.sy*t.y+u._1.ty,w:u._1.sx*t.w,h:u._1.sy*t.h};g()})())((()=>{if(u.tag==="Nothing")return e;if(u.tag==="Just")return u._1.sx*e;g()})())(n)(r.tag==="Just"?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 Fe(u1((()=>{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=>Fe((()=>{const n='transform="'+PT(t)+'"';return(n===""?"<g>":"<g "+n+">")+u1(e)+"</g>"})()),pushTransform:t=>Fe((()=>{const e='transform="'+wT(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:Fe("</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=lu(n)(t)(),u="clip"+oe(i);return Fe((()=>{const s='clip-path="url(#'+u+')"';return'<defs><clipPath id="'+u+'"><path d="'+xa(o)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";g()})()+"/></clipPath></defs>"+(s===""?"<g>":"<g "+s+">")})())(n)()}},popClip:Fe("</g>"),pushBlend:t=>Fe((()=>{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:Fe("</g>"),pushAlpha:t=>Fe((()=>{const e='opacity="'+kt(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:Fe("</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=>Fe('<rect x="'+kt(e.viewport.vx)+'" y="'+kt(e.viewport.vy)+'" width="'+kt(e.viewport.vw)+'" height="'+kt(e.viewport.vh)+'" fill="'+ur(t)+'" opacity="'+kt(rt(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,Fe(ST("bg-dots-"+oe(r))(t))(e)()}},measureText:t=>e=>n=>{const r=zf(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Wf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Kf,Monad0:()=>CT},DT=j_(s1),IT=ha(s1),QT=t=>e=>n=>r=>i=>{const o={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:n,outputAspect:t},u=Zr(o)(i);return{viewBox:kt(u.vx)+" "+kt(u.vy)+" "+kt(u.vw)+" "+kt(u.vh),body:(()=>{const s=[],a={value:0},c={value:0},f={value:0},d={value:T};return DT(o)(e)(i)({out:s,maskDepth:a,clipCounter:c,patternCounter:f,viewport:u,bake:d})(),xo("")(s)})(),vx:u.vx,vy:u.vy,vw:u.vw,vh:u.vh}},FT=t=>e=>n=>r=>i=>o=>{const u={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;g()})(),outputAspect:t},s=ta(i)((()=>{const a=[],c={value:0},f={value:0},d={value:0},l={value:T},_=r.levels.length-1|0;return _>=0&&_<r.levels.length?IT(r.levels[_].segment.layout)(r.levels[_].state)({out:a,maskDepth:c,clipCounter:f,patternCounter:d,viewport:Zr(u)(r),bake:l})():Q})())(o);return{parts:QT(t)(s.applied)(e)(n)(r),springs:s.springs}},Xi=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(i=>n(i._1)(i._2)),Apply0:()=>a1(t)}),a1=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=Xi(t);return i=>o=>r.bind(i)(u=>r.bind(o)(s=>Yi(t).pure(u(s))))})(),Functor0:()=>n}},Yi=t=>({pure:e=>n=>t.Applicative0().pure(b(e,n)),Apply0:()=>a1(t)}),AT=t=>{const e={Applicative0:()=>Yi(t),Bind1:()=>Xi(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},Ja=(t,e)=>({tag:t,_1:e}),Ta=t=>t,Bn=(t,e)=>({tag:t,_1:e}),ye=AT($n),At=Xi($n),De=ye.state(t=>b(t,t)),te=Yi($n),zn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},c1=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},hu=bu(te)(zt),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},MT=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},OT=(()=>{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)})())})(),RT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},pu=t=>e=>n=>J(r=>i=>t.Bind1().bind(r)(o=>e(o)(i)))(t.Applicative0().pure(n)),BT=J(t=>e=>j(C)(e)()(t))(Q),zT=(()=>{const t=(e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=j(C)(a._1)()(s),i=a._2;continue}g()}return u})(Q);return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,qt("Cons",r._3,n(r._6,i)));g()};return n(e,Ht)})())})(),WT=Bn("Exit"),qT=Ta("AnimatedKeyframe"),HT=Ta("Still"),$T=Ta("Title"),XT=t=>Ja("Par",t),g1=t=>Ja("Seq",t),YT=t=>e=>n=>{const r=cr(Xt,T,i=>i._1===t,n);if(r.tag==="Just"){const i=Xn(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 Ot(n)(b(t,e));g()},VT=t=>e=>W(n=>n._1===t?b(n._1,{...n._2,label:v("Just",e)}):b(n._1,n._2)),ve=t=>ye.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()})())),UT=t=>At.bind(ye.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>At.bind(De)(e=>{if(e.error.tag==="Just")return te.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!zn(t.op._1.id)(e.currNodes))return ve("cannot enter node "+t.op._1.id+": does not exist");if(!c1(t.op._1.id)(e.interiorOf))return ve("cannot enter node "+t.op._1.id+": it has no `inside` block");if(Be(fn)(t.op._1.id)(e.enterStack))return ve("cannot enter node "+t.op._1.id+": already entered");const n=t.op._1;return ye.state(r=>b(void 0,{...r,enterStack:Ot(r.enterStack)(n.id),scenes:Ot(r.scenes)(mi("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=ii(e.enterStack);if(n.tag==="Nothing")return ve("`exit` without a matching `enter`");if(n.tag==="Just"){const r=n._1.init;return ye.state(i=>b(void 0,{...i,enterStack:r,scenes:Ot(i.scenes)(ql)}))}g()}return te.pure()}g()})),ZT=t=>At.bind(De)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+oe(e.kfCounter);if(Re(i=>i.id===n,e.keyframes))return ve("duplicate frame name "+n);const r={...e,keyframes:Ot(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges,kind:yi}),kfCounter:e.kfCounter+1|0,currentKf:v("Just",n)};return ye.state(i=>b(void 0,r))}),KT=hu(t=>At.bind(De)(e=>{if(e.error.tag==="Just")return te.pure();if(e.error.tag==="Nothing")return c1(t.node)(e.interiorOf)?ve("node "+t.node+" has more than one `inside` block"):ye.state(n=>b(void 0,{...n,interiorOf:j(C)(t.node)(t.doc)(n.interiorOf)}));g()})),jT=t=>e=>{const n=e.from+"->"+e.to,r=e.newFrom+"->"+e.newTo,i=Pt("Left","cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist"),o=Wn(n)(t.currEdges)?Pt("Right",void 0):i;return(()=>{if(o.tag==="Left"){const u=o._1;return s=>Pt("Left",u)}if(o.tag==="Right"){const u=o._1;return s=>s(u)}g()})()(()=>{const u="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newFrom;if(!zn(e.newFrom)(t.currNodes))return Pt("Left",u);const s="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo;if(!zn(e.newTo)(t.currNodes))return Pt("Left",s);const a="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists";return n!==r&&Wn(r)(t.currEdges)?Pt("Left",a):Pt("Right",{nextCurrEdges:j(C)(r)()(ui(C)(n)(t.currEdges)),newId:r,newEdge:{id:r,from:{node:e.newFrom,port:T},to:{node:e.newTo,port:T},label:T}})})},f1={graphNodes:[],graphEdges:Q,currNodes:Q,currEdges:Q,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:T,currentLine:0,currentColumn:0,error:T,enterStack:[],interiorOf:Q},tw=At.bind(De)(t=>{if(t.error.tag==="Just")return te.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return ye.state(n=>b(void 0,{...n,scenes:Ot(n.scenes)(mi("Hold",e))}))}if(t.currentKf.tag==="Nothing")return te.pure()}g()}),_1=t=>e=>At.bind(De)(n=>{const r="ev-"+oe(n.eventCounter);return At.bind((()=>{const i={...n,eventCounter:n.eventCounter+1|0};return ye.state(o=>b(void 0,i))})())(()=>te.pure({events:[{id:r,kind:e,when:t}],firstId:v("Just",r),lastId:v("Just",r)}))}),ew=t=>e=>{if(e.tag==="Token"){const n=e._1;return At.bind(De)(r=>{const i=!zn(n.from)(r.currNodes),o=!zn(n.to)(r.currNodes);if(i||o)return At.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: "))(()=>te.pure({events:[],firstId:T,lastId:T}));const u=n.to+"->"+n.from,s=n.from+"->"+n.to;return Wn(s)(r.currEdges)?_1(t)(vc("SendToken",{from:n.from,to:n.to,edge:s,direction:zl,labels:n.labels})):Wn(u)(r.currEdges)?_1(t)(vc("SendToken",{from:n.from,to:n.to,edge:u,direction:Wl,labels:n.labels})):At.bind(ve("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>te.pure({events:[],firstId:T,lastId:T}))})}return te.pure({events:[],firstId:T,lastId:T})},nw=t=>e=>{if(0<t.length){const n=t[0];return At.bind(ye.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>ve(e))}return ve(e)},rw=t=>xt(e=>MT(e)(t.graphEdges))(Ct(ni,OT(t.currEdges))),iw=t=>e=>{const n=st(i=>i.from.node===e.id||i.to.node===e.id,rw(t)),r=pu(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(!Wn(u)(t.currEdges))return Pt("Left",c);const f="via "+o.from+" "+o.to+": no edge "+e.id+"\u2192"+o.to;if(!Wn(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 Wn(a)(t.currEdges)||RT(a)(i.synthesized)?Pt("Left",d):Pt("Right",{consumed:j(C)(u)()(j(C)(s)()(i.consumed)),synthesized:j(C)(a)({id:a,from:{node:o.from,port:T},to:{node:o.to,port:T},label: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=>!Wn(s.id)(o),n);return u.length===0?Pt("Right",{nextCurrEdges:Ee(C.compare,ke,Sn(C.compare,t.currEdges,BT(W(s=>s.id)(n))),zT((()=>{const s=a=>{if(a.tag==="Leaf")return Q;if(a.tag==="Node")return Wt("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 ("+xo(", ")(W(s=>s.from.node+"\u2192"+s.to.node)(u))+"). Use -edge to drop them or `via a b` to merge "+e.id+"'s endpoints.")})},wa=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq")return Tt(t._1)(wa);g()},ow=At.bind(De)(t=>{if(t.error.tag==="Just")return te.pure();if(t.error.tag==="Nothing"){const e=t.enterStack.length-1|0;return e>=0&&e<t.enterStack.length?ve("entered node "+t.enterStack[e]+" was never exited"):te.pure()}g()}),uw=t=>({nodes:W(ji)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,qt("Cons",n._4,e(n._6,r)));g()};return Ct($t.foldr,e(t.graphEdges,Ht))})(),constraints:[]}),sw=t=>{if(t.tag==="AddNode"){const e=t._1;return ye.state(n=>b(void 0,{...n,graphNodes:YT(e.id)({id:e.id,size:b(1,1),ports:[],label:v("Just",e.label),shape:e.shape})(n.graphNodes),currNodes:j(C)(e.id)()(n.currNodes)}))}if(t.tag==="DelNode"){const e=t._1;return At.bind(De)(n=>{if(!zn(e.id)(n.currNodes))return ve("cannot delete node "+e.id+": does not exist");const r=iw(n)(e);if(r.tag==="Left")return ve(r._1);if(r.tag==="Right"){const i=r._1;return ye.state(o=>b(void 0,{...o,currNodes:ui(C)(e.id)(o.currNodes),currEdges:i.nextCurrEdges,graphEdges:Ee(C.compare,ke,i.synthesized,o.graphEdges)}))}g()})}if(t.tag==="ModNode"){const e=t._1;return At.bind(De)(n=>{if(!zn(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 ye.state(i=>b(void 0,{...i,graphNodes:VT(e.id)(r)(i.graphNodes)}))}if(e.label.tag==="Nothing")return te.pure();g()})}if(t.tag==="AddEdge"){const e=t._1;return At.bind(De)(n=>{const r=!zn(e.from)(n.currNodes),i=!zn(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 ye.state(u=>b(void 0,{...u,graphEdges:j(C)(o)({id:o,from:{node:e.from,port:T},to:{node:e.to,port:T},label:e.label})(u.graphEdges),currEdges:j(C)(o)()(u.currEdges)}))})}if(t.tag==="DelEdge"){const e=t._1;return At.bind(De)(n=>{const r=e.from+"->"+e.to;return Wn(r)(n.currEdges)?ye.state(i=>b(void 0,{...i,currEdges:ui(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 At.bind(De)(n=>{const r=jT(n)(e);if(r.tag==="Left")return ve(r._1);if(r.tag==="Right"){const i=r._1;return ye.state(o=>b(void 0,{...o,currEdges:i.nextCurrEdges,graphEdges:j(C)(i.newId)(i.newEdge)(o.graphEdges)}))}g()})}return te.pure()},aw=t=>At.bind(ye.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>sw(t.op)),d1=t=>e=>n=>At.bind(hu(aw)(n))(()=>At.bind(De)(r=>{const i=e.tag==="Just"&&e._1!==""?e._1:"kf-"+oe(r.kfCounter);if(Re(u=>u.id===i,r.keyframes))return ve("duplicate frame name "+i);const o={...r,keyframes:Ot(r.keyframes)({id:i,nodes:r.currNodes,edges:r.currEdges,kind:t}),kfCounter:r.kfCounter+1|0,currentKf:v("Just",i),scenes:(()=>{if(r.currentKf.tag==="Nothing")return r.scenes;if(r.currentKf.tag==="Just")return Ot(r.scenes)(mi("Structural",{from:r.currentKf._1,to:i,focus:T}));g()})()};return ye.state(u=>b(void 0,o))})),l1=t=>e=>{const n=wa(e.ops),r=st(i=>!(i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge"),n);if(0<r.length){const i=r[0];return At.bind(ye.state(o=>b(void 0,{...o,currentLine:i.line,currentColumn:i.column})))(()=>ve("still/title blocks hold a static snapshot; they cannot contain tokens (a -> b) or enter/exit"))}return At.bind(d1(t)(e.name)(st(i=>i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge",n)))(()=>tw)},cw=t=>e=>{const n=Mt(r=>T,r=>i=>v("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return te.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return At.bind(Vi(t)(n._1.head))(i=>At.bind(pu({Applicative0:()=>Yi($n),Bind1:()=>Xi($n)})(o=>u=>At.bind(Vi((()=>{if(o.lastId.tag==="Just")return Zu("After",o.lastId._1);if(o.lastId.tag==="Nothing")return t;g()})())(u))(s=>te.pure({events:[...o.events,...s.events],firstId:(()=>{if(o.firstId.tag==="Just")return 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=>te.pure(o)))}g()},gw=t=>e=>{const n=Mt(r=>T,r=>i=>v("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return te.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return At.bind(Vi(t)(n._1.head))(i=>At.bind(fw((()=>{if(i.firstId.tag==="Just")return Zu("With",i.firstId._1);if(i.firstId.tag==="Nothing")return t;g()})())(r))(o=>te.pure({events:[...i.events,...o.events],firstId:i.firstId,lastId:(()=>{if(i.lastId.tag==="Just")return v("Just",i.lastId._1);if(i.lastId.tag==="Nothing")return o.lastId;g()})()})))}g()},Vi=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return At.bind(ye.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>ew(t)(n.op))}if(e.tag==="Seq")return cw(t)(e._1);if(e.tag==="Par")return gw(t)(e._1);g()},fw=t=>pu({Applicative0:()=>Yi($n),Bind1:()=>Xi($n)})(e=>n=>At.bind(Vi(t)(n))(r=>te.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}),_w=t=>At.bind(De)(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 At.bind(Vi(Bl)(t))(r=>At.bind(De)(i=>{const o={...i,scenes:Ot(i.scenes)(mi("DataFlow",{keyframe:n,events:r.events,focus:T}))};return ye.state(u=>b(void 0,o))}))}g()}),dw=t=>{const e=wa(t.ops),n=st(o=>o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge",e),r=st(o=>o.op.tag==="Enter"||o.op.tag==="Exit",e),i=st(o=>!(o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge")&&!(o.op.tag==="Enter"||o.op.tag==="Exit"),e);return r.length!==0&&i.length!==0?nw(r)("`enter`/`exit` cannot be mixed with flow tokens in the same frame"):At.bind((()=>{const o=d1(yi)(t.name)(n);return n.length!==0?o:te.pure()})())(()=>At.bind((()=>{const o=ZT(t.name);return n.length===0&&i.length!==0?o:te.pure()})())(()=>At.bind((()=>{const o=_w(t.ops);return i.length!==0?o:te.pure()})())(()=>hu(UT)(r))))},lw=t=>At.bind(De)(e=>{if(e.error.tag==="Just")return te.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return dw(t);if(t.kind==="Still")return l1(Ol)(t);if(t.kind==="Title")return l1(Rl)(t)}g()}),h1=t=>At.bind(KT(t.interiors))(()=>At.bind(hu(lw)(t.frames))(()=>At.bind(ow)(()=>At.bind(De)(e=>{if(e.error.tag==="Just")return te.pure(Pt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=hw(t.interiors);if(n.tag==="Left")return te.pure(Pt("Left",n._1));if(n.tag==="Right")return te.pure(Pt("Right",{seed:t.seed,graph:uw(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1}))}g()})))),hw=t=>{const e=pu(qa)(n=>r=>{const i=h1(r.doc)(f1)._1;return(()=>{if(i.tag==="Left"){const o=i._1;return u=>Pt("Left",o)}if(i.tag==="Right"){const o=i._1;return u=>u(o)}g()})()(o=>Pt("Right",j(C)(r.node)(o)(n)))})(Q)(t);if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right")return Pt("Right",e._1);g()},Kr=(t,e)=>({tag:"ParseError",_1:t,_2:e}),F=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),mu=(t,e,n)=>({tag:t,_1:e,_2:n}),pw=t=>mu("More",t),mw=t=>mu("Lift",t),yw={defer:t=>{const e=ml(t);return(n,r,i,o,u)=>yl(e)(n,r,i,o,u)}},p1={map:t=>e=>(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,c)=>r(f=>u(a,t(c)))))},xw={alt:t=>e=>(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>t(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:()=>p1},Nw=t=>{const e=t.Monad0();return n=>r=>{const i=o=>{let u=o,s=!0,a;for(;s;){const c=u();if(c.tag==="More"){u=c._1;continue}if(c.tag==="Lift"){s=!1,a=e.Bind1().Apply0().Functor0().map($a)(c._1);continue}if(c.tag==="Stop"){s=!1,a=e.Applicative0().pure(ei("Done",b(c._2,c._1)));continue}g()}return a};return t.tailRecM(i)(o=>r(n,pw,mw,(u,s)=>mu("Stop",u,Pt("Left",s)),(u,s)=>mu("Stop",u,Pt("Right",s))))}},m1=(t,e,n,r,i)=>i(t,t._2),Jw={index:0,line:1,column:1},Tw=(t=>{const e=Nw(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(to)(e(F(n,Jw,!1))(r))})(H1),y1={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:()=>p1},x1={pure:t=>(e,n,r,i,o)=>o(e,t),Apply0:()=>y1},ww={bind:t=>e=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,c)=>r(f=>e(c)(n._3&&!a._3?F(a._1,a._2,!0):a,r,i,o,u)))),Apply0:()=>y1},vw={Applicative0:()=>x1,Bind1:()=>ww},yu=t=>(e,n,r,i,o)=>n(u=>m1(e,n,r,i,(s,a)=>n(c=>i(e._3&&!s._3?F(s._1,s._2,!0):s,Kr(t,a))))),bw={empty:yu("No alternative"),Alt0:()=>xw},kw={Applicative0:()=>x1,Plus1:()=>bw},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($a)(i))(r.pure(ei("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return ei("Loop",qt("Cons",u._1,o));if(u.tag==="Done")return ei("Done",(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=qt("Cons",h._1,_),f=h._2;continue}g()}return l})(Ht)(o));g()})())))(Ht)})({tailRecM:t=>e=>(n,r,i,o,u)=>{const s=(a,c,f)=>t(c)(a,r,i,o,(d,l)=>{const _=a._3&&!d._3?F(d._1,d._2,!0):d;if(l.tag==="Loop")return f===0?r(h=>s(_,l._1,30)):s(_,l._1,f-1|0);if(l.tag==="Done")return u(_,l._1);g()});return s(n,e,30)},Monad0:()=>vw})(kw),Gt=t=>e=>{const n=yu("Expected "+e);return(r,i,o,u,s)=>{const a=r._1,c=r._2;return i(f=>t(F(a,c,!1),i,o,(d,l)=>{const _=d._3;return i(h=>_?u(d,l):n(r,i,o,u,s))},s))}},va=t=>(e,n,r,i,o)=>{const u=e._3,s=e._1,a=e._2;return n(c=>{const f=(d,l)=>{const _=d._3;return n(h=>_?i(F(d._1,d._2,u),l):o(e,void 0))};return n(d=>n(l=>t(F(s,a,!1),n,r,(_,h)=>f(F(_._1,_._2,!1),h),(_,h)=>n(p=>n(m=>yu("Negated parser succeeded")(_,n,r,f,(y,x)=>n(N=>o(_._3&&!y._3?F(y._1,y._2,!0):y,x))))))))})},Lw=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(F(c,f,!1),o,u,(l,_)=>{const h=l._3;return o(p=>h?s(l,_):r._1(i,o,u,s,a))},a))});g()})(T);return n=>{const r=e(n);if(r.tag==="Nothing")return yu("No alternative");if(r.tag==="Just")return r._1;g()}},Ew=t=>e=>n=>(r,i,o,u,s)=>i(a=>i(c=>i(f=>i(d=>t(r,i,o,u,(l,_)=>i(h=>i(p=>{const m=r._3&&!l._3?F(l._1,l._2,!0):l;return n(m,i,o,u,(y,x)=>i(N=>{const w=m._3&&!y._3?F(y._1,y._2,!0):y;return i(L=>i(k=>{const E=r._3&&!w._3?F(w._1,w._2,!0):w;return e(E,i,o,u,(O,Y)=>i(et=>s(E._3&&!O._3?F(O._1,O._2,!0):O,x)))}))}))}))))))),ba=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=Ph()(n);return r.tag==="Just"&&r._1===10?{index:t.index+1|0,line:t.line,column:t.column}:{index:t.index+1|0,line:t.line+1|0,column:1}}return e===9?{index:t.index+1|0,line:t.line,column:(t.column+8|0)-Un(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},Cw=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,c=i,f=o,d=No(c);if(d.tag==="Nothing"){u=!1,s=a;continue}if(d.tag==="Just"){r=d._1.tail===""?ba(a)(d._1.head)(f):ba(a)(d._1.head)(d._1.tail),i=d._1.tail,o=f;continue}g()}return s},Zt=t=>(e,n,r,i,o)=>{const u=No(e._1);if(u.tag==="Nothing")return i(e,Kr("Unexpected EOF",e._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return i(e,Kr("Expected Char",e._2));if(u._1.head>=0&&u._1.head<=65535){const s=Ic(u._1.head);return t(s)?o(F(u._1.tail,ba(e._2)(u._1.head)(u._1.tail),!0),s):i(e,Kr("Predicate unsatisfied",e._2))}}g()},ka=(t,e,n,r,i)=>t._1===""?i(F(t._1,t._2,!0),void 0):r(t,Kr("Expected EOF",t._2)),Sw=t=>(e,n,r,i,o)=>{const u=t(e._1);if(u.tag==="Left")return i(e,Kr(u._1,e._2));if(u.tag==="Right")return o(F(u._1.remainder,Cw(e._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);g()},jr=t=>Sw(e=>{const n=pl(t)(e);return n.tag==="Just"?Pt("Right",{value:t,consumed:t,remainder:n._1}):Pt("Left","Expected "+D1(t))}),Gw=Zt(t=>!0),N1=(t,e)=>({tag:t,_1:e}),Pw=jt(C)(zt),Dw=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},J1=Lw(zt),T1=(()=>{const t=Zt(e=>e===" "||e===" "||e===`
|
|
9
9
|
`||e==="\r");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?F(s._1,s._2,!0):s,void 0))))})(),La=(t,e,n,r,i)=>e(o=>jr("#")(t,e,n,r,(u,s)=>e(a=>{const c=un(Zt(d=>d!==`
|
|
10
|
-
`)),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>i(f._3&&!l._3?F(l._1,l._2,!0):l,void 0))))}))),
|
|
11
|
-
`||n==="\r");return(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>r(f=>t(F(s,a,!1),r,i,(d,l)=>r(_=>{const h=n._1,p=n._2;return r(m=>r(y=>La(F(h,p,!1),r,i,(x,N)=>{const w=x._3;return r(L=>{if(w)return o(x,N);const k=n._1,E=n._2;return r(O=>r(Y=>e(F(k,E,!1),r,i,(et,G)=>{const P=et._3;return r(V=>P?o(et,G):ka(n,r,i,o,u))},(et,G)=>r(P=>u(et,void 0)))))})},(x,N)=>r(w=>u(x,void 0)))))}),(d,l)=>r(_=>u(F(s,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),Ke=(()=>{const t=un((e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>
|
|
10
|
+
`)),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>i(f._3&&!l._3?F(l._1,l._2,!0):l,void 0))))}))),Iw=Gt((()=>{const t=Gt(Zt(n=>n==="}"))("'}'"),e=Zt(n=>n===`
|
|
11
|
+
`||n==="\r");return(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>r(f=>t(F(s,a,!1),r,i,(d,l)=>r(_=>{const h=n._1,p=n._2;return r(m=>r(y=>La(F(h,p,!1),r,i,(x,N)=>{const w=x._3;return r(L=>{if(w)return o(x,N);const k=n._1,E=n._2;return r(O=>r(Y=>e(F(k,E,!1),r,i,(et,G)=>{const P=et._3;return r(V=>P?o(et,G):ka(n,r,i,o,u))},(et,G)=>r(P=>u(et,void 0)))))})},(x,N)=>r(w=>u(x,void 0)))))}),(d,l)=>r(_=>u(F(s,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),Ke=(()=>{const t=un((e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>T1(F(u,s,!1),n,r,(c,f)=>{const d=c._3;return n(l=>d?i(c,f):La(e,n,r,i,o))},o))});return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?F(s._1,s._2,!0):s,void 0))))})(),gn=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>Ke(t._3&&!c._3?F(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>T1(F(s,a,!1),e,n,(f,d)=>{const l=f._3;return e(_=>l?r(f,d):La(t,e,n,r,u))},u))}),w1=(()=>{const t=Gt(Zt(e=>e==="|"))("'|'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=un(Zt(l=>l!=="|")),d=e._3&&!s._3?F(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(p=>{const m=Gt(Gt(Zt(x=>x==="|"))("'|'"))("closing '|'"),y=d._3&&!_._3?F(_._1,_._2,!0):_;return n(x=>m(y,n,r,i,(N,w)=>n(L=>o(y._3&&!N._3?F(N._1,N._2,!0):N,lr(Ct($t.foldr,h))))))})))})))})(),xu=Zt(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),Ae=(()=>{const t=un(Zt(e=>e===" "||e===" "));return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?F(s._1,s._2,!0):s,void 0))))})(),Qw=(()=>{const t=Gt(Zt(e=>e==="\\"))("'\\\\'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=e._3&&!s._3?F(s._1,s._2,!0):s;return n(d=>Gw(f,n,r,i,(l,_)=>n(h=>o(f._3&&!l._3?F(l._1,l._2,!0):l,_==="n"?`
|
|
12
12
|
`:_==="t"?" ":_==="r"?"\r":_))))})))})(),Fw=(()=>{const t=Zt(e=>e!=='"'&&e!=="\\"&&e!==`
|
|
13
|
-
`);return(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>Qw(F(u,s,!1),n,r,(c,f)=>n(d=>t(e,n,r,i,o)),o))}})(),Ea=(()=>{const t=Gt(Zt(e=>e==='"'))(`'"'`);return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=un(Fw),d=e._3&&!s._3?F(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(p=>{const m=Gt(Gt(Zt(x=>x==='"'))(`'"'`))(`closing '"' (unterminated string)`),y=d._3&&!_._3?F(_._1,_._2,!0):_;return n(x=>m(y,n,r,i,(N,w)=>n(L=>o(y._3&&!N._3?F(N._1,N._2,!0):N,lr(Ct($t.foldr,h))))))})))})))})(),Aw=(()=>{const t=Gt(Zt(e=>e===":"))("':'");return(e,n,r,i,o)=>n(u=>Ae(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 L=N._3;return d(k=>{if(L)return _(N,w);const E=f._1,O=f._2;return d(Y=>
|
|
14
|
-
`&&V!=="\r"&&V!=="#"&&V!=="}")),P=w._3&&!O._3?F(O._1,O._2,!0):O;return d(V=>G(P,d,l,x,(U,B)=>d(R=>h(P._3&&!U._3?F(U._1,U._2,!0):U,Nh(lr(Ct($t.foldr,B)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(e._3&&!s._3?F(s._1,s._2,!0):s,n,r,i,o))))})(),w1=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>T1(F(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):Ea(t,e,n,r,i))},i))},Ui=Zt(t=>t>="0"&&t<="9"),be=(()=>{const t=Gt(Zt(e=>e==="_"))("'_'");return(e,n,r,i,o)=>n(u=>{const s=(f,d)=>n(l=>{const _=un((()=>{const p=Gt(Zt(y=>y==="_"))("'_'"),m=Gt(Zt(y=>y==="-"))("'-'");return(y,x,N,w,L)=>{const k=y._1,E=y._2;return x(O=>xu(F(k,E,!1),x,N,(Y,et)=>{const G=Y._3;return x(P=>{if(G)return w(Y,et);const V=y._1,U=y._2;return x(B=>Ui(F(V,U,!1),x,N,(R,M)=>{const S=R._3;return x(I=>{if(S)return w(R,M);const D=y._1,A=y._2;return x(H=>p(F(D,A,!1),x,N,($,X)=>{const q=$._3;return x(z=>q?w($,X):m(y,x,N,w,L))},L))})},L))})},L))}})()),h=e._3&&!f._3?F(f._1,f._2,!0):f;return n(p=>_(h,n,r,i,(m,y)=>n(x=>o(h._3&&!m._3?F(m._1,m._2,!0):m,co(d)+lr(Ct($t.foldr,y))))))}),a=e._1,c=e._2;return n(f=>xu(F(a,c,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?i(d,l):t(e,n,r,i,s))},s))})})(),Mw=Gt((t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>Ea(F(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):be(t,e,n,r,i))},i))})("frame name (identifier or quoted string)"),v1=(t,e,n,r,i)=>e(o=>Ae(t,e,n,r,(u,s)=>e(a=>{const c=Gt(be)("attribute key"),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=f._3&&!l._3?F(l._1,l._2,!0):l;return e(m=>Ae(p,e,n,r,(y,x)=>e(N=>{const w=Gt(Gt(Zt(k=>k===":"))("':'"))("':'"),L=p._3&&!y._3?F(y._1,y._2,!0):y;return e(k=>w(L,e,n,r,(E,O)=>e(Y=>{const et=L._3&&!E._3?F(E._1,E._2,!0):E;return e(G=>Ae(et,e,n,r,(P,V)=>e(U=>{const B=Gt(be)("attribute value"),R=et._3&&!P._3?F(P._1,P._2,!0):P;return e(M=>B(R,e,n,r,(S,I)=>e(D=>{const A=R._3&&!S._3?F(S._1,S._2,!0):S;return e(H=>Ae(A,e,n,r,($,X)=>e(q=>i(A._3&&!$._3?F($._1,$._2,!0):$,b(_,I)))))})))})))})))})))})))}))),Ow=(t,e,n,r,i)=>e(o=>be(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>Ae(c,e,n,r,(d,l)=>e(_=>{const h=Gt((m,y,x,N,w)=>{const L=m._1,k=m._2;return y(E=>jr("->")(F(L,k,!1),y,x,(O,Y)=>{const et=O._3;return y(G=>et?N(O,Y):jr("<-")(m,y,x,N,w))},w))})("'->' or '<-'"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>Ae(w,e,n,r,(k,E)=>e(O=>{const Y=Gt(be)("target node identifier"),et=w._3&&!k._3?F(k._1,k._2,!0):k;return e(G=>Y(et,e,n,r,(P,V)=>e(U=>{const B=un((M,S,I,D,A)=>{const H=M._3;return S($=>S(X=>Ae(M,S,I,(q,z)=>D(F(q._1,q._2,H),z),(q,z)=>S(tt=>S(Z=>{const ct=M._3&&!q._3?F(q._1,q._2,!0):q;return w1(ct,S,I,(ft,at)=>D(F(ft._1,ft._2,H),at),(ft,at)=>S(yt=>A(ct._3&&!ft._3?F(ft._1,ft._2,!0):ft,at)))})))))}),R=et._3&&!P._3?F(P._1,P._2,!0):P;return e(M=>B(R,e,n,r,(S,I)=>e(D=>(()=>{if(x==="<-"){const H=Bn("Token",{from:V,to:s,labels:W(yc)(Ct($t.foldr,I))});return($,X,q,z,tt)=>tt($,H)}const A=Bn("Token",{from:s,to:V,labels:W(yc)(Ct($t.foldr,I))});return(H,$,X,q,z)=>z(H,A)})()(R._3&&!S._3?F(S._1,S._2,!0):S,e,n,r,i))))})))})))})))})))}))),Rw=(t,e,n,r,i)=>e(o=>Ui(t,e,n,r,(u,s)=>e(a=>{const c=un(Ui),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=Td(co(s)+lr(Ct($t.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(y,x,N,w,L)=>L(y,m)}if(p.tag==="Nothing")return(m,y,x,N,w)=>w(m,0);g()})()(f._3&&!l._3?F(l._1,l._2,!0):l,e,n,r,i)})))}))),Zi=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>jr(t)(e,n,r,(a,c)=>i(F(a._1,a._2,u),c),(a,c)=>n(f=>{const d=va((()=>{const _=Gt(Zt(p=>p==="_"))("'_'"),h=Gt(Zt(p=>p==="-"))("'-'");return(p,m,y,x,N)=>{const w=p._1,L=p._2;return m(k=>xu(F(w,L,!1),m,y,(E,O)=>{const Y=E._3;return m(et=>{if(Y)return x(E,O);const G=p._1,P=p._2;return m(V=>Ui(F(G,P,!1),m,y,(U,B)=>{const R=U._3;return m(M=>{if(R)return x(U,B);const S=p._1,I=p._2;return m(D=>_(F(S,I,!1),m,y,(A,H)=>{const $=A._3;return m(X=>$?x(A,H):h(p,m,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,p)=>i(F(h._1,h._2,u),p),(h,p)=>n(m=>{const y=l._3&&!h._3?F(h._1,h._2,!0):h;return n(x=>Ke(y,n,r,(N,w)=>i(F(N._1,N._2,u),w),(N,w)=>n(L=>o(y._3&&!N._3?F(N._1,N._2,!0):N,t))))})))})))},Bw=(t,e,n,r,i)=>e(o=>gn(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>Zi("via")(c,e,n,r,(d,l)=>e(_=>{const h=c._3&&!d._3?F(d._1,d._2,!0):d;return e(p=>be(h,e,n,r,(m,y)=>e(x=>{const N=h._3&&!m._3?F(m._1,m._2,!0):m;return e(w=>gn(N,e,n,r,(L,k)=>e(E=>{const O=N._3&&!L._3?F(L._1,L._2,!0):L;return e(Y=>be(O,e,n,r,(et,G)=>e(P=>i(O._3&&!et._3?F(et._1,et._2,!0):et,{from:y,to:G}))))})))})))})))}))),sr=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>jr(t)(e,n,r,(a,c)=>i(F(a._1,a._2,u),c),(a,c)=>n(f=>{const d=va((()=>{const _=Gt(Zt(p=>p==="_"))("'_'"),h=Gt(Zt(p=>p==="-"))("'-'");return(p,m,y,x,N)=>{const w=p._1,L=p._2;return m(k=>xu(F(w,L,!1),m,y,(E,O)=>{const Y=E._3;return m(et=>{if(Y)return x(E,O);const G=p._1,P=p._2;return m(V=>Ui(F(G,P,!1),m,y,(U,B)=>{const R=U._3;return m(M=>{if(R)return x(U,B);const S=p._1,I=p._2;return m(D=>_(F(S,I,!1),m,y,(A,H)=>{const $=A._3;return m(X=>$?x(A,H):h(p,m,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,p)=>i(F(h._1,h._2,u),p),(h,p)=>n(m=>o(l._3&&!h._3?F(h._1,h._2,!0):h,void 0))))})))},zw=(t,e,n,r,i)=>e(o=>sr("+edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>gn(w,e,n,r,(k,E)=>e(O=>{const Y=Gt(be)("target node identifier"),et=w._3&&!k._3?F(k._1,k._2,!0):k;return e(G=>Y(et,e,n,r,(P,V)=>e(U=>{const B=et._3&&!P._3?F(P._1,P._2,!0):P;return e(R=>{const M=(D,A)=>e(H=>i(B._3&&!D._3?F(D._1,D._2,!0):D,Bn("AddEdge",{from:x,to:V,label:A.tag==="Just"?v("Just",A._1):T}))),S=B._1,I=B._2;return e(D=>e(A=>{const H=($,X)=>{const q=$._3;return e(z=>q?r($,X):M(B,T))};return e($=>e(X=>Ae(F(S,I,!1),e,n,(q,z)=>H(F(q._1,q._2,!1),z),(q,z)=>e(tt=>e(Z=>w1(q,e,n,(ct,ft)=>H(F(ct._1,ct._2,!1),ft),(ct,ft)=>e(at=>{const yt=q._3&&!ct._3?F(ct._1,ct._2,!0):ct;return e(St=>M(yt,v("Just",ft)))})))))))}))})})))})))})))})))}))),Ww=(t,e,n,r,i)=>e(o=>sr("-edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>gn(w,e,n,r,(k,E)=>e(O=>{const Y=Gt(be)("target node identifier"),et=w._3&&!k._3?F(k._1,k._2,!0):k;return e(G=>Y(et,e,n,r,(P,V)=>e(U=>i(et._3&&!P._3?F(P._1,P._2,!0):P,Bn("DelEdge",{from:x,to:V})))))})))})))})))}))),qw=(t,e,n,r,i)=>e(o=>sr("-node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=un((k,E,O,Y,et)=>{const G=k._3;return Bw(k,E,O,(P,V)=>Y(F(P._1,P._2,G),V),et)}),L=p._3&&!y._3?F(y._1,y._2,!0):y;return e(k=>w(L,e,n,r,(E,O)=>e(Y=>i(L._3&&!E._3?F(E._1,E._2,!0):E,Bn("DelNode",{id:x,via:Ct($t.foldr,O)})))))})))})))}))),Hw=(t,e,n,r,i)=>e(o=>sr("enter")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>i(p._3&&!y._3?F(y._1,y._2,!0):y,Bn("Enter",{id:x})))))})))}))),$w=(t,e,n,r,i)=>e(o=>sr("exit")(t,e,n,r,(u,s)=>e(a=>i(t._3&&!u._3?F(u._1,u._2,!0):u,WT)))),Xw=(t,e,n,r,i)=>e(o=>sr("~edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>gn(w,e,n,r,(k,E)=>e(O=>{const Y=Gt(be)("target node identifier"),et=w._3&&!k._3?F(k._1,k._2,!0):k;return e(G=>Y(et,e,n,r,(P,V)=>e(U=>{const B=et._3&&!P._3?F(P._1,P._2,!0):P;return e(R=>Ke(B,e,n,r,(M,S)=>e(I=>{const D=Gt(jr("->"))("'->'"),A=B._3&&!M._3?F(M._1,M._2,!0):M;return e(H=>D(A,e,n,r,($,X)=>e(q=>{const z=A._3&&!$._3?F($._1,$._2,!0):$;return e(tt=>Ke(z,e,n,r,(Z,ct)=>e(ft=>{const at=Gt(be)("new source node identifier"),yt=z._3&&!Z._3?F(Z._1,Z._2,!0):Z;return e(St=>at(yt,e,n,r,(Rt,pt)=>e(Bt=>{const Jt=yt._3&&!Rt._3?F(Rt._1,Rt._2,!0):Rt;return e(mt=>gn(Jt,e,n,r,(gt,K)=>e(nt=>{const ht=Gt(be)("new target node identifier"),_t=Jt._3&&!gt._3?F(gt._1,gt._2,!0):gt;return e(Nt=>ht(_t,e,n,r,(wt,Kt)=>e(Se=>i(_t._3&&!wt._3?F(wt._1,wt._2,!0):wt,Bn("RepointEdge",{from:x,to:V,newFrom:pt,newTo:Kt})))))})))})))})))})))})))})))})))})))})))}))),Yw=(t,e,n,r,i)=>e(o=>sr("seed")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>Ae(c,e,n,r,(d,l)=>e(_=>{const h=Gt(Rw)("integer (seed value)"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>Ke(w,e,n,r,(k,E)=>e(O=>i(w._3&&!k._3?F(k._1,k._2,!0):k,x))))})))})))}))),Ki=Ew((()=>{const t=Gt(Zt(e=>e==="{"))("'{'");return(e,n,r,i,o)=>n(u=>n(s=>t(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?F(a._1,a._2,!0):a;return Ke(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?F(_._1,_._2,!0):_,h)))})))))})())(Gt((()=>{const t=Gt(Zt(e=>e==="}"))("'}'");return(e,n,r,i,o)=>n(u=>n(s=>Ke(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?F(a._1,a._2,!0):a;return t(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?F(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),Vw=Ki((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(Zt(p=>p===","))("','");return(p,m,y,x,N)=>{const w=p._3;return m(L=>m(k=>m(E=>m(O=>m(Y=>m(et=>Ae(p,m,y,(G,P)=>x(F(G._1,G._2,w),P),(G,P)=>m(V=>m(U=>{const B=p._3&&!G._3?F(G._1,G._2,!0):G;return h(B,m,y,(R,M)=>x(F(R._1,R._2,w),M),(R,M)=>m(S=>{const I=B._3&&!R._3?F(R._1,R._2,!0):R;return m(D=>m(A=>{const H=p._3&&!I._3?F(I._1,I._2,!0):I;return Ae(H,m,y,($,X)=>x(F($._1,$._2,w),X),($,X)=>m(q=>{const z=H._3&&!$._3?F($._1,$._2,!0):$;return m(tt=>m(Z=>{const ct=p._3&&!z._3?F(z._1,z._2,!0):z;return v1(ct,m,y,(ft,at)=>x(F(ft._1,ft._2,w),at),(ft,at)=>m(yt=>N(ct._3&&!ft._3?F(ft._1,ft._2,!0):ft,at)))}))}))}))}))})))))))))}})());return(h,p,m,y,x)=>p(N=>_(h,p,m,y,(w,L)=>p(k=>x(h._3&&!w._3?F(w._1,w._2,!0):w,Pw([l,...Ct($t.foldr,L)])))))}g()})()(t._3&&!c._3?F(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>e(f=>v1(F(s,a,!1),e,n,(d,l)=>e(_=>u(t,T)),(d,l)=>e(_=>u(d,v("Just",l))))))})),Uw=(t,e,n,r,i)=>e(o=>sr("+node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>e(k=>Ae(w,e,n,r,(E,O)=>e(Y=>{const et=Zt(P=>P===`
|
|
15
|
-
`||P==="\r"||P==="#"||P==="}"||P==="{"),G=w._3&&!E._3?F(E._1,E._2,!0):E;return e(P=>{const V=(R,M)=>e(S=>(M?((I,
|
|
13
|
+
`);return(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>Qw(F(u,s,!1),n,r,(c,f)=>n(d=>t(e,n,r,i,o)),o))}})(),Ea=(()=>{const t=Gt(Zt(e=>e==='"'))(`'"'`);return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=un(Fw),d=e._3&&!s._3?F(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(p=>{const m=Gt(Gt(Zt(x=>x==='"'))(`'"'`))(`closing '"' (unterminated string)`),y=d._3&&!_._3?F(_._1,_._2,!0):_;return n(x=>m(y,n,r,i,(N,w)=>n(L=>o(y._3&&!N._3?F(N._1,N._2,!0):N,lr(Ct($t.foldr,h))))))})))})))})(),Aw=(()=>{const t=Gt(Zt(e=>e===":"))("':'");return(e,n,r,i,o)=>n(u=>Ae(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 L=N._3;return d(k=>{if(L)return _(N,w);const E=f._1,O=f._2;return d(Y=>w1(F(E,O,!1),d,l,(et,G)=>{const P=et._3;return d(V=>P?_(et,G):Ea(f,d,l,_,h))},h))})};return d(N=>t(F(p,m,!1),d,l,x,(w,L)=>d(k=>d(E=>Ae(w,d,l,x,(O,Y)=>d(et=>{const G=un(Zt(V=>V!==`
|
|
14
|
+
`&&V!=="\r"&&V!=="#"&&V!=="}")),P=w._3&&!O._3?F(O._1,O._2,!0):O;return d(V=>G(P,d,l,x,(U,B)=>d(R=>h(P._3&&!U._3?F(U._1,U._2,!0):U,Nh(lr(Ct($t.foldr,B)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(e._3&&!s._3?F(s._1,s._2,!0):s,n,r,i,o))))})(),v1=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>w1(F(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):Ea(t,e,n,r,i))},i))},Ui=Zt(t=>t>="0"&&t<="9"),be=(()=>{const t=Gt(Zt(e=>e==="_"))("'_'");return(e,n,r,i,o)=>n(u=>{const s=(f,d)=>n(l=>{const _=un((()=>{const p=Gt(Zt(y=>y==="_"))("'_'"),m=Gt(Zt(y=>y==="-"))("'-'");return(y,x,N,w,L)=>{const k=y._1,E=y._2;return x(O=>xu(F(k,E,!1),x,N,(Y,et)=>{const G=Y._3;return x(P=>{if(G)return w(Y,et);const V=y._1,U=y._2;return x(B=>Ui(F(V,U,!1),x,N,(R,M)=>{const S=R._3;return x(D=>{if(S)return w(R,M);const I=y._1,A=y._2;return x(H=>p(F(I,A,!1),x,N,($,X)=>{const q=$._3;return x(z=>q?w($,X):m(y,x,N,w,L))},L))})},L))})},L))}})()),h=e._3&&!f._3?F(f._1,f._2,!0):f;return n(p=>_(h,n,r,i,(m,y)=>n(x=>o(h._3&&!m._3?F(m._1,m._2,!0):m,co(d)+lr(Ct($t.foldr,y))))))}),a=e._1,c=e._2;return n(f=>xu(F(a,c,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?i(d,l):t(e,n,r,i,s))},s))})})(),Mw=Gt((t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>Ea(F(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):be(t,e,n,r,i))},i))})("frame name (identifier or quoted string)"),b1=(t,e,n,r,i)=>e(o=>Ae(t,e,n,r,(u,s)=>e(a=>{const c=Gt(be)("attribute key"),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=f._3&&!l._3?F(l._1,l._2,!0):l;return e(m=>Ae(p,e,n,r,(y,x)=>e(N=>{const w=Gt(Gt(Zt(k=>k===":"))("':'"))("':'"),L=p._3&&!y._3?F(y._1,y._2,!0):y;return e(k=>w(L,e,n,r,(E,O)=>e(Y=>{const et=L._3&&!E._3?F(E._1,E._2,!0):E;return e(G=>Ae(et,e,n,r,(P,V)=>e(U=>{const B=Gt(be)("attribute value"),R=et._3&&!P._3?F(P._1,P._2,!0):P;return e(M=>B(R,e,n,r,(S,D)=>e(I=>{const A=R._3&&!S._3?F(S._1,S._2,!0):S;return e(H=>Ae(A,e,n,r,($,X)=>e(q=>i(A._3&&!$._3?F($._1,$._2,!0):$,b(_,D)))))})))})))})))})))})))}))),Ow=(t,e,n,r,i)=>e(o=>be(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>Ae(c,e,n,r,(d,l)=>e(_=>{const h=Gt((m,y,x,N,w)=>{const L=m._1,k=m._2;return y(E=>jr("->")(F(L,k,!1),y,x,(O,Y)=>{const et=O._3;return y(G=>et?N(O,Y):jr("<-")(m,y,x,N,w))},w))})("'->' or '<-'"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>Ae(w,e,n,r,(k,E)=>e(O=>{const Y=Gt(be)("target node identifier"),et=w._3&&!k._3?F(k._1,k._2,!0):k;return e(G=>Y(et,e,n,r,(P,V)=>e(U=>{const B=un((M,S,D,I,A)=>{const H=M._3;return S($=>S(X=>Ae(M,S,D,(q,z)=>I(F(q._1,q._2,H),z),(q,z)=>S(tt=>S(Z=>{const ct=M._3&&!q._3?F(q._1,q._2,!0):q;return v1(ct,S,D,(ft,at)=>I(F(ft._1,ft._2,H),at),(ft,at)=>S(yt=>A(ct._3&&!ft._3?F(ft._1,ft._2,!0):ft,at)))})))))}),R=et._3&&!P._3?F(P._1,P._2,!0):P;return e(M=>B(R,e,n,r,(S,D)=>e(I=>(()=>{if(x==="<-"){const H=Bn("Token",{from:V,to:s,labels:W(xc)(Ct($t.foldr,D))});return($,X,q,z,tt)=>tt($,H)}const A=Bn("Token",{from:s,to:V,labels:W(xc)(Ct($t.foldr,D))});return(H,$,X,q,z)=>z(H,A)})()(R._3&&!S._3?F(S._1,S._2,!0):S,e,n,r,i))))})))})))})))})))}))),Rw=(t,e,n,r,i)=>e(o=>Ui(t,e,n,r,(u,s)=>e(a=>{const c=un(Ui),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=Td(co(s)+lr(Ct($t.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(y,x,N,w,L)=>L(y,m)}if(p.tag==="Nothing")return(m,y,x,N,w)=>w(m,0);g()})()(f._3&&!l._3?F(l._1,l._2,!0):l,e,n,r,i)})))}))),Zi=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>jr(t)(e,n,r,(a,c)=>i(F(a._1,a._2,u),c),(a,c)=>n(f=>{const d=va((()=>{const _=Gt(Zt(p=>p==="_"))("'_'"),h=Gt(Zt(p=>p==="-"))("'-'");return(p,m,y,x,N)=>{const w=p._1,L=p._2;return m(k=>xu(F(w,L,!1),m,y,(E,O)=>{const Y=E._3;return m(et=>{if(Y)return x(E,O);const G=p._1,P=p._2;return m(V=>Ui(F(G,P,!1),m,y,(U,B)=>{const R=U._3;return m(M=>{if(R)return x(U,B);const S=p._1,D=p._2;return m(I=>_(F(S,D,!1),m,y,(A,H)=>{const $=A._3;return m(X=>$?x(A,H):h(p,m,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,p)=>i(F(h._1,h._2,u),p),(h,p)=>n(m=>{const y=l._3&&!h._3?F(h._1,h._2,!0):h;return n(x=>Ke(y,n,r,(N,w)=>i(F(N._1,N._2,u),w),(N,w)=>n(L=>o(y._3&&!N._3?F(N._1,N._2,!0):N,t))))})))})))},Bw=(t,e,n,r,i)=>e(o=>gn(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>Zi("via")(c,e,n,r,(d,l)=>e(_=>{const h=c._3&&!d._3?F(d._1,d._2,!0):d;return e(p=>be(h,e,n,r,(m,y)=>e(x=>{const N=h._3&&!m._3?F(m._1,m._2,!0):m;return e(w=>gn(N,e,n,r,(L,k)=>e(E=>{const O=N._3&&!L._3?F(L._1,L._2,!0):L;return e(Y=>be(O,e,n,r,(et,G)=>e(P=>i(O._3&&!et._3?F(et._1,et._2,!0):et,{from:y,to:G}))))})))})))})))}))),sr=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>jr(t)(e,n,r,(a,c)=>i(F(a._1,a._2,u),c),(a,c)=>n(f=>{const d=va((()=>{const _=Gt(Zt(p=>p==="_"))("'_'"),h=Gt(Zt(p=>p==="-"))("'-'");return(p,m,y,x,N)=>{const w=p._1,L=p._2;return m(k=>xu(F(w,L,!1),m,y,(E,O)=>{const Y=E._3;return m(et=>{if(Y)return x(E,O);const G=p._1,P=p._2;return m(V=>Ui(F(G,P,!1),m,y,(U,B)=>{const R=U._3;return m(M=>{if(R)return x(U,B);const S=p._1,D=p._2;return m(I=>_(F(S,D,!1),m,y,(A,H)=>{const $=A._3;return m(X=>$?x(A,H):h(p,m,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,p)=>i(F(h._1,h._2,u),p),(h,p)=>n(m=>o(l._3&&!h._3?F(h._1,h._2,!0):h,void 0))))})))},zw=(t,e,n,r,i)=>e(o=>sr("+edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>gn(w,e,n,r,(k,E)=>e(O=>{const Y=Gt(be)("target node identifier"),et=w._3&&!k._3?F(k._1,k._2,!0):k;return e(G=>Y(et,e,n,r,(P,V)=>e(U=>{const B=et._3&&!P._3?F(P._1,P._2,!0):P;return e(R=>{const M=(I,A)=>e(H=>i(B._3&&!I._3?F(I._1,I._2,!0):I,Bn("AddEdge",{from:x,to:V,label:A.tag==="Just"?v("Just",A._1):T}))),S=B._1,D=B._2;return e(I=>e(A=>{const H=($,X)=>{const q=$._3;return e(z=>q?r($,X):M(B,T))};return e($=>e(X=>Ae(F(S,D,!1),e,n,(q,z)=>H(F(q._1,q._2,!1),z),(q,z)=>e(tt=>e(Z=>v1(q,e,n,(ct,ft)=>H(F(ct._1,ct._2,!1),ft),(ct,ft)=>e(at=>{const yt=q._3&&!ct._3?F(ct._1,ct._2,!0):ct;return e(St=>M(yt,v("Just",ft)))})))))))}))})})))})))})))})))}))),Ww=(t,e,n,r,i)=>e(o=>sr("-edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>gn(w,e,n,r,(k,E)=>e(O=>{const Y=Gt(be)("target node identifier"),et=w._3&&!k._3?F(k._1,k._2,!0):k;return e(G=>Y(et,e,n,r,(P,V)=>e(U=>i(et._3&&!P._3?F(P._1,P._2,!0):P,Bn("DelEdge",{from:x,to:V})))))})))})))})))}))),qw=(t,e,n,r,i)=>e(o=>sr("-node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=un((k,E,O,Y,et)=>{const G=k._3;return Bw(k,E,O,(P,V)=>Y(F(P._1,P._2,G),V),et)}),L=p._3&&!y._3?F(y._1,y._2,!0):y;return e(k=>w(L,e,n,r,(E,O)=>e(Y=>i(L._3&&!E._3?F(E._1,E._2,!0):E,Bn("DelNode",{id:x,via:Ct($t.foldr,O)})))))})))})))}))),Hw=(t,e,n,r,i)=>e(o=>sr("enter")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>i(p._3&&!y._3?F(y._1,y._2,!0):y,Bn("Enter",{id:x})))))})))}))),$w=(t,e,n,r,i)=>e(o=>sr("exit")(t,e,n,r,(u,s)=>e(a=>i(t._3&&!u._3?F(u._1,u._2,!0):u,WT)))),Xw=(t,e,n,r,i)=>e(o=>sr("~edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>gn(w,e,n,r,(k,E)=>e(O=>{const Y=Gt(be)("target node identifier"),et=w._3&&!k._3?F(k._1,k._2,!0):k;return e(G=>Y(et,e,n,r,(P,V)=>e(U=>{const B=et._3&&!P._3?F(P._1,P._2,!0):P;return e(R=>Ke(B,e,n,r,(M,S)=>e(D=>{const I=Gt(jr("->"))("'->'"),A=B._3&&!M._3?F(M._1,M._2,!0):M;return e(H=>I(A,e,n,r,($,X)=>e(q=>{const z=A._3&&!$._3?F($._1,$._2,!0):$;return e(tt=>Ke(z,e,n,r,(Z,ct)=>e(ft=>{const at=Gt(be)("new source node identifier"),yt=z._3&&!Z._3?F(Z._1,Z._2,!0):Z;return e(St=>at(yt,e,n,r,(Rt,pt)=>e(Bt=>{const Jt=yt._3&&!Rt._3?F(Rt._1,Rt._2,!0):Rt;return e(mt=>gn(Jt,e,n,r,(gt,K)=>e(nt=>{const ht=Gt(be)("new target node identifier"),_t=Jt._3&&!gt._3?F(gt._1,gt._2,!0):gt;return e(Nt=>ht(_t,e,n,r,(wt,Kt)=>e(Se=>i(_t._3&&!wt._3?F(wt._1,wt._2,!0):wt,Bn("RepointEdge",{from:x,to:V,newFrom:pt,newTo:Kt})))))})))})))})))})))})))})))})))})))})))}))),Yw=(t,e,n,r,i)=>e(o=>sr("seed")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>Ae(c,e,n,r,(d,l)=>e(_=>{const h=Gt(Rw)("integer (seed value)"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>Ke(w,e,n,r,(k,E)=>e(O=>i(w._3&&!k._3?F(k._1,k._2,!0):k,x))))})))})))}))),Ki=Ew((()=>{const t=Gt(Zt(e=>e==="{"))("'{'");return(e,n,r,i,o)=>n(u=>n(s=>t(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?F(a._1,a._2,!0):a;return Ke(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?F(_._1,_._2,!0):_,h)))})))))})())(Gt((()=>{const t=Gt(Zt(e=>e==="}"))("'}'");return(e,n,r,i,o)=>n(u=>n(s=>Ke(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?F(a._1,a._2,!0):a;return t(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?F(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),Vw=Ki((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(Zt(p=>p===","))("','");return(p,m,y,x,N)=>{const w=p._3;return m(L=>m(k=>m(E=>m(O=>m(Y=>m(et=>Ae(p,m,y,(G,P)=>x(F(G._1,G._2,w),P),(G,P)=>m(V=>m(U=>{const B=p._3&&!G._3?F(G._1,G._2,!0):G;return h(B,m,y,(R,M)=>x(F(R._1,R._2,w),M),(R,M)=>m(S=>{const D=B._3&&!R._3?F(R._1,R._2,!0):R;return m(I=>m(A=>{const H=p._3&&!D._3?F(D._1,D._2,!0):D;return Ae(H,m,y,($,X)=>x(F($._1,$._2,w),X),($,X)=>m(q=>{const z=H._3&&!$._3?F($._1,$._2,!0):$;return m(tt=>m(Z=>{const ct=p._3&&!z._3?F(z._1,z._2,!0):z;return b1(ct,m,y,(ft,at)=>x(F(ft._1,ft._2,w),at),(ft,at)=>m(yt=>N(ct._3&&!ft._3?F(ft._1,ft._2,!0):ft,at)))}))}))}))}))})))))))))}})());return(h,p,m,y,x)=>p(N=>_(h,p,m,y,(w,L)=>p(k=>x(h._3&&!w._3?F(w._1,w._2,!0):w,Pw([l,...Ct($t.foldr,L)])))))}g()})()(t._3&&!c._3?F(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>e(f=>b1(F(s,a,!1),e,n,(d,l)=>e(_=>u(t,T)),(d,l)=>e(_=>u(d,v("Just",l))))))})),Uw=(t,e,n,r,i)=>e(o=>sr("+node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?F(u._1,u._2,!0):u;return e(f=>gn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),p=c._3&&!d._3?F(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>e(k=>Ae(w,e,n,r,(E,O)=>e(Y=>{const et=Zt(P=>P===`
|
|
15
|
+
`||P==="\r"||P==="#"||P==="}"||P==="{"),G=w._3&&!E._3?F(E._1,E._2,!0):E;return e(P=>{const V=(R,M)=>e(S=>(M?((D,I,A,H,$)=>$(D,"")):Aw)(G._3&&!R._3?F(R._1,R._2,!0):R,e,n,r,(D,I)=>e(A=>{const H=w._3&&!D._3?F(D._1,D._2,!0):D;return e($=>{const X=(tt,Z)=>e(ct=>i(H._3&&!tt._3?F(tt._1,tt._2,!0):tt,Bn("AddNode",{id:x,label:I,shape:(()=>{const ft=Dw("shape")(Z);if(ft.tag==="Just")return ft._1==="rectangle"||ft._1==="rect"?jn:ft._1==="cylinder"||ft._1==="cyl"?El:ft._1==="parallelogram"?Cl:ft._1==="diamond"?Sl:ft._1==="ellipse"?Gl:ft._1==="document"||ft._1==="doc"?Pl:ft._1==="cloud"?Dl:jn;if(ft.tag==="Nothing")return jn;g()})()}))),q=H._1,z=H._2;return e(tt=>{const Z=(ct,ft)=>{const at=ct._3;return e(yt=>at?r(ct,ft):X(H,Q))};return e(ct=>e(ft=>Ae(F(q,z,!1),e,n,(at,yt)=>Z(F(at._1,at._2,!1),yt),(at,yt)=>e(St=>e(Rt=>Vw(at,e,n,(pt,Bt)=>Z(F(pt._1,pt._2,!1),Bt),(pt,Bt)=>e(Jt=>X(at._3&&!pt._3?F(pt._1,pt._2,!0):pt,Bt))))))))})})}))),U=G._1,B=G._2;return e(R=>{const M=(S,D)=>{const I=S._3;return e(A=>I?r(S,D):V(G,!1))};return e(S=>e(D=>e(I=>ka(F(U,B,!1),e,n,(A,H)=>{const $=A._3;return e(X=>$?M(F(U,B,!1),H):e(q=>et(F(U,B,!1),e,n,(z,tt)=>M(F(U,B,!1),tt),(z,tt)=>e(Z=>e(ct=>V(F(U,B,!1),!0))))))},(A,H)=>e($=>e(X=>V(F(U,B,!1),!0)))))))})})}))))})))})))}))),Zw=(t,e,n,r,i)=>e(o=>m1(t,e,n,r,(u,s)=>e(a=>{const c=Gt(J1([Uw,qw,Xw,zw,Ww,Hw,$w,Ow]))("statement (+node, -node, +edge, -edge, ~edge, enter, exit, or 'a -> b')"),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>i(f._3&&!l._3?F(l._1,l._2,!0):l,Ja("Leaf",{op:_,line:s.line,column:s.column})))))}))),Kw=(t,e,n,r,i)=>e(o=>Zi("seq")(t,e,n,r,(u,s)=>e(a=>Ki(Ca(g1))(t._3&&!u._3?F(u._1,u._2,!0):u,e,n,r,i)))),jw=(t,e,n,r,i)=>e(o=>Zi("par")(t,e,n,r,(u,s)=>e(a=>Ki(Ca(XT))(t._3&&!u._3?F(u._1,u._2,!0):u,e,n,r,i)))),Ca=t=>{const e=un(tv());return(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,c)=>r(f=>u(n._3&&!a._3?F(a._1,a._2,!0):a,t(Ct($t.foldr,c))))))},tv=Ma(()=>{const t=va(Gt(Zt(e=>e==="}"))("'}'"));return(e,n,r,i,o)=>n(u=>{const s=e._3;return n(a=>n(c=>Ke(e,n,r,(f,d)=>i(F(f._1,f._2,s),d),(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?F(f._1,f._2,!0):f;return t(h,n,r,(p,m)=>i(F(p._1,p._2,s),m),(p,m)=>n(y=>{const x=h._3&&!p._3?F(p._1,p._2,!0):p;return n(N=>{const w=J1([(k,E,O,Y,et)=>{const G=k._3;return jw(k,E,O,(P,V)=>Y(F(P._1,P._2,G),V),et)},(k,E,O,Y,et)=>{const G=k._3;return Kw(k,E,O,(P,V)=>Y(F(P._1,P._2,G),V),et)},Zw]),L=e._3&&!x._3?F(x._1,x._2,!0):x;return n(k=>w(L,n,r,i,(E,O)=>n(Y=>{const et=L._3&&!E._3?F(E._1,E._2,!0):E;return n(G=>Ae(et,n,r,i,(P,V)=>n(U=>{const B=et._3&&!P._3?F(P._1,P._2,!0):P;return n(R=>Iw(B,n,r,i,(M,S)=>n(D=>o(B._3&&!M._3?F(M._1,M._2,!0):M,O))))})))})))})}))})))))})}),Sa=t=>e=>(n,r,i,o,u)=>r(s=>Zi(t)(n,r,i,o,(a,c)=>r(f=>{const d=n._3&&!a._3?F(a._1,a._2,!0):a;return r(l=>Mw(d,r,i,o,(_,h)=>r(p=>{const m=d._3&&!_._3?F(_._1,_._2,!0):_;return r(y=>Ke(m,r,i,o,(x,N)=>r(w=>{const L=Ki(Ca(g1)),k=m._3&&!x._3?F(x._1,x._2,!0):x;return r(E=>L(k,r,i,o,(O,Y)=>r(et=>{const G=k._3&&!O._3?F(O._1,O._2,!0):O;return r(P=>Ke(G,r,i,o,(V,U)=>r(B=>u(G._3&&!V._3?F(V._1,V._2,!0):V,{name:v("Just",h),ops:Y,kind:e}))))})))})))})))}))),ev=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>Sa("keyframe")(qT)(F(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>{if(f)return r(a,c);const l=t._1,_=t._2;return e(h=>Sa("still")(HT)(F(l,_,!1),e,n,(p,m)=>{const y=p._3;return e(x=>y?r(p,m):Sa("title")($T)(t,e,n,r,i))},i))})},i))},nv=(t,e,n,r,i)=>e(o=>Zi("inside")(t,e,n,r,(u,s)=>e(a=>{const c=Gt(be)("node identifier"),f=t._3&&!u._3?F(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=f._3&&!l._3?F(l._1,l._2,!0):l;return e(m=>Ke(p,e,n,r,(y,x)=>e(N=>{const w=p._3&&!y._3?F(y._1,y._2,!0):y;return e(L=>Ki(k1)(w,e,n,r,(k,E)=>e(O=>{const Y=w._3&&!k._3?F(k._1,k._2,!0):k;return e(et=>Ke(Y,e,n,r,(G,P)=>e(V=>i(Y._3&&!G._3?F(G._1,G._2,!0):G,{node:_,doc:E}))))})))})))})))}))),k1=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>{const l=un(rv()),_=t._3&&!c._3?F(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?F(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=>Yw(F(s,a,!1),e,n,(d,l)=>{const _=d._3;return e(h=>_?r(d,l):u(t,T))},(d,l)=>e(_=>u(d,v("Just",l))))))}),rv=Ma(()=>yw.defer(t=>(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>n(c=>nv(F(u,s,!1),n,r,(f,d)=>n(l=>n(_=>ev(e,n,r,i,(h,p)=>n(m=>o(h,N1("TopFrame",p)))))),(f,d)=>n(l=>o(f,N1("TopInside",d))))))})),iv=(()=>{const t=Gt((e,n,r,i,o)=>n(u=>n(s=>Ke(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?F(a._1,a._2,!0):a;return ka(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?F(_._1,_._2,!0):_,h)))}))))))("'keyframe', 'still', 'title', 'inside', or end of input");return(e,n,r,i,o)=>n(u=>n(s=>n(a=>n(c=>Ke(e,n,r,i,(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?F(f._1,f._2,!0):f;return k1(h,n,r,i,(p,m)=>n(y=>{const x=h._3&&!p._3?F(p._1,p._2,!0):p;return n(N=>n(w=>{const L=e._3&&!x._3?F(x._1,x._2,!0):x;return t(L,n,r,i,(k,E)=>n(O=>o(L._3&&!k._3?F(k._1,k._2,!0):k,m)))}))}))})))))))})(),ov=t=>{const e=Tw(t)(iv);if(e.tag==="Left")return Pt("Left",{msg:e._1._1,line:e._1._2.line,column:e._1._2.column});if(e.tag==="Right")return Pt("Right",e._1);g()},uv=t=>{const e=ov(t);if(e.tag==="Left")return Pt("Left",e._1.msg);if(e.tag==="Right")return Pt("Right",e._1);g()};function Ga(t,e,n,r){if(typeof window<"u"){var i=window[n];if(i!=null&&r instanceof i)return e(r)}for(var o=r;o!=null;){var u=Object.getPrototypeOf(o),s=u.constructor.name;if(s===n)return e(r);if(s==="Object")return t;o=u}return t}function ti(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function sv(t){return function(e){return function(){return e.getAttribute(t)}}}const L1=t=>{const e=sv(t);return n=>{const r=e(n);return()=>{const i=r();return sc(i,T,Xt)}}};function av(t){return function(e){return function(){e.textContent=t}}}function cv(t){return function(){return function(e){return t(e)()}}}function gv(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const fv=function(){return window};function _v(t){return function(e){return function(){e.value=t}}}function dv(t){return function(){return t.valueAsNumber}}function lv(t){return function(){return t.value}}function hv(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const pv=t=>t,mv=t=>()=>t.clientWidth||0,yv=()=>window.devicePixelRatio||1,Pa=(t,e)=>{e.innerHTML=t},Da=(t,e,n)=>{t.style.setProperty(e,n)},xv=(t,e)=>t.querySelector(`[data-mg="${e}"]`),Nv=t=>e=>t===e,Jv=t=>t,Tv=(t,e,n)=>({tag:t,_1:e,_2:n}),wv=zt.foldMap(Pd),Ia=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},vv=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bv=Tv("AutoSize"),kv=Jv("CanvasRenderer"),Lv=t=>e=>{const n=t-e*rt(de(ln(t/e)));return e<=0?0:n<0?n+e:n},Ev=t=>J(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),Cv=t=>{const e=L1("data-markgraf-titles")(t);return()=>{const n=e();return n.tag==="Nothing"||!(n.tag==="Just"&&n._1==="false")}},Sv=t=>{const e=L1("data-markgraf-theme")(t);return()=>{const n=e();if(n.tag==="Just")return n._1==="light"?ya:n._1==="dark"?yT:n._1==="blueprint"?xT:n._1==="whiteboard"?NT:n._1==="isometric"?JT:ya;if(n.tag==="Nothing")return ya;g()}},Gv=`
|
|
16
16
|
<canvas data-mg="stage" tabindex="0"></canvas>
|
|
17
17
|
<div data-mg="play-overlay" aria-hidden="true"></div>
|
|
18
18
|
<div data-mg="bar">
|
|
@@ -29,4 +29,4 @@ var Hv=(function(Tu){"use strict";function Aa(t){let e=0,n;return()=>{if(e===2)r
|
|
|
29
29
|
<option value="2">2\xD7</option>
|
|
30
30
|
</select>
|
|
31
31
|
</div>
|
|
32
|
-
`,qn=t=>e=>n=>()=>{const r=xv(t,e),i=
|
|
32
|
+
`,qn=t=>e=>n=>()=>{const r=xv(t,e),i=sc(r,T,Xt);if(i.tag==="Just")return n(i._1)();i.tag!=="Nothing"&&g()},Pv=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=wv(i=>'<span class="mg-tick" style="left:'+ci(si("Fixed",ai(0)(20)(2)))(100*i.startT/n)+'%" data-label="'+(()=>{if(i.scene.tag==="Structural")return i.scene._1.to;if(i.scene.tag==="DataFlow")return i.scene._1.keyframe;if(i.scene.tag==="Hold")return i.scene._1;if(i.scene.tag==="EnterNode"||i.scene.tag==="ExitNode")return"";g()})()+'"></span>')(e.spans);return qn(t)("ticks")(i=>()=>Pa(r,i))},Dv=t=>e=>n=>qn(t)("scrub")(r=>{const i=Ga(T,Xt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return n<=0?()=>{}:_v(oe(de(Vn(e/n*1e3))))(i._1);g()}),Qa=t=>e=>n=>{const r=cv(i=>n);return()=>{const i=r();return gv(t)(i)(!1)(e)()}},E1=()=>Md()/1e3,Fa=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>{const f=Ye(u.layout),d=Al(u.layout),l={center:{x:d.x+d.w/2,y:f.y+f.h/2},zoom:is(u.layout)(f)(0)},_=ju(u.layout)(l),h=()=>{const N=E1(),w=a.value;return a.value=N,w===0?0:N-w},p=sp(u)(Ia(c)(u.totalDuration)),m=o?p:{...p,levels:W(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:W(N=>({...N,state:{...N.state,camera:l}}))(m.levels)}:m;if(e==="CanvasRenderer")return()=>{const N=h(),w=pv(t),L=Zr({padding:8,outputAspect:T})(x),k=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){if(y)return{w:L.vw*1.0909090909090908,h:L.vh*1.0909090909090908};const M=mv(t)();return{w:M,h:L.vw<=0?M:M*L.vh/L.vw}}g()})(),E=yv(),O=k.w*E,Y=k.h*E,et=Rd(w)(),G=Bd(w)(),P=zd(w)(O);et!==O&&P();const V=Wd(w)(Y);if(G!==Y&&V(),Da(t,"height",oe(de(Vn(k.h)))+"px"),n.tag==="FixedSize")Da(t,"width",oe(de(Vn(k.w)))+"px");else if(n.tag==="AutoSize"){const M=oe(de(Vn(k.w)))+"px";y&&Da(t,"width",M)}else g();const U=Od(w)();_r(U)(),oo(U)({scaleX:E,scaleY:E})();const B=s.value,R=pT(r)(i)(U)({width:k.w,height:k.h})(x)(N)(B)();return s.value=R,dr(U)()};if(e==="SvgRenderer")return()=>{const N=h(),w=s.value,L=FT((()=>{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=L.springs,ti("viewBox")(L.parts.viewBox)(t)(),ti("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(ti("width")(oe(de(Vn(n._1))))(t)(),ti("height")(oe(de(Vn(n._2))))(t)()):n.tag==="AutoSize"||g(),Pa(L.parts.body,t)};g()},C1=t=>{const e=uv(t);if(e.tag==="Left")return Pt("Left",e._1);if(e.tag==="Right"){const n=h1(e._1)(f1)._1;if(n.tag==="Left")return Pt("Left",n._1.msg);if(n.tag==="Right")return Pt("Right",n._1)}g()},Iv=t=>{const e=C1(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return Id;g()},Aa=t=>e=>{const n=Vt(r=>r.startT<=e&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return n._1.scene._1.to;if(n._1.scene.tag==="DataFlow")return n._1.scene._1.keyframe;if(n._1.scene.tag==="Hold")return n._1.scene._1;if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return"";g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;if(r>=0&&r<t.spans.length){if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="Hold")return t.spans[r].scene._1;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return"";g()}return""}g()},Qv=t=>e=>qn(t)("speed")(n=>{const r=Ga(T,Xt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return Qa("change")(n)((()=>{const i=lv(r._1);return()=>{const o=i(),u=md(o,ec,Xt,T);if(u.tag==="Just")return e(u._1)();u.tag!=="Nothing"&&g()}})());g()}),Fv=t=>e=>n=>qn(t)("scrub")(r=>{const i=Ga(T,Xt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return Qa("input")(r)((()=>{const o=dv(i._1);return()=>{const u=o();return n.pause(),n.seek(u/1e3*e.totalDuration)()}})());g()}),Av=t=>e=>n=>{const r=Pv(t)(e);return()=>{r(),qn(t)("play")(i=>ti("data-mg-playing")("1")(i))(),Qv(t)(n.setSpeed)(),qn(t)("play")(i=>Qa("click")(i)(n.toggle))(),Fv(t)(e)(n)(),n.subscribe(i=>{const o=Ia(i.time)(e.totalDuration),u=Dv(t)(o)(e.totalDuration);return()=>(u(),qn(t)("time")(s=>av(ci(si("Fixed",ai(0)(20)(2)))(o)+" / "+ci(si("Fixed",ai(0)(20)(2)))(e.totalDuration))(s))(),qn(t)("play")(s=>ti("data-mg-playing")(i.playing?"1":"0")(s))())})()}},Mv={...mh,tokenZoomFloor:1,minZoom:1.6,maxZoom:3.2},Ov=t=>e=>{const n=Ff(t);return()=>{const r=n(),i=Af(t)(),o=N0(Mv)(c0)(t)(Mf(r)(i)(t));if(o.tag==="Left")return ac("[markgraf] precompute failed")();if(o.tag==="Right")return e(o._1)();g()}},Rv=t=>e=>n=>r=>i=>o=>u=>()=>{let s=1,a=!0,c=!1,f=0,d=0;const l={value:Q},_={value:0};let h=!1,p=[];Fa(t)(n)(r)(i)(o)(u)(e)(l)(_)(0)();const m=k=>()=>{const E=p,O=a,Y={time:k,keyframe:Aa(e)(k),playing:O};return Ev(et=>et(Y))(E)()},y=()=>(a=!1,m(f)()),x=()=>{if(!h&&(c=!1,a)){const k=E1(),E=d;d=k;const O=s,Y=f,et=Lv(E===0?Y+0*O:Y+(k-E)*O)(e.totalDuration+.8);return f=et,Fa(t)(n)(r)(i)(o)(u)(e)(l)(_)(et)(),m(et)(),N()}},N=()=>{if(!h&&!c){c=!0;const k=fv();hv(x)(k)()}},w=()=>(d=0,a=!0,N()),L=()=>(a||w(),m(f)());return w(),{play:L,pause:y,toggle:()=>a?y():L(),seek:k=>{const E=vv(0)(Ia(e.totalDuration)(k));return()=>(f=E,d=0,Fa(t)(n)(r)(i)(o)(u)(e)(l)(_)(E)(),m(E)())},setSpeed:k=>()=>s=k,currentTime:()=>f,currentKeyframe:()=>{const k=f;return Aa(e)(k)},isPlaying:()=>a,duration:e.totalDuration,subscribe:k=>()=>{p=Ot(p)(k);const E=f,O=a;k({time:E,keyframe:Aa(e)(E),playing:O})();const Y=ja(et=>!Nv(et)(k));return()=>{p=Y(p)}},destroy:()=>h=!0}},S1=t=>e=>{const n=C1(e);if(n.tag==="Left")return ac("[markgraf] parse failed: "+n._1);if(n.tag==="Right")return Ov(n._1)(r=>{const i=Cv(t);return()=>{const o=i(),u=Sv(t)();return Pa(Gv,t),qn(t)("stage")(s=>{const a=Rv(s)(r)(kv)(bv)(u)(TT)(o);return()=>{const c=a();return Av(t)(r)(c)()}})()}});g()},Bv=t=>{const e=t.getAttribute("data-markgraf-src-b64");if(e)try{return decodeURIComponent(escape(atob(e)))}catch{return atob(e)}return t.getAttribute("data-markgraf-src")||t.textContent||""};let Ln=null;const Nu=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",zv=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{Nu(t)?(Ln&&Ln!==t&&Nu(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=Bv(t),n=t.dataset.markgrafPaused==="true";t.textContent="",S1(t)(e)(),n?Nu(t)&&t.querySelector('[data-mg="play"]').click():Ln===null?Ln=t:Nu(t)&&t.querySelector('[data-mg="play"]').click(),zv(t)},Ju=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(Wv)},G1=()=>{document.addEventListener("keydown",t=>{if(t.code!=="Space"&&t.key!==" ")return;const e=t.target,n=e&&e.closest?.("[data-markgraf]");if(!n){const i=e?.tagName,o=(e?.type||"").toLowerCase();if(e?.isContentEditable||i==="TEXTAREA"||i==="SELECT"||i==="INPUT"&&!["range","checkbox","radio","button","submit","reset"].includes(o))return}const r=n||Ln||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=Iv(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>S1(e)(n)(),mountAll:Ju,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{Ju(),G1()}):(Ju(),G1())}return Tu.mountAll=Ju,Object.defineProperty(Tu,Symbol.toStringTag,{value:"Module"}),Tu})({});
|