@markgrafhq/markgraf-embed 0.1.23 → 0.1.24

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.

Potentially problematic release.


This version of @markgrafhq/markgraf-embed might be problematic. Click here for more details.

@@ -1,41 +1,41 @@
1
- var R6=(function(uc){"use strict";function qm(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 _(){throw new Error("Failed pattern match")}function Nr(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const Be=t=>e=>t,U=function(t){return function(e){for(var n=e.length,r=new Array(n),o=0;o<n;o++)r[o]=t(e[o]);return r}},Um={map:U},Nf=t=>t,Et=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,o=0;o<r;o++)for(var i=e(t[o]),a=i.length,s=0;s<a;s++)n.push(i[s]);return n}},Xm=function(t){return function(e){return{}.hasOwnProperty.call(e,t)}},Vm=function(t){return function(e){return e[t]}},ae=function(t){return t.toString()},Eo=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},Tf=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 o=r+1,i=o<e&&t[o]>="0"&&t[o]<="9"?"\\&":"";return"\\"+n.charCodeAt(0).toString(10)+i})+'"'},Ym=function(t){return function(e){for(var n=[],r=0,o=e.length;r<o;r++)n[r]=t(e[r]);return"["+n.join(",")+"]"}},cc=t=>t,Me=cc("LT"),ze=cc("GT"),an=cc("EQ"),T=(t,e)=>({tag:t,_1:e}),w=T("Nothing"),Ut=t=>T("Just",t),vf=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;_()},bf=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;_()},It=(t,e)=>({tag:t,_1:e}),Km=t=>It("Right",t),jm={map:t=>e=>{if(e.tag==="Left")return It("Left",e._1);if(e.tag==="Right")return It("Right",t(e._1));_()}},Jf={apply:t=>e=>{if(t.tag==="Left")return It("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return It("Left",e._1);if(e.tag==="Right")return It("Right",t._1(e._1))}_()},Functor0:()=>jm},Zm={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>It("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}_()},Apply0:()=>Jf},t2={pure:Km,Apply0:()=>Jf},Cf={Applicative0:()=>t2,Bind1:()=>Zm},e2=t=>t,n2={map:t=>e=>t(e)},kf={apply:t=>e=>t(e),Functor0:()=>n2},r2={bind:t=>e=>e(t),Apply0:()=>kf},o2={pure:e2,Apply0:()=>kf},Gn={Applicative0:()=>o2,Bind1:()=>r2},i2=function(t){return function(){return t}},a2={apply:t=>e=>()=>{const n=t(),r=e();return gc.pure(n(r))()},Functor0:()=>s2},gc={pure:i2,Apply0:()=>a2},s2={map:t=>e=>()=>{const n=e();return t(n)}},pi=(t,e)=>({tag:t,_1:e}),_c=t=>pi("Loop",t),u2=t=>pi("Done",t),c2={tailRecM:t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const a=r;if(a.tag==="Loop"){r=t(a._1);continue}if(a.tag==="Done"){o=!1,i=a._1;continue}_()}return i};return n=>e(t(n))},Monad0:()=>Gn},g2=function(t){return function(e){return function(){return t(e())}}},_2=function(t){return function(){return t}},f2=function(t){return function(e){return function(){return e(t())()}}},l2={map:g2},d2={Applicative0:()=>fc,Bind1:()=>h2},h2={bind:f2,Apply0:()=>Lf},Lf={apply:t=>e=>()=>{const n=t(),r=e();return fc.pure(n(r))()},Functor0:()=>l2},fc={pure:_2,Apply0:()=>Lf},p2={tailRecM:t=>e=>{const n=t(e);return()=>{let r=n();for(;r.tag==="Loop";){const i=r;if(i.tag==="Loop"){r=t(i._1)();continue}i.tag!=="Done"&&_()}const o=r;if(o.tag==="Done")return o._1;_()}},Monad0:()=>d2},m2=function(t){return function(e){return function(n){return function(){return t(e,n)}}}},y2=function(t,e,n,r){return n>=0&&n<r.length?t(r[n]):e},lc=function(t){return t.length},x2=function(t,e,n){return n.length>0?t(n.pop()):e},w2=m2(function(t,e){return e.push(t)}),N2=(t,e)=>({tag:"Iterator",_1:t,_2:e}),T2=t=>e=>n=>()=>{let r=!1;const o=e._2;for(;!r;){const i=o.value,a=e._1(i);if(a.tag==="Just"&&t(a._1)){n.push(a._1),e._2.value;const s=e._2.value;e._2.value=s+1|0;continue}r=!0}},v2=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const o=r.value,i=r.value;r.value=i+1|0;const a=t._1(o);if(a.tag==="Just"){e(a._1)();continue}if(a.tag==="Nothing"){n=!0;continue}_()}},mi=function(t){return function(e){return function(n){for(var r=e,o=n.length,i=o-1;i>=0;i--)r=t(n[i])(r);return r}}},b=function(t){return function(e){return function(n){for(var r=e,o=n.length,i=0;i<o;i++)r=t(r)(n[i]);return r}}},io=t=>{const e=t.Apply0();return n=>r=>n.foldr(o=>{const i=r(o);return a=>e.apply(e.Functor0().map(s=>Nf)(i))(a)})(t.pure())},yi=t=>{const e=io(t);return n=>{const r=e(n);return o=>i=>r(i)(o)}},Sf={foldr:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(n._1)(e);_()},foldl:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(e)(n._1);_()},foldMap:t=>{const e=t.mempty;return n=>r=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return n(r._1);_()}}},Mt={foldr:mi,foldl:b,foldMap:t=>{const e=t.mempty;return n=>Mt.foldr(r=>o=>t.Semigroup0().append(n(r))(o))(e)}},L=(t,e)=>({tag:"Tuple",_1:t,_2:e}),vn=t=>e=>L(t,e),rs=t=>t._2,os=t=>t._1,Ot=function(t){return function(e){for(var n=e.length,r=Array(n),o=0;o<n;o++)r[o]=t(o)(e[o]);return r}};var dc=function(t){return function(e){return t===e}};const b2=dc,J2=dc,xi=dc,is=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}}},Tr={eq:xi},C2={eq:J2},ao={eq:b2};var hc=function(t){return function(e){return function(n){return function(r){return function(o){return r<o?t:r===o?e:n}}}}};const k2=hc,L2=hc,P={compare:hc(Me)(an)(ze),Eq0:()=>Tr},at={compare:L2(Me)(an)(ze),Eq0:()=>C2},ut={compare:k2(Me)(an)(ze),Eq0:()=>ao},ea=function(t){return t},S2=(function(){function t(o){return[o]}function e(o){return function(i){return[o,i]}}function n(o){return function(i){return function(a){return[o,i,a]}}}function r(o){return function(i){return o.concat(i)}}return function(o){return function(i){return function(a){return function(s){return function(u){function c(g,l){switch(l-g){case 0:return a([]);case 1:return i(t)(s(u[g]));case 2:return o(i(e)(s(u[g])))(s(u[g+1]));case 3:return o(o(i(n)(s(u[g])))(s(u[g+1])))(s(u[g+2]));default:var d=g+Math.floor((l-g)/4)*2;return o(i(r)(c(g,d)))(c(d,l))}}return c(0,u.length)}}}}}})(),E2=t=>t,so={traverse:t=>{const e=t.Apply0();return S2(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>so.traverse(t)(E2),Functor0:()=>Um,Foldable1:()=>Mt},Yt=function(t,e){for(var n=t>e?-1:1,r=new Array(n*(e-t)+1),o=t,i=0;o!==e;)r[i++]=o,o+=n;return r[i]=o,r};var A2=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},P2=function(t,e){for(var n=[],r=0,o=0;o<t;o++)n[r++]=e;return n};const Ao=typeof Array.prototype.fill=="function"?A2:P2,Wt=(function(){function t(o,i){this.head=o,this.tail=i}var e={};function n(o){return function(i){return new t(o,i)}}function r(o){for(var i=[],a=0,s=o;s!==e;)i[a++]=s.head,s=s.tail;return i}return function(o,i){return r(o(n)(e)(i))}})(),At=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},Ef=function(t,e,n,r){for(var o=0;o<r.length;o++){var i=n(r[o]);if(e(i))return i}return t},Mr=function(t,e,n,r){for(var o=0,i=r.length;o<i;o++)if(n(r[o]))return t(o);return e},Af=function(t,e,n,r,o){if(n<0||n>o.length)return e;var i=o.slice();return i.splice(n,0,r),t(i)},Pf=function(t,e,n,r){if(n<0||n>=r.length)return e;var o=r.slice();return o.splice(n,1),t(o)},uo=function(t,e,n,r,o){if(n<0||n>=o.length)return e;var i=o.slice();return i[n]=r,t(i)},re=function(t){return t.slice().reverse()},bn=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 o=t[n],i=0,a=o.length;i<a;i++)e.push(o[i]);return e},dt=function(t,e){return e.filter(t)},R2=function(t,e,n){for(var r=n.length,o=e,i=new Array(r),a=0;a<r;a++)o=t(o)(n[a]),i[a]=o;return i},G2=(function(){function t(e,n,r,o,i,a){var s,u,c,g,l,d,f;for(s=i+(a-i>>1),s-i>1&&t(e,n,o,r,i,s),a-s>1&&t(e,n,o,r,s,a),u=i,c=s,g=i;u<s&&c<a;)l=o[u],d=o[c],f=n(e(l)(d)),f>0?(r[g++]=d,++c):(r[g++]=l,++u);for(;u<s;)r[g++]=o[u++];for(;c<a;)r[g++]=o[c++]}return function(e,n,r){var o;return r.length<2?r:(o=r.slice(0),t(e,n,o,r.slice(0),0,r.length),o)}})(),Rt=function(t,e,n){return n.slice(t,e)},$e=function(t,e,n){for(var r=e.length<n.length?e.length:n.length,o=new Array(r),i=0;i<r;i++)o[i]=t(e[i])(n[i]);return o},ne=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},pc=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Gt=t=>e=>G2(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;_()},e),D2=t=>e=>Gt(n=>r=>t.compare(e(n))(e(r))),St=t=>e=>(()=>{const n=w2(e);return()=>{const r=[...t];return n(r)(),r}})()(),zr=t=>{if(t.length===0)return t.length-1|0,w;const e=t.length-1|0;return e>=0&&e<t.length?T("Just",{init:Rt(0,t.length-1|0,t),last:t[e]}):w},F2=t=>e=>n=>t>=0&&t<n.length?uo(Ut,w,t,e(n[t]),n):w,vr=t=>e=>{const n=(r=>{let o=r,i=!0,a;for(;i;){const s=o;if(s>=0&&s<e.length){if(t(e[s])){o=s+1|0;continue}i=!1,a=T("Just",s);continue}i=!1,a=w}return a})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:Rt(0,n._1,e),rest:Rt(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};_()},wi=t=>e=>{const n=Gt(r=>o=>t(r._2)(o._2))(Ot(vn)(e));return 0<n.length?U(rs)(D2(ut)(os)((()=>{const r=[n[0]];for(const o of n){const i=t((()=>{const a=r.length-1|0;if(a>=0&&a<r.length)return r[a]._2;_()})())(o._2);(i==="LT"||i==="GT"||i!=="EQ")&&r.push(o)}return r})())):[]},I2=t=>e=>{const n=[],r=N2(o=>o>=0&&o<e.length?T("Just",e[o]):w,{value:0});return v2(r)(o=>()=>{const i=[];i.push(o),T2(t(o))(r)(i)(),n.push(i)})(),n},Kt=t=>e=>{const n=Mr(Ut,w,t,e);return n.tag==="Just"?T("Just",e[n._1]):w},na=t=>e=>dt(t,e),_n=t=>e=>n=>{const r=Mr(Ut,w,o=>t.eq(o)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;_()},as=t=>e=>Et(e)(t),wt=t=>as(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];_()}),ss=isFinite;function Rf(t,e,n,r){var o=parseFloat(t);return e(o)?n(o):r}const ke=Math.abs,B2=Math.acos,Po=function(t){return function(e){return Math.atan2(t,e)}},us=Math.ceil,Dn=Math.cos,Ni=Math.exp,Vn=Math.floor,cs=Math.log,M2=function(t){return function(e){return Math.min(t,e)}},mc=function(t){return function(e){return Math.pow(t,e)}},Fn=Math.round,fn=Math.sin,tn=Math.sqrt,z2=Math.tan,Q2=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},rt=function(t){return t},W2=(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 o=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(i){if(o.test(i)){var a=parseInt(i,n);return(a|0)===a?t(a):e}else return e}}}})(Ut)(w)(10),Gf=Q2(Ut)(w),de=t=>{if(!ss(t))return 0;if(t>=rt(2147483647))return 2147483647;if(t<=rt(-2147483648))return-2147483648;const e=Gf(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;_()},yt=(t,e,n)=>({tag:t,_1:e,_2:n}),R=yt("Nil"),ue={foldr:t=>e=>{const n=ue.foldl(o=>i=>t(i)(o))(e),r=(o=>i=>{let a=o,s=i,u=!0,c;for(;u;){const g=a,l=s;if(l.tag==="Nil"){u=!1,c=g;continue}if(l.tag==="Cons"){a=yt("Cons",l._1,g),s=l._2;continue}_()}return c})(R);return o=>n(r(o))},foldl:t=>e=>n=>{let r=e,o=n,i=!0,a;for(;i;){const s=r,u=o;if(u.tag==="Nil"){i=!1,a=s;continue}if(u.tag==="Cons"){r=t(s)(u._1),o=u._2;continue}_()}return a},foldMap:t=>{const e=t.mempty;return n=>ue.foldl(r=>{const o=t.Semigroup0().append(r);return i=>o(n(i))})(e)}},O2=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var a=[],s=i;;){var u=o(s);a.push(n(u));var c=r(u);if(t(c))return a;s=e(c)}}}}}}},H2=t=>{if(t.tag==="Just")return t._1;_()},$2={unfoldr1:O2(vf)(H2)(os)(rs)},q2=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var a=[],s=i;;){var u=o(s);if(t(u))return a;var c=e(u);a.push(n(c)),s=r(c)}}}}}}},U2=t=>{if(t.tag==="Just")return t._1;_()},mn={unfoldr:q2(vf)(U2)(os)(rs),Unfoldable10:()=>$2},ee=(t,e,n,r,o,i,a)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:a}),yn=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),gs=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),Df=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),M=ee("Leaf"),ir=yn("IterLeaf"),Se=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return ee("Node",1,1,t,e,n,r);if(r.tag==="Node")return ee("Node",1+r._1|0,1+r._2|0,t,e,n,r);_()}if(n.tag==="Node"){if(r.tag==="Leaf")return ee("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return ee("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,t,e,n,r)}_()},sn=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?ee("Node",1,1,t,e,M,M):r.tag==="Node"&&r._1>1?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;_()})()?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;_()})()?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;_()})()?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;_()})()?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);_()},Ti=(t,e,n)=>{if(n.tag==="Leaf")return gs(w,M,M);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const o=Ti(t,e,n._5);return gs(o._1,o._2,sn(n._3,n._4,o._3,n._6))}if(r==="GT"){const o=Ti(t,e,n._6);return gs(o._1,sn(n._3,n._4,n._5,o._2),o._3)}if(r==="EQ")return gs(T("Just",n._4),n._5,n._6)}_()},Ff=(t,e,n,r)=>{if(r.tag==="Leaf")return Df(t,e,n);if(r.tag==="Node"){const o=Ff(r._3,r._4,r._5,r._6);return Df(o._1,o._2,sn(t,e,n,o._3))}_()},vi=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=Ff(t._3,t._4,t._5,t._6);return sn(n._1,n._2,n._3,e)}_()},ar=(t,e,n)=>{if(e.tag==="Leaf")return M;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=Ti(t,n._3,e);return vi(ar(t,r._2,n._5),ar(t,r._3,n._6))}_()},_s=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return M;if(r.tag==="Node"){const o=Ti(t,r._3,n),i=_s(t,e,o._2,r._5),a=_s(t,e,o._3,r._6);if(o._1.tag==="Just")return sn(r._3,e(o._1._1)(r._4),i,a);if(o._1.tag==="Nothing")return vi(i,a)}_()},Qe=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const o=Ti(t,r._3,n),i=Qe(t,e,o._2,r._5),a=Qe(t,e,o._3,r._6);if(o._1.tag==="Just")return sn(r._3,e(o._1._1)(r._4),i,a);if(o._1.tag==="Nothing")return sn(r._3,r._4,i,a)}_()},If=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return M;if(o.tag==="Node"){const i=t.compare(n)(o._3);if(i==="LT")return sn(o._3,o._4,r(o._5),o._6);if(i==="GT")return sn(o._3,o._4,o._5,r(o._6));if(i==="EQ"){const a=e(o._4);if(a.tag==="Nothing")return vi(o._5,o._6);if(a.tag==="Just")return ee("Node",o._1,o._2,o._3,a._1,o._5,o._6)}}_()};return r},X2=t=>e=>{const n=r=>{if(r.tag==="Leaf")return M;if(r.tag==="Node"){const o=e(r._3)(r._4);if(o.tag==="Just")return sn(r._3,o._1,n(r._5),n(r._6));if(o.tag==="Nothing")return vi(n(r._5),n(r._6))}_()};return n},sr=(t=>e=>n=>{let r=n,o=!0,i;for(;o;){const a=r;if(a.tag==="IterLeaf"){o=!1,i=e();continue}if(a.tag==="IterEmit"){o=!1,i=t(a._1,a._2,a._3);continue}if(a.tag==="IterNode"){r=(s=>u=>{let c=s,g=u,l=!0,d;for(;l;){const f=c,h=g;if(h.tag==="Leaf"){l=!1,d=f;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){c=yn("IterEmit",h._3,h._4,f),g=h._5;continue}c=yn("IterEmit",h._3,h._4,yn("IterNode",h._6,f)),g=h._5;continue}_()}return d})(a._2)(a._1);continue}_()}return i})((t,e,n)=>T("Just",L(L(t,e),n)))(t=>w),zt=t=>e=>n=>r=>{const o=i=>{if(i.tag==="Leaf")return ee("Node",1,1,n,r,M,M);if(i.tag==="Node"){const a=t.compare(n)(i._3);if(a==="LT")return sn(i._3,i._4,o(i._5),i._6);if(a==="GT")return sn(i._3,i._4,i._5,o(i._6));if(a==="EQ")return ee("Node",i._1,i._2,n,e(i._4)(r),i._5,i._6)}_()};return o},it=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return ee("Node",1,1,e,n,M,M);if(o.tag==="Node"){const i=t.compare(e)(o._3);if(i==="LT")return sn(o._3,o._4,r(o._5),o._6);if(i==="GT")return sn(o._3,o._4,o._5,r(o._6));if(i==="EQ")return ee("Node",o._1,o._2,e,n,o._5,o._6)}_()};return r},ge=t=>e=>e.foldl(n=>r=>it(t)(r._1)(r._2)(n))(M),bi=t=>e=>{const n=r=>{if(r.tag==="Leaf")return M;if(r.tag==="Node"){const o=t.compare(e)(r._3);if(o==="LT")return sn(r._3,r._4,n(r._5),r._6);if(o==="GT")return sn(r._3,r._4,r._5,n(r._6));if(o==="EQ")return vi(r._5,r._6)}_()};return n},Bf=t=>{const e=t.compare;return n=>r=>o=>{const i=Ti(e,r,o),a=n(i._1);if(a.tag==="Nothing")return vi(i._2,i._3);if(a.tag==="Just")return sn(r,a._1,i._2,i._3);_()}},ve=function(t){return function(e){return t+e|0}},ur=function(t){return function(e){return t+e}},co=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},V2=function(t){return function(e){return t+e}},ye=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},Y2={append:V2},K2={append:ye},j2={mempty:"",Semigroup0:()=>Y2},Z2={mempty:[],Semigroup0:()=>K2},ra=null;function Jn(t,e,n){return t==null?e:n(t)}function P6(t){return t}function yc(t){return function(e){return function(n){return t.apply(n,[e])}}}const ty=yc(Number.prototype.toPrecision),ey=yc(Number.prototype.toFixed),ny=yc(Number.prototype.toExponential),Ro=(t,e)=>({tag:t,_1:e}),Go=t=>e=>n=>{const r=ut.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=ut.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},Do=t=>{if(t.tag==="Precision")return ty(t._1);if(t.tag==="Fixed")return ey(t._1);if(t.tag==="Exponential")return ny(t._1);_()},Mf=function(t){return function(){console.log(t)}};function zf(t){return function(){return t.getContext("2d")}}function Qf(t){return function(){return t.width}}function Wf(t){return function(){return t.height}}function Of(t){return function(e){return function(){t.width=e}}}function Hf(t){return function(e){return function(){t.height=e}}}function xc(t){return function(e){return function(){t.lineWidth=e}}}function ry(t){return function(e){return function(){t.fillStyle=e}}}function oy(t){return function(e){return function(){t.strokeStyle=e}}}function wc(t){return function(e){return function(){t.lineCap=e}}}function Nc(t){return function(e){return function(){t.lineJoin=e}}}function iy(t){return function(e){return function(){t.globalCompositeOperation=e}}}function ay(t){return function(e){return function(){t.globalAlpha=e}}}function $f(t){return function(){t.beginPath()}}function Tc(t){return function(){t.stroke()}}function vc(t){return function(){t.fill()}}function sy(t){return function(){t.clip()}}function oa(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function qf(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function Uf(t){return function(){t.closePath()}}function uy(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function cy(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function fs(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function Xf(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function gy(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function _y(t){return function(e){return function(){t.textAlign=e}}}function fy(t){return function(e){return function(){t.textBaseline=e}}}function ly(t){return function(e){return function(){t.font=e}}}function dy(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function br(t){return function(){t.save()}}function Jr(t){return function(){t.restore()}}function ia(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function hy(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const Vf=t=>t,bc=t=>t,Jc=t=>t,Cc=t=>t,ls=t=>t,py=ls("BaselineTop"),my=ls("BaselineMiddle"),yy=ls("BaselineAlphabetic"),xy=ls("BaselineBottom"),wy=Cc("AlignLeft"),Ny=Cc("AlignRight"),Ty=Cc("AlignCenter"),kc=Jc("BevelJoin"),Lc=Jc("RoundJoin"),Sc=Jc("MiterJoin"),Ec=bc("Round"),Ac=bc("Square"),Pc=bc("Butt"),vy=Vf("SourceOver"),by=Vf("Difference"),Jy=t=>e=>fy(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";_()})()),Cy=t=>e=>_y(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";_()})()),Rc=t=>e=>{if(e==="BevelJoin")return Nc(t)("bevel");if(e==="RoundJoin")return Nc(t)("round");if(e==="MiterJoin")return Nc(t)("miter");_()},Gc=t=>e=>{if(e==="Round")return wc(t)("round");if(e==="Square")return wc(t)("square");if(e==="Butt")return wc(t)("butt");_()},Yf=t=>e=>iy(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";_()})()),Kf={foldrWithIndex:t=>e=>{const n=mi(o=>{const i=o._1,a=o._2;return s=>t(i)(a)(s)})(e),r=Ot(vn);return o=>n(r(o))},foldlWithIndex:t=>e=>{const n=b(o=>i=>t(i._1)(o)(i._2))(e),r=Ot(vn);return o=>n(r(o))},foldMapWithIndex:t=>{const e=t.mempty;return n=>Kf.foldrWithIndex(r=>o=>i=>t.Semigroup0().append(n(r)(o))(i))(e)},Foldable0:()=>Mt},ln={foldr:t=>e=>{const n=ue.foldr(t)(e);return r=>n((()=>{const o=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return o(i._5,yt("Cons",i._3,o(i._6,a)));_()};return o(r,R)})())}},ky=t=>{const e={append:(()=>{const n=t.compare;return r=>o=>Qe(n,Be,r,o)})()};return{mempty:M,Semigroup0:()=>e}},aa=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},In=function(t){return t.join("")},Bn=function(t){return t.split("")},cr=function(t){return t},gr=function(t){return t.length},jf=function(t){return function(e){return e.substr(0,t)}},Ji=function(t){return function(e){return e.substring(t)}},Zf=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},Ly=t=>e=>{const n=Zf(gr(e)-gr(t)|0)(e);return n.after===t?T("Just",n.before):w},Yn=t=>e=>{const n=Zf(gr(t))(e);return n.before===t?T("Just",n.after):w},Sy=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},Ey=function(t){return t()},Ay=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},Py=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},Fo=t=>BigInt(t),Ry=t=>Number(t),ds=t=>e=>t+e,hs=t=>e=>t*e,Dc=t=>e=>t-e,t1=0n,ps=1n,e1=t=>e=>t^e,sa=t=>e=>t&e,Fc=t=>e=>t<<e,Ic=t=>e=>t>>e,Gy=t=>e=>t==e,Dy=t=>e=>t===e?0:t>e?1:-1,Fy={eq:Gy},n1={compare:t=>e=>{const n=Dy(t)(e);return n===1?ze:n===0?an:Me},Eq0:()=>Fy},Iy=Ay(Ut)(w),By=Py(Ut)(w),r1=function(t){throw new Error(t)},o1=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=at.compare(e._1)(n._1);return r==="LT"?Me:r==="GT"?ze:at.compare(e._2)(n._2)},Eq0:()=>t}})(),My=t=>e=>ke(t._1-e._1)+ke(t._2-e._2),Io=t=>t,ms=t=>t,Re=ms("North"),Ge=ms("South"),Qr=ms("East"),Wr=ms("West"),go=Io("Rectangle"),zy=Io("Cylinder"),Qy=Io("Parallelogram"),Wy=Io("Diamond"),Oy=Io("Ellipse"),Hy=Io("Document"),$y=Io("Cloud"),i1=b(ur)(0),qy=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},_o=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},ys=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},a1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Uy=t=>{const e={top:0,bottom:0,left:0,right:0},n=t.shape==="Cloud"?{...e,top:t.h*.38}:t.shape==="Cylinder"?{...e,bottom:5}:t.shape==="Document"?{...e,bottom:t.h*.05}:e;return[{x:t.x-n.left,y:t.y-n.top},{x:t.x+t.w+n.right,y:t.y+t.h+n.bottom}]},Ci=t=>e=>{const n=$e(a=>s=>({a,b:s,len:(()=>{const u=s.y-a.y,c=s.x-a.x;return tn(c*c+u*u)})()}),t,Rt(1,t.length,t)),r=i1(U(a=>a.len)(n)),o=qy(0)(r)(e*r),i=a=>s=>u=>{let c=a,g=s,l=u,d=!0,f;for(;d;){const h=c,m=g,p=l,x=At(y=>w,y=>N=>T("Just",{head:y,tail:N}),h);if(x.tag==="Nothing"){const y=t.length-1|0;if(y>=0&&y<t.length){d=!1,f=t[y];continue}d=!1,f=p;continue}if(x.tag==="Just"){if(m<=x._1.head.len){const y=x._1.head.len<=0?0:m/x._1.head.len;d=!1,f={x:x._1.head.a.x+(x._1.head.b.x-x._1.head.a.x)*y,y:x._1.head.a.y+(x._1.head.b.y-x._1.head.a.y)*y};continue}c=x._1.tail,g=m-x._1.head.len,l=p;continue}_()}return f};return 0<t.length?T("Just",i(n)(o)(t[0])):w},Xy=t=>e=>{const n=_o(1e-6)(t.scale);return{x:(e.x-t.tx)/n,y:(e.y-t.ty)/n,w:e.w/n,h:e.h/n}},xs=t=>i1($e(e=>n=>{const r=n.y-e.y,o=n.x-e.x;return tn(o*o+r*r)},t,Rt(1,t.length,t))),Bc={scale:1,tx:0,ty:0},Vy=t=>e=>{const n=_o(4)(.15*ys(e.w)(e.h)),r=_o(1)(t.w),o=_o(1)(t.h),i=_o(1)(e.w-2*n),a=_o(1)(e.h-2*n),s=.55*ys(i/r)(a/o);return{scale:s,tx:e.x+n+(i-r*s)/2-t.x*s,ty:e.y+n+(a-o*s)/2+2.5-t.y*s}},pe=t=>{const e=At(n=>w,n=>r=>T("Just",{head:n,tail:r}),[...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,yt("Cons",r._4,n(r._6,o)));_()};return Et(Wt(ue.foldr,n(t.nodes,R)))(Uy)})(),...bn((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,yt("Cons",r._4,n(r._6,o)));_()};return Wt(ue.foldr,n(t.edges,R))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=b(r=>o=>({minX:ys(r.minX)(o.x),minY:ys(r.minY)(o.y),maxX:_o(r.maxX)(o.x),maxY:_o(r.maxY)(o.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}}_()},Yy=t=>e=>(n=>r=>o=>{let i=n,a=r,s=o,u=!0,c;for(;u;){const g=i,l=a,d=s,f=At(h=>w,h=>m=>T("Just",{head:h,tail:m}),l);if(f.tag==="Nothing"){u=!1,c=d;continue}if(f.tag==="Just"){const h=a1(f._1.head)(g.interiors);if(h.tag==="Nothing"){u=!1,c=d;continue}if(h.tag==="Just"){i=h._1,a=f._1.tail,s=(()=>{const m=Vy(pe(h._1.layout))((()=>{const p=a1(f._1.head)(g.layout.nodes);if(p.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:go};if(p.tag==="Just")return p._1;_()})());return{scale:d.scale*m.scale,tx:d.scale*m.tx+d.tx,ty:d.scale*m.ty+d.ty}})();continue}}_()}return c})(t)(e)(Bc),Ky=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},jy=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},ws=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},Zy=t=>e=>n=>r=>{const o=pe(e);return n<=0||r<=0||o.w<=0||o.h<=0?1:t?Ky(o.w/n)(o.h/r):jy(o.w/n)(o.h/r)},s1=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;if(t.widthPx<=0||t.heightPx<=0){const a=1/ws(.05)(1)(e);return{w:n.w*a,h:n.h*a}}if(r>o){const a=1/ws(.05)(1)(e);return{w:n.h*r*a,h:n.h*a}}const i=1/ws(.05)(1)(e);return{w:n.w*i,h:n.w/r*i}},u1=t=>e=>n=>r=>o=>{const i=t+o/2,a=t+e-o/2,s=t+e/2,u=n+r/2;return o>=e?s:ws(i)(a)(u)},c1=t=>e=>n=>r=>{const o=pe(t);return{x:u1(o.x)(o.w)(e.x)(e.w)(n),y:u1(o.y)(o.h)(e.y)(e.h)(r)}},ua=t=>e=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:Zy(t)(e)(n.w)(n.h)}),tx=t=>e=>n=>r=>{const o={x:r.x-t.padding,y:r.y-t.padding,w:r.w+t.padding*2,h:r.h+t.padding*2},i=s1(e)(.65)(o),a=c1(n)(o)(i.w)(i.h),s={x:a.x-i.w/2,y:a.y-i.h/2,w:i.w,h:i.h};return{focus:r,paddedFocus:o,viewport:s,camera:ua(e.widthPx>0&&e.heightPx>0)(n)(s)}},ex=t=>e=>n=>r=>o=>{const i={x:o.x*r.scale+r.tx,y:o.y*r.scale+r.ty,w:o.w*r.scale,h:o.h*r.scale},a=t.padding*r.scale,s={x:i.x-a,y:i.y-a,w:i.w+a*2,h:i.h+a*2},u=s1(e)(.7)(s),c=c1(n)(s)(u.w)(u.h),g={x:c.x-u.w/2,y:c.y-u.h/2,w:u.w,h:u.h};return{footprint:i,viewport:g,camera:ua(e.widthPx>0&&e.heightPx>0)(n)(g)}},nx=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;return t.widthPx<=0||t.heightPx<=0?ua(t.widthPx>0&&t.heightPx>0)(e)((()=>{const i=n.w*.8,a=n.h*.8;return{x:n.x+n.w/2-i/2,y:n.y+n.h/2-a/2,w:i,h:a}})()):r>o?ua(t.widthPx>0&&t.heightPx>0)(e)((()=>{const i=n.w*.8,a=n.w/r*.8;return{x:n.x+n.w/2-i/2,y:n.y+n.h/2-a/2,w:i,h:a}})()):ua(t.widthPx>0&&t.heightPx>0)(e)((()=>{const i=n.h*r*.8,a=n.h*.8;return{x:n.x+n.w/2-i/2,y:n.y+n.h/2-a/2,w:i,h:a}})())},g1=t=>t,rx=(t,e)=>({tag:t,_1:e}),Mc=t=>t,ki=(t,e)=>({tag:t,_1:e}),zc=(t,e)=>({tag:t,_1:e}),ca=Mc("Animated"),ox=Mc("StaticStill"),ix=Mc("TitleCard"),ax=zc("First"),_1=g1("Forward"),f1=g1("Backward"),sx=ki("ExitNode"),l1=ge(P)(Mt),ux=t=>mi(e=>n=>({nodes:Qe(P.compare,Be,e.nodes,n.nodes),edges:Qe(P.compare,Be,e.edges,n.edges)}))({nodes:M,edges:M})(t.keyframes),cx=t=>e=>({entering:{nodes:ar(P.compare,e.nodes,t.nodes),edges:ar(P.compare,e.edges,t.edges)},leaving:{nodes:ar(P.compare,t.nodes,e.nodes),edges:ar(P.compare,t.edges,e.edges)},surviving:{nodes:_s(P.compare,Be,t.nodes,e.nodes),edges:_s(P.compare,Be,t.edges,e.edges)}}),Ns=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},Li=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Ts=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Qc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},gx=b(t=>e=>it(P)(e)()(t))(M),_x=b(t=>e=>it(P)(e)()(t))(M),fx=(()=>{const t=mn.unfoldr(sr);return e=>t(yn("IterNode",e,ir))})(),d1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},h1=ge(P)(Mt),Wc=t=>{const e=At(n=>w,n=>r=>T("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=b(r=>o=>({minX:Ns(r.minX)(o.x),minY:Ns(r.minY)(o.y),maxX:Li(r.maxX)(o.x),maxY:Li(r.maxY)(o.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}}_()},lx=t=>e=>n=>gx(Et(Wt(ln.foldr,n))(r=>{const o=Ts(r)(t);if(o.tag==="Just")return dt(i=>!Qc(i)(e),[o._1.source,o._1.target]);if(o.tag==="Nothing")return[];_()})),dx=t=>t.kind.tag==="SendToken"?T("Just",L(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):w,hx=t=>t.tag==="DataFlow"?wt(dx)(t._1.events):[],px=t=>e=>_x(wt(n=>Qc(n._2.source)(e)||Qc(n._2.target)(e)?T("Just",n._1):w)(fx(t))),Cr=t=>{const e=At(n=>w,n=>r=>T("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=b(r=>o=>({minX:Ns(r.minX)(o.x),minY:Ns(r.minY)(o.y),maxX:Li(r.maxX)(o.x+o.w),maxY:Li(r.maxY)(o.y+o.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}}_()},ga=t=>e=>n=>{if(n.tag==="Leaf")return pe(t);const r=px(e)(n),o=[...wt(i=>{const a=d1(i)(t.nodes);return a.tag==="Just"?T("Just",{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}):w})(Wt(ln.foldr,Qe(P.compare,Be,n,lx(e)(n)(r)))),...wt(i=>{const a=Ts(i)(t.edges);return a.tag==="Just"?T("Just",Wc(a._1)):w})(Wt(ln.foldr,r))];return o.length===0?pe(t):Cr(o)},vs=t=>e=>n=>{const r=[...wt(o=>o)([(()=>{const o=Ts(n)(t.edges);return o.tag==="Just"?T("Just",Wc(o._1)):w})()]),...(()=>{const o=Ts(n)(e);if(o.tag==="Just")return wt(i=>{const a=d1(i)(t.nodes);return a.tag==="Just"?T("Just",{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}):w})([o._1.source,o._1.target]);if(o.tag==="Nothing")return[];_()})()];return r.length===0?ga(t)(e)(M):Cr(r)},Kn=t=>e=>{const n=pe(t),r=n.w/Li(1e-4)(e.zoom),o=n.h/Li(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-o/2,w:r,h:o}},mx=t=>Qe(P.compare,Be,h1(U(e=>L(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),h1(Et(t.scenes)(hx))),Oc=t=>t,yx=t=>t,p1=Oc("Linear"),kr=Oc("EaseInOutQuad"),xx=Oc("SpringBouncy"),Hc=t=>e=>n=>{const r=tn(1-e*e),o=t*r;return 1-Ni(-e*t*n)*(Dn(o*n)+e/r*fn(o*n))},wx=t=>{const e=at.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;_()})(),r=at.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;_()},bs=t=>e=>(()=>{if(t==="Linear")return yx;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-mc(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*Ni(-6*n);if(t==="SpringBouncy")return Hc(6)(.7);_()})()(wx(e)),Js=t=>t,m1=t=>t,y1=t=>t,Mn=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Cs=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},ks=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},Nx=t=>e=>{const n=ut.compare(t._1)(e._1);return n==="LT"?Me:n==="GT"?ze:at.compare(t._2)(e._2)},Tx=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},vx=y1("Hold"),bx=y1("Gap"),zn=m1("LinearLerp"),fo=m1("ComposedLogLerp"),$c=Js("Overview"),_a=Js("DiveHome"),lo=Js("DiveTransition"),Ls=Js("ActionFocus"),Jx=t=>e=>n=>{const r=t.widthPx>0&&t.heightPx>0,o=t.widthPx/Mn(1e-6)(t.heightPx),i=pe(e),a=i.w/Mn(1e-6)(n.zoom),s=i.h/Mn(1e-6)(n.zoom),u=a/Mn(1e-6)(s),c=r&&o<u?a/o:s,g=r&&o>u?s*o:a;return{x:n.center.x-g/2,y:n.center.y-c/2,w:g,h:c}},qc=t=>e=>n=>{const r=n.center.y-e.center.y,o=n.center.x-e.center.x,i=tn(o*o+r*r),a=n.zoom-e.zoom,s=a<0?-a:a;return Cs(t.minTransition)(t.maxTransition)(Mn(t.panSpeed<=0?t.minTransition:i/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:s/t.zoomSpeed))},Cx=t=>({startT:t.startT,endT:t.endT,fromCam:t.fromCam,toCam:t.toCam,easing:t.easing,interp:t.interp,intent:t.intent}),kx=b(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:St(t)(e)})([]),Ss=t=>e=>n=>{const r=Cs(0)(1)((n-t)/Mn(1e-6)(e-t));return r*r*r*(r*(r*6-15)+10)},Lx=t=>e=>{const n=t.x-e.x;return(n<0?-n<.001:n<.001)&&(()=>{const r=t.y-e.y;return(r<0?-r<.001:r<.001)&&(()=>{const o=t.w-e.w;return(o<0?-o<.001:o<.001)&&(()=>{const i=t.h-e.h;return i<0?-i<.001:i<.001})()})()})()},Sx=t=>e=>t.tag==="Just"?e.tag==="Just"&&Lx(t._1)(e._1):t.tag==="Nothing"&&e.tag==="Nothing",x1=t=>e=>n=>r=>({center:{x:r.center.x*n.scale+n.tx,y:r.center.y*n.scale+n.ty},zoom:r.zoom*pe(t).w/Mn(1e-6)(n.scale*pe(e).w)}),Uc=t=>e=>n=>r=>({center:{x:t.center.x+(e.center.x-t.center.x)*n,y:t.center.y+(e.center.y-t.center.y)*n},zoom:Ni((()=>{const o=cs(Mn(1e-6)(t.zoom));return o+(cs(Mn(1e-6)(e.zoom))-o)*r})())}),Ex=b(t=>e=>{if(t.tag==="Nothing")return T("Just",e);if(t.tag==="Just")return e.endT>t._1.endT?T("Just",e):T("Just",t._1);_()})(w),Ax=t=>e=>n=>r=>{if(t<=0)return r;const o=Ni(-t*e);return{center:{x:r.center.x+(n.center.x-r.center.x)*o,y:r.center.y+(n.center.y-r.center.y)*o},zoom:Ni((()=>{const i=cs(Mn(1e-6)(r.zoom));return i+(cs(Mn(1e-6)(n.zoom))-i)*o})())}},Xc=t=>e=>n=>e.zoom>=t.zoom?Ss(.3)(1)(n):Ss(0)(.7)(n),Px={widthPx:0,heightPx:0},Rx={padding:24,easing:kr,minimumReadableLabelPx:11,minimumVisibleLabelPx:5,labelBasePx:11,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:0},Si=t=>e=>n=>r=>o=>{const i=Jx(e)(n)(r),a=o.x-t.padding,s=o.y-t.padding;return a>=i.x&&s>=i.y&&a+o.w+t.padding*2<=i.x+i.w&&s+o.h+t.padding*2<=i.y+i.h},Gx=t=>e=>n=>r=>o=>Kf.foldlWithIndex(i=>a=>s=>{const u=(()=>{if(s.kind==="Hold"){const c=(()=>{if(i===0)return s.toCam;if(s.focus.tag==="Just"){if(s.intent==="ActionFocus")return Si(t)(e)(n)(a.prev)(s.focus._1)?a.prev:Si(t)(e)(n)({center:a.prev.center,zoom:s.toCam.zoom})(s.focus._1)?{...s.toCam,center:a.prev.center}:{...s.toCam,center:{...s.toCam.center,x:(()=>{const g=pe(n).w/Mn(1e-6)(s.toCam.zoom);if(g<=0)return s.toCam.center.x;const l=s.focus._1.x+s.focus._1.w/2,d=e.widthPx<=0?0:ks(g/4)(6*g/e.widthPx),f=a.prev.center.x+g/2-d,h=l<a.prev.center.x-g/2+d?l-d+g/2:l>f?l+d-g/2:a.prev.center.x,m=pe(n);return g>=m.w?m.x+m.w/2:Cs(m.x+g/2)(m.x+m.w-g/2)(h)})()}};if(Si(t)(e)(n)(a.prev)(s.focus._1))return a.prev;if(Si(t)(e)(n)({center:a.prev.center,zoom:s.toCam.zoom})(s.focus._1))return{...s.toCam,center:a.prev.center}}return s.toCam})();return{startT:s.startT,endT:s.endT,fromCam:c,toCam:c,easing:s.easing,interp:zn,focus:s.focus,intent:s.intent}}if(s.kind==="Gap")return{startT:s.startT,endT:s.endT,fromCam:a.prev,toCam:(()=>{const c=i+1|0,g=Mr(Ut,w,l=>l.kind==="Hold",c<1?o:Rt(c,o.length,o));if(g.tag==="Just"){const l=(i+1|0)+g._1|0;return l>=0&&l<o.length?(()=>{if(o[l].focus.tag==="Just")return Si(t)(e)(n)(a.prev)(o[l].focus._1);if(o[l].focus.tag==="Nothing")return!1;_()})()?a.prev:o[l].fromCam:a.prev}if(g.tag==="Nothing")return a.prev;_()})(),easing:s.easing,interp:zn,focus:w,intent:s.intent};_()})();return{acc:St(a.acc)(u),prev:u.toCam}})({acc:[],prev:r})(o).acc,Dx=t=>e=>n=>r=>o=>i=>{const a=(u,c)=>ks(qc(t)(u.toCam)(c.toCam))(u.endT-u.startT),s=b(u=>c=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:T("Just",c)};if(u.pending.tag==="Just"){if(!(c.fromCam.zoom===c.toCam.zoom&&c.fromCam.center.x===c.toCam.center.x&&c.fromCam.center.y===c.toCam.center.y)||(()=>{if(c.focus.tag==="Just")return Si(t)(e)(n)(u.pending._1.toCam)(c.focus._1);if(c.focus.tag==="Nothing")return!1;_()})()||(()=>{const g=u.pending._1.toCam.center.x-c.toCam.center.x;return(g<0?-g<8:g<8)&&(()=>{const l=u.pending._1.toCam.center.y-c.toCam.center.y;return(l<0?-l<8:l<8)&&(()=>{const d=u.pending._1.toCam.zoom-c.toCam.zoom;return d<0?-d<.08:d<.08})()})()})()||a(u.pending._1,c)<=0)return{acc:St(u.acc)(u.pending._1),pending:T("Just",c)};if((()=>{const g=c.startT;return ne(l=>ke(l-g)<1e-4,o)})()){const g={startT:c.startT,endT:c.startT+ks(qc(t)(u.pending._1.toCam)(c.toCam))(c.endT-c.startT),fromCam:u.pending._1.toCam,toCam:c.toCam,easing:c.easing,interp:zn,focus:c.focus,intent:c.intent},l={...c,startT:g.endT,fromCam:c.toCam};return l.startT<l.endT?{acc:St(St(u.acc)(u.pending._1))(g),pending:T("Just",l)}:{acc:St(u.acc)(u.pending._1),pending:T("Just",g)}}return{acc:St(St(u.acc)({...u.pending._1,endT:c.startT-a(u.pending._1,c)}))({startT:c.startT-a(u.pending._1,c),endT:c.startT,fromCam:u.pending._1.toCam,toCam:c.toCam,easing:c.easing,interp:zn,focus:c.focus,intent:c.intent}),pending:T("Just",c)}}_()})({acc:[],pending:w})(i);if(s.pending.tag==="Nothing")return s.acc;if(s.pending.tag==="Just")return St(s.acc)(s.pending._1);_()},Fx=t=>e=>n=>{const r=e.w+n*2,o=e.h+n*2,i=pe(t);return r<=0||o<=0||i.w<=0||i.h<=0?1:ks(i.w/r)(i.h/o)},Ix=t=>e=>n=>e.zoom>=t.zoom?Uc(t)(e)(Ss(0)(.45)(n))(Xc(t)(e)(n)):Uc(t)(e)(Ss(.55)(1)(n))(Xc(t)(e)(n)),Bx=t=>e=>n=>{const r=n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT),o=bs(n.easing)(Cs(0)(1)(r));if(n.interp==="LinearLerp")return{center:{x:n.fromCam.center.x+(n.toCam.center.x-n.fromCam.center.x)*o,y:n.fromCam.center.y+(n.toCam.center.y-n.fromCam.center.y)*o},zoom:n.fromCam.zoom+(n.toCam.zoom-n.fromCam.zoom)*o};if(n.interp==="LogLerp")return Uc(n.fromCam)(n.toCam)(o)(o);if(n.interp==="ComposedLogLerp")return Ix(n.fromCam)(n.toCam)(r);_()},Mx=t=>e=>{if(t.tag==="Just"){if(e.tag==="Just")return T("Just",Cr([t._1,e._1]));if(e.tag==="Nothing")return T("Just",t._1);_()}if(t.tag==="Nothing"){if(e.tag==="Just")return T("Just",e._1);if(e.tag==="Nothing")return w}_()},zx=b(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?T("Just",t[n]):w;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&&(!(r._1.intent==="ActionFocus"||e.intent==="ActionFocus")||(r._1.intent==="Overview"?e.intent==="Overview":r._1.intent==="DiveHome"?e.intent==="DiveHome":r._1.intent==="DiveTransition"?e.intent==="DiveTransition":r._1.intent==="ActionFocus"&&e.intent==="ActionFocus")&&Sx(r._1.focus)(e.focus))&&(()=>{const o=r._1.toCam.center.x-e.toCam.center.x;return(o<0?-o<8:o<8)&&(()=>{const i=r._1.toCam.center.y-e.toCam.center.y;return(i<0?-i<8:i<8)&&(()=>{const a=r._1.toCam.zoom-e.toCam.zoom;return a<0?-a<.08:a<.08})()})()})()?St((()=>{const o=t.length-1|0;return o<1?[]:Rt(0,o,t)})())({...r._1,endT:e.endT,focus:Mx(r._1.focus)(e.focus)}):St(t)(e)})([]),Qx=t=>{const e=Gt(n=>r=>Nx(L((()=>{if(r.intent==="DiveTransition")return 3;if(r.intent==="ActionFocus")return 2;if(r.intent==="DiveHome")return 1;if(r.intent==="Overview")return 0;_()})(),r.startT))(L((()=>{if(n.intent==="DiveTransition")return 3;if(n.intent==="ActionFocus")return 2;if(n.intent==="DiveHome")return 1;if(n.intent==="Overview")return 0;_()})(),n.startT)))(t);return 0<e.length?T("Just",e[0]):w},Vc=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:Mn(r)(Fx(e)(n)(t.padding))}),Wx=t=>e=>n=>r=>o=>i=>{const a=Vc(t)(n)(pe(n))(0),s=dt(c=>c>=0&&c<=r,kx(Gt(at.compare)([0,r,...o,...Et(i)(c=>[c.startT,c.endT])]))),u=(c,g)=>ne(l=>l.priority>=1,dt(l=>l.startT<=g&&g<l.endT,i))?tx(t)(e)(n)(Cr(c)).camera:Vc(t)(n)(Cr(c))(0);return U(Cx)(Dx(t)(e)(n)(a)(o)(zx(Gx(t)(e)(n)(a)(wt(c=>{const g=(c._1+c._2)/2;if(c._2<=c._1)return w;const l=U(d=>d.bbox)(dt(d=>d.priority===b(Tx)(0)(U(f=>f.priority)(dt(f=>f.startT<=g&&g<f.endT,i))),dt(d=>d.startT<=g&&g<d.endT,i)));return l.length===0?T("Just",{kind:bx,startT:c._1,endT:c._2,fromCam:a,toCam:a,easing:t.easing,focus:w,intent:$c}):T("Just",{kind:vx,startT:c._1,endT:c._2,fromCam:u(l,g),toCam:u(l,g),easing:t.easing,focus:T("Just",Cr(l)),intent:ne(d=>d.priority>=1,dt(d=>d.startT<=g&&g<d.endT,i))?Ls:$c})})($e(vn,s,Rt(1,s.length,s)))))))},Bo=t=>e=>n=>r=>{const o=Qx(dt(i=>r>=i.startT&&r<i.endT,n));if(o.tag==="Just")return{camera:Bx()(r)(o._1),intent:o._1.intent};if(o.tag==="Nothing"){const i=Ex(n);return i.tag==="Just"&&r>=i._1.endT?{camera:i._1.toCam,intent:i._1.intent}:{camera:(()=>{const a=Vc(t)(e)(pe(e))(0);return 0<n.length?n[0].fromCam:a})(),intent:0<n.length?n[0].intent:$c}}_()};function ho(t){return t.charCodeAt(0)}function w1(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)}}},Mo=function(t){return function(e){return e.split(t)}},fa=function(t){return t.trim()},Qn=function(t){return function(e){return e.join(t)}};var Ox=typeof Array.from=="function",Hx=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",$x=typeof String.prototype.fromCodePoint=="function",qx=typeof String.prototype.codePointAt=="function";const Ux=function(t){return qx?function(e){return e.codePointAt(0)}:t},Xx=function(t){return $x?String.fromCodePoint:t},Vx=function(t){return function(e){return Hx?function(n){for(var r="",o=n[Symbol.iterator](),i=0;i<e;++i){var a=o.next();if(a.done)return r;r+=a.value}return r}:t(e)}},Yx=function(t){return function(e){return Ox?function(n){return Array.from(n,e)}:t}},Es=t=>{const e=gr(t);if(e===0)return w;if(e===1)return T("Just",{head:ho(aa(0)(t)),tail:""});const n=ho(aa(1)(t)),r=ho(aa(0)(t));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?T("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:Ji(2)(t)}):T("Just",{head:r,tail:Ji(1)(t)})},Kx=t=>{const e=Es(t);return e.tag==="Just"?T("Just",L(e._1.head,e._1.tail)):w},jx=t=>mn.unfoldr(Kx)(t),N1=Ux(t=>{const e=ho(aa(0)(t));if(55296<=e&&e<=56319&&gr(t)>1){const n=ho(aa(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),un=Yx(jx)(N1),T1=t=>un(t).length,Yc=t=>cr(t>=0&&t<=65535?w1(t):t<0?"\0":"\uFFFF"),Zx=Xx(t=>t<=65535?Yc(t):Yc(Nr(t-65536|0,1024)+55296|0)+Yc(co(t-65536|0)(1024)+56320|0)),v1=t=>e=>{if(t<1)return"";const n=Es(e);return n.tag==="Just"?Zx(n._1.head)+v1(t-1|0)(n._1.tail):e},De=Vx(v1),tw=t=>e=>e===""?w:T("Just",N1(e)),ew=t=>t,b1=t=>e=>{const n=e.vw/e.vh,r=e.vh*t,o={...e,vx:e.vx-(r-e.vw)/2,vw:r},i=e.vw/t,a={...e,vy:e.vy-(i-e.vh)/2,vh:i};return t<=0||e.vw<=0||e.vh<=0?e:t>n?o:t<n?a:e},J1=t=>e=>t.width<=0||t.height<=0?e:b1(t.width/t.height)(e),nw=t=>e=>{if(e.scene.tag==="Structural")return e.scene._1.to;if(e.scene.tag==="DataFlow")return e.scene._1.keyframe;if(e.scene.tag==="Hold")return e.scene._1;if(e.scene.tag==="EnterNode"||e.scene.tag==="ExitNode"||e.scene.tag==="StepScene")return t;_()},C1=t=>t,As=(t,e)=>({tag:t,_1:e}),Zn=(t,e,n)=>({tag:t,_1:e,_2:n}),k1=t=>t,zo=(t,e,n,r,o,i,a,s,u)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:a,_7:s,_8:u}),Kc=k1("PlopIn"),rw=k1("PlopOut"),ow=C1("DiveIn"),iw=C1("DiveOut"),xe=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},en=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},L1=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},S1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Qo=is(xi),E1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},aw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},A1=(()=>{const t=mn.unfoldr(sr);return e=>t(yn("IterNode",e,ir))})(),sw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},_r=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},Ps=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},uw=t=>t,P1=t=>e=>n=>n<t?0:n>1-e?1:(n-t)/xe(.05)(1-t-e),cw=t=>e=>t.labelBasePx*.62*rt(b(L1)(0)(U(T1)(Et(e)(n=>Mo(`
3
- `)(n))))),R1=t=>e=>{if(t.length===0)return e;const n=6.82*rt(b(L1)(0)(U(T1)(Et(t)(g=>Mo(`
4
- `)(g))))),r=n/2+14,o=e.y+e.h/2,i=o-5-8,a=xe(e.y+e.h)(i+12.6)-en(e.y)(i-12.6),s=e.x+e.w/2,u=s+13+n/2,c=xe(e.x+e.w)(u+r)-en(e.x)(u-r);return{x:s-c/2,y:o-a/2,w:c,h:a}},jc=(()=>{const t=b(e=>n=>{const r=e.previous.tag==="Just"&&ke(e.previous._1.endT-n.startT)<1e-4?{...n,fromCam:e.previous._1.toCam}:n;return{previous:T("Just",r),spans:St(e.spans)(r)}})({previous:w,spans:[]});return e=>t(e).spans})(),G1=t=>e=>n=>{const r=(t+e)/2,o=n-r,i=o<0?-1:1,a=(e-t)/2,s=a*.15,u=a-s,c=o<0?-o:o;return e<=t?(t+e)/2:c<=u?n:r+i*(a-s*Ni(-(c-u)/s))},Zc=t=>e=>{const n=S1(e)(t.keyframes);if(n.tag==="Nothing")return M;if(n.tag==="Just")return n._1.nodes;_()},D1=t=>e=>{if(e<t.startT)return Zn("AtKeyframe",t.initialKeyframe);const n=Kt(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Zn("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Zn("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return Zn("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode"||n._1.scene.tag==="StepScene")return Zn("AtKeyframe",t.initialKeyframe);_()}if(n.tag==="Nothing")return Zn("AtKeyframe",b(nw)(t.initialKeyframe)(t.spans));_()},Rs=t=>e=>n=>r=>{const o=Kt(i=>Qo(i.path)(e)&&(ke(i.endT-n)<1e-4||ke(i.startT-r)<1e-4))(t.segments);if(o.tag==="Just")return T("Just",o._1);if(o.tag==="Nothing")return Kt(i=>Qo(i.path)(e))(t.segments);_()},tg=t=>e=>{const n=S1(e)(t.keyframes);if(n.tag==="Nothing")return M;if(n.tag==="Just")return n._1.edges;_()},F1=(()=>{const t=(n,r,o,i,a)=>{let s=n,u=r,c=o,g=i,l=a,d=!0,f;for(;d;){if(s===0){const h=At(m=>w,m=>p=>T("Just",{head:m,tail:p}),u);if(h.tag==="Nothing"){d=!1,f=[];continue}if(h.tag==="Just"){s=1,u=h._1.head,c=h._1.head,g=!1,l=h._1.tail;continue}_()}if(s===1){const h=u,m=c,p=g,x=l,y=At(N=>w,N=>v=>T("Just",{head:N,tail:v}),x);if(y.tag==="Just"&&m.intent==="Overview"&&y._1.head.intent==="Overview"&&!(m.fromCam.zoom===m.toCam.zoom&&m.fromCam.center.x===m.toCam.center.x&&m.fromCam.center.y===m.toCam.center.y)&&!(y._1.head.fromCam.zoom===y._1.head.toCam.zoom&&y._1.head.fromCam.center.x===y._1.head.toCam.center.x&&y._1.head.fromCam.center.y===y._1.head.toCam.center.y)&&ke(m.toCam.center.x-y._1.head.fromCam.center.x)<1e-4&&ke(m.toCam.center.y-y._1.head.fromCam.center.y)<1e-4&&ke(m.toCam.zoom-y._1.head.fromCam.zoom)<1e-4&&ke(m.endT-y._1.head.startT)<1e-4){s=1,u=h,c=y._1.head,g=!0,l=y._1.tail;continue}d=!1,f=[p?{...h,endT:m.endT,toCam:m.toCam,easing:m.easing,interp:zn}:h,...e(x)]}}return f},e=n=>t(0,n);return e})(),gw=t=>e=>{const n=pe(e),r=J1({width:t.widthPx,height:t.heightPx})({vx:n.x,vy:n.y,vw:n.w,vh:n.h});return{w:r.vw,h:r.vh}},eg=t=>e=>n=>r=>{const o=xe(n.center.x-r.x)(r.x+r.w-n.center.x),i=xe(n.center.y-r.y)(r.y+r.h-n.center.y),a=gw(t)(e);return en(o<=0?n.zoom:a.w/(o*2))(i<=0?n.zoom:a.h/(i*2))},I1=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r,u=zr(s);if(u.tag==="Just"&&u._1.last.intent==="Overview"){n=[u._1.last,...a],r=u._1.init;continue}o=!1,i={prefix:s,overview:a}}return i},_w=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r,u=At(c=>w,c=>g=>T("Just",{head:c,tail:g}),s);if(u.tag==="Just"&&u._1.head.intent==="Overview"){n=St(a)(u._1.head),r=u._1.tail;continue}o=!1,i={overview:a,rest:s}}return i},Wo=t=>e=>n=>r=>o=>{const i={width:e.widthPx,height:e.heightPx},a=J1(i)((()=>{const s=Kn(n)(o);return{vx:s.x,vy:s.y,vw:s.w,vh:s.h}})());return t.labelBasePx*r.placement.scale*(i.width<=0||a.vw<=0?0:i.width/a.vw)},fw=t=>e=>n=>r=>o=>{const i=Wo(t)(e)(n)(r)(o);return i<=t.minimumReadableLabelPx?o:{...o,zoom:o.zoom*t.minimumReadableLabelPx/i}},lw=t=>e=>n=>{const r=wt(o=>o.scene.tag==="StepScene"?T("Just",o.startT):w)(e.spans);return b(o=>i=>{const a=Mr(Ut,w,s=>s.startT<i+1e-4&&s.endT>=i-1e-4,o);if(a.tag==="Nothing")return o;if(a.tag==="Just"){const s=a._1>=0&&a._1<o.length?T("Just",o[a._1]):w;if(s.tag==="Nothing")return o;if(s.tag==="Just"){if(s._1.startT>=i-1e-4)return o;const u=Kt(m=>m>i+1e-4)(r),c=(()=>{if(u.tag==="Nothing")return e.endT;if(u.tag==="Just")return u._1;_()})(),g=Gt(at.compare)(wt(m=>m.startT>=i-1e-4&&m.startT<c-1e-4&&(m.target.tag==="RelabelWindow"||(m.target.tag==="EdgeWindow"?m.target._2.tag==="Extend":m.target.tag==="TokenWindow"||m.target.tag==="FillWindow"))?T("Just",m.startT):w)(e.windows)),l=0<g.length?g[0]:i,d=a._1+1|0,f=d<1?o:Rt(d,o.length,o),h=Mr(Ut,w,m=>m.intent==="ActionFocus"&&m.startT>=l-1e-4&&m.startT<c-1e-4,f);if(h.tag==="Nothing")return o;if(h.tag==="Just"){const m=h._1>=0&&h._1<f.length?T("Just",f[h._1]):w;if(m.tag==="Nothing")return o;if(m.tag==="Just"){const p=(a._1+h._1|0)+2|0,x=p<1?o:Rt(p,o.length,o),y=s._1.toCam.zoom===m._1.toCam.zoom&&s._1.toCam.center.x===m._1.toCam.center.x&&s._1.toCam.center.y===m._1.toCam.center.y?s._1.fromCam:s._1.toCam,N=St(a._1<1?[]:Rt(0,a._1,o))({...s._1,endT:i,toCam:y}),v=m._1.startT-i;if(v<=1e-4)return[...N,{...m._1,fromCam:y},...x];const J=y.zoom===m._1.toCam.zoom&&y.center.x===m._1.toCam.center.x&&y.center.y===m._1.toCam.center.y,k=J?i+0:i+en(v)(qc(t)(y)(m._1.toCam)),S={...m._1,startT:k,endT:m._1.startT,fromCam:m._1.toCam,toCam:m._1.toCam},A={...m._1,startT:i,endT:k,fromCam:y};return[...N,...J?[]:[A],...S.endT>S.startT+1e-4?[S]:[],{...m._1,fromCam:m._1.toCam},...x]}}}}_()})(n)(r)},dw=t=>e=>n=>r=>({...r,fromCam:x1(t)(e)(n)(r.fromCam),toCam:x1(t)(e)(n)(r.toCam)}),B1=t=>e=>t.widthPx<=0?0:en(e/4)(32*e/t.widthPx),hw=t=>e=>n=>r=>o=>{const i=B1(e)(n),a=r+n/2-i;return o.x<r-n/2+i?o.x-i+n/2:o.x+o.w>a?o.x+o.w+i-n/2:r},pw=t=>e=>n=>ne(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),mw=t=>e=>n=>ne(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),yw=t=>e=>n=>ne(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),xw=t=>e=>n=>ne(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),Gs=t=>e=>n=>ne(r=>n(r)&&e>=r.startT&&e<r.endT,t),ww=t=>e=>n=>{if(e.length===0)return n;const r=en(160)(cw(t)(e)+31)/2,o=en(40)(t.labelBasePx*1.2+23);return{x:n.x-r,y:n.y-o,w:n.w+r*2,h:n.h+o*2}},Nw=t=>e=>n=>{const r=t.padding*.75,o=rt(8);return as(i=>{if(i.target.tag==="NodeWindow")return[];if(i.target.tag==="RelabelWindow")return[{startT:i.startT,endT:i.endT,bbox:ga(e)(n)(ee("Node",1,1,i.target._1,void 0,M,M)),priority:1}];if(i.target.tag==="EdgeWindow"){if(i.target._2.tag==="Extend")return[{startT:i.startT,endT:i.endT,bbox:vs(e)(n)(i.target._1),priority:1}];if(i.target._2.tag==="Retract")return[];_()}if(i.target.tag==="TokenWindow"){const a=E1(i.target._2)(e.edges);if(a.tag==="Just"){const s=(()=>{if(i.target._3==="Forward")return a._1;if(i.target._3==="Backward")return re(a._1);_()})();return Et(Yt(0,7))(u=>{const c=i.startT+(i.endT-i.startT)*(rt(u)/o),g=(()=>{const l=i.startT+(i.endT-i.startT)*(rt(u+1|0)/o);return{startT:c,endT:l,box:(()=>{const d=Ci(s)(P1(i.target._7)(i.target._8)(((c+l)/2-i.startT)/xe(1e-4)(i.endT-i.startT)));if(d.tag==="Just")return{x:d._1.x-r,y:d._1.y-r,w:0+r*2,h:0+r*2};if(d.tag==="Nothing")return{x:0,y:0,w:0,h:0};_()})()}})();return[{startT:g.startT,endT:g.endT,bbox:R1(i.target._6)(g.box),priority:1}]})}if(a.tag==="Nothing")return[{startT:i.startT,endT:i.endT,bbox:R1(i.target._6)(vs(e)(n)(i.target._2)),priority:1}];_()}if(i.target.tag==="FillWindow")return[{startT:i.startT,endT:i.endT,bbox:ww(t)(i.target._3)(ga(e)(n)(ee("Node",1,1,i.target._2,void 0,M,M))),priority:1}];_()})},Tw=t=>e=>n=>r=>o=>i=>{if(o.tag==="Nothing")return i.zoom;if(o.tag==="Just")return xe(0)(eg(e)(n)(i)((()=>{const a=t.padding*r.placement.scale;return{x:o._1.x-a,y:o._1.y-a,w:o._1.w+a*2,h:o._1.h+a*2}})()));_()},vw=t=>e=>{const n=D1(t)(e);if(n.tag==="AtKeyframe")return Zc(t)(n._1);if(n.tag==="InTransition")return Qe(P.compare,Be,Zc(t)(n._1),Zc(t)(n._2));_()},bw=t=>e=>n=>Gs(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n&&r.target._2==="PlopOut")?!0:mw(t.windows)(e)(n)?!1:Gs(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n)?!0:yw(t.windows)(e)(n)?!1:aw(n)(vw(t)(e)),M1=t=>e=>wt(n=>bw(t)(e)(n._1)?T("Just",{x:n._2.x,y:n._2.y,w:n._2.w,h:n._2.h}):w)(A1(t.layout.nodes)),Jw=t=>e=>{const n=M1(t)(e);return n.length===0?w:T("Just",Cr(n))},Cw=t=>wt(e=>{const n=Jw(t)(xe(e.startT)(e.endT-1e-4));if(n.tag==="Nothing")return w;if(n.tag==="Just")return T("Just",{startT:e.startT,endT:e.endT,bbox:n._1,priority:0});_()}),kw=t=>e=>n=>r=>o=>[...Cw(o)(dt(i=>i.startT>=o.startT&&i.endT<=o.endT,r.spans)),...Nw(t)(o.layout)(n)(o.windows)],Lw=t=>e=>n=>r=>o=>i=>Wx(t)(e)(i.layout)(o.endT)(wt(a=>a.scene.tag==="StepScene"?T("Just",a.startT):w)(i.spans))(kw(t)(n)(r)(o)(i)),Sw=t=>e=>{const n=D1(t)(e);if(n.tag==="AtKeyframe")return tg(t)(n._1);if(n.tag==="InTransition")return Qe(P.compare,Be,tg(t)(n._1),tg(t)(n._2));_()},Ew=t=>e=>n=>Gs(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n)?!0:pw(t.windows)(e)(n)?!1:Gs(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._1===n)?!0:xw(t.windows)(e)(n)?!1:sw(n)(Sw(t)(e)),Aw=t=>e=>{const n=[...M1(t)(e),...wt(r=>Ew(t)(e)(r._1)?T("Just",Wc(r._2)):w)(A1(t.layout.edges))];return n.length===0?w:T("Just",Cr(n))},Pw=t=>e=>n=>{const r=Kn(t)(n);return e.x>=r.x&&e.x+e.w<=r.x+r.w},z1=t=>e=>n=>r=>n>=e?_r(t+e-n/2)(t+n/2)(r):t+e/2,Q1=t=>e=>n=>r=>{if((()=>{const a=Kn(e)(n);return r.x>=a.x&&r.y>=a.y&&r.x+r.w<=a.x+a.w&&r.y+r.h<=a.y+a.h})())return n;const o={...n,zoom:en(n.zoom)(eg(t)(e)({...n,center:{x:r.x+r.w/2,y:r.y+r.h/2}})(r))},i=Kn(e)(o);return{...o,center:{x:z1(r.x)(r.w)(i.w)(n.center.x),y:z1(r.y)(r.h)(i.h)(n.center.y)}}},W1=t=>e=>n=>r=>o=>i=>a=>{if(o.tag==="Nothing")return a;if(o.tag==="Just"){const s=t.padding*r.placement.scale,u={x:o._1.x-s,y:o._1.y-s,w:o._1.w+s*2,h:o._1.h+s*2},c={x:u.x+u.w/2,y:u.y+u.h/2},g={...a,center:c},l={...g,zoom:eg(e)(n)(g)(u)},d=Kn(n)(l);return i.tag==="Nothing"?{...l,center:{x:d.w>=o._1.w?o._1.x+o._1.w/2:_r(o._1.x+d.w/2)(o._1.x+o._1.w-d.w/2)(c.x),y:d.h>=o._1.h?o._1.y+o._1.h/2:_r(o._1.y+d.h/2)(o._1.y+o._1.h-d.h/2)(c.y)}}:i.tag==="Just"?{...l,center:{x:d.w>=o._1.w?o._1.x+o._1.w/2:_r(o._1.x+d.w/2)(o._1.x+o._1.w-d.w/2)(i._1.x+i._1.w/2),y:d.h>=o._1.h?o._1.y+o._1.h/2:_r(o._1.y+d.h/2)(o._1.y+o._1.h-d.h/2)(i._1.y+i._1.h/2)}}:{...l,center:{x:(()=>{if(d.w>=o._1.w)return o._1.x+o._1.w/2;_()})(),y:(()=>{if(d.h>=o._1.h)return o._1.y+o._1.h/2;_()})()}}}_()},O1=t=>e=>n=>{const r=t.x+t.w/2,o=n>=t.w?{lo:r,hi:r}:{lo:t.x+n/2,hi:t.x+t.w-n/2};if(n>=e.w){const u=xe(o.lo)(e.x+e.w-n/2),c=en(o.hi)(e.x+n/2);return u<=c?{lo:u,hi:c}:o}const i=e.x+e.w/2;if(n>=e.w){const u=xe(o.lo)(i),c=en(o.hi)(i);return u<=c?{lo:u,hi:c}:o}const a=xe(o.lo)(e.x+n/2),s=en(o.hi)(e.x+e.w-n/2);return a<=s?{lo:a,hi:s}:o},Rw=t=>e=>n=>n.endT<=t||n.startT>=e?w:T("Just",{...n,startT:xe(t)(n.startT),endT:en(e)(n.endT)}),Gw=t=>e=>n=>r=>o=>i=>wt(Rw(i.startT)(i.endT))(U(dw(n)(i.layout)(i.placement))(Lw(t)(e)(r)(i.edgeEndpoints)(o)(i))),H1=t=>e=>n=>r=>{const o=pe(t),i=en(r.zoom)(o.w/xe(1e-4)(e.w));return{...r,center:{...r.center,x:(()=>{const a=O1(o)(e)(o.w/xe(1e-4)(i));return _r(a.lo)(a.hi)(n.center.x)})()},zoom:i}},Dw=t=>e=>n=>r=>o=>i=>a=>s=>{const u=B1(e)(s),c=pe(n),g={x:c.x-u,y:c.y-u,w:c.w+u*2,h:c.h+u*2},l=(()=>{if(o.tag==="Nothing")return a.center.x;if(o.tag==="Just")return hw()(e)(s)(i.center.x)(o._1);_()})();if(r.tag==="Nothing"){const d=g.x+g.w/2;return s>=g.w?_r(d)(d)(l):_r(g.x+s/2)(g.x+g.w-s/2)(l)}if(r.tag==="Just"){const d={x:r._1.x-u,y:r._1.y-u,w:r._1.w+u*2,h:r._1.h+u*2};if(s<d.w){const h=g.x+g.w/2;return s>=g.w?_r(h)(h)(l):_r(g.x+s/2)(g.x+g.w-s/2)(l)}const f=O1(g)(d)(s);return _r(f.lo)(f.hi)(l)}_()},Fw=t=>e=>n=>r=>o=>i=>a=>{const s=Kn(n)(a);return s.w<=0?a:{...a,center:{...a.center,x:Dw()(e)(n)(r)(o)(i)(a)(s.w)}}},Iw=t=>e=>n=>{const r=pe(t),o=r.h/xe(1e-4)(n.zoom),i=r.w/xe(1e-4)(n.zoom);return{...n,center:{x:i>=e.w?e.x+e.w/2:G1(e.x+i/2)(e.x+e.w-i/2)(n.center.x),y:o>=e.h?e.y+e.h/2:G1(e.y+o/2)(e.y+e.h-o/2)(n.center.y)}}},Oo=t=>e=>n=>Iw(t)((()=>{const r=e*n.placement.scale,o=pe(n.layout);return{x:o.x*n.placement.scale+n.placement.tx-r,y:o.y*n.placement.scale+n.placement.ty-r,w:o.w*n.placement.scale+r*2,h:o.h*n.placement.scale+r*2}})()),Bw=t=>e=>n=>r=>{const o=Kn(t)(r),i=pe(t),a=s=>{const u=Oo(t)(e)(n)(s);return Oo(t)(e)(n)({...u,zoom:xe(u.zoom)(xe(i.w/xe(1e-4)(2*en(u.center.x-o.x)(o.x+o.w-u.center.x)))(i.h/xe(1e-4)(2*en(u.center.y-o.y)(o.y+o.h-u.center.y))))})};return s=>a(a(s))},Mw=t=>e=>n=>r=>Oo(n)(t.padding)(r)(ex(t)(e)(n)(r.placement)(pe(r.layout)).camera),$1=t=>e=>n=>r=>o=>{const i=Mw(t)(e)(n)(o),a=Kt(s=>s.direction==="DiveIn"&&Qo(s.childPath)(o.path))(r.dives);if(a.tag==="Just"){const s=Rs(r)(a._1.parentPath)(a._1.startT)(a._1.endT);if(s.tag==="Just"){const u=Ps(a._1.node)(s._1.layout.nodes);if(u.tag==="Just"){const c=u._1.w*s._1.placement.scale,g=u._1.h*s._1.placement.scale,l=en(c)(g*2),d=nx(e)(n)({h:g,w:l,x:u._1.x*s._1.placement.scale+s._1.placement.tx+(c-l)*.5,y:u._1.y*s._1.placement.scale+s._1.placement.ty});return Bw(n)(t.padding)(o)(d)(d.zoom>i.zoom?d:i)}if(u.tag==="Nothing")return i;_()}if(s.tag==="Nothing")return i;_()}if(a.tag==="Nothing")return i;_()},q1=t=>e=>n=>r=>o=>{const i=Kn(n)(o);return(()=>{const a=pe(r.layout),s=a.x*r.placement.scale+r.placement.tx,u=a.y*r.placement.scale+r.placement.ty;return s>=i.x&&u>=i.y&&s+a.w*r.placement.scale<=i.x+i.w&&u+a.h*r.placement.scale<=i.y+i.h})()&&Wo(t)(e)(n)(r)(o)>=t.minimumReadableLabelPx},U1=t=>e=>n=>r=>o=>i=>q1(t)(e)(n)(r)(o)?o:fw(t)(e)(n)(r)(i),zw=t=>e=>n=>{const r=_w([])(n),o=At(u=>w,u=>c=>T("Just",{head:u,tail:c}),r.rest),i=r.overview.length-1|0,a=i>=0&&i<r.overview.length?T("Just",r.overview[i]):w,s=0<r.overview.length?T("Just",r.overview[0]):w;if(s.tag==="Just"){if(a.tag==="Just"){if(o.tag==="Just")return ke(s._1.startT-e.startT)<1e-4&&o._1.head.intent==="ActionFocus"?[{startT:s._1.startT,endT:a._1.endT,fromCam:t,toCam:t,easing:s._1.easing,interp:zn,intent:_a},{...o._1.head,fromCam:t},...o._1.tail]:n;if(o.tag==="Nothing"&&ke(s._1.startT-e.startT)<1e-4)return[{startT:s._1.startT,endT:a._1.endT,fromCam:t,toCam:t,easing:s._1.easing,interp:zn,intent:_a}]}return n}if(s.tag==="Nothing"&&a.tag==="Nothing"&&o.tag==="Just"&&ke(o._1.head.startT-e.startT)<1e-4&&o._1.head.intent==="ActionFocus"){const u=At(c=>w,c=>g=>T("Just",{head:c,tail:g}),o._1.tail);if(u.tag==="Nothing")return[{startT:o._1.head.startT,endT:o._1.head.endT,fromCam:t,toCam:t,easing:o._1.head.easing,interp:zn,intent:_a}];if(u.tag==="Just")return[{startT:o._1.head.startT,endT:o._1.head.endT,fromCam:t,toCam:t,easing:o._1.head.easing,interp:zn,intent:_a},{...u._1.head,fromCam:t},...u._1.tail];_()}return n},Qw=t=>e=>{const n=At(r=>w,r=>o=>T("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{...n._1.head,fromCam:t},...n._1.tail];_()},Ww=t=>e=>{const n=o=>i=>a=>{let s=o,u=i,c=a,g=!0,l;for(;g;){const d=s,f=u,h=At(m=>w,m=>p=>T("Just",{head:m,tail:p}),c);if(h.tag==="Nothing"){g=!1,l=St(d)(f);continue}if(h.tag==="Just"){if(f.intent==="Overview"&&h._1.head.intent==="ActionFocus"&&ke(f.endT-h._1.head.startT)<1e-4&&f.fromCam.zoom===f.toCam.zoom&&f.fromCam.center.x===f.toCam.center.x&&f.fromCam.center.y===f.toCam.center.y&&(()=>{const m=h._1.head.startT;return!(h._1.head.fromCam.zoom===h._1.head.toCam.zoom&&h._1.head.fromCam.center.x===h._1.head.toCam.center.x&&h._1.head.fromCam.center.y===h._1.head.toCam.center.y)&&ne(p=>ke(p.startT-m)<1e-4&&(p.target.tag==="RelabelWindow"?!0:p.target.tag==="EdgeWindow"?p.target._2.tag==="Extend":p.target.tag==="TokenWindow"||p.target.tag==="FillWindow"),t.windows)})()){const m=h._1.head.startT,p=Gt(at.compare)(wt(v=>v.target.tag==="EdgeWindow"&&v.target._2.tag==="Extend"&&ke(v.endT-m)<1e-4?T("Just",v.startT):w)(t.windows)),x=0<p.length?p[0]:m,y=xe(f.startT)(x-(h._1.head.endT-h._1.head.startT)),N={...f,endT:y};s=St(N.endT>N.startT?St(d)(N):d)({...h._1.head,startT:y,endT:x}),u={...h._1.head,startT:x,fromCam:h._1.head.toCam},c=h._1.tail;continue}s=St(d)(f),u=h._1.head,c=h._1.tail;continue}_()}return l},r=At(o=>w,o=>i=>T("Just",{head:o,tail:i}),e);if(r.tag==="Nothing")return[];if(r.tag==="Just")return n([])(r._1.head)(r._1.tail);_()},Ow=t=>e=>n=>r=>o=>i=>{const a=pe(r.layout),s={x:a.x*r.placement.scale+r.placement.tx,y:a.y*r.placement.scale+r.placement.ty,w:a.w*r.placement.scale,h:a.h*r.placement.scale},u=H1(n)(s)(o)(i);return s.w/xe(1e-4)(s.h)>=.33&&i.zoom/xe(1e-4)(u.zoom)<=1.25&&Kn(n)(u).w>=s.w-.001&&Wo(t)(e)(n)(r)(u)>=t.minimumReadableLabelPx*.85?u:i},Hw=t=>e=>n=>r=>o=>i=>a=>{const s=pe(r.layout),u=s.w*r.placement.scale,c=u/xe(1e-4)(s.h*r.placement.scale);if(o.tag==="Nothing")return a;if(o.tag==="Just"){if(Pw(n)(o._1)(a))return a;const g=H1(n)(o._1)(i)(a);return a.zoom/xe(1e-4)(g.zoom)<=1.25&&(Wo(t)(e)(n)(r)(g)>=t.minimumReadableLabelPx-.001||o._1.w>=u-.001&&c>=.33&&Wo(t)(e)(n)(r)(g)>=t.minimumReadableLabelPx*.85)?g:a}_()},$w=t=>e=>n=>r=>o=>i=>a=>{const s={...a,center:(()=>{if(i.tag==="Nothing")return a.center;if(i.tag==="Just")return{x:i._1.x+i._1.w/2,y:i._1.y+i._1.h/2};_()})()},u=Wo(t)(e)(n)(r)(s);return Fw()(e)(n)(o)(i)(a)(Hw(t)(e)(n)(r)(o)(a)(Ow(t)(e)(n)(r)(a)(u<=0?s:{...s,zoom:en(s.zoom*t.minimumReadableLabelPx/u)(Tw(t)(e)(n)(r)(i)(s))})))},ng=t=>e=>n=>r=>o=>i=>a=>r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?W1(t)(e)(n)(r)(o)(i)(a):q1(t)(e)(n)(r)(a)?a:$w(t)(e)(n)(r)(o)(i)(a),X1=t=>{const e=n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=i,g=At(l=>w,l=>d=>T("Just",{head:l,tail:d}),c);if(g.tag==="Just"&&g._1.head.intent==="Overview"){o=St(u)(g._1.head),i=g._1.tail;continue}a=!1,s={overview:u,rest:c}}return s};return(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=At(g=>w,g=>l=>T("Just",{head:g,tail:l}),i);if(c.tag==="Nothing"){a=!1,s=u;continue}if(c.tag==="Just"){if(c._1.head.intent==="Overview"){const g=e([c._1.head])(c._1.tail),l=At(h=>w,h=>m=>T("Just",{head:h,tail:m}),g.rest),d=u.length-1|0,f=d>=0&&d<u.length?T("Just",u[d]):w;if(f.tag==="Just"&&l.tag==="Just"&&f._1.intent==="ActionFocus"&&(()=>{const h=g.overview.length-1|0;return l._1.head.intent==="ActionFocus"&&(h>=0&&h<g.overview.length&&0<g.overview.length?g.overview[h].endT-g.overview[0].startT<=1.0001:!0)})()&&0<g.overview.length){const h=g.overview.length-1|0;if(h>=0&&h<g.overview.length){o=St(u)({startT:g.overview[0].startT,endT:g.overview[h].endT,fromCam:f._1.toCam,toCam:f._1.toCam,easing:g.overview[0].easing,interp:zn,intent:Ls}),i=[{...l._1.head,fromCam:f._1.toCam},...l._1.tail];continue}}o=[...u,...g.overview],i=g.rest;continue}o=St(u)(c._1.head),i=c._1.tail;continue}_()}return s})([])(t)},qw=t=>e=>n=>{const r=I1([])(n),o=r.overview.length-1|0;if(o>=0&&o<r.overview.length){if(0<r.overview.length){const i=r.prefix.length-1|0;if(i>=0&&i<r.prefix.length&&r.prefix[i].intent==="ActionFocus"&&ke(r.overview[o].endT-e.endT)<1e-4)return[...r.prefix,{startT:r.overview[0].startT,endT:r.overview[o].endT,fromCam:r.prefix[i].toCam,toCam:r.prefix[i].toCam,easing:r.overview[0].easing,interp:zn,intent:Ls}]}return n}return 0<r.overview.length&&r.prefix.length-1|0,n},V1=t=>e=>n=>{const r=I1([])(n),o=r.overview.length-1|0;if(o>=0&&o<r.overview.length){if(0<r.overview.length){const i=r.prefix.length-1|0;if(i>=0&&i<r.prefix.length&&(()=>{const a=r.overview[o].endT;return r.prefix[i].intent==="ActionFocus"&&(()=>{const s=r.overview.length-1|0;return ne(u=>u.direction==="DiveIn"&&Qo(u.parentPath)(t.path)&&ke(u.startT-a)<1e-4,e)&&(s>=0&&s<r.overview.length&&0<r.overview.length?r.overview[s].endT-r.overview[0].startT<=1.0001:!0)})()})())return[...r.prefix,{startT:r.overview[0].startT,endT:r.overview[o].endT,fromCam:r.prefix[i].toCam,toCam:r.prefix[i].toCam,easing:r.overview[0].easing,interp:zn,intent:Ls}]}return n}return n},Y1=t=>e=>{const n=e.fromCam.zoom===e.toCam.zoom&&e.fromCam.center.x===e.toCam.center.x&&e.fromCam.center.y===e.toCam.center.y?(e.startT+e.endT)/2:e.endT+1e-4,r=wt(o=>o.target.tag==="RelabelWindow"?T("Just",ga(t.layout)(t.edgeEndpoints)(ee("Node",1,1,o.target._1,void 0,M,M))):o.target.tag==="EdgeWindow"?o.target._2.tag==="Extend"?T("Just",vs(t.layout)(t.edgeEndpoints)(o.target._1)):w:o.target.tag==="TokenWindow"?T("Just",(()=>{const i=[...wt(a=>{const s=Ps(a)(t.layout.nodes);return s.tag==="Just"?T("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):w})([o.target._4,o.target._5]),...(()=>{const a=E1(o.target._2)(t.layout.edges),s=P1(o.target._7)(o.target._8)((n-o.startT)/xe(1e-4)(o.endT-o.startT)),u=(()=>{if(a.tag==="Just")return Ci((()=>{if(o.target._3==="Forward")return a._1;if(o.target._3==="Backward")return re(a._1);_()})())(s);if(a.tag==="Nothing")return w;_()})();return u.tag==="Just"?[{x:u._1.x,y:u._1.y,w:0,h:0}]:[]})()];return i.length===0?vs(t.layout)(t.edgeEndpoints)(o.target._2):Cr(i)})()):o.target.tag==="FillWindow"?T("Just",ga(t.layout)(t.edgeEndpoints)(ee("Node",1,1,o.target._2,void 0,M,M))):w)(dt(o=>o.startT<=n&&n<o.endT,t.windows));return r.length===0?w:T("Just",(()=>{const o=Cr(r);return{x:o.x*t.placement.scale+t.placement.tx,y:o.y*t.placement.scale+t.placement.ty,w:o.w*t.placement.scale,h:o.h*t.placement.scale}})())},rg=t=>e=>{const n=Aw(t)(e.endT+1e-4);return n.tag==="Just"?T("Just",{x:n._1.x*t.placement.scale+t.placement.tx,y:n._1.y*t.placement.scale+t.placement.ty,w:n._1.w*t.placement.scale,h:n._1.h*t.placement.scale}):w},Uw=t=>e=>n=>r=>o=>{const i=rg(r)(o),a=s=>{const u=Wo(t)(e)(n)(r)(s),c=u<=0||u>=t.minimumReadableLabelPx?s:{...s,zoom:s.zoom*t.minimumReadableLabelPx/u};return i.tag==="Just"&&(()=>{const g=Kn(n)(c);return!(i._1.x>=g.x&&i._1.y>=g.y&&i._1.x+i._1.w<=g.x+g.w&&i._1.y+i._1.h<=g.y+g.h)})()?s:c};return o.intent==="DiveHome"||o.intent==="ActionFocus"&&!(r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0)?o:{...o,fromCam:a(o.fromCam),toCam:a(o.toCam)}},Xw=t=>e=>n=>r=>o=>i=>{const a=Y1(r)(i),s=rg(r)(i),u=c=>{const g=W1(t)(e)(n)(r)(s)(a)(c);return{...g,zoom:en(o.zoom)(g.zoom)}};return{...i,fromCam:u(i.fromCam),toCam:u(i.toCam)}},Vw=t=>e=>n=>r=>o=>i=>i.intent==="ActionFocus"?Xw(t)(e)(n)(r)(o)(i):{...i,fromCam:U1(t)(e)(n)(r)(o)(i.fromCam),toCam:U1(t)(e)(n)(r)(o)(i.toCam)},Yw=t=>e=>n=>r=>o=>i=>{const a=o(i.fromCam),s=o(i.toCam),u=Y1(r)(i),c=rg(r)(i);return a.zoom===s.zoom&&a.center.x===s.center.x&&a.center.y===s.center.y?{...i,fromCam:ng(t)(e)(n)(r)(c)(u)(a),toCam:ng(t)(e)(n)(r)(c)(u)(s)}:{...i,fromCam:a,toCam:ng(t)(e)(n)(r)(c)(u)(s)}},Kw=t=>e=>n=>r=>o=>o.intent==="ActionFocus"?Yw(t)(e)(n)(r)(uw)(o):o,Ds=t=>e=>n=>r=>o=>i=>jc(U(Uw(t)(e)(n)(i))(lw(t)(i)(Ww(i)((()=>{const a=Gw(t)(e)(n)(r)(o)(i);if(i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0)return V1(i)(o.dives)(X1(F1(jc(U(Kw(t)(e)(n)(i))(a)))));const s=$1(t)(e)(n)(o)(i);return a.length===0?[{startT:i.startT,endT:i.endT,fromCam:s,toCam:s,easing:p1,interp:zn,intent:_a}]:qw()(i)(zw(s)(i)(V1(i)(o.dives)(X1(F1(jc(Qw(s)(U(Vw(t)(e)(n)(i)(s))(a))))))))})())))),jw=t=>e=>n=>r=>o=>Gt(i=>a=>at.compare(i.startT)(a.startT))(Et(o.segments)(Ds(t)(e)(n)(r)(o))),la=t=>e=>n=>r=>o=>i=>a=>{if(i.direction==="DiveIn"){const s=Oo(n)(t.padding)(a)(Bo(t)(n)(Ds(t)(e)(n)(r)(o)(a))(i.startT-1e-4).camera),u=Ps(i.node)(a.layout.nodes);return i.direction==="DiveIn"&&u.tag==="Just"?Q1(e)(n)(s)({x:u._1.x*a.placement.scale+a.placement.tx,y:u._1.y*a.placement.scale+a.placement.ty,w:u._1.w*a.placement.scale,h:u._1.h*a.placement.scale}):s}if(i.direction==="DiveOut"){const s=Oo(n)(t.padding)(a)(Bo(t)(n)(Ds(t)(e)(n)(r)(o)(a))(i.endT+1e-4).camera),u=Ps(i.node)(a.layout.nodes);return i.direction==="DiveIn"&&u.tag==="Just"?Q1(e)(n)(s)({x:u._1.x*a.placement.scale+a.placement.tx,y:u._1.y*a.placement.scale+a.placement.ty,w:u._1.w*a.placement.scale,h:u._1.h*a.placement.scale}):s}_()},Zw=t=>e=>n=>r=>o=>Et(o.dives)(i=>{const a=Rs(o)(i.parentPath)(i.startT)(i.endT);if(a.tag==="Just"){const s=i.childPath,u=Kt(c=>Qo(c.path)(s))(o.segments);if(u.tag==="Just"){const c=Ds(t)(e)(n)(r)(o)(u._1),g=$1(t)(e)(n)(o)(u._1),l=la(t)(e)(n)(r)(o)(i)(a._1),d=(()=>{if(i.direction==="DiveIn")return g;if(i.direction==="DiveOut")return Oo(n)(t.padding)(u._1)(Bo(t)(n)(c)(i.startT-1e-4).camera);_()})();if(i.direction==="DiveIn"){const f=Kt(h=>h.direction==="DiveIn"&&Qo(h.parentPath)(i.childPath)&&ke(h.startT-i.endT)<1e-4)(o.dives);if(f.tag==="Just"){const h=Rs(o)(f._1.parentPath)(f._1.startT)(f._1.endT);if(h.tag==="Just"){if(i.direction==="DiveIn"&&i.endT-i.startT>.12){const m=i.endT-.12,p={easing:kr,endT:m,fromCam:l,intent:lo,interp:fo,startT:i.startT,toCam:la(t)(e)(n)(r)(o)(f._1)(h._1)};return[p,{...p,startT:m,endT:i.endT,fromCam:la(t)(e)(n)(r)(o)(f._1)(h._1)}]}return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:kr,interp:fo,intent:lo}]}if(h.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:kr,interp:fo,intent:lo}];_()}if(f.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:kr,interp:fo,intent:lo}];_()}if(i.direction==="DiveOut"){const f=Kt(h=>h.direction==="DiveIn"&&Qo(h.parentPath)(i.childPath)&&ke(h.startT-i.endT)<1e-4)(o.dives);if(f.tag==="Just"){const h=Rs(o)(f._1.parentPath)(f._1.startT)(f._1.endT);if(h.tag==="Just"){if(i.direction==="DiveIn"&&i.endT-i.startT>.12){const m=i.endT-.12,p={easing:kr,endT:m,fromCam:d,intent:lo,interp:fo,startT:i.startT,toCam:la(t)(e)(n)(r)(o)(f._1)(h._1)};return[p,{...p,startT:m,endT:i.endT,fromCam:la(t)(e)(n)(r)(o)(f._1)(h._1)}]}return[{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:kr,interp:fo,intent:lo}]}if(h.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:kr,interp:fo,intent:lo}];_()}if(f.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:kr,interp:fo,intent:lo}]}_()}if(u.tag==="Nothing")return[];_()}if(a.tag==="Nothing")return[];_()}),K1=t=>e=>n=>r=>o=>[...Zw(t)(e)(n)(r)(o),...jw(t)(e)(n)(r)(o)],Ei=(t,e,n)=>({tag:t,_1:e,_2:n}),tN=t=>t,Ai=(t,e)=>({tag:t,_1:e}),j1=(t,e)=>({tag:t,_1:e}),og=t=>t,Fs=(t,e)=>({tag:t,_1:e}),ig=Fs("NotYet"),Z1=Fs("Consumed"),eN=og("FromSource"),tl=og("FromTarget"),nN=og("FromBoth"),ag=Ai("Hidden"),el=Ai("Visible"),sg=tN("ExtendFromSource"),ug=Ei("Retracted"),nl=Ei("Extended"),rN={eq:t=>e=>t.tag==="Retracted"?e.tag==="Retracted":t.tag==="Extending"?e.tag==="Extending"&&(t._1==="ExtendFromSource"?e._1==="ExtendFromSource":t._1==="ExtendFromTarget"&&e._1==="ExtendFromTarget")&&t._2===e._2:t.tag==="Extended"?e.tag==="Extended":t.tag==="Retracting"&&e.tag==="Retracting"&&(t._1==="FromSource"?e._1==="FromSource":t._1==="FromTarget"?e._1==="FromTarget":t._1==="FromBoth"&&e._1==="FromBoth")&&t._2===e._2},cg=t=>t,Is={eq:is(xi)},Bs=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},rl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Ho=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},ol=Mt.foldMap(ky(P)),gg=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},il=ge(P)(Mt),oN=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},iN=ge(P)(Mt),aN=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},sN=ge(P)(Mt),uN=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},al=cg("Backdrop"),cN=cg("FlyThrough"),cn=cg("Active"),Ms=t=>e=>n=>{const r=Kt(o=>Is.eq(o.path)(e)&&n>=o.startT&&n<o.endT)(t.segments);if(r.tag==="Just")return T("Just",r._1);if(r.tag==="Nothing")return Kt(o=>Is.eq(o.path)(e))(t.segments);_()},gN=t=>e=>{if(e.scene.tag==="Structural")return e.scene._1.to;if(e.scene.tag==="DataFlow")return e.scene._1.keyframe;if(e.scene.tag==="Hold")return e.scene._1;if(e.scene.tag==="EnterNode"||e.scene.tag==="ExitNode"||e.scene.tag==="StepScene")return t;_()},_N=t=>{const e=Kt(n=>n.path.length===0)(t.segments);if(e.tag==="Just")return e._1.edgeEndpoints;if(e.tag==="Nothing")return M;_()},fN=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:Bc,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:_N(t)}),lN=t=>U(e=>e<1?[]:Rt(0,e,t))(Yt(0,t.length-1|0)),zs=t=>e=>{const n=Bs(e)(t.keyframes);if(n.tag==="Nothing")return M;if(n.tag==="Just")return n._1.nodes;_()},_g=t=>e=>n=>{const r=Bs(e)(t.keyframes);if(r.tag==="Just")return rl(n)(r._1.labels);if(r.tag==="Nothing")return w;_()},fg=t=>e=>{const n=Bs(e)(t.keyframes);if(n.tag==="Nothing")return M;if(n.tag==="Just")return n._1.edges;_()},dN=t=>e=>wt(n=>rl(e)(n.labels))((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,yt("Cons",r._4,n(r._6,o)));_()};return Wt(ue.foldr,n(t.keyframes,R))})()),hN=b(t=>e=>{const n=zr(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?St(n._1.init)({...n._1.last,endT:Ho(n._1.last.endT)(e.endT),windows:St(n._1.last.windows)(e)}):St(t)({endT:e.endT,windows:[e]})})([]),pN=t=>e=>n=>ol(r=>ol(o=>o.target.tag==="FillWindow"?o.startT<=n?ee("Node",1,1,o.target._2,void 0,M,M):M:o.target.tag==="TokenWindow"&&o.startT+(o.endT-o.startT)*.25<=n?ee("Node",1,1,o.target._4,void 0,M,M):M)(r.windows))(dt(r=>n<=r.endT+t,hN(Gt(r=>o=>at.compare(r.startT)(o.startT))(dt(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),mN=t=>e=>{const n=At(r=>w,r=>o=>T("Just",{head:r,tail:o}),dN(t)(e));if(n.tag==="Nothing")return!1;if(n.tag==="Just"){const r=n._1.head;return ne(o=>o!==r,n._1.tail)}_()},yN=t=>e=>n=>ne(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),xN=t=>e=>n=>ne(r=>r.endT<=e&&r.target.tag==="RelabelWindow"&&r.target._1===n,t),wN=t=>e=>n=>ne(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),NN=t=>e=>n=>ne(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),TN=t=>e=>n=>ne(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),sl=t=>{const e=Ef(w,bf,o=>zs(t)((()=>{if(o.scene.tag==="Structural")return o.scene._1.to;if(o.scene.tag==="DataFlow")return o.scene._1.keyframe;if(o.scene.tag==="Hold")return o.scene._1;if(o.scene.tag==="EnterNode"||o.scene.tag==="ExitNode"||o.scene.tag==="StepScene")return t.initialKeyframe;_()})()).tag==="Leaf"?w:T("Just",Ho(o.startT)(o.endT-1e-4)),t.spans),n=(()=>{if(e.tag==="Nothing")return t.startT;if(e.tag==="Just")return e._1;_()})(),r=Kt(o=>o.target.tag==="NodeWindow"&&o.target._2==="PlopIn")(Gt(o=>i=>at.compare(o.startT)(i.startT))(t.windows));if(r.tag==="Nothing")return n;if(r.tag==="Just")return Ho(r._1.startT)(r._1.endT-1e-4);_()},da=t=>e=>n=>Kt(r=>n(r)&&e>=r.startT&&e<r.endT)(t),ha=t=>e=>{if(e<t.startT)return Zn("AtKeyframe",t.initialKeyframe);const n=Kt(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Zn("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Zn("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return Zn("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode"||n._1.scene.tag==="StepScene")return Zn("AtKeyframe",t.initialKeyframe);_()}if(n.tag==="Nothing")return Zn("AtKeyframe",b(gN)(t.initialKeyframe)(t.spans));_()},vN=t=>e=>{const n=ha(t)(e),r=Bs((()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;_()})())(t.keyframes);if(r.tag==="Just")return r._1.kind;if(r.tag==="Nothing")return ca;_()},bN=t=>e=>{const n=ha(t)(e);if(n.tag==="AtKeyframe")return De(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return De(3)(n._2)==="kf-"?"":n._2;_()},JN=t=>e=>n=>{const r=ha(t)(e);if(r.tag==="AtKeyframe")return _g(t)(r._1)(n);if(r.tag==="InTransition")return xN(t.windows)(e)(n)?_g(t)(r._2)(n):_g(t)(r._1)(n);_()},CN={segment:{startT:0,endT:0,path:[],layout:{nodes:M,edges:M,chipExtras:M,edgeLabels:M},placement:Bc,windows:[],spans:[],keyframes:M,initialKeyframe:"",edgeEndpoints:M},state:{animationTime:0,nodes:M,nodeLabels:M,edgeEndpoints:M,edges:M,tokens:M,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:ca,visited:M,nodeFadeAlpha:M,nodeLabelFadeAlpha:M,edgeFadeAlpha:M,nodeInvert:M},bgAlpha:1,minis:[],role:cn},Qs=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:CN},kN=t=>e=>{const n=ha(t)(e);if(n.tag==="AtKeyframe")return zs(t)(n._1);if(n.tag==="InTransition")return Qe(P.compare,Be,zs(t)(n._1),zs(t)(n._2));_()},LN=t=>e=>{const n=ha(t)(e);if(n.tag==="AtKeyframe")return fg(t)(n._1);if(n.tag==="InTransition")return Qe(P.compare,Be,fg(t)(n._1),fg(t)(n._2));_()},ul=t=>e=>{const n=t.endT-t.startT;return n<=0?1:Ho(0)(gg(1)((e-t.startT)/n))},SN=t=>e=>n=>Xc(Bo(t.cameraConfig)(t.layout)(t.cameraSpans)(n.startT).camera)(Bo(t.cameraConfig)(t.layout)(t.cameraSpans)(n.endT).camera)(ul(n)(e)),EN=t=>{const e=Ho(0)(gg(1)(t));return e<=0||e>=1?0:fn(3.141592653589793*e)},$o=t=>e=>{const n=t.endT-t.startT;return n<=0?1:Ho(0)(gg(1)((e-t.startT)/n))},AN=t=>e=>il(wt(n=>{const r=da(t.windows)(e)(o=>o.target.tag==="RelabelWindow"&&o.target._1===n);if(r.tag==="Just")return r._1.target.tag==="RelabelWindow"?T("Just",L(n,j1("RelabelingNode",{oldLabel:r._1.target._2,newLabel:r._1.target._3,progress:$o(r._1)(e)}))):w;if(r.tag==="Nothing"){if(mN(t)(n)){const o=JN(t)(e)(n);if(o.tag==="Just")return T("Just",L(n,j1("StaticNodeLabel",o._1)));if(o.tag==="Nothing")return w;_()}return w}_()})((()=>{const n=r=>{if(r.tag==="Leaf")return M;if(r.tag==="Node")return ee("Node",r._1,r._2,r._3,void 0,n(r._5),n(r._6));_()};return Wt(ln.foldr,n(t.layout.nodes))})())),PN=t=>e=>n=>r=>o=>{const i=da(e)(n)(a=>a.target.tag==="EdgeWindow"&&a.target._2.tag==="Retract"&&a.target._1===o);if(i.tag==="Just"){const a=bs(t.timing.edgeEasing)($o(i._1)(n)),s=i._1.target.tag==="EdgeWindow"?i._1.target._2:As("Extend",sg);if(s.tag==="Retract")return Ei("Retracting",s._1,a);if(s.tag==="Extend")return Ei("Extending",s._1,a);_()}if(i.tag==="Nothing"){if(yN(e)(n)(o))return ug;const a=da(e)(n)(s=>s.target.tag==="EdgeWindow"&&s.target._1===o);if(a.tag==="Just"){const s=bs(t.timing.edgeEasing)($o(a._1)(n)),u=a._1.target.tag==="EdgeWindow"?a._1.target._2:As("Extend",sg);if(u.tag==="Retract")return Ei("Retracting",u._1,s);if(u.tag==="Extend")return Ei("Extending",u._1,s);_()}if(a.tag==="Nothing")return TN(e)(n)(o)?ug:oN(o)(r)?nl:ug}_()},RN=t=>e=>n=>{const r=LN(e)(n);return iN(U(o=>L(o,PN(t)(e.windows)(n)(r)(o)))((()=>{const o=i=>{if(i.tag==="Leaf")return M;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,void 0,o(i._5),o(i._6));_()};return Wt(ln.foldr,o(e.layout.edges))})()))},GN=t=>e=>n=>r=>{const o=da(t)(e)(i=>i.target.tag==="NodeWindow"&&i.target._1===r&&i.target._2==="PlopOut");if(o.tag==="Just"){const i=$o(o._1)(e),a=o._1.target.tag==="NodeWindow"?o._1.target._2:Kc;if(a==="PlopIn")return Ai("PloppingIn",i);if(a==="PlopOut")return Ai("PloppingOut",i);_()}if(o.tag==="Nothing"){if(wN(t)(e)(r))return ag;const i=da(t)(e)(a=>a.target.tag==="NodeWindow"&&a.target._1===r);if(i.tag==="Just"){const a=$o(i._1)(e),s=i._1.target.tag==="NodeWindow"?i._1.target._2:Kc;if(s==="PlopIn")return Ai("PloppingIn",a);if(s==="PlopOut")return Ai("PloppingOut",a);_()}if(i.tag==="Nothing")return NN(t)(e)(r)?ag:aN(r)(n)?el:ag}_()},DN=t=>e=>{const n=kN(t)(e);return il(U(r=>L(r,GN(t.windows)(e)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return M;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));_()};return Wt(ln.foldr,r(t.layout.nodes))})()))},FN=t=>e=>n=>e.target.tag==="TokenWindow"?L(e.target._1,n<e.startT?ig:n>=e.endT?Z1:Fs("Travelling",{edge:e.target._2,direction:e.target._3,progress:bs(t.timing.tokenEasing)($o(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"?L(e.target._1,n<e.startT?ig:n>=e.endT?Z1:Fs("Filling",{node:e.target._2,progress:$o(e)(n),labels:e.target._3})):L("",ig),IN=t=>e=>n=>sN(U(r=>FN(t)(r)(n))(dt(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),BN=t=>e=>n=>({animationTime:n,nodes:DN(e)(n),nodeLabels:AN(e)(n),edgeEndpoints:e.edgeEndpoints,edges:RN(t)(e)(n),tokens:IN(t)(e.windows)(n),camera:Bo(t.cameraConfig)(e.layout)(t.cameraSpans)(n).camera,frameTitle:bN(e)(n),staticKind:vN(e)(n),visited:pN(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:M,nodeLabelFadeAlpha:M,edgeFadeAlpha:M,nodeInvert:M}),Pi=t=>e=>n=>r=>({segment:n,state:BN(t)(n)(e),bgAlpha:1,minis:MN(t)(e)(n),role:r}),MN=t=>e=>n=>wt(r=>{const o=Ms(t)(St(n.path)(r))(e);if(o.tag==="Just")return T("Just",{...Pi(t)(uN(o._1.startT)(o._1.endT-1e-4)(e))(o._1)(al),bgAlpha:0});if(o.tag==="Nothing")return w;_()})((()=>{const r=o=>{if(o.tag==="Leaf")return M;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));_()};return Wt(ln.foldr,r(n.layout.nodes))})()),zN=t=>e=>{if(t.direction==="DiveIn")return sl(e);if(t.direction==="DiveOut")return t.startT-1e-4;_()},cl=t=>e=>wt(n=>{const r=Kt(o=>o.direction==="DiveIn"&&Is.eq(o.childPath)((()=>{const i=n.length+1|0;return i<1?[]:Rt(0,i,e)})()))(t.dives);if(r.tag==="Just"){const o=Ms(t)(n)(r._1.startT-1e-4);if(o.tag==="Just")return T("Just",(()=>{const i=Pi(t)(r._1.startT-1e-4)(o._1)(al);return{...i,state:{...i.state,nodeFadeAlpha:ee("Node",1,1,r._1.node,0,M,M)}}})());if(o.tag==="Nothing")return w;_()}if(r.tag==="Nothing")return w;_()})(lN(e)),gl=t=>e=>{const n=dt(o=>e>=o.startT&&e<o.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:fN(t)},QN=t=>e=>n=>r=>{const o=s=>{const u=Pi(t)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT;_()})())(s)(cN);return{...u,bgAlpha:1,minis:dt(c=>!Is.eq(c.segment.path)(n.childPath),u.minis),state:{...u.state,edgeFadeAlpha:M,nodeFadeAlpha:ee("Node",1,1,n.node,0,M,M),nodeInvert:M,tokens:M}}},i=Ms(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT;_()})()),a=Ms(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;_()})());return[...cl(t)(n.parentPath),...(()=>{if(i.tag==="Just"){if(a.tag==="Just")return[o(i._1),{...Pi(t)(zN(n)(a._1))(a._1)(cn),bgAlpha:1}];if(a.tag==="Nothing")return[o(i._1)];_()}if(i.tag==="Nothing")return[Pi(t)(e)(gl(t)(e))(cn)];_()})()]},WN=t=>e=>Kt(n=>e>=n.startT&&e<n.endT)(t.dives),ON=t=>e=>{const n=gl(t)(e),r=t.dives.length!==0,o=Bo(t.cameraConfig)(t.layout)(t.cameraSpans)(e).camera,i=Oo(t.layout)(t.cameraConfig.padding)(n)(o),a=cl(t)(n.path),s=Pi(t)(n.path.length===0?e:Ho(e)(sl(n)))(n)(cn),u={...s,state:{...s.state,camera:i}},c=WN(t)(e);if(c.tag==="Just"){const g=SN(t)(e)(c._1),l=ul(c._1)(e);return{levels:QN(t)(e)(c._1)(g),camera:o,rootLayout:t.layout,hasDives:r,diving:!0,zoomStreak:EN(g),zoomDirection:(()=>{if(c._1.direction==="DiveIn")return-1;if(c._1.direction==="DiveOut")return 1;_()})(),diveDepth:(()=>{if(c._1.direction==="DiveIn")return g;if(c._1.direction==="DiveOut")return 1-g;_()})(),doorProgress:(()=>{if(c._1.direction==="DiveIn")return l;if(c._1.direction==="DiveOut")return 1-g;_()})()}}if(c.tag==="Nothing")return{levels:St(a)(u),camera:i,rootLayout:t.layout,hasDives:r,diving:!1,zoomStreak:0,zoomDirection:0,diveDepth:0,doorProgress:0};_()},HN=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},$N=t=>{const e=t.length;return(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=i;if(u>=e){a=!1,s=c;continue}const g=l=>d=>{let f=l,h=d,m=!0,p;for(;m;){const x=f,y=h;if(x>=e){m=!1,p=y;continue}if(u>=0&&u<t.length){if(x>=0&&x<t.length){f=x+1|0,h=(()=>{const N=t[u].position,v=t[u].size,J=t[x].position,k=t[x].size;return N._1<J._1+k._1&&J._1<N._1+v._1&&N._2<J._2+k._2&&J._2<N._2+v._2})()?y+1|0:y;continue}f=x+1|0,h=y;continue}m=!1,p=y}return p};o=u+1|0,i=g(u+1|0)(c)}return s})(0)(0)},_l=t=>b(e=>n=>e+My(n.start)(n.end))(0)(t.segments),fl=t=>e=>n=>({crossingCount:b(r=>o=>r+o.jumps.length|0)(0)(e),bendCount:b(r=>o=>r+o.bends.length|0)(0)(e),totalEdgeLength:b(r=>o=>r+_l(o))(0)(e),maxEdgeLength:b(r=>o=>HN(r)(_l(o)))(0)(e),nodeOverlapCount:$N(t),constraintViolations:n,jumpCount:b(r=>o=>r+o.jumps.length|0)(0)(e)}),lg=t=>t,le=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},dg=lg("LEFT"),qN=lg("RIGHT"),ll=lg("UNDEFINED"),UN={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},XN={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?an:Me;if(e==="LEFT")return ze;if(t==="RIGHT")return e==="RIGHT"?an:Me;if(e==="RIGHT")return ze;if(t==="UP")return e==="UP"?an:Me;if(e==="UP")return ze;if(t==="DOWN")return e==="DOWN"?an:Me;if(e==="DOWN")return ze;if(t==="UNDEFINED"&&e==="UNDEFINED")return an;_()},Eq0:()=>UN},VN=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){if(t==="LEFT"){if(i._3==="LEFT"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="LEFT"){n=i._6;continue}if(t==="RIGHT"){if(i._3==="RIGHT"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="RIGHT"){n=i._6;continue}if(t==="UP"){if(i._3==="UP"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="UP"){n=i._6;continue}if(t==="DOWN"){if(i._3==="DOWN"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="DOWN"){n=i._6;continue}if(t==="UNDEFINED"&&i._3==="UNDEFINED"){r=!1,o=!0;continue}}_()}return o},YN={x:0,y:0},Cn=t=>e=>n=>{const r=le(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:it(ut)(t)(e(r._1))(n.cNodes)};_()},pa=t=>e=>n=>{const r=le(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:it(ut)(t)(e(r._1))(n.cGroups)};_()},KN=t=>b(e=>n=>Cn(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),jN=t=>{const e=b(n=>r=>{const o=le(r)(t.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just")return b(i=>a=>zt(ut)(ye)(a)([r])(i))(n)(o._1.constraints);_()})(M)(t.cNodeOrder);return b(n=>r=>Cn(r)(o=>({...o,constraints:(()=>{const i=le(r)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;_()})()}))(n))(t)(t.cNodeOrder)},ZN=t=>e=>Cn(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}})),tT=t=>{const e=b(n=>r=>pa(r)(o=>({...o,outDegree:o.outDegreeReal}))(n))(t)(t.cGroupOrder);return b(n=>r=>Cn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder)},tr={left:!1,right:!1,up:!1,down:!1},eT={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},hg=t=>b(e=>n=>{const r=le(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const o=b(a=>s=>{const u=le(s)(e.cNodes);if(u.tag==="Nothing")return a;if(u.tag==="Just"){if(a.tag==="Nothing")return T("Just",s);if(a.tag==="Just"){const c=le(a._1)(e.cNodes);if(c.tag==="Nothing")return T("Just",s);if(c.tag==="Just")return u._1.hitbox.x<c._1.hitbox.x?T("Just",s):T("Just",a._1)}}_()})(w)(r._1.cNodes),i=pa(n)(a=>({...a,reference:o}))(e);if(o.tag==="Nothing")return i;if(o.tag==="Just"){const a=le(o._1)(i.cNodes);if(a.tag==="Nothing")return i;if(a.tag==="Just"){const s=a._1;return b(u=>c=>Cn(c)(g=>({...g,cGroupOffset:{x:g.hitbox.x-s.hitbox.x,y:g.hitbox.y-s.hitbox.y}}))(u))(i)(r._1.cNodes)}}}_()})(t)(t.cGroupOrder),kn=t=>hg({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return M;if(n.tag==="Node")return ee("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));_()};return e(t.cNodes)})()}),Lr=t=>hg({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return M;if(n.tag==="Node")return ee("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));_()};return e(t.cNodes)})()}),dl=t=>{const e=b(n=>r=>pa(r)(o=>({...o,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return b(n=>r=>{const o=le(r)(n.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just"){if(o._1.cGroup.tag==="Nothing")return n;if(o._1.cGroup.tag==="Just"){const i=o._1.cGroup._1;return b(a=>s=>{const u=le(s)(a.cNodes);if(u.tag==="Nothing")return a;if(u.tag==="Just")return u._1.cGroup.tag==="Just"&&u._1.cGroup._1!==i?pa(u._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(pa(i)(c=>_n(ao)(s)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,s]})(a)):a;_()})(n)(o._1.constraints)}}_()})(e)(e.cNodeOrder)},Ws=t=>{const e=jN(t.cGraph);return{...t,cGraph:dl(b(n=>r=>Cn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},nT=t=>e=>b(n=>r=>{if(t==="LEFT"||t==="UP"){const i=r._2;return Cn(r._1)(a=>({...a,constraints:[...a.constraints,i]}))(n)}const o=r._1;return Cn(r._2)(i=>({...i,constraints:[...i.constraints,o]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),er=t=>{const e={...t,cGraph:nT(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return M;if(r.tag==="Node")return ee("Node",r._1,r._2,r._3,{...r._4,constraints:[]},n(r._5),n(r._6));_()};return n(t.cGraph.cNodes)})()})};return{...e,cGraph:dl((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);_()})())}},rT=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?er(r):e==="RIGHT"?er({...r,cGraph:kn(r.cGraph)}):e==="UP"?er({...r,cGraph:Lr(r.cGraph)}):e==="DOWN"?er({...r,cGraph:kn(Lr(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?Ws({...r,cGraph:kn(r.cGraph)}):e==="UP"?er({...r,cGraph:Lr(r.cGraph)}):e==="DOWN"?er({...r,cGraph:kn(Lr(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?Ws({...r,cGraph:kn(r.cGraph)}):e==="UP"?er({...r,cGraph:Lr(kn(r.cGraph))}):e==="DOWN"?er({...r,cGraph:kn(Lr(kn(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?er({...r,cGraph:Lr(r.cGraph)}):e==="RIGHT"?er({...r,cGraph:kn(Lr(r.cGraph))}):e==="DOWN"?Ws({...r,cGraph:kn(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?er({...r,cGraph:Lr(kn(r.cGraph))}):e==="RIGHT"?er({...r,cGraph:kn(Lr(kn(r.cGraph)))}):e==="UP"?Ws({...r,cGraph:kn(r.cGraph)}):r;_()},hl=t=>e=>e.finished||!VN(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:rT(e.direction)(t)(e),oT=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?hl(dg)(t):t,n={...e,cGraph:tT(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);_()},pl=t=>e=>n=>{const r=le(t)(n.cNodes),o=le(e)(n.cGroups);return r.tag==="Just"&&o.tag==="Just"?(()=>{if(r._1.cGroup.tag==="Nothing")return!1;if(r._1.cGroup.tag==="Just")return!0;_()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:it(ut)(t)({...r._1,cGroup:T("Just",e)})(n.cNodes),cGroups:it(ut)(e)({...o._1,cNodes:_n(ao)(t)(o._1.cNodes)?o._1.cNodes:[...o._1.cNodes,t],reference:(()=>{if(o._1.reference.tag==="Nothing")return T("Just",t);if(o._1.reference.tag==="Just")return T("Just",o._1.reference._1);_()})()})(n.cGroups)}:n},ml=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:it(ut)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:w,cGroupOffset:YN,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:tr})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),pg=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:b(r=>o=>pl(o)(n)(r))({...e,cGroups:it(ut)(n)({id:n,master:t.master,cNodes:[],startPos:-1e308,incomingConstraints:[],outDegree:0,outDegreeReal:0,reference:w,delta:0,deltaNormalized:0})(e.cGroups),cGroupOrder:[...e.cGroupOrder,n],nextCGroupId:n+1|0})(t.nodes)}},iT=t=>b(e=>n=>{const r=le(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?pg({master:w,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),aT=t=>({cGraph:KN(iT(hg(t))),direction:ll,compactionAlgorithm:w,constraintAlgorithm:w,spacingsHandler:eT,lockFun:w,finished:!1}),sT=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},uT=t=>e=>{const n=at.compare(t._1)(e._1);return n==="LT"?Me:n==="GT"?ze:ut.compare(t._2)(e._2)},cT=(()=>{const t=mn.unfoldr(sr);return e=>t(yn("IterNode",e,ir))})(),yl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},xl=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",wl=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),Os=t=>e=>uT(L(t.hitbox.x+t.hitbox.width/2,t.id))(L(e.hitbox.x+e.hitbox.width/2,e.id)),gT=t=>e=>{const n=Mr(Ut,w,r=>Os(t)(r)==="LT",e);if(n.tag==="Just"){const r=Af(Ut,w,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;_()}if(n.tag==="Nothing")return St(e)(t);_()},Nl=t=>e=>{const n=dt(o=>Os(o)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?T("Just",n[r]):w},_T=t=>e=>{const n=gT(e)(t.intervals),r=Kt(i=>Os(e)(i)==="LT")(n),o=it(ut)(e.id)((()=>{const i=Nl(e)(n);return i.tag==="Just"?T("Just",i._1.id):w})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return it(ut)(r._1.id)(T("Just",e.id))(o);if(r.tag==="Nothing")return o;_()})()}},fT=t=>e=>{const n=at.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?ze:an:e.low?Me:an:n},lT=t=>b(e=>n=>Cn(n.id)(r=>({...r,constraints:[]}))(e))(t)(wt(e=>le(e)(t.cNodes))(t.cNodeOrder)),mg=t=>e=>b(n=>r=>{const o=le(r._1)(n.cNodes);if(o.tag==="Just")return Cn(r._1)(i=>({...i,constraints:[...i.constraints,...r._2]}))(n);if(o.tag==="Nothing")return n;_()})(e)(cT(t)),Tl=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}},vl=t=>e=>n=>b(r=>o=>n(o)?Cn(o.id)(Tl(t))(r):r)(e)(wt(r=>le(r)(e.cNodes))(e.cNodeOrder)),dT=t=>e=>{const n=(r,o,i)=>{const a=Cn(i)(Tl(t))(r);return o.length<=1?a:b(s=>u=>u===i?s:Cn(u)(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))(a)(o)};return b(r=>o=>{if(o.master.tag==="Nothing")return 0<o.cNodes.length?n(r,o.cNodes,o.cNodes[0]):r;if(o.master.tag==="Just")return n(r,o.cNodes,o.master._1);_()})(e)(wt(r=>le(r)(e.cGroups))(e.cGroupOrder))},hT=t=>e=>{const n=Nl(e)(t.intervals),r=Kt(i=>Os(e)(i)==="LT")(t.intervals),o=n.tag==="Just"&&(()=>{const i=yl(e.id)(t.cand);return(i.tag==="Nothing"?!1:i.tag==="Just"&&(i._1.tag==="Nothing"?!1:i._1.tag==="Just"&&i._1._1===n._1.id))&&n._1.cGroup.tag==="Just"&&e.cGroup.tag==="Just"&&n._1.cGroup._1!==e.cGroup._1})()?zt(ut)(ye)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const i=yl(r._1.id)(t.cand);return(i.tag==="Nothing"?!1:i.tag==="Just"&&(i._1.tag==="Nothing"?!1:i._1.tag==="Just"&&i._1._1===e.id))&&e.cGroup.tag==="Just"&&r._1.cGroup.tag==="Just"&&e.cGroup._1!==r._1.cGroup._1})()?zt(ut)(ye)(e.id)([r._1.id])(o):o,intervals:dt(i=>i.id!==e.id,t.intervals)}},pT=t=>e=>e.low?_T(t)(e.node):hT(t)(e.node),yg=t=>e=>b(pT)({intervals:[],cand:M,constraints:M})(Gt(fT)(Et(dt(t,wt(n=>le(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,mT=t=>e=>{const n=sT(0)(t/2-.5),r=mg(yg(xl)(vl(n)(e)(xl)))(e),o=mg(yg(wl)(vl(n)(r)(wl)))(r);return mg(yg(i=>!0)(dT(n)(o)))(o)},yT=t=>e=>mT(t)(lT(e.cGraph)),Hs=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},bl=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},xg=t=>e=>n=>r=>o=>({id:t,representedEdges:[o],affectedBends:[e,n],hitbox:{x:Hs(e._1)(n._1),y:Hs(e._2)(n._2),width:ke(e._1-n._1),height:ke(e._2-n._2)},ignoreSpacing:tr,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];_()})(),aPort:w}),xT=t=>e=>{const n=Hs(t.hitbox.x)(e.hitbox.x),r=Hs(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:bl(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:bl(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;_()})()}},wT=t=>e=>ke(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,NT=t=>e=>ke(t.hitbox.x-e.hitbox.x)<=1e-4?at.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?Me:ze,Jl=(t,e)=>({tag:t,_1:e}),wg=ge(P)(Mt),$s=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Cl=(()=>{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 o=P.compare(n._1)(r._1);if(o==="LT")return Me;if(o==="GT")return ze;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?an:Me;if(r._2.tag==="Nothing")return ze;if(n._2.tag==="Just"&&r._2.tag==="Just")return P.compare(n._2._1)(r._2._1);_()},Eq0:()=>t};return b(n=>r=>it(e)(r)()(n))(M)})(),Or=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},TT=b(t=>e=>it(XN)(e)()(t))(M),Ng=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=o1.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},vT=t=>e=>{const n=wg(U(i=>L(i.id,i))(t)),r=wt(i=>$s(i)(n))(e),o=ut.compare((()=>{const i=Cl(U(a=>L(a.from.node,a.from.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;_()})())((()=>{const i=Cl(U(a=>L(a.to.node,a.to.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;_()})());if(o==="LT")return{...tr,left:!0,right:!1};if(o==="GT")return{...tr,left:!1,right:!0};if(o==="EQ")return tr;_()},bT=t=>wt(e=>{if(e.direction==="V")return T("Just",{start:e.start,end:e.end});if(e.direction==="H")return w;_()})(t.segments),qs=t=>e=>n=>r=>{if(r.tag==="Just"){const o=Or(n)(e);if(o.tag==="Just"){const i=Kt(a=>a.id===r._1)(o._1);if(i.tag==="Just")return i._1.side;if(i.tag==="Nothing")return t;_()}if(o.tag==="Nothing")return t;_()}if(r.tag==="Nothing")return t;_()},JT=t=>e=>n=>{const r=ml({origin:T("Just",Jl("SegmentOrigin",n)),kind:T("Just","vs"),hitbox:n.hitbox})(e.cGraph),o=ZN(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const i=le(n.potentialGroupParents[0])(o.cNodes);if(i.tag==="Just"){if(i._1.cGroup.tag==="Just")return pl(r.id)(i._1.cGroup._1)(o);if(i._1.cGroup.tag==="Nothing")return o;_()}if(i.tag==="Nothing")return o;_()}return pg({master:T("Just",r.id),nodes:[r.id]})(o).graph})(),edgeToCs:b(i=>a=>zt(P)(ye)(a)([r.id])(i))(e.edgeToCs)(n.representedEdges),lockMap:it(ut)(r.id)(vT(t)(n.representedEdges))(e.lockMap)}},CT=t=>e=>n=>{const r=At(o=>w,o=>i=>T("Just",{head:o,tail:i}),Gt(NT)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const o=b(i=>a=>wT(i.survivor)(a)?{...i,survivor:xT(i.survivor)(a)}:{survivor:a,merged:[...i.merged,i.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return b(JT(t))(n)([...o.merged,o.survivor])}_()},kT=t=>({cGraph:{cNodes:M,cNodeOrder:[],cGroups:M,cGroupOrder:[],supportedDirections:TT([ll,dg,qN]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:M,edgeToCs:M,lockMap:M}),LT=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}},ST=t=>e=>n=>b(r=>o=>{const i=ml({origin:T("Just",Jl("NodeOrigin",o.node)),kind:w,hitbox:LT(o)})(r.cGraph),a=Or(o.node)(t),s=(()=>{if(a.tag==="Nothing")return L(0,0);if(a.tag==="Just")return a._1;_()})();return{...r,cGraph:pg({master:T("Just",i.id),nodes:[i.id]})(i.graph).graph,nodeToC:it(P)(o.node)(i.id)(r.nodeToC),lockMap:it(ut)(i.id)((()=>{const u=s._1-s._2|0;return u<0?{...tr,left:!0}:u>0?{...tr,right:!0}:tr})())(r.lockMap)}})(n)(e),ET=t=>b(e=>n=>zt(P)(r=>o=>L(r._1+o._1|0,r._2+o._2|0))(n.to.node)(L(1,0))(zt(P)(r=>o=>L(r._1+o._1|0,r._2+o._2|0))(n.from.node)(L(0,1))(e)))(M)(t),AT=t=>b(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?it(P)(n.origin._1._1)(n.hitbox.x)(e):e)(M)(wt(e=>le(e)(t.cNodes))(t.cNodeOrder)),PT=t=>b(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?it(P)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(M)(wt(e=>le(e)(t.cNodes))(t.cNodeOrder)),RT=t=>b(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return b(o=>i=>it(o1)(i)(r)(o))(e)(n.origin._1._1.affectedBends)}return e})(M)(wt(e=>le(e)(t.cNodes))(t.cNodeOrder)),kl=t=>{const e=wg(U(n=>L(n.id,n))(t.edges));return wt(n=>{const r=$s(n.edge)(e);if(r.tag==="Just")return n.reversed?T("Just",{edgeId:n.edge,src:r._1.to.node,tgt:r._1.from.node,srcSide:qs(Qr)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:qs(Wr)(t.ports)(r._1.from.node)(r._1.from.port),path:n}):T("Just",{edgeId:n.edge,src:r._1.from.node,tgt:r._1.to.node,srcSide:qs(Qr)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:qs(Wr)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return w;_()})(t.paths)},GT=t=>e=>{const n=Et(e)(r=>{if(r.src===r.tgt)return[];if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return[];const o=Or(r.tgt)(t.nodeToC),i=(()=>{if(o.tag==="Just")return le(o._1)(t.cGraph.cNodes);if(o.tag==="Nothing")return w;_()})(),a=Or(r.src)(t.nodeToC),s=(()=>{if(a.tag==="Just")return le(a._1)(t.cGraph.cNodes);if(a.tag==="Nothing")return w;_()})(),u=(()=>{if(s.tag==="Just"){if(i.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(i._1.cGroup.tag==="Just")return T("Just",{srcGroup:s._1.cGroup._1,tgtGroup:i._1.cGroup._1,delta:0,weight:100});if(i._1.cGroup.tag==="Nothing")return w;_()}if(s._1.cGroup.tag==="Nothing")return w;_()}if(i.tag==="Nothing")return w;_()}if(s.tag==="Nothing")return w;_()})(),c=f=>h=>m=>{if(s.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(m.cGroup.tag==="Just")return f(m.hitbox.x)&&m.cGroup._1!==s._1.cGroup._1?T("Just",h(m.cGroup._1)(s._1.cGroup._1)):w;if(m.cGroup.tag==="Nothing")return w;_()}if(s._1.cGroup.tag==="Nothing")return w;_()}if(s.tag==="Nothing")return w;_()},g=wt(f=>le(f)(t.cGraph.cNodes))((()=>{const f=$s(r.edgeId)(t.edgeToCs);if(f.tag==="Nothing")return[];if(f.tag==="Just")return f._1;_()})()),l=(()=>{if(s.tag==="Just"&&r.srcSide==="West"){const f=s._1;return wt(c(h=>h<f.hitbox.x)(h=>m=>({srcGroup:h,tgtGroup:m,delta:1,weight:100})))(g)}return[]})(),d=(()=>{if(s.tag==="Just"&&r.tgtSide==="East"){const f=s._1;return wt(c(h=>h>f.hitbox.x)(h=>m=>({srcGroup:m,tgtGroup:h,delta:1,weight:100})))(g)}return[]})();if(u.tag==="Nothing")return[];if(u.tag==="Just")return[u._1,...l,...d];_()});return{sameEdgeVerticalSegments:r=>o=>r.origin.tag==="Just"&&r.origin._1.tag==="SegmentOrigin"&&o.origin.tag==="Just"&&o.origin._1.tag==="SegmentOrigin"&&(()=>{const i=o.origin._1._1;return ne(a=>_n(Tr)(a)(i.representedEdges),r.origin._1._1.representedEdges)})(),vsLNodePair:r=>o=>r.origin.tag==="Just"&&o.origin.tag==="Just"&&(r.origin._1.tag==="SegmentOrigin"?o.origin._1.tag==="NodeOrigin":r.origin._1.tag==="NodeOrigin"&&o.origin._1.tag==="SegmentOrigin"),edgeLengthEdges:r=>n}},DT=t=>e=>{const n=rt(4),r=AT(t),o=PT(t),i=wg(U(s=>L(s.id,L(s.from.node,s.to.node)))(e.edges)),a=RT(t);return{nodes:U(s=>{const u=Or(s.node)(r);if(u.tag==="Just")return{...s,position:L(u._1/n,s.position._2)};if(u.tag==="Nothing")return s;_()})(e.nodes),edges:U(s=>{const u=$s(s.edge)(i),c=(()=>{if(u.tag==="Nothing")return s.segments;if(u.tag==="Just"){const g=Or(u._1._1)(o),l=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;_()})(),d=Or(u._1._2)(o),f=(()=>{if(d.tag==="Nothing")return 0;if(d.tag==="Just")return d._1;_()})();return Ot((()=>{const h=s.reversed?f:l,m=s.reversed?l:f,p=s.segments.length;return x=>y=>{if(y.direction==="V"){const N=(()=>{if(x===0)return h;if(x===(p-1|0))return m;const v=Ng(y.start)(a);if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;_()})();return{...y,start:L(y.start._1+N,y.start._2),end:L(y.end._1+N,y.end._2)}}if(y.direction==="H")return{...y,start:L((()=>{if(x===0)return y.start._1+h;const N=Ng(y.start)(a);if(N.tag==="Nothing")return y.start._1+0;if(N.tag==="Just")return y.start._1+N._1;_()})(),y.start._2),end:L((()=>{if(x===(p-1|0))return y.end._1+m;const N=Ng(y.end)(a);if(N.tag==="Nothing")return y.end._1+0;if(N.tag==="Just")return y.end._1+N._1;_()})(),y.end._2)};_()}})())(s.segments)}_()})();return{...s,segments:c,bends:$e(g=>l=>g.end,c,Rt(1,c.length,c))}})(e.paths)}},FT=t=>e=>n=>r=>o=>i=>{const a=xg(o.nextId)(i._2.start)(i._2.end)(w)(t.edgeId),s=(()=>{if(i._1===0){if(e.tag==="Nothing")return a;if(e.tag==="Just")return{...a,ignoreSpacing:i._2.end._2<e._1.y?{...a.ignoreSpacing,down:!0}:i._2.end._2>e._1.y+e._1.height?{...a.ignoreSpacing,up:!0}:{...a.ignoreSpacing,up:!0,down:!0}};_()}return a})();return{nextId:o.nextId+1|0,segments:[...o.segments,(()=>{if(i._1===r){if(n.tag==="Nothing")return s;if(n.tag==="Just")return{...s,ignoreSpacing:i._2.start._2<n._1.y?{...s.ignoreSpacing,down:!0}:i._2.start._2>n._1.y+n._1.height?{...s.ignoreSpacing,up:!0}:{...s.ignoreSpacing,up:!0,down:!0}};_()}return s})()]}},Ll=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...xg(i.nextId)(r.start)(L(r.start._1,o.down?n.y:n.y+n.height))(T("Just",e))(t.edgeId),aPort:T("Just",{node:t.src,side:o.side}),ignoreSpacing:o.down?{...tr,down:!0}:{...tr,up:!0}}]}),Us=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...xg(i.nextId)(r.end)(L(r.end._1,o.down?n.y:n.y+n.height))(T("Just",e))(t.edgeId),aPort:T("Just",{node:t.tgt,side:o.side}),ignoreSpacing:o.down?{...tr,down:!0}:{...tr,up:!0}}]}),IT=t=>e=>n=>{if(n.src===n.tgt)return e;const r=Or(n.src)(t.nodeToC),o=Or(n.tgt)(t.nodeToC),i=(()=>{if(r.tag==="Just"){const g=le(r._1)(t.cGraph.cNodes);return g.tag==="Just"?T("Just",g._1.hitbox):w}if(r.tag==="Nothing")return w;_()})(),a=(()=>{if(o.tag==="Just"){const g=le(o._1)(t.cGraph.cNodes);return g.tag==="Just"?T("Just",g._1.hitbox):w}if(o.tag==="Nothing")return w;_()})(),s=bT(n.path),u=b(FT(n)(i)(a)(s.length-1|0))(e)(Ot(g=>l=>L(g,l))(s));if(0<s.length){const g=(()=>{if(r.tag==="Just"&&i.tag==="Just"){if(n.srcSide==="North")return Ll(n)(r._1)(i._1)(s[0])({side:Re,down:!0})(u);if(n.srcSide==="South")return Ll(n)(r._1)(i._1)(s[0])({side:Ge,down:!1})(u)}return u})(),l=s.length-1|0;if(l>=0&&l<s.length&&o.tag==="Just"&&a.tag==="Just"){if(n.tgtSide==="North")return Us(n)(o._1)(a._1)(s[l])({side:Re,down:!0})(g);if(n.tgtSide==="South")return Us(n)(o._1)(a._1)(s[l])({side:Ge,down:!1})(g)}return g}const c=s.length-1|0;if(c>=0&&c<s.length&&o.tag==="Just"&&a.tag==="Just"){if(n.tgtSide==="North")return Us(n)(o._1)(a._1)(s[c])({side:Re,down:!0})(u);if(n.tgtSide==="South")return Us(n)(o._1)(a._1)(s[c])({side:Ge,down:!1})(u)}return u},BT=t=>e=>n=>CT(t)(b(IT(n))({nextId:0,segments:[]})(e).segments)(n),MT=t=>BT(t.edges)(kl(t))(ST(ET(t.edges))(t.nodes)(kT())),Hr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},Tg=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},vg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},zT=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},QT=t=>{const e=t.Eq0();return n=>r=>{const o=s=>{let u=s,c=!0,g;for(;c;){const l=u,d=At(f=>w,f=>h=>T("Just",{head:f,tail:h}),l.queue);if(d.tag==="Nothing"){c=!1,g=l;continue}if(d.tag==="Just"){const f=d._1.head;if((m=>{let p=m,x=!0,y;for(;x;){const N=p;if(N.tag==="Leaf"){x=!1,y=!1;continue}if(N.tag==="Node"){const v=t.compare(f)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){x=!1,y=!0;continue}}_()}return y})(l.removedNodes)){u={...l,queue:d._1.tail};continue}const h=Kt(m=>!Hr(m.eid)(l.removedEdges)&&(e.eq(m.src)(f)||e.eq(m.tgt)(f)))(r);if(h.tag==="Nothing"){u={...l,queue:d._1.tail};continue}if(h.tag==="Just"){const m=e.eq(h._1.src)(f)?h._1.tgt:h._1.src,p={...l,degree:it(t)(m)((()=>{const x=(y=>{let N=y,v=!0,J;for(;v;){const k=N;if(k.tag==="Leaf"){v=!1,J=w;continue}if(k.tag==="Node"){const S=t.compare(m)(k._3);if(S==="LT"){N=k._5;continue}if(S==="GT"){N=k._6;continue}if(S==="EQ"){v=!1,J=T("Just",k._4);continue}}_()}return J})(l.degree);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;_()})())(l.degree),removedNodes:it(t)(f)()(l.removedNodes),removedEdges:it(ut)(h._1.eid)()(l.removedEdges),record:[...l.record,{node:f,neighbour:m,viaSrc:e.eq(h._1.src)(f)}],queue:d._1.tail};if((()=>{const x=(N=>{let v=N,J=!0,k;for(;J;){const S=v;if(S.tag==="Leaf"){J=!1,k=w;continue}if(S.tag==="Node"){const A=t.compare(m)(S._3);if(A==="LT"){v=S._5;continue}if(A==="GT"){v=S._6;continue}if(A==="EQ"){J=!1,k=T("Just",S._4);continue}}_()}return k})(p.degree),y=N=>{let v=N,J=!0,k;for(;J;){const S=v;if(S.tag==="Leaf"){J=!1,k=!1;continue}if(S.tag==="Node"){const A=t.compare(m)(S._3);if(A==="LT"){v=S._5;continue}if(A==="GT"){v=S._6;continue}if(A==="EQ"){J=!1,k=!0;continue}}_()}return k};return(()=>{if(x.tag==="Nothing")return!1;if(x.tag==="Just")return x._1===1;_()})()&&!y(p.removedNodes)})()){u={...p,queue:[...p.queue,m]};continue}u=p;continue}}_()}return g},i=b(s=>u=>zt(t)(ve)(u.src)(1)(zt(t)(ve)(u.tgt)(1)(s)))(M)(r),a=o({degree:i,removedNodes:M,removedEdges:M,record:[],queue:dt(s=>{const u=(c=>{let g=c,l=!0,d;for(;l;){const f=g;if(f.tag==="Leaf"){l=!1,d=w;continue}if(f.tag==="Node"){const h=t.compare(s)(f._3);if(h==="LT"){g=f._5;continue}if(h==="GT"){g=f._6;continue}if(h==="EQ"){l=!1,d=T("Just",f._4);continue}}_()}return d})(i);if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1===1;_()},n)});return{coreNodes:dt(s=>!(u=>{let c=u,g=!0,l;for(;g;){const d=c;if(d.tag==="Leaf"){g=!1,l=!1;continue}if(d.tag==="Node"){const f=t.compare(s)(d._3);if(f==="LT"){c=d._5;continue}if(f==="GT"){c=d._6;continue}if(f==="EQ"){g=!1,l=!0;continue}}_()}return l})(a.removedNodes),n),coreEdges:dt(s=>!Hr(s.eid)(a.removedEdges),r),removed:a.record}}},WT=t=>e=>n=>b(r=>o=>{const i=o.neighbour,a=(()=>{const s=(u=>{let c=u,g=!0,l;for(;g;){const d=c;if(d.tag==="Leaf"){g=!1,l=w;continue}if(d.tag==="Node"){const f=t.compare(i)(d._3);if(f==="LT"){c=d._5;continue}if(f==="GT"){c=d._6;continue}if(f==="EQ"){g=!1,l=T("Just",d._4);continue}}_()}return l})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;_()})();return it(t)(o.node)(o.viaSrc?a-1|0:a+1|0)(r)})(n)(re(e)),bg=t=>{const e=t.Eq0();return n=>r=>o=>{const i={...o,treeNode:it(t)(r)()(o.treeNode)};return b(a=>s=>{if(Hr(s.eid)(a.st.edgeVisited))return a;const u={...a.st,edgeVisited:it(ut)(s.eid)()(a.st.edgeVisited)},c=e.eq(s.src)((()=>{const g=s.src,l=f=>{let h=f,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const y=t.compare(g)(x._3);if(y==="LT"){h=x._5;continue}if(y==="GT"){h=x._6;continue}if(y==="EQ"){m=!1,p=!0;continue}}_()}return p},d=s.tgt;return l(u.treeNode)&&!(f=>{let h=f,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const y=t.compare(d)(x._3);if(y==="LT"){h=x._5;continue}if(y==="GT"){h=x._6;continue}if(y==="EQ"){m=!1,p=!0;continue}}_()}return p})(u.treeNode)})()?s.src:(()=>{const g=s.tgt,l=f=>{let h=f,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const y=t.compare(g)(x._3);if(y==="LT"){h=x._5;continue}if(y==="GT"){h=x._6;continue}if(y==="EQ"){m=!1,p=!0;continue}}_()}return p},d=s.src;return l(u.treeNode)&&!(f=>{let h=f,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const y=t.compare(d)(x._3);if(y==="LT"){h=x._5;continue}if(y==="GT"){h=x._6;continue}if(y==="EQ"){m=!1,p=!0;continue}}_()}return p})(u.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(Hr(s.eid)(u.treeEdge)){if((l=>{let d=l,f=!0,h;for(;f;){const m=d;if(m.tag==="Leaf"){f=!1,h=!1;continue}if(m.tag==="Node"){const p=t.compare(c)(m._3);if(p==="LT"){d=m._5;continue}if(p==="GT"){d=m._6;continue}if(p==="EQ"){f=!1,h=!0;continue}}_()}return h})(u.treeNode))return{...a,st:u};const g=bg(t)(n)(c)(u);return{count:a.count+g.count|0,st:g.st}}if((()=>{const g=d=>{let f=d,h=!0,m;for(;h;){const p=f;if(p.tag==="Leaf"){h=!1,m=!1;continue}if(p.tag==="Node"){const x=t.compare(c)(p._3);if(x==="LT"){f=p._5;continue}if(x==="GT"){f=p._6;continue}if(x==="EQ"){h=!1,m=!0;continue}}_()}return m},l=s.tgt;return!g(u.treeNode)&&(()=>{const d=(m=>{let p=m,x=!0,y;for(;x;){const N=p;if(N.tag==="Leaf"){x=!1,y=w;continue}if(N.tag==="Node"){const v=t.compare(l)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){x=!1,y=T("Just",N._4);continue}}_()}return y})(u.layer),f=s.src,h=(m=>{let p=m,x=!0,y;for(;x;){const N=p;if(N.tag==="Leaf"){x=!1,y=w;continue}if(N.tag==="Node"){const v=t.compare(f)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){x=!1,y=T("Just",N._4);continue}}_()}return y})(u.layer);if(d.tag==="Nothing"){if(h.tag==="Nothing")return s.delta===0;if(h.tag==="Just")return s.delta===-h._1;_()}if(d.tag==="Just"){if(h.tag==="Nothing")return s.delta===(d._1-0|0);if(h.tag==="Just")return s.delta===(d._1-h._1|0)}_()})()})()){const g=bg(t)(n)(c)({...u,treeEdge:it(ut)(s.eid)()(u.treeEdge)});return{count:a.count+g.count|0,st:g.st}}return{...a,st:u}})({count:1,st:i})(dt(a=>(e.eq(a.src)(r)||e.eq(a.tgt)(r))&&!Hr(a.eid)(i.edgeVisited),n))}},Xs=t=>e=>n=>r=>{const o=r.src,i=(d=>{let f=d,h=!0,m;for(;h;){const p=f;if(p.tag==="Leaf"){h=!1,m=w;continue}if(p.tag==="Node"){const x=t.compare(o)(p._3);if(x==="LT"){f=p._5;continue}if(x==="GT"){f=p._6;continue}if(x==="EQ"){h=!1,m=T("Just",p._4);continue}}_()}return m})(e.poID),a=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;_()})(),s=r.tgt,u=(d=>{let f=d,h=!0,m;for(;h;){const p=f;if(p.tag==="Leaf"){h=!1,m=w;continue}if(p.tag==="Node"){const x=t.compare(s)(p._3);if(x==="LT"){f=p._5;continue}if(x==="GT"){f=p._6;continue}if(x==="EQ"){h=!1,m=T("Just",p._4);continue}}_()}return m})(e.poID),c=(()=>{if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;_()})(),g=(d=>{let f=d,h=!0,m;for(;h;){const p=f;if(p.tag==="Leaf"){h=!1,m=w;continue}if(p.tag==="Node"){const x=t.compare(n)(p._3);if(x==="LT"){f=p._5;continue}if(x==="GT"){f=p._6;continue}if(x==="EQ"){h=!1,m=T("Just",p._4);continue}}_()}return m})(e.poID),l=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;_()})();return(()=>{const d=r.src,f=(h=>{let m=h,p=!0,x;for(;p;){const y=m;if(y.tag==="Leaf"){p=!1,x=w;continue}if(y.tag==="Node"){const N=t.compare(d)(y._3);if(N==="LT"){m=y._5;continue}if(N==="GT"){m=y._6;continue}if(N==="EQ"){p=!1,x=T("Just",y._4);continue}}_()}return x})(e.lowestPoID);return(()=>{if(f.tag==="Nothing")return 0<=l;if(f.tag==="Just")return f._1<=l;_()})()&&(()=>{const h=r.tgt;return l<=a&&(()=>{const m=(p=>{let x=p,y=!0,N;for(;y;){const v=x;if(v.tag==="Leaf"){y=!1,N=w;continue}if(v.tag==="Node"){const J=t.compare(h)(v._3);if(J==="LT"){x=v._5;continue}if(J==="GT"){x=v._6;continue}if(J==="EQ"){y=!1,N=T("Just",v._4);continue}}_()}return N})(e.lowestPoID);return(()=>{if(m.tag==="Nothing")return 0<=l;if(m.tag==="Just")return m._1<=l;_()})()&&l<=c})()})()})()?a>=c:a<c},OT=t=>{const e=ge(t)(Mt);return n=>({layer:e(U(r=>L(r,0))(n)),treeNode:M,treeEdge:M,poID:M,lowestPoID:M,cutvalue:M,postOrder:1,edgeVisited:M})},HT=t=>e=>n=>b(r=>o=>{if((()=>{const g=o.src,l=h=>{let m=h,p=!0,x;for(;p;){const y=m;if(y.tag==="Leaf"){p=!1,x=!1;continue}if(y.tag==="Node"){const N=t.compare(g)(y._3);if(N==="LT"){m=y._5;continue}if(N==="GT"){m=y._6;continue}if(N==="EQ"){p=!1,x=!0;continue}}_()}return x},d=o.tgt,f=h=>{let m=h,p=!0,x;for(;p;){const y=m;if(y.tag==="Leaf"){p=!1,x=!1;continue}if(y.tag==="Node"){const N=t.compare(d)(y._3);if(N==="LT"){m=y._5;continue}if(N==="GT"){m=y._6;continue}if(N==="EQ"){p=!1,x=!0;continue}}_()}return x};return l(n.treeNode)===f(n.treeNode)})())return r;const i=o.tgt,a=(g=>{let l=g,d=!0,f;for(;d;){const h=l;if(h.tag==="Leaf"){d=!1,f=w;continue}if(h.tag==="Node"){const m=t.compare(i)(h._3);if(m==="LT"){l=h._5;continue}if(m==="GT"){l=h._6;continue}if(m==="EQ"){d=!1,f=T("Just",h._4);continue}}_()}return f})(n.layer),s=o.src,u=(g=>{let l=g,d=!0,f;for(;d;){const h=l;if(h.tag==="Leaf"){d=!1,f=w;continue}if(h.tag==="Node"){const m=t.compare(s)(h._3);if(m==="LT"){l=h._5;continue}if(m==="GT"){l=h._6;continue}if(m==="EQ"){d=!1,f=T("Just",h._4);continue}}_()}return f})(n.layer),c=(()=>{if(a.tag==="Nothing"){if(u.tag==="Nothing")return-o.delta;if(u.tag==="Just")return-u._1-o.delta|0;_()}if(a.tag==="Just"){if(u.tag==="Nothing")return(a._1-0|0)-o.delta|0;if(u.tag==="Just")return(a._1-u._1|0)-o.delta|0}_()})();return c<r.slack?{edge:T("Just",o),slack:c}:r})({edge:w,slack:1e9})(e).edge,$T=t=>{const e=ge(t)(Mt);return n=>r=>{const o=b(i=>a=>Tg(i)((()=>{const s=(u=>{let c=u,g=!0,l;for(;g;){const d=c;if(d.tag==="Leaf"){g=!1,l=w;continue}if(d.tag==="Node"){const f=t.compare(a)(d._3);if(f==="LT"){c=d._5;continue}if(f==="GT"){c=d._6;continue}if(f==="EQ"){g=!1,l=T("Just",d._4);continue}}_()}return l})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;_()})()))(1e9)(n);return e(U(i=>L(i,(()=>{const a=(s=>{let u=s,c=!0,g;for(;c;){const l=u;if(l.tag==="Leaf"){c=!1,g=w;continue}if(l.tag==="Node"){const d=t.compare(i)(l._3);if(d==="LT"){u=l._5;continue}if(d==="GT"){u=l._6;continue}if(d==="EQ"){c=!1,g=T("Just",l._4);continue}}_()}return g})(r);if(a.tag==="Nothing")return-o;if(a.tag==="Just")return a._1-o|0;_()})()))(n))}},Sl=t=>{const e=t.Eq0();return n=>r=>o=>{const i=b(s=>u=>{const c=Sl(t)(n)(e.eq(u.src)(r)?u.tgt:u.src)({...s.st,edgeVisited:it(ut)(u.eid)()(s.st.edgeVisited)});return{lowest:Tg(s.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:o})(dt(s=>Hr(s.eid)(o.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!Hr(s.eid)(o.edgeVisited),n)),a=Tg(i.lowest)(i.st.postOrder);return{lowest:a,st:{...i.st,poID:it(t)(r)(i.st.postOrder)(i.st.poID),lowestPoID:it(t)(r)(a)(i.st.lowestPoID),postOrder:i.st.postOrder+1|0}}}},El=t=>{const e=Sl(t);return n=>r=>o=>0<n.length?e(r)(n[0])({...o,edgeVisited:M,postOrder:1,poID:M,lowestPoID:M}).st:o},qT=t=>{const e=t.Eq0();return n=>r=>o=>dt(i=>Hr(i.eid)(r.treeEdge)&&(e.eq(i.src)(o)||e.eq(i.tgt)(o)),n)},UT=t=>e=>Kt(n=>{const r=vg(n.eid)(e.cutvalue);return Hr(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;_()})()})(t),Al=t=>{const e=bg(t);return n=>r=>o=>{const i=0<n.length?T("Just",n[0]):w;if(i.tag==="Nothing")return o;if(i.tag==="Just"){const a=e(r)(i._1)({...o,edgeVisited:M,treeNode:M,treeEdge:M});if(a.count>=n.length)return a.st;const s=HT(t)(r)(a.st);if(s.tag==="Nothing")return a.st;if(s.tag==="Just"){const u=s._1.tgt,c=(h=>{let m=h,p=!0,x;for(;p;){const y=m;if(y.tag==="Leaf"){p=!1,x=w;continue}if(y.tag==="Node"){const N=t.compare(u)(y._3);if(N==="LT"){m=y._5;continue}if(N==="GT"){m=y._6;continue}if(N==="EQ"){p=!1,x=T("Just",y._4);continue}}_()}return x})(a.st.layer),g=s._1.src,l=(h=>{let m=h,p=!0,x;for(;p;){const y=m;if(y.tag==="Leaf"){p=!1,x=w;continue}if(y.tag==="Node"){const N=t.compare(g)(y._3);if(N==="LT"){m=y._5;continue}if(N==="GT"){m=y._6;continue}if(N==="EQ"){p=!1,x=T("Just",y._4);continue}}_()}return x})(a.st.layer),d=(()=>{if(c.tag==="Nothing"){if(l.tag==="Nothing")return-s._1.delta;if(l.tag==="Just")return-l._1-s._1.delta|0;_()}if(c.tag==="Just"){if(l.tag==="Nothing")return(c._1-0|0)-s._1.delta|0;if(l.tag==="Just")return(c._1-l._1|0)-s._1.delta|0}_()})(),f=(()=>{const h=s._1.tgt;return(m=>{let p=m,x=!0,y;for(;x;){const N=p;if(N.tag==="Leaf"){x=!1,y=!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"){x=!1,y=!0;continue}}_()}return y})(a.st.treeNode)})()?-d:d;return Al(t)(n)(r)({...a.st,layer:b(h=>m=>(p=>{let x=p,y=!0,N;for(;y;){const v=x;if(v.tag==="Leaf"){y=!1,N=!1;continue}if(v.tag==="Node"){const J=t.compare(m)(v._3);if(J==="LT"){x=v._5;continue}if(J==="GT"){x=v._6;continue}if(J==="EQ"){y=!1,N=!0;continue}}_()}return N})(a.st.treeNode)?it(t)(m)((()=>{const p=(x=>{let y=x,N=!0,v;for(;N;){const J=y;if(J.tag==="Leaf"){N=!1,v=w;continue}if(J.tag==="Node"){const k=t.compare(m)(J._3);if(k==="LT"){y=J._5;continue}if(k==="GT"){y=J._6;continue}if(k==="EQ"){N=!1,v=T("Just",J._4);continue}}_()}return v})(a.st.layer);if(p.tag==="Nothing")return 0+f|0;if(p.tag==="Just")return p._1+f|0;_()})())(h):h)(a.st.layer)(n)})}}_()}},XT=t=>e=>n=>r=>b(o=>i=>{if(Xs(t)(r)(i.src)(n)&&!Xs(t)(r)(i.tgt)(n)){const a=i.tgt,s=(l=>{let d=l,f=!0,h;for(;f;){const m=d;if(m.tag==="Leaf"){f=!1,h=w;continue}if(m.tag==="Node"){const p=t.compare(a)(m._3);if(p==="LT"){d=m._5;continue}if(p==="GT"){d=m._6;continue}if(p==="EQ"){f=!1,h=T("Just",m._4);continue}}_()}return h})(r.layer),u=i.src,c=(l=>{let d=l,f=!0,h;for(;f;){const m=d;if(m.tag==="Leaf"){f=!1,h=w;continue}if(m.tag==="Node"){const p=t.compare(u)(m._3);if(p==="LT"){d=m._5;continue}if(p==="GT"){d=m._6;continue}if(p==="EQ"){f=!1,h=T("Just",m._4);continue}}_()}return h})(r.layer),g=(()=>{if(s.tag==="Nothing"){if(c.tag==="Nothing")return-i.delta;if(c.tag==="Just")return-c._1-i.delta|0;_()}if(s.tag==="Just"){if(c.tag==="Nothing")return(s._1-0|0)-i.delta|0;if(c.tag==="Just")return(s._1-c._1|0)-i.delta|0}_()})();if(g<o.slack)return{edge:T("Just",i),slack:g}}return o})({edge:w,slack:1e9})(e).edge,VT=t=>{const e=t.Eq0();return n=>r=>o=>i=>{const a=i.tgt,s=i.src;return b(u=>c=>{if((()=>{const g=vg(c.eid)(r.cutvalue);if(g.tag==="Just")return!0;if(g.tag==="Nothing")return!1;_()})()){const g=vg(c.eid)(r.cutvalue),l=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;_()})();return e.eq(s)(c.src)||e.eq(a)(c.tgt)?u-(l-c.weight):u+(l-c.weight)}return e.eq(o)(s)?e.eq(c.src)(o)?u+c.weight:u-c.weight:e.eq(c.src)(o)?u-c.weight:u+c.weight})(i.weight)(dt(u=>u.eid!==i.eid&&(e.eq(u.src)(o)||e.eq(u.tgt)(o)),n))}},YT=t=>{const e=VT(t);return n=>r=>o=>{const i=(a,s,u)=>{const c=(g=>{let l=g,d=!0,f;for(;d;){const h=l;if(h.tag==="Leaf"){d=!1,f=w;continue}if(h.tag==="Node"){const m=t.compare(a)(h._3);if(m==="LT"){l=h._5;continue}if(m==="GT"){l=h._6;continue}if(m==="EQ"){d=!1,f=T("Just",h._4);continue}}_()}return f})(u);if(c.tag==="Just")return it(t)(a)(dt(g=>g.eid!==s.eid,c._1))(u);if(c.tag==="Nothing")return u;_()};return(a=>s=>{let u=a,c=s,g=!0,l;for(;g;){const d=u,f=c,h=(p=>{let x=p,y=!0,N;for(;y;){const v=x;if(v.tag==="Leaf"){y=!1,N=w;continue}if(v.tag==="Node"){const J=t.compare(f)(v._3);if(J==="LT"){x=v._5;continue}if(J==="GT"){x=v._6;continue}if(J==="EQ"){y=!1,N=T("Just",v._4);continue}}_()}return N})(d.unknown),m=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;_()})();if(m.length===1){const p=t.Eq0().eq(m[0].src)(f)?m[0].tgt:m[0].src;u={unknown:i(f,m[0],i(p,m[0],d.unknown)),cutvalue:it(ut)(m[0].eid)(e(n)(d)(f)(m[0]))(d.cutvalue)},c=p;continue}g=!1,l=d}return l})(r)(o)}},Pl=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:c=>g=>c.delta===g.delta&&c.eid===g.eid&&n.eq(c.src)(g.src)&&e.eq(c.tgt)(g.tgt)&&c.weight===g.weight},o={compare:c=>g=>{const l=ut.compare(c.delta)(g.delta);if(l==="LT"||l==="GT"||l!=="EQ")return l;const d=ut.compare(c.eid)(g.eid);if(d==="LT"||d==="GT"||d!=="EQ")return d;const f=t.compare(c.src)(g.src);if(f==="LT"||f==="GT"||f!=="EQ")return f;const h=t.compare(c.tgt)(g.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const m=at.compare(c.weight)(g.weight);return m==="LT"||m==="GT"||m!=="EQ"?m:an},Eq0:()=>r},i=b(c=>g=>it(o)(g)()(c))(M),a=qT(t),s=ge(t)(Mt),u=YT(t);return c=>g=>l=>{const d={unknown:s(U(f=>L(f,Wt(ln.foldr,i(a(g)(l)(f)))))(c)),cutvalue:M};return{...l,cutvalue:b(u(g))(d)(dt(f=>{const h=(m=>{let p=m,x=!0,y;for(;x;){const N=p;if(N.tag==="Leaf"){x=!1,y=w;continue}if(N.tag==="Node"){const v=t.compare(f)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){x=!1,y=T("Just",N._4);continue}}_()}return y})(d.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;_()},c)).cutvalue}}},KT=t=>{const e=El(t),n=Pl(t);return r=>o=>i=>a=>s=>{const u={...s,treeEdge:it(ut)(a.eid)()(bi(ut)(i.eid)(s.treeEdge))},c=a.tgt,g=(m=>{let p=m,x=!0,y;for(;x;){const N=p;if(N.tag==="Leaf"){x=!1,y=w;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"){x=!1,y=T("Just",N._4);continue}}_()}return y})(u.layer),l=a.src,d=(m=>{let p=m,x=!0,y;for(;x;){const N=p;if(N.tag==="Leaf"){x=!1,y=w;continue}if(N.tag==="Node"){const v=t.compare(l)(N._3);if(v==="LT"){p=N._5;continue}if(v==="GT"){p=N._6;continue}if(v==="EQ"){x=!1,y=T("Just",N._4);continue}}_()}return y})(u.layer),f=(()=>{if(g.tag==="Nothing"){if(d.tag==="Nothing")return-a.delta;if(d.tag==="Just")return-d._1-a.delta|0;_()}if(g.tag==="Just"){if(d.tag==="Nothing")return(g._1-0|0)-a.delta|0;if(d.tag==="Just")return(g._1-d._1|0)-a.delta|0}_()})(),h=Xs(t)(u)(a.tgt)(i)?f:-f;return n(r)(o)(e(r)(o)({...u,layer:b(m=>p=>Xs(t)(u)(p)(i)?m:it(t)(p)((()=>{const x=(y=>{let N=y,v=!0,J;for(;v;){const k=N;if(k.tag==="Leaf"){v=!1,J=w;continue}if(k.tag==="Node"){const S=t.compare(p)(k._3);if(S==="LT"){N=k._5;continue}if(S==="GT"){N=k._6;continue}if(S==="EQ"){v=!1,J=T("Just",k._4);continue}}_()}return J})(u.layer);if(x.tag==="Nothing")return 0+h|0;if(x.tag==="Just")return x._1+h|0;_()})())(m))(u.layer)(r)}))}},jT=t=>{const e=KT(t);return n=>r=>o=>i=>(a=>s=>{let u=a,c=s,g=!0,l;for(;g;){const d=u,f=c;if(d===0){g=!1,l=f;continue}const h=UT(o)(f);if(h.tag==="Nothing"){g=!1,l=f;continue}if(h.tag==="Just"){const m=XT(t)(o)(h._1)(f);if(m.tag==="Nothing"){g=!1,l=f;continue}if(m.tag==="Just"){u=d-1|0,c=e(r)(o)(h._1)(m._1)(f);continue}}_()}return l})(n)(i)},ZT=t=>{const e=Pl(t),n=El(t),r=Al(t);return o=>i=>a=>e(o)(i)(n(o)(i)(r(o)(i)(a)))},Rl=t=>e=>b(n=>r=>zt(t)(ye)(e(r))([r])(n))(M),tv=t=>{const e=ge(t)(Mt);return n=>r=>o=>{const i=u=>c=>g=>l=>{let d=u,f=c,h=g,m=l,p=!0,x;for(;p;){const y=d,N=f,v=h,J=m,k=At(S=>w,S=>A=>T("Just",{head:S,tail:A}),v);if(k.tag==="Nothing"){p=!1,x=J;continue}if(k.tag==="Just"){const S=k._1.head,A=(E=>{let G=E,nt=!0,V;for(;nt;){const Q=G;if(Q.tag==="Leaf"){nt=!1,V=w;continue}if(Q.tag==="Node"){const Y=t.compare(S)(Q._3);if(Y==="LT"){G=Q._5;continue}if(Y==="GT"){G=Q._6;continue}if(Y==="EQ"){nt=!1,V=T("Just",Q._4);continue}}_()}return V})(J.layer),I=(()=>{if(A.tag==="Nothing")return 0;if(A.tag==="Just")return A._1;_()})(),$=b(E=>G=>{const nt=G.tgt,V=(Y=>{let X=Y,D=!0,F;for(;D;){const B=X;if(B.tag==="Leaf"){D=!1,F=w;continue}if(B.tag==="Node"){const z=t.compare(nt)(B._3);if(z==="LT"){X=B._5;continue}if(z==="GT"){X=B._6;continue}if(z==="EQ"){D=!1,F=T("Just",B._4);continue}}_()}return F})(E.incident),Q=(()=>{if(V.tag==="Nothing")return-1;if(V.tag==="Just")return V._1-1|0;_()})();return{st:{...E.st,layer:it(t)(G.tgt)(zT((()=>{const Y=G.tgt,X=(D=>{let F=D,B=!0,z;for(;B;){const j=F;if(j.tag==="Leaf"){B=!1,z=w;continue}if(j.tag==="Node"){const W=t.compare(Y)(j._3);if(W==="LT"){F=j._5;continue}if(W==="GT"){F=j._6;continue}if(W==="EQ"){B=!1,z=T("Just",j._4);continue}}_()}return z})(E.st.layer);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;_()})())(I+G.delta|0))(E.st.layer)},incident:it(t)(G.tgt)(Q)(E.incident),queue:Q===0?[...E.queue,G.tgt]:E.queue}})({st:J,incident:N,queue:k._1.tail})((()=>{const E=(G=>{let nt=G,V=!0,Q;for(;V;){const Y=nt;if(Y.tag==="Leaf"){V=!1,Q=w;continue}if(Y.tag==="Node"){const X=t.compare(S)(Y._3);if(X==="LT"){nt=Y._5;continue}if(X==="GT"){nt=Y._6;continue}if(X==="EQ"){V=!1,Q=T("Just",Y._4);continue}}_()}return Q})(y);if(E.tag==="Nothing")return[];if(E.tag==="Just")return E._1;_()})());d=y,f=$.incident,h=$.queue,m=$.st;continue}_()}return x},a=Rl(t)(u=>u.tgt)(r),s=e(U(u=>L(u,(()=>{const c=(g=>{let l=g,d=!0,f;for(;d;){const h=l;if(h.tag==="Leaf"){d=!1,f=w;continue}if(h.tag==="Node"){const m=t.compare(u)(h._3);if(m==="LT"){l=h._5;continue}if(m==="GT"){l=h._6;continue}if(m==="EQ"){d=!1,f=T("Just",h._4);continue}}_()}return f})(a);if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1.length;_()})()))(n));return i(Rl(t)(u=>u.src)(r))(s)(dt(u=>{const c=(g=>{let l=g,d=!0,f;for(;d;){const h=l;if(h.tag==="Leaf"){d=!1,f=w;continue}if(h.tag==="Node"){const m=t.compare(u)(h._3);if(m==="LT"){l=h._5;continue}if(m==="GT"){l=h._6;continue}if(m==="EQ"){d=!1,f=T("Just",h._4);continue}}_()}return f})(s);if(c.tag==="Nothing")return!0;if(c.tag==="Just")return c._1===0;_()},n))(o)}},ev=t=>{const e=OT(t),n=tv(t),r=ZT(t),o=jT(t);return i=>a=>{const s=n(i)(a)(e(i));return a.length===0?s.layer:o(4*i.length|0)(i)(a)(r(i)(a)(s)).layer}},Gl=t=>{const e=$T(t),n=ev(t),r=QT(t);return o=>i=>{if(o.length===0)return M;if(o.length<40)return e(o)(n(o)(i));const a=r(o)(i);return e(o)(WT(t)(a.removed)(n(a.coreNodes)(a.coreEdges)))}},Dl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Jg=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},nv=Gl(ut),ma=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}),rv=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=rt((()=>{const o=Dl(n.cGroup._1)(t);if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;_()})());return Cn(n.id)(o=>({...o,hitbox:{...o.hitbox,x:r+o.cGroupOffset.x}}))(e)}_()},ov=t=>e=>({...e,cGraph:b(rv(t))(e.cGraph)((()=>{const n=e.cGraph;return wt(r=>le(r)(n.cNodes))(n.cNodeOrder)})())}),iv=t=>e=>n=>r=>o=>{const i=de(us(e.cGroupOffset.x-t.cGroupOffset.x));return ma({src:o.nextNodeId,tgt:r,delta:Jg(0)(-i),weight:1})(ma({src:o.nextNodeId,tgt:n,delta:Jg(0)(i),weight:1})({...o,nodes:[...o.nodes,o.nextNodeId],nextNodeId:o.nextNodeId+1|0}))},av=t=>e=>n=>r=>o=>i=>a=>{const s=Jg(0)(de(us(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)?iv(n)(r)(o)(i)(a):ma({src:o,tgt:i,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(a)},sv=t=>e=>n=>r=>o=>{const i=le(o)(e.cGraph.cNodes);if(i.tag==="Nothing")return r;if(i.tag==="Just")return(n.cGroup.tag==="Nothing"?i._1.cGroup.tag==="Nothing":n.cGroup.tag==="Just"&&i._1.cGroup.tag==="Just"&&n.cGroup._1===i._1.cGroup._1)?r:n.cGroup.tag==="Just"&&i._1.cGroup.tag==="Just"?av(t)(e)(n)(i._1)(n.cGroup._1)(i._1.cGroup._1)(r):r;_()},uv=t=>e=>n=>r=>b(sv(t)(e)(r))(n)(r.constraints),cv=t=>e=>ma({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),gv=t=>{const e=b(o=>i=>zt(ut)(ve)(i.tgt)(1)(o))(M)(t.edges),n=dt(o=>{const i=Dl(o)(e);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return i._1===0;_()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return b(o=>i=>ma({src:r,tgt:i,delta:1,weight:0})(o))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},_v=t=>e=>{const n=gv(b(cv)(b(uv(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return wt(o=>le(o)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},fv=t=>e=>{const n=_v(t)(e);return ov(nv(n.nodes)(n.edges))(e)},Fl=t=>t,we=Fl("H"),me=Fl("V"),lv=t=>L(t._2,t._1),Il=t=>({...t,position:L(t.position._2,t.position._1),size:L(t.size._2,t.size._1)}),dv=t=>({start:L(t.start._2,t.start._1),end:L(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return me;if(t.direction==="V")return we;_()})()}),Bl=t=>({...t,segments:U(dv)(t.segments),bends:U(lv)(t.bends)}),hv=t=>({nodes:U(Il)(t.nodes),edges:t.edges,paths:U(Bl)(t.paths),ports:t.ports}),pv={nodeNode:8,edgeNode:4,edgeEdge:10},mv=t=>e=>({horizontalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r)||n.ignoreSpacing.right||r.ignoreSpacing.left)return 0;const o=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?o?t.edgeEdge:t.edgeNode:o?t.edgeNode:t.nodeNode},verticalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r))return 1;if(n.hitbox.y<=r.hitbox.y?n.ignoreSpacing.down||r.ignoreSpacing.up:n.ignoreSpacing.up||r.ignoreSpacing.down)return 0;const o=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?o?t.edgeEdge:t.edgeNode:o?t.edgeNode:t.nodeNode}}),yv=t=>e=>fv(e),xv=t=>e=>n=>{const r=hv(n),o=MT(r),i=GT(o)(kl(r)),a=DT(hl(dg)(oT({...aT(o.cGraph),compactionAlgorithm:T("Just",yv()(i)),constraintAlgorithm:T("Just",yT(e.edgeEdge)),spacingsHandler:mv(e)(i)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:U(Il)(a.nodes),edges:U(Bl)(a.edges)}},Ml=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},zl=t=>De(3)(t)==="$d:",wv=t=>e=>n=>b(r=>o=>{const i=Ml(o.from.node)(t),a=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;_()})(),s=Ml(o.to.node)(t),u=(()=>{if(s.tag==="Nothing")return-a;if(s.tag==="Just")return s._1-a|0;_()})();if(u<=1)return{...r,edges:[...r.edges,o],chains:[...r.chains,{edgeId:o.id,nodes:[o.from.node,o.to.node]}]};const c=o.id,g=U(d=>"$d:"+c+":"+ae(d))(Yt(1,u-1|0)),l=[o.from.node,...g,o.to.node];return{...r,layers:b(d=>f=>{const h=f._2,m=F2(a+f._1|0)(p=>[...p,h])(d);if(m.tag==="Nothing")return d;if(m.tag==="Just")return m._1;_()})(r.layers)($e(vn,Yt(1,u-1|0),g)),edges:[...r.edges,...$e(d=>f=>({id:c+":"+d+"->"+f,from:{node:d,port:o.from.port},to:{node:f,port:o.to.port},label:w}),l,Rt(1,l.length,l))],chains:[...r.chains,{edgeId:o.id,nodes:l}]}})({layers:n,edges:[],chains:[]})(e),Ql=t=>t,Ri=ge(ut)(Mt),Zt=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Wl=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Jt=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},Ct=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Gi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Nv=t=>e=>{const n=ut.compare(t._1)(e._1);return n==="LT"?Me:n==="GT"?ze:ut.compare(t._2)(e._2)},Di=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},Tv=(()=>{const t=mn.unfoldr(sr);return e=>t(yn("IterNode",e,ir))})(),vv=t=>t,Ol=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},bv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Vs=Ql("Regular"),Ys=Ql("Critical"),Hl=t=>e=>{const n=b(a=>s=>it(P)(s.node)(s)(a))(M)(e),r=1.25*rt(4),o=(a,s,u)=>(c=>g=>l=>{let d=c,f=g,h=l,m=!0,p;for(;m;){const x=d,y=f,N=h;if(N.critical){m=!1,p=N;continue}const v=At(k=>w,k=>S=>T("Just",{head:k,tail:S}),x),J=At(k=>w,k=>S=>T("Just",{head:k,tail:S}),y);if(v.tag==="Just"&&J.tag==="Just"){const k=v._1.head>J._1.head-a&&v._1.head<J._1.head+a?{...N,critical:!0}:v._1.head>J._1.head-r&&v._1.head<J._1.head+r?{...N,conflicts:N.conflicts+1|0}:N;if(k.critical){m=!1,p=k;continue}if(v._1.head<=J._1.head){d=v._1.tail,f=y,h=k;continue}d=x,f=J._1.tail,h=k;continue}m=!1,p=N}return p})(s)(u)({conflicts:0,critical:!1}),i=(a,s,u)=>{if(Ct(b(Ct)(-1e18)(s.incoming))(b(Ct)(-1e18)(s.outgoing))-Jt(b(Jt)(1e18)(s.incoming))(b(Jt)(1e18)(s.outgoing))<.001||Ct(b(Ct)(-1e18)(u.incoming))(b(Ct)(-1e18)(u.outgoing))-Jt(b(Jt)(1e18)(u.incoming))(b(Jt)(1e18)(u.outgoing))<.001)return[];const c=o(a,s.outgoing,u.incoming),g=o(a,u.outgoing,s.incoming);if(c.critical||g.critical)return[...c.critical?[{src:u.id,tgt:s.id,weight:1,kind:Ys}]:[],...g.critical?[{src:s.id,tgt:u.id,weight:1,kind:Ys}]:[]];const l=Jt(b(Jt)(1e18)(s.incoming))(b(Jt)(1e18)(s.outgoing)),d=Ct(b(Ct)(-1e18)(s.incoming))(b(Ct)(-1e18)(s.outgoing)),f=Jt(b(Jt)(1e18)(u.incoming))(b(Jt)(1e18)(u.outgoing)),h=Ct(b(Ct)(-1e18)(u.incoming))(b(Ct)(-1e18)(u.outgoing)),m=(1*c.conflicts|0)+(16*(b(x=>y=>y>h?x:y>=f?x+1|0:x)(0)(s.outgoing)+b(x=>y=>y>d?x:y>=l?x+1|0:x)(0)(u.incoming)|0)|0)|0,p=(1*g.conflicts|0)+(16*(b(x=>y=>y>d?x:y>=l?x+1|0:x)(0)(u.outgoing)+b(x=>y=>y>h?x:y>=f?x+1|0:x)(0)(s.incoming)|0)|0)|0;return m<p?[{src:s.id,tgt:u.id,weight:p-m|0,kind:Vs}]:m>p?[{src:u.id,tgt:s.id,weight:m-p|0,kind:Vs}]:m>0?[{src:s.id,tgt:u.id,weight:0,kind:Vs},{src:u.id,tgt:s.id,weight:0,kind:Vs}]:[]};return b(a=>s=>b(u=>c=>it(P)(c._1)(c._2)(u))(a)((()=>{const u=b(E=>G=>{const nt=G.edge.from.node+"|"+(()=>{if(G.edge.from.port.tag==="Just")return G.edge.from.port._1;if(G.edge.from.port.tag==="Nothing")return"_auto_"+G.edge.id;_()})(),V=Ol(nt)(E.entries);if(V.tag==="Nothing")return{...E,entries:it(P)(nt)({id:0,members:[G.edge.id],incoming:[G.fromPos._1],outgoing:[G.toPos._1],slot:0,mark:0,splitBy:w,splitPartner:w})(E.entries),order:[...E.order,nt]};if(V.tag==="Just")return{...E,entries:it(P)(nt)({...V._1,members:[...V._1.members,G.edge.id],incoming:[...vr(Q=>Q<G.fromPos._1)(V._1.incoming).init,G.fromPos._1,...vr(Q=>Q<=G.fromPos._1)(V._1.incoming).rest],outgoing:[...vr(Q=>Q<G.toPos._1)(V._1.outgoing).init,G.toPos._1,...vr(Q=>Q<=G.toPos._1)(V._1.outgoing).rest]})(E.entries)};_()})({entries:M,order:[]})(s._2),c=Ot(E=>G=>({...G,id:E}))(wt(E=>Ol(E)(u.entries))(u.order));if(c.length===0)return[];const g=b(E=>G=>E.prev.tag==="Just"&&G-E.prev._1<1e-9?E:{prev:T("Just",G),out:[...E.out,G]})({prev:w,out:[]})(Gt(at.compare)([...Et(c)(E=>E.incoming),...Et(c)(E=>E.outgoing)])).out,l=g.length<2?.2*r:.2*b(E=>G=>{if(E.prev.tag==="Nothing")return{prev:T("Just",G),mn:E.mn};if(E.prev.tag==="Just")return{prev:T("Just",G),mn:Jt(E.mn)(G-E.prev._1)};_()})({prev:w,mn:1e18})(g).mn,d={segments:c,deps:(()=>{const E=c.length;return Et(Et(Yt(0,E-2|0))(G=>Et(Yt(G+1|0,E-1|0))(nt=>[L(G,nt)])))(G=>G._1>=0&&G._1<c.length?G._2>=0&&G._2<c.length?i(l,c[G._1],c[G._2]):[]:[])})()},f=dt(E=>{if(E.kind==="Critical")return!0;if(E.kind==="Regular")return!1;_()},d.deps),h=(()=>{if(f.length<2)return d;const E=Ri((()=>{const Y=d.segments;return U(X=>L(X.id,X.mark))((()=>{const X=Y.length,D=B=>{let z=B,j=!0,W;for(;j;){const O=z,q=Kt(H=>{const ot=Zt(H)(O.inWeight);if(ot.tag==="Nothing")return!0;if(ot.tag==="Just")return ot._1===0;_()})(O.remaining);if(q.tag==="Nothing"){j=!1,W=O;continue}if(q.tag==="Just"){const H=q._1;z={...O,inWeight:b(ot=>et=>zt(ut)(ve)(et.tgt)(-et.weight)(ot))(O.inWeight)((()=>{const ot=Zt(H)(O.depsBySrc);if(ot.tag==="Nothing")return[];if(ot.tag==="Just")return ot._1;_()})()),marks:it(ut)(H)(O.nextSource)(O.marks),nextSource:O.nextSource+1|0,outWeight:b(ot=>et=>zt(ut)(ve)(et.src)(-et.weight)(ot))(O.outWeight)((()=>{const ot=Zt(H)(O.depsByTgt);if(ot.tag==="Nothing")return[];if(ot.tag==="Just")return ot._1;_()})()),remaining:dt(ot=>ot!==H,O.remaining)};continue}_()}return W},F=B=>{let z=B,j=!0,W;for(;j;){const O=z,q=Kt(H=>{const ot=Zt(H)(O.outWeight);if(ot.tag==="Nothing")return!0;if(ot.tag==="Just")return ot._1===0;_()})(O.remaining);if(q.tag==="Nothing"){j=!1,W=O;continue}if(q.tag==="Just"){const H=q._1;z={...O,inWeight:b(ot=>et=>zt(ut)(ve)(et.tgt)(-et.weight)(ot))(O.inWeight)((()=>{const ot=Zt(H)(O.depsBySrc);if(ot.tag==="Nothing")return[];if(ot.tag==="Just")return ot._1;_()})()),marks:it(ut)(H)(O.nextSink)(O.marks),nextSink:O.nextSink-1|0,outWeight:b(ot=>et=>zt(ut)(ve)(et.src)(-et.weight)(ot))(O.outWeight)((()=>{const ot=Zt(H)(O.depsByTgt);if(ot.tag==="Nothing")return[];if(ot.tag==="Just")return ot._1;_()})()),remaining:dt(ot=>ot!==H,O.remaining)};continue}_()}return W};return(B=>{let z=B,j=!0,W;for(;j;){const O=D(F(z));if(O.remaining.length===0){j=!1,W=U(q=>{const H=Zt(q.id)(O.marks),ot=(()=>{if(H.tag==="Nothing")return q.id;if(H.tag==="Just")return H._1;_()})();return{...q,mark:ot<X?(ot+X|0)+1|0:ot}})(Y);continue}z=(()=>{const q=ot=>{const et=Zt(ot)(O.outWeight),gt=Zt(ot)(O.inWeight);return(()=>{if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1;_()})()-(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;_()})()|0},H=Gt(ot=>et=>ut.compare(q(et))(q(ot)))(O.remaining);if(0<H.length){const ot=H[0];return{...O,inWeight:b(et=>gt=>zt(ut)(ve)(gt.tgt)(-gt.weight)(et))(O.inWeight)((()=>{const et=Zt(ot)(O.depsBySrc);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;_()})()),marks:it(ut)(ot)(O.nextSource)(O.marks),nextSource:O.nextSource+1|0,outWeight:b(et=>gt=>zt(ut)(ve)(gt.src)(-gt.weight)(et))(O.outWeight)((()=>{const et=Zt(ot)(O.depsByTgt);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;_()})()),remaining:dt(et=>et!==ot,O.remaining)}}return O})()}return W})({remaining:U(B=>B.id)(Y),marks:M,inWeight:b(B=>z=>zt(ut)(ve)(z.tgt)(z.weight)(B))(M)(f),outWeight:b(B=>z=>zt(ut)(ve)(z.src)(z.weight)(B))(M)(f),depsBySrc:b(B=>z=>zt(ut)(ye)(z.src)([z])(B))(M)(f),depsByTgt:b(B=>z=>zt(ut)(ye)(z.tgt)([z])(B))(M)(f),nextSink:X-1|0,nextSource:X+1|0})})())})()),G=dt(Y=>{const X=Zt(Y.src)(E),D=Zt(Y.tgt)(E);return(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;_()})()>(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;_()})()},f);if(G.length===0)return d;const nt=b(Y=>X=>{if(_n(ao)(X.src)(Y.decisions)||_n(ao)(X.tgt)(Y.decisions))return Y;const D=Zt(X.src)(Y.segMap),F=Zt(X.tgt)(Y.segMap);if(D.tag==="Just"&&F.tag==="Just"){const B=(D._1.incoming.length+D._1.outgoing.length|0)>2&&(F._1.incoming.length+F._1.outgoing.length|0)<=2,z=B?F._1:D._1;return{decisions:[...Y.decisions,z.id],segMap:it(ut)(z.id)({...z,splitBy:T("Just",B?D._1.id:F._1.id)})(Y.segMap)}}return Y})({decisions:[],segMap:Ri(U(Y=>L(Y.id,Y))(d.segments))})(G),V=nt.segMap,Q=b(Y=>X=>{const D=Jt(b(Jt)(1e18)(X.incoming))(b(Jt)(1e18)(X.outgoing)),F=Ct(b(Ct)(-1e18)(X.incoming))(b(Ct)(-1e18)(X.outgoing)),B=dt(q=>q.a.startPosition<=F&&q.a.endPosition>=D,Ot(q=>H=>({i:q,a:H}))(Y.freeAreas));if(B.length===0){const q={...X,incoming:Gt(at.compare)(X.incoming),outgoing:Gt(at.compare)([(D+F)/2]),splitPartner:T("Just",Y.nextId)},H={id:Y.nextId,incoming:Gt(at.compare)([(D+F)/2]),mark:0,members:X.members,outgoing:Gt(at.compare)(X.outgoing),slot:0,splitBy:w,splitPartner:T("Just",X.id)};return{segMap:it(ut)(H.id)(H)(it(ut)(q.id)(q)(Y.segMap)),freeAreas:Y.freeAreas,nextId:Y.nextId+1|0}}const z=0<B.length?T("Just",B[0]):w,j=(()=>{if(z.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(z.tag==="Just"){if(B.length===1)return z._1;const q=U(H=>({c:H,rating:(()=>{const ot=(H.a.startPosition+H.a.endPosition)/2,et=[ot],gt=[ot],Lt=b((()=>{const Nt=Y.segMap;return kt=>jt=>{const Tt=Zt(jt.tgt)(Nt);if(Tt.tag==="Nothing")return kt;if(Tt.tag==="Just"){const Vt=Jt(b(Jt)(1e18)(Tt._1.incoming))(b(Jt)(1e18)(Tt._1.outgoing)),Ft=Ct(b(Ct)(-1e18)(Tt._1.incoming))(b(Ct)(-1e18)(Tt._1.outgoing)),vt=Jt(b(Jt)(1e18)(X.incoming))(b(Jt)(1e18)(et)),mt=(()=>{const $t=Ct(b(Ct)(-1e18)(X.incoming))(b(Ct)(-1e18)(et)),te=b(se=>Te=>Te>Ft?se:Te>=Vt?se+1|0:se)(0)(et)+b(se=>Te=>Te>$t?se:Te>=vt?se+1|0:se)(0)(Tt._1.incoming)|0,on=Jt(b(Jt)(1e18)(X.incoming))(b(Jt)(1e18)(et)),He=Ct(b(Ct)(-1e18)(X.incoming))(b(Ct)(-1e18)(et)),Pn=Jt(b(Jt)(1e18)(Tt._1.incoming))(b(Jt)(1e18)(Tt._1.outgoing)),Rn=Ct(b(Ct)(-1e18)(Tt._1.incoming))(b(Ct)(-1e18)(Tt._1.outgoing)),Ze=b(se=>Te=>Te>He?se:Te>=on?se+1|0:se)(0)(Tt._1.outgoing)+b(se=>Te=>Te>Rn?se:Te>=Pn?se+1|0:se)(0)(X.incoming)|0;return te===Ze?te>0?{...kt,deps:kt.deps+2|0,crossings:kt.crossings+te|0}:kt:{...kt,deps:kt.deps+1|0,crossings:kt.crossings+Di(te)(Ze)|0}})(),lt=Jt(b(Jt)(1e18)(Tt._1.incoming))(b(Jt)(1e18)(Tt._1.outgoing)),xt=Ct(b(Ct)(-1e18)(Tt._1.incoming))(b(Ct)(-1e18)(Tt._1.outgoing)),Dt=Jt(b(Jt)(1e18)(gt))(b(Jt)(1e18)(X.outgoing)),ht=Ct(b(Ct)(-1e18)(gt))(b(Ct)(-1e18)(X.outgoing)),bt=b($t=>te=>te>xt?$t:te>=lt?$t+1|0:$t)(0)(X.outgoing)+b($t=>te=>te>ht?$t:te>=Dt?$t+1|0:$t)(0)(Tt._1.incoming)|0,Qt=Jt(b(Jt)(1e18)(gt))(b(Jt)(1e18)(X.outgoing)),Bt=Ct(b(Ct)(-1e18)(gt))(b(Ct)(-1e18)(X.outgoing)),ie=Jt(b(Jt)(1e18)(Tt._1.incoming))(b(Jt)(1e18)(Tt._1.outgoing)),ce=Ct(b(Ct)(-1e18)(Tt._1.incoming))(b(Ct)(-1e18)(Tt._1.outgoing)),gn=b($t=>te=>te>Bt?$t:te>=Qt?$t+1|0:$t)(0)(Tt._1.outgoing)+b($t=>te=>te>ce?$t:te>=ie?$t+1|0:$t)(0)(gt)|0;return bt===gn?bt>0?{...mt,deps:mt.deps+2|0,crossings:mt.crossings+bt|0}:mt:{...mt,deps:mt.deps+1|0,crossings:mt.crossings+Di(bt)(gn)|0}}_()}})())(b((()=>{const Nt=Y.segMap;return kt=>jt=>{const Tt=Zt(jt.src)(Nt);if(Tt.tag==="Nothing")return kt;if(Tt.tag==="Just"){const Vt=Jt(b(Jt)(1e18)(Tt._1.incoming))(b(Jt)(1e18)(Tt._1.outgoing)),Ft=Ct(b(Ct)(-1e18)(Tt._1.incoming))(b(Ct)(-1e18)(Tt._1.outgoing)),vt=Jt(b(Jt)(1e18)(X.incoming))(b(Jt)(1e18)(et)),mt=(()=>{const $t=Ct(b(Ct)(-1e18)(X.incoming))(b(Ct)(-1e18)(et)),te=b(se=>Te=>Te>Ft?se:Te>=Vt?se+1|0:se)(0)(et)+b(se=>Te=>Te>$t?se:Te>=vt?se+1|0:se)(0)(Tt._1.incoming)|0,on=Jt(b(Jt)(1e18)(X.incoming))(b(Jt)(1e18)(et)),He=Ct(b(Ct)(-1e18)(X.incoming))(b(Ct)(-1e18)(et)),Pn=Jt(b(Jt)(1e18)(Tt._1.incoming))(b(Jt)(1e18)(Tt._1.outgoing)),Rn=Ct(b(Ct)(-1e18)(Tt._1.incoming))(b(Ct)(-1e18)(Tt._1.outgoing)),Ze=b(se=>Te=>Te>He?se:Te>=on?se+1|0:se)(0)(Tt._1.outgoing)+b(se=>Te=>Te>Rn?se:Te>=Pn?se+1|0:se)(0)(X.incoming)|0;return te===Ze?te>0?{...kt,deps:kt.deps+2|0,crossings:kt.crossings+te|0}:kt:{...kt,deps:kt.deps+1|0,crossings:kt.crossings+Di(te)(Ze)|0}})(),lt=Jt(b(Jt)(1e18)(Tt._1.incoming))(b(Jt)(1e18)(Tt._1.outgoing)),xt=Ct(b(Ct)(-1e18)(Tt._1.incoming))(b(Ct)(-1e18)(Tt._1.outgoing)),Dt=Jt(b(Jt)(1e18)(gt))(b(Jt)(1e18)(X.outgoing)),ht=Ct(b(Ct)(-1e18)(gt))(b(Ct)(-1e18)(X.outgoing)),bt=b($t=>te=>te>xt?$t:te>=lt?$t+1|0:$t)(0)(X.outgoing)+b($t=>te=>te>ht?$t:te>=Dt?$t+1|0:$t)(0)(Tt._1.incoming)|0,Qt=Jt(b(Jt)(1e18)(gt))(b(Jt)(1e18)(X.outgoing)),Bt=Ct(b(Ct)(-1e18)(gt))(b(Ct)(-1e18)(X.outgoing)),ie=Jt(b(Jt)(1e18)(Tt._1.incoming))(b(Jt)(1e18)(Tt._1.outgoing)),ce=Ct(b(Ct)(-1e18)(Tt._1.incoming))(b(Ct)(-1e18)(Tt._1.outgoing)),gn=b($t=>te=>te>Bt?$t:te>=Qt?$t+1|0:$t)(0)(Tt._1.outgoing)+b($t=>te=>te>ce?$t:te>=ie?$t+1|0:$t)(0)(gt)|0;return bt===gn?bt>0?{...mt,deps:mt.deps+2|0,crossings:mt.crossings+bt|0}:mt:{...mt,deps:mt.deps+1|0,crossings:mt.crossings+Di(bt)(gn)|0}}_()}})())({crossings:0,deps:0})(dt(Nt=>Nt.tgt===X.id,d.deps)))(dt(Nt=>Nt.src===X.id,d.deps)),ft=(()=>{if(X.splitBy.tag==="Just")return Zt(X.splitBy._1)(Y.segMap);if(X.splitBy.tag==="Nothing")return w;_()})();if(ft.tag==="Just")return{...Lt,deps:Lt.deps+2|0,crossings:(()=>{const Nt=Jt(b(Jt)(1e18)(ft._1.incoming))(b(Jt)(1e18)(ft._1.outgoing)),kt=Jt(b(Jt)(1e18)(gt))(b(Jt)(1e18)(X.outgoing)),jt=Ct(b(Ct)(-1e18)(ft._1.incoming))(b(Ct)(-1e18)(ft._1.outgoing)),Tt=Ct(b(Ct)(-1e18)(gt))(b(Ct)(-1e18)(X.outgoing)),Vt=Jt(b(Jt)(1e18)(X.incoming))(b(Jt)(1e18)(et));return Lt.crossings+(()=>{const Ft=Jt(b(Jt)(1e18)(ft._1.incoming))(b(Jt)(1e18)(ft._1.outgoing)),vt=Ct(b(Ct)(-1e18)(X.incoming))(b(Ct)(-1e18)(et)),mt=Ct(b(Ct)(-1e18)(ft._1.incoming))(b(Ct)(-1e18)(ft._1.outgoing));return((b(lt=>xt=>xt>jt?lt:xt>=Nt?lt+1|0:lt)(0)(et)+b(lt=>xt=>xt>vt?lt:xt>=Vt?lt+1|0:lt)(0)(ft._1.incoming)|0)+b(lt=>xt=>xt>Tt?lt:xt>=kt?lt+1|0:lt)(0)(ft._1.outgoing)|0)+b(lt=>xt=>xt>mt?lt:xt>=Ft?lt+1|0:lt)(0)(gt)|0})()|0})()};if(ft.tag==="Nothing")return Lt;_()})()}))(B);return b(H=>ot=>ot.rating.crossings<H.rating.crossings||!(ot.rating.crossings>H.rating.crossings)&&(ot.rating.deps<H.rating.deps||!(ot.rating.deps>H.rating.deps)&&ot.c.a.size>H.c.a.size)?ot:H)(0<q.length?q[0]:{c:z._1,rating:{crossings:1e6,deps:1e6}})(q).c}_()})(),W={...X,incoming:Gt(at.compare)(X.incoming),outgoing:Gt(at.compare)([(j.a.startPosition+j.a.endPosition)/2]),splitPartner:T("Just",Y.nextId)},O={id:Y.nextId,incoming:Gt(at.compare)([(j.a.startPosition+j.a.endPosition)/2]),mark:0,members:X.members,outgoing:Gt(at.compare)(X.outgoing),slot:0,splitBy:w,splitPartner:T("Just",X.id)};return{segMap:it(ut)(O.id)(O)(it(ut)(W.id)(W)(Y.segMap)),freeAreas:(()=>{if(j.i>=0&&j.i<Y.freeAreas.length){const q=Pf(Ut,w,j.i,Y.freeAreas),H=(()=>{if(q.tag==="Nothing")return Y.freeAreas;if(q.tag==="Just")return q._1;_()})();if(Y.freeAreas[j.i].size/2<l)return H;const ot=(Y.freeAreas[j.i].startPosition+Y.freeAreas[j.i].endPosition)/2,et=ot-l,gt=ot+l;return[...j.i<1?[]:Rt(0,j.i,H),...Y.freeAreas[j.i].startPosition<=et?[{startPosition:Y.freeAreas[j.i].startPosition,endPosition:et,size:et-Y.freeAreas[j.i].startPosition}]:[],...gt<=Y.freeAreas[j.i].endPosition?[{startPosition:gt,endPosition:Y.freeAreas[j.i].endPosition,size:Y.freeAreas[j.i].endPosition-gt}]:[],...j.i<1?H:Rt(j.i,H.length,H)]}return Y.freeAreas})(),nextId:Y.nextId+1|0}})({segMap:V,freeAreas:(()=>{const Y=Gt(at.compare)([...Et(d.segments)(X=>X.incoming),...Et(d.segments)(X=>X.outgoing)]);return wt(vv)($e(X=>D=>D-X>=2*l?T("Just",{startPosition:X+l,endPosition:D-l,size:D-X-2*l}):w,Y,Rt(1,Y.length,Y)))})(),nextId:d.segments.length})(Gt(Y=>X=>at.compare(Ct(b(Ct)(-1e18)(Y.incoming))(b(Ct)(-1e18)(Y.outgoing))-Jt(b(Jt)(1e18)(Y.incoming))(b(Jt)(1e18)(Y.outgoing)))(Ct(b(Ct)(-1e18)(X.incoming))(b(Ct)(-1e18)(X.outgoing))-Jt(b(Jt)(1e18)(X.incoming))(b(Jt)(1e18)(X.outgoing))))(wt(Y=>Zt(Y)(V))(nt.decisions)));return{segments:(()=>{const Y=(X,D)=>{if(X.tag==="Leaf")return D;if(X.tag==="Node")return Y(X._5,yt("Cons",X._4,Y(X._6,D)));_()};return Wt(ue.foldr,Y(Q.segMap,R))})(),deps:(()=>{const Y=Q.segMap,X=(B,z)=>{if(B.tag==="Leaf")return z;if(B.tag==="Node")return X(B._5,yt("Cons",B._4,X(B._6,z)));_()},D=Wt(ue.foldr,X(Y,R)),F=D.length;return[...Et(Et(Yt(0,F-2|0))(B=>Et(Yt(B+1|0,F-1|0))(z=>[L(B,z)])))(B=>B._1>=0&&B._1<D.length?B._2>=0&&B._2<D.length?D[B._1].splitPartner.tag!=="Nothing"&&D[B._1].splitPartner.tag==="Just"&&D[B._1].splitPartner._1===D[B._2].id||D[B._2].splitPartner.tag!=="Nothing"&&D[B._2].splitPartner.tag==="Just"&&D[B._2].splitPartner._1===D[B._1].id?[]:i(l,D[B._1],D[B._2]):[]:[]),...Et(D)(B=>B.splitBy.tag==="Just"&&B.splitPartner.tag==="Just"&&(()=>{const z=Zt(B.splitPartner._1)(Y);if(z.tag==="Nothing")return!1;if(z.tag==="Just")return!0;_()})()&&(()=>{const z=Zt(B.splitBy._1)(Y);if(z.tag==="Nothing")return!1;if(z.tag==="Just")return!0;_()})()?[{src:B.id,tgt:B.splitBy._1,weight:1,kind:Ys},{src:B.splitBy._1,tgt:B.splitPartner._1,weight:1,kind:Ys}]:[])]})()}})(),m=h.segments,p=m.length,x=E=>{let G=E,nt=!0,V;for(;nt;){const Q=G,Y=Kt(X=>{const D=Zt(X)(Q.inWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;_()})(Q.remaining);if(Y.tag==="Nothing"){nt=!1,V=Q;continue}if(Y.tag==="Just"){const X=Y._1;G={...Q,inWeight:b(D=>F=>zt(ut)(ve)(F.tgt)(-F.weight)(D))(Q.inWeight)((()=>{const D=Zt(X)(Q.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;_()})()),marks:it(ut)(X)(Q.nextSource)(Q.marks),nextSource:Q.nextSource+1|0,outWeight:b(D=>F=>zt(ut)(ve)(F.src)(-F.weight)(D))(Q.outWeight)((()=>{const D=Zt(X)(Q.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;_()})()),remaining:dt(D=>D!==X,Q.remaining)};continue}_()}return V},y=E=>{let G=E,nt=!0,V;for(;nt;){const Q=G,Y=Kt(X=>{const D=Zt(X)(Q.outWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;_()})(Q.remaining);if(Y.tag==="Nothing"){nt=!1,V=Q;continue}if(Y.tag==="Just"){const X=Y._1;G={...Q,inWeight:b(D=>F=>zt(ut)(ve)(F.tgt)(-F.weight)(D))(Q.inWeight)((()=>{const D=Zt(X)(Q.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;_()})()),marks:it(ut)(X)(Q.nextSink)(Q.marks),nextSink:Q.nextSink-1|0,outWeight:b(D=>F=>zt(ut)(ve)(F.src)(-F.weight)(D))(Q.outWeight)((()=>{const D=Zt(X)(Q.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;_()})()),remaining:dt(D=>D!==X,Q.remaining)};continue}_()}return V},N=(E=>{let G=E,nt=!0,V;for(;nt;){const Q=x(y(G));if(Q.remaining.length===0){nt=!1,V=U(Y=>{const X=Zt(Y.id)(Q.marks),D=(()=>{if(X.tag==="Nothing")return Y.id;if(X.tag==="Just")return X._1;_()})();return{...Y,mark:D<p?(D+p|0)+1|0:D}})(m);continue}G=(()=>{const Y=D=>{const F=Zt(D)(Q.outWeight),B=Zt(D)(Q.inWeight);return(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;_()})()-(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;_()})()|0},X=Gt(D=>F=>ut.compare(Y(F))(Y(D)))(Q.remaining);if(0<X.length){const D=X[0];return{...Q,inWeight:b(F=>B=>zt(ut)(ve)(B.tgt)(-B.weight)(F))(Q.inWeight)((()=>{const F=Zt(D)(Q.depsBySrc);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;_()})()),marks:it(ut)(D)(Q.nextSource)(Q.marks),nextSource:Q.nextSource+1|0,outWeight:b(F=>B=>zt(ut)(ve)(B.src)(-B.weight)(F))(Q.outWeight)((()=>{const F=Zt(D)(Q.depsByTgt);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;_()})()),remaining:dt(F=>F!==D,Q.remaining)}}return Q})()}return V})({remaining:U(E=>E.id)(m),marks:M,inWeight:b(E=>G=>zt(ut)(ve)(G.tgt)(G.weight)(E))(M)(h.deps),outWeight:b(E=>G=>zt(ut)(ve)(G.src)(G.weight)(E))(M)(h.deps),depsBySrc:b(E=>G=>zt(ut)(ye)(G.src)([G])(E))(M)(h.deps),depsByTgt:b(E=>G=>zt(ut)(ye)(G.tgt)([G])(E))(M)(h.deps),nextSink:p-1|0,nextSource:p+1|0}),v=(()=>{const E=(()=>{const V=Ri(U(Q=>L(Q.id,Q.mark))(N));return{segments:N,deps:wt(Q=>(()=>{if(Q.kind==="Critical")return!0;if(Q.kind==="Regular")return!1;_()})()?T("Just",Q):(()=>{const Y=Zt(Q.src)(V),X=Zt(Q.tgt)(V);return(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;_()})()>(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;_()})()})()?Q.weight===0?w:T("Just",{src:Q.tgt,tgt:Q.src,weight:Q.weight,kind:Q.kind}):T("Just",Q))(h.deps)}})(),G=b(V=>Q=>zt(ut)(ve)(Q.tgt)(1)(V))(M)(E.deps),nt=(V=>{let Q=V,Y=!0,X;for(;Y;){const D=Q,F=At(B=>w,B=>z=>T("Just",{head:B,tail:z}),D.queue);if(F.tag==="Nothing"){Y=!1,X=D;continue}if(F.tag==="Just"){Q=b((()=>{const B=Zt(F._1.head)(D.slots),z=(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;_()})();return j=>W=>{const O=Zt(W)(j.inDegree),q=(()=>{if(O.tag==="Nothing")return-1;if(O.tag==="Just")return O._1-1|0;_()})();return{...j,slots:it(ut)(W)(Wl((()=>{const H=Zt(W)(j.slots);if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;_()})())(z+1|0))(j.slots),inDegree:it(ut)(W)(q)(j.inDegree),queue:q===0?[...j.queue,W]:j.queue}}})())({...D,queue:F._1.tail})((()=>{const B=Zt(F._1.head)(D.adj);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;_()})());continue}_()}return X})({slots:Ri(U(V=>L(V.id,0))(E.segments)),inDegree:G,adj:b(V=>Q=>zt(ut)(ye)(Q.src)([Q.tgt])(V))(M)(E.deps),queue:U(V=>V.id)(dt(V=>{const Q=Zt(V.id)(G);if(Q.tag==="Nothing")return!0;if(Q.tag==="Just")return Q._1===0;_()},E.segments))});return Gt(V=>Q=>ut.compare(V.slot)(Q.slot))(U(V=>({...V,slot:(()=>{const Q=Zt(V.id)(nt.slots);if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;_()})()}))(E.segments))})(),J=1+b(E=>G=>Wl(E)(G.slot))(0)(v)|0,k=Et(v)(E=>E.members),S=dt(E=>_n(Tr)(E.edge.id)(k),t),A=b(Ct)(-1e18)(U(E=>E.fromPos._2)(S)),I=b(Jt)(1e18)(U(E=>E.toPos._2)(S));if(A>I){const E=Ri(U(G=>L(G.id,G))(v));return bn(U(G=>U(nt=>L(nt,{slot:G.slot,slotCount:J,gapTop:I,gapBottom:A,partner:(()=>{if(G.splitPartner.tag==="Just"){const V=Zt(G.splitPartner._1)(E);if(V.tag==="Just")return T("Just",{slot:V._1.slot,splitX:0<V._1.incoming.length?V._1.incoming[0]:0});if(V.tag==="Nothing")return w;_()}if(G.splitPartner.tag==="Nothing")return w;_()})()}))(G.members))(dt(G=>{if(G.splitPartner.tag==="Just"){const nt=Zt(G.splitPartner._1)(E);return!(nt.tag==="Just"&&(()=>{if(nt._1.splitBy.tag==="Nothing")return!1;if(nt._1.splitBy.tag==="Just")return!0;_()})())}if(G.splitPartner.tag==="Nothing")return!0;_()},v)))}const $=Ri(U(E=>L(E.id,E))(v));return bn(U(E=>U(G=>L(G,{slot:E.slot,slotCount:J,gapTop:A,gapBottom:I,partner:(()=>{if(E.splitPartner.tag==="Just"){const nt=Zt(E.splitPartner._1)($);if(nt.tag==="Just")return T("Just",{slot:nt._1.slot,splitX:0<nt._1.incoming.length?nt._1.incoming[0]:0});if(nt.tag==="Nothing")return w;_()}if(E.splitPartner.tag==="Nothing")return w;_()})()}))(E.members))(dt(E=>{if(E.splitPartner.tag==="Just"){const G=Zt(E.splitPartner._1)($);return!(G.tag==="Just"&&(()=>{if(G._1.splitBy.tag==="Nothing")return!1;if(G._1.splitBy.tag==="Just")return!0;_()})())}if(E.splitPartner.tag==="Nothing")return!0;_()},v)))})()))(M)(Tv(b(a=>s=>{const u=Gi(s.edge.from.node)(n);if(u.tag==="Just"){const c=Gi(s.edge.to.node)(n);return c.tag==="Just"&&u._1.layer!==c._1.layer?zt(ut)(ye)(Di(u._1.layer)(c._1.layer))([s])(a):a}return a})(M)((()=>{const a=s=>L((()=>{const u=Gi(s.edge.from.node)(n);return u.tag==="Just"?u._1.layer:1e6})(),(()=>{const u=Gi(s.edge.from.node)(n);return u.tag==="Just"?u._1.order:1e6})());return Gt(s=>u=>Nv(a(s))(a(u)))(t)})())))},Jv=t=>e=>{const n=Hl(t)(e),r=b(o=>i=>it(P)(i.node)(i)(o))(M)(e);return b(o=>i=>{const a=Gi(i.edge.from.node)(r);if(a.tag==="Just"){const s=Gi(i.edge.to.node)(r);if(s.tag==="Just"&&a._1.layer!==s._1.layer){const u=bv(i.edge.id)(n);if(u.tag==="Just")return it(ut)(Di(a._1.layer)(s._1.layer))(u._1.slotCount)(o)}return o}return o})(M)(t)},Cg=ge(P)(Mt),$r=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},kg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Cv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t._1)(i._3._1);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(t._2==="North"){if(i._3._2==="North"){r=!1,o=T("Just",i._4);continue}n=i._5;continue}if(i._3._2==="North"){n=i._6;continue}if(t._2==="South"){if(i._3._2==="South"){r=!1,o=T("Just",i._4);continue}n=i._5;continue}if(i._3._2==="South"){n=i._6;continue}if(t._2==="East"){if(i._3._2==="East"){r=!1,o=T("Just",i._4);continue}n=i._5;continue}if(i._3._2==="East"){n=i._6;continue}if(t._2==="West"&&i._3._2==="West"){r=!1,o=T("Just",i._4);continue}}_()}return o},$l=t=>e=>{const n=e.position._1+e.size._1,r=e.position._2*2+e.size._2,o=e.position._1*2+e.size._1,i=e.position._2+e.size._2;if(t==="South")return L(o,i*2);if(t==="North")return L(o,e.position._2*2);if(t==="East")return L(n*2,r);if(t==="West")return L(e.position._1*2,r);_()},Lg=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};_()},ql=t=>e=>b(n=>r=>zt(t)(ye)(e(r))([r])(n))(M),Ul=t=>e=>n=>r=>{const o=(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;_()})()&&(()=>{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;_()})(),i=(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;_()})()&&(()=>{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;_()})();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:o||i?1:2},Xl=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,o=e.length;return o===0?M:Cg(o===1?U(i=>L(i,r))(e):Ot(i=>a=>L(a,t.lo+rt(i+1|0)*n/rt(o+1|0)))(e))},Vl=t=>e=>n=>r=>o=>{const i=ql(P)(f=>f.to.node)(t),a=ql(P)(f=>f.from.node)(t),s=b(f=>h=>it(P)(h.node)(h)(f))(M)(e),u=(f,h,m)=>{const p=$r(f)(s);if(p.tag==="Nothing")return L(0,0);if(p.tag==="Just"){const x=$r(f)(n);if(x.tag==="Nothing"){const y=rt(4);if(m==="South")return L(p._1.position._1*y+p._1.size._1*y/2,(p._1.position._2+p._1.size._2)*y);if(m==="North")return L(p._1.position._1*y+p._1.size._1*y/2,p._1.position._2*y);if(m==="East")return L((p._1.position._1+p._1.size._1)*y,p._1.position._2*y+p._1.size._2*y/2);if(m==="West")return L(p._1.position._1*y,p._1.position._2*y+p._1.size._2*y/2);_()}if(x.tag==="Just"){const y=Kt(N=>N.id===h)(x._1);if(y.tag==="Nothing"){const N=rt(4);if(m==="South")return L(p._1.position._1*N+p._1.size._1*N/2,(p._1.position._2+p._1.size._2)*N);if(m==="North")return L(p._1.position._1*N+p._1.size._1*N/2,p._1.position._2*N);if(m==="East")return L((p._1.position._1+p._1.size._1)*N,p._1.position._2*N+p._1.size._2*N/2);if(m==="West")return L(p._1.position._1*N,p._1.position._2*N+p._1.size._2*N/2);_()}if(y.tag==="Just"){const N=rt(4);if(y._1.side==="North")return L(p._1.position._1*N+rt(y._1.offset)*N,p._1.position._2*N);if(y._1.side==="South")return L(p._1.position._1*N+rt(y._1.offset)*N,(p._1.position._2+p._1.size._2)*N);if(y._1.side==="East")return L((p._1.position._1+p._1.size._1)*N,p._1.position._2*N+rt(y._1.offset)*N);if(y._1.side==="West")return L(p._1.position._1*N,p._1.position._2*N+rt(y._1.offset)*N)}}}_()},c=Cg(Et(r)(f=>{if(f.nodes.length<=2)return[];const h=rt(4);if(1<f.nodes.length){const m=$r(f.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 U(x=>L(x,p))($e(x=>y=>f.edgeId+":"+x+"->"+y,f.nodes,Rt(1,f.nodes.length,f.nodes)))}_()}return[]})),g=f=>{const h=$r(f.from.node)(s),m=$r(f.to.node)(s);if(h.tag==="Just"&&m.tag==="Just"){const p=h._1,x=m._1,y=Gt(N=>v=>ut.compare(N.score)(v.score))(U(N=>{const v=N._1,J=N._2;return{from:v,to:J,score:(()=>{const k=($,E,G,nt,V)=>{const Q=Lg($)(E),Y=Lg($)(G);return Q.lo<Y.hi&&Y.lo<Q.hi&&(v==="South"?J==="North"&&V._2>nt._2:v==="North"?J==="South"&&V._2<nt._2:v==="East"?J==="West"&&V._1>nt._1:v==="West"&&J==="East"&&V._1<nt._1)?0:Ul(v)(J)(nt)(V)},S=$l(v)(p),A=$l(J)(x),I=Ul(v)(J)(S)(A);return(()=>{if(I>0){if(v==="South")return J==="North"?k(Ge,p,x,S,A)*10|0:I*10|0;if(v==="North")return J==="South"?k(Re,p,x,S,A)*10|0:I*10|0;if(v==="East")return J==="West"?k(Qr,p,x,S,A)*10|0:I*10|0;if(v==="West"&&J==="East")return k(Wr,p,x,S,A)*10|0}return I*10|0})()+(v==="South"?J==="North"?x.layer>=p.layer?0:20:15:v==="North"?J==="South"?x.layer<=p.layer?0:20:15:v==="East"?J==="West"?5:15:v==="West"&&J==="East"?5:15)|0})()}})([L(Ge,Re),L(Qr,Re),L(Wr,Re),L(Ge,Qr),L(Ge,Wr),L(Re,Ge),L(Re,Qr),L(Re,Wr),L(Qr,Ge),L(Wr,Ge),L(Qr,Wr),L(Wr,Qr)]));if(0<y.length)return{from:y[0].from,to:y[0].to}}return{from:Ge,to:Re}},l=Cg(U(f=>L(f.id,g(f)))(t)),d=(f,h,m,p,x,y)=>{const N=rt(4),v=$r(h)(s);if(v.tag==="Nothing")return L(0,0);if(v.tag==="Just"){const J=Cv(L(m,f))(o);if(J.tag==="Just"){const k=v._1.position._1*N+J._1,S=rt(4);if(f==="South")return L(k,(v._1.position._2+v._1.size._2)*S);if(f==="North")return L(k,v._1.position._2*S);if(f==="East")return L((v._1.position._1+v._1.size._1)*S,k);if(f==="West")return L(v._1.position._1*S,k);_()}if(J.tag==="Nothing"){const k=Lg(f)(v._1),S=(k.lo+k.hi)/2,A=kg(m)(Xl(k)(U(E=>E.id)(Gt(E=>G=>at.compare(x(f)(E))(x(f)(G)))(dt(E=>{const G=kg(E.id)(l);if(G.tag==="Just"){const nt=y(G._1);return nt==="North"?f==="North":nt==="South"?f==="South":nt==="East"?f==="East":nt==="West"&&f==="West"}if(G.tag==="Nothing")return!0;_()},(()=>{const E=$r(h)(p);if(E.tag==="Nothing")return[];if(E.tag==="Just")return E._1;_()})()))))),I=(()=>{if(A.tag==="Nothing")return S;if(A.tag==="Just")return A._1;_()})(),$=rt(4);if(f==="South")return L(I,(v._1.position._2+v._1.size._2)*$);if(f==="North")return L(I,v._1.position._2*$);if(f==="East")return L((v._1.position._1+v._1.size._1)*$,I);if(f==="West")return L(v._1.position._1*$,I)}}_()};return U(f=>{const h=kg(f.edge.id)(c);if(h.tag==="Nothing")return f;if(h.tag==="Just")return{...f,fromPos:De(3)(f.edge.from.node)==="$d:"?L(h._1,f.fromPos._2):f.fromPos,toPos:De(3)(f.edge.to.node)==="$d:"?L(h._1,f.toPos._2):f.toPos};_()})(U(f=>{if(f.from.port.tag==="Just"&&f.to.port.tag==="Just")return{edge:f,fromPos:u(f.from.node,f.from.port._1,Ge),toPos:u(f.to.node,f.to.port._1,Re),fromSide:Ge,toSide:Re};const h=g(f);return{edge:f,fromPos:d(h.from,f.from.node,f.id,a,m=>p=>{const x=$r(p.to.node)(s);if(x.tag==="Nothing")return 0;if(x.tag==="Just"){const y=rt(4);if(m==="South"||m==="North")return x._1.position._1*y+x._1.size._1*y/2;if(m==="East"||m==="West")return x._1.position._2*y+x._1.size._2*y/2}_()},m=>m.from),toPos:d(h.to,f.to.node,f.id,i,m=>p=>{const x=$r(p.from.node)(s);if(x.tag==="Nothing")return 0;if(x.tag==="Just"){const y=rt(4);if(m==="South"||m==="North")return x._1.position._1*y+x._1.size._1*y/2;if(m==="East"||m==="West")return x._1.position._2*y+x._1.size._2*y/2}_()},m=>m.to),fromSide:h.from,toSide:h.to}})(t))},Ks=(()=>{const t={eq:e=>n=>e._1===n._1&&(e._2==="North"?n._2==="North":e._2==="South"?n._2==="South":e._2==="East"?n._2==="East":e._2==="West"&&n._2==="West")};return{compare:e=>n=>{const r=P.compare(e._1)(n._1);if(r==="LT")return Me;if(r==="GT")return ze;if(e._2==="North")return n._2==="North"?an:Me;if(n._2==="North")return ze;if(e._2==="South")return n._2==="South"?an:Me;if(n._2==="South")return ze;if(e._2==="East")return n._2==="East"?an:Me;if(n._2==="East")return ze;if(e._2==="West"&&n._2==="West")return an;_()},Eq0:()=>t}})(),kv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=Ks.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Lv=ge(P)(Mt),Sg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Sv=ge(Ks)(Mt),Yl=(()=>{const t=mn.unfoldr(sr);return e=>t(yn("IterNode",e,ir))})(),Fi=t=>e=>n=>r=>{const o=kv(L(e,n))(t);if(o.tag==="Nothing")return r;if(o.tag==="Just")return o._1;_()},Kl=t=>e=>n=>{const r=Lv(bn(U(a=>Ot(s=>u=>L(u,s))(a))(t))),o=(a,s)=>{if(a==="South"){const u=Sg(s.to.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;_()}if(a==="North"){const u=Sg(s.from.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;_()}return 0},i=a=>b(s=>u=>Qe(Ks.compare,Be,Sv(U(c=>L(L(c._1,a),c._2))(Yl(Xl({lo:0,hi:(()=>{const c=Sg(u._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return De(3)(u._1)==="$d:"?0:1;_()})()})(U(c=>c.id)(Gt(c=>g=>ut.compare(o(a,c))(o(a,g)))(u._2)))))),s))(M)(Yl(b(s=>u=>u.from.node===u.to.node?s:a==="South"?zt(P)(ye)(u.from.node)([u])(s):a==="North"?zt(P)(ye)(u.to.node)([u])(s):s)(M)(e)));return Qe(Ks.compare,Be,i(Re),i(Ge))},jl=t=>t,Zl=t=>t,td=t=>t,Ev=b(t=>e=>it(P)(e)()(t))(M),Av=(()=>{const t=mn.unfoldr(e=>{if(e.tag==="Nil")return w;if(e.tag==="Cons")return T("Just",L(e._1,e._2));_()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,yt("Cons",r._3,n(r._6,o)));_()};return n(e,R)})())})(),_t=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Wn=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},Sr=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Er=ge(P)(Mt),Eg=Bf(P),Ag=(()=>{const t=mn.unfoldr(sr);return e=>t(yn("IterNode",e,ir))})(),Pv=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Rv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},ed=td("VDown"),nd=td("VUp"),Gv=Zl("ForwardPhase"),Dv=Zl("StackPhase"),rd=jl("HRight"),od=jl("HLeft"),id=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},Fv=t=>e=>n=>{const r=b(a=>s=>zt(P)(ve)(s.tgt)(1)(a))(M)(t),o=Av(Ev([...U(a=>a.src)(t),...U(a=>a.tgt)(t),...(()=>{const a=(s,u)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return a(s._5,yt("Cons",s._4,a(s._6,u)));_()};return Wt(ue.foldr,a(e,R))})()])),i=b(a=>s=>zt(P)(ye)(s.src)([{target:s.tgt,sep:s.sep}])(a))(M)(t);return(a=>s=>u=>{let c=a,g=s,l=u,d=!0,f;for(;d;){const h=c,m=g,p=l,x=At(y=>w,y=>N=>T("Just",{head:y,tail:N}),h);if(x.tag==="Nothing"){d=!1,f=p;continue}if(x.tag==="Just"){const y=_t(x._1.head)(p),N=(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;_()})(),v=b(J=>k=>{const S=_t(k.target)(J.result),A=N+k.sep,I=_t(k.target)(J.indeg),$=(()=>{if(I.tag==="Nothing")return-1;if(I.tag==="Just")return I._1-1|0;_()})();return{newQueue:$===0?[...J.newQueue,k.target]:J.newQueue,result:it(P)(k.target)((()=>{if(S.tag==="Nothing")return A;if(S.tag==="Just"){if(n==="VDown")return Wn(S._1)(A);if(n==="VUp")return Sr(S._1)(A)}_()})())(J.result),indeg:it(P)(k.target)($)(J.indeg)}})({newQueue:[],result:p,indeg:m})((()=>{const J=_t(x._1.head)(i);if(J.tag==="Nothing")return[];if(J.tag==="Just")return J._1;_()})());c=[...x._1.tail,...v.newQueue],g=v.indeg,l=v.result;continue}_()}return f})(dt(a=>{const s=_t(a)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;_()},o))(r)(b(a=>s=>it(P)(s)(0)(a))(M)(o))},Iv=t=>{const e=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return e(i._5,yt("Cons",i._4,e(i._6,a)));_()},n=Wt(ue.foldr,e(t,R)),r=b(Wn)(999999)(n);if(r===0||n.length===0)return t;const o=i=>{if(i.tag==="Leaf")return M;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,i._4-r,o(i._5),o(i._6));_()};return o(t)},ad=t=>{const e=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return e(i._5,yt("Cons",i._4,e(i._6,a)));_()},n=e(t,R),r=i=>a=>{let s=i,u=a,c=!0,g;for(;c;){const l=s,d=u;if(d.tag==="Nil"){c=!1,g=l;continue}if(d.tag==="Cons"){s=Sr(l)(d._1),u=d._2;continue}_()}return g},o=i=>a=>{let s=i,u=a,c=!0,g;for(;c;){const l=s,d=u;if(d.tag==="Nil"){c=!1,g=l;continue}if(d.tag==="Cons"){s=Wn(l)(d._1),u=d._2;continue}_()}return g};return r(-999999)(n)-o(999999)(n)},ya=t=>e=>(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=i;if(u===e){a=!1,s=c;continue}o=(()=>{const g=_t(u)(t.align);if(g.tag==="Nothing")return e;if(g.tag==="Just")return g._1;_()})(),i=[...c,u]}return s})((()=>{const n=_t(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;_()})())([e]),Bv=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>g=>{const l=(D,F,B)=>{const z=D.from.node===F?D.from.port:D.to.node===F?D.to.port:w;if(z.tag==="Just"){const j=_t(F)(o);if(j.tag==="Just"){const W=Kt(O=>O.id===z._1)(j._1);if(W.tag==="Just"){const O=rt(W._1.offset)*rt(4);return B==="North"||B==="South"?O:0}if(W.tag==="Nothing"){const O=_t(F)(r),q=Fi(a)(D.id)(B)((()=>{if(O.tag==="Nothing")return .5;if(O.tag==="Just")return O._1._1/2;_()})());return B==="North"||B==="South"?q:0}_()}if(j.tag==="Nothing"){const W=_t(F)(r),O=Fi(a)(D.id)(B)((()=>{if(W.tag==="Nothing")return .5;if(W.tag==="Just")return W._1._1/2;_()})());return B==="North"||B==="South"?O:0}_()}if(z.tag==="Nothing"){const j=_t(F)(r),W=Fi(a)(D.id)(B)((()=>{if(j.tag==="Nothing")return .5;if(j.tag==="Just")return j._1._1/2;_()})());return B==="North"||B==="South"?W:0}_()},d=(D,F)=>{if(D.from.node===F){if(g==="HRight")return Ge;if(g==="HLeft")return Re;_()}if(g==="HRight")return Re;if(g==="HLeft")return Ge;_()},f=(D,F,B)=>b(z=>j=>it(P)(j)((()=>{const W=_t(j)(z);if(W.tag==="Nothing")return 0+F;if(W.tag==="Just")return W._1+F;_()})())(z))(B)(ya(u)(D)),h=(()=>{if(g==="HRight")return n;if(g==="HLeft")return re(n);_()})(),m=D=>{const F=_t(D)(r);if(F.tag==="Nothing")return 1;if(F.tag==="Just")return F._1._1;_()},p=Er(bn(Ot(D=>F=>U(B=>L(B,D))(F))(n))),x=(D,F)=>De(3)(D)==="$d:"&&De(3)(F)==="$d:"||De(3)(D)==="$d:"||De(3)(F)==="$d:"?10:rt(t.nodeGap),y=b(D=>F=>Eg(B=>T("Just",[...(()=>{if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;_()})(),F]))(F.to.node)(D))(M)(i),N=b(D=>F=>Eg(B=>T("Just",[...(()=>{if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;_()})(),F]))(F.from.node)(D))(M)(i),v=bn(n),J=b(D=>F=>{const B=_t(F)(u.root),z=(()=>{if(B.tag==="Nothing")return F;if(B.tag==="Just")return B._1;_()})();return F===z?D:Eg(j=>T("Just",(()=>{if(j.tag==="Nothing")return!0;if(j.tag==="Just")return j._1;_()})()&&De(3)(F)==="$d:"))(z)(D)})(Er(U(D=>L(D,!0))(wi(P.compare)((()=>{const D=(F,B)=>{if(F.tag==="Leaf")return B;if(F.tag==="Node")return D(F._5,yt("Cons",F._4,D(F._6,B)));_()};return Wt(ue.foldr,D(u.root,R))})()))))(v),k=(D,F)=>{const B=D.free,z=_t(B)(u.root),j=(()=>{if(z.tag==="Nothing")return B;if(z.tag==="Just")return z._1;_()})(),W=_t(j)(J),O=(()=>{if(W.tag==="Nothing")return!0;if(W.tag==="Just")return W._1;_()})();return b(q=>H=>{if(q.edge.tag==="Just")return q;if(q.edge.tag==="Nothing"){if((()=>{const ft=_t(j)(F.su);return!O&&(()=>{const Nt=_t(H.from.node)(p);return H.from.node!==H.to.node&&(()=>{const kt=_t(H.to.node)(p);return(()=>{if(Nt.tag==="Nothing")return-1;if(Nt.tag==="Just")return Nt._1;_()})()===(()=>{if(kt.tag==="Nothing")return-1;if(kt.tag==="Just")return kt._1;_()})()})()})()||(()=>{if(ft.tag==="Nothing")return!1;if(ft.tag==="Just")return ft._1;_()})()})())return q;const ot=H.from.node===B?H.to.node:H.from.node,et=_t(ot)(u.root),gt=(()=>{if(et.tag==="Nothing")return ot;if(et.tag==="Just")return et._1;_()})(),Lt=gt!==j;return Lt&&(()=>{const ft=_t(gt)(F.blockFinished);if(ft.tag==="Nothing")return!1;if(ft.tag==="Just")return ft._1;_()})()?{...q,edge:T("Just",H),hasEdges:!0}:{...q,hasEdges:q.hasEdges||Lt}}_()})({edge:w,hasEdges:!1})((()=>{if(D.isRoot){if(g==="HRight"){const q=_t(B)(y);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;_()}if(g==="HLeft"){const q=_t(B)(N);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}_()}if(g==="HRight"){const q=_t(B)(N);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;_()}if(g==="HLeft"){const q=_t(B)(y);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}_()})())},S=(D,F,B,z)=>{const j=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;_()})(),W={free:F,isRoot:B},O=k(W,z);if(O.edge.tag==="Nothing")return O.hasEdges?{thresh:j,state:{...z,queue:[...z.queue,W]}}:{thresh:j,state:z};if(O.edge.tag==="Just"){const q=O.edge._1.from.node===F?O.edge._1.to.node:O.edge._1.from.node;return{thresh:(()=>{const H=_t((()=>{const Lt=_t(q)(u.root);if(Lt.tag==="Nothing")return q;if(Lt.tag==="Just")return Lt._1;_()})())(z.x),ot=_t(q)(s),et=_t(F)(s),gt=(()=>{if(H.tag==="Just")return H._1;if(H.tag==="Nothing")return w;_()})();return(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;_()})()+(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;_()})()+l(O.edge._1,q,(()=>{if(B){if(g==="HRight")return Ge;if(g==="HLeft")return Re;_()}if(g==="HRight")return Re;if(g==="HLeft")return Ge;_()})())-(()=>{if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1;_()})()-l(O.edge._1,F,(()=>{if(B){if(g==="HRight")return Re;if(g==="HLeft")return Ge;_()}if(g==="HRight")return Ge;if(g==="HLeft")return Re;_()})())})(),state:{...z,su:it(P)((()=>{const H=_t(O.edge._1.from.node)(u.root);if(H.tag==="Nothing")return O.edge._1.from.node;if(H.tag==="Just")return H._1;_()})())(!0)(it(P)((()=>{const H=_t(O.edge._1.to.node)(u.root);if(H.tag==="Nothing")return O.edge._1.to.node;if(H.tag==="Just")return H._1;_()})())(!0)(z.su))}}}_()},A=(D,F,B,z)=>{const j=F===D,W=_t(F)(u.align),O=(()=>{if(W.tag==="Nothing")return F===D;if(W.tag==="Just")return W._1===D;_()})();if(!(j||O))return{thresh:B,state:z};const q=(()=>{if(c==="VDown")return j&&B<=-1e18;if(c==="VUp")return j&&B>=1e18;_()})()?S(D,F,!0,z):{thresh:B,state:z};return(()=>{if(c==="VDown")return q.thresh<=-1e18&&O;if(c==="VUp")return q.thresh>=1e18&&O;_()})()?S(D,F,!1,q.state):q},I=D=>F=>B=>{const z=_t(B)(e.nodeIndex),j=(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;_()})(),W=Kt(et=>_n(Tr)(B)(et))(h),O=(()=>{if(W.tag==="Nothing")return[];if(W.tag==="Just")return W._1;_()})(),q=O.length;if((()=>{if(c==="VDown")return j<=0;if(c==="VUp")return j>=(q-1|0);_()})()){const et=A(D,B,F.thresh,F.st);return{...F,st:et.state,thresh:et.thresh}}const H=(()=>{if(c==="VDown")return j-1|0;if(c==="VUp")return j+1|0;_()})(),ot=H>=0&&H<O.length?T("Just",O[H]):w;if(ot.tag==="Nothing")return F;if(ot.tag==="Just"){const et=_t(ot._1)(u.root),gt=(()=>{if(et.tag==="Nothing")return ot._1;if(et.tag==="Just")return et._1;_()})(),Lt=A(D,B,F.thresh,$(gt)(F.st)),ft=(()=>{const Bt=_t(D)(Lt.state.sink);if(Bt.tag==="Nothing")return D===D;if(Bt.tag==="Just")return Bt._1===D;_()})()?{...Lt.state,sink:it(P)(D)((()=>{const Bt=_t(gt)(Lt.state.sink);if(Bt.tag==="Nothing")return gt;if(Bt.tag==="Just")return Bt._1;_()})())(Lt.state.sink)}:Lt.state,Nt=_t(gt)(ft.sink),kt=(()=>{if(Nt.tag==="Nothing")return gt;if(Nt.tag==="Just")return Nt._1;_()})(),jt=_t(D)(ft.sink),Tt=(()=>{if(jt.tag==="Nothing")return D;if(jt.tag==="Just")return jt._1;_()})();if(Tt===kt){const Bt=_t(gt)(ft.x),ie=(()=>{if(Bt.tag==="Just")return Bt._1;if(Bt.tag==="Nothing")return w;_()})(),ce=(()=>{if(ie.tag==="Nothing")return 0;if(ie.tag==="Just")return ie._1;_()})(),gn=_t(D)(ft.x),$t=(()=>{if(gn.tag==="Just")return gn._1;if(gn.tag==="Nothing")return w;_()})(),te=(()=>{if($t.tag==="Nothing")return 0;if($t.tag==="Just")return $t._1;_()})(),on=x(B,ot._1),He=_t(ot._1)(s),Pn=_t(B)(s),Rn=(()=>{if(He.tag==="Nothing")return 0;if(He.tag==="Just")return He._1;_()})()-(()=>{if(Pn.tag==="Nothing")return 0;if(Pn.tag==="Just")return Pn._1;_()})();if(c==="VDown"){const Ze=Sr(ce+Rn+m(ot._1)+on)(Lt.thresh);return{st:{...ft,x:it(P)(D)(T("Just",F.initial?Ze:Sr(te)(Ze)))(ft.x)},initial:!1,thresh:Lt.thresh}}if(c==="VUp"){const Ze=Wn(ce+Rn-on-m(B))(Lt.thresh);return{st:{...ft,x:it(P)(D)(T("Just",F.initial?Ze:Wn(te)(Ze)))(ft.x)},initial:!1,thresh:Lt.thresh}}_()}const Vt=_t(gt)(ft.x),Ft=(()=>{if(Vt.tag==="Just")return Vt._1;if(Vt.tag==="Nothing")return w;_()})(),vt=(()=>{if(Ft.tag==="Nothing")return 0;if(Ft.tag==="Just")return Ft._1;_()})(),mt=_t(D)(ft.x),lt=(()=>{if(mt.tag==="Just")return mt._1;if(mt.tag==="Nothing")return w;_()})(),xt=(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;_()})(),Dt=rt(t.nodeGap),ht=_t(B)(s),bt=_t(ot._1)(s),Qt=(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;_()})()-(()=>{if(bt.tag==="Nothing")return 0;if(bt.tag==="Just")return bt._1;_()})();return{st:{...ft,classEdges:[...ft.classEdges,{src:Tt,tgt:kt,sep:(()=>{if(c==="VDown")return xt+Qt-vt-m(ot._1)-Dt;if(c==="VUp")return xt+Qt+m(B)+Dt-vt;_()})()}]},initial:F.initial,thresh:Lt.thresh}}_()},$=D=>F=>{const B=_t(D)(F.x),z=(()=>{if(B.tag==="Just")return B._1;if(B.tag==="Nothing")return w;_()})();if(z.tag==="Just")return F;if(z.tag==="Nothing"){const j=b(I(D))({st:{...F,x:it(P)(D)(T("Just",0))(F.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;_()})()})(ya(u)(D));return{...j.st,blockFinished:it(P)(D)(!0)(j.st.blockFinished)}}_()},E=b(D=>F=>b(B=>z=>{const j=_t(z)(u.root),W=(()=>{if(j.tag==="Nothing")return z;if(j.tag==="Just")return j._1;_()})();return W===z?$(W)(B):B})(D)((()=>{if(c==="VDown")return F;if(c==="VUp")return re(F);_()})()))({x:Er(U(D=>L(D,w))(v)),sink:Er(U(D=>L(D,D))(v)),classEdges:[],su:M,blockFinished:M,queue:[]})(h),G=Fv(E.classEdges)(E.sink)(c),nt=(D,F,B,z)=>{const j=_t(F)(z),W=_t(F)(s);return(()=>{if(j.tag==="Nothing")return 0;if(j.tag==="Just")return j._1;_()})()+(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;_()})()+l(D,F,B)},V=Er(U(D=>L(D,!0))(wi(P.compare)((()=>{const D=(F,B)=>{if(F.tag==="Leaf")return B;if(F.tag==="Node")return D(F._5,yt("Cons",F._4,D(F._6,B)));_()};return Wt(ue.foldr,D(u.root,R))})()))),Q=D=>F=>B=>{const z=k(B,{su:F.su,blockFinished:V}),j={phase:D,ppFree:B.free,ppIsRoot:B.isRoot,edgeId:w,delta:0,avail:0,shift:0,freeSu:(()=>{const W=_t((()=>{const O=_t(B.free)(u.root);if(O.tag==="Nothing")return B.free;if(O.tag==="Just")return O._1;_()})())(F.su);if(W.tag==="Nothing")return!1;if(W.tag==="Just")return W._1;_()})(),hasEdges:z.hasEdges,candCount:(()=>{if(B.isRoot){if(g==="HRight"){const W=_t(B.free)(y);if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1.length;_()}if(g==="HLeft"){const W=_t(B.free)(N);if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1.length}_()}if(g==="HRight"){const W=_t(B.free)(N);if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1.length;_()}if(g==="HLeft"){const W=_t(B.free)(y);if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1.length}_()})()};if(z.edge.tag==="Nothing")return{...F,stack:[...F.stack,B],trace:[...F.trace,j],x:F.x};if(z.edge.tag==="Just"){const W=z.edge._1.from.node===B.free?L(z.edge._1.from.node,z.edge._1.to.node):L(z.edge._1.to.node,z.edge._1.from.node),O=nt(z.edge._1,W._1,d(z.edge._1,W._1),F.x)-nt(z.edge._1,W._2,d(z.edge._1,W._2),F.x),q=_t(W._1)(u.root),H=(()=>{if(q.tag==="Nothing")return W._1;if(q.tag==="Just")return q._1;_()})(),ot={...j,edgeId:T("Just",z.edge._1.id),delta:O};if(O>0&&O<1e300){const et=b(ft=>Nt=>{const kt=_t(Nt)(p),jt=(()=>{if(kt.tag==="Nothing")return-1;if(kt.tag==="Just")return kt._1;_()})();if(jt>=0&&jt<n.length){const Ft=n[jt],vt=_t(Nt)(e.nodeIndex),mt=(()=>{if(vt.tag==="Nothing")return-2;if(vt.tag==="Just")return vt._1-1|0;_()})();return mt>=0&&mt<Ft.length?Wn(ft)((()=>{const lt=_t(Nt)(F.x),xt=_t(Nt)(s),Dt=_t(Ft[mt])(F.x),ht=_t(Ft[mt])(s);return(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;_()})()+(()=>{if(xt.tag==="Nothing")return 0;if(xt.tag==="Just")return xt._1;_()})()-((()=>{if(Dt.tag==="Nothing")return 0;if(Dt.tag==="Just")return Dt._1;_()})()+(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;_()})()+m(Ft[mt])+x(Nt,Ft[mt]))})()):ft}const Tt=_t(Nt)(e.nodeIndex),Vt=(()=>{if(Tt.tag==="Nothing")return-2;if(Tt.tag==="Just")return Tt._1-1|0;_()})();return Vt>=0&&Vt<0?Wn(ft)((()=>{const Ft=_t(Nt)(F.x),vt=_t(Nt)(s),mt=_t([][Vt])(F.x),lt=_t([][Vt])(s);return(()=>{if(Ft.tag==="Nothing")return 0;if(Ft.tag==="Just")return Ft._1;_()})()+(()=>{if(vt.tag==="Nothing")return 0;if(vt.tag==="Just")return vt._1;_()})()-((()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;_()})()+(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;_()})()+m([][Vt])+x(Nt,[][Vt]))})()):ft})(O)(ya(u)(H)),gt=et>0?-et:0,Lt={...F,x:et>0?f(H,gt,F.x):F.x,trace:[...F.trace,{...ot,avail:et,shift:gt}]};return et>0?Lt:{...Lt,stack:[...Lt.stack,B]}}if(O<0&&-O<1e300){const et=b(ft=>Nt=>{const kt=_t(Nt)(p),jt=(()=>{if(kt.tag==="Nothing")return-1;if(kt.tag==="Just")return kt._1;_()})();if(jt>=0&&jt<n.length){const Ft=n[jt],vt=_t(Nt)(e.nodeIndex),mt=(()=>{if(vt.tag==="Nothing")return 0;if(vt.tag==="Just")return vt._1+1|0;_()})();return mt>=0&&mt<Ft.length?Wn(ft)((()=>{const lt=_t(Ft[mt])(F.x),xt=_t(Ft[mt])(s),Dt=_t(Nt)(F.x),ht=_t(Nt)(s);return(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;_()})()+(()=>{if(xt.tag==="Nothing")return 0;if(xt.tag==="Just")return xt._1;_()})()-((()=>{if(Dt.tag==="Nothing")return 0;if(Dt.tag==="Just")return Dt._1;_()})()+(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;_()})()+m(Nt)+x(Nt,Ft[mt]))})()):ft}const Tt=_t(Nt)(e.nodeIndex),Vt=(()=>{if(Tt.tag==="Nothing")return 0;if(Tt.tag==="Just")return Tt._1+1|0;_()})();return Vt>=0&&Vt<0?Wn(ft)((()=>{const Ft=_t([][Vt])(F.x),vt=_t([][Vt])(s),mt=_t(Nt)(F.x),lt=_t(Nt)(s);return(()=>{if(Ft.tag==="Nothing")return 0;if(Ft.tag==="Just")return Ft._1;_()})()+(()=>{if(vt.tag==="Nothing")return 0;if(vt.tag==="Just")return vt._1;_()})()-((()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;_()})()+(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;_()})()+m(Nt)+x(Nt,[][Vt]))})()):ft})(-O)(ya(u)(H)),gt=et>0?et:0,Lt={...F,x:et>0?f(H,gt,F.x):F.x,trace:[...F.trace,{...ot,avail:et,shift:gt}]};return et>0?Lt:{...Lt,stack:[...Lt.stack,B]}}return{...F,stack:[...F.stack,B],trace:[...F.trace,ot],x:F.x}}_()},Y=b(Q(Gv))({x:Er(U(D=>L(D,(()=>{const F=_t(D)(u.root),B=(()=>{if(F.tag==="Nothing")return D;if(F.tag==="Just")return F._1;_()})(),z=_t(B)(E.x),j=_t((()=>{const O=_t(B)(E.sink);if(O.tag==="Nothing")return B;if(O.tag==="Just")return O._1;_()})())(G),W=(()=>{if(z.tag==="Just")return z._1;if(z.tag==="Nothing")return w;_()})();return(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;_()})()+(()=>{if(j.tag==="Nothing")return 0;if(j.tag==="Just")return j._1;_()})()})()))(v)),su:E.su,stack:[],trace:[]})(E.queue),X=b(Q(Dv))({...Y,stack:[]})(re(Y.stack));return{x:X.x,queue:E.queue,trace:X.trace}},Mv=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>g=>Bv(t)(e)(n)(r)(o)(i)(a)(s)(u)(c)(g).x,zv=t=>e=>n=>r=>o=>i=>{const a=(u,c,g)=>{const l=_t(c)(n),d=(()=>{if(l.tag==="Nothing")return .5;if(l.tag==="Just")return l._1._1/2;_()})(),f=u.from.node===c?u.from.port:u.to.node===c?u.to.port:w;if(f.tag==="Just"){const h=_t(c)(e);if(h.tag==="Just"){const m=Kt(p=>p.id===f._1)(h._1);if(m.tag==="Just"){const p=rt(m._1.offset)*rt(4);return g==="North"||g==="South"?p:0}if(m.tag==="Nothing"){const p=Fi(o)(u.id)(g)(d);return g==="North"||g==="South"?p:0}_()}if(h.tag==="Nothing"){const m=Fi(o)(u.id)(g)(d);return g==="North"||g==="South"?m:0}_()}if(f.tag==="Nothing"){const h=Fi(o)(u.id)(g)(d);return g==="North"||g==="South"?h:0}_()},s=u=>c=>g=>l=>{let d=u,f=c,h=g,m=l,p=!0,x;for(;p;){const y=d,N=f,v=h,J=At(k=>w,k=>S=>T("Just",{head:k,tail:S}),m);if(J.tag==="Nothing"){p=!1,x=y;continue}if(J.tag==="Just"){const k=J._1.head,S=Kt(I=>I.from.node===v&&I.to.node===k||I.from.node===k&&I.to.node===v)(r),A=(()=>{if(S.tag==="Nothing")return N+0;if(S.tag==="Just")return N+(a(S._1,v,S._1.from.node===v?Ge:Re)-a(S._1,k,S._1.from.node===k?Ge:Re));_()})();d=it(P)(k)(A)(y),f=A,h=k,m=J._1.tail;continue}_()}return x};return b(u=>c=>{const g=At(f=>w,f=>h=>T("Just",{head:f,tail:h}),ya(t)(c)),l=(()=>{if(g.tag==="Nothing")return it(P)(c)(0)(M);if(g.tag==="Just")return s(it(P)(g._1.head)(0)(M))(0)(g._1.head)(g._1.tail);_()})(),d=b(f=>h=>Sr(f)(-h._2))(0)(Ag(l));return b(f=>h=>it(P)(h._1)(h._2+d)(f))(u)(Ag(l))})(M)(wi(P.compare)((()=>{const u=(c,g)=>{if(c.tag==="Leaf")return g;if(c.tag==="Node")return u(c._5,yt("Cons",c._4,u(c._6,g)));_()};return Wt(ue.foldr,u(t.root,R))})()))},Qv=t=>e=>{const n=(o,i,a)=>De(3)(i)==="$d:"&&pc(zl,(()=>{const s=_t(i)(t.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;_()})()),r=o=>i=>a=>s=>u=>c=>g=>{let l=o,d=i,f=s,h=c,m=g,p=!0,x;for(;p;){const y=l,N=d,v=f,J=h,k=m,S=N.length;if(k>=S){p=!1,x=y;continue}const A=k>=0&&k<N.length?T("Just",N[k]):w,I=(()=>{if(A.tag==="Nothing")return"";if(A.tag==="Just")return A._1;_()})(),$=n(t,I);if(k===(S-1|0)||$){const E=(()=>{if($){const G=_t(I)(t.preds),nt=(()=>{if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;_()})();if(0<nt.length){const V=v-1|0,Q=_t(nt[0])(t.nodeIndex);if(Q.tag==="Nothing")return V;if(Q.tag==="Just")return Q._1;_()}}return v-1|0})();l=b(G=>nt=>{if(nt>=0&&nt<N.length){const V=N[nt];return n(t,V)?G:b(Q=>Y=>{const X=_t(Y)(t.nodeIndex),D=(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;_()})();return D<J||D>E?it(P)(Y+"\u2192"+V)()(Q):Q})(G)((()=>{const Q=_t(V)(t.preds);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;_()})())}return n(t,"")?G:b(V=>Q=>{const Y=_t(Q)(t.nodeIndex),X=(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;_()})();return X<J||X>E?it(P)(Q+"\u2192")()(V):V})(G)((()=>{const V=_t("")(t.preds);if(V.tag==="Nothing")return[];if(V.tag==="Just")return V._1;_()})())})(y)(Yt(0,k)),d=N,f=v,h=E,m=k+1|0;continue}l=y,d=N,f=v,h=J,m=k+1|0}return x};return e.length<3?M:b(o=>i=>{if(i>=0&&i<e.length){const a=e[i];return r(o)((()=>{const s=i+1|0;return s>=0&&s<e.length?e[s]:[]})())(a)(a.length)(i)(0)(0)}return r(o)((()=>{const a=i+1|0;return a>=0&&a<e.length?e[a]:[]})())([])(0)(i)(0)(0)})(M)(Yt(1,e.length-2|0))},Wv=t=>e=>n=>r=>o=>{const i=bn(e),a=b(s=>u=>{const c=b(g=>l=>{const d=(()=>{if(o==="HRight"){const p=_t(l)(t.preds);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;_()}if(o==="HLeft"){const p=_t(l)(t.succs);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1}_()})(),f=d.length;if(f===0)return g;const h=Nr(f-1|0,2),m=Nr(f,2);return b(p=>x=>{if((()=>{const y=_t(l)(p.align);if(y.tag==="Nothing")return l!==l;if(y.tag==="Just")return y._1!==l;_()})())return p;if(x>=0&&x<d.length){const y=_t(d[x])(t.nodeIndex),N=(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;_()})();if(!(id(d[x]+"\u2192"+l)(n)||id(l+"\u2192"+d[x])(n))&&(()=>{if(r==="VDown")return p.r<N;if(r==="VUp")return p.r>N;_()})()){const v=_t(d[x])(p.root),J=(()=>{if(v.tag==="Nothing")return d[x];if(v.tag==="Just")return v._1;_()})();return{root:it(P)(l)(J)(p.root),align:it(P)(d[x])(l)(it(P)(l)(J)(p.align)),r:N}}}return p})(g)((()=>{if(r==="VDown")return Yt(h,m);if(r==="VUp")return re(Yt(h,m));_()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;_()})()})((()=>{if(r==="VDown")return u;if(r==="VUp")return re(u);_()})());return{root:c.root,align:c.align}})({root:Er(U(s=>L(s,s))(i)),align:Er(U(s=>L(s,s))(i))})((()=>{if(o==="HRight")return e;if(o==="HLeft")return re(e);_()})());return{root:a.root,align:a.align}},js=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>{const g=Wv(e)(n)(s)(u)(c),l=zv(g)(o)(r)(i)(a)(c);return X2()(d=>f=>T("Just",(()=>{const h=_t(d)(l);if(h.tag==="Nothing")return f+0;if(h.tag==="Just")return f+h._1;_()})()))(Mv(t)(e)(n)(r)(o)(i)(a)(l)(g)(u)(c))},sd=t=>e=>Ot(n=>r=>b(o=>i=>i>=0&&i<e.length?i>=0&&i<t.length?o+e[i]+t[i]:o+e[i]+0:i>=0&&i<t.length?o+1+t[i]:o+1)(0)((()=>{const o=Yt(0,e.length-1|0);return n<1?[]:Rt(0,n,o)})()))(e),Ov=t=>e=>n=>r=>o=>i=>a=>{const s=Pv(0)(e.length-1|0),u=rt(t.layerGap),c=a(Ao(s,u)),g=Jv(Vl(o)(c)(r)(i)(M))(c);return U(l=>{const d=Rv(l)(g);return d.tag==="Just"&&d._1>0?Sr(u)(2+rt(d._1-1|0)*2.5):u})(Yt(0,s-1|0))},ud=t=>e=>n=>r=>pc(o=>b(i=>a=>{if(!i.ok)return i;const s=_t(a)(r),u=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;_()})(),c=_t(a)(n),g=(()=>{if(c.tag==="Nothing")return u+1;if(c.tag==="Just")return u+c._1._1;_()})();return u+1e-4>i.pos&&g+1e-4>i.pos?{ok:!0,pos:g}:{ok:!1,pos:i.pos}})({ok:!0,pos:-1e18})(o).ok,e),Hv=t=>e=>n=>r=>{const o=Gt(i=>a=>at.compare(i.w)(a.w))(U(i=>({l:i,w:ad(i)}))(dt(ud()(e)(n),r)));return 0<o.length?T("Just",o[0].l):w},$v=t=>e=>{const n=Er(bn(U(Ot(o=>i=>L(i,o)))(t))),r=o=>Gt(i=>a=>ut.compare((()=>{const s=_t(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;_()})())((()=>{const s=_t(a)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;_()})()))(o);return{preds:(()=>{const o=i=>{if(i.tag==="Leaf")return M;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));_()};return o(b(i=>a=>zt(P)(ye)(a.to.node)([a.from.node])(i))(M)(e))})(),succs:(()=>{const o=i=>{if(i.tag==="Leaf")return M;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));_()};return o(b(i=>a=>zt(P)(ye)(a.from.node)([a.to.node])(i))(M)(e))})(),nodeIndex:n}},qv=t=>e=>{const n=Gt(l=>d=>at.compare(l.w)(d.w))(Ot(l=>d=>({i:l,l:d,w:ad(d)}))(e)),r=0<n.length?T("Just",n[0]):w,o=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;_()})(),i=o>=0&&o<e.length?T("Just",e[o]):w,a=(()=>{if(i.tag==="Just")return(l=>d=>{let f=l,h=d,m=!0,p;for(;m;){const x=f,y=h;if(y.tag==="Nil"){m=!1,p=x;continue}if(y.tag==="Cons"){f=Wn(x)(y._1),h=y._2;continue}_()}return p})(999999)((()=>{const l=(d,f)=>{if(d.tag==="Leaf")return f;if(d.tag==="Node")return l(d._5,yt("Cons",d._4,l(d._6,f)));_()};return l(i._1,R)})());if(i.tag==="Nothing")return 0;_()})(),s=l=>b(d=>f=>Sr(d)((()=>{const h=_t(f._1)(t);if(h.tag==="Nothing")return f._2+1;if(h.tag==="Just")return f._2+h._1._1;_()})()))(-999999)(Ag(l)),u=o>=0&&o<e.length?T("Just",e[o]):w,c=(()=>{if(u.tag==="Just")return s(u._1);if(u.tag==="Nothing")return 0;_()})(),g=$e(l=>d=>{const f=h=>{if(h.tag==="Leaf")return M;if(h.tag==="Node")return ee("Node",h._1,h._2,h._3,h._4+d,f(h._5),f(h._6));_()};return f(l)},e,Ot(l=>d=>co(l)(2)===0?a-(f=>h=>{let m=f,p=h,x=!0,y;for(;x;){const N=m,v=p;if(v.tag==="Nil"){x=!1,y=N;continue}if(v.tag==="Cons"){m=Wn(N)(v._1),p=v._2;continue}_()}return y})(999999)((()=>{const f=(h,m)=>{if(h.tag==="Leaf")return m;if(h.tag==="Node")return f(h._5,yt("Cons",h._4,f(h._6,m)));_()};return f(d,R)})()):c-s(d))(e));return Iv(b(l=>d=>{const f=Gt(at.compare)(wt(_t(d))(g));return it(P)(d)(f.length===4?1<f.length&&2<f.length?(f[1]+f[2])/2:0:0<f.length?f[0]:0)(l)})(M)(wi(P.compare)(bn(U(l=>{const d=f=>{if(f.tag==="Leaf")return M;if(f.tag==="Node")return ee("Node",f._1,f._2,f._3,void 0,d(f._5),d(f._6));_()};return Wt(ln.foldr,d(l))})(g)))))},Uv=t=>e=>n=>r=>o=>i=>{const a=$v(e)(o),s=Qv(a)(e),u={nodeGap:t.nodeGap*4|0},c=Qe(P.compare,Be,Er(U(f=>L(f,L(1,1)))(dt(zl,bn(e)))),(()=>{const f=h=>{if(h.tag==="Leaf")return M;if(h.tag==="Node")return ee("Node",h._1,h._2,h._3,L(h._4._1*rt(4),h._4._2),f(h._5),f(h._6));_()};return f(n)})()),g=[js(u)(a)(e)(c)(r)(o)(i)(s)(ed)(rd),js(u)(a)(e)(c)(r)(o)(i)(s)(nd)(rd),js(u)(a)(e)(c)(r)(o)(i)(s)(ed)(od),js(u)(a)(e)(c)(r)(o)(i)(s)(nd)(od)],l=qv(c)(g);if(ud()(e)(c)(l))return l;const d=Hv()(e)(c)(g);if(d.tag==="Just")return d._1;if(d.tag==="Nothing")return g[0];_()},Xv=t=>e=>n=>r=>{const o=Ef(w,bf,i=>i.node===e?T("Just",i.position):w,t);if(o.tag==="Nothing")return t;if(o.tag==="Just"){const i=o._1;return U(a=>a.node===n?{...a,position:L(i._1+r._1,i._2+r._2)}:a)(t)}_()},Vv=t=>e=>n=>r=>{const o=dt(a=>_n(Tr)(a.node)(e),t),i=(()=>{if(n==="Vertical"){if(r==="Start")return b(a=>s=>Wn(a)(s.position._1))(99999)(o);if(r==="End")return b(a=>s=>Sr(a)(s.position._1))(0)(o);if(r==="Center"){const a=b(s=>u=>s+u.position._1)(0)(o);return o.length===0?0:a/rt(o.length)}_()}if(n==="Horizontal"){if(r==="Start")return b(a=>s=>Wn(a)(s.position._2))(99999)(o);if(r==="End")return b(a=>s=>Sr(a)(s.position._2))(0)(o);if(r==="Center"){const a=b(s=>u=>s+u.position._2)(0)(o);return o.length===0?0:a/rt(o.length)}}_()})();return U(a=>{if(_n(Tr)(a.node)(e)){if(n==="Vertical")return{...a,position:L(i,a.position._2)};if(n==="Horizontal")return{...a,position:L(a.position._1,i)};_()}return a})(t)},Yv=t=>e=>b(n=>r=>r.tag==="AlignGroup"?Vv(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?Xv(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),Kv=t=>e=>n=>r=>o=>i=>a=>s=>{const u=U(l=>b(d=>f=>Sr(d)((()=>{const h=_t(f)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;_()})()))(1)(l))(n),c=Uv(t)(n)(r)(o)(i)(s),g=sd(Ov(t)(n)(r)(o)(i)(a)(l=>{const d=sd(l)(u);return bn(Ot(f=>h=>Ot(m=>p=>({node:p,position:L((()=>{const x=_t(p)(c);return(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;_()})()/rt(4)})(),f>=0&&f<d.length?d[f]:0),size:(()=>{const x=De(3)(p)==="$d:"?L(0,1):L(1,1),y=_t(p)(r);if(y.tag==="Nothing")return x;if(y.tag==="Just")return y._1;_()})(),layer:f,order:m}))(h))(n))}))(u);return Yv(e)(bn(Ot(l=>d=>Ot(f=>h=>({node:h,position:L((()=>{const m=_t(h)(c);return(()=>{if(m.tag==="Nothing")return 0;if(m.tag==="Just")return m._1;_()})()/rt(4)})(),l>=0&&l<g.length?g[l]:0),size:(()=>{const m=De(3)(h)==="$d:"?L(0,1):L(1,1),p=_t(h)(r);if(p.tag==="Nothing")return m;if(p.tag==="Just")return p._1;_()})(),layer:l,order:f}))(d))(n)))},Pg=Fc(ps)(Fo(32)),cd=Fc(ps)(Fo(31)),xa=(()=>{const t=Iy("25214903917");if(t.tag==="Nothing")return t1;if(t.tag==="Just")return t._1;_()})(),wa=Dc(Fc(ps)(Fo(48)))(ps),jv=t=>{const e=By(t);return sa(e1((()=>{if(e.tag==="Nothing")return t1;if(e.tag==="Just")return e._1;_()})())(xa))(wa)},Rg=Fo(11),Zs=t=>e=>{const n=sa(ds(hs(e)(xa))(Rg))(wa);return L((()=>{const r=Gf(Ry(Ic(n)(Fo(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;_()})(),n)},Zv=t=>{const e=Zs(26)(t),n=Zs(27)(e._2);return L((rt(e._1)*mc(2)(27)+rt(n._1))/mc(2)(53),n._2)},tb=t=>e=>{const n=b(r=>o=>{const i=Zv(r.finalR);return{rs:[...r.rs,i._1],finalR:i._2}})({rs:[],finalR:t})(e);return L(U(r=>r.x)(Gt(r=>o=>at.compare(r.k)(o.k))($e(r=>o=>({x:r,k:o}),e,n.rs))),n.finalR)},eb=t=>{const e=sa(ds(hs(t)(xa))(Rg))(wa),n=sa(ds(hs(e)(xa))(Rg))(wa);return L(ds(hs((()=>{const r=Ic(e)(Fo(16));return n1.compare(r)(cd)!=="LT"?Dc(r)(Pg):r})())(Pg))((()=>{const r=Ic(n)(Fo(16));return n1.compare(r)(cd)!=="LT"?Dc(r)(Pg):r})()),n)},Na=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},tu=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},Gg=ge(P)(Mt),Ii=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},eu=ge(P)(Mt),nb=is(xi),rb=b(ur)(0),ob=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},gd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},ib=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const o=uo(Ut,w,t,n[e],n);if(o.tag==="Just")return uo(Ut,w,e,r,o._1);if(o.tag==="Nothing")return w;_()}}return w},ab=t=>e=>n=>r=>o=>Gg(b(i=>a=>{const s=Gt(u=>c=>ut.compare((()=>{const g=Na(u.id)(o);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;_()})())((()=>{const g=Na(c.id)(o);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;_()})()))(dt(u=>tu(u.to.node)(n),dt(u=>u.from.node===a,r)));return{ranks:[...i.ranks,...Ot(u=>c=>L(c.id,rt((i.rankSum+u|0)+1|0)))(s)],rankSum:i.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),sb=t=>e=>n=>r=>o=>Gg(b(i=>a=>{const s=Gt(c=>g=>{const l=ut.compare((()=>{const d=Ii(g.from.node)(n);if(d.tag==="Nothing")return-1;if(d.tag==="Just")return d._1;_()})())((()=>{const d=Ii(c.from.node)(n);if(d.tag==="Nothing")return-1;if(d.tag==="Just")return d._1;_()})());return l==="EQ"?ut.compare((()=>{const d=Na(c.id)(o);if(d.tag==="Nothing")return 1e6;if(d.tag==="Just")return d._1;_()})())((()=>{const d=Na(g.id)(o);if(d.tag==="Nothing")return 1e6;if(d.tag==="Just")return d._1;_()})()):l})(dt(c=>tu(c.from.node)(n),dt(c=>c.to.node===a,r))),u=s.length;return{ranks:[...i.ranks,...Ot(c=>g=>L(g.id,rt((i.rankSum+u|0)-c|0)))(s)],rankSum:i.rankSum+u|0}})({ranks:[],rankSum:0})(t).ranks),Dg=t=>e=>n=>{const r=eu(Ot(s=>u=>L(u,s))(t)),o=eu(Ot(s=>u=>L(u,s))(e)),i=wt(s=>{const u=Ii(s.from.node)(r),c=Ii(s.to.node)(o);if(u.tag==="Just"&&c.tag==="Just")return T("Just",L(u._1,c._1));const g=Ii(s.from.node)(o),l=Ii(s.to.node)(r);return g.tag==="Just"&&l.tag==="Just"?T("Just",L(l._1,g._1)):w})(n),a=i.length;return b(s=>u=>b(c=>g=>u>=0&&u<i.length&&g>=0&&g<i.length&&((i[u]._1-i[g]._1|0)*(i[u]._2-i[g]._2|0)|0)<0?c+1|0:c)(s)(Yt(u+1|0,a-1|0)))(0)(Yt(0,a-2|0))},ub=t=>e=>n=>r=>{const o=i=>a=>{let s=i,u=a,c=!0,g;for(;c;){const l=s,d=u;if(d>=(l.length-1|0)){c=!1,g=l;continue}if(d>=0&&d<l.length){const f=d+1|0;if(f>=0&&f<l.length){const h=l[d],m=l[f];if(ne(N=>N.before===h&&N.after===m,r)){s=l,u=d+1|0;continue}const p=uo(Ut,w,d,m,l),x=(()=>{if(p.tag==="Just")return uo(Ut,w,d+1|0,h,p._1);if(p.tag==="Nothing")return w;_()})(),y=(()=>{if(x.tag==="Nothing")return l;if(x.tag==="Just")return x._1;_()})();if(Dg(e)(y)(n)<Dg(e)(l)(n)){s=y,u=d+1|0;continue}s=l,u=d+1|0;continue}c=!1,g=l;continue}c=!1,g=l}return g};return(i=>{let a=i,s=!0,u;for(;s;){const c=a,g=o(c)(0);if(nb(g)(c)){s=!1,u=c;continue}a=g}return u})(t)},nu=t=>e=>b(n=>r=>{if(r>=0&&r<t.length){const o=t[r],i=r+1|0;if(i>=0&&i<t.length)return n+Dg(o)(t[i])(e)|0}return n})(0)(Yt(0,t.length-2|0)),cb=(()=>{const t=e=>{if(e.length<7){const i=a=>s=>{let u=a,c=s,g=!0,l;for(;g;){const d=u,f=c,h=f-1|0;if(h>=0&&h<d.length){if(f>=0&&f<d.length&&f>0&&d[h].key>d[f].key){const m=ib(f-1|0)(f)(d);if(m.tag==="Just"){u=m._1,c=f-1|0;continue}if(m.tag==="Nothing"){g=!1,l=d;continue}_()}g=!1,l=d;continue}g=!1,l=d}return l};return b(a=>s=>i(a)(s))(e)(Yt(1,e.length-1|0))}const n=Nr(e.length,2),r=t(Rt(0,n,e)),o=t(Rt(n,e.length,e));return(i=>a=>s=>{let u=i,c=a,g=s,l=!0,d;for(;l;){const f=u,h=c,m=g;if(h>=0&&h<r.length){if(m>=0&&m<o.length){if(r[h].key>o[m].key){u=St(f)(o[m]),c=h,g=m+1|0;continue}u=St(f)(r[h]),c=h+1|0,g=m;continue}l=!1,d=[...f,...h<1?r:Rt(h,r.length,r)];continue}l=!1,d=[...f,...m<1?o:Rt(m,o.length,o)]}return d})([])(0)(0)};return t})(),gb=t=>e=>n=>{const r=wt(c=>c.tag==="OrderConstraint"?T("Just",{before:c._1.before,after:c._1.after}):w)(t.constraints),o=c=>b(g=>l=>{const d=l.after,f=l.before,h=Mr(Ut,w,p=>p===f,g),m=Mr(Ut,w,p=>p===d,g);if(h.tag==="Just"&&m.tag==="Just"&&h._1>m._1){const p=Pf(Ut,w,h._1,g),x=(()=>{if(p.tag==="Nothing")return g;if(p.tag==="Just")return p._1;_()})(),y=Af(Ut,w,m._1,f,x);if(y.tag==="Nothing")return x;if(y.tag==="Just")return y._1;_()}return g})(c)(r),i=Gg(Ot(c=>g=>L(g.id,c))(n)),a=(c,g,l)=>{const d=c.length;return b(f=>h=>{const m=g?h-1|0:h+1|0,p=m>=0&&m<f._1.length?T("Just",f._1[m]):w;if(p.tag==="Just"){const x=h>=0&&h<f._1.length?T("Just",f._1[h]):w;if(x.tag==="Just"){const y=eu(Ot(S=>A=>L(A,S))(p._1)),N=eu(Ot(S=>A=>L(A,S))(x._1)),v=g?ab(p._1)(y)(N)(n)(i):sb(p._1)(y)(N)(n)(i),J=b(S=>A=>{const I=wt(E=>Na(E.id)(v))(dt(g?E=>E.to.node===A._2&&tu(E.from.node)(y):E=>E.from.node===A._2&&tu(E.to.node)(y),n));if(I.length===0)return{...S,items:[...S.items,{n:A._2,key:w,origIdx:A._1}]};const $=Zs(24)(S.r);return{items:[...S.items,{n:A._2,key:T("Just",(rb(I)+(rt($._1)*4172325152040912e-24-.03500000014901161))/rt(I.length)),origIdx:A._1}],r:$._2}})({items:[],r:f._2})(Ot(vn)(x._1)),k=uo(Ut,w,h,ub(o(U(S=>S.n)(cb((()=>{const S=J.items,A=I=>$=>{let E=I,G=$,nt=!0,V;for(;nt;){const Q=E,Y=G;if(Q>=0&&Q<S.length){if(S[Q].key.tag==="Just"){nt=!1,V=S[Q].key._1;continue}if(S[Q].key.tag==="Nothing"){E=Q+1|0,G=Y;continue}_()}nt=!1,V=Y}return V};return(I=>$=>E=>{let G=I,nt=$,V=E,Q=!0,Y;for(;Q;){const X=G,D=nt,F=V;if(X>=0&&X<S.length){if(S[X].key.tag==="Just"){G=X+1|0,nt=S[X].key._1,V=[...F,{n:S[X].n,key:S[X].key._1,origIdx:S[X].origIdx}];continue}if(S[X].key.tag==="Nothing"){const B=(D+A(X+1|0)(D+1))/2;G=X+1|0,nt=B,V=[...F,{n:S[X].n,key:B,origIdx:S[X].origIdx}];continue}_()}Q=!1,Y=F}return Y})(0)(-1)([])})()))))(p._1)(n)(r),f._1);if(k.tag==="Just")return L(k._1,J.r);if(k.tag==="Nothing")return L(f._1,f._2);_()}if(x.tag==="Nothing")return L(f._1,f._2);_()}if(p.tag==="Nothing")return L(f._1,f._2);_()})(L(c,l))(g?Yt(1,d-1|0):re(Yt(0,d-2|0)))},s=b(c=>g=>it(P)(g.from.node)()(it(P)(g.to.node)()(c)))(M)(n),u=b(c=>g=>{if(c.result.crossings===0)return c;const l=y=>N=>v=>J=>{let k=y,S=N,A=v,I=J,$=!0,E;for(;$;){const G=k,nt=S,V=A,Q=I;if(V===0){$=!1,E={layout:G,crossings:0,random:Q};continue}const Y=a(G,nt,Q),X=nu(Y._1)(n);if(X<V){k=Y._1,S=!nt,A=X,I=Y._2;continue}$=!1,E={layout:G,crossings:V,random:Y._2}}return E},d=Zs(1)(c.result.random),f=d._1!==0,h=t.modelOrder.tag==="Leaf",m=(c.firstTry||c.secondTry)&&!h?c.firstTry:f,p=(()=>{if(!h){const J=a(e,m,d._2);return l(J._1)(!m)(nu(J._1)(n))(J._2)}const y=m?0:ob(0)(e.length-1|0),N=y>=0&&y<e.length?T("Just",e[y]):w;if(N.tag==="Just"&&N._1.length>1){const J=dt(k=>gd(k)(s),N._1);if(J.length>1){const k=tb(d._2)(J),S=k._1,A=uo(Ut,w,y,o(b(I=>$=>gd($)(s)?I.idx>=0&&I.idx<S.length?{idx:I.idx+1|0,result:[...I.result,S[I.idx]]}:{idx:I.idx,result:[...I.result,$]}:{idx:I.idx,result:[...I.result,$]})({idx:0,result:[]})(N._1).result),e);if(A.tag==="Just"){const I=a(A._1,m,k._2);return l(I._1)(!m)(nu(I._1)(n))(I._2)}}}const v=a(e,m,d._2);return l(v._1)(!m)(nu(v._1)(n))(v._2)})(),x=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:x}})({result:{layout:e,crossings:1e9,random:sa(e1(eb(jv(1))._1)(xa))(wa)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Yt(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:u.layout},_b=t=>t,_d=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},dn=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Bi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},Ta=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=P.compare(e._1)(n._1);return r==="LT"?Me:r==="GT"?ze:P.compare(e._2)(n._2)},Eq0:()=>t}})(),fb=ge(P)(Mt),lb=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=Ta.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},db=_b("Greedy"),Fg=t=>e=>n=>b(r=>o=>{if(o.from.node===o.to.node)return r;if(o.from.node===e&&!_d(o.to.node)(r.marks)){const i=dn(o.to.node)(r.inDeg),a=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;_()})(),s=it(P)(o.to.node)(a)(r.inDeg);return(()=>{const u=dn(o.to.node)(r.outDeg);return a<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;_()})()&&!_n(Tr)(o.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,o.to.node]}:{...r,inDeg:s}}if(o.to.node===e&&!_d(o.from.node)(r.marks)){const i=dn(o.from.node)(r.outDeg),a=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;_()})(),s=it(P)(o.from.node)(a)(r.outDeg);return(()=>{const u=dn(o.from.node)(r.inDeg);return a<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;_()})()&&!_n(Tr)(o.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,o.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:dt(r=>r!==e,n.remaining)})(t),hb=b(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return it(P)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return it(P)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return it(P)(e._1.node)(99999)(t)}return t})(M),fd=t=>e=>n=>{const r=dn(e)(t),o=dn(n)(t);return r.tag==="Just"&&o.tag==="Just"&&r._1>o._1},ld=t=>e=>n=>r=>{if(Bi(n)(r.visited)||Bi(n)(r.visiting))return r;const o=b(pb(t)(e)(n))({...r,visiting:it(P)(n)()(r.visiting)})((()=>{const i=dn(n)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;_()})());return{...o,visiting:bi(P)(n)(o.visiting),visited:it(P)(n)()(o.visited)}},pb=t=>e=>n=>r=>o=>fd(t)(n)(o)?{...r,backEdges:it(Ta)(L(n,o))()(r.backEdges)}:Bi(o)(r.visiting)?{...r,backEdges:it(Ta)(L(n,o))()(r.backEdges)}:Bi(o)(r.visited)?r:ld(t)(e)(o)(r),mb=t=>e=>n=>{const r=d=>{let f=d,h=!0,m;for(;h;){const p=f,x=At(y=>w,y=>N=>T("Just",{head:y,tail:N}),p.sinks);if(x.tag==="Just"){f=Fg(n)(x._1.head)({...p,sinks:x._1.tail,marks:it(P)(x._1.head)(p.nextRight)(p.marks),nextRight:p.nextRight-1|0});continue}if(x.tag==="Nothing"){const y=At(N=>w,N=>v=>T("Just",{head:N,tail:v}),p.sources);if(y.tag==="Just"){f=Fg(n)(y._1.head)({...p,sources:y._1.tail,marks:it(P)(y._1.head)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}if(y.tag==="Nothing"){const N=J=>{const k=dn(J)(p.outDeg),S=dn(J)(p.inDeg);return(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;_()})()-(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;_()})()|0},v=Gt(J=>k=>{const S=ut.compare(N(k))(N(J));return S==="EQ"?ut.compare((()=>{const A=dn(J)(e);if(A.tag==="Nothing")return 1e6;if(A.tag==="Just")return A._1;_()})())((()=>{const A=dn(k)(e);if(A.tag==="Nothing")return 1e6;if(A.tag==="Just")return A._1;_()})()):S})(p.remaining);if(0<v.length){const J=v[0];f=Fg(n)(J)({...p,remaining:dt(k=>k!==J,p.remaining),marks:it(P)(J)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}h=!1,m=p;continue}}_()}return m},o=wi(P.compare)([...U(d=>d.from.node)(n),...U(d=>d.to.node)(n)]),i=dt(d=>d.from.node!==d.to.node,n),a=b(d=>f=>zt(P)(ve)(f.to.node)(1)(d))(M)(i),s=b(d=>f=>zt(P)(ve)(f.from.node)(1)(d))(M)(i),u=dt(d=>{const f=dn(d)(a);if(f.tag==="Nothing")return!0;if(f.tag==="Just")return f._1===0;_()},o),c=dt(d=>{const f=dn(d)(s);if(f.tag==="Nothing")return!0;if(f.tag==="Just")return f._1===0;_()},o),g=o.length+1|0,l=b(d=>f=>{const h=dn(f)(d);return h.tag==="Just"&&h._1<0?it(P)(f)(h._1+g|0)(d):d})(r({remaining:dt(d=>!_n(Tr)(d)(u)&&!_n(Tr)(d)(c),o),marks:M,inDeg:a,outDeg:s,sources:u,sinks:c,nextLeft:1,nextRight:-1}).marks)(o);return b(d=>f=>{if(f.from.node===f.to.node)return d;if(fd(t)(f.from.node)(f.to.node))return it(Ta)(L(f.from.node,f.to.node))()(d);const h=dn(f.from.node)(l),m=dn(f.to.node)(l);return h.tag==="Just"&&m.tag==="Just"&&h._1>m._1?it(Ta)(L(f.from.node,f.to.node))()(d):d})(M)(n)},yb=b(t=>e=>zt(P)(ye)(e.from.node)([e.to.node])(t))(M),xb=t=>e=>{const n=yb(e),r=wi(P.compare)([...U(i=>i.from.node)(e),...U(i=>i.to.node)(e)]),o=b(i=>a=>it(P)(a.to.node)()(i))(M)(e);return b(i=>a=>ld(t)(n)(a)(i))({visiting:M,visited:M,backEdges:M})([...dt(i=>!Bi(i)(o),r),...dt(i=>Bi(i)(o),r)]).backEdges},wb=t=>e=>n=>r=>{const o=fb(Ot(s=>u=>L(u,s))(e)),i=hb(n),a=(()=>{if(t==="DepthFirst")return xb(i)(r);if(t==="Greedy")return mb(i)(o)(r);_()})();return{edges:U(s=>lb(L(s.from.node,s.to.node))(a)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:a}},dd=Mt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),Ee=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},Ae=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},va=t=>e=>n=>r=>dd(o=>n>=o.x&&n<o.x+o.w&&e>o.y&&t<o.y+o.h)(r),ru=t=>e=>n=>r=>va(Ee(e)(n))(Ae(e)(n))(r)(t),ou=rt(4),Nb=as(t=>{if(t.direction==="H"){const e=Ee(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:Ae(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=Ee(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:Ae(t.start._2)(t.end._2)-e}]}_()}),ba=na(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})())}),Tb=t=>e=>n=>{const r=At(o=>w,o=>i=>T("Just",{head:o,tail:i}),e);if(r.tag==="Nothing")return[{start:t.start,end:n.end,direction:t.direction}];if(r.tag==="Just"){const o=(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],i=zr(r._1.tail);if(i.tag==="Nothing"){const a=o.length-1|0;return a>=0&&a<o.length&&(o[a].direction==="H"?n.direction==="H":o[a].direction==="V"&&n.direction==="V")?[...(()=>{const s=o.length-1|0;return s<1?[]:Rt(0,s,o)})(),{start:o[a].start,end:n.end,direction:n.direction}]:[...o,n]}if(i.tag==="Just")return(i._1.last.direction==="H"?n.direction==="H":i._1.last.direction==="V"&&n.direction==="V")?[...o,...i._1.init,{start:i._1.last.start,end:n.end,direction:n.direction}]:[...o,...r._1.tail,n]}_()},Ja=t=>{const e=r=>o=>{const i=At(a=>w,a=>s=>T("Just",{head:a,tail:s}),o);if(i.tag==="Nothing")return[r];if(i.tag==="Just")return(r.direction==="H"?i._1.head.direction==="H":r.direction==="V"&&i._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==i._1.head.end._1-i._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==i._1.head.end._2-i._1.head.start._2>=0;_()})()?e({start:r.start,end:i._1.head.end,direction:r.direction})(i._1.tail):[r,...e(i._1.head)(i._1.tail)];_()},n=At(r=>w,r=>o=>T("Just",{head:r,tail:o}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);_()},Ca=t=>e=>n=>r=>dd(o=>n>=o.y&&n<o.y+o.h&&e>o.x&&t<o.x+o.w)(r),ka=t=>e=>n=>r=>Ca(Ee(e)(n))(Ae(e)(n))(r)(t),vb=t=>e=>n=>r=>{const o=n+2|0,i=o<1?e:Rt(o,e.length,e),a=n<1?[]:Rt(0,n,e),s=(n+1|0)===(r-1|0),u=n===0,c=n>=0&&n<e.length?T("Just",e[n]):w;if(c.tag==="Just"){const g=n+1|0,l=g>=0&&g<e.length?T("Just",e[g]):w;if(l.tag==="Just"){const d=c._1.start._1===l._1.end._1&&(!u||c._1.direction==="V")&&(!s||l._1.direction==="V")&&!ru(t)(Ee(c._1.start._2)(l._1.end._2))(Ae(c._1.start._2)(l._1.end._2))(c._1.start._1)?T("Just",[...a,{start:c._1.start,end:l._1.end,direction:me},...i]):w,f=c._1.start._2===l._1.end._2&&(!u||c._1.direction==="H")&&(!s||l._1.direction==="H")&&!ka(t)(Ee(c._1.start._1)(l._1.end._1))(Ae(c._1.start._1)(l._1.end._1))(c._1.start._2)?T("Just",[...a,{start:c._1.start,end:l._1.end,direction:we},...i]):w;return d.tag==="Nothing"?f:d}if(l.tag==="Nothing")return w;_()}if(c.tag==="Nothing")return w;_()},bb=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,a;for(;i;){const s=o;if((s+1|0)>=n){i=!1,a=e;continue}const u=vb(t)(e)(s)(n);if(u.tag==="Just"){i=!1,a=u._1;continue}if(u.tag==="Nothing"){o=s+1|0;continue}_()}return a})(0)},Jb=t=>e=>n=>r=>{const o=(d,f,h)=>!ru(t)(Ee(f)(h))(Ae(f)(h))(d),i=n+3|0,a=i<1?e:Rt(i,e.length,e),s=n<1?[]:Rt(0,n,e),u=(n+2|0)===(r-1|0),c=n===0,g=(d,f,h)=>!ka(t)(Ee(f)(h))(Ae(f)(h))(d),l=n>=0&&n<e.length?T("Just",e[n]):w;if(l.tag==="Just"){const d=n+2|0,f=d>=0&&d<e.length?T("Just",e[d]):w;if(f.tag==="Just"){const h=l._1.start._1===f._1.end._1&&(!c||l._1.direction==="V")&&(!u||f._1.direction==="V")&&o(l._1.start._1,l._1.start._2,f._1.end._2)?T("Just",[...s,{start:l._1.start,end:f._1.end,direction:me},...a]):l._1.start._2===f._1.end._2&&(!c||l._1.direction==="H")&&(!u||f._1.direction==="H")&&g(l._1.start._2,l._1.start._1,f._1.end._1)?T("Just",[...s,{start:l._1.start,end:f._1.end,direction:we},...a]):w,m=(!c||l._1.direction==="V")&&(!u||f._1.direction==="H")&&o(l._1.start._1,l._1.start._2,f._1.end._2)&&g(f._1.end._2,l._1.start._1,f._1.end._1)?T("Just",[...s,{start:l._1.start,end:L(l._1.start._1,f._1.end._2),direction:me},{start:L(l._1.start._1,f._1.end._2),end:f._1.end,direction:we},...a]):w,p=(!c||l._1.direction==="H")&&(!u||f._1.direction==="V")&&g(l._1.start._2,l._1.start._1,f._1.end._1)&&o(f._1.end._1,l._1.start._2,f._1.end._2)?T("Just",[...s,{start:l._1.start,end:L(f._1.end._1,l._1.start._2),direction:we},{start:L(f._1.end._1,l._1.start._2),end:f._1.end,direction:me},...a]):w,x=m.tag==="Nothing"?p:m;return h.tag==="Nothing"?x:h}if(f.tag==="Nothing")return w;_()}if(l.tag==="Nothing")return w;_()},Cb=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,a;for(;i;){const s=o;if((s+2|0)>=n){i=!1,a=e;continue}const u=Jb(t)(e)(s)(n);if(u.tag==="Just"){i=!1,a=u._1;continue}if(u.tag==="Nothing"){o=s+1|0;continue}_()}return a})(0)},kb=t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const a=r,s=Ja(ba(bb(t)(Cb(t)(a))));if(s.length<a.length){r=s;continue}o=!1,i=s}return i};return n=>e(Ja(ba(n)))},Lb=t=>e=>n=>r=>{const o=Ee(n)(r),i=Ae(n)(r),a=dt(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Gt(c=>g=>at.compare(c.x)(g.x))(a);return 0<u.length?u[0].x-1:(n+r)/2}const s=Gt(u=>c=>at.compare(c.x)(u.x))(U(u=>({...u,x:u.x+u.w}))(a));return 0<s.length?s[0].x+1:(n+r)/2},Sb=t=>e=>n=>r=>{const o=Ee(n)(r),i=Ae(n)(r),a=dt(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Gt(c=>g=>at.compare(c.y)(g.y))(a);return 0<u.length?u[0].y-1:(n+r)/2}const s=Gt(u=>c=>at.compare(c.y)(u.y))(U(u=>({...u,y:u.y+u.h}))(a));return 0<s.length?s[0].y+1:(n+r)/2},Eb=t=>e=>n=>r=>{const o=Ee(n)(r),i=Ae(n)(r),a=dt(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Gt(c=>g=>at.compare(g.x)(c.x))(U(c=>({...c,x:c.x+c.w}))(a));return 0<u.length?u[0].x:(n+r)/2}const s=Gt(u=>c=>at.compare(u.x)(c.x))(a);return 0<s.length?s[0].x-1:(n+r)/2},Ab=t=>e=>n=>r=>{const o=Ee(n)(r),i=Ae(n)(r),a=dt(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Gt(c=>g=>at.compare(g.y)(c.y))(U(c=>({...c,y:c.y+c.h}))(a));return 0<u.length?u[0].y:(n+r)/2}const s=Gt(u=>c=>at.compare(u.y)(c.y))(a);return 0<s.length?s[0].y-1:(n+r)/2},hd=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,c=o,g=i;if(g>100){a=!1,s=c;continue}if(!u(c+g)){a=!1,s=c+g;continue}if(!u(c-g)){a=!1,s=c-g;continue}r=u,o=c,i=g+1}return s},pd=t=>e=>n=>r=>o=>{const i=Ee(e)(n),a=Ae(e)(n);if(!va(i)(a)(r)(t))return r;if(!va(i)(a)(o)(t))return o;const s=(r+o)/2;return va(i)(a)(s)(t)?hd(u=>va(i)(a)(u)(t))(s)(1):s},Pb=t=>e=>n=>r=>o=>{const i=Ee(e)(n),a=Ae(e)(n);if(!Ca(i)(a)(r)(t))return r;if(!Ca(i)(a)(o)(t))return o;const s=(r+o)/2;return Ca(i)(a)(s)(t)?hd(u=>Ca(i)(a)(u)(t))(s)(1):s},Rb=t=>e=>n=>r=>{const o=Ee(e)(n),i=Ae(e)(n),a=dt(c=>r>=c.x&&r<c.x+c.w&&c.y+c.h>o&&c.y<i,t),s=b(c=>g=>Ae(c)(g.x+g.w+4))(r+4)(a),u=b(c=>g=>Ee(c)(g.x-4))(r-4)(a);return(()=>{const c=s-r,g=u-r;return(c<0?-c:c)<=(g<0?-g:g)})()?s:u},Gb=t=>e=>n=>r=>{const o=Ee(e)(n),i=Ae(e)(n),a=dt(c=>r>=c.y&&r<c.y+c.h&&c.x+c.w>o&&c.x<i,t),s=b(c=>g=>Ae(c)(g.y+g.h+4))(r+4)(a),u=b(c=>g=>Ee(c)(g.y-4))(r-4)(a);return(()=>{const c=s-r,g=u-r;return(c<0?-c:c)<=(g<0?-g:g)})()?s:u},Db=t=>e=>n=>r=>o=>i=>a=>{const s=(()=>{if(r==="South")return L(o._1,o._2+4);if(r==="North")return L(o._1,o._2-4);if(r==="East")return L(o._1+4,o._2);if(r==="West")return L(o._1-4,o._2);_()})(),u=(()=>{if(i==="South")return L(a._1,a._2+4);if(i==="North")return L(a._1,a._2-4);if(i==="East")return L(a._1+4,a._2);if(i==="West")return L(a._1-4,a._2);_()})(),c=(J,k,S)=>!ru(e)(Ee(k)(S))(Ae(k)(S))(J),g=(J,k,S)=>!ru(n)(Ee(k)(S))(Ae(k)(S))(J),l=(J,k,S,A)=>t.tag==="Just"&&!ka(n)(Ee(J)(k))(Ae(J)(k))(t._1)?t._1:Pb(e)(J)(k)(S)(A),d=(J,k,S,A)=>{if(J===S){const $=Rb(e)(k)(A)(J),E=Sb(e)(J)(k)(A),G=Ab(e)(J)(k)(A);return[{start:L(J,k),end:L(J,E),direction:me},{start:L(J,E),end:L($,E),direction:we},{start:L($,E),end:L($,G),direction:me},{start:L($,G),end:L(S,G),direction:we},{start:L(S,G),end:L(S,A),direction:me}]}const I=l(J,S,k,A);return[{start:L(J,k),end:L(J,I),direction:me},{start:L(J,I),end:L(S,I),direction:we},{start:L(S,I),end:L(S,A),direction:me}]},f=(J,k,S,A)=>{if(k===A){const $=Gb(e)(J)(S)(k),E=Lb(e)(k)(J)(S),G=Eb(e)(k)(J)(S);return[{start:L(J,k),end:L(E,k),direction:we},{start:L(E,k),end:L(E,$),direction:me},{start:L(E,$),end:L(G,$),direction:we},{start:L(G,$),end:L(G,A),direction:me},{start:L(G,A),end:L(S,A),direction:we}]}const I=pd(e)(k)(A)(J)(S);return[{start:L(J,k),end:L(I,k),direction:we},{start:L(I,k),end:L(I,A),direction:me},{start:L(I,A),end:L(S,A),direction:we}]},h=(J,k,S)=>!ka(e)(Ee(k)(S))(Ae(k)(S))(J),m=(J,k,S)=>!ka(n)(Ee(k)(S))(Ae(k)(S))(J),p=(J,k,S,A)=>{if(m(k,J,S)&&g(S,k,A))return[{start:L(J,k),end:L(S,k),direction:we},{start:L(S,k),end:L(S,A),direction:me}];const I=pd(e)(k)(A)(J)(S);return[{start:L(J,k),end:L(I,k),direction:we},{start:L(I,k),end:L(I,A),direction:me},{start:L(I,A),end:L(S,A),direction:we}]},x=(J,k,S,A)=>{if(g(J,k,A)&&m(A,J,S))return[{start:L(J,k),end:L(J,A),direction:me},{start:L(J,A),end:L(S,A),direction:we}];const I=l(J,S,k,A);return[{start:L(J,k),end:L(J,I),direction:me},{start:L(J,I),end:L(S,I),direction:we},{start:L(S,I),end:L(S,A),direction:me}]},y=(()=>{if(r==="South")return i==="North"?s._1===u._1&&c(s._1,s._2,u._2)?[{start:L(s._1,s._2),end:L(u._1,u._2),direction:me}]:d(s._1,s._2,u._1,u._2):i==="East"||i==="West"?x(s._1,s._2,u._1,u._2):d(s._1,s._2,u._1,u._2);if(r==="North")return i==="South"?s._1===u._1&&c(s._1,s._2,u._2)?[{start:L(s._1,s._2),end:L(u._1,u._2),direction:me}]:d(s._1,s._2,u._1,u._2):i==="East"||i==="West"?x(s._1,s._2,u._1,u._2):d(s._1,s._2,u._1,u._2);if(r==="East")return i==="West"?s._2===u._2&&h(s._2,s._1,u._1)?[{start:L(s._1,s._2),end:L(u._1,u._2),direction:we}]:f(s._1,s._2,u._1,u._2):i==="North"||i==="South"?p(s._1,s._2,u._1,u._2):d(s._1,s._2,u._1,u._2);if(r==="West"){if(i==="East")return s._2===u._2&&h(s._2,s._1,u._1)?[{start:L(s._1,s._2),end:L(u._1,u._2),direction:we}]:f(s._1,s._2,u._1,u._2);if(i==="North"||i==="South")return p(s._1,s._2,u._1,u._2)}return d(s._1,s._2,u._1,u._2)})(),N=(()=>{if(r==="South"||r==="North")return me;if(r==="East"||r==="West")return we;_()})(),v={start:L(u._1,u._2),end:L(a._1,a._2),direction:(()=>{if(i==="South"||i==="North")return me;if(i==="East"||i==="West")return we;_()})()};return s._1===u._1&&s._2===u._2?[{start:L(o._1,o._2),end:L(a._1,a._2),direction:N}]:Tb({start:L(o._1,o._2),end:L(s._1,s._2),direction:N})(y)(v)},Fb=U(t=>({x:t.position._1*ou-2,y:t.position._2*ou-2,w:t.size._1*ou+4,h:t.size._2*ou+4})),md=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Mi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Ib=(()=>{const t=mn.unfoldr(sr);return e=>t(yn("IterNode",e,ir))})(),Ig=t=>e=>t.gapTop+1*rt(4)+rt(e)*2.5*rt(4),Bb=t=>e=>{const n=md(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return T("Just",{slot1Y:Ig(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Ig(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return w;_()}if(n.tag==="Nothing")return w;_()},Mb=t=>e=>{const n=b(r=>o=>it(P)(o.node)(o)(r))(M)(e);return bn(Ot(r=>o=>{const i=Mi(o.node)(n);if(i.tag==="Nothing")return[];if(i.tag==="Just"){const a=i._1;return Ot(s=>u=>{const c=o.edges.length,g=rt(4),l=a.position._1*g,d=a.position._2*g,f=a.size._2*g,h=rt((2*c|0)+1|0),m=d+f*rt(c-s|0)/h,p=d+f*rt((c+1|0)+s|0)/h,x=l-g*2.5*rt(s+1|0),y=[{start:L(l,m),end:L(x,m),direction:we},{start:L(x,m),end:L(x,p),direction:me},{start:L(x,p),end:L(l,p),direction:we}];return{edge:u.id,segments:y,bends:$e(N=>v=>N.end,y,Rt(1,3,y)),bendType:[],jumps:[],reversed:!1}})(o.edges)}_()})(U(r=>({node:r._1,edges:r._2}))(Ib(b(r=>o=>zt(P)(ye)(o.from.node)([o])(r))(M)(t)))))},zb=t=>e=>{const n=b(i=>a=>it(P)(a.node)(a)(i))(M)(e),r=i=>{const a=Mi(i)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1.position._1;_()},o=i=>{const a=Mi(i)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1.layer;_()};return Gt(i=>a=>{const s=ut.compare(o(i.edge.from.node))(o(a.edge.from.node));if(s==="EQ"){const u=at.compare(r(i.edge.from.node))(r(a.edge.from.node));return u==="EQ"?at.compare(r(i.edge.to.node))(r(a.edge.to.node)):u}return s})(t)},hn=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}},Qb=t=>t.from.node===t.to.node,Wb=t=>e=>n=>r=>{const o=kb(n)(Db(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:o,bends:$e(i=>a=>i.end,o,Rt(1,o.length,o)),bendType:[],jumps:[],reversed:!1}},Ob=t=>e=>n=>r=>{const o=[{start:L(r.fromPos._1,r.fromPos._2),end:L(r.fromPos._1,t.slot1Y),direction:me},{start:L(r.fromPos._1,t.slot1Y),end:L(t.splitX,t.slot1Y),direction:we},{start:L(t.splitX,t.slot1Y),end:L(t.splitX,t.slot2Y),direction:me},{start:L(t.splitX,t.slot2Y),end:L(r.toPos._1,t.slot2Y),direction:we},{start:L(r.toPos._1,t.slot2Y),end:L(r.toPos._1,r.toPos._2),direction:me}];return{edge:r.edge.id,segments:o,bends:$e(i=>a=>i.end,o,Rt(1,5,o)),bendType:[],jumps:[],reversed:!1}},Hb=t=>e=>n=>{const r=Mi(t.edge.from.node)(n);if(r.tag==="Just"){const i=Mi(t.edge.to.node)(n);return i.tag==="Just"?dt(a=>!(a.h===hn(r._1).h&&a.w===hn(r._1).w&&a.x===hn(r._1).x&&a.y===hn(r._1).y)&&!(a.h===hn(i._1).h&&a.w===hn(i._1).w&&a.x===hn(i._1).x&&a.y===hn(i._1).y),e):dt(a=>!(a.h===hn(r._1).h&&a.w===hn(r._1).w&&a.x===hn(r._1).x&&a.y===hn(r._1).y),e)}const o=Mi(t.edge.to.node)(n);return o.tag==="Just"?dt(i=>!(i.h===hn(o._1).h&&i.w===hn(o._1).w&&i.x===hn(o._1).x&&i.y===hn(o._1).y),e):dt(i=>!0,e)},$b=t=>e=>{const n=md(e.edge.id)(t);if(n.tag==="Just")return T("Just",Ig(n._1)(n._1.slot));if(n.tag==="Nothing")return w;_()},qb=t=>e=>n=>r=>o=>{const i=b(c=>g=>it(P)(g.node)(g)(c))(M)(e),a=Fb(e),s=Vl(dt(c=>c.from.node!==c.to.node,t))(e)(n)(r)(o),u=Hl(s)(e);return[...Mb(dt(Qb,t))(e),...b(c=>g=>{const l=Hb(g)(a)(i),d=[...l,...c.edgeObstacles],f=Bb(u)(g),h=(()=>{if(f.tag==="Just")return Ob(f._1)(l)(d)(g);if(f.tag==="Nothing")return Wb($b(u)(g))(l)(d)(g);_()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...Nb(h.segments)]}})({results:[],edgeObstacles:[]})(zb(s)(e)).results]},po=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},mo=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Ub=t=>e=>n=>{if(t.start._1!==e.start._1)return w;const r=mo(po(t.start._2)(t.end._2))(po(e.start._2)(e.end._2)),o=po(mo(t.start._2)(t.end._2))(mo(e.start._2)(e.end._2));return r<o?T("Just",{position:L(t.start._1,(r+o)/2),crossingEdge:n}):w},Xb=t=>e=>n=>{if(t.start._2!==e.start._2)return w;const r=mo(po(t.start._1)(t.end._1))(po(e.start._1)(e.end._1)),o=po(mo(t.start._1)(t.end._1))(mo(e.start._1)(e.end._1));return r<o?T("Just",{position:L((r+o)/2,t.start._2),crossingEdge:n}):w},Vb=t=>e=>n=>{if(t.direction==="H")return Xb(t)(e)(n);if(t.direction==="V")return Ub(t)(e)(n);_()},Yb=t=>e=>n=>{const r=t+1|0,o=r<1?n:Rt(r,n.length,n);return Et(e.segments)(i=>Et(o)(a=>wt(s=>Vb(i)(s)(a.edge))(dt(s=>s.direction==="H"?i.direction==="H":s.direction==="V"&&i.direction==="V",a.segments))))},Kb=t=>e=>n=>e.start._1>po(t.start._1)(t.end._1)&&e.start._1<mo(t.start._1)(t.end._1)&&t.start._2>po(e.start._2)(e.end._2)&&t.start._2<mo(e.start._2)(e.end._2)?T("Just",{position:L(e.start._1,t.start._2),crossingEdge:n}):w,jb=t=>e=>Et(dt(n=>n.direction==="H",t.segments))(n=>Et(e)(r=>wt(o=>Kb(n)(o)(r.edge))(dt(o=>o.direction==="V",r.segments)))),yd=t=>e=>n=>[...jb(e)(dt(r=>r.edge!==e.edge,n)),...Yb(t)(e)(n)],xd=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Zb=b(t=>e=>it(P)(e)()(t))(M),iu=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},tJ=Gl(P),Ar=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},wd=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},Bg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},eJ=ge(ut)(Mt),nJ=t=>e=>Qe(P.compare,Be,t,e),Nd=Ot(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),rJ=t=>b(e=>n=>({base:(()=>{const r=o=>i=>{let a=o,s=i,u=!0,c;for(;u;){const g=a,l=s;if(l.tag==="Nil"){u=!1,c=g;continue}if(l.tag==="Cons"){a=xd(g)(l._1),s=l._2;continue}_()}return c};return(e.base+r(0)((()=>{const o=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return o(i._5,yt("Cons",i._4,o(i._6,a)));_()};return o(n,R)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=o=>{if(o.tag==="Leaf")return M;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,o._4+e.base|0,r(o._5),r(o._6));_()};return r(n)})()]}))({base:0,result:[]})(t).result,oJ=t=>e=>{const n=Zb(t);return tJ(t)(Nd(dt(r=>iu(r.src)(n)&&iu(r.tgt)(n),e)))},iJ=t=>e=>{const n=b(o=>i=>zt(P)(ye)(i.tgt)([i.src])(zt(P)(ye)(i.src)([i.tgt])(o)))(M)(e),r=o=>i=>a=>{let s=o,u=i,c=a,g=!0,l;for(;g;){const d=s,f=u,h=c,m=At(p=>w,p=>x=>T("Just",{head:p,tail:x}),d);if(m.tag==="Nothing"){g=!1,l={nodes:h};continue}if(m.tag==="Just"){if(iu(m._1.head)(f)){s=m._1.tail,u=f,c=h;continue}s=[...m._1.tail,...(()=>{const p=Ar(m._1.head)(n);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;_()})()],u=it(P)(m._1.head)()(f),c=[...h,m._1.head];continue}_()}return l};return b(o=>i=>{if(iu(i)(o.visited))return o;const a=r([i])(o.visited)([]);return{...o,visited:b(s=>u=>it(P)(u)()(s))(o.visited)(a.nodes),components:[...o.components,a.nodes]}})({visited:M,components:[]})(t).components},aJ=t=>e=>n=>{const r=b(i=>a=>zt(P)(ve)(a.tgt)(1)(i))(M)(e),o=b(i=>a=>zt(P)(ve)(a.src)(1)(i))(M)(e);return b(i=>a=>{const s=Ar(a)(r),u=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;_()})();if((()=>{const y=Ar(a)(o);return(()=>{if(y.tag==="Nothing")return u!==0;if(y.tag==="Just")return u!==y._1;_()})()||u===0})())return i;const c=Ar(a)(i.layers),g=(()=>{if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1;_()})(),l=i.layers,d=b(y=>N=>N.tgt===a?{...y,mIn:wd(y.mIn)((()=>{const v=Ar(a)(l),J=Ar(N.src)(l);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;_()})()-(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;_()})()|0})())}:N.src===a?{...y,mOut:wd(y.mOut)((()=>{const v=Ar(N.tgt)(l),J=Ar(a)(l);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;_()})()-(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;_()})()|0})())}:y)({mIn:1e9,mOut:1e9})(e),f=d.mIn===1e9?-1:d.mIn,h=d.mOut===1e9?-1:d.mOut;if(f<0||h<0)return i;const m=(g-f|0)+1|0,p=(g+h|0)-1|0;if(p<m)return i;const x=b(y=>N=>{const v=Bg(N)(i.filling),J=(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;_()})();return J<y.bestFill?{best:N,bestFill:J}:y})({best:g,bestFill:(()=>{const y=Bg(g)(i.filling);if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;_()})()})(Yt(m,p));return x.best===g?i:{layers:it(P)(a)(x.best)(i.layers),filling:it(ut)(g)((()=>{const y=Bg(g)(i.filling);if(y.tag==="Nothing")return-1;if(y.tag==="Just")return y._1-1|0;_()})())(it(ut)(x.best)(x.bestFill+1|0)(i.filling))}})({layers:n,filling:eJ(U(i=>L(i,b(a=>s=>(()=>{const u=Ar(s)(n);return u.tag==="Nothing"?!1:u.tag==="Just"&&u._1===i})()?a+1|0:a)(0)(t)))(Yt(0,b(i=>a=>xd(i)((()=>{const s=Ar(a)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;_()})()))(0)(t))))})(t).layers},sJ=t=>e=>aJ(t)(Nd(e))(b(nJ)(M)(rJ(U(n=>oJ(n)(e))(iJ(t)(e))))),uJ=t=>t,qo=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},au=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Td=(()=>{const t=mn.unfoldr(sr);return e=>t(yn("IterNode",e,ir))})(),cJ=uJ("NetworkSimplex"),gJ=t=>e=>b(n=>r=>{const o=b(au)(0)(wt(i=>qo(i)(n))(r));return b(i=>a=>it(P)(a)(o)(i))(n)(r)})(e)(t),_J=t=>e=>({layers:U(n=>dt(r=>{const o=qo(r)(e);return o.tag==="Nothing"?!1:o.tag==="Just"&&o._1===n},t))(Yt(0,(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=i;if(c.tag==="Nil"){a=!1,s=u;continue}if(c.tag==="Cons"){o=au(u)(c._1),i=c._2;continue}_()}return s})(0)((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,yt("Cons",r._4,n(r._6,o)));_()};return n(e,R)})()))),nodeLayer:e}),fJ=t=>e=>n=>{const r=b(o=>i=>it(P)(i)(!0)(o))(M)(e);return b(o=>i=>it(P)(i._1)(i._2)(o))(sJ(e)(wt(o=>o.from.node===o.to.node||(()=>{const i=qo(o.from.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;_()})()||(()=>{const i=qo(o.to.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;_()})()?w:T("Just",{src:o.from.node,tgt:o.to.node}))(t)))(Td(n))},lJ=t=>e=>n=>r=>{const o=s=>u=>{const c=qo(u)(s);if(c.tag==="Just")return s;if(c.tag==="Nothing"){const g=dt(d=>d!==u,(()=>{const d=qo(u)(t);if(d.tag==="Nothing")return[];if(d.tag==="Just")return d._1;_()})()),l=b(o)(s)(g);return it(P)(u)(1+b(au)(0)(wt(d=>qo(d)(l))(g))|0)(l)}_()},i=b(o)(M)(n),a=(s=>u=>{let c=s,g=u,l=!0,d;for(;l;){const f=c,h=g;if(h.tag==="Nil"){l=!1,d=f;continue}if(h.tag==="Cons"){c=au(f)(h._1),g=h._2;continue}_()}return d})(1)((()=>{const s=(u,c)=>{if(u.tag==="Leaf")return c;if(u.tag==="Node")return s(u._5,yt("Cons",u._4,s(u._6,c)));_()};return s(i,R)})());return b(s=>u=>it(P)(u._1)(u._2)(s))((()=>{const s=u=>{if(u.tag==="Leaf")return M;if(u.tag==="Node")return ee("Node",u._1,u._2,u._3,a-u._4|0,s(u._5),s(u._6));_()};return s(i)})())(Td(r))},dJ=b(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return it(P)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return it(P)(e._1.node)(0)(t)}return t})(M),hJ=b(t=>e=>zt(P)(ye)(e.to.node)([e.from.node])(t))(M),pJ=b(t=>e=>zt(P)(ye)(e.from.node)([e.to.node])(t))(M),mJ=t=>e=>n=>r=>{const o=pJ(n),i=hJ(n),a=dJ(e);return _J(r)(gJ(wt(s=>s.tag==="SameLayer"?T("Just",s._1.nodes):w)(e))((()=>{if(t==="LongestPath")return lJ(o)(i)(r)(a);if(t==="NetworkSimplex")return fJ(n)(r)(a);_()})()))},yJ=ge(P)(Mt),xJ=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},vd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},bd=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},La=ge(P)(Mt),wJ=ge(P)(Mt),Jd=(()=>{const t=U(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>re(t(e))})(),NJ=t=>e=>n=>r=>{const o=yJ(U(a=>L(a.edge,a))(r)),i=a=>0<a.nodes.length&&(()=>{const s=xJ(a.edgeId)(n);return s.tag==="Just"&&a.nodes[0]!==s._1._1})();return U(a=>{if(a.nodes.length<=2){const g=vd(a.edgeId)(o);if(g.tag==="Just"){const l=i(a),d=Ja(ba(l?Jd(g._1.segments):g._1.segments));return{...g._1,edge:a.edgeId,segments:d,bends:$e(f=>h=>f.end,d,Rt(1,d.length,d)),reversed:l}}if(g.tag==="Nothing")return{edge:a.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};_()}const s=Et(wt(g=>vd(g)(o))($e(g=>l=>a.edgeId+":"+g+"->"+l,a.nodes,Rt(1,a.nodes.length,a.nodes))))(g=>g.segments),u=i(a),c=Ja(ba(u?Jd(s):s));return{edge:a.edgeId,segments:c,bends:$e(g=>l=>g.end,c,Rt(1,c.length,c)),bendType:[],jumps:[],reversed:u}})(t)},TJ={layers:[],edges:[],chains:[]},vJ={nodeGap:3,layerGap:2,iterations:8,layerer:cJ,cycleBreaker:db,compactPostRouting:!0,compactionSpacings:pv},bJ=t=>({pos:L(0,0),size:L(b(e=>n=>bd(e)(n.position._1+n.size._1))(0)(t),b(e=>n=>bd(e)(n.position._2+n.size._2))(0)(t))}),JJ=t=>e=>n=>{const r=La(U(c=>L(c.id,c.ports))(e.nodes)),o=dt(c=>De(3)(c.node)!=="$d:",n.placements),i=NJ(n.withDummies.chains)(n.acyclic.reversedEdges)(wJ(U(c=>L(c.id,L(c.from.node,c.to.node)))(e.edges)))(qb(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(Kl(n.ordered)(dt(c=>c.from.node!==c.to.node,n.withDummies.edges))((()=>{const c=g=>{if(g.tag==="Leaf")return M;if(g.tag==="Node")return ee("Node",g._1,g._2,g._3,L(g._4._1*4,g._4._2),c(g._5),c(g._6));_()};return c(La(U(g=>L(g.id,g.size))(e.nodes)))})()))),a=t.compactPostRouting?xv()(t.compactionSpacings)({nodes:o,edges:e.edges,paths:i,ports:r}):{nodes:o,edges:i},s=U(c=>{const g=Ja(ba(c.segments));return{...c,segments:g,bends:$e(l=>d=>l.end,g,Rt(1,g.length,g))}})(a.edges),u=Ot(c=>g=>({...g,jumps:yd(c)(g)(s)}))(s);return{nodes:a.nodes,edges:u,boundingBox:bJ(a.nodes),metrics:fl(a.nodes)(u)(0)}},Cd=t=>e=>n=>{const r=La(U(i=>L(i.id,i.size))(e.nodes)),o={...n,placements:Kv({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(La(U(i=>L(i.id,i.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(Kl(n.ordered)(n.withDummies.edges)((()=>{const i=a=>{if(a.tag==="Leaf")return M;if(a.tag==="Node")return ee("Node",a._1,a._2,a._3,L(a._4._1*4,a._4._2),i(a._5),i(a._6));_()};return i(r)})()))};return{pipeline:o,result:JJ(t)(e)(o)}},CJ=t=>e=>n=>Cd(t)(e)({...n,ordered:gb({iterations:t.iterations,constraints:e.constraints,modelOrder:La(Ot(r=>o=>L(o.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),kJ=t=>e=>n=>CJ(t)(e)({...n,withDummies:wv(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),LJ=t=>e=>{const n=U(o=>o.id)(e.nodes),r=wb(t.cycleBreaker)(n)(e.constraints)(e.edges);return kJ(t)(e)({acyclic:r,layered:mJ(t.layerer)(e.constraints)(r.edges)(n),withDummies:TJ,ordered:[],placements:[]})},Mg=ge(P)(Mt),SJ=ge(P)(Mt),EJ=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Pr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Sa=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},su=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},AJ=t=>e=>{const n=e.result.nodes,r=Mg(U(s=>L(s.node,s))(n)),o=SJ(U(s=>L(s.id,s))(t.edges)),i=U(s=>{const u=EJ(s.edge)(o);if(u.tag==="Just"){const c=Pr(u._1.from.node)(r);if(c.tag==="Just"){const g=Pr(u._1.to.node)(r);if(g.tag==="Just"){if(c._1.layer>=g._1.layer||s.jumps.length!==0)return s;const l=rt(4),d=c._1.position._1*l,f=(c._1.position._1+c._1.size._1)*l,h=g._1.position._1*l,m=(g._1.position._1+g._1.size._1)*l,p=Sa(d)(h),x=su(f)(m);if(p>x)return s;const y=(d+f)*.5,N=(h+m)*.5,v=su(x)(Sa(p)(c._1.size._1<=g._1.size._1?y:N)),J=(c._1.position._2+c._1.size._2)*l,k=g._1.position._2*l;return(()=>{const S=u._1.from.node,A=u._1.to.node;return ne(I=>{const $=rt(4);return I.node!==S&&I.node!==A&&v>I.position._1*$&&v<(I.position._1+I.size._1)*$&&I.position._2*$<k&&(I.position._2+I.size._2)*$>J},n)})()?s:{...s,segments:[{start:L(v,J),end:L(v,k),direction:me}],bends:[],bendType:[],jumps:[]}}if(g.tag==="Nothing")return s;_()}if(c.tag==="Nothing")return s;_()}if(u.tag==="Nothing")return s;_()})(e.result.edges),a=Ot(s=>u=>({...u,jumps:yd(s)(u)(i)}))(i);return{...e,result:{...e.result,edges:a,metrics:fl(e.result.nodes)(a)(e.result.metrics.constraintViolations)}}},PJ=t=>e=>n=>{const r=n.result.nodes,o=Mg(U(a=>L(a.node,a))(r)),i=n.result.boundingBox.size._1;return Mg(wt(a=>{const s=Pr(a.id)(o);if(s.tag==="Just"){const u=Pr(a.id)(n.pipeline.layered.nodeLayer);if(u.tag==="Just"){const c=u._1,g=wt(d=>{if(d.from.node===a.id){const f=Pr(d.to.node)(n.pipeline.layered.nodeLayer);if(f.tag==="Just")return f._1<=c?w:Pr(d.to.node)(o);if(f.tag==="Nothing")return w;_()}if(d.to.node===a.id){const f=Pr(d.from.node)(n.pipeline.layered.nodeLayer);if(f.tag==="Just")return f._1>=c?w:Pr(d.from.node)(o);if(f.tag==="Nothing")return w;_()}return w})(e.edges);if(g.length<2)return w;const l=At(d=>w,d=>f=>T("Just",{head:d,tail:f}),U(d=>d.position._1+d.size._1*.5)(g));if(l.tag==="Just"){const d=Sa(a.size._1)(b(Sa)(l._1.head)(l._1.tail)-b(su)(l._1.head)(l._1.tail)+2),f=s._1.position._1,h=f+s._1.size._1,m=dt(p=>{const x=Pr(p.node)(n.pipeline.layered.nodeLayer);return p.node!==a.id&&(x.tag==="Nothing"?!1:x.tag==="Just"&&x._1===c)},r);return d>a.size._1+.5&&d<=b(p=>x=>x.position._1>=h?su(p)(x.position._1-rt(t.nodeGap)):p)(i)(m)-b(p=>x=>x.position._1+x.size._1<=f?Sa(p)(x.position._1+x.size._1+rt(t.nodeGap)):p)(0)(m)?T("Just",L(a.id,L(d,a.size._2))):w}if(l.tag==="Nothing")return w;_()}if(u.tag==="Nothing")return w;_()}if(s.tag==="Nothing")return w;_()})(e.nodes))},RJ=t=>e=>{const n=LJ(t)(e),r=PJ(t)(e)(n),o=AJ(e)(Cd(t)({...e,nodes:U(i=>{const a=Pr(i.id)(r);if(a.tag==="Just")return{...i,size:a._1};if(a.tag==="Nothing")return i;_()})(e.nodes)})(n.pipeline));return r.tag==="Leaf"||b(i=>a=>i+a.bends.length|0)(0)(o.result.edges)>=b(i=>a=>i+a.bends.length|0)(0)(n.result.edges)?n:o},uu=t=>t,GJ=t=>t,qr=uu("RunText"),zg=uu("RunCode"),Qg=uu("RunHighlight"),Wg=uu("RunCodeHighlight"),DJ=t=>{const e=r=>{const o=At(i=>w,i=>a=>T("Just",{head:i,tail:a}),r);if(o.tag==="Nothing")return[];if(o.tag==="Just"){if(o._1.head==="\\"){const i=At(a=>w,a=>s=>T("Just",{head:a,tail:s}),o._1.tail);if(i.tag==="Nothing")return[o._1.head];if(i.tag==="Just")return[o._1.head,i._1.head,...e(i._1.tail)];_()}return o._1.head==="="&&0<o._1.tail.length&&o._1.tail[0]==="="?e(Rt(1,o._1.tail.length,o._1.tail)):[o._1.head,...e(o._1.tail)]}_()},n=Yn("md:")(t);if(n.tag==="Nothing")return t;if(n.tag==="Just")return In(e(Bn(n._1)));_()},FJ=t=>"md:"+t,nr=t=>{const e=(()=>{const r=Yn("md:")(t);if(r.tag==="Just")return!0;if(r.tag==="Nothing")return!1;_()})()?FJ:GJ,n=Mo(`
5
- `)((()=>{const r=Yn("md:")(t);if(r.tag==="Just")return r._1;if(r.tag==="Nothing")return t;_()})());return n.length===0?[e("")]:U(e)(n)},Og=t=>e=>n=>e.length===0?n:St(n)({style:t,text:In(e)}),IJ=t=>({code:!t.code,highlight:t.highlight,buf:[],runs:Og((()=>{if(!t.highlight){if(!t.code)return qr;if(t.code)return zg;_()}if(t.highlight){if(!t.code)return Qg;if(t.code)return Wg}_()})())(t.buf)(t.runs)}),BJ=t=>({code:t.code,highlight:!t.highlight,buf:[],runs:Og((()=>{if(!t.highlight){if(!t.code)return qr;if(t.code)return zg;_()}if(t.highlight){if(!t.code)return Qg;if(t.code)return Wg}_()})())(t.buf)(t.runs)}),MJ=t=>e=>0<e.length?{...t,buf:St(t.buf)(e[0])}:{...t,buf:St(t.buf)("\\")},zJ=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,c=o,g=At(l=>w,l=>d=>T("Just",{head:l,tail:d}),i);if(g.tag==="Nothing"){a=!1,s=c;continue}if(g.tag==="Just"){if(g._1.head==="\\"){r=u,o=MJ(c)(g._1.tail),i=Rt(1,g._1.tail.length,g._1.tail);continue}if(g._1.head==="`"){r=u,o=IJ(c),i=g._1.tail;continue}if(u&&g._1.head==="="&&0<g._1.tail.length&&g._1.tail[0]==="="){r=u,o=BJ(c),i=Rt(1,g._1.tail.length,g._1.tail);continue}r=u,o={...c,buf:St(c.buf)(g._1.head)},i=g._1.tail;continue}_()}return s},fr=t=>{const e=zJ((()=>{const n=Yn("md:")(t);if(n.tag==="Just")return!0;if(n.tag==="Nothing")return!1;_()})())({code:!1,highlight:!1,buf:[],runs:[]})(Bn((()=>{const n=Yn("md:")(t);if(n.tag==="Just")return n._1;if(n.tag==="Nothing")return t;_()})()));return Og((()=>{if(!e.highlight){if(!e.code)return qr;if(e.code)return zg;_()}if(e.highlight){if(!e.code)return Qg;if(e.code)return Wg}_()})())(e.buf)(e.runs)},Ur=(()=>{const t=Qn(""),e=U(n=>n.text);return n=>t(e(fr(n)))})();let Hg=null;function QJ(){return Hg||(typeof document>"u"?null:(Hg=document.createElement("canvas").getContext("2d"),Hg))}const kd=new Map,WJ=t=>e=>n=>r=>()=>{const o=`${n} ${e}px ${t}|${r}`,i=kd.get(o);if(i!==void 0)return i;const a=QJ();if(!a)return r.length*e*.62;a.font=`${n} ${e}px ${t}`;const s=a.measureText(r).width;return kd.set(o,s),s},OJ=so.traverse(gc),HJ=b(ur)(0),Uo=(()=>{const t=jn(`\r
6
- `)(" "),e=jn(`
7
- `)(" "),n=(()=>{const r=jn("\r")(" "),o=(()=>{const i=jn(" ")(" ");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),Ld=t=>e=>{const n=OJ(r=>{const o=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;if(r.style==="RunHighlight")return t.text;if(r.style==="RunCodeHighlight")return t.code;_()})();return WJ(o.family)(o.size)(o.weight)(Uo(r.text))})(fr(Uo(e)));return()=>{const r=n();return HJ(r)}},Sd={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"}},$J=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},zi=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},qJ=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},Ed=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},UJ=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Ad=t=>In(re(vr(e=>e===" ")(re(vr(e=>e===" ")(Bn(t)).rest)).rest)),XJ=t=>b(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?T("Just",n._1):e)(w)(Ot(vn)(t)),$g=t=>e=>{if(t<=0)return[e];if(gr(e)<=t)return[e];const n=Bn(e),r=t<1?[]:Rt(0,t,n),o=XJ(r);if(o.tag==="Just"){const i=Ad(jf(!(o._1>=0&&o._1<r.length)||r[o._1]===" "?o._1:o._1+1|0)(e)),a=Ad(Ji(o._1+1|0)(e));return a===""?[i]:[i,...$g(t)(a)]}if(o.tag==="Nothing"){const i=jf(t)(e),a=Ji(t)(e);return a===""?[i]:[i,...$g(t)(a)]}_()},VJ={cellW:7,cellH:3,maxLineWidth:20},YJ=t=>e=>{const n=U(i=>L((()=>{if(i.label.tag==="Just")return i.label._1;if(i.label.tag==="Nothing")return i.id;_()})(),i))(e.nodes),r=zi(1)(Nr((qJ(t.maxLineWidth)(b(i=>a=>zi(i)(gr(a._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),o=(r*t.cellW|0)-1|0;return{...e,nodes:U(i=>{const a=Et(Mo(`
8
- `)(i._1))($g(o)),s=b(l=>d=>zi(l)(gr(d)))(0)(a),u=zi(1)(Nr(a.length+t.cellH|0,t.cellH))+(i._2.shape==="Cylinder"||i._2.shape==="Document"?1:0)|0,c=i._2.shape==="Cylinder"?zi(1)(Nr((s+2|0)+t.cellW|0,t.cellW)):r,g=s>o?Nr((s+2|0)+t.cellW|0,t.cellW):c;return{...i._2,size:L(i._2.size._1!==1?Ed(i._2.size._1)(rt(g)):rt(g),i._2.size._2!==1?i._2.size._2:rt(u))}})(n)}},KJ=t=>e=>n=>({...n,nodes:U(r=>{const o=UJ(r.id)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just")return{...r,size:L(Ed(r.size._1)(rt(zi(1)(de(us(r.shape==="Cylinder"?(o._1+0)/t:(o._1+32)/t))))),r.size._2)};_()})(n.nodes)}),cu=t=>t,jJ=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},Xr=cu("TopSide"),Vr=cu("BottomSide"),Yr=cu("LeftSide"),Kr=cu("RightSide"),ZJ=t=>{const e=at.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;_()})(),r=at.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;_()},Pd=t=>e=>n=>{const r=jJ(t.h*.12)(t.w*.2),o=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*tn(ZJ((()=>{const i=(n-(t.x+o))/o;return 1-i*i})()))},qe=t=>e=>n=>r=>{let o=t,i=e,a=n,s=r,u=!0,c;for(;u;){const g=o,l=i,d=a,f=s;if(g==="Rectangle"){if(d==="TopSide"){u=!1,c=l.y;continue}if(d==="BottomSide"){u=!1,c=l.y+l.h;continue}if(d==="LeftSide"){u=!1,c=l.x;continue}if(d==="RightSide"){u=!1,c=l.x+l.w;continue}o=go,i=l,a=d,s=f;continue}if(g==="Cylinder"){if(d==="TopSide"){u=!1,c=Pd(l)(-1)(f);continue}if(d==="BottomSide"){u=!1,c=Pd(l)(1)(f);continue}if(d==="LeftSide"){u=!1,c=l.x;continue}if(d==="RightSide"){u=!1,c=l.x+l.w;continue}}o=go,i=l,a=d,s=f}return c},Rd=t=>e=>{const n=e.y-t.y,r=n<0?-n:n,o=e.x-(t.x+t.w),i=o<0?-o:o,a=e.x-t.x,s=a<0?-a:a,u=e.y-(t.y+t.h),c=u<0?-u:u;return r<=c&&r<=s&&r<=i?Xr:c<=s&&c<=i?Vr:s<=i?Yr:Kr},tC=(()=>{const t=mn.unfoldr(sr);return e=>t(yn("IterNode",e,ir))})(),qg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Xo=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Ea=ge(P)(Mt),Ug=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},eC=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},nC=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},rC=b(t=>e=>it(P)(e)()(t))(M),oC=b(t=>e=>it(P)(e)()(t))(M),Aa=so.traverse(gc),Xg=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Pa=ge(P)(Mt),iC=t=>e=>Qe(P.compare,Be,t,e),aC=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},sC=b(t=>e=>it(P)(e)()(t))(M),uC=ge(P)(Mt),cC=t=>e=>Qe(P.compare,Be,t,e),gC=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},_C=t=>e=>({...e,edges:Ea(U(n=>L(n._1,(()=>{const r=qg(n._1)(t);if(r.tag==="Nothing")return n._2;if(r.tag==="Just"){const o=Xo(r._1._2)(e.nodes),i=Xo(r._1._1)(e.nodes),a=(()=>{if(i.tag==="Nothing")return n._2;if(i.tag==="Just"){const s=At(u=>w,u=>c=>T("Just",{head:u,tail:c}),n._2);if(s.tag==="Nothing")return n._2;if(s.tag==="Just")return[(()=>{const u=At(d=>w,d=>f=>T("Just",{head:d,tail:f}),s._1.tail),c=u.tag==="Just"?T("Just",u._1.head):w,g={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},l=(()=>{if(c.tag==="Just"){if((c._1.x>s._1.head.x?c._1.x-s._1.head.x<.5:s._1.head.x-c._1.x<.5)&&s._1.head.x>=g.x-.5&&s._1.head.x<=g.x+g.w+.5)return c._1.y>=g.y+g.h?T("Just",Vr):c._1.y<=g.y?T("Just",Xr):w;if((c._1.y>s._1.head.y?c._1.y-s._1.head.y<.5:s._1.head.y-c._1.y<.5)&&s._1.head.y>=g.y-.5&&s._1.head.y<=g.y+g.h+.5){if(c._1.x>=g.x+g.w)return T("Just",Kr);if(c._1.x<=g.x)return T("Just",Yr)}return w}if(c.tag==="Nothing")return w;_()})();if(l.tag==="Just"){if(l._1==="TopSide")return{...s._1.head,y:qe(i._1.shape)(g)(Xr)(s._1.head.x)};if(l._1==="BottomSide")return{...s._1.head,y:qe(i._1.shape)(g)(Vr)(s._1.head.x)};if(l._1==="LeftSide")return{...s._1.head,x:qe(i._1.shape)(g)(Yr)(s._1.head.y)};if(l._1==="RightSide")return{...s._1.head,x:qe(i._1.shape)(g)(Kr)(s._1.head.y)};_()}if(l.tag==="Nothing"){const d={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},f=Rd(d)(s._1.head);if(f==="TopSide")return{...s._1.head,y:qe(i._1.shape)(d)(Xr)(s._1.head.x)};if(f==="BottomSide")return{...s._1.head,y:qe(i._1.shape)(d)(Vr)(s._1.head.x)};if(f==="LeftSide")return{...s._1.head,x:qe(i._1.shape)(d)(Yr)(s._1.head.y)};if(f==="RightSide")return{...s._1.head,x:qe(i._1.shape)(d)(Kr)(s._1.head.y)}}_()})(),...s._1.tail]}_()})();if(o.tag==="Nothing")return a;if(o.tag==="Just"){const s=zr(a);if(s.tag==="Nothing")return a;if(s.tag==="Just")return St(s._1.init)((()=>{const u=zr(s._1.init),c=u.tag==="Just"?T("Just",u._1.last):w,g={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},l=(()=>{if(c.tag==="Just"){if((c._1.x>s._1.last.x?c._1.x-s._1.last.x<.5:s._1.last.x-c._1.x<.5)&&s._1.last.x>=g.x-.5&&s._1.last.x<=g.x+g.w+.5)return c._1.y>=g.y+g.h?T("Just",Vr):c._1.y<=g.y?T("Just",Xr):w;if((c._1.y>s._1.last.y?c._1.y-s._1.last.y<.5:s._1.last.y-c._1.y<.5)&&s._1.last.y>=g.y-.5&&s._1.last.y<=g.y+g.h+.5){if(c._1.x>=g.x+g.w)return T("Just",Kr);if(c._1.x<=g.x)return T("Just",Yr)}return w}if(c.tag==="Nothing")return w;_()})();if(l.tag==="Just"){if(l._1==="TopSide")return{...s._1.last,y:qe(o._1.shape)(g)(Xr)(s._1.last.x)};if(l._1==="BottomSide")return{...s._1.last,y:qe(o._1.shape)(g)(Vr)(s._1.last.x)};if(l._1==="LeftSide")return{...s._1.last,x:qe(o._1.shape)(g)(Yr)(s._1.last.y)};if(l._1==="RightSide")return{...s._1.last,x:qe(o._1.shape)(g)(Kr)(s._1.last.y)};_()}if(l.tag==="Nothing"){const d={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},f=Rd(d)(s._1.last);if(f==="TopSide")return{...s._1.last,y:qe(o._1.shape)(d)(Xr)(s._1.last.x)};if(f==="BottomSide")return{...s._1.last,y:qe(o._1.shape)(d)(Vr)(s._1.last.x)};if(f==="LeftSide")return{...s._1.last,x:qe(o._1.shape)(d)(Yr)(s._1.last.y)};if(f==="RightSide")return{...s._1.last,x:qe(o._1.shape)(d)(Kr)(s._1.last.y)}}_()})())}}_()})()))(tC(e.edges)))}),fC=t=>e=>n=>{const r=Kt(o=>o.id===n)(t.graph.edges);if(r.tag==="Just")return T("Just",r._1);if(r.tag==="Nothing")return qg(n)(e);_()},lC=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 o=Xo(r.node)(e);if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return r.node;_()})(),shape:(()=>{const o=Xo(r.node)(n);if(o.tag==="Nothing")return go;if(o.tag==="Just")return o._1;_()})()}),dC=t=>({id:t,size:L(1,1),ports:[],label:T("Just",t),shape:go}),Gd=t=>e=>n=>{const r=wt(i=>Xo(e)(i.labels))(t.keyframes),o=At(i=>w,i=>a=>T("Just",{head:i,tail:a}),r);if(o.tag==="Nothing")return[n];if(o.tag==="Just")return[n,...r];_()},hC=t=>e=>n=>r=>L(r.node,lC(t)(e)(n)(r)),Dd=t=>nr(t),Fd=t=>{const e=Mo(`
9
- `)(t),n=e.length===0?[""]:e;return n.length*Ug(1)(b(r=>o=>Ug(r)(gr(o)))(0)(n))|0},pC=t=>{const e=At(n=>w,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return"";if(e.tag==="Just")return b(n=>r=>Fd(r)>Fd(n)?r:n)(e._1.head)(e._1.tail);_()},mC=t=>e=>pC(Gd(t)(e.id)((()=>{if(e.label.tag==="Just")return e.label._1;if(e.label.tag==="Nothing")return e.id;_()})())),Id=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,yt("Cons",n._4,e(n._6,r)));_()};return Wt(ue.foldr,e(t.interiors,R))},yC=t=>Ea(wt(e=>T("Just",L(e.edge,{id:e.edge,from:{node:e.from,port:w},to:{node:e.to,port:w},label:w})))(Et(t.scenes)(e=>e.tag==="DataFlow"?wt(n=>n.kind.tag==="SendToken"?T("Just",n.kind._1):w)(e._1.events):[]))),Bd=t=>{const e=ux(t),n=U(o=>({...o,label:T("Just",mC(t)(o))}))(dt(o=>eC(o.id)(e.nodes),t.graph.nodes)),r=dt(o=>nC(o.id)(e.edges),t.graph.edges);return{nodes:[...n,...U(dC)(Wt(ln.foldr,ar(P.compare,e.nodes,rC(U(o=>o.id)(n)))))],edges:[...r,...wt(fC(t)(yC(t)))(Wt(ln.foldr,ar(P.compare,e.edges,oC(U(o=>o.id)(r)))))],constraints:t.graph.constraints}},xC=t=>{const e=Aa(n=>{const r=Aa(Ld(Sd))(Gd(t)(n.id)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;_()})()));return()=>{const o=r();return L(n.id,b(Xg)(0)(o))}})(Bd(t).nodes);return()=>{const n=e();return Pa(n)}},Md=t=>{const e=xC(t);return()=>{const n=e(),r=Aa(Md)(Id(t))();return b(iC)(n)(r)}},wC=t=>e=>{const n=At(r=>w,r=>o=>T("Just",{head:r,tail:o}),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},...U(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];_()},NC=t=>e=>{const n=Pa(U(r=>L(r.id,r))(t.nodes));return{...e,nodes:U(r=>{const o=Xo(r.id)(n);return o.tag==="Just"&&o._1.size._2===1?{...r,size:L(r.size._1,aC(r.size._2)(rt(Ug(1)(Nr(nr((()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;_()})()).length+3|0,3))+(r.shape==="Cylinder"||r.shape==="Document"?1:0)|0)))}:r})(e.nodes)}},TC=t=>e=>L(e.edge,wC(t)(e)),vC=t=>e=>n=>r=>({nodes:Pa(U(hC(rt(4)*t)(e)(n))(r.nodes)),edges:Ea(U(TC(t))(r.edges)),chipExtras:M,edgeLabels:M}),bC=t=>e=>({..._C(Ea(U(n=>L(n.id,L(n.from.node,n.to.node)))(e.edges)))(vC(8)(Pa(U(n=>L(n.id,(()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;_()})()))(e.nodes)))(Pa(U(n=>L(n.id,n.shape))(e.nodes)))(RJ(vJ)(e).result)),edgeLabels:Ea(wt(n=>n.label.tag==="Just"?T("Just",L(n.id,n.label._1)):w)(e.edges))}),JC=t=>b(e=>n=>{if(n.tag==="Structural")return e;if(n.tag==="DataFlow")return b(r=>o=>{if(o.kind.tag==="SendToken")return b(i=>a=>it(P)(a)()(i))(r)(o.kind._1.labels);if(o.kind.tag==="FillNodeWithoutTransition")return b(i=>a=>it(P)(a)()(i))(r)(o.kind._1.labels);_()})(e)(n._1.events);if(n.tag==="Hold"||n.tag==="EnterNode"||n.tag==="ExitNode"||n.tag==="StepScene")return e;_()})(M)(t.scenes),CC=t=>{const e=Aa(n=>{const r=Ld(Sd)(n);return()=>{const o=r();return L(n,{labelW:o,charCount:gr(Ur(Uo(n))),lineCount:1})}})(Wt(ln.foldr,sC(Et(Wt(ln.foldr,JC(t)))(Dd))));return()=>{const n=e();return uC(n)}},zd=t=>{const e=CC(t);return()=>{const n=e(),r=Aa(zd)(Id(t))();return b(cC)(n)(r)}},kC=rt(4)*8,LC=t=>Et(t.scenes)(e=>{if(e.tag==="Structural")return[];if(e.tag==="DataFlow")return e._1.events;if(e.tag==="Hold")return[];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];if(e.tag==="StepScene")return[];_()}),SC=t=>e=>n=>{const r=o=>{const i=wt(a=>{const s=gC(a)(t);return s.tag==="Just"?T("Just",{w:s._1.labelW+28,h:rt($J(1)(s._1.lineCount))*13.2+12}):w})(Et(o)(Dd));return i.length===0?w:T("Just",{w:b(Xg)(0)(U(a=>a.w)(i)),h:b(Xg)(0)(U(a=>a.h)(i))})};return b(o=>i=>{if(i.kind.tag==="SendToken"){const a=qg(i.kind._1.edge)(n.edges),s=r(i.kind._1.labels);if(s.tag==="Just"&&a.tag==="Just"){const u=s._1;return zt(P)(ye)(i.kind._1.edge)(U(c=>({x:c.x+14+u.w,y:c.y-6-8-u.h}))(a._1))(o)}return o}if(i.kind.tag==="FillNodeWithoutTransition"){const a=Xo(i.kind._1.node)(n.nodes),s=r(i.kind._1.labels);return s.tag==="Just"&&a.tag==="Just"?zt(P)(ye)("__fill__:"+i.kind._1.node)((()=>{const u=a._1.y-s._1.h-14,c=a._1.x+a._1.w/2,g=c-s._1.w/2,l=c+s._1.w/2,d=a._1.y-14;return[{x:g,y:u},{x:l,y:u},{x:g,y:d},{x:l,y:d}]})())(o):o}_()})(M)(LC(e))},Qd=t=>e=>n=>{const r=Bd(n);return{layout:(()=>{const o=bC()(NC(r)(KJ(kC)(t)(YJ(VJ)(r))));return{...o,chipExtras:SC(e)(n)(o)}})(),interiors:(()=>{const o=Qd(t)(e),i=a=>{if(a.tag==="Leaf")return M;if(a.tag==="Node")return ee("Node",a._1,a._2,a._3,o(a._4),i(a._5),i(a._6));_()};return i(n.interiors)})()}},Wd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Vg=t=>e=>n=>{const r=t<.05?t:.05,o=(a,s)=>{if(s.tag==="Leaf")return a;if(s.tag==="Node")return o((()=>{const u=Wd(s._3)(n),c=(()=>{if(u.tag==="Just")return u._1;if(u.tag==="Nothing")return{x:s._4.x,y:s._4.y,vx:0,vy:0};_()})(),g=c.vx+(180*(s._4.x-c.x)-22*c.vx)*r,l=c.vy+(180*(s._4.y-c.y)-22*c.vy)*r;return it(P)(s._3)({x:c.x+g*r,y:c.y+l*r,vx:g,vy:l})(o(a,s._5))})(),s._6);_()},i=o(M,e);return{springs:i,applied:(()=>{const a=(s,u)=>{if(u.tag==="Leaf")return s;if(u.tag==="Node")return a((()=>{const c=a(s,u._5),g=Wd(u._3)(i);if(g.tag==="Just")return it(P)(u._3)({...u._4,x:g._1.x,y:g._1.y})(c);if(g.tag==="Nothing")return it(P)(u._3)(u._4)(c);_()})(),u._6);_()};return a(M,e)})()}},Z=(t,e)=>({tag:"CatQueue",_1:t,_2:e}),EC=t=>{let e=t,n=!0,r;for(;n;){const o=e;if(o._1.tag==="Nil"){if(o._2.tag==="Nil"){n=!1,r=w;continue}e=Z((i=>a=>{let s=i,u=a,c=!0,g;for(;c;){const l=s,d=u;if(d.tag==="Nil"){c=!1,g=l;continue}if(d.tag==="Cons"){s=yt("Cons",d._1,l),u=d._2;continue}_()}return g})(R)(o._2),R);continue}if(o._1.tag==="Cons"){n=!1,r=T("Just",L(o._1._1,Z(o._1._2,o._2)));continue}_()}return r},tt=(t,e,n)=>({tag:t,_1:e,_2:n}),ct=tt("CatNil"),AC=t=>e=>{if(t.tag==="CatNil")return e;if(e.tag==="CatNil")return t;if(t.tag==="CatCons")return tt("CatCons",t._1,Z(t._2._1,yt("Cons",e,t._2._2)));_()},PC=t=>e=>n=>{const r=o=>i=>a=>{let s=o,u=i,c=a,g=!0,l;for(;g;){const d=s,f=u,h=c;if(h.tag==="Nil"){g=!1,l=f;continue}if(h.tag==="Cons"){s=d,u=d(f)(h._1),c=h._2;continue}_()}return l};return(o=>i=>{let a=o,s=i,u=!0,c;for(;u;){const g=a,l=s,d=EC(g);if(d.tag==="Nothing"){u=!1,c=r(f=>h=>h(f))(e)(l);continue}if(d.tag==="Just"){a=d._1._2,s=yt("Cons",t(d._1._1),l);continue}_()}return c})(n)(R)},RC=t=>{if(t.tag==="CatNil")return w;if(t.tag==="CatCons")return T("Just",L(t._1,t._2._1.tag==="Nil"&&t._2._2.tag==="Nil"?ct:PC(AC)(ct)(t._2)));_()},K=(t,e)=>({tag:"Free",_1:t,_2:e}),st=(t,e,n)=>({tag:t,_1:e,_2:n}),Od=t=>{let e=t,n=!0,r;for(;n;){const o=e;if(o._1.tag==="Return"){const i=RC(o._2);if(i.tag==="Nothing"){n=!1,r=st("Return",o._1._1);continue}if(i.tag==="Just"){e=(()=>{const a=i._1._1(o._1._1);return K(a._1,(()=>{if(a._2.tag==="CatNil")return i._1._2;if(i._1._2.tag==="CatNil")return a._2;if(a._2.tag==="CatCons")return tt("CatCons",a._2._1,Z(a._2._2._1,yt("Cons",i._1._2,a._2._2._2)));_()})())})();continue}_()}if(o._1.tag==="Bind"){n=!1,r=st("Bind",o._1._1,i=>{const a=o._1._2(i);return K(a._1,(()=>{if(a._2.tag==="CatNil")return o._2;if(o._2.tag==="CatNil")return a._2;if(a._2.tag==="CatCons")return tt("CatCons",a._2._1,Z(a._2._2._1,yt("Cons",o._2,a._2._2._2)));_()})())});continue}_()}return r},GC=t=>e=>{const n=e.Monad0(),r=n.Bind1().Apply0().Functor0();return o=>e.tailRecM(i=>{const a=Od(i);if(a.tag==="Return")return r.map(u2)(n.Applicative0().pure(a._1));if(a.tag==="Bind")return r.map(_c)(o(t.map(a._2)(a._1)));_()})},DC=t=>e=>n=>{const r=Od(n);if(r.tag==="Return")return e(r._1);if(r.tag==="Bind")return t(r._1)(r._2);_()},Yg={Applicative0:()=>yo,Bind1:()=>Hd},FC={map:t=>e=>Hd.bind(e)(n=>yo.pure(t(n)))},Hd={bind:t=>e=>K(t._1,(()=>{if(t._2.tag==="CatNil")return tt("CatCons",e,Z(R,R));if(t._2.tag==="CatCons")return tt("CatCons",t._2._1,Z(t._2._2._1,yt("Cons",tt("CatCons",e,Z(R,R)),t._2._2._2)));_()})()),Apply0:()=>$d},$d={apply:t=>e=>{const n=r=>K(e._1,(()=>{if(e._2.tag==="CatNil")return tt("CatCons",o=>yo.pure(r(o)),Z(R,R));if(e._2.tag==="CatCons")return tt("CatCons",e._2._1,Z(e._2._2._1,yt("Cons",tt("CatCons",o=>yo.pure(r(o)),Z(R,R)),e._2._2._2)));_()})());return K(t._1,(()=>{if(t._2.tag==="CatNil")return tt("CatCons",n,Z(R,R));if(t._2.tag==="CatCons")return tt("CatCons",t._2._1,Z(t._2._2._1,yt("Cons",tt("CatCons",n,Z(R,R)),t._2._2._2)));_()})())},Functor0:()=>FC},yo={pure:t=>K(st("Return",t),ct),Apply0:()=>$d},IC=()=>()=>()=>t=>e=>n=>Xm(n.type)(t)?Vm(n.type)(t)(n.value):e(n),BC={map:t=>e=>({type:e.type,value:e.map(t)(e.value),map:e.map})},MC=t=>r1("Data.Functor.Variant: pattern match failure ["+t.type+"]"),zC=()=>()=>()=>t=>IC()()()(t)(MC);(function(){var t={},e="Pure",n="Throw",r="Catch",o="Sync",i="Async",a="Bind",s="Bracket",u="Fork",c="Sequential",g="Map",l="Apply",d="Alt",f="Cons",h="Resume",m="Release",p="Finalizer",x="Finalized",y="Forked";function N(z,j,W,O){this.tag=z,this._1=j,this._2=W,this._3=O}function v(z){var j=function(W,O,q){return new N(z,W,O,q)};return j.tag=z,j}function J(z){return new N(e,void 0)}function k(z){try{z()}catch(j){setTimeout(function(){throw j},0)}}function S(z,j,W){try{return j(W())}catch(O){return z(O)}}function A(z,j,W){try{return j(W)()}catch(O){return W(z(O))(),J}}var I=(function(){var z=1024,j=0,W=0,O=new Array(z),q=!1;function H(){var ot;for(q=!0;j!==0;)j--,ot=O[W],O[W]=void 0,W=(W+1)%z,ot();q=!1}return{isDraining:function(){return q},enqueue:function(ot){var et;j===z&&(et=q,H(),q=et),O[(W+j)%z]=ot,j++,q||H()}}})();function $(z){var j={},W=0,O=0;return{register:function(q){var H=W++;q.onComplete({rethrow:!0,handler:function(ot){return function(){O--,delete j[H]}}})(),j[H]=q,O++},isEmpty:function(){return O===0},killAll:function(q,H){return function(){if(O===0)return H();var ot=0,et={};function gt(ft){et[ft]=j[ft].kill(q,function(Nt){return function(){delete et[ft],ot--,z.isLeft(Nt)&&z.fromLeft(Nt)&&setTimeout(function(){throw z.fromLeft(Nt)},0),ot===0&&H()}})()}for(var Lt in j)j.hasOwnProperty(Lt)&&(ot++,gt(Lt));return j={},W=0,O=0,function(ft){return new N(o,function(){for(var Nt in et)et.hasOwnProperty(Nt)&&et[Nt]()})}}}}}var E=0,G=1,nt=2,V=3,Q=4,Y=5,X=6;function D(z,j,W){var O=0,q=E,H=W,ot=null,et=null,gt=null,Lt=null,ft=null,Nt=0,kt=0,jt=null,Tt=!0;function Vt(lt){for(var xt,Dt,ht;;)switch(xt=null,Dt=null,ht=null,q){case nt:q=G;try{H=gt(H),Lt===null?gt=null:(gt=Lt._1,Lt=Lt._2)}catch(Qt){q=Y,ot=z.left(Qt),H=null}break;case V:z.isLeft(H)?(q=Y,ot=H,H=null):gt===null?q=Y:(q=nt,H=z.fromRight(H));break;case G:switch(H.tag){case a:gt&&(Lt=new N(f,gt,Lt)),gt=H._2,q=G,H=H._1;break;case e:gt===null?(q=Y,H=z.right(H._1)):(q=nt,H=H._1);break;case o:q=V,H=S(z.left,z.right,H._1);break;case i:q=Q,H=A(z.left,H._1,function(Qt){return function(){O===lt&&(O++,I.enqueue(function(){O===lt+1&&(q=V,H=Qt,Vt(O))}))}});return;case n:q=Y,ot=z.left(H._1),H=null;break;case r:gt===null?ft=new N(f,H,ft,et):ft=new N(f,H,new N(f,new N(h,gt,Lt),ft,et),et),gt=null,Lt=null,q=G,H=H._1;break;case s:Nt++,gt===null?ft=new N(f,H,ft,et):ft=new N(f,H,new N(f,new N(h,gt,Lt),ft,et),et),gt=null,Lt=null,q=G,H=H._1;break;case u:q=V,xt=D(z,j,H._2),j&&j.register(xt),H._1&&xt.run(),H=z.right(xt);break;case c:q=G,H=B(z,j,H._1);break}break;case Y:if(gt=null,Lt=null,ft===null)q=X,H=et||ot||H;else switch(xt=ft._3,ht=ft._1,ft=ft._2,ht.tag){case r:et&&et!==xt&&Nt===0?q=Y:ot&&(q=G,H=ht._2(z.fromLeft(ot)),ot=null);break;case h:et&&et!==xt&&Nt===0||ot?q=Y:(gt=ht._1,Lt=ht._2,q=nt,H=z.fromRight(H));break;case s:Nt--,ot===null&&(Dt=z.fromRight(H),ft=new N(f,new N(m,ht._2,Dt),ft,xt),(et===xt||Nt>0)&&(q=G,H=ht._3(Dt)));break;case m:ft=new N(f,new N(x,H,ot),ft,et),q=G,et&&et!==xt&&Nt===0?H=ht._1.killed(z.fromLeft(et))(ht._2):ot?H=ht._1.failed(z.fromLeft(ot))(ht._2):H=ht._1.completed(z.fromRight(H))(ht._2),ot=null,Nt++;break;case p:Nt++,ft=new N(f,new N(x,H,ot),ft,et),q=G,H=ht._1;break;case x:Nt--,q=Y,H=ht._1,ot=ht._2;break}break;case X:for(var bt in jt)jt.hasOwnProperty(bt)&&(Tt=Tt&&jt[bt].rethrow,k(jt[bt].handler(H)));jt=null,et&&ot?setTimeout(function(){throw z.fromLeft(ot)},0):z.isLeft(H)&&Tt&&setTimeout(function(){if(Tt)throw z.fromLeft(H)},0);return;case E:q=G;break;case Q:return}}function Ft(lt){return function(){if(q===X)return Tt=Tt&&lt.rethrow,lt.handler(H)(),function(){};var xt=kt++;return jt=jt||{},jt[xt]=lt,function(){jt!==null&&delete jt[xt]}}}function vt(lt,xt){return function(){if(q===X)return xt(z.right(void 0))(),function(){};var Dt=Ft({rethrow:!1,handler:function(){return xt(z.right(void 0))}})();switch(q){case E:et=z.left(lt),q=X,H=et,Vt(O);break;case Q:et===null&&(et=z.left(lt)),Nt===0&&(q===Q&&(ft=new N(f,new N(p,H(lt)),ft,et)),q=Y,H=null,ot=null,Vt(++O));break;default:et===null&&(et=z.left(lt)),Nt===0&&(q=Y,H=null,ot=null)}return Dt}}function mt(lt){return function(){var xt=Ft({rethrow:!1,handler:lt})();return q===E&&Vt(O),xt}}return{kill:vt,join:mt,onComplete:Ft,isSuspended:function(){return q===E},run:function(){q===E&&(I.isDraining()?Vt(O):I.enqueue(function(){Vt(O)}))}}}function F(z,j,W,O){var q=0,H={},ot=0,et={},gt=new Error("[ParAff] Early exit"),Lt=null,ft=t;function Nt(Ft,vt,mt){var lt=vt,xt=null,Dt=null,ht=0,bt={},Qt,Bt;t:for(;;)switch(Qt=null,lt.tag){case y:if(lt._3===t&&(Qt=H[lt._1],bt[ht++]=Qt.kill(Ft,function(ie){return function(){ht--,ht===0&&mt(ie)()}})),xt===null)break t;lt=xt._2,Dt===null?xt=null:(xt=Dt._1,Dt=Dt._2);break;case g:lt=lt._2;break;case l:case d:xt&&(Dt=new N(f,xt,Dt)),xt=lt,lt=lt._1;break}if(ht===0)mt(z.right(void 0))();else for(Bt=0,Qt=ht;Bt<Qt;Bt++)bt[Bt]=bt[Bt]();return bt}function kt(Ft,vt,mt){var lt,xt,Dt,ht,bt,Qt;for(z.isLeft(Ft)?(lt=Ft,xt=null):(xt=Ft,lt=null);;){if(Dt=null,ht=null,bt=null,Qt=null,Lt!==null)return;if(vt===null){O(lt||xt)();return}if(vt._3!==t)return;switch(vt.tag){case g:lt===null?(vt._3=z.right(vt._1(z.fromRight(xt))),xt=vt._3):vt._3=lt;break;case l:if(Dt=vt._1._3,ht=vt._2._3,lt){if(vt._3=lt,bt=!0,Qt=ot++,et[Qt]=Nt(gt,lt===Dt?vt._2:vt._1,function(){return function(){delete et[Qt],bt?bt=!1:mt===null?kt(lt,null,null):kt(lt,mt._1,mt._2)}}),bt){bt=!1;return}}else{if(Dt===t||ht===t)return;xt=z.right(z.fromRight(Dt)(z.fromRight(ht))),vt._3=xt}break;case d:if(Dt=vt._1._3,ht=vt._2._3,Dt===t&&z.isLeft(ht)||ht===t&&z.isLeft(Dt))return;if(Dt!==t&&z.isLeft(Dt)&&ht!==t&&z.isLeft(ht))lt=xt===Dt?ht:Dt,xt=null,vt._3=lt;else if(vt._3=xt,bt=!0,Qt=ot++,et[Qt]=Nt(gt,xt===Dt?vt._2:vt._1,function(){return function(){delete et[Qt],bt?bt=!1:mt===null?kt(xt,null,null):kt(xt,mt._1,mt._2)}}),bt){bt=!1;return}break}mt===null?vt=null:(vt=mt._1,mt=mt._2)}}function jt(Ft){return function(vt){return function(){delete H[Ft._1],Ft._3=vt,kt(vt,Ft._2._1,Ft._2._2)}}}function Tt(){var Ft=G,vt=W,mt=null,lt=null,xt,Dt;t:for(;;)switch(xt=null,Dt=null,Ft){case G:switch(vt.tag){case g:mt&&(lt=new N(f,mt,lt)),mt=new N(g,vt._1,t,t),vt=vt._2;break;case l:mt&&(lt=new N(f,mt,lt)),mt=new N(l,t,vt._2,t),vt=vt._1;break;case d:mt&&(lt=new N(f,mt,lt)),mt=new N(d,t,vt._2,t),vt=vt._1;break;default:Dt=q++,Ft=Y,xt=vt,vt=new N(y,Dt,new N(f,mt,lt),t),xt=D(z,j,xt),xt.onComplete({rethrow:!1,handler:jt(vt)})(),H[Dt]=xt,j&&j.register(xt)}break;case Y:if(mt===null)break t;mt._1===t?(mt._1=vt,Ft=G,vt=mt._2,mt._2=t):(mt._2=vt,vt=mt,lt===null?mt=null:(mt=lt._1,lt=lt._2))}for(ft=vt,Dt=0;Dt<q;Dt++)H[Dt].run()}function Vt(Ft,vt){Lt=z.left(Ft);var mt;for(var lt in et)if(et.hasOwnProperty(lt)){mt=et[lt];for(lt in mt)mt.hasOwnProperty(lt)&&mt[lt]()}et=null;var xt=Nt(Ft,ft,vt);return function(Dt){return new N(i,function(ht){return function(){for(var bt in xt)xt.hasOwnProperty(bt)&&xt[bt]();return J}})}}return Tt(),function(Ft){return new N(i,function(vt){return function(){return Vt(Ft,vt)}})}}function B(z,j,W){return new N(i,function(O){return function(){return F(z,j,W,O)}})}return N.EMPTY=t,N.Pure=v(e),N.Throw=v(n),N.Catch=v(r),N.Sync=v(o),N.Async=v(i),N.Bind=v(a),N.Bracket=v(s),N.Fork=v(u),N.Seq=v(c),N.ParMap=v(g),N.ParApply=v(l),N.ParAlt=v(d),N.Fiber=D,N.Supervisor=$,N.Scheduler=I,N.nonCanceler=J,N})();const QC=t=>e=>DC(n=>r=>t({type:n.type,value:n.map(o=>r(o))(n.value),map:n.map}))(e),WC=t=>{const e=t.Bind1(),n=t.Applicative0().pure;return r=>{const o=qm(()=>QC(i=>e.bind(r(i))(o()))(n));return o()}};let qd=null;function OC(){return qd||(typeof document>"u"?null:qd=document.createElement("canvas").getContext("2d"))}const Kg=new Map;function Ud(t,e,n,r,o,i){const a=`${n} ${e}px ${t}`,s=a+"|"+r;if(Kg.has(s))return Kg.get(s);const u=OC();if(!u)return i;u.font=a;const c=o(u.measureText(r)),g=typeof document<"u"?document.fonts:null;if(!g||g.check(a))Kg.set(s,c);else if(g&&g.load)try{g.load(a)}catch{}return c}const HC=(t,e,n,r)=>Ud(t,e,n,r,o=>o.width,-1),$C=(t,e,n,r)=>Ud(t,e,n,r,o=>({ascent:o.actualBoundingBoxAscent,descent:o.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),gu=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Xd=t=>t,Vd={map:t=>e=>{if(e.tag==="MeasureText")return gu("MeasureText",e._1,e._2,n=>t(e._3(n)));if(e.tag==="MeasureInk")return gu("MeasureInk",e._1,e._2,n=>t(e._3(n)));_()}},jg=t=>e=>{const n=HC(t.family,t.size,t.weight,Uo(e));return n<0?rt(un(e).length)*t.size*.62:n},Zg=t=>e=>{const n=$C(t.family,t.size,t.weight,Uo(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},qC=t=>e=>K(st("Bind",{type:"metrics",value:gu("MeasureInk",t,e,Xd),map:Vd.map},n=>K(st("Return",n),ct)),ct),jr=t=>e=>K(st("Bind",{type:"metrics",value:gu("MeasureText",t,e,Xd),map:Vd.map},n=>K(st("Return",n),ct)),ct),Yd=t=>t,Kd=t=>t,_u=t=>t,jd=t=>t,Zd=t=>t,Xt=(t,e,n,r,o)=>({tag:t,_1:e,_2:n,_3:r,_4:o}),th=t=>t,t_=t=>t,UC=t_("BaselineTop"),xn=t_("BaselineMiddle"),XC=t_("BaselineBottom"),xo=th("AlignLeft"),Zr=th("AlignCenter"),Ye=Zd("RoundJoin"),Ra=Zd("MiterJoin"),Ln=jd("ButtCap"),lr=jd("RoundCap"),VC=_u("LayerPolyOut"),YC=_u("LayerPolyIn"),KC=_u("LayerNodeMask"),jC=_u("LayerOverlay"),Qi=Kd("NonZero"),e_=Kd("EvenOdd"),eh=Yd("Normal"),fu=Yd("Difference"),Ne={r:255,g:255,b:255,a:255},Ga=[5],be={map:t=>e=>{if(e.tag==="FillPath")return Xt("FillPath",e._1,e._2,t(e._3));if(e.tag==="StrokePath")return Xt("StrokePath",e._1,e._2,t(e._3));if(e.tag==="FillStrokePath")return Xt("FillStrokePath",e._1,e._2,e._3,t(e._4));if(e.tag==="DrawText")return Xt("DrawText",e._1,t(e._2));if(e.tag==="DrawTextAffine")return Xt("DrawTextAffine",e._1,e._2,t(e._3));if(e.tag==="PushTransform")return Xt("PushTransform",e._1,t(e._2));if(e.tag==="PopTransform")return Xt("PopTransform",t(e._1));if(e.tag==="PushClip")return Xt("PushClip",e._1,e._2,t(e._3));if(e.tag==="PopClip")return Xt("PopClip",t(e._1));if(e.tag==="PushBlend")return Xt("PushBlend",e._1,t(e._2));if(e.tag==="PopBlend")return Xt("PopBlend",t(e._1));if(e.tag==="PushAlpha")return Xt("PushAlpha",e._1,t(e._2));if(e.tag==="PopAlpha")return Xt("PopAlpha",t(e._1));if(e.tag==="PushBlur")return Xt("PushBlur",e._1,t(e._2));if(e.tag==="PopBlur")return Xt("PopBlur",t(e._1));if(e.tag==="PushLayer")return Xt("PushLayer",e._1,t(e._2));if(e.tag==="PopLayer")return Xt("PopLayer",t(e._1));if(e.tag==="SetViewport")return Xt("SetViewport",e._1,t(e._2));if(e.tag==="ClearBackground")return Xt("ClearBackground",e._1,t(e._2));if(e.tag==="BackgroundDots")return Xt("BackgroundDots",e._1,t(e._2));_()}},to={r:26,g:26,b:26,a:255},n_=t=>e=>Math.imul(t,e),Wi=t=>{const e=t+1831565813|0,n=n_(e^e>>>15)(e|1),r=n^(n+n_(n^n>>>7)(n|61)|0),o=r^r>>>14;return{prng:o,value:o<0?(rt(o)+4294967296)/4294967296:rt(o)/4294967296}},Fe=t=>e=>n=>{const r=Wi(n);return{prng:r.prng,value:t+r.value*(e-t)}},r_=t=>e=>b(n=>r=>n_(n^r)(-2048144789))(e)(U(ho)(Bn(t))),ZC=t=>t,nh=t=>t,t3=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},wn=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},rh=t=>e=>n=>{const r=ut.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=ut.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},o_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},e3=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},n3=nh("FlatLevel"),r3=nh("NestedLevel"),i_=ZC("GenieSilhouette"),o3=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const o=Wi(t);return{prng:o.prng,yLift:o.value*n.yJitter*r}},i3=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const o=Wi(t);return{prng:o.prng,dx:(o.value*2-1)*n.xJitter*r}},oh=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,o=tn(r*r+n*n),i=(t.r*t.r-e.r*e.r+o*o)/(2*o),a=tn(t3(0)(t.r*t.r-i*i)),s=t.cx+i*r/o,u=t.cy+i*n/o,c={x:s-a*n/o,y:u+a*r/o},g={x:s+a*n/o,y:u-a*r/o};return o===0||o>t.r+e.r?{x:(t.cx+e.cx)/2,y:t.cy}:c.y<g.y?c:g},Oi=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]},a3=t=>e=>n=>r=>o=>i=>{if(e)return{prng:t,r:o};if(n)return{prng:t,r:o*(1+i.rJitter)};if(r)return{prng:t,r:o*i.smallScale};const a=Wi(t);return{prng:a.prng,r:o*(1+a.value*i.rJitter)}},ih=t=>{const e=wn(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]},s3=t=>e=>n=>{const r=Wi(t),o=e.length;return o===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const i=rh(0)(o-1|0)(de(Vn(r.value*rt(n))));return i>=0&&i<e.length?e[i]:-1})()}},u3=t=>e=>{const n=Wi(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const o=rh(0)(r-1|0)(de(Vn(n.value*rt(r))));return o>=0&&o<e.length?e[o]:-1})()}},ah=t=>{const e=wn(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]},sh=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],uh={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},c3=t=>{const e=wn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,o=t.x+n;return[1,t.x,r,4,t.x,r+.5522847498*e,o-.5522847498*n,r+e,o,r+e,4,o+.5522847498*n,r+e,t.x+t.w,r+.5522847498*e,t.x+t.w,r]},ch=t=>{const e=wn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+t.h+5,o=t.y+e,i=r-e,a=t.x+n;return[1,t.x,o,4,t.x,o-.5522847498*e,a-.5522847498*n,t.y,a,t.y,4,a+.5522847498*n,t.y,t.x+t.w,o-.5522847498*e,t.x+t.w,o,2,t.x+t.w,i,4,t.x+t.w,i+.5522847498*e,a+.5522847498*n,r,a,r,4,a-.5522847498*n,r,t.x,i+.5522847498*e,t.x,i,5]},gh=t=>e=>{const n=e.y+e.h,r=M2(t.rBase*e.h)(e.w/(2*(1+(rt(t.minN)-1)*t.stepRatio))),o=e.w-2*r,i=2*r*t.stepRatio,a=o_(t.minN)(o<=0||i<=0?t.minN:de(Fn(o/i))+1|0),s=a>=3?Yt(1,a-2|0):[],u=s.length,c=Nr(u+1|0,2),g=c<1?[]:Rt(0,c,s),l=u3(t.seed)((()=>{const p=u-c|0;return p<1?s:Rt(p,s.length,s)})()),d=l.idx,f=s3(l.prng)(dt(p=>p!==d,g))(o_(1)(g.length-(_n(ao)(d)(g)?1:0)|0)),h=f.idx,m=a>=2?o/(rt(a)-1):0;return b(p=>x=>{const y=x===h,N=x===d,v=x===0||x===(a-1|0),J=a3(p.prng)(v)(N)(y)(r)(t),k=o3(J.prng)(v)(t)(e.h),S=i3(k.prng)(v)(t)(m);return{prng:S.prng,circles:St(p.circles)({cx:e.x+e3(J.r)(e.w-J.r)((a>=2?r+rt(x)/(rt(a)-1)*o+S.dx:r+0*o+S.dx)+(N?t.heroShift*m:y?-1*t.smallShift*m:0)),cy:n-k.yLift,r:J.r})}})({prng:f.prng,circles:[]})(Yt(0,a-1|0)).circles},_h=t=>e=>{const n=t.length;return Ot(r=>o=>({c:o,p1:(()=>{if(r===0)return{x:o.cx-o.r,y:e};const i=r-1|0;return i>=0&&i<t.length?oh(t[i])(o):{x:o.cx-o.r,y:e}})(),p2:(()=>{if(r===(n-1|0))return{x:o.cx+o.r,y:e};const i=r+1|0;return i>=0&&i<t.length?oh(o)(t[i]):{x:o.cx+o.r,y:e}})()}))(t)},fh=t=>{const e=wn(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]},g3=t=>e=>n=>{const r=Po(e.y-t.cy)(e.x-t.cx),o=Po(n.y-t.cy)(n.x-t.cx),i=o>r?o-r:o+6.283185307179586-r,a=o_(1)(de(us(i/1.5707963267948966))),s=i/rt(a),u=1.3333333333333333*z2(s/4);return Et(Yt(0,a-1|0))(c=>{const g=r+rt(c+1|0)*s,l=t.cx+t.r*Dn(g),d=t.cy+t.r*fn(g),f=r+rt(c)*s;return[4,t.cx+t.r*Dn(f)-u*t.r*fn(f),t.cy+t.r*fn(f)+u*t.r*Dn(f),l+u*t.r*fn(g),d-u*t.r*Dn(g),l,d]})},lh=t=>e=>{const n=t.h*.38,r=_h(gh(uh)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),o=wn(e)(wn(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...Et(r)(i=>g3(i.c)(i.p1)(i.p2)),2,t.x+t.w,t.y+t.h-o,3,t.x+t.w,t.y+t.h,t.x+t.w-o,t.y+t.h,2,t.x+o,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-o,2,r[0].p1.x,r[0].p1.y,5]:Oi(t)(e)},Vo=t=>e=>n=>r=>o=>i=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(o)(i);if(e==="Cylinder"){const a=ch(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);_()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}_()}if(e==="Parallelogram"){const a=ah(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);_()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}_()}if(e==="Diamond"){const a=fh(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);_()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}_()}if(e==="Ellipse"){const a=ih(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);_()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}_()}if(e==="Document"){const a=sh(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);_()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}_()}if(e==="Cloud"){const a=lh(n)(r);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);_()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}_()}return t.drawRoundedRect(n)(r)(o)(i)},_3={fillPath:t=>e=>K(st("Bind",{type:"render",value:Xt("FillPath",t,e,void 0),map:be.map},n=>K(st("Return",n),ct)),ct),strokePath:t=>e=>K(st("Bind",{type:"render",value:Xt("StrokePath",t,e,void 0),map:be.map},n=>K(st("Return",n),ct)),ct),fillStrokePath:t=>e=>n=>K(st("Bind",{type:"render",value:Xt("FillStrokePath",t,e,n,void 0),map:be.map},r=>K(st("Return",r),ct)),ct),drawRoundedRect:t=>e=>n=>r=>{if(n.tag==="Just"){if(r.tag==="Just")return K(st("Bind",{type:"render",value:Xt("FillStrokePath",Oi(t)(e),n._1,r._1,void 0),map:be.map},o=>K(st("Return",o),ct)),ct);if(r.tag==="Nothing")return K(st("Bind",{type:"render",value:Xt("FillPath",Oi(t)(e),n._1,void 0),map:be.map},o=>K(st("Return",o),ct)),ct);_()}if(n.tag==="Nothing"){if(r.tag==="Just")return K(st("Bind",{type:"render",value:Xt("StrokePath",Oi(t)(e),r._1,void 0),map:be.map},o=>K(st("Return",o),ct)),ct);if(r.tag==="Nothing")return K(st("Return",void 0),ct)}_()},drawText:t=>K(st("Bind",{type:"render",value:Xt("DrawText",t,void 0),map:be.map},e=>K(st("Return",e),ct)),ct),drawTextAffine:t=>e=>K(st("Bind",{type:"render",value:Xt("DrawTextAffine",t,e,void 0),map:be.map},n=>K(st("Return",n),ct)),ct),pushTransform:t=>K(st("Bind",{type:"render",value:Xt("PushTransform",t,void 0),map:be.map},e=>K(st("Return",e),ct)),ct),popTransform:K(st("Bind",{type:"render",value:Xt("PopTransform",void 0),map:be.map},t=>K(st("Return",t),ct)),ct),pushBakedTransform:t=>K(st("Bind",{type:"render",value:Xt("PushTransform",t,void 0),map:be.map},e=>K(st("Return",e),ct)),ct),popBakedTransform:K(st("Bind",{type:"render",value:Xt("PopTransform",void 0),map:be.map},t=>K(st("Return",t),ct)),ct),pushClip:t=>e=>K(st("Bind",{type:"render",value:Xt("PushClip",t,e,void 0),map:be.map},n=>K(st("Return",n),ct)),ct),popClip:K(st("Bind",{type:"render",value:Xt("PopClip",void 0),map:be.map},t=>K(st("Return",t),ct)),ct),pushBlend:t=>K(st("Bind",{type:"render",value:Xt("PushBlend",t,void 0),map:be.map},e=>K(st("Return",e),ct)),ct),popBlend:K(st("Bind",{type:"render",value:Xt("PopBlend",void 0),map:be.map},t=>K(st("Return",t),ct)),ct),pushAlpha:t=>K(st("Bind",{type:"render",value:Xt("PushAlpha",t,void 0),map:be.map},e=>K(st("Return",e),ct)),ct),popAlpha:K(st("Bind",{type:"render",value:Xt("PopAlpha",void 0),map:be.map},t=>K(st("Return",t),ct)),ct),pushBlur:t=>K(st("Bind",{type:"render",value:Xt("PushBlur",t,void 0),map:be.map},e=>K(st("Return",e),ct)),ct),popBlur:K(st("Bind",{type:"render",value:Xt("PopBlur",void 0),map:be.map},t=>K(st("Return",t),ct)),ct),pushLayer:t=>K(st("Bind",{type:"render",value:Xt("PushLayer",t,void 0),map:be.map},e=>K(st("Return",e),ct)),ct),popLayer:K(st("Bind",{type:"render",value:Xt("PopLayer",void 0),map:be.map},t=>K(st("Return",t),ct)),ct),setViewport:t=>K(st("Bind",{type:"render",value:Xt("SetViewport",t,void 0),map:be.map},e=>K(st("Return",e),ct)),ct),clearBackground:t=>K(st("Bind",{type:"render",value:Xt("ClearBackground",t,void 0),map:be.map},e=>K(st("Return",e),ct)),ct),backgroundDots:t=>K(st("Bind",{type:"render",value:Xt("BackgroundDots",t,void 0),map:be.map},e=>K(st("Return",e),ct)),ct),measureText:t=>e=>jr(t)(e),measureInk:t=>e=>qC(t)(e),insideTokenStyle:t=>K(st("Return",i_),ct),Monad0:()=>Yg},f3=t=>()=>t.clip("evenodd"),l3=t=>e=>()=>{t.filter=`blur(${e}px)`},d3=t=>e=>()=>{const n=e>0?t.canvas.width/e:1;t.setTransform(n,0,0,n,0,0)},h3=t=>e=>n=>r=>o=>()=>{const i=e>0?t.canvas.width/e:1;t.setTransform(i*n,0,0,i*n,i*r,i*o)},p3=t=>e=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(e.tile,.001))),r=Math.max(2,Math.round(e.tile*n)),o=document.createElement("canvas");o.width=r,o.height=r;const i=o.getContext("2d");i.scale(n,n),i.fillStyle=e.bgCss,i.fillRect(0,0,e.tile,e.tile),i.fillStyle=e.dotCss,i.beginPath(),i.arc(e.tile/2,e.tile/2,e.dotR,0,2*Math.PI),i.fill();const a=t.createPattern(o,"repeat");a&&typeof a.setTransform=="function"&&a.setTransform(new DOMMatrix().translateSelf(e.ox,e.oy).scaleSelf(1/n,1/n)),t.save(),t.fillStyle=a,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},a_=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},s_=t=>e=>n=>{const r=e.stroke;return()=>{const o=r.value,i=oy(t)(n);if(o!==n)return i(),e.stroke.value=n}},m3=t=>e=>n=>{const r=e.font;return()=>{const o=r.value,i=ly(t)(n);if(o!==n)return i(),e.font.value=n}},Da=t=>e=>n=>{const r=e.fill;return()=>{const o=r.value,i=ry(t)(n);if(o!==n)return i(),e.fill.value=n}},lu=t=>e=>{const n=e.length,r=i=>{if(i>=n)return()=>{};const a=i>=0&&i<e.length?e[i]:0;if(a===1){const s=qf(t)((()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})()),u=r(i+3|0);return()=>(s(),u())}if(a===2){const s=oa(t)((()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})()),u=r(i+3|0);return()=>(s(),u())}if(a===3){const s=ia(t)({cpx:(()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})(),cpy:(()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=i+3|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=i+4|0;return c>=0&&c<e.length?e[c]:0})()}),u=r(i+5|0);return()=>(s(),u())}if(a===4){const s=hy(t)({cp1x:(()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})(),cp1y:(()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})(),cp2x:(()=>{const c=i+3|0;return c>=0&&c<e.length?e[c]:0})(),cp2y:(()=>{const c=i+4|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=i+5|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=i+6|0;return c>=0&&c<e.length?e[c]:0})()}),u=r(i+7|0);return()=>(s(),u())}if(a===5){const s=Uf(t),u=r(i+1|0);return()=>(s(),u())}return()=>{}},o=$f(t);return()=>(o(),r(0)())},y3=t=>e=>n=>r=>o=>i=>{const a=a_(i)(a_(r/2)(o/2)),s=qf(t)(e+a)(n);return()=>(s(),oa(t)(e+r-a)(n)(),ia(t)({cpx:e+r,cpy:n,x:e+r,y:n+a})(),oa(t)(e+r)(n+o-a)(),ia(t)({cpx:e+r,cpy:n+o,x:e+r-a,y:n+o})(),oa(t)(e+a)(n+o)(),ia(t)({cpx:e,cpy:n+o,x:e,y:n+o-a})(),oa(t)(e)(n+a)(),ia(t)({cpx:e,cpy:n,x:e+a,y:n})(),Uf(t)())},x3=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),dh=t=>e=>{const n=cy(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=x3();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0},groupAlpha:{value:1},alphaSaves:{value:[]}}}},w3={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},N3=t=>ae(t.weight)+" "+Eo(t.size)+"px "+t.family,Rr=t=>{const e=Eo(rt(t.a)/255);return t.a>=255?"rgb("+ae(t.r)+","+ae(t.g)+","+ae(t.b)+")":"rgba("+ae(t.r)+","+ae(t.g)+","+ae(t.b)+","+e+")"},T3=t=>e=>n=>r=>{const o=br(t);return()=>(o(),d3(t)(e.width)(),Da(t)(n)(Rr(r))(),uy(t)({x:0,y:0,width:e.width,height:e.height})(),Jr(t)(),n.font.value="",n.fill.value="",n.stroke.value="")},v3=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",p3(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:Rr(n.bgColor),dotCss:Rr(n.dotColor),tile:n.tile,dotR:n.dotRadius,ox:n.origin.x,oy:n.origin.y})())},b3=t=>e=>n=>r=>{const o=Da(t)(e)(Rr(r));return()=>(o(),lu(t)(n)(),vc(t)())},J3=t=>e=>n=>r=>o=>{const i=Da(t)(e)(Rr(r));return()=>(i(),s_(t)(e)(Rr(o.color))(),xc(t)(o.width)(),Rc(t)((()=>{if(o.lineJoin==="RoundJoin")return Lc;if(o.lineJoin==="BevelJoin")return kc;if(o.lineJoin==="MiterJoin")return Sc;_()})())(),Gc(t)((()=>{if(o.lineCap==="ButtCap")return Pc;if(o.lineCap==="RoundCap")return Ec;if(o.lineCap==="SquareCap")return Ac;_()})())(),lu(t)(n)(),vc(t)(),Tc(t)())},C3=t=>e=>n=>r=>o=>i=>{const a=$f(t);return()=>{if(a(),y3(t)(n.x)(n.y)(n.w)(n.h)(r)(),o.tag==="Just"?(Da(t)(e)(Rr(o._1.color))(),vc(t)()):o.tag==="Nothing"||_(),i.tag==="Just")return s_(t)(e)(Rr(i._1.color))(),xc(t)(i._1.width)(),Rc(t)((()=>{if(i._1.lineJoin==="RoundJoin")return Lc;if(i._1.lineJoin==="BevelJoin")return kc;if(i._1.lineJoin==="MiterJoin")return Sc;_()})())(),Gc(t)((()=>{if(i._1.lineCap==="ButtCap")return Pc;if(i._1.lineCap==="RoundCap")return Ec;if(i._1.lineCap==="SquareCap")return Ac;_()})())(),Tc(t)();i.tag!=="Nothing"&&_()}},k3=t=>e=>n=>r=>{const o=s_(t)(e)(Rr(r.color));return()=>(o(),xc(t)(r.width)(),Rc(t)((()=>{if(r.lineJoin==="RoundJoin")return Lc;if(r.lineJoin==="BevelJoin")return kc;if(r.lineJoin==="MiterJoin")return Sc;_()})())(),Gc(t)((()=>{if(r.lineCap==="ButtCap")return Pc;if(r.lineCap==="RoundCap")return Ec;if(r.lineCap==="SquareCap")return Ac;_()})())(),lu(t)(n)(),Tc(t)())},hh=t=>e=>n=>{const r=Da(t)(e)(Rr(n.color));return()=>(r(),m3(t)(e)(N3(n.font))(),Cy(t)((()=>{if(n.align==="AlignLeft")return wy;if(n.align==="AlignCenter")return Ty;if(n.align==="AlignRight")return Ny;_()})())(),Jy(t)((()=>{if(n.baseline==="BaselineTop")return py;if(n.baseline==="BaselineMiddle")return my;if(n.baseline==="BaselineAlphabetic")return yy;if(n.baseline==="BaselineBottom")return xy;_()})())(),dy(t)(n.content)(n.x)(n.y)())},ph={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),a=o();return i(a)}},Functor0:()=>w3},L3={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>ph},S3=t=>e=>n=>{const r=a_(e.width/n.vw)(e.height/n.vh);return h3(t)(e.width)(r)((e.width-n.vw*r)/2-n.vx*r)((e.height-n.vh*r)/2-n.vy*r)},E3={pure:t=>e=>()=>t,Apply0:()=>ph},mh={Applicative0:()=>E3,Bind1:()=>L3},u_={fillPath:t=>e=>n=>{const r=b3(n.ctx)(n.styleCache)(t)(e.color),o=n.maskDepth;return()=>{if(o.value===0)return r()}},strokePath:t=>e=>n=>{const r=k3(n.ctx)(n.styleCache)(t)(e),o=n.maskDepth;return()=>{if(o.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const o=J3(r.ctx)(r.styleCache)(t)(e.color)(n),i=r.maskDepth;return()=>{if(i.value===0)return o()}},drawRoundedRect:t=>e=>n=>r=>o=>{const i=C3(o.ctx)(o.styleCache)(t)(e)(n)(r),a=o.maskDepth;return()=>{if(a.value===0)return i()}},drawText:t=>e=>{const n=hh(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=br(n.ctx),o=n.maskDepth;return()=>{if(o.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",gy(n.ctx)(t)(),hh(n.ctx)(n.styleCache)(e)(),Jr(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=br(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Xf(e.ctx)({translateX:t.tx,translateY:t.ty})(),fs(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBakedTransform:t=>e=>{const n=br(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Xf(e.ctx)({translateX:t.tx,translateY:t.ty})(),fs(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushClip:t=>e=>n=>{const r=br(n.ctx),o=n.maskDepth;return()=>{if(o.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",lu(n.ctx)(t)(),e==="NonZero")return sy(n.ctx)();if(e==="EvenOdd")return f3(n.ctx)();_()}}},popClip:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBlend:t=>e=>{const n=br(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 Yf(e.ctx)(vy)();if(t==="Difference")return Yf(e.ctx)(by)();_()}}},popBlend:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushAlpha:t=>e=>{const n=br(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="";const o=e.groupAlpha.value,i=e.alphaSaves.value;e.alphaSaves.value=[...i,o];const a=o*t;return e.groupAlpha.value=a,ay(e.ctx)(a)()}}},popAlpha:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0){e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="";const r=t.alphaSaves.value,o=zr(r);if(o.tag==="Just")return t.alphaSaves.value=o._1.init,t.groupAlpha.value=o._1.last;if(o.tag==="Nothing")return t.groupAlpha.value=1;_()}}},pushBlur:t=>e=>{const n=br(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="";const o=l3(e.ctx)(t);if(t>=.01)return o()}}},popBlur:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushLayer:t=>e=>{if(t==="LayerNodeMask"){const n=e.maskDepth;return()=>{const r=n.value;n.value=r+1|0}}return()=>{}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;if(n>0)return t.maskDepth.value=r}},setViewport:t=>e=>{const n=S3(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=T3(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=v3(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=jg(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Zg(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>i_,Monad0:()=>mh},A3=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Fa=t=>e=>n=>{const r=A3(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},c_=t=>{const e=at.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;_()})(),r=at.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;_()},P3=t=>{if(t.tag==="Retracted")return{lo:0,hi:0};if(t.tag==="Extended")return{lo:0,hi:1};if(t.tag==="Extending"){if(t._1==="ExtendFromSource")return{lo:0,hi:c_(t._2)};if(t._1==="ExtendFromTarget")return{lo:1-t._2,hi:1};_()}if(t.tag==="Retracting"){if(t._1==="FromSource")return{lo:t._2,hi:1};if(t._1==="FromTarget")return{lo:0,hi:1-t._2};if(t._1==="FromBoth")return{lo:t._2/2,hi:1-t._2/2}}_()},wo=t=>{if(t.tag==="Hidden")return{alpha:0,scale:1};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:c_(t._1),scale:1};if(t.tag==="PloppingOut")return{alpha:c_(1-t._1),scale:1};_()};function R3(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function G3(t){const e=t.length,n=new Array(e);for(let r=0;r<e;r++){const o=t[r],i=t[(r+1)%e];n[r]={a:o,b:i,len:R3(o,i)}}return n}function D3(t,e,n){let r=0;for(let o=0;o<t.length;o++){const i=t[o],a=r,s=a+i.len;if(n<=s){const u=i.len>1e-6?(n-a)/i.len:0;return{x:i.a.x+(i.b.x-i.a.x)*u,y:i.a.y+(i.b.y-i.a.y)*u}}r=s}return e.length>0?e[e.length-1]:{x:0,y:0}}function yh(t,e){if(e.length===0)return[];const n=G3(e);let r=0;for(let i=0;i<n.length;i++)r+=n[i].len;const o=new Array(t);for(let i=0;i<t;i++)o[i]=D3(n,e,i*r/t);return o}function F3(t,e){const n=e.length;if(n===0)return e;const r=(t%n+n)%n|0,o=new Array(n);for(let i=0;i<n;i++)o[i]=e[(i+r)%n];return o}function I3(t,e){const n=e.length;if(n===0)return e;let r=0,o=1/0;for(let i=0;i<n;i++){let a=0;for(let s=0;s<n;s++){const u=t[s]||{x:0,y:0},c=e[(s+i)%n]||{x:0,y:0},g=u.x-c.x,l=u.y-c.y;a+=g*g+l*l}a<o&&(o=a,r=i)}return F3(r,e)}const xh=t=>e=>n=>{const r=yh(t,e),o=yh(t,n),i=I3(r,o);return{from:r,to:i}};function wh(t){const e=t.length;if(e===0)return{x:0,y:0};let n=0,r=0;for(let o=0;o<e;o++)n+=t[o].x,r+=t[o].y;return{x:n/e,y:r/e}}function B3(t,e){const n=e.x-t.x,r=e.y-t.y,o=Math.sqrt(n*n+r*r);return o<=1e-4?{x:1,y:0}:{x:n/o,y:r/o}}function M3(t,e){const n=e.length;if(n===0)return e;const r=new Array(n);for(let o=0;o<n;o++){const i=e[((o-1)%n+n)%n],a=e[((o+1)%n+n)%n],s=e[o];r[o]={x:s.x+((i.x+a.x)/2-s.x)*t,y:s.y+((i.y+a.y)/2-s.y)*t}}return r}function z3(t){return t<0?0:t>1?1:t}const Nh=t=>e=>n=>r=>{const o=e.length;if(o===0)return[];const i=wh(e),a=wh(n),s=B3(i,a),u=new Array(o);let c=1/0,g=-1/0;for(let f=0;f<o;f++){const h=e[f],m=(h.x-i.x)*s.x+(h.y-i.y)*s.y;u[f]=m,m<c&&(c=m),m>g&&(g=m)}const l=g-c;let d=new Array(o);for(let f=0;f<o;f++){const h=e[f],m=n[f];if(m===void 0){d[f]=h;continue}const p=l<=1e-4?0:r.maxDelay*(1-(u[f]-c)/l),x=Math.max(1e-4,1-p),y=z3((t-p)/x),N=y*y*(3-2*y);d[f]={x:h.x+(m.x-h.x)*N,y:h.y+(m.y-h.y)*N}}for(let f=0;f<r.smoothPasses;f++)d=M3(.5,d);return d},Th=(t,e)=>({tag:t,_1:e}),vh=(t,e)=>({tag:t,_1:e}),Je=(t,e,n)=>({tag:t,_1:e,_2:n}),bh=t=>t,Ia=(t,e)=>({tag:t,_1:e}),Ba=(t,e)=>({tag:t,_1:e}),du=t=>t,hu=(t,e)=>({tag:t,_1:e}),Pe=(t,e,n)=>({tag:t,_1:e,_2:n}),eo=(t,e)=>({tag:t,_1:e}),Ma=(t,e)=>({tag:t,_1:e}),Jh=(t,e)=>({tag:t,_1:e}),Ch=t=>t,kh=(t,e)=>({tag:t,_1:e}),Yo=(t,e,n)=>({tag:t,_1:e,_2:n}),Lh=t=>t,Q3=t=>t,Ko=Lh("NormalTransform"),W3=Lh("BakedTransform"),Sh=Ch("TokenOutside"),Eh=Ch("TokenInside"),Hi=Ma("PlainText"),Ah=eo("FrameTitle"),O3=eo("Watermark"),H3=du("NodeShadow"),$3=du("NodeDoorwayFrame"),g_=du("NodeBody"),q3=du("NodeInversion"),__=bh("LabelsShown"),za=bh("LabelsHidden"),rr={map:t=>e=>{if(e.tag==="BeginFrame")return Pe("BeginFrame",e._1,t(e._2));if(e.tag==="EndFrame")return Pe("EndFrame",t(e._1));if(e.tag==="BeginGroup")return Pe("BeginGroup",e._1,t(e._2));if(e.tag==="EndGroup")return Pe("EndGroup",e._1,t(e._2));if(e.tag==="Background")return Pe("Background",e._1,t(e._2));if(e.tag==="Overlay")return Pe("Overlay",e._1,t(e._2));if(e.tag==="Node")return Pe("Node",e._1,t(e._2));if(e.tag==="Edge")return Pe("Edge",e._1,t(e._2));if(e.tag==="Text")return Pe("Text",e._1,t(e._2));if(e.tag==="Token")return Pe("Token",e._1,t(e._2));if(e.tag==="AskInsideTokenStyle")return Pe("AskInsideTokenStyle",e._1,n=>t(e._2(n)));_()}},Ph=t=>e=>jr(t)(e),U3=t=>{const e=t.Bind1().Apply0().Functor0(),n=WC(t);return r=>o=>n(zC()()()({scene:i=>{if(i.tag==="BeginFrame"){const a=i._2;return e.map(s=>a)(r.beginFrame(i._1))}if(i.tag==="EndFrame"){const a=i._1;return e.map(s=>a)(r.endFrame)}if(i.tag==="BeginGroup"){const a=i._2;return e.map(s=>a)(r.beginGroup(i._1))}if(i.tag==="EndGroup"){const a=i._2;return e.map(s=>a)(r.endGroup(i._1))}if(i.tag==="Background"){const a=i._2;return e.map(s=>a)(r.background(i._1))}if(i.tag==="Overlay"){const a=i._2;return e.map(s=>a)(r.overlay(i._1))}if(i.tag==="Node"){const a=i._2;return e.map(s=>a)(r.node(i._1))}if(i.tag==="Edge"){const a=i._2;return e.map(s=>a)(r.edge(i._1))}if(i.tag==="Text"){const a=i._2;return e.map(s=>a)(r.text(i._1))}if(i.tag==="Token"){const a=i._2;return e.map(s=>a)(r.token(i._1))}if(i.tag==="AskInsideTokenStyle")return e.map(i._2)(r.insideTokenStyle(i._1));_()},metrics:i=>{if(i.tag==="MeasureText")return e.map(i._3)(r.measureText(i._1)(i._2));if(i.tag==="MeasureInk")return e.map(i._3)(r.measureInk(i._1)(i._2));_()}}))(o)},X3=t=>K(st("Bind",{type:"scene",value:Pe("AskInsideTokenStyle",t,Q3),map:rr.map},e=>K(st("Return",e),ct)),ct),Rh=t=>K(st("Bind",{type:"scene",value:Pe("Background",t,void 0),map:rr.map},e=>K(st("Return",e),ct)),ct),Gh=t=>K(st("Bind",{type:"scene",value:Pe("Edge",t,void 0),map:rr.map},e=>K(st("Return",e),ct)),ct),Qa=t=>K(st("Bind",{type:"scene",value:Pe("Node",t,void 0),map:rr.map},e=>K(st("Return",e),ct)),ct),pu=t=>K(st("Bind",{type:"scene",value:Pe("Overlay",t,void 0),map:rr.map},e=>K(st("Return",e),ct)),ct),jo=t=>K(st("Bind",{type:"scene",value:Pe("Text",t,void 0),map:rr.map},e=>K(st("Return",e),ct)),ct),Dh=t=>K(st("Bind",{type:"scene",value:Pe("Token",t,void 0),map:rr.map},e=>K(st("Return",e),ct)),ct),V3=t=>e=>K(st("Bind",{type:"scene",value:Pe("BeginFrame",t,void 0),map:rr.map},n=>K(st("Return",n),ct)),tt("CatCons",()=>K(e._1,(()=>{if(e._2.tag==="CatNil")return tt("CatCons",()=>K(st("Bind",{type:"scene",value:Pe("EndFrame",void 0),map:rr.map},n=>K(st("Return",n),ct)),ct),Z(R,R));if(e._2.tag==="CatCons")return tt("CatCons",e._2._1,Z(e._2._2._1,yt("Cons",tt("CatCons",()=>K(st("Bind",{type:"scene",value:Pe("EndFrame",void 0),map:rr.map},n=>K(st("Return",n),ct)),ct),Z(R,R)),e._2._2._2)));_()})()),Z(R,R))),Ue=t=>e=>K(st("Bind",{type:"scene",value:Pe("BeginGroup",t,void 0),map:rr.map},n=>K(st("Return",n),ct)),tt("CatCons",()=>{const n=()=>K(st("Bind",{type:"scene",value:Pe("EndGroup",t,void 0),map:rr.map},r=>K(st("Return",r),ct)),ct);return K(e._1,(()=>{if(e._2.tag==="CatNil")return tt("CatCons",n,Z(R,R));if(e._2.tag==="CatCons")return tt("CatCons",e._2._1,Z(e._2._2._1,yt("Cons",tt("CatCons",n,Z(R,R)),e._2._2._2)));_()})())},Z(R,R))),Gr=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},Fh=b(ur)(0),Ih=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},Y3=b(t=>e=>t+e.len)(0),Bh=t=>{const e=At(n=>w,n=>r=>T("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,...Et(Rt(1,t.length,t))(n=>[2,n.x,n.y]),5];_()},K3=t=>e=>{const n=Gr(e)(Gr(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]},j3=t=>{const e=At(n=>w,n=>r=>T("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,...Et(e._1.tail)(n=>[2,n.x,n.y])];_()},Zo=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return ch(e);if(t.shape==="Parallelogram")return ah(e);if(t.shape==="Diamond")return fh(e);if(t.shape==="Ellipse")return ih(e);if(t.shape==="Document")return sh(e);if(t.shape==="Cloud")return lh(e)(7);if(t.shape==="Rectangle")return K3(e)(7);_()},Ie=t=>e=>n=>U(r=>{const o=rt(r)/rt(n);return{x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o}})(Yt(0,n-1|0)),Z3=t=>{const e=wn(t.w*.18)(t.h*.6);return[...Ie({x:t.x+e,y:t.y})({x:t.x+t.w,y:t.y})(16),...Ie({x:t.x+t.w,y:t.y})({x:t.x+t.w-e,y:t.y+t.h})(16),...Ie({x:t.x+t.w-e,y:t.y+t.h})({x:t.x,y:t.y+t.h})(16),...Ie({x:t.x,y:t.y+t.h})({x:t.x+e,y:t.y})(16)]},f_=t=>e=>{const n=Gr(t)(Gr(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}},l_=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return tn(r*r+n*n)},tk=t=>$e(e=>n=>({a:e,b:n,len:l_(e)(n)}),t,Rt(1,t.length,t)),ek=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?T("Just",e[n]):w,o=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];_()})(),i=0<e.length?T("Just",e[0]):w,a=(()=>{if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return{x:0,y:0};_()})(),s=e.length;return s<3?e:[a,...Et(Yt(1,s-2|0))(u=>{const c=u+1|0,g=c>=0&&c<e.length?T("Just",e[c]):w,l=u>=0&&u<e.length?T("Just",e[u]):w,d=u-1|0,f=d>=0&&d<e.length?T("Just",e[d]):w;if(f.tag==="Just"&&l.tag==="Just"&&g.tag==="Just"){const h=l._1,m=l_(h)(g._1),p=l_(f._1)(h),x=Gr(t)(m/2),y=Gr(t)(p/2),N=m>0?x/m:0,v=h.x+(g._1.x-h.x)*N,J=h.y+(g._1.y-h.y)*N,k=p>0?y/p:0,S=h.x+(f._1.x-h.x)*k,A=h.y+(f._1.y-h.y)*k;return U(I=>{const $=rt(I)/rt(10),E=1-$;return{x:E*E*S+2*E*$*h.x+$*$*v,y:E*E*A+2*E*$*h.y+$*$*J}})(Yt(0,10))}return[]}),...o]},nk=t=>e=>n=>r=>o=>U(i=>{const a=rt(i)/rt(o),s=1-a,u=a*a*a,c=3*s*a*a,g=3*s*s*a,l=s*s*s;return{x:l*t.x+g*e.x+c*n.x+u*r.x,y:l*t.y+g*e.y+c*n.y+u*r.y}})(Yt(0,o-1|0)),rk=t=>[...Ie({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...Ie({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...nk({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),...Ie({x:t.x,y:t.y+t.h*.85})({x:t.x,y:t.y})(12)],Mh=t=>e=>U(n=>{const r=6.283185307179586*rt(n)/rt(64);return{x:t.x+e*Dn(r),y:t.y+e*fn(r)}})(Yt(0,63)),zh=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]},ok=t=>{const e=t.y+t.h/2,n=wn(t.h*.4)(t.w*.2);return[...Ie({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...Ie({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...Ie({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...Ie({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...Ie({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...Ie({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},d_=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:Fh(U(n=>n.x)(t))/rt(e),y:Fh(U(n=>n.y)(t))/rt(e)}},mu=t=>e=>n=>r=>o=>U(i=>{const a=n+(r-n)*(rt(i)/rt(o));return{x:t.x+e*Dn(a),y:t.y+e*fn(a)}})(Yt(0,o-1|0)),h_=t=>e=>{const n=Gr(t)(Gr(e.w/2)(e.h/2));return[...Ie({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...mu({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...Ie({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...mu({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...Ie({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...mu({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...Ie({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...mu({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},yu=t=>e=>n=>r=>o=>i=>U(a=>{const s=r+(o-r)*(rt(a)/rt(i));return{x:t.x+e*Dn(s),y:t.y+n*fn(s)}})(Yt(0,i-1|0)),ik=t=>{const e=t.h*.38;return[...Et(_h(gh(uh)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=Po(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),o=Po(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return yu({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(o)(r>o?r:r+6.283185307179586)(16)}),...Ie({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...Ie({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...Ie({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},ak=t=>{const e=Gr(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,o=t.y+t.h+5-e-2,i=t.x+n;return[...yu({x:i,y:r})(n)(e)(3.141592653589793)(6.283185307179586)(24),...Ie({x:t.x+t.w,y:r})({x:t.x+t.w,y:o})(12),...yu({x:i,y:o})(n)(e)(0)(3.141592653589793)(24),...Ie({x:t.x,y:o})({x:t.x,y:r})(12)]},ti=t=>e=>e.shape==="Cylinder"?ak(e):e.shape==="Parallelogram"?Z3(e):e.shape==="Diamond"?ok(e):e.shape==="Ellipse"?h_(wn(e.w)(e.h)/2)(e):e.shape==="Document"?rk(e):e.shape==="Cloud"?ik(e):h_(t)(e),sk=t=>{const e=Gr(t.h*.075)(t.w*.075),n=t.w/2;return yu({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},uk=t=>e=>n=>b(r=>o=>{const i=r.pos+o.len,a=n<i?(n-r.pos)/o.len:1,s={x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a},u=e>r.pos?(e-r.pos)/o.len:0,c={x:o.a.x+(o.b.x-o.a.x)*u,y:o.a.y+(o.b.y-o.a.y)*u},g=r.points.length-1|0,l=g>=0&&g<r.points.length?(()=>{const d=r.points[g].x-c.x;return(d<0?-d<1e-4:d<1e-4)&&(()=>{const f=r.points[g].y-c.y;return f<0?-f<1e-4:f<1e-4})()})()?St(r.points)(s):[...r.points,c,s]:[c,s];return o.len<=0||i<=e||r.pos>=n?{...r,pos:i}:{pos:i,points:l}})({pos:0,points:[]})(t).points,ck=t=>e=>n=>{const r=At(o=>w,o=>i=>T("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const o=tk(t),i=Y3(o),a=Ih(0)(i)(e*i),s=Ih(0)(i)(n*i);return s<=a?[]:uk(o)(a)(s)}_()},gk=t=>e=>n=>r=>{const o=r.x-n.x,i=r.y-n.y,a=e.x-t.x,s=e.y-t.y,u=n.x-t.x,c=n.y-t.y,g=a*i-s*o,l=(u*i-c*o)/g,d=(u*s-c*a)/g;return(g<0?-g<1e-9:g<1e-9)?w:l>=0&&l<=1&&d>=0&&d<=1?T("Just",l):w},_k=t=>e=>n=>{const r=Gt(o=>i=>at.compare(o.t)(i.t))(wt(o=>{const i=gk(e)(n)(o._1)(o._2);return i.tag==="Just"?T("Just",{t:i._1,p:{x:e.x+(n.x-e.x)*i._1,y:e.y+(n.y-e.y)*i._1}}):w})($e(vn,t,[...Rt(1,t.length,t),...Rt(0,1,t)])));return 0<r.length?T("Just",r[0].p):w},Qh=t=>e=>{const n=zr(e);if(n.tag==="Nothing")return e;if(n.tag==="Just"){const r=n._1.init.length-1|0;if(r>=0&&r<n._1.init.length){const o=_k(t)(n._1.init[r])(n._1.last);if(o.tag==="Just")return St(n._1.init)(o._1);if(o.tag==="Nothing")return e;_()}return e}_()},No=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},p_=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},fk=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},lk=t=>e=>{const n=No(0)(t.y+4-e.y)+No(0)(e.y+e.h-(t.y+t.h-4)),r=No(0)(t.x+4-e.x)+No(0)(e.x+e.w-(t.x+t.w-4));return r*e.h+n*e.w+r*n},dk=t=>e=>{const n=t.y+t.h-6,r=t.y+6,o=t.x+14,i=t.x+t.w-14,a=b(No)(0)(U(s=>o-10<s.x+s.w+12&&i+10>s.x-12&&r-10<s.y+s.h+12&&n+10>s.y-12?p_((s.x+s.w+12-(o-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+a*.7071067811865476,y:t.y-a*.7071067811865476}},hk=t=>e=>{const n=p_(t.x+t.w)(e.x+e.w)-No(t.x)(e.x),r=p_(t.y+t.h)(e.y+e.h)-No(t.y)(e.y);return t.x<e.x+e.w&&t.x+t.w>e.x&&t.y<e.y+e.h&&t.y+t.h>e.y?n*r:0},Wh=t=>e=>n=>r=>{const o=t+4,i=No(0)(e-8),a=o+i-n;return n<=i?fk(o)(a)(r):t+(e-n)/2},m_=t=>e=>({...e,x:Wh(t.x)(t.w)(e.w)(e.x),y:Wh(t.y)(t.h)(e.h)(e.y)}),pk=t=>{const e=2*t.token.x-t.rect.x-t.rect.w,n=t.token.y-t.rect.h/2,r=t.token.x-t.rect.w/2,o=2*t.token.y-t.rect.y-t.rect.h;return[{...t.rect,x:t.rect.x,y:t.rect.y},{...t.rect,x:e,y:t.rect.y},{...t.rect,x:t.rect.x,y:o},{...t.rect,x:e,y:o},{...t.rect,x:t.rect.x,y:n},{...t.rect,x:e,y:n},{...t.rect,x:r,y:t.rect.y},{...t.rect,x:r,y:o}]},mk=t=>e=>n=>r=>o=>{const i=o.y+o.h/2-n.token.y,a=o.y-r.y;return(()=>{const s=o.x+o.w/2-n.token.x,u=o.x-r.x;return 1e6*lk(t)(o)+1e4*b(c=>g=>c+hk(o)(g))(0)(e)+.05*(u*u+a*a)+.01*(s*s+i*i)})()+(o.y>n.token.y?100:0)},yk=t=>e=>n=>r=>{const o=a=>{const s=m_(t)(a);return{rect:s,score:mk(t)(e)(n)(r)(s)}},i=At(a=>w,a=>s=>T("Just",{head:a,tail:s}),[r,n.rect,...pk(n)]);if(i.tag==="Nothing")return m_(t)(r);if(i.tag==="Just")return b(a=>s=>{const u=o(s);return u.score<a.score?u:a})(o(i._1.head))(i._1.tail).rect;_()},xk=t=>e=>n=>b(r=>o=>{const i=dk(o.rect)(r.obstacles),a=i.x>=t.x+4&&i.y>=t.y+4&&i.x+i.w<=t.x+t.w-4&&i.y+i.h<=t.y+t.h-4?i:yk(t)(r.obstacles)(o)(i);return{acc:it(P)(o.id)(a)(r.acc),obstacles:St(r.obstacles)(a)}})({acc:M,obstacles:e})(n).acc,y_=t=>t,no=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},ei=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},wk=yi(fc)(Mt),Nk=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Tk=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},Oh=y_("SegMove"),vk=y_("SegLine"),bk=y_("SegQuad"),Hh={offset:.4,passes:1,rMax:1.5},$h=t=>de(Vn(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,xu=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},wu=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},ro=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},Wa=(()=>{const t=b(e=>n=>((e*31|0)+de(Vn(n.x*100))|0)+de(Vn(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),Jk=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const o=n,i=r,a=o>=0&&o<t.length?T("Just",t[o]):w;if(a.tag==="Nothing"){n=t.length;continue}if(a.tag==="Just"){if(a._1===1){const s={x:(()=>{const u=o+1|0;return u>=0&&u<t.length?t[u]:0})(),y:(()=>{const u=o+2|0;return u>=0&&u<t.length?t[u]:0})()};e.push({kind:Oh,m:i,c:i,p:s,len:0}),r=s,n=o+3|0;continue}if(a._1===2){const s={x:(()=>{const g=o+1|0;return g>=0&&g<t.length?t[g]:0})(),y:(()=>{const g=o+2|0;return g>=0&&g<t.length?t[g]:0})()},u=s.x-i.x,c=s.y-i.y;e.push({kind:vk,m:i,c:i,p:s,len:tn(u*u+c*c)}),r=s,n=o+3|0;continue}if(a._1===3){const s={x:(()=>{const g=o+3|0;return g>=0&&g<t.length?t[g]:0})(),y:(()=>{const g=o+4|0;return g>=0&&g<t.length?t[g]:0})()},u=s.x-i.x,c=s.y-i.y;e.push({kind:bk,m:i,c:{x:(()=>{const g=o+1|0;return g>=0&&g<t.length?t[g]:0})(),y:(()=>{const g=o+2|0;return g>=0&&g<t.length?t[g]:0})()},p:s,len:tn(u*u+c*c)*1.05}),r=s,n=o+5|0;continue}if(a._1===5){e.push({kind:Oh,m:i,c:i,p:i,len:0}),n=o+1|0;continue}n=t.length;continue}_()}return e},Ck=t=>e=>{const n=e.length-1|0,r=n<1?[]:Rt(0,n,e),o=(()=>{const a=r.length-1|0;return a>=0&&a<r.length?T("Just",r[a]):w})(),i=e.length-1|0;if(i>=0&&i<e.length&&o.tag==="Just"){const a=e[i].y-o._1.y,s=e[i].x-o._1.x,u=tn(s*s+a*a);return u<=1e-4?e:St((()=>{const c=e.length-1|0;return c<1?[]:Rt(0,c,e)})())({x:e[i].x+s/u*t,y:e[i].y+a/u*t})}return e},kk=t=>e=>n=>re(b(r=>o=>{const i=Fe(0)(t)(r.prng),a=Fe(0)(6.283185307179586)(i.prng);return{prng:a.prng,out:[{x:o.x+i.value*Dn(a.value),y:o.y+i.value*fn(a.value)},...r.out]}})({prng:e,out:[]})(n).out),Lk=t=>e=>n=>{if(e.kind==="SegMove")return wu(t)(e.p);if(e.kind==="SegLine")return ro(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 ro(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});_()},Sk=t=>e=>{if(e.kind==="SegMove")return wu(t)(e.p);if(e.kind==="SegLine")return ro(t)(e.p);if(e.kind==="SegQuad")return xu(t)(e.c)(e.p);_()},qh=t=>e=>{const n=Jk(e),r=b(s=>u=>s+u.len)(0)(n)*no(0)(ei(1)(t)),o=[];let i=0,a=0;for(;a<n.length;){const s=a,u=i;if(s>=0&&s<n.length){if(u+n[s].len<=r){const c=n[s];Sk(o)(c)(),i=u+c.len,a=s+1|0;continue}if(u>=r){a=n.length;continue}Lk(o)(n[s])((r-u)/no(n[s].len)(1e-4))()}a=n.length}return o},Uh={offset:1.5,passes:2,rMax:14,overshoot:2.5},Xh=t=>e=>n=>r=>{const o=r.y-n.y,i=n.y-e.y,a=r.x-n.x,s=tn(a*a+o*o),u=n.x-e.x,c=tn(u*u+i*i),g=ei(t.rMax*(B2(c>0&&s>0?no(-1)(ei(1)((u*a+i*o)/(c*s))):1)/3.141592653589793))(.4*ei(c)(s));return{inP:c>0?{x:n.x-u/c*g,y:n.y-i/c*g}:n,curr:n,outP:s>0?{x:n.x+a/s*g,y:n.y+o/s*g}:n}},Vh=t=>e=>{const n=e.length,r=[],o=0<e.length?T("Just",e[0]):w;if(o.tag==="Just"?wu(r)(o._1)():o.tag==="Nothing"||_(),n>=3){let a=1;for(;a<=(n-2|0);){const s=a,u=s+1|0;if(u>=0&&u<e.length){if(s>=0&&s<e.length){const c=s-1|0;if(c>=0&&c<e.length){const g=Xh(t)(e[c])(e[s])(e[u]);ro(r)(g.inP)(),xu(r)(g.curr)(g.outP)()}}a=s+1|0;continue}a=s+1|0}}const i=e.length-1|0;return i>=0&&i<e.length&&n>=2&&ro(r)(e[i])(),r},Ek=t=>e=>n=>r=>o=>{if(o.length<4)return Vh(t)(o);const i=0<o.length?T("Just",o[0]):w,a=(()=>{if(i.tag==="Nothing")return{x:0,y:0};if(i.tag==="Just")return i._1;_()})(),s=o.length-1|0,u=co(co(e)(s)+s|0)(s),c=f=>{const h=co(f+s|0)(s);return h>=0&&h<o.length?o[h]:a},g=U(f=>Xh(t)(c((u+f|0)-1|0))(c(u+f|0))(c((u+f|0)+1|0)))(Yt(0,s-1|0)),l=[],d=0<g.length?T("Just",g[0]):w;if(d.tag==="Just")if(wu(l)(d._1.outP)(),wk((()=>{const f=At(h=>w,h=>m=>T("Just",m),g);if(f.tag==="Nothing")return[];if(f.tag==="Just")return f._1;_()})())(f=>{const h=ro(l)(f.inP);return()=>(h(),xu(l)(f.curr)(f.outP)())})(),n)ro(l)(d._1.inP)(),xu(l)(d._1.curr)(d._1.outP)(),l.push(5);else{const f=g.length-1|0;f>=0&&f<g.length?ro(l)((()=>{const h=1-r;return{x:g[f].outP.x+(d._1.inP.x-g[f].outP.x)*h,y:g[f].outP.y+(d._1.inP.y-g[f].outP.y)*h}})())():ro(l)(d._1.inP)()}else d.tag==="Nothing"||_();return l},$i=t=>e=>n=>r=>{const o=Nk(1)(r.length-1|0),i=Fe(0)(rt(o))(r_("shape")(e)),a=Tk(o-1|0)(de(Vn(i.value))),s=i.prng;return U(u=>{const c=Fe(0)(1)(r_(ae(u))(s)),g=Fe(-.18)(.3)(c.prng),l=c.value<.7,d=Fe(.5)(.85)(g.prng),f=kk(t.offset)(d.prng)(r);return{path:n?Ek(t)(a)(l)(g.value)(f):Vh(t)(f),alpha:d.value}})(Yt(0,t.passes-1|0))},Ak=t=>e=>n=>$i(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}]),Pk=t=>e=>n=>{const r=no(0)(ei(1)(n)),o=e.h/rt(4),i=no(6)(o*1.4);return wt(a=>a)(U(a=>{if(r<no(0)(rt(a)/rt(4)-.05))return w;const s=r_(ae(a))(t),u=no(0)(rt(a)/rt(4)-.05),c=co(a)(2)===0,g=c?e.x-2:e.x+e.w+2,l=c?e.x+e.w+2:e.x-2,d=e.y+(rt(a)+.5)*o;return T("Just",{path:qh(no(0)(ei(1)((r-u)/no(1e-4)(ei(1)(rt(a+1|0)/rt(4)+.05)-u))))((()=>{const f={rMax:2,offset:.6,passes:1},h=re(b(p=>x=>{const y=Fe(-o*.08)(o*.08)(p.prng);return{prng:y.prng,out:[{x:g+(l-g)*(rt(x)/rt(4)),y:d+y.value},...p.out]}})({prng:s,out:[]})(Yt(0,4)).out),m=h.length<2?[]:$i(f)(s)(!1)(h);return 0<m.length?m[0].path:[]})()),width:i,alpha:1})})(Yt(0,3)))},x_=(t,e,n)=>({tag:t,_1:e,_2:n}),Oa=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Yh=t=>t,w_=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},nn=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},On=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},Ke=(()=>{const t=mn.unfoldr(sr);return e=>t(yn("IterNode",e,ir))})(),Rk=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},ni=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},_e=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Gk=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},dr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Dk=Mt.foldMap(Z2),Nu=so.traverse(yo),qi=b(ur)(0),Kh=ge(P)(Mt),Fk=Bf(P),Ik=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},Bk=ge(P)(Mt),jh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},N_=Yh("FullTokenGeometry"),Mk=Yh("ConvexInsideGeometry"),ri=t=>{const e=t.Apply0();return n=>b(r=>o=>e.apply(e.Functor0().map(i=>Nf)(r))(n(o)))(t.pure())},Hn=ri(yo),Zh=t=>e=>n=>r=>o=>i=>{const a={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},u=Fa(o)(i)(r),c=0<t.length?T("Just",t[0]):w,g=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return s;_()})(),l=t.length-1|0,d=l>=0&&l<t.length?T("Just",t[l]):w,f=(()=>{if(d.tag==="Just")return d._1;if(d.tag==="Nothing")return a;_()})(),h=g.x-s.x,m=2*(()=>{const k=g.y-s.y;return(h<0?-h:h)+(k<0?-k:k)})(),p=f.x-a.x,x=2*(()=>{const k=f.y-a.y;return(p<0?-p:p)+(k<0?-k:k)})(),y=m+xs(t)+x,N=y<=1e-4?1:1-x/y,v=y<=1e-4?0:m/y,J=N-v;return{progress:u,morphOutEnd:v,morphInStart:N,outT:(()=>{if(v<=1e-4)return 1;const k=u/v,S=k<0?0:k>1?1:k;return S*S*(3-2*S)})(),inT:(()=>{if(N>=1)return 0;const k=(u-N)/(1-N),S=k<0?0:k>1?1:k;return S*S*(3-2*S)})(),pathStart:g,pathEnd:f,travelPt:(()=>{const k=Ci(t)(w_(0)(1)(J<=1e-4?0:(u-v)/J));if(k.tag==="Just")return k._1;if(k.tag==="Nothing")return g;_()})()}},tp=t=>e=>n=>r=>o=>i=>{const a=Zh(t)(e)(n)(r)(o)(i),s=xh(128)(ti(4)(e))(Mh(a.pathStart)(6)),u=xh(128)(Mh(a.pathEnd)(6))(ti(4)(n)),c={maxDelay:.4,smoothPasses:2};return a.progress<a.morphOutEnd?Yo("PolyShape",Nh(a.outT)(s.from)(s.to)(c)):a.progress>=a.morphInStart?Yo("PolyShape",Nh(a.inT)(u.from)(u.to)(c)):Yo("CircleShape",a.travelPt,6)},T_=t=>e=>n=>r=>o=>i=>{const a=tp(t)(e)(n)(r)(o)(i);if(a.tag==="PolyShape")return d_(a._1);if(a.tag==="CircleShape")return a._1;_()},ep=t=>e=>n=>r=>nn(t)(n-.5)<=On(e)(r+.5),zk=t=>{const e=n=>{const r=Kt(o=>n.x>=o._2.x-1&&n.x<=o._2.x+o._2.w+1&&n.y>=o._2.y-1&&n.y<=o._2.y+o._2.h+1)(Ke(t.nodes));return r.tag==="Just"?T("Just",r._1._2):w};return n=>{const r=(()=>{if(0<n.length){const i=e(n[0]);if(i.tag==="Just")return re(Qh(ti(7)(i._1))(re(n)))}return n})(),o=r.length-1|0;if(o>=0&&o<r.length){const i=e(r[o]);if(i.tag==="Just")return Qh(ti(7)(i._1))(r)}return r}},Qk=t=>e=>{const n=((t.bg.r+t.bg.g|0)+t.bg.b|0)<384,r=n?90:104,o=n?165:122,i=a=>Rk(255)(ni(0)(de(Fn(o+r*fn(e+a)))));return{r:i(0),g:i(-2.0943951023931953),b:i(-4.1887902047863905),a:255}},np=t=>e=>{if(t<=0)return[];const n=At(r=>w,r=>o=>T("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return un(n._1.head.text).length<=t?[n._1.head,...np(t-un(n._1.head.text).length|0)(n._1.tail)]:[{...n._1.head,text:De(t)(n._1.head.text)}];_()},v_=(()=>{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},o={r:28,g:101,b:192,a:255},i={r:247,g:248,b:250,a:255},a={r:42,g:48,b:60,a:255},s={r:120,g:130,b:146,a:255};return u=>{if(u==="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:to,nodeFill:Ne,nodeStroke:to,text:to,edge:to,arrowFill:to,tokenOutsideFill:to,tokenOutsideStroke:Ne,tokenInside:Ne,tokenInsideStroke:Ne,tokenInsideBlend:fu,tokenInsideAlpha:1,chipPillFill:to,chipPillText:Ne,chipHairline:{r:26,g:26,b:26,a:90},trailDot:to,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(u==="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:to,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:Ne,tokenOutsideStroke:Ne,tokenInside:Ne,tokenInsideStroke:Ne,tokenInsideBlend:fu,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(u==="Blueprint")return{bg:o,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:90,g:160,b:230,a:255},shadowFill:o,shadowDot:Ne,chip:Ne,chipShadow:{r:0,g:0,b:0,a:120},chipText:o,nodeFill:o,nodeStroke:Ne,text:Ne,edge:Ne,arrowFill:Ne,tokenOutsideFill:Ne,tokenOutsideStroke:Ne,tokenInside:Ne,tokenInsideStroke:Ne,tokenInsideBlend:eh,tokenInsideAlpha:.35,chipPillFill:Ne,chipPillText:o,chipHairline:{r:255,g:255,b:255,a:120},trailDot:Ne,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(u==="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:eh,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(u==="Isometric")return{bg:i,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:218,b:224,a:255},shadowFill:i,shadowDot:a,chip:{r:255,g:235,b:130,a:255},chipShadow:{r:100,g:110,b:125,a:90},chipText:a,nodeFill:{r:236,g:239,b:244,a:255},nodeStroke:a,text:a,edge:s,arrowFill:s,tokenOutsideFill:a,tokenOutsideStroke:Ne,tokenInside:Ne,tokenInsideStroke:Ne,tokenInsideBlend:fu,tokenInsideAlpha:1,chipPillFill:a,chipPillText:Ne,chipHairline:{r:60,g:66,b:78,a:90},trailDot:a,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};_()}})(),b_=t=>e=>Et(Ke(t))(n=>{const r=_e(n._1)(e.nodes);return r.tag==="Just"&&wo(r._1).alpha>0?Zo(n._2):[]}),Wk=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,...b_(e)(n)],Ok=t=>e=>n=>{const r=(o,i)=>de(Fn(rt(o)+(rt(i)-rt(o))*n));return{r:r(t.r,e.r),g:r(t.g,e.g),b:r(t.b,e.b),a:r(t.a,e.a)}},Hk=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=so.traverse(r);return i=>a=>{const s=Bn(a),u=.32*i.size;return o(c=>n.bind(c===0?r.pure(0):t.measureText(i)(De(c)(a)))(g=>n.bind(t.measureText(i)(De(c+1|0)(a)))(l=>n.bind(t.measureInk(i)(c>=0&&c<s.length?cr(s[c]):" "))(d=>r.pure({x:g,w:l-g,up:d.ascent-u,down:d.descent+u})))))(Yt(0,s.length-1|0))}},rp=t=>[...Zo({...t,x:t.x-1.25,y:t.y-1.25,w:t.w+2.5,h:t.h+2.5}),...Zo({...t,y:t.y-5})],$k=t=>e=>{const n=o=>(o.x-e.x)*(o.x-e.x)+(o.y-e.y)*(o.y-e.y),r=b(o=>i=>n(i)<n(o)?i:o)({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 U(o=>{const i=rt(o)/5;return{x:r.x+(e.x-r.x)*i,y:r.y+(e.y-r.y)*i}})([1,2,3,4])},Ha=t=>e=>n=>{const r=Gk(ae(e)+":"+ae(n))(t);if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;_()},qk=t=>e=>{const n=e.length;return b(r=>o=>b(i=>a=>it(P)(ae(o)+":"+ae(a))(a>=0&&a<e.length&&o>=0&&o<t.length?t[o]===e[a]?1+Ha(i)(o+1|0)(a+1|0)|0:ni(Ha(i)(o+1|0)(a))(Ha(i)(o)(a+1|0)):0)(i))(r)(n<=0?[]:re(Yt(0,n-1|0))))(M)((()=>{const r=t.length;return r<=0?[]:re(Yt(0,r-1|0))})())},J_=t=>nr(t),Uk=t=>e=>n=>r=>o=>i=>{const a=Zh(t)(e)(n)(r)(o)(i);return a.progress<a.morphOutEnd?x_("InsideRect",f_(2)(e)):a.progress>=a.morphInStart?x_("InsideRect",f_(2)(n)):x_("InsideBall",a.travelPt,6)},C_=t=>e=>n=>r=>o=>i=>a=>s=>{const u=(c,g)=>Dh({id:c,pass:t,geometry:Jh("FlatToken",g),position:(()=>{if(g.tag==="CircleShape")return g._1;if(g.tag==="PolyShape")return d_(g._1);_()})(),plan:kh("FlatTokenPlan",{wobble:n,fill:a,stroke:s})});return Hn(c=>{if(c._2.tag==="Travelling"){const g=_e(c._2._1.target)(r),l=_e(c._2._1.source)(r);if(l.tag==="Just"&&g.tag==="Just"){const d=dr(c._2._1.edge)(o);if(d.tag==="Just"){const f=(()=>{if(c._2._1.direction==="Forward")return d._1;if(c._2._1.direction==="Backward")return re(d._1);_()})();return u(c._1,(()=>{if(e==="FullTokenGeometry")return tp(f)(l._1)(g._1)(c._2._1.progress)(c._2._1.holdPre)(c._2._1.holdPost);if(e==="ConvexInsideGeometry"){const h=Uk(f)(l._1)(g._1)(c._2._1.progress)(c._2._1.holdPre)(c._2._1.holdPost);if(h.tag==="InsideRect")return Yo("PolyShape",h_(4)(h._1));if(h.tag==="InsideBall")return Yo("CircleShape",h._1,h._2)}_()})())}if(d.tag==="Nothing"){const f=Fa(c._2._1.holdPre)(c._2._1.holdPost)(c._2._1.progress),h={x:l._1.x+l._1.w/2,y:l._1.y+l._1.h/2},m={x:g._1.x+g._1.w/2,y:g._1.y+g._1.h/2};return Ue({path:[],role:cn,layer:w,effects:[Je("GroupAlpha",(()=>{if(f<.5){const x=f*2;return 1-nn(0)(On(1)(x))*nn(0)(On(1)(x))*(3-2*nn(0)(On(1)(x)))}const p=(f-.5)*2;return nn(0)(On(1)(p))*nn(0)(On(1)(p))*(3-2*nn(0)(On(1)(p)))})())]})(u(c._1,Yo("CircleShape",f<.5?h:m,6)))}_()}return K(st("Return",void 0),ct)}if(c._2.tag==="Filling"){if(n)return K(st("Return",void 0),ct);const g=_e(c._2._1.node)(r);if(g.tag==="Just")return u(c._1,Yo("PolyShape",ti(4)(e==="ConvexInsideGeometry"?f_(2)(g._1):g._1)));if(g.tag==="Nothing")return K(st("Return",void 0),ct);_()}return K(st("Return",void 0),ct)})(Ke(i.tokens))},Xk=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0();return o=>n.bind((()=>{const i=r.pure();if(o.clear.tag==="Nothing")return i;if(o.clear.tag==="Just")return t.clearBackground(o.clear._1);_()})())(()=>n.bind(t.setViewport(o.viewport))(()=>{const i=r.pure();if(o.dots.tag==="Nothing")return i;if(o.dots.tag==="Just")return t.backgroundDots(o.dots._1);_()}))},op=t=>e=>n=>r=>Ue({path:[],role:cn,layer:w,effects:[Je("GroupAlpha",n.fadeAlpha),Je("GroupTransform",Ko,{tx:t.x*(1-n.popScale),ty:(t.y+t.h)*(1-n.popScale),sx:n.popScale,sy:n.popScale}),Je("GroupTransform",Ko,{tx:0,ty:e.y*(1-n.flipY),sx:1,sy:n.flipY})]})(jo(r)),Vk=t=>e=>n=>r=>o=>i=>a=>s=>{const u=c=>g=>{const l=At(d=>w,d=>f=>T("Just",{head:d,tail:f}),g);if(l.tag==="Nothing")return K(st("Return",void 0),ct);if(l.tag==="Just"){const d=l._1,f=jr(o)(cr(d.head)),h=m=>{const p=jo({owner:eo("NodeText",r),text:cr(d.head),spec:{x:c,y:a-e*o.size*.11*fn(t*5-c*.22),content:cr(d.head),font:o,color:Ok(n.text)(Qk(n)(t*2.2+c*.16))(e),align:xo,baseline:xn},bounds:w,plan:Hi});return K(p._1,(()=>{if(p._2.tag==="CatNil")return tt("CatCons",()=>u(c+m)(d.tail),Z(R,R));if(p._2.tag==="CatCons")return tt("CatCons",p._2._1,Z(p._2._2._1,yt("Cons",tt("CatCons",()=>u(c+m)(d.tail),Z(R,R)),p._2._2._2)));_()})())};return K(f._1,(()=>{if(f._2.tag==="CatNil")return tt("CatCons",h,Z(R,R));if(f._2.tag==="CatCons")return tt("CatCons",f._2._1,Z(f._2._2._1,yt("Cons",tt("CatCons",h,Z(R,R)),f._2._2._2)));_()})())}_()};return u(i)(Bn(s))},ip=t=>e=>n=>r=>o=>i=>a=>s=>u=>i==="RunHighlight"||i==="RunCodeHighlight"?Vk(t)(e)(n)(r)(o)(a)(s)(u):jo({owner:eo("NodeText",r),text:u,spec:{x:a,y:s,content:u,font:o,color:n.text,align:xo,baseline:xn},bounds:w,plan:Hi}),Yk=t=>e=>n=>r=>o=>i=>a=>op(o)(i)(a)({owner:eo("TokenText",t),text:n,spec:{x:i.x,y:i.y,content:n,font:{family:e.fontFamily,size:11,weight:500},color:e.chipText,align:Zr,baseline:xn},bounds:T("Just",o),plan:Ma("TokenFillingText",{shadow:{...o,y:o.y+1.5},shadowFill:{color:e.chipShadow,flat:!0},radius:6,fill:{color:e.chip,flat:!0},stroke:{color:e.chipHairline,width:1,lineJoin:Ye,lineCap:Ln},leader:[1,i.x,o.y+o.h,2,r.x+r.w/2,r.y]})}),Kk={offset:.8,passes:2,rMax:5},ap=t=>e=>n=>r=>t.strokePath((()=>{const o=At(i=>w,i=>a=>T("Just",{head:i,tail:a}),U(i=>i.pt)(R2(i=>a=>{const s=rt(a)/rt(72),u=Fe(-.18)(.18)(i.prng),c=Fe(-.1)(.1)(u.prng),g=Fe(-.07)(.07)(c.prng),l=n*(.05+.55*s)*(1+c.value),d=s*28.274333882308138+u.value;return{prng:g.prng,pt:{x:e.x+Dn(d)*l+g.value*n,y:e.y+fn(d)*l+g.value*n}}},{prng:137,pt:{x:e.x,y:e.y}},Yt(0,72))));if(o.tag==="Just")return[1,o._1.head.x,o._1.head.y,...Dk(i=>[2,i.x,i.y])(o._1.tail)];if(o.tag==="Nothing")return[];_()})())({color:r,width:5.5,lineJoin:Ye,lineCap:lr}),jk=t=>{const e=t.Monad0().Applicative0();return n=>{if(n.geometry.tag==="FlatToken"&&n.plan.tag==="FlatTokenPlan"){if(n.geometry._1.tag==="CircleShape")return n.plan._1.wobble?ap(t)(n.geometry._1._1)(n.geometry._1._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(zh(n.geometry._1._1)(n.geometry._1._2))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:Ye,lineCap:Ln});if(n.geometry._1.tag==="PolyShape")return n.plan._1.wobble&&n.geometry._1._1.length>=3?ap(t)(d_(n.geometry._1._1))(6)({r:200,g:35,b:30,a:220}):n.geometry._1._1.length>=3?t.fillStrokePath(Bh(n.geometry._1._1))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:Ye,lineCap:Ln}):e.pure();_()}return e.pure()}},Zk=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popClip,i=t.popTransform,a=t.popAlpha;return s=>u=>c=>g=>l=>{const d=wo(l),f=c*d.alpha,h={...g,y:g.y+5},m=g.x+g.w/2,p=g.y+g.h/2,x=rp(h),y=r.bind(t.pushAlpha(f))(()=>r.bind(t.pushTransform({tx:m*(1-d.scale),ty:p*(1-d.scale),sx:d.scale,sy:d.scale}))(()=>r.bind(t.pushClip(x)(e_))(()=>r.bind(Vo(t)(h.shape)({x:h.x,y:h.y,w:h.w,h:h.h})(7)(T("Just",{color:s.shadowFill,flat:!0}))(w))(()=>r.bind((()=>{const N=r.bind(t.pushClip(Zo(h))(Qi))(()=>r.bind(t.backgroundDots({viewport:{vx:h.x,vy:h.y,vw:h.w,vh:h.h},bgColor:s.bgTransparent,dotColor:s.shadowDot,tile:1.6,dotRadius:.25,origin:{x:0,y:0}}))(()=>o));return u&&!s.wobble?N:n.pure()})())(()=>r.bind(Vo(t)(h.shape)({x:h.x,y:h.y,w:h.w,h:h.h})(7)(w)(T("Just",{color:s.nodeStroke,width:1.25,lineJoin:Ye,lineCap:Ln})))(()=>r.bind(o)(()=>r.bind(i)(()=>a))))))));return f>0&&!s.wobble?y:n.pure()}},tL=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=ri(e.Applicative0());return i=>a=>s=>o(u=>n.bind(t.pushAlpha(u.alpha))(()=>n.bind(t.strokePath(u.path)({color:i.nodeFill,width:u.width,lineJoin:Ye,lineCap:lr}))(()=>r)))(Pk($h(a)+7777|0)(a)(s))},eL=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=e.Applicative0(),i=ri(o),a=t.popClip,s=ri(o),u=so.traverse(o),c=Hk(t),g=tL(t),l=t.popTransform;return d=>f=>h=>m=>p=>x=>y=>N=>v=>J=>{const k=F=>n.bind(t.pushAlpha(F.alpha))(()=>n.bind(t.strokePath(F.path)({color:h.nodeStroke,width:2,lineJoin:Ye,lineCap:lr}))(()=>r)),S={family:h.fontFamily,size:h.wobble?15:11,weight:h.wobble?800:500},A=nr(v.label===""?N:v.label),I=S.size*1.2,$=v.shape==="Cylinder"?t.strokePath(c3({x:v.x,y:v.y,w:v.w,h:v.h}))({color:h.nodeStroke,width:1.25,lineJoin:Ye,lineCap:Ln}):o.pure(),E=(v.shape==="Cylinder"?(v.y+(v.y+v.h+5-2*wn(v.h*.075)(v.w*.075)))/2:(v.y+v.y+v.h)/2)-rt(A.length)*I/2+I/2,G=J.tag==="PloppingOut"&&h.wobble?J._1:-1,nt=G>=0,V=wo(J),Q=nt?{alpha:1,scale:1}:V,Y=v.x+v.w/2,X=v.y+v.h/2,D=n.bind(t.pushAlpha(Q.alpha))(()=>n.bind(t.pushTransform({tx:Y*(1-Q.scale),ty:X*(1-Q.scale),sx:Q.scale,sy:Q.scale}))(()=>{const F={x:v.x,y:v.y,w:v.w,h:v.h},B={color:h.nodeStroke,width:h.wobble?2:1.25*f,lineJoin:Ye,lineCap:h.wobble?lr:Ln},z=(()=>{if(h.wobble){if(v.shape==="Rectangle")return i(k)(Ak(Uh)($h(F))(F));const j=ti(7)(v);return n.bind(i(k)((()=>{const W=Wa(j);return j.length<4?[]:$i(Hh)(W)(!0)(j)})()))(()=>s(W=>i(k)((()=>{const O=Wa(W);return W.length<2?[]:$i(Hh)(O)(!1)(W)})()))(v.shape==="Cylinder"?[sk(v)]:[]))}return n.bind(Vo(t)(v.shape)(F)(7)(w)(T("Just",B)))(()=>$)})();return n.bind((()=>{if(p.tag==="Nothing")return n.bind(t.pushAlpha(m))(()=>n.bind(h.wobble?z:n.bind(Vo(t)(v.shape)(F)(7)(T("Just",{color:h.nodeFill,flat:!1}))(T("Just",B)))(()=>$))(()=>n.bind((()=>{if(y.tag==="Just"&&h.wobble&&!nt){const j=y._1;return n.bind(u(c(S))(A))(W=>{const O=Gt(ht=>bt=>at.compare(ht.x)(bt.x)),q=de(Vn(v.x*7919+v.y*3001))*-1640531535|0,H=Fe(5)(7.5)(q),ot=Fe(0)(H.value)(H.prng),et=-(1+2*Fe(-1)(1)(ot.prng).value*3.141592653589793/180),gt=(ht,bt,Qt,Bt,ie)=>O(wt(ce=>ce)([et*bt+ht>=Bt&&et*bt+ht<=ie?T("Just",{x:bt,y:et*bt+ht}):w,et*Qt+ht>=Bt&&et*Qt+ht<=ie?T("Just",{x:Qt,y:et*Qt+ht}):w,(()=>{const ce=(Bt-ht)/et;return ce>=bt&&ce<=Qt?T("Just",{x:ce,y:Bt}):w})(),(()=>{const ce=(ie-ht)/et;return ce>=bt&&ce<=Qt?T("Just",{x:ce,y:ie}):w})()])),Lt=H.value,ft=co(j.frameHash)(3),Nt=ft===0?{r:200,g:35,b:30,a:220}:ft===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},kt=v.x+v.w/2,jt=bn(Ot(ht=>bt=>Ot((()=>{const Qt=E+rt(ht)*I,Bt=kt-b(ie=>ce=>ie+ce.w)(0)(bt)/2;return ie=>ce=>{const gn=S.size*.1,$t=ie-1|0,te=$t>=0&&$t<bt.length&&ie>0?(bt[$t].x+bt[$t].w+ce.x)/2:ce.x-gn;return{x:Bt+te-1,y:Qt-ce.up-1,w:nn(0)((()=>{const on=ie+1|0;return on>=0&&on<bt.length&&ie<(bt.length-1|0)?(ce.x+ce.w+bt[on].x)/2-te:ce.x+ce.w+gn-te})())+2,h:ce.up+ce.down+2}}})())(bt))(W)),Tt=v.y+4,Vt=v.x+v.w-4,Ft=v.x+4,vt=Tt-et*Ft+ot.value,mt=v.y+v.h-4,lt=Et(Et(Ot(ht=>bt=>{const Qt=(bt.from.x+bt.to.x)/2,Bt=(bt.from.y+bt.to.y)/2,ie=Fe(-1)(1)(q+(911*(ht+1|0)|0)|0),ce=Fe(-3)(5)(ie.prng),gn=ie.value*3.141592653589793/180,$t=Dn(gn),te=fn(gn),on=He=>({x:Qt+(He.x-Qt)*$t-(He.y-Bt)*te,y:Bt+(He.x-Qt)*te+(He.y-Bt)*$t});return{from:(()=>{const He=on(bt.from),Pn=He.y-Bt,Rn=He.x-Qt,Ze=tn(Rn*Rn+Pn*Pn),se=Ze<1e-4?1:(Ze+ce.value)/Ze;return{x:Qt+Rn*se,y:Bt+Pn*se}})(),to:(()=>{const He=on(bt.to),Pn=Fe(-3)(5)(ce.prng).value,Rn=He.y-Bt,Ze=He.x-Qt,se=tn(Ze*Ze+Rn*Rn),Te=se<1e-4?1:(se+Pn)/se;return{x:Qt+Ze*Te,y:Bt+Rn*Te}})()}})(wt(ht=>{const bt=gt(vt+rt(ht)*Lt,Ft,Vt,Tt,mt);return bt.length===2?T("Just",{from:bt[0],to:bt[1]}):w})(Yt(0,ni(1)(de(Vn((mt-et*Vt-vt)/Lt)))))))(ht=>dt(bt=>bt.to.x-bt.from.x>1,b(bt=>Qt=>Et(bt)(Bt=>{const ie=gt(Bt.from.y-et*Bt.from.x,Qt.x,Qt.x+Qt.w,Qt.y,Qt.y+Qt.h);return ie.length===2?ie[0].x>Bt.from.x+.001&&ie[1].x<Bt.to.x-.001?[{from:Bt.from,to:ie[0]},{from:ie[1],to:Bt.to}]:ie[0].x<=Bt.from.x+.001&&ie[1].x<Bt.to.x-.001?[{from:ie[1],to:Bt.to}]:ie[0].x>Bt.from.x+.001&&ie[1].x>=Bt.to.x-.001?[{from:Bt.from,to:ie[0]}]:[]:[Bt]}))([ht])(jt))))(ht=>(()=>{const bt=ht.to.x-ht.from.x;return tn(2)*(bt>=0?bt:-bt)<=28})()?[ht]:[{from:ht.from,to:{x:ht.from.x+(ht.to.x-ht.from.x)*.495,y:ht.from.y+(ht.to.y-ht.from.y)*.495}},{from:{x:ht.from.x+(ht.to.x-ht.from.x)*.505,y:ht.from.y+(ht.to.y-ht.from.y)*.505},to:ht.to}]),xt=lt.length,Dt=ht=>nn(0)(On(1)(j.t*rt(xt)-rt(ht)));return n.bind(t.pushClip(Bh(ti(7)(v)))(Qi))(()=>n.bind(i(ht=>{const bt=ht._1,Qt=Fe(1.4)(1.9)(q+(1303*(bt+1|0)|0)|0),Bt=Fe(.35)(.8)(Qt.prng),ie=i(ce=>n.bind(t.pushAlpha(ce.alpha*Bt.value))(()=>n.bind(t.strokePath(qh(Dt(bt))(ce.path))({color:Nt,width:Qt.value,lineJoin:Ye,lineCap:lr}))(()=>r)))($i({...Uh,rMax:0,offset:.5})(q+(53*(bt+1|0)|0)|0)(!1)([ht._2.from,ht._2.to]));return Dt(bt)>0?ie:o.pure()})(Ot(vn)(lt)))(()=>a))})}return o.pure()})())(()=>n.bind((()=>{if(d==="LabelsShown"){const j=n.bind(t.pushAlpha(x))(()=>n.bind(i(W=>t.drawText({x:v.x+v.w/2,y:E+rt(W._1)*I,content:W._2,font:S,color:h.text,align:Zr,baseline:xn}))(Ot(vn)(A)))(()=>r));return x>0?j:o.pure()}if(d==="LabelsHidden")return o.pure();_()})())(()=>n.bind((()=>{const j=g(h)(F)(G);return nt?j:o.pure()})())(()=>r)))));if(p.tag==="Just"){const j=p._1;return n.bind((()=>{const W=n.bind(t.pushAlpha(m))(()=>n.bind(Vo(t)(v.shape)(F)(7)(T("Just",{color:h.nodeFill,flat:!1}))(w))(()=>r));return m>0&&!h.wobble?W:o.pure()})())(()=>{const W=n.bind(t.pushAlpha(j))(()=>n.bind(z)(()=>r));return j>0?W:o.pure()})}_()})())(()=>n.bind(l)(()=>r))}));return Q.alpha*nn(m)((()=>{if(p.tag==="Nothing")return m;if(p.tag==="Just")return p._1;_()})())>0?D:o.pure()}},nL=t=>e=>n=>{const r={family:t.fontFamily,size:11,weight:500};return Hn(o=>{if(o._2===""||(()=>{const s=dr(o._1)(n.edges);return s.tag==="Nothing"||!(s.tag==="Just"&&rN.eq(s._1)(nl))})())return K(st("Return",void 0),ct);const i=dr(o._1)(e.edges),a=(()=>{if(i.tag==="Just")return Ci(i._1)(.5);if(i.tag==="Nothing")return w;_()})();if(a.tag==="Nothing")return K(st("Return",void 0),ct);if(a.tag==="Just"){const s=a._1,u=jr(r)(o._2),c=g=>{const l=g+12;return jo({owner:eo("EdgeText",o._1),text:o._2,spec:{x:s.x,y:s.y,content:o._2,font:r,color:t.chipPillText,align:Zr,baseline:xn},bounds:T("Just",{x:s.x-l/2,y:s.y-8.5,w:l,h:17}),plan:Ma("RoundedText",{radius:3,fill:T("Just",{color:t.chipPillFill,flat:!0}),stroke:w})})};return K(u._1,(()=>{if(u._2.tag==="CatNil")return tt("CatCons",c,Z(R,R));if(u._2.tag==="CatCons")return tt("CatCons",u._2._1,Z(u._2._2._1,yt("Cons",tt("CatCons",c,Z(R,R)),u._2._2._2)));_()})())}_()})(Ke(e.edgeLabels))},rL=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popClip,i=t.popTransform,a=t.popAlpha;return s=>u=>c=>g=>l=>{const d=wo(l),f=c*d.alpha,h=g.x+g.w/2,m=g.y-5+g.h/2,p=rp(g),x=r.bind(t.pushAlpha(f))(()=>r.bind(t.pushTransform({tx:h*(1-d.scale),ty:m*(1-d.scale),sx:d.scale,sy:d.scale}))(()=>r.bind(t.pushClip(p)(e_))(()=>r.bind(Vo(t)(g.shape)({x:g.x,y:g.y,w:g.w,h:g.h})(7)(T("Just",{color:s.shadowFill,flat:!0}))(w))(()=>r.bind((()=>{const y=r.bind(t.pushClip(Zo(g))(Qi))(()=>r.bind(t.backgroundDots({viewport:{vx:g.x,vy:g.y,vw:g.w,vh:g.h},bgColor:s.bgTransparent,dotColor:s.shadowDot,tile:1.6,dotRadius:.25,origin:{x:0,y:0}}))(()=>o));return u?y:n.pure()})())(()=>r.bind(Vo(t)(g.shape)({x:g.x,y:g.y,w:g.w,h:g.h})(7)(w)(T("Just",{color:s.nodeStroke,width:1.25,lineJoin:Ye,lineCap:Ln})))(()=>r.bind(o)(()=>r.bind(i)(()=>a))))))));return f>0&&!s.wobble?x:n.pure()}},oL=t=>{const e=Zk(t),n=rL(t),r=eL(t);return o=>{if(o.geometry.tag==="FlatNode"&&o.plan.tag==="FlatNodePlan"){const i={x:o.geometry._1.bounds.x,y:o.geometry._1.bounds.y,w:o.geometry._1.bounds.w,h:o.geometry._1.bounds.h,label:o.plan._1.label,shape:o.geometry._1.shape};if(o.role==="NodeShadow")return e(o.plan._1.palette)(o.plan._1.inkBoost>0)(o.alpha)(i)(o.plan._1.animState);if(o.role==="NodeDoorwayFrame")return n(o.plan._1.palette)(o.plan._1.inkBoost>0)(o.alpha)(i)(o.plan._1.animState);if(o.role==="NodeBody"||o.role==="NodeInversion")return r(za)(o.plan._1.inkBoost)(o.plan._1.palette)(o.alpha)(o.plan._1.outlineAlpha)(0)(o.plan._1.arrival)(o.id)(i)(o.plan._1.animState);_()}return t.Monad0().Applicative0().pure()}},iL=t=>e=>{const n=Bn(t),r=n.length,o=Bn(e),i=o.length,a=qk(n)(o);return(s=>u=>c=>{let g=s,l=u,d=c,f=!0,h;for(;f;){const m=g,p=l,x=d;if(m>=r&&p>=i){f=!1,h=re(x);continue}if(m>=r){if(p>=0&&p<o.length){g=m,l=p+1|0,d=[Oa("DiffInsert",p,o[p]),...x];continue}f=!1,h=re(x);continue}if(p>=i){if(m>=0&&m<n.length){g=m+1|0,l=p,d=[Oa("DiffDelete",m,n[m]),...x];continue}f=!1,h=re(x);continue}if(p>=0&&p<o.length){if(m>=0&&m<n.length){if(n[m]===o[p]){g=m+1|0,l=p+1|0,d=[Oa("DiffKeep",m,p,n[m]),...x];continue}if(Ha(a)(m+1|0)(p)>=Ha(a)(m)(p+1|0)){g=m+1|0,l=p,d=[Oa("DiffDelete",m,n[m]),...x];continue}g=m,l=p+1|0,d=[Oa("DiffInsert",p,o[p]),...x];continue}f=!1,h=re(x);continue}f=!1,h=re(x)}return h})(0)(0)([])},sp=t=>e=>n=>r=>o=>Hn(i=>{if(t.tag==="Just"&&i._1===t._1)return K(st("Return",void 0),ct);const a=_e(i._1)(o.nodes);if(a.tag==="Just"){const s=_e(i._1)(o.nodeLabels),u=(()=>{if(s.tag==="Nothing")return i._2;if(s.tag==="Just"){if(s._1.tag==="StaticNodeLabel")return{...i._2,label:s._1._1===""?i._1:s._1._1};if(s._1.tag==="RelabelingNode")return{...i._2,label:(()=>{const c=s._1._1.progress<.5?s._1._1.oldLabel:s._1._1.newLabel;return c===""?i._1:c})()}}_()})();return Qa({id:i._1,role:H3,geometry:Ia("FlatNode",{shape:u.shape,bounds:{x:u.x,y:u.y,w:u.w,h:u.h}}),alpha:(()=>{const c=_e(i._1)(o.nodeFadeAlpha),g=(()=>{if(c.tag==="Nothing")return 1;if(c.tag==="Just")return c._1;_()})();return g<1?0:g})(),plan:Ba("FlatNodePlan",{palette:e,label:(()=>{const c=_e(i._1)(o.nodeLabels);if(c.tag==="Just"){if(c._1.tag==="StaticNodeLabel")return c._1._1===""?i._1:c._1._1;if(c._1.tag==="RelabelingNode"){const g=c._1._1.progress<.5?c._1._1.oldLabel:c._1._1.newLabel;return g===""?i._1:g}_()}if(c.tag==="Nothing")return u.label===""?i._1:u.label;_()})(),labelVisibility:za,inkBoost:n?1:0,labelAlpha:0,outlineAlpha:w,arrival:w,animState:a._1})})}if(a.tag==="Nothing")return K(st("Return",void 0),ct);_()})(Ke(r.nodes)),aL=t=>e=>n=>(()=>{const r=t.x-e.x;return r<0?-r<=1e-6:r<=1e-6})()?t.x>=n.x-.5&&t.x<=n.x+n.w+.5&&ep(On(t.y)(e.y))(nn(t.y)(e.y))(n.y)(n.y+n.h):(()=>{const r=t.y-e.y;return r<0?-r<=1e-6:r<=1e-6})()?t.y>=n.y-.5&&t.y<=n.y+n.h+.5&&ep(On(t.x)(e.x))(nn(t.x)(e.x))(n.x)(n.x+n.w):!0,up=t=>e=>n=>r=>r.length===2&&(()=>{const o=r[1],i=r[0];return pc(a=>a._1===e||a._1===n||!aL(i)(o)(a._2),Ke(t))})(),k_=t=>e=>n=>r=>o=>i=>a=>s=>{const u=fr(s),c=l=>d=>f=>{const h=At(p=>w,p=>x=>T("Just",{head:p,tail:x}),f),m=At(p=>w,p=>x=>T("Just",{head:p,tail:x}),d);if(m.tag==="Just"&&h.tag==="Just"){const p=ip(t)(e)(n)(r)(m._1.head.style==="RunCode"||m._1.head.style==="RunCodeHighlight"?{...o,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:o)(m._1.head.style)(l)(a)(m._1.head.text);return K(p._1,(()=>{if(p._2.tag==="CatNil")return tt("CatCons",()=>c(l+h._1.head)(m._1.tail)(h._1.tail),Z(R,R));if(p._2.tag==="CatCons")return tt("CatCons",p._2._1,Z(p._2._2._1,yt("Cons",tt("CatCons",()=>c(l+h._1.head)(m._1.tail)(h._1.tail),Z(R,R)),p._2._2._2)));_()})())}return K(st("Return",void 0),ct)};if(u.length===1&&u[0].style==="RunText")return jo({owner:eo("NodeText",r),text:u[0].text,spec:{x:i,y:a,content:u[0].text,font:o,color:n.text,align:Zr,baseline:xn},bounds:w,plan:Hi});const g=Nu(l=>jr(l.style==="RunCode"||l.style==="RunCodeHighlight"?{...o,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:o)(l.text))(u);return K(g._1,(()=>{if(g._2.tag==="CatNil")return tt("CatCons",l=>c(i-qi(l)/2)(u)(l),Z(R,R));if(g._2.tag==="CatCons")return tt("CatCons",g._2._1,Z(g._2._2._1,yt("Cons",tt("CatCons",l=>c(i-qi(l)/2)(u)(l),Z(R,R)),g._2._2._2)));_()})())},sL=t=>e=>{const n=Nu(r=>jr(r.style==="RunCode"||r.style==="RunCodeHighlight"?{...t,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:t)(r.text))(fr(e));return K(n._1,(()=>{if(n._2.tag==="CatNil")return tt("CatCons",r=>K(st("Return",qi(r)),ct),Z(R,R));if(n._2.tag==="CatCons")return tt("CatCons",n._2._1,Z(n._2._2._1,yt("Cons",tt("CatCons",r=>K(st("Return",qi(r)),ct),Z(R,R)),n._2._2._2)));_()})())},cp=t=>e=>n=>r=>{const o=nr(r===""?t:r),i=n.size*1.2,a=(e.shape==="Cylinder"?(e.y+(e.y+e.h+5-2*wn(e.h*.075)(e.w*.075)))/2:(e.y+e.y+e.h)/2)-rt(o.length)*i/2+i/2,s=Nu(sL(n))(o),u=c=>K(st("Return",Ot(g=>l=>({line:Ur(l),runs:fr(l),left:g>=0&&g<c.length?e.x+e.w/2-c[g]/2:e.x+e.w/2-0,y:a+rt(g)*i}))(o)),ct);return K(s._1,(()=>{if(s._2.tag==="CatNil")return tt("CatCons",u,Z(R,R));if(s._2.tag==="CatCons")return tt("CatCons",s._2._1,Z(s._2._2._1,yt("Cons",tt("CatCons",u,Z(R,R)),s._2._2._2)));_()})())},uL=t=>e=>n=>{const r=Nu(o=>jr(o.style==="RunCode"||o.style==="RunCodeHighlight"?{...t,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:t)(o.text))(np(e)(n));return K(r._1,(()=>{if(r._2.tag==="CatNil")return tt("CatCons",o=>K(st("Return",qi(o)),ct),Z(R,R));if(r._2.tag==="CatCons")return tt("CatCons",r._2._1,Z(r._2._2._1,yt("Cons",tt("CatCons",o=>K(st("Return",qi(o)),ct),Z(R,R)),r._2._2._2)));_()})())},gp=t=>{const e=n=>{if(n.tag==="Leaf")return M;if(n.tag==="Node")return ee("Node",n._1,n._2,n._3,m_({x:t.vx,y:t.vy,w:t.vw,h:t.vh})(n._4),e(n._5),e(n._6));_()};return e},cL=t=>e=>n=>On(e)(nn(t)(n)),_p=t=>e=>n=>t>e?[]:[...U(cL(t)(e))(n),(t+e)/2],gL=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=ri(r);return i=>a=>s=>u=>c=>g=>{const l=un(g).length,d=rt(l+1|0),f=p=>{const x=(s*d-rt(p))/1.5,y=x<0?0:x>1?1:x;return y*y*(3-2*y)},h=(p=>{let x=p,y=!0,N;for(;y;){const v=x;if(v>=l){y=!1,N=v;continue}if(f(v)>=1){x=v+1|0;continue}y=!1,N=v}return N})(0),m=h>=l?[]:vr(p=>f(p)>0)(Yt(h,l-1|0)).init;return n.bind((()=>{const p=t.drawText({x:u,y:c,content:De(h)(g),font:i,color:a,align:xo,baseline:xn});return h>0?p:r.pure()})())(()=>o(p=>n.bind(t.measureText(i)(De(p)(g)))(x=>{const y=f(p);return t.drawText({x:u+x,y:c-(1-y)*10,content:De(1)(Ji(gr(De(p)(g)))(g)),font:i,color:{...a,a:de(Vn(y*rt(a.a)))},align:xo,baseline:xn})}))(m))}},fp=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=ri(r),i=gL(t);return a=>{const s={...a.spec,content:DJ(a.spec.content)};if(a.plan.tag==="PlainText")return t.drawText(s);if(a.plan.tag==="RoundedText")return n.bind((()=>{const u=r.pure();if(a.bounds.tag==="Nothing")return u;if(a.bounds.tag==="Just")return t.drawRoundedRect(a.bounds._1)(a.plan._1.radius)(a.plan._1.fill)(a.plan._1.stroke);_()})())(()=>t.drawText(s));if(a.plan.tag==="TokenTravelText"){const u=a.plan._1;return n.bind(o(c=>t.fillPath(zh(c)(1.5))(u.trailFill))(u.trail))(()=>n.bind((()=>{const c=r.pure();if(a.bounds.tag==="Nothing")return c;if(a.bounds.tag==="Just")return t.drawRoundedRect(a.bounds._1)(u.radius)(T("Just",u.fill))(w);_()})())(()=>i(s.font)(s.color)(u.reveal)(u.textLeft)(s.y)(Ur(a.text))))}if(a.plan.tag==="TokenFillingText"){const u=a.plan._1;return n.bind(t.drawRoundedRect(u.shadow)(u.radius)(T("Just",u.shadowFill))(w))(()=>n.bind((()=>{const c=r.pure();if(a.bounds.tag==="Nothing")return c;if(a.bounds.tag==="Just")return t.drawRoundedRect(a.bounds._1)(u.radius)(T("Just",u.fill))(T("Just",u.stroke));_()})())(()=>n.bind(t.strokePath(u.leader)(u.stroke))(()=>t.drawText(s))))}if(a.plan.tag==="AffineText")return t.drawTextAffine(a.plan._1)(s);_()}},_L=t=>e=>n=>r=>o=>i=>a=>op(r)(o)(i)({owner:eo("TokenText",t),text:n.line,spec:{x:o.x,y:o.y,content:n.line,font:{family:e.fontFamily,size:11,weight:500},color:e.chipPillText,align:xo,baseline:xn},bounds:T("Just",r),plan:Ma("TokenTravelText",{trail:$k(r)(a),trailFill:{color:e.trailDot,flat:!0},radius:3,fill:{color:e.chipPillFill,flat:!0},textLeft:r.x+14,reveal:(()=>{const s=n.phaseInLabel/.45;return s<0?0:s>1?1:s})()})}),Tu=t=>e=>n=>r=>{const o=U(f=>rt(ni(1)(un(f).length)))(r),i=nn(1)(b(ur)(0)(o)),a=Fa(e)(n)(t),s=a*i,u=ni(1)(r.length),c=(f=>h=>m=>{let p=f,x=h,y=m,N=!0,v;for(;N;){const J=p,k=x,S=At(A=>w,A=>I=>T("Just",{head:A,tail:I}),y);if(S.tag==="Nothing"){N=!1,v=ni(0)(u-1|0);continue}if(S.tag==="Just"){if(k+S._1.head>=s){N=!1,v=J;continue}p=J+1|0,x=k+S._1.head,y=S._1.tail;continue}_()}return v})(0)(0)(o),g=b(ur)(0)(c<1?[]:Rt(0,c,o)),l=g/i;if(c>=0&&c<o.length){const f=(g+o[c])/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(f<=l)return 1;const h=(a-l)/(f-l);return h<0?0:h>1?1:h})()}}const d=(g+1)/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(d<=l)return 1;const f=(a-l)/(d-l);return f<0?0:f>1?1:f})()}},lp=t=>e=>n=>r=>o=>t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Tu(r)(0)(0)(U(ea)(o)).line))(i=>{const a=i+28;return t.Applicative0().pure({x:n.x+n.w/2-a/2,y:n.y-25.2-14,w:a,h:25.2})}),fL=t=>{const e=t.Bind1(),n=t.Applicative0(),r=so.traverse(n);return o=>i=>a=>e.Apply0().Functor0().map(s=>Kh(wt(u=>u)(s)))(r(s=>{if(s._2.tag==="Filling"&&s._2._1.labels.length!==0){const u=_e(s._2._1.node)(i);if(u.tag==="Just")return e.bind(lp(t)(o)(u._1)(s._2._1.progress)(s._2._1.labels))(c=>n.pure(T("Just",L(s._1,c))));if(u.tag==="Nothing")return n.pure(w);_()}return n.pure(w)})(Ke(a.tokens)))},lL=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const c=T_(n)(r)(o)(i)(a)(s);return t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Tu(i)(a)(s)(Et(u)(J_)).line))(g=>t.Applicative0().pure({x:c.x+14+g/2-g/2-14,y:c.y-6-8-6.6-6,w:g+28,h:25.2}))},dL=t=>{const e=t.Bind1(),n=t.Applicative0(),r=so.traverse(n);return o=>i=>a=>s=>e.Apply0().Functor0().map(u=>Kh(wt(c=>c)(u)))(r(u=>{if(u._2.tag==="Travelling"&&u._2._1.labels.length!==0){const c=_e(u._2._1.target)(i),g=_e(u._2._1.source)(i),l=dr(u._2._1.edge)(a);if(l.tag==="Just"&&g.tag==="Just"&&c.tag==="Just"){const d=(()=>{if(u._2._1.direction==="Forward")return l._1;if(u._2._1.direction==="Backward")return re(l._1);_()})(),f=T_(d)(g._1)(c._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost);return e.bind(lL(t)(o)(d)(g._1)(c._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost)(u._2._1.labels))(h=>n.pure(T("Just",L(u._1,{id:u._1,rect:h,token:f}))))}}return n.pure(w)})(Ke(s.tokens)))},L_=t=>e=>n=>{const r=(e*rt(t+1|0)-rt(n))/1.5,o=r<0?0:r>1?1:r;return o*o*(3-2*o)},Ui=t=>e=>n=>{const r=uL(t)(n)(e.runs);return K(r._1,(()=>{if(r._2.tag==="CatNil")return tt("CatCons",o=>K(st("Return",e.left+o),ct),Z(R,R));if(r._2.tag==="CatCons")return tt("CatCons",r._2._1,Z(r._2._2._1,yt("Cons",tt("CatCons",o=>K(st("Return",e.left+o),ct),Z(R,R)),r._2._2._2)));_()})())},hL=t=>e=>n=>r=>o=>i=>a=>s=>{const u=s<0?0:s>1?1:s,c=nn(8)(o.size*.9),g=(h,m,p,x,y)=>{const N=Ue({path:[],role:cn,layer:w,effects:[Je("GroupAlpha",h)]})(ip(t)(1)(e)(n)(y==="RunCode"||y==="RunCodeHighlight"?{...o,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:o)(y)(m)(p)(cr(x)));return h>.001?N:K(st("Return",void 0),ct)},l=(h,m)=>{const p=un(h.line).length;return L_(p)(u)((p-m|0)-1|0)},d=cp(n)(r)(o)(i),f=h=>{const m=cp(n)(r)(o)(a),p=x=>Hn(y=>{const N=y>=0&&y<h.length?T("Just",h[y]):w,v=y>=0&&y<x.length?T("Just",x[y]):w;return Hn(J=>{if(J.tag==="DiffKeep"){if(N.tag==="Just"){if(v.tag==="Just"){const k=v._1,S=N._1,A=Ui(o)(S)(J._1),I=$=>{const E=Ui(o)(k)(J._2),G=nt=>g(1,$+(nt-$)*u,S.y+(k.y-S.y)*u,J._3,(()=>{if(u<.5){const Q=Et(S.runs)(Y=>Ao(un(Y.text).length,Y.style));return J._1>=0&&J._1<Q.length?Q[J._1]:qr}const V=Et(k.runs)(Q=>Ao(un(Q.text).length,Q.style));return J._2>=0&&J._2<V.length?V[J._2]:qr})());return K(E._1,(()=>{if(E._2.tag==="CatNil")return tt("CatCons",G,Z(R,R));if(E._2.tag==="CatCons")return tt("CatCons",E._2._1,Z(E._2._2._1,yt("Cons",tt("CatCons",G,Z(R,R)),E._2._2._2)));_()})())};return K(A._1,(()=>{if(A._2.tag==="CatNil")return tt("CatCons",I,Z(R,R));if(A._2.tag==="CatCons")return tt("CatCons",A._2._1,Z(A._2._2._1,yt("Cons",tt("CatCons",I,Z(R,R)),A._2._2._2)));_()})())}if(v.tag==="Nothing"){const k=N._1,S=Ui(o)(k)(J._1),A=I=>{const $=l(k,J._1);return g(1-$,I,k.y-c*$,J._3,(()=>{const E=Et(k.runs)(G=>Ao(un(G.text).length,G.style));return J._1>=0&&J._1<E.length?E[J._1]:qr})())};return K(S._1,(()=>{if(S._2.tag==="CatNil")return tt("CatCons",A,Z(R,R));if(S._2.tag==="CatCons")return tt("CatCons",S._2._1,Z(S._2._2._1,yt("Cons",tt("CatCons",A,Z(R,R)),S._2._2._2)));_()})())}_()}if(N.tag==="Nothing"){if(v.tag==="Just"){const k=v._1,S=Ui(o)(k)(J._2),A=I=>{const $=L_(un(k.line).length)(u)(J._2);return g($,I,k.y-c*(1-$),J._3,(()=>{const E=Et(k.runs)(G=>Ao(un(G.text).length,G.style));return J._2>=0&&J._2<E.length?E[J._2]:qr})())};return K(S._1,(()=>{if(S._2.tag==="CatNil")return tt("CatCons",A,Z(R,R));if(S._2.tag==="CatCons")return tt("CatCons",S._2._1,Z(S._2._2._1,yt("Cons",tt("CatCons",A,Z(R,R)),S._2._2._2)));_()})())}if(v.tag==="Nothing")return K(st("Return",void 0),ct)}_()}if(J.tag==="DiffDelete"){if(N.tag==="Just"){const k=N._1,S=Ui(o)(k)(J._1),A=I=>{const $=l(k,J._1);return g(1-$,I,k.y-c*$,J._2,(()=>{const E=Et(k.runs)(G=>Ao(un(G.text).length,G.style));return J._1>=0&&J._1<E.length?E[J._1]:qr})())};return K(S._1,(()=>{if(S._2.tag==="CatNil")return tt("CatCons",A,Z(R,R));if(S._2.tag==="CatCons")return tt("CatCons",S._2._1,Z(S._2._2._1,yt("Cons",tt("CatCons",A,Z(R,R)),S._2._2._2)));_()})())}if(N.tag==="Nothing")return K(st("Return",void 0),ct);_()}if(J.tag==="DiffInsert"){if(v.tag==="Just"){const k=v._1,S=Ui(o)(k)(J._1),A=I=>{const $=L_(un(k.line).length)(u)(J._1);return g($,I,k.y-c*(1-$),J._2,(()=>{const E=Et(k.runs)(G=>Ao(un(G.text).length,G.style));return J._1>=0&&J._1<E.length?E[J._1]:qr})())};return K(S._1,(()=>{if(S._2.tag==="CatNil")return tt("CatCons",A,Z(R,R));if(S._2.tag==="CatCons")return tt("CatCons",S._2._1,Z(S._2._2._1,yt("Cons",tt("CatCons",A,Z(R,R)),S._2._2._2)));_()})())}if(v.tag==="Nothing")return K(st("Return",void 0),ct)}_()})(iL((()=>{if(N.tag==="Nothing")return"";if(N.tag==="Just")return N._1.line;_()})())((()=>{if(v.tag==="Nothing")return"";if(v.tag==="Just")return v._1.line;_()})()))})(Yt(0,ni(h.length)(x.length)-1|0));return K(m._1,(()=>{if(m._2.tag==="CatNil")return tt("CatCons",p,Z(R,R));if(m._2.tag==="CatCons")return tt("CatCons",m._2._1,Z(m._2._2._1,yt("Cons",tt("CatCons",p,Z(R,R)),m._2._2._2)));_()})())};return K(d._1,(()=>{if(d._2.tag==="CatNil")return tt("CatCons",f,Z(R,R));if(d._2.tag==="CatCons")return tt("CatCons",d._2._1,Z(d._2._2._1,yt("Cons",tt("CatCons",f,Z(R,R)),d._2._2._2)));_()})())},dp=t=>e=>n=>r=>o=>i=>a=>s=>{const u=wo(a),c=a.tag==="PloppingOut"&&e.wobble?{alpha:1,scale:1}:u,g=nr((()=>{if(s.tag==="Just"){if(s._1.tag==="StaticNodeLabel")return s._1._1===""?o:s._1._1;if(s._1.tag==="RelabelingNode"){const x=s._1._1.progress<.5?s._1._1.oldLabel:s._1._1.newLabel;return x===""?o:x}_()}if(s.tag==="Nothing")return i.label===""?o:i.label;_()})()),l={family:e.fontFamily,size:e.wobble?15:11,weight:e.wobble?800:500},d=l.size*1.2,f=(i.shape==="Cylinder"?(i.y+(i.y+i.h+5-2*wn(i.h*.075)(i.w*.075)))/2:(i.y+i.y+i.h)/2)-rt(g.length)*d/2+d/2,h=(x,y)=>{const N=Ue({path:[],role:cn,layer:w,effects:[Je("GroupAlpha",x)]})(Hn(v=>k_(t)(1)(e)(o)(l)(i.x+i.w/2)(f+rt(v._1)*d)(v._2))(Ot(vn)(nr(y))));return x>.001?N:K(st("Return",void 0),ct)},m=(x,y)=>Hn(N=>k_(t)(x)(e)(o)(l)(i.x+i.w/2)(f+rt(N._1)*d)(N._2))(Ot(vn)(nr(y))),p=Ue({path:[],role:cn,layer:w,effects:[Je("GroupAlpha",c.alpha*n),Je("GroupTransform",Ko,{tx:(i.x+i.w/2)*(1-c.scale),ty:(i.y+i.h/2)*(1-c.scale),sx:c.scale,sy:c.scale}),Je("GroupAlpha",r)]})((()=>{if(s.tag==="Just"&&s._1.tag==="RelabelingNode"&&Ur(s._1._1.oldLabel)===Ur(s._1._1.newLabel)&&!ne(x=>ne(y=>y.style==="RunHighlight"||y.style==="RunCodeHighlight",fr(x)),nr(s._1._1.oldLabel))&&ne(x=>ne(y=>y.style==="RunHighlight"||y.style==="RunCodeHighlight",fr(x)),nr(s._1._1.newLabel)))return m(s._1._1.progress<0?0:s._1._1.progress>1?1:s._1._1.progress,s._1._1.newLabel);if(s.tag==="Just"&&s._1.tag==="RelabelingNode"&&Ur(s._1._1.oldLabel)===Ur(s._1._1.newLabel)&&ne(x=>ne(y=>y.style==="RunHighlight"||y.style==="RunCodeHighlight",fr(x)),nr(s._1._1.oldLabel))&&!ne(x=>ne(y=>y.style==="RunHighlight"||y.style==="RunCodeHighlight",fr(x)),nr(s._1._1.newLabel)))return m(s._1._1.progress<0?1:s._1._1.progress>1?0:1-s._1._1.progress,s._1._1.oldLabel);if(s.tag==="Just"&&s._1.tag==="RelabelingNode"){if(Ur(s._1._1.oldLabel)===Ur(s._1._1.newLabel)){const x=s._1._1,y=h(x.progress<0?1:x.progress>1?0:1-x.progress,x.oldLabel),N=()=>h(x.progress<0?0:x.progress>1?1:x.progress,x.newLabel);return K(y._1,(()=>{if(y._2.tag==="CatNil")return tt("CatCons",N,Z(R,R));if(y._2.tag==="CatCons")return tt("CatCons",y._2._1,Z(y._2._2._1,yt("Cons",tt("CatCons",N,Z(R,R)),y._2._2._2)));_()})())}return hL(t)(e)(o)(i)(l)(s._1._1.oldLabel)(s._1._1.newLabel)(s._1._1.progress)}return Hn(x=>k_(t)(1)(e)(o)(l)(i.x+i.w/2)(f+rt(x._1)*d)(x._2))(Ot(vn)(g))})());return r>0&&c.alpha*n>0?p:K(st("Return",void 0),ct)},hp=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>g=>l=>d=>{const f=Qa({id:c,role:t,geometry:Ia("FlatNode",{shape:g.shape,bounds:{x:g.x,y:g.y,w:g.w,h:g.h}}),alpha:i,plan:Ba("FlatNodePlan",{palette:o,label:(()=>{if(d.tag==="Just"){if(d._1.tag==="StaticNodeLabel")return d._1._1===""?c:d._1._1;if(d._1.tag==="RelabelingNode"){const m=d._1._1.progress<.5?d._1._1.oldLabel:d._1._1.newLabel;return m===""?c:m}_()}if(d.tag==="Nothing")return g.label===""?c:g.label;_()})(),labelVisibility:n,inkBoost:r,labelAlpha:s,outlineAlpha:a,arrival:u,animState:l})}),h=()=>{if(n==="LabelsHidden")return K(st("Return",void 0),ct);if(n==="LabelsShown")return dp(e)(o)(i)(s)(c)(g)(l)(d);_()};return K(f._1,(()=>{if(f._2.tag==="CatNil")return tt("CatCons",h,Z(R,R));if(f._2.tag==="CatCons")return tt("CatCons",f._2._1,Z(f._2._2._1,yt("Cons",tt("CatCons",h,Z(R,R)),f._2._2._2)));_()})())},pp=t=>e=>n=>{const r={...t,nodeFill:t.text,text:t.nodeFill,nodeStroke:t.nodeFill};return Hn(o=>{const i=_e(o._1)(n.nodes),a=_e(o._1)(e.nodes),s=a.tag==="Just"&&i.tag==="Just"?Ue({path:[],role:cn,layer:w,effects:[Je("GroupAlpha",o._2)]})(hp(q3)(n.animationTime)(__)(1)(r)(1)(w)(1)(w)(o._1)((()=>{const u=_e(o._1)(n.nodeLabels);if(u.tag==="Nothing")return a._1;if(u.tag==="Just"){if(u._1.tag==="StaticNodeLabel")return{...a._1,label:u._1._1===""?o._1:u._1._1};if(u._1.tag==="RelabelingNode")return{...a._1,label:(()=>{const c=u._1._1.progress<.5?u._1._1.oldLabel:u._1._1.newLabel;return c===""?o._1:c})()}}_()})())(i._1)(_e(o._1)(n.nodeLabels))):K(st("Return",void 0),ct);return o._2>0?s:K(st("Return",void 0),ct)})(Ke(n.nodeInvert))},mp=t=>e=>n=>{const r=Hc(6)(.55)(w_(0)(1)((1-t)/.06)),o=t>.94,i=o&&n>1e-4,a=Hc(6)(.55)(w_(0)(1)(t/.06)),s=t<.06,u=s&&e>1e-4,c=o&&n<=1e-4;return{popScale:u?a:i?r:1,flipY:s&&e<=1e-4?a:c?r:1,fadeAlpha:(()=>{if(u){const g=t/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}if(i){const g=(1-t)/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}return 1})()}},pL=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>o=>{const i=o.length-1|0,a=i<1?[]:Rt(0,i,o),s=a.length-1|0,u=s>=0&&s<a.length?T("Just",a[s]):w,c=o.length-1|0,g=c>=0&&c<o.length?T("Just",o[c]):w;if(g.tag==="Just"&&u.tag==="Just"){const l=Fe(.78)(1.18)(Wa(o)+19|0),d=Fe(.4)(.62)(l.prng),f=r.wobble?8.75*d.value:4.375,h=Fe(.4)(.62)(d.prng),m=r.wobble?8.75*h.value:4.375,p=g._1.y-u._1.y,x=g._1.x-u._1.x,y=tn(x*x+p*p),N=p/y,v=-N,J=x/y,k=g._1.x+J*.875,S=g._1.y+N*.875,A=r.wobble?8.75*l.value:8.75,I=k-J*A,$=S-N*A,E=I+v*f,G=$+J*f,nt=[1,k,S,2,I+v*4.375,$+J*4.375,2,I-v*4.375,$-J*4.375,5],V=I-v*m,Q=$-J*m,Y={color:r.arrowFill,width:2,lineJoin:Ye,lineCap:lr};return y<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,E,G,2,k,S])(Y))(()=>t.strokePath([1,V,Q,2,k,S])(Y)):t.fillPath(nt)({color:r.arrowFill,flat:!0})}return n.pure()}},mL=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=ri(n),i=t.popAlpha,a=pL(t);return s=>u=>c=>g=>l=>{const d=ek(8)(g),f=c&&l.hi>=.9&&(1-l.hi)*xs(d)<=8.75?1:l.hi;if(f<=l.lo)return n.pure();const h=ck(d)(l.lo)(f);if(h.length===0)return n.pure();const m={color:s.edge,width:s.wobble?2:.9375,lineJoin:Ye,lineCap:lr},p=s.wobble?Fe(-10)(4)(Wa(h)).value:0,x=s.wobble?Ck(p)(h):h;return r.bind(s.wobble?o(y=>r.bind(t.pushAlpha(y.alpha))(()=>r.bind(t.strokePath(y.path)(m))(()=>i)))((()=>{const y=Wa(h);return x.length<2?[]:$i(Kk)(y)(!1)(x)})()):t.strokePath(j3(h))(m))(()=>{const y=a(s)(x);return u&&f>=.999?y:n.pure()})}},yL=t=>{const e=mL(t);return n=>n.geometry.tag==="FlatRoute"&&n.plan.tag==="FlatEdgePlan"?e(n.plan._1)(n.arrow)(n.settlingAtTarget)(n.geometry._1)(n.visible):t.Monad0().Applicative0().pure()},xL=t=>e=>{const n=i=>{const a=_e(i)(t.nodes);if(a.tag==="Nothing")return!1;if(a.tag==="Just"){const s=a._1;return!ne(u=>0<u._2.length&&u._2[0].x>=s.x&&u._2[0].x<=s.x+s.w&&u._2[0].y>=s.y&&u._2[0].y<=s.y+s.h,Ke(t.edges))}_()},r=b(i=>a=>(i*31|0)+ho(a)|0)(5381)(Bn(e.frameTitle)),o=i=>{const a=_e(i)(t.nodes);if(a.tag==="Nothing")return!1;if(a.tag==="Just"){const s=a._1;return!ne(u=>{const c=u._2.length-1|0;return c>=0&&c<u._2.length&&u._2[c].x>=s.x&&u._2[c].x<=s.x+s.w&&u._2[c].y>=s.y&&u._2[c].y<=s.y+s.h},Ke(t.edges))}_()};return b(i=>a=>{const s=a._2;return Fk(u=>{if(u.tag==="Nothing")return T("Just",s);if(u.tag==="Just")return T("Just",{t:nn(u._1.t)(s.t),angle:s.t>=u._1.t?s.angle:u._1.angle,bigCircle:u._1.bigCircle||s.bigCircle,frameHash:u._1.frameHash});_()})(a._1)(i)})(M)(Et(Ke(e.tokens))(i=>{if(i._2.tag==="Filling"){const a=i._2._1.node;return[L(a,{t:1,angle:(()=>{const s=wt(u=>(()=>{const c=_e(a)(t.nodes),g=u._2.length-1|0;return g>=0&&g<u._2.length&&c.tag==="Just"&&u._2[g].x>=c._1.x&&u._2[g].x<=c._1.x+c._1.w&&u._2[g].y>=c._1.y&&u._2[g].y<=c._1.y+c._1.h})()?T("Just",u._2):w)(Ke(t.edges));if(0<s.length){const u=s[0].length-1|0,c=u<1?[]:Rt(0,u,s[0]),g=c.length-1|0;if(g>=0&&g<c.length){const l=s[0].length-1|0;return l>=0&&l<s[0].length?Po(s[0][l].y-c[g].y)(s[0][l].x-c[g].x):0}s[0].length-1|0}return 0})(),bigCircle:n(a)||o(a),frameHash:r})]}if(i._2.tag==="Travelling"){if(i._2._1.progress>=.75)return[L(i._2._1.target,{t:(i._2._1.progress-.75)/.25,angle:(()=>{const a=dr(i._2._1.edge)(t.edges);if(a.tag==="Just"){const s=a._1.length-1|0,u=s<1?[]:Rt(0,s,a._1),c=u.length-1|0;if(c>=0&&c<u.length){const g=a._1.length-1|0;return g>=0&&g<a._1.length?Po(a._1[g].y-u[c].y)(a._1[g].x-u[c].x):0}return a._1.length-1|0,0}if(a.tag==="Nothing")return 0;_()})(),bigCircle:n(i._2._1.target)||o(i._2._1.target),frameHash:r})];if(i._2._1.progress<.25)return[L(i._2._1.source,{t:i._2._1.progress/.25,angle:(()=>{const a=dr(i._2._1.edge)(t.edges);if(a.tag==="Just")return 1<a._1.length&&0<a._1.length?Po(a._1[1].y-a._1[0].y)(a._1[1].x-a._1[0].x):0;if(a.tag==="Nothing")return 0;_()})(),bigCircle:n(i._2._1.source)||o(i._2._1.source),frameHash:r})]}return[]}))},wL=t=>b(e=>n=>(e*31|0)+ho(n)|0)(5381)(Bn(t.frameTitle)),yp=t=>e=>n=>r=>o=>i=>{const a=wL(i),s=xL(o)(i);return Hn(u=>{const c=_e(u._1)(i.nodes);if(c.tag==="Just")return hp(g_)(i.animationTime)(e)(n)(r)((()=>{const g=_e(u._1)(i.nodeFadeAlpha);if(g.tag==="Nothing")return 1;if(g.tag==="Just")return g._1;_()})())(t(u._1))((()=>{const g=_e(u._1)(i.nodeLabelFadeAlpha);if(g.tag==="Nothing")return 1;if(g.tag==="Just")return g._1;_()})())((()=>{const g=_e(u._1)(s);return g.tag==="Just"?T("Just",g._1):g.tag==="Nothing"&&Ik(u._1)(i.visited)?T("Just",{t:1,angle:0,bigCircle:!1,frameHash:a}):w})())(u._1)((()=>{const g=_e(u._1)(i.nodeLabels);if(g.tag==="Nothing")return u._2;if(g.tag==="Just"){if(g._1.tag==="StaticNodeLabel")return{...u._2,label:g._1._1===""?u._1:g._1._1};if(g._1.tag==="RelabelingNode")return{...u._2,label:(()=>{const l=g._1._1.progress<.5?g._1._1.oldLabel:g._1._1.newLabel;return l===""?u._1:l})()}}_()})())(c._1)(_e(u._1)(i.nodeLabels));if(c.tag==="Nothing")return K(st("Return",void 0),ct);_()})(Ke(o.nodes))},xp=t=>e=>n=>r=>o=>i=>{const a=o.x+o.w/2<=i.x+i.w/2,s=a?Kr:Yr,u=a?Yr:Kr,c=nn(o.y)(i.y),g=On(o.y+o.h)(i.y+i.h);return Kt(up(t)(e)(n))(wt(l=>{if(c>g)return w;const d=qe(i.shape)({x:i.x,y:i.y,w:i.w,h:i.h})(u)(l),f=qe(o.shape)({x:o.x,y:o.y,w:o.w,h:o.h})(s)(l);return(a?d>=f+1e-6:f>=d+1e-6)?T("Just",[{x:f,y:l},{x:d,y:l}]):w})(_p(c)(g)(wt(l=>l)([(()=>{if(0<r.length){const l=r.length-1|0;if(l>=0&&l<r.length){const d=r[l];if((()=>{const f=r[0].y-d.y;return f<0?-f<=1e-6:f<=1e-6})())return T("Just",(r[0].y+d.y)/2)}}return w})(),T("Just",i.y+i.h/2),T("Just",o.y+o.h/2)]))))},wp=t=>e=>n=>r=>o=>i=>{const a=o.y+o.h/2<=i.y+i.h/2,s=a?Vr:Xr,u=a?Xr:Vr,c=nn(o.x)(i.x),g=On(o.x+o.w)(i.x+i.w);return Kt(up(t)(e)(n))(wt(l=>{if(c>g)return w;const d=qe(i.shape)({x:i.x,y:i.y,w:i.w,h:i.h})(u)(l),f=qe(o.shape)({x:o.x,y:o.y,w:o.w,h:o.h})(s)(l);return(a?d>=f+1e-6:f>=d+1e-6)?T("Just",[{x:l,y:f},{x:l,y:d}]):w})(_p(c)(g)(wt(l=>l)([(()=>{if(0<r.length){const l=r.length-1|0;if(l>=0&&l<r.length){const d=r[l];if((()=>{const f=r[0].x-d.x;return f<0?-f<=1e-6:f<=1e-6})())return T("Just",(r[0].x+d.x)/2)}}return w})(),T("Just",i.x+i.w/2),T("Just",o.x+o.w/2)]))))},NL=t=>e=>n=>r=>{const o=_e(e)(t);if(o.tag==="Just"){const i=_e(n)(t);if(i.tag==="Just"){if((()=>{const u=i._1.y+i._1.h/2-(o._1.y+o._1.h/2),c=i._1.x+i._1.w/2-(o._1.x+o._1.w/2);return(u<0?-u:u)>=(c<0?-c:c)})()){const u=wp(t)(e)(n)(r)(o._1)(i._1),c=xp(t)(e)(n)(r)(o._1)(i._1);if(u.tag==="Just")return T("Just",u._1);if(u.tag==="Nothing")return c;_()}const a=xp(t)(e)(n)(r)(o._1)(i._1),s=wp(t)(e)(n)(r)(o._1)(i._1);if(a.tag==="Just")return T("Just",a._1);if(a.tag==="Nothing")return s;_()}if(i.tag==="Nothing")return w;_()}if(o.tag==="Nothing")return w;_()},Xi=t=>e=>n=>{const r=zk(t);return Qe(P.compare,Be,Bk(wt(o=>{const i=dr(o._1)(t.edges);if(i.tag==="Just"){const a=NL(n)(o._2.source)(o._2.target)(i._1);return a.tag==="Just"?T("Just",L(o._1,a._1)):w}if(i.tag==="Nothing")return w;_()})(Ke(e))),(()=>{const o=i=>{if(i.tag==="Leaf")return M;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));_()};return o(t.edges)})())},Np=t=>e=>n=>Hn((()=>{const r=Xi(e)(n.edgeEndpoints)(e.nodes);return o=>{const i=dr(o._1)(n.edges);if(i.tag==="Just"){const a=dr(o._1)(n.edgeFadeAlpha),s=(()=>{if(a.tag==="Nothing")return 1;if(a.tag==="Just")return a._1;_()})(),u=Gh({id:o._1,geometry:Th("FlatRoute",(()=>{const c=dr(o._1)(r);if(c.tag==="Nothing")return o._2;if(c.tag==="Just")return c._1;_()})()),visible:P3(i._1),arrow:(()=>{const c=Yn("conn:")(o._1);if(c.tag==="Just")return!1;if(c.tag==="Nothing")return!0;_()})(),settlingAtTarget:i._1.tag==="Extending"&&i._1._1==="ExtendFromSource",plan:vh("FlatEdgePlan",t)});return s===1?u:Ue({path:[],role:cn,layer:w,effects:[Je("GroupAlpha",s)]})(u)}if(i.tag==="Nothing")return K(st("Return",void 0),ct);_()}})())(Ke(e.edges)),vu=t=>e=>n=>r=>{const o=e.nodes,i=Xi(e)(n.edgeEndpoints)(e.nodes);return Ue({path:[],role:cn,layer:T("Just",jC),effects:[]})(Hn(a=>{if(a._2.tag==="Travelling"){if(a._2._1.labels.length!==0){const s=_e(a._2._1.target)(o),u=_e(a._2._1.source)(o),c=dr(a._2._1.edge)(i),g=jh(a._1)(r);if(g.tag==="Just"&&c.tag==="Just"&&u.tag==="Just"&&s.tag==="Just")return _L(a._1)(t)(Tu(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(Et(a._2._1.labels)(J_)))(g._1)({x:g._1.x+g._1.w/2,y:g._1.y+g._1.h/2})(mp(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost))(T_((()=>{if(a._2._1.direction==="Forward")return c._1;if(a._2._1.direction==="Backward")return re(c._1);_()})())(u._1)(s._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost))}return K(st("Return",void 0),ct)}if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const s=_e(a._2._1.node)(o);if(s.tag==="Just"){const u=s._1,c=lp(Yg)(Ph)(u)(a._2._1.progress)(a._2._1.labels),g=l=>Yk(a._1)(t)(Tu(a._2._1.progress)(0)(0)(Et(a._2._1.labels)(J_)).line)(u)(l)({x:l.x+l.w/2,y:l.y+l.h/2})(mp(a._2._1.progress)(0)(0));return K(c._1,(()=>{if(c._2.tag==="CatNil")return tt("CatCons",g,Z(R,R));if(c._2.tag==="CatCons")return tt("CatCons",c._2._1,Z(c._2._2._1,yt("Cons",tt("CatCons",g,Z(R,R)),c._2._2._2)));_()})())}if(s.tag==="Nothing")return K(st("Return",void 0),ct);_()}return K(st("Return",void 0),ct)})(Ke(n.tokens)))},Tp=t=>e=>n=>r=>{if(e.tokenInsideBlend==="Difference"){const o=n.nodes,i=Xi(n)(r.edgeEndpoints)(n.nodes),a=X3(t),s=u=>{const c=Ue({path:[],role:cn,layer:T("Just",YC),effects:[Je("GroupBlend",fu),Je("GroupClip",b_(o)(r),Qi)]})(C_(Eh)(u==="ConvexAbsorb"?Mk:N_)(e.wobble)(o)(i)(r)(e.tokenInside)(e.tokenInsideStroke)),g=()=>Ue({path:[],role:cn,layer:T("Just",KC),effects:[]})(Hn(l=>{const d=_e(l._1)(r.nodes);return d.tag==="Just"&&wo(d._1).alpha>0?pu(hu("FloorOverlay",{path:Zo(l._2),fill:T("Just",{color:Ne,flat:!1}),stroke:w})):K(st("Return",void 0),ct)})(Ke(o)));return K(c._1,(()=>{if(c._2.tag==="CatNil")return tt("CatCons",g,Z(R,R));if(c._2.tag==="CatCons")return tt("CatCons",c._2._1,Z(c._2._2._1,yt("Cons",tt("CatCons",g,Z(R,R)),c._2._2._2)));_()})())};return K(a._1,(()=>{if(a._2.tag==="CatNil")return tt("CatCons",s,Z(R,R));if(a._2.tag==="CatCons")return tt("CatCons",a._2._1,Z(a._2._2._1,yt("Cons",tt("CatCons",s,Z(R,R)),a._2._2._2)));_()})())}if(e.tokenInsideBlend==="Normal")return Ue({path:[],role:cn,layer:w,effects:[Je("GroupClip",b_(n.nodes)(r),Qi),Je("GroupAlpha",e.tokenInsideAlpha)]})(C_(Eh)(N_)(e.wobble)(n.nodes)(Xi(n)(r.edgeEndpoints)(n.nodes))(r)(e.tokenInside)(e.tokenInsideStroke));_()},S_=t=>e=>n=>r=>Ue({path:[],role:cn,layer:T("Just",VC),effects:[Je("GroupClip",Wk(e)(n.nodes)(r),e_)]})(C_(Sh)(N_)(t.wobble)(n.nodes)(Xi(n)(r.edgeEndpoints)(n.nodes))(r)(t.tokenOutsideFill)(t.tokenOutsideStroke)),E_=t=>{const e=t.Bind1(),n=dL(t),r=fL(t);return o=>i=>a=>s=>{const u=a.nodes;return e.bind(n(o)(u)(Xi(a)(s.edgeEndpoints)(a.nodes))(s))(c=>e.bind(r(o)(u)(s))(g=>t.Applicative0().pure(xk({x:i.vx,y:i.vy,w:i.vw,h:i.vh})([...wt(l=>{const d=_e(l._1)(s.nodes);return d.tag==="Just"&&wo(d._1).alpha>0?T("Just",{x:l._2.x,y:l._2.y,w:l._2.w,h:l._2.h}):w})(Ke(u)),...(()=>{const l=(d,f)=>{if(d.tag==="Leaf")return f;if(d.tag==="Node")return l(d._5,yt("Cons",d._4,l(d._6,f)));_()};return Wt(ue.foldr,l(g,R))})()])(wt(l=>jh(l)(c))((()=>{const l=d=>{if(d.tag==="Leaf")return M;if(d.tag==="Node")return ee("Node",d._1,d._2,d._3,void 0,l(d._5),l(d._6));_()};return Gt(P.compare)(Wt(ln.foldr,l(c)))})())))))}},TL=E_(Yg),vp=t=>e=>n=>r=>{const o=TL(Ph)(e)(n)(r);return K(o._1,(()=>{if(o._2.tag==="CatNil")return tt("CatCons",i=>vu(t)(n)(r)(i),Z(R,R));if(o._2.tag==="CatCons")return tt("CatCons",o._2._1,Z(o._2._2._1,yt("Cons",tt("CatCons",i=>vu(t)(n)(r)(i),Z(R,R)),o._2._2._2)));_()})())},vL=t=>e=>n=>{const r=ut.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=ut.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},bp=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},Jp=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},A_=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Cp=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},bL=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},P_=(()=>{const t=mn.unfoldr(sr);return e=>t(yn("IterNode",e,ir))})(),JL=io(yo)(Mt),CL=t=>e=>{const n=fn(t.angle),r=Dn(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},kL=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=>vL(0)(255)(de(Fn(rt(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},rn=t=>e=>n=>r=>({x:(e-n)*Dn(t.angle),y:(e+n)*fn(t.angle)-r}),G_=t=>{const e=At(n=>w,n=>r=>T("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,...Et(e._1.tail)(n=>[2,n.x,n.y]),5];_()},LL=t=>e=>n=>{const r=n.id,o=n.np,i=Qa({id:r,role:g_,geometry:Ia("IsoSlab",{south:[n.box.ground.d,n.box.ground.c,n.box.top.c,n.box.top.d],east:[n.box.ground.b,n.box.ground.c,n.box.top.c,n.box.top.b],top:[n.box.top.a,n.box.top.b,n.box.top.c,n.box.top.d]}),alpha:1,plan:Ba("IsoNodePlan",{config:t,palette:e})}),a=()=>jo({owner:eo("NodeText",r),text:o.label,spec:{x:o.x+o.w/2,y:0,content:o.label,font:{family:e.fontFamily,size:11,weight:600},color:e.text,align:Zr,baseline:xn},bounds:w,plan:Ma("AffineText",CL(t)(o.y+o.h))});return K(i._1,(()=>{if(i._2.tag==="CatNil")return tt("CatCons",a,Z(R,R));if(i._2.tag==="CatCons")return tt("CatCons",i._2._1,Z(i._2._2._1,yt("Cons",tt("CatCons",a,Z(R,R)),i._2._2._2)));_()})())},SL=t=>e=>n=>r=>o=>{const i=$e(vn,o,Rt(1,o.length,o)),a=i.length-1|0;return Ot(s=>u=>({depth:(u._1.x+u._1.y+u._2.x+u._2.y)/2,draw:Gh({id:n,geometry:Th("IsoSegments",[[rn(t)(u._1.x)(u._1.y)(0),rn(t)(u._2.x)(u._2.y)(0)]]),visible:{lo:0,hi:1},arrow:r&&s===a,settlingAtTarget:!1,plan:vh("IsoEdgePlan",{config:t,palette:e})})}))(i)},EL=t=>e=>n=>r=>o=>{const i=(()=>{if(t==="Forward")return o;if(t==="Backward")return re(o);_()})();if(0<i.length){const s=Ci(i)(bp(0)(1)(Fa(n)(r)(e)));if(s.tag==="Nothing")return i[0];if(s.tag==="Just")return s._1;_()}const a=Ci(i)(bp(0)(1)(Fa(n)(r)(e)));if(a.tag==="Nothing")return{x:0,y:0};if(a.tag==="Just")return a._1;_()},AL=t=>{const e=At(n=>w,n=>r=>T("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,...Et(e._1.tail)(n=>[2,n.x,n.y])];_()},PL=t=>{const e=At(n=>w,n=>r=>T("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=b(r=>o=>({minX:Jp(r.minX)(o.x),minY:Jp(r.minY)(o.y),maxX:A_(r.maxX)(o.x),maxY:A_(r.maxY)(o.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}}_()},RL=t=>{const e=t.Monad0(),n=e.Bind1();return r=>{if(r.geometry.tag==="IsoSlab"&&r.plan.tag==="IsoNodePlan"){const o=r.geometry._1,i=r.plan._1.palette,a=(s,u)=>t.fillStrokePath(G_(s))({color:u,flat:!0})({color:i.nodeStroke,width:1,lineJoin:Ye,lineCap:Ln});return n.bind(a(o.south,R_(.66)(i.nodeFill)))(()=>n.bind(a(o.east,R_(.82)(i.nodeFill)))(()=>a(o.top,i.nodeFill)))}return e.Applicative0().pure()}},GL=t=>{const e=t.Monad0(),n=e.Bind1();return r=>{if(r.geometry.tag==="IsoCube"&&r.plan.tag==="IsoTokenPlan"){const o=r.geometry._1,i=r.plan._1.palette,a=(s,u)=>t.fillStrokePath(G_(s))({color:R_(u)(i.tokenOutsideFill),flat:!0})({color:i.tokenOutsideStroke,width:1,lineJoin:Ye,lineCap:Ln});return n.bind(a(o.south,.66))(()=>n.bind(a(o.east,.82))(()=>a(o.top,1)))}return e.Applicative0().pure()}},DL={angle:.5235987755982988,boxHeight:26,transparentBg:!0},FL=t=>e=>n=>{const r=Cp(t)(n.nodeLabels);if(r.tag==="Just"){if(r._1.tag==="StaticNodeLabel")return r._1._1===""?t:r._1._1;if(r._1.tag==="RelabelingNode"){const o=r._1._1.progress<.5?r._1._1.oldLabel:r._1._1.newLabel;return o===""?t:o}_()}if(r.tag==="Nothing")return e.label===""?t:e.label;_()},IL=t=>e=>n=>{const r=n.x-5.5,o=n.x+5.5,i=n.y-5.5,a=n.y+5.5,s=e+11,u=rn(t)(o)(i)(s),c=rn(t)(o)(a)(s),g=rn(t)(r)(a)(s),l=rn(t)(o)(a)(e);return{south:[rn(t)(r)(a)(e),l,c,g],east:[rn(t)(o)(i)(e),l,c,u],top:[rn(t)(r)(i)(s),u,c,g]}},BL=t=>e=>n=>r=>{const o=r._1,i=(a,s)=>({depth:s.x+s.y,draw:Dh({id:o,pass:Sh,geometry:Jh("IsoCube",IL(t)(a)(s)),position:s,plan:kh("IsoTokenPlan",{config:t,palette:e,baseZ:a})})});if(r._2.tag==="Travelling"){const a=bL(r._2._1.edge)(n.edges);return a.tag==="Just"?T("Just",i(0,EL(r._2._1.direction)(r._2._1.progress)(r._2._1.holdPre)(r._2._1.holdPost)(a._1))):w}if(r._2.tag==="Filling"){const a=Cp(r._2._1.node)(n.nodes);if(a.tag==="Just")return T("Just",i(t.boxHeight,{x:a._1.x+a._1.w/2,y:a._1.y+a._1.h/2}))}return w},ML=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:rn(t)(e.x)(e.y)(0),b:rn(t)(r)(e.y)(0),c:rn(t)(r)(n)(0),d:rn(t)(e.x)(n)(0)},top:{a:rn(t)(e.x)(e.y)(t.boxHeight),b:rn(t)(r)(e.y)(t.boxHeight),c:rn(t)(r)(n)(t.boxHeight),d:rn(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},kp=t=>e=>U(n=>({id:n._1,np:n._2,box:ML(t)(n._2)}))(P_(e.nodes)),zL=t=>e=>[...Et(kp(t)(e))(kL),...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,yt("Cons",r._4,n(r._6,o)));_()};return Et(Wt(ue.foldr,n(e.edges,R)))(U(r=>rn(t)(r.x)(r.y)(0)))})()],QL=t=>e=>n=>U(r=>({...r,np:{...r.np,label:FL(r.id)(r.np)(n)}}))(kp(t)(e)),WL=t=>e=>n=>r=>{const o=v_(e),i=[...Et(P_(n.edges))(u=>SL(t)(o)(u._1)((()=>{const c=Yn("conn:")(u._1);if(c.tag==="Just")return!1;if(c.tag==="Nothing")return!0;_()})())(u._2)),...U(u=>({depth:u.box.depth,draw:LL(t)(o)(u)}))(QL(t)(n)(r)),...wt(BL(t)(o)(n))(P_(r.tokens))],a=Rh({viewport:PL(zL(t)(n)),clear:T("Just",t.transparentBg?o.bgTransparent:o.bg),dots:w}),s=()=>JL(u=>u.draw)(Gt(u=>c=>at.compare(u.depth)(c.depth))(i));return K(a._1,(()=>{if(a._2.tag==="CatNil")return tt("CatCons",s,Z(R,R));if(a._2.tag==="CatCons")return tt("CatCons",a._2._1,Z(a._2._2._1,yt("Cons",tt("CatCons",s,Z(R,R)),a._2._2._2)));_()})())},OL=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=A_(1e-4)(tn(n*n+e*e)),o=e/r,i=n/r,a=t.to.y-o*7,s=t.to.x-i*7;return G_([t.to,{x:s-o*3,y:a+i*3},{x:s+o*3,y:a-i*3}])},HL=t=>{const e=t.Monad0(),n=e.Applicative0(),r=io(n)(Mt);return o=>{if(o.geometry.tag==="IsoSegments"&&o.plan.tag==="IsoEdgePlan"){const i=o.plan._1.palette,a=o.geometry._1;return e.Bind1().bind(r(s=>t.strokePath(AL(s))({color:i.edge,width:1.5,lineJoin:Ye,lineCap:lr}))(a))(()=>{const s=a.length-1|0;if(s>=0&&s<a.length){const c=a[s],g=c.length-1|0,l=g<1?[]:Rt(0,g,c),d=l.length-1|0;if(d>=0&&d<l.length){const h=a.length-1|0,m=(()=>{if(h>=0&&h<a.length){const p=a[h],x=p.length-1|0;if(x>=0&&x<p.length)return t.fillPath(OL({from:l[d],to:p[x]}))({color:i.arrowFill,flat:!0})}return n.pure()})();return o.arrow?m:n.pure()}a.length-1|0;const f=n.pure();return o.arrow?f:n.pure()}a.length-1|0;const u=n.pure();return o.arrow?u:n.pure()})}return n.pure()}},Lp=(t,e)=>({tag:t,_1:e}),D_=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;_()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;_()},F_=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},oi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},$L=yi(yo)(Mt),qL=Lp("ResolvedLabels"),UL=t=>{const e=Kt(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return Qs(t);_()},XL=t=>e=>n=>{const r=D_(0)(1)((n-t)/F_(1e-6)(e-t));return r*r*(3-2*r)},$a=t=>e=>{const n=F_(1)(pe(e.rootLayout).w),r=!e.diving&&e.levels.length===1,o=r?1:e.diving?1-D_(0)(1)(e.doorProgress):0,i=Kn(e.rootLayout)(e.camera),a=r?1:D_(0)(1)(i.w/n),s=Qs(e).state.frameTitle===""?0*a*o:40*a*o,u=t.padding*a*a*o;return(()=>{if(t.outputAspect.tag==="Nothing")return ew;if(t.outputAspect.tag==="Just")return b1(t.outputAspect._1);_()})()({vx:i.x-u,vy:i.y-u-s,vw:i.w+2*u,vh:i.h+2*u+s})},VL=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=oi(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,o=n._1.y*t.segment.placement.scale+t.segment.placement.ty,i=n._1.w*t.segment.placement.scale,a=n._1.h*t.segment.placement.scale;return[1,r,o,2,r+i,o,2,r+i,o+a,2,r,o+a,5]}}_()},I_=t=>e=>{const n=Xy(e.segment.placement)({x:t.vx,y:t.vy,w:t.vw,h:t.vh});return{vx:n.x,vy:n.y,vw:n.w,vh:n.h}},Sp=t=>e=>t===""?K(st("Return",void 0),ct):jo({owner:O3,text:t,spec:{x:e.vx+6,y:e.vy+6,content:t,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:xo,baseline:UC},bounds:w,plan:Hi}),Ep=t=>e=>{if(t==="")return K(st("Return",void 0),ct);const n=e.vh/720,r=56*n,o=jr({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:56,weight:700})(t),i=a=>{const s=r+16*n*2,u=a*n+28*n*2,c=e.vy+e.vh/2,g=e.vx+e.vw/2,l={x:g-u/2,y:c-s/2,w:u,h:s};return pu(hu("TitleCardOverlay",{backing:{path:Oi(l)(16*n),fill:T("Just",{color:{r:255,g:255,b:255,a:235},flat:!0}),stroke:T("Just",{color:{r:0,g:0,b:0,a:255},width:1.5*n,lineJoin:Ye,lineCap:lr})},text:{owner:Ah,text:t,spec:{x:g,y:c,content:t,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:r,weight:700},color:{r:28,g:30,b:36,a:255},align:Zr,baseline:xn},bounds:T("Just",l),plan:Hi}}))};return K(o._1,(()=>{if(o._2.tag==="CatNil")return tt("CatCons",i,Z(R,R));if(o._2.tag==="CatCons")return tt("CatCons",o._2._1,Z(o._2._2._1,yt("Cons",tt("CatCons",i,Z(R,R)),o._2._2._2)));_()})())},Ap=t=>e=>{if(t==="")return K(st("Return",void 0),ct);const n=e.vh/720,r=15*n,o=jr({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:15,weight:600})(t),i=a=>{const s=e.vy+12*n,u=r+6*n*2,c=a*n+11*n*2,g=e.vx+e.vw/2,l={x:g-c/2,y:s,w:c,h:u};return pu(hu("FrameTitleOverlay",{backing:T("Just",{path:Oi(l)(u/2),fill:T("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}),stroke:T("Just",{color:{r:0,g:0,b:0,a:255},width:1*n,lineJoin:Ye,lineCap:lr})}),text:{owner:Ah,text:t,spec:{x:g,y:s+u/2,content:t,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:r,weight:600},color:{r:28,g:30,b:36,a:255},align:Zr,baseline:xn},bounds:T("Just",l),plan:Hi}}))};return K(o._1,(()=>{if(o._2.tag==="CatNil")return tt("CatCons",i,Z(R,R));if(o._2.tag==="CatCons")return tt("CatCons",o._2._1,Z(o._2._2._1,yt("Cons",tt("CatCons",i,Z(R,R)),o._2._2._2)));_()})())},YL=t=>e=>n=>r=>o=>i=>a=>s=>{const u=v_(t.theme),c=(()=>{if(s.tag==="ResolvedLabels")return vp(u)(o)(i)(a);if(s.tag==="SpringLabels")return vu(u)(i)(a)(gp(o)(s._1));_()})(),g=Rh({viewport:o,clear:T("Just",t.transparentBg?u.bgTransparent:u.bg),dots:w}),l=()=>{const d=Ue({path:[],role:cn,layer:w,effects:n<1?[Je("GroupAlpha",n)]:[]})((()=>{const f=Np(u)(i)(a),h=()=>{const m=sp(r)(u)(t.halftoneShadows)(i)(a),p=()=>{const x=yp(N=>r.tag!=="Nothing"&&r.tag==="Just"&&r._1===N?T("Just",0):w)(__)(1)(u)(i)(a),y=()=>{const N=pp(u)(i)(a),v=()=>{const J=S_(u)(o)(i)(a),k=()=>{const S=Tp(n3)(u)(i)(a),A=()=>{const I=()=>{const $=nL(u)(i)(a);return a.staticKind!=="Animated"?$:K(st("Return",void 0),ct)};return K(c._1,(()=>{if(c._2.tag==="CatNil")return tt("CatCons",I,Z(R,R));if(c._2.tag==="CatCons")return tt("CatCons",c._2._1,Z(c._2._2._1,yt("Cons",tt("CatCons",I,Z(R,R)),c._2._2._2)));_()})())};return K(S._1,(()=>{if(S._2.tag==="CatNil")return tt("CatCons",A,Z(R,R));if(S._2.tag==="CatCons")return tt("CatCons",S._2._1,Z(S._2._2._1,yt("Cons",tt("CatCons",A,Z(R,R)),S._2._2._2)));_()})())};return K(J._1,(()=>{if(J._2.tag==="CatNil")return tt("CatCons",k,Z(R,R));if(J._2.tag==="CatCons")return tt("CatCons",J._2._1,Z(J._2._2._1,yt("Cons",tt("CatCons",k,Z(R,R)),J._2._2._2)));_()})())};return K(N._1,(()=>{if(N._2.tag==="CatNil")return tt("CatCons",v,Z(R,R));if(N._2.tag==="CatCons")return tt("CatCons",N._2._1,Z(N._2._2._1,yt("Cons",tt("CatCons",v,Z(R,R)),N._2._2._2)));_()})())};return K(x._1,(()=>{if(x._2.tag==="CatNil")return tt("CatCons",y,Z(R,R));if(x._2.tag==="CatCons")return tt("CatCons",x._2._1,Z(x._2._2._1,yt("Cons",tt("CatCons",y,Z(R,R)),x._2._2._2)));_()})())};return K(m._1,(()=>{if(m._2.tag==="CatNil")return tt("CatCons",p,Z(R,R));if(m._2.tag==="CatCons")return tt("CatCons",m._2._1,Z(m._2._2._1,yt("Cons",tt("CatCons",p,Z(R,R)),m._2._2._2)));_()})())};return K(f._1,(()=>{if(f._2.tag==="CatNil")return tt("CatCons",h,Z(R,R));if(f._2.tag==="CatCons")return tt("CatCons",f._2._1,Z(f._2._2._1,yt("Cons",tt("CatCons",h,Z(R,R)),f._2._2._2)));_()})())})());if(n>0){const f=()=>{const h=Sp(t.watermark)(o),m=()=>a.staticKind==="TitleCard"?Ep(a.frameTitle)(o):Ap(a.frameTitle)(o);return K(h._1,(()=>{if(h._2.tag==="CatNil")return tt("CatCons",m,Z(R,R));if(h._2.tag==="CatCons")return tt("CatCons",h._2._1,Z(h._2._2._1,yt("Cons",tt("CatCons",m,Z(R,R)),h._2._2._2)));_()})())};return K(d._1,(()=>{if(d._2.tag==="CatNil")return tt("CatCons",f,Z(R,R));if(d._2.tag==="CatCons")return tt("CatCons",d._2._1,Z(d._2._2._1,yt("Cons",tt("CatCons",f,Z(R,R)),d._2._2._2)));_()})())}return K(st("Return",void 0),tt("CatCons",()=>{const f=Sp(t.watermark)(o),h=()=>a.staticKind==="TitleCard"?Ep(a.frameTitle)(o):Ap(a.frameTitle)(o);return K(f._1,(()=>{if(f._2.tag==="CatNil")return tt("CatCons",h,Z(R,R));if(f._2.tag==="CatCons")return tt("CatCons",f._2._1,Z(f._2._2._1,yt("Cons",tt("CatCons",h,Z(R,R)),f._2._2._2)));_()})())},Z(R,R)))};return K(g._1,(()=>{if(g._2.tag==="CatNil")return tt("CatCons",l,Z(R,R));if(g._2.tag==="CatCons")return tt("CatCons",g._2._1,Z(g._2._2._1,yt("Cons",tt("CatCons",l,Z(R,R)),g._2._2._2)));_()})())},KL=t=>e=>n=>r=>o=>i=>{const a=i.segment.path.length-1|0,s=a>=0&&a<i.segment.path.length?T("Just",i.segment.path[a]):w;if(s.tag==="Nothing")return K(st("Return",void 0),ct);if(s.tag==="Just"){const u=oi(s._1)(o.segment.layout.nodes);if(u.tag==="Nothing")return K(st("Return",void 0),ct);if(u.tag==="Just"){const c=u._1,g=oi(s._1)(o.state.nodes),l=(()=>{if(g.tag==="Nothing")return el;if(g.tag==="Just")return g._1;_()})(),d=oi(s._1)(o.state.nodeInvert),f=(1-XL(.08)(.14)(r))*(()=>{if(d.tag==="Nothing")return 1;if(d.tag==="Just")return 1-d._1;_()})();return Ue({path:o.segment.path,role:o.role,layer:w,effects:[Je("GroupAlpha",o.bgAlpha),Je("GroupTransform",Ko,n)]})((()=>{const h=Qa({id:s._1,role:$3,geometry:Ia("FlatNode",{shape:c.shape,bounds:{x:c.x,y:c.y+5,w:c.w,h:c.h}}),alpha:1,plan:Ba("FlatNodePlan",{palette:t,label:c.label,labelVisibility:za,inkBoost:e?1:0,labelAlpha:0,outlineAlpha:T("Just",1),arrival:w,animState:l})}),m=()=>{const p=Qa({id:s._1,role:g_,geometry:Ia("FlatNode",{shape:c.shape,bounds:{x:c.x,y:c.y,w:c.w,h:c.h}}),alpha:f,plan:Ba("FlatNodePlan",{palette:t,label:c.label,labelVisibility:za,inkBoost:1,labelAlpha:0,outlineAlpha:T("Just",1),arrival:w,animState:l})}),x=()=>dp(o.state.animationTime)(t)(1)(f)(s._1)(c)(l)(oi(s._1)(o.state.nodeLabels));return K(p._1,(()=>{if(p._2.tag==="CatNil")return tt("CatCons",x,Z(R,R));if(p._2.tag==="CatCons")return tt("CatCons",p._2._1,Z(p._2._2._1,yt("Cons",tt("CatCons",x,Z(R,R)),p._2._2._2)));_()})())};return K(h._1,(()=>{if(h._2.tag==="CatNil")return tt("CatCons",m,Z(R,R));if(h._2.tag==="CatCons")return tt("CatCons",h._2._1,Z(h._2._2._1,yt("Cons",tt("CatCons",m,Z(R,R)),h._2._2._2)));_()})())})())}}_()},Pp=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const c=[1,e.viewport.vx,e.viewport.vy,2,e.viewport.vx+e.viewport.vw,e.viewport.vy,2,e.viewport.vx+e.viewport.vw,e.viewport.vy+e.viewport.vh,2,e.viewport.vx,e.viewport.vy+e.viewport.vh,5],g=u.state,l={tx:s.segment.placement.tx,ty:s.segment.placement.ty,sx:s.segment.placement.scale,sy:s.segment.placement.scale},d=v_(t.theme),f=u.segment.layout,h=pe(f),m={vx:h.x-1e3,vy:h.y-1e3,vw:h.w+2e3,vh:h.h+2e3},p=u.segment.path.length-1|0,x=p>=0&&p<u.segment.path.length?oi(u.segment.path[p])(s.segment.layout.nodes):w,y=u.role==="Active"||11*u.segment.placement.scale*n>=5?__:za,N=I_(e.viewport)(u),v=(()=>{if(y==="LabelsHidden")return K(st("Return",void 0),ct);if(y==="LabelsShown")return i.tag==="Leaf"?vp(d)(N)(f)(g):vu(d)(f)(g)(gp(N)(i));_()})(),J={tx:u.segment.placement.tx,ty:u.segment.placement.ty,sx:u.segment.placement.scale,sy:u.segment.placement.scale},k=Ue({path:u.segment.path,role:u.role,layer:w,effects:[Je("GroupAlpha",u.bgAlpha)]})((()=>{const A=Ue({path:u.segment.path,role:u.role,layer:w,effects:[Je("GroupClip",(()=>{if(r>=.52)return c;const $=VL(s)((()=>{const E=u.segment.path.length-1|0;return E>=0&&E<u.segment.path.length?T("Just",u.segment.path[E]):w})());return $.length===0?c:$})(),Qi)]})((()=>{const $=(()=>{if(x.tag==="Just")return Ue({path:s.segment.path,role:s.role,layer:w,effects:[Je("GroupTransform",Ko,l)]})(pu(hu("FloorOverlay",{path:Zo({...x._1,x:x._1.x+1,y:x._1.y+1,w:x._1.w-2,h:x._1.h-2}),fill:T("Just",{color:d.bg,flat:!0}),stroke:w})));if(x.tag==="Nothing")return K(st("Return",void 0),ct);_()})(),E=(s.role==="Active"||s.role==="FlyThrough")&&!t.transparentBg?$:K(st("Return",void 0),ct),G=()=>{const nt=Ue({path:u.segment.path,role:u.role,layer:w,effects:[Je("GroupTransform",Ko,J)]})((()=>{const Q=Np(d)(f)(g),Y=()=>{const X=sp(a)(d)(t.halftoneShadows)(f)(g),D=()=>{const F=yp(z=>a.tag!=="Nothing"&&a.tag==="Just"&&a._1===z?T("Just",0):w)(y)(1)(d)(f)(g),B=()=>{const z=pp(d)(f)(g);return K(z._1,(()=>{if(z._2.tag==="CatNil")return tt("CatCons",()=>S_(d)(m)(f)(g),Z(R,R));if(z._2.tag==="CatCons")return tt("CatCons",z._2._1,Z(z._2._2._1,yt("Cons",tt("CatCons",()=>S_(d)(m)(f)(g),Z(R,R)),z._2._2._2)));_()})())};return K(F._1,(()=>{if(F._2.tag==="CatNil")return tt("CatCons",B,Z(R,R));if(F._2.tag==="CatCons")return tt("CatCons",F._2._1,Z(F._2._2._1,yt("Cons",tt("CatCons",B,Z(R,R)),F._2._2._2)));_()})())};return K(X._1,(()=>{if(X._2.tag==="CatNil")return tt("CatCons",D,Z(R,R));if(X._2.tag==="CatCons")return tt("CatCons",X._2._1,Z(X._2._2._1,yt("Cons",tt("CatCons",D,Z(R,R)),X._2._2._2)));_()})())};return K(Q._1,(()=>{if(Q._2.tag==="CatNil")return tt("CatCons",Y,Z(R,R));if(Q._2.tag==="CatCons")return tt("CatCons",Q._2._1,Z(Q._2._2._1,yt("Cons",tt("CatCons",Y,Z(R,R)),Q._2._2._2)));_()})())})()),V=()=>Ue({path:u.segment.path,role:u.role,layer:w,effects:[Je("GroupTransform",W3,J)]})(Tp(r3)(d)(f)(g));return K(nt._1,(()=>{if(nt._2.tag==="CatNil")return tt("CatCons",V,Z(R,R));if(nt._2.tag==="CatCons")return tt("CatCons",nt._2._1,Z(nt._2._2._1,yt("Cons",tt("CatCons",V,Z(R,R)),nt._2._2._2)));_()})())};return K(E._1,(()=>{if(E._2.tag==="CatNil")return tt("CatCons",G,Z(R,R));if(E._2.tag==="CatCons")return tt("CatCons",E._2._1,Z(E._2._2._1,yt("Cons",tt("CatCons",G,Z(R,R)),E._2._2._2)));_()})())})()),I=()=>Ue({path:u.segment.path,role:u.role,layer:w,effects:[Je("GroupTransform",Ko,J)]})(v);return K(A._1,(()=>{if(A._2.tag==="CatNil")return tt("CatCons",I,Z(R,R));if(A._2.tag==="CatCons")return tt("CatCons",A._2._1,Z(A._2._2._1,yt("Cons",tt("CatCons",I,Z(R,R)),A._2._2._2)));_()})())})()),S=()=>s.role==="FlyThrough"?KL(d)(t.halftoneShadows)(l)(o)(s)(u):K(st("Return",void 0),ct);return K(k._1,(()=>{if(k._2.tag==="CatNil")return tt("CatCons",S,Z(R,R));if(k._2.tag==="CatCons")return tt("CatCons",k._2._1,Z(k._2._2._1,yt("Cons",tt("CatCons",S,Z(R,R)),k._2._2._2)));_()})())},jL=t=>e=>n=>r=>$L(r.minis)(o=>{const i=Pp(t)(e)(n)(0)(0)(M)(w)(r)(o);return(()=>{const a=o.segment.path.length-1|0;return o.bgAlpha>0&&a>=0&&a<o.segment.path.length&&(()=>{const s=oi(o.segment.path[a])(r.state.nodes);if(s.tag==="Just")return s._1.tag==="Hidden"?!1:s._1.tag!=="PloppingOut";if(s.tag==="Nothing")return!1;_()})()})()?i:K(st("Return",void 0),ct)}),ZL=t=>e=>n=>{if(t.theme==="Isometric")return WL({...DL,transparentBg:t.transparentBg})(t.theme)(Qs(n).segment.layout)(Qs(n).state);const r=$a(t)(n),o=u=>n.hasDives?r.vw/F_(1)(pe(n.rootLayout).w):1,i={tileScale:o(),viewport:r},a=u=>c=>{if(c.length===0)return K(st("Return",void 0),ct);const g=At(l=>w,l=>d=>T("Just",{head:l,tail:d}),c);if(g.tag==="Nothing")return K(st("Return",void 0),ct);if(g.tag==="Just"){const l=Pp(t)(i)(n.camera.zoom)(n.diveDepth)(n.doorProgress)(g._1.head.role==="Active"?e:M)((()=>{if(g._1.head.role==="FlyThrough"&&0<g._1.tail.length){const d=g._1.tail[0].segment.path.length-1|0;if(d>=0&&d<g._1.tail[0].segment.path.length)return T("Just",g._1.tail[0].segment.path[d])}return w})())(u)(g._1.head);return g._1.head.role==="Active"||g._1.head.role==="FlyThrough"?K(l._1,(()=>{if(l._2.tag==="CatNil")return tt("CatCons",()=>a(g._1.head)(g._1.tail),Z(R,R));if(l._2.tag==="CatCons")return tt("CatCons",l._2._1,Z(l._2._2._1,yt("Cons",tt("CatCons",()=>a(g._1.head)(g._1.tail),Z(R,R)),l._2._2._2)));_()})()):K(st("Return",void 0),tt("CatCons",()=>a(g._1.head)(g._1.tail),Z(R,R)))}_()},s=At(u=>w,u=>c=>T("Just",{head:u,tail:c}),n.levels);if(s.tag==="Nothing")return K(st("Return",void 0),ct);if(s.tag==="Just"){const u=s._1.tail,c=s._1.head,g=u.length===0,l=YL(t)(o())(c.role==="Active"||c.role==="FlyThrough"?c.bgAlpha:0)((()=>{if(c.role==="FlyThrough"&&0<u.length){const f=u[0].segment.path.length-1|0;if(f>=0&&f<u[0].segment.path.length)return T("Just",u[0].segment.path[f])}return w})())(r)(c.segment.layout)(UL(n).state)(g&&e.tag!=="Leaf"?Lp("SpringLabels",e):qL),d=()=>{const f=jL(t)(i)(n.camera.zoom)(c);return c.role==="Active"||c.role==="FlyThrough"?K(f._1,(()=>{if(f._2.tag==="CatNil")return tt("CatCons",()=>a(c)(u),Z(R,R));if(f._2.tag==="CatCons")return tt("CatCons",f._2._1,Z(f._2._2._1,yt("Cons",tt("CatCons",()=>a(c)(u),Z(R,R)),f._2._2._2)));_()})()):K(st("Return",void 0),tt("CatCons",()=>a(c)(u),Z(R,R)))};return K(l._1,(()=>{if(l._2.tag==="CatNil")return tt("CatCons",d,Z(R,R));if(l._2.tag==="CatCons")return tt("CatCons",l._2._1,Z(l._2._2._1,yt("Cons",tt("CatCons",d,Z(R,R)),l._2._2._2)));_()})())}_()},B_=t=>e=>n=>V3({viewport:$a(t)(n),camera:n.camera})(ZL(t)(e)(n)),M_=t=>e=>{if(e.fill.tag==="Just"){if(e.stroke.tag==="Just")return t.fillStrokePath(e.path)(e.fill._1)(e.stroke._1);if(e.stroke.tag==="Nothing")return t.fillPath(e.path)(e.fill._1);_()}if(e.fill.tag==="Nothing"){if(e.stroke.tag==="Just")return t.strokePath(e.path)(e.stroke._1);if(e.stroke.tag==="Nothing")return t.Monad0().Applicative0().pure()}_()},t5=t=>{const e=t.Monad0(),n=e.Bind1(),r=io(e.Applicative0())(Sf),o=fp(t);return i=>{if(i.tag==="FrameTitleOverlay"){const a=i._1;return n.bind(r(M_(t))(a.backing))(()=>o(a.text))}if(i.tag==="TitleCardOverlay"){const a=i._1;return n.bind(M_(t)(a.backing))(()=>o(a.text))}if(i.tag==="FloorOverlay")return M_(t)(i._1);_()}},e5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=io(n)(Mt),o=t.popTransform,i=t.popBakedTransform,a=(()=>{const u=t.popClip,c=t.popAlpha,g=t.popBlend,l=t.popBlur;return d=>{if(d.tag==="GroupTransform"){if(d._1==="NormalTransform")return o;if(d._1==="BakedTransform")return i;_()}if(d.tag==="GroupClip")return u;if(d.tag==="GroupAlpha")return c;if(d.tag==="GroupBlend")return g;if(d.tag==="GroupBlur")return l;_()}})(),s=t.popLayer;return u=>e.Bind1().bind(r(a)(re(u.effects)))(()=>{if(u.layer.tag==="Just")return s;if(u.layer.tag==="Nothing")return n.pure();_()})},n5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=io(n)(Mt);return o=>e.Bind1().bind((()=>{if(o.layer.tag==="Just")return t.pushLayer(o.layer._1);if(o.layer.tag==="Nothing")return n.pure();_()})())(()=>r(i=>{if(i.tag==="GroupTransform"){if(i._1==="NormalTransform")return t.pushTransform(i._2);if(i._1==="BakedTransform")return t.pushBakedTransform(i._2);_()}if(i.tag==="GroupClip")return t.pushClip(i._1)(i._2);if(i.tag==="GroupAlpha")return t.pushAlpha(i._1);if(i.tag==="GroupBlend")return t.pushBlend(i._1);if(i.tag==="GroupBlur")return t.pushBlur(i._1);_()})(o.effects))},Rp=t=>{const e=t.Monad0(),n=oL(t),r=RL(t),o=yL(t),i=HL(t),a=jk(t),s=GL(t);return U3(e)({beginFrame:u=>t.setViewport(u.viewport),endFrame:e.Applicative0().pure(),beginGroup:n5(t),endGroup:e5(t),background:Xk(t),overlay:t5(t),node:u=>{if(u.geometry.tag==="FlatNode")return n(u);if(u.geometry.tag==="IsoSlab")return r(u);_()},edge:u=>{if(u.geometry.tag==="FlatRoute")return o(u);if(u.geometry.tag==="IsoSegments")return i(u);_()},text:fp(t),token:u=>{if(u.geometry.tag==="FlatToken")return a(u);if(u.geometry.tag==="IsoCube")return s(u);_()},insideTokenStyle:t.insideTokenStyle,measureText:t.measureText,measureInk:t.measureInk})},r5=E_(mh)(u_.measureText),Gp=Rp(u_),bu=t=>$a({padding:24,outputAspect:t.width<=0||t.height<=0?w:T("Just",t.width/t.height)}),o5=t=>e=>n=>r=>o=>i=>a=>{const s={padding:24,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;_()})(),halftoneShadows:!1,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?w:T("Just",r.width/r.height)},u=dh(n)(r);return()=>{const c=u(),g=o.levels.length-1|0;if(g>=0&&g<o.levels.length){const d=r5(I_(bu(r)(o))(o.levels[g]))(o.levels[g].segment.layout)(o.levels[g].state)(c)(),f=Vg(i)(d)(a);return Gp(B_(s)(f.applied)(o))(c)(),f.springs}const l=Vg(i)(M)(a);return Gp(B_(s)(l.applied)(o))(c)(),l.springs}},qa=t=>"rgb("+ae(t.r)+","+ae(t.g)+","+ae(t.b)+")",ii=t=>t===1?7:t===2?10:t===3?14:t===4?13:t===5?5:t===6?1:t===7?4:t===8?1:t===9?2:t===10?1:t===11?2:t===12?1:t===18?2:t===19?1:t===13?2:t===14?1:t===15||t===16?5:1,fe=Do(Ro("Fixed",Go(0)(20)(2))),z_=t=>{const e=n=>{const r=n>=0&&n<t.length?T("Just",t[n]):w;if(r.tag==="Just")return r._1===1?["M",fe((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===2?["L",fe((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===3?["Q",fe((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+5|0)]:r._1===4?["C",fe((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+5|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+6|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+7|0)]:r._1===5?["Z",...e(n+1|0)]:[];if(r.tag==="Nothing")return[];_()};return Qn(" ")(e(0))},i5=t=>fe(t.vx)+" "+fe(t.vy)+" "+fe(t.vw)+" "+fe(t.vh),$n=t=>e=>de(Vn(e>=0&&e<t.length?t[e]:0)),Q_=t=>e=>{const n=$n(t.ops)(e+1|0);return Rt(n,n+$n(t.ops)(e+2|0)|0,t.paths)},Dp=(()=>{const t=jn("&")("&amp;"),e=jn("<")("&lt;"),n=(()=>{const r=jn(">")("&gt;"),o=(()=>{const i=jn('"')("&quot;");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),a5={vx:0,vy:0,vw:1,vh:1},s5=t=>(e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i>=0&&i<t.length){if(t[i]===15){const a=i+1|0;r=!1,o={vx:a>=0&&a<t.length?t[a]:0,vy:(()=>{const s=a+1|0;return s>=0&&s<t.length?t[s]:0})(),vw:(()=>{const s=a+2|0;return s>=0&&s<t.length?t[s]:0})(),vh:(()=>{const s=a+3|0;return s>=0&&s<t.length?t[s]:0})()};continue}n=i+ii(t[i])|0;continue}r=!1,o=a5}return o})(0),Ua=t=>e=>({r:$n(t)(e),g:$n(t)(e+1|0),b:$n(t)(e+2|0),a:$n(t)(e+3|0)}),Fp=t=>e=>({color:Ua(t)(e),width:(()=>{const n=e+4|0;return n>=0&&n<t.length?t[n]:0})(),join:$n(t)(e+5|0),cap:$n(t)(e+6|0)}),u5=t=>e=>'<rect x="'+fe(t.vx)+'" y="'+fe(t.vy)+'" width="'+fe(t.vw)+'" height="'+fe(t.vh)+'" fill="'+qa(e)+'" opacity="'+fe(rt(e.a)/255)+'"/>',c5=t=>e=>'<path d="'+z_(t)+'" fill="'+qa(e)+'" fill-opacity="'+fe(rt(e.a)/255)+'"/>',Ip=t=>' stroke="'+qa(t.color)+'" stroke-opacity="'+fe(rt(t.color.a)/255)+'" stroke-width="'+fe(t.width)+'" stroke-linejoin="'+(t.join===0?"round":t.join===1?"bevel":"miter")+'" stroke-linecap="'+(t.cap===0?"butt":t.cap===1?"round":"square")+'"',g5=t=>e=>n=>'<path d="'+z_(t)+'" fill="'+qa(e)+'" fill-opacity="'+fe(rt(e.a)/255)+'"'+Ip(n)+"/>",_5=t=>e=>'<path d="'+z_(t)+'" fill="none"'+Ip(e)+"/>",f5=t=>e=>{const n=Ua(t.ops)(e+7|0),r=$n(t.ops)(e+12|0),o=$n(t.ops)(e+11|0);return'<text x="'+fe((()=>{const i=e+1|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" y="'+fe((()=>{const i=e+2|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'"'+(r===0?' dy="0.8em"':r===1?' dy="0.32em"':"")+' fill="'+qa(n)+'" fill-opacity="'+fe(rt(n.a)/255)+'" font-size="'+fe((()=>{const i=e+5|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" font-family="'+Dp((()=>{const i=$n(t.ops)(e+4|0);return i>=0&&i<t.strs.length?t.strs[i]+", ui-sans-serif, system-ui, sans-serif":", ui-sans-serif, system-ui, sans-serif"})())+'" font-weight="'+ae($n(t.ops)(e+6|0))+'" text-anchor="'+(o===0?"start":o===1?"middle":"end")+'">'+Dp((()=>{const i=$n(t.ops)(e+3|0);return i>=0&&i<t.strs.length?t.strs[i]:""})())+"</text>"},ai=t=>e=>n=>{const r=n>=0&&n<e.ops.length?T("Just",e.ops[n]):w;if(r.tag==="Just")return r._1===1?c5(Q_(e)(n))(Ua(e.ops)(n+3|0))+ai(t)(e)(n+ii(r._1)|0):r._1===2?_5(Q_(e)(n))(Fp(e.ops)(n+3|0))+ai(t)(e)(n+ii(r._1)|0):r._1===3?g5(Q_(e)(n))(Ua(e.ops)(n+3|0))(Fp(e.ops)(n+7|0))+ai(t)(e)(n+ii(r._1)|0):r._1===4?f5(e)(n)+ai(t)(e)(n+ii(r._1)|0):r._1===16?u5(t)(Ua(e.ops)(n+1|0))+ai(t)(e)(n+ii(r._1)|0):ai(t)(e)(n+ii(r._1)|0);if(r.tag==="Nothing")return"";_()},l5=t=>{const e=s5(t.ops);return{viewBox:i5(e),body:ai(e)(t)(0),vx:e.vx,vy:e.vy,vw:e.vw,vh:e.vh}},d5=GC(BC)(p2),Bp=t=>e=>{const n=t.strs;return()=>{const r=lc(n);return t.strs.push(e),r}},Ju=t=>e=>{const n=t.paths;return()=>{const r=lc(n);return t.paths.push(...e),{offset:r,len:e.length}}},h5=t=>e=>{const n=e.tx,r=t.ops;return()=>{r.push(n),t.ops.push(e.ty),t.ops.push(e.sx),t.ops.push(e.sy)}},Mp=t=>e=>{const n=e.vx,r=t.ops;return()=>{r.push(n),t.ops.push(e.vy),t.ops.push(e.vw),t.ops.push(e.vh)}},oo=t=>e=>{const n=rt(e),r=t.ops;return()=>{r.push(n)}},Cu=t=>e=>{const n=e.len,r=oo(t)(e.offset);return()=>(r(),oo(t)(n)())},p5=()=>{const t=[],e=[],n=[],r=[];return r.push(1),{ops:t,paths:e,strs:n,alphaStack:r}},m5=t=>{if(t.tag==="MeasureText"){const e=t._3(jg(t._1)(t._2));return()=>e}if(t.tag==="MeasureInk"){const e=t._3(Zg(t._1)(t._2));return()=>e}_()},zp=t=>{const e=t.alphaStack;return()=>{const n=lc(e);if(n===0)return 1;const r=y2(Ut,w,n-1|0,t.alphaStack);if(r.tag==="Nothing")return 1;if(r.tag==="Just")return r._1;_()}},si=t=>e=>{const n=zp(t);return()=>{const r=n();return oo(t)(e.r)(),oo(t)(e.g)(),oo(t)(e.b)(),oo(t)(de(Vn(rt(e.a)*r+.5)))()}},Qp=t=>e=>{const n=si(t)(e.color);return()=>{n(),t.ops.push(e.width),t.ops.push((()=>{if(e.lineJoin==="RoundJoin")return 0;if(e.lineJoin==="BevelJoin")return 1;if(e.lineJoin==="MiterJoin")return 2;_()})()),t.ops.push((()=>{if(e.lineCap==="ButtCap")return 0;if(e.lineCap==="RoundCap")return 1;if(e.lineCap==="SquareCap")return 2;_()})())}},y5=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r;if(s.tag==="FillPath"){const u=s._3,c=s._2,g=Ju(a)(s._1);o=!1,i=()=>{const l=g();return a.ops.push(1),Cu(a)(l)(),si(a)(c.color)(),u};continue}if(s.tag==="StrokePath"){const u=s._3,c=s._2,g=Ju(a)(s._1);o=!1,i=()=>{const l=g();return a.ops.push(2),Cu(a)(l)(),Qp(a)(c)(),u};continue}if(s.tag==="FillStrokePath"){const u=s._2,c=s._4,g=s._3,l=Ju(a)(s._1);o=!1,i=()=>{const d=l();return a.ops.push(3),Cu(a)(d)(),si(a)(u.color)(),Qp(a)(g)(),c};continue}if(s.tag==="DrawText"){const u=s._2,c=s._1,g=Bp(a)(Uo(c.content));o=!1,i=()=>{const l=g(),d=Bp(a)(c.font.family)();return a.ops.push(4),a.ops.push(c.x),a.ops.push(c.y),oo(a)(l)(),oo(a)(d)(),a.ops.push(c.font.size),oo(a)(c.font.weight)(),si(a)(c.color)(),a.ops.push((()=>{if(c.align==="AlignLeft")return 0;if(c.align==="AlignCenter")return 1;if(c.align==="AlignRight")return 2;_()})()),a.ops.push((()=>{if(c.baseline==="BaselineTop")return 0;if(c.baseline==="BaselineMiddle")return 1;if(c.baseline==="BaselineAlphabetic")return 2;if(c.baseline==="BaselineBottom")return 3;_()})()),u};continue}if(s.tag==="DrawTextAffine"){n=a,r=Xt("DrawText",{...s._2,x:s._1.a*s._2.x+s._1.c*s._2.y+s._1.e,y:s._1.b*s._2.x+s._1.d*s._2.y+s._1.f},s._3);continue}if(s.tag==="PushTransform"){const u=s._2,c=s._1,g=a.ops;o=!1,i=()=>(g.push(5),h5(a)(c)(),u);continue}if(s.tag==="PopTransform"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(6),u);continue}if(s.tag==="PushClip"){const u=s._3,c=s._2,g=Ju(a)(s._1);o=!1,i=()=>{const l=g();return a.ops.push(7),Cu(a)(l)(),a.ops.push((()=>{if(c==="NonZero")return 0;if(c==="EvenOdd")return 1;_()})()),u};continue}if(s.tag==="PopClip"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(8),u);continue}if(s.tag==="PushBlend"){const u=s._1,c=s._2,g=a.ops;o=!1,i=()=>(g.push(9),a.ops.push((()=>{if(u==="Normal")return 0;if(u==="Difference")return 1;_()})()),c);continue}if(s.tag==="PopBlend"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(10),u);continue}if(s.tag==="PushAlpha"){const u=s._1,c=s._2,g=zp(a);o=!1,i=()=>{const l=g();return a.alphaStack.push(l*u),a.ops.push(11),a.ops.push(u),c};continue}if(s.tag==="PopAlpha"){const u=s._1,c=a.alphaStack;o=!1,i=()=>(x2(Ut,w,c),a.ops.push(12),u);continue}if(s.tag==="PushBlur"){const u=s._2,c=s._1,g=a.ops;o=!1,i=()=>(g.push(18),a.ops.push(c),u);continue}if(s.tag==="PopBlur"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(19),u);continue}if(s.tag==="PushLayer"){const u=s._1,c=s._2,g=a.ops;o=!1,i=()=>(g.push(13),a.ops.push((()=>{if(u==="LayerBase")return 0;if(u==="LayerPolyOut")return 1;if(u==="LayerPolyIn")return 2;if(u==="LayerNodeMask")return 3;if(u==="LayerOverlay")return 4;_()})()),c);continue}if(s.tag==="PopLayer"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(14),u);continue}if(s.tag==="SetViewport"){const u=s._2,c=s._1,g=a.ops;o=!1,i=()=>(g.push(15),Mp(a)(c)(),u);continue}if(s.tag==="ClearBackground"){const u=s._1,c=s._2,g=a.ops;o=!1,i=()=>(g.push(16),si(a)(u)(),c);continue}if(s.tag==="BackgroundDots"){const u=s._2,c=s._1,g=a.ops;o=!1,i=()=>(g.push(17),Mp(a)(c.viewport)(),si(a)(c.bgColor)(),si(a)(c.dotColor)(),a.ops.push(c.tile),a.ops.push(c.dotRadius),a.ops.push(c.origin.x),a.ops.push(c.origin.y),u);continue}_()}return i},x5=t=>e=>e.type==="metrics"?m5(e.value):e.type==="render"?y5(t)(e.value):r1("Data.Functor.Variant: pattern match failure ["+e.type+"]"),w5=t=>{const e=p5();return d5(x5(e))(t)(),{ops:e.ops,paths:e.paths,strs:e.strs}},N5=t=>t,Xa=t=>t,W_=Xa("Light"),T5=Xa("Dark"),v5=Xa("Blueprint"),b5=Xa("Whiteboard"),J5=Xa("Isometric"),C5=N5("TransparentBackground"),To=t=>"rgb("+ae(t.r)+","+ae(t.g)+","+ae(t.b)+")",ku=Do(Ro("Fixed",Go(0)(20)(6))),Dr=Do(Ro("Fixed",Go(0)(20)(4))),k5=t=>"translate("+Dr(t.tx)+","+Dr(t.ty)+") scale("+Dr(t.sx)+","+Dr(t.sy)+")",Ht=Do(Ro("Fixed",Go(0)(20)(2))),O_=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,o=r>=0&&r<t.length?T("Just",t[r]):w;if(o.tag==="Nothing"){n=t.length;continue}if(o.tag==="Just"){if(o._1===1){e.push("M"),e.push(Ht((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Ht((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),n=r+3|0;continue}if(o._1===2){e.push("L"),e.push(Ht((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Ht((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),n=r+3|0;continue}if(o._1===3){e.push("Q"),e.push(Ht((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Ht((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Ht((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Ht((()=>{const i=r+4|0;return i>=0&&i<t.length?t[i]:0})())),n=r+5|0;continue}if(o._1===4){e.push("C"),e.push(Ht((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Ht((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Ht((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Ht((()=>{const i=r+4|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Ht((()=>{const i=r+5|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Ht((()=>{const i=r+6|0;return i>=0&&i<t.length?t[i]:0})())),n=r+7|0;continue}if(o._1===5){e.push("Z"),n=r+1|0;continue}n=t.length;continue}_()}return Qn(" ")(e)},L5={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},H_=(()=>{const t=jn("&")("&amp;"),e=jn("<")("&lt;"),n=(()=>{const r=jn(">")("&gt;"),o=(()=>{const i=jn('"')("&quot;");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),S5=t=>{if(t.style==="RunText"||t.style==="RunHighlight")return"<tspan>"+H_(t.text)+"</tspan>";if(t.style==="RunCode"||t.style==="RunCodeHighlight")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+H_(t.text)+"</tspan>";_()},je=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},E5=t=>e=>{const n=[];let r=0;const o=i=>{const a=i>=0&&i<e.length?t.sx*e[i]+t.tx:t.sx*0+t.tx;return()=>{n.push(a),n.push((()=>{const s=i+1|0;return s>=0&&s<e.length?t.sy*e[s]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const i=r,a=i>=0&&i<e.length?T("Just",e[i]):w;if(a.tag==="Nothing"){r=e.length;continue}if(a.tag==="Just"){if(a._1===1){n.push(a._1),o(i+1|0)(),r=i+3|0;continue}if(a._1===2){n.push(a._1),o(i+1|0)(),r=i+3|0;continue}if(a._1===3){n.push(a._1),o(i+1|0)(),o(i+3|0)(),r=i+5|0;continue}if(a._1===4){n.push(a._1),o(i+1|0)(),o(i+3|0)(),o(i+5|0)(),r=i+7|0;continue}if(a._1===5){n.push(a._1),r=i+1|0;continue}r=e.length;continue}_()}return n},Lu=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return E5(r._1)(e);_()}},Wp={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),a=o();return i(a)}},Functor0:()=>L5},A5={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>Wp},P5={pure:t=>e=>()=>t,Apply0:()=>Wp},Op={Applicative0:()=>P5,Bind1:()=>A5},R5=t=>e=>'<defs><pattern id="'+t+'" x="'+Ht(e.origin.x)+'" y="'+Ht(e.origin.y)+'" width="'+Ht(e.tile)+'" height="'+Ht(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+Ht(e.tile)+'" height="'+Ht(e.tile)+'" fill="'+To(e.bgColor)+'" fill-opacity="'+Ht(rt(e.bgColor.a)/255)+'"/>')+'<circle cx="'+Ht(e.tile/2)+'" cy="'+Ht(e.tile/2)+'" r="'+Ht(e.dotRadius)+'" fill="'+To(e.dotColor)+'"/></pattern></defs><rect x="'+Ht(e.viewport.vx)+'" y="'+Ht(e.viewport.vy)+'" width="'+Ht(e.viewport.vw)+'" height="'+Ht(e.viewport.vh)+'" fill="url(#'+t+')"/>',Hp=t=>e=>'<path d="'+O_(t)+'" fill="'+To(e)+'" fill-opacity="'+Ht(rt(e.a)/255)+'"/>',G5=t=>e=>n=>r=>'<rect x="'+Ht(t.x)+'" y="'+Ht(t.y)+'" width="'+Ht(t.w)+'" height="'+Ht(t.h)+'" rx="'+Ht(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+To(n._1.color)+'" fill-opacity="'+Ht(rt(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';_()})()+(()=>{if(r.tag==="Just")return' stroke="'+To(r._1.color)+'" stroke-opacity="'+Ht(rt(r._1.color.a)/255)+'" stroke-width="'+Ht(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";_()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";_()})()+'"';if(r.tag==="Nothing")return"";_()})()+"/>",$p=t=>e=>'<path d="'+O_(t)+'" fill="none" stroke="'+To(e.color)+'" stroke-opacity="'+Ht(rt(e.color.a)/255)+'" stroke-width="'+Ht(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";_()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";_()})()+'"/>',qp=t=>{const e=fr(Uo(t.content));return'<text x="'+Ht(t.x)+'" y="'+Ht(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"";_()})()+' fill="'+To(t.color)+'" fill-opacity="'+Ht(rt(t.color.a)/255)+'" font-size="'+Ht(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+ae(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";_()})()+'">'+(e.length===1&&e[0].style==="RunText"?H_(e[0].text):Qn("")(U(S5)(e)))+"</text>"},D5=t=>"matrix("+Dr(t.a)+" "+Dr(t.b)+" "+Dr(t.c)+" "+Dr(t.d)+" "+Dr(t.e)+" "+Dr(t.f)+")",Up={fillPath:t=>e=>n=>{const r=Lu(n)(t);return()=>{const o=r();return je(Hp(o)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=Lu(n)(t);return()=>{const o=r(),i=n.bake.value;return je($p(o)((()=>{if(i.tag==="Nothing")return e;if(i.tag==="Just")return{...e,width:i._1.sx*e.width};_()})()))(n)()}},fillStrokePath:t=>e=>n=>r=>{const o=Lu(r)(t);return()=>{const i=o(),a=r.bake.value;return je(Hp(i)(e.color)+$p(i)((()=>{if(a.tag==="Nothing")return n;if(a.tag==="Just")return{...n,width:a._1.sx*n.width};_()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>o=>{const i=o.bake;return()=>{const a=i.value;return je(G5((()=>{if(a.tag==="Nothing")return t;if(a.tag==="Just")return{x:a._1.sx*t.x+a._1.tx,y:a._1.sy*t.y+a._1.ty,w:a._1.sx*t.w,h:a._1.sy*t.h};_()})())((()=>{if(a.tag==="Nothing")return e;if(a.tag==="Just")return a._1.sx*e;_()})())(n)(r.tag==="Just"?T("Just",(()=>{if(a.tag==="Nothing")return r._1;if(a.tag==="Just")return{...r._1,width:a._1.sx*r._1.width};_()})()):w))(o)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return je(qp((()=>{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}};_()})()))(e)()}},drawTextAffine:t=>e=>je((()=>{const n='transform="'+D5(t)+'"';return(n===""?"<g>":"<g "+n+">")+qp(e)+"</g>"})()),pushTransform:t=>je((()=>{const e='transform="'+k5(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:je("</g>"),pushBakedTransform:t=>e=>{const n=e.bake;return()=>{n.value=T("Just",t)}},popBakedTransform:t=>{const e=t.bake;return()=>{e.value=w}},pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const o=r.value;n.clipCounter.value=o+1|0;const i=Lu(n)(t)(),a="clip"+ae(o);return je((()=>{const s='clip-path="url(#'+a+')"';return'<defs><clipPath id="'+a+'"><path d="'+O_(i)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";_()})()+"/></clipPath></defs>"+(s===""?"<g>":"<g "+s+">")})())(n)()}},popClip:je("</g>"),pushBlend:t=>je((()=>{const e=(()=>{if(t==="Normal")return'style="mix-blend-mode: normal"';if(t==="Difference")return'style="mix-blend-mode: difference"';_()})();return e===""?"<g>":"<g "+e+">"})()),popBlend:je("</g>"),pushAlpha:t=>je((()=>{const e='opacity="'+Ht(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:je("</g>"),pushBlur:t=>e=>{if(t<.01)return je("<g>")(e);const n=e.patternCounter;return()=>{const r=n.value;e.patternCounter.value=r+1|0;const o="lvl-blur-"+ae(r);return je((()=>{const i='filter="url(#'+o+')"';return'<defs><filter id="'+o+'" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="'+Ht(t)+'"/></filter></defs>'+(i===""?"<g>":"<g "+i+">")})())(e)()}},popBlur:je("</g>"),pushLayer:t=>e=>{const n=(()=>{if(t==="LayerNodeMask"){const r=e.maskDepth;return()=>{const o=r.value;e.maskDepth.value=o+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=>je('<rect x="'+Ht(e.viewport.vx)+'" y="'+Ht(e.viewport.vy)+'" width="'+Ht(e.viewport.vw)+'" height="'+Ht(e.viewport.vh)+'" fill="'+To(t)+'" opacity="'+Ht(rt(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,je(R5("bg-dots-"+ae(r))(t))(e)()}},measureText:t=>e=>n=>{const r=jg(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Zg(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>i_,Monad0:()=>Op},F5=Rp(Up),I5=E_(Op)(Up.measureText),B5=t=>e=>n=>r=>o=>{const i={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;_()})(),halftoneShadows:!1,watermark:"",theme:n,outputAspect:t},a=$a(i)(o);return{viewBox:ku(a.vx)+" "+ku(a.vy)+" "+ku(a.vw)+" "+ku(a.vh),body:(()=>{const s=[],u={value:0},c={value:0},g={value:0},l={value:w};return F5(B_(i)(e)(o))({out:s,maskDepth:u,clipCounter:c,patternCounter:g,viewport:a,bake:l})(),Qn("")(s)})(),vx:a.vx,vy:a.vy,vw:a.vw,vh:a.vh}},M5=t=>e=>n=>r=>o=>i=>{const a={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;_()})(),outputAspect:t},s=Vg(o)((()=>{const u=[],c={value:0},g={value:0},l={value:0},d={value:w},f=r.levels.length-1|0;if(f>=0&&f<r.levels.length){const h=I_($a(a)(r))(r.levels[f]);return I5(h)(r.levels[f].segment.layout)(r.levels[f].state)({out:u,maskDepth:c,clipCounter:g,patternCounter:l,viewport:h,bake:d})()}return M})())(i);return{parts:B5(t)(s.applied)(e)(n)(r),springs:s.springs}},vo=(t,e)=>({tag:t,_1:e}),Su=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Sn=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Xp=ge(P)(Mt),Vp=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},Yp=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Eu=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Au=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},ui=(()=>{const t=mn.unfoldr(e=>{if(e.tag==="Nil")return w;if(e.tag==="Cons")return T("Just",L(e._1,e._2));_()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,yt("Cons",r._3,n(r._6,o)));_()};return n(e,R)})())})(),z5=b(t=>e=>it(P)(e)()(t))(M),$_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},Kp=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},Q5=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Pu=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},W5=vo("NoKeyframes"),O5=t=>vo("DuplicateEventId",t),H5=t=>vo("UnknownEvent",t),$5=t=>e=>({...e,cameraSpans:K1(e.cameraConfig)(t)(e.layout)(e.keyframes)({endT:e.totalDuration,spans:e.spans,windows:e.windows,segments:e.segments,dives:e.dives})}),q5=t=>e=>n=>r=>{const o=Su(r.edge)(e.edges),i=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return xs(o._1);_()})(),a=Sn(t.minTokenDuration)(Sn(rt(b(s=>u=>s+un(u).length|0)(0)(r.labels))*t.tokenReadSecPerChar)(t.tokenSpeed<=0?0:i/t.tokenSpeed))+n.post;return{duration:a,holdPre:0,holdPost:a<=0?0:n.post/a}},U5=as(t=>{const e=Mo(`
10
- `)(t);return e.length===0?[""]:e}),X5=t=>e=>Xp(wt(n=>{if(n.kind.tag==="SendToken")return T("Just",L(n.id,{post:(()=>{const r=n.id;return(()=>{const o=n.kind._1.to;return ne(i=>{if(i.kind.tag==="SendToken")return(i.when.tag==="First"?!1:i.when.tag==="After"&&i.when._1===r)&&i.kind._1.from===o;if(i.kind.tag==="FillNodeWithoutTransition")return!1;_()},e)})()?0:t.tokenHold})()}));if(n.kind.tag==="FillNodeWithoutTransition")return w;_()})(e)),V5=t=>{if(t.event.kind.tag==="SendToken")return T("Just",{startT:t.startT,endT:t.endT,target:zo("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 T("Just",{startT:t.startT,endT:t.endT,target:zo("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});_()},Y5=t=>wt((()=>{const e=t.path;return n=>n.target.tag==="TokenWindow"?T("Just",{path:e,eventId:n.target._1,window:n,from:n.target._4,to:n.target._5,labels:n.target._6,holdPre:n.target._7,holdPost:n.target._8}):w})())(t.windows),K5=t=>e=>n=>{const r=Su(n)(t);if(r.tag==="Nothing")return tl;if(r.tag==="Just"){const o=Vp(r._1.target)(e);return Vp(r._1.source)(e)?o?nN:eN:tl}_()},jp=t=>e=>{if(t.tag==="Just"&&t._1>e.endT+1e-4){const n=Sn(0)(e.endT-e.startT),r=Sn(e.startT)(t._1-n);return{...e,startT:r,endT:r+n}}return e},Zp=U(ea),j5={post:0},Z5=t=>e=>n=>r=>o=>{const i=Yp(o.event.id)(n),a=(()=>{if(i.tag==="Nothing")return j5;if(i.tag==="Just")return i._1;_()})(),s=(()=>{if(o.event.when.tag==="First")return 0;if(o.event.when.tag==="At")return o.event.when._1;if(o.event.when.tag==="After"){const c=o.event.when._1,g=Kt(l=>l.event.id===c)(r);if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1.endT;_()}if(o.event.when.tag==="With"){const c=o.event.when._1,g=Kt(l=>l.event.id===c)(r);if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1.startT}_()})(),u=(()=>{if(o.event.kind.tag==="SendToken")return q5(t)(e)(a)(o.event.kind._1);if(o.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};_()})();return St(r)({startT:s,endT:s+u.duration,event:o.event,holdPre:u.holdPre,holdPost:u.holdPost})},t0=t=>e=>n=>b(Z5(t)(e)(X5(t)(n)))([])(Ot(r=>o=>({event:o}))(n)),tS=t=>b(e=>n=>{const r=zr(e);if(r.tag==="Nothing")return[n];if(r.tag==="Just")return n.startT<=r._1.last.endT+1e-4?St(r._1.init)({...r._1.last,endT:Sn(r._1.last.endT)(n.endT)}):St(e)(n);_()})([])(Gt(e=>n=>at.compare(e.startT)(n.startT))(t)),eS=t=>e=>{const n=Eu(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;_()},nS=t=>e=>{const n=Gt(at.compare)(wt(r=>r.target.tag==="RelabelWindow"?r.target._1===e?T("Just",r.startT):w:r.target.tag==="TokenWindow"?r.target._4===e||r.target._5===e?T("Just",r.startT):w:r.target.tag==="FillWindow"&&r.target._2===e?T("Just",r.startT):w)(t));return 0<n.length?T("Just",n[0]):w},rS=t=>e=>{const n=Gt(at.compare)(wt(r=>r.target.tag==="TokenWindow"&&r.target._2===e?T("Just",r.startT):w)(t));return 0<n.length?T("Just",n[0]):w},oS=t=>e=>e.target.tag==="NodeWindow"?e.target._2==="PlopIn"?jp(nS(t.windows)(e.target._1))(e):e:e.target.tag==="EdgeWindow"&&e.target._2.tag==="Extend"?jp(rS(t.windows)(e.target._1))(e):e,iS=t=>({...t,windows:Gt(e=>n=>at.compare(e.startT)(n.startT))(U(oS(t))(t.windows))}),aS=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];_()},Ru={id:"",nodes:M,edges:M,labels:M,kind:ca},sS=t=>e=>cx((()=>{const n=Au(e.from)(t);if(n.tag==="Nothing")return Ru;if(n.tag==="Just")return n._1;_()})())((()=>{const n=Au(e.to)(t);if(n.tag==="Nothing")return Ru;if(n.tag==="Just")return n._1;_()})()),uS=t=>e=>{const n=Eu(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:M};if(n.tag==="Just")return n._1;_()},e0={id:"",index:-1,kind:"",name:"",time:0,endTime:0,path:[],tokenIndex:-1,lineIndex:-1,text:"",from:"",to:""},cS=t=>e=>e.scene.tag==="StepScene"?T("Just",{...e0,id:"step:"+e.scene._1,kind:"step",name:e.scene._1,time:e.startT,endTime:e.startT,path:Zp(t)}):w,gS=t=>wt(cS(t.path))(t.spans),q_=t=>e=>n=>r=>{const o=Su(r)(n.edges);if(o.tag==="Just")return t<=0?e:Sn(e)(xs(o._1)/t);if(o.tag==="Nothing")return e;_()},n0=t=>e=>n=>r=>o=>{const i=Au(o.to)(n),a=(()=>{if(i.tag==="Nothing")return Ru;if(i.tag==="Just")return i._1;_()})(),s=t.plop,u=Au(o.from)(n),c=(()=>{if(u.tag==="Nothing")return Ru;if(u.tag==="Just")return u._1;_()})(),g=sS(n)(o),l=U(y=>({startT:0,endT:0+q_(t.edgeSpeed)(t.minEdgeDuration)(e)(y),target:zo("EdgeWindow",y,As("Extend",sg))}))(ui(g.entering.edges)),d=U(y=>({startT:0,endT:s,target:zo("NodeWindow",y,Kc)}))(ui(g.entering.nodes)),f=U(y=>({startT:0,endT:t.plop,target:zo("RelabelWindow",y.node,y.oldLabel,y.newLabel)}))(wt(y=>{const N=Eu(y)(c.labels);if(N.tag==="Just"){const v=Eu(y)(a.labels);if(v.tag==="Just")return N._1===v._1?w:T("Just",{node:y,oldLabel:N._1,newLabel:v._1});if(v.tag==="Nothing")return w;_()}if(N.tag==="Nothing")return w;_()})(ui(g.surviving.nodes))),h=b(Sn)(0)(U(y=>q_(t.edgeSpeed)(t.minEdgeDuration)(e)(y))(ui(g.leaving.edges))),m=y=>ne(N=>{const v=Su(N)(r);if(v.tag==="Just")return v._1.source===y||v._1.target===y;if(v.tag==="Nothing")return!1;_()},ui(g.leaving.edges))?h:0,p=U(y=>({startT:m(y),endT:m(y)+t.plop,target:zo("NodeWindow",y,rw)}))(ui(g.leaving.nodes)),x=U(y=>({startT:0,endT:q_(t.edgeSpeed)(t.minEdgeDuration)(e)(y),target:zo("EdgeWindow",y,As("Retract",K5(r)(g.leaving.nodes)(y)))}))(ui(g.leaving.edges));return{duration:(()=>{const y=Gt(at.compare)([...U(v=>v.endT)(x),...U(v=>v.endT)(p),...U(v=>v.endT)(d),...U(v=>v.endT)(f),...U(v=>v.endT)(l)]),N=y.length-1|0;return N>=0&&N<y.length?y[N]+t.gap:t.gap})(),windows:[...x,...p,...d,...f,...l]}},_S=t=>e=>n=>r=>o=>i=>U((()=>{const a=o.startT;return s=>({...s,startT:s.startT+a,endT:s.endT+a})})())(n0(t)(e)(n)(r)(i).windows),fS=t=>wt(e=>Wt(mi,e).length>1?T("Just",(()=>{const n=At(r=>w,r=>o=>T("Just",{head:r,tail:o}),Wt(mi,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";_()})()):w)(I2(xi)(Gt(P.compare)(t))),lS=t=>{const e=U(r=>r.id)(t),n=z5(e);return[...U(O5)(fS(e)),...U(H5)(dt(r=>!$_(r)(n),Et(t)(aS)))]},dS=t=>{const e=Xp(U(r=>L(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];_()})()))(t)),n=r=>o=>i=>{if($_(i)(o))return[vo("ScheduleCycle",[...Wt(ln.foldr,o),i])];if($_(i)(r))return[];const a=Yp(i)(e);if(a.tag==="Nothing")return[];if(a.tag==="Just")return Et(a._1)(n(it(P)(i)()(r))(it(P)(i)()(o)));_()};return Et(t)(r=>n(M)(M)(r.id))},hS={plop:.5,gap:0,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:0,stillHold:1.8,hatchHold:0,tokenReadSecPerChar:.06,nodeEasing:xx,edgeEasing:kr,tokenEasing:p1,diveDur:2.45,retreatDur:2.45},pS=t=>e=>n=>r=>U((()=>{const o=n.startT;return i=>({...i,startT:i.startT+o,endT:i.endT+o})})())(wt(V5)(t0(t)(e)(r.events))),mS=t=>e=>n=>r=>o=>{if(o.scene.tag==="Structural")return _S(t)(e)(n)(r)(o)(o.scene._1);if(o.scene.tag==="Hold")return[];if(o.scene.tag==="DataFlow")return pS(t)(e)(o)(o.scene._1);if(o.scene.tag==="EnterNode")return[];if(o.scene.tag==="ExitNode")return[];if(o.scene.tag==="StepScene")return[];_()},yS=t=>e=>n=>{const r=t0(t)(e)(n.events);return r.length===0?t.gap:b(Sn)(0)(U(o=>o.endT)(r))+t.gap},xS=t=>e=>n=>r=>o=>{if(o.tag==="Structural")return n0(t)(e)(n)(r)(o._1).duration;if(o.tag==="Hold")return t.stillHold;if(o.tag==="DataFlow")return yS(t)(e)(o._1);if(o.tag==="EnterNode"||o.tag==="ExitNode"||o.tag==="StepScene")return 0;_()},r0=t=>e=>n=>r=>o=>i=>{const a=Yy(e)(r),s=n.layout,u=l1(U(p=>L(p.id,p))(o.keyframes)),c=0<o.keyframes.length?T("Just",o.keyframes[0]):w,g=(()=>{if(c.tag==="Just")return c._1.id;if(c.tag==="Nothing")return"";_()})(),l=mx(o),d=p=>({startT:p.runStart,endT:p.t,path:r,layout:s,placement:a,windows:p.runWindows,spans:p.runSpans,keyframes:u,initialKeyframe:g,edgeEndpoints:l}),f=p=>({segments:p.runSpans.length===0?p.segments:St(p.segments)(d(p)),spans:p.spans,windows:p.windows,dives:p.dives}),h=b(p=>x=>{if(x.tag==="EnterNode"){const J=f(p),k=p.runSpans.length===0?{...J,segments:St(J.segments)(d(p))}:J,S=p.t+t.diveDur,A=St(r)(x._1),I=r0(t)(e)(uS(n)(x._1))(A)(eS(o)(x._1))(S),$=I.endT+t.retreatDur;return{...p,t:$,runStart:$,runSpans:[],runWindows:[],segments:[...k.segments,...I.segments],spans:[...k.spans,...I.spans],windows:[...k.windows,...I.windows],dives:[...k.dives,{startT:p.t,endT:S,node:x._1,parentPath:r,childPath:A,direction:ow},...I.dives,{startT:I.endT,endT:$,node:x._1,parentPath:r,childPath:A,direction:iw}]}}if(x.tag==="ExitNode")return p;const y=p.t+xS(t)(s)(u)(l)(x),N={startT:p.t,endT:y,scene:x},v=mS(t)(s)(u)(l)(N);return{...p,t:y,runSpans:St(p.runSpans)(N),runWindows:[...p.runWindows,...v],spans:St(p.spans)(N),windows:[...p.windows,...v]}})({t:i,runStart:i,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(o.scenes),m=f(h);return{endT:h.t,spans:m.spans,windows:Gt(p=>x=>at.compare(p.startT)(x.startT))(m.windows),segments:m.segments,dives:m.dives}},wS=t=>e=>{const n=at.compare(t.time)(e.time);return n==="EQ"?P.compare(t.id)(e.id):n},qn=t=>e=>e-b(n=>r=>n+Sn(0)(Kp(e)(r.endT)-r.startT))(0)(t),NS=t=>e=>{const n=Sn(t.startT)(e.startT),r=Kp(t.endT)(e.endT);return r>n+1e-4?T("Just",{startT:n,endT:r}):w},TS=t=>e=>{if(e.scene.tag==="Structural"){const n=b(r=>o=>({cursor:Sn(r.cursor)(o.endT),cuts:o.startT>r.cursor+1e-4?St(r.cuts)({startT:r.cursor,endT:o.startT}):r.cuts}))({cursor:e.startT,cuts:[]})(Gt(r=>o=>at.compare(r.startT)(o.startT))(wt(NS(e))(t)));return e.endT>n.cursor+1e-4?St(n.cuts)({startT:n.cursor,endT:e.endT}):n.cuts}return[]},vS=t=>{const e=tS(Et(t.spans)(TS(t.windows)));return e.length===0?t:{...t,endT:qn(e)(t.endT),spans:U(n=>({...n,startT:qn(e)(n.startT),endT:qn(e)(n.endT)}))(t.spans),windows:Gt(n=>r=>at.compare(n.startT)(r.startT))(U(n=>({...n,startT:qn(e)(n.startT),endT:qn(e)(n.endT)}))(t.windows)),segments:U(n=>({...n,startT:qn(e)(n.startT),endT:qn(e)(n.endT),spans:U(r=>({...r,startT:qn(e)(r.startT),endT:qn(e)(r.endT)}))(n.spans),windows:Gt(r=>o=>at.compare(r.startT)(o.startT))(U(r=>({...r,startT:qn(e)(r.startT),endT:qn(e)(r.endT)}))(n.windows))}))(t.segments),dives:U(n=>({...n,startT:qn(e)(n.startT),endT:qn(e)(n.endT)}))(t.dives)}},bS=t=>{const e=U(iS)(t.segments);return vS({...t,segments:e,windows:Gt(n=>r=>at.compare(n.startT)(r.startT))(Et(e)(n=>n.windows))})},JS=t=>e=>n=>{const r=Sn(.05)(1-t-e),o=u=>{if(u<=0)return 0;if(u>=1)return 1;const c=t+u*r;return c<0?0:c>1?1:c},i=U5(n),a=U(u=>rt(Q5(1)(un(u).length)))(i),s=Sn(1)(b(ur)(0)(a));return Ot(u=>c=>({lineIndex:u,text:c,start:o(b(ur)(0)(u<1?[]:Rt(0,u,a))/s),end:o(u>=0&&u<a.length?(b(ur)(0)(u<1?[]:Rt(0,u,a))+a[u])/s:(b(ur)(0)(u<1?[]:Rt(0,u,a))+1)/s)}))(i)},CS=t=>{const e=Sn(0)(t.window.endT-t.window.startT);return U(n=>({...e0,id:"token:"+t.eventId+":line:"+ae(n.lineIndex),kind:"tokenLine",time:t.window.startT+n.start*e,endTime:t.window.startT+n.end*e,path:Zp(t.path),tokenIndex:t.tokenIndex,lineIndex:n.lineIndex,text:n.text,from:t.from,to:t.to}))(JS(t.holdPre)(t.holdPost)(t.labels))},kS=t=>Et(Ot(e=>n=>({path:n.path,eventId:n.eventId,window:n.window,from:n.from,to:n.to,labels:n.labels,holdPre:n.holdPre,holdPost:n.holdPost,tokenIndex:e}))(Et(t)(Y5)))(CS),LS=t=>Ot(e=>n=>({...n,index:e}))(Gt(wS)([...Et(t.segments)(gS),...kS(t.segments)])),SS=t=>e=>{if(e.tag==="Structural")return wt(n=>n)([Pu(e._1.from)(t)?w:T("Just",vo("UnknownKeyframe",e._1.from)),Pu(e._1.to)(t)?w:T("Just",vo("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return wt(n=>n)([Pu(e._1)(t)?w:T("Just",vo("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...wt(n=>n)([Pu(e._1.keyframe)(t)?w:T("Just",vo("UnknownKeyframe",e._1.keyframe))]),...lS(e._1.events),...dS(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];if(e.tag==="StepScene")return[];_()},ES=t=>e=>{const n=Et(e)(SS(t));return n.length===0?It("Right",void 0):It("Left",n)},AS=t=>e=>n=>r=>{if(0<n.keyframes.length){const o=n.keyframes[0],i=l1(U(s=>L(s.id,s))(n.keyframes)),a=ES(i)(n.scenes);return(()=>{if(a.tag==="Left"){const s=a._1;return u=>It("Left",s)}if(a.tag==="Right"){const s=a._1;return u=>u(s)}_()})()(()=>{const s=bS(r0(e)(r)(r)([])(n)(0));return It("Right",{totalDuration:s.endT,windows:s.windows,spans:s.spans,keyframes:i,initialKeyframe:o.id,timing:e,layout:r.layout,cameraSpans:K1(t)(Px)(r.layout)(i)(s),cameraConfig:t,levelTree:r,segments:s.segments,dives:s.dives,cues:LS(s),seed:n.seed})})}return It("Left",[W5])},ci=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(o=>n(o._1)(o._2)),Apply0:()=>o0(t)}),o0=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>o=>i=>e.map(a=>L(r(a._1),a._2))(o(i))};return{apply:(()=>{const r=ci(t);return o=>i=>r.bind(o)(a=>r.bind(i)(s=>gi(t).pure(a(s))))})(),Functor0:()=>n}},gi=t=>({pure:e=>n=>t.Applicative0().pure(L(e,n)),Apply0:()=>o0(t)}),i0=t=>{const e={Applicative0:()=>gi(t),Bind1:()=>ci(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},or=(t,e)=>({tag:"ParseError",_1:t,_2:e}),C=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),Gu=(t,e,n)=>({tag:t,_1:e,_2:n}),PS=t=>Gu("More",t),RS=t=>Gu("Lift",t),GS={defer:t=>{const e=Sy(t);return(n,r,o,i,a)=>Ey(e)(n,r,o,i,a)}},a0={map:t=>e=>(n,r,o,i,a)=>r(s=>e(n,r,o,i,(u,c)=>r(g=>a(u,t(c)))))},DS={alt:t=>e=>(n,r,o,i,a)=>{const s=n._1,u=n._2;return r(c=>t(C(s,u,!1),r,o,(g,l)=>{const d=g._3;return r(f=>d?i(g,l):e(n,r,o,i,a))},a))},Functor0:()=>a0},FS=t=>{const e=t.Monad0();return n=>r=>{const o=i=>{let a=i,s=!0,u;for(;s;){const c=a();if(c.tag==="More"){a=c._1;continue}if(c.tag==="Lift"){s=!1,u=e.Bind1().Apply0().Functor0().map(_c)(c._1);continue}if(c.tag==="Stop"){s=!1,u=e.Applicative0().pure(pi("Done",L(c._2,c._1)));continue}_()}return u};return t.tailRecM(o)(i=>r(n,PS,RS,(a,s)=>Gu("Stop",a,It("Left",s)),(a,s)=>Gu("Stop",a,It("Right",s))))}},Un=(t,e,n,r,o)=>o(t,t._2),IS={index:0,line:1,column:1},s0=(t=>{const e=FS(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(os)(e(C(n,IS,!1))(r))})(c2),Du=(t,e,n,r,o)=>o(C(t._1,t._2,!0),void 0),u0={apply:t=>e=>(n,r,o,i,a)=>r(s=>t(n,r,o,i,(u,c)=>r(g=>{const l=n._3&&!u._3?C(u._1,u._2,!0):u;return e(l,r,o,i,(d,f)=>r(h=>a(l._3&&!d._3?C(d._1,d._2,!0):d,c(f))))}))),Functor0:()=>a0},c0={pure:t=>(e,n,r,o,i)=>i(e,t),Apply0:()=>u0},BS={bind:t=>e=>(n,r,o,i,a)=>r(s=>t(n,r,o,i,(u,c)=>r(g=>e(c)(n._3&&!u._3?C(u._1,u._2,!0):u,r,o,i,a)))),Apply0:()=>u0},MS={Applicative0:()=>c0,Bind1:()=>BS},Fu=t=>(e,n,r,o,i)=>n(a=>Un(e,n,r,o,(s,u)=>n(c=>o(e._3&&!s._3?C(s._1,s._2,!0):s,or(t,u))))),zS={empty:Fu("No alternative"),Alt0:()=>DS},QS={Applicative0:()=>c0,Plus1:()=>zS},Xe=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return o=>t.tailRecM(i=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(_c)(o))(r.pure(pi("Done",void 0))))(a=>r.pure((()=>{if(a.tag==="Loop")return pi("Loop",yt("Cons",a._1,i));if(a.tag==="Done")return pi("Done",(s=>u=>{let c=s,g=u,l=!0,d;for(;l;){const f=c,h=g;if(h.tag==="Nil"){l=!1,d=f;continue}if(h.tag==="Cons"){c=yt("Cons",h._1,f),g=h._2;continue}_()}return d})(R)(i));_()})())))(R)})({tailRecM:t=>e=>(n,r,o,i,a)=>{const s=(u,c,g)=>t(c)(u,r,o,i,(l,d)=>{const f=u._3&&!l._3?C(l._1,l._2,!0):l;if(d.tag==="Loop")return g===0?r(h=>s(f,d._1,30)):s(f,d._1,g-1|0);if(d.tag==="Done")return a(f,d._1);_()});return s(n,e,30)},Monad0:()=>MS})(QS),pt=t=>e=>{const n=Fu("Expected "+e);return(r,o,i,a,s)=>{const u=r._1,c=r._2;return o(g=>t(C(u,c,!1),o,i,(l,d)=>{const f=l._3;return o(h=>f?a(l,d):n(r,o,i,a,s))},s))}},bo=t=>(e,n,r,o,i)=>{const a=e._3,s=e._1,u=e._2;return n(c=>{const g=(l,d)=>{const f=l._3;return n(h=>f?o(C(l._1,l._2,a),d):i(e,void 0))};return n(l=>n(d=>t(C(s,u,!1),n,r,(f,h)=>g(C(f._1,f._2,!1),h),(f,h)=>n(m=>n(p=>Fu("Negated parser succeeded")(f,n,r,g,(x,y)=>n(N=>i(f._3&&!x._3?C(x._1,x._2,!0):x,y))))))))})},WS=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return T("Just",n);if(r.tag==="Just")return T("Just",(o,i,a,s,u)=>{const c=o._1,g=o._2;return i(l=>n(C(c,g,!1),i,a,(d,f)=>{const h=d._3;return i(m=>h?s(d,f):r._1(o,i,a,s,u))},u))});_()})(w);return n=>{const r=e(n);if(r.tag==="Nothing")return Fu("No alternative");if(r.tag==="Just")return r._1;_()}},g0=t=>e=>n=>(r,o,i,a,s)=>o(u=>o(c=>o(g=>o(l=>t(r,o,i,a,(d,f)=>o(h=>o(m=>{const p=r._3&&!d._3?C(d._1,d._2,!0):d;return n(p,o,i,a,(x,y)=>o(N=>{const v=p._3&&!x._3?C(x._1,x._2,!0):x;return o(J=>o(k=>{const S=r._3&&!v._3?C(v._1,v._2,!0):v;return e(S,o,i,a,(A,I)=>o($=>s(S._3&&!A._3?C(A._1,A._2,!0):A,y)))}))}))}))))))),U_=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=tw()(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)-co(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},OS=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,c=o,g=i,l=Es(c);if(l.tag==="Nothing"){a=!1,s=u;continue}if(l.tag==="Just"){r=l._1.tail===""?U_(u)(l._1.head)(g):U_(u)(l._1.head)(l._1.tail),o=l._1.tail,i=g;continue}_()}return s},Pt=t=>(e,n,r,o,i)=>{const a=Es(e._1);if(a.tag==="Nothing")return o(e,or("Unexpected EOF",e._2));if(a.tag==="Just"){if(a._1.head<0||a._1.head>65535)return o(e,or("Expected Char",e._2));if(a._1.head>=0&&a._1.head<=65535){const s=w1(a._1.head);return t(s)?i(C(a._1.tail,U_(e._2)(a._1.head)(a._1.tail),!0),s):o(e,or("Predicate unsatisfied",e._2))}}_()},Vi=(t,e,n,r,o)=>t._1===""?o(C(t._1,t._2,!0),void 0):r(t,or("Expected EOF",t._2)),HS=t=>(e,n,r,o,i)=>{const a=t(e._1);if(a.tag==="Left")return o(e,or(a._1,e._2));if(a.tag==="Right")return i(C(a._1.remainder,OS(e._2)(a._1.consumed)(a._1.remainder),a._1.consumed!==""),a._1.value);_()},Le=t=>HS(e=>{const n=Yn(t)(e);return n.tag==="Just"?It("Right",{value:t,consumed:t,remainder:n._1}):It("Left","Expected "+Tf(t))}),X_=Pt(t=>!0),_0=(t,e)=>({tag:t,_1:e}),f0=(t,e,n)=>({tag:t,_1:e,_2:n}),$S=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},l0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},qS=t=>e=>b(n=>r=>(()=>{if(n.tag==="Left"){const o=n._1;return i=>It("Left",o)}if(n.tag==="Right"){const o=n._1;return i=>i(o)}_()})()(o=>t(o)(r)))(It("Right",e)),d0=t=>e=>n=>$S(t)(n.values)?It("Right",{...n,values:it(P)(t)(e)(n.values)}):It("Left","label has no placeholder `"+t+"`"),h0=(()=>{const t=bo((e,n,r,o,i)=>{const a=e._3;return Le("{{")(e,n,r,(s,u)=>o(C(s._1,s._2,a),u),i)});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>X_(e._3&&!s._3?C(s._1,s._2,!0):s,n,r,o,i))))})(),US=(()=>{const t=bo((e,n,r,o,i)=>{const a=e._3;return Le("}}")(e,n,r,(s,u)=>o(C(s._1,s._2,a),u),i)});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>X_(e._3&&!s._3?C(s._1,s._2,!0):s,n,r,o,i))))})(),Yi=t=>Qn("")(U(e=>{if(e.tag==="LabelText")return e._1;if(e.tag==="LabelSlot"){const n=l0(e._1)(t.values);if(n.tag==="Just")return n._1;if(n.tag==="Nothing")return""}_()})(t.parts)),XS=(t,e,n,r,o)=>e(i=>h0(t,e,n,r,(a,s)=>e(u=>{const c=Xe(h0),g=t._3&&!a._3?C(a._1,a._2,!0):a;return e(l=>c(g,e,n,r,(d,f)=>e(h=>o(g._3&&!d._3?C(d._1,d._2,!0):d,f0("ParsedText",In([s,...Wt(ue.foldr,f)]))))))}))),VS=t=>t===" "||t===" "||t===`
11
- `||t==="\r",p0=(()=>{const t=Xe(Pt(VS));return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>i(s,void 0))))})(),YS=t=>t>="a"&&t<="z"||t>="A"&&t<="Z"||t==="_",KS=t=>t>="a"&&t<="z"||t>="A"&&t<="Z"||t==="_"||t>="0"&&t<="9"||t==="-",jS=(t,e,n,r,o)=>e(i=>Pt(YS)(t,e,n,r,(a,s)=>e(u=>{const c=Xe(Pt(KS)),g=t._3&&!a._3?C(a._1,a._2,!0):a;return e(l=>c(g,e,n,r,(d,f)=>e(h=>o(g._3&&!d._3?C(d._1,d._2,!0):d,cr(s)+In(Wt(ue.foldr,f))))))}))),ZS=(t,e,n,r,o)=>e(i=>Le("{{")(t,e,n,r,(a,s)=>e(u=>{const c=t._3&&!a._3?C(a._1,a._2,!0):a;return e(g=>p0(c,e,n,r,(l,d)=>e(f=>{const h=c._3&&!l._3?C(l._1,l._2,!0):l;return e(m=>jS(h,e,n,r,(p,x)=>e(y=>{const N=h._3&&!p._3?C(p._1,p._2,!0):p;return e(v=>p0(N,e,n,r,(J,k)=>e(S=>{const A=pt(Pt($=>$===":"))("':'"),I=N._3&&!J._3?C(J._1,J._2,!0):J;return e($=>A(I,e,n,r,(E,G)=>e(nt=>{const V=Xe(US),Q=I._3&&!E._3?C(E._1,E._2,!0):E;return e(Y=>e(X=>V(Q,e,n,r,(D,F)=>e(B=>{const z=In(Wt(ue.foldr,F));return e(j=>{const W=Q._3&&!D._3?C(D._1,D._2,!0):D;return e(O=>Le("}}")(W,e,n,r,(q,H)=>e(ot=>o(W._3&&!q._3?C(q._1,q._2,!0):q,f0("ParsedSlot",x,fa(z))))))})}))))})))})))})))})))}))),tE=(()=>{const t=Xe((e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>ZS(C(a,s,!1),n,r,(c,g)=>{const l=c._3;return n(d=>l?o(c,g):XS(e,n,r,o,i))},i))});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>i(s,Wt(ue.foldr,u)))))})(),eE=t=>{const e=qS(n=>r=>{if(r.tag==="ParsedText")return It("Right",{...n,parts:St(n.parts)(_0("LabelText",r._1))});if(r.tag==="ParsedSlot"){const o=l0(r._1)(n.values);return o.tag==="Just"&&o._1!==r._2?It("Left","placeholder `"+r._1+"` has conflicting initial values"):It("Right",{parts:St(n.parts)(_0("LabelSlot",r._1)),values:it(P)(r._1)(r._2)(n.values)})}_()})({parts:[],values:M})(t);if(e.tag==="Left")return It("Left",e._1);if(e.tag==="Right")return It("Right",e._1);_()},Iu=t=>{const e=s0(t)((n,r,o,i,a)=>r(s=>r(u=>tE(n,r,o,i,(c,g)=>r(l=>r(d=>{const f=n._3&&!c._3?C(c._1,c._2,!0):c;return Vi(f,r,o,i,(h,m)=>r(p=>a(f._3&&!h._3?C(h._1,h._2,!0):h,g)))}))))));if(e.tag==="Left")return It("Left",e._1._1);if(e.tag==="Right")return eE(e._1);_()},_i=(t,e)=>({tag:t,_1:e}),Fr=(t,e)=>({tag:t,_1:e}),Bu=t=>t,Xn=(t,e)=>({tag:t,_1:e}),V_=t=>t,m0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},nE=ge(P)(Mt),y0=(()=>{const t=mn.unfoldr(e=>{if(e.tag==="Nil")return w;if(e.tag==="Cons")return T("Just",L(e._1,e._2));_()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,yt("Cons",r._3,n(r._6,o)));_()};return n(e,R)})())})(),Ce=i0(Gn),rE=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},oE=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},iE=ge(P)(Mt),Y_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},aE=b(t=>e=>it(P)(e)()(t))(M),qt=ci(Gn),Ve=Ce.state(t=>L(t,t)),he=gi(Gn),x0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},w0=io(he),K_=w0(Mt),sE=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},hr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},pr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},uE=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},Mu=t=>e=>n=>b(r=>o=>t.Bind1().bind(r)(i=>e(i)(o)))(t.Applicative0().pure(n)),cE=b(t=>e=>it(P)(e)()(t))(M),gE=(()=>{const t=(e=>n=>{let r=e,o=n,i=!0,a;for(;i;){const s=r,u=o;if(u.tag==="Nil"){i=!1,a=s;continue}if(u.tag==="Cons"){r=it(P)(u._1)()(s),o=u._2;continue}_()}return a})(M);return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,yt("Cons",r._3,n(r._6,o)));_()};return n(e,R)})())})(),_E=b(t=>e=>it(P)(e)()(t))(M),fE=w0(Sf),lE=V_("AnimatedSurface"),dE=V_("StillSurface"),hE=V_("SequenceSurface"),pE=Xn("Exit"),zu=Bu("AnimatedKeyframe"),j_=Bu("Still"),mE=Bu("Title"),N0=Bu("StepMarker"),yE=t=>Fr("Par",t),xE=t=>Fr("Seq",t),wE=t=>Fr("GroupSeq",t),T0=t=>_i("StepDive",t),NE={line:0,column:0,endLine:0,endColumn:0},TE=t=>e=>n=>{const r=Mr(Ut,w,o=>o._1===t,n);if(r.tag==="Just"){const o=uo(Ut,w,r._1,L(t,e),n);if(o.tag==="Nothing")return n;if(o.tag==="Just")return o._1;_()}if(r.tag==="Nothing")return St(n)(L(t,e));_()},vE=t=>e=>U(n=>n._1===t?L(n._1,{...n._2,label:T("Just",e)}):L(n._1,n._2)),v0=t=>nE(wt(e=>{const n=m0(e)(t.currLabels);return n.tag==="Just"?T("Just",L(e,n._1)):w})(y0(t.currNodes))),b0=t=>{const e=t.compare;return n=>b(r=>o=>Qe(e,Be,r,n(o)))(M)},Z_=b0(P),tf=b0(P),J0=t=>e=>Ce.state(n=>L(void 0,{...n,graphNodes:vE(t)(Yi(e))(n.graphNodes),currLabels:it(P)(t)(Yi(e))(n.currLabels),currLabelTemplates:it(P)(t)(e)(n.currLabelTemplates)})),bE=t=>{const e=t.span;return Ce.state(n=>L(void 0,{...n,currentSpan:e}))},JE=rt(4)*8,CE=t=>t.tag==="Just"&&ss(t._1)&&t._1>0?L(rE(1)(t._1/JE),1):L(1,1),kE=t=>e=>({structural:[...t.structural,...e.structural],flow:t.flow||e.flow,dives:[...t.dives,...e.dives]}),LE=t=>e=>e.kind==="Animated"||oE(e.id)(t),C0={graphNodes:[],graphEdges:M,currNodes:M,currEdges:M,currLabels:M,currLabelTemplates:M,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:w,currentSpan:NE,error:w,enterStack:[],interiorOf:M,stepNames:M},k0=t=>e=>n=>{const r=Wt(ln.foldr,n);return Qn(", ")(U(e)(Rt(0,6,r)))+(r.length>6?", \u2026":"")},SE=t=>e=>{const n=Y_(e)(iE(U(r=>L(r.id,r))(t.graph.edges)));if(n.tag==="Just")return(()=>{const r=Yn("conn:")(n._1.id);if(r.tag==="Just")return!1;if(r.tag==="Nothing")return!0;_()})()?n._1.from.node+" -> "+n._1.to.node:n._1.from.node+" -- "+n._1.to.node;if(n.tag==="Nothing")return e;_()},EE=t=>e=>n=>{const r=k0()(ea)(e),o=k0()(SE(t))(n);return(r===""?"animated flow contains unused topology: every animated node or edge must be visited by a token or fill.":"animated flow contains unused topology: every animated node or edge must be visited by a token or fill. Unused nodes: "+r+".")+(o===""?"":" Unused edges: "+o+".")+" Move context-only topology into a `still`/`title`, remove it, or add token/fill events."},AE=t=>{if(t.kind.tag==="SendToken")return aE([t.kind._1.from,t.kind._1.to]);if(t.kind.tag==="FillNodeWithoutTransition")return ee("Node",1,1,t.kind._1.node,void 0,M,M);_()},PE=t=>Z_(AE)(t.events),RE=t=>{if(t.kind.tag==="SendToken")return ee("Node",1,1,t.kind._1.edge,void 0,M,M);if(t.kind.tag==="FillNodeWithoutTransition")return M;_()},GE=t=>tf(RE)(t.events),mr=t=>Ce.state(e=>L(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:T("Just",{msg:t,line:e.currentSpan.line,column:e.currentSpan.column,endLine:e.currentSpan.endLine,endColumn:e.currentSpan.endColumn})};_()})())),DE=K_(t=>qt.bind(Ve)(e=>{if(e.error.tag==="Just")return he.pure();if(e.error.tag==="Nothing")return x0(t.node)(e.interiorOf)?mr("node "+t.node+" has more than one `inside` block"):Ce.state(n=>L(void 0,{...n,interiorOf:it(P)(t.node)(t.doc)(n.interiorOf)}));_()})),FE=t=>qt.bind(Ve)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ae(e.kfCounter);if(ne(o=>o.id===n,e.keyframes))return mr("duplicate frame name "+n);const r={...e,keyframes:St(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges,labels:v0(e),kind:ca}),kfCounter:e.kfCounter+1|0,currentKf:T("Just",n)};return Ce.state(o=>L(void 0,r))}),We=t=>e=>qt.bind(Ce.state(n=>L(void 0,{...n,currentSpan:t})))(()=>mr(e)),L0=t=>e=>qt.bind(Ve)(n=>sE(e)(n.stepNames)?We(t)("duplicate step name "+e):Ce.state(r=>L(void 0,{...r,scenes:St(r.scenes)(ki("StepScene",e)),stepNames:it(P)(e)()(r.stepNames)}))),IE=t=>{if(t.ops.tag==="Leaf"){const e=t.ops._1;return qt.bind((()=>{const n=e.span;return Ce.state(r=>L(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?L0(e.span)(e.op._1.name):mr("step marker frame did not contain a step"))}if(t.ops.tag==="Seq"&&t.ops._1.length===1&&t.ops._1[0].tag==="Leaf"){const e=t.ops._1[0]._1;return qt.bind((()=>{const n=e.span;return Ce.state(r=>L(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?L0(e.span)(e.op._1.name):mr("step marker frame did not contain a step"))}return mr("step marker frame did not contain a step")},BE=t=>qt.bind((()=>{const e=t.span;return Ce.state(n=>L(void 0,{...n,currentSpan:e}))})())(()=>qt.bind(Ve)(e=>{if(e.error.tag==="Just")return he.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!hr(t.op._1.id)(e.currNodes))return We(0<t.operands.length?t.operands[0]:t.span)("cannot dive into node "+t.op._1.id+": does not exist");if(!x0(t.op._1.id)(e.interiorOf))return We(0<t.operands.length?t.operands[0]:t.span)("cannot enter node "+t.op._1.id+": it has no `inside` block. Add the block at the document level, alongside the animated statements:\n\ninside "+t.op._1.id+` {
1
+ var aG=(function(tc){"use strict";function Sm(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 Nr(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const Qe=t=>e=>t,Y=function(t){return function(e){for(var n=e.length,r=new Array(n),o=0;o<n;o++)r[o]=t(e[o]);return r}},Em={map:Y},cf=t=>t,Et=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,o=0;o<r;o++)for(var i=e(t[o]),a=i.length,s=0;s<a;s++)n.push(i[s]);return n}},Pm=function(t){return function(e){return{}.hasOwnProperty.call(e,t)}},Gm=function(t){return function(e){return e[t]}},ae=function(t){return t.toString()},Fo=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},Am=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 o=r+1,i=o<e&&t[o]>="0"&&t[o]<="9"?"\\&":"";return"\\"+n.charCodeAt(0).toString(10)+i})+'"'},ec=t=>t,ze=ec("LT"),Me=ec("GT"),un=ec("EQ"),N=(t,e)=>({tag:t,_1:e}),w=N("Nothing"),Yt=t=>N("Just",t),gf=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;g()},_f=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;g()},It=(t,e)=>({tag:t,_1:e}),Rm=t=>It("Right",t),Dm={map:t=>e=>{if(e.tag==="Left")return It("Left",e._1);if(e.tag==="Right")return It("Right",t(e._1));g()}},ff={apply:t=>e=>{if(t.tag==="Left")return It("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return It("Left",e._1);if(e.tag==="Right")return It("Right",t._1(e._1))}g()},Functor0:()=>Dm},Fm={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>It("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}g()},Apply0:()=>ff},Im={pure:Rm,Apply0:()=>ff},df={Applicative0:()=>Im,Bind1:()=>Fm},Bm=t=>t,Qm={map:t=>e=>t(e)},lf={apply:t=>e=>t(e),Functor0:()=>Qm},zm={bind:t=>e=>e(t),Apply0:()=>lf},Mm={pure:Bm,Apply0:()=>lf},In={Applicative0:()=>Mm,Bind1:()=>zm},Om=function(t){return function(){return t}},Wm={apply:t=>e=>()=>{const n=t(),r=e();return nc.pure(n(r))()},Functor0:()=>qm},nc={pure:Om,Apply0:()=>Wm},qm={map:t=>e=>()=>{const n=e();return t(n)}},Ti=(t,e)=>({tag:t,_1:e}),rc=t=>Ti("Loop",t),Hm=t=>Ti("Done",t),$m={tailRecM:t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const a=r;if(a.tag==="Loop"){r=t(a._1);continue}if(a.tag==="Done"){o=!1,i=a._1;continue}g()}return i};return n=>e(t(n))},Monad0:()=>In},Ym=function(t){return function(e){return function(){return t(e())}}},Vm=function(t){return function(){return t}},Xm=function(t){return function(e){return function(){return e(t())()}}},Um={map:Ym},Km={Applicative0:()=>oc,Bind1:()=>Zm},Zm={bind:Xm,Apply0:()=>hf},hf={apply:t=>e=>()=>{const n=t(),r=e();return oc.pure(n(r))()},Functor0:()=>Um},oc={pure:Vm,Apply0:()=>hf},jm={tailRecM:t=>e=>{const n=t(e);return()=>{let r=n();for(;r.tag==="Loop";){const i=r;if(i.tag==="Loop"){r=t(i._1)();continue}i.tag!=="Done"&&g()}const o=r;if(o.tag==="Done")return o._1;g()}},Monad0:()=>Km},t2=function(t){return function(e){return function(n){return function(){return t(e,n)}}}},e2=function(t,e,n,r){return n>=0&&n<r.length?t(r[n]):e},ic=function(t){return t.length},n2=function(t,e,n){return n.length>0?t(n.pop()):e},r2=t2(function(t,e){return e.push(t)}),o2=(t,e)=>({tag:"Iterator",_1:t,_2:e}),i2=t=>e=>n=>()=>{let r=!1;const o=e._2;for(;!r;){const i=o.value,a=e._1(i);if(a.tag==="Just"&&t(a._1)){n.push(a._1),e._2.value;const s=e._2.value;e._2.value=s+1|0;continue}r=!0}},a2=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const o=r.value,i=r.value;r.value=i+1|0;const a=t._1(o);if(a.tag==="Just"){e(a._1)();continue}if(a.tag==="Nothing"){n=!0;continue}g()}},Ni=function(t){return function(e){return function(n){for(var r=e,o=n.length,i=o-1;i>=0;i--)r=t(n[i])(r);return r}}},J=function(t){return function(e){return function(n){for(var r=e,o=n.length,i=0;i<o;i++)r=t(r)(n[i]);return r}}},co=t=>{const e=t.Apply0();return n=>r=>n.foldr(o=>{const i=r(o);return a=>e.apply(e.Functor0().map(s=>cf)(i))(a)})(t.pure())},vi=t=>{const e=co(t);return n=>{const r=e(n);return o=>i=>r(i)(o)}},pf={foldr:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(n._1)(e);g()},foldl:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(e)(n._1);g()},foldMap:t=>{const e=t.mempty;return n=>r=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return n(r._1);g()}}},Qt={foldr:Ni,foldl:J,foldMap:t=>{const e=t.mempty;return n=>Qt.foldr(r=>o=>t.Semigroup0().append(n(r))(o))(e)}},L=(t,e)=>({tag:"Tuple",_1:t,_2:e}),bn=t=>e=>L(t,e),Ua=t=>t._2,Ka=t=>t._1,Wt=function(t){return function(e){for(var n=e.length,r=Array(n),o=0;o<n;o++)r[o]=t(o)(e[o]);return r}};var ac=function(t){return function(e){return t===e}};const s2=ac,u2=ac,ta=ac,sc=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}}},vr={eq:ta},c2={eq:u2},go={eq:s2};var uc=function(t){return function(e){return function(n){return function(r){return function(o){return r<o?t:r===o?e:n}}}}};const g2=uc,_2=uc,A={compare:uc(ze)(un)(Me),Eq0:()=>vr},at={compare:_2(ze)(un)(Me),Eq0:()=>c2},ut={compare:g2(ze)(un)(Me),Eq0:()=>go},ea=function(t){return t},f2=(function(){function t(o){return[o]}function e(o){return function(i){return[o,i]}}function n(o){return function(i){return function(a){return[o,i,a]}}}function r(o){return function(i){return o.concat(i)}}return function(o){return function(i){return function(a){return function(s){return function(u){function c(_,l){switch(l-_){case 0:return a([]);case 1:return i(t)(s(u[_]));case 2:return o(i(e)(s(u[_])))(s(u[_+1]));case 3:return o(o(i(n)(s(u[_])))(s(u[_+1])))(s(u[_+2]));default:var f=_+Math.floor((l-_)/4)*2;return o(i(r)(c(_,f)))(c(f,l))}}return c(0,u.length)}}}}}})(),d2=t=>t,_o={traverse:t=>{const e=t.Apply0();return f2(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>_o.traverse(t)(d2),Functor0:()=>Em,Foldable1:()=>Qt},Ut=function(t,e){for(var n=t>e?-1:1,r=new Array(n*(e-t)+1),o=t,i=0;o!==e;)r[i++]=o,o+=n;return r[i]=o,r};var l2=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},h2=function(t,e){for(var n=[],r=0,o=0;o<t;o++)n[r++]=e;return n};const Io=typeof Array.prototype.fill=="function"?l2:h2,Ot=(function(){function t(o,i){this.head=o,this.tail=i}var e={};function n(o){return function(i){return new t(o,i)}}function r(o){for(var i=[],a=0,s=o;s!==e;)i[a++]=s.head,s=s.tail;return i}return function(o,i){return r(o(n)(e)(i))}})(),Pt=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},mf=function(t,e,n,r){for(var o=0;o<r.length;o++){var i=n(r[o]);if(e(i))return i}return t},Mr=function(t,e,n,r){for(var o=0,i=r.length;o<i;o++)if(n(r[o]))return t(o);return e},yf=function(t,e,n,r,o){if(n<0||n>o.length)return e;var i=o.slice();return i.splice(n,0,r),t(i)},xf=function(t,e,n,r){if(n<0||n>=r.length)return e;var o=r.slice();return o.splice(n,1),t(o)},fo=function(t,e,n,r,o){if(n<0||n>=o.length)return e;var i=o.slice();return i[n]=r,t(i)},re=function(t){return t.slice().reverse()},kn=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 o=t[n],i=0,a=o.length;i<a;i++)e.push(o[i]);return e},lt=function(t,e){return e.filter(t)},p2=function(t,e,n){for(var r=n.length,o=e,i=new Array(r),a=0;a<r;a++)o=t(o)(n[a]),i[a]=o;return i},m2=(function(){function t(e,n,r,o,i,a){var s,u,c,_,l,f,d;for(s=i+(a-i>>1),s-i>1&&t(e,n,o,r,i,s),a-s>1&&t(e,n,o,r,s,a),u=i,c=s,_=i;u<s&&c<a;)l=o[u],f=o[c],d=n(e(l)(f)),d>0?(r[_++]=f,++c):(r[_++]=l,++u);for(;u<s;)r[_++]=o[u++];for(;c<a;)r[_++]=o[c++]}return function(e,n,r){var o;return r.length<2?r:(o=r.slice(0),t(e,n,o,r.slice(0),0,r.length),o)}})(),At=function(t,e,n){return n.slice(t,e)},$e=function(t,e,n){for(var r=e.length<n.length?e.length:n.length,o=new Array(r),i=0;i<r;i++)o[i]=t(e[i])(n[i]);return o},ne=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},cc=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Rt=t=>e=>m2(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),y2=t=>e=>Rt(n=>r=>t.compare(e(n))(e(r))),St=t=>e=>(()=>{const n=r2(e);return()=>{const r=[...t];return n(r)(),r}})()(),Or=t=>{if(t.length===0)return t.length-1|0,w;const e=t.length-1|0;return e>=0&&e<t.length?N("Just",{init:At(0,t.length-1|0,t),last:t[e]}):w},x2=t=>e=>n=>t>=0&&t<n.length?fo(Yt,w,t,e(n[t]),n):w,Jr=t=>e=>{const n=(r=>{let o=r,i=!0,a;for(;i;){const s=o;if(s>=0&&s<e.length){if(t(e[s])){o=s+1|0;continue}i=!1,a=N("Just",s);continue}i=!1,a=w}return a})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:At(0,n._1,e),rest:At(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};g()},Ji=t=>e=>{const n=Rt(r=>o=>t(r._2)(o._2))(Wt(bn)(e));return 0<n.length?Y(Ua)(y2(ut)(Ka)((()=>{const r=[n[0]];for(const o of n){const i=t((()=>{const a=r.length-1|0;if(a>=0&&a<r.length)return r[a]._2;g()})())(o._2);(i==="LT"||i==="GT"||i!=="EQ")&&r.push(o)}return r})())):[]},w2=t=>e=>{const n=[],r=o2(o=>o>=0&&o<e.length?N("Just",e[o]):w,{value:0});return a2(r)(o=>()=>{const i=[];i.push(o),i2(t(o))(r)(i)(),n.push(i)})(),n},te=t=>e=>{const n=Mr(Yt,w,t,e);return n.tag==="Just"?N("Just",e[n._1]):w},na=t=>e=>lt(t,e),ln=t=>e=>n=>{const r=Mr(Yt,w,o=>t.eq(o)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},Za=t=>e=>Et(e)(t),wt=t=>Za(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];g()}),ja=isFinite;function wf(t,e,n,r){var o=parseFloat(t);return e(o)?n(o):r}const de=Math.abs,T2=Math.acos,Bo=function(t){return function(e){return Math.atan2(t,e)}},ts=Math.ceil,hn=Math.cos,Ci=Math.exp,Kn=Math.floor,es=Math.log,N2=function(t){return function(e){return Math.min(t,e)}},gc=function(t){return function(e){return Math.pow(t,e)}},Bn=Math.round,en=Math.sin,nn=Math.sqrt,v2=Math.tan,J2=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},nt=function(t){return t},C2=(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 o=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(i){if(o.test(i)){var a=parseInt(i,n);return(a|0)===a?t(a):e}else return e}}}})(Yt)(w)(10),Tf=J2(Yt)(w),he=t=>{if(!ja(t))return 0;if(t>=nt(2147483647))return 2147483647;if(t<=nt(-2147483648))return-2147483648;const e=Tf(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;g()},pt=(t,e,n)=>({tag:t,_1:e,_2:n}),G=pt("Nil"),ue={foldr:t=>e=>{const n=ue.foldl(o=>i=>t(i)(o))(e),r=(o=>i=>{let a=o,s=i,u=!0,c;for(;u;){const _=a,l=s;if(l.tag==="Nil"){u=!1,c=_;continue}if(l.tag==="Cons"){a=pt("Cons",l._1,_),s=l._2;continue}g()}return c})(G);return o=>n(r(o))},foldl:t=>e=>n=>{let r=e,o=n,i=!0,a;for(;i;){const s=r,u=o;if(u.tag==="Nil"){i=!1,a=s;continue}if(u.tag==="Cons"){r=t(s)(u._1),o=u._2;continue}g()}return a},foldMap:t=>{const e=t.mempty;return n=>ue.foldl(r=>{const o=t.Semigroup0().append(r);return i=>o(n(i))})(e)}},b2=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var a=[],s=i;;){var u=o(s);a.push(n(u));var c=r(u);if(t(c))return a;s=e(c)}}}}}}},k2=t=>{if(t.tag==="Just")return t._1;g()},L2={unfoldr1:b2(gf)(k2)(Ka)(Ua)},S2=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var a=[],s=i;;){var u=o(s);if(t(u))return a;var c=e(u);a.push(n(c)),s=r(c)}}}}}}},E2=t=>{if(t.tag==="Just")return t._1;g()},wn={unfoldr:S2(gf)(E2)(Ka)(Ua),Unfoldable10:()=>L2},ee=(t,e,n,r,o,i,a)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:a}),Tn=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),ns=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),Nf=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),Q=ee("Leaf"),ur=Tn("IterLeaf"),Se=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return ee("Node",1,1,t,e,n,r);if(r.tag==="Node")return ee("Node",1+r._1|0,1+r._2|0,t,e,n,r);g()}if(n.tag==="Node"){if(r.tag==="Leaf")return ee("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return ee("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()},cn=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?ee("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()},bi=(t,e,n)=>{if(n.tag==="Leaf")return ns(w,Q,Q);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const o=bi(t,e,n._5);return ns(o._1,o._2,cn(n._3,n._4,o._3,n._6))}if(r==="GT"){const o=bi(t,e,n._6);return ns(o._1,cn(n._3,n._4,n._5,o._2),o._3)}if(r==="EQ")return ns(N("Just",n._4),n._5,n._6)}g()},vf=(t,e,n,r)=>{if(r.tag==="Leaf")return Nf(t,e,n);if(r.tag==="Node"){const o=vf(r._3,r._4,r._5,r._6);return Nf(o._1,o._2,cn(t,e,n,o._3))}g()},ki=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=vf(t._3,t._4,t._5,t._6);return cn(n._1,n._2,n._3,e)}g()},cr=(t,e,n)=>{if(e.tag==="Leaf")return Q;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=bi(t,n._3,e);return ki(cr(t,r._2,n._5),cr(t,r._3,n._6))}g()},rs=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return Q;if(r.tag==="Node"){const o=bi(t,r._3,n),i=rs(t,e,o._2,r._5),a=rs(t,e,o._3,r._6);if(o._1.tag==="Just")return cn(r._3,e(o._1._1)(r._4),i,a);if(o._1.tag==="Nothing")return ki(i,a)}g()},Oe=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const o=bi(t,r._3,n),i=Oe(t,e,o._2,r._5),a=Oe(t,e,o._3,r._6);if(o._1.tag==="Just")return cn(r._3,e(o._1._1)(r._4),i,a);if(o._1.tag==="Nothing")return cn(r._3,r._4,i,a)}g()},Jf=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node"){const i=t.compare(n)(o._3);if(i==="LT")return cn(o._3,o._4,r(o._5),o._6);if(i==="GT")return cn(o._3,o._4,o._5,r(o._6));if(i==="EQ"){const a=e(o._4);if(a.tag==="Nothing")return ki(o._5,o._6);if(a.tag==="Just")return ee("Node",o._1,o._2,o._3,a._1,o._5,o._6)}}g()};return r},P2=t=>e=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node"){const o=e(r._3)(r._4);if(o.tag==="Just")return cn(r._3,o._1,n(r._5),n(r._6));if(o.tag==="Nothing")return ki(n(r._5),n(r._6))}g()};return n},gr=(t=>e=>n=>{let r=n,o=!0,i;for(;o;){const a=r;if(a.tag==="IterLeaf"){o=!1,i=e();continue}if(a.tag==="IterEmit"){o=!1,i=t(a._1,a._2,a._3);continue}if(a.tag==="IterNode"){r=(s=>u=>{let c=s,_=u,l=!0,f;for(;l;){const d=c,h=_;if(h.tag==="Leaf"){l=!1,f=d;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){c=Tn("IterEmit",h._3,h._4,d),_=h._5;continue}c=Tn("IterEmit",h._3,h._4,Tn("IterNode",h._6,d)),_=h._5;continue}g()}return f})(a._2)(a._1);continue}g()}return i})((t,e,n)=>N("Just",L(L(t,e),n)))(t=>w),zt=t=>e=>n=>r=>{const o=i=>{if(i.tag==="Leaf")return ee("Node",1,1,n,r,Q,Q);if(i.tag==="Node"){const a=t.compare(n)(i._3);if(a==="LT")return cn(i._3,i._4,o(i._5),i._6);if(a==="GT")return cn(i._3,i._4,i._5,o(i._6));if(a==="EQ")return ee("Node",i._1,i._2,n,e(i._4)(r),i._5,i._6)}g()};return o},it=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return ee("Node",1,1,e,n,Q,Q);if(o.tag==="Node"){const i=t.compare(e)(o._3);if(i==="LT")return cn(o._3,o._4,r(o._5),o._6);if(i==="GT")return cn(o._3,o._4,o._5,r(o._6));if(i==="EQ")return ee("Node",o._1,o._2,e,n,o._5,o._6)}g()};return r},ge=t=>e=>e.foldl(n=>r=>it(t)(r._1)(r._2)(n))(Q),Li=t=>e=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node"){const o=t.compare(e)(r._3);if(o==="LT")return cn(r._3,r._4,n(r._5),r._6);if(o==="GT")return cn(r._3,r._4,r._5,n(r._6));if(o==="EQ")return ki(r._5,r._6)}g()};return n},Cf=t=>{const e=t.compare;return n=>r=>o=>{const i=bi(e,r,o),a=n(i._1);if(a.tag==="Nothing")return ki(i._2,i._3);if(a.tag==="Just")return cn(r,a._1,i._2,i._3);g()}},Ce=function(t){return function(e){return t+e|0}},_r=function(t){return function(e){return t+e}},lo=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},G2=function(t){return function(e){return t+e}},we=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},A2={append:G2},R2={append:we},D2={mempty:"",Semigroup0:()=>A2},F2={mempty:[],Semigroup0:()=>R2},ra=null;function Ln(t,e,n){return t==null?e:n(t)}function iG(t){return t}function _c(t){return function(e){return function(n){return t.apply(n,[e])}}}const I2=_c(Number.prototype.toPrecision),B2=_c(Number.prototype.toFixed),Q2=_c(Number.prototype.toExponential),Qo=(t,e)=>({tag:t,_1:e}),zo=t=>e=>n=>{const r=ut.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ut.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Mo=t=>{if(t.tag==="Precision")return I2(t._1);if(t.tag==="Fixed")return B2(t._1);if(t.tag==="Exponential")return Q2(t._1);g()},bf=function(t){return function(){console.log(t)}};function kf(t){return function(){return t.getContext("2d")}}function Lf(t){return function(){return t.width}}function Sf(t){return function(){return t.height}}function Ef(t){return function(e){return function(){t.width=e}}}function Pf(t){return function(e){return function(){t.height=e}}}function fc(t){return function(e){return function(){t.lineWidth=e}}}function z2(t){return function(e){return function(){t.fillStyle=e}}}function M2(t){return function(e){return function(){t.strokeStyle=e}}}function dc(t){return function(e){return function(){t.lineCap=e}}}function lc(t){return function(e){return function(){t.lineJoin=e}}}function O2(t){return function(e){return function(){t.globalCompositeOperation=e}}}function W2(t){return function(e){return function(){t.globalAlpha=e}}}function Gf(t){return function(){t.beginPath()}}function hc(t){return function(){t.stroke()}}function pc(t){return function(){t.fill()}}function q2(t){return function(){t.clip()}}function oa(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function Af(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function Rf(t){return function(){t.closePath()}}function H2(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function $2(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function os(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function Df(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function Y2(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function V2(t){return function(e){return function(){t.textAlign=e}}}function X2(t){return function(e){return function(){t.textBaseline=e}}}function U2(t){return function(e){return function(){t.font=e}}}function K2(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function Cr(t){return function(){t.save()}}function br(t){return function(){t.restore()}}function ia(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function Z2(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const Ff=t=>t,mc=t=>t,yc=t=>t,xc=t=>t,is=t=>t,j2=is("BaselineTop"),ty=is("BaselineMiddle"),ey=is("BaselineAlphabetic"),ny=is("BaselineBottom"),ry=xc("AlignLeft"),oy=xc("AlignRight"),iy=xc("AlignCenter"),wc=yc("BevelJoin"),Tc=yc("RoundJoin"),Nc=yc("MiterJoin"),vc=mc("Round"),Jc=mc("Square"),Cc=mc("Butt"),ay=Ff("SourceOver"),sy=Ff("Difference"),uy=t=>e=>X2(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()})()),cy=t=>e=>V2(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()})()),bc=t=>e=>{if(e==="BevelJoin")return lc(t)("bevel");if(e==="RoundJoin")return lc(t)("round");if(e==="MiterJoin")return lc(t)("miter");g()},kc=t=>e=>{if(e==="Round")return dc(t)("round");if(e==="Square")return dc(t)("square");if(e==="Butt")return dc(t)("butt");g()},If=t=>e=>O2(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()})()),Bf={foldrWithIndex:t=>e=>{const n=Ni(o=>{const i=o._1,a=o._2;return s=>t(i)(a)(s)})(e),r=Wt(bn);return o=>n(r(o))},foldlWithIndex:t=>e=>{const n=J(o=>i=>t(i._1)(o)(i._2))(e),r=Wt(bn);return o=>n(r(o))},foldMapWithIndex:t=>{const e=t.mempty;return n=>Bf.foldrWithIndex(r=>o=>i=>t.Semigroup0().append(n(r)(o))(i))(e)},Foldable0:()=>Qt},pn={foldr:t=>e=>{const n=ue.foldr(t)(e);return r=>n((()=>{const o=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return o(i._5,pt("Cons",i._3,o(i._6,a)));g()};return o(r,G)})())}},gy=t=>{const e={append:(()=>{const n=t.compare;return r=>o=>Oe(n,Qe,r,o)})()};return{mempty:Q,Semigroup0:()=>e}},aa=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},Qn=function(t){return t.join("")},zn=function(t){return t.split("")},fr=function(t){return t},dr=function(t){return t.length},Qf=function(t){return function(e){return e.substr(0,t)}},Si=function(t){return function(e){return e.substring(t)}},zf=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},_y=t=>e=>{const n=zf(dr(e)-dr(t)|0)(e);return n.after===t?N("Just",n.before):w},Zn=t=>e=>{const n=zf(dr(t))(e);return n.before===t?N("Just",n.after):w},fy=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},dy=function(t){return t()},ly=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},hy=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},Oo=t=>BigInt(t),py=t=>Number(t),as=t=>e=>t+e,ss=t=>e=>t*e,Lc=t=>e=>t-e,Mf=0n,us=1n,Of=t=>e=>t^e,sa=t=>e=>t&e,Sc=t=>e=>t<<e,Ec=t=>e=>t>>e,my=t=>e=>t==e,yy=t=>e=>t===e?0:t>e?1:-1,xy={eq:my},Wf={compare:t=>e=>{const n=yy(t)(e);return n===1?Me:n===0?un:ze},Eq0:()=>xy},wy=ly(Yt)(w),Ty=hy(Yt)(w),qf=function(t){throw new Error(t)},Hf=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=at.compare(e._1)(n._1);return r==="LT"?ze:r==="GT"?Me:at.compare(e._2)(n._2)},Eq0:()=>t}})(),Ny=t=>e=>de(t._1-e._1)+de(t._2-e._2),Wo=t=>t,cs=t=>t,Re=cs("North"),De=cs("South"),Wr=cs("East"),qr=cs("West"),ho=Wo("Rectangle"),vy=Wo("Cylinder"),Jy=Wo("Parallelogram"),Cy=Wo("Diamond"),by=Wo("Ellipse"),ky=Wo("Document"),Ly=Wo("Cloud"),$f=J(_r)(0),Sy=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},po=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},gs=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Yf=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Ey=t=>{const e={top:0,bottom:0,left:0,right:0},n=t.shape==="Cloud"?{...e,top:t.h*.38}:t.shape==="Cylinder"?{...e,bottom:5}:t.shape==="Document"?{...e,bottom:t.h*.05}:e;return[{x:t.x-n.left,y:t.y-n.top},{x:t.x+t.w+n.right,y:t.y+t.h+n.bottom}]},Ei=t=>e=>{const n=$e(a=>s=>({a,b:s,len:(()=>{const u=s.y-a.y,c=s.x-a.x;return nn(c*c+u*u)})()}),t,At(1,t.length,t)),r=$f(Y(a=>a.len)(n)),o=Sy(0)(r)(e*r),i=a=>s=>u=>{let c=a,_=s,l=u,f=!0,d;for(;f;){const h=c,m=_,p=l,x=Pt(y=>w,y=>T=>N("Just",{head:y,tail:T}),h);if(x.tag==="Nothing"){const y=t.length-1|0;if(y>=0&&y<t.length){f=!1,d=t[y];continue}f=!1,d=p;continue}if(x.tag==="Just"){if(m<=x._1.head.len){const y=x._1.head.len<=0?0:m/x._1.head.len;f=!1,d={x:x._1.head.a.x+(x._1.head.b.x-x._1.head.a.x)*y,y:x._1.head.a.y+(x._1.head.b.y-x._1.head.a.y)*y};continue}c=x._1.tail,_=m-x._1.head.len,l=p;continue}g()}return d};return 0<t.length?N("Just",i(n)(o)(t[0])):w},Py=t=>e=>{const n=po(1e-6)(t.scale);return{x:(e.x-t.tx)/n,y:(e.y-t.ty)/n,w:e.w/n,h:e.h/n}},_s=t=>$f($e(e=>n=>{const r=n.y-e.y,o=n.x-e.x;return nn(o*o+r*r)},t,At(1,t.length,t))),Pc={scale:1,tx:0,ty:0},Gy=t=>e=>{const n=po(4)(.15*gs(e.w)(e.h)),r=po(1)(t.w),o=po(1)(t.h),i=po(1)(e.w-2*n),a=po(1)(e.h-2*n),s=.55*gs(i/r)(a/o);return{scale:s,tx:e.x+n+(i-r*s)/2-t.x*s,ty:e.y+n+(a-o*s)/2+2.5-t.y*s}},ye=t=>{const e=Pt(n=>w,n=>r=>N("Just",{head:n,tail:r}),[...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,pt("Cons",r._4,n(r._6,o)));g()};return Et(Ot(ue.foldr,n(t.nodes,G)))(Ey)})(),...kn((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,pt("Cons",r._4,n(r._6,o)));g()};return Ot(ue.foldr,n(t.edges,G))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>o=>({minX:gs(r.minX)(o.x),minY:gs(r.minY)(o.y),maxX:po(r.maxX)(o.x),maxY:po(r.maxY)(o.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()},Ay=t=>e=>(n=>r=>o=>{let i=n,a=r,s=o,u=!0,c;for(;u;){const _=i,l=a,f=s,d=Pt(h=>w,h=>m=>N("Just",{head:h,tail:m}),l);if(d.tag==="Nothing"){u=!1,c=f;continue}if(d.tag==="Just"){const h=Yf(d._1.head)(_.interiors);if(h.tag==="Nothing"){u=!1,c=f;continue}if(h.tag==="Just"){i=h._1,a=d._1.tail,s=(()=>{const m=Gy(ye(h._1.layout))((()=>{const p=Yf(d._1.head)(_.layout.nodes);if(p.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:ho};if(p.tag==="Just")return p._1;g()})());return{scale:f.scale*m.scale,tx:f.scale*m.tx+f.tx,ty:f.scale*m.ty+f.ty}})();continue}}g()}return c})(t)(e)(Pc),Ry=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Dy=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},fs=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Fy=t=>e=>n=>r=>{const o=ye(e);return n<=0||r<=0||o.w<=0||o.h<=0?1:t?Ry(o.w/n)(o.h/r):Dy(o.w/n)(o.h/r)},Vf=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;if(t.widthPx<=0||t.heightPx<=0){const a=1/fs(.05)(1)(e);return{w:n.w*a,h:n.h*a}}if(r>o){const a=1/fs(.05)(1)(e);return{w:n.h*r*a,h:n.h*a}}const i=1/fs(.05)(1)(e);return{w:n.w*i,h:n.w/r*i}},Xf=t=>e=>n=>r=>o=>{const i=t+o/2,a=t+e-o/2,s=t+e/2,u=n+r/2;return o>=e?s:fs(i)(a)(u)},Uf=t=>e=>n=>r=>{const o=ye(t);return{x:Xf(o.x)(o.w)(e.x)(e.w)(n),y:Xf(o.y)(o.h)(e.y)(e.h)(r)}},ua=t=>e=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:Fy(t)(e)(n.w)(n.h)}),Iy=t=>e=>n=>r=>{const o={x:r.x-t.padding,y:r.y-t.padding,w:r.w+t.padding*2,h:r.h+t.padding*2},i=Vf(e)(.65)(o),a=Uf(n)(o)(i.w)(i.h),s={x:a.x-i.w/2,y:a.y-i.h/2,w:i.w,h:i.h};return{focus:r,paddedFocus:o,viewport:s,camera:ua(e.widthPx>0&&e.heightPx>0)(n)(s)}},By=t=>e=>n=>r=>o=>{const i={x:o.x*r.scale+r.tx,y:o.y*r.scale+r.ty,w:o.w*r.scale,h:o.h*r.scale},a=t.padding*r.scale,s={x:i.x-a,y:i.y-a,w:i.w+a*2,h:i.h+a*2},u=Vf(e)(.7)(s),c=Uf(n)(s)(u.w)(u.h),_={x:c.x-u.w/2,y:c.y-u.h/2,w:u.w,h:u.h};return{footprint:i,viewport:_,camera:ua(e.widthPx>0&&e.heightPx>0)(n)(_)}},Qy=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;return t.widthPx<=0||t.heightPx<=0?ua(t.widthPx>0&&t.heightPx>0)(e)((()=>{const i=n.w*.8,a=n.h*.8;return{x:n.x+n.w/2-i/2,y:n.y+n.h/2-a/2,w:i,h:a}})()):r>o?ua(t.widthPx>0&&t.heightPx>0)(e)((()=>{const i=n.w*.8,a=n.w/r*.8;return{x:n.x+n.w/2-i/2,y:n.y+n.h/2-a/2,w:i,h:a}})()):ua(t.widthPx>0&&t.heightPx>0)(e)((()=>{const i=n.h*r*.8,a=n.h*.8;return{x:n.x+n.w/2-i/2,y:n.y+n.h/2-a/2,w:i,h:a}})())},Kf=t=>t,zy=(t,e)=>({tag:t,_1:e}),Gc=t=>t,Pi=(t,e)=>({tag:t,_1:e}),Ac=(t,e)=>({tag:t,_1:e}),ca=Gc("Animated"),My=Gc("StaticStill"),Oy=Gc("TitleCard"),Wy=Ac("First"),Zf=Kf("Forward"),jf=Kf("Backward"),qy=Pi("ExitNode"),t1=ge(A)(Qt),Hy=t=>Ni(e=>n=>({nodes:Oe(A.compare,Qe,e.nodes,n.nodes),edges:Oe(A.compare,Qe,e.edges,n.edges)}))({nodes:Q,edges:Q})(t.keyframes),$y=t=>e=>({entering:{nodes:cr(A.compare,e.nodes,t.nodes),edges:cr(A.compare,e.edges,t.edges)},leaving:{nodes:cr(A.compare,t.nodes,e.nodes),edges:cr(A.compare,t.edges,e.edges)},surviving:{nodes:rs(A.compare,Qe,t.nodes,e.nodes),edges:rs(A.compare,Qe,t.edges,e.edges)}}),ds=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Gi=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ls=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Rc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},Yy=J(t=>e=>it(A)(e)()(t))(Q),Vy=J(t=>e=>it(A)(e)()(t))(Q),Xy=(()=>{const t=wn.unfoldr(gr);return e=>t(Tn("IterNode",e,ur))})(),e1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},n1=ge(A)(Qt),Dc=t=>{const e=Pt(n=>w,n=>r=>N("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=>o=>({minX:ds(r.minX)(o.x),minY:ds(r.minY)(o.y),maxX:Gi(r.maxX)(o.x),maxY:Gi(r.maxY)(o.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()},Uy=t=>e=>n=>Yy(Et(Ot(pn.foldr,n))(r=>{const o=ls(r)(t);if(o.tag==="Just")return lt(i=>!Rc(i)(e),[o._1.source,o._1.target]);if(o.tag==="Nothing")return[];g()})),Ky=t=>t.kind.tag==="SendToken"?N("Just",L(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):w,Zy=t=>t.tag==="DataFlow"?wt(Ky)(t._1.events):[],jy=t=>e=>Vy(wt(n=>Rc(n._2.source)(e)||Rc(n._2.target)(e)?N("Just",n._1):w)(Xy(t))),kr=t=>{const e=Pt(n=>w,n=>r=>N("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=>o=>({minX:ds(r.minX)(o.x),minY:ds(r.minY)(o.y),maxX:Gi(r.maxX)(o.x+o.w),maxY:Gi(r.maxY)(o.y+o.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()},ga=t=>e=>n=>{if(n.tag==="Leaf")return ye(t);const r=jy(e)(n),o=[...wt(i=>{const a=e1(i)(t.nodes);return a.tag==="Just"?N("Just",{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}):w})(Ot(pn.foldr,Oe(A.compare,Qe,n,Uy(e)(n)(r)))),...wt(i=>{const a=ls(i)(t.edges);return a.tag==="Just"?N("Just",Dc(a._1)):w})(Ot(pn.foldr,r))];return o.length===0?ye(t):kr(o)},hs=t=>e=>n=>{const r=[...wt(o=>o)([(()=>{const o=ls(n)(t.edges);return o.tag==="Just"?N("Just",Dc(o._1)):w})()]),...(()=>{const o=ls(n)(e);if(o.tag==="Just")return wt(i=>{const a=e1(i)(t.nodes);return a.tag==="Just"?N("Just",{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}):w})([o._1.source,o._1.target]);if(o.tag==="Nothing")return[];g()})()];return r.length===0?ga(t)(e)(Q):kr(r)},jn=t=>e=>{const n=ye(t),r=n.w/Gi(1e-4)(e.zoom),o=n.h/Gi(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-o/2,w:r,h:o}},tx=t=>Oe(A.compare,Qe,n1(Y(e=>L(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),n1(Et(t.scenes)(Zy))),Fc=t=>t,ex=t=>t,r1=Fc("Linear"),Lr=Fc("EaseInOutQuad"),nx=Fc("SpringBouncy"),_a=t=>e=>n=>{const r=nn(1-e*e),o=t*r;return 1-Ci(-e*t*n)*(hn(o*n)+e/r*en(o*n))},rx=t=>{const e=at.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=at.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},ps=t=>e=>(()=>{if(t==="Linear")return ex;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-gc(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*Ci(-6*n);if(t==="SpringBouncy")return _a(6)(.7);g()})()(rx(e)),ms=t=>t,o1=t=>t,i1=t=>t,Mn=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ys=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},xs=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ox=t=>e=>{const n=ut.compare(t._1)(e._1);return n==="LT"?ze:n==="GT"?Me:at.compare(t._2)(e._2)},ix=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ax=i1("Hold"),sx=i1("Gap"),On=o1("LinearLerp"),mo=o1("ComposedLogLerp"),Ic=ms("Overview"),fa=ms("DiveHome"),yo=ms("DiveTransition"),ws=ms("ActionFocus"),ux=t=>e=>n=>{const r=t.widthPx>0&&t.heightPx>0,o=t.widthPx/Mn(1e-6)(t.heightPx),i=ye(e),a=i.w/Mn(1e-6)(n.zoom),s=i.h/Mn(1e-6)(n.zoom),u=a/Mn(1e-6)(s),c=r&&o<u?a/o:s,_=r&&o>u?s*o:a;return{x:n.center.x-_/2,y:n.center.y-c/2,w:_,h:c}},Bc=t=>e=>n=>{const r=n.center.y-e.center.y,o=n.center.x-e.center.x,i=nn(o*o+r*r),a=n.zoom-e.zoom,s=a<0?-a:a;return ys(t.minTransition)(t.maxTransition)(Mn(t.panSpeed<=0?t.minTransition:i/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:s/t.zoomSpeed))},cx=t=>({startT:t.startT,endT:t.endT,fromCam:t.fromCam,toCam:t.toCam,easing:t.easing,interp:t.interp,intent:t.intent}),gx=J(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:St(t)(e)})([]),Ts=t=>e=>n=>{const r=ys(0)(1)((n-t)/Mn(1e-6)(e-t));return r*r*r*(r*(r*6-15)+10)},_x=t=>e=>{const n=t.x-e.x;return(n<0?-n<.001:n<.001)&&(()=>{const r=t.y-e.y;return(r<0?-r<.001:r<.001)&&(()=>{const o=t.w-e.w;return(o<0?-o<.001:o<.001)&&(()=>{const i=t.h-e.h;return i<0?-i<.001:i<.001})()})()})()},fx=t=>e=>t.tag==="Just"?e.tag==="Just"&&_x(t._1)(e._1):t.tag==="Nothing"&&e.tag==="Nothing",a1=t=>e=>n=>r=>({center:{x:r.center.x*n.scale+n.tx,y:r.center.y*n.scale+n.ty},zoom:r.zoom*ye(t).w/Mn(1e-6)(n.scale*ye(e).w)}),Qc=t=>e=>n=>r=>({center:{x:t.center.x+(e.center.x-t.center.x)*n,y:t.center.y+(e.center.y-t.center.y)*n},zoom:Ci((()=>{const o=es(Mn(1e-6)(t.zoom));return o+(es(Mn(1e-6)(e.zoom))-o)*r})())}),dx=J(t=>e=>{if(t.tag==="Nothing")return N("Just",e);if(t.tag==="Just")return e.endT>t._1.endT?N("Just",e):N("Just",t._1);g()})(w),lx=t=>e=>n=>r=>{if(t<=0)return r;const o=Ci(-t*e);return{center:{x:r.center.x+(n.center.x-r.center.x)*o,y:r.center.y+(n.center.y-r.center.y)*o},zoom:Ci((()=>{const i=es(Mn(1e-6)(r.zoom));return i+(es(Mn(1e-6)(n.zoom))-i)*o})())}},zc=t=>e=>n=>e.zoom>=t.zoom?Ts(.3)(1)(n):Ts(0)(.7)(n),hx={widthPx:0,heightPx:0},px={padding:24,easing:Lr,minimumReadableLabelPx:11,minimumVisibleLabelPx:5,labelBasePx:11,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:0},Ai=t=>e=>n=>r=>o=>{const i=ux(e)(n)(r),a=o.x-t.padding,s=o.y-t.padding;return a>=i.x&&s>=i.y&&a+o.w+t.padding*2<=i.x+i.w&&s+o.h+t.padding*2<=i.y+i.h},mx=t=>e=>n=>r=>o=>Bf.foldlWithIndex(i=>a=>s=>{const u=(()=>{if(s.kind==="Hold"){const c=(()=>{if(i===0)return s.toCam;if(s.focus.tag==="Just"){if(s.intent==="ActionFocus")return Ai(t)(e)(n)(a.prev)(s.focus._1)?a.prev:Ai(t)(e)(n)({center:a.prev.center,zoom:s.toCam.zoom})(s.focus._1)?{...s.toCam,center:a.prev.center}:{...s.toCam,center:{...s.toCam.center,x:(()=>{const _=ye(n).w/Mn(1e-6)(s.toCam.zoom);if(_<=0)return s.toCam.center.x;const l=s.focus._1.x+s.focus._1.w/2,f=e.widthPx<=0?0:xs(_/4)(6*_/e.widthPx),d=a.prev.center.x+_/2-f,h=l<a.prev.center.x-_/2+f?l-f+_/2:l>d?l+f-_/2:a.prev.center.x,m=ye(n);return _>=m.w?m.x+m.w/2:ys(m.x+_/2)(m.x+m.w-_/2)(h)})()}};if(Ai(t)(e)(n)(a.prev)(s.focus._1))return a.prev;if(Ai(t)(e)(n)({center:a.prev.center,zoom:s.toCam.zoom})(s.focus._1))return{...s.toCam,center:a.prev.center}}return s.toCam})();return{startT:s.startT,endT:s.endT,fromCam:c,toCam:c,easing:s.easing,interp:On,focus:s.focus,intent:s.intent}}if(s.kind==="Gap")return{startT:s.startT,endT:s.endT,fromCam:a.prev,toCam:(()=>{const c=i+1|0,_=Mr(Yt,w,l=>l.kind==="Hold",c<1?o:At(c,o.length,o));if(_.tag==="Just"){const l=(i+1|0)+_._1|0;return l>=0&&l<o.length?(()=>{if(o[l].focus.tag==="Just")return Ai(t)(e)(n)(a.prev)(o[l].focus._1);if(o[l].focus.tag==="Nothing")return!1;g()})()?a.prev:o[l].fromCam:a.prev}if(_.tag==="Nothing")return a.prev;g()})(),easing:s.easing,interp:On,focus:w,intent:s.intent};g()})();return{acc:St(a.acc)(u),prev:u.toCam}})({acc:[],prev:r})(o).acc,yx=t=>e=>n=>r=>o=>i=>{const a=(u,c)=>xs(Bc(t)(u.toCam)(c.toCam))(u.endT-u.startT),s=J(u=>c=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:N("Just",c)};if(u.pending.tag==="Just"){if(!(c.fromCam.zoom===c.toCam.zoom&&c.fromCam.center.x===c.toCam.center.x&&c.fromCam.center.y===c.toCam.center.y)||(()=>{if(c.focus.tag==="Just")return Ai(t)(e)(n)(u.pending._1.toCam)(c.focus._1);if(c.focus.tag==="Nothing")return!1;g()})()||(()=>{const _=u.pending._1.toCam.center.x-c.toCam.center.x;return(_<0?-_<8:_<8)&&(()=>{const l=u.pending._1.toCam.center.y-c.toCam.center.y;return(l<0?-l<8:l<8)&&(()=>{const f=u.pending._1.toCam.zoom-c.toCam.zoom;return f<0?-f<.08:f<.08})()})()})()||a(u.pending._1,c)<=0)return{acc:St(u.acc)(u.pending._1),pending:N("Just",c)};if((()=>{const _=c.startT;return ne(l=>de(l-_)<1e-4,o)})()){const _={startT:c.startT,endT:c.startT+xs(Bc(t)(u.pending._1.toCam)(c.toCam))(c.endT-c.startT),fromCam:u.pending._1.toCam,toCam:c.toCam,easing:c.easing,interp:On,focus:c.focus,intent:c.intent},l={...c,startT:_.endT,fromCam:c.toCam};return l.startT<l.endT?{acc:St(St(u.acc)(u.pending._1))(_),pending:N("Just",l)}:{acc:St(u.acc)(u.pending._1),pending:N("Just",_)}}return{acc:St(St(u.acc)({...u.pending._1,endT:c.startT-a(u.pending._1,c)}))({startT:c.startT-a(u.pending._1,c),endT:c.startT,fromCam:u.pending._1.toCam,toCam:c.toCam,easing:c.easing,interp:On,focus:c.focus,intent:c.intent}),pending:N("Just",c)}}g()})({acc:[],pending:w})(i);if(s.pending.tag==="Nothing")return s.acc;if(s.pending.tag==="Just")return St(s.acc)(s.pending._1);g()},xx=t=>e=>n=>{const r=e.w+n*2,o=e.h+n*2,i=ye(t);return r<=0||o<=0||i.w<=0||i.h<=0?1:xs(i.w/r)(i.h/o)},wx=t=>e=>n=>e.zoom>=t.zoom?Qc(t)(e)(Ts(0)(.45)(n))(zc(t)(e)(n)):Qc(t)(e)(Ts(.55)(1)(n))(zc(t)(e)(n)),Tx=t=>e=>n=>{const r=n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT),o=ps(n.easing)(ys(0)(1)(r));if(n.interp==="LinearLerp")return{center:{x:n.fromCam.center.x+(n.toCam.center.x-n.fromCam.center.x)*o,y:n.fromCam.center.y+(n.toCam.center.y-n.fromCam.center.y)*o},zoom:n.fromCam.zoom+(n.toCam.zoom-n.fromCam.zoom)*o};if(n.interp==="LogLerp")return Qc(n.fromCam)(n.toCam)(o)(o);if(n.interp==="ComposedLogLerp")return wx(n.fromCam)(n.toCam)(r);g()},Nx=t=>e=>{if(t.tag==="Just"){if(e.tag==="Just")return N("Just",kr([t._1,e._1]));if(e.tag==="Nothing")return N("Just",t._1);g()}if(t.tag==="Nothing"){if(e.tag==="Just")return N("Just",e._1);if(e.tag==="Nothing")return w}g()},vx=J(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?N("Just",t[n]):w;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&&(!(r._1.intent==="ActionFocus"||e.intent==="ActionFocus")||(r._1.intent==="Overview"?e.intent==="Overview":r._1.intent==="DiveHome"?e.intent==="DiveHome":r._1.intent==="DiveTransition"?e.intent==="DiveTransition":r._1.intent==="ActionFocus"&&e.intent==="ActionFocus")&&fx(r._1.focus)(e.focus))&&(()=>{const o=r._1.toCam.center.x-e.toCam.center.x;return(o<0?-o<8:o<8)&&(()=>{const i=r._1.toCam.center.y-e.toCam.center.y;return(i<0?-i<8:i<8)&&(()=>{const a=r._1.toCam.zoom-e.toCam.zoom;return a<0?-a<.08:a<.08})()})()})()?St((()=>{const o=t.length-1|0;return o<1?[]:At(0,o,t)})())({...r._1,endT:e.endT,focus:Nx(r._1.focus)(e.focus)}):St(t)(e)})([]),Jx=t=>{const e=Rt(n=>r=>ox(L((()=>{if(r.intent==="DiveTransition")return 3;if(r.intent==="ActionFocus")return 2;if(r.intent==="DiveHome")return 1;if(r.intent==="Overview")return 0;g()})(),r.startT))(L((()=>{if(n.intent==="DiveTransition")return 3;if(n.intent==="ActionFocus")return 2;if(n.intent==="DiveHome")return 1;if(n.intent==="Overview")return 0;g()})(),n.startT)))(t);return 0<e.length?N("Just",e[0]):w},Mc=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:Mn(r)(xx(e)(n)(t.padding))}),Cx=t=>e=>n=>r=>o=>i=>{const a=Mc(t)(n)(ye(n))(0),s=lt(c=>c>=0&&c<=r,gx(Rt(at.compare)([0,r,...o,...Et(i)(c=>[c.startT,c.endT])]))),u=(c,_)=>ne(l=>l.priority>=1,lt(l=>l.startT<=_&&_<l.endT,i))?Iy(t)(e)(n)(kr(c)).camera:Mc(t)(n)(kr(c))(0);return Y(cx)(yx(t)(e)(n)(a)(o)(vx(mx(t)(e)(n)(a)(wt(c=>{const _=(c._1+c._2)/2;if(c._2<=c._1)return w;const l=Y(f=>f.bbox)(lt(f=>f.priority===J(ix)(0)(Y(d=>d.priority)(lt(d=>d.startT<=_&&_<d.endT,i))),lt(f=>f.startT<=_&&_<f.endT,i)));return l.length===0?N("Just",{kind:sx,startT:c._1,endT:c._2,fromCam:a,toCam:a,easing:t.easing,focus:w,intent:Ic}):N("Just",{kind:ax,startT:c._1,endT:c._2,fromCam:u(l,_),toCam:u(l,_),easing:t.easing,focus:N("Just",kr(l)),intent:ne(f=>f.priority>=1,lt(f=>f.startT<=_&&_<f.endT,i))?ws:Ic})})($e(bn,s,At(1,s.length,s)))))))},qo=t=>e=>n=>r=>{const o=Jx(lt(i=>r>=i.startT&&r<i.endT,n));if(o.tag==="Just")return{camera:Tx()(r)(o._1),intent:o._1.intent};if(o.tag==="Nothing"){const i=dx(n);return i.tag==="Just"&&r>=i._1.endT?{camera:i._1.toCam,intent:i._1.intent}:{camera:(()=>{const a=Mc(t)(e)(ye(e))(0);return 0<n.length?n[0].fromCam:a})(),intent:0<n.length?n[0].intent:Ic}}g()};function xo(t){return t.charCodeAt(0)}function s1(t){return String.fromCharCode(t)}const tr=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},Ho=function(t){return function(e){return e.split(t)}},da=function(t){return t.trim()},Wn=function(t){return function(e){return e.join(t)}};var bx=typeof Array.from=="function",kx=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",Lx=typeof String.prototype.fromCodePoint=="function",Sx=typeof String.prototype.codePointAt=="function";const Ex=function(t){return Sx?function(e){return e.codePointAt(0)}:t},Px=function(t){return Lx?String.fromCodePoint:t},Gx=function(t){return function(e){return kx?function(n){for(var r="",o=n[Symbol.iterator](),i=0;i<e;++i){var a=o.next();if(a.done)return r;r+=a.value}return r}:t(e)}},Ax=function(t){return function(e){return bx?function(n){return Array.from(n,e)}:t}},Ns=t=>{const e=dr(t);if(e===0)return w;if(e===1)return N("Just",{head:xo(aa(0)(t)),tail:""});const n=xo(aa(1)(t)),r=xo(aa(0)(t));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?N("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:Si(2)(t)}):N("Just",{head:r,tail:Si(1)(t)})},Rx=t=>{const e=Ns(t);return e.tag==="Just"?N("Just",L(e._1.head,e._1.tail)):w},Dx=t=>wn.unfoldr(Rx)(t),u1=Ex(t=>{const e=xo(aa(0)(t));if(55296<=e&&e<=56319&&dr(t)>1){const n=xo(aa(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),gn=Ax(Dx)(u1),c1=t=>gn(t).length,Oc=t=>fr(t>=0&&t<=65535?s1(t):t<0?"\0":"\uFFFF"),Fx=Px(t=>t<=65535?Oc(t):Oc(Nr(t-65536|0,1024)+55296|0)+Oc(lo(t-65536|0)(1024)+56320|0)),g1=t=>e=>{if(t<1)return"";const n=Ns(e);return n.tag==="Just"?Fx(n._1.head)+g1(t-1|0)(n._1.tail):e},Fe=Gx(g1),Ix=t=>e=>e===""?w:N("Just",u1(e)),Bx=t=>t,_1=t=>e=>{const n=e.vw/e.vh,r=e.vh*t,o={...e,vx:e.vx-(r-e.vw)/2,vw:r},i=e.vw/t,a={...e,vy:e.vy-(i-e.vh)/2,vh:i};return t<=0||e.vw<=0||e.vh<=0?e:t>n?o:t<n?a:e},f1=t=>e=>t.width<=0||t.height<=0?e:_1(t.width/t.height)(e),Qx=t=>e=>{if(e.scene.tag==="Structural")return e.scene._1.to;if(e.scene.tag==="DataFlow")return e.scene._1.keyframe;if(e.scene.tag==="Hold")return e.scene._1;if(e.scene.tag==="EnterNode"||e.scene.tag==="ExitNode"||e.scene.tag==="StepScene")return t;g()},d1=t=>t,vs=(t,e)=>({tag:t,_1:e}),er=(t,e,n)=>({tag:t,_1:e,_2:n}),l1=t=>t,$o=(t,e,n,r,o,i,a,s,u)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:a,_7:s,_8:u}),Wc=l1("PlopIn"),zx=l1("PlopOut"),Mx=d1("DiveIn"),Ox=d1("DiveOut"),Te=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},rn=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},h1=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},p1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Yo=sc(ta),m1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Wx=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},y1=(()=>{const t=wn.unfoldr(gr);return e=>t(Tn("IterNode",e,ur))})(),qx=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},lr=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Js=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Hx=t=>t,x1=t=>e=>n=>n<t?0:n>1-e?1:(n-t)/Te(.05)(1-t-e),$x=t=>e=>t.labelBasePx*.62*nt(J(h1)(0)(Y(c1)(Et(e)(n=>Ho(`
3
+ `)(n))))),w1=t=>e=>{if(t.length===0)return e;const n=6.82*nt(J(h1)(0)(Y(c1)(Et(t)(_=>Ho(`
4
+ `)(_))))),r=n/2+14,o=e.y+e.h/2,i=o-5-8,a=Te(e.y+e.h)(i+12.6)-rn(e.y)(i-12.6),s=e.x+e.w/2,u=s+13+n/2,c=Te(e.x+e.w)(u+r)-rn(e.x)(u-r);return{x:s-c/2,y:o-a/2,w:c,h:a}},qc=(()=>{const t=J(e=>n=>{const r=e.previous.tag==="Just"&&de(e.previous._1.endT-n.startT)<1e-4?{...n,fromCam:e.previous._1.toCam}:n;return{previous:N("Just",r),spans:St(e.spans)(r)}})({previous:w,spans:[]});return e=>t(e).spans})(),T1=t=>e=>n=>{const r=(t+e)/2,o=n-r,i=o<0?-1:1,a=(e-t)/2,s=a*.15,u=a-s,c=o<0?-o:o;return e<=t?(t+e)/2:c<=u?n:r+i*(a-s*Ci(-(c-u)/s))},Hc=t=>e=>{const n=p1(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.nodes;g()},N1=t=>e=>{if(e<t.startT)return er("AtKeyframe",t.initialKeyframe);const n=te(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return er("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return er("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return er("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode"||n._1.scene.tag==="StepScene")return er("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing")return er("AtKeyframe",J(Qx)(t.initialKeyframe)(t.spans));g()},Cs=t=>e=>n=>r=>{const o=te(i=>Yo(i.path)(e)&&(de(i.endT-n)<1e-4||de(i.startT-r)<1e-4))(t.segments);if(o.tag==="Just")return N("Just",o._1);if(o.tag==="Nothing")return te(i=>Yo(i.path)(e))(t.segments);g()},$c=t=>e=>{const n=p1(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.edges;g()},v1=(()=>{const t=(n,r,o,i,a)=>{let s=n,u=r,c=o,_=i,l=a,f=!0,d;for(;f;){if(s===0){const h=Pt(m=>w,m=>p=>N("Just",{head:m,tail:p}),u);if(h.tag==="Nothing"){f=!1,d=[];continue}if(h.tag==="Just"){s=1,u=h._1.head,c=h._1.head,_=!1,l=h._1.tail;continue}g()}if(s===1){const h=u,m=c,p=_,x=l,y=Pt(T=>w,T=>v=>N("Just",{head:T,tail:v}),x);if(y.tag==="Just"&&m.intent==="Overview"&&y._1.head.intent==="Overview"&&!(m.fromCam.zoom===m.toCam.zoom&&m.fromCam.center.x===m.toCam.center.x&&m.fromCam.center.y===m.toCam.center.y)&&!(y._1.head.fromCam.zoom===y._1.head.toCam.zoom&&y._1.head.fromCam.center.x===y._1.head.toCam.center.x&&y._1.head.fromCam.center.y===y._1.head.toCam.center.y)&&de(m.toCam.center.x-y._1.head.fromCam.center.x)<1e-4&&de(m.toCam.center.y-y._1.head.fromCam.center.y)<1e-4&&de(m.toCam.zoom-y._1.head.fromCam.zoom)<1e-4&&de(m.endT-y._1.head.startT)<1e-4){s=1,u=h,c=y._1.head,_=!0,l=y._1.tail;continue}f=!1,d=[p?{...h,endT:m.endT,toCam:m.toCam,easing:m.easing,interp:On}:h,...e(x)]}}return d},e=n=>t(0,n);return e})(),Yx=t=>e=>{const n=ye(e),r=f1({width:t.widthPx,height:t.heightPx})({vx:n.x,vy:n.y,vw:n.w,vh:n.h});return{w:r.vw,h:r.vh}},Yc=t=>e=>n=>r=>{const o=Te(n.center.x-r.x)(r.x+r.w-n.center.x),i=Te(n.center.y-r.y)(r.y+r.h-n.center.y),a=Yx(t)(e);return rn(o<=0?n.zoom:a.w/(o*2))(i<=0?n.zoom:a.h/(i*2))},J1=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r,u=Or(s);if(u.tag==="Just"&&u._1.last.intent==="Overview"){n=[u._1.last,...a],r=u._1.init;continue}o=!1,i={prefix:s,overview:a}}return i},Vx=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r,u=Pt(c=>w,c=>_=>N("Just",{head:c,tail:_}),s);if(u.tag==="Just"&&u._1.head.intent==="Overview"){n=St(a)(u._1.head),r=u._1.tail;continue}o=!1,i={overview:a,rest:s}}return i},Vo=t=>e=>n=>r=>o=>{const i={width:e.widthPx,height:e.heightPx},a=f1(i)((()=>{const s=jn(n)(o);return{vx:s.x,vy:s.y,vw:s.w,vh:s.h}})());return t.labelBasePx*r.placement.scale*(i.width<=0||a.vw<=0?0:i.width/a.vw)},Xx=t=>e=>n=>r=>o=>{const i=Vo(t)(e)(n)(r)(o);return i<=t.minimumReadableLabelPx?o:{...o,zoom:o.zoom*t.minimumReadableLabelPx/i}},Ux=t=>e=>n=>{const r=wt(o=>o.scene.tag==="StepScene"?N("Just",o.startT):w)(e.spans);return J(o=>i=>{const a=Mr(Yt,w,s=>s.startT<i+1e-4&&s.endT>=i-1e-4,o);if(a.tag==="Nothing")return o;if(a.tag==="Just"){const s=a._1>=0&&a._1<o.length?N("Just",o[a._1]):w;if(s.tag==="Nothing")return o;if(s.tag==="Just"){if(s._1.startT>=i-1e-4)return o;const u=te(m=>m>i+1e-4)(r),c=(()=>{if(u.tag==="Nothing")return e.endT;if(u.tag==="Just")return u._1;g()})(),_=Rt(at.compare)(wt(m=>m.startT>=i-1e-4&&m.startT<c-1e-4&&(m.target.tag==="RelabelWindow"||(m.target.tag==="EdgeWindow"?m.target._2.tag==="Extend":m.target.tag==="TokenWindow"||m.target.tag==="FillWindow"))?N("Just",m.startT):w)(e.windows)),l=0<_.length?_[0]:i,f=a._1+1|0,d=f<1?o:At(f,o.length,o),h=Mr(Yt,w,m=>m.intent==="ActionFocus"&&m.startT>=l-1e-4&&m.startT<c-1e-4,d);if(h.tag==="Nothing")return o;if(h.tag==="Just"){const m=h._1>=0&&h._1<d.length?N("Just",d[h._1]):w;if(m.tag==="Nothing")return o;if(m.tag==="Just"){const p=(a._1+h._1|0)+2|0,x=p<1?o:At(p,o.length,o),y=s._1.toCam.zoom===m._1.toCam.zoom&&s._1.toCam.center.x===m._1.toCam.center.x&&s._1.toCam.center.y===m._1.toCam.center.y?s._1.fromCam:s._1.toCam,T=St(a._1<1?[]:At(0,a._1,o))({...s._1,endT:i,toCam:y}),v=m._1.startT-i;if(v<=1e-4)return[...T,{...m._1,fromCam:y},...x];const b=y.zoom===m._1.toCam.zoom&&y.center.x===m._1.toCam.center.x&&y.center.y===m._1.toCam.center.y,C=b?i+0:i+rn(v)(Bc(t)(y)(m._1.toCam)),S={...m._1,startT:C,endT:m._1.startT,fromCam:m._1.toCam,toCam:m._1.toCam},P={...m._1,startT:i,endT:C,fromCam:y};return[...T,...b?[]:[P],...S.endT>S.startT+1e-4?[S]:[],{...m._1,fromCam:m._1.toCam},...x]}}}}g()})(n)(r)},Kx=t=>e=>n=>r=>({...r,fromCam:a1(t)(e)(n)(r.fromCam),toCam:a1(t)(e)(n)(r.toCam)}),C1=t=>e=>t.widthPx<=0?0:rn(e/4)(32*e/t.widthPx),Zx=t=>e=>n=>r=>o=>{const i=C1(e)(n),a=r+n/2-i;return o.x<r-n/2+i?o.x-i+n/2:o.x+o.w>a?o.x+o.w+i-n/2:r},jx=t=>e=>n=>ne(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),tw=t=>e=>n=>ne(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),ew=t=>e=>n=>ne(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),nw=t=>e=>n=>ne(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),bs=t=>e=>n=>ne(r=>n(r)&&e>=r.startT&&e<r.endT,t),rw=t=>e=>n=>{if(e.length===0)return n;const r=rn(160)($x(t)(e)+31)/2,o=rn(40)(t.labelBasePx*1.2+23);return{x:n.x-r,y:n.y-o,w:n.w+r*2,h:n.h+o*2}},ow=t=>e=>n=>{const r=t.padding*.75,o=nt(8);return Za(i=>{if(i.target.tag==="NodeWindow")return[];if(i.target.tag==="RelabelWindow")return[{startT:i.startT,endT:i.endT,bbox:ga(e)(n)(ee("Node",1,1,i.target._1,void 0,Q,Q)),priority:1}];if(i.target.tag==="EdgeWindow"){if(i.target._2.tag==="Extend")return[{startT:i.startT,endT:i.endT,bbox:hs(e)(n)(i.target._1),priority:1}];if(i.target._2.tag==="Retract")return[];g()}if(i.target.tag==="TokenWindow"){const a=m1(i.target._2)(e.edges);if(a.tag==="Just"){const s=(()=>{if(i.target._3==="Forward")return a._1;if(i.target._3==="Backward")return re(a._1);g()})();return Et(Ut(0,7))(u=>{const c=i.startT+(i.endT-i.startT)*(nt(u)/o),_=(()=>{const l=i.startT+(i.endT-i.startT)*(nt(u+1|0)/o);return{startT:c,endT:l,box:(()=>{const f=Ei(s)(x1(i.target._7)(i.target._8)(((c+l)/2-i.startT)/Te(1e-4)(i.endT-i.startT)));if(f.tag==="Just")return{x:f._1.x-r,y:f._1.y-r,w:0+r*2,h:0+r*2};if(f.tag==="Nothing")return{x:0,y:0,w:0,h:0};g()})()}})();return[{startT:_.startT,endT:_.endT,bbox:w1(i.target._6)(_.box),priority:1}]})}if(a.tag==="Nothing")return[{startT:i.startT,endT:i.endT,bbox:w1(i.target._6)(hs(e)(n)(i.target._2)),priority:1}];g()}if(i.target.tag==="FillWindow")return[{startT:i.startT,endT:i.endT,bbox:rw(t)(i.target._3)(ga(e)(n)(ee("Node",1,1,i.target._2,void 0,Q,Q))),priority:1}];g()})},iw=t=>e=>n=>r=>o=>i=>{if(o.tag==="Nothing")return i.zoom;if(o.tag==="Just")return Te(0)(Yc(e)(n)(i)((()=>{const a=t.padding*r.placement.scale;return{x:o._1.x-a,y:o._1.y-a,w:o._1.w+a*2,h:o._1.h+a*2}})()));g()},aw=t=>e=>{const n=N1(t)(e);if(n.tag==="AtKeyframe")return Hc(t)(n._1);if(n.tag==="InTransition")return Oe(A.compare,Qe,Hc(t)(n._1),Hc(t)(n._2));g()},sw=t=>e=>n=>bs(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n&&r.target._2==="PlopOut")?!0:tw(t.windows)(e)(n)?!1:bs(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n)?!0:ew(t.windows)(e)(n)?!1:Wx(n)(aw(t)(e)),b1=t=>e=>wt(n=>sw(t)(e)(n._1)?N("Just",{x:n._2.x,y:n._2.y,w:n._2.w,h:n._2.h}):w)(y1(t.layout.nodes)),uw=t=>e=>{const n=b1(t)(e);return n.length===0?w:N("Just",kr(n))},cw=t=>wt(e=>{const n=uw(t)(Te(e.startT)(e.endT-1e-4));if(n.tag==="Nothing")return w;if(n.tag==="Just")return N("Just",{startT:e.startT,endT:e.endT,bbox:n._1,priority:0});g()}),gw=t=>e=>n=>r=>o=>[...cw(o)(lt(i=>i.startT>=o.startT&&i.endT<=o.endT,r.spans)),...ow(t)(o.layout)(n)(o.windows)],_w=t=>e=>n=>r=>o=>i=>Cx(t)(e)(i.layout)(o.endT)(wt(a=>a.scene.tag==="StepScene"?N("Just",a.startT):w)(i.spans))(gw(t)(n)(r)(o)(i)),fw=t=>e=>{const n=N1(t)(e);if(n.tag==="AtKeyframe")return $c(t)(n._1);if(n.tag==="InTransition")return Oe(A.compare,Qe,$c(t)(n._1),$c(t)(n._2));g()},dw=t=>e=>n=>bs(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n)?!0:jx(t.windows)(e)(n)?!1:bs(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._1===n)?!0:nw(t.windows)(e)(n)?!1:qx(n)(fw(t)(e)),lw=t=>e=>{const n=[...b1(t)(e),...wt(r=>dw(t)(e)(r._1)?N("Just",Dc(r._2)):w)(y1(t.layout.edges))];return n.length===0?w:N("Just",kr(n))},hw=t=>e=>n=>{const r=jn(t)(n);return e.x>=r.x&&e.x+e.w<=r.x+r.w},k1=t=>e=>n=>r=>n>=e?lr(t+e-n/2)(t+n/2)(r):t+e/2,L1=t=>e=>n=>r=>{if((()=>{const a=jn(e)(n);return r.x>=a.x&&r.y>=a.y&&r.x+r.w<=a.x+a.w&&r.y+r.h<=a.y+a.h})())return n;const o={...n,zoom:rn(n.zoom)(Yc(t)(e)({...n,center:{x:r.x+r.w/2,y:r.y+r.h/2}})(r))},i=jn(e)(o);return{...o,center:{x:k1(r.x)(r.w)(i.w)(n.center.x),y:k1(r.y)(r.h)(i.h)(n.center.y)}}},S1=t=>e=>n=>r=>o=>i=>a=>{if(o.tag==="Nothing")return a;if(o.tag==="Just"){const s=t.padding*r.placement.scale,u={x:o._1.x-s,y:o._1.y-s,w:o._1.w+s*2,h:o._1.h+s*2},c={x:u.x+u.w/2,y:u.y+u.h/2},_={...a,center:c},l={..._,zoom:Yc(e)(n)(_)(u)},f=jn(n)(l);return i.tag==="Nothing"?{...l,center:{x:f.w>=o._1.w?o._1.x+o._1.w/2:lr(o._1.x+f.w/2)(o._1.x+o._1.w-f.w/2)(c.x),y:f.h>=o._1.h?o._1.y+o._1.h/2:lr(o._1.y+f.h/2)(o._1.y+o._1.h-f.h/2)(c.y)}}:i.tag==="Just"?{...l,center:{x:f.w>=o._1.w?o._1.x+o._1.w/2:lr(o._1.x+f.w/2)(o._1.x+o._1.w-f.w/2)(i._1.x+i._1.w/2),y:f.h>=o._1.h?o._1.y+o._1.h/2:lr(o._1.y+f.h/2)(o._1.y+o._1.h-f.h/2)(i._1.y+i._1.h/2)}}:{...l,center:{x:(()=>{if(f.w>=o._1.w)return o._1.x+o._1.w/2;g()})(),y:(()=>{if(f.h>=o._1.h)return o._1.y+o._1.h/2;g()})()}}}g()},E1=t=>e=>n=>{const r=t.x+t.w/2,o=n>=t.w?{lo:r,hi:r}:{lo:t.x+n/2,hi:t.x+t.w-n/2};if(n>=e.w){const u=Te(o.lo)(e.x+e.w-n/2),c=rn(o.hi)(e.x+n/2);return u<=c?{lo:u,hi:c}:o}const i=e.x+e.w/2;if(n>=e.w){const u=Te(o.lo)(i),c=rn(o.hi)(i);return u<=c?{lo:u,hi:c}:o}const a=Te(o.lo)(e.x+n/2),s=rn(o.hi)(e.x+e.w-n/2);return a<=s?{lo:a,hi:s}:o},pw=t=>e=>n=>n.endT<=t||n.startT>=e?w:N("Just",{...n,startT:Te(t)(n.startT),endT:rn(e)(n.endT)}),mw=t=>e=>n=>r=>o=>i=>wt(pw(i.startT)(i.endT))(Y(Kx(n)(i.layout)(i.placement))(_w(t)(e)(r)(i.edgeEndpoints)(o)(i))),P1=t=>e=>n=>r=>{const o=ye(t),i=rn(r.zoom)(o.w/Te(1e-4)(e.w));return{...r,center:{...r.center,x:(()=>{const a=E1(o)(e)(o.w/Te(1e-4)(i));return lr(a.lo)(a.hi)(n.center.x)})()},zoom:i}},yw=t=>e=>n=>r=>o=>i=>a=>s=>{const u=C1(e)(s),c=ye(n),_={x:c.x-u,y:c.y-u,w:c.w+u*2,h:c.h+u*2},l=(()=>{if(o.tag==="Nothing")return a.center.x;if(o.tag==="Just")return Zx()(e)(s)(i.center.x)(o._1);g()})();if(r.tag==="Nothing"){const f=_.x+_.w/2;return s>=_.w?lr(f)(f)(l):lr(_.x+s/2)(_.x+_.w-s/2)(l)}if(r.tag==="Just"){const f={x:r._1.x-u,y:r._1.y-u,w:r._1.w+u*2,h:r._1.h+u*2};if(s<f.w){const h=_.x+_.w/2;return s>=_.w?lr(h)(h)(l):lr(_.x+s/2)(_.x+_.w-s/2)(l)}const d=E1(_)(f)(s);return lr(d.lo)(d.hi)(l)}g()},xw=t=>e=>n=>r=>o=>i=>a=>{const s=jn(n)(a);return s.w<=0?a:{...a,center:{...a.center,x:yw()(e)(n)(r)(o)(i)(a)(s.w)}}},ww=t=>e=>n=>{const r=ye(t),o=r.h/Te(1e-4)(n.zoom),i=r.w/Te(1e-4)(n.zoom);return{...n,center:{x:i>=e.w?e.x+e.w/2:T1(e.x+i/2)(e.x+e.w-i/2)(n.center.x),y:o>=e.h?e.y+e.h/2:T1(e.y+o/2)(e.y+e.h-o/2)(n.center.y)}}},Xo=t=>e=>n=>ww(t)((()=>{const r=e*n.placement.scale,o=ye(n.layout);return{x:o.x*n.placement.scale+n.placement.tx-r,y:o.y*n.placement.scale+n.placement.ty-r,w:o.w*n.placement.scale+r*2,h:o.h*n.placement.scale+r*2}})()),Tw=t=>e=>n=>r=>{const o=jn(t)(r),i=ye(t),a=s=>{const u=Xo(t)(e)(n)(s);return Xo(t)(e)(n)({...u,zoom:Te(u.zoom)(Te(i.w/Te(1e-4)(2*rn(u.center.x-o.x)(o.x+o.w-u.center.x)))(i.h/Te(1e-4)(2*rn(u.center.y-o.y)(o.y+o.h-u.center.y))))})};return s=>a(a(s))},Nw=t=>e=>n=>r=>Xo(n)(t.padding)(r)(By(t)(e)(n)(r.placement)(ye(r.layout)).camera),G1=t=>e=>n=>r=>o=>{const i=Nw(t)(e)(n)(o),a=te(s=>s.direction==="DiveIn"&&Yo(s.childPath)(o.path))(r.dives);if(a.tag==="Just"){const s=Cs(r)(a._1.parentPath)(a._1.startT)(a._1.endT);if(s.tag==="Just"){const u=Js(a._1.node)(s._1.layout.nodes);if(u.tag==="Just"){const c=u._1.w*s._1.placement.scale,_=u._1.h*s._1.placement.scale,l=rn(c)(_*2),f=Qy(e)(n)({h:_,w:l,x:u._1.x*s._1.placement.scale+s._1.placement.tx+(c-l)*.5,y:u._1.y*s._1.placement.scale+s._1.placement.ty});return Tw(n)(t.padding)(o)(f)(f.zoom>i.zoom?f:i)}if(u.tag==="Nothing")return i;g()}if(s.tag==="Nothing")return i;g()}if(a.tag==="Nothing")return i;g()},A1=t=>e=>n=>r=>o=>{const i=jn(n)(o);return(()=>{const a=ye(r.layout),s=a.x*r.placement.scale+r.placement.tx,u=a.y*r.placement.scale+r.placement.ty;return s>=i.x&&u>=i.y&&s+a.w*r.placement.scale<=i.x+i.w&&u+a.h*r.placement.scale<=i.y+i.h})()&&Vo(t)(e)(n)(r)(o)>=t.minimumReadableLabelPx},R1=t=>e=>n=>r=>o=>i=>A1(t)(e)(n)(r)(o)?o:Xx(t)(e)(n)(r)(i),vw=t=>e=>n=>{const r=Vx([])(n),o=Pt(u=>w,u=>c=>N("Just",{head:u,tail:c}),r.rest),i=r.overview.length-1|0,a=i>=0&&i<r.overview.length?N("Just",r.overview[i]):w,s=0<r.overview.length?N("Just",r.overview[0]):w;if(s.tag==="Just"){if(a.tag==="Just"){if(o.tag==="Just")return de(s._1.startT-e.startT)<1e-4&&o._1.head.intent==="ActionFocus"?[{startT:s._1.startT,endT:a._1.endT,fromCam:t,toCam:t,easing:s._1.easing,interp:On,intent:fa},{...o._1.head,fromCam:t},...o._1.tail]:n;if(o.tag==="Nothing"&&de(s._1.startT-e.startT)<1e-4)return[{startT:s._1.startT,endT:a._1.endT,fromCam:t,toCam:t,easing:s._1.easing,interp:On,intent:fa}]}return n}if(s.tag==="Nothing"&&a.tag==="Nothing"&&o.tag==="Just"&&de(o._1.head.startT-e.startT)<1e-4&&o._1.head.intent==="ActionFocus"){const u=Pt(c=>w,c=>_=>N("Just",{head:c,tail:_}),o._1.tail);if(u.tag==="Nothing")return[{startT:o._1.head.startT,endT:o._1.head.endT,fromCam:t,toCam:t,easing:o._1.head.easing,interp:On,intent:fa}];if(u.tag==="Just")return[{startT:o._1.head.startT,endT:o._1.head.endT,fromCam:t,toCam:t,easing:o._1.head.easing,interp:On,intent:fa},{...u._1.head,fromCam:t},...u._1.tail];g()}return n},Jw=t=>e=>{const n=Pt(r=>w,r=>o=>N("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{...n._1.head,fromCam:t},...n._1.tail];g()},Cw=t=>e=>{const n=o=>i=>a=>{let s=o,u=i,c=a,_=!0,l;for(;_;){const f=s,d=u,h=Pt(m=>w,m=>p=>N("Just",{head:m,tail:p}),c);if(h.tag==="Nothing"){_=!1,l=St(f)(d);continue}if(h.tag==="Just"){if(d.intent==="Overview"&&h._1.head.intent==="ActionFocus"&&de(d.endT-h._1.head.startT)<1e-4&&d.fromCam.zoom===d.toCam.zoom&&d.fromCam.center.x===d.toCam.center.x&&d.fromCam.center.y===d.toCam.center.y&&(()=>{const m=h._1.head.startT;return!(h._1.head.fromCam.zoom===h._1.head.toCam.zoom&&h._1.head.fromCam.center.x===h._1.head.toCam.center.x&&h._1.head.fromCam.center.y===h._1.head.toCam.center.y)&&ne(p=>de(p.startT-m)<1e-4&&(p.target.tag==="RelabelWindow"?!0:p.target.tag==="EdgeWindow"?p.target._2.tag==="Extend":p.target.tag==="TokenWindow"||p.target.tag==="FillWindow"),t.windows)})()){const m=h._1.head.startT,p=Rt(at.compare)(wt(v=>v.target.tag==="EdgeWindow"&&v.target._2.tag==="Extend"&&de(v.endT-m)<1e-4?N("Just",v.startT):w)(t.windows)),x=0<p.length?p[0]:m,y=Te(d.startT)(x-(h._1.head.endT-h._1.head.startT)),T={...d,endT:y};s=St(T.endT>T.startT?St(f)(T):f)({...h._1.head,startT:y,endT:x}),u={...h._1.head,startT:x,fromCam:h._1.head.toCam},c=h._1.tail;continue}s=St(f)(d),u=h._1.head,c=h._1.tail;continue}g()}return l},r=Pt(o=>w,o=>i=>N("Just",{head:o,tail:i}),e);if(r.tag==="Nothing")return[];if(r.tag==="Just")return n([])(r._1.head)(r._1.tail);g()},bw=t=>e=>n=>r=>o=>i=>{const a=ye(r.layout),s={x:a.x*r.placement.scale+r.placement.tx,y:a.y*r.placement.scale+r.placement.ty,w:a.w*r.placement.scale,h:a.h*r.placement.scale},u=P1(n)(s)(o)(i);return s.w/Te(1e-4)(s.h)>=.33&&i.zoom/Te(1e-4)(u.zoom)<=1.25&&jn(n)(u).w>=s.w-.001&&Vo(t)(e)(n)(r)(u)>=t.minimumReadableLabelPx*.85?u:i},kw=t=>e=>n=>r=>o=>i=>a=>{const s=ye(r.layout),u=s.w*r.placement.scale,c=u/Te(1e-4)(s.h*r.placement.scale);if(o.tag==="Nothing")return a;if(o.tag==="Just"){if(hw(n)(o._1)(a))return a;const _=P1(n)(o._1)(i)(a);return a.zoom/Te(1e-4)(_.zoom)<=1.25&&(Vo(t)(e)(n)(r)(_)>=t.minimumReadableLabelPx-.001||o._1.w>=u-.001&&c>=.33&&Vo(t)(e)(n)(r)(_)>=t.minimumReadableLabelPx*.85)?_:a}g()},Lw=t=>e=>n=>r=>o=>i=>a=>{const s={...a,center:(()=>{if(i.tag==="Nothing")return a.center;if(i.tag==="Just")return{x:i._1.x+i._1.w/2,y:i._1.y+i._1.h/2};g()})()},u=Vo(t)(e)(n)(r)(s);return xw()(e)(n)(o)(i)(a)(kw(t)(e)(n)(r)(o)(a)(bw(t)(e)(n)(r)(a)(u<=0?s:{...s,zoom:rn(s.zoom*t.minimumReadableLabelPx/u)(iw(t)(e)(n)(r)(i)(s))})))},Vc=t=>e=>n=>r=>o=>i=>a=>r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?S1(t)(e)(n)(r)(o)(i)(a):A1(t)(e)(n)(r)(a)?a:Lw(t)(e)(n)(r)(o)(i)(a),D1=t=>{const e=n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=i,_=Pt(l=>w,l=>f=>N("Just",{head:l,tail:f}),c);if(_.tag==="Just"&&_._1.head.intent==="Overview"){o=St(u)(_._1.head),i=_._1.tail;continue}a=!1,s={overview:u,rest:c}}return s};return(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=Pt(_=>w,_=>l=>N("Just",{head:_,tail:l}),i);if(c.tag==="Nothing"){a=!1,s=u;continue}if(c.tag==="Just"){if(c._1.head.intent==="Overview"){const _=e([c._1.head])(c._1.tail),l=Pt(h=>w,h=>m=>N("Just",{head:h,tail:m}),_.rest),f=u.length-1|0,d=f>=0&&f<u.length?N("Just",u[f]):w;if(d.tag==="Just"&&l.tag==="Just"&&d._1.intent==="ActionFocus"&&(()=>{const h=_.overview.length-1|0;return l._1.head.intent==="ActionFocus"&&(h>=0&&h<_.overview.length&&0<_.overview.length?_.overview[h].endT-_.overview[0].startT<=1.0001:!0)})()&&0<_.overview.length){const h=_.overview.length-1|0;if(h>=0&&h<_.overview.length){o=St(u)({startT:_.overview[0].startT,endT:_.overview[h].endT,fromCam:d._1.toCam,toCam:d._1.toCam,easing:_.overview[0].easing,interp:On,intent:ws}),i=[{...l._1.head,fromCam:d._1.toCam},...l._1.tail];continue}}o=[...u,..._.overview],i=_.rest;continue}o=St(u)(c._1.head),i=c._1.tail;continue}g()}return s})([])(t)},Sw=t=>e=>n=>{const r=J1([])(n),o=r.overview.length-1|0;if(o>=0&&o<r.overview.length){if(0<r.overview.length){const i=r.prefix.length-1|0;if(i>=0&&i<r.prefix.length&&r.prefix[i].intent==="ActionFocus"&&de(r.overview[o].endT-e.endT)<1e-4)return[...r.prefix,{startT:r.overview[0].startT,endT:r.overview[o].endT,fromCam:r.prefix[i].toCam,toCam:r.prefix[i].toCam,easing:r.overview[0].easing,interp:On,intent:ws}]}return n}return 0<r.overview.length&&r.prefix.length-1|0,n},F1=t=>e=>n=>{const r=J1([])(n),o=r.overview.length-1|0;if(o>=0&&o<r.overview.length){if(0<r.overview.length){const i=r.prefix.length-1|0;if(i>=0&&i<r.prefix.length&&(()=>{const a=r.overview[o].endT;return r.prefix[i].intent==="ActionFocus"&&(()=>{const s=r.overview.length-1|0;return ne(u=>u.direction==="DiveIn"&&Yo(u.parentPath)(t.path)&&de(u.startT-a)<1e-4,e)&&(s>=0&&s<r.overview.length&&0<r.overview.length?r.overview[s].endT-r.overview[0].startT<=1.0001:!0)})()})())return[...r.prefix,{startT:r.overview[0].startT,endT:r.overview[o].endT,fromCam:r.prefix[i].toCam,toCam:r.prefix[i].toCam,easing:r.overview[0].easing,interp:On,intent:ws}]}return n}return n},I1=t=>e=>{const n=e.fromCam.zoom===e.toCam.zoom&&e.fromCam.center.x===e.toCam.center.x&&e.fromCam.center.y===e.toCam.center.y?(e.startT+e.endT)/2:e.endT+1e-4,r=wt(o=>o.target.tag==="RelabelWindow"?N("Just",ga(t.layout)(t.edgeEndpoints)(ee("Node",1,1,o.target._1,void 0,Q,Q))):o.target.tag==="EdgeWindow"?o.target._2.tag==="Extend"?N("Just",hs(t.layout)(t.edgeEndpoints)(o.target._1)):w:o.target.tag==="TokenWindow"?N("Just",(()=>{const i=[...wt(a=>{const s=Js(a)(t.layout.nodes);return s.tag==="Just"?N("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):w})([o.target._4,o.target._5]),...(()=>{const a=m1(o.target._2)(t.layout.edges),s=x1(o.target._7)(o.target._8)((n-o.startT)/Te(1e-4)(o.endT-o.startT)),u=(()=>{if(a.tag==="Just")return Ei((()=>{if(o.target._3==="Forward")return a._1;if(o.target._3==="Backward")return re(a._1);g()})())(s);if(a.tag==="Nothing")return w;g()})();return u.tag==="Just"?[{x:u._1.x,y:u._1.y,w:0,h:0}]:[]})()];return i.length===0?hs(t.layout)(t.edgeEndpoints)(o.target._2):kr(i)})()):o.target.tag==="FillWindow"?N("Just",ga(t.layout)(t.edgeEndpoints)(ee("Node",1,1,o.target._2,void 0,Q,Q))):w)(lt(o=>o.startT<=n&&n<o.endT,t.windows));return r.length===0?w:N("Just",(()=>{const o=kr(r);return{x:o.x*t.placement.scale+t.placement.tx,y:o.y*t.placement.scale+t.placement.ty,w:o.w*t.placement.scale,h:o.h*t.placement.scale}})())},Xc=t=>e=>{const n=lw(t)(e.endT+1e-4);return n.tag==="Just"?N("Just",{x:n._1.x*t.placement.scale+t.placement.tx,y:n._1.y*t.placement.scale+t.placement.ty,w:n._1.w*t.placement.scale,h:n._1.h*t.placement.scale}):w},Ew=t=>e=>n=>r=>o=>{const i=Xc(r)(o),a=s=>{const u=Vo(t)(e)(n)(r)(s),c=u<=0||u>=t.minimumReadableLabelPx?s:{...s,zoom:s.zoom*t.minimumReadableLabelPx/u};return i.tag==="Just"&&(()=>{const _=jn(n)(c);return!(i._1.x>=_.x&&i._1.y>=_.y&&i._1.x+i._1.w<=_.x+_.w&&i._1.y+i._1.h<=_.y+_.h)})()?s:c};return o.intent==="DiveHome"||o.intent==="ActionFocus"&&!(r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0)?o:{...o,fromCam:a(o.fromCam),toCam:a(o.toCam)}},Pw=t=>e=>n=>r=>o=>i=>{const a=I1(r)(i),s=Xc(r)(i),u=c=>{const _=S1(t)(e)(n)(r)(s)(a)(c);return{..._,zoom:rn(o.zoom)(_.zoom)}};return{...i,fromCam:u(i.fromCam),toCam:u(i.toCam)}},Gw=t=>e=>n=>r=>o=>i=>i.intent==="ActionFocus"?Pw(t)(e)(n)(r)(o)(i):{...i,fromCam:R1(t)(e)(n)(r)(o)(i.fromCam),toCam:R1(t)(e)(n)(r)(o)(i.toCam)},Aw=t=>e=>n=>r=>o=>i=>{const a=o(i.fromCam),s=o(i.toCam),u=I1(r)(i),c=Xc(r)(i);return a.zoom===s.zoom&&a.center.x===s.center.x&&a.center.y===s.center.y?{...i,fromCam:Vc(t)(e)(n)(r)(c)(u)(a),toCam:Vc(t)(e)(n)(r)(c)(u)(s)}:{...i,fromCam:a,toCam:Vc(t)(e)(n)(r)(c)(u)(s)}},Rw=t=>e=>n=>r=>o=>o.intent==="ActionFocus"?Aw(t)(e)(n)(r)(Hx)(o):o,ks=t=>e=>n=>r=>o=>i=>qc(Y(Ew(t)(e)(n)(i))(Ux(t)(i)(Cw(i)((()=>{const a=mw(t)(e)(n)(r)(o)(i);if(i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0)return F1(i)(o.dives)(D1(v1(qc(Y(Rw(t)(e)(n)(i))(a)))));const s=G1(t)(e)(n)(o)(i);return a.length===0?[{startT:i.startT,endT:i.endT,fromCam:s,toCam:s,easing:r1,interp:On,intent:fa}]:Sw()(i)(vw(s)(i)(F1(i)(o.dives)(D1(v1(qc(Jw(s)(Y(Gw(t)(e)(n)(i)(s))(a))))))))})())))),Dw=t=>e=>n=>r=>o=>Rt(i=>a=>at.compare(i.startT)(a.startT))(Et(o.segments)(ks(t)(e)(n)(r)(o))),la=t=>e=>n=>r=>o=>i=>a=>{if(i.direction==="DiveIn"){const s=Xo(n)(t.padding)(a)(qo(t)(n)(ks(t)(e)(n)(r)(o)(a))(i.startT-1e-4).camera),u=Js(i.node)(a.layout.nodes);return i.direction==="DiveIn"&&u.tag==="Just"?L1(e)(n)(s)({x:u._1.x*a.placement.scale+a.placement.tx,y:u._1.y*a.placement.scale+a.placement.ty,w:u._1.w*a.placement.scale,h:u._1.h*a.placement.scale}):s}if(i.direction==="DiveOut"){const s=Xo(n)(t.padding)(a)(qo(t)(n)(ks(t)(e)(n)(r)(o)(a))(i.endT+1e-4).camera),u=Js(i.node)(a.layout.nodes);return i.direction==="DiveIn"&&u.tag==="Just"?L1(e)(n)(s)({x:u._1.x*a.placement.scale+a.placement.tx,y:u._1.y*a.placement.scale+a.placement.ty,w:u._1.w*a.placement.scale,h:u._1.h*a.placement.scale}):s}g()},Fw=t=>e=>n=>r=>o=>Et(o.dives)(i=>{const a=Cs(o)(i.parentPath)(i.startT)(i.endT);if(a.tag==="Just"){const s=i.childPath,u=te(c=>Yo(c.path)(s))(o.segments);if(u.tag==="Just"){const c=ks(t)(e)(n)(r)(o)(u._1),_=G1(t)(e)(n)(o)(u._1),l=la(t)(e)(n)(r)(o)(i)(a._1),f=(()=>{if(i.direction==="DiveIn")return _;if(i.direction==="DiveOut")return Xo(n)(t.padding)(u._1)(qo(t)(n)(c)(i.startT-1e-4).camera);g()})();if(i.direction==="DiveIn"){const d=te(h=>h.direction==="DiveIn"&&Yo(h.parentPath)(i.childPath)&&de(h.startT-i.endT)<1e-4)(o.dives);if(d.tag==="Just"){const h=Cs(o)(d._1.parentPath)(d._1.startT)(d._1.endT);if(h.tag==="Just"){if(i.direction==="DiveIn"&&i.endT-i.startT>.12){const m=i.endT-.12,p={easing:Lr,endT:m,fromCam:l,intent:yo,interp:mo,startT:i.startT,toCam:la(t)(e)(n)(r)(o)(d._1)(h._1)};return[p,{...p,startT:m,endT:i.endT,fromCam:la(t)(e)(n)(r)(o)(d._1)(h._1)}]}return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:f,easing:Lr,interp:mo,intent:yo}]}if(h.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:f,easing:Lr,interp:mo,intent:yo}];g()}if(d.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:f,easing:Lr,interp:mo,intent:yo}];g()}if(i.direction==="DiveOut"){const d=te(h=>h.direction==="DiveIn"&&Yo(h.parentPath)(i.childPath)&&de(h.startT-i.endT)<1e-4)(o.dives);if(d.tag==="Just"){const h=Cs(o)(d._1.parentPath)(d._1.startT)(d._1.endT);if(h.tag==="Just"){if(i.direction==="DiveIn"&&i.endT-i.startT>.12){const m=i.endT-.12,p={easing:Lr,endT:m,fromCam:f,intent:yo,interp:mo,startT:i.startT,toCam:la(t)(e)(n)(r)(o)(d._1)(h._1)};return[p,{...p,startT:m,endT:i.endT,fromCam:la(t)(e)(n)(r)(o)(d._1)(h._1)}]}return[{startT:i.startT,endT:i.endT,fromCam:f,toCam:l,easing:Lr,interp:mo,intent:yo}]}if(h.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:f,toCam:l,easing:Lr,interp:mo,intent:yo}];g()}if(d.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:f,toCam:l,easing:Lr,interp:mo,intent:yo}]}g()}if(u.tag==="Nothing")return[];g()}if(a.tag==="Nothing")return[];g()}),B1=t=>e=>n=>r=>o=>[...Fw(t)(e)(n)(r)(o),...Dw(t)(e)(n)(r)(o)],Ri=(t,e,n)=>({tag:t,_1:e,_2:n}),Iw=t=>t,Di=(t,e)=>({tag:t,_1:e}),Q1=(t,e)=>({tag:t,_1:e}),Uc=t=>t,Ls=(t,e)=>({tag:t,_1:e}),Kc=Ls("NotYet"),z1=Ls("Consumed"),Bw=Uc("FromSource"),M1=Uc("FromTarget"),Qw=Uc("FromBoth"),Zc=Di("Hidden"),O1=Di("Visible"),jc=Iw("ExtendFromSource"),tg=Ri("Retracted"),W1=Ri("Extended"),zw={eq:t=>e=>t.tag==="Retracted"?e.tag==="Retracted":t.tag==="Extending"?e.tag==="Extending"&&(t._1==="ExtendFromSource"?e._1==="ExtendFromSource":t._1==="ExtendFromTarget"&&e._1==="ExtendFromTarget")&&t._2===e._2:t.tag==="Extended"?e.tag==="Extended":t.tag==="Retracting"&&e.tag==="Retracting"&&(t._1==="FromSource"?e._1==="FromSource":t._1==="FromTarget"?e._1==="FromTarget":t._1==="FromBoth"&&e._1==="FromBoth")&&t._2===e._2},eg=t=>t,Ss=(t,e)=>({tag:t,_1:e}),Es={eq:sc(ta)},Ps=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},q1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Sr=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},H1=Qt.foldMap(gy(A)),ha=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},$1=ge(A)(Qt),Mw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},Ow=ge(A)(Qt),Ww=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},qw=ge(A)(Qt),Hw=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Y1=Ss("Closed"),$w=Ss("Open"),V1=eg("Backdrop"),Yw=eg("FlyThrough"),_n=eg("Active"),Gs=t=>e=>n=>{const r=te(o=>Es.eq(o.path)(e)&&n>=o.startT&&n<o.endT)(t.segments);if(r.tag==="Just")return N("Just",r._1);if(r.tag==="Nothing")return te(o=>Es.eq(o.path)(e))(t.segments);g()},Vw=t=>e=>{if(e.scene.tag==="Structural")return e.scene._1.to;if(e.scene.tag==="DataFlow")return e.scene._1.keyframe;if(e.scene.tag==="Hold")return e.scene._1;if(e.scene.tag==="EnterNode"||e.scene.tag==="ExitNode"||e.scene.tag==="StepScene")return t;g()},Xw=t=>{const e=te(n=>n.path.length===0)(t.segments);if(e.tag==="Just")return e._1.edgeEndpoints;if(e.tag==="Nothing")return Q;g()},Uw=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:Pc,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:Xw(t)}),Kw=t=>Y(e=>e<1?[]:At(0,e,t))(Ut(0,t.length-1|0)),As=t=>e=>{const n=Ps(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.nodes;g()},ng=t=>e=>n=>{const r=Ps(e)(t.keyframes);if(r.tag==="Just")return q1(n)(r._1.labels);if(r.tag==="Nothing")return w;g()},rg=t=>e=>{const n=Ps(e)(t.keyframes);if(n.tag==="Nothing")return Q;if(n.tag==="Just")return n._1.edges;g()},Zw=t=>e=>wt(n=>q1(e)(n.labels))((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,pt("Cons",r._4,n(r._6,o)));g()};return Ot(ue.foldr,n(t.keyframes,G))})()),jw=J(t=>e=>{const n=Or(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?St(n._1.init)({...n._1.last,endT:Sr(n._1.last.endT)(e.endT),windows:St(n._1.last.windows)(e)}):St(t)({endT:e.endT,windows:[e]})})([]),tT=t=>e=>n=>H1(r=>H1(o=>o.target.tag==="FillWindow"?o.startT<=n?ee("Node",1,1,o.target._2,void 0,Q,Q):Q:o.target.tag==="TokenWindow"&&o.startT+(o.endT-o.startT)*.25<=n?ee("Node",1,1,o.target._4,void 0,Q,Q):Q)(r.windows))(lt(r=>n<=r.endT+t,jw(Rt(r=>o=>at.compare(r.startT)(o.startT))(lt(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),eT=t=>e=>{const n=Pt(r=>w,r=>o=>N("Just",{head:r,tail:o}),Zw(t)(e));if(n.tag==="Nothing")return!1;if(n.tag==="Just"){const r=n._1.head;return ne(o=>o!==r,n._1.tail)}g()},nT=t=>e=>n=>ne(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),rT=t=>e=>n=>ne(r=>r.endT<=e&&r.target.tag==="RelabelWindow"&&r.target._1===n,t),oT=t=>e=>n=>ne(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),iT=t=>e=>n=>ne(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),aT=t=>e=>n=>ne(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),X1=t=>{const e=mf(w,_f,o=>As(t)((()=>{if(o.scene.tag==="Structural")return o.scene._1.to;if(o.scene.tag==="DataFlow")return o.scene._1.keyframe;if(o.scene.tag==="Hold")return o.scene._1;if(o.scene.tag==="EnterNode"||o.scene.tag==="ExitNode"||o.scene.tag==="StepScene")return t.initialKeyframe;g()})()).tag==="Leaf"?w:N("Just",Sr(o.startT)(o.endT-1e-4)),t.spans),n=(()=>{if(e.tag==="Nothing")return t.startT;if(e.tag==="Just")return e._1;g()})(),r=te(o=>o.target.tag==="NodeWindow"&&o.target._2==="PlopIn")(Rt(o=>i=>at.compare(o.startT)(i.startT))(t.windows));if(r.tag==="Nothing")return n;if(r.tag==="Just")return Sr(r._1.startT)(r._1.endT-1e-4);g()},pa=t=>e=>n=>te(r=>n(r)&&e>=r.startT&&e<r.endT)(t),ma=t=>e=>{if(e<t.startT)return er("AtKeyframe",t.initialKeyframe);const n=te(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return er("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return er("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return er("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode"||n._1.scene.tag==="StepScene")return er("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing")return er("AtKeyframe",J(Vw)(t.initialKeyframe)(t.spans));g()},sT=t=>e=>{const n=ma(t)(e),r=Ps((()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;g()})())(t.keyframes);if(r.tag==="Just")return r._1.kind;if(r.tag==="Nothing")return ca;g()},uT=t=>e=>{const n=ma(t)(e);if(n.tag==="AtKeyframe")return Fe(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return Fe(3)(n._2)==="kf-"?"":n._2;g()},cT=t=>e=>n=>{const r=ma(t)(e);if(r.tag==="AtKeyframe")return ng(t)(r._1)(n);if(r.tag==="InTransition")return rT(t.windows)(e)(n)?ng(t)(r._2)(n):ng(t)(r._1)(n);g()},gT={segment:{startT:0,endT:0,path:[],layout:{nodes:Q,edges:Q,chipExtras:Q,edgeLabels:Q},placement:Pc,windows:[],spans:[],keyframes:Q,initialKeyframe:"",edgeEndpoints:Q},state:{animationTime:0,nodes:Q,nodeLabels:Q,edgeEndpoints:Q,edges:Q,tokens:Q,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:ca,visited:Q,nodeFadeAlpha:Q,nodeLabelFadeAlpha:Q,edgeFadeAlpha:Q,nodeInvert:Q},bgAlpha:1,minis:[],role:_n},Rs=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:gT},_T=t=>e=>{const n=ma(t)(e);if(n.tag==="AtKeyframe")return As(t)(n._1);if(n.tag==="InTransition")return Oe(A.compare,Qe,As(t)(n._1),As(t)(n._2));g()},fT=t=>e=>{const n=ma(t)(e);if(n.tag==="AtKeyframe")return rg(t)(n._1);if(n.tag==="InTransition")return Oe(A.compare,Qe,rg(t)(n._1),rg(t)(n._2));g()},U1=t=>e=>{const n=t.endT-t.startT;return n<=0?1:Sr(0)(ha(1)((e-t.startT)/n))},dT=t=>e=>n=>zc(qo(t.cameraConfig)(t.layout)(t.cameraSpans)(n.startT).camera)(qo(t.cameraConfig)(t.layout)(t.cameraSpans)(n.endT).camera)(U1(n)(e)),K1=t=>e=>n=>{const r=Sr(0)(ha(1)((n-t)/Sr(1e-6)(e-t)));return r*r*r*(r*(r*6-15)+10)},Z1=t=>{if(t.tag==="Closed")return 0;if(t.tag==="Opening")return K1(.3)(1)(t._1);if(t.tag==="Open")return 1;if(t.tag==="Closing")return 1-K1(0)(.7)(t._1);g()},lT=t=>{const e=Z1(t);return e<=0||e>=1?0:en(3.141592653589793*e)},Uo=t=>e=>{const n=t.endT-t.startT;return n<=0?1:Sr(0)(ha(1)((e-t.startT)/n))},hT=t=>e=>$1(wt(n=>{const r=pa(t.windows)(e)(o=>o.target.tag==="RelabelWindow"&&o.target._1===n);if(r.tag==="Just")return r._1.target.tag==="RelabelWindow"?N("Just",L(n,Q1("RelabelingNode",{oldLabel:r._1.target._2,newLabel:r._1.target._3,progress:Uo(r._1)(e)}))):w;if(r.tag==="Nothing"){if(eT(t)(n)){const o=cT(t)(e)(n);if(o.tag==="Just")return N("Just",L(n,Q1("StaticNodeLabel",o._1)));if(o.tag==="Nothing")return w;g()}return w}g()})((()=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node")return ee("Node",r._1,r._2,r._3,void 0,n(r._5),n(r._6));g()};return Ot(pn.foldr,n(t.layout.nodes))})())),pT=t=>e=>n=>r=>o=>{const i=pa(e)(n)(a=>a.target.tag==="EdgeWindow"&&a.target._2.tag==="Retract"&&a.target._1===o);if(i.tag==="Just"){const a=ps(t.timing.edgeEasing)(Uo(i._1)(n)),s=i._1.target.tag==="EdgeWindow"?i._1.target._2:vs("Extend",jc);if(s.tag==="Retract")return Ri("Retracting",s._1,a);if(s.tag==="Extend")return Ri("Extending",s._1,a);g()}if(i.tag==="Nothing"){if(nT(e)(n)(o))return tg;const a=pa(e)(n)(s=>s.target.tag==="EdgeWindow"&&s.target._1===o);if(a.tag==="Just"){const s=ps(t.timing.edgeEasing)(Uo(a._1)(n)),u=a._1.target.tag==="EdgeWindow"?a._1.target._2:vs("Extend",jc);if(u.tag==="Retract")return Ri("Retracting",u._1,s);if(u.tag==="Extend")return Ri("Extending",u._1,s);g()}if(a.tag==="Nothing")return aT(e)(n)(o)?tg:Mw(o)(r)?W1:tg}g()},mT=t=>e=>n=>{const r=fT(e)(n);return Ow(Y(o=>L(o,pT(t)(e.windows)(n)(r)(o)))((()=>{const o=i=>{if(i.tag==="Leaf")return Q;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,void 0,o(i._5),o(i._6));g()};return Ot(pn.foldr,o(e.layout.edges))})()))},yT=t=>e=>n=>r=>{const o=pa(t)(e)(i=>i.target.tag==="NodeWindow"&&i.target._1===r&&i.target._2==="PlopOut");if(o.tag==="Just"){const i=Uo(o._1)(e),a=o._1.target.tag==="NodeWindow"?o._1.target._2:Wc;if(a==="PlopIn")return Di("PloppingIn",i);if(a==="PlopOut")return Di("PloppingOut",i);g()}if(o.tag==="Nothing"){if(oT(t)(e)(r))return Zc;const i=pa(t)(e)(a=>a.target.tag==="NodeWindow"&&a.target._1===r);if(i.tag==="Just"){const a=Uo(i._1)(e),s=i._1.target.tag==="NodeWindow"?i._1.target._2:Wc;if(s==="PlopIn")return Di("PloppingIn",a);if(s==="PlopOut")return Di("PloppingOut",a);g()}if(i.tag==="Nothing")return iT(t)(e)(r)?Zc:Ww(r)(n)?O1:Zc}g()},xT=t=>e=>{const n=_T(t)(e);return $1(Y(r=>L(r,yT(t.windows)(e)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));g()};return Ot(pn.foldr,r(t.layout.nodes))})()))},wT=t=>e=>n=>e.target.tag==="TokenWindow"?L(e.target._1,n<e.startT?Kc:n>=e.endT?z1:Ls("Travelling",{edge:e.target._2,direction:e.target._3,progress:ps(t.timing.tokenEasing)(Uo(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"?L(e.target._1,n<e.startT?Kc:n>=e.endT?z1:Ls("Filling",{node:e.target._2,progress:Uo(e)(n),labels:e.target._3})):L("",Kc),TT=t=>e=>n=>qw(Y(r=>wT(t)(r)(n))(lt(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),NT=t=>e=>n=>({animationTime:n,nodes:xT(e)(n),nodeLabels:hT(e)(n),edgeEndpoints:e.edgeEndpoints,edges:mT(t)(e)(n),tokens:TT(t)(e.windows)(n),camera:qo(t.cameraConfig)(e.layout)(t.cameraSpans)(n).camera,frameTitle:uT(e)(n),staticKind:sT(e)(n),visited:tT(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:Q,nodeLabelFadeAlpha:Q,edgeFadeAlpha:Q,nodeInvert:Q}),Fi=t=>e=>n=>r=>({segment:n,state:NT(t)(n)(e),bgAlpha:1,minis:vT(t)(e)(n),role:r}),vT=t=>e=>n=>wt(r=>{const o=Gs(t)(St(n.path)(r))(e);if(o.tag==="Just")return N("Just",{...Fi(t)(Hw(o._1.startT)(o._1.endT-1e-4)(e))(o._1)(V1),bgAlpha:0});if(o.tag==="Nothing")return w;g()})((()=>{const r=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));g()};return Ot(pn.foldr,r(n.layout.nodes))})()),JT=t=>e=>{if(t.direction==="DiveIn")return X1(e);if(t.direction==="DiveOut")return t.startT-1e-4;g()},j1=t=>e=>wt(n=>{const r=te(o=>o.direction==="DiveIn"&&Es.eq(o.childPath)((()=>{const i=n.length+1|0;return i<1?[]:At(0,i,e)})()))(t.dives);if(r.tag==="Just"){const o=Gs(t)(n)(r._1.startT-1e-4);if(o.tag==="Just")return N("Just",(()=>{const i=Fi(t)(r._1.startT-1e-4)(o._1)(V1);return{...i,state:{...i.state,nodeFadeAlpha:ee("Node",1,1,r._1.node,0,Q,Q)}}})());if(o.tag==="Nothing")return w;g()}if(r.tag==="Nothing")return w;g()})(Kw(e)),td=t=>e=>{const n=lt(o=>e>=o.startT&&e<o.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:Uw(t)},CT=t=>e=>n=>r=>{const o=s=>{const u=Fi(t)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT;g()})())(s)(Yw);return{...u,bgAlpha:1,minis:lt(c=>!Es.eq(c.segment.path)(n.childPath),u.minis),state:{...u.state,edgeFadeAlpha:Q,nodeFadeAlpha:ee("Node",1,1,n.node,0,Q,Q),nodeInvert:Q,tokens:Q}}},i=Gs(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT;g()})()),a=Gs(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})());return[...j1(t)(n.parentPath),...(()=>{if(i.tag==="Just"){if(a.tag==="Just")return[o(i._1),{...Fi(t)(JT(n)(a._1))(a._1)(_n),bgAlpha:1}];if(a.tag==="Nothing")return[o(i._1)];g()}if(i.tag==="Nothing")return[Fi(t)(e)(td(t)(e))(_n)];g()})()]},bT=t=>e=>te(n=>e>=n.startT&&e<n.endT)(t.dives),kT=t=>e=>{const n=td(t)(e),r=t.dives.length!==0,o=qo(t.cameraConfig)(t.layout)(t.cameraSpans)(e).camera,i=Xo(t.layout)(t.cameraConfig.padding)(n)(o),a=j1(t)(n.path),s=Fi(t)(n.path.length===0?e:Sr(e)(X1(n)))(n)(_n),u={...s,state:{...s.state,camera:i}},c=bT(t)(e);if(c.tag==="Just"){const _=U1(c._1)(e);return{levels:CT(t)(e)(c._1)(dT(t)(e)(c._1)),camera:o,rootLayout:t.layout,hasDives:r,portalState:(()=>{if(c._1.direction==="DiveIn")return Ss("Opening",Sr(0)(ha(1)(_)));if(c._1.direction==="DiveOut")return Ss("Closing",Sr(0)(ha(1)(_)));g()})()}}if(c.tag==="Nothing")return{levels:St(a)(u),camera:i,rootLayout:t.layout,hasDives:r,portalState:n.path.length===0?Y1:$w};g()},LT=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ST=t=>{const e=t.length;return(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=i;if(u>=e){a=!1,s=c;continue}const _=l=>f=>{let d=l,h=f,m=!0,p;for(;m;){const x=d,y=h;if(x>=e){m=!1,p=y;continue}if(u>=0&&u<t.length){if(x>=0&&x<t.length){d=x+1|0,h=(()=>{const T=t[u].position,v=t[u].size,b=t[x].position,C=t[x].size;return T._1<b._1+C._1&&b._1<T._1+v._1&&T._2<b._2+C._2&&b._2<T._2+v._2})()?y+1|0:y;continue}d=x+1|0,h=y;continue}m=!1,p=y}return p};o=u+1|0,i=_(u+1|0)(c)}return s})(0)(0)},ed=t=>J(e=>n=>e+Ny(n.start)(n.end))(0)(t.segments),nd=t=>e=>n=>({crossingCount:J(r=>o=>r+o.jumps.length|0)(0)(e),bendCount:J(r=>o=>r+o.bends.length|0)(0)(e),totalEdgeLength:J(r=>o=>r+ed(o))(0)(e),maxEdgeLength:J(r=>o=>LT(r)(ed(o)))(0)(e),nodeOverlapCount:ST(t),constraintViolations:n,jumpCount:J(r=>o=>r+o.jumps.length|0)(0)(e)}),og=t=>t,le=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ig=og("LEFT"),ET=og("RIGHT"),rd=og("UNDEFINED"),PT={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},GT={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?un:ze;if(e==="LEFT")return Me;if(t==="RIGHT")return e==="RIGHT"?un:ze;if(e==="RIGHT")return Me;if(t==="UP")return e==="UP"?un:ze;if(e==="UP")return Me;if(t==="DOWN")return e==="DOWN"?un:ze;if(e==="DOWN")return Me;if(t==="UNDEFINED"&&e==="UNDEFINED")return un;g()},Eq0:()=>PT},AT=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){if(t==="LEFT"){if(i._3==="LEFT"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="LEFT"){n=i._6;continue}if(t==="RIGHT"){if(i._3==="RIGHT"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="RIGHT"){n=i._6;continue}if(t==="UP"){if(i._3==="UP"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="UP"){n=i._6;continue}if(t==="DOWN"){if(i._3==="DOWN"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="DOWN"){n=i._6;continue}if(t==="UNDEFINED"&&i._3==="UNDEFINED"){r=!1,o=!0;continue}}g()}return o},RT={x:0,y:0},Sn=t=>e=>n=>{const r=le(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:it(ut)(t)(e(r._1))(n.cNodes)};g()},ya=t=>e=>n=>{const r=le(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:it(ut)(t)(e(r._1))(n.cGroups)};g()},DT=t=>J(e=>n=>Sn(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),FT=t=>{const e=J(n=>r=>{const o=le(r)(t.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just")return J(i=>a=>zt(ut)(we)(a)([r])(i))(n)(o._1.constraints);g()})(Q)(t.cNodeOrder);return J(n=>r=>Sn(r)(o=>({...o,constraints:(()=>{const i=le(r)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;g()})()}))(n))(t)(t.cNodeOrder)},IT=t=>e=>Sn(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}})),BT=t=>{const e=J(n=>r=>ya(r)(o=>({...o,outDegree:o.outDegreeReal}))(n))(t)(t.cGroupOrder);return J(n=>r=>Sn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder)},nr={left:!1,right:!1,up:!1,down:!1},QT={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},ag=t=>J(e=>n=>{const r=le(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const o=J(a=>s=>{const u=le(s)(e.cNodes);if(u.tag==="Nothing")return a;if(u.tag==="Just"){if(a.tag==="Nothing")return N("Just",s);if(a.tag==="Just"){const c=le(a._1)(e.cNodes);if(c.tag==="Nothing")return N("Just",s);if(c.tag==="Just")return u._1.hitbox.x<c._1.hitbox.x?N("Just",s):N("Just",a._1)}}g()})(w)(r._1.cNodes),i=ya(n)(a=>({...a,reference:o}))(e);if(o.tag==="Nothing")return i;if(o.tag==="Just"){const a=le(o._1)(i.cNodes);if(a.tag==="Nothing")return i;if(a.tag==="Just"){const s=a._1;return J(u=>c=>Sn(c)(_=>({..._,cGroupOffset:{x:_.hitbox.x-s.hitbox.x,y:_.hitbox.y-s.hitbox.y}}))(u))(i)(r._1.cNodes)}}}g()})(t)(t.cGroupOrder),En=t=>ag({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return Q;if(n.tag==="Node")return ee("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)})()}),Er=t=>ag({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return Q;if(n.tag==="Node")return ee("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)})()}),od=t=>{const e=J(n=>r=>ya(r)(o=>({...o,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return J(n=>r=>{const o=le(r)(n.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just"){if(o._1.cGroup.tag==="Nothing")return n;if(o._1.cGroup.tag==="Just"){const i=o._1.cGroup._1;return J(a=>s=>{const u=le(s)(a.cNodes);if(u.tag==="Nothing")return a;if(u.tag==="Just")return u._1.cGroup.tag==="Just"&&u._1.cGroup._1!==i?ya(u._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(ya(i)(c=>ln(go)(s)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,s]})(a)):a;g()})(n)(o._1.constraints)}}g()})(e)(e.cNodeOrder)},Ds=t=>{const e=FT(t.cGraph);return{...t,cGraph:od(J(n=>r=>Sn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},zT=t=>e=>J(n=>r=>{if(t==="LEFT"||t==="UP"){const i=r._2;return Sn(r._1)(a=>({...a,constraints:[...a.constraints,i]}))(n)}const o=r._1;return Sn(r._2)(i=>({...i,constraints:[...i.constraints,o]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),rr=t=>{const e={...t,cGraph:zT(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return Q;if(r.tag==="Node")return ee("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:od((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);g()})())}},MT=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?rr(r):e==="RIGHT"?rr({...r,cGraph:En(r.cGraph)}):e==="UP"?rr({...r,cGraph:Er(r.cGraph)}):e==="DOWN"?rr({...r,cGraph:En(Er(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?Ds({...r,cGraph:En(r.cGraph)}):e==="UP"?rr({...r,cGraph:Er(r.cGraph)}):e==="DOWN"?rr({...r,cGraph:En(Er(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?Ds({...r,cGraph:En(r.cGraph)}):e==="UP"?rr({...r,cGraph:Er(En(r.cGraph))}):e==="DOWN"?rr({...r,cGraph:En(Er(En(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?rr({...r,cGraph:Er(r.cGraph)}):e==="RIGHT"?rr({...r,cGraph:En(Er(r.cGraph))}):e==="DOWN"?Ds({...r,cGraph:En(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?rr({...r,cGraph:Er(En(r.cGraph))}):e==="RIGHT"?rr({...r,cGraph:En(Er(En(r.cGraph)))}):e==="UP"?Ds({...r,cGraph:En(r.cGraph)}):r;g()},id=t=>e=>e.finished||!AT(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:MT(e.direction)(t)(e),OT=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?id(ig)(t):t,n={...e,cGraph:BT(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},ad=t=>e=>n=>{const r=le(t)(n.cNodes),o=le(e)(n.cGroups);return r.tag==="Just"&&o.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:it(ut)(t)({...r._1,cGroup:N("Just",e)})(n.cNodes),cGroups:it(ut)(e)({...o._1,cNodes:ln(go)(t)(o._1.cNodes)?o._1.cNodes:[...o._1.cNodes,t],reference:(()=>{if(o._1.reference.tag==="Nothing")return N("Just",t);if(o._1.reference.tag==="Just")return N("Just",o._1.reference._1);g()})()})(n.cGroups)}:n},sd=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:it(ut)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:w,cGroupOffset:RT,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:nr})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),sg=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:J(r=>o=>ad(o)(n)(r))({...e,cGroups:it(ut)(n)({id:n,master:t.master,cNodes:[],startPos:-1e308,incomingConstraints:[],outDegree:0,outDegreeReal:0,reference:w,delta:0,deltaNormalized:0})(e.cGroups),cGroupOrder:[...e.cGroupOrder,n],nextCGroupId:n+1|0})(t.nodes)}},WT=t=>J(e=>n=>{const r=le(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?sg({master:w,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),qT=t=>({cGraph:DT(WT(ag(t))),direction:rd,compactionAlgorithm:w,constraintAlgorithm:w,spacingsHandler:QT,lockFun:w,finished:!1}),HT=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},$T=t=>e=>{const n=at.compare(t._1)(e._1);return n==="LT"?ze:n==="GT"?Me:ut.compare(t._2)(e._2)},YT=(()=>{const t=wn.unfoldr(gr);return e=>t(Tn("IterNode",e,ur))})(),ud=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},cd=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",gd=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),Fs=t=>e=>$T(L(t.hitbox.x+t.hitbox.width/2,t.id))(L(e.hitbox.x+e.hitbox.width/2,e.id)),VT=t=>e=>{const n=Mr(Yt,w,r=>Fs(t)(r)==="LT",e);if(n.tag==="Just"){const r=yf(Yt,w,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return St(e)(t);g()},_d=t=>e=>{const n=lt(o=>Fs(o)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?N("Just",n[r]):w},XT=t=>e=>{const n=VT(e)(t.intervals),r=te(i=>Fs(e)(i)==="LT")(n),o=it(ut)(e.id)((()=>{const i=_d(e)(n);return i.tag==="Just"?N("Just",i._1.id):w})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return it(ut)(r._1.id)(N("Just",e.id))(o);if(r.tag==="Nothing")return o;g()})()}},UT=t=>e=>{const n=at.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?Me:un:e.low?ze:un:n},KT=t=>J(e=>n=>Sn(n.id)(r=>({...r,constraints:[]}))(e))(t)(wt(e=>le(e)(t.cNodes))(t.cNodeOrder)),ug=t=>e=>J(n=>r=>{const o=le(r._1)(n.cNodes);if(o.tag==="Just")return Sn(r._1)(i=>({...i,constraints:[...i.constraints,...r._2]}))(n);if(o.tag==="Nothing")return n;g()})(e)(YT(t)),fd=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}},dd=t=>e=>n=>J(r=>o=>n(o)?Sn(o.id)(fd(t))(r):r)(e)(wt(r=>le(r)(e.cNodes))(e.cNodeOrder)),ZT=t=>e=>{const n=(r,o,i)=>{const a=Sn(i)(fd(t))(r);return o.length<=1?a:J(s=>u=>u===i?s:Sn(u)(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))(a)(o)};return J(r=>o=>{if(o.master.tag==="Nothing")return 0<o.cNodes.length?n(r,o.cNodes,o.cNodes[0]):r;if(o.master.tag==="Just")return n(r,o.cNodes,o.master._1);g()})(e)(wt(r=>le(r)(e.cGroups))(e.cGroupOrder))},jT=t=>e=>{const n=_d(e)(t.intervals),r=te(i=>Fs(e)(i)==="LT")(t.intervals),o=n.tag==="Just"&&(()=>{const i=ud(e.id)(t.cand);return(i.tag==="Nothing"?!1:i.tag==="Just"&&(i._1.tag==="Nothing"?!1:i._1.tag==="Just"&&i._1._1===n._1.id))&&n._1.cGroup.tag==="Just"&&e.cGroup.tag==="Just"&&n._1.cGroup._1!==e.cGroup._1})()?zt(ut)(we)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const i=ud(r._1.id)(t.cand);return(i.tag==="Nothing"?!1:i.tag==="Just"&&(i._1.tag==="Nothing"?!1:i._1.tag==="Just"&&i._1._1===e.id))&&e.cGroup.tag==="Just"&&r._1.cGroup.tag==="Just"&&e.cGroup._1!==r._1.cGroup._1})()?zt(ut)(we)(e.id)([r._1.id])(o):o,intervals:lt(i=>i.id!==e.id,t.intervals)}},tN=t=>e=>e.low?XT(t)(e.node):jT(t)(e.node),cg=t=>e=>J(tN)({intervals:[],cand:Q,constraints:Q})(Rt(UT)(Et(lt(t,wt(n=>le(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,eN=t=>e=>{const n=HT(0)(t/2-.5),r=ug(cg(cd)(dd(n)(e)(cd)))(e),o=ug(cg(gd)(dd(n)(r)(gd)))(r);return ug(cg(i=>!0)(ZT(n)(o)))(o)},nN=t=>e=>eN(t)(KT(e.cGraph)),Is=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ld=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},gg=t=>e=>n=>r=>o=>({id:t,representedEdges:[o],affectedBends:[e,n],hitbox:{x:Is(e._1)(n._1),y:Is(e._2)(n._2),width:de(e._1-n._1),height:de(e._2-n._2)},ignoreSpacing:nr,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:w}),rN=t=>e=>{const n=Is(t.hitbox.x)(e.hitbox.x),r=Is(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:ld(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:ld(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()})()}},oN=t=>e=>de(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,iN=t=>e=>de(t.hitbox.x-e.hitbox.x)<=1e-4?at.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?ze:Me,hd=(t,e)=>({tag:t,_1:e}),_g=ge(A)(Qt),Bs=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},pd=(()=>{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 o=A.compare(n._1)(r._1);if(o==="LT")return ze;if(o==="GT")return Me;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?un:ze;if(r._2.tag==="Nothing")return Me;if(n._2.tag==="Just"&&r._2.tag==="Just")return A.compare(n._2._1)(r._2._1);g()},Eq0:()=>t};return J(n=>r=>it(e)(r)()(n))(Q)})(),Hr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},aN=J(t=>e=>it(GT)(e)()(t))(Q),fg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=Hf.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},sN=t=>e=>{const n=_g(Y(i=>L(i.id,i))(t)),r=wt(i=>Bs(i)(n))(e),o=ut.compare((()=>{const i=pd(Y(a=>L(a.from.node,a.from.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;g()})())((()=>{const i=pd(Y(a=>L(a.to.node,a.to.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;g()})());if(o==="LT")return{...nr,left:!0,right:!1};if(o==="GT")return{...nr,left:!1,right:!0};if(o==="EQ")return nr;g()},uN=t=>wt(e=>{if(e.direction==="V")return N("Just",{start:e.start,end:e.end});if(e.direction==="H")return w;g()})(t.segments),Qs=t=>e=>n=>r=>{if(r.tag==="Just"){const o=Hr(n)(e);if(o.tag==="Just"){const i=te(a=>a.id===r._1)(o._1);if(i.tag==="Just")return i._1.side;if(i.tag==="Nothing")return t;g()}if(o.tag==="Nothing")return t;g()}if(r.tag==="Nothing")return t;g()},cN=t=>e=>n=>{const r=sd({origin:N("Just",hd("SegmentOrigin",n)),kind:N("Just","vs"),hitbox:n.hitbox})(e.cGraph),o=IT(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const i=le(n.potentialGroupParents[0])(o.cNodes);if(i.tag==="Just"){if(i._1.cGroup.tag==="Just")return ad(r.id)(i._1.cGroup._1)(o);if(i._1.cGroup.tag==="Nothing")return o;g()}if(i.tag==="Nothing")return o;g()}return sg({master:N("Just",r.id),nodes:[r.id]})(o).graph})(),edgeToCs:J(i=>a=>zt(A)(we)(a)([r.id])(i))(e.edgeToCs)(n.representedEdges),lockMap:it(ut)(r.id)(sN(t)(n.representedEdges))(e.lockMap)}},gN=t=>e=>n=>{const r=Pt(o=>w,o=>i=>N("Just",{head:o,tail:i}),Rt(iN)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const o=J(i=>a=>oN(i.survivor)(a)?{...i,survivor:rN(i.survivor)(a)}:{survivor:a,merged:[...i.merged,i.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return J(cN(t))(n)([...o.merged,o.survivor])}g()},_N=t=>({cGraph:{cNodes:Q,cNodeOrder:[],cGroups:Q,cGroupOrder:[],supportedDirections:aN([rd,ig,ET]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:Q,edgeToCs:Q,lockMap:Q}),fN=t=>{const e=nt(4);return{x:t.position._1*e,y:t.position._2*e,width:t.size._1*e,height:t.size._2*e}},dN=t=>e=>n=>J(r=>o=>{const i=sd({origin:N("Just",hd("NodeOrigin",o.node)),kind:w,hitbox:fN(o)})(r.cGraph),a=Hr(o.node)(t),s=(()=>{if(a.tag==="Nothing")return L(0,0);if(a.tag==="Just")return a._1;g()})();return{...r,cGraph:sg({master:N("Just",i.id),nodes:[i.id]})(i.graph).graph,nodeToC:it(A)(o.node)(i.id)(r.nodeToC),lockMap:it(ut)(i.id)((()=>{const u=s._1-s._2|0;return u<0?{...nr,left:!0}:u>0?{...nr,right:!0}:nr})())(r.lockMap)}})(n)(e),lN=t=>J(e=>n=>zt(A)(r=>o=>L(r._1+o._1|0,r._2+o._2|0))(n.to.node)(L(1,0))(zt(A)(r=>o=>L(r._1+o._1|0,r._2+o._2|0))(n.from.node)(L(0,1))(e)))(Q)(t),hN=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?it(A)(n.origin._1._1)(n.hitbox.x)(e):e)(Q)(wt(e=>le(e)(t.cNodes))(t.cNodeOrder)),pN=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?it(A)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(Q)(wt(e=>le(e)(t.cNodes))(t.cNodeOrder)),mN=t=>J(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return J(o=>i=>it(Hf)(i)(r)(o))(e)(n.origin._1._1.affectedBends)}return e})(Q)(wt(e=>le(e)(t.cNodes))(t.cNodeOrder)),md=t=>{const e=_g(Y(n=>L(n.id,n))(t.edges));return wt(n=>{const r=Bs(n.edge)(e);if(r.tag==="Just")return n.reversed?N("Just",{edgeId:n.edge,src:r._1.to.node,tgt:r._1.from.node,srcSide:Qs(Wr)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:Qs(qr)(t.ports)(r._1.from.node)(r._1.from.port),path:n}):N("Just",{edgeId:n.edge,src:r._1.from.node,tgt:r._1.to.node,srcSide:Qs(Wr)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:Qs(qr)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return w;g()})(t.paths)},yN=t=>e=>{const n=Et(e)(r=>{if(r.src===r.tgt)return[];if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return[];const o=Hr(r.tgt)(t.nodeToC),i=(()=>{if(o.tag==="Just")return le(o._1)(t.cGraph.cNodes);if(o.tag==="Nothing")return w;g()})(),a=Hr(r.src)(t.nodeToC),s=(()=>{if(a.tag==="Just")return le(a._1)(t.cGraph.cNodes);if(a.tag==="Nothing")return w;g()})(),u=(()=>{if(s.tag==="Just"){if(i.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(i._1.cGroup.tag==="Just")return N("Just",{srcGroup:s._1.cGroup._1,tgtGroup:i._1.cGroup._1,delta:0,weight:100});if(i._1.cGroup.tag==="Nothing")return w;g()}if(s._1.cGroup.tag==="Nothing")return w;g()}if(i.tag==="Nothing")return w;g()}if(s.tag==="Nothing")return w;g()})(),c=d=>h=>m=>{if(s.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(m.cGroup.tag==="Just")return d(m.hitbox.x)&&m.cGroup._1!==s._1.cGroup._1?N("Just",h(m.cGroup._1)(s._1.cGroup._1)):w;if(m.cGroup.tag==="Nothing")return w;g()}if(s._1.cGroup.tag==="Nothing")return w;g()}if(s.tag==="Nothing")return w;g()},_=wt(d=>le(d)(t.cGraph.cNodes))((()=>{const d=Bs(r.edgeId)(t.edgeToCs);if(d.tag==="Nothing")return[];if(d.tag==="Just")return d._1;g()})()),l=(()=>{if(s.tag==="Just"&&r.srcSide==="West"){const d=s._1;return wt(c(h=>h<d.hitbox.x)(h=>m=>({srcGroup:h,tgtGroup:m,delta:1,weight:100})))(_)}return[]})(),f=(()=>{if(s.tag==="Just"&&r.tgtSide==="East"){const d=s._1;return wt(c(h=>h>d.hitbox.x)(h=>m=>({srcGroup:m,tgtGroup:h,delta:1,weight:100})))(_)}return[]})();if(u.tag==="Nothing")return[];if(u.tag==="Just")return[u._1,...l,...f];g()});return{sameEdgeVerticalSegments:r=>o=>r.origin.tag==="Just"&&r.origin._1.tag==="SegmentOrigin"&&o.origin.tag==="Just"&&o.origin._1.tag==="SegmentOrigin"&&(()=>{const i=o.origin._1._1;return ne(a=>ln(vr)(a)(i.representedEdges),r.origin._1._1.representedEdges)})(),vsLNodePair:r=>o=>r.origin.tag==="Just"&&o.origin.tag==="Just"&&(r.origin._1.tag==="SegmentOrigin"?o.origin._1.tag==="NodeOrigin":r.origin._1.tag==="NodeOrigin"&&o.origin._1.tag==="SegmentOrigin"),edgeLengthEdges:r=>n}},xN=t=>e=>{const n=nt(4),r=hN(t),o=pN(t),i=_g(Y(s=>L(s.id,L(s.from.node,s.to.node)))(e.edges)),a=mN(t);return{nodes:Y(s=>{const u=Hr(s.node)(r);if(u.tag==="Just")return{...s,position:L(u._1/n,s.position._2)};if(u.tag==="Nothing")return s;g()})(e.nodes),edges:Y(s=>{const u=Bs(s.edge)(i),c=(()=>{if(u.tag==="Nothing")return s.segments;if(u.tag==="Just"){const _=Hr(u._1._1)(o),l=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;g()})(),f=Hr(u._1._2)(o),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return Wt((()=>{const h=s.reversed?d:l,m=s.reversed?l:d,p=s.segments.length;return x=>y=>{if(y.direction==="V"){const T=(()=>{if(x===0)return h;if(x===(p-1|0))return m;const v=fg(y.start)(a);if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})();return{...y,start:L(y.start._1+T,y.start._2),end:L(y.end._1+T,y.end._2)}}if(y.direction==="H")return{...y,start:L((()=>{if(x===0)return y.start._1+h;const T=fg(y.start)(a);if(T.tag==="Nothing")return y.start._1+0;if(T.tag==="Just")return y.start._1+T._1;g()})(),y.start._2),end:L((()=>{if(x===(p-1|0))return y.end._1+m;const T=fg(y.end)(a);if(T.tag==="Nothing")return y.end._1+0;if(T.tag==="Just")return y.end._1+T._1;g()})(),y.end._2)};g()}})())(s.segments)}g()})();return{...s,segments:c,bends:$e(_=>l=>_.end,c,At(1,c.length,c))}})(e.paths)}},wN=t=>e=>n=>r=>o=>i=>{const a=gg(o.nextId)(i._2.start)(i._2.end)(w)(t.edgeId),s=(()=>{if(i._1===0){if(e.tag==="Nothing")return a;if(e.tag==="Just")return{...a,ignoreSpacing:i._2.end._2<e._1.y?{...a.ignoreSpacing,down:!0}:i._2.end._2>e._1.y+e._1.height?{...a.ignoreSpacing,up:!0}:{...a.ignoreSpacing,up:!0,down:!0}};g()}return a})();return{nextId:o.nextId+1|0,segments:[...o.segments,(()=>{if(i._1===r){if(n.tag==="Nothing")return s;if(n.tag==="Just")return{...s,ignoreSpacing:i._2.start._2<n._1.y?{...s.ignoreSpacing,down:!0}:i._2.start._2>n._1.y+n._1.height?{...s.ignoreSpacing,up:!0}:{...s.ignoreSpacing,up:!0,down:!0}};g()}return s})()]}},yd=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...gg(i.nextId)(r.start)(L(r.start._1,o.down?n.y:n.y+n.height))(N("Just",e))(t.edgeId),aPort:N("Just",{node:t.src,side:o.side}),ignoreSpacing:o.down?{...nr,down:!0}:{...nr,up:!0}}]}),zs=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...gg(i.nextId)(r.end)(L(r.end._1,o.down?n.y:n.y+n.height))(N("Just",e))(t.edgeId),aPort:N("Just",{node:t.tgt,side:o.side}),ignoreSpacing:o.down?{...nr,down:!0}:{...nr,up:!0}}]}),TN=t=>e=>n=>{if(n.src===n.tgt)return e;const r=Hr(n.src)(t.nodeToC),o=Hr(n.tgt)(t.nodeToC),i=(()=>{if(r.tag==="Just"){const _=le(r._1)(t.cGraph.cNodes);return _.tag==="Just"?N("Just",_._1.hitbox):w}if(r.tag==="Nothing")return w;g()})(),a=(()=>{if(o.tag==="Just"){const _=le(o._1)(t.cGraph.cNodes);return _.tag==="Just"?N("Just",_._1.hitbox):w}if(o.tag==="Nothing")return w;g()})(),s=uN(n.path),u=J(wN(n)(i)(a)(s.length-1|0))(e)(Wt(_=>l=>L(_,l))(s));if(0<s.length){const _=(()=>{if(r.tag==="Just"&&i.tag==="Just"){if(n.srcSide==="North")return yd(n)(r._1)(i._1)(s[0])({side:Re,down:!0})(u);if(n.srcSide==="South")return yd(n)(r._1)(i._1)(s[0])({side:De,down:!1})(u)}return u})(),l=s.length-1|0;if(l>=0&&l<s.length&&o.tag==="Just"&&a.tag==="Just"){if(n.tgtSide==="North")return zs(n)(o._1)(a._1)(s[l])({side:Re,down:!0})(_);if(n.tgtSide==="South")return zs(n)(o._1)(a._1)(s[l])({side:De,down:!1})(_)}return _}const c=s.length-1|0;if(c>=0&&c<s.length&&o.tag==="Just"&&a.tag==="Just"){if(n.tgtSide==="North")return zs(n)(o._1)(a._1)(s[c])({side:Re,down:!0})(u);if(n.tgtSide==="South")return zs(n)(o._1)(a._1)(s[c])({side:De,down:!1})(u)}return u},NN=t=>e=>n=>gN(t)(J(TN(n))({nextId:0,segments:[]})(e).segments)(n),vN=t=>NN(t.edges)(md(t))(dN(lN(t.edges))(t.nodes)(_N())),$r=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},dg=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},lg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},JN=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},CN=t=>{const e=t.Eq0();return n=>r=>{const o=s=>{let u=s,c=!0,_;for(;c;){const l=u,f=Pt(d=>w,d=>h=>N("Just",{head:d,tail:h}),l.queue);if(f.tag==="Nothing"){c=!1,_=l;continue}if(f.tag==="Just"){const d=f._1.head;if((m=>{let p=m,x=!0,y;for(;x;){const T=p;if(T.tag==="Leaf"){x=!1,y=!1;continue}if(T.tag==="Node"){const v=t.compare(d)(T._3);if(v==="LT"){p=T._5;continue}if(v==="GT"){p=T._6;continue}if(v==="EQ"){x=!1,y=!0;continue}}g()}return y})(l.removedNodes)){u={...l,queue:f._1.tail};continue}const h=te(m=>!$r(m.eid)(l.removedEdges)&&(e.eq(m.src)(d)||e.eq(m.tgt)(d)))(r);if(h.tag==="Nothing"){u={...l,queue:f._1.tail};continue}if(h.tag==="Just"){const m=e.eq(h._1.src)(d)?h._1.tgt:h._1.src,p={...l,degree:it(t)(m)((()=>{const x=(y=>{let T=y,v=!0,b;for(;v;){const C=T;if(C.tag==="Leaf"){v=!1,b=w;continue}if(C.tag==="Node"){const S=t.compare(m)(C._3);if(S==="LT"){T=C._5;continue}if(S==="GT"){T=C._6;continue}if(S==="EQ"){v=!1,b=N("Just",C._4);continue}}g()}return b})(l.degree);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;g()})())(l.degree),removedNodes:it(t)(d)()(l.removedNodes),removedEdges:it(ut)(h._1.eid)()(l.removedEdges),record:[...l.record,{node:d,neighbour:m,viaSrc:e.eq(h._1.src)(d)}],queue:f._1.tail};if((()=>{const x=(T=>{let v=T,b=!0,C;for(;b;){const S=v;if(S.tag==="Leaf"){b=!1,C=w;continue}if(S.tag==="Node"){const P=t.compare(m)(S._3);if(P==="LT"){v=S._5;continue}if(P==="GT"){v=S._6;continue}if(P==="EQ"){b=!1,C=N("Just",S._4);continue}}g()}return C})(p.degree),y=T=>{let v=T,b=!0,C;for(;b;){const S=v;if(S.tag==="Leaf"){b=!1,C=!1;continue}if(S.tag==="Node"){const P=t.compare(m)(S._3);if(P==="LT"){v=S._5;continue}if(P==="GT"){v=S._6;continue}if(P==="EQ"){b=!1,C=!0;continue}}g()}return C};return(()=>{if(x.tag==="Nothing")return!1;if(x.tag==="Just")return x._1===1;g()})()&&!y(p.removedNodes)})()){u={...p,queue:[...p.queue,m]};continue}u=p;continue}}g()}return _},i=J(s=>u=>zt(t)(Ce)(u.src)(1)(zt(t)(Ce)(u.tgt)(1)(s)))(Q)(r),a=o({degree:i,removedNodes:Q,removedEdges:Q,record:[],queue:lt(s=>{const u=(c=>{let _=c,l=!0,f;for(;l;){const d=_;if(d.tag==="Leaf"){l=!1,f=w;continue}if(d.tag==="Node"){const h=t.compare(s)(d._3);if(h==="LT"){_=d._5;continue}if(h==="GT"){_=d._6;continue}if(h==="EQ"){l=!1,f=N("Just",d._4);continue}}g()}return f})(i);if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1===1;g()},n)});return{coreNodes:lt(s=>!(u=>{let c=u,_=!0,l;for(;_;){const f=c;if(f.tag==="Leaf"){_=!1,l=!1;continue}if(f.tag==="Node"){const d=t.compare(s)(f._3);if(d==="LT"){c=f._5;continue}if(d==="GT"){c=f._6;continue}if(d==="EQ"){_=!1,l=!0;continue}}g()}return l})(a.removedNodes),n),coreEdges:lt(s=>!$r(s.eid)(a.removedEdges),r),removed:a.record}}},bN=t=>e=>n=>J(r=>o=>{const i=o.neighbour,a=(()=>{const s=(u=>{let c=u,_=!0,l;for(;_;){const f=c;if(f.tag==="Leaf"){_=!1,l=w;continue}if(f.tag==="Node"){const d=t.compare(i)(f._3);if(d==="LT"){c=f._5;continue}if(d==="GT"){c=f._6;continue}if(d==="EQ"){_=!1,l=N("Just",f._4);continue}}g()}return l})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})();return it(t)(o.node)(o.viaSrc?a-1|0:a+1|0)(r)})(n)(re(e)),hg=t=>{const e=t.Eq0();return n=>r=>o=>{const i={...o,treeNode:it(t)(r)()(o.treeNode)};return J(a=>s=>{if($r(s.eid)(a.st.edgeVisited))return a;const u={...a.st,edgeVisited:it(ut)(s.eid)()(a.st.edgeVisited)},c=e.eq(s.src)((()=>{const _=s.src,l=d=>{let h=d,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const y=t.compare(_)(x._3);if(y==="LT"){h=x._5;continue}if(y==="GT"){h=x._6;continue}if(y==="EQ"){m=!1,p=!0;continue}}g()}return p},f=s.tgt;return l(u.treeNode)&&!(d=>{let h=d,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const y=t.compare(f)(x._3);if(y==="LT"){h=x._5;continue}if(y==="GT"){h=x._6;continue}if(y==="EQ"){m=!1,p=!0;continue}}g()}return p})(u.treeNode)})()?s.src:(()=>{const _=s.tgt,l=d=>{let h=d,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const y=t.compare(_)(x._3);if(y==="LT"){h=x._5;continue}if(y==="GT"){h=x._6;continue}if(y==="EQ"){m=!1,p=!0;continue}}g()}return p},f=s.src;return l(u.treeNode)&&!(d=>{let h=d,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const y=t.compare(f)(x._3);if(y==="LT"){h=x._5;continue}if(y==="GT"){h=x._6;continue}if(y==="EQ"){m=!1,p=!0;continue}}g()}return p})(u.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if($r(s.eid)(u.treeEdge)){if((l=>{let f=l,d=!0,h;for(;d;){const m=f;if(m.tag==="Leaf"){d=!1,h=!1;continue}if(m.tag==="Node"){const p=t.compare(c)(m._3);if(p==="LT"){f=m._5;continue}if(p==="GT"){f=m._6;continue}if(p==="EQ"){d=!1,h=!0;continue}}g()}return h})(u.treeNode))return{...a,st:u};const _=hg(t)(n)(c)(u);return{count:a.count+_.count|0,st:_.st}}if((()=>{const _=f=>{let d=f,h=!0,m;for(;h;){const p=d;if(p.tag==="Leaf"){h=!1,m=!1;continue}if(p.tag==="Node"){const x=t.compare(c)(p._3);if(x==="LT"){d=p._5;continue}if(x==="GT"){d=p._6;continue}if(x==="EQ"){h=!1,m=!0;continue}}g()}return m},l=s.tgt;return!_(u.treeNode)&&(()=>{const f=(m=>{let p=m,x=!0,y;for(;x;){const T=p;if(T.tag==="Leaf"){x=!1,y=w;continue}if(T.tag==="Node"){const v=t.compare(l)(T._3);if(v==="LT"){p=T._5;continue}if(v==="GT"){p=T._6;continue}if(v==="EQ"){x=!1,y=N("Just",T._4);continue}}g()}return y})(u.layer),d=s.src,h=(m=>{let p=m,x=!0,y;for(;x;){const T=p;if(T.tag==="Leaf"){x=!1,y=w;continue}if(T.tag==="Node"){const v=t.compare(d)(T._3);if(v==="LT"){p=T._5;continue}if(v==="GT"){p=T._6;continue}if(v==="EQ"){x=!1,y=N("Just",T._4);continue}}g()}return y})(u.layer);if(f.tag==="Nothing"){if(h.tag==="Nothing")return s.delta===0;if(h.tag==="Just")return s.delta===-h._1;g()}if(f.tag==="Just"){if(h.tag==="Nothing")return s.delta===(f._1-0|0);if(h.tag==="Just")return s.delta===(f._1-h._1|0)}g()})()})()){const _=hg(t)(n)(c)({...u,treeEdge:it(ut)(s.eid)()(u.treeEdge)});return{count:a.count+_.count|0,st:_.st}}return{...a,st:u}})({count:1,st:i})(lt(a=>(e.eq(a.src)(r)||e.eq(a.tgt)(r))&&!$r(a.eid)(i.edgeVisited),n))}},Ms=t=>e=>n=>r=>{const o=r.src,i=(f=>{let d=f,h=!0,m;for(;h;){const p=d;if(p.tag==="Leaf"){h=!1,m=w;continue}if(p.tag==="Node"){const x=t.compare(o)(p._3);if(x==="LT"){d=p._5;continue}if(x==="GT"){d=p._6;continue}if(x==="EQ"){h=!1,m=N("Just",p._4);continue}}g()}return m})(e.poID),a=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})(),s=r.tgt,u=(f=>{let d=f,h=!0,m;for(;h;){const p=d;if(p.tag==="Leaf"){h=!1,m=w;continue}if(p.tag==="Node"){const x=t.compare(s)(p._3);if(x==="LT"){d=p._5;continue}if(x==="GT"){d=p._6;continue}if(x==="EQ"){h=!1,m=N("Just",p._4);continue}}g()}return m})(e.poID),c=(()=>{if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()})(),_=(f=>{let d=f,h=!0,m;for(;h;){const p=d;if(p.tag==="Leaf"){h=!1,m=w;continue}if(p.tag==="Node"){const x=t.compare(n)(p._3);if(x==="LT"){d=p._5;continue}if(x==="GT"){d=p._6;continue}if(x==="EQ"){h=!1,m=N("Just",p._4);continue}}g()}return m})(e.poID),l=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;g()})();return(()=>{const f=r.src,d=(h=>{let m=h,p=!0,x;for(;p;){const y=m;if(y.tag==="Leaf"){p=!1,x=w;continue}if(y.tag==="Node"){const T=t.compare(f)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){p=!1,x=N("Just",y._4);continue}}g()}return x})(e.lowestPoID);return(()=>{if(d.tag==="Nothing")return 0<=l;if(d.tag==="Just")return d._1<=l;g()})()&&(()=>{const h=r.tgt;return l<=a&&(()=>{const m=(p=>{let x=p,y=!0,T;for(;y;){const v=x;if(v.tag==="Leaf"){y=!1,T=w;continue}if(v.tag==="Node"){const b=t.compare(h)(v._3);if(b==="LT"){x=v._5;continue}if(b==="GT"){x=v._6;continue}if(b==="EQ"){y=!1,T=N("Just",v._4);continue}}g()}return T})(e.lowestPoID);return(()=>{if(m.tag==="Nothing")return 0<=l;if(m.tag==="Just")return m._1<=l;g()})()&&l<=c})()})()})()?a>=c:a<c},kN=t=>{const e=ge(t)(Qt);return n=>({layer:e(Y(r=>L(r,0))(n)),treeNode:Q,treeEdge:Q,poID:Q,lowestPoID:Q,cutvalue:Q,postOrder:1,edgeVisited:Q})},LN=t=>e=>n=>J(r=>o=>{if((()=>{const _=o.src,l=h=>{let m=h,p=!0,x;for(;p;){const y=m;if(y.tag==="Leaf"){p=!1,x=!1;continue}if(y.tag==="Node"){const T=t.compare(_)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){p=!1,x=!0;continue}}g()}return x},f=o.tgt,d=h=>{let m=h,p=!0,x;for(;p;){const y=m;if(y.tag==="Leaf"){p=!1,x=!1;continue}if(y.tag==="Node"){const T=t.compare(f)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){p=!1,x=!0;continue}}g()}return x};return l(n.treeNode)===d(n.treeNode)})())return r;const i=o.tgt,a=(_=>{let l=_,f=!0,d;for(;f;){const h=l;if(h.tag==="Leaf"){f=!1,d=w;continue}if(h.tag==="Node"){const m=t.compare(i)(h._3);if(m==="LT"){l=h._5;continue}if(m==="GT"){l=h._6;continue}if(m==="EQ"){f=!1,d=N("Just",h._4);continue}}g()}return d})(n.layer),s=o.src,u=(_=>{let l=_,f=!0,d;for(;f;){const h=l;if(h.tag==="Leaf"){f=!1,d=w;continue}if(h.tag==="Node"){const m=t.compare(s)(h._3);if(m==="LT"){l=h._5;continue}if(m==="GT"){l=h._6;continue}if(m==="EQ"){f=!1,d=N("Just",h._4);continue}}g()}return d})(n.layer),c=(()=>{if(a.tag==="Nothing"){if(u.tag==="Nothing")return-o.delta;if(u.tag==="Just")return-u._1-o.delta|0;g()}if(a.tag==="Just"){if(u.tag==="Nothing")return(a._1-0|0)-o.delta|0;if(u.tag==="Just")return(a._1-u._1|0)-o.delta|0}g()})();return c<r.slack?{edge:N("Just",o),slack:c}:r})({edge:w,slack:1e9})(e).edge,SN=t=>{const e=ge(t)(Qt);return n=>r=>{const o=J(i=>a=>dg(i)((()=>{const s=(u=>{let c=u,_=!0,l;for(;_;){const f=c;if(f.tag==="Leaf"){_=!1,l=w;continue}if(f.tag==="Node"){const d=t.compare(a)(f._3);if(d==="LT"){c=f._5;continue}if(d==="GT"){c=f._6;continue}if(d==="EQ"){_=!1,l=N("Just",f._4);continue}}g()}return l})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(1e9)(n);return e(Y(i=>L(i,(()=>{const a=(s=>{let u=s,c=!0,_;for(;c;){const l=u;if(l.tag==="Leaf"){c=!1,_=w;continue}if(l.tag==="Node"){const f=t.compare(i)(l._3);if(f==="LT"){u=l._5;continue}if(f==="GT"){u=l._6;continue}if(f==="EQ"){c=!1,_=N("Just",l._4);continue}}g()}return _})(r);if(a.tag==="Nothing")return-o;if(a.tag==="Just")return a._1-o|0;g()})()))(n))}},xd=t=>{const e=t.Eq0();return n=>r=>o=>{const i=J(s=>u=>{const c=xd(t)(n)(e.eq(u.src)(r)?u.tgt:u.src)({...s.st,edgeVisited:it(ut)(u.eid)()(s.st.edgeVisited)});return{lowest:dg(s.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:o})(lt(s=>$r(s.eid)(o.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!$r(s.eid)(o.edgeVisited),n)),a=dg(i.lowest)(i.st.postOrder);return{lowest:a,st:{...i.st,poID:it(t)(r)(i.st.postOrder)(i.st.poID),lowestPoID:it(t)(r)(a)(i.st.lowestPoID),postOrder:i.st.postOrder+1|0}}}},wd=t=>{const e=xd(t);return n=>r=>o=>0<n.length?e(r)(n[0])({...o,edgeVisited:Q,postOrder:1,poID:Q,lowestPoID:Q}).st:o},EN=t=>{const e=t.Eq0();return n=>r=>o=>lt(i=>$r(i.eid)(r.treeEdge)&&(e.eq(i.src)(o)||e.eq(i.tgt)(o)),n)},PN=t=>e=>te(n=>{const r=lg(n.eid)(e.cutvalue);return $r(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),Td=t=>{const e=hg(t);return n=>r=>o=>{const i=0<n.length?N("Just",n[0]):w;if(i.tag==="Nothing")return o;if(i.tag==="Just"){const a=e(r)(i._1)({...o,edgeVisited:Q,treeNode:Q,treeEdge:Q});if(a.count>=n.length)return a.st;const s=LN(t)(r)(a.st);if(s.tag==="Nothing")return a.st;if(s.tag==="Just"){const u=s._1.tgt,c=(h=>{let m=h,p=!0,x;for(;p;){const y=m;if(y.tag==="Leaf"){p=!1,x=w;continue}if(y.tag==="Node"){const T=t.compare(u)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){p=!1,x=N("Just",y._4);continue}}g()}return x})(a.st.layer),_=s._1.src,l=(h=>{let m=h,p=!0,x;for(;p;){const y=m;if(y.tag==="Leaf"){p=!1,x=w;continue}if(y.tag==="Node"){const T=t.compare(_)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){p=!1,x=N("Just",y._4);continue}}g()}return x})(a.st.layer),f=(()=>{if(c.tag==="Nothing"){if(l.tag==="Nothing")return-s._1.delta;if(l.tag==="Just")return-l._1-s._1.delta|0;g()}if(c.tag==="Just"){if(l.tag==="Nothing")return(c._1-0|0)-s._1.delta|0;if(l.tag==="Just")return(c._1-l._1|0)-s._1.delta|0}g()})(),d=(()=>{const h=s._1.tgt;return(m=>{let p=m,x=!0,y;for(;x;){const T=p;if(T.tag==="Leaf"){x=!1,y=!1;continue}if(T.tag==="Node"){const v=t.compare(h)(T._3);if(v==="LT"){p=T._5;continue}if(v==="GT"){p=T._6;continue}if(v==="EQ"){x=!1,y=!0;continue}}g()}return y})(a.st.treeNode)})()?-f:f;return Td(t)(n)(r)({...a.st,layer:J(h=>m=>(p=>{let x=p,y=!0,T;for(;y;){const v=x;if(v.tag==="Leaf"){y=!1,T=!1;continue}if(v.tag==="Node"){const b=t.compare(m)(v._3);if(b==="LT"){x=v._5;continue}if(b==="GT"){x=v._6;continue}if(b==="EQ"){y=!1,T=!0;continue}}g()}return T})(a.st.treeNode)?it(t)(m)((()=>{const p=(x=>{let y=x,T=!0,v;for(;T;){const b=y;if(b.tag==="Leaf"){T=!1,v=w;continue}if(b.tag==="Node"){const C=t.compare(m)(b._3);if(C==="LT"){y=b._5;continue}if(C==="GT"){y=b._6;continue}if(C==="EQ"){T=!1,v=N("Just",b._4);continue}}g()}return v})(a.st.layer);if(p.tag==="Nothing")return 0+d|0;if(p.tag==="Just")return p._1+d|0;g()})())(h):h)(a.st.layer)(n)})}}g()}},GN=t=>e=>n=>r=>J(o=>i=>{if(Ms(t)(r)(i.src)(n)&&!Ms(t)(r)(i.tgt)(n)){const a=i.tgt,s=(l=>{let f=l,d=!0,h;for(;d;){const m=f;if(m.tag==="Leaf"){d=!1,h=w;continue}if(m.tag==="Node"){const p=t.compare(a)(m._3);if(p==="LT"){f=m._5;continue}if(p==="GT"){f=m._6;continue}if(p==="EQ"){d=!1,h=N("Just",m._4);continue}}g()}return h})(r.layer),u=i.src,c=(l=>{let f=l,d=!0,h;for(;d;){const m=f;if(m.tag==="Leaf"){d=!1,h=w;continue}if(m.tag==="Node"){const p=t.compare(u)(m._3);if(p==="LT"){f=m._5;continue}if(p==="GT"){f=m._6;continue}if(p==="EQ"){d=!1,h=N("Just",m._4);continue}}g()}return h})(r.layer),_=(()=>{if(s.tag==="Nothing"){if(c.tag==="Nothing")return-i.delta;if(c.tag==="Just")return-c._1-i.delta|0;g()}if(s.tag==="Just"){if(c.tag==="Nothing")return(s._1-0|0)-i.delta|0;if(c.tag==="Just")return(s._1-c._1|0)-i.delta|0}g()})();if(_<o.slack)return{edge:N("Just",i),slack:_}}return o})({edge:w,slack:1e9})(e).edge,AN=t=>{const e=t.Eq0();return n=>r=>o=>i=>{const a=i.tgt,s=i.src;return J(u=>c=>{if((()=>{const _=lg(c.eid)(r.cutvalue);if(_.tag==="Just")return!0;if(_.tag==="Nothing")return!1;g()})()){const _=lg(c.eid)(r.cutvalue),l=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;g()})();return e.eq(s)(c.src)||e.eq(a)(c.tgt)?u-(l-c.weight):u+(l-c.weight)}return e.eq(o)(s)?e.eq(c.src)(o)?u+c.weight:u-c.weight:e.eq(c.src)(o)?u-c.weight:u+c.weight})(i.weight)(lt(u=>u.eid!==i.eid&&(e.eq(u.src)(o)||e.eq(u.tgt)(o)),n))}},RN=t=>{const e=AN(t);return n=>r=>o=>{const i=(a,s,u)=>{const c=(_=>{let l=_,f=!0,d;for(;f;){const h=l;if(h.tag==="Leaf"){f=!1,d=w;continue}if(h.tag==="Node"){const m=t.compare(a)(h._3);if(m==="LT"){l=h._5;continue}if(m==="GT"){l=h._6;continue}if(m==="EQ"){f=!1,d=N("Just",h._4);continue}}g()}return d})(u);if(c.tag==="Just")return it(t)(a)(lt(_=>_.eid!==s.eid,c._1))(u);if(c.tag==="Nothing")return u;g()};return(a=>s=>{let u=a,c=s,_=!0,l;for(;_;){const f=u,d=c,h=(p=>{let x=p,y=!0,T;for(;y;){const v=x;if(v.tag==="Leaf"){y=!1,T=w;continue}if(v.tag==="Node"){const b=t.compare(d)(v._3);if(b==="LT"){x=v._5;continue}if(b==="GT"){x=v._6;continue}if(b==="EQ"){y=!1,T=N("Just",v._4);continue}}g()}return T})(f.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)(d)?m[0].tgt:m[0].src;u={unknown:i(d,m[0],i(p,m[0],f.unknown)),cutvalue:it(ut)(m[0].eid)(e(n)(f)(d)(m[0]))(f.cutvalue)},c=p;continue}_=!1,l=f}return l})(r)(o)}},Nd=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:c=>_=>c.delta===_.delta&&c.eid===_.eid&&n.eq(c.src)(_.src)&&e.eq(c.tgt)(_.tgt)&&c.weight===_.weight},o={compare:c=>_=>{const l=ut.compare(c.delta)(_.delta);if(l==="LT"||l==="GT"||l!=="EQ")return l;const f=ut.compare(c.eid)(_.eid);if(f==="LT"||f==="GT"||f!=="EQ")return f;const d=t.compare(c.src)(_.src);if(d==="LT"||d==="GT"||d!=="EQ")return d;const h=t.compare(c.tgt)(_.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const m=at.compare(c.weight)(_.weight);return m==="LT"||m==="GT"||m!=="EQ"?m:un},Eq0:()=>r},i=J(c=>_=>it(o)(_)()(c))(Q),a=EN(t),s=ge(t)(Qt),u=RN(t);return c=>_=>l=>{const f={unknown:s(Y(d=>L(d,Ot(pn.foldr,i(a(_)(l)(d)))))(c)),cutvalue:Q};return{...l,cutvalue:J(u(_))(f)(lt(d=>{const h=(m=>{let p=m,x=!0,y;for(;x;){const T=p;if(T.tag==="Leaf"){x=!1,y=w;continue}if(T.tag==="Node"){const v=t.compare(d)(T._3);if(v==="LT"){p=T._5;continue}if(v==="GT"){p=T._6;continue}if(v==="EQ"){x=!1,y=N("Just",T._4);continue}}g()}return y})(f.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;g()},c)).cutvalue}}},DN=t=>{const e=wd(t),n=Nd(t);return r=>o=>i=>a=>s=>{const u={...s,treeEdge:it(ut)(a.eid)()(Li(ut)(i.eid)(s.treeEdge))},c=a.tgt,_=(m=>{let p=m,x=!0,y;for(;x;){const T=p;if(T.tag==="Leaf"){x=!1,y=w;continue}if(T.tag==="Node"){const v=t.compare(c)(T._3);if(v==="LT"){p=T._5;continue}if(v==="GT"){p=T._6;continue}if(v==="EQ"){x=!1,y=N("Just",T._4);continue}}g()}return y})(u.layer),l=a.src,f=(m=>{let p=m,x=!0,y;for(;x;){const T=p;if(T.tag==="Leaf"){x=!1,y=w;continue}if(T.tag==="Node"){const v=t.compare(l)(T._3);if(v==="LT"){p=T._5;continue}if(v==="GT"){p=T._6;continue}if(v==="EQ"){x=!1,y=N("Just",T._4);continue}}g()}return y})(u.layer),d=(()=>{if(_.tag==="Nothing"){if(f.tag==="Nothing")return-a.delta;if(f.tag==="Just")return-f._1-a.delta|0;g()}if(_.tag==="Just"){if(f.tag==="Nothing")return(_._1-0|0)-a.delta|0;if(f.tag==="Just")return(_._1-f._1|0)-a.delta|0}g()})(),h=Ms(t)(u)(a.tgt)(i)?d:-d;return n(r)(o)(e(r)(o)({...u,layer:J(m=>p=>Ms(t)(u)(p)(i)?m:it(t)(p)((()=>{const x=(y=>{let T=y,v=!0,b;for(;v;){const C=T;if(C.tag==="Leaf"){v=!1,b=w;continue}if(C.tag==="Node"){const S=t.compare(p)(C._3);if(S==="LT"){T=C._5;continue}if(S==="GT"){T=C._6;continue}if(S==="EQ"){v=!1,b=N("Just",C._4);continue}}g()}return b})(u.layer);if(x.tag==="Nothing")return 0+h|0;if(x.tag==="Just")return x._1+h|0;g()})())(m))(u.layer)(r)}))}},FN=t=>{const e=DN(t);return n=>r=>o=>i=>(a=>s=>{let u=a,c=s,_=!0,l;for(;_;){const f=u,d=c;if(f===0){_=!1,l=d;continue}const h=PN(o)(d);if(h.tag==="Nothing"){_=!1,l=d;continue}if(h.tag==="Just"){const m=GN(t)(o)(h._1)(d);if(m.tag==="Nothing"){_=!1,l=d;continue}if(m.tag==="Just"){u=f-1|0,c=e(r)(o)(h._1)(m._1)(d);continue}}g()}return l})(n)(i)},IN=t=>{const e=Nd(t),n=wd(t),r=Td(t);return o=>i=>a=>e(o)(i)(n(o)(i)(r(o)(i)(a)))},vd=t=>e=>J(n=>r=>zt(t)(we)(e(r))([r])(n))(Q),BN=t=>{const e=ge(t)(Qt);return n=>r=>o=>{const i=u=>c=>_=>l=>{let f=u,d=c,h=_,m=l,p=!0,x;for(;p;){const y=f,T=d,v=h,b=m,C=Pt(S=>w,S=>P=>N("Just",{head:S,tail:P}),v);if(C.tag==="Nothing"){p=!1,x=b;continue}if(C.tag==="Just"){const S=C._1.head,P=(E=>{let R=E,et=!0,rt;for(;et;){const $=R;if($.tag==="Leaf"){et=!1,rt=w;continue}if($.tag==="Node"){const X=t.compare(S)($._3);if(X==="LT"){R=$._5;continue}if(X==="GT"){R=$._6;continue}if(X==="EQ"){et=!1,rt=N("Just",$._4);continue}}g()}return rt})(b.layer),F=(()=>{if(P.tag==="Nothing")return 0;if(P.tag==="Just")return P._1;g()})(),W=J(E=>R=>{const et=R.tgt,rt=(X=>{let V=X,D=!0,B;for(;D;){const I=V;if(I.tag==="Leaf"){D=!1,B=w;continue}if(I.tag==="Node"){const M=t.compare(et)(I._3);if(M==="LT"){V=I._5;continue}if(M==="GT"){V=I._6;continue}if(M==="EQ"){D=!1,B=N("Just",I._4);continue}}g()}return B})(E.incident),$=(()=>{if(rt.tag==="Nothing")return-1;if(rt.tag==="Just")return rt._1-1|0;g()})();return{st:{...E.st,layer:it(t)(R.tgt)(JN((()=>{const X=R.tgt,V=(D=>{let B=D,I=!0,M;for(;I;){const j=B;if(j.tag==="Leaf"){I=!1,M=w;continue}if(j.tag==="Node"){const z=t.compare(X)(j._3);if(z==="LT"){B=j._5;continue}if(z==="GT"){B=j._6;continue}if(z==="EQ"){I=!1,M=N("Just",j._4);continue}}g()}return M})(E.st.layer);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1;g()})())(F+R.delta|0))(E.st.layer)},incident:it(t)(R.tgt)($)(E.incident),queue:$===0?[...E.queue,R.tgt]:E.queue}})({st:b,incident:T,queue:C._1.tail})((()=>{const E=(R=>{let et=R,rt=!0,$;for(;rt;){const X=et;if(X.tag==="Leaf"){rt=!1,$=w;continue}if(X.tag==="Node"){const V=t.compare(S)(X._3);if(V==="LT"){et=X._5;continue}if(V==="GT"){et=X._6;continue}if(V==="EQ"){rt=!1,$=N("Just",X._4);continue}}g()}return $})(y);if(E.tag==="Nothing")return[];if(E.tag==="Just")return E._1;g()})());f=y,d=W.incident,h=W.queue,m=W.st;continue}g()}return x},a=vd(t)(u=>u.tgt)(r),s=e(Y(u=>L(u,(()=>{const c=(_=>{let l=_,f=!0,d;for(;f;){const h=l;if(h.tag==="Leaf"){f=!1,d=w;continue}if(h.tag==="Node"){const m=t.compare(u)(h._3);if(m==="LT"){l=h._5;continue}if(m==="GT"){l=h._6;continue}if(m==="EQ"){f=!1,d=N("Just",h._4);continue}}g()}return d})(a);if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1.length;g()})()))(n));return i(vd(t)(u=>u.src)(r))(s)(lt(u=>{const c=(_=>{let l=_,f=!0,d;for(;f;){const h=l;if(h.tag==="Leaf"){f=!1,d=w;continue}if(h.tag==="Node"){const m=t.compare(u)(h._3);if(m==="LT"){l=h._5;continue}if(m==="GT"){l=h._6;continue}if(m==="EQ"){f=!1,d=N("Just",h._4);continue}}g()}return d})(s);if(c.tag==="Nothing")return!0;if(c.tag==="Just")return c._1===0;g()},n))(o)}},QN=t=>{const e=kN(t),n=BN(t),r=IN(t),o=FN(t);return i=>a=>{const s=n(i)(a)(e(i));return a.length===0?s.layer:o(4*i.length|0)(i)(a)(r(i)(a)(s)).layer}},Jd=t=>{const e=SN(t),n=QN(t),r=CN(t);return o=>i=>{if(o.length===0)return Q;if(o.length<40)return e(o)(n(o)(i));const a=r(o)(i);return e(o)(bN(t)(a.removed)(n(a.coreNodes)(a.coreEdges)))}},Cd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},pg=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},zN=Jd(ut),xa=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}),MN=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=nt((()=>{const o=Cd(n.cGroup._1)(t);if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})());return Sn(n.id)(o=>({...o,hitbox:{...o.hitbox,x:r+o.cGroupOffset.x}}))(e)}g()},ON=t=>e=>({...e,cGraph:J(MN(t))(e.cGraph)((()=>{const n=e.cGraph;return wt(r=>le(r)(n.cNodes))(n.cNodeOrder)})())}),WN=t=>e=>n=>r=>o=>{const i=he(ts(e.cGroupOffset.x-t.cGroupOffset.x));return xa({src:o.nextNodeId,tgt:r,delta:pg(0)(-i),weight:1})(xa({src:o.nextNodeId,tgt:n,delta:pg(0)(i),weight:1})({...o,nodes:[...o.nodes,o.nextNodeId],nextNodeId:o.nextNodeId+1|0}))},qN=t=>e=>n=>r=>o=>i=>a=>{const s=pg(0)(he(ts(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)?WN(n)(r)(o)(i)(a):xa({src:o,tgt:i,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(a)},HN=t=>e=>n=>r=>o=>{const i=le(o)(e.cGraph.cNodes);if(i.tag==="Nothing")return r;if(i.tag==="Just")return(n.cGroup.tag==="Nothing"?i._1.cGroup.tag==="Nothing":n.cGroup.tag==="Just"&&i._1.cGroup.tag==="Just"&&n.cGroup._1===i._1.cGroup._1)?r:n.cGroup.tag==="Just"&&i._1.cGroup.tag==="Just"?qN(t)(e)(n)(i._1)(n.cGroup._1)(i._1.cGroup._1)(r):r;g()},$N=t=>e=>n=>r=>J(HN(t)(e)(r))(n)(r.constraints),YN=t=>e=>xa({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),VN=t=>{const e=J(o=>i=>zt(ut)(Ce)(i.tgt)(1)(o))(Q)(t.edges),n=lt(o=>{const i=Cd(o)(e);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return i._1===0;g()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return J(o=>i=>xa({src:r,tgt:i,delta:1,weight:0})(o))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},XN=t=>e=>{const n=VN(J(YN)(J($N(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return wt(o=>le(o)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},UN=t=>e=>{const n=XN(t)(e);return ON(zN(n.nodes)(n.edges))(e)},bd=t=>t,Ne=bd("H"),xe=bd("V"),KN=t=>L(t._2,t._1),kd=t=>({...t,position:L(t.position._2,t.position._1),size:L(t.size._2,t.size._1)}),ZN=t=>({start:L(t.start._2,t.start._1),end:L(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return xe;if(t.direction==="V")return Ne;g()})()}),Ld=t=>({...t,segments:Y(ZN)(t.segments),bends:Y(KN)(t.bends)}),jN=t=>({nodes:Y(kd)(t.nodes),edges:t.edges,paths:Y(Ld)(t.paths),ports:t.ports}),tv={nodeNode:8,edgeNode:4,edgeEdge:10},ev=t=>e=>({horizontalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r)||n.ignoreSpacing.right||r.ignoreSpacing.left)return 0;const o=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?o?t.edgeEdge:t.edgeNode:o?t.edgeNode:t.nodeNode},verticalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r))return 1;if(n.hitbox.y<=r.hitbox.y?n.ignoreSpacing.down||r.ignoreSpacing.up:n.ignoreSpacing.up||r.ignoreSpacing.down)return 0;const o=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?o?t.edgeEdge:t.edgeNode:o?t.edgeNode:t.nodeNode}}),nv=t=>e=>UN(e),rv=t=>e=>n=>{const r=jN(n),o=vN(r),i=yN(o)(md(r)),a=xN(id(ig)(OT({...qT(o.cGraph),compactionAlgorithm:N("Just",nv()(i)),constraintAlgorithm:N("Just",nN(e.edgeEdge)),spacingsHandler:ev(e)(i)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:Y(kd)(a.nodes),edges:Y(Ld)(a.edges)}},Sd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Ed=t=>Fe(3)(t)==="$d:",ov=t=>e=>n=>J(r=>o=>{const i=Sd(o.from.node)(t),a=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})(),s=Sd(o.to.node)(t),u=(()=>{if(s.tag==="Nothing")return-a;if(s.tag==="Just")return s._1-a|0;g()})();if(u<=1)return{...r,edges:[...r.edges,o],chains:[...r.chains,{edgeId:o.id,nodes:[o.from.node,o.to.node]}]};const c=o.id,_=Y(f=>"$d:"+c+":"+ae(f))(Ut(1,u-1|0)),l=[o.from.node,..._,o.to.node];return{...r,layers:J(f=>d=>{const h=d._2,m=x2(a+d._1|0)(p=>[...p,h])(f);if(m.tag==="Nothing")return f;if(m.tag==="Just")return m._1;g()})(r.layers)($e(bn,Ut(1,u-1|0),_)),edges:[...r.edges,...$e(f=>d=>({id:c+":"+f+"->"+d,from:{node:f,port:o.from.port},to:{node:d,port:o.to.port},label:w}),l,At(1,l.length,l))],chains:[...r.chains,{edgeId:o.id,nodes:l}]}})({layers:n,edges:[],chains:[]})(e),Pd=t=>t,Ii=ge(ut)(Qt),Zt=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Gd=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ct=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},bt=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Bi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},iv=t=>e=>{const n=ut.compare(t._1)(e._1);return n==="LT"?ze:n==="GT"?Me:ut.compare(t._2)(e._2)},Qi=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},av=(()=>{const t=wn.unfoldr(gr);return e=>t(Tn("IterNode",e,ur))})(),sv=t=>t,Ad=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},uv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Os=Pd("Regular"),Ws=Pd("Critical"),Rd=t=>e=>{const n=J(a=>s=>it(A)(s.node)(s)(a))(Q)(e),r=1.25*nt(4),o=(a,s,u)=>(c=>_=>l=>{let f=c,d=_,h=l,m=!0,p;for(;m;){const x=f,y=d,T=h;if(T.critical){m=!1,p=T;continue}const v=Pt(C=>w,C=>S=>N("Just",{head:C,tail:S}),x),b=Pt(C=>w,C=>S=>N("Just",{head:C,tail:S}),y);if(v.tag==="Just"&&b.tag==="Just"){const C=v._1.head>b._1.head-a&&v._1.head<b._1.head+a?{...T,critical:!0}:v._1.head>b._1.head-r&&v._1.head<b._1.head+r?{...T,conflicts:T.conflicts+1|0}:T;if(C.critical){m=!1,p=C;continue}if(v._1.head<=b._1.head){f=v._1.tail,d=y,h=C;continue}f=x,d=b._1.tail,h=C;continue}m=!1,p=T}return p})(s)(u)({conflicts:0,critical:!1}),i=(a,s,u)=>{if(bt(J(bt)(-1e18)(s.incoming))(J(bt)(-1e18)(s.outgoing))-Ct(J(Ct)(1e18)(s.incoming))(J(Ct)(1e18)(s.outgoing))<.001||bt(J(bt)(-1e18)(u.incoming))(J(bt)(-1e18)(u.outgoing))-Ct(J(Ct)(1e18)(u.incoming))(J(Ct)(1e18)(u.outgoing))<.001)return[];const c=o(a,s.outgoing,u.incoming),_=o(a,u.outgoing,s.incoming);if(c.critical||_.critical)return[...c.critical?[{src:u.id,tgt:s.id,weight:1,kind:Ws}]:[],..._.critical?[{src:s.id,tgt:u.id,weight:1,kind:Ws}]:[]];const l=Ct(J(Ct)(1e18)(s.incoming))(J(Ct)(1e18)(s.outgoing)),f=bt(J(bt)(-1e18)(s.incoming))(J(bt)(-1e18)(s.outgoing)),d=Ct(J(Ct)(1e18)(u.incoming))(J(Ct)(1e18)(u.outgoing)),h=bt(J(bt)(-1e18)(u.incoming))(J(bt)(-1e18)(u.outgoing)),m=(1*c.conflicts|0)+(16*(J(x=>y=>y>h?x:y>=d?x+1|0:x)(0)(s.outgoing)+J(x=>y=>y>f?x:y>=l?x+1|0:x)(0)(u.incoming)|0)|0)|0,p=(1*_.conflicts|0)+(16*(J(x=>y=>y>f?x:y>=l?x+1|0:x)(0)(u.outgoing)+J(x=>y=>y>h?x:y>=d?x+1|0:x)(0)(s.incoming)|0)|0)|0;return m<p?[{src:s.id,tgt:u.id,weight:p-m|0,kind:Os}]:m>p?[{src:u.id,tgt:s.id,weight:m-p|0,kind:Os}]:m>0?[{src:s.id,tgt:u.id,weight:0,kind:Os},{src:u.id,tgt:s.id,weight:0,kind:Os}]:[]};return J(a=>s=>J(u=>c=>it(A)(c._1)(c._2)(u))(a)((()=>{const u=J(E=>R=>{const et=R.edge.from.node+"|"+(()=>{if(R.edge.from.port.tag==="Just")return R.edge.from.port._1;if(R.edge.from.port.tag==="Nothing")return"_auto_"+R.edge.id;g()})(),rt=Ad(et)(E.entries);if(rt.tag==="Nothing")return{...E,entries:it(A)(et)({id:0,members:[R.edge.id],incoming:[R.fromPos._1],outgoing:[R.toPos._1],slot:0,mark:0,splitBy:w,splitPartner:w})(E.entries),order:[...E.order,et]};if(rt.tag==="Just")return{...E,entries:it(A)(et)({...rt._1,members:[...rt._1.members,R.edge.id],incoming:[...Jr($=>$<R.fromPos._1)(rt._1.incoming).init,R.fromPos._1,...Jr($=>$<=R.fromPos._1)(rt._1.incoming).rest],outgoing:[...Jr($=>$<R.toPos._1)(rt._1.outgoing).init,R.toPos._1,...Jr($=>$<=R.toPos._1)(rt._1.outgoing).rest]})(E.entries)};g()})({entries:Q,order:[]})(s._2),c=Wt(E=>R=>({...R,id:E}))(wt(E=>Ad(E)(u.entries))(u.order));if(c.length===0)return[];const _=J(E=>R=>E.prev.tag==="Just"&&R-E.prev._1<1e-9?E:{prev:N("Just",R),out:[...E.out,R]})({prev:w,out:[]})(Rt(at.compare)([...Et(c)(E=>E.incoming),...Et(c)(E=>E.outgoing)])).out,l=_.length<2?.2*r:.2*J(E=>R=>{if(E.prev.tag==="Nothing")return{prev:N("Just",R),mn:E.mn};if(E.prev.tag==="Just")return{prev:N("Just",R),mn:Ct(E.mn)(R-E.prev._1)};g()})({prev:w,mn:1e18})(_).mn,f={segments:c,deps:(()=>{const E=c.length;return Et(Et(Ut(0,E-2|0))(R=>Et(Ut(R+1|0,E-1|0))(et=>[L(R,et)])))(R=>R._1>=0&&R._1<c.length?R._2>=0&&R._2<c.length?i(l,c[R._1],c[R._2]):[]:[])})()},d=lt(E=>{if(E.kind==="Critical")return!0;if(E.kind==="Regular")return!1;g()},f.deps),h=(()=>{if(d.length<2)return f;const E=Ii((()=>{const X=f.segments;return Y(V=>L(V.id,V.mark))((()=>{const V=X.length,D=I=>{let M=I,j=!0,z;for(;j;){const q=M,H=te(O=>{const ot=Zt(O)(q.inWeight);if(ot.tag==="Nothing")return!0;if(ot.tag==="Just")return ot._1===0;g()})(q.remaining);if(H.tag==="Nothing"){j=!1,z=q;continue}if(H.tag==="Just"){const O=H._1;M={...q,inWeight:J(ot=>tt=>zt(ut)(Ce)(tt.tgt)(-tt.weight)(ot))(q.inWeight)((()=>{const ot=Zt(O)(q.depsBySrc);if(ot.tag==="Nothing")return[];if(ot.tag==="Just")return ot._1;g()})()),marks:it(ut)(O)(q.nextSource)(q.marks),nextSource:q.nextSource+1|0,outWeight:J(ot=>tt=>zt(ut)(Ce)(tt.src)(-tt.weight)(ot))(q.outWeight)((()=>{const ot=Zt(O)(q.depsByTgt);if(ot.tag==="Nothing")return[];if(ot.tag==="Just")return ot._1;g()})()),remaining:lt(ot=>ot!==O,q.remaining)};continue}g()}return z},B=I=>{let M=I,j=!0,z;for(;j;){const q=M,H=te(O=>{const ot=Zt(O)(q.outWeight);if(ot.tag==="Nothing")return!0;if(ot.tag==="Just")return ot._1===0;g()})(q.remaining);if(H.tag==="Nothing"){j=!1,z=q;continue}if(H.tag==="Just"){const O=H._1;M={...q,inWeight:J(ot=>tt=>zt(ut)(Ce)(tt.tgt)(-tt.weight)(ot))(q.inWeight)((()=>{const ot=Zt(O)(q.depsBySrc);if(ot.tag==="Nothing")return[];if(ot.tag==="Just")return ot._1;g()})()),marks:it(ut)(O)(q.nextSink)(q.marks),nextSink:q.nextSink-1|0,outWeight:J(ot=>tt=>zt(ut)(Ce)(tt.src)(-tt.weight)(ot))(q.outWeight)((()=>{const ot=Zt(O)(q.depsByTgt);if(ot.tag==="Nothing")return[];if(ot.tag==="Just")return ot._1;g()})()),remaining:lt(ot=>ot!==O,q.remaining)};continue}g()}return z};return(I=>{let M=I,j=!0,z;for(;j;){const q=D(B(M));if(q.remaining.length===0){j=!1,z=Y(H=>{const O=Zt(H.id)(q.marks),ot=(()=>{if(O.tag==="Nothing")return H.id;if(O.tag==="Just")return O._1;g()})();return{...H,mark:ot<V?(ot+V|0)+1|0:ot}})(X);continue}M=(()=>{const H=ot=>{const tt=Zt(ot)(q.outWeight),gt=Zt(ot)(q.inWeight);return(()=>{if(tt.tag==="Nothing")return 0;if(tt.tag==="Just")return tt._1;g()})()-(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()|0},O=Rt(ot=>tt=>ut.compare(H(tt))(H(ot)))(q.remaining);if(0<O.length){const ot=O[0];return{...q,inWeight:J(tt=>gt=>zt(ut)(Ce)(gt.tgt)(-gt.weight)(tt))(q.inWeight)((()=>{const tt=Zt(ot)(q.depsBySrc);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),marks:it(ut)(ot)(q.nextSource)(q.marks),nextSource:q.nextSource+1|0,outWeight:J(tt=>gt=>zt(ut)(Ce)(gt.src)(-gt.weight)(tt))(q.outWeight)((()=>{const tt=Zt(ot)(q.depsByTgt);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),remaining:lt(tt=>tt!==ot,q.remaining)}}return q})()}return z})({remaining:Y(I=>I.id)(X),marks:Q,inWeight:J(I=>M=>zt(ut)(Ce)(M.tgt)(M.weight)(I))(Q)(d),outWeight:J(I=>M=>zt(ut)(Ce)(M.src)(M.weight)(I))(Q)(d),depsBySrc:J(I=>M=>zt(ut)(we)(M.src)([M])(I))(Q)(d),depsByTgt:J(I=>M=>zt(ut)(we)(M.tgt)([M])(I))(Q)(d),nextSink:V-1|0,nextSource:V+1|0})})())})()),R=lt(X=>{const V=Zt(X.src)(E),D=Zt(X.tgt)(E);return(()=>{if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1;g()})()>(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;g()})()},d);if(R.length===0)return f;const et=J(X=>V=>{if(ln(go)(V.src)(X.decisions)||ln(go)(V.tgt)(X.decisions))return X;const D=Zt(V.src)(X.segMap),B=Zt(V.tgt)(X.segMap);if(D.tag==="Just"&&B.tag==="Just"){const I=(D._1.incoming.length+D._1.outgoing.length|0)>2&&(B._1.incoming.length+B._1.outgoing.length|0)<=2,M=I?B._1:D._1;return{decisions:[...X.decisions,M.id],segMap:it(ut)(M.id)({...M,splitBy:N("Just",I?D._1.id:B._1.id)})(X.segMap)}}return X})({decisions:[],segMap:Ii(Y(X=>L(X.id,X))(f.segments))})(R),rt=et.segMap,$=J(X=>V=>{const D=Ct(J(Ct)(1e18)(V.incoming))(J(Ct)(1e18)(V.outgoing)),B=bt(J(bt)(-1e18)(V.incoming))(J(bt)(-1e18)(V.outgoing)),I=lt(H=>H.a.startPosition<=B&&H.a.endPosition>=D,Wt(H=>O=>({i:H,a:O}))(X.freeAreas));if(I.length===0){const H={...V,incoming:Rt(at.compare)(V.incoming),outgoing:Rt(at.compare)([(D+B)/2]),splitPartner:N("Just",X.nextId)},O={id:X.nextId,incoming:Rt(at.compare)([(D+B)/2]),mark:0,members:V.members,outgoing:Rt(at.compare)(V.outgoing),slot:0,splitBy:w,splitPartner:N("Just",V.id)};return{segMap:it(ut)(O.id)(O)(it(ut)(H.id)(H)(X.segMap)),freeAreas:X.freeAreas,nextId:X.nextId+1|0}}const M=0<I.length?N("Just",I[0]):w,j=(()=>{if(M.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(M.tag==="Just"){if(I.length===1)return M._1;const H=Y(O=>({c:O,rating:(()=>{const ot=(O.a.startPosition+O.a.endPosition)/2,tt=[ot],gt=[ot],Lt=J((()=>{const Tt=X.segMap;return kt=>Kt=>{const Nt=Zt(Kt.tgt)(Tt);if(Nt.tag==="Nothing")return kt;if(Nt.tag==="Just"){const Xt=Ct(J(Ct)(1e18)(Nt._1.incoming))(J(Ct)(1e18)(Nt._1.outgoing)),Ft=bt(J(bt)(-1e18)(Nt._1.incoming))(J(bt)(-1e18)(Nt._1.outgoing)),vt=Ct(J(Ct)(1e18)(V.incoming))(J(Ct)(1e18)(tt)),yt=(()=>{const Ht=bt(J(bt)(-1e18)(V.incoming))(J(bt)(-1e18)(tt)),jt=J(se=>Je=>Je>Ft?se:Je>=Xt?se+1|0:se)(0)(tt)+J(se=>Je=>Je>Ht?se:Je>=vt?se+1|0:se)(0)(Nt._1.incoming)|0,sn=Ct(J(Ct)(1e18)(V.incoming))(J(Ct)(1e18)(tt)),He=bt(J(bt)(-1e18)(V.incoming))(J(bt)(-1e18)(tt)),Dn=Ct(J(Ct)(1e18)(Nt._1.incoming))(J(Ct)(1e18)(Nt._1.outgoing)),Fn=bt(J(bt)(-1e18)(Nt._1.incoming))(J(bt)(-1e18)(Nt._1.outgoing)),tn=J(se=>Je=>Je>He?se:Je>=sn?se+1|0:se)(0)(Nt._1.outgoing)+J(se=>Je=>Je>Fn?se:Je>=Dn?se+1|0:se)(0)(V.incoming)|0;return jt===tn?jt>0?{...kt,deps:kt.deps+2|0,crossings:kt.crossings+jt|0}:kt:{...kt,deps:kt.deps+1|0,crossings:kt.crossings+Qi(jt)(tn)|0}})(),dt=Ct(J(Ct)(1e18)(Nt._1.incoming))(J(Ct)(1e18)(Nt._1.outgoing)),xt=bt(J(bt)(-1e18)(Nt._1.incoming))(J(bt)(-1e18)(Nt._1.outgoing)),Dt=Ct(J(Ct)(1e18)(gt))(J(Ct)(1e18)(V.outgoing)),ht=bt(J(bt)(-1e18)(gt))(J(bt)(-1e18)(V.outgoing)),Jt=J(Ht=>jt=>jt>xt?Ht:jt>=dt?Ht+1|0:Ht)(0)(V.outgoing)+J(Ht=>jt=>jt>ht?Ht:jt>=Dt?Ht+1|0:Ht)(0)(Nt._1.incoming)|0,Mt=Ct(J(Ct)(1e18)(gt))(J(Ct)(1e18)(V.outgoing)),Bt=bt(J(bt)(-1e18)(gt))(J(bt)(-1e18)(V.outgoing)),ie=Ct(J(Ct)(1e18)(Nt._1.incoming))(J(Ct)(1e18)(Nt._1.outgoing)),ce=bt(J(bt)(-1e18)(Nt._1.incoming))(J(bt)(-1e18)(Nt._1.outgoing)),dn=J(Ht=>jt=>jt>Bt?Ht:jt>=Mt?Ht+1|0:Ht)(0)(Nt._1.outgoing)+J(Ht=>jt=>jt>ce?Ht:jt>=ie?Ht+1|0:Ht)(0)(gt)|0;return Jt===dn?Jt>0?{...yt,deps:yt.deps+2|0,crossings:yt.crossings+Jt|0}:yt:{...yt,deps:yt.deps+1|0,crossings:yt.crossings+Qi(Jt)(dn)|0}}g()}})())(J((()=>{const Tt=X.segMap;return kt=>Kt=>{const Nt=Zt(Kt.src)(Tt);if(Nt.tag==="Nothing")return kt;if(Nt.tag==="Just"){const Xt=Ct(J(Ct)(1e18)(Nt._1.incoming))(J(Ct)(1e18)(Nt._1.outgoing)),Ft=bt(J(bt)(-1e18)(Nt._1.incoming))(J(bt)(-1e18)(Nt._1.outgoing)),vt=Ct(J(Ct)(1e18)(V.incoming))(J(Ct)(1e18)(tt)),yt=(()=>{const Ht=bt(J(bt)(-1e18)(V.incoming))(J(bt)(-1e18)(tt)),jt=J(se=>Je=>Je>Ft?se:Je>=Xt?se+1|0:se)(0)(tt)+J(se=>Je=>Je>Ht?se:Je>=vt?se+1|0:se)(0)(Nt._1.incoming)|0,sn=Ct(J(Ct)(1e18)(V.incoming))(J(Ct)(1e18)(tt)),He=bt(J(bt)(-1e18)(V.incoming))(J(bt)(-1e18)(tt)),Dn=Ct(J(Ct)(1e18)(Nt._1.incoming))(J(Ct)(1e18)(Nt._1.outgoing)),Fn=bt(J(bt)(-1e18)(Nt._1.incoming))(J(bt)(-1e18)(Nt._1.outgoing)),tn=J(se=>Je=>Je>He?se:Je>=sn?se+1|0:se)(0)(Nt._1.outgoing)+J(se=>Je=>Je>Fn?se:Je>=Dn?se+1|0:se)(0)(V.incoming)|0;return jt===tn?jt>0?{...kt,deps:kt.deps+2|0,crossings:kt.crossings+jt|0}:kt:{...kt,deps:kt.deps+1|0,crossings:kt.crossings+Qi(jt)(tn)|0}})(),dt=Ct(J(Ct)(1e18)(Nt._1.incoming))(J(Ct)(1e18)(Nt._1.outgoing)),xt=bt(J(bt)(-1e18)(Nt._1.incoming))(J(bt)(-1e18)(Nt._1.outgoing)),Dt=Ct(J(Ct)(1e18)(gt))(J(Ct)(1e18)(V.outgoing)),ht=bt(J(bt)(-1e18)(gt))(J(bt)(-1e18)(V.outgoing)),Jt=J(Ht=>jt=>jt>xt?Ht:jt>=dt?Ht+1|0:Ht)(0)(V.outgoing)+J(Ht=>jt=>jt>ht?Ht:jt>=Dt?Ht+1|0:Ht)(0)(Nt._1.incoming)|0,Mt=Ct(J(Ct)(1e18)(gt))(J(Ct)(1e18)(V.outgoing)),Bt=bt(J(bt)(-1e18)(gt))(J(bt)(-1e18)(V.outgoing)),ie=Ct(J(Ct)(1e18)(Nt._1.incoming))(J(Ct)(1e18)(Nt._1.outgoing)),ce=bt(J(bt)(-1e18)(Nt._1.incoming))(J(bt)(-1e18)(Nt._1.outgoing)),dn=J(Ht=>jt=>jt>Bt?Ht:jt>=Mt?Ht+1|0:Ht)(0)(Nt._1.outgoing)+J(Ht=>jt=>jt>ce?Ht:jt>=ie?Ht+1|0:Ht)(0)(gt)|0;return Jt===dn?Jt>0?{...yt,deps:yt.deps+2|0,crossings:yt.crossings+Jt|0}:yt:{...yt,deps:yt.deps+1|0,crossings:yt.crossings+Qi(Jt)(dn)|0}}g()}})())({crossings:0,deps:0})(lt(Tt=>Tt.tgt===V.id,f.deps)))(lt(Tt=>Tt.src===V.id,f.deps)),ft=(()=>{if(V.splitBy.tag==="Just")return Zt(V.splitBy._1)(X.segMap);if(V.splitBy.tag==="Nothing")return w;g()})();if(ft.tag==="Just")return{...Lt,deps:Lt.deps+2|0,crossings:(()=>{const Tt=Ct(J(Ct)(1e18)(ft._1.incoming))(J(Ct)(1e18)(ft._1.outgoing)),kt=Ct(J(Ct)(1e18)(gt))(J(Ct)(1e18)(V.outgoing)),Kt=bt(J(bt)(-1e18)(ft._1.incoming))(J(bt)(-1e18)(ft._1.outgoing)),Nt=bt(J(bt)(-1e18)(gt))(J(bt)(-1e18)(V.outgoing)),Xt=Ct(J(Ct)(1e18)(V.incoming))(J(Ct)(1e18)(tt));return Lt.crossings+(()=>{const Ft=Ct(J(Ct)(1e18)(ft._1.incoming))(J(Ct)(1e18)(ft._1.outgoing)),vt=bt(J(bt)(-1e18)(V.incoming))(J(bt)(-1e18)(tt)),yt=bt(J(bt)(-1e18)(ft._1.incoming))(J(bt)(-1e18)(ft._1.outgoing));return((J(dt=>xt=>xt>Kt?dt:xt>=Tt?dt+1|0:dt)(0)(tt)+J(dt=>xt=>xt>vt?dt:xt>=Xt?dt+1|0:dt)(0)(ft._1.incoming)|0)+J(dt=>xt=>xt>Nt?dt:xt>=kt?dt+1|0:dt)(0)(ft._1.outgoing)|0)+J(dt=>xt=>xt>yt?dt:xt>=Ft?dt+1|0:dt)(0)(gt)|0})()|0})()};if(ft.tag==="Nothing")return Lt;g()})()}))(I);return J(O=>ot=>ot.rating.crossings<O.rating.crossings||!(ot.rating.crossings>O.rating.crossings)&&(ot.rating.deps<O.rating.deps||!(ot.rating.deps>O.rating.deps)&&ot.c.a.size>O.c.a.size)?ot:O)(0<H.length?H[0]:{c:M._1,rating:{crossings:1e6,deps:1e6}})(H).c}g()})(),z={...V,incoming:Rt(at.compare)(V.incoming),outgoing:Rt(at.compare)([(j.a.startPosition+j.a.endPosition)/2]),splitPartner:N("Just",X.nextId)},q={id:X.nextId,incoming:Rt(at.compare)([(j.a.startPosition+j.a.endPosition)/2]),mark:0,members:V.members,outgoing:Rt(at.compare)(V.outgoing),slot:0,splitBy:w,splitPartner:N("Just",V.id)};return{segMap:it(ut)(q.id)(q)(it(ut)(z.id)(z)(X.segMap)),freeAreas:(()=>{if(j.i>=0&&j.i<X.freeAreas.length){const H=xf(Yt,w,j.i,X.freeAreas),O=(()=>{if(H.tag==="Nothing")return X.freeAreas;if(H.tag==="Just")return H._1;g()})();if(X.freeAreas[j.i].size/2<l)return O;const ot=(X.freeAreas[j.i].startPosition+X.freeAreas[j.i].endPosition)/2,tt=ot-l,gt=ot+l;return[...j.i<1?[]:At(0,j.i,O),...X.freeAreas[j.i].startPosition<=tt?[{startPosition:X.freeAreas[j.i].startPosition,endPosition:tt,size:tt-X.freeAreas[j.i].startPosition}]:[],...gt<=X.freeAreas[j.i].endPosition?[{startPosition:gt,endPosition:X.freeAreas[j.i].endPosition,size:X.freeAreas[j.i].endPosition-gt}]:[],...j.i<1?O:At(j.i,O.length,O)]}return X.freeAreas})(),nextId:X.nextId+1|0}})({segMap:rt,freeAreas:(()=>{const X=Rt(at.compare)([...Et(f.segments)(V=>V.incoming),...Et(f.segments)(V=>V.outgoing)]);return wt(sv)($e(V=>D=>D-V>=2*l?N("Just",{startPosition:V+l,endPosition:D-l,size:D-V-2*l}):w,X,At(1,X.length,X)))})(),nextId:f.segments.length})(Rt(X=>V=>at.compare(bt(J(bt)(-1e18)(X.incoming))(J(bt)(-1e18)(X.outgoing))-Ct(J(Ct)(1e18)(X.incoming))(J(Ct)(1e18)(X.outgoing)))(bt(J(bt)(-1e18)(V.incoming))(J(bt)(-1e18)(V.outgoing))-Ct(J(Ct)(1e18)(V.incoming))(J(Ct)(1e18)(V.outgoing))))(wt(X=>Zt(X)(rt))(et.decisions)));return{segments:(()=>{const X=(V,D)=>{if(V.tag==="Leaf")return D;if(V.tag==="Node")return X(V._5,pt("Cons",V._4,X(V._6,D)));g()};return Ot(ue.foldr,X($.segMap,G))})(),deps:(()=>{const X=$.segMap,V=(I,M)=>{if(I.tag==="Leaf")return M;if(I.tag==="Node")return V(I._5,pt("Cons",I._4,V(I._6,M)));g()},D=Ot(ue.foldr,V(X,G)),B=D.length;return[...Et(Et(Ut(0,B-2|0))(I=>Et(Ut(I+1|0,B-1|0))(M=>[L(I,M)])))(I=>I._1>=0&&I._1<D.length?I._2>=0&&I._2<D.length?D[I._1].splitPartner.tag!=="Nothing"&&D[I._1].splitPartner.tag==="Just"&&D[I._1].splitPartner._1===D[I._2].id||D[I._2].splitPartner.tag!=="Nothing"&&D[I._2].splitPartner.tag==="Just"&&D[I._2].splitPartner._1===D[I._1].id?[]:i(l,D[I._1],D[I._2]):[]:[]),...Et(D)(I=>I.splitBy.tag==="Just"&&I.splitPartner.tag==="Just"&&(()=>{const M=Zt(I.splitPartner._1)(X);if(M.tag==="Nothing")return!1;if(M.tag==="Just")return!0;g()})()&&(()=>{const M=Zt(I.splitBy._1)(X);if(M.tag==="Nothing")return!1;if(M.tag==="Just")return!0;g()})()?[{src:I.id,tgt:I.splitBy._1,weight:1,kind:Ws},{src:I.splitBy._1,tgt:I.splitPartner._1,weight:1,kind:Ws}]:[])]})()}})(),m=h.segments,p=m.length,x=E=>{let R=E,et=!0,rt;for(;et;){const $=R,X=te(V=>{const D=Zt(V)($.inWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;g()})($.remaining);if(X.tag==="Nothing"){et=!1,rt=$;continue}if(X.tag==="Just"){const V=X._1;R={...$,inWeight:J(D=>B=>zt(ut)(Ce)(B.tgt)(-B.weight)(D))($.inWeight)((()=>{const D=Zt(V)($.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),marks:it(ut)(V)($.nextSource)($.marks),nextSource:$.nextSource+1|0,outWeight:J(D=>B=>zt(ut)(Ce)(B.src)(-B.weight)(D))($.outWeight)((()=>{const D=Zt(V)($.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),remaining:lt(D=>D!==V,$.remaining)};continue}g()}return rt},y=E=>{let R=E,et=!0,rt;for(;et;){const $=R,X=te(V=>{const D=Zt(V)($.outWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;g()})($.remaining);if(X.tag==="Nothing"){et=!1,rt=$;continue}if(X.tag==="Just"){const V=X._1;R={...$,inWeight:J(D=>B=>zt(ut)(Ce)(B.tgt)(-B.weight)(D))($.inWeight)((()=>{const D=Zt(V)($.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),marks:it(ut)(V)($.nextSink)($.marks),nextSink:$.nextSink-1|0,outWeight:J(D=>B=>zt(ut)(Ce)(B.src)(-B.weight)(D))($.outWeight)((()=>{const D=Zt(V)($.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),remaining:lt(D=>D!==V,$.remaining)};continue}g()}return rt},T=(E=>{let R=E,et=!0,rt;for(;et;){const $=x(y(R));if($.remaining.length===0){et=!1,rt=Y(X=>{const V=Zt(X.id)($.marks),D=(()=>{if(V.tag==="Nothing")return X.id;if(V.tag==="Just")return V._1;g()})();return{...X,mark:D<p?(D+p|0)+1|0:D}})(m);continue}R=(()=>{const X=D=>{const B=Zt(D)($.outWeight),I=Zt(D)($.inWeight);return(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})()-(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;g()})()|0},V=Rt(D=>B=>ut.compare(X(B))(X(D)))($.remaining);if(0<V.length){const D=V[0];return{...$,inWeight:J(B=>I=>zt(ut)(Ce)(I.tgt)(-I.weight)(B))($.inWeight)((()=>{const B=Zt(D)($.depsBySrc);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;g()})()),marks:it(ut)(D)($.nextSource)($.marks),nextSource:$.nextSource+1|0,outWeight:J(B=>I=>zt(ut)(Ce)(I.src)(-I.weight)(B))($.outWeight)((()=>{const B=Zt(D)($.depsByTgt);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;g()})()),remaining:lt(B=>B!==D,$.remaining)}}return $})()}return rt})({remaining:Y(E=>E.id)(m),marks:Q,inWeight:J(E=>R=>zt(ut)(Ce)(R.tgt)(R.weight)(E))(Q)(h.deps),outWeight:J(E=>R=>zt(ut)(Ce)(R.src)(R.weight)(E))(Q)(h.deps),depsBySrc:J(E=>R=>zt(ut)(we)(R.src)([R])(E))(Q)(h.deps),depsByTgt:J(E=>R=>zt(ut)(we)(R.tgt)([R])(E))(Q)(h.deps),nextSink:p-1|0,nextSource:p+1|0}),v=(()=>{const E=(()=>{const rt=Ii(Y($=>L($.id,$.mark))(T));return{segments:T,deps:wt($=>(()=>{if($.kind==="Critical")return!0;if($.kind==="Regular")return!1;g()})()?N("Just",$):(()=>{const X=Zt($.src)(rt),V=Zt($.tgt)(rt);return(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;g()})()>(()=>{if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1;g()})()})()?$.weight===0?w:N("Just",{src:$.tgt,tgt:$.src,weight:$.weight,kind:$.kind}):N("Just",$))(h.deps)}})(),R=J(rt=>$=>zt(ut)(Ce)($.tgt)(1)(rt))(Q)(E.deps),et=(rt=>{let $=rt,X=!0,V;for(;X;){const D=$,B=Pt(I=>w,I=>M=>N("Just",{head:I,tail:M}),D.queue);if(B.tag==="Nothing"){X=!1,V=D;continue}if(B.tag==="Just"){$=J((()=>{const I=Zt(B._1.head)(D.slots),M=(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;g()})();return j=>z=>{const q=Zt(z)(j.inDegree),H=(()=>{if(q.tag==="Nothing")return-1;if(q.tag==="Just")return q._1-1|0;g()})();return{...j,slots:it(ut)(z)(Gd((()=>{const O=Zt(z)(j.slots);if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;g()})())(M+1|0))(j.slots),inDegree:it(ut)(z)(H)(j.inDegree),queue:H===0?[...j.queue,z]:j.queue}}})())({...D,queue:B._1.tail})((()=>{const I=Zt(B._1.head)(D.adj);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})());continue}g()}return V})({slots:Ii(Y(rt=>L(rt.id,0))(E.segments)),inDegree:R,adj:J(rt=>$=>zt(ut)(we)($.src)([$.tgt])(rt))(Q)(E.deps),queue:Y(rt=>rt.id)(lt(rt=>{const $=Zt(rt.id)(R);if($.tag==="Nothing")return!0;if($.tag==="Just")return $._1===0;g()},E.segments))});return Rt(rt=>$=>ut.compare(rt.slot)($.slot))(Y(rt=>({...rt,slot:(()=>{const $=Zt(rt.id)(et.slots);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;g()})()}))(E.segments))})(),b=1+J(E=>R=>Gd(E)(R.slot))(0)(v)|0,C=Et(v)(E=>E.members),S=lt(E=>ln(vr)(E.edge.id)(C),t),P=J(bt)(-1e18)(Y(E=>E.fromPos._2)(S)),F=J(Ct)(1e18)(Y(E=>E.toPos._2)(S));if(P>F){const E=Ii(Y(R=>L(R.id,R))(v));return kn(Y(R=>Y(et=>L(et,{slot:R.slot,slotCount:b,gapTop:F,gapBottom:P,partner:(()=>{if(R.splitPartner.tag==="Just"){const rt=Zt(R.splitPartner._1)(E);if(rt.tag==="Just")return N("Just",{slot:rt._1.slot,splitX:0<rt._1.incoming.length?rt._1.incoming[0]:0});if(rt.tag==="Nothing")return w;g()}if(R.splitPartner.tag==="Nothing")return w;g()})()}))(R.members))(lt(R=>{if(R.splitPartner.tag==="Just"){const et=Zt(R.splitPartner._1)(E);return!(et.tag==="Just"&&(()=>{if(et._1.splitBy.tag==="Nothing")return!1;if(et._1.splitBy.tag==="Just")return!0;g()})())}if(R.splitPartner.tag==="Nothing")return!0;g()},v)))}const W=Ii(Y(E=>L(E.id,E))(v));return kn(Y(E=>Y(R=>L(R,{slot:E.slot,slotCount:b,gapTop:P,gapBottom:F,partner:(()=>{if(E.splitPartner.tag==="Just"){const et=Zt(E.splitPartner._1)(W);if(et.tag==="Just")return N("Just",{slot:et._1.slot,splitX:0<et._1.incoming.length?et._1.incoming[0]:0});if(et.tag==="Nothing")return w;g()}if(E.splitPartner.tag==="Nothing")return w;g()})()}))(E.members))(lt(E=>{if(E.splitPartner.tag==="Just"){const R=Zt(E.splitPartner._1)(W);return!(R.tag==="Just"&&(()=>{if(R._1.splitBy.tag==="Nothing")return!1;if(R._1.splitBy.tag==="Just")return!0;g()})())}if(E.splitPartner.tag==="Nothing")return!0;g()},v)))})()))(Q)(av(J(a=>s=>{const u=Bi(s.edge.from.node)(n);if(u.tag==="Just"){const c=Bi(s.edge.to.node)(n);return c.tag==="Just"&&u._1.layer!==c._1.layer?zt(ut)(we)(Qi(u._1.layer)(c._1.layer))([s])(a):a}return a})(Q)((()=>{const a=s=>L((()=>{const u=Bi(s.edge.from.node)(n);return u.tag==="Just"?u._1.layer:1e6})(),(()=>{const u=Bi(s.edge.from.node)(n);return u.tag==="Just"?u._1.order:1e6})());return Rt(s=>u=>iv(a(s))(a(u)))(t)})())))},cv=t=>e=>{const n=Rd(t)(e),r=J(o=>i=>it(A)(i.node)(i)(o))(Q)(e);return J(o=>i=>{const a=Bi(i.edge.from.node)(r);if(a.tag==="Just"){const s=Bi(i.edge.to.node)(r);if(s.tag==="Just"&&a._1.layer!==s._1.layer){const u=uv(i.edge.id)(n);if(u.tag==="Just")return it(ut)(Qi(a._1.layer)(s._1.layer))(u._1.slotCount)(o)}return o}return o})(Q)(t)},mg=ge(A)(Qt),Yr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},yg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},gv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t._1)(i._3._1);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(t._2==="North"){if(i._3._2==="North"){r=!1,o=N("Just",i._4);continue}n=i._5;continue}if(i._3._2==="North"){n=i._6;continue}if(t._2==="South"){if(i._3._2==="South"){r=!1,o=N("Just",i._4);continue}n=i._5;continue}if(i._3._2==="South"){n=i._6;continue}if(t._2==="East"){if(i._3._2==="East"){r=!1,o=N("Just",i._4);continue}n=i._5;continue}if(i._3._2==="East"){n=i._6;continue}if(t._2==="West"&&i._3._2==="West"){r=!1,o=N("Just",i._4);continue}}g()}return o},Dd=t=>e=>{const n=e.position._1+e.size._1,r=e.position._2*2+e.size._2,o=e.position._1*2+e.size._1,i=e.position._2+e.size._2;if(t==="South")return L(o,i*2);if(t==="North")return L(o,e.position._2*2);if(t==="East")return L(n*2,r);if(t==="West")return L(e.position._1*2,r);g()},xg=t=>e=>{const n=nt(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()},Fd=t=>e=>J(n=>r=>zt(t)(we)(e(r))([r])(n))(Q),Id=t=>e=>n=>r=>{const o=(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()})(),i=(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:o||i?1:2},Bd=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,o=e.length;return o===0?Q:mg(o===1?Y(i=>L(i,r))(e):Wt(i=>a=>L(a,t.lo+nt(i+1|0)*n/nt(o+1|0)))(e))},Qd=t=>e=>n=>r=>o=>{const i=Fd(A)(d=>d.to.node)(t),a=Fd(A)(d=>d.from.node)(t),s=J(d=>h=>it(A)(h.node)(h)(d))(Q)(e),u=(d,h,m)=>{const p=Yr(d)(s);if(p.tag==="Nothing")return L(0,0);if(p.tag==="Just"){const x=Yr(d)(n);if(x.tag==="Nothing"){const y=nt(4);if(m==="South")return L(p._1.position._1*y+p._1.size._1*y/2,(p._1.position._2+p._1.size._2)*y);if(m==="North")return L(p._1.position._1*y+p._1.size._1*y/2,p._1.position._2*y);if(m==="East")return L((p._1.position._1+p._1.size._1)*y,p._1.position._2*y+p._1.size._2*y/2);if(m==="West")return L(p._1.position._1*y,p._1.position._2*y+p._1.size._2*y/2);g()}if(x.tag==="Just"){const y=te(T=>T.id===h)(x._1);if(y.tag==="Nothing"){const T=nt(4);if(m==="South")return L(p._1.position._1*T+p._1.size._1*T/2,(p._1.position._2+p._1.size._2)*T);if(m==="North")return L(p._1.position._1*T+p._1.size._1*T/2,p._1.position._2*T);if(m==="East")return L((p._1.position._1+p._1.size._1)*T,p._1.position._2*T+p._1.size._2*T/2);if(m==="West")return L(p._1.position._1*T,p._1.position._2*T+p._1.size._2*T/2);g()}if(y.tag==="Just"){const T=nt(4);if(y._1.side==="North")return L(p._1.position._1*T+nt(y._1.offset)*T,p._1.position._2*T);if(y._1.side==="South")return L(p._1.position._1*T+nt(y._1.offset)*T,(p._1.position._2+p._1.size._2)*T);if(y._1.side==="East")return L((p._1.position._1+p._1.size._1)*T,p._1.position._2*T+nt(y._1.offset)*T);if(y._1.side==="West")return L(p._1.position._1*T,p._1.position._2*T+nt(y._1.offset)*T)}}}g()},c=mg(Et(r)(d=>{if(d.nodes.length<=2)return[];const h=nt(4);if(1<d.nodes.length){const m=Yr(d.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 Y(x=>L(x,p))($e(x=>y=>d.edgeId+":"+x+"->"+y,d.nodes,At(1,d.nodes.length,d.nodes)))}g()}return[]})),_=d=>{const h=Yr(d.from.node)(s),m=Yr(d.to.node)(s);if(h.tag==="Just"&&m.tag==="Just"){const p=h._1,x=m._1,y=Rt(T=>v=>ut.compare(T.score)(v.score))(Y(T=>{const v=T._1,b=T._2;return{from:v,to:b,score:(()=>{const C=(W,E,R,et,rt)=>{const $=xg(W)(E),X=xg(W)(R);return $.lo<X.hi&&X.lo<$.hi&&(v==="South"?b==="North"&&rt._2>et._2:v==="North"?b==="South"&&rt._2<et._2:v==="East"?b==="West"&&rt._1>et._1:v==="West"&&b==="East"&&rt._1<et._1)?0:Id(v)(b)(et)(rt)},S=Dd(v)(p),P=Dd(b)(x),F=Id(v)(b)(S)(P);return(()=>{if(F>0){if(v==="South")return b==="North"?C(De,p,x,S,P)*10|0:F*10|0;if(v==="North")return b==="South"?C(Re,p,x,S,P)*10|0:F*10|0;if(v==="East")return b==="West"?C(Wr,p,x,S,P)*10|0:F*10|0;if(v==="West"&&b==="East")return C(qr,p,x,S,P)*10|0}return F*10|0})()+(v==="South"?b==="North"?x.layer>=p.layer?0:20:15:v==="North"?b==="South"?x.layer<=p.layer?0:20:15:v==="East"?b==="West"?5:15:v==="West"&&b==="East"?5:15)|0})()}})([L(De,Re),L(Wr,Re),L(qr,Re),L(De,Wr),L(De,qr),L(Re,De),L(Re,Wr),L(Re,qr),L(Wr,De),L(qr,De),L(Wr,qr),L(qr,Wr)]));if(0<y.length)return{from:y[0].from,to:y[0].to}}return{from:De,to:Re}},l=mg(Y(d=>L(d.id,_(d)))(t)),f=(d,h,m,p,x,y)=>{const T=nt(4),v=Yr(h)(s);if(v.tag==="Nothing")return L(0,0);if(v.tag==="Just"){const b=gv(L(m,d))(o);if(b.tag==="Just"){const C=v._1.position._1*T+b._1,S=nt(4);if(d==="South")return L(C,(v._1.position._2+v._1.size._2)*S);if(d==="North")return L(C,v._1.position._2*S);if(d==="East")return L((v._1.position._1+v._1.size._1)*S,C);if(d==="West")return L(v._1.position._1*S,C);g()}if(b.tag==="Nothing"){const C=xg(d)(v._1),S=(C.lo+C.hi)/2,P=yg(m)(Bd(C)(Y(E=>E.id)(Rt(E=>R=>at.compare(x(d)(E))(x(d)(R)))(lt(E=>{const R=yg(E.id)(l);if(R.tag==="Just"){const et=y(R._1);return et==="North"?d==="North":et==="South"?d==="South":et==="East"?d==="East":et==="West"&&d==="West"}if(R.tag==="Nothing")return!0;g()},(()=>{const E=Yr(h)(p);if(E.tag==="Nothing")return[];if(E.tag==="Just")return E._1;g()})()))))),F=(()=>{if(P.tag==="Nothing")return S;if(P.tag==="Just")return P._1;g()})(),W=nt(4);if(d==="South")return L(F,(v._1.position._2+v._1.size._2)*W);if(d==="North")return L(F,v._1.position._2*W);if(d==="East")return L((v._1.position._1+v._1.size._1)*W,F);if(d==="West")return L(v._1.position._1*W,F)}}g()};return Y(d=>{const h=yg(d.edge.id)(c);if(h.tag==="Nothing")return d;if(h.tag==="Just")return{...d,fromPos:Fe(3)(d.edge.from.node)==="$d:"?L(h._1,d.fromPos._2):d.fromPos,toPos:Fe(3)(d.edge.to.node)==="$d:"?L(h._1,d.toPos._2):d.toPos};g()})(Y(d=>{if(d.from.port.tag==="Just"&&d.to.port.tag==="Just")return{edge:d,fromPos:u(d.from.node,d.from.port._1,De),toPos:u(d.to.node,d.to.port._1,Re),fromSide:De,toSide:Re};const h=_(d);return{edge:d,fromPos:f(h.from,d.from.node,d.id,a,m=>p=>{const x=Yr(p.to.node)(s);if(x.tag==="Nothing")return 0;if(x.tag==="Just"){const y=nt(4);if(m==="South"||m==="North")return x._1.position._1*y+x._1.size._1*y/2;if(m==="East"||m==="West")return x._1.position._2*y+x._1.size._2*y/2}g()},m=>m.from),toPos:f(h.to,d.to.node,d.id,i,m=>p=>{const x=Yr(p.from.node)(s);if(x.tag==="Nothing")return 0;if(x.tag==="Just"){const y=nt(4);if(m==="South"||m==="North")return x._1.position._1*y+x._1.size._1*y/2;if(m==="East"||m==="West")return x._1.position._2*y+x._1.size._2*y/2}g()},m=>m.to),fromSide:h.from,toSide:h.to}})(t))},qs=(()=>{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=A.compare(e._1)(n._1);if(r==="LT")return ze;if(r==="GT")return Me;if(e._2==="North")return n._2==="North"?un:ze;if(n._2==="North")return Me;if(e._2==="South")return n._2==="South"?un:ze;if(n._2==="South")return Me;if(e._2==="East")return n._2==="East"?un:ze;if(n._2==="East")return Me;if(e._2==="West"&&n._2==="West")return un;g()},Eq0:()=>t}})(),_v=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=qs.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},fv=ge(A)(Qt),wg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},dv=ge(qs)(Qt),zd=(()=>{const t=wn.unfoldr(gr);return e=>t(Tn("IterNode",e,ur))})(),zi=t=>e=>n=>r=>{const o=_v(L(e,n))(t);if(o.tag==="Nothing")return r;if(o.tag==="Just")return o._1;g()},Md=t=>e=>n=>{const r=fv(kn(Y(a=>Wt(s=>u=>L(u,s))(a))(t))),o=(a,s)=>{if(a==="South"){const u=wg(s.to.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()}if(a==="North"){const u=wg(s.from.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()}return 0},i=a=>J(s=>u=>Oe(qs.compare,Qe,dv(Y(c=>L(L(c._1,a),c._2))(zd(Bd({lo:0,hi:(()=>{const c=wg(u._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return Fe(3)(u._1)==="$d:"?0:1;g()})()})(Y(c=>c.id)(Rt(c=>_=>ut.compare(o(a,c))(o(a,_)))(u._2)))))),s))(Q)(zd(J(s=>u=>u.from.node===u.to.node?s:a==="South"?zt(A)(we)(u.from.node)([u])(s):a==="North"?zt(A)(we)(u.to.node)([u])(s):s)(Q)(e)));return Oe(qs.compare,Qe,i(Re),i(De))},Od=t=>t,Wd=t=>t,qd=t=>t,lv=J(t=>e=>it(A)(e)()(t))(Q),hv=(()=>{const t=wn.unfoldr(e=>{if(e.tag==="Nil")return w;if(e.tag==="Cons")return N("Just",L(e._1,e._2));g()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,pt("Cons",r._3,n(r._6,o)));g()};return n(e,G)})())})(),_t=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},qn=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Pr=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Gr=ge(A)(Qt),Tg=Cf(A),Ng=(()=>{const t=wn.unfoldr(gr);return e=>t(Tn("IterNode",e,ur))})(),pv=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},mv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Hd=qd("VDown"),$d=qd("VUp"),yv=Wd("ForwardPhase"),xv=Wd("StackPhase"),Yd=Od("HRight"),Vd=Od("HLeft"),Xd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},wv=t=>e=>n=>{const r=J(a=>s=>zt(A)(Ce)(s.tgt)(1)(a))(Q)(t),o=hv(lv([...Y(a=>a.src)(t),...Y(a=>a.tgt)(t),...(()=>{const a=(s,u)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return a(s._5,pt("Cons",s._4,a(s._6,u)));g()};return Ot(ue.foldr,a(e,G))})()])),i=J(a=>s=>zt(A)(we)(s.src)([{target:s.tgt,sep:s.sep}])(a))(Q)(t);return(a=>s=>u=>{let c=a,_=s,l=u,f=!0,d;for(;f;){const h=c,m=_,p=l,x=Pt(y=>w,y=>T=>N("Just",{head:y,tail:T}),h);if(x.tag==="Nothing"){f=!1,d=p;continue}if(x.tag==="Just"){const y=_t(x._1.head)(p),T=(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;g()})(),v=J(b=>C=>{const S=_t(C.target)(b.result),P=T+C.sep,F=_t(C.target)(b.indeg),W=(()=>{if(F.tag==="Nothing")return-1;if(F.tag==="Just")return F._1-1|0;g()})();return{newQueue:W===0?[...b.newQueue,C.target]:b.newQueue,result:it(A)(C.target)((()=>{if(S.tag==="Nothing")return P;if(S.tag==="Just"){if(n==="VDown")return qn(S._1)(P);if(n==="VUp")return Pr(S._1)(P)}g()})())(b.result),indeg:it(A)(C.target)(W)(b.indeg)}})({newQueue:[],result:p,indeg:m})((()=>{const b=_t(x._1.head)(i);if(b.tag==="Nothing")return[];if(b.tag==="Just")return b._1;g()})());c=[...x._1.tail,...v.newQueue],_=v.indeg,l=v.result;continue}g()}return d})(lt(a=>{const s=_t(a)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;g()},o))(r)(J(a=>s=>it(A)(s)(0)(a))(Q)(o))},Tv=t=>{const e=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return e(i._5,pt("Cons",i._4,e(i._6,a)));g()},n=Ot(ue.foldr,e(t,G)),r=J(qn)(999999)(n);if(r===0||n.length===0)return t;const o=i=>{if(i.tag==="Leaf")return Q;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,i._4-r,o(i._5),o(i._6));g()};return o(t)},Ud=t=>{const e=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return e(i._5,pt("Cons",i._4,e(i._6,a)));g()},n=e(t,G),r=i=>a=>{let s=i,u=a,c=!0,_;for(;c;){const l=s,f=u;if(f.tag==="Nil"){c=!1,_=l;continue}if(f.tag==="Cons"){s=Pr(l)(f._1),u=f._2;continue}g()}return _},o=i=>a=>{let s=i,u=a,c=!0,_;for(;c;){const l=s,f=u;if(f.tag==="Nil"){c=!1,_=l;continue}if(f.tag==="Cons"){s=qn(l)(f._1),u=f._2;continue}g()}return _};return r(-999999)(n)-o(999999)(n)},wa=t=>e=>(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=i;if(u===e){a=!1,s=c;continue}o=(()=>{const _=_t(u)(t.align);if(_.tag==="Nothing")return e;if(_.tag==="Just")return _._1;g()})(),i=[...c,u]}return s})((()=>{const n=_t(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;g()})())([e]),Nv=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>_=>{const l=(D,B,I)=>{const M=D.from.node===B?D.from.port:D.to.node===B?D.to.port:w;if(M.tag==="Just"){const j=_t(B)(o);if(j.tag==="Just"){const z=te(q=>q.id===M._1)(j._1);if(z.tag==="Just"){const q=nt(z._1.offset)*nt(4);return I==="North"||I==="South"?q:0}if(z.tag==="Nothing"){const q=_t(B)(r),H=zi(a)(D.id)(I)((()=>{if(q.tag==="Nothing")return .5;if(q.tag==="Just")return q._1._1/2;g()})());return I==="North"||I==="South"?H:0}g()}if(j.tag==="Nothing"){const z=_t(B)(r),q=zi(a)(D.id)(I)((()=>{if(z.tag==="Nothing")return .5;if(z.tag==="Just")return z._1._1/2;g()})());return I==="North"||I==="South"?q:0}g()}if(M.tag==="Nothing"){const j=_t(B)(r),z=zi(a)(D.id)(I)((()=>{if(j.tag==="Nothing")return .5;if(j.tag==="Just")return j._1._1/2;g()})());return I==="North"||I==="South"?z:0}g()},f=(D,B)=>{if(D.from.node===B){if(_==="HRight")return De;if(_==="HLeft")return Re;g()}if(_==="HRight")return Re;if(_==="HLeft")return De;g()},d=(D,B,I)=>J(M=>j=>it(A)(j)((()=>{const z=_t(j)(M);if(z.tag==="Nothing")return 0+B;if(z.tag==="Just")return z._1+B;g()})())(M))(I)(wa(u)(D)),h=(()=>{if(_==="HRight")return n;if(_==="HLeft")return re(n);g()})(),m=D=>{const B=_t(D)(r);if(B.tag==="Nothing")return 1;if(B.tag==="Just")return B._1._1;g()},p=Gr(kn(Wt(D=>B=>Y(I=>L(I,D))(B))(n))),x=(D,B)=>Fe(3)(D)==="$d:"&&Fe(3)(B)==="$d:"||Fe(3)(D)==="$d:"||Fe(3)(B)==="$d:"?10:nt(t.nodeGap),y=J(D=>B=>Tg(I=>N("Just",[...(()=>{if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})(),B]))(B.to.node)(D))(Q)(i),T=J(D=>B=>Tg(I=>N("Just",[...(()=>{if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})(),B]))(B.from.node)(D))(Q)(i),v=kn(n),b=J(D=>B=>{const I=_t(B)(u.root),M=(()=>{if(I.tag==="Nothing")return B;if(I.tag==="Just")return I._1;g()})();return B===M?D:Tg(j=>N("Just",(()=>{if(j.tag==="Nothing")return!0;if(j.tag==="Just")return j._1;g()})()&&Fe(3)(B)==="$d:"))(M)(D)})(Gr(Y(D=>L(D,!0))(Ji(A.compare)((()=>{const D=(B,I)=>{if(B.tag==="Leaf")return I;if(B.tag==="Node")return D(B._5,pt("Cons",B._4,D(B._6,I)));g()};return Ot(ue.foldr,D(u.root,G))})()))))(v),C=(D,B)=>{const I=D.free,M=_t(I)(u.root),j=(()=>{if(M.tag==="Nothing")return I;if(M.tag==="Just")return M._1;g()})(),z=_t(j)(b),q=(()=>{if(z.tag==="Nothing")return!0;if(z.tag==="Just")return z._1;g()})();return J(H=>O=>{if(H.edge.tag==="Just")return H;if(H.edge.tag==="Nothing"){if((()=>{const ft=_t(j)(B.su);return!q&&(()=>{const Tt=_t(O.from.node)(p);return O.from.node!==O.to.node&&(()=>{const kt=_t(O.to.node)(p);return(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._1;g()})()===(()=>{if(kt.tag==="Nothing")return-1;if(kt.tag==="Just")return kt._1;g()})()})()})()||(()=>{if(ft.tag==="Nothing")return!1;if(ft.tag==="Just")return ft._1;g()})()})())return H;const ot=O.from.node===I?O.to.node:O.from.node,tt=_t(ot)(u.root),gt=(()=>{if(tt.tag==="Nothing")return ot;if(tt.tag==="Just")return tt._1;g()})(),Lt=gt!==j;return Lt&&(()=>{const ft=_t(gt)(B.blockFinished);if(ft.tag==="Nothing")return!1;if(ft.tag==="Just")return ft._1;g()})()?{...H,edge:N("Just",O),hasEdges:!0}:{...H,hasEdges:H.hasEdges||Lt}}g()})({edge:w,hasEdges:!1})((()=>{if(D.isRoot){if(_==="HRight"){const H=_t(I)(y);if(H.tag==="Nothing")return[];if(H.tag==="Just")return H._1;g()}if(_==="HLeft"){const H=_t(I)(T);if(H.tag==="Nothing")return[];if(H.tag==="Just")return H._1}g()}if(_==="HRight"){const H=_t(I)(T);if(H.tag==="Nothing")return[];if(H.tag==="Just")return H._1;g()}if(_==="HLeft"){const H=_t(I)(y);if(H.tag==="Nothing")return[];if(H.tag==="Just")return H._1}g()})())},S=(D,B,I,M)=>{const j=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),z={free:B,isRoot:I},q=C(z,M);if(q.edge.tag==="Nothing")return q.hasEdges?{thresh:j,state:{...M,queue:[...M.queue,z]}}:{thresh:j,state:M};if(q.edge.tag==="Just"){const H=q.edge._1.from.node===B?q.edge._1.to.node:q.edge._1.from.node;return{thresh:(()=>{const O=_t((()=>{const Lt=_t(H)(u.root);if(Lt.tag==="Nothing")return H;if(Lt.tag==="Just")return Lt._1;g()})())(M.x),ot=_t(H)(s),tt=_t(B)(s),gt=(()=>{if(O.tag==="Just")return O._1;if(O.tag==="Nothing")return w;g()})();return(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()+(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;g()})()+l(q.edge._1,H,(()=>{if(I){if(_==="HRight")return De;if(_==="HLeft")return Re;g()}if(_==="HRight")return Re;if(_==="HLeft")return De;g()})())-(()=>{if(tt.tag==="Nothing")return 0;if(tt.tag==="Just")return tt._1;g()})()-l(q.edge._1,B,(()=>{if(I){if(_==="HRight")return Re;if(_==="HLeft")return De;g()}if(_==="HRight")return De;if(_==="HLeft")return Re;g()})())})(),state:{...M,su:it(A)((()=>{const O=_t(q.edge._1.from.node)(u.root);if(O.tag==="Nothing")return q.edge._1.from.node;if(O.tag==="Just")return O._1;g()})())(!0)(it(A)((()=>{const O=_t(q.edge._1.to.node)(u.root);if(O.tag==="Nothing")return q.edge._1.to.node;if(O.tag==="Just")return O._1;g()})())(!0)(M.su))}}}g()},P=(D,B,I,M)=>{const j=B===D,z=_t(B)(u.align),q=(()=>{if(z.tag==="Nothing")return B===D;if(z.tag==="Just")return z._1===D;g()})();if(!(j||q))return{thresh:I,state:M};const H=(()=>{if(c==="VDown")return j&&I<=-1e18;if(c==="VUp")return j&&I>=1e18;g()})()?S(D,B,!0,M):{thresh:I,state:M};return(()=>{if(c==="VDown")return H.thresh<=-1e18&&q;if(c==="VUp")return H.thresh>=1e18&&q;g()})()?S(D,B,!1,H.state):H},F=D=>B=>I=>{const M=_t(I)(e.nodeIndex),j=(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})(),z=te(tt=>ln(vr)(I)(tt))(h),q=(()=>{if(z.tag==="Nothing")return[];if(z.tag==="Just")return z._1;g()})(),H=q.length;if((()=>{if(c==="VDown")return j<=0;if(c==="VUp")return j>=(H-1|0);g()})()){const tt=P(D,I,B.thresh,B.st);return{...B,st:tt.state,thresh:tt.thresh}}const O=(()=>{if(c==="VDown")return j-1|0;if(c==="VUp")return j+1|0;g()})(),ot=O>=0&&O<q.length?N("Just",q[O]):w;if(ot.tag==="Nothing")return B;if(ot.tag==="Just"){const tt=_t(ot._1)(u.root),gt=(()=>{if(tt.tag==="Nothing")return ot._1;if(tt.tag==="Just")return tt._1;g()})(),Lt=P(D,I,B.thresh,W(gt)(B.st)),ft=(()=>{const Bt=_t(D)(Lt.state.sink);if(Bt.tag==="Nothing")return D===D;if(Bt.tag==="Just")return Bt._1===D;g()})()?{...Lt.state,sink:it(A)(D)((()=>{const Bt=_t(gt)(Lt.state.sink);if(Bt.tag==="Nothing")return gt;if(Bt.tag==="Just")return Bt._1;g()})())(Lt.state.sink)}:Lt.state,Tt=_t(gt)(ft.sink),kt=(()=>{if(Tt.tag==="Nothing")return gt;if(Tt.tag==="Just")return Tt._1;g()})(),Kt=_t(D)(ft.sink),Nt=(()=>{if(Kt.tag==="Nothing")return D;if(Kt.tag==="Just")return Kt._1;g()})();if(Nt===kt){const Bt=_t(gt)(ft.x),ie=(()=>{if(Bt.tag==="Just")return Bt._1;if(Bt.tag==="Nothing")return w;g()})(),ce=(()=>{if(ie.tag==="Nothing")return 0;if(ie.tag==="Just")return ie._1;g()})(),dn=_t(D)(ft.x),Ht=(()=>{if(dn.tag==="Just")return dn._1;if(dn.tag==="Nothing")return w;g()})(),jt=(()=>{if(Ht.tag==="Nothing")return 0;if(Ht.tag==="Just")return Ht._1;g()})(),sn=x(I,ot._1),He=_t(ot._1)(s),Dn=_t(I)(s),Fn=(()=>{if(He.tag==="Nothing")return 0;if(He.tag==="Just")return He._1;g()})()-(()=>{if(Dn.tag==="Nothing")return 0;if(Dn.tag==="Just")return Dn._1;g()})();if(c==="VDown"){const tn=Pr(ce+Fn+m(ot._1)+sn)(Lt.thresh);return{st:{...ft,x:it(A)(D)(N("Just",B.initial?tn:Pr(jt)(tn)))(ft.x)},initial:!1,thresh:Lt.thresh}}if(c==="VUp"){const tn=qn(ce+Fn-sn-m(I))(Lt.thresh);return{st:{...ft,x:it(A)(D)(N("Just",B.initial?tn:qn(jt)(tn)))(ft.x)},initial:!1,thresh:Lt.thresh}}g()}const Xt=_t(gt)(ft.x),Ft=(()=>{if(Xt.tag==="Just")return Xt._1;if(Xt.tag==="Nothing")return w;g()})(),vt=(()=>{if(Ft.tag==="Nothing")return 0;if(Ft.tag==="Just")return Ft._1;g()})(),yt=_t(D)(ft.x),dt=(()=>{if(yt.tag==="Just")return yt._1;if(yt.tag==="Nothing")return w;g()})(),xt=(()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1;g()})(),Dt=nt(t.nodeGap),ht=_t(I)(s),Jt=_t(ot._1)(s),Mt=(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()-(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})();return{st:{...ft,classEdges:[...ft.classEdges,{src:Nt,tgt:kt,sep:(()=>{if(c==="VDown")return xt+Mt-vt-m(ot._1)-Dt;if(c==="VUp")return xt+Mt+m(I)+Dt-vt;g()})()}]},initial:B.initial,thresh:Lt.thresh}}g()},W=D=>B=>{const I=_t(D)(B.x),M=(()=>{if(I.tag==="Just")return I._1;if(I.tag==="Nothing")return w;g()})();if(M.tag==="Just")return B;if(M.tag==="Nothing"){const j=J(F(D))({st:{...B,x:it(A)(D)(N("Just",0))(B.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})()})(wa(u)(D));return{...j.st,blockFinished:it(A)(D)(!0)(j.st.blockFinished)}}g()},E=J(D=>B=>J(I=>M=>{const j=_t(M)(u.root),z=(()=>{if(j.tag==="Nothing")return M;if(j.tag==="Just")return j._1;g()})();return z===M?W(z)(I):I})(D)((()=>{if(c==="VDown")return B;if(c==="VUp")return re(B);g()})()))({x:Gr(Y(D=>L(D,w))(v)),sink:Gr(Y(D=>L(D,D))(v)),classEdges:[],su:Q,blockFinished:Q,queue:[]})(h),R=wv(E.classEdges)(E.sink)(c),et=(D,B,I,M)=>{const j=_t(B)(M),z=_t(B)(s);return(()=>{if(j.tag==="Nothing")return 0;if(j.tag==="Just")return j._1;g()})()+(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})()+l(D,B,I)},rt=Gr(Y(D=>L(D,!0))(Ji(A.compare)((()=>{const D=(B,I)=>{if(B.tag==="Leaf")return I;if(B.tag==="Node")return D(B._5,pt("Cons",B._4,D(B._6,I)));g()};return Ot(ue.foldr,D(u.root,G))})()))),$=D=>B=>I=>{const M=C(I,{su:B.su,blockFinished:rt}),j={phase:D,ppFree:I.free,ppIsRoot:I.isRoot,edgeId:w,delta:0,avail:0,shift:0,freeSu:(()=>{const z=_t((()=>{const q=_t(I.free)(u.root);if(q.tag==="Nothing")return I.free;if(q.tag==="Just")return q._1;g()})())(B.su);if(z.tag==="Nothing")return!1;if(z.tag==="Just")return z._1;g()})(),hasEdges:M.hasEdges,candCount:(()=>{if(I.isRoot){if(_==="HRight"){const z=_t(I.free)(y);if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1.length;g()}if(_==="HLeft"){const z=_t(I.free)(T);if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1.length}g()}if(_==="HRight"){const z=_t(I.free)(T);if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1.length;g()}if(_==="HLeft"){const z=_t(I.free)(y);if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1.length}g()})()};if(M.edge.tag==="Nothing")return{...B,stack:[...B.stack,I],trace:[...B.trace,j],x:B.x};if(M.edge.tag==="Just"){const z=M.edge._1.from.node===I.free?L(M.edge._1.from.node,M.edge._1.to.node):L(M.edge._1.to.node,M.edge._1.from.node),q=et(M.edge._1,z._1,f(M.edge._1,z._1),B.x)-et(M.edge._1,z._2,f(M.edge._1,z._2),B.x),H=_t(z._1)(u.root),O=(()=>{if(H.tag==="Nothing")return z._1;if(H.tag==="Just")return H._1;g()})(),ot={...j,edgeId:N("Just",M.edge._1.id),delta:q};if(q>0&&q<1e300){const tt=J(ft=>Tt=>{const kt=_t(Tt)(p),Kt=(()=>{if(kt.tag==="Nothing")return-1;if(kt.tag==="Just")return kt._1;g()})();if(Kt>=0&&Kt<n.length){const Ft=n[Kt],vt=_t(Tt)(e.nodeIndex),yt=(()=>{if(vt.tag==="Nothing")return-2;if(vt.tag==="Just")return vt._1-1|0;g()})();return yt>=0&&yt<Ft.length?qn(ft)((()=>{const dt=_t(Tt)(B.x),xt=_t(Tt)(s),Dt=_t(Ft[yt])(B.x),ht=_t(Ft[yt])(s);return(()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1;g()})()+(()=>{if(xt.tag==="Nothing")return 0;if(xt.tag==="Just")return xt._1;g()})()-((()=>{if(Dt.tag==="Nothing")return 0;if(Dt.tag==="Just")return Dt._1;g()})()+(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+m(Ft[yt])+x(Tt,Ft[yt]))})()):ft}const Nt=_t(Tt)(e.nodeIndex),Xt=(()=>{if(Nt.tag==="Nothing")return-2;if(Nt.tag==="Just")return Nt._1-1|0;g()})();return Xt>=0&&Xt<0?qn(ft)((()=>{const Ft=_t(Tt)(B.x),vt=_t(Tt)(s),yt=_t([][Xt])(B.x),dt=_t([][Xt])(s);return(()=>{if(Ft.tag==="Nothing")return 0;if(Ft.tag==="Just")return Ft._1;g()})()+(()=>{if(vt.tag==="Nothing")return 0;if(vt.tag==="Just")return vt._1;g()})()-((()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;g()})()+(()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1;g()})()+m([][Xt])+x(Tt,[][Xt]))})()):ft})(q)(wa(u)(O)),gt=tt>0?-tt:0,Lt={...B,x:tt>0?d(O,gt,B.x):B.x,trace:[...B.trace,{...ot,avail:tt,shift:gt}]};return tt>0?Lt:{...Lt,stack:[...Lt.stack,I]}}if(q<0&&-q<1e300){const tt=J(ft=>Tt=>{const kt=_t(Tt)(p),Kt=(()=>{if(kt.tag==="Nothing")return-1;if(kt.tag==="Just")return kt._1;g()})();if(Kt>=0&&Kt<n.length){const Ft=n[Kt],vt=_t(Tt)(e.nodeIndex),yt=(()=>{if(vt.tag==="Nothing")return 0;if(vt.tag==="Just")return vt._1+1|0;g()})();return yt>=0&&yt<Ft.length?qn(ft)((()=>{const dt=_t(Ft[yt])(B.x),xt=_t(Ft[yt])(s),Dt=_t(Tt)(B.x),ht=_t(Tt)(s);return(()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1;g()})()+(()=>{if(xt.tag==="Nothing")return 0;if(xt.tag==="Just")return xt._1;g()})()-((()=>{if(Dt.tag==="Nothing")return 0;if(Dt.tag==="Just")return Dt._1;g()})()+(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+m(Tt)+x(Tt,Ft[yt]))})()):ft}const Nt=_t(Tt)(e.nodeIndex),Xt=(()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1+1|0;g()})();return Xt>=0&&Xt<0?qn(ft)((()=>{const Ft=_t([][Xt])(B.x),vt=_t([][Xt])(s),yt=_t(Tt)(B.x),dt=_t(Tt)(s);return(()=>{if(Ft.tag==="Nothing")return 0;if(Ft.tag==="Just")return Ft._1;g()})()+(()=>{if(vt.tag==="Nothing")return 0;if(vt.tag==="Just")return vt._1;g()})()-((()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;g()})()+(()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1;g()})()+m(Tt)+x(Tt,[][Xt]))})()):ft})(-q)(wa(u)(O)),gt=tt>0?tt:0,Lt={...B,x:tt>0?d(O,gt,B.x):B.x,trace:[...B.trace,{...ot,avail:tt,shift:gt}]};return tt>0?Lt:{...Lt,stack:[...Lt.stack,I]}}return{...B,stack:[...B.stack,I],trace:[...B.trace,ot],x:B.x}}g()},X=J($(yv))({x:Gr(Y(D=>L(D,(()=>{const B=_t(D)(u.root),I=(()=>{if(B.tag==="Nothing")return D;if(B.tag==="Just")return B._1;g()})(),M=_t(I)(E.x),j=_t((()=>{const q=_t(I)(E.sink);if(q.tag==="Nothing")return I;if(q.tag==="Just")return q._1;g()})())(R),z=(()=>{if(M.tag==="Just")return M._1;if(M.tag==="Nothing")return w;g()})();return(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})()+(()=>{if(j.tag==="Nothing")return 0;if(j.tag==="Just")return j._1;g()})()})()))(v)),su:E.su,stack:[],trace:[]})(E.queue),V=J($(xv))({...X,stack:[]})(re(X.stack));return{x:V.x,queue:E.queue,trace:V.trace}},vv=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>_=>Nv(t)(e)(n)(r)(o)(i)(a)(s)(u)(c)(_).x,Jv=t=>e=>n=>r=>o=>i=>{const a=(u,c,_)=>{const l=_t(c)(n),f=(()=>{if(l.tag==="Nothing")return .5;if(l.tag==="Just")return l._1._1/2;g()})(),d=u.from.node===c?u.from.port:u.to.node===c?u.to.port:w;if(d.tag==="Just"){const h=_t(c)(e);if(h.tag==="Just"){const m=te(p=>p.id===d._1)(h._1);if(m.tag==="Just"){const p=nt(m._1.offset)*nt(4);return _==="North"||_==="South"?p:0}if(m.tag==="Nothing"){const p=zi(o)(u.id)(_)(f);return _==="North"||_==="South"?p:0}g()}if(h.tag==="Nothing"){const m=zi(o)(u.id)(_)(f);return _==="North"||_==="South"?m:0}g()}if(d.tag==="Nothing"){const h=zi(o)(u.id)(_)(f);return _==="North"||_==="South"?h:0}g()},s=u=>c=>_=>l=>{let f=u,d=c,h=_,m=l,p=!0,x;for(;p;){const y=f,T=d,v=h,b=Pt(C=>w,C=>S=>N("Just",{head:C,tail:S}),m);if(b.tag==="Nothing"){p=!1,x=y;continue}if(b.tag==="Just"){const C=b._1.head,S=te(F=>F.from.node===v&&F.to.node===C||F.from.node===C&&F.to.node===v)(r),P=(()=>{if(S.tag==="Nothing")return T+0;if(S.tag==="Just")return T+(a(S._1,v,S._1.from.node===v?De:Re)-a(S._1,C,S._1.from.node===C?De:Re));g()})();f=it(A)(C)(P)(y),d=P,h=C,m=b._1.tail;continue}g()}return x};return J(u=>c=>{const _=Pt(d=>w,d=>h=>N("Just",{head:d,tail:h}),wa(t)(c)),l=(()=>{if(_.tag==="Nothing")return it(A)(c)(0)(Q);if(_.tag==="Just")return s(it(A)(_._1.head)(0)(Q))(0)(_._1.head)(_._1.tail);g()})(),f=J(d=>h=>Pr(d)(-h._2))(0)(Ng(l));return J(d=>h=>it(A)(h._1)(h._2+f)(d))(u)(Ng(l))})(Q)(Ji(A.compare)((()=>{const u=(c,_)=>{if(c.tag==="Leaf")return _;if(c.tag==="Node")return u(c._5,pt("Cons",c._4,u(c._6,_)));g()};return Ot(ue.foldr,u(t.root,G))})()))},Cv=t=>e=>{const n=(o,i,a)=>Fe(3)(i)==="$d:"&&cc(Ed,(()=>{const s=_t(i)(t.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;g()})()),r=o=>i=>a=>s=>u=>c=>_=>{let l=o,f=i,d=s,h=c,m=_,p=!0,x;for(;p;){const y=l,T=f,v=d,b=h,C=m,S=T.length;if(C>=S){p=!1,x=y;continue}const P=C>=0&&C<T.length?N("Just",T[C]):w,F=(()=>{if(P.tag==="Nothing")return"";if(P.tag==="Just")return P._1;g()})(),W=n(t,F);if(C===(S-1|0)||W){const E=(()=>{if(W){const R=_t(F)(t.preds),et=(()=>{if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;g()})();if(0<et.length){const rt=v-1|0,$=_t(et[0])(t.nodeIndex);if($.tag==="Nothing")return rt;if($.tag==="Just")return $._1;g()}}return v-1|0})();l=J(R=>et=>{if(et>=0&&et<T.length){const rt=T[et];return n(t,rt)?R:J($=>X=>{const V=_t(X)(t.nodeIndex),D=(()=>{if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1;g()})();return D<b||D>E?it(A)(X+"\u2192"+rt)()($):$})(R)((()=>{const $=_t(rt)(t.preds);if($.tag==="Nothing")return[];if($.tag==="Just")return $._1;g()})())}return n(t,"")?R:J(rt=>$=>{const X=_t($)(t.nodeIndex),V=(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;g()})();return V<b||V>E?it(A)($+"\u2192")()(rt):rt})(R)((()=>{const rt=_t("")(t.preds);if(rt.tag==="Nothing")return[];if(rt.tag==="Just")return rt._1;g()})())})(y)(Ut(0,C)),f=T,d=v,h=E,m=C+1|0;continue}l=y,f=T,d=v,h=b,m=C+1|0}return x};return e.length<3?Q:J(o=>i=>{if(i>=0&&i<e.length){const a=e[i];return r(o)((()=>{const s=i+1|0;return s>=0&&s<e.length?e[s]:[]})())(a)(a.length)(i)(0)(0)}return r(o)((()=>{const a=i+1|0;return a>=0&&a<e.length?e[a]:[]})())([])(0)(i)(0)(0)})(Q)(Ut(1,e.length-2|0))},bv=t=>e=>n=>r=>o=>{const i=kn(e),a=J(s=>u=>{const c=J(_=>l=>{const f=(()=>{if(o==="HRight"){const p=_t(l)(t.preds);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;g()}if(o==="HLeft"){const p=_t(l)(t.succs);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1}g()})(),d=f.length;if(d===0)return _;const h=Nr(d-1|0,2),m=Nr(d,2);return J(p=>x=>{if((()=>{const y=_t(l)(p.align);if(y.tag==="Nothing")return l!==l;if(y.tag==="Just")return y._1!==l;g()})())return p;if(x>=0&&x<f.length){const y=_t(f[x])(t.nodeIndex),T=(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;g()})();if(!(Xd(f[x]+"\u2192"+l)(n)||Xd(l+"\u2192"+f[x])(n))&&(()=>{if(r==="VDown")return p.r<T;if(r==="VUp")return p.r>T;g()})()){const v=_t(f[x])(p.root),b=(()=>{if(v.tag==="Nothing")return f[x];if(v.tag==="Just")return v._1;g()})();return{root:it(A)(l)(b)(p.root),align:it(A)(f[x])(l)(it(A)(l)(b)(p.align)),r:T}}}return p})(_)((()=>{if(r==="VDown")return Ut(h,m);if(r==="VUp")return re(Ut(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 u;if(r==="VUp")return re(u);g()})());return{root:c.root,align:c.align}})({root:Gr(Y(s=>L(s,s))(i)),align:Gr(Y(s=>L(s,s))(i))})((()=>{if(o==="HRight")return e;if(o==="HLeft")return re(e);g()})());return{root:a.root,align:a.align}},Hs=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>{const _=bv(e)(n)(s)(u)(c),l=Jv(_)(o)(r)(i)(a)(c);return P2()(f=>d=>N("Just",(()=>{const h=_t(f)(l);if(h.tag==="Nothing")return d+0;if(h.tag==="Just")return d+h._1;g()})()))(vv(t)(e)(n)(r)(o)(i)(a)(l)(_)(u)(c))},Kd=t=>e=>Wt(n=>r=>J(o=>i=>i>=0&&i<e.length?i>=0&&i<t.length?o+e[i]+t[i]:o+e[i]+0:i>=0&&i<t.length?o+1+t[i]:o+1)(0)((()=>{const o=Ut(0,e.length-1|0);return n<1?[]:At(0,n,o)})()))(e),kv=t=>e=>n=>r=>o=>i=>a=>{const s=pv(0)(e.length-1|0),u=nt(t.layerGap),c=a(Io(s,u)),_=cv(Qd(o)(c)(r)(i)(Q))(c);return Y(l=>{const f=mv(l)(_);return f.tag==="Just"&&f._1>0?Pr(u)(2+nt(f._1-1|0)*2.5):u})(Ut(0,s-1|0))},Zd=t=>e=>n=>r=>cc(o=>J(i=>a=>{if(!i.ok)return i;const s=_t(a)(r),u=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})(),c=_t(a)(n),_=(()=>{if(c.tag==="Nothing")return u+1;if(c.tag==="Just")return u+c._1._1;g()})();return u+1e-4>i.pos&&_+1e-4>i.pos?{ok:!0,pos:_}:{ok:!1,pos:i.pos}})({ok:!0,pos:-1e18})(o).ok,e),Lv=t=>e=>n=>r=>{const o=Rt(i=>a=>at.compare(i.w)(a.w))(Y(i=>({l:i,w:Ud(i)}))(lt(Zd()(e)(n),r)));return 0<o.length?N("Just",o[0].l):w},Sv=t=>e=>{const n=Gr(kn(Y(Wt(o=>i=>L(i,o)))(t))),r=o=>Rt(i=>a=>ut.compare((()=>{const s=_t(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})())((()=>{const s=_t(a)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(o);return{preds:(()=>{const o=i=>{if(i.tag==="Leaf")return Q;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(J(i=>a=>zt(A)(we)(a.to.node)([a.from.node])(i))(Q)(e))})(),succs:(()=>{const o=i=>{if(i.tag==="Leaf")return Q;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(J(i=>a=>zt(A)(we)(a.from.node)([a.to.node])(i))(Q)(e))})(),nodeIndex:n}},Ev=t=>e=>{const n=Rt(l=>f=>at.compare(l.w)(f.w))(Wt(l=>f=>({i:l,l:f,w:Ud(f)}))(e)),r=0<n.length?N("Just",n[0]):w,o=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;g()})(),i=o>=0&&o<e.length?N("Just",e[o]):w,a=(()=>{if(i.tag==="Just")return(l=>f=>{let d=l,h=f,m=!0,p;for(;m;){const x=d,y=h;if(y.tag==="Nil"){m=!1,p=x;continue}if(y.tag==="Cons"){d=qn(x)(y._1),h=y._2;continue}g()}return p})(999999)((()=>{const l=(f,d)=>{if(f.tag==="Leaf")return d;if(f.tag==="Node")return l(f._5,pt("Cons",f._4,l(f._6,d)));g()};return l(i._1,G)})());if(i.tag==="Nothing")return 0;g()})(),s=l=>J(f=>d=>Pr(f)((()=>{const h=_t(d._1)(t);if(h.tag==="Nothing")return d._2+1;if(h.tag==="Just")return d._2+h._1._1;g()})()))(-999999)(Ng(l)),u=o>=0&&o<e.length?N("Just",e[o]):w,c=(()=>{if(u.tag==="Just")return s(u._1);if(u.tag==="Nothing")return 0;g()})(),_=$e(l=>f=>{const d=h=>{if(h.tag==="Leaf")return Q;if(h.tag==="Node")return ee("Node",h._1,h._2,h._3,h._4+f,d(h._5),d(h._6));g()};return d(l)},e,Wt(l=>f=>lo(l)(2)===0?a-(d=>h=>{let m=d,p=h,x=!0,y;for(;x;){const T=m,v=p;if(v.tag==="Nil"){x=!1,y=T;continue}if(v.tag==="Cons"){m=qn(T)(v._1),p=v._2;continue}g()}return y})(999999)((()=>{const d=(h,m)=>{if(h.tag==="Leaf")return m;if(h.tag==="Node")return d(h._5,pt("Cons",h._4,d(h._6,m)));g()};return d(f,G)})()):c-s(f))(e));return Tv(J(l=>f=>{const d=Rt(at.compare)(wt(_t(f))(_));return it(A)(f)(d.length===4?1<d.length&&2<d.length?(d[1]+d[2])/2:0:0<d.length?d[0]:0)(l)})(Q)(Ji(A.compare)(kn(Y(l=>{const f=d=>{if(d.tag==="Leaf")return Q;if(d.tag==="Node")return ee("Node",d._1,d._2,d._3,void 0,f(d._5),f(d._6));g()};return Ot(pn.foldr,f(l))})(_)))))},Pv=t=>e=>n=>r=>o=>i=>{const a=Sv(e)(o),s=Cv(a)(e),u={nodeGap:t.nodeGap*4|0},c=Oe(A.compare,Qe,Gr(Y(d=>L(d,L(1,1)))(lt(Ed,kn(e)))),(()=>{const d=h=>{if(h.tag==="Leaf")return Q;if(h.tag==="Node")return ee("Node",h._1,h._2,h._3,L(h._4._1*nt(4),h._4._2),d(h._5),d(h._6));g()};return d(n)})()),_=[Hs(u)(a)(e)(c)(r)(o)(i)(s)(Hd)(Yd),Hs(u)(a)(e)(c)(r)(o)(i)(s)($d)(Yd),Hs(u)(a)(e)(c)(r)(o)(i)(s)(Hd)(Vd),Hs(u)(a)(e)(c)(r)(o)(i)(s)($d)(Vd)],l=Ev(c)(_);if(Zd()(e)(c)(l))return l;const f=Lv()(e)(c)(_);if(f.tag==="Just")return f._1;if(f.tag==="Nothing")return _[0];g()},Gv=t=>e=>n=>r=>{const o=mf(w,_f,i=>i.node===e?N("Just",i.position):w,t);if(o.tag==="Nothing")return t;if(o.tag==="Just"){const i=o._1;return Y(a=>a.node===n?{...a,position:L(i._1+r._1,i._2+r._2)}:a)(t)}g()},Av=t=>e=>n=>r=>{const o=lt(a=>ln(vr)(a.node)(e),t),i=(()=>{if(n==="Vertical"){if(r==="Start")return J(a=>s=>qn(a)(s.position._1))(99999)(o);if(r==="End")return J(a=>s=>Pr(a)(s.position._1))(0)(o);if(r==="Center"){const a=J(s=>u=>s+u.position._1)(0)(o);return o.length===0?0:a/nt(o.length)}g()}if(n==="Horizontal"){if(r==="Start")return J(a=>s=>qn(a)(s.position._2))(99999)(o);if(r==="End")return J(a=>s=>Pr(a)(s.position._2))(0)(o);if(r==="Center"){const a=J(s=>u=>s+u.position._2)(0)(o);return o.length===0?0:a/nt(o.length)}}g()})();return Y(a=>{if(ln(vr)(a.node)(e)){if(n==="Vertical")return{...a,position:L(i,a.position._2)};if(n==="Horizontal")return{...a,position:L(a.position._1,i)};g()}return a})(t)},Rv=t=>e=>J(n=>r=>r.tag==="AlignGroup"?Av(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?Gv(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),Dv=t=>e=>n=>r=>o=>i=>a=>s=>{const u=Y(l=>J(f=>d=>Pr(f)((()=>{const h=_t(d)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;g()})()))(1)(l))(n),c=Pv(t)(n)(r)(o)(i)(s),_=Kd(kv(t)(n)(r)(o)(i)(a)(l=>{const f=Kd(l)(u);return kn(Wt(d=>h=>Wt(m=>p=>({node:p,position:L((()=>{const x=_t(p)(c);return(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})()/nt(4)})(),d>=0&&d<f.length?f[d]:0),size:(()=>{const x=Fe(3)(p)==="$d:"?L(0,1):L(1,1),y=_t(p)(r);if(y.tag==="Nothing")return x;if(y.tag==="Just")return y._1;g()})(),layer:d,order:m}))(h))(n))}))(u);return Rv(e)(kn(Wt(l=>f=>Wt(d=>h=>({node:h,position:L((()=>{const m=_t(h)(c);return(()=>{if(m.tag==="Nothing")return 0;if(m.tag==="Just")return m._1;g()})()/nt(4)})(),l>=0&&l<_.length?_[l]:0),size:(()=>{const m=Fe(3)(h)==="$d:"?L(0,1):L(1,1),p=_t(h)(r);if(p.tag==="Nothing")return m;if(p.tag==="Just")return p._1;g()})(),layer:l,order:d}))(f))(n)))},vg=Sc(us)(Oo(32)),jd=Sc(us)(Oo(31)),Ta=(()=>{const t=wy("25214903917");if(t.tag==="Nothing")return Mf;if(t.tag==="Just")return t._1;g()})(),Na=Lc(Sc(us)(Oo(48)))(us),Fv=t=>{const e=Ty(t);return sa(Of((()=>{if(e.tag==="Nothing")return Mf;if(e.tag==="Just")return e._1;g()})())(Ta))(Na)},Jg=Oo(11),$s=t=>e=>{const n=sa(as(ss(e)(Ta))(Jg))(Na);return L((()=>{const r=Tf(py(Ec(n)(Oo(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},Iv=t=>{const e=$s(26)(t),n=$s(27)(e._2);return L((nt(e._1)*gc(2)(27)+nt(n._1))/gc(2)(53),n._2)},Bv=t=>e=>{const n=J(r=>o=>{const i=Iv(r.finalR);return{rs:[...r.rs,i._1],finalR:i._2}})({rs:[],finalR:t})(e);return L(Y(r=>r.x)(Rt(r=>o=>at.compare(r.k)(o.k))($e(r=>o=>({x:r,k:o}),e,n.rs))),n.finalR)},Qv=t=>{const e=sa(as(ss(t)(Ta))(Jg))(Na),n=sa(as(ss(e)(Ta))(Jg))(Na);return L(as(ss((()=>{const r=Ec(e)(Oo(16));return Wf.compare(r)(jd)!=="LT"?Lc(r)(vg):r})())(vg))((()=>{const r=Ec(n)(Oo(16));return Wf.compare(r)(jd)!=="LT"?Lc(r)(vg):r})()),n)},va=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Ys=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},Cg=ge(A)(Qt),Mi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Vs=ge(A)(Qt),zv=sc(ta),Mv=J(_r)(0),Ov=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},tl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},Wv=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const o=fo(Yt,w,t,n[e],n);if(o.tag==="Just")return fo(Yt,w,e,r,o._1);if(o.tag==="Nothing")return w;g()}}return w},qv=t=>e=>n=>r=>o=>Cg(J(i=>a=>{const s=Rt(u=>c=>ut.compare((()=>{const _=va(u.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;g()})())((()=>{const _=va(c.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;g()})()))(lt(u=>Ys(u.to.node)(n),lt(u=>u.from.node===a,r)));return{ranks:[...i.ranks,...Wt(u=>c=>L(c.id,nt((i.rankSum+u|0)+1|0)))(s)],rankSum:i.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),Hv=t=>e=>n=>r=>o=>Cg(J(i=>a=>{const s=Rt(c=>_=>{const l=ut.compare((()=>{const f=Mi(_.from.node)(n);if(f.tag==="Nothing")return-1;if(f.tag==="Just")return f._1;g()})())((()=>{const f=Mi(c.from.node)(n);if(f.tag==="Nothing")return-1;if(f.tag==="Just")return f._1;g()})());return l==="EQ"?ut.compare((()=>{const f=va(c.id)(o);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})())((()=>{const f=va(_.id)(o);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})()):l})(lt(c=>Ys(c.from.node)(n),lt(c=>c.to.node===a,r))),u=s.length;return{ranks:[...i.ranks,...Wt(c=>_=>L(_.id,nt((i.rankSum+u|0)-c|0)))(s)],rankSum:i.rankSum+u|0}})({ranks:[],rankSum:0})(t).ranks),bg=t=>e=>n=>{const r=Vs(Wt(s=>u=>L(u,s))(t)),o=Vs(Wt(s=>u=>L(u,s))(e)),i=wt(s=>{const u=Mi(s.from.node)(r),c=Mi(s.to.node)(o);if(u.tag==="Just"&&c.tag==="Just")return N("Just",L(u._1,c._1));const _=Mi(s.from.node)(o),l=Mi(s.to.node)(r);return _.tag==="Just"&&l.tag==="Just"?N("Just",L(l._1,_._1)):w})(n),a=i.length;return J(s=>u=>J(c=>_=>u>=0&&u<i.length&&_>=0&&_<i.length&&((i[u]._1-i[_]._1|0)*(i[u]._2-i[_]._2|0)|0)<0?c+1|0:c)(s)(Ut(u+1|0,a-1|0)))(0)(Ut(0,a-2|0))},$v=t=>e=>n=>r=>{const o=i=>a=>{let s=i,u=a,c=!0,_;for(;c;){const l=s,f=u;if(f>=(l.length-1|0)){c=!1,_=l;continue}if(f>=0&&f<l.length){const d=f+1|0;if(d>=0&&d<l.length){const h=l[f],m=l[d];if(ne(T=>T.before===h&&T.after===m,r)){s=l,u=f+1|0;continue}const p=fo(Yt,w,f,m,l),x=(()=>{if(p.tag==="Just")return fo(Yt,w,f+1|0,h,p._1);if(p.tag==="Nothing")return w;g()})(),y=(()=>{if(x.tag==="Nothing")return l;if(x.tag==="Just")return x._1;g()})();if(bg(e)(y)(n)<bg(e)(l)(n)){s=y,u=f+1|0;continue}s=l,u=f+1|0;continue}c=!1,_=l;continue}c=!1,_=l}return _};return(i=>{let a=i,s=!0,u;for(;s;){const c=a,_=o(c)(0);if(zv(_)(c)){s=!1,u=c;continue}a=_}return u})(t)},Xs=t=>e=>J(n=>r=>{if(r>=0&&r<t.length){const o=t[r],i=r+1|0;if(i>=0&&i<t.length)return n+bg(o)(t[i])(e)|0}return n})(0)(Ut(0,t.length-2|0)),Yv=(()=>{const t=e=>{if(e.length<7){const i=a=>s=>{let u=a,c=s,_=!0,l;for(;_;){const f=u,d=c,h=d-1|0;if(h>=0&&h<f.length){if(d>=0&&d<f.length&&d>0&&f[h].key>f[d].key){const m=Wv(d-1|0)(d)(f);if(m.tag==="Just"){u=m._1,c=d-1|0;continue}if(m.tag==="Nothing"){_=!1,l=f;continue}g()}_=!1,l=f;continue}_=!1,l=f}return l};return J(a=>s=>i(a)(s))(e)(Ut(1,e.length-1|0))}const n=Nr(e.length,2),r=t(At(0,n,e)),o=t(At(n,e.length,e));return(i=>a=>s=>{let u=i,c=a,_=s,l=!0,f;for(;l;){const d=u,h=c,m=_;if(h>=0&&h<r.length){if(m>=0&&m<o.length){if(r[h].key>o[m].key){u=St(d)(o[m]),c=h,_=m+1|0;continue}u=St(d)(r[h]),c=h+1|0,_=m;continue}l=!1,f=[...d,...h<1?r:At(h,r.length,r)];continue}l=!1,f=[...d,...m<1?o:At(m,o.length,o)]}return f})([])(0)(0)};return t})(),Vv=t=>e=>n=>{const r=wt(c=>c.tag==="OrderConstraint"?N("Just",{before:c._1.before,after:c._1.after}):w)(t.constraints),o=c=>J(_=>l=>{const f=l.after,d=l.before,h=Mr(Yt,w,p=>p===d,_),m=Mr(Yt,w,p=>p===f,_);if(h.tag==="Just"&&m.tag==="Just"&&h._1>m._1){const p=xf(Yt,w,h._1,_),x=(()=>{if(p.tag==="Nothing")return _;if(p.tag==="Just")return p._1;g()})(),y=yf(Yt,w,m._1,d,x);if(y.tag==="Nothing")return x;if(y.tag==="Just")return y._1;g()}return _})(c)(r),i=Cg(Wt(c=>_=>L(_.id,c))(n)),a=(c,_,l)=>{const f=c.length;return J(d=>h=>{const m=_?h-1|0:h+1|0,p=m>=0&&m<d._1.length?N("Just",d._1[m]):w;if(p.tag==="Just"){const x=h>=0&&h<d._1.length?N("Just",d._1[h]):w;if(x.tag==="Just"){const y=Vs(Wt(S=>P=>L(P,S))(p._1)),T=Vs(Wt(S=>P=>L(P,S))(x._1)),v=_?qv(p._1)(y)(T)(n)(i):Hv(p._1)(y)(T)(n)(i),b=J(S=>P=>{const F=wt(E=>va(E.id)(v))(lt(_?E=>E.to.node===P._2&&Ys(E.from.node)(y):E=>E.from.node===P._2&&Ys(E.to.node)(y),n));if(F.length===0)return{...S,items:[...S.items,{n:P._2,key:w,origIdx:P._1}]};const W=$s(24)(S.r);return{items:[...S.items,{n:P._2,key:N("Just",(Mv(F)+(nt(W._1)*4172325152040912e-24-.03500000014901161))/nt(F.length)),origIdx:P._1}],r:W._2}})({items:[],r:d._2})(Wt(bn)(x._1)),C=fo(Yt,w,h,$v(o(Y(S=>S.n)(Yv((()=>{const S=b.items,P=F=>W=>{let E=F,R=W,et=!0,rt;for(;et;){const $=E,X=R;if($>=0&&$<S.length){if(S[$].key.tag==="Just"){et=!1,rt=S[$].key._1;continue}if(S[$].key.tag==="Nothing"){E=$+1|0,R=X;continue}g()}et=!1,rt=X}return rt};return(F=>W=>E=>{let R=F,et=W,rt=E,$=!0,X;for(;$;){const V=R,D=et,B=rt;if(V>=0&&V<S.length){if(S[V].key.tag==="Just"){R=V+1|0,et=S[V].key._1,rt=[...B,{n:S[V].n,key:S[V].key._1,origIdx:S[V].origIdx}];continue}if(S[V].key.tag==="Nothing"){const I=(D+P(V+1|0)(D+1))/2;R=V+1|0,et=I,rt=[...B,{n:S[V].n,key:I,origIdx:S[V].origIdx}];continue}g()}$=!1,X=B}return X})(0)(-1)([])})()))))(p._1)(n)(r),d._1);if(C.tag==="Just")return L(C._1,b.r);if(C.tag==="Nothing")return L(d._1,d._2);g()}if(x.tag==="Nothing")return L(d._1,d._2);g()}if(p.tag==="Nothing")return L(d._1,d._2);g()})(L(c,l))(_?Ut(1,f-1|0):re(Ut(0,f-2|0)))},s=J(c=>_=>it(A)(_.from.node)()(it(A)(_.to.node)()(c)))(Q)(n),u=J(c=>_=>{if(c.result.crossings===0)return c;const l=y=>T=>v=>b=>{let C=y,S=T,P=v,F=b,W=!0,E;for(;W;){const R=C,et=S,rt=P,$=F;if(rt===0){W=!1,E={layout:R,crossings:0,random:$};continue}const X=a(R,et,$),V=Xs(X._1)(n);if(V<rt){C=X._1,S=!et,P=V,F=X._2;continue}W=!1,E={layout:R,crossings:rt,random:X._2}}return E},f=$s(1)(c.result.random),d=f._1!==0,h=t.modelOrder.tag==="Leaf",m=(c.firstTry||c.secondTry)&&!h?c.firstTry:d,p=(()=>{if(!h){const b=a(e,m,f._2);return l(b._1)(!m)(Xs(b._1)(n))(b._2)}const y=m?0:Ov(0)(e.length-1|0),T=y>=0&&y<e.length?N("Just",e[y]):w;if(T.tag==="Just"&&T._1.length>1){const b=lt(C=>tl(C)(s),T._1);if(b.length>1){const C=Bv(f._2)(b),S=C._1,P=fo(Yt,w,y,o(J(F=>W=>tl(W)(s)?F.idx>=0&&F.idx<S.length?{idx:F.idx+1|0,result:[...F.result,S[F.idx]]}:{idx:F.idx,result:[...F.result,W]}:{idx:F.idx,result:[...F.result,W]})({idx:0,result:[]})(T._1).result),e);if(P.tag==="Just"){const F=a(P._1,m,C._2);return l(F._1)(!m)(Xs(F._1)(n))(F._2)}}}const v=a(e,m,f._2);return l(v._1)(!m)(Xs(v._1)(n))(v._2)})(),x=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:x}})({result:{layout:e,crossings:1e9,random:sa(Of(Qv(Fv(1))._1)(Ta))(Na)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Ut(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:u.layout},Xv=t=>t,el=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},mn=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Oi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},Ja=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=A.compare(e._1)(n._1);return r==="LT"?ze:r==="GT"?Me:A.compare(e._2)(n._2)},Eq0:()=>t}})(),Uv=ge(A)(Qt),Kv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=Ja.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},Zv=Xv("Greedy"),kg=t=>e=>n=>J(r=>o=>{if(o.from.node===o.to.node)return r;if(o.from.node===e&&!el(o.to.node)(r.marks)){const i=mn(o.to.node)(r.inDeg),a=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;g()})(),s=it(A)(o.to.node)(a)(r.inDeg);return(()=>{const u=mn(o.to.node)(r.outDeg);return a<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;g()})()&&!ln(vr)(o.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,o.to.node]}:{...r,inDeg:s}}if(o.to.node===e&&!el(o.from.node)(r.marks)){const i=mn(o.from.node)(r.outDeg),a=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;g()})(),s=it(A)(o.from.node)(a)(r.outDeg);return(()=>{const u=mn(o.from.node)(r.inDeg);return a<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;g()})()&&!ln(vr)(o.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,o.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:lt(r=>r!==e,n.remaining)})(t),jv=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return it(A)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return it(A)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return it(A)(e._1.node)(99999)(t)}return t})(Q),nl=t=>e=>n=>{const r=mn(e)(t),o=mn(n)(t);return r.tag==="Just"&&o.tag==="Just"&&r._1>o._1},rl=t=>e=>n=>r=>{if(Oi(n)(r.visited)||Oi(n)(r.visiting))return r;const o=J(tJ(t)(e)(n))({...r,visiting:it(A)(n)()(r.visiting)})((()=>{const i=mn(n)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;g()})());return{...o,visiting:Li(A)(n)(o.visiting),visited:it(A)(n)()(o.visited)}},tJ=t=>e=>n=>r=>o=>nl(t)(n)(o)?{...r,backEdges:it(Ja)(L(n,o))()(r.backEdges)}:Oi(o)(r.visiting)?{...r,backEdges:it(Ja)(L(n,o))()(r.backEdges)}:Oi(o)(r.visited)?r:rl(t)(e)(o)(r),eJ=t=>e=>n=>{const r=f=>{let d=f,h=!0,m;for(;h;){const p=d,x=Pt(y=>w,y=>T=>N("Just",{head:y,tail:T}),p.sinks);if(x.tag==="Just"){d=kg(n)(x._1.head)({...p,sinks:x._1.tail,marks:it(A)(x._1.head)(p.nextRight)(p.marks),nextRight:p.nextRight-1|0});continue}if(x.tag==="Nothing"){const y=Pt(T=>w,T=>v=>N("Just",{head:T,tail:v}),p.sources);if(y.tag==="Just"){d=kg(n)(y._1.head)({...p,sources:y._1.tail,marks:it(A)(y._1.head)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}if(y.tag==="Nothing"){const T=b=>{const C=mn(b)(p.outDeg),S=mn(b)(p.inDeg);return(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;g()})()-(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;g()})()|0},v=Rt(b=>C=>{const S=ut.compare(T(C))(T(b));return S==="EQ"?ut.compare((()=>{const P=mn(b)(e);if(P.tag==="Nothing")return 1e6;if(P.tag==="Just")return P._1;g()})())((()=>{const P=mn(C)(e);if(P.tag==="Nothing")return 1e6;if(P.tag==="Just")return P._1;g()})()):S})(p.remaining);if(0<v.length){const b=v[0];d=kg(n)(b)({...p,remaining:lt(C=>C!==b,p.remaining),marks:it(A)(b)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}h=!1,m=p;continue}}g()}return m},o=Ji(A.compare)([...Y(f=>f.from.node)(n),...Y(f=>f.to.node)(n)]),i=lt(f=>f.from.node!==f.to.node,n),a=J(f=>d=>zt(A)(Ce)(d.to.node)(1)(f))(Q)(i),s=J(f=>d=>zt(A)(Ce)(d.from.node)(1)(f))(Q)(i),u=lt(f=>{const d=mn(f)(a);if(d.tag==="Nothing")return!0;if(d.tag==="Just")return d._1===0;g()},o),c=lt(f=>{const d=mn(f)(s);if(d.tag==="Nothing")return!0;if(d.tag==="Just")return d._1===0;g()},o),_=o.length+1|0,l=J(f=>d=>{const h=mn(d)(f);return h.tag==="Just"&&h._1<0?it(A)(d)(h._1+_|0)(f):f})(r({remaining:lt(f=>!ln(vr)(f)(u)&&!ln(vr)(f)(c),o),marks:Q,inDeg:a,outDeg:s,sources:u,sinks:c,nextLeft:1,nextRight:-1}).marks)(o);return J(f=>d=>{if(d.from.node===d.to.node)return f;if(nl(t)(d.from.node)(d.to.node))return it(Ja)(L(d.from.node,d.to.node))()(f);const h=mn(d.from.node)(l),m=mn(d.to.node)(l);return h.tag==="Just"&&m.tag==="Just"&&h._1>m._1?it(Ja)(L(d.from.node,d.to.node))()(f):f})(Q)(n)},nJ=J(t=>e=>zt(A)(we)(e.from.node)([e.to.node])(t))(Q),rJ=t=>e=>{const n=nJ(e),r=Ji(A.compare)([...Y(i=>i.from.node)(e),...Y(i=>i.to.node)(e)]),o=J(i=>a=>it(A)(a.to.node)()(i))(Q)(e);return J(i=>a=>rl(t)(n)(a)(i))({visiting:Q,visited:Q,backEdges:Q})([...lt(i=>!Oi(i)(o),r),...lt(i=>Oi(i)(o),r)]).backEdges},oJ=t=>e=>n=>r=>{const o=Uv(Wt(s=>u=>L(u,s))(e)),i=jv(n),a=(()=>{if(t==="DepthFirst")return rJ(i)(r);if(t==="Greedy")return eJ(i)(o)(r);g()})();return{edges:Y(s=>Kv(L(s.from.node,s.to.node))(a)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:a}},ol=Qt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),Ee=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Pe=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ca=t=>e=>n=>r=>ol(o=>n>=o.x&&n<o.x+o.w&&e>o.y&&t<o.y+o.h)(r),Us=t=>e=>n=>r=>Ca(Ee(e)(n))(Pe(e)(n))(r)(t),Ks=nt(4),iJ=Za(t=>{if(t.direction==="H"){const e=Ee(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:Pe(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=Ee(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:Pe(t.start._2)(t.end._2)-e}]}g()}),ba=na(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})())}),aJ=t=>e=>n=>{const r=Pt(o=>w,o=>i=>N("Just",{head:o,tail:i}),e);if(r.tag==="Nothing")return[{start:t.start,end:n.end,direction:t.direction}];if(r.tag==="Just"){const o=(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],i=Or(r._1.tail);if(i.tag==="Nothing"){const a=o.length-1|0;return a>=0&&a<o.length&&(o[a].direction==="H"?n.direction==="H":o[a].direction==="V"&&n.direction==="V")?[...(()=>{const s=o.length-1|0;return s<1?[]:At(0,s,o)})(),{start:o[a].start,end:n.end,direction:n.direction}]:[...o,n]}if(i.tag==="Just")return(i._1.last.direction==="H"?n.direction==="H":i._1.last.direction==="V"&&n.direction==="V")?[...o,...i._1.init,{start:i._1.last.start,end:n.end,direction:n.direction}]:[...o,...r._1.tail,n]}g()},ka=t=>{const e=r=>o=>{const i=Pt(a=>w,a=>s=>N("Just",{head:a,tail:s}),o);if(i.tag==="Nothing")return[r];if(i.tag==="Just")return(r.direction==="H"?i._1.head.direction==="H":r.direction==="V"&&i._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==i._1.head.end._1-i._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==i._1.head.end._2-i._1.head.start._2>=0;g()})()?e({start:r.start,end:i._1.head.end,direction:r.direction})(i._1.tail):[r,...e(i._1.head)(i._1.tail)];g()},n=Pt(r=>w,r=>o=>N("Just",{head:r,tail:o}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);g()},La=t=>e=>n=>r=>ol(o=>n>=o.y&&n<o.y+o.h&&e>o.x&&t<o.x+o.w)(r),Sa=t=>e=>n=>r=>La(Ee(e)(n))(Pe(e)(n))(r)(t),sJ=t=>e=>n=>r=>{const o=n+2|0,i=o<1?e:At(o,e.length,e),a=n<1?[]:At(0,n,e),s=(n+1|0)===(r-1|0),u=n===0,c=n>=0&&n<e.length?N("Just",e[n]):w;if(c.tag==="Just"){const _=n+1|0,l=_>=0&&_<e.length?N("Just",e[_]):w;if(l.tag==="Just"){const f=c._1.start._1===l._1.end._1&&(!u||c._1.direction==="V")&&(!s||l._1.direction==="V")&&!Us(t)(Ee(c._1.start._2)(l._1.end._2))(Pe(c._1.start._2)(l._1.end._2))(c._1.start._1)?N("Just",[...a,{start:c._1.start,end:l._1.end,direction:xe},...i]):w,d=c._1.start._2===l._1.end._2&&(!u||c._1.direction==="H")&&(!s||l._1.direction==="H")&&!Sa(t)(Ee(c._1.start._1)(l._1.end._1))(Pe(c._1.start._1)(l._1.end._1))(c._1.start._2)?N("Just",[...a,{start:c._1.start,end:l._1.end,direction:Ne},...i]):w;return f.tag==="Nothing"?d:f}if(l.tag==="Nothing")return w;g()}if(c.tag==="Nothing")return w;g()},uJ=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,a;for(;i;){const s=o;if((s+1|0)>=n){i=!1,a=e;continue}const u=sJ(t)(e)(s)(n);if(u.tag==="Just"){i=!1,a=u._1;continue}if(u.tag==="Nothing"){o=s+1|0;continue}g()}return a})(0)},cJ=t=>e=>n=>r=>{const o=(f,d,h)=>!Us(t)(Ee(d)(h))(Pe(d)(h))(f),i=n+3|0,a=i<1?e:At(i,e.length,e),s=n<1?[]:At(0,n,e),u=(n+2|0)===(r-1|0),c=n===0,_=(f,d,h)=>!Sa(t)(Ee(d)(h))(Pe(d)(h))(f),l=n>=0&&n<e.length?N("Just",e[n]):w;if(l.tag==="Just"){const f=n+2|0,d=f>=0&&f<e.length?N("Just",e[f]):w;if(d.tag==="Just"){const h=l._1.start._1===d._1.end._1&&(!c||l._1.direction==="V")&&(!u||d._1.direction==="V")&&o(l._1.start._1,l._1.start._2,d._1.end._2)?N("Just",[...s,{start:l._1.start,end:d._1.end,direction:xe},...a]):l._1.start._2===d._1.end._2&&(!c||l._1.direction==="H")&&(!u||d._1.direction==="H")&&_(l._1.start._2,l._1.start._1,d._1.end._1)?N("Just",[...s,{start:l._1.start,end:d._1.end,direction:Ne},...a]):w,m=(!c||l._1.direction==="V")&&(!u||d._1.direction==="H")&&o(l._1.start._1,l._1.start._2,d._1.end._2)&&_(d._1.end._2,l._1.start._1,d._1.end._1)?N("Just",[...s,{start:l._1.start,end:L(l._1.start._1,d._1.end._2),direction:xe},{start:L(l._1.start._1,d._1.end._2),end:d._1.end,direction:Ne},...a]):w,p=(!c||l._1.direction==="H")&&(!u||d._1.direction==="V")&&_(l._1.start._2,l._1.start._1,d._1.end._1)&&o(d._1.end._1,l._1.start._2,d._1.end._2)?N("Just",[...s,{start:l._1.start,end:L(d._1.end._1,l._1.start._2),direction:Ne},{start:L(d._1.end._1,l._1.start._2),end:d._1.end,direction:xe},...a]):w,x=m.tag==="Nothing"?p:m;return h.tag==="Nothing"?x:h}if(d.tag==="Nothing")return w;g()}if(l.tag==="Nothing")return w;g()},gJ=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,a;for(;i;){const s=o;if((s+2|0)>=n){i=!1,a=e;continue}const u=cJ(t)(e)(s)(n);if(u.tag==="Just"){i=!1,a=u._1;continue}if(u.tag==="Nothing"){o=s+1|0;continue}g()}return a})(0)},_J=t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const a=r,s=ka(ba(uJ(t)(gJ(t)(a))));if(s.length<a.length){r=s;continue}o=!1,i=s}return i};return n=>e(ka(ba(n)))},fJ=t=>e=>n=>r=>{const o=Ee(n)(r),i=Pe(n)(r),a=lt(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Rt(c=>_=>at.compare(c.x)(_.x))(a);return 0<u.length?u[0].x-1:(n+r)/2}const s=Rt(u=>c=>at.compare(c.x)(u.x))(Y(u=>({...u,x:u.x+u.w}))(a));return 0<s.length?s[0].x+1:(n+r)/2},dJ=t=>e=>n=>r=>{const o=Ee(n)(r),i=Pe(n)(r),a=lt(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Rt(c=>_=>at.compare(c.y)(_.y))(a);return 0<u.length?u[0].y-1:(n+r)/2}const s=Rt(u=>c=>at.compare(c.y)(u.y))(Y(u=>({...u,y:u.y+u.h}))(a));return 0<s.length?s[0].y+1:(n+r)/2},lJ=t=>e=>n=>r=>{const o=Ee(n)(r),i=Pe(n)(r),a=lt(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Rt(c=>_=>at.compare(_.x)(c.x))(Y(c=>({...c,x:c.x+c.w}))(a));return 0<u.length?u[0].x:(n+r)/2}const s=Rt(u=>c=>at.compare(u.x)(c.x))(a);return 0<s.length?s[0].x-1:(n+r)/2},hJ=t=>e=>n=>r=>{const o=Ee(n)(r),i=Pe(n)(r),a=lt(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Rt(c=>_=>at.compare(_.y)(c.y))(Y(c=>({...c,y:c.y+c.h}))(a));return 0<u.length?u[0].y:(n+r)/2}const s=Rt(u=>c=>at.compare(u.y)(c.y))(a);return 0<s.length?s[0].y-1:(n+r)/2},il=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,c=o,_=i;if(_>100){a=!1,s=c;continue}if(!u(c+_)){a=!1,s=c+_;continue}if(!u(c-_)){a=!1,s=c-_;continue}r=u,o=c,i=_+1}return s},al=t=>e=>n=>r=>o=>{const i=Ee(e)(n),a=Pe(e)(n);if(!Ca(i)(a)(r)(t))return r;if(!Ca(i)(a)(o)(t))return o;const s=(r+o)/2;return Ca(i)(a)(s)(t)?il(u=>Ca(i)(a)(u)(t))(s)(1):s},pJ=t=>e=>n=>r=>o=>{const i=Ee(e)(n),a=Pe(e)(n);if(!La(i)(a)(r)(t))return r;if(!La(i)(a)(o)(t))return o;const s=(r+o)/2;return La(i)(a)(s)(t)?il(u=>La(i)(a)(u)(t))(s)(1):s},mJ=t=>e=>n=>r=>{const o=Ee(e)(n),i=Pe(e)(n),a=lt(c=>r>=c.x&&r<c.x+c.w&&c.y+c.h>o&&c.y<i,t),s=J(c=>_=>Pe(c)(_.x+_.w+4))(r+4)(a),u=J(c=>_=>Ee(c)(_.x-4))(r-4)(a);return(()=>{const c=s-r,_=u-r;return(c<0?-c:c)<=(_<0?-_:_)})()?s:u},yJ=t=>e=>n=>r=>{const o=Ee(e)(n),i=Pe(e)(n),a=lt(c=>r>=c.y&&r<c.y+c.h&&c.x+c.w>o&&c.x<i,t),s=J(c=>_=>Pe(c)(_.y+_.h+4))(r+4)(a),u=J(c=>_=>Ee(c)(_.y-4))(r-4)(a);return(()=>{const c=s-r,_=u-r;return(c<0?-c:c)<=(_<0?-_:_)})()?s:u},xJ=t=>e=>n=>r=>o=>i=>a=>{const s=(()=>{if(r==="South")return L(o._1,o._2+4);if(r==="North")return L(o._1,o._2-4);if(r==="East")return L(o._1+4,o._2);if(r==="West")return L(o._1-4,o._2);g()})(),u=(()=>{if(i==="South")return L(a._1,a._2+4);if(i==="North")return L(a._1,a._2-4);if(i==="East")return L(a._1+4,a._2);if(i==="West")return L(a._1-4,a._2);g()})(),c=(b,C,S)=>!Us(e)(Ee(C)(S))(Pe(C)(S))(b),_=(b,C,S)=>!Us(n)(Ee(C)(S))(Pe(C)(S))(b),l=(b,C,S,P)=>t.tag==="Just"&&!Sa(n)(Ee(b)(C))(Pe(b)(C))(t._1)?t._1:pJ(e)(b)(C)(S)(P),f=(b,C,S,P)=>{if(b===S){const W=mJ(e)(C)(P)(b),E=dJ(e)(b)(C)(P),R=hJ(e)(b)(C)(P);return[{start:L(b,C),end:L(b,E),direction:xe},{start:L(b,E),end:L(W,E),direction:Ne},{start:L(W,E),end:L(W,R),direction:xe},{start:L(W,R),end:L(S,R),direction:Ne},{start:L(S,R),end:L(S,P),direction:xe}]}const F=l(b,S,C,P);return[{start:L(b,C),end:L(b,F),direction:xe},{start:L(b,F),end:L(S,F),direction:Ne},{start:L(S,F),end:L(S,P),direction:xe}]},d=(b,C,S,P)=>{if(C===P){const W=yJ(e)(b)(S)(C),E=fJ(e)(C)(b)(S),R=lJ(e)(C)(b)(S);return[{start:L(b,C),end:L(E,C),direction:Ne},{start:L(E,C),end:L(E,W),direction:xe},{start:L(E,W),end:L(R,W),direction:Ne},{start:L(R,W),end:L(R,P),direction:xe},{start:L(R,P),end:L(S,P),direction:Ne}]}const F=al(e)(C)(P)(b)(S);return[{start:L(b,C),end:L(F,C),direction:Ne},{start:L(F,C),end:L(F,P),direction:xe},{start:L(F,P),end:L(S,P),direction:Ne}]},h=(b,C,S)=>!Sa(e)(Ee(C)(S))(Pe(C)(S))(b),m=(b,C,S)=>!Sa(n)(Ee(C)(S))(Pe(C)(S))(b),p=(b,C,S,P)=>{if(m(C,b,S)&&_(S,C,P))return[{start:L(b,C),end:L(S,C),direction:Ne},{start:L(S,C),end:L(S,P),direction:xe}];const F=al(e)(C)(P)(b)(S);return[{start:L(b,C),end:L(F,C),direction:Ne},{start:L(F,C),end:L(F,P),direction:xe},{start:L(F,P),end:L(S,P),direction:Ne}]},x=(b,C,S,P)=>{if(_(b,C,P)&&m(P,b,S))return[{start:L(b,C),end:L(b,P),direction:xe},{start:L(b,P),end:L(S,P),direction:Ne}];const F=l(b,S,C,P);return[{start:L(b,C),end:L(b,F),direction:xe},{start:L(b,F),end:L(S,F),direction:Ne},{start:L(S,F),end:L(S,P),direction:xe}]},y=(()=>{if(r==="South")return i==="North"?s._1===u._1&&c(s._1,s._2,u._2)?[{start:L(s._1,s._2),end:L(u._1,u._2),direction:xe}]:f(s._1,s._2,u._1,u._2):i==="East"||i==="West"?x(s._1,s._2,u._1,u._2):f(s._1,s._2,u._1,u._2);if(r==="North")return i==="South"?s._1===u._1&&c(s._1,s._2,u._2)?[{start:L(s._1,s._2),end:L(u._1,u._2),direction:xe}]:f(s._1,s._2,u._1,u._2):i==="East"||i==="West"?x(s._1,s._2,u._1,u._2):f(s._1,s._2,u._1,u._2);if(r==="East")return i==="West"?s._2===u._2&&h(s._2,s._1,u._1)?[{start:L(s._1,s._2),end:L(u._1,u._2),direction:Ne}]:d(s._1,s._2,u._1,u._2):i==="North"||i==="South"?p(s._1,s._2,u._1,u._2):f(s._1,s._2,u._1,u._2);if(r==="West"){if(i==="East")return s._2===u._2&&h(s._2,s._1,u._1)?[{start:L(s._1,s._2),end:L(u._1,u._2),direction:Ne}]:d(s._1,s._2,u._1,u._2);if(i==="North"||i==="South")return p(s._1,s._2,u._1,u._2)}return f(s._1,s._2,u._1,u._2)})(),T=(()=>{if(r==="South"||r==="North")return xe;if(r==="East"||r==="West")return Ne;g()})(),v={start:L(u._1,u._2),end:L(a._1,a._2),direction:(()=>{if(i==="South"||i==="North")return xe;if(i==="East"||i==="West")return Ne;g()})()};return s._1===u._1&&s._2===u._2?[{start:L(o._1,o._2),end:L(a._1,a._2),direction:T}]:aJ({start:L(o._1,o._2),end:L(s._1,s._2),direction:T})(y)(v)},wJ=Y(t=>({x:t.position._1*Ks-2,y:t.position._2*Ks-2,w:t.size._1*Ks+4,h:t.size._2*Ks+4})),sl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Wi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},TJ=(()=>{const t=wn.unfoldr(gr);return e=>t(Tn("IterNode",e,ur))})(),Lg=t=>e=>t.gapTop+1*nt(4)+nt(e)*2.5*nt(4),NJ=t=>e=>{const n=sl(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return N("Just",{slot1Y:Lg(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Lg(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return w;g()}if(n.tag==="Nothing")return w;g()},vJ=t=>e=>{const n=J(r=>o=>it(A)(o.node)(o)(r))(Q)(e);return kn(Wt(r=>o=>{const i=Wi(o.node)(n);if(i.tag==="Nothing")return[];if(i.tag==="Just"){const a=i._1;return Wt(s=>u=>{const c=o.edges.length,_=nt(4),l=a.position._1*_,f=a.position._2*_,d=a.size._2*_,h=nt((2*c|0)+1|0),m=f+d*nt(c-s|0)/h,p=f+d*nt((c+1|0)+s|0)/h,x=l-_*2.5*nt(s+1|0),y=[{start:L(l,m),end:L(x,m),direction:Ne},{start:L(x,m),end:L(x,p),direction:xe},{start:L(x,p),end:L(l,p),direction:Ne}];return{edge:u.id,segments:y,bends:$e(T=>v=>T.end,y,At(1,3,y)),bendType:[],jumps:[],reversed:!1}})(o.edges)}g()})(Y(r=>({node:r._1,edges:r._2}))(TJ(J(r=>o=>zt(A)(we)(o.from.node)([o])(r))(Q)(t)))))},JJ=t=>e=>{const n=J(i=>a=>it(A)(a.node)(a)(i))(Q)(e),r=i=>{const a=Wi(i)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1.position._1;g()},o=i=>{const a=Wi(i)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1.layer;g()};return Rt(i=>a=>{const s=ut.compare(o(i.edge.from.node))(o(a.edge.from.node));if(s==="EQ"){const u=at.compare(r(i.edge.from.node))(r(a.edge.from.node));return u==="EQ"?at.compare(r(i.edge.to.node))(r(a.edge.to.node)):u}return s})(t)},yn=t=>{const e=nt(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}},CJ=t=>t.from.node===t.to.node,bJ=t=>e=>n=>r=>{const o=_J(n)(xJ(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:o,bends:$e(i=>a=>i.end,o,At(1,o.length,o)),bendType:[],jumps:[],reversed:!1}},kJ=t=>e=>n=>r=>{const o=[{start:L(r.fromPos._1,r.fromPos._2),end:L(r.fromPos._1,t.slot1Y),direction:xe},{start:L(r.fromPos._1,t.slot1Y),end:L(t.splitX,t.slot1Y),direction:Ne},{start:L(t.splitX,t.slot1Y),end:L(t.splitX,t.slot2Y),direction:xe},{start:L(t.splitX,t.slot2Y),end:L(r.toPos._1,t.slot2Y),direction:Ne},{start:L(r.toPos._1,t.slot2Y),end:L(r.toPos._1,r.toPos._2),direction:xe}];return{edge:r.edge.id,segments:o,bends:$e(i=>a=>i.end,o,At(1,5,o)),bendType:[],jumps:[],reversed:!1}},LJ=t=>e=>n=>{const r=Wi(t.edge.from.node)(n);if(r.tag==="Just"){const i=Wi(t.edge.to.node)(n);return i.tag==="Just"?lt(a=>!(a.h===yn(r._1).h&&a.w===yn(r._1).w&&a.x===yn(r._1).x&&a.y===yn(r._1).y)&&!(a.h===yn(i._1).h&&a.w===yn(i._1).w&&a.x===yn(i._1).x&&a.y===yn(i._1).y),e):lt(a=>!(a.h===yn(r._1).h&&a.w===yn(r._1).w&&a.x===yn(r._1).x&&a.y===yn(r._1).y),e)}const o=Wi(t.edge.to.node)(n);return o.tag==="Just"?lt(i=>!(i.h===yn(o._1).h&&i.w===yn(o._1).w&&i.x===yn(o._1).x&&i.y===yn(o._1).y),e):lt(i=>!0,e)},SJ=t=>e=>{const n=sl(e.edge.id)(t);if(n.tag==="Just")return N("Just",Lg(n._1)(n._1.slot));if(n.tag==="Nothing")return w;g()},EJ=t=>e=>n=>r=>o=>{const i=J(c=>_=>it(A)(_.node)(_)(c))(Q)(e),a=wJ(e),s=Qd(lt(c=>c.from.node!==c.to.node,t))(e)(n)(r)(o),u=Rd(s)(e);return[...vJ(lt(CJ,t))(e),...J(c=>_=>{const l=LJ(_)(a)(i),f=[...l,...c.edgeObstacles],d=NJ(u)(_),h=(()=>{if(d.tag==="Just")return kJ(d._1)(l)(f)(_);if(d.tag==="Nothing")return bJ(SJ(u)(_))(l)(f)(_);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...iJ(h.segments)]}})({results:[],edgeObstacles:[]})(JJ(s)(e)).results]},wo=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},To=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},PJ=t=>e=>n=>{if(t.start._1!==e.start._1)return w;const r=To(wo(t.start._2)(t.end._2))(wo(e.start._2)(e.end._2)),o=wo(To(t.start._2)(t.end._2))(To(e.start._2)(e.end._2));return r<o?N("Just",{position:L(t.start._1,(r+o)/2),crossingEdge:n}):w},GJ=t=>e=>n=>{if(t.start._2!==e.start._2)return w;const r=To(wo(t.start._1)(t.end._1))(wo(e.start._1)(e.end._1)),o=wo(To(t.start._1)(t.end._1))(To(e.start._1)(e.end._1));return r<o?N("Just",{position:L((r+o)/2,t.start._2),crossingEdge:n}):w},AJ=t=>e=>n=>{if(t.direction==="H")return GJ(t)(e)(n);if(t.direction==="V")return PJ(t)(e)(n);g()},RJ=t=>e=>n=>{const r=t+1|0,o=r<1?n:At(r,n.length,n);return Et(e.segments)(i=>Et(o)(a=>wt(s=>AJ(i)(s)(a.edge))(lt(s=>s.direction==="H"?i.direction==="H":s.direction==="V"&&i.direction==="V",a.segments))))},DJ=t=>e=>n=>e.start._1>wo(t.start._1)(t.end._1)&&e.start._1<To(t.start._1)(t.end._1)&&t.start._2>wo(e.start._2)(e.end._2)&&t.start._2<To(e.start._2)(e.end._2)?N("Just",{position:L(e.start._1,t.start._2),crossingEdge:n}):w,FJ=t=>e=>Et(lt(n=>n.direction==="H",t.segments))(n=>Et(e)(r=>wt(o=>DJ(n)(o)(r.edge))(lt(o=>o.direction==="V",r.segments)))),ul=t=>e=>n=>[...FJ(e)(lt(r=>r.edge!==e.edge,n)),...RJ(t)(e)(n)],cl=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},IJ=J(t=>e=>it(A)(e)()(t))(Q),Zs=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},BJ=Jd(A),Ar=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},gl=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Sg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},QJ=ge(ut)(Qt),zJ=t=>e=>Oe(A.compare,Qe,t,e),_l=Wt(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),MJ=t=>J(e=>n=>({base:(()=>{const r=o=>i=>{let a=o,s=i,u=!0,c;for(;u;){const _=a,l=s;if(l.tag==="Nil"){u=!1,c=_;continue}if(l.tag==="Cons"){a=cl(_)(l._1),s=l._2;continue}g()}return c};return(e.base+r(0)((()=>{const o=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return o(i._5,pt("Cons",i._4,o(i._6,a)));g()};return o(n,G)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=o=>{if(o.tag==="Leaf")return Q;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,o._4+e.base|0,r(o._5),r(o._6));g()};return r(n)})()]}))({base:0,result:[]})(t).result,OJ=t=>e=>{const n=IJ(t);return BJ(t)(_l(lt(r=>Zs(r.src)(n)&&Zs(r.tgt)(n),e)))},WJ=t=>e=>{const n=J(o=>i=>zt(A)(we)(i.tgt)([i.src])(zt(A)(we)(i.src)([i.tgt])(o)))(Q)(e),r=o=>i=>a=>{let s=o,u=i,c=a,_=!0,l;for(;_;){const f=s,d=u,h=c,m=Pt(p=>w,p=>x=>N("Just",{head:p,tail:x}),f);if(m.tag==="Nothing"){_=!1,l={nodes:h};continue}if(m.tag==="Just"){if(Zs(m._1.head)(d)){s=m._1.tail,u=d,c=h;continue}s=[...m._1.tail,...(()=>{const p=Ar(m._1.head)(n);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;g()})()],u=it(A)(m._1.head)()(d),c=[...h,m._1.head];continue}g()}return l};return J(o=>i=>{if(Zs(i)(o.visited))return o;const a=r([i])(o.visited)([]);return{...o,visited:J(s=>u=>it(A)(u)()(s))(o.visited)(a.nodes),components:[...o.components,a.nodes]}})({visited:Q,components:[]})(t).components},qJ=t=>e=>n=>{const r=J(i=>a=>zt(A)(Ce)(a.tgt)(1)(i))(Q)(e),o=J(i=>a=>zt(A)(Ce)(a.src)(1)(i))(Q)(e);return J(i=>a=>{const s=Ar(a)(r),u=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})();if((()=>{const y=Ar(a)(o);return(()=>{if(y.tag==="Nothing")return u!==0;if(y.tag==="Just")return u!==y._1;g()})()||u===0})())return i;const c=Ar(a)(i.layers),_=(()=>{if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1;g()})(),l=i.layers,f=J(y=>T=>T.tgt===a?{...y,mIn:gl(y.mIn)((()=>{const v=Ar(a)(l),b=Ar(T.src)(l);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;g()})()|0})())}:T.src===a?{...y,mOut:gl(y.mOut)((()=>{const v=Ar(T.tgt)(l),b=Ar(a)(l);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;g()})()|0})())}:y)({mIn:1e9,mOut:1e9})(e),d=f.mIn===1e9?-1:f.mIn,h=f.mOut===1e9?-1:f.mOut;if(d<0||h<0)return i;const m=(_-d|0)+1|0,p=(_+h|0)-1|0;if(p<m)return i;const x=J(y=>T=>{const v=Sg(T)(i.filling),b=(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})();return b<y.bestFill?{best:T,bestFill:b}:y})({best:_,bestFill:(()=>{const y=Sg(_)(i.filling);if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;g()})()})(Ut(m,p));return x.best===_?i:{layers:it(A)(a)(x.best)(i.layers),filling:it(ut)(_)((()=>{const y=Sg(_)(i.filling);if(y.tag==="Nothing")return-1;if(y.tag==="Just")return y._1-1|0;g()})())(it(ut)(x.best)(x.bestFill+1|0)(i.filling))}})({layers:n,filling:QJ(Y(i=>L(i,J(a=>s=>(()=>{const u=Ar(s)(n);return u.tag==="Nothing"?!1:u.tag==="Just"&&u._1===i})()?a+1|0:a)(0)(t)))(Ut(0,J(i=>a=>cl(i)((()=>{const s=Ar(a)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(0)(t))))})(t).layers},HJ=t=>e=>qJ(t)(_l(e))(J(zJ)(Q)(MJ(Y(n=>OJ(n)(e))(WJ(t)(e))))),$J=t=>t,Ko=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},js=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fl=(()=>{const t=wn.unfoldr(gr);return e=>t(Tn("IterNode",e,ur))})(),YJ=$J("NetworkSimplex"),VJ=t=>e=>J(n=>r=>{const o=J(js)(0)(wt(i=>Ko(i)(n))(r));return J(i=>a=>it(A)(a)(o)(i))(n)(r)})(e)(t),XJ=t=>e=>({layers:Y(n=>lt(r=>{const o=Ko(r)(e);return o.tag==="Nothing"?!1:o.tag==="Just"&&o._1===n},t))(Ut(0,(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=i;if(c.tag==="Nil"){a=!1,s=u;continue}if(c.tag==="Cons"){o=js(u)(c._1),i=c._2;continue}g()}return s})(0)((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,pt("Cons",r._4,n(r._6,o)));g()};return n(e,G)})()))),nodeLayer:e}),UJ=t=>e=>n=>{const r=J(o=>i=>it(A)(i)(!0)(o))(Q)(e);return J(o=>i=>it(A)(i._1)(i._2)(o))(HJ(e)(wt(o=>o.from.node===o.to.node||(()=>{const i=Ko(o.from.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;g()})()||(()=>{const i=Ko(o.to.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;g()})()?w:N("Just",{src:o.from.node,tgt:o.to.node}))(t)))(fl(n))},KJ=t=>e=>n=>r=>{const o=s=>u=>{const c=Ko(u)(s);if(c.tag==="Just")return s;if(c.tag==="Nothing"){const _=lt(f=>f!==u,(()=>{const f=Ko(u)(t);if(f.tag==="Nothing")return[];if(f.tag==="Just")return f._1;g()})()),l=J(o)(s)(_);return it(A)(u)(1+J(js)(0)(wt(f=>Ko(f)(l))(_))|0)(l)}g()},i=J(o)(Q)(n),a=(s=>u=>{let c=s,_=u,l=!0,f;for(;l;){const d=c,h=_;if(h.tag==="Nil"){l=!1,f=d;continue}if(h.tag==="Cons"){c=js(d)(h._1),_=h._2;continue}g()}return f})(1)((()=>{const s=(u,c)=>{if(u.tag==="Leaf")return c;if(u.tag==="Node")return s(u._5,pt("Cons",u._4,s(u._6,c)));g()};return s(i,G)})());return J(s=>u=>it(A)(u._1)(u._2)(s))((()=>{const s=u=>{if(u.tag==="Leaf")return Q;if(u.tag==="Node")return ee("Node",u._1,u._2,u._3,a-u._4|0,s(u._5),s(u._6));g()};return s(i)})())(fl(r))},ZJ=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return it(A)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return it(A)(e._1.node)(0)(t)}return t})(Q),jJ=J(t=>e=>zt(A)(we)(e.to.node)([e.from.node])(t))(Q),tC=J(t=>e=>zt(A)(we)(e.from.node)([e.to.node])(t))(Q),eC=t=>e=>n=>r=>{const o=tC(n),i=jJ(n),a=ZJ(e);return XJ(r)(VJ(wt(s=>s.tag==="SameLayer"?N("Just",s._1.nodes):w)(e))((()=>{if(t==="LongestPath")return KJ(o)(i)(r)(a);if(t==="NetworkSimplex")return UJ(n)(r)(a);g()})()))},nC=ge(A)(Qt),rC=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},dl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ll=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ea=ge(A)(Qt),oC=ge(A)(Qt),hl=(()=>{const t=Y(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>re(t(e))})(),iC=t=>e=>n=>r=>{const o=nC(Y(a=>L(a.edge,a))(r)),i=a=>0<a.nodes.length&&(()=>{const s=rC(a.edgeId)(n);return s.tag==="Just"&&a.nodes[0]!==s._1._1})();return Y(a=>{if(a.nodes.length<=2){const _=dl(a.edgeId)(o);if(_.tag==="Just"){const l=i(a),f=ka(ba(l?hl(_._1.segments):_._1.segments));return{..._._1,edge:a.edgeId,segments:f,bends:$e(d=>h=>d.end,f,At(1,f.length,f)),reversed:l}}if(_.tag==="Nothing")return{edge:a.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};g()}const s=Et(wt(_=>dl(_)(o))($e(_=>l=>a.edgeId+":"+_+"->"+l,a.nodes,At(1,a.nodes.length,a.nodes))))(_=>_.segments),u=i(a),c=ka(ba(u?hl(s):s));return{edge:a.edgeId,segments:c,bends:$e(_=>l=>_.end,c,At(1,c.length,c)),bendType:[],jumps:[],reversed:u}})(t)},aC={layers:[],edges:[],chains:[]},sC={nodeGap:3,layerGap:2,iterations:8,layerer:YJ,cycleBreaker:Zv,compactPostRouting:!0,compactionSpacings:tv},uC=t=>({pos:L(0,0),size:L(J(e=>n=>ll(e)(n.position._1+n.size._1))(0)(t),J(e=>n=>ll(e)(n.position._2+n.size._2))(0)(t))}),cC=t=>e=>n=>{const r=Ea(Y(c=>L(c.id,c.ports))(e.nodes)),o=lt(c=>Fe(3)(c.node)!=="$d:",n.placements),i=iC(n.withDummies.chains)(n.acyclic.reversedEdges)(oC(Y(c=>L(c.id,L(c.from.node,c.to.node)))(e.edges)))(EJ(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(Md(n.ordered)(lt(c=>c.from.node!==c.to.node,n.withDummies.edges))((()=>{const c=_=>{if(_.tag==="Leaf")return Q;if(_.tag==="Node")return ee("Node",_._1,_._2,_._3,L(_._4._1*4,_._4._2),c(_._5),c(_._6));g()};return c(Ea(Y(_=>L(_.id,_.size))(e.nodes)))})()))),a=t.compactPostRouting?rv()(t.compactionSpacings)({nodes:o,edges:e.edges,paths:i,ports:r}):{nodes:o,edges:i},s=Y(c=>{const _=ka(ba(c.segments));return{...c,segments:_,bends:$e(l=>f=>l.end,_,At(1,_.length,_))}})(a.edges),u=Wt(c=>_=>({..._,jumps:ul(c)(_)(s)}))(s);return{nodes:a.nodes,edges:u,boundingBox:uC(a.nodes),metrics:nd(a.nodes)(u)(0)}},pl=t=>e=>n=>{const r=Ea(Y(i=>L(i.id,i.size))(e.nodes)),o={...n,placements:Dv({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(Ea(Y(i=>L(i.id,i.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(Md(n.ordered)(n.withDummies.edges)((()=>{const i=a=>{if(a.tag==="Leaf")return Q;if(a.tag==="Node")return ee("Node",a._1,a._2,a._3,L(a._4._1*4,a._4._2),i(a._5),i(a._6));g()};return i(r)})()))};return{pipeline:o,result:cC(t)(e)(o)}},gC=t=>e=>n=>pl(t)(e)({...n,ordered:Vv({iterations:t.iterations,constraints:e.constraints,modelOrder:Ea(Wt(r=>o=>L(o.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),_C=t=>e=>n=>gC(t)(e)({...n,withDummies:ov(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),fC=t=>e=>{const n=Y(o=>o.id)(e.nodes),r=oJ(t.cycleBreaker)(n)(e.constraints)(e.edges);return _C(t)(e)({acyclic:r,layered:eC(t.layerer)(e.constraints)(r.edges)(n),withDummies:aC,ordered:[],placements:[]})},Eg=ge(A)(Qt),dC=ge(A)(Qt),lC=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Rr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Pa=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},tu=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},hC=t=>e=>{const n=e.result.nodes,r=Eg(Y(s=>L(s.node,s))(n)),o=dC(Y(s=>L(s.id,s))(t.edges)),i=Y(s=>{const u=lC(s.edge)(o);if(u.tag==="Just"){const c=Rr(u._1.from.node)(r);if(c.tag==="Just"){const _=Rr(u._1.to.node)(r);if(_.tag==="Just"){if(c._1.layer>=_._1.layer||s.jumps.length!==0)return s;const l=nt(4),f=c._1.position._1*l,d=(c._1.position._1+c._1.size._1)*l,h=_._1.position._1*l,m=(_._1.position._1+_._1.size._1)*l,p=Pa(f)(h),x=tu(d)(m);if(p>x)return s;const y=(f+d)*.5,T=(h+m)*.5,v=tu(x)(Pa(p)(c._1.size._1<=_._1.size._1?y:T)),b=(c._1.position._2+c._1.size._2)*l,C=_._1.position._2*l;return(()=>{const S=u._1.from.node,P=u._1.to.node;return ne(F=>{const W=nt(4);return F.node!==S&&F.node!==P&&v>F.position._1*W&&v<(F.position._1+F.size._1)*W&&F.position._2*W<C&&(F.position._2+F.size._2)*W>b},n)})()?s:{...s,segments:[{start:L(v,b),end:L(v,C),direction:xe}],bends:[],bendType:[],jumps:[]}}if(_.tag==="Nothing")return s;g()}if(c.tag==="Nothing")return s;g()}if(u.tag==="Nothing")return s;g()})(e.result.edges),a=Wt(s=>u=>({...u,jumps:ul(s)(u)(i)}))(i);return{...e,result:{...e.result,edges:a,metrics:nd(e.result.nodes)(a)(e.result.metrics.constraintViolations)}}},pC=t=>e=>n=>{const r=n.result.nodes,o=Eg(Y(a=>L(a.node,a))(r)),i=n.result.boundingBox.size._1;return Eg(wt(a=>{const s=Rr(a.id)(o);if(s.tag==="Just"){const u=Rr(a.id)(n.pipeline.layered.nodeLayer);if(u.tag==="Just"){const c=u._1,_=wt(f=>{if(f.from.node===a.id){const d=Rr(f.to.node)(n.pipeline.layered.nodeLayer);if(d.tag==="Just")return d._1<=c?w:Rr(f.to.node)(o);if(d.tag==="Nothing")return w;g()}if(f.to.node===a.id){const d=Rr(f.from.node)(n.pipeline.layered.nodeLayer);if(d.tag==="Just")return d._1>=c?w:Rr(f.from.node)(o);if(d.tag==="Nothing")return w;g()}return w})(e.edges);if(_.length<2)return w;const l=Pt(f=>w,f=>d=>N("Just",{head:f,tail:d}),Y(f=>f.position._1+f.size._1*.5)(_));if(l.tag==="Just"){const f=Pa(a.size._1)(J(Pa)(l._1.head)(l._1.tail)-J(tu)(l._1.head)(l._1.tail)+2),d=s._1.position._1,h=d+s._1.size._1,m=lt(p=>{const x=Rr(p.node)(n.pipeline.layered.nodeLayer);return p.node!==a.id&&(x.tag==="Nothing"?!1:x.tag==="Just"&&x._1===c)},r);return f>a.size._1+.5&&f<=J(p=>x=>x.position._1>=h?tu(p)(x.position._1-nt(t.nodeGap)):p)(i)(m)-J(p=>x=>x.position._1+x.size._1<=d?Pa(p)(x.position._1+x.size._1+nt(t.nodeGap)):p)(0)(m)?N("Just",L(a.id,L(f,a.size._2))):w}if(l.tag==="Nothing")return w;g()}if(u.tag==="Nothing")return w;g()}if(s.tag==="Nothing")return w;g()})(e.nodes))},mC=t=>e=>{const n=fC(t)(e),r=pC(t)(e)(n),o=hC(e)(pl(t)({...e,nodes:Y(i=>{const a=Rr(i.id)(r);if(a.tag==="Just")return{...i,size:a._1};if(a.tag==="Nothing")return i;g()})(e.nodes)})(n.pipeline));return r.tag==="Leaf"||J(i=>a=>i+a.bends.length|0)(0)(o.result.edges)>=J(i=>a=>i+a.bends.length|0)(0)(n.result.edges)?n:o},eu=t=>t,yC=t=>t,Vr=eu("RunText"),Pg=eu("RunCode"),Gg=eu("RunHighlight"),Ag=eu("RunCodeHighlight"),xC=t=>{const e=r=>{const o=Pt(i=>w,i=>a=>N("Just",{head:i,tail:a}),r);if(o.tag==="Nothing")return[];if(o.tag==="Just"){if(o._1.head==="\\"){const i=Pt(a=>w,a=>s=>N("Just",{head:a,tail:s}),o._1.tail);if(i.tag==="Nothing")return[o._1.head];if(i.tag==="Just")return[o._1.head,i._1.head,...e(i._1.tail)];g()}return o._1.head==="="&&0<o._1.tail.length&&o._1.tail[0]==="="?e(At(1,o._1.tail.length,o._1.tail)):[o._1.head,...e(o._1.tail)]}g()},n=Zn("md:")(t);if(n.tag==="Nothing")return t;if(n.tag==="Just")return Qn(e(zn(n._1)));g()},wC=t=>"md:"+t,or=t=>{const e=(()=>{const r=Zn("md:")(t);if(r.tag==="Just")return!0;if(r.tag==="Nothing")return!1;g()})()?wC:yC,n=Ho(`
5
+ `)((()=>{const r=Zn("md:")(t);if(r.tag==="Just")return r._1;if(r.tag==="Nothing")return t;g()})());return n.length===0?[e("")]:Y(e)(n)},Rg=t=>e=>n=>e.length===0?n:St(n)({style:t,text:Qn(e)}),TC=t=>({code:!t.code,highlight:t.highlight,buf:[],runs:Rg((()=>{if(!t.highlight){if(!t.code)return Vr;if(t.code)return Pg;g()}if(t.highlight){if(!t.code)return Gg;if(t.code)return Ag}g()})())(t.buf)(t.runs)}),NC=t=>({code:t.code,highlight:!t.highlight,buf:[],runs:Rg((()=>{if(!t.highlight){if(!t.code)return Vr;if(t.code)return Pg;g()}if(t.highlight){if(!t.code)return Gg;if(t.code)return Ag}g()})())(t.buf)(t.runs)}),vC=t=>e=>0<e.length?{...t,buf:St(t.buf)(e[0])}:{...t,buf:St(t.buf)("\\")},JC=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,c=o,_=Pt(l=>w,l=>f=>N("Just",{head:l,tail:f}),i);if(_.tag==="Nothing"){a=!1,s=c;continue}if(_.tag==="Just"){if(_._1.head==="\\"){r=u,o=vC(c)(_._1.tail),i=At(1,_._1.tail.length,_._1.tail);continue}if(_._1.head==="`"){r=u,o=TC(c),i=_._1.tail;continue}if(u&&_._1.head==="="&&0<_._1.tail.length&&_._1.tail[0]==="="){r=u,o=NC(c),i=At(1,_._1.tail.length,_._1.tail);continue}r=u,o={...c,buf:St(c.buf)(_._1.head)},i=_._1.tail;continue}g()}return s},hr=t=>{const e=JC((()=>{const n=Zn("md:")(t);if(n.tag==="Just")return!0;if(n.tag==="Nothing")return!1;g()})())({code:!1,highlight:!1,buf:[],runs:[]})(zn((()=>{const n=Zn("md:")(t);if(n.tag==="Just")return n._1;if(n.tag==="Nothing")return t;g()})()));return Rg((()=>{if(!e.highlight){if(!e.code)return Vr;if(e.code)return Pg;g()}if(e.highlight){if(!e.code)return Gg;if(e.code)return Ag}g()})())(e.buf)(e.runs)},Xr=(()=>{const t=Wn(""),e=Y(n=>n.text);return n=>t(e(hr(n)))})();let Dg=null;function CC(){return Dg||(typeof document>"u"?null:(Dg=document.createElement("canvas").getContext("2d"),Dg))}const ml=new Map,bC=t=>e=>n=>r=>()=>{const o=`${n} ${e}px ${t}|${r}`,i=ml.get(o);if(i!==void 0)return i;const a=CC();if(!a)return r.length*e*.62;a.font=`${n} ${e}px ${t}`;const s=a.measureText(r).width;return ml.set(o,s),s},kC=_o.traverse(nc),LC=J(_r)(0),Zo=(()=>{const t=tr(`\r
6
+ `)(" "),e=tr(`
7
+ `)(" "),n=(()=>{const r=tr("\r")(" "),o=(()=>{const i=tr(" ")(" ");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),yl=t=>e=>{const n=kC(r=>{const o=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;if(r.style==="RunHighlight")return t.text;if(r.style==="RunCodeHighlight")return t.code;g()})();return bC(o.family)(o.size)(o.weight)(Zo(r.text))})(hr(Zo(e)));return()=>{const r=n();return LC(r)}},xl={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"}},SC=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},qi=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},EC=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},wl=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},PC=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Tl=t=>Qn(re(Jr(e=>e===" ")(re(Jr(e=>e===" ")(zn(t)).rest)).rest)),GC=t=>J(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?N("Just",n._1):e)(w)(Wt(bn)(t)),Fg=t=>e=>{if(t<=0)return[e];if(dr(e)<=t)return[e];const n=zn(e),r=t<1?[]:At(0,t,n),o=GC(r);if(o.tag==="Just"){const i=Tl(Qf(!(o._1>=0&&o._1<r.length)||r[o._1]===" "?o._1:o._1+1|0)(e)),a=Tl(Si(o._1+1|0)(e));return a===""?[i]:[i,...Fg(t)(a)]}if(o.tag==="Nothing"){const i=Qf(t)(e),a=Si(t)(e);return a===""?[i]:[i,...Fg(t)(a)]}g()},AC={cellW:7,cellH:3,maxLineWidth:20},RC=t=>e=>{const n=Y(i=>L((()=>{if(i.label.tag==="Just")return i.label._1;if(i.label.tag==="Nothing")return i.id;g()})(),i))(e.nodes),r=qi(1)(Nr((EC(t.maxLineWidth)(J(i=>a=>qi(i)(dr(a._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),o=(r*t.cellW|0)-1|0;return{...e,nodes:Y(i=>{const a=Et(Ho(`
8
+ `)(i._1))(Fg(o)),s=J(l=>f=>qi(l)(dr(f)))(0)(a),u=qi(1)(Nr(a.length+t.cellH|0,t.cellH))+(i._2.shape==="Cylinder"||i._2.shape==="Document"?1:0)|0,c=i._2.shape==="Cylinder"?qi(1)(Nr((s+2|0)+t.cellW|0,t.cellW)):r,_=s>o?Nr((s+2|0)+t.cellW|0,t.cellW):c;return{...i._2,size:L(i._2.size._1!==1?wl(i._2.size._1)(nt(_)):nt(_),i._2.size._2!==1?i._2.size._2:nt(u))}})(n)}},DC=t=>e=>n=>({...n,nodes:Y(r=>{const o=PC(r.id)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just")return{...r,size:L(wl(r.size._1)(nt(qi(1)(he(ts(r.shape==="Cylinder"?(o._1+0)/t:(o._1+32)/t))))),r.size._2)};g()})(n.nodes)}),nu=t=>t,FC=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ur=nu("TopSide"),Kr=nu("BottomSide"),Zr=nu("LeftSide"),jr=nu("RightSide"),IC=t=>{const e=at.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=at.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Nl=t=>e=>n=>{const r=FC(t.h*.12)(t.w*.2),o=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*nn(IC((()=>{const i=(n-(t.x+o))/o;return 1-i*i})()))},Ye=t=>e=>n=>r=>{let o=t,i=e,a=n,s=r,u=!0,c;for(;u;){const _=o,l=i,f=a,d=s;if(_==="Rectangle"){if(f==="TopSide"){u=!1,c=l.y;continue}if(f==="BottomSide"){u=!1,c=l.y+l.h;continue}if(f==="LeftSide"){u=!1,c=l.x;continue}if(f==="RightSide"){u=!1,c=l.x+l.w;continue}o=ho,i=l,a=f,s=d;continue}if(_==="Cylinder"){if(f==="TopSide"){u=!1,c=Nl(l)(-1)(d);continue}if(f==="BottomSide"){u=!1,c=Nl(l)(1)(d);continue}if(f==="LeftSide"){u=!1,c=l.x;continue}if(f==="RightSide"){u=!1,c=l.x+l.w;continue}}o=ho,i=l,a=f,s=d}return c},vl=t=>e=>{const n=e.y-t.y,r=n<0?-n:n,o=e.x-(t.x+t.w),i=o<0?-o:o,a=e.x-t.x,s=a<0?-a:a,u=e.y-(t.y+t.h),c=u<0?-u:u;return r<=c&&r<=s&&r<=i?Ur:c<=s&&c<=i?Kr:s<=i?Zr:jr},BC=(()=>{const t=wn.unfoldr(gr);return e=>t(Tn("IterNode",e,ur))})(),Ig=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},jo=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Ga=ge(A)(Qt),Bg=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},QC=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},zC=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},MC=J(t=>e=>it(A)(e)()(t))(Q),OC=J(t=>e=>it(A)(e)()(t))(Q),Aa=_o.traverse(nc),Qg=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ra=ge(A)(Qt),WC=t=>e=>Oe(A.compare,Qe,t,e),qC=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},HC=J(t=>e=>it(A)(e)()(t))(Q),$C=ge(A)(Qt),YC=t=>e=>Oe(A.compare,Qe,t,e),VC=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},XC=t=>e=>({...e,edges:Ga(Y(n=>L(n._1,(()=>{const r=Ig(n._1)(t);if(r.tag==="Nothing")return n._2;if(r.tag==="Just"){const o=jo(r._1._2)(e.nodes),i=jo(r._1._1)(e.nodes),a=(()=>{if(i.tag==="Nothing")return n._2;if(i.tag==="Just"){const s=Pt(u=>w,u=>c=>N("Just",{head:u,tail:c}),n._2);if(s.tag==="Nothing")return n._2;if(s.tag==="Just")return[(()=>{const u=Pt(f=>w,f=>d=>N("Just",{head:f,tail:d}),s._1.tail),c=u.tag==="Just"?N("Just",u._1.head):w,_={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},l=(()=>{if(c.tag==="Just"){if((c._1.x>s._1.head.x?c._1.x-s._1.head.x<.5:s._1.head.x-c._1.x<.5)&&s._1.head.x>=_.x-.5&&s._1.head.x<=_.x+_.w+.5)return c._1.y>=_.y+_.h?N("Just",Kr):c._1.y<=_.y?N("Just",Ur):w;if((c._1.y>s._1.head.y?c._1.y-s._1.head.y<.5:s._1.head.y-c._1.y<.5)&&s._1.head.y>=_.y-.5&&s._1.head.y<=_.y+_.h+.5){if(c._1.x>=_.x+_.w)return N("Just",jr);if(c._1.x<=_.x)return N("Just",Zr)}return w}if(c.tag==="Nothing")return w;g()})();if(l.tag==="Just"){if(l._1==="TopSide")return{...s._1.head,y:Ye(i._1.shape)(_)(Ur)(s._1.head.x)};if(l._1==="BottomSide")return{...s._1.head,y:Ye(i._1.shape)(_)(Kr)(s._1.head.x)};if(l._1==="LeftSide")return{...s._1.head,x:Ye(i._1.shape)(_)(Zr)(s._1.head.y)};if(l._1==="RightSide")return{...s._1.head,x:Ye(i._1.shape)(_)(jr)(s._1.head.y)};g()}if(l.tag==="Nothing"){const f={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},d=vl(f)(s._1.head);if(d==="TopSide")return{...s._1.head,y:Ye(i._1.shape)(f)(Ur)(s._1.head.x)};if(d==="BottomSide")return{...s._1.head,y:Ye(i._1.shape)(f)(Kr)(s._1.head.x)};if(d==="LeftSide")return{...s._1.head,x:Ye(i._1.shape)(f)(Zr)(s._1.head.y)};if(d==="RightSide")return{...s._1.head,x:Ye(i._1.shape)(f)(jr)(s._1.head.y)}}g()})(),...s._1.tail]}g()})();if(o.tag==="Nothing")return a;if(o.tag==="Just"){const s=Or(a);if(s.tag==="Nothing")return a;if(s.tag==="Just")return St(s._1.init)((()=>{const u=Or(s._1.init),c=u.tag==="Just"?N("Just",u._1.last):w,_={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},l=(()=>{if(c.tag==="Just"){if((c._1.x>s._1.last.x?c._1.x-s._1.last.x<.5:s._1.last.x-c._1.x<.5)&&s._1.last.x>=_.x-.5&&s._1.last.x<=_.x+_.w+.5)return c._1.y>=_.y+_.h?N("Just",Kr):c._1.y<=_.y?N("Just",Ur):w;if((c._1.y>s._1.last.y?c._1.y-s._1.last.y<.5:s._1.last.y-c._1.y<.5)&&s._1.last.y>=_.y-.5&&s._1.last.y<=_.y+_.h+.5){if(c._1.x>=_.x+_.w)return N("Just",jr);if(c._1.x<=_.x)return N("Just",Zr)}return w}if(c.tag==="Nothing")return w;g()})();if(l.tag==="Just"){if(l._1==="TopSide")return{...s._1.last,y:Ye(o._1.shape)(_)(Ur)(s._1.last.x)};if(l._1==="BottomSide")return{...s._1.last,y:Ye(o._1.shape)(_)(Kr)(s._1.last.x)};if(l._1==="LeftSide")return{...s._1.last,x:Ye(o._1.shape)(_)(Zr)(s._1.last.y)};if(l._1==="RightSide")return{...s._1.last,x:Ye(o._1.shape)(_)(jr)(s._1.last.y)};g()}if(l.tag==="Nothing"){const f={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},d=vl(f)(s._1.last);if(d==="TopSide")return{...s._1.last,y:Ye(o._1.shape)(f)(Ur)(s._1.last.x)};if(d==="BottomSide")return{...s._1.last,y:Ye(o._1.shape)(f)(Kr)(s._1.last.x)};if(d==="LeftSide")return{...s._1.last,x:Ye(o._1.shape)(f)(Zr)(s._1.last.y)};if(d==="RightSide")return{...s._1.last,x:Ye(o._1.shape)(f)(jr)(s._1.last.y)}}g()})())}}g()})()))(BC(e.edges)))}),UC=t=>e=>n=>{const r=te(o=>o.id===n)(t.graph.edges);if(r.tag==="Just")return N("Just",r._1);if(r.tag==="Nothing")return Ig(n)(e);g()},KC=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 o=jo(r.node)(e);if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return r.node;g()})(),shape:(()=>{const o=jo(r.node)(n);if(o.tag==="Nothing")return ho;if(o.tag==="Just")return o._1;g()})()}),ZC=t=>({id:t,size:L(1,1),ports:[],label:N("Just",t),shape:ho}),Jl=t=>e=>n=>{const r=wt(i=>jo(e)(i.labels))(t.keyframes),o=Pt(i=>w,i=>a=>N("Just",{head:i,tail:a}),r);if(o.tag==="Nothing")return[n];if(o.tag==="Just")return[n,...r];g()},jC=t=>e=>n=>r=>L(r.node,KC(t)(e)(n)(r)),Cl=t=>or(t),bl=t=>{const e=Ho(`
9
+ `)(t),n=e.length===0?[""]:e;return n.length*Bg(1)(J(r=>o=>Bg(r)(dr(o)))(0)(n))|0},tb=t=>{const e=Pt(n=>w,n=>r=>N("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return"";if(e.tag==="Just")return J(n=>r=>bl(r)>bl(n)?r:n)(e._1.head)(e._1.tail);g()},eb=t=>e=>tb(Jl(t)(e.id)((()=>{if(e.label.tag==="Just")return e.label._1;if(e.label.tag==="Nothing")return e.id;g()})())),kl=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,pt("Cons",n._4,e(n._6,r)));g()};return Ot(ue.foldr,e(t.interiors,G))},nb=t=>Ga(wt(e=>N("Just",L(e.edge,{id:e.edge,from:{node:e.from,port:w},to:{node:e.to,port:w},label:w})))(Et(t.scenes)(e=>e.tag==="DataFlow"?wt(n=>n.kind.tag==="SendToken"?N("Just",n.kind._1):w)(e._1.events):[]))),Ll=t=>{const e=Hy(t),n=Y(o=>({...o,label:N("Just",eb(t)(o))}))(lt(o=>QC(o.id)(e.nodes),t.graph.nodes)),r=lt(o=>zC(o.id)(e.edges),t.graph.edges);return{nodes:[...n,...Y(ZC)(Ot(pn.foldr,cr(A.compare,e.nodes,MC(Y(o=>o.id)(n)))))],edges:[...r,...wt(UC(t)(nb(t)))(Ot(pn.foldr,cr(A.compare,e.edges,OC(Y(o=>o.id)(r)))))],constraints:t.graph.constraints}},rb=t=>{const e=Aa(n=>{const r=Aa(yl(xl))(Jl(t)(n.id)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})()));return()=>{const o=r();return L(n.id,J(Qg)(0)(o))}})(Ll(t).nodes);return()=>{const n=e();return Ra(n)}},Sl=t=>{const e=rb(t);return()=>{const n=e(),r=Aa(Sl)(kl(t))();return J(WC)(n)(r)}},ob=t=>e=>{const n=Pt(r=>w,r=>o=>N("Just",{head:r,tail:o}),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},...Y(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];g()},ib=t=>e=>{const n=Ra(Y(r=>L(r.id,r))(t.nodes));return{...e,nodes:Y(r=>{const o=jo(r.id)(n);return o.tag==="Just"&&o._1.size._2===1?{...r,size:L(r.size._1,qC(r.size._2)(nt(Bg(1)(Nr(or((()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;g()})()).length+3|0,3))+(r.shape==="Cylinder"||r.shape==="Document"?1:0)|0)))}:r})(e.nodes)}},ab=t=>e=>L(e.edge,ob(t)(e)),sb=t=>e=>n=>r=>({nodes:Ra(Y(jC(nt(4)*t)(e)(n))(r.nodes)),edges:Ga(Y(ab(t))(r.edges)),chipExtras:Q,edgeLabels:Q}),ub=t=>e=>({...XC(Ga(Y(n=>L(n.id,L(n.from.node,n.to.node)))(e.edges)))(sb(8)(Ra(Y(n=>L(n.id,(()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})()))(e.nodes)))(Ra(Y(n=>L(n.id,n.shape))(e.nodes)))(mC(sC)(e).result)),edgeLabels:Ga(wt(n=>n.label.tag==="Just"?N("Just",L(n.id,n.label._1)):w)(e.edges))}),cb=t=>J(e=>n=>{if(n.tag==="Structural")return e;if(n.tag==="DataFlow")return J(r=>o=>{if(o.kind.tag==="SendToken")return J(i=>a=>it(A)(a)()(i))(r)(o.kind._1.labels);if(o.kind.tag==="FillNodeWithoutTransition")return J(i=>a=>it(A)(a)()(i))(r)(o.kind._1.labels);g()})(e)(n._1.events);if(n.tag==="Hold"||n.tag==="EnterNode"||n.tag==="ExitNode"||n.tag==="StepScene")return e;g()})(Q)(t.scenes),gb=t=>{const e=Aa(n=>{const r=yl(xl)(n);return()=>{const o=r();return L(n,{labelW:o,charCount:dr(Xr(Zo(n))),lineCount:1})}})(Ot(pn.foldr,HC(Et(Ot(pn.foldr,cb(t)))(Cl))));return()=>{const n=e();return $C(n)}},El=t=>{const e=gb(t);return()=>{const n=e(),r=Aa(El)(kl(t))();return J(YC)(n)(r)}},_b=nt(4)*8,fb=t=>Et(t.scenes)(e=>{if(e.tag==="Structural")return[];if(e.tag==="DataFlow")return e._1.events;if(e.tag==="Hold")return[];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];if(e.tag==="StepScene")return[];g()}),db=t=>e=>n=>{const r=o=>{const i=wt(a=>{const s=VC(a)(t);return s.tag==="Just"?N("Just",{w:s._1.labelW+28,h:nt(SC(1)(s._1.lineCount))*13.2+12}):w})(Et(o)(Cl));return i.length===0?w:N("Just",{w:J(Qg)(0)(Y(a=>a.w)(i)),h:J(Qg)(0)(Y(a=>a.h)(i))})};return J(o=>i=>{if(i.kind.tag==="SendToken"){const a=Ig(i.kind._1.edge)(n.edges),s=r(i.kind._1.labels);if(s.tag==="Just"&&a.tag==="Just"){const u=s._1;return zt(A)(we)(i.kind._1.edge)(Y(c=>({x:c.x+14+u.w,y:c.y-6-8-u.h}))(a._1))(o)}return o}if(i.kind.tag==="FillNodeWithoutTransition"){const a=jo(i.kind._1.node)(n.nodes),s=r(i.kind._1.labels);return s.tag==="Just"&&a.tag==="Just"?zt(A)(we)("__fill__:"+i.kind._1.node)((()=>{const u=a._1.y-s._1.h-14,c=a._1.x+a._1.w/2,_=c-s._1.w/2,l=c+s._1.w/2,f=a._1.y-14;return[{x:_,y:u},{x:l,y:u},{x:_,y:f},{x:l,y:f}]})())(o):o}g()})(Q)(fb(e))},Pl=t=>e=>n=>{const r=Ll(n);return{layout:(()=>{const o=ub()(ib(r)(DC(_b)(t)(RC(AC)(r))));return{...o,chipExtras:db(e)(n)(o)}})(),interiors:(()=>{const o=Pl(t)(e),i=a=>{if(a.tag==="Leaf")return Q;if(a.tag==="Node")return ee("Node",a._1,a._2,a._3,o(a._4),i(a._5),i(a._6));g()};return i(n.interiors)})()}},Gl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},zg=t=>e=>n=>{const r=t<.05?t:.05,o=(a,s)=>{if(s.tag==="Leaf")return a;if(s.tag==="Node")return o((()=>{const u=Gl(s._3)(n),c=(()=>{if(u.tag==="Just")return u._1;if(u.tag==="Nothing")return{x:s._4.x,y:s._4.y,vx:0,vy:0};g()})(),_=c.vx+(180*(s._4.x-c.x)-22*c.vx)*r,l=c.vy+(180*(s._4.y-c.y)-22*c.vy)*r;return it(A)(s._3)({x:c.x+_*r,y:c.y+l*r,vx:_,vy:l})(o(a,s._5))})(),s._6);g()},i=o(Q,e);return{springs:i,applied:(()=>{const a=(s,u)=>{if(u.tag==="Leaf")return s;if(u.tag==="Node")return a((()=>{const c=a(s,u._5),_=Gl(u._3)(i);if(_.tag==="Just")return it(A)(u._3)({...u._4,x:_._1.x,y:_._1.y})(c);if(_.tag==="Nothing")return it(A)(u._3)(u._4)(c);g()})(),u._6);g()};return a(Q,e)})()}},K=(t,e)=>({tag:"CatQueue",_1:t,_2:e}),lb=t=>{let e=t,n=!0,r;for(;n;){const o=e;if(o._1.tag==="Nil"){if(o._2.tag==="Nil"){n=!1,r=w;continue}e=K((i=>a=>{let s=i,u=a,c=!0,_;for(;c;){const l=s,f=u;if(f.tag==="Nil"){c=!1,_=l;continue}if(f.tag==="Cons"){s=pt("Cons",f._1,l),u=f._2;continue}g()}return _})(G)(o._2),G);continue}if(o._1.tag==="Cons"){n=!1,r=N("Just",L(o._1._1,K(o._1._2,o._2)));continue}g()}return r},Z=(t,e,n)=>({tag:t,_1:e,_2:n}),ct=Z("CatNil"),hb=t=>e=>{if(t.tag==="CatNil")return e;if(e.tag==="CatNil")return t;if(t.tag==="CatCons")return Z("CatCons",t._1,K(t._2._1,pt("Cons",e,t._2._2)));g()},pb=t=>e=>n=>{const r=o=>i=>a=>{let s=o,u=i,c=a,_=!0,l;for(;_;){const f=s,d=u,h=c;if(h.tag==="Nil"){_=!1,l=d;continue}if(h.tag==="Cons"){s=f,u=f(d)(h._1),c=h._2;continue}g()}return l};return(o=>i=>{let a=o,s=i,u=!0,c;for(;u;){const _=a,l=s,f=lb(_);if(f.tag==="Nothing"){u=!1,c=r(d=>h=>h(d))(e)(l);continue}if(f.tag==="Just"){a=f._1._2,s=pt("Cons",t(f._1._1),l);continue}g()}return c})(n)(G)},mb=t=>{if(t.tag==="CatNil")return w;if(t.tag==="CatCons")return N("Just",L(t._1,t._2._1.tag==="Nil"&&t._2._2.tag==="Nil"?ct:pb(hb)(ct)(t._2)));g()},U=(t,e)=>({tag:"Free",_1:t,_2:e}),st=(t,e,n)=>({tag:t,_1:e,_2:n}),Al=t=>{let e=t,n=!0,r;for(;n;){const o=e;if(o._1.tag==="Return"){const i=mb(o._2);if(i.tag==="Nothing"){n=!1,r=st("Return",o._1._1);continue}if(i.tag==="Just"){e=(()=>{const a=i._1._1(o._1._1);return U(a._1,(()=>{if(a._2.tag==="CatNil")return i._1._2;if(i._1._2.tag==="CatNil")return a._2;if(a._2.tag==="CatCons")return Z("CatCons",a._2._1,K(a._2._2._1,pt("Cons",i._1._2,a._2._2._2)));g()})())})();continue}g()}if(o._1.tag==="Bind"){n=!1,r=st("Bind",o._1._1,i=>{const a=o._1._2(i);return U(a._1,(()=>{if(a._2.tag==="CatNil")return o._2;if(o._2.tag==="CatNil")return a._2;if(a._2.tag==="CatCons")return Z("CatCons",a._2._1,K(a._2._2._1,pt("Cons",o._2,a._2._2._2)));g()})())});continue}g()}return r},yb=t=>e=>{const n=e.Monad0(),r=n.Bind1().Apply0().Functor0();return o=>e.tailRecM(i=>{const a=Al(i);if(a.tag==="Return")return r.map(Hm)(n.Applicative0().pure(a._1));if(a.tag==="Bind")return r.map(rc)(o(t.map(a._2)(a._1)));g()})},xb=t=>e=>n=>{const r=Al(n);if(r.tag==="Return")return e(r._1);if(r.tag==="Bind")return t(r._1)(r._2);g()},Mg={Applicative0:()=>No,Bind1:()=>Rl},wb={map:t=>e=>Rl.bind(e)(n=>No.pure(t(n)))},Rl={bind:t=>e=>U(t._1,(()=>{if(t._2.tag==="CatNil")return Z("CatCons",e,K(G,G));if(t._2.tag==="CatCons")return Z("CatCons",t._2._1,K(t._2._2._1,pt("Cons",Z("CatCons",e,K(G,G)),t._2._2._2)));g()})()),Apply0:()=>Dl},Dl={apply:t=>e=>{const n=r=>U(e._1,(()=>{if(e._2.tag==="CatNil")return Z("CatCons",o=>No.pure(r(o)),K(G,G));if(e._2.tag==="CatCons")return Z("CatCons",e._2._1,K(e._2._2._1,pt("Cons",Z("CatCons",o=>No.pure(r(o)),K(G,G)),e._2._2._2)));g()})());return U(t._1,(()=>{if(t._2.tag==="CatNil")return Z("CatCons",n,K(G,G));if(t._2.tag==="CatCons")return Z("CatCons",t._2._1,K(t._2._2._1,pt("Cons",Z("CatCons",n,K(G,G)),t._2._2._2)));g()})())},Functor0:()=>wb},No={pure:t=>U(st("Return",t),ct),Apply0:()=>Dl},Tb=()=>()=>()=>t=>e=>n=>Pm(n.type)(t)?Gm(n.type)(t)(n.value):e(n),Nb={map:t=>e=>({type:e.type,value:e.map(t)(e.value),map:e.map})},vb=t=>qf("Data.Functor.Variant: pattern match failure ["+t.type+"]"),Jb=()=>()=>()=>t=>Tb()()()(t)(vb);(function(){var t={},e="Pure",n="Throw",r="Catch",o="Sync",i="Async",a="Bind",s="Bracket",u="Fork",c="Sequential",_="Map",l="Apply",f="Alt",d="Cons",h="Resume",m="Release",p="Finalizer",x="Finalized",y="Forked";function T(M,j,z,q){this.tag=M,this._1=j,this._2=z,this._3=q}function v(M){var j=function(z,q,H){return new T(M,z,q,H)};return j.tag=M,j}function b(M){return new T(e,void 0)}function C(M){try{M()}catch(j){setTimeout(function(){throw j},0)}}function S(M,j,z){try{return j(z())}catch(q){return M(q)}}function P(M,j,z){try{return j(z)()}catch(q){return z(M(q))(),b}}var F=(function(){var M=1024,j=0,z=0,q=new Array(M),H=!1;function O(){var ot;for(H=!0;j!==0;)j--,ot=q[z],q[z]=void 0,z=(z+1)%M,ot();H=!1}return{isDraining:function(){return H},enqueue:function(ot){var tt;j===M&&(tt=H,O(),H=tt),q[(z+j)%M]=ot,j++,H||O()}}})();function W(M){var j={},z=0,q=0;return{register:function(H){var O=z++;H.onComplete({rethrow:!0,handler:function(ot){return function(){q--,delete j[O]}}})(),j[O]=H,q++},isEmpty:function(){return q===0},killAll:function(H,O){return function(){if(q===0)return O();var ot=0,tt={};function gt(ft){tt[ft]=j[ft].kill(H,function(Tt){return function(){delete tt[ft],ot--,M.isLeft(Tt)&&M.fromLeft(Tt)&&setTimeout(function(){throw M.fromLeft(Tt)},0),ot===0&&O()}})()}for(var Lt in j)j.hasOwnProperty(Lt)&&(ot++,gt(Lt));return j={},z=0,q=0,function(ft){return new T(o,function(){for(var Tt in tt)tt.hasOwnProperty(Tt)&&tt[Tt]()})}}}}}var E=0,R=1,et=2,rt=3,$=4,X=5,V=6;function D(M,j,z){var q=0,H=E,O=z,ot=null,tt=null,gt=null,Lt=null,ft=null,Tt=0,kt=0,Kt=null,Nt=!0;function Xt(dt){for(var xt,Dt,ht;;)switch(xt=null,Dt=null,ht=null,H){case et:H=R;try{O=gt(O),Lt===null?gt=null:(gt=Lt._1,Lt=Lt._2)}catch(Mt){H=X,ot=M.left(Mt),O=null}break;case rt:M.isLeft(O)?(H=X,ot=O,O=null):gt===null?H=X:(H=et,O=M.fromRight(O));break;case R:switch(O.tag){case a:gt&&(Lt=new T(d,gt,Lt)),gt=O._2,H=R,O=O._1;break;case e:gt===null?(H=X,O=M.right(O._1)):(H=et,O=O._1);break;case o:H=rt,O=S(M.left,M.right,O._1);break;case i:H=$,O=P(M.left,O._1,function(Mt){return function(){q===dt&&(q++,F.enqueue(function(){q===dt+1&&(H=rt,O=Mt,Xt(q))}))}});return;case n:H=X,ot=M.left(O._1),O=null;break;case r:gt===null?ft=new T(d,O,ft,tt):ft=new T(d,O,new T(d,new T(h,gt,Lt),ft,tt),tt),gt=null,Lt=null,H=R,O=O._1;break;case s:Tt++,gt===null?ft=new T(d,O,ft,tt):ft=new T(d,O,new T(d,new T(h,gt,Lt),ft,tt),tt),gt=null,Lt=null,H=R,O=O._1;break;case u:H=rt,xt=D(M,j,O._2),j&&j.register(xt),O._1&&xt.run(),O=M.right(xt);break;case c:H=R,O=I(M,j,O._1);break}break;case X:if(gt=null,Lt=null,ft===null)H=V,O=tt||ot||O;else switch(xt=ft._3,ht=ft._1,ft=ft._2,ht.tag){case r:tt&&tt!==xt&&Tt===0?H=X:ot&&(H=R,O=ht._2(M.fromLeft(ot)),ot=null);break;case h:tt&&tt!==xt&&Tt===0||ot?H=X:(gt=ht._1,Lt=ht._2,H=et,O=M.fromRight(O));break;case s:Tt--,ot===null&&(Dt=M.fromRight(O),ft=new T(d,new T(m,ht._2,Dt),ft,xt),(tt===xt||Tt>0)&&(H=R,O=ht._3(Dt)));break;case m:ft=new T(d,new T(x,O,ot),ft,tt),H=R,tt&&tt!==xt&&Tt===0?O=ht._1.killed(M.fromLeft(tt))(ht._2):ot?O=ht._1.failed(M.fromLeft(ot))(ht._2):O=ht._1.completed(M.fromRight(O))(ht._2),ot=null,Tt++;break;case p:Tt++,ft=new T(d,new T(x,O,ot),ft,tt),H=R,O=ht._1;break;case x:Tt--,H=X,O=ht._1,ot=ht._2;break}break;case V:for(var Jt in Kt)Kt.hasOwnProperty(Jt)&&(Nt=Nt&&Kt[Jt].rethrow,C(Kt[Jt].handler(O)));Kt=null,tt&&ot?setTimeout(function(){throw M.fromLeft(ot)},0):M.isLeft(O)&&Nt&&setTimeout(function(){if(Nt)throw M.fromLeft(O)},0);return;case E:H=R;break;case $:return}}function Ft(dt){return function(){if(H===V)return Nt=Nt&&dt.rethrow,dt.handler(O)(),function(){};var xt=kt++;return Kt=Kt||{},Kt[xt]=dt,function(){Kt!==null&&delete Kt[xt]}}}function vt(dt,xt){return function(){if(H===V)return xt(M.right(void 0))(),function(){};var Dt=Ft({rethrow:!1,handler:function(){return xt(M.right(void 0))}})();switch(H){case E:tt=M.left(dt),H=V,O=tt,Xt(q);break;case $:tt===null&&(tt=M.left(dt)),Tt===0&&(H===$&&(ft=new T(d,new T(p,O(dt)),ft,tt)),H=X,O=null,ot=null,Xt(++q));break;default:tt===null&&(tt=M.left(dt)),Tt===0&&(H=X,O=null,ot=null)}return Dt}}function yt(dt){return function(){var xt=Ft({rethrow:!1,handler:dt})();return H===E&&Xt(q),xt}}return{kill:vt,join:yt,onComplete:Ft,isSuspended:function(){return H===E},run:function(){H===E&&(F.isDraining()?Xt(q):F.enqueue(function(){Xt(q)}))}}}function B(M,j,z,q){var H=0,O={},ot=0,tt={},gt=new Error("[ParAff] Early exit"),Lt=null,ft=t;function Tt(Ft,vt,yt){var dt=vt,xt=null,Dt=null,ht=0,Jt={},Mt,Bt;t:for(;;)switch(Mt=null,dt.tag){case y:if(dt._3===t&&(Mt=O[dt._1],Jt[ht++]=Mt.kill(Ft,function(ie){return function(){ht--,ht===0&&yt(ie)()}})),xt===null)break t;dt=xt._2,Dt===null?xt=null:(xt=Dt._1,Dt=Dt._2);break;case _:dt=dt._2;break;case l:case f:xt&&(Dt=new T(d,xt,Dt)),xt=dt,dt=dt._1;break}if(ht===0)yt(M.right(void 0))();else for(Bt=0,Mt=ht;Bt<Mt;Bt++)Jt[Bt]=Jt[Bt]();return Jt}function kt(Ft,vt,yt){var dt,xt,Dt,ht,Jt,Mt;for(M.isLeft(Ft)?(dt=Ft,xt=null):(xt=Ft,dt=null);;){if(Dt=null,ht=null,Jt=null,Mt=null,Lt!==null)return;if(vt===null){q(dt||xt)();return}if(vt._3!==t)return;switch(vt.tag){case _:dt===null?(vt._3=M.right(vt._1(M.fromRight(xt))),xt=vt._3):vt._3=dt;break;case l:if(Dt=vt._1._3,ht=vt._2._3,dt){if(vt._3=dt,Jt=!0,Mt=ot++,tt[Mt]=Tt(gt,dt===Dt?vt._2:vt._1,function(){return function(){delete tt[Mt],Jt?Jt=!1:yt===null?kt(dt,null,null):kt(dt,yt._1,yt._2)}}),Jt){Jt=!1;return}}else{if(Dt===t||ht===t)return;xt=M.right(M.fromRight(Dt)(M.fromRight(ht))),vt._3=xt}break;case f:if(Dt=vt._1._3,ht=vt._2._3,Dt===t&&M.isLeft(ht)||ht===t&&M.isLeft(Dt))return;if(Dt!==t&&M.isLeft(Dt)&&ht!==t&&M.isLeft(ht))dt=xt===Dt?ht:Dt,xt=null,vt._3=dt;else if(vt._3=xt,Jt=!0,Mt=ot++,tt[Mt]=Tt(gt,xt===Dt?vt._2:vt._1,function(){return function(){delete tt[Mt],Jt?Jt=!1:yt===null?kt(xt,null,null):kt(xt,yt._1,yt._2)}}),Jt){Jt=!1;return}break}yt===null?vt=null:(vt=yt._1,yt=yt._2)}}function Kt(Ft){return function(vt){return function(){delete O[Ft._1],Ft._3=vt,kt(vt,Ft._2._1,Ft._2._2)}}}function Nt(){var Ft=R,vt=z,yt=null,dt=null,xt,Dt;t:for(;;)switch(xt=null,Dt=null,Ft){case R:switch(vt.tag){case _:yt&&(dt=new T(d,yt,dt)),yt=new T(_,vt._1,t,t),vt=vt._2;break;case l:yt&&(dt=new T(d,yt,dt)),yt=new T(l,t,vt._2,t),vt=vt._1;break;case f:yt&&(dt=new T(d,yt,dt)),yt=new T(f,t,vt._2,t),vt=vt._1;break;default:Dt=H++,Ft=X,xt=vt,vt=new T(y,Dt,new T(d,yt,dt),t),xt=D(M,j,xt),xt.onComplete({rethrow:!1,handler:Kt(vt)})(),O[Dt]=xt,j&&j.register(xt)}break;case X:if(yt===null)break t;yt._1===t?(yt._1=vt,Ft=R,vt=yt._2,yt._2=t):(yt._2=vt,vt=yt,dt===null?yt=null:(yt=dt._1,dt=dt._2))}for(ft=vt,Dt=0;Dt<H;Dt++)O[Dt].run()}function Xt(Ft,vt){Lt=M.left(Ft);var yt;for(var dt in tt)if(tt.hasOwnProperty(dt)){yt=tt[dt];for(dt in yt)yt.hasOwnProperty(dt)&&yt[dt]()}tt=null;var xt=Tt(Ft,ft,vt);return function(Dt){return new T(i,function(ht){return function(){for(var Jt in xt)xt.hasOwnProperty(Jt)&&xt[Jt]();return b}})}}return Nt(),function(Ft){return new T(i,function(vt){return function(){return Xt(Ft,vt)}})}}function I(M,j,z){return new T(i,function(q){return function(){return B(M,j,z,q)}})}return T.EMPTY=t,T.Pure=v(e),T.Throw=v(n),T.Catch=v(r),T.Sync=v(o),T.Async=v(i),T.Bind=v(a),T.Bracket=v(s),T.Fork=v(u),T.Seq=v(c),T.ParMap=v(_),T.ParApply=v(l),T.ParAlt=v(f),T.Fiber=D,T.Supervisor=W,T.Scheduler=F,T.nonCanceler=b,T})();const Cb=t=>e=>xb(n=>r=>t({type:n.type,value:n.map(o=>r(o))(n.value),map:n.map}))(e),bb=t=>{const e=t.Bind1(),n=t.Applicative0().pure;return r=>{const o=Sm(()=>Cb(i=>e.bind(r(i))(o()))(n));return o()}};let Fl=null;function kb(){return Fl||(typeof document>"u"?null:Fl=document.createElement("canvas").getContext("2d"))}const Og=new Map;function Il(t,e,n,r,o,i){const a=`${n} ${e}px ${t}`,s=a+"|"+r;if(Og.has(s))return Og.get(s);const u=kb();if(!u)return i;u.font=a;const c=o(u.measureText(r)),_=typeof document<"u"?document.fonts:null;if(!_||_.check(a))Og.set(s,c);else if(_&&_.load)try{_.load(a)}catch{}return c}const Lb=(t,e,n,r)=>Il(t,e,n,r,o=>o.width,-1),Sb=(t,e,n,r)=>Il(t,e,n,r,o=>({ascent:o.actualBoundingBoxAscent,descent:o.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),ru=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Bl=t=>t,Ql={map:t=>e=>{if(e.tag==="MeasureText")return ru("MeasureText",e._1,e._2,n=>t(e._3(n)));if(e.tag==="MeasureInk")return ru("MeasureInk",e._1,e._2,n=>t(e._3(n)));g()}},Wg=t=>e=>{const n=Lb(t.family,t.size,t.weight,Zo(e));return n<0?nt(gn(e).length)*t.size*.62:n},qg=t=>e=>{const n=Sb(t.family,t.size,t.weight,Zo(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},Eb=t=>e=>U(st("Bind",{type:"metrics",value:ru("MeasureInk",t,e,Bl),map:Ql.map},n=>U(st("Return",n),ct)),ct),to=t=>e=>U(st("Bind",{type:"metrics",value:ru("MeasureText",t,e,Bl),map:Ql.map},n=>U(st("Return",n),ct)),ct),zl=t=>t,Ml=t=>t,ou=t=>t,Ol=t=>t,Wl=t=>t,Vt=(t,e,n,r,o)=>({tag:t,_1:e,_2:n,_3:r,_4:o}),ql=t=>t,Hg=t=>t,Pb=Hg("BaselineTop"),Nn=Hg("BaselineMiddle"),Gb=Hg("BaselineBottom"),vo=ql("AlignLeft"),eo=ql("AlignCenter"),Ve=Wl("RoundJoin"),Da=Wl("MiterJoin"),Pn=Ol("ButtCap"),ir=Ol("RoundCap"),Ab=ou("LayerPolyOut"),Rb=ou("LayerPolyIn"),Db=ou("LayerNodeMask"),Fb=ou("LayerOverlay"),Jo=Ml("NonZero"),$g=Ml("EvenOdd"),Hl=zl("Normal"),iu=zl("Difference"),ve={r:255,g:255,b:255,a:255},ti=[5],be={map:t=>e=>{if(e.tag==="FillPath")return Vt("FillPath",e._1,e._2,t(e._3));if(e.tag==="StrokePath")return Vt("StrokePath",e._1,e._2,t(e._3));if(e.tag==="FillStrokePath")return Vt("FillStrokePath",e._1,e._2,e._3,t(e._4));if(e.tag==="DrawText")return Vt("DrawText",e._1,t(e._2));if(e.tag==="DrawTextAffine")return Vt("DrawTextAffine",e._1,e._2,t(e._3));if(e.tag==="PushTransform")return Vt("PushTransform",e._1,t(e._2));if(e.tag==="PopTransform")return Vt("PopTransform",t(e._1));if(e.tag==="PushClip")return Vt("PushClip",e._1,e._2,t(e._3));if(e.tag==="PopClip")return Vt("PopClip",t(e._1));if(e.tag==="PushBlend")return Vt("PushBlend",e._1,t(e._2));if(e.tag==="PopBlend")return Vt("PopBlend",t(e._1));if(e.tag==="PushAlpha")return Vt("PushAlpha",e._1,t(e._2));if(e.tag==="PopAlpha")return Vt("PopAlpha",t(e._1));if(e.tag==="PushBlur")return Vt("PushBlur",e._1,t(e._2));if(e.tag==="PopBlur")return Vt("PopBlur",t(e._1));if(e.tag==="PushLayer")return Vt("PushLayer",e._1,t(e._2));if(e.tag==="PopLayer")return Vt("PopLayer",t(e._1));if(e.tag==="SetViewport")return Vt("SetViewport",e._1,t(e._2));if(e.tag==="ClearBackground")return Vt("ClearBackground",e._1,t(e._2));if(e.tag==="BackgroundDots")return Vt("BackgroundDots",e._1,t(e._2));g()}},no={r:26,g:26,b:26,a:255},Yg=t=>e=>Math.imul(t,e),Hi=t=>{const e=t+1831565813|0,n=Yg(e^e>>>15)(e|1),r=n^(n+Yg(n^n>>>7)(n|61)|0),o=r^r>>>14;return{prng:o,value:o<0?(nt(o)+4294967296)/4294967296:nt(o)/4294967296}},Ie=t=>e=>n=>{const r=Hi(n);return{prng:r.prng,value:t+r.value*(e-t)}},Vg=t=>e=>J(n=>r=>Yg(n^r)(-2048144789))(e)(Y(xo)(zn(t))),Ib=t=>t,$l=t=>t,Bb=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},vn=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Yl=t=>e=>n=>{const r=ut.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ut.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Xg=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Qb=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},zb=$l("FlatLevel"),Mb=$l("NestedLevel"),Ug=Ib("GenieSilhouette"),Ob=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const o=Hi(t);return{prng:o.prng,yLift:o.value*n.yJitter*r}},Wb=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const o=Hi(t);return{prng:o.prng,dx:(o.value*2-1)*n.xJitter*r}},Vl=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,o=nn(r*r+n*n),i=(t.r*t.r-e.r*e.r+o*o)/(2*o),a=nn(Bb(0)(t.r*t.r-i*i)),s=t.cx+i*r/o,u=t.cy+i*n/o,c={x:s-a*n/o,y:u+a*r/o},_={x:s+a*n/o,y:u-a*r/o};return o===0||o>t.r+e.r?{x:(t.cx+e.cx)/2,y:t.cy}:c.y<_.y?c:_},$i=t=>e=>{const n=vn(e)(vn(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},qb=t=>e=>n=>r=>o=>i=>{if(e)return{prng:t,r:o};if(n)return{prng:t,r:o*(1+i.rJitter)};if(r)return{prng:t,r:o*i.smallScale};const a=Hi(t);return{prng:a.prng,r:o*(1+a.value*i.rJitter)}},Xl=t=>{const e=vn(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]},Hb=t=>e=>n=>{const r=Hi(t),o=e.length;return o===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const i=Yl(0)(o-1|0)(he(Kn(r.value*nt(n))));return i>=0&&i<e.length?e[i]:-1})()}},$b=t=>e=>{const n=Hi(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const o=Yl(0)(r-1|0)(he(Kn(n.value*nt(r))));return o>=0&&o<e.length?e[o]:-1})()}},Ul=t=>{const e=vn(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]},Kl=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],Zl={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},Yb=t=>{const e=vn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,o=t.x+n;return[1,t.x,r,4,t.x,r+.5522847498*e,o-.5522847498*n,r+e,o,r+e,4,o+.5522847498*n,r+e,t.x+t.w,r+.5522847498*e,t.x+t.w,r]},jl=t=>{const e=vn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+t.h+5,o=t.y+e,i=r-e,a=t.x+n;return[1,t.x,o,4,t.x,o-.5522847498*e,a-.5522847498*n,t.y,a,t.y,4,a+.5522847498*n,t.y,t.x+t.w,o-.5522847498*e,t.x+t.w,o,2,t.x+t.w,i,4,t.x+t.w,i+.5522847498*e,a+.5522847498*n,r,a,r,4,a-.5522847498*n,r,t.x,i+.5522847498*e,t.x,i,5]},th=t=>e=>{const n=e.y+e.h,r=N2(t.rBase*e.h)(e.w/(2*(1+(nt(t.minN)-1)*t.stepRatio))),o=e.w-2*r,i=2*r*t.stepRatio,a=Xg(t.minN)(o<=0||i<=0?t.minN:he(Bn(o/i))+1|0),s=a>=3?Ut(1,a-2|0):[],u=s.length,c=Nr(u+1|0,2),_=c<1?[]:At(0,c,s),l=$b(t.seed)((()=>{const p=u-c|0;return p<1?s:At(p,s.length,s)})()),f=l.idx,d=Hb(l.prng)(lt(p=>p!==f,_))(Xg(1)(_.length-(ln(go)(f)(_)?1:0)|0)),h=d.idx,m=a>=2?o/(nt(a)-1):0;return J(p=>x=>{const y=x===h,T=x===f,v=x===0||x===(a-1|0),b=qb(p.prng)(v)(T)(y)(r)(t),C=Ob(b.prng)(v)(t)(e.h),S=Wb(C.prng)(v)(t)(m);return{prng:S.prng,circles:St(p.circles)({cx:e.x+Qb(b.r)(e.w-b.r)((a>=2?r+nt(x)/(nt(a)-1)*o+S.dx:r+0*o+S.dx)+(T?t.heroShift*m:y?-1*t.smallShift*m:0)),cy:n-C.yLift,r:b.r})}})({prng:d.prng,circles:[]})(Ut(0,a-1|0)).circles},eh=t=>e=>{const n=t.length;return Wt(r=>o=>({c:o,p1:(()=>{if(r===0)return{x:o.cx-o.r,y:e};const i=r-1|0;return i>=0&&i<t.length?Vl(t[i])(o):{x:o.cx-o.r,y:e}})(),p2:(()=>{if(r===(n-1|0))return{x:o.cx+o.r,y:e};const i=r+1|0;return i>=0&&i<t.length?Vl(o)(t[i]):{x:o.cx+o.r,y:e}})()}))(t)},nh=t=>{const e=vn(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]},Vb=t=>e=>n=>{const r=Bo(e.y-t.cy)(e.x-t.cx),o=Bo(n.y-t.cy)(n.x-t.cx),i=o>r?o-r:o+6.283185307179586-r,a=Xg(1)(he(ts(i/1.5707963267948966))),s=i/nt(a),u=1.3333333333333333*v2(s/4);return Et(Ut(0,a-1|0))(c=>{const _=r+nt(c+1|0)*s,l=t.cx+t.r*hn(_),f=t.cy+t.r*en(_),d=r+nt(c)*s;return[4,t.cx+t.r*hn(d)-u*t.r*en(d),t.cy+t.r*en(d)+u*t.r*hn(d),l+u*t.r*en(_),f-u*t.r*hn(_),l,f]})},rh=t=>e=>{const n=t.h*.38,r=eh(th(Zl)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),o=vn(e)(vn(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...Et(r)(i=>Vb(i.c)(i.p1)(i.p2)),2,t.x+t.w,t.y+t.h-o,3,t.x+t.w,t.y+t.h,t.x+t.w-o,t.y+t.h,2,t.x+o,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-o,2,r[0].p1.x,r[0].p1.y,5]:$i(t)(e)},ei=t=>e=>n=>r=>o=>i=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(o)(i);if(e==="Cylinder"){const a=jl(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Parallelogram"){const a=Ul(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Diamond"){const a=nh(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Ellipse"){const a=Xl(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Document"){const a=Kl(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Cloud"){const a=rh(n)(r);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}return t.drawRoundedRect(n)(r)(o)(i)},Xb={fillPath:t=>e=>U(st("Bind",{type:"render",value:Vt("FillPath",t,e,void 0),map:be.map},n=>U(st("Return",n),ct)),ct),strokePath:t=>e=>U(st("Bind",{type:"render",value:Vt("StrokePath",t,e,void 0),map:be.map},n=>U(st("Return",n),ct)),ct),fillStrokePath:t=>e=>n=>U(st("Bind",{type:"render",value:Vt("FillStrokePath",t,e,n,void 0),map:be.map},r=>U(st("Return",r),ct)),ct),drawRoundedRect:t=>e=>n=>r=>{if(n.tag==="Just"){if(r.tag==="Just")return U(st("Bind",{type:"render",value:Vt("FillStrokePath",$i(t)(e),n._1,r._1,void 0),map:be.map},o=>U(st("Return",o),ct)),ct);if(r.tag==="Nothing")return U(st("Bind",{type:"render",value:Vt("FillPath",$i(t)(e),n._1,void 0),map:be.map},o=>U(st("Return",o),ct)),ct);g()}if(n.tag==="Nothing"){if(r.tag==="Just")return U(st("Bind",{type:"render",value:Vt("StrokePath",$i(t)(e),r._1,void 0),map:be.map},o=>U(st("Return",o),ct)),ct);if(r.tag==="Nothing")return U(st("Return",void 0),ct)}g()},drawText:t=>U(st("Bind",{type:"render",value:Vt("DrawText",t,void 0),map:be.map},e=>U(st("Return",e),ct)),ct),drawTextAffine:t=>e=>U(st("Bind",{type:"render",value:Vt("DrawTextAffine",t,e,void 0),map:be.map},n=>U(st("Return",n),ct)),ct),pushTransform:t=>U(st("Bind",{type:"render",value:Vt("PushTransform",t,void 0),map:be.map},e=>U(st("Return",e),ct)),ct),popTransform:U(st("Bind",{type:"render",value:Vt("PopTransform",void 0),map:be.map},t=>U(st("Return",t),ct)),ct),pushBakedTransform:t=>U(st("Bind",{type:"render",value:Vt("PushTransform",t,void 0),map:be.map},e=>U(st("Return",e),ct)),ct),popBakedTransform:U(st("Bind",{type:"render",value:Vt("PopTransform",void 0),map:be.map},t=>U(st("Return",t),ct)),ct),pushClip:t=>e=>U(st("Bind",{type:"render",value:Vt("PushClip",t,e,void 0),map:be.map},n=>U(st("Return",n),ct)),ct),popClip:U(st("Bind",{type:"render",value:Vt("PopClip",void 0),map:be.map},t=>U(st("Return",t),ct)),ct),pushBlend:t=>U(st("Bind",{type:"render",value:Vt("PushBlend",t,void 0),map:be.map},e=>U(st("Return",e),ct)),ct),popBlend:U(st("Bind",{type:"render",value:Vt("PopBlend",void 0),map:be.map},t=>U(st("Return",t),ct)),ct),pushAlpha:t=>U(st("Bind",{type:"render",value:Vt("PushAlpha",t,void 0),map:be.map},e=>U(st("Return",e),ct)),ct),popAlpha:U(st("Bind",{type:"render",value:Vt("PopAlpha",void 0),map:be.map},t=>U(st("Return",t),ct)),ct),pushBlur:t=>U(st("Bind",{type:"render",value:Vt("PushBlur",t,void 0),map:be.map},e=>U(st("Return",e),ct)),ct),popBlur:U(st("Bind",{type:"render",value:Vt("PopBlur",void 0),map:be.map},t=>U(st("Return",t),ct)),ct),pushLayer:t=>U(st("Bind",{type:"render",value:Vt("PushLayer",t,void 0),map:be.map},e=>U(st("Return",e),ct)),ct),popLayer:U(st("Bind",{type:"render",value:Vt("PopLayer",void 0),map:be.map},t=>U(st("Return",t),ct)),ct),setViewport:t=>U(st("Bind",{type:"render",value:Vt("SetViewport",t,void 0),map:be.map},e=>U(st("Return",e),ct)),ct),clearBackground:t=>U(st("Bind",{type:"render",value:Vt("ClearBackground",t,void 0),map:be.map},e=>U(st("Return",e),ct)),ct),backgroundDots:t=>U(st("Bind",{type:"render",value:Vt("BackgroundDots",t,void 0),map:be.map},e=>U(st("Return",e),ct)),ct),measureText:t=>e=>to(t)(e),measureInk:t=>e=>Eb(t)(e),insideTokenStyle:t=>U(st("Return",Ug),ct),Monad0:()=>Mg},Ub=t=>()=>t.clip("evenodd"),Kb=t=>e=>()=>{t.filter=`blur(${e}px)`},Zb=t=>e=>()=>{const n=e>0?t.canvas.width/e:1;t.setTransform(n,0,0,n,0,0)},jb=t=>e=>n=>r=>o=>()=>{const i=e>0?t.canvas.width/e:1;t.setTransform(i*n,0,0,i*n,i*r,i*o)},t3=t=>e=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(e.tile,.001))),r=Math.max(2,Math.round(e.tile*n)),o=document.createElement("canvas");o.width=r,o.height=r;const i=o.getContext("2d");i.scale(n,n),i.fillStyle=e.bgCss,i.fillRect(0,0,e.tile,e.tile),i.fillStyle=e.dotCss,i.beginPath(),i.arc(e.tile/2,e.tile/2,e.dotR,0,2*Math.PI),i.fill();const a=t.createPattern(o,"repeat");a&&typeof a.setTransform=="function"&&a.setTransform(new DOMMatrix().translateSelf(e.ox,e.oy).scaleSelf(1/n,1/n)),t.save(),t.fillStyle=a,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},Kg=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Zg=t=>e=>n=>{const r=e.stroke;return()=>{const o=r.value,i=M2(t)(n);if(o!==n)return i(),e.stroke.value=n}},e3=t=>e=>n=>{const r=e.font;return()=>{const o=r.value,i=U2(t)(n);if(o!==n)return i(),e.font.value=n}},Fa=t=>e=>n=>{const r=e.fill;return()=>{const o=r.value,i=z2(t)(n);if(o!==n)return i(),e.fill.value=n}},au=t=>e=>{const n=e.length,r=i=>{if(i>=n)return()=>{};const a=i>=0&&i<e.length?e[i]:0;if(a===1){const s=Af(t)((()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})()),u=r(i+3|0);return()=>(s(),u())}if(a===2){const s=oa(t)((()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})()),u=r(i+3|0);return()=>(s(),u())}if(a===3){const s=ia(t)({cpx:(()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})(),cpy:(()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=i+3|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=i+4|0;return c>=0&&c<e.length?e[c]:0})()}),u=r(i+5|0);return()=>(s(),u())}if(a===4){const s=Z2(t)({cp1x:(()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})(),cp1y:(()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})(),cp2x:(()=>{const c=i+3|0;return c>=0&&c<e.length?e[c]:0})(),cp2y:(()=>{const c=i+4|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=i+5|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=i+6|0;return c>=0&&c<e.length?e[c]:0})()}),u=r(i+7|0);return()=>(s(),u())}if(a===5){const s=Rf(t),u=r(i+1|0);return()=>(s(),u())}return()=>{}},o=Gf(t);return()=>(o(),r(0)())},n3=t=>e=>n=>r=>o=>i=>{const a=Kg(i)(Kg(r/2)(o/2)),s=Af(t)(e+a)(n);return()=>(s(),oa(t)(e+r-a)(n)(),ia(t)({cpx:e+r,cpy:n,x:e+r,y:n+a})(),oa(t)(e+r)(n+o-a)(),ia(t)({cpx:e+r,cpy:n+o,x:e+r-a,y:n+o})(),oa(t)(e+a)(n+o)(),ia(t)({cpx:e,cpy:n+o,x:e,y:n+o-a})(),oa(t)(e)(n+a)(),ia(t)({cpx:e,cpy:n,x:e+a,y:n})(),Rf(t)())},r3=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),oh=t=>e=>{const n=$2(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=r3();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0},groupAlpha:{value:1},alphaSaves:{value:[]}}}},o3={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},i3=t=>ae(t.weight)+" "+Fo(t.size)+"px "+t.family,Dr=t=>{const e=Fo(nt(t.a)/255);return t.a>=255?"rgb("+ae(t.r)+","+ae(t.g)+","+ae(t.b)+")":"rgba("+ae(t.r)+","+ae(t.g)+","+ae(t.b)+","+e+")"},a3=t=>e=>n=>r=>{const o=Cr(t);return()=>(o(),Zb(t)(e.width)(),Fa(t)(n)(Dr(r))(),H2(t)({x:0,y:0,width:e.width,height:e.height})(),br(t)(),n.font.value="",n.fill.value="",n.stroke.value="")},s3=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",t3(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:Dr(n.bgColor),dotCss:Dr(n.dotColor),tile:n.tile,dotR:n.dotRadius,ox:n.origin.x,oy:n.origin.y})())},u3=t=>e=>n=>r=>{const o=Fa(t)(e)(Dr(r));return()=>(o(),au(t)(n)(),pc(t)())},c3=t=>e=>n=>r=>o=>{const i=Fa(t)(e)(Dr(r));return()=>(i(),Zg(t)(e)(Dr(o.color))(),fc(t)(o.width)(),bc(t)((()=>{if(o.lineJoin==="RoundJoin")return Tc;if(o.lineJoin==="BevelJoin")return wc;if(o.lineJoin==="MiterJoin")return Nc;g()})())(),kc(t)((()=>{if(o.lineCap==="ButtCap")return Cc;if(o.lineCap==="RoundCap")return vc;if(o.lineCap==="SquareCap")return Jc;g()})())(),au(t)(n)(),pc(t)(),hc(t)())},g3=t=>e=>n=>r=>o=>i=>{const a=Gf(t);return()=>{if(a(),n3(t)(n.x)(n.y)(n.w)(n.h)(r)(),o.tag==="Just"?(Fa(t)(e)(Dr(o._1.color))(),pc(t)()):o.tag==="Nothing"||g(),i.tag==="Just")return Zg(t)(e)(Dr(i._1.color))(),fc(t)(i._1.width)(),bc(t)((()=>{if(i._1.lineJoin==="RoundJoin")return Tc;if(i._1.lineJoin==="BevelJoin")return wc;if(i._1.lineJoin==="MiterJoin")return Nc;g()})())(),kc(t)((()=>{if(i._1.lineCap==="ButtCap")return Cc;if(i._1.lineCap==="RoundCap")return vc;if(i._1.lineCap==="SquareCap")return Jc;g()})())(),hc(t)();i.tag!=="Nothing"&&g()}},_3=t=>e=>n=>r=>{const o=Zg(t)(e)(Dr(r.color));return()=>(o(),fc(t)(r.width)(),bc(t)((()=>{if(r.lineJoin==="RoundJoin")return Tc;if(r.lineJoin==="BevelJoin")return wc;if(r.lineJoin==="MiterJoin")return Nc;g()})())(),kc(t)((()=>{if(r.lineCap==="ButtCap")return Cc;if(r.lineCap==="RoundCap")return vc;if(r.lineCap==="SquareCap")return Jc;g()})())(),au(t)(n)(),hc(t)())},ih=t=>e=>n=>{const r=Fa(t)(e)(Dr(n.color));return()=>(r(),e3(t)(e)(i3(n.font))(),cy(t)((()=>{if(n.align==="AlignLeft")return ry;if(n.align==="AlignCenter")return iy;if(n.align==="AlignRight")return oy;g()})())(),uy(t)((()=>{if(n.baseline==="BaselineTop")return j2;if(n.baseline==="BaselineMiddle")return ty;if(n.baseline==="BaselineAlphabetic")return ey;if(n.baseline==="BaselineBottom")return ny;g()})())(),K2(t)(n.content)(n.x)(n.y)())},ah={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),a=o();return i(a)}},Functor0:()=>o3},f3={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>ah},d3=t=>e=>n=>{const r=Kg(e.width/n.vw)(e.height/n.vh);return jb(t)(e.width)(r)((e.width-n.vw*r)/2-n.vx*r)((e.height-n.vh*r)/2-n.vy*r)},l3={pure:t=>e=>()=>t,Apply0:()=>ah},sh={Applicative0:()=>l3,Bind1:()=>f3},jg={fillPath:t=>e=>n=>{const r=u3(n.ctx)(n.styleCache)(t)(e.color),o=n.maskDepth;return()=>{if(o.value===0)return r()}},strokePath:t=>e=>n=>{const r=_3(n.ctx)(n.styleCache)(t)(e),o=n.maskDepth;return()=>{if(o.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const o=c3(r.ctx)(r.styleCache)(t)(e.color)(n),i=r.maskDepth;return()=>{if(i.value===0)return o()}},drawRoundedRect:t=>e=>n=>r=>o=>{const i=g3(o.ctx)(o.styleCache)(t)(e)(n)(r),a=o.maskDepth;return()=>{if(a.value===0)return i()}},drawText:t=>e=>{const n=ih(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=Cr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Y2(n.ctx)(t)(),ih(n.ctx)(n.styleCache)(e)(),br(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=Cr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Df(e.ctx)({translateX:t.tx,translateY:t.ty})(),os(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=br(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBakedTransform:t=>e=>{const n=Cr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Df(e.ctx)({translateX:t.tx,translateY:t.ty})(),os(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=br(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushClip:t=>e=>n=>{const r=Cr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",au(n.ctx)(t)(),e==="NonZero")return q2(n.ctx)();if(e==="EvenOdd")return Ub(n.ctx)();g()}}},popClip:t=>{const e=br(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBlend:t=>e=>{const n=Cr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){if(n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",t==="Normal")return If(e.ctx)(ay)();if(t==="Difference")return If(e.ctx)(sy)();g()}}},popBlend:t=>{const e=br(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushAlpha:t=>e=>{const n=Cr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="";const o=e.groupAlpha.value,i=e.alphaSaves.value;e.alphaSaves.value=[...i,o];const a=o*t;return e.groupAlpha.value=a,W2(e.ctx)(a)()}}},popAlpha:t=>{const e=br(t.ctx),n=t.maskDepth;return()=>{if(n.value===0){e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="";const r=t.alphaSaves.value,o=Or(r);if(o.tag==="Just")return t.alphaSaves.value=o._1.init,t.groupAlpha.value=o._1.last;if(o.tag==="Nothing")return t.groupAlpha.value=1;g()}}},pushBlur:t=>e=>{const n=Cr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="";const o=Kb(e.ctx)(t);if(t>=.01)return o()}}},popBlur:t=>{const e=br(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=d3(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=a3(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=s3(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=Wg(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=qg(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Ug,Monad0:()=>sh},h3=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ia=t=>e=>n=>{const r=h3(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},t_=t=>{const e=at.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=at.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},p3=t=>{if(t.tag==="Retracted")return{lo:0,hi:0};if(t.tag==="Extended")return{lo:0,hi:1};if(t.tag==="Extending"){if(t._1==="ExtendFromSource")return{lo:0,hi:t_(t._2)};if(t._1==="ExtendFromTarget")return{lo:1-t._2,hi:1};g()}if(t.tag==="Retracting"){if(t._1==="FromSource")return{lo:t._2,hi:1};if(t._1==="FromTarget")return{lo:0,hi:1-t._2};if(t._1==="FromBoth")return{lo:t._2/2,hi:1-t._2/2}}g()},ni=t=>{if(t.tag==="Hidden")return{alpha:0,scale:1};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:t_(t._1),scale:1};if(t.tag==="PloppingOut")return{alpha:t_(1-t._1),scale:1};g()};function m3(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function y3(t){const e=t.length,n=new Array(e);for(let r=0;r<e;r++){const o=t[r],i=t[(r+1)%e];n[r]={a:o,b:i,len:m3(o,i)}}return n}function x3(t,e,n){let r=0;for(let o=0;o<t.length;o++){const i=t[o],a=r,s=a+i.len;if(n<=s){const u=i.len>1e-6?(n-a)/i.len:0;return{x:i.a.x+(i.b.x-i.a.x)*u,y:i.a.y+(i.b.y-i.a.y)*u}}r=s}return e.length>0?e[e.length-1]:{x:0,y:0}}function uh(t,e){if(e.length===0)return[];const n=y3(e);let r=0;for(let i=0;i<n.length;i++)r+=n[i].len;const o=new Array(t);for(let i=0;i<t;i++)o[i]=x3(n,e,i*r/t);return o}function w3(t,e){const n=e.length;if(n===0)return e;const r=(t%n+n)%n|0,o=new Array(n);for(let i=0;i<n;i++)o[i]=e[(i+r)%n];return o}function T3(t,e){const n=e.length;if(n===0)return e;let r=0,o=1/0;for(let i=0;i<n;i++){let a=0;for(let s=0;s<n;s++){const u=t[s]||{x:0,y:0},c=e[(s+i)%n]||{x:0,y:0},_=u.x-c.x,l=u.y-c.y;a+=_*_+l*l}a<o&&(o=a,r=i)}return w3(r,e)}const ch=t=>e=>n=>{const r=uh(t,e),o=uh(t,n),i=T3(r,o);return{from:r,to:i}};function gh(t){const e=t.length;if(e===0)return{x:0,y:0};let n=0,r=0;for(let o=0;o<e;o++)n+=t[o].x,r+=t[o].y;return{x:n/e,y:r/e}}function N3(t,e){const n=e.x-t.x,r=e.y-t.y,o=Math.sqrt(n*n+r*r);return o<=1e-4?{x:1,y:0}:{x:n/o,y:r/o}}function v3(t,e){const n=e.length;if(n===0)return e;const r=new Array(n);for(let o=0;o<n;o++){const i=e[((o-1)%n+n)%n],a=e[((o+1)%n+n)%n],s=e[o];r[o]={x:s.x+((i.x+a.x)/2-s.x)*t,y:s.y+((i.y+a.y)/2-s.y)*t}}return r}function J3(t){return t<0?0:t>1?1:t}const _h=t=>e=>n=>r=>{const o=e.length;if(o===0)return[];const i=gh(e),a=gh(n),s=N3(i,a),u=new Array(o);let c=1/0,_=-1/0;for(let d=0;d<o;d++){const h=e[d],m=(h.x-i.x)*s.x+(h.y-i.y)*s.y;u[d]=m,m<c&&(c=m),m>_&&(_=m)}const l=_-c;let f=new Array(o);for(let d=0;d<o;d++){const h=e[d],m=n[d];if(m===void 0){f[d]=h;continue}const p=l<=1e-4?0:r.maxDelay*(1-(u[d]-c)/l),x=Math.max(1e-4,1-p),y=J3((t-p)/x),T=y*y*(3-2*y);f[d]={x:h.x+(m.x-h.x)*T,y:h.y+(m.y-h.y)*T}}for(let d=0;d<r.smoothPasses;d++)f=v3(.5,f);return f},fh=(t,e)=>({tag:t,_1:e}),dh=(t,e)=>({tag:t,_1:e}),me=(t,e,n)=>({tag:t,_1:e,_2:n}),lh=t=>t,su=(t,e)=>({tag:t,_1:e}),uu=(t,e)=>({tag:t,_1:e}),cu=t=>t,ro=(t,e)=>({tag:t,_1:e}),Ge=(t,e,n)=>({tag:t,_1:e,_2:n}),oo=(t,e)=>({tag:t,_1:e}),ri=(t,e)=>({tag:t,_1:e}),hh=(t,e)=>({tag:t,_1:e}),ph=t=>t,mh=(t,e)=>({tag:t,_1:e}),oi=(t,e,n)=>({tag:t,_1:e,_2:n}),yh=t=>t,C3=t=>t,ii=yh("NormalTransform"),b3=yh("BakedTransform"),xh=ph("TokenOutside"),wh=ph("TokenInside"),gu=ri("PlainText"),Th=oo("FrameTitle"),k3=oo("Watermark"),L3=cu("NodeShadow"),S3=cu("NodeDoorwayFrame"),Nh=cu("NodeBody"),E3=cu("NodeInversion"),e_=lh("LabelsShown"),_u=lh("LabelsHidden"),ar={map:t=>e=>{if(e.tag==="BeginFrame")return Ge("BeginFrame",e._1,t(e._2));if(e.tag==="EndFrame")return Ge("EndFrame",t(e._1));if(e.tag==="BeginGroup")return Ge("BeginGroup",e._1,t(e._2));if(e.tag==="EndGroup")return Ge("EndGroup",e._1,t(e._2));if(e.tag==="Background")return Ge("Background",e._1,t(e._2));if(e.tag==="Overlay")return Ge("Overlay",e._1,t(e._2));if(e.tag==="Node")return Ge("Node",e._1,t(e._2));if(e.tag==="Edge")return Ge("Edge",e._1,t(e._2));if(e.tag==="Text")return Ge("Text",e._1,t(e._2));if(e.tag==="Token")return Ge("Token",e._1,t(e._2));if(e.tag==="AskInsideTokenStyle")return Ge("AskInsideTokenStyle",e._1,n=>t(e._2(n)));g()}},vh=t=>e=>to(t)(e),P3=t=>{const e=t.Bind1().Apply0().Functor0(),n=bb(t);return r=>o=>n(Jb()()()({scene:i=>{if(i.tag==="BeginFrame"){const a=i._2;return e.map(s=>a)(r.beginFrame(i._1))}if(i.tag==="EndFrame"){const a=i._1;return e.map(s=>a)(r.endFrame)}if(i.tag==="BeginGroup"){const a=i._2;return e.map(s=>a)(r.beginGroup(i._1))}if(i.tag==="EndGroup"){const a=i._2;return e.map(s=>a)(r.endGroup(i._1))}if(i.tag==="Background"){const a=i._2;return e.map(s=>a)(r.background(i._1))}if(i.tag==="Overlay"){const a=i._2;return e.map(s=>a)(r.overlay(i._1))}if(i.tag==="Node"){const a=i._2;return e.map(s=>a)(r.node(i._1))}if(i.tag==="Edge"){const a=i._2;return e.map(s=>a)(r.edge(i._1))}if(i.tag==="Text"){const a=i._2;return e.map(s=>a)(r.text(i._1))}if(i.tag==="Token"){const a=i._2;return e.map(s=>a)(r.token(i._1))}if(i.tag==="AskInsideTokenStyle")return e.map(i._2)(r.insideTokenStyle(i._1));g()},metrics:i=>{if(i.tag==="MeasureText")return e.map(i._3)(r.measureText(i._1)(i._2));if(i.tag==="MeasureInk")return e.map(i._3)(r.measureInk(i._1)(i._2));g()}}))(o)},G3=t=>U(st("Bind",{type:"scene",value:Ge("AskInsideTokenStyle",t,C3),map:ar.map},e=>U(st("Return",e),ct)),ct),Jh=t=>U(st("Bind",{type:"scene",value:Ge("Background",t,void 0),map:ar.map},e=>U(st("Return",e),ct)),ct),Ch=t=>U(st("Bind",{type:"scene",value:Ge("Edge",t,void 0),map:ar.map},e=>U(st("Return",e),ct)),ct),fu=t=>U(st("Bind",{type:"scene",value:Ge("Node",t,void 0),map:ar.map},e=>U(st("Return",e),ct)),ct),io=t=>U(st("Bind",{type:"scene",value:Ge("Overlay",t,void 0),map:ar.map},e=>U(st("Return",e),ct)),ct),ai=t=>U(st("Bind",{type:"scene",value:Ge("Text",t,void 0),map:ar.map},e=>U(st("Return",e),ct)),ct),bh=t=>U(st("Bind",{type:"scene",value:Ge("Token",t,void 0),map:ar.map},e=>U(st("Return",e),ct)),ct),A3=t=>e=>U(st("Bind",{type:"scene",value:Ge("BeginFrame",t,void 0),map:ar.map},n=>U(st("Return",n),ct)),Z("CatCons",()=>U(e._1,(()=>{if(e._2.tag==="CatNil")return Z("CatCons",()=>U(st("Bind",{type:"scene",value:Ge("EndFrame",void 0),map:ar.map},n=>U(st("Return",n),ct)),ct),K(G,G));if(e._2.tag==="CatCons")return Z("CatCons",e._2._1,K(e._2._2._1,pt("Cons",Z("CatCons",()=>U(st("Bind",{type:"scene",value:Ge("EndFrame",void 0),map:ar.map},n=>U(st("Return",n),ct)),ct),K(G,G)),e._2._2._2)));g()})()),K(G,G))),Ae=t=>e=>U(st("Bind",{type:"scene",value:Ge("BeginGroup",t,void 0),map:ar.map},n=>U(st("Return",n),ct)),Z("CatCons",()=>{const n=()=>U(st("Bind",{type:"scene",value:Ge("EndGroup",t,void 0),map:ar.map},r=>U(st("Return",r),ct)),ct);return U(e._1,(()=>{if(e._2.tag==="CatNil")return Z("CatCons",n,K(G,G));if(e._2.tag==="CatCons")return Z("CatCons",e._2._1,K(e._2._2._1,pt("Cons",Z("CatCons",n,K(G,G)),e._2._2._2)));g()})())},K(G,G))),Fr=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},kh=J(_r)(0),Lh=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},R3=J(t=>e=>t+e.len)(0),Sh=t=>{const e=Pt(n=>w,n=>r=>N("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,...Et(At(1,t.length,t))(n=>[2,n.x,n.y]),5];g()},D3=t=>e=>{const n=Fr(e)(Fr(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]},F3=t=>{const e=Pt(n=>w,n=>r=>N("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,...Et(e._1.tail)(n=>[2,n.x,n.y])];g()},Co=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return jl(e);if(t.shape==="Parallelogram")return Ul(e);if(t.shape==="Diamond")return nh(e);if(t.shape==="Ellipse")return Xl(e);if(t.shape==="Document")return Kl(e);if(t.shape==="Cloud")return rh(e)(7);if(t.shape==="Rectangle")return D3(e)(7);g()},Be=t=>e=>n=>Y(r=>{const o=nt(r)/nt(n);return{x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o}})(Ut(0,n-1|0)),I3=t=>{const e=vn(t.w*.18)(t.h*.6);return[...Be({x:t.x+e,y:t.y})({x:t.x+t.w,y:t.y})(16),...Be({x:t.x+t.w,y:t.y})({x:t.x+t.w-e,y:t.y+t.h})(16),...Be({x:t.x+t.w-e,y:t.y+t.h})({x:t.x,y:t.y+t.h})(16),...Be({x:t.x,y:t.y+t.h})({x:t.x+e,y:t.y})(16)]},n_=t=>e=>{const n=Fr(t)(Fr(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}},r_=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return nn(r*r+n*n)},B3=t=>$e(e=>n=>({a:e,b:n,len:r_(e)(n)}),t,At(1,t.length,t)),Q3=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?N("Just",e[n]):w,o=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];g()})(),i=0<e.length?N("Just",e[0]):w,a=(()=>{if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return{x:0,y:0};g()})(),s=e.length;return s<3?e:[a,...Et(Ut(1,s-2|0))(u=>{const c=u+1|0,_=c>=0&&c<e.length?N("Just",e[c]):w,l=u>=0&&u<e.length?N("Just",e[u]):w,f=u-1|0,d=f>=0&&f<e.length?N("Just",e[f]):w;if(d.tag==="Just"&&l.tag==="Just"&&_.tag==="Just"){const h=l._1,m=r_(h)(_._1),p=r_(d._1)(h),x=Fr(t)(m/2),y=Fr(t)(p/2),T=m>0?x/m:0,v=h.x+(_._1.x-h.x)*T,b=h.y+(_._1.y-h.y)*T,C=p>0?y/p:0,S=h.x+(d._1.x-h.x)*C,P=h.y+(d._1.y-h.y)*C;return Y(F=>{const W=nt(F)/nt(10),E=1-W;return{x:E*E*S+2*E*W*h.x+W*W*v,y:E*E*P+2*E*W*h.y+W*W*b}})(Ut(0,10))}return[]}),...o]},z3=t=>e=>n=>r=>o=>Y(i=>{const a=nt(i)/nt(o),s=1-a,u=a*a*a,c=3*s*a*a,_=3*s*s*a,l=s*s*s;return{x:l*t.x+_*e.x+c*n.x+u*r.x,y:l*t.y+_*e.y+c*n.y+u*r.y}})(Ut(0,o-1|0)),M3=t=>[...Be({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...Be({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...z3({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),...Be({x:t.x,y:t.y+t.h*.85})({x:t.x,y:t.y})(12)],Eh=t=>e=>Y(n=>{const r=6.283185307179586*nt(n)/nt(64);return{x:t.x+e*hn(r),y:t.y+e*en(r)}})(Ut(0,63)),Ph=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]},O3=t=>{const e=t.y+t.h/2,n=vn(t.h*.4)(t.w*.2);return[...Be({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...Be({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...Be({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...Be({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...Be({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...Be({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},o_=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:kh(Y(n=>n.x)(t))/nt(e),y:kh(Y(n=>n.y)(t))/nt(e)}},du=t=>e=>n=>r=>o=>Y(i=>{const a=n+(r-n)*(nt(i)/nt(o));return{x:t.x+e*hn(a),y:t.y+e*en(a)}})(Ut(0,o-1|0)),i_=t=>e=>{const n=Fr(t)(Fr(e.w/2)(e.h/2));return[...Be({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...du({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...Be({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...du({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...Be({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...du({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...Be({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...du({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},lu=t=>e=>n=>r=>o=>i=>Y(a=>{const s=r+(o-r)*(nt(a)/nt(i));return{x:t.x+e*hn(s),y:t.y+n*en(s)}})(Ut(0,i-1|0)),W3=t=>{const e=t.h*.38;return[...Et(eh(th(Zl)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=Bo(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),o=Bo(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return lu({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(o)(r>o?r:r+6.283185307179586)(16)}),...Be({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...Be({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...Be({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},q3=t=>{const e=Fr(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,o=t.y+t.h+5-e-2,i=t.x+n;return[...lu({x:i,y:r})(n)(e)(3.141592653589793)(6.283185307179586)(24),...Be({x:t.x+t.w,y:r})({x:t.x+t.w,y:o})(12),...lu({x:i,y:o})(n)(e)(0)(3.141592653589793)(24),...Be({x:t.x,y:o})({x:t.x,y:r})(12)]},si=t=>e=>e.shape==="Cylinder"?q3(e):e.shape==="Parallelogram"?I3(e):e.shape==="Diamond"?O3(e):e.shape==="Ellipse"?i_(vn(e.w)(e.h)/2)(e):e.shape==="Document"?M3(e):e.shape==="Cloud"?W3(e):i_(t)(e),H3=t=>{const e=Fr(t.h*.075)(t.w*.075),n=t.w/2;return lu({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},$3=t=>e=>n=>J(r=>o=>{const i=r.pos+o.len,a=n<i?(n-r.pos)/o.len:1,s={x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a},u=e>r.pos?(e-r.pos)/o.len:0,c={x:o.a.x+(o.b.x-o.a.x)*u,y:o.a.y+(o.b.y-o.a.y)*u},_=r.points.length-1|0,l=_>=0&&_<r.points.length?(()=>{const f=r.points[_].x-c.x;return(f<0?-f<1e-4:f<1e-4)&&(()=>{const d=r.points[_].y-c.y;return d<0?-d<1e-4:d<1e-4})()})()?St(r.points)(s):[...r.points,c,s]:[c,s];return o.len<=0||i<=e||r.pos>=n?{...r,pos:i}:{pos:i,points:l}})({pos:0,points:[]})(t).points,Y3=t=>e=>n=>{const r=Pt(o=>w,o=>i=>N("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const o=B3(t),i=R3(o),a=Lh(0)(i)(e*i),s=Lh(0)(i)(n*i);return s<=a?[]:$3(o)(a)(s)}g()},V3=t=>e=>n=>r=>{const o=r.x-n.x,i=r.y-n.y,a=e.x-t.x,s=e.y-t.y,u=n.x-t.x,c=n.y-t.y,_=a*i-s*o,l=(u*i-c*o)/_,f=(u*s-c*a)/_;return(_<0?-_<1e-9:_<1e-9)?w:l>=0&&l<=1&&f>=0&&f<=1?N("Just",l):w},X3=t=>e=>n=>{const r=Rt(o=>i=>at.compare(o.t)(i.t))(wt(o=>{const i=V3(e)(n)(o._1)(o._2);return i.tag==="Just"?N("Just",{t:i._1,p:{x:e.x+(n.x-e.x)*i._1,y:e.y+(n.y-e.y)*i._1}}):w})($e(bn,t,[...At(1,t.length,t),...At(0,1,t)])));return 0<r.length?N("Just",r[0].p):w},Gh=t=>e=>{const n=Or(e);if(n.tag==="Nothing")return e;if(n.tag==="Just"){const r=n._1.init.length-1|0;if(r>=0&&r<n._1.init.length){const o=X3(t)(n._1.init[r])(n._1.last);if(o.tag==="Just")return St(n._1.init)(o._1);if(o.tag==="Nothing")return e;g()}return e}g()},bo=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},a_=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},U3=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},K3=t=>e=>{const n=bo(0)(t.y+4-e.y)+bo(0)(e.y+e.h-(t.y+t.h-4)),r=bo(0)(t.x+4-e.x)+bo(0)(e.x+e.w-(t.x+t.w-4));return r*e.h+n*e.w+r*n},Z3=t=>e=>{const n=t.y+t.h-6,r=t.y+6,o=t.x+14,i=t.x+t.w-14,a=J(bo)(0)(Y(s=>o-10<s.x+s.w+12&&i+10>s.x-12&&r-10<s.y+s.h+12&&n+10>s.y-12?a_((s.x+s.w+12-(o-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+a*.7071067811865476,y:t.y-a*.7071067811865476}},j3=t=>e=>{const n=a_(t.x+t.w)(e.x+e.w)-bo(t.x)(e.x),r=a_(t.y+t.h)(e.y+e.h)-bo(t.y)(e.y);return t.x<e.x+e.w&&t.x+t.w>e.x&&t.y<e.y+e.h&&t.y+t.h>e.y?n*r:0},Ah=t=>e=>n=>r=>{const o=t+4,i=bo(0)(e-8),a=o+i-n;return n<=i?U3(o)(a)(r):t+(e-n)/2},s_=t=>e=>({...e,x:Ah(t.x)(t.w)(e.w)(e.x),y:Ah(t.y)(t.h)(e.h)(e.y)}),tk=t=>{const e=2*t.token.x-t.rect.x-t.rect.w,n=t.token.y-t.rect.h/2,r=t.token.x-t.rect.w/2,o=2*t.token.y-t.rect.y-t.rect.h;return[{...t.rect,x:t.rect.x,y:t.rect.y},{...t.rect,x:e,y:t.rect.y},{...t.rect,x:t.rect.x,y:o},{...t.rect,x:e,y:o},{...t.rect,x:t.rect.x,y:n},{...t.rect,x:e,y:n},{...t.rect,x:r,y:t.rect.y},{...t.rect,x:r,y:o}]},ek=t=>e=>n=>r=>o=>{const i=o.y+o.h/2-n.token.y,a=o.y-r.y;return(()=>{const s=o.x+o.w/2-n.token.x,u=o.x-r.x;return 1e6*K3(t)(o)+1e4*J(c=>_=>c+j3(o)(_))(0)(e)+.05*(u*u+a*a)+.01*(s*s+i*i)})()+(o.y>n.token.y?100:0)},nk=t=>e=>n=>r=>{const o=a=>{const s=s_(t)(a);return{rect:s,score:ek(t)(e)(n)(r)(s)}},i=Pt(a=>w,a=>s=>N("Just",{head:a,tail:s}),[r,n.rect,...tk(n)]);if(i.tag==="Nothing")return s_(t)(r);if(i.tag==="Just")return J(a=>s=>{const u=o(s);return u.score<a.score?u:a})(o(i._1.head))(i._1.tail).rect;g()},rk=t=>e=>n=>J(r=>o=>{const i=Z3(o.rect)(r.obstacles),a=i.x>=t.x+4&&i.y>=t.y+4&&i.x+i.w<=t.x+t.w-4&&i.y+i.h<=t.y+t.h-4?i:nk(t)(r.obstacles)(o)(i);return{acc:it(A)(o.id)(a)(r.acc),obstacles:St(r.obstacles)(a)}})({acc:Q,obstacles:e})(n).acc,u_=t=>t,ao=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ui=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ok=vi(oc)(Qt),ik=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ak=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Rh=u_("SegMove"),sk=u_("SegLine"),uk=u_("SegQuad"),Dh={offset:.4,passes:1,rMax:1.5},Fh=t=>he(Kn(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,hu=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},pu=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},so=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},Ba=(()=>{const t=J(e=>n=>((e*31|0)+he(Kn(n.x*100))|0)+he(Kn(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),ck=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const o=n,i=r,a=o>=0&&o<t.length?N("Just",t[o]):w;if(a.tag==="Nothing"){n=t.length;continue}if(a.tag==="Just"){if(a._1===1){const s={x:(()=>{const u=o+1|0;return u>=0&&u<t.length?t[u]:0})(),y:(()=>{const u=o+2|0;return u>=0&&u<t.length?t[u]:0})()};e.push({kind:Rh,m:i,c:i,p:s,len:0}),r=s,n=o+3|0;continue}if(a._1===2){const s={x:(()=>{const _=o+1|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+2|0;return _>=0&&_<t.length?t[_]:0})()},u=s.x-i.x,c=s.y-i.y;e.push({kind:sk,m:i,c:i,p:s,len:nn(u*u+c*c)}),r=s,n=o+3|0;continue}if(a._1===3){const s={x:(()=>{const _=o+3|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+4|0;return _>=0&&_<t.length?t[_]:0})()},u=s.x-i.x,c=s.y-i.y;e.push({kind:uk,m:i,c:{x:(()=>{const _=o+1|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+2|0;return _>=0&&_<t.length?t[_]:0})()},p:s,len:nn(u*u+c*c)*1.05}),r=s,n=o+5|0;continue}if(a._1===5){e.push({kind:Rh,m:i,c:i,p:i,len:0}),n=o+1|0;continue}n=t.length;continue}g()}return e},gk=t=>e=>{const n=e.length-1|0,r=n<1?[]:At(0,n,e),o=(()=>{const a=r.length-1|0;return a>=0&&a<r.length?N("Just",r[a]):w})(),i=e.length-1|0;if(i>=0&&i<e.length&&o.tag==="Just"){const a=e[i].y-o._1.y,s=e[i].x-o._1.x,u=nn(s*s+a*a);return u<=1e-4?e:St((()=>{const c=e.length-1|0;return c<1?[]:At(0,c,e)})())({x:e[i].x+s/u*t,y:e[i].y+a/u*t})}return e},_k=t=>e=>n=>re(J(r=>o=>{const i=Ie(0)(t)(r.prng),a=Ie(0)(6.283185307179586)(i.prng);return{prng:a.prng,out:[{x:o.x+i.value*hn(a.value),y:o.y+i.value*en(a.value)},...r.out]}})({prng:e,out:[]})(n).out),fk=t=>e=>n=>{if(e.kind==="SegMove")return pu(t)(e.p);if(e.kind==="SegLine")return so(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 so(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});g()},dk=t=>e=>{if(e.kind==="SegMove")return pu(t)(e.p);if(e.kind==="SegLine")return so(t)(e.p);if(e.kind==="SegQuad")return hu(t)(e.c)(e.p);g()},Ih=t=>e=>{const n=ck(e),r=J(s=>u=>s+u.len)(0)(n)*ao(0)(ui(1)(t)),o=[];let i=0,a=0;for(;a<n.length;){const s=a,u=i;if(s>=0&&s<n.length){if(u+n[s].len<=r){const c=n[s];dk(o)(c)(),i=u+c.len,a=s+1|0;continue}if(u>=r){a=n.length;continue}fk(o)(n[s])((r-u)/ao(n[s].len)(1e-4))()}a=n.length}return o},Bh={offset:1.5,passes:2,rMax:14,overshoot:2.5},Qh=t=>e=>n=>r=>{const o=r.y-n.y,i=n.y-e.y,a=r.x-n.x,s=nn(a*a+o*o),u=n.x-e.x,c=nn(u*u+i*i),_=ui(t.rMax*(T2(c>0&&s>0?ao(-1)(ui(1)((u*a+i*o)/(c*s))):1)/3.141592653589793))(.4*ui(c)(s));return{inP:c>0?{x:n.x-u/c*_,y:n.y-i/c*_}:n,curr:n,outP:s>0?{x:n.x+a/s*_,y:n.y+o/s*_}:n}},zh=t=>e=>{const n=e.length,r=[],o=0<e.length?N("Just",e[0]):w;if(o.tag==="Just"?pu(r)(o._1)():o.tag==="Nothing"||g(),n>=3){let a=1;for(;a<=(n-2|0);){const s=a,u=s+1|0;if(u>=0&&u<e.length){if(s>=0&&s<e.length){const c=s-1|0;if(c>=0&&c<e.length){const _=Qh(t)(e[c])(e[s])(e[u]);so(r)(_.inP)(),hu(r)(_.curr)(_.outP)()}}a=s+1|0;continue}a=s+1|0}}const i=e.length-1|0;return i>=0&&i<e.length&&n>=2&&so(r)(e[i])(),r},lk=t=>e=>n=>r=>o=>{if(o.length<4)return zh(t)(o);const i=0<o.length?N("Just",o[0]):w,a=(()=>{if(i.tag==="Nothing")return{x:0,y:0};if(i.tag==="Just")return i._1;g()})(),s=o.length-1|0,u=lo(lo(e)(s)+s|0)(s),c=d=>{const h=lo(d+s|0)(s);return h>=0&&h<o.length?o[h]:a},_=Y(d=>Qh(t)(c((u+d|0)-1|0))(c(u+d|0))(c((u+d|0)+1|0)))(Ut(0,s-1|0)),l=[],f=0<_.length?N("Just",_[0]):w;if(f.tag==="Just")if(pu(l)(f._1.outP)(),ok((()=>{const d=Pt(h=>w,h=>m=>N("Just",m),_);if(d.tag==="Nothing")return[];if(d.tag==="Just")return d._1;g()})())(d=>{const h=so(l)(d.inP);return()=>(h(),hu(l)(d.curr)(d.outP)())})(),n)so(l)(f._1.inP)(),hu(l)(f._1.curr)(f._1.outP)(),l.push(5);else{const d=_.length-1|0;d>=0&&d<_.length?so(l)((()=>{const h=1-r;return{x:_[d].outP.x+(f._1.inP.x-_[d].outP.x)*h,y:_[d].outP.y+(f._1.inP.y-_[d].outP.y)*h}})())():so(l)(f._1.inP)()}else f.tag==="Nothing"||g();return l},Yi=t=>e=>n=>r=>{const o=ik(1)(r.length-1|0),i=Ie(0)(nt(o))(Vg("shape")(e)),a=ak(o-1|0)(he(Kn(i.value))),s=i.prng;return Y(u=>{const c=Ie(0)(1)(Vg(ae(u))(s)),_=Ie(-.18)(.3)(c.prng),l=c.value<.7,f=Ie(.5)(.85)(_.prng),d=_k(t.offset)(f.prng)(r);return{path:n?lk(t)(a)(l)(_.value)(d):zh(t)(d),alpha:f.value}})(Ut(0,t.passes-1|0))},hk=t=>e=>n=>Yi(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}]),pk=t=>e=>n=>{const r=ao(0)(ui(1)(n)),o=e.h/nt(4),i=ao(6)(o*1.4);return wt(a=>a)(Y(a=>{if(r<ao(0)(nt(a)/nt(4)-.05))return w;const s=Vg(ae(a))(t),u=ao(0)(nt(a)/nt(4)-.05),c=lo(a)(2)===0,_=c?e.x-2:e.x+e.w+2,l=c?e.x+e.w+2:e.x-2,f=e.y+(nt(a)+.5)*o;return N("Just",{path:Ih(ao(0)(ui(1)((r-u)/ao(1e-4)(ui(1)(nt(a+1|0)/nt(4)+.05)-u))))((()=>{const d={rMax:2,offset:.6,passes:1},h=re(J(p=>x=>{const y=Ie(-o*.08)(o*.08)(p.prng);return{prng:y.prng,out:[{x:_+(l-_)*(nt(x)/nt(4)),y:f+y.value},...p.out]}})({prng:s,out:[]})(Ut(0,4)).out),m=h.length<2?[]:Yi(d)(s)(!1)(h);return 0<m.length?m[0].path:[]})()),width:i,alpha:1})})(Ut(0,3)))},c_=(t,e,n)=>({tag:t,_1:e,_2:n}),Qa=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Mh=t=>t,g_=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},on=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Hn=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ze=(()=>{const t=wn.unfoldr(gr);return e=>t(Tn("IterNode",e,ur))})(),mk=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ci=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},_e=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},yk=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},pr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},xk=Qt.foldMap(F2),mu=_o.traverse(No),Vi=J(_r)(0),Oh=ge(A)(Qt),wk=Cf(A),Tk=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},Nk=ge(A)(Qt),Wh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},__=Mh("FullTokenGeometry"),vk=Mh("ConvexInsideGeometry"),gi=t=>{const e=t.Apply0();return n=>J(r=>o=>e.apply(e.Functor0().map(i=>cf)(r))(n(o)))(t.pure())},$n=gi(No),qh=t=>e=>n=>r=>o=>i=>{const a={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},u=Ia(o)(i)(r),c=0<t.length?N("Just",t[0]):w,_=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return s;g()})(),l=t.length-1|0,f=l>=0&&l<t.length?N("Just",t[l]):w,d=(()=>{if(f.tag==="Just")return f._1;if(f.tag==="Nothing")return a;g()})(),h=_.x-s.x,m=2*(()=>{const C=_.y-s.y;return(h<0?-h:h)+(C<0?-C:C)})(),p=d.x-a.x,x=2*(()=>{const C=d.y-a.y;return(p<0?-p:p)+(C<0?-C:C)})(),y=m+_s(t)+x,T=y<=1e-4?1:1-x/y,v=y<=1e-4?0:m/y,b=T-v;return{progress:u,morphOutEnd:v,morphInStart:T,outT:(()=>{if(v<=1e-4)return 1;const C=u/v,S=C<0?0:C>1?1:C;return S*S*(3-2*S)})(),inT:(()=>{if(T>=1)return 0;const C=(u-T)/(1-T),S=C<0?0:C>1?1:C;return S*S*(3-2*S)})(),pathStart:_,pathEnd:d,travelPt:(()=>{const C=Ei(t)(g_(0)(1)(b<=1e-4?0:(u-v)/b));if(C.tag==="Just")return C._1;if(C.tag==="Nothing")return _;g()})()}},Hh=t=>e=>n=>r=>o=>i=>{const a=qh(t)(e)(n)(r)(o)(i),s=ch(128)(si(4)(e))(Eh(a.pathStart)(6)),u=ch(128)(Eh(a.pathEnd)(6))(si(4)(n)),c={maxDelay:.4,smoothPasses:2};return a.progress<a.morphOutEnd?oi("PolyShape",_h(a.outT)(s.from)(s.to)(c)):a.progress>=a.morphInStart?oi("PolyShape",_h(a.inT)(u.from)(u.to)(c)):oi("CircleShape",a.travelPt,6)},f_=t=>e=>n=>r=>o=>i=>{const a=Hh(t)(e)(n)(r)(o)(i);if(a.tag==="PolyShape")return o_(a._1);if(a.tag==="CircleShape")return a._1;g()},$h=t=>e=>n=>r=>on(t)(n-.5)<=Hn(e)(r+.5),Jk=t=>{const e=n=>{const r=te(o=>n.x>=o._2.x-1&&n.x<=o._2.x+o._2.w+1&&n.y>=o._2.y-1&&n.y<=o._2.y+o._2.h+1)(Ze(t.nodes));return r.tag==="Just"?N("Just",r._1._2):w};return n=>{const r=(()=>{if(0<n.length){const i=e(n[0]);if(i.tag==="Just")return re(Gh(si(7)(i._1))(re(n)))}return n})(),o=r.length-1|0;if(o>=0&&o<r.length){const i=e(r[o]);if(i.tag==="Just")return Gh(si(7)(i._1))(r)}return r}},Ck=t=>e=>{const n=((t.bg.r+t.bg.g|0)+t.bg.b|0)<384,r=n?90:104,o=n?165:122,i=a=>mk(255)(ci(0)(he(Bn(o+r*en(e+a)))));return{r:i(0),g:i(-2.0943951023931953),b:i(-4.1887902047863905),a:255}},Yh=t=>e=>{if(t<=0)return[];const n=Pt(r=>w,r=>o=>N("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return gn(n._1.head.text).length<=t?[n._1.head,...Yh(t-gn(n._1.head.text).length|0)(n._1.tail)]:[{...n._1.head,text:Fe(t)(n._1.head.text)}];g()},d_=(()=>{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},o={r:28,g:101,b:192,a:255},i={r:247,g:248,b:250,a:255},a={r:42,g:48,b:60,a:255},s={r:120,g:130,b:146,a:255};return u=>{if(u==="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:no,nodeFill:ve,nodeStroke:no,text:no,edge:no,arrowFill:no,tokenOutsideFill:no,tokenOutsideStroke:ve,tokenInside:ve,tokenInsideStroke:ve,tokenInsideBlend:iu,tokenInsideAlpha:1,chipPillFill:no,chipPillText:ve,chipHairline:{r:26,g:26,b:26,a:90},trailDot:no,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(u==="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:no,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:ve,tokenOutsideStroke:ve,tokenInside:ve,tokenInsideStroke:ve,tokenInsideBlend:iu,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(u==="Blueprint")return{bg:o,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:90,g:160,b:230,a:255},shadowFill:o,shadowDot:ve,chip:ve,chipShadow:{r:0,g:0,b:0,a:120},chipText:o,nodeFill:o,nodeStroke:ve,text:ve,edge:ve,arrowFill:ve,tokenOutsideFill:ve,tokenOutsideStroke:ve,tokenInside:ve,tokenInsideStroke:ve,tokenInsideBlend:Hl,tokenInsideAlpha:.35,chipPillFill:ve,chipPillText:o,chipHairline:{r:255,g:255,b:255,a:120},trailDot:ve,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(u==="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:Hl,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(u==="Isometric")return{bg:i,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:218,b:224,a:255},shadowFill:i,shadowDot:a,chip:{r:255,g:235,b:130,a:255},chipShadow:{r:100,g:110,b:125,a:90},chipText:a,nodeFill:{r:236,g:239,b:244,a:255},nodeStroke:a,text:a,edge:s,arrowFill:s,tokenOutsideFill:a,tokenOutsideStroke:ve,tokenInside:ve,tokenInsideStroke:ve,tokenInsideBlend:iu,tokenInsideAlpha:1,chipPillFill:a,chipPillText:ve,chipHairline:{r:60,g:66,b:78,a:90},trailDot:a,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};g()}})(),l_=t=>e=>Et(Ze(t))(n=>{const r=_e(n._1)(e.nodes);return r.tag==="Just"&&ni(r._1).alpha>0?Co(n._2):[]}),bk=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,...l_(e)(n)],kk=t=>e=>n=>{const r=(o,i)=>he(Bn(nt(o)+(nt(i)-nt(o))*n));return{r:r(t.r,e.r),g:r(t.g,e.g),b:r(t.b,e.b),a:r(t.a,e.a)}},Lk=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=_o.traverse(r);return i=>a=>{const s=zn(a),u=.32*i.size;return o(c=>n.bind(c===0?r.pure(0):t.measureText(i)(Fe(c)(a)))(_=>n.bind(t.measureText(i)(Fe(c+1|0)(a)))(l=>n.bind(t.measureInk(i)(c>=0&&c<s.length?fr(s[c]):" "))(f=>r.pure({x:_,w:l-_,up:f.ascent-u,down:f.descent+u})))))(Ut(0,s.length-1|0))}},Vh=t=>[...Co({...t,x:t.x-1.25,y:t.y-1.25,w:t.w+2.5,h:t.h+2.5}),...Co({...t,y:t.y-5})],Sk=t=>e=>{const n=o=>(o.x-e.x)*(o.x-e.x)+(o.y-e.y)*(o.y-e.y),r=J(o=>i=>n(i)<n(o)?i:o)({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 Y(o=>{const i=nt(o)/5;return{x:r.x+(e.x-r.x)*i,y:r.y+(e.y-r.y)*i}})([1,2,3,4])},za=t=>e=>n=>{const r=yk(ae(e)+":"+ae(n))(t);if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()},Ek=t=>e=>{const n=e.length;return J(r=>o=>J(i=>a=>it(A)(ae(o)+":"+ae(a))(a>=0&&a<e.length&&o>=0&&o<t.length?t[o]===e[a]?1+za(i)(o+1|0)(a+1|0)|0:ci(za(i)(o+1|0)(a))(za(i)(o)(a+1|0)):0)(i))(r)(n<=0?[]:re(Ut(0,n-1|0))))(Q)((()=>{const r=t.length;return r<=0?[]:re(Ut(0,r-1|0))})())},h_=t=>or(t),Pk=t=>e=>n=>r=>o=>i=>{const a=qh(t)(e)(n)(r)(o)(i);return a.progress<a.morphOutEnd?c_("InsideRect",n_(2)(e)):a.progress>=a.morphInStart?c_("InsideRect",n_(2)(n)):c_("InsideBall",a.travelPt,6)},p_=t=>e=>n=>r=>o=>i=>a=>s=>{const u=(c,_)=>bh({id:c,pass:t,geometry:hh("FlatToken",_),position:(()=>{if(_.tag==="CircleShape")return _._1;if(_.tag==="PolyShape")return o_(_._1);g()})(),plan:mh("FlatTokenPlan",{wobble:n,fill:a,stroke:s})});return $n(c=>{if(c._2.tag==="Travelling"){const _=_e(c._2._1.target)(r),l=_e(c._2._1.source)(r);if(l.tag==="Just"&&_.tag==="Just"){const f=pr(c._2._1.edge)(o);if(f.tag==="Just"){const d=(()=>{if(c._2._1.direction==="Forward")return f._1;if(c._2._1.direction==="Backward")return re(f._1);g()})();return u(c._1,(()=>{if(e==="FullTokenGeometry")return Hh(d)(l._1)(_._1)(c._2._1.progress)(c._2._1.holdPre)(c._2._1.holdPost);if(e==="ConvexInsideGeometry"){const h=Pk(d)(l._1)(_._1)(c._2._1.progress)(c._2._1.holdPre)(c._2._1.holdPost);if(h.tag==="InsideRect")return oi("PolyShape",i_(4)(h._1));if(h.tag==="InsideBall")return oi("CircleShape",h._1,h._2)}g()})())}if(f.tag==="Nothing"){const d=Ia(c._2._1.holdPre)(c._2._1.holdPost)(c._2._1.progress),h={x:l._1.x+l._1.w/2,y:l._1.y+l._1.h/2},m={x:_._1.x+_._1.w/2,y:_._1.y+_._1.h/2};return Ae({path:[],role:_n,layer:w,effects:[me("GroupAlpha",(()=>{if(d<.5){const x=d*2;return 1-on(0)(Hn(1)(x))*on(0)(Hn(1)(x))*(3-2*on(0)(Hn(1)(x)))}const p=(d-.5)*2;return on(0)(Hn(1)(p))*on(0)(Hn(1)(p))*(3-2*on(0)(Hn(1)(p)))})())]})(u(c._1,oi("CircleShape",d<.5?h:m,6)))}g()}return U(st("Return",void 0),ct)}if(c._2.tag==="Filling"){if(n)return U(st("Return",void 0),ct);const _=_e(c._2._1.node)(r);if(_.tag==="Just")return u(c._1,oi("PolyShape",si(4)(e==="ConvexInsideGeometry"?n_(2)(_._1):_._1)));if(_.tag==="Nothing")return U(st("Return",void 0),ct);g()}return U(st("Return",void 0),ct)})(Ze(i.tokens))},Gk=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0();return o=>n.bind((()=>{const i=r.pure();if(o.clear.tag==="Nothing")return i;if(o.clear.tag==="Just")return t.clearBackground(o.clear._1);g()})())(()=>n.bind(t.setViewport(o.viewport))(()=>{const i=r.pure();if(o.dots.tag==="Nothing")return i;if(o.dots.tag==="Just")return t.backgroundDots(o.dots._1);g()}))},Xh=t=>e=>n=>r=>Ae({path:[],role:_n,layer:w,effects:[me("GroupAlpha",n.fadeAlpha),me("GroupTransform",ii,{tx:t.x*(1-n.popScale),ty:(t.y+t.h)*(1-n.popScale),sx:n.popScale,sy:n.popScale}),me("GroupTransform",ii,{tx:0,ty:e.y*(1-n.flipY),sx:1,sy:n.flipY})]})(ai(r)),Ak=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const c=_=>l=>{const f=Pt(d=>w,d=>h=>N("Just",{head:d,tail:h}),l);if(f.tag==="Nothing")return U(st("Return",void 0),ct);if(f.tag==="Just"){const d=f._1,h=to(i)(fr(d.head)),m=p=>{const x=ai({owner:oo("NodeText",o),text:fr(d.head),spec:{x:_,y:s-n*i.size*.11*en(e*5-_*.22),content:fr(d.head),font:i,color:kk(r.text)(Ck(r)(e*2.2+_*.16))(n),align:vo,baseline:Nn},bounds:w,plan:t});return U(x._1,(()=>{if(x._2.tag==="CatNil")return Z("CatCons",()=>c(_+p)(d.tail),K(G,G));if(x._2.tag==="CatCons")return Z("CatCons",x._2._1,K(x._2._2._1,pt("Cons",Z("CatCons",()=>c(_+p)(d.tail),K(G,G)),x._2._2._2)));g()})())};return U(h._1,(()=>{if(h._2.tag==="CatNil")return Z("CatCons",m,K(G,G));if(h._2.tag==="CatCons")return Z("CatCons",h._2._1,K(h._2._2._1,pt("Cons",Z("CatCons",m,K(G,G)),h._2._2._2)));g()})())}g()};return c(a)(zn(u))},Uh=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>a==="RunHighlight"||a==="RunCodeHighlight"?Ak(t)(e)(n)(r)(o)(i)(s)(u)(c):ai({owner:oo("NodeText",o),text:c,spec:{x:s,y:u,content:c,font:i,color:r.text,align:vo,baseline:Nn},bounds:w,plan:t}),Rk=t=>e=>n=>r=>o=>i=>a=>Xh(o)(i)(a)({owner:oo("TokenText",t),text:n,spec:{x:i.x,y:i.y,content:n,font:{family:e.fontFamily,size:11,weight:500},color:e.chipText,align:eo,baseline:Nn},bounds:N("Just",o),plan:ri("TokenFillingText",{shadow:{...o,y:o.y+1.5},shadowFill:{color:e.chipShadow,flat:!0},radius:6,fill:{color:e.chip,flat:!0},stroke:{color:e.chipHairline,width:1,lineJoin:Ve,lineCap:Pn},leader:[1,i.x,o.y+o.h,2,r.x+r.w/2,r.y]})}),Dk={offset:.8,passes:2,rMax:5},Kh=t=>e=>n=>r=>t.strokePath((()=>{const o=Pt(i=>w,i=>a=>N("Just",{head:i,tail:a}),Y(i=>i.pt)(p2(i=>a=>{const s=nt(a)/nt(72),u=Ie(-.18)(.18)(i.prng),c=Ie(-.1)(.1)(u.prng),_=Ie(-.07)(.07)(c.prng),l=n*(.05+.55*s)*(1+c.value),f=s*28.274333882308138+u.value;return{prng:_.prng,pt:{x:e.x+hn(f)*l+_.value*n,y:e.y+en(f)*l+_.value*n}}},{prng:137,pt:{x:e.x,y:e.y}},Ut(0,72))));if(o.tag==="Just")return[1,o._1.head.x,o._1.head.y,...xk(i=>[2,i.x,i.y])(o._1.tail)];if(o.tag==="Nothing")return[];g()})())({color:r,width:5.5,lineJoin:Ve,lineCap:ir}),Fk=t=>{const e=t.Monad0().Applicative0();return n=>{if(n.geometry.tag==="FlatToken"&&n.plan.tag==="FlatTokenPlan"){if(n.geometry._1.tag==="CircleShape")return n.plan._1.wobble?Kh(t)(n.geometry._1._1)(n.geometry._1._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(Ph(n.geometry._1._1)(n.geometry._1._2))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:Ve,lineCap:Pn});if(n.geometry._1.tag==="PolyShape")return n.plan._1.wobble&&n.geometry._1._1.length>=3?Kh(t)(o_(n.geometry._1._1))(6)({r:200,g:35,b:30,a:220}):n.geometry._1._1.length>=3?t.fillStrokePath(Sh(n.geometry._1._1))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:Ve,lineCap:Pn}):e.pure();g()}return e.pure()}},Ik=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popClip,i=t.popTransform,a=t.popAlpha;return s=>u=>c=>_=>l=>{const f=ni(l),d=c*f.alpha,h={..._,y:_.y+5},m=_.x+_.w/2,p=_.y+_.h/2,x=Vh(h),y=r.bind(t.pushAlpha(d))(()=>r.bind(t.pushTransform({tx:m*(1-f.scale),ty:p*(1-f.scale),sx:f.scale,sy:f.scale}))(()=>r.bind(t.pushClip(x)($g))(()=>r.bind(ei(t)(h.shape)({x:h.x,y:h.y,w:h.w,h:h.h})(7)(N("Just",{color:s.shadowFill,flat:!0}))(w))(()=>r.bind((()=>{const T=r.bind(t.pushClip(Co(h))(Jo))(()=>r.bind(t.backgroundDots({viewport:{vx:h.x,vy:h.y,vw:h.w,vh:h.h},bgColor:s.bgTransparent,dotColor:s.shadowDot,tile:1.6,dotRadius:.25,origin:{x:0,y:0}}))(()=>o));return u&&!s.wobble?T:n.pure()})())(()=>r.bind(ei(t)(h.shape)({x:h.x,y:h.y,w:h.w,h:h.h})(7)(w)(N("Just",{color:s.nodeStroke,width:1.25,lineJoin:Ve,lineCap:Pn})))(()=>r.bind(o)(()=>r.bind(i)(()=>a))))))));return d>0&&!s.wobble?y:n.pure()}},Bk=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=gi(e.Applicative0());return i=>a=>s=>o(u=>n.bind(t.pushAlpha(u.alpha))(()=>n.bind(t.strokePath(u.path)({color:i.nodeFill,width:u.width,lineJoin:Ve,lineCap:ir}))(()=>r)))(pk(Fh(a)+7777|0)(a)(s))},Qk=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=e.Applicative0(),i=gi(o),a=t.popClip,s=gi(o),u=_o.traverse(o),c=Lk(t),_=Bk(t),l=t.popTransform;return f=>d=>h=>m=>p=>x=>y=>T=>v=>b=>{const C=B=>n.bind(t.pushAlpha(B.alpha))(()=>n.bind(t.strokePath(B.path)({color:h.nodeStroke,width:2,lineJoin:Ve,lineCap:ir}))(()=>r)),S={family:h.fontFamily,size:h.wobble?15:11,weight:h.wobble?800:500},P=or(v.label===""?T:v.label),F=S.size*1.2,W=v.shape==="Cylinder"?t.strokePath(Yb({x:v.x,y:v.y,w:v.w,h:v.h}))({color:h.nodeStroke,width:1.25,lineJoin:Ve,lineCap:Pn}):o.pure(),E=(v.shape==="Cylinder"?(v.y+(v.y+v.h+5-2*vn(v.h*.075)(v.w*.075)))/2:(v.y+v.y+v.h)/2)-nt(P.length)*F/2+F/2,R=b.tag==="PloppingOut"&&h.wobble?b._1:-1,et=R>=0,rt=ni(b),$=et?{alpha:1,scale:1}:rt,X=v.x+v.w/2,V=v.y+v.h/2,D=n.bind(t.pushAlpha($.alpha))(()=>n.bind(t.pushTransform({tx:X*(1-$.scale),ty:V*(1-$.scale),sx:$.scale,sy:$.scale}))(()=>{const B={x:v.x,y:v.y,w:v.w,h:v.h},I={color:h.nodeStroke,width:h.wobble?2:1.25*d,lineJoin:Ve,lineCap:h.wobble?ir:Pn},M=(()=>{if(h.wobble){if(v.shape==="Rectangle")return i(C)(hk(Bh)(Fh(B))(B));const j=si(7)(v);return n.bind(i(C)((()=>{const z=Ba(j);return j.length<4?[]:Yi(Dh)(z)(!0)(j)})()))(()=>s(z=>i(C)((()=>{const q=Ba(z);return z.length<2?[]:Yi(Dh)(q)(!1)(z)})()))(v.shape==="Cylinder"?[H3(v)]:[]))}return n.bind(ei(t)(v.shape)(B)(7)(w)(N("Just",I)))(()=>W)})();return n.bind((()=>{if(p.tag==="Nothing")return n.bind(t.pushAlpha(m))(()=>n.bind(h.wobble?M:n.bind(ei(t)(v.shape)(B)(7)(N("Just",{color:h.nodeFill,flat:!1}))(N("Just",I)))(()=>W))(()=>n.bind((()=>{if(y.tag==="Just"&&h.wobble&&!et){const j=y._1;return n.bind(u(c(S))(P))(z=>{const q=Rt(ht=>Jt=>at.compare(ht.x)(Jt.x)),H=he(Kn(v.x*7919+v.y*3001))*-1640531535|0,O=Ie(5)(7.5)(H),ot=Ie(0)(O.value)(O.prng),tt=-(1+2*Ie(-1)(1)(ot.prng).value*3.141592653589793/180),gt=(ht,Jt,Mt,Bt,ie)=>q(wt(ce=>ce)([tt*Jt+ht>=Bt&&tt*Jt+ht<=ie?N("Just",{x:Jt,y:tt*Jt+ht}):w,tt*Mt+ht>=Bt&&tt*Mt+ht<=ie?N("Just",{x:Mt,y:tt*Mt+ht}):w,(()=>{const ce=(Bt-ht)/tt;return ce>=Jt&&ce<=Mt?N("Just",{x:ce,y:Bt}):w})(),(()=>{const ce=(ie-ht)/tt;return ce>=Jt&&ce<=Mt?N("Just",{x:ce,y:ie}):w})()])),Lt=O.value,ft=lo(j.frameHash)(3),Tt=ft===0?{r:200,g:35,b:30,a:220}:ft===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},kt=v.x+v.w/2,Kt=kn(Wt(ht=>Jt=>Wt((()=>{const Mt=E+nt(ht)*F,Bt=kt-J(ie=>ce=>ie+ce.w)(0)(Jt)/2;return ie=>ce=>{const dn=S.size*.1,Ht=ie-1|0,jt=Ht>=0&&Ht<Jt.length&&ie>0?(Jt[Ht].x+Jt[Ht].w+ce.x)/2:ce.x-dn;return{x:Bt+jt-1,y:Mt-ce.up-1,w:on(0)((()=>{const sn=ie+1|0;return sn>=0&&sn<Jt.length&&ie<(Jt.length-1|0)?(ce.x+ce.w+Jt[sn].x)/2-jt:ce.x+ce.w+dn-jt})())+2,h:ce.up+ce.down+2}}})())(Jt))(z)),Nt=v.y+4,Xt=v.x+v.w-4,Ft=v.x+4,vt=Nt-tt*Ft+ot.value,yt=v.y+v.h-4,dt=Et(Et(Wt(ht=>Jt=>{const Mt=(Jt.from.x+Jt.to.x)/2,Bt=(Jt.from.y+Jt.to.y)/2,ie=Ie(-1)(1)(H+(911*(ht+1|0)|0)|0),ce=Ie(-3)(5)(ie.prng),dn=ie.value*3.141592653589793/180,Ht=hn(dn),jt=en(dn),sn=He=>({x:Mt+(He.x-Mt)*Ht-(He.y-Bt)*jt,y:Bt+(He.x-Mt)*jt+(He.y-Bt)*Ht});return{from:(()=>{const He=sn(Jt.from),Dn=He.y-Bt,Fn=He.x-Mt,tn=nn(Fn*Fn+Dn*Dn),se=tn<1e-4?1:(tn+ce.value)/tn;return{x:Mt+Fn*se,y:Bt+Dn*se}})(),to:(()=>{const He=sn(Jt.to),Dn=Ie(-3)(5)(ce.prng).value,Fn=He.y-Bt,tn=He.x-Mt,se=nn(tn*tn+Fn*Fn),Je=se<1e-4?1:(se+Dn)/se;return{x:Mt+tn*Je,y:Bt+Fn*Je}})()}})(wt(ht=>{const Jt=gt(vt+nt(ht)*Lt,Ft,Xt,Nt,yt);return Jt.length===2?N("Just",{from:Jt[0],to:Jt[1]}):w})(Ut(0,ci(1)(he(Kn((yt-tt*Xt-vt)/Lt)))))))(ht=>lt(Jt=>Jt.to.x-Jt.from.x>1,J(Jt=>Mt=>Et(Jt)(Bt=>{const ie=gt(Bt.from.y-tt*Bt.from.x,Mt.x,Mt.x+Mt.w,Mt.y,Mt.y+Mt.h);return ie.length===2?ie[0].x>Bt.from.x+.001&&ie[1].x<Bt.to.x-.001?[{from:Bt.from,to:ie[0]},{from:ie[1],to:Bt.to}]:ie[0].x<=Bt.from.x+.001&&ie[1].x<Bt.to.x-.001?[{from:ie[1],to:Bt.to}]:ie[0].x>Bt.from.x+.001&&ie[1].x>=Bt.to.x-.001?[{from:Bt.from,to:ie[0]}]:[]:[Bt]}))([ht])(Kt))))(ht=>(()=>{const Jt=ht.to.x-ht.from.x;return nn(2)*(Jt>=0?Jt:-Jt)<=28})()?[ht]:[{from:ht.from,to:{x:ht.from.x+(ht.to.x-ht.from.x)*.495,y:ht.from.y+(ht.to.y-ht.from.y)*.495}},{from:{x:ht.from.x+(ht.to.x-ht.from.x)*.505,y:ht.from.y+(ht.to.y-ht.from.y)*.505},to:ht.to}]),xt=dt.length,Dt=ht=>on(0)(Hn(1)(j.t*nt(xt)-nt(ht)));return n.bind(t.pushClip(Sh(si(7)(v)))(Jo))(()=>n.bind(i(ht=>{const Jt=ht._1,Mt=Ie(1.4)(1.9)(H+(1303*(Jt+1|0)|0)|0),Bt=Ie(.35)(.8)(Mt.prng),ie=i(ce=>n.bind(t.pushAlpha(ce.alpha*Bt.value))(()=>n.bind(t.strokePath(Ih(Dt(Jt))(ce.path))({color:Tt,width:Mt.value,lineJoin:Ve,lineCap:ir}))(()=>r)))(Yi({...Bh,rMax:0,offset:.5})(H+(53*(Jt+1|0)|0)|0)(!1)([ht._2.from,ht._2.to]));return Dt(Jt)>0?ie:o.pure()})(Wt(bn)(dt)))(()=>a))})}return o.pure()})())(()=>n.bind((()=>{if(f==="LabelsShown"){const j=n.bind(t.pushAlpha(x))(()=>n.bind(i(z=>t.drawText({x:v.x+v.w/2,y:E+nt(z._1)*F,content:z._2,font:S,color:h.text,align:eo,baseline:Nn}))(Wt(bn)(P)))(()=>r));return x>0?j:o.pure()}if(f==="LabelsHidden")return o.pure();g()})())(()=>n.bind((()=>{const j=_(h)(B)(R);return et?j:o.pure()})())(()=>r)))));if(p.tag==="Just"){const j=p._1;return n.bind((()=>{const z=n.bind(t.pushAlpha(m))(()=>n.bind(ei(t)(v.shape)(B)(7)(N("Just",{color:h.nodeFill,flat:!1}))(w))(()=>r));return m>0&&!h.wobble?z:o.pure()})())(()=>{const z=n.bind(t.pushAlpha(j))(()=>n.bind(M)(()=>r));return j>0?z:o.pure()})}g()})())(()=>n.bind(l)(()=>r))}));return $.alpha*on(m)((()=>{if(p.tag==="Nothing")return m;if(p.tag==="Just")return p._1;g()})())>0?D:o.pure()}},zk=t=>e=>n=>{const r={family:t.fontFamily,size:11,weight:500};return $n(o=>{if(o._2===""||(()=>{const s=pr(o._1)(n.edges);return s.tag==="Nothing"||!(s.tag==="Just"&&zw.eq(s._1)(W1))})())return U(st("Return",void 0),ct);const i=pr(o._1)(e.edges),a=(()=>{if(i.tag==="Just")return Ei(i._1)(.5);if(i.tag==="Nothing")return w;g()})();if(a.tag==="Nothing")return U(st("Return",void 0),ct);if(a.tag==="Just"){const s=a._1,u=to(r)(o._2),c=_=>{const l=_+12;return ai({owner:oo("EdgeText",o._1),text:o._2,spec:{x:s.x,y:s.y,content:o._2,font:r,color:t.chipPillText,align:eo,baseline:Nn},bounds:N("Just",{x:s.x-l/2,y:s.y-8.5,w:l,h:17}),plan:ri("RoundedText",{radius:3,fill:N("Just",{color:t.chipPillFill,flat:!0}),stroke:w})})};return U(u._1,(()=>{if(u._2.tag==="CatNil")return Z("CatCons",c,K(G,G));if(u._2.tag==="CatCons")return Z("CatCons",u._2._1,K(u._2._2._1,pt("Cons",Z("CatCons",c,K(G,G)),u._2._2._2)));g()})())}g()})(Ze(e.edgeLabels))},Mk=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popClip,i=t.popTransform,a=t.popAlpha;return s=>u=>c=>_=>l=>{const f=ni(l),d=c*f.alpha,h=_.x+_.w/2,m=_.y-5+_.h/2,p=Vh(_),x=r.bind(t.pushAlpha(d))(()=>r.bind(t.pushTransform({tx:h*(1-f.scale),ty:m*(1-f.scale),sx:f.scale,sy:f.scale}))(()=>r.bind(t.pushClip(p)($g))(()=>r.bind(ei(t)(_.shape)({x:_.x,y:_.y,w:_.w,h:_.h})(7)(N("Just",{color:s.shadowFill,flat:!0}))(w))(()=>r.bind((()=>{const y=r.bind(t.pushClip(Co(_))(Jo))(()=>r.bind(t.backgroundDots({viewport:{vx:_.x,vy:_.y,vw:_.w,vh:_.h},bgColor:s.bgTransparent,dotColor:s.shadowDot,tile:1.6,dotRadius:.25,origin:{x:0,y:0}}))(()=>o));return u?y:n.pure()})())(()=>r.bind(ei(t)(_.shape)({x:_.x,y:_.y,w:_.w,h:_.h})(7)(w)(N("Just",{color:s.nodeStroke,width:1.25,lineJoin:Ve,lineCap:Pn})))(()=>r.bind(o)(()=>r.bind(i)(()=>a))))))));return d>0&&!s.wobble?x:n.pure()}},Ok=t=>{const e=Ik(t),n=Mk(t),r=Qk(t);return o=>{if(o.geometry.tag==="FlatNode"&&o.plan.tag==="FlatNodePlan"){const i={x:o.geometry._1.bounds.x,y:o.geometry._1.bounds.y,w:o.geometry._1.bounds.w,h:o.geometry._1.bounds.h,label:o.plan._1.label,shape:o.geometry._1.shape};if(o.role==="NodeShadow")return e(o.plan._1.palette)(o.plan._1.inkBoost>0)(o.alpha)(i)(o.plan._1.animState);if(o.role==="NodeDoorwayFrame")return n(o.plan._1.palette)(o.plan._1.inkBoost>0)(o.alpha)(i)(o.plan._1.animState);if(o.role==="NodeBody"||o.role==="NodeInversion")return r(_u)(o.plan._1.inkBoost)(o.plan._1.palette)(o.alpha)(o.plan._1.outlineAlpha)(0)(o.plan._1.arrival)(o.id)(i)(o.plan._1.animState);g()}return t.Monad0().Applicative0().pure()}},Wk=t=>e=>{const n=zn(t),r=n.length,o=zn(e),i=o.length,a=Ek(n)(o);return(s=>u=>c=>{let _=s,l=u,f=c,d=!0,h;for(;d;){const m=_,p=l,x=f;if(m>=r&&p>=i){d=!1,h=re(x);continue}if(m>=r){if(p>=0&&p<o.length){_=m,l=p+1|0,f=[Qa("DiffInsert",p,o[p]),...x];continue}d=!1,h=re(x);continue}if(p>=i){if(m>=0&&m<n.length){_=m+1|0,l=p,f=[Qa("DiffDelete",m,n[m]),...x];continue}d=!1,h=re(x);continue}if(p>=0&&p<o.length){if(m>=0&&m<n.length){if(n[m]===o[p]){_=m+1|0,l=p+1|0,f=[Qa("DiffKeep",m,p,n[m]),...x];continue}if(za(a)(m+1|0)(p)>=za(a)(m)(p+1|0)){_=m+1|0,l=p,f=[Qa("DiffDelete",m,n[m]),...x];continue}_=m,l=p+1|0,f=[Qa("DiffInsert",p,o[p]),...x];continue}d=!1,h=re(x);continue}d=!1,h=re(x)}return h})(0)(0)([])},Zh=t=>e=>n=>r=>o=>$n(i=>{if(t.tag==="Just"&&i._1===t._1)return U(st("Return",void 0),ct);const a=_e(i._1)(o.nodes);if(a.tag==="Just"){const s=_e(i._1)(o.nodeLabels),u=(()=>{if(s.tag==="Nothing")return i._2;if(s.tag==="Just"){if(s._1.tag==="StaticNodeLabel")return{...i._2,label:s._1._1===""?i._1:s._1._1};if(s._1.tag==="RelabelingNode")return{...i._2,label:(()=>{const c=s._1._1.progress<.5?s._1._1.oldLabel:s._1._1.newLabel;return c===""?i._1:c})()}}g()})();return fu({id:i._1,role:L3,geometry:su("FlatNode",{shape:u.shape,bounds:{x:u.x,y:u.y,w:u.w,h:u.h}}),alpha:(()=>{const c=_e(i._1)(o.nodeFadeAlpha),_=(()=>{if(c.tag==="Nothing")return 1;if(c.tag==="Just")return c._1;g()})();return _<1?0:_})(),plan:uu("FlatNodePlan",{palette:e,label:(()=>{const c=_e(i._1)(o.nodeLabels);if(c.tag==="Just"){if(c._1.tag==="StaticNodeLabel")return c._1._1===""?i._1:c._1._1;if(c._1.tag==="RelabelingNode"){const _=c._1._1.progress<.5?c._1._1.oldLabel:c._1._1.newLabel;return _===""?i._1:_}g()}if(c.tag==="Nothing")return u.label===""?i._1:u.label;g()})(),labelVisibility:_u,inkBoost:n?1:0,labelAlpha:0,outlineAlpha:w,arrival:w,animState:a._1})})}if(a.tag==="Nothing")return U(st("Return",void 0),ct);g()})(Ze(r.nodes)),qk=t=>e=>n=>(()=>{const r=t.x-e.x;return r<0?-r<=1e-6:r<=1e-6})()?t.x>=n.x-.5&&t.x<=n.x+n.w+.5&&$h(Hn(t.y)(e.y))(on(t.y)(e.y))(n.y)(n.y+n.h):(()=>{const r=t.y-e.y;return r<0?-r<=1e-6:r<=1e-6})()?t.y>=n.y-.5&&t.y<=n.y+n.h+.5&&$h(Hn(t.x)(e.x))(on(t.x)(e.x))(n.x)(n.x+n.w):!0,jh=t=>e=>n=>r=>r.length===2&&(()=>{const o=r[1],i=r[0];return cc(a=>a._1===e||a._1===n||!qk(i)(o)(a._2),Ze(t))})(),m_=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const c=hr(u),_=f=>d=>h=>{const m=Pt(x=>w,x=>y=>N("Just",{head:x,tail:y}),h),p=Pt(x=>w,x=>y=>N("Just",{head:x,tail:y}),d);if(p.tag==="Just"&&m.tag==="Just"){const x=Uh(t)(e)(n)(r)(o)(p._1.head.style==="RunCode"||p._1.head.style==="RunCodeHighlight"?{...i,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:i)(p._1.head.style)(f)(s)(p._1.head.text);return U(x._1,(()=>{if(x._2.tag==="CatNil")return Z("CatCons",()=>_(f+m._1.head)(p._1.tail)(m._1.tail),K(G,G));if(x._2.tag==="CatCons")return Z("CatCons",x._2._1,K(x._2._2._1,pt("Cons",Z("CatCons",()=>_(f+m._1.head)(p._1.tail)(m._1.tail),K(G,G)),x._2._2._2)));g()})())}return U(st("Return",void 0),ct)};if(c.length===1&&c[0].style==="RunText")return ai({owner:oo("NodeText",o),text:c[0].text,spec:{x:a,y:s,content:c[0].text,font:i,color:r.text,align:eo,baseline:Nn},bounds:w,plan:t});const l=mu(f=>to(f.style==="RunCode"||f.style==="RunCodeHighlight"?{...i,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:i)(f.text))(c);return U(l._1,(()=>{if(l._2.tag==="CatNil")return Z("CatCons",f=>_(a-Vi(f)/2)(c)(f),K(G,G));if(l._2.tag==="CatCons")return Z("CatCons",l._2._1,K(l._2._2._1,pt("Cons",Z("CatCons",f=>_(a-Vi(f)/2)(c)(f),K(G,G)),l._2._2._2)));g()})())},Hk=t=>e=>{const n=mu(r=>to(r.style==="RunCode"||r.style==="RunCodeHighlight"?{...t,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:t)(r.text))(hr(e));return U(n._1,(()=>{if(n._2.tag==="CatNil")return Z("CatCons",r=>U(st("Return",Vi(r)),ct),K(G,G));if(n._2.tag==="CatCons")return Z("CatCons",n._2._1,K(n._2._2._1,pt("Cons",Z("CatCons",r=>U(st("Return",Vi(r)),ct),K(G,G)),n._2._2._2)));g()})())},tp=t=>e=>n=>r=>{const o=or(r===""?t:r),i=n.size*1.2,a=(e.shape==="Cylinder"?(e.y+(e.y+e.h+5-2*vn(e.h*.075)(e.w*.075)))/2:(e.y+e.y+e.h)/2)-nt(o.length)*i/2+i/2,s=mu(Hk(n))(o),u=c=>U(st("Return",Wt(_=>l=>({line:Xr(l),runs:hr(l),left:_>=0&&_<c.length?e.x+e.w/2-c[_]/2:e.x+e.w/2-0,y:a+nt(_)*i}))(o)),ct);return U(s._1,(()=>{if(s._2.tag==="CatNil")return Z("CatCons",u,K(G,G));if(s._2.tag==="CatCons")return Z("CatCons",s._2._1,K(s._2._2._1,pt("Cons",Z("CatCons",u,K(G,G)),s._2._2._2)));g()})())},$k=t=>e=>n=>{const r=mu(o=>to(o.style==="RunCode"||o.style==="RunCodeHighlight"?{...t,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:t)(o.text))(Yh(e)(n));return U(r._1,(()=>{if(r._2.tag==="CatNil")return Z("CatCons",o=>U(st("Return",Vi(o)),ct),K(G,G));if(r._2.tag==="CatCons")return Z("CatCons",r._2._1,K(r._2._2._1,pt("Cons",Z("CatCons",o=>U(st("Return",Vi(o)),ct),K(G,G)),r._2._2._2)));g()})())},ep=t=>{const e=n=>{if(n.tag==="Leaf")return Q;if(n.tag==="Node")return ee("Node",n._1,n._2,n._3,s_({x:t.vx,y:t.vy,w:t.vw,h:t.vh})(n._4),e(n._5),e(n._6));g()};return e},Yk=t=>e=>n=>Hn(e)(on(t)(n)),np=t=>e=>n=>t>e?[]:[...Y(Yk(t)(e))(n),(t+e)/2],Vk=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=gi(r);return i=>a=>s=>u=>c=>_=>{const l=gn(_).length,f=nt(l+1|0),d=p=>{const x=(s*f-nt(p))/1.5,y=x<0?0:x>1?1:x;return y*y*(3-2*y)},h=(p=>{let x=p,y=!0,T;for(;y;){const v=x;if(v>=l){y=!1,T=v;continue}if(d(v)>=1){x=v+1|0;continue}y=!1,T=v}return T})(0),m=h>=l?[]:Jr(p=>d(p)>0)(Ut(h,l-1|0)).init;return n.bind((()=>{const p=t.drawText({x:u,y:c,content:Fe(h)(_),font:i,color:a,align:vo,baseline:Nn});return h>0?p:r.pure()})())(()=>o(p=>n.bind(t.measureText(i)(Fe(p)(_)))(x=>{const y=d(p);return t.drawText({x:u+x,y:c-(1-y)*10,content:Fe(1)(Si(dr(Fe(p)(_)))(_)),font:i,color:{...a,a:he(Kn(y*nt(a.a)))},align:vo,baseline:Nn})}))(m))}},rp=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=gi(r),i=Vk(t);return a=>{const s={...a.spec,content:xC(a.spec.content)};if(a.plan.tag==="PlainText")return t.drawText(s);if(a.plan.tag==="RoundedText")return n.bind((()=>{const u=r.pure();if(a.bounds.tag==="Nothing")return u;if(a.bounds.tag==="Just")return t.drawRoundedRect(a.bounds._1)(a.plan._1.radius)(a.plan._1.fill)(a.plan._1.stroke);g()})())(()=>t.drawText(s));if(a.plan.tag==="TokenTravelText"){const u=a.plan._1;return n.bind(o(c=>t.fillPath(Ph(c)(1.5))(u.trailFill))(u.trail))(()=>n.bind((()=>{const c=r.pure();if(a.bounds.tag==="Nothing")return c;if(a.bounds.tag==="Just")return t.drawRoundedRect(a.bounds._1)(u.radius)(N("Just",u.fill))(w);g()})())(()=>i(s.font)(s.color)(u.reveal)(u.textLeft)(s.y)(Xr(a.text))))}if(a.plan.tag==="TokenFillingText"){const u=a.plan._1;return n.bind(t.drawRoundedRect(u.shadow)(u.radius)(N("Just",u.shadowFill))(w))(()=>n.bind((()=>{const c=r.pure();if(a.bounds.tag==="Nothing")return c;if(a.bounds.tag==="Just")return t.drawRoundedRect(a.bounds._1)(u.radius)(N("Just",u.fill))(N("Just",u.stroke));g()})())(()=>n.bind(t.strokePath(u.leader)(u.stroke))(()=>t.drawText(s))))}if(a.plan.tag==="AffineText")return t.drawTextAffine(a.plan._1)(s);g()}},Xk=t=>e=>n=>r=>o=>i=>a=>Xh(r)(o)(i)({owner:oo("TokenText",t),text:n.line,spec:{x:o.x,y:o.y,content:n.line,font:{family:e.fontFamily,size:11,weight:500},color:e.chipPillText,align:vo,baseline:Nn},bounds:N("Just",r),plan:ri("TokenTravelText",{trail:Sk(r)(a),trailFill:{color:e.trailDot,flat:!0},radius:3,fill:{color:e.chipPillFill,flat:!0},textLeft:r.x+14,reveal:(()=>{const s=n.phaseInLabel/.45;return s<0?0:s>1?1:s})()})}),yu=t=>e=>n=>r=>{const o=Y(d=>nt(ci(1)(gn(d).length)))(r),i=on(1)(J(_r)(0)(o)),a=Ia(e)(n)(t),s=a*i,u=ci(1)(r.length),c=(d=>h=>m=>{let p=d,x=h,y=m,T=!0,v;for(;T;){const b=p,C=x,S=Pt(P=>w,P=>F=>N("Just",{head:P,tail:F}),y);if(S.tag==="Nothing"){T=!1,v=ci(0)(u-1|0);continue}if(S.tag==="Just"){if(C+S._1.head>=s){T=!1,v=b;continue}p=b+1|0,x=C+S._1.head,y=S._1.tail;continue}g()}return v})(0)(0)(o),_=J(_r)(0)(c<1?[]:At(0,c,o)),l=_/i;if(c>=0&&c<o.length){const d=(_+o[c])/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(d<=l)return 1;const h=(a-l)/(d-l);return h<0?0:h>1?1:h})()}}const f=(_+1)/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(f<=l)return 1;const d=(a-l)/(f-l);return d<0?0:d>1?1:d})()}},op=t=>e=>n=>r=>o=>t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(yu(r)(0)(0)(Y(ea)(o)).line))(i=>{const a=i+28;return t.Applicative0().pure({x:n.x+n.w/2-a/2,y:n.y-25.2-14,w:a,h:25.2})}),Uk=t=>{const e=t.Bind1(),n=t.Applicative0(),r=_o.traverse(n);return o=>i=>a=>e.Apply0().Functor0().map(s=>Oh(wt(u=>u)(s)))(r(s=>{if(s._2.tag==="Filling"&&s._2._1.labels.length!==0){const u=_e(s._2._1.node)(i);if(u.tag==="Just")return e.bind(op(t)(o)(u._1)(s._2._1.progress)(s._2._1.labels))(c=>n.pure(N("Just",L(s._1,c))));if(u.tag==="Nothing")return n.pure(w);g()}return n.pure(w)})(Ze(a.tokens)))},Kk=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const c=f_(n)(r)(o)(i)(a)(s);return t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(yu(i)(a)(s)(Et(u)(h_)).line))(_=>t.Applicative0().pure({x:c.x+14+_/2-_/2-14,y:c.y-6-8-6.6-6,w:_+28,h:25.2}))},Zk=t=>{const e=t.Bind1(),n=t.Applicative0(),r=_o.traverse(n);return o=>i=>a=>s=>e.Apply0().Functor0().map(u=>Oh(wt(c=>c)(u)))(r(u=>{if(u._2.tag==="Travelling"&&u._2._1.labels.length!==0){const c=_e(u._2._1.target)(i),_=_e(u._2._1.source)(i),l=pr(u._2._1.edge)(a);if(l.tag==="Just"&&_.tag==="Just"&&c.tag==="Just"){const f=(()=>{if(u._2._1.direction==="Forward")return l._1;if(u._2._1.direction==="Backward")return re(l._1);g()})(),d=f_(f)(_._1)(c._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost);return e.bind(Kk(t)(o)(f)(_._1)(c._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost)(u._2._1.labels))(h=>n.pure(N("Just",L(u._1,{id:u._1,rect:h,token:d}))))}}return n.pure(w)})(Ze(s.tokens)))},y_=t=>e=>n=>{const r=(e*nt(t+1|0)-nt(n))/1.5,o=r<0?0:r>1?1:r;return o*o*(3-2*o)},Xi=t=>e=>n=>{const r=$k(t)(n)(e.runs);return U(r._1,(()=>{if(r._2.tag==="CatNil")return Z("CatCons",o=>U(st("Return",e.left+o),ct),K(G,G));if(r._2.tag==="CatCons")return Z("CatCons",r._2._1,K(r._2._2._1,pt("Cons",Z("CatCons",o=>U(st("Return",e.left+o),ct),K(G,G)),r._2._2._2)));g()})())},jk=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const c=u<0?0:u>1?1:u,_=on(8)(i.size*.9),l=(m,p,x,y,T)=>{const v=Ae({path:[],role:_n,layer:w,effects:[me("GroupAlpha",m)]})(Uh(t)(e)(1)(n)(r)(T==="RunCode"||T==="RunCodeHighlight"?{...i,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:i)(T)(p)(x)(fr(y)));return m>.001?v:U(st("Return",void 0),ct)},f=(m,p)=>{const x=gn(m.line).length;return y_(x)(c)((x-p|0)-1|0)},d=tp(r)(o)(i)(a),h=m=>{const p=tp(r)(o)(i)(s),x=y=>$n(T=>{const v=T>=0&&T<m.length?N("Just",m[T]):w,b=T>=0&&T<y.length?N("Just",y[T]):w;return $n(C=>{if(C.tag==="DiffKeep"){if(v.tag==="Just"){if(b.tag==="Just"){const S=b._1,P=v._1,F=Xi(i)(P)(C._1),W=E=>{const R=Xi(i)(S)(C._2),et=rt=>l(1,E+(rt-E)*c,P.y+(S.y-P.y)*c,C._3,(()=>{if(c<.5){const X=Et(P.runs)(V=>Io(gn(V.text).length,V.style));return C._1>=0&&C._1<X.length?X[C._1]:Vr}const $=Et(S.runs)(X=>Io(gn(X.text).length,X.style));return C._2>=0&&C._2<$.length?$[C._2]:Vr})());return U(R._1,(()=>{if(R._2.tag==="CatNil")return Z("CatCons",et,K(G,G));if(R._2.tag==="CatCons")return Z("CatCons",R._2._1,K(R._2._2._1,pt("Cons",Z("CatCons",et,K(G,G)),R._2._2._2)));g()})())};return U(F._1,(()=>{if(F._2.tag==="CatNil")return Z("CatCons",W,K(G,G));if(F._2.tag==="CatCons")return Z("CatCons",F._2._1,K(F._2._2._1,pt("Cons",Z("CatCons",W,K(G,G)),F._2._2._2)));g()})())}if(b.tag==="Nothing"){const S=v._1,P=Xi(i)(S)(C._1),F=W=>{const E=f(S,C._1);return l(1-E,W,S.y-_*E,C._3,(()=>{const R=Et(S.runs)(et=>Io(gn(et.text).length,et.style));return C._1>=0&&C._1<R.length?R[C._1]:Vr})())};return U(P._1,(()=>{if(P._2.tag==="CatNil")return Z("CatCons",F,K(G,G));if(P._2.tag==="CatCons")return Z("CatCons",P._2._1,K(P._2._2._1,pt("Cons",Z("CatCons",F,K(G,G)),P._2._2._2)));g()})())}g()}if(v.tag==="Nothing"){if(b.tag==="Just"){const S=b._1,P=Xi(i)(S)(C._2),F=W=>{const E=y_(gn(S.line).length)(c)(C._2);return l(E,W,S.y-_*(1-E),C._3,(()=>{const R=Et(S.runs)(et=>Io(gn(et.text).length,et.style));return C._2>=0&&C._2<R.length?R[C._2]:Vr})())};return U(P._1,(()=>{if(P._2.tag==="CatNil")return Z("CatCons",F,K(G,G));if(P._2.tag==="CatCons")return Z("CatCons",P._2._1,K(P._2._2._1,pt("Cons",Z("CatCons",F,K(G,G)),P._2._2._2)));g()})())}if(b.tag==="Nothing")return U(st("Return",void 0),ct)}g()}if(C.tag==="DiffDelete"){if(v.tag==="Just"){const S=v._1,P=Xi(i)(S)(C._1),F=W=>{const E=f(S,C._1);return l(1-E,W,S.y-_*E,C._2,(()=>{const R=Et(S.runs)(et=>Io(gn(et.text).length,et.style));return C._1>=0&&C._1<R.length?R[C._1]:Vr})())};return U(P._1,(()=>{if(P._2.tag==="CatNil")return Z("CatCons",F,K(G,G));if(P._2.tag==="CatCons")return Z("CatCons",P._2._1,K(P._2._2._1,pt("Cons",Z("CatCons",F,K(G,G)),P._2._2._2)));g()})())}if(v.tag==="Nothing")return U(st("Return",void 0),ct);g()}if(C.tag==="DiffInsert"){if(b.tag==="Just"){const S=b._1,P=Xi(i)(S)(C._1),F=W=>{const E=y_(gn(S.line).length)(c)(C._1);return l(E,W,S.y-_*(1-E),C._2,(()=>{const R=Et(S.runs)(et=>Io(gn(et.text).length,et.style));return C._1>=0&&C._1<R.length?R[C._1]:Vr})())};return U(P._1,(()=>{if(P._2.tag==="CatNil")return Z("CatCons",F,K(G,G));if(P._2.tag==="CatCons")return Z("CatCons",P._2._1,K(P._2._2._1,pt("Cons",Z("CatCons",F,K(G,G)),P._2._2._2)));g()})())}if(b.tag==="Nothing")return U(st("Return",void 0),ct)}g()})(Wk((()=>{if(v.tag==="Nothing")return"";if(v.tag==="Just")return v._1.line;g()})())((()=>{if(b.tag==="Nothing")return"";if(b.tag==="Just")return b._1.line;g()})()))})(Ut(0,ci(m.length)(y.length)-1|0));return U(p._1,(()=>{if(p._2.tag==="CatNil")return Z("CatCons",x,K(G,G));if(p._2.tag==="CatCons")return Z("CatCons",p._2._1,K(p._2._2._1,pt("Cons",Z("CatCons",x,K(G,G)),p._2._2._2)));g()})())};return U(d._1,(()=>{if(d._2.tag==="CatNil")return Z("CatCons",h,K(G,G));if(d._2.tag==="CatCons")return Z("CatCons",d._2._1,K(d._2._2._1,pt("Cons",Z("CatCons",h,K(G,G)),d._2._2._2)));g()})())},x_=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const c=ni(s),_=s.tag==="PloppingOut"&&n.wobble?{alpha:1,scale:1}:c,l=or((()=>{if(u.tag==="Just"){if(u._1.tag==="StaticNodeLabel")return u._1._1===""?i:u._1._1;if(u._1.tag==="RelabelingNode"){const y=u._1._1.progress<.5?u._1._1.oldLabel:u._1._1.newLabel;return y===""?i:y}g()}if(u.tag==="Nothing")return a.label===""?i:a.label;g()})()),f={family:n.fontFamily,size:n.wobble?15:11,weight:n.wobble?800:500},d=f.size*1.2,h=(a.shape==="Cylinder"?(a.y+(a.y+a.h+5-2*vn(a.h*.075)(a.w*.075)))/2:(a.y+a.y+a.h)/2)-nt(l.length)*d/2+d/2,m=(y,T)=>{const v=Ae({path:[],role:_n,layer:w,effects:[me("GroupAlpha",y)]})($n(b=>m_(t)(e)(1)(n)(i)(f)(a.x+a.w/2)(h+nt(b._1)*d)(b._2))(Wt(bn)(or(T))));return y>.001?v:U(st("Return",void 0),ct)},p=(y,T)=>$n(v=>m_(t)(e)(y)(n)(i)(f)(a.x+a.w/2)(h+nt(v._1)*d)(v._2))(Wt(bn)(or(T))),x=Ae({path:[],role:_n,layer:w,effects:[me("GroupAlpha",_.alpha*r),me("GroupTransform",ii,{tx:(a.x+a.w/2)*(1-_.scale),ty:(a.y+a.h/2)*(1-_.scale),sx:_.scale,sy:_.scale}),me("GroupAlpha",o)]})((()=>{if(u.tag==="Just"&&u._1.tag==="RelabelingNode"&&Xr(u._1._1.oldLabel)===Xr(u._1._1.newLabel)&&!ne(y=>ne(T=>T.style==="RunHighlight"||T.style==="RunCodeHighlight",hr(y)),or(u._1._1.oldLabel))&&ne(y=>ne(T=>T.style==="RunHighlight"||T.style==="RunCodeHighlight",hr(y)),or(u._1._1.newLabel)))return p(u._1._1.progress<0?0:u._1._1.progress>1?1:u._1._1.progress,u._1._1.newLabel);if(u.tag==="Just"&&u._1.tag==="RelabelingNode"&&Xr(u._1._1.oldLabel)===Xr(u._1._1.newLabel)&&ne(y=>ne(T=>T.style==="RunHighlight"||T.style==="RunCodeHighlight",hr(y)),or(u._1._1.oldLabel))&&!ne(y=>ne(T=>T.style==="RunHighlight"||T.style==="RunCodeHighlight",hr(y)),or(u._1._1.newLabel)))return p(u._1._1.progress<0?1:u._1._1.progress>1?0:1-u._1._1.progress,u._1._1.oldLabel);if(u.tag==="Just"&&u._1.tag==="RelabelingNode"){if(Xr(u._1._1.oldLabel)===Xr(u._1._1.newLabel)){const y=u._1._1,T=m(y.progress<0?1:y.progress>1?0:1-y.progress,y.oldLabel),v=()=>m(y.progress<0?0:y.progress>1?1:y.progress,y.newLabel);return U(T._1,(()=>{if(T._2.tag==="CatNil")return Z("CatCons",v,K(G,G));if(T._2.tag==="CatCons")return Z("CatCons",T._2._1,K(T._2._2._1,pt("Cons",Z("CatCons",v,K(G,G)),T._2._2._2)));g()})())}return jk(t)(e)(n)(i)(a)(f)(u._1._1.oldLabel)(u._1._1.newLabel)(u._1._1.progress)}return $n(y=>m_(t)(e)(1)(n)(i)(f)(a.x+a.w/2)(h+nt(y._1)*d)(y._2))(Wt(bn)(l))})());return o>0&&_.alpha*r>0?x:U(st("Return",void 0),ct)},ip=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>_=>l=>f=>{const d=fu({id:c,role:t,geometry:su("FlatNode",{shape:_.shape,bounds:{x:_.x,y:_.y,w:_.w,h:_.h}}),alpha:i,plan:uu("FlatNodePlan",{palette:o,label:(()=>{if(f.tag==="Just"){if(f._1.tag==="StaticNodeLabel")return f._1._1===""?c:f._1._1;if(f._1.tag==="RelabelingNode"){const m=f._1._1.progress<.5?f._1._1.oldLabel:f._1._1.newLabel;return m===""?c:m}g()}if(f.tag==="Nothing")return _.label===""?c:_.label;g()})(),labelVisibility:n,inkBoost:r,labelAlpha:s,outlineAlpha:a,arrival:u,animState:l})}),h=()=>{if(n==="LabelsHidden")return U(st("Return",void 0),ct);if(n==="LabelsShown")return x_(gu)(e)(o)(i)(s)(c)(_)(l)(f);g()};return U(d._1,(()=>{if(d._2.tag==="CatNil")return Z("CatCons",h,K(G,G));if(d._2.tag==="CatCons")return Z("CatCons",d._2._1,K(d._2._2._1,pt("Cons",Z("CatCons",h,K(G,G)),d._2._2._2)));g()})())},ap=t=>e=>n=>{const r={...t,nodeFill:t.text,text:t.nodeFill,nodeStroke:t.nodeFill};return $n(o=>{const i=_e(o._1)(n.nodes),a=_e(o._1)(e.nodes),s=a.tag==="Just"&&i.tag==="Just"?Ae({path:[],role:_n,layer:w,effects:[me("GroupAlpha",o._2)]})(ip(E3)(n.animationTime)(e_)(1)(r)(1)(w)(1)(w)(o._1)((()=>{const u=_e(o._1)(n.nodeLabels);if(u.tag==="Nothing")return a._1;if(u.tag==="Just"){if(u._1.tag==="StaticNodeLabel")return{...a._1,label:u._1._1===""?o._1:u._1._1};if(u._1.tag==="RelabelingNode")return{...a._1,label:(()=>{const c=u._1._1.progress<.5?u._1._1.oldLabel:u._1._1.newLabel;return c===""?o._1:c})()}}g()})())(i._1)(_e(o._1)(n.nodeLabels))):U(st("Return",void 0),ct);return o._2>0?s:U(st("Return",void 0),ct)})(Ze(n.nodeInvert))},sp=t=>e=>n=>{const r=_a(6)(.55)(g_(0)(1)((1-t)/.06)),o=t>.94,i=o&&n>1e-4,a=_a(6)(.55)(g_(0)(1)(t/.06)),s=t<.06,u=s&&e>1e-4,c=o&&n<=1e-4;return{popScale:u?a:i?r:1,flipY:s&&e<=1e-4?a:c?r:1,fadeAlpha:(()=>{if(u){const _=t/.06;return _<0?.55:_>1?1:.55+.44999999999999996*_}if(i){const _=(1-t)/.06;return _<0?.55:_>1?1:.55+.44999999999999996*_}return 1})()}},t5=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>o=>{const i=o.length-1|0,a=i<1?[]:At(0,i,o),s=a.length-1|0,u=s>=0&&s<a.length?N("Just",a[s]):w,c=o.length-1|0,_=c>=0&&c<o.length?N("Just",o[c]):w;if(_.tag==="Just"&&u.tag==="Just"){const l=Ie(.78)(1.18)(Ba(o)+19|0),f=Ie(.4)(.62)(l.prng),d=r.wobble?8.75*f.value:4.375,h=Ie(.4)(.62)(f.prng),m=r.wobble?8.75*h.value:4.375,p=_._1.y-u._1.y,x=_._1.x-u._1.x,y=nn(x*x+p*p),T=p/y,v=-T,b=x/y,C=_._1.x+b*.875,S=_._1.y+T*.875,P=r.wobble?8.75*l.value:8.75,F=C-b*P,W=S-T*P,E=F+v*d,R=W+b*d,et=[1,C,S,2,F+v*4.375,W+b*4.375,2,F-v*4.375,W-b*4.375,5],rt=F-v*m,$=W-b*m,X={color:r.arrowFill,width:2,lineJoin:Ve,lineCap:ir};return y<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,E,R,2,C,S])(X))(()=>t.strokePath([1,rt,$,2,C,S])(X)):t.fillPath(et)({color:r.arrowFill,flat:!0})}return n.pure()}},e5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=gi(n),i=t.popAlpha,a=t5(t);return s=>u=>c=>_=>l=>{const f=Q3(8)(_),d=c&&l.hi>=.9&&(1-l.hi)*_s(f)<=8.75?1:l.hi;if(d<=l.lo)return n.pure();const h=Y3(f)(l.lo)(d);if(h.length===0)return n.pure();const m={color:s.edge,width:s.wobble?2:.9375,lineJoin:Ve,lineCap:ir},p=s.wobble?Ie(-10)(4)(Ba(h)).value:0,x=s.wobble?gk(p)(h):h;return r.bind(s.wobble?o(y=>r.bind(t.pushAlpha(y.alpha))(()=>r.bind(t.strokePath(y.path)(m))(()=>i)))((()=>{const y=Ba(h);return x.length<2?[]:Yi(Dk)(y)(!1)(x)})()):t.strokePath(F3(h))(m))(()=>{const y=a(s)(x);return u&&d>=.999?y:n.pure()})}},n5=t=>{const e=e5(t);return n=>n.geometry.tag==="FlatRoute"&&n.plan.tag==="FlatEdgePlan"?e(n.plan._1)(n.arrow)(n.settlingAtTarget)(n.geometry._1)(n.visible):t.Monad0().Applicative0().pure()},r5=t=>e=>{const n=i=>{const a=_e(i)(t.nodes);if(a.tag==="Nothing")return!1;if(a.tag==="Just"){const s=a._1;return!ne(u=>0<u._2.length&&u._2[0].x>=s.x&&u._2[0].x<=s.x+s.w&&u._2[0].y>=s.y&&u._2[0].y<=s.y+s.h,Ze(t.edges))}g()},r=J(i=>a=>(i*31|0)+xo(a)|0)(5381)(zn(e.frameTitle)),o=i=>{const a=_e(i)(t.nodes);if(a.tag==="Nothing")return!1;if(a.tag==="Just"){const s=a._1;return!ne(u=>{const c=u._2.length-1|0;return c>=0&&c<u._2.length&&u._2[c].x>=s.x&&u._2[c].x<=s.x+s.w&&u._2[c].y>=s.y&&u._2[c].y<=s.y+s.h},Ze(t.edges))}g()};return J(i=>a=>{const s=a._2;return wk(u=>{if(u.tag==="Nothing")return N("Just",s);if(u.tag==="Just")return N("Just",{t:on(u._1.t)(s.t),angle:s.t>=u._1.t?s.angle:u._1.angle,bigCircle:u._1.bigCircle||s.bigCircle,frameHash:u._1.frameHash});g()})(a._1)(i)})(Q)(Et(Ze(e.tokens))(i=>{if(i._2.tag==="Filling"){const a=i._2._1.node;return[L(a,{t:1,angle:(()=>{const s=wt(u=>(()=>{const c=_e(a)(t.nodes),_=u._2.length-1|0;return _>=0&&_<u._2.length&&c.tag==="Just"&&u._2[_].x>=c._1.x&&u._2[_].x<=c._1.x+c._1.w&&u._2[_].y>=c._1.y&&u._2[_].y<=c._1.y+c._1.h})()?N("Just",u._2):w)(Ze(t.edges));if(0<s.length){const u=s[0].length-1|0,c=u<1?[]:At(0,u,s[0]),_=c.length-1|0;if(_>=0&&_<c.length){const l=s[0].length-1|0;return l>=0&&l<s[0].length?Bo(s[0][l].y-c[_].y)(s[0][l].x-c[_].x):0}s[0].length-1|0}return 0})(),bigCircle:n(a)||o(a),frameHash:r})]}if(i._2.tag==="Travelling"){if(i._2._1.progress>=.75)return[L(i._2._1.target,{t:(i._2._1.progress-.75)/.25,angle:(()=>{const a=pr(i._2._1.edge)(t.edges);if(a.tag==="Just"){const s=a._1.length-1|0,u=s<1?[]:At(0,s,a._1),c=u.length-1|0;if(c>=0&&c<u.length){const _=a._1.length-1|0;return _>=0&&_<a._1.length?Bo(a._1[_].y-u[c].y)(a._1[_].x-u[c].x):0}return a._1.length-1|0,0}if(a.tag==="Nothing")return 0;g()})(),bigCircle:n(i._2._1.target)||o(i._2._1.target),frameHash:r})];if(i._2._1.progress<.25)return[L(i._2._1.source,{t:i._2._1.progress/.25,angle:(()=>{const a=pr(i._2._1.edge)(t.edges);if(a.tag==="Just")return 1<a._1.length&&0<a._1.length?Bo(a._1[1].y-a._1[0].y)(a._1[1].x-a._1[0].x):0;if(a.tag==="Nothing")return 0;g()})(),bigCircle:n(i._2._1.source)||o(i._2._1.source),frameHash:r})]}return[]}))},o5=t=>J(e=>n=>(e*31|0)+xo(n)|0)(5381)(zn(t.frameTitle)),up=t=>e=>n=>r=>o=>i=>{const a=o5(i),s=r5(o)(i);return $n(u=>{const c=_e(u._1)(i.nodes);if(c.tag==="Just")return ip(Nh)(i.animationTime)(e)(n)(r)((()=>{const _=_e(u._1)(i.nodeFadeAlpha);if(_.tag==="Nothing")return 1;if(_.tag==="Just")return _._1;g()})())(t(u._1))((()=>{const _=_e(u._1)(i.nodeLabelFadeAlpha);if(_.tag==="Nothing")return 1;if(_.tag==="Just")return _._1;g()})())((()=>{const _=_e(u._1)(s);return _.tag==="Just"?N("Just",_._1):_.tag==="Nothing"&&Tk(u._1)(i.visited)?N("Just",{t:1,angle:0,bigCircle:!1,frameHash:a}):w})())(u._1)((()=>{const _=_e(u._1)(i.nodeLabels);if(_.tag==="Nothing")return u._2;if(_.tag==="Just"){if(_._1.tag==="StaticNodeLabel")return{...u._2,label:_._1._1===""?u._1:_._1._1};if(_._1.tag==="RelabelingNode")return{...u._2,label:(()=>{const l=_._1._1.progress<.5?_._1._1.oldLabel:_._1._1.newLabel;return l===""?u._1:l})()}}g()})())(c._1)(_e(u._1)(i.nodeLabels));if(c.tag==="Nothing")return U(st("Return",void 0),ct);g()})(Ze(o.nodes))},cp=t=>e=>n=>r=>o=>i=>{const a=o.x+o.w/2<=i.x+i.w/2,s=a?jr:Zr,u=a?Zr:jr,c=on(o.y)(i.y),_=Hn(o.y+o.h)(i.y+i.h);return te(jh(t)(e)(n))(wt(l=>{if(c>_)return w;const f=Ye(i.shape)({x:i.x,y:i.y,w:i.w,h:i.h})(u)(l),d=Ye(o.shape)({x:o.x,y:o.y,w:o.w,h:o.h})(s)(l);return(a?f>=d+1e-6:d>=f+1e-6)?N("Just",[{x:d,y:l},{x:f,y:l}]):w})(np(c)(_)(wt(l=>l)([(()=>{if(0<r.length){const l=r.length-1|0;if(l>=0&&l<r.length){const f=r[l];if((()=>{const d=r[0].y-f.y;return d<0?-d<=1e-6:d<=1e-6})())return N("Just",(r[0].y+f.y)/2)}}return w})(),N("Just",i.y+i.h/2),N("Just",o.y+o.h/2)]))))},gp=t=>e=>n=>r=>o=>i=>{const a=o.y+o.h/2<=i.y+i.h/2,s=a?Kr:Ur,u=a?Ur:Kr,c=on(o.x)(i.x),_=Hn(o.x+o.w)(i.x+i.w);return te(jh(t)(e)(n))(wt(l=>{if(c>_)return w;const f=Ye(i.shape)({x:i.x,y:i.y,w:i.w,h:i.h})(u)(l),d=Ye(o.shape)({x:o.x,y:o.y,w:o.w,h:o.h})(s)(l);return(a?f>=d+1e-6:d>=f+1e-6)?N("Just",[{x:l,y:d},{x:l,y:f}]):w})(np(c)(_)(wt(l=>l)([(()=>{if(0<r.length){const l=r.length-1|0;if(l>=0&&l<r.length){const f=r[l];if((()=>{const d=r[0].x-f.x;return d<0?-d<=1e-6:d<=1e-6})())return N("Just",(r[0].x+f.x)/2)}}return w})(),N("Just",i.x+i.w/2),N("Just",o.x+o.w/2)]))))},i5=t=>e=>n=>r=>{const o=_e(e)(t);if(o.tag==="Just"){const i=_e(n)(t);if(i.tag==="Just"){if((()=>{const u=i._1.y+i._1.h/2-(o._1.y+o._1.h/2),c=i._1.x+i._1.w/2-(o._1.x+o._1.w/2);return(u<0?-u:u)>=(c<0?-c:c)})()){const u=gp(t)(e)(n)(r)(o._1)(i._1),c=cp(t)(e)(n)(r)(o._1)(i._1);if(u.tag==="Just")return N("Just",u._1);if(u.tag==="Nothing")return c;g()}const a=cp(t)(e)(n)(r)(o._1)(i._1),s=gp(t)(e)(n)(r)(o._1)(i._1);if(a.tag==="Just")return N("Just",a._1);if(a.tag==="Nothing")return s;g()}if(i.tag==="Nothing")return w;g()}if(o.tag==="Nothing")return w;g()},Ui=t=>e=>n=>{const r=Jk(t);return Oe(A.compare,Qe,Nk(wt(o=>{const i=pr(o._1)(t.edges);if(i.tag==="Just"){const a=i5(n)(o._2.source)(o._2.target)(i._1);return a.tag==="Just"?N("Just",L(o._1,a._1)):w}if(i.tag==="Nothing")return w;g()})(Ze(e))),(()=>{const o=i=>{if(i.tag==="Leaf")return Q;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(t.edges)})())},_p=t=>e=>n=>$n((()=>{const r=Ui(e)(n.edgeEndpoints)(e.nodes);return o=>{const i=pr(o._1)(n.edges);if(i.tag==="Just"){const a=pr(o._1)(n.edgeFadeAlpha),s=(()=>{if(a.tag==="Nothing")return 1;if(a.tag==="Just")return a._1;g()})(),u=Ch({id:o._1,geometry:fh("FlatRoute",(()=>{const c=pr(o._1)(r);if(c.tag==="Nothing")return o._2;if(c.tag==="Just")return c._1;g()})()),visible:p3(i._1),arrow:(()=>{const c=Zn("conn:")(o._1);if(c.tag==="Just")return!1;if(c.tag==="Nothing")return!0;g()})(),settlingAtTarget:i._1.tag==="Extending"&&i._1._1==="ExtendFromSource",plan:dh("FlatEdgePlan",t)});return s===1?u:Ae({path:[],role:_n,layer:w,effects:[me("GroupAlpha",s)]})(u)}if(i.tag==="Nothing")return U(st("Return",void 0),ct);g()}})())(Ze(e.edges)),xu=t=>e=>n=>r=>{const o=e.nodes,i=Ui(e)(n.edgeEndpoints)(e.nodes);return Ae({path:[],role:_n,layer:N("Just",Fb),effects:[]})($n(a=>{if(a._2.tag==="Travelling"){if(a._2._1.labels.length!==0){const s=_e(a._2._1.target)(o),u=_e(a._2._1.source)(o),c=pr(a._2._1.edge)(i),_=Wh(a._1)(r);if(_.tag==="Just"&&c.tag==="Just"&&u.tag==="Just"&&s.tag==="Just")return Xk(a._1)(t)(yu(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(Et(a._2._1.labels)(h_)))(_._1)({x:_._1.x+_._1.w/2,y:_._1.y+_._1.h/2})(sp(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost))(f_((()=>{if(a._2._1.direction==="Forward")return c._1;if(a._2._1.direction==="Backward")return re(c._1);g()})())(u._1)(s._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost))}return U(st("Return",void 0),ct)}if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const s=_e(a._2._1.node)(o);if(s.tag==="Just"){const u=s._1,c=op(Mg)(vh)(u)(a._2._1.progress)(a._2._1.labels),_=l=>Rk(a._1)(t)(yu(a._2._1.progress)(0)(0)(Et(a._2._1.labels)(h_)).line)(u)(l)({x:l.x+l.w/2,y:l.y+l.h/2})(sp(a._2._1.progress)(0)(0));return U(c._1,(()=>{if(c._2.tag==="CatNil")return Z("CatCons",_,K(G,G));if(c._2.tag==="CatCons")return Z("CatCons",c._2._1,K(c._2._2._1,pt("Cons",Z("CatCons",_,K(G,G)),c._2._2._2)));g()})())}if(s.tag==="Nothing")return U(st("Return",void 0),ct);g()}return U(st("Return",void 0),ct)})(Ze(n.tokens)))},fp=t=>e=>n=>r=>{if(e.tokenInsideBlend==="Difference"){const o=n.nodes,i=Ui(n)(r.edgeEndpoints)(n.nodes),a=G3(t),s=u=>{const c=Ae({path:[],role:_n,layer:N("Just",Rb),effects:[me("GroupBlend",iu),me("GroupClip",l_(o)(r),Jo)]})(p_(wh)(u==="ConvexAbsorb"?vk:__)(e.wobble)(o)(i)(r)(e.tokenInside)(e.tokenInsideStroke)),_=()=>Ae({path:[],role:_n,layer:N("Just",Db),effects:[]})($n(l=>{const f=_e(l._1)(r.nodes);return f.tag==="Just"&&ni(f._1).alpha>0?io(ro("FloorOverlay",{path:Co(l._2),fill:N("Just",{color:ve,flat:!1}),stroke:w})):U(st("Return",void 0),ct)})(Ze(o)));return U(c._1,(()=>{if(c._2.tag==="CatNil")return Z("CatCons",_,K(G,G));if(c._2.tag==="CatCons")return Z("CatCons",c._2._1,K(c._2._2._1,pt("Cons",Z("CatCons",_,K(G,G)),c._2._2._2)));g()})())};return U(a._1,(()=>{if(a._2.tag==="CatNil")return Z("CatCons",s,K(G,G));if(a._2.tag==="CatCons")return Z("CatCons",a._2._1,K(a._2._2._1,pt("Cons",Z("CatCons",s,K(G,G)),a._2._2._2)));g()})())}if(e.tokenInsideBlend==="Normal")return Ae({path:[],role:_n,layer:w,effects:[me("GroupClip",l_(n.nodes)(r),Jo),me("GroupAlpha",e.tokenInsideAlpha)]})(p_(wh)(__)(e.wobble)(n.nodes)(Ui(n)(r.edgeEndpoints)(n.nodes))(r)(e.tokenInside)(e.tokenInsideStroke));g()},w_=t=>e=>n=>r=>Ae({path:[],role:_n,layer:N("Just",Ab),effects:[me("GroupClip",bk(e)(n.nodes)(r),$g)]})(p_(xh)(__)(t.wobble)(n.nodes)(Ui(n)(r.edgeEndpoints)(n.nodes))(r)(t.tokenOutsideFill)(t.tokenOutsideStroke)),T_=t=>{const e=t.Bind1(),n=Zk(t),r=Uk(t);return o=>i=>a=>s=>{const u=a.nodes;return e.bind(n(o)(u)(Ui(a)(s.edgeEndpoints)(a.nodes))(s))(c=>e.bind(r(o)(u)(s))(_=>t.Applicative0().pure(rk({x:i.vx,y:i.vy,w:i.vw,h:i.vh})([...wt(l=>{const f=_e(l._1)(s.nodes);return f.tag==="Just"&&ni(f._1).alpha>0?N("Just",{x:l._2.x,y:l._2.y,w:l._2.w,h:l._2.h}):w})(Ze(u)),...(()=>{const l=(f,d)=>{if(f.tag==="Leaf")return d;if(f.tag==="Node")return l(f._5,pt("Cons",f._4,l(f._6,d)));g()};return Ot(ue.foldr,l(_,G))})()])(wt(l=>Wh(l)(c))((()=>{const l=f=>{if(f.tag==="Leaf")return Q;if(f.tag==="Node")return ee("Node",f._1,f._2,f._3,void 0,l(f._5),l(f._6));g()};return Rt(A.compare)(Ot(pn.foldr,l(c)))})())))))}},a5=T_(Mg),dp=t=>e=>n=>r=>{const o=a5(vh)(e)(n)(r);return U(o._1,(()=>{if(o._2.tag==="CatNil")return Z("CatCons",i=>xu(t)(n)(r)(i),K(G,G));if(o._2.tag==="CatCons")return Z("CatCons",o._2._1,K(o._2._2._1,pt("Cons",Z("CatCons",i=>xu(t)(n)(r)(i),K(G,G)),o._2._2._2)));g()})())},s5=t=>e=>n=>{const r=ut.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ut.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},lp=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},hp=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},N_=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},pp=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},u5=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},v_=(()=>{const t=wn.unfoldr(gr);return e=>t(Tn("IterNode",e,ur))})(),c5=co(No)(Qt),g5=t=>e=>{const n=en(t.angle),r=hn(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},_5=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],J_=t=>e=>{const n=r=>s5(0)(255)(he(Bn(nt(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},an=t=>e=>n=>r=>({x:(e-n)*hn(t.angle),y:(e+n)*en(t.angle)-r}),C_=t=>{const e=Pt(n=>w,n=>r=>N("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,...Et(e._1.tail)(n=>[2,n.x,n.y]),5];g()},f5=t=>e=>n=>{const r=n.id,o=n.np,i=fu({id:r,role:Nh,geometry:su("IsoSlab",{south:[n.box.ground.d,n.box.ground.c,n.box.top.c,n.box.top.d],east:[n.box.ground.b,n.box.ground.c,n.box.top.c,n.box.top.b],top:[n.box.top.a,n.box.top.b,n.box.top.c,n.box.top.d]}),alpha:1,plan:uu("IsoNodePlan",{config:t,palette:e})}),a=()=>ai({owner:oo("NodeText",r),text:o.label,spec:{x:o.x+o.w/2,y:0,content:o.label,font:{family:e.fontFamily,size:11,weight:600},color:e.text,align:eo,baseline:Nn},bounds:w,plan:ri("AffineText",g5(t)(o.y+o.h))});return U(i._1,(()=>{if(i._2.tag==="CatNil")return Z("CatCons",a,K(G,G));if(i._2.tag==="CatCons")return Z("CatCons",i._2._1,K(i._2._2._1,pt("Cons",Z("CatCons",a,K(G,G)),i._2._2._2)));g()})())},d5=t=>e=>n=>r=>o=>{const i=$e(bn,o,At(1,o.length,o)),a=i.length-1|0;return Wt(s=>u=>({depth:(u._1.x+u._1.y+u._2.x+u._2.y)/2,draw:Ch({id:n,geometry:fh("IsoSegments",[[an(t)(u._1.x)(u._1.y)(0),an(t)(u._2.x)(u._2.y)(0)]]),visible:{lo:0,hi:1},arrow:r&&s===a,settlingAtTarget:!1,plan:dh("IsoEdgePlan",{config:t,palette:e})})}))(i)},l5=t=>e=>n=>r=>o=>{const i=(()=>{if(t==="Forward")return o;if(t==="Backward")return re(o);g()})();if(0<i.length){const s=Ei(i)(lp(0)(1)(Ia(n)(r)(e)));if(s.tag==="Nothing")return i[0];if(s.tag==="Just")return s._1;g()}const a=Ei(i)(lp(0)(1)(Ia(n)(r)(e)));if(a.tag==="Nothing")return{x:0,y:0};if(a.tag==="Just")return a._1;g()},h5=t=>{const e=Pt(n=>w,n=>r=>N("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,...Et(e._1.tail)(n=>[2,n.x,n.y])];g()},p5=t=>{const e=Pt(n=>w,n=>r=>N("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=>o=>({minX:hp(r.minX)(o.x),minY:hp(r.minY)(o.y),maxX:N_(r.maxX)(o.x),maxY:N_(r.maxY)(o.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()},m5=t=>{const e=t.Monad0(),n=e.Bind1();return r=>{if(r.geometry.tag==="IsoSlab"&&r.plan.tag==="IsoNodePlan"){const o=r.geometry._1,i=r.plan._1.palette,a=(s,u)=>t.fillStrokePath(C_(s))({color:u,flat:!0})({color:i.nodeStroke,width:1,lineJoin:Ve,lineCap:Pn});return n.bind(a(o.south,J_(.66)(i.nodeFill)))(()=>n.bind(a(o.east,J_(.82)(i.nodeFill)))(()=>a(o.top,i.nodeFill)))}return e.Applicative0().pure()}},y5=t=>{const e=t.Monad0(),n=e.Bind1();return r=>{if(r.geometry.tag==="IsoCube"&&r.plan.tag==="IsoTokenPlan"){const o=r.geometry._1,i=r.plan._1.palette,a=(s,u)=>t.fillStrokePath(C_(s))({color:J_(u)(i.tokenOutsideFill),flat:!0})({color:i.tokenOutsideStroke,width:1,lineJoin:Ve,lineCap:Pn});return n.bind(a(o.south,.66))(()=>n.bind(a(o.east,.82))(()=>a(o.top,1)))}return e.Applicative0().pure()}},x5={angle:.5235987755982988,boxHeight:26,transparentBg:!0},w5=t=>e=>n=>{const r=pp(t)(n.nodeLabels);if(r.tag==="Just"){if(r._1.tag==="StaticNodeLabel")return r._1._1===""?t:r._1._1;if(r._1.tag==="RelabelingNode"){const o=r._1._1.progress<.5?r._1._1.oldLabel:r._1._1.newLabel;return o===""?t:o}g()}if(r.tag==="Nothing")return e.label===""?t:e.label;g()},T5=t=>e=>n=>{const r=n.x-5.5,o=n.x+5.5,i=n.y-5.5,a=n.y+5.5,s=e+11,u=an(t)(o)(i)(s),c=an(t)(o)(a)(s),_=an(t)(r)(a)(s),l=an(t)(o)(a)(e);return{south:[an(t)(r)(a)(e),l,c,_],east:[an(t)(o)(i)(e),l,c,u],top:[an(t)(r)(i)(s),u,c,_]}},N5=t=>e=>n=>r=>{const o=r._1,i=(a,s)=>({depth:s.x+s.y,draw:bh({id:o,pass:xh,geometry:hh("IsoCube",T5(t)(a)(s)),position:s,plan:mh("IsoTokenPlan",{config:t,palette:e,baseZ:a})})});if(r._2.tag==="Travelling"){const a=u5(r._2._1.edge)(n.edges);return a.tag==="Just"?N("Just",i(0,l5(r._2._1.direction)(r._2._1.progress)(r._2._1.holdPre)(r._2._1.holdPost)(a._1))):w}if(r._2.tag==="Filling"){const a=pp(r._2._1.node)(n.nodes);if(a.tag==="Just")return N("Just",i(t.boxHeight,{x:a._1.x+a._1.w/2,y:a._1.y+a._1.h/2}))}return w},v5=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:an(t)(e.x)(e.y)(0),b:an(t)(r)(e.y)(0),c:an(t)(r)(n)(0),d:an(t)(e.x)(n)(0)},top:{a:an(t)(e.x)(e.y)(t.boxHeight),b:an(t)(r)(e.y)(t.boxHeight),c:an(t)(r)(n)(t.boxHeight),d:an(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},mp=t=>e=>Y(n=>({id:n._1,np:n._2,box:v5(t)(n._2)}))(v_(e.nodes)),J5=t=>e=>[...Et(mp(t)(e))(_5),...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,pt("Cons",r._4,n(r._6,o)));g()};return Et(Ot(ue.foldr,n(e.edges,G)))(Y(r=>an(t)(r.x)(r.y)(0)))})()],C5=t=>e=>n=>Y(r=>({...r,np:{...r.np,label:w5(r.id)(r.np)(n)}}))(mp(t)(e)),b5=t=>e=>n=>r=>{const o=d_(e),i=[...Et(v_(n.edges))(u=>d5(t)(o)(u._1)((()=>{const c=Zn("conn:")(u._1);if(c.tag==="Just")return!1;if(c.tag==="Nothing")return!0;g()})())(u._2)),...Y(u=>({depth:u.box.depth,draw:f5(t)(o)(u)}))(C5(t)(n)(r)),...wt(N5(t)(o)(n))(v_(r.tokens))],a=Jh({viewport:p5(J5(t)(n)),clear:N("Just",t.transparentBg?o.bgTransparent:o.bg),dots:w}),s=()=>c5(u=>u.draw)(Rt(u=>c=>at.compare(u.depth)(c.depth))(i));return U(a._1,(()=>{if(a._2.tag==="CatNil")return Z("CatCons",s,K(G,G));if(a._2.tag==="CatCons")return Z("CatCons",a._2._1,K(a._2._2._1,pt("Cons",Z("CatCons",s,K(G,G)),a._2._2._2)));g()})())},k5=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=N_(1e-4)(nn(n*n+e*e)),o=e/r,i=n/r,a=t.to.y-o*7,s=t.to.x-i*7;return C_([t.to,{x:s-o*3,y:a+i*3},{x:s+o*3,y:a-i*3}])},L5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=co(n)(Qt);return o=>{if(o.geometry.tag==="IsoSegments"&&o.plan.tag==="IsoEdgePlan"){const i=o.plan._1.palette,a=o.geometry._1;return e.Bind1().bind(r(s=>t.strokePath(h5(s))({color:i.edge,width:1.5,lineJoin:Ve,lineCap:ir}))(a))(()=>{const s=a.length-1|0;if(s>=0&&s<a.length){const c=a[s],_=c.length-1|0,l=_<1?[]:At(0,_,c),f=l.length-1|0;if(f>=0&&f<l.length){const h=a.length-1|0,m=(()=>{if(h>=0&&h<a.length){const p=a[h],x=p.length-1|0;if(x>=0&&x<p.length)return t.fillPath(k5({from:l[f],to:p[x]}))({color:i.arrowFill,flat:!0})}return n.pure()})();return o.arrow?m:n.pure()}a.length-1|0;const d=n.pure();return o.arrow?d:n.pure()}a.length-1|0;const u=n.pure();return o.arrow?u:n.pure()})}return n.pure()}},yp=t=>t,Xe=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ko=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},S5=yp("Split"),E5=yp("Fall"),fn=t=>e=>n=>r=>{const o=n?0:1,i=1-de(r.x-o)*en(e)*1.1,a=de(i)<.06?i<0?-.06:.06:i,s=t.y+t.h/2,u=t.x+t.w/2;return{x:u+(t.x+(o+(r.x-o)*hn(e))*t.w-u)/a,y:s+(t.y+r.y*t.h-s)/a}},P5=t=>e=>n=>{const r=fn(t)(e)(n)({x:.5,y:.5}),o=t.x+.5*t.w,i=fn(t)(e)(n)({x:.5,y:0}),a=n?0:1,s=t.x+a*t.w,u=fn(t)(e)(n)({x:a,y:0}),c=fn(t)(e)(n)({x:a,y:1}),_=(c.y-u.y)/Xe(1e-6)(t.h),l=(c.x-u.x)/Xe(1e-6)(t.h),f=o-s,d=(i.y-u.y)/(de(f)<1e-6?f<0?-1e-6:1e-6:f),h=t.y+t.h/2,m=t.x+t.w/2,p=o-s,x=(i.x-u.x)/(de(p)<1e-6?p<0?-1e-6:1e-6:p);return{a:x,b:d,c:l,d:_,e:r.x-x*m-l*h,f:r.y-d*m-_*h}},b_=t=>{const e=Xe(0)(t)*3.05,n=hn(e);return{expansion:1+en(e)*.16,verticalScale:de(n)<.06?n<0?-.06:.06:n}},Lo=t=>e=>n=>{const r=b_(e),o=t.x+t.w/2,i=t.y+t.h;return{x:o+(t.x+n.x*t.w-o)*r.expansion,y:i+(t.y+n.y*t.h-i)*r.verticalScale}},G5=t=>e=>{const n=b_(e),r=Lo(t)(e)({x:.5,y:.5});return{a:n.expansion,b:0,c:0,d:n.verticalScale,e:r.x-n.expansion*(t.x+t.w/2),f:r.y-n.verticalScale*(t.y+t.h/2)}},A5=t=>Xe(0)(t.w)/Xe(1e-6)(Xe(0)(t.h))>=4?E5:S5,R5=t=>e=>n=>{const r=n/Xe(1e-6)(t.h),o=n/Xe(1e-6)(t.w),i=(s,u,c)=>{const _=Lo(t)(e)(s),l=Lo(t)(e)(u),f=Lo(t)(e)(c);return[4,_.x,_.y,l.x,l.y,f.x,f.y]},a=[...(()=>{const s=Lo(t)(e)({x:o,y:0});return[1,s.x,s.y]})(),...i({x:o*.44771525016920644,y:0},{x:0,y:r*.44771525016920644},{x:0,y:r}),...(()=>{const s=Lo(t)(e)({x:0,y:1-r});return[2,s.x,s.y]})(),...i({x:0,y:1-r*.44771525016920644},{x:o*.44771525016920644,y:1},{x:o,y:1}),...(()=>{const s=Lo(t)(e)({x:1-o,y:1});return[2,s.x,s.y]})(),...i({x:1-o*.44771525016920644,y:1},{x:1,y:1-r*.44771525016920644},{x:1,y:1-r}),...(()=>{const s=Lo(t)(e)({x:1,y:r});return[2,s.x,s.y]})(),...i({x:1,y:r*.44771525016920644},{x:1-o*.44771525016920644,y:0},{x:1-o,y:0}),...ti];return{face:a,labelAffine:G5(t)(e),labelVisible:b_(e).verticalScale>0,outline:a}},k_=t=>_a(10.8)(.48)(ko(1)(Xe(0)(t)))/_a(10.8)(.48)(1),D5=t=>e=>{const n=k_(ko(1)(Xe(0)((1-ko(1)(Xe(0)(t))-.48)/.5))*.48)/k_(.48);if(e<0){const r=ko(1)(Xe(0)((t-.25)/.28));return k_(r*r*r)}return ko(1)(de(1-n))},F5=t=>D5((()=>{if(t.tag==="Closed")return 0;if(t.tag==="Opening")return t._1;if(t.tag==="Open")return 1;if(t.tag==="Closing")return 1-t._1;g()})())(t.tag==="Opening"?-1:t.tag==="Closing"?1:0),xp=t=>e=>n=>{const r=ko(1)(Xe(0)((n-t)/Xe(1e-6)(e-t)));return r*r*(3-2*r)},wp=t=>e=>n=>r=>{const o=n/Xe(1e-6)(t.h),i=n/Xe(1e-6)(t.w),a=xp(.08)(.2)(e),s=o*a,u=i*a,c=Xe(0)(e)*1.91986,_=(l,f,d)=>{const h=fn(t)(c)(r)(r?l:{...l,x:1-l.x}),m=fn(t)(c)(r)(r?f:{...f,x:1-f.x}),p=fn(t)(c)(r)(r?d:{...d,x:1-d.x});return[4,h.x,h.y,m.x,m.y,p.x,p.y]};return{leaf:{face:[...(()=>{const l={x:i,y:0},f=fn(t)(c)(r)(r?l:{...l,x:1-l.x});return[1,f.x,f.y]})(),..._({x:i*.44771525016920644,y:0},{x:0,y:o*.44771525016920644},{x:0,y:o}),...(()=>{const l={x:0,y:1-o},f=fn(t)(c)(r)(r?l:{...l,x:1});return[2,f.x,f.y]})(),..._({x:0,y:1-o*.44771525016920644},{x:i*.44771525016920644,y:1},{x:i,y:1}),...(()=>{const l={x:.5-u,y:1},f=fn(t)(c)(r)(r?l:{...l,x:1-l.x});return[2,f.x,f.y]})(),..._({x:.5-u*.44771525016920644,y:1},{x:.5,y:1-s*.44771525016920644},{x:.5,y:1-s}),...(()=>{const l={x:.5,y:s},f=fn(t)(c)(r)(r?l:{...l,x:.5});return[2,f.x,f.y]})(),..._({x:.5,y:s*.44771525016920644},{x:.5-u*.44771525016920644,y:0},{x:.5-u,y:0}),...ti],labelAffine:P5(t)(c)(r),labelVisible:hn(c)>0,outline:[...(()=>{const l={x:.5,y:s},f=fn(t)(c)(r)(r?l:{...l,x:.5});return[1,f.x,f.y]})(),..._({x:.5,y:s*.44771525016920644},{x:.5-u*.44771525016920644,y:0},{x:.5-u,y:0}),...(()=>{const l={x:i,y:0},f=fn(t)(c)(r)(r?l:{...l,x:1-l.x});return[2,f.x,f.y]})(),..._({x:i*.44771525016920644,y:0},{x:0,y:o*.44771525016920644},{x:0,y:o}),...(()=>{const l={x:0,y:1-o},f=fn(t)(c)(r)(r?l:{...l,x:1});return[2,f.x,f.y]})(),..._({x:0,y:1-o*.44771525016920644},{x:i*.44771525016920644,y:1},{x:i,y:1}),...(()=>{const l={x:.5-u,y:1},f=fn(t)(c)(r)(r?l:{...l,x:1-l.x});return[2,f.x,f.y]})(),..._({x:.5-u*.44771525016920644,y:1},{x:.5,y:1-s*.44771525016920644},{x:.5,y:1-s})]},seam:[...(()=>{const l={x:.5,y:s},f=fn(t)(c)(r)(r?l:{...l,x:.5});return[1,f.x,f.y]})(),...(()=>{const l={x:.5,y:1-s},f=fn(t)(c)(r)(r?l:{...l,x:.5});return[2,f.x,f.y]})()]}},I5=t=>e=>n=>{const r=xp(.08)(.26)(e),o=wp(t)(e)(n)(!1),i=wp(t)(e)(n)(!0);return{leaves:[i.leaf,o.leaf],seams:[{alpha:r,path:i.seam},{alpha:r,path:o.seam}]}},B5=t=>e=>n=>Xe(0)(ko(t)(ko(Xe(0)(e)/2)(Xe(0)(n)/2))),Q5=t=>e=>n=>{const r=B5(n)(e.w)(e.h),o=F5(t),i=A5(e);if(i==="Fall")return{leaves:[R5(e)(o)(r)],seams:[]};if(i==="Split")return I5(e)(o)(r);g()},Tp=(t,e)=>({tag:t,_1:e}),Np=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},z5=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},_i=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},L_=vi(No)(Qt),M5=Tp("ResolvedLabels"),O5=t=>{const e=te(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return Rs(t);g()},Ma=t=>e=>{const n=Np(1)(ye(e.rootLayout).w),r=e.portalState.tag==="Closed"&&e.levels.length===1,o=(()=>{if(r)return 1;if(e.portalState.tag==="Opening"||e.portalState.tag==="Closing"){if(e.portalState.tag==="Closed")return 1;if(e.portalState.tag==="Opening")return 1-e.portalState._1;if(e.portalState.tag==="Open")return 0;if(e.portalState.tag==="Closing")return 1-(1-e.portalState._1);g()}return 0})(),i=jn(e.rootLayout)(e.camera),a=r?1:z5(0)(1)(i.w/n),s=Rs(e).state.frameTitle===""?0*a*o:40*a*o,u=t.padding*a*a*o;return(()=>{if(t.outputAspect.tag==="Nothing")return Bx;if(t.outputAspect.tag==="Just")return _1(t.outputAspect._1);g()})()({vx:i.x-u,vy:i.y-u-s,vw:i.w+2*u,vh:i.h+2*u+s})},W5=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=_i(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,o=n._1.y*t.segment.placement.scale+t.segment.placement.ty,i=n._1.w*t.segment.placement.scale,a=n._1.h*t.segment.placement.scale;return[1,r,o,2,r+i,o,2,r+i,o+a,2,r,o+a,5]}}g()},S_=t=>e=>{const n=Py(e.segment.placement)({x:t.vx,y:t.vy,w:t.vw,h:t.vh});return{vx:n.x,vy:n.y,vw:n.w,vh:n.h}},vp=t=>e=>t===""?U(st("Return",void 0),ct):ai({owner:k3,text:t,spec:{x:e.vx+6,y:e.vy+6,content:t,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:vo,baseline:Pb},bounds:w,plan:gu}),Jp=t=>e=>{if(t==="")return U(st("Return",void 0),ct);const n=e.vh/720,r=56*n,o=to({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:56,weight:700})(t),i=a=>{const s=r+16*n*2,u=a*n+28*n*2,c=e.vy+e.vh/2,_=e.vx+e.vw/2,l={x:_-u/2,y:c-s/2,w:u,h:s};return io(ro("TitleCardOverlay",{backing:{path:$i(l)(16*n),fill:N("Just",{color:{r:255,g:255,b:255,a:235},flat:!0}),stroke:N("Just",{color:{r:0,g:0,b:0,a:255},width:1.5*n,lineJoin:Ve,lineCap:ir})},text:{owner:Th,text:t,spec:{x:_,y:c,content:t,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:r,weight:700},color:{r:28,g:30,b:36,a:255},align:eo,baseline:Nn},bounds:N("Just",l),plan:gu}}))};return U(o._1,(()=>{if(o._2.tag==="CatNil")return Z("CatCons",i,K(G,G));if(o._2.tag==="CatCons")return Z("CatCons",o._2._1,K(o._2._2._1,pt("Cons",Z("CatCons",i,K(G,G)),o._2._2._2)));g()})())},Cp=t=>e=>{if(t==="")return U(st("Return",void 0),ct);const n=e.vh/720,r=15*n,o=to({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:15,weight:600})(t),i=a=>{const s=e.vy+12*n,u=r+6*n*2,c=a*n+11*n*2,_=e.vx+e.vw/2,l={x:_-c/2,y:s,w:c,h:u};return io(ro("FrameTitleOverlay",{backing:N("Just",{path:$i(l)(u/2),fill:N("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}),stroke:N("Just",{color:{r:0,g:0,b:0,a:255},width:1*n,lineJoin:Ve,lineCap:ir})}),text:{owner:Th,text:t,spec:{x:_,y:s+u/2,content:t,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:r,weight:600},color:{r:28,g:30,b:36,a:255},align:eo,baseline:Nn},bounds:N("Just",l),plan:gu}}))};return U(o._1,(()=>{if(o._2.tag==="CatNil")return Z("CatCons",i,K(G,G));if(o._2.tag==="CatCons")return Z("CatCons",o._2._1,K(o._2._2._1,pt("Cons",Z("CatCons",i,K(G,G)),o._2._2._2)));g()})())},q5=t=>e=>n=>r=>o=>i=>a=>s=>{const u=d_(t.theme),c=(()=>{if(s.tag==="ResolvedLabels")return dp(u)(o)(i)(a);if(s.tag==="SpringLabels")return xu(u)(i)(a)(ep(o)(s._1));g()})(),_=Jh({viewport:o,clear:N("Just",t.transparentBg?u.bgTransparent:u.bg),dots:w}),l=()=>{const f=Ae({path:[],role:_n,layer:w,effects:n<1?[me("GroupAlpha",n)]:[]})((()=>{const d=_p(u)(i)(a),h=()=>{const m=Zh(r)(u)(t.halftoneShadows)(i)(a),p=()=>{const x=up(T=>r.tag!=="Nothing"&&r.tag==="Just"&&r._1===T?N("Just",0):w)(e_)(1)(u)(i)(a),y=()=>{const T=ap(u)(i)(a),v=()=>{const b=w_(u)(o)(i)(a),C=()=>{const S=fp(zb)(u)(i)(a),P=()=>{const F=()=>{const W=zk(u)(i)(a);return a.staticKind!=="Animated"?W:U(st("Return",void 0),ct)};return U(c._1,(()=>{if(c._2.tag==="CatNil")return Z("CatCons",F,K(G,G));if(c._2.tag==="CatCons")return Z("CatCons",c._2._1,K(c._2._2._1,pt("Cons",Z("CatCons",F,K(G,G)),c._2._2._2)));g()})())};return U(S._1,(()=>{if(S._2.tag==="CatNil")return Z("CatCons",P,K(G,G));if(S._2.tag==="CatCons")return Z("CatCons",S._2._1,K(S._2._2._1,pt("Cons",Z("CatCons",P,K(G,G)),S._2._2._2)));g()})())};return U(b._1,(()=>{if(b._2.tag==="CatNil")return Z("CatCons",C,K(G,G));if(b._2.tag==="CatCons")return Z("CatCons",b._2._1,K(b._2._2._1,pt("Cons",Z("CatCons",C,K(G,G)),b._2._2._2)));g()})())};return U(T._1,(()=>{if(T._2.tag==="CatNil")return Z("CatCons",v,K(G,G));if(T._2.tag==="CatCons")return Z("CatCons",T._2._1,K(T._2._2._1,pt("Cons",Z("CatCons",v,K(G,G)),T._2._2._2)));g()})())};return U(x._1,(()=>{if(x._2.tag==="CatNil")return Z("CatCons",y,K(G,G));if(x._2.tag==="CatCons")return Z("CatCons",x._2._1,K(x._2._2._1,pt("Cons",Z("CatCons",y,K(G,G)),x._2._2._2)));g()})())};return U(m._1,(()=>{if(m._2.tag==="CatNil")return Z("CatCons",p,K(G,G));if(m._2.tag==="CatCons")return Z("CatCons",m._2._1,K(m._2._2._1,pt("Cons",Z("CatCons",p,K(G,G)),m._2._2._2)));g()})())};return U(d._1,(()=>{if(d._2.tag==="CatNil")return Z("CatCons",h,K(G,G));if(d._2.tag==="CatCons")return Z("CatCons",d._2._1,K(d._2._2._1,pt("Cons",Z("CatCons",h,K(G,G)),d._2._2._2)));g()})())})());if(n>0){const d=()=>{const h=vp(t.watermark)(o),m=()=>a.staticKind==="TitleCard"?Jp(a.frameTitle)(o):Cp(a.frameTitle)(o);return U(h._1,(()=>{if(h._2.tag==="CatNil")return Z("CatCons",m,K(G,G));if(h._2.tag==="CatCons")return Z("CatCons",h._2._1,K(h._2._2._1,pt("Cons",Z("CatCons",m,K(G,G)),h._2._2._2)));g()})())};return U(f._1,(()=>{if(f._2.tag==="CatNil")return Z("CatCons",d,K(G,G));if(f._2.tag==="CatCons")return Z("CatCons",f._2._1,K(f._2._2._1,pt("Cons",Z("CatCons",d,K(G,G)),f._2._2._2)));g()})())}return U(st("Return",void 0),Z("CatCons",()=>{const d=vp(t.watermark)(o),h=()=>a.staticKind==="TitleCard"?Jp(a.frameTitle)(o):Cp(a.frameTitle)(o);return U(d._1,(()=>{if(d._2.tag==="CatNil")return Z("CatCons",h,K(G,G));if(d._2.tag==="CatCons")return Z("CatCons",d._2._1,K(d._2._2._1,pt("Cons",Z("CatCons",h,K(G,G)),d._2._2._2)));g()})())},K(G,G)))};return U(_._1,(()=>{if(_._2.tag==="CatNil")return Z("CatCons",l,K(G,G));if(_._2.tag==="CatCons")return Z("CatCons",_._2._1,K(_._2._2._1,pt("Cons",Z("CatCons",l,K(G,G)),_._2._2._2)));g()})())},H5=t=>e=>n=>r=>o=>i=>{const a=i.segment.path.length-1|0,s=a>=0&&a<i.segment.path.length?N("Just",i.segment.path[a]):w;if(s.tag==="Nothing")return U(st("Return",void 0),ct);if(s.tag==="Just"){const u=_i(s._1)(o.segment.layout.nodes);if(u.tag==="Nothing")return U(st("Return",void 0),ct);if(u.tag==="Just"){const c=u._1,_=_i(s._1)(o.state.nodes),l=(()=>{if(_.tag==="Nothing")return O1;if(_.tag==="Just")return _._1;g()})(),f={color:t.nodeStroke,width:t.wobble?2:1.25,lineJoin:Ve,lineCap:ir},d={...f,width:1.25},h=Q5(r)({x:c.x,y:c.y,w:c.w,h:c.h})(7);return Ae({path:o.segment.path,role:o.role,layer:w,effects:[me("GroupAlpha",o.bgAlpha),me("GroupTransform",ii,n)]})((()=>{const m=fu({id:s._1,role:S3,geometry:su("FlatNode",{shape:c.shape,bounds:{x:c.x,y:c.y+5,w:c.w,h:c.h}}),alpha:1,plan:uu("FlatNodePlan",{palette:t,label:c.label,labelVisibility:_u,inkBoost:e?1:0,labelAlpha:0,outlineAlpha:N("Just",1),arrival:w,animState:l})}),p=()=>{const x=io(ro("FloorOverlay",{path:Co(c),fill:w,stroke:N("Just",f)})),y=()=>{const T=L_(h.leaves)(b=>{const C=io(ro("FloorOverlay",{path:b.face,fill:N("Just",{color:t.nodeFill,flat:!1}),stroke:w}));if(C._2.tag==="CatNil")return U(C._1,Z("CatCons",()=>io(ro("FloorOverlay",{path:b.outline,fill:w,stroke:N("Just",f)})),K(G,pt("Cons",Z("CatCons",()=>{const S=Ae({path:o.segment.path,role:o.role,layer:w,effects:[me("GroupClip",b.face,Jo)]})(x_(ri("AffineText",b.labelAffine))(o.state.animationTime)(t)(1)(1)(s._1)(c)(l)(_i(s._1)(o.state.nodeLabels)));return b.labelVisible?S:U(st("Return",void 0),ct)},K(G,G)),G))));if(C._2.tag==="CatCons")return U(C._1,Z("CatCons",C._2._1,K(C._2._2._1,pt("Cons",Z("CatCons",()=>{const S=Ae({path:o.segment.path,role:o.role,layer:w,effects:[me("GroupClip",b.face,Jo)]})(x_(ri("AffineText",b.labelAffine))(o.state.animationTime)(t)(1)(1)(s._1)(c)(l)(_i(s._1)(o.state.nodeLabels)));return b.labelVisible?S:U(st("Return",void 0),ct)},K(G,G)),pt("Cons",Z("CatCons",()=>io(ro("FloorOverlay",{path:b.outline,fill:w,stroke:N("Just",f)})),K(G,G)),C._2._2._2)))));g()}),v=()=>L_(h.seams)(b=>{const C=Ae({path:o.segment.path,role:o.role,layer:w,effects:[me("GroupAlpha",b.alpha)]})(io(ro("FloorOverlay",{path:b.path,fill:w,stroke:N("Just",d)})));return b.alpha>0?C:U(st("Return",void 0),ct)});return U(T._1,(()=>{if(T._2.tag==="CatNil")return Z("CatCons",v,K(G,G));if(T._2.tag==="CatCons")return Z("CatCons",T._2._1,K(T._2._2._1,pt("Cons",Z("CatCons",v,K(G,G)),T._2._2._2)));g()})())};return U(x._1,(()=>{if(x._2.tag==="CatNil")return Z("CatCons",y,K(G,G));if(x._2.tag==="CatCons")return Z("CatCons",x._2._1,K(x._2._2._1,pt("Cons",Z("CatCons",y,K(G,G)),x._2._2._2)));g()})())};return U(m._1,(()=>{if(m._2.tag==="CatNil")return Z("CatCons",p,K(G,G));if(m._2.tag==="CatCons")return Z("CatCons",m._2._1,K(m._2._2._1,pt("Cons",Z("CatCons",p,K(G,G)),m._2._2._2)));g()})())})())}}g()},bp=t=>e=>n=>r=>o=>i=>a=>s=>{const u=[1,e.viewport.vx,e.viewport.vy,2,e.viewport.vx+e.viewport.vw,e.viewport.vy,2,e.viewport.vx+e.viewport.vw,e.viewport.vy+e.viewport.vh,2,e.viewport.vx,e.viewport.vy+e.viewport.vh,5],c=s.state,_={tx:a.segment.placement.tx,ty:a.segment.placement.ty,sx:a.segment.placement.scale,sy:a.segment.placement.scale},l=d_(t.theme),f=s.segment.layout,d=ye(f),h={vx:d.x-1e3,vy:d.y-1e3,vw:d.w+2e3,vh:d.h+2e3},m=s.segment.path.length-1|0,p=m>=0&&m<s.segment.path.length?_i(s.segment.path[m])(a.segment.layout.nodes):w,x=s.role==="Active"||11*s.segment.placement.scale*n>=5?e_:_u,y=S_(e.viewport)(s),T=(()=>{if(x==="LabelsHidden")return U(st("Return",void 0),ct);if(x==="LabelsShown")return o.tag==="Leaf"?dp(l)(y)(f)(c):xu(l)(f)(c)(ep(y)(o));g()})(),v={tx:s.segment.placement.tx,ty:s.segment.placement.ty,sx:s.segment.placement.scale,sy:s.segment.placement.scale},b=Ae({path:s.segment.path,role:s.role,layer:w,effects:[me("GroupAlpha",s.bgAlpha)]})((()=>{const S=Ae({path:s.segment.path,role:s.role,layer:w,effects:[me("GroupClip",(()=>{if(Z1(r)>=.52)return u;const F=W5(a)((()=>{const W=s.segment.path.length-1|0;return W>=0&&W<s.segment.path.length?N("Just",s.segment.path[W]):w})());return F.length===0?u:F})(),Jo)]})((()=>{const F=(()=>{if(p.tag==="Just")return Ae({path:a.segment.path,role:a.role,layer:w,effects:[me("GroupTransform",ii,_)]})(io(ro("FloorOverlay",{path:Co({...p._1,x:p._1.x+1,y:p._1.y+1,w:p._1.w-2,h:p._1.h-2}),fill:N("Just",{color:l.bg,flat:!0}),stroke:w})));if(p.tag==="Nothing")return U(st("Return",void 0),ct);g()})(),W=(a.role==="Active"||a.role==="FlyThrough")&&!t.transparentBg?F:U(st("Return",void 0),ct),E=()=>{const R=Ae({path:s.segment.path,role:s.role,layer:w,effects:[me("GroupTransform",ii,v)]})((()=>{const rt=_p(l)(f)(c),$=()=>{const X=Zh(i)(l)(t.halftoneShadows)(f)(c),V=()=>{const D=up(I=>i.tag!=="Nothing"&&i.tag==="Just"&&i._1===I?N("Just",0):w)(x)(1)(l)(f)(c),B=()=>{const I=ap(l)(f)(c);return U(I._1,(()=>{if(I._2.tag==="CatNil")return Z("CatCons",()=>w_(l)(h)(f)(c),K(G,G));if(I._2.tag==="CatCons")return Z("CatCons",I._2._1,K(I._2._2._1,pt("Cons",Z("CatCons",()=>w_(l)(h)(f)(c),K(G,G)),I._2._2._2)));g()})())};return U(D._1,(()=>{if(D._2.tag==="CatNil")return Z("CatCons",B,K(G,G));if(D._2.tag==="CatCons")return Z("CatCons",D._2._1,K(D._2._2._1,pt("Cons",Z("CatCons",B,K(G,G)),D._2._2._2)));g()})())};return U(X._1,(()=>{if(X._2.tag==="CatNil")return Z("CatCons",V,K(G,G));if(X._2.tag==="CatCons")return Z("CatCons",X._2._1,K(X._2._2._1,pt("Cons",Z("CatCons",V,K(G,G)),X._2._2._2)));g()})())};return U(rt._1,(()=>{if(rt._2.tag==="CatNil")return Z("CatCons",$,K(G,G));if(rt._2.tag==="CatCons")return Z("CatCons",rt._2._1,K(rt._2._2._1,pt("Cons",Z("CatCons",$,K(G,G)),rt._2._2._2)));g()})())})()),et=()=>Ae({path:s.segment.path,role:s.role,layer:w,effects:[me("GroupTransform",b3,v)]})(fp(Mb)(l)(f)(c));return U(R._1,(()=>{if(R._2.tag==="CatNil")return Z("CatCons",et,K(G,G));if(R._2.tag==="CatCons")return Z("CatCons",R._2._1,K(R._2._2._1,pt("Cons",Z("CatCons",et,K(G,G)),R._2._2._2)));g()})())};return U(W._1,(()=>{if(W._2.tag==="CatNil")return Z("CatCons",E,K(G,G));if(W._2.tag==="CatCons")return Z("CatCons",W._2._1,K(W._2._2._1,pt("Cons",Z("CatCons",E,K(G,G)),W._2._2._2)));g()})())})()),P=()=>Ae({path:s.segment.path,role:s.role,layer:w,effects:[me("GroupTransform",ii,v)]})(T);return U(S._1,(()=>{if(S._2.tag==="CatNil")return Z("CatCons",P,K(G,G));if(S._2.tag==="CatCons")return Z("CatCons",S._2._1,K(S._2._2._1,pt("Cons",Z("CatCons",P,K(G,G)),S._2._2._2)));g()})())})()),C=()=>a.role==="FlyThrough"?H5(l)(t.halftoneShadows)(_)(r)(a)(s):U(st("Return",void 0),ct);return U(b._1,(()=>{if(b._2.tag==="CatNil")return Z("CatCons",C,K(G,G));if(b._2.tag==="CatCons")return Z("CatCons",b._2._1,K(b._2._2._1,pt("Cons",Z("CatCons",C,K(G,G)),b._2._2._2)));g()})())},$5=t=>e=>n=>r=>L_(r.minis)(o=>{const i=bp(t)(e)(n)(Y1)(Q)(w)(r)(o);return(()=>{const a=o.segment.path.length-1|0;return o.bgAlpha>0&&a>=0&&a<o.segment.path.length&&(()=>{const s=_i(o.segment.path[a])(r.state.nodes);if(s.tag==="Just")return s._1.tag==="Hidden"?!1:s._1.tag!=="PloppingOut";if(s.tag==="Nothing")return!1;g()})()})()?i:U(st("Return",void 0),ct)}),Y5=t=>e=>n=>{if(t.theme==="Isometric")return b5({...x5,transparentBg:t.transparentBg})(t.theme)(Rs(n).segment.layout)(Rs(n).state);const r=Ma(t)(n),o=u=>n.hasDives?r.vw/Np(1)(ye(n.rootLayout).w):1,i={tileScale:o(),viewport:r},a=u=>c=>{if(c.length===0)return U(st("Return",void 0),ct);const _=Pt(l=>w,l=>f=>N("Just",{head:l,tail:f}),c);if(_.tag==="Nothing")return U(st("Return",void 0),ct);if(_.tag==="Just"){const l=bp(t)(i)(n.camera.zoom)(n.portalState)(_._1.head.role==="Active"?e:Q)((()=>{if(_._1.head.role==="FlyThrough"&&0<_._1.tail.length){const f=_._1.tail[0].segment.path.length-1|0;if(f>=0&&f<_._1.tail[0].segment.path.length)return N("Just",_._1.tail[0].segment.path[f])}return w})())(u)(_._1.head);return _._1.head.role==="Active"||_._1.head.role==="FlyThrough"?U(l._1,(()=>{if(l._2.tag==="CatNil")return Z("CatCons",()=>a(_._1.head)(_._1.tail),K(G,G));if(l._2.tag==="CatCons")return Z("CatCons",l._2._1,K(l._2._2._1,pt("Cons",Z("CatCons",()=>a(_._1.head)(_._1.tail),K(G,G)),l._2._2._2)));g()})()):U(st("Return",void 0),Z("CatCons",()=>a(_._1.head)(_._1.tail),K(G,G)))}g()},s=Pt(u=>w,u=>c=>N("Just",{head:u,tail:c}),n.levels);if(s.tag==="Nothing")return U(st("Return",void 0),ct);if(s.tag==="Just"){const u=s._1.tail,c=s._1.head,_=u.length===0,l=q5(t)(o())(c.role==="Active"||c.role==="FlyThrough"?c.bgAlpha:0)((()=>{if(c.role==="FlyThrough"&&0<u.length){const d=u[0].segment.path.length-1|0;if(d>=0&&d<u[0].segment.path.length)return N("Just",u[0].segment.path[d])}return w})())(r)(c.segment.layout)(O5(n).state)(_&&e.tag!=="Leaf"?Tp("SpringLabels",e):M5),f=()=>{const d=$5(t)(i)(n.camera.zoom)(c);return c.role==="Active"||c.role==="FlyThrough"?U(d._1,(()=>{if(d._2.tag==="CatNil")return Z("CatCons",()=>a(c)(u),K(G,G));if(d._2.tag==="CatCons")return Z("CatCons",d._2._1,K(d._2._2._1,pt("Cons",Z("CatCons",()=>a(c)(u),K(G,G)),d._2._2._2)));g()})()):U(st("Return",void 0),Z("CatCons",()=>a(c)(u),K(G,G)))};return U(l._1,(()=>{if(l._2.tag==="CatNil")return Z("CatCons",f,K(G,G));if(l._2.tag==="CatCons")return Z("CatCons",l._2._1,K(l._2._2._1,pt("Cons",Z("CatCons",f,K(G,G)),l._2._2._2)));g()})())}g()},E_=t=>e=>n=>A3({viewport:Ma(t)(n),camera:n.camera})(Y5(t)(e)(n)),P_=t=>e=>{if(e.fill.tag==="Just"){if(e.stroke.tag==="Just")return t.fillStrokePath(e.path)(e.fill._1)(e.stroke._1);if(e.stroke.tag==="Nothing")return t.fillPath(e.path)(e.fill._1);g()}if(e.fill.tag==="Nothing"){if(e.stroke.tag==="Just")return t.strokePath(e.path)(e.stroke._1);if(e.stroke.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()},V5=t=>{const e=t.Monad0(),n=e.Bind1(),r=co(e.Applicative0())(pf),o=rp(t);return i=>{if(i.tag==="FrameTitleOverlay"){const a=i._1;return n.bind(r(P_(t))(a.backing))(()=>o(a.text))}if(i.tag==="TitleCardOverlay"){const a=i._1;return n.bind(P_(t)(a.backing))(()=>o(a.text))}if(i.tag==="FloorOverlay")return P_(t)(i._1);g()}},X5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=co(n)(Qt),o=t.popTransform,i=t.popBakedTransform,a=(()=>{const u=t.popClip,c=t.popAlpha,_=t.popBlend,l=t.popBlur;return f=>{if(f.tag==="GroupTransform"){if(f._1==="NormalTransform")return o;if(f._1==="BakedTransform")return i;g()}if(f.tag==="GroupClip")return u;if(f.tag==="GroupAlpha")return c;if(f.tag==="GroupBlend")return _;if(f.tag==="GroupBlur")return l;g()}})(),s=t.popLayer;return u=>e.Bind1().bind(r(a)(re(u.effects)))(()=>{if(u.layer.tag==="Just")return s;if(u.layer.tag==="Nothing")return n.pure();g()})},U5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=co(n)(Qt);return o=>e.Bind1().bind((()=>{if(o.layer.tag==="Just")return t.pushLayer(o.layer._1);if(o.layer.tag==="Nothing")return n.pure();g()})())(()=>r(i=>{if(i.tag==="GroupTransform"){if(i._1==="NormalTransform")return t.pushTransform(i._2);if(i._1==="BakedTransform")return t.pushBakedTransform(i._2);g()}if(i.tag==="GroupClip")return t.pushClip(i._1)(i._2);if(i.tag==="GroupAlpha")return t.pushAlpha(i._1);if(i.tag==="GroupBlend")return t.pushBlend(i._1);if(i.tag==="GroupBlur")return t.pushBlur(i._1);g()})(o.effects))},kp=t=>{const e=t.Monad0(),n=Ok(t),r=m5(t),o=n5(t),i=L5(t),a=Fk(t),s=y5(t);return P3(e)({beginFrame:u=>t.setViewport(u.viewport),endFrame:e.Applicative0().pure(),beginGroup:U5(t),endGroup:X5(t),background:Gk(t),overlay:V5(t),node:u=>{if(u.geometry.tag==="FlatNode")return n(u);if(u.geometry.tag==="IsoSlab")return r(u);g()},edge:u=>{if(u.geometry.tag==="FlatRoute")return o(u);if(u.geometry.tag==="IsoSegments")return i(u);g()},text:rp(t),token:u=>{if(u.geometry.tag==="FlatToken")return a(u);if(u.geometry.tag==="IsoCube")return s(u);g()},insideTokenStyle:t.insideTokenStyle,measureText:t.measureText,measureInk:t.measureInk})},K5=T_(sh)(jg.measureText),Lp=kp(jg),Sp=t=>Ma({padding:24,outputAspect:t.width<=0||t.height<=0?w:N("Just",t.width/t.height)}),Z5=t=>e=>n=>r=>o=>i=>a=>{const s={padding:24,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;g()})(),halftoneShadows:!1,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?w:N("Just",r.width/r.height)},u=oh(n)(r);return()=>{const c=u(),_=o.levels.length-1|0;if(_>=0&&_<o.levels.length){const f=K5(S_(Sp(r)(o))(o.levels[_]))(o.levels[_].segment.layout)(o.levels[_].state)(c)(),d=zg(i)(f)(a);return Lp(E_(s)(d.applied)(o))(c)(),d.springs}const l=zg(i)(Q)(a);return Lp(E_(s)(l.applied)(o))(c)(),l.springs}},Oa=t=>"rgb("+ae(t.r)+","+ae(t.g)+","+ae(t.b)+")",fi=t=>t===1?7:t===2?10:t===3?14:t===4?13:t===5?5:t===6?1:t===7?4:t===8?1:t===9?2:t===10?1:t===11?2:t===12?1:t===18?2:t===19?1:t===13?2:t===14?1:t===15||t===16?5:1,fe=Mo(Qo("Fixed",zo(0)(20)(2))),G_=t=>{const e=n=>{const r=n>=0&&n<t.length?N("Just",t[n]):w;if(r.tag==="Just")return r._1===1?["M",fe((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===2?["L",fe((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===3?["Q",fe((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+5|0)]:r._1===4?["C",fe((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+5|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+6|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+7|0)]:r._1===5?["Z",...e(n+1|0)]:[];if(r.tag==="Nothing")return[];g()};return Wn(" ")(e(0))},j5=t=>fe(t.vx)+" "+fe(t.vy)+" "+fe(t.vw)+" "+fe(t.vh),Yn=t=>e=>he(Kn(e>=0&&e<t.length?t[e]:0)),A_=t=>e=>{const n=Yn(t.ops)(e+1|0);return At(n,n+Yn(t.ops)(e+2|0)|0,t.paths)},Ep=(()=>{const t=tr("&")("&amp;"),e=tr("<")("&lt;"),n=(()=>{const r=tr(">")("&gt;"),o=(()=>{const i=tr('"')("&quot;");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),tL={vx:0,vy:0,vw:1,vh:1},eL=t=>(e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i>=0&&i<t.length){if(t[i]===15){const a=i+1|0;r=!1,o={vx:a>=0&&a<t.length?t[a]:0,vy:(()=>{const s=a+1|0;return s>=0&&s<t.length?t[s]:0})(),vw:(()=>{const s=a+2|0;return s>=0&&s<t.length?t[s]:0})(),vh:(()=>{const s=a+3|0;return s>=0&&s<t.length?t[s]:0})()};continue}n=i+fi(t[i])|0;continue}r=!1,o=tL}return o})(0),Wa=t=>e=>({r:Yn(t)(e),g:Yn(t)(e+1|0),b:Yn(t)(e+2|0),a:Yn(t)(e+3|0)}),Pp=t=>e=>({color:Wa(t)(e),width:(()=>{const n=e+4|0;return n>=0&&n<t.length?t[n]:0})(),join:Yn(t)(e+5|0),cap:Yn(t)(e+6|0)}),nL=t=>e=>'<rect x="'+fe(t.vx)+'" y="'+fe(t.vy)+'" width="'+fe(t.vw)+'" height="'+fe(t.vh)+'" fill="'+Oa(e)+'" opacity="'+fe(nt(e.a)/255)+'"/>',rL=t=>e=>'<path d="'+G_(t)+'" fill="'+Oa(e)+'" fill-opacity="'+fe(nt(e.a)/255)+'"/>',Gp=t=>' stroke="'+Oa(t.color)+'" stroke-opacity="'+fe(nt(t.color.a)/255)+'" stroke-width="'+fe(t.width)+'" stroke-linejoin="'+(t.join===0?"round":t.join===1?"bevel":"miter")+'" stroke-linecap="'+(t.cap===0?"butt":t.cap===1?"round":"square")+'"',oL=t=>e=>n=>'<path d="'+G_(t)+'" fill="'+Oa(e)+'" fill-opacity="'+fe(nt(e.a)/255)+'"'+Gp(n)+"/>",iL=t=>e=>'<path d="'+G_(t)+'" fill="none"'+Gp(e)+"/>",aL=t=>e=>{const n=Wa(t.ops)(e+7|0),r=Yn(t.ops)(e+12|0),o=Yn(t.ops)(e+11|0);return'<text x="'+fe((()=>{const i=e+1|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" y="'+fe((()=>{const i=e+2|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'"'+(r===0?' dy="0.8em"':r===1?' dy="0.32em"':"")+' fill="'+Oa(n)+'" fill-opacity="'+fe(nt(n.a)/255)+'" font-size="'+fe((()=>{const i=e+5|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" font-family="'+Ep((()=>{const i=Yn(t.ops)(e+4|0);return i>=0&&i<t.strs.length?t.strs[i]+", ui-sans-serif, system-ui, sans-serif":", ui-sans-serif, system-ui, sans-serif"})())+'" font-weight="'+ae(Yn(t.ops)(e+6|0))+'" text-anchor="'+(o===0?"start":o===1?"middle":"end")+'">'+Ep((()=>{const i=Yn(t.ops)(e+3|0);return i>=0&&i<t.strs.length?t.strs[i]:""})())+"</text>"},di=t=>e=>n=>{const r=n>=0&&n<e.ops.length?N("Just",e.ops[n]):w;if(r.tag==="Just")return r._1===1?rL(A_(e)(n))(Wa(e.ops)(n+3|0))+di(t)(e)(n+fi(r._1)|0):r._1===2?iL(A_(e)(n))(Pp(e.ops)(n+3|0))+di(t)(e)(n+fi(r._1)|0):r._1===3?oL(A_(e)(n))(Wa(e.ops)(n+3|0))(Pp(e.ops)(n+7|0))+di(t)(e)(n+fi(r._1)|0):r._1===4?aL(e)(n)+di(t)(e)(n+fi(r._1)|0):r._1===16?nL(t)(Wa(e.ops)(n+1|0))+di(t)(e)(n+fi(r._1)|0):di(t)(e)(n+fi(r._1)|0);if(r.tag==="Nothing")return"";g()},sL=t=>{const e=eL(t.ops);return{viewBox:j5(e),body:di(e)(t)(0),vx:e.vx,vy:e.vy,vw:e.vw,vh:e.vh}},uL=yb(Nb)(jm),Ap=t=>e=>{const n=t.strs;return()=>{const r=ic(n);return t.strs.push(e),r}},wu=t=>e=>{const n=t.paths;return()=>{const r=ic(n);return t.paths.push(...e),{offset:r,len:e.length}}},cL=t=>e=>{const n=e.tx,r=t.ops;return()=>{r.push(n),t.ops.push(e.ty),t.ops.push(e.sx),t.ops.push(e.sy)}},Rp=t=>e=>{const n=e.vx,r=t.ops;return()=>{r.push(n),t.ops.push(e.vy),t.ops.push(e.vw),t.ops.push(e.vh)}},uo=t=>e=>{const n=nt(e),r=t.ops;return()=>{r.push(n)}},Tu=t=>e=>{const n=e.len,r=uo(t)(e.offset);return()=>(r(),uo(t)(n)())},gL=()=>{const t=[],e=[],n=[],r=[];return r.push(1),{ops:t,paths:e,strs:n,alphaStack:r}},_L=t=>{if(t.tag==="MeasureText"){const e=t._3(Wg(t._1)(t._2));return()=>e}if(t.tag==="MeasureInk"){const e=t._3(qg(t._1)(t._2));return()=>e}g()},Dp=t=>{const e=t.alphaStack;return()=>{const n=ic(e);if(n===0)return 1;const r=e2(Yt,w,n-1|0,t.alphaStack);if(r.tag==="Nothing")return 1;if(r.tag==="Just")return r._1;g()}},li=t=>e=>{const n=Dp(t);return()=>{const r=n();return uo(t)(e.r)(),uo(t)(e.g)(),uo(t)(e.b)(),uo(t)(he(Kn(nt(e.a)*r+.5)))()}},Fp=t=>e=>{const n=li(t)(e.color);return()=>{n(),t.ops.push(e.width),t.ops.push((()=>{if(e.lineJoin==="RoundJoin")return 0;if(e.lineJoin==="BevelJoin")return 1;if(e.lineJoin==="MiterJoin")return 2;g()})()),t.ops.push((()=>{if(e.lineCap==="ButtCap")return 0;if(e.lineCap==="RoundCap")return 1;if(e.lineCap==="SquareCap")return 2;g()})())}},fL=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r;if(s.tag==="FillPath"){const u=s._3,c=s._2,_=wu(a)(s._1);o=!1,i=()=>{const l=_();return a.ops.push(1),Tu(a)(l)(),li(a)(c.color)(),u};continue}if(s.tag==="StrokePath"){const u=s._3,c=s._2,_=wu(a)(s._1);o=!1,i=()=>{const l=_();return a.ops.push(2),Tu(a)(l)(),Fp(a)(c)(),u};continue}if(s.tag==="FillStrokePath"){const u=s._2,c=s._4,_=s._3,l=wu(a)(s._1);o=!1,i=()=>{const f=l();return a.ops.push(3),Tu(a)(f)(),li(a)(u.color)(),Fp(a)(_)(),c};continue}if(s.tag==="DrawText"){const u=s._2,c=s._1,_=Ap(a)(Zo(c.content));o=!1,i=()=>{const l=_(),f=Ap(a)(c.font.family)();return a.ops.push(4),a.ops.push(c.x),a.ops.push(c.y),uo(a)(l)(),uo(a)(f)(),a.ops.push(c.font.size),uo(a)(c.font.weight)(),li(a)(c.color)(),a.ops.push((()=>{if(c.align==="AlignLeft")return 0;if(c.align==="AlignCenter")return 1;if(c.align==="AlignRight")return 2;g()})()),a.ops.push((()=>{if(c.baseline==="BaselineTop")return 0;if(c.baseline==="BaselineMiddle")return 1;if(c.baseline==="BaselineAlphabetic")return 2;if(c.baseline==="BaselineBottom")return 3;g()})()),u};continue}if(s.tag==="DrawTextAffine"){n=a,r=Vt("DrawText",{...s._2,x:s._1.a*s._2.x+s._1.c*s._2.y+s._1.e,y:s._1.b*s._2.x+s._1.d*s._2.y+s._1.f},s._3);continue}if(s.tag==="PushTransform"){const u=s._2,c=s._1,_=a.ops;o=!1,i=()=>(_.push(5),cL(a)(c)(),u);continue}if(s.tag==="PopTransform"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(6),u);continue}if(s.tag==="PushClip"){const u=s._3,c=s._2,_=wu(a)(s._1);o=!1,i=()=>{const l=_();return a.ops.push(7),Tu(a)(l)(),a.ops.push((()=>{if(c==="NonZero")return 0;if(c==="EvenOdd")return 1;g()})()),u};continue}if(s.tag==="PopClip"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(8),u);continue}if(s.tag==="PushBlend"){const u=s._1,c=s._2,_=a.ops;o=!1,i=()=>(_.push(9),a.ops.push((()=>{if(u==="Normal")return 0;if(u==="Difference")return 1;g()})()),c);continue}if(s.tag==="PopBlend"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(10),u);continue}if(s.tag==="PushAlpha"){const u=s._1,c=s._2,_=Dp(a);o=!1,i=()=>{const l=_();return a.alphaStack.push(l*u),a.ops.push(11),a.ops.push(u),c};continue}if(s.tag==="PopAlpha"){const u=s._1,c=a.alphaStack;o=!1,i=()=>(n2(Yt,w,c),a.ops.push(12),u);continue}if(s.tag==="PushBlur"){const u=s._2,c=s._1,_=a.ops;o=!1,i=()=>(_.push(18),a.ops.push(c),u);continue}if(s.tag==="PopBlur"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(19),u);continue}if(s.tag==="PushLayer"){const u=s._1,c=s._2,_=a.ops;o=!1,i=()=>(_.push(13),a.ops.push((()=>{if(u==="LayerBase")return 0;if(u==="LayerPolyOut")return 1;if(u==="LayerPolyIn")return 2;if(u==="LayerNodeMask")return 3;if(u==="LayerOverlay")return 4;g()})()),c);continue}if(s.tag==="PopLayer"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(14),u);continue}if(s.tag==="SetViewport"){const u=s._2,c=s._1,_=a.ops;o=!1,i=()=>(_.push(15),Rp(a)(c)(),u);continue}if(s.tag==="ClearBackground"){const u=s._1,c=s._2,_=a.ops;o=!1,i=()=>(_.push(16),li(a)(u)(),c);continue}if(s.tag==="BackgroundDots"){const u=s._2,c=s._1,_=a.ops;o=!1,i=()=>(_.push(17),Rp(a)(c.viewport)(),li(a)(c.bgColor)(),li(a)(c.dotColor)(),a.ops.push(c.tile),a.ops.push(c.dotRadius),a.ops.push(c.origin.x),a.ops.push(c.origin.y),u);continue}g()}return i},dL=t=>e=>e.type==="metrics"?_L(e.value):e.type==="render"?fL(t)(e.value):qf("Data.Functor.Variant: pattern match failure ["+e.type+"]"),lL=t=>{const e=gL();return uL(dL(e))(t)(),{ops:e.ops,paths:e.paths,strs:e.strs}},hL=t=>t,qa=t=>t,R_=qa("Light"),pL=qa("Dark"),mL=qa("Blueprint"),yL=qa("Whiteboard"),xL=qa("Isometric"),wL=hL("TransparentBackground"),So=t=>"rgb("+ae(t.r)+","+ae(t.g)+","+ae(t.b)+")",Nu=Mo(Qo("Fixed",zo(0)(20)(6))),Ir=Mo(Qo("Fixed",zo(0)(20)(4))),TL=t=>"translate("+Ir(t.tx)+","+Ir(t.ty)+") scale("+Ir(t.sx)+","+Ir(t.sy)+")",qt=Mo(Qo("Fixed",zo(0)(20)(2))),D_=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,o=r>=0&&r<t.length?N("Just",t[r]):w;if(o.tag==="Nothing"){n=t.length;continue}if(o.tag==="Just"){if(o._1===1){e.push("M"),e.push(qt((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(qt((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),n=r+3|0;continue}if(o._1===2){e.push("L"),e.push(qt((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(qt((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),n=r+3|0;continue}if(o._1===3){e.push("Q"),e.push(qt((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(qt((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(qt((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(qt((()=>{const i=r+4|0;return i>=0&&i<t.length?t[i]:0})())),n=r+5|0;continue}if(o._1===4){e.push("C"),e.push(qt((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(qt((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(qt((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(qt((()=>{const i=r+4|0;return i>=0&&i<t.length?t[i]:0})())),e.push(qt((()=>{const i=r+5|0;return i>=0&&i<t.length?t[i]:0})())),e.push(qt((()=>{const i=r+6|0;return i>=0&&i<t.length?t[i]:0})())),n=r+7|0;continue}if(o._1===5){e.push("Z"),n=r+1|0;continue}n=t.length;continue}g()}return Wn(" ")(e)},NL={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},F_=(()=>{const t=tr("&")("&amp;"),e=tr("<")("&lt;"),n=(()=>{const r=tr(">")("&gt;"),o=(()=>{const i=tr('"')("&quot;");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),vL=t=>{if(t.style==="RunText"||t.style==="RunHighlight")return"<tspan>"+F_(t.text)+"</tspan>";if(t.style==="RunCode"||t.style==="RunCodeHighlight")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+F_(t.text)+"</tspan>";g()},je=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},JL=t=>e=>{const n=[];let r=0;const o=i=>{const a=i>=0&&i<e.length?t.sx*e[i]+t.tx:t.sx*0+t.tx;return()=>{n.push(a),n.push((()=>{const s=i+1|0;return s>=0&&s<e.length?t.sy*e[s]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const i=r,a=i>=0&&i<e.length?N("Just",e[i]):w;if(a.tag==="Nothing"){r=e.length;continue}if(a.tag==="Just"){if(a._1===1){n.push(a._1),o(i+1|0)(),r=i+3|0;continue}if(a._1===2){n.push(a._1),o(i+1|0)(),r=i+3|0;continue}if(a._1===3){n.push(a._1),o(i+1|0)(),o(i+3|0)(),r=i+5|0;continue}if(a._1===4){n.push(a._1),o(i+1|0)(),o(i+3|0)(),o(i+5|0)(),r=i+7|0;continue}if(a._1===5){n.push(a._1),r=i+1|0;continue}r=e.length;continue}g()}return n},vu=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return JL(r._1)(e);g()}},Ip={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),a=o();return i(a)}},Functor0:()=>NL},CL={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>Ip},bL={pure:t=>e=>()=>t,Apply0:()=>Ip},Bp={Applicative0:()=>bL,Bind1:()=>CL},kL=t=>e=>'<defs><pattern id="'+t+'" x="'+qt(e.origin.x)+'" y="'+qt(e.origin.y)+'" width="'+qt(e.tile)+'" height="'+qt(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+qt(e.tile)+'" height="'+qt(e.tile)+'" fill="'+So(e.bgColor)+'" fill-opacity="'+qt(nt(e.bgColor.a)/255)+'"/>')+'<circle cx="'+qt(e.tile/2)+'" cy="'+qt(e.tile/2)+'" r="'+qt(e.dotRadius)+'" fill="'+So(e.dotColor)+'"/></pattern></defs><rect x="'+qt(e.viewport.vx)+'" y="'+qt(e.viewport.vy)+'" width="'+qt(e.viewport.vw)+'" height="'+qt(e.viewport.vh)+'" fill="url(#'+t+')"/>',Qp=t=>e=>'<path d="'+D_(t)+'" fill="'+So(e)+'" fill-opacity="'+qt(nt(e.a)/255)+'"/>',LL=t=>e=>n=>r=>'<rect x="'+qt(t.x)+'" y="'+qt(t.y)+'" width="'+qt(t.w)+'" height="'+qt(t.h)+'" rx="'+qt(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+So(n._1.color)+'" fill-opacity="'+qt(nt(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';g()})()+(()=>{if(r.tag==="Just")return' stroke="'+So(r._1.color)+'" stroke-opacity="'+qt(nt(r._1.color.a)/255)+'" stroke-width="'+qt(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()})()+"/>",zp=t=>e=>'<path d="'+D_(t)+'" fill="none" stroke="'+So(e.color)+'" stroke-opacity="'+qt(nt(e.color.a)/255)+'" stroke-width="'+qt(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()})()+'"/>',Mp=t=>{const e=hr(Zo(t.content));return'<text x="'+qt(t.x)+'" y="'+qt(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="'+So(t.color)+'" fill-opacity="'+qt(nt(t.color.a)/255)+'" font-size="'+qt(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+ae(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"?F_(e[0].text):Wn("")(Y(vL)(e)))+"</text>"},SL=t=>"matrix("+Ir(t.a)+" "+Ir(t.b)+" "+Ir(t.c)+" "+Ir(t.d)+" "+Ir(t.e)+" "+Ir(t.f)+")",Op={fillPath:t=>e=>n=>{const r=vu(n)(t);return()=>{const o=r();return je(Qp(o)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=vu(n)(t);return()=>{const o=r(),i=n.bake.value;return je(zp(o)((()=>{if(i.tag==="Nothing")return e;if(i.tag==="Just")return{...e,width:i._1.sx*e.width};g()})()))(n)()}},fillStrokePath:t=>e=>n=>r=>{const o=vu(r)(t);return()=>{const i=o(),a=r.bake.value;return je(Qp(i)(e.color)+zp(i)((()=>{if(a.tag==="Nothing")return n;if(a.tag==="Just")return{...n,width:a._1.sx*n.width};g()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>o=>{const i=o.bake;return()=>{const a=i.value;return je(LL((()=>{if(a.tag==="Nothing")return t;if(a.tag==="Just")return{x:a._1.sx*t.x+a._1.tx,y:a._1.sy*t.y+a._1.ty,w:a._1.sx*t.w,h:a._1.sy*t.h};g()})())((()=>{if(a.tag==="Nothing")return e;if(a.tag==="Just")return a._1.sx*e;g()})())(n)(r.tag==="Just"?N("Just",(()=>{if(a.tag==="Nothing")return r._1;if(a.tag==="Just")return{...r._1,width:a._1.sx*r._1.width};g()})()):w))(o)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return je(Mp((()=>{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=>je((()=>{const n='transform="'+SL(t)+'"';return(n===""?"<g>":"<g "+n+">")+Mp(e)+"</g>"})()),pushTransform:t=>je((()=>{const e='transform="'+TL(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:je("</g>"),pushBakedTransform:t=>e=>{const n=e.bake;return()=>{n.value=N("Just",t)}},popBakedTransform:t=>{const e=t.bake;return()=>{e.value=w}},pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const o=r.value;n.clipCounter.value=o+1|0;const i=vu(n)(t)(),a="clip"+ae(o);return je((()=>{const s='clip-path="url(#'+a+')"';return'<defs><clipPath id="'+a+'"><path d="'+D_(i)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";g()})()+"/></clipPath></defs>"+(s===""?"<g>":"<g "+s+">")})())(n)()}},popClip:je("</g>"),pushBlend:t=>je((()=>{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:je("</g>"),pushAlpha:t=>je((()=>{const e='opacity="'+qt(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:je("</g>"),pushBlur:t=>e=>{if(t<.01)return je("<g>")(e);const n=e.patternCounter;return()=>{const r=n.value;e.patternCounter.value=r+1|0;const o="lvl-blur-"+ae(r);return je((()=>{const i='filter="url(#'+o+')"';return'<defs><filter id="'+o+'" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="'+qt(t)+'"/></filter></defs>'+(i===""?"<g>":"<g "+i+">")})())(e)()}},popBlur:je("</g>"),pushLayer:t=>e=>{const n=(()=>{if(t==="LayerNodeMask"){const r=e.maskDepth;return()=>{const o=r.value;e.maskDepth.value=o+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=>je('<rect x="'+qt(e.viewport.vx)+'" y="'+qt(e.viewport.vy)+'" width="'+qt(e.viewport.vw)+'" height="'+qt(e.viewport.vh)+'" fill="'+So(t)+'" opacity="'+qt(nt(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,je(kL("bg-dots-"+ae(r))(t))(e)()}},measureText:t=>e=>n=>{const r=Wg(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=qg(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Ug,Monad0:()=>Bp},EL=kp(Op),PL=T_(Bp)(Op.measureText),GL=t=>e=>n=>r=>o=>{const i={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;g()})(),halftoneShadows:!1,watermark:"",theme:n,outputAspect:t},a=Ma(i)(o);return{viewBox:Nu(a.vx)+" "+Nu(a.vy)+" "+Nu(a.vw)+" "+Nu(a.vh),body:(()=>{const s=[],u={value:0},c={value:0},_={value:0},l={value:w};return EL(E_(i)(e)(o))({out:s,maskDepth:u,clipCounter:c,patternCounter:_,viewport:a,bake:l})(),Wn("")(s)})(),vx:a.vx,vy:a.vy,vw:a.vw,vh:a.vh}},AL=t=>e=>n=>r=>o=>i=>{const a={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;g()})(),outputAspect:t},s=zg(o)((()=>{const u=[],c={value:0},_={value:0},l={value:0},f={value:w},d=r.levels.length-1|0;if(d>=0&&d<r.levels.length){const h=S_(Ma(a)(r))(r.levels[d]);return PL(h)(r.levels[d].segment.layout)(r.levels[d].state)({out:u,maskDepth:c,clipCounter:_,patternCounter:l,viewport:h,bake:f})()}return Q})())(i);return{parts:GL(t)(s.applied)(e)(n)(r),springs:s.springs}},Eo=(t,e)=>({tag:t,_1:e}),Ju=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Gn=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Wp=ge(A)(Qt),qp=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},Hp=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Cu=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},bu=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},hi=(()=>{const t=wn.unfoldr(e=>{if(e.tag==="Nil")return w;if(e.tag==="Cons")return N("Just",L(e._1,e._2));g()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,pt("Cons",r._3,n(r._6,o)));g()};return n(e,G)})())})(),RL=J(t=>e=>it(A)(e)()(t))(Q),I_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},$p=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},DL=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ku=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},FL=Eo("NoKeyframes"),IL=t=>Eo("DuplicateEventId",t),BL=t=>Eo("UnknownEvent",t),QL=t=>e=>({...e,cameraSpans:B1(e.cameraConfig)(t)(e.layout)(e.keyframes)({endT:e.totalDuration,spans:e.spans,windows:e.windows,segments:e.segments,dives:e.dives})}),zL=t=>e=>n=>r=>{const o=Ju(r.edge)(e.edges),i=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return _s(o._1);g()})(),a=Gn(t.minTokenDuration)(Gn(nt(J(s=>u=>s+gn(u).length|0)(0)(r.labels))*t.tokenReadSecPerChar)(t.tokenSpeed<=0?0:i/t.tokenSpeed))+n.post;return{duration:a,holdPre:0,holdPost:a<=0?0:n.post/a}},ML=Za(t=>{const e=Ho(`
10
+ `)(t);return e.length===0?[""]:e}),OL=t=>e=>Wp(wt(n=>{if(n.kind.tag==="SendToken")return N("Just",L(n.id,{post:(()=>{const r=n.id;return(()=>{const o=n.kind._1.to;return ne(i=>{if(i.kind.tag==="SendToken")return(i.when.tag==="First"?!1:i.when.tag==="After"&&i.when._1===r)&&i.kind._1.from===o;if(i.kind.tag==="FillNodeWithoutTransition")return!1;g()},e)})()?0:t.tokenHold})()}));if(n.kind.tag==="FillNodeWithoutTransition")return w;g()})(e)),WL=t=>{if(t.event.kind.tag==="SendToken")return N("Just",{startT:t.startT,endT:t.endT,target:$o("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 N("Just",{startT:t.startT,endT:t.endT,target:$o("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},qL=t=>wt((()=>{const e=t.path;return n=>n.target.tag==="TokenWindow"?N("Just",{path:e,eventId:n.target._1,window:n,from:n.target._4,to:n.target._5,labels:n.target._6,holdPre:n.target._7,holdPost:n.target._8}):w})())(t.windows),HL=t=>e=>n=>{const r=Ju(n)(t);if(r.tag==="Nothing")return M1;if(r.tag==="Just"){const o=qp(r._1.target)(e);return qp(r._1.source)(e)?o?Qw:Bw:M1}g()},Yp=t=>e=>{if(t.tag==="Just"&&t._1>e.endT+1e-4){const n=Gn(0)(e.endT-e.startT),r=Gn(e.startT)(t._1-n);return{...e,startT:r,endT:r+n}}return e},Vp=Y(ea),$L={post:0},YL=t=>e=>n=>r=>o=>{const i=Hp(o.event.id)(n),a=(()=>{if(i.tag==="Nothing")return $L;if(i.tag==="Just")return i._1;g()})(),s=(()=>{if(o.event.when.tag==="First")return 0;if(o.event.when.tag==="At")return o.event.when._1;if(o.event.when.tag==="After"){const c=o.event.when._1,_=te(l=>l.event.id===c)(r);if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1.endT;g()}if(o.event.when.tag==="With"){const c=o.event.when._1,_=te(l=>l.event.id===c)(r);if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1.startT}g()})(),u=(()=>{if(o.event.kind.tag==="SendToken")return zL(t)(e)(a)(o.event.kind._1);if(o.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return St(r)({startT:s,endT:s+u.duration,event:o.event,holdPre:u.holdPre,holdPost:u.holdPost})},Xp=t=>e=>n=>J(YL(t)(e)(OL(t)(n)))([])(Wt(r=>o=>({event:o}))(n)),VL=t=>J(e=>n=>{const r=Or(e);if(r.tag==="Nothing")return[n];if(r.tag==="Just")return n.startT<=r._1.last.endT+1e-4?St(r._1.init)({...r._1.last,endT:Gn(r._1.last.endT)(n.endT)}):St(e)(n);g()})([])(Rt(e=>n=>at.compare(e.startT)(n.startT))(t)),XL=t=>e=>{const n=Cu(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},UL=t=>e=>{const n=Rt(at.compare)(wt(r=>r.target.tag==="RelabelWindow"?r.target._1===e?N("Just",r.startT):w:r.target.tag==="TokenWindow"?r.target._4===e||r.target._5===e?N("Just",r.startT):w:r.target.tag==="FillWindow"&&r.target._2===e?N("Just",r.startT):w)(t));return 0<n.length?N("Just",n[0]):w},KL=t=>e=>{const n=Rt(at.compare)(wt(r=>r.target.tag==="TokenWindow"&&r.target._2===e?N("Just",r.startT):w)(t));return 0<n.length?N("Just",n[0]):w},ZL=t=>e=>e.target.tag==="NodeWindow"?e.target._2==="PlopIn"?Yp(UL(t.windows)(e.target._1))(e):e:e.target.tag==="EdgeWindow"&&e.target._2.tag==="Extend"?Yp(KL(t.windows)(e.target._1))(e):e,jL=t=>({...t,windows:Rt(e=>n=>at.compare(e.startT)(n.startT))(Y(ZL(t))(t.windows))}),tS=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()},Lu={id:"",nodes:Q,edges:Q,labels:Q,kind:ca},eS=t=>e=>$y((()=>{const n=bu(e.from)(t);if(n.tag==="Nothing")return Lu;if(n.tag==="Just")return n._1;g()})())((()=>{const n=bu(e.to)(t);if(n.tag==="Nothing")return Lu;if(n.tag==="Just")return n._1;g()})()),nS=t=>e=>{const n=Cu(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:Q};if(n.tag==="Just")return n._1;g()},Up={id:"",index:-1,kind:"",name:"",time:0,endTime:0,path:[],tokenIndex:-1,lineIndex:-1,text:"",from:"",to:""},rS=t=>e=>e.scene.tag==="StepScene"?N("Just",{...Up,id:"step:"+e.scene._1,kind:"step",name:e.scene._1,time:e.startT,endTime:e.startT,path:Vp(t)}):w,oS=t=>wt(rS(t.path))(t.spans),B_=t=>e=>n=>r=>{const o=Ju(r)(n.edges);if(o.tag==="Just")return t<=0?e:Gn(e)(_s(o._1)/t);if(o.tag==="Nothing")return e;g()},Kp=t=>e=>n=>r=>o=>{const i=bu(o.to)(n),a=(()=>{if(i.tag==="Nothing")return Lu;if(i.tag==="Just")return i._1;g()})(),s=t.plop,u=bu(o.from)(n),c=(()=>{if(u.tag==="Nothing")return Lu;if(u.tag==="Just")return u._1;g()})(),_=eS(n)(o),l=Y(y=>({startT:0,endT:0+B_(t.edgeSpeed)(t.minEdgeDuration)(e)(y),target:$o("EdgeWindow",y,vs("Extend",jc))}))(hi(_.entering.edges)),f=Y(y=>({startT:0,endT:s,target:$o("NodeWindow",y,Wc)}))(hi(_.entering.nodes)),d=Y(y=>({startT:0,endT:t.plop,target:$o("RelabelWindow",y.node,y.oldLabel,y.newLabel)}))(wt(y=>{const T=Cu(y)(c.labels);if(T.tag==="Just"){const v=Cu(y)(a.labels);if(v.tag==="Just")return T._1===v._1?w:N("Just",{node:y,oldLabel:T._1,newLabel:v._1});if(v.tag==="Nothing")return w;g()}if(T.tag==="Nothing")return w;g()})(hi(_.surviving.nodes))),h=J(Gn)(0)(Y(y=>B_(t.edgeSpeed)(t.minEdgeDuration)(e)(y))(hi(_.leaving.edges))),m=y=>ne(T=>{const v=Ju(T)(r);if(v.tag==="Just")return v._1.source===y||v._1.target===y;if(v.tag==="Nothing")return!1;g()},hi(_.leaving.edges))?h:0,p=Y(y=>({startT:m(y),endT:m(y)+t.plop,target:$o("NodeWindow",y,zx)}))(hi(_.leaving.nodes)),x=Y(y=>({startT:0,endT:B_(t.edgeSpeed)(t.minEdgeDuration)(e)(y),target:$o("EdgeWindow",y,vs("Retract",HL(r)(_.leaving.nodes)(y)))}))(hi(_.leaving.edges));return{duration:(()=>{const y=Rt(at.compare)([...Y(v=>v.endT)(x),...Y(v=>v.endT)(p),...Y(v=>v.endT)(f),...Y(v=>v.endT)(d),...Y(v=>v.endT)(l)]),T=y.length-1|0;return T>=0&&T<y.length?y[T]+t.gap:t.gap})(),windows:[...x,...p,...f,...d,...l]}},iS=t=>e=>n=>r=>o=>i=>Y((()=>{const a=o.startT;return s=>({...s,startT:s.startT+a,endT:s.endT+a})})())(Kp(t)(e)(n)(r)(i).windows),aS=t=>wt(e=>Ot(Ni,e).length>1?N("Just",(()=>{const n=Pt(r=>w,r=>o=>N("Just",{head:r,tail:o}),Ot(Ni,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):w)(w2(ta)(Rt(A.compare)(t))),sS=t=>{const e=Y(r=>r.id)(t),n=RL(e);return[...Y(IL)(aS(e)),...Y(BL)(lt(r=>!I_(r)(n),Et(t)(tS)))]},uS=t=>{const e=Wp(Y(r=>L(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=>o=>i=>{if(I_(i)(o))return[Eo("ScheduleCycle",[...Ot(pn.foldr,o),i])];if(I_(i)(r))return[];const a=Hp(i)(e);if(a.tag==="Nothing")return[];if(a.tag==="Just")return Et(a._1)(n(it(A)(i)()(r))(it(A)(i)()(o)));g()};return Et(t)(r=>n(Q)(Q)(r.id))},cS={plop:.5,gap:0,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:0,stillHold:1.8,hatchHold:0,tokenReadSecPerChar:.06,nodeEasing:nx,edgeEasing:Lr,tokenEasing:r1,diveDur:2.45,retreatDur:2.45},gS=t=>e=>n=>r=>Y((()=>{const o=n.startT;return i=>({...i,startT:i.startT+o,endT:i.endT+o})})())(wt(WL)(Xp(t)(e)(r.events))),_S=t=>e=>n=>r=>o=>{if(o.scene.tag==="Structural")return iS(t)(e)(n)(r)(o)(o.scene._1);if(o.scene.tag==="Hold")return[];if(o.scene.tag==="DataFlow")return gS(t)(e)(o)(o.scene._1);if(o.scene.tag==="EnterNode")return[];if(o.scene.tag==="ExitNode")return[];if(o.scene.tag==="StepScene")return[];g()},fS=t=>e=>n=>{const r=Xp(t)(e)(n.events);return r.length===0?t.gap:J(Gn)(0)(Y(o=>o.endT)(r))+t.gap},dS=t=>e=>n=>r=>o=>{if(o.tag==="Structural")return Kp(t)(e)(n)(r)(o._1).duration;if(o.tag==="Hold")return t.stillHold;if(o.tag==="DataFlow")return fS(t)(e)(o._1);if(o.tag==="EnterNode"||o.tag==="ExitNode"||o.tag==="StepScene")return 0;g()},Zp=t=>e=>n=>r=>o=>i=>{const a=Ay(e)(r),s=n.layout,u=t1(Y(p=>L(p.id,p))(o.keyframes)),c=0<o.keyframes.length?N("Just",o.keyframes[0]):w,_=(()=>{if(c.tag==="Just")return c._1.id;if(c.tag==="Nothing")return"";g()})(),l=tx(o),f=p=>({startT:p.runStart,endT:p.t,path:r,layout:s,placement:a,windows:p.runWindows,spans:p.runSpans,keyframes:u,initialKeyframe:_,edgeEndpoints:l}),d=p=>({segments:p.runSpans.length===0?p.segments:St(p.segments)(f(p)),spans:p.spans,windows:p.windows,dives:p.dives}),h=J(p=>x=>{if(x.tag==="EnterNode"){const b=d(p),C=p.runSpans.length===0?{...b,segments:St(b.segments)(f(p))}:b,S=p.t+t.diveDur,P=St(r)(x._1),F=Zp(t)(e)(nS(n)(x._1))(P)(XL(o)(x._1))(S),W=F.endT+t.retreatDur;return{...p,t:W,runStart:W,runSpans:[],runWindows:[],segments:[...C.segments,...F.segments],spans:[...C.spans,...F.spans],windows:[...C.windows,...F.windows],dives:[...C.dives,{startT:p.t,endT:S,node:x._1,parentPath:r,childPath:P,direction:Mx},...F.dives,{startT:F.endT,endT:W,node:x._1,parentPath:r,childPath:P,direction:Ox}]}}if(x.tag==="ExitNode")return p;const y=p.t+dS(t)(s)(u)(l)(x),T={startT:p.t,endT:y,scene:x},v=_S(t)(s)(u)(l)(T);return{...p,t:y,runSpans:St(p.runSpans)(T),runWindows:[...p.runWindows,...v],spans:St(p.spans)(T),windows:[...p.windows,...v]}})({t:i,runStart:i,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(o.scenes),m=d(h);return{endT:h.t,spans:m.spans,windows:Rt(p=>x=>at.compare(p.startT)(x.startT))(m.windows),segments:m.segments,dives:m.dives}},lS=t=>e=>{const n=at.compare(t.time)(e.time);return n==="EQ"?A.compare(t.id)(e.id):n},Vn=t=>e=>e-J(n=>r=>n+Gn(0)($p(e)(r.endT)-r.startT))(0)(t),hS=t=>e=>{const n=Gn(t.startT)(e.startT),r=$p(t.endT)(e.endT);return r>n+1e-4?N("Just",{startT:n,endT:r}):w},pS=t=>e=>{if(e.scene.tag==="Structural"){const n=J(r=>o=>({cursor:Gn(r.cursor)(o.endT),cuts:o.startT>r.cursor+1e-4?St(r.cuts)({startT:r.cursor,endT:o.startT}):r.cuts}))({cursor:e.startT,cuts:[]})(Rt(r=>o=>at.compare(r.startT)(o.startT))(wt(hS(e))(t)));return e.endT>n.cursor+1e-4?St(n.cuts)({startT:n.cursor,endT:e.endT}):n.cuts}return[]},mS=t=>{const e=VL(Et(t.spans)(pS(t.windows)));return e.length===0?t:{...t,endT:Vn(e)(t.endT),spans:Y(n=>({...n,startT:Vn(e)(n.startT),endT:Vn(e)(n.endT)}))(t.spans),windows:Rt(n=>r=>at.compare(n.startT)(r.startT))(Y(n=>({...n,startT:Vn(e)(n.startT),endT:Vn(e)(n.endT)}))(t.windows)),segments:Y(n=>({...n,startT:Vn(e)(n.startT),endT:Vn(e)(n.endT),spans:Y(r=>({...r,startT:Vn(e)(r.startT),endT:Vn(e)(r.endT)}))(n.spans),windows:Rt(r=>o=>at.compare(r.startT)(o.startT))(Y(r=>({...r,startT:Vn(e)(r.startT),endT:Vn(e)(r.endT)}))(n.windows))}))(t.segments),dives:Y(n=>({...n,startT:Vn(e)(n.startT),endT:Vn(e)(n.endT)}))(t.dives)}},yS=t=>{const e=Y(jL)(t.segments);return mS({...t,segments:e,windows:Rt(n=>r=>at.compare(n.startT)(r.startT))(Et(e)(n=>n.windows))})},xS=t=>e=>n=>{const r=Gn(.05)(1-t-e),o=u=>{if(u<=0)return 0;if(u>=1)return 1;const c=t+u*r;return c<0?0:c>1?1:c},i=ML(n),a=Y(u=>nt(DL(1)(gn(u).length)))(i),s=Gn(1)(J(_r)(0)(a));return Wt(u=>c=>({lineIndex:u,text:c,start:o(J(_r)(0)(u<1?[]:At(0,u,a))/s),end:o(u>=0&&u<a.length?(J(_r)(0)(u<1?[]:At(0,u,a))+a[u])/s:(J(_r)(0)(u<1?[]:At(0,u,a))+1)/s)}))(i)},wS=t=>{const e=Gn(0)(t.window.endT-t.window.startT);return Y(n=>({...Up,id:"token:"+t.eventId+":line:"+ae(n.lineIndex),kind:"tokenLine",time:t.window.startT+n.start*e,endTime:t.window.startT+n.end*e,path:Vp(t.path),tokenIndex:t.tokenIndex,lineIndex:n.lineIndex,text:n.text,from:t.from,to:t.to}))(xS(t.holdPre)(t.holdPost)(t.labels))},TS=t=>Et(Wt(e=>n=>({path:n.path,eventId:n.eventId,window:n.window,from:n.from,to:n.to,labels:n.labels,holdPre:n.holdPre,holdPost:n.holdPost,tokenIndex:e}))(Et(t)(qL)))(wS),NS=t=>Wt(e=>n=>({...n,index:e}))(Rt(lS)([...Et(t.segments)(oS),...TS(t.segments)])),vS=t=>e=>{if(e.tag==="Structural")return wt(n=>n)([ku(e._1.from)(t)?w:N("Just",Eo("UnknownKeyframe",e._1.from)),ku(e._1.to)(t)?w:N("Just",Eo("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return wt(n=>n)([ku(e._1)(t)?w:N("Just",Eo("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...wt(n=>n)([ku(e._1.keyframe)(t)?w:N("Just",Eo("UnknownKeyframe",e._1.keyframe))]),...sS(e._1.events),...uS(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];if(e.tag==="StepScene")return[];g()},JS=t=>e=>{const n=Et(e)(vS(t));return n.length===0?It("Right",void 0):It("Left",n)},CS=t=>e=>n=>r=>{if(0<n.keyframes.length){const o=n.keyframes[0],i=t1(Y(s=>L(s.id,s))(n.keyframes)),a=JS(i)(n.scenes);return(()=>{if(a.tag==="Left"){const s=a._1;return u=>It("Left",s)}if(a.tag==="Right"){const s=a._1;return u=>u(s)}g()})()(()=>{const s=yS(Zp(e)(r)(r)([])(n)(0));return It("Right",{totalDuration:s.endT,windows:s.windows,spans:s.spans,keyframes:i,initialKeyframe:o.id,timing:e,layout:r.layout,cameraSpans:B1(t)(hx)(r.layout)(i)(s),cameraConfig:t,levelTree:r,segments:s.segments,dives:s.dives,cues:NS(s),seed:n.seed})})}return It("Left",[FL])},pi=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(o=>n(o._1)(o._2)),Apply0:()=>jp(t)}),jp=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>o=>i=>e.map(a=>L(r(a._1),a._2))(o(i))};return{apply:(()=>{const r=pi(t);return o=>i=>r.bind(o)(a=>r.bind(i)(s=>mi(t).pure(a(s))))})(),Functor0:()=>n}},mi=t=>({pure:e=>n=>t.Applicative0().pure(L(e,n)),Apply0:()=>jp(t)}),t0=t=>{const e={Applicative0:()=>mi(t),Bind1:()=>pi(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},sr=(t,e)=>({tag:"ParseError",_1:t,_2:e}),k=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),Su=(t,e,n)=>({tag:t,_1:e,_2:n}),bS=t=>Su("More",t),kS=t=>Su("Lift",t),LS={defer:t=>{const e=fy(t);return(n,r,o,i,a)=>dy(e)(n,r,o,i,a)}},e0={map:t=>e=>(n,r,o,i,a)=>r(s=>e(n,r,o,i,(u,c)=>r(_=>a(u,t(c)))))},SS={alt:t=>e=>(n,r,o,i,a)=>{const s=n._1,u=n._2;return r(c=>t(k(s,u,!1),r,o,(_,l)=>{const f=_._3;return r(d=>f?i(_,l):e(n,r,o,i,a))},a))},Functor0:()=>e0},ES=t=>{const e=t.Monad0();return n=>r=>{const o=i=>{let a=i,s=!0,u;for(;s;){const c=a();if(c.tag==="More"){a=c._1;continue}if(c.tag==="Lift"){s=!1,u=e.Bind1().Apply0().Functor0().map(rc)(c._1);continue}if(c.tag==="Stop"){s=!1,u=e.Applicative0().pure(Ti("Done",L(c._2,c._1)));continue}g()}return u};return t.tailRecM(o)(i=>r(n,bS,kS,(a,s)=>Su("Stop",a,It("Left",s)),(a,s)=>Su("Stop",a,It("Right",s))))}},Xn=(t,e,n,r,o)=>o(t,t._2),PS={index:0,line:1,column:1},n0=(t=>{const e=ES(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(Ka)(e(k(n,PS,!1))(r))})($m),Eu=(t,e,n,r,o)=>o(k(t._1,t._2,!0),void 0),r0={apply:t=>e=>(n,r,o,i,a)=>r(s=>t(n,r,o,i,(u,c)=>r(_=>{const l=n._3&&!u._3?k(u._1,u._2,!0):u;return e(l,r,o,i,(f,d)=>r(h=>a(l._3&&!f._3?k(f._1,f._2,!0):f,c(d))))}))),Functor0:()=>e0},o0={pure:t=>(e,n,r,o,i)=>i(e,t),Apply0:()=>r0},GS={bind:t=>e=>(n,r,o,i,a)=>r(s=>t(n,r,o,i,(u,c)=>r(_=>e(c)(n._3&&!u._3?k(u._1,u._2,!0):u,r,o,i,a)))),Apply0:()=>r0},AS={Applicative0:()=>o0,Bind1:()=>GS},Pu=t=>(e,n,r,o,i)=>n(a=>Xn(e,n,r,o,(s,u)=>n(c=>o(e._3&&!s._3?k(s._1,s._2,!0):s,sr(t,u))))),RS={empty:Pu("No alternative"),Alt0:()=>SS},DS={Applicative0:()=>o0,Plus1:()=>RS},Ue=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return o=>t.tailRecM(i=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(rc)(o))(r.pure(Ti("Done",void 0))))(a=>r.pure((()=>{if(a.tag==="Loop")return Ti("Loop",pt("Cons",a._1,i));if(a.tag==="Done")return Ti("Done",(s=>u=>{let c=s,_=u,l=!0,f;for(;l;){const d=c,h=_;if(h.tag==="Nil"){l=!1,f=d;continue}if(h.tag==="Cons"){c=pt("Cons",h._1,d),_=h._2;continue}g()}return f})(G)(i));g()})())))(G)})({tailRecM:t=>e=>(n,r,o,i,a)=>{const s=(u,c,_)=>t(c)(u,r,o,i,(l,f)=>{const d=u._3&&!l._3?k(l._1,l._2,!0):l;if(f.tag==="Loop")return _===0?r(h=>s(d,f._1,30)):s(d,f._1,_-1|0);if(f.tag==="Done")return a(d,f._1);g()});return s(n,e,30)},Monad0:()=>AS})(DS),mt=t=>e=>{const n=Pu("Expected "+e);return(r,o,i,a,s)=>{const u=r._1,c=r._2;return o(_=>t(k(u,c,!1),o,i,(l,f)=>{const d=l._3;return o(h=>d?a(l,f):n(r,o,i,a,s))},s))}},Po=t=>(e,n,r,o,i)=>{const a=e._3,s=e._1,u=e._2;return n(c=>{const _=(l,f)=>{const d=l._3;return n(h=>d?o(k(l._1,l._2,a),f):i(e,void 0))};return n(l=>n(f=>t(k(s,u,!1),n,r,(d,h)=>_(k(d._1,d._2,!1),h),(d,h)=>n(m=>n(p=>Pu("Negated parser succeeded")(d,n,r,_,(x,y)=>n(T=>i(d._3&&!x._3?k(x._1,x._2,!0):x,y))))))))})},FS=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return N("Just",n);if(r.tag==="Just")return N("Just",(o,i,a,s,u)=>{const c=o._1,_=o._2;return i(l=>n(k(c,_,!1),i,a,(f,d)=>{const h=f._3;return i(m=>h?s(f,d):r._1(o,i,a,s,u))},u))});g()})(w);return n=>{const r=e(n);if(r.tag==="Nothing")return Pu("No alternative");if(r.tag==="Just")return r._1;g()}},i0=t=>e=>n=>(r,o,i,a,s)=>o(u=>o(c=>o(_=>o(l=>t(r,o,i,a,(f,d)=>o(h=>o(m=>{const p=r._3&&!f._3?k(f._1,f._2,!0):f;return n(p,o,i,a,(x,y)=>o(T=>{const v=p._3&&!x._3?k(x._1,x._2,!0):x;return o(b=>o(C=>{const S=r._3&&!v._3?k(v._1,v._2,!0):v;return e(S,o,i,a,(P,F)=>o(W=>s(S._3&&!P._3?k(P._1,P._2,!0):P,y)))}))}))}))))))),Q_=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=Ix()(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)-lo(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},IS=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,c=o,_=i,l=Ns(c);if(l.tag==="Nothing"){a=!1,s=u;continue}if(l.tag==="Just"){r=l._1.tail===""?Q_(u)(l._1.head)(_):Q_(u)(l._1.head)(l._1.tail),o=l._1.tail,i=_;continue}g()}return s},Gt=t=>(e,n,r,o,i)=>{const a=Ns(e._1);if(a.tag==="Nothing")return o(e,sr("Unexpected EOF",e._2));if(a.tag==="Just"){if(a._1.head<0||a._1.head>65535)return o(e,sr("Expected Char",e._2));if(a._1.head>=0&&a._1.head<=65535){const s=s1(a._1.head);return t(s)?i(k(a._1.tail,Q_(e._2)(a._1.head)(a._1.tail),!0),s):o(e,sr("Predicate unsatisfied",e._2))}}g()},Ki=(t,e,n,r,o)=>t._1===""?o(k(t._1,t._2,!0),void 0):r(t,sr("Expected EOF",t._2)),BS=t=>(e,n,r,o,i)=>{const a=t(e._1);if(a.tag==="Left")return o(e,sr(a._1,e._2));if(a.tag==="Right")return i(k(a._1.remainder,IS(e._2)(a._1.consumed)(a._1.remainder),a._1.consumed!==""),a._1.value);g()},Le=t=>BS(e=>{const n=Zn(t)(e);return n.tag==="Just"?It("Right",{value:t,consumed:t,remainder:n._1}):It("Left","Expected "+Am(t))}),z_=Gt(t=>!0),a0=(t,e)=>({tag:t,_1:e}),s0=(t,e,n)=>({tag:t,_1:e,_2:n}),QS=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},u0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},zS=t=>e=>J(n=>r=>(()=>{if(n.tag==="Left"){const o=n._1;return i=>It("Left",o)}if(n.tag==="Right"){const o=n._1;return i=>i(o)}g()})()(o=>t(o)(r)))(It("Right",e)),c0=t=>e=>n=>QS(t)(n.values)?It("Right",{...n,values:it(A)(t)(e)(n.values)}):It("Left","label has no placeholder `"+t+"`"),g0=(()=>{const t=Po((e,n,r,o,i)=>{const a=e._3;return Le("{{")(e,n,r,(s,u)=>o(k(s._1,s._2,a),u),i)});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>z_(e._3&&!s._3?k(s._1,s._2,!0):s,n,r,o,i))))})(),MS=(()=>{const t=Po((e,n,r,o,i)=>{const a=e._3;return Le("}}")(e,n,r,(s,u)=>o(k(s._1,s._2,a),u),i)});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>z_(e._3&&!s._3?k(s._1,s._2,!0):s,n,r,o,i))))})(),Zi=t=>Wn("")(Y(e=>{if(e.tag==="LabelText")return e._1;if(e.tag==="LabelSlot"){const n=u0(e._1)(t.values);if(n.tag==="Just")return n._1;if(n.tag==="Nothing")return""}g()})(t.parts)),OS=(t,e,n,r,o)=>e(i=>g0(t,e,n,r,(a,s)=>e(u=>{const c=Ue(g0),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>c(_,e,n,r,(f,d)=>e(h=>o(_._3&&!f._3?k(f._1,f._2,!0):f,s0("ParsedText",Qn([s,...Ot(ue.foldr,d)]))))))}))),WS=t=>t===" "||t===" "||t===`
11
+ `||t==="\r",_0=(()=>{const t=Ue(Gt(WS));return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>i(s,void 0))))})(),qS=t=>t>="a"&&t<="z"||t>="A"&&t<="Z"||t==="_",HS=t=>t>="a"&&t<="z"||t>="A"&&t<="Z"||t==="_"||t>="0"&&t<="9"||t==="-",$S=(t,e,n,r,o)=>e(i=>Gt(qS)(t,e,n,r,(a,s)=>e(u=>{const c=Ue(Gt(HS)),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>c(_,e,n,r,(f,d)=>e(h=>o(_._3&&!f._3?k(f._1,f._2,!0):f,fr(s)+Qn(Ot(ue.foldr,d))))))}))),YS=(t,e,n,r,o)=>e(i=>Le("{{")(t,e,n,r,(a,s)=>e(u=>{const c=t._3&&!a._3?k(a._1,a._2,!0):a;return e(_=>_0(c,e,n,r,(l,f)=>e(d=>{const h=c._3&&!l._3?k(l._1,l._2,!0):l;return e(m=>$S(h,e,n,r,(p,x)=>e(y=>{const T=h._3&&!p._3?k(p._1,p._2,!0):p;return e(v=>_0(T,e,n,r,(b,C)=>e(S=>{const P=mt(Gt(W=>W===":"))("':'"),F=T._3&&!b._3?k(b._1,b._2,!0):b;return e(W=>P(F,e,n,r,(E,R)=>e(et=>{const rt=Ue(MS),$=F._3&&!E._3?k(E._1,E._2,!0):E;return e(X=>e(V=>rt($,e,n,r,(D,B)=>e(I=>{const M=Qn(Ot(ue.foldr,B));return e(j=>{const z=$._3&&!D._3?k(D._1,D._2,!0):D;return e(q=>Le("}}")(z,e,n,r,(H,O)=>e(ot=>o(z._3&&!H._3?k(H._1,H._2,!0):H,s0("ParsedSlot",x,da(M))))))})}))))})))})))})))})))}))),VS=(()=>{const t=Ue((e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>YS(k(a,s,!1),n,r,(c,_)=>{const l=c._3;return n(f=>l?o(c,_):OS(e,n,r,o,i))},i))});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>i(s,Ot(ue.foldr,u)))))})(),XS=t=>{const e=zS(n=>r=>{if(r.tag==="ParsedText")return It("Right",{...n,parts:St(n.parts)(a0("LabelText",r._1))});if(r.tag==="ParsedSlot"){const o=u0(r._1)(n.values);return o.tag==="Just"&&o._1!==r._2?It("Left","placeholder `"+r._1+"` has conflicting initial values"):It("Right",{parts:St(n.parts)(a0("LabelSlot",r._1)),values:it(A)(r._1)(r._2)(n.values)})}g()})({parts:[],values:Q})(t);if(e.tag==="Left")return It("Left",e._1);if(e.tag==="Right")return It("Right",e._1);g()},Gu=t=>{const e=n0(t)((n,r,o,i,a)=>r(s=>r(u=>VS(n,r,o,i,(c,_)=>r(l=>r(f=>{const d=n._3&&!c._3?k(c._1,c._2,!0):c;return Ki(d,r,o,i,(h,m)=>r(p=>a(d._3&&!h._3?k(h._1,h._2,!0):h,_)))}))))));if(e.tag==="Left")return It("Left",e._1._1);if(e.tag==="Right")return XS(e._1);g()},yi=(t,e)=>({tag:t,_1:e}),Br=(t,e)=>({tag:t,_1:e}),Au=t=>t,Un=(t,e)=>({tag:t,_1:e}),M_=t=>t,f0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},US=ge(A)(Qt),d0=(()=>{const t=wn.unfoldr(e=>{if(e.tag==="Nil")return w;if(e.tag==="Cons")return N("Just",L(e._1,e._2));g()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,pt("Cons",r._3,n(r._6,o)));g()};return n(e,G)})())})(),ke=t0(In),KS=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ZS=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},jS=ge(A)(Qt),O_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},t4=J(t=>e=>it(A)(e)()(t))(Q),$t=pi(In),Ke=ke.state(t=>L(t,t)),pe=mi(In),l0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},h0=co(pe),W_=h0(Qt),e4=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},mr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},yr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},n4=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},Ru=t=>e=>n=>J(r=>o=>t.Bind1().bind(r)(i=>e(i)(o)))(t.Applicative0().pure(n)),r4=J(t=>e=>it(A)(e)()(t))(Q),o4=(()=>{const t=(e=>n=>{let r=e,o=n,i=!0,a;for(;i;){const s=r,u=o;if(u.tag==="Nil"){i=!1,a=s;continue}if(u.tag==="Cons"){r=it(A)(u._1)()(s),o=u._2;continue}g()}return a})(Q);return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,pt("Cons",r._3,n(r._6,o)));g()};return n(e,G)})())})(),i4=J(t=>e=>it(A)(e)()(t))(Q),a4=h0(pf),s4=M_("AnimatedSurface"),u4=M_("StillSurface"),c4=M_("SequenceSurface"),g4=Un("Exit"),Du=Au("AnimatedKeyframe"),q_=Au("Still"),_4=Au("Title"),p0=Au("StepMarker"),f4=t=>Br("Par",t),d4=t=>Br("Seq",t),l4=t=>Br("GroupSeq",t),m0=t=>yi("StepDive",t),h4={line:0,column:0,endLine:0,endColumn:0},p4=t=>e=>n=>{const r=Mr(Yt,w,o=>o._1===t,n);if(r.tag==="Just"){const o=fo(Yt,w,r._1,L(t,e),n);if(o.tag==="Nothing")return n;if(o.tag==="Just")return o._1;g()}if(r.tag==="Nothing")return St(n)(L(t,e));g()},m4=t=>e=>Y(n=>n._1===t?L(n._1,{...n._2,label:N("Just",e)}):L(n._1,n._2)),y0=t=>US(wt(e=>{const n=f0(e)(t.currLabels);return n.tag==="Just"?N("Just",L(e,n._1)):w})(d0(t.currNodes))),x0=t=>{const e=t.compare;return n=>J(r=>o=>Oe(e,Qe,r,n(o)))(Q)},H_=x0(A),$_=x0(A),w0=t=>e=>ke.state(n=>L(void 0,{...n,graphNodes:m4(t)(Zi(e))(n.graphNodes),currLabels:it(A)(t)(Zi(e))(n.currLabels),currLabelTemplates:it(A)(t)(e)(n.currLabelTemplates)})),y4=t=>{const e=t.span;return ke.state(n=>L(void 0,{...n,currentSpan:e}))},x4=nt(4)*8,w4=t=>t.tag==="Just"&&ja(t._1)&&t._1>0?L(KS(1)(t._1/x4),1):L(1,1),T4=t=>e=>({structural:[...t.structural,...e.structural],flow:t.flow||e.flow,dives:[...t.dives,...e.dives]}),N4=t=>e=>e.kind==="Animated"||ZS(e.id)(t),T0={graphNodes:[],graphEdges:Q,currNodes:Q,currEdges:Q,currLabels:Q,currLabelTemplates:Q,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:w,currentSpan:h4,error:w,enterStack:[],interiorOf:Q,stepNames:Q},N0=t=>e=>n=>{const r=Ot(pn.foldr,n);return Wn(", ")(Y(e)(At(0,6,r)))+(r.length>6?", \u2026":"")},v4=t=>e=>{const n=O_(e)(jS(Y(r=>L(r.id,r))(t.graph.edges)));if(n.tag==="Just")return(()=>{const r=Zn("conn:")(n._1.id);if(r.tag==="Just")return!1;if(r.tag==="Nothing")return!0;g()})()?n._1.from.node+" -> "+n._1.to.node:n._1.from.node+" -- "+n._1.to.node;if(n.tag==="Nothing")return e;g()},J4=t=>e=>n=>{const r=N0()(ea)(e),o=N0()(v4(t))(n);return(r===""?"animated flow contains unused topology: every animated node or edge must be visited by a token or fill.":"animated flow contains unused topology: every animated node or edge must be visited by a token or fill. Unused nodes: "+r+".")+(o===""?"":" Unused edges: "+o+".")+" Move context-only topology into a `still`/`title`, remove it, or add token/fill events."},C4=t=>{if(t.kind.tag==="SendToken")return t4([t.kind._1.from,t.kind._1.to]);if(t.kind.tag==="FillNodeWithoutTransition")return ee("Node",1,1,t.kind._1.node,void 0,Q,Q);g()},b4=t=>H_(C4)(t.events),k4=t=>{if(t.kind.tag==="SendToken")return ee("Node",1,1,t.kind._1.edge,void 0,Q,Q);if(t.kind.tag==="FillNodeWithoutTransition")return Q;g()},L4=t=>$_(k4)(t.events),xr=t=>ke.state(e=>L(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:N("Just",{msg:t,line:e.currentSpan.line,column:e.currentSpan.column,endLine:e.currentSpan.endLine,endColumn:e.currentSpan.endColumn})};g()})())),S4=W_(t=>$t.bind(Ke)(e=>{if(e.error.tag==="Just")return pe.pure();if(e.error.tag==="Nothing")return l0(t.node)(e.interiorOf)?xr("node "+t.node+" has more than one `inside` block"):ke.state(n=>L(void 0,{...n,interiorOf:it(A)(t.node)(t.doc)(n.interiorOf)}));g()})),E4=t=>$t.bind(Ke)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ae(e.kfCounter);if(ne(o=>o.id===n,e.keyframes))return xr("duplicate frame name "+n);const r={...e,keyframes:St(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges,labels:y0(e),kind:ca}),kfCounter:e.kfCounter+1|0,currentKf:N("Just",n)};return ke.state(o=>L(void 0,r))}),We=t=>e=>$t.bind(ke.state(n=>L(void 0,{...n,currentSpan:t})))(()=>xr(e)),v0=t=>e=>$t.bind(Ke)(n=>e4(e)(n.stepNames)?We(t)("duplicate step name "+e):ke.state(r=>L(void 0,{...r,scenes:St(r.scenes)(Pi("StepScene",e)),stepNames:it(A)(e)()(r.stepNames)}))),P4=t=>{if(t.ops.tag==="Leaf"){const e=t.ops._1;return $t.bind((()=>{const n=e.span;return ke.state(r=>L(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?v0(e.span)(e.op._1.name):xr("step marker frame did not contain a step"))}if(t.ops.tag==="Seq"&&t.ops._1.length===1&&t.ops._1[0].tag==="Leaf"){const e=t.ops._1[0]._1;return $t.bind((()=>{const n=e.span;return ke.state(r=>L(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?v0(e.span)(e.op._1.name):xr("step marker frame did not contain a step"))}return xr("step marker frame did not contain a step")},G4=t=>$t.bind((()=>{const e=t.span;return ke.state(n=>L(void 0,{...n,currentSpan:e}))})())(()=>$t.bind(Ke)(e=>{if(e.error.tag==="Just")return pe.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!mr(t.op._1.id)(e.currNodes))return We(0<t.operands.length?t.operands[0]:t.span)("cannot dive into node "+t.op._1.id+": does not exist");if(!l0(t.op._1.id)(e.interiorOf))return We(0<t.operands.length?t.operands[0]:t.span)("cannot enter node "+t.op._1.id+": it has no `inside` block. Add the block at the document level, alongside the animated statements:\n\ninside "+t.op._1.id+` {
12
12
  + detail: Detail
13
- }`);const n=t.op._1;return Ce.state(r=>L(void 0,{...r,enterStack:St(r.enterStack)(n.id),scenes:St(r.scenes)(ki("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=zr(e.enterStack);if(n.tag==="Nothing")return mr("`out` without a matching `into`");if(n.tag==="Just"){const r=n._1.init;return Ce.state(o=>L(void 0,{...o,enterStack:r,scenes:St(o.scenes)(sx)}))}_()}return he.pure()}_()})),Qu={structural:[],flow:!1,dives:[]},ME=qt.bind(Ve)(t=>{if(t.error.tag==="Just")return he.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return Ce.state(n=>L(void 0,{...n,scenes:St(n.scenes)(ki("Hold",e))}))}if(t.currentKf.tag==="Nothing")return he.pure()}_()}),zE=t=>e=>qt.bind(Ve)(n=>{const r="ev-"+ae(n.eventCounter);return qt.bind((()=>{const o={...n,eventCounter:n.eventCounter+1|0};return Ce.state(i=>L(void 0,o))})())(()=>he.pure({events:[{id:r,kind:e,when:t}],firstId:T("Just",r),lastId:T("Just",r)}))}),QE=t=>t.tag==="DataFlow"?T("Just",t._1):w,WE=t=>wt(e=>Y_(e)(t.graphEdges))(Wt(mi,y0(t.currEdges))),OE=t=>e=>{const n=dt(o=>o.from.node===e.id||o.to.node===e.id,WE(t)),r=Mu(Cf)(o=>i=>{const a=i.from+"->"+e.id,s=e.id+"->"+i.to,u=i.from+"->"+i.to,c="via "+i.from+" "+i.to+": no edge "+i.from+"\u2192"+e.id;if(!pr(a)(t.currEdges))return It("Left",c);const g="via "+i.from+" "+i.to+": no edge "+e.id+"\u2192"+i.to;if(!pr(s)(t.currEdges))return It("Left",g);const l="via "+i.from+" "+i.to+": would create "+i.from+"\u2192"+i.to+" but it already exists";return pr(u)(t.currEdges)||uE(u)(o.synthesized)?It("Left",l):It("Right",{consumed:it(P)(a)()(it(P)(s)()(o.consumed)),synthesized:it(P)(u)({id:u,from:{node:i.from,port:w},to:{node:i.to,port:w},label:w})(o.synthesized)})})({consumed:M,synthesized:M})(e.via);return(()=>{if(r.tag==="Left"){const o=r._1;return i=>It("Left",o)}if(r.tag==="Right"){const o=r._1;return i=>i(o)}_()})()(o=>{const i=o.consumed,a=dt(s=>!pr(s.id)(i),n);return a.length===0?It("Right",{nextCurrEdges:Qe(P.compare,Be,ar(P.compare,t.currEdges,cE(U(s=>s.id)(n))),gE((()=>{const s=u=>{if(u.tag==="Leaf")return M;if(u.tag==="Node")return ee("Node",u._1,u._2,u._3,void 0,s(u._5),s(u._6));_()};return s(o.synthesized)})())),synthesized:o.synthesized}):It("Left","cannot delete node "+e.id+": still connected ("+Qn(", ")(U(s=>(()=>{const u=Yn("conn:")(s.id);if(u.tag==="Just")return!1;if(u.tag==="Nothing")return!0;_()})()?s.from.node+"\u2192"+s.to.node:s.from.node+"--"+s.to.node)(a))+"). Use `- a -> b` or `- a -- b` to drop them, or `via a b` to merge "+e.id+"'s endpoints.")})},S0=t=>e=>n=>{if(t){if(e){const i=0<n.operands.length?n.operands[0]:n.span,a=1<n.operands.length?n.operands[1]:n.span;return{line:i.line,column:i.column,endLine:a.endLine,endColumn:a.endColumn}}return 0<n.operands.length?n.operands[0]:n.span}if(e)return 1<n.operands.length?n.operands[1]:n.span;const r=0<n.operands.length?n.operands[0]:n.span,o=1<n.operands.length?n.operands[1]:n.span;return{line:r.line,column:r.column,endLine:o.endLine,endColumn:o.endColumn}},E0=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq"||t.tag==="GroupSeq")return Et(t._1)(E0);_()},HE=t=>({nodes:U(rs)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,yt("Cons",n._4,e(n._6,r)));_()};return Wt(ue.foldr,e(t.graphEdges,R))})(),constraints:[]}),ef=t=>{if(t.tag==="Leaf")return t._1.op.tag==="AddNode"||t._1.op.tag==="DelNode"||t._1.op.tag==="ModNode"||t._1.op.tag==="ModNodeSlot"||t._1.op.tag==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?{...Qu,structural:[t._1]}:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?{...Qu,dives:[t._1]}:{...Qu,flow:!0};if(t.tag==="Seq"||t.tag==="GroupSeq"||t.tag==="Par")return b(kE)(Qu)(U(ef)(t._1));_()},Wu=t=>{if(t.tag==="Leaf")return t._1.op.tag==="AddNode"||t._1.op.tag==="DelNode"||t._1.op.tag==="ModNode"||t._1.op.tag==="ModNodeSlot"||t._1.op.tag==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?[_i("StepStructural",[t._1])]:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?[_i("StepDive",t._1)]:[_i("StepFlow",t)];if(t.tag==="Seq")return Et(t._1)(Wu);if(t.tag==="GroupSeq")return qE(t)(t._1);if(t.tag==="Par")return $E(t)(t._1);_()},$E=t=>e=>{const n=ef(t);return n.structural.length!==0&&!n.flow&&n.dives.length===0?[_i("StepStructural",n.structural)]:n.structural.length===0&&n.flow&&n.dives.length===0?[_i("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?U(T0)(n.dives):Et(e)(Wu)},qE=t=>e=>{const n=ef(t);return n.structural.length===0&&n.flow&&n.dives.length===0?[_i("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?U(T0)(n.dives):Et(e)(Wu)},UE=t=>e=>qt.bind(Ve)(n=>{const r=e.from+"->"+e.to,o=e.newFrom+"->"+e.newTo;return pr(r)(n.currEdges)?hr(e.newFrom)(n.currNodes)?hr(e.newTo)(n.currNodes)?r!==o&&pr(o)(n.currEdges)?We((()=>{const i=2<t.operands.length?t.operands[2]:t.span,a=3<t.operands.length?t.operands[3]:t.span;return{line:i.line,column:i.column,endLine:a.endLine,endColumn:a.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists"):Ce.state(i=>L(void 0,{...i,currEdges:it(P)(o)()(bi(P)(r)(i.currEdges)),graphEdges:it(P)(o)({id:o,from:{node:e.newFrom,port:w},to:{node:e.newTo,port:w},label:w})(i.graphEdges)})):We(3<t.operands.length?t.operands[3]:t.span)("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo):We(2<t.operands.length?t.operands[2]:t.span)("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newFrom):We((()=>{const i=0<t.operands.length?t.operands[0]:t.span,a=1<t.operands.length?t.operands[1]:t.span;return{line:i.line,column:i.column,endLine:a.endLine,endColumn:a.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist")}),XE=t=>e=>{const n=wt(QE)(e.scenes),r=dt(LE(_E(U(a=>a.keyframe)(n))),e.keyframes),o=ar(P.compare,Z_(a=>a.nodes)(r),Z_(PE)(n)),i=ar(P.compare,tf(a=>a.edges)(r),tf(GE)(n));return t!=="AnimatedSurface"||n.length===0||o.tag==="Leaf"&&i.tag==="Leaf"?w:T("Just",EE(e)(o)(i))},VE=t=>e=>{const n=e.to+"->"+e.from,r=e.from+"->"+e.to,o=e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;if(pr(r)(t.currEdges))return T("Just",{id:r,direction:_1});if(pr(n)(t.currEdges))return T("Just",{id:n,direction:f1});const i=Y_(o)(t.graphEdges);if(i.tag==="Just")return pr(o)(t.currEdges)?T("Just",{id:o,direction:i._1.from.node===e.from&&i._1.to.node===e.to?_1:f1}):w;if(i.tag==="Nothing")return w;_()},YE=t=>e=>{if(e.op.tag==="Token"){const n=e.op._1;return qt.bind(Ve)(r=>{const o=!hr(n.from)(r.currNodes),i=!hr(n.to)(r.currNodes);if(o||i)return qt.bind(We(S0(o)(i)(e))(o?i?"token references unknown node: "+n.from+", "+n.to:"token references unknown node: "+n.from:i?"token references unknown node: "+n.to:"token references unknown node: "))(()=>he.pure({events:[],firstId:w,lastId:w}));const a=VE(r)(n);if(a.tag==="Just")return zE(t)(rx("SendToken",{from:n.from,to:n.to,edge:a._1.id,direction:a._1.direction,labels:n.labels}));if(a.tag==="Nothing")return qt.bind(We((()=>{const s=0<e.operands.length?e.operands[0]:e.span,u=1<e.operands.length?e.operands[1]:e.span;return{line:s.line,column:s.column,endLine:u.endLine,endColumn:u.endColumn}})())("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>he.pure({events:[],firstId:w,lastId:w}));_()})}return he.pure({events:[],firstId:w,lastId:w})},KE=t=>e=>{const n=At(r=>w,r=>o=>T("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return he.pure({events:[],firstId:w,lastId:w});if(n.tag==="Just"){const r=n._1.tail;return qt.bind(Va(t)(n._1.head))(o=>qt.bind(Mu({Applicative0:()=>gi(Gn),Bind1:()=>ci(Gn)})(i=>a=>qt.bind(Va((()=>{if(i.lastId.tag==="Just")return zc("After",i.lastId._1);if(i.lastId.tag==="Nothing")return t;_()})())(a))(s=>he.pure({events:[...i.events,...s.events],firstId:(()=>{if(i.firstId.tag==="Just")return T("Just",i.firstId._1);if(i.firstId.tag==="Nothing")return s.firstId;_()})(),lastId:(()=>{if(s.lastId.tag==="Just")return T("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return i.lastId;_()})()})))(o)(r))(i=>he.pure(i)))}_()},jE=t=>e=>{const n=At(r=>w,r=>o=>T("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return he.pure({events:[],firstId:w,lastId:w});if(n.tag==="Just"){const r=n._1.tail;return qt.bind(Va(t)(n._1.head))(o=>qt.bind(ZE((()=>{if(o.firstId.tag==="Just")return zc("With",o.firstId._1);if(o.firstId.tag==="Nothing")return t;_()})())(r))(i=>he.pure({events:[...o.events,...i.events],firstId:o.firstId,lastId:(()=>{if(o.lastId.tag==="Just")return T("Just",o.lastId._1);if(o.lastId.tag==="Nothing")return i.lastId;_()})()})))}_()},Va=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return qt.bind((()=>{const r=n.span;return Ce.state(o=>L(void 0,{...o,currentSpan:r}))})())(()=>YE(t)(n))}if(e.tag==="Seq"||e.tag==="GroupSeq")return KE(t)(e._1);if(e.tag==="Par")return jE(t)(e._1);_()},ZE=t=>Mu({Applicative0:()=>gi(Gn),Bind1:()=>ci(Gn)})(e=>n=>qt.bind(Va(t)(n))(r=>he.pure({events:[...e.events,...r.events],firstId:(()=>{if(e.firstId.tag==="Just")return T("Just",e.firstId._1);if(e.firstId.tag==="Nothing")return r.firstId;_()})(),lastId:(()=>{if(r.lastId.tag==="Just")return T("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;_()})()})))({events:[],firstId:w,lastId:w}),t4=t=>qt.bind(Ve)(e=>{if(e.currentKf.tag==="Nothing")return mr("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return qt.bind(Va(ax)(t))(r=>qt.bind(Ve)(o=>{const i={...o,scenes:St(o.scenes)(ki("DataFlow",{keyframe:n,events:r.events,focus:w}))};return Ce.state(a=>L(void 0,i))}))}_()}),e4=t=>e=>Ce.state(n=>L(void 0,{...n,graphNodes:TE(t.id)({id:t.id,size:CE(t.width),ports:[],label:T("Just",Yi(e)),shape:t.shape})(n.graphNodes),currNodes:it(P)(t.id)()(n.currNodes),currLabels:it(P)(t.id)(Yi(e))(n.currLabels),currLabelTemplates:it(P)(t.id)(e)(n.currLabelTemplates)})),n4=t=>{if(t.op.tag==="AddNode"){const e=t.op._1;return qt.bind(Ve)(n=>{if(hr(e.id)(n.currNodes))return We(0<t.operands.length?t.operands[0]:t.span)("cannot add node "+e.id+": already exists");const r=Iu(e.label);if(r.tag==="Left")return We(0<t.operands.length?t.operands[0]:t.span)("invalid label for node "+e.id+": "+r._1);if(r.tag==="Right")return e4(e)(r._1);_()})}if(t.op.tag==="DelNode"){const e=t.op._1;return qt.bind(Ve)(n=>{if(!hr(e.id)(n.currNodes))return We(0<t.operands.length?t.operands[0]:t.span)("cannot delete node "+e.id+": does not exist");const r=OE(n)(e);if(r.tag==="Left")return We(0<t.operands.length?t.operands[0]:t.span)(r._1);if(r.tag==="Right"){const o=r._1;return Ce.state(i=>L(void 0,{...i,currNodes:bi(P)(e.id)(i.currNodes),currEdges:o.nextCurrEdges,graphEdges:Qe(P.compare,Be,o.synthesized,i.graphEdges)}))}_()})}if(t.op.tag==="ModNode"){const e=t.op._1;return qt.bind(Ve)(n=>{if(!hr(e.id)(n.currNodes))return We(0<t.operands.length?t.operands[0]:t.span)("cannot relabel node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=Iu(e.label._1);if(r.tag==="Left")return We(0<t.operands.length?t.operands[0]:t.span)("invalid label for node "+e.id+": "+r._1);if(r.tag==="Right")return J0(e.id)(r._1);_()}if(e.label.tag==="Nothing")return he.pure();_()})}if(t.op.tag==="ModNodeSlot"){const e=t.op._1;return qt.bind(Ve)(n=>{if(!hr(e.id)(n.currNodes))return We(0<t.operands.length?t.operands[0]:t.span)("cannot update placeholder on node "+e.id+": does not exist");const r=m0(e.id)(n.currLabelTemplates);if(r.tag==="Nothing")return We(1<t.operands.length?t.operands[1]:t.span)("node "+e.id+" label has no placeholder `"+e.slot+"`");if(r.tag==="Just"){const o=d0(e.slot)(e.value)(r._1);if(o.tag==="Left")return We(1<t.operands.length?t.operands[1]:t.span)("node "+e.id+" "+o._1);if(o.tag==="Right")return J0(e.id)(o._1)}_()})}if(t.op.tag==="AddEdge"){const e=t.op._1;return qt.bind(Ve)(n=>{const r=!hr(e.from)(n.currNodes),o=!hr(e.to)(n.currNodes);if(r||o)return We(S0(r)(o)(t))((e.directed?"cannot add edge ":"cannot add connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": unknown node "+(r?o?e.from+", "+e.to:e.from:o?e.to:""));const i=e.directed?e.from+"->"+e.to:e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;return pr(i)(n.currEdges)?We((()=>{const a=0<t.operands.length?t.operands[0]:t.span,s=1<t.operands.length?t.operands[1]:t.span;return{line:a.line,column:a.column,endLine:s.endLine,endColumn:s.endColumn}})())((e.directed?"cannot add edge ":"cannot add connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": already exists"):Ce.state(a=>L(void 0,{...a,graphEdges:it(P)(i)({id:i,from:{node:e.from,port:w},to:{node:e.to,port:w},label:e.label})(a.graphEdges),currEdges:it(P)(i)()(a.currEdges)}))})}if(t.op.tag==="DelEdge"){const e=t.op._1;return qt.bind(Ve)(n=>{const r=e.directed?e.from+"->"+e.to:e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;return pr(r)(n.currEdges)?Ce.state(o=>L(void 0,{...o,currEdges:bi(P)(r)(o.currEdges)})):We((()=>{const o=0<t.operands.length?t.operands[0]:t.span,i=1<t.operands.length?t.operands[1]:t.span;return{line:o.line,column:o.column,endLine:i.endLine,endColumn:i.endColumn}})())((e.directed?"cannot delete edge ":"cannot delete connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": does not exist")})}return t.op.tag==="RepointEdge"?UE(t)(t.op._1):he.pure()},r4=t=>qt.bind((()=>{const e=t.span;return Ce.state(n=>L(void 0,{...n,currentSpan:e}))})())(()=>n4(t)),A0=t=>e=>n=>qt.bind(K_(r4)(n))(()=>qt.bind(Ve)(r=>{const o=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ae(r.kfCounter);if(ne(a=>a.id===o,r.keyframes))return qt.bind(fE(bE)(0<n.length?T("Just",n[0]):w))(()=>mr("duplicate frame name "+o));const i={...r,keyframes:St(r.keyframes)({id:o,nodes:r.currNodes,edges:r.currEdges,labels:v0(r),kind:t}),kfCounter:r.kfCounter+1|0,currentKf:T("Just",o),scenes:(()=>{if(r.currentKf.tag==="Nothing")return r.scenes;if(r.currentKf.tag==="Just")return St(r.scenes)(ki("Structural",{from:r.currentKf._1,to:o,focus:w}));_()})()};return Ce.state(a=>L(void 0,i))})),o4=t=>e=>n=>{if(n.tag==="StepStructural")return qt.bind((()=>{const r=A0(ca)(e?w:t)(n._1);return n._1.length!==0?r:he.pure()})())(()=>he.pure(!0));if(n.tag==="StepFlow"){const r=n._1,o=!e&&(()=>{if(t.tag==="Just")return t._1!=="";if(t.tag==="Nothing")return!1;_()})();return qt.bind((()=>{const i=FE(t);return o?i:he.pure()})())(()=>qt.bind(t4(r))(()=>he.pure(e||o)))}if(n.tag==="StepDive")return qt.bind(BE(n._1))(()=>he.pure(e));_()},P0=t=>e=>n=>{const r=At(o=>w,o=>i=>T("Just",{head:o,tail:i}),n);if(r.tag==="Nothing")return he.pure();if(r.tag==="Just"){const o=r._1.head,i=r._1.tail;return qt.bind(Ve)(a=>{if(a.error.tag==="Just")return he.pure();if(a.error.tag==="Nothing")return qt.bind(o4(t)(e)(o))(s=>P0(t)(s)(i));_()})}_()},R0=t=>e=>{const n=E0(e.ops),r=dt(i=>i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="ModNodeSlot"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge",n),o=dt(i=>!(i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="ModNodeSlot"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge"),n);return 0<o.length?qt.bind((()=>{const i=o[0].span;return Ce.state(a=>L(void 0,{...a,currentSpan:i}))})())(()=>mr("still/title blocks hold a still snapshot; they cannot contain movement tokens (`api ~> db`) or dive commands (`into`/`out`)")):t==="TitleCard"&&r.length===0?mr(e.name.tag==="Just"&&e.name._1!==""?'title "'+e.name._1+'" has an empty body; give it nodes/edges to title, or use a still':"title has an empty body; give it nodes/edges to title, or use a still"):qt.bind(A0(t)(e.name)(r))(()=>ME)},i4=t=>qt.bind(Ve)(e=>{if(e.error.tag==="Just")return he.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return P0(t.name)(!1)(Wu(t.ops));if(t.kind==="Still")return R0(ox)(t);if(t.kind==="Title")return R0(ix)(t);if(t.kind==="StepMarker")return IE(t)}_()}),G0=t=>qt.bind(DE(t.interiors))(()=>qt.bind(K_(i4)(t.frames))(()=>qt.bind(Ve)(e=>{if(e.error.tag==="Just")return he.pure(It("Left",e.error._1));if(e.error.tag==="Nothing"){const n=a4(t.interiors);if(n.tag==="Left")return he.pure(It("Left",n._1));if(n.tag==="Right"){const r={seed:t.seed,graph:HE(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1};return he.pure((()=>{const o=XE(t.mode)(r);if(o.tag==="Just")return It("Left",{msg:o._1,line:0,column:0,endLine:0,endColumn:0});if(o.tag==="Nothing")return It("Right",r);_()})())}}_()}))),a4=t=>{const e=Mu(Cf)(n=>r=>{const o=G0(r.doc)(C0)._1;return(()=>{if(o.tag==="Left"){const i=o._1;return a=>It("Left",i)}if(o.tag==="Right"){const i=o._1;return a=>a(i)}_()})()(i=>It("Right",it(P)(r.node)(i)(n)))})(M)(t);if(e.tag==="Left")return It("Left",e._1);if(e.tag==="Right")return It("Right",e._1);_()},Ou=(t,e)=>({tag:t,_1:e}),nf=WS(Mt),s4=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},u4=ge(P)(Mt),D0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Ya=(()=>{const t=pt(Pt(r=>r==="}"))("'}'"),e=pt(Pt(r=>r==="#"))("'#'"),n=Pt(r=>r===`
14
- `||r==="\r");return(r,o,i,a,s)=>{const u=r._1,c=r._2;return o(g=>o(l=>t(C(u,c,!1),o,i,(d,f)=>o(h=>{const m=r._1,p=r._2;return o(x=>o(y=>e(C(m,p,!1),o,i,(N,v)=>o(J=>{const k=r._1,S=r._2;return o(A=>o(I=>n(C(k,S,!1),o,i,($,E)=>o(G=>Vi(r,o,i,a,s)),($,E)=>o(G=>s(C(k,S,!1),void 0)))))}),(N,v)=>o(J=>s(C(m,p,!1),void 0)))))}),(d,f)=>o(h=>s(C(u,c,!1),void 0)))))}})(),Nn=t=>(e,n,r,o,i)=>n(a=>Un(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?C(s._1,s._2,!0):s;return n(l=>t(g,n,r,o,(d,f)=>n(h=>{const m=g._3&&!d._3?C(d._1,d._2,!0):d;return n(p=>Un(m,n,r,o,(x,y)=>n(N=>i(m._3&&!x._3?C(x._1,x._2,!0):x,L(f,{line:u.line,column:u.column,endLine:y.line,endColumn:y.column})))))})))}))),c4=(()=>{const t=Pt(e=>e===" "||e===" "||e===`
15
- `||e==="\r");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>i(e._3&&!s._3?C(s._1,s._2,!0):s,void 0))))})(),F0=(t,e,n,r,o)=>e(i=>Le("#")(t,e,n,r,(a,s)=>e(u=>{const c=Xe(Pt(l=>l!==`
16
- `)),g=t._3&&!a._3?C(a._1,a._2,!0):a;return e(l=>c(g,e,n,r,(d,f)=>e(h=>o(g._3&&!d._3?C(d._1,d._2,!0):d,void 0))))}))),I0=pt((()=>{const t=pt(Pt(n=>n==="}"))("'}'"),e=Pt(n=>n===`
17
- `||n==="\r");return(n,r,o,i,a)=>{const s=n._1,u=n._2;return r(c=>r(g=>t(C(s,u,!1),r,o,(l,d)=>r(f=>{const h=n._1,m=n._2;return r(p=>r(x=>F0(C(h,m,!1),r,o,(y,N)=>{const v=y._3;return r(J=>{if(v)return i(y,N);const k=n._1,S=n._2;return r(A=>r(I=>e(C(k,S,!1),r,o,($,E)=>{const G=$._3;return r(nt=>G?i($,E):Vi(n,r,o,i,a))},($,E)=>r(G=>a($,void 0)))))})},(y,N)=>r(v=>a(y,void 0)))))}),(l,d)=>r(f=>a(C(s,u,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),Tn=(()=>{const t=Xe((e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>c4(C(a,s,!1),n,r,(c,g)=>{const l=c._3;return n(d=>l?o(c,g):F0(e,n,r,o,i))},i))});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>i(e._3&&!s._3?C(s._1,s._2,!0):s,void 0))))})(),B0=(()=>{const t=Pt(e=>e!=="|");return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>n(c=>Le("\\|")(C(a,s,!1),n,r,(g,l)=>n(d=>n(f=>t(e,n,r,o,(h,m)=>n(p=>i(h,cr(m)))))),(g,l)=>n(d=>i(g,"|")))))}})(),g4=pt(nf([(t,e,n,r,o)=>e(i=>{const a=t._3;return Le("->")(t,e,n,(s,u)=>r(C(s._1,s._2,a),u),(s,u)=>e(c=>o(s,!0)))}),(t,e,n,r,o)=>e(i=>{const a=t._3;return Le("--")(t,e,n,(s,u)=>r(C(s._1,s._2,a),u),(s,u)=>e(c=>o(s,!1)))})]))("edge arrow '->' or '--'"),_4=t=>t!==`
18
- `&&t!=="\r"&&t!=="#"&&t!=="}"&&t!=="{",Hu=Pt(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),f4=t=>t===" "||t===" "||t==="\r",l4=t=>In(re(vr(f4)(re(Bn(t))).rest)),rf=t=>t===`
19
- `||t==="\r"||t==="#"||t==="}",d4=t=>t===`
20
- `||t==="\r"||t==="#"||t==="}"||t==="{",h4=t=>t!=="{"&&t!==`
21
- `&&t!=="\r",M0=t=>fa(t)==="",p4=t=>re(vr(M0)(re(vr(M0)(t).rest)).rest),m4=t=>(e=>n=>{let r=e,o=n,i=!0,a;for(;i;){const s=r,u=At(c=>w,c=>g=>T("Just",{head:c,tail:g}),o);if(u.tag==="Just"&&(u._1.head===" "||u._1.head===" ")){r=s+1|0,o=u._1.tail;continue}i=!1,a=s}return a})(0)(Bn(t)),y4=t=>{const e=At(n=>w,n=>r=>T("Just",{head:n,tail:r}),U(m4)(dt(n=>fa(n)!=="",t)));if(e.tag==="Nothing")return 0;if(e.tag==="Just")return b(s4)(e._1.head)(e._1.tail);_()},x4=(()=>{const t=pt(Pt(e=>e==="-"))("'-'");return(e,n,r,o,i)=>{const a=e._3;return n(s=>t(e,n,r,(u,c)=>o(C(u._1,u._2,a),c),(u,c)=>n(g=>{const l=bo((()=>{const f=pt(Pt(m=>m===">"))("'>'"),h=pt(Pt(m=>m==="-"))("'-'");return(m,p,x,y,N)=>{const v=m._1,J=m._2;return p(k=>f(C(v,J,!1),p,x,(S,A)=>{const I=S._3;return p($=>I?y(S,A):h(m,p,x,y,N))},N))}})()),d=e._3&&!u._3?C(u._1,u._2,!0):u;return n(f=>l(d,n,r,(h,m)=>o(C(h._1,h._2,a),m),(h,m)=>n(p=>i(d._3&&!h._3?C(h._1,h._2,!0):h,"-"))))})))}})(),oe=(()=>{const t=Xe(Pt(e=>e===" "||e===" "));return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>i(e._3&&!s._3?C(s._1,s._2,!0):s,void 0))))})(),Jo=(()=>{const t=Pt(e=>e===" "||e===" ");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>oe(e._3&&!s._3?C(s._1,s._2,!0):s,n,r,o,i))))})(),z0=(t,e,n,r,o)=>e(i=>e(a=>oe(t,e,n,r,(s,u)=>e(c=>e(g=>{const l=t._3&&!s._3?C(s._1,s._2,!0):s;return Ya(l,e,n,r,(d,f)=>e(h=>o(l._3&&!d._3?C(d._1,d._2,!0):d,f)))}))))),Q0=(t,e,n,r,o)=>e(i=>oe(t,e,n,r,(a,s)=>e(u=>{const c=pt(Pt(l=>l==="-"))("'-'"),g=t._3&&!a._3?C(a._1,a._2,!0):a;return e(l=>{const d=(m,p)=>e(x=>(()=>{if(p.tag==="Just")return(y,N,v,J,k)=>N(S=>g4(y,N,v,J,(A,I)=>N($=>k(A,T("Just",I)))));if(p.tag==="Nothing")return(y,N,v,J,k)=>k(y,w);_()})()(g._3&&!m._3?C(m._1,m._2,!0):m,e,n,r,o)),f=g._1,h=g._2;return e(m=>e(p=>c(C(f,h,!1),e,n,(x,y)=>e(N=>d(g,w)),(x,y)=>e(N=>d(C(f,h,!1),T("Just",y))))))})}))),w4=t=>{const e=Yn("Expected ")(t),n=(()=>{if(e.tag==="Nothing")return t;if(e.tag==="Just")return e._1;_()})();return n==="'{'"?"Open the block with `{`.":n==="integer (seed value)"?"Put an integer after `seed`.":n==="closing '}'"?"Close this block with `}`.":n===`closing '"' (unterminated string)`?'This string is unterminated; close it with `"`.':n==="closing '|'"?"Close this pipe label with `|`.":n==="space after '+'"?"Put a space after `+`: `+ api: API`.":n==="node identifier after '+'"?"Put a node id after `+`: `+ api: API`.":n==="space after '-'"?"Put a space after `-`: `- api`.":n==="node identifier after '-'"?"Put a node id after `-`: `- api`.":n==="space after '~'"?"Put a space after `~`: `~ api: API` or `~ api -> db => api -> cache`.":n==="node relabel label"?"Give the replacement label after `~ api`: `~ api: API`.":n==="node placeholder value"?"Give the replacement value after the placeholder name: `~ total.count: 3`.":n==="node identifier"?"Put a node identifier here.":n==="space after 'inside'"?"Put a space after `inside`: `inside api { ... }`.":n==="node identifier after 'inside'"?"Tell `inside` which node owns this interior: `inside api { ... }`.":n==="source node identifier after 'via'"?"Put the source node after `via`: `via a b`.":n==="target node identifier after 'via'"?"Put the second endpoint after `via`: `via a b`.":n==="source node identifier"?"Put a source node identifier here.":n==="new source node identifier"?"Put the new source node identifier after `=>`.":n==="new target node identifier"?"Put the new target node identifier after the replacement arrow.":n==="edge arrow '->' or '--'"?"Use `->` for a directed edge or `--` for an undirected edge.":n==="source edge arrow '->'"?"Use `->` in the edge you are changing: `~ api -> db => api -> cache`.":n==="replacement edge arrow '->'"?"Use `->` in the replacement edge: `~ api -> db => api -> cache`.":n==="repoint separator '=>'"?"Use `=>` before the replacement edge: `~ api -> db => api -> cache`.":n==="target node identifier"?"Put a target node after the arrow.":n==="'~>'"?"Use `~>` for movement from left to right.":n==="'<~'"?"Use `<~` for movement from right to left.":n==="'->' or '<-'"?"Use `~>` / `<~` for movement tokens.":n==='label ("\u2026", : rest-of-line, or |\u2026|)'?'label must use `: text`, `"text"`, or `|multi-line|`.':n==="attribute key"?"Start each attribute with a name, like `shape`.":n==="':'"?"Put `:` between the attribute name and value: `{shape: cylinder}`.":n==="attribute value"?"Put an attribute value after `:`.":n==="closing '}' for attributes"?"Close the attribute block with `}`.":n==="space after 'into'"?"Put a space after `into`: `into api`.":n==="node identifier after 'into'"?"Tell `into` which node to dive into.":n==="space after 'step'"?"Put a space after `step`: `step request`.":n==="step name"?"Name the step: `step request`.":n==="newline or '}' (statements end at the end of the line)"?"This statement has extra text. Put the next statement on a new line or close the block with `}`.":n==="statement (+ node, - node, + edge, - edge, ~ node, into, out, or 'a ~> b'/'a <~ b')"?"I don't recognize this statement. Start with `+`, `-`, `~`, `into`, `out`, `par`, `seq`, or movement like `api ~> db`.":n==="'scene', 'still', 'title', 'step', 'inside', a statement, or end of input"?"Start with a statement like `+ api: API`, a marker like `step request`, or a block with `scene`, `still`, `title`, or `inside`.":n},N4=t=>{const e=fa(t),n=Yn('"')(e),r=(()=>{if(n.tag==="Just")return Ly('"')(n._1);if(n.tag==="Nothing")return w;_()})(),o=(()=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;_()})();return o===""?w:T("Just",o)},W0=t=>e=>t!=="AnimatedSurface"&&e.statements.length!==0?{...e,frames:St(e.frames)((()=>{if(t==="StillSurface")return{name:w,ops:Fr("Seq",e.statements),kind:j_};if(t==="SequenceSurface")return{name:w,ops:Fr("Seq",e.statements),kind:zu};if(t==="AnimatedSurface")return{name:w,ops:Fr("Seq",e.statements),kind:zu};_()})()),statements:[]}:e,T4=(()=>{const t=pt(Pt(e=>e==="\\"))("'\\\\'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?C(s._1,s._2,!0):s;return n(l=>X_(g,n,r,o,(d,f)=>n(h=>i(g._3&&!d._3?C(d._1,d._2,!0):d,f==="n"?`
22
- `:f==="t"?" ":f==="r"?"\r":f))))})))})(),v4=(()=>{const t=Pt(e=>e!=='"'&&e!=="\\"&&e!==`
23
- `);return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>T4(C(a,s,!1),n,r,(c,g)=>n(l=>t(e,n,r,o,i)),i))}})(),O0=(()=>{const t=pt(Pt(e=>e==='"'))(`'"'`);return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=Xe(v4),l=e._3&&!s._3?C(s._1,s._2,!0):s;return n(d=>g(l,n,r,o,(f,h)=>n(m=>{const p=pt(pt(Pt(y=>y==='"'))(`'"'`))(`closing '"' (unterminated string)`),x=l._3&&!f._3?C(f._1,f._2,!0):f;return n(y=>p(x,n,r,o,(N,v)=>n(J=>i(x._3&&!N._3?C(N._1,N._2,!0):N,In(Wt(ue.foldr,h))))))})))})))})(),b4={frames:[],statements:[]},H0=t=>{const e=p4(Mo(`
24
- `)(t));return Qn(`
25
- `)(U(l4)(U(Ji(y4(e)))(e)))},J4=(t,e,n,r,o)=>{const i=t._3;return e(a=>Le("|md")(t,e,n,(s,u)=>r(C(s._1,s._2,i),u),(s,u)=>e(c=>{const g=pt((d,f,h,m,p)=>{const x=d._1,y=d._2;return f(N=>Le(`\r
26
- `)(C(x,y,!1),f,h,(v,J)=>{const k=v._3;return f(S=>{if(k)return m(v,J);const A=d._1,I=d._2;return f($=>Le(`
27
- `)(C(A,I,!1),f,h,(E,G)=>{const nt=E._3;return f(V=>nt?m(E,G):Le("\r")(d,f,h,m,p))},p))})},p))})("newline after '|md'"),l=t._3&&!s._3?C(s._1,s._2,!0):s;return e(d=>g(l,e,n,(f,h)=>r(C(f._1,f._2,i),h),(f,h)=>e(m=>{const p=Xe(B0),x=l._3&&!f._3?C(f._1,f._2,!0):f;return e(y=>p(x,e,n,(N,v)=>r(C(N._1,N._2,i),v),(N,v)=>e(J=>{const k=pt(pt(Pt(A=>A==="|"))("'|'"))("closing '|'"),S=x._3&&!N._3?C(N._1,N._2,!0):N;return e(A=>k(S,e,n,(I,$)=>r(C(I._1,I._2,i),$),(I,$)=>e(E=>o(S._3&&!I._3?C(I._1,I._2,!0):I,"md:"+H0(Qn("")(Wt(ue.foldr,v)))))))})))})))})))},C4=(()=>{const t=pt(Pt(e=>e==="|"))("'|'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=Xe(B0),l=e._3&&!s._3?C(s._1,s._2,!0):s;return n(d=>g(l,n,r,o,(f,h)=>n(m=>{const p=pt(pt(Pt(y=>y==="|"))("'|'"))("closing '|'"),x=l._3&&!f._3?C(f._1,f._2,!0):f;return n(y=>p(x,n,r,o,(N,v)=>n(J=>i(x._3&&!N._3?C(N._1,N._2,!0):N,H0(Qn("")(Wt(ue.foldr,h)))))))})))})))})(),fi=Pt(t=>t>="0"&&t<="9"),k4=(()=>{const t=pt(Pt(e=>e==="_"))("'_'");return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>Hu(C(a,s,!1),n,r,(c,g)=>{const l=c._3;return n(d=>{if(l)return o(c,g);const f=e._1,h=e._2;return n(m=>fi(C(f,h,!1),n,r,(p,x)=>{const y=p._3;return n(N=>{if(y)return o(p,x);const v=e._1,J=e._2;return n(k=>t(C(v,J,!1),n,r,(S,A)=>{const I=S._3;return n($=>I?o(S,A):x4(e,n,r,o,i))},i))})},i))})},i))}})(),Oe=(()=>{const t=pt(Pt(e=>e==="_"))("'_'");return(e,n,r,o,i)=>n(a=>{const s=(g,l)=>n(d=>{const f=Xe(k4),h=e._3&&!g._3?C(g._1,g._2,!0):g;return n(m=>f(h,n,r,o,(p,x)=>n(y=>i(h._3&&!p._3?C(p._1,p._2,!0):p,cr(l)+In(Wt(ue.foldr,x))))))}),u=e._1,c=e._2;return n(g=>Hu(C(u,c,!1),n,r,(l,d)=>{const f=l._3;return n(h=>f?o(l,d):t(e,n,r,o,s))},s))})})(),L4=t=>e=>n=>(r,o,i,a,s)=>o(u=>oe(r,o,i,a,(c,g)=>o(l=>{const d=Nn(pt(Oe)("target node identifier")),f=r._3&&!c._3?C(c._1,c._2,!0):c;return o(h=>d(f,o,i,a,(m,p)=>o(x=>s(f._3&&!m._3?C(m._1,m._2,!0):m,{op:Xn("DelEdge",{from:t,to:p._1,directed:n}),operands:[e,p._2]}))))}))),S4=(t,e,n,r,o)=>e(i=>Un(t,e,n,r,(a,s)=>e(u=>{const c=t._3&&!a._3?C(a._1,a._2,!0):a;return e(g=>{const l=c._3;return e(d=>Oe(c,e,n,(f,h)=>r(C(f._1,f._2,l),h),(f,h)=>e(m=>{const p=c._3&&!f._3?C(f._1,f._2,!0):f;return e(x=>oe(p,e,n,(y,N)=>r(C(y._1,y._2,l),N),(y,N)=>e(v=>{const J=p._3&&!y._3?C(y._1,y._2,!0):y;return e(k=>{const S=($,E)=>e(G=>{const nt=J._3&&!$._3?C($._1,$._2,!0):$;return e(V=>r(c._3&&!nt._3?C(nt._1,nt._2,!0):nt,or("Use `~>` / `<~` for movement tokens.",s)))}),A=J._1,I=J._2;return e($=>Le("->")(C(A,I,!1),e,n,(E,G)=>{const nt=E._3;return e(V=>nt?r(C(E._1,E._2,l),G):Le("<-")(J,e,n,(Q,Y)=>r(C(Q._1,Q._2,l),Y),S))},S))})})))})))})}))),E4=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>Nn(Oe)(t,e,n,(u,c)=>r(C(u._1,u._2,a),c),(u,c)=>e(g=>{const l=t._3&&!u._3?C(u._1,u._2,!0):u;return e(d=>oe(l,e,n,(f,h)=>r(C(f._1,f._2,a),h),(f,h)=>e(m=>{const p=pt(Pt(y=>y==="~"))("'~'"),x=l._3&&!f._3?C(f._1,f._2,!0):f;return e(y=>{const N=(k,S)=>e(A=>{const I=x._3&&!k._3?C(k._1,k._2,!0):k;return e($=>{const E=c._1,G=c._2,nt=t._3&&!I._3?C(I._1,I._2,!0):I;return e(V=>oe(nt,e,n,r,(Q,Y)=>e(X=>{const D=pt(Pt(z=>z==="~"))("'~'"),F=pt(Pt(z=>z==="<"))("'<'"),B=nt._3&&!Q._3?C(Q._1,Q._2,!0):Q;return e(z=>{const j=(q,H)=>e(ot=>{const et=H==="~"?pt(Le("~>"))("'~>'"):pt(Le("<~"))("'<~'"),gt=B._3&&!q._3?C(q._1,q._2,!0):q;return e(Lt=>et(gt,e,n,r,(ft,Nt)=>e(kt=>o(gt._3&&!ft._3?C(ft._1,ft._2,!0):ft,L(E,L(G,Nt))))))}),W=B._1,O=B._2;return e(q=>D(C(W,O,!1),e,n,(H,ot)=>{const et=H._3;return e(gt=>et?r(B,ot):F(B,e,n,(Lt,ft)=>r(B,ft),(Lt,ft)=>j(B,ft)))},(H,ot)=>j(B,ot)))})})))})}),v=x._1,J=x._2;return e(k=>p(C(v,J,!1),e,n,(S,A)=>{const I=S._3;return e($=>I?r(C(x._1,x._2,a),A):e(E=>Le("<~")(x,e,n,(G,nt)=>r(C(x._1,x._2,a),nt),(G,nt)=>e(V=>N(x)))))},(S,A)=>N(x)))})})))})))}),A4=t=>e=>{const n=pt(Le("->"))("source edge arrow '->'");return(r,o,i,a,s)=>o(u=>n(r,o,i,a,(c,g)=>o(l=>{const d=r._3&&!c._3?C(c._1,c._2,!0):c;return o(f=>oe(d,o,i,a,(h,m)=>o(p=>{const x=Nn(pt(Oe)("target node identifier")),y=d._3&&!h._3?C(h._1,h._2,!0):h;return o(N=>x(y,o,i,a,(v,J)=>o(k=>{const S=J._1,A=J._2,I=y._3&&!v._3?C(v._1,v._2,!0):v;return o($=>oe(I,o,i,a,(E,G)=>o(nt=>{const V=pt(Le("=>"))("repoint separator '=>'"),Q=I._3&&!E._3?C(E._1,E._2,!0):E;return o(Y=>V(Q,o,i,a,(X,D)=>o(F=>{const B=Q._3&&!X._3?C(X._1,X._2,!0):X;return o(z=>oe(B,o,i,a,(j,W)=>o(O=>{const q=Nn(pt(Oe)("new source node identifier")),H=B._3&&!j._3?C(j._1,j._2,!0):j;return o(ot=>q(H,o,i,a,(et,gt)=>o(Lt=>{const ft=gt._1,Nt=gt._2,kt=H._3&&!et._3?C(et._1,et._2,!0):et;return o(jt=>oe(kt,o,i,a,(Tt,Vt)=>o(Ft=>{const vt=pt(Le("->"))("replacement edge arrow '->'"),mt=kt._3&&!Tt._3?C(Tt._1,Tt._2,!0):Tt;return o(lt=>vt(mt,o,i,a,(xt,Dt)=>o(ht=>{const bt=mt._3&&!xt._3?C(xt._1,xt._2,!0):xt;return o(Qt=>oe(bt,o,i,a,(Bt,ie)=>o(ce=>{const gn=Nn(pt(Oe)("new target node identifier")),$t=bt._3&&!Bt._3?C(Bt._1,Bt._2,!0):Bt;return o(te=>gn($t,o,i,a,(on,He)=>o(Pn=>s($t._3&&!on._3?C(on._1,on._2,!0):on,{op:Xn("RepointEdge",{from:t,to:S,newFrom:ft,newTo:He._1}),operands:[e,A,Nt,He._2]}))))})))})))})))})))})))})))})))})))})))})))},P4=(t,e,n,r,o)=>e(i=>fi(t,e,n,r,(a,s)=>e(u=>{const c=Xe(fi),g=t._3&&!a._3?C(a._1,a._2,!0):a;return e(l=>c(g,e,n,r,(d,f)=>e(h=>{const m=W2(cr(s)+In(Wt(ue.foldr,f)));return(()=>{if(m.tag==="Just"){const p=m._1;return(x,y,N,v,J)=>J(x,p)}if(m.tag==="Nothing")return(p,x,y,N,v)=>v(p,0);_()})()(g._3&&!d._3?C(d._1,d._2,!0):d,e,n,r,o)})))}))),R4=t=>(e,n,r,o,i)=>{const a=e._3;return n(s=>Le(t)(e,n,r,(u,c)=>o(C(u._1,u._2,a),c),(u,c)=>n(g=>{const l=bo((()=>{const f=pt(Pt(m=>m==="_"))("'_'"),h=pt(Pt(m=>m==="-"))("'-'");return(m,p,x,y,N)=>{const v=m._1,J=m._2;return p(k=>Hu(C(v,J,!1),p,x,(S,A)=>{const I=S._3;return p($=>{if(I)return y(S,A);const E=m._1,G=m._2;return p(nt=>fi(C(E,G,!1),p,x,(V,Q)=>{const Y=V._3;return p(X=>{if(Y)return y(V,Q);const D=m._1,F=m._2;return p(B=>f(C(D,F,!1),p,x,(z,j)=>{const W=z._3;return p(O=>W?y(z,j):h(m,p,x,y,N))},N))})},N))})},N))}})()),d=e._3&&!u._3?C(u._1,u._2,!0):u;return n(f=>l(d,n,r,(h,m)=>o(C(h._1,h._2,a),m),(h,m)=>n(p=>{const x=d._3&&!h._3?C(h._1,h._2,!0):h;return n(y=>Tn(x,n,r,(N,v)=>o(C(N._1,N._2,a),v),(N,v)=>n(J=>i(x._3&&!N._3?C(N._1,N._2,!0):N,t))))})))})))},G4=(t,e,n,r,o)=>e(i=>fi(t,e,n,r,(a,s)=>e(u=>{const c=Xe((()=>{const l=pt(Pt(d=>d==="."))("'.'");return(d,f,h,m,p)=>{const x=d._1,y=d._2;return f(N=>fi(C(x,y,!1),f,h,(v,J)=>{const k=v._3;return f(S=>k?m(v,J):l(d,f,h,m,p))},p))}})()),g=t._3&&!a._3?C(a._1,a._2,!0):a;return e(l=>c(g,e,n,r,(d,f)=>e(h=>o(g._3&&!d._3?C(d._1,d._2,!0):d,cr(s)+In(Wt(ue.foldr,f))))))}))),En=t=>(e,n,r,o,i)=>{const a=e._3;return n(s=>Le(t)(e,n,r,(u,c)=>o(C(u._1,u._2,a),c),(u,c)=>n(g=>{const l=bo((()=>{const f=pt(Pt(m=>m==="_"))("'_'"),h=pt(Pt(m=>m==="-"))("'-'");return(m,p,x,y,N)=>{const v=m._1,J=m._2;return p(k=>Hu(C(v,J,!1),p,x,(S,A)=>{const I=S._3;return p($=>{if(I)return y(S,A);const E=m._1,G=m._2;return p(nt=>fi(C(E,G,!1),p,x,(V,Q)=>{const Y=V._3;return p(X=>{if(Y)return y(V,Q);const D=m._1,F=m._2;return p(B=>f(C(D,F,!1),p,x,(z,j)=>{const W=z._3;return p(O=>W?y(z,j):h(m,p,x,y,N))},N))})},N))})},N))}})()),d=e._3&&!u._3?C(u._1,u._2,!0):u;return n(f=>l(d,n,r,(h,m)=>o(C(h._1,h._2,a),m),(h,m)=>n(p=>i(d._3&&!h._3?C(h._1,h._2,!0):h,void 0))))})))},D4=(t,e,n,r,o)=>e(i=>En("into")(t,e,n,r,(a,s)=>e(u=>{const c=pt(Jo)("space after 'into'"),g=t._3&&!a._3?C(a._1,a._2,!0):a;return e(l=>c(g,e,n,r,(d,f)=>e(h=>{const m=Nn(pt(Oe)("node identifier after 'into'")),p=g._3&&!d._3?C(d._1,d._2,!0):d;return e(x=>m(p,e,n,r,(y,N)=>e(v=>o(p._3&&!y._3?C(y._1,y._2,!0):y,{op:Xn("Enter",{id:N._1}),operands:[N._2]}))))})))}))),F4=(t,e,n,r,o)=>e(i=>En("out")(t,e,n,r,(a,s)=>e(u=>o(t._3&&!a._3?C(a._1,a._2,!0):a,{op:pE,operands:[]})))),I4=(t,e,n,r,o)=>e(i=>En("seed")(t,e,n,r,(a,s)=>e(u=>{const c=t._3&&!a._3?C(a._1,a._2,!0):a;return e(g=>oe(c,e,n,r,(l,d)=>e(f=>{const h=pt(P4)("integer (seed value)"),m=c._3&&!l._3?C(l._1,l._2,!0):l;return e(p=>h(m,e,n,r,(x,y)=>e(N=>{const v=m._3&&!x._3?C(x._1,x._2,!0):x;return e(J=>Tn(v,e,n,r,(k,S)=>e(A=>o(v._3&&!k._3?C(k._1,k._2,!0):k,y))))})))})))}))),$0=(t,e,n,r,o)=>{const i=t._3;return e(a=>En("diagram")(t,e,n,(s,u)=>r(C(s._1,s._2,i),u),(s,u)=>e(c=>{const g=pt(Jo)("space after 'diagram'"),l=t._3&&!s._3?C(s._1,s._2,!0):s;return e(d=>g(l,e,n,(f,h)=>r(C(f._1,f._2,i),h),(f,h)=>e(m=>{const p=pt(En("sequence"))("diagram mode"),x=l._3&&!f._3?C(f._1,f._2,!0):f;return e(y=>p(x,e,n,(N,v)=>r(C(N._1,N._2,i),v),(N,v)=>e(J=>{const k=x._3&&!N._3?C(N._1,N._2,!0):N;return e(S=>z0(k,e,n,(A,I)=>r(C(A._1,A._2,i),I),(A,I)=>e($=>o(k._3&&!A._3?C(A._1,A._2,!0):A,hE))))})))})))})))},q0=(t,e,n,r,o)=>{const i=t._3;return e(a=>En("still")(t,e,n,(s,u)=>r(C(s._1,s._2,i),u),(s,u)=>e(c=>{const g=t._3&&!s._3?C(s._1,s._2,!0):s;return e(l=>z0(g,e,n,(d,f)=>r(C(d._1,d._2,i),f),(d,f)=>e(h=>o(g._3&&!d._3?C(d._1,d._2,!0):d,dE))))})))},U0=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>q0(C(i,a,!1),e,n,(u,c)=>{const g=u._3;return e(l=>g?r(u,c):$0(t,e,n,r,o))},o))},B4=t=>(e,n,r,o,i)=>n(a=>Un(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?C(s._1,s._2,!0):s;return n(l=>{const d=g._3;return U0(g,n,r,(f,h)=>o(C(f._1,f._2,d),h),(f,h)=>n(m=>o(g._3&&!f._3?C(f._1,f._2,!0):f,or((()=>{if(t==="AnimatedSurface")return"Put diagram mode headers at the top of the document.";if(t==="AnimatedSurface")return"This document already declares `animation`; choose one diagram mode.";if(t==="StillSurface")return"This document already declares `still`; choose one diagram mode.";if(t==="SequenceSurface")return"This document already declares `diagram sequence`; choose one diagram mode.";_()})(),u))))})}))),M4=t=>(e,n,r,o,i)=>n(a=>Un(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?C(s._1,s._2,!0):s;return n(l=>{const d=(m,p)=>n(x=>(()=>{if(p.tag==="Just"){const y=(()=>{if(t==="AnimatedSurface")return"This document already declares `animation`; choose one diagram mode.";if(t==="StillSurface")return"This document already declares `still`; choose one diagram mode.";if(t==="SequenceSurface")return"This document already declares `diagram sequence`; choose one diagram mode.";_()})();return(N,v,J,k,S)=>k(N,or(y,u))}if(p.tag==="Nothing")return(y,N,v,J,k)=>k(y,void 0);_()})()(g._3&&!m._3?C(m._1,m._2,!0):m,n,r,o,i)),f=g._1,h=g._2;return n(m=>n(p=>U0(C(f,h,!1),n,r,(x,y)=>{const N=x._3;return n(v=>N?o(x,y):d(g,w))},(x,y)=>n(N=>d(x,T("Just",y))))))})}))),z4=(t,e,n,r,o)=>e(i=>{const a=(c,g)=>e(l=>{const d=t._3&&!c._3?C(c._1,c._2,!0):c;return e(f=>Tn(d,e,n,r,(h,m)=>e(p=>{const x=d._3&&!h._3?C(h._1,h._2,!0):h;return e(y=>M4(g)(x,e,n,r,(N,v)=>e(J=>o(x._3&&!N._3?C(N._1,N._2,!0):N,g))))})))}),s=t._1,u=t._2;return e(c=>q0(C(s,u,!1),e,n,(g,l)=>{const d=g._3;return e(f=>d?r(g,l):$0(t,e,n,r,a))},a))}),Q4=(t,e,n,r,o)=>e(i=>{const a=(c,g)=>e(l=>o(c,(()=>{if(g.tag==="Nothing")return lE;if(g.tag==="Just")return g._1;_()})())),s=t._1,u=t._2;return e(c=>e(g=>z4(C(s,u,!1),e,n,(l,d)=>{const f=l._3;return e(h=>f?r(l,d):a(t,w))},(l,d)=>e(f=>a(l,T("Just",d))))))}),W4=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>oe(t,e,n,(u,c)=>r(C(u._1,u._2,a),c),(u,c)=>e(g=>En("via")(t._3&&!u._3?C(u._1,u._2,!0):u,e,n,(l,d)=>r(C(l._1,l._2,a),d),(l,d)=>e(f=>{const h=t._3&&!l._3?C(l._1,l._2,!0):l;return e(m=>Du(h,e,n,r,(p,x)=>e(y=>{const N=h._3&&!p._3?C(p._1,p._2,!0):p;return e(v=>Jo(N,e,n,r,(J,k)=>e(S=>{const A=pt(Oe)("source node identifier after 'via'"),I=N._3&&!J._3?C(J._1,J._2,!0):J;return e($=>A(I,e,n,r,(E,G)=>e(nt=>{const V=I._3&&!E._3?C(E._1,E._2,!0):E;return e(Q=>oe(V,e,n,r,(Y,X)=>e(D=>{const F=pt(Oe)("target node identifier after 'via'"),B=V._3&&!Y._3?C(Y._1,Y._2,!0):Y;return e(z=>F(B,e,n,r,(j,W)=>e(O=>o(B._3&&!j._3?C(j._1,j._2,!0):j,{from:G,to:W}))))})))})))})))})))})))))}),O4=t=>e=>{const n=Xe(W4);return(r,o,i,a,s)=>o(u=>n(r,o,i,a,(c,g)=>o(l=>s(r._3&&!c._3?C(c._1,c._2,!0):c,{op:Xn("DelNode",{id:t,via:Wt(ue.foldr,g)}),operands:[e]}))))},H4=(()=>{const t=pt(Pt(e=>e==="-"))("'-'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=pt(Jo)("space after '-'"),l=e._3&&!s._3?C(s._1,s._2,!0):s;return n(d=>g(l,n,r,o,(f,h)=>n(m=>{const p=Nn(pt(Oe)("node identifier after '-'")),x=l._3&&!f._3?C(f._1,f._2,!0):f;return n(y=>p(x,n,r,o,(N,v)=>n(J=>{const k=v._1,S=v._2,A=x._3&&!N._3?C(N._1,N._2,!0):N;return n(I=>Q0(A,n,r,o,($,E)=>n(G=>(()=>{if(E.tag==="Just")return L4(k)(S)(E._1);if(E.tag==="Nothing")return O4(k)(S);_()})()(A._3&&!$._3?C($._1,$._2,!0):$,n,r,o,i))))})))})))})))})(),yr=t=>e=>(n,r,o,i,a)=>r(s=>Un(n,r,o,i,(u,c)=>r(g=>{const l=n._3&&!u._3?C(u._1,u._2,!0):u;return r(d=>En(t)(l,r,o,i,(f,h)=>r(m=>i(l._3&&!f._3?C(f._1,f._2,!0):f,or(e,c)))))}))),$4=t=>t==="AnimatedSurface"?(e,n,r,o,i)=>n(a=>Un(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?C(s._1,s._2,!0):s;return n(l=>En("step")(g,n,r,o,(d,f)=>n(h=>{const m=pt(Jo)("space after 'step'"),p=g._3&&!d._3?C(d._1,d._2,!0):d;return n(x=>m(p,n,r,o,(y,N)=>n(v=>{const J=Nn(pt(Oe)("step name")),k=p._3&&!y._3?C(y._1,y._2,!0):y;return n(S=>J(k,n,r,o,(A,I)=>n($=>{const E=I._1,G=I._2,nt=k._3&&!A._3?C(A._1,A._2,!0):A;return n(V=>Un(nt,n,r,o,(Q,Y)=>n(X=>{const D=nt._3&&!Q._3?C(Q._1,Q._2,!0):Q;return n(F=>oe(D,n,r,o,(B,z)=>n(j=>{const W=D._3&&!B._3?C(B._1,B._2,!0):B;return n(O=>I0(W,n,r,o,(q,H)=>n(ot=>{const et=W._3&&!q._3?C(q._1,q._2,!0):q;return n(gt=>Tn(et,n,r,o,(Lt,ft)=>n(Nt=>{const kt={line:u.line,column:u.column,endLine:Y.line,endColumn:Y.column};return i(et._3&&!Lt._3?C(Lt._1,Lt._2,!0):Lt,{name:T("Just",E),ops:Fr("Leaf",{op:Xn("Step",{name:E}),line:kt.line,column:kt.column,endLine:kt.endLine,endColumn:kt.endColumn,span:kt,operands:[G]}),kind:N0})})))})))})))})))})))})))})))}))):yr("step")("`step` markers are only supported in animated diagrams."),q4=(()=>{const t=pt(Pt(e=>e===":"))("':'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?C(s._1,s._2,!0):s;return n(l=>oe(g,n,r,o,(d,f)=>n(h=>{const m=Xe(Pt(_4)),p=g._3&&!d._3?C(d._1,d._2,!0):d;return n(x=>m(p,n,r,o,(y,N)=>n(v=>i(p._3&&!y._3?C(y._1,y._2,!0):y,fa(In(Wt(ue.foldr,N)))))))})))})))})(),X0=pt((t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>q4(C(i,a,!1),e,n,(u,c)=>{const g=u._3;return e(l=>{if(g)return r(u,c);const d=t._1,f=t._2;return e(h=>J4(C(d,f,!1),e,n,(m,p)=>{const x=m._3;return e(y=>{if(x)return r(m,p);const N=t._1,v=t._2;return e(J=>C4(C(N,v,!1),e,n,(k,S)=>{const A=k._3;return e(I=>A?r(k,S):O0(t,e,n,r,o))},o))})},o))})},o))})('label ("\u2026", : rest-of-line, or |\u2026|)'),V0=(t,e,n,r,o)=>e(i=>oe(t,e,n,r,(a,s)=>e(u=>X0(t._3&&!a._3?C(a._1,a._2,!0):a,e,n,r,o)))),$u=t=>(e,n,r,o,i)=>n(a=>oe(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?C(s._1,s._2,!0):s;return n(l=>{const d=(m,p)=>n(x=>(p?((y,N,v,J,k)=>k(y,w)):(y,N,v,J,k)=>N(S=>V0(y,N,v,J,(A,I)=>N($=>k(A,T("Just",I))))))(g._3&&!m._3?C(m._1,m._2,!0):m,n,r,o,i)),f=g._1,h=g._2;return n(m=>{const p=(x,y)=>{const N=x._3;return n(v=>N?o(x,y):d(g,!1))};return n(x=>n(y=>n(N=>Vi(C(f,h,!1),n,r,(v,J)=>{const k=v._3;return n(S=>k?p(C(f,h,!1),J):n(A=>Pt(t)(C(f,h,!1),n,r,(I,$)=>p(C(f,h,!1),$),(I,$)=>n(E=>n(G=>d(C(f,h,!1),!0))))))},(v,J)=>n(k=>n(S=>d(C(f,h,!1),!0)))))))})})}))),U4=t=>e=>n=>(r,o,i,a,s)=>o(u=>oe(r,o,i,a,(c,g)=>o(l=>{const d=Nn(pt(Oe)("target node identifier")),f=r._3&&!c._3?C(c._1,c._2,!0):c;return o(h=>d(f,o,i,a,(m,p)=>o(x=>{const y=p._1,N=p._2,v=f._3&&!m._3?C(m._1,m._2,!0):m;return o(J=>$u(rf)(v,o,i,a,(k,S)=>o(A=>s(v._3&&!k._3?C(k._1,k._2,!0):k,{op:Xn("AddEdge",{from:t,to:y,label:S.tag==="Just"?T("Just",S._1):w,directed:n}),operands:[e,N]}))))})))}))),X4=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>Nn(Oe)(t,e,n,(u,c)=>r(C(u._1,u._2,a),c),(u,c)=>e(g=>{const l=t._3&&!u._3?C(u._1,u._2,!0):u;return e(d=>oe(l,e,n,(f,h)=>r(C(f._1,f._2,a),h),(f,h)=>e(m=>{const p=pt(Pt(y=>y==="<"))("'<'"),x=l._3&&!f._3?C(f._1,f._2,!0):f;return e(y=>p(x,e,n,(N,v)=>r(C(x._1,x._2,a),v),(N,v)=>e(J=>{const k=bo((A,I,$,E,G)=>{const nt=A._3;return Le("<-")(A,I,$,(V,Q)=>E(C(V._1,V._2,nt),Q),G)}),S=x._3&&!x._3?C(x._1,x._2,!0):x;return e(A=>k(S,e,n,(I,$)=>r(C(I._1,I._2,a),$),(I,$)=>e(E=>{const G=S._3&&!I._3?C(I._1,I._2,!0):I;return e(nt=>{const V=c._1,Q=c._2,Y=t._3&&!G._3?C(G._1,G._2,!0):G;return e(X=>oe(Y,e,n,r,(D,F)=>e(B=>{const z=pt(Le("<~"))("'<~'"),j=Y._3&&!D._3?C(D._1,D._2,!0):D;return e(W=>z(j,e,n,r,(O,q)=>e(H=>{const ot=j._3&&!O._3?C(O._1,O._2,!0):O;return e(et=>oe(ot,e,n,r,(gt,Lt)=>e(ft=>{const Nt=Nn(pt(Oe)("target node identifier")),kt=ot._3&&!gt._3?C(gt._1,gt._2,!0):gt;return e(jt=>Nt(kt,e,n,r,(Tt,Vt)=>e(Ft=>{const vt=Vt._1,mt=Vt._2,lt=kt._3&&!Tt._3?C(Tt._1,Tt._2,!0):Tt;return e(xt=>$u(rf)(lt,e,n,r,(Dt,ht)=>e(bt=>o(lt._3&&!Dt._3?C(Dt._1,Dt._2,!0):Dt,{op:Xn("Token",{from:vt,to:V,labels:(()=>{if(ht.tag==="Nothing")return[];if(ht.tag==="Just")return[ht._1];_()})()}),operands:[mt,Q]}))))})))})))})))})))})})))})))})))})))}),V4=(t,e,n,r,o)=>e(i=>E4(t,e,n,r,(a,s)=>e(u=>{const c=s._2._2,g=s._1,l=s._2._1,d=t._3&&!a._3?C(a._1,a._2,!0):a;return e(f=>oe(d,e,n,r,(h,m)=>e(p=>{const x=Nn(pt(Oe)("target node identifier")),y=d._3&&!h._3?C(h._1,h._2,!0):h;return e(N=>x(y,e,n,r,(v,J)=>e(k=>{const S=J._1,A=J._2,I=y._3&&!v._3?C(v._1,v._2,!0):v;return e($=>$u(rf)(I,e,n,r,(E,G)=>e(nt=>(c==="<~"?((V,Q,Y,X,D)=>D(V,{op:Xn("Token",{from:S,to:g,labels:(()=>{if(G.tag==="Nothing")return[];if(G.tag==="Just")return[G._1];_()})()}),operands:c==="<~"?[A,l]:[l,A]})):(V,Q,Y,X,D)=>D(V,{op:Xn("Token",{from:g,to:S,labels:(()=>{if(G.tag==="Nothing")return[];if(G.tag==="Just")return[G._1];_()})()}),operands:c==="<~"?[A,l]:[l,A]}))(I._3&&!E._3?C(E._1,E._2,!0):E,e,n,r,o))))})))})))}))),Y4=(t,e,n,r,o)=>e(i=>$u(d4)(t,e,n,r,(a,s)=>e(u=>o(a,(()=>{if(s.tag==="Nothing")return"";if(s.tag==="Just")return s._1;_()})())))),K4=t=>e=>n=>r=>(o,i,a,s,u)=>i(c=>Un(o,i,a,s,(g,l)=>i(d=>{const f=o._3&&!g._3?C(g._1,g._2,!0):g;return i(h=>{const m=(y,N)=>i(v=>(()=>{if(N.tag==="Just")return(J,k,S,A,I)=>A(J,or("node placeholder value",l));if(N.tag==="Nothing")return(J,k,S,A,I)=>k($=>V0(J,k,S,A,(E,G)=>k(nt=>I(J._3&&!E._3?C(E._1,E._2,!0):E,{op:Xn("ModNodeSlot",{id:t,slot:n,value:G}),operands:[e,r]}))));_()})()(f._3&&!y._3?C(y._1,y._2,!0):y,i,a,s,u)),p=f._1,x=f._2;return i(y=>i(N=>Ya(C(p,x,!1),i,a,(v,J)=>i(k=>m(f,w)),(v,J)=>i(k=>m(C(p,x,!1),T("Just",J))))))})}))),j4=t=>e=>(n,r,o,i,a)=>r(s=>Un(n,r,o,i,(u,c)=>r(g=>{const l=n._3&&!u._3?C(u._1,u._2,!0):u;return r(d=>{const f=(p,x)=>r(y=>(()=>{if(x.tag==="Just")return(N,v,J,k,S)=>k(N,or("node relabel label",c));if(x.tag==="Nothing")return(N,v,J,k,S)=>v(A=>X0(N,v,J,k,(I,$)=>v(E=>S(N._3&&!I._3?C(I._1,I._2,!0):I,{op:Xn("ModNode",{id:t,label:T("Just",$)}),operands:[e]}))));_()})()(l._3&&!p._3?C(p._1,p._2,!0):p,r,o,i,a)),h=l._1,m=l._2;return r(p=>r(x=>Ya(C(h,m,!1),r,o,(y,N)=>r(v=>f(l,w)),(y,N)=>r(v=>f(C(h,m,!1),T("Just",N))))))})}))),Z4=(()=>{const t=pt(Pt(e=>e==="~"))("'~'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=pt(Jo)("space after '~'"),l=e._3&&!s._3?C(s._1,s._2,!0):s;return n(d=>g(l,n,r,o,(f,h)=>n(m=>{const p=Nn(pt(Oe)("source node identifier")),x=l._3&&!f._3?C(f._1,f._2,!0):f;return n(y=>p(x,n,r,o,(N,v)=>n(J=>{const k=v._1,S=v._2,A=pt(Pt(E=>E==="."))("'.'"),I=Nn(pt(Oe)("placeholder name")),$=x._3&&!N._3?C(N._1,N._2,!0):N;return n(E=>{const G=(Q,Y)=>n(X=>(()=>{if(Y.tag==="Just")return K4(k)(S)(Y._1._1)(Y._1._2);if(Y.tag==="Nothing")return(D,F,B,z,j)=>F(W=>oe(D,F,B,z,(O,q)=>F(H=>{const ot=pt(Pt(gt=>gt==="-"))("'-'"),et=D._3&&!O._3?C(O._1,O._2,!0):O;return F(gt=>{const Lt=(kt,jt)=>F(Tt=>(()=>{if(jt.tag==="Just")return A4(k)(S);if(jt.tag==="Nothing")return j4(k)(S);_()})()(et._3&&!kt._3?C(kt._1,kt._2,!0):kt,F,B,z,j)),ft=et._1,Nt=et._2;return F(kt=>F(jt=>ot(C(ft,Nt,!1),F,B,(Tt,Vt)=>F(Ft=>Lt(et,w)),(Tt,Vt)=>F(Ft=>Lt(C(ft,Nt,!1),T("Just",Vt))))))})})));_()})()($._3&&!Q._3?C(Q._1,Q._2,!0):Q,n,r,o,i)),nt=$._1,V=$._2;return n(Q=>n(Y=>{const X=(D,F)=>{const B=D._3;return n(z=>B?o(D,F):G($,w))};return n(D=>n(F=>A(C(nt,V,!1),n,r,(B,z)=>X(C(B._1,B._2,!1),z),(B,z)=>n(j=>n(W=>I(B,n,r,(O,q)=>X(C(O._1,O._2,!1),q),(O,q)=>n(H=>{const ot=B._3&&!O._3?C(O._1,O._2,!0):O;return n(et=>G(ot,T("Just",q)))})))))))}))})})))})))})))})(),of=g0((()=>{const t=pt(Pt(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(a=>n(s=>t(e,n,r,o,(u,c)=>n(g=>n(l=>{const d=e._3&&!u._3?C(u._1,u._2,!0):u;return Tn(d,n,r,o,(f,h)=>n(m=>i(d._3&&!f._3?C(f._1,f._2,!0):f,h)))})))))})())(pt((()=>{const t=pt(Pt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>n(s=>Tn(e,n,r,o,(u,c)=>n(g=>n(l=>{const d=e._3&&!u._3?C(u._1,u._2,!0):u;return t(d,n,r,o,(f,h)=>n(m=>i(d._3&&!f._3?C(f._1,f._2,!0):f,h)))})))))})())("closing '}'")),tA=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>O0(C(i,a,!1),e,n,(u,c)=>{const g=u._3;return e(l=>{if(g)return r(u,c);const d=t._1,f=t._2;return e(h=>G4(C(d,f,!1),e,n,(m,p)=>{const x=m._3;return e(y=>x?r(m,p):Oe(t,e,n,r,o))},o))})},o))},Y0=(t,e,n,r,o)=>e(i=>oe(t,e,n,r,(a,s)=>e(u=>{const c=pt(Oe)("attribute key"),g=t._3&&!a._3?C(a._1,a._2,!0):a;return e(l=>c(g,e,n,r,(d,f)=>e(h=>{const m=g._3&&!d._3?C(d._1,d._2,!0):d;return e(p=>oe(m,e,n,r,(x,y)=>e(N=>{const v=pt(pt(Pt(k=>k===":"))("':'"))("':'"),J=m._3&&!x._3?C(x._1,x._2,!0):x;return e(k=>v(J,e,n,r,(S,A)=>e(I=>{const $=J._3&&!S._3?C(S._1,S._2,!0):S;return e(E=>oe($,e,n,r,(G,nt)=>e(V=>{const Q=pt(tA)("attribute value"),Y=$._3&&!G._3?C(G._1,G._2,!0):G;return e(X=>Q(Y,e,n,r,(D,F)=>e(B=>{const z=Y._3&&!D._3?C(D._1,D._2,!0):D;return e(j=>oe(z,e,n,r,(W,O)=>e(q=>o(z._3&&!W._3?C(W._1,W._2,!0):W,L(f,F)))))})))})))})))})))})))}))),eA=g0((()=>{const t=pt(Pt(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(a=>n(s=>t(e,n,r,o,(u,c)=>n(g=>n(l=>{const d=e._3&&!u._3?C(u._1,u._2,!0):u;return oe(d,n,r,o,(f,h)=>n(m=>i(d._3&&!f._3?C(f._1,f._2,!0):f,h)))})))))})())(pt((()=>{const t=pt(Pt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>n(s=>oe(e,n,r,o,(u,c)=>n(g=>n(l=>{const d=e._3&&!u._3?C(u._1,u._2,!0):u;return t(d,n,r,o,(f,h)=>n(m=>i(d._3&&!f._3?C(f._1,f._2,!0):f,h)))})))))})())("closing '}' for attributes"))((()=>{const t=pt(Pt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>{const s=(g,l)=>n(d=>(()=>{if(l.tag==="Just")return(f,h,m,p,x)=>x(f,M);if(l.tag==="Nothing")return(f,h,m,p,x)=>h(y=>Y0(f,h,m,p,(N,v)=>h(J=>{const k=Xe((()=>{const A=pt(Pt(I=>I===","))("','");return(I,$,E,G,nt)=>{const V=I._3;return $(Q=>$(Y=>$(X=>$(D=>$(F=>$(B=>oe(I,$,E,(z,j)=>G(C(z._1,z._2,V),j),(z,j)=>$(W=>$(O=>{const q=I._3&&!z._3?C(z._1,z._2,!0):z;return A(q,$,E,(H,ot)=>G(C(H._1,H._2,V),ot),(H,ot)=>$(et=>{const gt=q._3&&!H._3?C(H._1,H._2,!0):H;return $(Lt=>$(ft=>{const Nt=I._3&&!gt._3?C(gt._1,gt._2,!0):gt;return oe(Nt,$,E,(kt,jt)=>G(C(kt._1,kt._2,V),jt),(kt,jt)=>$(Tt=>{const Vt=Nt._3&&!kt._3?C(kt._1,kt._2,!0):kt;return $(Ft=>$(vt=>{const mt=I._3&&!Vt._3?C(Vt._1,Vt._2,!0):Vt;return Y0(mt,$,E,(lt,xt)=>G(C(lt._1,lt._2,V),xt),(lt,xt)=>$(Dt=>nt(mt._3&&!lt._3?C(lt._1,lt._2,!0):lt,xt)))}))}))}))}))})))))))))}})()),S=f._3&&!N._3?C(N._1,N._2,!0):N;return h(A=>k(S,h,m,p,(I,$)=>h(E=>x(S._3&&!I._3?C(I._1,I._2,!0):I,u4([v,...Wt(ue.foldr,$)])))))})));_()})()(e._3&&!g._3?C(g._1,g._2,!0):g,n,r,o,i)),u=e._1,c=e._2;return n(g=>n(l=>t(C(u,c,!1),n,r,(d,f)=>n(h=>s(e,w)),(d,f)=>n(h=>s(C(u,c,!1),T("Just",f))))))})})()),nA=(t,e,n,r,o)=>e(i=>oe(t,e,n,r,(a,s)=>e(u=>{const c=pt(Pt(l=>l==="{"))("'{'"),g=t._3&&!a._3?C(a._1,a._2,!0):a;return e(l=>{const d=(m,p)=>e(x=>(()=>{if(p.tag==="Just")return eA;if(p.tag==="Nothing")return(y,N,v,J,k)=>k(y,M);_()})()(g._3&&!m._3?C(m._1,m._2,!0):m,e,n,r,o)),f=g._1,h=g._2;return e(m=>e(p=>c(C(f,h,!1),e,n,(x,y)=>e(N=>d(g,w)),(x,y)=>e(N=>d(C(f,h,!1),T("Just",y))))))})}))),rA=t=>e=>(n,r,o,i,a)=>r(s=>Y4(n,r,o,i,(u,c)=>r(g=>{const l=n._3&&!u._3?C(u._1,u._2,!0):u;return r(d=>nA(l,r,o,i,(f,h)=>r(m=>a(l._3&&!f._3?C(f._1,f._2,!0):f,{op:Xn("AddNode",{id:t,label:c,shape:(()=>{const p=D0("shape")(h);if(p.tag==="Just")return p._1==="rectangle"||p._1==="rect"?go:p._1==="cylinder"||p._1==="cyl"?zy:p._1==="parallelogram"?Qy:p._1==="diamond"?Wy:p._1==="ellipse"?Oy:p._1==="document"||p._1==="doc"?Hy:p._1==="cloud"?$y:go;if(p.tag==="Nothing")return go;_()})(),width:(()=>{const p=D0("width")(h);if(p.tag==="Just")return Rf(p._1,ss,Ut,w);if(p.tag==="Nothing")return w;_()})()}),operands:[e]}))))}))),oA=(()=>{const t=pt(Pt(e=>e==="+"))("'+'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=pt(Jo)("space after '+'"),l=e._3&&!s._3?C(s._1,s._2,!0):s;return n(d=>g(l,n,r,o,(f,h)=>n(m=>{const p=Nn(pt(Oe)("node identifier after '+'")),x=l._3&&!f._3?C(f._1,f._2,!0):f;return n(y=>p(x,n,r,o,(N,v)=>n(J=>{const k=v._1,S=v._2,A=x._3&&!N._3?C(N._1,N._2,!0):N;return n(I=>Q0(A,n,r,o,($,E)=>n(G=>(()=>{if(E.tag==="Just")return U4(k)(S)(E._1);if(E.tag==="Nothing")return rA(k)(S);_()})()(A._3&&!$._3?C($._1,$._2,!0):$,n,r,o,i))))})))})))})))})(),iA=(t,e,n,r,o)=>e(i=>Un(t,e,n,r,(a,s)=>e(u=>{const c=pt(nf([yr("+node")("Node additions use `+ api: API`."),yr("+edge")("Graph edges use `+ api -> db`."),yr("+conn")("Undirected graph edges use `+ api -- db`."),yr("-node")("Node removals use `- api`."),yr("-edge")("Graph edge removals use `- api -> db`."),yr("-conn")("Undirected graph edge removals use `- api -- db`."),yr("~edge")("Graph edge repoints use `~ api -> db => api -> cache`."),yr("enter")("Dive commands use `into api`."),yr("exit")("Return from a dive with `out`."),S4,oA,H4,Z4,V4,X4,D4,F4]))("statement (+ node, - node, + edge, - edge, ~ node, into, out, or 'a ~> b'/'a <~ b')"),g=t._3&&!a._3?C(a._1,a._2,!0):a;return e(l=>c(g,e,n,r,(d,f)=>e(h=>{const m=g._3&&!d._3?C(d._1,d._2,!0):d;return e(p=>Un(m,e,n,r,(x,y)=>e(N=>{const v={line:s.line,column:s.column,endLine:y.line,endColumn:y.column};return o(m._3&&!x._3?C(x._1,x._2,!0):x,Fr("Leaf",{op:f.op,line:v.line,column:v.column,endLine:v.endLine,endColumn:v.endColumn,span:v,operands:f.operands}))})))})))}))),K0=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>Tn(t,e,n,(u,c)=>r(C(u._1,u._2,a),c),(u,c)=>e(g=>{const l=bo(pt(Pt(f=>f==="}"))("'}'")),d=t._3&&!u._3?C(u._1,u._2,!0):u;return e(f=>l(d,e,n,(h,m)=>r(C(h._1,h._2,a),m),(h,m)=>e(p=>bo(Vi)(d._3&&!h._3?C(h._1,h._2,!0):h,e,n,(x,y)=>r(C(x._1,x._2,a),y),(x,y)=>e(N=>{const v=t._3&&!x._3?C(x._1,x._2,!0):x;return e(J=>Du(v,e,n,r,(k,S)=>e(A=>{const I=nf([sA,aA,iA]),$=v._3&&!k._3?C(k._1,k._2,!0):k;return e(E=>I($,e,n,r,(G,nt)=>e(V=>{const Q=$._3&&!G._3?C(G._1,G._2,!0):G;return e(Y=>oe(Q,e,n,r,(X,D)=>e(F=>{const B=Q._3&&!X._3?C(X._1,X._2,!0):X;return e(z=>I0(B,e,n,r,(j,W)=>e(O=>{const q=B._3&&!j._3?C(j._1,j._2,!0):j;return e(H=>Tn(q,e,n,r,(ot,et)=>e(gt=>o(q._3&&!ot._3?C(ot._1,ot._2,!0):ot,nt))))})))})))})))})))})))))})))}),aA=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>{const u=(c,g)=>{const l=c._3;return e(d=>l?r(c,g):e(f=>{const h=t._3;return e(m=>En("seq")(t,e,n,(p,x)=>r(C(p._1,p._2,h),x),(p,x)=>e(y=>{const N=t._3&&!p._3?C(p._1,p._2,!0):p;return e(v=>oe(N,e,n,(J,k)=>r(C(J._1,J._2,h),k),(J,k)=>e(S=>Ya(N._3&&!J._3?C(J._1,J._2,!0):J,e,n,(A,I)=>r(C(A._1,A._2,h),I),(A,I)=>e($=>{const E=t._3&&!A._3?C(A._1,A._2,!0):A;return e(G=>Du(E,e,n,r,(nt,V)=>e(Q=>{const Y=pt(pt(Pt(D=>D==="{"))("'{'"))("'{'"),X=E._3&&!nt._3?C(nt._1,nt._2,!0):nt;return e(D=>Y(X,e,n,r,(F,B)=>e(z=>o(X._3&&!F._3?C(F._1,F._2,!0):F,Fr("GroupSeq",[])))))})))})))))})))}))};return e(c=>e(g=>En("seq")(C(i,a,!1),e,n,(l,d)=>u(C(l._1,l._2,!1),d),(l,d)=>e(f=>e(h=>oe(l,e,n,(m,p)=>u(C(m._1,m._2,!1),p),(m,p)=>e(x=>{const y=l._3&&!m._3?C(m._1,m._2,!0):m;return pt(Pt(N=>N==="{"))("'{'")(y,e,n,(N,v)=>u(C(y._1,y._2,!1),v),(N,v)=>e(J=>of(af(wE))(y,e,n,u,o)))})))))))})},sA=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>{const u=(c,g)=>{const l=c._3;return e(d=>l?r(c,g):e(f=>{const h=t._3;return e(m=>En("par")(t,e,n,(p,x)=>r(C(p._1,p._2,h),x),(p,x)=>e(y=>{const N=t._3&&!p._3?C(p._1,p._2,!0):p;return e(v=>oe(N,e,n,(J,k)=>r(C(J._1,J._2,h),k),(J,k)=>e(S=>Ya(N._3&&!J._3?C(J._1,J._2,!0):J,e,n,(A,I)=>r(C(A._1,A._2,h),I),(A,I)=>e($=>{const E=t._3&&!A._3?C(A._1,A._2,!0):A;return e(G=>Du(E,e,n,r,(nt,V)=>e(Q=>{const Y=pt(pt(Pt(D=>D==="{"))("'{'"))("'{'"),X=E._3&&!nt._3?C(nt._1,nt._2,!0):nt;return e(D=>Y(X,e,n,r,(F,B)=>e(z=>o(X._3&&!F._3?C(F._1,F._2,!0):F,Fr("Par",[])))))})))})))))})))}))};return e(c=>e(g=>En("par")(C(i,a,!1),e,n,(l,d)=>u(C(l._1,l._2,!1),d),(l,d)=>e(f=>e(h=>oe(l,e,n,(m,p)=>u(C(m._1,m._2,!1),p),(m,p)=>e(x=>{const y=l._3&&!m._3?C(m._1,m._2,!0):m;return pt(Pt(N=>N==="{"))("'{'")(y,e,n,(N,v)=>u(C(y._1,y._2,!1),v),(N,v)=>e(J=>of(af(yE))(y,e,n,u,o)))})))))))})},af=t=>{const e=Xe(K0);return(n,r,o,i,a)=>r(s=>e(n,r,o,i,(u,c)=>r(g=>a(n._3&&!u._3?C(u._1,u._2,!0):u,t(Wt(ue.foldr,c))))))},sf=t=>e=>(n,r,o,i,a)=>r(s=>R4(t)(n,r,o,i,(u,c)=>r(g=>{const l=Xe(Pt(h4)),d=n._3&&!u._3?C(u._1,u._2,!0):u;return r(f=>l(d,r,o,i,(h,m)=>r(p=>{const x=pt(pt(Pt(N=>N==="{"))("'{'"))("'{'"),y=d._3&&!h._3?C(h._1,h._2,!0):h;return r(N=>x(y,r,o,i,(v,J)=>r(k=>{const S=y._3&&!v._3?C(v._1,v._2,!0):v;return r(A=>Tn(S,r,o,i,(I,$)=>r(E=>{const G=af(xE),nt=S._3&&!I._3?C(I._1,I._2,!0):I;return r(V=>G(nt,r,o,i,(Q,Y)=>r(X=>{const D=nt._3&&!Q._3?C(Q._1,Q._2,!0):Q;return r(F=>Tn(D,r,o,i,(B,z)=>r(j=>{const W=pt(pt(Pt(q=>q==="}"))("'}'"))("closing '}'"),O=D._3&&!B._3?C(B._1,B._2,!0):B;return r(q=>W(O,r,o,i,(H,ot)=>r(et=>{const gt=O._3&&!H._3?C(H._1,H._2,!0):H;return r(Lt=>Tn(gt,r,o,i,(ft,Nt)=>r(kt=>a(gt._3&&!ft._3?C(ft._1,ft._2,!0):ft,{name:N4(In(Wt(ue.foldr,m))),ops:Y,kind:e}))))})))})))})))})))})))})))}))),uA=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>yr("keyframe")("Drop the `keyframe` wrapper; Markgraf animates statements in order.")(C(i,a,!1),e,n,(u,c)=>{const g=u._3;return e(l=>{if(g)return r(u,c);const d=t._1,f=t._2;return e(h=>sf("scene")(zu)(C(d,f,!1),e,n,(m,p)=>{const x=m._3;return e(y=>{if(x)return r(m,p);const N=t._1,v=t._2;return e(J=>sf("still")(j_)(C(N,v,!1),e,n,(k,S)=>{const A=k._3;return e(I=>A?r(k,S):sf("title")(mE)(t,e,n,r,o))},o))})},o))})},o))},cA=t=>e=>n=>{if(t==="AnimatedSurface")return{...e,frames:St(e.frames)({name:w,ops:n,kind:zu})};if(t==="StillSurface")return{...e,statements:St(e.statements)(n)};if(t==="SequenceSurface")return{...e,statements:St(e.statements)(n)};_()},gA=t=>e=>n=>{if(n.tag==="TopFrame"){const r=W0(t)(e);return{...r,frames:St(r.frames)((()=>{if(t==="AnimatedSurface")return n._1;if(t==="StillSurface")return{...n._1,kind:n._1.kind==="AnimatedKeyframe"?j_:n._1.kind==="StepMarker"?N0:n._1.kind};if(t==="SequenceSurface")return n._1;_()})())}}if(n.tag==="TopStatement")return cA(t)(e)(n._1);if(n.tag==="TopInside")return e;_()},_A=t=>{const e=b(gA(t))(b4);return n=>W0(t)(e(n)).frames},fA=t=>GS.defer(e=>{const n=$4(t);return(r,o,i,a,s)=>{const u=r._1,c=r._2;return o(g=>B4(t)(C(u,c,!1),o,i,(l,d)=>{const f=l._3;return o(h=>{if(f)return a(l,d);const m=r._1,p=r._2;return o(x=>o(y=>lA(C(m,p,!1),o,i,(N,v)=>{const J=N._3;return o(k=>{if(J)return a(N,v);const S=r._1,A=r._2;return o(I=>o($=>n(C(S,A,!1),o,i,(E,G)=>{const nt=E._3;return o(V=>{if(nt)return a(E,G);const Q=r._1,Y=r._2;return o(X=>o(D=>uA(C(Q,Y,!1),o,i,(F,B)=>{const z=F._3;return o(j=>z?a(F,B):o(W=>K0(r,o,i,a,(O,q)=>o(H=>s(O,Ou("TopStatement",q))))))},(F,B)=>o(z=>s(F,Ou("TopFrame",B))))))})},(E,G)=>o(nt=>s(E,Ou("TopFrame",G))))))})},(N,v)=>o(J=>s(N,Ou("TopInside",v))))))})},s))}}),lA=(t,e,n,r,o)=>e(i=>En("inside")(t,e,n,r,(a,s)=>e(u=>{const c=pt(Jo)("space after 'inside'"),g=t._3&&!a._3?C(a._1,a._2,!0):a;return e(l=>c(g,e,n,r,(d,f)=>e(h=>{const m=pt(Oe)("node identifier after 'inside'"),p=g._3&&!d._3?C(d._1,d._2,!0):d;return e(x=>m(p,e,n,r,(y,N)=>e(v=>{const J=p._3&&!y._3?C(y._1,y._2,!0):y;return e(k=>Tn(J,e,n,r,(S,A)=>e(I=>{const $=J._3&&!S._3?C(S._1,S._2,!0):S;return e(E=>of(j0)($,e,n,r,(G,nt)=>e(V=>{const Q=$._3&&!G._3?C(G._1,G._2,!0):G;return e(Y=>Tn(Q,e,n,r,(X,D)=>e(F=>o(Q._3&&!X._3?C(X._1,X._2,!0):X,{node:N,doc:nt}))))})))})))})))})))}))),j0=(t,e,n,r,o)=>e(i=>Q4(t,e,n,r,(a,s)=>e(u=>{const c=t._3&&!a._3?C(a._1,a._2,!0):a;return e(g=>{const l=(h,m)=>e(p=>{const x=Xe(fA(s)),y=c._3&&!h._3?C(h._1,h._2,!0):h;return e(N=>x(y,e,n,r,(v,J)=>e(k=>{const S=Wt(ue.foldr,J);return o(y._3&&!v._3?C(v._1,v._2,!0):v,{seed:(()=>{if(m.tag==="Nothing")return 0;if(m.tag==="Just")return m._1;_()})(),mode:s,frames:_A(s)(S),interiors:wt(A=>{if(A.tag==="TopInside")return T("Just",A._1);if(A.tag==="TopFrame"||A.tag==="TopStatement")return w;_()})(S)})})))}),d=c._1,f=c._2;return e(h=>e(m=>I4(C(d,f,!1),e,n,(p,x)=>{const y=p._3;return e(N=>y?r(p,x):l(c,w))},(p,x)=>e(y=>l(p,T("Just",x))))))})}))),dA=(()=>{const t=pt((e,n,r,o,i)=>n(a=>n(s=>Tn(e,n,r,o,(u,c)=>n(g=>n(l=>{const d=e._3&&!u._3?C(u._1,u._2,!0):u;return Vi(d,n,r,o,(f,h)=>n(m=>i(d._3&&!f._3?C(f._1,f._2,!0):f,h)))}))))))("'scene', 'still', 'title', 'step', 'inside', a statement, or end of input");return(e,n,r,o,i)=>n(a=>n(s=>n(u=>n(c=>Tn(e,n,r,o,(g,l)=>n(d=>n(f=>{const h=e._3&&!g._3?C(g._1,g._2,!0):g;return j0(h,n,r,o,(m,p)=>n(x=>{const y=h._3&&!m._3?C(m._1,m._2,!0):m;return n(N=>n(v=>{const J=e._3&&!y._3?C(y._1,y._2,!0):y;return t(J,n,r,o,(k,S)=>n(A=>i(J._3&&!k._3?C(k._1,k._2,!0):k,p)))}))}))})))))))})(),hA=t=>{const e=s0(t)(dA);if(e.tag==="Left")return It("Left",{msg:w4(e._1._1),line:e._1._2.line,column:e._1._2.column,endLine:e._1._2.line,endColumn:e._1._2.column+1|0});if(e.tag==="Right")return It("Right",e._1);_()},pA=t=>{const e=hA(t);if(e.tag==="Left")return It("Left",e._1.msg);if(e.tag==="Right")return It("Right",e._1);_()},mA=()=>({tag:"ParFrag"}),Z0=t=>t,yA=Z0("Sync"),xA=Z0("SelfMsg"),wA=mA(),Co=i0(Gn),An=ci(Gn),xr=Co.state(t=>L(t,t)),ko=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},tm=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},qu=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},Lo=gi(Gn),NA=t=>e=>b(n=>r=>ci(Gn).bind(n)(o=>t(o)(r)))(gi(Gn).pure(e)),em=io(Lo)(Mt),nm=t=>e=>Co.state(n=>L(void 0,{...n,lifelines:If(P)(r=>T("Just",{...r,label:Yi(e)}))(t)(n.lifelines),labelTemplates:it(P)(t)(e)(n.labelTemplates)})),Ka=t=>Co.state(e=>L(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:T("Just",t)};_()})())),TA=t=>e=>n=>An.bind(xr)(r=>{const o=ko(t)(r.labelTemplates);if(o.tag==="Nothing")return Ka("node "+t+" label has no placeholder `"+e+"`");if(o.tag==="Just"){const i=d0(e)(n)(o._1);if(i.tag==="Left")return Ka("node "+t+" "+i._1);if(i.tag==="Right")return nm(t)(i._1)}_()}),vA=t=>e=>{const n=Iu(e);if(n.tag==="Left")return Ka("invalid label for node "+t+": "+n._1);if(n.tag==="Right")return nm(t)(n._1);_()},bA=t=>e=>n=>{const r=ko(n)(t.lifelines);return ko(e)(t.lifelines).tag==="Nothing"?r.tag==="Nothing"?e+", "+n:e:r.tag==="Nothing"?n:""},JA={lifelines:M,labelTemplates:M,lifelineOrder:[],messages:[],fragments:[],frameEndRows:[],row:0,error:w},CA=t=>e=>n=>An.bind(xr)(r=>{const o=ko(t)(r.lifelines),i=ko(e)(r.lifelines);if(o.tag==="Just"&&i.tag==="Just"){const a={...r,messages:[{fromCol:o._1.column,toCol:i._1.column,labels:n,row:r.row,kind:t===e?xA:yA},...r.messages],row:r.row+1|0};return Co.state(s=>L(void 0,a))}return Ka("token references unknown node: "+bA(r)(t)(e))}),kA=t=>Co.state(e=>L(void 0,{...e,lifelines:If(P)(n=>T("Just",{...n,destroyedAt:T("Just",e.row)}))(t)(e.lifelines)})),LA=t=>e=>{const n=e.lifelineOrder.length,r=At(o=>w,o=>i=>T("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return{fromCol:0,toCol:qu(0)(e.lifelineOrder.length-1|0)};if(r.tag==="Just")return b(o=>i=>({fromCol:tm(o.fromCol)(tm(i.fromCol)(i.toCol)),toCol:qu(o.toCol)(qu(i.fromCol)(i.toCol))}))({fromCol:n,toCol:0})(t);_()},SA=t=>({lifelines:wt(e=>ko(e)(t.lifelines))(t.lifelineOrder),messages:re(t.messages),fragments:re(t.fragments),frameEndRows:t.frameEndRows,totalRows:t.row}),EA=t=>e=>An.bind(xr)(n=>{const r=ko(t)(n.lifelines);if(r.tag==="Just")return Lo.pure();if(r.tag==="Nothing"){const o={...n,lifelines:it(P)(t)({id:t,label:Yi(e),column:n.lifelineOrder.length,createdAt:n.row,destroyedAt:w})(n.lifelines),labelTemplates:it(P)(t)(e)(n.labelTemplates),lifelineOrder:St(n.lifelineOrder)(t),row:n.row>0||n.messages.length!==0?n.row+1|0:n.row};return Co.state(i=>L(void 0,o))}_()}),AA=t=>e=>An.bind(xr)(n=>{const r=ko(t)(n.lifelines);if(r.tag==="Just")return Lo.pure();if(r.tag==="Nothing"){const o=Iu(e);if(o.tag==="Left")return Ka("invalid label for node "+t+": "+o._1);if(o.tag==="Right")return EA(t)(o._1)}_()}),PA=t=>{if(t.tag==="AddNode")return AA(t._1.id)(t._1.label);if(t.tag==="DelNode")return kA(t._1.id);if(t.tag==="ModNode"){if(t._1.label.tag==="Just")return vA(t._1.id)(t._1.label._1);if(t._1.label.tag==="Nothing")return Lo.pure();_()}return t.tag==="ModNodeSlot"?TA(t._1.id)(t._1.slot)(t._1.value):t.tag==="Token"?CA(t._1.from)(t._1.to)(t._1.labels):Lo.pure()},RA=t=>An.bind(xr)(e=>{const n=e.row;return An.bind(NA(r=>o=>An.bind(xr)(i=>{const a=r.childMessages.length===0?r.dividers:[i.row,...r.dividers],s=i.messages;return An.bind(uf(o))(()=>An.bind(xr)(u=>Lo.pure({dividers:a,childMessages:[...r.childMessages,...(()=>{const c=u.messages.length-s.length|0;return c<1?[]:Rt(0,c,u.messages)})()]})))}))({dividers:[],childMessages:[]})(t))(r=>An.bind(xr)(o=>{const i=LA(r.childMessages)(o),a={kind:wA,label:"par",fromRow:n,toRow:qu(o.row)(n+1|0),fromCol:i.fromCol,toCol:i.toCol,regionDividers:re(r.dividers)},s=Co.state(u=>L(void 0,{...u,fragments:[a,...u.fragments]}));return r.childMessages.length>=2?s:Lo.pure()}))}),uf=t=>{if(t.tag==="Leaf")return PA(t._1.op);if(t.tag==="Seq"||t.tag==="GroupSeq")return em(uf)(t._1);if(t.tag==="Par")return RA(t._1);_()},GA=t=>{const e=An.bind(em(n=>An.bind(xr)(r=>An.bind(uf(n.ops))(()=>An.bind(xr)(o=>{const i=Co.state(a=>L(void 0,{...a,frameEndRows:St(a.frameEndRows)(a.row-1|0)}));return(o.messages.length-r.messages.length|0)>0?i:Lo.pure()}))))(t.frames))(()=>xr)(JA)._1;if(e.error.tag==="Just")return It("Left",e.error._1);if(e.error.tag==="Nothing")return It("Right",SA(e));_()},DA=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},FA={padding:24,headerHeight:36,headerWidth:120,columnSpacing:160,rowHeight:36,topGap:24,bottomGap:24},IA=t=>{const e=84+rt(DA(1)(t.totalRows))*36,n=Ot(r=>o=>({lifeline:o,x:84+rt(r)*160}))(t.lifelines);return{metrics:FA,columns:n,width:(()=>{const r=n.length-1|0;return r>=0&&r<n.length?n[r].x+84:48})(),height:e+48,headerTop:24,headerBottom:60,bodyTop:84,bodyBottom:e,diagram:t}},BA=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},rm=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},om=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}_()}return o},im=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},MA=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},zA=b(t=>e=>it(ut)(e)()(t))(M),QA={r:255,g:255,b:255,a:255},Uu={r:26,g:26,b:26,a:255},WA={color:{r:232,g:232,b:232,a:255},flat:!0},OA={r:232,g:232,b:232,a:255},Xu=t=>e=>n=>r=>o=>[1,t+o,e,2,n-o,e,3,n,e,n,e+o,2,n,r-o,3,n,r,n-o,r,2,t+o,r,3,t,r,t,r-o,2,t,e+o,3,t,e,t+o,e,...Ga],am=t=>e=>n=>({...n,stack:St(n.stack)(t),openedAt:it(ut)(t)(e)(n.openedAt)}),Vu=t=>e=>{const n=e.stack.length-1|0;if(n>=0&&n<e.stack.length){const r=BA(e.stack[n])(e.openedAt),o=(()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return r._1;_()})();return{...e,stack:e.stack.length===0?[]:Rt(0,e.stack.length-1|0,e.stack),openedAt:bi(ut)(e.stack[n])(e.openedAt),spans:St(e.spans)({col:e.stack[n],fromRow:o,toRow:rm(o)(t)})}}return e},sm=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,c=o,g=i,l=g.stack.length-1|0;if(l>=0&&l<g.stack.length){if(u(g.stack[l])){a=!1,s=g;continue}r=u,o=c,i=Vu(c)(g);continue}a=!1,s=g}return s},um=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r,u=s.stack.length-1|0;if(u>=0&&u<s.stack.length){n=a,r=Vu(a)(s);continue}o=!1,i=s}return i},HA=t=>e=>{const n=_n(ao)(e.fromCol)(t.stack)?sm((()=>{const r=e.fromCol;return o=>r===o})())(e.row-1|0)(t):am(e.fromCol)(e.row)(um(e.row-1|0)(t));if(_n(ao)(e.toCol)(n.stack)){const r=sm((()=>{const o=e.toCol;return i=>o===i})())(e.row-1|0)(Vu(e.row)(n));return{...r,returnRows:it(ut)(e.row)()(r.returnRows)}}return am(e.toCol)(e.row)(n)},$A=t=>e=>n=>{const r=HA(e)(n);return om(n.row)(t)?um(n.row)(r):r},Yu={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:Ra,lineCap:lr},cm={r:26,g:26,b:26,a:255},qA={color:{r:130,g:130,b:130,a:255},width:1,lineJoin:Ra,lineCap:Ln},gm={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:Ra,lineCap:Ln},UA={color:{r:244,g:244,b:244,a:255},flat:!0},_m=t=>e=>n=>ne(r=>r.col===e&&r.fromRow<=n&&n<=r.toRow,t),fm={color:{r:90,g:90,b:90,a:255},width:1,lineJoin:Ra,lineCap:Ln},XA={stack:[],openedAt:M,spans:[],returnRows:M},VA={color:{r:150,g:150,b:150,a:255},width:1,lineJoin:Ra,lineCap:Ln},YA=t=>e=>n=>r=>o=>{const i=e.bodyTop+(rt(o)+.5)*e.metrics.rowHeight-e.metrics.rowHeight/2;return t.strokePath([1,n,i,2,r,i])(VA)},KA=t=>{const e=t.Monad0(),n=e.Bind1(),r=yi(e.Applicative0())(Mt);return o=>i=>{const a=o.bodyTop+(rt(i.fromRow)+.5)*o.metrics.rowHeight-o.metrics.rowHeight/2-6,s=i.fromCol>=0&&i.fromCol<o.columns.length?o.columns[i.fromCol].x-16:o.metrics.padding-16,u=[1,s,a,2,s+38,a,2,s+32,a+14,2,s,a+14,...Ga],c=i.toCol>=0&&i.toCol<o.columns.length?o.columns[i.toCol].x+16:o.metrics.padding+16,g=o.bodyTop+(rt(rm(i.toRow)(i.fromRow+1|0)-1|0)+.5)*o.metrics.rowHeight+o.metrics.rowHeight/2+6;return n.bind(t.strokePath([1,s,a,2,c,a,2,c,g,2,s,g,...Ga])(fm))(()=>n.bind(t.fillStrokePath(u)(WA)(fm))(()=>n.bind(t.drawText({x:s+6,y:a+7,content:"par",font:{family:"Inter",size:11,weight:700},color:Uu,align:xo,baseline:xn}))(()=>r(i.regionDividers)(YA(t)(o)(s)(c)))))}},lm=t=>e=>t>=e?[]:[L(t,im(e)(t+6)),...lm(t+10)(e)],jA=t=>e=>{if(e<=t)return[];const n=r=>r>=e?[]:[L(r,im(e)(r+6)),...n(r+10)];return n(t)},ZA=t=>{const e=yi(t.Monad0().Applicative0())(Mt);return n=>r=>e(jA(n.headerTop+n.metrics.headerHeight+rt(r.lifeline.createdAt)*n.metrics.rowHeight+4)((()=>{if(r.lifeline.destroyedAt.tag==="Just")return n.bodyTop+(rt(r.lifeline.destroyedAt._1)+.5)*n.metrics.rowHeight;if(r.lifeline.destroyedAt.tag==="Nothing")return n.bodyBottom;_()})()))(o=>t.strokePath([1,r.x,o._1,2,r.x,o._2])(qA))},dm=t=>e=>t<=e?[]:[L(t,MA(e)(t-6)),...dm(t-6-4)(e)],tP=t=>e=>t===e?[]:t<e?lm(t)(e):dm(t)(e),eP=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.headerTop+rt(r.lifeline.createdAt)*n.metrics.rowHeight,i=n.metrics.headerWidth/2,a=o+n.metrics.headerHeight,s=Xu(r.x-i)(o)(r.x+i)(a)(6);return e.bind(t.fillStrokePath(Xu(r.x-i)(o+5)(r.x+i)(a+5)(6))({color:OA,flat:!0})(gm))(()=>e.bind(t.fillStrokePath(s)(UA)(gm))(()=>t.drawText({x:r.x,y:o+n.metrics.headerHeight/2,content:r.lifeline.label,font:{family:"Inter",size:14,weight:600},color:Uu,align:Zr,baseline:xn})))}},nP=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r,u=s.stack.length-1|0;if(u>=0&&u<s.stack.length){n=a,r=Vu(a)(s);continue}o=!1,i=s}return i},rP=t=>nP((()=>{const e=t.diagram.messages.length-1|0;return e>=0&&e<t.diagram.messages.length?t.diagram.messages[e].row:0})())(b($A(zA(t.diagram.frameEndRows)))(XA)(dt(e=>e.kind==="Sync"||e.kind!=="SelfMsg",t.diagram.messages))),oP=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.bodyTop+(rt(r.row)+.5)*n.metrics.rowHeight,i=r.fromCol>=0&&r.fromCol<n.columns.length?n.columns[r.fromCol].x:n.metrics.padding,a=o-n.metrics.rowHeight*.3,s=i+36,u=o+n.metrics.rowHeight*.3,c=i+10,g=[1,i,u,2,c,u-5,2,c,u+5,...Ga];return e.bind(t.strokePath([1,i,a,2,s,a,2,s,u,2,i,u])(Yu))(()=>e.bind(t.fillPath(g)({color:cm,flat:!0}))(()=>t.drawText({x:i+42,y:o,content:Qn(" ")(U(ea)(r.labels)),font:{family:"Inter",size:12,weight:400},color:Uu,align:xo,baseline:xn})))}},iP=t=>{const e=t.Monad0(),n=e.Bind1(),r=yi(e.Applicative0())(Mt);return o=>i=>a=>s=>{const u=a?o.bodyTop+(rt(s.row)+.5)*o.metrics.rowHeight+o.metrics.rowHeight*.5:o.bodyTop+(rt(s.row)+.5)*o.metrics.rowHeight,c=s.toCol>=s.fromCol?1:-1,g=(s.fromCol>=0&&s.fromCol<o.columns.length?o.columns[s.fromCol].x:o.metrics.padding)+(_m(i)(s.fromCol)(s.row)?c*6:c*0),l=(s.toCol>=0&&s.toCol<o.columns.length?o.columns[s.toCol].x:o.metrics.padding)-(_m(i)(s.toCol)(s.row)?c*6:c*0),d=l-c*10,f=a?t.strokePath([1,d,u-5,2,l,u,2,d,u+5])(Yu):t.fillPath([1,l,u,2,d,u-5,2,d,u+5,...Ga])({color:cm,flat:!0});return n.bind(a?r(tP(g)(l))(h=>t.strokePath([1,h._1,u,2,h._2,u])(Yu)):t.strokePath([1,g,u,2,l,u])(Yu))(()=>n.bind(f)(()=>t.drawText({x:(g+l)/2,y:u-6,content:Qn(" ")(U(ea)(s.labels)),font:{family:"Inter",size:12,weight:400},color:Uu,align:Zr,baseline:XC})))}},aP=t=>{const e=oP(t),n=iP(t);return r=>o=>i=>a=>{if(a.kind==="SelfMsg")return e(r)(a);if(a.kind==="Sync")return n(r)(o)(om(a.row)(i))(a);_()}},hm={color:{r:26,g:26,b:26,a:255},width:1.25,lineJoin:Ye,lineCap:Ln},sP={color:{r:232,g:232,b:232,a:255},flat:!0},uP={color:{r:252,g:252,b:252,a:255},flat:!0},cP=t=>e=>n=>{const r=n.col>=0&&n.col<e.columns.length?e.columns[n.col].x:e.metrics.padding,o=e.bodyTop+(rt(n.fromRow)+.5)*e.metrics.rowHeight,i=e.bodyTop+(rt(n.toRow)+.5)*e.metrics.rowHeight+e.metrics.rowHeight*.5,a=Xu(r-6)(o)(r+6)(i)(3);return t.Monad0().Bind1().bind(t.fillStrokePath(Xu(r-6)(o+5)(r+6)(i+5)(3))(sP)(hm))(()=>t.fillStrokePath(a)(uP)(hm))},pm=t=>{const e=t.Monad0(),n=e.Bind1(),r=yi(e.Applicative0())(Mt),o=eP(t),i=ZA(t),a=KA(t),s=aP(t);return u=>{const c=rP(u);return n.bind(t.setViewport({vx:0,vy:0,vw:u.width,vh:u.height}))(()=>n.bind(t.clearBackground(QA))(()=>n.bind(r(u.columns)(o(u)))(()=>n.bind(r(u.columns)(i(u)))(()=>n.bind(r(c.spans)(cP(t)(u)))(()=>n.bind(r(u.diagram.fragments)(a(u)))(()=>r(u.diagram.messages)(s(u)(c.spans)(c.returnRows))))))))}},gP=pm(_3);function mm(t){return function(e){return function(){return t.add(e)}}}function cf(t,e,n,r){if(typeof window<"u"){var o=window[n];if(o!=null&&r instanceof o)return e(r)}for(var i=r;i!=null;){var a=Object.getPrototypeOf(i),s=a.constructor.name;if(s===n)return e(r);if(s==="Object")return t;i=a}return t}function ym(t){return function(){return t.classList}}function pn(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function _P(t){return function(e){return function(){return e.getAttribute(t)}}}const xm=t=>{const e=_P(t);return n=>{const r=e(n);return()=>{const o=r();return Jn(o,w,Ut)}}};function fP(t){return function(e){return function(){e.textContent=t}}}function lP(t){return function(){return function(e){return t(e)()}}}function dP(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const gf=function(){return window};function hP(t){return function(e){return function(){e.value=t}}}function pP(t){return function(){return t.valueAsNumber}}function mP(t){return function(){return t.value}}function _f(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const Ku=t=>t,ju=t=>()=>{const e=t.getBoundingClientRect?.(),n=e?.width||t.clientWidth||0,r=e?.height||t.clientHeight||0;return{width:n,height:r}},wm=t=>e=>()=>{let n=0;const r=()=>{n||(n=requestAnimationFrame(()=>{n=0,e()}))},o=typeof ResizeObserver>"u"?null:new ResizeObserver(r);return o?.observe(t),window.addEventListener("resize",r),()=>{n&&cancelAnimationFrame(n),o?.disconnect(),window.removeEventListener("resize",r)}},Nm=()=>window.devicePixelRatio||1,Tm=()=>performance.now()/1e3,yP=t=>e=>n=>r=>o=>()=>{const i=Math.max(1,e||t.clientWidth||r),a=Math.max(1,n||t.clientHeight||o),s="Markgraf needs more room",u=`Resize to at least ${Math.round(r)} \xD7 ${Math.round(o)} px`;if(t.setAttribute("data-mg-too-small","1"),t.setAttribute("data-mg-viewport-css-width",String(e||0)),t.setAttribute("data-mg-viewport-css-height",String(n||0)),t.setAttribute("data-mg-camera-vw","0"),t.setAttribute("data-mg-camera-vh","0"),t.setAttribute("data-mg-camera-zoom","0"),t instanceof SVGElement){t.setAttribute("viewBox",`0 0 ${i} ${a}`),t.setAttribute("preserveAspectRatio","xMidYMid meet"),t.innerHTML=`
13
+ }`);const n=t.op._1;return ke.state(r=>L(void 0,{...r,enterStack:St(r.enterStack)(n.id),scenes:St(r.scenes)(Pi("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=Or(e.enterStack);if(n.tag==="Nothing")return xr("`out` without a matching `into`");if(n.tag==="Just"){const r=n._1.init;return ke.state(o=>L(void 0,{...o,enterStack:r,scenes:St(o.scenes)(qy)}))}g()}return pe.pure()}g()})),Fu={structural:[],flow:!1,dives:[]},A4=$t.bind(Ke)(t=>{if(t.error.tag==="Just")return pe.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return ke.state(n=>L(void 0,{...n,scenes:St(n.scenes)(Pi("Hold",e))}))}if(t.currentKf.tag==="Nothing")return pe.pure()}g()}),R4=t=>e=>$t.bind(Ke)(n=>{const r="ev-"+ae(n.eventCounter);return $t.bind((()=>{const o={...n,eventCounter:n.eventCounter+1|0};return ke.state(i=>L(void 0,o))})())(()=>pe.pure({events:[{id:r,kind:e,when:t}],firstId:N("Just",r),lastId:N("Just",r)}))}),D4=t=>t.tag==="DataFlow"?N("Just",t._1):w,F4=t=>wt(e=>O_(e)(t.graphEdges))(Ot(Ni,d0(t.currEdges))),I4=t=>e=>{const n=lt(o=>o.from.node===e.id||o.to.node===e.id,F4(t)),r=Ru(df)(o=>i=>{const a=i.from+"->"+e.id,s=e.id+"->"+i.to,u=i.from+"->"+i.to,c="via "+i.from+" "+i.to+": no edge "+i.from+"\u2192"+e.id;if(!yr(a)(t.currEdges))return It("Left",c);const _="via "+i.from+" "+i.to+": no edge "+e.id+"\u2192"+i.to;if(!yr(s)(t.currEdges))return It("Left",_);const l="via "+i.from+" "+i.to+": would create "+i.from+"\u2192"+i.to+" but it already exists";return yr(u)(t.currEdges)||n4(u)(o.synthesized)?It("Left",l):It("Right",{consumed:it(A)(a)()(it(A)(s)()(o.consumed)),synthesized:it(A)(u)({id:u,from:{node:i.from,port:w},to:{node:i.to,port:w},label:w})(o.synthesized)})})({consumed:Q,synthesized:Q})(e.via);return(()=>{if(r.tag==="Left"){const o=r._1;return i=>It("Left",o)}if(r.tag==="Right"){const o=r._1;return i=>i(o)}g()})()(o=>{const i=o.consumed,a=lt(s=>!yr(s.id)(i),n);return a.length===0?It("Right",{nextCurrEdges:Oe(A.compare,Qe,cr(A.compare,t.currEdges,r4(Y(s=>s.id)(n))),o4((()=>{const s=u=>{if(u.tag==="Leaf")return Q;if(u.tag==="Node")return ee("Node",u._1,u._2,u._3,void 0,s(u._5),s(u._6));g()};return s(o.synthesized)})())),synthesized:o.synthesized}):It("Left","cannot delete node "+e.id+": still connected ("+Wn(", ")(Y(s=>(()=>{const u=Zn("conn:")(s.id);if(u.tag==="Just")return!1;if(u.tag==="Nothing")return!0;g()})()?s.from.node+"\u2192"+s.to.node:s.from.node+"--"+s.to.node)(a))+"). Use `- a -> b` or `- a -- b` to drop them, or `via a b` to merge "+e.id+"'s endpoints.")})},J0=t=>e=>n=>{if(t){if(e){const i=0<n.operands.length?n.operands[0]:n.span,a=1<n.operands.length?n.operands[1]:n.span;return{line:i.line,column:i.column,endLine:a.endLine,endColumn:a.endColumn}}return 0<n.operands.length?n.operands[0]:n.span}if(e)return 1<n.operands.length?n.operands[1]:n.span;const r=0<n.operands.length?n.operands[0]:n.span,o=1<n.operands.length?n.operands[1]:n.span;return{line:r.line,column:r.column,endLine:o.endLine,endColumn:o.endColumn}},C0=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq"||t.tag==="GroupSeq")return Et(t._1)(C0);g()},B4=t=>({nodes:Y(Ua)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,pt("Cons",n._4,e(n._6,r)));g()};return Ot(ue.foldr,e(t.graphEdges,G))})(),constraints:[]}),Y_=t=>{if(t.tag==="Leaf")return t._1.op.tag==="AddNode"||t._1.op.tag==="DelNode"||t._1.op.tag==="ModNode"||t._1.op.tag==="ModNodeSlot"||t._1.op.tag==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?{...Fu,structural:[t._1]}:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?{...Fu,dives:[t._1]}:{...Fu,flow:!0};if(t.tag==="Seq"||t.tag==="GroupSeq"||t.tag==="Par")return J(T4)(Fu)(Y(Y_)(t._1));g()},Iu=t=>{if(t.tag==="Leaf")return t._1.op.tag==="AddNode"||t._1.op.tag==="DelNode"||t._1.op.tag==="ModNode"||t._1.op.tag==="ModNodeSlot"||t._1.op.tag==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?[yi("StepStructural",[t._1])]:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?[yi("StepDive",t._1)]:[yi("StepFlow",t)];if(t.tag==="Seq")return Et(t._1)(Iu);if(t.tag==="GroupSeq")return z4(t)(t._1);if(t.tag==="Par")return Q4(t)(t._1);g()},Q4=t=>e=>{const n=Y_(t);return n.structural.length!==0&&!n.flow&&n.dives.length===0?[yi("StepStructural",n.structural)]:n.structural.length===0&&n.flow&&n.dives.length===0?[yi("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?Y(m0)(n.dives):Et(e)(Iu)},z4=t=>e=>{const n=Y_(t);return n.structural.length===0&&n.flow&&n.dives.length===0?[yi("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?Y(m0)(n.dives):Et(e)(Iu)},M4=t=>e=>$t.bind(Ke)(n=>{const r=e.from+"->"+e.to,o=e.newFrom+"->"+e.newTo;return yr(r)(n.currEdges)?mr(e.newFrom)(n.currNodes)?mr(e.newTo)(n.currNodes)?r!==o&&yr(o)(n.currEdges)?We((()=>{const i=2<t.operands.length?t.operands[2]:t.span,a=3<t.operands.length?t.operands[3]:t.span;return{line:i.line,column:i.column,endLine:a.endLine,endColumn:a.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists"):ke.state(i=>L(void 0,{...i,currEdges:it(A)(o)()(Li(A)(r)(i.currEdges)),graphEdges:it(A)(o)({id:o,from:{node:e.newFrom,port:w},to:{node:e.newTo,port:w},label:w})(i.graphEdges)})):We(3<t.operands.length?t.operands[3]:t.span)("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo):We(2<t.operands.length?t.operands[2]:t.span)("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newFrom):We((()=>{const i=0<t.operands.length?t.operands[0]:t.span,a=1<t.operands.length?t.operands[1]:t.span;return{line:i.line,column:i.column,endLine:a.endLine,endColumn:a.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist")}),O4=t=>e=>{const n=wt(D4)(e.scenes),r=lt(N4(i4(Y(a=>a.keyframe)(n))),e.keyframes),o=cr(A.compare,H_(a=>a.nodes)(r),H_(b4)(n)),i=cr(A.compare,$_(a=>a.edges)(r),$_(L4)(n));return t!=="AnimatedSurface"||n.length===0||o.tag==="Leaf"&&i.tag==="Leaf"?w:N("Just",J4(e)(o)(i))},W4=t=>e=>{const n=e.to+"->"+e.from,r=e.from+"->"+e.to,o=e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;if(yr(r)(t.currEdges))return N("Just",{id:r,direction:Zf});if(yr(n)(t.currEdges))return N("Just",{id:n,direction:jf});const i=O_(o)(t.graphEdges);if(i.tag==="Just")return yr(o)(t.currEdges)?N("Just",{id:o,direction:i._1.from.node===e.from&&i._1.to.node===e.to?Zf:jf}):w;if(i.tag==="Nothing")return w;g()},q4=t=>e=>{if(e.op.tag==="Token"){const n=e.op._1;return $t.bind(Ke)(r=>{const o=!mr(n.from)(r.currNodes),i=!mr(n.to)(r.currNodes);if(o||i)return $t.bind(We(J0(o)(i)(e))(o?i?"token references unknown node: "+n.from+", "+n.to:"token references unknown node: "+n.from:i?"token references unknown node: "+n.to:"token references unknown node: "))(()=>pe.pure({events:[],firstId:w,lastId:w}));const a=W4(r)(n);if(a.tag==="Just")return R4(t)(zy("SendToken",{from:n.from,to:n.to,edge:a._1.id,direction:a._1.direction,labels:n.labels}));if(a.tag==="Nothing")return $t.bind(We((()=>{const s=0<e.operands.length?e.operands[0]:e.span,u=1<e.operands.length?e.operands[1]:e.span;return{line:s.line,column:s.column,endLine:u.endLine,endColumn:u.endColumn}})())("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>pe.pure({events:[],firstId:w,lastId:w}));g()})}return pe.pure({events:[],firstId:w,lastId:w})},H4=t=>e=>{const n=Pt(r=>w,r=>o=>N("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return pe.pure({events:[],firstId:w,lastId:w});if(n.tag==="Just"){const r=n._1.tail;return $t.bind(Ha(t)(n._1.head))(o=>$t.bind(Ru({Applicative0:()=>mi(In),Bind1:()=>pi(In)})(i=>a=>$t.bind(Ha((()=>{if(i.lastId.tag==="Just")return Ac("After",i.lastId._1);if(i.lastId.tag==="Nothing")return t;g()})())(a))(s=>pe.pure({events:[...i.events,...s.events],firstId:(()=>{if(i.firstId.tag==="Just")return N("Just",i.firstId._1);if(i.firstId.tag==="Nothing")return s.firstId;g()})(),lastId:(()=>{if(s.lastId.tag==="Just")return N("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return i.lastId;g()})()})))(o)(r))(i=>pe.pure(i)))}g()},$4=t=>e=>{const n=Pt(r=>w,r=>o=>N("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return pe.pure({events:[],firstId:w,lastId:w});if(n.tag==="Just"){const r=n._1.tail;return $t.bind(Ha(t)(n._1.head))(o=>$t.bind(Y4((()=>{if(o.firstId.tag==="Just")return Ac("With",o.firstId._1);if(o.firstId.tag==="Nothing")return t;g()})())(r))(i=>pe.pure({events:[...o.events,...i.events],firstId:o.firstId,lastId:(()=>{if(o.lastId.tag==="Just")return N("Just",o.lastId._1);if(o.lastId.tag==="Nothing")return i.lastId;g()})()})))}g()},Ha=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return $t.bind((()=>{const r=n.span;return ke.state(o=>L(void 0,{...o,currentSpan:r}))})())(()=>q4(t)(n))}if(e.tag==="Seq"||e.tag==="GroupSeq")return H4(t)(e._1);if(e.tag==="Par")return $4(t)(e._1);g()},Y4=t=>Ru({Applicative0:()=>mi(In),Bind1:()=>pi(In)})(e=>n=>$t.bind(Ha(t)(n))(r=>pe.pure({events:[...e.events,...r.events],firstId:(()=>{if(e.firstId.tag==="Just")return N("Just",e.firstId._1);if(e.firstId.tag==="Nothing")return r.firstId;g()})(),lastId:(()=>{if(r.lastId.tag==="Just")return N("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;g()})()})))({events:[],firstId:w,lastId:w}),V4=t=>$t.bind(Ke)(e=>{if(e.currentKf.tag==="Nothing")return xr("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return $t.bind(Ha(Wy)(t))(r=>$t.bind(Ke)(o=>{const i={...o,scenes:St(o.scenes)(Pi("DataFlow",{keyframe:n,events:r.events,focus:w}))};return ke.state(a=>L(void 0,i))}))}g()}),X4=t=>e=>ke.state(n=>L(void 0,{...n,graphNodes:p4(t.id)({id:t.id,size:w4(t.width),ports:[],label:N("Just",Zi(e)),shape:t.shape})(n.graphNodes),currNodes:it(A)(t.id)()(n.currNodes),currLabels:it(A)(t.id)(Zi(e))(n.currLabels),currLabelTemplates:it(A)(t.id)(e)(n.currLabelTemplates)})),U4=t=>{if(t.op.tag==="AddNode"){const e=t.op._1;return $t.bind(Ke)(n=>{if(mr(e.id)(n.currNodes))return We(0<t.operands.length?t.operands[0]:t.span)("cannot add node "+e.id+": already exists");const r=Gu(e.label);if(r.tag==="Left")return We(0<t.operands.length?t.operands[0]:t.span)("invalid label for node "+e.id+": "+r._1);if(r.tag==="Right")return X4(e)(r._1);g()})}if(t.op.tag==="DelNode"){const e=t.op._1;return $t.bind(Ke)(n=>{if(!mr(e.id)(n.currNodes))return We(0<t.operands.length?t.operands[0]:t.span)("cannot delete node "+e.id+": does not exist");const r=I4(n)(e);if(r.tag==="Left")return We(0<t.operands.length?t.operands[0]:t.span)(r._1);if(r.tag==="Right"){const o=r._1;return ke.state(i=>L(void 0,{...i,currNodes:Li(A)(e.id)(i.currNodes),currEdges:o.nextCurrEdges,graphEdges:Oe(A.compare,Qe,o.synthesized,i.graphEdges)}))}g()})}if(t.op.tag==="ModNode"){const e=t.op._1;return $t.bind(Ke)(n=>{if(!mr(e.id)(n.currNodes))return We(0<t.operands.length?t.operands[0]:t.span)("cannot relabel node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=Gu(e.label._1);if(r.tag==="Left")return We(0<t.operands.length?t.operands[0]:t.span)("invalid label for node "+e.id+": "+r._1);if(r.tag==="Right")return w0(e.id)(r._1);g()}if(e.label.tag==="Nothing")return pe.pure();g()})}if(t.op.tag==="ModNodeSlot"){const e=t.op._1;return $t.bind(Ke)(n=>{if(!mr(e.id)(n.currNodes))return We(0<t.operands.length?t.operands[0]:t.span)("cannot update placeholder on node "+e.id+": does not exist");const r=f0(e.id)(n.currLabelTemplates);if(r.tag==="Nothing")return We(1<t.operands.length?t.operands[1]:t.span)("node "+e.id+" label has no placeholder `"+e.slot+"`");if(r.tag==="Just"){const o=c0(e.slot)(e.value)(r._1);if(o.tag==="Left")return We(1<t.operands.length?t.operands[1]:t.span)("node "+e.id+" "+o._1);if(o.tag==="Right")return w0(e.id)(o._1)}g()})}if(t.op.tag==="AddEdge"){const e=t.op._1;return $t.bind(Ke)(n=>{const r=!mr(e.from)(n.currNodes),o=!mr(e.to)(n.currNodes);if(r||o)return We(J0(r)(o)(t))((e.directed?"cannot add edge ":"cannot add connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": unknown node "+(r?o?e.from+", "+e.to:e.from:o?e.to:""));const i=e.directed?e.from+"->"+e.to:e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;return yr(i)(n.currEdges)?We((()=>{const a=0<t.operands.length?t.operands[0]:t.span,s=1<t.operands.length?t.operands[1]:t.span;return{line:a.line,column:a.column,endLine:s.endLine,endColumn:s.endColumn}})())((e.directed?"cannot add edge ":"cannot add connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": already exists"):ke.state(a=>L(void 0,{...a,graphEdges:it(A)(i)({id:i,from:{node:e.from,port:w},to:{node:e.to,port:w},label:e.label})(a.graphEdges),currEdges:it(A)(i)()(a.currEdges)}))})}if(t.op.tag==="DelEdge"){const e=t.op._1;return $t.bind(Ke)(n=>{const r=e.directed?e.from+"->"+e.to:e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;return yr(r)(n.currEdges)?ke.state(o=>L(void 0,{...o,currEdges:Li(A)(r)(o.currEdges)})):We((()=>{const o=0<t.operands.length?t.operands[0]:t.span,i=1<t.operands.length?t.operands[1]:t.span;return{line:o.line,column:o.column,endLine:i.endLine,endColumn:i.endColumn}})())((e.directed?"cannot delete edge ":"cannot delete connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": does not exist")})}return t.op.tag==="RepointEdge"?M4(t)(t.op._1):pe.pure()},K4=t=>$t.bind((()=>{const e=t.span;return ke.state(n=>L(void 0,{...n,currentSpan:e}))})())(()=>U4(t)),b0=t=>e=>n=>$t.bind(W_(K4)(n))(()=>$t.bind(Ke)(r=>{const o=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ae(r.kfCounter);if(ne(a=>a.id===o,r.keyframes))return $t.bind(a4(y4)(0<n.length?N("Just",n[0]):w))(()=>xr("duplicate frame name "+o));const i={...r,keyframes:St(r.keyframes)({id:o,nodes:r.currNodes,edges:r.currEdges,labels:y0(r),kind:t}),kfCounter:r.kfCounter+1|0,currentKf:N("Just",o),scenes:(()=>{if(r.currentKf.tag==="Nothing")return r.scenes;if(r.currentKf.tag==="Just")return St(r.scenes)(Pi("Structural",{from:r.currentKf._1,to:o,focus:w}));g()})()};return ke.state(a=>L(void 0,i))})),Z4=t=>e=>n=>{if(n.tag==="StepStructural")return $t.bind((()=>{const r=b0(ca)(e?w:t)(n._1);return n._1.length!==0?r:pe.pure()})())(()=>pe.pure(!0));if(n.tag==="StepFlow"){const r=n._1,o=!e&&(()=>{if(t.tag==="Just")return t._1!=="";if(t.tag==="Nothing")return!1;g()})();return $t.bind((()=>{const i=E4(t);return o?i:pe.pure()})())(()=>$t.bind(V4(r))(()=>pe.pure(e||o)))}if(n.tag==="StepDive")return $t.bind(G4(n._1))(()=>pe.pure(e));g()},k0=t=>e=>n=>{const r=Pt(o=>w,o=>i=>N("Just",{head:o,tail:i}),n);if(r.tag==="Nothing")return pe.pure();if(r.tag==="Just"){const o=r._1.head,i=r._1.tail;return $t.bind(Ke)(a=>{if(a.error.tag==="Just")return pe.pure();if(a.error.tag==="Nothing")return $t.bind(Z4(t)(e)(o))(s=>k0(t)(s)(i));g()})}g()},L0=t=>e=>{const n=C0(e.ops),r=lt(i=>i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="ModNodeSlot"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge",n),o=lt(i=>!(i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="ModNodeSlot"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge"),n);return 0<o.length?$t.bind((()=>{const i=o[0].span;return ke.state(a=>L(void 0,{...a,currentSpan:i}))})())(()=>xr("still/title blocks hold a still snapshot; they cannot contain movement tokens (`api ~> db`) or dive commands (`into`/`out`)")):t==="TitleCard"&&r.length===0?xr(e.name.tag==="Just"&&e.name._1!==""?'title "'+e.name._1+'" has an empty body; give it nodes/edges to title, or use a still':"title has an empty body; give it nodes/edges to title, or use a still"):$t.bind(b0(t)(e.name)(r))(()=>A4)},j4=t=>$t.bind(Ke)(e=>{if(e.error.tag==="Just")return pe.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return k0(t.name)(!1)(Iu(t.ops));if(t.kind==="Still")return L0(My)(t);if(t.kind==="Title")return L0(Oy)(t);if(t.kind==="StepMarker")return P4(t)}g()}),S0=t=>$t.bind(S4(t.interiors))(()=>$t.bind(W_(j4)(t.frames))(()=>$t.bind(Ke)(e=>{if(e.error.tag==="Just")return pe.pure(It("Left",e.error._1));if(e.error.tag==="Nothing"){const n=tE(t.interiors);if(n.tag==="Left")return pe.pure(It("Left",n._1));if(n.tag==="Right"){const r={seed:t.seed,graph:B4(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1};return pe.pure((()=>{const o=O4(t.mode)(r);if(o.tag==="Just")return It("Left",{msg:o._1,line:0,column:0,endLine:0,endColumn:0});if(o.tag==="Nothing")return It("Right",r);g()})())}}g()}))),tE=t=>{const e=Ru(df)(n=>r=>{const o=S0(r.doc)(T0)._1;return(()=>{if(o.tag==="Left"){const i=o._1;return a=>It("Left",i)}if(o.tag==="Right"){const i=o._1;return a=>a(i)}g()})()(i=>It("Right",it(A)(r.node)(i)(n)))})(Q)(t);if(e.tag==="Left")return It("Left",e._1);if(e.tag==="Right")return It("Right",e._1);g()},Bu=(t,e)=>({tag:t,_1:e}),V_=FS(Qt),eE=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},nE=ge(A)(Qt),E0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},$a=(()=>{const t=mt(Gt(r=>r==="}"))("'}'"),e=mt(Gt(r=>r==="#"))("'#'"),n=Gt(r=>r===`
14
+ `||r==="\r");return(r,o,i,a,s)=>{const u=r._1,c=r._2;return o(_=>o(l=>t(k(u,c,!1),o,i,(f,d)=>o(h=>{const m=r._1,p=r._2;return o(x=>o(y=>e(k(m,p,!1),o,i,(T,v)=>o(b=>{const C=r._1,S=r._2;return o(P=>o(F=>n(k(C,S,!1),o,i,(W,E)=>o(R=>Ki(r,o,i,a,s)),(W,E)=>o(R=>s(k(C,S,!1),void 0)))))}),(T,v)=>o(b=>s(k(m,p,!1),void 0)))))}),(f,d)=>o(h=>s(k(u,c,!1),void 0)))))}})(),Jn=t=>(e,n,r,o,i)=>n(a=>Xn(e,n,r,o,(s,u)=>n(c=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>t(_,n,r,o,(f,d)=>n(h=>{const m=_._3&&!f._3?k(f._1,f._2,!0):f;return n(p=>Xn(m,n,r,o,(x,y)=>n(T=>i(m._3&&!x._3?k(x._1,x._2,!0):x,L(d,{line:u.line,column:u.column,endLine:y.line,endColumn:y.column})))))})))}))),rE=(()=>{const t=Gt(e=>e===" "||e===" "||e===`
15
+ `||e==="\r");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>i(e._3&&!s._3?k(s._1,s._2,!0):s,void 0))))})(),P0=(t,e,n,r,o)=>e(i=>Le("#")(t,e,n,r,(a,s)=>e(u=>{const c=Ue(Gt(l=>l!==`
16
+ `)),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>c(_,e,n,r,(f,d)=>e(h=>o(_._3&&!f._3?k(f._1,f._2,!0):f,void 0))))}))),G0=mt((()=>{const t=mt(Gt(n=>n==="}"))("'}'"),e=Gt(n=>n===`
17
+ `||n==="\r");return(n,r,o,i,a)=>{const s=n._1,u=n._2;return r(c=>r(_=>t(k(s,u,!1),r,o,(l,f)=>r(d=>{const h=n._1,m=n._2;return r(p=>r(x=>P0(k(h,m,!1),r,o,(y,T)=>{const v=y._3;return r(b=>{if(v)return i(y,T);const C=n._1,S=n._2;return r(P=>r(F=>e(k(C,S,!1),r,o,(W,E)=>{const R=W._3;return r(et=>R?i(W,E):Ki(n,r,o,i,a))},(W,E)=>r(R=>a(W,void 0)))))})},(y,T)=>r(v=>a(y,void 0)))))}),(l,f)=>r(d=>a(k(s,u,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),Cn=(()=>{const t=Ue((e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>rE(k(a,s,!1),n,r,(c,_)=>{const l=c._3;return n(f=>l?o(c,_):P0(e,n,r,o,i))},i))});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>i(e._3&&!s._3?k(s._1,s._2,!0):s,void 0))))})(),A0=(()=>{const t=Gt(e=>e!=="|");return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>n(c=>Le("\\|")(k(a,s,!1),n,r,(_,l)=>n(f=>n(d=>t(e,n,r,o,(h,m)=>n(p=>i(h,fr(m)))))),(_,l)=>n(f=>i(_,"|")))))}})(),oE=mt(V_([(t,e,n,r,o)=>e(i=>{const a=t._3;return Le("->")(t,e,n,(s,u)=>r(k(s._1,s._2,a),u),(s,u)=>e(c=>o(s,!0)))}),(t,e,n,r,o)=>e(i=>{const a=t._3;return Le("--")(t,e,n,(s,u)=>r(k(s._1,s._2,a),u),(s,u)=>e(c=>o(s,!1)))})]))("edge arrow '->' or '--'"),iE=t=>t!==`
18
+ `&&t!=="\r"&&t!=="#"&&t!=="}"&&t!=="{",Qu=Gt(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),aE=t=>t===" "||t===" "||t==="\r",sE=t=>Qn(re(Jr(aE)(re(zn(t))).rest)),X_=t=>t===`
19
+ `||t==="\r"||t==="#"||t==="}",uE=t=>t===`
20
+ `||t==="\r"||t==="#"||t==="}"||t==="{",cE=t=>t!=="{"&&t!==`
21
+ `&&t!=="\r",R0=t=>da(t)==="",gE=t=>re(Jr(R0)(re(Jr(R0)(t).rest)).rest),_E=t=>(e=>n=>{let r=e,o=n,i=!0,a;for(;i;){const s=r,u=Pt(c=>w,c=>_=>N("Just",{head:c,tail:_}),o);if(u.tag==="Just"&&(u._1.head===" "||u._1.head===" ")){r=s+1|0,o=u._1.tail;continue}i=!1,a=s}return a})(0)(zn(t)),fE=t=>{const e=Pt(n=>w,n=>r=>N("Just",{head:n,tail:r}),Y(_E)(lt(n=>da(n)!=="",t)));if(e.tag==="Nothing")return 0;if(e.tag==="Just")return J(eE)(e._1.head)(e._1.tail);g()},dE=(()=>{const t=mt(Gt(e=>e==="-"))("'-'");return(e,n,r,o,i)=>{const a=e._3;return n(s=>t(e,n,r,(u,c)=>o(k(u._1,u._2,a),c),(u,c)=>n(_=>{const l=Po((()=>{const d=mt(Gt(m=>m===">"))("'>'"),h=mt(Gt(m=>m==="-"))("'-'");return(m,p,x,y,T)=>{const v=m._1,b=m._2;return p(C=>d(k(v,b,!1),p,x,(S,P)=>{const F=S._3;return p(W=>F?y(S,P):h(m,p,x,y,T))},T))}})()),f=e._3&&!u._3?k(u._1,u._2,!0):u;return n(d=>l(f,n,r,(h,m)=>o(k(h._1,h._2,a),m),(h,m)=>n(p=>i(f._3&&!h._3?k(h._1,h._2,!0):h,"-"))))})))}})(),oe=(()=>{const t=Ue(Gt(e=>e===" "||e===" "));return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>i(e._3&&!s._3?k(s._1,s._2,!0):s,void 0))))})(),Go=(()=>{const t=Gt(e=>e===" "||e===" ");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>oe(e._3&&!s._3?k(s._1,s._2,!0):s,n,r,o,i))))})(),D0=(t,e,n,r,o)=>e(i=>e(a=>oe(t,e,n,r,(s,u)=>e(c=>e(_=>{const l=t._3&&!s._3?k(s._1,s._2,!0):s;return $a(l,e,n,r,(f,d)=>e(h=>o(l._3&&!f._3?k(f._1,f._2,!0):f,d)))}))))),F0=(t,e,n,r,o)=>e(i=>oe(t,e,n,r,(a,s)=>e(u=>{const c=mt(Gt(l=>l==="-"))("'-'"),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>{const f=(m,p)=>e(x=>(()=>{if(p.tag==="Just")return(y,T,v,b,C)=>T(S=>oE(y,T,v,b,(P,F)=>T(W=>C(P,N("Just",F)))));if(p.tag==="Nothing")return(y,T,v,b,C)=>C(y,w);g()})()(_._3&&!m._3?k(m._1,m._2,!0):m,e,n,r,o)),d=_._1,h=_._2;return e(m=>e(p=>c(k(d,h,!1),e,n,(x,y)=>e(T=>f(_,w)),(x,y)=>e(T=>f(k(d,h,!1),N("Just",y))))))})}))),lE=t=>{const e=Zn("Expected ")(t),n=(()=>{if(e.tag==="Nothing")return t;if(e.tag==="Just")return e._1;g()})();return n==="'{'"?"Open the block with `{`.":n==="integer (seed value)"?"Put an integer after `seed`.":n==="closing '}'"?"Close this block with `}`.":n===`closing '"' (unterminated string)`?'This string is unterminated; close it with `"`.':n==="closing '|'"?"Close this pipe label with `|`.":n==="space after '+'"?"Put a space after `+`: `+ api: API`.":n==="node identifier after '+'"?"Put a node id after `+`: `+ api: API`.":n==="space after '-'"?"Put a space after `-`: `- api`.":n==="node identifier after '-'"?"Put a node id after `-`: `- api`.":n==="space after '~'"?"Put a space after `~`: `~ api: API` or `~ api -> db => api -> cache`.":n==="node relabel label"?"Give the replacement label after `~ api`: `~ api: API`.":n==="node placeholder value"?"Give the replacement value after the placeholder name: `~ total.count: 3`.":n==="node identifier"?"Put a node identifier here.":n==="space after 'inside'"?"Put a space after `inside`: `inside api { ... }`.":n==="node identifier after 'inside'"?"Tell `inside` which node owns this interior: `inside api { ... }`.":n==="source node identifier after 'via'"?"Put the source node after `via`: `via a b`.":n==="target node identifier after 'via'"?"Put the second endpoint after `via`: `via a b`.":n==="source node identifier"?"Put a source node identifier here.":n==="new source node identifier"?"Put the new source node identifier after `=>`.":n==="new target node identifier"?"Put the new target node identifier after the replacement arrow.":n==="edge arrow '->' or '--'"?"Use `->` for a directed edge or `--` for an undirected edge.":n==="source edge arrow '->'"?"Use `->` in the edge you are changing: `~ api -> db => api -> cache`.":n==="replacement edge arrow '->'"?"Use `->` in the replacement edge: `~ api -> db => api -> cache`.":n==="repoint separator '=>'"?"Use `=>` before the replacement edge: `~ api -> db => api -> cache`.":n==="target node identifier"?"Put a target node after the arrow.":n==="'~>'"?"Use `~>` for movement from left to right.":n==="'<~'"?"Use `<~` for movement from right to left.":n==="'->' or '<-'"?"Use `~>` / `<~` for movement tokens.":n==='label ("\u2026", : rest-of-line, or |\u2026|)'?'label must use `: text`, `"text"`, or `|multi-line|`.':n==="attribute key"?"Start each attribute with a name, like `shape`.":n==="':'"?"Put `:` between the attribute name and value: `{shape: cylinder}`.":n==="attribute value"?"Put an attribute value after `:`.":n==="closing '}' for attributes"?"Close the attribute block with `}`.":n==="space after 'into'"?"Put a space after `into`: `into api`.":n==="node identifier after 'into'"?"Tell `into` which node to dive into.":n==="space after 'step'"?"Put a space after `step`: `step request`.":n==="step name"?"Name the step: `step request`.":n==="newline or '}' (statements end at the end of the line)"?"This statement has extra text. Put the next statement on a new line or close the block with `}`.":n==="statement (+ node, - node, + edge, - edge, ~ node, into, out, or 'a ~> b'/'a <~ b')"?"I don't recognize this statement. Start with `+`, `-`, `~`, `into`, `out`, `par`, `seq`, or movement like `api ~> db`.":n==="'scene', 'still', 'title', 'step', 'inside', a statement, or end of input"?"Start with a statement like `+ api: API`, a marker like `step request`, or a block with `scene`, `still`, `title`, or `inside`.":n},hE=t=>{const e=da(t),n=Zn('"')(e),r=(()=>{if(n.tag==="Just")return _y('"')(n._1);if(n.tag==="Nothing")return w;g()})(),o=(()=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()})();return o===""?w:N("Just",o)},I0=t=>e=>t!=="AnimatedSurface"&&e.statements.length!==0?{...e,frames:St(e.frames)((()=>{if(t==="StillSurface")return{name:w,ops:Br("Seq",e.statements),kind:q_};if(t==="SequenceSurface")return{name:w,ops:Br("Seq",e.statements),kind:Du};if(t==="AnimatedSurface")return{name:w,ops:Br("Seq",e.statements),kind:Du};g()})()),statements:[]}:e,pE=(()=>{const t=mt(Gt(e=>e==="\\"))("'\\\\'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>z_(_,n,r,o,(f,d)=>n(h=>i(_._3&&!f._3?k(f._1,f._2,!0):f,d==="n"?`
22
+ `:d==="t"?" ":d==="r"?"\r":d))))})))})(),mE=(()=>{const t=Gt(e=>e!=='"'&&e!=="\\"&&e!==`
23
+ `);return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>pE(k(a,s,!1),n,r,(c,_)=>n(l=>t(e,n,r,o,i)),i))}})(),B0=(()=>{const t=mt(Gt(e=>e==='"'))(`'"'`);return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const _=Ue(mE),l=e._3&&!s._3?k(s._1,s._2,!0):s;return n(f=>_(l,n,r,o,(d,h)=>n(m=>{const p=mt(mt(Gt(y=>y==='"'))(`'"'`))(`closing '"' (unterminated string)`),x=l._3&&!d._3?k(d._1,d._2,!0):d;return n(y=>p(x,n,r,o,(T,v)=>n(b=>i(x._3&&!T._3?k(T._1,T._2,!0):T,Qn(Ot(ue.foldr,h))))))})))})))})(),yE={frames:[],statements:[]},Q0=t=>{const e=gE(Ho(`
24
+ `)(t));return Wn(`
25
+ `)(Y(sE)(Y(Si(fE(e)))(e)))},xE=(t,e,n,r,o)=>{const i=t._3;return e(a=>Le("|md")(t,e,n,(s,u)=>r(k(s._1,s._2,i),u),(s,u)=>e(c=>{const _=mt((f,d,h,m,p)=>{const x=f._1,y=f._2;return d(T=>Le(`\r
26
+ `)(k(x,y,!1),d,h,(v,b)=>{const C=v._3;return d(S=>{if(C)return m(v,b);const P=f._1,F=f._2;return d(W=>Le(`
27
+ `)(k(P,F,!1),d,h,(E,R)=>{const et=E._3;return d(rt=>et?m(E,R):Le("\r")(f,d,h,m,p))},p))})},p))})("newline after '|md'"),l=t._3&&!s._3?k(s._1,s._2,!0):s;return e(f=>_(l,e,n,(d,h)=>r(k(d._1,d._2,i),h),(d,h)=>e(m=>{const p=Ue(A0),x=l._3&&!d._3?k(d._1,d._2,!0):d;return e(y=>p(x,e,n,(T,v)=>r(k(T._1,T._2,i),v),(T,v)=>e(b=>{const C=mt(mt(Gt(P=>P==="|"))("'|'"))("closing '|'"),S=x._3&&!T._3?k(T._1,T._2,!0):T;return e(P=>C(S,e,n,(F,W)=>r(k(F._1,F._2,i),W),(F,W)=>e(E=>o(S._3&&!F._3?k(F._1,F._2,!0):F,"md:"+Q0(Wn("")(Ot(ue.foldr,v)))))))})))})))})))},wE=(()=>{const t=mt(Gt(e=>e==="|"))("'|'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const _=Ue(A0),l=e._3&&!s._3?k(s._1,s._2,!0):s;return n(f=>_(l,n,r,o,(d,h)=>n(m=>{const p=mt(mt(Gt(y=>y==="|"))("'|'"))("closing '|'"),x=l._3&&!d._3?k(d._1,d._2,!0):d;return n(y=>p(x,n,r,o,(T,v)=>n(b=>i(x._3&&!T._3?k(T._1,T._2,!0):T,Q0(Wn("")(Ot(ue.foldr,h)))))))})))})))})(),xi=Gt(t=>t>="0"&&t<="9"),TE=(()=>{const t=mt(Gt(e=>e==="_"))("'_'");return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>Qu(k(a,s,!1),n,r,(c,_)=>{const l=c._3;return n(f=>{if(l)return o(c,_);const d=e._1,h=e._2;return n(m=>xi(k(d,h,!1),n,r,(p,x)=>{const y=p._3;return n(T=>{if(y)return o(p,x);const v=e._1,b=e._2;return n(C=>t(k(v,b,!1),n,r,(S,P)=>{const F=S._3;return n(W=>F?o(S,P):dE(e,n,r,o,i))},i))})},i))})},i))}})(),qe=(()=>{const t=mt(Gt(e=>e==="_"))("'_'");return(e,n,r,o,i)=>n(a=>{const s=(_,l)=>n(f=>{const d=Ue(TE),h=e._3&&!_._3?k(_._1,_._2,!0):_;return n(m=>d(h,n,r,o,(p,x)=>n(y=>i(h._3&&!p._3?k(p._1,p._2,!0):p,fr(l)+Qn(Ot(ue.foldr,x))))))}),u=e._1,c=e._2;return n(_=>Qu(k(u,c,!1),n,r,(l,f)=>{const d=l._3;return n(h=>d?o(l,f):t(e,n,r,o,s))},s))})})(),NE=t=>e=>n=>(r,o,i,a,s)=>o(u=>oe(r,o,i,a,(c,_)=>o(l=>{const f=Jn(mt(qe)("target node identifier")),d=r._3&&!c._3?k(c._1,c._2,!0):c;return o(h=>f(d,o,i,a,(m,p)=>o(x=>s(d._3&&!m._3?k(m._1,m._2,!0):m,{op:Un("DelEdge",{from:t,to:p._1,directed:n}),operands:[e,p._2]}))))}))),vE=(t,e,n,r,o)=>e(i=>Xn(t,e,n,r,(a,s)=>e(u=>{const c=t._3&&!a._3?k(a._1,a._2,!0):a;return e(_=>{const l=c._3;return e(f=>qe(c,e,n,(d,h)=>r(k(d._1,d._2,l),h),(d,h)=>e(m=>{const p=c._3&&!d._3?k(d._1,d._2,!0):d;return e(x=>oe(p,e,n,(y,T)=>r(k(y._1,y._2,l),T),(y,T)=>e(v=>{const b=p._3&&!y._3?k(y._1,y._2,!0):y;return e(C=>{const S=(W,E)=>e(R=>{const et=b._3&&!W._3?k(W._1,W._2,!0):W;return e(rt=>r(c._3&&!et._3?k(et._1,et._2,!0):et,sr("Use `~>` / `<~` for movement tokens.",s)))}),P=b._1,F=b._2;return e(W=>Le("->")(k(P,F,!1),e,n,(E,R)=>{const et=E._3;return e(rt=>et?r(k(E._1,E._2,l),R):Le("<-")(b,e,n,($,X)=>r(k($._1,$._2,l),X),S))},S))})})))})))})}))),JE=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>Jn(qe)(t,e,n,(u,c)=>r(k(u._1,u._2,a),c),(u,c)=>e(_=>{const l=t._3&&!u._3?k(u._1,u._2,!0):u;return e(f=>oe(l,e,n,(d,h)=>r(k(d._1,d._2,a),h),(d,h)=>e(m=>{const p=mt(Gt(y=>y==="~"))("'~'"),x=l._3&&!d._3?k(d._1,d._2,!0):d;return e(y=>{const T=(C,S)=>e(P=>{const F=x._3&&!C._3?k(C._1,C._2,!0):C;return e(W=>{const E=c._1,R=c._2,et=t._3&&!F._3?k(F._1,F._2,!0):F;return e(rt=>oe(et,e,n,r,($,X)=>e(V=>{const D=mt(Gt(M=>M==="~"))("'~'"),B=mt(Gt(M=>M==="<"))("'<'"),I=et._3&&!$._3?k($._1,$._2,!0):$;return e(M=>{const j=(H,O)=>e(ot=>{const tt=O==="~"?mt(Le("~>"))("'~>'"):mt(Le("<~"))("'<~'"),gt=I._3&&!H._3?k(H._1,H._2,!0):H;return e(Lt=>tt(gt,e,n,r,(ft,Tt)=>e(kt=>o(gt._3&&!ft._3?k(ft._1,ft._2,!0):ft,L(E,L(R,Tt))))))}),z=I._1,q=I._2;return e(H=>D(k(z,q,!1),e,n,(O,ot)=>{const tt=O._3;return e(gt=>tt?r(I,ot):B(I,e,n,(Lt,ft)=>r(I,ft),(Lt,ft)=>j(I,ft)))},(O,ot)=>j(I,ot)))})})))})}),v=x._1,b=x._2;return e(C=>p(k(v,b,!1),e,n,(S,P)=>{const F=S._3;return e(W=>F?r(k(x._1,x._2,a),P):e(E=>Le("<~")(x,e,n,(R,et)=>r(k(x._1,x._2,a),et),(R,et)=>e(rt=>T(x)))))},(S,P)=>T(x)))})})))})))}),CE=t=>e=>{const n=mt(Le("->"))("source edge arrow '->'");return(r,o,i,a,s)=>o(u=>n(r,o,i,a,(c,_)=>o(l=>{const f=r._3&&!c._3?k(c._1,c._2,!0):c;return o(d=>oe(f,o,i,a,(h,m)=>o(p=>{const x=Jn(mt(qe)("target node identifier")),y=f._3&&!h._3?k(h._1,h._2,!0):h;return o(T=>x(y,o,i,a,(v,b)=>o(C=>{const S=b._1,P=b._2,F=y._3&&!v._3?k(v._1,v._2,!0):v;return o(W=>oe(F,o,i,a,(E,R)=>o(et=>{const rt=mt(Le("=>"))("repoint separator '=>'"),$=F._3&&!E._3?k(E._1,E._2,!0):E;return o(X=>rt($,o,i,a,(V,D)=>o(B=>{const I=$._3&&!V._3?k(V._1,V._2,!0):V;return o(M=>oe(I,o,i,a,(j,z)=>o(q=>{const H=Jn(mt(qe)("new source node identifier")),O=I._3&&!j._3?k(j._1,j._2,!0):j;return o(ot=>H(O,o,i,a,(tt,gt)=>o(Lt=>{const ft=gt._1,Tt=gt._2,kt=O._3&&!tt._3?k(tt._1,tt._2,!0):tt;return o(Kt=>oe(kt,o,i,a,(Nt,Xt)=>o(Ft=>{const vt=mt(Le("->"))("replacement edge arrow '->'"),yt=kt._3&&!Nt._3?k(Nt._1,Nt._2,!0):Nt;return o(dt=>vt(yt,o,i,a,(xt,Dt)=>o(ht=>{const Jt=yt._3&&!xt._3?k(xt._1,xt._2,!0):xt;return o(Mt=>oe(Jt,o,i,a,(Bt,ie)=>o(ce=>{const dn=Jn(mt(qe)("new target node identifier")),Ht=Jt._3&&!Bt._3?k(Bt._1,Bt._2,!0):Bt;return o(jt=>dn(Ht,o,i,a,(sn,He)=>o(Dn=>s(Ht._3&&!sn._3?k(sn._1,sn._2,!0):sn,{op:Un("RepointEdge",{from:t,to:S,newFrom:ft,newTo:He._1}),operands:[e,P,Tt,He._2]}))))})))})))})))})))})))})))})))})))})))})))},bE=(t,e,n,r,o)=>e(i=>xi(t,e,n,r,(a,s)=>e(u=>{const c=Ue(xi),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>c(_,e,n,r,(f,d)=>e(h=>{const m=C2(fr(s)+Qn(Ot(ue.foldr,d)));return(()=>{if(m.tag==="Just"){const p=m._1;return(x,y,T,v,b)=>b(x,p)}if(m.tag==="Nothing")return(p,x,y,T,v)=>v(p,0);g()})()(_._3&&!f._3?k(f._1,f._2,!0):f,e,n,r,o)})))}))),kE=t=>(e,n,r,o,i)=>{const a=e._3;return n(s=>Le(t)(e,n,r,(u,c)=>o(k(u._1,u._2,a),c),(u,c)=>n(_=>{const l=Po((()=>{const d=mt(Gt(m=>m==="_"))("'_'"),h=mt(Gt(m=>m==="-"))("'-'");return(m,p,x,y,T)=>{const v=m._1,b=m._2;return p(C=>Qu(k(v,b,!1),p,x,(S,P)=>{const F=S._3;return p(W=>{if(F)return y(S,P);const E=m._1,R=m._2;return p(et=>xi(k(E,R,!1),p,x,(rt,$)=>{const X=rt._3;return p(V=>{if(X)return y(rt,$);const D=m._1,B=m._2;return p(I=>d(k(D,B,!1),p,x,(M,j)=>{const z=M._3;return p(q=>z?y(M,j):h(m,p,x,y,T))},T))})},T))})},T))}})()),f=e._3&&!u._3?k(u._1,u._2,!0):u;return n(d=>l(f,n,r,(h,m)=>o(k(h._1,h._2,a),m),(h,m)=>n(p=>{const x=f._3&&!h._3?k(h._1,h._2,!0):h;return n(y=>Cn(x,n,r,(T,v)=>o(k(T._1,T._2,a),v),(T,v)=>n(b=>i(x._3&&!T._3?k(T._1,T._2,!0):T,t))))})))})))},LE=(t,e,n,r,o)=>e(i=>xi(t,e,n,r,(a,s)=>e(u=>{const c=Ue((()=>{const l=mt(Gt(f=>f==="."))("'.'");return(f,d,h,m,p)=>{const x=f._1,y=f._2;return d(T=>xi(k(x,y,!1),d,h,(v,b)=>{const C=v._3;return d(S=>C?m(v,b):l(f,d,h,m,p))},p))}})()),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>c(_,e,n,r,(f,d)=>e(h=>o(_._3&&!f._3?k(f._1,f._2,!0):f,fr(s)+Qn(Ot(ue.foldr,d))))))}))),An=t=>(e,n,r,o,i)=>{const a=e._3;return n(s=>Le(t)(e,n,r,(u,c)=>o(k(u._1,u._2,a),c),(u,c)=>n(_=>{const l=Po((()=>{const d=mt(Gt(m=>m==="_"))("'_'"),h=mt(Gt(m=>m==="-"))("'-'");return(m,p,x,y,T)=>{const v=m._1,b=m._2;return p(C=>Qu(k(v,b,!1),p,x,(S,P)=>{const F=S._3;return p(W=>{if(F)return y(S,P);const E=m._1,R=m._2;return p(et=>xi(k(E,R,!1),p,x,(rt,$)=>{const X=rt._3;return p(V=>{if(X)return y(rt,$);const D=m._1,B=m._2;return p(I=>d(k(D,B,!1),p,x,(M,j)=>{const z=M._3;return p(q=>z?y(M,j):h(m,p,x,y,T))},T))})},T))})},T))}})()),f=e._3&&!u._3?k(u._1,u._2,!0):u;return n(d=>l(f,n,r,(h,m)=>o(k(h._1,h._2,a),m),(h,m)=>n(p=>i(f._3&&!h._3?k(h._1,h._2,!0):h,void 0))))})))},SE=(t,e,n,r,o)=>e(i=>An("into")(t,e,n,r,(a,s)=>e(u=>{const c=mt(Go)("space after 'into'"),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>c(_,e,n,r,(f,d)=>e(h=>{const m=Jn(mt(qe)("node identifier after 'into'")),p=_._3&&!f._3?k(f._1,f._2,!0):f;return e(x=>m(p,e,n,r,(y,T)=>e(v=>o(p._3&&!y._3?k(y._1,y._2,!0):y,{op:Un("Enter",{id:T._1}),operands:[T._2]}))))})))}))),EE=(t,e,n,r,o)=>e(i=>An("out")(t,e,n,r,(a,s)=>e(u=>o(t._3&&!a._3?k(a._1,a._2,!0):a,{op:g4,operands:[]})))),PE=(t,e,n,r,o)=>e(i=>An("seed")(t,e,n,r,(a,s)=>e(u=>{const c=t._3&&!a._3?k(a._1,a._2,!0):a;return e(_=>oe(c,e,n,r,(l,f)=>e(d=>{const h=mt(bE)("integer (seed value)"),m=c._3&&!l._3?k(l._1,l._2,!0):l;return e(p=>h(m,e,n,r,(x,y)=>e(T=>{const v=m._3&&!x._3?k(x._1,x._2,!0):x;return e(b=>Cn(v,e,n,r,(C,S)=>e(P=>o(v._3&&!C._3?k(C._1,C._2,!0):C,y))))})))})))}))),z0=(t,e,n,r,o)=>{const i=t._3;return e(a=>An("diagram")(t,e,n,(s,u)=>r(k(s._1,s._2,i),u),(s,u)=>e(c=>{const _=mt(Go)("space after 'diagram'"),l=t._3&&!s._3?k(s._1,s._2,!0):s;return e(f=>_(l,e,n,(d,h)=>r(k(d._1,d._2,i),h),(d,h)=>e(m=>{const p=mt(An("sequence"))("diagram mode"),x=l._3&&!d._3?k(d._1,d._2,!0):d;return e(y=>p(x,e,n,(T,v)=>r(k(T._1,T._2,i),v),(T,v)=>e(b=>{const C=x._3&&!T._3?k(T._1,T._2,!0):T;return e(S=>D0(C,e,n,(P,F)=>r(k(P._1,P._2,i),F),(P,F)=>e(W=>o(C._3&&!P._3?k(P._1,P._2,!0):P,c4))))})))})))})))},M0=(t,e,n,r,o)=>{const i=t._3;return e(a=>An("still")(t,e,n,(s,u)=>r(k(s._1,s._2,i),u),(s,u)=>e(c=>{const _=t._3&&!s._3?k(s._1,s._2,!0):s;return e(l=>D0(_,e,n,(f,d)=>r(k(f._1,f._2,i),d),(f,d)=>e(h=>o(_._3&&!f._3?k(f._1,f._2,!0):f,u4))))})))},O0=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>M0(k(i,a,!1),e,n,(u,c)=>{const _=u._3;return e(l=>_?r(u,c):z0(t,e,n,r,o))},o))},GE=t=>(e,n,r,o,i)=>n(a=>Xn(e,n,r,o,(s,u)=>n(c=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>{const f=_._3;return O0(_,n,r,(d,h)=>o(k(d._1,d._2,f),h),(d,h)=>n(m=>o(_._3&&!d._3?k(d._1,d._2,!0):d,sr((()=>{if(t==="AnimatedSurface")return"Put diagram mode headers at the top of the document.";if(t==="AnimatedSurface")return"This document already declares `animation`; choose one diagram mode.";if(t==="StillSurface")return"This document already declares `still`; choose one diagram mode.";if(t==="SequenceSurface")return"This document already declares `diagram sequence`; choose one diagram mode.";g()})(),u))))})}))),AE=t=>(e,n,r,o,i)=>n(a=>Xn(e,n,r,o,(s,u)=>n(c=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>{const f=(m,p)=>n(x=>(()=>{if(p.tag==="Just"){const y=(()=>{if(t==="AnimatedSurface")return"This document already declares `animation`; choose one diagram mode.";if(t==="StillSurface")return"This document already declares `still`; choose one diagram mode.";if(t==="SequenceSurface")return"This document already declares `diagram sequence`; choose one diagram mode.";g()})();return(T,v,b,C,S)=>C(T,sr(y,u))}if(p.tag==="Nothing")return(y,T,v,b,C)=>C(y,void 0);g()})()(_._3&&!m._3?k(m._1,m._2,!0):m,n,r,o,i)),d=_._1,h=_._2;return n(m=>n(p=>O0(k(d,h,!1),n,r,(x,y)=>{const T=x._3;return n(v=>T?o(x,y):f(_,w))},(x,y)=>n(T=>f(x,N("Just",y))))))})}))),RE=(t,e,n,r,o)=>e(i=>{const a=(c,_)=>e(l=>{const f=t._3&&!c._3?k(c._1,c._2,!0):c;return e(d=>Cn(f,e,n,r,(h,m)=>e(p=>{const x=f._3&&!h._3?k(h._1,h._2,!0):h;return e(y=>AE(_)(x,e,n,r,(T,v)=>e(b=>o(x._3&&!T._3?k(T._1,T._2,!0):T,_))))})))}),s=t._1,u=t._2;return e(c=>M0(k(s,u,!1),e,n,(_,l)=>{const f=_._3;return e(d=>f?r(_,l):z0(t,e,n,r,a))},a))}),DE=(t,e,n,r,o)=>e(i=>{const a=(c,_)=>e(l=>o(c,(()=>{if(_.tag==="Nothing")return s4;if(_.tag==="Just")return _._1;g()})())),s=t._1,u=t._2;return e(c=>e(_=>RE(k(s,u,!1),e,n,(l,f)=>{const d=l._3;return e(h=>d?r(l,f):a(t,w))},(l,f)=>e(d=>a(l,N("Just",f))))))}),FE=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>oe(t,e,n,(u,c)=>r(k(u._1,u._2,a),c),(u,c)=>e(_=>An("via")(t._3&&!u._3?k(u._1,u._2,!0):u,e,n,(l,f)=>r(k(l._1,l._2,a),f),(l,f)=>e(d=>{const h=t._3&&!l._3?k(l._1,l._2,!0):l;return e(m=>Eu(h,e,n,r,(p,x)=>e(y=>{const T=h._3&&!p._3?k(p._1,p._2,!0):p;return e(v=>Go(T,e,n,r,(b,C)=>e(S=>{const P=mt(qe)("source node identifier after 'via'"),F=T._3&&!b._3?k(b._1,b._2,!0):b;return e(W=>P(F,e,n,r,(E,R)=>e(et=>{const rt=F._3&&!E._3?k(E._1,E._2,!0):E;return e($=>oe(rt,e,n,r,(X,V)=>e(D=>{const B=mt(qe)("target node identifier after 'via'"),I=rt._3&&!X._3?k(X._1,X._2,!0):X;return e(M=>B(I,e,n,r,(j,z)=>e(q=>o(I._3&&!j._3?k(j._1,j._2,!0):j,{from:R,to:z}))))})))})))})))})))})))))}),IE=t=>e=>{const n=Ue(FE);return(r,o,i,a,s)=>o(u=>n(r,o,i,a,(c,_)=>o(l=>s(r._3&&!c._3?k(c._1,c._2,!0):c,{op:Un("DelNode",{id:t,via:Ot(ue.foldr,_)}),operands:[e]}))))},BE=(()=>{const t=mt(Gt(e=>e==="-"))("'-'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const _=mt(Go)("space after '-'"),l=e._3&&!s._3?k(s._1,s._2,!0):s;return n(f=>_(l,n,r,o,(d,h)=>n(m=>{const p=Jn(mt(qe)("node identifier after '-'")),x=l._3&&!d._3?k(d._1,d._2,!0):d;return n(y=>p(x,n,r,o,(T,v)=>n(b=>{const C=v._1,S=v._2,P=x._3&&!T._3?k(T._1,T._2,!0):T;return n(F=>F0(P,n,r,o,(W,E)=>n(R=>(()=>{if(E.tag==="Just")return NE(C)(S)(E._1);if(E.tag==="Nothing")return IE(C)(S);g()})()(P._3&&!W._3?k(W._1,W._2,!0):W,n,r,o,i))))})))})))})))})(),wr=t=>e=>(n,r,o,i,a)=>r(s=>Xn(n,r,o,i,(u,c)=>r(_=>{const l=n._3&&!u._3?k(u._1,u._2,!0):u;return r(f=>An(t)(l,r,o,i,(d,h)=>r(m=>i(l._3&&!d._3?k(d._1,d._2,!0):d,sr(e,c)))))}))),QE=t=>t==="AnimatedSurface"?(e,n,r,o,i)=>n(a=>Xn(e,n,r,o,(s,u)=>n(c=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>An("step")(_,n,r,o,(f,d)=>n(h=>{const m=mt(Go)("space after 'step'"),p=_._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(p,n,r,o,(y,T)=>n(v=>{const b=Jn(mt(qe)("step name")),C=p._3&&!y._3?k(y._1,y._2,!0):y;return n(S=>b(C,n,r,o,(P,F)=>n(W=>{const E=F._1,R=F._2,et=C._3&&!P._3?k(P._1,P._2,!0):P;return n(rt=>Xn(et,n,r,o,($,X)=>n(V=>{const D=et._3&&!$._3?k($._1,$._2,!0):$;return n(B=>oe(D,n,r,o,(I,M)=>n(j=>{const z=D._3&&!I._3?k(I._1,I._2,!0):I;return n(q=>G0(z,n,r,o,(H,O)=>n(ot=>{const tt=z._3&&!H._3?k(H._1,H._2,!0):H;return n(gt=>Cn(tt,n,r,o,(Lt,ft)=>n(Tt=>{const kt={line:u.line,column:u.column,endLine:X.line,endColumn:X.column};return i(tt._3&&!Lt._3?k(Lt._1,Lt._2,!0):Lt,{name:N("Just",E),ops:Br("Leaf",{op:Un("Step",{name:E}),line:kt.line,column:kt.column,endLine:kt.endLine,endColumn:kt.endColumn,span:kt,operands:[R]}),kind:p0})})))})))})))})))})))})))})))}))):wr("step")("`step` markers are only supported in animated diagrams."),zE=(()=>{const t=mt(Gt(e=>e===":"))("':'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>oe(_,n,r,o,(f,d)=>n(h=>{const m=Ue(Gt(iE)),p=_._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(p,n,r,o,(y,T)=>n(v=>i(p._3&&!y._3?k(y._1,y._2,!0):y,da(Qn(Ot(ue.foldr,T)))))))})))})))})(),W0=mt((t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>zE(k(i,a,!1),e,n,(u,c)=>{const _=u._3;return e(l=>{if(_)return r(u,c);const f=t._1,d=t._2;return e(h=>xE(k(f,d,!1),e,n,(m,p)=>{const x=m._3;return e(y=>{if(x)return r(m,p);const T=t._1,v=t._2;return e(b=>wE(k(T,v,!1),e,n,(C,S)=>{const P=C._3;return e(F=>P?r(C,S):B0(t,e,n,r,o))},o))})},o))})},o))})('label ("\u2026", : rest-of-line, or |\u2026|)'),q0=(t,e,n,r,o)=>e(i=>oe(t,e,n,r,(a,s)=>e(u=>W0(t._3&&!a._3?k(a._1,a._2,!0):a,e,n,r,o)))),zu=t=>(e,n,r,o,i)=>n(a=>oe(e,n,r,o,(s,u)=>n(c=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>{const f=(m,p)=>n(x=>(p?((y,T,v,b,C)=>C(y,w)):(y,T,v,b,C)=>T(S=>q0(y,T,v,b,(P,F)=>T(W=>C(P,N("Just",F))))))(_._3&&!m._3?k(m._1,m._2,!0):m,n,r,o,i)),d=_._1,h=_._2;return n(m=>{const p=(x,y)=>{const T=x._3;return n(v=>T?o(x,y):f(_,!1))};return n(x=>n(y=>n(T=>Ki(k(d,h,!1),n,r,(v,b)=>{const C=v._3;return n(S=>C?p(k(d,h,!1),b):n(P=>Gt(t)(k(d,h,!1),n,r,(F,W)=>p(k(d,h,!1),W),(F,W)=>n(E=>n(R=>f(k(d,h,!1),!0))))))},(v,b)=>n(C=>n(S=>f(k(d,h,!1),!0)))))))})})}))),ME=t=>e=>n=>(r,o,i,a,s)=>o(u=>oe(r,o,i,a,(c,_)=>o(l=>{const f=Jn(mt(qe)("target node identifier")),d=r._3&&!c._3?k(c._1,c._2,!0):c;return o(h=>f(d,o,i,a,(m,p)=>o(x=>{const y=p._1,T=p._2,v=d._3&&!m._3?k(m._1,m._2,!0):m;return o(b=>zu(X_)(v,o,i,a,(C,S)=>o(P=>s(v._3&&!C._3?k(C._1,C._2,!0):C,{op:Un("AddEdge",{from:t,to:y,label:S.tag==="Just"?N("Just",S._1):w,directed:n}),operands:[e,T]}))))})))}))),OE=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>Jn(qe)(t,e,n,(u,c)=>r(k(u._1,u._2,a),c),(u,c)=>e(_=>{const l=t._3&&!u._3?k(u._1,u._2,!0):u;return e(f=>oe(l,e,n,(d,h)=>r(k(d._1,d._2,a),h),(d,h)=>e(m=>{const p=mt(Gt(y=>y==="<"))("'<'"),x=l._3&&!d._3?k(d._1,d._2,!0):d;return e(y=>p(x,e,n,(T,v)=>r(k(x._1,x._2,a),v),(T,v)=>e(b=>{const C=Po((P,F,W,E,R)=>{const et=P._3;return Le("<-")(P,F,W,(rt,$)=>E(k(rt._1,rt._2,et),$),R)}),S=x._3&&!x._3?k(x._1,x._2,!0):x;return e(P=>C(S,e,n,(F,W)=>r(k(F._1,F._2,a),W),(F,W)=>e(E=>{const R=S._3&&!F._3?k(F._1,F._2,!0):F;return e(et=>{const rt=c._1,$=c._2,X=t._3&&!R._3?k(R._1,R._2,!0):R;return e(V=>oe(X,e,n,r,(D,B)=>e(I=>{const M=mt(Le("<~"))("'<~'"),j=X._3&&!D._3?k(D._1,D._2,!0):D;return e(z=>M(j,e,n,r,(q,H)=>e(O=>{const ot=j._3&&!q._3?k(q._1,q._2,!0):q;return e(tt=>oe(ot,e,n,r,(gt,Lt)=>e(ft=>{const Tt=Jn(mt(qe)("target node identifier")),kt=ot._3&&!gt._3?k(gt._1,gt._2,!0):gt;return e(Kt=>Tt(kt,e,n,r,(Nt,Xt)=>e(Ft=>{const vt=Xt._1,yt=Xt._2,dt=kt._3&&!Nt._3?k(Nt._1,Nt._2,!0):Nt;return e(xt=>zu(X_)(dt,e,n,r,(Dt,ht)=>e(Jt=>o(dt._3&&!Dt._3?k(Dt._1,Dt._2,!0):Dt,{op:Un("Token",{from:vt,to:rt,labels:(()=>{if(ht.tag==="Nothing")return[];if(ht.tag==="Just")return[ht._1];g()})()}),operands:[yt,$]}))))})))})))})))})))})})))})))})))})))}),WE=(t,e,n,r,o)=>e(i=>JE(t,e,n,r,(a,s)=>e(u=>{const c=s._2._2,_=s._1,l=s._2._1,f=t._3&&!a._3?k(a._1,a._2,!0):a;return e(d=>oe(f,e,n,r,(h,m)=>e(p=>{const x=Jn(mt(qe)("target node identifier")),y=f._3&&!h._3?k(h._1,h._2,!0):h;return e(T=>x(y,e,n,r,(v,b)=>e(C=>{const S=b._1,P=b._2,F=y._3&&!v._3?k(v._1,v._2,!0):v;return e(W=>zu(X_)(F,e,n,r,(E,R)=>e(et=>(c==="<~"?((rt,$,X,V,D)=>D(rt,{op:Un("Token",{from:S,to:_,labels:(()=>{if(R.tag==="Nothing")return[];if(R.tag==="Just")return[R._1];g()})()}),operands:c==="<~"?[P,l]:[l,P]})):(rt,$,X,V,D)=>D(rt,{op:Un("Token",{from:_,to:S,labels:(()=>{if(R.tag==="Nothing")return[];if(R.tag==="Just")return[R._1];g()})()}),operands:c==="<~"?[P,l]:[l,P]}))(F._3&&!E._3?k(E._1,E._2,!0):E,e,n,r,o))))})))})))}))),qE=(t,e,n,r,o)=>e(i=>zu(uE)(t,e,n,r,(a,s)=>e(u=>o(a,(()=>{if(s.tag==="Nothing")return"";if(s.tag==="Just")return s._1;g()})())))),HE=t=>e=>n=>r=>(o,i,a,s,u)=>i(c=>Xn(o,i,a,s,(_,l)=>i(f=>{const d=o._3&&!_._3?k(_._1,_._2,!0):_;return i(h=>{const m=(y,T)=>i(v=>(()=>{if(T.tag==="Just")return(b,C,S,P,F)=>P(b,sr("node placeholder value",l));if(T.tag==="Nothing")return(b,C,S,P,F)=>C(W=>q0(b,C,S,P,(E,R)=>C(et=>F(b._3&&!E._3?k(E._1,E._2,!0):E,{op:Un("ModNodeSlot",{id:t,slot:n,value:R}),operands:[e,r]}))));g()})()(d._3&&!y._3?k(y._1,y._2,!0):y,i,a,s,u)),p=d._1,x=d._2;return i(y=>i(T=>$a(k(p,x,!1),i,a,(v,b)=>i(C=>m(d,w)),(v,b)=>i(C=>m(k(p,x,!1),N("Just",b))))))})}))),$E=t=>e=>(n,r,o,i,a)=>r(s=>Xn(n,r,o,i,(u,c)=>r(_=>{const l=n._3&&!u._3?k(u._1,u._2,!0):u;return r(f=>{const d=(p,x)=>r(y=>(()=>{if(x.tag==="Just")return(T,v,b,C,S)=>C(T,sr("node relabel label",c));if(x.tag==="Nothing")return(T,v,b,C,S)=>v(P=>W0(T,v,b,C,(F,W)=>v(E=>S(T._3&&!F._3?k(F._1,F._2,!0):F,{op:Un("ModNode",{id:t,label:N("Just",W)}),operands:[e]}))));g()})()(l._3&&!p._3?k(p._1,p._2,!0):p,r,o,i,a)),h=l._1,m=l._2;return r(p=>r(x=>$a(k(h,m,!1),r,o,(y,T)=>r(v=>d(l,w)),(y,T)=>r(v=>d(k(h,m,!1),N("Just",T))))))})}))),YE=(()=>{const t=mt(Gt(e=>e==="~"))("'~'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const _=mt(Go)("space after '~'"),l=e._3&&!s._3?k(s._1,s._2,!0):s;return n(f=>_(l,n,r,o,(d,h)=>n(m=>{const p=Jn(mt(qe)("source node identifier")),x=l._3&&!d._3?k(d._1,d._2,!0):d;return n(y=>p(x,n,r,o,(T,v)=>n(b=>{const C=v._1,S=v._2,P=mt(Gt(E=>E==="."))("'.'"),F=Jn(mt(qe)("placeholder name")),W=x._3&&!T._3?k(T._1,T._2,!0):T;return n(E=>{const R=($,X)=>n(V=>(()=>{if(X.tag==="Just")return HE(C)(S)(X._1._1)(X._1._2);if(X.tag==="Nothing")return(D,B,I,M,j)=>B(z=>oe(D,B,I,M,(q,H)=>B(O=>{const ot=mt(Gt(gt=>gt==="-"))("'-'"),tt=D._3&&!q._3?k(q._1,q._2,!0):q;return B(gt=>{const Lt=(kt,Kt)=>B(Nt=>(()=>{if(Kt.tag==="Just")return CE(C)(S);if(Kt.tag==="Nothing")return $E(C)(S);g()})()(tt._3&&!kt._3?k(kt._1,kt._2,!0):kt,B,I,M,j)),ft=tt._1,Tt=tt._2;return B(kt=>B(Kt=>ot(k(ft,Tt,!1),B,I,(Nt,Xt)=>B(Ft=>Lt(tt,w)),(Nt,Xt)=>B(Ft=>Lt(k(ft,Tt,!1),N("Just",Xt))))))})})));g()})()(W._3&&!$._3?k($._1,$._2,!0):$,n,r,o,i)),et=W._1,rt=W._2;return n($=>n(X=>{const V=(D,B)=>{const I=D._3;return n(M=>I?o(D,B):R(W,w))};return n(D=>n(B=>P(k(et,rt,!1),n,r,(I,M)=>V(k(I._1,I._2,!1),M),(I,M)=>n(j=>n(z=>F(I,n,r,(q,H)=>V(k(q._1,q._2,!1),H),(q,H)=>n(O=>{const ot=I._3&&!q._3?k(q._1,q._2,!0):q;return n(tt=>R(ot,N("Just",H)))})))))))}))})})))})))})))})(),U_=i0((()=>{const t=mt(Gt(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(a=>n(s=>t(e,n,r,o,(u,c)=>n(_=>n(l=>{const f=e._3&&!u._3?k(u._1,u._2,!0):u;return Cn(f,n,r,o,(d,h)=>n(m=>i(f._3&&!d._3?k(d._1,d._2,!0):d,h)))})))))})())(mt((()=>{const t=mt(Gt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>n(s=>Cn(e,n,r,o,(u,c)=>n(_=>n(l=>{const f=e._3&&!u._3?k(u._1,u._2,!0):u;return t(f,n,r,o,(d,h)=>n(m=>i(f._3&&!d._3?k(d._1,d._2,!0):d,h)))})))))})())("closing '}'")),VE=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>B0(k(i,a,!1),e,n,(u,c)=>{const _=u._3;return e(l=>{if(_)return r(u,c);const f=t._1,d=t._2;return e(h=>LE(k(f,d,!1),e,n,(m,p)=>{const x=m._3;return e(y=>x?r(m,p):qe(t,e,n,r,o))},o))})},o))},H0=(t,e,n,r,o)=>e(i=>oe(t,e,n,r,(a,s)=>e(u=>{const c=mt(qe)("attribute key"),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>c(_,e,n,r,(f,d)=>e(h=>{const m=_._3&&!f._3?k(f._1,f._2,!0):f;return e(p=>oe(m,e,n,r,(x,y)=>e(T=>{const v=mt(mt(Gt(C=>C===":"))("':'"))("':'"),b=m._3&&!x._3?k(x._1,x._2,!0):x;return e(C=>v(b,e,n,r,(S,P)=>e(F=>{const W=b._3&&!S._3?k(S._1,S._2,!0):S;return e(E=>oe(W,e,n,r,(R,et)=>e(rt=>{const $=mt(VE)("attribute value"),X=W._3&&!R._3?k(R._1,R._2,!0):R;return e(V=>$(X,e,n,r,(D,B)=>e(I=>{const M=X._3&&!D._3?k(D._1,D._2,!0):D;return e(j=>oe(M,e,n,r,(z,q)=>e(H=>o(M._3&&!z._3?k(z._1,z._2,!0):z,L(d,B)))))})))})))})))})))})))}))),XE=i0((()=>{const t=mt(Gt(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(a=>n(s=>t(e,n,r,o,(u,c)=>n(_=>n(l=>{const f=e._3&&!u._3?k(u._1,u._2,!0):u;return oe(f,n,r,o,(d,h)=>n(m=>i(f._3&&!d._3?k(d._1,d._2,!0):d,h)))})))))})())(mt((()=>{const t=mt(Gt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>n(s=>oe(e,n,r,o,(u,c)=>n(_=>n(l=>{const f=e._3&&!u._3?k(u._1,u._2,!0):u;return t(f,n,r,o,(d,h)=>n(m=>i(f._3&&!d._3?k(d._1,d._2,!0):d,h)))})))))})())("closing '}' for attributes"))((()=>{const t=mt(Gt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>{const s=(_,l)=>n(f=>(()=>{if(l.tag==="Just")return(d,h,m,p,x)=>x(d,Q);if(l.tag==="Nothing")return(d,h,m,p,x)=>h(y=>H0(d,h,m,p,(T,v)=>h(b=>{const C=Ue((()=>{const P=mt(Gt(F=>F===","))("','");return(F,W,E,R,et)=>{const rt=F._3;return W($=>W(X=>W(V=>W(D=>W(B=>W(I=>oe(F,W,E,(M,j)=>R(k(M._1,M._2,rt),j),(M,j)=>W(z=>W(q=>{const H=F._3&&!M._3?k(M._1,M._2,!0):M;return P(H,W,E,(O,ot)=>R(k(O._1,O._2,rt),ot),(O,ot)=>W(tt=>{const gt=H._3&&!O._3?k(O._1,O._2,!0):O;return W(Lt=>W(ft=>{const Tt=F._3&&!gt._3?k(gt._1,gt._2,!0):gt;return oe(Tt,W,E,(kt,Kt)=>R(k(kt._1,kt._2,rt),Kt),(kt,Kt)=>W(Nt=>{const Xt=Tt._3&&!kt._3?k(kt._1,kt._2,!0):kt;return W(Ft=>W(vt=>{const yt=F._3&&!Xt._3?k(Xt._1,Xt._2,!0):Xt;return H0(yt,W,E,(dt,xt)=>R(k(dt._1,dt._2,rt),xt),(dt,xt)=>W(Dt=>et(yt._3&&!dt._3?k(dt._1,dt._2,!0):dt,xt)))}))}))}))}))})))))))))}})()),S=d._3&&!T._3?k(T._1,T._2,!0):T;return h(P=>C(S,h,m,p,(F,W)=>h(E=>x(S._3&&!F._3?k(F._1,F._2,!0):F,nE([v,...Ot(ue.foldr,W)])))))})));g()})()(e._3&&!_._3?k(_._1,_._2,!0):_,n,r,o,i)),u=e._1,c=e._2;return n(_=>n(l=>t(k(u,c,!1),n,r,(f,d)=>n(h=>s(e,w)),(f,d)=>n(h=>s(k(u,c,!1),N("Just",d))))))})})()),UE=(t,e,n,r,o)=>e(i=>oe(t,e,n,r,(a,s)=>e(u=>{const c=mt(Gt(l=>l==="{"))("'{'"),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>{const f=(m,p)=>e(x=>(()=>{if(p.tag==="Just")return XE;if(p.tag==="Nothing")return(y,T,v,b,C)=>C(y,Q);g()})()(_._3&&!m._3?k(m._1,m._2,!0):m,e,n,r,o)),d=_._1,h=_._2;return e(m=>e(p=>c(k(d,h,!1),e,n,(x,y)=>e(T=>f(_,w)),(x,y)=>e(T=>f(k(d,h,!1),N("Just",y))))))})}))),KE=t=>e=>(n,r,o,i,a)=>r(s=>qE(n,r,o,i,(u,c)=>r(_=>{const l=n._3&&!u._3?k(u._1,u._2,!0):u;return r(f=>UE(l,r,o,i,(d,h)=>r(m=>a(l._3&&!d._3?k(d._1,d._2,!0):d,{op:Un("AddNode",{id:t,label:c,shape:(()=>{const p=E0("shape")(h);if(p.tag==="Just")return p._1==="rectangle"||p._1==="rect"?ho:p._1==="cylinder"||p._1==="cyl"?vy:p._1==="parallelogram"?Jy:p._1==="diamond"?Cy:p._1==="ellipse"?by:p._1==="document"||p._1==="doc"?ky:p._1==="cloud"?Ly:ho;if(p.tag==="Nothing")return ho;g()})(),width:(()=>{const p=E0("width")(h);if(p.tag==="Just")return wf(p._1,ja,Yt,w);if(p.tag==="Nothing")return w;g()})()}),operands:[e]}))))}))),ZE=(()=>{const t=mt(Gt(e=>e==="+"))("'+'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const _=mt(Go)("space after '+'"),l=e._3&&!s._3?k(s._1,s._2,!0):s;return n(f=>_(l,n,r,o,(d,h)=>n(m=>{const p=Jn(mt(qe)("node identifier after '+'")),x=l._3&&!d._3?k(d._1,d._2,!0):d;return n(y=>p(x,n,r,o,(T,v)=>n(b=>{const C=v._1,S=v._2,P=x._3&&!T._3?k(T._1,T._2,!0):T;return n(F=>F0(P,n,r,o,(W,E)=>n(R=>(()=>{if(E.tag==="Just")return ME(C)(S)(E._1);if(E.tag==="Nothing")return KE(C)(S);g()})()(P._3&&!W._3?k(W._1,W._2,!0):W,n,r,o,i))))})))})))})))})(),jE=(t,e,n,r,o)=>e(i=>Xn(t,e,n,r,(a,s)=>e(u=>{const c=mt(V_([wr("+node")("Node additions use `+ api: API`."),wr("+edge")("Graph edges use `+ api -> db`."),wr("+conn")("Undirected graph edges use `+ api -- db`."),wr("-node")("Node removals use `- api`."),wr("-edge")("Graph edge removals use `- api -> db`."),wr("-conn")("Undirected graph edge removals use `- api -- db`."),wr("~edge")("Graph edge repoints use `~ api -> db => api -> cache`."),wr("enter")("Dive commands use `into api`."),wr("exit")("Return from a dive with `out`."),vE,ZE,BE,YE,WE,OE,SE,EE]))("statement (+ node, - node, + edge, - edge, ~ node, into, out, or 'a ~> b'/'a <~ b')"),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>c(_,e,n,r,(f,d)=>e(h=>{const m=_._3&&!f._3?k(f._1,f._2,!0):f;return e(p=>Xn(m,e,n,r,(x,y)=>e(T=>{const v={line:s.line,column:s.column,endLine:y.line,endColumn:y.column};return o(m._3&&!x._3?k(x._1,x._2,!0):x,Br("Leaf",{op:d.op,line:v.line,column:v.column,endLine:v.endLine,endColumn:v.endColumn,span:v,operands:d.operands}))})))})))}))),$0=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>Cn(t,e,n,(u,c)=>r(k(u._1,u._2,a),c),(u,c)=>e(_=>{const l=Po(mt(Gt(d=>d==="}"))("'}'")),f=t._3&&!u._3?k(u._1,u._2,!0):u;return e(d=>l(f,e,n,(h,m)=>r(k(h._1,h._2,a),m),(h,m)=>e(p=>Po(Ki)(f._3&&!h._3?k(h._1,h._2,!0):h,e,n,(x,y)=>r(k(x._1,x._2,a),y),(x,y)=>e(T=>{const v=t._3&&!x._3?k(x._1,x._2,!0):x;return e(b=>Eu(v,e,n,r,(C,S)=>e(P=>{const F=V_([e6,t6,jE]),W=v._3&&!C._3?k(C._1,C._2,!0):C;return e(E=>F(W,e,n,r,(R,et)=>e(rt=>{const $=W._3&&!R._3?k(R._1,R._2,!0):R;return e(X=>oe($,e,n,r,(V,D)=>e(B=>{const I=$._3&&!V._3?k(V._1,V._2,!0):V;return e(M=>G0(I,e,n,r,(j,z)=>e(q=>{const H=I._3&&!j._3?k(j._1,j._2,!0):j;return e(O=>Cn(H,e,n,r,(ot,tt)=>e(gt=>o(H._3&&!ot._3?k(ot._1,ot._2,!0):ot,et))))})))})))})))})))})))))})))}),t6=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>{const u=(c,_)=>{const l=c._3;return e(f=>l?r(c,_):e(d=>{const h=t._3;return e(m=>An("seq")(t,e,n,(p,x)=>r(k(p._1,p._2,h),x),(p,x)=>e(y=>{const T=t._3&&!p._3?k(p._1,p._2,!0):p;return e(v=>oe(T,e,n,(b,C)=>r(k(b._1,b._2,h),C),(b,C)=>e(S=>$a(T._3&&!b._3?k(b._1,b._2,!0):b,e,n,(P,F)=>r(k(P._1,P._2,h),F),(P,F)=>e(W=>{const E=t._3&&!P._3?k(P._1,P._2,!0):P;return e(R=>Eu(E,e,n,r,(et,rt)=>e($=>{const X=mt(mt(Gt(D=>D==="{"))("'{'"))("'{'"),V=E._3&&!et._3?k(et._1,et._2,!0):et;return e(D=>X(V,e,n,r,(B,I)=>e(M=>o(V._3&&!B._3?k(B._1,B._2,!0):B,Br("GroupSeq",[])))))})))})))))})))}))};return e(c=>e(_=>An("seq")(k(i,a,!1),e,n,(l,f)=>u(k(l._1,l._2,!1),f),(l,f)=>e(d=>e(h=>oe(l,e,n,(m,p)=>u(k(m._1,m._2,!1),p),(m,p)=>e(x=>{const y=l._3&&!m._3?k(m._1,m._2,!0):m;return mt(Gt(T=>T==="{"))("'{'")(y,e,n,(T,v)=>u(k(y._1,y._2,!1),v),(T,v)=>e(b=>U_(K_(l4))(y,e,n,u,o)))})))))))})},e6=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>{const u=(c,_)=>{const l=c._3;return e(f=>l?r(c,_):e(d=>{const h=t._3;return e(m=>An("par")(t,e,n,(p,x)=>r(k(p._1,p._2,h),x),(p,x)=>e(y=>{const T=t._3&&!p._3?k(p._1,p._2,!0):p;return e(v=>oe(T,e,n,(b,C)=>r(k(b._1,b._2,h),C),(b,C)=>e(S=>$a(T._3&&!b._3?k(b._1,b._2,!0):b,e,n,(P,F)=>r(k(P._1,P._2,h),F),(P,F)=>e(W=>{const E=t._3&&!P._3?k(P._1,P._2,!0):P;return e(R=>Eu(E,e,n,r,(et,rt)=>e($=>{const X=mt(mt(Gt(D=>D==="{"))("'{'"))("'{'"),V=E._3&&!et._3?k(et._1,et._2,!0):et;return e(D=>X(V,e,n,r,(B,I)=>e(M=>o(V._3&&!B._3?k(B._1,B._2,!0):B,Br("Par",[])))))})))})))))})))}))};return e(c=>e(_=>An("par")(k(i,a,!1),e,n,(l,f)=>u(k(l._1,l._2,!1),f),(l,f)=>e(d=>e(h=>oe(l,e,n,(m,p)=>u(k(m._1,m._2,!1),p),(m,p)=>e(x=>{const y=l._3&&!m._3?k(m._1,m._2,!0):m;return mt(Gt(T=>T==="{"))("'{'")(y,e,n,(T,v)=>u(k(y._1,y._2,!1),v),(T,v)=>e(b=>U_(K_(f4))(y,e,n,u,o)))})))))))})},K_=t=>{const e=Ue($0);return(n,r,o,i,a)=>r(s=>e(n,r,o,i,(u,c)=>r(_=>a(n._3&&!u._3?k(u._1,u._2,!0):u,t(Ot(ue.foldr,c))))))},Z_=t=>e=>(n,r,o,i,a)=>r(s=>kE(t)(n,r,o,i,(u,c)=>r(_=>{const l=Ue(Gt(cE)),f=n._3&&!u._3?k(u._1,u._2,!0):u;return r(d=>l(f,r,o,i,(h,m)=>r(p=>{const x=mt(mt(Gt(T=>T==="{"))("'{'"))("'{'"),y=f._3&&!h._3?k(h._1,h._2,!0):h;return r(T=>x(y,r,o,i,(v,b)=>r(C=>{const S=y._3&&!v._3?k(v._1,v._2,!0):v;return r(P=>Cn(S,r,o,i,(F,W)=>r(E=>{const R=K_(d4),et=S._3&&!F._3?k(F._1,F._2,!0):F;return r(rt=>R(et,r,o,i,($,X)=>r(V=>{const D=et._3&&!$._3?k($._1,$._2,!0):$;return r(B=>Cn(D,r,o,i,(I,M)=>r(j=>{const z=mt(mt(Gt(H=>H==="}"))("'}'"))("closing '}'"),q=D._3&&!I._3?k(I._1,I._2,!0):I;return r(H=>z(q,r,o,i,(O,ot)=>r(tt=>{const gt=q._3&&!O._3?k(O._1,O._2,!0):O;return r(Lt=>Cn(gt,r,o,i,(ft,Tt)=>r(kt=>a(gt._3&&!ft._3?k(ft._1,ft._2,!0):ft,{name:hE(Qn(Ot(ue.foldr,m))),ops:X,kind:e}))))})))})))})))})))})))})))}))),n6=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>wr("keyframe")("Drop the `keyframe` wrapper; Markgraf animates statements in order.")(k(i,a,!1),e,n,(u,c)=>{const _=u._3;return e(l=>{if(_)return r(u,c);const f=t._1,d=t._2;return e(h=>Z_("scene")(Du)(k(f,d,!1),e,n,(m,p)=>{const x=m._3;return e(y=>{if(x)return r(m,p);const T=t._1,v=t._2;return e(b=>Z_("still")(q_)(k(T,v,!1),e,n,(C,S)=>{const P=C._3;return e(F=>P?r(C,S):Z_("title")(_4)(t,e,n,r,o))},o))})},o))})},o))},r6=t=>e=>n=>{if(t==="AnimatedSurface")return{...e,frames:St(e.frames)({name:w,ops:n,kind:Du})};if(t==="StillSurface")return{...e,statements:St(e.statements)(n)};if(t==="SequenceSurface")return{...e,statements:St(e.statements)(n)};g()},o6=t=>e=>n=>{if(n.tag==="TopFrame"){const r=I0(t)(e);return{...r,frames:St(r.frames)((()=>{if(t==="AnimatedSurface")return n._1;if(t==="StillSurface")return{...n._1,kind:n._1.kind==="AnimatedKeyframe"?q_:n._1.kind==="StepMarker"?p0:n._1.kind};if(t==="SequenceSurface")return n._1;g()})())}}if(n.tag==="TopStatement")return r6(t)(e)(n._1);if(n.tag==="TopInside")return e;g()},i6=t=>{const e=J(o6(t))(yE);return n=>I0(t)(e(n)).frames},a6=t=>LS.defer(e=>{const n=QE(t);return(r,o,i,a,s)=>{const u=r._1,c=r._2;return o(_=>GE(t)(k(u,c,!1),o,i,(l,f)=>{const d=l._3;return o(h=>{if(d)return a(l,f);const m=r._1,p=r._2;return o(x=>o(y=>s6(k(m,p,!1),o,i,(T,v)=>{const b=T._3;return o(C=>{if(b)return a(T,v);const S=r._1,P=r._2;return o(F=>o(W=>n(k(S,P,!1),o,i,(E,R)=>{const et=E._3;return o(rt=>{if(et)return a(E,R);const $=r._1,X=r._2;return o(V=>o(D=>n6(k($,X,!1),o,i,(B,I)=>{const M=B._3;return o(j=>M?a(B,I):o(z=>$0(r,o,i,a,(q,H)=>o(O=>s(q,Bu("TopStatement",H))))))},(B,I)=>o(M=>s(B,Bu("TopFrame",I))))))})},(E,R)=>o(et=>s(E,Bu("TopFrame",R))))))})},(T,v)=>o(b=>s(T,Bu("TopInside",v))))))})},s))}}),s6=(t,e,n,r,o)=>e(i=>An("inside")(t,e,n,r,(a,s)=>e(u=>{const c=mt(Go)("space after 'inside'"),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>c(_,e,n,r,(f,d)=>e(h=>{const m=mt(qe)("node identifier after 'inside'"),p=_._3&&!f._3?k(f._1,f._2,!0):f;return e(x=>m(p,e,n,r,(y,T)=>e(v=>{const b=p._3&&!y._3?k(y._1,y._2,!0):y;return e(C=>Cn(b,e,n,r,(S,P)=>e(F=>{const W=b._3&&!S._3?k(S._1,S._2,!0):S;return e(E=>U_(Y0)(W,e,n,r,(R,et)=>e(rt=>{const $=W._3&&!R._3?k(R._1,R._2,!0):R;return e(X=>Cn($,e,n,r,(V,D)=>e(B=>o($._3&&!V._3?k(V._1,V._2,!0):V,{node:T,doc:et}))))})))})))})))})))}))),Y0=(t,e,n,r,o)=>e(i=>DE(t,e,n,r,(a,s)=>e(u=>{const c=t._3&&!a._3?k(a._1,a._2,!0):a;return e(_=>{const l=(h,m)=>e(p=>{const x=Ue(a6(s)),y=c._3&&!h._3?k(h._1,h._2,!0):h;return e(T=>x(y,e,n,r,(v,b)=>e(C=>{const S=Ot(ue.foldr,b);return o(y._3&&!v._3?k(v._1,v._2,!0):v,{seed:(()=>{if(m.tag==="Nothing")return 0;if(m.tag==="Just")return m._1;g()})(),mode:s,frames:i6(s)(S),interiors:wt(P=>{if(P.tag==="TopInside")return N("Just",P._1);if(P.tag==="TopFrame"||P.tag==="TopStatement")return w;g()})(S)})})))}),f=c._1,d=c._2;return e(h=>e(m=>PE(k(f,d,!1),e,n,(p,x)=>{const y=p._3;return e(T=>y?r(p,x):l(c,w))},(p,x)=>e(y=>l(p,N("Just",x))))))})}))),u6=(()=>{const t=mt((e,n,r,o,i)=>n(a=>n(s=>Cn(e,n,r,o,(u,c)=>n(_=>n(l=>{const f=e._3&&!u._3?k(u._1,u._2,!0):u;return Ki(f,n,r,o,(d,h)=>n(m=>i(f._3&&!d._3?k(d._1,d._2,!0):d,h)))}))))))("'scene', 'still', 'title', 'step', 'inside', a statement, or end of input");return(e,n,r,o,i)=>n(a=>n(s=>n(u=>n(c=>Cn(e,n,r,o,(_,l)=>n(f=>n(d=>{const h=e._3&&!_._3?k(_._1,_._2,!0):_;return Y0(h,n,r,o,(m,p)=>n(x=>{const y=h._3&&!m._3?k(m._1,m._2,!0):m;return n(T=>n(v=>{const b=e._3&&!y._3?k(y._1,y._2,!0):y;return t(b,n,r,o,(C,S)=>n(P=>i(b._3&&!C._3?k(C._1,C._2,!0):C,p)))}))}))})))))))})(),c6=t=>{const e=n0(t)(u6);if(e.tag==="Left")return It("Left",{msg:lE(e._1._1),line:e._1._2.line,column:e._1._2.column,endLine:e._1._2.line,endColumn:e._1._2.column+1|0});if(e.tag==="Right")return It("Right",e._1);g()},g6=t=>{const e=c6(t);if(e.tag==="Left")return It("Left",e._1.msg);if(e.tag==="Right")return It("Right",e._1);g()},_6=()=>({tag:"ParFrag"}),V0=t=>t,f6=V0("Sync"),d6=V0("SelfMsg"),l6=_6(),Ao=t0(In),Rn=pi(In),Tr=Ao.state(t=>L(t,t)),Ro=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},X0=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Mu=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Do=mi(In),h6=t=>e=>J(n=>r=>pi(In).bind(n)(o=>t(o)(r)))(mi(In).pure(e)),U0=co(Do)(Qt),K0=t=>e=>Ao.state(n=>L(void 0,{...n,lifelines:Jf(A)(r=>N("Just",{...r,label:Zi(e)}))(t)(n.lifelines),labelTemplates:it(A)(t)(e)(n.labelTemplates)})),Ya=t=>Ao.state(e=>L(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:N("Just",t)};g()})())),p6=t=>e=>n=>Rn.bind(Tr)(r=>{const o=Ro(t)(r.labelTemplates);if(o.tag==="Nothing")return Ya("node "+t+" label has no placeholder `"+e+"`");if(o.tag==="Just"){const i=c0(e)(n)(o._1);if(i.tag==="Left")return Ya("node "+t+" "+i._1);if(i.tag==="Right")return K0(t)(i._1)}g()}),m6=t=>e=>{const n=Gu(e);if(n.tag==="Left")return Ya("invalid label for node "+t+": "+n._1);if(n.tag==="Right")return K0(t)(n._1);g()},y6=t=>e=>n=>{const r=Ro(n)(t.lifelines);return Ro(e)(t.lifelines).tag==="Nothing"?r.tag==="Nothing"?e+", "+n:e:r.tag==="Nothing"?n:""},x6={lifelines:Q,labelTemplates:Q,lifelineOrder:[],messages:[],fragments:[],frameEndRows:[],row:0,error:w},w6=t=>e=>n=>Rn.bind(Tr)(r=>{const o=Ro(t)(r.lifelines),i=Ro(e)(r.lifelines);if(o.tag==="Just"&&i.tag==="Just"){const a={...r,messages:[{fromCol:o._1.column,toCol:i._1.column,labels:n,row:r.row,kind:t===e?d6:f6},...r.messages],row:r.row+1|0};return Ao.state(s=>L(void 0,a))}return Ya("token references unknown node: "+y6(r)(t)(e))}),T6=t=>Ao.state(e=>L(void 0,{...e,lifelines:Jf(A)(n=>N("Just",{...n,destroyedAt:N("Just",e.row)}))(t)(e.lifelines)})),N6=t=>e=>{const n=e.lifelineOrder.length,r=Pt(o=>w,o=>i=>N("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return{fromCol:0,toCol:Mu(0)(e.lifelineOrder.length-1|0)};if(r.tag==="Just")return J(o=>i=>({fromCol:X0(o.fromCol)(X0(i.fromCol)(i.toCol)),toCol:Mu(o.toCol)(Mu(i.fromCol)(i.toCol))}))({fromCol:n,toCol:0})(t);g()},v6=t=>({lifelines:wt(e=>Ro(e)(t.lifelines))(t.lifelineOrder),messages:re(t.messages),fragments:re(t.fragments),frameEndRows:t.frameEndRows,totalRows:t.row}),J6=t=>e=>Rn.bind(Tr)(n=>{const r=Ro(t)(n.lifelines);if(r.tag==="Just")return Do.pure();if(r.tag==="Nothing"){const o={...n,lifelines:it(A)(t)({id:t,label:Zi(e),column:n.lifelineOrder.length,createdAt:n.row,destroyedAt:w})(n.lifelines),labelTemplates:it(A)(t)(e)(n.labelTemplates),lifelineOrder:St(n.lifelineOrder)(t),row:n.row>0||n.messages.length!==0?n.row+1|0:n.row};return Ao.state(i=>L(void 0,o))}g()}),C6=t=>e=>Rn.bind(Tr)(n=>{const r=Ro(t)(n.lifelines);if(r.tag==="Just")return Do.pure();if(r.tag==="Nothing"){const o=Gu(e);if(o.tag==="Left")return Ya("invalid label for node "+t+": "+o._1);if(o.tag==="Right")return J6(t)(o._1)}g()}),b6=t=>{if(t.tag==="AddNode")return C6(t._1.id)(t._1.label);if(t.tag==="DelNode")return T6(t._1.id);if(t.tag==="ModNode"){if(t._1.label.tag==="Just")return m6(t._1.id)(t._1.label._1);if(t._1.label.tag==="Nothing")return Do.pure();g()}return t.tag==="ModNodeSlot"?p6(t._1.id)(t._1.slot)(t._1.value):t.tag==="Token"?w6(t._1.from)(t._1.to)(t._1.labels):Do.pure()},k6=t=>Rn.bind(Tr)(e=>{const n=e.row;return Rn.bind(h6(r=>o=>Rn.bind(Tr)(i=>{const a=r.childMessages.length===0?r.dividers:[i.row,...r.dividers],s=i.messages;return Rn.bind(j_(o))(()=>Rn.bind(Tr)(u=>Do.pure({dividers:a,childMessages:[...r.childMessages,...(()=>{const c=u.messages.length-s.length|0;return c<1?[]:At(0,c,u.messages)})()]})))}))({dividers:[],childMessages:[]})(t))(r=>Rn.bind(Tr)(o=>{const i=N6(r.childMessages)(o),a={kind:l6,label:"par",fromRow:n,toRow:Mu(o.row)(n+1|0),fromCol:i.fromCol,toCol:i.toCol,regionDividers:re(r.dividers)},s=Ao.state(u=>L(void 0,{...u,fragments:[a,...u.fragments]}));return r.childMessages.length>=2?s:Do.pure()}))}),j_=t=>{if(t.tag==="Leaf")return b6(t._1.op);if(t.tag==="Seq"||t.tag==="GroupSeq")return U0(j_)(t._1);if(t.tag==="Par")return k6(t._1);g()},L6=t=>{const e=Rn.bind(U0(n=>Rn.bind(Tr)(r=>Rn.bind(j_(n.ops))(()=>Rn.bind(Tr)(o=>{const i=Ao.state(a=>L(void 0,{...a,frameEndRows:St(a.frameEndRows)(a.row-1|0)}));return(o.messages.length-r.messages.length|0)>0?i:Do.pure()}))))(t.frames))(()=>Tr)(x6)._1;if(e.error.tag==="Just")return It("Left",e.error._1);if(e.error.tag==="Nothing")return It("Right",v6(e));g()},S6=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},E6={padding:24,headerHeight:36,headerWidth:120,columnSpacing:160,rowHeight:36,topGap:24,bottomGap:24},P6=t=>{const e=84+nt(S6(1)(t.totalRows))*36,n=Wt(r=>o=>({lifeline:o,x:84+nt(r)*160}))(t.lifelines);return{metrics:E6,columns:n,width:(()=>{const r=n.length-1|0;return r>=0&&r<n.length?n[r].x+84:48})(),height:e+48,headerTop:24,headerBottom:60,bodyTop:84,bodyBottom:e,diagram:t}},G6=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Z0=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},j0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}g()}return o},tm=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},A6=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},R6=J(t=>e=>it(ut)(e)()(t))(Q),D6={r:255,g:255,b:255,a:255},Ou={r:26,g:26,b:26,a:255},F6={color:{r:232,g:232,b:232,a:255},flat:!0},I6={r:232,g:232,b:232,a:255},Wu=t=>e=>n=>r=>o=>[1,t+o,e,2,n-o,e,3,n,e,n,e+o,2,n,r-o,3,n,r,n-o,r,2,t+o,r,3,t,r,t,r-o,2,t,e+o,3,t,e,t+o,e,...ti],em=t=>e=>n=>({...n,stack:St(n.stack)(t),openedAt:it(ut)(t)(e)(n.openedAt)}),qu=t=>e=>{const n=e.stack.length-1|0;if(n>=0&&n<e.stack.length){const r=G6(e.stack[n])(e.openedAt),o=(()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return r._1;g()})();return{...e,stack:e.stack.length===0?[]:At(0,e.stack.length-1|0,e.stack),openedAt:Li(ut)(e.stack[n])(e.openedAt),spans:St(e.spans)({col:e.stack[n],fromRow:o,toRow:Z0(o)(t)})}}return e},nm=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,c=o,_=i,l=_.stack.length-1|0;if(l>=0&&l<_.stack.length){if(u(_.stack[l])){a=!1,s=_;continue}r=u,o=c,i=qu(c)(_);continue}a=!1,s=_}return s},rm=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r,u=s.stack.length-1|0;if(u>=0&&u<s.stack.length){n=a,r=qu(a)(s);continue}o=!1,i=s}return i},B6=t=>e=>{const n=ln(go)(e.fromCol)(t.stack)?nm((()=>{const r=e.fromCol;return o=>r===o})())(e.row-1|0)(t):em(e.fromCol)(e.row)(rm(e.row-1|0)(t));if(ln(go)(e.toCol)(n.stack)){const r=nm((()=>{const o=e.toCol;return i=>o===i})())(e.row-1|0)(qu(e.row)(n));return{...r,returnRows:it(ut)(e.row)()(r.returnRows)}}return em(e.toCol)(e.row)(n)},Q6=t=>e=>n=>{const r=B6(e)(n);return j0(n.row)(t)?rm(n.row)(r):r},Hu={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:Da,lineCap:ir},om={r:26,g:26,b:26,a:255},z6={color:{r:130,g:130,b:130,a:255},width:1,lineJoin:Da,lineCap:Pn},im={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:Da,lineCap:Pn},M6={color:{r:244,g:244,b:244,a:255},flat:!0},am=t=>e=>n=>ne(r=>r.col===e&&r.fromRow<=n&&n<=r.toRow,t),sm={color:{r:90,g:90,b:90,a:255},width:1,lineJoin:Da,lineCap:Pn},O6={stack:[],openedAt:Q,spans:[],returnRows:Q},W6={color:{r:150,g:150,b:150,a:255},width:1,lineJoin:Da,lineCap:Pn},q6=t=>e=>n=>r=>o=>{const i=e.bodyTop+(nt(o)+.5)*e.metrics.rowHeight-e.metrics.rowHeight/2;return t.strokePath([1,n,i,2,r,i])(W6)},H6=t=>{const e=t.Monad0(),n=e.Bind1(),r=vi(e.Applicative0())(Qt);return o=>i=>{const a=o.bodyTop+(nt(i.fromRow)+.5)*o.metrics.rowHeight-o.metrics.rowHeight/2-6,s=i.fromCol>=0&&i.fromCol<o.columns.length?o.columns[i.fromCol].x-16:o.metrics.padding-16,u=[1,s,a,2,s+38,a,2,s+32,a+14,2,s,a+14,...ti],c=i.toCol>=0&&i.toCol<o.columns.length?o.columns[i.toCol].x+16:o.metrics.padding+16,_=o.bodyTop+(nt(Z0(i.toRow)(i.fromRow+1|0)-1|0)+.5)*o.metrics.rowHeight+o.metrics.rowHeight/2+6;return n.bind(t.strokePath([1,s,a,2,c,a,2,c,_,2,s,_,...ti])(sm))(()=>n.bind(t.fillStrokePath(u)(F6)(sm))(()=>n.bind(t.drawText({x:s+6,y:a+7,content:"par",font:{family:"Inter",size:11,weight:700},color:Ou,align:vo,baseline:Nn}))(()=>r(i.regionDividers)(q6(t)(o)(s)(c)))))}},um=t=>e=>t>=e?[]:[L(t,tm(e)(t+6)),...um(t+10)(e)],$6=t=>e=>{if(e<=t)return[];const n=r=>r>=e?[]:[L(r,tm(e)(r+6)),...n(r+10)];return n(t)},Y6=t=>{const e=vi(t.Monad0().Applicative0())(Qt);return n=>r=>e($6(n.headerTop+n.metrics.headerHeight+nt(r.lifeline.createdAt)*n.metrics.rowHeight+4)((()=>{if(r.lifeline.destroyedAt.tag==="Just")return n.bodyTop+(nt(r.lifeline.destroyedAt._1)+.5)*n.metrics.rowHeight;if(r.lifeline.destroyedAt.tag==="Nothing")return n.bodyBottom;g()})()))(o=>t.strokePath([1,r.x,o._1,2,r.x,o._2])(z6))},cm=t=>e=>t<=e?[]:[L(t,A6(e)(t-6)),...cm(t-6-4)(e)],V6=t=>e=>t===e?[]:t<e?um(t)(e):cm(t)(e),X6=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.headerTop+nt(r.lifeline.createdAt)*n.metrics.rowHeight,i=n.metrics.headerWidth/2,a=o+n.metrics.headerHeight,s=Wu(r.x-i)(o)(r.x+i)(a)(6);return e.bind(t.fillStrokePath(Wu(r.x-i)(o+5)(r.x+i)(a+5)(6))({color:I6,flat:!0})(im))(()=>e.bind(t.fillStrokePath(s)(M6)(im))(()=>t.drawText({x:r.x,y:o+n.metrics.headerHeight/2,content:r.lifeline.label,font:{family:"Inter",size:14,weight:600},color:Ou,align:eo,baseline:Nn})))}},U6=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r,u=s.stack.length-1|0;if(u>=0&&u<s.stack.length){n=a,r=qu(a)(s);continue}o=!1,i=s}return i},K6=t=>U6((()=>{const e=t.diagram.messages.length-1|0;return e>=0&&e<t.diagram.messages.length?t.diagram.messages[e].row:0})())(J(Q6(R6(t.diagram.frameEndRows)))(O6)(lt(e=>e.kind==="Sync"||e.kind!=="SelfMsg",t.diagram.messages))),Z6=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.bodyTop+(nt(r.row)+.5)*n.metrics.rowHeight,i=r.fromCol>=0&&r.fromCol<n.columns.length?n.columns[r.fromCol].x:n.metrics.padding,a=o-n.metrics.rowHeight*.3,s=i+36,u=o+n.metrics.rowHeight*.3,c=i+10,_=[1,i,u,2,c,u-5,2,c,u+5,...ti];return e.bind(t.strokePath([1,i,a,2,s,a,2,s,u,2,i,u])(Hu))(()=>e.bind(t.fillPath(_)({color:om,flat:!0}))(()=>t.drawText({x:i+42,y:o,content:Wn(" ")(Y(ea)(r.labels)),font:{family:"Inter",size:12,weight:400},color:Ou,align:vo,baseline:Nn})))}},j6=t=>{const e=t.Monad0(),n=e.Bind1(),r=vi(e.Applicative0())(Qt);return o=>i=>a=>s=>{const u=a?o.bodyTop+(nt(s.row)+.5)*o.metrics.rowHeight+o.metrics.rowHeight*.5:o.bodyTop+(nt(s.row)+.5)*o.metrics.rowHeight,c=s.toCol>=s.fromCol?1:-1,_=(s.fromCol>=0&&s.fromCol<o.columns.length?o.columns[s.fromCol].x:o.metrics.padding)+(am(i)(s.fromCol)(s.row)?c*6:c*0),l=(s.toCol>=0&&s.toCol<o.columns.length?o.columns[s.toCol].x:o.metrics.padding)-(am(i)(s.toCol)(s.row)?c*6:c*0),f=l-c*10,d=a?t.strokePath([1,f,u-5,2,l,u,2,f,u+5])(Hu):t.fillPath([1,l,u,2,f,u-5,2,f,u+5,...ti])({color:om,flat:!0});return n.bind(a?r(V6(_)(l))(h=>t.strokePath([1,h._1,u,2,h._2,u])(Hu)):t.strokePath([1,_,u,2,l,u])(Hu))(()=>n.bind(d)(()=>t.drawText({x:(_+l)/2,y:u-6,content:Wn(" ")(Y(ea)(s.labels)),font:{family:"Inter",size:12,weight:400},color:Ou,align:eo,baseline:Gb})))}},tP=t=>{const e=Z6(t),n=j6(t);return r=>o=>i=>a=>{if(a.kind==="SelfMsg")return e(r)(a);if(a.kind==="Sync")return n(r)(o)(j0(a.row)(i))(a);g()}},gm={color:{r:26,g:26,b:26,a:255},width:1.25,lineJoin:Ve,lineCap:Pn},eP={color:{r:232,g:232,b:232,a:255},flat:!0},nP={color:{r:252,g:252,b:252,a:255},flat:!0},rP=t=>e=>n=>{const r=n.col>=0&&n.col<e.columns.length?e.columns[n.col].x:e.metrics.padding,o=e.bodyTop+(nt(n.fromRow)+.5)*e.metrics.rowHeight,i=e.bodyTop+(nt(n.toRow)+.5)*e.metrics.rowHeight+e.metrics.rowHeight*.5,a=Wu(r-6)(o)(r+6)(i)(3);return t.Monad0().Bind1().bind(t.fillStrokePath(Wu(r-6)(o+5)(r+6)(i+5)(3))(eP)(gm))(()=>t.fillStrokePath(a)(nP)(gm))},_m=t=>{const e=t.Monad0(),n=e.Bind1(),r=vi(e.Applicative0())(Qt),o=X6(t),i=Y6(t),a=H6(t),s=tP(t);return u=>{const c=K6(u);return n.bind(t.setViewport({vx:0,vy:0,vw:u.width,vh:u.height}))(()=>n.bind(t.clearBackground(D6))(()=>n.bind(r(u.columns)(o(u)))(()=>n.bind(r(u.columns)(i(u)))(()=>n.bind(r(c.spans)(rP(t)(u)))(()=>n.bind(r(u.diagram.fragments)(a(u)))(()=>r(u.diagram.messages)(s(u)(c.spans)(c.returnRows))))))))}},oP=_m(Xb);function fm(t){return function(e){return function(){return t.add(e)}}}function tf(t,e,n,r){if(typeof window<"u"){var o=window[n];if(o!=null&&r instanceof o)return e(r)}for(var i=r;i!=null;){var a=Object.getPrototypeOf(i),s=a.constructor.name;if(s===n)return e(r);if(s==="Object")return t;i=a}return t}function dm(t){return function(){return t.classList}}function xn(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function iP(t){return function(e){return function(){return e.getAttribute(t)}}}const lm=t=>{const e=iP(t);return n=>{const r=e(n);return()=>{const o=r();return Ln(o,w,Yt)}}};function aP(t){return function(e){return function(){e.textContent=t}}}function sP(t){return function(){return function(e){return t(e)()}}}function uP(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const ef=function(){return window};function cP(t){return function(e){return function(){e.value=t}}}function gP(t){return function(){return t.valueAsNumber}}function _P(t){return function(){return t.value}}function nf(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const $u=t=>t,Yu=t=>()=>{const e=t.getBoundingClientRect?.(),n=e?.width||t.clientWidth||0,r=e?.height||t.clientHeight||0;return{width:n,height:r}},hm=t=>e=>()=>{let n=0;const r=()=>{n||(n=requestAnimationFrame(()=>{n=0,e()}))},o=typeof ResizeObserver>"u"?null:new ResizeObserver(r);return o?.observe(t),window.addEventListener("resize",r),()=>{n&&cancelAnimationFrame(n),o?.disconnect(),window.removeEventListener("resize",r)}},pm=()=>window.devicePixelRatio||1,mm=()=>performance.now()/1e3,fP=t=>e=>n=>r=>o=>()=>{const i=Math.max(1,e||t.clientWidth||r),a=Math.max(1,n||t.clientHeight||o),s="Markgraf needs more room",u=`Resize to at least ${Math.round(r)} \xD7 ${Math.round(o)} px`;if(t.setAttribute("data-mg-too-small","1"),t.setAttribute("data-mg-viewport-css-width",String(e||0)),t.setAttribute("data-mg-viewport-css-height",String(n||0)),t.setAttribute("data-mg-camera-vw","0"),t.setAttribute("data-mg-camera-vh","0"),t.setAttribute("data-mg-camera-zoom","0"),t instanceof SVGElement){t.setAttribute("viewBox",`0 0 ${i} ${a}`),t.setAttribute("preserveAspectRatio","xMidYMid meet"),t.innerHTML=`
28
28
  <rect x="0" y="0" width="${i}" height="${a}" rx="16" fill="#111827"/>
29
29
  <text x="${i/2}" y="${a/2-10}" text-anchor="middle" dominant-baseline="middle" fill="#f9fafb" font-family="system-ui, sans-serif" font-size="18" font-weight="700">${s}</text>
30
30
  <text x="${i/2}" y="${a/2+18}" text-anchor="middle" dominant-baseline="middle" fill="#cbd5e1" font-family="system-ui, sans-serif" font-size="13">${u}</text>
31
- `;return}if(t instanceof HTMLCanvasElement){const c=window.devicePixelRatio||1;t.width=Math.max(1,Math.round(i*c)),t.height=Math.max(1,Math.round(a*c));const g=t.getContext("2d");if(!g)return;g.save(),g.scale(c,c),g.clearRect(0,0,i,a),g.fillStyle="#111827",g.fillRect(0,0,i,a),g.textAlign="center",g.textBaseline="middle",g.fillStyle="#f9fafb",g.font="700 18px system-ui, sans-serif",g.fillText(s,i/2,a/2-10),g.fillStyle="#cbd5e1",g.font="13px system-ui, sans-serif",g.fillText(u,i/2,a/2+18),g.restore();return}t.textContent=`${s}. ${u}.`},ja=(t,e)=>{e.innerHTML=t},Zu=(t,e,n)=>{t.style.setProperty(e,n)},xP=(t,e)=>t.querySelector(`[data-mg="${e}"]`),tc=t=>e=>t===e,li=new WeakMap,Za=new WeakSet,ts=new WeakMap,ec=new WeakMap,nc=new WeakSet,Ki=new WeakMap,rc=new WeakMap,oc=new WeakMap;let wP=0;const NP=`#version 300 es
31
+ `;return}if(t instanceof HTMLCanvasElement){const c=window.devicePixelRatio||1;t.width=Math.max(1,Math.round(i*c)),t.height=Math.max(1,Math.round(a*c));const _=t.getContext("2d");if(!_)return;_.save(),_.scale(c,c),_.clearRect(0,0,i,a),_.fillStyle="#111827",_.fillRect(0,0,i,a),_.textAlign="center",_.textBaseline="middle",_.fillStyle="#f9fafb",_.font="700 18px system-ui, sans-serif",_.fillText(s,i/2,a/2-10),_.fillStyle="#cbd5e1",_.font="13px system-ui, sans-serif",_.fillText(u,i/2,a/2+18),_.restore();return}t.textContent=`${s}. ${u}.`},Va=(t,e)=>{e.innerHTML=t},Vu=(t,e,n)=>{t.style.setProperty(e,n)},dP=(t,e)=>t.querySelector(`[data-mg="${e}"]`),Xu=t=>e=>t===e,Uu=new WeakMap,rf=new WeakSet,lP=`#version 300 es
32
32
  precision highp float;
33
33
  out vec2 vUv;
34
34
  void main() {
35
35
  vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
36
36
  vUv = p;
37
37
  gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
38
- }`,TP=`#version 300 es
38
+ }`,hP=`#version 300 es
39
39
  precision highp float;
40
40
  uniform sampler2D uScene;
41
41
  uniform float uStrength;
@@ -44,7 +44,6 @@ uniform float uTime;
44
44
  in vec2 vUv;
45
45
  out vec4 fragColor;
46
46
 
47
-
48
47
  float grain(vec2 pixel, float frame) {
49
48
  vec2 cell = floor(pixel);
50
49
  return fract(sin(dot(cell + vec2(frame * 17.0, frame * 31.0), vec2(12.9898, 78.233))) * 43758.5453);
@@ -54,209 +53,13 @@ void main() {
54
53
  float film = clamp(uFilmAmount, 0.0, 1.0);
55
54
  vec4 color = texture(uScene, vUv);
56
55
  float strength = clamp(uStrength, 0.0, 1.0);
57
- // Non-spatial film character only: never shift, resample, or shade scene
58
- // pixels. Spatial vignettes read as muddy gradients on flat diagram fills.
59
56
  float frame = floor(uTime * 18.0);
60
57
  float grainValue = grain(gl_FragCoord.xy, frame) - 0.5;
61
58
  color.rgb += grainValue * (0.026 + 0.014 * strength) * film;
62
59
  float flicker = sin(uTime * 21.7) * 0.004 + sin(uTime * 7.1) * 0.003;
63
60
  color.rgb *= 1.0 + flicker * film;
64
61
  fragColor = color;
65
- }`,vP=`#version 300 es
66
- precision highp float;
67
- uniform vec4 uDestRect;
68
- uniform float uOpen;
69
- uniform float uPanel;
70
- uniform float uFall;
71
- out vec2 vLocal;
72
- out float vSurface;
73
- out float vThickness;
74
-
75
- void main() {
76
- vec2 corners[6] = vec2[6](
77
- vec2(0.0, 0.0), vec2(1.0, 0.0), vec2(0.0, 1.0),
78
- vec2(0.0, 1.0), vec2(1.0, 0.0), vec2(1.0, 1.0)
79
- );
80
- int surface = gl_VertexID / 6;
81
- vec2 p = corners[gl_VertexID - surface * 6];
82
- bool falling = uFall > 0.5;
83
- bool left = uPanel < 0.0;
84
- if (surface == 3 || (!falling && surface == 0 && !left)) p.x = 1.0 - p.x;
85
- float closedX;
86
- float localY;
87
- float thickness;
88
- if (falling) {
89
- if (surface == 0) {
90
- // The top edge of a single panel hinged along its bottom.
91
- closedX = p.x;
92
- localY = 0.0;
93
- thickness = p.y;
94
- } else if (surface == 1 || surface == 2) {
95
- // Left and right edges.
96
- closedX = surface == 1 ? 0.0 : 1.0;
97
- localY = p.x;
98
- thickness = p.y;
99
- } else {
100
- closedX = p.x;
101
- localY = p.y;
102
- thickness = surface == 3 ? 1.0 : 0.0;
103
- }
104
- } else if (surface == 0) {
105
- // The unhinged vertical edge.
106
- closedX = 0.5;
107
- localY = p.y;
108
- thickness = p.x;
109
- } else if (surface == 1 || surface == 2) {
110
- // Top and bottom edges.
111
- closedX = left ? p.x * 0.5 : 0.5 + p.x * 0.5;
112
- localY = surface == 1 ? 0.0 : 1.0;
113
- thickness = p.y;
114
- } else {
115
- closedX = left ? p.x * 0.5 : 0.5 + p.x * 0.5;
116
- localY = p.y;
117
- thickness = surface == 3 ? 1.0 : 0.0;
118
- }
119
-
120
- float slabDepth = 0.032;
121
- float projectedW;
122
- vec2 projectedLocal;
123
- if (falling) {
124
- float angle = max(0.0, uOpen) * 3.05;
125
- float towardViewer = (1.0 - localY) * sin(angle);
126
- float rotatedY = 1.0 + (localY - 1.0) * cos(angle);
127
- rotatedY += slabDepth * sin(angle) * thickness;
128
- towardViewer -= slabDepth * cos(angle) * thickness;
129
- projectedW = 1.0 - towardViewer * 0.22;
130
- projectedLocal = vec2(closedX, rotatedY);
131
- } else {
132
- float hingeX = left ? 0.0 : 1.0;
133
- float angle = max(0.0, uOpen) * 1.91986;
134
- float towardViewer = abs(closedX - hingeX) * sin(angle);
135
- float rotatedX = hingeX + (closedX - hingeX) * cos(angle);
136
- // The authored face is the front of a shallow slab. Its body extends away
137
- // from the viewer, rotated about the same border-welded vertical hinge.
138
- float panelSide = left ? 1.0 : -1.0;
139
- rotatedX += panelSide * slabDepth * sin(angle) * thickness;
140
- towardViewer -= slabDepth * cos(angle) * thickness;
141
- projectedW = 1.0 - towardViewer * 1.1;
142
- projectedLocal = vec2(rotatedX, localY);
143
- }
144
- vec2 center = uDestRect.xy + uDestRect.zw * 0.5;
145
- vec2 world = uDestRect.xy + projectedLocal * uDestRect.zw;
146
- vec2 projected = center + (world - center) / projectedW;
147
- vec2 ndc = vec2(projected.x * 2.0 - 1.0, 1.0 - projected.y * 2.0);
148
- gl_Position = vec4(ndc * projectedW, 0.0, projectedW);
149
- vLocal = vec2(closedX, localY);
150
- vSurface = float(surface);
151
- vThickness = thickness;
152
- }`,bP=`#version 300 es
153
- precision highp float;
154
- uniform sampler2D uDoor;
155
- uniform vec4 uCaptureRect;
156
- uniform vec2 uFaceSize;
157
- uniform float uOpen;
158
- uniform float uAttention;
159
- uniform float uPanel;
160
- uniform float uFall;
161
- uniform float uRadius;
162
- in vec2 vLocal;
163
- in float vSurface;
164
- in float vThickness;
165
- out vec4 fragColor;
166
-
167
- float roundedPanel(vec2 local) {
168
- bool falling = uFall > 0.5;
169
- bool left = uPanel < 0.0;
170
- vec2 panelLocal = falling
171
- ? local
172
- : vec2(left ? local.x * 2.0 : (local.x - 0.5) * 2.0, local.y);
173
- vec2 panelSize = vec2(falling ? uFaceSize.x : uFaceSize.x * 0.5, uFaceSize.y);
174
- vec2 halfSize = panelSize * 0.5;
175
- float radius = min(uRadius, min(halfSize.x, halfSize.y));
176
- bool innerCorner = !falling && (left ? panelLocal.x > 0.5 : panelLocal.x < 0.5);
177
- float innerReveal = smoothstep(0.08, 0.20, uOpen);
178
- float cornerRadius = innerCorner ? radius * innerReveal : radius;
179
- vec2 q =
180
- abs((panelLocal - 0.5) * panelSize) -
181
- (halfSize - vec2(cornerRadius));
182
- return
183
- length(max(q, 0.0)) +
184
- min(max(q.x, q.y), 0.0) -
185
- cornerRadius;
186
- }
187
- vec2 doorUv(vec2 local) {
188
- return vec2(
189
- uCaptureRect.x + local.x * uCaptureRect.z,
190
- 1.0 - (uCaptureRect.y + local.y * uCaptureRect.w)
191
- );
192
- }
193
- float bayer4(vec2 pixel) {
194
- float thresholds[16] = float[16](
195
- 0.0, 8.0, 2.0, 10.0,
196
- 12.0, 4.0, 14.0, 6.0,
197
- 3.0, 11.0, 1.0, 9.0,
198
- 15.0, 7.0, 13.0, 5.0
199
- );
200
- ivec2 cell = ivec2(mod(floor(pixel), 4.0));
201
- return (thresholds[cell.y * 4 + cell.x] + 0.5) / 16.0;
202
- }
203
-
204
-
205
-
206
- void main() {
207
- // Each moving half keeps the authored outer radius. Its cut-edge corners
208
- // round only after the split opens, so the closed leaves still form one
209
- // continuous rounded face without a notched centre seam.
210
- if (roundedPanel(vLocal) > 0.0) discard;
211
- if (uOpen < 0.08 && vSurface < 3.5) discard;
212
- vec4 material = texture(uDoor, doorUv(vLocal));
213
- if (vSurface > 3.5) {
214
- material.rgb *= 1.0 - 0.20 * uOpen;
215
- } else if (vSurface > 2.5) {
216
- // Recover a label-free base color, then use a uniform two-tone stipple.
217
- // Spatial lighting ramps looked like accidental gradients on flat nodes.
218
- vec4 back0 = texture(uDoor, doorUv(vec2(0.34, 0.30)));
219
- vec4 back1 = texture(uDoor, doorUv(vec2(0.66, 0.30)));
220
- vec4 back2 = texture(uDoor, doorUv(vec2(0.34, 0.70)));
221
- vec4 back3 = texture(uDoor, doorUv(vec2(0.66, 0.70)));
222
- float backWeight = back0.a + back1.a + back2.a + back3.a;
223
- vec3 backMaterial =
224
- (
225
- back0.rgb * back0.a +
226
- back1.rgb * back1.a +
227
- back2.rgb * back2.a +
228
- back3.rgb * back3.a
229
- ) / max(0.001, backWeight);
230
- if (backWeight < 0.1) backMaterial = material.rgb;
231
- float angle = smoothstep(0.08, 0.18, uOpen) * 1.91986;
232
- float facing = abs(cos(angle));
233
- float density = mix(0.46, 0.66, facing);
234
- float dither = bayer4(gl_FragCoord.xy * 0.5);
235
- vec3 darkInk = backMaterial * 0.48;
236
- vec3 lightInk = min(vec3(1.0), backMaterial * 0.96 + vec3(0.025));
237
- material.rgb = mix(darkInk, lightInk, step(dither, density));
238
- } else {
239
- if (vSurface > 0.5 && vSurface < 1.5) {
240
- float ledgeDither = bayer4(gl_FragCoord.xy * 0.5);
241
- material.rgb = mix(vec3(0.11), vec3(0.46), step(ledgeDither, 0.44));
242
- } else {
243
- material.rgb = vec3(vSurface < 0.5 ? 0.18 : 0.24);
244
- }
245
- }
246
- if (vSurface > 2.5) {
247
- float splitReveal = smoothstep(0.18, 0.34, uOpen);
248
- float edgeDistance = abs(roundedPanel(vLocal));
249
- float screenPixel = max(fwidth(edgeDistance), 0.0001);
250
- float outline = splitReveal
251
- * (1.0 - smoothstep(0.35 * screenPixel, 3.5 * screenPixel, edgeDistance));
252
- float outlineX = uPanel < 0.0 ? 0.0 : 1.0;
253
- vec4 outlineMaterial = texture(uDoor, doorUv(vec2(outlineX, 0.5)));
254
- material.rgb = mix(material.rgb, outlineMaterial.rgb, outline);
255
- material.a = max(material.a, outline * outlineMaterial.a);
256
- }
257
- material.a = 1.0;
258
- fragColor = material;
259
- }`,vm=(t,e,n)=>{const r=t.createShader(e);if(!r)throw new Error("Unable to allocate zoom shader");if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS)){const o=t.getShaderInfoLog(r)||"Zoom shader compilation failed";throw t.deleteShader(r),new Error(o)}return r},bm=(t,e,n,r)=>{const o=vm(t,t.VERTEX_SHADER,e),i=vm(t,t.FRAGMENT_SHADER,n),a=t.createProgram();if(!a)throw new Error(`Unable to allocate ${r} program`);if(t.attachShader(a,o),t.attachShader(a,i),t.linkProgram(a),t.deleteShader(o),t.deleteShader(i),!t.getProgramParameter(a,t.LINK_STATUS)){const s=t.getProgramInfoLog(a)||`${r} shader link failed`;throw t.deleteProgram(a),new Error(s)}return a},Jm=t=>{if(typeof document>"u"||typeof t?.getContext!="function"||!t.parentElement)return null;const e=document.createElement("canvas"),n=e.getContext("webgl2",{alpha:!0,antialias:!1,depth:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,stencil:!1});if(!n)return null;const r=t.parentElement,o=r.style.position,i=getComputedStyle(r).position==="static";i&&(r.style.position="relative"),e.dataset.mg="velocity-pass",e.setAttribute("aria-hidden","true"),Object.assign(e.style,{display:"none",left:`${t.offsetLeft}px`,pointerEvents:"none",position:"absolute",top:`${t.offsetTop}px`,zIndex:"1"}),t.insertAdjacentElement("afterend",e);try{const a=bm(n,NP,TP,"zoom"),s=bm(n,vP,bP,"door"),u=n.createTexture();if(!u)throw new Error("Unable to allocate zoom texture");return n.bindTexture(n.TEXTURE_2D,u),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!0),n.useProgram(a),n.uniform1i(n.getUniformLocation(a,"uScene"),0),n.useProgram(s),n.uniform1i(n.getUniformLocation(s,"uDoor"),1),{changedPosition:i,doorAttentionLocation:n.getUniformLocation(s,"uAttention"),doorCaptureLocation:n.getUniformLocation(s,"uCaptureRect"),doorDestLocation:n.getUniformLocation(s,"uDestRect"),doorFaceSizeLocation:n.getUniformLocation(s,"uFaceSize"),doorRadiusLocation:n.getUniformLocation(s,"uRadius"),doorFallLocation:n.getUniformLocation(s,"uFall"),doorOpenLocation:n.getUniformLocation(s,"uOpen"),doorPanelLocation:n.getUniformLocation(s,"uPanel"),doorProgram:s,doorTextures:new Map,gl:n,overlay:e,overlayHeight:-1,overlayLeft:-1,overlayTop:-1,overlayWidth:-1,parent:r,program:a,restorePosition:o,restoreVisibility:t.style.visibility,sceneTextureHeight:0,sceneTextureWidth:0,source:t,texture:u,zoomFilmAmountLocation:n.getUniformLocation(a,"uFilmAmount"),zoomStrengthLocation:n.getUniformLocation(a,"uStrength"),zoomTimeLocation:n.getUniformLocation(a,"uTime")}}catch{return e.remove(),i&&r.style.position==="relative"&&(r.style.position=o),null}},Cm=t=>{const e=Ki.get(t);e&&e(),Ki.delete(t)},JP=t=>{if(li.has(t)||Za.has(t)||Ki.has(t))return;const e=()=>{if(Ki.delete(t),!t.isConnected||li.has(t))return;let n=null;try{n=Jm(t)}catch{n=null}n?li.set(t,n):(Za.add(t),t.setAttribute("data-mg-gpu-pass","unavailable"))};if(typeof requestIdleCallback=="function"){const n=requestIdleCallback(e,{timeout:50});Ki.set(t,()=>cancelIdleCallback(n))}else{const n=setTimeout(e,0);Ki.set(t,()=>clearTimeout(n))}},CP=(t,e)=>{e&&(e.overlay.style.display!=="none"&&(e.overlay.style.display="none"),t.style.visibility!==e.restoreVisibility&&(t.style.visibility=e.restoreVisibility)),t.getAttribute("data-mg-gpu-pass")!=="idle"&&t.setAttribute("data-mg-gpu-pass","idle"),t.removeAttribute("data-mg-door-motion")},kP=(t,e)=>{const n=ts.get(t),r=n?.canvas||document.createElement("canvas");r.width!==t.width&&(r.width=t.width),r.height!==t.height&&(r.height=t.height);const o=r.getContext("2d");o&&(o.clearRect(0,0,r.width,r.height),o.drawImage(t,0,0),ts.set(t,{canvas:r,capture:[e.x,e.y,e.w,e.h],faceSize:[e.w*t.width,e.h*t.height],key:String(e.key),radius:e.r*t.width,version:(n?.version||0)+1}))},ff=(t,e,n)=>{const r=Math.max(0,Math.min(1,(n-t)/Math.max(1e-6,e-t)));return r*r*(3-2*r)},LP=(t,e,n)=>Math.max(0,Math.min(Number(t)||0,Math.max(0,Number(e)||0)*.5,Math.max(0,Number(n)||0)*.5)),SP=4,EP=(t,e)=>Math.max(0,Number(t)||0)/Math.max(1e-6,Math.max(0,Number(e)||0))>=SP,AP=(t,e)=>{let n=(Number(t)|0)^2166136261;for(let r=0;r<String(e).length;r+=1)n=Math.imul(n^String(e).charCodeAt(r),16777619);return n>>>0},km=(t,e,n,r)=>EP(n,r)||AP(t,e)%3===0,ji=.48,Zi=10.8,Lm=Math.sqrt(1-ji*ji),ic=Zi*Lm,Sm=ji/Lm,PP=1-Math.exp(-ji*Zi)*(Math.cos(ic)+Sm*Math.sin(ic)),lf=t=>{const e=Math.max(0,Math.min(1,t));return(1-Math.exp(-ji*Zi*e)*(Math.cos(ic*e)+Sm*Math.sin(ic*e)))/PP},RP=(t,e,n)=>{let r=Number.isFinite(t.value)?t.value:0,o=Number.isFinite(t.velocity)?t.velocity:0,i=Math.max(0,Math.min(.1,Number(n)||0));const a=Number(e)>=.5?1:0;for(;i>0;){const s=Math.min(i,.008333333333333333),u=Zi*Zi*(a-r)-2*ji*Zi*o;o+=u*s,r+=o*s,i-=s}return{value:r,velocity:o}},Em=(t,e,n,r)=>{const o=String(e.key),i=Number(e.progress)||0,a=Number(e.depth)||0,s=ec.get(t),u=s&&s.key===o&&s.direction===n,c=u&&Math.abs(i-s.progress)>.12;let g=u?s:{direction:n,key:o,progress:i,value:Am(a,i,n),velocity:0};if(c)g={...g,value:Am(a,i,n),velocity:0};else{const l=1-Math.max(0,Math.min(1,a)),d=(n<0?i>=.25:l<.48)?1:0;g={...g,...RP(g,d,r)}}return g.progress=i,ec.set(t,g),g.value},Am=(t,e,n)=>{if(n<0){const s=Math.max(0,Math.min(1,(e-.25)/.28));return lf(s*s*s)}const r=1-Math.max(0,Math.min(1,t)),o=Math.max(0,Math.min(1,(r-.48)/.5)),i=.48,a=lf(o*i)/lf(i);return Math.min(1,Math.abs(1-a))},di="http://www.w3.org/2000/svg",GP=t=>{if(!t.parentElement)return null;const e=t.parentElement,n=e.style.position,r=getComputedStyle(e).position==="static";r&&(e.style.position="relative");const o=document.createElementNS(di,"svg");o.dataset.mg="svg-door-pass",o.setAttribute("aria-hidden","true"),o.setAttribute("viewBox","0 0 1 1"),o.setAttribute("preserveAspectRatio","none");const i=document.createElementNS(di,"defs");o.appendChild(i);const a=h=>{const m=document.createElementNS(di,"path");m.dataset.mgDoorLeaf=h;const p=`mg-door-${h}-${++wP}`;m.setAttribute("id",p),m.setAttribute("vector-effect","non-scaling-stroke"),m.setAttribute("stroke-linejoin","round"),o.appendChild(m);const x=document.createElementNS(di,"clipPath"),y=`${p}-clip`;x.setAttribute("id",y),x.setAttribute("clipPathUnits","userSpaceOnUse");const N=document.createElementNS(di,"use");N.setAttribute("href",`#${p}`),x.appendChild(N),i.appendChild(x);const v=document.createElementNS(di,"text");return v.dataset.mgDoorLabelClip=`url(#${y})`,v.dataset.mgDoorLabelHalf=h,v.setAttribute("clip-path",`url(#${y})`),v.setAttribute("text-anchor","middle"),v.setAttribute("stroke","none"),{label:v,leaf:m}},s=a("left"),u=a("right"),c=(h,m)=>{const p=document.createElementNS(di,"path");return p.dataset[h==="outer"?"mgDoorOuter":"mgDoorSeam"]=m,p.setAttribute("fill","none"),p.setAttribute("stroke-linejoin","round"),p.setAttribute("vector-effect","non-scaling-stroke"),o.appendChild(p),p},g=c("outer","left"),l=c("outer","right"),d=c("seam","left"),f=c("seam","right");return o.appendChild(s.label),o.appendChild(u.label),Object.assign(o.style,{display:"none",pointerEvents:"none",position:"absolute",zIndex:"1"}),t.insertAdjacentElement("afterend",o),{changedPosition:r,left:s.leaf,leftLabel:s.label,overlay:o,leftOuter:g,leftSeam:d,parent:e,restorePosition:n,right:u.leaf,rightLabel:u.label,rightOuter:l,rightSeam:f}},So=(t,e,n,r,o)=>{const i=n?0:1,a=Math.abs(r-i)*Math.sin(e),s=i+(r-i)*Math.cos(e),u=1-a*1.1,c=Number(t.x)+Number(t.w)*.5,g=Number(t.y)+Number(t.h)*.5,l=Number(t.x)+s*Number(t.w),d=Number(t.y)+o*Number(t.h);return[c+(l-c)/u,g+(d-g)/u]},Pm=(t,e,n,r)=>{const o=Math.max(0,e)*1.91986,i=Math.max(0,Math.min(.5,Number(t.r)/Math.max(1e-6,Number(t.w)))),a=Math.max(0,Math.min(.5,Number(t.r)*r/Math.max(1e-6,Number(t.h)))),s=p=>So(t,o,n,p[0],p[1]),u=(p,...x)=>`${p}${x.map(s).map(y=>`${y[0]},${y[1]}`).join(" ")}`,c=.5522847498307936,g=ff(.08,.2,e),l=i*g,d=a*g,f=[u("M",[.5,d]),u("L",[.5,1-d])].join(" ");if(n){const p=[u("M",[i,0]),u("C",[i*(1-c),0],[0,a*(1-c)],[0,a]),u("L",[0,1-a]),u("C",[0,1-a*(1-c)],[i*(1-c),1],[i,1]),u("L",[.5-l,1]),u("C",[.5-l*(1-c),1],[.5,1-d*(1-c)],[.5,1-d]),u("L",[.5,d]),u("C",[.5,d*(1-c)],[.5-l*(1-c),0],[.5-l,0]),"Z"].join(" "),x=[u("M",[.5,d]),u("C",[.5,d*(1-c)],[.5-l*(1-c),0],[.5-l,0]),u("L",[i,0]),u("C",[i*(1-c),0],[0,a*(1-c)],[0,a]),u("L",[0,1-a]),u("C",[0,1-a*(1-c)],[i*(1-c),1],[i,1]),u("L",[.5-l,1]),u("C",[.5-l*(1-c),1],[.5,1-d*(1-c)],[.5,1-d])].join(" ");return{fill:p,outer:x,seam:f}}const h=[u("M",[.5+l,0]),u("L",[1-i,0]),u("C",[1-i*(1-c),0],[1,a*(1-c)],[1,a]),u("L",[1,1-a]),u("C",[1,1-a*(1-c)],[1-i*(1-c),1],[1-i,1]),u("L",[.5+l,1]),u("C",[.5+l*(1-c),1],[.5,1-d*(1-c)],[.5,1-d]),u("L",[.5,d]),u("C",[.5,d*(1-c)],[.5+l*(1-c),0],[.5+l,0]),"Z"].join(" "),m=[u("M",[.5,d]),u("C",[.5,d*(1-c)],[.5+l*(1-c),0],[.5+l,0]),u("L",[1-i,0]),u("C",[1-i*(1-c),0],[1,a*(1-c)],[1,a]),u("L",[1,1-a]),u("C",[1,1-a*(1-c)],[1-i*(1-c),1],[1-i,1]),u("L",[.5+l,1]),u("C",[.5+l*(1-c),1],[.5,1-d*(1-c)],[.5,1-d])].join(" ");return{fill:h,outer:m,seam:f}},df=(t,e)=>{const n=Math.max(0,e)*3.05,r=Math.cos(n);return{expansion:1+Math.sin(n)*.16,verticalScale:Math.abs(r)<.06?r<0?-.06:.06:r}},hf=(t,e,n,r)=>{const{expansion:o,verticalScale:i}=df(t,e),a=Number(t.x)+Number(t.w)*.5,s=Number(t.y)+Number(t.h),u=Number(t.x)+n*Number(t.w),c=Number(t.y)+r*Number(t.h);return[a+(u-a)*o,s+(c-s)*i]},DP=(t,e,n)=>{const r=Math.max(0,Math.min(.5,Number(t.r)/Math.max(1e-6,Number(t.w)))),o=Math.max(0,Math.min(.5,Number(t.r)*n/Math.max(1e-6,Number(t.h)))),i=c=>hf(t,e,c[0],c[1]),a=(c,...g)=>`${c}${g.map(i).map(l=>`${l[0]},${l[1]}`).join(" ")}`,s=.5522847498307936,u=[a("M",[r,0]),a("C",[r*(1-s),0],[0,o*(1-s)],[0,o]),a("L",[0,1-o]),a("C",[0,1-o*(1-s)],[r*(1-s),1],[r,1]),a("L",[1-r,1]),a("C",[1-r*(1-s),1],[1,1-o*(1-s)],[1,1-o]),a("L",[1,o]),a("C",[1,o*(1-s)],[1-r*(1-s),0],[1-r,0]),"Z"].join(" ");return{fill:u,outer:u,seam:""}},FP=(t,e,n)=>{const{expansion:r,verticalScale:o}=df(t,e),i=Number(t.x)+Number(t.w)*.5,a=Number(t.y)+Number(t.h)*.5,s=hf(t,e,.5,.5),u=r*n,c=o*n;return`matrix(${u} 0 0 ${c} ${s[0]-u*i} ${s[1]-c*a})`},IP=(t,e,n)=>{const r=n.left+(Number(e.x)+Number(e.w)*.5)*n.width,o=n.top+(Number(e.y)+Number(e.h)*.5)*n.height,i=f=>String(f||"").replace(/\s+/g," ").trim(),a=i(e.label);let s=null,u=null,c=1/0,g=!1;for(const f of t.querySelectorAll("text")){const h=i(f.textContent);if(!h)continue;const m=f.getBoundingClientRect();if(m.width<=0||m.height<=0)continue;const p=a!==""&&h===a;if(p&&!g&&(c=1/0,s=null,u=null,g=!0),g&&!p)continue;const x=Math.abs(m.left+m.width*.5-r)+Math.abs(m.top+m.height*.5-o);x<c&&(c=x,s=f,u=m)}if(!s||!u)return null;const l=getComputedStyle(s),d=Number.parseFloat(l.fontSize)||Number.parseFloat(s.getAttribute("font-size"))||u.height*.8;return{dominantBaseline:s.getAttribute("dominant-baseline"),dy:s.getAttribute("dy"),fill:s.getAttribute("fill")||l.fill||"rgb(244,244,245)",fontFamily:s.getAttribute("font-family")||l.fontFamily||"sans-serif",doorHeight:Math.max(1e-6,Math.abs(Number(e.h))),fontSize:d/Math.max(1,n.height),fontStyle:s.getAttribute("font-style")||l.fontStyle||"normal",fontWeight:s.getAttribute("font-weight")||l.fontWeight||"400",opacity:s.getAttribute("fill-opacity")||l.fillOpacity||"1",text:a||s.textContent.trim()}},BP=(t,e,n,r,o)=>{const i=Math.max(0,e)*1.91986,a=Number(t.x),s=Number(t.y),u=Number(t.w),c=Number(t.h),g=n?0:1,l=.5,d=[a+g*u,s],f=[a+l*u,s],h=So(t,i,n,g,0),m=So(t,i,n,l,0),p=So(t,i,n,g,1);let x=(m[0]-h[0])/(f[0]-d[0]),y=(m[1]-h[1])/(f[0]-d[0]),N=(p[0]-h[0])/c,v=(p[1]-h[1])/c;const J=Math.hypot(x*r.width,y*r.height),k=(x<0?-1:1)*r.height/Math.max(1e-6,J);x*=k*o,y*=k*o,N*=o,v*=o;const S=.5,A=a+S*u,I=s+c*.5,$=So(t,i,n,S,.5),E=$[0]-x*A-N*I,G=$[1]-y*A-v*I;return`matrix(${x} ${y} ${N} ${v} ${E} ${G})`},MP=(t,e,n)=>{const r=Array.from(t.querySelectorAll("rect[fill][stroke]")).filter(c=>c.getAttribute("fill")!=="none"&&c.getAttribute("stroke")!=="none"),o={x:n.left+Number(e.x)*n.width,y:n.top+Number(e.y)*n.height,w:Number(e.w)*n.width,h:Number(e.h)*n.height},i=o.x+o.w*.5,a=o.y+o.h*.5;let s=null,u=1/0;for(const c of r){const g=c.getBoundingClientRect();if(g.width<=0||g.height<=0)continue;const l=Math.abs(g.left+g.width*.5-i)/Math.max(1,o.w)+Math.abs(g.top+g.height*.5-a)/Math.max(1,o.h),d=Math.abs(Math.log(g.width/Math.max(1,o.w)))+Math.abs(Math.log(g.height/Math.max(1,o.h))),f=l+d;f<u&&(u=f,s=c)}return s||(s=r[0]||null),{fill:s?.getAttribute("fill")||"rgb(24,24,27)",stroke:s?.getAttribute("stroke")||"rgb(244,244,245)"}},Rm=(t,e,n,r)=>{const o=n?.armed>0&&Number(n.w)>0&&Number(n.h)>0,i=o&&n?.active>0,a=String(n?.key||"");let s=null,u=oc.get(t);if(o&&u?.key!==a){oc.delete(t),s=t.getBoundingClientRect();const V=IP(t,n,s);V?(u={key:a,label:V},oc.set(t,u)):u=null}const c=i?Em(t,n,e,r):0,g=i&&(c>.08||Number(n?.faceAlpha)<.999);let l=rc.get(t);if(!g){l&&(l.overlay.style.display="none"),t.setAttribute("data-mg-svg-door-pass","idle"),t.removeAttribute("data-mg-door-motion");return}if(!l){if(l=GP(t),!l)return;rc.set(t,l)}s||(s=t.getBoundingClientRect());const d=km(n.seed,n.key,Number(n.w)*s.width,Number(n.h)*s.height);t.setAttribute("data-mg-door-motion",d?"fall":"split");const{fill:f,stroke:h}=MP(t,n,s);for(const V of[l.left,l.right])V.setAttribute("fill",f),V.setAttribute("stroke","none"),V.setAttribute("fill-opacity","1");for(const V of[l.leftOuter,l.rightOuter])V.setAttribute("stroke",h),V.setAttribute("stroke-width","1.25"),V.setAttribute("stroke-opacity","1");const m=d?0:ff(.08,.26,c);for(const V of[l.leftSeam,l.rightSeam])V.setAttribute("stroke",h),V.setAttribute("stroke-width","1.25"),V.setAttribute("stroke-opacity",String(m));const p=s.width/Math.max(1e-6,s.height),x=d?DP(n,c,p):Pm(n,c,!0,p),y=d?{fill:"",outer:"",seam:""}:Pm(n,c,!1,p);l.left.setAttribute("d",x.fill),l.leftOuter.setAttribute("d",x.outer),l.leftSeam.setAttribute("d",x.seam),l.right.setAttribute("d",y.fill),l.rightOuter.setAttribute("d",y.outer),l.rightSeam.setAttribute("d",y.seam);const N=u?.key===a?u.label:null,v=Math.max(0,c)*1.91986,J=df(n,c),k=d?J.verticalScale>0:So(n,v,!0,.5,0)[0]>So(n,v,!0,0,0)[0],S=N?Math.abs(Number(n.h))/Math.max(1e-6,N.doorHeight):0,A=N?N.fontSize*s.height*S*(d?J.verticalScale:1):0,I=d?[hf(n,c,.5,.5)].some(([V,Q])=>V>=0&&V<=1&&Q>=0&&Q<=1):[!0,!1].map(V=>So(n,v,V,.5,.5)).some(([V,Q])=>V>=0&&V<=1&&Q>=0&&Q<=1),$=k&&A>=8&&I,E=[[l.leftLabel,!0],[l.rightLabel,!1]];for(const[V,Q]of E){if(!N){V.setAttribute("display","none");continue}if(!$&&!Q||d&&!Q){V.setAttribute("display","none"),V.textContent="";continue}V.removeAttribute("display"),V.textContent=N.text,V.setAttribute("fill",N.fill),V.setAttribute("fill-opacity",N.opacity),V.setAttribute("font-family",N.fontFamily),V.setAttribute("font-size",String(N.fontSize)),V.setAttribute("font-style",N.fontStyle),V.setAttribute("font-weight",N.fontWeight),N.dominantBaseline==null?V.removeAttribute("dominant-baseline"):V.setAttribute("dominant-baseline",N.dominantBaseline),N.dy==null?V.removeAttribute("dy"):V.setAttribute("dy",N.dy);const Y=Math.max(.04,Math.min(.96,Number(n.x)+Number(n.w)*.5)),X=Math.max(.04,Math.min(.96,Number(n.y)+Number(n.h)*.5));V.setAttribute("x",String($?Number(n.x)+Number(n.w)*.5:Y)),V.setAttribute("y",String($?Number(n.y)+Number(n.h)*.5:X)),$?(V.setAttribute("clip-path",V.dataset.mgDoorLabelClip),V.setAttribute("transform",d?FP(n,c,S):BP(n,c,Q,s,S))):(V.removeAttribute("clip-path"),V.removeAttribute("transform"))}const{overlay:G}=l,nt=l.parent.getBoundingClientRect();G.style.left=`${s.left-nt.left-l.parent.clientLeft}px`,G.style.top=`${s.top-nt.top-l.parent.clientTop}px`,G.style.width=`${s.width}px`,G.style.height=`${s.height}px`,G.style.display="block",t.setAttribute("data-mg-svg-door-pass","active")},zP=t=>{const e=rc.get(t);e&&(e.overlay.remove(),e.changedPosition&&e.parent.style.position==="relative"&&(e.parent.style.position=e.restorePosition)),rc.delete(t),ec.delete(t),oc.delete(t),t.removeAttribute("data-mg-svg-door-pass"),t.removeAttribute("data-mg-door-motion")},QP=(t,e,n)=>{const{gl:r}=t,o=ts.get(e),i=o?.key===String(n.key)?o:null,a=i?.canvas||e,s=r.createTexture();return s?(r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,s),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR_MIPMAP_LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,a),r.generateMipmap(r.TEXTURE_2D),{capture:i?.capture||[n.x,n.y,n.w,n.h],faceSize:i?.faceSize||[n.w*a.width,n.h*a.height],radius:i?.radius||n.r*a.width,version:i?.version||0,texture:s}):null},Gm=(t,e,n,r,o)=>{const i=r?.active>0&&Number(r.w)>0&&Number(r.h)>0,a=i?Em(t,r,n,o):0,s=i&&(a>.08||Number(r?.faceAlpha)<.999),u=i&&(s||Number(e)>=.008);let c=li.get(t);if(r?.prewarm>0&&!c&&JP(t),!u){r?.armed>0?nc.has(t)||(kP(t,r),nc.add(t)):nc.delete(t),CP(t,c);return}if(Za.has(t)){t.setAttribute("data-mg-gpu-pass","unavailable");return}if(!c){Cm(t);try{c=Jm(t)}catch{c=null}if(!c){Za.add(t),t.setAttribute("data-mg-gpu-pass","unavailable");return}li.set(t,c)}const{gl:g,overlay:l,program:d,texture:f}=c,h=Math.max(1,t.width),m=Math.max(1,t.height),p=h,x=m;l.width!==p&&(l.width=p),l.height!==x&&(l.height=x);const y=t.offsetLeft,N=t.offsetTop,v=t.clientWidth,J=t.clientHeight;c.overlayLeft!==y&&(l.style.left=`${y}px`,c.overlayLeft=y),c.overlayTop!==N&&(l.style.top=`${N}px`,c.overlayTop=N),c.overlayWidth!==v&&(l.style.width=`${v}px`,c.overlayWidth=v),c.overlayHeight!==J&&(l.style.height=`${J}px`,c.overlayHeight=J),l.style.display!=="block"&&(l.style.display="block"),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,f),c.sceneTextureWidth!==h||c.sceneTextureHeight!==m?(g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,t),c.sceneTextureWidth=h,c.sceneTextureHeight=m):g.texSubImage2D(g.TEXTURE_2D,0,0,0,g.RGBA,g.UNSIGNED_BYTE,t),g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,p,x),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,f),g.useProgram(d),g.uniform1f(c.zoomFilmAmountLocation,Math.sqrt(Math.max(0,Math.min(1,Number(e)||0)))),g.uniform1f(c.zoomTimeLocation,performance.now()/1e3),g.uniform1f(c.zoomStrengthLocation,Math.max(0,Math.min(1,Number(e)||0))),g.drawArrays(g.TRIANGLES,0,3);const k=i?ts.get(t):null,S=k?.key===String(r.key)?k.version:null;let A=i?c.doorTextures.get(String(r.key)):null;i&&(!A||S!==null&&A.version!==S)&&(A&&g.deleteTexture(A.texture),A=QP(c,t,r),A&&c.doorTextures.set(String(r.key),A));const I=ff(.08,.18,a),$=Number(r.faceAlpha)<.999;if(i&&A&&(I>.001||$)){g.enable(g.BLEND),g.blendFunc(g.SRC_ALPHA,g.ONE_MINUS_SRC_ALPHA),g.enable(g.CULL_FACE),g.frontFace(g.CW),g.activeTexture(g.TEXTURE1),g.bindTexture(g.TEXTURE_2D,A.texture),g.useProgram(c.doorProgram),g.uniform4fv(c.doorCaptureLocation,A.capture),g.uniform2fv(c.doorFaceSizeLocation,A.faceSize),g.uniform1f(c.doorRadiusLocation,LP(A.radius,A.faceSize[0],A.faceSize[1]));const E=Number(r.x),G=Number(r.y),nt=Number(r.w),V=Number(r.h);g.uniform4f(c.doorDestLocation,E,G,nt,V),g.uniform1f(c.doorAttentionLocation,0),g.uniform1f(c.doorOpenLocation,a);const Q=km(r.seed,r.key,A.faceSize[0],A.faceSize[1]);t.setAttribute("data-mg-door-motion",Q?"fall":"split"),g.uniform1f(c.doorFallLocation,Q?1:0),Q?(g.uniform1f(c.doorPanelLocation,0),g.drawArrays(g.TRIANGLES,0,30)):(g.uniform1f(c.doorPanelLocation,-1),g.drawArrays(g.TRIANGLES,0,30),g.uniform1f(c.doorPanelLocation,1),g.drawArrays(g.TRIANGLES,0,30)),g.disable(g.BLEND),g.disable(g.CULL_FACE)}t.getAttribute("data-mg-gpu-pass")!=="active"&&t.setAttribute("data-mg-gpu-pass","active"),t.style.visibility!=="hidden"&&(t.style.visibility="hidden")},WP=t=>{Cm(t);const e=li.get(t);if(e){e.gl.deleteTexture(e.texture);for(const n of e.doorTextures.values())e.gl.deleteTexture(n.texture);e.gl.deleteProgram(e.doorProgram),e.gl.deleteProgram(e.program),e.overlay.remove(),t.style.visibility=e.restoreVisibility,e.changedPosition&&e.parent.style.position==="relative"&&(e.parent.style.position=e.restorePosition)}li.delete(t),Za.delete(t),ts.delete(t),nc.delete(t),t.removeAttribute("data-mg-gpu-pass"),t.removeAttribute("data-mg-door-motion"),ec.delete(t)},Dm=(t,e)=>({tag:t,_1:e}),Fm=t=>t,OP=(t,e,n)=>({tag:t,_1:e,_2:n}),wr=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;_()},HP=pm(u_),$P=Mt.foldMap(j2),qP=is(xi),es=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=P.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}_()}return o},Im=Ym(Tf),hi=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;_()},pf=OP("AutoSize"),UP=Fm("CanvasRenderer"),XP=Fm("SvgRenderer"),VP=t=>e=>{const n=t-e*rt(de(Vn(t/e)));return e<=0?0:n<0?n+e:n},ta=t=>b(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),YP=t=>{const e=xm("data-markgraf-titles")(t);return()=>{const n=e();return n.tag==="Nothing"||!(n.tag==="Just"&&n._1==="false")}},KP=t=>{const e=xm("data-markgraf-theme")(t);return()=>{const n=e();if(n.tag==="Just")return n._1==="light"?W_:n._1==="dark"?T5:n._1==="blueprint"?v5:n._1==="whiteboard"?b5:n._1==="isometric"?J5:W_;if(n.tag==="Nothing")return W_;_()}},jP=`
62
+ }`,ym=(t,e,n)=>{const r=t.createShader(e);if(!r)throw new Error("Unable to allocate zoom shader");if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS)){const o=t.getShaderInfoLog(r)||"Zoom shader compilation failed";throw t.deleteShader(r),new Error(o)}return r},pP=(t,e,n)=>{const r=ym(t,t.VERTEX_SHADER,e),o=ym(t,t.FRAGMENT_SHADER,n),i=t.createProgram();if(!i)throw new Error("Unable to allocate zoom program");if(t.attachShader(i,r),t.attachShader(i,o),t.linkProgram(i),t.deleteShader(r),t.deleteShader(o),!t.getProgramParameter(i,t.LINK_STATUS)){const a=t.getProgramInfoLog(i)||"Zoom shader link failed";throw t.deleteProgram(i),new Error(a)}return i},mP=t=>{if(typeof document>"u"||typeof t?.getContext!="function"||!t.parentElement)return null;const e=document.createElement("canvas"),n=e.getContext("webgl2",{alpha:!0,antialias:!1,depth:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,stencil:!1});if(!n)return null;const r=t.parentElement,o=r.style.position,i=getComputedStyle(r).position==="static";i&&(r.style.position="relative"),e.dataset.mg="velocity-pass",e.setAttribute("aria-hidden","true"),Object.assign(e.style,{display:"none",left:`${t.offsetLeft}px`,pointerEvents:"none",position:"absolute",top:`${t.offsetTop}px`,zIndex:"1"}),t.insertAdjacentElement("afterend",e);try{const a=pP(n,lP,hP),s=n.createTexture();if(!s)throw new Error("Unable to allocate zoom texture");return n.bindTexture(n.TEXTURE_2D,s),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!0),n.useProgram(a),n.uniform1i(n.getUniformLocation(a,"uScene"),0),{changedPosition:i,gl:n,overlay:e,overlayHeight:-1,overlayLeft:-1,overlayTop:-1,overlayWidth:-1,parent:r,program:a,restorePosition:o,restoreVisibility:t.style.visibility,sceneTextureHeight:0,sceneTextureWidth:0,source:t,texture:s,zoomFilmAmountLocation:n.getUniformLocation(a,"uFilmAmount"),zoomStrengthLocation:n.getUniformLocation(a,"uStrength"),zoomTimeLocation:n.getUniformLocation(a,"uTime")}}catch{return e.remove(),i&&r.style.position==="relative"&&(r.style.position=o),null}},yP=(t,e)=>{e&&(e.overlay.style.display!=="none"&&(e.overlay.style.display="none"),t.style.visibility!==e.restoreVisibility&&(t.style.visibility=e.restoreVisibility)),t.getAttribute("data-mg-gpu-pass")!=="idle"&&t.setAttribute("data-mg-gpu-pass","idle")},xm=(t,e)=>{let n=Uu.get(t);if(Number(e)<.008){yP(t,n);return}if(rf.has(t)){t.setAttribute("data-mg-gpu-pass","unavailable");return}if(!n){try{n=mP(t)}catch{n=null}if(!n){rf.add(t),t.setAttribute("data-mg-gpu-pass","unavailable");return}Uu.set(t,n)}const{gl:r,overlay:o,program:i,texture:a}=n,s=Math.max(1,t.width),u=Math.max(1,t.height);o.width!==s&&(o.width=s),o.height!==u&&(o.height=u);const c=t.offsetLeft,_=t.offsetTop,l=t.clientWidth,f=t.clientHeight;n.overlayLeft!==c&&(o.style.left=`${c}px`,n.overlayLeft=c),n.overlayTop!==_&&(o.style.top=`${_}px`,n.overlayTop=_),n.overlayWidth!==l&&(o.style.width=`${l}px`,n.overlayWidth=l),n.overlayHeight!==f&&(o.style.height=`${f}px`,n.overlayHeight=f),o.style.display!=="block"&&(o.style.display="block"),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,a),n.sceneTextureWidth!==s||n.sceneTextureHeight!==u?(r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t),n.sceneTextureWidth=s,n.sceneTextureHeight=u):r.texSubImage2D(r.TEXTURE_2D,0,0,0,r.RGBA,r.UNSIGNED_BYTE,t),r.bindFramebuffer(r.FRAMEBUFFER,null),r.viewport(0,0,s,u),r.useProgram(i);const d=Math.max(0,Math.min(1,Number(e)||0));r.uniform1f(n.zoomFilmAmountLocation,Math.sqrt(d)),r.uniform1f(n.zoomTimeLocation,performance.now()/1e3),r.uniform1f(n.zoomStrengthLocation,d),r.drawArrays(r.TRIANGLES,0,3),t.getAttribute("data-mg-gpu-pass")!=="active"&&t.setAttribute("data-mg-gpu-pass","active"),t.style.visibility!=="hidden"&&(t.style.visibility="hidden")},xP=t=>{const e=Uu.get(t);e&&(e.gl.deleteTexture(e.texture),e.gl.deleteProgram(e.program),e.overlay.remove(),t.style.visibility=e.restoreVisibility,e.changedPosition&&e.parent.style.position==="relative"&&(e.parent.style.position=e.restorePosition)),Uu.delete(t),rf.delete(t),t.removeAttribute("data-mg-gpu-pass")},wm=(t,e)=>({tag:t,_1:e}),Tm=t=>t,wP=(t,e,n)=>({tag:t,_1:e,_2:n}),wi=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},TP=_m(jg),NP=Qt.foldMap(D2),Ku=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},of=wP("AutoSize"),vP=Tm("CanvasRenderer"),JP=Tm("SvgRenderer"),CP=t=>e=>{const n=t-e*nt(he(Kn(t/e)));return e<=0?0:n<0?n+e:n},ji=t=>J(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),bP=t=>{const e=lm("data-markgraf-titles")(t);return()=>{const n=e();return n.tag==="Nothing"||!(n.tag==="Just"&&n._1==="false")}},kP=t=>{const e=lm("data-markgraf-theme")(t);return()=>{const n=e();if(n.tag==="Just")return n._1==="light"?R_:n._1==="dark"?pL:n._1==="blueprint"?mL:n._1==="whiteboard"?yL:n._1==="isometric"?xL:R_;if(n.tag==="Nothing")return R_;g()}},LP=`
260
63
  <canvas data-mg="stage" tabindex="0"></canvas>
261
64
  <div data-mg="play-overlay" aria-hidden="true"></div>
262
65
  <div data-mg="bar">
@@ -273,6 +76,6 @@ void main() {
273
76
  <option value="2">2\xD7</option>
274
77
  </select>
275
78
  </div>
276
- `,Bm=t=>e=>{const n=Jn(t,w,Ut);if(n.tag==="Just"){const r=Jn(n._1.stopAt,w,Ut);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;_()}if(n.tag==="Nothing")return e;_()},ZP=t=>e=>ne(n=>n.direction==="DiveIn"&&n.startT>=e&&n.startT-e<=1,t.dives),t6=t=>e=>{const n=o=>r(o),r=o=>({...o,state:{...o.state,animationTime:t},minis:U(n)(o.minis)});return{...e,levels:U(r)(e.levels)}},Mm=t=>e=>({...e,state:{...e.state,camera:t},minis:U(n=>Mm(t)(n))(e.minis)}),e6=t=>e=>n=>{const r=Kn(n.rootLayout)(n.camera),o=pn("data-mg-too-small")("0")(t);return()=>(o(),pn("data-mg-camera-vw")(Eo(r.w))(t)(),pn("data-mg-camera-vh")(Eo(r.h))(t)(),pn("data-mg-camera-zoom")(Eo(n.camera.zoom))(t)(),pn("data-mg-viewport-css-width")(Eo(e.w))(t)(),pn("data-mg-viewport-css-height")(Eo(e.h))(t)())},n6=t=>{const e=GA(t);if(e.tag==="Left")return It("Left",e._1);if(e.tag==="Right")return It("Right",IA(e._1));_()},r6=t=>e=>n=>{if(e.tag==="FixedSize")return()=>({w:e._1,h:e._2});if(e.tag==="AutoSize"){const r=ju(t);return()=>{const o=r(),i=o.width<=0?n.width:o.width;return{w:i,h:o.height<=0?i*n.height/wr(1)(n.width):o.height}}}_()},o6=t=>ne(e=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,yt("Cons",r._4,n(r._6,o)));_()};return ne(r=>{const o=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return o(i._5,yt("Cons",i._4,o(i._6,a)));_()};return ne(i=>ne(a=>a.style==="RunHighlight"||a.style==="RunCodeHighlight",fr(i)),Wt(ue.foldr,o(r.labels,R)))},Wt(ue.foldr,n(e.keyframes,R)))},t.segments),i6=t=>e=>n=>{const r=l5(w5(gP(n))),o=pn("viewBox")(r.viewBox)(t);return()=>(o(),pn("preserveAspectRatio")("xMidYMid meet")(t)(),e.tag==="FixedSize"?(pn("width")(ae(de(Fn(e._1))))(t)(),pn("height")(ae(de(Fn(e._2))))(t)()):e.tag==="AutoSize"||_(),ja(r.body,t))},a6=t=>e=>n=>{const r=Ku(t),o=r6(t)(e)(n);return()=>{const i=o(),a=Nm(),s=i.w*a,u=i.h*a,c=Qf(r)(),g=Wf(r)(),l=Of(r)(s);c!==s&&l();const d=Hf(r)(u);g!==u&&d(),e.tag==="FixedSize"?(Zu(t,"width",ae(de(Fn(i.w)))+"px"),Zu(t,"height",ae(de(Fn(i.h)))+"px")):e.tag==="AutoSize"||_();const f=zf(r)();br(f)(),fs(f)({scaleX:a,scaleY:a})();const h=dh(f)({width:i.w,height:i.h})();return HP(n)(h)(),Jr(f)()}},s6=t=>e=>n=>r=>{if(e==="CanvasRenderer")return a6(t)(n)(r);if(e==="SvgRenderer")return i6(t)(n)(r);_()},u6=t=>e=>n=>r=>()=>{let o=!1,i=()=>{},a=[];const s=()=>{const c=o,g=s6(t)(e)(n)(r);if(!c)return g()},u={time:0,keyframe:"sequence",playing:!1};return s(),i=wm(t)(()=>{s();const c=a;return ta(g=>g(u))(c)()})(),{play:()=>{},playWith:c=>()=>{},pause:()=>{},toggle:()=>{},seek:c=>()=>{},seekCue:c=>()=>{},seekStep:c=>()=>{},playToCue:c=>g=>()=>{},playToStep:c=>g=>()=>{},playNext:c=>()=>{},playPrevious:c=>()=>{},setSpeed:c=>()=>{},currentTime:(()=>{const c=u.time;return()=>c})(),currentKeyframe:(()=>{const c=u.keyframe;return()=>c})(),isPlaying:()=>!1,duration:0,cues:[],steps:[],subscribe:c=>()=>{a=St(a)(c),c(u)();const g=na(l=>!tc(l)(c));return()=>{a=g(a)}},subscribeCue:c=>()=>()=>{},subscribeComplete:c=>()=>()=>{},destroy:()=>(o=!0,i())}},Ir=t=>e=>n=>()=>{const r=xP(t,e),o=Jn(r,w,Ut);if(o.tag==="Just")return n(o._1)();o.tag!=="Nothing"&&_()},c6=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=$P(o=>'<span class="mg-tick" style="left:'+Do(Ro("Fixed",Go(0)(20)(2)))(100*o.startT/n)+'%" data-label="'+(()=>{if(o.scene.tag==="Structural")return o.scene._1.to;if(o.scene.tag==="DataFlow")return o.scene._1.keyframe;if(o.scene.tag==="Hold")return o.scene._1;if(o.scene.tag==="EnterNode"||o.scene.tag==="ExitNode")return"";if(o.scene.tag==="StepScene")return o.scene._1;_()})()+'"></span>')(e.spans);return Ir(t)("ticks")(o=>()=>ja(r,o))},g6=t=>e=>n=>Ir(t)("scrub")(r=>{const o=cf(w,Ut,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return n<=0?()=>{}:hP(ae(de(Fn(e/n*1e3))))(o._1);_()}),_6=t=>e=>{const n=Kt(r=>r.direction==="DiveIn"&&r.startT>=e&&r.startT-e<=.12)(t.dives);if(n.tag==="Just"){const r=n._1,o=Kt(i=>qP(i.path)(r.parentPath)&&i.startT<=e&&r.startT<=i.endT+1e-4)(t.segments);if(o.tag==="Just"){const i=es(r.node)(o._1.layout.nodes);if(i.tag==="Just")return T("Just",{box:{x:i._1.x*o._1.placement.scale+o._1.placement.tx,y:i._1.y*o._1.placement.scale+o._1.placement.ty,w:i._1.w*o._1.placement.scale,h:i._1.h*o._1.placement.scale},faceAlpha:1,label:i._1.label,radius:7*o._1.placement.scale,key:Im(r.childPath)});if(i.tag==="Nothing")return w;_()}if(o.tag==="Nothing")return w;_()}if(n.tag==="Nothing")return w;_()},mf=t=>e=>n=>{const r=lP(o=>n);return()=>{const o=r();return dP(t)(o)(!1)(e)()}},f6=t=>e=>{const n=ym(t);return()=>{const r=n();return mm(r)("markgraf-embed")(),ja(`
79
+ `,Nm=t=>e=>{const n=Ln(t,w,Yt);if(n.tag==="Just"){const r=Ln(n._1.stopAt,w,Yt);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return e;g()},SP=t=>e=>{const n=o=>r(o),r=o=>({...o,state:{...o.state,animationTime:t},minis:Y(n)(o.minis)});return{...e,levels:Y(r)(e.levels)}},vm=t=>e=>({...e,state:{...e.state,camera:t},minis:Y(n=>vm(t)(n))(e.minis)}),EP=t=>e=>n=>{const r=jn(n.rootLayout)(n.camera),o=xn("data-mg-too-small")("0")(t);return()=>(o(),xn("data-mg-camera-vw")(Fo(r.w))(t)(),xn("data-mg-camera-vh")(Fo(r.h))(t)(),xn("data-mg-camera-zoom")(Fo(n.camera.zoom))(t)(),xn("data-mg-viewport-css-width")(Fo(e.w))(t)(),xn("data-mg-viewport-css-height")(Fo(e.h))(t)())},PP=t=>{const e=L6(t);if(e.tag==="Left")return It("Left",e._1);if(e.tag==="Right")return It("Right",P6(e._1));g()},GP=t=>e=>n=>{if(e.tag==="FixedSize")return()=>({w:e._1,h:e._2});if(e.tag==="AutoSize"){const r=Yu(t);return()=>{const o=r(),i=o.width<=0?n.width:o.width;return{w:i,h:o.height<=0?i*n.height/wi(1)(n.width):o.height}}}g()},AP=t=>ne(e=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,pt("Cons",r._4,n(r._6,o)));g()};return ne(r=>{const o=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return o(i._5,pt("Cons",i._4,o(i._6,a)));g()};return ne(i=>ne(a=>a.style==="RunHighlight"||a.style==="RunCodeHighlight",hr(i)),Ot(ue.foldr,o(r.labels,G)))},Ot(ue.foldr,n(e.keyframes,G)))},t.segments),RP=t=>e=>n=>{const r=sL(lL(oP(n))),o=xn("viewBox")(r.viewBox)(t);return()=>(o(),xn("preserveAspectRatio")("xMidYMid meet")(t)(),e.tag==="FixedSize"?(xn("width")(ae(he(Bn(e._1))))(t)(),xn("height")(ae(he(Bn(e._2))))(t)()):e.tag==="AutoSize"||g(),Va(r.body,t))},DP=t=>e=>n=>{const r=$u(t),o=GP(t)(e)(n);return()=>{const i=o(),a=pm(),s=i.w*a,u=i.h*a,c=Lf(r)(),_=Sf(r)(),l=Ef(r)(s);c!==s&&l();const f=Pf(r)(u);_!==u&&f(),e.tag==="FixedSize"?(Vu(t,"width",ae(he(Bn(i.w)))+"px"),Vu(t,"height",ae(he(Bn(i.h)))+"px")):e.tag==="AutoSize"||g();const d=kf(r)();Cr(d)(),os(d)({scaleX:a,scaleY:a})();const h=oh(d)({width:i.w,height:i.h})();return TP(n)(h)(),br(d)()}},FP=t=>e=>n=>r=>{if(e==="CanvasRenderer")return DP(t)(n)(r);if(e==="SvgRenderer")return RP(t)(n)(r);g()},IP=t=>e=>n=>r=>()=>{let o=!1,i=()=>{},a=[];const s=()=>{const c=o,_=FP(t)(e)(n)(r);if(!c)return _()},u={time:0,keyframe:"sequence",playing:!1};return s(),i=hm(t)(()=>{s();const c=a;return ji(_=>_(u))(c)()})(),{play:()=>{},playWith:c=>()=>{},pause:()=>{},toggle:()=>{},seek:c=>()=>{},seekCue:c=>()=>{},seekStep:c=>()=>{},playToCue:c=>_=>()=>{},playToStep:c=>_=>()=>{},playNext:c=>()=>{},playPrevious:c=>()=>{},setSpeed:c=>()=>{},currentTime:(()=>{const c=u.time;return()=>c})(),currentKeyframe:(()=>{const c=u.keyframe;return()=>c})(),isPlaying:()=>!1,duration:0,cues:[],steps:[],subscribe:c=>()=>{a=St(a)(c),c(u)();const _=na(l=>!Xu(l)(c));return()=>{a=_(a)}},subscribeCue:c=>()=>()=>{},subscribeComplete:c=>()=>()=>{},destroy:()=>(o=!0,i())}},Qr=t=>e=>n=>()=>{const r=dP(t,e),o=Ln(r,w,Yt);if(o.tag==="Just")return n(o._1)();o.tag!=="Nothing"&&g()},BP=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=NP(o=>'<span class="mg-tick" style="left:'+Mo(Qo("Fixed",zo(0)(20)(2)))(100*o.startT/n)+'%" data-label="'+(()=>{if(o.scene.tag==="Structural")return o.scene._1.to;if(o.scene.tag==="DataFlow")return o.scene._1.keyframe;if(o.scene.tag==="Hold")return o.scene._1;if(o.scene.tag==="EnterNode"||o.scene.tag==="ExitNode")return"";if(o.scene.tag==="StepScene")return o.scene._1;g()})()+'"></span>')(e.spans);return Qr(t)("ticks")(o=>()=>Va(r,o))},QP=t=>e=>n=>Qr(t)("scrub")(r=>{const o=tf(w,Yt,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return n<=0?()=>{}:cP(ae(he(Bn(e/n*1e3))))(o._1);g()}),af=t=>e=>n=>{const r=sP(o=>n);return()=>{const o=r();return uP(t)(o)(!1)(e)()}},zP=t=>e=>{const n=dm(t);return()=>{const r=n();return fm(r)("markgraf-embed")(),Va(`
277
80
  <svg data-mg="stage" tabindex="0" role="img" aria-label="Markgraf sequence diagram"></svg>
278
- `,t),Ir(t)("stage")(o=>{const i=u6(o)(XP)(pf)(e);return()=>{const a=gf();_f(()=>{i()})(a)()}})()}},l6=t=>e=>{const n=Jn(t,w,Ut);if(n.tag==="Just"){const r=Jn(n._1.loop,w,Ut);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;_()}if(n.tag==="Nothing")return e;_()},yf=t=>e=>{const n=Kt(r=>r.startT<=e&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return n._1.scene._1.to;if(n._1.scene.tag==="DataFlow")return n._1.scene._1.keyframe;if(n._1.scene.tag==="Hold")return n._1.scene._1;if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return"";if(n._1.scene.tag==="StepScene")return n._1.scene._1;_()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;if(r>=0&&r<t.spans.length){if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="Hold")return t.spans[r].scene._1;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return"";if(t.spans[r].scene.tag==="StepScene")return t.spans[r].scene._1;_()}return""}_()},d6=t=>e=>Ir(t)("speed")(n=>{const r=cf(w,Ut,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return mf("change")(n)((()=>{const o=mP(r._1);return()=>{const i=o(),a=Rf(i,ss,Ut,w);if(a.tag==="Just")return e(a._1)();a.tag!=="Nothing"&&_()}})());_()}),h6=t=>e=>n=>Ir(t)("scrub")(r=>{const o=cf(w,Ut,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return mf("input")(r)((()=>{const i=pP(o._1);return()=>{const a=i();return n.pause(),n.seek(a/1e3*e.totalDuration)()}})());_()}),p6=t=>e=>n=>{const r=c6(t)(e);return()=>{r(),Ir(t)("play")(o=>pn("data-mg-playing")("1")(o))(),d6(t)(n.setSpeed)(),Ir(t)("play")(o=>mf("click")(o)(n.toggle))(),h6(t)(e)(n)(),n.subscribe(o=>{const i=g6(t)(o.time)(e.totalDuration);return()=>(i(),Ir(t)("time")(a=>fP(Do(Ro("Fixed",Go(0)(20)(2)))(o.time)+" / "+Do(Ro("Fixed",Go(0)(20)(2)))(e.totalDuration))(a))(),Ir(t)("play")(a=>pn("data-mg-playing")(o.playing?"1":"0")(a))())})()}},xf={active:0,armed:0,depth:0,faceAlpha:1,progress:0,h:0,key:"",label:"",prewarm:0,r:0,seed:0,w:0,x:0,y:0},m6=t=>e=>n=>{const r=Md(n);return()=>{const o=r(),i=zd(n)(),a=AS(Rx)(hS)(n)(Qd(o)(i)(n));if(a.tag==="Left")return It("Left","precompute failed");if(a.tag==="Right")return It("Right",{schedule:a._1});_()}},y6=t=>{let e=t,n=!0,r;for(;n;){const o=At(i=>w,i=>a=>T("Just",{head:i,tail:a}),e);if(o.tag==="Nothing"){n=!1,r=w;continue}if(o.tag==="Just"){const i=0<o._1.tail.length?T("Just",o._1.tail[0]):w;if(i.tag==="Just"&&o._1.head.role==="FlyThrough"){const a=i._1.segment.path.length-1|0,s=a>=0&&a<i._1.segment.path.length?T("Just",i._1.segment.path[a]):w;if(s.tag==="Just"){const u=es(s._1)(o._1.head.segment.layout.nodes);if(u.tag==="Just"){n=!1,r=T("Just",{box:(()=>{const c=o._1.head.segment.placement;return{x:u._1.x*c.scale+c.tx,y:u._1.y*c.scale+c.ty,w:u._1.w*c.scale,h:u._1.h*c.scale}})(),faceAlpha:hi((()=>{const c=es(s._1)(o._1.head.state.nodes);return c.tag==="Just"?wo(c._1).alpha:0})())(hi((()=>{const c=es(s._1)(o._1.head.state.nodeFadeAlpha);if(c.tag==="Nothing")return 1;if(c.tag==="Just")return c._1;_()})())((()=>{const c=es(s._1)(o._1.head.state.nodeLabelFadeAlpha);if(c.tag==="Nothing")return 1;if(c.tag==="Just")return c._1;_()})())),label:u._1.label,key:Im(i._1.segment.path),radius:7*o._1.head.segment.placement.scale});continue}if(u.tag==="Nothing"){n=!1,r=w;continue}_()}if(s.tag==="Nothing"){n=!1,r=w;continue}_()}e=o._1.tail;continue}_()}return r},zm=t=>e=>n=>r=>o=>i=>{const a=wr(1)(n),s=wr(1)(r),u=hi(a/wr(1e-6)(o.vw))(s/wr(1e-6)(o.vh)),c=(s-o.vh*u)/2,g=(a-o.vw*u)/2,l=(f,h,m,p)=>({active:f,armed:1,depth:h,faceAlpha:p.faceAlpha,progress:m,h:p.box.h*u/s,key:p.key,label:p.label,prewarm:1,r:p.radius*u/a,seed:rt(t.seed),w:p.box.w*u/a,x:(g+(p.box.x-o.vx)*u)/a,y:(c+(p.box.y-o.vy)*u)/s}),d=y6(i.levels);if(d.tag==="Just")return l(1,i.diveDepth,i.doorProgress,d._1);if(d.tag==="Nothing"){const f=_6(t)(e);if(f.tag==="Just")return l(0,0,0,f._1);if(f.tag==="Nothing")return{...xf,prewarm:ZP(t)(e)?1:0}}_()},x6=t=>e=>(()=>{const n=Jn(t,w,Ut);if(n.tag==="Just")return{...n._1,direction:e<0?"backward":"forward"};if(n.tag==="Nothing")return{direction:e<0?"backward":"forward",speed:ra,duration:ra,loop:ra,stopAt:ra};_()})(),Qm=t=>e=>{const n=Jn(t,w,Ut);if(n.tag==="Just"){const r=Jn(n._1.direction,w,Ut);if(r.tag==="Just"){if(r._1==="backward"||r._1==="reverse")return-1;if(r._1==="forward")return 1}return e}if(n.tag==="Nothing")return e;_()},w6=t=>e=>{const n=dt(o=>o.time<=e+1e-4,t),r=n.length-1|0;return r>=0&&r<n.length?n[r].index:-1},N6=t=>e=>{if(e.tag==="FixedSize"){const n=e._1<=0||e._2<=0?w:T("Just",e._1/e._2);return()=>n}if(e.tag==="AutoSize"){const n=ju(t);return()=>{const r=n();return r.width<=0||r.height<=0?w:T("Just",r.width/r.height)}}_()},ns=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>g=>l=>d=>()=>{const f=Tm(),h=l.value,m=g.value,p=h===0?0:f-h,x=m+p;l.value=f,g.value=x;const y=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const E=ju(t)();return{w:E.width<=0?200:E.width,h:E.height<=0?180:E.height}}_()})();if(y.w<200||y.h<180){if(yP(t)(y.w)(y.h)(200)(180)(),e==="CanvasRenderer")return Gm(Ku(t),0,0,xf,p);if(e==="SvgRenderer")return Rm(t,0,xf,p);_()}const N=s.value,v=(()=>{if(N.tag==="Just"&&N._1.w===y.w&&N._1.h===y.h)return N._1.schedule;const E=$5({widthPx:y.w,heightPx:y.h})(a);return s.value=T("Just",{w:y.w,h:y.h,schedule:E}),E})(),J=hi(d)(v.totalDuration),k=t6(x)(ON(v)(J)),S=i?k:{...k,levels:U(E=>({...E,state:{...E.state,frameTitle:""}}))(k.levels)},A=c.value,I=(()=>{if(A.tag==="Nothing")return S.camera;if(A.tag==="Just")return Ax(a.cameraConfig.cameraDecay)(p)(A._1)(S.camera);_()})();c.value=T("Just",I);const $={...S,camera:I,levels:U(Mm(I))(S.levels)};if(e6(t)(y)($)(),e==="CanvasRenderer"){const E=Ku(t),G=bu({width:0,height:0})($),nt=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const O=ju(t)();return{w:O.width,h:O.height<=0?G.vw<=0?O.width:O.width*G.vh/G.vw:O.height}}_()})(),V=Nm(),Q=nt.w*V,Y=nt.h*V,X=Qf(E)(),D=Wf(E)(),F=Of(E)(Q);X!==Q&&F();const B=Hf(E)(Y);D!==Y&&B(),n.tag==="FixedSize"?(Zu(t,"width",ae(de(Fn(nt.w)))+"px"),Zu(t,"height",ae(de(Fn(nt.h)))+"px")):n.tag==="AutoSize"||_();const z=zf(E)();br(z)(),fs(z)({scaleX:V,scaleY:V})();const j=u.value,W=o5(r)(o)(z)({width:nt.w,height:nt.h})($)(p)(j)();return u.value=W,Jr(z)(),Gm(E,$.zoomStreak,$.zoomDirection,zm(v)(J)(nt.w)(nt.h)(bu({width:nt.w,height:nt.h})($))($),p)}if(e==="SvgRenderer"){const E=u.value,G=N6(t)(n)(),nt=M5(G)(r)(o)($)(p)(E);return u.value=nt.springs,pn("viewBox")(nt.parts.viewBox)(t)(),pn("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(pn("width")(ae(de(Fn(n._1))))(t)(),pn("height")(ae(de(Fn(n._2))))(t)()):n.tag==="AutoSize"||_(),ja(nt.parts.body,t),Rm(t,$.zoomDirection,zm(v)(J)(y.w)(y.h)(bu({width:y.w,height:y.h})($))($),p)}_()},T6=t=>{const e=G0(t)(C0)._1;if(e.tag==="Left")return It("Left",e._1.msg);if(e.tag==="Right")return It("Right",e._1);_()},Wm=t=>{const e=pA(t);if(e.tag==="Left")return It("Left",e._1);if(e.tag==="Right"){if(e._1.mode==="SequenceSurface"){const r=n6(e._1);if(r.tag==="Left")return It("Left",r._1);if(r.tag==="Right")return It("Right",Dm("LoadedSequence",r._1));_()}const n=T6(e._1);if(n.tag==="Left")return It("Left",n._1);if(n.tag==="Right")return It("Right",Dm("LoadedAnimation",n._1))}_()},v6=t=>{const e=Wm(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return ra;_()},Om=t=>e=>n=>r=>{const o=n+1e-4>=e?dt(a=>a.time>e+1e-4&&a.time<=n+1e-4,t):[...dt(a=>a.time>e+1e-4,t),...dt(a=>a.time<=n+1e-4,t)],i=n<=e+1e-4?re(dt(a=>a.time<e-1e-4&&a.time>=n-1e-4,t)):[...re(dt(a=>a.time<e-1e-4,t)),...re(dt(a=>a.time>=n-1e-4,t))];return(()=>{const a=n-e;return a<0?-a<=1e-4:a<=1e-4})()?[]:r>=0?o:i},b6=t=>e=>n=>r=>Kt(o=>ne(i=>i===o.kind,e)&&(o.time>n+1e-4||(()=>{const i=o.time-n;return(i<0?-i<=1e-4:i<=1e-4)&&o.index>r})()))(t),J6=t=>e=>n=>r=>{const o=dt(a=>ne(s=>s===a.kind,e)&&(a.time<n-1e-4||(()=>{const s=a.time-n;return(s<0?-s<=1e-4:s<=1e-4)&&a.index<r})()),t),i=o.length-1|0;return i>=0&&i<o.length?T("Just",o[i]):w},wf=t=>e=>n=>{const r=Jn(e,w,Ut);if(r.tag==="Just"){const o=Jn(r._1.speed,w,Ut);if(o.tag==="Just"){const i=wr(1e-4)(o._1<0?-o._1:o._1);return()=>t.value=i}if(o.tag==="Nothing"){const i=Jn(r._1.duration,w,Ut);if(i.tag==="Just"&&n.tag==="Just"){const a=n._1/i._1,s=wr(1e-4)(a<0?-a:a);if(i._1>0)return()=>t.value=s}return()=>{}}_()}if(r.tag==="Nothing")return()=>{};_()},C6=t=>e=>n=>r=>{const o=r.time-e,i=o<0?-o<=1e-4:o<=1e-4,a=r.time<e-1e-4||i&&r.index<n,s=a?-1:1,u=r.time>e+1e-4||i&&r.index>n,c=Jn(t,w,Ut);if(c.tag==="Just"){const g=Jn(c._1.direction,w,Ut);if(g.tag==="Just"){if(g._1==="forward")return i||u?T("Just",1):w;if(g._1==="backward"||g._1==="reverse")return i||a?T("Just",-1):w}return T("Just",s)}if(c.tag==="Nothing")return T("Just",s);_()},k6=t=>e=>n=>r=>o=>i=>a=>()=>{const s={value:1};let u=1,c=!0,g=w,l=-1,d=!0,f=!1,h=0,m=0;const p={value:M},x={value:w},y={value:0},N={value:0},v={value:w};let J=!1,k=()=>{},S=[],A=[],I=[];ns(t)(n)(r)(o)(i)(a)(e)(v)(p)(x)(y)(N)(0)();const $=W=>{const O=W.index;return()=>{l=O;const q=A;return ta(H=>H(W))(q)()}},E=W=>()=>{const O=S,q=d,H={time:W,keyframe:yf(e)(W),playing:q};return ta(ot=>ot(H))(O)()},G=()=>(d=!1,g=w,E(h)()),nt=W=>()=>(h=W,ns(t)(n)(r)(o)(i)(a)(e)(v)(p)(x)(y)(N)(W)(),E(W)()),V=W=>{const O=wr(0)(hi(e.totalDuration)(W));return()=>(h=O,l=w6(e.cues)(O),m=0,g=w,x.value=w,ns(t)(n)(r)(o)(i)(a)(e)(v)(p)(x)(y)(N)(O)(),E(O)())},Q=(W,O,q,H,ot)=>()=>{d=!1,g=w;const et=h;E(et)();const gt={reason:W,direction:O<0?"backward":"forward",targetId:q,targetStep:H,reached:ot,time:et},Lt=I;return ta(ft=>ft(gt))(Lt)()},Y=o6(e),X=()=>{if(!J){if(f=!1,d){const W=Tm(),O=m;m=W;const q=s.value,H=u,ot=c,et=g,gt=h,Lt=O===0?gt+0*q*H:gt+(W-O)*q*H;if(et.tag==="Just"){const ft=H>=0?et._1.cue.time>=gt-1e-4&&et._1.cue.time<=Lt+1e-4:et._1.cue.time<=gt+1e-4&&et._1.cue.time>=Lt-1e-4,Nt=ft?et._1.cue.time:wr(0)(hi(e.totalDuration)(Lt));(H>=0?Nt+1e-4<gt:Nt>gt+1e-4)&&(x.value=w),nt(Nt)(),ta(jt=>$(jt))(Om(e.cues)(gt)(Nt)(H))();const kt=Q("target",H,et._1.targetId,et._1.targetStep,!0);ft&&kt(),ft||D()}else if(et.tag==="Nothing"){const ft=H>=0?e.totalDuration:0,Nt=!ot&&(H>=0?ft>=gt-1e-4&&ft<=Lt+1e-4:ft<=gt+1e-4&&ft>=Lt-1e-4),kt=ot?VP(Lt)(e.totalDuration+.8):wr(0)(hi(e.totalDuration)(Lt));(H>=0?kt+1e-4<gt:kt>gt+1e-4)&&(x.value=w),nt(kt)(),ta(Tt=>$(Tt))(Om(e.cues)(gt)(kt)(H))();const jt=Q("boundary",H,"","",!0);Nt&&jt(),Nt||D()}else _()}if(Y&&!d){const W=h;return ns(t)(n)(r)(o)(i)(a)(e)(v)(p)(x)(y)(N)(W)(),D()}}},D=()=>{if(!J&&!f){f=!0;const W=gf();_f(X)(W)()}},F=()=>(m=0,d=!0,D()),B=()=>(u=1,c=!0,g=w,F(),E(h)()),z=(W,O)=>()=>{const q=h;return u=W,c=!1,g=w,wf(s)(O)(T("Just",W>=0?e.totalDuration-q:q))(),F()},j=(W,O)=>()=>{const q=h,H=l,ot=C6(O)(q)(H)(W);if(ot.tag==="Nothing")return z(Qm(O)(1),O)();if(ot.tag==="Just"){const et=W.time-q,gt=et<0?-et:et;return u=ot._1,c=!1,g=T("Just",{cue:W,direction:ot._1,targetId:W.id,targetStep:W.name}),wf(s)(O)(T("Just",gt))(),gt<=1e-4?(V(W.time)(),$(W)(),Q("target",ot._1,W.id,W.name,!0)()):F()}_()};return k=wm(t)(()=>{if(!J){const W=h;return ns(t)(n)(r)(o)(i)(a)(e)(v)(p)(x)(y)(N)(W)(),E(W)()}})(),F(),{play:B,playWith:W=>{const O=Qm(W)(1);return()=>(u=O,c=l6(W)(!1),g=w,wf(s)(W)(w)(),F(),E(h)())},pause:G,toggle:()=>d?G():B(),seek:W=>V(W),seekCue:W=>{const O=Kt(q=>q.id===W)(e.cues);if(O.tag==="Nothing")return()=>{};if(O.tag==="Just"){const q=O._1,H=V(q.time);return()=>(H(),$(q)())}_()},seekStep:W=>{const O=Kt(q=>q.kind==="step"&&q.name===W)(e.cues);if(O.tag==="Nothing")return()=>{};if(O.tag==="Just"){const q=O._1,H=V(q.time);return()=>(H(),$(q)())}_()},playToCue:W=>O=>{const q=Kt(H=>H.id===W)(e.cues);if(q.tag==="Nothing")return()=>{};if(q.tag==="Just")return j(q._1,O);_()},playToStep:W=>O=>{const q=Kt(H=>H.kind==="step"&&H.name===W)(e.cues);if(q.tag==="Nothing")return()=>{};if(q.tag==="Just")return j(q._1,O);_()},playNext:W=>()=>{const O=h,q=l,H=b6(e.cues)(Bm(W)(["step"]))(O)(q);if(H.tag==="Nothing")return z(1,W)();if(H.tag==="Just")return j(H._1,W)();_()},playPrevious:W=>()=>{const O=h,q=l,H=J6(e.cues)(Bm(W)(["step"]))(O)(q);if(H.tag==="Nothing")return z(-1,W)();if(H.tag==="Just")return j(H._1,x6(W)(-1))();_()},setSpeed:W=>{const O=wr(1e-4)(W<0?-W:W);return()=>s.value=O},currentTime:()=>h,currentKeyframe:()=>{const W=h;return yf(e)(W)},isPlaying:()=>d,duration:e.totalDuration,cues:e.cues,steps:dt(W=>W.kind==="step",e.cues),subscribe:W=>()=>{S=St(S)(W);const O=h,q=d;W({time:O,keyframe:yf(e)(O),playing:q})();const H=na(ot=>!tc(ot)(W));return()=>{S=H(S)}},subscribeCue:W=>()=>{A=St(A)(W);const O=na(q=>!tc(q)(W));return()=>{A=O(A)}},subscribeComplete:W=>()=>{I=St(I)(W);const O=na(q=>!tc(q)(W));return()=>{I=O(I)}},destroy:()=>{if(J=!0,k(),n==="CanvasRenderer")return WP(Ku(t));if(n==="SvgRenderer")return zP(t);_()}}},L6=t=>e=>{const n=ym(t);return()=>{const r=n();mm(r)("markgraf-embed")();const o=YP(t)(),i=KP(t)();return ja(jP,t),Ir(t)("stage")(a=>{const s=m6()(pf)(e);return()=>{const u=gf();_f(()=>{const c=s();if(c.tag==="Left")return Mf("[markgraf] precompute failed")();if(c.tag==="Right"){const g=k6(a)(c._1.schedule)(UP)(pf)(i)(C5)(o)();return p6(t)(c._1.schedule)(g)()}_()})(u)()}})()}},Hm=t=>e=>{const n=Wm(e);if(n.tag==="Left")return Mf("[markgraf] parse failed: "+n._1);if(n.tag==="Right"){if(n._1.tag==="LoadedAnimation")return L6(t)(n._1._1);if(n._1.tag==="LoadedSequence")return f6(t)(n._1._1)}_()},S6=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 Br=null;const ac=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",E6=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{ac(t)?(Br&&Br!==t&&ac(Br)&&Br.querySelector('[data-mg="play"]').click(),Br=t):Br===t&&(Br=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},A6=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=S6(t),n=t.dataset.markgrafPaused==="true";t.textContent="",Hm(t)(e)(),t.querySelector('[data-mg="play"]')&&(n?ac(t)&&t.querySelector('[data-mg="play"]').click():Br===null?Br=t:ac(t)&&t.querySelector('[data-mg="play"]').click(),E6(t))},sc=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(A6)},$m=()=>{document.addEventListener("keydown",t=>{if(t.code!=="Space"&&t.key!==" ")return;const e=t.target,n=e&&e.closest?.("[data-markgraf]");if(!n){const o=e?.tagName,i=(e?.type||"").toLowerCase();if(e?.isContentEditable||o==="TEXTAREA"||o==="SELECT"||o==="INPUT"&&!["range","checkbox","radio","button","submit","reset"].includes(i))return}const r=n||Br||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=v6(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>Hm(e)(n)(),mountAll:sc,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{sc(),$m()}):(sc(),$m())}return uc.mountAll=sc,Object.defineProperty(uc,Symbol.toStringTag,{value:"Module"}),uc})({});
81
+ `,t),Qr(t)("stage")(o=>{const i=IP(o)(JP)(of)(e);return()=>{const a=ef();nf(()=>{i()})(a)()}})()}},MP=t=>e=>{const n=Ln(t,w,Yt);if(n.tag==="Just"){const r=Ln(n._1.loop,w,Yt);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return e;g()},sf=t=>e=>{const n=te(r=>r.startT<=e&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return n._1.scene._1.to;if(n._1.scene.tag==="DataFlow")return n._1.scene._1.keyframe;if(n._1.scene.tag==="Hold")return n._1.scene._1;if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return"";if(n._1.scene.tag==="StepScene")return n._1.scene._1;g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;if(r>=0&&r<t.spans.length){if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="Hold")return t.spans[r].scene._1;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return"";if(t.spans[r].scene.tag==="StepScene")return t.spans[r].scene._1;g()}return""}g()},OP=t=>e=>Qr(t)("speed")(n=>{const r=tf(w,Yt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return af("change")(n)((()=>{const o=_P(r._1);return()=>{const i=o(),a=wf(i,ja,Yt,w);if(a.tag==="Just")return e(a._1)();a.tag!=="Nothing"&&g()}})());g()}),WP=t=>e=>n=>Qr(t)("scrub")(r=>{const o=tf(w,Yt,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return af("input")(r)((()=>{const i=gP(o._1);return()=>{const a=i();return n.pause(),n.seek(a/1e3*e.totalDuration)()}})());g()}),qP=t=>e=>n=>{const r=BP(t)(e);return()=>{r(),Qr(t)("play")(o=>xn("data-mg-playing")("1")(o))(),OP(t)(n.setSpeed)(),Qr(t)("play")(o=>af("click")(o)(n.toggle))(),WP(t)(e)(n)(),n.subscribe(o=>{const i=QP(t)(o.time)(e.totalDuration);return()=>(i(),Qr(t)("time")(a=>aP(Mo(Qo("Fixed",zo(0)(20)(2)))(o.time)+" / "+Mo(Qo("Fixed",zo(0)(20)(2)))(e.totalDuration))(a))(),Qr(t)("play")(a=>xn("data-mg-playing")(o.playing?"1":"0")(a))())})()}},HP=t=>e=>n=>{const r=Sl(n);return()=>{const o=r(),i=El(n)(),a=CS(px)(cS)(n)(Pl(o)(i)(n));if(a.tag==="Left")return It("Left","precompute failed");if(a.tag==="Right")return It("Right",{schedule:a._1});g()}},$P=t=>e=>(()=>{const n=Ln(t,w,Yt);if(n.tag==="Just")return{...n._1,direction:e<0?"backward":"forward"};if(n.tag==="Nothing")return{direction:e<0?"backward":"forward",speed:ra,duration:ra,loop:ra,stopAt:ra};g()})(),Jm=t=>e=>{const n=Ln(t,w,Yt);if(n.tag==="Just"){const r=Ln(n._1.direction,w,Yt);if(r.tag==="Just"){if(r._1==="backward"||r._1==="reverse")return-1;if(r._1==="forward")return 1}return e}if(n.tag==="Nothing")return e;g()},YP=t=>e=>{const n=lt(o=>o.time<=e+1e-4,t),r=n.length-1|0;return r>=0&&r<n.length?n[r].index:-1},VP=t=>e=>{if(e.tag==="FixedSize"){const n=e._1<=0||e._2<=0?w:N("Just",e._1/e._2);return()=>n}if(e.tag==="AutoSize"){const n=Yu(t);return()=>{const r=n();return r.width<=0||r.height<=0?w:N("Just",r.width/r.height)}}g()},Xa=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>_=>l=>f=>()=>{const d=mm(),h=l.value,m=_.value,p=h===0?0:d-h,x=m+p;l.value=d,_.value=x;const y=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const W=Yu(t)();return{w:W.width<=0?200:W.width,h:W.height<=0?180:W.height}}g()})();if(y.w<200||y.h<180){if(fP(t)(y.w)(y.h)(200)(180)(),e==="CanvasRenderer")return xm($u(t),0);if(e==="SvgRenderer")return;g()}const T=s.value,v=(()=>{if(T.tag==="Just"&&T._1.w===y.w&&T._1.h===y.h)return T._1.schedule;const W=QL({widthPx:y.w,heightPx:y.h})(a);return s.value=N("Just",{w:y.w,h:y.h,schedule:W}),W})(),b=SP(x)(kT(v)(Ku(f)(v.totalDuration))),C=i?b:{...b,levels:Y(W=>({...W,state:{...W.state,frameTitle:""}}))(b.levels)},S=c.value,P=(()=>{if(S.tag==="Nothing")return C.camera;if(S.tag==="Just")return lx(a.cameraConfig.cameraDecay)(p)(S._1)(C.camera);g()})();c.value=N("Just",P);const F={...C,camera:P,levels:Y(vm(P))(C.levels)};if(EP(t)(y)(F)(),e==="CanvasRenderer"){const W=$u(t),E=Sp({width:0,height:0})(F),R=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const z=Yu(t)();return{w:z.width,h:z.height<=0?E.vw<=0?z.width:z.width*E.vh/E.vw:z.height}}g()})(),et=pm(),rt=R.w*et,$=R.h*et,X=Lf(W)(),V=Sf(W)(),D=Ef(W)(rt);X!==rt&&D();const B=Pf(W)($);V!==$&&B(),n.tag==="FixedSize"?(Vu(t,"width",ae(he(Bn(R.w)))+"px"),Vu(t,"height",ae(he(Bn(R.h)))+"px")):n.tag==="AutoSize"||g();const I=kf(W)();Cr(I)(),os(I)({scaleX:et,scaleY:et})();const M=u.value,j=Z5(r)(o)(I)({width:R.w,height:R.h})(F)(p)(M)();return u.value=j,br(I)(),xm(W,lT(F.portalState))}if(e==="SvgRenderer"){const W=u.value,E=VP(t)(n)(),R=AL(E)(r)(o)(F)(p)(W);return u.value=R.springs,xn("viewBox")(R.parts.viewBox)(t)(),xn("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(xn("width")(ae(he(Bn(n._1))))(t)(),xn("height")(ae(he(Bn(n._2))))(t)()):n.tag==="AutoSize"||g(),Va(R.parts.body,t)}g()},XP=t=>{const e=S0(t)(T0)._1;if(e.tag==="Left")return It("Left",e._1.msg);if(e.tag==="Right")return It("Right",e._1);g()},Cm=t=>{const e=g6(t);if(e.tag==="Left")return It("Left",e._1);if(e.tag==="Right"){if(e._1.mode==="SequenceSurface"){const r=PP(e._1);if(r.tag==="Left")return It("Left",r._1);if(r.tag==="Right")return It("Right",wm("LoadedSequence",r._1));g()}const n=XP(e._1);if(n.tag==="Left")return It("Left",n._1);if(n.tag==="Right")return It("Right",wm("LoadedAnimation",n._1))}g()},UP=t=>{const e=Cm(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return ra;g()},bm=t=>e=>n=>r=>{const o=n+1e-4>=e?lt(a=>a.time>e+1e-4&&a.time<=n+1e-4,t):[...lt(a=>a.time>e+1e-4,t),...lt(a=>a.time<=n+1e-4,t)],i=n<=e+1e-4?re(lt(a=>a.time<e-1e-4&&a.time>=n-1e-4,t)):[...re(lt(a=>a.time<e-1e-4,t)),...re(lt(a=>a.time>=n-1e-4,t))];return(()=>{const a=n-e;return a<0?-a<=1e-4:a<=1e-4})()?[]:r>=0?o:i},KP=t=>e=>n=>r=>te(o=>ne(i=>i===o.kind,e)&&(o.time>n+1e-4||(()=>{const i=o.time-n;return(i<0?-i<=1e-4:i<=1e-4)&&o.index>r})()))(t),ZP=t=>e=>n=>r=>{const o=lt(a=>ne(s=>s===a.kind,e)&&(a.time<n-1e-4||(()=>{const s=a.time-n;return(s<0?-s<=1e-4:s<=1e-4)&&a.index<r})()),t),i=o.length-1|0;return i>=0&&i<o.length?N("Just",o[i]):w},uf=t=>e=>n=>{const r=Ln(e,w,Yt);if(r.tag==="Just"){const o=Ln(r._1.speed,w,Yt);if(o.tag==="Just"){const i=wi(1e-4)(o._1<0?-o._1:o._1);return()=>t.value=i}if(o.tag==="Nothing"){const i=Ln(r._1.duration,w,Yt);if(i.tag==="Just"&&n.tag==="Just"){const a=n._1/i._1,s=wi(1e-4)(a<0?-a:a);if(i._1>0)return()=>t.value=s}return()=>{}}g()}if(r.tag==="Nothing")return()=>{};g()},jP=t=>e=>n=>r=>{const o=r.time-e,i=o<0?-o<=1e-4:o<=1e-4,a=r.time<e-1e-4||i&&r.index<n,s=a?-1:1,u=r.time>e+1e-4||i&&r.index>n,c=Ln(t,w,Yt);if(c.tag==="Just"){const _=Ln(c._1.direction,w,Yt);if(_.tag==="Just"){if(_._1==="forward")return i||u?N("Just",1):w;if(_._1==="backward"||_._1==="reverse")return i||a?N("Just",-1):w}return N("Just",s)}if(c.tag==="Nothing")return N("Just",s);g()},tG=t=>e=>n=>r=>o=>i=>a=>()=>{const s={value:1};let u=1,c=!0,_=w,l=-1,f=!0,d=!1,h=0,m=0;const p={value:Q},x={value:w},y={value:0},T={value:0},v={value:w};let b=!1,C=()=>{},S=[],P=[],F=[];Xa(t)(n)(r)(o)(i)(a)(e)(v)(p)(x)(y)(T)(0)();const W=z=>{const q=z.index;return()=>{l=q;const H=P;return ji(O=>O(z))(H)()}},E=z=>()=>{const q=S,H=f,O={time:z,keyframe:sf(e)(z),playing:H};return ji(ot=>ot(O))(q)()},R=()=>(f=!1,_=w,E(h)()),et=z=>()=>(h=z,Xa(t)(n)(r)(o)(i)(a)(e)(v)(p)(x)(y)(T)(z)(),E(z)()),rt=z=>{const q=wi(0)(Ku(e.totalDuration)(z));return()=>(h=q,l=YP(e.cues)(q),m=0,_=w,x.value=w,Xa(t)(n)(r)(o)(i)(a)(e)(v)(p)(x)(y)(T)(q)(),E(q)())},$=(z,q,H,O,ot)=>()=>{f=!1,_=w;const tt=h;E(tt)();const gt={reason:z,direction:q<0?"backward":"forward",targetId:H,targetStep:O,reached:ot,time:tt},Lt=F;return ji(ft=>ft(gt))(Lt)()},X=AP(e),V=()=>{if(!b){if(d=!1,f){const z=mm(),q=m;m=z;const H=s.value,O=u,ot=c,tt=_,gt=h,Lt=q===0?gt+0*H*O:gt+(z-q)*H*O;if(tt.tag==="Just"){const ft=O>=0?tt._1.cue.time>=gt-1e-4&&tt._1.cue.time<=Lt+1e-4:tt._1.cue.time<=gt+1e-4&&tt._1.cue.time>=Lt-1e-4,Tt=ft?tt._1.cue.time:wi(0)(Ku(e.totalDuration)(Lt));(O>=0?Tt+1e-4<gt:Tt>gt+1e-4)&&(x.value=w),et(Tt)(),ji(Kt=>W(Kt))(bm(e.cues)(gt)(Tt)(O))();const kt=$("target",O,tt._1.targetId,tt._1.targetStep,!0);ft&&kt(),ft||D()}else if(tt.tag==="Nothing"){const ft=O>=0?e.totalDuration:0,Tt=!ot&&(O>=0?ft>=gt-1e-4&&ft<=Lt+1e-4:ft<=gt+1e-4&&ft>=Lt-1e-4),kt=ot?CP(Lt)(e.totalDuration+.8):wi(0)(Ku(e.totalDuration)(Lt));(O>=0?kt+1e-4<gt:kt>gt+1e-4)&&(x.value=w),et(kt)(),ji(Nt=>W(Nt))(bm(e.cues)(gt)(kt)(O))();const Kt=$("boundary",O,"","",!0);Tt&&Kt(),Tt||D()}else g()}if(X&&!f){const z=h;return Xa(t)(n)(r)(o)(i)(a)(e)(v)(p)(x)(y)(T)(z)(),D()}}},D=()=>{if(!b&&!d){d=!0;const z=ef();nf(V)(z)()}},B=()=>(m=0,f=!0,D()),I=()=>(u=1,c=!0,_=w,B(),E(h)()),M=(z,q)=>()=>{const H=h;return u=z,c=!1,_=w,uf(s)(q)(N("Just",z>=0?e.totalDuration-H:H))(),B()},j=(z,q)=>()=>{const H=h,O=l,ot=jP(q)(H)(O)(z);if(ot.tag==="Nothing")return M(Jm(q)(1),q)();if(ot.tag==="Just"){const tt=z.time-H,gt=tt<0?-tt:tt;return u=ot._1,c=!1,_=N("Just",{cue:z,direction:ot._1,targetId:z.id,targetStep:z.name}),uf(s)(q)(N("Just",gt))(),gt<=1e-4?(rt(z.time)(),W(z)(),$("target",ot._1,z.id,z.name,!0)()):B()}g()};return C=hm(t)(()=>{if(!b){const z=h;return Xa(t)(n)(r)(o)(i)(a)(e)(v)(p)(x)(y)(T)(z)(),E(z)()}})(),B(),{play:I,playWith:z=>{const q=Jm(z)(1);return()=>(u=q,c=MP(z)(!1),_=w,uf(s)(z)(w)(),B(),E(h)())},pause:R,toggle:()=>f?R():I(),seek:z=>rt(z),seekCue:z=>{const q=te(H=>H.id===z)(e.cues);if(q.tag==="Nothing")return()=>{};if(q.tag==="Just"){const H=q._1,O=rt(H.time);return()=>(O(),W(H)())}g()},seekStep:z=>{const q=te(H=>H.kind==="step"&&H.name===z)(e.cues);if(q.tag==="Nothing")return()=>{};if(q.tag==="Just"){const H=q._1,O=rt(H.time);return()=>(O(),W(H)())}g()},playToCue:z=>q=>{const H=te(O=>O.id===z)(e.cues);if(H.tag==="Nothing")return()=>{};if(H.tag==="Just")return j(H._1,q);g()},playToStep:z=>q=>{const H=te(O=>O.kind==="step"&&O.name===z)(e.cues);if(H.tag==="Nothing")return()=>{};if(H.tag==="Just")return j(H._1,q);g()},playNext:z=>()=>{const q=h,H=l,O=KP(e.cues)(Nm(z)(["step"]))(q)(H);if(O.tag==="Nothing")return M(1,z)();if(O.tag==="Just")return j(O._1,z)();g()},playPrevious:z=>()=>{const q=h,H=l,O=ZP(e.cues)(Nm(z)(["step"]))(q)(H);if(O.tag==="Nothing")return M(-1,z)();if(O.tag==="Just")return j(O._1,$P(z)(-1))();g()},setSpeed:z=>{const q=wi(1e-4)(z<0?-z:z);return()=>s.value=q},currentTime:()=>h,currentKeyframe:()=>{const z=h;return sf(e)(z)},isPlaying:()=>f,duration:e.totalDuration,cues:e.cues,steps:lt(z=>z.kind==="step",e.cues),subscribe:z=>()=>{S=St(S)(z);const q=h,H=f;z({time:q,keyframe:sf(e)(q),playing:H})();const O=na(ot=>!Xu(ot)(z));return()=>{S=O(S)}},subscribeCue:z=>()=>{P=St(P)(z);const q=na(H=>!Xu(H)(z));return()=>{P=q(P)}},subscribeComplete:z=>()=>{F=St(F)(z);const q=na(H=>!Xu(H)(z));return()=>{F=q(F)}},destroy:()=>{if(b=!0,C(),n==="CanvasRenderer")return xP($u(t));n!=="SvgRenderer"&&g()}}},eG=t=>e=>{const n=dm(t);return()=>{const r=n();fm(r)("markgraf-embed")();const o=bP(t)(),i=kP(t)();return Va(LP,t),Qr(t)("stage")(a=>{const s=HP()(of)(e);return()=>{const u=ef();nf(()=>{const c=s();if(c.tag==="Left")return bf("[markgraf] precompute failed")();if(c.tag==="Right"){const _=tG(a)(c._1.schedule)(vP)(of)(i)(wL)(o)();return qP(t)(c._1.schedule)(_)()}g()})(u)()}})()}},km=t=>e=>{const n=Cm(e);if(n.tag==="Left")return bf("[markgraf] parse failed: "+n._1);if(n.tag==="Right"){if(n._1.tag==="LoadedAnimation")return eG(t)(n._1._1);if(n._1.tag==="LoadedSequence")return zP(t)(n._1._1)}g()},nG=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 zr=null;const Zu=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",rG=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{Zu(t)?(zr&&zr!==t&&Zu(zr)&&zr.querySelector('[data-mg="play"]').click(),zr=t):zr===t&&(zr=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},oG=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=nG(t),n=t.dataset.markgrafPaused==="true";t.textContent="",km(t)(e)(),t.querySelector('[data-mg="play"]')&&(n?Zu(t)&&t.querySelector('[data-mg="play"]').click():zr===null?zr=t:Zu(t)&&t.querySelector('[data-mg="play"]').click(),rG(t))},ju=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(oG)},Lm=()=>{document.addEventListener("keydown",t=>{if(t.code!=="Space"&&t.key!==" ")return;const e=t.target,n=e&&e.closest?.("[data-markgraf]");if(!n){const o=e?.tagName,i=(e?.type||"").toLowerCase();if(e?.isContentEditable||o==="TEXTAREA"||o==="SELECT"||o==="INPUT"&&!["range","checkbox","radio","button","submit","reset"].includes(i))return}const r=n||zr||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=UP(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>km(e)(n)(),mountAll:ju,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{ju(),Lm()}):(ju(),Lm())}return tc.mountAll=ju,Object.defineProperty(tc,Symbol.toStringTag,{value:"Module"}),tc})({});