@markgrafhq/markgraf-embed 0.1.4 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,18 @@
1
- var Vm=(function(Ao){"use strict";function Rc(e){let t=0,n;return()=>{if(t===2)return n;if(t===1)throw new Error("Binding demanded before initialized");return t=1,n=e(),t=2,n}}function c(){throw new Error("Failed pattern match")}function Rn(e,t){return t>0?Math.floor(e/t):t<0?-Math.floor(e/-t):0}const me=e=>t=>e,V=function(e){return function(t){for(var n=t.length,r=new Array(n),i=0;i<n;i++)r[i]=e(t[i]);return r}},Ic={map:V},Nu=e=>e,St=typeof Array.prototype.flatMap=="function"?function(e){return function(t){return e.flatMap(t)}}:function(e){return function(t){for(var n=[],r=e.length,i=0;i<r;i++)for(var o=t(e[i]),u=o.length,s=0;s<u;s++)n.push(o[s]);return n}},ue=function(e){return e.toString()},xu=function(e){var t=e.toString();return isNaN(t+".0")?t:t+".0"},Dc=function(e){var t=e.length;return'"'+e.replace(/[\0-\x1F\x7F"\\]/g,function(n,r){switch(n){case'"':case"\\":return"\\"+n;case"\x07":return"\\a";case"\b":return"\\b";case"\f":return"\\f";case`
2
- `:return"\\n";case"\r":return"\\r";case" ":return"\\t";case"\v":return"\\v"}var i=r+1,o=i<t&&e[i]>="0"&&e[i]<="9"?"\\&":"";return"\\"+n.charCodeAt(0).toString(10)+o})+'"'},zo=e=>e,Ae=zo("LT"),ze=zo("GT"),Oe=zo("EQ"),E=(e,t)=>({tag:e,_1:t}),T=E("Nothing"),Xt=e=>E("Just",e),vu=e=>{if(e.tag==="Nothing")return!0;if(e.tag==="Just")return!1;c()},Gc=e=>{if(e.tag==="Nothing")return!1;if(e.tag==="Just")return!0;c()},kt=(e,t)=>({tag:e,_1:t}),Mc=e=>kt("Right",e),Wc={map:e=>t=>{if(t.tag==="Left")return kt("Left",t._1);if(t.tag==="Right")return kt("Right",e(t._1));c()}},Tu={apply:e=>t=>{if(e.tag==="Left")return kt("Left",e._1);if(e.tag==="Right"){if(t.tag==="Left")return kt("Left",t._1);if(t.tag==="Right")return kt("Right",e._1(t._1))}c()},Functor0:()=>Wc},Ac={bind:e=>{if(e.tag==="Left"){const t=e._1;return n=>kt("Left",t)}if(e.tag==="Right"){const t=e._1;return n=>n(t)}c()},Apply0:()=>Tu},zc={pure:Mc,Apply0:()=>Tu},Bc={Applicative0:()=>zc,Bind1:()=>Ac},$c=e=>e,Qc={map:e=>t=>e(t)},wu={apply:e=>t=>e(t),Functor0:()=>Qc},qc={bind:e=>t=>t(e),Apply0:()=>wu},Hc={pure:$c,Apply0:()=>wu},un={Applicative0:()=>Hc,Bind1:()=>qc},Yc=function(e){return function(){return e}},Vc={apply:e=>t=>()=>{const n=e(),r=t();return bu.pure(n(r))()},Functor0:()=>Oc},bu={pure:Yc,Apply0:()=>Vc},Oc={map:e=>t=>()=>{const n=t();return e(n)}},or=(e,t)=>({tag:e,_1:t}),ku=e=>or("Loop",e),Fc={tailRecM:e=>{const t=n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="Loop"){r=e(u._1);continue}if(u.tag==="Done"){i=!1,o=u._1;continue}c()}return o};return n=>t(e(n))},Monad0:()=>un},Xc=(function(e){return function(t){return function(n){return function(){return e(t,n)}}}})(function(e,t){return t.push(e)}),Uc=(e,t)=>({tag:"Iterator",_1:e,_2:t}),Kc=e=>t=>n=>()=>{let r=!1;const i=t._2;for(;!r;){const o=i.value,u=t._1(o);if(u.tag==="Just"&&e(u._1)){n.push(u._1),t._2.value;const s=t._2.value;t._2.value=s+1|0;continue}r=!0}},Zc=e=>t=>()=>{let n=!1;const r=e._2;for(;!n;){const i=r.value,o=r.value;r.value=o+1|0;const u=e._1(i);if(u.tag==="Just"){t(u._1)();continue}if(u.tag==="Nothing"){n=!0;continue}c()}},ir=function(e){return function(t){return function(n){for(var r=t,i=n.length,o=i-1;o>=0;o--)r=e(n[o])(r);return r}}},y=function(e){return function(t){return function(n){for(var r=t,i=n.length,o=0;o<i;o++)r=e(r)(n[o]);return r}}},jc=e=>{const t=e.Apply0();return n=>r=>n.foldr(i=>{const o=r(i);return u=>t.apply(t.Functor0().map(s=>Nu)(o))(u)})(e.pure())},At={foldr:ir,foldl:y,foldMap:e=>{const t=e.mempty;return n=>At.foldr(r=>i=>e.Semigroup0().append(n(r))(i))(t)}},x=(e,t)=>({tag:"Tuple",_1:e,_2:t}),In=e=>t=>x(e,t),$r=e=>e._2,Qr=e=>e._1,Dt=function(e){return function(t){for(var n=t.length,r=Array(n),i=0;i<n;i++)r[i]=e(i)(t[i]);return r}};var Bo=function(e){return function(t){return e===t}};const tf=Bo,ef=Bo,$o=Bo,nf=function(e){return function(t){return function(n){if(t.length!==n.length)return!1;for(var r=0;r<t.length;r++)if(!e(t[r])(n[r]))return!1;return!0}}},Fe={eq:$o},rf={eq:ef},Qo={eq:tf};var qo=function(e){return function(t){return function(n){return function(r){return function(i){return r<i?e:r===i?t:n}}}}};const of=qo,uf=qo,k={compare:qo(Ae)(Oe)(ze),Eq0:()=>Fe},lt={compare:uf(Ae)(Oe)(ze),Eq0:()=>rf},ot={compare:of(Ae)(Oe)(ze),Eq0:()=>Qo},Lu=function(e){return e},sf=(function(){function e(i){return[i]}function t(i){return function(o){return[i,o]}}function n(i){return function(o){return function(u){return[i,o,u]}}}function r(i){return function(o){return i.concat(o)}}return function(i){return function(o){return function(u){return function(s){return function(a){function f(g,d){switch(d-g){case 0:return u([]);case 1:return o(e)(s(a[g]));case 2:return i(o(t)(s(a[g])))(s(a[g+1]));case 3:return i(i(o(n)(s(a[g])))(s(a[g+1])))(s(a[g+2]));default:var l=g+Math.floor((d-g)/4)*2;return i(o(r)(f(g,l)))(f(l,d))}}return f(0,a.length)}}}}}})(),af=e=>e,qr={traverse:e=>{const t=e.Apply0();return sf(t.apply)(t.Functor0().map)(e.pure)},sequence:e=>qr.traverse(e)(af),Functor0:()=>Ic,Foldable1:()=>At},qt=function(e,t){for(var n=e>t?-1:1,r=new Array(n*(t-e)+1),i=e,o=0;i!==t;)r[o++]=i,i+=n;return r[o]=i,r};var cf=function(e,t){if(e<1)return[];var n=new Array(e);return n.fill(t)},ff=function(e,t){for(var n=[],r=0,i=0;i<e;i++)n[r++]=t;return n};const gf=typeof Array.prototype.fill=="function"?cf:ff,bt=(function(){function e(i,o){this.head=i,this.tail=o}var t={};function n(i){return function(o){return new e(i,o)}}function r(i){for(var o=[],u=0,s=i;s!==t;)o[u++]=s.head,s=s.tail;return o}return function(i,o){return r(i(n)(t)(o))}})(),Ht=function(e,t,n){return n.length===0?e({}):t(n[0])(n.slice(1))},_f=function(e,t,n,r){for(var i=0;i<r.length;i++){var o=n(r[i]);if(t(o))return o}return e},Dn=function(e,t,n,r){for(var i=0,o=r.length;i<o;i++)if(n(r[i]))return e(i);return t},df=function(e,t,n,r){for(var i=r.length-1;i>=0;i--)if(n(r[i]))return e(i);return t},lf=function(e,t,n,r,i){if(n<0||n>i.length)return t;var o=i.slice();return o.splice(n,0,r),e(o)},Eu=function(e,t,n,r){if(n<0||n>=r.length)return t;var i=r.slice();return i.splice(n,1),e(i)},Gn=function(e,t,n,r,i){if(n<0||n>=i.length)return t;var o=i.slice();return o[n]=r,e(o)},le=function(e){return e.slice().reverse()},Te=function(e){if(e.length<=1e4)return Array.prototype.concat.apply([],e);for(var t=[],n=0,r=e.length;n<r;n++)for(var i=e[n],o=0,u=i.length;o<u;o++)t.push(i[o]);return t},at=function(e,t){return t.filter(e)},hf=(function(){function e(t,n,r,i,o,u){var s,a,f,g,d,l,_;for(s=o+(u-o>>1),s-o>1&&e(t,n,i,r,o,s),u-s>1&&e(t,n,i,r,s,u),a=o,f=s,g=o;a<s&&f<u;)d=i[a],l=i[f],_=n(t(d)(l)),_>0?(r[g++]=l,++f):(r[g++]=d,++a);for(;a<s;)r[g++]=i[a++];for(;f<u;)r[g++]=i[f++]}return function(t,n,r){var i;return r.length<2?r:(i=r.slice(0),e(t,n,i,r.slice(0),0,r.length),i)}})(),Gt=function(e,t,n){return n.slice(e,t)},ye=function(e,t,n){for(var r=t.length<n.length?t.length:n.length,i=new Array(r),o=0;o<r;o++)i[o]=e(t[o])(n[o]);return i},sn=function(e,t){for(var n=t.length,r=0;r<n;r++)if(e(t[r]))return!0;return!1},Cu=function(e,t){for(var n=t.length,r=0;r<n;r++)if(!e(t[r]))return!1;return!0},vt=e=>t=>hf(e,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;c()},t),pf=e=>t=>vt(n=>r=>e.compare(t(n))(t(r))),de=e=>t=>(()=>{const n=Xc(t);return()=>{const r=[...e];return n(r)(),r}})()(),mf=e=>{if(e.length===0)return e.length-1|0,T;const t=e.length-1|0;return t>=0&&t<e.length?E("Just",{init:Gt(0,e.length-1|0,e),last:e[t]}):T},yf=e=>t=>n=>e>=0&&e<n.length?Gn(Xt,T,e,t(n[e]),n):T,pn=e=>t=>{const n=(r=>{let i=r,o=!0,u;for(;o;){const s=i;if(s>=0&&s<t.length){if(e(t[s])){i=s+1|0;continue}o=!1,u=E("Just",s);continue}o=!1,u=T}return u})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:t}:{init:Gt(0,n._1,t),rest:Gt(n._1,t.length,t)};if(n.tag==="Nothing")return{init:t,rest:[]};c()},Mn=e=>t=>{const n=vt(r=>i=>e(r._2)(i._2))(Dt(In)(t));return 0<n.length?V($r)(pf(ot)(Qr)((()=>{const r=[n[0]];for(const i of n){const o=e((()=>{const u=r.length-1|0;if(u>=0&&u<r.length)return r[u]._2;c()})())(i._2);(o==="LT"||o==="GT"||o!=="EQ")&&r.push(i)}return r})())):[]},Jf=e=>t=>{const n=[],r=Uc(i=>i>=0&&i<t.length?E("Just",t[i]):T,{value:0});return Zc(r)(i=>()=>{const o=[];o.push(i),Kc(e(i))(r)(o)(),n.push(o)})(),n},ge=e=>t=>{const n=Dn(Xt,T,e,t);return n.tag==="Just"?E("Just",t[n._1]):T},Su=e=>t=>at(e,t),Be=e=>t=>n=>{const r=Dn(Xt,T,i=>e.eq(i)(t),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;c()},Pu=e=>t=>St(t)(e),Pt=e=>Pu(t=>{const n=e(t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];c()}),Ru=isFinite;function Nf(e,t,n,r){var i=parseFloat(e);return t(i)?n(i):r}const Iu=Math.abs,xf=Math.ceil,Ho=Math.cos,Du=Math.exp,Gu=Math.floor,Yo=function(e){return function(t){return Math.pow(e,t)}},Mu=Math.round,Vo=Math.sin,Wn=Math.sqrt,vf=function(e){return function(t){return function(n){return(n|0)===n?e(n):t}}},ct=function(e){return e},Tf=(function(e){return function(t){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var i=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(o){if(i.test(o)){var u=parseInt(o,n);return(u|0)===u?e(u):t}else return t}}}})(Xt)(T)(10),Wu=vf(Xt)(T),ur=e=>{if(!Ru(e))return 0;if(e>=ct(2147483647))return 2147483647;if(e<=ct(-2147483648))return-2147483648;const t=Wu(e);if(t.tag==="Nothing")return 0;if(t.tag==="Just")return t._1;c()},zt=(e,t,n)=>({tag:e,_1:t,_2:n}),Qt=zt("Nil"),Yt={foldr:e=>t=>{const n=Yt.foldl(i=>o=>e(o)(i))(t),r=(i=>o=>{let u=i,s=o,a=!0,f;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,f=g;continue}if(d.tag==="Cons"){u=zt("Cons",d._1,g),s=d._2;continue}c()}return f})(Qt);return i=>n(r(i))},foldl:e=>t=>n=>{let r=t,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=e(s)(a._1),i=a._2;continue}c()}return u},foldMap:e=>{const t=e.mempty;return n=>Yt.foldl(r=>{const i=e.Semigroup0().append(r);return o=>i(n(o))})(t)}},wf=function(e){return function(t){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);u.push(n(a));var f=r(a);if(e(f))return u;s=t(f)}}}}}}},bf=e=>{if(e.tag==="Just")return e._1;c()},kf={unfoldr1:wf(vu)(bf)(Qr)($r)},Lf=function(e){return function(t){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);if(e(a))return u;var f=t(a);u.push(n(f)),s=r(f)}}}}}}},Ef=e=>{if(e.tag==="Just")return e._1;c()},Ie={unfoldr:Lf(vu)(Ef)(Qr)($r),Unfoldable10:()=>kf},Ft=(e,t,n,r,i,o,u)=>({tag:e,_1:t,_2:n,_3:r,_4:i,_5:o,_6:u}),De=(e,t,n,r)=>({tag:e,_1:t,_2:n,_3:r}),Hr=(e,t,n)=>({tag:"Split",_1:e,_2:t,_3:n}),Au=(e,t,n)=>({tag:"SplitLast",_1:e,_2:t,_3:n}),$=Ft("Leaf"),mn=De("IterLeaf"),jt=(e,t,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return Ft("Node",1,1,e,t,n,r);if(r.tag==="Node")return Ft("Node",1+r._1|0,1+r._2|0,e,t,n,r);c()}if(n.tag==="Node"){if(r.tag==="Leaf")return Ft("Node",1+n._1|0,1+n._2|0,e,t,n,r);if(r.tag==="Node")return Ft("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,e,t,n,r)}c()},Je=(e,t,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?Ft("Node",1,1,e,t,$,$):r.tag==="Node"&&r._1>1?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;c()})()?jt(r._5._3,r._5._4,jt(e,t,n,r._5._5),jt(r._3,r._4,r._5._6,r._6)):jt(r._3,r._4,jt(e,t,n,r._5),r._6):jt(e,t,n,r);if(n.tag==="Node")return r.tag==="Node"?r._1>(n._1+1|0)?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;c()})()?jt(r._5._3,r._5._4,jt(e,t,n,r._5._5),jt(r._3,r._4,r._5._6,r._6)):jt(r._3,r._4,jt(e,t,n,r._5),r._6):n._1>(r._1+1|0)?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;c()})()?jt(n._6._3,n._6._4,jt(n._3,n._4,n._5,n._6._5),jt(e,t,n._6._6,r)):jt(n._3,n._4,n._5,jt(e,t,n._6,r)):jt(e,t,n,r):r.tag==="Leaf"&&n._1>1?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;c()})()?jt(n._6._3,n._6._4,jt(n._3,n._4,n._5,n._6._5),jt(e,t,n._6._6,r)):jt(n._3,n._4,n._5,jt(e,t,n._6,r)):jt(e,t,n,r);c()},An=(e,t,n)=>{if(n.tag==="Leaf")return Hr(T,$,$);if(n.tag==="Node"){const r=e(t)(n._3);if(r==="LT"){const i=An(e,t,n._5);return Hr(i._1,i._2,Je(n._3,n._4,i._3,n._6))}if(r==="GT"){const i=An(e,t,n._6);return Hr(i._1,Je(n._3,n._4,n._5,i._2),i._3)}if(r==="EQ")return Hr(E("Just",n._4),n._5,n._6)}c()},zu=(e,t,n,r)=>{if(r.tag==="Leaf")return Au(e,t,n);if(r.tag==="Node"){const i=zu(r._3,r._4,r._5,r._6);return Au(i._1,i._2,Je(e,t,n,i._3))}c()},sr=(e,t)=>{if(e.tag==="Leaf")return t;if(e.tag==="Node"){const n=zu(e._3,e._4,e._5,e._6);return Je(n._1,n._2,n._3,t)}c()},Xe=(e,t,n)=>{if(t.tag==="Leaf")return $;if(n.tag==="Leaf")return t;if(n.tag==="Node"){const r=An(e,n._3,t);return sr(Xe(e,r._2,n._5),Xe(e,r._3,n._6))}c()},Yr=(e,t,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return $;if(r.tag==="Node"){const i=An(e,r._3,n),o=Yr(e,t,i._2,r._5),u=Yr(e,t,i._3,r._6);if(i._1.tag==="Just")return Je(r._3,t(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return sr(o,u)}c()},Ne=(e,t,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const i=An(e,r._3,n),o=Ne(e,t,i._2,r._5),u=Ne(e,t,i._3,r._6);if(i._1.tag==="Just")return Je(r._3,t(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return Je(r._3,r._4,o,u)}c()},Cf=e=>t=>{const n=r=>{if(r.tag==="Leaf")return $;if(r.tag==="Node"){const i=t(r._3)(r._4);if(i.tag==="Just")return Je(r._3,i._1,n(r._5),n(r._6));if(i.tag==="Nothing")return sr(n(r._5),n(r._6))}c()};return n},yn=(e=>t=>n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="IterLeaf"){i=!1,o=t();continue}if(u.tag==="IterEmit"){i=!1,o=e(u._1,u._2,u._3);continue}if(u.tag==="IterNode"){r=(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Leaf"){d=!1,l=_;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){f=De("IterEmit",h._3,h._4,_),g=h._5;continue}f=De("IterEmit",h._3,h._4,De("IterNode",h._6,_)),g=h._5;continue}c()}return l})(u._2)(u._1);continue}c()}return o})((e,t,n)=>E("Just",x(x(e,t),n)))(e=>T),Tt=e=>t=>n=>r=>{const i=o=>{if(o.tag==="Leaf")return Ft("Node",1,1,n,r,$,$);if(o.tag==="Node"){const u=e.compare(n)(o._3);if(u==="LT")return Je(o._3,o._4,i(o._5),o._6);if(u==="GT")return Je(o._3,o._4,o._5,i(o._6));if(u==="EQ")return Ft("Node",o._1,o._2,n,t(o._4)(r),o._5,o._6)}c()};return i},Z=e=>t=>n=>{const r=i=>{if(i.tag==="Leaf")return Ft("Node",1,1,t,n,$,$);if(i.tag==="Node"){const o=e.compare(t)(i._3);if(o==="LT")return Je(i._3,i._4,r(i._5),i._6);if(o==="GT")return Je(i._3,i._4,i._5,r(i._6));if(o==="EQ")return Ft("Node",i._1,i._2,t,n,i._5,i._6)}c()};return r},te=e=>t=>t.foldl(n=>r=>Z(e)(r._1)(r._2)(n))($),ar=e=>t=>{const n=r=>{if(r.tag==="Leaf")return $;if(r.tag==="Node"){const i=e.compare(t)(r._3);if(i==="LT")return Je(r._3,r._4,n(r._5),r._6);if(i==="GT")return Je(r._3,r._4,r._5,n(r._6));if(i==="EQ")return sr(r._5,r._6)}c()};return n},Sf=e=>{const t=e.compare;return n=>r=>i=>{const o=An(t,r,i),u=n(o._1);if(u.tag==="Nothing")return sr(o._2,o._3);if(u.tag==="Just")return Je(r,u._1,o._2,o._3);c()}},Zt=function(e){return function(t){return e+t|0}},cr=function(e){return function(t){return e+t}},Oo=function(e){return function(t){if(t===0)return 0;var n=Math.abs(t);return(e%n+n)%n}},Pf=function(e){return function(t){return e+t}},se=function(e){return function(t){return e.length===0?t:t.length===0?e:e.concat(t)}},Rf={append:Pf},If={mempty:"",Semigroup0:()=>Rf};function Df(e,t,n){return e==null?t:n(e)}function Fo(e){return function(t){return function(n){return e.apply(n,[t])}}}const Gf=Fo(Number.prototype.toPrecision),Mf=Fo(Number.prototype.toFixed),Wf=Fo(Number.prototype.toExponential),fr=(e,t)=>({tag:e,_1:t}),gr=e=>t=>n=>{const r=ot.compare(e)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),o=ot.compare(t)(i);if(o==="LT"||o==="EQ")return t;if(o==="GT")return i;c()},_r=e=>{if(e.tag==="Precision")return Gf(e._1);if(e.tag==="Fixed")return Mf(e._1);if(e.tag==="Exponential")return Wf(e._1);c()},Bu=function(e){return function(){console.log(e)}};function $u(){return Date.now()}function Af(e){return function(){return e.getContext("2d")}}function zf(e){return function(){return e.width}}function Bf(e){return function(){return e.height}}function $f(e){return function(t){return function(){e.width=t}}}function Qf(e){return function(t){return function(){e.height=t}}}function Xo(e){return function(t){return function(){e.lineWidth=t}}}function qf(e){return function(t){return function(){e.fillStyle=t}}}function Hf(e){return function(t){return function(){e.strokeStyle=t}}}function Uo(e){return function(t){return function(){e.lineCap=t}}}function Ko(e){return function(t){return function(){e.lineJoin=t}}}function Yf(e){return function(t){return function(){e.globalCompositeOperation=t}}}function Vf(e){return function(t){return function(){e.globalAlpha=t}}}function Qu(e){return function(){e.beginPath()}}function Zo(e){return function(){e.stroke()}}function jo(e){return function(){e.fill()}}function Of(e){return function(){e.clip()}}function Ff(e){return function(t){return function(n){return function(){e.lineTo(t,n)}}}}function Xf(e){return function(t){return function(n){return function(){e.moveTo(t,n)}}}}function Uf(e){return function(){e.closePath()}}function Kf(e){return function(t){return function(){e.fillRect(t.x,t.y,t.width,t.height)}}}function Zf(e){return function(t){return function(){e.clearRect(t.x,t.y,t.width,t.height)}}}function ti(e){return function(t){return function(){e.scale(t.scaleX,t.scaleY)}}}function qu(e){return function(t){return function(){e.translate(t.translateX,t.translateY)}}}function jf(e){return function(t){return function(){e.textAlign=t}}}function tg(e){return function(t){return function(){e.textBaseline=t}}}function eg(e){return function(t){return function(){e.font=t}}}function ng(e){return function(t){return function(n){return function(r){return function(){e.fillText(t,n,r)}}}}}function dr(e){return function(){e.save()}}function lr(e){return function(){e.restore()}}function rg(e){return function(t){return function(){e.quadraticCurveTo(t.cpx,t.cpy,t.x,t.y)}}}function og(e){return function(t){return function(){e.bezierCurveTo(t.cp1x,t.cp1y,t.cp2x,t.cp2y,t.x,t.y)}}}const Hu=e=>e,ei=e=>e,ni=e=>e,ri=e=>e,Vr=e=>e,ig=Vr("BaselineTop"),ug=Vr("BaselineMiddle"),sg=Vr("BaselineAlphabetic"),ag=Vr("BaselineBottom"),cg=ri("AlignLeft"),fg=ri("AlignRight"),gg=ri("AlignCenter"),oi=ni("BevelJoin"),Or=ni("RoundJoin"),ii=ni("MiterJoin"),ui=ei("Round"),si=ei("Square"),ai=ei("Butt"),_g=Hu("SourceOver"),dg=Hu("Difference"),lg=e=>t=>tg(e)((()=>{if(t==="BaselineTop")return"top";if(t==="BaselineHanging")return"hanging";if(t==="BaselineMiddle")return"middle";if(t==="BaselineAlphabetic")return"alphabetic";if(t==="BaselineIdeographic")return"ideographic";if(t==="BaselineBottom")return"bottom";c()})()),hg=e=>t=>jf(e)((()=>{if(t==="AlignLeft")return"left";if(t==="AlignRight")return"right";if(t==="AlignCenter")return"center";if(t==="AlignStart")return"start";if(t==="AlignEnd")return"end";c()})()),Fr=e=>t=>{if(t==="BevelJoin")return Ko(e)("bevel");if(t==="RoundJoin")return Ko(e)("round");if(t==="MiterJoin")return Ko(e)("miter");c()},ci=e=>t=>{if(t==="Round")return Uo(e)("round");if(t==="Square")return Uo(e)("square");if(t==="Butt")return Uo(e)("butt");c()},Yu=e=>t=>Yf(e)((()=>{if(t==="SourceOver")return"source-over";if(t==="SourceIn")return"source-in";if(t==="SourceOut")return"source-out";if(t==="SourceAtop")return"source-atop";if(t==="DestinationOver")return"destination-over";if(t==="DestinationIn")return"destination-in";if(t==="DestinationOut")return"destination-out";if(t==="DestinationAtop")return"destination-atop";if(t==="Lighter")return"lighter";if(t==="Copy")return"copy";if(t==="Xor")return"xor";if(t==="Multiply")return"multiply";if(t==="Screen")return"screen";if(t==="Overlay")return"overlay";if(t==="Darken")return"darken";if(t==="Lighten")return"lighten";if(t==="ColorDodge")return"color-dodge";if(t==="ColorBurn")return"color-burn";if(t==="HardLight")return"hard-light";if(t==="SoftLight")return"soft-light";if(t==="Difference")return"difference";if(t==="Exclusion")return"exclusion";if(t==="Hue")return"hue";if(t==="Saturation")return"saturation";if(t==="Color")return"color";if(t==="Luminosity")return"luminosity";c()})()),ke={foldr:e=>t=>{const n=Yt.foldr(e)(t);return r=>n((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,zt("Cons",o._3,i(o._6,u)));c()};return i(r,Qt)})())}},Xr=e=>e,pg=e=>e,mg=Xr("Linear"),yg=Xr("EaseInOutQuad"),Jg=Xr("EaseOutExpo"),Ng=Xr("SpringBouncy"),hr=e=>t=>n=>{const r=Wn(1-t*t),i=e*r;return 1-Du(-t*e*n)*(Ho(i*n)+t/r*Vo(i*n))},xg=e=>{const t=lt.compare(0)(e),n=(()=>{if(t==="LT")return e;if(t==="EQ"||t==="GT")return 0;c()})(),r=lt.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;c()},fi=e=>t=>(()=>{if(e==="Linear")return pg;if(e==="EaseInQuad")return n=>n*n;if(e==="EaseOutQuad")return n=>1-(1-n)*(1-n);if(e==="EaseInOutQuad")return n=>n<.5?2*n*n:1-2*(1-n)*(1-n);if(e==="EaseInCubic")return n=>n*n*n;if(e==="EaseOutCubic")return n=>1-(1-n)*(1-n)*(1-n);if(e==="EaseInOutCubic")return n=>n<.5?4*n*n*n:1-(-2*n+2)*(-2*n+2)*(-2*n+2)/2;if(e==="EaseOutExpo")return n=>n>=1?1:1-Yo(2)(-10*n);if(e==="Spring")return n=>1-(1+6*n)*Du(-6*n);if(e==="SpringBouncy")return hr(6)(.7);c()})()(xg(t)),Vu=y(cr)(0),vg=e=>t=>n=>{const r=lt.compare(e)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),o=lt.compare(t)(i);if(o==="LT"||o==="EQ")return t;if(o==="GT")return i;c()},Ou=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Fu=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Xu=e=>t=>{const n=ye(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,f=s.x-u.x;return Wn(f*f+a*a)})()}),e,Gt(1,e.length,e)),r=Vu(V(u=>u.len)(n)),i=vg(0)(r)(t*r),o=u=>s=>a=>{let f=u,g=s,d=a,l=!0,_;for(;l;){const h=f,p=g,m=d,N=Ht(J=>T,J=>v=>E("Just",{head:J,tail:v}),h);if(N.tag==="Nothing"){const J=e.length-1|0;if(J>=0&&J<e.length){l=!1,_=e[J];continue}l=!1,_=m;continue}if(N.tag==="Just"){if(p<=N._1.head.len){const J=N._1.head.len<=0?0:p/N._1.head.len;l=!1,_={x:N._1.head.a.x+(N._1.head.b.x-N._1.head.a.x)*J,y:N._1.head.a.y+(N._1.head.b.y-N._1.head.a.y)*J};continue}f=N._1.tail,g=p-N._1.head.len,d=m;continue}c()}return _};return 0<e.length?E("Just",o(n)(i)(e[0])):T},gi=e=>Vu(ye(t=>n=>{const r=n.y-t.y,i=n.x-t.x;return Wn(i*i+r*r)},e,Gt(1,e.length,e))),an=e=>{const t=Ht(n=>T,n=>r=>E("Just",{head:n,tail:r}),[...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._4,n(r._6,i)));c()};return St(bt(Yt.foldr,n(e.nodes,Qt)))(r=>[{x:r.x,y:r.y},{x:r.x+r.w,y:r.y+r.h}])})(),...Te((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._4,n(r._6,i)));c()};return bt(Yt.foldr,n(e.edges,Qt))})()),...Te((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._4,n(r._6,i)));c()};return bt(Yt.foldr,n(e.chipExtras,Qt))})())]);if(t.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(t.tag==="Just"){const n=y(r=>i=>({minX:Ou(r.minX)(i.x),minY:Ou(r.minY)(i.y),maxX:Fu(r.maxX)(i.x),maxY:Fu(r.maxY)(i.y)}))({minX:t._1.head.x,minY:t._1.head.y,maxX:t._1.head.x,maxY:t._1.head.y})(t._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},pr=function(e){return function(t){if(e>=0&&e<t.length)return t.charAt(e);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},zn=function(e){return e.join("")},Uu=function(e){return e.split("")},_i=function(e){return e},Jn=function(e){return e.length},Ku=function(e){return function(t){return t.substr(0,e)}},mr=function(e){return function(t){return t.substring(e)}},Tg=function(e){return function(t){return{before:t.substring(0,e),after:t.substring(e)}}},wg=e=>t=>{const n=Tg(Jn(e))(t);return n.before===e?E("Just",n.after):T},bg=e=>t=>n=>{try{var r=BigInt(n);return e(r)}catch{return t}},kg=e=>t=>n=>{try{var r=BigInt(n);return e(r)}catch{return t}},Nn=e=>BigInt(e),Lg=e=>Number(e),Ur=e=>t=>e+t,Kr=e=>t=>e*t,di=e=>t=>e-t,Zu=0n,Zr=1n,ju=e=>t=>e^t,yr=e=>t=>e&t,li=e=>t=>e<<t,hi=e=>t=>e>>t,Eg=e=>t=>e==t,Cg=e=>t=>e===t?0:e>t?1:-1,Sg={eq:Eg},ts={compare:e=>t=>{const n=Cg(e)(t);return n===1?ze:n===0?Oe:Ae},Eq0:()=>Sg},Pg=bg(Xt)(T),Rg=kg(Xt)(T),Ig=e=>t=>Iu(e._1-t._1)+Iu(e._2-t._2),jr=e=>e,ae=jr("North"),ce=jr("South"),xn=jr("East"),vn=jr("West"),es=e=>e,ns=(e,t)=>({tag:e,_1:t}),rs=(e,t)=>({tag:e,_1:t}),pi=(e,t)=>({tag:e,_1:t}),Dg=pi("First"),Gg=es("Forward"),Mg=es("Backward"),Wg=te(k)(At),Ag=e=>ir(t=>n=>({nodes:Ne(k.compare,me,t.nodes,n.nodes),edges:Ne(k.compare,me,t.edges,n.edges)}))({nodes:$,edges:$})(e.keyframes),zg=e=>t=>({entering:{nodes:Xe(k.compare,t.nodes,e.nodes),edges:Xe(k.compare,t.edges,e.edges)},leaving:{nodes:Xe(k.compare,e.nodes,t.nodes),edges:Xe(k.compare,e.edges,t.edges)},surviving:{nodes:Yr(k.compare,me,e.nodes,t.nodes),edges:Yr(k.compare,me,e.edges,t.edges)}}),os=e=>e,mi=e=>t=>n=>{const r=lt.compare(e)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),o=lt.compare(t)(i);if(o==="LT"||o==="EQ")return t;if(o==="GT")return i;c()},Tn=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Bn=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},$n=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},yi=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Bg=y(e=>t=>Z(k)(t)()(e))($),$g=y(e=>t=>Z(k)(t)()(e))($),Qg=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),is=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},us=te(k)(At),qg=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Hg=os("Hold"),Yg=os("Gap"),Vg=e=>t=>n=>{const r=n.center.y-t.center.y,i=n.center.x-t.center.x,o=Wn(i*i+r*r),u=n.zoom-t.zoom,s=u<0?-u:u;return mi(e.minTransition)(e.maxTransition)(Tn(e.panSpeed<=0?e.minTransition:o/e.panSpeed)(e.zoomSpeed<=0?e.minTransition:s/e.zoomSpeed))},Og=y(e=>t=>{const n=e.length-1|0;return n>=0&&n<e.length&&e[n]===t?e:de(e)(t)})([]),Ji=e=>{const t=Ht(n=>T,n=>r=>E("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(t.tag==="Just"){const n=y(r=>i=>({minX:Bn(r.minX)(i.x),minY:Bn(r.minY)(i.y),maxX:Tn(r.maxX)(i.x),maxY:Tn(r.maxY)(i.y)}))({minX:t._1.head.x,minY:t._1.head.y,maxX:t._1.head.x,maxY:t._1.head.y})(t._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},ss=e=>{const t=Ht(n=>T,n=>r=>E("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return T;if(t.tag==="Just")return E("Just",Ji(e));c()},Fg=e=>t=>n=>Bg(St(bt(ke.foldr,n))(r=>{const i=$n(r)(e);if(i.tag==="Just")return at(o=>!yi(o)(t),[i._1.source,i._1.target]);if(i.tag==="Nothing")return[];c()})),Xg=e=>t=>n=>{const r=fi(e.easing)(mi(0)(1)(n.endT<=n.startT?1:(t-n.startT)/(n.endT-n.startT)));return{center:{x:n.fromCam.center.x+(n.toCam.center.x-n.fromCam.center.x)*r,y:n.fromCam.center.y+(n.toCam.center.y-n.fromCam.center.y)*r},zoom:n.fromCam.zoom+(n.toCam.zoom-n.fromCam.zoom)*r}},Ug=e=>t=>n=>r=>{const i=(u,s)=>Bn(Vg(e)(u.toCam)(s.toCam))(u.endT-u.startT),o=y(u=>s=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:E("Just",s)};if(u.pending.tag==="Just")return!(s.fromCam.zoom===s.toCam.zoom&&s.fromCam.center.x===s.toCam.center.x&&s.fromCam.center.y===s.toCam.center.y)||(()=>{const a=u.pending._1.toCam.center.x-s.toCam.center.x;return(a<0?-a<8:a<8)&&(()=>{const f=u.pending._1.toCam.center.y-s.toCam.center.y;return(f<0?-f<8:f<8)&&(()=>{const g=u.pending._1.toCam.zoom-s.toCam.zoom;return g<0?-g<.08:g<.08})()})()})()||i(u.pending._1,s)<=0?{acc:de(u.acc)(u.pending._1),pending:E("Just",s)}:{acc:de(de(u.acc)({...u.pending._1,endT:s.startT-i(u.pending._1,s)}))({startT:s.startT-i(u.pending._1,s),endT:s.startT,fromCam:u.pending._1.toCam,toCam:s.toCam}),pending:E("Just",s)};c()})({acc:[],pending:T})(r);if(o.pending.tag==="Nothing")return o.acc;if(o.pending.tag==="Just")return de(o.acc)(o.pending._1);c()},Kg=e=>e.kind.tag==="SendToken"?E("Just",x(e.kind._1.edge,{source:e.kind._1.from,target:e.kind._1.to})):T,Zg=e=>e.tag==="DataFlow"?Pt(Kg)(e._1.events):[],jg=e=>t=>$g(Pt(n=>yi(n._2.source)(t)||yi(n._2.target)(t)?E("Just",n._1):T)(Qg(e))),t_=e=>t=>{const n=r=>{const i=df(Xt,T,o=>o.kind==="Hold",r<1?[]:Gt(0,r,t));if(i.tag==="Just")return i._1>=0&&i._1<t.length?E("Just",t[i._1].cam):T;if(i.tag==="Nothing")return T;c()};return Dt(r=>i=>{if(i.kind==="Hold")return{startT:i.startT,endT:i.endT,fromCam:i.cam,toCam:i.cam};if(i.kind==="Gap")return{startT:i.startT,endT:i.endT,fromCam:(()=>{const o=n(r);if(o.tag==="Nothing")return e;if(o.tag==="Just")return o._1;c()})(),toCam:(()=>{const o=n(r),u=(()=>{if(o.tag==="Nothing")return e;if(o.tag==="Just")return o._1;c()})(),s=r+1|0,a=Dn(Xt,T,f=>f.kind==="Hold",s<1?t:Gt(s,t.length,t));if(a.tag==="Just"){const f=(r+1|0)+a._1|0;return f>=0&&f<t.length?t[f].cam:u}if(a.tag==="Nothing")return u;c()})()};c()})(t)},as={padding:24,easing:Jg,minZoom:.9,maxZoom:2.5,panSpeed:700,zoomSpeed:1.5,minTransition:.3,maxTransition:1.4},e_=e=>t=>n=>{const r=t.w+n*2,i=t.h+n*2,o=an(e);return r<=0||i<=0||o.w<=0||o.h<=0?1:Bn(o.w/r)(o.h/i)},Ni=e=>{const t=Ht(n=>T,n=>r=>E("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(t.tag==="Just"){const n=y(r=>i=>({minX:Bn(r.minX)(i.x),minY:Bn(r.minY)(i.y),maxX:Tn(r.maxX)(i.x+i.w),maxY:Tn(r.maxY)(i.y+i.h)}))({minX:t._1.head.x,minY:t._1.head.y,maxX:t._1.head.x+t._1.head.w,maxY:t._1.head.y+t._1.head.h})(t._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},cs=e=>t=>n=>{if(n.tag==="Leaf")return an(e);const r=jg(t)(n),i=[...Pt(o=>{const u=is(o)(e.nodes);return u.tag==="Just"?E("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):T})(bt(ke.foldr,Ne(k.compare,me,n,Fg(t)(n)(r)))),...Pt(o=>{const u=$n(o)(e.edges);return u.tag==="Just"?E("Just",Ji(u._1)):T})(bt(ke.foldr,r)),...Pt(o=>{const u=$n(o)(e.chipExtras);if(u.tag==="Just")return ss(u._1);if(u.tag==="Nothing")return T;c()})(bt(ke.foldr,r))];return i.length===0?an(e):Ni(i)},n_=e=>t=>n=>r=>{const i=[...Pt(o=>o)([(()=>{const o=$n(n)(e.edges);return o.tag==="Just"?E("Just",Ji(o._1)):T})(),(()=>{const o=$n(n)(e.chipExtras);if(o.tag==="Just")return ss(o._1);if(o.tag==="Nothing")return T;c()})()]),...(()=>{const o=$n(n)(t);if(o.tag==="Just")return Pt(u=>{const s=is(u)(e.nodes);return s.tag==="Just"?E("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):T})([o._1.source,o._1.target]);if(o.tag==="Nothing")return[];c()})()];return i.length===0?cs(e)(t)(r):Ni(i)},r_=y(e=>t=>{const n=e.length-1|0,r=n>=0&&n<e.length?E("Just",e[n]):T;return r.tag==="Just"&&r._1.fromCam.zoom===r._1.toCam.zoom&&r._1.fromCam.center.x===r._1.toCam.center.x&&r._1.fromCam.center.y===r._1.toCam.center.y&&t.fromCam.zoom===t.toCam.zoom&&t.fromCam.center.x===t.toCam.center.x&&t.fromCam.center.y===t.toCam.center.y&&(()=>{const i=r._1.toCam.center.x-t.toCam.center.x;return(i<0?-i<8:i<8)&&(()=>{const o=r._1.toCam.center.y-t.toCam.center.y;return(o<0?-o<8:o<8)&&(()=>{const u=r._1.toCam.zoom-t.toCam.zoom;return u<0?-u<.08:u<.08})()})()})()?de((()=>{const i=e.length-1|0;return i<1?[]:Gt(0,i,e)})())({...r._1,endT:t.endT}):de(e)(t)})([]),fs=e=>t=>{const n=an(e),r=n.w/Tn(1e-4)(t.zoom),i=n.h/Tn(1e-4)(t.zoom);return{x:t.center.x-r/2,y:t.center.y-i/2,w:r,h:i}},o_=e=>Ne(k.compare,me,us(V(t=>x(t.id,{source:t.from.node,target:t.to.node}))(e.graph.edges)),us(St(e.scenes)(Zg))),xi=e=>t=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:mi(e.minZoom)(e.maxZoom)(e_(t)(n)(e.padding))}),i_=e=>t=>n=>r=>{const i=xi(e)(t)(an(t)),o=at(u=>u>=0&&u<=n,Og(vt(lt.compare)([0,n,...St(r)(u=>[u.startT,u.endT])])));return Ug(e)(t)(i)(r_(t_(i)(Pt(u=>{const s=(u._1+u._2)/2;if(u._2<=u._1)return T;const a=y(qg)(0)(V(g=>g.priority)(at(g=>g.startT<=s&&s<g.endT,r))),f=V(g=>g.bbox)(at(g=>g.priority===a,at(g=>g.startT<=s&&s<g.endT,r)));return f.length===0?E("Just",{kind:Yg,startT:u._1,endT:u._2,cam:i}):E("Just",{kind:Hg,startT:u._1,endT:u._2,cam:xi(e)(t)(Ni(f))})})(ye(In,o,Gt(1,o.length,o))))))},u_=e=>t=>n=>r=>{const i=ge(o=>r>=o.startT&&r<o.endT)(n);if(i.tag==="Just")return Xg(e)(r)(i._1);if(i.tag==="Nothing"){const o=n.length-1|0;if(o>=0&&o<n.length&&r>=n[o].endT)return n[o].toCam;const u=xi(e)(t)(an(t));return 0<n.length?n[0].fromCam:u}c()};function Jr(e){return e.charCodeAt(0)}function gs(e){return String.fromCharCode(e)}const cn=function(e){return function(t){return function(n){return n.replace(new RegExp(e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),t)}}},vi=function(e){return function(t){return t.split(e)}},s_=function(e){return e.trim()},Ti=function(e){return function(t){return t.join(e)}};var a_=typeof Array.from=="function",c_=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",f_=typeof String.prototype.fromCodePoint=="function",g_=typeof String.prototype.codePointAt=="function";const __=function(e){return g_?function(t){return t.codePointAt(0)}:e},d_=function(e){return f_?String.fromCodePoint:e},l_=function(e){return function(t){return c_?function(n){for(var r="",i=n[Symbol.iterator](),o=0;o<t;++o){var u=i.next();if(u.done)return r;r+=u.value}return r}:e(t)}},h_=function(e){return function(t){return a_?function(n){return Array.from(n,t)}:e}},to=e=>{const t=Jn(e);if(t===0)return T;if(t===1)return E("Just",{head:Jr(pr(0)(e)),tail:""});const n=Jr(pr(1)(e)),r=Jr(pr(0)(e));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?E("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:mr(2)(e)}):E("Just",{head:r,tail:mr(1)(e)})},p_=e=>{const t=to(e);return t.tag==="Just"?E("Just",x(t._1.head,t._1.tail)):T},m_=e=>Ie.unfoldr(p_)(e),_s=__(e=>{const t=Jr(pr(0)(e));if(55296<=t&&t<=56319&&Jn(e)>1){const n=Jr(pr(1)(e));if(56320<=n&&n<=57343)return(((t-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return t}),wi=h_(m_)(_s),bi=e=>_i(e>=0&&e<=65535?gs(e):e<0?"\0":"\uFFFF"),y_=d_(e=>e<=65535?bi(e):bi(Rn(e-65536|0,1024)+55296|0)+bi(Oo(e-65536|0)(1024)+56320|0)),ds=e=>t=>{if(e<1)return"";const n=to(t);return n.tag==="Just"?y_(n._1.head)+ds(e-1|0)(n._1.tail):t},ie=l_(ds),J_=e=>t=>t===""?T:E("Just",_s(t)),eo=(e,t,n)=>({tag:e,_1:t,_2:n}),N_=()=>({tag:"ExtendFromSource"}),no=(e,t)=>({tag:e,_1:t}),ki=e=>e,ro=(e,t)=>({tag:e,_1:t}),Li=ro("NotYet"),ls=ro("Consumed"),x_=ki("FromSource"),hs=ki("FromTarget"),v_=ki("FromBoth"),ps=no("Hidden"),T_=no("Visible"),ms=N_(),ys=eo("Retracted"),w_=eo("Extended"),Ei=(e,t)=>({tag:e,_1:t}),Qn=(e,t,n)=>({tag:e,_1:t,_2:n}),Js=e=>e,wn=(e,t)=>({tag:e,_1:t}),qn=(e,t,n,r,i,o,u,s,a)=>({tag:e,_1:t,_2:n,_3:r,_4:i,_5:o,_6:u,_7:s,_8:a}),Ns=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},oo=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},fn=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Nr=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},xs=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},vs=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Hn=(()=>{const e=Ie.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return E("Just",x(t._1,t._2));c()});return t=>e((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._3,n(r._6,i)));c()};return n(t,Qt)})())})(),b_=y(e=>t=>Z(k)(t)()(e))($),Ci=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},k_=te(k)(At),L_=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Si=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},E_=wn("NoKeyframes"),C_=e=>wn("DuplicateEventId",e),S_=e=>wn("UnknownEvent",e),Ts=Js("PlopIn"),P_=Js("PlopOut"),R_=e=>t=>Pt(n=>{if(n.target.tag==="NodeWindow"||n.target.tag==="EdgeWindow")return T;if(n.target.tag==="TokenWindow")return E("Just",{startT:n.startT,endT:n.endT,bbox:n_(e)(t)(n.target._2)($),priority:1});if(n.target.tag==="FillWindow")return E("Just",{startT:n.startT,endT:n.endT,bbox:cs(e)(t)(Ft("Node",1,1,n.target._2,void 0,$,$)),priority:1});c()}),I_=e=>t=>n=>r=>i=>{const o=ct(y(f=>g=>f+wi(g).length|0)(0)(n.labels))*e.tokenReadSecPerChar,u=f=>{const g=Ns(f)(t.nodes);if(g.tag==="Just")return{x:g._1.x+g._1.w/2,y:g._1.y+g._1.h/2};if(g.tag==="Nothing")return{x:0,y:0};c()},s=oo(n.edge)(t.edges),a=(()=>{if(s.tag==="Just"){const f=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return le(s._1);c()})(),g=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return le(s._1);c()})(),d=u(n.from),l=g.length-1|0;return(2*(()=>{const _=0<f.length?f[0]:u(n.from),h=_.x-d.x,p=_.y-d.y;return(h<0?-h:h)+(p<0?-p:p)})()+gi(s._1)+2*(()=>{const _=l>=0&&l<g.length?g[l]:u(n.to),h=u(n.to),p=h.x-_.x,m=h.y-_.y;return(p<0?-p:p)+(m<0?-m:m)})())/e.tokenSpeed}if(s.tag==="Nothing")return 0/e.tokenSpeed;c()})();return e.tokenSpeed<=0?e.minTokenDuration:fn(e.minTokenDuration)(fn(a)(o)/fn(.05)(1-r-i))},D_=e=>{if(e.event.kind.tag==="SendToken")return E("Just",{startT:e.startT,endT:e.endT,target:qn("TokenWindow",e.event.id,e.event.kind._1.edge,e.event.kind._1.direction,e.event.kind._1.from,e.event.kind._1.to,e.event.kind._1.labels,e.holdPre,e.holdPost)});if(e.event.kind.tag==="FillNodeWithoutTransition")return E("Just",{startT:e.startT,endT:e.endT,target:qn("FillWindow",e.event.id,e.event.kind._1.node,e.event.kind._1.labels)});c()},G_=e=>t=>n=>Pt(r=>{const i=Pt(o=>Ns(o)(e.nodes))(bt(ke.foldr,(()=>{if(r.scene.tag==="Structural")return Ne(k.compare,me,(()=>{const o=Nr(r.scene._1.from)(n);if(o.tag==="Nothing")return $;if(o.tag==="Just")return o._1.nodes;c()})(),(()=>{const o=Nr(r.scene._1.to)(n);if(o.tag==="Nothing")return $;if(o.tag==="Just")return o._1.nodes;c()})());if(r.scene.tag==="DataFlow"){const o=Nr(r.scene._1.keyframe)(n);if(o.tag==="Nothing")return $;if(o.tag==="Just")return o._1.nodes}c()})()));return i.length===0?T:E("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const o=y(u=>s=>({minX:xs(u.minX)(s.x),minY:xs(u.minY)(s.y),maxX:fn(u.maxX)(s.x+s.w),maxY:fn(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})(Gt(1,i.length,i));return{x:o.minX,y:o.minY,w:o.maxX-o.minX,h:o.maxY-o.minY}})(),priority:0})}),M_=e=>t=>n=>{const r=oo(n)(e);if(r.tag==="Nothing")return hs;if(r.tag==="Just"){const i=vs(r._1.target)(t);return vs(r._1.source)(t)?i?v_:x_:hs}c()},W_=e=>t=>n=>r=>{const i=(()=>{if(r.event.when.tag==="First")return 0;if(r.event.when.tag==="At")return r.event.when._1;if(r.event.when.tag==="After"){const o=r.event.when._1,u=ge(s=>s.event.id===o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.endT;c()}if(r.event.when.tag==="With"){const o=r.event.when._1,u=ge(s=>s.event.id===o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.startT}c()})();return de(n)({startT:i,endT:(()=>{if(r.event.kind.tag==="SendToken")return i+I_(e)(t)(r.event.kind._1)(r.holdPre)(r.holdPost);if(r.event.kind.tag==="FillNodeWithoutTransition")return i+e.plop;c()})(),event:r.event,holdPre:r.holdPre,holdPost:r.holdPost})},Pi=e=>t=>{if(t<0)return Qn("AtKeyframe",e.initialKeyframe);if(t>=e.totalDuration){const r=e.spans.length-1|0;return r>=0&&r<e.spans.length?Qn("AtKeyframe",(()=>{if(e.spans[r].scene.tag==="Structural")return e.spans[r].scene._1.to;if(e.spans[r].scene.tag==="DataFlow")return e.spans[r].scene._1.keyframe;c()})()):Qn("AtKeyframe",e.initialKeyframe)}const n=ge(r=>t>=r.startT&&t<r.endT)(e.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Qn("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Qn("AtKeyframe",n._1.scene._1.keyframe);c()}if(n.tag==="Nothing")return Qn("AtKeyframe",e.initialKeyframe);c()},A_=e=>{if(e.when.tag==="First")return[];if(e.when.tag==="At")return[];if(e.when.tag==="After")return[e.when._1];if(e.when.tag==="With")return[e.when._1];c()},ws={id:"",nodes:$,edges:$},z_=e=>t=>zg((()=>{const n=Nr(t.from)(e);if(n.tag==="Nothing")return ws;if(n.tag==="Just")return n._1;c()})())((()=>{const n=Nr(t.to)(e);if(n.tag==="Nothing")return ws;if(n.tag==="Just")return n._1;c()})()),Ri=e=>t=>n=>r=>{const i=oo(r)(n.edges);if(i.tag==="Just")return e<=0?t:fn(t)(gi(i._1)/e);if(i.tag==="Nothing")return t;c()},bs=e=>t=>n=>r=>i=>{const o=e.plop,u=z_(n)(i),s=V(_=>({startT:0,endT:0+Ri(e.edgeSpeed)(e.minEdgeDuration)(t)(_),target:qn("EdgeWindow",_,Ei("Extend",ms))}))(Hn(u.entering.edges)),a=V(_=>({startT:0,endT:o,target:qn("NodeWindow",_,Ts)}))(Hn(u.entering.nodes)),f=y(fn)(0)(V(_=>Ri(e.edgeSpeed)(e.minEdgeDuration)(t)(_))(Hn(u.leaving.edges))),g=_=>sn(h=>{const p=oo(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;c()},Hn(u.leaving.edges))?f:0,d=V(_=>({startT:g(_),endT:g(_)+e.plop,target:qn("NodeWindow",_,P_)}))(Hn(u.leaving.nodes)),l=V(_=>({startT:0,endT:Ri(e.edgeSpeed)(e.minEdgeDuration)(t)(_),target:qn("EdgeWindow",_,Ei("Retract",M_(r)(u.leaving.nodes)(_)))}))(Hn(u.leaving.edges));return{duration:(()=>{const _=vt(lt.compare)([...V(p=>p.endT)(l),...V(p=>p.endT)(d),...V(p=>p.endT)(a),...V(p=>p.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+e.gap:e.gap})(),windows:[...l,...d,...a,...s]}},B_=e=>t=>n=>r=>i=>o=>V((()=>{const u=i.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())(bs(e)(t)(n)(r)(o).windows),$_=e=>Pt(t=>bt(ir,t).length>1?E("Just",(()=>{const n=Ht(r=>T,r=>i=>E("Just",{head:r,tail:i}),bt(ir,t));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";c()})()):T)(Jf($o)(vt(k.compare)(e))),Q_=e=>{const t=V(r=>r.id)(e),n=b_(t);return[...V(C_)($_(t)),...V(S_)(at(r=>!Ci(r)(n),St(e)(A_)))]},q_=e=>{const t=k_(V(r=>x(r.id,(()=>{if(r.when.tag==="First")return[];if(r.when.tag==="At")return[];if(r.when.tag==="After")return[r.when._1];if(r.when.tag==="With")return[r.when._1];c()})()))(e)),n=r=>i=>o=>{if(Ci(o)(i))return[wn("ScheduleCycle",[...bt(ke.foldr,i),o])];if(Ci(o)(r))return[];const u=L_(o)(t);if(u.tag==="Nothing")return[];if(u.tag==="Just")return St(u._1)(n(Z(k)(o)()(r))(Z(k)(o)()(i)));c()};return St(e)(r=>n($)($)(r.id))},H_={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:100,minTokenDuration:1.4,tokenReadSecPerChar:.06,nodeEasing:Ng,edgeEasing:yg,tokenEasing:mg},Y_=e=>t=>{if(t.tag==="Structural")return Pt(n=>n)([Si(t._1.from)(e)?T:E("Just",wn("UnknownKeyframe",t._1.from)),Si(t._1.to)(e)?T:E("Just",wn("UnknownKeyframe",t._1.to))]);if(t.tag==="DataFlow")return[...Pt(n=>n)([Si(t._1.keyframe)(e)?T:E("Just",wn("UnknownKeyframe",t._1.keyframe))]),...Q_(t._1.events),...q_(t._1.events)];c()},V_=e=>t=>{const n=St(t)(Y_(e));return n.length===0?kt("Right",void 0):kt("Left",n)},ks=e=>t=>n=>y(W_(e)(t))([])(Dt(r=>i=>({event:i,holdPre:i.kind.tag==="SendToken"?(()=>{const o=r-1|0;return o>=0&&o<n.length&&n[o].kind.tag==="SendToken"&&n[o].kind._1.to===i.kind._1.from})()?0:.18:0,holdPost:i.kind.tag==="SendToken"?(()=>{const o=r+1|0;return o>=0&&o<n.length&&n[o].kind.tag==="SendToken"&&n[o].kind._1.from===i.kind._1.to})()?0:.18:0}))(n)),O_=e=>t=>n=>{const r=ks(e)(t)(n.events);return r.length===0?e.gap:y(fn)(0)(V(i=>i.endT)(r))+e.gap},F_=e=>t=>n=>r=>i=>{if(i.tag==="Structural")return bs(e)(t)(n)(r)(i._1).duration;if(i.tag==="DataFlow")return O_(e)(t)(i._1);c()},X_=e=>t=>n=>r=>i=>y(o=>u=>{const s=F_(e)(t)(n)(r)(u);return{acc:de(o.acc)({startT:o.t,endT:o.t+s,scene:u}),t:o.t+s}})({acc:[],t:0})(i).acc,U_=e=>t=>n=>r=>V((()=>{const i=n.startT;return o=>({...o,startT:o.startT+i,endT:o.endT+i})})())(Pt(D_)(ks(e)(t)(r.events))),K_=e=>t=>n=>r=>i=>{if(i.scene.tag==="Structural")return B_(e)(t)(n)(r)(i)(i.scene._1);if(i.scene.tag==="DataFlow")return U_(e)(t)(i)(i.scene._1);c()},Z_=e=>t=>n=>{const r=0<t.keyframes.length?E("Just",t.keyframes[0]):T;if(r.tag==="Nothing")return kt("Left",[E_]);if(r.tag==="Just"){const i=r._1,o=Wg(V(a=>x(a.id,a))(t.keyframes)),u=o_(t),s=V_(o)(t.scenes);return(()=>{if(s.tag==="Left"){const a=s._1;return f=>kt("Left",a)}if(s.tag==="Right"){const a=s._1;return f=>f(a)}c()})()(()=>{const a=X_(e)(n)(o)(u)(t.scenes),f=a.length-1|0,g=f>=0&&f<a.length?a[f].endT:0,d=vt(l=>_=>lt.compare(l.startT)(_.startT))(St(a)(K_(e)(n)(o)(u)));return kt("Right",{totalDuration:g,windows:d,spans:a,keyframes:o,initialKeyframe:i.id,timing:e,layout:n,cameraSpans:i_(as)(n)(g)([...G_(n)(u)(o)(a),...R_(n)(u)(d)]),cameraConfig:as})})}c()},xr=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Ls=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},io=e=>t=>n=>{const r=lt.compare(e)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),o=lt.compare(t)(i);if(o==="LT"||o==="EQ")return t;if(o==="GT")return i;c()},j_=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},t1=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},e1=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},n1=te(k)(At),r1=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},o1=te(k)(At),i1=te(k)(At),u1=e=>t=>n=>r=>{const i=an(e),o=i.w/xr(1e-4)(t.zoom)/2,u=i.h/xr(1e-4)(t.zoom)/2,s=n.y-t.center.y,a=n.x-t.center.x;return{...t,center:{x:o<=1e-4?t.center.x+0*r*.35:a<0?t.center.x+a/(1+-a/o)*r*.35:t.center.x+a/(1+a/o)*r*.35,y:u<=1e-4?t.center.y+0*r*.35:s<0?t.center.y+s/(1+-s/u)*r*.35:t.center.y+s/(1+s/u)*r*.35}}},Ii=e=>t=>{const n=Ls(t)(e.keyframes);if(n.tag==="Nothing")return $;if(n.tag==="Just")return n._1.nodes;c()},Di=e=>t=>{const n=Ls(t)(e.keyframes);if(n.tag==="Nothing")return $;if(n.tag==="Just")return n._1.edges;c()},s1=e=>t=>n=>sn(r=>r.endT<=t&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,e),a1=e=>t=>n=>sn(r=>r.endT<=t&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,e),c1=e=>t=>n=>sn(r=>r.startT>t&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,e),f1=e=>t=>n=>sn(r=>r.startT>t&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,e),g1=e=>t=>{const n=Pi(e)(t);if(n.tag==="AtKeyframe")return ie(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return ie(3)(n._2)==="kf-"?"":n._2;c()},Es=e=>t=>n=>ge(r=>n(r)&&t>=r.startT&&t<r.endT)(e),_1=e=>{const t=io(0)(1)(e/.2),n=io(0)(1)((1-e)/.2);return t*t*(3-2*t)*n*n*(3-2*n)},d1=e=>t=>{if(t.tag==="Travelling"){const n=j_(t._1.edge)(e.edges);if(n.tag==="Just"){const r=Xu(n._1)(t._1.progress);return r.tag==="Just"?E("Just",{dot:r._1,weight:_1(t._1.progress)}):T}if(n.tag==="Nothing")return T;c()}return T},l1=e=>t=>{const n=Pi(e)(t);if(n.tag==="AtKeyframe")return Ii(e)(n._1);if(n.tag==="InTransition")return Ne(k.compare,me,Ii(e)(n._1),Ii(e)(n._2));c()},h1=e=>t=>{const n=Pi(e)(t);if(n.tag==="AtKeyframe")return Di(e)(n._1);if(n.tag==="InTransition")return Ne(k.compare,me,Di(e)(n._1),Di(e)(n._2));c()},p1=e=>t=>{const n=an(e),r=n.h/xr(1e-4)(t.zoom),i=n.w/xr(1e-4)(t.zoom);return{...t,center:{x:i>=n.w?n.x+n.w/2:io(n.x+i/2)(n.x+n.w-i/2)(t.center.x),y:r>=n.h?n.y+n.h/2:io(n.y+r/2)(n.y+n.h-r/2)(t.center.y)}}},uo=e=>t=>{const n=e.endT-e.startT;return n<=0?1:xr(0)(t1(1)((t-e.startT)/n))},m1=e=>t=>n=>r=>{const i=Es(e.windows)(t)(o=>o.target.tag==="EdgeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=fi(e.timing.edgeEasing)(uo(i._1)(t)),u=i._1.target.tag==="EdgeWindow"?i._1.target._2:Ei("Extend",ms);if(u.tag==="Retract")return eo("Retracting",u._1,o);if(u.tag==="Extend")return eo("Extending",u._1,o);c()}if(i.tag==="Nothing")return f1(e.windows)(t)(r)||s1(e.windows)(t)(r)?ys:e1(r)(n)?w_:ys;c()},y1=e=>t=>{const n=h1(e)(t);return n1(V(r=>x(r,m1(e)(t)(n)(r)))((()=>{const r=i=>{if(i.tag==="Leaf")return $;if(i.tag==="Node")return Ft("Node",i._1,i._2,i._3,void 0,r(i._5),r(i._6));c()};return bt(ke.foldr,r(e.layout.edges))})()))},J1=e=>t=>n=>r=>{const i=Es(e.windows)(t)(o=>o.target.tag==="NodeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=uo(i._1)(t),u=i._1.target.tag==="NodeWindow"?i._1.target._2:Ts;if(u==="PlopIn")return no("PloppingIn",o);if(u==="PlopOut")return no("PloppingOut",o);c()}if(i.tag==="Nothing")return c1(e.windows)(t)(r)||a1(e.windows)(t)(r)?ps:r1(r)(n)?T_:ps;c()},N1=e=>t=>{const n=l1(e)(t);return o1(V(r=>x(r,J1(e)(t)(n)(r)))((()=>{const r=i=>{if(i.tag==="Leaf")return $;if(i.tag==="Node")return Ft("Node",i._1,i._2,i._3,void 0,r(i._5),r(i._6));c()};return bt(ke.foldr,r(e.layout.nodes))})()))},x1=e=>t=>n=>t.target.tag==="TokenWindow"?x(t.target._1,n<t.startT?Li:n>=t.endT?ls:ro("Travelling",{edge:t.target._2,direction:t.target._3,progress:fi(e.timing.tokenEasing)(uo(t)(n)),labels:t.target._6,source:t.target._4,target:t.target._5,holdPre:t.target._7,holdPost:t.target._8})):t.target.tag==="FillWindow"?x(t.target._1,n<t.startT?Li:n>=t.endT?ls:ro("Filling",{node:t.target._2,progress:uo(t)(n),labels:t.target._3})):x("",Li),v1=e=>t=>i1(V(n=>x1(e)(n)(t))(at(n=>n.target.tag==="TokenWindow"||n.target.tag==="FillWindow",e.windows))),T1=e=>t=>{const n=Pt(d1(e))((()=>{const r=(i,o)=>{if(i.tag==="Leaf")return o;if(i.tag==="Node")return r(i._5,zt("Cons",i._4,r(i._6,o)));c()};return bt(Yt.foldr,r(t.tokens,Qt))})());return 0<n.length?E("Just",n[0]):T},w1=e=>t=>{const n=T1(e)(t);if(n.tag==="Nothing")return t.camera;if(n.tag==="Just")return u1(e)(t.camera)(n._1.dot)(n._1.weight);c()},b1=e=>t=>{const n={nodes:N1(e)(t),edges:y1(e)(t),tokens:v1(e)(t),camera:u_(e.cameraConfig)(e.layout)(e.cameraSpans)(t),frameTitle:g1(e)(t)};return{...n,camera:p1(e.layout)(w1(e.layout)(n))}};let Gi=null;function k1(){return Gi||(typeof document>"u"?null:(Gi=document.createElement("canvas").getContext("2d"),Gi))}const Cs=new Map,L1=e=>t=>n=>r=>()=>{const i=`${n} ${t}px ${e}|${r}`,o=Cs.get(i);if(o!==void 0)return o;const u=k1();if(!u)return r.length*t*.62;u.font=`${n} ${t}px ${e}`;const s=u.measureText(r).width;return Cs.set(i,s),s},so=(()=>{const e=cn(`\r
3
- `)(" "),t=cn(`
4
- `)(" "),n=(()=>{const r=cn("\r")(" "),i=(()=>{const o=cn(" ")(" ");return u=>o(r(u))})();return o=>i(t(o))})();return r=>n(e(r))})(),vr=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},E1=e=>t=>{const n=ot.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},C1=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},S1=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Ss=e=>zn(le(pn(t=>t===" ")(le(pn(t=>t===" ")(Uu(e)).rest)).rest)),P1=e=>y(t=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?E("Just",n._1):t)(T)(Dt(In)(e)),Mi=e=>t=>{if(e<=0)return[t];if(Jn(t)<=e)return[t];const n=Uu(t),r=e<1?[]:Gt(0,e,n),i=P1(r);if(i.tag==="Just"){const o=Ss(Ku(!(i._1>=0&&i._1<r.length)||r[i._1]===" "?i._1:i._1+1|0)(t)),u=Ss(mr(i._1+1|0)(t));return u===""?[o]:[o,...Mi(e)(u)]}if(i.tag==="Nothing"){const o=Ku(e)(t),u=mr(e)(t);return u===""?[o]:[o,...Mi(e)(u)]}c()},R1={cellW:7,cellH:3,maxLineWidth:20},I1=e=>t=>{const n=V(o=>x((()=>{if(o.label.tag==="Just")return o.label._1;if(o.label.tag==="Nothing")return o.id;c()})(),o))(t.nodes),r=vr(1)(Rn((E1(e.maxLineWidth)(y(o=>u=>vr(o)(Jn(u._1)))(0)(n))+2|0)+e.cellW|0,e.cellW)),i=(r*e.cellW|0)-1|0;return{...t,nodes:V(o=>{if(!(o._2.size._1===1&&o._2.size._2===1))return o._2;const u=St(vi(`
5
- `)(o._1))(Mi(i)),s=y(a=>f=>vr(a)(Jn(f)))(0)(u);return{...o._2,size:x(ct(s>i?Rn((s+2|0)+e.cellW|0,e.cellW):r),ct(vr(1)(Rn(u.length+e.cellH|0,e.cellH))))}})(n)}},D1=e=>t=>n=>({...n,nodes:V(r=>{const i=S1(r.id)(t);if(i.tag==="Nothing")return r;if(i.tag==="Just")return{...r,size:x(C1(r.size._1)(ct(vr(1)(ur(xf((i._1+32)/e))))),r.size._2)};c()})(n.nodes)}),G1=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},M1=e=>{const t=e.length;return(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,f=o;if(a>=t){u=!1,s=f;continue}const g=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const N=_,J=h;if(N>=t){p=!1,m=J;continue}if(a>=0&&a<e.length){if(N>=0&&N<e.length){_=N+1|0,h=(()=>{const v=e[a].position,w=e[a].size,L=e[N].position,b=e[N].size;return v._1<L._1+b._1&&L._1<v._1+w._1&&v._2<L._2+b._2&&L._2<v._2+w._2})()?J+1|0:J;continue}_=N+1|0,h=J;continue}p=!1,m=J}return m};i=a+1|0,o=g(a+1|0)(f)}return s})(0)(0)},Ps=e=>y(t=>n=>t+Ig(n.start)(n.end))(0)(e.segments),W1=e=>t=>n=>({crossingCount:y(r=>i=>r+i.jumps.length|0)(0)(t),bendCount:y(r=>i=>r+i.bends.length|0)(0)(t),totalEdgeLength:y(r=>i=>r+Ps(i))(0)(t),maxEdgeLength:y(r=>i=>G1(r)(Ps(i)))(0)(t),nodeOverlapCount:M1(e),constraintViolations:n,jumpCount:y(r=>i=>r+i.jumps.length|0)(0)(t)}),Rs=e=>e,Yn=te(ot)(At),xt=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=ot.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Is=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},it=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},ut=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Ue=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},A1=e=>t=>{const n=ot.compare(e._1)(t._1);return n==="LT"?Ae:n==="GT"?ze:ot.compare(e._2)(t._2)},Vn=e=>t=>{const n=ot.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},z1=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),B1=e=>e,ao=Rs("Regular"),co=Rs("Critical"),Ds=e=>t=>{const n=y(u=>s=>Z(k)(s.node)(s)(u))($)(t),r=1.25*ct(4),i=(u,s,a)=>(f=>g=>d=>{let l=f,_=g,h=d,p=!0,m;for(;p;){const N=l,J=_,v=h;if(v.critical){p=!1,m=v;continue}const w=Ht(b=>T,b=>S=>E("Just",{head:b,tail:S}),N),L=Ht(b=>T,b=>S=>E("Just",{head:b,tail:S}),J);if(w.tag==="Just"&&L.tag==="Just"){const b=w._1.head>L._1.head-u&&w._1.head<L._1.head+u?{...v,critical:!0}:w._1.head>L._1.head-r&&w._1.head<L._1.head+r?{...v,conflicts:v.conflicts+1|0}:v;if(b.critical){p=!1,m=b;continue}if(w._1.head<=L._1.head){l=w._1.tail,_=J,h=b;continue}l=N,_=L._1.tail,h=b;continue}p=!1,m=v}return m})(s)(a)({conflicts:0,critical:!1}),o=(u,s,a)=>{if(ut(y(ut)(-1e18)(s.incoming))(y(ut)(-1e18)(s.outgoing))-it(y(it)(1e18)(s.incoming))(y(it)(1e18)(s.outgoing))<.001||ut(y(ut)(-1e18)(a.incoming))(y(ut)(-1e18)(a.outgoing))-it(y(it)(1e18)(a.incoming))(y(it)(1e18)(a.outgoing))<.001)return[];const f=i(u,s.outgoing,a.incoming),g=i(u,a.outgoing,s.incoming);if(f.critical||g.critical)return[...f.critical?[{src:a.id,tgt:s.id,weight:1,kind:co}]:[],...g.critical?[{src:s.id,tgt:a.id,weight:1,kind:co}]:[]];const d=it(y(it)(1e18)(s.incoming))(y(it)(1e18)(s.outgoing)),l=ut(y(ut)(-1e18)(s.incoming))(y(ut)(-1e18)(s.outgoing)),_=it(y(it)(1e18)(a.incoming))(y(it)(1e18)(a.outgoing)),h=ut(y(ut)(-1e18)(a.incoming))(y(ut)(-1e18)(a.outgoing)),p=(1*f.conflicts|0)+(16*(y(N=>J=>J>h?N:J>=_?N+1|0:N)(0)(s.outgoing)+y(N=>J=>J>l?N:J>=d?N+1|0:N)(0)(a.incoming)|0)|0)|0,m=(1*g.conflicts|0)+(16*(y(N=>J=>J>l?N:J>=d?N+1|0:N)(0)(a.outgoing)+y(N=>J=>J>h?N:J>=_?N+1|0:N)(0)(s.incoming)|0)|0)|0;return p<m?[{src:s.id,tgt:a.id,weight:m-p|0,kind:ao}]:p>m?[{src:a.id,tgt:s.id,weight:p-m|0,kind:ao}]:p>0?[{src:s.id,tgt:a.id,weight:0,kind:ao},{src:a.id,tgt:s.id,weight:0,kind:ao}]:[]};return y(u=>s=>y(a=>f=>Z(k)(f._1)(f._2)(a))(u)((()=>{const a=y(R=>P=>{const et=P.edge.from.node+"|"+(()=>{if(P.edge.from.port.tag==="Just")return P.edge.from.port._1;if(P.edge.from.port.tag==="Nothing")return"_auto_"+P.edge.id;c()})(),K=Ue(et)(R.entries);if(K.tag==="Nothing")return{...R,entries:Z(k)(et)({id:0,members:[P.edge.id],incoming:[P.fromPos._1],outgoing:[P.toPos._1],slot:0,mark:0,splitBy:T,splitPartner:T})(R.entries),order:[...R.order,et]};if(K.tag==="Just")return{...R,entries:Z(k)(et)({...K._1,members:[...K._1.members,P.edge.id],incoming:[...pn(B=>B<P.fromPos._1)(K._1.incoming).init,P.fromPos._1,...pn(B=>B<=P.fromPos._1)(K._1.incoming).rest],outgoing:[...pn(B=>B<P.toPos._1)(K._1.outgoing).init,P.toPos._1,...pn(B=>B<=P.toPos._1)(K._1.outgoing).rest]})(R.entries)};c()})({entries:$,order:[]})(s._2),f=Dt(R=>P=>({...P,id:R}))(Pt(R=>Ue(R)(a.entries))(a.order));if(f.length===0)return[];const g=y(R=>P=>R.prev.tag==="Just"&&P-R.prev._1<1e-9?R:{prev:E("Just",P),out:[...R.out,P]})({prev:T,out:[]})(vt(lt.compare)([...St(f)(R=>R.incoming),...St(f)(R=>R.outgoing)])).out,d=g.length<2?.2*r:.2*y(R=>P=>{if(R.prev.tag==="Nothing")return{prev:E("Just",P),mn:R.mn};if(R.prev.tag==="Just")return{prev:E("Just",P),mn:it(R.mn)(P-R.prev._1)};c()})({prev:T,mn:1e18})(g).mn,l={segments:f,deps:(()=>{const R=f.length;return St(St(qt(0,R-2|0))(P=>St(qt(P+1|0,R-1|0))(et=>[x(P,et)])))(P=>P._1>=0&&P._1<f.length?P._2>=0&&P._2<f.length?o(d,f[P._1],f[P._2]):[]:[])})()},_=at(R=>{if(R.kind==="Critical")return!0;if(R.kind==="Regular")return!1;c()},l.deps),h=(()=>{if(_.length<2)return l;const R=Yn((()=>{const q=l.segments;return V(M=>x(M.id,M.mark))((()=>{const M=q.length,C=D=>{let G=D,Y=!0,X;for(;Y;){const H=G,Q=ge(W=>{const U=xt(W)(H.inWeight);if(U.tag==="Nothing")return!0;if(U.tag==="Just")return U._1===0;c()})(H.remaining);if(Q.tag==="Nothing"){Y=!1,X=H;continue}if(Q.tag==="Just"){const W=Q._1;G={...H,inWeight:y(U=>F=>Tt(ot)(Zt)(F.tgt)(-F.weight)(U))(H.inWeight)((()=>{const U=xt(W)(H.depsBySrc);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),marks:Z(ot)(W)(H.nextSource)(H.marks),nextSource:H.nextSource+1|0,outWeight:y(U=>F=>Tt(ot)(Zt)(F.src)(-F.weight)(U))(H.outWeight)((()=>{const U=xt(W)(H.depsByTgt);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),remaining:at(U=>U!==W,H.remaining)};continue}c()}return X},I=D=>{let G=D,Y=!0,X;for(;Y;){const H=G,Q=ge(W=>{const U=xt(W)(H.outWeight);if(U.tag==="Nothing")return!0;if(U.tag==="Just")return U._1===0;c()})(H.remaining);if(Q.tag==="Nothing"){Y=!1,X=H;continue}if(Q.tag==="Just"){const W=Q._1;G={...H,inWeight:y(U=>F=>Tt(ot)(Zt)(F.tgt)(-F.weight)(U))(H.inWeight)((()=>{const U=xt(W)(H.depsBySrc);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),marks:Z(ot)(W)(H.nextSink)(H.marks),nextSink:H.nextSink-1|0,outWeight:y(U=>F=>Tt(ot)(Zt)(F.src)(-F.weight)(U))(H.outWeight)((()=>{const U=xt(W)(H.depsByTgt);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),remaining:at(U=>U!==W,H.remaining)};continue}c()}return X};return(D=>{let G=D,Y=!0,X;for(;Y;){const H=C(I(G));if(H.remaining.length===0){Y=!1,X=V(Q=>{const W=xt(Q.id)(H.marks),U=(()=>{if(W.tag==="Nothing")return Q.id;if(W.tag==="Just")return W._1;c()})();return{...Q,mark:U<M?(U+M|0)+1|0:U}})(q);continue}G=(()=>{const Q=U=>{const F=xt(U)(H.outWeight),_t=xt(U)(H.inWeight);return(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;c()})()-(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;c()})()|0},W=vt(U=>F=>ot.compare(Q(F))(Q(U)))(H.remaining);if(0<W.length){const U=W[0];return{...H,inWeight:y(F=>_t=>Tt(ot)(Zt)(_t.tgt)(-_t.weight)(F))(H.inWeight)((()=>{const F=xt(U)(H.depsBySrc);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;c()})()),marks:Z(ot)(U)(H.nextSource)(H.marks),nextSource:H.nextSource+1|0,outWeight:y(F=>_t=>Tt(ot)(Zt)(_t.src)(-_t.weight)(F))(H.outWeight)((()=>{const F=xt(U)(H.depsByTgt);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;c()})()),remaining:at(F=>F!==U,H.remaining)}}return H})()}return X})({remaining:V(D=>D.id)(q),marks:$,inWeight:y(D=>G=>Tt(ot)(Zt)(G.tgt)(G.weight)(D))($)(_),outWeight:y(D=>G=>Tt(ot)(Zt)(G.src)(G.weight)(D))($)(_),depsBySrc:y(D=>G=>Tt(ot)(se)(G.src)([G])(D))($)(_),depsByTgt:y(D=>G=>Tt(ot)(se)(G.tgt)([G])(D))($)(_),nextSink:M-1|0,nextSource:M+1|0})})())})()),P=at(q=>{const M=xt(q.src)(R),C=xt(q.tgt)(R);return(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;c()})()>(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;c()})()},_);if(P.length===0)return l;const et=y(q=>M=>{if(Be(Qo)(M.src)(q.decisions)||Be(Qo)(M.tgt)(q.decisions))return q;const C=xt(M.src)(q.segMap),I=xt(M.tgt)(q.segMap);if(C.tag==="Just"&&I.tag==="Just"){const D=(C._1.incoming.length+C._1.outgoing.length|0)>2&&(I._1.incoming.length+I._1.outgoing.length|0)<=2,G=D?I._1:C._1;return{decisions:[...q.decisions,G.id],segMap:Z(ot)(G.id)({...G,splitBy:E("Just",D?C._1.id:I._1.id)})(q.segMap)}}return q})({decisions:[],segMap:Yn(V(q=>x(q.id,q))(l.segments))})(P),K=et.segMap,B=y(q=>M=>{const C=it(y(it)(1e18)(M.incoming))(y(it)(1e18)(M.outgoing)),I=ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(M.outgoing)),D=at(Q=>Q.a.startPosition<=I&&Q.a.endPosition>=C,Dt(Q=>W=>({i:Q,a:W}))(q.freeAreas));if(D.length===0){const Q={...M,incoming:vt(lt.compare)(M.incoming),outgoing:vt(lt.compare)([(C+I)/2]),splitPartner:E("Just",q.nextId)},W={id:q.nextId,incoming:vt(lt.compare)([(C+I)/2]),mark:0,members:M.members,outgoing:vt(lt.compare)(M.outgoing),slot:0,splitBy:T,splitPartner:E("Just",M.id)};return{segMap:Z(ot)(W.id)(W)(Z(ot)(Q.id)(Q)(q.segMap)),freeAreas:q.freeAreas,nextId:q.nextId+1|0}}const G=0<D.length?E("Just",D[0]):T,Y=(()=>{if(G.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(G.tag==="Just"){if(D.length===1)return G._1;const Q=V(W=>({c:W,rating:(()=>{const U=(W.a.startPosition+W.a.endPosition)/2,F=[U],_t=[U],pt=y((()=>{const ht=q.segMap;return wt=>It=>{const dt=xt(It.tgt)(ht);if(dt.tag==="Nothing")return wt;if(dt.tag==="Just"){const Mt=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),mt=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),gt=it(y(it)(1e18)(M.incoming))(y(it)(1e18)(F)),rt=(()=>{const Et=ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(F)),Rt=y(Wt=>oe=>oe>mt?Wt:oe>=Mt?Wt+1|0:Wt)(0)(F)+y(Wt=>oe=>oe>Et?Wt:oe>=gt?Wt+1|0:Wt)(0)(dt._1.incoming)|0,nr=it(y(it)(1e18)(M.incoming))(y(it)(1e18)(F)),Sn=ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(F)),Pn=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),rr=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),We=y(Wt=>oe=>oe>Sn?Wt:oe>=nr?Wt+1|0:Wt)(0)(dt._1.outgoing)+y(Wt=>oe=>oe>rr?Wt:oe>=Pn?Wt+1|0:Wt)(0)(M.incoming)|0;return Rt===We?Rt>0?{...wt,deps:wt.deps+2|0,crossings:wt.crossings+Rt|0}:wt:{...wt,deps:wt.deps+1|0,crossings:wt.crossings+Vn(Rt)(We)|0}})(),nt=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),st=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),yt=it(y(it)(1e18)(_t))(y(it)(1e18)(M.outgoing)),Jt=ut(y(ut)(-1e18)(_t))(y(ut)(-1e18)(M.outgoing)),Ct=y(Et=>Rt=>Rt>st?Et:Rt>=nt?Et+1|0:Et)(0)(M.outgoing)+y(Et=>Rt=>Rt>Jt?Et:Rt>=yt?Et+1|0:Et)(0)(dt._1.incoming)|0,$t=it(y(it)(1e18)(_t))(y(it)(1e18)(M.outgoing)),re=ut(y(ut)(-1e18)(_t))(y(ut)(-1e18)(M.outgoing)),Ve=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),er=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),on=y(Et=>Rt=>Rt>re?Et:Rt>=$t?Et+1|0:Et)(0)(dt._1.outgoing)+y(Et=>Rt=>Rt>er?Et:Rt>=Ve?Et+1|0:Et)(0)(_t)|0;return Ct===on?Ct>0?{...rt,deps:rt.deps+2|0,crossings:rt.crossings+Ct|0}:rt:{...rt,deps:rt.deps+1|0,crossings:rt.crossings+Vn(Ct)(on)|0}}c()}})())(y((()=>{const ht=q.segMap;return wt=>It=>{const dt=xt(It.src)(ht);if(dt.tag==="Nothing")return wt;if(dt.tag==="Just"){const Mt=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),mt=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),gt=it(y(it)(1e18)(M.incoming))(y(it)(1e18)(F)),rt=(()=>{const Et=ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(F)),Rt=y(Wt=>oe=>oe>mt?Wt:oe>=Mt?Wt+1|0:Wt)(0)(F)+y(Wt=>oe=>oe>Et?Wt:oe>=gt?Wt+1|0:Wt)(0)(dt._1.incoming)|0,nr=it(y(it)(1e18)(M.incoming))(y(it)(1e18)(F)),Sn=ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(F)),Pn=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),rr=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),We=y(Wt=>oe=>oe>Sn?Wt:oe>=nr?Wt+1|0:Wt)(0)(dt._1.outgoing)+y(Wt=>oe=>oe>rr?Wt:oe>=Pn?Wt+1|0:Wt)(0)(M.incoming)|0;return Rt===We?Rt>0?{...wt,deps:wt.deps+2|0,crossings:wt.crossings+Rt|0}:wt:{...wt,deps:wt.deps+1|0,crossings:wt.crossings+Vn(Rt)(We)|0}})(),nt=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),st=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),yt=it(y(it)(1e18)(_t))(y(it)(1e18)(M.outgoing)),Jt=ut(y(ut)(-1e18)(_t))(y(ut)(-1e18)(M.outgoing)),Ct=y(Et=>Rt=>Rt>st?Et:Rt>=nt?Et+1|0:Et)(0)(M.outgoing)+y(Et=>Rt=>Rt>Jt?Et:Rt>=yt?Et+1|0:Et)(0)(dt._1.incoming)|0,$t=it(y(it)(1e18)(_t))(y(it)(1e18)(M.outgoing)),re=ut(y(ut)(-1e18)(_t))(y(ut)(-1e18)(M.outgoing)),Ve=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),er=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),on=y(Et=>Rt=>Rt>re?Et:Rt>=$t?Et+1|0:Et)(0)(dt._1.outgoing)+y(Et=>Rt=>Rt>er?Et:Rt>=Ve?Et+1|0:Et)(0)(_t)|0;return Ct===on?Ct>0?{...rt,deps:rt.deps+2|0,crossings:rt.crossings+Ct|0}:rt:{...rt,deps:rt.deps+1|0,crossings:rt.crossings+Vn(Ct)(on)|0}}c()}})())({crossings:0,deps:0})(at(ht=>ht.tgt===M.id,l.deps)))(at(ht=>ht.src===M.id,l.deps)),ft=(()=>{if(M.splitBy.tag==="Just")return xt(M.splitBy._1)(q.segMap);if(M.splitBy.tag==="Nothing")return T;c()})();if(ft.tag==="Just")return{...pt,deps:pt.deps+2|0,crossings:(()=>{const ht=it(y(it)(1e18)(ft._1.incoming))(y(it)(1e18)(ft._1.outgoing)),wt=it(y(it)(1e18)(_t))(y(it)(1e18)(M.outgoing)),It=ut(y(ut)(-1e18)(ft._1.incoming))(y(ut)(-1e18)(ft._1.outgoing)),dt=ut(y(ut)(-1e18)(_t))(y(ut)(-1e18)(M.outgoing)),Mt=it(y(it)(1e18)(M.incoming))(y(it)(1e18)(F));return pt.crossings+(()=>{const mt=it(y(it)(1e18)(ft._1.incoming))(y(it)(1e18)(ft._1.outgoing)),gt=ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(F)),rt=ut(y(ut)(-1e18)(ft._1.incoming))(y(ut)(-1e18)(ft._1.outgoing));return((y(nt=>st=>st>It?nt:st>=ht?nt+1|0:nt)(0)(F)+y(nt=>st=>st>gt?nt:st>=Mt?nt+1|0:nt)(0)(ft._1.incoming)|0)+y(nt=>st=>st>dt?nt:st>=wt?nt+1|0:nt)(0)(ft._1.outgoing)|0)+y(nt=>st=>st>rt?nt:st>=mt?nt+1|0:nt)(0)(_t)|0})()|0})()};if(ft.tag==="Nothing")return pt;c()})()}))(D);return y(W=>U=>U.rating.crossings<W.rating.crossings||!(U.rating.crossings>W.rating.crossings)&&(U.rating.deps<W.rating.deps||!(U.rating.deps>W.rating.deps)&&U.c.a.size>W.c.a.size)?U:W)(0<Q.length?Q[0]:{c:G._1,rating:{crossings:1e6,deps:1e6}})(Q).c}c()})(),X={...M,incoming:vt(lt.compare)(M.incoming),outgoing:vt(lt.compare)([(Y.a.startPosition+Y.a.endPosition)/2]),splitPartner:E("Just",q.nextId)},H={id:q.nextId,incoming:vt(lt.compare)([(Y.a.startPosition+Y.a.endPosition)/2]),mark:0,members:M.members,outgoing:vt(lt.compare)(M.outgoing),slot:0,splitBy:T,splitPartner:E("Just",M.id)};return{segMap:Z(ot)(H.id)(H)(Z(ot)(X.id)(X)(q.segMap)),freeAreas:(()=>{if(Y.i>=0&&Y.i<q.freeAreas.length){const Q=Eu(Xt,T,Y.i,q.freeAreas),W=(()=>{if(Q.tag==="Nothing")return q.freeAreas;if(Q.tag==="Just")return Q._1;c()})();if(q.freeAreas[Y.i].size/2<d)return W;const U=(q.freeAreas[Y.i].startPosition+q.freeAreas[Y.i].endPosition)/2,F=U-d,_t=U+d;return[...Y.i<1?[]:Gt(0,Y.i,W),...q.freeAreas[Y.i].startPosition<=F?[{startPosition:q.freeAreas[Y.i].startPosition,endPosition:F,size:F-q.freeAreas[Y.i].startPosition}]:[],..._t<=q.freeAreas[Y.i].endPosition?[{startPosition:_t,endPosition:q.freeAreas[Y.i].endPosition,size:q.freeAreas[Y.i].endPosition-_t}]:[],...Y.i<1?W:Gt(Y.i,W.length,W)]}return q.freeAreas})(),nextId:q.nextId+1|0}})({segMap:K,freeAreas:(()=>{const q=vt(lt.compare)([...St(l.segments)(M=>M.incoming),...St(l.segments)(M=>M.outgoing)]);return Pt(B1)(ye(M=>C=>C-M>=2*d?E("Just",{startPosition:M+d,endPosition:C-d,size:C-M-2*d}):T,q,Gt(1,q.length,q)))})(),nextId:l.segments.length})(vt(q=>M=>lt.compare(ut(y(ut)(-1e18)(q.incoming))(y(ut)(-1e18)(q.outgoing))-it(y(it)(1e18)(q.incoming))(y(it)(1e18)(q.outgoing)))(ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(M.outgoing))-it(y(it)(1e18)(M.incoming))(y(it)(1e18)(M.outgoing))))(Pt(q=>xt(q)(K))(et.decisions)));return{segments:(()=>{const q=(M,C)=>{if(M.tag==="Leaf")return C;if(M.tag==="Node")return q(M._5,zt("Cons",M._4,q(M._6,C)));c()};return bt(Yt.foldr,q(B.segMap,Qt))})(),deps:(()=>{const q=B.segMap,M=(D,G)=>{if(D.tag==="Leaf")return G;if(D.tag==="Node")return M(D._5,zt("Cons",D._4,M(D._6,G)));c()},C=bt(Yt.foldr,M(q,Qt)),I=C.length;return[...St(St(qt(0,I-2|0))(D=>St(qt(D+1|0,I-1|0))(G=>[x(D,G)])))(D=>D._1>=0&&D._1<C.length?D._2>=0&&D._2<C.length?C[D._1].splitPartner.tag!=="Nothing"&&C[D._1].splitPartner.tag==="Just"&&C[D._1].splitPartner._1===C[D._2].id||C[D._2].splitPartner.tag!=="Nothing"&&C[D._2].splitPartner.tag==="Just"&&C[D._2].splitPartner._1===C[D._1].id?[]:o(d,C[D._1],C[D._2]):[]:[]),...St(C)(D=>D.splitBy.tag==="Just"&&D.splitPartner.tag==="Just"&&(()=>{const G=xt(D.splitPartner._1)(q);if(G.tag==="Nothing")return!1;if(G.tag==="Just")return!0;c()})()&&(()=>{const G=xt(D.splitBy._1)(q);if(G.tag==="Nothing")return!1;if(G.tag==="Just")return!0;c()})()?[{src:D.id,tgt:D.splitBy._1,weight:1,kind:co},{src:D.splitBy._1,tgt:D.splitPartner._1,weight:1,kind:co}]:[])]})()}})(),p=h.segments,m=p.length,N=R=>{let P=R,et=!0,K;for(;et;){const B=P,q=ge(M=>{const C=xt(M)(B.inWeight);if(C.tag==="Nothing")return!0;if(C.tag==="Just")return C._1===0;c()})(B.remaining);if(q.tag==="Nothing"){et=!1,K=B;continue}if(q.tag==="Just"){const M=q._1;P={...B,inWeight:y(C=>I=>Tt(ot)(Zt)(I.tgt)(-I.weight)(C))(B.inWeight)((()=>{const C=xt(M)(B.depsBySrc);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),marks:Z(ot)(M)(B.nextSource)(B.marks),nextSource:B.nextSource+1|0,outWeight:y(C=>I=>Tt(ot)(Zt)(I.src)(-I.weight)(C))(B.outWeight)((()=>{const C=xt(M)(B.depsByTgt);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),remaining:at(C=>C!==M,B.remaining)};continue}c()}return K},J=R=>{let P=R,et=!0,K;for(;et;){const B=P,q=ge(M=>{const C=xt(M)(B.outWeight);if(C.tag==="Nothing")return!0;if(C.tag==="Just")return C._1===0;c()})(B.remaining);if(q.tag==="Nothing"){et=!1,K=B;continue}if(q.tag==="Just"){const M=q._1;P={...B,inWeight:y(C=>I=>Tt(ot)(Zt)(I.tgt)(-I.weight)(C))(B.inWeight)((()=>{const C=xt(M)(B.depsBySrc);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),marks:Z(ot)(M)(B.nextSink)(B.marks),nextSink:B.nextSink-1|0,outWeight:y(C=>I=>Tt(ot)(Zt)(I.src)(-I.weight)(C))(B.outWeight)((()=>{const C=xt(M)(B.depsByTgt);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),remaining:at(C=>C!==M,B.remaining)};continue}c()}return K},v=(R=>{let P=R,et=!0,K;for(;et;){const B=N(J(P));if(B.remaining.length===0){et=!1,K=V(q=>{const M=xt(q.id)(B.marks),C=(()=>{if(M.tag==="Nothing")return q.id;if(M.tag==="Just")return M._1;c()})();return{...q,mark:C<m?(C+m|0)+1|0:C}})(p);continue}P=(()=>{const q=C=>{const I=xt(C)(B.outWeight),D=xt(C)(B.inWeight);return(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;c()})()-(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;c()})()|0},M=vt(C=>I=>ot.compare(q(I))(q(C)))(B.remaining);if(0<M.length){const C=M[0];return{...B,inWeight:y(I=>D=>Tt(ot)(Zt)(D.tgt)(-D.weight)(I))(B.inWeight)((()=>{const I=xt(C)(B.depsBySrc);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;c()})()),marks:Z(ot)(C)(B.nextSource)(B.marks),nextSource:B.nextSource+1|0,outWeight:y(I=>D=>Tt(ot)(Zt)(D.src)(-D.weight)(I))(B.outWeight)((()=>{const I=xt(C)(B.depsByTgt);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;c()})()),remaining:at(I=>I!==C,B.remaining)}}return B})()}return K})({remaining:V(R=>R.id)(p),marks:$,inWeight:y(R=>P=>Tt(ot)(Zt)(P.tgt)(P.weight)(R))($)(h.deps),outWeight:y(R=>P=>Tt(ot)(Zt)(P.src)(P.weight)(R))($)(h.deps),depsBySrc:y(R=>P=>Tt(ot)(se)(P.src)([P])(R))($)(h.deps),depsByTgt:y(R=>P=>Tt(ot)(se)(P.tgt)([P])(R))($)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),w=(()=>{const R=(()=>{const K=Yn(V(B=>x(B.id,B.mark))(v));return{segments:v,deps:Pt(B=>(()=>{if(B.kind==="Critical")return!0;if(B.kind==="Regular")return!1;c()})()?E("Just",B):(()=>{const q=xt(B.src)(K),M=xt(B.tgt)(K);return(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;c()})()>(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;c()})()})()?B.weight===0?T:E("Just",{src:B.tgt,tgt:B.src,weight:B.weight,kind:B.kind}):E("Just",B))(h.deps)}})(),P=y(K=>B=>Tt(ot)(Zt)(B.tgt)(1)(K))($)(R.deps),et=(K=>{let B=K,q=!0,M;for(;q;){const C=B,I=Ht(D=>T,D=>G=>E("Just",{head:D,tail:G}),C.queue);if(I.tag==="Nothing"){q=!1,M=C;continue}if(I.tag==="Just"){B=y((()=>{const D=xt(I._1.head)(C.slots),G=(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;c()})();return Y=>X=>{const H=xt(X)(Y.inDegree),Q=(()=>{if(H.tag==="Nothing")return-1;if(H.tag==="Just")return H._1-1|0;c()})();return{...Y,slots:Z(ot)(X)(Is((()=>{const W=xt(X)(Y.slots);if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;c()})())(G+1|0))(Y.slots),inDegree:Z(ot)(X)(Q)(Y.inDegree),queue:Q===0?[...Y.queue,X]:Y.queue}}})())({...C,queue:I._1.tail})((()=>{const D=xt(I._1.head)(C.adj);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})());continue}c()}return M})({slots:Yn(V(K=>x(K.id,0))(R.segments)),inDegree:P,adj:y(K=>B=>Tt(ot)(se)(B.src)([B.tgt])(K))($)(R.deps),queue:V(K=>K.id)(at(K=>{const B=xt(K.id)(P);if(B.tag==="Nothing")return!0;if(B.tag==="Just")return B._1===0;c()},R.segments))});return vt(K=>B=>ot.compare(K.slot)(B.slot))(V(K=>({...K,slot:(()=>{const B=xt(K.id)(et.slots);if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;c()})()}))(R.segments))})(),L=1+y(R=>P=>Is(R)(P.slot))(0)(w)|0,b=St(w)(R=>R.members),S=at(R=>Be(Fe)(R.edge.id)(b),e),A=y(ut)(-1e18)(V(R=>R.fromPos._2)(S)),O=y(it)(1e18)(V(R=>R.toPos._2)(S));if(A>O){const R=Yn(V(P=>x(P.id,P))(w));return Te(V(P=>V(et=>x(et,{slot:P.slot,slotCount:L,gapTop:O,gapBottom:A,partner:(()=>{if(P.splitPartner.tag==="Just"){const K=xt(P.splitPartner._1)(R);if(K.tag==="Just")return E("Just",{slot:K._1.slot,splitX:0<K._1.incoming.length?K._1.incoming[0]:0});if(K.tag==="Nothing")return T;c()}if(P.splitPartner.tag==="Nothing")return T;c()})()}))(P.members))(at(P=>{if(P.splitPartner.tag==="Just"){const et=xt(P.splitPartner._1)(R);return!(et.tag==="Just"&&(()=>{if(et._1.splitBy.tag==="Nothing")return!1;if(et._1.splitBy.tag==="Just")return!0;c()})())}if(P.splitPartner.tag==="Nothing")return!0;c()},w)))}const j=Yn(V(R=>x(R.id,R))(w));return Te(V(R=>V(P=>x(P,{slot:R.slot,slotCount:L,gapTop:A,gapBottom:O,partner:(()=>{if(R.splitPartner.tag==="Just"){const et=xt(R.splitPartner._1)(j);if(et.tag==="Just")return E("Just",{slot:et._1.slot,splitX:0<et._1.incoming.length?et._1.incoming[0]:0});if(et.tag==="Nothing")return T;c()}if(R.splitPartner.tag==="Nothing")return T;c()})()}))(R.members))(at(R=>{if(R.splitPartner.tag==="Just"){const P=xt(R.splitPartner._1)(j);return!(P.tag==="Just"&&(()=>{if(P._1.splitBy.tag==="Nothing")return!1;if(P._1.splitBy.tag==="Just")return!0;c()})())}if(R.splitPartner.tag==="Nothing")return!0;c()},w)))})()))($)(z1(y(u=>s=>{const a=Ue(s.edge.from.node)(n);if(a.tag==="Just"){const f=Ue(s.edge.to.node)(n);return f.tag==="Just"&&a._1.layer!==f._1.layer?Tt(ot)(se)(Vn(a._1.layer)(f._1.layer))([s])(u):u}return u})($)((()=>{const u=s=>x((()=>{const a=Ue(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=Ue(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return vt(s=>a=>A1(u(s))(u(a)))(e)})())))},$1=e=>t=>{const n=Ds(e)(t),r=y(i=>o=>Z(k)(o.node)(o)(i))($)(t);return y(i=>o=>{const u=Ue(o.edge.from.node)(r);if(u.tag==="Just"){const s=Ue(o.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=Ue(o.edge.id)(n);if(a.tag==="Just")return Z(ot)(Vn(u._1.layer)(s._1.layer))(a._1.slotCount)(i)}return i}return i})($)(e)},Gs=e=>e,Ut=Gs("H"),Kt=Gs("V"),Ms=At.foldMap((()=>{const e={append:t=>n=>t||n};return{mempty:!1,Semigroup0:()=>e}})()),ee=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},ne=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Tr=e=>t=>n=>r=>Ms(i=>n>=i.x&&n<i.x+i.w&&t>i.y&&e<i.y+i.h)(r),fo=e=>t=>n=>r=>Tr(ee(t)(n))(ne(t)(n))(r)(e),go=ct(4),Q1=Pu(e=>{if(e.direction==="H"){const t=ee(e.start._1)(e.end._1);return[{x:t,y:e.start._2-1,w:ne(e.start._1)(e.end._1)-t,h:2}]}if(e.direction==="V"){const t=ee(e.start._2)(e.end._2);return[{x:e.start._1-1,y:t,w:2,h:ne(e.start._2)(e.end._2)-t}]}c()}),Ws=Su(e=>!(e.start._1===e.end._1&&e.start._2===e.end._2)),q1=e=>t=>n=>{const r=Ht(i=>T,i=>o=>E("Just",{head:i,tail:o}),t);if(r.tag==="Nothing")return[{start:e.start,end:n.end,direction:e.direction}];if(r.tag==="Just"){const i=(r._1.head.direction==="H"?e.direction==="H":r._1.head.direction==="V"&&e.direction==="V")?[{start:e.start,end:r._1.head.end,direction:e.direction}]:[e,r._1.head],o=mf(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?[]:Gt(0,s,i)})(),{start:i[u].start,end:n.end,direction:n.direction}]:[...i,n]}if(o.tag==="Just")return(o._1.last.direction==="H"?n.direction==="H":o._1.last.direction==="V"&&n.direction==="V")?[...i,...o._1.init,{start:o._1.last.start,end:n.end,direction:n.direction}]:[...i,...r._1.tail,n]}c()},Wi=e=>{const t=r=>i=>{const o=Ht(u=>T,u=>s=>E("Just",{head:u,tail:s}),i);if(o.tag==="Nothing")return[r];if(o.tag==="Just")return(r.direction==="H"?o._1.head.direction==="H":r.direction==="V"&&o._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==o._1.head.end._1-o._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==o._1.head.end._2-o._1.head.start._2>=0;c()})()?t({start:r.start,end:o._1.head.end,direction:r.direction})(o._1.tail):[r,...t(o._1.head)(o._1.tail)];c()},n=Ht(r=>T,r=>i=>E("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return t(n._1.head)(n._1.tail);c()},wr=e=>t=>n=>r=>Ms(i=>n>=i.y&&n<i.y+i.h&&t>i.x&&e<i.x+i.w)(r),br=e=>t=>n=>r=>wr(ee(t)(n))(ne(t)(n))(r)(e),H1=e=>t=>n=>r=>{const i=n+2|0,o=i<1?t:Gt(i,t.length,t),u=n<1?[]:Gt(0,n,t),s=(n+1|0)===(r-1|0),a=n===0,f=n>=0&&n<t.length?E("Just",t[n]):T;if(f.tag==="Just"){const g=n+1|0,d=g>=0&&g<t.length?E("Just",t[g]):T;if(d.tag==="Just"){const l=f._1.start._1===d._1.end._1&&(!a||f._1.direction==="V")&&(!s||d._1.direction==="V")&&!fo(e)(ee(f._1.start._2)(d._1.end._2))(ne(f._1.start._2)(d._1.end._2))(f._1.start._1)?E("Just",[...u,{start:f._1.start,end:d._1.end,direction:Kt},...o]):T,_=f._1.start._2===d._1.end._2&&(!a||f._1.direction==="H")&&(!s||d._1.direction==="H")&&!br(e)(ee(f._1.start._1)(d._1.end._1))(ne(f._1.start._1)(d._1.end._1))(f._1.start._2)?E("Just",[...u,{start:f._1.start,end:d._1.end,direction:Ut},...o]):T;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return T;c()}if(f.tag==="Nothing")return T;c()},Y1=e=>t=>{const n=t.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+1|0)>=n){o=!1,u=t;continue}const a=H1(e)(t)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}c()}return u})(0)},V1=e=>t=>n=>r=>{const i=(l,_,h)=>!fo(e)(ee(_)(h))(ne(_)(h))(l),o=n+3|0,u=o<1?t:Gt(o,t.length,t),s=n<1?[]:Gt(0,n,t),a=(n+2|0)===(r-1|0),f=n===0,g=(l,_,h)=>!br(e)(ee(_)(h))(ne(_)(h))(l),d=n>=0&&n<t.length?E("Just",t[n]):T;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<t.length?E("Just",t[l]):T;if(_.tag==="Just"){const h=d._1.start._1===_._1.end._1&&(!f||d._1.direction==="V")&&(!a||_._1.direction==="V")&&i(d._1.start._1,d._1.start._2,_._1.end._2)?E("Just",[...s,{start:d._1.start,end:_._1.end,direction:Kt},...u]):d._1.start._2===_._1.end._2&&(!f||d._1.direction==="H")&&(!a||_._1.direction==="H")&&g(d._1.start._2,d._1.start._1,_._1.end._1)?E("Just",[...s,{start:d._1.start,end:_._1.end,direction:Ut},...u]):T,p=(!f||d._1.direction==="V")&&(!a||_._1.direction==="H")&&i(d._1.start._1,d._1.start._2,_._1.end._2)&&g(_._1.end._2,d._1.start._1,_._1.end._1)?E("Just",[...s,{start:d._1.start,end:x(d._1.start._1,_._1.end._2),direction:Kt},{start:x(d._1.start._1,_._1.end._2),end:_._1.end,direction:Ut},...u]):T,m=(!f||d._1.direction==="H")&&(!a||_._1.direction==="V")&&g(d._1.start._2,d._1.start._1,_._1.end._1)&&i(_._1.end._1,d._1.start._2,_._1.end._2)?E("Just",[...s,{start:d._1.start,end:x(_._1.end._1,d._1.start._2),direction:Ut},{start:x(_._1.end._1,d._1.start._2),end:_._1.end,direction:Kt},...u]):T,N=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?N:h}if(_.tag==="Nothing")return T;c()}if(d.tag==="Nothing")return T;c()},O1=e=>t=>{const n=t.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+2|0)>=n){o=!1,u=t;continue}const a=V1(e)(t)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}c()}return u})(0)},F1=e=>{const t=n=>{let r=n,i=!0,o;for(;i;){const u=r,s=Wi(Ws(Y1(e)(O1(e)(u))));if(s.length<u.length){r=s;continue}i=!1,o=s}return o};return n=>t(Wi(Ws(n)))},X1=e=>t=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=at(a=>t>=a.y&&t<a.y+a.h&&a.x+a.w>i&&a.x<o,e);if(r>n){const a=vt(f=>g=>lt.compare(f.x)(g.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=vt(a=>f=>lt.compare(f.x)(a.x))(V(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},U1=e=>t=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=at(a=>t>=a.x&&t<a.x+a.w&&a.y+a.h>i&&a.y<o,e);if(r>n){const a=vt(f=>g=>lt.compare(f.y)(g.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=vt(a=>f=>lt.compare(f.y)(a.y))(V(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},K1=e=>t=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=at(a=>t>=a.y&&t<a.y+a.h&&a.x+a.w>i&&a.x<o,e);if(r>n){const a=vt(f=>g=>lt.compare(g.x)(f.x))(V(f=>({...f,x:f.x+f.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=vt(a=>f=>lt.compare(a.x)(f.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},Z1=e=>t=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=at(a=>t>=a.x&&t<a.x+a.w&&a.y+a.h>i&&a.y<o,e);if(r>n){const a=vt(f=>g=>lt.compare(g.y)(f.y))(V(f=>({...f,y:f.y+f.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=vt(a=>f=>lt.compare(a.y)(f.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},As=e=>t=>n=>{let r=e,i=t,o=n,u=!0,s;for(;u;){const a=r,f=i,g=o;if(g>100){u=!1,s=f;continue}if(!a(f+g)){u=!1,s=f+g;continue}if(!a(f-g)){u=!1,s=f-g;continue}r=a,i=f,o=g+1}return s},zs=e=>t=>n=>r=>i=>{const o=ee(t)(n),u=ne(t)(n);if(!Tr(o)(u)(r)(e))return r;if(!Tr(o)(u)(i)(e))return i;const s=(r+i)/2;return Tr(o)(u)(s)(e)?As(a=>Tr(o)(u)(a)(e))(s)(1):s},j1=e=>t=>n=>r=>i=>{const o=ee(t)(n),u=ne(t)(n);if(!wr(o)(u)(r)(e))return r;if(!wr(o)(u)(i)(e))return i;const s=(r+i)/2;return wr(o)(u)(s)(e)?As(a=>wr(o)(u)(a)(e))(s)(1):s},td=e=>t=>n=>r=>{const i=ee(t)(n),o=ne(t)(n),u=at(f=>r>=f.x&&r<f.x+f.w&&f.y+f.h>i&&f.y<o,e),s=y(f=>g=>ne(f)(g.x+g.w+4))(r+4)(u),a=y(f=>g=>ee(f)(g.x-4))(r-4)(u);return(()=>{const f=s-r,g=a-r;return(f<0?-f:f)<=(g<0?-g:g)})()?s:a},ed=e=>t=>n=>r=>{const i=ee(t)(n),o=ne(t)(n),u=at(f=>r>=f.y&&r<f.y+f.h&&f.x+f.w>i&&f.x<o,e),s=y(f=>g=>ne(f)(g.y+g.h+4))(r+4)(u),a=y(f=>g=>ee(f)(g.y-4))(r-4)(u);return(()=>{const f=s-r,g=a-r;return(f<0?-f:f)<=(g<0?-g:g)})()?s:a},nd=e=>t=>n=>r=>i=>o=>u=>{const s=(()=>{if(r==="South")return x(i._1,i._2+4);if(r==="North")return x(i._1,i._2-4);if(r==="East")return x(i._1+4,i._2);if(r==="West")return x(i._1-4,i._2);c()})(),a=(()=>{if(o==="South")return x(u._1,u._2+4);if(o==="North")return x(u._1,u._2-4);if(o==="East")return x(u._1+4,u._2);if(o==="West")return x(u._1-4,u._2);c()})(),f=(L,b,S)=>!fo(t)(ee(b)(S))(ne(b)(S))(L),g=(L,b,S)=>!fo(n)(ee(b)(S))(ne(b)(S))(L),d=(L,b,S,A)=>e.tag==="Just"&&!br(n)(ee(L)(b))(ne(L)(b))(e._1)?e._1:j1(t)(L)(b)(S)(A),l=(L,b,S,A)=>{if(L===S){const j=td(t)(b)(A)(L),R=U1(t)(L)(b)(A),P=Z1(t)(L)(b)(A);return[{start:x(L,b),end:x(L,R),direction:Kt},{start:x(L,R),end:x(j,R),direction:Ut},{start:x(j,R),end:x(j,P),direction:Kt},{start:x(j,P),end:x(S,P),direction:Ut},{start:x(S,P),end:x(S,A),direction:Kt}]}const O=d(L,S,b,A);return[{start:x(L,b),end:x(L,O),direction:Kt},{start:x(L,O),end:x(S,O),direction:Ut},{start:x(S,O),end:x(S,A),direction:Kt}]},_=(L,b,S,A)=>{if(b===A){const j=ed(t)(L)(S)(b),R=X1(t)(b)(L)(S),P=K1(t)(b)(L)(S);return[{start:x(L,b),end:x(R,b),direction:Ut},{start:x(R,b),end:x(R,j),direction:Kt},{start:x(R,j),end:x(P,j),direction:Ut},{start:x(P,j),end:x(P,A),direction:Kt},{start:x(P,A),end:x(S,A),direction:Ut}]}const O=zs(t)(b)(A)(L)(S);return[{start:x(L,b),end:x(O,b),direction:Ut},{start:x(O,b),end:x(O,A),direction:Kt},{start:x(O,A),end:x(S,A),direction:Ut}]},h=(L,b,S)=>!br(t)(ee(b)(S))(ne(b)(S))(L),p=(L,b,S)=>!br(n)(ee(b)(S))(ne(b)(S))(L),m=(L,b,S,A)=>{if(p(b,L,S)&&g(S,b,A))return[{start:x(L,b),end:x(S,b),direction:Ut},{start:x(S,b),end:x(S,A),direction:Kt}];const O=zs(t)(b)(A)(L)(S);return[{start:x(L,b),end:x(O,b),direction:Ut},{start:x(O,b),end:x(O,A),direction:Kt},{start:x(O,A),end:x(S,A),direction:Ut}]},N=(L,b,S,A)=>{if(g(L,b,A)&&p(A,L,S))return[{start:x(L,b),end:x(L,A),direction:Kt},{start:x(L,A),end:x(S,A),direction:Ut}];const O=d(L,S,b,A);return[{start:x(L,b),end:x(L,O),direction:Kt},{start:x(L,O),end:x(S,O),direction:Ut},{start:x(S,O),end:x(S,A),direction:Kt}]},J=(()=>{if(r==="South")return o==="North"?s._1===a._1&&f(s._1,s._2,a._2)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Kt}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?N(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="North")return o==="South"?s._1===a._1&&f(s._1,s._2,a._2)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Kt}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?N(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="East")return o==="West"?s._2===a._2&&h(s._2,s._1,a._1)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Ut}]:_(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:x(s._1,s._2),end:x(a._1,a._2),direction:Ut}]:_(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)})(),v=(()=>{if(r==="South"||r==="North")return Kt;if(r==="East"||r==="West")return Ut;c()})(),w={start:x(a._1,a._2),end:x(u._1,u._2),direction:(()=>{if(o==="South"||o==="North")return Kt;if(o==="East"||o==="West")return Ut;c()})()};return s._1===a._1&&s._2===a._2?[{start:x(i._1,i._2),end:x(u._1,u._2),direction:v}]:q1({start:x(i._1,i._2),end:x(s._1,s._2),direction:v})(J)(w)},rd=V(e=>({x:e.position._1*go-2,y:e.position._2*go-2,w:e.size._1*go+4,h:e.size._2*go+4})),Bs=te(k)(At),Ke=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},od=te(k)(At),$s=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},id=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e._1)(o._3._1);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(e._2==="North"){if(o._3._2==="North"){r=!1,i=E("Just",o._4);continue}n=o._5;continue}if(o._3._2==="North"){n=o._6;continue}if(e._2==="South"){if(o._3._2==="South"){r=!1,i=E("Just",o._4);continue}n=o._5;continue}if(o._3._2==="South"){n=o._6;continue}if(e._2==="East"){if(o._3._2==="East"){r=!1,i=E("Just",o._4);continue}n=o._5;continue}if(o._3._2==="East"){n=o._6;continue}if(e._2==="West"&&o._3._2==="West"){r=!1,i=E("Just",o._4);continue}}c()}return i},ud=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Qs=e=>t=>{const n=t.position._1+t.size._1,r=t.position._2*2+t.size._2,i=t.position._1*2+t.size._1,o=t.position._2+t.size._2;if(e==="South")return x(i,o*2);if(e==="North")return x(i,t.position._2*2);if(e==="East")return x(n*2,r);if(e==="West")return x(t.position._1*2,r);c()},Ai=e=>t=>{const n=ct(4);if(e==="South")return{lo:t.position._1*n,hi:(t.position._1+t.size._1)*n};if(e==="North")return{lo:t.position._1*n,hi:(t.position._1+t.size._1)*n};if(e==="East")return{lo:t.position._2*n,hi:(t.position._2+t.size._2)*n};if(e==="West")return{lo:t.position._2*n,hi:(t.position._2+t.size._2)*n};c()},qs=e=>t=>y(n=>r=>Tt(e)(se)(t(r))([r])(n))($),Hs=e=>t=>n=>r=>{const i=(e==="South"||e==="North")&&(t==="East"||t==="West")&&(()=>{if(e==="South")return r._2>n._2;if(e==="North")return r._2<n._2;if(e==="East")return r._2>n._2;if(e==="West")return r._2<n._2;c()})()&&(()=>{if(t==="East")return n._1>r._1;if(t==="West"||t==="North")return n._1<r._1;if(t==="South")return n._1>r._1;c()})(),o=(e==="East"||e==="West")&&(t==="North"||t==="South")&&(()=>{if(e==="South")return r._1>n._1;if(e==="North")return r._1<n._1;if(e==="East")return r._1>n._1;if(e==="West")return r._1<n._1;c()})()&&(()=>{if(t==="East")return n._2>r._2;if(t==="West"||t==="North")return n._2<r._2;if(t==="South")return n._2>r._2;c()})();return(e==="South"?t==="North"&&n._1===r._1&&r._2>n._2:e==="North"?t==="South"&&n._1===r._1&&r._2<n._2:e==="East"?t==="West"&&n._2===r._2&&r._1>n._1:e==="West"&&t==="East"&&n._2===r._2&&r._1<n._1)?0:i||o?1:2},Ys=e=>t=>{const n=e.hi-e.lo,r=(e.lo+e.hi)/2,i=t.length;return i===0?$:Bs(i===1?V(o=>x(o,r))(t):Dt(o=>u=>x(u,e.lo+ct(o+1|0)*n/ct(i+1|0)))(t))},Vs=e=>t=>n=>r=>i=>{const o=qs(k)(_=>_.to.node)(e),u=qs(k)(_=>_.from.node)(e),s=y(_=>h=>Z(k)(h.node)(h)(_))($)(t),a=(_,h,p)=>{const m=Ke(_)(s);if(m.tag==="Nothing")return x(0,0);if(m.tag==="Just"){const N=Ke(_)(n);if(N.tag==="Nothing"){const J=ct(4);if(p==="South")return x(m._1.position._1*J+m._1.size._1*J/2,(m._1.position._2+m._1.size._2)*J);if(p==="North")return x(m._1.position._1*J+m._1.size._1*J/2,m._1.position._2*J);if(p==="East")return x((m._1.position._1+m._1.size._1)*J,m._1.position._2*J+m._1.size._2*J/2);if(p==="West")return x(m._1.position._1*J,m._1.position._2*J+m._1.size._2*J/2);c()}if(N.tag==="Just"){const J=ge(v=>v.id===h)(N._1);if(J.tag==="Nothing"){const v=ct(4);if(p==="South")return x(m._1.position._1*v+m._1.size._1*v/2,(m._1.position._2+m._1.size._2)*v);if(p==="North")return x(m._1.position._1*v+m._1.size._1*v/2,m._1.position._2*v);if(p==="East")return x((m._1.position._1+m._1.size._1)*v,m._1.position._2*v+m._1.size._2*v/2);if(p==="West")return x(m._1.position._1*v,m._1.position._2*v+m._1.size._2*v/2);c()}if(J.tag==="Just"){const v=ct(4);if(J._1.side==="North")return x(m._1.position._1*v+ct(J._1.offset)*v,m._1.position._2*v);if(J._1.side==="South")return x(m._1.position._1*v+ct(J._1.offset)*v,(m._1.position._2+m._1.size._2)*v);if(J._1.side==="East")return x((m._1.position._1+m._1.size._1)*v,m._1.position._2*v+ct(J._1.offset)*v);if(J._1.side==="West")return x(m._1.position._1*v,m._1.position._2*v+ct(J._1.offset)*v)}}}c()},f=od(St(r)(_=>{if(_.nodes.length<=2)return[];const h=ct(4);if(1<_.nodes.length){const p=Ke(_.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 V(N=>x(N,m))(ye(N=>J=>_.edgeId+":"+N+"->"+J,_.nodes,Gt(1,_.nodes.length,_.nodes)))}c()}return[]})),g=_=>{const h=Ke(_.from.node)(s),p=Ke(_.to.node)(s);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,N=p._1,J=vt(v=>w=>ot.compare(v.score)(w.score))(V(v=>{const w=v._1,L=v._2;return{from:w,to:L,score:(()=>{const b=(j,R,P,et,K)=>{const B=Ai(j)(R),q=Ai(j)(P);return B.lo<q.hi&&q.lo<B.hi&&(w==="South"?L==="North"&&K._2>et._2:w==="North"?L==="South"&&K._2<et._2:w==="East"?L==="West"&&K._1>et._1:w==="West"&&L==="East"&&K._1<et._1)?0:Hs(w)(L)(et)(K)},S=Qs(w)(m),A=Qs(L)(N),O=Hs(w)(L)(S)(A);return(()=>{if(O>0){if(w==="South")return L==="North"?b(ce,m,N,S,A)*10|0:O*10|0;if(w==="North")return L==="South"?b(ae,m,N,S,A)*10|0:O*10|0;if(w==="East")return L==="West"?b(xn,m,N,S,A)*10|0:O*10|0;if(w==="West"&&L==="East")return b(vn,m,N,S,A)*10|0}return O*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})()}})([x(ce,ae),x(xn,ae),x(vn,ae),x(ce,xn),x(ce,vn),x(ae,ce),x(ae,xn),x(ae,vn),x(xn,ce),x(vn,ce),x(xn,vn),x(vn,xn)]));if(0<J.length)return{from:J[0].from,to:J[0].to}}return{from:ce,to:ae}},d=Bs(V(_=>x(_.id,g(_)))(e)),l=(_,h,p,m,N,J)=>{const v=ct(4),w=Ke(h)(s);if(w.tag==="Nothing")return x(0,0);if(w.tag==="Just"){const L=id(x(p,_))(i);if(L.tag==="Just"){const b=w._1.position._1*v+L._1,S=ct(4);if(_==="South")return x(b,(w._1.position._2+w._1.size._2)*S);if(_==="North")return x(b,w._1.position._2*S);if(_==="East")return x((w._1.position._1+w._1.size._1)*S,b);if(_==="West")return x(w._1.position._1*S,b);c()}if(L.tag==="Nothing"){const b=Ai(_)(w._1),S=(b.lo+b.hi)/2,A=$s(p)(Ys(b)(V(R=>R.id)(vt(R=>P=>lt.compare(N(_)(R))(N(_)(P)))(at(R=>{const P=$s(R.id)(d);if(P.tag==="Just"){const et=J(P._1);return et==="North"?_==="North":et==="South"?_==="South":et==="East"?_==="East":et==="West"&&_==="West"}if(P.tag==="Nothing")return!0;c()},(()=>{const R=Ke(h)(m);if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;c()})()))))),O=(()=>{if(A.tag==="Nothing")return S;if(A.tag==="Just")return A._1;c()})(),j=ct(4);if(_==="South")return x(O,(w._1.position._2+w._1.size._2)*j);if(_==="North")return x(O,w._1.position._2*j);if(_==="East")return x((w._1.position._1+w._1.size._1)*j,O);if(_==="West")return x(w._1.position._1*j,O)}}c()};return V(_=>{const h=ud(_.edge.id)(f);if(h.tag==="Nothing")return _;if(h.tag==="Just")return{..._,fromPos:ie(3)(_.edge.from.node)==="$d:"?x(h._1,_.fromPos._2):_.fromPos,toPos:ie(3)(_.edge.to.node)==="$d:"?x(h._1,_.toPos._2):_.toPos};c()})(V(_=>{if(_.from.port.tag==="Just"&&_.to.port.tag==="Just")return{edge:_,fromPos:a(_.from.node,_.from.port._1,ce),toPos:a(_.to.node,_.to.port._1,ae),fromSide:ce,toSide:ae};const h=g(_);return{edge:_,fromPos:l(h.from,_.from.node,_.id,u,p=>m=>{const N=Ke(m.to.node)(s);if(N.tag==="Nothing")return 0;if(N.tag==="Just"){const J=ct(4);if(p==="South"||p==="North")return N._1.position._1*J+N._1.size._1*J/2;if(p==="East"||p==="West")return N._1.position._2*J+N._1.size._2*J/2}c()},p=>p.from),toPos:l(h.to,_.to.node,_.id,o,p=>m=>{const N=Ke(m.from.node)(s);if(N.tag==="Nothing")return 0;if(N.tag==="Just"){const J=ct(4);if(p==="South"||p==="North")return N._1.position._1*J+N._1.size._1*J/2;if(p==="East"||p==="West")return N._1.position._2*J+N._1.size._2*J/2}c()},p=>p.to),fromSide:h.from,toSide:h.to}})(e))},Os=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},On=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},sd=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),zi=e=>t=>e.gapTop+1*ct(4)+ct(t)*2.5*ct(4),ad=e=>t=>{const n=Os(t.edge.id)(e);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return E("Just",{slot1Y:zi(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:zi(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return T;c()}if(n.tag==="Nothing")return T;c()},cd=e=>t=>{const n=y(r=>i=>Z(k)(i.node)(i)(r))($)(t);return Te(Dt(r=>i=>{const o=On(i.node)(n);if(o.tag==="Nothing")return[];if(o.tag==="Just"){const u=o._1;return Dt(s=>a=>{const f=i.edges.length,g=ct(4),d=u.position._1*g,l=u.position._2*g,_=u.size._2*g,h=ct((2*f|0)+1|0),p=l+_*ct(f-s|0)/h,m=l+_*ct((f+1|0)+s|0)/h,N=d-g*2.5*ct(s+1|0),J=[{start:x(d,p),end:x(N,p),direction:Ut},{start:x(N,p),end:x(N,m),direction:Kt},{start:x(N,m),end:x(d,m),direction:Ut}];return{edge:a.id,segments:J,bends:ye(v=>w=>v.end,J,Gt(1,3,J)),bendType:[],jumps:[],reversed:!1}})(i.edges)}c()})(V(r=>({node:r._1,edges:r._2}))(sd(y(r=>i=>Tt(k)(se)(i.from.node)([i])(r))($)(e)))))},fd=e=>t=>{const n=y(o=>u=>Z(k)(u.node)(u)(o))($)(t),r=o=>{const u=On(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.position._1;c()},i=o=>{const u=On(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.layer;c()};return vt(o=>u=>{const s=ot.compare(i(o.edge.from.node))(i(u.edge.from.node));if(s==="EQ"){const a=lt.compare(r(o.edge.from.node))(r(u.edge.from.node));return a==="EQ"?lt.compare(r(o.edge.to.node))(r(u.edge.to.node)):a}return s})(e)},he=e=>{const t=ct(4);return{x:e.position._1*t-2,y:e.position._2*t-2,w:e.size._1*t+4,h:e.size._2*t+4}},gd=e=>e.from.node===e.to.node,_d=e=>t=>n=>r=>{const i=F1(n)(nd(e)(t)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:i,bends:ye(o=>u=>o.end,i,Gt(1,i.length,i)),bendType:[],jumps:[],reversed:!1}},dd=e=>t=>n=>r=>{const i=[{start:x(r.fromPos._1,r.fromPos._2),end:x(r.fromPos._1,e.slot1Y),direction:Kt},{start:x(r.fromPos._1,e.slot1Y),end:x(e.splitX,e.slot1Y),direction:Ut},{start:x(e.splitX,e.slot1Y),end:x(e.splitX,e.slot2Y),direction:Kt},{start:x(e.splitX,e.slot2Y),end:x(r.toPos._1,e.slot2Y),direction:Ut},{start:x(r.toPos._1,e.slot2Y),end:x(r.toPos._1,r.toPos._2),direction:Kt}];return{edge:r.edge.id,segments:i,bends:ye(o=>u=>o.end,i,Gt(1,5,i)),bendType:[],jumps:[],reversed:!1}},ld=e=>t=>n=>{const r=On(e.edge.from.node)(n);if(r.tag==="Just"){const o=On(e.edge.to.node)(n);return o.tag==="Just"?at(u=>!(u.h===he(r._1).h&&u.w===he(r._1).w&&u.x===he(r._1).x&&u.y===he(r._1).y)&&!(u.h===he(o._1).h&&u.w===he(o._1).w&&u.x===he(o._1).x&&u.y===he(o._1).y),t):at(u=>!(u.h===he(r._1).h&&u.w===he(r._1).w&&u.x===he(r._1).x&&u.y===he(r._1).y),t)}const i=On(e.edge.to.node)(n);return i.tag==="Just"?at(o=>!(o.h===he(i._1).h&&o.w===he(i._1).w&&o.x===he(i._1).x&&o.y===he(i._1).y),t):at(o=>!0,t)},hd=e=>t=>{const n=Os(t.edge.id)(e);if(n.tag==="Just")return E("Just",zi(n._1)(n._1.slot));if(n.tag==="Nothing")return T;c()},pd=e=>t=>n=>r=>i=>{const o=y(f=>g=>Z(k)(g.node)(g)(f))($)(t),u=rd(t),s=Vs(at(f=>f.from.node!==f.to.node,e))(t)(n)(r)(i),a=Ds(s)(t);return[...cd(at(gd,e))(t),...y(f=>g=>{const d=ld(g)(u)(o),l=[...d,...f.edgeObstacles],_=ad(a)(g),h=(()=>{if(_.tag==="Just")return dd(_._1)(d)(l)(g);if(_.tag==="Nothing")return _d(hd(a)(g))(d)(l)(g);c()})();return{results:[...f.results,h],edgeObstacles:[...f.edgeObstacles,...Q1(h.segments)]}})({results:[],edgeObstacles:[]})(fd(s)(t)).results]},gn=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},_n=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},md=e=>t=>n=>{if(e.start._1!==t.start._1)return T;const r=_n(gn(e.start._2)(e.end._2))(gn(t.start._2)(t.end._2)),i=gn(_n(e.start._2)(e.end._2))(_n(t.start._2)(t.end._2));return r<i?E("Just",{position:x(e.start._1,(r+i)/2),crossingEdge:n}):T},yd=e=>t=>n=>{if(e.start._2!==t.start._2)return T;const r=_n(gn(e.start._1)(e.end._1))(gn(t.start._1)(t.end._1)),i=gn(_n(e.start._1)(e.end._1))(_n(t.start._1)(t.end._1));return r<i?E("Just",{position:x((r+i)/2,e.start._2),crossingEdge:n}):T},Jd=e=>t=>n=>{if(e.direction==="H")return yd(e)(t)(n);if(e.direction==="V")return md(e)(t)(n);c()},Nd=e=>t=>n=>{const r=e+1|0,i=r<1?n:Gt(r,n.length,n);return St(t.segments)(o=>St(i)(u=>Pt(s=>Jd(o)(s)(u.edge))(at(s=>s.direction==="H"?o.direction==="H":s.direction==="V"&&o.direction==="V",u.segments))))},xd=e=>t=>n=>t.start._1>gn(e.start._1)(e.end._1)&&t.start._1<_n(e.start._1)(e.end._1)&&e.start._2>gn(t.start._2)(t.end._2)&&e.start._2<_n(t.start._2)(t.end._2)?E("Just",{position:x(t.start._1,e.start._2),crossingEdge:n}):T,vd=e=>t=>St(at(n=>n.direction==="H",e.segments))(n=>St(t)(r=>Pt(i=>xd(n)(i)(r.edge))(at(i=>i.direction==="V",r.segments)))),Td=e=>t=>n=>[...vd(t)(at(r=>r.edge!==t.edge,n)),...Nd(e)(t)(n)],_o=(()=>{const e={eq:t=>n=>t._1===n._1&&(t._2==="North"?n._2==="North":t._2==="South"?n._2==="South":t._2==="East"?n._2==="East":t._2==="West"&&n._2==="West")};return{compare:t=>n=>{const r=k.compare(t._1)(n._1);if(r==="LT")return Ae;if(r==="GT")return ze;if(t._2==="North")return n._2==="North"?Oe:Ae;if(n._2==="North")return ze;if(t._2==="South")return n._2==="South"?Oe:Ae;if(n._2==="South")return ze;if(t._2==="East")return n._2==="East"?Oe:Ae;if(n._2==="East")return ze;if(t._2==="West"&&n._2==="West")return Oe;c()},Eq0:()=>e}})(),wd=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=_o.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},bd=te(k)(At),Bi=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},kd=te(_o)(At),Fs=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),Fn=e=>t=>n=>r=>{const i=wd(x(t,n))(e);if(i.tag==="Nothing")return r;if(i.tag==="Just")return i._1;c()},Xs=e=>t=>n=>{const r=bd(Te(V(u=>Dt(s=>a=>x(a,s))(u))(e))),i=(u,s)=>{if(u==="South"){const a=Bi(s.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()}if(u==="North"){const a=Bi(s.from.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()}return 0},o=u=>y(s=>a=>Ne(_o.compare,me,kd(V(f=>x(x(f._1,u),f._2))(Fs(Ys({lo:0,hi:(()=>{const f=Bi(a._1)(n);if(f.tag==="Just")return f._1._1;if(f.tag==="Nothing")return ie(3)(a._1)==="$d:"?0:1;c()})()})(V(f=>f.id)(vt(f=>g=>ot.compare(i(u,f))(i(u,g)))(a._2)))))),s))($)(Fs(y(s=>a=>a.from.node===a.to.node?s:u==="South"?Tt(k)(se)(a.from.node)([a])(s):u==="North"?Tt(k)(se)(a.to.node)([a])(s):s)($)(t)));return Ne(_o.compare,me,o(ae),o(ce))},Us=e=>e,Ks=e=>e,Zs=e=>e,Ld=y(e=>t=>Z(k)(t)()(e))($),Ed=(()=>{const e=Ie.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return E("Just",x(t._1,t._2));c()});return t=>e((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._3,n(r._6,i)));c()};return n(t,Qt)})())})(),tt=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Le=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},$e=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Se=te(k)(At),$i=Sf(k),kr=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),js=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Cd=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Sd=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=ot.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},ta=Zs("VDown"),ea=Zs("VUp"),Pd=Ks("ForwardPhase"),Rd=Ks("StackPhase"),na=Us("HRight"),ra=Us("HLeft"),Id=e=>t=>n=>{const r=y(u=>s=>Tt(k)(Zt)(s.tgt)(1)(u))($)(e),i=Ed(Ld([...V(u=>u.src)(e),...V(u=>u.tgt)(e),...(()=>{const u=(s,a)=>{if(s.tag==="Leaf")return a;if(s.tag==="Node")return u(s._5,zt("Cons",s._4,u(s._6,a)));c()};return bt(Yt.foldr,u(t,Qt))})()])),o=y(u=>s=>Tt(k)(se)(s.src)([{target:s.tgt,sep:s.sep}])(u))($)(e);return(u=>s=>a=>{let f=u,g=s,d=a,l=!0,_;for(;l;){const h=f,p=g,m=d,N=Ht(J=>T,J=>v=>E("Just",{head:J,tail:v}),h);if(N.tag==="Nothing"){l=!1,_=m;continue}if(N.tag==="Just"){const J=tt(N._1.head)(m),v=(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;c()})(),w=y(L=>b=>{const S=tt(b.target)(L.result),A=v+b.sep,O=tt(b.target)(L.indeg),j=(()=>{if(O.tag==="Nothing")return-1;if(O.tag==="Just")return O._1-1|0;c()})();return{newQueue:j===0?[...L.newQueue,b.target]:L.newQueue,result:Z(k)(b.target)((()=>{if(S.tag==="Nothing")return A;if(S.tag==="Just"){if(n==="VDown")return Le(S._1)(A);if(n==="VUp")return $e(S._1)(A)}c()})())(L.result),indeg:Z(k)(b.target)(j)(L.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const L=tt(N._1.head)(o);if(L.tag==="Nothing")return[];if(L.tag==="Just")return L._1;c()})());f=[...N._1.tail,...w.newQueue],g=w.indeg,d=w.result;continue}c()}return _})(at(u=>{const s=tt(u)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;c()},i))($)(y(u=>s=>Z(k)(s)(0)(u))($)(i))},Dd=e=>{const t=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return t(o._5,zt("Cons",o._4,t(o._6,u)));c()},n=bt(Yt.foldr,t(e,Qt)),r=y(Le)(999999)(n);if(r===0||n.length===0)return e;const i=o=>{if(o.tag==="Leaf")return $;if(o.tag==="Node")return Ft("Node",o._1,o._2,o._3,o._4-r,i(o._5),i(o._6));c()};return i(e)},Gd=e=>t=>{const n=(i,o,u)=>ie(3)(o)==="$d:"&&Cu(s=>ie(3)(s)==="$d:",(()=>{const s=tt(o)(e.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;c()})()),r=i=>o=>u=>s=>a=>f=>g=>{let d=i,l=o,_=s,h=f,p=g,m=!0,N;for(;m;){const J=d,v=l,w=_,L=h,b=p,S=v.length;if(b>=S){m=!1,N=J;continue}const A=b>=0&&b<v.length?E("Just",v[b]):T,O=(()=>{if(A.tag==="Nothing")return"";if(A.tag==="Just")return A._1;c()})(),j=n(e,O);if(b===(S-1|0)||j){const R=(()=>{if(j){const P=tt(O)(e.preds),et=(()=>{if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;c()})();if(0<et.length){const K=w-1|0,B=tt(et[0])(e.nodeIndex);if(B.tag==="Nothing")return K;if(B.tag==="Just")return B._1;c()}}return w-1|0})();d=y(P=>et=>{if(et>=0&&et<v.length){const K=v[et];return n(e,K)?P:y(B=>q=>{const M=tt(q)(e.nodeIndex),C=(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;c()})();return C<L||C>R?Z(k)(q+"\u2192"+K)()(B):B})(P)((()=>{const B=tt(K)(e.preds);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;c()})())}return n(e,"")?P:y(K=>B=>{const q=tt(B)(e.nodeIndex),M=(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;c()})();return M<L||M>R?Z(k)(B+"\u2192")()(K):K})(P)((()=>{const K=tt("")(e.preds);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;c()})())})(J)(qt(0,b)),l=v,_=w,h=R,p=b+1|0;continue}d=J,l=v,_=w,h=L,p=b+1|0}return N};return t.length<3?$:y(i=>o=>{if(o>=0&&o<t.length){const u=t[o];return r(i)((()=>{const s=o+1|0;return s>=0&&s<t.length?t[s]:[]})())(u)(u.length)(o)(0)(0)}return r(i)((()=>{const u=o+1|0;return u>=0&&u<t.length?t[u]:[]})())([])(0)(o)(0)(0)})($)(qt(1,t.length-2|0))},oa=e=>{const t=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return t(o._5,zt("Cons",o._4,t(o._6,u)));c()},n=t(e,Qt),r=o=>u=>{let s=o,a=u,f=!0,g;for(;f;){const d=s,l=a;if(l.tag==="Nil"){f=!1,g=d;continue}if(l.tag==="Cons"){s=$e(d)(l._1),a=l._2;continue}c()}return g},i=o=>u=>{let s=o,a=u,f=!0,g;for(;f;){const d=s,l=a;if(l.tag==="Nil"){f=!1,g=d;continue}if(l.tag==="Cons"){s=Le(d)(l._1),a=l._2;continue}c()}return g};return r(-999999)(n)-i(999999)(n)},Lr=e=>t=>(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,f=o;if(a===t){u=!1,s=f;continue}i=(()=>{const g=tt(a)(e.align);if(g.tag==="Nothing")return t;if(g.tag==="Just")return g._1;c()})(),o=[...f,a]}return s})((()=>{const n=tt(t)(e.align);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;c()})())([t]),Md=e=>t=>n=>r=>i=>o=>u=>s=>a=>f=>g=>{const d=(C,I,D)=>{const G=C.from.node===I?C.from.port:C.to.node===I?C.to.port:T;if(G.tag==="Just"){const Y=tt(I)(i);if(Y.tag==="Just"){const X=ge(H=>H.id===G._1)(Y._1);if(X.tag==="Just"){const H=ct(X._1.offset)*ct(4);return D==="North"||D==="South"?H:0}if(X.tag==="Nothing"){const H=tt(I)(r),Q=Fn(u)(C.id)(D)((()=>{if(H.tag==="Nothing")return .5;if(H.tag==="Just")return H._1._1/2;c()})());return D==="North"||D==="South"?Q:0}c()}if(Y.tag==="Nothing"){const X=tt(I)(r),H=Fn(u)(C.id)(D)((()=>{if(X.tag==="Nothing")return .5;if(X.tag==="Just")return X._1._1/2;c()})());return D==="North"||D==="South"?H:0}c()}if(G.tag==="Nothing"){const Y=tt(I)(r),X=Fn(u)(C.id)(D)((()=>{if(Y.tag==="Nothing")return .5;if(Y.tag==="Just")return Y._1._1/2;c()})());return D==="North"||D==="South"?X:0}c()},l=(C,I)=>{if(C.from.node===I){if(g==="HRight")return ce;if(g==="HLeft")return ae;c()}if(g==="HRight")return ae;if(g==="HLeft")return ce;c()},_=(C,I,D)=>y(G=>Y=>Z(k)(Y)((()=>{const X=tt(Y)(G);if(X.tag==="Nothing")return 0+I;if(X.tag==="Just")return X._1+I;c()})())(G))(D)(Lr(a)(C)),h=(()=>{if(g==="HRight")return n;if(g==="HLeft")return le(n);c()})(),p=C=>{const I=tt(C)(r);if(I.tag==="Nothing")return 1;if(I.tag==="Just")return I._1._1;c()},m=Se(Te(Dt(C=>I=>V(D=>x(D,C))(I))(n))),N=(C,I)=>ie(3)(C)==="$d:"&&ie(3)(I)==="$d:"||ie(3)(C)==="$d:"||ie(3)(I)==="$d:"?10:ct(e.nodeGap),J=y(C=>I=>$i(D=>E("Just",[...(()=>{if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})(),I]))(I.to.node)(C))($)(o),v=y(C=>I=>$i(D=>E("Just",[...(()=>{if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})(),I]))(I.from.node)(C))($)(o),w=Te(n),L=y(C=>I=>{const D=tt(I)(a.root),G=(()=>{if(D.tag==="Nothing")return I;if(D.tag==="Just")return D._1;c()})();return I===G?C:$i(Y=>E("Just",(()=>{if(Y.tag==="Nothing")return!0;if(Y.tag==="Just")return Y._1;c()})()&&ie(3)(I)==="$d:"))(G)(C)})(Se(V(C=>x(C,!0))(Mn(k.compare)((()=>{const C=(I,D)=>{if(I.tag==="Leaf")return D;if(I.tag==="Node")return C(I._5,zt("Cons",I._4,C(I._6,D)));c()};return bt(Yt.foldr,C(a.root,Qt))})()))))(w),b=(C,I)=>{const D=C.free,G=tt(D)(a.root),Y=(()=>{if(G.tag==="Nothing")return D;if(G.tag==="Just")return G._1;c()})(),X=tt(Y)(L),H=(()=>{if(X.tag==="Nothing")return!0;if(X.tag==="Just")return X._1;c()})();return y(Q=>W=>{if(Q.edge.tag==="Just")return Q;if(Q.edge.tag==="Nothing"){if((()=>{const ft=tt(Y)(I.su);return!H&&(()=>{const ht=tt(W.from.node)(m);return W.from.node!==W.to.node&&(()=>{const wt=tt(W.to.node)(m);return(()=>{if(ht.tag==="Nothing")return-1;if(ht.tag==="Just")return ht._1;c()})()===(()=>{if(wt.tag==="Nothing")return-1;if(wt.tag==="Just")return wt._1;c()})()})()})()||(()=>{if(ft.tag==="Nothing")return!1;if(ft.tag==="Just")return ft._1;c()})()})())return Q;const U=W.from.node===D?W.to.node:W.from.node,F=tt(U)(a.root),_t=(()=>{if(F.tag==="Nothing")return U;if(F.tag==="Just")return F._1;c()})(),pt=_t!==Y;return pt&&(()=>{const ft=tt(_t)(I.blockFinished);if(ft.tag==="Nothing")return!1;if(ft.tag==="Just")return ft._1;c()})()?{...Q,edge:E("Just",W),hasEdges:!0}:{...Q,hasEdges:Q.hasEdges||pt}}c()})({edge:T,hasEdges:!1})((()=>{if(C.isRoot){if(g==="HRight"){const Q=tt(D)(J);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()}if(g==="HLeft"){const Q=tt(D)(v);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1}c()}if(g==="HRight"){const Q=tt(D)(v);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()}if(g==="HLeft"){const Q=tt(D)(J);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1}c()})())},S=(C,I,D,G)=>{const Y=(()=>{if(f==="VDown")return-1e18;if(f==="VUp")return 1e18;c()})(),X={free:I,isRoot:D},H=b(X,G);if(H.edge.tag==="Nothing")return H.hasEdges?{thresh:Y,state:{...G,queue:[...G.queue,X]}}:{thresh:Y,state:G};if(H.edge.tag==="Just"){const Q=H.edge._1.from.node===I?H.edge._1.to.node:H.edge._1.from.node;return{thresh:(()=>{const W=tt((()=>{const pt=tt(Q)(a.root);if(pt.tag==="Nothing")return Q;if(pt.tag==="Just")return pt._1;c()})())(G.x),U=tt(Q)(s),F=tt(I)(s),_t=(()=>{if(W.tag==="Just")return W._1;if(W.tag==="Nothing")return T;c()})();return(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;c()})()+(()=>{if(U.tag==="Nothing")return 0;if(U.tag==="Just")return U._1;c()})()+d(H.edge._1,Q,(()=>{if(D){if(g==="HRight")return ce;if(g==="HLeft")return ae;c()}if(g==="HRight")return ae;if(g==="HLeft")return ce;c()})())-(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;c()})()-d(H.edge._1,I,(()=>{if(D){if(g==="HRight")return ae;if(g==="HLeft")return ce;c()}if(g==="HRight")return ce;if(g==="HLeft")return ae;c()})())})(),state:{...G,su:Z(k)((()=>{const W=tt(H.edge._1.from.node)(a.root);if(W.tag==="Nothing")return H.edge._1.from.node;if(W.tag==="Just")return W._1;c()})())(!0)(Z(k)((()=>{const W=tt(H.edge._1.to.node)(a.root);if(W.tag==="Nothing")return H.edge._1.to.node;if(W.tag==="Just")return W._1;c()})())(!0)(G.su))}}}c()},A=(C,I,D,G)=>{const Y=I===C,X=tt(I)(a.align),H=(()=>{if(X.tag==="Nothing")return I===C;if(X.tag==="Just")return X._1===C;c()})();if(!(Y||H))return{thresh:D,state:G};const Q=(()=>{if(f==="VDown")return Y&&D<=-1e18;if(f==="VUp")return Y&&D>=1e18;c()})()?S(C,I,!0,G):{thresh:D,state:G};return(()=>{if(f==="VDown")return Q.thresh<=-1e18&&H;if(f==="VUp")return Q.thresh>=1e18&&H;c()})()?S(C,I,!1,Q.state):Q},O=C=>I=>D=>{const G=tt(D)(t.nodeIndex),Y=(()=>{if(G.tag==="Nothing")return 0;if(G.tag==="Just")return G._1;c()})(),X=ge(F=>Be(Fe)(D)(F))(h),H=(()=>{if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;c()})(),Q=H.length;if((()=>{if(f==="VDown")return Y<=0;if(f==="VUp")return Y>=(Q-1|0);c()})()){const F=A(C,D,I.thresh,I.st);return{...I,st:F.state,thresh:F.thresh}}const W=(()=>{if(f==="VDown")return Y-1|0;if(f==="VUp")return Y+1|0;c()})(),U=W>=0&&W<H.length?E("Just",H[W]):T;if(U.tag==="Nothing")return I;if(U.tag==="Just"){const F=tt(U._1)(a.root),_t=(()=>{if(F.tag==="Nothing")return U._1;if(F.tag==="Just")return F._1;c()})(),pt=A(C,D,I.thresh,j(_t)(I.st)),ft=(()=>{const re=tt(C)(pt.state.sink);if(re.tag==="Nothing")return C===C;if(re.tag==="Just")return re._1===C;c()})()?{...pt.state,sink:Z(k)(C)((()=>{const re=tt(_t)(pt.state.sink);if(re.tag==="Nothing")return _t;if(re.tag==="Just")return re._1;c()})())(pt.state.sink)}:pt.state,ht=tt(_t)(ft.sink),wt=(()=>{if(ht.tag==="Nothing")return _t;if(ht.tag==="Just")return ht._1;c()})(),It=tt(C)(ft.sink),dt=(()=>{if(It.tag==="Nothing")return C;if(It.tag==="Just")return It._1;c()})();if(dt===wt){const re=tt(_t)(ft.x),Ve=(()=>{if(re.tag==="Just")return re._1;if(re.tag==="Nothing")return T;c()})(),er=(()=>{if(Ve.tag==="Nothing")return 0;if(Ve.tag==="Just")return Ve._1;c()})(),on=tt(C)(ft.x),Et=(()=>{if(on.tag==="Just")return on._1;if(on.tag==="Nothing")return T;c()})(),Rt=(()=>{if(Et.tag==="Nothing")return 0;if(Et.tag==="Just")return Et._1;c()})(),nr=N(D,U._1),Sn=tt(U._1)(s),Pn=tt(D)(s),rr=(()=>{if(Sn.tag==="Nothing")return 0;if(Sn.tag==="Just")return Sn._1;c()})()-(()=>{if(Pn.tag==="Nothing")return 0;if(Pn.tag==="Just")return Pn._1;c()})();if(f==="VDown"){const We=$e(er+rr+p(U._1)+nr)(pt.thresh);return{st:{...ft,x:Z(k)(C)(E("Just",I.initial?We:$e(Rt)(We)))(ft.x)},initial:!1,thresh:pt.thresh}}if(f==="VUp"){const We=Le(er+rr-nr-p(D))(pt.thresh);return{st:{...ft,x:Z(k)(C)(E("Just",I.initial?We:Le(Rt)(We)))(ft.x)},initial:!1,thresh:pt.thresh}}c()}const Mt=tt(_t)(ft.x),mt=(()=>{if(Mt.tag==="Just")return Mt._1;if(Mt.tag==="Nothing")return T;c()})(),gt=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})(),rt=tt(C)(ft.x),nt=(()=>{if(rt.tag==="Just")return rt._1;if(rt.tag==="Nothing")return T;c()})(),st=(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})(),yt=ct(e.nodeGap),Jt=tt(D)(s),Ct=tt(U._1)(s),$t=(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;c()})()-(()=>{if(Ct.tag==="Nothing")return 0;if(Ct.tag==="Just")return Ct._1;c()})();return{st:{...ft,classEdges:[...ft.classEdges,{src:dt,tgt:wt,sep:(()=>{if(f==="VDown")return st+$t-gt-p(U._1)-yt;if(f==="VUp")return st+$t+p(D)+yt-gt;c()})()}]},initial:I.initial,thresh:pt.thresh}}c()},j=C=>I=>{const D=tt(C)(I.x),G=(()=>{if(D.tag==="Just")return D._1;if(D.tag==="Nothing")return T;c()})();if(G.tag==="Just")return I;if(G.tag==="Nothing"){const Y=y(O(C))({st:{...I,x:Z(k)(C)(E("Just",0))(I.x)},initial:!0,thresh:(()=>{if(f==="VDown")return-1e18;if(f==="VUp")return 1e18;c()})()})(Lr(a)(C));return{...Y.st,blockFinished:Z(k)(C)(!0)(Y.st.blockFinished)}}c()},R=y(C=>I=>y(D=>G=>{const Y=tt(G)(a.root),X=(()=>{if(Y.tag==="Nothing")return G;if(Y.tag==="Just")return Y._1;c()})();return X===G?j(X)(D):D})(C)((()=>{if(f==="VDown")return I;if(f==="VUp")return le(I);c()})()))({x:Se(V(C=>x(C,T))(w)),sink:Se(V(C=>x(C,C))(w)),classEdges:[],su:$,blockFinished:$,queue:[]})(h),P=Id(R.classEdges)(R.sink)(f),et=(C,I,D,G)=>{const Y=tt(I)(G),X=tt(I)(s);return(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;c()})()+(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;c()})()+d(C,I,D)},K=Se(V(C=>x(C,!0))(Mn(k.compare)((()=>{const C=(I,D)=>{if(I.tag==="Leaf")return D;if(I.tag==="Node")return C(I._5,zt("Cons",I._4,C(I._6,D)));c()};return bt(Yt.foldr,C(a.root,Qt))})()))),B=C=>I=>D=>{const G=b(D,{su:I.su,blockFinished:K}),Y={phase:C,ppFree:D.free,ppIsRoot:D.isRoot,edgeId:T,delta:0,avail:0,shift:0,freeSu:(()=>{const X=tt((()=>{const H=tt(D.free)(a.root);if(H.tag==="Nothing")return D.free;if(H.tag==="Just")return H._1;c()})())(I.su);if(X.tag==="Nothing")return!1;if(X.tag==="Just")return X._1;c()})(),hasEdges:G.hasEdges,candCount:(()=>{if(D.isRoot){if(g==="HRight"){const X=tt(D.free)(J);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length;c()}if(g==="HLeft"){const X=tt(D.free)(v);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length}c()}if(g==="HRight"){const X=tt(D.free)(v);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length;c()}if(g==="HLeft"){const X=tt(D.free)(J);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length}c()})()};if(G.edge.tag==="Nothing")return{...I,stack:[...I.stack,D],trace:[...I.trace,Y],x:I.x};if(G.edge.tag==="Just"){const X=G.edge._1.from.node===D.free?x(G.edge._1.from.node,G.edge._1.to.node):x(G.edge._1.to.node,G.edge._1.from.node),H=et(G.edge._1,X._1,l(G.edge._1,X._1),I.x)-et(G.edge._1,X._2,l(G.edge._1,X._2),I.x),Q=tt(X._1)(a.root),W=(()=>{if(Q.tag==="Nothing")return X._1;if(Q.tag==="Just")return Q._1;c()})(),U={...Y,edgeId:E("Just",G.edge._1.id),delta:H};if(H>0&&H<1e300){const F=y(ft=>ht=>{const wt=tt(ht)(m),It=(()=>{if(wt.tag==="Nothing")return-1;if(wt.tag==="Just")return wt._1;c()})();if(It>=0&&It<n.length){const mt=n[It],gt=tt(ht)(t.nodeIndex),rt=(()=>{if(gt.tag==="Nothing")return-2;if(gt.tag==="Just")return gt._1-1|0;c()})();return rt>=0&&rt<mt.length?Le(ft)((()=>{const nt=tt(ht)(I.x),st=tt(ht)(s),yt=tt(mt[rt])(I.x),Jt=tt(mt[rt])(s);return(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;c()})()-((()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;c()})()+p(mt[rt])+N(ht,mt[rt]))})()):ft}const dt=tt(ht)(t.nodeIndex),Mt=(()=>{if(dt.tag==="Nothing")return-2;if(dt.tag==="Just")return dt._1-1|0;c()})();return Mt>=0&&Mt<0?Le(ft)((()=>{const mt=tt(ht)(I.x),gt=tt(ht)(s),rt=tt([][Mt])(I.x),nt=tt([][Mt])(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})()+(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;c()})()-((()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+p([][Mt])+N(ht,[][Mt]))})()):ft})(H)(Lr(a)(W)),_t=F>0?-F:0,pt={...I,x:F>0?_(W,_t,I.x):I.x,trace:[...I.trace,{...U,avail:F,shift:_t}]};return F>0?pt:{...pt,stack:[...pt.stack,D]}}if(H<0&&-H<1e300){const F=y(ft=>ht=>{const wt=tt(ht)(m),It=(()=>{if(wt.tag==="Nothing")return-1;if(wt.tag==="Just")return wt._1;c()})();if(It>=0&&It<n.length){const mt=n[It],gt=tt(ht)(t.nodeIndex),rt=(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1+1|0;c()})();return rt>=0&&rt<mt.length?Le(ft)((()=>{const nt=tt(mt[rt])(I.x),st=tt(mt[rt])(s),yt=tt(ht)(I.x),Jt=tt(ht)(s);return(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;c()})()-((()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;c()})()+p(ht)+N(ht,mt[rt]))})()):ft}const dt=tt(ht)(t.nodeIndex),Mt=(()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1+1|0;c()})();return Mt>=0&&Mt<0?Le(ft)((()=>{const mt=tt([][Mt])(I.x),gt=tt([][Mt])(s),rt=tt(ht)(I.x),nt=tt(ht)(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})()+(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;c()})()-((()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+p(ht)+N(ht,[][Mt]))})()):ft})(-H)(Lr(a)(W)),_t=F>0?F:0,pt={...I,x:F>0?_(W,_t,I.x):I.x,trace:[...I.trace,{...U,avail:F,shift:_t}]};return F>0?pt:{...pt,stack:[...pt.stack,D]}}return{...I,stack:[...I.stack,D],trace:[...I.trace,U],x:I.x}}c()},q=y(B(Pd))({x:Se(V(C=>x(C,(()=>{const I=tt(C)(a.root),D=(()=>{if(I.tag==="Nothing")return C;if(I.tag==="Just")return I._1;c()})(),G=tt(D)(R.x),Y=tt((()=>{const H=tt(D)(R.sink);if(H.tag==="Nothing")return D;if(H.tag==="Just")return H._1;c()})())(P),X=(()=>{if(G.tag==="Just")return G._1;if(G.tag==="Nothing")return T;c()})();return(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;c()})()+(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;c()})()})()))(w)),su:R.su,stack:[],trace:[]})(R.queue),M=y(B(Rd))({...q,stack:[]})(le(q.stack));return{x:M.x,queue:R.queue,trace:M.trace}},Wd=e=>t=>n=>r=>i=>o=>u=>s=>a=>f=>g=>Md(e)(t)(n)(r)(i)(o)(u)(s)(a)(f)(g).x,Ad=e=>t=>n=>r=>i=>o=>{const u=(a,f,g)=>{const d=tt(f)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;c()})(),_=a.from.node===f?a.from.port:a.to.node===f?a.to.port:T;if(_.tag==="Just"){const h=tt(f)(t);if(h.tag==="Just"){const p=ge(m=>m.id===_._1)(h._1);if(p.tag==="Just"){const m=ct(p._1.offset)*ct(4);return g==="North"||g==="South"?m:0}if(p.tag==="Nothing"){const m=Fn(i)(a.id)(g)(l);return g==="North"||g==="South"?m:0}c()}if(h.tag==="Nothing"){const p=Fn(i)(a.id)(g)(l);return g==="North"||g==="South"?p:0}c()}if(_.tag==="Nothing"){const h=Fn(i)(a.id)(g)(l);return g==="North"||g==="South"?h:0}c()},s=a=>f=>g=>d=>{let l=a,_=f,h=g,p=d,m=!0,N;for(;m;){const J=l,v=_,w=h,L=Ht(b=>T,b=>S=>E("Just",{head:b,tail:S}),p);if(L.tag==="Nothing"){m=!1,N=J;continue}if(L.tag==="Just"){const b=L._1.head,S=ge(O=>O.from.node===w&&O.to.node===b||O.from.node===b&&O.to.node===w)(r),A=(()=>{if(S.tag==="Nothing")return v+0;if(S.tag==="Just")return v+(u(S._1,w,S._1.from.node===w?ce:ae)-u(S._1,b,S._1.from.node===b?ce:ae));c()})();l=Z(k)(b)(A)(J),_=A,h=b,p=L._1.tail;continue}c()}return N};return y(a=>f=>{const g=Ht(_=>T,_=>h=>E("Just",{head:_,tail:h}),Lr(e)(f)),d=(()=>{if(g.tag==="Nothing")return Z(k)(f)(0)($);if(g.tag==="Just")return s(Z(k)(g._1.head)(0)($))(0)(g._1.head)(g._1.tail);c()})(),l=y(_=>h=>$e(_)(-h._2))(0)(kr(d));return y(_=>h=>Z(k)(h._1)(h._2+l)(_))(a)(kr(d))})($)(Mn(k.compare)((()=>{const a=(f,g)=>{if(f.tag==="Leaf")return g;if(f.tag==="Node")return a(f._5,zt("Cons",f._4,a(f._6,g)));c()};return bt(Yt.foldr,a(e.root,Qt))})()))},zd=e=>t=>n=>r=>i=>{const o=Te(t),u=y(s=>a=>{const f=y(g=>d=>{const l=(()=>{if(i==="HRight"){const m=tt(d)(e.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;c()}if(i==="HLeft"){const m=tt(d)(e.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}c()})(),_=l.length;if(_===0)return g;const h=Rn(_-1|0,2),p=Rn(_,2);return y(m=>N=>{if((()=>{const J=tt(d)(m.align);if(J.tag==="Nothing")return d!==d;if(J.tag==="Just")return J._1!==d;c()})())return m;if(N>=0&&N<l.length){const J=tt(l[N])(e.nodeIndex),v=(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;c()})();if(!(js(l[N]+"\u2192"+d)(n)||js(d+"\u2192"+l[N])(n))&&(()=>{if(r==="VDown")return m.r<v;if(r==="VUp")return m.r>v;c()})()){const w=tt(l[N])(m.root),L=(()=>{if(w.tag==="Nothing")return l[N];if(w.tag==="Just")return w._1;c()})();return{root:Z(k)(d)(L)(m.root),align:Z(k)(l[N])(d)(Z(k)(d)(L)(m.align)),r:v}}}return m})(g)((()=>{if(r==="VDown")return qt(h,p);if(r==="VUp")return le(qt(h,p));c()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;c()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return le(a);c()})());return{root:f.root,align:f.align}})({root:Se(V(s=>x(s,s))(o)),align:Se(V(s=>x(s,s))(o))})((()=>{if(i==="HRight")return t;if(i==="HLeft")return le(t);c()})());return{root:u.root,align:u.align}},lo=e=>t=>n=>r=>i=>o=>u=>s=>a=>f=>{const g=zd(t)(n)(s)(a)(f),d=Ad(g)(i)(r)(o)(u)(f);return Cf()(l=>_=>E("Just",(()=>{const h=tt(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;c()})()))(Wd(e)(t)(n)(r)(i)(o)(u)(d)(g)(a)(f))},ia=e=>t=>Dt(n=>r=>y(i=>o=>o>=0&&o<t.length?o>=0&&o<e.length?i+t[o]+e[o]:i+t[o]+0:o>=0&&o<e.length?i+1+e[o]:i+1)(0)((()=>{const i=qt(0,t.length-1|0);return n<1?[]:Gt(0,n,i)})()))(t),Bd=e=>t=>n=>r=>i=>o=>u=>{const s=Cd(0)(t.length-1|0),a=ct(e.layerGap),f=u(gf(s,a)),g=$1(Vs(i)(f)(r)(o)($))(f);return V(d=>{const l=Sd(d)(g);return l.tag==="Just"&&l._1>0?$e(a)(2+ct(l._1-1|0)*2.5):a})(qt(0,s-1|0))},ua=e=>t=>n=>r=>Cu(i=>y(o=>u=>{if(!o.ok)return o;const s=tt(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})(),f=tt(u)(n),g=(()=>{if(f.tag==="Nothing")return a+1;if(f.tag==="Just")return a+f._1._1;c()})();return a+1e-4>o.pos&&g+1e-4>o.pos?{ok:!0,pos:g}:{ok:!1,pos:o.pos}})({ok:!0,pos:-1e18})(i).ok,t),$d=e=>t=>n=>r=>{const i=vt(o=>u=>lt.compare(o.w)(u.w))(V(o=>({l:o,w:oa(o)}))(at(ua()(t)(n),r)));return 0<i.length?E("Just",i[0].l):T},Qd=e=>t=>{const n=Se(Te(V(Dt(i=>o=>x(o,i)))(e))),r=i=>vt(o=>u=>ot.compare((()=>{const s=tt(o)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})())((()=>{const s=tt(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(i);return{preds:(()=>{const i=o=>{if(o.tag==="Leaf")return $;if(o.tag==="Node")return Ft("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));c()};return i(y(o=>u=>Tt(k)(se)(u.to.node)([u.from.node])(o))($)(t))})(),succs:(()=>{const i=o=>{if(o.tag==="Leaf")return $;if(o.tag==="Node")return Ft("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));c()};return i(y(o=>u=>Tt(k)(se)(u.from.node)([u.to.node])(o))($)(t))})(),nodeIndex:n}},qd=e=>t=>{const n=vt(d=>l=>lt.compare(d.w)(l.w))(Dt(d=>l=>({i:d,l,w:oa(l)}))(t)),r=0<n.length?E("Just",n[0]):T,i=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;c()})(),o=i>=0&&i<t.length?E("Just",t[i]):T,u=(()=>{if(o.tag==="Just")return(d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const N=_,J=h;if(J.tag==="Nil"){p=!1,m=N;continue}if(J.tag==="Cons"){_=Le(N)(J._1),h=J._2;continue}c()}return m})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,zt("Cons",l._4,d(l._6,_)));c()};return d(o._1,Qt)})());if(o.tag==="Nothing")return 0;c()})(),s=d=>y(l=>_=>$e(l)((()=>{const h=tt(_._1)(e);if(h.tag==="Nothing")return _._2+1;if(h.tag==="Just")return _._2+h._1._1;c()})()))(-999999)(kr(d)),a=i>=0&&i<t.length?E("Just",t[i]):T,f=(()=>{if(a.tag==="Just")return s(a._1);if(a.tag==="Nothing")return 0;c()})(),g=ye(d=>l=>{const _=h=>{if(h.tag==="Leaf")return $;if(h.tag==="Node")return Ft("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));c()};return _(d)},t,Dt(d=>l=>Oo(d)(2)===0?u-(_=>h=>{let p=_,m=h,N=!0,J;for(;N;){const v=p,w=m;if(w.tag==="Nil"){N=!1,J=v;continue}if(w.tag==="Cons"){p=Le(v)(w._1),m=w._2;continue}c()}return J})(999999)((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,zt("Cons",h._4,_(h._6,p)));c()};return _(l,Qt)})()):f-s(l))(t));return Dd(y(d=>l=>{const _=vt(lt.compare)(Pt(tt(l))(g));return Z(k)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})($)(Mn(k.compare)(Te(V(d=>{const l=_=>{if(_.tag==="Leaf")return $;if(_.tag==="Node")return Ft("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));c()};return bt(ke.foldr,l(d))})(g)))))},Hd=e=>t=>n=>r=>i=>o=>{const u=Qd(t)(i),s=Gd(u)(t),a={nodeGap:e.nodeGap*4|0},f=Ne(k.compare,me,Se(V(_=>x(_,x(0,1)))(at(_=>ie(3)(_)==="$d:",Te(t)))),(()=>{const _=h=>{if(h.tag==="Leaf")return $;if(h.tag==="Node")return Ft("Node",h._1,h._2,h._3,x(h._4._1*ct(4),h._4._2),_(h._5),_(h._6));c()};return _(n)})()),g=[lo(a)(u)(t)(f)(r)(i)(o)(s)(ta)(na),lo(a)(u)(t)(f)(r)(i)(o)(s)(ea)(na),lo(a)(u)(t)(f)(r)(i)(o)(s)(ta)(ra),lo(a)(u)(t)(f)(r)(i)(o)(s)(ea)(ra)],d=qd(f)(g);if(ua()(t)(f)(d))return d;const l=$d()(t)(f)(g);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return g[0];c()},Yd=e=>t=>n=>r=>{const i=_f(T,Gc,o=>o.node===t?E("Just",o.position):T,e);if(i.tag==="Nothing")return e;if(i.tag==="Just"){const o=i._1;return V(u=>u.node===n?{...u,position:x(o._1+r._1,o._2+r._2)}:u)(e)}c()},Vd=e=>t=>n=>r=>{const i=at(u=>Be(Fe)(u.node)(t),e),o=(()=>{if(n==="Vertical"){if(r==="Start")return y(u=>s=>Le(u)(s.position._1))(99999)(i);if(r==="End")return y(u=>s=>$e(u)(s.position._1))(0)(i);if(r==="Center"){const u=y(s=>a=>s+a.position._1)(0)(i);return i.length===0?0:u/ct(i.length)}c()}if(n==="Horizontal"){if(r==="Start")return y(u=>s=>Le(u)(s.position._2))(99999)(i);if(r==="End")return y(u=>s=>$e(u)(s.position._2))(0)(i);if(r==="Center"){const u=y(s=>a=>s+a.position._2)(0)(i);return i.length===0?0:u/ct(i.length)}}c()})();return V(u=>{if(Be(Fe)(u.node)(t)){if(n==="Vertical")return{...u,position:x(o,u.position._2)};if(n==="Horizontal")return{...u,position:x(u.position._1,o)};c()}return u})(e)},Od=e=>t=>y(n=>r=>{if(r.tag==="Lock"){const i=r._1.node,o=r._1.position;return V(u=>u.node===i?{...u,position:o}:u)(n)}return r.tag==="AlignGroup"?Vd(n)(V(Lu)(r._1.nodes))(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?Yd(n)(r._1.anchor)(r._1.target)(r._1.offset):n})(t)(e),Fd=e=>t=>n=>r=>i=>o=>u=>s=>{const a=Se(V(_=>x(_._1,_._2))(kr(r))),f=V(V(Lu))(n),g=V(_=>y(h=>p=>$e(h)((()=>{const m=tt(p)(a);if(m.tag==="Nothing")return 1;if(m.tag==="Just")return m._1._2;c()})()))(1)(_))(f),d=Hd(e)(f)(a)(Se(V(_=>x(_._1,_._2))(kr(i))))(o)(s),l=ia(Bd(e)(n)(r)(i)(o)(u)(_=>{const h=ia(_)(g);return Te(Dt(p=>m=>Dt(N=>J=>({node:J,position:x((()=>{const v=tt(J)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;c()})()/ct(4)})(),p>=0&&p<h.length?h[p]:0),size:(()=>{const v=ie(3)(J)==="$d:"?x(0,1):x(1,1),w=tt(J)(a);if(w.tag==="Nothing")return v;if(w.tag==="Just")return w._1;c()})(),layer:p,order:N}))(m))(f))}))(g);return Od(t)(Te(Dt(_=>h=>Dt(p=>m=>({node:m,position:x((()=>{const N=tt(m)(d);return(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})()/ct(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const N=ie(3)(m)==="$d:"?x(0,1):x(1,1),J=tt(m)(a);if(J.tag==="Nothing")return N;if(J.tag==="Just")return J._1;c()})(),layer:_,order:p}))(h))(f)))},Qi=li(Zr)(Nn(32)),sa=li(Zr)(Nn(31)),Er=(()=>{const e=Pg("25214903917");if(e.tag==="Nothing")return Zu;if(e.tag==="Just")return e._1;c()})(),Cr=di(li(Zr)(Nn(48)))(Zr),Xd=e=>{const t=Rg(e);return yr(ju((()=>{if(t.tag==="Nothing")return Zu;if(t.tag==="Just")return t._1;c()})())(Er))(Cr)},qi=Nn(11),ho=e=>t=>{const n=yr(Ur(Kr(t)(Er))(qi))(Cr);return x((()=>{const r=Wu(Lg(hi(n)(Nn(48-e|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;c()})(),n)},Ud=e=>{const t=ho(26)(e),n=ho(27)(t._2);return x((ct(t._1)*Yo(2)(27)+ct(n._1))/Yo(2)(53),n._2)},Kd=e=>t=>{const n=y(r=>i=>{const o=Ud(r.finalR);return{rs:[...r.rs,o._1],finalR:o._2}})({rs:[],finalR:e})(t);return x(V(r=>r.x)(vt(r=>i=>lt.compare(r.k)(i.k))(ye(r=>i=>({x:r,k:i}),t,n.rs))),n.finalR)},Zd=e=>{const t=yr(Ur(Kr(e)(Er))(qi))(Cr),n=yr(Ur(Kr(t)(Er))(qi))(Cr);return x(Ur(Kr((()=>{const r=hi(t)(Nn(16));return ts.compare(r)(sa)!=="LT"?di(r)(Qi):r})())(Qi))((()=>{const r=hi(n)(Nn(16));return ts.compare(r)(sa)!=="LT"?di(r)(Qi):r})()),n)},Sr=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},po=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Hi=te(k)(At),Qe=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},mo=te(k)(At),jd=nf($o),tl=y(cr)(0),el=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},aa=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},nl=e=>t=>n=>r=>i=>Hi(y(o=>u=>{const s=vt(a=>f=>ot.compare((()=>{const g=Sr(a.id)(i);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;c()})())((()=>{const g=Sr(f.id)(i);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;c()})()))(at(a=>po(a.to.node)(n),at(a=>a.from.node===u,r)));return{ranks:[...o.ranks,...Dt(a=>f=>x(f.id,ct((o.rankSum+a|0)+1|0)))(s)],rankSum:o.rankSum+s.length|0}})({ranks:[],rankSum:0})(e).ranks),rl=e=>t=>n=>r=>i=>Hi(y(o=>u=>{const s=vt(f=>g=>{const d=ot.compare((()=>{const l=Qe(g.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Qe(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})());return d==="EQ"?ot.compare((()=>{const l=Sr(f.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Sr(g.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})()):d})(at(f=>po(f.from.node)(n),at(f=>f.to.node===u,r))),a=s.length;return{ranks:[...o.ranks,...Dt(f=>g=>x(g.id,ct((o.rankSum+a|0)-f|0)))(s)],rankSum:o.rankSum+a|0}})({ranks:[],rankSum:0})(e).ranks),Yi=e=>t=>n=>{const r=mo(Dt(s=>a=>x(a,s))(e)),i=mo(Dt(s=>a=>x(a,s))(t)),o=Pt(s=>{const a=Qe(s.from.node)(r),f=Qe(s.to.node)(i);if(a.tag==="Just"&&f.tag==="Just")return E("Just",x(a._1,f._1));const g=Qe(s.from.node)(i),d=Qe(s.to.node)(r);return g.tag==="Just"&&d.tag==="Just"?E("Just",x(d._1,g._1)):T})(n),u=o.length;return y(s=>a=>y(f=>g=>a>=0&&a<o.length&&g>=0&&g<o.length&&((o[a]._1-o[g]._1|0)*(o[a]._2-o[g]._2|0)|0)<0?f+1|0:f)(s)(qt(a+1|0,u-1|0)))(0)(qt(0,u-2|0))},ol=e=>t=>n=>r=>i=>{const o=u=>s=>{let a=u,f=s,g=!0,d;for(;g;){const l=a,_=f;if(_>=(l.length-1|0)){g=!1,d=l;continue}const h=_>=0&&_<l.length?E("Just",l[_]):T,p=_+1|0;if(p>=0&&p<l.length&&h.tag==="Just"){const m=h._1,N=l[p];if(sn(L=>L.before===m&&L.after===N,i)){a=l,f=_+1|0;continue}if((()=>{const L=Qe(m)(e),b=Qe(N)(e);return L.tag==="Just"&&b.tag==="Just"&&L._1<b._1})()){a=l,f=_+1|0;continue}const J=Gn(Xt,T,_,N,l),v=(()=>{if(J.tag==="Just")return Gn(Xt,T,_+1|0,m,J._1);if(J.tag==="Nothing")return T;c()})(),w=(()=>{if(v.tag==="Nothing")return l;if(v.tag==="Just")return v._1;c()})();if(Yi(n)(w)(r)<Yi(n)(l)(r)){a=w,f=_+1|0;continue}a=l,f=_+1|0;continue}g=!1,d=l}return d};return(u=>{let s=u,a=!0,f;for(;a;){const g=s,d=o(g)(0);if(jd(d)(g)){a=!1,f=g;continue}s=d}return f})(t)},yo=e=>t=>y(n=>r=>{if(r>=0&&r<e.length){const i=e[r],o=r+1|0;if(o>=0&&o<e.length)return n+Yi(i)(e[o])(t)|0}return n})(0)(qt(0,e.length-2|0)),il=e=>t=>n=>{const r=Pt(f=>f.tag==="OrderConstraint"?E("Just",{before:f._1.before,after:f._1.after}):T)(e.constraints),i=f=>y(g=>d=>{const l=d.after,_=d.before,h=Dn(Xt,T,m=>m===_,g),p=Dn(Xt,T,m=>m===l,g);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=Eu(Xt,T,h._1,g),N=(()=>{if(m.tag==="Nothing")return g;if(m.tag==="Just")return m._1;c()})(),J=lf(Xt,T,p._1,_,N);if(J.tag==="Nothing")return N;if(J.tag==="Just")return J._1;c()}return g})(f)(r),o=Hi(Dt(f=>g=>x(g.id,f))(n)),u=(f,g,d)=>{const l=f.length;return y(_=>h=>{const p=g?h-1|0:h+1|0,m=p>=0&&p<_._1.length?E("Just",_._1[p]):T;if(m.tag==="Just"){const N=h>=0&&h<_._1.length?E("Just",_._1[h]):T;if(N.tag==="Just"){const J=mo(Dt(S=>A=>x(A,S))(m._1)),v=mo(Dt(S=>A=>x(A,S))(N._1)),w=g?nl(m._1)(J)(v)(n)(o):rl(m._1)(J)(v)(n)(o),L=y(S=>A=>{const O=Pt(R=>Sr(R.id)(w))(at(g?R=>R.to.node===A._2&&po(R.from.node)(J):R=>R.from.node===A._2&&po(R.to.node)(J),n));if(O.length===0)return{...S,items:[...S.items,{n:A._2,key:T,origIdx:A._1}]};const j=ho(24)(S.r);return{items:[...S.items,{n:A._2,key:E("Just",(tl(O)+(ct(j._1)*4172325152040912e-24-.03500000014901161))/ct(O.length)),origIdx:A._1}],r:j._2}})({items:[],r:_._2})(Dt(In)(N._1)),b=Gn(Xt,T,h,ol(e.modelOrder)(i(V(S=>S.n)(vt(S=>A=>{const O=Qe(S.n)(e.modelOrder),j=Qe(A.n)(e.modelOrder);if(O.tag==="Just"&&j.tag==="Just"){const R=ot.compare(O._1)(j._1);return R==="EQ"?lt.compare(S.key)(A.key):R}return lt.compare(S.key)(A.key)})((()=>{const S=L.items,A=O=>j=>{let R=O,P=j,et=!0,K;for(;et;){const B=R,q=P;if(B>=0&&B<S.length){if(S[B].key.tag==="Just"){et=!1,K=S[B].key._1;continue}if(S[B].key.tag==="Nothing"){R=B+1|0,P=q;continue}c()}et=!1,K=q}return K};return(O=>j=>R=>{let P=O,et=j,K=R,B=!0,q;for(;B;){const M=P,C=et,I=K;if(M>=0&&M<S.length){if(S[M].key.tag==="Just"){P=M+1|0,et=S[M].key._1,K=[...I,{n:S[M].n,key:S[M].key._1,origIdx:S[M].origIdx}];continue}if(S[M].key.tag==="Nothing"){const D=(C+A(M+1|0)(C+1))/2;P=M+1|0,et=D,K=[...I,{n:S[M].n,key:D,origIdx:S[M].origIdx}];continue}c()}B=!1,q=I}return q})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(b.tag==="Just")return x(b._1,L.r);if(b.tag==="Nothing")return x(_._1,_._2);c()}if(N.tag==="Nothing")return x(_._1,_._2);c()}if(m.tag==="Nothing")return x(_._1,_._2);c()})(x(f,d))(g?qt(1,l-1|0):le(qt(0,l-2|0)))},s=y(f=>g=>Z(k)(g.from.node)()(Z(k)(g.to.node)()(f)))($)(n),a=y(f=>g=>{if(f.result.crossings===0)return f;const d=J=>v=>w=>L=>{let b=J,S=v,A=w,O=L,j=!0,R;for(;j;){const P=b,et=S,K=A,B=O;if(K===0){j=!1,R={layout:P,crossings:0,random:B};continue}const q=u(P,et,B),M=yo(q._1)(n);if(M<K){b=q._1,S=!et,A=M,O=q._2;continue}j=!1,R={layout:P,crossings:K,random:q._2}}return R},l=ho(1)(f.result.random),_=l._1!==0,h=e.modelOrder.tag==="Leaf",p=(f.firstTry||f.secondTry)&&!h?f.firstTry:_,m=(()=>{if(!h){const L=u(t,p,l._2);return d(L._1)(!p)(yo(L._1)(n))(L._2)}const J=p?0:el(0)(t.length-1|0),v=J>=0&&J<t.length?E("Just",t[J]):T;if(v.tag==="Just"&&v._1.length>1){const L=at(b=>aa(b)(s),v._1);if(L.length>1){const b=Kd(l._2)(L),S=b._1,A=Gn(Xt,T,J,i(y(O=>j=>aa(j)(s)?O.idx>=0&&O.idx<S.length?{idx:O.idx+1|0,result:[...O.result,S[O.idx]]}:{idx:O.idx,result:[...O.result,j]}:{idx:O.idx,result:[...O.result,j]})({idx:0,result:[]})(v._1).result),t);if(A.tag==="Just"){const O=u(A._1,p,b._2);return d(O._1)(!p)(yo(O._1)(n))(O._2)}}}const w=u(t,p,l._2);return d(w._1)(!p)(yo(w._1)(n))(w._2)})(),N=f.secondTry?!1:f.secondTry;return f.firstTry?{result:m.crossings<f.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...f.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<f.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...f.result,random:m.random},firstTry:f.firstTry,secondTry:N}})({result:{layout:t,crossings:1e9,random:yr(ju(Zd(Xd(1))._1)(Er))(Cr)},firstTry:e.modelOrder.tag!=="Leaf",secondTry:!1})(qt(1,e.iterations)).result;return t.length<=0||e.iterations<=0?t:a.layout},ul=e=>e,ca=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},pe=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Xn=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Pr=(()=>{const e={eq:t=>n=>t._1===n._1&&t._2===n._2};return{compare:t=>n=>{const r=k.compare(t._1)(n._1);return r==="LT"?Ae:r==="GT"?ze:k.compare(t._2)(n._2)},Eq0:()=>e}})(),sl=te(k)(At),al=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=Pr.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},cl=ul("Greedy"),Vi=e=>t=>n=>y(r=>i=>{if(i.from.node===i.to.node)return r;if(i.from.node===t&&!ca(i.to.node)(r.marks)){const o=pe(i.to.node)(r.inDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;c()})(),s=Z(k)(i.to.node)(u)(r.inDeg);return(()=>{const a=pe(i.to.node)(r.outDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;c()})()&&!Be(Fe)(i.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,i.to.node]}:{...r,inDeg:s}}if(i.to.node===t&&!ca(i.from.node)(r.marks)){const o=pe(i.from.node)(r.outDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;c()})(),s=Z(k)(i.from.node)(u)(r.outDeg);return(()=>{const a=pe(i.from.node)(r.inDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;c()})()&&!Be(Fe)(i.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,i.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:at(r=>r!==t,n.remaining)})(e),fl=y(e=>t=>{if(t.tag==="LayerConstraint"){if(t._1.pin.tag==="SpecificLayer")return Z(k)(t._1.node)(t._1.pin._1)(e);if(t._1.pin.tag==="FirstLayer")return Z(k)(t._1.node)(0)(e);if(t._1.pin.tag==="LastLayer")return Z(k)(t._1.node)(99999)(e)}return e})($),fa=e=>t=>n=>{const r=pe(t)(e),i=pe(n)(e);return r.tag==="Just"&&i.tag==="Just"&&r._1>i._1},ga=e=>t=>n=>r=>{if(Xn(n)(r.visited)||Xn(n)(r.visiting))return r;const i=y(gl(e)(t)(n))({...r,visiting:Z(k)(n)()(r.visiting)})((()=>{const o=pe(n)(t);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;c()})());return{...i,visiting:ar(k)(n)(i.visiting),visited:Z(k)(n)()(i.visited)}},gl=e=>t=>n=>r=>i=>fa(e)(n)(i)?{...r,backEdges:Z(Pr)(x(n,i))()(r.backEdges)}:Xn(i)(r.visiting)?{...r,backEdges:Z(Pr)(x(n,i))()(r.backEdges)}:Xn(i)(r.visited)?r:ga(e)(t)(i)(r),_l=e=>t=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,N=Ht(J=>T,J=>v=>E("Just",{head:J,tail:v}),m.sinks);if(N.tag==="Just"){_=Vi(n)(N._1.head)({...m,sinks:N._1.tail,marks:Z(k)(N._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(N.tag==="Nothing"){const J=Ht(v=>T,v=>w=>E("Just",{head:v,tail:w}),m.sources);if(J.tag==="Just"){_=Vi(n)(J._1.head)({...m,sources:J._1.tail,marks:Z(k)(J._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(J.tag==="Nothing"){const v=L=>{const b=pe(L)(m.outDeg),S=pe(L)(m.inDeg);return(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;c()})()-(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;c()})()|0},w=vt(L=>b=>{const S=ot.compare(v(b))(v(L));return S==="EQ"?ot.compare((()=>{const A=pe(L)(t);if(A.tag==="Nothing")return 1e6;if(A.tag==="Just")return A._1;c()})())((()=>{const A=pe(b)(t);if(A.tag==="Nothing")return 1e6;if(A.tag==="Just")return A._1;c()})()):S})(m.remaining);if(0<w.length){const L=w[0];_=Vi(n)(L)({...m,remaining:at(b=>b!==L,m.remaining),marks:Z(k)(L)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}c()}return p},i=Mn(k.compare)([...V(l=>l.from.node)(n),...V(l=>l.to.node)(n)]),o=at(l=>l.from.node!==l.to.node,n),u=y(l=>_=>Tt(k)(Zt)(_.to.node)(1)(l))($)(o),s=y(l=>_=>Tt(k)(Zt)(_.from.node)(1)(l))($)(o),a=at(l=>{const _=pe(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;c()},i),f=at(l=>{const _=pe(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;c()},i),g=i.length+1|0,d=y(l=>_=>{const h=pe(_)(l);return h.tag==="Just"&&h._1<0?Z(k)(_)(h._1+g|0)(l):l})(r({remaining:at(l=>!Be(Fe)(l)(a)&&!Be(Fe)(l)(f),i),marks:$,inDeg:u,outDeg:s,sources:a,sinks:f,nextLeft:1,nextRight:-1}).marks)(i);return y(l=>_=>{if(_.from.node===_.to.node)return l;if(fa(e)(_.from.node)(_.to.node))return Z(Pr)(x(_.from.node,_.to.node))()(l);const h=pe(_.from.node)(d),p=pe(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?Z(Pr)(x(_.from.node,_.to.node))()(l):l})($)(n)},dl=y(e=>t=>Tt(k)(se)(t.from.node)([t.to.node])(e))($),ll=e=>t=>{const n=dl(t),r=Mn(k.compare)([...V(o=>o.from.node)(t),...V(o=>o.to.node)(t)]),i=y(o=>u=>Z(k)(u.to.node)()(o))($)(t);return y(o=>u=>ga(e)(n)(u)(o))({visiting:$,visited:$,backEdges:$})([...at(o=>!Xn(o)(i),r),...at(o=>Xn(o)(i),r)]).backEdges},hl=e=>t=>n=>r=>{const i=sl(Dt(s=>a=>x(a,s))(t)),o=fl(n),u=(()=>{if(e==="DepthFirst")return ll(o)(r);if(e==="Greedy")return _l(o)(i)(r);c()})();return{edges:V(s=>al(x(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},_a=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},pl=e=>t=>n=>y(r=>i=>{const o=_a(i.from.node)(e),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;c()})(),s=_a(i.to.node)(e),a=(()=>{if(s.tag==="Nothing")return-u;if(s.tag==="Just")return s._1-u|0;c()})();if(a<=1)return{...r,edges:[...r.edges,i],chains:[...r.chains,{edgeId:i.id,nodes:[i.from.node,i.to.node]}]};const f=i.id,g=V(l=>"$d:"+f+":"+ue(l))(qt(1,a-1|0)),d=[i.from.node,...g,i.to.node];return{...r,layers:y(l=>_=>{const h=_._2,p=yf(u+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;c()})(r.layers)(ye(In,qt(1,a-1|0),g)),edges:[...r.edges,...ye(l=>_=>({id:f+":"+l+"->"+_,from:{node:l,port:i.from.port},to:{node:_,port:i.to.port}}),d,Gt(1,d.length,d))],chains:[...r.chains,{edgeId:i.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(t),Oi=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},fe=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Vt=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Rr=e=>t=>{const n=ot.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},bn=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=ot.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Jo=te(k)(At),Un=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=ot.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},ml=(()=>{const e={eq:n=>r=>n.delta===r.delta&&n.eid===r.eid&&n.src===r.src&&n.tgt===r.tgt&&n.weight===r.weight},t={compare:n=>r=>{const i=ot.compare(n.delta)(r.delta);if(i==="LT"||i==="GT"||i!=="EQ")return i;const o=ot.compare(n.eid)(r.eid);if(o==="LT"||o==="GT"||o!=="EQ")return o;const u=k.compare(n.src)(r.src);if(u==="LT"||u==="GT"||u!=="EQ")return u;const s=k.compare(n.tgt)(r.tgt);if(s==="LT"||s==="GT"||s!=="EQ")return s;const a=ot.compare(n.weight)(r.weight);return a==="LT"||a==="GT"||a!=="EQ"?a:Oe},Eq0:()=>e};return y(n=>r=>Z(t)(r)()(n))($)})(),yl=y(e=>t=>Z(k)(t)()(e))($),Jl=te(ot)(At),Nl=e=>t=>Ne(k.compare,me,e,t),xl=e=>y(t=>n=>({base:(()=>{const r=i=>o=>{let u=i,s=o,a=!0,f;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,f=g;continue}if(d.tag==="Cons"){u=Oi(g)(d._1),s=d._2;continue}c()}return f};return(t.base+r(0)((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,zt("Cons",o._4,i(o._6,u)));c()};return i(n,Qt)})())|0)+1|0})(),result:[...t.result,(()=>{if(t.base===0)return n;const r=i=>{if(i.tag==="Leaf")return $;if(i.tag==="Node")return Ft("Node",i._1,i._2,i._3,i._4+t.base|0,r(i._5),r(i._6));c()};return r(n)})()]}))({base:0,result:[]})(e).result,vl=e=>t=>{const n=o=>{let u=o,s=!0,a;for(;s;){const f=u,g=Ht(d=>T,d=>l=>E("Just",{head:d,tail:l}),f.queue);if(g.tag==="Nothing"){s=!1,a=f;continue}if(g.tag==="Just"){if(fe(g._1.head)(f.removedNodes)){u={...f,queue:g._1.tail};continue}const d=ge(l=>!fe(l.src+"\u2192"+l.tgt)(f.removedEdges)&&(l.src===g._1.head||l.tgt===g._1.head))(t);if(d.tag==="Nothing"){u={...f,queue:g._1.tail};continue}if(d.tag==="Just"){const l=d._1.src===g._1.head?d._1.tgt:d._1.src,_={...f,degree:Z(k)(l)((()=>{const h=Vt(l)(f.degree);if(h.tag==="Nothing")return-1;if(h.tag==="Just")return h._1-1|0;c()})())(f.degree),removedNodes:Z(k)(g._1.head)()(f.removedNodes),removedEdges:Z(k)(d._1.src+"\u2192"+d._1.tgt)()(f.removedEdges),record:[...f.record,{node:g._1.head,neighbour:l,viaSrc:d._1.src===g._1.head}],queue:g._1.tail};if((()=>{const h=Vt(l)(_.degree);return(()=>{if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1===1;c()})()&&!fe(l)(_.removedNodes)})()){u={..._,queue:[..._.queue,l]};continue}u=_;continue}}c()}return a},r=y(o=>u=>Tt(k)(Zt)(u.src)(1)(Tt(k)(Zt)(u.tgt)(1)(o)))($)(t),i=n({degree:r,removedNodes:$,removedEdges:$,record:[],queue:at(o=>{const u=Vt(o)(r);if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1===1;c()},e)});return{coreNodes:at(o=>!fe(o)(i.removedNodes),e),coreEdges:at(o=>!fe(o.src+"\u2192"+o.tgt)(i.removedEdges),t),removed:i.record}},Tl=e=>t=>y(n=>r=>{const i=Vt(r.neighbour)(n),o=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;c()})();return Z(k)(r.node)(r.viaSrc?o-1|0:o+1|0)(n)})(t)(le(e)),da=e=>t=>n=>{const r=y(o=>u=>{const s=da(e)(u.src===t?u.tgt:u.src)({...o.st,edgeVisited:Z(ot)(u.eid)()(o.st.edgeVisited)});return{lowest:Rr(o.lowest)(s.lowest),st:s.st}})({lowest:1e9,st:n})(at(o=>bn(o.eid)(n.treeEdge)&&(o.src===t||o.tgt===t)&&!bn(o.eid)(n.edgeVisited),e)),i=Rr(r.lowest)(r.st.postOrder);return{lowest:i,st:{...r.st,poID:Z(k)(t)(r.st.postOrder)(r.st.poID),lowestPoID:Z(k)(t)(i)(r.st.lowestPoID),postOrder:r.st.postOrder+1|0}}},la=e=>t=>n=>da(t)(0<e.length?e[0]:"")({...n,edgeVisited:$,postOrder:1,poID:$,lowestPoID:$}).st,ha=e=>t=>{const n=y(r=>i=>Rr(r)((()=>{const o=Vt(i)(t);if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;c()})()))(1e9)(e);return Jo(V(r=>x(r,(()=>{const i=Vt(r)(t);if(i.tag==="Nothing")return-n;if(i.tag==="Just")return i._1-n|0;c()})()))(e))},Fi=e=>t=>{const n=Vt(t)(e.poID);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;c()},pa=e=>t=>{const n=Vt(t)(e.lowestPoID);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;c()},wl=e=>t=>ge(n=>{const r=Un(n.eid)(t.cutvalue);return bn(n.eid)(t.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<0;c()})()})(e),we=e=>t=>{const n=Vt(t)(e.layer);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;c()},bl=e=>t=>y(n=>r=>{if(fe(r.src)(t.treeNode)===fe(r.tgt)(t.treeNode))return n;const i=(we(t)(r.tgt)-we(t)(r.src)|0)-r.delta|0;return i<n.slack?{edge:E("Just",r),slack:i}:n})({edge:T,slack:1e9})(e).edge,Xi=e=>t=>n=>{const r={...n,treeNode:Z(k)(t)()(n.treeNode)};return y(i=>o=>{if(bn(o.eid)(i.st.edgeVisited))return i;const u={...i.st,edgeVisited:Z(ot)(o.eid)()(i.st.edgeVisited)},s=(fe(o.src)(u.treeNode)&&!fe(o.tgt)(u.treeNode)?o.src===o.src:fe(o.tgt)(u.treeNode)&&!fe(o.src)(u.treeNode)?o.src===o.tgt:o.src===o.src)?o.tgt:o.src;if(bn(o.eid)(u.treeEdge)){if(fe(s)(u.treeNode))return{...i,st:u};const a=Xi(e)(s)(u);return{count:i.count+a.count|0,st:a.st}}if(!fe(s)(u.treeNode)&&o.delta===(we(u)(o.tgt)-we(u)(o.src)|0)){const a=Xi(e)(s)({...u,treeEdge:Z(ot)(o.eid)()(u.treeEdge)});return{count:i.count+a.count|0,st:a.st}}return{...i,st:u}})({count:1,st:r})(at(i=>(i.src===t||i.tgt===t)&&!bn(i.eid)(r.edgeVisited),e))},No=e=>t=>n=>{const r=Fi(e)(n.src),i=Fi(e)(n.tgt),o=Fi(e)(t);return pa(e)(n.src)<=o&&o<=r&&pa(e)(n.tgt)<=o&&o<=i?r>=i:r<i},kl=e=>t=>({layer:Jo(V(n=>x(n,0))(e)),treeNode:$,treeEdge:$,poID:$,lowestPoID:$,cutvalue:$,postOrder:1,edgeVisited:$}),Ll=e=>t=>n=>at(r=>bn(r.eid)(t.treeEdge)&&(r.src===n||r.tgt===n),e),El=e=>t=>n=>{let r=e,i=t,o=n,u=!0,s;for(;u;){const a=r,f=i,g=o,d=Xi(f)(0<a.length?a[0]:"")({...g,edgeVisited:$,treeNode:$,treeEdge:$});if(d.count>=a.length){u=!1,s=d.st;continue}const l=bl(f)(d.st);if(l.tag==="Nothing"){u=!1,s=d.st;continue}if(l.tag==="Just"){const _=(we(d.st)(l._1.tgt)-we(d.st)(l._1.src)|0)-l._1.delta|0,h=fe(l._1.tgt)(d.st.treeNode)?-_:_;r=a,i=f,o={...d.st,layer:y(p=>m=>fe(m)(d.st.treeNode)?Z(k)(m)(we(d.st)(m)+h|0)(p):p)(d.st.layer)(a)};continue}c()}return s},Cl=e=>t=>n=>y(r=>i=>{if(No(n)(i.src)(t)&&!No(n)(i.tgt)(t)){const o=(we(n)(i.tgt)-we(n)(i.src)|0)-i.delta|0;if(o<r.slack)return{edge:E("Just",i),slack:o}}return r})({edge:T,slack:1e9})(e).edge,Sl=e=>t=>{const n=y(i=>o=>Tt(k)(se)(o.tgt)([o.src])(Tt(k)(se)(o.src)([o.tgt])(i)))($)(t),r=i=>o=>u=>{let s=i,a=o,f=u,g=!0,d;for(;g;){const l=s,_=a,h=f,p=Ht(m=>T,m=>N=>E("Just",{head:m,tail:N}),l);if(p.tag==="Nothing"){g=!1,d={nodes:h};continue}if(p.tag==="Just"){if(fe(p._1.head)(_)){s=p._1.tail,a=_,f=h;continue}s=[...p._1.tail,...(()=>{const m=Vt(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;c()})()],a=Z(k)(p._1.head)()(_),f=[...h,p._1.head];continue}c()}return d};return y(i=>o=>{if(fe(o)(i.visited))return i;const u=r([o])(i.visited)([]);return{...i,visited:y(s=>a=>Z(k)(a)()(s))(i.visited)(u.nodes),components:[...i.components,u.nodes]}})({visited:$,components:[]})(e).components},Pl=e=>t=>n=>r=>{const i=r.tgt,o=r.src;return y(u=>s=>{if((()=>{const a=Un(s.eid)(t.cutvalue);if(a.tag==="Just")return!0;if(a.tag==="Nothing")return!1;c()})()){const a=Un(s.eid)(t.cutvalue),f=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()})();return o===s.src||i===s.tgt?u-(f-s.weight|0)|0:u+(f-s.weight|0)|0}return n===o?s.src===n?u+s.weight|0:u-s.weight|0:s.src===n?u-s.weight|0:u+s.weight|0})(r.weight)(at(u=>u.eid!==r.eid&&(u.src===n||u.tgt===n),e))},Rl=e=>t=>n=>(r=>i=>{let o=r,u=i,s=!0,a;for(;s;){const f=o,g=u,d=Vt(g)(f.unknown),l=(()=>{if(d.tag==="Nothing")return[];if(d.tag==="Just")return d._1;c()})();if(l.length===1){const _=l[0].src===g?l[0].tgt:l[0].src;o={unknown:(()=>{const h=Vt(_)(f.unknown),p=(()=>{if(h.tag==="Just")return Z(k)(_)(at(N=>N.eid!==l[0].eid,h._1))(f.unknown);if(h.tag==="Nothing")return f.unknown;c()})(),m=Vt(g)(p);if(m.tag==="Just")return Z(k)(g)(at(N=>N.eid!==l[0].eid,m._1))(p);if(m.tag==="Nothing")return p;c()})(),cutvalue:Z(ot)(l[0].eid)(Pl(e)(f)(g)(l[0]))(f.cutvalue)},u=_;continue}s=!1,a=f}return a})(t)(n),ma=e=>t=>n=>{const r={unknown:Jo(V(i=>x(i,bt(ke.foldr,ml(Ll(t)(n)(i)))))(e)),cutvalue:$};return{...n,cutvalue:y(Rl(t))(r)(at(i=>{const o=Vt(i)(r.unknown);if(o.tag==="Nothing")return!1;if(o.tag==="Just")return o._1.length===1;c()},e)).cutvalue}},Il=e=>t=>n=>r=>i=>{const o={...i,treeEdge:Z(ot)(r.eid)()(ar(ot)(n.eid)(i.treeEdge))},u=(we(o)(r.tgt)-we(o)(r.src)|0)-r.delta|0,s=No(o)(r.tgt)(n)?-u:u;return ma(e)(t)(la(e)(t)({...o,layer:y(a=>f=>No(o)(f)(n)?a:Z(k)(f)(we(o)(f)+s|0)(a))(o.layer)(e)}))},Dl=e=>t=>n=>r=>(i=>o=>{let u=i,s=o,a=!0,f;for(;a;){const g=u,d=s;if(g===0){a=!1,f=d;continue}const l=wl(n)(d);if(l.tag==="Nothing"){a=!1,f=d;continue}if(l.tag==="Just"){const _=Cl(n)(l._1)(d);if(_.tag==="Nothing"){a=!1,f=d;continue}if(_.tag==="Just"){u=g-1|0,s=Il(t)(n)(l._1)(_._1)(d);continue}}c()}return f})(e)(r),Gl=e=>t=>n=>ma(e)(t)(la(e)(t)(El(e)(t)(n))),ya=e=>y(t=>n=>Tt(k)(se)(e(n))([n])(t))($),Ml=e=>t=>n=>{const r=u=>s=>a=>f=>{let g=u,d=s,l=a,_=f,h=!0,p;for(;h;){const m=g,N=d,J=l,v=_,w=Ht(L=>T,L=>b=>E("Just",{head:L,tail:b}),J);if(w.tag==="Nothing"){h=!1,p=v;continue}if(w.tag==="Just"){const L=we(v)(w._1.head),b=y(S=>A=>{const O=Vt(A.tgt)(S.incident),j=(()=>{if(O.tag==="Nothing")return-1;if(O.tag==="Just")return O._1-1|0;c()})();return{st:{...S.st,layer:Z(k)(A.tgt)(Oi(we(S.st)(A.tgt))(L+A.delta|0))(S.st.layer)},incident:Z(k)(A.tgt)(j)(S.incident),queue:j===0?[...S.queue,A.tgt]:S.queue}})({st:v,incident:N,queue:w._1.tail})((()=>{const S=Vt(w._1.head)(m);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;c()})());g=m,d=b.incident,l=b.queue,_=b.st;continue}c()}return p},i=ya(u=>u.tgt)(t),o=Jo(V(u=>x(u,(()=>{const s=Vt(u)(i);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.length;c()})()))(e));return r(ya(u=>u.src)(t))(o)(at(u=>{const s=Vt(u)(o);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;c()},e))(n)},Ja=e=>t=>{const n=Dt(i=>o=>({src:o.src,tgt:o.tgt,delta:1,weight:1,eid:i}))(t),r=Ml(e)(n)(kl(e)(n));return n.length===0?r.layer:Dl(4*e.length|0)(e)(n)(Gl(e)(n)(r)).layer},Wl=e=>t=>{const n=yl(e),r=at(o=>fe(o.src)(n)&&fe(o.tgt)(n),t);if(e.length<40)return ha(e)(Ja(e)(r));const i=vl(e)(r);return ha(e)(Tl(i.removed)(Ja(i.coreNodes)(i.coreEdges)))},Al=e=>t=>n=>{const r=y(o=>u=>Tt(k)(Zt)(u.tgt)(1)(o))($)(t),i=y(o=>u=>Tt(k)(Zt)(u.src)(1)(o))($)(t);return y(o=>u=>{const s=Vt(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})();if((()=>{const J=Vt(u)(i);return(()=>{if(J.tag==="Nothing")return a!==0;if(J.tag==="Just")return a!==J._1;c()})()||a===0})())return o;const f=Vt(u)(o.layers),g=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;c()})(),d=o.layers,l=y(J=>v=>v.tgt===u?{...J,mIn:Rr(J.mIn)((()=>{const w=Vt(u)(d),L=Vt(v.src)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})()-(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;c()})()|0})())}:v.src===u?{...J,mOut:Rr(J.mOut)((()=>{const w=Vt(v.tgt)(d),L=Vt(u)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})()-(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;c()})()|0})())}:J)({mIn:1e9,mOut:1e9})(t),_=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(_<0||h<0)return o;const p=(g-_|0)+1|0,m=(g+h|0)-1|0;if(m<p)return o;const N=y(J=>v=>{const w=Un(v)(o.filling),L=(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})();return L<J.bestFill?{best:v,bestFill:L}:J})({best:g,bestFill:(()=>{const J=Un(g)(o.filling);if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;c()})()})(qt(p,m));return N.best===g?o:{layers:Z(k)(u)(N.best)(o.layers),filling:Z(ot)(g)((()=>{const J=Un(g)(o.filling);if(J.tag==="Nothing")return-1;if(J.tag==="Just")return J._1-1|0;c()})())(Z(ot)(N.best)(N.bestFill+1|0)(o.filling))}})({layers:n,filling:Jl(V(o=>x(o,y(u=>s=>(()=>{const a=Vt(s)(n);return a.tag==="Nothing"?!1:a.tag==="Just"&&a._1===o})()?u+1|0:u)(0)(e)))(qt(0,y(o=>u=>Oi(o)((()=>{const s=Vt(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(0)(e))))})(e).layers},zl=e=>t=>Al(e)(Dt(n=>r=>({src:r.src,tgt:r.tgt,delta:1,weight:1,eid:n}))(t))(y(Nl)($)(xl(V(n=>Wl(n)(t))(Sl(e)(t))))),Bl=e=>e,kn=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},xo=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Na=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),$l=Bl("NetworkSimplex"),Ql=e=>t=>y(n=>r=>{const i=y(xo)(0)(Pt(o=>kn(o)(n))(r));return y(o=>u=>Z(k)(u)(i)(o))(n)(r)})(t)(e),ql=e=>t=>({layers:V(n=>at(r=>{const i=kn(r)(t);return i.tag==="Nothing"?!1:i.tag==="Just"&&i._1===n},e))(qt(0,(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,f=o;if(f.tag==="Nil"){u=!1,s=a;continue}if(f.tag==="Cons"){i=xo(a)(f._1),o=f._2;continue}c()}return s})(0)((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._4,n(r._6,i)));c()};return n(t,Qt)})()))),nodeLayer:t}),Hl=e=>t=>n=>{const r=y(i=>o=>Z(k)(o)(!0)(i))($)(t);return y(i=>o=>Z(k)(o._1)(o._2)(i))(zl(t)(Pt(i=>i.from.node===i.to.node||(()=>{const o=kn(i.from.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;c()})()||(()=>{const o=kn(i.to.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;c()})()?T:E("Just",{src:i.from.node,tgt:i.to.node}))(e)))(Na(n))},Yl=e=>t=>n=>r=>{const i=s=>a=>{const f=kn(a)(s);if(f.tag==="Just")return s;if(f.tag==="Nothing"){const g=at(l=>l!==a,(()=>{const l=kn(a)(e);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;c()})()),d=y(i)(s)(g);return Z(k)(a)(1+y(xo)(0)(Pt(l=>kn(l)(d))(g))|0)(d)}c()},o=y(i)($)(n),u=(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){f=xo(_)(h._1),g=h._2;continue}c()}return l})(1)((()=>{const s=(a,f)=>{if(a.tag==="Leaf")return f;if(a.tag==="Node")return s(a._5,zt("Cons",a._4,s(a._6,f)));c()};return s(o,Qt)})());return y(s=>a=>Z(k)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return $;if(a.tag==="Node")return Ft("Node",a._1,a._2,a._3,u-a._4|0,s(a._5),s(a._6));c()};return s(o)})())(Na(r))},Vl=y(e=>t=>{if(t.tag==="LayerConstraint"){if(t._1.pin.tag==="SpecificLayer")return Z(k)(t._1.node)(t._1.pin._1)(e);if(t._1.pin.tag==="FirstLayer")return Z(k)(t._1.node)(0)(e)}return e})($),Ol=y(e=>t=>Tt(k)(se)(t.to.node)([t.from.node])(e))($),Fl=y(e=>t=>Tt(k)(se)(t.from.node)([t.to.node])(e))($),Xl=e=>t=>n=>r=>{const i=Fl(n),o=Ol(n),u=Vl(t);return ql(r)(Ql(Pt(s=>s.tag==="SameLayer"?E("Just",s._1.nodes):T)(t))((()=>{if(e==="LongestPath")return Yl(i)(o)(r)(u);if(e==="NetworkSimplex")return Hl(n)(r)(u);c()})()))},Ul=te(k)(At),Kl=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},xa=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},va=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Ir=te(k)(At),Zl=te(k)(At),Ta=(()=>{const e=V(t=>({start:t.end,end:t.start,direction:t.direction}));return t=>le(e(t))})(),jl=e=>t=>n=>r=>{const i=Ul(V(u=>x(u.edge,u))(r)),o=u=>0<u.nodes.length&&(()=>{const s=Kl(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return V(u=>{if(u.nodes.length<=2){const g=xa(u.edgeId)(i);if(g.tag==="Just"){const d=o(u);return{...g._1,edge:u.edgeId,segments:d?Ta(g._1.segments):g._1.segments,reversed:d}}if(g.tag==="Nothing")return{edge:u.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};c()}const s=St(Pt(g=>xa(g)(i))(ye(g=>d=>u.edgeId+":"+g+"->"+d,u.nodes,Gt(1,u.nodes.length,u.nodes))))(g=>g.segments),a=o(u),f=Wi(a?Ta(s):s);return{edge:u.edgeId,segments:f,bends:ye(g=>d=>g.end,f,Gt(1,f.length,f)),bendType:[],jumps:[],reversed:a}})(e)},t0={layers:[],edges:[],chains:[]},e0={nodeGap:3,layerGap:2,iterations:8,layerer:$l,cycleBreaker:cl},n0=e=>({pos:x(0,0),size:x(y(t=>n=>va(t)(n.position._1+n.size._1))(0)(e),y(t=>n=>va(t)(n.position._2+n.size._2))(0)(e))}),r0=e=>t=>{const n=at(o=>ie(3)(o.node)!=="$d:",t.placements),r=jl(t.withDummies.chains)(t.acyclic.reversedEdges)(Zl(V(o=>x(o.id,x(o.from.node,o.to.node)))(e.edges)))(pd(t.withDummies.edges)(t.placements)(Ir(V(o=>x(o.id,o.ports))(e.nodes)))(t.withDummies.chains)(Xs(t.ordered)(at(o=>o.from.node!==o.to.node,t.withDummies.edges))((()=>{const o=u=>{if(u.tag==="Leaf")return $;if(u.tag==="Node")return Ft("Node",u._1,u._2,u._3,x(u._4._1*4,u._4._2),o(u._5),o(u._6));c()};return o(Ir(V(u=>x(u.id,u.size))(e.nodes)))})()))),i=Dt(o=>u=>({...u,jumps:Td(o)(u)(r)}))(r);return{nodes:n,edges:i,boundingBox:n0(n),metrics:W1(n)(i)(0)}},o0=e=>t=>n=>{const r=Ir(V(o=>x(o.id,o.size))(t.nodes)),i={...n,placements:Fd({nodeGap:e.nodeGap,layerGap:e.layerGap})(t.constraints)(n.ordered)(r)(Ir(V(o=>x(o.id,o.ports))(t.nodes)))(n.withDummies.edges)(n.withDummies.chains)(Xs(n.ordered)(n.withDummies.edges)((()=>{const o=u=>{if(u.tag==="Leaf")return $;if(u.tag==="Node")return Ft("Node",u._1,u._2,u._3,x(u._4._1*4,u._4._2),o(u._5),o(u._6));c()};return o(r)})()))};return{pipeline:i,result:r0(t)(i)}},i0=e=>t=>n=>o0(e)(t)({...n,ordered:il({iterations:e.iterations,constraints:t.constraints,modelOrder:Ir(Dt(r=>i=>x(i.id,r))(t.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),u0=e=>t=>n=>i0(e)(t)({...n,withDummies:pl(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),s0=e=>t=>{const n=V(i=>i.id)(t.nodes),r=hl(e.cycleBreaker)(n)(t.constraints)(t.edges);return u0(e)(t)({acyclic:r,layered:Xl(e.layerer)(t.constraints)(r.edges)(n),withDummies:t0,ordered:[],placements:[]})},a0=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},c0=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},wa=te(k)(At),f0=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},g0=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},_0=y(e=>t=>Z(k)(t)()(e))($),d0=y(e=>t=>Z(k)(t)()(e))($),l0=qr.traverse(bu),Ui=te(k)(At),h0=e=>t=>n=>{const r=ge(i=>i.id===n)(e.graph.edges);if(r.tag==="Just")return E("Just",r._1);if(r.tag==="Nothing")return a0(n)(t);c()},p0=e=>t=>n=>({x:n.position._1*e,y:n.position._2*e,w:n.size._1*e,h:n.size._2*e,label:(()=>{const r=c0(n.node)(t);if(r.tag==="Just")return r._1;if(r.tag==="Nothing")return n.node;c()})()}),m0=e=>({id:e,size:x(1,1),ports:[],label:E("Just",e)}),y0=e=>t=>n=>x(n.node,p0(e)(t)(n)),J0=e=>wa(Pt(t=>E("Just",x(t.edge,{id:t.edge,from:{node:t.from,port:T},to:{node:t.to,port:T}})))(St(e.scenes)(t=>t.tag==="DataFlow"?Pt(n=>n.kind.tag==="SendToken"?E("Just",n.kind._1):T)(t._1.events):[]))),ba=e=>{const t=Ag(e),n=at(i=>f0(i.id)(t.nodes),e.graph.nodes),r=at(i=>g0(i.id)(t.edges),e.graph.edges);return{nodes:[...n,...V(m0)(bt(ke.foldr,Xe(k.compare,t.nodes,_0(V(i=>i.id)(n)))))],edges:[...r,...Pt(h0(e)(J0(e)))(bt(ke.foldr,Xe(k.compare,t.edges,d0(V(i=>i.id)(r)))))],constraints:e.graph.constraints}},N0=e=>{const t=l0(n=>{const r=L1("Ilisarniq, ui-sans-serif, system-ui, sans-serif")(11)("500")(so((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;c()})()));return()=>{const i=r();return x(n.id,i)}})(ba(e).nodes);return()=>{const n=t();return Ui(n)}},x0=e=>t=>{const n=Ht(r=>T,r=>i=>E("Just",{head:r,tail:i}),t.segments);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{x:n._1.head.start._1*e,y:n._1.head.start._2*e},...V(r=>({x:r.end._1*e,y:r.end._2*e}))([n._1.head,...n._1.tail])];c()},v0=e=>t=>x(t.edge,x0(e)(t)),T0=e=>t=>n=>({nodes:Ui(V(y0(ct(4)*e)(t))(n.nodes)),edges:wa(V(v0(e))(n.edges)),chipExtras:$}),w0=ct(4)*8,b0=e=>t=>{const n=D1(w0)(e)(I1(R1)(ba(t)));return T0(8)(Ui(V(r=>x(r.id,(()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;c()})()))(n.nodes)))(s0(e0)(n).result)},ka=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},k0=e=>t=>n=>{const r=e<.05?e:.05,i=(u,s)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return i((()=>{const a=ka(s._3)(n),f=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return{x:s._4.x,y:s._4.y,vx:0,vy:0};c()})(),g=f.vx+(180*(s._4.x-f.x)-22*f.vx)*r,d=f.vy+(180*(s._4.y-f.y)-22*f.vy)*r;return Z(k)(s._3)({x:f.x+g*r,y:f.y+d*r,vx:g,vy:d})(i(u,s._5))})(),s._6);c()},o=i($,t);return{springs:o,applied:(()=>{const u=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return u((()=>{const f=u(s,a._5),g=ka(a._3)(o);if(g.tag==="Just")return Z(k)(a._3)({...a._4,x:g._1.x,y:g._1.y})(f);if(g.tag==="Nothing")return Z(k)(a._3)(a._4)(f);c()})(),a._6);c()};return u($,t)})()}};(function(){var e={},t="Pure",n="Throw",r="Catch",i="Sync",o="Async",u="Bind",s="Bracket",a="Fork",f="Sequential",g="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",N="Finalized",J="Forked";function v(G,Y,X,H){this.tag=G,this._1=Y,this._2=X,this._3=H}function w(G){var Y=function(X,H,Q){return new v(G,X,H,Q)};return Y.tag=G,Y}function L(G){return new v(t,void 0)}function b(G){try{G()}catch(Y){setTimeout(function(){throw Y},0)}}function S(G,Y,X){try{return Y(X())}catch(H){return G(H)}}function A(G,Y,X){try{return Y(X)()}catch(H){return X(G(H))(),L}}var O=(function(){var G=1024,Y=0,X=0,H=new Array(G),Q=!1;function W(){var U;for(Q=!0;Y!==0;)Y--,U=H[X],H[X]=void 0,X=(X+1)%G,U();Q=!1}return{isDraining:function(){return Q},enqueue:function(U){var F;Y===G&&(F=Q,W(),Q=F),H[(X+Y)%G]=U,Y++,Q||W()}}})();function j(G){var Y={},X=0,H=0;return{register:function(Q){var W=X++;Q.onComplete({rethrow:!0,handler:function(U){return function(){H--,delete Y[W]}}})(),Y[W]=Q,H++},isEmpty:function(){return H===0},killAll:function(Q,W){return function(){if(H===0)return W();var U=0,F={};function _t(ft){F[ft]=Y[ft].kill(Q,function(ht){return function(){delete F[ft],U--,G.isLeft(ht)&&G.fromLeft(ht)&&setTimeout(function(){throw G.fromLeft(ht)},0),U===0&&W()}})()}for(var pt in Y)Y.hasOwnProperty(pt)&&(U++,_t(pt));return Y={},X=0,H=0,function(ft){return new v(i,function(){for(var ht in F)F.hasOwnProperty(ht)&&F[ht]()})}}}}}var R=0,P=1,et=2,K=3,B=4,q=5,M=6;function C(G,Y,X){var H=0,Q=R,W=X,U=null,F=null,_t=null,pt=null,ft=null,ht=0,wt=0,It=null,dt=!0;function Mt(nt){for(var st,yt,Jt;;)switch(st=null,yt=null,Jt=null,Q){case et:Q=P;try{W=_t(W),pt===null?_t=null:(_t=pt._1,pt=pt._2)}catch($t){Q=q,U=G.left($t),W=null}break;case K:G.isLeft(W)?(Q=q,U=W,W=null):_t===null?Q=q:(Q=et,W=G.fromRight(W));break;case P:switch(W.tag){case u:_t&&(pt=new v(_,_t,pt)),_t=W._2,Q=P,W=W._1;break;case t:_t===null?(Q=q,W=G.right(W._1)):(Q=et,W=W._1);break;case i:Q=K,W=S(G.left,G.right,W._1);break;case o:Q=B,W=A(G.left,W._1,function($t){return function(){H===nt&&(H++,O.enqueue(function(){H===nt+1&&(Q=K,W=$t,Mt(H))}))}});return;case n:Q=q,U=G.left(W._1),W=null;break;case r:_t===null?ft=new v(_,W,ft,F):ft=new v(_,W,new v(_,new v(h,_t,pt),ft,F),F),_t=null,pt=null,Q=P,W=W._1;break;case s:ht++,_t===null?ft=new v(_,W,ft,F):ft=new v(_,W,new v(_,new v(h,_t,pt),ft,F),F),_t=null,pt=null,Q=P,W=W._1;break;case a:Q=K,st=C(G,Y,W._2),Y&&Y.register(st),W._1&&st.run(),W=G.right(st);break;case f:Q=P,W=D(G,Y,W._1);break}break;case q:if(_t=null,pt=null,ft===null)Q=M,W=F||U||W;else switch(st=ft._3,Jt=ft._1,ft=ft._2,Jt.tag){case r:F&&F!==st&&ht===0?Q=q:U&&(Q=P,W=Jt._2(G.fromLeft(U)),U=null);break;case h:F&&F!==st&&ht===0||U?Q=q:(_t=Jt._1,pt=Jt._2,Q=et,W=G.fromRight(W));break;case s:ht--,U===null&&(yt=G.fromRight(W),ft=new v(_,new v(p,Jt._2,yt),ft,st),(F===st||ht>0)&&(Q=P,W=Jt._3(yt)));break;case p:ft=new v(_,new v(N,W,U),ft,F),Q=P,F&&F!==st&&ht===0?W=Jt._1.killed(G.fromLeft(F))(Jt._2):U?W=Jt._1.failed(G.fromLeft(U))(Jt._2):W=Jt._1.completed(G.fromRight(W))(Jt._2),U=null,ht++;break;case m:ht++,ft=new v(_,new v(N,W,U),ft,F),Q=P,W=Jt._1;break;case N:ht--,Q=q,W=Jt._1,U=Jt._2;break}break;case M:for(var Ct in It)It.hasOwnProperty(Ct)&&(dt=dt&&It[Ct].rethrow,b(It[Ct].handler(W)));It=null,F&&U?setTimeout(function(){throw G.fromLeft(U)},0):G.isLeft(W)&&dt&&setTimeout(function(){if(dt)throw G.fromLeft(W)},0);return;case R:Q=P;break;case B:return}}function mt(nt){return function(){if(Q===M)return dt=dt&&nt.rethrow,nt.handler(W)(),function(){};var st=wt++;return It=It||{},It[st]=nt,function(){It!==null&&delete It[st]}}}function gt(nt,st){return function(){if(Q===M)return st(G.right(void 0))(),function(){};var yt=mt({rethrow:!1,handler:function(){return st(G.right(void 0))}})();switch(Q){case R:F=G.left(nt),Q=M,W=F,Mt(H);break;case B:F===null&&(F=G.left(nt)),ht===0&&(Q===B&&(ft=new v(_,new v(m,W(nt)),ft,F)),Q=q,W=null,U=null,Mt(++H));break;default:F===null&&(F=G.left(nt)),ht===0&&(Q=q,W=null,U=null)}return yt}}function rt(nt){return function(){var st=mt({rethrow:!1,handler:nt})();return Q===R&&Mt(H),st}}return{kill:gt,join:rt,onComplete:mt,isSuspended:function(){return Q===R},run:function(){Q===R&&(O.isDraining()?Mt(H):O.enqueue(function(){Mt(H)}))}}}function I(G,Y,X,H){var Q=0,W={},U=0,F={},_t=new Error("[ParAff] Early exit"),pt=null,ft=e;function ht(mt,gt,rt){var nt=gt,st=null,yt=null,Jt=0,Ct={},$t,re;t:for(;;)switch($t=null,nt.tag){case J:if(nt._3===e&&($t=W[nt._1],Ct[Jt++]=$t.kill(mt,function(Ve){return function(){Jt--,Jt===0&&rt(Ve)()}})),st===null)break t;nt=st._2,yt===null?st=null:(st=yt._1,yt=yt._2);break;case g:nt=nt._2;break;case d:case l:st&&(yt=new v(_,st,yt)),st=nt,nt=nt._1;break}if(Jt===0)rt(G.right(void 0))();else for(re=0,$t=Jt;re<$t;re++)Ct[re]=Ct[re]();return Ct}function wt(mt,gt,rt){var nt,st,yt,Jt,Ct,$t;for(G.isLeft(mt)?(nt=mt,st=null):(st=mt,nt=null);;){if(yt=null,Jt=null,Ct=null,$t=null,pt!==null)return;if(gt===null){H(nt||st)();return}if(gt._3!==e)return;switch(gt.tag){case g:nt===null?(gt._3=G.right(gt._1(G.fromRight(st))),st=gt._3):gt._3=nt;break;case d:if(yt=gt._1._3,Jt=gt._2._3,nt){if(gt._3=nt,Ct=!0,$t=U++,F[$t]=ht(_t,nt===yt?gt._2:gt._1,function(){return function(){delete F[$t],Ct?Ct=!1:rt===null?wt(nt,null,null):wt(nt,rt._1,rt._2)}}),Ct){Ct=!1;return}}else{if(yt===e||Jt===e)return;st=G.right(G.fromRight(yt)(G.fromRight(Jt))),gt._3=st}break;case l:if(yt=gt._1._3,Jt=gt._2._3,yt===e&&G.isLeft(Jt)||Jt===e&&G.isLeft(yt))return;if(yt!==e&&G.isLeft(yt)&&Jt!==e&&G.isLeft(Jt))nt=st===yt?Jt:yt,st=null,gt._3=nt;else if(gt._3=st,Ct=!0,$t=U++,F[$t]=ht(_t,st===yt?gt._2:gt._1,function(){return function(){delete F[$t],Ct?Ct=!1:rt===null?wt(st,null,null):wt(st,rt._1,rt._2)}}),Ct){Ct=!1;return}break}rt===null?gt=null:(gt=rt._1,rt=rt._2)}}function It(mt){return function(gt){return function(){delete W[mt._1],mt._3=gt,wt(gt,mt._2._1,mt._2._2)}}}function dt(){var mt=P,gt=X,rt=null,nt=null,st,yt;t:for(;;)switch(st=null,yt=null,mt){case P:switch(gt.tag){case g:rt&&(nt=new v(_,rt,nt)),rt=new v(g,gt._1,e,e),gt=gt._2;break;case d:rt&&(nt=new v(_,rt,nt)),rt=new v(d,e,gt._2,e),gt=gt._1;break;case l:rt&&(nt=new v(_,rt,nt)),rt=new v(l,e,gt._2,e),gt=gt._1;break;default:yt=Q++,mt=q,st=gt,gt=new v(J,yt,new v(_,rt,nt),e),st=C(G,Y,st),st.onComplete({rethrow:!1,handler:It(gt)})(),W[yt]=st,Y&&Y.register(st)}break;case q:if(rt===null)break t;rt._1===e?(rt._1=gt,mt=P,gt=rt._2,rt._2=e):(rt._2=gt,gt=rt,nt===null?rt=null:(rt=nt._1,nt=nt._2))}for(ft=gt,yt=0;yt<Q;yt++)W[yt].run()}function Mt(mt,gt){pt=G.left(mt);var rt;for(var nt in F)if(F.hasOwnProperty(nt)){rt=F[nt];for(nt in rt)rt.hasOwnProperty(nt)&&rt[nt]()}F=null;var st=ht(mt,ft,gt);return function(yt){return new v(o,function(Jt){return function(){for(var Ct in st)st.hasOwnProperty(Ct)&&st[Ct]();return L}})}}return dt(),function(mt){return new v(o,function(gt){return function(){return Mt(mt,gt)}})}}function D(G,Y,X){return new v(o,function(H){return function(){return I(G,Y,X,H)}})}return v.EMPTY=e,v.Pure=w(t),v.Throw=w(n),v.Catch=w(r),v.Sync=w(i),v.Async=w(o),v.Bind=w(u),v.Bracket=w(s),v.Fork=w(a),v.Seq=w(f),v.ParMap=w(g),v.ParApply=w(d),v.ParAlt=w(l),v.Fiber=C,v.Supervisor=j,v.Scheduler=O,v.nonCanceler=L,v})();let Ki=null;function L0(){return Ki||(typeof document>"u"?null:(Ki=document.createElement("canvas").getContext("2d"),Ki))}const La=new Map,Ea=e=>t=>n=>r=>{const i=`${n} ${t}px ${e}|${r}`,o=La.get(i);if(o!==void 0)return o;const u=L0();if(!u)return r.length*t*.62;u.font=`${n} ${t}px ${e}`;const s=u.measureText(r).width;return La.set(i,s),s},E0=e=>()=>e.clip("evenodd"),C0=e=>t=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(t.tile,.001))),r=Math.max(2,Math.round(t.tile*n)),i=document.createElement("canvas");i.width=r,i.height=r;const o=i.getContext("2d");o.scale(n,n),o.fillStyle=t.bgCss,o.fillRect(0,0,t.tile,t.tile),o.fillStyle=t.dotCss,o.beginPath(),o.arc(t.tile/2,t.tile/2,t.dotR,0,2*Math.PI),o.fill();const u=e.createPattern(i,"repeat");u&&typeof u.setTransform=="function"&&u.setTransform(new DOMMatrix().scaleSelf(1/n,1/n)),e.save(),e.fillStyle=u,e.fillRect(t.vx,t.vy,t.vw,t.vh),e.restore()},S0=e=>t=>n=>r=>i=>o=>()=>{if(typeof e.roundRect=="function")e.roundRect(t,n,r,i,o);else{const u=Math.min(o,r/2,i/2);e.moveTo(t+u,n),e.lineTo(t+r-u,n),e.quadraticCurveTo(t+r,n,t+r,n+u),e.lineTo(t+r,n+i-u),e.quadraticCurveTo(t+r,n+i,t+r-u,n+i),e.lineTo(t+u,n+i),e.quadraticCurveTo(t,n+i,t,n+i-u),e.lineTo(t,n+u),e.quadraticCurveTo(t,n,t+u,n),e.closePath()}},P0=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Zi=e=>t=>n=>{const r=t.stroke;return()=>{const i=r.value,o=Hf(e)(n);if(i!==n)return o(),t.stroke.value=n}},R0=e=>t=>n=>{const r=t.font;return()=>{const i=r.value,o=eg(e)(n);if(i!==n)return o(),t.font.value=n}},Dr=e=>t=>n=>{const r=t.fill;return()=>{const i=r.value,o=qf(e)(n);if(i!==n)return o(),t.fill.value=n}},vo=e=>t=>{const n=t.length,r=o=>{if(o>=n)return()=>{};const u=o>=0&&o<t.length?t[o]:0;if(u===1){const s=Xf(e)((()=>{const f=o+1|0;return f>=0&&f<t.length?t[f]:0})())((()=>{const f=o+2|0;return f>=0&&f<t.length?t[f]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===2){const s=Ff(e)((()=>{const f=o+1|0;return f>=0&&f<t.length?t[f]:0})())((()=>{const f=o+2|0;return f>=0&&f<t.length?t[f]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===3){const s=rg(e)({cpx:(()=>{const f=o+1|0;return f>=0&&f<t.length?t[f]:0})(),cpy:(()=>{const f=o+2|0;return f>=0&&f<t.length?t[f]:0})(),x:(()=>{const f=o+3|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=o+4|0;return f>=0&&f<t.length?t[f]:0})()}),a=r(o+5|0);return()=>(s(),a())}if(u===4){const s=og(e)({cp1x:(()=>{const f=o+1|0;return f>=0&&f<t.length?t[f]:0})(),cp1y:(()=>{const f=o+2|0;return f>=0&&f<t.length?t[f]:0})(),cp2x:(()=>{const f=o+3|0;return f>=0&&f<t.length?t[f]:0})(),cp2y:(()=>{const f=o+4|0;return f>=0&&f<t.length?t[f]:0})(),x:(()=>{const f=o+5|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=o+6|0;return f>=0&&f<t.length?t[f]:0})()}),a=r(o+7|0);return()=>(s(),a())}if(u===5){const s=Uf(e),a=r(o+1|0);return()=>(s(),a())}return()=>{}},i=Qu(e);return()=>(i(),r(0)())},I0=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),D0=e=>t=>{const n=Zf(e)({x:0,y:0,width:t.width,height:t.height});return()=>{n();const r=I0();return{ctx:e,surface:t,styleCache:r,maskDepth:{value:0}}}},G0={map:e=>t=>n=>{const r=t(n);return()=>{const i=r();return e(i)}}},M0=e=>ue(e.weight)+" "+xu(e.size)+"px Ilisarniq, ui-sans-serif, system-ui, sans-serif",qe=e=>{const t=xu(ct(e.a)/255);return e.a>=255?"rgb("+ue(e.r)+","+ue(e.g)+","+ue(e.b)+")":"rgba("+ue(e.r)+","+ue(e.g)+","+ue(e.b)+","+t+")"},W0=e=>t=>n=>r=>{const i=Dr(e)(n)(qe(r));return()=>(i(),Kf(e)({x:0,y:0,width:t.width,height:t.height})())},A0=e=>t=>n=>{const r=t.font;return()=>(r.value="",t.fill.value="",t.stroke.value="",C0(e)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:qe(n.bgColor),dotCss:qe(n.dotColor),tile:n.tile,dotR:n.dotRadius})())},z0=e=>t=>n=>r=>{const i=Dr(e)(t)(qe(r));return()=>(i(),vo(e)(n)(),jo(e)())},B0=e=>t=>n=>r=>i=>{const o=Dr(e)(t)(qe(r));return()=>(o(),Zi(e)(t)(qe(i.color))(),Xo(e)(i.width)(),Fr(e)((()=>{if(i.lineJoin==="RoundJoin")return Or;if(i.lineJoin==="BevelJoin")return oi;if(i.lineJoin==="MiterJoin")return ii;c()})())(),ci(e)((()=>{if(i.lineCap==="ButtCap")return ai;if(i.lineCap==="RoundCap")return ui;if(i.lineCap==="SquareCap")return si;c()})())(),vo(e)(n)(),jo(e)(),Zo(e)())},$0=e=>t=>n=>r=>i=>o=>{const u=Qu(e);return()=>{if(u(),S0(e)(n.x)(n.y)(n.w)(n.h)(r)(),i.tag==="Just"?(Dr(e)(t)(qe(i._1.color))(),jo(e)()):i.tag==="Nothing"||c(),o.tag==="Just")return Zi(e)(t)(qe(o._1.color))(),Xo(e)(o._1.width)(),Fr(e)((()=>{if(o._1.lineJoin==="RoundJoin")return Or;if(o._1.lineJoin==="BevelJoin")return oi;if(o._1.lineJoin==="MiterJoin")return ii;c()})())(),ci(e)((()=>{if(o._1.lineCap==="ButtCap")return ai;if(o._1.lineCap==="RoundCap")return ui;if(o._1.lineCap==="SquareCap")return si;c()})())(),Zo(e)();o.tag!=="Nothing"&&c()}},Q0=e=>t=>n=>r=>{const i=Zi(e)(t)(qe(r.color));return()=>(i(),Xo(e)(r.width)(),Fr(e)((()=>{if(r.lineJoin==="RoundJoin")return Or;if(r.lineJoin==="BevelJoin")return oi;if(r.lineJoin==="MiterJoin")return ii;c()})())(),ci(e)((()=>{if(r.lineCap==="ButtCap")return ai;if(r.lineCap==="RoundCap")return ui;if(r.lineCap==="SquareCap")return si;c()})())(),vo(e)(n)(),Zo(e)())},q0=e=>t=>n=>{const r=Dr(e)(t)(qe(n.color));return()=>(r(),R0(e)(t)(M0(n.font))(),hg(e)((()=>{if(n.align==="AlignLeft")return cg;if(n.align==="AlignCenter")return gg;if(n.align==="AlignRight")return fg;c()})())(),lg(e)((()=>{if(n.baseline==="BaselineTop")return ig;if(n.baseline==="BaselineMiddle")return ug;if(n.baseline==="BaselineAlphabetic")return sg;if(n.baseline==="BaselineBottom")return ag;c()})())(),ng(e)(n.content)(n.x)(n.y)())},Ca={apply:e=>t=>n=>{const r=e(n),i=t(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>G0},H0={bind:e=>t=>n=>{const r=e(n);return()=>{const i=r();return t(i)(n)()}},Apply0:()=>Ca},Y0=e=>t=>n=>{const r=P0(t.width/n.vw)(t.height/n.vh),i=qu(e)({translateX:(t.width-n.vw*r)/2-n.vx*r,translateY:(t.height-n.vh*r)/2-n.vy*r});return()=>(i(),ti(e)({scaleX:r,scaleY:r})(),Fr(e)(Or)())},V0={pure:e=>t=>()=>e,Apply0:()=>Ca},O0={Applicative0:()=>V0,Bind1:()=>H0},Sa={fillPath:e=>t=>n=>{const r=z0(n.ctx)(n.styleCache)(e)(t.color),i=n.maskDepth;return()=>{if(i.value===0)return r()}},strokePath:e=>t=>n=>{const r=Q0(n.ctx)(n.styleCache)(e)(t),i=n.maskDepth;return()=>{if(i.value===0)return r()}},fillStrokePath:e=>t=>n=>r=>{const i=B0(r.ctx)(r.styleCache)(e)(t.color)(n),o=r.maskDepth;return()=>{if(o.value===0)return i()}},drawRoundedRect:e=>t=>n=>r=>i=>{const o=$0(i.ctx)(i.styleCache)(e)(t)(n)(r),u=i.maskDepth;return()=>{if(u.value===0)return o()}},drawText:e=>t=>{const n=q0(t.ctx)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},pushTransform:e=>t=>{const n=dr(t.ctx),r=t.maskDepth;return()=>{if(r.value===0)return n(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="",qu(t.ctx)({translateX:e.tx,translateY:e.ty})(),ti(t.ctx)({scaleX:e.sx,scaleY:e.sy})()}},popTransform:e=>{const t=lr(e.ctx),n=e.maskDepth;return()=>{if(n.value===0)return t(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value=""}},pushClip:e=>t=>n=>{const r=dr(n.ctx),i=n.maskDepth;return()=>{if(i.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",vo(n.ctx)(e)(),t==="NonZero")return Of(n.ctx)();if(t==="EvenOdd")return E0(n.ctx)();c()}}},popClip:e=>{const t=lr(e.ctx),n=e.maskDepth;return()=>{if(n.value===0)return t(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value=""}},pushBlend:e=>t=>{const n=dr(t.ctx),r=t.maskDepth;return()=>{if(r.value===0){if(n(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="",e==="Normal")return Yu(t.ctx)(_g)();if(e==="Difference")return Yu(t.ctx)(dg)();c()}}},popBlend:e=>{const t=lr(e.ctx),n=e.maskDepth;return()=>{if(n.value===0)return t(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value=""}},pushAlpha:e=>t=>{const n=dr(t.ctx),r=t.maskDepth;return()=>{if(r.value===0)return n(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="",Vf(t.ctx)(e)()}},popAlpha:e=>{const t=lr(e.ctx),n=e.maskDepth;return()=>{if(n.value===0)return t(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value=""}},pushLayer:e=>t=>{if(e==="LayerNodeMask"){const n=t.maskDepth;return()=>{const r=n.value;n.value=r+1|0}}return()=>{}},popLayer:e=>{const t=e.maskDepth;return()=>{const n=t.value,r=n-1|0;if(n>0)return e.maskDepth.value=r}},setViewport:e=>t=>{const n=Y0(t.ctx)(t.surface)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:e=>t=>{const n=W0(t.ctx)(t.surface)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:e=>t=>{const n=A0(t.ctx)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},measureText:e=>t=>n=>{const r=Ea(e.family)(e.size)(e.weight)(so(t));return()=>r},Monad0:()=>O0};function F0(e,t){const n=t.x-e.x,r=t.y-e.y;return Math.sqrt(n*n+r*r)}function X0(e){const t=e.length,n=new Array(t);for(let r=0;r<t;r++){const i=e[r],o=e[(r+1)%t];n[r]={a:i,b:o,len:F0(i,o)}}return n}function U0(e,t,n){let r=0;for(let i=0;i<e.length;i++){const o=e[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 t.length>0?t[t.length-1]:{x:0,y:0}}function Pa(e,t){if(t.length===0)return[];const n=X0(t);let r=0;for(let o=0;o<n.length;o++)r+=n[o].len;const i=new Array(e);for(let o=0;o<e;o++)i[o]=U0(n,t,o*r/e);return i}function K0(e,t){const n=t.length;if(n===0)return t;const r=(e%n+n)%n|0,i=new Array(n);for(let o=0;o<n;o++)i[o]=t[(o+r)%n];return i}function Z0(e,t){const n=t.length;if(n===0)return t;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=e[s]||{x:0,y:0},f=t[(s+o)%n]||{x:0,y:0},g=a.x-f.x,d=a.y-f.y;u+=g*g+d*d}u<i&&(i=u,r=o)}return K0(r,t)}const Ra=e=>t=>n=>{const r=Pa(e,t),i=Pa(e,n),o=Z0(r,i);return{from:r,to:o}};function Ia(e){const t=e.length;if(t===0)return{x:0,y:0};let n=0,r=0;for(let i=0;i<t;i++)n+=e[i].x,r+=e[i].y;return{x:n/t,y:r/t}}function j0(e,t){const n=t.x-e.x,r=t.y-e.y,i=Math.sqrt(n*n+r*r);return i<=1e-4?{x:1,y:0}:{x:n/i,y:r/i}}function th(e,t){const n=t.length;if(n===0)return t;const r=new Array(n);for(let i=0;i<n;i++){const o=t[((i-1)%n+n)%n],u=t[((i+1)%n+n)%n],s=t[i];r[i]={x:s.x+((o.x+u.x)/2-s.x)*e,y:s.y+((o.y+u.y)/2-s.y)*e}}return r}function eh(e){return e<0?0:e>1?1:e}const Da=e=>t=>n=>r=>{const i=t.length;if(i===0)return[];const o=Ia(t),u=Ia(n),s=j0(o,u),a=new Array(i);let f=1/0,g=-1/0;for(let _=0;_<i;_++){const h=t[_],p=(h.x-o.x)*s.x+(h.y-o.y)*s.y;a[_]=p,p<f&&(f=p),p>g&&(g=p)}const d=g-f;let l=new Array(i);for(let _=0;_<i;_++){const h=t[_],p=n[_];if(p===void 0){l[_]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(a[_]-f)/d),N=Math.max(1e-4,1-m),J=eh((e-m)/N),v=J*J*(3-2*J);l[_]={x:h.x+(p.x-h.x)*v,y:h.y+(p.y-h.y)*v}}for(let _=0;_<r.smoothPasses;_++)l=th(.5,l);return l},nh=e=>e,Ga=e=>e,To=e=>e,Ma=e=>e,rh=e=>e,Wa=e=>e,Aa=e=>e,za=Aa("BaselineTop"),Gr=Aa("BaselineMiddle"),wo=Wa("AlignLeft"),ji=Wa("AlignCenter"),He=rh("RoundJoin"),dn=Ma("ButtCap"),Ba=Ma("RoundCap"),oh=To("LayerPolyOut"),ih=To("LayerPolyIn"),uh=To("LayerNodeMask"),sh=To("LayerOverlay"),$a=Ga("NonZero"),ah=Ga("EvenOdd"),ch=nh("Difference"),Kn={r:255,g:255,b:255,a:255},Ze={r:26,g:26,b:26,a:255},tu=(e,t,n)=>({tag:e,_1:t,_2:n}),je=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Mr=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Qa=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Ln=e=>t=>n=>{const r=lt.compare(e)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),o=lt.compare(t)(i);if(o==="LT"||o==="EQ")return t;if(o==="GT")return i;c()},Ee=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},tn=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),eu=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},qa=te(k)(At),Ha=y(cr)(0),bo=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Ya=e=>{const t=e.Monad0().Bind1(),n=e.popTransform,r=e.popAlpha;return i=>o=>u=>s=>a=>t.bind(e.pushAlpha(i.fadeAlpha))(()=>t.bind(e.pushTransform({tx:o*(1-i.popScale),ty:u*(1-i.popScale),sx:i.popScale,sy:i.popScale}))(()=>t.bind(e.pushTransform({tx:0,ty:s.y*(1-i.flipY),sx:1,sy:i.flipY}))(()=>t.bind(a)(()=>t.bind(n)(()=>t.bind(n)(()=>r))))))},en=e=>{const t=e.Apply0();return n=>y(r=>i=>t.apply(t.Functor0().map(o=>Nu)(r))(n(i)))(e.pure())},fh=e=>({x:e.x,y:e.y,w:e.w,h:e.h}),gh=y(e=>t=>e+t.len)(0),_h=e=>{const t=Ht(n=>T,n=>r=>E("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return[];if(t.tag==="Just")return[1,t._1.head.x,t._1.head.y,...St(Gt(1,e.length,e))(n=>[2,n.x,n.y]),5];c()},dh=e=>t=>{const n=e.y+e.h-6,r=e.y+6,i=e.x+14,o=e.x+e.w-14,u=y(Mr)(0)(V(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?je((s.x+s.w+12-(i-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(t));return{...e,x:e.x+u*.7071067811865476,y:e.y-u*.7071067811865476}},lh={r:26,g:26,b:26,a:255},hh={r:214,g:211,b:209,a:255},Va=e=>t=>{const n=je(t)(je(e.w/2)(e.h/2));return[1,e.x+n,e.y,2,e.x+e.w-n,e.y,3,e.x+e.w,e.y,e.x+e.w,e.y+n,2,e.x+e.w,e.y+e.h-n,3,e.x+e.w,e.y+e.h,e.x+e.w-n,e.y+e.h,2,e.x+n,e.y+e.h,3,e.x,e.y+e.h,e.x,e.y+e.h-n,2,e.x,e.y+n,3,e.x,e.y,e.x+n,e.y,5]},ph=e=>t=>n=>y(r=>i=>{const o=Qa(i)(t);if(o.tag==="Nothing")return r;if(o.tag==="Just"){const u=dh(o._1)(r.obstacles);return{acc:Z(k)(i)(u)(r.acc),obstacles:de(r.obstacles)(u)}}c()})({acc:$,obstacles:n})(e).acc,mh=e=>{const t=Ht(n=>T,n=>r=>E("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return[];if(t.tag==="Just")return[1,t._1.head.x,t._1.head.y,...St(t._1.tail)(n=>[2,n.x,n.y])];c()},ko=e=>{if(e.tag==="Hidden")return{alpha:0,scale:0};if(e.tag==="Visible")return{alpha:1,scale:1};if(e.tag==="PloppingIn")return{alpha:e._1>0?1:0,scale:hr(8)(.6)(Ln(0)(1)(e._1))};if(e.tag==="PloppingOut")return{alpha:e._1<1?1:0,scale:hr(8)(.6)(Ln(0)(1)(1-e._1))};c()},Oa=e=>t=>St(tn(e.nodes))(n=>{const r=Ee(n._1)(t.nodes);return r.tag==="Just"&&ko(r._1).alpha>0?Va(n._2)(7):[]}),yh=e=>t=>n=>[1,e.vx,e.vy,2,e.vx+e.vw,e.vy,2,e.vx+e.vw,e.vy+e.vh,2,e.vx,e.vy+e.vh,5,...Oa(t)(n)],Lo=e=>t=>n=>V(r=>{const i=ct(r)/ct(n);return{x:e.x+(t.x-e.x)*i,y:e.y+(t.y-e.y)*i}})(qt(0,n-1|0)),Jh=e=>t=>{const n=i=>(i.x-t.x)*(i.x-t.x)+(i.y-t.y)*(i.y-t.y),r=y(i=>o=>n(o)<n(i)?o:i)({x:e.x,y:e.y})([{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x,y:e.y+e.h},{x:e.x+e.w,y:e.y+e.h}]);return V(i=>{const o=ct(i)/5;return{x:r.x+(t.x-r.x)*o,y:r.y+(t.y-r.y)*o}})([1,2,3,4])},Fa=e=>{const t=vi(`
6
- `)(e);return t.length===0?[""]:t},nu=e=>t=>{const n=je(e)(je(t.w/2)(t.h/2));return{...t,x:t.x+n,y:t.y+n,w:t.w-2*n,h:t.h-2*n}},Nh=e=>{const t=e.Monad0(),n=t.Applicative0(),r=t.Bind1(),i=en(n),o=e.popTransform,u=e.popAlpha;return s=>a=>f=>{const g=vi(`
7
- `)(a.label===""?s:a.label),d=g.length===0?[""]:g,l=a.y+a.h/2-ct(d.length)*13.2/2+6.6,_=ko(f),h=a.x+a.w/2,p=a.y+a.h/2,m=r.bind(e.pushAlpha(_.alpha))(()=>r.bind(e.pushTransform({tx:h*(1-_.scale),ty:p*(1-_.scale),sx:_.scale,sy:_.scale}))(()=>r.bind(e.drawRoundedRect({x:a.x,y:a.y,w:a.w,h:a.h})(7)(E("Just",{color:Kn,flat:!1}))(E("Just",{color:Ze,width:1.25,lineJoin:He,lineCap:dn})))(()=>r.bind(i(N=>e.drawText({x:a.x+a.w/2,y:l+ct(N._1)*13.2,content:N._2,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500},color:Ze,align:ji,baseline:Gr}))(Dt(In)(d)))(()=>r.bind(o)(()=>u)))));return _.alpha>0?m:n.pure()}},Xa=e=>{const t=Nh(e),n=e.Monad0().Applicative0(),r=en(n);return i=>o=>r(u=>{const s=Ee(u._1)(o.nodes);if(s.tag==="Just")return t(u._1)(u._2)(s._1);if(s.tag==="Nothing")return n.pure();c()})(tn(i.nodes))},ru=e=>t=>{const n=t.y-e.y,r=t.x-e.x;return Wn(r*r+n*n)},xh=e=>ye(t=>n=>({a:t,b:n,len:ru(t)(n)}),e,Gt(1,e.length,e)),vh=e=>t=>{const n=t.length-1|0,r=n>=0&&n<t.length?E("Just",t[n]):T,i=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];c()})(),o=0<t.length?E("Just",t[0]):T,u=(()=>{if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return{x:0,y:0};c()})(),s=t.length;return s<3?t:[u,...St(qt(1,s-2|0))(a=>{const f=a+1|0,g=f>=0&&f<t.length?E("Just",t[f]):T,d=a>=0&&a<t.length?E("Just",t[a]):T,l=a-1|0,_=l>=0&&l<t.length?E("Just",t[l]):T;if(_.tag==="Just"&&d.tag==="Just"&&g.tag==="Just"){const h=d._1,p=ru(h)(g._1),m=ru(_._1)(h),N=je(e)(p/2),J=je(e)(m/2),v=p>0?N/p:0,w=h.x+(g._1.x-h.x)*v,L=h.y+(g._1.y-h.y)*v,b=m>0?J/m:0,S=h.x+(_._1.x-h.x)*b,A=h.y+(_._1.y-h.y)*b;return V(O=>{const j=ct(O)/ct(10),R=1-j;return{x:R*R*S+2*R*j*h.x+j*j*w,y:R*R*A+2*R*j*h.y+j*j*L}})(qt(0,10))}return[]}),...i]},Th=e=>{const t=e.Monad0(),n=t.Bind1(),r=t.Applicative0(),i=en(r);return o=>u=>s=>a=>f=>g=>{const d=wi(g).length,l=ct(d+1|0),_=m=>{const N=(s*l-ct(m))/1.5,J=N<0?0:N>1?1:N;return J*J*(3-2*J)},h=(m=>{let N=m,J=!0,v;for(;J;){const w=N;if(w>=d){J=!1,v=w;continue}if(_(w)>=1){N=w+1|0;continue}J=!1,v=w}return v})(0),p=h>=d?[]:pn(m=>_(m)>0)(qt(h,d-1|0)).init;return n.bind((()=>{const m=e.drawText({x:a,y:f,content:ie(h)(g),font:o,color:u,align:wo,baseline:Gr});return h>0?m:r.pure()})())(()=>i(m=>n.bind(e.measureText(o)(ie(m)(g)))(N=>{const J=_(m);return e.drawText({x:a+N,y:f-(1-J)*10,content:ie(1)(mr(Jn(ie(m)(g)))(g)),font:o,color:{...u,a:ur(Gu(J*ct(u.a)))},align:wo,baseline:Gr})}))(p))}},Eo=e=>t=>n=>r=>{const i=V(h=>ct(eu(1)(wi(h).length)))(r),o=Mr(1)(y(cr)(0)(i)),u=Mr(.05)(1-t-n),s=e<t?0:e>1-n?1:(e-t)/u,a=s*o,f=eu(1)(r.length),g=(h=>p=>m=>{let N=h,J=p,v=m,w=!0,L;for(;w;){const b=N,S=J,A=Ht(O=>T,O=>j=>E("Just",{head:O,tail:j}),v);if(A.tag==="Nothing"){w=!1,L=eu(0)(f-1|0);continue}if(A.tag==="Just"){if(S+A._1.head>=a){w=!1,L=b;continue}N=b+1|0,J=S+A._1.head,v=A._1.tail;continue}c()}return L})(0)(0)(i),d=y(cr)(0)(g<1?[]:Gt(0,g,i)),l=d/o;if(g>=0&&g<i.length){const h=(d+i[g])/o;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(h<=l)return 1;const p=(s-l)/(h-l);return p<0?0:p>1?1:p})()}}const _=(d+1)/o;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(_<=l)return 1;const h=(s-l)/(_-l);return h<0?0:h>1?1:h})()}},wh=e=>{const t=e.Monad0();return n=>r=>i=>t.Bind1().bind(e.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Eo(r)(0)(0)(i).line))(o=>{const u=o+28;return t.Applicative0().pure({x:n.x+n.w/2-u/2,y:n.y-25.2-14,w:u,h:25.2})})},bh=e=>{const t=e.Monad0(),n=t.Bind1(),r=wh(e),i=t.Applicative0(),o=qr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>qa(Pt(f=>f)(a)))(o(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const f=Ee(a._2._1.node)(u.nodes);if(f.tag==="Just")return n.bind(r(f._1)(a._2._1.progress)(a._2._1.labels))(g=>i.pure(E("Just",x(a._1,g))));if(f.tag==="Nothing")return i.pure(T);c()}return i.pure(T)})(tn(s.tokens)))},Ua=e=>t=>V(n=>{const r=6.283185307179586*ct(n)/ct(64);return{x:e.x+t*Ho(r),y:e.y+t*Vo(r)}})(qt(0,63)),ou=e=>t=>{const n=.5522847498*t;return[1,e.x+t,e.y,4,e.x+t,e.y+n,e.x+n,e.y+t,e.x,e.y+t,4,e.x-n,e.y+t,e.x-t,e.y+n,e.x-t,e.y,4,e.x-t,e.y-n,e.x-n,e.y-t,e.x,e.y-t,4,e.x+n,e.y-t,e.x+t,e.y-n,e.x+t,e.y,5]},kh=e=>{const t=e.Monad0().Bind1(),n=e.popAlpha;return r=>i=>o=>u=>s=>a=>f=>{const g={x:o.x+o.w/2,y:o.y+o.h/2},d=Mr(.05)(1-a-f),l=s<a?0:s>1-f?1:(s-a)/d,_={x:u.x+u.w/2,y:u.y+u.h/2},h=(p,m)=>t.bind(e.pushAlpha(m))(()=>t.bind(e.fillStrokePath(ou(p)(6))({color:r,flat:!0})({color:i,width:1,lineJoin:He,lineCap:dn}))(()=>n));return l<.5?h(g,(()=>{const p=l*2;return 1-(p<0?0:p>1?1:p)*(p<0?0:p>1?1:p)*(p<0?3:p>1?1:3-2*p)})()):h(_,(()=>{const p=(l-.5)*2;return(p<0?0:p>1?1:p)*(p<0?0:p>1?1:p)*(p<0?3:p>1?1:3-2*p)})())}},Lh={r:255,g:235,b:130,a:255},Eh=e=>{const t=e.length;return t===0?{x:0,y:0}:{x:Ha(V(n=>n.x)(e))/ct(t),y:Ha(V(n=>n.y)(e))/ct(t)}},Ka=e=>t=>n=>{const r=hr(6)(.55)(Ln(0)(1)((1-e)/.06)),i=e>.94,o=i&&n>1e-4,u=hr(6)(.55)(Ln(0)(1)(e/.06)),s=e<.06,a=s&&t>1e-4,f=i&&n<=1e-4;return{popScale:a?u:o?r:1,flipY:s&&t<=1e-4?u:f?r:1,fadeAlpha:(()=>{if(a){const g=e/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}if(o){const g=(1-e)/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}return 1})()}},Ch=e=>{const t=e.Monad0().Bind1(),n=Ya(e);return r=>i=>o=>u=>{const s=Ka(o)(0)(0),a={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500},f=Eo(o)(0)(0)(u);return t.bind(e.measureText(a)(f.line))(g=>{const d={r:26,g:26,b:26,a:90},l=i.x+i.w/2,_=g+28,h=i.y-25.2-14,p=l-_/2,m=[1,l,h+25.2,2,l,i.y],N={x:l,y:h+12.6};return n(s)(l-_/2)(h+25.2)(N)(t.bind(e.drawRoundedRect({x:l-_/2,y:h+1.5,w:_,h:25.2})(6)(E("Just",{color:hh,flat:!0}))(T))(()=>t.bind(e.drawRoundedRect({x:p,y:h,w:_,h:25.2})(6)(E("Just",{color:Lh,flat:!0}))(E("Just",{color:d,width:1,lineJoin:He,lineCap:dn})))(()=>t.bind(e.strokePath(m)({color:d,width:1,lineJoin:He,lineCap:dn}))(()=>e.drawText({x:l,y:N.y,content:f.line,font:a,color:Ze,align:ji,baseline:Gr})))))})}},Za={r:0,g:0,b:0,a:0},Sh=e=>t=>e.backgroundDots({viewport:{vx:t.x,vy:t.y,vw:t.w,vh:t.h},bgColor:Za,dotColor:lh,tile:1.6,dotRadius:.25}),Ph={r:214,g:211,b:209,a:255},ja={r:255,g:255,b:255,a:255},tc=e=>{const t=e.Monad0().Bind1();return n=>r=>n?t.bind(e.clearBackground(Za))(()=>e.setViewport(r)):t.bind(e.setViewport(r))(()=>e.backgroundDots({viewport:r,bgColor:ja,dotColor:Ph,tile:12,dotRadius:.7}))},Rh=e=>{const t=e.Monad0(),n=t.Applicative0(),r=t.Bind1(),i=e.popClip,o=e.popTransform,u=e.popAlpha;return s=>a=>f=>{const g=ko(f),d={...a,y:a.y+5},l=d.x+d.w/2,_=d.y+d.h/2,h=r.bind(e.pushAlpha(g.alpha))(()=>r.bind(e.pushTransform({tx:l*(1-g.scale),ty:_*(1-g.scale),sx:g.scale,sy:g.scale}))(()=>r.bind(e.drawRoundedRect({x:d.x,y:d.y,w:d.w,h:d.h})(7)(E("Just",{color:ja,flat:!0}))(T))(()=>r.bind((()=>{const p=r.bind(e.pushClip(Va(d)(7))($a))(()=>r.bind(Sh(e)(d))(()=>i));return s?p:n.pure()})())(()=>r.bind(e.drawRoundedRect({x:d.x,y:d.y,w:d.w,h:d.h})(7)(T)(E("Just",{color:Ze,width:1.25,lineJoin:He,lineCap:dn})))(()=>r.bind(o)(()=>u))))));return g.alpha>0?h:n.pure()}},ec=e=>{const t=Rh(e),n=e.Monad0().Applicative0(),r=en(n);return i=>o=>u=>r(s=>{const a=Ee(s._1)(u.nodes);if(a.tag==="Just")return t(i)(s._2)(a._1);if(a.tag==="Nothing")return n.pure();c()})(tn(o.nodes))},Ih=e=>{const t=e.Monad0().Applicative0();return n=>{const r=n.length-1|0,i=r<1?[]:Gt(0,r,n),o=i.length-1|0,u=o>=0&&o<i.length?E("Just",i[o]):T,s=n.length-1|0;if(s>=0&&s<n.length&&u.tag==="Just"){const a=n[s].y-u._1.y,f=n[s].x-u._1.x,g=Wn(f*f+a*a),d=a/g,l=-d,_=f/g,h=n[s].x+_*.875,p=n[s].y+d*.875,m=p-d*8.75,N=h-_*8.75,J=[1,h,p,2,N+l*4.375,m+_*4.375,2,N-l*4.375,m-_*4.375,5];return g<=1e-4?t.pure():e.fillPath(J)({color:Ze,flat:!0})}return t.pure()}},Co=e=>t=>n=>r=>i=>V(o=>{const u=n+(r-n)*(ct(o)/ct(i));return{x:e.x+t*Ho(u),y:e.y+t*Vo(u)}})(qt(0,i-1|0)),nc=e=>t=>{const n=je(e)(je(t.w/2)(t.h/2));return[...Lo({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(6),...Co({x:t.x+t.w-n,y:t.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...Lo({x:t.x+t.w,y:t.y+n})({x:t.x+t.w,y:t.y+t.h-n})(6),...Co({x:t.x+t.w-n,y:t.y+t.h-n})(n)(0)(1.5707963267948966)(12),...Lo({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(6),...Co({x:t.x+n,y:t.y+t.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...Lo({x:t.x,y:t.y+t.h-n})({x:t.x,y:t.y+n})(6),...Co({x:t.x+n,y:t.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},Dh=e=>t=>n=>y(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=t>r.pos?(t-r.pos)/i.len:0,f={x:i.a.x+(i.b.x-i.a.x)*a,y:i.a.y+(i.b.y-i.a.y)*a},g=r.points.length-1|0,d=g>=0&&g<r.points.length?(()=>{const l=r.points[g].x-f.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const _=r.points[g].y-f.y;return _<0?-_<1e-4:_<1e-4})()})()?de(r.points)(s):[...r.points,f,s]:[f,s];return i.len<=0||o<=t||r.pos>=n?{...r,pos:o}:{pos:o,points:d}})({pos:0,points:[]})(e).points,Gh=e=>t=>n=>{const r=Ht(i=>T,i=>o=>E("Just",{head:i,tail:o}),e);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const i=xh(e),o=gh(i),u=Ln(0)(o)(t*o),s=Ln(0)(o)(n*o);return s<=u?[]:Dh(i)(u)(s)}c()},Mh=e=>{const t=e.Monad0(),n=t.Applicative0(),r=Ih(e);return i=>o=>u=>{const s=vh(8)(o);if(u.hi<=u.lo)return n.pure();const a=Gh(s)(u.lo)(u.hi);return a.length===0?n.pure():t.Bind1().bind(e.strokePath(mh(a))({color:Ze,width:.9375,lineJoin:He,lineCap:Ba}))(()=>r(a))}},rc=e=>{const t=Mh(e),n=e.Monad0().Applicative0(),r=en(n);return i=>o=>r(u=>{const s=bo(u._1)(o.edges);if(s.tag==="Just")return t(u._1)(u._2)((()=>{if(s._1.tag==="Retracted")return{lo:0,hi:0};if(s._1.tag==="Extended")return{lo:0,hi:1};if(s._1.tag==="Extending")return{lo:0,hi:s._1._2};if(s._1.tag==="Retracting"){if(s._1._1==="FromSource")return{lo:s._1._2,hi:1};if(s._1._1==="FromTarget")return{lo:0,hi:1-s._1._2};if(s._1._1==="FromBoth")return{lo:s._1._2/2,hi:1-s._1._2/2}}c()})());if(s.tag==="Nothing")return n.pure();c()})(tn(i.edges))},oc=e=>t=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:t.x+t.w/2,y:t.y+t.h/2},a=0<e.length?E("Just",e[0]):T,f=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return s;c()})(),g=e.length-1|0,d=g>=0&&g<e.length?E("Just",e[g]):T,l=(()=>{if(d.tag==="Just")return d._1;if(d.tag==="Nothing")return u;c()})(),_=Ra(128)(nc(5)(nu(2)(t)))(Ua(f)(6)),h=Mr(.05)(1-i-o),p=r<i?0:r>1-o?1:(r-i)/h,m=f.x-s.x,N=2*(()=>{const K=f.y-s.y;return(m<0?-m:m)+(K<0?-K:K)})(),J=l.x-u.x,v=2*(()=>{const K=l.y-u.y;return(J<0?-J:J)+(K<0?-K:K)})(),w=N+gi(e)+v,L=w<=1e-4?1:1-v/w,b=w<=1e-4?0:N/w,S=L-b,A=Ra(128)(Ua(l)(6))(nc(5)(nu(2)(n))),O={maxDelay:.4,smoothPasses:2},j=Xu(e)(Ln(0)(1)(S<=1e-4?0:(p-b)/S)),R=(()=>{if(j.tag==="Just")return j._1;if(j.tag==="Nothing")return f;c()})(),P=(()=>{if(L>=1)return 0;const K=(p-L)/(1-L),B=K<0?0:K>1?1:K;return B*B*(3-2*B)})(),et=(()=>{if(b<=1e-4)return 1;const K=p/b,B=K<0?0:K>1?1:K;return B*B*(3-2*B)})();return p<b?tu("PolyShape",Da(et)(_.from)(_.to)(O)):p>=L?tu("PolyShape",Da(P)(A.from)(A.to)(O)):tu("CircleShape",R,6)},Wh=e=>t=>n=>r=>i=>o=>u=>s=>a=>{const f=oc(r)(i)(o)(u)(s)(a);if(f.tag==="CircleShape")return e.fillStrokePath(ou(f._1)(f._2))({color:t,flat:!0})({color:n,width:1,lineJoin:He,lineCap:dn});if(f.tag==="PolyShape")return f._1.length>=3?e.fillStrokePath(_h(f._1))({color:t,flat:!0})({color:n,width:1,lineJoin:He,lineCap:dn}):e.Monad0().Applicative0().pure();c()},ic=e=>{const t=kh(e),n=e.Monad0().Applicative0(),r=en(n);return i=>o=>u=>s=>r(a=>{if(a._2.tag==="Travelling"){const f=Ee(a._2._1.target)(i.nodes),g=Ee(a._2._1.source)(i.nodes);if(g.tag==="Just"&&f.tag==="Just"){const d=bo(a._2._1.edge)(i.edges);if(d.tag==="Just")return Wh(e)(u)(s)((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return le(d._1);c()})())(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);if(d.tag==="Nothing")return t(u)(s)(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);c()}return n.pure()}if(a._2.tag==="Filling"){const f=Ee(a._2._1.node)(i.nodes);if(f.tag==="Just")return e.drawRoundedRect((()=>{const g=nu(2)(f._1);return{x:g.x,y:g.y,w:g.w,h:g.h}})())(5)(E("Just",{color:u,flat:!0}))(E("Just",{color:s,width:1,lineJoin:He,lineCap:dn}));if(f.tag==="Nothing")return n.pure();c()}return n.pure()})(tn(o.tokens))},uc=e=>{const t=e.Monad0(),n=t.Bind1(),r=ic(e),i=e.popClip,o=e.popBlend,u=e.popLayer,s=t.Applicative0(),a=en(s);return f=>g=>n.bind(e.pushLayer(ih))(()=>n.bind(e.pushBlend(ch))(()=>n.bind(e.pushClip(Oa(f)(g))($a))(()=>n.bind(r(f)(g)(Kn)(Kn))(()=>n.bind(i)(()=>n.bind(o)(()=>n.bind(u)(()=>n.bind(e.pushLayer(uh))(()=>n.bind(a(d=>{const l=Ee(d._1)(g.nodes);return l.tag==="Just"&&ko(l._1).alpha>0?e.drawRoundedRect({x:d._2.x,y:d._2.y,w:d._2.w,h:d._2.h})(7)(E("Just",{color:Kn,flat:!1}))(T):s.pure()})(tn(f.nodes)))(()=>u)))))))))},sc=e=>{const t=e.Monad0().Bind1(),n=ic(e),r=e.popClip,i=e.popLayer;return o=>u=>s=>t.bind(e.pushLayer(oh))(()=>t.bind(e.pushClip(yh(o)(u)(s))(ah))(()=>t.bind(n(u)(s)(Ze)(Kn))(()=>t.bind(r)(()=>i))))},ac=e=>t=>n=>r=>i=>o=>{const u=oc(e)(t)(n)(r)(i)(o);if(u.tag==="PolyShape")return Eh(u._1);if(u.tag==="CircleShape")return u._1;c()},Ah=e=>{const t=Ya(e),n=e.Monad0(),r=n.Bind1(),i=en(n.Applicative0()),o=Th(e);return u=>s=>a=>f=>g=>d=>l=>_=>{const h=Eo(f)(g)(d)(St(l)(Fa)),p=h.line,m=h.phaseInLabel/.45,N=m<0?0:m>1?1:m,J=_.w,v=_.y,w=_.x,L=w+14,b=_.h,S=v+b/2;return t(Ka(f)(g)(d))(w)(v+b)({x:w+J/2,y:S})(r.bind(i(A=>e.fillPath(ou(A)(1.5))({color:Ze,flat:!0}))(Jh(_)(ac(u)(s)(a)(f)(g)(d))))(()=>r.bind(e.drawRoundedRect({x:w,y:v,w:J,h:b})(3)(E("Just",{color:Ze,flat:!0}))(T))(()=>o({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Kn)(N)(L)(S)(p))))}},cc=e=>{const t=Ah(e),n=e.Monad0(),r=n.Applicative0(),i=Ch(e),o=n.Bind1(),u=en(r),s=e.popLayer;return a=>f=>g=>o.bind(e.pushLayer(sh))(()=>o.bind(u(d=>{if(d._2.tag==="Travelling"){if(d._2._1.labels.length!==0){const l=Ee(d._2._1.target)(a.nodes),_=Ee(d._2._1.source)(a.nodes),h=bo(d._2._1.edge)(a.edges),p=Qa(d._1)(g);if(p.tag==="Just"&&h.tag==="Just"&&_.tag==="Just"&&l.tag==="Just")return t((()=>{if(d._2._1.direction==="Forward")return h._1;if(d._2._1.direction==="Backward")return le(h._1);c()})())(_._1)(l._1)(d._2._1.progress)(d._2._1.holdPre)(d._2._1.holdPost)(d._2._1.labels)(p._1)}return r.pure()}if(d._2.tag==="Filling"&&d._2._1.labels.length!==0){const l=Ee(d._2._1.node)(a.nodes);if(l.tag==="Just")return i(a)(l._1)(d._2._1.progress)(d._2._1.labels);if(l.tag==="Nothing")return r.pure();c()}return r.pure()})(tn(f.tokens)))(()=>s))},zh=e=>{const t=e.Monad0();return n=>r=>i=>o=>u=>s=>a=>{const f=ac(n)(r)(i)(o)(u)(s);return t.Bind1().bind(e.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Eo(o)(u)(s)(St(a)(Fa)).line))(g=>t.Applicative0().pure({x:f.x+14+g/2-g/2-14,y:f.y-6-8-6.6-6,w:g+28,h:25.2}))}},Bh=e=>{const t=e.Monad0(),n=t.Bind1(),r=zh(e),i=t.Applicative0(),o=qr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>qa(Pt(f=>f)(a)))(o(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const f=Ee(a._2._1.target)(u.nodes),g=Ee(a._2._1.source)(u.nodes),d=bo(a._2._1.edge)(u.edges);if(d.tag==="Just"&&g.tag==="Just"&&f.tag==="Just")return n.bind(r((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return le(d._1);c()})())(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(l=>i.pure(E("Just",x(a._1,l))))}return i.pure(T)})(tn(s.tokens)))},fc=e=>{const t=e.Monad0(),n=t.Bind1(),r=Bh(e),i=bh(e);return o=>u=>n.bind(r(o)(u))(s=>n.bind(i(o)(u))(a=>t.Applicative0().pure(ph((()=>{const f=g=>{if(g.tag==="Leaf")return $;if(g.tag==="Node")return Ft("Node",g._1,g._2,g._3,void 0,f(g._5),f(g._6));c()};return vt(k.compare)(bt(ke.foldr,f(s)))})())(s)([...V(fh)((()=>{const f=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return f(g._5,zt("Cons",g._4,f(g._6,d)));c()};return bt(Yt.foldr,f(o.nodes,Qt))})()),...(()=>{const f=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return f(g._5,zt("Cons",g._4,f(g._6,d)));c()};return bt(Yt.foldr,f(a,Qt))})()]))))},$h=e=>{const t=fc(e),n=cc(e);return r=>i=>e.Monad0().Bind1().bind(t(r)(i))(o=>n(r)(i)(o))},So=e=>t=>n=>{const r=fs(t)(n.camera);return{vx:r.x-e.padding,vy:r.y-e.padding-40,vw:r.w+2*e.padding,vh:r.h+2*e.padding+40}},gc=e=>{const t=e.Monad0(),n=t.Bind1();return r=>i=>{if(r==="")return t.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(e.measureText(s)(r))(a=>{const f=i.vy+12*o,g=u+6*o*2,d=a+11*o*2,l=i.vx+i.vw/2;return n.bind(e.drawRoundedRect({x:l-d/2,y:f,w:d,h:g})(g/2)(E("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}))(E("Just",{color:{r:0,g:0,b:0,a:255},width:1*o,lineJoin:He,lineCap:Ba})))(()=>e.drawText({x:l,y:f+g/2,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:ji,baseline:Gr}))})}},Qh=e=>{const t=e.Monad0().Bind1(),n=tc(e),r=rc(e),i=ec(e),o=Xa(e),u=sc(e),s=uc(e),a=$h(e),f=gc(e);return g=>d=>l=>{const _=So(g)(d)(l);return t.bind(n(g.transparentBg)(_))(()=>t.bind(r(d)(l))(()=>t.bind(i(g.halftoneShadows)(d)(l))(()=>t.bind(o(d)(l))(()=>t.bind(u(_)(d)(l))(()=>t.bind(s(d)(l))(()=>t.bind(a(d)(l))(()=>t.bind(g.watermark===""?e.Monad0().Applicative0().pure():e.drawText({x:_.vx+6,y:_.vy+6,content:g.watermark,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:wo,baseline:za}))(()=>f(l.frameTitle)(_)))))))))}},qh=e=>{const t=e.Monad0().Bind1(),n=tc(e),r=rc(e),i=ec(e),o=Xa(e),u=sc(e),s=uc(e),a=cc(e),f=gc(e);return g=>d=>l=>_=>{const h=So(g)(d)(l);return t.bind(n(g.transparentBg)(h))(()=>t.bind(r(d)(l))(()=>t.bind(i(g.halftoneShadows)(d)(l))(()=>t.bind(o(d)(l))(()=>t.bind(u(h)(d)(l))(()=>t.bind(s(d)(l))(()=>t.bind(a(d)(l)(_))(()=>t.bind(g.watermark===""?e.Monad0().Applicative0().pure():e.drawText({x:h.vx+6,y:h.vy+6,content:g.watermark,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:wo,baseline:za}))(()=>f(l.frameTitle)(h)))))))))}},_c=e=>t=>n=>{const r=lt.compare(e)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),o=lt.compare(t)(i);if(o==="LT"||o==="EQ")return t;if(o==="GT")return i;c()},Hh=fc(Sa),Yh=qh(Sa),Vh=e=>{const t=e.vx+e.vw-4,n=e.vy+e.vh-4,r=e.vx+4,i=e.vy+4,o=u=>{if(u.tag==="Leaf")return $;if(u.tag==="Node")return Ft("Node",u._1,u._2,u._3,{...u._4,x:_c(r)(t-u._4.w)(u._4.x),y:_c(i)(n-u._4.h)(u._4.y)},o(u._5),o(u._6));c()};return o},Oh=e=>t=>n=>r=>i=>o=>{const u={padding:24,transparentBg:!1,halftoneShadows:!0,watermark:""},s=D0(e)(t);return()=>{const a=s(),f=Hh(n)(r)(a)(),g=k0(i)(Vh(So(u)(n)(r))(f))(o);return Yh(u)(n)(r)(g.applied)(a)(),g.springs}},ln=e=>"rgb("+ue(e.r)+","+ue(e.g)+","+ue(e.b)+")",Po=_r(fr("Fixed",gr(0)(20)(4))),Fh=e=>"translate("+Po(e.tx)+","+Po(e.ty)+") scale("+Po(e.sx)+","+Po(e.sy)+")",Nt=_r(fr("Fixed",gr(0)(20)(2))),iu=e=>{const t=[];let n=0;for(;n<e.length;){const r=n,i=r>=0&&r<e.length?E("Just",e[r]):T;if(i.tag==="Nothing"){n=e.length;continue}if(i.tag==="Just"){if(i._1===1){t.push("M"),t.push(Nt((()=>{const o=r+1|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+2|0;return o>=0&&o<e.length?e[o]:0})())),n=r+3|0;continue}if(i._1===2){t.push("L"),t.push(Nt((()=>{const o=r+1|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+2|0;return o>=0&&o<e.length?e[o]:0})())),n=r+3|0;continue}if(i._1===3){t.push("Q"),t.push(Nt((()=>{const o=r+1|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+2|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+3|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+4|0;return o>=0&&o<e.length?e[o]:0})())),n=r+5|0;continue}if(i._1===4){t.push("C"),t.push(Nt((()=>{const o=r+1|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+2|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+3|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+4|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+5|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+6|0;return o>=0&&o<e.length?e[o]:0})())),n=r+7|0;continue}if(i._1===5){t.push("Z"),n=r+1|0;continue}n=e.length;continue}c()}return Ti(" ")(t)},Xh={map:e=>t=>n=>{const r=t(n);return()=>{const i=r();return e(i)}}},Uh=(()=>{const e=cn("&")("&amp;"),t=cn("<")("&lt;"),n=(()=>{const r=cn(">")("&gt;"),i=(()=>{const o=cn('"')("&quot;");return u=>o(r(u))})();return o=>i(t(o))})();return r=>n(e(r))})(),xe=e=>t=>{const n=t.maskDepth;return()=>{n.value===0&&t.out.push(e)}},dc={apply:e=>t=>n=>{const r=e(n),i=t(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>Xh},Kh={bind:e=>t=>n=>{const r=e(n);return()=>{const i=r();return t(i)(n)()}},Apply0:()=>dc},Zh={pure:e=>t=>()=>e,Apply0:()=>dc},jh={Applicative0:()=>Zh,Bind1:()=>Kh},tp=e=>t=>'<defs><pattern id="'+e+'" x="0" y="0" width="'+Nt(t.tile)+'" height="'+Nt(t.tile)+'" patternUnits="userSpaceOnUse">'+(t.bgColor.a===0?"":'<rect width="'+Nt(t.tile)+'" height="'+Nt(t.tile)+'" fill="'+ln(t.bgColor)+'" fill-opacity="'+Nt(ct(t.bgColor.a)/255)+'"/>')+'<circle cx="'+Nt(t.tile/2)+'" cy="'+Nt(t.tile/2)+'" r="'+Nt(t.dotRadius)+'" fill="'+ln(t.dotColor)+'"/></pattern></defs><rect x="'+Nt(t.viewport.vx)+'" y="'+Nt(t.viewport.vy)+'" width="'+Nt(t.viewport.vw)+'" height="'+Nt(t.viewport.vh)+'" fill="url(#'+e+')"/>',lc=e=>t=>'<path d="'+iu(e)+'" fill="'+ln(t)+'" fill-opacity="'+Nt(ct(t.a)/255)+'"/>',ep=e=>t=>n=>r=>'<rect x="'+Nt(e.x)+'" y="'+Nt(e.y)+'" width="'+Nt(e.w)+'" height="'+Nt(e.h)+'" rx="'+Nt(t)+'"'+(()=>{if(n.tag==="Just")return' fill="'+ln(n._1.color)+'" fill-opacity="'+Nt(ct(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';c()})()+(()=>{if(r.tag==="Just")return' stroke="'+ln(r._1.color)+'" stroke-opacity="'+Nt(ct(r._1.color.a)/255)+'" stroke-width="'+Nt(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";c()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";c()})()+'"';if(r.tag==="Nothing")return"";c()})()+"/>",hc=e=>t=>'<path d="'+iu(e)+'" fill="none" stroke="'+ln(t.color)+'" stroke-opacity="'+Nt(ct(t.color.a)/255)+'" stroke-width="'+Nt(t.width)+'" stroke-linejoin="'+(()=>{if(t.lineJoin==="RoundJoin")return"round";if(t.lineJoin==="BevelJoin")return"bevel";if(t.lineJoin==="MiterJoin")return"miter";c()})()+'" stroke-linecap="'+(()=>{if(t.lineCap==="ButtCap")return"butt";if(t.lineCap==="RoundCap")return"round";if(t.lineCap==="SquareCap")return"square";c()})()+'"/>',np=e=>'<text x="'+Nt(e.x)+'" y="'+Nt(e.y)+'"'+(()=>{if(e.baseline==="BaselineTop")return' dy="0.8em"';if(e.baseline==="BaselineMiddle")return' dy="0.32em"';if(e.baseline==="BaselineAlphabetic"||e.baseline==="BaselineBottom")return"";c()})()+' fill="'+ln(e.color)+'" fill-opacity="'+Nt(ct(e.color.a)/255)+'" font-size="'+Nt(e.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+ue(e.font.weight)+'" text-anchor="'+(()=>{if(e.align==="AlignLeft")return"start";if(e.align==="AlignCenter")return"middle";if(e.align==="AlignRight")return"end";c()})()+'">'+Uh(so(e.content))+"</text>",rp=Qh({fillPath:e=>t=>xe(lc(e)(t.color)),strokePath:e=>t=>xe(hc(e)(t)),fillStrokePath:e=>t=>n=>xe(lc(e)(t.color)+hc(e)(n)),drawRoundedRect:e=>t=>n=>r=>xe(ep(e)(t)(n)(r)),drawText:e=>xe(np(e)),pushTransform:e=>xe((()=>{const t='transform="'+Fh(e)+'"';return t===""?"<g>":"<g "+t+">"})()),popTransform:xe("</g>"),pushClip:e=>t=>n=>{const r=n.clipCounter;return()=>{const i=r.value;n.clipCounter.value=i+1|0;const o="clip"+ue(i);return xe((()=>{const u='clip-path="url(#'+o+')"';return'<defs><clipPath id="'+o+'"><path d="'+iu(e)+'"'+(()=>{if(t==="EvenOdd")return' clip-rule="evenodd"';if(t==="NonZero")return"";c()})()+"/></clipPath></defs>"+(u===""?"<g>":"<g "+u+">")})())(n)()}},popClip:xe("</g>"),pushBlend:e=>xe((()=>{const t=(()=>{if(e==="Normal")return'style="mix-blend-mode: normal"';if(e==="Difference")return'style="mix-blend-mode: difference"';c()})();return t===""?"<g>":"<g "+t+">"})()),popBlend:xe("</g>"),pushAlpha:e=>xe((()=>{const t='opacity="'+Nt(e)+'"';return t===""?"<g>":"<g "+t+">"})()),popAlpha:xe("</g>"),pushLayer:e=>t=>{const n=(()=>{if(e==="LayerNodeMask"){const r=t.maskDepth;return()=>{const i=r.value;t.maskDepth.value=i+1|0}}return()=>{}})();return()=>{n(),t.out.push("<g>")}},popLayer:e=>{const t=e.maskDepth;return()=>{const n=t.value,r=n-1|0;n>0&&(e.maskDepth.value=r),e.out.push("</g>")}},setViewport:e=>t=>()=>{},clearBackground:e=>t=>xe('<rect x="'+Nt(t.viewport.vx)+'" y="'+Nt(t.viewport.vy)+'" width="'+Nt(t.viewport.vw)+'" height="'+Nt(t.viewport.vh)+'" fill="'+ln(e)+'" opacity="'+Nt(ct(e.a)/255)+'"/>')(t),backgroundDots:e=>t=>{const n=t.patternCounter;return()=>{const r=n.value;return t.patternCounter.value=r+1|0,xe(tp("bg-dots-"+ue(r))(e))(t)()}},measureText:e=>t=>n=>{const r=Ea(e.family)(e.size)(e.weight)(so(t));return()=>r},Monad0:()=>jh}),op=e=>t=>{const n={padding:24,transparentBg:!1,halftoneShadows:!0,watermark:""},r=So(n)(e)(t);return{viewBox:Nt(r.vx)+" "+Nt(r.vy)+" "+Nt(r.vw)+" "+Nt(r.vh),body:(()=>{const i=[],o={value:0},u={value:0},s={value:0};return rp(n)(e)(t)({out:i,maskDepth:o,clipCounter:u,patternCounter:s,viewport:r})(),Ti("")(i)})()}},Wr=e=>({bind:t=>n=>r=>e.Bind1().bind(t(r))(i=>n(i._1)(i._2)),Apply0:()=>pc(e)}),pc=e=>{const t=e.Bind1().Apply0().Functor0(),n={map:r=>i=>o=>t.map(u=>x(r(u._1),u._2))(i(o))};return{apply:(()=>{const r=Wr(e);return i=>o=>r.bind(i)(u=>r.bind(o)(s=>Ar(e).pure(u(s))))})(),Functor0:()=>n}},Ar=e=>({pure:t=>n=>e.Applicative0().pure(x(t,n)),Apply0:()=>pc(e)}),ip=e=>{const t={Applicative0:()=>Ar(e),Bind1:()=>Wr(e)};return{state:n=>r=>e.Applicative0().pure(n(r)),Monad0:()=>t}},uu=(e,t)=>({tag:e,_1:t}),En=(e,t)=>({tag:e,_1:t}),be=ip(un),Bt=Wr(un),Ce=be.state(e=>x(e,e)),nn=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},hn=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},_e=Ar(un),up=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},sp=(()=>{const e=Ie.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return E("Just",x(t._1,t._2));c()});return t=>e((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._3,n(r._6,i)));c()};return n(t,Qt)})())})(),ap=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},su=e=>t=>n=>y(r=>i=>e.Bind1().bind(r)(o=>t(o)(i)))(e.Applicative0().pure(n)),cp=y(e=>t=>Z(k)(t)()(e))($),fp=(()=>{const e=(t=>n=>{let r=t,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=Z(k)(a._1)()(s),i=a._2;continue}c()}return u})($);return t=>e((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._3,n(r._6,i)));c()};return n(t,Qt)})())})(),mc=jc(_e)(At),gp=e=>uu("Par",e),yc=e=>uu("Seq",e),_p=e=>t=>n=>{const r=Dn(Xt,T,i=>i._1===e,n);if(r.tag==="Just"){const i=Gn(Xt,T,r._1,x(e,t),n);if(i.tag==="Nothing")return n;if(i.tag==="Just")return i._1;c()}if(r.tag==="Nothing")return de(n)(x(e,t));c()},dp=e=>t=>V(n=>n._1===e?x(n._1,{...n._2,label:E("Just",t)}):x(n._1,n._2)),Ge=e=>be.state(t=>x(void 0,(()=>{if(t.error.tag==="Just")return t;if(t.error.tag==="Nothing")return{...t,error:E("Just",{msg:e,line:t.currentLine,column:t.currentColumn})};c()})())),lp=e=>Bt.bind(Ce)(t=>{const n=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ue(t.kfCounter);if(sn(i=>i.id===n,t.keyframes))return Ge("duplicate frame name "+n);const r={...t,keyframes:de(t.keyframes)({id:n,nodes:t.currNodes,edges:t.currEdges}),kfCounter:t.kfCounter+1|0,currentKf:E("Just",n)};return be.state(i=>x(void 0,r))}),hp=e=>t=>{const n=t.from+"->"+t.to,r=t.newFrom+"->"+t.newTo,i=kt("Left","cannot repoint "+t.from+"\u2192"+t.to+": edge does not exist"),o=nn(n)(e.currEdges)?kt("Right",void 0):i;return(()=>{if(o.tag==="Left"){const u=o._1;return s=>kt("Left",u)}if(o.tag==="Right"){const u=o._1;return s=>s(u)}c()})()(()=>{const u="cannot repoint "+t.from+"\u2192"+t.to+" to "+t.newFrom+"\u2192"+t.newTo+": unknown node "+t.newFrom;if(!hn(t.newFrom)(e.currNodes))return kt("Left",u);const s="cannot repoint "+t.from+"\u2192"+t.to+" to "+t.newFrom+"\u2192"+t.newTo+": unknown node "+t.newTo;if(!hn(t.newTo)(e.currNodes))return kt("Left",s);const a="cannot repoint "+t.from+"\u2192"+t.to+" to "+t.newFrom+"\u2192"+t.newTo+": target edge already exists";return n!==r&&nn(r)(e.currEdges)?kt("Left",a):kt("Right",{nextCurrEdges:Z(k)(r)()(ar(k)(n)(e.currEdges)),newId:r,newEdge:{id:r,from:{node:t.newFrom,port:T},to:{node:t.newTo,port:T}}})})},pp={graphNodes:[],graphEdges:$,currNodes:$,currEdges:$,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:T,currentLine:0,currentColumn:0,error:T},Jc=e=>t=>Bt.bind(Ce)(n=>{const r="ev-"+ue(n.eventCounter);return Bt.bind((()=>{const i={...n,eventCounter:n.eventCounter+1|0};return be.state(o=>x(void 0,i))})())(()=>_e.pure({events:[{id:r,kind:t,when:e}],firstId:E("Just",r),lastId:E("Just",r)}))}),mp=e=>t=>{if(t.tag==="Token"){const n=t._1;return Bt.bind(Ce)(r=>{const i=!hn(n.from)(r.currNodes),o=!hn(n.to)(r.currNodes);if(i||o)return Bt.bind(Ge(i?o?"token references unknown node: "+n.from+", "+n.to:"token references unknown node: "+n.from:o?"token references unknown node: "+n.to:"token references unknown node: "))(()=>_e.pure({events:[],firstId:T,lastId:T}));const u=n.to+"->"+n.from,s=n.from+"->"+n.to;return nn(s)(r.currEdges)?Jc(e)(ns("SendToken",{from:n.from,to:n.to,edge:s,direction:Gg,labels:n.labels})):nn(u)(r.currEdges)?Jc(e)(ns("SendToken",{from:n.from,to:n.to,edge:u,direction:Mg,labels:n.labels})):Bt.bind(Ge("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>_e.pure({events:[],firstId:T,lastId:T}))})}return _e.pure({events:[],firstId:T,lastId:T})},yp=e=>Pt(t=>up(t)(e.graphEdges))(bt(ir,sp(e.currEdges))),Jp=e=>t=>{const n=at(i=>i.from.node===t.id||i.to.node===t.id,yp(e)),r=su(Bc)(i=>o=>{const u=o.from+"->"+t.id,s=t.id+"->"+o.to,a=o.from+"->"+o.to,f="via "+o.from+" "+o.to+": no edge "+o.from+"\u2192"+t.id;if(!nn(u)(e.currEdges))return kt("Left",f);const g="via "+o.from+" "+o.to+": no edge "+t.id+"\u2192"+o.to;if(!nn(s)(e.currEdges))return kt("Left",g);const d="via "+o.from+" "+o.to+": would create "+o.from+"\u2192"+o.to+" but it already exists";return nn(a)(e.currEdges)||ap(a)(i.synthesized)?kt("Left",d):kt("Right",{consumed:Z(k)(u)()(Z(k)(s)()(i.consumed)),synthesized:Z(k)(a)({id:a,from:{node:o.from,port:T},to:{node:o.to,port:T}})(i.synthesized)})})({consumed:$,synthesized:$})(t.via);return(()=>{if(r.tag==="Left"){const i=r._1;return o=>kt("Left",i)}if(r.tag==="Right"){const i=r._1;return o=>o(i)}c()})()(i=>{const o=i.consumed,u=at(s=>!nn(s.id)(o),n);return u.length===0?kt("Right",{nextCurrEdges:Ne(k.compare,me,Xe(k.compare,e.currEdges,cp(V(s=>s.id)(n))),fp((()=>{const s=a=>{if(a.tag==="Leaf")return $;if(a.tag==="Node")return Ft("Node",a._1,a._2,a._3,void 0,s(a._5),s(a._6));c()};return s(i.synthesized)})())),synthesized:i.synthesized}):kt("Left","cannot delete node "+t.id+": still connected ("+Ti(", ")(V(s=>s.from.node+"\u2192"+s.to.node)(u))+"). Use -edge to drop them or `via a b` to merge "+t.id+"'s endpoints.")})},Nc=e=>{if(e.tag==="Leaf")return[e._1];if(e.tag==="Par"||e.tag==="Seq")return St(e._1)(Nc);c()},Np=e=>({nodes:V($r)(e.graphNodes),edges:(()=>{const t=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return t(n._5,zt("Cons",n._4,t(n._6,r)));c()};return bt(Yt.foldr,t(e.graphEdges,Qt))})(),constraints:[]}),xp=e=>{if(e.tag==="AddNode"){const t=e._1;return be.state(n=>x(void 0,{...n,graphNodes:_p(t.id)({id:t.id,size:x(1,1),ports:[],label:E("Just",t.label)})(n.graphNodes),currNodes:Z(k)(t.id)()(n.currNodes)}))}if(e.tag==="DelNode"){const t=e._1;return Bt.bind(Ce)(n=>{if(!hn(t.id)(n.currNodes))return Ge("cannot delete node "+t.id+": does not exist");const r=Jp(n)(t);if(r.tag==="Left")return Ge(r._1);if(r.tag==="Right"){const i=r._1;return be.state(o=>x(void 0,{...o,currNodes:ar(k)(t.id)(o.currNodes),currEdges:i.nextCurrEdges,graphEdges:Ne(k.compare,me,i.synthesized,o.graphEdges)}))}c()})}if(e.tag==="ModNode"){const t=e._1;return Bt.bind(Ce)(n=>{if(!hn(t.id)(n.currNodes))return Ge("cannot modify node "+t.id+": does not exist");if(t.label.tag==="Just"){const r=t.label._1;return be.state(i=>x(void 0,{...i,graphNodes:dp(t.id)(r)(i.graphNodes)}))}if(t.label.tag==="Nothing")return _e.pure();c()})}if(e.tag==="AddEdge"){const t=e._1;return Bt.bind(Ce)(n=>{const r=!hn(t.from)(n.currNodes),i=!hn(t.to)(n.currNodes);if(r||i)return Ge("cannot add edge "+t.from+"\u2192"+t.to+": unknown node "+(r?i?t.from+", "+t.to:t.from:i?t.to:""));const o=t.from+"->"+t.to;return be.state(u=>x(void 0,{...u,graphEdges:Z(k)(o)({id:o,from:{node:t.from,port:T},to:{node:t.to,port:T}})(u.graphEdges),currEdges:Z(k)(o)()(u.currEdges)}))})}if(e.tag==="DelEdge"){const t=e._1;return Bt.bind(Ce)(n=>{const r=t.from+"->"+t.to;return nn(r)(n.currEdges)?be.state(i=>x(void 0,{...i,currEdges:ar(k)(r)(i.currEdges)})):Ge("cannot delete edge "+t.from+"\u2192"+t.to+": does not exist")})}if(e.tag==="RepointEdge"){const t=e._1;return Bt.bind(Ce)(n=>{const r=hp(n)(t);if(r.tag==="Left")return Ge(r._1);if(r.tag==="Right"){const i=r._1;return be.state(o=>x(void 0,{...o,currEdges:i.nextCurrEdges,graphEdges:Z(k)(i.newId)(i.newEdge)(o.graphEdges)}))}c()})}return _e.pure()},vp=e=>Bt.bind(be.state(t=>x(void 0,{...t,currentLine:e.line,currentColumn:e.column})))(()=>xp(e.op)),Tp=e=>t=>Bt.bind(mc(vp)(t))(()=>Bt.bind(Ce)(n=>{const r=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ue(n.kfCounter);if(sn(o=>o.id===r,n.keyframes))return Ge("duplicate frame name "+r);const i={...n,keyframes:de(n.keyframes)({id:r,nodes:n.currNodes,edges:n.currEdges}),kfCounter:n.kfCounter+1|0,currentKf:E("Just",r),scenes:(()=>{if(n.currentKf.tag==="Nothing")return n.scenes;if(n.currentKf.tag==="Just")return de(n.scenes)(rs("Structural",{from:n.currentKf._1,to:r,focus:T}));c()})()};return be.state(o=>x(void 0,i))})),wp=e=>t=>{const n=Ht(r=>T,r=>i=>E("Just",{head:r,tail:i}),t);if(n.tag==="Nothing")return _e.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return Bt.bind(zr(e)(n._1.head))(i=>Bt.bind(su({Applicative0:()=>Ar(un),Bind1:()=>Wr(un)})(o=>u=>Bt.bind(zr((()=>{if(o.lastId.tag==="Just")return pi("After",o.lastId._1);if(o.lastId.tag==="Nothing")return e;c()})())(u))(s=>_e.pure({events:[...o.events,...s.events],firstId:(()=>{if(o.firstId.tag==="Just")return E("Just",o.firstId._1);if(o.firstId.tag==="Nothing")return s.firstId;c()})(),lastId:(()=>{if(s.lastId.tag==="Just")return E("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return o.lastId;c()})()})))(i)(r))(o=>_e.pure(o)))}c()},bp=e=>t=>{const n=Ht(r=>T,r=>i=>E("Just",{head:r,tail:i}),t);if(n.tag==="Nothing")return _e.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return Bt.bind(zr(e)(n._1.head))(i=>Bt.bind(kp((()=>{if(i.firstId.tag==="Just")return pi("With",i.firstId._1);if(i.firstId.tag==="Nothing")return e;c()})())(r))(o=>_e.pure({events:[...i.events,...o.events],firstId:i.firstId,lastId:(()=>{if(i.lastId.tag==="Just")return E("Just",i.lastId._1);if(i.lastId.tag==="Nothing")return o.lastId;c()})()})))}c()},zr=e=>t=>{if(t.tag==="Leaf"){const n=t._1;return Bt.bind(be.state(r=>x(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>mp(e)(n.op))}if(t.tag==="Seq")return wp(e)(t._1);if(t.tag==="Par")return bp(e)(t._1);c()},kp=e=>su({Applicative0:()=>Ar(un),Bind1:()=>Wr(un)})(t=>n=>Bt.bind(zr(e)(n))(r=>_e.pure({events:[...t.events,...r.events],firstId:(()=>{if(t.firstId.tag==="Just")return E("Just",t.firstId._1);if(t.firstId.tag==="Nothing")return r.firstId;c()})(),lastId:(()=>{if(r.lastId.tag==="Just")return E("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return t.lastId;c()})()})))({events:[],firstId:T,lastId:T}),Lp=e=>Bt.bind(Ce)(t=>{if(t.currentKf.tag==="Nothing")return Ge("flow ops before any structural frame");if(t.currentKf.tag==="Just"){const n=t.currentKf._1;return Bt.bind(zr(Dg)(e))(r=>Bt.bind(Ce)(i=>{const o={...i,scenes:de(i.scenes)(rs("DataFlow",{keyframe:n,events:r.events,focus:T}))};return be.state(u=>x(void 0,o))}))}c()}),Ep=e=>Bt.bind(Ce)(t=>{if(t.error.tag==="Just")return _e.pure();if(t.error.tag==="Nothing"){const n=Nc(e.ops),r=at(o=>o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge",n),i=at(o=>!(o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge"),n);return Bt.bind((()=>{const o=Tp(e.name)(r);return r.length!==0?o:_e.pure()})())(()=>Bt.bind((()=>{const o=lp(e.name);return r.length===0&&i.length!==0?o:_e.pure()})())(()=>{const o=Lp(e.ops);return i.length!==0?o:_e.pure()}))}c()}),Cp=e=>Bt.bind(mc(Ep)(e.frames))(()=>Bt.bind(Ce)(t=>_e.pure((()=>{if(t.error.tag==="Just")return kt("Left",t.error._1);if(t.error.tag==="Nothing")return kt("Right",{seed:e.seed,graph:Np(t),keyframes:t.keyframes,scenes:t.scenes});c()})())))(pp)._1,Zn=(e,t)=>({tag:"ParseError",_1:e,_2:t}),z=(e,t,n)=>({tag:"ParseState",_1:e,_2:t,_3:n}),Ro=(e,t,n)=>({tag:e,_1:t,_2:n}),Sp=e=>Ro("More",e),Pp=e=>Ro("Lift",e),xc={map:e=>t=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,f)=>r(g=>u(a,e(f)))))},Rp={alt:e=>t=>(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(f=>e(z(s,a,!1),r,i,(g,d)=>{const l=g._3;return r(_=>l?o(g,d):t(n,r,i,o,u))},u))},Functor0:()=>xc},Ip=e=>{const t=e.Monad0();return n=>r=>{const i=o=>{let u=o,s=!0,a;for(;s;){const f=u();if(f.tag==="More"){u=f._1;continue}if(f.tag==="Lift"){s=!1,a=t.Bind1().Apply0().Functor0().map(ku)(f._1);continue}if(f.tag==="Stop"){s=!1,a=t.Applicative0().pure(or("Done",x(f._2,f._1)));continue}c()}return a};return e.tailRecM(i)(o=>r(n,Sp,Pp,(u,s)=>Ro("Stop",u,kt("Left",s)),(u,s)=>Ro("Stop",u,kt("Right",s))))}},vc=(e,t,n,r,i)=>i(e,e._2),Dp={index:0,line:1,column:1},Gp=(e=>{const t=Ip(e);return n=>r=>e.Monad0().Bind1().Apply0().Functor0().map(Qr)(t(z(n,Dp,!1))(r))})(Fc),Tc={apply:e=>t=>(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,f)=>r(g=>{const d=n._3&&!a._3?z(a._1,a._2,!0):a;return t(d,r,i,o,(l,_)=>r(h=>u(d._3&&!l._3?z(l._1,l._2,!0):l,f(_))))}))),Functor0:()=>xc},wc={pure:e=>(t,n,r,i,o)=>o(t,e),Apply0:()=>Tc},Mp={bind:e=>t=>(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,f)=>r(g=>t(f)(n._3&&!a._3?z(a._1,a._2,!0):a,r,i,o,u)))),Apply0:()=>Tc},Wp={Applicative0:()=>wc,Bind1:()=>Mp},Io=e=>(t,n,r,i,o)=>n(u=>vc(t,n,r,i,(s,a)=>n(f=>i(t._3&&!s._3?z(s._1,s._2,!0):s,Zn(e,a))))),Ap={empty:Io("No alternative"),Alt0:()=>Rp},zp={Applicative0:()=>wc,Plus1:()=>Ap},Pe=(e=>t=>{const n=t.Plus1().Alt0(),r=t.Applicative0();return i=>e.tailRecM(o=>e.Monad0().Bind1().bind(n.alt(n.Functor0().map(ku)(i))(r.pure(or("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return or("Loop",zt("Cons",u._1,o));if(u.tag==="Done")return or("Done",(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){f=zt("Cons",h._1,_),g=h._2;continue}c()}return l})(Qt)(o));c()})())))(Qt)})({tailRecM:e=>t=>(n,r,i,o,u)=>{const s=(a,f,g)=>e(f)(a,r,i,o,(d,l)=>{const _=a._3&&!d._3?z(d._1,d._2,!0):d;if(l.tag==="Loop")return g===0?r(h=>s(_,l._1,30)):s(_,l._1,g-1|0);if(l.tag==="Done")return u(_,l._1);c()});return s(n,t,30)},Monad0:()=>Wp})(zp),Lt=e=>t=>{const n=Io("Expected "+t);return(r,i,o,u,s)=>{const a=r._1,f=r._2;return i(g=>e(z(a,f,!1),i,o,(d,l)=>{const _=d._3;return i(h=>_?u(d,l):n(r,i,o,u,s))},s))}},au=e=>(t,n,r,i,o)=>{const u=t._3,s=t._1,a=t._2;return n(f=>{const g=(d,l)=>{const _=d._3;return n(h=>_?i(z(d._1,d._2,u),l):o(t,void 0))};return n(d=>n(l=>e(z(s,a,!1),n,r,(_,h)=>g(z(_._1,_._2,!1),h),(_,h)=>n(p=>n(m=>Io("Negated parser succeeded")(_,n,r,g,(N,J)=>n(v=>o(_._3&&!N._3?z(N._1,N._2,!0):N,J))))))))})},Bp=e=>{const t=e.foldr(n=>r=>{if(r.tag==="Nothing")return E("Just",n);if(r.tag==="Just")return E("Just",(i,o,u,s,a)=>{const f=i._1,g=i._2;return o(d=>n(z(f,g,!1),o,u,(l,_)=>{const h=l._3;return o(p=>h?s(l,_):r._1(i,o,u,s,a))},a))});c()})(T);return n=>{const r=t(n);if(r.tag==="Nothing")return Io("No alternative");if(r.tag==="Just")return r._1;c()}},$p=e=>t=>n=>(r,i,o,u,s)=>i(a=>i(f=>i(g=>i(d=>e(r,i,o,u,(l,_)=>i(h=>i(p=>{const m=r._3&&!l._3?z(l._1,l._2,!0):l;return n(m,i,o,u,(N,J)=>i(v=>{const w=m._3&&!N._3?z(N._1,N._2,!0):N;return i(L=>i(b=>{const S=r._3&&!w._3?z(w._1,w._2,!0):w;return t(S,i,o,u,(A,O)=>i(j=>s(S._3&&!A._3?z(A._1,A._2,!0):A,J)))}))}))}))))))),cu=e=>t=>n=>{if(t===10)return{index:e.index+1|0,line:e.line+1|0,column:1};if(t===13){const r=J_()(n);return r.tag==="Just"&&r._1===10?{index:e.index+1|0,line:e.line,column:e.column}:{index:e.index+1|0,line:e.line+1|0,column:1}}return t===9?{index:e.index+1|0,line:e.line,column:(e.column+8|0)-Oo(e.column-1|0)(8)|0}:{index:e.index+1|0,line:e.line,column:e.column+1|0}},Qp=e=>t=>n=>{let r=e,i=t,o=n,u=!0,s;for(;u;){const a=r,f=i,g=o,d=to(f);if(d.tag==="Nothing"){u=!1,s=a;continue}if(d.tag==="Just"){r=d._1.tail===""?cu(a)(d._1.head)(g):cu(a)(d._1.head)(d._1.tail),i=d._1.tail,o=g;continue}c()}return s},Ot=e=>(t,n,r,i,o)=>{const u=to(t._1);if(u.tag==="Nothing")return i(t,Zn("Unexpected EOF",t._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return i(t,Zn("Expected Char",t._2));if(u._1.head>=0&&u._1.head<=65535){const s=gs(u._1.head);return e(s)?o(z(u._1.tail,cu(t._2)(u._1.head)(u._1.tail),!0),s):i(t,Zn("Predicate unsatisfied",t._2))}}c()},bc=(e,t,n,r,i)=>e._1===""?i(z(e._1,e._2,!0),void 0):r(e,Zn("Expected EOF",e._2)),qp=e=>(t,n,r,i,o)=>{const u=e(t._1);if(u.tag==="Left")return i(t,Zn(u._1,t._2));if(u.tag==="Right")return o(z(u._1.remainder,Qp(t._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);c()},jn=e=>qp(t=>{const n=wg(e)(t);return n.tag==="Just"?kt("Right",{value:e,consumed:e,remainder:n._1}):kt("Left","Expected "+Dc(e))}),Hp=Ot(e=>!0),kc=Bp(At),Lc=(()=>{const e=Ot(t=>t===" "||t===" "||t===`
8
- `||t==="\r");return(t,n,r,i,o)=>n(u=>e(t,n,r,i,(s,a)=>n(f=>o(t._3&&!s._3?z(s._1,s._2,!0):s,void 0))))})(),fu=(e,t,n,r,i)=>t(o=>jn("#")(e,t,n,r,(u,s)=>t(a=>{const f=Pe(Ot(d=>d!==`
9
- `)),g=e._3&&!u._3?z(u._1,u._2,!0):u;return t(d=>f(g,t,n,r,(l,_)=>t(h=>i(g._3&&!l._3?z(l._1,l._2,!0):l,void 0))))}))),Yp=Lt((()=>{const e=Lt(Ot(n=>n==="}"))("'}'"),t=Ot(n=>n===`
10
- `||n==="\r");return(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(f=>r(g=>e(z(s,a,!1),r,i,(d,l)=>r(_=>{const h=n._1,p=n._2;return r(m=>r(N=>fu(z(h,p,!1),r,i,(J,v)=>{const w=J._3;return r(L=>{if(w)return o(J,v);const b=n._1,S=n._2;return r(A=>r(O=>t(z(b,S,!1),r,i,(j,R)=>{const P=j._3;return r(et=>P?o(j,R):bc(n,r,i,o,u))},(j,R)=>r(P=>u(j,void 0)))))})},(J,v)=>r(w=>u(J,void 0)))))}),(d,l)=>r(_=>u(z(s,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),Re=(()=>{const e=Pe((t,n,r,i,o)=>{const u=t._1,s=t._2;return n(a=>Lc(z(u,s,!1),n,r,(f,g)=>{const d=f._3;return n(l=>d?i(f,g):fu(t,n,r,i,o))},o))});return(t,n,r,i,o)=>n(u=>e(t,n,r,i,(s,a)=>n(f=>o(t._3&&!s._3?z(s._1,s._2,!0):s,void 0))))})(),Me=(e,t,n,r,i)=>t(o=>{const u=(f,g)=>t(d=>Re(e._3&&!f._3?z(f._1,f._2,!0):f,t,n,r,i)),s=e._1,a=e._2;return t(f=>Lc(z(s,a,!1),t,n,(g,d)=>{const l=g._3;return t(_=>l?r(g,d):fu(e,t,n,r,u))},u))}),Ec=(()=>{const e=Lt(Ot(t=>t==="|"))("'|'");return(t,n,r,i,o)=>n(u=>e(t,n,r,i,(s,a)=>n(f=>{const g=Pe(Ot(l=>l!=="|")),d=t._3&&!s._3?z(s._1,s._2,!0):s;return n(l=>g(d,n,r,i,(_,h)=>n(p=>{const m=Lt(Lt(Ot(J=>J==="|"))("'|'"))("closing '|'"),N=d._3&&!_._3?z(_._1,_._2,!0):_;return n(J=>m(N,n,r,i,(v,w)=>n(L=>o(N._3&&!v._3?z(v._1,v._2,!0):v,zn(bt(Yt.foldr,h))))))})))})))})(),Do=Ot(e=>e>="a"&&e<="z"||e>="A"&&e<="Z"),Cn=(()=>{const e=Pe(Ot(t=>t===" "||t===" "));return(t,n,r,i,o)=>n(u=>e(t,n,r,i,(s,a)=>n(f=>o(t._3&&!s._3?z(s._1,s._2,!0):s,void 0))))})(),Vp=(()=>{const e=Lt(Ot(t=>t==="\\"))("'\\\\'");return(t,n,r,i,o)=>n(u=>e(t,n,r,i,(s,a)=>n(f=>{const g=t._3&&!s._3?z(s._1,s._2,!0):s;return n(d=>Hp(g,n,r,i,(l,_)=>n(h=>o(g._3&&!l._3?z(l._1,l._2,!0):l,_==="n"?`
11
- `:_==="t"?" ":_==="r"?"\r":_))))})))})(),Op=(()=>{const e=Ot(t=>t!=='"'&&t!=="\\"&&t!==`
12
- `);return(t,n,r,i,o)=>{const u=t._1,s=t._2;return n(a=>Vp(z(u,s,!1),n,r,(f,g)=>n(d=>e(t,n,r,i,o)),o))}})(),gu=(()=>{const e=Lt(Ot(t=>t==='"'))(`'"'`);return(t,n,r,i,o)=>n(u=>e(t,n,r,i,(s,a)=>n(f=>{const g=Pe(Op),d=t._3&&!s._3?z(s._1,s._2,!0):s;return n(l=>g(d,n,r,i,(_,h)=>n(p=>{const m=Lt(Lt(Ot(J=>J==='"'))(`'"'`))(`closing '"' (unterminated string)`),N=d._3&&!_._3?z(_._1,_._2,!0):_;return n(J=>m(N,n,r,i,(v,w)=>n(L=>o(N._3&&!v._3?z(v._1,v._2,!0):v,zn(bt(Yt.foldr,h))))))})))})))})(),Fp=(()=>{const e=Lt(Ot(t=>t===":"))("':'");return(t,n,r,i,o)=>n(u=>Cn(t,n,r,i,(s,a)=>n(f=>Lt((g,d,l,_,h)=>{const p=g._1,m=g._2;return d(N=>{const J=(v,w)=>{const L=v._3;return d(b=>{if(L)return _(v,w);const S=g._1,A=g._2;return d(O=>Ec(z(S,A,!1),d,l,(j,R)=>{const P=j._3;return d(et=>P?_(j,R):gu(g,d,l,_,h))},h))})};return d(v=>e(z(p,m,!1),d,l,J,(w,L)=>d(b=>d(S=>Cn(w,d,l,J,(A,O)=>d(j=>{const R=Pe(Ot(et=>et!==`
13
- `&&et!=="\r"&&et!=="#"&&et!=="}")),P=w._3&&!A._3?z(A._1,A._2,!0):A;return d(et=>R(P,d,l,J,(K,B)=>d(q=>h(P._3&&!K._3?z(K._1,K._2,!0):K,s_(zn(bt(Yt.foldr,B)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(t._3&&!s._3?z(s._1,s._2,!0):s,n,r,i,o))))})(),Xp=(e,t,n,r,i)=>{const o=e._1,u=e._2;return t(s=>Ec(z(o,u,!1),t,n,(a,f)=>{const g=a._3;return t(d=>g?r(a,f):gu(e,t,n,r,i))},i))},Br=Ot(e=>e>="0"&&e<="9"),ve=(()=>{const e=Lt(Ot(t=>t==="_"))("'_'");return(t,n,r,i,o)=>n(u=>{const s=(g,d)=>n(l=>{const _=Pe((()=>{const p=Lt(Ot(N=>N==="_"))("'_'"),m=Lt(Ot(N=>N==="-"))("'-'");return(N,J,v,w,L)=>{const b=N._1,S=N._2;return J(A=>Do(z(b,S,!1),J,v,(O,j)=>{const R=O._3;return J(P=>{if(R)return w(O,j);const et=N._1,K=N._2;return J(B=>Br(z(et,K,!1),J,v,(q,M)=>{const C=q._3;return J(I=>{if(C)return w(q,M);const D=N._1,G=N._2;return J(Y=>p(z(D,G,!1),J,v,(X,H)=>{const Q=X._3;return J(W=>Q?w(X,H):m(N,J,v,w,L))},L))})},L))})},L))}})()),h=t._3&&!g._3?z(g._1,g._2,!0):g;return n(p=>_(h,n,r,i,(m,N)=>n(J=>o(h._3&&!m._3?z(m._1,m._2,!0):m,_i(d)+zn(bt(Yt.foldr,N))))))}),a=t._1,f=t._2;return n(g=>Do(z(a,f,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?i(d,l):e(t,n,r,i,s))},s))})})(),Up=Lt((e,t,n,r,i)=>{const o=e._1,u=e._2;return t(s=>gu(z(o,u,!1),t,n,(a,f)=>{const g=a._3;return t(d=>g?r(a,f):ve(e,t,n,r,i))},i))})("frame name (identifier or quoted string)"),Kp=(e,t,n,r,i)=>t(o=>ve(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Cn(f,t,n,r,(d,l)=>t(_=>{const h=Lt((m,N,J,v,w)=>{const L=m._1,b=m._2;return N(S=>jn("->")(z(L,b,!1),N,J,(A,O)=>{const j=A._3;return N(R=>j?v(A,O):jn("<-")(m,N,J,v,w))},w))})("'->' or '<-'"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=p._3&&!N._3?z(N._1,N._2,!0):N;return t(L=>Cn(w,t,n,r,(b,S)=>t(A=>{const O=Lt(ve)("target node identifier"),j=w._3&&!b._3?z(b._1,b._2,!0):b;return t(R=>O(j,t,n,r,(P,et)=>t(K=>{const B=Pe((M,C,I,D,G)=>{const Y=M._3;return C(X=>C(H=>Cn(M,C,I,(Q,W)=>D(z(Q._1,Q._2,Y),W),(Q,W)=>C(U=>C(F=>{const _t=M._3&&!Q._3?z(Q._1,Q._2,!0):Q;return Xp(_t,C,I,(pt,ft)=>D(z(pt._1,pt._2,Y),ft),(pt,ft)=>C(ht=>G(_t._3&&!pt._3?z(pt._1,pt._2,!0):pt,ft)))})))))}),q=j._3&&!P._3?z(P._1,P._2,!0):P;return t(M=>B(q,t,n,r,(C,I)=>t(D=>(()=>{if(J==="<-"){const Y=En("Token",{from:et,to:s,labels:bt(Yt.foldr,I)});return(X,H,Q,W,U)=>U(X,Y)}const G=En("Token",{from:s,to:et,labels:bt(Yt.foldr,I)});return(Y,X,H,Q,W)=>W(Y,G)})()(q._3&&!C._3?z(C._1,C._2,!0):C,t,n,r,i))))})))})))})))})))}))),Zp=(e,t,n,r,i)=>t(o=>Br(e,t,n,r,(u,s)=>t(a=>{const f=Pe(Br),g=e._3&&!u._3?z(u._1,u._2,!0):u;return t(d=>f(g,t,n,r,(l,_)=>t(h=>{const p=Tf(_i(s)+zn(bt(Yt.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(N,J,v,w,L)=>L(N,m)}if(p.tag==="Nothing")return(m,N,J,v,w)=>w(m,0);c()})()(g._3&&!l._3?z(l._1,l._2,!0):l,t,n,r,i)})))}))),Go=e=>(t,n,r,i,o)=>{const u=t._3;return n(s=>jn(e)(t,n,r,(a,f)=>i(z(a._1,a._2,u),f),(a,f)=>n(g=>{const d=au((()=>{const _=Lt(Ot(p=>p==="_"))("'_'"),h=Lt(Ot(p=>p==="-"))("'-'");return(p,m,N,J,v)=>{const w=p._1,L=p._2;return m(b=>Do(z(w,L,!1),m,N,(S,A)=>{const O=S._3;return m(j=>{if(O)return J(S,A);const R=p._1,P=p._2;return m(et=>Br(z(R,P,!1),m,N,(K,B)=>{const q=K._3;return m(M=>{if(q)return J(K,B);const C=p._1,I=p._2;return m(D=>_(z(C,I,!1),m,N,(G,Y)=>{const X=G._3;return m(H=>X?J(G,Y):h(p,m,N,J,v))},v))})},v))})},v))}})()),l=t._3&&!a._3?z(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(z(h._1,h._2,u),p),(h,p)=>n(m=>{const N=l._3&&!h._3?z(h._1,h._2,!0):h;return n(J=>Re(N,n,r,(v,w)=>i(z(v._1,v._2,u),w),(v,w)=>n(L=>o(N._3&&!v._3?z(v._1,v._2,!0):v,e))))})))})))},jp=(e,t,n,r,i)=>t(o=>Me(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Go("via")(f,t,n,r,(d,l)=>t(_=>{const h=f._3&&!d._3?z(d._1,d._2,!0):d;return t(p=>ve(h,t,n,r,(m,N)=>t(J=>{const v=h._3&&!m._3?z(m._1,m._2,!0):m;return t(w=>Me(v,t,n,r,(L,b)=>t(S=>{const A=v._3&&!L._3?z(L._1,L._2,!0):L;return t(O=>ve(A,t,n,r,(j,R)=>t(P=>i(A._3&&!j._3?z(j._1,j._2,!0):j,{from:N,to:R}))))})))})))})))}))),tr=e=>(t,n,r,i,o)=>{const u=t._3;return n(s=>jn(e)(t,n,r,(a,f)=>i(z(a._1,a._2,u),f),(a,f)=>n(g=>{const d=au((()=>{const _=Lt(Ot(p=>p==="_"))("'_'"),h=Lt(Ot(p=>p==="-"))("'-'");return(p,m,N,J,v)=>{const w=p._1,L=p._2;return m(b=>Do(z(w,L,!1),m,N,(S,A)=>{const O=S._3;return m(j=>{if(O)return J(S,A);const R=p._1,P=p._2;return m(et=>Br(z(R,P,!1),m,N,(K,B)=>{const q=K._3;return m(M=>{if(q)return J(K,B);const C=p._1,I=p._2;return m(D=>_(z(C,I,!1),m,N,(G,Y)=>{const X=G._3;return m(H=>X?J(G,Y):h(p,m,N,J,v))},v))})},v))})},v))}})()),l=t._3&&!a._3?z(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(z(h._1,h._2,u),p),(h,p)=>n(m=>o(l._3&&!h._3?z(h._1,h._2,!0):h,void 0))))})))},tm=(e,t,n,r,i)=>t(o=>tr("+edge")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Me(f,t,n,r,(d,l)=>t(_=>{const h=Lt(ve)("source node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=p._3&&!N._3?z(N._1,N._2,!0):N;return t(L=>Me(w,t,n,r,(b,S)=>t(A=>{const O=Lt(ve)("target node identifier"),j=w._3&&!b._3?z(b._1,b._2,!0):b;return t(R=>O(j,t,n,r,(P,et)=>t(K=>i(j._3&&!P._3?z(P._1,P._2,!0):P,En("AddEdge",{from:J,to:et})))))})))})))})))}))),em=(e,t,n,r,i)=>t(o=>tr("+node")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Me(f,t,n,r,(d,l)=>t(_=>{const h=Lt(ve)("node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=p._3&&!N._3?z(N._1,N._2,!0):N;return t(L=>Fp(w,t,n,r,(b,S)=>t(A=>i(w._3&&!b._3?z(b._1,b._2,!0):b,En("AddNode",{id:J,label:S})))))})))})))}))),nm=(e,t,n,r,i)=>t(o=>tr("-edge")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Me(f,t,n,r,(d,l)=>t(_=>{const h=Lt(ve)("source node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=p._3&&!N._3?z(N._1,N._2,!0):N;return t(L=>Me(w,t,n,r,(b,S)=>t(A=>{const O=Lt(ve)("target node identifier"),j=w._3&&!b._3?z(b._1,b._2,!0):b;return t(R=>O(j,t,n,r,(P,et)=>t(K=>i(j._3&&!P._3?z(P._1,P._2,!0):P,En("DelEdge",{from:J,to:et})))))})))})))})))}))),rm=(e,t,n,r,i)=>t(o=>tr("-node")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Me(f,t,n,r,(d,l)=>t(_=>{const h=Lt(ve)("node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=Pe((b,S,A,O,j)=>{const R=b._3;return jp(b,S,A,(P,et)=>O(z(P._1,P._2,R),et),j)}),L=p._3&&!N._3?z(N._1,N._2,!0):N;return t(b=>w(L,t,n,r,(S,A)=>t(O=>i(L._3&&!S._3?z(S._1,S._2,!0):S,En("DelNode",{id:J,via:bt(Yt.foldr,A)})))))})))})))}))),om=(e,t,n,r,i)=>t(o=>tr("~edge")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Me(f,t,n,r,(d,l)=>t(_=>{const h=Lt(ve)("source node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=p._3&&!N._3?z(N._1,N._2,!0):N;return t(L=>Me(w,t,n,r,(b,S)=>t(A=>{const O=Lt(ve)("target node identifier"),j=w._3&&!b._3?z(b._1,b._2,!0):b;return t(R=>O(j,t,n,r,(P,et)=>t(K=>{const B=j._3&&!P._3?z(P._1,P._2,!0):P;return t(q=>Re(B,t,n,r,(M,C)=>t(I=>{const D=Lt(jn("->"))("'->'"),G=B._3&&!M._3?z(M._1,M._2,!0):M;return t(Y=>D(G,t,n,r,(X,H)=>t(Q=>{const W=G._3&&!X._3?z(X._1,X._2,!0):X;return t(U=>Re(W,t,n,r,(F,_t)=>t(pt=>{const ft=Lt(ve)("new source node identifier"),ht=W._3&&!F._3?z(F._1,F._2,!0):F;return t(wt=>ft(ht,t,n,r,(It,dt)=>t(Mt=>{const mt=ht._3&&!It._3?z(It._1,It._2,!0):It;return t(gt=>Me(mt,t,n,r,(rt,nt)=>t(st=>{const yt=Lt(ve)("new target node identifier"),Jt=mt._3&&!rt._3?z(rt._1,rt._2,!0):rt;return t(Ct=>yt(Jt,t,n,r,($t,re)=>t(Ve=>i(Jt._3&&!$t._3?z($t._1,$t._2,!0):$t,En("RepointEdge",{from:J,to:et,newFrom:dt,newTo:re})))))})))})))})))})))})))})))})))})))})))}))),im=(e,t,n,r,i)=>t(o=>vc(e,t,n,r,(u,s)=>t(a=>{const f=Lt(kc([em,rm,om,tm,nm,Kp]))("statement (+node, -node, +edge, -edge, ~edge, or 'a -> b')"),g=e._3&&!u._3?z(u._1,u._2,!0):u;return t(d=>f(g,t,n,r,(l,_)=>t(h=>i(g._3&&!l._3?z(l._1,l._2,!0):l,uu("Leaf",{op:_,line:s.line,column:s.column})))))}))),um=(e,t,n,r,i)=>t(o=>tr("seed")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Cn(f,t,n,r,(d,l)=>t(_=>{const h=Lt(Zp)("integer (seed value)"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=p._3&&!N._3?z(N._1,N._2,!0):N;return t(L=>Re(w,t,n,r,(b,S)=>t(A=>i(w._3&&!b._3?z(b._1,b._2,!0):b,J))))})))})))}))),_u=$p((()=>{const e=Lt(Ot(t=>t==="{"))("'{'");return(t,n,r,i,o)=>n(u=>n(s=>e(t,n,r,i,(a,f)=>n(g=>n(d=>{const l=t._3&&!a._3?z(a._1,a._2,!0):a;return Re(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?z(_._1,_._2,!0):_,h)))})))))})())(Lt((()=>{const e=Lt(Ot(t=>t==="}"))("'}'");return(t,n,r,i,o)=>n(u=>n(s=>Re(t,n,r,i,(a,f)=>n(g=>n(d=>{const l=t._3&&!a._3?z(a._1,a._2,!0):a;return e(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?z(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),sm=(e,t,n,r,i)=>t(o=>Go("seq")(e,t,n,r,(u,s)=>t(a=>_u(du(yc))(e._3&&!u._3?z(u._1,u._2,!0):u,t,n,r,i)))),am=(e,t,n,r,i)=>t(o=>Go("par")(e,t,n,r,(u,s)=>t(a=>_u(du(gp))(e._3&&!u._3?z(u._1,u._2,!0):u,t,n,r,i)))),du=e=>{const t=Pe(cm());return(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,f)=>r(g=>u(n._3&&!a._3?z(a._1,a._2,!0):a,e(bt(Yt.foldr,f))))))},cm=Rc(()=>{const e=au(Lt(Ot(t=>t==="}"))("'}'"));return(t,n,r,i,o)=>n(u=>{const s=t._3;return n(a=>n(f=>Re(t,n,r,(g,d)=>i(z(g._1,g._2,s),d),(g,d)=>n(l=>n(_=>{const h=t._3&&!g._3?z(g._1,g._2,!0):g;return e(h,n,r,(p,m)=>i(z(p._1,p._2,s),m),(p,m)=>n(N=>{const J=h._3&&!p._3?z(p._1,p._2,!0):p;return n(v=>{const w=kc([(b,S,A,O,j)=>{const R=b._3;return am(b,S,A,(P,et)=>O(z(P._1,P._2,R),et),j)},(b,S,A,O,j)=>{const R=b._3;return sm(b,S,A,(P,et)=>O(z(P._1,P._2,R),et),j)},im]),L=t._3&&!J._3?z(J._1,J._2,!0):J;return n(b=>w(L,n,r,i,(S,A)=>n(O=>{const j=L._3&&!S._3?z(S._1,S._2,!0):S;return n(R=>Cn(j,n,r,i,(P,et)=>n(K=>{const B=j._3&&!P._3?z(P._1,P._2,!0):P;return n(q=>Yp(B,n,r,i,(M,C)=>n(I=>o(B._3&&!M._3?z(M._1,M._2,!0):M,A))))})))})))})}))})))))})}),fm=(e,t,n,r,i)=>t(o=>Go("frame")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Up(f,t,n,r,(d,l)=>t(_=>{const h=f._3&&!d._3?z(d._1,d._2,!0):d;return t(p=>Re(h,t,n,r,(m,N)=>t(J=>{const v=_u(du(yc)),w=h._3&&!m._3?z(m._1,m._2,!0):m;return t(L=>v(w,t,n,r,(b,S)=>t(A=>{const O=w._3&&!b._3?z(b._1,b._2,!0):b;return t(j=>Re(O,t,n,r,(R,P)=>t(et=>i(O._3&&!R._3?z(R._1,R._2,!0):R,{name:E("Just",l),ops:S}))))})))})))})))}))),gm=(e,t,n,r,i)=>t(o=>Re(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>{const d=(h,p)=>t(m=>{const N=Pe(fm),J=f._3&&!h._3?z(h._1,h._2,!0):h;return t(v=>N(J,t,n,r,(w,L)=>t(b=>{const S=J._3&&!w._3?z(w._1,w._2,!0):w;return t(A=>Re(S,t,n,r,(O,j)=>t(R=>{const P=Lt(bc)("'frame' or end of input"),et=S._3&&!O._3?z(O._1,O._2,!0):O;return t(K=>P(et,t,n,r,(B,q)=>t(M=>i(et._3&&!B._3?z(B._1,B._2,!0):B,{seed:(()=>{if(p.tag==="Just")return p._1;if(p.tag==="Nothing")return 0;c()})(),frames:bt(Yt.foldr,L)}))))})))})))}),l=f._1,_=f._2;return t(h=>t(p=>um(z(l,_,!1),t,n,(m,N)=>{const J=m._3;return t(v=>J?r(m,N):d(f,T))},(m,N)=>t(J=>d(m,E("Just",N))))))})}))),_m=e=>{const t=Gp(e)(gm);if(t.tag==="Left")return kt("Left",{msg:t._1._1,line:t._1._2.line,column:t._1._2.column});if(t.tag==="Right")return kt("Right",t._1);c()},dm=e=>{const t=_m(e);if(t.tag==="Left")return kt("Left",t._1.msg);if(t.tag==="Right")return kt("Right",t._1);c()};function lu(e,t,n,r){if(typeof window<"u"){var i=window[n];if(i!=null&&r instanceof i)return t(r)}for(var o=r;o!=null;){var u=Object.getPrototypeOf(o),s=u.constructor.name;if(s===n)return t(r);if(s==="Object")return e;o=u}return e}function Mo(e){return function(t){return function(n){return function(){n.setAttribute(e,t)}}}}function lm(e){return function(t){return function(){t.textContent=e}}}function hm(e){return function(){return function(t){return e(t)()}}}function pm(e){return function(t){return function(n){return function(r){return function(){return r.addEventListener(e,t,n)}}}}}const mm=function(){return window};function ym(e){return function(t){return function(){t.value=e}}}function Jm(e){return function(){return e.valueAsNumber}}function Nm(e){return function(){return e.value}}function xm(e){return function(t){return function(){return t.requestAnimationFrame(e)}}}const vm=e=>e,Tm=e=>()=>e.clientWidth||0,wm=()=>window.devicePixelRatio||1,hu=(e,t)=>{t.innerHTML=e},bm=(e,t,n)=>{e.style.setProperty(t,n)},km=(e,t)=>e.querySelector(`[data-mg="${t}"]`),Lm=e=>t=>e===t,Em=e=>e,Cm=At.foldMap(If),Cc=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Sm=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Pm=Em("CanvasRenderer"),Rm=e=>t=>{const n=e-t*ct(ur(Gu(e/t)));return t<=0?0:n<0?n+t:n},Im=e=>t=>{const n=N0(e);return()=>{const r=n(),i=Z_(H_)(e)(b0(r)(e));if(i.tag==="Left")return Bu("[markgraf] precompute failed")();if(i.tag==="Right")return t(i._1)();c()}},Dm=e=>y(t=>n=>{const r=e(n);return()=>(t(),r())})(()=>{}),Gm=`
1
+ var Tw=(function(mu){"use strict";function ka(t){let e=0,n;return()=>{if(e===2)return n;if(e===1)throw new Error("Binding demanded before initialized");return e=1,n=t(),e=2,n}}function g(){throw new Error("Failed pattern match")}function En(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const Le=t=>e=>t,H=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}},T1={map:H},Ea=t=>t,Tt=typeof Array.prototype.flatMap=="function"?function(t){return function(e){return t.flatMap(e)}}:function(t){return function(e){for(var n=[],r=t.length,i=0;i<r;i++)for(var o=e(t[i]),u=o.length,s=0;s<u;s++)n.push(o[s]);return n}},ie=function(t){return t.toString()},Ga=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},v1=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})+'"'},yu=t=>t,ye=yu("LT"),xe=yu("GT"),Se=yu("EQ"),w=(t,e)=>({tag:t,_1:e}),T=w("Nothing"),Yt=t=>w("Just",t),Ca=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;g()},Sa=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;g()},St=(t,e)=>({tag:t,_1:e}),w1=t=>St("Right",t),b1={map:t=>e=>{if(e.tag==="Left")return St("Left",e._1);if(e.tag==="Right")return St("Right",t(e._1));g()}},Da={apply:t=>e=>{if(t.tag==="Left")return St("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return St("Left",e._1);if(e.tag==="Right")return St("Right",t._1(e._1))}g()},Functor0:()=>b1},L1={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>St("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}g()},Apply0:()=>Da},k1={pure:w1,Apply0:()=>Da},Pa={Applicative0:()=>k1,Bind1:()=>L1},E1=t=>t,G1={map:t=>e=>t(e)},Ia={apply:t=>e=>t(e),Functor0:()=>G1},C1={bind:t=>e=>e(t),Apply0:()=>Ia},S1={pure:E1,Apply0:()=>Ia},Wn={Applicative0:()=>S1,Bind1:()=>C1},D1=function(t){return function(){return t}},P1={apply:t=>e=>()=>{const n=t(),r=e();return xu.pure(n(r))()},Functor0:()=>I1},xu={pure:D1,Apply0:()=>P1},I1={map:t=>e=>()=>{const n=e();return t(n)}},Zr=(t,e)=>({tag:t,_1:e}),Qa=t=>Zr("Loop",t),Q1={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:()=>Wn},F1=function(t){return function(e){return function(){return t(e())}}},A1=function(t){return function(){return t}},M1={map:F1},B1={apply:t=>e=>()=>{const n=t(),r=e();return Fa.pure(n(r))()},Functor0:()=>M1},Fa={pure:A1,Apply0:()=>B1},z1=(function(t){return function(e){return function(n){return function(){return t(e,n)}}}})(function(t,e){return e.push(t)}),R1=(t,e)=>({tag:"Iterator",_1:t,_2:e}),W1=t=>e=>n=>()=>{let r=!1;const i=e._2;for(;!r;){const o=i.value,u=e._1(o);if(u.tag==="Just"&&t(u._1)){n.push(u._1),e._2.value;const s=e._2.value;e._2.value=s+1|0;continue}r=!0}},H1=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const i=r.value,o=r.value;r.value=o+1|0;const u=t._1(i);if(u.tag==="Just"){e(u._1)();continue}if(u.tag==="Nothing"){n=!0;continue}g()}},Kr=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=i-1;o>=0;o--)r=t(n[o])(r);return r}}},J=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=0;o<i;o++)r=t(r)(n[o]);return r}}},Nu=t=>{const e=t.Apply0();return n=>r=>n.foldr(i=>{const o=r(i);return u=>e.apply(e.Functor0().map(s=>Ea)(o))(u)})(t.pure())},O1=t=>{const e=Nu(t);return n=>{const r=e(n);return i=>o=>r(o)(i)}},Bt={foldr:Kr,foldl:J,foldMap:t=>{const e=t.mempty;return n=>Bt.foldr(r=>i=>t.Semigroup0().append(n(r))(i))(e)}},b=(t,e)=>({tag:"Tuple",_1:t,_2:e}),Hn=t=>e=>b(t,e),$i=t=>t._2,Yi=t=>t._1,Qt=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 Ju=function(t){return function(e){return t===e}};const q1=Ju,$1=Ju,ti=Ju,Tu=function(t){return function(e){return function(n){if(e.length!==n.length)return!1;for(var r=0;r<e.length;r++)if(!t(e[r])(n[r]))return!1;return!0}}},gn={eq:ti},Y1={eq:$1},xr={eq:q1};var vu=function(t){return function(e){return function(n){return function(r){return function(i){return r<i?t:r===i?e:n}}}}};const V1=vu,X1=vu,C={compare:vu(ye)(Se)(xe),Eq0:()=>gn},st={compare:X1(ye)(Se)(xe),Eq0:()=>Y1},it={compare:V1(ye)(Se)(xe),Eq0:()=>xr},U1=function(t){return t},j1=(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)}}}}}})(),Z1=t=>t,rr={traverse:t=>{const e=t.Apply0();return j1(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>rr.traverse(t)(Z1),Functor0:()=>T1,Foldable1:()=>Bt},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 K1=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},td=function(t,e){for(var n=[],r=0,i=0;i<t;i++)n[r++]=e;return n};const ed=typeof Array.prototype.fill=="function"?K1:td,kt=(function(){function t(i,o){this.head=i,this.tail=o}var e={};function n(i){return function(o){return new t(i,o)}}function r(i){for(var o=[],u=0,s=i;s!==e;)o[u++]=s.head,s=s.tail;return o}return function(i,o){return r(i(n)(e)(o))}})(),Ft=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},Aa=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},ir=function(t,e,n,r){for(var i=0,o=r.length;i<o;i++)if(n(r[i]))return t(i);return e},Ma=function(t,e,n,r){for(var i=r.length-1;i>=0;i--)if(n(r[i]))return t(i);return e},Ba=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)},On=function(t,e,n,r,i){if(n<0||n>=i.length)return e;var o=i.slice();return o[n]=r,t(o)},ke=function(t){return t.slice().reverse()},Ae=function(t){if(t.length<=1e4)return Array.prototype.concat.apply([],t);for(var e=[],n=0,r=t.length;n<r;n++)for(var i=t[n],o=0,u=i.length;o<u;o++)e.push(i[o]);return e},ct=function(t,e){return e.filter(t)},nd=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},rd=(function(){function t(e,n,r,i,o,u){var s,a,c,f,d,l,_;for(s=o+(u-o>>1),s-o>1&&t(e,n,i,r,o,s),u-s>1&&t(e,n,i,r,s,u),a=o,c=s,f=o;a<s&&c<u;)d=i[a],l=i[c],_=n(e(d)(l)),_>0?(r[f++]=l,++c):(r[f++]=d,++a);for(;a<s;)r[f++]=i[a++];for(;c<u;)r[f++]=i[c++]}return function(e,n,r){var i;return r.length<2?r:(i=r.slice(0),t(e,n,i,r.slice(0),0,r.length),i)}})(),bt=function(t,e,n){return n.slice(t,e)},Je=function(t,e,n){for(var r=e.length<n.length?e.length:n.length,i=new Array(r),o=0;o<r;o++)i[o]=t(e[o])(n[o]);return i},Me=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},Ra=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Lt=t=>e=>rd(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),id=t=>e=>Lt(n=>r=>t.compare(e(n))(e(r))),zt=t=>e=>(()=>{const n=z1(e);return()=>{const r=[...t];return n(r)(),r}})()(),Vi=t=>{if(t.length===0)return t.length-1|0,T;const e=t.length-1|0;return e>=0&&e<t.length?w("Just",{init:bt(0,t.length-1|0,t),last:t[e]}):T},od=t=>e=>n=>t>=0&&t<n.length?On(Yt,T,t,e(n[t]),n):T,or=t=>e=>{const n=(r=>{let i=r,o=!0,u;for(;o;){const s=i;if(s>=0&&s<e.length){if(t(e[s])){i=s+1|0;continue}o=!1,u=w("Just",s);continue}o=!1,u=T}return u})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:bt(0,n._1,e),rest:bt(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};g()},Nr=t=>e=>{const n=Lt(r=>i=>t(r._2)(i._2))(Qt(Hn)(e));return 0<n.length?H($i)(id(it)(Yi)((()=>{const r=[n[0]];for(const i of n){const o=t((()=>{const u=r.length-1|0;if(u>=0&&u<r.length)return r[u]._2;g()})())(i._2);(o==="LT"||o==="GT"||o!=="EQ")&&r.push(i)}return r})())):[]},ud=t=>e=>{const n=[],r=R1(i=>i>=0&&i<e.length?w("Just",e[i]):T,{value:0});return H1(r)(i=>()=>{const o=[];o.push(i),W1(t(i))(r)(o)(),n.push(o)})(),n},Zt=t=>e=>{const n=ir(Yt,T,t,e);return n.tag==="Just"?w("Just",e[n._1]):T},Wa=t=>e=>ct(t,e),Be=t=>e=>n=>{const r=ir(Yt,T,i=>t.eq(i)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},Ha=t=>e=>Tt(e)(t),xt=t=>Ha(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];g()}),Oa=isFinite;function sd(t,e,n,r){var i=parseFloat(t);return e(i)?n(i):r}const qn=Math.abs,ad=Math.acos,ur=function(t){return function(e){return Math.atan2(t,e)}},Xi=Math.ceil,Ke=Math.cos,Ui=Math.exp,dn=Math.floor,qa=Math.log,cd=function(t){return function(e){return Math.min(t,e)}},wu=function(t){return function(e){return Math.pow(t,e)}},$n=Math.round,Oe=Math.sin,Ee=Math.sqrt,gd=Math.tan,fd=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},rt=function(t){return t},_d=(function(t){return function(e){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var i=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(o){if(i.test(o)){var u=parseInt(o,n);return(u|0)===u?t(u):e}else return e}}}})(Yt)(T)(10),$a=fd(Yt)(T),de=t=>{if(!Oa(t))return 0;if(t>=rt(2147483647))return 2147483647;if(t<=rt(-2147483648))return-2147483648;const e=$a(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;g()},Ot=(t,e,n)=>({tag:t,_1:e,_2:n}),qt=Ot("Nil"),$t={foldr:t=>e=>{const n=$t.foldl(i=>o=>t(o)(i))(e),r=(i=>o=>{let u=i,s=o,a=!0,c;for(;a;){const f=u,d=s;if(d.tag==="Nil"){a=!1,c=f;continue}if(d.tag==="Cons"){u=Ot("Cons",d._1,f),s=d._2;continue}g()}return c})(qt);return i=>n(r(i))},foldl:t=>e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=t(s)(a._1),i=a._2;continue}g()}return u},foldMap:t=>{const e=t.mempty;return n=>$t.foldl(r=>{const i=t.Semigroup0().append(r);return o=>i(n(o))})(e)}},dd=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)}}}}}}},ld=t=>{if(t.tag==="Just")return t._1;g()},hd={unfoldr1:dd(Ca)(ld)(Yi)($i)},pd=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)}}}}}}},md=t=>{if(t.tag==="Just")return t._1;g()},qe={unfoldr:pd(Ca)(md)(Yi)($i),Unfoldable10:()=>hd},Wt=(t,e,n,r,i,o,u)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u}),$e=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),ji=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),Ya=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),Q=Wt("Leaf"),ln=$e("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()},Jr=(t,e,n)=>{if(n.tag==="Leaf")return ji(T,Q,Q);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const i=Jr(t,e,n._5);return ji(i._1,i._2,ze(n._3,n._4,i._3,n._6))}if(r==="GT"){const i=Jr(t,e,n._6);return ji(i._1,ze(n._3,n._4,n._5,i._2),i._3)}if(r==="EQ")return ji(w("Just",n._4),n._5,n._6)}g()},Va=(t,e,n,r)=>{if(r.tag==="Leaf")return Ya(t,e,n);if(r.tag==="Node"){const i=Va(r._3,r._4,r._5,r._6);return Ya(i._1,i._2,ze(t,e,n,i._3))}g()},ei=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=Va(t._3,t._4,t._5,t._6);return ze(n._1,n._2,n._3,e)}g()},Gn=(t,e,n)=>{if(e.tag==="Leaf")return Q;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=Jr(t,n._3,e);return ei(Gn(t,r._2,n._5),Gn(t,r._3,n._6))}g()},Zi=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return Q;if(r.tag==="Node"){const i=Jr(t,r._3,n),o=Zi(t,e,i._2,r._5),u=Zi(t,e,i._3,r._6);if(i._1.tag==="Just")return ze(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return ei(o,u)}g()},Ge=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const i=Jr(t,r._3,n),o=Ge(t,e,i._2,r._5),u=Ge(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()},yd=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 ei(n(r._5),n(r._6))}g()};return n},hn=(t=>e=>n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="IterLeaf"){i=!1,o=e();continue}if(u.tag==="IterEmit"){i=!1,o=t(u._1,u._2,u._3);continue}if(u.tag==="IterNode"){r=(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Leaf"){d=!1,l=_;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){c=$e("IterEmit",h._3,h._4,_),f=h._5;continue}c=$e("IterEmit",h._3,h._4,$e("IterNode",h._6,_)),f=h._5;continue}g()}return l})(u._2)(u._1);continue}g()}return o})((t,e,n)=>w("Just",b(b(t,e),n)))(t=>T),vt=t=>e=>n=>r=>{const i=o=>{if(o.tag==="Leaf")return 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},Kt=t=>e=>e.foldl(n=>r=>j(t)(r._1)(r._2)(n))(Q),ni=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 ei(r._5,r._6)}g()};return n},Xa=t=>{const e=t.compare;return n=>r=>i=>{const o=Jr(e,r,i),u=n(o._1);if(u.tag==="Nothing")return ei(o._2,o._3);if(u.tag==="Just")return ze(r,u._1,o._2,o._3);g()}},oe=function(t){return function(e){return t+e|0}},Tr=function(t){return function(e){return t+e}},Yn=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},xd=function(t){return function(e){return t+e}},te=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},Nd={append:xd},Jd={append:te},Td={mempty:"",Semigroup0:()=>Nd},vd={mempty:[],Semigroup0:()=>Jd},wd=null;function Ua(t,e,n){return t==null?e:n(t)}function Jw(t){return t}function bu(t){return function(e){return function(n){return t.apply(n,[e])}}}const bd=bu(Number.prototype.toPrecision),Ld=bu(Number.prototype.toFixed),kd=bu(Number.prototype.toExponential),ri=(t,e)=>({tag:t,_1:e}),ii=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},oi=t=>{if(t.tag==="Precision")return bd(t._1);if(t.tag==="Fixed")return Ld(t._1);if(t.tag==="Exponential")return kd(t._1);g()},ja=function(t){return function(){console.log(t)}};function Ed(){return Date.now()}function Gd(t){return function(){return t.getContext("2d")}}function Cd(t){return function(){return t.width}}function Sd(t){return function(){return t.height}}function Dd(t){return function(e){return function(){t.width=e}}}function Pd(t){return function(e){return function(){t.height=e}}}function Lu(t){return function(e){return function(){t.lineWidth=e}}}function Id(t){return function(e){return function(){t.fillStyle=e}}}function Qd(t){return function(e){return function(){t.strokeStyle=e}}}function ku(t){return function(e){return function(){t.lineCap=e}}}function Eu(t){return function(e){return function(){t.lineJoin=e}}}function Fd(t){return function(e){return function(){t.globalCompositeOperation=e}}}function Ad(t){return function(e){return function(){t.globalAlpha=e}}}function Za(t){return function(){t.beginPath()}}function Gu(t){return function(){t.stroke()}}function Cu(t){return function(){t.fill()}}function Md(t){return function(){t.clip()}}function ui(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function Ka(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function tc(t){return function(){t.closePath()}}function Bd(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function zd(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function Ki(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function Su(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function Rd(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function Wd(t){return function(e){return function(){t.textAlign=e}}}function Hd(t){return function(e){return function(){t.textBaseline=e}}}function Od(t){return function(e){return function(){t.font=e}}}function qd(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function sr(t){return function(){t.save()}}function ar(t){return function(){t.restore()}}function si(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function $d(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const ec=t=>t,Du=t=>t,Pu=t=>t,Iu=t=>t,to=t=>t,Yd=to("BaselineTop"),Vd=to("BaselineMiddle"),Xd=to("BaselineAlphabetic"),Ud=to("BaselineBottom"),jd=Iu("AlignLeft"),Zd=Iu("AlignRight"),Kd=Iu("AlignCenter"),Qu=Pu("BevelJoin"),eo=Pu("RoundJoin"),Fu=Pu("MiterJoin"),Au=Du("Round"),Mu=Du("Square"),Bu=Du("Butt"),tl=ec("SourceOver"),el=ec("Difference"),nl=t=>e=>Hd(t)((()=>{if(e==="BaselineTop")return"top";if(e==="BaselineHanging")return"hanging";if(e==="BaselineMiddle")return"middle";if(e==="BaselineAlphabetic")return"alphabetic";if(e==="BaselineIdeographic")return"ideographic";if(e==="BaselineBottom")return"bottom";g()})()),rl=t=>e=>Wd(t)((()=>{if(e==="AlignLeft")return"left";if(e==="AlignRight")return"right";if(e==="AlignCenter")return"center";if(e==="AlignStart")return"start";if(e==="AlignEnd")return"end";g()})()),no=t=>e=>{if(e==="BevelJoin")return Eu(t)("bevel");if(e==="RoundJoin")return Eu(t)("round");if(e==="MiterJoin")return Eu(t)("miter");g()},zu=t=>e=>{if(e==="Round")return ku(t)("round");if(e==="Square")return ku(t)("square");if(e==="Butt")return ku(t)("butt");g()},nc=t=>e=>Fd(t)((()=>{if(e==="SourceOver")return"source-over";if(e==="SourceIn")return"source-in";if(e==="SourceOut")return"source-out";if(e==="SourceAtop")return"source-atop";if(e==="DestinationOver")return"destination-over";if(e==="DestinationIn")return"destination-in";if(e==="DestinationOut")return"destination-out";if(e==="DestinationAtop")return"destination-atop";if(e==="Lighter")return"lighter";if(e==="Copy")return"copy";if(e==="Xor")return"xor";if(e==="Multiply")return"multiply";if(e==="Screen")return"screen";if(e==="Overlay")return"overlay";if(e==="Darken")return"darken";if(e==="Lighten")return"lighten";if(e==="ColorDodge")return"color-dodge";if(e==="ColorBurn")return"color-burn";if(e==="HardLight")return"hard-light";if(e==="SoftLight")return"soft-light";if(e==="Difference")return"difference";if(e==="Exclusion")return"exclusion";if(e==="Hue")return"hue";if(e==="Saturation")return"saturation";if(e==="Color")return"color";if(e==="Luminosity")return"luminosity";g()})()),Re={foldr:t=>e=>{const n=$t.foldr(t)(e);return r=>n((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,Ot("Cons",o._3,i(o._6,u)));g()};return i(r,qt)})())}},il=t=>{const e={append:(()=>{const n=t.compare;return r=>i=>Ge(n,Le,r,i)})()};return{mempty:Q,Semigroup0:()=>e}},ai=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},cr=function(t){return t.join("")},Vn=function(t){return t.split("")},ro=function(t){return t},Xn=function(t){return t.length},rc=function(t){return function(e){return e.substr(0,t)}},ci=function(t){return function(e){return e.substring(t)}},ol=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},ul=t=>e=>{const n=ol(Xn(t))(e);return n.before===t?w("Just",n.after):T},sl=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},al=function(t){return t()},cl=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},gl=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},gr=t=>BigInt(t),fl=t=>Number(t),io=t=>e=>t+e,oo=t=>e=>t*e,Ru=t=>e=>t-e,ic=0n,uo=1n,oc=t=>e=>t^e,gi=t=>e=>t&e,Wu=t=>e=>t<<e,Hu=t=>e=>t>>e,_l=t=>e=>t==e,dl=t=>e=>t===e?0:t>e?1:-1,ll={eq:_l},uc={compare:t=>e=>{const n=dl(t)(e);return n===1?xe:n===0?Se:ye},Eq0:()=>ll},hl=cl(Yt)(T),pl=gl(Yt)(T),sc=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=st.compare(e._1)(n._1);return r==="LT"?ye:r==="GT"?xe:st.compare(e._2)(n._2)},Eq0:()=>t}})(),ml=t=>e=>qn(t._1-e._1)+qn(t._2-e._2),fr=t=>t,so=t=>t,le=so("North"),he=so("South"),pn=so("East"),_r=so("West"),Un=fr("Rectangle"),yl=fr("Cylinder"),xl=fr("Parallelogram"),Nl=fr("Diamond"),Jl=fr("Ellipse"),Tl=fr("Document"),vl=fr("Cloud"),ac=t=>t,cc=J(Tr)(0),wl=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},mn=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fi=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},gc=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},vr=t=>e=>{const n=Je(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,c=s.x-u.x;return Ee(c*c+a*a)})()}),t,bt(1,t.length,t)),r=cc(H(u=>u.len)(n)),i=wl(0)(r)(e*r),o=u=>s=>a=>{let c=u,f=s,d=a,l=!0,_;for(;l;){const h=c,m=f,p=d,y=Ft(x=>T,x=>N=>w("Just",{head:x,tail:N}),h);if(y.tag==="Nothing"){const x=t.length-1|0;if(x>=0&&x<t.length){l=!1,_=t[x];continue}l=!1,_=p;continue}if(y.tag==="Just"){if(m<=y._1.head.len){const x=y._1.head.len<=0?0:m/y._1.head.len;l=!1,_={x:y._1.head.a.x+(y._1.head.b.x-y._1.head.a.x)*x,y:y._1.head.a.y+(y._1.head.b.y-y._1.head.a.y)*x};continue}c=y._1.tail,f=m-y._1.head.len,d=p;continue}g()}return _};return 0<t.length?w("Just",o(n)(i)(t[0])):T},bl=t=>e=>{const n=mn(1)(t.w),r=mn(1)(t.h),i=mn(1)(e.w-8),o=mn(1)(e.h-8),u=fi(i/n)(o/r);return{scale:u,tx:e.x+4+(i-n*u)/2-t.x*u,ty:e.y+4+(o-r*u)/2-t.y*u}},_i=t=>cc(Je(e=>n=>{const r=n.y-e.y,i=n.x-e.x;return Ee(i*i+r*r)},t,bt(1,t.length,t))),Ll=t=>e=>n=>r=>i=>{const o=0<t.length?w("Just",t[0]):T,u=(()=>{if(o.tag==="Nothing")return e;if(o.tag==="Just")return o._1;g()})(),s=t.length-1|0,a=s>=0&&s<t.length?w("Just",t[s]):T,c=(()=>{if(a.tag==="Nothing")return n;if(a.tag==="Just")return a._1;g()})(),f=mn(.05)(1-i.pre-i.post),d=r<i.pre?0:r>1-i.post?1:(r-i.pre)/f,l=c.x-n.x,_=2*(()=>{const v=c.y-n.y;return(l<0?-l:l)+(v<0?-v:v)})(),h=u.x-e.x,m=2*(()=>{const v=u.y-e.y;return(h<0?-h:h)+(v<0?-v:v)})(),p=m+_i(t)+_,y=p<=1e-4?1:1-_/p,x=p<=1e-4?0:m/p;if(d<=x){const v=x<=1e-4?1:d/x;return{x:e.x+(u.x-e.x)*v,y:e.y+(u.y-e.y)*v}}if(d>=y){const v=y>=1?0:(d-y)/(1-y);return{x:c.x+(n.x-c.x)*v,y:c.y+(n.y-c.y)*v}}const N=vr(t)((d-x)/mn(1e-4)(y-x));if(N.tag==="Nothing")return u;if(N.tag==="Just")return N._1;g()},kl=t=>{const e=Ft(n=>T,n=>r=>w("Just",{head:n,tail:r}),(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._4,n(r._6,i)));g()};return Tt(kt($t.foldr,n(t.nodes,qt)))(r=>[{x:r.x,y:r.y},{x:r.x+r.w,y:r.y+r.h}])})());if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:fi(r.minX)(i.x),minY:fi(r.minY)(i.y),maxX:mn(r.maxX)(i.x),maxY:mn(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},Ou={scale:1,tx:0,ty:0},Ye=t=>{const e=Ft(n=>T,n=>r=>w("Just",{head:n,tail:r}),[...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._4,n(r._6,i)));g()};return Tt(kt($t.foldr,n(t.nodes,qt)))(r=>[{x:r.x,y:r.y},{x:r.x+r.w,y:r.y+r.h}])})(),...Ae((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._4,n(r._6,i)));g()};return kt($t.foldr,n(t.edges,qt))})()),...Ae((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._4,n(r._6,i)));g()};return kt($t.foldr,n(t.chipExtras,qt))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:fi(r.minX)(i.x),minY:fi(r.minY)(i.y),maxX:mn(r.maxX)(i.x),maxY:mn(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},El=t=>e=>(n=>r=>i=>{let o=n,u=r,s=i,a=!0,c;for(;a;){const f=o,d=u,l=s,_=Ft(h=>T,h=>m=>w("Just",{head:h,tail:m}),d);if(_.tag==="Nothing"){a=!1,c=l;continue}if(_.tag==="Just"){const h=gc(_._1.head)(f.interiors);if(h.tag==="Nothing"){a=!1,c=l;continue}if(h.tag==="Just"){o=h._1,u=_._1.tail,s=(()=>{const m=bl(Ye(h._1.layout))((()=>{const p=gc(_._1.head)(f.layout.nodes);if(p.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:Un};if(p.tag==="Just")return p._1;g()})());return{scale:l.scale*m.scale,tx:l.scale*m.tx+l.tx,ty:l.scale*m.ty+l.ty}})();continue}}g()}return c})(t)(e)(Ou),fc=t=>t,_c=(t,e)=>({tag:t,_1:e}),ao=(t,e)=>({tag:t,_1:e}),qu=(t,e)=>({tag:t,_1:e}),Gl=qu("First"),Cl=fc("Forward"),Sl=fc("Backward"),Dl=ao("ExitNode"),dc=Kt(C)(Bt),Pl=t=>Kr(e=>n=>({nodes:Ge(C.compare,Le,e.nodes,n.nodes),edges:Ge(C.compare,Le,e.edges,n.edges)}))({nodes:Q,edges:Q})(t.keyframes),Il=t=>e=>({entering:{nodes:Gn(C.compare,e.nodes,t.nodes),edges:Gn(C.compare,e.edges,t.edges)},leaving:{nodes:Gn(C.compare,t.nodes,e.nodes),edges:Gn(C.compare,t.edges,e.edges)},surviving:{nodes:Zi(C.compare,Le,t.nodes,e.nodes),edges:Zi(C.compare,Le,t.edges,e.edges)}}),co=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},wr=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},di=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},$u=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},Ql=J(t=>e=>j(C)(e)()(t))(Q),Fl=J(t=>e=>j(C)(e)()(t))(Q),Al=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),lc=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},hc=Kt(C)(Bt),li=t=>{const e=Ft(n=>T,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:co(r.minX)(i.x),minY:co(r.minY)(i.y),maxX:wr(r.maxX)(i.x),maxY:wr(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},Ml=t=>{const e=Ft(n=>T,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return T;if(e.tag==="Just")return w("Just",li(t));g()},Bl=t=>e=>n=>Ql(Tt(kt(Re.foldr,n))(r=>{const i=di(r)(t);if(i.tag==="Just")return ct(o=>!$u(o)(e),[i._1.source,i._1.target]);if(i.tag==="Nothing")return[];g()})),zl=t=>t.kind.tag==="SendToken"?w("Just",b(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):T,Rl=t=>t.tag==="DataFlow"?xt(zl)(t._1.events):[],Wl=t=>e=>Fl(xt(n=>$u(n._2.source)(e)||$u(n._2.target)(e)?w("Just",n._1):T)(Al(t))),Hl=t=>{const e=t.length-1|0;return e>=0&&e<t.length?0<t.length?t[0].x===t[e].x&&t[0].y===t[e].y?w("Just",li([t[0]])):w("Just",li([t[0],t[e]])):T:0<t.length?w("Just",li([t[0]])):T},go=t=>{const e=Ft(n=>T,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:co(r.minX)(i.x),minY:co(r.minY)(i.y),maxX:wr(r.maxX)(i.x+i.w),maxY:wr(r.maxY)(i.y+i.h)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x+e._1.head.w,maxY:e._1.head.y+e._1.head.h})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},pc=t=>e=>n=>{if(n.tag==="Leaf")return Ye(t);const r=Wl(e)(n),i=[...xt(o=>{const u=lc(o)(t.nodes);return u.tag==="Just"?w("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):T})(kt(Re.foldr,Ge(C.compare,Le,n,Bl(e)(n)(r)))),...xt(o=>{const u=di(o)(t.edges);return u.tag==="Just"?w("Just",li(u._1)):T})(kt(Re.foldr,r)),...xt(o=>{const u=di(o)(t.chipExtras);if(u.tag==="Just")return Ml(u._1);if(u.tag==="Nothing")return T;g()})(kt(Re.foldr,r))];return i.length===0?Ye(t):go(i)},hi=t=>e=>n=>{const r=[...xt(i=>i)([(()=>{const i=di(n)(t.chipExtras);if(i.tag==="Just")return Hl(i._1);if(i.tag==="Nothing")return T;g()})()]),...(()=>{const i=di(n)(e);if(i.tag==="Just")return xt(o=>{const u=lc(o)(t.nodes);return u.tag==="Just"?w("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):T})([i._1.source,i._1.target]);if(i.tag==="Nothing")return[];g()})()];return r.length===0?pc(t)(e)(Q):go(r)},Yu=t=>e=>{const n=Ye(t),r=n.w/wr(1e-4)(e.zoom),i=n.h/wr(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-i/2,w:r,h:i}},Ol=t=>Ge(C.compare,Le,hc(H(e=>b(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),hc(Tt(t.scenes)(Rl))),Vu=t=>t,ql=t=>t,dr=Vu("Linear"),$l=Vu("EaseInOutQuad"),Yl=Vu("SpringBouncy"),pi=t=>e=>n=>{const r=Ee(1-e*e),i=t*r;return 1-Ui(-e*t*n)*(Ke(i*n)+e/r*Oe(i*n))},Vl=t=>{const e=st.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=st.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Xu=t=>e=>(()=>{if(t==="Linear")return ql;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-wu(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*Ui(-6*n);if(t==="SpringBouncy")return pi(6)(.7);g()})()(Vl(e)),mc=t=>t,Uu=t=>t,fo=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},mi=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},yc=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Xl=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ul=Uu("Hold"),jl=Uu("Gap"),Zl=Uu("Move"),yi=mc("LinearLerp"),xc=mc("LogLerp"),Kl=t=>e=>n=>{const r=n.center.y-e.center.y,i=n.center.x-e.center.x,o=Ee(i*i+r*r),u=n.zoom-e.zoom,s=u<0?-u:u;return fo(t.minTransition)(t.maxTransition)(mi(t.panSpeed<=0?t.minTransition:o/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:s/t.zoomSpeed))},th=J(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:zt(t)(e)})([]),Nc=t=>e=>{const n={x:0,y:0},r=0<t.length?t[0].pos:n,i=Ma(Yt,T,o=>o.t<=e,t);if(i.tag==="Nothing")return r;if(i.tag==="Just"){const o=i._1+1|0;if(o>=0&&o<t.length){if(i._1>=0&&i._1<t.length){const u=fo(0)(1)(t[o].t<=t[i._1].t?0:(e-t[i._1].t)/(t[o].t-t[i._1].t));return{x:t[i._1].pos.x+(t[o].pos.x-t[i._1].pos.x)*u,y:t[i._1].pos.y+(t[o].pos.y-t[i._1].pos.y)*u}}return n}return i._1>=0&&i._1<t.length?t[i._1].pos:n}g()},ju=t=>e=>({center:{x:e.center.x*t.scale+t.tx,y:e.center.y*t.scale+t.ty},zoom:e.zoom/mi(1e-6)(t.scale)}),eh=t=>e=>n=>({center:{x:t.center.x+(e.center.x-t.center.x)*n,y:t.center.y+(e.center.y-t.center.y)*n},zoom:Ui((()=>{const r=qa(mi(1e-6)(t.zoom));return r+(qa(mi(1e-6)(e.zoom))-r)*n})())}),nh=t=>e=>n=>{const r=Xu(n.easing)(fo(0)(1)(n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT)));if(n.interp==="LinearLerp")return{center:{x:n.fromCam.center.x+(n.toCam.center.x-n.fromCam.center.x)*r,y:n.fromCam.center.y+(n.toCam.center.y-n.fromCam.center.y)*r},zoom:n.fromCam.zoom+(n.toCam.zoom-n.fromCam.zoom)*r};if(n.interp==="LogLerp")return eh(n.fromCam)(n.toCam)(r);g()},rh=t=>e=>n=>r=>{const i=(u,s)=>yc(Kl(t)(u.toCam)(s.toCam))(u.endT-u.startT),o=J(u=>s=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:w("Just",s)};if(u.pending.tag==="Just")return!(s.fromCam.zoom===s.toCam.zoom&&s.fromCam.center.x===s.toCam.center.x&&s.fromCam.center.y===s.toCam.center.y)||(()=>{const a=u.pending._1.toCam.center.x-s.toCam.center.x;return(a<0?-a<8:a<8)&&(()=>{const c=u.pending._1.toCam.center.y-s.toCam.center.y;return(c<0?-c<8:c<8)&&(()=>{const f=u.pending._1.toCam.zoom-s.toCam.zoom;return f<0?-f<.08:f<.08})()})()})()||i(u.pending._1,s)<=0?{acc:zt(u.acc)(u.pending._1),pending:w("Just",s)}:{acc:zt(zt(u.acc)({...u.pending._1,endT:s.startT-i(u.pending._1,s)}))({startT:s.startT-i(u.pending._1,s),endT:s.startT,fromCam:u.pending._1.toCam,toCam:s.toCam,easing:s.easing,interp:yi}),pending:w("Just",s)};g()})({acc:[],pending:T})(r);if(o.pending.tag==="Nothing")return o.acc;if(o.pending.tag==="Just")return zt(o.acc)(o.pending._1);g()},ih=t=>e=>{const n=r=>{const i=Ma(Yt,T,o=>o.kind==="Hold"||o.kind==="Move",r<1?[]:bt(0,r,e));if(i.tag==="Just")return i._1>=0&&i._1<e.length?w("Just",e[i._1].toCam):T;if(i.tag==="Nothing")return T;g()};return Qt(r=>i=>{if(i.kind==="Hold")return{startT:i.startT,endT:i.endT,fromCam:i.fromCam,toCam:i.toCam,easing:i.easing,interp:yi};if(i.kind==="Move")return{startT:i.startT,endT:i.endT,fromCam:i.fromCam,toCam:i.toCam,easing:dr,interp:yi};if(i.kind==="Gap")return{startT:i.startT,endT:i.endT,fromCam:(()=>{const o=n(r);if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;g()})(),toCam:(()=>{const o=n(r),u=(()=>{if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;g()})(),s=r+1|0,a=ir(Yt,T,c=>c.kind==="Hold"||c.kind==="Move",s<1?e:bt(s,e.length,e));if(a.tag==="Just"){const c=(r+1|0)+a._1|0;return c>=0&&c<e.length?e[c].fromCam:u}if(a.tag==="Nothing")return u;g()})(),easing:i.easing,interp:yi};g()})(e)},oh={padding:24,easing:dr,minZoom:.9,maxZoom:2.5,tokenZoomFloor:0,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:16},Zu=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:yc(o.w/r)(o.h/i)},uh=J(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?w("Just",t[n]):T;return r.tag==="Just"&&r._1.fromCam.zoom===r._1.toCam.zoom&&r._1.fromCam.center.x===r._1.toCam.center.x&&r._1.fromCam.center.y===r._1.toCam.center.y&&e.fromCam.zoom===e.toCam.zoom&&e.fromCam.center.x===e.toCam.center.x&&e.fromCam.center.y===e.toCam.center.y&&(()=>{const i=r._1.toCam.center.x-e.toCam.center.x;return(i<0?-i<8:i<8)&&(()=>{const o=r._1.toCam.center.y-e.toCam.center.y;return(o<0?-o<8:o<8)&&(()=>{const u=r._1.toCam.zoom-e.toCam.zoom;return u<0?-u<.08:u<.08})()})()})()?zt((()=>{const i=t.length-1|0;return i<1?[]:bt(0,i,t)})())({...r._1,endT:e.endT}):zt(t)(e)})([]),xi=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:mi(r)(fo(t.minZoom)(t.maxZoom)(Zu(e)(n)(t.padding)))}),sh=t=>e=>n=>r=>{const i=Lt(s=>a=>it.compare(a.priority)(s.priority)),o=xi(t)(e)(Ye(e))(0),u=ct(s=>s>=0&&s<=n,th(Lt(st.compare)([0,n,...Tt(r)(s=>[s.startT,s.endT]),...Tt(r)(s=>{if(s.pathFollow.tag==="Nothing")return[];if(s.pathFollow.tag==="Just")return H(a=>a.t)(s.pathFollow._1.samples);g()})])));return rh(t)(e)(o)(uh(ih(o)(xt(s=>{const a=(s._1+s._2)/2;if(s._2<=s._1)return T;const c=xt(d=>d.pathFollow)(i(ct(d=>d.startT<=a&&a<d.endT,r)));if(0<c.length)return w("Just",{kind:Zl,startT:s._1,endT:s._2,fromCam:{center:Nc(c[0].samples)(s._1),zoom:c[0].zoom},toCam:{center:Nc(c[0].samples)(s._2),zoom:c[0].zoom},easing:dr});const f=H(d=>d.bbox)(ct(d=>d.priority===J(Xl)(0)(H(l=>l.priority)(ct(l=>l.startT<=a&&a<l.endT,r))),ct(d=>d.startT<=a&&a<d.endT,r)));return f.length===0?w("Just",{kind:jl,startT:s._1,endT:s._2,fromCam:o,toCam:o,easing:t.easing}):w("Just",{kind:Ul,startT:s._1,endT:s._2,fromCam:xi(t)(e)(go(f))(Me(d=>d.priority>=1,ct(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),toCam:xi(t)(e)(go(f))(Me(d=>d.priority>=1,ct(d=>d.startT<=a&&a<d.endT,r))?t.tokenZoomFloor:0),easing:t.easing})})(Je(Hn,u,bt(1,u.length,u))))))},Jc=t=>e=>n=>r=>{const i=Zt(o=>r>=o.startT&&r<o.endT)(n);if(i.tag==="Just")return nh()(r)(i._1);if(i.tag==="Nothing"){const o=n.length-1|0;if(o>=0&&o<n.length&&r>=n[o].endT)return n[o].toCam;const u=xi(t)(e)(Ye(e))(0);return 0<n.length?n[0].fromCam:u}g()};function Cn(t){return t.charCodeAt(0)}function Tc(t){return String.fromCharCode(t)}const jn=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},_o=function(t){return function(e){return e.split(t)}},ah=function(t){return t.trim()},lo=function(t){return function(e){return e.join(t)}};var ch=typeof Array.from=="function",gh=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",fh=typeof String.prototype.fromCodePoint=="function",_h=typeof String.prototype.codePointAt=="function";const dh=function(t){return _h?function(e){return e.codePointAt(0)}:t},lh=function(t){return fh?String.fromCodePoint:t},hh=function(t){return function(e){return gh?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)}},ph=function(t){return function(e){return ch?function(n){return Array.from(n,e)}:t}},ho=t=>{const e=Xn(t);if(e===0)return T;if(e===1)return w("Just",{head:Cn(ai(0)(t)),tail:""});const n=Cn(ai(1)(t)),r=Cn(ai(0)(t));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?w("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:ci(2)(t)}):w("Just",{head:r,tail:ci(1)(t)})},mh=t=>{const e=ho(t);return e.tag==="Just"?w("Just",b(e._1.head,e._1.tail)):T},yh=t=>qe.unfoldr(mh)(t),vc=dh(t=>{const e=Cn(ai(0)(t));if(55296<=e&&e<=56319&&Xn(t)>1){const n=Cn(ai(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),po=ph(yh)(vc),Ku=t=>ro(t>=0&&t<=65535?Tc(t):t<0?"\0":"\uFFFF"),xh=lh(t=>t<=65535?Ku(t):Ku(En(t-65536|0,1024)+55296|0)+Ku(Yn(t-65536|0)(1024)+56320|0)),wc=t=>e=>{if(t<1)return"";const n=ho(e);return n.tag==="Just"?xh(n._1.head)+wc(t-1|0)(n._1.tail):e},me=hh(wc),Nh=t=>e=>e===""?T:w("Just",vc(e)),br=(t,e,n)=>({tag:t,_1:e,_2:n}),Jh=()=>({tag:"ExtendFromSource"}),Lr=(t,e)=>({tag:t,_1:e}),ts=t=>t,mo=(t,e)=>({tag:t,_1:e}),es=mo("NotYet"),bc=mo("Consumed"),Th=ts("FromSource"),Lc=ts("FromTarget"),kc=ts("FromBoth"),yo=Lr("Hidden"),vh=Lr("Visible"),ns=Jh(),xo=br("Retracted"),wh=br("Extended"),Ec=t=>t,rs=(t,e)=>({tag:t,_1:e}),kr=(t,e,n)=>({tag:t,_1:e,_2:n}),Gc=t=>t,lr=(t,e)=>({tag:t,_1:e}),Er=(t,e,n,r,i,o,u,s,a)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u,_7:s,_8:a}),Ni=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},yn=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Cc=Kt(C)(Bt),is=Tu(ti),Ji=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},No=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ti=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Sc=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},Dc=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},Gr=(()=>{const t=qe.unfoldr(e=>{if(e.tag==="Nil")return T;if(e.tag==="Cons")return w("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._3,n(r._6,i)));g()};return n(e,qt)})())})(),bh=J(t=>e=>j(C)(e)()(t))(Q),os=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},us=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Lh=lr("NoKeyframes"),kh=t=>lr("DuplicateEventId",t),Eh=t=>lr("UnknownEvent",t),Pc=Gc("PlopIn"),Gh=Gc("PlopOut"),Ch=Ec("DiveIn"),Sh=Ec("DiveOut"),Dh=t=>e=>n=>r=>{const i=Ni(r.edge)(e.edges),o=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return _i(i._1);g()})(),u=yn(t.minTokenDuration)(yn(rt(J(s=>a=>s+po(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}},Ph=t=>e=>Cc(xt(n=>{if(n.kind.tag==="SendToken")return w("Just",b(n.id,{pre:(()=>{const r=n.when;return(()=>{const i=n.kind._1.from;return Me(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 Me(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)),Ih=t=>{if(t.event.kind.tag==="SendToken")return w("Just",{startT:t.startT,endT:t.endT,target:Er("TokenWindow",t.event.id,t.event.kind._1.edge,t.event.kind._1.direction,t.event.kind._1.from,t.event.kind._1.to,t.event.kind._1.labels,t.holdPre,t.holdPost)});if(t.event.kind.tag==="FillNodeWithoutTransition")return w("Just",{startT:t.startT,endT:t.endT,target:Er("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},Qh=t=>e=>n=>r=>{const i=Zt(o=>is(o.path)(e)&&(qn(o.endT-n)<1e-4||qn(o.startT-r)<1e-4))(t.segments);if(i.tag==="Just")return w("Just",i._1);if(i.tag==="Nothing")return Zt(o=>is(o.path)(e))(t.segments);g()},Fh=t=>e=>n=>xt(r=>{const i=xt(o=>Ti(o)(t.nodes))(kt(Re.foldr,(()=>{if(r.scene.tag==="Structural")return Ge(C.compare,Le,(()=>{const o=Ji(r.scene._1.from)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()})(),(()=>{const o=Ji(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=Ji(r.scene._1.keyframe)(n);if(o.tag==="Nothing")return Q;if(o.tag==="Just")return o._1.nodes;g()}if(r.scene.tag==="EnterNode"||r.scene.tag==="ExitNode")return Q;g()})()));return i.length===0?T:w("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const o=J(u=>s=>({minX:No(u.minX)(s.x),minY:No(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})}),Ah=t=>e=>n=>{const r=Ni(n)(t);if(r.tag==="Nothing")return Lc;if(r.tag==="Just"){const i=Sc(r._1.target)(e);return Sc(r._1.source)(e)?i?kc:Th:Lc}g()},Mh={pre:0,post:0},Bh=t=>e=>n=>r=>i=>{const o=Dc(i.event.id)(n),u=(()=>{if(o.tag==="Nothing")return Mh;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=Zt(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=Zt(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 Dh(t)(e)(u)(i.event.kind._1);if(i.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return zt(r)({startT:s,endT:s+a.duration,event:i.event,holdPre:a.holdPre,holdPost:a.holdPost})},Ic=t=>e=>n=>J(Bh(t)(e)(Ph(t)(n)))([])(Qt(r=>i=>({event:i}))(n)),zh=t=>e=>{const n=Ti(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},Rh=t=>e=>({...e,fromCam:ju(t)(e.fromCam),toCam:ju(t)(e.toCam)}),Wh=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()},Qc={id:"",nodes:Q,edges:Q},Hh=t=>e=>Il((()=>{const n=Ji(e.from)(t);if(n.tag==="Nothing")return Qc;if(n.tag==="Just")return n._1;g()})())((()=>{const n=Ji(e.to)(t);if(n.tag==="Nothing")return Qc;if(n.tag==="Just")return n._1;g()})()),Oh=t=>e=>{const n=Ti(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:Q};if(n.tag==="Just")return n._1;g()},ss=t=>e=>n=>r=>{const i=Ni(r)(n.edges);if(i.tag==="Just")return t<=0?e:yn(e)(_i(i._1)/t);if(i.tag==="Nothing")return e;g()},Fc=t=>e=>n=>r=>i=>{const o=t.plop,u=Hh(n)(i),s=H(_=>({startT:0,endT:0+ss(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Er("EdgeWindow",_,rs("Extend",ns))}))(Gr(u.entering.edges)),a=H(_=>({startT:0,endT:o,target:Er("NodeWindow",_,Pc)}))(Gr(u.entering.nodes)),c=J(yn)(0)(H(_=>ss(t.edgeSpeed)(t.minEdgeDuration)(e)(_))(Gr(u.leaving.edges))),f=_=>Me(h=>{const m=Ni(h)(r);if(m.tag==="Just")return m._1.source===_||m._1.target===_;if(m.tag==="Nothing")return!1;g()},Gr(u.leaving.edges))?c:0,d=H(_=>({startT:f(_),endT:f(_)+t.plop,target:Er("NodeWindow",_,Gh)}))(Gr(u.leaving.nodes)),l=H(_=>({startT:0,endT:ss(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Er("EdgeWindow",_,rs("Retract",Ah(r)(u.leaving.nodes)(_)))}))(Gr(u.leaving.edges));return{duration:(()=>{const _=Lt(st.compare)([...H(m=>m.endT)(l),...H(m=>m.endT)(d),...H(m=>m.endT)(a),...H(m=>m.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+t.gap:t.gap})(),windows:[...l,...d,...a,...s]}},qh=t=>e=>n=>r=>i=>o=>H((()=>{const u=i.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())(Fc(t)(e)(n)(r)(o).windows),$h=t=>xt(e=>kt(Kr,e).length>1?w("Just",(()=>{const n=Ft(r=>T,r=>i=>w("Just",{head:r,tail:i}),kt(Kr,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):T)(ud(ti)(Lt(C.compare)(t))),Yh=t=>{const e=H(r=>r.id)(t),n=bh(e);return[...H(kh)($h(e)),...H(Eh)(ct(r=>!os(r)(n),Tt(t)(Wh)))]},Vh=t=>e=>n=>{const r=yn(t.minZoom)(t.tokenZoomFloor);return xt(i=>{if(i.target.tag==="NodeWindow"||i.target.tag==="EdgeWindow")return T;if(i.target.tag==="TokenWindow")return w("Just",(()=>{const o={pre:i.target._7,post:i.target._8};if(t.tokenZoomFloor<=0)return{startT:i.startT,endT:i.endT,bbox:hi(e)(n)(i.target._2),priority:1,pathFollow:T};const u=Ni(i.target._2)(e.edges);if(u.tag==="Just"){const s=Ti(i.target._4)(e.nodes);if(s.tag==="Just"){const a=Ti(i.target._5)(e.nodes);if(a.tag==="Just"){const c=a._1;return{startT:i.startT,endT:i.endT,bbox:hi(e)(n)(i.target._2),priority:1,pathFollow:w("Just",{samples:(()=>{const f=i.startT+o.pre*(i.endT-i.startT),d=yn(1e-4)(i.endT-o.post*(i.endT-i.startT)-f),l=i.endT-i.startT;return H(_=>{const h=f+rt(_)/rt(32)*d;return{t:h,pos:Ll(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:hi(e)(n)(i.target._2),priority:1,pathFollow:T};g()}if(s.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:hi(e)(n)(i.target._2),priority:1,pathFollow:T};g()}if(u.tag==="Nothing")return{startT:i.startT,endT:i.endT,bbox:hi(e)(n)(i.target._2),priority:1,pathFollow:T};g()})());if(i.target.tag==="FillWindow")return w("Just",{startT:i.startT,endT:i.endT,bbox:pc(e)(n)(Wt("Node",1,1,i.target._2,void 0,Q,Q)),priority:1,pathFollow:T});g()})},Xh=t=>e=>n=>r=>i=>sh(t)(i.layout)(r.endT)([...Fh(i.layout)(n)(e)(ct(o=>o.startT>=i.startT&&o.endT<=i.endT,r.spans)),...Vh(t)(i.layout)(n)(i.windows)]),Uh=t=>{const e=Cc(H(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(os(o)(i))return[lr("ScheduleCycle",[...kt(Re.foldr,i),o])];if(os(o)(r))return[];const u=Dc(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))},jh={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:.5,hatchHold:.4,tokenReadSecPerChar:.06,nodeEasing:Yl,edgeEasing:$l,tokenEasing:dr,diveDur:1.2,retreatDur:1.2},Zh=t=>e=>n=>r=>H((()=>{const i=n.startT;return o=>({...o,startT:o.startT+i,endT:o.endT+i})})())(xt(Ih)(Ic(t)(e)(r.events))),Kh=t=>e=>n=>r=>i=>{if(i.scene.tag==="Structural")return qh(t)(e)(n)(r)(i)(i.scene._1);if(i.scene.tag==="DataFlow")return Zh(t)(e)(i)(i.scene._1);if(i.scene.tag==="EnterNode")return[];if(i.scene.tag==="ExitNode")return[];g()},t0=t=>e=>n=>{const r=Ic(t)(e)(n.events);return r.length===0?t.gap:J(yn)(0)(H(i=>i.endT)(r))+t.gap},e0=t=>e=>n=>r=>i=>{if(i.tag==="Structural")return Fc(t)(e)(n)(r)(i._1).duration;if(i.tag==="DataFlow")return t0(t)(e)(i._1);if(i.tag==="EnterNode"||i.tag==="ExitNode")return 0;g()},Ac=t=>e=>n=>r=>i=>o=>{const u=El(e)(r),s=n.layout,a=dc(H(m=>b(m.id,m))(i.keyframes)),c=0<i.keyframes.length?w("Just",i.keyframes[0]):T,f=(()=>{if(c.tag==="Just")return c._1.id;if(c.tag==="Nothing")return"";g()})(),d=Ol(i),l=m=>({segments:m.runSpans.length===0?m.segments:zt(m.segments)({startT:m.runStart,endT:m.t,path:r,layout:s,placement:u,windows:m.runWindows,spans:m.runSpans,keyframes:a,initialKeyframe:f,edgeEndpoints:d}),spans:m.spans,windows:m.windows,dives:m.dives}),_=J(m=>p=>{if(p.tag==="EnterNode"){const v=l(m),k=m.t+t.diveDur,L=zt(r)(p._1),E=Ac(t)(e)(Oh(n)(p._1))(L)(zh(i)(p._1))(k),B=E.endT+t.retreatDur;return{...m,t:B,runStart:B,runSpans:[],runWindows:[],segments:[...v.segments,...E.segments],spans:[...v.spans,...E.spans],windows:[...v.windows,...E.windows],dives:[...v.dives,{startT:m.t,endT:k,node:p._1,parentPath:r,childPath:L,direction:Ch},...E.dives,{startT:E.endT,endT:B,node:p._1,parentPath:r,childPath:L,direction:Sh}]}}if(p.tag==="ExitNode")return m;const y=m.t+e0(t)(s)(a)(d)(p),x={startT:m.t,endT:y,scene:p},N=Kh(t)(s)(a)(d)(x);return{...m,t:y,runSpans:zt(m.runSpans)(x),runWindows:[...m.runWindows,...N],spans:zt(m.spans)(x),windows:[...m.windows,...N]}})({t:o,runStart:o,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(i.scenes),h=l(_);return{endT:_.t,spans:h.spans,windows:Lt(m=>p=>st.compare(m.startT)(p.startT))(h.windows),segments:h.segments,dives:h.dives}},n0=t=>e=>n=>n.endT<=t||n.startT>=e?T:w("Just",{...n,startT:yn(t)(n.startT),endT:No(e)(n.endT)}),as=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:No(Zu(e)(i)(t.padding*n.placement.scale))(40/(11*n.placement.scale))}},r0=t=>e=>n=>n.placement.scale===1&&n.placement.tx===0&&n.placement.ty===0?ju(n.placement)(xi(t)(n.layout)(Ye(n.layout))(0)):as(t)(e)(n),i0=t=>e=>n=>r=>xt(i=>{const o=Qh(r)(i.parentPath)(i.startT)(i.endT);if(o.tag==="Just"){const u=i.childPath,s=Zt(a=>is(a.path)(u))(r.segments);if(s.tag==="Just"){const a=r0(t)(e)(o._1),c=as(t)(e)(s._1);if(i.direction==="DiveIn")return w("Just",{startT:i.startT,endT:i.endT,fromCam:a,toCam:c,easing:dr,interp:xc});if(i.direction==="DiveOut")return w("Just",{startT:i.startT,endT:i.endT,fromCam:c,toCam:a,easing:dr,interp:xc});g()}if(s.tag==="Nothing")return T;g()}if(o.tag==="Nothing")return T;g()})(r.dives),o0=t=>e=>{if(e.tag==="Structural")return xt(n=>n)([us(e._1.from)(t)?T:w("Just",lr("UnknownKeyframe",e._1.from)),us(e._1.to)(t)?T:w("Just",lr("UnknownKeyframe",e._1.to))]);if(e.tag==="DataFlow")return[...xt(n=>n)([us(e._1.keyframe)(t)?T:w("Just",lr("UnknownKeyframe",e._1.keyframe))]),...Yh(e._1.events),...Uh(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()},u0=t=>e=>{const n=Tt(e)(o0(t));return n.length===0?St("Right",void 0):St("Left",n)},s0=t=>e=>n=>r=>Lt(i=>o=>st.compare(i.startT)(o.startT))(Tt(r.segments)(i=>i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0?xt(n0(i.startT)(i.endT))(H(Rh(i.placement))(Xh(t)(n)(i.edgeEndpoints)(r)(i))):[(()=>{const o=as(t)(e)(i);return{startT:i.startT,endT:i.endT,fromCam:o,toCam:o,easing:dr,interp:yi}})()])),a0=t=>e=>n=>r=>{if(0<n.keyframes.length){const i=n.keyframes[0],o=dc(H(s=>b(s.id,s))(n.keyframes)),u=u0(o)(n.scenes);return(()=>{if(u.tag==="Left"){const s=u._1;return a=>St("Left",s)}if(u.tag==="Right"){const s=u._1;return a=>a(s)}g()})()(()=>{const s=Ac(e)(r)(r)([])(n)(0);return St("Right",{totalDuration:s.endT,windows:s.windows,spans:s.spans,keyframes:o,initialKeyframe:i.id,timing:e,layout:r.layout,cameraSpans:[...s0(t)(r.layout)(o)(s),...i0(t)(r.layout)(o)(s)],cameraConfig:t,levelTree:r,segments:s.segments,dives:s.dives,seed:n.seed})})}return St("Left",[Lh])},cs=t=>e=>Math.imul(t,e),Cr=t=>{const e=t+1831565813|0,n=cs(e^e>>>15)(e|1),r=n^(n+cs(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=Cr(n);return{prng:r.prng,value:t+r.value*(e-t)}},gs=t=>e=>J(n=>r=>cs(n^r)(-2048144789))(e)(H(Cn)(Vn(t))),fs=t=>t,tn=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jo=Tu(ti),c0=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),Mc=Kt(C)(Bt),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=w("Just",o._4);continue}}g()}return i},zc=Bt.foldMap(il(C)),Rc=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},g0=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},Sr=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},f0=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},_0=Kt(C)(Bt),d0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},l0=Kt(C)(Bt),h0=fs("Backdrop"),Wc=fs("FlyThrough"),To=fs("Active"),Hc=t=>e=>n=>{const r=(t+e)/2,i=n-r,o=i<0?-1:1,u=(e-t)/2,s=u*.15,a=u-s,c=i<0?-i:i;return e<=t?(t+e)/2:c<=a?n:r+o*(u-s*Ui(-(c-a)/s))},p0=t=>e=>n=>r=>{const i=Ye(t),o=i.w/tn(1e-4)(e.zoom)/2,u=i.h/tn(1e-4)(e.zoom)/2,s=n.y-e.center.y,a=n.x-e.center.x;return{...e,center:{x:o<=1e-4?e.center.x+0*r*.35:a<0?e.center.x+a/(1+-a/o)*r*.35:e.center.x+a/(1+a/o)*r*.35,y:u<=1e-4?e.center.y+0*r*.35:s<0?e.center.y+s/(1+-s/u)*r*.35:e.center.y+s/(1+s/u)*r*.35}}},_s=t=>e=>n=>{const r=Zt(i=>Jo(i.path)(e)&&n>=i.startT&&n<i.endT)(t.segments);if(r.tag==="Just")return w("Just",r._1);if(r.tag==="Nothing")return Zt(i=>Jo(i.path)(e))(t.segments);g()},m0=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:Ou,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:Q}),y0=t=>H(e=>e<1?[]:bt(0,e,t))(It(0,t.length-1|0)),x0=t=>J(e=>n=>(e*31|0)+Cn(n)|0)(7)(Vn(t)),Oc=t=>e=>n=>({...n,state:{...n.state,nodes:Mc(H(r=>b(r._1,t(r._1)(r._2)))(c0(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)})()}}),ds=t=>e=>{const n=Bc(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.nodes;g()},ls=t=>e=>{const n=Bc(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.edges;g()},hs=t=>e=>{if(e<t.startT)return kr("AtKeyframe",t.initialKeyframe);const n=Zt(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return kr("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return kr("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return kr("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;return r>=0&&r<t.spans.length?kr("AtKeyframe",(()=>{if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return t.initialKeyframe;g()})()):kr("AtKeyframe",t.initialKeyframe)}g()},N0=J(t=>e=>{const n=Vi(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?zt(n._1.init)({...n._1.last,endT:tn(n._1.last.endT)(e.endT),windows:zt(n._1.last.windows)(e)}):zt(t)({endT:e.endT,windows:[e]})})([]),J0=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))(ct(r=>n<=r.endT+t,N0(Lt(r=>i=>st.compare(r.startT)(i.startT))(ct(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),T0=t=>e=>n=>Me(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),v0=t=>e=>n=>Me(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),w0=t=>e=>n=>Me(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),b0=t=>e=>n=>Me(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),L0=t=>e=>{const n=hs(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()},qc=t=>e=>n=>Zt(r=>n(r)&&e>=r.startT&&e<r.endT)(t),k0=t=>{const e=Rc(0)(1)(t/.2),n=Rc(0)(1)((1-t)/.2);return e*e*(3-2*e)*n*n*(3-2*n)},E0=t=>e=>{if(e.tag==="Travelling"){const n=g0(e._1.edge)(t.edges);if(n.tag==="Just"){const r=vr(n._1)(e._1.progress);return r.tag==="Just"?w("Just",{dot:r._1,weight:k0(e._1.progress)}):T}if(n.tag==="Nothing")return T;g()}return T},G0={segment:{startT:0,endT:0,path:[],layout:{nodes:Q,edges:Q,chipExtras:Q},placement:Ou,windows:[],spans:[],keyframes:Q,initialKeyframe:"",edgeEndpoints:Q},state:{nodes:Q,edges:Q,tokens:Q,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",visited:Q,nodeFadeAlpha:Q,nodeInvert:Q},bgAlpha:1,role:To},vo=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:G0},C0=t=>e=>{const n=hs(t)(e);if(n.tag==="AtKeyframe")return ds(t)(n._1);if(n.tag==="InTransition")return Ge(C.compare,Le,ds(t)(n._1),ds(t)(n._2));g()},S0=t=>e=>{const n=hs(t)(e);if(n.tag==="AtKeyframe")return ls(t)(n._1);if(n.tag==="InTransition")return Ge(C.compare,Le,ls(t)(n._1),ls(t)(n._2));g()},D0=t=>e=>{const n=t.w/tn(1e-4)(e.zoom),r=t.h/tn(1e-4)(e.zoom);return{...e,center:{x:n>=t.w?t.x+t.w/2:Hc(t.x+n/2)(t.x+t.w-n/2)(e.center.x),y:r>=t.h?t.y+t.h/2:Hc(t.y+r/2)(t.y+t.h-r/2)(e.center.y)}}},P0=t=>D0((()=>{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}})()),I0=t=>e=>{const n=t.endT-t.startT;return n<=0?1:tn(0)(Sr(1)((e-t.startT)/n))},$c=t=>e=>n=>tn(0)(Sr(1)((n-ae(0)(.3)(t+x0(e)|0).value)/tn(1e-4)(.7))),Yc=t=>e=>n=>Oc(r=>i=>i.tag==="Hidden"?yo:Lr("PloppingOut",r===e?tn(0)(Sr(1)((n-.45)/tn(1e-4)(.55))):$c(t)(r)(n)))(r=>r.tag==="Retracted"?xo:br("Retracting",kc,n)),Vc=t=>e=>Oc(n=>r=>r.tag==="Hidden"?yo:Lr("PloppingIn",$c(t)(n)(e)))(n=>n.tag==="Retracted"?xo:br("Extending",ns,e)),wo=t=>e=>{const n=t.endT-t.startT;return n<=0?1:tn(0)(Sr(1)((e-t.startT)/n))},Q0=t=>e=>n=>r=>i=>{const o=qc(e)(n)(u=>u.target.tag==="EdgeWindow"&&u.target._1===i);if(o.tag==="Just"){const u=Xu(t.timing.edgeEasing)(wo(o._1)(n)),s=o._1.target.tag==="EdgeWindow"?o._1.target._2:rs("Extend",ns);if(s.tag==="Retract")return br("Retracting",s._1,u);if(s.tag==="Extend")return br("Extending",s._1,u);g()}if(o.tag==="Nothing")return b0(e)(n)(i)||T0(e)(n)(i)?xo:f0(i)(r)?wh:xo;g()},F0=t=>e=>n=>{const r=S0(e)(n);return _0(H(i=>b(i,Q0(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 kt(Re.foldr,i(e.layout.edges))})()))},A0=t=>e=>n=>r=>{const i=qc(t)(e)(o=>o.target.tag==="NodeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=wo(i._1)(e),u=i._1.target.tag==="NodeWindow"?i._1.target._2:Pc;if(u==="PlopIn")return Lr("PloppingIn",o);if(u==="PlopOut")return Lr("PloppingOut",o);g()}if(i.tag==="Nothing")return w0(t)(e)(r)||v0(t)(e)(r)?yo:d0(r)(n)?vh:yo;g()},M0=t=>e=>n=>{const r=C0(e)(n);return Mc(H(i=>b(i,A0(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 kt(Re.foldr,i(e.layout.nodes))})()))},B0=t=>e=>n=>e.target.tag==="TokenWindow"?b(e.target._1,n<e.startT?es:n>=e.endT?bc:mo("Travelling",{edge:e.target._2,direction:e.target._3,progress:Xu(t.timing.tokenEasing)(wo(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?es:n>=e.endT?bc:mo("Filling",{node:e.target._2,progress:wo(e)(n),labels:e.target._3})):b("",es),z0=t=>e=>n=>l0(H(r=>B0(t)(r)(n))(ct(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),Dr=t=>e=>n=>({nodes:M0()(e)(n),edges:F0(t)(e)(n),tokens:z0(t)(e.windows)(n),camera:Jc(t.cameraConfig)(e.layout)(t.cameraSpans)(n),frameTitle:L0(e)(n),visited:J0(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:Q,nodeInvert:Q}),R0=t=>e=>n=>Aa(T,Sa,r=>r.direction==="DiveIn"&&Jo(r.parentPath)(e.path)&&n>=r.startT-.7&&n<r.startT?w("Just",{node:r.node,phase:(n-(r.startT-.7))/.7}):T,t.dives),W0=t=>e=>n=>r=>{const i=R0(t)(e)(n);if(i.tag==="Just"){const o=Oe(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()},Xc=t=>e=>xt(n=>{const r=Zt(i=>i.direction==="DiveIn"&&Jo(i.childPath)((()=>{const o=n.length+1|0;return o<1?[]:bt(0,o,e)})()))(t.dives);if(r.tag==="Just"){const i=_s(t)(n)(r._1.startT-1e-4);if(i.tag==="Just")return w("Just",{bgAlpha:1,role:h0,segment:i._1,state:{...Dr(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()})(y0(e)),Uc=t=>e=>{const n=ct(i=>e>=i.startT&&e<i.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:m0(t)},H0=t=>e=>n=>{const r=I0(n)(e),i=_s(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),o=_s(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),u=tn(0)(Sr(1)(r/.6)),s=tn(0)(Sr(1)((r-.4)/.6)),a=(()=>{if(n.direction==="DiveIn")return Yc(t.seed)(n.node)(u);if(n.direction==="DiveOut")return Vc(t.seed)(s);g()})(),c=(()=>{if(n.direction==="DiveIn")return Vc(t.seed)(s);if(n.direction==="DiveOut")return Yc(t.seed)(n.node)(u);g()})();return[...Xc(t)(n.parentPath),...(()=>{if(i.tag==="Just"){if(o.tag==="Just")return[a({segment:i._1,state:Dr(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:Wc}),c({segment:o._1,state:Dr(t)(o._1)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),bgAlpha:1,role:To})];if(o.tag==="Nothing")return[a({segment:i._1,state:Dr(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:Wc})];g()}if(i.tag==="Nothing")return[(()=>{const f=Uc(t)(e);return{segment:f,state:Dr(t)(f)(e),bgAlpha:1,role:To}})()];g()})()]},O0=t=>e=>{const n=xt(E0(t))((()=>{const r=(i,o)=>{if(i.tag==="Leaf")return o;if(i.tag==="Node")return r(i._5,Ot("Cons",i._4,r(i._6,o)));g()};return kt($t.foldr,r(e.tokens,qt))})());return 0<n.length?w("Just",n[0]):T},q0=t=>e=>{const n=O0(t)(e);if(n.tag==="Nothing")return e.camera;if(n.tag==="Just")return p0(t)(e.camera)(n._1.dot)(n._1.weight);g()},$0=t=>e=>t.placement.scale===1&&t.placement.tx===0&&t.placement.ty===0?q0(t.layout)(e):e.camera,Y0=t=>e=>Zt(n=>e>=n.startT&&e<n.endT)(t.dives),V0=t=>e=>{const n=Uc(t)(e),r=Dr(t)(n)(e),i=t.dives.length!==0,o=Jc(t.cameraConfig)(t.layout)(t.cameraSpans)(e),u=P0(n)($0(n)({...r,camera:o})),s=W0(t)(n)(e)({bgAlpha:1,role:To,segment:n,state:{...r,camera:u}}),a=Xc(t)(n.path),c=Y0(t)(e);if(c.tag==="Just")return{levels:H0(t)(e)(c._1),camera:o,rootLayout:t.layout,hasDives:i,diving:!0};if(c.tag==="Nothing")return{levels:zt(a)(s),camera:u,rootLayout:t.layout,hasDives:i,diving:!1};g()},jc=t=>t,Zc=jc("RunText"),X0=jc("RunCode"),Kc=t=>e=>n=>e.length===0?n:zt(n)({style:t,text:cr(e)}),U0=t=>({style:(()=>{if(t.style==="RunText")return X0;if(t.style==="RunCode")return Zc;g()})(),buf:[],runs:Kc(t.style)(t.buf)(t.runs)}),j0=t=>e=>0<e.length?{...t,buf:zt(t.buf)(e[0])}:{...t,buf:zt(t.buf)("\\")},Z0=t=>e=>{let n=t,r=e,i=!0,o;for(;i;){const u=n,s=Ft(a=>T,a=>c=>w("Just",{head:a,tail:c}),r);if(s.tag==="Nothing"){i=!1,o=u;continue}if(s.tag==="Just"){if(s._1.head==="\\"){n=j0(u)(s._1.tail),r=bt(1,s._1.tail.length,s._1.tail);continue}if(s._1.head==="`"){n=U0(u),r=s._1.tail;continue}n={...u,buf:zt(u.buf)(s._1.head)},r=s._1.tail;continue}g()}return o},tg=t=>{const e=Z0({style:Zc,buf:[],runs:[]})(Vn(t));return Kc(e.style)(e.buf)(e.runs)};let ps=null;function K0(){return ps||(typeof document>"u"?null:(ps=document.createElement("canvas").getContext("2d"),ps))}const eg=new Map,tp=t=>e=>n=>r=>()=>{const i=`${n} ${e}px ${t}|${r}`,o=eg.get(i);if(o!==void 0)return o;const u=K0();if(!u)return r.length*e*.62;u.font=`${n} ${e}px ${t}`;const s=u.measureText(r).width;return eg.set(i,s),s},ep=rr.traverse(xu),np=J(Tr)(0),Pr=(()=>{const t=jn(`\r
3
+ `)(" "),e=jn(`
4
+ `)(" "),n=(()=>{const r=jn("\r")(" "),i=(()=>{const o=jn(" ")(" ");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),ng=t=>e=>{const n=ep(r=>{const i=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;g()})();return tp(i.family)(i.size)(i.weight)(Pr(r.text))})(tg(Pr(e)));return()=>{const r=n();return np(r)}},rg={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"}},rp=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ir=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ip=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},op=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},up=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},ig=t=>cr(ke(or(e=>e===" ")(ke(or(e=>e===" ")(Vn(t)).rest)).rest)),sp=t=>J(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?w("Just",n._1):e)(T)(Qt(Hn)(t)),ms=t=>e=>{if(t<=0)return[e];if(Xn(e)<=t)return[e];const n=Vn(e),r=t<1?[]:bt(0,t,n),i=sp(r);if(i.tag==="Just"){const o=ig(rc(!(i._1>=0&&i._1<r.length)||r[i._1]===" "?i._1:i._1+1|0)(e)),u=ig(ci(i._1+1|0)(e));return u===""?[o]:[o,...ms(t)(u)]}if(i.tag==="Nothing"){const o=rc(t)(e),u=ci(t)(e);return u===""?[o]:[o,...ms(t)(u)]}g()},ap={cellW:7,cellH:3,maxLineWidth:20},cp=t=>e=>{const n=H(o=>b((()=>{if(o.label.tag==="Just")return o.label._1;if(o.label.tag==="Nothing")return o.id;g()})(),o))(e.nodes),r=Ir(1)(En((ip(t.maxLineWidth)(J(o=>u=>Ir(o)(Xn(u._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),i=(r*t.cellW|0)-1|0;return{...e,nodes:H(o=>{if(!(o._2.size._1===1&&o._2.size._2===1))return o._2;const u=Tt(_o(`
5
+ `)(o._1))(ms(i)),s=J(c=>f=>Ir(c)(Xn(f)))(0)(u),a=o._2.shape==="Cylinder"?Ir(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(Ir(1)(En(u.length+t.cellH|0,t.cellH))+(o._2.shape==="Cylinder"?1:0)|0))}})(n)}},gp=t=>e=>n=>({...n,nodes:H(r=>{const i=up(r.id)(e);if(i.tag==="Nothing")return r;if(i.tag==="Just")return{...r,size:b(op(r.size._1)(rt(Ir(1)(de(Xi(r.shape==="Cylinder"?(i._1+0)/t:(i._1+32)/t))))),r.size._2)};g()})(n.nodes)}),fp=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},_p=t=>{const e=t.length;return(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(a>=e){u=!1,s=c;continue}const f=d=>l=>{let _=d,h=l,m=!0,p;for(;m;){const y=_,x=h;if(y>=e){m=!1,p=x;continue}if(a>=0&&a<t.length){if(y>=0&&y<t.length){_=y+1|0,h=(()=>{const N=t[a].position,v=t[a].size,k=t[y].position,L=t[y].size;return N._1<k._1+L._1&&k._1<N._1+v._1&&N._2<k._2+L._2&&k._2<N._2+v._2})()?x+1|0:x;continue}_=y+1|0,h=x;continue}m=!1,p=x}return p};i=a+1|0,o=f(a+1|0)(c)}return s})(0)(0)},og=t=>J(e=>n=>e+ml(n.start)(n.end))(0)(t.segments),dp=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+og(i))(0)(e),maxEdgeLength:J(r=>i=>fp(r)(og(i)))(0)(e),nodeOverlapCount:_p(t),constraintViolations:n,jumpCount:J(r=>i=>r+i.jumps.length|0)(0)(e)}),ys=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=w("Just",o._4);continue}}g()}return i},xs=ys("LEFT"),lp=ys("RIGHT"),ug=ys("UNDEFINED"),hp={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},pp={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?Se:ye;if(e==="LEFT")return xe;if(t==="RIGHT")return e==="RIGHT"?Se:ye;if(e==="RIGHT")return xe;if(t==="UP")return e==="UP"?Se:ye;if(e==="UP")return xe;if(t==="DOWN")return e==="DOWN"?Se:ye;if(e==="DOWN")return xe;if(t==="UNDEFINED"&&e==="UNDEFINED")return Se;g()},Eq0:()=>hp},mp=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},yp={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()},vi=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()},xp=t=>J(e=>n=>Ve(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),Np=t=>{const e=J(n=>r=>{const i=Ut(r)(t.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just")return J(o=>u=>vt(it)(te)(u)([r])(o))(n)(i._1.constraints);g()})(Q)(t.cNodeOrder);return J(n=>r=>Ve(r)(i=>({...i,constraints:(()=>{const o=Ut(r)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})()}))(n))(t)(t.cNodeOrder)},Jp=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}})),Tp=t=>{const e=J(n=>r=>vi(r)(i=>({...i,outDegree:i.outDegreeReal}))(n))(t)(t.cGroupOrder);return J(n=>r=>Ve(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder)},sn={left:!1,right:!1,up:!1,down:!1},vp={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},Ns=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 w("Just",s);if(u.tag==="Just"){const c=Ut(u._1)(e.cNodes);if(c.tag==="Nothing")return w("Just",s);if(c.tag==="Just")return a._1.hitbox.x<c._1.hitbox.x?w("Just",s):w("Just",u._1)}}g()})(T)(r._1.cNodes),o=vi(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),Xe=t=>Ns({...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=>Ns({...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)})()}),sg=t=>{const e=J(n=>r=>vi(r)(i=>({...i,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return J(n=>r=>{const i=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?vi(a._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(vi(o)(c=>Be(xr)(s)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,s]})(u)):u;g()})(n)(i._1.constraints)}}g()})(e)(e.cNodeOrder)},bo=t=>{const e=Np(t.cGraph);return{...t,cGraph:sg(J(n=>r=>Ve(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},wp=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),an=t=>{const e={...t,cGraph:wp(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:sg((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);g()})())}},bp=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?an(r):e==="RIGHT"?an({...r,cGraph:Xe(r.cGraph)}):e==="UP"?an({...r,cGraph:xn(r.cGraph)}):e==="DOWN"?an({...r,cGraph:Xe(xn(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?bo({...r,cGraph:Xe(r.cGraph)}):e==="UP"?an({...r,cGraph:xn(r.cGraph)}):e==="DOWN"?an({...r,cGraph:Xe(xn(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?bo({...r,cGraph:Xe(r.cGraph)}):e==="UP"?an({...r,cGraph:xn(Xe(r.cGraph))}):e==="DOWN"?an({...r,cGraph:Xe(xn(Xe(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?an({...r,cGraph:xn(r.cGraph)}):e==="RIGHT"?an({...r,cGraph:Xe(xn(r.cGraph))}):e==="DOWN"?bo({...r,cGraph:Xe(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?an({...r,cGraph:xn(Xe(r.cGraph))}):e==="RIGHT"?an({...r,cGraph:Xe(xn(Xe(r.cGraph)))}):e==="UP"?bo({...r,cGraph:Xe(r.cGraph)}):r;g()},ag=t=>e=>e.finished||!mp(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:bp(e.direction)(t)(e),Lp=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?ag(xs)(t):t,n={...e,cGraph:Tp(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},cg=t=>e=>n=>{const r=Ut(t)(n.cNodes),i=Ut(e)(n.cGroups);return r.tag==="Just"&&i.tag==="Just"?(()=>{if(r._1.cGroup.tag==="Nothing")return!1;if(r._1.cGroup.tag==="Just")return!0;g()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:j(it)(t)({...r._1,cGroup:w("Just",e)})(n.cNodes),cGroups:j(it)(e)({...i._1,cNodes:Be(xr)(t)(i._1.cNodes)?i._1.cNodes:[...i._1.cNodes,t],reference:(()=>{if(i._1.reference.tag==="Nothing")return w("Just",t);if(i._1.reference.tag==="Just")return w("Just",i._1.reference._1);g()})()})(n.cGroups)}:n},gg=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:j(it)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:T,cGroupOffset:yp,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:sn})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),Js=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:J(r=>i=>cg(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)}},kp=t=>J(e=>n=>{const r=Ut(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?Js({master:T,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),Ep=t=>({cGraph:xp(kp(Ns(t))),direction:ug,compactionAlgorithm:T,constraintAlgorithm:T,spacingsHandler:vp,lockFun:T,finished:!1}),fg=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Gp=t=>e=>{const n=st.compare(t._1)(e._1);return n==="LT"?ye:n==="GT"?xe:it.compare(t._2)(e._2)},Cp=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),_g=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=it.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},dg=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",lg=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),hg=rt(4),pg=fg(0)(hg/2-.5),Sp=fg(0)(hg/2-.5),Lo=t=>e=>Gp(b(t.hitbox.x+t.hitbox.width/2,t.id))(b(e.hitbox.x+e.hitbox.width/2,e.id)),Dp=t=>e=>{const n=ir(Yt,T,r=>Lo(t)(r)==="LT",e);if(n.tag==="Just"){const r=Ba(Yt,T,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return zt(e)(t);g()},mg=t=>e=>{const n=ct(i=>Lo(i)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?w("Just",n[r]):T},Pp=t=>e=>{const n=Dp(e)(t.intervals),r=Zt(o=>Lo(e)(o)==="LT")(n),i=j(it)(e.id)((()=>{const o=mg(e)(n);return o.tag==="Just"?w("Just",o._1.id):T})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return j(it)(r._1.id)(w("Just",e.id))(i);if(r.tag==="Nothing")return i;g()})()}},Ip=t=>e=>{const n=st.compare(t.low?t.node.hitbox.y:t.node.hitbox.y+t.node.hitbox.height)(e.low?e.node.hitbox.y:e.node.hitbox.y+e.node.hitbox.height);return n==="EQ"?t.low?t.low&&!e.low?xe:Se:e.low?ye:Se:n},Qp=t=>J(e=>n=>Ve(n.id)(r=>({...r,constraints:[]}))(e))(t)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),Fp=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)(Cp(t)),yg=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}},xg=t=>e=>n=>J(r=>i=>n(i)?Ve(i.id)(yg(t))(r):r)(e)(xt(r=>Ut(r)(e.cNodes))(e.cNodeOrder)),Ap=t=>e=>{const n=(r,i,o)=>{const u=Ve(o)(yg(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))},Mp=t=>e=>{const n=mg(e)(t.intervals),r=Zt(o=>Lo(e)(o)==="LT")(t.intervals),i=n.tag==="Just"&&(()=>{const o=_g(e.id)(t.cand);return(o.tag==="Nothing"?!1:o.tag==="Just"&&(o._1.tag==="Nothing"?!1:o._1.tag==="Just"&&o._1._1===n._1.id))&&n._1.cGroup.tag==="Just"&&e.cGroup.tag==="Just"&&n._1.cGroup._1!==e.cGroup._1})()?vt(it)(te)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const o=_g(r._1.id)(t.cand);return(o.tag==="Nothing"?!1:o.tag==="Just"&&(o._1.tag==="Nothing"?!1:o._1.tag==="Just"&&o._1._1===e.id))&&e.cGroup.tag==="Just"&&r._1.cGroup.tag==="Just"&&e.cGroup._1!==r._1.cGroup._1})()?vt(it)(te)(e.id)([r._1.id])(i):i,intervals:ct(o=>o.id!==e.id,t.intervals)}},Bp=t=>e=>e.low?Pp(t)(e.node):Mp(t)(e.node),Ts=t=>e=>Fp(J(Bp)({intervals:[],cand:Q,constraints:Q})(Lt(Ip)(Tt(ct(t,xt(n=>Ut(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints)(e),zp=t=>Ts(e=>!0)(Ap(pg)(Ts(lg)(xg(pg)(Ts(dg)(xg(Sp)(t)(dg)))(lg)))),Rp=t=>zp(Qp(t.cGraph)),ko=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ng=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},vs=t=>e=>n=>r=>i=>({id:t,representedEdges:[i],affectedBends:[e,n],hitbox:{x:ko(e._1)(n._1),y:ko(e._2)(n._2),width:qn(e._1-n._1),height:qn(e._2-n._2)},ignoreSpacing:sn,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:T}),Wp=t=>e=>{const n=ko(t.hitbox.x)(e.hitbox.x),r=ko(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:Ng(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Ng(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()})()}},Hp=t=>e=>qn(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,Op=t=>e=>qn(t.hitbox.x-e.hitbox.x)<=1e-4?st.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?ye:xe,Jg=(t,e)=>({tag:t,_1:e}),ws=Kt(C)(Bt),Eo=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},Tg=(()=>{const t={eq:n=>r=>n._1===r._1&&(n._2.tag==="Nothing"?r._2.tag==="Nothing":n._2.tag==="Just"&&r._2.tag==="Just"&&n._2._1===r._2._1)},e={compare:n=>r=>{const i=C.compare(n._1)(r._1);if(i==="LT")return ye;if(i==="GT")return xe;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?Se:ye;if(r._2.tag==="Nothing")return xe;if(n._2.tag==="Just"&&r._2.tag==="Just")return C.compare(n._2._1)(r._2._1);g()},Eq0:()=>t};return J(n=>r=>j(e)(r)()(n))(Q)})(),Sn=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},qp=J(t=>e=>j(pp)(e)()(t))(Q),bs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=sc.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},$p=t=>e=>{const n=ws(H(o=>b(o.id,o))(t)),r=xt(o=>Eo(o)(n))(e),i=it.compare((()=>{const o=Tg(H(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=Tg(H(u=>b(u.to.node,u.to.port))(r));if(o.tag==="Leaf")return 0;if(o.tag==="Node")return o._2;g()})());if(i==="LT")return{...sn,left:!0,right:!1};if(i==="GT")return{...sn,left:!1,right:!0};if(i==="EQ")return sn;g()},Yp=t=>xt(e=>{if(e.direction==="V")return w("Just",{start:e.start,end:e.end});if(e.direction==="H")return T;g()})(t.segments),Go=t=>e=>n=>{if(n.tag==="Just"){const r=Sn(e)(t);if(r.tag==="Just"){const i=Zt(o=>o.id===n._1)(r._1);if(i.tag==="Just")return i._1.side;if(i.tag==="Nothing")return pn;g()}if(r.tag==="Nothing")return pn;g()}if(n.tag==="Nothing")return pn;g()},Vp=t=>e=>n=>{const r=gg({origin:w("Just",Jg("SegmentOrigin",n)),kind:w("Just","vs"),hitbox:n.hitbox})(e.cGraph),i=Jp(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 cg(r.id)(o._1.cGroup._1)(i);if(o._1.cGroup.tag==="Nothing")return i;g()}if(o.tag==="Nothing")return i;g()}return Js({master:w("Just",r.id),nodes:[r.id]})(i).graph})(),edgeToCs:J(o=>u=>vt(C)(te)(u)([r.id])(o))(e.edgeToCs)(n.representedEdges),lockMap:j(it)(r.id)($p(t)(n.representedEdges))(e.lockMap)}},Xp=t=>e=>n=>{const r=Ft(i=>T,i=>o=>w("Just",{head:i,tail:o}),Lt(Op)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const i=J(o=>u=>Hp(o.survivor)(u)?{...o,survivor:Wp(o.survivor)(u)}:{survivor:u,merged:[...o.merged,o.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return J(Vp(t))(n)([...i.merged,i.survivor])}g()},Up=t=>({cGraph:{cNodes:Q,cNodeOrder:[],cGroups:Q,cGroupOrder:[],supportedDirections:qp([ug,xs,lp]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:Q,edgeToCs:Q,lockMap:Q}),jp=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}},Zp=t=>e=>n=>J(r=>i=>{const o=gg({origin:w("Just",Jg("NodeOrigin",i.node)),kind:T,hitbox:jp(i)})(r.cGraph),u=Sn(i.node)(t),s=(()=>{if(u.tag==="Nothing")return b(0,0);if(u.tag==="Just")return u._1;g()})();return{...r,cGraph:Js({master:w("Just",o.id),nodes:[o.id]})(o.graph).graph,nodeToC:j(C)(i.node)(o.id)(r.nodeToC),lockMap:j(it)(o.id)((()=>{const a=s._1-s._2|0;return a<0?{...sn,left:!0}:a>0?{...sn,right:!0}:sn})())(r.lockMap)}})(n)(e),Kp=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),tm=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)),em=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)),nm=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(sc)(o)(r)(i))(e)(n.origin._1._1.affectedBends)}return e})(Q)(xt(e=>Ut(e)(t.cNodes))(t.cNodeOrder)),vg=t=>{const e=ws(H(n=>b(n.id,n))(t.edges));return xt(n=>{const r=Eo(n.edge)(e);if(r.tag==="Just")return n.reversed?w("Just",{edgeId:n.edge,src:r._1.to.node,tgt:r._1.from.node,srcSide:Go(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:Go(t.ports)(r._1.from.node)(r._1.from.port),path:n}):w("Just",{edgeId:n.edge,src:r._1.from.node,tgt:r._1.to.node,srcSide:Go(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:Go(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return T;g()})(t.paths)},rm=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=Sn(r.tgt)(t.nodeToC),o=(()=>{if(i.tag==="Just")return Ut(i._1)(t.cGraph.cNodes);if(i.tag==="Nothing")return T;g()})(),u=Sn(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 w("Just",{srcGroup:s._1.cGroup._1,tgtGroup:o._1.cGroup._1,delta:0,weight:100});if(o._1.cGroup.tag==="Nothing")return T;g()}if(s._1.cGroup.tag==="Nothing")return T;g()}if(o.tag==="Nothing")return T;g()}if(s.tag==="Nothing")return T;g()})(),c=_=>h=>m=>{if(s.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(m.cGroup.tag==="Just")return _(m.hitbox.x)&&m.cGroup._1!==s._1.cGroup._1?w("Just",h(m.cGroup._1)(s._1.cGroup._1)):T;if(m.cGroup.tag==="Nothing")return T;g()}if(s._1.cGroup.tag==="Nothing")return T;g()}if(s.tag==="Nothing")return T;g()},f=xt(_=>Ut(_)(t.cGraph.cNodes))((()=>{const _=Eo(r.edgeId)(t.edgeToCs);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})()),d=(()=>{if(s.tag==="Just"&&r.srcSide==="West"){const _=s._1;return xt(c(h=>h<_.hitbox.x)(h=>m=>({srcGroup:h,tgtGroup:m,delta:1,weight:100})))(f)}return[]})(),l=(()=>{if(s.tag==="Just"&&r.tgtSide==="East"){const _=s._1;return xt(c(h=>h>_.hitbox.x)(h=>m=>({srcGroup:m,tgtGroup:h,delta:1,weight:100})))(f)}return[]})();if(a.tag==="Nothing")return[];if(a.tag==="Just")return[a._1,...d,...l];g()});return{sameEdgeVerticalSegments:r=>i=>r.origin.tag==="Just"&&r.origin._1.tag==="SegmentOrigin"&&i.origin.tag==="Just"&&i.origin._1.tag==="SegmentOrigin"&&(()=>{const o=i.origin._1._1;return Me(u=>Be(gn)(u)(o.representedEdges),r.origin._1._1.representedEdges)})(),vsLNodePair:r=>i=>r.origin.tag==="Just"&&i.origin.tag==="Just"&&(r.origin._1.tag==="SegmentOrigin"?i.origin._1.tag==="NodeOrigin":r.origin._1.tag==="NodeOrigin"&&i.origin._1.tag==="SegmentOrigin"),edgeLengthEdges:r=>n}},im=t=>e=>{const n=rt(4),r=tm(t),i=em(t),o=ws(H(s=>b(s.id,b(s.from.node,s.to.node)))(e.edges)),u=nm(t);return{nodes:H(s=>{const a=Sn(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:H(s=>{const a=Eo(s.edge)(o),c=(()=>{if(a.tag==="Nothing")return s.segments;if(a.tag==="Just"){const f=Sn(a._1._1)(i),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})(),l=Sn(a._1._2)(i),_=(()=>{if(l.tag==="Nothing")return 0;if(l.tag==="Just")return l._1;g()})();return Qt((()=>{const h=s.reversed?_:d,m=s.reversed?d:_,p=s.segments.length;return y=>x=>{if(x.direction==="V"){const N=(()=>{if(y===0)return h;if(y===(p-1|0))return m;const v=bs(x.start)(u);if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})();return{...x,start:b(x.start._1+N,x.start._2),end:b(x.end._1+N,x.end._2)}}if(x.direction==="H")return{...x,start:b((()=>{if(y===0)return x.start._1+h;const N=bs(x.start)(u);if(N.tag==="Nothing")return x.start._1+0;if(N.tag==="Just")return x.start._1+N._1;g()})(),x.start._2),end:b((()=>{if(y===(p-1|0))return x.end._1+m;const N=bs(x.end)(u);if(N.tag==="Nothing")return x.end._1+0;if(N.tag==="Just")return x.end._1+N._1;g()})(),x.end._2)};g()}})())(s.segments)}g()})();return{...s,segments:c,bends:Je(f=>d=>f.end,c,bt(1,c.length,c))}})(e.paths)}},om=t=>e=>n=>r=>i=>o=>{const u=vs(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})()]}},wg=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...vs(o.nextId)(r.start)(b(r.start._1,i.down?n.y:n.y+n.height))(w("Just",e))(t.edgeId),aPort:w("Just",{node:t.src,side:i.side}),ignoreSpacing:i.down?{...sn,down:!0}:{...sn,up:!0}}]}),Co=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...vs(o.nextId)(r.end)(b(r.end._1,i.down?n.y:n.y+n.height))(w("Just",e))(t.edgeId),aPort:w("Just",{node:t.tgt,side:i.side}),ignoreSpacing:i.down?{...sn,down:!0}:{...sn,up:!0}}]}),um=t=>e=>n=>{const r=Sn(n.src)(t.nodeToC),i=Sn(n.tgt)(t.nodeToC),o=(()=>{if(r.tag==="Just"){const f=Ut(r._1)(t.cGraph.cNodes);return f.tag==="Just"?w("Just",f._1.hitbox):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"?w("Just",f._1.hitbox):T}if(i.tag==="Nothing")return T;g()})(),s=Yp(n.path),a=J(om(n)(o)(u)(s.length-1|0))(e)(Qt(f=>d=>b(f,d))(s));if(0<s.length){const f=(()=>{if(r.tag==="Just"&&o.tag==="Just"){if(n.srcSide==="North")return wg(n)(r._1)(o._1)(s[0])({side:le,down:!0})(a);if(n.srcSide==="South")return wg(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 Co(n)(i._1)(u._1)(s[d])({side:le,down:!0})(f);if(n.tgtSide==="South")return Co(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 Co(n)(i._1)(u._1)(s[c])({side:le,down:!0})(a);if(n.tgtSide==="South")return Co(n)(i._1)(u._1)(s[c])({side:he,down:!1})(a)}return a},sm=t=>e=>n=>Xp(t)(J(um(n))({nextId:0,segments:[]})(e).segments)(n),am=t=>sm(t.edges)(vg(t))(Zp(Kp(t.edges))(t.nodes)(Up())),Dn=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},Ls=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ks=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=it.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},cm=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},gm=t=>{const e=t.Eq0();return n=>r=>{const i=s=>{let a=s,c=!0,f;for(;c;){const d=a,l=Ft(_=>T,_=>h=>w("Just",{head:_,tail:h}),d.queue);if(l.tag==="Nothing"){c=!1,f=d;continue}if(l.tag==="Just"){const _=l._1.head;if((m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=!1;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){y=!1,x=!0;continue}}g()}return x})(d.removedNodes)){a={...d,queue:l._1.tail};continue}const h=Zt(m=>!Dn(m.eid)(d.removedEdges)&&(e.eq(m.src)(_)||e.eq(m.tgt)(_)))(r);if(h.tag==="Nothing"){a={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const m=e.eq(h._1.src)(_)?h._1.tgt:h._1.src,p={...d,degree:j(t)(m)((()=>{const y=(x=>{let N=x,v=!0,k;for(;v;){const L=N;if(L.tag==="Leaf"){v=!1,k=T;continue}if(L.tag==="Node"){const E=t.compare(m)(L._3);if(E==="LT"){N=L._5;continue}if(E==="GT"){N=L._6;continue}if(E==="EQ"){v=!1,k=w("Just",L._4);continue}}g()}return k})(d.degree);if(y.tag==="Nothing")return-1;if(y.tag==="Just")return y._1-1|0;g()})())(d.degree),removedNodes:j(t)(_)()(d.removedNodes),removedEdges:j(it)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:_,neighbour:m,viaSrc:e.eq(h._1.src)(_)}],queue:l._1.tail};if((()=>{const y=(N=>{let v=N,k=!0,L;for(;k;){const E=v;if(E.tag==="Leaf"){k=!1,L=T;continue}if(E.tag==="Node"){const B=t.compare(m)(E._3);if(B==="LT"){v=E._5;continue}if(B==="GT"){v=E._6;continue}if(B==="EQ"){k=!1,L=w("Just",E._4);continue}}g()}return L})(p.degree),x=N=>{let v=N,k=!0,L;for(;k;){const E=v;if(E.tag==="Leaf"){k=!1,L=!1;continue}if(E.tag==="Node"){const B=t.compare(m)(E._3);if(B==="LT"){v=E._5;continue}if(B==="GT"){v=E._6;continue}if(B==="EQ"){k=!1,L=!0;continue}}g()}return L};return(()=>{if(y.tag==="Nothing")return!1;if(y.tag==="Just")return y._1===1;g()})()&&!x(p.removedNodes)})()){a={...p,queue:[...p.queue,m]};continue}a=p;continue}}g()}return f},o=J(s=>a=>vt(t)(oe)(a.src)(1)(vt(t)(oe)(a.tgt)(1)(s)))(Q)(r),u=i({degree:o,removedNodes:Q,removedEdges:Q,record:[],queue:ct(s=>{const a=(c=>{let f=c,d=!0,l;for(;d;){const _=f;if(_.tag==="Leaf"){d=!1,l=T;continue}if(_.tag==="Node"){const h=t.compare(s)(_._3);if(h==="LT"){f=_._5;continue}if(h==="GT"){f=_._6;continue}if(h==="EQ"){d=!1,l=w("Just",_._4);continue}}g()}return l})(o);if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1===1;g()},n)});return{coreNodes:ct(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:ct(s=>!Dn(s.eid)(u.removedEdges),r),removed:u.record}}},fm=t=>e=>n=>J(r=>i=>{const o=i.neighbour,u=(()=>{const s=(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=T;continue}if(l.tag==="Node"){const _=t.compare(o)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=w("Just",l._4);continue}}g()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})();return j(t)(i.node)(i.viaSrc?u-1|0:u+1|0)(r)})(n)(ke(e)),Es=t=>{const e=t.Eq0();return n=>r=>i=>{const o={...i,treeNode:j(t)(r)()(i.treeNode)};return J(u=>s=>{if(Dn(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=_,m=!0,p;for(;m;){const y=h;if(y.tag==="Leaf"){m=!1,p=!1;continue}if(y.tag==="Node"){const x=t.compare(f)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){m=!1,p=!0;continue}}g()}return p},l=s.tgt;return d(a.treeNode)&&!(_=>{let h=_,m=!0,p;for(;m;){const y=h;if(y.tag==="Leaf"){m=!1,p=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){m=!1,p=!0;continue}}g()}return p})(a.treeNode)})()?s.src:(()=>{const f=s.tgt,d=_=>{let h=_,m=!0,p;for(;m;){const y=h;if(y.tag==="Leaf"){m=!1,p=!1;continue}if(y.tag==="Node"){const x=t.compare(f)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){m=!1,p=!0;continue}}g()}return p},l=s.src;return d(a.treeNode)&&!(_=>{let h=_,m=!0,p;for(;m;){const y=h;if(y.tag==="Leaf"){m=!1,p=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){m=!1,p=!0;continue}}g()}return p})(a.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(Dn(s.eid)(a.treeEdge)){if((d=>{let l=d,_=!0,h;for(;_;){const m=l;if(m.tag==="Leaf"){_=!1,h=!1;continue}if(m.tag==="Node"){const p=t.compare(c)(m._3);if(p==="LT"){l=m._5;continue}if(p==="GT"){l=m._6;continue}if(p==="EQ"){_=!1,h=!0;continue}}g()}return h})(a.treeNode))return{...u,st:a};const f=Es(t)(n)(c)(a);return{count:u.count+f.count|0,st:f.st}}if((()=>{const f=l=>{let _=l,h=!0,m;for(;h;){const p=_;if(p.tag==="Leaf"){h=!1,m=!1;continue}if(p.tag==="Node"){const y=t.compare(c)(p._3);if(y==="LT"){_=p._5;continue}if(y==="GT"){_=p._6;continue}if(y==="EQ"){h=!1,m=!0;continue}}g()}return m},d=s.tgt;return!f(a.treeNode)&&(()=>{const l=(m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const v=t.compare(d)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){y=!1,x=w("Just",N._4);continue}}g()}return x})(a.layer),_=s.src,h=(m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){y=!1,x=w("Just",N._4);continue}}g()}return x})(a.layer);if(l.tag==="Nothing"){if(h.tag==="Nothing")return s.delta===0;if(h.tag==="Just")return s.delta===-h._1;g()}if(l.tag==="Just"){if(h.tag==="Nothing")return s.delta===(l._1-0|0);if(h.tag==="Just")return s.delta===(l._1-h._1|0)}g()})()})()){const f=Es(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})(ct(u=>(e.eq(u.src)(r)||e.eq(u.tgt)(r))&&!Dn(u.eid)(o.edgeVisited),n))}},So=t=>e=>n=>r=>{const i=r.src,o=(l=>{let _=l,h=!0,m;for(;h;){const p=_;if(p.tag==="Leaf"){h=!1,m=T;continue}if(p.tag==="Node"){const y=t.compare(i)(p._3);if(y==="LT"){_=p._5;continue}if(y==="GT"){_=p._6;continue}if(y==="EQ"){h=!1,m=w("Just",p._4);continue}}g()}return m})(e.poID),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})(),s=r.tgt,a=(l=>{let _=l,h=!0,m;for(;h;){const p=_;if(p.tag==="Leaf"){h=!1,m=T;continue}if(p.tag==="Node"){const y=t.compare(s)(p._3);if(y==="LT"){_=p._5;continue}if(y==="GT"){_=p._6;continue}if(y==="EQ"){h=!1,m=w("Just",p._4);continue}}g()}return m})(e.poID),c=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})(),f=(l=>{let _=l,h=!0,m;for(;h;){const p=_;if(p.tag==="Leaf"){h=!1,m=T;continue}if(p.tag==="Node"){const y=t.compare(n)(p._3);if(y==="LT"){_=p._5;continue}if(y==="GT"){_=p._6;continue}if(y==="EQ"){h=!1,m=w("Just",p._4);continue}}g()}return m})(e.poID),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return(()=>{const l=r.src,_=(h=>{let m=h,p=!0,y;for(;p;){const x=m;if(x.tag==="Leaf"){p=!1,y=T;continue}if(x.tag==="Node"){const N=t.compare(l)(x._3);if(N==="LT"){m=x._5;continue}if(N==="GT"){m=x._6;continue}if(N==="EQ"){p=!1,y=w("Just",x._4);continue}}g()}return y})(e.lowestPoID);return(()=>{if(_.tag==="Nothing")return 0<=d;if(_.tag==="Just")return _._1<=d;g()})()&&(()=>{const h=r.tgt;return d<=u&&(()=>{const m=(p=>{let y=p,x=!0,N;for(;x;){const v=y;if(v.tag==="Leaf"){x=!1,N=T;continue}if(v.tag==="Node"){const k=t.compare(h)(v._3);if(k==="LT"){y=v._5;continue}if(k==="GT"){y=v._6;continue}if(k==="EQ"){x=!1,N=w("Just",v._4);continue}}g()}return N})(e.lowestPoID);return(()=>{if(m.tag==="Nothing")return 0<=d;if(m.tag==="Just")return m._1<=d;g()})()&&d<=c})()})()})()?u>=c:u<c},_m=t=>{const e=Kt(t)(Bt);return n=>({layer:e(H(r=>b(r,0))(n)),treeNode:Q,treeEdge:Q,poID:Q,lowestPoID:Q,cutvalue:Q,postOrder:1,edgeVisited:Q})},dm=t=>e=>n=>J(r=>i=>{if((()=>{const f=i.src,d=h=>{let m=h,p=!0,y;for(;p;){const x=m;if(x.tag==="Leaf"){p=!1,y=!1;continue}if(x.tag==="Node"){const N=t.compare(f)(x._3);if(N==="LT"){m=x._5;continue}if(N==="GT"){m=x._6;continue}if(N==="EQ"){p=!1,y=!0;continue}}g()}return y},l=i.tgt,_=h=>{let m=h,p=!0,y;for(;p;){const x=m;if(x.tag==="Leaf"){p=!1,y=!1;continue}if(x.tag==="Node"){const N=t.compare(l)(x._3);if(N==="LT"){m=x._5;continue}if(N==="GT"){m=x._6;continue}if(N==="EQ"){p=!1,y=!0;continue}}g()}return y};return d(n.treeNode)===_(n.treeNode)})())return r;const o=i.tgt,u=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const m=t.compare(o)(h._3);if(m==="LT"){d=h._5;continue}if(m==="GT"){d=h._6;continue}if(m==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(n.layer),s=i.src,a=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const m=t.compare(s)(h._3);if(m==="LT"){d=h._5;continue}if(m==="GT"){d=h._6;continue}if(m==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(n.layer),c=(()=>{if(u.tag==="Nothing"){if(a.tag==="Nothing")return-i.delta;if(a.tag==="Just")return-a._1-i.delta|0;g()}if(u.tag==="Just"){if(a.tag==="Nothing")return(u._1-0|0)-i.delta|0;if(a.tag==="Just")return(u._1-a._1|0)-i.delta|0}g()})();return c<r.slack?{edge:w("Just",i),slack:c}:r})({edge:T,slack:1e9})(e).edge,lm=t=>{const e=Kt(t)(Bt);return n=>r=>{const i=J(o=>u=>Ls(o)((()=>{const s=(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=T;continue}if(l.tag==="Node"){const _=t.compare(u)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=w("Just",l._4);continue}}g()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(1e9)(n);return e(H(o=>b(o,(()=>{const u=(s=>{let a=s,c=!0,f;for(;c;){const d=a;if(d.tag==="Leaf"){c=!1,f=T;continue}if(d.tag==="Node"){const l=t.compare(o)(d._3);if(l==="LT"){a=d._5;continue}if(l==="GT"){a=d._6;continue}if(l==="EQ"){c=!1,f=w("Just",d._4);continue}}g()}return f})(r);if(u.tag==="Nothing")return-i;if(u.tag==="Just")return u._1-i|0;g()})()))(n))}},bg=t=>{const e=t.Eq0();return n=>r=>i=>{const o=J(s=>a=>{const c=bg(t)(n)(e.eq(a.src)(r)?a.tgt:a.src)({...s.st,edgeVisited:j(it)(a.eid)()(s.st.edgeVisited)});return{lowest:Ls(s.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:i})(ct(s=>Dn(s.eid)(i.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!Dn(s.eid)(i.edgeVisited),n)),u=Ls(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}}}},Lg=t=>{const e=bg(t);return n=>r=>i=>0<n.length?e(r)(n[0])({...i,edgeVisited:Q,postOrder:1,poID:Q,lowestPoID:Q}).st:i},hm=t=>{const e=t.Eq0();return n=>r=>i=>ct(o=>Dn(o.eid)(r.treeEdge)&&(e.eq(o.src)(i)||e.eq(o.tgt)(i)),n)},pm=t=>e=>Zt(n=>{const r=ks(n.eid)(e.cutvalue);return Dn(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),kg=t=>{const e=Es(t);return n=>r=>i=>{const o=0<n.length?w("Just",n[0]):T;if(o.tag==="Nothing")return i;if(o.tag==="Just"){const u=e(r)(o._1)({...i,edgeVisited:Q,treeNode:Q,treeEdge:Q});if(u.count>=n.length)return u.st;const s=dm(t)(r)(u.st);if(s.tag==="Nothing")return u.st;if(s.tag==="Just"){const a=s._1.tgt,c=(h=>{let m=h,p=!0,y;for(;p;){const x=m;if(x.tag==="Leaf"){p=!1,y=T;continue}if(x.tag==="Node"){const N=t.compare(a)(x._3);if(N==="LT"){m=x._5;continue}if(N==="GT"){m=x._6;continue}if(N==="EQ"){p=!1,y=w("Just",x._4);continue}}g()}return y})(u.st.layer),f=s._1.src,d=(h=>{let m=h,p=!0,y;for(;p;){const x=m;if(x.tag==="Leaf"){p=!1,y=T;continue}if(x.tag==="Node"){const N=t.compare(f)(x._3);if(N==="LT"){m=x._5;continue}if(N==="GT"){m=x._6;continue}if(N==="EQ"){p=!1,y=w("Just",x._4);continue}}g()}return y})(u.st.layer),l=(()=>{if(c.tag==="Nothing"){if(d.tag==="Nothing")return-s._1.delta;if(d.tag==="Just")return-d._1-s._1.delta|0;g()}if(c.tag==="Just"){if(d.tag==="Nothing")return(c._1-0|0)-s._1.delta|0;if(d.tag==="Just")return(c._1-d._1|0)-s._1.delta|0}g()})(),_=(()=>{const h=s._1.tgt;return(m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=!1;continue}if(N.tag==="Node"){const v=t.compare(h)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){y=!1,x=!0;continue}}g()}return x})(u.st.treeNode)})()?-l:l;return kg(t)(n)(r)({...u.st,layer:J(h=>m=>(p=>{let y=p,x=!0,N;for(;x;){const v=y;if(v.tag==="Leaf"){x=!1,N=!1;continue}if(v.tag==="Node"){const k=t.compare(m)(v._3);if(k==="LT"){y=v._5;continue}if(k==="GT"){y=v._6;continue}if(k==="EQ"){x=!1,N=!0;continue}}g()}return N})(u.st.treeNode)?j(t)(m)((()=>{const p=(y=>{let x=y,N=!0,v;for(;N;){const k=x;if(k.tag==="Leaf"){N=!1,v=T;continue}if(k.tag==="Node"){const L=t.compare(m)(k._3);if(L==="LT"){x=k._5;continue}if(L==="GT"){x=k._6;continue}if(L==="EQ"){N=!1,v=w("Just",k._4);continue}}g()}return v})(u.st.layer);if(p.tag==="Nothing")return 0+_|0;if(p.tag==="Just")return p._1+_|0;g()})())(h):h)(u.st.layer)(n)})}}g()}},mm=t=>e=>n=>r=>J(i=>o=>{if(So(t)(r)(o.src)(n)&&!So(t)(r)(o.tgt)(n)){const u=o.tgt,s=(d=>{let l=d,_=!0,h;for(;_;){const m=l;if(m.tag==="Leaf"){_=!1,h=T;continue}if(m.tag==="Node"){const p=t.compare(u)(m._3);if(p==="LT"){l=m._5;continue}if(p==="GT"){l=m._6;continue}if(p==="EQ"){_=!1,h=w("Just",m._4);continue}}g()}return h})(r.layer),a=o.src,c=(d=>{let l=d,_=!0,h;for(;_;){const m=l;if(m.tag==="Leaf"){_=!1,h=T;continue}if(m.tag==="Node"){const p=t.compare(a)(m._3);if(p==="LT"){l=m._5;continue}if(p==="GT"){l=m._6;continue}if(p==="EQ"){_=!1,h=w("Just",m._4);continue}}g()}return h})(r.layer),f=(()=>{if(s.tag==="Nothing"){if(c.tag==="Nothing")return-o.delta;if(c.tag==="Just")return-c._1-o.delta|0;g()}if(s.tag==="Just"){if(c.tag==="Nothing")return(s._1-0|0)-o.delta|0;if(c.tag==="Just")return(s._1-c._1|0)-o.delta|0}g()})();if(f<i.slack)return{edge:w("Just",o),slack:f}}return i})({edge:T,slack:1e9})(e).edge,ym=t=>{const e=t.Eq0();return n=>r=>i=>o=>{const u=o.tgt,s=o.src;return J(a=>c=>{if((()=>{const f=ks(c.eid)(r.cutvalue);if(f.tag==="Just")return!0;if(f.tag==="Nothing")return!1;g()})()){const f=ks(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)(ct(a=>a.eid!==o.eid&&(e.eq(a.src)(i)||e.eq(a.tgt)(i)),n))}},xm=t=>{const e=ym(t);return n=>r=>i=>{const o=(u,s,a)=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const m=t.compare(u)(h._3);if(m==="LT"){d=h._5;continue}if(m==="GT"){d=h._6;continue}if(m==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(a);if(c.tag==="Just")return j(t)(u)(ct(f=>f.eid!==s.eid,c._1))(a);if(c.tag==="Nothing")return a;g()};return(u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=(p=>{let y=p,x=!0,N;for(;x;){const v=y;if(v.tag==="Leaf"){x=!1,N=T;continue}if(v.tag==="Node"){const k=t.compare(_)(v._3);if(k==="LT"){y=v._5;continue}if(k==="GT"){y=v._6;continue}if(k==="EQ"){x=!1,N=w("Just",v._4);continue}}g()}return N})(l.unknown),m=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;g()})();if(m.length===1){const p=t.Eq0().eq(m[0].src)(_)?m[0].tgt:m[0].src;a={unknown:o(_,m[0],o(p,m[0],l.unknown)),cutvalue:j(it)(m[0].eid)(e(n)(l)(_)(m[0]))(l.cutvalue)},c=p;continue}f=!1,d=l}return d})(r)(i)}},Eg=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:c=>f=>c.delta===f.delta&&c.eid===f.eid&&n.eq(c.src)(f.src)&&e.eq(c.tgt)(f.tgt)&&c.weight===f.weight},i={compare:c=>f=>{const d=it.compare(c.delta)(f.delta);if(d==="LT"||d==="GT"||d!=="EQ")return d;const l=it.compare(c.eid)(f.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const _=t.compare(c.src)(f.src);if(_==="LT"||_==="GT"||_!=="EQ")return _;const h=t.compare(c.tgt)(f.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const m=st.compare(c.weight)(f.weight);return m==="LT"||m==="GT"||m!=="EQ"?m:Se},Eq0:()=>r},o=J(c=>f=>j(i)(f)()(c))(Q),u=hm(t),s=Kt(t)(Bt),a=xm(t);return c=>f=>d=>{const l={unknown:s(H(_=>b(_,kt(Re.foldr,o(u(f)(d)(_)))))(c)),cutvalue:Q};return{...d,cutvalue:J(a(f))(l)(ct(_=>{const h=(m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){y=!1,x=w("Just",N._4);continue}}g()}return x})(l.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;g()},c)).cutvalue}}},Nm=t=>{const e=Lg(t),n=Eg(t);return r=>i=>o=>u=>s=>{const a={...s,treeEdge:j(it)(u.eid)()(ni(it)(o.eid)(s.treeEdge))},c=u.tgt,f=(m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const v=t.compare(c)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){y=!1,x=w("Just",N._4);continue}}g()}return x})(a.layer),d=u.src,l=(m=>{let p=m,y=!0,x;for(;y;){const N=p;if(N.tag==="Leaf"){y=!1,x=T;continue}if(N.tag==="Node"){const v=t.compare(d)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){y=!1,x=w("Just",N._4);continue}}g()}return x})(a.layer),_=(()=>{if(f.tag==="Nothing"){if(l.tag==="Nothing")return-u.delta;if(l.tag==="Just")return-l._1-u.delta|0;g()}if(f.tag==="Just"){if(l.tag==="Nothing")return(f._1-0|0)-u.delta|0;if(l.tag==="Just")return(f._1-l._1|0)-u.delta|0}g()})(),h=So(t)(a)(u.tgt)(o)?_:-_;return n(r)(i)(e(r)(i)({...a,layer:J(m=>p=>So(t)(a)(p)(o)?m:j(t)(p)((()=>{const y=(x=>{let N=x,v=!0,k;for(;v;){const L=N;if(L.tag==="Leaf"){v=!1,k=T;continue}if(L.tag==="Node"){const E=t.compare(p)(L._3);if(E==="LT"){N=L._5;continue}if(E==="GT"){N=L._6;continue}if(E==="EQ"){v=!1,k=w("Just",L._4);continue}}g()}return k})(a.layer);if(y.tag==="Nothing")return 0+h|0;if(y.tag==="Just")return y._1+h|0;g()})())(m))(a.layer)(r)}))}},Jm=t=>{const e=Nm(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=pm(i)(_);if(h.tag==="Nothing"){f=!1,d=_;continue}if(h.tag==="Just"){const m=mm(t)(i)(h._1)(_);if(m.tag==="Nothing"){f=!1,d=_;continue}if(m.tag==="Just"){a=l-1|0,c=e(r)(i)(h._1)(m._1)(_);continue}}g()}return d})(n)(o)},Tm=t=>{const e=Eg(t),n=Lg(t),r=kg(t);return i=>o=>u=>e(i)(o)(n(i)(o)(r(i)(o)(u)))},Gg=t=>e=>J(n=>r=>vt(t)(te)(e(r))([r])(n))(Q),vm=t=>{const e=Kt(t)(Bt);return n=>r=>i=>{const o=a=>c=>f=>d=>{let l=a,_=c,h=f,m=d,p=!0,y;for(;p;){const x=l,N=_,v=h,k=m,L=Ft(E=>T,E=>B=>w("Just",{head:E,tail:B}),v);if(L.tag==="Nothing"){p=!1,y=k;continue}if(L.tag==="Just"){const E=L._1.head,B=(D=>{let S=D,Z=!0,X;for(;Z;){const W=S;if(W.tag==="Leaf"){Z=!1,X=T;continue}if(W.tag==="Node"){const z=t.compare(E)(W._3);if(z==="LT"){S=W._5;continue}if(z==="GT"){S=W._6;continue}if(z==="EQ"){Z=!1,X=w("Just",W._4);continue}}g()}return X})(k.layer),V=(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})(),et=J(D=>S=>{const Z=S.tgt,X=(z=>{let M=z,G=!0,P;for(;G;){const I=M;if(I.tag==="Leaf"){G=!1,P=T;continue}if(I.tag==="Node"){const F=t.compare(Z)(I._3);if(F==="LT"){M=I._5;continue}if(F==="GT"){M=I._6;continue}if(F==="EQ"){G=!1,P=w("Just",I._4);continue}}g()}return P})(D.incident),W=(()=>{if(X.tag==="Nothing")return-1;if(X.tag==="Just")return X._1-1|0;g()})();return{st:{...D.st,layer:j(t)(S.tgt)(cm((()=>{const z=S.tgt,M=(G=>{let P=G,I=!0,F;for(;I;){const O=P;if(O.tag==="Leaf"){I=!1,F=T;continue}if(O.tag==="Node"){const Y=t.compare(z)(O._3);if(Y==="LT"){P=O._5;continue}if(Y==="GT"){P=O._6;continue}if(Y==="EQ"){I=!1,F=w("Just",O._4);continue}}g()}return F})(D.st.layer);if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})())(V+S.delta|0))(D.st.layer)},incident:j(t)(S.tgt)(W)(D.incident),queue:W===0?[...D.queue,S.tgt]:D.queue}})({st:k,incident:N,queue:L._1.tail})((()=>{const D=(S=>{let Z=S,X=!0,W;for(;X;){const z=Z;if(z.tag==="Leaf"){X=!1,W=T;continue}if(z.tag==="Node"){const M=t.compare(E)(z._3);if(M==="LT"){Z=z._5;continue}if(M==="GT"){Z=z._6;continue}if(M==="EQ"){X=!1,W=w("Just",z._4);continue}}g()}return W})(x);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})());l=x,_=et.incident,h=et.queue,m=et.st;continue}g()}return y},u=Gg(t)(a=>a.tgt)(r),s=e(H(a=>b(a,(()=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const m=t.compare(a)(h._3);if(m==="LT"){d=h._5;continue}if(m==="GT"){d=h._6;continue}if(m==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(u);if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1.length;g()})()))(n));return o(Gg(t)(a=>a.src)(r))(s)(ct(a=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const m=t.compare(a)(h._3);if(m==="LT"){d=h._5;continue}if(m==="GT"){d=h._6;continue}if(m==="EQ"){l=!1,_=w("Just",h._4);continue}}g()}return _})(s);if(c.tag==="Nothing")return!0;if(c.tag==="Just")return c._1===0;g()},n))(i)}},wm=t=>{const e=_m(t),n=vm(t),r=Tm(t),i=Jm(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}},Cg=t=>{const e=lm(t),n=wm(t),r=gm(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)(fm(t)(u.removed)(n(u.coreNodes)(u.coreEdges)))}},Sg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=it.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Gs=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bm=Cg(it),wi=t=>e=>({...e,edges:[...e.edges,{src:t.src,tgt:t.tgt,delta:t.delta,weight:t.weight,eid:e.nextEid}],nextEid:e.nextEid+1|0}),Lm=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=rt((()=>{const i=Sg(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()},km=t=>e=>({...e,cGraph:J(Lm(t))(e.cGraph)((()=>{const n=e.cGraph;return xt(r=>Ut(r)(n.cNodes))(n.cNodeOrder)})())}),Em=t=>e=>n=>r=>i=>{const o=de(Xi(e.cGroupOffset.x-t.cGroupOffset.x));return wi({src:i.nextNodeId,tgt:r,delta:Gs(0)(-o),weight:1})(wi({src:i.nextNodeId,tgt:n,delta:Gs(0)(o),weight:1})({...i,nodes:[...i.nodes,i.nextNodeId],nextNodeId:i.nextNodeId+1|0}))},Gm=t=>e=>n=>r=>i=>o=>u=>{const s=Gs(0)(de(Xi(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)?Em(n)(r)(i)(o)(u):wi({src:i,tgt:o,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(u)},Cm=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"?Gm(t)(e)(n)(o._1)(n.cGroup._1)(o._1.cGroup._1)(r):r;g()},Sm=t=>e=>n=>r=>J(Cm(t)(e)(r))(n)(r.constraints),Dm=t=>e=>wi({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),Pm=t=>{const e=J(i=>o=>vt(it)(oe)(o.tgt)(1)(i))(Q)(t.edges),n=ct(i=>{const o=Sg(i)(e);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return o._1===0;g()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return J(i=>o=>wi({src:r,tgt:o,delta:1,weight:0})(i))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},Im=t=>e=>{const n=Pm(J(Dm)(J(Sm(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}},Qm=t=>e=>{const n=Im(t)(e);return km(bm(n.nodes)(n.edges))(e)},Dg=t=>t,ee=Dg("H"),ne=Dg("V"),Fm=t=>b(t._2,t._1),Pg=t=>({...t,position:b(t.position._2,t.position._1),size:b(t.size._2,t.size._1)}),Am=t=>({start:b(t.start._2,t.start._1),end:b(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return ne;if(t.direction==="V")return ee;g()})()}),Ig=t=>({...t,segments:H(Am)(t.segments),bends:H(Fm)(t.bends)}),Mm=t=>({nodes:H(Pg)(t.nodes),edges:t.edges,paths:H(Ig)(t.paths),ports:t.ports}),Bm=t=>({horizontalSpacing:e=>n=>{if(t.sameEdgeVerticalSegments(e)(n)||e.ignoreSpacing.right||n.ignoreSpacing.left)return 0;const r=n.kind.tag==="Nothing"?!1:n.kind.tag==="Just"&&n.kind._1==="vs";return e.kind.tag!=="Nothing"&&e.kind.tag==="Just"&&e.kind._1==="vs"?r?10:4:r?4:8},verticalSpacing:e=>n=>{if(t.sameEdgeVerticalSegments(e)(n))return 1;if(e.hitbox.y<=n.hitbox.y?e.ignoreSpacing.down||n.ignoreSpacing.up:e.ignoreSpacing.up||n.ignoreSpacing.down)return 0;const r=n.kind.tag==="Nothing"?!1:n.kind.tag==="Just"&&n.kind._1==="vs";return e.kind.tag!=="Nothing"&&e.kind.tag==="Just"&&e.kind._1==="vs"?r?10:4:r?4:8}}),zm=t=>e=>Qm(e),Rm=t=>e=>{const n=Mm(e),r=am(n),i=rm(r)(vg(n)),o=im(ag(xs)(Lp({...Ep(r.cGraph),compactionAlgorithm:w("Just",zm()(i)),constraintAlgorithm:w("Just",Rp),spacingsHandler:Bm(i)})).cGraph)({nodes:n.nodes,edges:n.edges,paths:n.paths});return{nodes:H(Pg)(o.nodes),edges:H(Ig)(o.edges)}},Qg=t=>t,Qr=Kt(it)(Bt),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=w("Just",o._4);continue}}g()}return i},Fg=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},dt=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ht=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Fr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Wm=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?ye:n==="GT"?xe:it.compare(t._2)(e._2)},Ar=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Hm=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),Om=t=>t,Ag=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},qm=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},Do=Qg("Regular"),Po=Qg("Critical"),Mg=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,m=!0,p;for(;m;){const y=l,x=_,N=h;if(N.critical){m=!1,p=N;continue}const v=Ft(L=>T,L=>E=>w("Just",{head:L,tail:E}),y),k=Ft(L=>T,L=>E=>w("Just",{head:L,tail:E}),x);if(v.tag==="Just"&&k.tag==="Just"){const L=v._1.head>k._1.head-u&&v._1.head<k._1.head+u?{...N,critical:!0}:v._1.head>k._1.head-r&&v._1.head<k._1.head+r?{...N,conflicts:N.conflicts+1|0}:N;if(L.critical){m=!1,p=L;continue}if(v._1.head<=k._1.head){l=v._1.tail,_=x,h=L;continue}l=y,_=k._1.tail,h=L;continue}m=!1,p=N}return p})(s)(a)({conflicts:0,critical:!1}),o=(u,s,a)=>{if(ht(J(ht)(-1e18)(s.incoming))(J(ht)(-1e18)(s.outgoing))-dt(J(dt)(1e18)(s.incoming))(J(dt)(1e18)(s.outgoing))<.001||ht(J(ht)(-1e18)(a.incoming))(J(ht)(-1e18)(a.outgoing))-dt(J(dt)(1e18)(a.incoming))(J(dt)(1e18)(a.outgoing))<.001)return[];const c=i(u,s.outgoing,a.incoming),f=i(u,a.outgoing,s.incoming);if(c.critical||f.critical)return[...c.critical?[{src:a.id,tgt:s.id,weight:1,kind:Po}]:[],...f.critical?[{src:s.id,tgt:a.id,weight:1,kind:Po}]:[]];const d=dt(J(dt)(1e18)(s.incoming))(J(dt)(1e18)(s.outgoing)),l=ht(J(ht)(-1e18)(s.incoming))(J(ht)(-1e18)(s.outgoing)),_=dt(J(dt)(1e18)(a.incoming))(J(dt)(1e18)(a.outgoing)),h=ht(J(ht)(-1e18)(a.incoming))(J(ht)(-1e18)(a.outgoing)),m=(1*c.conflicts|0)+(16*(J(y=>x=>x>h?y:x>=_?y+1|0:y)(0)(s.outgoing)+J(y=>x=>x>l?y:x>=d?y+1|0:y)(0)(a.incoming)|0)|0)|0,p=(1*f.conflicts|0)+(16*(J(y=>x=>x>l?y:x>=d?y+1|0:y)(0)(a.outgoing)+J(y=>x=>x>h?y:x>=_?y+1|0:y)(0)(s.incoming)|0)|0)|0;return m<p?[{src:s.id,tgt:a.id,weight:p-m|0,kind:Do}]:m>p?[{src:a.id,tgt:s.id,weight:m-p|0,kind:Do}]:m>0?[{src:s.id,tgt:a.id,weight:0,kind:Do},{src:a.id,tgt:s.id,weight:0,kind:Do}]:[]};return J(u=>s=>J(a=>c=>j(C)(c._1)(c._2)(a))(u)((()=>{const a=J(D=>S=>{const Z=S.edge.from.node+"|"+(()=>{if(S.edge.from.port.tag==="Just")return S.edge.from.port._1;if(S.edge.from.port.tag==="Nothing")return"_auto_"+S.edge.id;g()})(),X=Ag(Z)(D.entries);if(X.tag==="Nothing")return{...D,entries:j(C)(Z)({id:0,members:[S.edge.id],incoming:[S.fromPos._1],outgoing:[S.toPos._1],slot:0,mark:0,splitBy:T,splitPartner:T})(D.entries),order:[...D.order,Z]};if(X.tag==="Just")return{...D,entries:j(C)(Z)({...X._1,members:[...X._1.members,S.edge.id],incoming:[...or(W=>W<S.fromPos._1)(X._1.incoming).init,S.fromPos._1,...or(W=>W<=S.fromPos._1)(X._1.incoming).rest],outgoing:[...or(W=>W<S.toPos._1)(X._1.outgoing).init,S.toPos._1,...or(W=>W<=S.toPos._1)(X._1.outgoing).rest]})(D.entries)};g()})({entries:Q,order:[]})(s._2),c=Qt(D=>S=>({...S,id:D}))(xt(D=>Ag(D)(a.entries))(a.order));if(c.length===0)return[];const f=J(D=>S=>D.prev.tag==="Just"&&S-D.prev._1<1e-9?D:{prev:w("Just",S),out:[...D.out,S]})({prev:T,out:[]})(Lt(st.compare)([...Tt(c)(D=>D.incoming),...Tt(c)(D=>D.outgoing)])).out,d=f.length<2?.2*r:.2*J(D=>S=>{if(D.prev.tag==="Nothing")return{prev:w("Just",S),mn:D.mn};if(D.prev.tag==="Just")return{prev:w("Just",S),mn:dt(D.mn)(S-D.prev._1)};g()})({prev:T,mn:1e18})(f).mn,l={segments:c,deps:(()=>{const D=c.length;return Tt(Tt(It(0,D-2|0))(S=>Tt(It(S+1|0,D-1|0))(Z=>[b(S,Z)])))(S=>S._1>=0&&S._1<c.length?S._2>=0&&S._2<c.length?o(d,c[S._1],c[S._2]):[]:[])})()},_=ct(D=>{if(D.kind==="Critical")return!0;if(D.kind==="Regular")return!1;g()},l.deps),h=(()=>{if(_.length<2)return l;const D=Qr((()=>{const z=l.segments;return H(M=>b(M.id,M.mark))((()=>{const M=z.length,G=I=>{let F=I,O=!0,Y;for(;O;){const q=F,$=Zt(R=>{const tt=Dt(R)(q.inWeight);if(tt.tag==="Nothing")return!0;if(tt.tag==="Just")return tt._1===0;g()})(q.remaining);if($.tag==="Nothing"){O=!1,Y=q;continue}if($.tag==="Just"){const R=$._1;F={...q,inWeight:J(tt=>K=>vt(it)(oe)(K.tgt)(-K.weight)(tt))(q.inWeight)((()=>{const tt=Dt(R)(q.depsBySrc);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),marks:j(it)(R)(q.nextSource)(q.marks),nextSource:q.nextSource+1|0,outWeight:J(tt=>K=>vt(it)(oe)(K.src)(-K.weight)(tt))(q.outWeight)((()=>{const tt=Dt(R)(q.depsByTgt);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),remaining:ct(tt=>tt!==R,q.remaining)};continue}g()}return Y},P=I=>{let F=I,O=!0,Y;for(;O;){const q=F,$=Zt(R=>{const tt=Dt(R)(q.outWeight);if(tt.tag==="Nothing")return!0;if(tt.tag==="Just")return tt._1===0;g()})(q.remaining);if($.tag==="Nothing"){O=!1,Y=q;continue}if($.tag==="Just"){const R=$._1;F={...q,inWeight:J(tt=>K=>vt(it)(oe)(K.tgt)(-K.weight)(tt))(q.inWeight)((()=>{const tt=Dt(R)(q.depsBySrc);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),marks:j(it)(R)(q.nextSink)(q.marks),nextSink:q.nextSink-1|0,outWeight:J(tt=>K=>vt(it)(oe)(K.src)(-K.weight)(tt))(q.outWeight)((()=>{const tt=Dt(R)(q.depsByTgt);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),remaining:ct(tt=>tt!==R,q.remaining)};continue}g()}return Y};return(I=>{let F=I,O=!0,Y;for(;O;){const q=G(P(F));if(q.remaining.length===0){O=!1,Y=H($=>{const R=Dt($.id)(q.marks),tt=(()=>{if(R.tag==="Nothing")return $.id;if(R.tag==="Just")return R._1;g()})();return{...$,mark:tt<M?(tt+M|0)+1|0:tt}})(z);continue}F=(()=>{const $=tt=>{const K=Dt(tt)(q.outWeight),gt=Dt(tt)(q.inWeight);return(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()-(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()|0},R=Lt(tt=>K=>it.compare($(K))($(tt)))(q.remaining);if(0<R.length){const tt=R[0];return{...q,inWeight:J(K=>gt=>vt(it)(oe)(gt.tgt)(-gt.weight)(K))(q.inWeight)((()=>{const K=Dt(tt)(q.depsBySrc);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),marks:j(it)(tt)(q.nextSource)(q.marks),nextSource:q.nextSource+1|0,outWeight:J(K=>gt=>vt(it)(oe)(gt.src)(-gt.weight)(K))(q.outWeight)((()=>{const K=Dt(tt)(q.depsByTgt);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),remaining:ct(K=>K!==tt,q.remaining)}}return q})()}return Y})({remaining:H(I=>I.id)(z),marks:Q,inWeight:J(I=>F=>vt(it)(oe)(F.tgt)(F.weight)(I))(Q)(_),outWeight:J(I=>F=>vt(it)(oe)(F.src)(F.weight)(I))(Q)(_),depsBySrc:J(I=>F=>vt(it)(te)(F.src)([F])(I))(Q)(_),depsByTgt:J(I=>F=>vt(it)(te)(F.tgt)([F])(I))(Q)(_),nextSink:M-1|0,nextSource:M+1|0})})())})()),S=ct(z=>{const M=Dt(z.src)(D),G=Dt(z.tgt)(D);return(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()>(()=>{if(G.tag==="Nothing")return 0;if(G.tag==="Just")return G._1;g()})()},_);if(S.length===0)return l;const Z=J(z=>M=>{if(Be(xr)(M.src)(z.decisions)||Be(xr)(M.tgt)(z.decisions))return z;const G=Dt(M.src)(z.segMap),P=Dt(M.tgt)(z.segMap);if(G.tag==="Just"&&P.tag==="Just"){const I=(G._1.incoming.length+G._1.outgoing.length|0)>2&&(P._1.incoming.length+P._1.outgoing.length|0)<=2,F=I?P._1:G._1;return{decisions:[...z.decisions,F.id],segMap:j(it)(F.id)({...F,splitBy:w("Just",I?G._1.id:P._1.id)})(z.segMap)}}return z})({decisions:[],segMap:Qr(H(z=>b(z.id,z))(l.segments))})(S),X=Z.segMap,W=J(z=>M=>{const G=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(M.outgoing)),P=ht(J(ht)(-1e18)(M.incoming))(J(ht)(-1e18)(M.outgoing)),I=ct($=>$.a.startPosition<=P&&$.a.endPosition>=G,Qt($=>R=>({i:$,a:R}))(z.freeAreas));if(I.length===0){const $={...M,incoming:Lt(st.compare)(M.incoming),outgoing:Lt(st.compare)([(G+P)/2]),splitPartner:w("Just",z.nextId)},R={id:z.nextId,incoming:Lt(st.compare)([(G+P)/2]),mark:0,members:M.members,outgoing:Lt(st.compare)(M.outgoing),slot:0,splitBy:T,splitPartner:w("Just",M.id)};return{segMap:j(it)(R.id)(R)(j(it)($.id)($)(z.segMap)),freeAreas:z.freeAreas,nextId:z.nextId+1|0}}const F=0<I.length?w("Just",I[0]):T,O=(()=>{if(F.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(F.tag==="Just"){if(I.length===1)return F._1;const $=H(R=>({c:R,rating:(()=>{const tt=(R.a.startPosition+R.a.endPosition)/2,K=[tt],gt=[tt],_t=J((()=>{const yt=z.segMap;return Et=>At=>{const pt=Dt(At.tgt)(yt);if(pt.tag==="Nothing")return Et;if(pt.tag==="Just"){const Mt=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),Jt=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),mt=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(K)),nt=(()=>{const Ct=ht(J(ht)(-1e18)(M.incoming))(J(ht)(-1e18)(K)),Pt=J(Xt=>_e=>_e>Jt?Xt:_e>=Mt?Xt+1|0:Xt)(0)(K)+J(Xt=>_e=>_e>Ct?Xt:_e>=mt?Xt+1|0:Xt)(0)(pt._1.incoming)|0,je=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(K)),Ze=ht(J(ht)(-1e18)(M.incoming))(J(ht)(-1e18)(K)),kn=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),jr=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),_n=J(Xt=>_e=>_e>Ze?Xt:_e>=je?Xt+1|0:Xt)(0)(pt._1.outgoing)+J(Xt=>_e=>_e>jr?Xt:_e>=kn?Xt+1|0:Xt)(0)(M.incoming)|0;return Pt===_n?Pt>0?{...Et,deps:Et.deps+2|0,crossings:Et.crossings+Pt|0}:Et:{...Et,deps:Et.deps+1|0,crossings:Et.crossings+Ar(Pt)(_n)|0}})(),U=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),ut=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),ft=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(M.outgoing)),lt=ht(J(ht)(-1e18)(gt))(J(ht)(-1e18)(M.outgoing)),Nt=J(Ct=>Pt=>Pt>ut?Ct:Pt>=U?Ct+1|0:Ct)(0)(M.outgoing)+J(Ct=>Pt=>Pt>lt?Ct:Pt>=ft?Ct+1|0:Ct)(0)(pt._1.incoming)|0,Ht=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(M.outgoing)),Vt=ht(J(ht)(-1e18)(gt))(J(ht)(-1e18)(M.outgoing)),De=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),un=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),Ne=J(Ct=>Pt=>Pt>Vt?Ct:Pt>=Ht?Ct+1|0:Ct)(0)(pt._1.outgoing)+J(Ct=>Pt=>Pt>un?Ct:Pt>=De?Ct+1|0:Ct)(0)(gt)|0;return Nt===Ne?Nt>0?{...nt,deps:nt.deps+2|0,crossings:nt.crossings+Nt|0}:nt:{...nt,deps:nt.deps+1|0,crossings:nt.crossings+Ar(Nt)(Ne)|0}}g()}})())(J((()=>{const yt=z.segMap;return Et=>At=>{const pt=Dt(At.src)(yt);if(pt.tag==="Nothing")return Et;if(pt.tag==="Just"){const Mt=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),Jt=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),mt=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(K)),nt=(()=>{const Ct=ht(J(ht)(-1e18)(M.incoming))(J(ht)(-1e18)(K)),Pt=J(Xt=>_e=>_e>Jt?Xt:_e>=Mt?Xt+1|0:Xt)(0)(K)+J(Xt=>_e=>_e>Ct?Xt:_e>=mt?Xt+1|0:Xt)(0)(pt._1.incoming)|0,je=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(K)),Ze=ht(J(ht)(-1e18)(M.incoming))(J(ht)(-1e18)(K)),kn=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),jr=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),_n=J(Xt=>_e=>_e>Ze?Xt:_e>=je?Xt+1|0:Xt)(0)(pt._1.outgoing)+J(Xt=>_e=>_e>jr?Xt:_e>=kn?Xt+1|0:Xt)(0)(M.incoming)|0;return Pt===_n?Pt>0?{...Et,deps:Et.deps+2|0,crossings:Et.crossings+Pt|0}:Et:{...Et,deps:Et.deps+1|0,crossings:Et.crossings+Ar(Pt)(_n)|0}})(),U=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),ut=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),ft=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(M.outgoing)),lt=ht(J(ht)(-1e18)(gt))(J(ht)(-1e18)(M.outgoing)),Nt=J(Ct=>Pt=>Pt>ut?Ct:Pt>=U?Ct+1|0:Ct)(0)(M.outgoing)+J(Ct=>Pt=>Pt>lt?Ct:Pt>=ft?Ct+1|0:Ct)(0)(pt._1.incoming)|0,Ht=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(M.outgoing)),Vt=ht(J(ht)(-1e18)(gt))(J(ht)(-1e18)(M.outgoing)),De=dt(J(dt)(1e18)(pt._1.incoming))(J(dt)(1e18)(pt._1.outgoing)),un=ht(J(ht)(-1e18)(pt._1.incoming))(J(ht)(-1e18)(pt._1.outgoing)),Ne=J(Ct=>Pt=>Pt>Vt?Ct:Pt>=Ht?Ct+1|0:Ct)(0)(pt._1.outgoing)+J(Ct=>Pt=>Pt>un?Ct:Pt>=De?Ct+1|0:Ct)(0)(gt)|0;return Nt===Ne?Nt>0?{...nt,deps:nt.deps+2|0,crossings:nt.crossings+Nt|0}:nt:{...nt,deps:nt.deps+1|0,crossings:nt.crossings+Ar(Nt)(Ne)|0}}g()}})())({crossings:0,deps:0})(ct(yt=>yt.tgt===M.id,l.deps)))(ct(yt=>yt.src===M.id,l.deps)),at=(()=>{if(M.splitBy.tag==="Just")return Dt(M.splitBy._1)(z.segMap);if(M.splitBy.tag==="Nothing")return T;g()})();if(at.tag==="Just")return{..._t,deps:_t.deps+2|0,crossings:(()=>{const yt=dt(J(dt)(1e18)(at._1.incoming))(J(dt)(1e18)(at._1.outgoing)),Et=dt(J(dt)(1e18)(gt))(J(dt)(1e18)(M.outgoing)),At=ht(J(ht)(-1e18)(at._1.incoming))(J(ht)(-1e18)(at._1.outgoing)),pt=ht(J(ht)(-1e18)(gt))(J(ht)(-1e18)(M.outgoing)),Mt=dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(K));return _t.crossings+(()=>{const Jt=dt(J(dt)(1e18)(at._1.incoming))(J(dt)(1e18)(at._1.outgoing)),mt=ht(J(ht)(-1e18)(M.incoming))(J(ht)(-1e18)(K)),nt=ht(J(ht)(-1e18)(at._1.incoming))(J(ht)(-1e18)(at._1.outgoing));return((J(U=>ut=>ut>At?U:ut>=yt?U+1|0:U)(0)(K)+J(U=>ut=>ut>mt?U:ut>=Mt?U+1|0:U)(0)(at._1.incoming)|0)+J(U=>ut=>ut>pt?U:ut>=Et?U+1|0:U)(0)(at._1.outgoing)|0)+J(U=>ut=>ut>nt?U:ut>=Jt?U+1|0:U)(0)(gt)|0})()|0})()};if(at.tag==="Nothing")return _t;g()})()}))(I);return J(R=>tt=>tt.rating.crossings<R.rating.crossings||!(tt.rating.crossings>R.rating.crossings)&&(tt.rating.deps<R.rating.deps||!(tt.rating.deps>R.rating.deps)&&tt.c.a.size>R.c.a.size)?tt:R)(0<$.length?$[0]:{c:F._1,rating:{crossings:1e6,deps:1e6}})($).c}g()})(),Y={...M,incoming:Lt(st.compare)(M.incoming),outgoing:Lt(st.compare)([(O.a.startPosition+O.a.endPosition)/2]),splitPartner:w("Just",z.nextId)},q={id:z.nextId,incoming:Lt(st.compare)([(O.a.startPosition+O.a.endPosition)/2]),mark:0,members:M.members,outgoing:Lt(st.compare)(M.outgoing),slot:0,splitBy:T,splitPartner:w("Just",M.id)};return{segMap:j(it)(q.id)(q)(j(it)(Y.id)(Y)(z.segMap)),freeAreas:(()=>{if(O.i>=0&&O.i<z.freeAreas.length){const $=za(Yt,T,O.i,z.freeAreas),R=(()=>{if($.tag==="Nothing")return z.freeAreas;if($.tag==="Just")return $._1;g()})();if(z.freeAreas[O.i].size/2<d)return R;const tt=(z.freeAreas[O.i].startPosition+z.freeAreas[O.i].endPosition)/2,K=tt-d,gt=tt+d;return[...O.i<1?[]:bt(0,O.i,R),...z.freeAreas[O.i].startPosition<=K?[{startPosition:z.freeAreas[O.i].startPosition,endPosition:K,size:K-z.freeAreas[O.i].startPosition}]:[],...gt<=z.freeAreas[O.i].endPosition?[{startPosition:gt,endPosition:z.freeAreas[O.i].endPosition,size:z.freeAreas[O.i].endPosition-gt}]:[],...O.i<1?R:bt(O.i,R.length,R)]}return z.freeAreas})(),nextId:z.nextId+1|0}})({segMap:X,freeAreas:(()=>{const z=Lt(st.compare)([...Tt(l.segments)(M=>M.incoming),...Tt(l.segments)(M=>M.outgoing)]);return xt(Om)(Je(M=>G=>G-M>=2*d?w("Just",{startPosition:M+d,endPosition:G-d,size:G-M-2*d}):T,z,bt(1,z.length,z)))})(),nextId:l.segments.length})(Lt(z=>M=>st.compare(ht(J(ht)(-1e18)(z.incoming))(J(ht)(-1e18)(z.outgoing))-dt(J(dt)(1e18)(z.incoming))(J(dt)(1e18)(z.outgoing)))(ht(J(ht)(-1e18)(M.incoming))(J(ht)(-1e18)(M.outgoing))-dt(J(dt)(1e18)(M.incoming))(J(dt)(1e18)(M.outgoing))))(xt(z=>Dt(z)(X))(Z.decisions)));return{segments:(()=>{const z=(M,G)=>{if(M.tag==="Leaf")return G;if(M.tag==="Node")return z(M._5,Ot("Cons",M._4,z(M._6,G)));g()};return kt($t.foldr,z(W.segMap,qt))})(),deps:(()=>{const z=W.segMap,M=(I,F)=>{if(I.tag==="Leaf")return F;if(I.tag==="Node")return M(I._5,Ot("Cons",I._4,M(I._6,F)));g()},G=kt($t.foldr,M(z,qt)),P=G.length;return[...Tt(Tt(It(0,P-2|0))(I=>Tt(It(I+1|0,P-1|0))(F=>[b(I,F)])))(I=>I._1>=0&&I._1<G.length?I._2>=0&&I._2<G.length?G[I._1].splitPartner.tag!=="Nothing"&&G[I._1].splitPartner.tag==="Just"&&G[I._1].splitPartner._1===G[I._2].id||G[I._2].splitPartner.tag!=="Nothing"&&G[I._2].splitPartner.tag==="Just"&&G[I._2].splitPartner._1===G[I._1].id?[]:o(d,G[I._1],G[I._2]):[]:[]),...Tt(G)(I=>I.splitBy.tag==="Just"&&I.splitPartner.tag==="Just"&&(()=>{const F=Dt(I.splitPartner._1)(z);if(F.tag==="Nothing")return!1;if(F.tag==="Just")return!0;g()})()&&(()=>{const F=Dt(I.splitBy._1)(z);if(F.tag==="Nothing")return!1;if(F.tag==="Just")return!0;g()})()?[{src:I.id,tgt:I.splitBy._1,weight:1,kind:Po},{src:I.splitBy._1,tgt:I.splitPartner._1,weight:1,kind:Po}]:[])]})()}})(),m=h.segments,p=m.length,y=D=>{let S=D,Z=!0,X;for(;Z;){const W=S,z=Zt(M=>{const G=Dt(M)(W.inWeight);if(G.tag==="Nothing")return!0;if(G.tag==="Just")return G._1===0;g()})(W.remaining);if(z.tag==="Nothing"){Z=!1,X=W;continue}if(z.tag==="Just"){const M=z._1;S={...W,inWeight:J(G=>P=>vt(it)(oe)(P.tgt)(-P.weight)(G))(W.inWeight)((()=>{const G=Dt(M)(W.depsBySrc);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()),marks:j(it)(M)(W.nextSource)(W.marks),nextSource:W.nextSource+1|0,outWeight:J(G=>P=>vt(it)(oe)(P.src)(-P.weight)(G))(W.outWeight)((()=>{const G=Dt(M)(W.depsByTgt);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()),remaining:ct(G=>G!==M,W.remaining)};continue}g()}return X},x=D=>{let S=D,Z=!0,X;for(;Z;){const W=S,z=Zt(M=>{const G=Dt(M)(W.outWeight);if(G.tag==="Nothing")return!0;if(G.tag==="Just")return G._1===0;g()})(W.remaining);if(z.tag==="Nothing"){Z=!1,X=W;continue}if(z.tag==="Just"){const M=z._1;S={...W,inWeight:J(G=>P=>vt(it)(oe)(P.tgt)(-P.weight)(G))(W.inWeight)((()=>{const G=Dt(M)(W.depsBySrc);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()),marks:j(it)(M)(W.nextSink)(W.marks),nextSink:W.nextSink-1|0,outWeight:J(G=>P=>vt(it)(oe)(P.src)(-P.weight)(G))(W.outWeight)((()=>{const G=Dt(M)(W.depsByTgt);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()),remaining:ct(G=>G!==M,W.remaining)};continue}g()}return X},N=(D=>{let S=D,Z=!0,X;for(;Z;){const W=y(x(S));if(W.remaining.length===0){Z=!1,X=H(z=>{const M=Dt(z.id)(W.marks),G=(()=>{if(M.tag==="Nothing")return z.id;if(M.tag==="Just")return M._1;g()})();return{...z,mark:G<p?(G+p|0)+1|0:G}})(m);continue}S=(()=>{const z=G=>{const P=Dt(G)(W.outWeight),I=Dt(G)(W.inWeight);return(()=>{if(P.tag==="Nothing")return 0;if(P.tag==="Just")return P._1;g()})()-(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;g()})()|0},M=Lt(G=>P=>it.compare(z(P))(z(G)))(W.remaining);if(0<M.length){const G=M[0];return{...W,inWeight:J(P=>I=>vt(it)(oe)(I.tgt)(-I.weight)(P))(W.inWeight)((()=>{const P=Dt(G)(W.depsBySrc);if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})()),marks:j(it)(G)(W.nextSource)(W.marks),nextSource:W.nextSource+1|0,outWeight:J(P=>I=>vt(it)(oe)(I.src)(-I.weight)(P))(W.outWeight)((()=>{const P=Dt(G)(W.depsByTgt);if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})()),remaining:ct(P=>P!==G,W.remaining)}}return W})()}return X})({remaining:H(D=>D.id)(m),marks:Q,inWeight:J(D=>S=>vt(it)(oe)(S.tgt)(S.weight)(D))(Q)(h.deps),outWeight:J(D=>S=>vt(it)(oe)(S.src)(S.weight)(D))(Q)(h.deps),depsBySrc:J(D=>S=>vt(it)(te)(S.src)([S])(D))(Q)(h.deps),depsByTgt:J(D=>S=>vt(it)(te)(S.tgt)([S])(D))(Q)(h.deps),nextSink:p-1|0,nextSource:p+1|0}),v=(()=>{const D=(()=>{const X=Qr(H(W=>b(W.id,W.mark))(N));return{segments:N,deps:xt(W=>(()=>{if(W.kind==="Critical")return!0;if(W.kind==="Regular")return!1;g()})()?w("Just",W):(()=>{const z=Dt(W.src)(X),M=Dt(W.tgt)(X);return(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})()>(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()})()?W.weight===0?T:w("Just",{src:W.tgt,tgt:W.src,weight:W.weight,kind:W.kind}):w("Just",W))(h.deps)}})(),S=J(X=>W=>vt(it)(oe)(W.tgt)(1)(X))(Q)(D.deps),Z=(X=>{let W=X,z=!0,M;for(;z;){const G=W,P=Ft(I=>T,I=>F=>w("Just",{head:I,tail:F}),G.queue);if(P.tag==="Nothing"){z=!1,M=G;continue}if(P.tag==="Just"){W=J((()=>{const I=Dt(P._1.head)(G.slots),F=(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;g()})();return O=>Y=>{const q=Dt(Y)(O.inDegree),$=(()=>{if(q.tag==="Nothing")return-1;if(q.tag==="Just")return q._1-1|0;g()})();return{...O,slots:j(it)(Y)(Fg((()=>{const R=Dt(Y)(O.slots);if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})())(F+1|0))(O.slots),inDegree:j(it)(Y)($)(O.inDegree),queue:$===0?[...O.queue,Y]:O.queue}}})())({...G,queue:P._1.tail})((()=>{const I=Dt(P._1.head)(G.adj);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})());continue}g()}return M})({slots:Qr(H(X=>b(X.id,0))(D.segments)),inDegree:S,adj:J(X=>W=>vt(it)(te)(W.src)([W.tgt])(X))(Q)(D.deps),queue:H(X=>X.id)(ct(X=>{const W=Dt(X.id)(S);if(W.tag==="Nothing")return!0;if(W.tag==="Just")return W._1===0;g()},D.segments))});return Lt(X=>W=>it.compare(X.slot)(W.slot))(H(X=>({...X,slot:(()=>{const W=Dt(X.id)(Z.slots);if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})()}))(D.segments))})(),k=1+J(D=>S=>Fg(D)(S.slot))(0)(v)|0,L=Tt(v)(D=>D.members),E=ct(D=>Be(gn)(D.edge.id)(L),t),B=J(ht)(-1e18)(H(D=>D.fromPos._2)(E)),V=J(dt)(1e18)(H(D=>D.toPos._2)(E));if(B>V){const D=Qr(H(S=>b(S.id,S))(v));return Ae(H(S=>H(Z=>b(Z,{slot:S.slot,slotCount:k,gapTop:V,gapBottom:B,partner:(()=>{if(S.splitPartner.tag==="Just"){const X=Dt(S.splitPartner._1)(D);if(X.tag==="Just")return w("Just",{slot:X._1.slot,splitX:0<X._1.incoming.length?X._1.incoming[0]:0});if(X.tag==="Nothing")return T;g()}if(S.splitPartner.tag==="Nothing")return T;g()})()}))(S.members))(ct(S=>{if(S.splitPartner.tag==="Just"){const Z=Dt(S.splitPartner._1)(D);return!(Z.tag==="Just"&&(()=>{if(Z._1.splitBy.tag==="Nothing")return!1;if(Z._1.splitBy.tag==="Just")return!0;g()})())}if(S.splitPartner.tag==="Nothing")return!0;g()},v)))}const et=Qr(H(D=>b(D.id,D))(v));return Ae(H(D=>H(S=>b(S,{slot:D.slot,slotCount:k,gapTop:B,gapBottom:V,partner:(()=>{if(D.splitPartner.tag==="Just"){const Z=Dt(D.splitPartner._1)(et);if(Z.tag==="Just")return w("Just",{slot:Z._1.slot,splitX:0<Z._1.incoming.length?Z._1.incoming[0]:0});if(Z.tag==="Nothing")return T;g()}if(D.splitPartner.tag==="Nothing")return T;g()})()}))(D.members))(ct(D=>{if(D.splitPartner.tag==="Just"){const S=Dt(D.splitPartner._1)(et);return!(S.tag==="Just"&&(()=>{if(S._1.splitBy.tag==="Nothing")return!1;if(S._1.splitBy.tag==="Just")return!0;g()})())}if(D.splitPartner.tag==="Nothing")return!0;g()},v)))})()))(Q)(Hm(J(u=>s=>{const a=Fr(s.edge.from.node)(n);if(a.tag==="Just"){const c=Fr(s.edge.to.node)(n);return c.tag==="Just"&&a._1.layer!==c._1.layer?vt(it)(te)(Ar(a._1.layer)(c._1.layer))([s])(u):u}return u})(Q)((()=>{const u=s=>b((()=>{const a=Fr(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=Fr(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return Lt(s=>a=>Wm(u(s))(u(a)))(t)})())))},$m=t=>e=>{const n=Mg(t)(e),r=J(i=>o=>j(C)(o.node)(o)(i))(Q)(e);return J(i=>o=>{const u=Fr(o.edge.from.node)(r);if(u.tag==="Just"){const s=Fr(o.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=qm(o.edge.id)(n);if(a.tag==="Just")return j(it)(Ar(u._1.layer)(s._1.layer))(a._1.slotCount)(i)}return i}return i})(Q)(t)},Bg=Bt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),ce=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ge=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bi=t=>e=>n=>r=>Bg(i=>n>=i.x&&n<i.x+i.w&&e>i.y&&t<i.y+i.h)(r),Io=t=>e=>n=>r=>bi(ce(e)(n))(ge(e)(n))(r)(t),Qo=rt(4),Ym=Ha(t=>{if(t.direction==="H"){const e=ce(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:ge(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=ce(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:ge(t.start._2)(t.end._2)-e}]}g()}),Li=Wa(t=>{const e=t.start._1-t.end._1;return!((e<0?-e<1e-6:e<1e-6)&&(()=>{const n=t.start._2-t.end._2;return n<0?-n<1e-6:n<1e-6})())}),Vm=t=>e=>n=>{const r=Ft(i=>T,i=>o=>w("Just",{head:i,tail:o}),e);if(r.tag==="Nothing")return[{start:t.start,end:n.end,direction:t.direction}];if(r.tag==="Just"){const i=(r._1.head.direction==="H"?t.direction==="H":r._1.head.direction==="V"&&t.direction==="V")?[{start:t.start,end:r._1.head.end,direction:t.direction}]:[t,r._1.head],o=Vi(r._1.tail);if(o.tag==="Nothing"){const u=i.length-1|0;return u>=0&&u<i.length&&(i[u].direction==="H"?n.direction==="H":i[u].direction==="V"&&n.direction==="V")?[...(()=>{const s=i.length-1|0;return s<1?[]:bt(0,s,i)})(),{start:i[u].start,end:n.end,direction:n.direction}]:[...i,n]}if(o.tag==="Just")return(o._1.last.direction==="H"?n.direction==="H":o._1.last.direction==="V"&&n.direction==="V")?[...i,...o._1.init,{start:o._1.last.start,end:n.end,direction:n.direction}]:[...i,...r._1.tail,n]}g()},ki=t=>{const e=r=>i=>{const o=Ft(u=>T,u=>s=>w("Just",{head:u,tail:s}),i);if(o.tag==="Nothing")return[r];if(o.tag==="Just")return(r.direction==="H"?o._1.head.direction==="H":r.direction==="V"&&o._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==o._1.head.end._1-o._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==o._1.head.end._2-o._1.head.start._2>=0;g()})()?e({start:r.start,end:o._1.head.end,direction:r.direction})(o._1.tail):[r,...e(o._1.head)(o._1.tail)];g()},n=Ft(r=>T,r=>i=>w("Just",{head:r,tail:i}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);g()},Ei=t=>e=>n=>r=>Bg(i=>n>=i.y&&n<i.y+i.h&&e>i.x&&t<i.x+i.w)(r),Gi=t=>e=>n=>r=>Ei(ce(e)(n))(ge(e)(n))(r)(t),Xm=t=>e=>n=>r=>{const i=n+2|0,o=i<1?e:bt(i,e.length,e),u=n<1?[]:bt(0,n,e),s=(n+1|0)===(r-1|0),a=n===0,c=n>=0&&n<e.length?w("Just",e[n]):T;if(c.tag==="Just"){const f=n+1|0,d=f>=0&&f<e.length?w("Just",e[f]):T;if(d.tag==="Just"){const l=c._1.start._1===d._1.end._1&&(!a||c._1.direction==="V")&&(!s||d._1.direction==="V")&&!Io(t)(ce(c._1.start._2)(d._1.end._2))(ge(c._1.start._2)(d._1.end._2))(c._1.start._1)?w("Just",[...u,{start:c._1.start,end:d._1.end,direction:ne},...o]):T,_=c._1.start._2===d._1.end._2&&(!a||c._1.direction==="H")&&(!s||d._1.direction==="H")&&!Gi(t)(ce(c._1.start._1)(d._1.end._1))(ge(c._1.start._1)(d._1.end._1))(c._1.start._2)?w("Just",[...u,{start:c._1.start,end:d._1.end,direction:ee},...o]):T;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return T;g()}if(c.tag==="Nothing")return T;g()},Um=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=Xm(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)},jm=t=>e=>n=>r=>{const i=(l,_,h)=>!Io(t)(ce(_)(h))(ge(_)(h))(l),o=n+3|0,u=o<1?e:bt(o,e.length,e),s=n<1?[]:bt(0,n,e),a=(n+2|0)===(r-1|0),c=n===0,f=(l,_,h)=>!Gi(t)(ce(_)(h))(ge(_)(h))(l),d=n>=0&&n<e.length?w("Just",e[n]):T;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<e.length?w("Just",e[l]):T;if(_.tag==="Just"){const h=d._1.start._1===_._1.end._1&&(!c||d._1.direction==="V")&&(!a||_._1.direction==="V")&&i(d._1.start._1,d._1.start._2,_._1.end._2)?w("Just",[...s,{start:d._1.start,end:_._1.end,direction:ne},...u]):d._1.start._2===_._1.end._2&&(!c||d._1.direction==="H")&&(!a||_._1.direction==="H")&&f(d._1.start._2,d._1.start._1,_._1.end._1)?w("Just",[...s,{start:d._1.start,end:_._1.end,direction:ee},...u]):T,m=(!c||d._1.direction==="V")&&(!a||_._1.direction==="H")&&i(d._1.start._1,d._1.start._2,_._1.end._2)&&f(_._1.end._2,d._1.start._1,_._1.end._1)?w("Just",[...s,{start:d._1.start,end:b(d._1.start._1,_._1.end._2),direction:ne},{start:b(d._1.start._1,_._1.end._2),end:_._1.end,direction:ee},...u]):T,p=(!c||d._1.direction==="H")&&(!a||_._1.direction==="V")&&f(d._1.start._2,d._1.start._1,_._1.end._1)&&i(_._1.end._1,d._1.start._2,_._1.end._2)?w("Just",[...s,{start:d._1.start,end:b(_._1.end._1,d._1.start._2),direction:ee},{start:b(_._1.end._1,d._1.start._2),end:_._1.end,direction:ne},...u]):T,y=m.tag==="Nothing"?p:m;return h.tag==="Nothing"?y:h}if(_.tag==="Nothing")return T;g()}if(d.tag==="Nothing")return T;g()},Zm=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=jm(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)},Km=t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r,s=ki(Li(Um(t)(Zm(t)(u))));if(s.length<u.length){r=s;continue}i=!1,o=s}return o};return n=>e(ki(Li(n)))},t2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=ct(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=Lt(c=>f=>st.compare(c.x)(f.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=Lt(a=>c=>st.compare(c.x)(a.x))(H(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},e2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=ct(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=Lt(c=>f=>st.compare(c.y)(f.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=Lt(a=>c=>st.compare(c.y)(a.y))(H(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},n2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=ct(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=Lt(c=>f=>st.compare(f.x)(c.x))(H(c=>({...c,x:c.x+c.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=Lt(a=>c=>st.compare(a.x)(c.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},r2=t=>e=>n=>r=>{const i=ce(n)(r),o=ge(n)(r),u=ct(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=Lt(c=>f=>st.compare(f.y)(c.y))(H(c=>({...c,y:c.y+c.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=Lt(a=>c=>st.compare(a.y)(c.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},zg=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},Rg=t=>e=>n=>r=>i=>{const o=ce(e)(n),u=ge(e)(n);if(!bi(o)(u)(r)(t))return r;if(!bi(o)(u)(i)(t))return i;const s=(r+i)/2;return bi(o)(u)(s)(t)?zg(a=>bi(o)(u)(a)(t))(s)(1):s},i2=t=>e=>n=>r=>i=>{const o=ce(e)(n),u=ge(e)(n);if(!Ei(o)(u)(r)(t))return r;if(!Ei(o)(u)(i)(t))return i;const s=(r+i)/2;return Ei(o)(u)(s)(t)?zg(a=>Ei(o)(u)(a)(t))(s)(1):s},o2=t=>e=>n=>r=>{const i=ce(e)(n),o=ge(e)(n),u=ct(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},u2=t=>e=>n=>r=>{const i=ce(e)(n),o=ge(e)(n),u=ct(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},s2=t=>e=>n=>r=>i=>o=>u=>{const s=(()=>{if(r==="South")return b(i._1,i._2+4);if(r==="North")return b(i._1,i._2-4);if(r==="East")return b(i._1+4,i._2);if(r==="West")return b(i._1-4,i._2);g()})(),a=(()=>{if(o==="South")return b(u._1,u._2+4);if(o==="North")return b(u._1,u._2-4);if(o==="East")return b(u._1+4,u._2);if(o==="West")return b(u._1-4,u._2);g()})(),c=(k,L,E)=>!Io(e)(ce(L)(E))(ge(L)(E))(k),f=(k,L,E)=>!Io(n)(ce(L)(E))(ge(L)(E))(k),d=(k,L,E,B)=>t.tag==="Just"&&!Gi(n)(ce(k)(L))(ge(k)(L))(t._1)?t._1:i2(e)(k)(L)(E)(B),l=(k,L,E,B)=>{if(k===E){const et=o2(e)(L)(B)(k),D=e2(e)(k)(L)(B),S=r2(e)(k)(L)(B);return[{start:b(k,L),end:b(k,D),direction:ne},{start:b(k,D),end:b(et,D),direction:ee},{start:b(et,D),end:b(et,S),direction:ne},{start:b(et,S),end:b(E,S),direction:ee},{start:b(E,S),end:b(E,B),direction:ne}]}const V=d(k,E,L,B);return[{start:b(k,L),end:b(k,V),direction:ne},{start:b(k,V),end:b(E,V),direction:ee},{start:b(E,V),end:b(E,B),direction:ne}]},_=(k,L,E,B)=>{if(L===B){const et=u2(e)(k)(E)(L),D=t2(e)(L)(k)(E),S=n2(e)(L)(k)(E);return[{start:b(k,L),end:b(D,L),direction:ee},{start:b(D,L),end:b(D,et),direction:ne},{start:b(D,et),end:b(S,et),direction:ee},{start:b(S,et),end:b(S,B),direction:ne},{start:b(S,B),end:b(E,B),direction:ee}]}const V=Rg(e)(L)(B)(k)(E);return[{start:b(k,L),end:b(V,L),direction:ee},{start:b(V,L),end:b(V,B),direction:ne},{start:b(V,B),end:b(E,B),direction:ee}]},h=(k,L,E)=>!Gi(e)(ce(L)(E))(ge(L)(E))(k),m=(k,L,E)=>!Gi(n)(ce(L)(E))(ge(L)(E))(k),p=(k,L,E,B)=>{if(m(L,k,E)&&f(E,L,B))return[{start:b(k,L),end:b(E,L),direction:ee},{start:b(E,L),end:b(E,B),direction:ne}];const V=Rg(e)(L)(B)(k)(E);return[{start:b(k,L),end:b(V,L),direction:ee},{start:b(V,L),end:b(V,B),direction:ne},{start:b(V,B),end:b(E,B),direction:ee}]},y=(k,L,E,B)=>{if(f(k,L,B)&&m(B,k,E))return[{start:b(k,L),end:b(k,B),direction:ne},{start:b(k,B),end:b(E,B),direction:ee}];const V=d(k,E,L,B);return[{start:b(k,L),end:b(k,V),direction:ne},{start:b(k,V),end:b(E,V),direction:ee},{start:b(E,V),end:b(E,B),direction:ne}]},x=(()=>{if(r==="South")return o==="North"?s._1===a._1&&c(s._1,s._2,a._2)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:ne}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?y(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="North")return o==="South"?s._1===a._1&&c(s._1,s._2,a._2)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:ne}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?y(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="East")return o==="West"?s._2===a._2&&h(s._2,s._1,a._1)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:ee}]:_(s._1,s._2,a._1,a._2):o==="North"||o==="South"?p(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="West"){if(o==="East")return s._2===a._2&&h(s._2,s._1,a._1)?[{start:b(s._1,s._2),end:b(a._1,a._2),direction:ee}]:_(s._1,s._2,a._1,a._2);if(o==="North"||o==="South")return p(s._1,s._2,a._1,a._2)}return l(s._1,s._2,a._1,a._2)})(),N=(()=>{if(r==="South"||r==="North")return ne;if(r==="East"||r==="West")return ee;g()})(),v={start:b(a._1,a._2),end:b(u._1,u._2),direction:(()=>{if(o==="South"||o==="North")return ne;if(o==="East"||o==="West")return ee;g()})()};return s._1===a._1&&s._2===a._2?[{start:b(i._1,i._2),end:b(u._1,u._2),direction:N}]:Vm({start:b(i._1,i._2),end:b(s._1,s._2),direction:N})(x)(v)},a2=H(t=>({x:t.position._1*Qo-2,y:t.position._2*Qo-2,w:t.size._1*Qo+4,h:t.size._2*Qo+4})),Cs=Kt(C)(Bt),Pn=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},Ss=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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=w("Just",o._4);continue}}g()}return i},c2=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t._1)(o._3._1);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(t._2==="North"){if(o._3._2==="North"){r=!1,i=w("Just",o._4);continue}n=o._5;continue}if(o._3._2==="North"){n=o._6;continue}if(t._2==="South"){if(o._3._2==="South"){r=!1,i=w("Just",o._4);continue}n=o._5;continue}if(o._3._2==="South"){n=o._6;continue}if(t._2==="East"){if(o._3._2==="East"){r=!1,i=w("Just",o._4);continue}n=o._5;continue}if(o._3._2==="East"){n=o._6;continue}if(t._2==="West"&&o._3._2==="West"){r=!1,i=w("Just",o._4);continue}}g()}return i},Wg=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()},Ds=t=>e=>{const n=rt(4);if(t==="South")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="North")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="East")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};if(t==="West")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};g()},Hg=t=>e=>J(n=>r=>vt(t)(te)(e(r))([r])(n))(Q),Og=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},qg=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,i=e.length;return i===0?Q:Cs(i===1?H(o=>b(o,r))(e):Qt(o=>u=>b(u,t.lo+rt(o+1|0)*n/rt(i+1|0)))(e))},$g=t=>e=>n=>r=>i=>{const o=Hg(C)(_=>_.to.node)(t),u=Hg(C)(_=>_.from.node)(t),s=J(_=>h=>j(C)(h.node)(h)(_))(Q)(e),a=(_,h,m)=>{const p=Pn(_)(s);if(p.tag==="Nothing")return b(0,0);if(p.tag==="Just"){const y=Pn(_)(n);if(y.tag==="Nothing"){const x=rt(4);if(m==="South")return b(p._1.position._1*x+p._1.size._1*x/2,(p._1.position._2+p._1.size._2)*x);if(m==="North")return b(p._1.position._1*x+p._1.size._1*x/2,p._1.position._2*x);if(m==="East")return b((p._1.position._1+p._1.size._1)*x,p._1.position._2*x+p._1.size._2*x/2);if(m==="West")return b(p._1.position._1*x,p._1.position._2*x+p._1.size._2*x/2);g()}if(y.tag==="Just"){const x=Zt(N=>N.id===h)(y._1);if(x.tag==="Nothing"){const N=rt(4);if(m==="South")return b(p._1.position._1*N+p._1.size._1*N/2,(p._1.position._2+p._1.size._2)*N);if(m==="North")return b(p._1.position._1*N+p._1.size._1*N/2,p._1.position._2*N);if(m==="East")return b((p._1.position._1+p._1.size._1)*N,p._1.position._2*N+p._1.size._2*N/2);if(m==="West")return b(p._1.position._1*N,p._1.position._2*N+p._1.size._2*N/2);g()}if(x.tag==="Just"){const N=rt(4);if(x._1.side==="North")return b(p._1.position._1*N+rt(x._1.offset)*N,p._1.position._2*N);if(x._1.side==="South")return b(p._1.position._1*N+rt(x._1.offset)*N,(p._1.position._2+p._1.size._2)*N);if(x._1.side==="East")return b((p._1.position._1+p._1.size._1)*N,p._1.position._2*N+rt(x._1.offset)*N);if(x._1.side==="West")return b(p._1.position._1*N,p._1.position._2*N+rt(x._1.offset)*N)}}}g()},c=Cs(Tt(r)(_=>{if(_.nodes.length<=2)return[];const h=rt(4);if(1<_.nodes.length){const m=Pn(_.nodes[1])(s);if(m.tag==="Nothing")return[];if(m.tag==="Just"){const p=m._1.position._1*h+m._1.size._1*h/2;return H(y=>b(y,p))(Je(y=>x=>_.edgeId+":"+y+"->"+x,_.nodes,bt(1,_.nodes.length,_.nodes)))}g()}return[]})),f=_=>{const h=Pn(_.from.node)(s),m=Pn(_.to.node)(s);if(h.tag==="Just"&&m.tag==="Just"){const p=h._1,y=m._1,x=Lt(N=>v=>it.compare(N.score)(v.score))(H(N=>{const v=N._1,k=N._2;return{from:v,to:k,score:(()=>{const L=(et,D,S,Z,X)=>{const W=Ds(et)(D),z=Ds(et)(S);return W.lo<z.hi&&z.lo<W.hi&&(v==="South"?k==="North"&&X._2>Z._2:v==="North"?k==="South"&&X._2<Z._2:v==="East"?k==="West"&&X._1>Z._1:v==="West"&&k==="East"&&X._1<Z._1)?0:Og(v)(k)(Z)(X)},E=Wg(v)(p),B=Wg(k)(y),V=Og(v)(k)(E)(B);return(()=>{if(V>0){if(v==="South")return k==="North"?L(he,p,y,E,B)*10|0:V*10|0;if(v==="North")return k==="South"?L(le,p,y,E,B)*10|0:V*10|0;if(v==="East")return k==="West"?L(pn,p,y,E,B)*10|0:V*10|0;if(v==="West"&&k==="East")return L(_r,p,y,E,B)*10|0}return V*10|0})()+(v==="South"?k==="North"?0:15:v==="North"?k==="South"?0:15:v==="East"?k==="West"?5:15:v==="West"&&k==="East"?5:15)|0})()}})([b(he,le),b(pn,le),b(_r,le),b(he,pn),b(he,_r),b(le,he),b(le,pn),b(le,_r),b(pn,he),b(_r,he),b(pn,_r),b(_r,pn)]));if(0<x.length)return{from:x[0].from,to:x[0].to}}return{from:he,to:le}},d=Cs(H(_=>b(_.id,f(_)))(t)),l=(_,h,m,p,y,x)=>{const N=rt(4),v=Pn(h)(s);if(v.tag==="Nothing")return b(0,0);if(v.tag==="Just"){const k=c2(b(m,_))(i);if(k.tag==="Just"){const L=v._1.position._1*N+k._1,E=rt(4);if(_==="South")return b(L,(v._1.position._2+v._1.size._2)*E);if(_==="North")return b(L,v._1.position._2*E);if(_==="East")return b((v._1.position._1+v._1.size._1)*E,L);if(_==="West")return b(v._1.position._1*E,L);g()}if(k.tag==="Nothing"){const L=Ds(_)(v._1),E=(L.lo+L.hi)/2,B=Ss(m)(qg(L)(H(D=>D.id)(Lt(D=>S=>st.compare(y(_)(D))(y(_)(S)))(ct(D=>{const S=Ss(D.id)(d);if(S.tag==="Just"){const Z=x(S._1);return Z==="North"?_==="North":Z==="South"?_==="South":Z==="East"?_==="East":Z==="West"&&_==="West"}if(S.tag==="Nothing")return!0;g()},(()=>{const D=Pn(h)(p);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()))))),V=(()=>{if(B.tag==="Nothing")return E;if(B.tag==="Just")return B._1;g()})(),et=rt(4);if(_==="South")return b(V,(v._1.position._2+v._1.size._2)*et);if(_==="North")return b(V,v._1.position._2*et);if(_==="East")return b((v._1.position._1+v._1.size._1)*et,V);if(_==="West")return b(v._1.position._1*et,V)}}g()};return H(_=>{const h=Ss(_.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()})(H(_=>{if(_.from.port.tag==="Just"&&_.to.port.tag==="Just")return{edge:_,fromPos:a(_.from.node,_.from.port._1,he),toPos:a(_.to.node,_.to.port._1,le),fromSide:he,toSide:le};const h=f(_);return{edge:_,fromPos:l(h.from,_.from.node,_.id,u,m=>p=>{const y=Pn(p.to.node)(s);if(y.tag==="Nothing")return 0;if(y.tag==="Just"){const x=rt(4);if(m==="South"||m==="North")return y._1.position._1*x+y._1.size._1*x/2;if(m==="East"||m==="West")return y._1.position._2*x+y._1.size._2*x/2}g()},m=>m.from),toPos:l(h.to,_.to.node,_.id,o,m=>p=>{const y=Pn(p.from.node)(s);if(y.tag==="Nothing")return 0;if(y.tag==="Just"){const x=rt(4);if(m==="South"||m==="North")return y._1.position._1*x+y._1.size._1*x/2;if(m==="East"||m==="West")return y._1.position._2*x+y._1.size._2*x/2}g()},m=>m.to),fromSide:h.from,toSide:h.to}})(t))},Yg=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},Mr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=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=w("Just",o._4);continue}}g()}return i},g2=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),Ps=t=>e=>t.gapTop+1*rt(4)+rt(e)*2.5*rt(4),f2=t=>e=>{const n=Yg(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return w("Just",{slot1Y:Ps(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Ps(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return T;g()}if(n.tag==="Nothing")return T;g()},_2=t=>e=>{const n=J(r=>i=>j(C)(i.node)(i)(r))(Q)(e);return Ae(Qt(r=>i=>{const o=Mr(i.node)(n);if(o.tag==="Nothing")return[];if(o.tag==="Just"){const u=o._1;return Qt(s=>a=>{const c=i.edges.length,f=rt(4),d=u.position._1*f,l=u.position._2*f,_=u.size._2*f,h=rt((2*c|0)+1|0),m=l+_*rt(c-s|0)/h,p=l+_*rt((c+1|0)+s|0)/h,y=d-f*2.5*rt(s+1|0),x=[{start:b(d,m),end:b(y,m),direction:ee},{start:b(y,m),end:b(y,p),direction:ne},{start:b(y,p),end:b(d,p),direction:ee}];return{edge:a.id,segments:x,bends:Je(N=>v=>N.end,x,bt(1,3,x)),bendType:[],jumps:[],reversed:!1}})(i.edges)}g()})(H(r=>({node:r._1,edges:r._2}))(g2(J(r=>i=>vt(C)(te)(i.from.node)([i])(r))(Q)(t)))))},d2=t=>e=>{const n=J(o=>u=>j(C)(u.node)(u)(o))(Q)(e),r=o=>{const u=Mr(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.position._1;g()},i=o=>{const u=Mr(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.layer;g()};return Lt(o=>u=>{const s=it.compare(i(o.edge.from.node))(i(u.edge.from.node));if(s==="EQ"){const a=st.compare(r(o.edge.from.node))(r(u.edge.from.node));return a==="EQ"?st.compare(r(o.edge.to.node))(r(u.edge.to.node)):a}return s})(t)},Pe=t=>{const e=rt(4);return{x:t.position._1*e-2,y:t.position._2*e-2,w:t.size._1*e+4,h:t.size._2*e+4}},l2=t=>t.from.node===t.to.node,h2=t=>e=>n=>r=>{const i=Km(n)(s2(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:i,bends:Je(o=>u=>o.end,i,bt(1,i.length,i)),bendType:[],jumps:[],reversed:!1}},p2=t=>e=>n=>r=>{const i=[{start:b(r.fromPos._1,r.fromPos._2),end:b(r.fromPos._1,t.slot1Y),direction:ne},{start:b(r.fromPos._1,t.slot1Y),end:b(t.splitX,t.slot1Y),direction:ee},{start:b(t.splitX,t.slot1Y),end:b(t.splitX,t.slot2Y),direction:ne},{start:b(t.splitX,t.slot2Y),end:b(r.toPos._1,t.slot2Y),direction:ee},{start:b(r.toPos._1,t.slot2Y),end:b(r.toPos._1,r.toPos._2),direction:ne}];return{edge:r.edge.id,segments:i,bends:Je(o=>u=>o.end,i,bt(1,5,i)),bendType:[],jumps:[],reversed:!1}},m2=t=>e=>n=>{const r=Mr(t.edge.from.node)(n);if(r.tag==="Just"){const o=Mr(t.edge.to.node)(n);return o.tag==="Just"?ct(u=>!(u.h===Pe(r._1).h&&u.w===Pe(r._1).w&&u.x===Pe(r._1).x&&u.y===Pe(r._1).y)&&!(u.h===Pe(o._1).h&&u.w===Pe(o._1).w&&u.x===Pe(o._1).x&&u.y===Pe(o._1).y),e):ct(u=>!(u.h===Pe(r._1).h&&u.w===Pe(r._1).w&&u.x===Pe(r._1).x&&u.y===Pe(r._1).y),e)}const i=Mr(t.edge.to.node)(n);return i.tag==="Just"?ct(o=>!(o.h===Pe(i._1).h&&o.w===Pe(i._1).w&&o.x===Pe(i._1).x&&o.y===Pe(i._1).y),e):ct(o=>!0,e)},y2=t=>e=>{const n=Yg(e.edge.id)(t);if(n.tag==="Just")return w("Just",Ps(n._1)(n._1.slot));if(n.tag==="Nothing")return T;g()},x2=t=>e=>n=>r=>i=>{const o=J(c=>f=>j(C)(f.node)(f)(c))(Q)(e),u=a2(e),s=$g(ct(c=>c.from.node!==c.to.node,t))(e)(n)(r)(i),a=Mg(s)(e);return[..._2(ct(l2,t))(e),...J(c=>f=>{const d=m2(f)(u)(o),l=[...d,...c.edgeObstacles],_=f2(a)(f),h=(()=>{if(_.tag==="Just")return p2(_._1)(d)(l)(f);if(_.tag==="Nothing")return h2(y2(a)(f))(d)(l)(f);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...Ym(h.segments)]}})({results:[],edgeObstacles:[]})(d2(s)(e)).results]},Zn=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Kn=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},N2=t=>e=>n=>{if(t.start._1!==e.start._1)return T;const r=Kn(Zn(t.start._2)(t.end._2))(Zn(e.start._2)(e.end._2)),i=Zn(Kn(t.start._2)(t.end._2))(Kn(e.start._2)(e.end._2));return r<i?w("Just",{position:b(t.start._1,(r+i)/2),crossingEdge:n}):T},J2=t=>e=>n=>{if(t.start._2!==e.start._2)return T;const r=Kn(Zn(t.start._1)(t.end._1))(Zn(e.start._1)(e.end._1)),i=Zn(Kn(t.start._1)(t.end._1))(Kn(e.start._1)(e.end._1));return r<i?w("Just",{position:b((r+i)/2,t.start._2),crossingEdge:n}):T},T2=t=>e=>n=>{if(t.direction==="H")return J2(t)(e)(n);if(t.direction==="V")return N2(t)(e)(n);g()},v2=t=>e=>n=>{const r=t+1|0,i=r<1?n:bt(r,n.length,n);return Tt(e.segments)(o=>Tt(i)(u=>xt(s=>T2(o)(s)(u.edge))(ct(s=>s.direction==="H"?o.direction==="H":s.direction==="V"&&o.direction==="V",u.segments))))},w2=t=>e=>n=>e.start._1>Zn(t.start._1)(t.end._1)&&e.start._1<Kn(t.start._1)(t.end._1)&&t.start._2>Zn(e.start._2)(e.end._2)&&t.start._2<Kn(e.start._2)(e.end._2)?w("Just",{position:b(e.start._1,t.start._2),crossingEdge:n}):T,b2=t=>e=>Tt(ct(n=>n.direction==="H",t.segments))(n=>Tt(e)(r=>xt(i=>w2(n)(i)(r.edge))(ct(i=>i.direction==="V",r.segments)))),L2=t=>e=>n=>[...b2(e)(ct(r=>r.edge!==e.edge,n)),...v2(t)(e)(n)],Vg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Xg=t=>me(3)(t)==="$d:",k2=t=>e=>n=>J(r=>i=>{const o=Vg(i.from.node)(t),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})(),s=Vg(i.to.node)(t),a=(()=>{if(s.tag==="Nothing")return-u;if(s.tag==="Just")return s._1-u|0;g()})();if(a<=1)return{...r,edges:[...r.edges,i],chains:[...r.chains,{edgeId:i.id,nodes:[i.from.node,i.to.node]}]};const c=i.id,f=H(l=>"$d:"+c+":"+ie(l))(It(1,a-1|0)),d=[i.from.node,...f,i.to.node];return{...r,layers:J(l=>_=>{const h=_._2,m=od(u+_._1|0)(p=>[...p,h])(l);if(m.tag==="Nothing")return l;if(m.tag==="Just")return m._1;g()})(r.layers)(Je(Hn,It(1,a-1|0),f)),edges:[...r.edges,...Je(l=>_=>({id:c+":"+l+"->"+_,from:{node:l,port:i.from.port},to:{node:_,port:i.to.port}}),d,bt(1,d.length,d))],chains:[...r.chains,{edgeId:i.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),Fo=(()=>{const t={eq:e=>n=>e._1===n._1&&(e._2==="North"?n._2==="North":e._2==="South"?n._2==="South":e._2==="East"?n._2==="East":e._2==="West"&&n._2==="West")};return{compare:e=>n=>{const r=C.compare(e._1)(n._1);if(r==="LT")return ye;if(r==="GT")return xe;if(e._2==="North")return n._2==="North"?Se:ye;if(n._2==="North")return xe;if(e._2==="South")return n._2==="South"?Se:ye;if(n._2==="South")return xe;if(e._2==="East")return n._2==="East"?Se:ye;if(n._2==="East")return xe;if(e._2==="West"&&n._2==="West")return Se;g()},Eq0:()=>t}})(),E2=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=Fo.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},G2=Kt(C)(Bt),Is=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},C2=Kt(Fo)(Bt),Ug=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),Br=t=>e=>n=>r=>{const i=E2(b(e,n))(t);if(i.tag==="Nothing")return r;if(i.tag==="Just")return i._1;g()},jg=t=>e=>n=>{const r=G2(Ae(H(u=>Qt(s=>a=>b(a,s))(u))(t))),i=(u,s)=>{if(u==="South"){const a=Is(s.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()}if(u==="North"){const a=Is(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=>Ge(Fo.compare,Le,C2(H(c=>b(b(c._1,u),c._2))(Ug(qg({lo:0,hi:(()=>{const c=Is(a._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return me(3)(a._1)==="$d:"?0:1;g()})()})(H(c=>c.id)(Lt(c=>f=>it.compare(i(u,c))(i(u,f)))(a._2)))))),s))(Q)(Ug(J(s=>a=>a.from.node===a.to.node?s:u==="South"?vt(C)(te)(a.from.node)([a])(s):u==="North"?vt(C)(te)(a.to.node)([a])(s):s)(Q)(e)));return Ge(Fo.compare,Le,o(le),o(he))},Zg=t=>t,Kg=t=>t,tf=t=>t,S2=J(t=>e=>j(C)(e)()(t))(Q),D2=(()=>{const t=qe.unfoldr(e=>{if(e.tag==="Nil")return T;if(e.tag==="Cons")return w("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._3,n(r._6,i)));g()};return n(e,qt)})())})(),ot=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},en=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Nn=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jn=Kt(C)(Bt),Qs=Xa(C),Fs=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),P2=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},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=it.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},ef=tf("VDown"),nf=tf("VUp"),Q2=Kg("ForwardPhase"),F2=Kg("StackPhase"),rf=Zg("HRight"),of=Zg("HLeft"),uf=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},A2=t=>e=>n=>{const r=J(u=>s=>vt(C)(oe)(s.tgt)(1)(u))(Q)(t),i=D2(S2([...H(u=>u.src)(t),...H(u=>u.tgt)(t),...(()=>{const u=(s,a)=>{if(s.tag==="Leaf")return a;if(s.tag==="Node")return u(s._5,Ot("Cons",s._4,u(s._6,a)));g()};return kt($t.foldr,u(e,qt))})()])),o=J(u=>s=>vt(C)(te)(s.src)([{target:s.tgt,sep:s.sep}])(u))(Q)(t);return(u=>s=>a=>{let c=u,f=s,d=a,l=!0,_;for(;l;){const h=c,m=f,p=d,y=Ft(x=>T,x=>N=>w("Just",{head:x,tail:N}),h);if(y.tag==="Nothing"){l=!1,_=p;continue}if(y.tag==="Just"){const x=ot(y._1.head)(p),N=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})(),v=J(k=>L=>{const E=ot(L.target)(k.result),B=N+L.sep,V=ot(L.target)(k.indeg),et=(()=>{if(V.tag==="Nothing")return-1;if(V.tag==="Just")return V._1-1|0;g()})();return{newQueue:et===0?[...k.newQueue,L.target]:k.newQueue,result:j(C)(L.target)((()=>{if(E.tag==="Nothing")return B;if(E.tag==="Just"){if(n==="VDown")return en(E._1)(B);if(n==="VUp")return Nn(E._1)(B)}g()})())(k.result),indeg:j(C)(L.target)(et)(k.indeg)}})({newQueue:[],result:p,indeg:m})((()=>{const k=ot(y._1.head)(o);if(k.tag==="Nothing")return[];if(k.tag==="Just")return k._1;g()})());c=[...y._1.tail,...v.newQueue],f=v.indeg,d=v.result;continue}g()}return _})(ct(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))},M2=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,Ot("Cons",o._4,e(o._6,u)));g()},n=kt($t.foldr,e(t,qt)),r=J(en)(999999)(n);if(r===0||n.length===0)return t;const i=o=>{if(o.tag==="Leaf")return 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)},sf=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,Ot("Cons",o._4,e(o._6,u)));g()},n=e(t,qt),r=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l.tag==="Nil"){c=!1,f=d;continue}if(l.tag==="Cons"){s=Nn(d)(l._1),a=l._2;continue}g()}return f},i=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l.tag==="Nil"){c=!1,f=d;continue}if(l.tag==="Cons"){s=en(d)(l._1),a=l._2;continue}g()}return f};return r(-999999)(n)-i(999999)(n)},Ci=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]),B2=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>{const d=(G,P,I)=>{const F=G.from.node===P?G.from.port:G.to.node===P?G.to.port:T;if(F.tag==="Just"){const O=ot(P)(i);if(O.tag==="Just"){const Y=Zt(q=>q.id===F._1)(O._1);if(Y.tag==="Just"){const q=rt(Y._1.offset)*rt(4);return I==="North"||I==="South"?q:0}if(Y.tag==="Nothing"){const q=ot(P)(r),$=Br(u)(G.id)(I)((()=>{if(q.tag==="Nothing")return .5;if(q.tag==="Just")return q._1._1/2;g()})());return I==="North"||I==="South"?$:0}g()}if(O.tag==="Nothing"){const Y=ot(P)(r),q=Br(u)(G.id)(I)((()=>{if(Y.tag==="Nothing")return .5;if(Y.tag==="Just")return Y._1._1/2;g()})());return I==="North"||I==="South"?q:0}g()}if(F.tag==="Nothing"){const O=ot(P)(r),Y=Br(u)(G.id)(I)((()=>{if(O.tag==="Nothing")return .5;if(O.tag==="Just")return O._1._1/2;g()})());return I==="North"||I==="South"?Y:0}g()},l=(G,P)=>{if(G.from.node===P){if(f==="HRight")return he;if(f==="HLeft")return le;g()}if(f==="HRight")return le;if(f==="HLeft")return he;g()},_=(G,P,I)=>J(F=>O=>j(C)(O)((()=>{const Y=ot(O)(F);if(Y.tag==="Nothing")return 0+P;if(Y.tag==="Just")return Y._1+P;g()})())(F))(I)(Ci(a)(G)),h=(()=>{if(f==="HRight")return n;if(f==="HLeft")return ke(n);g()})(),m=G=>{const P=ot(G)(r);if(P.tag==="Nothing")return 1;if(P.tag==="Just")return P._1._1;g()},p=Jn(Ae(Qt(G=>P=>H(I=>b(I,G))(P))(n))),y=(G,P)=>me(3)(G)==="$d:"&&me(3)(P)==="$d:"||me(3)(G)==="$d:"||me(3)(P)==="$d:"?10:rt(t.nodeGap),x=J(G=>P=>Qs(I=>w("Just",[...(()=>{if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})(),P]))(P.to.node)(G))(Q)(o),N=J(G=>P=>Qs(I=>w("Just",[...(()=>{if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})(),P]))(P.from.node)(G))(Q)(o),v=Ae(n),k=J(G=>P=>{const I=ot(P)(a.root),F=(()=>{if(I.tag==="Nothing")return P;if(I.tag==="Just")return I._1;g()})();return P===F?G:Qs(O=>w("Just",(()=>{if(O.tag==="Nothing")return!0;if(O.tag==="Just")return O._1;g()})()&&me(3)(P)==="$d:"))(F)(G)})(Jn(H(G=>b(G,!0))(Nr(C.compare)((()=>{const G=(P,I)=>{if(P.tag==="Leaf")return I;if(P.tag==="Node")return G(P._5,Ot("Cons",P._4,G(P._6,I)));g()};return kt($t.foldr,G(a.root,qt))})()))))(v),L=(G,P)=>{const I=G.free,F=ot(I)(a.root),O=(()=>{if(F.tag==="Nothing")return I;if(F.tag==="Just")return F._1;g()})(),Y=ot(O)(k),q=(()=>{if(Y.tag==="Nothing")return!0;if(Y.tag==="Just")return Y._1;g()})();return J($=>R=>{if($.edge.tag==="Just")return $;if($.edge.tag==="Nothing"){if((()=>{const at=ot(O)(P.su);return!q&&(()=>{const yt=ot(R.from.node)(p);return R.from.node!==R.to.node&&(()=>{const Et=ot(R.to.node)(p);return(()=>{if(yt.tag==="Nothing")return-1;if(yt.tag==="Just")return yt._1;g()})()===(()=>{if(Et.tag==="Nothing")return-1;if(Et.tag==="Just")return Et._1;g()})()})()})()||(()=>{if(at.tag==="Nothing")return!1;if(at.tag==="Just")return at._1;g()})()})())return $;const tt=R.from.node===I?R.to.node:R.from.node,K=ot(tt)(a.root),gt=(()=>{if(K.tag==="Nothing")return tt;if(K.tag==="Just")return K._1;g()})(),_t=gt!==O;return _t&&(()=>{const at=ot(gt)(P.blockFinished);if(at.tag==="Nothing")return!1;if(at.tag==="Just")return at._1;g()})()?{...$,edge:w("Just",R),hasEdges:!0}:{...$,hasEdges:$.hasEdges||_t}}g()})({edge:T,hasEdges:!1})((()=>{if(G.isRoot){if(f==="HRight"){const $=ot(I)(x);if($.tag==="Nothing")return[];if($.tag==="Just")return $._1;g()}if(f==="HLeft"){const $=ot(I)(N);if($.tag==="Nothing")return[];if($.tag==="Just")return $._1}g()}if(f==="HRight"){const $=ot(I)(N);if($.tag==="Nothing")return[];if($.tag==="Just")return $._1;g()}if(f==="HLeft"){const $=ot(I)(x);if($.tag==="Nothing")return[];if($.tag==="Just")return $._1}g()})())},E=(G,P,I,F)=>{const O=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),Y={free:P,isRoot:I},q=L(Y,F);if(q.edge.tag==="Nothing")return q.hasEdges?{thresh:O,state:{...F,queue:[...F.queue,Y]}}:{thresh:O,state:F};if(q.edge.tag==="Just"){const $=q.edge._1.from.node===P?q.edge._1.to.node:q.edge._1.from.node;return{thresh:(()=>{const R=ot((()=>{const _t=ot($)(a.root);if(_t.tag==="Nothing")return $;if(_t.tag==="Just")return _t._1;g()})())(F.x),tt=ot($)(s),K=ot(P)(s),gt=(()=>{if(R.tag==="Just")return R._1;if(R.tag==="Nothing")return T;g()})();return(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()+(()=>{if(tt.tag==="Nothing")return 0;if(tt.tag==="Just")return tt._1;g()})()+d(q.edge._1,$,(()=>{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(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()-d(q.edge._1,P,(()=>{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:{...F,su:j(C)((()=>{const R=ot(q.edge._1.from.node)(a.root);if(R.tag==="Nothing")return q.edge._1.from.node;if(R.tag==="Just")return R._1;g()})())(!0)(j(C)((()=>{const R=ot(q.edge._1.to.node)(a.root);if(R.tag==="Nothing")return q.edge._1.to.node;if(R.tag==="Just")return R._1;g()})())(!0)(F.su))}}}g()},B=(G,P,I,F)=>{const O=P===G,Y=ot(P)(a.align),q=(()=>{if(Y.tag==="Nothing")return P===G;if(Y.tag==="Just")return Y._1===G;g()})();if(!(O||q))return{thresh:I,state:F};const $=(()=>{if(c==="VDown")return O&&I<=-1e18;if(c==="VUp")return O&&I>=1e18;g()})()?E(G,P,!0,F):{thresh:I,state:F};return(()=>{if(c==="VDown")return $.thresh<=-1e18&&q;if(c==="VUp")return $.thresh>=1e18&&q;g()})()?E(G,P,!1,$.state):$},V=G=>P=>I=>{const F=ot(I)(e.nodeIndex),O=(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;g()})(),Y=Zt(K=>Be(gn)(I)(K))(h),q=(()=>{if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1;g()})(),$=q.length;if((()=>{if(c==="VDown")return O<=0;if(c==="VUp")return O>=($-1|0);g()})()){const K=B(G,I,P.thresh,P.st);return{...P,st:K.state,thresh:K.thresh}}const R=(()=>{if(c==="VDown")return O-1|0;if(c==="VUp")return O+1|0;g()})(),tt=R>=0&&R<q.length?w("Just",q[R]):T;if(tt.tag==="Nothing")return P;if(tt.tag==="Just"){const K=ot(tt._1)(a.root),gt=(()=>{if(K.tag==="Nothing")return tt._1;if(K.tag==="Just")return K._1;g()})(),_t=B(G,I,P.thresh,et(gt)(P.st)),at=(()=>{const Vt=ot(G)(_t.state.sink);if(Vt.tag==="Nothing")return G===G;if(Vt.tag==="Just")return Vt._1===G;g()})()?{..._t.state,sink:j(C)(G)((()=>{const Vt=ot(gt)(_t.state.sink);if(Vt.tag==="Nothing")return gt;if(Vt.tag==="Just")return Vt._1;g()})())(_t.state.sink)}:_t.state,yt=ot(gt)(at.sink),Et=(()=>{if(yt.tag==="Nothing")return gt;if(yt.tag==="Just")return yt._1;g()})(),At=ot(G)(at.sink),pt=(()=>{if(At.tag==="Nothing")return G;if(At.tag==="Just")return At._1;g()})();if(pt===Et){const Vt=ot(gt)(at.x),De=(()=>{if(Vt.tag==="Just")return Vt._1;if(Vt.tag==="Nothing")return T;g()})(),un=(()=>{if(De.tag==="Nothing")return 0;if(De.tag==="Just")return De._1;g()})(),Ne=ot(G)(at.x),Ct=(()=>{if(Ne.tag==="Just")return Ne._1;if(Ne.tag==="Nothing")return T;g()})(),Pt=(()=>{if(Ct.tag==="Nothing")return 0;if(Ct.tag==="Just")return Ct._1;g()})(),je=y(I,tt._1),Ze=ot(tt._1)(s),kn=ot(I)(s),jr=(()=>{if(Ze.tag==="Nothing")return 0;if(Ze.tag==="Just")return Ze._1;g()})()-(()=>{if(kn.tag==="Nothing")return 0;if(kn.tag==="Just")return kn._1;g()})();if(c==="VDown"){const _n=Nn(un+jr+m(tt._1)+je)(_t.thresh);return{st:{...at,x:j(C)(G)(w("Just",P.initial?_n:Nn(Pt)(_n)))(at.x)},initial:!1,thresh:_t.thresh}}if(c==="VUp"){const _n=en(un+jr-je-m(I))(_t.thresh);return{st:{...at,x:j(C)(G)(w("Just",P.initial?_n:en(Pt)(_n)))(at.x)},initial:!1,thresh:_t.thresh}}g()}const Mt=ot(gt)(at.x),Jt=(()=>{if(Mt.tag==="Just")return Mt._1;if(Mt.tag==="Nothing")return T;g()})(),mt=(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})(),nt=ot(G)(at.x),U=(()=>{if(nt.tag==="Just")return nt._1;if(nt.tag==="Nothing")return T;g()})(),ut=(()=>{if(U.tag==="Nothing")return 0;if(U.tag==="Just")return U._1;g()})(),ft=rt(t.nodeGap),lt=ot(I)(s),Nt=ot(tt._1)(s),Ht=(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()-(()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1;g()})();return{st:{...at,classEdges:[...at.classEdges,{src:pt,tgt:Et,sep:(()=>{if(c==="VDown")return ut+Ht-mt-m(tt._1)-ft;if(c==="VUp")return ut+Ht+m(I)+ft-mt;g()})()}]},initial:P.initial,thresh:_t.thresh}}g()},et=G=>P=>{const I=ot(G)(P.x),F=(()=>{if(I.tag==="Just")return I._1;if(I.tag==="Nothing")return T;g()})();if(F.tag==="Just")return P;if(F.tag==="Nothing"){const O=J(V(G))({st:{...P,x:j(C)(G)(w("Just",0))(P.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})()})(Ci(a)(G));return{...O.st,blockFinished:j(C)(G)(!0)(O.st.blockFinished)}}g()},D=J(G=>P=>J(I=>F=>{const O=ot(F)(a.root),Y=(()=>{if(O.tag==="Nothing")return F;if(O.tag==="Just")return O._1;g()})();return Y===F?et(Y)(I):I})(G)((()=>{if(c==="VDown")return P;if(c==="VUp")return ke(P);g()})()))({x:Jn(H(G=>b(G,T))(v)),sink:Jn(H(G=>b(G,G))(v)),classEdges:[],su:Q,blockFinished:Q,queue:[]})(h),S=A2(D.classEdges)(D.sink)(c),Z=(G,P,I,F)=>{const O=ot(P)(F),Y=ot(P)(s);return(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;g()})()+(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;g()})()+d(G,P,I)},X=Jn(H(G=>b(G,!0))(Nr(C.compare)((()=>{const G=(P,I)=>{if(P.tag==="Leaf")return I;if(P.tag==="Node")return G(P._5,Ot("Cons",P._4,G(P._6,I)));g()};return kt($t.foldr,G(a.root,qt))})()))),W=G=>P=>I=>{const F=L(I,{su:P.su,blockFinished:X}),O={phase:G,ppFree:I.free,ppIsRoot:I.isRoot,edgeId:T,delta:0,avail:0,shift:0,freeSu:(()=>{const Y=ot((()=>{const q=ot(I.free)(a.root);if(q.tag==="Nothing")return I.free;if(q.tag==="Just")return q._1;g()})())(P.su);if(Y.tag==="Nothing")return!1;if(Y.tag==="Just")return Y._1;g()})(),hasEdges:F.hasEdges,candCount:(()=>{if(I.isRoot){if(f==="HRight"){const Y=ot(I.free)(x);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length;g()}if(f==="HLeft"){const Y=ot(I.free)(N);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length}g()}if(f==="HRight"){const Y=ot(I.free)(N);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length;g()}if(f==="HLeft"){const Y=ot(I.free)(x);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length}g()})()};if(F.edge.tag==="Nothing")return{...P,stack:[...P.stack,I],trace:[...P.trace,O],x:P.x};if(F.edge.tag==="Just"){const Y=F.edge._1.from.node===I.free?b(F.edge._1.from.node,F.edge._1.to.node):b(F.edge._1.to.node,F.edge._1.from.node),q=Z(F.edge._1,Y._1,l(F.edge._1,Y._1),P.x)-Z(F.edge._1,Y._2,l(F.edge._1,Y._2),P.x),$=ot(Y._1)(a.root),R=(()=>{if($.tag==="Nothing")return Y._1;if($.tag==="Just")return $._1;g()})(),tt={...O,edgeId:w("Just",F.edge._1.id),delta:q};if(q>0&&q<1e300){const K=J(at=>yt=>{const Et=ot(yt)(p),At=(()=>{if(Et.tag==="Nothing")return-1;if(Et.tag==="Just")return Et._1;g()})();if(At>=0&&At<n.length){const Jt=n[At],mt=ot(yt)(e.nodeIndex),nt=(()=>{if(mt.tag==="Nothing")return-2;if(mt.tag==="Just")return mt._1-1|0;g()})();return nt>=0&&nt<Jt.length?en(at)((()=>{const U=ot(yt)(P.x),ut=ot(yt)(s),ft=ot(Jt[nt])(P.x),lt=ot(Jt[nt])(s);return(()=>{if(U.tag==="Nothing")return 0;if(U.tag==="Just")return U._1;g()})()+(()=>{if(ut.tag==="Nothing")return 0;if(ut.tag==="Just")return ut._1;g()})()-((()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;g()})()+(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()+m(Jt[nt])+y(yt,Jt[nt]))})()):at}const pt=ot(yt)(e.nodeIndex),Mt=(()=>{if(pt.tag==="Nothing")return-2;if(pt.tag==="Just")return pt._1-1|0;g()})();return Mt>=0&&Mt<0?en(at)((()=>{const Jt=ot(yt)(P.x),mt=ot(yt)(s),nt=ot([][Mt])(P.x),U=ot([][Mt])(s);return(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})()+(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()-((()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;g()})()+(()=>{if(U.tag==="Nothing")return 0;if(U.tag==="Just")return U._1;g()})()+m([][Mt])+y(yt,[][Mt]))})()):at})(q)(Ci(a)(R)),gt=K>0?-K:0,_t={...P,x:K>0?_(R,gt,P.x):P.x,trace:[...P.trace,{...tt,avail:K,shift:gt}]};return K>0?_t:{..._t,stack:[..._t.stack,I]}}if(q<0&&-q<1e300){const K=J(at=>yt=>{const Et=ot(yt)(p),At=(()=>{if(Et.tag==="Nothing")return-1;if(Et.tag==="Just")return Et._1;g()})();if(At>=0&&At<n.length){const Jt=n[At],mt=ot(yt)(e.nodeIndex),nt=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1+1|0;g()})();return nt>=0&&nt<Jt.length?en(at)((()=>{const U=ot(Jt[nt])(P.x),ut=ot(Jt[nt])(s),ft=ot(yt)(P.x),lt=ot(yt)(s);return(()=>{if(U.tag==="Nothing")return 0;if(U.tag==="Just")return U._1;g()})()+(()=>{if(ut.tag==="Nothing")return 0;if(ut.tag==="Just")return ut._1;g()})()-((()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;g()})()+(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()+m(yt)+y(yt,Jt[nt]))})()):at}const pt=ot(yt)(e.nodeIndex),Mt=(()=>{if(pt.tag==="Nothing")return 0;if(pt.tag==="Just")return pt._1+1|0;g()})();return Mt>=0&&Mt<0?en(at)((()=>{const Jt=ot([][Mt])(P.x),mt=ot([][Mt])(s),nt=ot(yt)(P.x),U=ot(yt)(s);return(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})()+(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()-((()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;g()})()+(()=>{if(U.tag==="Nothing")return 0;if(U.tag==="Just")return U._1;g()})()+m(yt)+y(yt,[][Mt]))})()):at})(-q)(Ci(a)(R)),gt=K>0?K:0,_t={...P,x:K>0?_(R,gt,P.x):P.x,trace:[...P.trace,{...tt,avail:K,shift:gt}]};return K>0?_t:{..._t,stack:[..._t.stack,I]}}return{...P,stack:[...P.stack,I],trace:[...P.trace,tt],x:P.x}}g()},z=J(W(Q2))({x:Jn(H(G=>b(G,(()=>{const P=ot(G)(a.root),I=(()=>{if(P.tag==="Nothing")return G;if(P.tag==="Just")return P._1;g()})(),F=ot(I)(D.x),O=ot((()=>{const q=ot(I)(D.sink);if(q.tag==="Nothing")return I;if(q.tag==="Just")return q._1;g()})())(S),Y=(()=>{if(F.tag==="Just")return F._1;if(F.tag==="Nothing")return T;g()})();return(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;g()})()+(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;g()})()})()))(v)),su:D.su,stack:[],trace:[]})(D.queue),M=J(W(F2))({...z,stack:[]})(ke(z.stack));return{x:M.x,queue:D.queue,trace:M.trace}},z2=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>B2(t)(e)(n)(r)(i)(o)(u)(s)(a)(c)(f).x,R2=t=>e=>n=>r=>i=>o=>{const u=(a,c,f)=>{const d=ot(c)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;g()})(),_=a.from.node===c?a.from.port:a.to.node===c?a.to.port:T;if(_.tag==="Just"){const h=ot(c)(e);if(h.tag==="Just"){const m=Zt(p=>p.id===_._1)(h._1);if(m.tag==="Just"){const p=rt(m._1.offset)*rt(4);return f==="North"||f==="South"?p:0}if(m.tag==="Nothing"){const p=Br(i)(a.id)(f)(l);return f==="North"||f==="South"?p:0}g()}if(h.tag==="Nothing"){const m=Br(i)(a.id)(f)(l);return f==="North"||f==="South"?m:0}g()}if(_.tag==="Nothing"){const h=Br(i)(a.id)(f)(l);return f==="North"||f==="South"?h:0}g()},s=a=>c=>f=>d=>{let l=a,_=c,h=f,m=d,p=!0,y;for(;p;){const x=l,N=_,v=h,k=Ft(L=>T,L=>E=>w("Just",{head:L,tail:E}),m);if(k.tag==="Nothing"){p=!1,y=x;continue}if(k.tag==="Just"){const L=k._1.head,E=Zt(V=>V.from.node===v&&V.to.node===L||V.from.node===L&&V.to.node===v)(r),B=(()=>{if(E.tag==="Nothing")return N+0;if(E.tag==="Just")return N+(u(E._1,v,E._1.from.node===v?he:le)-u(E._1,L,E._1.from.node===L?he:le));g()})();l=j(C)(L)(B)(x),_=B,h=L,m=k._1.tail;continue}g()}return y};return J(a=>c=>{const f=Ft(_=>T,_=>h=>w("Just",{head:_,tail:h}),Ci(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)(Fs(d));return J(_=>h=>j(C)(h._1)(h._2+l)(_))(a)(Fs(d))})(Q)(Nr(C.compare)((()=>{const a=(c,f)=>{if(c.tag==="Leaf")return f;if(c.tag==="Node")return a(c._5,Ot("Cons",c._4,a(c._6,f)));g()};return kt($t.foldr,a(t.root,qt))})()))},W2=t=>e=>{const n=(i,o,u)=>me(3)(o)==="$d:"&&Ra(Xg,(()=>{const s=ot(o)(t.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;g()})()),r=i=>o=>u=>s=>a=>c=>f=>{let d=i,l=o,_=s,h=c,m=f,p=!0,y;for(;p;){const x=d,N=l,v=_,k=h,L=m,E=N.length;if(L>=E){p=!1,y=x;continue}const B=L>=0&&L<N.length?w("Just",N[L]):T,V=(()=>{if(B.tag==="Nothing")return"";if(B.tag==="Just")return B._1;g()})(),et=n(t,V);if(L===(E-1|0)||et){const D=(()=>{if(et){const S=ot(V)(t.preds),Z=(()=>{if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})();if(0<Z.length){const X=v-1|0,W=ot(Z[0])(t.nodeIndex);if(W.tag==="Nothing")return X;if(W.tag==="Just")return W._1;g()}}return v-1|0})();d=J(S=>Z=>{if(Z>=0&&Z<N.length){const X=N[Z];return n(t,X)?S:J(W=>z=>{const M=ot(z)(t.nodeIndex),G=(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})();return G<k||G>D?j(C)(z+"\u2192"+X)()(W):W})(S)((()=>{const W=ot(X)(t.preds);if(W.tag==="Nothing")return[];if(W.tag==="Just")return W._1;g()})())}return n(t,"")?S:J(X=>W=>{const z=ot(W)(t.nodeIndex),M=(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})();return M<k||M>D?j(C)(W+"\u2192")()(X):X})(S)((()=>{const X=ot("")(t.preds);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()})())})(x)(It(0,L)),l=N,_=v,h=D,m=L+1|0;continue}d=x,l=N,_=v,h=k,m=L+1|0}return y};return e.length<3?Q:J(i=>o=>{if(o>=0&&o<e.length){const u=e[o];return r(i)((()=>{const s=o+1|0;return s>=0&&s<e.length?e[s]:[]})())(u)(u.length)(o)(0)(0)}return r(i)((()=>{const u=o+1|0;return u>=0&&u<e.length?e[u]:[]})())([])(0)(o)(0)(0)})(Q)(It(1,e.length-2|0))},H2=t=>e=>n=>r=>i=>{const o=Ae(e),u=J(s=>a=>{const c=J(f=>d=>{const l=(()=>{if(i==="HRight"){const p=ot(d)(t.preds);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;g()}if(i==="HLeft"){const p=ot(d)(t.succs);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1}g()})(),_=l.length;if(_===0)return f;const h=En(_-1|0,2),m=En(_,2);return J(p=>y=>{if((()=>{const x=ot(d)(p.align);if(x.tag==="Nothing")return d!==d;if(x.tag==="Just")return x._1!==d;g()})())return p;if(y>=0&&y<l.length){const x=ot(l[y])(t.nodeIndex),N=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})();if(!(uf(l[y]+"\u2192"+d)(n)||uf(d+"\u2192"+l[y])(n))&&(()=>{if(r==="VDown")return p.r<N;if(r==="VUp")return p.r>N;g()})()){const v=ot(l[y])(p.root),k=(()=>{if(v.tag==="Nothing")return l[y];if(v.tag==="Just")return v._1;g()})();return{root:j(C)(d)(k)(p.root),align:j(C)(l[y])(d)(j(C)(d)(k)(p.align)),r:N}}}return p})(f)((()=>{if(r==="VDown")return It(h,m);if(r==="VUp")return ke(It(h,m));g()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;g()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return ke(a);g()})());return{root:c.root,align:c.align}})({root:Jn(H(s=>b(s,s))(o)),align:Jn(H(s=>b(s,s))(o))})((()=>{if(i==="HRight")return e;if(i==="HLeft")return ke(e);g()})());return{root:u.root,align:u.align}},Ao=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>{const f=H2(e)(n)(s)(a)(c),d=R2(f)(i)(r)(o)(u)(c);return yd()(l=>_=>w("Just",(()=>{const h=ot(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;g()})()))(z2(t)(e)(n)(r)(i)(o)(u)(d)(f)(a)(c))},af=t=>e=>Qt(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),O2=t=>e=>n=>r=>i=>o=>u=>{const s=P2(0)(e.length-1|0),a=rt(t.layerGap),c=u(ed(s,a)),f=$m($g(i)(c)(r)(o)(Q))(c);return H(d=>{const l=I2(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))},cf=t=>e=>n=>r=>Ra(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),q2=t=>e=>n=>r=>{const i=Lt(o=>u=>st.compare(o.w)(u.w))(H(o=>({l:o,w:sf(o)}))(ct(cf()(e)(n),r)));return 0<i.length?w("Just",i[0].l):T},$2=t=>e=>{const n=Jn(Ae(H(Qt(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)(te)(u.to.node)([u.from.node])(o))(Q)(e))})(),succs:(()=>{const i=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return 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)(te)(u.from.node)([u.to.node])(o))(Q)(e))})(),nodeIndex:n}},Y2=t=>e=>{const n=Lt(d=>l=>st.compare(d.w)(l.w))(Qt(d=>l=>({i:d,l,w:sf(l)}))(e)),r=0<n.length?w("Just",n[0]):T,i=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;g()})(),o=i>=0&&i<e.length?w("Just",e[i]):T,u=(()=>{if(o.tag==="Just")return(d=>l=>{let _=d,h=l,m=!0,p;for(;m;){const y=_,x=h;if(x.tag==="Nil"){m=!1,p=y;continue}if(x.tag==="Cons"){_=en(y)(x._1),h=x._2;continue}g()}return p})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,Ot("Cons",l._4,d(l._6,_)));g()};return d(o._1,qt)})());if(o.tag==="Nothing")return 0;g()})(),s=d=>J(l=>_=>Nn(l)((()=>{const h=ot(_._1)(t);if(h.tag==="Nothing")return _._2+1;if(h.tag==="Just")return _._2+h._1._1;g()})()))(-999999)(Fs(d)),a=i>=0&&i<e.length?w("Just",e[i]):T,c=(()=>{if(a.tag==="Just")return s(a._1);if(a.tag==="Nothing")return 0;g()})(),f=Je(d=>l=>{const _=h=>{if(h.tag==="Leaf")return 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,Qt(d=>l=>Yn(d)(2)===0?u-(_=>h=>{let m=_,p=h,y=!0,x;for(;y;){const N=m,v=p;if(v.tag==="Nil"){y=!1,x=N;continue}if(v.tag==="Cons"){m=en(N)(v._1),p=v._2;continue}g()}return x})(999999)((()=>{const _=(h,m)=>{if(h.tag==="Leaf")return m;if(h.tag==="Node")return _(h._5,Ot("Cons",h._4,_(h._6,m)));g()};return _(l,qt)})()):c-s(l))(e));return M2(J(d=>l=>{const _=Lt(st.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)(Nr(C.compare)(Ae(H(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 kt(Re.foldr,l(d))})(f)))))},V2=t=>e=>n=>r=>i=>o=>{const u=$2(e)(i),s=W2(u)(e),a={nodeGap:t.nodeGap*4|0},c=Ge(C.compare,Le,Jn(H(_=>b(_,b(1,1)))(ct(Xg,Ae(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=[Ao(a)(u)(e)(c)(r)(i)(o)(s)(ef)(rf),Ao(a)(u)(e)(c)(r)(i)(o)(s)(nf)(rf),Ao(a)(u)(e)(c)(r)(i)(o)(s)(ef)(of),Ao(a)(u)(e)(c)(r)(i)(o)(s)(nf)(of)],d=Y2(c)(f);if(cf()(e)(c)(d))return d;const l=q2()(e)(c)(f);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return f[0];g()},X2=t=>e=>n=>r=>{const i=Aa(T,Sa,o=>o.node===e?w("Just",o.position):T,t);if(i.tag==="Nothing")return t;if(i.tag==="Just"){const o=i._1;return H(u=>u.node===n?{...u,position:b(o._1+r._1,o._2+r._2)}:u)(t)}g()},U2=t=>e=>n=>r=>{const i=ct(u=>Be(gn)(u.node)(e),t),o=(()=>{if(n==="Vertical"){if(r==="Start")return J(u=>s=>en(u)(s.position._1))(99999)(i);if(r==="End")return J(u=>s=>Nn(u)(s.position._1))(0)(i);if(r==="Center"){const u=J(s=>a=>s+a.position._1)(0)(i);return i.length===0?0:u/rt(i.length)}g()}if(n==="Horizontal"){if(r==="Start")return J(u=>s=>en(u)(s.position._2))(99999)(i);if(r==="End")return J(u=>s=>Nn(u)(s.position._2))(0)(i);if(r==="Center"){const u=J(s=>a=>s+a.position._2)(0)(i);return i.length===0?0:u/rt(i.length)}}g()})();return H(u=>{if(Be(gn)(u.node)(e)){if(n==="Vertical")return{...u,position:b(o,u.position._2)};if(n==="Horizontal")return{...u,position:b(u.position._1,o)};g()}return u})(t)},j2=t=>e=>J(n=>r=>r.tag==="AlignGroup"?U2(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?X2(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),Z2=t=>e=>n=>r=>i=>o=>u=>s=>{const a=H(d=>J(l=>_=>Nn(l)((()=>{const h=ot(_)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;g()})()))(1)(d))(n),c=V2(t)(n)(r)(i)(o)(s),f=af(O2(t)(n)(r)(i)(o)(u)(d=>{const l=af(d)(a);return Ae(Qt(_=>h=>Qt(m=>p=>({node:p,position:b((()=>{const y=ot(p)(c);return(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;g()})()/rt(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const y=me(3)(p)==="$d:"?b(0,1):b(1,1),x=ot(p)(r);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;g()})(),layer:_,order:m}))(h))(n))}))(a);return j2(e)(Ae(Qt(d=>l=>Qt(_=>h=>({node:h,position:b((()=>{const m=ot(h)(c);return(()=>{if(m.tag==="Nothing")return 0;if(m.tag==="Just")return m._1;g()})()/rt(4)})(),d>=0&&d<f.length?f[d]:0),size:(()=>{const m=me(3)(h)==="$d:"?b(0,1):b(1,1),p=ot(h)(r);if(p.tag==="Nothing")return m;if(p.tag==="Just")return p._1;g()})(),layer:d,order:_}))(l))(n)))},As=Wu(uo)(gr(32)),gf=Wu(uo)(gr(31)),Si=(()=>{const t=hl("25214903917");if(t.tag==="Nothing")return ic;if(t.tag==="Just")return t._1;g()})(),Di=Ru(Wu(uo)(gr(48)))(uo),K2=t=>{const e=pl(t);return gi(oc((()=>{if(e.tag==="Nothing")return ic;if(e.tag==="Just")return e._1;g()})())(Si))(Di)},Ms=gr(11),Mo=t=>e=>{const n=gi(io(oo(e)(Si))(Ms))(Di);return b((()=>{const r=$a(fl(Hu(n)(gr(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},ty=t=>{const e=Mo(26)(t),n=Mo(27)(e._2);return b((rt(e._1)*wu(2)(27)+rt(n._1))/wu(2)(53),n._2)},ey=t=>e=>{const n=J(r=>i=>{const o=ty(r.finalR);return{rs:[...r.rs,o._1],finalR:o._2}})({rs:[],finalR:t})(e);return b(H(r=>r.x)(Lt(r=>i=>st.compare(r.k)(i.k))(Je(r=>i=>({x:r,k:i}),e,n.rs))),n.finalR)},ny=t=>{const e=gi(io(oo(t)(Si))(Ms))(Di),n=gi(io(oo(e)(Si))(Ms))(Di);return b(io(oo((()=>{const r=Hu(e)(gr(16));return uc.compare(r)(gf)!=="LT"?Ru(r)(As):r})())(As))((()=>{const r=Hu(n)(gr(16));return uc.compare(r)(gf)!=="LT"?Ru(r)(As):r})()),n)},Pi=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Bo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Bs=Kt(C)(Bt),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=w("Just",o._4);continue}}g()}return i},zo=Kt(C)(Bt),ry=Tu(ti),iy=J(Tr)(0),oy=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ff=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},uy=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const i=On(Yt,T,t,n[e],n);if(i.tag==="Just")return On(Yt,T,e,r,i._1);if(i.tag==="Nothing")return T;g()}}return T},sy=t=>e=>n=>r=>i=>Bs(J(o=>u=>{const s=Lt(a=>c=>it.compare((()=>{const f=Pi(a.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})())((()=>{const f=Pi(c.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})()))(ct(a=>Bo(a.to.node)(n),ct(a=>a.from.node===u,r)));return{ranks:[...o.ranks,...Qt(a=>c=>b(c.id,rt((o.rankSum+a|0)+1|0)))(s)],rankSum:o.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),ay=t=>e=>n=>r=>i=>Bs(J(o=>u=>{const s=Lt(c=>f=>{const d=it.compare((()=>{const l=zr(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=zr(c.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})());return d==="EQ"?it.compare((()=>{const l=Pi(c.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})())((()=>{const l=Pi(f.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})()):d})(ct(c=>Bo(c.from.node)(n),ct(c=>c.to.node===u,r))),a=s.length;return{ranks:[...o.ranks,...Qt(c=>f=>b(f.id,rt((o.rankSum+a|0)-c|0)))(s)],rankSum:o.rankSum+a|0}})({ranks:[],rankSum:0})(t).ranks),zs=t=>e=>n=>{const r=zo(Qt(s=>a=>b(a,s))(t)),i=zo(Qt(s=>a=>b(a,s))(e)),o=xt(s=>{const a=zr(s.from.node)(r),c=zr(s.to.node)(i);if(a.tag==="Just"&&c.tag==="Just")return w("Just",b(a._1,c._1));const f=zr(s.from.node)(i),d=zr(s.to.node)(r);return f.tag==="Just"&&d.tag==="Just"?w("Just",b(d._1,f._1)):T})(n),u=o.length;return J(s=>a=>J(c=>f=>a>=0&&a<o.length&&f>=0&&f<o.length&&((o[a]._1-o[f]._1|0)*(o[a]._2-o[f]._2|0)|0)<0?c+1|0:c)(s)(It(a+1|0,u-1|0)))(0)(It(0,u-2|0))},cy=t=>e=>n=>r=>{const i=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l>=(d.length-1|0)){c=!1,f=d;continue}if(l>=0&&l<d.length){const _=l+1|0;if(_>=0&&_<d.length){const h=d[l],m=d[_];if(Me(N=>N.before===h&&N.after===m,r)){s=d,a=l+1|0;continue}const p=On(Yt,T,l,m,d),y=(()=>{if(p.tag==="Just")return On(Yt,T,l+1|0,h,p._1);if(p.tag==="Nothing")return T;g()})(),x=(()=>{if(y.tag==="Nothing")return d;if(y.tag==="Just")return y._1;g()})();if(zs(e)(x)(n)<zs(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(ry(f)(c)){s=!1,a=c;continue}u=f}return a})(t)},Ro=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+zs(i)(t[o])(e)|0}return n})(0)(It(0,t.length-2|0)),gy=(()=>{const t=e=>{if(e.length<7){const o=u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=_-1|0;if(h>=0&&h<l.length){if(_>=0&&_<l.length&&_>0&&l[h].key>l[_].key){const m=uy(_-1|0)(_)(l);if(m.tag==="Just"){a=m._1,c=_-1|0;continue}if(m.tag==="Nothing"){f=!1,d=l;continue}g()}f=!1,d=l;continue}f=!1,d=l}return d};return J(u=>s=>o(u)(s))(e)(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,m=f;if(h>=0&&h<r.length){if(m>=0&&m<i.length){if(r[h].key>i[m].key){a=zt(_)(i[m]),c=h,f=m+1|0;continue}a=zt(_)(r[h]),c=h+1|0,f=m;continue}d=!1,l=[..._,...h<1?r:bt(h,r.length,r)];continue}d=!1,l=[..._,...m<1?i:bt(m,i.length,i)]}return l})([])(0)(0)};return t})(),fy=t=>e=>n=>{const r=xt(c=>c.tag==="OrderConstraint"?w("Just",{before:c._1.before,after:c._1.after}):T)(t.constraints),i=c=>J(f=>d=>{const l=d.after,_=d.before,h=ir(Yt,T,p=>p===_,f),m=ir(Yt,T,p=>p===l,f);if(h.tag==="Just"&&m.tag==="Just"&&h._1>m._1){const p=za(Yt,T,h._1,f),y=(()=>{if(p.tag==="Nothing")return f;if(p.tag==="Just")return p._1;g()})(),x=Ba(Yt,T,m._1,_,y);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;g()}return f})(c)(r),o=Bs(Qt(c=>f=>b(f.id,c))(n)),u=(c,f,d)=>{const l=c.length;return J(_=>h=>{const m=f?h-1|0:h+1|0,p=m>=0&&m<_._1.length?w("Just",_._1[m]):T;if(p.tag==="Just"){const y=h>=0&&h<_._1.length?w("Just",_._1[h]):T;if(y.tag==="Just"){const x=zo(Qt(E=>B=>b(B,E))(p._1)),N=zo(Qt(E=>B=>b(B,E))(y._1)),v=f?sy(p._1)(x)(N)(n)(o):ay(p._1)(x)(N)(n)(o),k=J(E=>B=>{const V=xt(D=>Pi(D.id)(v))(ct(f?D=>D.to.node===B._2&&Bo(D.from.node)(x):D=>D.from.node===B._2&&Bo(D.to.node)(x),n));if(V.length===0)return{...E,items:[...E.items,{n:B._2,key:T,origIdx:B._1}]};const et=Mo(24)(E.r);return{items:[...E.items,{n:B._2,key:w("Just",(iy(V)+(rt(et._1)*4172325152040912e-24-.03500000014901161))/rt(V.length)),origIdx:B._1}],r:et._2}})({items:[],r:_._2})(Qt(Hn)(y._1)),L=On(Yt,T,h,cy(i(H(E=>E.n)(gy((()=>{const E=k.items,B=V=>et=>{let D=V,S=et,Z=!0,X;for(;Z;){const W=D,z=S;if(W>=0&&W<E.length){if(E[W].key.tag==="Just"){Z=!1,X=E[W].key._1;continue}if(E[W].key.tag==="Nothing"){D=W+1|0,S=z;continue}g()}Z=!1,X=z}return X};return(V=>et=>D=>{let S=V,Z=et,X=D,W=!0,z;for(;W;){const M=S,G=Z,P=X;if(M>=0&&M<E.length){if(E[M].key.tag==="Just"){S=M+1|0,Z=E[M].key._1,X=[...P,{n:E[M].n,key:E[M].key._1,origIdx:E[M].origIdx}];continue}if(E[M].key.tag==="Nothing"){const I=(G+B(M+1|0)(G+1))/2;S=M+1|0,Z=I,X=[...P,{n:E[M].n,key:I,origIdx:E[M].origIdx}];continue}g()}W=!1,z=P}return z})(0)(-1)([])})()))))(p._1)(n)(r),_._1);if(L.tag==="Just")return b(L._1,k.r);if(L.tag==="Nothing")return b(_._1,_._2);g()}if(y.tag==="Nothing")return b(_._1,_._2);g()}if(p.tag==="Nothing")return b(_._1,_._2);g()})(b(c,d))(f?It(1,l-1|0):ke(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=>v=>k=>{let L=x,E=N,B=v,V=k,et=!0,D;for(;et;){const S=L,Z=E,X=B,W=V;if(X===0){et=!1,D={layout:S,crossings:0,random:W};continue}const z=u(S,Z,W),M=Ro(z._1)(n);if(M<X){L=z._1,E=!Z,B=M,V=z._2;continue}et=!1,D={layout:S,crossings:X,random:z._2}}return D},l=Mo(1)(c.result.random),_=l._1!==0,h=t.modelOrder.tag==="Leaf",m=(c.firstTry||c.secondTry)&&!h?c.firstTry:_,p=(()=>{if(!h){const k=u(e,m,l._2);return d(k._1)(!m)(Ro(k._1)(n))(k._2)}const x=m?0:oy(0)(e.length-1|0),N=x>=0&&x<e.length?w("Just",e[x]):T;if(N.tag==="Just"&&N._1.length>1){const k=ct(L=>ff(L)(s),N._1);if(k.length>1){const L=ey(l._2)(k),E=L._1,B=On(Yt,T,x,i(J(V=>et=>ff(et)(s)?V.idx>=0&&V.idx<E.length?{idx:V.idx+1|0,result:[...V.result,E[V.idx]]}:{idx:V.idx,result:[...V.result,et]}:{idx:V.idx,result:[...V.result,et]})({idx:0,result:[]})(N._1).result),e);if(B.tag==="Just"){const V=u(B._1,m,L._2);return d(V._1)(!m)(Ro(V._1)(n))(V._2)}}}const v=u(e,m,l._2);return d(v._1)(!m)(Ro(v._1)(n))(v._2)})(),y=c.secondTry?!1:c.secondTry;return c.firstTry?{result:p.crossings<c.result.crossings?{layout:p.layout,crossings:p.crossings,random:p.random}:{...c.result,random:p.random},firstTry:!1,secondTry:!0}:{result:p.crossings<c.result.crossings?{layout:p.layout,crossings:p.crossings,random:p.random}:{...c.result,random:p.random},firstTry:c.firstTry,secondTry:y}})({result:{layout:e,crossings:1e9,random:gi(oc(ny(K2(1))._1)(Si))(Di)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(It(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:a.layout},_y=t=>t,_f=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.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},Ie=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},Rr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!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},Ii=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=C.compare(e._1)(n._1);return r==="LT"?ye:r==="GT"?xe:C.compare(e._2)(n._2)},Eq0:()=>t}})(),dy=Kt(C)(Bt),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=Ii.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},hy=_y("Greedy"),Rs=t=>e=>n=>J(r=>i=>{if(i.from.node===i.to.node)return r;if(i.from.node===e&&!_f(i.to.node)(r.marks)){const o=Ie(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=Ie(i.to.node)(r.outDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!Be(gn)(i.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,i.to.node]}:{...r,inDeg:s}}if(i.to.node===e&&!_f(i.from.node)(r.marks)){const o=Ie(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=Ie(i.from.node)(r.inDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!Be(gn)(i.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,i.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:ct(r=>r!==e,n.remaining)})(t),py=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),df=t=>e=>n=>{const r=Ie(e)(t),i=Ie(n)(t);return r.tag==="Just"&&i.tag==="Just"&&r._1>i._1},lf=t=>e=>n=>r=>{if(Rr(n)(r.visited)||Rr(n)(r.visiting))return r;const i=J(my(t)(e)(n))({...r,visiting:j(C)(n)()(r.visiting)})((()=>{const o=Ie(n)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})());return{...i,visiting:ni(C)(n)(i.visiting),visited:j(C)(n)()(i.visited)}},my=t=>e=>n=>r=>i=>df(t)(n)(i)?{...r,backEdges:j(Ii)(b(n,i))()(r.backEdges)}:Rr(i)(r.visiting)?{...r,backEdges:j(Ii)(b(n,i))()(r.backEdges)}:Rr(i)(r.visited)?r:lf(t)(e)(i)(r),yy=t=>e=>n=>{const r=l=>{let _=l,h=!0,m;for(;h;){const p=_,y=Ft(x=>T,x=>N=>w("Just",{head:x,tail:N}),p.sinks);if(y.tag==="Just"){_=Rs(n)(y._1.head)({...p,sinks:y._1.tail,marks:j(C)(y._1.head)(p.nextRight)(p.marks),nextRight:p.nextRight-1|0});continue}if(y.tag==="Nothing"){const x=Ft(N=>T,N=>v=>w("Just",{head:N,tail:v}),p.sources);if(x.tag==="Just"){_=Rs(n)(x._1.head)({...p,sources:x._1.tail,marks:j(C)(x._1.head)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}if(x.tag==="Nothing"){const N=k=>{const L=Ie(k)(p.outDeg),E=Ie(k)(p.inDeg);return(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;g()})()-(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;g()})()|0},v=Lt(k=>L=>{const E=it.compare(N(L))(N(k));return E==="EQ"?it.compare((()=>{const B=Ie(k)(e);if(B.tag==="Nothing")return 1e6;if(B.tag==="Just")return B._1;g()})())((()=>{const B=Ie(L)(e);if(B.tag==="Nothing")return 1e6;if(B.tag==="Just")return B._1;g()})()):E})(p.remaining);if(0<v.length){const k=v[0];_=Rs(n)(k)({...p,remaining:ct(L=>L!==k,p.remaining),marks:j(C)(k)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}h=!1,m=p;continue}}g()}return m},i=Nr(C.compare)([...H(l=>l.from.node)(n),...H(l=>l.to.node)(n)]),o=ct(l=>l.from.node!==l.to.node,n),u=J(l=>_=>vt(C)(oe)(_.to.node)(1)(l))(Q)(o),s=J(l=>_=>vt(C)(oe)(_.from.node)(1)(l))(Q)(o),a=ct(l=>{const _=Ie(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),c=ct(l=>{const _=Ie(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=Ie(_)(l);return h.tag==="Just"&&h._1<0?j(C)(_)(h._1+f|0)(l):l})(r({remaining:ct(l=>!Be(gn)(l)(a)&&!Be(gn)(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(df(t)(_.from.node)(_.to.node))return j(Ii)(b(_.from.node,_.to.node))()(l);const h=Ie(_.from.node)(d),m=Ie(_.to.node)(d);return h.tag==="Just"&&m.tag==="Just"&&h._1>m._1?j(Ii)(b(_.from.node,_.to.node))()(l):l})(Q)(n)},xy=J(t=>e=>vt(C)(te)(e.from.node)([e.to.node])(t))(Q),Ny=t=>e=>{const n=xy(e),r=Nr(C.compare)([...H(o=>o.from.node)(e),...H(o=>o.to.node)(e)]),i=J(o=>u=>j(C)(u.to.node)()(o))(Q)(e);return J(o=>u=>lf(t)(n)(u)(o))({visiting:Q,visited:Q,backEdges:Q})([...ct(o=>!Rr(o)(i),r),...ct(o=>Rr(o)(i),r)]).backEdges},Jy=t=>e=>n=>r=>{const i=dy(Qt(s=>a=>b(a,s))(e)),o=py(n),u=(()=>{if(t==="DepthFirst")return Ny(o)(r);if(t==="Greedy")return yy(o)(i)(r);g()})();return{edges:H(s=>ly(b(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},hf=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ty=J(t=>e=>j(C)(e)()(t))(Q),Wo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},vy=Cg(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=w("Just",o._4);continue}}g()}return i},pf=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ws=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=it.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},wy=Kt(it)(Bt),by=t=>e=>Ge(C.compare,Le,t,e),mf=Qt(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),Ly=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=hf(f)(d._1),s=d._2;continue}g()}return c};return(e.base+r(0)((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,Ot("Cons",o._4,i(o._6,u)));g()};return i(n,qt)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=i=>{if(i.tag==="Leaf")return 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,ky=t=>e=>{const n=Ty(t);return vy(t)(mf(ct(r=>Wo(r.src)(n)&&Wo(r.tgt)(n),e)))},Ey=t=>e=>{const n=J(i=>o=>vt(C)(te)(o.tgt)([o.src])(vt(C)(te)(o.src)([o.tgt])(i)))(Q)(e),r=i=>o=>u=>{let s=i,a=o,c=u,f=!0,d;for(;f;){const l=s,_=a,h=c,m=Ft(p=>T,p=>y=>w("Just",{head:p,tail:y}),l);if(m.tag==="Nothing"){f=!1,d={nodes:h};continue}if(m.tag==="Just"){if(Wo(m._1.head)(_)){s=m._1.tail,a=_,c=h;continue}s=[...m._1.tail,...(()=>{const p=Tn(m._1.head)(n);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;g()})()],a=j(C)(m._1.head)()(_),c=[...h,m._1.head];continue}g()}return d};return J(i=>o=>{if(Wo(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},Gy=t=>e=>n=>{const r=J(o=>u=>vt(C)(oe)(u.tgt)(1)(o))(Q)(e),i=J(o=>u=>vt(C)(oe)(u.src)(1)(o))(Q)(e);return J(o=>u=>{const s=Tn(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})();if((()=>{const x=Tn(u)(i);return(()=>{if(x.tag==="Nothing")return a!==0;if(x.tag==="Just")return a!==x._1;g()})()||a===0})())return o;const c=Tn(u)(o.layers),f=(()=>{if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1;g()})(),d=o.layers,l=J(x=>N=>N.tgt===u?{...x,mIn:pf(x.mIn)((()=>{const v=Tn(u)(d),k=Tn(N.src)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})()-(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;g()})()|0})())}:N.src===u?{...x,mOut:pf(x.mOut)((()=>{const v=Tn(N.tgt)(d),k=Tn(u)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})()-(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;g()})()|0})())}:x)({mIn:1e9,mOut:1e9})(e),_=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(_<0||h<0)return o;const m=(f-_|0)+1|0,p=(f+h|0)-1|0;if(p<m)return o;const y=J(x=>N=>{const v=Ws(N)(o.filling),k=(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})();return k<x.bestFill?{best:N,bestFill:k}:x})({best:f,bestFill:(()=>{const x=Ws(f)(o.filling);if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})()})(It(m,p));return y.best===f?o:{layers:j(C)(u)(y.best)(o.layers),filling:j(it)(f)((()=>{const x=Ws(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:wy(H(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=>hf(o)((()=>{const s=Tn(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(0)(t))))})(t).layers},Cy=t=>e=>Gy(t)(mf(e))(J(by)(Q)(Ly(H(n=>ky(n)(e))(Ey(t)(e))))),Sy=t=>t,hr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Ho=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},yf=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),Dy=Sy("NetworkSimplex"),Py=t=>e=>J(n=>r=>{const i=J(Ho)(0)(xt(o=>hr(o)(n))(r));return J(o=>u=>j(C)(u)(i)(o))(n)(r)})(e)(t),Iy=t=>e=>({layers:H(n=>ct(r=>{const i=hr(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=Ho(a)(c._1),o=c._2;continue}g()}return s})(0)((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._4,n(r._6,i)));g()};return n(e,qt)})()))),nodeLayer:e}),Qy=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))(Cy(e)(xt(i=>i.from.node===i.to.node||(()=>{const o=hr(i.from.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()||(()=>{const o=hr(i.to.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()?T:w("Just",{src:i.from.node,tgt:i.to.node}))(t)))(yf(n))},Fy=t=>e=>n=>r=>{const i=s=>a=>{const c=hr(a)(s);if(c.tag==="Just")return s;if(c.tag==="Nothing"){const f=ct(l=>l!==a,(()=>{const l=hr(a)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;g()})()),d=J(i)(s)(f);return j(C)(a)(1+J(Ho)(0)(xt(l=>hr(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=Ho(_)(h._1),f=h._2;continue}g()}return l})(1)((()=>{const s=(a,c)=>{if(a.tag==="Leaf")return c;if(a.tag==="Node")return s(a._5,Ot("Cons",a._4,s(a._6,c)));g()};return s(o,qt)})());return J(s=>a=>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)})())(yf(r))},Ay=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),My=J(t=>e=>vt(C)(te)(e.to.node)([e.from.node])(t))(Q),By=J(t=>e=>vt(C)(te)(e.from.node)([e.to.node])(t))(Q),zy=t=>e=>n=>r=>{const i=By(n),o=My(n),u=Ay(e);return Iy(r)(Py(xt(s=>s.tag==="SameLayer"?w("Just",s._1.nodes):T)(e))((()=>{if(t==="LongestPath")return Fy(i)(o)(r)(u);if(t==="NetworkSimplex")return Qy(n)(r)(u);g()})()))},Ry=Kt(C)(Bt),Wy=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},xf=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},Nf=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Qi=Kt(C)(Bt),Hy=Kt(C)(Bt),Jf=(()=>{const t=H(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>ke(t(e))})(),Oy=t=>e=>n=>r=>{const i=Ry(H(u=>b(u.edge,u))(r)),o=u=>0<u.nodes.length&&(()=>{const s=Wy(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return H(u=>{if(u.nodes.length<=2){const f=xf(u.edgeId)(i);if(f.tag==="Just"){const d=o(u),l=ki(Li(d?Jf(f._1.segments):f._1.segments));return{...f._1,edge:u.edgeId,segments:l,bends:Je(_=>h=>_.end,l,bt(1,l.length,l)),reversed:d}}if(f.tag==="Nothing")return{edge:u.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};g()}const s=Tt(xt(f=>xf(f)(i))(Je(f=>d=>u.edgeId+":"+f+"->"+d,u.nodes,bt(1,u.nodes.length,u.nodes))))(f=>f.segments),a=o(u),c=ki(Li(a?Jf(s):s));return{edge:u.edgeId,segments:c,bends:Je(f=>d=>f.end,c,bt(1,c.length,c)),bendType:[],jumps:[],reversed:a}})(t)},qy={layers:[],edges:[],chains:[]},$y={nodeGap:3,layerGap:2,iterations:8,layerer:Dy,cycleBreaker:hy,compactPostRouting:!1},Yy=t=>({pos:b(0,0),size:b(J(e=>n=>Nf(e)(n.position._1+n.size._1))(0)(t),J(e=>n=>Nf(e)(n.position._2+n.size._2))(0)(t))}),Vy=t=>e=>n=>{const r=Qi(H(c=>b(c.id,c.ports))(e.nodes)),i=ct(c=>me(3)(c.node)!=="$d:",n.placements),o=Oy(n.withDummies.chains)(n.acyclic.reversedEdges)(Hy(H(c=>b(c.id,b(c.from.node,c.to.node)))(e.edges)))(x2(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(jg(n.ordered)(ct(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(Qi(H(f=>b(f.id,f.size))(e.nodes)))})()))),u=t.compactPostRouting?Rm()({nodes:i,edges:e.edges,paths:o,ports:r}):{nodes:i,edges:o},s=H(c=>{const f=ki(Li(c.segments));return{...c,segments:f,bends:Je(d=>l=>d.end,f,bt(1,f.length,f))}})(u.edges),a=Qt(c=>f=>({...f,jumps:L2(c)(f)(s)}))(s);return{nodes:u.nodes,edges:a,boundingBox:Yy(u.nodes),metrics:dp(u.nodes)(a)(0)}},Xy=t=>e=>n=>{const r=Qi(H(o=>b(o.id,o.size))(e.nodes)),i={...n,placements:Z2({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(Qi(H(o=>b(o.id,o.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(jg(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:Vy(t)(e)(i)}},Uy=t=>e=>n=>Xy(t)(e)({...n,ordered:fy({iterations:t.iterations,constraints:e.constraints,modelOrder:Qi(Qt(r=>i=>b(i.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),jy=t=>e=>n=>Uy(t)(e)({...n,withDummies:k2(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),Zy=t=>e=>{const n=H(i=>i.id)(e.nodes),r=Jy(t.cycleBreaker)(n)(e.constraints)(e.edges);return jy(t)(e)({acyclic:r,layered:zy(t.layerer)(e.constraints)(r.edges)(n),withDummies:qy,ordered:[],placements:[]})},Oo=t=>t,Ky=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Hs=Oo("TopSide"),Os=Oo("BottomSide"),qs=Oo("LeftSide"),$s=Oo("RightSide"),tx=t=>{const e=st.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=st.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Tf=t=>e=>n=>{const r=Ky(t.h*.12)(t.w*.2),i=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*Ee(tx((()=>{const o=(n-(t.x+i))/i;return 1-o*o})()))},tr=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=Un,o=d,u=l,s=_;continue}if(f==="Cylinder"){if(l==="TopSide"){a=!1,c=Tf(d)(-1)(_);continue}if(l==="BottomSide"){a=!1,c=Tf(d)(1)(_);continue}if(l==="LeftSide"){a=!1,c=d.x;continue}if(l==="RightSide"){a=!1,c=d.x+d.w;continue}}i=Un,o=d,u=l,s=_}return c},vf=t=>e=>{const n=e.y-t.y,r=n<0?-n:n,i=e.x-(t.x+t.w),o=i<0?-i:i,u=e.x-t.x,s=u<0?-u:u,a=e.y-(t.y+t.h),c=a<0?-a:a;return r<=c&&r<=s&&r<=o?Hs:c<=s&&c<=o?Os:s<=o?qs:$s},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=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},Fi=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},ex=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),qo=Kt(C)(Bt),nx=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},rx=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},ix=J(t=>e=>j(C)(e)()(t))(Q),ox=J(t=>e=>j(C)(e)()(t))(Q),$o=rr.traverse(xu),Yo=Kt(C)(Bt),ux=t=>e=>Ge(C.compare,Le,t,e),sx=J(t=>e=>j(C)(e)()(t))(Q),ax=Kt(C)(Bt),cx=t=>e=>Ge(C.compare,Le,t,e),gx=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},wf=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fx=t=>e=>({...e,edges:qo(H(n=>b(n._1,(()=>{const r=Ys(n._1)(t);if(r.tag==="Nothing")return n._2;if(r.tag==="Just"){const i=Fi(r._1._2)(e.nodes),o=Fi(r._1._1)(e.nodes),u=(()=>{if(o.tag==="Nothing")return n._2;if(o.tag==="Just"){const s=Ft(a=>T,a=>c=>w("Just",{head:a,tail:c}),n._2);if(s.tag==="Nothing")return n._2;if(s.tag==="Just"){const a={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},c=vf(a)(s._1.head);return[(()=>{if(c==="TopSide")return{...s._1.head,y:tr(o._1.shape)(a)(Hs)(s._1.head.x)};if(c==="BottomSide")return{...s._1.head,y:tr(o._1.shape)(a)(Os)(s._1.head.x)};if(c==="LeftSide")return{...s._1.head,x:tr(o._1.shape)(a)(qs)(s._1.head.y)};if(c==="RightSide")return{...s._1.head,x:tr(o._1.shape)(a)($s)(s._1.head.y)};g()})(),...s._1.tail]}}g()})();if(i.tag==="Nothing")return u;if(i.tag==="Just"){const s=Vi(u);if(s.tag==="Nothing")return u;if(s.tag==="Just")return zt(s._1.init)((()=>{const a={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},c=vf(a)(s._1.last);if(c==="TopSide")return{...s._1.last,y:tr(i._1.shape)(a)(Hs)(s._1.last.x)};if(c==="BottomSide")return{...s._1.last,y:tr(i._1.shape)(a)(Os)(s._1.last.x)};if(c==="LeftSide")return{...s._1.last,x:tr(i._1.shape)(a)(qs)(s._1.last.y)};if(c==="RightSide")return{...s._1.last,x:tr(i._1.shape)(a)($s)(s._1.last.y)};g()})())}}g()})()))(ex(e.edges)))}),_x=t=>e=>n=>{const r=Zt(i=>i.id===n)(t.graph.edges);if(r.tag==="Just")return w("Just",r._1);if(r.tag==="Nothing")return Ys(n)(e);g()},dx=t=>e=>n=>r=>({x:r.position._1*t,y:r.position._2*t,w:r.size._1*t,h:r.size._2*t,label:(()=>{const i=Fi(r.node)(e);if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return r.node;g()})(),shape:(()=>{const i=Fi(r.node)(n);if(i.tag==="Nothing")return Un;if(i.tag==="Just")return i._1;g()})()}),lx=t=>({id:t,size:b(1,1),ports:[],label:w("Just",t),shape:Un}),hx=t=>e=>n=>r=>b(r.node,dx(t)(e)(n)(r)),bf=t=>{const e=_o(`
6
+ `)(t);return e.length===0?[""]:e},Lf=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Ot("Cons",n._4,e(n._6,r)));g()};return kt($t.foldr,e(t.interiors,qt))},px=t=>qo(xt(e=>w("Just",b(e.edge,{id:e.edge,from:{node:e.from,port:T},to:{node:e.to,port:T}})))(Tt(t.scenes)(e=>e.tag==="DataFlow"?xt(n=>n.kind.tag==="SendToken"?w("Just",n.kind._1):T)(e._1.events):[]))),kf=t=>{const e=Pl(t),n=ct(i=>nx(i.id)(e.nodes),t.graph.nodes),r=ct(i=>rx(i.id)(e.edges),t.graph.edges);return{nodes:[...n,...H(lx)(kt(Re.foldr,Gn(C.compare,e.nodes,ix(H(i=>i.id)(n)))))],edges:[...r,...xt(_x(t)(px(t)))(kt(Re.foldr,Gn(C.compare,e.edges,ox(H(i=>i.id)(r)))))],constraints:t.graph.constraints}},mx=t=>{const e=$o(n=>{const r=ng(rg)((()=>{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)}})(kf(t).nodes);return()=>{const n=e();return Yo(n)}},Ef=t=>{const e=mx(t);return()=>{const n=e(),r=$o(Ef)(Lf(t))();return J(ux)(n)(r)}},yx=t=>e=>{const n=Ft(r=>T,r=>i=>w("Just",{head:r,tail:i}),e.segments);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{x:n._1.head.start._1*t,y:n._1.head.start._2*t},...H(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];g()},xx=t=>e=>b(e.edge,yx(t)(e)),Nx=t=>e=>n=>r=>({nodes:Yo(H(hx(rt(4)*t)(e)(n))(r.nodes)),edges:qo(H(xx(t))(r.edges)),chipExtras:Q}),Jx=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==="EnterNode"||n.tag==="ExitNode")return e;g()})(Q)(t.scenes),Tx=t=>{const e=$o(n=>{const r=ng(rg)(n);return()=>{const i=r();return b(n,{labelW:i,charCount:Xn(Pr(n)),lineCount:1})}})(kt(Re.foldr,sx(Tt(kt(Re.foldr,Jx(t)))(bf))));return()=>{const n=e();return ax(n)}},Gf=t=>{const e=Tx(t);return()=>{const n=e(),r=$o(Gf)(Lf(t))();return J(cx)(n)(r)}},vx=rt(4)*8,wx=t=>e=>{const n=gp(vx)(t)(cp(ap)(kf(e)));return fx(qo(H(r=>b(r.id,b(r.from.node,r.to.node)))(n.edges)))(Nx(8)(Yo(H(r=>b(r.id,(()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;g()})()))(n.nodes)))(Yo(H(r=>b(r.id,r.shape))(n.nodes)))(Zy($y)(n).result))},bx=t=>Tt(t.scenes)(e=>{if(e.tag==="Structural")return[];if(e.tag==="DataFlow")return e._1.events;if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()}),Lx=t=>e=>n=>{const r=i=>{const o=xt(u=>{const s=gx(u)(t);return s.tag==="Just"?w("Just",{w:s._1.labelW+28,h:rt(rp(1)(s._1.lineCount))*13.2+12}):T})(Tt(i)(bf));return o.length===0?T:w("Just",{w:J(wf)(0)(H(u=>u.w)(o)),h:J(wf)(0)(H(u=>u.h)(o))})};return J(i=>o=>{if(o.kind.tag==="SendToken"){const u=Ys(o.kind._1.edge)(n.edges),s=r(o.kind._1.labels);if(s.tag==="Just"&&u.tag==="Just"){const a=s._1;return vt(C)(te)(o.kind._1.edge)(H(c=>({x:c.x+14+a.w,y:c.y-6-8-a.h}))(u._1))(i)}return i}if(o.kind.tag==="FillNodeWithoutTransition"){const u=Fi(o.kind._1.node)(n.nodes),s=r(o.kind._1.labels);return s.tag==="Just"&&u.tag==="Just"?vt(C)(te)("__fill__:"+o.kind._1.node)((()=>{const a=u._1.y-s._1.h-14,c=u._1.x+u._1.w/2,f=c-s._1.w/2,d=c+s._1.w/2,l=u._1.y-14;return[{x:f,y:a},{x:d,y:a},{x:f,y:l},{x:d,y:l}]})())(i):i}g()})(Q)(bx(e))},Cf=t=>e=>n=>({layout:(()=>{const r=wx(t)(n);return{...r,chipExtras:Lx(e)(n)(r)}})(),interiors:(()=>{const r=Cf(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)})()}),Sf=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},Vs=t=>e=>n=>{const r=t<.05?t:.05,i=(u,s)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return i((()=>{const a=Sf(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=Sf(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",m="Release",p="Finalizer",y="Finalized",x="Forked";function N(F,O,Y,q){this.tag=F,this._1=O,this._2=Y,this._3=q}function v(F){var O=function(Y,q,$){return new N(F,Y,q,$)};return O.tag=F,O}function k(F){return new N(e,void 0)}function L(F){try{F()}catch(O){setTimeout(function(){throw O},0)}}function E(F,O,Y){try{return O(Y())}catch(q){return F(q)}}function B(F,O,Y){try{return O(Y)()}catch(q){return Y(F(q))(),k}}var V=(function(){var F=1024,O=0,Y=0,q=new Array(F),$=!1;function R(){var tt;for($=!0;O!==0;)O--,tt=q[Y],q[Y]=void 0,Y=(Y+1)%F,tt();$=!1}return{isDraining:function(){return $},enqueue:function(tt){var K;O===F&&(K=$,R(),$=K),q[(Y+O)%F]=tt,O++,$||R()}}})();function et(F){var O={},Y=0,q=0;return{register:function($){var R=Y++;$.onComplete({rethrow:!0,handler:function(tt){return function(){q--,delete O[R]}}})(),O[R]=$,q++},isEmpty:function(){return q===0},killAll:function($,R){return function(){if(q===0)return R();var tt=0,K={};function gt(at){K[at]=O[at].kill($,function(yt){return function(){delete K[at],tt--,F.isLeft(yt)&&F.fromLeft(yt)&&setTimeout(function(){throw F.fromLeft(yt)},0),tt===0&&R()}})()}for(var _t in O)O.hasOwnProperty(_t)&&(tt++,gt(_t));return O={},Y=0,q=0,function(at){return new N(i,function(){for(var yt in K)K.hasOwnProperty(yt)&&K[yt]()})}}}}}var D=0,S=1,Z=2,X=3,W=4,z=5,M=6;function G(F,O,Y){var q=0,$=D,R=Y,tt=null,K=null,gt=null,_t=null,at=null,yt=0,Et=0,At=null,pt=!0;function Mt(U){for(var ut,ft,lt;;)switch(ut=null,ft=null,lt=null,$){case Z:$=S;try{R=gt(R),_t===null?gt=null:(gt=_t._1,_t=_t._2)}catch(Ht){$=z,tt=F.left(Ht),R=null}break;case X:F.isLeft(R)?($=z,tt=R,R=null):gt===null?$=z:($=Z,R=F.fromRight(R));break;case S:switch(R.tag){case u:gt&&(_t=new N(_,gt,_t)),gt=R._2,$=S,R=R._1;break;case e:gt===null?($=z,R=F.right(R._1)):($=Z,R=R._1);break;case i:$=X,R=E(F.left,F.right,R._1);break;case o:$=W,R=B(F.left,R._1,function(Ht){return function(){q===U&&(q++,V.enqueue(function(){q===U+1&&($=X,R=Ht,Mt(q))}))}});return;case n:$=z,tt=F.left(R._1),R=null;break;case r:gt===null?at=new N(_,R,at,K):at=new N(_,R,new N(_,new N(h,gt,_t),at,K),K),gt=null,_t=null,$=S,R=R._1;break;case s:yt++,gt===null?at=new N(_,R,at,K):at=new N(_,R,new N(_,new N(h,gt,_t),at,K),K),gt=null,_t=null,$=S,R=R._1;break;case a:$=X,ut=G(F,O,R._2),O&&O.register(ut),R._1&&ut.run(),R=F.right(ut);break;case c:$=S,R=I(F,O,R._1);break}break;case z:if(gt=null,_t=null,at===null)$=M,R=K||tt||R;else switch(ut=at._3,lt=at._1,at=at._2,lt.tag){case r:K&&K!==ut&&yt===0?$=z:tt&&($=S,R=lt._2(F.fromLeft(tt)),tt=null);break;case h:K&&K!==ut&&yt===0||tt?$=z:(gt=lt._1,_t=lt._2,$=Z,R=F.fromRight(R));break;case s:yt--,tt===null&&(ft=F.fromRight(R),at=new N(_,new N(m,lt._2,ft),at,ut),(K===ut||yt>0)&&($=S,R=lt._3(ft)));break;case m:at=new N(_,new N(y,R,tt),at,K),$=S,K&&K!==ut&&yt===0?R=lt._1.killed(F.fromLeft(K))(lt._2):tt?R=lt._1.failed(F.fromLeft(tt))(lt._2):R=lt._1.completed(F.fromRight(R))(lt._2),tt=null,yt++;break;case p:yt++,at=new N(_,new N(y,R,tt),at,K),$=S,R=lt._1;break;case y:yt--,$=z,R=lt._1,tt=lt._2;break}break;case M:for(var Nt in At)At.hasOwnProperty(Nt)&&(pt=pt&&At[Nt].rethrow,L(At[Nt].handler(R)));At=null,K&&tt?setTimeout(function(){throw F.fromLeft(tt)},0):F.isLeft(R)&&pt&&setTimeout(function(){if(pt)throw F.fromLeft(R)},0);return;case D:$=S;break;case W:return}}function Jt(U){return function(){if($===M)return pt=pt&&U.rethrow,U.handler(R)(),function(){};var ut=Et++;return At=At||{},At[ut]=U,function(){At!==null&&delete At[ut]}}}function mt(U,ut){return function(){if($===M)return ut(F.right(void 0))(),function(){};var ft=Jt({rethrow:!1,handler:function(){return ut(F.right(void 0))}})();switch($){case D:K=F.left(U),$=M,R=K,Mt(q);break;case W:K===null&&(K=F.left(U)),yt===0&&($===W&&(at=new N(_,new N(p,R(U)),at,K)),$=z,R=null,tt=null,Mt(++q));break;default:K===null&&(K=F.left(U)),yt===0&&($=z,R=null,tt=null)}return ft}}function nt(U){return function(){var ut=Jt({rethrow:!1,handler:U})();return $===D&&Mt(q),ut}}return{kill:mt,join:nt,onComplete:Jt,isSuspended:function(){return $===D},run:function(){$===D&&(V.isDraining()?Mt(q):V.enqueue(function(){Mt(q)}))}}}function P(F,O,Y,q){var $=0,R={},tt=0,K={},gt=new Error("[ParAff] Early exit"),_t=null,at=t;function yt(Jt,mt,nt){var U=mt,ut=null,ft=null,lt=0,Nt={},Ht,Vt;t:for(;;)switch(Ht=null,U.tag){case x:if(U._3===t&&(Ht=R[U._1],Nt[lt++]=Ht.kill(Jt,function(De){return function(){lt--,lt===0&&nt(De)()}})),ut===null)break t;U=ut._2,ft===null?ut=null:(ut=ft._1,ft=ft._2);break;case f:U=U._2;break;case d:case l:ut&&(ft=new N(_,ut,ft)),ut=U,U=U._1;break}if(lt===0)nt(F.right(void 0))();else for(Vt=0,Ht=lt;Vt<Ht;Vt++)Nt[Vt]=Nt[Vt]();return Nt}function Et(Jt,mt,nt){var U,ut,ft,lt,Nt,Ht;for(F.isLeft(Jt)?(U=Jt,ut=null):(ut=Jt,U=null);;){if(ft=null,lt=null,Nt=null,Ht=null,_t!==null)return;if(mt===null){q(U||ut)();return}if(mt._3!==t)return;switch(mt.tag){case f:U===null?(mt._3=F.right(mt._1(F.fromRight(ut))),ut=mt._3):mt._3=U;break;case d:if(ft=mt._1._3,lt=mt._2._3,U){if(mt._3=U,Nt=!0,Ht=tt++,K[Ht]=yt(gt,U===ft?mt._2:mt._1,function(){return function(){delete K[Ht],Nt?Nt=!1:nt===null?Et(U,null,null):Et(U,nt._1,nt._2)}}),Nt){Nt=!1;return}}else{if(ft===t||lt===t)return;ut=F.right(F.fromRight(ft)(F.fromRight(lt))),mt._3=ut}break;case l:if(ft=mt._1._3,lt=mt._2._3,ft===t&&F.isLeft(lt)||lt===t&&F.isLeft(ft))return;if(ft!==t&&F.isLeft(ft)&&lt!==t&&F.isLeft(lt))U=ut===ft?lt:ft,ut=null,mt._3=U;else if(mt._3=ut,Nt=!0,Ht=tt++,K[Ht]=yt(gt,ut===ft?mt._2:mt._1,function(){return function(){delete K[Ht],Nt?Nt=!1:nt===null?Et(ut,null,null):Et(ut,nt._1,nt._2)}}),Nt){Nt=!1;return}break}nt===null?mt=null:(mt=nt._1,nt=nt._2)}}function At(Jt){return function(mt){return function(){delete R[Jt._1],Jt._3=mt,Et(mt,Jt._2._1,Jt._2._2)}}}function pt(){var Jt=S,mt=Y,nt=null,U=null,ut,ft;t:for(;;)switch(ut=null,ft=null,Jt){case S:switch(mt.tag){case f:nt&&(U=new N(_,nt,U)),nt=new N(f,mt._1,t,t),mt=mt._2;break;case d:nt&&(U=new N(_,nt,U)),nt=new N(d,t,mt._2,t),mt=mt._1;break;case l:nt&&(U=new N(_,nt,U)),nt=new N(l,t,mt._2,t),mt=mt._1;break;default:ft=$++,Jt=z,ut=mt,mt=new N(x,ft,new N(_,nt,U),t),ut=G(F,O,ut),ut.onComplete({rethrow:!1,handler:At(mt)})(),R[ft]=ut,O&&O.register(ut)}break;case z:if(nt===null)break t;nt._1===t?(nt._1=mt,Jt=S,mt=nt._2,nt._2=t):(nt._2=mt,mt=nt,U===null?nt=null:(nt=U._1,U=U._2))}for(at=mt,ft=0;ft<$;ft++)R[ft].run()}function Mt(Jt,mt){_t=F.left(Jt);var nt;for(var U in K)if(K.hasOwnProperty(U)){nt=K[U];for(U in nt)nt.hasOwnProperty(U)&&nt[U]()}K=null;var ut=yt(Jt,at,mt);return function(ft){return new N(o,function(lt){return function(){for(var Nt in ut)ut.hasOwnProperty(Nt)&&ut[Nt]();return k}})}}return pt(),function(Jt){return new N(o,function(mt){return function(){return Mt(Jt,mt)}})}}function I(F,O,Y){return new N(o,function(q){return function(){return P(F,O,Y,q)}})}return N.EMPTY=t,N.Pure=v(e),N.Throw=v(n),N.Catch=v(r),N.Sync=v(i),N.Async=v(o),N.Bind=v(u),N.Bracket=v(s),N.Fork=v(a),N.Seq=v(c),N.ParMap=v(f),N.ParApply=v(d),N.ParAlt=v(l),N.Fiber=G,N.Supervisor=et,N.Scheduler=V,N.nonCanceler=k,N})();let Df=null;function kx(){return Df||(typeof document>"u"?null:Df=document.createElement("canvas").getContext("2d"))}const Xs=new Map;function Pf(t,e,n,r,i,o){const u=`${n} ${e}px ${t}`,s=u+"|"+r;if(Xs.has(s))return Xs.get(s);const a=kx();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))Xs.set(s,c);else if(f&&f.load)try{f.load(u)}catch{}return c}const Ex=(t,e,n,r)=>Pf(t,e,n,r,i=>i.width,-1),Gx=(t,e,n,r)=>Pf(t,e,n,r,i=>({ascent:i.actualBoundingBoxAscent,descent:i.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),If=t=>e=>{const n=Ex(t.family,t.size,t.weight,Pr(e));return n<0?rt(po(e).length)*t.size*.62:n},Qf=t=>e=>{const n=Gx(t.family,t.size,t.weight,Pr(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},Ff=t=>t,Af=t=>t,Vo=t=>t,Mf=t=>t,Cx=t=>t,Bf=t=>t,zf=t=>t,Sx=zf("BaselineTop"),Wr=zf("BaselineMiddle"),Us=Bf("AlignLeft"),Xo=Bf("AlignCenter"),Te=Cx("RoundJoin"),fn=Mf("ButtCap"),In=Mf("RoundCap"),Dx=Vo("LayerPolyOut"),Px=Vo("LayerPolyIn"),Ix=Vo("LayerNodeMask"),Qx=Vo("LayerOverlay"),js=Af("NonZero"),Fx=Af("EvenOdd"),Rf=Ff("Normal"),Uo=Ff("Difference"),re={r:255,g:255,b:255,a:255},Qn={r:26,g:26,b:26,a:255},Ax=t=>t,Wf=t=>t,Mx=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},nn=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Hf=t=>e=>n=>{const r=it.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=it.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},Zs=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Bx=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},zx=Wf("FlatLevel"),Rx=Wf("NestedLevel"),Of=Ax("GenieSilhouette"),Wx=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const i=Cr(t);return{prng:i.prng,yLift:i.value*n.yJitter*r}},Hx=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const i=Cr(t);return{prng:i.prng,dx:(i.value*2-1)*n.xJitter*r}},qf=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,i=Ee(r*r+n*n),o=(t.r*t.r-e.r*e.r+i*i)/(2*i),u=Ee(Mx(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},Ox=t=>e=>{const n=nn(e)(nn(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},qx=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=Cr(t);return{prng:u.prng,r:i*(1+u.value*o.rJitter)}},$f=t=>{const e=nn(t.w)(t.h)/2;return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,4,t.x+t.w-e+.5522847498307936*e,t.y,t.x+t.w,t.y+e-.5522847498307936*e,t.x+t.w,t.y+e,4,t.x+t.w,t.y+e+.5522847498307936*e,t.x+t.w-e+.5522847498307936*e,t.y+t.h,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,4,t.x+e-.5522847498307936*e,t.y+t.h,t.x,t.y+e+.5522847498307936*e,t.x,t.y+e,4,t.x,t.y+e-.5522847498307936*e,t.x+e-.5522847498307936*e,t.y,t.x+e,t.y,5]},$x=t=>e=>n=>{const r=Cr(t),i=e.length;return i===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const o=Hf(0)(i-1|0)(de(dn(r.value*rt(n))));return o>=0&&o<e.length?e[o]:-1})()}},Yx=t=>e=>{const n=Cr(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const i=Hf(0)(r-1|0)(de(dn(n.value*rt(r))));return i>=0&&i<e.length?e[i]:-1})()}},Yf=t=>{const e=nn(t.w*.18)(t.h*.6);return[1,t.x+e,t.y,2,t.x+t.w,t.y,2,t.x+t.w-e,t.y+t.h,2,t.x,t.y+t.h,5]},Vf=t=>[1,t.x,t.y,2,t.x+t.w,t.y,2,t.x+t.w,t.y+t.h*.85,4,t.x+t.w*.66,t.y+t.h*1.05,t.x+t.w*.34,t.y+t.h*.65,t.x,t.y+t.h*.85,5],Xf={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},Vx=t=>{const e=nn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,i=t.x+n;return[1,t.x,r,4,t.x,r+.5522847498*e,i-.5522847498*n,r+e,i,r+e,4,i+.5522847498*n,r+e,t.x+t.w,r+.5522847498*e,t.x+t.w,r]},Uf=t=>{const e=nn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+t.h+5,i=t.y+e,o=r-e,u=t.x+n;return[1,t.x,i,4,t.x,i-.5522847498*e,u-.5522847498*n,t.y,u,t.y,4,u+.5522847498*n,t.y,t.x+t.w,i-.5522847498*e,t.x+t.w,i,2,t.x+t.w,o,4,t.x+t.w,o+.5522847498*e,u+.5522847498*n,r,u,r,4,u-.5522847498*n,r,t.x,o+.5522847498*e,t.x,o,5]},jf=t=>e=>{const n=e.y+e.h,r=cd(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=Zs(t.minN)(i<=0||o<=0?t.minN:de($n(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=Yx(t.seed)((()=>{const p=a-c|0;return p<1?s:bt(p,s.length,s)})()),l=d.idx,_=$x(d.prng)(ct(p=>p!==l,f))(Zs(1)(f.length-(Be(xr)(l)(f)?1:0)|0)),h=_.idx,m=u>=2?i/(rt(u)-1):0;return J(p=>y=>{const x=y===h,N=y===l,v=y===0||y===(u-1|0),k=qx(p.prng)(v)(N)(x)(r)(t),L=Wx(k.prng)(v)(t)(e.h),E=Hx(L.prng)(v)(t)(m);return{prng:E.prng,circles:zt(p.circles)({cx:e.x+Bx(k.r)(e.w-k.r)((u>=2?r+rt(y)/(rt(u)-1)*i+E.dx:r+0*i+E.dx)+(N?t.heroShift*m:x?-1*t.smallShift*m:0)),cy:n-L.yLift,r:k.r})}})({prng:_.prng,circles:[]})(It(0,u-1|0)).circles},Zf=t=>e=>{const n=t.length;return Qt(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?qf(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?qf(i)(t[o]):{x:i.cx+i.r,y:e}})()}))(t)},Kf=t=>{const e=nn(t.h*.4)(t.w*.2);return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,2,t.x+t.w,t.y+t.h/2,2,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,2,t.x,t.y+t.h/2,5]},Xx=t=>e=>n=>{const r=ur(e.y-t.cy)(e.x-t.cx),i=ur(n.y-t.cy)(n.x-t.cx),o=i>r?i-r:i+6.283185307179586-r,u=Zs(1)(de(Xi(o/1.5707963267948966))),s=o/rt(u),a=1.3333333333333333*gd(s/4);return Tt(It(0,u-1|0))(c=>{const f=r+rt(c+1|0)*s,d=t.cx+t.r*Ke(f),l=t.cy+t.r*Oe(f),_=r+rt(c)*s;return[4,t.cx+t.r*Ke(_)-a*t.r*Oe(_),t.cy+t.r*Oe(_)+a*t.r*Ke(_),d+a*t.r*Oe(f),l-a*t.r*Ke(f),d,l]})},t_=t=>e=>{const n=t.h*.38,r=Zf(jf(Xf)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),i=nn(e)(nn(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...Tt(r)(o=>Xx(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]:Ox(t)(e)},e_=t=>e=>n=>r=>i=>o=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(i)(o);if(e==="Cylinder"){const u=Uf(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Parallelogram"){const u=Yf(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Diamond"){const u=Kf(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=$f(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Document"){const u=Vf(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Cloud"){const u=t_(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)},Ux=t=>()=>t.clip("evenodd"),jx=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()},Ks=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ta=t=>e=>n=>{const r=e.stroke;return()=>{const i=r.value,o=Qd(t)(n);if(i!==n)return o(),e.stroke.value=n}},Zx=t=>e=>n=>{const r=e.font;return()=>{const i=r.value,o=Od(t)(n);if(i!==n)return o(),e.font.value=n}},Ai=t=>e=>n=>{const r=e.fill;return()=>{const i=r.value,o=Id(t)(n);if(i!==n)return o(),e.fill.value=n}},jo=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=Ka(t)((()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===2){const s=ui(t)((()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===3){const s=si(t)({cpx:(()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})(),cpy:(()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=o+3|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=o+4|0;return c>=0&&c<e.length?e[c]:0})()}),a=r(o+5|0);return()=>(s(),a())}if(u===4){const s=$d(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=tc(t),a=r(o+1|0);return()=>(s(),a())}return()=>{}},i=Za(t);return()=>(i(),r(0)())},Kx=t=>e=>n=>r=>i=>o=>{const u=Ks(o)(Ks(r/2)(i/2)),s=Ka(t)(e+u)(n);return()=>(s(),ui(t)(e+r-u)(n)(),si(t)({cpx:e+r,cpy:n,x:e+r,y:n+u})(),ui(t)(e+r)(n+i-u)(),si(t)({cpx:e+r,cpy:n+i,x:e+r-u,y:n+i})(),ui(t)(e+u)(n+i)(),si(t)({cpx:e,cpy:n+i,x:e,y:n+i-u})(),ui(t)(e)(n+u)(),si(t)({cpx:e,cpy:n,x:e+u,y:n})(),tc(t)())},tN=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),eN=t=>e=>{const n=zd(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=tN();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0}}}},nN={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},rN=t=>ie(t.weight)+" "+Ga(t.size)+"px "+t.family,vn=t=>{const e=Ga(rt(t.a)/255);return t.a>=255?"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")":"rgba("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+","+e+")"},iN=t=>e=>n=>r=>{const i=Ai(t)(n)(vn(r));return()=>(i(),Bd(t)({x:0,y:0,width:e.width,height:e.height})())},oN=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",jx(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})())},uN=t=>e=>n=>r=>{const i=Ai(t)(e)(vn(r));return()=>(i(),jo(t)(n)(),Cu(t)())},sN=t=>e=>n=>r=>i=>{const o=Ai(t)(e)(vn(r));return()=>(o(),ta(t)(e)(vn(i.color))(),Lu(t)(i.width)(),no(t)((()=>{if(i.lineJoin==="RoundJoin")return eo;if(i.lineJoin==="BevelJoin")return Qu;if(i.lineJoin==="MiterJoin")return Fu;g()})())(),zu(t)((()=>{if(i.lineCap==="ButtCap")return Bu;if(i.lineCap==="RoundCap")return Au;if(i.lineCap==="SquareCap")return Mu;g()})())(),jo(t)(n)(),Cu(t)(),Gu(t)())},aN=t=>e=>n=>r=>i=>o=>{const u=Za(t);return()=>{if(u(),Kx(t)(n.x)(n.y)(n.w)(n.h)(r)(),i.tag==="Just"?(Ai(t)(e)(vn(i._1.color))(),Cu(t)()):i.tag==="Nothing"||g(),o.tag==="Just")return ta(t)(e)(vn(o._1.color))(),Lu(t)(o._1.width)(),no(t)((()=>{if(o._1.lineJoin==="RoundJoin")return eo;if(o._1.lineJoin==="BevelJoin")return Qu;if(o._1.lineJoin==="MiterJoin")return Fu;g()})())(),zu(t)((()=>{if(o._1.lineCap==="ButtCap")return Bu;if(o._1.lineCap==="RoundCap")return Au;if(o._1.lineCap==="SquareCap")return Mu;g()})())(),Gu(t)();o.tag!=="Nothing"&&g()}},cN=t=>e=>n=>r=>{const i=ta(t)(e)(vn(r.color));return()=>(i(),Lu(t)(r.width)(),no(t)((()=>{if(r.lineJoin==="RoundJoin")return eo;if(r.lineJoin==="BevelJoin")return Qu;if(r.lineJoin==="MiterJoin")return Fu;g()})())(),zu(t)((()=>{if(r.lineCap==="ButtCap")return Bu;if(r.lineCap==="RoundCap")return Au;if(r.lineCap==="SquareCap")return Mu;g()})())(),jo(t)(n)(),Gu(t)())},n_=t=>e=>n=>{const r=Ai(t)(e)(vn(n.color));return()=>(r(),Zx(t)(e)(rN(n.font))(),rl(t)((()=>{if(n.align==="AlignLeft")return jd;if(n.align==="AlignCenter")return Kd;if(n.align==="AlignRight")return Zd;g()})())(),nl(t)((()=>{if(n.baseline==="BaselineTop")return Yd;if(n.baseline==="BaselineMiddle")return Vd;if(n.baseline==="BaselineAlphabetic")return Xd;if(n.baseline==="BaselineBottom")return Ud;g()})())(),qd(t)(n.content)(n.x)(n.y)())},r_={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>nN},gN={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>r_},fN=t=>e=>n=>{const r=Ks(e.width/n.vw)(e.height/n.vh),i=Su(t)({translateX:(e.width-n.vw*r)/2-n.vx*r,translateY:(e.height-n.vh*r)/2-n.vy*r});return()=>(i(),Ki(t)({scaleX:r,scaleY:r})(),no(t)(eo)())},_N={pure:t=>e=>()=>t,Apply0:()=>r_},dN={Applicative0:()=>_N,Bind1:()=>gN},i_={fillPath:t=>e=>n=>{const r=uN(n.ctx)(n.styleCache)(t)(e.color),i=n.maskDepth;return()=>{if(i.value===0)return r()}},strokePath:t=>e=>n=>{const r=cN(n.ctx)(n.styleCache)(t)(e),i=n.maskDepth;return()=>{if(i.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const i=sN(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=aN(i.ctx)(i.styleCache)(t)(e)(n)(r),u=i.maskDepth;return()=>{if(u.value===0)return o()}},drawText:t=>e=>{const n=n_(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=sr(n.ctx),i=n.maskDepth;return()=>{if(i.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Rd(n.ctx)(t)(),n_(n.ctx)(n.styleCache)(e)(),ar(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=sr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Su(e.ctx)({translateX:t.tx,translateY:t.ty})(),Ki(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=ar(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBakedTransform:t=>e=>{const n=sr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Su(e.ctx)({translateX:t.tx,translateY:t.ty})(),Ki(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=ar(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushClip:t=>e=>n=>{const r=sr(n.ctx),i=n.maskDepth;return()=>{if(i.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",jo(n.ctx)(t)(),e==="NonZero")return Md(n.ctx)();if(e==="EvenOdd")return Ux(n.ctx)();g()}}},popClip:t=>{const e=ar(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBlend:t=>e=>{const n=sr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){if(n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",t==="Normal")return nc(e.ctx)(tl)();if(t==="Difference")return nc(e.ctx)(el)();g()}}},popBlend:t=>{const e=ar(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushAlpha:t=>e=>{const n=sr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Ad(e.ctx)(t)()}},popAlpha:t=>{const e=ar(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushLayer:t=>e=>{if(t==="LayerNodeMask"){const n=e.maskDepth;return()=>{const r=n.value;n.value=r+1|0}}return()=>{}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;if(n>0)return t.maskDepth.value=r}},setViewport:t=>e=>{const n=fN(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=iN(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=oN(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=If(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Qf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Of,Monad0:()=>dN},lN=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Hr=t=>e=>n=>{const r=lN(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},o_=t=>{const e=st.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=st.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Zo=t=>{if(t.tag==="Hidden")return{alpha:0,scale:0};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:t._1>0?1:0,scale:pi(8)(.6)(o_(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:pi(8)(.6)(o_(1-t._1))};g()};function hN(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function pN(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:hN(i,o)}}return n}function mN(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 u_(t,e){if(e.length===0)return[];const n=pN(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]=mN(n,e,o*r/t);return i}function yN(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 xN(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 yN(r,e)}const s_=t=>e=>n=>{const r=u_(t,e),i=u_(t,n),o=xN(r,i);return{from:r,to:o}};function a_(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 NN(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 JN(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 TN(t){return t<0?0:t>1?1:t}const c_=t=>e=>n=>r=>{const i=e.length;if(i===0)return[];const o=a_(e),u=a_(n),s=NN(o,u),a=new Array(i);let c=1/0,f=-1/0;for(let _=0;_<i;_++){const h=e[_],m=(h.x-o.x)*s.x+(h.y-o.y)*s.y;a[_]=m,m<c&&(c=m),m>f&&(f=m)}const d=f-c;let l=new Array(i);for(let _=0;_<i;_++){const h=e[_],m=n[_];if(m===void 0){l[_]=h;continue}const p=d<=1e-4?0:r.maxDelay*(1-(a[_]-c)/d),y=Math.max(1e-4,1-p),x=TN((t-p)/y),N=x*x*(3-2*x);l[_]={x:h.x+(m.x-h.x)*N,y:h.y+(m.y-h.y)*N}}for(let _=0;_<r.smoothPasses;_++)l=JN(.5,l);return l},wn=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},g_=J(Tr)(0),f_=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},vN=J(t=>e=>t+e.len)(0),__=t=>{const e=Ft(n=>T,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Tt(bt(1,t.length,t))(n=>[2,n.x,n.y]),5];g()},wN=t=>e=>{const n=wn(e)(wn(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},bN=t=>{const e=Ft(n=>T,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Tt(e._1.tail)(n=>[2,n.x,n.y])];g()},LN=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return Uf(e);if(t.shape==="Parallelogram")return Yf(e);if(t.shape==="Diamond")return Kf(e);if(t.shape==="Ellipse")return $f(e);if(t.shape==="Document")return Vf(e);if(t.shape==="Cloud")return t_(e)(7);if(t.shape==="Rectangle")return wN(e)(7);g()},pe=t=>e=>n=>H(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)),kN=t=>{const e=nn(t.w*.18)(t.h*.6);return[...pe({x:t.x+e,y:t.y})({x:t.x+t.w,y:t.y})(16),...pe({x:t.x+t.w,y:t.y})({x:t.x+t.w-e,y:t.y+t.h})(16),...pe({x:t.x+t.w-e,y:t.y+t.h})({x:t.x,y:t.y+t.h})(16),...pe({x:t.x,y:t.y+t.h})({x:t.x+e,y:t.y})(16)]},Or=t=>e=>{const n=wn(t)(wn(e.w/2)(e.h/2));return{...e,x:e.x+n,y:e.y+n,w:e.w-2*n,h:e.h-2*n}},ea=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return Ee(r*r+n*n)},EN=t=>Je(e=>n=>({a:e,b:n,len:ea(e)(n)}),t,bt(1,t.length,t)),GN=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?w("Just",e[n]):T,i=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];g()})(),o=0<e.length?w("Just",e[0]):T,u=(()=>{if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return{x:0,y:0};g()})(),s=e.length;return s<3?e:[u,...Tt(It(1,s-2|0))(a=>{const c=a+1|0,f=c>=0&&c<e.length?w("Just",e[c]):T,d=a>=0&&a<e.length?w("Just",e[a]):T,l=a-1|0,_=l>=0&&l<e.length?w("Just",e[l]):T;if(_.tag==="Just"&&d.tag==="Just"&&f.tag==="Just"){const h=d._1,m=ea(h)(f._1),p=ea(_._1)(h),y=wn(t)(m/2),x=wn(t)(p/2),N=m>0?y/m:0,v=h.x+(f._1.x-h.x)*N,k=h.y+(f._1.y-h.y)*N,L=p>0?x/p:0,E=h.x+(_._1.x-h.x)*L,B=h.y+(_._1.y-h.y)*L;return H(V=>{const et=rt(V)/rt(10),D=1-et;return{x:D*D*E+2*D*et*h.x+et*et*v,y:D*D*B+2*D*et*h.y+et*et*k}})(It(0,10))}return[]}),...i]},CN=t=>e=>n=>r=>i=>H(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)),SN=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),...CN({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)],d_=t=>e=>H(n=>{const r=6.283185307179586*rt(n)/rt(64);return{x:t.x+e*Ke(r),y:t.y+e*Oe(r)}})(It(0,63)),Ko=t=>e=>{const n=.5522847498*e;return[1,t.x+e,t.y,4,t.x+e,t.y+n,t.x+n,t.y+e,t.x,t.y+e,4,t.x-n,t.y+e,t.x-e,t.y+n,t.x-e,t.y,4,t.x-e,t.y-n,t.x-n,t.y-e,t.x,t.y-e,4,t.x+n,t.y-e,t.x+e,t.y-n,t.x+e,t.y,5]},DN=t=>{const e=t.y+t.h/2,n=nn(t.h*.4)(t.w*.2);return[...pe({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...pe({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...pe({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...pe({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...pe({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...pe({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},l_=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:g_(H(n=>n.x)(t))/rt(e),y:g_(H(n=>n.y)(t))/rt(e)}},tu=t=>e=>n=>r=>i=>H(o=>{const u=n+(r-n)*(rt(o)/rt(i));return{x:t.x+e*Ke(u),y:t.y+e*Oe(u)}})(It(0,i-1|0)),h_=t=>e=>{const n=wn(t)(wn(e.w/2)(e.h/2));return[...pe({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...tu({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),...tu({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),...tu({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),...tu({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},eu=t=>e=>n=>r=>i=>o=>H(u=>{const s=r+(i-r)*(rt(u)/rt(o));return{x:t.x+e*Ke(s),y:t.y+n*Oe(s)}})(It(0,o-1|0)),PN=t=>{const e=t.h*.38;return[...Tt(Zf(jf(Xf)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=ur(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),i=ur(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return eu({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)]},IN=t=>{const e=wn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,i=t.y+t.h+5-e-2,o=t.x+n;return[...eu({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),...eu({x:o,y:i})(n)(e)(0)(3.141592653589793)(24),...pe({x:t.x,y:i})({x:t.x,y:r})(12)]},nu=t=>e=>e.shape==="Cylinder"?IN(e):e.shape==="Parallelogram"?kN(e):e.shape==="Diamond"?DN(e):e.shape==="Ellipse"?h_(nn(e.w)(e.h)/2)(e):e.shape==="Document"?SN(e):e.shape==="Cloud"?PN(e):h_(t)(e),QN=t=>{const e=wn(t.h*.075)(t.w*.075),n=t.w/2;return eu({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},FN=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})()})()?zt(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,AN=t=>e=>n=>{const r=Ft(i=>T,i=>o=>w("Just",{head:i,tail:o}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const i=EN(t),o=vN(i),u=f_(0)(o)(e*o),s=f_(0)(o)(n*o);return s<=u?[]:FN(i)(u)(s)}g()},na=t=>t,Fn=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},pr=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},MN=O1(Fa)(Bt),BN=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},zN=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},p_=na("SegMove"),RN=na("SegLine"),WN=na("SegQuad"),m_={offset:.4,passes:1,rMax:1.5},y_=t=>de(dn(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,ru=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},iu=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},An=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},Mi=(()=>{const t=J(e=>n=>((e*31|0)+de(dn(n.x*100))|0)+de(dn(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),HN=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const i=n,o=r,u=i>=0&&i<t.length?w("Just",t[i]):T;if(u.tag==="Nothing"){n=t.length;continue}if(u.tag==="Just"){if(u._1===1){const s={x:(()=>{const a=i+1|0;return a>=0&&a<t.length?t[a]:0})(),y:(()=>{const a=i+2|0;return a>=0&&a<t.length?t[a]:0})()};e.push({kind:p_,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:RN,m:o,c:o,p:s,len:Ee(a*a+c*c)}),r=s,n=i+3|0;continue}if(u._1===3){const s={x:(()=>{const f=i+3|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+4|0;return f>=0&&f<t.length?t[f]:0})()},a=s.x-o.x,c=s.y-o.y;e.push({kind:WN,m:o,c:{x:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()},p:s,len:Ee(a*a+c*c)*1.05}),r=s,n=i+5|0;continue}if(u._1===5){e.push({kind:p_,m:o,c:o,p:o,len:0}),n=i+1|0;continue}n=t.length;continue}g()}return e},ON=t=>e=>{const n=e.length-1|0,r=n<1?[]:bt(0,n,e),i=(()=>{const u=r.length-1|0;return u>=0&&u<r.length?w("Just",r[u]):T})(),o=e.length-1|0;if(o>=0&&o<e.length&&i.tag==="Just"){const u=e[o].y-i._1.y,s=e[o].x-i._1.x,a=Ee(s*s+u*u);return a<=1e-4?e:zt((()=>{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},qN=t=>e=>n=>ke(J(r=>i=>{const o=ae(0)(t)(r.prng),u=ae(0)(6.283185307179586)(o.prng);return{prng:u.prng,out:[{x:i.x+o.value*Ke(u.value),y:i.y+o.value*Oe(u.value)},...r.out]}})({prng:e,out:[]})(n).out),$N=t=>e=>n=>{if(e.kind==="SegMove")return iu(t)(e.p);if(e.kind==="SegLine")return An(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 An(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});g()},YN=t=>e=>{if(e.kind==="SegMove")return iu(t)(e.p);if(e.kind==="SegLine")return An(t)(e.p);if(e.kind==="SegQuad")return ru(t)(e.c)(e.p);g()},x_=t=>e=>{const n=HN(e),r=J(s=>a=>s+a.len)(0)(n)*Fn(0)(pr(1)(t)),i=[];let o=0,u=0;for(;u<n.length;){const s=u,a=o;if(s>=0&&s<n.length){if(a+n[s].len<=r){const c=n[s];YN(i)(c)(),o=a+c.len,u=s+1|0;continue}if(a>=r){u=n.length;continue}$N(i)(n[s])((r-a)/Fn(n[s].len)(1e-4))()}u=n.length}return i},N_={offset:1.5,passes:2,rMax:14,overshoot:2.5},J_=t=>e=>n=>r=>{const i=r.y-n.y,o=n.y-e.y,u=r.x-n.x,s=Ee(u*u+i*i),a=n.x-e.x,c=Ee(a*a+o*o),f=pr(t.rMax*(ad(c>0&&s>0?Fn(-1)(pr(1)((a*u+o*i)/(c*s))):1)/3.141592653589793))(.4*pr(c)(s));return{inP:c>0?{x:n.x-a/c*f,y:n.y-o/c*f}:n,curr:n,outP:s>0?{x:n.x+u/s*f,y:n.y+i/s*f}:n}},T_=t=>e=>{const n=e.length,r=[],i=0<e.length?w("Just",e[0]):T;if(i.tag==="Just"?iu(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=J_(t)(e[c])(e[s])(e[a]);An(r)(f.inP)(),ru(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&&An(r)(e[o])(),r},VN=t=>e=>n=>r=>i=>{if(i.length<4)return T_(t)(i);const o=0<i.length?w("Just",i[0]):T,u=(()=>{if(o.tag==="Nothing")return{x:0,y:0};if(o.tag==="Just")return o._1;g()})(),s=i.length-1|0,a=Yn(Yn(e)(s)+s|0)(s),c=_=>{const h=Yn(_+s|0)(s);return h>=0&&h<i.length?i[h]:u},f=H(_=>J_(t)(c((a+_|0)-1|0))(c(a+_|0))(c((a+_|0)+1|0)))(It(0,s-1|0)),d=[],l=0<f.length?w("Just",f[0]):T;if(l.tag==="Just")if(iu(d)(l._1.outP)(),MN((()=>{const _=Ft(h=>T,h=>m=>w("Just",m),f);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})())(_=>{const h=An(d)(_.inP);return()=>(h(),ru(d)(_.curr)(_.outP)())})(),n)An(d)(l._1.inP)(),ru(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const _=f.length-1|0;_>=0&&_<f.length?An(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}})())():An(d)(l._1.inP)()}else l.tag==="Nothing"||g();return d},qr=t=>e=>n=>r=>{const i=BN(1)(r.length-1|0),o=ae(0)(rt(i))(gs("shape")(e)),u=zN(i-1|0)(de(dn(o.value))),s=o.prng;return H(a=>{const c=ae(0)(1)(gs(ie(a))(s)),f=ae(-.18)(.3)(c.prng),d=c.value<.7,l=ae(.5)(.85)(f.prng),_=qN(t.offset)(l.prng)(r);return{path:n?VN(t)(u)(d)(f.value)(_):T_(t)(_),alpha:l.value}})(It(0,t.passes-1|0))},XN=t=>e=>n=>qr(t)(e)(!0)([{x:n.x,y:n.y},{x:n.x+n.w,y:n.y},{x:n.x+n.w,y:n.y+n.h},{x:n.x,y:n.y+n.h},{x:n.x,y:n.y}]),UN=t=>e=>n=>{const r=Fn(0)(pr(1)(n)),i=e.h/rt(4),o=Fn(6)(i*1.4);return xt(u=>u)(H(u=>{if(r<Fn(0)(rt(u)/rt(4)-.05))return T;const s=gs(ie(u))(t),a=Fn(0)(rt(u)/rt(4)-.05),c=Yn(u)(2)===0,f=c?e.x-2:e.x+e.w+2,d=c?e.x+e.w+2:e.x-2,l=e.y+(rt(u)+.5)*i;return w("Just",{path:x_(Fn(0)(pr(1)((r-a)/Fn(1e-4)(pr(1)(rt(u+1|0)/rt(4)+.05)-a))))((()=>{const _={rMax:2,offset:.6,passes:1},h=ke(J(p=>y=>{const x=ae(-i*.08)(i*.08)(p.prng);return{prng:x.prng,out:[{x:f+(d-f)*(rt(y)/rt(4)),y:l+x.value},...p.out]}})({prng:s,out:[]})(It(0,4)).out),m=h.length<2?[]:qr(_)(s)(!1)(h);return 0<m.length?m[0].path:[]})()),width:o,alpha:1})})(It(0,3)))},ra=(t,e,n)=>({tag:t,_1:e,_2:n}),v_=t=>t,ia=(t,e,n)=>({tag:t,_1:e,_2:n}),ou=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},w_=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Bi=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},b_=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},fe=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},We=(()=>{const t=qe.unfoldr(hn);return e=>t($e("IterNode",e,ln))})(),mr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},jN=Bt.foldMap(vd),uu=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},L_=Kt(C)(Bt),ZN=Xa(C),KN=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},oa=v_("LabelsShown"),tJ=v_("LabelsHidden"),k_=t=>{const e=t.Monad0().Bind1(),n=t.popTransform,r=t.popAlpha;return i=>o=>u=>s=>a=>e.bind(t.pushAlpha(i.fadeAlpha))(()=>e.bind(t.pushTransform({tx:o*(1-i.popScale),ty:u*(1-i.popScale),sx:i.popScale,sy:i.popScale}))(()=>e.bind(t.pushTransform({tx:0,ty:s.y*(1-i.flipY),sx:1,sy:i.flipY}))(()=>e.bind(a)(()=>e.bind(n)(()=>e.bind(n)(()=>r))))))},rn=t=>{const e=t.Apply0();return n=>J(r=>i=>e.apply(e.Functor0().map(o=>Ea)(r))(n(i)))(t.pure())},E_=t=>e=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},a=Hr(i)(o)(r),c=0<t.length?w("Just",t[0]):T,f=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return s;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?w("Just",t[d]):T,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return u;g()})(),h=s_(128)(nu(4)(Or(2)(e)))(d_(f)(6)),m=f.x-s.x,p=2*(()=>{const Z=f.y-s.y;return(m<0?-m:m)+(Z<0?-Z:Z)})(),y=_.x-u.x,x=2*(()=>{const Z=_.y-u.y;return(y<0?-y:y)+(Z<0?-Z:Z)})(),N=p+_i(t)+x,v=N<=1e-4?1:1-x/N,k=N<=1e-4?0:p/N,L=v-k,E=s_(128)(d_(_)(6))(nu(4)(Or(2)(n))),B={maxDelay:.4,smoothPasses:2},V=vr(t)(ou(0)(1)(L<=1e-4?0:(a-k)/L)),et=(()=>{if(V.tag==="Just")return V._1;if(V.tag==="Nothing")return f;g()})(),D=(()=>{if(v>=1)return 0;const Z=(a-v)/(1-v),X=Z<0?0:Z>1?1:Z;return X*X*(3-2*X)})(),S=(()=>{if(k<=1e-4)return 1;const Z=a/k,X=Z<0?0:Z>1?1:Z;return X*X*(3-2*X)})();return a<k?ia("PolyShape",c_(S)(h.from)(h.to)(B)):a>=v?ia("PolyShape",c_(D)(E.from)(E.to)(B)):ia("CircleShape",et,6)},G_=t=>e=>n=>r=>i=>o=>{const u=E_(t)(e)(n)(r)(i)(o);if(u.tag==="PolyShape")return l_(u._1);if(u.tag==="CircleShape")return u._1;g()},eJ=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(Bi)(0)(H(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?w_((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}},nJ=t=>e=>n=>J(r=>i=>{const o=b_(i)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just"){const u=eJ(o._1)(r.obstacles);return{acc:j(C)(i)(u)(r.acc),obstacles:zt(r.obstacles)(u)}}g()})({acc:Q,obstacles:n})(t).acc,ua=(()=>{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:Qn,nodeFill:re,nodeStroke:Qn,text:Qn,edge:Qn,arrowFill:Qn,tokenOutsideFill:Qn,tokenOutsideStroke:re,tokenInside:re,tokenInsideStroke:re,tokenInsideBlend:Uo,tokenInsideAlpha:1,chipPillFill:Qn,chipPillText:re,chipHairline:{r:26,g:26,b:26,a:90},trailDot:Qn,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:Qn,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:re,tokenOutsideStroke:re,tokenInside:re,tokenInsideStroke:re,tokenInsideBlend:Uo,tokenInsideAlpha:1,chipPillFill:e,chipPillText:t,chipHairline:{r:244,g:244,b:245,a:120},trailDot:e,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Blueprint")return{bg:i,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:90,g:160,b:230,a:255},shadowFill:i,shadowDot:re,chip:re,chipShadow:{r:0,g:0,b:0,a:120},chipText:i,nodeFill:i,nodeStroke:re,text:re,edge:re,arrowFill:re,tokenOutsideFill:re,tokenOutsideStroke:re,tokenInside:re,tokenInsideStroke:re,tokenInsideBlend:Rf,tokenInsideAlpha:.35,chipPillFill:re,chipPillText:i,chipHairline:{r:255,g:255,b:255,a:120},trailDot:re,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Whiteboard")return{bg:n,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:0,g:0,b:0,a:0},shadowFill:n,shadowDot:r,chip:{r:217,g:74,b:56,a:255},chipShadow:{r:26,g:26,b:26,a:60},chipText:n,nodeFill:n,nodeStroke:r,text:r,edge:r,arrowFill:r,tokenOutsideFill:r,tokenOutsideStroke:n,tokenInside:n,tokenInsideStroke:n,tokenInsideBlend:Rf,tokenInsideAlpha:1,chipPillFill:r,chipPillText:n,chipHairline:{r:26,g:26,b:26,a:90},trailDot:r,wobble:!0,fontFamily:"Supermarker, Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Isometric")return{bg:o,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:218,b:224,a:255},shadowFill:o,shadowDot:u,chip:{r:255,g:235,b:130,a:255},chipShadow:{r:100,g:110,b:125,a:90},chipText:u,nodeFill:{r:236,g:239,b:244,a:255},nodeStroke:u,text:u,edge:s,arrowFill:s,tokenOutsideFill:u,tokenOutsideStroke:re,tokenInside:re,tokenInsideStroke:re,tokenInsideBlend:Uo,tokenInsideAlpha:1,chipPillFill:u,chipPillText:re,chipHairline:{r:60,g:66,b:78,a:90},trailDot:u,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};g()}})(),sa=t=>e=>Tt(We(t.nodes))(n=>{const r=fe(n._1)(e.nodes);return r.tag==="Just"&&Zo(r._1).alpha>0?LN(n._2):[]}),rJ=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,...sa(e)(n)],iJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=rr.traverse(r);return o=>u=>{const s=Vn(u),a=.32*o.size;return i(c=>n.bind(c===0?r.pure(0):t.measureText(o)(me(c)(u)))(f=>n.bind(t.measureText(o)(me(c+1|0)(u)))(d=>n.bind(t.measureInk(o)(c>=0&&c<s.length?ro(s[c]):" "))(l=>r.pure({x:f,w:d-f,up:l.ascent-a,down:l.descent+a})))))(It(0,s.length-1|0))}},oJ=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 H(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])},aa=t=>{const e=_o(`
7
+ `)(t);return e.length===0?[""]:e},uJ=t=>e=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},a=Hr(i)(o)(r),c=0<t.length?w("Just",t[0]):T,f=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return s;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?w("Just",t[d]):T,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return u;g()})(),h=f.x-s.x,m=2*(()=>{const B=f.y-s.y;return(h<0?-h:h)+(B<0?-B:B)})(),p=_.x-u.x,y=2*(()=>{const B=_.y-u.y;return(p<0?-p:p)+(B<0?-B:B)})(),x=m+_i(t)+y,N=x<=1e-4?1:1-y/x,v=x<=1e-4?0:m/x,k=N-v,L=vr(t)(ou(0)(1)(k<=1e-4?0:(a-v)/k)),E=(()=>{if(L.tag==="Just")return L._1;if(L.tag==="Nothing")return f;g()})();return a<v?ra("InsideRect",Or(2)(e)):a>=N?ra("InsideRect",Or(2)(n)):ra("InsideBall",E,6)},sJ={offset:.8,passes:2,rMax:5},aJ=t=>{const e=t.Monad0().Applicative0(),n=rn(e);return r=>i=>o=>u=>{const s={color:u,width:1,lineJoin:Te,lineCap:fn},a={color:o,flat:!0},c=f=>t.drawRoundedRect({x:f.x,y:f.y,w:f.w,h:f.h})(4)(w("Just",a))(w("Just",s));return n(f=>{if(f._2.tag==="Travelling"){const d=mr(f._2._1.edge)(r.edges),l=fe(f._2._1.target)(r.nodes),_=fe(f._2._1.source)(r.nodes);if(_.tag==="Just"&&l.tag==="Just"&&d.tag==="Just"){const h=uJ((()=>{if(f._2._1.direction==="Forward")return d._1;if(f._2._1.direction==="Backward")return ke(d._1);g()})())(_._1)(l._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);if(h.tag==="InsideRect")return c(h._1);if(h.tag==="InsideBall")return t.fillStrokePath(Ko(h._1)(h._2))(a)(s);g()}return e.pure()}if(f._2.tag==="Filling"){const d=fe(f._2._1.node)(r.nodes);if(d.tag==="Just")return c(Or(2)(d._1));if(d.tag==="Nothing")return e.pure();g()}return e.pure()})(We(i.tokens))}},C_=t=>e=>n=>r=>t.strokePath((()=>{const i=Ft(o=>T,o=>u=>w("Just",{head:o,tail:u}),H(o=>o.pt)(nd(o=>u=>{const s=rt(u)/rt(72),a=ae(-.18)(.18)(o.prng),c=ae(-.1)(.1)(a.prng),f=ae(-.07)(.07)(c.prng),d=n*(.05+.55*s)*(1+c.value),l=s*28.274333882308138+a.value;return{prng:f.prng,pt:{x:e.x+Ke(l)*d+f.value*n,y:e.y+Oe(l)*d+f.value*n}}},{prng:137,pt:{x:e.x,y:e.y}},It(0,72))));if(i.tag==="Just")return[1,i._1.head.x,i._1.head.y,...jN(o=>[2,o.x,o.y])(i._1.tail)];if(i.tag==="Nothing")return[];g()})())({color:r,width:5.5,lineJoin:Te,lineCap:In}),cJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=rn(e.Applicative0());return o=>u=>s=>i(a=>n.bind(t.pushAlpha(a.alpha))(()=>n.bind(t.strokePath(a.path)({color:o.nodeFill,width:a.width,lineJoin:Te,lineCap:In}))(()=>r)))(UN(y_(u)+7777|0)(u)(s))},S_=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=e.Applicative0(),o=rn(i),u=rn(i),s=rr.traverse(i),a=iJ(t),c=cJ(t),f=t.popTransform;return d=>l=>_=>h=>m=>p=>y=>{const x=z=>n.bind(t.pushAlpha(z.alpha))(()=>n.bind(t.strokePath(z.path)({color:l.nodeStroke,width:2,lineJoin:Te,lineCap:In}))(()=>r)),N={family:l.fontFamily,size:l.wobble?15:11,weight:l.wobble?800:500},v=_o(`
8
+ `)(p.label===""?m:p.label),k=v.length===0?[""]:v,L=N.size*1.2,E=p.shape==="Cylinder"?t.strokePath(Vx({x:p.x,y:p.y,w:p.w,h:p.h}))({color:l.nodeStroke,width:1.25,lineJoin:Te,lineCap:fn}):i.pure(),B=(p.shape==="Cylinder"?(p.y+(p.y+p.h+5-2*nn(p.h*.075)(p.w*.075)))/2:(p.y+p.y+p.h)/2)-rt(k.length)*L/2+L/2,V=y.tag==="PloppingOut"&&l.wobble?y._1:-1,et=V>=0,D=Zo(y),S=et?{alpha:1,scale:1}:D,Z=p.x+p.w/2,X=p.y+p.h/2,W=n.bind(t.pushAlpha(S.alpha*_))(()=>n.bind(t.pushTransform({tx:Z*(1-S.scale),ty:X*(1-S.scale),sx:S.scale,sy:S.scale}))(()=>{const z={x:p.x,y:p.y,w:p.w,h:p.h},M={color:l.nodeStroke,width:l.wobble?2:1.25,lineJoin:Te,lineCap:l.wobble?In:fn};return n.bind((()=>{if(l.wobble){if(p.shape==="Rectangle")return o(x)(XN(N_)(y_(z))(z));const G=nu(7)(p);return n.bind(o(x)((()=>{const P=Mi(G);return G.length<4?[]:qr(m_)(P)(!0)(G)})()))(()=>u(P=>o(x)((()=>{const I=Mi(P);return P.length<2?[]:qr(m_)(I)(!1)(P)})()))(p.shape==="Cylinder"?[QN(p)]:[]))}return n.bind(e_(t)(p.shape)(z)(7)(w("Just",{color:l.nodeFill,flat:!1}))(w("Just",M)))(()=>E)})())(()=>n.bind((()=>{if(h.tag==="Just"&&l.wobble&&!et){const G=h._1;return n.bind(s(a(N))(k))(P=>{const I=Lt(nt=>U=>st.compare(nt.x)(U.x)),F=de(dn(p.x*7919+p.y*3001))*-1640531535|0,O=ae(5)(7.5)(F),Y=ae(0)(O.value)(O.prng),q=-(1+2*ae(-1)(1)(Y.prng).value*3.141592653589793/180),$=(nt,U,ut,ft,lt)=>I(xt(Nt=>Nt)([q*U+nt>=ft&&q*U+nt<=lt?w("Just",{x:U,y:q*U+nt}):T,q*ut+nt>=ft&&q*ut+nt<=lt?w("Just",{x:ut,y:q*ut+nt}):T,(()=>{const Nt=(ft-nt)/q;return Nt>=U&&Nt<=ut?w("Just",{x:Nt,y:ft}):T})(),(()=>{const Nt=(lt-nt)/q;return Nt>=U&&Nt<=ut?w("Just",{x:Nt,y:lt}):T})()])),R=O.value,tt=Yn(G.frameHash)(3),K=tt===0?{r:200,g:35,b:30,a:220}:tt===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},gt=p.x+p.w/2,_t=Ae(Qt(nt=>U=>Qt((()=>{const ut=B+rt(nt)*L,ft=gt-J(lt=>Nt=>lt+Nt.w)(0)(U)/2;return lt=>Nt=>{const Ht=N.size*.1,Vt=lt-1|0,De=Vt>=0&&Vt<U.length&&lt>0?(U[Vt].x+U[Vt].w+Nt.x)/2:Nt.x-Ht;return{x:ft+De-1,y:ut-Nt.up-1,w:Bi(0)((()=>{const un=lt+1|0;return un>=0&&un<U.length&&lt<(U.length-1|0)?(Nt.x+Nt.w+U[un].x)/2-De:Nt.x+Nt.w+Ht-De})())+2,h:Nt.up+Nt.down+2}}})())(U))(P)),at=p.y+4,yt=p.x+p.w-4,Et=p.x+4,At=at-q*Et+Y.value,pt=p.y+p.h-4,Mt=Tt(Tt(Qt(nt=>U=>{const ut=(U.from.x+U.to.x)/2,ft=(U.from.y+U.to.y)/2,lt=ae(-1)(1)(F+(911*(nt+1|0)|0)|0),Nt=ae(-3)(5)(lt.prng),Ht=lt.value*3.141592653589793/180,Vt=Ke(Ht),De=Oe(Ht),un=Ne=>({x:ut+(Ne.x-ut)*Vt-(Ne.y-ft)*De,y:ft+(Ne.x-ut)*De+(Ne.y-ft)*Vt});return{from:(()=>{const Ne=un(U.from),Ct=Ne.y-ft,Pt=Ne.x-ut,je=Ee(Pt*Pt+Ct*Ct),Ze=je<1e-4?1:(je+Nt.value)/je;return{x:ut+Pt*Ze,y:ft+Ct*Ze}})(),to:(()=>{const Ne=un(U.to),Ct=ae(-3)(5)(Nt.prng).value,Pt=Ne.y-ft,je=Ne.x-ut,Ze=Ee(je*je+Pt*Pt),kn=Ze<1e-4?1:(Ze+Ct)/Ze;return{x:ut+je*kn,y:ft+Pt*kn}})()}})(xt(nt=>{const U=$(At+rt(nt)*R,Et,yt,at,pt);return U.length===2?w("Just",{from:U[0],to:U[1]}):T})(It(0,uu(1)(de(dn((pt-q*yt-At)/R)))))))(nt=>ct(U=>U.to.x-U.from.x>1,J(U=>ut=>Tt(U)(ft=>{const lt=$(ft.from.y-q*ft.from.x,ut.x,ut.x+ut.w,ut.y,ut.y+ut.h);return lt.length===2?lt[0].x>ft.from.x+.001&&lt[1].x<ft.to.x-.001?[{from:ft.from,to:lt[0]},{from:lt[1],to:ft.to}]:lt[0].x<=ft.from.x+.001&&lt[1].x<ft.to.x-.001?[{from:lt[1],to:ft.to}]:lt[0].x>ft.from.x+.001&&lt[1].x>=ft.to.x-.001?[{from:ft.from,to:lt[0]}]:[]:[ft]}))([nt])(_t))))(nt=>(()=>{const U=nt.to.x-nt.from.x;return Ee(2)*(U>=0?U:-U)<=28})()?[nt]:[{from:nt.from,to:{x:nt.from.x+(nt.to.x-nt.from.x)*.495,y:nt.from.y+(nt.to.y-nt.from.y)*.495}},{from:{x:nt.from.x+(nt.to.x-nt.from.x)*.505,y:nt.from.y+(nt.to.y-nt.from.y)*.505},to:nt.to}]),Jt=Mt.length,mt=nt=>Bi(0)(w_(1)(G.t*rt(Jt)-rt(nt)));return o(nt=>{const U=nt._1,ut=ae(1.4)(1.9)(F+(1303*(U+1|0)|0)|0),ft=ae(.35)(.8)(ut.prng),lt=o(Nt=>n.bind(t.pushAlpha(Nt.alpha*ft.value))(()=>n.bind(t.strokePath(x_(mt(U))(Nt.path))({color:K,width:ut.value,lineJoin:Te,lineCap:In}))(()=>r)))(qr({...N_,rMax:0,offset:.5})(F+(53*(U+1|0)|0)|0)(!1)([nt._2.from,nt._2.to]));return mt(U)>0?lt:i.pure()})(Qt(Hn)(Mt))})}return i.pure()})())(()=>n.bind((()=>{if(d==="LabelsShown")return o(G=>t.drawText({x:p.x+p.w/2,y:B+rt(G._1)*L,content:G._2,font:N,color:l.text,align:Xo,baseline:Wr}))(Qt(Hn)(k));if(d==="LabelsHidden")return i.pure();g()})())(()=>n.bind((()=>{const G=c(l)(z)(V);return et?G:i.pure()})())(()=>n.bind(f)(()=>r)))))}));return S.alpha*_>0?W:i.pure()}},gJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=S_(t),o=t.popAlpha,u=rn(n);return s=>a=>c=>{const f={...s,nodeFill:s.text,text:s.nodeFill,nodeStroke:s.nodeFill};return u(d=>{const l=fe(d._1)(c.nodes),_=fe(d._1)(a.nodes),h=(()=>{if(_.tag==="Just"&&l.tag==="Just"){const m=l._1,p=_._1;return r.bind(t.pushAlpha(d._2))(()=>r.bind(i(oa)(f)(1)(T)(d._1)(p)(m))(()=>o))}return n.pure()})();return d._2>0?h:n.pure()})(We(c.nodeInvert))}},D_=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}))},fJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=t.popAlpha;return o=>u=>s=>a=>c=>f=>d=>l=>_=>{const h=(()=>{if(_>1e-4&&d>1-_){const p=(1-d)/_;return p<0?0:p>1?1:p}if(l>1e-4&&d<l){const p=d/l;return p<0?0:p>1?1:p}return 1})(),m=E_(a)(c)(f)(d)(l)(_);if(m.tag==="CircleShape")return o?C_(t)(m._1)(m._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(Ko(m._1)(m._2))({color:u,flat:!0})({color:s,width:1,lineJoin:Te,lineCap:fn});if(m.tag==="PolyShape"&&o&&m._1.length>=3)return r.bind(t.pushAlpha(h))(()=>r.bind(C_(t)(l_(m._1))(6)({r:200,g:35,b:30,a:220}))(()=>i));if(m.tag==="PolyShape")return o?n.pure():m._1.length>=3?t.fillStrokePath(__(m._1))({color:u,flat:!0})({color:s,width:1,lineJoin:Te,lineCap:fn}):n.pure();g()}},_J=t=>{const e=t.Monad0().Bind1(),n=t.popAlpha;return r=>i=>o=>u=>s=>a=>c=>{const f=Hr(a)(c)(s),d={x:o.x+o.w/2,y:o.y+o.h/2},l={x:u.x+u.w/2,y:u.y+u.h/2},_=(h,m)=>e.bind(t.pushAlpha(m))(()=>e.bind(t.fillStrokePath(Ko(h)(6))({color:r,flat:!0})({color:i,width:1,lineJoin:Te,lineCap:fn}))(()=>n));return f<.5?_(d,(()=>{const h=f*2;return 1-(h<0?0:h>1?1:h)*(h<0?0:h>1?1:h)*(h<0?3:h>1?1:3-2*h)})()):_(l,(()=>{const h=(f-.5)*2;return(h<0?0:h>1?1:h)*(h<0?0:h>1?1:h)*(h<0?3:h>1?1:3-2*h)})())}},su=t=>{const e=fJ(t),n=_J(t),r=t.Monad0().Applicative0(),i=rn(r);return o=>u=>s=>a=>c=>i(f=>{if(f._2.tag==="Travelling"){const d=fe(f._2._1.target)(u.nodes),l=fe(f._2._1.source)(u.nodes);if(l.tag==="Just"&&d.tag==="Just"){const _=mr(f._2._1.edge)(u.edges);if(_.tag==="Just")return e(o)(a)(c)((()=>{if(f._2._1.direction==="Forward")return _._1;if(f._2._1.direction==="Backward")return ke(_._1);g()})())(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);if(_.tag==="Nothing")return n(a)(c)(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);g()}return r.pure()}if(f._2.tag==="Filling"){if(o)return r.pure();const d=fe(f._2._1.node)(u.nodes);if(d.tag==="Just")return t.fillStrokePath(__(nu(4)(Or(2)(d._1))))({color:a,flat:!0})({color:c,width:1,lineJoin:Te,lineCap:fn});if(d.tag==="Nothing")return r.pure();g()}return r.pure()})(We(s.tokens))},P_=t=>{const e=su(t),n=t.Monad0(),r=n.Bind1(),i=su(t),o=aJ(t),u=t.popClip,s=t.popBlend,a=t.popLayer,c=n.Applicative0(),f=rn(c),d=t.popAlpha;return l=>_=>h=>m=>{const p=_.wobble?e(!0)(h)(m)(_.tokenInside)(_.tokenInsideStroke):r.bind(t.insideTokenStyle(l))(y=>{if(y==="GenieSilhouette")return i(!1)(h)(m)(_.tokenInside)(_.tokenInsideStroke);if(y==="ConvexAbsorb")return o(h)(m)(_.tokenInside)(_.tokenInsideStroke);g()});if(_.tokenInsideBlend==="Difference")return r.bind(t.pushLayer(Px))(()=>r.bind(t.pushBlend(Uo))(()=>r.bind(t.pushClip(sa(h)(m))(js))(()=>r.bind(p)(()=>r.bind(u)(()=>r.bind(s)(()=>r.bind(a)(()=>r.bind(t.pushLayer(Ix))(()=>r.bind(f(y=>{const x=fe(y._1)(m.nodes);return x.tag==="Just"&&Zo(x._1).alpha>0?e_(t)(y._2.shape)({x:y._2.x,y:y._2.y,w:y._2.w,h:y._2.h})(7)(w("Just",{color:re,flat:!1}))(T):c.pure()})(We(h.nodes)))(()=>a)))))))));if(_.tokenInsideBlend==="Normal")return r.bind(t.pushClip(sa(h)(m))(js))(()=>r.bind(t.pushAlpha(_.tokenInsideAlpha))(()=>r.bind(p)(()=>r.bind(d)(()=>u))));g()}},I_=t=>{const e=t.Monad0().Bind1(),n=su(t),r=su(t),i=t.popClip,o=t.popLayer;return u=>s=>a=>c=>e.bind(t.pushLayer(Dx))(()=>e.bind(t.pushClip(rJ(s)(a)(c))(Fx))(()=>e.bind(u.wobble?n(!0)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke):r(!1)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke))(()=>e.bind(i)(()=>o))))},dJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=rn(r);return o=>u=>s=>a=>c=>f=>{const d=po(f).length,l=rt(d+1|0),_=p=>{const y=(s*l-rt(p))/1.5,x=y<0?0:y>1?1:y;return x*x*(3-2*x)},h=(p=>{let y=p,x=!0,N;for(;x;){const v=y;if(v>=d){x=!1,N=v;continue}if(_(v)>=1){y=v+1|0;continue}x=!1,N=v}return N})(0),m=h>=d?[]:or(p=>_(p)>0)(It(h,d-1|0)).init;return n.bind((()=>{const p=t.drawText({x:a,y:c,content:me(h)(f),font:o,color:u,align:Us,baseline:Wr});return h>0?p:r.pure()})())(()=>i(p=>n.bind(t.measureText(o)(me(p)(f)))(y=>{const x=_(p);return t.drawText({x:a+y,y:c-(1-x)*10,content:me(1)(ci(Xn(me(p)(f)))(f)),font:o,color:{...u,a:de(dn(x*rt(u.a)))},align:Us,baseline:Wr})}))(m))}},au=t=>e=>n=>r=>{const i=H(_=>rt(uu(1)(po(_).length)))(r),o=Bi(1)(J(Tr)(0)(i)),u=Hr(e)(n)(t),s=u*o,a=uu(1)(r.length),c=(_=>h=>m=>{let p=_,y=h,x=m,N=!0,v;for(;N;){const k=p,L=y,E=Ft(B=>T,B=>V=>w("Just",{head:B,tail:V}),x);if(E.tag==="Nothing"){N=!1,v=uu(0)(a-1|0);continue}if(E.tag==="Just"){if(L+E._1.head>=s){N=!1,v=k;continue}p=k+1|0,y=L+E._1.head,x=E._1.tail;continue}g()}return v})(0)(0)(i),f=J(Tr)(0)(c<1?[]:bt(0,c,i)),d=f/o;if(c>=0&&c<i.length){const _=(f+i[c])/o;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(_<=d)return 1;const h=(u-d)/(_-d);return h<0?0:h>1?1:h})()}}const l=(f+1)/o;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(l<=d)return 1;const _=(u-d)/(l-d);return _<0?0:_>1?1:_})()}},lJ=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})(au(r)(0)(0)(H(U1)(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})})},hJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=lJ(t),i=e.Applicative0(),o=rr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>L_(xt(c=>c)(a)))(o(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const c=fe(a._2._1.node)(u.nodes);if(c.tag==="Just")return n.bind(r(c._1)(a._2._1.progress)(a._2._1.labels))(f=>i.pure(w("Just",b(a._1,f))));if(c.tag==="Nothing")return i.pure(T);g()}return i.pure(T)})(We(s.tokens)))},pJ=t=>{const e=t.Monad0();return n=>r=>i=>o=>u=>s=>a=>{const c=G_(n)(r)(i)(o)(u)(s);return e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(au(o)(u)(s)(Tt(a)(aa)).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}))}},mJ=t=>{const e=t.Monad0(),n=e.Bind1(),r=pJ(t),i=e.Applicative0(),o=rr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>L_(xt(c=>c)(a)))(o(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const c=fe(a._2._1.target)(u.nodes),f=fe(a._2._1.source)(u.nodes),d=mr(a._2._1.edge)(u.edges);if(d.tag==="Just"&&f.tag==="Just"&&c.tag==="Just")return n.bind(r((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return ke(d._1);g()})())(f._1)(c._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(l=>i.pure(w("Just",b(a._1,l))))}return i.pure(T)})(We(s.tokens)))},ca=t=>{const e=t.Monad0(),n=e.Bind1(),r=mJ(t),i=hJ(t);return o=>u=>n.bind(r(o)(u))(s=>n.bind(i(o)(u))(a=>e.Applicative0().pure(nJ((()=>{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)(kt(Re.foldr,c(s)))})())(s)([...xt(c=>{const f=fe(c._1)(u.nodes);return f.tag==="Just"&&Zo(f._1).alpha>0?w("Just",{x:c._2.x,y:c._2.y,w:c._2.w,h:c._2.h}):T})(We(o.nodes)),...(()=>{const c=(f,d)=>{if(f.tag==="Leaf")return d;if(f.tag==="Node")return c(f._5,Ot("Cons",f._4,c(f._6,d)));g()};return kt($t.foldr,c(a,qt))})()]))))},Q_=t=>e=>n=>{const r=pi(6)(.55)(ou(0)(1)((1-t)/.06)),i=t>.94,o=i&&n>1e-4,u=pi(6)(.55)(ou(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})()}},yJ=t=>{const e=t.Monad0().Bind1(),n=k_(t);return r=>i=>o=>u=>s=>{const a=Q_(u)(0)(0),c={family:r.fontFamily,size:11,weight:500},f=au(u)(0)(0)(Tt(s)(aa));return e.bind(t.measureText(c)(f.line))(d=>{const l=o.x+o.w/2,_=d+28,h=o.y-25.2-14,m=l-_/2,p=[1,l,h+25.2,2,l,o.y],y={x:l,y:h+12.6};return n(a)(l-_/2)(h+25.2)(y)(e.bind(t.drawRoundedRect({x:l-_/2,y:h+1.5,w:_,h:25.2})(6)(w("Just",{color:r.chipShadow,flat:!0}))(T))(()=>e.bind(t.drawRoundedRect({x:m,y:h,w:_,h:25.2})(6)(w("Just",{color:r.chip,flat:!0}))(w("Just",{color:r.chipHairline,width:1,lineJoin:Te,lineCap:fn})))(()=>e.bind(t.strokePath(p)({color:r.chipHairline,width:1,lineJoin:Te,lineCap:fn}))(()=>t.drawText({x:l,y:y.y,content:f.line,font:c,color:r.chipText,align:Xo,baseline:Wr})))))})}},xJ=t=>{const e=k_(t),n=t.Monad0(),r=n.Bind1(),i=rn(n.Applicative0()),o=dJ(t);return u=>s=>a=>c=>f=>d=>l=>_=>h=>{const m=au(f)(d)(l)(Tt(_)(aa)),p=m.line,y=m.phaseInLabel/.45,x=y<0?0:y>1?1:y,N=h.w,v=h.y,k=h.x,L=k+14,E=h.h,B=v+E/2;return e(Q_(f)(d)(l))(k)(v+E)({x:k+N/2,y:B})(r.bind(i(V=>t.fillPath(Ko(V)(1.5))({color:u.trailDot,flat:!0}))(oJ(h)(G_(s)(a)(c)(f)(d)(l))))(()=>r.bind(t.drawRoundedRect({x:k,y:v,w:N,h:E})(3)(w("Just",{color:u.chipPillFill,flat:!0}))(T))(()=>o({family:u.fontFamily,size:11,weight:500})(u.chipPillText)(x)(L)(B)(p))))}},ga=t=>{const e=xJ(t),n=t.Monad0(),r=n.Applicative0(),i=yJ(t),o=n.Bind1(),u=rn(r),s=t.popLayer;return a=>c=>f=>d=>o.bind(t.pushLayer(Qx))(()=>o.bind(u(l=>{if(l._2.tag==="Travelling"){if(l._2._1.labels.length!==0){const _=fe(l._2._1.target)(c.nodes),h=fe(l._2._1.source)(c.nodes),m=mr(l._2._1.edge)(c.edges),p=b_(l._1)(d);if(p.tag==="Just"&&m.tag==="Just"&&h.tag==="Just"&&_.tag==="Just")return e(a)((()=>{if(l._2._1.direction==="Forward")return m._1;if(l._2._1.direction==="Backward")return ke(m._1);g()})())(h._1)(_._1)(l._2._1.progress)(l._2._1.holdPre)(l._2._1.holdPost)(l._2._1.labels)(p._1)}return r.pure()}if(l._2.tag==="Filling"&&l._2._1.labels.length!==0){const _=fe(l._2._1.node)(c.nodes);if(_.tag==="Just")return i(a)(c)(_._1)(l._2._1.progress)(l._2._1.labels);if(_.tag==="Nothing")return r.pure();g()}return r.pure()})(We(f.tokens)))(()=>s))},F_=t=>{const e=ca(t),n=ga(t);return r=>i=>o=>t.Monad0().Bind1().bind(e(i)(o))(u=>n(r)(i)(o)(u))},NJ=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>i=>{const o=i.length-1|0,u=o<1?[]:bt(0,o,i),s=u.length-1|0,a=s>=0&&s<u.length?w("Just",u[s]):T,c=i.length-1|0,f=c>=0&&c<i.length?w("Just",i[c]):T;if(f.tag==="Just"&&a.tag==="Just"){const d=ae(.78)(1.18)(Mi(i)+19|0),l=ae(.4)(.62)(d.prng),_=r.wobble?8.75*l.value:4.375,h=ae(.4)(.62)(l.prng),m=r.wobble?8.75*h.value:4.375,p=f._1.y-a._1.y,y=f._1.x-a._1.x,x=Ee(y*y+p*p),N=p/x,v=-N,k=y/x,L=f._1.x+k*.875,E=f._1.y+N*.875,B=r.wobble?8.75*d.value:8.75,V=L-k*B,et=E-N*B,D=V+v*_,S=et+k*_,Z=[1,L,E,2,V+v*4.375,et+k*4.375,2,V-v*4.375,et-k*4.375,5],X=V-v*m,W=et-k*m,z={color:r.arrowFill,width:2,lineJoin:Te,lineCap:In};return x<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,D,S,2,L,E])(z))(()=>t.strokePath([1,X,W,2,L,E])(z)):t.fillPath(Z)({color:r.arrowFill,flat:!0})}return n.pure()}},JJ=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=rn(n),o=t.popAlpha,u=NJ(t);return s=>a=>c=>f=>{const d=GN(8)(c);if(f.hi<=f.lo)return n.pure();const l=AN(d)(f.lo)(f.hi);if(l.length===0)return n.pure();const _={color:s.edge,width:s.wobble?2:.9375,lineJoin:Te,lineCap:In},h=s.wobble?ae(-10)(4)(Mi(l)).value:0,m=s.wobble?ON(h)(l):l;return r.bind(s.wobble?i(p=>r.bind(t.pushAlpha(p.alpha))(()=>r.bind(t.strokePath(p.path)(_))(()=>o)))((()=>{const p=Mi(l);return m.length<2?[]:qr(sJ)(p)(!1)(m)})()):t.strokePath(bN(l))(_))(()=>{const p=u(s)(m);return f.hi>=.999?p:n.pure()})}},A_=t=>{const e=JJ(t),n=t.Monad0().Applicative0(),r=rn(n);return i=>o=>u=>r(s=>{const a=mr(s._1)(u.edges);if(a.tag==="Just")return e(i)(s._1)(s._2)((()=>{if(a._1.tag==="Retracted")return{lo:0,hi:0};if(a._1.tag==="Extended")return{lo:0,hi:1};if(a._1.tag==="Extending")return{lo:0,hi:a._1._2};if(a._1.tag==="Retracting"){if(a._1._1==="FromSource")return{lo:a._1._2,hi:1};if(a._1._1==="FromTarget")return{lo:0,hi:1-a._1._2};if(a._1._1==="FromBoth")return{lo:a._1._2/2,hi:1-a._1._2/2}}g()})());if(a.tag==="Nothing")return n.pure();g()})(We(o.edges))},TJ=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!Me(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,We(t.edges))}g()},r=J(o=>u=>(o*31|0)+Cn(u)|0)(5381)(Vn(e.frameTitle)),i=o=>{const u=fe(o)(t.nodes);if(u.tag==="Nothing")return!1;if(u.tag==="Just"){const s=u._1;return!Me(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},We(t.edges))}g()};return J(o=>u=>{const s=u._2;return ZN(a=>{if(a.tag==="Nothing")return w("Just",s);if(a.tag==="Just")return w("Just",{t:Bi(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(We(e.tokens))(o=>{if(o._2.tag==="Filling"){const u=o._2._1.node;return[b(u,{t:1,angle:(()=>{const s=xt(a=>(()=>{const c=fe(u)(t.nodes),f=a._2.length-1|0;return f>=0&&f<a._2.length&&c.tag==="Just"&&a._2[f].x>=c._1.x&&a._2[f].x<=c._1.x+c._1.w&&a._2[f].y>=c._1.y&&a._2[f].y<=c._1.y+c._1.h})()?w("Just",a._2):T)(We(t.edges));if(0<s.length){const a=s[0].length-1|0,c=a<1?[]:bt(0,a,s[0]),f=c.length-1|0;if(f>=0&&f<c.length){const d=s[0].length-1|0;return d>=0&&d<s[0].length?ur(s[0][d].y-c[f].y)(s[0][d].x-c[f].x):0}s[0].length-1|0}return 0})(),bigCircle:n(u)||i(u),frameHash:r})]}if(o._2.tag==="Travelling"){if(o._2._1.progress>=.75)return[b(o._2._1.target,{t:(o._2._1.progress-.75)/.25,angle:(()=>{const u=mr(o._2._1.edge)(t.edges);if(u.tag==="Just"){const s=u._1.length-1|0,a=s<1?[]:bt(0,s,u._1),c=a.length-1|0;if(c>=0&&c<a.length){const f=u._1.length-1|0;return f>=0&&f<u._1.length?ur(u._1[f].y-a[c].y)(u._1[f].x-a[c].x):0}return u._1.length-1|0,0}if(u.tag==="Nothing")return 0;g()})(),bigCircle:n(o._2._1.target)||i(o._2._1.target),frameHash:r})];if(o._2._1.progress<.25)return[b(o._2._1.source,{t:o._2._1.progress/.25,angle:(()=>{const u=mr(o._2._1.edge)(t.edges);if(u.tag==="Just")return 1<u._1.length&&0<u._1.length?ur(u._1[1].y-u._1[0].y)(u._1[1].x-u._1[0].x):0;if(u.tag==="Nothing")return 0;g()})(),bigCircle:n(o._2._1.source)||i(o._2._1.source),frameHash:r})]}return[]}))},vJ=t=>J(e=>n=>(e*31|0)+Cn(n)|0)(5381)(Vn(t.frameTitle)),M_=t=>{const e=S_(t),n=t.Monad0().Applicative0(),r=rn(n);return i=>o=>u=>s=>{const a=vJ(s),c=TJ(u)(s);return r(f=>{const d=fe(f._1)(s.nodes);if(d.tag==="Just")return e(i)(o)((()=>{const l=fe(f._1)(s.nodeFadeAlpha);if(l.tag==="Nothing")return 1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=fe(f._1)(c);return l.tag==="Just"?w("Just",l._1):l.tag==="Nothing"&&KN(f._1)(s.visited)?w("Just",{t:1,angle:0,bigCircle:!1,frameHash:a}):T})())(f._1)(f._2)(d._1);if(d.tag==="Nothing")return n.pure();g()})(We(u.nodes))}},B_=t=>t,z_=t=>e=>{const n=e.vw/e.vh,r=e.vh*t,i={...e,vx:e.vx-(r-e.vw)/2,vw:r},o=e.vw/t,u={...e,vy:e.vy-(o-e.vh)/2,vh:o};return t<=0||e.vw<=0||e.vh<=0?e:t>n?i:t<n?u:e},wJ=t=>e=>n=>{const r=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()},R_=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},W_=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},fa=t=>e=>{const n=st.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=w("Just",o._4);continue}}g()}return i},LJ=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},kJ=t=>e=>{const n=Oe(t.angle),r=Ke(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},EJ=t=>[t.box.ground.a,t.box.ground.b,t.box.ground.c,t.box.ground.d,t.box.top.a,t.box.top.b,t.box.top.c,t.box.top.d],$r=t=>e=>{const n=r=>wJ(0)(255)(de($n(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)*Ke(t.angle),y:(e+n)*Oe(t.angle)-r}),yr=t=>{const e=Ft(n=>T,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Tt(e._1.tail)(n=>[2,n.x,n.y]),5];g()},GJ=t=>e=>n=>r=>i=>{const o=(()=>{if(t==="Forward")return i;if(t==="Backward")return ke(i);g()})();if(0<o.length){const s=vr(o)(R_(0)(1)(Hr(n)(r)(e)));if(s.tag==="Nothing")return o[0];if(s.tag==="Just")return s._1;g()}const u=vr(o)(R_(0)(1)(Hr(n)(r)(e)));if(u.tag==="Nothing")return{x:0,y:0};if(u.tag==="Just")return u._1;g()},CJ=t=>{const e=Ft(n=>T,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Tt(e._1.tail)(n=>[2,n.x,n.y])];g()},SJ=t=>{const e=Ft(n=>T,n=>r=>w("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{vx:0,vy:0,vw:0,vh:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:W_(r.minX)(i.x),minY:W_(r.minY)(i.y),maxX:fa(r.maxX)(i.x),maxY:fa(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()},DJ=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>{const o=i.box,u=i.np,s={color:r.nodeStroke,width:1,lineJoin:Te,lineCap:fn};return e.bind(t.fillStrokePath(yr([o.ground.d,o.ground.c,o.top.c,o.top.d]))({color:$r(.66)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(yr([o.ground.b,o.ground.c,o.top.c,o.top.b]))({color:$r(.82)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(yr([o.top.a,o.top.b,o.top.c,o.top.d]))({color:$r(1)(r.nodeFill),flat:!0})(s))(()=>t.drawTextAffine(kJ(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:Xo,baseline:Wr}))))}},PJ=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>o=>{const u={color:r.tokenOutsideStroke,width:1,lineJoin:Te,lineCap:fn},s=o.x-5.5,a=o.x+5.5,c=o.y-5.5,f=o.y+5.5,d=i+11,l=Ce(n)(s)(c)(d),_=Ce(n)(a)(c)(d),h=Ce(n)(a)(f)(d),m=Ce(n)(s)(f)(d),p=Ce(n)(a)(f)(i),y=Ce(n)(a)(c)(i);return e.bind(t.fillStrokePath(yr([Ce(n)(s)(f)(i),p,h,m]))({color:$r(.66)(r.tokenOutsideFill),flat:!0})(u))(()=>e.bind(t.fillStrokePath(yr([y,p,h,_]))({color:$r(.82)(r.tokenOutsideFill),flat:!0})(u))(()=>t.fillStrokePath(yr([l,_,h,m]))({color:$r(1)(r.tokenOutsideFill),flat:!0})(u)))}},IJ=t=>{const e=PJ(t);return n=>r=>i=>o=>{if(o.tag==="Travelling"){const u=bJ(o._1.edge)(i.edges);return u.tag==="Just"?w("Just",(()=>{const s=GJ(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=LJ(o._1.node)(i.nodes);if(u.tag==="Just")return w("Just",(()=>{const s={x:u._1.x+u._1.w/2,y:u._1.y+u._1.h/2};return{depth:s.x+s.y,draw:e(n)(r)(n.boxHeight)(s)}})())}return T}},QJ={angle:.5235987755982988,boxHeight:26,transparentBg:!0},FJ=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:Ce(t)(e.x)(e.y)(0),b:Ce(t)(r)(e.y)(0),c:Ce(t)(r)(n)(0),d:Ce(t)(e.x)(n)(0)},top:{a:Ce(t)(e.x)(e.y)(t.boxHeight),b:Ce(t)(r)(e.y)(t.boxHeight),c:Ce(t)(r)(n)(t.boxHeight),d:Ce(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},H_=t=>e=>H(n=>({np:n,box:FJ(t)(n)}))((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._4,n(r._6,i)));g()};return kt($t.foldr,n(e.nodes,qt))})()),AJ=t=>e=>[...Tt(H_(t)(e))(EJ),...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._4,n(r._6,i)));g()};return Tt(kt($t.foldr,n(e.edges,qt)))(H(r=>Ce(t)(r.x)(r.y)(0)))})()],MJ=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=fa(1e-4)(Ee(n*n+e*e)),i=e/r,o=n/r,u=t.to.y-i*7,s=t.to.x-o*7;return yr([t.to,{x:s-i*3,y:u+o*3},{x:s+i*3,y:u-o*3}])},BJ=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(CJ([c,a]))({color:i.edge,width:1.5,lineJoin:Te,lineCap:In}))(()=>{const f=t.fillPath(MJ({from:c,to:a}))({color:i.arrowFill,flat:!0});return o?f:n.pure()})}},zJ=t=>{const e=BJ(t);return n=>r=>i=>{const o=Je(Hn,i,bt(1,i.length,i)),u=o.length-1|0;return Qt(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)}},RJ=t=>{const e=DJ(t),n=IJ(t),r=zJ(t),i=t.Monad0(),o=D_(t),u=Nu(i.Applicative0())(Bt);return s=>a=>c=>f=>{const d=ua(a),l=[...(()=>{const _=(h,m)=>{if(h.tag==="Leaf")return m;if(h.tag==="Node")return _(h._5,Ot("Cons",h._4,_(h._6,m)));g()};return Tt(kt($t.foldr,_(c.edges,qt)))(r(s)(d))})(),...H(_=>({depth:_.box.depth,draw:e(s)(d)(_)}))(H_(s)(c)),...xt(n(s)(d)(c))((()=>{const _=(h,m)=>{if(h.tag==="Leaf")return m;if(h.tag==="Node")return _(h._5,Ot("Cons",h._4,_(h._6,m)));g()};return kt($t.foldr,_(f.tokens,qt))})())];return i.Bind1().bind(o(d)(s.transparentBg)(1)(SJ(AJ(s)(c))))(()=>u(_=>_.draw)(Lt(_=>h=>st.compare(_.depth)(h.depth))(l)))}},O_=(t,e)=>({tag:t,_1:e}),WJ=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},HJ=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},OJ=O_("ResolvedLabels"),qJ=t=>{const e=Zt(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return vo(t);g()},$J=t=>e=>n=>{const r=n.frameTitle===""?0:40,i=Yu(e)(n.camera);return(()=>{if(t.outputAspect.tag==="Nothing")return B_;if(t.outputAspect.tag==="Just")return z_(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})},YJ=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=WJ(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()},VJ=t=>{const e=t.Monad0(),n=e.Bind1();return r=>i=>{if(r==="")return e.Applicative0().pure();const o=i.vh/720,u=15*o,s={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:600};return n.bind(t.measureText(s)(r))(a=>{const c=i.vy+12*o,f=u+6*o*2,d=a+11*o*2,l=i.vx+i.vw/2;return n.bind(t.drawRoundedRect({x:l-d/2,y:c,w:d,h:f})(f/2)(w("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}))(w("Just",{color:{r:0,g:0,b:0,a:255},width:1*o,lineJoin:Te,lineCap:In})))(()=>t.drawText({x:l,y:c+f/2,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:Xo,baseline:Wr}))})}},XJ=t=>{const e=F_(t),n=ga(t),r=t.Monad0(),i=r.Bind1(),o=D_(t),u=r.Applicative0(),s=A_(t),a=M_(t)(oa),c=gJ(t),f=I_(t),d=P_(t),l=VJ(t);return _=>h=>m=>p=>y=>x=>N=>{const v=ua(_.theme),k=(()=>{if(N.tag==="ResolvedLabels")return e(v)(y)(x);if(N.tag==="SpringLabels")return n(v)(y)(x)(N._1);g()})();return i.bind(o(v)(_.transparentBg)(h)(p))(()=>i.bind((()=>{const L=i.bind(s(v)(y)(x))(()=>i.bind(a(v)(y)(x))(()=>i.bind(c(v)(y)(x))(()=>i.bind(f(v)(p)(y)(x))(()=>i.bind(d(zx)(v)(y)(x))(()=>k)))));return m?L:u.pure()})())(()=>i.bind(_.watermark===""?t.Monad0().Applicative0().pure():t.drawText({x:p.vx+6,y:p.vy+6,content:_.watermark,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:Us,baseline:Sx}))(()=>l(x.frameTitle)(p))))}},UJ=t=>{const e=t.Monad0(),n=F_(t),r=ga(t),i=e.Bind1(),o=A_(t),u=M_(t),s=I_(t),a=t.popTransform,c=P_(t),f=t.popBakedTransform,d=t.popClip,l=t.popAlpha;return _=>h=>m=>p=>y=>{const x=y.state,N={tx:y.segment.placement.tx,ty:y.segment.placement.ty,sx:y.segment.placement.scale,sy:y.segment.placement.scale},v=ua(_.theme),k=y.segment.layout,L=Ye(k),E={vx:L.x-1e3,vy:L.y-1e3,vw:L.w+2e3,vh:L.h+2e3},B=11*y.segment.placement.scale*h>=5?oa:tJ,V=(()=>{if(B==="LabelsHidden")return e.Applicative0().pure();if(B==="LabelsShown")return m.tag==="Leaf"?n(v)(k)(x):r(v)(k)(x)(m);g()})(),et=YJ(p)((()=>{const D=y.segment.path.length-1|0;return D>=0&&D<y.segment.path.length?w("Just",y.segment.path[D]):T})());return i.bind(t.pushAlpha(y.bgAlpha))(()=>i.bind(t.pushClip(et)(js))(()=>i.bind(t.pushTransform(N))(()=>i.bind(o(v)(k)(x))(()=>i.bind(u(B)(v)(k)(x))(()=>i.bind(s(v)(E)(k)(x))(()=>i.bind(a)(()=>i.bind(t.pushBakedTransform(N))(()=>i.bind(c(Rx)(v)(k)(x))(()=>i.bind(f)(()=>i.bind(t.pushTransform(N))(()=>i.bind(V)(()=>i.bind(a)(()=>i.bind(d)(()=>l))))))))))))))}},jJ=t=>e=>{const n=Yu(t)(e);return{vx:n.x,vy:n.y,vw:n.w,vh:n.h}},Yr=t=>e=>e.diving||e.levels.length>1?(()=>{if(t.outputAspect.tag==="Nothing")return B_;if(t.outputAspect.tag==="Just")return z_(t.outputAspect._1);g()})()(jJ(e.rootLayout)(e.camera)):$J(t)(e.rootLayout)({...vo(e).state,camera:e.camera}),q_=t=>{const e=RJ(t),n=t.Monad0(),r=n.Applicative0(),i=n.Bind1(),o=UJ(t),u=XJ(t);return s=>a=>c=>{if(s.theme==="Isometric")return e({...QJ,transparentBg:s.transparentBg})(s.theme)(vo(c).segment.layout)(vo(c).state);const f=Yr(s)(c),d=_=>h=>{if(h.length===0)return r.pure();const m=Ft(p=>T,p=>y=>w("Just",{head:p,tail:y}),h);if(m.tag==="Nothing")return r.pure();if(m.tag==="Just"){const p=m._1.head,y=m._1.tail;return i.bind((()=>{const x=o(s)(c.camera.zoom)(p.role==="Active"?a:Q)(_)(p);return c.diving||p.role==="Active"?x:r.pure()})())(()=>d(p)(y))}g()},l=Ft(_=>T,_=>h=>w("Just",{head:_,tail:h}),c.levels);if(l.tag==="Nothing")return r.pure();if(l.tag==="Just"){const _=l._1.tail,h=l._1.head;return i.bind(u(s)(c.hasDives?f.vw/HJ(1)(Ye(c.rootLayout).w):1)(h.role==="Active"||h.role==="FlyThrough")(f)(h.segment.layout)(qJ(c).state)(_.length===0&&a.tag!=="Leaf"?O_("SpringLabels",a):OJ))(()=>d(h)(_))}g()}},$_=t=>e=>n=>{const r=st.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=st.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},ZJ=ca(i_),Y_=q_(i_),V_=t=>{const e=t.vx+t.vw-4,n=t.vy+t.vh-4,r=t.vx+4,i=t.vy+4,o=u=>{if(u.tag==="Leaf")return Q;if(u.tag==="Node")return Wt("Node",u._1,u._2,u._3,{...u._4,x:$_(r)(e-u._4.w)(u._4.x),y:$_(i)(n-u._4.h)(u._4.y)},o(u._5),o(u._6));g()};return o},KJ=t=>e=>n=>r=>i=>o=>u=>{const s={padding:8,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?T:w("Just",r.width/r.height)},a=eN(n)(r);return()=>{const c=a(),f=i.levels.length-1|0;if(f>=0&&f<i.levels.length){const l=ZJ(i.levels[f].segment.layout)(i.levels[f].state)(c)(),_=Vs(o)(V_(Yr(s)(i))(l))(u);return Y_(s)(_.applied)(i)(c)(),_.springs}const d=Vs(o)(V_(Yr(s)(i))(Q))(u);return Y_(s)(d.applied)(i)(c)(),d.springs}},tT=t=>t,eT=(t=>t)("Light"),nT=tT("TransparentBackground"),er=t=>"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")",bn=oi(ri("Fixed",ii(0)(20)(4))),rT=t=>"translate("+bn(t.tx)+","+bn(t.ty)+") scale("+bn(t.sx)+","+bn(t.sy)+")",wt=oi(ri("Fixed",ii(0)(20)(2))),_a=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,i=r>=0&&r<t.length?w("Just",t[r]):T;if(i.tag==="Nothing"){n=t.length;continue}if(i.tag==="Just"){if(i._1===1){e.push("M"),e.push(wt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===2){e.push("L"),e.push(wt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===3){e.push("Q"),e.push(wt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),n=r+5|0;continue}if(i._1===4){e.push("C"),e.push(wt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+5|0;return o>=0&&o<t.length?t[o]:0})())),e.push(wt((()=>{const o=r+6|0;return o>=0&&o<t.length?t[o]:0})())),n=r+7|0;continue}if(i._1===5){e.push("Z"),n=r+1|0;continue}n=t.length;continue}g()}return lo(" ")(e)},iT={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},da=(()=>{const t=jn("&")("&amp;"),e=jn("<")("&lt;"),n=(()=>{const r=jn(">")("&gt;"),i=(()=>{const o=jn('"')("&quot;");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),oT=t=>{if(t.style==="RunText")return"<tspan>"+da(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+da(t.text)+"</tspan>";g()},Qe=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},uT=t=>e=>{const n=[];let r=0;const i=o=>{const u=o>=0&&o<e.length?t.sx*e[o]+t.tx:t.sx*0+t.tx;return()=>{n.push(u),n.push((()=>{const s=o+1|0;return s>=0&&s<e.length?t.sy*e[s]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const o=r,u=o>=0&&o<e.length?w("Just",e[o]):T;if(u.tag==="Nothing"){r=e.length;continue}if(u.tag==="Just"){if(u._1===1){n.push(u._1),i(o+1|0)(),r=o+3|0;continue}if(u._1===2){n.push(u._1),i(o+1|0)(),r=o+3|0;continue}if(u._1===3){n.push(u._1),i(o+1|0)(),i(o+3|0)(),r=o+5|0;continue}if(u._1===4){n.push(u._1),i(o+1|0)(),i(o+3|0)(),i(o+5|0)(),r=o+7|0;continue}if(u._1===5){n.push(u._1),r=o+1|0;continue}r=e.length;continue}g()}return n},cu=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return uT(r._1)(e);g()}},X_={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>iT},sT={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>X_},aT={pure:t=>e=>()=>t,Apply0:()=>X_},cT={Applicative0:()=>aT,Bind1:()=>sT},gT=t=>e=>'<defs><pattern id="'+t+'" x="0" y="0" width="'+wt(e.tile)+'" height="'+wt(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+wt(e.tile)+'" height="'+wt(e.tile)+'" fill="'+er(e.bgColor)+'" fill-opacity="'+wt(rt(e.bgColor.a)/255)+'"/>')+'<circle cx="'+wt(e.tile/2)+'" cy="'+wt(e.tile/2)+'" r="'+wt(e.dotRadius)+'" fill="'+er(e.dotColor)+'"/></pattern></defs><rect x="'+wt(e.viewport.vx)+'" y="'+wt(e.viewport.vy)+'" width="'+wt(e.viewport.vw)+'" height="'+wt(e.viewport.vh)+'" fill="url(#'+t+')"/>',U_=t=>e=>'<path d="'+_a(t)+'" fill="'+er(e)+'" fill-opacity="'+wt(rt(e.a)/255)+'"/>',fT=t=>e=>n=>r=>'<rect x="'+wt(t.x)+'" y="'+wt(t.y)+'" width="'+wt(t.w)+'" height="'+wt(t.h)+'" rx="'+wt(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+er(n._1.color)+'" fill-opacity="'+wt(rt(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';g()})()+(()=>{if(r.tag==="Just")return' stroke="'+er(r._1.color)+'" stroke-opacity="'+wt(rt(r._1.color.a)/255)+'" stroke-width="'+wt(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";g()})()+'"';if(r.tag==="Nothing")return"";g()})()+"/>",j_=t=>e=>'<path d="'+_a(t)+'" fill="none" stroke="'+er(e.color)+'" stroke-opacity="'+wt(rt(e.color.a)/255)+'" stroke-width="'+wt(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";g()})()+'"/>',Z_=t=>{const e=tg(Pr(t.content));return'<text x="'+wt(t.x)+'" y="'+wt(t.y)+'"'+(()=>{if(t.baseline==="BaselineTop")return' dy="0.8em"';if(t.baseline==="BaselineMiddle")return' dy="0.32em"';if(t.baseline==="BaselineAlphabetic"||t.baseline==="BaselineBottom")return"";g()})()+' fill="'+er(t.color)+'" fill-opacity="'+wt(rt(t.color.a)/255)+'" font-size="'+wt(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+ie(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";g()})()+'">'+(e.length===1&&e[0].style==="RunText"?da(e[0].text):lo("")(H(oT)(e)))+"</text>"},_T=t=>"matrix("+bn(t.a)+" "+bn(t.b)+" "+bn(t.c)+" "+bn(t.d)+" "+bn(t.e)+" "+bn(t.f)+")",K_={fillPath:t=>e=>n=>{const r=cu(n)(t);return()=>{const i=r();return Qe(U_(i)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=cu(n)(t);return()=>{const i=r(),o=n.bake.value;return Qe(j_(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=cu(r)(t);return()=>{const o=i(),u=r.bake.value;return Qe(U_(o)(e.color)+j_(o)((()=>{if(u.tag==="Nothing")return n;if(u.tag==="Just")return{...n,width:u._1.sx*n.width};g()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>i=>{const o=i.bake;return()=>{const u=o.value;return Qe(fT((()=>{if(u.tag==="Nothing")return t;if(u.tag==="Just")return{x:u._1.sx*t.x+u._1.tx,y:u._1.sy*t.y+u._1.ty,w:u._1.sx*t.w,h:u._1.sy*t.h};g()})())((()=>{if(u.tag==="Nothing")return e;if(u.tag==="Just")return u._1.sx*e;g()})())(n)(r.tag==="Just"?w("Just",(()=>{if(u.tag==="Nothing")return r._1;if(u.tag==="Just")return{...r._1,width:u._1.sx*r._1.width};g()})()):T))(i)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return Qe(Z_((()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return{...t,x:r._1.sx*t.x+r._1.tx,y:r._1.sy*t.y+r._1.ty,font:{...t.font,size:r._1.sx*t.font.size}};g()})()))(e)()}},drawTextAffine:t=>e=>Qe((()=>{const n='transform="'+_T(t)+'"';return(n===""?"<g>":"<g "+n+">")+Z_(e)+"</g>"})()),pushTransform:t=>Qe((()=>{const e='transform="'+rT(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:Qe("</g>"),pushBakedTransform:t=>e=>{const n=e.bake;return()=>{n.value=w("Just",t)}},popBakedTransform:t=>{const e=t.bake;return()=>{e.value=T}},pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const i=r.value;n.clipCounter.value=i+1|0;const o=cu(n)(t)(),u="clip"+ie(i);return Qe((()=>{const s='clip-path="url(#'+u+')"';return'<defs><clipPath id="'+u+'"><path d="'+_a(o)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";g()})()+"/></clipPath></defs>"+(s===""?"<g>":"<g "+s+">")})())(n)()}},popClip:Qe("</g>"),pushBlend:t=>Qe((()=>{const e=(()=>{if(t==="Normal")return'style="mix-blend-mode: normal"';if(t==="Difference")return'style="mix-blend-mode: difference"';g()})();return e===""?"<g>":"<g "+e+">"})()),popBlend:Qe("</g>"),pushAlpha:t=>Qe((()=>{const e='opacity="'+wt(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:Qe("</g>"),pushLayer:t=>e=>{const n=(()=>{if(t==="LayerNodeMask"){const r=e.maskDepth;return()=>{const i=r.value;e.maskDepth.value=i+1|0}}return()=>{}})();return()=>{n(),e.out.push("<g>")}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;n>0&&(t.maskDepth.value=r),t.out.push("</g>")}},setViewport:t=>e=>()=>{},clearBackground:t=>e=>Qe('<rect x="'+wt(e.viewport.vx)+'" y="'+wt(e.viewport.vy)+'" width="'+wt(e.viewport.vw)+'" height="'+wt(e.viewport.vh)+'" fill="'+er(t)+'" opacity="'+wt(rt(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,Qe(gT("bg-dots-"+ie(r))(t))(e)()}},measureText:t=>e=>n=>{const r=If(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Qf(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Of,Monad0:()=>cT},dT=q_(K_),lT=ca(K_),hT=t=>e=>n=>r=>i=>{const o={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:n,outputAspect:t},u=Yr(o)(i);return{viewBox:wt(u.vx)+" "+wt(u.vy)+" "+wt(u.vw)+" "+wt(u.vh),body:(()=>{const s=[],a={value:0},c={value:0},f={value:0},d={value:T};return dT(o)(e)(i)({out:s,maskDepth:a,clipCounter:c,patternCounter:f,viewport:u,bake:d})(),lo("")(s)})(),vx:u.vx,vy:u.vy,vw:u.vw,vh:u.vh}},pT=t=>e=>n=>r=>i=>o=>{const u={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;g()})(),outputAspect:t},s=Vs(i)((()=>{const a=[],c={value:0},f={value:0},d={value:0},l={value:T},_=r.levels.length-1|0;return _>=0&&_<r.levels.length?lT(r.levels[_].segment.layout)(r.levels[_].state)({out:a,maskDepth:c,clipCounter:f,patternCounter:d,viewport:Yr(u)(r),bake:l})():Q})())(o);return{parts:hT(t)(s.applied)(e)(n)(r),springs:s.springs}},zi=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(i=>n(i._1)(i._2)),Apply0:()=>t1(t)}),t1=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>i=>o=>e.map(u=>b(r(u._1),u._2))(i(o))};return{apply:(()=>{const r=zi(t);return i=>o=>r.bind(i)(u=>r.bind(o)(s=>Ri(t).pure(u(s))))})(),Functor0:()=>n}},Ri=t=>({pure:e=>n=>t.Applicative0().pure(b(e,n)),Apply0:()=>t1(t)}),mT=t=>{const e={Applicative0:()=>Ri(t),Bind1:()=>zi(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},la=(t,e)=>({tag:t,_1:e}),Mn=(t,e)=>({tag:t,_1:e}),ve=mT(Wn),Rt=zi(Wn),Fe=ve.state(t=>b(t,t)),ue=Ri(Wn),Bn=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},e1=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},gu=Nu(ue)(Bt),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},yT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=w("Just",o._4);continue}}g()}return i},xT=(()=>{const t=qe.unfoldr(e=>{if(e.tag==="Nil")return T;if(e.tag==="Cons")return w("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Ot("Cons",r._3,n(r._6,i)));g()};return n(e,qt)})())})(),NT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},fu=t=>e=>n=>J(r=>i=>t.Bind1().bind(r)(o=>e(o)(i)))(t.Applicative0().pure(n)),JT=J(t=>e=>j(C)(e)()(t))(Q),TT=(()=>{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,Ot("Cons",r._3,n(r._6,i)));g()};return n(e,qt)})())})(),vT=Mn("Exit"),wT=t=>la("Par",t),n1=t=>la("Seq",t),bT=t=>e=>n=>{const r=ir(Yt,T,i=>i._1===t,n);if(r.tag==="Just"){const i=On(Yt,T,r._1,b(t,e),n);if(i.tag==="Nothing")return n;if(i.tag==="Just")return i._1;g()}if(r.tag==="Nothing")return zt(n)(b(t,e));g()},LT=t=>e=>H(n=>n._1===t?b(n._1,{...n._2,label:w("Just",e)}):b(n._1,n._2)),we=t=>ve.state(e=>b(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:w("Just",{msg:t,line:e.currentLine,column:e.currentColumn})};g()})())),kT=t=>Rt.bind(ve.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>Rt.bind(Fe)(e=>{if(e.error.tag==="Just")return ue.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!Bn(t.op._1.id)(e.currNodes))return we("cannot enter node "+t.op._1.id+": does not exist");if(!e1(t.op._1.id)(e.interiorOf))return we("cannot enter node "+t.op._1.id+": it has no `inside` block");if(Be(gn)(t.op._1.id)(e.enterStack))return we("cannot enter node "+t.op._1.id+": already entered");const n=t.op._1;return ve.state(r=>b(void 0,{...r,enterStack:zt(r.enterStack)(n.id),scenes:zt(r.scenes)(ao("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=Vi(e.enterStack);if(n.tag==="Nothing")return we("`exit` without a matching `enter`");if(n.tag==="Just"){const r=n._1.init;return ve.state(i=>b(void 0,{...i,enterStack:r,scenes:zt(i.scenes)(Dl)}))}g()}return ue.pure()}g()})),ET=t=>Rt.bind(Fe)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ie(e.kfCounter);if(Me(i=>i.id===n,e.keyframes))return we("duplicate frame name "+n);const r={...e,keyframes:zt(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges}),kfCounter:e.kfCounter+1|0,currentKf:w("Just",n)};return ve.state(i=>b(void 0,r))}),GT=gu(t=>Rt.bind(Fe)(e=>{if(e.error.tag==="Just")return ue.pure();if(e.error.tag==="Nothing")return e1(t.node)(e.interiorOf)?we("node "+t.node+" has more than one `inside` block"):ve.state(n=>b(void 0,{...n,interiorOf:j(C)(t.node)(t.doc)(n.interiorOf)}));g()})),CT=t=>e=>{const n=e.from+"->"+e.to,r=e.newFrom+"->"+e.newTo,i=St("Left","cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist"),o=zn(n)(t.currEdges)?St("Right",void 0):i;return(()=>{if(o.tag==="Left"){const u=o._1;return s=>St("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(!Bn(e.newFrom)(t.currNodes))return St("Left",u);const s="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo;if(!Bn(e.newTo)(t.currNodes))return St("Left",s);const a="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists";return n!==r&&zn(r)(t.currEdges)?St("Left",a):St("Right",{nextCurrEdges:j(C)(r)()(ni(C)(n)(t.currEdges)),newId:r,newEdge:{id:r,from:{node:e.newFrom,port:T},to:{node:e.newTo,port:T}}})})},r1={graphNodes:[],graphEdges:Q,currNodes:Q,currEdges:Q,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:T,currentLine:0,currentColumn:0,error:T,enterStack:[],interiorOf:Q},i1=t=>e=>Rt.bind(Fe)(n=>{const r="ev-"+ie(n.eventCounter);return Rt.bind((()=>{const i={...n,eventCounter:n.eventCounter+1|0};return ve.state(o=>b(void 0,i))})())(()=>ue.pure({events:[{id:r,kind:e,when:t}],firstId:w("Just",r),lastId:w("Just",r)}))}),ST=t=>e=>{if(e.tag==="Token"){const n=e._1;return Rt.bind(Fe)(r=>{const i=!Bn(n.from)(r.currNodes),o=!Bn(n.to)(r.currNodes);if(i||o)return Rt.bind(we(i?o?"token references unknown node: "+n.from+", "+n.to:"token references unknown node: "+n.from:o?"token references unknown node: "+n.to:"token references unknown node: "))(()=>ue.pure({events:[],firstId:T,lastId:T}));const u=n.to+"->"+n.from,s=n.from+"->"+n.to;return zn(s)(r.currEdges)?i1(t)(_c("SendToken",{from:n.from,to:n.to,edge:s,direction:Cl,labels:n.labels})):zn(u)(r.currEdges)?i1(t)(_c("SendToken",{from:n.from,to:n.to,edge:u,direction:Sl,labels:n.labels})):Rt.bind(we("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>ue.pure({events:[],firstId:T,lastId:T}))})}return ue.pure({events:[],firstId:T,lastId:T})},DT=t=>e=>{if(0<t.length){const n=t[0];return Rt.bind(ve.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>we(e))}return we(e)},PT=t=>xt(e=>yT(e)(t.graphEdges))(kt(Kr,xT(t.currEdges))),IT=t=>e=>{const n=ct(i=>i.from.node===e.id||i.to.node===e.id,PT(t)),r=fu(Pa)(i=>o=>{const u=o.from+"->"+e.id,s=e.id+"->"+o.to,a=o.from+"->"+o.to,c="via "+o.from+" "+o.to+": no edge "+o.from+"\u2192"+e.id;if(!zn(u)(t.currEdges))return St("Left",c);const f="via "+o.from+" "+o.to+": no edge "+e.id+"\u2192"+o.to;if(!zn(s)(t.currEdges))return St("Left",f);const d="via "+o.from+" "+o.to+": would create "+o.from+"\u2192"+o.to+" but it already exists";return zn(a)(t.currEdges)||NT(a)(i.synthesized)?St("Left",d):St("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}})(i.synthesized)})})({consumed:Q,synthesized:Q})(e.via);return(()=>{if(r.tag==="Left"){const i=r._1;return o=>St("Left",i)}if(r.tag==="Right"){const i=r._1;return o=>o(i)}g()})()(i=>{const o=i.consumed,u=ct(s=>!zn(s.id)(o),n);return u.length===0?St("Right",{nextCurrEdges:Ge(C.compare,Le,Gn(C.compare,t.currEdges,JT(H(s=>s.id)(n))),TT((()=>{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}):St("Left","cannot delete node "+e.id+": still connected ("+lo(", ")(H(s=>s.from.node+"\u2192"+s.to.node)(u))+"). Use -edge to drop them or `via a b` to merge "+e.id+"'s endpoints.")})},o1=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq")return Tt(t._1)(o1);g()},QT=Rt.bind(Fe)(t=>{if(t.error.tag==="Just")return ue.pure();if(t.error.tag==="Nothing"){const e=t.enterStack.length-1|0;return e>=0&&e<t.enterStack.length?we("entered node "+t.enterStack[e]+" was never exited"):ue.pure()}g()}),FT=t=>({nodes:H($i)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Ot("Cons",n._4,e(n._6,r)));g()};return kt($t.foldr,e(t.graphEdges,qt))})(),constraints:[]}),AT=t=>{if(t.tag==="AddNode"){const e=t._1;return ve.state(n=>b(void 0,{...n,graphNodes:bT(e.id)({id:e.id,size:b(1,1),ports:[],label:w("Just",e.label),shape:e.shape})(n.graphNodes),currNodes:j(C)(e.id)()(n.currNodes)}))}if(t.tag==="DelNode"){const e=t._1;return Rt.bind(Fe)(n=>{if(!Bn(e.id)(n.currNodes))return we("cannot delete node "+e.id+": does not exist");const r=IT(n)(e);if(r.tag==="Left")return we(r._1);if(r.tag==="Right"){const i=r._1;return ve.state(o=>b(void 0,{...o,currNodes:ni(C)(e.id)(o.currNodes),currEdges:i.nextCurrEdges,graphEdges:Ge(C.compare,Le,i.synthesized,o.graphEdges)}))}g()})}if(t.tag==="ModNode"){const e=t._1;return Rt.bind(Fe)(n=>{if(!Bn(e.id)(n.currNodes))return we("cannot modify node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=e.label._1;return ve.state(i=>b(void 0,{...i,graphNodes:LT(e.id)(r)(i.graphNodes)}))}if(e.label.tag==="Nothing")return ue.pure();g()})}if(t.tag==="AddEdge"){const e=t._1;return Rt.bind(Fe)(n=>{const r=!Bn(e.from)(n.currNodes),i=!Bn(e.to)(n.currNodes);if(r||i)return we("cannot add edge "+e.from+"\u2192"+e.to+": unknown node "+(r?i?e.from+", "+e.to:e.from:i?e.to:""));const o=e.from+"->"+e.to;return ve.state(u=>b(void 0,{...u,graphEdges:j(C)(o)({id:o,from:{node:e.from,port:T},to:{node:e.to,port:T}})(u.graphEdges),currEdges:j(C)(o)()(u.currEdges)}))})}if(t.tag==="DelEdge"){const e=t._1;return Rt.bind(Fe)(n=>{const r=e.from+"->"+e.to;return zn(r)(n.currEdges)?ve.state(i=>b(void 0,{...i,currEdges:ni(C)(r)(i.currEdges)})):we("cannot delete edge "+e.from+"\u2192"+e.to+": does not exist")})}if(t.tag==="RepointEdge"){const e=t._1;return Rt.bind(Fe)(n=>{const r=CT(n)(e);if(r.tag==="Left")return we(r._1);if(r.tag==="Right"){const i=r._1;return ve.state(o=>b(void 0,{...o,currEdges:i.nextCurrEdges,graphEdges:j(C)(i.newId)(i.newEdge)(o.graphEdges)}))}g()})}return ue.pure()},MT=t=>Rt.bind(ve.state(e=>b(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>AT(t.op)),BT=t=>e=>Rt.bind(gu(MT)(e))(()=>Rt.bind(Fe)(n=>{const r=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ie(n.kfCounter);if(Me(o=>o.id===r,n.keyframes))return we("duplicate frame name "+r);const i={...n,keyframes:zt(n.keyframes)({id:r,nodes:n.currNodes,edges:n.currEdges}),kfCounter:n.kfCounter+1|0,currentKf:w("Just",r),scenes:(()=>{if(n.currentKf.tag==="Nothing")return n.scenes;if(n.currentKf.tag==="Just")return zt(n.scenes)(ao("Structural",{from:n.currentKf._1,to:r,focus:T}));g()})()};return ve.state(o=>b(void 0,i))})),zT=t=>e=>{const n=Ft(r=>T,r=>i=>w("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return ue.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return Rt.bind(Wi(t)(n._1.head))(i=>Rt.bind(fu({Applicative0:()=>Ri(Wn),Bind1:()=>zi(Wn)})(o=>u=>Rt.bind(Wi((()=>{if(o.lastId.tag==="Just")return qu("After",o.lastId._1);if(o.lastId.tag==="Nothing")return t;g()})())(u))(s=>ue.pure({events:[...o.events,...s.events],firstId:(()=>{if(o.firstId.tag==="Just")return w("Just",o.firstId._1);if(o.firstId.tag==="Nothing")return s.firstId;g()})(),lastId:(()=>{if(s.lastId.tag==="Just")return w("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return o.lastId;g()})()})))(i)(r))(o=>ue.pure(o)))}g()},RT=t=>e=>{const n=Ft(r=>T,r=>i=>w("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return ue.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return Rt.bind(Wi(t)(n._1.head))(i=>Rt.bind(WT((()=>{if(i.firstId.tag==="Just")return qu("With",i.firstId._1);if(i.firstId.tag==="Nothing")return t;g()})())(r))(o=>ue.pure({events:[...i.events,...o.events],firstId:i.firstId,lastId:(()=>{if(i.lastId.tag==="Just")return w("Just",i.lastId._1);if(i.lastId.tag==="Nothing")return o.lastId;g()})()})))}g()},Wi=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return Rt.bind(ve.state(r=>b(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>ST(t)(n.op))}if(e.tag==="Seq")return zT(t)(e._1);if(e.tag==="Par")return RT(t)(e._1);g()},WT=t=>fu({Applicative0:()=>Ri(Wn),Bind1:()=>zi(Wn)})(e=>n=>Rt.bind(Wi(t)(n))(r=>ue.pure({events:[...e.events,...r.events],firstId:(()=>{if(e.firstId.tag==="Just")return w("Just",e.firstId._1);if(e.firstId.tag==="Nothing")return r.firstId;g()})(),lastId:(()=>{if(r.lastId.tag==="Just")return w("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;g()})()})))({events:[],firstId:T,lastId:T}),HT=t=>Rt.bind(Fe)(e=>{if(e.currentKf.tag==="Nothing")return we("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return Rt.bind(Wi(Gl)(t))(r=>Rt.bind(Fe)(i=>{const o={...i,scenes:zt(i.scenes)(ao("DataFlow",{keyframe:n,events:r.events,focus:T}))};return ve.state(u=>b(void 0,o))}))}g()}),OT=t=>Rt.bind(Fe)(e=>{if(e.error.tag==="Just")return ue.pure();if(e.error.tag==="Nothing"){const n=o1(t.ops),r=ct(u=>u.op.tag==="AddNode"||u.op.tag==="DelNode"||u.op.tag==="ModNode"||u.op.tag==="AddEdge"||u.op.tag==="DelEdge"||u.op.tag==="RepointEdge",n),i=ct(u=>u.op.tag==="Enter"||u.op.tag==="Exit",n),o=ct(u=>!(u.op.tag==="AddNode"||u.op.tag==="DelNode"||u.op.tag==="ModNode"||u.op.tag==="AddEdge"||u.op.tag==="DelEdge"||u.op.tag==="RepointEdge")&&!(u.op.tag==="Enter"||u.op.tag==="Exit"),n);return i.length!==0&&o.length!==0?DT(i)("`enter`/`exit` cannot be mixed with flow tokens in the same frame"):Rt.bind((()=>{const u=BT(t.name)(r);return r.length!==0?u:ue.pure()})())(()=>Rt.bind((()=>{const u=ET(t.name);return r.length===0&&o.length!==0?u:ue.pure()})())(()=>Rt.bind((()=>{const u=HT(t.ops);return o.length!==0?u:ue.pure()})())(()=>gu(kT)(i))))}g()}),u1=t=>Rt.bind(GT(t.interiors))(()=>Rt.bind(gu(OT)(t.frames))(()=>Rt.bind(QT)(()=>Rt.bind(Fe)(e=>{if(e.error.tag==="Just")return ue.pure(St("Left",e.error._1));if(e.error.tag==="Nothing"){const n=qT(t.interiors);if(n.tag==="Left")return ue.pure(St("Left",n._1));if(n.tag==="Right")return ue.pure(St("Right",{seed:t.seed,graph:FT(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1}))}g()})))),qT=t=>{const e=fu(Pa)(n=>r=>{const i=u1(r.doc)(r1)._1;return(()=>{if(i.tag==="Left"){const o=i._1;return u=>St("Left",o)}if(i.tag==="Right"){const o=i._1;return u=>u(o)}g()})()(o=>St("Right",j(C)(r.node)(o)(n)))})(Q)(t);if(e.tag==="Left")return St("Left",e._1);if(e.tag==="Right")return St("Right",e._1);g()},Vr=(t,e)=>({tag:"ParseError",_1:t,_2:e}),A=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),_u=(t,e,n)=>({tag:t,_1:e,_2:n}),$T=t=>_u("More",t),YT=t=>_u("Lift",t),VT={defer:t=>{const e=sl(t);return(n,r,i,o,u)=>al(e)(n,r,i,o,u)}},s1={map:t=>e=>(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,c)=>r(f=>u(a,t(c)))))},XT={alt:t=>e=>(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>t(A(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:()=>s1},UT=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(Qa)(c._1);continue}if(c.tag==="Stop"){s=!1,a=e.Applicative0().pure(Zr("Done",b(c._2,c._1)));continue}g()}return a};return t.tailRecM(i)(o=>r(n,$T,YT,(u,s)=>_u("Stop",u,St("Left",s)),(u,s)=>_u("Stop",u,St("Right",s))))}},a1=(t,e,n,r,i)=>i(t,t._2),jT={index:0,line:1,column:1},ZT=(t=>{const e=UT(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(Yi)(e(A(n,jT,!1))(r))})(Q1),c1={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?A(a._1,a._2,!0):a;return e(d,r,i,o,(l,_)=>r(h=>u(d._3&&!l._3?A(l._1,l._2,!0):l,c(_))))}))),Functor0:()=>s1},g1={pure:t=>(e,n,r,i,o)=>o(e,t),Apply0:()=>c1},KT={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?A(a._1,a._2,!0):a,r,i,o,u)))),Apply0:()=>c1},tv={Applicative0:()=>g1,Bind1:()=>KT},du=t=>(e,n,r,i,o)=>n(u=>a1(e,n,r,i,(s,a)=>n(c=>i(e._3&&!s._3?A(s._1,s._2,!0):s,Vr(t,a))))),ev={empty:du("No alternative"),Alt0:()=>XT},nv={Applicative0:()=>g1,Plus1:()=>ev},on=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return i=>t.tailRecM(o=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(Qa)(i))(r.pure(Zr("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return Zr("Loop",Ot("Cons",u._1,o));if(u.tag==="Done")return Zr("Done",(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=Ot("Cons",h._1,_),f=h._2;continue}g()}return l})(qt)(o));g()})())))(qt)})({tailRecM:t=>e=>(n,r,i,o,u)=>{const s=(a,c,f)=>t(c)(a,r,i,o,(d,l)=>{const _=a._3&&!d._3?A(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:()=>tv})(nv),Gt=t=>e=>{const n=du("Expected "+e);return(r,i,o,u,s)=>{const a=r._1,c=r._2;return i(f=>t(A(a,c,!1),i,o,(d,l)=>{const _=d._3;return i(h=>_?u(d,l):n(r,i,o,u,s))},s))}},ha=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(A(d._1,d._2,u),l):o(e,void 0))};return n(d=>n(l=>t(A(s,a,!1),n,r,(_,h)=>f(A(_._1,_._2,!1),h),(_,h)=>n(m=>n(p=>du("Negated parser succeeded")(_,n,r,f,(y,x)=>n(N=>o(_._3&&!y._3?A(y._1,y._2,!0):y,x))))))))})},rv=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return w("Just",n);if(r.tag==="Just")return w("Just",(i,o,u,s,a)=>{const c=i._1,f=i._2;return o(d=>n(A(c,f,!1),o,u,(l,_)=>{const h=l._3;return o(m=>h?s(l,_):r._1(i,o,u,s,a))},a))});g()})(T);return n=>{const r=e(n);if(r.tag==="Nothing")return du("No alternative");if(r.tag==="Just")return r._1;g()}},iv=t=>e=>n=>(r,i,o,u,s)=>i(a=>i(c=>i(f=>i(d=>t(r,i,o,u,(l,_)=>i(h=>i(m=>{const p=r._3&&!l._3?A(l._1,l._2,!0):l;return n(p,i,o,u,(y,x)=>i(N=>{const v=p._3&&!y._3?A(y._1,y._2,!0):y;return i(k=>i(L=>{const E=r._3&&!v._3?A(v._1,v._2,!0):v;return e(E,i,o,u,(B,V)=>i(et=>s(E._3&&!B._3?A(B._1,B._2,!0):B,x)))}))}))}))))))),pa=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=Nh()(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)-Yn(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},ov=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,c=i,f=o,d=ho(c);if(d.tag==="Nothing"){u=!1,s=a;continue}if(d.tag==="Just"){r=d._1.tail===""?pa(a)(d._1.head)(f):pa(a)(d._1.head)(d._1.tail),i=d._1.tail,o=f;continue}g()}return s},jt=t=>(e,n,r,i,o)=>{const u=ho(e._1);if(u.tag==="Nothing")return i(e,Vr("Unexpected EOF",e._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return i(e,Vr("Expected Char",e._2));if(u._1.head>=0&&u._1.head<=65535){const s=Tc(u._1.head);return t(s)?o(A(u._1.tail,pa(e._2)(u._1.head)(u._1.tail),!0),s):i(e,Vr("Predicate unsatisfied",e._2))}}g()},ma=(t,e,n,r,i)=>t._1===""?i(A(t._1,t._2,!0),void 0):r(t,Vr("Expected EOF",t._2)),uv=t=>(e,n,r,i,o)=>{const u=t(e._1);if(u.tag==="Left")return i(e,Vr(u._1,e._2));if(u.tag==="Right")return o(A(u._1.remainder,ov(e._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);g()},Xr=t=>uv(e=>{const n=ul(t)(e);return n.tag==="Just"?St("Right",{value:t,consumed:t,remainder:n._1}):St("Left","Expected "+v1(t))}),sv=jt(t=>!0),f1=(t,e)=>({tag:t,_1:e}),av=Kt(C)(Bt),cv=t=>e=>{let n=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=w("Just",o._4);continue}}g()}return i},_1=rv(Bt),d1=(()=>{const t=jt(e=>e===" "||e===" "||e===`
9
+ `||e==="\r");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?A(s._1,s._2,!0):s,void 0))))})(),ya=(t,e,n,r,i)=>e(o=>Xr("#")(t,e,n,r,(u,s)=>e(a=>{const c=on(jt(d=>d!==`
10
+ `)),f=t._3&&!u._3?A(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>i(f._3&&!l._3?A(l._1,l._2,!0):l,void 0))))}))),gv=Gt((()=>{const t=Gt(jt(n=>n==="}"))("'}'"),e=jt(n=>n===`
11
+ `||n==="\r");return(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>r(f=>t(A(s,a,!1),r,i,(d,l)=>r(_=>{const h=n._1,m=n._2;return r(p=>r(y=>ya(A(h,m,!1),r,i,(x,N)=>{const v=x._3;return r(k=>{if(v)return o(x,N);const L=n._1,E=n._2;return r(B=>r(V=>e(A(L,E,!1),r,i,(et,D)=>{const S=et._3;return r(Z=>S?o(et,D):ma(n,r,i,o,u))},(et,D)=>r(S=>u(et,void 0)))))})},(x,N)=>r(v=>u(x,void 0)))))}),(d,l)=>r(_=>u(A(s,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),Ue=(()=>{const t=on((e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>d1(A(u,s,!1),n,r,(c,f)=>{const d=c._3;return n(l=>d?i(c,f):ya(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?A(s._1,s._2,!0):s,void 0))))})(),cn=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>Ue(t._3&&!c._3?A(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>d1(A(s,a,!1),e,n,(f,d)=>{const l=f._3;return e(_=>l?r(f,d):ya(t,e,n,r,u))},u))}),l1=(()=>{const t=Gt(jt(e=>e==="|"))("'|'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=on(jt(l=>l!=="|")),d=e._3&&!s._3?A(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(m=>{const p=Gt(Gt(jt(x=>x==="|"))("'|'"))("closing '|'"),y=d._3&&!_._3?A(_._1,_._2,!0):_;return n(x=>p(y,n,r,i,(N,v)=>n(k=>o(y._3&&!N._3?A(N._1,N._2,!0):N,cr(kt($t.foldr,h))))))})))})))})(),lu=jt(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),He=(()=>{const t=on(jt(e=>e===" "||e===" "));return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?A(s._1,s._2,!0):s,void 0))))})(),fv=(()=>{const t=Gt(jt(e=>e==="\\"))("'\\\\'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=e._3&&!s._3?A(s._1,s._2,!0):s;return n(d=>sv(f,n,r,i,(l,_)=>n(h=>o(f._3&&!l._3?A(l._1,l._2,!0):l,_==="n"?`
12
+ `:_==="t"?" ":_==="r"?"\r":_))))})))})(),_v=(()=>{const t=jt(e=>e!=='"'&&e!=="\\"&&e!==`
13
+ `);return(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>fv(A(u,s,!1),n,r,(c,f)=>n(d=>t(e,n,r,i,o)),o))}})(),xa=(()=>{const t=Gt(jt(e=>e==='"'))(`'"'`);return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=on(_v),d=e._3&&!s._3?A(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(m=>{const p=Gt(Gt(jt(x=>x==='"'))(`'"'`))(`closing '"' (unterminated string)`),y=d._3&&!_._3?A(_._1,_._2,!0):_;return n(x=>p(y,n,r,i,(N,v)=>n(k=>o(y._3&&!N._3?A(N._1,N._2,!0):N,cr(kt($t.foldr,h))))))})))})))})(),dv=(()=>{const t=Gt(jt(e=>e===":"))("':'");return(e,n,r,i,o)=>n(u=>He(e,n,r,i,(s,a)=>n(c=>Gt((f,d,l,_,h)=>{const m=f._1,p=f._2;return d(y=>{const x=(N,v)=>{const k=N._3;return d(L=>{if(k)return _(N,v);const E=f._1,B=f._2;return d(V=>l1(A(E,B,!1),d,l,(et,D)=>{const S=et._3;return d(Z=>S?_(et,D):xa(f,d,l,_,h))},h))})};return d(N=>t(A(m,p,!1),d,l,x,(v,k)=>d(L=>d(E=>He(v,d,l,x,(B,V)=>d(et=>{const D=on(jt(Z=>Z!==`
14
+ `&&Z!=="\r"&&Z!=="#"&&Z!=="}")),S=v._3&&!B._3?A(B._1,B._2,!0):B;return d(Z=>D(S,d,l,x,(X,W)=>d(z=>h(S._3&&!X._3?A(X._1,X._2,!0):X,ah(cr(kt($t.foldr,W)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(e._3&&!s._3?A(s._1,s._2,!0):s,n,r,i,o))))})(),lv=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>l1(A(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):xa(t,e,n,r,i))},i))},Hi=jt(t=>t>="0"&&t<="9"),be=(()=>{const t=Gt(jt(e=>e==="_"))("'_'");return(e,n,r,i,o)=>n(u=>{const s=(f,d)=>n(l=>{const _=on((()=>{const m=Gt(jt(y=>y==="_"))("'_'"),p=Gt(jt(y=>y==="-"))("'-'");return(y,x,N,v,k)=>{const L=y._1,E=y._2;return x(B=>lu(A(L,E,!1),x,N,(V,et)=>{const D=V._3;return x(S=>{if(D)return v(V,et);const Z=y._1,X=y._2;return x(W=>Hi(A(Z,X,!1),x,N,(z,M)=>{const G=z._3;return x(P=>{if(G)return v(z,M);const I=y._1,F=y._2;return x(O=>m(A(I,F,!1),x,N,(Y,q)=>{const $=Y._3;return x(R=>$?v(Y,q):p(y,x,N,v,k))},k))})},k))})},k))}})()),h=e._3&&!f._3?A(f._1,f._2,!0):f;return n(m=>_(h,n,r,i,(p,y)=>n(x=>o(h._3&&!p._3?A(p._1,p._2,!0):p,ro(d)+cr(kt($t.foldr,y))))))}),a=e._1,c=e._2;return n(f=>lu(A(a,c,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?i(d,l):t(e,n,r,i,s))},s))})})(),hv=Gt((t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>xa(A(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)"),h1=(t,e,n,r,i)=>e(o=>He(t,e,n,r,(u,s)=>e(a=>{const c=Gt(be)("attribute key"),f=t._3&&!u._3?A(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const m=f._3&&!l._3?A(l._1,l._2,!0):l;return e(p=>He(m,e,n,r,(y,x)=>e(N=>{const v=Gt(Gt(jt(L=>L===":"))("':'"))("':'"),k=m._3&&!y._3?A(y._1,y._2,!0):y;return e(L=>v(k,e,n,r,(E,B)=>e(V=>{const et=k._3&&!E._3?A(E._1,E._2,!0):E;return e(D=>He(et,e,n,r,(S,Z)=>e(X=>{const W=Gt(be)("attribute value"),z=et._3&&!S._3?A(S._1,S._2,!0):S;return e(M=>W(z,e,n,r,(G,P)=>e(I=>{const F=z._3&&!G._3?A(G._1,G._2,!0):G;return e(O=>He(F,e,n,r,(Y,q)=>e($=>i(F._3&&!Y._3?A(Y._1,Y._2,!0):Y,b(_,P)))))})))})))})))})))})))}))),pv=(t,e,n,r,i)=>e(o=>be(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?A(u._1,u._2,!0):u;return e(f=>He(c,e,n,r,(d,l)=>e(_=>{const h=Gt((p,y,x,N,v)=>{const k=p._1,L=p._2;return y(E=>Xr("->")(A(k,L,!1),y,x,(B,V)=>{const et=B._3;return y(D=>et?N(B,V):Xr("<-")(p,y,x,N,v))},v))})("'->' or '<-'"),m=c._3&&!d._3?A(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?A(y._1,y._2,!0):y;return e(k=>He(v,e,n,r,(L,E)=>e(B=>{const V=Gt(be)("target node identifier"),et=v._3&&!L._3?A(L._1,L._2,!0):L;return e(D=>V(et,e,n,r,(S,Z)=>e(X=>{const W=on((M,G,P,I,F)=>{const O=M._3;return G(Y=>G(q=>He(M,G,P,($,R)=>I(A($._1,$._2,O),R),($,R)=>G(tt=>G(K=>{const gt=M._3&&!$._3?A($._1,$._2,!0):$;return lv(gt,G,P,(_t,at)=>I(A(_t._1,_t._2,O),at),(_t,at)=>G(yt=>F(gt._3&&!_t._3?A(_t._1,_t._2,!0):_t,at)))})))))}),z=et._3&&!S._3?A(S._1,S._2,!0):S;return e(M=>W(z,e,n,r,(G,P)=>e(I=>(()=>{if(x==="<-"){const O=Mn("Token",{from:Z,to:s,labels:H(ac)(kt($t.foldr,P))});return(Y,q,$,R,tt)=>tt(Y,O)}const F=Mn("Token",{from:s,to:Z,labels:H(ac)(kt($t.foldr,P))});return(O,Y,q,$,R)=>R(O,F)})()(z._3&&!G._3?A(G._1,G._2,!0):G,e,n,r,i))))})))})))})))})))}))),mv=(t,e,n,r,i)=>e(o=>Hi(t,e,n,r,(u,s)=>e(a=>{const c=on(Hi),f=t._3&&!u._3?A(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const m=_d(ro(s)+cr(kt($t.foldr,_)));return(()=>{if(m.tag==="Just"){const p=m._1;return(y,x,N,v,k)=>k(y,p)}if(m.tag==="Nothing")return(p,y,x,N,v)=>v(p,0);g()})()(f._3&&!l._3?A(l._1,l._2,!0):l,e,n,r,i)})))}))),Oi=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>Xr(t)(e,n,r,(a,c)=>i(A(a._1,a._2,u),c),(a,c)=>n(f=>{const d=ha((()=>{const _=Gt(jt(m=>m==="_"))("'_'"),h=Gt(jt(m=>m==="-"))("'-'");return(m,p,y,x,N)=>{const v=m._1,k=m._2;return p(L=>lu(A(v,k,!1),p,y,(E,B)=>{const V=E._3;return p(et=>{if(V)return x(E,B);const D=m._1,S=m._2;return p(Z=>Hi(A(D,S,!1),p,y,(X,W)=>{const z=X._3;return p(M=>{if(z)return x(X,W);const G=m._1,P=m._2;return p(I=>_(A(G,P,!1),p,y,(F,O)=>{const Y=F._3;return p(q=>Y?x(F,O):h(m,p,y,x,N))},N))})},N))})},N))}})()),l=e._3&&!a._3?A(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,m)=>i(A(h._1,h._2,u),m),(h,m)=>n(p=>{const y=l._3&&!h._3?A(h._1,h._2,!0):h;return n(x=>Ue(y,n,r,(N,v)=>i(A(N._1,N._2,u),v),(N,v)=>n(k=>o(y._3&&!N._3?A(N._1,N._2,!0):N,t))))})))})))},yv=(t,e,n,r,i)=>e(o=>cn(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?A(u._1,u._2,!0):u;return e(f=>Oi("via")(c,e,n,r,(d,l)=>e(_=>{const h=c._3&&!d._3?A(d._1,d._2,!0):d;return e(m=>be(h,e,n,r,(p,y)=>e(x=>{const N=h._3&&!p._3?A(p._1,p._2,!0):p;return e(v=>cn(N,e,n,r,(k,L)=>e(E=>{const B=N._3&&!k._3?A(k._1,k._2,!0):k;return e(V=>be(B,e,n,r,(et,D)=>e(S=>i(B._3&&!et._3?A(et._1,et._2,!0):et,{from:y,to:D}))))})))})))})))}))),nr=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>Xr(t)(e,n,r,(a,c)=>i(A(a._1,a._2,u),c),(a,c)=>n(f=>{const d=ha((()=>{const _=Gt(jt(m=>m==="_"))("'_'"),h=Gt(jt(m=>m==="-"))("'-'");return(m,p,y,x,N)=>{const v=m._1,k=m._2;return p(L=>lu(A(v,k,!1),p,y,(E,B)=>{const V=E._3;return p(et=>{if(V)return x(E,B);const D=m._1,S=m._2;return p(Z=>Hi(A(D,S,!1),p,y,(X,W)=>{const z=X._3;return p(M=>{if(z)return x(X,W);const G=m._1,P=m._2;return p(I=>_(A(G,P,!1),p,y,(F,O)=>{const Y=F._3;return p(q=>Y?x(F,O):h(m,p,y,x,N))},N))})},N))})},N))}})()),l=e._3&&!a._3?A(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,m)=>i(A(h._1,h._2,u),m),(h,m)=>n(p=>o(l._3&&!h._3?A(h._1,h._2,!0):h,void 0))))})))},xv=(t,e,n,r,i)=>e(o=>nr("+edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?A(u._1,u._2,!0):u;return e(f=>cn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),m=c._3&&!d._3?A(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?A(y._1,y._2,!0):y;return e(k=>cn(v,e,n,r,(L,E)=>e(B=>{const V=Gt(be)("target node identifier"),et=v._3&&!L._3?A(L._1,L._2,!0):L;return e(D=>V(et,e,n,r,(S,Z)=>e(X=>i(et._3&&!S._3?A(S._1,S._2,!0):S,Mn("AddEdge",{from:x,to:Z})))))})))})))})))}))),Nv=(t,e,n,r,i)=>e(o=>nr("-edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?A(u._1,u._2,!0):u;return e(f=>cn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),m=c._3&&!d._3?A(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?A(y._1,y._2,!0):y;return e(k=>cn(v,e,n,r,(L,E)=>e(B=>{const V=Gt(be)("target node identifier"),et=v._3&&!L._3?A(L._1,L._2,!0):L;return e(D=>V(et,e,n,r,(S,Z)=>e(X=>i(et._3&&!S._3?A(S._1,S._2,!0):S,Mn("DelEdge",{from:x,to:Z})))))})))})))})))}))),Jv=(t,e,n,r,i)=>e(o=>nr("-node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?A(u._1,u._2,!0):u;return e(f=>cn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),m=c._3&&!d._3?A(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=on((L,E,B,V,et)=>{const D=L._3;return yv(L,E,B,(S,Z)=>V(A(S._1,S._2,D),Z),et)}),k=m._3&&!y._3?A(y._1,y._2,!0):y;return e(L=>v(k,e,n,r,(E,B)=>e(V=>i(k._3&&!E._3?A(E._1,E._2,!0):E,Mn("DelNode",{id:x,via:kt($t.foldr,B)})))))})))})))}))),Tv=(t,e,n,r,i)=>e(o=>nr("enter")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?A(u._1,u._2,!0):u;return e(f=>cn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),m=c._3&&!d._3?A(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>i(m._3&&!y._3?A(y._1,y._2,!0):y,Mn("Enter",{id:x})))))})))}))),vv=(t,e,n,r,i)=>e(o=>nr("exit")(t,e,n,r,(u,s)=>e(a=>i(t._3&&!u._3?A(u._1,u._2,!0):u,vT)))),wv=(t,e,n,r,i)=>e(o=>nr("~edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?A(u._1,u._2,!0):u;return e(f=>cn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("source node identifier"),m=c._3&&!d._3?A(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?A(y._1,y._2,!0):y;return e(k=>cn(v,e,n,r,(L,E)=>e(B=>{const V=Gt(be)("target node identifier"),et=v._3&&!L._3?A(L._1,L._2,!0):L;return e(D=>V(et,e,n,r,(S,Z)=>e(X=>{const W=et._3&&!S._3?A(S._1,S._2,!0):S;return e(z=>Ue(W,e,n,r,(M,G)=>e(P=>{const I=Gt(Xr("->"))("'->'"),F=W._3&&!M._3?A(M._1,M._2,!0):M;return e(O=>I(F,e,n,r,(Y,q)=>e($=>{const R=F._3&&!Y._3?A(Y._1,Y._2,!0):Y;return e(tt=>Ue(R,e,n,r,(K,gt)=>e(_t=>{const at=Gt(be)("new source node identifier"),yt=R._3&&!K._3?A(K._1,K._2,!0):K;return e(Et=>at(yt,e,n,r,(At,pt)=>e(Mt=>{const Jt=yt._3&&!At._3?A(At._1,At._2,!0):At;return e(mt=>cn(Jt,e,n,r,(nt,U)=>e(ut=>{const ft=Gt(be)("new target node identifier"),lt=Jt._3&&!nt._3?A(nt._1,nt._2,!0):nt;return e(Nt=>ft(lt,e,n,r,(Ht,Vt)=>e(De=>i(lt._3&&!Ht._3?A(Ht._1,Ht._2,!0):Ht,Mn("RepointEdge",{from:x,to:Z,newFrom:pt,newTo:Vt})))))})))})))})))})))})))})))})))})))})))}))),bv=(t,e,n,r,i)=>e(o=>nr("seed")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?A(u._1,u._2,!0):u;return e(f=>He(c,e,n,r,(d,l)=>e(_=>{const h=Gt(mv)("integer (seed value)"),m=c._3&&!d._3?A(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?A(y._1,y._2,!0):y;return e(k=>Ue(v,e,n,r,(L,E)=>e(B=>i(v._3&&!L._3?A(L._1,L._2,!0):L,x))))})))})))}))),qi=iv((()=>{const t=Gt(jt(e=>e==="{"))("'{'");return(e,n,r,i,o)=>n(u=>n(s=>t(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?A(a._1,a._2,!0):a;return Ue(l,n,r,i,(_,h)=>n(m=>o(l._3&&!_._3?A(_._1,_._2,!0):_,h)))})))))})())(Gt((()=>{const t=Gt(jt(e=>e==="}"))("'}'");return(e,n,r,i,o)=>n(u=>n(s=>Ue(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?A(a._1,a._2,!0):a;return t(l,n,r,i,(_,h)=>n(m=>o(l._3&&!_._3?A(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),Lv=qi((t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>(()=>{if(f.tag==="Nothing")return(l,_,h,m,p)=>p(l,Q);if(f.tag==="Just"){const l=f._1,_=on((()=>{const h=Gt(jt(m=>m===","))("','");return(m,p,y,x,N)=>{const v=m._3;return p(k=>p(L=>p(E=>p(B=>p(V=>p(et=>He(m,p,y,(D,S)=>x(A(D._1,D._2,v),S),(D,S)=>p(Z=>p(X=>{const W=m._3&&!D._3?A(D._1,D._2,!0):D;return h(W,p,y,(z,M)=>x(A(z._1,z._2,v),M),(z,M)=>p(G=>{const P=W._3&&!z._3?A(z._1,z._2,!0):z;return p(I=>p(F=>{const O=m._3&&!P._3?A(P._1,P._2,!0):P;return He(O,p,y,(Y,q)=>x(A(Y._1,Y._2,v),q),(Y,q)=>p($=>{const R=O._3&&!Y._3?A(Y._1,Y._2,!0):Y;return p(tt=>p(K=>{const gt=m._3&&!R._3?A(R._1,R._2,!0):R;return h1(gt,p,y,(_t,at)=>x(A(_t._1,_t._2,v),at),(_t,at)=>p(yt=>N(gt._3&&!_t._3?A(_t._1,_t._2,!0):_t,at)))}))}))}))}))})))))))))}})());return(h,m,p,y,x)=>m(N=>_(h,m,p,y,(v,k)=>m(L=>x(h._3&&!v._3?A(v._1,v._2,!0):v,av([l,...kt($t.foldr,k)])))))}g()})()(t._3&&!c._3?A(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>e(f=>h1(A(s,a,!1),e,n,(d,l)=>e(_=>u(t,T)),(d,l)=>e(_=>u(d,w("Just",l))))))})),kv=(t,e,n,r,i)=>e(o=>nr("+node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?A(u._1,u._2,!0):u;return e(f=>cn(c,e,n,r,(d,l)=>e(_=>{const h=Gt(be)("node identifier"),m=c._3&&!d._3?A(d._1,d._2,!0):d;return e(p=>h(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?A(y._1,y._2,!0):y;return e(k=>e(L=>He(v,e,n,r,(E,B)=>e(V=>{const et=jt(S=>S===`
15
+ `||S==="\r"||S==="#"||S==="}"||S==="{"),D=v._3&&!E._3?A(E._1,E._2,!0):E;return e(S=>{const Z=(z,M)=>e(G=>(M?((P,I,F,O,Y)=>Y(P,"")):dv)(D._3&&!z._3?A(z._1,z._2,!0):z,e,n,r,(P,I)=>e(F=>{const O=v._3&&!P._3?A(P._1,P._2,!0):P;return e(Y=>{const q=(tt,K)=>e(gt=>i(O._3&&!tt._3?A(tt._1,tt._2,!0):tt,Mn("AddNode",{id:x,label:I,shape:(()=>{const _t=cv("shape")(K);if(_t.tag==="Just")return _t._1==="rectangle"||_t._1==="rect"?Un:_t._1==="cylinder"||_t._1==="cyl"?yl:_t._1==="parallelogram"?xl:_t._1==="diamond"?Nl:_t._1==="ellipse"?Jl:_t._1==="document"||_t._1==="doc"?Tl:_t._1==="cloud"?vl:Un;if(_t.tag==="Nothing")return Un;g()})()}))),$=O._1,R=O._2;return e(tt=>{const K=(gt,_t)=>{const at=gt._3;return e(yt=>at?r(gt,_t):q(O,Q))};return e(gt=>e(_t=>He(A($,R,!1),e,n,(at,yt)=>K(A(at._1,at._2,!1),yt),(at,yt)=>e(Et=>e(At=>Lv(at,e,n,(pt,Mt)=>K(A(pt._1,pt._2,!1),Mt),(pt,Mt)=>e(Jt=>q(at._3&&!pt._3?A(pt._1,pt._2,!0):pt,Mt))))))))})})}))),X=D._1,W=D._2;return e(z=>{const M=(G,P)=>{const I=G._3;return e(F=>I?r(G,P):Z(D,!1))};return e(G=>e(P=>e(I=>ma(A(X,W,!1),e,n,(F,O)=>{const Y=F._3;return e(q=>Y?M(A(X,W,!1),O):e($=>et(A(X,W,!1),e,n,(R,tt)=>M(A(X,W,!1),tt),(R,tt)=>e(K=>e(gt=>Z(A(X,W,!1),!0))))))},(F,O)=>e(Y=>e(q=>Z(A(X,W,!1),!0)))))))})})}))))})))})))}))),Ev=(t,e,n,r,i)=>e(o=>a1(t,e,n,r,(u,s)=>e(a=>{const c=Gt(_1([kv,Jv,wv,xv,Nv,Tv,vv,pv]))("statement (+node, -node, +edge, -edge, ~edge, enter, exit, or 'a -> b')"),f=t._3&&!u._3?A(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>i(f._3&&!l._3?A(l._1,l._2,!0):l,la("Leaf",{op:_,line:s.line,column:s.column})))))}))),Gv=(t,e,n,r,i)=>e(o=>Oi("seq")(t,e,n,r,(u,s)=>e(a=>qi(Na(n1))(t._3&&!u._3?A(u._1,u._2,!0):u,e,n,r,i)))),Cv=(t,e,n,r,i)=>e(o=>Oi("par")(t,e,n,r,(u,s)=>e(a=>qi(Na(wT))(t._3&&!u._3?A(u._1,u._2,!0):u,e,n,r,i)))),Na=t=>{const e=on(Sv());return(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,c)=>r(f=>u(n._3&&!a._3?A(a._1,a._2,!0):a,t(kt($t.foldr,c))))))},Sv=ka(()=>{const t=ha(Gt(jt(e=>e==="}"))("'}'"));return(e,n,r,i,o)=>n(u=>{const s=e._3;return n(a=>n(c=>Ue(e,n,r,(f,d)=>i(A(f._1,f._2,s),d),(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?A(f._1,f._2,!0):f;return t(h,n,r,(m,p)=>i(A(m._1,m._2,s),p),(m,p)=>n(y=>{const x=h._3&&!m._3?A(m._1,m._2,!0):m;return n(N=>{const v=_1([(L,E,B,V,et)=>{const D=L._3;return Cv(L,E,B,(S,Z)=>V(A(S._1,S._2,D),Z),et)},(L,E,B,V,et)=>{const D=L._3;return Gv(L,E,B,(S,Z)=>V(A(S._1,S._2,D),Z),et)},Ev]),k=e._3&&!x._3?A(x._1,x._2,!0):x;return n(L=>v(k,n,r,i,(E,B)=>n(V=>{const et=k._3&&!E._3?A(E._1,E._2,!0):E;return n(D=>He(et,n,r,i,(S,Z)=>n(X=>{const W=et._3&&!S._3?A(S._1,S._2,!0):S;return n(z=>gv(W,n,r,i,(M,G)=>n(P=>o(W._3&&!M._3?A(M._1,M._2,!0):M,B))))})))})))})}))})))))})}),Dv=(t,e,n,r,i)=>e(o=>Oi("frame")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?A(u._1,u._2,!0):u;return e(f=>hv(c,e,n,r,(d,l)=>e(_=>{const h=c._3&&!d._3?A(d._1,d._2,!0):d;return e(m=>Ue(h,e,n,r,(p,y)=>e(x=>{const N=qi(Na(n1)),v=h._3&&!p._3?A(p._1,p._2,!0):p;return e(k=>N(v,e,n,r,(L,E)=>e(B=>{const V=v._3&&!L._3?A(L._1,L._2,!0):L;return e(et=>Ue(V,e,n,r,(D,S)=>e(Z=>i(V._3&&!D._3?A(D._1,D._2,!0):D,{name:w("Just",l),ops:E}))))})))})))})))}))),Pv=(t,e,n,r,i)=>e(o=>Oi("inside")(t,e,n,r,(u,s)=>e(a=>{const c=Gt(be)("node identifier"),f=t._3&&!u._3?A(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const m=f._3&&!l._3?A(l._1,l._2,!0):l;return e(p=>Ue(m,e,n,r,(y,x)=>e(N=>{const v=m._3&&!y._3?A(y._1,y._2,!0):y;return e(k=>qi(p1)(v,e,n,r,(L,E)=>e(B=>{const V=v._3&&!L._3?A(L._1,L._2,!0):L;return e(et=>Ue(V,e,n,r,(D,S)=>e(Z=>i(V._3&&!D._3?A(D._1,D._2,!0):D,{node:_,doc:E}))))})))})))})))}))),p1=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>{const l=on(Iv()),_=t._3&&!c._3?A(c._1,c._2,!0):c;return e(h=>l(_,e,n,r,(m,p)=>e(y=>{const x=kt($t.foldr,p);return i(_._3&&!m._3?A(m._1,m._2,!0):m,{seed:(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})(),frames:xt(N=>{if(N.tag==="TopFrame")return w("Just",N._1);if(N.tag==="TopInside")return T;g()})(x),interiors:xt(N=>{if(N.tag==="TopInside")return w("Just",N._1);if(N.tag==="TopFrame")return T;g()})(x)})})))}),s=t._1,a=t._2;return e(c=>e(f=>bv(A(s,a,!1),e,n,(d,l)=>{const _=d._3;return e(h=>_?r(d,l):u(t,T))},(d,l)=>e(_=>u(d,w("Just",l))))))}),Iv=ka(()=>VT.defer(t=>(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>n(c=>Pv(A(u,s,!1),n,r,(f,d)=>n(l=>n(_=>Dv(e,n,r,i,(h,m)=>n(p=>o(h,f1("TopFrame",m)))))),(f,d)=>n(l=>o(f,f1("TopInside",d))))))})),Qv=(()=>{const t=Gt((e,n,r,i,o)=>n(u=>n(s=>Ue(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?A(a._1,a._2,!0):a;return ma(l,n,r,i,(_,h)=>n(m=>o(l._3&&!_._3?A(_._1,_._2,!0):_,h)))}))))))("'frame', 'inside', or end of input");return(e,n,r,i,o)=>n(u=>n(s=>n(a=>n(c=>Ue(e,n,r,i,(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?A(f._1,f._2,!0):f;return p1(h,n,r,i,(m,p)=>n(y=>{const x=h._3&&!m._3?A(m._1,m._2,!0):m;return n(N=>n(v=>{const k=e._3&&!x._3?A(x._1,x._2,!0):x;return t(k,n,r,i,(L,E)=>n(B=>o(k._3&&!L._3?A(L._1,L._2,!0):L,p)))}))}))})))))))})(),Fv=t=>{const e=ZT(t)(Qv);if(e.tag==="Left")return St("Left",{msg:e._1._1,line:e._1._2.line,column:e._1._2.column});if(e.tag==="Right")return St("Right",e._1);g()},Av=t=>{const e=Fv(t);if(e.tag==="Left")return St("Left",e._1.msg);if(e.tag==="Right")return St("Right",e._1);g()};function Ja(t,e,n,r){if(typeof window<"u"){var i=window[n];if(i!=null&&r instanceof i)return e(r)}for(var o=r;o!=null;){var u=Object.getPrototypeOf(o),s=u.constructor.name;if(s===n)return e(r);if(s==="Object")return t;o=u}return t}function Ur(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function Mv(t){return function(e){return function(){return e.getAttribute(t)}}}const Bv=t=>{const e=Mv(t);return n=>{const r=e(n);return()=>{const i=r();return Ua(i,T,Yt)}}};function zv(t){return function(e){return function(){e.textContent=t}}}function Rv(t){return function(){return function(e){return t(e)()}}}function Wv(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const Hv=function(){return window};function Ov(t){return function(e){return function(){e.value=t}}}function qv(t){return function(){return t.valueAsNumber}}function $v(t){return function(){return t.value}}function Yv(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const Vv=t=>t,Xv=t=>()=>t.clientWidth||0,Uv=()=>window.devicePixelRatio||1,Ta=(t,e)=>{e.innerHTML=t},va=(t,e,n)=>{t.style.setProperty(e,n)},jv=(t,e)=>t.querySelector(`[data-mg="${e}"]`),Zv=t=>e=>t===e,Kv=t=>t,tw=(t,e,n)=>({tag:t,_1:e,_2:n}),ew=Bt.foldMap(Td),m1=t=>e=>{const n=st.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},nw=t=>e=>{const n=st.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},rw=tw("AutoSize"),iw=Kv("CanvasRenderer"),ow=t=>e=>{const n=t-e*rt(de(dn(t/e)));return e<=0?0:n<0?n+e:n},uw=t=>J(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),sw=t=>{const e=Bv("data-markgraf-titles")(t);return()=>{const n=e();return n.tag==="Nothing"||!(n.tag==="Just"&&n._1==="false")}},aw=`
14
16
  <canvas data-mg="stage" tabindex="0"></canvas>
15
17
  <div data-mg="play-overlay" aria-hidden="true"></div>
16
18
  <div data-mg="bar">
@@ -27,4 +29,4 @@ var Vm=(function(Ao){"use strict";function Rc(e){let t=0,n;return()=>{if(t===2)r
27
29
  <option value="2">2\xD7</option>
28
30
  </select>
29
31
  </div>
30
- `,rn=e=>t=>n=>()=>{const r=km(e,t),i=Df(r,T,Xt);if(i.tag==="Just")return n(i._1)();i.tag!=="Nothing"&&c()},Mm=e=>t=>{const n=t.totalDuration<=0?1:t.totalDuration,r=Cm(i=>'<span class="mg-tick" style="left:'+_r(fr("Fixed",gr(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;c()})()+'"></span>')(t.spans);return rn(e)("ticks")(i=>()=>hu(r,i))},Wm=e=>t=>n=>rn(e)("scrub")(r=>{const i=lu(T,Xt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return n<=0?()=>{}:ym(ue(ur(Mu(t/n*1e3))))(i._1);c()}),pu=e=>t=>n=>{const r=hm(i=>n);return()=>{const i=r();return pm(e)(i)(!1)(t)()}},mu=e=>t=>n=>r=>i=>o=>{const u=b1(n)(Cc(o)(n.totalDuration));if(t==="CanvasRenderer")return()=>{const s=$u(),a=i.value;i.value=s;const f=vm(e),g=fs(n.layout)(u.camera),d=g.w+48,l=g.h+48,_=Tm(e)(),h=d<=0?_:_*l/d,p=wm(),m=_*p,N=h*p,J=zf(f)(),v=Bf(f)(),w=$f(f)(m);J!==m&&w();const L=Qf(f)(N);v!==N&&L(),bm(e,"height",ue(ur(Mu(h)))+"px");const b=Af(f)();dr(b)(),ti(b)({scaleX:p,scaleY:p})();const S=r.value,A=Oh(b)({width:_,height:h})(n.layout)(u)(a===0?0:(s-a)/1e3)(S)();return r.value=A,lr(b)()};if(t==="SvgRenderer"){const s=op(n.layout)(u),a=Mo("viewBox")(s.viewBox)(e);return()=>(a(),Mo("preserveAspectRatio")("xMidYMid meet")(e)(),hu(s.body,e))}c()},Am=e=>{const t=dm(e);if(t.tag==="Left")return kt("Left",t._1);if(t.tag==="Right"){const n=Cp(t._1);if(n.tag==="Left")return kt("Left",n._1.msg);if(n.tag==="Right")return kt("Right",n._1)}c()},yu=e=>t=>{const n=ge(r=>r.startT<=t&&t<r.endT)(e.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;c()}if(n.tag==="Nothing"){const r=e.spans.length-1|0;if(r>=0&&r<e.spans.length){if(e.spans[r].scene.tag==="Structural")return e.spans[r].scene._1.to;if(e.spans[r].scene.tag==="DataFlow")return e.spans[r].scene._1.keyframe;c()}return""}c()},zm=e=>t=>rn(e)("speed")(n=>{const r=lu(T,Xt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return pu("change")(n)((()=>{const i=Nm(r._1);return()=>{const o=i(),u=Nf(o,Ru,Xt,T);if(u.tag==="Just")return t(u._1)();u.tag!=="Nothing"&&c()}})());c()}),Bm=e=>t=>n=>rn(e)("scrub")(r=>{const i=lu(T,Xt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return pu("input")(r)((()=>{const o=Jm(i._1);return()=>{const u=o();return n.pause(),n.seek(u/1e3*t.totalDuration)()}})());c()}),$m=e=>t=>n=>{const r=Mm(e)(t);return()=>{r(),rn(e)("play")(i=>Mo("data-mg-playing")("1")(i))(),zm(e)(n.setSpeed)(),rn(e)("play")(i=>pu("click")(i)(n.toggle))(),Bm(e)(t)(n)(),n.subscribe(i=>{const o=Wm(e)(i.time)(t.totalDuration);return()=>(o(),rn(e)("time")(u=>lm(_r(fr("Fixed",gr(0)(20)(2)))(i.time)+" / "+_r(fr("Fixed",gr(0)(20)(2)))(t.totalDuration))(u))(),rn(e)("play")(u=>Mo("data-mg-playing")(i.playing?"1":"0")(u))())})()}},Qm=e=>t=>n=>()=>{let r=1,i=!0,o=!1,u=0,s=0;const a={value:$},f={value:0};let g=!1,d=[];mu(e)(n)(t)(a)(f)(0)();const l=J=>()=>{const v=d,w=i,L={time:J,keyframe:yu(t)(J),playing:w};return Dm(b=>b(L))(v)()},_=()=>(i=!1,l(u)()),h=()=>{if(!g&&(o=!1,i)){const J=$u(),v=s;s=J;const w=r,L=u,b=Rm(v===0?L+0*w:L+(J-v)/1e3*w)(t.totalDuration+.8);return u=b,mu(e)(n)(t)(a)(f)(b)(),l(b)(),p()}},p=()=>{if(!g&&!o){o=!0;const J=mm();xm(h)(J)()}},m=()=>(s=0,i=!0,p()),N=()=>(i||m(),l(u)());return m(),{play:N,pause:_,toggle:()=>i?_():N(),seek:J=>{const v=Sm(0)(Cc(t.totalDuration)(J));return()=>(u=v,s=0,mu(e)(n)(t)(a)(f)(v)(),l(v)())},setSpeed:J=>()=>r=J,currentTime:()=>u,currentKeyframe:()=>{const J=u;return yu(t)(J)},isPlaying:()=>i,duration:t.totalDuration,subscribe:J=>()=>{d=de(d)(J);const v=u,w=i;J({time:v,keyframe:yu(t)(v),playing:w})();const L=Su(b=>!Lm(b)(J));return()=>{d=L(d)}},destroy:()=>g=!0}},Sc=e=>t=>{const n=Am(t);if(n.tag==="Left")return Bu("[markgraf] parse failed: "+n._1);if(n.tag==="Right")return Im(n._1)(r=>()=>(hu(Gm,e),rn(e)("stage")(i=>{const o=Qm(i)(r)(Pm);return()=>{const u=o();return $m(e)(r)(u)()}})()));c()},qm=e=>{const t=e.getAttribute("data-markgraf-src-b64");if(t)try{return decodeURIComponent(escape(atob(t)))}catch{return atob(t)}return e.getAttribute("data-markgraf-src")||e.textContent||""};let Ye=null;const Ju=e=>e.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",Hm=e=>{const t=e.querySelector('[data-mg="play"]');if(!t)return;t.addEventListener("click",()=>{queueMicrotask(()=>{Ju(e)?(Ye&&Ye!==e&&Ju(Ye)&&Ye.querySelector('[data-mg="play"]').click(),Ye=e):Ye===e&&(Ye=null)})});const n=r=>{r.preventDefault(),t.click()};e.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},Ym=e=>{if(e.dataset.markgrafMounted==="1")return;e.dataset.markgrafMounted="1";const t=qm(e);e.textContent="",Sc(e)(t)(),Ye===null?Ye=e:Ju(e)&&e.querySelector('[data-mg="play"]').click(),Hm(e)},Wo=(e=document)=>{e.querySelectorAll("[data-markgraf]").forEach(Ym)},Pc=()=>{document.addEventListener("keydown",e=>{if(e.code!=="Space"&&e.key!==" ")return;const t=e.target,n=t&&t.closest?.("[data-markgraf]");if(!n){const i=t?.tagName,o=(t?.type||"").toLowerCase();if(t?.isContentEditable||i==="TEXTAREA"||i==="SELECT"||i==="INPUT"&&!["range","checkbox","radio","button","submit","reset"].includes(o))return}const r=n||Ye||document.querySelector("[data-markgraf]");r&&(e.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};return typeof window<"u"&&(window.markgraf={mount:(e,t)=>Sc(e)(t)(),mountAll:Wo},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{Wo(),Pc()}):(Wo(),Pc())),Ao.mountAll=Wo,Object.defineProperty(Ao,Symbol.toStringTag,{value:"Module"}),Ao})({});
32
+ `,Rn=t=>e=>n=>()=>{const r=jv(t,e),i=Ua(r,T,Yt);if(i.tag==="Just")return n(i._1)();i.tag!=="Nothing"&&g()},cw=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=ew(i=>'<span class="mg-tick" style="left:'+oi(ri("Fixed",ii(0)(20)(2)))(100*i.startT/n)+'%" data-label="'+(()=>{if(i.scene.tag==="Structural")return i.scene._1.to;if(i.scene.tag==="DataFlow")return i.scene._1.keyframe;if(i.scene.tag==="EnterNode"||i.scene.tag==="ExitNode")return"";g()})()+'"></span>')(e.spans);return Rn(t)("ticks")(i=>()=>Ta(r,i))},gw=t=>e=>n=>Rn(t)("scrub")(r=>{const i=Ja(T,Yt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return n<=0?()=>{}:Ov(ie(de($n(e/n*1e3))))(i._1);g()}),wa=t=>e=>n=>{const r=Rv(i=>n);return()=>{const i=r();return Wv(t)(i)(!1)(e)()}},y1=()=>Ed()/1e3,ba=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>{const f=Ye(u.layout),d=kl(u.layout),l={center:{x:d.x+d.w/2,y:f.y+f.h/2},zoom:Zu(u.layout)(f)(0)},_=Yu(u.layout)(l),h=()=>{const N=y1(),v=a.value;return a.value=N,v===0?0:N-v},m=V0(u)(m1(c)(u.totalDuration)),p=o?m:{...m,levels:H(N=>({...N,state:{...N.state,frameTitle:""}}))(m.levels)},y=u.dives.length===0&&(_.w+48)*1.0909090909090908<=1100&&(_.h+48)*1.0909090909090908<=1400,x=y?{...p,camera:l,levels:H(N=>({...N,state:{...N.state,camera:l}}))(p.levels)}:p;if(e==="CanvasRenderer")return()=>{const N=h(),v=Vv(t),k=Yr({padding:8,outputAspect:T})(x),L=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){if(y)return{w:k.vw*1.0909090909090908,h:k.vh*1.0909090909090908};const M=Xv(t)();return{w:M,h:k.vw<=0?M:M*k.vh/k.vw}}g()})(),E=Uv(),B=L.w*E,V=L.h*E,et=Cd(v)(),D=Sd(v)(),S=Dd(v)(B);et!==B&&S();const Z=Pd(v)(V);if(D!==V&&Z(),va(t,"height",ie(de($n(L.h)))+"px"),n.tag==="FixedSize")va(t,"width",ie(de($n(L.w)))+"px");else if(n.tag==="AutoSize"){const M=ie(de($n(L.w)))+"px";y&&va(t,"width",M)}else g();const X=Gd(v)();sr(X)(),Ki(X)({scaleX:E,scaleY:E})();const W=s.value,z=KJ(r)(i)(X)({width:L.w,height:L.h})(x)(N)(W)();return s.value=z,ar(X)()};if(e==="SvgRenderer")return()=>{const N=h(),v=s.value,k=pT((()=>{if(n.tag==="AutoSize")return T;if(n.tag==="FixedSize")return n._1<=0||n._2<=0?T:w("Just",n._1/n._2);g()})())(r)(i)(x)(N)(v);return s.value=k.springs,Ur("viewBox")(k.parts.viewBox)(t)(),Ur("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(Ur("width")(ie(de($n(n._1))))(t)(),Ur("height")(ie(de($n(n._2))))(t)()):n.tag==="AutoSize"||g(),Ta(k.parts.body,t)};g()},x1=t=>{const e=Av(t);if(e.tag==="Left")return St("Left",e._1);if(e.tag==="Right"){const n=u1(e._1)(r1)._1;if(n.tag==="Left")return St("Left",n._1.msg);if(n.tag==="Right")return St("Right",n._1)}g()},fw=t=>{const e=x1(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return wd;g()},La=t=>e=>{const n=Zt(r=>r.startT<=e&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return n._1.scene._1.to;if(n._1.scene.tag==="DataFlow")return n._1.scene._1.keyframe;if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return"";g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;if(r>=0&&r<t.spans.length){if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return"";g()}return""}g()},_w=t=>e=>Rn(t)("speed")(n=>{const r=Ja(T,Yt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return wa("change")(n)((()=>{const i=$v(r._1);return()=>{const o=i(),u=sd(o,Oa,Yt,T);if(u.tag==="Just")return e(u._1)();u.tag!=="Nothing"&&g()}})());g()}),dw=t=>e=>n=>Rn(t)("scrub")(r=>{const i=Ja(T,Yt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return wa("input")(r)((()=>{const o=qv(i._1);return()=>{const u=o();return n.pause(),n.seek(u/1e3*e.totalDuration)()}})());g()}),lw=t=>e=>n=>{const r=cw(t)(e);return()=>{r(),Rn(t)("play")(i=>Ur("data-mg-playing")("1")(i))(),_w(t)(n.setSpeed)(),Rn(t)("play")(i=>wa("click")(i)(n.toggle))(),dw(t)(e)(n)(),n.subscribe(i=>{const o=gw(t)(i.time)(e.totalDuration);return()=>(o(),Rn(t)("time")(u=>zv(oi(ri("Fixed",ii(0)(20)(2)))(i.time)+" / "+oi(ri("Fixed",ii(0)(20)(2)))(e.totalDuration))(u))(),Rn(t)("play")(u=>Ur("data-mg-playing")(i.playing?"1":"0")(u))())})()}},hw={...oh,tokenZoomFloor:1,minZoom:1.6,maxZoom:3.2},pw=t=>e=>{const n=Ef(t);return()=>{const r=n(),i=Gf(t)(),o=a0(hw)(jh)(t)(Cf(r)(i)(t));if(o.tag==="Left")return ja("[markgraf] precompute failed")();if(o.tag==="Right")return e(o._1)();g()}},mw=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,m=[];ba(t)(n)(r)(i)(o)(u)(e)(l)(_)(0)();const p=L=>()=>{const E=m,B=a,V={time:L,keyframe:La(e)(L),playing:B};return uw(et=>et(V))(E)()},y=()=>(a=!1,p(f)()),x=()=>{if(!h&&(c=!1,a)){const L=y1(),E=d;d=L;const B=s,V=f,et=ow(E===0?V+0*B:V+(L-E)*B)(e.totalDuration+.8);return f=et,ba(t)(n)(r)(i)(o)(u)(e)(l)(_)(et)(),p(et)(),N()}},N=()=>{if(!h&&!c){c=!0;const L=Hv();Yv(x)(L)()}},v=()=>(d=0,a=!0,N()),k=()=>(a||v(),p(f)());return v(),{play:k,pause:y,toggle:()=>a?y():k(),seek:L=>{const E=nw(0)(m1(e.totalDuration)(L));return()=>(f=E,d=0,ba(t)(n)(r)(i)(o)(u)(e)(l)(_)(E)(),p(E)())},setSpeed:L=>()=>s=L,currentTime:()=>f,currentKeyframe:()=>{const L=f;return La(e)(L)},isPlaying:()=>a,duration:e.totalDuration,subscribe:L=>()=>{m=zt(m)(L);const E=f,B=a;L({time:E,keyframe:La(e)(E),playing:B})();const V=Wa(et=>!Zv(et)(L));return()=>{m=V(m)}},destroy:()=>h=!0}},N1=t=>e=>{const n=x1(e);if(n.tag==="Left")return ja("[markgraf] parse failed: "+n._1);if(n.tag==="Right")return pw(n._1)(r=>{const i=sw(t);return()=>{const o=i();return Ta(aw,t),Rn(t)("stage")(u=>{const s=mw(u)(r)(iw)(rw)(eT)(nT)(o);return()=>{const a=s();return lw(t)(r)(a)()}})()}});g()},yw=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 hu=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",xw=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{hu(t)?(Ln&&Ln!==t&&hu(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)},Nw=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=yw(t),n=t.dataset.markgrafPaused==="true";t.textContent="",N1(t)(e)(),n?hu(t)&&t.querySelector('[data-mg="play"]').click():Ln===null?Ln=t:hu(t)&&t.querySelector('[data-mg="play"]').click(),xw(t)},pu=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(Nw)},J1=()=>{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=fw(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>N1(e)(n)(),mountAll:pu,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{pu(),J1()}):(pu(),J1())}return mu.mountAll=pu,Object.defineProperty(mu,Symbol.toStringTag,{value:"Module"}),mu})({});