@markgrafhq/markgraf-embed 0.1.19 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/markgraf-embed.js +28 -27
- package/package.json +1 -1
package/dist/markgraf-embed.js
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
var
|
|
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})+'"'},_u=t=>t,De=_u("LT"),Ie=_u("GT"),Ye=_u("EQ"),N=(t,e)=>({tag:t,_1:e}),w=N("Nothing"),Yt=t=>N("Just",t),s_=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;g()},a_=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;g()},Wt=(t,e)=>({tag:t,_1:e}),Xp=t=>Wt("Right",t),Yp={map:t=>e=>{if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right")return Wt("Right",t(e._1));g()}},u_={apply:t=>e=>{if(t.tag==="Left")return Wt("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right")return Wt("Right",t._1(e._1))}g()},Functor0:()=>Yp},Up={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Wt("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}g()},Apply0:()=>u_},Kp={pure:Xp,Apply0:()=>u_},c_={Applicative0:()=>Kp,Bind1:()=>Up},jp=t=>t,Zp={map:t=>e=>t(e)},g_={apply:t=>e=>t(e),Functor0:()=>Zp},t0={bind:t=>e=>e(t),Apply0:()=>g_},e0={pure:jp,Apply0:()=>g_},Tn={Applicative0:()=>e0,Bind1:()=>t0},n0=function(t){return function(){return t}},r0={apply:t=>e=>()=>{const n=t(),r=e();return fu.pure(n(r))()},Functor0:()=>o0},fu={pure:n0,Apply0:()=>r0},o0={map:t=>e=>()=>{const n=e();return t(n)}},Do=(t,e)=>({tag:t,_1:e}),du=t=>Do("Loop",t),i0=t=>Do("Done",t),s0={tailRecM:t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const s=r;if(s.tag==="Loop"){r=t(s._1);continue}if(s.tag==="Done"){o=!1,i=s._1;continue}g()}return i};return n=>e(t(n))},Monad0:()=>Tn},a0=function(t){return function(e){return function(){return t(e())}}},u0=function(t){return function(){return t}},c0=function(t){return function(e){return function(){return e(t())()}}},g0={map:a0},_0={Applicative0:()=>lu,Bind1:()=>f0},f0={bind:c0,Apply0:()=>__},__={apply:t=>e=>()=>{const n=t(),r=e();return lu.pure(n(r))()},Functor0:()=>g0},lu={pure:u0,Apply0:()=>__},d0={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:()=>_0},l0=function(t){return function(e){return function(n){return function(){return t(e,n)}}}},h0=function(t,e,n,r){return n>=0&&n<r.length?t(r[n]):e},hu=function(t){return t.length},p0=function(t,e,n){return n.length>0?t(n.pop()):e},m0=l0(function(t,e){return e.push(t)}),y0=(t,e)=>({tag:"Iterator",_1:t,_2:e}),x0=t=>e=>n=>()=>{let r=!1;const o=e._2;for(;!r;){const i=o.value,s=e._1(i);if(s.tag==="Just"&&t(s._1)){n.push(s._1),e._2.value;const a=e._2.value;e._2.value=a+1|0;continue}r=!0}},w0=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const o=r.value,i=r.value;r.value=i+1|0;const s=t._1(o);if(s.tag==="Just"){e(s._1)();continue}if(s.tag==="Nothing"){n=!0;continue}g()}},Io=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}}},v=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}}},Ar=t=>{const e=t.Apply0();return n=>r=>n.foldr(o=>{const i=r(o);return s=>e.apply(e.Functor0().map(a=>i_)(i))(s)})(t.pure())},Ao=t=>{const e=Ar(t);return n=>{const r=e(n);return o=>i=>r(i)(o)}},f_={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()}}},Mt={foldr:Io,foldl:v,foldMap:t=>{const e=t.mempty;return n=>Mt.foldr(r=>o=>t.Semigroup0().append(n(r))(o))(e)}},C=(t,e)=>({tag:"Tuple",_1:t,_2:e}),Gn=t=>e=>C(t,e),ps=t=>t._2,ms=t=>t._1,Ht=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 pu=function(t){return function(e){return t===e}};const J0=pu,N0=pu,Ti=pu,mu=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}}},Zn={eq:Ti},v0={eq:N0},Rr={eq:J0};var yu=function(t){return function(e){return function(n){return function(r){return function(o){return r<o?t:r===o?e:n}}}}};const T0=yu,b0=yu,P={compare:yu(De)(Ye)(Ie),Eq0:()=>Zn},it={compare:b0(De)(Ye)(Ie),Eq0:()=>v0},ot={compare:T0(De)(Ye)(Ie),Eq0:()=>Rr},bi=function(t){return t},C0=(function(){function t(o){return[o]}function e(o){return function(i){return[o,i]}}function n(o){return function(i){return function(s){return[o,i,s]}}}function r(o){return function(i){return o.concat(i)}}return function(o){return function(i){return function(s){return function(a){return function(u){function c(_,d){switch(d-_){case 0:return s([]);case 1:return i(t)(a(u[_]));case 2:return o(i(e)(a(u[_])))(a(u[_+1]));case 3:return o(o(i(n)(a(u[_])))(a(u[_+1])))(a(u[_+2]));default:var l=_+Math.floor((d-_)/4)*2;return o(i(r)(c(_,l)))(c(l,d))}}return c(0,u.length)}}}}}})(),k0=t=>t,no={traverse:t=>{const e=t.Apply0();return C0(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>no.traverse(t)(k0),Functor0:()=>Op,Foldable1:()=>Mt},Kt=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 L0=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},S0=function(t,e){for(var n=[],r=0,o=0;o<t;o++)n[r++]=e;return n};const E0=typeof Array.prototype.fill=="function"?L0:S0,jt=(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=[],s=0,a=o;a!==e;)i[s++]=a.head,a=a.tail;return i}return function(o,i){return r(o(n)(e)(i))}})(),zt=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},d_=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},ro=function(t,e,n,r){for(var o=0,i=r.length;o<i;o++)if(n(r[o]))return t(o);return e},l_=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)},h_=function(t,e,n,r){if(n<0||n>=r.length)return e;var o=r.slice();return o.splice(n,1),t(o)},Fr=function(t,e,n,r,o){if(n<0||n>=o.length)return e;var i=o.slice();return i[n]=r,t(i)},se=function(t){return t.slice().reverse()},ln=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,s=o.length;i<s;i++)e.push(o[i]);return e},ft=function(t,e){return e.filter(t)},G0=function(t,e,n){for(var r=n.length,o=e,i=new Array(r),s=0;s<r;s++)o=t(o)(n[s]),i[s]=o;return i},P0=(function(){function t(e,n,r,o,i,s){var a,u,c,_,d,l,f;for(a=i+(s-i>>1),a-i>1&&t(e,n,o,r,i,a),s-a>1&&t(e,n,o,r,a,s),u=i,c=a,_=i;u<a&&c<s;)d=o[u],l=o[c],f=n(e(d)(l)),f>0?(r[_++]=l,++c):(r[_++]=d,++u);for(;u<a;)r[_++]=o[u++];for(;c<s;)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)}})(),Dt=function(t,e,n){return n.slice(t,e)},Qe=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},p_=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},It=t=>e=>P0(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),B0=t=>e=>It(n=>r=>t.compare(e(n))(e(r))),Pt=t=>e=>(()=>{const n=m0(e);return()=>{const r=[...t];return n(r)(),r}})()(),Qr=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:Dt(0,t.length-1|0,t),last:t[e]}):w},D0=t=>e=>n=>t>=0&&t<n.length?Fr(Yt,w,t,e(n[t]),n):w,tr=t=>e=>{const n=(r=>{let o=r,i=!0,s;for(;i;){const a=o;if(a>=0&&a<e.length){if(t(e[a])){o=a+1|0;continue}i=!1,s=N("Just",a);continue}i=!1,s=w}return s})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:Dt(0,n._1,e),rest:Dt(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};g()},Ro=t=>e=>{const n=It(r=>o=>t(r._2)(o._2))(Ht(Gn)(e));return 0<n.length?$(ps)(B0(ot)(ms)((()=>{const r=[n[0]];for(const o of n){const i=t((()=>{const s=r.length-1|0;if(s>=0&&s<r.length)return r[s]._2;g()})())(o._2);(i==="LT"||i==="GT"||i!=="EQ")&&r.push(o)}return r})())):[]},I0=t=>e=>{const n=[],r=y0(o=>o>=0&&o<e.length?N("Just",e[o]):w,{value:0});return w0(r)(o=>()=>{const i=[];i.push(o),x0(t(o))(r)(i)(),n.push(i)})(),n},re=t=>e=>{const n=ro(Yt,w,t,e);return n.tag==="Just"?N("Just",e[n._1]):w},Ci=t=>e=>ft(t,e),tn=t=>e=>n=>{const r=ro(Yt,w,o=>t.eq(o)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},ys=t=>e=>St(e)(t),vt=t=>ys(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];g()}),m_=isFinite;function A0(t,e,n,r){var o=parseFloat(t);return e(o)?n(o):r}const Pn=Math.abs,R0=Math.acos,oo=function(t){return function(e){return Math.atan2(t,e)}},xs=Math.ceil,bn=Math.cos,Fo=Math.exp,Bn=Math.floor,ws=Math.log,F0=function(t){return function(e){return Math.min(t,e)}},xu=function(t){return function(e){return Math.pow(t,e)}},On=Math.round,hn=Math.sin,He=Math.sqrt,Q0=Math.tan,M0=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},nt=function(t){return t},z0=(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 s=parseInt(i,n);return(s|0)===s?t(s):e}else return e}}}})(Yt)(w)(10),y_=M0(Yt)(w),de=t=>{if(!m_(t))return 0;if(t>=nt(2147483647))return 2147483647;if(t<=nt(-2147483648))return-2147483648;const e=y_(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;g()},kt=(t,e,n)=>({tag:t,_1:e,_2:n}),H=kt("Nil"),le={foldr:t=>e=>{const n=le.foldl(o=>i=>t(i)(o))(e),r=(o=>i=>{let s=o,a=i,u=!0,c;for(;u;){const _=s,d=a;if(d.tag==="Nil"){u=!1,c=_;continue}if(d.tag==="Cons"){s=kt("Cons",d._1,_),a=d._2;continue}g()}return c})(H);return o=>n(r(o))},foldl:t=>e=>n=>{let r=e,o=n,i=!0,s;for(;i;){const a=r,u=o;if(u.tag==="Nil"){i=!1,s=a;continue}if(u.tag==="Cons"){r=t(a)(u._1),o=u._2;continue}g()}return s},foldMap:t=>{const e=t.mempty;return n=>le.foldl(r=>{const o=t.Semigroup0().append(r);return i=>o(n(i))})(e)}},W0=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var s=[],a=i;;){var u=o(a);s.push(n(u));var c=r(u);if(t(c))return s;a=e(c)}}}}}}},q0=t=>{if(t.tag==="Just")return t._1;g()},O0={unfoldr1:W0(s_)(q0)(ms)(ps)},H0=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var s=[],a=i;;){var u=o(a);if(t(u))return s;var c=e(u);s.push(n(c)),a=r(c)}}}}}}},$0=t=>{if(t.tag==="Just")return t._1;g()},en={unfoldr:H0(s_)($0)(ms)(ps),Unfoldable10:()=>O0},te=(t,e,n,r,o,i,s)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:s}),nn=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Js=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),x_=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),R=te("Leaf"),Dn=nn("IterLeaf"),ve=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return te("Node",1,1,t,e,n,r);if(r.tag==="Node")return te("Node",1+r._1|0,1+r._2|0,t,e,n,r);g()}if(n.tag==="Node"){if(r.tag==="Leaf")return te("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return te("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()},Ue=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?te("Node",1,1,t,e,R,R):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()})()?ve(r._5._3,r._5._4,ve(t,e,n,r._5._5),ve(r._3,r._4,r._5._6,r._6)):ve(r._3,r._4,ve(t,e,n,r._5),r._6):ve(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()})()?ve(r._5._3,r._5._4,ve(t,e,n,r._5._5),ve(r._3,r._4,r._5._6,r._6)):ve(r._3,r._4,ve(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()})()?ve(n._6._3,n._6._4,ve(n._3,n._4,n._5,n._6._5),ve(t,e,n._6._6,r)):ve(n._3,n._4,n._5,ve(t,e,n._6,r)):ve(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()})()?ve(n._6._3,n._6._4,ve(n._3,n._4,n._5,n._6._5),ve(t,e,n._6._6,r)):ve(n._3,n._4,n._5,ve(t,e,n._6,r)):ve(t,e,n,r);g()},Qo=(t,e,n)=>{if(n.tag==="Leaf")return Js(w,R,R);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const o=Qo(t,e,n._5);return Js(o._1,o._2,Ue(n._3,n._4,o._3,n._6))}if(r==="GT"){const o=Qo(t,e,n._6);return Js(o._1,Ue(n._3,n._4,n._5,o._2),o._3)}if(r==="EQ")return Js(N("Just",n._4),n._5,n._6)}g()},w_=(t,e,n,r)=>{if(r.tag==="Leaf")return x_(t,e,n);if(r.tag==="Node"){const o=w_(r._3,r._4,r._5,r._6);return x_(o._1,o._2,Ue(t,e,n,o._3))}g()},Mo=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=w_(t._3,t._4,t._5,t._6);return Ue(n._1,n._2,n._3,e)}g()},Hn=(t,e,n)=>{if(e.tag==="Leaf")return R;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=Qo(t,n._3,e);return Mo(Hn(t,r._2,n._5),Hn(t,r._3,n._6))}g()},Ns=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return R;if(r.tag==="Node"){const o=Qo(t,r._3,n),i=Ns(t,e,o._2,r._5),s=Ns(t,e,o._3,r._6);if(o._1.tag==="Just")return Ue(r._3,e(o._1._1)(r._4),i,s);if(o._1.tag==="Nothing")return Mo(i,s)}g()},Ae=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const o=Qo(t,r._3,n),i=Ae(t,e,o._2,r._5),s=Ae(t,e,o._3,r._6);if(o._1.tag==="Just")return Ue(r._3,e(o._1._1)(r._4),i,s);if(o._1.tag==="Nothing")return Ue(r._3,r._4,i,s)}g()},J_=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return R;if(o.tag==="Node"){const i=t.compare(n)(o._3);if(i==="LT")return Ue(o._3,o._4,r(o._5),o._6);if(i==="GT")return Ue(o._3,o._4,o._5,r(o._6));if(i==="EQ"){const s=e(o._4);if(s.tag==="Nothing")return Mo(o._5,o._6);if(s.tag==="Just")return te("Node",o._1,o._2,o._3,s._1,o._5,o._6)}}g()};return r},V0=t=>e=>{const n=r=>{if(r.tag==="Leaf")return R;if(r.tag==="Node"){const o=e(r._3)(r._4);if(o.tag==="Just")return Ue(r._3,o._1,n(r._5),n(r._6));if(o.tag==="Nothing")return Mo(n(r._5),n(r._6))}g()};return n},In=(t=>e=>n=>{let r=n,o=!0,i;for(;o;){const s=r;if(s.tag==="IterLeaf"){o=!1,i=e();continue}if(s.tag==="IterEmit"){o=!1,i=t(s._1,s._2,s._3);continue}if(s.tag==="IterNode"){r=(a=>u=>{let c=a,_=u,d=!0,l;for(;d;){const f=c,h=_;if(h.tag==="Leaf"){d=!1,l=f;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){c=nn("IterEmit",h._3,h._4,f),_=h._5;continue}c=nn("IterEmit",h._3,h._4,nn("IterNode",h._6,f)),_=h._5;continue}g()}return l})(s._2)(s._1);continue}g()}return i})((t,e,n)=>N("Just",C(C(t,e),n)))(t=>w),Ft=t=>e=>n=>r=>{const o=i=>{if(i.tag==="Leaf")return te("Node",1,1,n,r,R,R);if(i.tag==="Node"){const s=t.compare(n)(i._3);if(s==="LT")return Ue(i._3,i._4,o(i._5),i._6);if(s==="GT")return Ue(i._3,i._4,i._5,o(i._6));if(s==="EQ")return te("Node",i._1,i._2,n,e(i._4)(r),i._5,i._6)}g()};return o},rt=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return te("Node",1,1,e,n,R,R);if(o.tag==="Node"){const i=t.compare(e)(o._3);if(i==="LT")return Ue(o._3,o._4,r(o._5),o._6);if(i==="GT")return Ue(o._3,o._4,o._5,r(o._6));if(i==="EQ")return te("Node",o._1,o._2,e,n,o._5,o._6)}g()};return r},ce=t=>e=>e.foldl(n=>r=>rt(t)(r._1)(r._2)(n))(R),zo=t=>e=>{const n=r=>{if(r.tag==="Leaf")return R;if(r.tag==="Node"){const o=t.compare(e)(r._3);if(o==="LT")return Ue(r._3,r._4,n(r._5),r._6);if(o==="GT")return Ue(r._3,r._4,r._5,n(r._6));if(o==="EQ")return Mo(r._5,r._6)}g()};return n},N_=t=>{const e=t.compare;return n=>r=>o=>{const i=Qo(e,r,o),s=n(i._1);if(s.tag==="Nothing")return Mo(i._2,i._3);if(s.tag==="Just")return Ue(r,s._1,i._2,i._3);g()}},xe=function(t){return function(e){return t+e|0}},er=function(t){return function(e){return t+e}},Mr=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},X0=function(t){return function(e){return t+e}},he=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},Y0={append:X0},U0={append:he},K0={mempty:"",Semigroup0:()=>Y0},j0={mempty:[],Semigroup0:()=>U0},ki=null;function pn(t,e,n){return t==null?e:n(t)}function d4(t){return t}function wu(t){return function(e){return function(n){return t.apply(n,[e])}}}const Z0=wu(Number.prototype.toPrecision),tm=wu(Number.prototype.toFixed),em=wu(Number.prototype.toExponential),Wo=(t,e)=>({tag:t,_1:e}),qo=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Oo=t=>{if(t.tag==="Precision")return Z0(t._1);if(t.tag==="Fixed")return tm(t._1);if(t.tag==="Exponential")return em(t._1);g()},v_=function(t){return function(){console.log(t)}};function nm(){return Date.now()}function T_(t){return function(){return t.getContext("2d")}}function b_(t){return function(){return t.width}}function C_(t){return function(){return t.height}}function k_(t){return function(e){return function(){t.width=e}}}function L_(t){return function(e){return function(){t.height=e}}}function Ju(t){return function(e){return function(){t.lineWidth=e}}}function rm(t){return function(e){return function(){t.fillStyle=e}}}function om(t){return function(e){return function(){t.strokeStyle=e}}}function Nu(t){return function(e){return function(){t.lineCap=e}}}function vu(t){return function(e){return function(){t.lineJoin=e}}}function im(t){return function(e){return function(){t.globalCompositeOperation=e}}}function sm(t){return function(e){return function(){t.globalAlpha=e}}}function S_(t){return function(){t.beginPath()}}function Tu(t){return function(){t.stroke()}}function bu(t){return function(){t.fill()}}function am(t){return function(){t.clip()}}function Li(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function E_(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function G_(t){return function(){t.closePath()}}function um(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function cm(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function Si(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function Cu(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function gm(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function _m(t){return function(e){return function(){t.textAlign=e}}}function fm(t){return function(e){return function(){t.textBaseline=e}}}function dm(t){return function(e){return function(){t.font=e}}}function lm(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function xr(t){return function(){t.save()}}function wr(t){return function(){t.restore()}}function Ei(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function hm(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const P_=t=>t,ku=t=>t,Lu=t=>t,Su=t=>t,vs=t=>t,pm=vs("BaselineTop"),mm=vs("BaselineMiddle"),ym=vs("BaselineAlphabetic"),xm=vs("BaselineBottom"),wm=Su("AlignLeft"),Jm=Su("AlignRight"),Nm=Su("AlignCenter"),Eu=Lu("BevelJoin"),Ts=Lu("RoundJoin"),Gu=Lu("MiterJoin"),Pu=ku("Round"),Bu=ku("Square"),Du=ku("Butt"),vm=P_("SourceOver"),Tm=P_("Difference"),bm=t=>e=>fm(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()})()),Cm=t=>e=>_m(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()})()),bs=t=>e=>{if(e==="BevelJoin")return vu(t)("bevel");if(e==="RoundJoin")return vu(t)("round");if(e==="MiterJoin")return vu(t)("miter");g()},Iu=t=>e=>{if(e==="Round")return Nu(t)("round");if(e==="Square")return Nu(t)("square");if(e==="Butt")return Nu(t)("butt");g()},B_=t=>e=>im(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()})()),D_={foldrWithIndex:t=>e=>{const n=Io(o=>{const i=o._1,s=o._2;return a=>t(i)(s)(a)})(e),r=Ht(Gn);return o=>n(r(o))},foldlWithIndex:t=>e=>{const n=v(o=>i=>t(i._1)(o)(i._2))(e),r=Ht(Gn);return o=>n(r(o))},foldMapWithIndex:t=>{const e=t.mempty;return n=>D_.foldrWithIndex(r=>o=>i=>t.Semigroup0().append(n(r)(o))(i))(e)},Foldable0:()=>Mt},rn={foldr:t=>e=>{const n=le.foldr(t)(e);return r=>n((()=>{const o=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return o(i._5,kt("Cons",i._3,o(i._6,s)));g()};return o(r,H)})())}},km=t=>{const e={append:(()=>{const n=t.compare;return r=>o=>Ae(n,Be,r,o)})()};return{mempty:R,Semigroup0:()=>e}},Gi=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},zr=function(t){return t.join("")},Jr=function(t){return t.split("")},Pi=function(t){return t},nr=function(t){return t.length},I_=function(t){return function(e){return e.substr(0,t)}},Ho=function(t){return function(e){return e.substring(t)}},A_=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},Lm=t=>e=>{const n=A_(nr(e)-nr(t)|0)(e);return n.after===t?N("Just",n.before):w},io=t=>e=>{const n=A_(nr(t))(e);return n.before===t?N("Just",n.after):w},Sm=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},Em=function(t){return t()},Gm=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},Pm=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},so=t=>BigInt(t),Bm=t=>Number(t),Cs=t=>e=>t+e,ks=t=>e=>t*e,Au=t=>e=>t-e,R_=0n,Ls=1n,F_=t=>e=>t^e,Bi=t=>e=>t&e,Ru=t=>e=>t<<e,Fu=t=>e=>t>>e,Dm=t=>e=>t==e,Im=t=>e=>t===e?0:t>e?1:-1,Am={eq:Dm},Q_={compare:t=>e=>{const n=Im(t)(e);return n===1?Ie:n===0?Ye:De},Eq0:()=>Am},Rm=Gm(Yt)(w),Fm=Pm(Yt)(w),M_=function(t){throw new Error(t)},z_=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=it.compare(e._1)(n._1);return r==="LT"?De:r==="GT"?Ie:it.compare(e._2)(n._2)},Eq0:()=>t}})(),Qm=t=>e=>Pn(t._1-e._1)+Pn(t._2-e._2),ao=t=>t,Ss=t=>t,Le=Ss("North"),Se=Ss("South"),Nr=Ss("East"),vr=Ss("West"),Wr=ao("Rectangle"),Mm=ao("Cylinder"),zm=ao("Parallelogram"),Wm=ao("Diamond"),qm=ao("Ellipse"),Om=ao("Document"),Hm=ao("Cloud"),W_=v(er)(0),$m=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},qr=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Es=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},q_=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Vm=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}]},uo=t=>e=>{const n=Qe(s=>a=>({a:s,b:a,len:(()=>{const u=a.y-s.y,c=a.x-s.x;return He(c*c+u*u)})()}),t,Dt(1,t.length,t)),r=W_($(s=>s.len)(n)),o=$m(0)(r)(e*r),i=s=>a=>u=>{let c=s,_=a,d=u,l=!0,f;for(;l;){const h=c,p=_,m=d,J=zt(x=>w,x=>y=>N("Just",{head:x,tail:y}),h);if(J.tag==="Nothing"){const x=t.length-1|0;if(x>=0&&x<t.length){l=!1,f=t[x];continue}l=!1,f=m;continue}if(J.tag==="Just"){if(p<=J._1.head.len){const x=J._1.head.len<=0?0:p/J._1.head.len;l=!1,f={x:J._1.head.a.x+(J._1.head.b.x-J._1.head.a.x)*x,y:J._1.head.a.y+(J._1.head.b.y-J._1.head.a.y)*x};continue}c=J._1.tail,_=p-J._1.head.len,d=m;continue}g()}return f};return 0<t.length?N("Just",i(n)(o)(t[0])):w},Xm=t=>e=>{const n=qr(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}},Gs=t=>W_(Qe(e=>n=>{const r=n.y-e.y,o=n.x-e.x;return He(o*o+r*r)},t,Dt(1,t.length,t))),Ym=t=>e=>{const n=qr(4)(.15*Es(e.w)(e.h)),r=qr(1)(t.w),o=qr(1)(t.h),i=qr(1)(e.w-2*n),s=qr(1)(e.h-2*n),a=Es(i/r)(s/o);return{scale:a,tx:e.x+n+(i-r*a)/2-t.x*a,ty:e.y+n+(s-o*a)/2-t.y*a}},Qu={scale:1,tx:0,ty:0},_e=t=>{const e=zt(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,kt("Cons",r._4,n(r._6,o)));g()};return St(jt(le.foldr,n(t.nodes,H)))(Vm)})(),...ln((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,kt("Cons",r._4,n(r._6,o)));g()};return jt(le.foldr,n(t.edges,H))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=v(r=>o=>({minX:Es(r.minX)(o.x),minY:Es(r.minY)(o.y),maxX:qr(r.maxX)(o.x),maxY:qr(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()},Um=t=>e=>(n=>r=>o=>{let i=n,s=r,a=o,u=!0,c;for(;u;){const _=i,d=s,l=a,f=zt(h=>w,h=>p=>N("Just",{head:h,tail:p}),d);if(f.tag==="Nothing"){u=!1,c=l;continue}if(f.tag==="Just"){const h=q_(f._1.head)(_.interiors);if(h.tag==="Nothing"){u=!1,c=l;continue}if(h.tag==="Just"){i=h._1,s=f._1.tail,a=(()=>{const p=Ym(_e(h._1.layout))((()=>{const m=q_(f._1.head)(_.layout.nodes);if(m.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:Wr};if(m.tag==="Just")return m._1;g()})());return{scale:l.scale*p.scale,tx:l.scale*p.tx+l.tx,ty:l.scale*p.ty+l.ty}})();continue}}g()}return c})(t)(e)(Qu),Km=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},jm=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ps=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Zm=t=>e=>n=>r=>{const o=_e(e);return n<=0||r<=0||o.w<=0||o.h<=0?1:t?Km(o.w/n)(o.h/r):jm(o.w/n)(o.h/r)},O_=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;if(t.widthPx<=0||t.heightPx<=0){const s=1/Ps(.05)(1)(e);return{w:n.w*s,h:n.h*s}}if(r>o){const s=1/Ps(.05)(1)(e);return{w:n.h*r*s,h:n.h*s}}const i=1/Ps(.05)(1)(e);return{w:n.w*i,h:n.w/r*i}},H_=t=>e=>n=>r=>o=>{const i=t+o/2,s=t+e-o/2,a=t+e/2,u=n+r/2;return o>=e?a:Ps(i)(s)(u)},$_=t=>e=>n=>r=>{const o=_e(t);return{x:H_(o.x)(o.w)(e.x)(e.w)(n),y:H_(o.y)(o.h)(e.y)(e.h)(r)}},V_=t=>e=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:Zm(t)(e)(n.w)(n.h)}),t2=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=O_(e)(.65)(o),s=$_(n)(o)(i.w)(i.h),a={x:s.x-i.w/2,y:s.y-i.h/2,w:i.w,h:i.h};return{focus:r,paddedFocus:o,viewport:a,camera:V_(e.widthPx>0&&e.heightPx>0)(n)(a)}},e2=t=>e=>n=>r=>o=>i=>{const s=_e(r),a={x:s.x*o.scale+o.tx,y:s.y*o.scale+o.ty,w:s.w*o.scale,h:s.h*o.scale},u=t.padding*o.scale,c={x:a.x-u,y:a.y-u,w:a.w+u*2,h:a.h+u*2},_=O_(e)(.7)(c),d=$_(n)(c)(_.w)(_.h),l={x:d.x-_.w/2,y:d.y-_.h/2,w:_.w,h:_.h};return{footprint:a,viewport:l,camera:V_(e.widthPx>0&&e.heightPx>0)(n)(l)}},X_=t=>t,n2=(t,e)=>({tag:t,_1:e}),Mu=t=>t,$o=(t,e)=>({tag:t,_1:e}),zu=(t,e)=>({tag:t,_1:e}),Di=Mu("Animated"),r2=Mu("StaticStill"),o2=Mu("TitleCard"),i2=zu("First"),Y_=X_("Forward"),U_=X_("Backward"),s2=$o("ExitNode"),K_=ce(P)(Mt),a2=t=>Io(e=>n=>({nodes:Ae(P.compare,Be,e.nodes,n.nodes),edges:Ae(P.compare,Be,e.edges,n.edges)}))({nodes:R,edges:R})(t.keyframes),u2=t=>e=>({entering:{nodes:Hn(P.compare,e.nodes,t.nodes),edges:Hn(P.compare,e.edges,t.edges)},leaving:{nodes:Hn(P.compare,t.nodes,e.nodes),edges:Hn(P.compare,t.edges,e.edges)},surviving:{nodes:Ns(P.compare,Be,t.nodes,e.nodes),edges:Ns(P.compare,Be,t.edges,e.edges)}}),Bs=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Vo=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ds=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Wu=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},c2=v(t=>e=>rt(P)(e)()(t))(R),g2=v(t=>e=>rt(P)(e)()(t))(R),_2=(()=>{const t=en.unfoldr(In);return e=>t(nn("IterNode",e,Dn))})(),j_=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Z_=ce(P)(Mt),Is=t=>{const e=zt(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=v(r=>o=>({minX:Bs(r.minX)(o.x),minY:Bs(r.minY)(o.y),maxX:Vo(r.maxX)(o.x),maxY:Vo(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()},f2=t=>e=>n=>c2(St(jt(rn.foldr,n))(r=>{const o=Ds(r)(t);if(o.tag==="Just")return ft(i=>!Wu(i)(e),[o._1.source,o._1.target]);if(o.tag==="Nothing")return[];g()})),d2=t=>t.kind.tag==="SendToken"?N("Just",C(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):w,l2=t=>t.tag==="DataFlow"?vt(d2)(t._1.events):[],h2=t=>e=>g2(vt(n=>Wu(n._2.source)(e)||Wu(n._2.target)(e)?N("Just",n._1):w)(_2(t))),Tr=t=>{const e=zt(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=v(r=>o=>({minX:Bs(r.minX)(o.x),minY:Bs(r.minY)(o.y),maxX:Vo(r.maxX)(o.x+o.w),maxY:Vo(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()},qu=t=>e=>n=>{if(n.tag==="Leaf")return _e(t);const r=h2(e)(n),o=[...vt(i=>{const s=j_(i)(t.nodes);return s.tag==="Just"?N("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):w})(jt(rn.foldr,Ae(P.compare,Be,n,f2(e)(n)(r)))),...vt(i=>{const s=Ds(i)(t.edges);return s.tag==="Just"?N("Just",Is(s._1)):w})(jt(rn.foldr,r))];return o.length===0?_e(t):Tr(o)},tf=t=>e=>n=>{const r=[...vt(o=>o)([(()=>{const o=Ds(n)(t.edges);return o.tag==="Just"?N("Just",Is(o._1)):w})()]),...(()=>{const o=Ds(n)(e);if(o.tag==="Just")return vt(i=>{const s=j_(i)(t.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._1.source,o._1.target]);if(o.tag==="Nothing")return[];g()})()];return r.length===0?qu(t)(e)(R):Tr(r)},co=t=>e=>{const n=_e(t),r=n.w/Vo(1e-4)(e.zoom),o=n.h/Vo(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-o/2,w:r,h:o}},p2=t=>Ae(P.compare,Be,Z_($(e=>C(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),Z_(St(t.scenes)(l2))),Ou=t=>t,m2=t=>t,Hu=Ou("Linear"),go=Ou("EaseInOutQuad"),y2=Ou("SpringBouncy"),Ii=t=>e=>n=>{const r=He(1-e*e),o=t*r;return 1-Fo(-e*t*n)*(bn(o*n)+e/r*hn(o*n))},x2=t=>{const e=it.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=it.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Or=t=>e=>(()=>{if(t==="Linear")return m2;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-xu(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*Fo(-6*n);if(t==="SpringBouncy")return Ii(6)(.7);g()})()(x2(e)),As=t=>t,ef=t=>t,nf=t=>t,An=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ai=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},$u=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},w2=t=>e=>{const n=ot.compare(t._1)(e._1);return n==="LT"?De:n==="GT"?Ie:it.compare(t._2)(e._2)},J2=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},N2=nf("Hold"),v2=nf("Gap"),Hr=ef("LinearLerp"),rf=ef("StagedLogLerp"),Vu=As("Overview"),of=As("DiveHome"),sf=As("DiveTransition"),Rs=As("ActionFocus"),T2=t=>e=>{const n=_e(t),r=n.h/An(1e-6)(e.zoom),o=n.w/An(1e-6)(e.zoom);return{x:e.center.x-o/2,y:e.center.y-r/2,w:o,h:r}},b2=t=>e=>n=>{const r=n.center.y-e.center.y,o=n.center.x-e.center.x,i=He(o*o+r*r),s=n.zoom-e.zoom,a=s<0?-s:s;return Ai(t.minTransition)(t.maxTransition)(An(t.panSpeed<=0?t.minTransition:i/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:a/t.zoomSpeed))},C2=t=>({startT:t.startT,endT:t.endT,fromCam:t.fromCam,toCam:t.toCam,easing:t.easing,interp:t.interp,intent:t.intent}),af=t=>e=>Or(go)(Ai(0)(1)((e-t)/An(1e-4)(1-t))),uf=t=>e=>Or(go)(Ai(0)(1)(e/An(1e-4)(t))),k2=v(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:Pt(t)(e)})([]),L2=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})()})()})()},S2=t=>e=>t.tag==="Just"?e.tag==="Just"&&L2(t._1)(e._1):t.tag==="Nothing"&&e.tag==="Nothing",cf=t=>e=>n=>r=>({center:{x:r.center.x*n.scale+n.tx,y:r.center.y*n.scale+n.ty},zoom:r.zoom*_e(t).w/An(1e-6)(n.scale*_e(e).w)}),gf=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:Fo((()=>{const o=ws(An(1e-6)(t.zoom));return o+(ws(An(1e-6)(e.zoom))-o)*r})())}),E2=v(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),G2=t=>e=>n=>r=>{const o=Fo(-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:Fo((()=>{const i=ws(An(1e-6)(r.zoom));return i+(ws(An(1e-6)(n.zoom))-i)*o})())}},P2=t=>e=>n=>e.zoom>=t.zoom?af(.18000000000000005)(n):uf(.82)(n),B2=t=>e=>n=>e.zoom>=t.zoom?uf(.28)(n):af(.72)(n),D2=t=>e=>n=>gf(t)(e)(B2(t)(e)(n))(P2(t)(e)(n)),I2=t=>e=>n=>{const r=n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT),o=Or(n.easing)(Ai(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 gf(n.fromCam)(n.toCam)(o)(o);if(n.interp==="StagedLogLerp")return D2(n.fromCam)(n.toCam)(r);g()},A2={widthPx:0,heightPx:0},R2={padding:24,easing:Hu,minimumReadableLabelPx:11,minimumVisibleLabelPx:5,labelBasePx:11,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:6},Xo=t=>e=>n=>r=>o=>{const i=T2(n)(r),s=o.x-t.padding,a=o.y-t.padding;return s>=i.x&&a>=i.y&&s+o.w+t.padding*2<=i.x+i.w&&a+o.h+t.padding*2<=i.y+i.h},F2=t=>e=>n=>r=>o=>D_.foldlWithIndex(i=>s=>a=>{const u=(()=>{if(a.kind==="Hold"){const c=(()=>{if(a.focus.tag==="Just"){if(a.intent==="ActionFocus")return Xo(t)(e)(n)(s.prev)(a.focus._1)?s.prev:Xo(t)(e)(n)({center:s.prev.center,zoom:a.toCam.zoom})(a.focus._1)?{...a.toCam,center:s.prev.center}:{...a.toCam,center:{...a.toCam.center,x:(()=>{const _=_e(n).w/An(1e-6)(a.toCam.zoom);if(_<=0)return a.toCam.center.x;const d=a.focus._1.x+a.focus._1.w/2,l=e.widthPx<=0?0:$u(_/4)(6*_/e.widthPx),f=s.prev.center.x+_/2-l,h=d<s.prev.center.x-_/2+l?d-l+_/2:d>f?d+l-_/2:s.prev.center.x,p=_e(n);return _>=p.w?p.x+p.w/2:Ai(p.x+_/2)(p.x+p.w-_/2)(h)})()}};if(Xo(t)(e)(n)(s.prev)(a.focus._1))return s.prev;if(Xo(t)(e)(n)({center:s.prev.center,zoom:a.toCam.zoom})(a.focus._1))return{...a.toCam,center:s.prev.center}}return a.toCam})();return{startT:a.startT,endT:a.endT,fromCam:c,toCam:c,easing:a.easing,interp:Hr,focus:a.focus,intent:a.intent}}if(a.kind==="Gap")return{startT:a.startT,endT:a.endT,fromCam:s.prev,toCam:(()=>{const c=i+1|0,_=ro(Yt,w,d=>d.kind==="Hold",c<1?o:Dt(c,o.length,o));if(_.tag==="Just"){const d=(i+1|0)+_._1|0;return d>=0&&d<o.length?(()=>{if(o[d].focus.tag==="Just")return Xo(t)(e)(n)(s.prev)(o[d].focus._1);if(o[d].focus.tag==="Nothing")return!1;g()})()?s.prev:o[d].fromCam:s.prev}if(_.tag==="Nothing")return s.prev;g()})(),easing:a.easing,interp:Hr,focus:w,intent:a.intent};g()})();return{acc:Pt(s.acc)(u),prev:u.toCam}})({acc:[],prev:r})(o).acc,Q2=t=>e=>n=>r=>o=>{const i=(a,u)=>$u(b2(t)(a.toCam)(u.toCam))(a.endT-a.startT),s=v(a=>u=>{if(a.pending.tag==="Nothing")return{acc:a.acc,pending:N("Just",u)};if(a.pending.tag==="Just")return!(u.fromCam.zoom===u.toCam.zoom&&u.fromCam.center.x===u.toCam.center.x&&u.fromCam.center.y===u.toCam.center.y)||(()=>{if(u.focus.tag==="Just")return Xo(t)(e)(n)(a.pending._1.toCam)(u.focus._1);if(u.focus.tag==="Nothing")return!1;g()})()||(()=>{const c=a.pending._1.toCam.center.x-u.toCam.center.x;return(c<0?-c<8:c<8)&&(()=>{const _=a.pending._1.toCam.center.y-u.toCam.center.y;return(_<0?-_<8:_<8)&&(()=>{const d=a.pending._1.toCam.zoom-u.toCam.zoom;return d<0?-d<.08:d<.08})()})()})()||i(a.pending._1,u)<=0?{acc:Pt(a.acc)(a.pending._1),pending:N("Just",u)}:{acc:Pt(Pt(a.acc)({...a.pending._1,endT:u.startT-i(a.pending._1,u)}))({startT:u.startT-i(a.pending._1,u),endT:u.startT,fromCam:a.pending._1.toCam,toCam:u.toCam,easing:u.easing,interp:Hr,focus:u.focus,intent:u.intent}),pending:N("Just",u)};g()})({acc:[],pending:w})(o);if(s.pending.tag==="Nothing")return s.acc;if(s.pending.tag==="Just")return Pt(s.acc)(s.pending._1);g()},M2=t=>e=>n=>{const r=e.w+n*2,o=e.h+n*2,i=_e(t);return r<=0||o<=0||i.w<=0||i.h<=0?1:$u(i.w/r)(i.h/o)},z2=t=>e=>{if(t.tag==="Just"){if(e.tag==="Just")return N("Just",Tr([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()},W2=v(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")&&S2(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 s=r._1.toCam.zoom-e.toCam.zoom;return s<0?-s<.08:s<.08})()})()})()?Pt((()=>{const o=t.length-1|0;return o<1?[]:Dt(0,o,t)})())({...r._1,endT:e.endT,focus:z2(r._1.focus)(e.focus)}):Pt(t)(e)})([]),q2=t=>{const e=It(n=>r=>w2(C((()=>{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))(C((()=>{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},Xu=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:An(r)(M2(e)(n)(t.padding))}),O2=t=>e=>n=>r=>o=>{const i=Xu(t)(n)(_e(n))(0),s=ft(u=>u>=0&&u<=r,k2(It(it.compare)([0,r,...St(o)(u=>[u.startT,u.endT])]))),a=(u,c)=>Ne(_=>_.priority>=1,ft(_=>_.startT<=c&&c<_.endT,o))?t2(t)(e)(n)(Tr(u)).camera:Xu(t)(n)(Tr(u))(0);return $(C2)(Q2(t)(e)(n)(i)(W2(F2(t)(e)(n)(i)(vt(u=>{const c=(u._1+u._2)/2;if(u._2<=u._1)return w;const _=$(d=>d.bbox)(ft(d=>d.priority===v(J2)(0)($(l=>l.priority)(ft(l=>l.startT<=c&&c<l.endT,o))),ft(d=>d.startT<=c&&c<d.endT,o)));return _.length===0?N("Just",{kind:v2,startT:u._1,endT:u._2,fromCam:i,toCam:i,easing:t.easing,focus:w,intent:Vu}):N("Just",{kind:N2,startT:u._1,endT:u._2,fromCam:a(_,c),toCam:a(_,c),easing:t.easing,focus:N("Just",Tr(_)),intent:Ne(d=>d.priority>=1,ft(d=>d.startT<=c&&c<d.endT,o))?Rs:Vu})})(Qe(Gn,s,Dt(1,s.length,s)))))))},Ri=t=>e=>n=>r=>{const o=q2(ft(i=>r>=i.startT&&r<i.endT,n));if(o.tag==="Just")return{camera:I2()(r)(o._1),intent:o._1.intent};if(o.tag==="Nothing"){const i=E2(n);return i.tag==="Just"&&r>=i._1.endT?{camera:i._1.toCam,intent:i._1.intent}:{camera:(()=>{const s=Xu(t)(e)(_e(e))(0);return 0<n.length?n[0].fromCam:s})(),intent:0<n.length?n[0].intent:Vu}}g()};function $r(t){return t.charCodeAt(0)}function _f(t){return String.fromCharCode(t)}const Rn=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},Vr=function(t){return function(e){return e.split(t)}},Fs=function(t){return t.trim()},rr=function(t){return function(e){return e.join(t)}};var H2=typeof Array.from=="function",$2=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",V2=typeof String.prototype.fromCodePoint=="function",X2=typeof String.prototype.codePointAt=="function";const Y2=function(t){return X2?function(e){return e.codePointAt(0)}:t},U2=function(t){return V2?String.fromCodePoint:t},K2=function(t){return function(e){return $2?function(n){for(var r="",o=n[Symbol.iterator](),i=0;i<e;++i){var s=o.next();if(s.done)return r;r+=s.value}return r}:t(e)}},j2=function(t){return function(e){return H2?function(n){return Array.from(n,e)}:t}},Qs=t=>{const e=nr(t);if(e===0)return w;if(e===1)return N("Just",{head:$r(Gi(0)(t)),tail:""});const n=$r(Gi(1)(t)),r=$r(Gi(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:Ho(2)(t)}):N("Just",{head:r,tail:Ho(1)(t)})},Z2=t=>{const e=Qs(t);return e.tag==="Just"?N("Just",C(e._1.head,e._1.tail)):w},ty=t=>en.unfoldr(Z2)(t),ff=Y2(t=>{const e=$r(Gi(0)(t));if(55296<=e&&e<=56319&&nr(t)>1){const n=$r(Gi(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),Yo=j2(ty)(ff),ey=t=>Yo(t).length,Yu=t=>Pi(t>=0&&t<=65535?_f(t):t<0?"\0":"\uFFFF"),ny=U2(t=>t<=65535?Yu(t):Yu(yr(t-65536|0,1024)+55296|0)+Yu(Mr(t-65536|0)(1024)+56320|0)),df=t=>e=>{if(t<1)return"";const n=Qs(e);return n.tag==="Just"?ny(n._1.head)+df(t-1|0)(n._1.tail):e},Re=K2(df),ry=t=>e=>e===""?w:N("Just",ff(e)),lf=t=>t,Ms=(t,e)=>({tag:t,_1:e}),Fn=(t,e,n)=>({tag:t,_1:e,_2:n}),hf=t=>t,Uo=(t,e,n,r,o,i,s,a,u)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:s,_7:a,_8:u}),Uu=hf("PlopIn"),oy=hf("PlopOut"),iy=lf("DiveIn"),sy=lf("DiveOut"),Ko=(t,e,n)=>({tag:t,_1:e,_2:n}),ay=t=>t,jo=(t,e)=>({tag:t,_1:e}),Ku=t=>t,zs=(t,e)=>({tag:t,_1:e}),ju=zs("NotYet"),pf=zs("Consumed"),uy=Ku("FromSource"),mf=Ku("FromTarget"),cy=Ku("FromBoth"),Zu=jo("Hidden"),gy=jo("Visible"),tc=ay("ExtendFromSource"),ec=Ko("Retracted"),yf=Ko("Extended"),_y={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},nc=t=>t,xf=ce(P)(Mt),Fi={eq:mu(Ti)},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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},wf=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},fy=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},oc=(()=>{const t=en.unfoldr(In);return e=>t(nn("IterNode",e,Dn))})(),$n=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},_o=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Jf=Mt.foldMap(km(P)),Nf=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},dy=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},ly=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},hy=ce(P)(Mt),py=ce(P)(Mt),vf=nc("Backdrop"),my=nc("FlyThrough"),fn=nc("Active"),yy=t=>e=>n=>({...n,state:{...n.state,edgeFadeAlpha:xf($(r=>C(r,e))(t))}}),Tf=t=>e=>n=>{const r=(t+e)/2,o=n-r,i=o<0?-1:1,s=(e-t)/2,a=s*.15,u=s-a,c=o<0?-o:o;return e<=t?(t+e)/2:c<=u?n:r+i*(s-a*Fo(-(c-u)/a))},Ws=t=>e=>n=>{const r=re(o=>Fi.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 re(o=>Fi.eq(o.path)(e))(t.segments);g()},xy=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()},wy=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:Qu,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:R}),Jy=t=>$(e=>e<1?[]:Dt(0,e,t))(Kt(0,t.length-1|0)),ic=t=>e=>{const n=rc(e)(t.keyframes);if(n.tag==="Nothing")return R;if(n.tag==="Just")return n._1.nodes;g()},sc=t=>e=>{const n=rc(e)(t.keyframes);if(n.tag==="Nothing")return R;if(n.tag==="Just")return n._1.edges;g()},Ny=t=>e=>{const n=[...vt(r=>{if(r._2.tag==="Hidden")return w;const o=wf(r._1)(t.layout.nodes);return o.tag==="Just"?N("Just",(()=>{const i=o._1.x*t.placement.scale+t.placement.tx,s=o._1.y*t.placement.scale+t.placement.ty;return{x:i,y:s,w:(o._1.x+o._1.w)*t.placement.scale+t.placement.tx-i,h:(o._1.y+o._1.h)*t.placement.scale+t.placement.ty-s}})()):w})(oc(e.nodes)),...vt(r=>{if(r._2.tag==="Retracted")return w;const o=fy(r._1)(t.layout.edges);return o.tag==="Just"?N("Just",(()=>{const i=Is(o._1),s=i.x*t.placement.scale+t.placement.tx,a=i.y*t.placement.scale+t.placement.ty;return{x:s,y:a,w:(i.x+i.w)*t.placement.scale+t.placement.tx-s,h:(i.y+i.h)*t.placement.scale+t.placement.ty-a}})()):w})(oc(e.edges))];return n.length===0?w:N("Just",Tr(n))},vy=v(t=>e=>{const n=Qr(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?Pt(n._1.init)({...n._1.last,endT:$n(n._1.last.endT)(e.endT),windows:Pt(n._1.last.windows)(e)}):Pt(t)({endT:e.endT,windows:[e]})})([]),Ty=t=>e=>{const n=$n(t.lo)(e.lo),r=_o(t.hi)(e.hi);return n<=r?{lo:n,hi:r}:t},by=t=>e=>n=>Jf(r=>Jf(o=>o.target.tag==="FillWindow"?o.startT<=n?te("Node",1,1,o.target._2,void 0,R,R):R:o.target.tag==="TokenWindow"&&o.startT+(o.endT-o.startT)*.25<=n?te("Node",1,1,o.target._4,void 0,R,R):R)(r.windows))(ft(r=>n<=r.endT+t,vy(It(r=>o=>it.compare(r.startT)(o.startT))(ft(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),Cy=t=>e=>n=>Ne(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),ky=t=>e=>n=>Ne(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),Ly=t=>e=>n=>Ne(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),Sy=t=>e=>n=>Ne(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),qs=t=>e=>n=>re(r=>n(r)&&e>=r.startT&&e<r.endT)(t),Os=t=>e=>{if(e<t.startT)return Fn("AtKeyframe",t.initialKeyframe);const n=re(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Fn("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Fn("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return Fn("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode"||n._1.scene.tag==="StepScene")return Fn("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing")return Fn("AtKeyframe",v(xy)(t.initialKeyframe)(t.spans));g()},Ey=t=>e=>{const n=Os(t)(e),r=rc((()=>{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 Di;g()},Gy=t=>e=>{const n=Os(t)(e);if(n.tag==="AtKeyframe")return Re(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return Re(3)(n._2)==="kf-"?"":n._2;g()},Py={segment:{startT:0,endT:0,path:[],layout:{nodes:R,edges:R,chipExtras:R,edgeLabels:R},placement:Qu,windows:[],spans:[],keyframes:R,initialKeyframe:"",edgeEndpoints:R},state:{nodes:R,edges:R,tokens:R,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:Di,visited:R,nodeFadeAlpha:R,nodeLabelFadeAlpha:R,edgeFadeAlpha:R,nodeInvert:R},bgAlpha:1,blur:0,minis:[],role:fn},Hs=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:Py},By=t=>e=>{const n=wf(e)(t.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1,o=i=>i.x>=r.x-1&&i.x<=r.x+r.w+1&&i.y>=r.y-1&&i.y<=r.y+r.h+1;return vt(i=>(()=>{if(0<i._2.length){const a=i._2.length-1|0;return o(i._2[0])||a>=0&&a<i._2.length&&o(i._2[a])}const s=i._2.length-1|0;return s>=0&&s<i._2.length&&o(i._2[s])})()?N("Just",i._1):w)(oc(t.edges))}g()},Dy=t=>e=>{const n=Os(t)(e);if(n.tag==="AtKeyframe")return ic(t)(n._1);if(n.tag==="InTransition")return Ae(P.compare,Be,ic(t)(n._1),ic(t)(n._2));g()},Iy=t=>e=>{const n=Os(t)(e);if(n.tag==="AtKeyframe")return sc(t)(n._1);if(n.tag==="InTransition")return Ae(P.compare,Be,sc(t)(n._1),sc(t)(n._2));g()},Ay=t=>e=>n=>r=>{const o=_e(t).w/$n(1e-4)(r.zoom),i=_e(e.layout),s=i.x*e.placement.scale+e.placement.tx,a=(()=>{const c=(()=>{const _=i.y*e.placement.scale+e.placement.ty;return{x:s,y:_,w:(i.x+i.w)*e.placement.scale+e.placement.tx-s,h:(i.y+i.h)*e.placement.scale+e.placement.ty-_}})();return o>=c.w?{lo:c.x+c.w-o/2,hi:c.x+o/2}:{lo:c.x+o/2,hi:c.x+c.w-o/2}})(),u=Ny(e)(n);if(u.tag==="Nothing")return r;if(u.tag==="Just"){if(o>=u._1.w){const c=Ty(a)(o>=u._1.w?{lo:u._1.x+u._1.w-o/2,hi:u._1.x+o/2}:{lo:u._1.x+o/2,hi:u._1.x+u._1.w-o/2});return{...r,center:{...r.center,x:Nf(c.lo)(c.hi)(r.center.x)}}}return r}g()},Ry=t=>e=>n=>{const r=_e(t),o=r.h/$n(1e-4)(n.zoom),i=r.w/$n(1e-4)(n.zoom);return{...n,center:{x:i>=e.w?e.x+e.w/2:Tf(e.x+i/2)(e.x+e.w-i/2)(n.center.x),y:o>=e.h?e.y+e.h/2:Tf(e.y+o/2)(e.y+e.h-o/2)(n.center.y)}}},Fy=t=>e=>n=>Ry(t)((()=>{const r=e*n.placement.scale,o=_e(n.layout),i=(()=>{const s=o.x*n.placement.scale+n.placement.tx,a=o.y*n.placement.scale+n.placement.ty;return{x:s,y:a,w:(o.x+o.w)*n.placement.scale+n.placement.tx-s,h:(o.y+o.h)*n.placement.scale+n.placement.ty-a}})();return{x:i.x-r,y:i.y-r,w:i.w+r*2,h:i.h+r*2}})()),Qy=t=>e=>{const n=t.endT-t.startT;return n<=0?1:$n(0)(_o(1)((e-t.startT)/n))},Zo=t=>e=>{const n=t.endT-t.startT;return n<=0?1:$n(0)(_o(1)((e-t.startT)/n))},My=t=>e=>n=>r=>o=>{const i=qs(e)(n)(s=>s.target.tag==="EdgeWindow"&&s.target._2.tag==="Retract"&&s.target._1===o);if(i.tag==="Just"){const s=Or(t.timing.edgeEasing)(Zo(i._1)(n)),a=i._1.target.tag==="EdgeWindow"?i._1.target._2:Ms("Extend",tc);if(a.tag==="Retract")return Ko("Retracting",a._1,s);if(a.tag==="Extend")return Ko("Extending",a._1,s);g()}if(i.tag==="Nothing"){if(Cy(e)(n)(o))return ec;const s=qs(e)(n)(a=>a.target.tag==="EdgeWindow"&&a.target._1===o);if(s.tag==="Just"){const a=Or(t.timing.edgeEasing)(Zo(s._1)(n)),u=s._1.target.tag==="EdgeWindow"?s._1.target._2:Ms("Extend",tc);if(u.tag==="Retract")return Ko("Retracting",u._1,a);if(u.tag==="Extend")return Ko("Extending",u._1,a);g()}if(s.tag==="Nothing")return Sy(e)(n)(o)?ec:dy(o)(r)?yf:ec}g()},zy=t=>e=>n=>{const r=Iy(e)(n);return xf($(o=>C(o,My(t)(e.windows)(n)(r)(o)))((()=>{const o=i=>{if(i.tag==="Leaf")return R;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,void 0,o(i._5),o(i._6));g()};return jt(rn.foldr,o(e.layout.edges))})()))},Wy=t=>e=>n=>r=>{const o=qs(t)(e)(i=>i.target.tag==="NodeWindow"&&i.target._1===r&&i.target._2==="PlopOut");if(o.tag==="Just"){const i=Zo(o._1)(e),s=o._1.target.tag==="NodeWindow"?o._1.target._2:Uu;if(s==="PlopIn")return jo("PloppingIn",i);if(s==="PlopOut")return jo("PloppingOut",i);g()}if(o.tag==="Nothing"){if(ky(t)(e)(r))return Zu;const i=qs(t)(e)(s=>s.target.tag==="NodeWindow"&&s.target._1===r);if(i.tag==="Just"){const s=Zo(i._1)(e),a=i._1.target.tag==="NodeWindow"?i._1.target._2:Uu;if(a==="PlopIn")return jo("PloppingIn",s);if(a==="PlopOut")return jo("PloppingOut",s);g()}if(i.tag==="Nothing")return Ly(t)(e)(r)?Zu:ly(r)(n)?gy:Zu}g()},qy=t=>e=>{const n=Dy(t)(e);return hy($(r=>C(r,Wy(t.windows)(e)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return R;if(o.tag==="Node")return te("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));g()};return jt(rn.foldr,r(t.layout.nodes))})()))},Oy=t=>e=>n=>e.target.tag==="TokenWindow"?C(e.target._1,n<e.startT?ju:n>=e.endT?pf:zs("Travelling",{edge:e.target._2,direction:e.target._3,progress:Or(t.timing.tokenEasing)(Zo(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"?C(e.target._1,n<e.startT?ju:n>=e.endT?pf:zs("Filling",{node:e.target._2,progress:Zo(e)(n),labels:e.target._3})):C("",ju),Hy=t=>e=>n=>py($(r=>Oy(t)(r)(n))(ft(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),$y=t=>e=>n=>({nodes:qy(e)(n),edges:zy(t)(e)(n),tokens:Hy(t)(e.windows)(n),camera:Ri(t.cameraConfig)(e.layout)(t.cameraSpans)(n).camera,frameTitle:Gy(e)(n),staticKind:Ey(e)(n),visited:by(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:R,nodeLabelFadeAlpha:R,edgeFadeAlpha:R,nodeInvert:R}),ti=t=>e=>n=>r=>({segment:n,state:$y(t)(n)(e),bgAlpha:1,blur:0,minis:Vy(t)(e)(n),role:r}),Vy=t=>e=>n=>vt(r=>{const o=Ws(t)(Pt(n.path)(r))(e);if(o.tag==="Just")return N("Just",{...ti(t)(Nf(o._1.startT)(o._1.endT-1e-4)(e))(o._1)(vf),bgAlpha:0});if(o.tag==="Nothing")return w;g()})((()=>{const r=o=>{if(o.tag==="Leaf")return R;if(o.tag==="Node")return te("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));g()};return jt(rn.foldr,r(n.layout.nodes))})()),Xy=t=>e=>n=>d_(w,a_,r=>r.direction==="DiveIn"&&Fi.eq(r.parentPath)(e.path)&&n>=r.startT-.7&&n<r.startT?N("Just",{node:r.node,phase:(n-(r.startT-.7))/.7}):w,t.dives),Yy=t=>e=>n=>r=>{const o=Xy(t)(e)(n);if(o.tag==="Just"){const i=hn(3.141592653589793*o._1.phase*3);return{...r,state:{...r.state,nodeInvert:te("Node",1,1,o._1.node,1*i*i,R,R)}}}if(o.tag==="Nothing")return r;g()},bf=t=>e=>vt(n=>{const r=re(o=>o.direction==="DiveIn"&&Fi.eq(o.childPath)((()=>{const i=n.length+1|0;return i<1?[]:Dt(0,i,e)})()))(t.dives);if(r.tag==="Just"){const o=Ws(t)(n)(r._1.startT-1e-4);if(o.tag==="Just")return N("Just",(()=>{const i=ti(t)(r._1.startT-1e-4)(o._1)(vf);return{...i,state:{...i.state,nodeFadeAlpha:te("Node",1,1,r._1.node,0,R,R)}}})());if(o.tag==="Nothing")return w;g()}if(r.tag==="Nothing")return w;g()})(Jy(e)),Cf=t=>e=>{const n=ft(o=>e>=o.startT&&e<o.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:wy(t)},Uy=t=>e=>n=>{const r=Qy(n)(e),o=Ws(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),i=Ws(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),s=(()=>{if(n.direction==="DiveIn")return Or(go)(r);if(n.direction==="DiveOut")return 1-Or(go)(r);g()})(),a=1-$n(0)(_o(1)((s-.1)/.25)),u=1-$n(0)(_o(1)((s-.1)/.25)),c=1-$n(0)(_o(1)((s-.8)/.2)),_=l=>{const f=ti(t)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})())(l)(my);return{...yy(By(l.layout)(n.node))(u)({...f,state:{...f.state,nodeFadeAlpha:te("Node",1,1,n.node,a,R,R),nodeLabelFadeAlpha:te("Node",1,1,n.node,u,R,R)}}),minis:ft(h=>!Fi.eq(h.segment.path)(n.childPath),f.minis),bgAlpha:c}},d=0+1*$n(0)(_o(1)((s-.1)/.5));return[...bf(t)(n.parentPath),...(()=>{if(o.tag==="Just"){if(i.tag==="Just")return[_(o._1),{...ti(t)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})())(i._1)(fn),bgAlpha:d}];if(i.tag==="Nothing")return[_(o._1)];g()}if(o.tag==="Nothing")return[ti(t)(e)(Cf(t)(e))(fn)];g()})()]},Ky=t=>e=>re(n=>e>=n.startT&&e<n.endT)(t.dives),jy=t=>e=>{const n=Cf(t)(e),r=ti(t)(e)(n)(fn),o=t.dives.length!==0,i=Ri(t.cameraConfig)(t.layout)(t.cameraSpans)(e).camera,s=Ay(t.layout)(n)(r.state)(Fy(t.layout)(t.cameraConfig.padding)(n)(i)),a=Yy(t)(n)(e)({...r,state:{...r.state,camera:s}}),u=bf(t)(n.path),c=Ky(t)(e);if(c.tag==="Just")return{levels:Uy(t)(e)(c._1),camera:i,rootLayout:t.layout,hasDives:o,diving:!0};if(c.tag==="Nothing")return{levels:Pt(u)(a),camera:s,rootLayout:t.layout,hasDives:o,diving:!1};g()},Zy=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},tx=t=>{const e=t.length;return(n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=i;if(u>=e){s=!1,a=c;continue}const _=d=>l=>{let f=d,h=l,p=!0,m;for(;p;){const J=f,x=h;if(J>=e){p=!1,m=x;continue}if(u>=0&&u<t.length){if(J>=0&&J<t.length){f=J+1|0,h=(()=>{const y=t[u].position,T=t[u].size,b=t[J].position,L=t[J].size;return y._1<b._1+L._1&&b._1<y._1+T._1&&y._2<b._2+L._2&&b._2<y._2+T._2})()?x+1|0:x;continue}f=J+1|0,h=x;continue}p=!1,m=x}return m};o=u+1|0,i=_(u+1|0)(c)}return a})(0)(0)},kf=t=>v(e=>n=>e+Qm(n.start)(n.end))(0)(t.segments),ex=t=>e=>n=>({crossingCount:v(r=>o=>r+o.jumps.length|0)(0)(e),bendCount:v(r=>o=>r+o.bends.length|0)(0)(e),totalEdgeLength:v(r=>o=>r+kf(o))(0)(e),maxEdgeLength:v(r=>o=>Zy(r)(kf(o)))(0)(e),nodeOverlapCount:tx(t),constraintViolations:n,jumpCount:v(r=>o=>r+o.jumps.length|0)(0)(e)}),ac=t=>t,ue=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 s=ot.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},uc=ac("LEFT"),nx=ac("RIGHT"),Lf=ac("UNDEFINED"),rx={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},ox={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?Ye:De;if(e==="LEFT")return Ie;if(t==="RIGHT")return e==="RIGHT"?Ye:De;if(e==="RIGHT")return Ie;if(t==="UP")return e==="UP"?Ye:De;if(e==="UP")return Ie;if(t==="DOWN")return e==="DOWN"?Ye:De;if(e==="DOWN")return Ie;if(t==="UNDEFINED"&&e==="UNDEFINED")return Ye;g()},Eq0:()=>rx},ix=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},sx={x:0,y:0},mn=t=>e=>n=>{const r=ue(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:rt(ot)(t)(e(r._1))(n.cNodes)};g()},Qi=t=>e=>n=>{const r=ue(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:rt(ot)(t)(e(r._1))(n.cGroups)};g()},ax=t=>v(e=>n=>mn(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),ux=t=>{const e=v(n=>r=>{const o=ue(r)(t.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just")return v(i=>s=>Ft(ot)(he)(s)([r])(i))(n)(o._1.constraints);g()})(R)(t.cNodeOrder);return v(n=>r=>mn(r)(o=>({...o,constraints:(()=>{const i=ue(r)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;g()})()}))(n))(t)(t.cNodeOrder)},cx=t=>e=>mn(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}})),gx=t=>{const e=v(n=>r=>Qi(r)(o=>({...o,outDegree:o.outDegreeReal}))(n))(t)(t.cGroupOrder);return v(n=>r=>mn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder)},Qn={left:!1,right:!1,up:!1,down:!1},_x={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},cc=t=>v(e=>n=>{const r=ue(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const o=v(s=>a=>{const u=ue(a)(e.cNodes);if(u.tag==="Nothing")return s;if(u.tag==="Just"){if(s.tag==="Nothing")return N("Just",a);if(s.tag==="Just"){const c=ue(s._1)(e.cNodes);if(c.tag==="Nothing")return N("Just",a);if(c.tag==="Just")return u._1.hitbox.x<c._1.hitbox.x?N("Just",a):N("Just",s._1)}}g()})(w)(r._1.cNodes),i=Qi(n)(s=>({...s,reference:o}))(e);if(o.tag==="Nothing")return i;if(o.tag==="Just"){const s=ue(o._1)(i.cNodes);if(s.tag==="Nothing")return i;if(s.tag==="Just"){const a=s._1;return v(u=>c=>mn(c)(_=>({..._,cGroupOffset:{x:_.hitbox.x-a.hitbox.x,y:_.hitbox.y-a.hitbox.y}}))(u))(i)(r._1.cNodes)}}}g()})(t)(t.cGroupOrder),yn=t=>cc({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return R;if(n.tag==="Node")return te("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)})()}),or=t=>cc({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return R;if(n.tag==="Node")return te("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)})()}),Sf=t=>{const e=v(n=>r=>Qi(r)(o=>({...o,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return v(n=>r=>{const o=ue(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 v(s=>a=>{const u=ue(a)(s.cNodes);if(u.tag==="Nothing")return s;if(u.tag==="Just")return u._1.cGroup.tag==="Just"&&u._1.cGroup._1!==i?Qi(u._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(Qi(i)(c=>tn(Rr)(a)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,a]})(s)):s;g()})(n)(o._1.constraints)}}g()})(e)(e.cNodeOrder)},$s=t=>{const e=ux(t.cGraph);return{...t,cGraph:Sf(v(n=>r=>mn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},fx=t=>e=>v(n=>r=>{if(t==="LEFT"||t==="UP"){const i=r._2;return mn(r._1)(s=>({...s,constraints:[...s.constraints,i]}))(n)}const o=r._1;return mn(r._2)(i=>({...i,constraints:[...i.constraints,o]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),Mn=t=>{const e={...t,cGraph:fx(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return R;if(r.tag==="Node")return te("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:Sf((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);g()})())}},dx=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?Mn(r):e==="RIGHT"?Mn({...r,cGraph:yn(r.cGraph)}):e==="UP"?Mn({...r,cGraph:or(r.cGraph)}):e==="DOWN"?Mn({...r,cGraph:yn(or(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?$s({...r,cGraph:yn(r.cGraph)}):e==="UP"?Mn({...r,cGraph:or(r.cGraph)}):e==="DOWN"?Mn({...r,cGraph:yn(or(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?$s({...r,cGraph:yn(r.cGraph)}):e==="UP"?Mn({...r,cGraph:or(yn(r.cGraph))}):e==="DOWN"?Mn({...r,cGraph:yn(or(yn(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?Mn({...r,cGraph:or(r.cGraph)}):e==="RIGHT"?Mn({...r,cGraph:yn(or(r.cGraph))}):e==="DOWN"?$s({...r,cGraph:yn(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?Mn({...r,cGraph:or(yn(r.cGraph))}):e==="RIGHT"?Mn({...r,cGraph:yn(or(yn(r.cGraph)))}):e==="UP"?$s({...r,cGraph:yn(r.cGraph)}):r;g()},Ef=t=>e=>e.finished||!ix(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:dx(e.direction)(t)(e),lx=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?Ef(uc)(t):t,n={...e,cGraph:gx(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},Gf=t=>e=>n=>{const r=ue(t)(n.cNodes),o=ue(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:rt(ot)(t)({...r._1,cGroup:N("Just",e)})(n.cNodes),cGroups:rt(ot)(e)({...o._1,cNodes:tn(Rr)(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},Pf=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:rt(ot)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:w,cGroupOffset:sx,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:Qn})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),gc=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:v(r=>o=>Gf(o)(n)(r))({...e,cGroups:rt(ot)(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)}},hx=t=>v(e=>n=>{const r=ue(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?gc({master:w,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),px=t=>({cGraph:ax(hx(cc(t))),direction:Lf,compactionAlgorithm:w,constraintAlgorithm:w,spacingsHandler:_x,lockFun:w,finished:!1}),mx=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},yx=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?De:n==="GT"?Ie:ot.compare(t._2)(e._2)},xx=(()=>{const t=en.unfoldr(In);return e=>t(nn("IterNode",e,Dn))})(),Bf=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 s=ot.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Df=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",If=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),Vs=t=>e=>yx(C(t.hitbox.x+t.hitbox.width/2,t.id))(C(e.hitbox.x+e.hitbox.width/2,e.id)),wx=t=>e=>{const n=ro(Yt,w,r=>Vs(t)(r)==="LT",e);if(n.tag==="Just"){const r=l_(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 Pt(e)(t);g()},Af=t=>e=>{const n=ft(o=>Vs(o)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?N("Just",n[r]):w},Jx=t=>e=>{const n=wx(e)(t.intervals),r=re(i=>Vs(e)(i)==="LT")(n),o=rt(ot)(e.id)((()=>{const i=Af(e)(n);return i.tag==="Just"?N("Just",i._1.id):w})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return rt(ot)(r._1.id)(N("Just",e.id))(o);if(r.tag==="Nothing")return o;g()})()}},Nx=t=>e=>{const n=it.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?Ie:Ye:e.low?De:Ye:n},vx=t=>v(e=>n=>mn(n.id)(r=>({...r,constraints:[]}))(e))(t)(vt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),_c=t=>e=>v(n=>r=>{const o=ue(r._1)(n.cNodes);if(o.tag==="Just")return mn(r._1)(i=>({...i,constraints:[...i.constraints,...r._2]}))(n);if(o.tag==="Nothing")return n;g()})(e)(xx(t)),Rf=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}},Ff=t=>e=>n=>v(r=>o=>n(o)?mn(o.id)(Rf(t))(r):r)(e)(vt(r=>ue(r)(e.cNodes))(e.cNodeOrder)),Tx=t=>e=>{const n=(r,o,i)=>{const s=mn(i)(Rf(t))(r);return o.length<=1?s:v(a=>u=>u===i?a:mn(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)(a))(s)(o)};return v(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)(vt(r=>ue(r)(e.cGroups))(e.cGroupOrder))},bx=t=>e=>{const n=Af(e)(t.intervals),r=re(i=>Vs(e)(i)==="LT")(t.intervals),o=n.tag==="Just"&&(()=>{const i=Bf(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})()?Ft(ot)(he)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const i=Bf(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})()?Ft(ot)(he)(e.id)([r._1.id])(o):o,intervals:ft(i=>i.id!==e.id,t.intervals)}},Cx=t=>e=>e.low?Jx(t)(e.node):bx(t)(e.node),fc=t=>e=>v(Cx)({intervals:[],cand:R,constraints:R})(It(Nx)(St(ft(t,vt(n=>ue(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,kx=t=>e=>{const n=mx(0)(t/2-.5),r=_c(fc(Df)(Ff(n)(e)(Df)))(e),o=_c(fc(If)(Ff(n)(r)(If)))(r);return _c(fc(i=>!0)(Tx(n)(o)))(o)},Lx=t=>e=>kx(t)(vx(e.cGraph)),Xs=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Qf=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},dc=t=>e=>n=>r=>o=>({id:t,representedEdges:[o],affectedBends:[e,n],hitbox:{x:Xs(e._1)(n._1),y:Xs(e._2)(n._2),width:Pn(e._1-n._1),height:Pn(e._2-n._2)},ignoreSpacing:Qn,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:w}),Sx=t=>e=>{const n=Xs(t.hitbox.x)(e.hitbox.x),r=Xs(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:Qf(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Qf(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()})()}},Ex=t=>e=>Pn(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,Gx=t=>e=>Pn(t.hitbox.x-e.hitbox.x)<=1e-4?it.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?De:Ie,Mf=(t,e)=>({tag:t,_1:e}),lc=ce(P)(Mt),Ys=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},zf=(()=>{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 De;if(o==="GT")return Ie;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?Ye:De;if(r._2.tag==="Nothing")return Ie;if(n._2.tag==="Just"&&r._2.tag==="Just")return P.compare(n._2._1)(r._2._1);g()},Eq0:()=>t};return v(n=>r=>rt(e)(r)()(n))(R)})(),br=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Px=v(t=>e=>rt(ox)(e)()(t))(R),hc=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 s=z_.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Bx=t=>e=>{const n=lc($(i=>C(i.id,i))(t)),r=vt(i=>Ys(i)(n))(e),o=ot.compare((()=>{const i=zf($(s=>C(s.from.node,s.from.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;g()})())((()=>{const i=zf($(s=>C(s.to.node,s.to.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;g()})());if(o==="LT")return{...Qn,left:!0,right:!1};if(o==="GT")return{...Qn,left:!1,right:!0};if(o==="EQ")return Qn;g()},Dx=t=>vt(e=>{if(e.direction==="V")return N("Just",{start:e.start,end:e.end});if(e.direction==="H")return w;g()})(t.segments),Us=t=>e=>n=>r=>{if(r.tag==="Just"){const o=br(n)(e);if(o.tag==="Just"){const i=re(s=>s.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()},Ix=t=>e=>n=>{const r=Pf({origin:N("Just",Mf("SegmentOrigin",n)),kind:N("Just","vs"),hitbox:n.hitbox})(e.cGraph),o=cx(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const i=ue(n.potentialGroupParents[0])(o.cNodes);if(i.tag==="Just"){if(i._1.cGroup.tag==="Just")return Gf(r.id)(i._1.cGroup._1)(o);if(i._1.cGroup.tag==="Nothing")return o;g()}if(i.tag==="Nothing")return o;g()}return gc({master:N("Just",r.id),nodes:[r.id]})(o).graph})(),edgeToCs:v(i=>s=>Ft(P)(he)(s)([r.id])(i))(e.edgeToCs)(n.representedEdges),lockMap:rt(ot)(r.id)(Bx(t)(n.representedEdges))(e.lockMap)}},Ax=t=>e=>n=>{const r=zt(o=>w,o=>i=>N("Just",{head:o,tail:i}),It(Gx)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const o=v(i=>s=>Ex(i.survivor)(s)?{...i,survivor:Sx(i.survivor)(s)}:{survivor:s,merged:[...i.merged,i.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return v(Ix(t))(n)([...o.merged,o.survivor])}g()},Rx=t=>({cGraph:{cNodes:R,cNodeOrder:[],cGroups:R,cGroupOrder:[],supportedDirections:Px([Lf,uc,nx]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:R,edgeToCs:R,lockMap:R}),Fx=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}},Qx=t=>e=>n=>v(r=>o=>{const i=Pf({origin:N("Just",Mf("NodeOrigin",o.node)),kind:w,hitbox:Fx(o)})(r.cGraph),s=br(o.node)(t),a=(()=>{if(s.tag==="Nothing")return C(0,0);if(s.tag==="Just")return s._1;g()})();return{...r,cGraph:gc({master:N("Just",i.id),nodes:[i.id]})(i.graph).graph,nodeToC:rt(P)(o.node)(i.id)(r.nodeToC),lockMap:rt(ot)(i.id)((()=>{const u=a._1-a._2|0;return u<0?{...Qn,left:!0}:u>0?{...Qn,right:!0}:Qn})())(r.lockMap)}})(n)(e),Mx=t=>v(e=>n=>Ft(P)(r=>o=>C(r._1+o._1|0,r._2+o._2|0))(n.to.node)(C(1,0))(Ft(P)(r=>o=>C(r._1+o._1|0,r._2+o._2|0))(n.from.node)(C(0,1))(e)))(R)(t),zx=t=>v(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?rt(P)(n.origin._1._1)(n.hitbox.x)(e):e)(R)(vt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),Wx=t=>v(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?rt(P)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(R)(vt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),qx=t=>v(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return v(o=>i=>rt(z_)(i)(r)(o))(e)(n.origin._1._1.affectedBends)}return e})(R)(vt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),Wf=t=>{const e=lc($(n=>C(n.id,n))(t.edges));return vt(n=>{const r=Ys(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:Us(Nr)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:Us(vr)(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:Us(Nr)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:Us(vr)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return w;g()})(t.paths)},Ox=t=>e=>{const n=St(e)(r=>{if(r.src===r.tgt)return[];if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return[];const o=br(r.tgt)(t.nodeToC),i=(()=>{if(o.tag==="Just")return ue(o._1)(t.cGraph.cNodes);if(o.tag==="Nothing")return w;g()})(),s=br(r.src)(t.nodeToC),a=(()=>{if(s.tag==="Just")return ue(s._1)(t.cGraph.cNodes);if(s.tag==="Nothing")return w;g()})(),u=(()=>{if(a.tag==="Just"){if(i.tag==="Just"){if(a._1.cGroup.tag==="Just"){if(i._1.cGroup.tag==="Just")return N("Just",{srcGroup:a._1.cGroup._1,tgtGroup:i._1.cGroup._1,delta:0,weight:100});if(i._1.cGroup.tag==="Nothing")return w;g()}if(a._1.cGroup.tag==="Nothing")return w;g()}if(i.tag==="Nothing")return w;g()}if(a.tag==="Nothing")return w;g()})(),c=f=>h=>p=>{if(a.tag==="Just"){if(a._1.cGroup.tag==="Just"){if(p.cGroup.tag==="Just")return f(p.hitbox.x)&&p.cGroup._1!==a._1.cGroup._1?N("Just",h(p.cGroup._1)(a._1.cGroup._1)):w;if(p.cGroup.tag==="Nothing")return w;g()}if(a._1.cGroup.tag==="Nothing")return w;g()}if(a.tag==="Nothing")return w;g()},_=vt(f=>ue(f)(t.cGraph.cNodes))((()=>{const f=Ys(r.edgeId)(t.edgeToCs);if(f.tag==="Nothing")return[];if(f.tag==="Just")return f._1;g()})()),d=(()=>{if(a.tag==="Just"&&r.srcSide==="West"){const f=a._1;return vt(c(h=>h<f.hitbox.x)(h=>p=>({srcGroup:h,tgtGroup:p,delta:1,weight:100})))(_)}return[]})(),l=(()=>{if(a.tag==="Just"&&r.tgtSide==="East"){const f=a._1;return vt(c(h=>h>f.hitbox.x)(h=>p=>({srcGroup:p,tgtGroup:h,delta:1,weight:100})))(_)}return[]})();if(u.tag==="Nothing")return[];if(u.tag==="Just")return[u._1,...d,...l];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(s=>tn(Zn)(s)(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}},Hx=t=>e=>{const n=nt(4),r=zx(t),o=Wx(t),i=lc($(a=>C(a.id,C(a.from.node,a.to.node)))(e.edges)),s=qx(t);return{nodes:$(a=>{const u=br(a.node)(r);if(u.tag==="Just")return{...a,position:C(u._1/n,a.position._2)};if(u.tag==="Nothing")return a;g()})(e.nodes),edges:$(a=>{const u=Ys(a.edge)(i),c=(()=>{if(u.tag==="Nothing")return a.segments;if(u.tag==="Just"){const _=br(u._1._1)(o),d=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;g()})(),l=br(u._1._2)(o),f=(()=>{if(l.tag==="Nothing")return 0;if(l.tag==="Just")return l._1;g()})();return Ht((()=>{const h=a.reversed?f:d,p=a.reversed?d:f,m=a.segments.length;return J=>x=>{if(x.direction==="V"){const y=(()=>{if(J===0)return h;if(J===(m-1|0))return p;const T=hc(x.start)(s);if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})();return{...x,start:C(x.start._1+y,x.start._2),end:C(x.end._1+y,x.end._2)}}if(x.direction==="H")return{...x,start:C((()=>{if(J===0)return x.start._1+h;const y=hc(x.start)(s);if(y.tag==="Nothing")return x.start._1+0;if(y.tag==="Just")return x.start._1+y._1;g()})(),x.start._2),end:C((()=>{if(J===(m-1|0))return x.end._1+p;const y=hc(x.end)(s);if(y.tag==="Nothing")return x.end._1+0;if(y.tag==="Just")return x.end._1+y._1;g()})(),x.end._2)};g()}})())(a.segments)}g()})();return{...a,segments:c,bends:Qe(_=>d=>_.end,c,Dt(1,c.length,c))}})(e.paths)}},$x=t=>e=>n=>r=>o=>i=>{const s=dc(o.nextId)(i._2.start)(i._2.end)(w)(t.edgeId),a=(()=>{if(i._1===0){if(e.tag==="Nothing")return s;if(e.tag==="Just")return{...s,ignoreSpacing:i._2.end._2<e._1.y?{...s.ignoreSpacing,down:!0}:i._2.end._2>e._1.y+e._1.height?{...s.ignoreSpacing,up:!0}:{...s.ignoreSpacing,up:!0,down:!0}};g()}return s})();return{nextId:o.nextId+1|0,segments:[...o.segments,(()=>{if(i._1===r){if(n.tag==="Nothing")return a;if(n.tag==="Just")return{...a,ignoreSpacing:i._2.start._2<n._1.y?{...a.ignoreSpacing,down:!0}:i._2.start._2>n._1.y+n._1.height?{...a.ignoreSpacing,up:!0}:{...a.ignoreSpacing,up:!0,down:!0}};g()}return a})()]}},qf=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...dc(i.nextId)(r.start)(C(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?{...Qn,down:!0}:{...Qn,up:!0}}]}),Ks=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...dc(i.nextId)(r.end)(C(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?{...Qn,down:!0}:{...Qn,up:!0}}]}),Vx=t=>e=>n=>{if(n.src===n.tgt)return e;const r=br(n.src)(t.nodeToC),o=br(n.tgt)(t.nodeToC),i=(()=>{if(r.tag==="Just"){const _=ue(r._1)(t.cGraph.cNodes);return _.tag==="Just"?N("Just",_._1.hitbox):w}if(r.tag==="Nothing")return w;g()})(),s=(()=>{if(o.tag==="Just"){const _=ue(o._1)(t.cGraph.cNodes);return _.tag==="Just"?N("Just",_._1.hitbox):w}if(o.tag==="Nothing")return w;g()})(),a=Dx(n.path),u=v($x(n)(i)(s)(a.length-1|0))(e)(Ht(_=>d=>C(_,d))(a));if(0<a.length){const _=(()=>{if(r.tag==="Just"&&i.tag==="Just"){if(n.srcSide==="North")return qf(n)(r._1)(i._1)(a[0])({side:Le,down:!0})(u);if(n.srcSide==="South")return qf(n)(r._1)(i._1)(a[0])({side:Se,down:!1})(u)}return u})(),d=a.length-1|0;if(d>=0&&d<a.length&&o.tag==="Just"&&s.tag==="Just"){if(n.tgtSide==="North")return Ks(n)(o._1)(s._1)(a[d])({side:Le,down:!0})(_);if(n.tgtSide==="South")return Ks(n)(o._1)(s._1)(a[d])({side:Se,down:!1})(_)}return _}const c=a.length-1|0;if(c>=0&&c<a.length&&o.tag==="Just"&&s.tag==="Just"){if(n.tgtSide==="North")return Ks(n)(o._1)(s._1)(a[c])({side:Le,down:!0})(u);if(n.tgtSide==="South")return Ks(n)(o._1)(s._1)(a[c])({side:Se,down:!1})(u)}return u},Xx=t=>e=>n=>Ax(t)(v(Vx(n))({nextId:0,segments:[]})(e).segments)(n),Yx=t=>Xx(t.edges)(Wf(t))(Qx(Mx(t.edges))(t.nodes)(Rx())),Cr=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 s=ot.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},pc=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},mc=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 s=ot.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Ux=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Kx=t=>{const e=t.Eq0();return n=>r=>{const o=a=>{let u=a,c=!0,_;for(;c;){const d=u,l=zt(f=>w,f=>h=>N("Just",{head:f,tail:h}),d.queue);if(l.tag==="Nothing"){c=!1,_=d;continue}if(l.tag==="Just"){const f=l._1.head;if((p=>{let m=p,J=!0,x;for(;J;){const y=m;if(y.tag==="Leaf"){J=!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"){J=!1,x=!0;continue}}g()}return x})(d.removedNodes)){u={...d,queue:l._1.tail};continue}const h=re(p=>!Cr(p.eid)(d.removedEdges)&&(e.eq(p.src)(f)||e.eq(p.tgt)(f)))(r);if(h.tag==="Nothing"){u={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const p=e.eq(h._1.src)(f)?h._1.tgt:h._1.src,m={...d,degree:rt(t)(p)((()=>{const J=(x=>{let y=x,T=!0,b;for(;T;){const L=y;if(L.tag==="Leaf"){T=!1,b=w;continue}if(L.tag==="Node"){const E=t.compare(p)(L._3);if(E==="LT"){y=L._5;continue}if(E==="GT"){y=L._6;continue}if(E==="EQ"){T=!1,b=N("Just",L._4);continue}}g()}return b})(d.degree);if(J.tag==="Nothing")return-1;if(J.tag==="Just")return J._1-1|0;g()})())(d.degree),removedNodes:rt(t)(f)()(d.removedNodes),removedEdges:rt(ot)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:f,neighbour:p,viaSrc:e.eq(h._1.src)(f)}],queue:l._1.tail};if((()=>{const J=(y=>{let T=y,b=!0,L;for(;b;){const E=T;if(E.tag==="Leaf"){b=!1,L=w;continue}if(E.tag==="Node"){const B=t.compare(p)(E._3);if(B==="LT"){T=E._5;continue}if(B==="GT"){T=E._6;continue}if(B==="EQ"){b=!1,L=N("Just",E._4);continue}}g()}return L})(m.degree),x=y=>{let T=y,b=!0,L;for(;b;){const E=T;if(E.tag==="Leaf"){b=!1,L=!1;continue}if(E.tag==="Node"){const B=t.compare(p)(E._3);if(B==="LT"){T=E._5;continue}if(B==="GT"){T=E._6;continue}if(B==="EQ"){b=!1,L=!0;continue}}g()}return L};return(()=>{if(J.tag==="Nothing")return!1;if(J.tag==="Just")return J._1===1;g()})()&&!x(m.removedNodes)})()){u={...m,queue:[...m.queue,p]};continue}u=m;continue}}g()}return _},i=v(a=>u=>Ft(t)(xe)(u.src)(1)(Ft(t)(xe)(u.tgt)(1)(a)))(R)(r),s=o({degree:i,removedNodes:R,removedEdges:R,record:[],queue:ft(a=>{const u=(c=>{let _=c,d=!0,l;for(;d;){const f=_;if(f.tag==="Leaf"){d=!1,l=w;continue}if(f.tag==="Node"){const h=t.compare(a)(f._3);if(h==="LT"){_=f._5;continue}if(h==="GT"){_=f._6;continue}if(h==="EQ"){d=!1,l=N("Just",f._4);continue}}g()}return l})(i);if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1===1;g()},n)});return{coreNodes:ft(a=>!(u=>{let c=u,_=!0,d;for(;_;){const l=c;if(l.tag==="Leaf"){_=!1,d=!1;continue}if(l.tag==="Node"){const f=t.compare(a)(l._3);if(f==="LT"){c=l._5;continue}if(f==="GT"){c=l._6;continue}if(f==="EQ"){_=!1,d=!0;continue}}g()}return d})(s.removedNodes),n),coreEdges:ft(a=>!Cr(a.eid)(s.removedEdges),r),removed:s.record}}},jx=t=>e=>n=>v(r=>o=>{const i=o.neighbour,s=(()=>{const a=(u=>{let c=u,_=!0,d;for(;_;){const l=c;if(l.tag==="Leaf"){_=!1,d=w;continue}if(l.tag==="Node"){const f=t.compare(i)(l._3);if(f==="LT"){c=l._5;continue}if(f==="GT"){c=l._6;continue}if(f==="EQ"){_=!1,d=N("Just",l._4);continue}}g()}return d})(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})();return rt(t)(o.node)(o.viaSrc?s-1|0:s+1|0)(r)})(n)(se(e)),yc=t=>{const e=t.Eq0();return n=>r=>o=>{const i={...o,treeNode:rt(t)(r)()(o.treeNode)};return v(s=>a=>{if(Cr(a.eid)(s.st.edgeVisited))return s;const u={...s.st,edgeVisited:rt(ot)(a.eid)()(s.st.edgeVisited)},c=e.eq(a.src)((()=>{const _=a.src,d=f=>{let h=f,p=!0,m;for(;p;){const J=h;if(J.tag==="Leaf"){p=!1,m=!1;continue}if(J.tag==="Node"){const x=t.compare(_)(J._3);if(x==="LT"){h=J._5;continue}if(x==="GT"){h=J._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=a.tgt;return d(u.treeNode)&&!(f=>{let h=f,p=!0,m;for(;p;){const J=h;if(J.tag==="Leaf"){p=!1,m=!1;continue}if(J.tag==="Node"){const x=t.compare(l)(J._3);if(x==="LT"){h=J._5;continue}if(x==="GT"){h=J._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(u.treeNode)})()?a.src:(()=>{const _=a.tgt,d=f=>{let h=f,p=!0,m;for(;p;){const J=h;if(J.tag==="Leaf"){p=!1,m=!1;continue}if(J.tag==="Node"){const x=t.compare(_)(J._3);if(x==="LT"){h=J._5;continue}if(x==="GT"){h=J._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=a.src;return d(u.treeNode)&&!(f=>{let h=f,p=!0,m;for(;p;){const J=h;if(J.tag==="Leaf"){p=!1,m=!1;continue}if(J.tag==="Node"){const x=t.compare(l)(J._3);if(x==="LT"){h=J._5;continue}if(x==="GT"){h=J._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(u.treeNode)})()?a.tgt:a.src)?a.tgt:a.src;if(Cr(a.eid)(u.treeEdge)){if((d=>{let l=d,f=!0,h;for(;f;){const p=l;if(p.tag==="Leaf"){f=!1,h=!1;continue}if(p.tag==="Node"){const m=t.compare(c)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){f=!1,h=!0;continue}}g()}return h})(u.treeNode))return{...s,st:u};const _=yc(t)(n)(c)(u);return{count:s.count+_.count|0,st:_.st}}if((()=>{const _=l=>{let f=l,h=!0,p;for(;h;){const m=f;if(m.tag==="Leaf"){h=!1,p=!1;continue}if(m.tag==="Node"){const J=t.compare(c)(m._3);if(J==="LT"){f=m._5;continue}if(J==="GT"){f=m._6;continue}if(J==="EQ"){h=!1,p=!0;continue}}g()}return p},d=a.tgt;return!_(u.treeNode)&&(()=>{const l=(p=>{let m=p,J=!0,x;for(;J;){const y=m;if(y.tag==="Leaf"){J=!1,x=w;continue}if(y.tag==="Node"){const T=t.compare(d)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){J=!1,x=N("Just",y._4);continue}}g()}return x})(u.layer),f=a.src,h=(p=>{let m=p,J=!0,x;for(;J;){const y=m;if(y.tag==="Leaf"){J=!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"){J=!1,x=N("Just",y._4);continue}}g()}return x})(u.layer);if(l.tag==="Nothing"){if(h.tag==="Nothing")return a.delta===0;if(h.tag==="Just")return a.delta===-h._1;g()}if(l.tag==="Just"){if(h.tag==="Nothing")return a.delta===(l._1-0|0);if(h.tag==="Just")return a.delta===(l._1-h._1|0)}g()})()})()){const _=yc(t)(n)(c)({...u,treeEdge:rt(ot)(a.eid)()(u.treeEdge)});return{count:s.count+_.count|0,st:_.st}}return{...s,st:u}})({count:1,st:i})(ft(s=>(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!Cr(s.eid)(i.edgeVisited),n))}},js=t=>e=>n=>r=>{const o=r.src,i=(l=>{let f=l,h=!0,p;for(;h;){const m=f;if(m.tag==="Leaf"){h=!1,p=w;continue}if(m.tag==="Node"){const J=t.compare(o)(m._3);if(J==="LT"){f=m._5;continue}if(J==="GT"){f=m._6;continue}if(J==="EQ"){h=!1,p=N("Just",m._4);continue}}g()}return p})(e.poID),s=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})(),a=r.tgt,u=(l=>{let f=l,h=!0,p;for(;h;){const m=f;if(m.tag==="Leaf"){h=!1,p=w;continue}if(m.tag==="Node"){const J=t.compare(a)(m._3);if(J==="LT"){f=m._5;continue}if(J==="GT"){f=m._6;continue}if(J==="EQ"){h=!1,p=N("Just",m._4);continue}}g()}return p})(e.poID),c=(()=>{if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()})(),_=(l=>{let f=l,h=!0,p;for(;h;){const m=f;if(m.tag==="Leaf"){h=!1,p=w;continue}if(m.tag==="Node"){const J=t.compare(n)(m._3);if(J==="LT"){f=m._5;continue}if(J==="GT"){f=m._6;continue}if(J==="EQ"){h=!1,p=N("Just",m._4);continue}}g()}return p})(e.poID),d=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;g()})();return(()=>{const l=r.src,f=(h=>{let p=h,m=!0,J;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,J=w;continue}if(x.tag==="Node"){const y=t.compare(l)(x._3);if(y==="LT"){p=x._5;continue}if(y==="GT"){p=x._6;continue}if(y==="EQ"){m=!1,J=N("Just",x._4);continue}}g()}return J})(e.lowestPoID);return(()=>{if(f.tag==="Nothing")return 0<=d;if(f.tag==="Just")return f._1<=d;g()})()&&(()=>{const h=r.tgt;return d<=s&&(()=>{const p=(m=>{let J=m,x=!0,y;for(;x;){const T=J;if(T.tag==="Leaf"){x=!1,y=w;continue}if(T.tag==="Node"){const b=t.compare(h)(T._3);if(b==="LT"){J=T._5;continue}if(b==="GT"){J=T._6;continue}if(b==="EQ"){x=!1,y=N("Just",T._4);continue}}g()}return y})(e.lowestPoID);return(()=>{if(p.tag==="Nothing")return 0<=d;if(p.tag==="Just")return p._1<=d;g()})()&&d<=c})()})()})()?s>=c:s<c},Zx=t=>{const e=ce(t)(Mt);return n=>({layer:e($(r=>C(r,0))(n)),treeNode:R,treeEdge:R,poID:R,lowestPoID:R,cutvalue:R,postOrder:1,edgeVisited:R})},tw=t=>e=>n=>v(r=>o=>{if((()=>{const _=o.src,d=h=>{let p=h,m=!0,J;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,J=!1;continue}if(x.tag==="Node"){const y=t.compare(_)(x._3);if(y==="LT"){p=x._5;continue}if(y==="GT"){p=x._6;continue}if(y==="EQ"){m=!1,J=!0;continue}}g()}return J},l=o.tgt,f=h=>{let p=h,m=!0,J;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,J=!1;continue}if(x.tag==="Node"){const y=t.compare(l)(x._3);if(y==="LT"){p=x._5;continue}if(y==="GT"){p=x._6;continue}if(y==="EQ"){m=!1,J=!0;continue}}g()}return J};return d(n.treeNode)===f(n.treeNode)})())return r;const i=o.tgt,s=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=w;continue}if(h.tag==="Node"){const p=t.compare(i)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(n.layer),a=o.src,u=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=w;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(n.layer),c=(()=>{if(s.tag==="Nothing"){if(u.tag==="Nothing")return-o.delta;if(u.tag==="Just")return-u._1-o.delta|0;g()}if(s.tag==="Just"){if(u.tag==="Nothing")return(s._1-0|0)-o.delta|0;if(u.tag==="Just")return(s._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,ew=t=>{const e=ce(t)(Mt);return n=>r=>{const o=v(i=>s=>pc(i)((()=>{const a=(u=>{let c=u,_=!0,d;for(;_;){const l=c;if(l.tag==="Leaf"){_=!1,d=w;continue}if(l.tag==="Node"){const f=t.compare(s)(l._3);if(f==="LT"){c=l._5;continue}if(f==="GT"){c=l._6;continue}if(f==="EQ"){_=!1,d=N("Just",l._4);continue}}g()}return d})(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})()))(1e9)(n);return e($(i=>C(i,(()=>{const s=(a=>{let u=a,c=!0,_;for(;c;){const d=u;if(d.tag==="Leaf"){c=!1,_=w;continue}if(d.tag==="Node"){const l=t.compare(i)(d._3);if(l==="LT"){u=d._5;continue}if(l==="GT"){u=d._6;continue}if(l==="EQ"){c=!1,_=N("Just",d._4);continue}}g()}return _})(r);if(s.tag==="Nothing")return-o;if(s.tag==="Just")return s._1-o|0;g()})()))(n))}},Of=t=>{const e=t.Eq0();return n=>r=>o=>{const i=v(a=>u=>{const c=Of(t)(n)(e.eq(u.src)(r)?u.tgt:u.src)({...a.st,edgeVisited:rt(ot)(u.eid)()(a.st.edgeVisited)});return{lowest:pc(a.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:o})(ft(a=>Cr(a.eid)(o.treeEdge)&&(e.eq(a.src)(r)||e.eq(a.tgt)(r))&&!Cr(a.eid)(o.edgeVisited),n)),s=pc(i.lowest)(i.st.postOrder);return{lowest:s,st:{...i.st,poID:rt(t)(r)(i.st.postOrder)(i.st.poID),lowestPoID:rt(t)(r)(s)(i.st.lowestPoID),postOrder:i.st.postOrder+1|0}}}},Hf=t=>{const e=Of(t);return n=>r=>o=>0<n.length?e(r)(n[0])({...o,edgeVisited:R,postOrder:1,poID:R,lowestPoID:R}).st:o},nw=t=>{const e=t.Eq0();return n=>r=>o=>ft(i=>Cr(i.eid)(r.treeEdge)&&(e.eq(i.src)(o)||e.eq(i.tgt)(o)),n)},rw=t=>e=>re(n=>{const r=mc(n.eid)(e.cutvalue);return Cr(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),$f=t=>{const e=yc(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 s=e(r)(i._1)({...o,edgeVisited:R,treeNode:R,treeEdge:R});if(s.count>=n.length)return s.st;const a=tw(t)(r)(s.st);if(a.tag==="Nothing")return s.st;if(a.tag==="Just"){const u=a._1.tgt,c=(h=>{let p=h,m=!0,J;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,J=w;continue}if(x.tag==="Node"){const y=t.compare(u)(x._3);if(y==="LT"){p=x._5;continue}if(y==="GT"){p=x._6;continue}if(y==="EQ"){m=!1,J=N("Just",x._4);continue}}g()}return J})(s.st.layer),_=a._1.src,d=(h=>{let p=h,m=!0,J;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,J=w;continue}if(x.tag==="Node"){const y=t.compare(_)(x._3);if(y==="LT"){p=x._5;continue}if(y==="GT"){p=x._6;continue}if(y==="EQ"){m=!1,J=N("Just",x._4);continue}}g()}return J})(s.st.layer),l=(()=>{if(c.tag==="Nothing"){if(d.tag==="Nothing")return-a._1.delta;if(d.tag==="Just")return-d._1-a._1.delta|0;g()}if(c.tag==="Just"){if(d.tag==="Nothing")return(c._1-0|0)-a._1.delta|0;if(d.tag==="Just")return(c._1-d._1|0)-a._1.delta|0}g()})(),f=(()=>{const h=a._1.tgt;return(p=>{let m=p,J=!0,x;for(;J;){const y=m;if(y.tag==="Leaf"){J=!1,x=!1;continue}if(y.tag==="Node"){const T=t.compare(h)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){J=!1,x=!0;continue}}g()}return x})(s.st.treeNode)})()?-l:l;return $f(t)(n)(r)({...s.st,layer:v(h=>p=>(m=>{let J=m,x=!0,y;for(;x;){const T=J;if(T.tag==="Leaf"){x=!1,y=!1;continue}if(T.tag==="Node"){const b=t.compare(p)(T._3);if(b==="LT"){J=T._5;continue}if(b==="GT"){J=T._6;continue}if(b==="EQ"){x=!1,y=!0;continue}}g()}return y})(s.st.treeNode)?rt(t)(p)((()=>{const m=(J=>{let x=J,y=!0,T;for(;y;){const b=x;if(b.tag==="Leaf"){y=!1,T=w;continue}if(b.tag==="Node"){const L=t.compare(p)(b._3);if(L==="LT"){x=b._5;continue}if(L==="GT"){x=b._6;continue}if(L==="EQ"){y=!1,T=N("Just",b._4);continue}}g()}return T})(s.st.layer);if(m.tag==="Nothing")return 0+f|0;if(m.tag==="Just")return m._1+f|0;g()})())(h):h)(s.st.layer)(n)})}}g()}},ow=t=>e=>n=>r=>v(o=>i=>{if(js(t)(r)(i.src)(n)&&!js(t)(r)(i.tgt)(n)){const s=i.tgt,a=(d=>{let l=d,f=!0,h;for(;f;){const p=l;if(p.tag==="Leaf"){f=!1,h=w;continue}if(p.tag==="Node"){const m=t.compare(s)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){f=!1,h=N("Just",p._4);continue}}g()}return h})(r.layer),u=i.src,c=(d=>{let l=d,f=!0,h;for(;f;){const p=l;if(p.tag==="Leaf"){f=!1,h=w;continue}if(p.tag==="Node"){const m=t.compare(u)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){f=!1,h=N("Just",p._4);continue}}g()}return h})(r.layer),_=(()=>{if(a.tag==="Nothing"){if(c.tag==="Nothing")return-i.delta;if(c.tag==="Just")return-c._1-i.delta|0;g()}if(a.tag==="Just"){if(c.tag==="Nothing")return(a._1-0|0)-i.delta|0;if(c.tag==="Just")return(a._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,iw=t=>{const e=t.Eq0();return n=>r=>o=>i=>{const s=i.tgt,a=i.src;return v(u=>c=>{if((()=>{const _=mc(c.eid)(r.cutvalue);if(_.tag==="Just")return!0;if(_.tag==="Nothing")return!1;g()})()){const _=mc(c.eid)(r.cutvalue),d=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;g()})();return e.eq(a)(c.src)||e.eq(s)(c.tgt)?u-(d-c.weight):u+(d-c.weight)}return e.eq(o)(a)?e.eq(c.src)(o)?u+c.weight:u-c.weight:e.eq(c.src)(o)?u-c.weight:u+c.weight})(i.weight)(ft(u=>u.eid!==i.eid&&(e.eq(u.src)(o)||e.eq(u.tgt)(o)),n))}},sw=t=>{const e=iw(t);return n=>r=>o=>{const i=(s,a,u)=>{const c=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=w;continue}if(h.tag==="Node"){const p=t.compare(s)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(u);if(c.tag==="Just")return rt(t)(s)(ft(_=>_.eid!==a.eid,c._1))(u);if(c.tag==="Nothing")return u;g()};return(s=>a=>{let u=s,c=a,_=!0,d;for(;_;){const l=u,f=c,h=(m=>{let J=m,x=!0,y;for(;x;){const T=J;if(T.tag==="Leaf"){x=!1,y=w;continue}if(T.tag==="Node"){const b=t.compare(f)(T._3);if(b==="LT"){J=T._5;continue}if(b==="GT"){J=T._6;continue}if(b==="EQ"){x=!1,y=N("Just",T._4);continue}}g()}return y})(l.unknown),p=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;g()})();if(p.length===1){const m=t.Eq0().eq(p[0].src)(f)?p[0].tgt:p[0].src;u={unknown:i(f,p[0],i(m,p[0],l.unknown)),cutvalue:rt(ot)(p[0].eid)(e(n)(l)(f)(p[0]))(l.cutvalue)},c=m;continue}_=!1,d=l}return d})(r)(o)}},Vf=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 d=ot.compare(c.delta)(_.delta);if(d==="LT"||d==="GT"||d!=="EQ")return d;const l=ot.compare(c.eid)(_.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const f=t.compare(c.src)(_.src);if(f==="LT"||f==="GT"||f!=="EQ")return f;const h=t.compare(c.tgt)(_.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const p=it.compare(c.weight)(_.weight);return p==="LT"||p==="GT"||p!=="EQ"?p:Ye},Eq0:()=>r},i=v(c=>_=>rt(o)(_)()(c))(R),s=nw(t),a=ce(t)(Mt),u=sw(t);return c=>_=>d=>{const l={unknown:a($(f=>C(f,jt(rn.foldr,i(s(_)(d)(f)))))(c)),cutvalue:R};return{...d,cutvalue:v(u(_))(l)(ft(f=>{const h=(p=>{let m=p,J=!0,x;for(;J;){const y=m;if(y.tag==="Leaf"){J=!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"){J=!1,x=N("Just",y._4);continue}}g()}return x})(l.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;g()},c)).cutvalue}}},aw=t=>{const e=Hf(t),n=Vf(t);return r=>o=>i=>s=>a=>{const u={...a,treeEdge:rt(ot)(s.eid)()(zo(ot)(i.eid)(a.treeEdge))},c=s.tgt,_=(p=>{let m=p,J=!0,x;for(;J;){const y=m;if(y.tag==="Leaf"){J=!1,x=w;continue}if(y.tag==="Node"){const T=t.compare(c)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){J=!1,x=N("Just",y._4);continue}}g()}return x})(u.layer),d=s.src,l=(p=>{let m=p,J=!0,x;for(;J;){const y=m;if(y.tag==="Leaf"){J=!1,x=w;continue}if(y.tag==="Node"){const T=t.compare(d)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){J=!1,x=N("Just",y._4);continue}}g()}return x})(u.layer),f=(()=>{if(_.tag==="Nothing"){if(l.tag==="Nothing")return-s.delta;if(l.tag==="Just")return-l._1-s.delta|0;g()}if(_.tag==="Just"){if(l.tag==="Nothing")return(_._1-0|0)-s.delta|0;if(l.tag==="Just")return(_._1-l._1|0)-s.delta|0}g()})(),h=js(t)(u)(s.tgt)(i)?f:-f;return n(r)(o)(e(r)(o)({...u,layer:v(p=>m=>js(t)(u)(m)(i)?p:rt(t)(m)((()=>{const J=(x=>{let y=x,T=!0,b;for(;T;){const L=y;if(L.tag==="Leaf"){T=!1,b=w;continue}if(L.tag==="Node"){const E=t.compare(m)(L._3);if(E==="LT"){y=L._5;continue}if(E==="GT"){y=L._6;continue}if(E==="EQ"){T=!1,b=N("Just",L._4);continue}}g()}return b})(u.layer);if(J.tag==="Nothing")return 0+h|0;if(J.tag==="Just")return J._1+h|0;g()})())(p))(u.layer)(r)}))}},uw=t=>{const e=aw(t);return n=>r=>o=>i=>(s=>a=>{let u=s,c=a,_=!0,d;for(;_;){const l=u,f=c;if(l===0){_=!1,d=f;continue}const h=rw(o)(f);if(h.tag==="Nothing"){_=!1,d=f;continue}if(h.tag==="Just"){const p=ow(t)(o)(h._1)(f);if(p.tag==="Nothing"){_=!1,d=f;continue}if(p.tag==="Just"){u=l-1|0,c=e(r)(o)(h._1)(p._1)(f);continue}}g()}return d})(n)(i)},cw=t=>{const e=Vf(t),n=Hf(t),r=$f(t);return o=>i=>s=>e(o)(i)(n(o)(i)(r(o)(i)(s)))},Xf=t=>e=>v(n=>r=>Ft(t)(he)(e(r))([r])(n))(R),gw=t=>{const e=ce(t)(Mt);return n=>r=>o=>{const i=u=>c=>_=>d=>{let l=u,f=c,h=_,p=d,m=!0,J;for(;m;){const x=l,y=f,T=h,b=p,L=zt(E=>w,E=>B=>N("Just",{head:E,tail:B}),T);if(L.tag==="Nothing"){m=!1,J=b;continue}if(L.tag==="Just"){const E=L._1.head,B=(I=>{let A=I,j=!0,Z;for(;j;){const M=A;if(M.tag==="Leaf"){j=!1,Z=w;continue}if(M.tag==="Node"){const W=t.compare(E)(M._3);if(W==="LT"){A=M._5;continue}if(W==="GT"){A=M._6;continue}if(W==="EQ"){j=!1,Z=N("Just",M._4);continue}}g()}return Z})(b.layer),z=(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})(),U=v(I=>A=>{const j=A.tgt,Z=(W=>{let O=W,D=!0,F;for(;D;){const S=O;if(S.tag==="Leaf"){D=!1,F=w;continue}if(S.tag==="Node"){const G=t.compare(j)(S._3);if(G==="LT"){O=S._5;continue}if(G==="GT"){O=S._6;continue}if(G==="EQ"){D=!1,F=N("Just",S._4);continue}}g()}return F})(I.incident),M=(()=>{if(Z.tag==="Nothing")return-1;if(Z.tag==="Just")return Z._1-1|0;g()})();return{st:{...I.st,layer:rt(t)(A.tgt)(Ux((()=>{const W=A.tgt,O=(D=>{let F=D,S=!0,G;for(;S;){const Q=F;if(Q.tag==="Leaf"){S=!1,G=w;continue}if(Q.tag==="Node"){const V=t.compare(W)(Q._3);if(V==="LT"){F=Q._5;continue}if(V==="GT"){F=Q._6;continue}if(V==="EQ"){S=!1,G=N("Just",Q._4);continue}}g()}return G})(I.st.layer);if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;g()})())(z+A.delta|0))(I.st.layer)},incident:rt(t)(A.tgt)(M)(I.incident),queue:M===0?[...I.queue,A.tgt]:I.queue}})({st:b,incident:y,queue:L._1.tail})((()=>{const I=(A=>{let j=A,Z=!0,M;for(;Z;){const W=j;if(W.tag==="Leaf"){Z=!1,M=w;continue}if(W.tag==="Node"){const O=t.compare(E)(W._3);if(O==="LT"){j=W._5;continue}if(O==="GT"){j=W._6;continue}if(O==="EQ"){Z=!1,M=N("Just",W._4);continue}}g()}return M})(x);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})());l=x,f=U.incident,h=U.queue,p=U.st;continue}g()}return J},s=Xf(t)(u=>u.tgt)(r),a=e($(u=>C(u,(()=>{const c=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=w;continue}if(h.tag==="Node"){const p=t.compare(u)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(s);if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1.length;g()})()))(n));return i(Xf(t)(u=>u.src)(r))(a)(ft(u=>{const c=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=w;continue}if(h.tag==="Node"){const p=t.compare(u)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(a);if(c.tag==="Nothing")return!0;if(c.tag==="Just")return c._1===0;g()},n))(o)}},_w=t=>{const e=Zx(t),n=gw(t),r=cw(t),o=uw(t);return i=>s=>{const a=n(i)(s)(e(i));return s.length===0?a.layer:o(4*i.length|0)(i)(s)(r(i)(s)(a)).layer}},Yf=t=>{const e=ew(t),n=_w(t),r=Kx(t);return o=>i=>{if(o.length===0)return R;if(o.length<40)return e(o)(n(o)(i));const s=r(o)(i);return e(o)(jx(t)(s.removed)(n(s.coreNodes)(s.coreEdges)))}},Uf=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 s=ot.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},xc=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fw=Yf(ot),Mi=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}),dw=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=nt((()=>{const o=Uf(n.cGroup._1)(t);if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})());return mn(n.id)(o=>({...o,hitbox:{...o.hitbox,x:r+o.cGroupOffset.x}}))(e)}g()},lw=t=>e=>({...e,cGraph:v(dw(t))(e.cGraph)((()=>{const n=e.cGraph;return vt(r=>ue(r)(n.cNodes))(n.cNodeOrder)})())}),hw=t=>e=>n=>r=>o=>{const i=de(xs(e.cGroupOffset.x-t.cGroupOffset.x));return Mi({src:o.nextNodeId,tgt:r,delta:xc(0)(-i),weight:1})(Mi({src:o.nextNodeId,tgt:n,delta:xc(0)(i),weight:1})({...o,nodes:[...o.nodes,o.nextNodeId],nextNodeId:o.nextNodeId+1|0}))},pw=t=>e=>n=>r=>o=>i=>s=>{const a=xc(0)(de(xs(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)?hw(n)(r)(o)(i)(s):Mi({src:o,tgt:i,delta:a,weight:t.vsLNodePair(n)(r)?2:1})(s)},mw=t=>e=>n=>r=>o=>{const i=ue(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"?pw(t)(e)(n)(i._1)(n.cGroup._1)(i._1.cGroup._1)(r):r;g()},yw=t=>e=>n=>r=>v(mw(t)(e)(r))(n)(r.constraints),xw=t=>e=>Mi({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),ww=t=>{const e=v(o=>i=>Ft(ot)(xe)(i.tgt)(1)(o))(R)(t.edges),n=ft(o=>{const i=Uf(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 v(o=>i=>Mi({src:r,tgt:i,delta:1,weight:0})(o))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},Jw=t=>e=>{const n=ww(v(xw)(v(yw(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return vt(o=>ue(o)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},Nw=t=>e=>{const n=Jw(t)(e);return lw(fw(n.nodes)(n.edges))(e)},Kf=t=>t,pe=Kf("H"),me=Kf("V"),vw=t=>C(t._2,t._1),jf=t=>({...t,position:C(t.position._2,t.position._1),size:C(t.size._2,t.size._1)}),Tw=t=>({start:C(t.start._2,t.start._1),end:C(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return me;if(t.direction==="V")return pe;g()})()}),Zf=t=>({...t,segments:$(Tw)(t.segments),bends:$(vw)(t.bends)}),bw=t=>({nodes:$(jf)(t.nodes),edges:t.edges,paths:$(Zf)(t.paths),ports:t.ports}),Cw={nodeNode:8,edgeNode:4,edgeEdge:10},kw=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}}),Lw=t=>e=>Nw(e),Sw=t=>e=>n=>{const r=bw(n),o=Yx(r),i=Ox(o)(Wf(r)),s=Hx(Ef(uc)(lx({...px(o.cGraph),compactionAlgorithm:N("Just",Lw()(i)),constraintAlgorithm:N("Just",Lx(e.edgeEdge)),spacingsHandler:kw(e)(i)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:$(jf)(s.nodes),edges:$(Zf)(s.edges)}},t1=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},e1=t=>Re(3)(t)==="$d:",Ew=t=>e=>n=>v(r=>o=>{const i=t1(o.from.node)(t),s=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})(),a=t1(o.to.node)(t),u=(()=>{if(a.tag==="Nothing")return-s;if(a.tag==="Just")return a._1-s|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,_=$(l=>"$d:"+c+":"+ie(l))(Kt(1,u-1|0)),d=[o.from.node,..._,o.to.node];return{...r,layers:v(l=>f=>{const h=f._2,p=D0(s+f._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;g()})(r.layers)(Qe(Gn,Kt(1,u-1|0),_)),edges:[...r.edges,...Qe(l=>f=>({id:c+":"+l+"->"+f,from:{node:l,port:o.from.port},to:{node:f,port:o.to.port},label:w}),d,Dt(1,d.length,d))],chains:[...r.chains,{edgeId:o.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),n1=t=>t,ei=ce(ot)(Mt),Xt=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 s=ot.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},r1=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jt=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Nt=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ni=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Gw=t=>e=>{const n=ot.compare(t._1)(e._1);return n==="LT"?De:n==="GT"?Ie:ot.compare(t._2)(e._2)},ri=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Pw=(()=>{const t=en.unfoldr(In);return e=>t(nn("IterNode",e,Dn))})(),Bw=t=>t,o1=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Dw=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Zs=n1("Regular"),ta=n1("Critical"),i1=t=>e=>{const n=v(s=>a=>rt(P)(a.node)(a)(s))(R)(e),r=1.25*nt(4),o=(s,a,u)=>(c=>_=>d=>{let l=c,f=_,h=d,p=!0,m;for(;p;){const J=l,x=f,y=h;if(y.critical){p=!1,m=y;continue}const T=zt(L=>w,L=>E=>N("Just",{head:L,tail:E}),J),b=zt(L=>w,L=>E=>N("Just",{head:L,tail:E}),x);if(T.tag==="Just"&&b.tag==="Just"){const L=T._1.head>b._1.head-s&&T._1.head<b._1.head+s?{...y,critical:!0}:T._1.head>b._1.head-r&&T._1.head<b._1.head+r?{...y,conflicts:y.conflicts+1|0}:y;if(L.critical){p=!1,m=L;continue}if(T._1.head<=b._1.head){l=T._1.tail,f=x,h=L;continue}l=J,f=b._1.tail,h=L;continue}p=!1,m=y}return m})(a)(u)({conflicts:0,critical:!1}),i=(s,a,u)=>{if(Nt(v(Nt)(-1e18)(a.incoming))(v(Nt)(-1e18)(a.outgoing))-Jt(v(Jt)(1e18)(a.incoming))(v(Jt)(1e18)(a.outgoing))<.001||Nt(v(Nt)(-1e18)(u.incoming))(v(Nt)(-1e18)(u.outgoing))-Jt(v(Jt)(1e18)(u.incoming))(v(Jt)(1e18)(u.outgoing))<.001)return[];const c=o(s,a.outgoing,u.incoming),_=o(s,u.outgoing,a.incoming);if(c.critical||_.critical)return[...c.critical?[{src:u.id,tgt:a.id,weight:1,kind:ta}]:[],..._.critical?[{src:a.id,tgt:u.id,weight:1,kind:ta}]:[]];const d=Jt(v(Jt)(1e18)(a.incoming))(v(Jt)(1e18)(a.outgoing)),l=Nt(v(Nt)(-1e18)(a.incoming))(v(Nt)(-1e18)(a.outgoing)),f=Jt(v(Jt)(1e18)(u.incoming))(v(Jt)(1e18)(u.outgoing)),h=Nt(v(Nt)(-1e18)(u.incoming))(v(Nt)(-1e18)(u.outgoing)),p=(1*c.conflicts|0)+(16*(v(J=>x=>x>h?J:x>=f?J+1|0:J)(0)(a.outgoing)+v(J=>x=>x>l?J:x>=d?J+1|0:J)(0)(u.incoming)|0)|0)|0,m=(1*_.conflicts|0)+(16*(v(J=>x=>x>l?J:x>=d?J+1|0:J)(0)(u.outgoing)+v(J=>x=>x>h?J:x>=f?J+1|0:J)(0)(a.incoming)|0)|0)|0;return p<m?[{src:a.id,tgt:u.id,weight:m-p|0,kind:Zs}]:p>m?[{src:u.id,tgt:a.id,weight:p-m|0,kind:Zs}]:p>0?[{src:a.id,tgt:u.id,weight:0,kind:Zs},{src:u.id,tgt:a.id,weight:0,kind:Zs}]:[]};return v(s=>a=>v(u=>c=>rt(P)(c._1)(c._2)(u))(s)((()=>{const u=v(I=>A=>{const j=A.edge.from.node+"|"+(()=>{if(A.edge.from.port.tag==="Just")return A.edge.from.port._1;if(A.edge.from.port.tag==="Nothing")return"_auto_"+A.edge.id;g()})(),Z=o1(j)(I.entries);if(Z.tag==="Nothing")return{...I,entries:rt(P)(j)({id:0,members:[A.edge.id],incoming:[A.fromPos._1],outgoing:[A.toPos._1],slot:0,mark:0,splitBy:w,splitPartner:w})(I.entries),order:[...I.order,j]};if(Z.tag==="Just")return{...I,entries:rt(P)(j)({...Z._1,members:[...Z._1.members,A.edge.id],incoming:[...tr(M=>M<A.fromPos._1)(Z._1.incoming).init,A.fromPos._1,...tr(M=>M<=A.fromPos._1)(Z._1.incoming).rest],outgoing:[...tr(M=>M<A.toPos._1)(Z._1.outgoing).init,A.toPos._1,...tr(M=>M<=A.toPos._1)(Z._1.outgoing).rest]})(I.entries)};g()})({entries:R,order:[]})(a._2),c=Ht(I=>A=>({...A,id:I}))(vt(I=>o1(I)(u.entries))(u.order));if(c.length===0)return[];const _=v(I=>A=>I.prev.tag==="Just"&&A-I.prev._1<1e-9?I:{prev:N("Just",A),out:[...I.out,A]})({prev:w,out:[]})(It(it.compare)([...St(c)(I=>I.incoming),...St(c)(I=>I.outgoing)])).out,d=_.length<2?.2*r:.2*v(I=>A=>{if(I.prev.tag==="Nothing")return{prev:N("Just",A),mn:I.mn};if(I.prev.tag==="Just")return{prev:N("Just",A),mn:Jt(I.mn)(A-I.prev._1)};g()})({prev:w,mn:1e18})(_).mn,l={segments:c,deps:(()=>{const I=c.length;return St(St(Kt(0,I-2|0))(A=>St(Kt(A+1|0,I-1|0))(j=>[C(A,j)])))(A=>A._1>=0&&A._1<c.length?A._2>=0&&A._2<c.length?i(d,c[A._1],c[A._2]):[]:[])})()},f=ft(I=>{if(I.kind==="Critical")return!0;if(I.kind==="Regular")return!1;g()},l.deps),h=(()=>{if(f.length<2)return l;const I=ei((()=>{const W=l.segments;return $(O=>C(O.id,O.mark))((()=>{const O=W.length,D=S=>{let G=S,Q=!0,V;for(;Q;){const Y=G,X=re(q=>{const K=Xt(q)(Y.inWeight);if(K.tag==="Nothing")return!0;if(K.tag==="Just")return K._1===0;g()})(Y.remaining);if(X.tag==="Nothing"){Q=!1,V=Y;continue}if(X.tag==="Just"){const q=X._1;G={...Y,inWeight:v(K=>et=>Ft(ot)(xe)(et.tgt)(-et.weight)(K))(Y.inWeight)((()=>{const K=Xt(q)(Y.depsBySrc);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),marks:rt(ot)(q)(Y.nextSource)(Y.marks),nextSource:Y.nextSource+1|0,outWeight:v(K=>et=>Ft(ot)(xe)(et.src)(-et.weight)(K))(Y.outWeight)((()=>{const K=Xt(q)(Y.depsByTgt);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),remaining:ft(K=>K!==q,Y.remaining)};continue}g()}return V},F=S=>{let G=S,Q=!0,V;for(;Q;){const Y=G,X=re(q=>{const K=Xt(q)(Y.outWeight);if(K.tag==="Nothing")return!0;if(K.tag==="Just")return K._1===0;g()})(Y.remaining);if(X.tag==="Nothing"){Q=!1,V=Y;continue}if(X.tag==="Just"){const q=X._1;G={...Y,inWeight:v(K=>et=>Ft(ot)(xe)(et.tgt)(-et.weight)(K))(Y.inWeight)((()=>{const K=Xt(q)(Y.depsBySrc);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),marks:rt(ot)(q)(Y.nextSink)(Y.marks),nextSink:Y.nextSink-1|0,outWeight:v(K=>et=>Ft(ot)(xe)(et.src)(-et.weight)(K))(Y.outWeight)((()=>{const K=Xt(q)(Y.depsByTgt);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),remaining:ft(K=>K!==q,Y.remaining)};continue}g()}return V};return(S=>{let G=S,Q=!0,V;for(;Q;){const Y=D(F(G));if(Y.remaining.length===0){Q=!1,V=$(X=>{const q=Xt(X.id)(Y.marks),K=(()=>{if(q.tag==="Nothing")return X.id;if(q.tag==="Just")return q._1;g()})();return{...X,mark:K<O?(K+O|0)+1|0:K}})(W);continue}G=(()=>{const X=K=>{const et=Xt(K)(Y.outWeight),lt=Xt(K)(Y.inWeight);return(()=>{if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1;g()})()-(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()|0},q=It(K=>et=>ot.compare(X(et))(X(K)))(Y.remaining);if(0<q.length){const K=q[0];return{...Y,inWeight:v(et=>lt=>Ft(ot)(xe)(lt.tgt)(-lt.weight)(et))(Y.inWeight)((()=>{const et=Xt(K)(Y.depsBySrc);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;g()})()),marks:rt(ot)(K)(Y.nextSource)(Y.marks),nextSource:Y.nextSource+1|0,outWeight:v(et=>lt=>Ft(ot)(xe)(lt.src)(-lt.weight)(et))(Y.outWeight)((()=>{const et=Xt(K)(Y.depsByTgt);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;g()})()),remaining:ft(et=>et!==K,Y.remaining)}}return Y})()}return V})({remaining:$(S=>S.id)(W),marks:R,inWeight:v(S=>G=>Ft(ot)(xe)(G.tgt)(G.weight)(S))(R)(f),outWeight:v(S=>G=>Ft(ot)(xe)(G.src)(G.weight)(S))(R)(f),depsBySrc:v(S=>G=>Ft(ot)(he)(G.src)([G])(S))(R)(f),depsByTgt:v(S=>G=>Ft(ot)(he)(G.tgt)([G])(S))(R)(f),nextSink:O-1|0,nextSource:O+1|0})})())})()),A=ft(W=>{const O=Xt(W.src)(I),D=Xt(W.tgt)(I);return(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;g()})()>(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;g()})()},f);if(A.length===0)return l;const j=v(W=>O=>{if(tn(Rr)(O.src)(W.decisions)||tn(Rr)(O.tgt)(W.decisions))return W;const D=Xt(O.src)(W.segMap),F=Xt(O.tgt)(W.segMap);if(D.tag==="Just"&&F.tag==="Just"){const S=(D._1.incoming.length+D._1.outgoing.length|0)>2&&(F._1.incoming.length+F._1.outgoing.length|0)<=2,G=S?F._1:D._1;return{decisions:[...W.decisions,G.id],segMap:rt(ot)(G.id)({...G,splitBy:N("Just",S?D._1.id:F._1.id)})(W.segMap)}}return W})({decisions:[],segMap:ei($(W=>C(W.id,W))(l.segments))})(A),Z=j.segMap,M=v(W=>O=>{const D=Jt(v(Jt)(1e18)(O.incoming))(v(Jt)(1e18)(O.outgoing)),F=Nt(v(Nt)(-1e18)(O.incoming))(v(Nt)(-1e18)(O.outgoing)),S=ft(X=>X.a.startPosition<=F&&X.a.endPosition>=D,Ht(X=>q=>({i:X,a:q}))(W.freeAreas));if(S.length===0){const X={...O,incoming:It(it.compare)(O.incoming),outgoing:It(it.compare)([(D+F)/2]),splitPartner:N("Just",W.nextId)},q={id:W.nextId,incoming:It(it.compare)([(D+F)/2]),mark:0,members:O.members,outgoing:It(it.compare)(O.outgoing),slot:0,splitBy:w,splitPartner:N("Just",O.id)};return{segMap:rt(ot)(q.id)(q)(rt(ot)(X.id)(X)(W.segMap)),freeAreas:W.freeAreas,nextId:W.nextId+1|0}}const G=0<S.length?N("Just",S[0]):w,Q=(()=>{if(G.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(G.tag==="Just"){if(S.length===1)return G._1;const X=$(q=>({c:q,rating:(()=>{const K=(q.a.startPosition+q.a.endPosition)/2,et=[K],lt=[K],Ct=v((()=>{const Tt=W.segMap;return Et=>Zt=>{const bt=Xt(Zt.tgt)(Tt);if(bt.tag==="Nothing")return Et;if(bt.tag==="Just"){const Ut=Jt(v(Jt)(1e18)(bt._1.incoming))(v(Jt)(1e18)(bt._1.outgoing)),Bt=Nt(v(Nt)(-1e18)(bt._1.incoming))(v(Nt)(-1e18)(bt._1.outgoing)),wt=Jt(v(Jt)(1e18)(O.incoming))(v(Jt)(1e18)(et)),mt=(()=>{const Ot=Nt(v(Nt)(-1e18)(O.incoming))(v(Nt)(-1e18)(et)),qt=v(oe=>fe=>fe>Bt?oe:fe>=Ut?oe+1|0:oe)(0)(et)+v(oe=>fe=>fe>Ot?oe:fe>=wt?oe+1|0:oe)(0)(bt._1.incoming)|0,We=Jt(v(Jt)(1e18)(O.incoming))(v(Jt)(1e18)(et)),vn=Nt(v(Nt)(-1e18)(O.incoming))(v(Nt)(-1e18)(et)),Ze=Jt(v(Jt)(1e18)(bt._1.incoming))(v(Jt)(1e18)(bt._1.outgoing)),_n=Nt(v(Nt)(-1e18)(bt._1.incoming))(v(Nt)(-1e18)(bt._1.outgoing)),Fe=v(oe=>fe=>fe>vn?oe:fe>=We?oe+1|0:oe)(0)(bt._1.outgoing)+v(oe=>fe=>fe>_n?oe:fe>=Ze?oe+1|0:oe)(0)(O.incoming)|0;return qt===Fe?qt>0?{...Et,deps:Et.deps+2|0,crossings:Et.crossings+qt|0}:Et:{...Et,deps:Et.deps+1|0,crossings:Et.crossings+ri(qt)(Fe)|0}})(),ct=Jt(v(Jt)(1e18)(bt._1.incoming))(v(Jt)(1e18)(bt._1.outgoing)),yt=Nt(v(Nt)(-1e18)(bt._1.incoming))(v(Nt)(-1e18)(bt._1.outgoing)),dt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(O.outgoing)),ht=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(O.outgoing)),Lt=v(Ot=>qt=>qt>yt?Ot:qt>=ct?Ot+1|0:Ot)(0)(O.outgoing)+v(Ot=>qt=>qt>ht?Ot:qt>=dt?Ot+1|0:Ot)(0)(bt._1.incoming)|0,Gt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(O.outgoing)),Qt=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(O.outgoing)),ne=Jt(v(Jt)(1e18)(bt._1.incoming))(v(Jt)(1e18)(bt._1.outgoing)),Nn=Nt(v(Nt)(-1e18)(bt._1.incoming))(v(Nt)(-1e18)(bt._1.outgoing)),ze=v(Ot=>qt=>qt>Qt?Ot:qt>=Gt?Ot+1|0:Ot)(0)(bt._1.outgoing)+v(Ot=>qt=>qt>Nn?Ot:qt>=ne?Ot+1|0:Ot)(0)(lt)|0;return Lt===ze?Lt>0?{...mt,deps:mt.deps+2|0,crossings:mt.crossings+Lt|0}:mt:{...mt,deps:mt.deps+1|0,crossings:mt.crossings+ri(Lt)(ze)|0}}g()}})())(v((()=>{const Tt=W.segMap;return Et=>Zt=>{const bt=Xt(Zt.src)(Tt);if(bt.tag==="Nothing")return Et;if(bt.tag==="Just"){const Ut=Jt(v(Jt)(1e18)(bt._1.incoming))(v(Jt)(1e18)(bt._1.outgoing)),Bt=Nt(v(Nt)(-1e18)(bt._1.incoming))(v(Nt)(-1e18)(bt._1.outgoing)),wt=Jt(v(Jt)(1e18)(O.incoming))(v(Jt)(1e18)(et)),mt=(()=>{const Ot=Nt(v(Nt)(-1e18)(O.incoming))(v(Nt)(-1e18)(et)),qt=v(oe=>fe=>fe>Bt?oe:fe>=Ut?oe+1|0:oe)(0)(et)+v(oe=>fe=>fe>Ot?oe:fe>=wt?oe+1|0:oe)(0)(bt._1.incoming)|0,We=Jt(v(Jt)(1e18)(O.incoming))(v(Jt)(1e18)(et)),vn=Nt(v(Nt)(-1e18)(O.incoming))(v(Nt)(-1e18)(et)),Ze=Jt(v(Jt)(1e18)(bt._1.incoming))(v(Jt)(1e18)(bt._1.outgoing)),_n=Nt(v(Nt)(-1e18)(bt._1.incoming))(v(Nt)(-1e18)(bt._1.outgoing)),Fe=v(oe=>fe=>fe>vn?oe:fe>=We?oe+1|0:oe)(0)(bt._1.outgoing)+v(oe=>fe=>fe>_n?oe:fe>=Ze?oe+1|0:oe)(0)(O.incoming)|0;return qt===Fe?qt>0?{...Et,deps:Et.deps+2|0,crossings:Et.crossings+qt|0}:Et:{...Et,deps:Et.deps+1|0,crossings:Et.crossings+ri(qt)(Fe)|0}})(),ct=Jt(v(Jt)(1e18)(bt._1.incoming))(v(Jt)(1e18)(bt._1.outgoing)),yt=Nt(v(Nt)(-1e18)(bt._1.incoming))(v(Nt)(-1e18)(bt._1.outgoing)),dt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(O.outgoing)),ht=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(O.outgoing)),Lt=v(Ot=>qt=>qt>yt?Ot:qt>=ct?Ot+1|0:Ot)(0)(O.outgoing)+v(Ot=>qt=>qt>ht?Ot:qt>=dt?Ot+1|0:Ot)(0)(bt._1.incoming)|0,Gt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(O.outgoing)),Qt=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(O.outgoing)),ne=Jt(v(Jt)(1e18)(bt._1.incoming))(v(Jt)(1e18)(bt._1.outgoing)),Nn=Nt(v(Nt)(-1e18)(bt._1.incoming))(v(Nt)(-1e18)(bt._1.outgoing)),ze=v(Ot=>qt=>qt>Qt?Ot:qt>=Gt?Ot+1|0:Ot)(0)(bt._1.outgoing)+v(Ot=>qt=>qt>Nn?Ot:qt>=ne?Ot+1|0:Ot)(0)(lt)|0;return Lt===ze?Lt>0?{...mt,deps:mt.deps+2|0,crossings:mt.crossings+Lt|0}:mt:{...mt,deps:mt.deps+1|0,crossings:mt.crossings+ri(Lt)(ze)|0}}g()}})())({crossings:0,deps:0})(ft(Tt=>Tt.tgt===O.id,l.deps)))(ft(Tt=>Tt.src===O.id,l.deps)),pt=(()=>{if(O.splitBy.tag==="Just")return Xt(O.splitBy._1)(W.segMap);if(O.splitBy.tag==="Nothing")return w;g()})();if(pt.tag==="Just")return{...Ct,deps:Ct.deps+2|0,crossings:(()=>{const Tt=Jt(v(Jt)(1e18)(pt._1.incoming))(v(Jt)(1e18)(pt._1.outgoing)),Et=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(O.outgoing)),Zt=Nt(v(Nt)(-1e18)(pt._1.incoming))(v(Nt)(-1e18)(pt._1.outgoing)),bt=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(O.outgoing)),Ut=Jt(v(Jt)(1e18)(O.incoming))(v(Jt)(1e18)(et));return Ct.crossings+(()=>{const Bt=Jt(v(Jt)(1e18)(pt._1.incoming))(v(Jt)(1e18)(pt._1.outgoing)),wt=Nt(v(Nt)(-1e18)(O.incoming))(v(Nt)(-1e18)(et)),mt=Nt(v(Nt)(-1e18)(pt._1.incoming))(v(Nt)(-1e18)(pt._1.outgoing));return((v(ct=>yt=>yt>Zt?ct:yt>=Tt?ct+1|0:ct)(0)(et)+v(ct=>yt=>yt>wt?ct:yt>=Ut?ct+1|0:ct)(0)(pt._1.incoming)|0)+v(ct=>yt=>yt>bt?ct:yt>=Et?ct+1|0:ct)(0)(pt._1.outgoing)|0)+v(ct=>yt=>yt>mt?ct:yt>=Bt?ct+1|0:ct)(0)(lt)|0})()|0})()};if(pt.tag==="Nothing")return Ct;g()})()}))(S);return v(q=>K=>K.rating.crossings<q.rating.crossings||!(K.rating.crossings>q.rating.crossings)&&(K.rating.deps<q.rating.deps||!(K.rating.deps>q.rating.deps)&&K.c.a.size>q.c.a.size)?K:q)(0<X.length?X[0]:{c:G._1,rating:{crossings:1e6,deps:1e6}})(X).c}g()})(),V={...O,incoming:It(it.compare)(O.incoming),outgoing:It(it.compare)([(Q.a.startPosition+Q.a.endPosition)/2]),splitPartner:N("Just",W.nextId)},Y={id:W.nextId,incoming:It(it.compare)([(Q.a.startPosition+Q.a.endPosition)/2]),mark:0,members:O.members,outgoing:It(it.compare)(O.outgoing),slot:0,splitBy:w,splitPartner:N("Just",O.id)};return{segMap:rt(ot)(Y.id)(Y)(rt(ot)(V.id)(V)(W.segMap)),freeAreas:(()=>{if(Q.i>=0&&Q.i<W.freeAreas.length){const X=h_(Yt,w,Q.i,W.freeAreas),q=(()=>{if(X.tag==="Nothing")return W.freeAreas;if(X.tag==="Just")return X._1;g()})();if(W.freeAreas[Q.i].size/2<d)return q;const K=(W.freeAreas[Q.i].startPosition+W.freeAreas[Q.i].endPosition)/2,et=K-d,lt=K+d;return[...Q.i<1?[]:Dt(0,Q.i,q),...W.freeAreas[Q.i].startPosition<=et?[{startPosition:W.freeAreas[Q.i].startPosition,endPosition:et,size:et-W.freeAreas[Q.i].startPosition}]:[],...lt<=W.freeAreas[Q.i].endPosition?[{startPosition:lt,endPosition:W.freeAreas[Q.i].endPosition,size:W.freeAreas[Q.i].endPosition-lt}]:[],...Q.i<1?q:Dt(Q.i,q.length,q)]}return W.freeAreas})(),nextId:W.nextId+1|0}})({segMap:Z,freeAreas:(()=>{const W=It(it.compare)([...St(l.segments)(O=>O.incoming),...St(l.segments)(O=>O.outgoing)]);return vt(Bw)(Qe(O=>D=>D-O>=2*d?N("Just",{startPosition:O+d,endPosition:D-d,size:D-O-2*d}):w,W,Dt(1,W.length,W)))})(),nextId:l.segments.length})(It(W=>O=>it.compare(Nt(v(Nt)(-1e18)(W.incoming))(v(Nt)(-1e18)(W.outgoing))-Jt(v(Jt)(1e18)(W.incoming))(v(Jt)(1e18)(W.outgoing)))(Nt(v(Nt)(-1e18)(O.incoming))(v(Nt)(-1e18)(O.outgoing))-Jt(v(Jt)(1e18)(O.incoming))(v(Jt)(1e18)(O.outgoing))))(vt(W=>Xt(W)(Z))(j.decisions)));return{segments:(()=>{const W=(O,D)=>{if(O.tag==="Leaf")return D;if(O.tag==="Node")return W(O._5,kt("Cons",O._4,W(O._6,D)));g()};return jt(le.foldr,W(M.segMap,H))})(),deps:(()=>{const W=M.segMap,O=(S,G)=>{if(S.tag==="Leaf")return G;if(S.tag==="Node")return O(S._5,kt("Cons",S._4,O(S._6,G)));g()},D=jt(le.foldr,O(W,H)),F=D.length;return[...St(St(Kt(0,F-2|0))(S=>St(Kt(S+1|0,F-1|0))(G=>[C(S,G)])))(S=>S._1>=0&&S._1<D.length?S._2>=0&&S._2<D.length?D[S._1].splitPartner.tag!=="Nothing"&&D[S._1].splitPartner.tag==="Just"&&D[S._1].splitPartner._1===D[S._2].id||D[S._2].splitPartner.tag!=="Nothing"&&D[S._2].splitPartner.tag==="Just"&&D[S._2].splitPartner._1===D[S._1].id?[]:i(d,D[S._1],D[S._2]):[]:[]),...St(D)(S=>S.splitBy.tag==="Just"&&S.splitPartner.tag==="Just"&&(()=>{const G=Xt(S.splitPartner._1)(W);if(G.tag==="Nothing")return!1;if(G.tag==="Just")return!0;g()})()&&(()=>{const G=Xt(S.splitBy._1)(W);if(G.tag==="Nothing")return!1;if(G.tag==="Just")return!0;g()})()?[{src:S.id,tgt:S.splitBy._1,weight:1,kind:ta},{src:S.splitBy._1,tgt:S.splitPartner._1,weight:1,kind:ta}]:[])]})()}})(),p=h.segments,m=p.length,J=I=>{let A=I,j=!0,Z;for(;j;){const M=A,W=re(O=>{const D=Xt(O)(M.inWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;g()})(M.remaining);if(W.tag==="Nothing"){j=!1,Z=M;continue}if(W.tag==="Just"){const O=W._1;A={...M,inWeight:v(D=>F=>Ft(ot)(xe)(F.tgt)(-F.weight)(D))(M.inWeight)((()=>{const D=Xt(O)(M.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),marks:rt(ot)(O)(M.nextSource)(M.marks),nextSource:M.nextSource+1|0,outWeight:v(D=>F=>Ft(ot)(xe)(F.src)(-F.weight)(D))(M.outWeight)((()=>{const D=Xt(O)(M.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),remaining:ft(D=>D!==O,M.remaining)};continue}g()}return Z},x=I=>{let A=I,j=!0,Z;for(;j;){const M=A,W=re(O=>{const D=Xt(O)(M.outWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;g()})(M.remaining);if(W.tag==="Nothing"){j=!1,Z=M;continue}if(W.tag==="Just"){const O=W._1;A={...M,inWeight:v(D=>F=>Ft(ot)(xe)(F.tgt)(-F.weight)(D))(M.inWeight)((()=>{const D=Xt(O)(M.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),marks:rt(ot)(O)(M.nextSink)(M.marks),nextSink:M.nextSink-1|0,outWeight:v(D=>F=>Ft(ot)(xe)(F.src)(-F.weight)(D))(M.outWeight)((()=>{const D=Xt(O)(M.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),remaining:ft(D=>D!==O,M.remaining)};continue}g()}return Z},y=(I=>{let A=I,j=!0,Z;for(;j;){const M=J(x(A));if(M.remaining.length===0){j=!1,Z=$(W=>{const O=Xt(W.id)(M.marks),D=(()=>{if(O.tag==="Nothing")return W.id;if(O.tag==="Just")return O._1;g()})();return{...W,mark:D<m?(D+m|0)+1|0:D}})(p);continue}A=(()=>{const W=D=>{const F=Xt(D)(M.outWeight),S=Xt(D)(M.inWeight);return(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;g()})()-(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;g()})()|0},O=It(D=>F=>ot.compare(W(F))(W(D)))(M.remaining);if(0<O.length){const D=O[0];return{...M,inWeight:v(F=>S=>Ft(ot)(xe)(S.tgt)(-S.weight)(F))(M.inWeight)((()=>{const F=Xt(D)(M.depsBySrc);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})()),marks:rt(ot)(D)(M.nextSource)(M.marks),nextSource:M.nextSource+1|0,outWeight:v(F=>S=>Ft(ot)(xe)(S.src)(-S.weight)(F))(M.outWeight)((()=>{const F=Xt(D)(M.depsByTgt);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})()),remaining:ft(F=>F!==D,M.remaining)}}return M})()}return Z})({remaining:$(I=>I.id)(p),marks:R,inWeight:v(I=>A=>Ft(ot)(xe)(A.tgt)(A.weight)(I))(R)(h.deps),outWeight:v(I=>A=>Ft(ot)(xe)(A.src)(A.weight)(I))(R)(h.deps),depsBySrc:v(I=>A=>Ft(ot)(he)(A.src)([A])(I))(R)(h.deps),depsByTgt:v(I=>A=>Ft(ot)(he)(A.tgt)([A])(I))(R)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),T=(()=>{const I=(()=>{const Z=ei($(M=>C(M.id,M.mark))(y));return{segments:y,deps:vt(M=>(()=>{if(M.kind==="Critical")return!0;if(M.kind==="Regular")return!1;g()})()?N("Just",M):(()=>{const W=Xt(M.src)(Z),O=Xt(M.tgt)(Z);return(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})()>(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;g()})()})()?M.weight===0?w:N("Just",{src:M.tgt,tgt:M.src,weight:M.weight,kind:M.kind}):N("Just",M))(h.deps)}})(),A=v(Z=>M=>Ft(ot)(xe)(M.tgt)(1)(Z))(R)(I.deps),j=(Z=>{let M=Z,W=!0,O;for(;W;){const D=M,F=zt(S=>w,S=>G=>N("Just",{head:S,tail:G}),D.queue);if(F.tag==="Nothing"){W=!1,O=D;continue}if(F.tag==="Just"){M=v((()=>{const S=Xt(F._1.head)(D.slots),G=(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;g()})();return Q=>V=>{const Y=Xt(V)(Q.inDegree),X=(()=>{if(Y.tag==="Nothing")return-1;if(Y.tag==="Just")return Y._1-1|0;g()})();return{...Q,slots:rt(ot)(V)(r1((()=>{const q=Xt(V)(Q.slots);if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;g()})())(G+1|0))(Q.slots),inDegree:rt(ot)(V)(X)(Q.inDegree),queue:X===0?[...Q.queue,V]:Q.queue}}})())({...D,queue:F._1.tail})((()=>{const S=Xt(F._1.head)(D.adj);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})());continue}g()}return O})({slots:ei($(Z=>C(Z.id,0))(I.segments)),inDegree:A,adj:v(Z=>M=>Ft(ot)(he)(M.src)([M.tgt])(Z))(R)(I.deps),queue:$(Z=>Z.id)(ft(Z=>{const M=Xt(Z.id)(A);if(M.tag==="Nothing")return!0;if(M.tag==="Just")return M._1===0;g()},I.segments))});return It(Z=>M=>ot.compare(Z.slot)(M.slot))($(Z=>({...Z,slot:(()=>{const M=Xt(Z.id)(j.slots);if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()}))(I.segments))})(),b=1+v(I=>A=>r1(I)(A.slot))(0)(T)|0,L=St(T)(I=>I.members),E=ft(I=>tn(Zn)(I.edge.id)(L),t),B=v(Nt)(-1e18)($(I=>I.fromPos._2)(E)),z=v(Jt)(1e18)($(I=>I.toPos._2)(E));if(B>z){const I=ei($(A=>C(A.id,A))(T));return ln($(A=>$(j=>C(j,{slot:A.slot,slotCount:b,gapTop:z,gapBottom:B,partner:(()=>{if(A.splitPartner.tag==="Just"){const Z=Xt(A.splitPartner._1)(I);if(Z.tag==="Just")return N("Just",{slot:Z._1.slot,splitX:0<Z._1.incoming.length?Z._1.incoming[0]:0});if(Z.tag==="Nothing")return w;g()}if(A.splitPartner.tag==="Nothing")return w;g()})()}))(A.members))(ft(A=>{if(A.splitPartner.tag==="Just"){const j=Xt(A.splitPartner._1)(I);return!(j.tag==="Just"&&(()=>{if(j._1.splitBy.tag==="Nothing")return!1;if(j._1.splitBy.tag==="Just")return!0;g()})())}if(A.splitPartner.tag==="Nothing")return!0;g()},T)))}const U=ei($(I=>C(I.id,I))(T));return ln($(I=>$(A=>C(A,{slot:I.slot,slotCount:b,gapTop:B,gapBottom:z,partner:(()=>{if(I.splitPartner.tag==="Just"){const j=Xt(I.splitPartner._1)(U);if(j.tag==="Just")return N("Just",{slot:j._1.slot,splitX:0<j._1.incoming.length?j._1.incoming[0]:0});if(j.tag==="Nothing")return w;g()}if(I.splitPartner.tag==="Nothing")return w;g()})()}))(I.members))(ft(I=>{if(I.splitPartner.tag==="Just"){const A=Xt(I.splitPartner._1)(U);return!(A.tag==="Just"&&(()=>{if(A._1.splitBy.tag==="Nothing")return!1;if(A._1.splitBy.tag==="Just")return!0;g()})())}if(I.splitPartner.tag==="Nothing")return!0;g()},T)))})()))(R)(Pw(v(s=>a=>{const u=ni(a.edge.from.node)(n);if(u.tag==="Just"){const c=ni(a.edge.to.node)(n);return c.tag==="Just"&&u._1.layer!==c._1.layer?Ft(ot)(he)(ri(u._1.layer)(c._1.layer))([a])(s):s}return s})(R)((()=>{const s=a=>C((()=>{const u=ni(a.edge.from.node)(n);return u.tag==="Just"?u._1.layer:1e6})(),(()=>{const u=ni(a.edge.from.node)(n);return u.tag==="Just"?u._1.order:1e6})());return It(a=>u=>Gw(s(a))(s(u)))(t)})())))},Iw=t=>e=>{const n=i1(t)(e),r=v(o=>i=>rt(P)(i.node)(i)(o))(R)(e);return v(o=>i=>{const s=ni(i.edge.from.node)(r);if(s.tag==="Just"){const a=ni(i.edge.to.node)(r);if(a.tag==="Just"&&s._1.layer!==a._1.layer){const u=Dw(i.edge.id)(n);if(u.tag==="Just")return rt(ot)(ri(s._1.layer)(a._1.layer))(u._1.slotCount)(o)}return o}return o})(R)(t)},wc=ce(P)(Mt),kr=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Jc=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Aw=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 s=P.compare(t._1)(i._3._1);if(s==="LT"){n=i._5;continue}if(s==="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},s1=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 C(o,i*2);if(t==="North")return C(o,e.position._2*2);if(t==="East")return C(n*2,r);if(t==="West")return C(e.position._1*2,r);g()},Nc=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()},a1=t=>e=>v(n=>r=>Ft(t)(he)(e(r))([r])(n))(R),u1=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},c1=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,o=e.length;return o===0?R:wc(o===1?$(i=>C(i,r))(e):Ht(i=>s=>C(s,t.lo+nt(i+1|0)*n/nt(o+1|0)))(e))},g1=t=>e=>n=>r=>o=>{const i=a1(P)(f=>f.to.node)(t),s=a1(P)(f=>f.from.node)(t),a=v(f=>h=>rt(P)(h.node)(h)(f))(R)(e),u=(f,h,p)=>{const m=kr(f)(a);if(m.tag==="Nothing")return C(0,0);if(m.tag==="Just"){const J=kr(f)(n);if(J.tag==="Nothing"){const x=nt(4);if(p==="South")return C(m._1.position._1*x+m._1.size._1*x/2,(m._1.position._2+m._1.size._2)*x);if(p==="North")return C(m._1.position._1*x+m._1.size._1*x/2,m._1.position._2*x);if(p==="East")return C((m._1.position._1+m._1.size._1)*x,m._1.position._2*x+m._1.size._2*x/2);if(p==="West")return C(m._1.position._1*x,m._1.position._2*x+m._1.size._2*x/2);g()}if(J.tag==="Just"){const x=re(y=>y.id===h)(J._1);if(x.tag==="Nothing"){const y=nt(4);if(p==="South")return C(m._1.position._1*y+m._1.size._1*y/2,(m._1.position._2+m._1.size._2)*y);if(p==="North")return C(m._1.position._1*y+m._1.size._1*y/2,m._1.position._2*y);if(p==="East")return C((m._1.position._1+m._1.size._1)*y,m._1.position._2*y+m._1.size._2*y/2);if(p==="West")return C(m._1.position._1*y,m._1.position._2*y+m._1.size._2*y/2);g()}if(x.tag==="Just"){const y=nt(4);if(x._1.side==="North")return C(m._1.position._1*y+nt(x._1.offset)*y,m._1.position._2*y);if(x._1.side==="South")return C(m._1.position._1*y+nt(x._1.offset)*y,(m._1.position._2+m._1.size._2)*y);if(x._1.side==="East")return C((m._1.position._1+m._1.size._1)*y,m._1.position._2*y+nt(x._1.offset)*y);if(x._1.side==="West")return C(m._1.position._1*y,m._1.position._2*y+nt(x._1.offset)*y)}}}g()},c=wc(St(r)(f=>{if(f.nodes.length<=2)return[];const h=nt(4);if(1<f.nodes.length){const p=kr(f.nodes[1])(a);if(p.tag==="Nothing")return[];if(p.tag==="Just"){const m=p._1.position._1*h+p._1.size._1*h/2;return $(J=>C(J,m))(Qe(J=>x=>f.edgeId+":"+J+"->"+x,f.nodes,Dt(1,f.nodes.length,f.nodes)))}g()}return[]})),_=f=>{const h=kr(f.from.node)(a),p=kr(f.to.node)(a);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,J=p._1,x=It(y=>T=>ot.compare(y.score)(T.score))($(y=>{const T=y._1,b=y._2;return{from:T,to:b,score:(()=>{const L=(U,I,A,j,Z)=>{const M=Nc(U)(I),W=Nc(U)(A);return M.lo<W.hi&&W.lo<M.hi&&(T==="South"?b==="North"&&Z._2>j._2:T==="North"?b==="South"&&Z._2<j._2:T==="East"?b==="West"&&Z._1>j._1:T==="West"&&b==="East"&&Z._1<j._1)?0:u1(T)(b)(j)(Z)},E=s1(T)(m),B=s1(b)(J),z=u1(T)(b)(E)(B);return(()=>{if(z>0){if(T==="South")return b==="North"?L(Se,m,J,E,B)*10|0:z*10|0;if(T==="North")return b==="South"?L(Le,m,J,E,B)*10|0:z*10|0;if(T==="East")return b==="West"?L(Nr,m,J,E,B)*10|0:z*10|0;if(T==="West"&&b==="East")return L(vr,m,J,E,B)*10|0}return z*10|0})()+(T==="South"?b==="North"?J.layer>=m.layer?0:20:15:T==="North"?b==="South"?J.layer<=m.layer?0:20:15:T==="East"?b==="West"?5:15:T==="West"&&b==="East"?5:15)|0})()}})([C(Se,Le),C(Nr,Le),C(vr,Le),C(Se,Nr),C(Se,vr),C(Le,Se),C(Le,Nr),C(Le,vr),C(Nr,Se),C(vr,Se),C(Nr,vr),C(vr,Nr)]));if(0<x.length)return{from:x[0].from,to:x[0].to}}return{from:Se,to:Le}},d=wc($(f=>C(f.id,_(f)))(t)),l=(f,h,p,m,J,x)=>{const y=nt(4),T=kr(h)(a);if(T.tag==="Nothing")return C(0,0);if(T.tag==="Just"){const b=Aw(C(p,f))(o);if(b.tag==="Just"){const L=T._1.position._1*y+b._1,E=nt(4);if(f==="South")return C(L,(T._1.position._2+T._1.size._2)*E);if(f==="North")return C(L,T._1.position._2*E);if(f==="East")return C((T._1.position._1+T._1.size._1)*E,L);if(f==="West")return C(T._1.position._1*E,L);g()}if(b.tag==="Nothing"){const L=Nc(f)(T._1),E=(L.lo+L.hi)/2,B=Jc(p)(c1(L)($(I=>I.id)(It(I=>A=>it.compare(J(f)(I))(J(f)(A)))(ft(I=>{const A=Jc(I.id)(d);if(A.tag==="Just"){const j=x(A._1);return j==="North"?f==="North":j==="South"?f==="South":j==="East"?f==="East":j==="West"&&f==="West"}if(A.tag==="Nothing")return!0;g()},(()=>{const I=kr(h)(m);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})()))))),z=(()=>{if(B.tag==="Nothing")return E;if(B.tag==="Just")return B._1;g()})(),U=nt(4);if(f==="South")return C(z,(T._1.position._2+T._1.size._2)*U);if(f==="North")return C(z,T._1.position._2*U);if(f==="East")return C((T._1.position._1+T._1.size._1)*U,z);if(f==="West")return C(T._1.position._1*U,z)}}g()};return $(f=>{const h=Jc(f.edge.id)(c);if(h.tag==="Nothing")return f;if(h.tag==="Just")return{...f,fromPos:Re(3)(f.edge.from.node)==="$d:"?C(h._1,f.fromPos._2):f.fromPos,toPos:Re(3)(f.edge.to.node)==="$d:"?C(h._1,f.toPos._2):f.toPos};g()})($(f=>{if(f.from.port.tag==="Just"&&f.to.port.tag==="Just")return{edge:f,fromPos:u(f.from.node,f.from.port._1,Se),toPos:u(f.to.node,f.to.port._1,Le),fromSide:Se,toSide:Le};const h=_(f);return{edge:f,fromPos:l(h.from,f.from.node,f.id,s,p=>m=>{const J=kr(m.to.node)(a);if(J.tag==="Nothing")return 0;if(J.tag==="Just"){const x=nt(4);if(p==="South"||p==="North")return J._1.position._1*x+J._1.size._1*x/2;if(p==="East"||p==="West")return J._1.position._2*x+J._1.size._2*x/2}g()},p=>p.from),toPos:l(h.to,f.to.node,f.id,i,p=>m=>{const J=kr(m.from.node)(a);if(J.tag==="Nothing")return 0;if(J.tag==="Just"){const x=nt(4);if(p==="South"||p==="North")return J._1.position._1*x+J._1.size._1*x/2;if(p==="East"||p==="West")return J._1.position._2*x+J._1.size._2*x/2}g()},p=>p.to),fromSide:h.from,toSide:h.to}})(t))},ea=(()=>{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 De;if(r==="GT")return Ie;if(e._2==="North")return n._2==="North"?Ye:De;if(n._2==="North")return Ie;if(e._2==="South")return n._2==="South"?Ye:De;if(n._2==="South")return Ie;if(e._2==="East")return n._2==="East"?Ye:De;if(n._2==="East")return Ie;if(e._2==="West"&&n._2==="West")return Ye;g()},Eq0:()=>t}})(),Rw=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 s=ea.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Fw=ce(P)(Mt),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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Qw=ce(ea)(Mt),_1=(()=>{const t=en.unfoldr(In);return e=>t(nn("IterNode",e,Dn))})(),oi=t=>e=>n=>r=>{const o=Rw(C(e,n))(t);if(o.tag==="Nothing")return r;if(o.tag==="Just")return o._1;g()},f1=t=>e=>n=>{const r=Fw(ln($(s=>Ht(a=>u=>C(u,a))(s))(t))),o=(s,a)=>{if(s==="South"){const u=vc(a.to.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()}if(s==="North"){const u=vc(a.from.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()}return 0},i=s=>v(a=>u=>Ae(ea.compare,Be,Qw($(c=>C(C(c._1,s),c._2))(_1(c1({lo:0,hi:(()=>{const c=vc(u._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return Re(3)(u._1)==="$d:"?0:1;g()})()})($(c=>c.id)(It(c=>_=>ot.compare(o(s,c))(o(s,_)))(u._2)))))),a))(R)(_1(v(a=>u=>u.from.node===u.to.node?a:s==="South"?Ft(P)(he)(u.from.node)([u])(a):s==="North"?Ft(P)(he)(u.to.node)([u])(a):a)(R)(e)));return Ae(ea.compare,Be,i(Le),i(Se))},d1=t=>t,l1=t=>t,h1=t=>t,Mw=v(t=>e=>rt(P)(e)()(t))(R),zw=(()=>{const t=en.unfoldr(e=>{if(e.tag==="Nil")return w;if(e.tag==="Cons")return N("Just",C(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,kt("Cons",r._3,n(r._6,o)));g()};return n(e,H)})())})(),gt=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Cn=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ir=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},sr=ce(P)(Mt),Tc=N_(P),bc=(()=>{const t=en.unfoldr(In);return e=>t(nn("IterNode",e,Dn))})(),Ww=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},qw=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 s=ot.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},p1=h1("VDown"),m1=h1("VUp"),Ow=l1("ForwardPhase"),Hw=l1("StackPhase"),y1=d1("HRight"),x1=d1("HLeft"),w1=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},$w=t=>e=>n=>{const r=v(s=>a=>Ft(P)(xe)(a.tgt)(1)(s))(R)(t),o=zw(Mw([...$(s=>s.src)(t),...$(s=>s.tgt)(t),...(()=>{const s=(a,u)=>{if(a.tag==="Leaf")return u;if(a.tag==="Node")return s(a._5,kt("Cons",a._4,s(a._6,u)));g()};return jt(le.foldr,s(e,H))})()])),i=v(s=>a=>Ft(P)(he)(a.src)([{target:a.tgt,sep:a.sep}])(s))(R)(t);return(s=>a=>u=>{let c=s,_=a,d=u,l=!0,f;for(;l;){const h=c,p=_,m=d,J=zt(x=>w,x=>y=>N("Just",{head:x,tail:y}),h);if(J.tag==="Nothing"){l=!1,f=m;continue}if(J.tag==="Just"){const x=gt(J._1.head)(m),y=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})(),T=v(b=>L=>{const E=gt(L.target)(b.result),B=y+L.sep,z=gt(L.target)(b.indeg),U=(()=>{if(z.tag==="Nothing")return-1;if(z.tag==="Just")return z._1-1|0;g()})();return{newQueue:U===0?[...b.newQueue,L.target]:b.newQueue,result:rt(P)(L.target)((()=>{if(E.tag==="Nothing")return B;if(E.tag==="Just"){if(n==="VDown")return Cn(E._1)(B);if(n==="VUp")return ir(E._1)(B)}g()})())(b.result),indeg:rt(P)(L.target)(U)(b.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const b=gt(J._1.head)(i);if(b.tag==="Nothing")return[];if(b.tag==="Just")return b._1;g()})());c=[...J._1.tail,...T.newQueue],_=T.indeg,d=T.result;continue}g()}return f})(ft(s=>{const a=gt(s)(r);if(a.tag==="Nothing")return!0;if(a.tag==="Just")return a._1===0;g()},o))(r)(v(s=>a=>rt(P)(a)(0)(s))(R)(o))},Vw=t=>{const e=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return e(i._5,kt("Cons",i._4,e(i._6,s)));g()},n=jt(le.foldr,e(t,H)),r=v(Cn)(999999)(n);if(r===0||n.length===0)return t;const o=i=>{if(i.tag==="Leaf")return R;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,i._4-r,o(i._5),o(i._6));g()};return o(t)},J1=t=>{const e=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return e(i._5,kt("Cons",i._4,e(i._6,s)));g()},n=e(t,H),r=i=>s=>{let a=i,u=s,c=!0,_;for(;c;){const d=a,l=u;if(l.tag==="Nil"){c=!1,_=d;continue}if(l.tag==="Cons"){a=ir(d)(l._1),u=l._2;continue}g()}return _},o=i=>s=>{let a=i,u=s,c=!0,_;for(;c;){const d=a,l=u;if(l.tag==="Nil"){c=!1,_=d;continue}if(l.tag==="Cons"){a=Cn(d)(l._1),u=l._2;continue}g()}return _};return r(-999999)(n)-o(999999)(n)},zi=t=>e=>(n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=i;if(u===e){s=!1,a=c;continue}o=(()=>{const _=gt(u)(t.align);if(_.tag==="Nothing")return e;if(_.tag==="Just")return _._1;g()})(),i=[...c,u]}return a})((()=>{const n=gt(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;g()})())([e]),Xw=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>_=>{const d=(D,F,S)=>{const G=D.from.node===F?D.from.port:D.to.node===F?D.to.port:w;if(G.tag==="Just"){const Q=gt(F)(o);if(Q.tag==="Just"){const V=re(Y=>Y.id===G._1)(Q._1);if(V.tag==="Just"){const Y=nt(V._1.offset)*nt(4);return S==="North"||S==="South"?Y:0}if(V.tag==="Nothing"){const Y=gt(F)(r),X=oi(s)(D.id)(S)((()=>{if(Y.tag==="Nothing")return .5;if(Y.tag==="Just")return Y._1._1/2;g()})());return S==="North"||S==="South"?X:0}g()}if(Q.tag==="Nothing"){const V=gt(F)(r),Y=oi(s)(D.id)(S)((()=>{if(V.tag==="Nothing")return .5;if(V.tag==="Just")return V._1._1/2;g()})());return S==="North"||S==="South"?Y:0}g()}if(G.tag==="Nothing"){const Q=gt(F)(r),V=oi(s)(D.id)(S)((()=>{if(Q.tag==="Nothing")return .5;if(Q.tag==="Just")return Q._1._1/2;g()})());return S==="North"||S==="South"?V:0}g()},l=(D,F)=>{if(D.from.node===F){if(_==="HRight")return Se;if(_==="HLeft")return Le;g()}if(_==="HRight")return Le;if(_==="HLeft")return Se;g()},f=(D,F,S)=>v(G=>Q=>rt(P)(Q)((()=>{const V=gt(Q)(G);if(V.tag==="Nothing")return 0+F;if(V.tag==="Just")return V._1+F;g()})())(G))(S)(zi(u)(D)),h=(()=>{if(_==="HRight")return n;if(_==="HLeft")return se(n);g()})(),p=D=>{const F=gt(D)(r);if(F.tag==="Nothing")return 1;if(F.tag==="Just")return F._1._1;g()},m=sr(ln(Ht(D=>F=>$(S=>C(S,D))(F))(n))),J=(D,F)=>Re(3)(D)==="$d:"&&Re(3)(F)==="$d:"||Re(3)(D)==="$d:"||Re(3)(F)==="$d:"?10:nt(t.nodeGap),x=v(D=>F=>Tc(S=>N("Just",[...(()=>{if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})(),F]))(F.to.node)(D))(R)(i),y=v(D=>F=>Tc(S=>N("Just",[...(()=>{if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})(),F]))(F.from.node)(D))(R)(i),T=ln(n),b=v(D=>F=>{const S=gt(F)(u.root),G=(()=>{if(S.tag==="Nothing")return F;if(S.tag==="Just")return S._1;g()})();return F===G?D:Tc(Q=>N("Just",(()=>{if(Q.tag==="Nothing")return!0;if(Q.tag==="Just")return Q._1;g()})()&&Re(3)(F)==="$d:"))(G)(D)})(sr($(D=>C(D,!0))(Ro(P.compare)((()=>{const D=(F,S)=>{if(F.tag==="Leaf")return S;if(F.tag==="Node")return D(F._5,kt("Cons",F._4,D(F._6,S)));g()};return jt(le.foldr,D(u.root,H))})()))))(T),L=(D,F)=>{const S=D.free,G=gt(S)(u.root),Q=(()=>{if(G.tag==="Nothing")return S;if(G.tag==="Just")return G._1;g()})(),V=gt(Q)(b),Y=(()=>{if(V.tag==="Nothing")return!0;if(V.tag==="Just")return V._1;g()})();return v(X=>q=>{if(X.edge.tag==="Just")return X;if(X.edge.tag==="Nothing"){if((()=>{const pt=gt(Q)(F.su);return!Y&&(()=>{const Tt=gt(q.from.node)(m);return q.from.node!==q.to.node&&(()=>{const Et=gt(q.to.node)(m);return(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._1;g()})()===(()=>{if(Et.tag==="Nothing")return-1;if(Et.tag==="Just")return Et._1;g()})()})()})()||(()=>{if(pt.tag==="Nothing")return!1;if(pt.tag==="Just")return pt._1;g()})()})())return X;const K=q.from.node===S?q.to.node:q.from.node,et=gt(K)(u.root),lt=(()=>{if(et.tag==="Nothing")return K;if(et.tag==="Just")return et._1;g()})(),Ct=lt!==Q;return Ct&&(()=>{const pt=gt(lt)(F.blockFinished);if(pt.tag==="Nothing")return!1;if(pt.tag==="Just")return pt._1;g()})()?{...X,edge:N("Just",q),hasEdges:!0}:{...X,hasEdges:X.hasEdges||Ct}}g()})({edge:w,hasEdges:!1})((()=>{if(D.isRoot){if(_==="HRight"){const X=gt(S)(x);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()}if(_==="HLeft"){const X=gt(S)(y);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1}g()}if(_==="HRight"){const X=gt(S)(y);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()}if(_==="HLeft"){const X=gt(S)(x);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1}g()})())},E=(D,F,S,G)=>{const Q=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),V={free:F,isRoot:S},Y=L(V,G);if(Y.edge.tag==="Nothing")return Y.hasEdges?{thresh:Q,state:{...G,queue:[...G.queue,V]}}:{thresh:Q,state:G};if(Y.edge.tag==="Just"){const X=Y.edge._1.from.node===F?Y.edge._1.to.node:Y.edge._1.from.node;return{thresh:(()=>{const q=gt((()=>{const Ct=gt(X)(u.root);if(Ct.tag==="Nothing")return X;if(Ct.tag==="Just")return Ct._1;g()})())(G.x),K=gt(X)(a),et=gt(F)(a),lt=(()=>{if(q.tag==="Just")return q._1;if(q.tag==="Nothing")return w;g()})();return(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()+(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+d(Y.edge._1,X,(()=>{if(S){if(_==="HRight")return Se;if(_==="HLeft")return Le;g()}if(_==="HRight")return Le;if(_==="HLeft")return Se;g()})())-(()=>{if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1;g()})()-d(Y.edge._1,F,(()=>{if(S){if(_==="HRight")return Le;if(_==="HLeft")return Se;g()}if(_==="HRight")return Se;if(_==="HLeft")return Le;g()})())})(),state:{...G,su:rt(P)((()=>{const q=gt(Y.edge._1.from.node)(u.root);if(q.tag==="Nothing")return Y.edge._1.from.node;if(q.tag==="Just")return q._1;g()})())(!0)(rt(P)((()=>{const q=gt(Y.edge._1.to.node)(u.root);if(q.tag==="Nothing")return Y.edge._1.to.node;if(q.tag==="Just")return q._1;g()})())(!0)(G.su))}}}g()},B=(D,F,S,G)=>{const Q=F===D,V=gt(F)(u.align),Y=(()=>{if(V.tag==="Nothing")return F===D;if(V.tag==="Just")return V._1===D;g()})();if(!(Q||Y))return{thresh:S,state:G};const X=(()=>{if(c==="VDown")return Q&&S<=-1e18;if(c==="VUp")return Q&&S>=1e18;g()})()?E(D,F,!0,G):{thresh:S,state:G};return(()=>{if(c==="VDown")return X.thresh<=-1e18&&Y;if(c==="VUp")return X.thresh>=1e18&&Y;g()})()?E(D,F,!1,X.state):X},z=D=>F=>S=>{const G=gt(S)(e.nodeIndex),Q=(()=>{if(G.tag==="Nothing")return 0;if(G.tag==="Just")return G._1;g()})(),V=re(et=>tn(Zn)(S)(et))(h),Y=(()=>{if(V.tag==="Nothing")return[];if(V.tag==="Just")return V._1;g()})(),X=Y.length;if((()=>{if(c==="VDown")return Q<=0;if(c==="VUp")return Q>=(X-1|0);g()})()){const et=B(D,S,F.thresh,F.st);return{...F,st:et.state,thresh:et.thresh}}const q=(()=>{if(c==="VDown")return Q-1|0;if(c==="VUp")return Q+1|0;g()})(),K=q>=0&&q<Y.length?N("Just",Y[q]):w;if(K.tag==="Nothing")return F;if(K.tag==="Just"){const et=gt(K._1)(u.root),lt=(()=>{if(et.tag==="Nothing")return K._1;if(et.tag==="Just")return et._1;g()})(),Ct=B(D,S,F.thresh,U(lt)(F.st)),pt=(()=>{const Qt=gt(D)(Ct.state.sink);if(Qt.tag==="Nothing")return D===D;if(Qt.tag==="Just")return Qt._1===D;g()})()?{...Ct.state,sink:rt(P)(D)((()=>{const Qt=gt(lt)(Ct.state.sink);if(Qt.tag==="Nothing")return lt;if(Qt.tag==="Just")return Qt._1;g()})())(Ct.state.sink)}:Ct.state,Tt=gt(lt)(pt.sink),Et=(()=>{if(Tt.tag==="Nothing")return lt;if(Tt.tag==="Just")return Tt._1;g()})(),Zt=gt(D)(pt.sink),bt=(()=>{if(Zt.tag==="Nothing")return D;if(Zt.tag==="Just")return Zt._1;g()})();if(bt===Et){const Qt=gt(lt)(pt.x),ne=(()=>{if(Qt.tag==="Just")return Qt._1;if(Qt.tag==="Nothing")return w;g()})(),Nn=(()=>{if(ne.tag==="Nothing")return 0;if(ne.tag==="Just")return ne._1;g()})(),ze=gt(D)(pt.x),Ot=(()=>{if(ze.tag==="Just")return ze._1;if(ze.tag==="Nothing")return w;g()})(),qt=(()=>{if(Ot.tag==="Nothing")return 0;if(Ot.tag==="Just")return Ot._1;g()})(),We=J(S,K._1),vn=gt(K._1)(a),Ze=gt(S)(a),_n=(()=>{if(vn.tag==="Nothing")return 0;if(vn.tag==="Just")return vn._1;g()})()-(()=>{if(Ze.tag==="Nothing")return 0;if(Ze.tag==="Just")return Ze._1;g()})();if(c==="VDown"){const Fe=ir(Nn+_n+p(K._1)+We)(Ct.thresh);return{st:{...pt,x:rt(P)(D)(N("Just",F.initial?Fe:ir(qt)(Fe)))(pt.x)},initial:!1,thresh:Ct.thresh}}if(c==="VUp"){const Fe=Cn(Nn+_n-We-p(S))(Ct.thresh);return{st:{...pt,x:rt(P)(D)(N("Just",F.initial?Fe:Cn(qt)(Fe)))(pt.x)},initial:!1,thresh:Ct.thresh}}g()}const Ut=gt(lt)(pt.x),Bt=(()=>{if(Ut.tag==="Just")return Ut._1;if(Ut.tag==="Nothing")return w;g()})(),wt=(()=>{if(Bt.tag==="Nothing")return 0;if(Bt.tag==="Just")return Bt._1;g()})(),mt=gt(D)(pt.x),ct=(()=>{if(mt.tag==="Just")return mt._1;if(mt.tag==="Nothing")return w;g()})(),yt=(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})(),dt=nt(t.nodeGap),ht=gt(S)(a),Lt=gt(K._1)(a),Gt=(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()-(()=>{if(Lt.tag==="Nothing")return 0;if(Lt.tag==="Just")return Lt._1;g()})();return{st:{...pt,classEdges:[...pt.classEdges,{src:bt,tgt:Et,sep:(()=>{if(c==="VDown")return yt+Gt-wt-p(K._1)-dt;if(c==="VUp")return yt+Gt+p(S)+dt-wt;g()})()}]},initial:F.initial,thresh:Ct.thresh}}g()},U=D=>F=>{const S=gt(D)(F.x),G=(()=>{if(S.tag==="Just")return S._1;if(S.tag==="Nothing")return w;g()})();if(G.tag==="Just")return F;if(G.tag==="Nothing"){const Q=v(z(D))({st:{...F,x:rt(P)(D)(N("Just",0))(F.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})()})(zi(u)(D));return{...Q.st,blockFinished:rt(P)(D)(!0)(Q.st.blockFinished)}}g()},I=v(D=>F=>v(S=>G=>{const Q=gt(G)(u.root),V=(()=>{if(Q.tag==="Nothing")return G;if(Q.tag==="Just")return Q._1;g()})();return V===G?U(V)(S):S})(D)((()=>{if(c==="VDown")return F;if(c==="VUp")return se(F);g()})()))({x:sr($(D=>C(D,w))(T)),sink:sr($(D=>C(D,D))(T)),classEdges:[],su:R,blockFinished:R,queue:[]})(h),A=$w(I.classEdges)(I.sink)(c),j=(D,F,S,G)=>{const Q=gt(F)(G),V=gt(F)(a);return(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;g()})()+(()=>{if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1;g()})()+d(D,F,S)},Z=sr($(D=>C(D,!0))(Ro(P.compare)((()=>{const D=(F,S)=>{if(F.tag==="Leaf")return S;if(F.tag==="Node")return D(F._5,kt("Cons",F._4,D(F._6,S)));g()};return jt(le.foldr,D(u.root,H))})()))),M=D=>F=>S=>{const G=L(S,{su:F.su,blockFinished:Z}),Q={phase:D,ppFree:S.free,ppIsRoot:S.isRoot,edgeId:w,delta:0,avail:0,shift:0,freeSu:(()=>{const V=gt((()=>{const Y=gt(S.free)(u.root);if(Y.tag==="Nothing")return S.free;if(Y.tag==="Just")return Y._1;g()})())(F.su);if(V.tag==="Nothing")return!1;if(V.tag==="Just")return V._1;g()})(),hasEdges:G.hasEdges,candCount:(()=>{if(S.isRoot){if(_==="HRight"){const V=gt(S.free)(x);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length;g()}if(_==="HLeft"){const V=gt(S.free)(y);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length}g()}if(_==="HRight"){const V=gt(S.free)(y);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length;g()}if(_==="HLeft"){const V=gt(S.free)(x);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length}g()})()};if(G.edge.tag==="Nothing")return{...F,stack:[...F.stack,S],trace:[...F.trace,Q],x:F.x};if(G.edge.tag==="Just"){const V=G.edge._1.from.node===S.free?C(G.edge._1.from.node,G.edge._1.to.node):C(G.edge._1.to.node,G.edge._1.from.node),Y=j(G.edge._1,V._1,l(G.edge._1,V._1),F.x)-j(G.edge._1,V._2,l(G.edge._1,V._2),F.x),X=gt(V._1)(u.root),q=(()=>{if(X.tag==="Nothing")return V._1;if(X.tag==="Just")return X._1;g()})(),K={...Q,edgeId:N("Just",G.edge._1.id),delta:Y};if(Y>0&&Y<1e300){const et=v(pt=>Tt=>{const Et=gt(Tt)(m),Zt=(()=>{if(Et.tag==="Nothing")return-1;if(Et.tag==="Just")return Et._1;g()})();if(Zt>=0&&Zt<n.length){const Bt=n[Zt],wt=gt(Tt)(e.nodeIndex),mt=(()=>{if(wt.tag==="Nothing")return-2;if(wt.tag==="Just")return wt._1-1|0;g()})();return mt>=0&&mt<Bt.length?Cn(pt)((()=>{const ct=gt(Tt)(F.x),yt=gt(Tt)(a),dt=gt(Bt[mt])(F.x),ht=gt(Bt[mt])(a);return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._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()})()+(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+p(Bt[mt])+J(Tt,Bt[mt]))})()):pt}const bt=gt(Tt)(e.nodeIndex),Ut=(()=>{if(bt.tag==="Nothing")return-2;if(bt.tag==="Just")return bt._1-1|0;g()})();return Ut>=0&&Ut<0?Cn(pt)((()=>{const Bt=gt(Tt)(F.x),wt=gt(Tt)(a),mt=gt([][Ut])(F.x),ct=gt([][Ut])(a);return(()=>{if(Bt.tag==="Nothing")return 0;if(Bt.tag==="Just")return Bt._1;g()})()+(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1;g()})()-((()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()+(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+p([][Ut])+J(Tt,[][Ut]))})()):pt})(Y)(zi(u)(q)),lt=et>0?-et:0,Ct={...F,x:et>0?f(q,lt,F.x):F.x,trace:[...F.trace,{...K,avail:et,shift:lt}]};return et>0?Ct:{...Ct,stack:[...Ct.stack,S]}}if(Y<0&&-Y<1e300){const et=v(pt=>Tt=>{const Et=gt(Tt)(m),Zt=(()=>{if(Et.tag==="Nothing")return-1;if(Et.tag==="Just")return Et._1;g()})();if(Zt>=0&&Zt<n.length){const Bt=n[Zt],wt=gt(Tt)(e.nodeIndex),mt=(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1+1|0;g()})();return mt>=0&&mt<Bt.length?Cn(pt)((()=>{const ct=gt(Bt[mt])(F.x),yt=gt(Bt[mt])(a),dt=gt(Tt)(F.x),ht=gt(Tt)(a);return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._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()})()+(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+p(Tt)+J(Tt,Bt[mt]))})()):pt}const bt=gt(Tt)(e.nodeIndex),Ut=(()=>{if(bt.tag==="Nothing")return 0;if(bt.tag==="Just")return bt._1+1|0;g()})();return Ut>=0&&Ut<0?Cn(pt)((()=>{const Bt=gt([][Ut])(F.x),wt=gt([][Ut])(a),mt=gt(Tt)(F.x),ct=gt(Tt)(a);return(()=>{if(Bt.tag==="Nothing")return 0;if(Bt.tag==="Just")return Bt._1;g()})()+(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1;g()})()-((()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()+(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+p(Tt)+J(Tt,[][Ut]))})()):pt})(-Y)(zi(u)(q)),lt=et>0?et:0,Ct={...F,x:et>0?f(q,lt,F.x):F.x,trace:[...F.trace,{...K,avail:et,shift:lt}]};return et>0?Ct:{...Ct,stack:[...Ct.stack,S]}}return{...F,stack:[...F.stack,S],trace:[...F.trace,K],x:F.x}}g()},W=v(M(Ow))({x:sr($(D=>C(D,(()=>{const F=gt(D)(u.root),S=(()=>{if(F.tag==="Nothing")return D;if(F.tag==="Just")return F._1;g()})(),G=gt(S)(I.x),Q=gt((()=>{const Y=gt(S)(I.sink);if(Y.tag==="Nothing")return S;if(Y.tag==="Just")return Y._1;g()})())(A),V=(()=>{if(G.tag==="Just")return G._1;if(G.tag==="Nothing")return w;g()})();return(()=>{if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1;g()})()+(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;g()})()})()))(T)),su:I.su,stack:[],trace:[]})(I.queue),O=v(M(Hw))({...W,stack:[]})(se(W.stack));return{x:O.x,queue:I.queue,trace:O.trace}},Yw=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>_=>Xw(t)(e)(n)(r)(o)(i)(s)(a)(u)(c)(_).x,Uw=t=>e=>n=>r=>o=>i=>{const s=(u,c,_)=>{const d=gt(c)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;g()})(),f=u.from.node===c?u.from.port:u.to.node===c?u.to.port:w;if(f.tag==="Just"){const h=gt(c)(e);if(h.tag==="Just"){const p=re(m=>m.id===f._1)(h._1);if(p.tag==="Just"){const m=nt(p._1.offset)*nt(4);return _==="North"||_==="South"?m:0}if(p.tag==="Nothing"){const m=oi(o)(u.id)(_)(l);return _==="North"||_==="South"?m:0}g()}if(h.tag==="Nothing"){const p=oi(o)(u.id)(_)(l);return _==="North"||_==="South"?p:0}g()}if(f.tag==="Nothing"){const h=oi(o)(u.id)(_)(l);return _==="North"||_==="South"?h:0}g()},a=u=>c=>_=>d=>{let l=u,f=c,h=_,p=d,m=!0,J;for(;m;){const x=l,y=f,T=h,b=zt(L=>w,L=>E=>N("Just",{head:L,tail:E}),p);if(b.tag==="Nothing"){m=!1,J=x;continue}if(b.tag==="Just"){const L=b._1.head,E=re(z=>z.from.node===T&&z.to.node===L||z.from.node===L&&z.to.node===T)(r),B=(()=>{if(E.tag==="Nothing")return y+0;if(E.tag==="Just")return y+(s(E._1,T,E._1.from.node===T?Se:Le)-s(E._1,L,E._1.from.node===L?Se:Le));g()})();l=rt(P)(L)(B)(x),f=B,h=L,p=b._1.tail;continue}g()}return J};return v(u=>c=>{const _=zt(f=>w,f=>h=>N("Just",{head:f,tail:h}),zi(t)(c)),d=(()=>{if(_.tag==="Nothing")return rt(P)(c)(0)(R);if(_.tag==="Just")return a(rt(P)(_._1.head)(0)(R))(0)(_._1.head)(_._1.tail);g()})(),l=v(f=>h=>ir(f)(-h._2))(0)(bc(d));return v(f=>h=>rt(P)(h._1)(h._2+l)(f))(u)(bc(d))})(R)(Ro(P.compare)((()=>{const u=(c,_)=>{if(c.tag==="Leaf")return _;if(c.tag==="Node")return u(c._5,kt("Cons",c._4,u(c._6,_)));g()};return jt(le.foldr,u(t.root,H))})()))},Kw=t=>e=>{const n=(o,i,s)=>Re(3)(i)==="$d:"&&p_(e1,(()=>{const a=gt(i)(t.preds);if(a.tag==="Nothing")return[];if(a.tag==="Just")return a._1;g()})()),r=o=>i=>s=>a=>u=>c=>_=>{let d=o,l=i,f=a,h=c,p=_,m=!0,J;for(;m;){const x=d,y=l,T=f,b=h,L=p,E=y.length;if(L>=E){m=!1,J=x;continue}const B=L>=0&&L<y.length?N("Just",y[L]):w,z=(()=>{if(B.tag==="Nothing")return"";if(B.tag==="Just")return B._1;g()})(),U=n(t,z);if(L===(E-1|0)||U){const I=(()=>{if(U){const A=gt(z)(t.preds),j=(()=>{if(A.tag==="Nothing")return[];if(A.tag==="Just")return A._1;g()})();if(0<j.length){const Z=T-1|0,M=gt(j[0])(t.nodeIndex);if(M.tag==="Nothing")return Z;if(M.tag==="Just")return M._1;g()}}return T-1|0})();d=v(A=>j=>{if(j>=0&&j<y.length){const Z=y[j];return n(t,Z)?A:v(M=>W=>{const O=gt(W)(t.nodeIndex),D=(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;g()})();return D<b||D>I?rt(P)(W+"\u2192"+Z)()(M):M})(A)((()=>{const M=gt(Z)(t.preds);if(M.tag==="Nothing")return[];if(M.tag==="Just")return M._1;g()})())}return n(t,"")?A:v(Z=>M=>{const W=gt(M)(t.nodeIndex),O=(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})();return O<b||O>I?rt(P)(M+"\u2192")()(Z):Z})(A)((()=>{const Z=gt("")(t.preds);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;g()})())})(x)(Kt(0,L)),l=y,f=T,h=I,p=L+1|0;continue}d=x,l=y,f=T,h=b,p=L+1|0}return J};return e.length<3?R:v(o=>i=>{if(i>=0&&i<e.length){const s=e[i];return r(o)((()=>{const a=i+1|0;return a>=0&&a<e.length?e[a]:[]})())(s)(s.length)(i)(0)(0)}return r(o)((()=>{const s=i+1|0;return s>=0&&s<e.length?e[s]:[]})())([])(0)(i)(0)(0)})(R)(Kt(1,e.length-2|0))},jw=t=>e=>n=>r=>o=>{const i=ln(e),s=v(a=>u=>{const c=v(_=>d=>{const l=(()=>{if(o==="HRight"){const m=gt(d)(t.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()}if(o==="HLeft"){const m=gt(d)(t.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}g()})(),f=l.length;if(f===0)return _;const h=yr(f-1|0,2),p=yr(f,2);return v(m=>J=>{if((()=>{const x=gt(d)(m.align);if(x.tag==="Nothing")return d!==d;if(x.tag==="Just")return x._1!==d;g()})())return m;if(J>=0&&J<l.length){const x=gt(l[J])(t.nodeIndex),y=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})();if(!(w1(l[J]+"\u2192"+d)(n)||w1(d+"\u2192"+l[J])(n))&&(()=>{if(r==="VDown")return m.r<y;if(r==="VUp")return m.r>y;g()})()){const T=gt(l[J])(m.root),b=(()=>{if(T.tag==="Nothing")return l[J];if(T.tag==="Just")return T._1;g()})();return{root:rt(P)(d)(b)(m.root),align:rt(P)(l[J])(d)(rt(P)(d)(b)(m.align)),r:y}}}return m})(_)((()=>{if(r==="VDown")return Kt(h,p);if(r==="VUp")return se(Kt(h,p));g()})())})({root:a.root,align:a.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;g()})()})((()=>{if(r==="VDown")return u;if(r==="VUp")return se(u);g()})());return{root:c.root,align:c.align}})({root:sr($(a=>C(a,a))(i)),align:sr($(a=>C(a,a))(i))})((()=>{if(o==="HRight")return e;if(o==="HLeft")return se(e);g()})());return{root:s.root,align:s.align}},na=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>{const _=jw(e)(n)(a)(u)(c),d=Uw(_)(o)(r)(i)(s)(c);return V0()(l=>f=>N("Just",(()=>{const h=gt(l)(d);if(h.tag==="Nothing")return f+0;if(h.tag==="Just")return f+h._1;g()})()))(Yw(t)(e)(n)(r)(o)(i)(s)(d)(_)(u)(c))},N1=t=>e=>Ht(n=>r=>v(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=Kt(0,e.length-1|0);return n<1?[]:Dt(0,n,o)})()))(e),Zw=t=>e=>n=>r=>o=>i=>s=>{const a=Ww(0)(e.length-1|0),u=nt(t.layerGap),c=s(E0(a,u)),_=Iw(g1(o)(c)(r)(i)(R))(c);return $(d=>{const l=qw(d)(_);return l.tag==="Just"&&l._1>0?ir(u)(2+nt(l._1-1|0)*2.5):u})(Kt(0,a-1|0))},v1=t=>e=>n=>r=>p_(o=>v(i=>s=>{if(!i.ok)return i;const a=gt(s)(r),u=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})(),c=gt(s)(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),tJ=t=>e=>n=>r=>{const o=It(i=>s=>it.compare(i.w)(s.w))($(i=>({l:i,w:J1(i)}))(ft(v1()(e)(n),r)));return 0<o.length?N("Just",o[0].l):w},eJ=t=>e=>{const n=sr(ln($(Ht(o=>i=>C(i,o)))(t))),r=o=>It(i=>s=>ot.compare((()=>{const a=gt(i)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})())((()=>{const a=gt(s)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})()))(o);return{preds:(()=>{const o=i=>{if(i.tag==="Leaf")return R;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(v(i=>s=>Ft(P)(he)(s.to.node)([s.from.node])(i))(R)(e))})(),succs:(()=>{const o=i=>{if(i.tag==="Leaf")return R;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(v(i=>s=>Ft(P)(he)(s.from.node)([s.to.node])(i))(R)(e))})(),nodeIndex:n}},nJ=t=>e=>{const n=It(d=>l=>it.compare(d.w)(l.w))(Ht(d=>l=>({i:d,l,w:J1(l)}))(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,s=(()=>{if(i.tag==="Just")return(d=>l=>{let f=d,h=l,p=!0,m;for(;p;){const J=f,x=h;if(x.tag==="Nil"){p=!1,m=J;continue}if(x.tag==="Cons"){f=Cn(J)(x._1),h=x._2;continue}g()}return m})(999999)((()=>{const d=(l,f)=>{if(l.tag==="Leaf")return f;if(l.tag==="Node")return d(l._5,kt("Cons",l._4,d(l._6,f)));g()};return d(i._1,H)})());if(i.tag==="Nothing")return 0;g()})(),a=d=>v(l=>f=>ir(l)((()=>{const h=gt(f._1)(t);if(h.tag==="Nothing")return f._2+1;if(h.tag==="Just")return f._2+h._1._1;g()})()))(-999999)(bc(d)),u=o>=0&&o<e.length?N("Just",e[o]):w,c=(()=>{if(u.tag==="Just")return a(u._1);if(u.tag==="Nothing")return 0;g()})(),_=Qe(d=>l=>{const f=h=>{if(h.tag==="Leaf")return R;if(h.tag==="Node")return te("Node",h._1,h._2,h._3,h._4+l,f(h._5),f(h._6));g()};return f(d)},e,Ht(d=>l=>Mr(d)(2)===0?s-(f=>h=>{let p=f,m=h,J=!0,x;for(;J;){const y=p,T=m;if(T.tag==="Nil"){J=!1,x=y;continue}if(T.tag==="Cons"){p=Cn(y)(T._1),m=T._2;continue}g()}return x})(999999)((()=>{const f=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return f(h._5,kt("Cons",h._4,f(h._6,p)));g()};return f(l,H)})()):c-a(l))(e));return Vw(v(d=>l=>{const f=It(it.compare)(vt(gt(l))(_));return rt(P)(l)(f.length===4?1<f.length&&2<f.length?(f[1]+f[2])/2:0:0<f.length?f[0]:0)(d)})(R)(Ro(P.compare)(ln($(d=>{const l=f=>{if(f.tag==="Leaf")return R;if(f.tag==="Node")return te("Node",f._1,f._2,f._3,void 0,l(f._5),l(f._6));g()};return jt(rn.foldr,l(d))})(_)))))},rJ=t=>e=>n=>r=>o=>i=>{const s=eJ(e)(o),a=Kw(s)(e),u={nodeGap:t.nodeGap*4|0},c=Ae(P.compare,Be,sr($(f=>C(f,C(1,1)))(ft(e1,ln(e)))),(()=>{const f=h=>{if(h.tag==="Leaf")return R;if(h.tag==="Node")return te("Node",h._1,h._2,h._3,C(h._4._1*nt(4),h._4._2),f(h._5),f(h._6));g()};return f(n)})()),_=[na(u)(s)(e)(c)(r)(o)(i)(a)(p1)(y1),na(u)(s)(e)(c)(r)(o)(i)(a)(m1)(y1),na(u)(s)(e)(c)(r)(o)(i)(a)(p1)(x1),na(u)(s)(e)(c)(r)(o)(i)(a)(m1)(x1)],d=nJ(c)(_);if(v1()(e)(c)(d))return d;const l=tJ()(e)(c)(_);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return _[0];g()},oJ=t=>e=>n=>r=>{const o=d_(w,a_,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 $(s=>s.node===n?{...s,position:C(i._1+r._1,i._2+r._2)}:s)(t)}g()},iJ=t=>e=>n=>r=>{const o=ft(s=>tn(Zn)(s.node)(e),t),i=(()=>{if(n==="Vertical"){if(r==="Start")return v(s=>a=>Cn(s)(a.position._1))(99999)(o);if(r==="End")return v(s=>a=>ir(s)(a.position._1))(0)(o);if(r==="Center"){const s=v(a=>u=>a+u.position._1)(0)(o);return o.length===0?0:s/nt(o.length)}g()}if(n==="Horizontal"){if(r==="Start")return v(s=>a=>Cn(s)(a.position._2))(99999)(o);if(r==="End")return v(s=>a=>ir(s)(a.position._2))(0)(o);if(r==="Center"){const s=v(a=>u=>a+u.position._2)(0)(o);return o.length===0?0:s/nt(o.length)}}g()})();return $(s=>{if(tn(Zn)(s.node)(e)){if(n==="Vertical")return{...s,position:C(i,s.position._2)};if(n==="Horizontal")return{...s,position:C(s.position._1,i)};g()}return s})(t)},sJ=t=>e=>v(n=>r=>r.tag==="AlignGroup"?iJ(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?oJ(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),aJ=t=>e=>n=>r=>o=>i=>s=>a=>{const u=$(d=>v(l=>f=>ir(l)((()=>{const h=gt(f)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;g()})()))(1)(d))(n),c=rJ(t)(n)(r)(o)(i)(a),_=N1(Zw(t)(n)(r)(o)(i)(s)(d=>{const l=N1(d)(u);return ln(Ht(f=>h=>Ht(p=>m=>({node:m,position:C((()=>{const J=gt(m)(c);return(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;g()})()/nt(4)})(),f>=0&&f<l.length?l[f]:0),size:(()=>{const J=Re(3)(m)==="$d:"?C(0,1):C(1,1),x=gt(m)(r);if(x.tag==="Nothing")return J;if(x.tag==="Just")return x._1;g()})(),layer:f,order:p}))(h))(n))}))(u);return sJ(e)(ln(Ht(d=>l=>Ht(f=>h=>({node:h,position:C((()=>{const p=gt(h)(c);return(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})()/nt(4)})(),d>=0&&d<_.length?_[d]:0),size:(()=>{const p=Re(3)(h)==="$d:"?C(0,1):C(1,1),m=gt(h)(r);if(m.tag==="Nothing")return p;if(m.tag==="Just")return m._1;g()})(),layer:d,order:f}))(l))(n)))},Cc=Ru(Ls)(so(32)),T1=Ru(Ls)(so(31)),Wi=(()=>{const t=Rm("25214903917");if(t.tag==="Nothing")return R_;if(t.tag==="Just")return t._1;g()})(),qi=Au(Ru(Ls)(so(48)))(Ls),uJ=t=>{const e=Fm(t);return Bi(F_((()=>{if(e.tag==="Nothing")return R_;if(e.tag==="Just")return e._1;g()})())(Wi))(qi)},kc=so(11),ra=t=>e=>{const n=Bi(Cs(ks(e)(Wi))(kc))(qi);return C((()=>{const r=y_(Bm(Fu(n)(so(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},cJ=t=>{const e=ra(26)(t),n=ra(27)(e._2);return C((nt(e._1)*xu(2)(27)+nt(n._1))/xu(2)(53),n._2)},gJ=t=>e=>{const n=v(r=>o=>{const i=cJ(r.finalR);return{rs:[...r.rs,i._1],finalR:i._2}})({rs:[],finalR:t})(e);return C($(r=>r.x)(It(r=>o=>it.compare(r.k)(o.k))(Qe(r=>o=>({x:r,k:o}),e,n.rs))),n.finalR)},_J=t=>{const e=Bi(Cs(ks(t)(Wi))(kc))(qi),n=Bi(Cs(ks(e)(Wi))(kc))(qi);return C(Cs(ks((()=>{const r=Fu(e)(so(16));return Q_.compare(r)(T1)!=="LT"?Au(r)(Cc):r})())(Cc))((()=>{const r=Fu(n)(so(16));return Q_.compare(r)(T1)!=="LT"?Au(r)(Cc):r})()),n)},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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},oa=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Lc=ce(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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ia=ce(P)(Mt),fJ=mu(Ti),dJ=v(er)(0),lJ=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},b1=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},hJ=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const o=Fr(Yt,w,t,n[e],n);if(o.tag==="Just")return Fr(Yt,w,e,r,o._1);if(o.tag==="Nothing")return w;g()}}return w},pJ=t=>e=>n=>r=>o=>Lc(v(i=>s=>{const a=It(u=>c=>ot.compare((()=>{const _=Oi(u.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;g()})())((()=>{const _=Oi(c.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;g()})()))(ft(u=>oa(u.to.node)(n),ft(u=>u.from.node===s,r)));return{ranks:[...i.ranks,...Ht(u=>c=>C(c.id,nt((i.rankSum+u|0)+1|0)))(a)],rankSum:i.rankSum+a.length|0}})({ranks:[],rankSum:0})(t).ranks),mJ=t=>e=>n=>r=>o=>Lc(v(i=>s=>{const a=It(c=>_=>{const d=ot.compare((()=>{const l=ii(_.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=ii(c.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})());return d==="EQ"?ot.compare((()=>{const l=Oi(c.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})())((()=>{const l=Oi(_.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})()):d})(ft(c=>oa(c.from.node)(n),ft(c=>c.to.node===s,r))),u=a.length;return{ranks:[...i.ranks,...Ht(c=>_=>C(_.id,nt((i.rankSum+u|0)-c|0)))(a)],rankSum:i.rankSum+u|0}})({ranks:[],rankSum:0})(t).ranks),Sc=t=>e=>n=>{const r=ia(Ht(a=>u=>C(u,a))(t)),o=ia(Ht(a=>u=>C(u,a))(e)),i=vt(a=>{const u=ii(a.from.node)(r),c=ii(a.to.node)(o);if(u.tag==="Just"&&c.tag==="Just")return N("Just",C(u._1,c._1));const _=ii(a.from.node)(o),d=ii(a.to.node)(r);return _.tag==="Just"&&d.tag==="Just"?N("Just",C(d._1,_._1)):w})(n),s=i.length;return v(a=>u=>v(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)(a)(Kt(u+1|0,s-1|0)))(0)(Kt(0,s-2|0))},yJ=t=>e=>n=>r=>{const o=i=>s=>{let a=i,u=s,c=!0,_;for(;c;){const d=a,l=u;if(l>=(d.length-1|0)){c=!1,_=d;continue}if(l>=0&&l<d.length){const f=l+1|0;if(f>=0&&f<d.length){const h=d[l],p=d[f];if(Ne(y=>y.before===h&&y.after===p,r)){a=d,u=l+1|0;continue}const m=Fr(Yt,w,l,p,d),J=(()=>{if(m.tag==="Just")return Fr(Yt,w,l+1|0,h,m._1);if(m.tag==="Nothing")return w;g()})(),x=(()=>{if(J.tag==="Nothing")return d;if(J.tag==="Just")return J._1;g()})();if(Sc(e)(x)(n)<Sc(e)(d)(n)){a=x,u=l+1|0;continue}a=d,u=l+1|0;continue}c=!1,_=d;continue}c=!1,_=d}return _};return(i=>{let s=i,a=!0,u;for(;a;){const c=s,_=o(c)(0);if(fJ(_)(c)){a=!1,u=c;continue}s=_}return u})(t)},sa=t=>e=>v(n=>r=>{if(r>=0&&r<t.length){const o=t[r],i=r+1|0;if(i>=0&&i<t.length)return n+Sc(o)(t[i])(e)|0}return n})(0)(Kt(0,t.length-2|0)),xJ=(()=>{const t=e=>{if(e.length<7){const i=s=>a=>{let u=s,c=a,_=!0,d;for(;_;){const l=u,f=c,h=f-1|0;if(h>=0&&h<l.length){if(f>=0&&f<l.length&&f>0&&l[h].key>l[f].key){const p=hJ(f-1|0)(f)(l);if(p.tag==="Just"){u=p._1,c=f-1|0;continue}if(p.tag==="Nothing"){_=!1,d=l;continue}g()}_=!1,d=l;continue}_=!1,d=l}return d};return v(s=>a=>i(s)(a))(e)(Kt(1,e.length-1|0))}const n=yr(e.length,2),r=t(Dt(0,n,e)),o=t(Dt(n,e.length,e));return(i=>s=>a=>{let u=i,c=s,_=a,d=!0,l;for(;d;){const f=u,h=c,p=_;if(h>=0&&h<r.length){if(p>=0&&p<o.length){if(r[h].key>o[p].key){u=Pt(f)(o[p]),c=h,_=p+1|0;continue}u=Pt(f)(r[h]),c=h+1|0,_=p;continue}d=!1,l=[...f,...h<1?r:Dt(h,r.length,r)];continue}d=!1,l=[...f,...p<1?o:Dt(p,o.length,o)]}return l})([])(0)(0)};return t})(),wJ=t=>e=>n=>{const r=vt(c=>c.tag==="OrderConstraint"?N("Just",{before:c._1.before,after:c._1.after}):w)(t.constraints),o=c=>v(_=>d=>{const l=d.after,f=d.before,h=ro(Yt,w,m=>m===f,_),p=ro(Yt,w,m=>m===l,_);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=h_(Yt,w,h._1,_),J=(()=>{if(m.tag==="Nothing")return _;if(m.tag==="Just")return m._1;g()})(),x=l_(Yt,w,p._1,f,J);if(x.tag==="Nothing")return J;if(x.tag==="Just")return x._1;g()}return _})(c)(r),i=Lc(Ht(c=>_=>C(_.id,c))(n)),s=(c,_,d)=>{const l=c.length;return v(f=>h=>{const p=_?h-1|0:h+1|0,m=p>=0&&p<f._1.length?N("Just",f._1[p]):w;if(m.tag==="Just"){const J=h>=0&&h<f._1.length?N("Just",f._1[h]):w;if(J.tag==="Just"){const x=ia(Ht(E=>B=>C(B,E))(m._1)),y=ia(Ht(E=>B=>C(B,E))(J._1)),T=_?pJ(m._1)(x)(y)(n)(i):mJ(m._1)(x)(y)(n)(i),b=v(E=>B=>{const z=vt(I=>Oi(I.id)(T))(ft(_?I=>I.to.node===B._2&&oa(I.from.node)(x):I=>I.from.node===B._2&&oa(I.to.node)(x),n));if(z.length===0)return{...E,items:[...E.items,{n:B._2,key:w,origIdx:B._1}]};const U=ra(24)(E.r);return{items:[...E.items,{n:B._2,key:N("Just",(dJ(z)+(nt(U._1)*4172325152040912e-24-.03500000014901161))/nt(z.length)),origIdx:B._1}],r:U._2}})({items:[],r:f._2})(Ht(Gn)(J._1)),L=Fr(Yt,w,h,yJ(o($(E=>E.n)(xJ((()=>{const E=b.items,B=z=>U=>{let I=z,A=U,j=!0,Z;for(;j;){const M=I,W=A;if(M>=0&&M<E.length){if(E[M].key.tag==="Just"){j=!1,Z=E[M].key._1;continue}if(E[M].key.tag==="Nothing"){I=M+1|0,A=W;continue}g()}j=!1,Z=W}return Z};return(z=>U=>I=>{let A=z,j=U,Z=I,M=!0,W;for(;M;){const O=A,D=j,F=Z;if(O>=0&&O<E.length){if(E[O].key.tag==="Just"){A=O+1|0,j=E[O].key._1,Z=[...F,{n:E[O].n,key:E[O].key._1,origIdx:E[O].origIdx}];continue}if(E[O].key.tag==="Nothing"){const S=(D+B(O+1|0)(D+1))/2;A=O+1|0,j=S,Z=[...F,{n:E[O].n,key:S,origIdx:E[O].origIdx}];continue}g()}M=!1,W=F}return W})(0)(-1)([])})()))))(m._1)(n)(r),f._1);if(L.tag==="Just")return C(L._1,b.r);if(L.tag==="Nothing")return C(f._1,f._2);g()}if(J.tag==="Nothing")return C(f._1,f._2);g()}if(m.tag==="Nothing")return C(f._1,f._2);g()})(C(c,d))(_?Kt(1,l-1|0):se(Kt(0,l-2|0)))},a=v(c=>_=>rt(P)(_.from.node)()(rt(P)(_.to.node)()(c)))(R)(n),u=v(c=>_=>{if(c.result.crossings===0)return c;const d=x=>y=>T=>b=>{let L=x,E=y,B=T,z=b,U=!0,I;for(;U;){const A=L,j=E,Z=B,M=z;if(Z===0){U=!1,I={layout:A,crossings:0,random:M};continue}const W=s(A,j,M),O=sa(W._1)(n);if(O<Z){L=W._1,E=!j,B=O,z=W._2;continue}U=!1,I={layout:A,crossings:Z,random:W._2}}return I},l=ra(1)(c.result.random),f=l._1!==0,h=t.modelOrder.tag==="Leaf",p=(c.firstTry||c.secondTry)&&!h?c.firstTry:f,m=(()=>{if(!h){const b=s(e,p,l._2);return d(b._1)(!p)(sa(b._1)(n))(b._2)}const x=p?0:lJ(0)(e.length-1|0),y=x>=0&&x<e.length?N("Just",e[x]):w;if(y.tag==="Just"&&y._1.length>1){const b=ft(L=>b1(L)(a),y._1);if(b.length>1){const L=gJ(l._2)(b),E=L._1,B=Fr(Yt,w,x,o(v(z=>U=>b1(U)(a)?z.idx>=0&&z.idx<E.length?{idx:z.idx+1|0,result:[...z.result,E[z.idx]]}:{idx:z.idx,result:[...z.result,U]}:{idx:z.idx,result:[...z.result,U]})({idx:0,result:[]})(y._1).result),e);if(B.tag==="Just"){const z=s(B._1,p,L._2);return d(z._1)(!p)(sa(z._1)(n))(z._2)}}}const T=s(e,p,l._2);return d(T._1)(!p)(sa(T._1)(n))(T._2)})(),J=c.secondTry?!1:c.secondTry;return c.firstTry?{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:c.firstTry,secondTry:J}})({result:{layout:e,crossings:1e9,random:Bi(F_(_J(uJ(1))._1)(Wi))(qi)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Kt(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:u.layout},JJ=t=>t,C1=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},on=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},si=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Hi=(()=>{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"?De:r==="GT"?Ie:P.compare(e._2)(n._2)},Eq0:()=>t}})(),NJ=ce(P)(Mt),vJ=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 s=Hi.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},TJ=JJ("Greedy"),Ec=t=>e=>n=>v(r=>o=>{if(o.from.node===o.to.node)return r;if(o.from.node===e&&!C1(o.to.node)(r.marks)){const i=on(o.to.node)(r.inDeg),s=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;g()})(),a=rt(P)(o.to.node)(s)(r.inDeg);return(()=>{const u=on(o.to.node)(r.outDeg);return s<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;g()})()&&!tn(Zn)(o.to.node)(r.sources)})()?{...r,inDeg:a,sources:[...r.sources,o.to.node]}:{...r,inDeg:a}}if(o.to.node===e&&!C1(o.from.node)(r.marks)){const i=on(o.from.node)(r.outDeg),s=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;g()})(),a=rt(P)(o.from.node)(s)(r.outDeg);return(()=>{const u=on(o.from.node)(r.inDeg);return s<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;g()})()&&!tn(Zn)(o.from.node)(r.sinks)})()?{...r,outDeg:a,sinks:[...r.sinks,o.from.node]}:{...r,outDeg:a}}return r})({...n,remaining:ft(r=>r!==e,n.remaining)})(t),bJ=v(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return rt(P)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return rt(P)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return rt(P)(e._1.node)(99999)(t)}return t})(R),k1=t=>e=>n=>{const r=on(e)(t),o=on(n)(t);return r.tag==="Just"&&o.tag==="Just"&&r._1>o._1},L1=t=>e=>n=>r=>{if(si(n)(r.visited)||si(n)(r.visiting))return r;const o=v(CJ(t)(e)(n))({...r,visiting:rt(P)(n)()(r.visiting)})((()=>{const i=on(n)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;g()})());return{...o,visiting:zo(P)(n)(o.visiting),visited:rt(P)(n)()(o.visited)}},CJ=t=>e=>n=>r=>o=>k1(t)(n)(o)?{...r,backEdges:rt(Hi)(C(n,o))()(r.backEdges)}:si(o)(r.visiting)?{...r,backEdges:rt(Hi)(C(n,o))()(r.backEdges)}:si(o)(r.visited)?r:L1(t)(e)(o)(r),kJ=t=>e=>n=>{const r=l=>{let f=l,h=!0,p;for(;h;){const m=f,J=zt(x=>w,x=>y=>N("Just",{head:x,tail:y}),m.sinks);if(J.tag==="Just"){f=Ec(n)(J._1.head)({...m,sinks:J._1.tail,marks:rt(P)(J._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(J.tag==="Nothing"){const x=zt(y=>w,y=>T=>N("Just",{head:y,tail:T}),m.sources);if(x.tag==="Just"){f=Ec(n)(x._1.head)({...m,sources:x._1.tail,marks:rt(P)(x._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(x.tag==="Nothing"){const y=b=>{const L=on(b)(m.outDeg),E=on(b)(m.inDeg);return(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;g()})()-(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;g()})()|0},T=It(b=>L=>{const E=ot.compare(y(L))(y(b));return E==="EQ"?ot.compare((()=>{const B=on(b)(e);if(B.tag==="Nothing")return 1e6;if(B.tag==="Just")return B._1;g()})())((()=>{const B=on(L)(e);if(B.tag==="Nothing")return 1e6;if(B.tag==="Just")return B._1;g()})()):E})(m.remaining);if(0<T.length){const b=T[0];f=Ec(n)(b)({...m,remaining:ft(L=>L!==b,m.remaining),marks:rt(P)(b)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}g()}return p},o=Ro(P.compare)([...$(l=>l.from.node)(n),...$(l=>l.to.node)(n)]),i=ft(l=>l.from.node!==l.to.node,n),s=v(l=>f=>Ft(P)(xe)(f.to.node)(1)(l))(R)(i),a=v(l=>f=>Ft(P)(xe)(f.from.node)(1)(l))(R)(i),u=ft(l=>{const f=on(l)(s);if(f.tag==="Nothing")return!0;if(f.tag==="Just")return f._1===0;g()},o),c=ft(l=>{const f=on(l)(a);if(f.tag==="Nothing")return!0;if(f.tag==="Just")return f._1===0;g()},o),_=o.length+1|0,d=v(l=>f=>{const h=on(f)(l);return h.tag==="Just"&&h._1<0?rt(P)(f)(h._1+_|0)(l):l})(r({remaining:ft(l=>!tn(Zn)(l)(u)&&!tn(Zn)(l)(c),o),marks:R,inDeg:s,outDeg:a,sources:u,sinks:c,nextLeft:1,nextRight:-1}).marks)(o);return v(l=>f=>{if(f.from.node===f.to.node)return l;if(k1(t)(f.from.node)(f.to.node))return rt(Hi)(C(f.from.node,f.to.node))()(l);const h=on(f.from.node)(d),p=on(f.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?rt(Hi)(C(f.from.node,f.to.node))()(l):l})(R)(n)},LJ=v(t=>e=>Ft(P)(he)(e.from.node)([e.to.node])(t))(R),SJ=t=>e=>{const n=LJ(e),r=Ro(P.compare)([...$(i=>i.from.node)(e),...$(i=>i.to.node)(e)]),o=v(i=>s=>rt(P)(s.to.node)()(i))(R)(e);return v(i=>s=>L1(t)(n)(s)(i))({visiting:R,visited:R,backEdges:R})([...ft(i=>!si(i)(o),r),...ft(i=>si(i)(o),r)]).backEdges},EJ=t=>e=>n=>r=>{const o=NJ(Ht(a=>u=>C(u,a))(e)),i=bJ(n),s=(()=>{if(t==="DepthFirst")return SJ(i)(r);if(t==="Greedy")return kJ(i)(o)(r);g()})();return{edges:$(a=>vJ(C(a.from.node,a.to.node))(s)?{...a,from:a.to,to:a.from}:a)(r),reversedEdges:s}},S1=Mt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),Te=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},be=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},$i=t=>e=>n=>r=>S1(o=>n>=o.x&&n<o.x+o.w&&e>o.y&&t<o.y+o.h)(r),aa=t=>e=>n=>r=>$i(Te(e)(n))(be(e)(n))(r)(t),ua=nt(4),GJ=ys(t=>{if(t.direction==="H"){const e=Te(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:be(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=Te(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:be(t.start._2)(t.end._2)-e}]}g()}),Vi=Ci(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})())}),PJ=t=>e=>n=>{const r=zt(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=Qr(r._1.tail);if(i.tag==="Nothing"){const s=o.length-1|0;return s>=0&&s<o.length&&(o[s].direction==="H"?n.direction==="H":o[s].direction==="V"&&n.direction==="V")?[...(()=>{const a=o.length-1|0;return a<1?[]:Dt(0,a,o)})(),{start:o[s].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()},Xi=t=>{const e=r=>o=>{const i=zt(s=>w,s=>a=>N("Just",{head:s,tail:a}),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=zt(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()},Yi=t=>e=>n=>r=>S1(o=>n>=o.y&&n<o.y+o.h&&e>o.x&&t<o.x+o.w)(r),Ui=t=>e=>n=>r=>Yi(Te(e)(n))(be(e)(n))(r)(t),BJ=t=>e=>n=>r=>{const o=n+2|0,i=o<1?e:Dt(o,e.length,e),s=n<1?[]:Dt(0,n,e),a=(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,d=_>=0&&_<e.length?N("Just",e[_]):w;if(d.tag==="Just"){const l=c._1.start._1===d._1.end._1&&(!u||c._1.direction==="V")&&(!a||d._1.direction==="V")&&!aa(t)(Te(c._1.start._2)(d._1.end._2))(be(c._1.start._2)(d._1.end._2))(c._1.start._1)?N("Just",[...s,{start:c._1.start,end:d._1.end,direction:me},...i]):w,f=c._1.start._2===d._1.end._2&&(!u||c._1.direction==="H")&&(!a||d._1.direction==="H")&&!Ui(t)(Te(c._1.start._1)(d._1.end._1))(be(c._1.start._1)(d._1.end._1))(c._1.start._2)?N("Just",[...s,{start:c._1.start,end:d._1.end,direction:pe},...i]):w;return l.tag==="Nothing"?f:l}if(d.tag==="Nothing")return w;g()}if(c.tag==="Nothing")return w;g()},DJ=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,s;for(;i;){const a=o;if((a+1|0)>=n){i=!1,s=e;continue}const u=BJ(t)(e)(a)(n);if(u.tag==="Just"){i=!1,s=u._1;continue}if(u.tag==="Nothing"){o=a+1|0;continue}g()}return s})(0)},IJ=t=>e=>n=>r=>{const o=(l,f,h)=>!aa(t)(Te(f)(h))(be(f)(h))(l),i=n+3|0,s=i<1?e:Dt(i,e.length,e),a=n<1?[]:Dt(0,n,e),u=(n+2|0)===(r-1|0),c=n===0,_=(l,f,h)=>!Ui(t)(Te(f)(h))(be(f)(h))(l),d=n>=0&&n<e.length?N("Just",e[n]):w;if(d.tag==="Just"){const l=n+2|0,f=l>=0&&l<e.length?N("Just",e[l]):w;if(f.tag==="Just"){const h=d._1.start._1===f._1.end._1&&(!c||d._1.direction==="V")&&(!u||f._1.direction==="V")&&o(d._1.start._1,d._1.start._2,f._1.end._2)?N("Just",[...a,{start:d._1.start,end:f._1.end,direction:me},...s]):d._1.start._2===f._1.end._2&&(!c||d._1.direction==="H")&&(!u||f._1.direction==="H")&&_(d._1.start._2,d._1.start._1,f._1.end._1)?N("Just",[...a,{start:d._1.start,end:f._1.end,direction:pe},...s]):w,p=(!c||d._1.direction==="V")&&(!u||f._1.direction==="H")&&o(d._1.start._1,d._1.start._2,f._1.end._2)&&_(f._1.end._2,d._1.start._1,f._1.end._1)?N("Just",[...a,{start:d._1.start,end:C(d._1.start._1,f._1.end._2),direction:me},{start:C(d._1.start._1,f._1.end._2),end:f._1.end,direction:pe},...s]):w,m=(!c||d._1.direction==="H")&&(!u||f._1.direction==="V")&&_(d._1.start._2,d._1.start._1,f._1.end._1)&&o(f._1.end._1,d._1.start._2,f._1.end._2)?N("Just",[...a,{start:d._1.start,end:C(f._1.end._1,d._1.start._2),direction:pe},{start:C(f._1.end._1,d._1.start._2),end:f._1.end,direction:me},...s]):w,J=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?J:h}if(f.tag==="Nothing")return w;g()}if(d.tag==="Nothing")return w;g()},AJ=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,s;for(;i;){const a=o;if((a+2|0)>=n){i=!1,s=e;continue}const u=IJ(t)(e)(a)(n);if(u.tag==="Just"){i=!1,s=u._1;continue}if(u.tag==="Nothing"){o=a+1|0;continue}g()}return s})(0)},RJ=t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const s=r,a=Xi(Vi(DJ(t)(AJ(t)(s))));if(a.length<s.length){r=a;continue}o=!1,i=a}return i};return n=>e(Xi(Vi(n)))},FJ=t=>e=>n=>r=>{const o=Te(n)(r),i=be(n)(r),s=ft(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=It(c=>_=>it.compare(c.x)(_.x))(s);return 0<u.length?u[0].x-1:(n+r)/2}const a=It(u=>c=>it.compare(c.x)(u.x))($(u=>({...u,x:u.x+u.w}))(s));return 0<a.length?a[0].x+1:(n+r)/2},QJ=t=>e=>n=>r=>{const o=Te(n)(r),i=be(n)(r),s=ft(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=It(c=>_=>it.compare(c.y)(_.y))(s);return 0<u.length?u[0].y-1:(n+r)/2}const a=It(u=>c=>it.compare(c.y)(u.y))($(u=>({...u,y:u.y+u.h}))(s));return 0<a.length?a[0].y+1:(n+r)/2},MJ=t=>e=>n=>r=>{const o=Te(n)(r),i=be(n)(r),s=ft(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=It(c=>_=>it.compare(_.x)(c.x))($(c=>({...c,x:c.x+c.w}))(s));return 0<u.length?u[0].x:(n+r)/2}const a=It(u=>c=>it.compare(u.x)(c.x))(s);return 0<a.length?a[0].x-1:(n+r)/2},zJ=t=>e=>n=>r=>{const o=Te(n)(r),i=be(n)(r),s=ft(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=It(c=>_=>it.compare(_.y)(c.y))($(c=>({...c,y:c.y+c.h}))(s));return 0<u.length?u[0].y:(n+r)/2}const a=It(u=>c=>it.compare(u.y)(c.y))(s);return 0<a.length?a[0].y-1:(n+r)/2},E1=t=>e=>n=>{let r=t,o=e,i=n,s=!0,a;for(;s;){const u=r,c=o,_=i;if(_>100){s=!1,a=c;continue}if(!u(c+_)){s=!1,a=c+_;continue}if(!u(c-_)){s=!1,a=c-_;continue}r=u,o=c,i=_+1}return a},G1=t=>e=>n=>r=>o=>{const i=Te(e)(n),s=be(e)(n);if(!$i(i)(s)(r)(t))return r;if(!$i(i)(s)(o)(t))return o;const a=(r+o)/2;return $i(i)(s)(a)(t)?E1(u=>$i(i)(s)(u)(t))(a)(1):a},WJ=t=>e=>n=>r=>o=>{const i=Te(e)(n),s=be(e)(n);if(!Yi(i)(s)(r)(t))return r;if(!Yi(i)(s)(o)(t))return o;const a=(r+o)/2;return Yi(i)(s)(a)(t)?E1(u=>Yi(i)(s)(u)(t))(a)(1):a},qJ=t=>e=>n=>r=>{const o=Te(e)(n),i=be(e)(n),s=ft(c=>r>=c.x&&r<c.x+c.w&&c.y+c.h>o&&c.y<i,t),a=v(c=>_=>be(c)(_.x+_.w+4))(r+4)(s),u=v(c=>_=>Te(c)(_.x-4))(r-4)(s);return(()=>{const c=a-r,_=u-r;return(c<0?-c:c)<=(_<0?-_:_)})()?a:u},OJ=t=>e=>n=>r=>{const o=Te(e)(n),i=be(e)(n),s=ft(c=>r>=c.y&&r<c.y+c.h&&c.x+c.w>o&&c.x<i,t),a=v(c=>_=>be(c)(_.y+_.h+4))(r+4)(s),u=v(c=>_=>Te(c)(_.y-4))(r-4)(s);return(()=>{const c=a-r,_=u-r;return(c<0?-c:c)<=(_<0?-_:_)})()?a:u},HJ=t=>e=>n=>r=>o=>i=>s=>{const a=(()=>{if(r==="South")return C(o._1,o._2+4);if(r==="North")return C(o._1,o._2-4);if(r==="East")return C(o._1+4,o._2);if(r==="West")return C(o._1-4,o._2);g()})(),u=(()=>{if(i==="South")return C(s._1,s._2+4);if(i==="North")return C(s._1,s._2-4);if(i==="East")return C(s._1+4,s._2);if(i==="West")return C(s._1-4,s._2);g()})(),c=(b,L,E)=>!aa(e)(Te(L)(E))(be(L)(E))(b),_=(b,L,E)=>!aa(n)(Te(L)(E))(be(L)(E))(b),d=(b,L,E,B)=>t.tag==="Just"&&!Ui(n)(Te(b)(L))(be(b)(L))(t._1)?t._1:WJ(e)(b)(L)(E)(B),l=(b,L,E,B)=>{if(b===E){const U=qJ(e)(L)(B)(b),I=QJ(e)(b)(L)(B),A=zJ(e)(b)(L)(B);return[{start:C(b,L),end:C(b,I),direction:me},{start:C(b,I),end:C(U,I),direction:pe},{start:C(U,I),end:C(U,A),direction:me},{start:C(U,A),end:C(E,A),direction:pe},{start:C(E,A),end:C(E,B),direction:me}]}const z=d(b,E,L,B);return[{start:C(b,L),end:C(b,z),direction:me},{start:C(b,z),end:C(E,z),direction:pe},{start:C(E,z),end:C(E,B),direction:me}]},f=(b,L,E,B)=>{if(L===B){const U=OJ(e)(b)(E)(L),I=FJ(e)(L)(b)(E),A=MJ(e)(L)(b)(E);return[{start:C(b,L),end:C(I,L),direction:pe},{start:C(I,L),end:C(I,U),direction:me},{start:C(I,U),end:C(A,U),direction:pe},{start:C(A,U),end:C(A,B),direction:me},{start:C(A,B),end:C(E,B),direction:pe}]}const z=G1(e)(L)(B)(b)(E);return[{start:C(b,L),end:C(z,L),direction:pe},{start:C(z,L),end:C(z,B),direction:me},{start:C(z,B),end:C(E,B),direction:pe}]},h=(b,L,E)=>!Ui(e)(Te(L)(E))(be(L)(E))(b),p=(b,L,E)=>!Ui(n)(Te(L)(E))(be(L)(E))(b),m=(b,L,E,B)=>{if(p(L,b,E)&&_(E,L,B))return[{start:C(b,L),end:C(E,L),direction:pe},{start:C(E,L),end:C(E,B),direction:me}];const z=G1(e)(L)(B)(b)(E);return[{start:C(b,L),end:C(z,L),direction:pe},{start:C(z,L),end:C(z,B),direction:me},{start:C(z,B),end:C(E,B),direction:pe}]},J=(b,L,E,B)=>{if(_(b,L,B)&&p(B,b,E))return[{start:C(b,L),end:C(b,B),direction:me},{start:C(b,B),end:C(E,B),direction:pe}];const z=d(b,E,L,B);return[{start:C(b,L),end:C(b,z),direction:me},{start:C(b,z),end:C(E,z),direction:pe},{start:C(E,z),end:C(E,B),direction:me}]},x=(()=>{if(r==="South")return i==="North"?a._1===u._1&&c(a._1,a._2,u._2)?[{start:C(a._1,a._2),end:C(u._1,u._2),direction:me}]:l(a._1,a._2,u._1,u._2):i==="East"||i==="West"?J(a._1,a._2,u._1,u._2):l(a._1,a._2,u._1,u._2);if(r==="North")return i==="South"?a._1===u._1&&c(a._1,a._2,u._2)?[{start:C(a._1,a._2),end:C(u._1,u._2),direction:me}]:l(a._1,a._2,u._1,u._2):i==="East"||i==="West"?J(a._1,a._2,u._1,u._2):l(a._1,a._2,u._1,u._2);if(r==="East")return i==="West"?a._2===u._2&&h(a._2,a._1,u._1)?[{start:C(a._1,a._2),end:C(u._1,u._2),direction:pe}]:f(a._1,a._2,u._1,u._2):i==="North"||i==="South"?m(a._1,a._2,u._1,u._2):l(a._1,a._2,u._1,u._2);if(r==="West"){if(i==="East")return a._2===u._2&&h(a._2,a._1,u._1)?[{start:C(a._1,a._2),end:C(u._1,u._2),direction:pe}]:f(a._1,a._2,u._1,u._2);if(i==="North"||i==="South")return m(a._1,a._2,u._1,u._2)}return l(a._1,a._2,u._1,u._2)})(),y=(()=>{if(r==="South"||r==="North")return me;if(r==="East"||r==="West")return pe;g()})(),T={start:C(u._1,u._2),end:C(s._1,s._2),direction:(()=>{if(i==="South"||i==="North")return me;if(i==="East"||i==="West")return pe;g()})()};return a._1===u._1&&a._2===u._2?[{start:C(o._1,o._2),end:C(s._1,s._2),direction:y}]:PJ({start:C(o._1,o._2),end:C(a._1,a._2),direction:y})(x)(T)},$J=$(t=>({x:t.position._1*ua-2,y:t.position._2*ua-2,w:t.size._1*ua+4,h:t.size._2*ua+4})),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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ai=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},VJ=(()=>{const t=en.unfoldr(In);return e=>t(nn("IterNode",e,Dn))})(),Gc=t=>e=>t.gapTop+1*nt(4)+nt(e)*2.5*nt(4),XJ=t=>e=>{const n=P1(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return N("Just",{slot1Y:Gc(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Gc(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return w;g()}if(n.tag==="Nothing")return w;g()},YJ=t=>e=>{const n=v(r=>o=>rt(P)(o.node)(o)(r))(R)(e);return ln(Ht(r=>o=>{const i=ai(o.node)(n);if(i.tag==="Nothing")return[];if(i.tag==="Just"){const s=i._1;return Ht(a=>u=>{const c=o.edges.length,_=nt(4),d=s.position._1*_,l=s.position._2*_,f=s.size._2*_,h=nt((2*c|0)+1|0),p=l+f*nt(c-a|0)/h,m=l+f*nt((c+1|0)+a|0)/h,J=d-_*2.5*nt(a+1|0),x=[{start:C(d,p),end:C(J,p),direction:pe},{start:C(J,p),end:C(J,m),direction:me},{start:C(J,m),end:C(d,m),direction:pe}];return{edge:u.id,segments:x,bends:Qe(y=>T=>y.end,x,Dt(1,3,x)),bendType:[],jumps:[],reversed:!1}})(o.edges)}g()})($(r=>({node:r._1,edges:r._2}))(VJ(v(r=>o=>Ft(P)(he)(o.from.node)([o])(r))(R)(t)))))},UJ=t=>e=>{const n=v(i=>s=>rt(P)(s.node)(s)(i))(R)(e),r=i=>{const s=ai(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.position._1;g()},o=i=>{const s=ai(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.layer;g()};return It(i=>s=>{const a=ot.compare(o(i.edge.from.node))(o(s.edge.from.node));if(a==="EQ"){const u=it.compare(r(i.edge.from.node))(r(s.edge.from.node));return u==="EQ"?it.compare(r(i.edge.to.node))(r(s.edge.to.node)):u}return a})(t)},sn=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}},KJ=t=>t.from.node===t.to.node,jJ=t=>e=>n=>r=>{const o=RJ(n)(HJ(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:o,bends:Qe(i=>s=>i.end,o,Dt(1,o.length,o)),bendType:[],jumps:[],reversed:!1}},ZJ=t=>e=>n=>r=>{const o=[{start:C(r.fromPos._1,r.fromPos._2),end:C(r.fromPos._1,t.slot1Y),direction:me},{start:C(r.fromPos._1,t.slot1Y),end:C(t.splitX,t.slot1Y),direction:pe},{start:C(t.splitX,t.slot1Y),end:C(t.splitX,t.slot2Y),direction:me},{start:C(t.splitX,t.slot2Y),end:C(r.toPos._1,t.slot2Y),direction:pe},{start:C(r.toPos._1,t.slot2Y),end:C(r.toPos._1,r.toPos._2),direction:me}];return{edge:r.edge.id,segments:o,bends:Qe(i=>s=>i.end,o,Dt(1,5,o)),bendType:[],jumps:[],reversed:!1}},tN=t=>e=>n=>{const r=ai(t.edge.from.node)(n);if(r.tag==="Just"){const i=ai(t.edge.to.node)(n);return i.tag==="Just"?ft(s=>!(s.h===sn(r._1).h&&s.w===sn(r._1).w&&s.x===sn(r._1).x&&s.y===sn(r._1).y)&&!(s.h===sn(i._1).h&&s.w===sn(i._1).w&&s.x===sn(i._1).x&&s.y===sn(i._1).y),e):ft(s=>!(s.h===sn(r._1).h&&s.w===sn(r._1).w&&s.x===sn(r._1).x&&s.y===sn(r._1).y),e)}const o=ai(t.edge.to.node)(n);return o.tag==="Just"?ft(i=>!(i.h===sn(o._1).h&&i.w===sn(o._1).w&&i.x===sn(o._1).x&&i.y===sn(o._1).y),e):ft(i=>!0,e)},eN=t=>e=>{const n=P1(e.edge.id)(t);if(n.tag==="Just")return N("Just",Gc(n._1)(n._1.slot));if(n.tag==="Nothing")return w;g()},nN=t=>e=>n=>r=>o=>{const i=v(c=>_=>rt(P)(_.node)(_)(c))(R)(e),s=$J(e),a=g1(ft(c=>c.from.node!==c.to.node,t))(e)(n)(r)(o),u=i1(a)(e);return[...YJ(ft(KJ,t))(e),...v(c=>_=>{const d=tN(_)(s)(i),l=[...d,...c.edgeObstacles],f=XJ(u)(_),h=(()=>{if(f.tag==="Just")return ZJ(f._1)(d)(l)(_);if(f.tag==="Nothing")return jJ(eN(u)(_))(d)(l)(_);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...GJ(h.segments)]}})({results:[],edgeObstacles:[]})(UJ(a)(e)).results]},Xr=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Yr=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},rN=t=>e=>n=>{if(t.start._1!==e.start._1)return w;const r=Yr(Xr(t.start._2)(t.end._2))(Xr(e.start._2)(e.end._2)),o=Xr(Yr(t.start._2)(t.end._2))(Yr(e.start._2)(e.end._2));return r<o?N("Just",{position:C(t.start._1,(r+o)/2),crossingEdge:n}):w},oN=t=>e=>n=>{if(t.start._2!==e.start._2)return w;const r=Yr(Xr(t.start._1)(t.end._1))(Xr(e.start._1)(e.end._1)),o=Xr(Yr(t.start._1)(t.end._1))(Yr(e.start._1)(e.end._1));return r<o?N("Just",{position:C((r+o)/2,t.start._2),crossingEdge:n}):w},iN=t=>e=>n=>{if(t.direction==="H")return oN(t)(e)(n);if(t.direction==="V")return rN(t)(e)(n);g()},sN=t=>e=>n=>{const r=t+1|0,o=r<1?n:Dt(r,n.length,n);return St(e.segments)(i=>St(o)(s=>vt(a=>iN(i)(a)(s.edge))(ft(a=>a.direction==="H"?i.direction==="H":a.direction==="V"&&i.direction==="V",s.segments))))},aN=t=>e=>n=>e.start._1>Xr(t.start._1)(t.end._1)&&e.start._1<Yr(t.start._1)(t.end._1)&&t.start._2>Xr(e.start._2)(e.end._2)&&t.start._2<Yr(e.start._2)(e.end._2)?N("Just",{position:C(e.start._1,t.start._2),crossingEdge:n}):w,uN=t=>e=>St(ft(n=>n.direction==="H",t.segments))(n=>St(e)(r=>vt(o=>aN(n)(o)(r.edge))(ft(o=>o.direction==="V",r.segments)))),cN=t=>e=>n=>[...uN(e)(ft(r=>r.edge!==e.edge,n)),...sN(t)(e)(n)],B1=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},gN=v(t=>e=>rt(P)(e)()(t))(R),ca=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},_N=Yf(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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},D1=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;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 s=ot.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},fN=ce(ot)(Mt),dN=t=>e=>Ae(P.compare,Be,t,e),I1=Ht(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),lN=t=>v(e=>n=>({base:(()=>{const r=o=>i=>{let s=o,a=i,u=!0,c;for(;u;){const _=s,d=a;if(d.tag==="Nil"){u=!1,c=_;continue}if(d.tag==="Cons"){s=B1(_)(d._1),a=d._2;continue}g()}return c};return(e.base+r(0)((()=>{const o=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return o(i._5,kt("Cons",i._4,o(i._6,s)));g()};return o(n,H)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=o=>{if(o.tag==="Leaf")return R;if(o.tag==="Node")return te("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,hN=t=>e=>{const n=gN(t);return _N(t)(I1(ft(r=>ca(r.src)(n)&&ca(r.tgt)(n),e)))},pN=t=>e=>{const n=v(o=>i=>Ft(P)(he)(i.tgt)([i.src])(Ft(P)(he)(i.src)([i.tgt])(o)))(R)(e),r=o=>i=>s=>{let a=o,u=i,c=s,_=!0,d;for(;_;){const l=a,f=u,h=c,p=zt(m=>w,m=>J=>N("Just",{head:m,tail:J}),l);if(p.tag==="Nothing"){_=!1,d={nodes:h};continue}if(p.tag==="Just"){if(ca(p._1.head)(f)){a=p._1.tail,u=f,c=h;continue}a=[...p._1.tail,...(()=>{const m=ar(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()})()],u=rt(P)(p._1.head)()(f),c=[...h,p._1.head];continue}g()}return d};return v(o=>i=>{if(ca(i)(o.visited))return o;const s=r([i])(o.visited)([]);return{...o,visited:v(a=>u=>rt(P)(u)()(a))(o.visited)(s.nodes),components:[...o.components,s.nodes]}})({visited:R,components:[]})(t).components},mN=t=>e=>n=>{const r=v(i=>s=>Ft(P)(xe)(s.tgt)(1)(i))(R)(e),o=v(i=>s=>Ft(P)(xe)(s.src)(1)(i))(R)(e);return v(i=>s=>{const a=ar(s)(r),u=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})();if((()=>{const x=ar(s)(o);return(()=>{if(x.tag==="Nothing")return u!==0;if(x.tag==="Just")return u!==x._1;g()})()||u===0})())return i;const c=ar(s)(i.layers),_=(()=>{if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1;g()})(),d=i.layers,l=v(x=>y=>y.tgt===s?{...x,mIn:D1(x.mIn)((()=>{const T=ar(s)(d),b=ar(y.src)(d);return(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;g()})()|0})())}:y.src===s?{...x,mOut:D1(x.mOut)((()=>{const T=ar(y.tgt)(d),b=ar(s)(d);return(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;g()})()|0})())}:x)({mIn:1e9,mOut:1e9})(e),f=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(f<0||h<0)return i;const p=(_-f|0)+1|0,m=(_+h|0)-1|0;if(m<p)return i;const J=v(x=>y=>{const T=Pc(y)(i.filling),b=(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})();return b<x.bestFill?{best:y,bestFill:b}:x})({best:_,bestFill:(()=>{const x=Pc(_)(i.filling);if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})()})(Kt(p,m));return J.best===_?i:{layers:rt(P)(s)(J.best)(i.layers),filling:rt(ot)(_)((()=>{const x=Pc(_)(i.filling);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;g()})())(rt(ot)(J.best)(J.bestFill+1|0)(i.filling))}})({layers:n,filling:fN($(i=>C(i,v(s=>a=>(()=>{const u=ar(a)(n);return u.tag==="Nothing"?!1:u.tag==="Just"&&u._1===i})()?s+1|0:s)(0)(t)))(Kt(0,v(i=>s=>B1(i)((()=>{const a=ar(s)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})()))(0)(t))))})(t).layers},yN=t=>e=>mN(t)(I1(e))(v(dN)(R)(lN($(n=>hN(n)(e))(pN(t)(e))))),xN=t=>t,fo=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ga=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},A1=(()=>{const t=en.unfoldr(In);return e=>t(nn("IterNode",e,Dn))})(),wN=xN("NetworkSimplex"),JN=t=>e=>v(n=>r=>{const o=v(ga)(0)(vt(i=>fo(i)(n))(r));return v(i=>s=>rt(P)(s)(o)(i))(n)(r)})(e)(t),NN=t=>e=>({layers:$(n=>ft(r=>{const o=fo(r)(e);return o.tag==="Nothing"?!1:o.tag==="Just"&&o._1===n},t))(Kt(0,(n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=i;if(c.tag==="Nil"){s=!1,a=u;continue}if(c.tag==="Cons"){o=ga(u)(c._1),i=c._2;continue}g()}return a})(0)((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,kt("Cons",r._4,n(r._6,o)));g()};return n(e,H)})()))),nodeLayer:e}),vN=t=>e=>n=>{const r=v(o=>i=>rt(P)(i)(!0)(o))(R)(e);return v(o=>i=>rt(P)(i._1)(i._2)(o))(yN(e)(vt(o=>o.from.node===o.to.node||(()=>{const i=fo(o.from.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;g()})()||(()=>{const i=fo(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)))(A1(n))},TN=t=>e=>n=>r=>{const o=a=>u=>{const c=fo(u)(a);if(c.tag==="Just")return a;if(c.tag==="Nothing"){const _=ft(l=>l!==u,(()=>{const l=fo(u)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;g()})()),d=v(o)(a)(_);return rt(P)(u)(1+v(ga)(0)(vt(l=>fo(l)(d))(_))|0)(d)}g()},i=v(o)(R)(n),s=(a=>u=>{let c=a,_=u,d=!0,l;for(;d;){const f=c,h=_;if(h.tag==="Nil"){d=!1,l=f;continue}if(h.tag==="Cons"){c=ga(f)(h._1),_=h._2;continue}g()}return l})(1)((()=>{const a=(u,c)=>{if(u.tag==="Leaf")return c;if(u.tag==="Node")return a(u._5,kt("Cons",u._4,a(u._6,c)));g()};return a(i,H)})());return v(a=>u=>rt(P)(u._1)(u._2)(a))((()=>{const a=u=>{if(u.tag==="Leaf")return R;if(u.tag==="Node")return te("Node",u._1,u._2,u._3,s-u._4|0,a(u._5),a(u._6));g()};return a(i)})())(A1(r))},bN=v(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return rt(P)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return rt(P)(e._1.node)(0)(t)}return t})(R),CN=v(t=>e=>Ft(P)(he)(e.to.node)([e.from.node])(t))(R),kN=v(t=>e=>Ft(P)(he)(e.from.node)([e.to.node])(t))(R),LN=t=>e=>n=>r=>{const o=kN(n),i=CN(n),s=bN(e);return NN(r)(JN(vt(a=>a.tag==="SameLayer"?N("Just",a._1.nodes):w)(e))((()=>{if(t==="LongestPath")return TN(o)(i)(r)(s);if(t==="NetworkSimplex")return vN(n)(r)(s);g()})()))},SN=ce(P)(Mt),EN=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},R1=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},F1=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ki=ce(P)(Mt),GN=ce(P)(Mt),Q1=(()=>{const t=$(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>se(t(e))})(),PN=t=>e=>n=>r=>{const o=SN($(s=>C(s.edge,s))(r)),i=s=>0<s.nodes.length&&(()=>{const a=EN(s.edgeId)(n);return a.tag==="Just"&&s.nodes[0]!==a._1._1})();return $(s=>{if(s.nodes.length<=2){const _=R1(s.edgeId)(o);if(_.tag==="Just"){const d=i(s),l=Xi(Vi(d?Q1(_._1.segments):_._1.segments));return{..._._1,edge:s.edgeId,segments:l,bends:Qe(f=>h=>f.end,l,Dt(1,l.length,l)),reversed:d}}if(_.tag==="Nothing")return{edge:s.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};g()}const a=St(vt(_=>R1(_)(o))(Qe(_=>d=>s.edgeId+":"+_+"->"+d,s.nodes,Dt(1,s.nodes.length,s.nodes))))(_=>_.segments),u=i(s),c=Xi(Vi(u?Q1(a):a));return{edge:s.edgeId,segments:c,bends:Qe(_=>d=>_.end,c,Dt(1,c.length,c)),bendType:[],jumps:[],reversed:u}})(t)},BN={layers:[],edges:[],chains:[]},DN={nodeGap:3,layerGap:2,iterations:8,layerer:wN,cycleBreaker:TJ,compactPostRouting:!0,compactionSpacings:Cw},IN=t=>({pos:C(0,0),size:C(v(e=>n=>F1(e)(n.position._1+n.size._1))(0)(t),v(e=>n=>F1(e)(n.position._2+n.size._2))(0)(t))}),AN=t=>e=>n=>{const r=Ki($(c=>C(c.id,c.ports))(e.nodes)),o=ft(c=>Re(3)(c.node)!=="$d:",n.placements),i=PN(n.withDummies.chains)(n.acyclic.reversedEdges)(GN($(c=>C(c.id,C(c.from.node,c.to.node)))(e.edges)))(nN(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(f1(n.ordered)(ft(c=>c.from.node!==c.to.node,n.withDummies.edges))((()=>{const c=_=>{if(_.tag==="Leaf")return R;if(_.tag==="Node")return te("Node",_._1,_._2,_._3,C(_._4._1*4,_._4._2),c(_._5),c(_._6));g()};return c(Ki($(_=>C(_.id,_.size))(e.nodes)))})()))),s=t.compactPostRouting?Sw()(t.compactionSpacings)({nodes:o,edges:e.edges,paths:i,ports:r}):{nodes:o,edges:i},a=$(c=>{const _=Xi(Vi(c.segments));return{...c,segments:_,bends:Qe(d=>l=>d.end,_,Dt(1,_.length,_))}})(s.edges),u=Ht(c=>_=>({..._,jumps:cN(c)(_)(a)}))(a);return{nodes:s.nodes,edges:u,boundingBox:IN(s.nodes),metrics:ex(s.nodes)(u)(0)}},RN=t=>e=>n=>{const r=Ki($(i=>C(i.id,i.size))(e.nodes)),o={...n,placements:aJ({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(Ki($(i=>C(i.id,i.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(f1(n.ordered)(n.withDummies.edges)((()=>{const i=s=>{if(s.tag==="Leaf")return R;if(s.tag==="Node")return te("Node",s._1,s._2,s._3,C(s._4._1*4,s._4._2),i(s._5),i(s._6));g()};return i(r)})()))};return{pipeline:o,result:AN(t)(e)(o)}},FN=t=>e=>n=>RN(t)(e)({...n,ordered:wJ({iterations:t.iterations,constraints:e.constraints,modelOrder:Ki(Ht(r=>o=>C(o.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),QN=t=>e=>n=>FN(t)(e)({...n,withDummies:Ew(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),MN=t=>e=>{const n=$(o=>o.id)(e.nodes),r=EJ(t.cycleBreaker)(n)(e.constraints)(e.edges);return QN(t)(e)({acyclic:r,layered:LN(t.layerer)(e.constraints)(r.edges)(n),withDummies:BN,ordered:[],placements:[]})},M1=t=>t,z1=M1("RunText"),zN=M1("RunCode"),W1=t=>e=>n=>e.length===0?n:Pt(n)({style:t,text:zr(e)}),WN=t=>({style:(()=>{if(t.style==="RunText")return zN;if(t.style==="RunCode")return z1;g()})(),buf:[],runs:W1(t.style)(t.buf)(t.runs)}),qN=t=>e=>0<e.length?{...t,buf:Pt(t.buf)(e[0])}:{...t,buf:Pt(t.buf)("\\")},ON=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=zt(u=>w,u=>c=>N("Just",{head:u,tail:c}),r);if(a.tag==="Nothing"){o=!1,i=s;continue}if(a.tag==="Just"){if(a._1.head==="\\"){n=qN(s)(a._1.tail),r=Dt(1,a._1.tail.length,a._1.tail);continue}if(a._1.head==="`"){n=WN(s),r=a._1.tail;continue}n={...s,buf:Pt(s.buf)(a._1.head)},r=a._1.tail;continue}g()}return i},q1=t=>{const e=ON({style:z1,buf:[],runs:[]})(Jr(t));return W1(e.style)(e.buf)(e.runs)};let Bc=null;function HN(){return Bc||(typeof document>"u"?null:(Bc=document.createElement("canvas").getContext("2d"),Bc))}const O1=new Map,$N=t=>e=>n=>r=>()=>{const o=`${n} ${e}px ${t}|${r}`,i=O1.get(o);if(i!==void 0)return i;const s=HN();if(!s)return r.length*e*.62;s.font=`${n} ${e}px ${t}`;const a=s.measureText(r).width;return O1.set(o,a),a},VN=no.traverse(fu),XN=v(er)(0),lo=(()=>{const t=Rn(`\r
|
|
3
|
-
`)(" "),e=
|
|
4
|
-
`)(" "),n=(()=>{const r=
|
|
5
|
-
`)(i._1))(
|
|
6
|
-
`)(t);return e.length===0?[""]:e},j1=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,kt("Cons",n._4,e(n._6,r)));g()};return jt(le.foldr,e(t.interiors,H))},wv=t=>Zi(vt(e=>N("Just",C(e.edge,{id:e.edge,from:{node:e.from,port:w},to:{node:e.to,port:w},label:w})))(St(t.scenes)(e=>e.tag==="DataFlow"?vt(n=>n.kind.tag==="SendToken"?N("Just",n.kind._1):w)(e._1.events):[]))),Z1=t=>{const e=a2(t),n=ft(o=>sv(o.id)(e.nodes),t.graph.nodes),r=ft(o=>av(o.id)(e.edges),t.graph.edges);return{nodes:[...n,...$(yv)(jt(rn.foldr,Hn(P.compare,e.nodes,uv($(o=>o.id)(n)))))],edges:[...r,...vt(pv(t)(wv(t)))(jt(rn.foldr,Hn(P.compare,e.edges,cv($(o=>o.id)(r)))))],constraints:t.graph.constraints}},Jv=t=>{const e=fa(n=>{const r=H1($1)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})());return()=>{const o=r();return C(n.id,o)}})(Z1(t).nodes);return()=>{const n=e();return da(n)}},td=t=>{const e=Jv(t);return()=>{const n=e(),r=fa(td)(j1(t))();return v(gv)(n)(r)}},Nv=t=>e=>{const n=zt(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},...$(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];g()},vv=t=>e=>C(e.edge,Nv(t)(e)),Tv=t=>e=>n=>r=>({nodes:da($(xv(nt(4)*t)(e)(n))(r.nodes)),edges:Zi($(vv(t))(r.edges)),chipExtras:R,edgeLabels:R}),bv=t=>e=>({...hv(Zi($(n=>C(n.id,C(n.from.node,n.to.node)))(e.edges)))(Tv(8)(da($(n=>C(n.id,(()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})()))(e.nodes)))(da($(n=>C(n.id,n.shape))(e.nodes)))(MN(DN)(e).result)),edgeLabels:Zi(vt(n=>n.label.tag==="Just"?N("Just",C(n.id,n.label._1)):w)(e.edges))}),Cv=t=>v(e=>n=>{if(n.tag==="Structural")return e;if(n.tag==="DataFlow")return v(r=>o=>{if(o.kind.tag==="SendToken")return v(i=>s=>rt(P)(s)()(i))(r)(o.kind._1.labels);if(o.kind.tag==="FillNodeWithoutTransition")return v(i=>s=>rt(P)(s)()(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()})(R)(t.scenes),kv=t=>{const e=fa(n=>{const r=H1($1)(n);return()=>{const o=r();return C(n,{labelW:o,charCount:nr(lo(n)),lineCount:1})}})(jt(rn.foldr,_v(St(jt(rn.foldr,Cv(t)))(K1))));return()=>{const n=e();return fv(n)}},ed=t=>{const e=kv(t);return()=>{const n=e(),r=fa(ed)(j1(t))();return v(dv)(n)(r)}},Lv=nt(4)*8,Sv=t=>St(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()}),Ev=t=>e=>n=>{const r=o=>{const i=vt(s=>{const a=lv(s)(t);return a.tag==="Just"?N("Just",{w:a._1.labelW+28,h:nt(YN(1)(a._1.lineCount))*13.2+12}):w})(St(o)(K1));return i.length===0?w:N("Just",{w:v(U1)(0)($(s=>s.w)(i)),h:v(U1)(0)($(s=>s.h)(i))})};return v(o=>i=>{if(i.kind.tag==="SendToken"){const s=Ic(i.kind._1.edge)(n.edges),a=r(i.kind._1.labels);if(a.tag==="Just"&&s.tag==="Just"){const u=a._1;return Ft(P)(he)(i.kind._1.edge)($(c=>({x:c.x+14+u.w,y:c.y-6-8-u.h}))(s._1))(o)}return o}if(i.kind.tag==="FillNodeWithoutTransition"){const s=ji(i.kind._1.node)(n.nodes),a=r(i.kind._1.labels);return a.tag==="Just"&&s.tag==="Just"?Ft(P)(he)("__fill__:"+i.kind._1.node)((()=>{const u=s._1.y-a._1.h-14,c=s._1.x+s._1.w/2,_=c-a._1.w/2,d=c+a._1.w/2,l=s._1.y-14;return[{x:_,y:u},{x:d,y:u},{x:_,y:l},{x:d,y:l}]})())(o):o}g()})(R)(Sv(e))},nd=t=>e=>n=>({layout:(()=>{const r=bv()(nv(Lv)(t)(ev(tv)(Z1(n))));return{...r,chipExtras:Ev(e)(n)(r)}})(),interiors:(()=>{const r=nd(t)(e),o=i=>{if(i.tag==="Leaf")return R;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(n.interiors)})()}),rd=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Ac=t=>e=>n=>{const r=t<.05?t:.05,o=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return o((()=>{const u=rd(a._3)(n),c=(()=>{if(u.tag==="Just")return u._1;if(u.tag==="Nothing")return{x:a._4.x,y:a._4.y,vx:0,vy:0};g()})(),_=c.vx+(180*(a._4.x-c.x)-22*c.vx)*r,d=c.vy+(180*(a._4.y-c.y)-22*c.vy)*r;return rt(P)(a._3)({x:c.x+_*r,y:c.y+d*r,vx:_,vy:d})(o(s,a._5))})(),a._6);g()},i=o(R,e);return{springs:i,applied:(()=>{const s=(a,u)=>{if(u.tag==="Leaf")return a;if(u.tag==="Node")return s((()=>{const c=s(a,u._5),_=rd(u._3)(i);if(_.tag==="Just")return rt(P)(u._3)({...u._4,x:_._1.x,y:_._1.y})(c);if(_.tag==="Nothing")return rt(P)(u._3)(u._4)(c);g()})(),u._6);g()};return s(R,e)})()}},st=(t,e)=>({tag:"CatQueue",_1:t,_2:e}),Gv=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=st((i=>s=>{let a=i,u=s,c=!0,_;for(;c;){const d=a,l=u;if(l.tag==="Nil"){c=!1,_=d;continue}if(l.tag==="Cons"){a=kt("Cons",l._1,d),u=l._2;continue}g()}return _})(H)(o._2),H);continue}if(o._1.tag==="Cons"){n=!1,r=N("Just",C(o._1._1,st(o._1._2,o._2)));continue}g()}return r},at=(t,e,n)=>({tag:t,_1:e,_2:n}),_t=at("CatNil"),Pv=t=>e=>{if(t.tag==="CatNil")return e;if(e.tag==="CatNil")return t;if(t.tag==="CatCons")return at("CatCons",t._1,st(t._2._1,kt("Cons",e,t._2._2)));g()},Bv=t=>e=>n=>{const r=o=>i=>s=>{let a=o,u=i,c=s,_=!0,d;for(;_;){const l=a,f=u,h=c;if(h.tag==="Nil"){_=!1,d=f;continue}if(h.tag==="Cons"){a=l,u=l(f)(h._1),c=h._2;continue}g()}return d};return(o=>i=>{let s=o,a=i,u=!0,c;for(;u;){const _=s,d=a,l=Gv(_);if(l.tag==="Nothing"){u=!1,c=r(f=>h=>h(f))(e)(d);continue}if(l.tag==="Just"){s=l._1._2,a=kt("Cons",t(l._1._1),d);continue}g()}return c})(n)(H)},Dv=t=>{if(t.tag==="CatNil")return w;if(t.tag==="CatCons")return N("Just",C(t._1,t._2._1.tag==="Nil"&&t._2._2.tag==="Nil"?_t:Bv(Pv)(_t)(t._2)));g()},tt=(t,e)=>({tag:"Free",_1:t,_2:e}),ut=(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=Dv(o._2);if(i.tag==="Nothing"){n=!1,r=ut("Return",o._1._1);continue}if(i.tag==="Just"){e=(()=>{const s=i._1._1(o._1._1);return tt(s._1,(()=>{if(s._2.tag==="CatNil")return i._1._2;if(i._1._2.tag==="CatNil")return s._2;if(s._2.tag==="CatCons")return at("CatCons",s._2._1,st(s._2._2._1,kt("Cons",i._1._2,s._2._2._2)));g()})())})();continue}g()}if(o._1.tag==="Bind"){n=!1,r=ut("Bind",o._1._1,i=>{const s=o._1._2(i);return tt(s._1,(()=>{if(s._2.tag==="CatNil")return o._2;if(o._2.tag==="CatNil")return s._2;if(s._2.tag==="CatCons")return at("CatCons",s._2._1,st(s._2._2._1,kt("Cons",o._2,s._2._2._2)));g()})())});continue}g()}return r},Iv=t=>e=>{const n=e.Monad0(),r=n.Bind1().Apply0().Functor0();return o=>e.tailRecM(i=>{const s=od(i);if(s.tag==="Return")return r.map(i0)(n.Applicative0().pure(s._1));if(s.tag==="Bind")return r.map(du)(o(t.map(s._2)(s._1)));g()})},Av=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);g()},Rc={Applicative0:()=>xo,Bind1:()=>id},Rv={map:t=>e=>id.bind(e)(n=>xo.pure(t(n)))},id={bind:t=>e=>tt(t._1,(()=>{if(t._2.tag==="CatNil")return at("CatCons",e,st(H,H));if(t._2.tag==="CatCons")return at("CatCons",t._2._1,st(t._2._2._1,kt("Cons",at("CatCons",e,st(H,H)),t._2._2._2)));g()})()),Apply0:()=>sd},sd={apply:t=>e=>{const n=r=>tt(e._1,(()=>{if(e._2.tag==="CatNil")return at("CatCons",o=>xo.pure(r(o)),st(H,H));if(e._2.tag==="CatCons")return at("CatCons",e._2._1,st(e._2._2._1,kt("Cons",at("CatCons",o=>xo.pure(r(o)),st(H,H)),e._2._2._2)));g()})());return tt(t._1,(()=>{if(t._2.tag==="CatNil")return at("CatCons",n,st(H,H));if(t._2.tag==="CatCons")return at("CatCons",t._2._1,st(t._2._2._1,kt("Cons",at("CatCons",n,st(H,H)),t._2._2._2)));g()})())},Functor0:()=>Rv},xo={pure:t=>tt(ut("Return",t),_t),Apply0:()=>sd},Fv=()=>()=>()=>t=>e=>n=>Hp(n.type)(t)?$p(n.type)(t)(n.value):e(n),Qv={map:t=>e=>({type:e.type,value:e.map(t)(e.value),map:e.map})},Mv=t=>M_("Data.Functor.Variant: pattern match failure ["+t.type+"]"),zv=()=>()=>()=>t=>Fv()()()(t)(Mv);(function(){var t={},e="Pure",n="Throw",r="Catch",o="Sync",i="Async",s="Bind",a="Bracket",u="Fork",c="Sequential",_="Map",d="Apply",l="Alt",f="Cons",h="Resume",p="Release",m="Finalizer",J="Finalized",x="Forked";function y(G,Q,V,Y){this.tag=G,this._1=Q,this._2=V,this._3=Y}function T(G){var Q=function(V,Y,X){return new y(G,V,Y,X)};return Q.tag=G,Q}function b(G){return new y(e,void 0)}function L(G){try{G()}catch(Q){setTimeout(function(){throw Q},0)}}function E(G,Q,V){try{return Q(V())}catch(Y){return G(Y)}}function B(G,Q,V){try{return Q(V)()}catch(Y){return V(G(Y))(),b}}var z=(function(){var G=1024,Q=0,V=0,Y=new Array(G),X=!1;function q(){var K;for(X=!0;Q!==0;)Q--,K=Y[V],Y[V]=void 0,V=(V+1)%G,K();X=!1}return{isDraining:function(){return X},enqueue:function(K){var et;Q===G&&(et=X,q(),X=et),Y[(V+Q)%G]=K,Q++,X||q()}}})();function U(G){var Q={},V=0,Y=0;return{register:function(X){var q=V++;X.onComplete({rethrow:!0,handler:function(K){return function(){Y--,delete Q[q]}}})(),Q[q]=X,Y++},isEmpty:function(){return Y===0},killAll:function(X,q){return function(){if(Y===0)return q();var K=0,et={};function lt(pt){et[pt]=Q[pt].kill(X,function(Tt){return function(){delete et[pt],K--,G.isLeft(Tt)&&G.fromLeft(Tt)&&setTimeout(function(){throw G.fromLeft(Tt)},0),K===0&&q()}})()}for(var Ct in Q)Q.hasOwnProperty(Ct)&&(K++,lt(Ct));return Q={},V=0,Y=0,function(pt){return new y(o,function(){for(var Tt in et)et.hasOwnProperty(Tt)&&et[Tt]()})}}}}}var I=0,A=1,j=2,Z=3,M=4,W=5,O=6;function D(G,Q,V){var Y=0,X=I,q=V,K=null,et=null,lt=null,Ct=null,pt=null,Tt=0,Et=0,Zt=null,bt=!0;function Ut(ct){for(var yt,dt,ht;;)switch(yt=null,dt=null,ht=null,X){case j:X=A;try{q=lt(q),Ct===null?lt=null:(lt=Ct._1,Ct=Ct._2)}catch(Gt){X=W,K=G.left(Gt),q=null}break;case Z:G.isLeft(q)?(X=W,K=q,q=null):lt===null?X=W:(X=j,q=G.fromRight(q));break;case A:switch(q.tag){case s:lt&&(Ct=new y(f,lt,Ct)),lt=q._2,X=A,q=q._1;break;case e:lt===null?(X=W,q=G.right(q._1)):(X=j,q=q._1);break;case o:X=Z,q=E(G.left,G.right,q._1);break;case i:X=M,q=B(G.left,q._1,function(Gt){return function(){Y===ct&&(Y++,z.enqueue(function(){Y===ct+1&&(X=Z,q=Gt,Ut(Y))}))}});return;case n:X=W,K=G.left(q._1),q=null;break;case r:lt===null?pt=new y(f,q,pt,et):pt=new y(f,q,new y(f,new y(h,lt,Ct),pt,et),et),lt=null,Ct=null,X=A,q=q._1;break;case a:Tt++,lt===null?pt=new y(f,q,pt,et):pt=new y(f,q,new y(f,new y(h,lt,Ct),pt,et),et),lt=null,Ct=null,X=A,q=q._1;break;case u:X=Z,yt=D(G,Q,q._2),Q&&Q.register(yt),q._1&&yt.run(),q=G.right(yt);break;case c:X=A,q=S(G,Q,q._1);break}break;case W:if(lt=null,Ct=null,pt===null)X=O,q=et||K||q;else switch(yt=pt._3,ht=pt._1,pt=pt._2,ht.tag){case r:et&&et!==yt&&Tt===0?X=W:K&&(X=A,q=ht._2(G.fromLeft(K)),K=null);break;case h:et&&et!==yt&&Tt===0||K?X=W:(lt=ht._1,Ct=ht._2,X=j,q=G.fromRight(q));break;case a:Tt--,K===null&&(dt=G.fromRight(q),pt=new y(f,new y(p,ht._2,dt),pt,yt),(et===yt||Tt>0)&&(X=A,q=ht._3(dt)));break;case p:pt=new y(f,new y(J,q,K),pt,et),X=A,et&&et!==yt&&Tt===0?q=ht._1.killed(G.fromLeft(et))(ht._2):K?q=ht._1.failed(G.fromLeft(K))(ht._2):q=ht._1.completed(G.fromRight(q))(ht._2),K=null,Tt++;break;case m:Tt++,pt=new y(f,new y(J,q,K),pt,et),X=A,q=ht._1;break;case J:Tt--,X=W,q=ht._1,K=ht._2;break}break;case O:for(var Lt in Zt)Zt.hasOwnProperty(Lt)&&(bt=bt&&Zt[Lt].rethrow,L(Zt[Lt].handler(q)));Zt=null,et&&K?setTimeout(function(){throw G.fromLeft(K)},0):G.isLeft(q)&&bt&&setTimeout(function(){if(bt)throw G.fromLeft(q)},0);return;case I:X=A;break;case M:return}}function Bt(ct){return function(){if(X===O)return bt=bt&&ct.rethrow,ct.handler(q)(),function(){};var yt=Et++;return Zt=Zt||{},Zt[yt]=ct,function(){Zt!==null&&delete Zt[yt]}}}function wt(ct,yt){return function(){if(X===O)return yt(G.right(void 0))(),function(){};var dt=Bt({rethrow:!1,handler:function(){return yt(G.right(void 0))}})();switch(X){case I:et=G.left(ct),X=O,q=et,Ut(Y);break;case M:et===null&&(et=G.left(ct)),Tt===0&&(X===M&&(pt=new y(f,new y(m,q(ct)),pt,et)),X=W,q=null,K=null,Ut(++Y));break;default:et===null&&(et=G.left(ct)),Tt===0&&(X=W,q=null,K=null)}return dt}}function mt(ct){return function(){var yt=Bt({rethrow:!1,handler:ct})();return X===I&&Ut(Y),yt}}return{kill:wt,join:mt,onComplete:Bt,isSuspended:function(){return X===I},run:function(){X===I&&(z.isDraining()?Ut(Y):z.enqueue(function(){Ut(Y)}))}}}function F(G,Q,V,Y){var X=0,q={},K=0,et={},lt=new Error("[ParAff] Early exit"),Ct=null,pt=t;function Tt(Bt,wt,mt){var ct=wt,yt=null,dt=null,ht=0,Lt={},Gt,Qt;t:for(;;)switch(Gt=null,ct.tag){case x:if(ct._3===t&&(Gt=q[ct._1],Lt[ht++]=Gt.kill(Bt,function(ne){return function(){ht--,ht===0&&mt(ne)()}})),yt===null)break t;ct=yt._2,dt===null?yt=null:(yt=dt._1,dt=dt._2);break;case _:ct=ct._2;break;case d:case l:yt&&(dt=new y(f,yt,dt)),yt=ct,ct=ct._1;break}if(ht===0)mt(G.right(void 0))();else for(Qt=0,Gt=ht;Qt<Gt;Qt++)Lt[Qt]=Lt[Qt]();return Lt}function Et(Bt,wt,mt){var ct,yt,dt,ht,Lt,Gt;for(G.isLeft(Bt)?(ct=Bt,yt=null):(yt=Bt,ct=null);;){if(dt=null,ht=null,Lt=null,Gt=null,Ct!==null)return;if(wt===null){Y(ct||yt)();return}if(wt._3!==t)return;switch(wt.tag){case _:ct===null?(wt._3=G.right(wt._1(G.fromRight(yt))),yt=wt._3):wt._3=ct;break;case d:if(dt=wt._1._3,ht=wt._2._3,ct){if(wt._3=ct,Lt=!0,Gt=K++,et[Gt]=Tt(lt,ct===dt?wt._2:wt._1,function(){return function(){delete et[Gt],Lt?Lt=!1:mt===null?Et(ct,null,null):Et(ct,mt._1,mt._2)}}),Lt){Lt=!1;return}}else{if(dt===t||ht===t)return;yt=G.right(G.fromRight(dt)(G.fromRight(ht))),wt._3=yt}break;case l:if(dt=wt._1._3,ht=wt._2._3,dt===t&&G.isLeft(ht)||ht===t&&G.isLeft(dt))return;if(dt!==t&&G.isLeft(dt)&&ht!==t&&G.isLeft(ht))ct=yt===dt?ht:dt,yt=null,wt._3=ct;else if(wt._3=yt,Lt=!0,Gt=K++,et[Gt]=Tt(lt,yt===dt?wt._2:wt._1,function(){return function(){delete et[Gt],Lt?Lt=!1:mt===null?Et(yt,null,null):Et(yt,mt._1,mt._2)}}),Lt){Lt=!1;return}break}mt===null?wt=null:(wt=mt._1,mt=mt._2)}}function Zt(Bt){return function(wt){return function(){delete q[Bt._1],Bt._3=wt,Et(wt,Bt._2._1,Bt._2._2)}}}function bt(){var Bt=A,wt=V,mt=null,ct=null,yt,dt;t:for(;;)switch(yt=null,dt=null,Bt){case A:switch(wt.tag){case _:mt&&(ct=new y(f,mt,ct)),mt=new y(_,wt._1,t,t),wt=wt._2;break;case d:mt&&(ct=new y(f,mt,ct)),mt=new y(d,t,wt._2,t),wt=wt._1;break;case l:mt&&(ct=new y(f,mt,ct)),mt=new y(l,t,wt._2,t),wt=wt._1;break;default:dt=X++,Bt=W,yt=wt,wt=new y(x,dt,new y(f,mt,ct),t),yt=D(G,Q,yt),yt.onComplete({rethrow:!1,handler:Zt(wt)})(),q[dt]=yt,Q&&Q.register(yt)}break;case W:if(mt===null)break t;mt._1===t?(mt._1=wt,Bt=A,wt=mt._2,mt._2=t):(mt._2=wt,wt=mt,ct===null?mt=null:(mt=ct._1,ct=ct._2))}for(pt=wt,dt=0;dt<X;dt++)q[dt].run()}function Ut(Bt,wt){Ct=G.left(Bt);var mt;for(var ct in et)if(et.hasOwnProperty(ct)){mt=et[ct];for(ct in mt)mt.hasOwnProperty(ct)&&mt[ct]()}et=null;var yt=Tt(Bt,pt,wt);return function(dt){return new y(i,function(ht){return function(){for(var Lt in yt)yt.hasOwnProperty(Lt)&&yt[Lt]();return b}})}}return bt(),function(Bt){return new y(i,function(wt){return function(){return Ut(Bt,wt)}})}}function S(G,Q,V){return new y(i,function(Y){return function(){return F(G,Q,V,Y)}})}return y.EMPTY=t,y.Pure=T(e),y.Throw=T(n),y.Catch=T(r),y.Sync=T(o),y.Async=T(i),y.Bind=T(s),y.Bracket=T(a),y.Fork=T(u),y.Seq=T(c),y.ParMap=T(_),y.ParApply=T(d),y.ParAlt=T(l),y.Fiber=D,y.Supervisor=U,y.Scheduler=z,y.nonCanceler=b,y})();const Wv=t=>e=>Av(n=>r=>t({type:n.type,value:n.map(o=>r(o))(n.value),map:n.map}))(e),qv=t=>{const e=t.Bind1(),n=t.Applicative0().pure;return r=>{const o=qp(()=>Wv(i=>e.bind(r(i))(o()))(n));return o()}};let ad=null;function Ov(){return ad||(typeof document>"u"?null:ad=document.createElement("canvas").getContext("2d"))}const Fc=new Map;function ud(t,e,n,r,o,i){const s=`${n} ${e}px ${t}`,a=s+"|"+r;if(Fc.has(a))return Fc.get(a);const u=Ov();if(!u)return i;u.font=s;const c=o(u.measureText(r)),_=typeof document<"u"?document.fonts:null;if(!_||_.check(s))Fc.set(a,c);else if(_&&_.load)try{_.load(s)}catch{}return c}const Hv=(t,e,n,r)=>ud(t,e,n,r,o=>o.width,-1),$v=(t,e,n,r)=>ud(t,e,n,r,o=>({ascent:o.actualBoundingBoxAscent,descent:o.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),la=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),cd=t=>t,gd={map:t=>e=>{if(e.tag==="MeasureText")return la("MeasureText",e._1,e._2,n=>t(e._3(n)));if(e.tag==="MeasureInk")return la("MeasureInk",e._1,e._2,n=>t(e._3(n)));g()}},Qc=t=>e=>{const n=Hv(t.family,t.size,t.weight,lo(e));return n<0?nt(Yo(e).length)*t.size*.62:n},Mc=t=>e=>{const n=$v(t.family,t.size,t.weight,lo(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},Vv=t=>e=>tt(ut("Bind",{type:"metrics",value:la("MeasureInk",t,e,cd),map:gd.map},n=>tt(ut("Return",n),_t)),_t),ts=t=>e=>tt(ut("Bind",{type:"metrics",value:la("MeasureText",t,e,cd),map:gd.map},n=>tt(ut("Return",n),_t)),_t),_d=t=>t,fd=t=>t,ha=t=>t,dd=t=>t,ld=t=>t,$t=(t,e,n,r,o)=>({tag:t,_1:e,_2:n,_3:r,_4:o}),hd=t=>t,zc=t=>t,Xv=zc("BaselineTop"),kn=zc("BaselineMiddle"),Yv=zc("BaselineBottom"),ci=hd("AlignLeft"),Lr=hd("AlignCenter"),$e=ld("RoundJoin"),es=ld("MiterJoin"),Ln=dd("ButtCap"),Vn=dd("RoundCap"),Uv=ha("LayerPolyOut"),Kv=ha("LayerPolyIn"),jv=ha("LayerNodeMask"),Zv=ha("LayerOverlay"),ns=fd("NonZero"),tT=fd("EvenOdd"),pd=_d("Normal"),pa=_d("Difference"),ye={r:255,g:255,b:255,a:255},rs=[5],we={map:t=>e=>{if(e.tag==="FillPath")return $t("FillPath",e._1,e._2,t(e._3));if(e.tag==="StrokePath")return $t("StrokePath",e._1,e._2,t(e._3));if(e.tag==="FillStrokePath")return $t("FillStrokePath",e._1,e._2,e._3,t(e._4));if(e.tag==="DrawText")return $t("DrawText",e._1,t(e._2));if(e.tag==="DrawTextAffine")return $t("DrawTextAffine",e._1,e._2,t(e._3));if(e.tag==="PushTransform")return $t("PushTransform",e._1,t(e._2));if(e.tag==="PopTransform")return $t("PopTransform",t(e._1));if(e.tag==="PushClip")return $t("PushClip",e._1,e._2,t(e._3));if(e.tag==="PopClip")return $t("PopClip",t(e._1));if(e.tag==="PushBlend")return $t("PushBlend",e._1,t(e._2));if(e.tag==="PopBlend")return $t("PopBlend",t(e._1));if(e.tag==="PushAlpha")return $t("PushAlpha",e._1,t(e._2));if(e.tag==="PopAlpha")return $t("PopAlpha",t(e._1));if(e.tag==="PushBlur")return $t("PushBlur",e._1,t(e._2));if(e.tag==="PopBlur")return $t("PopBlur",t(e._1));if(e.tag==="PushLayer")return $t("PushLayer",e._1,t(e._2));if(e.tag==="PopLayer")return $t("PopLayer",t(e._1));if(e.tag==="SetViewport")return $t("SetViewport",e._1,t(e._2));if(e.tag==="ClearBackground")return $t("ClearBackground",e._1,t(e._2));if(e.tag==="BackgroundDots")return $t("BackgroundDots",e._1,t(e._2));g()}},Sr={r:26,g:26,b:26,a:255},Wc=t=>e=>Math.imul(t,e),gi=t=>{const e=t+1831565813|0,n=Wc(e^e>>>15)(e|1),r=n^(n+Wc(n^n>>>7)(n|61)|0),o=r^r>>>14;return{prng:o,value:o<0?(nt(o)+4294967296)/4294967296:nt(o)/4294967296}},Ee=t=>e=>n=>{const r=gi(n);return{prng:r.prng,value:t+r.value*(e-t)}},qc=t=>e=>v(n=>r=>Wc(n^r)(-2048144789))(e)($($r)(Jr(t))),eT=t=>t,md=t=>t,nT=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},xn=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},yd=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Oc=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},rT=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},oT=md("FlatLevel"),iT=md("NestedLevel"),Hc=eT("GenieSilhouette"),sT=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const o=gi(t);return{prng:o.prng,yLift:o.value*n.yJitter*r}},aT=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const o=gi(t);return{prng:o.prng,dx:(o.value*2-1)*n.xJitter*r}},xd=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,o=He(r*r+n*n),i=(t.r*t.r-e.r*e.r+o*o)/(2*o),s=He(nT(0)(t.r*t.r-i*i)),a=t.cx+i*r/o,u=t.cy+i*n/o,c={x:a-s*n/o,y:u+s*r/o},_={x:a+s*n/o,y:u-s*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=xn(e)(xn(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]},uT=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 s=gi(t);return{prng:s.prng,r:o*(1+s.value*i.rJitter)}},wd=t=>{const e=xn(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]},cT=t=>e=>n=>{const r=gi(t),o=e.length;return o===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const i=yd(0)(o-1|0)(de(Bn(r.value*nt(n))));return i>=0&&i<e.length?e[i]:-1})()}},gT=t=>e=>{const n=gi(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const o=yd(0)(r-1|0)(de(Bn(n.value*nt(r))));return o>=0&&o<e.length?e[o]:-1})()}},Jd=t=>{const e=xn(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]},Nd=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],vd={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},_T=t=>{const e=xn(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]},Td=t=>{const e=xn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+t.h+5,o=t.y+e,i=r-e,s=t.x+n;return[1,t.x,o,4,t.x,o-.5522847498*e,s-.5522847498*n,t.y,s,t.y,4,s+.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,s+.5522847498*n,r,s,r,4,s-.5522847498*n,r,t.x,i+.5522847498*e,t.x,i,5]},bd=t=>e=>{const n=e.y+e.h,r=F0(t.rBase*e.h)(e.w/(2*(1+(nt(t.minN)-1)*t.stepRatio))),o=e.w-2*r,i=2*r*t.stepRatio,s=Oc(t.minN)(o<=0||i<=0?t.minN:de(On(o/i))+1|0),a=s>=3?Kt(1,s-2|0):[],u=a.length,c=yr(u+1|0,2),_=c<1?[]:Dt(0,c,a),d=gT(t.seed)((()=>{const m=u-c|0;return m<1?a:Dt(m,a.length,a)})()),l=d.idx,f=cT(d.prng)(ft(m=>m!==l,_))(Oc(1)(_.length-(tn(Rr)(l)(_)?1:0)|0)),h=f.idx,p=s>=2?o/(nt(s)-1):0;return v(m=>J=>{const x=J===h,y=J===l,T=J===0||J===(s-1|0),b=uT(m.prng)(T)(y)(x)(r)(t),L=sT(b.prng)(T)(t)(e.h),E=aT(L.prng)(T)(t)(p);return{prng:E.prng,circles:Pt(m.circles)({cx:e.x+rT(b.r)(e.w-b.r)((s>=2?r+nt(J)/(nt(s)-1)*o+E.dx:r+0*o+E.dx)+(y?t.heroShift*p:x?-1*t.smallShift*p:0)),cy:n-L.yLift,r:b.r})}})({prng:f.prng,circles:[]})(Kt(0,s-1|0)).circles},Cd=t=>e=>{const n=t.length;return Ht(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?xd(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?xd(o)(t[i]):{x:o.cx+o.r,y:e}})()}))(t)},kd=t=>{const e=xn(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]},fT=t=>e=>n=>{const r=oo(e.y-t.cy)(e.x-t.cx),o=oo(n.y-t.cy)(n.x-t.cx),i=o>r?o-r:o+6.283185307179586-r,s=Oc(1)(de(xs(i/1.5707963267948966))),a=i/nt(s),u=1.3333333333333333*Q0(a/4);return St(Kt(0,s-1|0))(c=>{const _=r+nt(c+1|0)*a,d=t.cx+t.r*bn(_),l=t.cy+t.r*hn(_),f=r+nt(c)*a;return[4,t.cx+t.r*bn(f)-u*t.r*hn(f),t.cy+t.r*hn(f)+u*t.r*bn(f),d+u*t.r*hn(_),l-u*t.r*bn(_),d,l]})},Ld=t=>e=>{const n=t.h*.38,r=Cd(bd(vd)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),o=xn(e)(xn(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...St(r)(i=>fT(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)},dT=t=>e=>n=>r=>o=>i=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(o)(i);if(e==="Cylinder"){const s=Td(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Parallelogram"){const s=Jd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Diamond"){const s=kd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Ellipse"){const s=wd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Document"){const s=Nd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Cloud"){const s=Ld(n)(r);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}return t.drawRoundedRect(n)(r)(o)(i)},lT={fillPath:t=>e=>tt(ut("Bind",{type:"render",value:$t("FillPath",t,e,void 0),map:we.map},n=>tt(ut("Return",n),_t)),_t),strokePath:t=>e=>tt(ut("Bind",{type:"render",value:$t("StrokePath",t,e,void 0),map:we.map},n=>tt(ut("Return",n),_t)),_t),fillStrokePath:t=>e=>n=>tt(ut("Bind",{type:"render",value:$t("FillStrokePath",t,e,n,void 0),map:we.map},r=>tt(ut("Return",r),_t)),_t),drawRoundedRect:t=>e=>n=>r=>{if(n.tag==="Just"){if(r.tag==="Just")return tt(ut("Bind",{type:"render",value:$t("FillStrokePath",_i(t)(e),n._1,r._1,void 0),map:we.map},o=>tt(ut("Return",o),_t)),_t);if(r.tag==="Nothing")return tt(ut("Bind",{type:"render",value:$t("FillPath",_i(t)(e),n._1,void 0),map:we.map},o=>tt(ut("Return",o),_t)),_t);g()}if(n.tag==="Nothing"){if(r.tag==="Just")return tt(ut("Bind",{type:"render",value:$t("StrokePath",_i(t)(e),r._1,void 0),map:we.map},o=>tt(ut("Return",o),_t)),_t);if(r.tag==="Nothing")return tt(ut("Return",void 0),_t)}g()},drawText:t=>tt(ut("Bind",{type:"render",value:$t("DrawText",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),drawTextAffine:t=>e=>tt(ut("Bind",{type:"render",value:$t("DrawTextAffine",t,e,void 0),map:we.map},n=>tt(ut("Return",n),_t)),_t),pushTransform:t=>tt(ut("Bind",{type:"render",value:$t("PushTransform",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),popTransform:tt(ut("Bind",{type:"render",value:$t("PopTransform",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),pushBakedTransform:t=>tt(ut("Bind",{type:"render",value:$t("PushTransform",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),popBakedTransform:tt(ut("Bind",{type:"render",value:$t("PopTransform",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),pushClip:t=>e=>tt(ut("Bind",{type:"render",value:$t("PushClip",t,e,void 0),map:we.map},n=>tt(ut("Return",n),_t)),_t),popClip:tt(ut("Bind",{type:"render",value:$t("PopClip",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),pushBlend:t=>tt(ut("Bind",{type:"render",value:$t("PushBlend",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),popBlend:tt(ut("Bind",{type:"render",value:$t("PopBlend",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),pushAlpha:t=>tt(ut("Bind",{type:"render",value:$t("PushAlpha",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),popAlpha:tt(ut("Bind",{type:"render",value:$t("PopAlpha",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),pushBlur:t=>tt(ut("Bind",{type:"render",value:$t("PushBlur",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),popBlur:tt(ut("Bind",{type:"render",value:$t("PopBlur",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),pushLayer:t=>tt(ut("Bind",{type:"render",value:$t("PushLayer",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),popLayer:tt(ut("Bind",{type:"render",value:$t("PopLayer",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),setViewport:t=>tt(ut("Bind",{type:"render",value:$t("SetViewport",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),clearBackground:t=>tt(ut("Bind",{type:"render",value:$t("ClearBackground",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),backgroundDots:t=>tt(ut("Bind",{type:"render",value:$t("BackgroundDots",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),measureText:t=>e=>ts(t)(e),measureInk:t=>e=>Vv(t)(e),insideTokenStyle:t=>tt(ut("Return",Hc),_t),Monad0:()=>Rc},hT=t=>()=>t.clip("evenodd"),pT=t=>e=>()=>{t.filter=`blur(${e}px)`},mT=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 s=t.createPattern(o,"repeat");s&&typeof s.setTransform=="function"&&s.setTransform(new DOMMatrix().translateSelf(e.ox,e.oy).scaleSelf(1/n,1/n)),t.save(),t.fillStyle=s,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},$c=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Vc=t=>e=>n=>{const r=e.stroke;return()=>{const o=r.value,i=om(t)(n);if(o!==n)return i(),e.stroke.value=n}},yT=t=>e=>n=>{const r=e.font;return()=>{const o=r.value,i=dm(t)(n);if(o!==n)return i(),e.font.value=n}},os=t=>e=>n=>{const r=e.fill;return()=>{const o=r.value,i=rm(t)(n);if(o!==n)return i(),e.fill.value=n}},ma=t=>e=>{const n=e.length,r=i=>{if(i>=n)return()=>{};const s=i>=0&&i<e.length?e[i]:0;if(s===1){const a=E_(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()=>(a(),u())}if(s===2){const a=Li(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()=>(a(),u())}if(s===3){const a=Ei(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()=>(a(),u())}if(s===4){const a=hm(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()=>(a(),u())}if(s===5){const a=G_(t),u=r(i+1|0);return()=>(a(),u())}return()=>{}},o=S_(t);return()=>(o(),r(0)())},xT=t=>e=>n=>r=>o=>i=>{const s=$c(i)($c(r/2)(o/2)),a=E_(t)(e+s)(n);return()=>(a(),Li(t)(e+r-s)(n)(),Ei(t)({cpx:e+r,cpy:n,x:e+r,y:n+s})(),Li(t)(e+r)(n+o-s)(),Ei(t)({cpx:e+r,cpy:n+o,x:e+r-s,y:n+o})(),Li(t)(e+s)(n+o)(),Ei(t)({cpx:e,cpy:n+o,x:e,y:n+o-s})(),Li(t)(e)(n+s)(),Ei(t)({cpx:e,cpy:n,x:e+s,y:n})(),G_(t)())},wT=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),Sd=t=>e=>{const n=cm(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=wT();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0},groupAlpha:{value:1},alphaSaves:{value:[]}}}},JT={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},NT=t=>ie(t.weight)+" "+eo(t.size)+"px "+t.family,ur=t=>{const e=eo(nt(t.a)/255);return t.a>=255?"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")":"rgba("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+","+e+")"},vT=t=>e=>n=>r=>{const o=os(t)(n)(ur(r));return()=>(o(),um(t)({x:0,y:0,width:e.width,height:e.height})())},TT=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",mT(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:ur(n.bgColor),dotCss:ur(n.dotColor),tile:n.tile,dotR:n.dotRadius,ox:n.origin.x,oy:n.origin.y})())},bT=t=>e=>n=>r=>{const o=os(t)(e)(ur(r));return()=>(o(),ma(t)(n)(),bu(t)())},CT=t=>e=>n=>r=>o=>{const i=os(t)(e)(ur(r));return()=>(i(),Vc(t)(e)(ur(o.color))(),Ju(t)(o.width)(),bs(t)((()=>{if(o.lineJoin==="RoundJoin")return Ts;if(o.lineJoin==="BevelJoin")return Eu;if(o.lineJoin==="MiterJoin")return Gu;g()})())(),Iu(t)((()=>{if(o.lineCap==="ButtCap")return Du;if(o.lineCap==="RoundCap")return Pu;if(o.lineCap==="SquareCap")return Bu;g()})())(),ma(t)(n)(),bu(t)(),Tu(t)())},kT=t=>e=>n=>r=>o=>i=>{const s=S_(t);return()=>{if(s(),xT(t)(n.x)(n.y)(n.w)(n.h)(r)(),o.tag==="Just"?(os(t)(e)(ur(o._1.color))(),bu(t)()):o.tag==="Nothing"||g(),i.tag==="Just")return Vc(t)(e)(ur(i._1.color))(),Ju(t)(i._1.width)(),bs(t)((()=>{if(i._1.lineJoin==="RoundJoin")return Ts;if(i._1.lineJoin==="BevelJoin")return Eu;if(i._1.lineJoin==="MiterJoin")return Gu;g()})())(),Iu(t)((()=>{if(i._1.lineCap==="ButtCap")return Du;if(i._1.lineCap==="RoundCap")return Pu;if(i._1.lineCap==="SquareCap")return Bu;g()})())(),Tu(t)();i.tag!=="Nothing"&&g()}},LT=t=>e=>n=>r=>{const o=Vc(t)(e)(ur(r.color));return()=>(o(),Ju(t)(r.width)(),bs(t)((()=>{if(r.lineJoin==="RoundJoin")return Ts;if(r.lineJoin==="BevelJoin")return Eu;if(r.lineJoin==="MiterJoin")return Gu;g()})())(),Iu(t)((()=>{if(r.lineCap==="ButtCap")return Du;if(r.lineCap==="RoundCap")return Pu;if(r.lineCap==="SquareCap")return Bu;g()})())(),ma(t)(n)(),Tu(t)())},Ed=t=>e=>n=>{const r=os(t)(e)(ur(n.color));return()=>(r(),yT(t)(e)(NT(n.font))(),Cm(t)((()=>{if(n.align==="AlignLeft")return wm;if(n.align==="AlignCenter")return Nm;if(n.align==="AlignRight")return Jm;g()})())(),bm(t)((()=>{if(n.baseline==="BaselineTop")return pm;if(n.baseline==="BaselineMiddle")return mm;if(n.baseline==="BaselineAlphabetic")return ym;if(n.baseline==="BaselineBottom")return xm;g()})())(),lm(t)(n.content)(n.x)(n.y)())},Gd={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),s=o();return i(s)}},Functor0:()=>JT},ST={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>Gd},ET=t=>e=>n=>{const r=$c(e.width/n.vw)(e.height/n.vh),o=Cu(t)({translateX:(e.width-n.vw*r)/2-n.vx*r,translateY:(e.height-n.vh*r)/2-n.vy*r});return()=>(o(),Si(t)({scaleX:r,scaleY:r})(),bs(t)(Ts)())},GT={pure:t=>e=>()=>t,Apply0:()=>Gd},Pd={Applicative0:()=>GT,Bind1:()=>ST},Xc={fillPath:t=>e=>n=>{const r=bT(n.ctx)(n.styleCache)(t)(e.color),o=n.maskDepth;return()=>{if(o.value===0)return r()}},strokePath:t=>e=>n=>{const r=LT(n.ctx)(n.styleCache)(t)(e),o=n.maskDepth;return()=>{if(o.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const o=CT(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=kT(o.ctx)(o.styleCache)(t)(e)(n)(r),s=o.maskDepth;return()=>{if(s.value===0)return i()}},drawText:t=>e=>{const n=Ed(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=xr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",gm(n.ctx)(t)(),Ed(n.ctx)(n.styleCache)(e)(),wr(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=xr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Cu(e.ctx)({translateX:t.tx,translateY:t.ty})(),Si(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=wr(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=xr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Cu(e.ctx)({translateX:t.tx,translateY:t.ty})(),Si(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=wr(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=xr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",ma(n.ctx)(t)(),e==="NonZero")return am(n.ctx)();if(e==="EvenOdd")return hT(n.ctx)();g()}}},popClip:t=>{const e=wr(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=xr(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 B_(e.ctx)(vm)();if(t==="Difference")return B_(e.ctx)(Tm)();g()}}},popBlend:t=>{const e=wr(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=xr(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 s=o*t;return e.groupAlpha.value=s,sm(e.ctx)(s)()}}},popAlpha:t=>{const e=wr(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=Qr(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=xr(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=pT(e.ctx)(t);if(t>=.01)return o()}}},popBlur:t=>{const e=wr(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=ET(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=vT(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=TT(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=Qc(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Mc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Hc,Monad0:()=>Pd},PT=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fi=t=>e=>n=>{const r=PT(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},BT=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._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()},Bd=t=>{const e=it.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=it.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},di=t=>{if(t.tag==="Hidden")return{alpha:0,scale:0};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:t._1>0?1:0,scale:Ii(8)(.6)(Bd(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:Ii(8)(.6)(Bd(1-t._1))};g()};function DT(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function IT(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:DT(o,i)}}return n}function AT(t,e,n){let r=0;for(let o=0;o<t.length;o++){const i=t[o],s=r,a=s+i.len;if(n<=a){const u=i.len>1e-6?(n-s)/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=a}return e.length>0?e[e.length-1]:{x:0,y:0}}function Dd(t,e){if(e.length===0)return[];const n=IT(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]=AT(n,e,i*r/t);return o}function RT(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 FT(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 s=0;for(let a=0;a<n;a++){const u=t[a]||{x:0,y:0},c=e[(a+i)%n]||{x:0,y:0},_=u.x-c.x,d=u.y-c.y;s+=_*_+d*d}s<o&&(o=s,r=i)}return RT(r,e)}const Id=t=>e=>n=>{const r=Dd(t,e),o=Dd(t,n),i=FT(r,o);return{from:r,to:i}};function Ad(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 QT(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 MT(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],s=e[((o+1)%n+n)%n],a=e[o];r[o]={x:a.x+((i.x+s.x)/2-a.x)*t,y:a.y+((i.y+s.y)/2-a.y)*t}}return r}function zT(t){return t<0?0:t>1?1:t}const Rd=t=>e=>n=>r=>{const o=e.length;if(o===0)return[];const i=Ad(e),s=Ad(n),a=QT(i,s),u=new Array(o);let c=1/0,_=-1/0;for(let f=0;f<o;f++){const h=e[f],p=(h.x-i.x)*a.x+(h.y-i.y)*a.y;u[f]=p,p<c&&(c=p),p>_&&(_=p)}const d=_-c;let l=new Array(o);for(let f=0;f<o;f++){const h=e[f],p=n[f];if(p===void 0){l[f]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(u[f]-c)/d),J=Math.max(1e-4,1-m),x=zT((t-m)/J),y=x*x*(3-2*x);l[f]={x:h.x+(p.x-h.x)*y,y:h.y+(p.y-h.y)*y}}for(let f=0;f<r.smoothPasses;f++)l=MT(.5,l);return l},Fd=(t,e)=>({tag:t,_1:e}),Qd=(t,e)=>({tag:t,_1:e}),Ce=(t,e,n)=>({tag:t,_1:e,_2:n}),Md=t=>t,Yc=(t,e)=>({tag:t,_1:e}),Uc=(t,e)=>({tag:t,_1:e}),Kc=t=>t,ya=(t,e)=>({tag:t,_1:e}),ke=(t,e,n)=>({tag:t,_1:e,_2:n}),wo=(t,e)=>({tag:t,_1:e}),is=(t,e)=>({tag:t,_1:e}),zd=(t,e)=>({tag:t,_1:e}),Wd=t=>t,qd=(t,e)=>({tag:t,_1:e}),Jo=(t,e,n)=>({tag:t,_1:e,_2:n}),Od=t=>t,WT=t=>t,li=Od("NormalTransform"),qT=Od("BakedTransform"),Hd=Wd("TokenOutside"),$d=Wd("TokenInside"),xa=is("PlainText"),Vd=wo("FrameTitle"),OT=wo("Watermark"),HT=Kc("NodeShadow"),Xd=Kc("NodeBody"),$T=Kc("NodeInversion"),jc=Md("LabelsShown"),Zc=Md("LabelsHidden"),zn={map:t=>e=>{if(e.tag==="BeginFrame")return ke("BeginFrame",e._1,t(e._2));if(e.tag==="EndFrame")return ke("EndFrame",t(e._1));if(e.tag==="BeginGroup")return ke("BeginGroup",e._1,t(e._2));if(e.tag==="EndGroup")return ke("EndGroup",e._1,t(e._2));if(e.tag==="Background")return ke("Background",e._1,t(e._2));if(e.tag==="Overlay")return ke("Overlay",e._1,t(e._2));if(e.tag==="Node")return ke("Node",e._1,t(e._2));if(e.tag==="Edge")return ke("Edge",e._1,t(e._2));if(e.tag==="Text")return ke("Text",e._1,t(e._2));if(e.tag==="Token")return ke("Token",e._1,t(e._2));if(e.tag==="AskInsideTokenStyle")return ke("AskInsideTokenStyle",e._1,n=>t(e._2(n)));g()}},Yd=t=>e=>ts(t)(e),VT=t=>{const e=t.Bind1().Apply0().Functor0(),n=qv(t);return r=>o=>n(zv()()()({scene:i=>{if(i.tag==="BeginFrame"){const s=i._2;return e.map(a=>s)(r.beginFrame(i._1))}if(i.tag==="EndFrame"){const s=i._1;return e.map(a=>s)(r.endFrame)}if(i.tag==="BeginGroup"){const s=i._2;return e.map(a=>s)(r.beginGroup(i._1))}if(i.tag==="EndGroup"){const s=i._2;return e.map(a=>s)(r.endGroup(i._1))}if(i.tag==="Background"){const s=i._2;return e.map(a=>s)(r.background(i._1))}if(i.tag==="Overlay"){const s=i._2;return e.map(a=>s)(r.overlay(i._1))}if(i.tag==="Node"){const s=i._2;return e.map(a=>s)(r.node(i._1))}if(i.tag==="Edge"){const s=i._2;return e.map(a=>s)(r.edge(i._1))}if(i.tag==="Text"){const s=i._2;return e.map(a=>s)(r.text(i._1))}if(i.tag==="Token"){const s=i._2;return e.map(a=>s)(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)},XT=t=>tt(ut("Bind",{type:"scene",value:ke("AskInsideTokenStyle",t,WT),map:zn.map},e=>tt(ut("Return",e),_t)),_t),Ud=t=>tt(ut("Bind",{type:"scene",value:ke("Background",t,void 0),map:zn.map},e=>tt(ut("Return",e),_t)),_t),Kd=t=>tt(ut("Bind",{type:"scene",value:ke("Edge",t,void 0),map:zn.map},e=>tt(ut("Return",e),_t)),_t),tg=t=>tt(ut("Bind",{type:"scene",value:ke("Node",t,void 0),map:zn.map},e=>tt(ut("Return",e),_t)),_t),wa=t=>tt(ut("Bind",{type:"scene",value:ke("Overlay",t,void 0),map:zn.map},e=>tt(ut("Return",e),_t)),_t),ss=t=>tt(ut("Bind",{type:"scene",value:ke("Text",t,void 0),map:zn.map},e=>tt(ut("Return",e),_t)),_t),jd=t=>tt(ut("Bind",{type:"scene",value:ke("Token",t,void 0),map:zn.map},e=>tt(ut("Return",e),_t)),_t),YT=t=>e=>tt(ut("Bind",{type:"scene",value:ke("BeginFrame",t,void 0),map:zn.map},n=>tt(ut("Return",n),_t)),at("CatCons",()=>tt(e._1,(()=>{if(e._2.tag==="CatNil")return at("CatCons",()=>tt(ut("Bind",{type:"scene",value:ke("EndFrame",void 0),map:zn.map},n=>tt(ut("Return",n),_t)),_t),st(H,H));if(e._2.tag==="CatCons")return at("CatCons",e._2._1,st(e._2._2._1,kt("Cons",at("CatCons",()=>tt(ut("Bind",{type:"scene",value:ke("EndFrame",void 0),map:zn.map},n=>tt(ut("Return",n),_t)),_t),st(H,H)),e._2._2._2)));g()})()),st(H,H))),Ke=t=>e=>tt(ut("Bind",{type:"scene",value:ke("BeginGroup",t,void 0),map:zn.map},n=>tt(ut("Return",n),_t)),at("CatCons",()=>{const n=()=>tt(ut("Bind",{type:"scene",value:ke("EndGroup",t,void 0),map:zn.map},r=>tt(ut("Return",r),_t)),_t);return tt(e._1,(()=>{if(e._2.tag==="CatNil")return at("CatCons",n,st(H,H));if(e._2.tag==="CatCons")return at("CatCons",e._2._1,st(e._2._2._1,kt("Cons",at("CatCons",n,st(H,H)),e._2._2._2)));g()})())},st(H,H))),cr=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Zd=v(er)(0),tl=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},UT=v(t=>e=>t+e.len)(0),el=t=>{const e=zt(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,...St(Dt(1,t.length,t))(n=>[2,n.x,n.y]),5];g()},nl=t=>e=>{const n=cr(e)(cr(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]},KT=t=>{const e=zt(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,...St(e._1.tail)(n=>[2,n.x,n.y])];g()},eg=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return Td(e);if(t.shape==="Parallelogram")return Jd(e);if(t.shape==="Diamond")return kd(e);if(t.shape==="Ellipse")return wd(e);if(t.shape==="Document")return Nd(e);if(t.shape==="Cloud")return Ld(e)(7);if(t.shape==="Rectangle")return nl(e)(7);g()},Ge=t=>e=>n=>$(r=>{const o=nt(r)/nt(n);return{x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o}})(Kt(0,n-1|0)),jT=t=>{const e=xn(t.w*.18)(t.h*.6);return[...Ge({x:t.x+e,y:t.y})({x:t.x+t.w,y:t.y})(16),...Ge({x:t.x+t.w,y:t.y})({x:t.x+t.w-e,y:t.y+t.h})(16),...Ge({x:t.x+t.w-e,y:t.y+t.h})({x:t.x,y:t.y+t.h})(16),...Ge({x:t.x,y:t.y+t.h})({x:t.x+e,y:t.y})(16)]},as=t=>e=>{const n=cr(t)(cr(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}},ng=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return He(r*r+n*n)},ZT=t=>Qe(e=>n=>({a:e,b:n,len:ng(e)(n)}),t,Dt(1,t.length,t)),t3=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,s=(()=>{if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return{x:0,y:0};g()})(),a=e.length;return a<3?e:[s,...St(Kt(1,a-2|0))(u=>{const c=u+1|0,_=c>=0&&c<e.length?N("Just",e[c]):w,d=u>=0&&u<e.length?N("Just",e[u]):w,l=u-1|0,f=l>=0&&l<e.length?N("Just",e[l]):w;if(f.tag==="Just"&&d.tag==="Just"&&_.tag==="Just"){const h=d._1,p=ng(h)(_._1),m=ng(f._1)(h),J=cr(t)(p/2),x=cr(t)(m/2),y=p>0?J/p:0,T=h.x+(_._1.x-h.x)*y,b=h.y+(_._1.y-h.y)*y,L=m>0?x/m:0,E=h.x+(f._1.x-h.x)*L,B=h.y+(f._1.y-h.y)*L;return $(z=>{const U=nt(z)/nt(10),I=1-U;return{x:I*I*E+2*I*U*h.x+U*U*T,y:I*I*B+2*I*U*h.y+U*U*b}})(Kt(0,10))}return[]}),...o]},e3=t=>e=>n=>r=>o=>$(i=>{const s=nt(i)/nt(o),a=1-s,u=s*s*s,c=3*a*s*s,_=3*a*a*s,d=a*a*a;return{x:d*t.x+_*e.x+c*n.x+u*r.x,y:d*t.y+_*e.y+c*n.y+u*r.y}})(Kt(0,o-1|0)),n3=t=>[...Ge({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...Ge({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...e3({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),...Ge({x:t.x,y:t.y+t.h*.85})({x:t.x,y:t.y})(12)],rl=t=>e=>$(n=>{const r=6.283185307179586*nt(n)/nt(64);return{x:t.x+e*bn(r),y:t.y+e*hn(r)}})(Kt(0,63)),ol=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]},r3=t=>{const e=t.y+t.h/2,n=xn(t.h*.4)(t.w*.2);return[...Ge({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...Ge({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...Ge({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...Ge({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...Ge({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...Ge({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},rg=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:Zd($(n=>n.x)(t))/nt(e),y:Zd($(n=>n.y)(t))/nt(e)}},Ja=t=>e=>n=>r=>o=>$(i=>{const s=n+(r-n)*(nt(i)/nt(o));return{x:t.x+e*bn(s),y:t.y+e*hn(s)}})(Kt(0,o-1|0)),og=t=>e=>{const n=cr(t)(cr(e.w/2)(e.h/2));return[...Ge({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...Ja({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...Ge({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...Ja({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...Ge({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...Ja({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...Ge({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...Ja({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},Na=t=>e=>n=>r=>o=>i=>$(s=>{const a=r+(o-r)*(nt(s)/nt(i));return{x:t.x+e*bn(a),y:t.y+n*hn(a)}})(Kt(0,i-1|0)),o3=t=>{const e=t.h*.38;return[...St(Cd(bd(vd)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=oo(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),o=oo(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return Na({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(o)(r>o?r:r+6.283185307179586)(16)}),...Ge({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...Ge({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...Ge({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},i3=t=>{const e=cr(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[...Na({x:i,y:r})(n)(e)(3.141592653589793)(6.283185307179586)(24),...Ge({x:t.x+t.w,y:r})({x:t.x+t.w,y:o})(12),...Na({x:i,y:o})(n)(e)(0)(3.141592653589793)(24),...Ge({x:t.x,y:o})({x:t.x,y:r})(12)]},No=t=>e=>e.shape==="Cylinder"?i3(e):e.shape==="Parallelogram"?jT(e):e.shape==="Diamond"?r3(e):e.shape==="Ellipse"?og(xn(e.w)(e.h)/2)(e):e.shape==="Document"?n3(e):e.shape==="Cloud"?o3(e):og(t)(e),s3=t=>{const e=cr(t.h*.075)(t.w*.075),n=t.w/2;return Na({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},a3=t=>e=>n=>v(r=>o=>{const i=r.pos+o.len,s=n<i?(n-r.pos)/o.len:1,a={x:o.a.x+(o.b.x-o.a.x)*s,y:o.a.y+(o.b.y-o.a.y)*s},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,d=_>=0&&_<r.points.length?(()=>{const l=r.points[_].x-c.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const f=r.points[_].y-c.y;return f<0?-f<1e-4:f<1e-4})()})()?Pt(r.points)(a):[...r.points,c,a]:[c,a];return o.len<=0||i<=e||r.pos>=n?{...r,pos:i}:{pos:i,points:d}})({pos:0,points:[]})(t).points,u3=t=>e=>n=>{const r=zt(o=>w,o=>i=>N("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const o=ZT(t),i=UT(o),s=tl(0)(i)(e*i),a=tl(0)(i)(n*i);return a<=s?[]:a3(o)(s)(a)}g()},c3=t=>e=>n=>r=>{const o=r.x-n.x,i=r.y-n.y,s=e.x-t.x,a=e.y-t.y,u=n.x-t.x,c=n.y-t.y,_=s*i-a*o,d=(u*i-c*o)/_,l=(u*a-c*s)/_;return(_<0?-_<1e-9:_<1e-9)?w:d>=0&&d<=1&&l>=0&&l<=1?N("Just",d):w},g3=t=>e=>n=>{const r=It(o=>i=>it.compare(o.t)(i.t))(vt(o=>{const i=c3(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})(Qe(Gn,t,[...Dt(1,t.length,t),...Dt(0,1,t)])));return 0<r.length?N("Just",r[0].p):w},il=t=>e=>{const n=Qr(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=g3(t)(n._1.init[r])(n._1.last);if(o.tag==="Just")return Pt(n._1.init)(o._1);if(o.tag==="Nothing")return e;g()}return e}g()},Ur=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ig=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},_3=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},f3=t=>e=>{const n=Ur(0)(t.y+4-e.y)+Ur(0)(e.y+e.h-(t.y+t.h-4)),r=Ur(0)(t.x+4-e.x)+Ur(0)(e.x+e.w-(t.x+t.w-4));return r*e.h+n*e.w+r*n},d3=t=>e=>{const n=t.y+t.h-6,r=t.y+6,o=t.x+14,i=t.x+t.w-14,s=v(Ur)(0)($(a=>o-10<a.x+a.w+12&&i+10>a.x-12&&r-10<a.y+a.h+12&&n+10>a.y-12?ig((a.x+a.w+12-(o-10))/.7071067811865476)((n+10-(a.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+s*.7071067811865476,y:t.y-s*.7071067811865476}},l3=t=>e=>{const n=ig(t.x+t.w)(e.x+e.w)-Ur(t.x)(e.x),r=ig(t.y+t.h)(e.y+e.h)-Ur(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},sl=t=>e=>n=>r=>{const o=t+4,i=Ur(0)(e-8),s=o+i-n;return n<=i?_3(o)(s)(r):t+(e-n)/2},sg=t=>e=>({...e,x:sl(t.x)(t.w)(e.w)(e.x),y:sl(t.y)(t.h)(e.h)(e.y)}),h3=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}]},p3=t=>e=>n=>r=>o=>{const i=o.y+o.h/2-n.token.y,s=o.y-r.y;return(()=>{const a=o.x+o.w/2-n.token.x,u=o.x-r.x;return 1e6*f3(t)(o)+1e4*v(c=>_=>c+l3(o)(_))(0)(e)+.05*(u*u+s*s)+.01*(a*a+i*i)})()+(o.y>n.token.y?100:0)},m3=t=>e=>n=>r=>{const o=s=>{const a=sg(t)(s);return{rect:a,score:p3(t)(e)(n)(r)(a)}},i=zt(s=>w,s=>a=>N("Just",{head:s,tail:a}),[r,n.rect,...h3(n)]);if(i.tag==="Nothing")return sg(t)(r);if(i.tag==="Just")return v(s=>a=>{const u=o(a);return u.score<s.score?u:s})(o(i._1.head))(i._1.tail).rect;g()},y3=t=>e=>n=>v(r=>o=>{const i=d3(o.rect)(r.obstacles),s=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:m3(t)(r.obstacles)(o)(i);return{acc:rt(P)(o.id)(s)(r.acc),obstacles:Pt(r.obstacles)(s)}})({acc:R,obstacles:e})(n).acc,ag=t=>t,Er=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},vo=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},x3=Ao(lu)(Mt),w3=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},J3=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},al=ag("SegMove"),N3=ag("SegLine"),v3=ag("SegQuad"),ul={offset:.4,passes:1,rMax:1.5},cl=t=>de(Bn(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,va=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},Ta=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},Gr=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},us=(()=>{const t=v(e=>n=>((e*31|0)+de(Bn(n.x*100))|0)+de(Bn(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),T3=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const o=n,i=r,s=o>=0&&o<t.length?N("Just",t[o]):w;if(s.tag==="Nothing"){n=t.length;continue}if(s.tag==="Just"){if(s._1===1){const a={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:al,m:i,c:i,p:a,len:0}),r=a,n=o+3|0;continue}if(s._1===2){const a={x:(()=>{const _=o+1|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+2|0;return _>=0&&_<t.length?t[_]:0})()},u=a.x-i.x,c=a.y-i.y;e.push({kind:N3,m:i,c:i,p:a,len:He(u*u+c*c)}),r=a,n=o+3|0;continue}if(s._1===3){const a={x:(()=>{const _=o+3|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+4|0;return _>=0&&_<t.length?t[_]:0})()},u=a.x-i.x,c=a.y-i.y;e.push({kind:v3,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:a,len:He(u*u+c*c)*1.05}),r=a,n=o+5|0;continue}if(s._1===5){e.push({kind:al,m:i,c:i,p:i,len:0}),n=o+1|0;continue}n=t.length;continue}g()}return e},b3=t=>e=>{const n=e.length-1|0,r=n<1?[]:Dt(0,n,e),o=(()=>{const s=r.length-1|0;return s>=0&&s<r.length?N("Just",r[s]):w})(),i=e.length-1|0;if(i>=0&&i<e.length&&o.tag==="Just"){const s=e[i].y-o._1.y,a=e[i].x-o._1.x,u=He(a*a+s*s);return u<=1e-4?e:Pt((()=>{const c=e.length-1|0;return c<1?[]:Dt(0,c,e)})())({x:e[i].x+a/u*t,y:e[i].y+s/u*t})}return e},C3=t=>e=>n=>se(v(r=>o=>{const i=Ee(0)(t)(r.prng),s=Ee(0)(6.283185307179586)(i.prng);return{prng:s.prng,out:[{x:o.x+i.value*bn(s.value),y:o.y+i.value*hn(s.value)},...r.out]}})({prng:e,out:[]})(n).out),k3=t=>e=>n=>{if(e.kind==="SegMove")return Ta(t)(e.p);if(e.kind==="SegLine")return Gr(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 Gr(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});g()},L3=t=>e=>{if(e.kind==="SegMove")return Ta(t)(e.p);if(e.kind==="SegLine")return Gr(t)(e.p);if(e.kind==="SegQuad")return va(t)(e.c)(e.p);g()},gl=t=>e=>{const n=T3(e),r=v(a=>u=>a+u.len)(0)(n)*Er(0)(vo(1)(t)),o=[];let i=0,s=0;for(;s<n.length;){const a=s,u=i;if(a>=0&&a<n.length){if(u+n[a].len<=r){const c=n[a];L3(o)(c)(),i=u+c.len,s=a+1|0;continue}if(u>=r){s=n.length;continue}k3(o)(n[a])((r-u)/Er(n[a].len)(1e-4))()}s=n.length}return o},_l={offset:1.5,passes:2,rMax:14,overshoot:2.5},fl=t=>e=>n=>r=>{const o=r.y-n.y,i=n.y-e.y,s=r.x-n.x,a=He(s*s+o*o),u=n.x-e.x,c=He(u*u+i*i),_=vo(t.rMax*(R0(c>0&&a>0?Er(-1)(vo(1)((u*s+i*o)/(c*a))):1)/3.141592653589793))(.4*vo(c)(a));return{inP:c>0?{x:n.x-u/c*_,y:n.y-i/c*_}:n,curr:n,outP:a>0?{x:n.x+s/a*_,y:n.y+o/a*_}:n}},dl=t=>e=>{const n=e.length,r=[],o=0<e.length?N("Just",e[0]):w;if(o.tag==="Just"?Ta(r)(o._1)():o.tag==="Nothing"||g(),n>=3){let s=1;for(;s<=(n-2|0);){const a=s,u=a+1|0;if(u>=0&&u<e.length){if(a>=0&&a<e.length){const c=a-1|0;if(c>=0&&c<e.length){const _=fl(t)(e[c])(e[a])(e[u]);Gr(r)(_.inP)(),va(r)(_.curr)(_.outP)()}}s=a+1|0;continue}s=a+1|0}}const i=e.length-1|0;return i>=0&&i<e.length&&n>=2&&Gr(r)(e[i])(),r},S3=t=>e=>n=>r=>o=>{if(o.length<4)return dl(t)(o);const i=0<o.length?N("Just",o[0]):w,s=(()=>{if(i.tag==="Nothing")return{x:0,y:0};if(i.tag==="Just")return i._1;g()})(),a=o.length-1|0,u=Mr(Mr(e)(a)+a|0)(a),c=f=>{const h=Mr(f+a|0)(a);return h>=0&&h<o.length?o[h]:s},_=$(f=>fl(t)(c((u+f|0)-1|0))(c(u+f|0))(c((u+f|0)+1|0)))(Kt(0,a-1|0)),d=[],l=0<_.length?N("Just",_[0]):w;if(l.tag==="Just")if(Ta(d)(l._1.outP)(),x3((()=>{const f=zt(h=>w,h=>p=>N("Just",p),_);if(f.tag==="Nothing")return[];if(f.tag==="Just")return f._1;g()})())(f=>{const h=Gr(d)(f.inP);return()=>(h(),va(d)(f.curr)(f.outP)())})(),n)Gr(d)(l._1.inP)(),va(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const f=_.length-1|0;f>=0&&f<_.length?Gr(d)((()=>{const h=1-r;return{x:_[f].outP.x+(l._1.inP.x-_[f].outP.x)*h,y:_[f].outP.y+(l._1.inP.y-_[f].outP.y)*h}})())():Gr(d)(l._1.inP)()}else l.tag==="Nothing"||g();return d},hi=t=>e=>n=>r=>{const o=w3(1)(r.length-1|0),i=Ee(0)(nt(o))(qc("shape")(e)),s=J3(o-1|0)(de(Bn(i.value))),a=i.prng;return $(u=>{const c=Ee(0)(1)(qc(ie(u))(a)),_=Ee(-.18)(.3)(c.prng),d=c.value<.7,l=Ee(.5)(.85)(_.prng),f=C3(t.offset)(l.prng)(r);return{path:n?S3(t)(s)(d)(_.value)(f):dl(t)(f),alpha:l.value}})(Kt(0,t.passes-1|0))},E3=t=>e=>n=>hi(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}]),G3=t=>e=>n=>{const r=Er(0)(vo(1)(n)),o=e.h/nt(4),i=Er(6)(o*1.4);return vt(s=>s)($(s=>{if(r<Er(0)(nt(s)/nt(4)-.05))return w;const a=qc(ie(s))(t),u=Er(0)(nt(s)/nt(4)-.05),c=Mr(s)(2)===0,_=c?e.x-2:e.x+e.w+2,d=c?e.x+e.w+2:e.x-2,l=e.y+(nt(s)+.5)*o;return N("Just",{path:gl(Er(0)(vo(1)((r-u)/Er(1e-4)(vo(1)(nt(s+1|0)/nt(4)+.05)-u))))((()=>{const f={rMax:2,offset:.6,passes:1},h=se(v(m=>J=>{const x=Ee(-o*.08)(o*.08)(m.prng);return{prng:x.prng,out:[{x:_+(d-_)*(nt(J)/nt(4)),y:l+x.value},...m.out]}})({prng:a,out:[]})(Kt(0,4)).out),p=h.length<2?[]:hi(f)(a)(!1)(h);return 0<p.length?p[0].path:[]})()),width:i,alpha:1})})(Kt(0,3)))},ug=(t,e,n)=>({tag:t,_1:e,_2:n}),ba=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Pe=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},je=(()=>{const t=en.unfoldr(In);return e=>t(nn("IterNode",e,Dn))})(),gr=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},To=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},P3=Mt.foldMap(j0),Ca=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ll=ce(P)(Mt),hl=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},B3=N_(P),D3=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},bo=t=>{const e=t.Apply0();return n=>v(r=>o=>e.apply(e.Functor0().map(i=>i_)(r))(n(o)))(t.pure())},Br=bo(xo),pl=t=>e=>n=>r=>o=>i=>{const s={x:n.x+n.w/2,y:n.y+n.h/2},a={x:e.x+e.w/2,y:e.y+e.h/2},u=fi(o)(i)(r),c=0<t.length?N("Just",t[0]):w,_=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return a;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?N("Just",t[d]):w,f=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return s;g()})(),h=Id(128)(No(4)(as(2)(e)))(rl(_)(6)),p=_.x-a.x,m=2*(()=>{const j=_.y-a.y;return(p<0?-p:p)+(j<0?-j:j)})(),J=f.x-s.x,x=2*(()=>{const j=f.y-s.y;return(J<0?-J:J)+(j<0?-j:j)})(),y=m+Gs(t)+x,T=y<=1e-4?1:1-x/y,b=y<=1e-4?0:m/y,L=T-b,E=Id(128)(rl(f)(6))(No(4)(as(2)(n))),B={maxDelay:.4,smoothPasses:2},z=uo(t)(ba(0)(1)(L<=1e-4?0:(u-b)/L)),U=(()=>{if(z.tag==="Just")return z._1;if(z.tag==="Nothing")return _;g()})(),I=(()=>{if(T>=1)return 0;const j=(u-T)/(1-T),Z=j<0?0:j>1?1:j;return Z*Z*(3-2*Z)})(),A=(()=>{if(b<=1e-4)return 1;const j=u/b,Z=j<0?0:j>1?1:j;return Z*Z*(3-2*Z)})();return u<b?Jo("PolyShape",Rd(A)(h.from)(h.to)(B)):u>=T?Jo("PolyShape",Rd(I)(E.from)(E.to)(B)):Jo("CircleShape",U,6)},cg=t=>e=>n=>r=>o=>i=>{const s=pl(t)(e)(n)(r)(o)(i);if(s.tag==="PolyShape")return rg(s._1);if(s.tag==="CircleShape")return s._1;g()},gg=(()=>{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},s={r:42,g:48,b:60,a:255},a={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:Sr,nodeFill:ye,nodeStroke:Sr,text:Sr,edge:Sr,arrowFill:Sr,tokenOutsideFill:Sr,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:pa,tokenInsideAlpha:1,chipPillFill:Sr,chipPillText:ye,chipHairline:{r:26,g:26,b:26,a:90},trailDot:Sr,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:Sr,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:ye,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:pa,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:ye,chip:ye,chipShadow:{r:0,g:0,b:0,a:120},chipText:o,nodeFill:o,nodeStroke:ye,text:ye,edge:ye,arrowFill:ye,tokenOutsideFill:ye,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:pd,tokenInsideAlpha:.35,chipPillFill:ye,chipPillText:o,chipHairline:{r:255,g:255,b:255,a:120},trailDot:ye,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:pd,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:s,chip:{r:255,g:235,b:130,a:255},chipShadow:{r:100,g:110,b:125,a:90},chipText:s,nodeFill:{r:236,g:239,b:244,a:255},nodeStroke:s,text:s,edge:a,arrowFill:a,tokenOutsideFill:s,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:pa,tokenInsideAlpha:1,chipPillFill:s,chipPillText:ye,chipHairline:{r:60,g:66,b:78,a:90},trailDot:s,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};g()}})(),_g=t=>e=>St(je(t.nodes))(n=>{const r=Pe(n._1)(e.nodes);return r.tag==="Just"&&di(r._1).alpha>0?eg(n._2):[]}),I3=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,..._g(e)(n)],A3=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=no.traverse(r);return i=>s=>{const a=Jr(s),u=.32*i.size;return o(c=>n.bind(c===0?r.pure(0):t.measureText(i)(Re(c)(s)))(_=>n.bind(t.measureText(i)(Re(c+1|0)(s)))(d=>n.bind(t.measureInk(i)(c>=0&&c<a.length?Pi(a[c]):" "))(l=>r.pure({x:_,w:d-_,up:l.ascent-u,down:l.descent+u})))))(Kt(0,a.length-1|0))}},R3=t=>e=>{const n=o=>(o.x-e.x)*(o.x-e.x)+(o.y-e.y)*(o.y-e.y),r=v(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 $(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])},fg=t=>{const e=Vr(`
|
|
7
|
-
`)(t);return e.length===0?[""]:e},
|
|
8
|
-
`)(u.label===""?a:u.label),f=l.length===0?[""]:l,h={family:r.fontFamily,size:r.wobble?15:11,weight:r.wobble?800:500},p=h.size*1.2,m={tx:(u.x+u.w/2)*(1-d.scale),ty:(u.y+u.h/2)*(1-d.scale),sx:d.scale,sy:d.scale},
|
|
9
|
-
`)(y.label===""?x:y.label),B=E.length===0?[""]:E,z=L.size*1.2,U=y.shape==="Cylinder"?t.strokePath(_T({x:y.x,y:y.y,w:y.w,h:y.h}))({color:h.nodeStroke,width:1.25,lineJoin:$e,lineCap:Ln}):o.pure(),I=(y.shape==="Cylinder"?(y.y+(y.y+y.h+5-2*xn(y.h*.075)(y.w*.075)))/2:(y.y+y.y+y.h)/2)-nt(B.length)*z/2+z/2,A=T.tag==="PloppingOut"&&h.wobble?T._1:-1,j=A>=0,Z=di(T),M=j?{alpha:1,scale:1}:Z,W=y.x+y.w/2,O=y.y+y.h/2,D=n.bind(t.pushAlpha(M.alpha*p))(()=>n.bind(t.pushTransform({tx:W*(1-M.scale),ty:O*(1-M.scale),sx:M.scale,sy:M.scale}))(()=>{const F={x:y.x,y:y.y,w:y.w,h:y.h},S={color:h.nodeStroke,width:h.wobble?2:1.25*f,lineJoin:$e,lineCap:h.wobble?Vn:Ln};return n.bind((()=>{if(h.wobble){if(y.shape==="Rectangle")return i(b)(E3(_l)(cl(F))(F));const G=No(7)(y);return n.bind(i(b)((()=>{const Q=us(G);return G.length<4?[]:hi(ul)(Q)(!0)(G)})()))(()=>a(Q=>i(b)((()=>{const V=us(Q);return Q.length<2?[]:hi(ul)(V)(!1)(Q)})()))(y.shape==="Cylinder"?[s3(y)]:[]))}return n.bind(dT(t)(y.shape)(F)(7)(N("Just",{color:h.nodeFill,flat:!1}))(N("Just",S)))(()=>U)})())(()=>n.bind((()=>{if(J.tag==="Just"&&h.wobble&&!j){const G=J._1;return n.bind(u(c(L))(B))(Q=>{const V=It(dt=>ht=>it.compare(dt.x)(ht.x)),Y=de(Bn(y.x*7919+y.y*3001))*-1640531535|0,X=Ee(5)(7.5)(Y),q=Ee(0)(X.value)(X.prng),K=-(1+2*Ee(-1)(1)(q.prng).value*3.141592653589793/180),et=(dt,ht,Lt,Gt,Qt)=>V(vt(ne=>ne)([K*ht+dt>=Gt&&K*ht+dt<=Qt?N("Just",{x:ht,y:K*ht+dt}):w,K*Lt+dt>=Gt&&K*Lt+dt<=Qt?N("Just",{x:Lt,y:K*Lt+dt}):w,(()=>{const ne=(Gt-dt)/K;return ne>=ht&&ne<=Lt?N("Just",{x:ne,y:Gt}):w})(),(()=>{const ne=(Qt-dt)/K;return ne>=ht&&ne<=Lt?N("Just",{x:ne,y:Qt}):w})()])),lt=X.value,Ct=Mr(G.frameHash)(3),pt=Ct===0?{r:200,g:35,b:30,a:220}:Ct===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},Tt=y.x+y.w/2,Et=ln(Ht(dt=>ht=>Ht((()=>{const Lt=I+nt(dt)*z,Gt=Tt-v(Qt=>ne=>Qt+ne.w)(0)(ht)/2;return Qt=>ne=>{const Nn=L.size*.1,ze=Qt-1|0,Ot=ze>=0&&ze<ht.length&&Qt>0?(ht[ze].x+ht[ze].w+ne.x)/2:ne.x-Nn;return{x:Gt+Ot-1,y:Lt-ne.up-1,w:gr(0)((()=>{const qt=Qt+1|0;return qt>=0&&qt<ht.length&&Qt<(ht.length-1|0)?(ne.x+ne.w+ht[qt].x)/2-Ot:ne.x+ne.w+Nn-Ot})())+2,h:ne.up+ne.down+2}}})())(ht))(Q)),Zt=y.y+4,bt=y.x+y.w-4,Ut=y.x+4,Bt=Zt-K*Ut+q.value,wt=y.y+y.h-4,mt=St(St(Ht(dt=>ht=>{const Lt=(ht.from.x+ht.to.x)/2,Gt=(ht.from.y+ht.to.y)/2,Qt=Ee(-1)(1)(Y+(911*(dt+1|0)|0)|0),ne=Ee(-3)(5)(Qt.prng),Nn=Qt.value*3.141592653589793/180,ze=bn(Nn),Ot=hn(Nn),qt=We=>({x:Lt+(We.x-Lt)*ze-(We.y-Gt)*Ot,y:Gt+(We.x-Lt)*Ot+(We.y-Gt)*ze});return{from:(()=>{const We=qt(ht.from),vn=We.y-Gt,Ze=We.x-Lt,_n=He(Ze*Ze+vn*vn),Fe=_n<1e-4?1:(_n+ne.value)/_n;return{x:Lt+Ze*Fe,y:Gt+vn*Fe}})(),to:(()=>{const We=qt(ht.to),vn=Ee(-3)(5)(ne.prng).value,Ze=We.y-Gt,_n=We.x-Lt,Fe=He(_n*_n+Ze*Ze),oe=Fe<1e-4?1:(Fe+vn)/Fe;return{x:Lt+_n*oe,y:Gt+Ze*oe}})()}})(vt(dt=>{const ht=et(Bt+nt(dt)*lt,Ut,bt,Zt,wt);return ht.length===2?N("Just",{from:ht[0],to:ht[1]}):w})(Kt(0,Ca(1)(de(Bn((wt-K*bt-Bt)/lt)))))))(dt=>ft(ht=>ht.to.x-ht.from.x>1,v(ht=>Lt=>St(ht)(Gt=>{const Qt=et(Gt.from.y-K*Gt.from.x,Lt.x,Lt.x+Lt.w,Lt.y,Lt.y+Lt.h);return Qt.length===2?Qt[0].x>Gt.from.x+.001&&Qt[1].x<Gt.to.x-.001?[{from:Gt.from,to:Qt[0]},{from:Qt[1],to:Gt.to}]:Qt[0].x<=Gt.from.x+.001&&Qt[1].x<Gt.to.x-.001?[{from:Qt[1],to:Gt.to}]:Qt[0].x>Gt.from.x+.001&&Qt[1].x>=Gt.to.x-.001?[{from:Gt.from,to:Qt[0]}]:[]:[Gt]}))([dt])(Et))))(dt=>(()=>{const ht=dt.to.x-dt.from.x;return He(2)*(ht>=0?ht:-ht)<=28})()?[dt]:[{from:dt.from,to:{x:dt.from.x+(dt.to.x-dt.from.x)*.495,y:dt.from.y+(dt.to.y-dt.from.y)*.495}},{from:{x:dt.from.x+(dt.to.x-dt.from.x)*.505,y:dt.from.y+(dt.to.y-dt.from.y)*.505},to:dt.to}]),ct=mt.length,yt=dt=>gr(0)(To(1)(G.t*nt(ct)-nt(dt)));return n.bind(t.pushClip(el(No(7)(y)))(ns))(()=>n.bind(i(dt=>{const ht=dt._1,Lt=Ee(1.4)(1.9)(Y+(1303*(ht+1|0)|0)|0),Gt=Ee(.35)(.8)(Lt.prng),Qt=i(ne=>n.bind(t.pushAlpha(ne.alpha*Gt.value))(()=>n.bind(t.strokePath(gl(yt(ht))(ne.path))({color:pt,width:Lt.value,lineJoin:$e,lineCap:Vn}))(()=>r)))(hi({..._l,rMax:0,offset:.5})(Y+(53*(ht+1|0)|0)|0)(!1)([dt._2.from,dt._2.to]));return yt(ht)>0?Qt:o.pure()})(Ht(Gn)(mt)))(()=>s))})}return o.pure()})())(()=>n.bind((()=>{if(l==="LabelsShown"){const G=n.bind(t.pushAlpha(m))(()=>n.bind(i(Q=>t.drawText({x:y.x+y.w/2,y:I+nt(Q._1)*z,content:Q._2,font:L,color:h.text,align:Lr,baseline:kn}))(Ht(Gn)(B)))(()=>r));return m>0?G:o.pure()}if(l==="LabelsHidden")return o.pure();g()})())(()=>n.bind((()=>{const G=_(h)(F)(A);return j?G:o.pure()})())(()=>n.bind(d)(()=>r)))))}));return M.alpha*p>0?D:o.pure()}},$3=t=>{const e=q3(t),n=H3(t);return r=>{if(r.geometry.tag==="FlatNode"&&r.plan.tag==="FlatNodePlan"){const o={x:r.geometry._1.bounds.x,y:r.geometry._1.bounds.y,w:r.geometry._1.bounds.w,h:r.geometry._1.bounds.h,label:r.plan._1.label,shape:r.geometry._1.shape};if(r.role==="NodeShadow")return e(r.plan._1.palette)(r.plan._1.inkBoost>0)(o)(r.plan._1.animState);if(r.role==="NodeBody"||r.role==="NodeInversion")return n(Zc)(r.plan._1.inkBoost)(r.plan._1.palette)(r.alpha)(0)(r.plan._1.arrival)(r.id)(o)(r.plan._1.animState);g()}return t.Monad0().Applicative0().pure()}},vl=t=>e=>n=>{const r=o=>{const i=re(s=>o.x>=s._2.x-1&&o.x<=s._2.x+s._2.w+1&&o.y>=s._2.y-1&&o.y<=s._2.y+s._2.h+1)(je(e.nodes));return i.tag==="Just"?N("Just",i._1._2):w};return Br(o=>{const i=Pr(o._1)(n.edges);if(i.tag==="Just"){const s=Pr(o._1)(n.edgeFadeAlpha),a=(()=>{if(s.tag==="Nothing")return 1;if(s.tag==="Just")return s._1;g()})(),u=Kd({id:o._1,geometry:Fd("FlatRoute",(()=>{const c=(()=>{if(0<o._2.length){const d=r(o._2[0]);if(d.tag==="Just")return se(il(No(7)(d._1))(se(o._2)))}return o._2})(),_=c.length-1|0;if(_>=0&&_<c.length){const d=r(c[_]);if(d.tag==="Just")return il(No(7)(d._1))(c)}return c})()),visible:BT(i._1),arrow:(()=>{const c=io("conn:")(o._1);if(c.tag==="Just")return!1;if(c.tag==="Nothing")return!0;g()})(),plan:Qd("FlatEdgePlan",t)});return a===1?u:Ke({path:[],role:fn,layer:w,effects:[Ce("GroupAlpha",a)]})(u)}if(i.tag==="Nothing")return tt(ut("Return",void 0),_t);g()})(je(e.edges))},V3=t=>e=>n=>{const r={family:t.fontFamily,size:11,weight:500};return Br(o=>{if(o._2===""||(()=>{const a=Pr(o._1)(n.edges);return a.tag==="Nothing"||!(a.tag==="Just"&&_y.eq(a._1)(yf))})())return tt(ut("Return",void 0),_t);const i=Pr(o._1)(e.edges),s=(()=>{if(i.tag==="Just")return uo(i._1)(.5);if(i.tag==="Nothing")return w;g()})();if(s.tag==="Nothing")return tt(ut("Return",void 0),_t);if(s.tag==="Just"){const a=s._1,u=ts(r)(o._2),c=_=>{const d=_+12;return ss({owner:wo("EdgeText",o._1),text:o._2,spec:{x:a.x,y:a.y,content:o._2,font:r,color:t.chipPillText,align:Lr,baseline:kn},bounds:N("Just",{x:a.x-d/2,y:a.y-8.5,w:d,h:17}),plan:is("RoundedText",{radius:3,fill:N("Just",{color:t.chipPillFill,flat:!0}),stroke:w})})};return tt(u._1,(()=>{if(u._2.tag==="CatNil")return at("CatCons",c,st(H,H));if(u._2.tag==="CatCons")return at("CatCons",u._2._1,st(u._2._2._1,kt("Cons",at("CatCons",c,st(H,H)),u._2._2._2)));g()})())}g()})(je(e.edgeLabels))},Tl=t=>{const e=n=>{if(n.tag==="Leaf")return R;if(n.tag==="Node")return te("Node",n._1,n._2,n._3,sg({x:t.vx,y:t.vy,w:t.vw,h:t.vh})(n._4),e(n._5),e(n._6));g()};return e},X3=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=bo(r);return i=>s=>a=>u=>c=>_=>{const d=Yo(_).length,l=nt(d+1|0),f=m=>{const J=(a*l-nt(m))/1.5,x=J<0?0:J>1?1:J;return x*x*(3-2*x)},h=(m=>{let J=m,x=!0,y;for(;x;){const T=J;if(T>=d){x=!1,y=T;continue}if(f(T)>=1){J=T+1|0;continue}x=!1,y=T}return y})(0),p=h>=d?[]:tr(m=>f(m)>0)(Kt(h,d-1|0)).init;return n.bind((()=>{const m=t.drawText({x:u,y:c,content:Re(h)(_),font:i,color:s,align:ci,baseline:kn});return h>0?m:r.pure()})())(()=>o(m=>n.bind(t.measureText(i)(Re(m)(_)))(J=>{const x=f(m);return t.drawText({x:u+J,y:c-(1-x)*10,content:Re(1)(Ho(nr(Re(m)(_)))(_)),font:i,color:{...s,a:de(Bn(x*nt(s.a)))},align:ci,baseline:kn})}))(p))}},bl=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=bo(r),i=X3(t);return s=>{if(s.plan.tag==="PlainText")return t.drawText(s.spec);if(s.plan.tag==="RoundedText")return n.bind((()=>{const a=r.pure();if(s.bounds.tag==="Nothing")return a;if(s.bounds.tag==="Just")return t.drawRoundedRect(s.bounds._1)(s.plan._1.radius)(s.plan._1.fill)(s.plan._1.stroke);g()})())(()=>t.drawText(s.spec));if(s.plan.tag==="TokenTravelText"){const a=s.plan._1;return n.bind(o(u=>t.fillPath(ol(u)(1.5))(a.trailFill))(a.trail))(()=>n.bind((()=>{const u=r.pure();if(s.bounds.tag==="Nothing")return u;if(s.bounds.tag==="Just")return t.drawRoundedRect(s.bounds._1)(a.radius)(N("Just",a.fill))(w);g()})())(()=>i(s.spec.font)(s.spec.color)(a.reveal)(a.textLeft)(s.spec.y)(s.text)))}if(s.plan.tag==="TokenFillingText"){const a=s.plan._1;return n.bind(t.drawRoundedRect(a.shadow)(a.radius)(N("Just",a.shadowFill))(w))(()=>n.bind((()=>{const u=r.pure();if(s.bounds.tag==="Nothing")return u;if(s.bounds.tag==="Just")return t.drawRoundedRect(s.bounds._1)(a.radius)(N("Just",a.fill))(N("Just",a.stroke));g()})())(()=>n.bind(t.strokePath(a.leader)(a.stroke))(()=>t.drawText(s.spec))))}if(s.plan.tag==="AffineText")return t.drawTextAffine(s.plan._1)(s.spec);g()}},Y3=t=>e=>n=>r=>o=>i=>s=>ml(r)(o)(i)({owner:wo("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:ci,baseline:kn},bounds:N("Just",r),plan:is("TokenTravelText",{trail:R3(r)(s),trailFill:{color:e.trailDot,flat:!0},radius:3,fill:{color:e.chipPillFill,flat:!0},textLeft:r.x+14,reveal:(()=>{const a=n.phaseInLabel/.45;return a<0?0:a>1?1:a})()})}),ka=t=>e=>n=>r=>{const o=$(f=>nt(Ca(1)(Yo(f).length)))(r),i=gr(1)(v(er)(0)(o)),s=fi(e)(n)(t),a=s*i,u=Ca(1)(r.length),c=(f=>h=>p=>{let m=f,J=h,x=p,y=!0,T;for(;y;){const b=m,L=J,E=zt(B=>w,B=>z=>N("Just",{head:B,tail:z}),x);if(E.tag==="Nothing"){y=!1,T=Ca(0)(u-1|0);continue}if(E.tag==="Just"){if(L+E._1.head>=a){y=!1,T=b;continue}m=b+1|0,J=L+E._1.head,x=E._1.tail;continue}g()}return T})(0)(0)(o),_=v(er)(0)(c<1?[]:Dt(0,c,o)),d=_/i;if(c>=0&&c<o.length){const f=(_+o[c])/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(f<=d)return 1;const h=(s-d)/(f-d);return h<0?0:h>1?1:h})()}}const l=(_+1)/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(l<=d)return 1;const f=(s-d)/(l-d);return f<0?0:f>1?1:f})()}},Cl=t=>e=>n=>r=>o=>t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(ka(r)(0)(0)($(bi)(o)).line))(i=>{const s=i+28;return t.Applicative0().pure({x:n.x+n.w/2-s/2,y:n.y-25.2-14,w:s,h:25.2})}),U3=t=>{const e=t.Bind1(),n=t.Applicative0(),r=no.traverse(n);return o=>i=>s=>e.Apply0().Functor0().map(a=>ll(vt(u=>u)(a)))(r(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const u=Pe(a._2._1.node)(i.nodes);if(u.tag==="Just")return e.bind(Cl(t)(o)(u._1)(a._2._1.progress)(a._2._1.labels))(c=>n.pure(N("Just",C(a._1,c))));if(u.tag==="Nothing")return n.pure(w);g()}return n.pure(w)})(je(s.tokens)))},K3=t=>e=>n=>r=>o=>i=>s=>a=>u=>{const c=cg(n)(r)(o)(i)(s)(a);return t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(ka(i)(s)(a)(St(u)(fg)).line))(_=>t.Applicative0().pure({x:c.x+14+_/2-_/2-14,y:c.y-6-8-6.6-6,w:_+28,h:25.2}))},j3=t=>{const e=t.Bind1(),n=t.Applicative0(),r=no.traverse(n);return o=>i=>s=>e.Apply0().Functor0().map(a=>ll(vt(u=>u)(a)))(r(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const u=Pe(a._2._1.target)(i.nodes),c=Pe(a._2._1.source)(i.nodes),_=Pr(a._2._1.edge)(i.edges);if(_.tag==="Just"&&c.tag==="Just"&&u.tag==="Just"){const d=(()=>{if(a._2._1.direction==="Forward")return _._1;if(a._2._1.direction==="Backward")return se(_._1);g()})(),l=cg(d)(c._1)(u._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);return e.bind(K3(t)(o)(d)(c._1)(u._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(f=>n.pure(N("Just",C(a._1,{id:a._1,rect:f,token:l}))))}}return n.pure(w)})(je(s.tokens)))},hg=t=>{const e=t.Bind1(),n=j3(t),r=U3(t);return o=>i=>s=>a=>e.bind(n(o)(s)(a))(u=>e.bind(r(o)(s)(a))(c=>t.Applicative0().pure(y3({x:i.vx,y:i.vy,w:i.vw,h:i.vh})([...vt(_=>{const d=Pe(_._1)(a.nodes);return d.tag==="Just"&&di(d._1).alpha>0?N("Just",{x:_._2.x,y:_._2.y,w:_._2.w,h:_._2.h}):w})(je(s.nodes)),...(()=>{const _=(d,l)=>{if(d.tag==="Leaf")return l;if(d.tag==="Node")return _(d._5,kt("Cons",d._4,_(d._6,l)));g()};return jt(le.foldr,_(c,H))})()])(vt(_=>hl(_)(u))((()=>{const _=d=>{if(d.tag==="Leaf")return R;if(d.tag==="Node")return te("Node",d._1,d._2,d._3,void 0,_(d._5),_(d._6));g()};return It(P.compare)(jt(rn.foldr,_(u)))})())))))},Z3=hg(Rc),kl=t=>e=>n=>{const r=Ii(6)(.55)(ba(0)(1)((1-t)/.06)),o=t>.94,i=o&&n>1e-4,s=Ii(6)(.55)(ba(0)(1)(t/.06)),a=t<.06,u=a&&e>1e-4,c=o&&n<=1e-4;return{popScale:u?s:i?r:1,flipY:a&&e<=1e-4?s: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})()}},La=t=>e=>n=>r=>Ke({path:[],role:fn,layer:N("Just",Zv),effects:[]})(Br(o=>{if(o._2.tag==="Travelling"){if(o._2._1.labels.length!==0){const i=Pe(o._2._1.target)(e.nodes),s=Pe(o._2._1.source)(e.nodes),a=Pr(o._2._1.edge)(e.edges),u=hl(o._1)(r);if(u.tag==="Just"&&a.tag==="Just"&&s.tag==="Just"&&i.tag==="Just")return Y3(o._1)(t)(ka(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost)(St(o._2._1.labels)(fg)))(u._1)({x:u._1.x+u._1.w/2,y:u._1.y+u._1.h/2})(kl(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost))(cg((()=>{if(o._2._1.direction==="Forward")return a._1;if(o._2._1.direction==="Backward")return se(a._1);g()})())(s._1)(i._1)(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost))}return tt(ut("Return",void 0),_t)}if(o._2.tag==="Filling"&&o._2._1.labels.length!==0){const i=Pe(o._2._1.node)(e.nodes);if(i.tag==="Just"){const s=i._1,a=Cl(Rc)(Yd)(s)(o._2._1.progress)(o._2._1.labels),u=c=>M3(o._1)(t)(ka(o._2._1.progress)(0)(0)(St(o._2._1.labels)(fg)).line)(s)(c)({x:c.x+c.w/2,y:c.y+c.h/2})(kl(o._2._1.progress)(0)(0));return tt(a._1,(()=>{if(a._2.tag==="CatNil")return at("CatCons",u,st(H,H));if(a._2.tag==="CatCons")return at("CatCons",a._2._1,st(a._2._2._1,kt("Cons",at("CatCons",u,st(H,H)),a._2._2._2)));g()})())}if(i.tag==="Nothing")return tt(ut("Return",void 0),_t);g()}return tt(ut("Return",void 0),_t)})(je(n.tokens))),Ll=t=>e=>n=>r=>{const o=Z3(Yd)(e)(n)(r);return tt(o._1,(()=>{if(o._2.tag==="CatNil")return at("CatCons",i=>La(t)(n)(r)(i),st(H,H));if(o._2.tag==="CatCons")return at("CatCons",o._2._1,st(o._2._2._1,kt("Cons",at("CatCons",i=>La(t)(n)(r)(i),st(H,H)),o._2._2._2)));g()})())},tb=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>o=>{const i=o.length-1|0,s=i<1?[]:Dt(0,i,o),a=s.length-1|0,u=a>=0&&a<s.length?N("Just",s[a]):w,c=o.length-1|0,_=c>=0&&c<o.length?N("Just",o[c]):w;if(_.tag==="Just"&&u.tag==="Just"){const d=Ee(.78)(1.18)(us(o)+19|0),l=Ee(.4)(.62)(d.prng),f=r.wobble?8.75*l.value:4.375,h=Ee(.4)(.62)(l.prng),p=r.wobble?8.75*h.value:4.375,m=_._1.y-u._1.y,J=_._1.x-u._1.x,x=He(J*J+m*m),y=m/x,T=-y,b=J/x,L=_._1.x+b*.875,E=_._1.y+y*.875,B=r.wobble?8.75*d.value:8.75,z=L-b*B,U=E-y*B,I=z+T*f,A=U+b*f,j=[1,L,E,2,z+T*4.375,U+b*4.375,2,z-T*4.375,U-b*4.375,5],Z=z-T*p,M=U-b*p,W={color:r.arrowFill,width:2,lineJoin:$e,lineCap:Vn};return x<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,I,A,2,L,E])(W))(()=>t.strokePath([1,Z,M,2,L,E])(W)):t.fillPath(j)({color:r.arrowFill,flat:!0})}return n.pure()}},eb=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=bo(n),i=t.popAlpha,s=tb(t);return a=>u=>c=>_=>{const d=t3(8)(c);if(_.hi<=_.lo)return n.pure();const l=u3(d)(_.lo)(_.hi);if(l.length===0)return n.pure();const f={color:a.edge,width:a.wobble?2:.9375,lineJoin:$e,lineCap:Vn},h=a.wobble?Ee(-10)(4)(us(l)).value:0,p=a.wobble?b3(h)(l):l;return r.bind(a.wobble?o(m=>r.bind(t.pushAlpha(m.alpha))(()=>r.bind(t.strokePath(m.path)(f))(()=>i)))((()=>{const m=us(l);return p.length<2?[]:hi(z3)(m)(!1)(p)})()):t.strokePath(KT(l))(f))(()=>{const m=s(a)(p);return u&&_.hi>=.999?m:n.pure()})}},nb=t=>{const e=eb(t);return n=>n.geometry.tag==="FlatRoute"&&n.plan.tag==="FlatEdgePlan"?e(n.plan._1)(n.arrow)(n.geometry._1)(n.visible):t.Monad0().Applicative0().pure()},rb=t=>e=>{const n=i=>{const s=Pe(i)(t.nodes);if(s.tag==="Nothing")return!1;if(s.tag==="Just"){const a=s._1;return!Ne(u=>0<u._2.length&&u._2[0].x>=a.x&&u._2[0].x<=a.x+a.w&&u._2[0].y>=a.y&&u._2[0].y<=a.y+a.h,je(t.edges))}g()},r=v(i=>s=>(i*31|0)+$r(s)|0)(5381)(Jr(e.frameTitle)),o=i=>{const s=Pe(i)(t.nodes);if(s.tag==="Nothing")return!1;if(s.tag==="Just"){const a=s._1;return!Ne(u=>{const c=u._2.length-1|0;return c>=0&&c<u._2.length&&u._2[c].x>=a.x&&u._2[c].x<=a.x+a.w&&u._2[c].y>=a.y&&u._2[c].y<=a.y+a.h},je(t.edges))}g()};return v(i=>s=>{const a=s._2;return B3(u=>{if(u.tag==="Nothing")return N("Just",a);if(u.tag==="Just")return N("Just",{t:gr(u._1.t)(a.t),angle:a.t>=u._1.t?a.angle:u._1.angle,bigCircle:u._1.bigCircle||a.bigCircle,frameHash:u._1.frameHash});g()})(s._1)(i)})(R)(St(je(e.tokens))(i=>{if(i._2.tag==="Filling"){const s=i._2._1.node;return[C(s,{t:1,angle:(()=>{const a=vt(u=>(()=>{const c=Pe(s)(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)(je(t.edges));if(0<a.length){const u=a[0].length-1|0,c=u<1?[]:Dt(0,u,a[0]),_=c.length-1|0;if(_>=0&&_<c.length){const d=a[0].length-1|0;return d>=0&&d<a[0].length?oo(a[0][d].y-c[_].y)(a[0][d].x-c[_].x):0}a[0].length-1|0}return 0})(),bigCircle:n(s)||o(s),frameHash:r})]}if(i._2.tag==="Travelling"){if(i._2._1.progress>=.75)return[C(i._2._1.target,{t:(i._2._1.progress-.75)/.25,angle:(()=>{const s=Pr(i._2._1.edge)(t.edges);if(s.tag==="Just"){const a=s._1.length-1|0,u=a<1?[]:Dt(0,a,s._1),c=u.length-1|0;if(c>=0&&c<u.length){const _=s._1.length-1|0;return _>=0&&_<s._1.length?oo(s._1[_].y-u[c].y)(s._1[_].x-u[c].x):0}return s._1.length-1|0,0}if(s.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[C(i._2._1.source,{t:i._2._1.progress/.25,angle:(()=>{const s=Pr(i._2._1.edge)(t.edges);if(s.tag==="Just")return 1<s._1.length&&0<s._1.length?oo(s._1[1].y-s._1[0].y)(s._1[1].x-s._1[0].x):0;if(s.tag==="Nothing")return 0;g()})(),bigCircle:n(i._2._1.source)||o(i._2._1.source),frameHash:r})]}return[]}))},ob=t=>v(e=>n=>(e*31|0)+$r(n)|0)(5381)(Jr(t.frameTitle)),Sl=t=>e=>n=>r=>o=>{const i=ob(o),s=rb(r)(o);return Br(a=>{const u=Pe(a._1)(o.nodes);if(u.tag==="Just")return yl(Xd)(t)(e)(n)((()=>{const c=Pe(a._1)(o.nodeFadeAlpha);if(c.tag==="Nothing")return 1;if(c.tag==="Just")return c._1;g()})())((()=>{const c=Pe(a._1)(o.nodeLabelFadeAlpha);if(c.tag==="Nothing")return 1;if(c.tag==="Just")return c._1;g()})())((()=>{const c=Pe(a._1)(s);return c.tag==="Just"?N("Just",c._1):c.tag==="Nothing"&&D3(a._1)(o.visited)?N("Just",{t:1,angle:0,bigCircle:!1,frameHash:i}):w})())(a._1)(a._2)(u._1);if(u.tag==="Nothing")return tt(ut("Return",void 0),_t);g()})(je(r.nodes))},ib=t=>t,El=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,s={...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?s:e},Gl=t=>e=>t.width<=0||t.height<=0?e:El(t.width/t.height)(e),sb=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Pl=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Bl=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},pg=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ab=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ub=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},mg=(()=>{const t=en.unfoldr(In);return e=>t(nn("IterNode",e,Dn))})(),cb=Ar(xo)(Mt),gb=t=>e=>{const n=hn(t.angle),r=bn(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},_b=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],yg=t=>e=>{const n=r=>sb(0)(255)(de(On(nt(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},Ve=t=>e=>n=>r=>({x:(e-n)*bn(t.angle),y:(e+n)*hn(t.angle)-r}),xg=t=>{const e=zt(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,...St(e._1.tail)(n=>[2,n.x,n.y]),5];g()},fb=t=>e=>n=>{const r=n.id,o=n.np,i=tg({id:r,role:Xd,geometry:Yc("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:Uc("IsoNodePlan",{config:t,palette:e})}),s=()=>ss({owner:wo("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:Lr,baseline:kn},bounds:w,plan:is("AffineText",gb(t)(o.y+o.h))});return tt(i._1,(()=>{if(i._2.tag==="CatNil")return at("CatCons",s,st(H,H));if(i._2.tag==="CatCons")return at("CatCons",i._2._1,st(i._2._2._1,kt("Cons",at("CatCons",s,st(H,H)),i._2._2._2)));g()})())},db=t=>e=>n=>r=>o=>{const i=Qe(Gn,o,Dt(1,o.length,o)),s=i.length-1|0;return Ht(a=>u=>({depth:(u._1.x+u._1.y+u._2.x+u._2.y)/2,draw:Kd({id:n,geometry:Fd("IsoSegments",[[Ve(t)(u._1.x)(u._1.y)(0),Ve(t)(u._2.x)(u._2.y)(0)]]),visible:{lo:0,hi:1},arrow:r&&a===s,plan:Qd("IsoEdgePlan",{config:t,palette:e})})}))(i)},lb=t=>e=>n=>r=>o=>{const i=(()=>{if(t==="Forward")return o;if(t==="Backward")return se(o);g()})();if(0<i.length){const a=uo(i)(Pl(0)(1)(fi(n)(r)(e)));if(a.tag==="Nothing")return i[0];if(a.tag==="Just")return a._1;g()}const s=uo(i)(Pl(0)(1)(fi(n)(r)(e)));if(s.tag==="Nothing")return{x:0,y:0};if(s.tag==="Just")return s._1;g()},hb=t=>{const e=zt(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,...St(e._1.tail)(n=>[2,n.x,n.y])];g()},pb=t=>{const e=zt(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=v(r=>o=>({minX:Bl(r.minX)(o.x),minY:Bl(r.minY)(o.y),maxX:pg(r.maxX)(o.x),maxY:pg(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()},mb=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,s=(a,u)=>t.fillStrokePath(xg(a))({color:u,flat:!0})({color:i.nodeStroke,width:1,lineJoin:$e,lineCap:Ln});return n.bind(s(o.south,yg(.66)(i.nodeFill)))(()=>n.bind(s(o.east,yg(.82)(i.nodeFill)))(()=>s(o.top,i.nodeFill)))}return e.Applicative0().pure()}},yb=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,s=(a,u)=>t.fillStrokePath(xg(a))({color:yg(u)(i.tokenOutsideFill),flat:!0})({color:i.tokenOutsideStroke,width:1,lineJoin:$e,lineCap:Ln});return n.bind(s(o.south,.66))(()=>n.bind(s(o.east,.82))(()=>s(o.top,1)))}return e.Applicative0().pure()}},xb={angle:.5235987755982988,boxHeight:26,transparentBg:!0},wb=t=>e=>n=>{const r=n.x-5.5,o=n.x+5.5,i=n.y-5.5,s=n.y+5.5,a=e+11,u=Ve(t)(o)(i)(a),c=Ve(t)(o)(s)(a),_=Ve(t)(r)(s)(a),d=Ve(t)(o)(s)(e);return{south:[Ve(t)(r)(s)(e),d,c,_],east:[Ve(t)(o)(i)(e),d,c,u],top:[Ve(t)(r)(i)(a),u,c,_]}},Jb=t=>e=>n=>r=>{const o=r._1,i=(s,a)=>({depth:a.x+a.y,draw:jd({id:o,pass:Hd,geometry:zd("IsoCube",wb(t)(s)(a)),position:a,plan:qd("IsoTokenPlan",{config:t,palette:e,baseZ:s})})});if(r._2.tag==="Travelling"){const s=ab(r._2._1.edge)(n.edges);return s.tag==="Just"?N("Just",i(0,lb(r._2._1.direction)(r._2._1.progress)(r._2._1.holdPre)(r._2._1.holdPost)(s._1))):w}if(r._2.tag==="Filling"){const s=ub(r._2._1.node)(n.nodes);if(s.tag==="Just")return N("Just",i(t.boxHeight,{x:s._1.x+s._1.w/2,y:s._1.y+s._1.h/2}))}return w},Nb=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:Ve(t)(e.x)(e.y)(0),b:Ve(t)(r)(e.y)(0),c:Ve(t)(r)(n)(0),d:Ve(t)(e.x)(n)(0)},top:{a:Ve(t)(e.x)(e.y)(t.boxHeight),b:Ve(t)(r)(e.y)(t.boxHeight),c:Ve(t)(r)(n)(t.boxHeight),d:Ve(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},Dl=t=>e=>$(n=>({id:n._1,np:n._2,box:Nb(t)(n._2)}))(mg(e.nodes)),vb=t=>e=>[...St(Dl(t)(e))(_b),...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,kt("Cons",r._4,n(r._6,o)));g()};return St(jt(le.foldr,n(e.edges,H)))($(r=>Ve(t)(r.x)(r.y)(0)))})()],Tb=t=>e=>n=>r=>{const o=gg(e),i=[...St(mg(n.edges))(u=>db(t)(o)(u._1)((()=>{const c=io("conn:")(u._1);if(c.tag==="Just")return!1;if(c.tag==="Nothing")return!0;g()})())(u._2)),...$(u=>({depth:u.box.depth,draw:fb(t)(o)(u)}))(Dl(t)(n)),...vt(Jb(t)(o)(n))(mg(r.tokens))],s=Ud({viewport:pb(vb(t)(n)),clear:N("Just",t.transparentBg?o.bgTransparent:o.bg),dots:w}),a=()=>cb(u=>u.draw)(It(u=>c=>it.compare(u.depth)(c.depth))(i));return tt(s._1,(()=>{if(s._2.tag==="CatNil")return at("CatCons",a,st(H,H));if(s._2.tag==="CatCons")return at("CatCons",s._2._1,st(s._2._2._1,kt("Cons",at("CatCons",a,st(H,H)),s._2._2._2)));g()})())},bb=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=pg(1e-4)(He(n*n+e*e)),o=e/r,i=n/r,s=t.to.y-o*7,a=t.to.x-i*7;return xg([t.to,{x:a-o*3,y:s+i*3},{x:a+o*3,y:s-i*3}])},Cb=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Ar(n)(Mt);return o=>{if(o.geometry.tag==="IsoSegments"&&o.plan.tag==="IsoEdgePlan"){const i=o.plan._1.palette,s=o.geometry._1;return e.Bind1().bind(r(a=>t.strokePath(hb(a))({color:i.edge,width:1.5,lineJoin:$e,lineCap:Vn}))(s))(()=>{const a=s.length-1|0;if(a>=0&&a<s.length){const c=s[a],_=c.length-1|0,d=_<1?[]:Dt(0,_,c),l=d.length-1|0;if(l>=0&&l<d.length){const h=s.length-1|0,p=(()=>{if(h>=0&&h<s.length){const m=s[h],J=m.length-1|0;if(J>=0&&J<m.length)return t.fillPath(bb({from:d[l],to:m[J]}))({color:i.arrowFill,flat:!0})}return n.pure()})();return o.arrow?p:n.pure()}s.length-1|0;const f=n.pure();return o.arrow?f:n.pure()}s.length-1|0;const u=n.pure();return o.arrow?u:n.pure()})}return n.pure()}},Il=(t,e)=>({tag:t,_1:e}),Sa=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},kb=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Lb=Ao(xo)(Mt),Sb=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Eb=Il("ResolvedLabels"),Gb=t=>{const e=re(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return Hs(t);g()},pi=t=>e=>{const n=Sa(1)(_e(e.rootLayout).w),r=co(e.rootLayout)(e.camera),o=!e.diving&&e.levels.length===1?1:kb(0)(1)(r.w/n),i=Hs(e).state.frameTitle===""?0*o:40*o,s=t.padding*o*o;return(()=>{if(t.outputAspect.tag==="Nothing")return ib;if(t.outputAspect.tag==="Just")return El(t.outputAspect._1);g()})()({vx:r.x-s,vy:r.y-s-i,vw:r.w+2*s,vh:r.h+2*s+i})},Pb=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=wg(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,s=n._1.h*t.segment.placement.scale;return[1,r,o,2,r+i,o,2,r+i,o+s,2,r,o+s,5]}}g()},Jg=t=>e=>{const n=Xm(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}},Al=t=>e=>t===""?tt(ut("Return",void 0),_t):ss({owner:OT,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:ci,baseline:Xv},bounds:w,plan:xa}),Rl=t=>e=>{if(t==="")return tt(ut("Return",void 0),_t);const n=e.vh/720,r=56*n,o=ts({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:56,weight:700})(t),i=s=>{const a=r+16*n*2,u=s*n+28*n*2,c=e.vy+e.vh/2,_=e.vx+e.vw/2,d={x:_-u/2,y:c-a/2,w:u,h:a};return wa(ya("TitleCardOverlay",{backing:{path:_i(d)(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:$e,lineCap:Vn})},text:{owner:Vd,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:Lr,baseline:kn},bounds:N("Just",d),plan:xa}}))};return tt(o._1,(()=>{if(o._2.tag==="CatNil")return at("CatCons",i,st(H,H));if(o._2.tag==="CatCons")return at("CatCons",o._2._1,st(o._2._2._1,kt("Cons",at("CatCons",i,st(H,H)),o._2._2._2)));g()})())},Fl=t=>e=>{if(t==="")return tt(ut("Return",void 0),_t);const n=e.vh/720,r=15*n,o=ts({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:15,weight:600})(t),i=s=>{const a=e.vy+12*n,u=r+6*n*2,c=s*n+11*n*2,_=e.vx+e.vw/2,d={x:_-c/2,y:a,w:c,h:u};return wa(ya("FrameTitleOverlay",{backing:N("Just",{path:_i(d)(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:$e,lineCap:Vn})}),text:{owner:Vd,text:t,spec:{x:_,y:a+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:Lr,baseline:kn},bounds:N("Just",d),plan:xa}}))};return tt(o._1,(()=>{if(o._2.tag==="CatNil")return at("CatCons",i,st(H,H));if(o._2.tag==="CatCons")return at("CatCons",o._2._1,st(o._2._2._1,kt("Cons",at("CatCons",i,st(H,H)),o._2._2._2)));g()})())},Bb=t=>e=>n=>r=>o=>i=>s=>a=>{const u=gg(t.theme),c=(()=>{if(a.tag==="ResolvedLabels")return Ll(u)(o)(i)(s);if(a.tag==="SpringLabels")return La(u)(i)(s)(Tl(o)(a._1));g()})(),_=Ud({viewport:o,clear:N("Just",t.transparentBg?u.bgTransparent:u.bg),dots:w}),d=()=>{const l=Ke({path:[],role:fn,layer:w,effects:[...n<1?[Ce("GroupAlpha",n)]:[],...r>0?[Ce("GroupBlur",r)]:[]]})((()=>{const f=vl(u)(i)(s),h=()=>{const p=Jl(u)(t.halftoneShadows)(i)(s),m=()=>{const J=Sl(jc)(1)(u)(i)(s),x=()=>{const y=Nl(u)(i)(s),T=()=>{const b=lg(u)(o)(i)(s),L=()=>{const E=xl(oT)(u)(i)(s),B=()=>{const z=()=>{const U=V3(u)(i)(s);return s.staticKind!=="Animated"?U:tt(ut("Return",void 0),_t)};return tt(c._1,(()=>{if(c._2.tag==="CatNil")return at("CatCons",z,st(H,H));if(c._2.tag==="CatCons")return at("CatCons",c._2._1,st(c._2._2._1,kt("Cons",at("CatCons",z,st(H,H)),c._2._2._2)));g()})())};return tt(E._1,(()=>{if(E._2.tag==="CatNil")return at("CatCons",B,st(H,H));if(E._2.tag==="CatCons")return at("CatCons",E._2._1,st(E._2._2._1,kt("Cons",at("CatCons",B,st(H,H)),E._2._2._2)));g()})())};return tt(b._1,(()=>{if(b._2.tag==="CatNil")return at("CatCons",L,st(H,H));if(b._2.tag==="CatCons")return at("CatCons",b._2._1,st(b._2._2._1,kt("Cons",at("CatCons",L,st(H,H)),b._2._2._2)));g()})())};return tt(y._1,(()=>{if(y._2.tag==="CatNil")return at("CatCons",T,st(H,H));if(y._2.tag==="CatCons")return at("CatCons",y._2._1,st(y._2._2._1,kt("Cons",at("CatCons",T,st(H,H)),y._2._2._2)));g()})())};return tt(J._1,(()=>{if(J._2.tag==="CatNil")return at("CatCons",x,st(H,H));if(J._2.tag==="CatCons")return at("CatCons",J._2._1,st(J._2._2._1,kt("Cons",at("CatCons",x,st(H,H)),J._2._2._2)));g()})())};return tt(p._1,(()=>{if(p._2.tag==="CatNil")return at("CatCons",m,st(H,H));if(p._2.tag==="CatCons")return at("CatCons",p._2._1,st(p._2._2._1,kt("Cons",at("CatCons",m,st(H,H)),p._2._2._2)));g()})())};return tt(f._1,(()=>{if(f._2.tag==="CatNil")return at("CatCons",h,st(H,H));if(f._2.tag==="CatCons")return at("CatCons",f._2._1,st(f._2._2._1,kt("Cons",at("CatCons",h,st(H,H)),f._2._2._2)));g()})())})());if(n>0){const f=()=>{const h=Al(t.watermark)(o),p=()=>s.staticKind==="TitleCard"?Rl(s.frameTitle)(o):Fl(s.frameTitle)(o);return tt(h._1,(()=>{if(h._2.tag==="CatNil")return at("CatCons",p,st(H,H));if(h._2.tag==="CatCons")return at("CatCons",h._2._1,st(h._2._2._1,kt("Cons",at("CatCons",p,st(H,H)),h._2._2._2)));g()})())};return tt(l._1,(()=>{if(l._2.tag==="CatNil")return at("CatCons",f,st(H,H));if(l._2.tag==="CatCons")return at("CatCons",l._2._1,st(l._2._2._1,kt("Cons",at("CatCons",f,st(H,H)),l._2._2._2)));g()})())}return tt(ut("Return",void 0),at("CatCons",()=>{const f=Al(t.watermark)(o),h=()=>s.staticKind==="TitleCard"?Rl(s.frameTitle)(o):Fl(s.frameTitle)(o);return tt(f._1,(()=>{if(f._2.tag==="CatNil")return at("CatCons",h,st(H,H));if(f._2.tag==="CatCons")return at("CatCons",f._2._1,st(f._2._2._1,kt("Cons",at("CatCons",h,st(H,H)),f._2._2._2)));g()})())},st(H,H)))};return tt(_._1,(()=>{if(_._2.tag==="CatNil")return at("CatCons",d,st(H,H));if(_._2.tag==="CatCons")return at("CatCons",_._2._1,st(_._2._2._1,kt("Cons",at("CatCons",d,st(H,H)),_._2._2._2)));g()})())},Ng=t=>e=>n=>r=>Lb(r.minis)(o=>{const i=Ql(t)(e)(n)(R)(r)(o);return(()=>{const s=o.segment.path.length-1|0;return o.bgAlpha>0&&s>=0&&s<o.segment.path.length&&(()=>{const a=wg(o.segment.path[s])(r.state.nodes);if(a.tag==="Just")return a._1.tag==="Hidden"?!1:a._1.tag!=="PloppingOut";if(a.tag==="Nothing")return!1;g()})()})()?i:tt(ut("Return",void 0),_t)}),Ql=t=>e=>n=>r=>o=>i=>{const s=i.state,a={tx:i.segment.placement.tx,ty:i.segment.placement.ty,sx:i.segment.placement.scale,sy:i.segment.placement.scale},u=gg(t.theme),c=i.segment.layout,_=_e(c),d={vx:_.x-1e3,vy:_.y-1e3,vw:_.w+2e3,vh:_.h+2e3},l=i.segment.path.length-1|0,f=l>=0&&l<i.segment.path.length?wg(i.segment.path[l])(o.segment.layout.nodes):w,h=i.segment.placement.scale*n,p=Sb(8)(Sa(1)(1/(1.25*Sa(1e-6)(h)))),m=11*h>=5?jc:Zc,J=Jg(e.viewport)(i),x=(()=>{if(m==="LabelsHidden")return tt(ut("Return",void 0),_t);if(m==="LabelsShown")return r.tag==="Leaf"?Ll(u)(J)(c)(s):La(u)(c)(s)(Tl(J)(r));g()})();return Ke({path:i.segment.path,role:i.role,layer:w,effects:[Ce("GroupAlpha",i.bgAlpha),...i.blur>0?[Ce("GroupBlur",i.blur*i.segment.placement.scale)]:[]]})((()=>{const y=Ke({path:i.segment.path,role:i.role,layer:w,effects:[Ce("GroupClip",Pb(o)((()=>{const b=i.segment.path.length-1|0;return b>=0&&b<i.segment.path.length?N("Just",i.segment.path[b]):w})()),ns)]})((()=>{const b=(()=>{if(f.tag==="Just")return Ke({path:o.segment.path,role:o.role,layer:w,effects:[Ce("GroupTransform",li,{tx:o.segment.placement.tx,ty:o.segment.placement.ty,sx:o.segment.placement.scale,sy:o.segment.placement.scale})]})(wa(ya("FloorOverlay",{path:eg({...f._1,x:f._1.x+1,y:f._1.y+1,w:f._1.w-2,h:f._1.h-2}),fill:N("Just",{color:u.bg,flat:!0}),stroke:w})));if(f.tag==="Nothing")return tt(ut("Return",void 0),_t);g()})(),L=o.role==="Active"||o.role==="FlyThrough"?b:tt(ut("Return",void 0),_t),E=()=>{const B=Ke({path:i.segment.path,role:i.role,layer:w,effects:[Ce("GroupTransform",li,a)]})((()=>{const U=vl(u)(c)(s),I=()=>{const A=Jl(u)(t.halftoneShadows)(c)(s),j=()=>{const Z=Sl(m)(p)(u)(c)(s),M=()=>{const W=Nl(u)(c)(s);return tt(W._1,(()=>{if(W._2.tag==="CatNil")return at("CatCons",()=>lg(u)(d)(c)(s),st(H,H));if(W._2.tag==="CatCons")return at("CatCons",W._2._1,st(W._2._2._1,kt("Cons",at("CatCons",()=>lg(u)(d)(c)(s),st(H,H)),W._2._2._2)));g()})())};return tt(Z._1,(()=>{if(Z._2.tag==="CatNil")return at("CatCons",M,st(H,H));if(Z._2.tag==="CatCons")return at("CatCons",Z._2._1,st(Z._2._2._1,kt("Cons",at("CatCons",M,st(H,H)),Z._2._2._2)));g()})())};return tt(A._1,(()=>{if(A._2.tag==="CatNil")return at("CatCons",j,st(H,H));if(A._2.tag==="CatCons")return at("CatCons",A._2._1,st(A._2._2._1,kt("Cons",at("CatCons",j,st(H,H)),A._2._2._2)));g()})())};return tt(U._1,(()=>{if(U._2.tag==="CatNil")return at("CatCons",I,st(H,H));if(U._2.tag==="CatCons")return at("CatCons",U._2._1,st(U._2._2._1,kt("Cons",at("CatCons",I,st(H,H)),U._2._2._2)));g()})())})()),z=()=>Ke({path:i.segment.path,role:i.role,layer:w,effects:[Ce("GroupTransform",qT,a)]})(xl(iT)(u)(c)(s));return tt(B._1,(()=>{if(B._2.tag==="CatNil")return at("CatCons",z,st(H,H));if(B._2.tag==="CatCons")return at("CatCons",B._2._1,st(B._2._2._1,kt("Cons",at("CatCons",z,st(H,H)),B._2._2._2)));g()})())};return tt(L._1,(()=>{if(L._2.tag==="CatNil")return at("CatCons",E,st(H,H));if(L._2.tag==="CatCons")return at("CatCons",L._2._1,st(L._2._2._1,kt("Cons",at("CatCons",E,st(H,H)),L._2._2._2)));g()})())})()),T=()=>{const b=Ke({path:i.segment.path,role:i.role,layer:w,effects:[Ce("GroupTransform",li,a)]})(x);return tt(b._1,(()=>{if(b._2.tag==="CatNil")return at("CatCons",()=>Ng(t)(e)(n)(i),st(H,H));if(b._2.tag==="CatCons")return at("CatCons",b._2._1,st(b._2._2._1,kt("Cons",at("CatCons",()=>Ng(t)(e)(n)(i),st(H,H)),b._2._2._2)));g()})())};return tt(y._1,(()=>{if(y._2.tag==="CatNil")return at("CatCons",T,st(H,H));if(y._2.tag==="CatCons")return at("CatCons",y._2._1,st(y._2._2._1,kt("Cons",at("CatCons",T,st(H,H)),y._2._2._2)));g()})())})())},Db=t=>e=>n=>{if(t.theme==="Isometric")return Tb({...xb,transparentBg:t.transparentBg})(t.theme)(Hs(n).segment.layout)(Hs(n).state);const r=pi(t)(n),o=u=>n.hasDives?r.vw/Sa(1)(_e(n.rootLayout).w):1,i={tileScale:o(),viewport:r},s=u=>c=>{if(c.length===0)return tt(ut("Return",void 0),_t);const _=zt(d=>w,d=>l=>N("Just",{head:d,tail:l}),c);if(_.tag==="Nothing")return tt(ut("Return",void 0),_t);if(_.tag==="Just"){const d=Ql(t)(i)(n.camera.zoom)(_._1.head.role==="Active"?e:R)(u)(_._1.head);return n.diving||_._1.head.role==="Active"?tt(d._1,(()=>{if(d._2.tag==="CatNil")return at("CatCons",()=>s(_._1.head)(_._1.tail),st(H,H));if(d._2.tag==="CatCons")return at("CatCons",d._2._1,st(d._2._2._1,kt("Cons",at("CatCons",()=>s(_._1.head)(_._1.tail),st(H,H)),d._2._2._2)));g()})()):tt(ut("Return",void 0),at("CatCons",()=>s(_._1.head)(_._1.tail),st(H,H)))}g()},a=zt(u=>w,u=>c=>N("Just",{head:u,tail:c}),n.levels);if(a.tag==="Nothing")return tt(ut("Return",void 0),_t);if(a.tag==="Just"){const u=a._1.tail,c=a._1.head,_=u.length===0,d=Bb(t)(o())(c.role==="Active"||c.role==="FlyThrough"?c.bgAlpha:0)(c.blur)(r)(c.segment.layout)(Gb(n).state)(_&&e.tag!=="Leaf"?Il("SpringLabels",e):Eb),l=()=>{const f=Ng(t)(i)(n.camera.zoom)(c);return c.role==="Active"||c.role==="FlyThrough"?tt(f._1,(()=>{if(f._2.tag==="CatNil")return at("CatCons",()=>s(c)(u),st(H,H));if(f._2.tag==="CatCons")return at("CatCons",f._2._1,st(f._2._2._1,kt("Cons",at("CatCons",()=>s(c)(u),st(H,H)),f._2._2._2)));g()})()):tt(ut("Return",void 0),at("CatCons",()=>s(c)(u),st(H,H)))};return tt(d._1,(()=>{if(d._2.tag==="CatNil")return at("CatCons",l,st(H,H));if(d._2.tag==="CatCons")return at("CatCons",d._2._1,st(d._2._2._1,kt("Cons",at("CatCons",l,st(H,H)),d._2._2._2)));g()})())}g()},vg=t=>e=>n=>YT({viewport:pi(t)(n),camera:n.camera})(Db(t)(e)(n)),Tg=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()},Ib=t=>{const e=t.Monad0(),n=e.Bind1(),r=Ar(e.Applicative0())(f_),o=bl(t);return i=>{if(i.tag==="FrameTitleOverlay"){const s=i._1;return n.bind(r(Tg(t))(s.backing))(()=>o(s.text))}if(i.tag==="TitleCardOverlay"){const s=i._1;return n.bind(Tg(t)(s.backing))(()=>o(s.text))}if(i.tag==="FloorOverlay")return Tg(t)(i._1);g()}},Ab=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Ar(n)(Mt),o=t.popTransform,i=t.popBakedTransform,s=(()=>{const u=t.popClip,c=t.popAlpha,_=t.popBlend,d=t.popBlur;return l=>{if(l.tag==="GroupTransform"){if(l._1==="NormalTransform")return o;if(l._1==="BakedTransform")return i;g()}if(l.tag==="GroupClip")return u;if(l.tag==="GroupAlpha")return c;if(l.tag==="GroupBlend")return _;if(l.tag==="GroupBlur")return d;g()}})(),a=t.popLayer;return u=>e.Bind1().bind(r(s)(se(u.effects)))(()=>{if(u.layer.tag==="Just")return a;if(u.layer.tag==="Nothing")return n.pure();g()})},Rb=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Ar(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();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))},Ml=t=>{const e=t.Monad0(),n=$3(t),r=mb(t),o=nb(t),i=Cb(t),s=W3(t),a=yb(t);return VT(e)({beginFrame:u=>t.setViewport(u.viewport),endFrame:e.Applicative0().pure(),beginGroup:Rb(t),endGroup:Ab(t),background:Q3(t),overlay:Ib(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:bl(t),token:u=>{if(u.geometry.tag==="FlatToken")return s(u);if(u.geometry.tag==="IsoCube")return a(u);g()},insideTokenStyle:t.insideTokenStyle,measureText:t.measureText,measureInk:t.measureInk})},Fb=hg(Pd)(Xc.measureText),zl=Ml(Xc),Qb=t=>e=>n=>r=>o=>i=>s=>{const a={padding:24,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?w:N("Just",r.width/r.height)},u=Sd(n)(r);return()=>{const c=u(),_=o.levels.length-1|0;if(_>=0&&_<o.levels.length){const l=Fb(Jg(pi(a)(o))(o.levels[_]))(o.levels[_].segment.layout)(o.levels[_].state)(c)(),f=Ac(i)(l)(s);return zl(vg(a)(f.applied)(o))(c)(),f.springs}const d=Ac(i)(R)(s);return zl(vg(a)(d.applied)(o))(c)(),d.springs}},cs=t=>"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")",Co=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,ae=Oo(Wo("Fixed",qo(0)(20)(2))),bg=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",ae((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===2?["L",ae((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===3?["Q",ae((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+5|0)]:r._1===4?["C",ae((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+5|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{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 rr(" ")(e(0))},Mb=t=>ae(t.vx)+" "+ae(t.vy)+" "+ae(t.vw)+" "+ae(t.vh),Sn=t=>e=>de(Bn(e>=0&&e<t.length?t[e]:0)),Cg=t=>e=>{const n=Sn(t.ops)(e+1|0);return Dt(n,n+Sn(t.ops)(e+2|0)|0,t.paths)},Wl=(()=>{const t=Rn("&")("&"),e=Rn("<")("<"),n=(()=>{const r=Rn(">")(">"),o=(()=>{const i=Rn('"')(""");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),zb={vx:0,vy:0,vw:1,vh:1},Wb=t=>(e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i>=0&&i<t.length){if(t[i]===15){const s=i+1|0;r=!1,o={vx:s>=0&&s<t.length?t[s]:0,vy:(()=>{const a=s+1|0;return a>=0&&a<t.length?t[a]:0})(),vw:(()=>{const a=s+2|0;return a>=0&&a<t.length?t[a]:0})(),vh:(()=>{const a=s+3|0;return a>=0&&a<t.length?t[a]:0})()};continue}n=i+Co(t[i])|0;continue}r=!1,o=zb}return o})(0),gs=t=>e=>({r:Sn(t)(e),g:Sn(t)(e+1|0),b:Sn(t)(e+2|0),a:Sn(t)(e+3|0)}),ql=t=>e=>({color:gs(t)(e),width:(()=>{const n=e+4|0;return n>=0&&n<t.length?t[n]:0})(),join:Sn(t)(e+5|0),cap:Sn(t)(e+6|0)}),qb=t=>e=>'<rect x="'+ae(t.vx)+'" y="'+ae(t.vy)+'" width="'+ae(t.vw)+'" height="'+ae(t.vh)+'" fill="'+cs(e)+'" opacity="'+ae(nt(e.a)/255)+'"/>',Ob=t=>e=>'<path d="'+bg(t)+'" fill="'+cs(e)+'" fill-opacity="'+ae(nt(e.a)/255)+'"/>',Ol=t=>' stroke="'+cs(t.color)+'" stroke-opacity="'+ae(nt(t.color.a)/255)+'" stroke-width="'+ae(t.width)+'" stroke-linejoin="'+(t.join===0?"round":t.join===1?"bevel":"miter")+'" stroke-linecap="'+(t.cap===0?"butt":t.cap===1?"round":"square")+'"',Hb=t=>e=>n=>'<path d="'+bg(t)+'" fill="'+cs(e)+'" fill-opacity="'+ae(nt(e.a)/255)+'"'+Ol(n)+"/>",$b=t=>e=>'<path d="'+bg(t)+'" fill="none"'+Ol(e)+"/>",Vb=t=>e=>{const n=gs(t.ops)(e+7|0),r=Sn(t.ops)(e+12|0),o=Sn(t.ops)(e+11|0);return'<text x="'+ae((()=>{const i=e+1|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" y="'+ae((()=>{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="'+cs(n)+'" fill-opacity="'+ae(nt(n.a)/255)+'" font-size="'+ae((()=>{const i=e+5|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" font-family="'+Wl((()=>{const i=Sn(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="'+ie(Sn(t.ops)(e+6|0))+'" text-anchor="'+(o===0?"start":o===1?"middle":"end")+'">'+Wl((()=>{const i=Sn(t.ops)(e+3|0);return i>=0&&i<t.strs.length?t.strs[i]:""})())+"</text>"},ko=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?Ob(Cg(e)(n))(gs(e.ops)(n+3|0))+ko(t)(e)(n+Co(r._1)|0):r._1===2?$b(Cg(e)(n))(ql(e.ops)(n+3|0))+ko(t)(e)(n+Co(r._1)|0):r._1===3?Hb(Cg(e)(n))(gs(e.ops)(n+3|0))(ql(e.ops)(n+7|0))+ko(t)(e)(n+Co(r._1)|0):r._1===4?Vb(e)(n)+ko(t)(e)(n+Co(r._1)|0):r._1===16?qb(t)(gs(e.ops)(n+1|0))+ko(t)(e)(n+Co(r._1)|0):ko(t)(e)(n+Co(r._1)|0);if(r.tag==="Nothing")return"";g()},Xb=t=>{const e=Wb(t.ops);return{viewBox:Mb(e),body:ko(e)(t)(0),vx:e.vx,vy:e.vy,vw:e.vw,vh:e.vh}},Yb=Iv(Qv)(d0),Hl=t=>e=>{const n=t.strs;return()=>{const r=hu(n);return t.strs.push(e),r}},Ea=t=>e=>{const n=t.paths;return()=>{const r=hu(n);return t.paths.push(...e),{offset:r,len:e.length}}},Ub=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)}},$l=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)}},Dr=t=>e=>{const n=nt(e),r=t.ops;return()=>{r.push(n)}},Ga=t=>e=>{const n=e.len,r=Dr(t)(e.offset);return()=>(r(),Dr(t)(n)())},Kb=()=>{const t=[],e=[],n=[],r=[];return r.push(1),{ops:t,paths:e,strs:n,alphaStack:r}},jb=t=>{if(t.tag==="MeasureText"){const e=t._3(Qc(t._1)(t._2));return()=>e}if(t.tag==="MeasureInk"){const e=t._3(Mc(t._1)(t._2));return()=>e}g()},Vl=t=>{const e=t.alphaStack;return()=>{const n=hu(e);if(n===0)return 1;const r=h0(Yt,w,n-1|0,t.alphaStack);if(r.tag==="Nothing")return 1;if(r.tag==="Just")return r._1;g()}},Lo=t=>e=>{const n=Vl(t);return()=>{const r=n();return Dr(t)(e.r)(),Dr(t)(e.g)(),Dr(t)(e.b)(),Dr(t)(de(Bn(nt(e.a)*r+.5)))()}},Xl=t=>e=>{const n=Lo(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()})())}},Zb=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r;if(a.tag==="FillPath"){const u=a._3,c=a._2,_=Ea(s)(a._1);o=!1,i=()=>{const d=_();return s.ops.push(1),Ga(s)(d)(),Lo(s)(c.color)(),u};continue}if(a.tag==="StrokePath"){const u=a._3,c=a._2,_=Ea(s)(a._1);o=!1,i=()=>{const d=_();return s.ops.push(2),Ga(s)(d)(),Xl(s)(c)(),u};continue}if(a.tag==="FillStrokePath"){const u=a._2,c=a._4,_=a._3,d=Ea(s)(a._1);o=!1,i=()=>{const l=d();return s.ops.push(3),Ga(s)(l)(),Lo(s)(u.color)(),Xl(s)(_)(),c};continue}if(a.tag==="DrawText"){const u=a._2,c=a._1,_=Hl(s)(lo(c.content));o=!1,i=()=>{const d=_(),l=Hl(s)(c.font.family)();return s.ops.push(4),s.ops.push(c.x),s.ops.push(c.y),Dr(s)(d)(),Dr(s)(l)(),s.ops.push(c.font.size),Dr(s)(c.font.weight)(),Lo(s)(c.color)(),s.ops.push((()=>{if(c.align==="AlignLeft")return 0;if(c.align==="AlignCenter")return 1;if(c.align==="AlignRight")return 2;g()})()),s.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(a.tag==="DrawTextAffine"){n=s,r=$t("DrawText",{...a._2,x:a._1.a*a._2.x+a._1.c*a._2.y+a._1.e,y:a._1.b*a._2.x+a._1.d*a._2.y+a._1.f},a._3);continue}if(a.tag==="PushTransform"){const u=a._2,c=a._1,_=s.ops;o=!1,i=()=>(_.push(5),Ub(s)(c)(),u);continue}if(a.tag==="PopTransform"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(6),u);continue}if(a.tag==="PushClip"){const u=a._3,c=a._2,_=Ea(s)(a._1);o=!1,i=()=>{const d=_();return s.ops.push(7),Ga(s)(d)(),s.ops.push((()=>{if(c==="NonZero")return 0;if(c==="EvenOdd")return 1;g()})()),u};continue}if(a.tag==="PopClip"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(8),u);continue}if(a.tag==="PushBlend"){const u=a._1,c=a._2,_=s.ops;o=!1,i=()=>(_.push(9),s.ops.push((()=>{if(u==="Normal")return 0;if(u==="Difference")return 1;g()})()),c);continue}if(a.tag==="PopBlend"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(10),u);continue}if(a.tag==="PushAlpha"){const u=a._1,c=a._2,_=Vl(s);o=!1,i=()=>{const d=_();return s.alphaStack.push(d*u),s.ops.push(11),s.ops.push(u),c};continue}if(a.tag==="PopAlpha"){const u=a._1,c=s.alphaStack;o=!1,i=()=>(p0(Yt,w,c),s.ops.push(12),u);continue}if(a.tag==="PushBlur"){const u=a._2,c=a._1,_=s.ops;o=!1,i=()=>(_.push(18),s.ops.push(c),u);continue}if(a.tag==="PopBlur"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(19),u);continue}if(a.tag==="PushLayer"){const u=a._1,c=a._2,_=s.ops;o=!1,i=()=>(_.push(13),s.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(a.tag==="PopLayer"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(14),u);continue}if(a.tag==="SetViewport"){const u=a._2,c=a._1,_=s.ops;o=!1,i=()=>(_.push(15),$l(s)(c)(),u);continue}if(a.tag==="ClearBackground"){const u=a._1,c=a._2,_=s.ops;o=!1,i=()=>(_.push(16),Lo(s)(u)(),c);continue}if(a.tag==="BackgroundDots"){const u=a._2,c=a._1,_=s.ops;o=!1,i=()=>(_.push(17),$l(s)(c.viewport)(),Lo(s)(c.bgColor)(),Lo(s)(c.dotColor)(),s.ops.push(c.tile),s.ops.push(c.dotRadius),s.ops.push(c.origin.x),s.ops.push(c.origin.y),u);continue}g()}return i},tC=t=>e=>e.type==="metrics"?jb(e.value):e.type==="render"?Zb(t)(e.value):M_("Data.Functor.Variant: pattern match failure ["+e.type+"]"),eC=t=>{const e=Kb();return Yb(tC(e))(t)(),{ops:e.ops,paths:e.paths,strs:e.strs}},nC=t=>t,_s=t=>t,kg=_s("Light"),rC=_s("Dark"),oC=_s("Blueprint"),iC=_s("Whiteboard"),sC=_s("Isometric"),aC=nC("TransparentBackground"),Kr=t=>"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")",_r=Oo(Wo("Fixed",qo(0)(20)(4))),uC=t=>"translate("+_r(t.tx)+","+_r(t.ty)+") scale("+_r(t.sx)+","+_r(t.sy)+")",Rt=Oo(Wo("Fixed",qo(0)(20)(2))),Lg=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(Rt((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Rt((()=>{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(Rt((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Rt((()=>{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(Rt((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Rt((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Rt((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Rt((()=>{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(Rt((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Rt((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Rt((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Rt((()=>{const i=r+4|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Rt((()=>{const i=r+5|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Rt((()=>{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 rr(" ")(e)},cC={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},Sg=(()=>{const t=Rn("&")("&"),e=Rn("<")("<"),n=(()=>{const r=Rn(">")(">"),o=(()=>{const i=Rn('"')(""");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),gC=t=>{if(t.style==="RunText")return"<tspan>"+Sg(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+Sg(t.text)+"</tspan>";g()},qe=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},_C=t=>e=>{const n=[];let r=0;const o=i=>{const s=i>=0&&i<e.length?t.sx*e[i]+t.tx:t.sx*0+t.tx;return()=>{n.push(s),n.push((()=>{const a=i+1|0;return a>=0&&a<e.length?t.sy*e[a]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const i=r,s=i>=0&&i<e.length?N("Just",e[i]):w;if(s.tag==="Nothing"){r=e.length;continue}if(s.tag==="Just"){if(s._1===1){n.push(s._1),o(i+1|0)(),r=i+3|0;continue}if(s._1===2){n.push(s._1),o(i+1|0)(),r=i+3|0;continue}if(s._1===3){n.push(s._1),o(i+1|0)(),o(i+3|0)(),r=i+5|0;continue}if(s._1===4){n.push(s._1),o(i+1|0)(),o(i+3|0)(),o(i+5|0)(),r=i+7|0;continue}if(s._1===5){n.push(s._1),r=i+1|0;continue}r=e.length;continue}g()}return n},Pa=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return _C(r._1)(e);g()}},Yl={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),s=o();return i(s)}},Functor0:()=>cC},fC={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>Yl},dC={pure:t=>e=>()=>t,Apply0:()=>Yl},Ul={Applicative0:()=>dC,Bind1:()=>fC},lC=t=>e=>'<defs><pattern id="'+t+'" x="'+Rt(e.origin.x)+'" y="'+Rt(e.origin.y)+'" width="'+Rt(e.tile)+'" height="'+Rt(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+Rt(e.tile)+'" height="'+Rt(e.tile)+'" fill="'+Kr(e.bgColor)+'" fill-opacity="'+Rt(nt(e.bgColor.a)/255)+'"/>')+'<circle cx="'+Rt(e.tile/2)+'" cy="'+Rt(e.tile/2)+'" r="'+Rt(e.dotRadius)+'" fill="'+Kr(e.dotColor)+'"/></pattern></defs><rect x="'+Rt(e.viewport.vx)+'" y="'+Rt(e.viewport.vy)+'" width="'+Rt(e.viewport.vw)+'" height="'+Rt(e.viewport.vh)+'" fill="url(#'+t+')"/>',Kl=t=>e=>'<path d="'+Lg(t)+'" fill="'+Kr(e)+'" fill-opacity="'+Rt(nt(e.a)/255)+'"/>',hC=t=>e=>n=>r=>'<rect x="'+Rt(t.x)+'" y="'+Rt(t.y)+'" width="'+Rt(t.w)+'" height="'+Rt(t.h)+'" rx="'+Rt(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+Kr(n._1.color)+'" fill-opacity="'+Rt(nt(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';g()})()+(()=>{if(r.tag==="Just")return' stroke="'+Kr(r._1.color)+'" stroke-opacity="'+Rt(nt(r._1.color.a)/255)+'" stroke-width="'+Rt(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()})()+"/>",jl=t=>e=>'<path d="'+Lg(t)+'" fill="none" stroke="'+Kr(e.color)+'" stroke-opacity="'+Rt(nt(e.color.a)/255)+'" stroke-width="'+Rt(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()})()+'"/>',Zl=t=>{const e=q1(lo(t.content));return'<text x="'+Rt(t.x)+'" y="'+Rt(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="'+Kr(t.color)+'" fill-opacity="'+Rt(nt(t.color.a)/255)+'" font-size="'+Rt(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+ie(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";g()})()+'">'+(e.length===1&&e[0].style==="RunText"?Sg(e[0].text):rr("")($(gC)(e)))+"</text>"},pC=t=>"matrix("+_r(t.a)+" "+_r(t.b)+" "+_r(t.c)+" "+_r(t.d)+" "+_r(t.e)+" "+_r(t.f)+")",th={fillPath:t=>e=>n=>{const r=Pa(n)(t);return()=>{const o=r();return qe(Kl(o)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=Pa(n)(t);return()=>{const o=r(),i=n.bake.value;return qe(jl(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=Pa(r)(t);return()=>{const i=o(),s=r.bake.value;return qe(Kl(i)(e.color)+jl(i)((()=>{if(s.tag==="Nothing")return n;if(s.tag==="Just")return{...n,width:s._1.sx*n.width};g()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>o=>{const i=o.bake;return()=>{const s=i.value;return qe(hC((()=>{if(s.tag==="Nothing")return t;if(s.tag==="Just")return{x:s._1.sx*t.x+s._1.tx,y:s._1.sy*t.y+s._1.ty,w:s._1.sx*t.w,h:s._1.sy*t.h};g()})())((()=>{if(s.tag==="Nothing")return e;if(s.tag==="Just")return s._1.sx*e;g()})())(n)(r.tag==="Just"?N("Just",(()=>{if(s.tag==="Nothing")return r._1;if(s.tag==="Just")return{...r._1,width:s._1.sx*r._1.width};g()})()):w))(o)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return qe(Zl((()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return{...t,x:r._1.sx*t.x+r._1.tx,y:r._1.sy*t.y+r._1.ty,font:{...t.font,size:r._1.sx*t.font.size}};g()})()))(e)()}},drawTextAffine:t=>e=>qe((()=>{const n='transform="'+pC(t)+'"';return(n===""?"<g>":"<g "+n+">")+Zl(e)+"</g>"})()),pushTransform:t=>qe((()=>{const e='transform="'+uC(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:qe("</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=Pa(n)(t)(),s="clip"+ie(o);return qe((()=>{const a='clip-path="url(#'+s+')"';return'<defs><clipPath id="'+s+'"><path d="'+Lg(i)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";g()})()+"/></clipPath></defs>"+(a===""?"<g>":"<g "+a+">")})())(n)()}},popClip:qe("</g>"),pushBlend:t=>qe((()=>{const e=(()=>{if(t==="Normal")return'style="mix-blend-mode: normal"';if(t==="Difference")return'style="mix-blend-mode: difference"';g()})();return e===""?"<g>":"<g "+e+">"})()),popBlend:qe("</g>"),pushAlpha:t=>qe((()=>{const e='opacity="'+Rt(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:qe("</g>"),pushBlur:t=>e=>{if(t<.01)return qe("<g>")(e);const n=e.patternCounter;return()=>{const r=n.value;e.patternCounter.value=r+1|0;const o="lvl-blur-"+ie(r);return qe((()=>{const i='filter="url(#'+o+')"';return'<defs><filter id="'+o+'" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="'+Rt(t)+'"/></filter></defs>'+(i===""?"<g>":"<g "+i+">")})())(e)()}},popBlur:qe("</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=>qe('<rect x="'+Rt(e.viewport.vx)+'" y="'+Rt(e.viewport.vy)+'" width="'+Rt(e.viewport.vw)+'" height="'+Rt(e.viewport.vh)+'" fill="'+Kr(t)+'" opacity="'+Rt(nt(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,qe(lC("bg-dots-"+ie(r))(t))(e)()}},measureText:t=>e=>n=>{const r=Qc(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Mc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Hc,Monad0:()=>Ul},mC=Ml(th),yC=hg(Ul)(th.measureText),xC=t=>e=>n=>r=>o=>{const i={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:n,outputAspect:t},s=pi(i)(o);return{viewBox:Rt(s.vx)+" "+Rt(s.vy)+" "+Rt(s.vw)+" "+Rt(s.vh),body:(()=>{const a=[],u={value:0},c={value:0},_={value:0},d={value:w};return mC(vg(i)(e)(o))({out:a,maskDepth:u,clipCounter:c,patternCounter:_,viewport:s,bake:d})(),rr("")(a)})(),vx:s.vx,vy:s.vy,vw:s.vw,vh:s.vh}},wC=t=>e=>n=>r=>o=>i=>{const s={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;g()})(),outputAspect:t},a=Ac(o)((()=>{const u=[],c={value:0},_={value:0},d={value:0},l={value:w},f=r.levels.length-1|0;if(f>=0&&f<r.levels.length){const h=Jg(pi(s)(r))(r.levels[f]);return yC(h)(r.levels[f].segment.layout)(r.levels[f].state)({out:u,maskDepth:c,clipCounter:_,patternCounter:d,viewport:h,bake:l})()}return R})())(i);return{parts:xC(t)(a.applied)(e)(n)(r),springs:a.springs}},JC=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()},Xe=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Wn=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},NC=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Ba=mu(Ti),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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},eh=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},TC=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},bC=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},nh=(()=>{const t=en.unfoldr(In);return e=>t(nn("IterNode",e,Dn))})(),yi=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},CC=t=>t,rh=t=>e=>n=>n<t?0:n>1-e?1:(n-t)/Xe(.05)(1-t-e),kC=t=>e=>t.labelBasePx*.62*nt(v(NC)(0)($(ey)(St(e)(n=>Vr(`
|
|
10
|
-
`)(n))))),oh=(()=>{const t=v(e=>n=>{const r=e.previous.tag==="Just"&&Pn(e.previous._1.endT-n.startT)<1e-4?{...n,fromCam:e.previous._1.toCam}:n;return{previous:N("Just",r),spans:Pt(e.spans)(r)}})({previous:w,spans:[]});return e=>t(e).spans})(),Eg=t=>e=>{const n=mi(e)(t.keyframes);if(n.tag==="Nothing")return R;if(n.tag==="Just")return n._1.nodes;g()},ih=t=>e=>{if(e<t.startT)return Fn("AtKeyframe",t.initialKeyframe);const n=re(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Fn("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Fn("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return Fn("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode"||n._1.scene.tag==="StepScene")return Fn("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing")return Fn("AtKeyframe",v(JC)(t.initialKeyframe)(t.spans));g()},LC=t=>e=>n=>r=>{const o=re(i=>Ba(i.path)(e)&&(Pn(i.endT-n)<1e-4||Pn(i.startT-r)<1e-4))(t.segments);if(o.tag==="Just")return N("Just",o._1);if(o.tag==="Nothing")return re(i=>Ba(i.path)(e))(t.segments);g()},Gg=t=>e=>{const n=mi(e)(t.keyframes);if(n.tag==="Nothing")return R;if(n.tag==="Just")return n._1.edges;g()},SC=t=>e=>n=>vt(r=>{const o=vt(i=>vC(i)(t.nodes))(jt(rn.foldr,(()=>{if(r.scene.tag==="Structural")return Ae(P.compare,Be,(()=>{const i=mi(r.scene._1.from)(n);if(i.tag==="Nothing")return R;if(i.tag==="Just")return i._1.nodes;g()})(),(()=>{const i=mi(r.scene._1.to)(n);if(i.tag==="Nothing")return R;if(i.tag==="Just")return i._1.nodes;g()})());if(r.scene.tag==="DataFlow"){const i=mi(r.scene._1.keyframe)(n);if(i.tag==="Nothing")return R;if(i.tag==="Just")return i._1.nodes;g()}if(r.scene.tag==="Hold"){const i=mi(r.scene._1)(n);if(i.tag==="Nothing")return R;if(i.tag==="Just")return i._1.nodes;g()}if(r.scene.tag==="EnterNode"||r.scene.tag==="ExitNode"||r.scene.tag==="StepScene")return R;g()})()));return o.length===0?w:N("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const i=v(s=>a=>({minX:Wn(s.minX)(a.x),minY:Wn(s.minY)(a.y),maxX:Xe(s.maxX)(a.x+a.w),maxY:Xe(s.maxY)(a.y+a.h)}))(0<o.length?{minX:o[0].x,minY:o[0].y,maxX:o[0].x+o[0].w,maxY:o[0].y+o[0].h}:{minX:0,minY:0,maxX:0,maxY:0})(Dt(1,o.length,o));return{x:i.minX,y:i.minY,w:i.maxX-i.minX,h:i.maxY-i.minY}})(),priority:0})}),EC=t=>e=>{const n=_e(e),r=Gl({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}},GC=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),s=EC(t)(e);return Wn(o<=0?n.zoom:s.w/(o*2))(i<=0?n.zoom:s.h/(i*2))},sh=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r,u=Qr(a);if(u.tag==="Just"&&u._1.last.intent==="Overview"){n=[u._1.last,...s],r=u._1.init;continue}o=!1,i={prefix:a,overview:s}}return i},PC=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r,u=zt(c=>w,c=>_=>N("Just",{head:c,tail:_}),a);if(u.tag==="Just"&&u._1.head.intent==="Overview"){n=Pt(s)(u._1.head),r=u._1.tail;continue}o=!1,i={overview:s,rest:a}}return i},xi=t=>e=>n=>r=>o=>{const i={width:e.widthPx,height:e.heightPx},s=Gl(i)((()=>{const a=co(n)(o);return{vx:a.x,vy:a.y,vw:a.w,vh:a.h}})());return t.labelBasePx*r.placement.scale*(i.width<=0||s.vw<=0?0:i.width/s.vw)},BC=t=>e=>n=>r=>o=>{const i=xi(t)(e)(n)(r)(o);return i<=t.minimumReadableLabelPx?o:{...o,zoom:o.zoom*t.minimumReadableLabelPx/i}},DC=t=>e=>n=>r=>({...r,fromCam:cf(t)(e)(n)(r.fromCam),toCam:cf(t)(e)(n)(r.toCam)}),IC=t=>e=>t.widthPx<=0?0:Wn(e/4)(6*e/t.widthPx),AC=t=>e=>n=>r=>o=>{const i=IC(e)(n),s=r+n/2-i;return o<r-n/2+i?o-i+n/2:o>s?o+i-n/2:r},RC=t=>e=>n=>Ne(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),FC=t=>e=>n=>Ne(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),QC=t=>e=>n=>Ne(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),MC=t=>e=>n=>Ne(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),Da=t=>e=>n=>Ne(r=>n(r)&&e>=r.startT&&e<r.endT,t),Pg=t=>e=>n=>{if(e.length===0)return n;const r=Wn(160)(kC(t)(e)+31),o=Wn(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}},zC=t=>e=>n=>{const r=t.padding*.75,o=nt(8);return ys(i=>{if(i.target.tag==="NodeWindow")return[];if(i.target.tag==="EdgeWindow")return[];if(i.target.tag==="TokenWindow"){const s=eh(i.target._2)(e.edges);if(s.tag==="Just"){const a=(()=>{if(i.target._3==="Forward")return s._1;if(i.target._3==="Backward")return se(s._1);g()})();return St(Kt(0,7))(u=>{const c=i.startT+(i.endT-i.startT)*(nt(u)/o),_=(()=>{const d=i.startT+(i.endT-i.startT)*(nt(u+1|0)/o);return{startT:c,endT:d,box:(()=>{const l=uo(a)(rh(i.target._7)(i.target._8)(((c+d)/2-i.startT)/Xe(1e-4)(i.endT-i.startT)));if(l.tag==="Just")return{x:l._1.x-r,y:l._1.y-r,w:0+r*2,h:0+r*2};if(l.tag==="Nothing")return{x:0,y:0,w:0,h:0};g()})()}})();return[{startT:_.startT,endT:_.endT,bbox:Pg(t)(i.target._6)(_.box),priority:1}]})}if(s.tag==="Nothing")return[{startT:i.startT,endT:i.endT,bbox:Pg(t)(i.target._6)(tf(e)(n)(i.target._2)),priority:1}];g()}if(i.target.tag==="FillWindow")return[{startT:i.startT,endT:i.endT,bbox:Pg(t)(i.target._3)(qu(e)(n)(te("Node",1,1,i.target._2,void 0,R,R))),priority:1}];g()})},WC=t=>e=>n=>r=>o=>[...SC(o.layout)(n)(e)(ft(i=>i.startT>=o.startT&&i.endT<=o.endT,r.spans)),...zC(t)(o.layout)(n)(o.windows)],qC=t=>e=>n=>r=>o=>i=>O2(t)(e)(i.layout)(o.endT)(WC(t)(n)(r)(o)(i)),OC=t=>e=>n=>r=>o=>i=>{if(o.tag==="Nothing")return i.zoom;if(o.tag==="Just")return Xe(0)(GC(e)(n)(i)((()=>{const s=t.padding*r.placement.scale;return{x:o._1.x-s,y:o._1.y-s,w:o._1.w+s*2,h:o._1.h+s*2}})()));g()},HC=t=>e=>{const n=ih(t)(e);if(n.tag==="AtKeyframe")return Eg(t)(n._1);if(n.tag==="InTransition")return Ae(P.compare,Be,Eg(t)(n._1),Eg(t)(n._2));g()},$C=t=>e=>n=>Da(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n&&r.target._2==="PlopOut")?!0:FC(t.windows)(e)(n)?!1:Da(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n)?!0:QC(t.windows)(e)(n)?!1:TC(n)(HC(t)(e)),VC=t=>e=>{const n=ih(t)(e);if(n.tag==="AtKeyframe")return Gg(t)(n._1);if(n.tag==="InTransition")return Ae(P.compare,Be,Gg(t)(n._1),Gg(t)(n._2));g()},XC=t=>e=>n=>Da(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n)?!0:RC(t.windows)(e)(n)?!1:Da(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._1===n)?!0:MC(t.windows)(e)(n)?!1:bC(n)(VC(t)(e)),YC=t=>e=>{const n=[...vt(r=>$C(t)(e)(r._1)?N("Just",{x:r._2.x,y:r._2.y,w:r._2.w,h:r._2.h}):w)(nh(t.layout.nodes)),...vt(r=>XC(t)(e)(r._1)?N("Just",Is(r._2)):w)(nh(t.layout.edges))];return n.length===0?w:N("Just",Tr(n))},UC=t=>e=>n=>{const r=co(t)(n);return e.x>=r.x&&e.x+e.w<=r.x+r.w},ah=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=Wn(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=Wn(o.hi)(i);return u<=c?{lo:u,hi:c}:o}const s=Xe(o.lo)(e.x+n/2),a=Wn(o.hi)(e.x+e.w-n/2);return s<=a?{lo:s,hi:a}:o},KC=t=>e=>n=>n.endT<=t||n.startT>=e?w:N("Just",{...n,startT:Xe(t)(n.startT),endT:Wn(e)(n.endT)}),uh=t=>e=>n=>r=>o=>i=>vt(KC(i.startT)(i.endT))($(DC(n)(i.layout)(i.placement))(qC(t)(e)(r)(i.edgeEndpoints)(o)(i))),ch=t=>e=>n=>r=>{const o=_e(t),i=Wn(r.zoom)(o.w/Xe(1e-4)(e.w));return{...r,center:{...r.center,x:(()=>{const s=ah(o)(e)(o.w/Xe(1e-4)(i));return yi(s.lo)(s.hi)(n.center.x)})()},zoom:i}},jC=t=>e=>n=>r=>o=>i=>s=>a=>{const u=_e(n),c=(()=>{if(o.tag==="Nothing")return s.center.x;if(o.tag==="Just")return AC()(e)(a)(i.center.x)(o._1.x+o._1.w/2);g()})();if(r.tag==="Nothing"){const _=u.x+u.w/2;return a>=u.w?yi(_)(_)(c):yi(u.x+a/2)(u.x+u.w-a/2)(c)}if(r.tag==="Just"){if(a<r._1.w){const d=u.x+u.w/2;return a>=u.w?yi(d)(d)(c):yi(u.x+a/2)(u.x+u.w-a/2)(c)}const _=ah(u)(r._1)(a);return yi(_.lo)(_.hi)(c)}g()},ZC=t=>e=>n=>r=>o=>i=>s=>{const a=co(n)(s);return a.w<=0?s:{...s,center:{...s.center,x:jC()(e)(n)(r)(o)(i)(s)(a.w)}}},gh=t=>e=>n=>r=>e2(t)(e)(n)(r.layout)(r.placement)((()=>{if(r.layout.nodes.tag==="Leaf")return 0;if(r.layout.nodes.tag==="Node")return r.layout.nodes._2;g()})()).camera,_h=t=>e=>n=>r=>o=>{const i=co(n)(o);return(()=>{const s=_e(r.layout),a=s.x*r.placement.scale+r.placement.tx,u=s.y*r.placement.scale+r.placement.ty;return a>=i.x&&u>=i.y&&a+s.w*r.placement.scale<=i.x+i.w&&u+s.h*r.placement.scale<=i.y+i.h})()&&xi(t)(e)(n)(r)(o)>=t.minimumReadableLabelPx},Bg=t=>e=>n=>r=>o=>i=>_h(t)(e)(n)(r)(o)?o:BC(t)(e)(n)(r)(i),tk=t=>e=>n=>{const r=PC([])(n),o=zt(s=>w,s=>a=>N("Just",{head:s,tail:a}),r.rest),i=r.overview.length-1|0;return i>=0&&i<r.overview.length&&0<r.overview.length&&o.tag==="Just"&&Pn(r.overview[0].startT-e.startT)<1e-4&&o._1.head.intent==="ActionFocus"?[{startT:r.overview[0].startT,endT:r.overview[i].endT,fromCam:t,toCam:t,easing:r.overview[0].easing,interp:Hr,intent:of},{...o._1.head,fromCam:t},...o._1.tail]:n},ek=t=>e=>{const n=zt(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()},nk=t=>e=>n=>r=>o=>i=>{const s=_e(r.layout),a={x:s.x*r.placement.scale+r.placement.tx,y:s.y*r.placement.scale+r.placement.ty,w:s.w*r.placement.scale,h:s.h*r.placement.scale},u=ch(n)(a)(o)(i);return a.w/Xe(1e-4)(a.h)>=.33&&i.zoom/Xe(1e-4)(u.zoom)<=1.25&&co(n)(u).w>=a.w-.001&&xi(t)(e)(n)(r)(u)>=t.minimumReadableLabelPx*.85?u:i},rk=t=>e=>n=>r=>o=>i=>s=>{const a=_e(r.layout),u=a.w*r.placement.scale,c=u/Xe(1e-4)(a.h*r.placement.scale);if(o.tag==="Nothing")return s;if(o.tag==="Just"){if(UC(n)(o._1)(s))return s;const _=ch(n)(o._1)(i)(s);return s.zoom/Xe(1e-4)(_.zoom)<=1.25&&(xi(t)(e)(n)(r)(_)>=t.minimumReadableLabelPx-.001||o._1.w>=u-.001&&c>=.33&&xi(t)(e)(n)(r)(_)>=t.minimumReadableLabelPx*.85)?_:s}g()},ok=t=>e=>n=>r=>o=>i=>s=>{const a={...s,center:(()=>{if(i.tag==="Nothing")return s.center;if(i.tag==="Just")return{x:i._1.x+i._1.w/2,y:i._1.y+i._1.h/2};g()})()},u=xi(t)(e)(n)(r)(a);return ZC()(e)(n)(o)(i)(s)(rk(t)(e)(n)(r)(o)(s)(nk(t)(e)(n)(r)(s)(u<=0?a:{...a,zoom:Wn(a.zoom*t.minimumReadableLabelPx/u)(OC(t)(e)(n)(r)(i)(a))})))},Dg=t=>e=>n=>r=>o=>i=>s=>_h(t)(e)(n)(r)(s)?s:ok(t)(e)(n)(r)(o)(i)(s),fh=t=>{const e=n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=i,_=zt(d=>w,d=>l=>N("Just",{head:d,tail:l}),c);if(_.tag==="Just"&&_._1.head.intent==="Overview"){o=Pt(u)(_._1.head),i=_._1.tail;continue}s=!1,a={overview:u,rest:c}}return a};return(n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=zt(_=>w,_=>d=>N("Just",{head:_,tail:d}),i);if(c.tag==="Nothing"){s=!1,a=u;continue}if(c.tag==="Just"){if(c._1.head.intent==="Overview"){const _=e([c._1.head])(c._1.tail),d=zt(h=>w,h=>p=>N("Just",{head:h,tail:p}),_.rest),l=u.length-1|0,f=l>=0&&l<u.length?N("Just",u[l]):w;if(f.tag==="Just"&&d.tag==="Just"&&f._1.intent==="ActionFocus"&&(()=>{const h=_.overview.length-1|0;return d._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=Pt(u)({startT:_.overview[0].startT,endT:_.overview[h].endT,fromCam:f._1.toCam,toCam:f._1.toCam,easing:_.overview[0].easing,interp:Hr,intent:Rs}),i=[{...d._1.head,fromCam:f._1.toCam},...d._1.tail];continue}}o=[...u,..._.overview],i=_.rest;continue}o=Pt(u)(c._1.head),i=c._1.tail;continue}g()}return a})([])(t)},ik=t=>e=>n=>{const r=sh([])(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"&&Pn(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:Hr,intent:Rs}]}return n}return 0<r.overview.length&&r.prefix.length-1|0,n},dh=t=>e=>n=>{const r=sh([])(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 s=r.overview[o].endT;return r.prefix[i].intent==="ActionFocus"&&(()=>{const a=r.overview.length-1|0;return Ne(u=>u.direction==="DiveIn"&&Ba(u.parentPath)(t.path)&&Pn(u.startT-s)<1e-4,e)&&(a>=0&&a<r.overview.length&&0<r.overview.length?r.overview[a].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:Hr,intent:Rs}]}return n}return n},sk=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=vt(o=>o.target.tag==="TokenWindow"?N("Just",(()=>{const i=eh(o.target._2)(t.layout.edges),s=rh(o.target._7)(o.target._8)((n-o.startT)/Xe(1e-4)(o.endT-o.startT)),a=(()=>{if(i.tag==="Just")return uo((()=>{if(o.target._3==="Forward")return i._1;if(o.target._3==="Backward")return se(i._1);g()})())(s);if(i.tag==="Nothing")return w;g()})();if(a.tag==="Just")return{x:a._1.x,y:a._1.y,w:0,h:0};if(a.tag==="Nothing")return tf(t.layout)(t.edgeEndpoints)(o.target._2);g()})()):o.target.tag==="FillWindow"?N("Just",qu(t.layout)(t.edgeEndpoints)(te("Node",1,1,o.target._2,void 0,R,R))):w)(ft(o=>o.startT<=n&&n<o.endT,t.windows));return r.length===0?w:N("Just",(()=>{const o=Tr(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}})())},ak=t=>e=>{const n=YC(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},lh=t=>e=>n=>r=>o=>i=>{const s=o(i.fromCam),a=o(i.toCam),u=sk(r)(i),c=ak(r)(i);return s.zoom===a.zoom&&s.center.x===a.center.x&&s.center.y===a.center.y?{...i,fromCam:Dg(t)(e)(n)(r)(c)(u)(s),toCam:Dg(t)(e)(n)(r)(c)(u)(a)}:{...i,fromCam:s,toCam:Dg(t)(e)(n)(r)(c)(u)(a)}},hh=t=>e=>n=>r=>o=>i=>i.intent==="ActionFocus"?lh(t)(e)(n)(r)(Bg(t)(e)(n)(r)(o))(i):{...i,fromCam:Bg(t)(e)(n)(r)(o)(i.fromCam),toCam:Bg(t)(e)(n)(r)(o)(i.toCam)},ph=t=>e=>n=>r=>o=>i=>{const s=re(a=>a.intent==="ActionFocus"&&a.startT>=r.startT-1e-4)(i);if(s.tag==="Just"){const a=hh(t)(e)(n)(r)(o)(s._1).toCam;return{...o,center:a.center,zoom:a.zoom<o.zoom?a.zoom:o.zoom}}if(s.tag==="Nothing")return o;g()},uk=t=>e=>n=>r=>o=>ph(t)(e)(n)(r)(gh(t)(e)(n)(r))(o),ck=t=>e=>n=>r=>o=>o.intent==="ActionFocus"?lh(t)(e)(n)(r)(CC)(o):o,Ia=t=>e=>n=>r=>o=>i=>{const s=uh(t)(e)(n)(r)(o)(i);if(i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0)return dh(i)(o.dives)(fh(oh($(ck(t)(e)(n)(i))(s))));const a=gh(t)(e)(n)(i),u=ph(t)(e)(n)(i)(a)(s);return s.length===0?[{startT:i.startT,endT:i.endT,fromCam:u,toCam:u,easing:Hu,interp:Hr,intent:of}]:ik()(i)(tk(u)(i)(dh(i)(o.dives)(fh(oh(ek(u)($(hh(t)(e)(n)(i)(a))(s)))))))},gk=t=>e=>n=>r=>o=>It(i=>s=>it.compare(i.startT)(s.startT))(St(o.segments)(Ia(t)(e)(n)(r)(o))),_k=t=>e=>n=>r=>o=>i=>s=>{if(i.direction==="DiveIn")return Ri(t)(n)(Ia(t)(e)(n)(r)(o)(s))(i.startT-1e-4).camera;if(i.direction==="DiveOut")return Ri(t)(n)(Ia(t)(e)(n)(r)(o)(s))(i.endT+1e-4).camera;g()},fk=t=>e=>n=>r=>o=>vt(i=>{const s=LC(o)(i.parentPath)(i.startT)(i.endT);if(s.tag==="Just"){const a=i.childPath,u=re(c=>Ba(c.path)(a))(o.segments);if(u.tag==="Just"){const c=Ia(t)(e)(n)(r)(o)(u._1),_=uk(t)(e)(n)(u._1)(uh(t)(e)(n)(r)(o)(u._1)),d=_k(t)(e)(n)(r)(o)(i)(s._1),l=(()=>{if(i.direction==="DiveIn")return _;if(i.direction==="DiveOut")return Ri(t)(n)(c)(i.startT-1e-4).camera;g()})();if(i.direction==="DiveIn")return N("Just",{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:go,interp:rf,intent:sf});if(i.direction==="DiveOut")return N("Just",{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:go,interp:rf,intent:sf});g()}if(u.tag==="Nothing")return w;g()}if(s.tag==="Nothing")return w;g()})(o.dives),mh=t=>e=>n=>r=>o=>[...fk(t)(e)(n)(r)(o),...gk(t)(e)(n)(r)(o)],jr=(t,e)=>({tag:t,_1:e}),Aa=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},fr=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},yh=ce(P)(Mt),xh=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Nh=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},wi=(()=>{const t=en.unfoldr(e=>{if(e.tag==="Nil")return w;if(e.tag==="Cons")return N("Just",C(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,kt("Cons",r._3,n(r._6,o)));g()};return n(e,H)})())})(),dk=v(t=>e=>rt(P)(e)()(t))(R),Ig=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},lk=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ra=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},hk=jr("NoKeyframes"),pk=t=>jr("DuplicateEventId",t),mk=t=>jr("UnknownEvent",t),yk=t=>e=>({...e,cameraSpans:mh(e.cameraConfig)(t)(e.layout)(e.keyframes)({endT:e.totalDuration,spans:e.spans,windows:e.windows,segments:e.segments,dives:e.dives})}),xk=t=>e=>n=>r=>{const o=Aa(r.edge)(e.edges),i=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return Gs(o._1);g()})(),s=fr(t.minTokenDuration)(fr(nt(v(a=>u=>a+Yo(u).length|0)(0)(r.labels))*t.tokenReadSecPerChar)(t.tokenSpeed<=0?0:i/t.tokenSpeed))+n.pre+n.post;return{duration:s,holdPre:s<=0?0:n.pre/s,holdPost:s<=0?0:n.post/s}},wk=ys(t=>{const e=Vr(`
|
|
11
|
-
`)(t);return e.length===0?[""]:e}),Jk=t=>e=>yh(vt(n=>{if(n.kind.tag==="SendToken")return N("Just",C(n.id,{pre:(()=>{const r=n.when;return(()=>{const o=n.kind._1.from;return Ne(i=>{if(i.kind.tag==="SendToken")return(r.tag==="First"?!1:r.tag==="After"&&r._1===i.id)&&i.kind._1.to===o;if(i.kind.tag==="FillNodeWithoutTransition")return!1;g()},e)})()?0:t.tokenHold})(),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)),Nk=t=>{if(t.event.kind.tag==="SendToken")return N("Just",{startT:t.startT,endT:t.endT,target:Uo("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:Uo("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},vk=t=>vt((()=>{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),Tk=t=>e=>n=>{const r=Aa(n)(t);if(r.tag==="Nothing")return mf;if(r.tag==="Just"){const o=xh(r._1.target)(e);return xh(r._1.source)(e)?o?cy:uy:mf}g()},vh=$(bi),bk={pre:0,post:0},Ck=t=>e=>n=>r=>o=>{const i=wh(o.event.id)(n),s=(()=>{if(i.tag==="Nothing")return bk;if(i.tag==="Just")return i._1;g()})(),a=(()=>{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,_=re(d=>d.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,_=re(d=>d.event.id===c)(r);if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1.startT}g()})(),u=(()=>{if(o.event.kind.tag==="SendToken")return xk(t)(e)(s)(o.event.kind._1);if(o.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return Pt(r)({startT:a,endT:a+u.duration,event:o.event,holdPre:u.holdPre,holdPost:u.holdPost})},Th=t=>e=>n=>v(Ck(t)(e)(Jk(t)(n)))([])(Ht(r=>o=>({event:o}))(n)),kk=t=>e=>{const n=Jh(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},bh=t=>e=>n=>{if(e.tag==="Just"&&e._1>n.endT+1e-4){const r=fr(0)(n.endT-n.startT),o=fr(t.startT)(e._1-r);return{...n,startT:o,endT:o+r}}return n},Lk=t=>e=>{const n=It(it.compare)(vt(r=>r.target.tag==="TokenWindow"?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},Sk=t=>e=>{const n=It(it.compare)(vt(r=>r.target.tag==="TokenWindow"&&r.target._2===e?N("Just",r.startT):w)(t));return 0<n.length?N("Just",n[0]):w},Ek=t=>e=>e.target.tag==="NodeWindow"?e.target._2==="PlopIn"?bh(t)(Lk(t.windows)(e.target._1))(e):e:e.target.tag==="EdgeWindow"&&e.target._2.tag==="Extend"?bh(t)(Sk(t.windows)(e.target._1))(e):e,Gk=t=>({...t,windows:It(e=>n=>it.compare(e.startT)(n.startT))($(Ek(t))(t.windows))}),Pk=t=>{const e=$(Gk)(t.segments);return{...t,segments:e,windows:It(n=>r=>it.compare(n.startT)(r.startT))(St(e)(n=>n.windows))}},Bk=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()},Ch={id:"",nodes:R,edges:R,kind:Di},Dk=t=>e=>u2((()=>{const n=Nh(e.from)(t);if(n.tag==="Nothing")return Ch;if(n.tag==="Just")return n._1;g()})())((()=>{const n=Nh(e.to)(t);if(n.tag==="Nothing")return Ch;if(n.tag==="Just")return n._1;g()})()),Ik=t=>e=>{const n=Jh(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:R};if(n.tag==="Just")return n._1;g()},kh={id:"",index:-1,kind:"",name:"",time:0,endTime:0,path:[],tokenIndex:-1,lineIndex:-1,text:"",from:"",to:""},Ak=t=>e=>e.scene.tag==="StepScene"?N("Just",{...kh,id:"step:"+e.scene._1,kind:"step",name:e.scene._1,time:e.startT,endTime:e.startT,path:vh(t)}):w,Rk=t=>vt(Ak(t.path))(t.spans),Ag=t=>e=>n=>r=>{const o=Aa(r)(n.edges);if(o.tag==="Just")return t<=0?e:fr(e)(Gs(o._1)/t);if(o.tag==="Nothing")return e;g()},Lh=t=>e=>n=>r=>o=>{const i=t.plop,s=Dk(n)(o),a=$(f=>({startT:0,endT:0+Ag(t.edgeSpeed)(t.minEdgeDuration)(e)(f),target:Uo("EdgeWindow",f,Ms("Extend",tc))}))(wi(s.entering.edges)),u=$(f=>({startT:0,endT:i,target:Uo("NodeWindow",f,Uu)}))(wi(s.entering.nodes)),c=v(fr)(0)($(f=>Ag(t.edgeSpeed)(t.minEdgeDuration)(e)(f))(wi(s.leaving.edges))),_=f=>Ne(h=>{const p=Aa(h)(r);if(p.tag==="Just")return p._1.source===f||p._1.target===f;if(p.tag==="Nothing")return!1;g()},wi(s.leaving.edges))?c:0,d=$(f=>({startT:_(f),endT:_(f)+t.plop,target:Uo("NodeWindow",f,oy)}))(wi(s.leaving.nodes)),l=$(f=>({startT:0,endT:Ag(t.edgeSpeed)(t.minEdgeDuration)(e)(f),target:Uo("EdgeWindow",f,Ms("Retract",Tk(r)(s.leaving.nodes)(f)))}))(wi(s.leaving.edges));return{duration:(()=>{const f=It(it.compare)([...$(p=>p.endT)(l),...$(p=>p.endT)(d),...$(p=>p.endT)(u),...$(p=>p.endT)(a)]),h=f.length-1|0;return h>=0&&h<f.length?f[h]+t.gap:t.gap})(),windows:[...l,...d,...u,...a]}},Fk=t=>e=>n=>r=>o=>i=>$((()=>{const s=o.startT;return a=>({...a,startT:a.startT+s,endT:a.endT+s})})())(Lh(t)(e)(n)(r)(i).windows),Qk=t=>vt(e=>jt(Io,e).length>1?N("Just",(()=>{const n=zt(r=>w,r=>o=>N("Just",{head:r,tail:o}),jt(Io,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):w)(I0(Ti)(It(P.compare)(t))),Mk=t=>{const e=$(r=>r.id)(t),n=dk(e);return[...$(pk)(Qk(e)),...$(mk)(ft(r=>!Ig(r)(n),St(t)(Bk)))]},zk=t=>{const e=yh($(r=>C(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(Ig(i)(o))return[jr("ScheduleCycle",[...jt(rn.foldr,o),i])];if(Ig(i)(r))return[];const s=wh(i)(e);if(s.tag==="Nothing")return[];if(s.tag==="Just")return St(s._1)(n(rt(P)(i)()(r))(rt(P)(i)()(o)));g()};return St(t)(r=>n(R)(R)(r.id))},Wk={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:.5,stillHold:1.8,hatchHold:.4,tokenReadSecPerChar:.06,nodeEasing:y2,edgeEasing:go,tokenEasing:Hu,diveDur:1.2,retreatDur:1.2},qk=t=>e=>n=>r=>$((()=>{const o=n.startT;return i=>({...i,startT:i.startT+o,endT:i.endT+o})})())(vt(Nk)(Th(t)(e)(r.events))),Ok=t=>e=>n=>r=>o=>{if(o.scene.tag==="Structural")return Fk(t)(e)(n)(r)(o)(o.scene._1);if(o.scene.tag==="Hold")return[];if(o.scene.tag==="DataFlow")return qk(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()},Hk=t=>e=>n=>{const r=Th(t)(e)(n.events);return r.length===0?t.gap:v(fr)(0)($(o=>o.endT)(r))+t.gap},$k=t=>e=>n=>r=>o=>{if(o.tag==="Structural")return Lh(t)(e)(n)(r)(o._1).duration;if(o.tag==="Hold")return t.stillHold;if(o.tag==="DataFlow")return Hk(t)(e)(o._1);if(o.tag==="EnterNode"||o.tag==="ExitNode"||o.tag==="StepScene")return 0;g()},Sh=t=>e=>n=>r=>o=>i=>{const s=Um(e)(r),a=n.layout,u=K_($(p=>C(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()})(),d=p2(o),l=p=>({segments:p.runSpans.length===0?p.segments:Pt(p.segments)({startT:p.runStart,endT:p.t,path:r,layout:a,placement:s,windows:p.runWindows,spans:p.runSpans,keyframes:u,initialKeyframe:_,edgeEndpoints:d}),spans:p.spans,windows:p.windows,dives:p.dives}),f=v(p=>m=>{if(m.tag==="EnterNode"){const T=l(p),b=p.t+t.diveDur,L=Pt(r)(m._1),E=Sh(t)(e)(Ik(n)(m._1))(L)(kk(o)(m._1))(b),B=E.endT+t.retreatDur;return{...p,t:B,runStart:B,runSpans:[],runWindows:[],segments:[...T.segments,...E.segments],spans:[...T.spans,...E.spans],windows:[...T.windows,...E.windows],dives:[...T.dives,{startT:p.t,endT:b,node:m._1,parentPath:r,childPath:L,direction:iy},...E.dives,{startT:E.endT,endT:B,node:m._1,parentPath:r,childPath:L,direction:sy}]}}if(m.tag==="ExitNode")return p;const J=p.t+$k(t)(a)(u)(d)(m),x={startT:p.t,endT:J,scene:m},y=Ok(t)(a)(u)(d)(x);return{...p,t:J,runSpans:Pt(p.runSpans)(x),runWindows:[...p.runWindows,...y],spans:Pt(p.spans)(x),windows:[...p.windows,...y]}})({t:i,runStart:i,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(o.scenes),h=l(f);return{endT:f.t,spans:h.spans,windows:It(p=>m=>it.compare(p.startT)(m.startT))(h.windows),segments:h.segments,dives:h.dives}},Vk=t=>e=>{const n=it.compare(t.time)(e.time);return n==="EQ"?P.compare(t.id)(e.id):n},Xk=t=>e=>n=>{const r=fr(.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=wk(n),s=$(u=>nt(lk(1)(Yo(u).length)))(i),a=fr(1)(v(er)(0)(s));return Ht(u=>c=>({lineIndex:u,text:c,start:o(v(er)(0)(u<1?[]:Dt(0,u,s))/a),end:o(u>=0&&u<s.length?(v(er)(0)(u<1?[]:Dt(0,u,s))+s[u])/a:(v(er)(0)(u<1?[]:Dt(0,u,s))+1)/a)}))(i)},Yk=t=>{const e=fr(0)(t.window.endT-t.window.startT);return $(n=>({...kh,id:"token:"+t.eventId+":line:"+ie(n.lineIndex),kind:"tokenLine",time:t.window.startT+n.start*e,endTime:t.window.startT+n.end*e,path:vh(t.path),tokenIndex:t.tokenIndex,lineIndex:n.lineIndex,text:n.text,from:t.from,to:t.to}))(Xk(t.holdPre)(t.holdPost)(t.labels))},Uk=t=>St(Ht(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}))(St(t)(vk)))(Yk),Kk=t=>Ht(e=>n=>({...n,index:e}))(It(Vk)([...St(t.segments)(Rk),...Uk(t.segments)])),jk=t=>e=>{if(e.tag==="Structural")return vt(n=>n)([Ra(e._1.from)(t)?w:N("Just",jr("UnknownKeyframe",e._1.from)),Ra(e._1.to)(t)?w:N("Just",jr("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return vt(n=>n)([Ra(e._1)(t)?w:N("Just",jr("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...vt(n=>n)([Ra(e._1.keyframe)(t)?w:N("Just",jr("UnknownKeyframe",e._1.keyframe))]),...Mk(e._1.events),...zk(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];if(e.tag==="StepScene")return[];g()},Zk=t=>e=>{const n=St(e)(jk(t));return n.length===0?Wt("Right",void 0):Wt("Left",n)},t5=t=>e=>n=>r=>{if(0<n.keyframes.length){const o=n.keyframes[0],i=K_($(a=>C(a.id,a))(n.keyframes)),s=Zk(i)(n.scenes);return(()=>{if(s.tag==="Left"){const a=s._1;return u=>Wt("Left",a)}if(s.tag==="Right"){const a=s._1;return u=>u(a)}g()})()(()=>{const a=Pk(Sh(e)(r)(r)([])(n)(0));return Wt("Right",{totalDuration:a.endT,windows:a.windows,spans:a.spans,keyframes:i,initialKeyframe:o.id,timing:e,layout:r.layout,cameraSpans:mh(t)(A2)(r.layout)(i)(a),cameraConfig:t,levelTree:r,segments:a.segments,dives:a.dives,cues:Kk(a),seed:n.seed})})}return Wt("Left",[hk])},So=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(o=>n(o._1)(o._2)),Apply0:()=>Eh(t)}),Eh=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>o=>i=>e.map(s=>C(r(s._1),s._2))(o(i))};return{apply:(()=>{const r=So(t);return o=>i=>r.bind(o)(s=>r.bind(i)(a=>Eo(t).pure(s(a))))})(),Functor0:()=>n}},Eo=t=>({pure:e=>n=>t.Applicative0().pure(C(e,n)),Apply0:()=>Eh(t)}),Gh=t=>{const e={Applicative0:()=>Eo(t),Bind1:()=>So(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},Go=(t,e)=>({tag:t,_1:e}),dr=(t,e)=>({tag:t,_1:e}),Fa=t=>t,Xn=(t,e)=>({tag:t,_1:e}),Rg=t=>t,Je=Gh(Tn),e5=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},n5=ce(P)(Mt),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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},r5=v(t=>e=>rt(P)(e)()(t))(R),Vt=So(Tn),Oe=Je.state(t=>C(t,t)),ge=Eo(Tn),Ph=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Bh=Ar(ge),Qg=Bh(Mt),o5=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},lr=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},i5=(()=>{const t=en.unfoldr(e=>{if(e.tag==="Nil")return w;if(e.tag==="Cons")return N("Just",C(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,kt("Cons",r._3,n(r._6,o)));g()};return n(e,H)})())})(),Yn=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},s5=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Qa=t=>e=>n=>v(r=>o=>t.Bind1().bind(r)(i=>e(i)(o)))(t.Applicative0().pure(n)),a5=v(t=>e=>rt(P)(e)()(t))(R),u5=(()=>{const t=(e=>n=>{let r=e,o=n,i=!0,s;for(;i;){const a=r,u=o;if(u.tag==="Nil"){i=!1,s=a;continue}if(u.tag==="Cons"){r=rt(P)(u._1)()(a),o=u._2;continue}g()}return s})(R);return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,kt("Cons",r._3,n(r._6,o)));g()};return n(e,H)})())})(),c5=Bh(f_),g5=v(t=>e=>rt(P)(e)()(t))(R),_5=Rg("AnimatedSurface"),f5=Rg("StillSurface"),d5=Rg("SequenceSurface"),l5=Xn("Exit"),Ma=Fa("AnimatedKeyframe"),Mg=Fa("Still"),h5=Fa("Title"),Dh=Fa("StepMarker"),p5=t=>dr("Par",t),m5=t=>dr("Seq",t),y5=t=>dr("GroupSeq",t),Ih=t=>Go("StepDive",t),x5={line:0,column:0,endLine:0,endColumn:0},w5=t=>e=>n=>{const r=ro(Yt,w,o=>o._1===t,n);if(r.tag==="Just"){const o=Fr(Yt,w,r._1,C(t,e),n);if(o.tag==="Nothing")return n;if(o.tag==="Just")return o._1;g()}if(r.tag==="Nothing")return Pt(n)(C(t,e));g()},J5=t=>e=>$(n=>n._1===t?C(n._1,{...n._2,label:N("Just",e)}):C(n._1,n._2)),Ah=t=>{const e=t.compare;return n=>v(r=>o=>Ae(e,Be,r,n(o)))(R)},zg=Ah(P),Wg=Ah(P),N5=t=>{const e=t.span;return Je.state(n=>C(void 0,{...n,currentSpan:e}))},v5=t=>e=>({structural:[...t.structural,...e.structural],flow:t.flow||e.flow,dives:[...t.dives,...e.dives]}),T5=t=>e=>e.kind==="Animated"||e5(e.id)(t),Rh={graphNodes:[],graphEdges:R,currNodes:R,currEdges:R,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:w,currentSpan:x5,error:w,enterStack:[],interiorOf:R,stepNames:R},Fh=t=>e=>n=>{const r=jt(rn.foldr,n);return rr(", ")($(e)(Dt(0,6,r)))+(r.length>6?", \u2026":"")},b5=t=>e=>{const n=Fg(e)(n5($(r=>C(r.id,r))(t.graph.edges)));if(n.tag==="Just")return(()=>{const r=io("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()},C5=t=>e=>n=>{const r=Fh()(bi)(e),o=Fh()(b5(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."},k5=t=>{if(t.kind.tag==="SendToken")return r5([t.kind._1.from,t.kind._1.to]);if(t.kind.tag==="FillNodeWithoutTransition")return te("Node",1,1,t.kind._1.node,void 0,R,R);g()},L5=t=>zg(k5)(t.events),S5=t=>{if(t.kind.tag==="SendToken")return te("Node",1,1,t.kind._1.edge,void 0,R,R);if(t.kind.tag==="FillNodeWithoutTransition")return R;g()},E5=t=>Wg(S5)(t.events),Un=t=>Je.state(e=>C(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()})())),G5=Qg(t=>Vt.bind(Oe)(e=>{if(e.error.tag==="Just")return ge.pure();if(e.error.tag==="Nothing")return Ph(t.node)(e.interiorOf)?Un("node "+t.node+" has more than one `inside` block"):Je.state(n=>C(void 0,{...n,interiorOf:rt(P)(t.node)(t.doc)(n.interiorOf)}));g()})),P5=t=>Vt.bind(Oe)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ie(e.kfCounter);if(Ne(o=>o.id===n,e.keyframes))return Un("duplicate frame name "+n);const r={...e,keyframes:Pt(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges,kind:Di}),kfCounter:e.kfCounter+1|0,currentKf:N("Just",n)};return Je.state(o=>C(void 0,r))}),un=t=>e=>Vt.bind(Je.state(n=>C(void 0,{...n,currentSpan:t})))(()=>Un(e)),Qh=t=>e=>Vt.bind(Oe)(n=>o5(e)(n.stepNames)?un(t)("duplicate step name "+e):Je.state(r=>C(void 0,{...r,scenes:Pt(r.scenes)($o("StepScene",e)),stepNames:rt(P)(e)()(r.stepNames)}))),B5=t=>{if(t.ops.tag==="Leaf"){const e=t.ops._1;return Vt.bind((()=>{const n=e.span;return Je.state(r=>C(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?Qh(e.span)(e.op._1.name):Un("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 Vt.bind((()=>{const n=e.span;return Je.state(r=>C(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?Qh(e.span)(e.op._1.name):Un("step marker frame did not contain a step"))}return Un("step marker frame did not contain a step")},D5=t=>Vt.bind((()=>{const e=t.span;return Je.state(n=>C(void 0,{...n,currentSpan:e}))})())(()=>Vt.bind(Oe)(e=>{if(e.error.tag==="Just")return ge.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!lr(t.op._1.id)(e.currNodes))return un(0<t.operands.length?t.operands[0]:t.span)("cannot dive into node "+t.op._1.id+": does not exist");if(!Ph(t.op._1.id)(e.interiorOf))return un(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 A4=(function(cu){"use strict";function Xp(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 Tr(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const Ie=t=>e=>t,O=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}},Yp={map:O},i_=t=>t,St=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]),s=i.length,a=0;a<s;a++)n.push(i[a]);return n}},Kp=function(t){return function(e){return{}.hasOwnProperty.call(e,t)}},jp=function(t){return function(e){return e[t]}},ie=function(t){return t.toString()},ao=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},Zp=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})+'"'},gu=t=>t,Be=gu("LT"),De=gu("GT"),Ye=gu("EQ"),N=(t,e)=>({tag:t,_1:e}),J=N("Nothing"),Ut=t=>N("Just",t),s_=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;g()},a_=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;g()},Wt=(t,e)=>({tag:t,_1:e}),t0=t=>Wt("Right",t),e0={map:t=>e=>{if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right")return Wt("Right",t(e._1));g()}},u_={apply:t=>e=>{if(t.tag==="Left")return Wt("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right")return Wt("Right",t._1(e._1))}g()},Functor0:()=>e0},n0={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Wt("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}g()},Apply0:()=>u_},r0={pure:t0,Apply0:()=>u_},c_={Applicative0:()=>r0,Bind1:()=>n0},o0=t=>t,i0={map:t=>e=>t(e)},g_={apply:t=>e=>t(e),Functor0:()=>i0},s0={bind:t=>e=>e(t),Apply0:()=>g_},a0={pure:o0,Apply0:()=>g_},kn={Applicative0:()=>a0,Bind1:()=>s0},u0=function(t){return function(){return t}},c0={apply:t=>e=>()=>{const n=t(),r=e();return _u.pure(n(r))()},Functor0:()=>g0},_u={pure:u0,Apply0:()=>c0},g0={map:t=>e=>()=>{const n=e();return t(n)}},Ao=(t,e)=>({tag:t,_1:e}),fu=t=>Ao("Loop",t),_0=t=>Ao("Done",t),f0={tailRecM:t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const s=r;if(s.tag==="Loop"){r=t(s._1);continue}if(s.tag==="Done"){o=!1,i=s._1;continue}g()}return i};return n=>e(t(n))},Monad0:()=>kn},d0=function(t){return function(e){return function(){return t(e())}}},l0=function(t){return function(){return t}},h0=function(t){return function(e){return function(){return e(t())()}}},p0={map:d0},m0={Applicative0:()=>du,Bind1:()=>y0},y0={bind:h0,Apply0:()=>__},__={apply:t=>e=>()=>{const n=t(),r=e();return du.pure(n(r))()},Functor0:()=>p0},du={pure:l0,Apply0:()=>__},x0={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:()=>m0},w0=function(t){return function(e){return function(n){return function(){return t(e,n)}}}},J0=function(t,e,n,r){return n>=0&&n<r.length?t(r[n]):e},lu=function(t){return t.length},N0=function(t,e,n){return n.length>0?t(n.pop()):e},T0=w0(function(t,e){return e.push(t)}),v0=(t,e)=>({tag:"Iterator",_1:t,_2:e}),C0=t=>e=>n=>()=>{let r=!1;const o=e._2;for(;!r;){const i=o.value,s=e._1(i);if(s.tag==="Just"&&t(s._1)){n.push(s._1),e._2.value;const a=e._2.value;e._2.value=a+1|0;continue}r=!0}},b0=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const o=r.value,i=r.value;r.value=i+1|0;const s=t._1(o);if(s.tag==="Just"){e(s._1)();continue}if(s.tag==="Nothing"){n=!0;continue}g()}},Io=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}}},T=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}}},Wr=t=>{const e=t.Apply0();return n=>r=>n.foldr(o=>{const i=r(o);return s=>e.apply(e.Functor0().map(a=>i_)(i))(s)})(t.pure())},Fo=t=>{const e=Wr(t);return n=>{const r=e(n);return o=>i=>r(i)(o)}},f_={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()}}},zt={foldr:Io,foldl:T,foldMap:t=>{const e=t.mempty;return n=>zt.foldr(r=>o=>t.Semigroup0().append(n(r))(o))(e)}},b=(t,e)=>({tag:"Tuple",_1:t,_2:e}),An=t=>e=>b(t,e),ps=t=>t._2,ms=t=>t._1,Ht=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 hu=function(t){return function(e){return t===e}};const k0=hu,L0=hu,vi=hu,pu=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:vi},S0={eq:L0},qr={eq:k0};var mu=function(t){return function(e){return function(n){return function(r){return function(o){return r<o?t:r===o?e:n}}}}};const E0=mu,G0=mu,P={compare:mu(Be)(Ye)(De),Eq0:()=>tr},ot={compare:G0(Be)(Ye)(De),Eq0:()=>S0},it={compare:E0(Be)(Ye)(De),Eq0:()=>qr},Ci=function(t){return t},P0=(function(){function t(o){return[o]}function e(o){return function(i){return[o,i]}}function n(o){return function(i){return function(s){return[o,i,s]}}}function r(o){return function(i){return o.concat(i)}}return function(o){return function(i){return function(s){return function(a){return function(u){function c(_,d){switch(d-_){case 0:return s([]);case 1:return i(t)(a(u[_]));case 2:return o(i(e)(a(u[_])))(a(u[_+1]));case 3:return o(o(i(n)(a(u[_])))(a(u[_+1])))(a(u[_+2]));default:var l=_+Math.floor((d-_)/4)*2;return o(i(r)(c(_,l)))(c(l,d))}}return c(0,u.length)}}}}}})(),B0=t=>t,uo={traverse:t=>{const e=t.Apply0();return P0(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>uo.traverse(t)(B0),Functor0:()=>Yp,Foldable1:()=>zt},Kt=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 D0=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},R0=function(t,e){for(var n=[],r=0,o=0;o<t;o++)n[r++]=e;return n};const A0=typeof Array.prototype.fill=="function"?D0:R0,Zt=(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=[],s=0,a=o;a!==e;)i[s++]=a.head,a=a.tail;return i}return function(o,i){return r(o(n)(e)(i))}})(),Ft=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},d_=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},vr=function(t,e,n,r){for(var o=0,i=r.length;o<i;o++)if(n(r[o]))return t(o);return e},l_=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)},h_=function(t,e,n,r){if(n<0||n>=r.length)return e;var o=r.slice();return o.splice(n,1),t(o)},Or=function(t,e,n,r,o){if(n<0||n>=o.length)return e;var i=o.slice();return i[n]=r,t(i)},se=function(t){return t.slice().reverse()},hn=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,s=o.length;i<s;i++)e.push(o[i]);return e},ft=function(t,e){return e.filter(t)},I0=function(t,e,n){for(var r=n.length,o=e,i=new Array(r),s=0;s<r;s++)o=t(o)(n[s]),i[s]=o;return i},F0=(function(){function t(e,n,r,o,i,s){var a,u,c,_,d,l,f;for(a=i+(s-i>>1),a-i>1&&t(e,n,o,r,i,a),s-a>1&&t(e,n,o,r,a,s),u=i,c=a,_=i;u<a&&c<s;)d=o[u],l=o[c],f=n(e(d)(l)),f>0?(r[_++]=l,++c):(r[_++]=d,++u);for(;u<a;)r[_++]=o[u++];for(;c<s;)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)}})(),Bt=function(t,e,n){return n.slice(t,e)},Fe=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},xe=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},p_=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Pt=t=>e=>F0(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),Q0=t=>e=>Pt(n=>r=>t.compare(e(n))(e(r))),kt=t=>e=>(()=>{const n=T0(e);return()=>{const r=[...t];return n(r)(),r}})()(),Cr=t=>{if(t.length===0)return t.length-1|0,J;const e=t.length-1|0;return e>=0&&e<t.length?N("Just",{init:Bt(0,t.length-1|0,t),last:t[e]}):J},M0=t=>e=>n=>t>=0&&t<n.length?Or(Ut,J,t,e(n[t]),n):J,er=t=>e=>{const n=(r=>{let o=r,i=!0,s;for(;i;){const a=o;if(a>=0&&a<e.length){if(t(e[a])){o=a+1|0;continue}i=!1,s=N("Just",a);continue}i=!1,s=J}return s})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:Bt(0,n._1,e),rest:Bt(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};g()},Qo=t=>e=>{const n=Pt(r=>o=>t(r._2)(o._2))(Ht(An)(e));return 0<n.length?O(ps)(Q0(it)(ms)((()=>{const r=[n[0]];for(const o of n){const i=t((()=>{const s=r.length-1|0;if(s>=0&&s<r.length)return r[s]._2;g()})())(o._2);(i==="LT"||i==="GT"||i!=="EQ")&&r.push(o)}return r})())):[]},z0=t=>e=>{const n=[],r=v0(o=>o>=0&&o<e.length?N("Just",e[o]):J,{value:0});return b0(r)(o=>()=>{const i=[];i.push(o),C0(t(o))(r)(i)(),n.push(i)})(),n},re=t=>e=>{const n=vr(Ut,J,t,e);return n.tag==="Just"?N("Just",e[n._1]):J},bi=t=>e=>ft(t,e),en=t=>e=>n=>{const r=vr(Ut,J,o=>t.eq(o)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},ys=t=>e=>St(e)(t),Tt=t=>ys(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];g()}),m_=isFinite;function W0(t,e,n,r){var o=parseFloat(t);return e(o)?n(o):r}const Qe=Math.abs,q0=Math.acos,co=function(t){return function(e){return Math.atan2(t,e)}},xs=Math.ceil,Ln=Math.cos,Mo=Math.exp,In=Math.floor,ws=Math.log,O0=function(t){return function(e){return Math.min(t,e)}},yu=function(t){return function(e){return Math.pow(t,e)}},$n=Math.round,pn=Math.sin,Ve=Math.sqrt,H0=Math.tan,$0=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},nt=function(t){return t},V0=(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 s=parseInt(i,n);return(s|0)===s?t(s):e}else return e}}}})(Ut)(J)(10),y_=$0(Ut)(J),fe=t=>{if(!m_(t))return 0;if(t>=nt(2147483647))return 2147483647;if(t<=nt(-2147483648))return-2147483648;const e=y_(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;g()},Lt=(t,e,n)=>({tag:t,_1:e,_2:n}),$=Lt("Nil"),de={foldr:t=>e=>{const n=de.foldl(o=>i=>t(i)(o))(e),r=(o=>i=>{let s=o,a=i,u=!0,c;for(;u;){const _=s,d=a;if(d.tag==="Nil"){u=!1,c=_;continue}if(d.tag==="Cons"){s=Lt("Cons",d._1,_),a=d._2;continue}g()}return c})($);return o=>n(r(o))},foldl:t=>e=>n=>{let r=e,o=n,i=!0,s;for(;i;){const a=r,u=o;if(u.tag==="Nil"){i=!1,s=a;continue}if(u.tag==="Cons"){r=t(a)(u._1),o=u._2;continue}g()}return s},foldMap:t=>{const e=t.mempty;return n=>de.foldl(r=>{const o=t.Semigroup0().append(r);return i=>o(n(i))})(e)}},U0=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var s=[],a=i;;){var u=o(a);s.push(n(u));var c=r(u);if(t(c))return s;a=e(c)}}}}}}},X0=t=>{if(t.tag==="Just")return t._1;g()},Y0={unfoldr1:U0(s_)(X0)(ms)(ps)},K0=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var s=[],a=i;;){var u=o(a);if(t(u))return s;var c=e(u);s.push(n(c)),a=r(c)}}}}}}},j0=t=>{if(t.tag==="Just")return t._1;g()},nn={unfoldr:K0(s_)(j0)(ms)(ps),Unfoldable10:()=>Y0},te=(t,e,n,r,o,i,s)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:s}),rn=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Js=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),x_=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),I=te("Leaf"),Fn=rn("IterLeaf"),Te=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return te("Node",1,1,t,e,n,r);if(r.tag==="Node")return te("Node",1+r._1|0,1+r._2|0,t,e,n,r);g()}if(n.tag==="Node"){if(r.tag==="Leaf")return te("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return te("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()},Ke=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?te("Node",1,1,t,e,I,I):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()})()?Te(r._5._3,r._5._4,Te(t,e,n,r._5._5),Te(r._3,r._4,r._5._6,r._6)):Te(r._3,r._4,Te(t,e,n,r._5),r._6):Te(t,e,n,r);if(n.tag==="Node")return r.tag==="Node"?r._1>(n._1+1|0)?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;g()})()?Te(r._5._3,r._5._4,Te(t,e,n,r._5._5),Te(r._3,r._4,r._5._6,r._6)):Te(r._3,r._4,Te(t,e,n,r._5),r._6):n._1>(r._1+1|0)?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?Te(n._6._3,n._6._4,Te(n._3,n._4,n._5,n._6._5),Te(t,e,n._6._6,r)):Te(n._3,n._4,n._5,Te(t,e,n._6,r)):Te(t,e,n,r):r.tag==="Leaf"&&n._1>1?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?Te(n._6._3,n._6._4,Te(n._3,n._4,n._5,n._6._5),Te(t,e,n._6._6,r)):Te(n._3,n._4,n._5,Te(t,e,n._6,r)):Te(t,e,n,r);g()},zo=(t,e,n)=>{if(n.tag==="Leaf")return Js(J,I,I);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const o=zo(t,e,n._5);return Js(o._1,o._2,Ke(n._3,n._4,o._3,n._6))}if(r==="GT"){const o=zo(t,e,n._6);return Js(o._1,Ke(n._3,n._4,n._5,o._2),o._3)}if(r==="EQ")return Js(N("Just",n._4),n._5,n._6)}g()},w_=(t,e,n,r)=>{if(r.tag==="Leaf")return x_(t,e,n);if(r.tag==="Node"){const o=w_(r._3,r._4,r._5,r._6);return x_(o._1,o._2,Ke(t,e,n,o._3))}g()},Wo=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=w_(t._3,t._4,t._5,t._6);return Ke(n._1,n._2,n._3,e)}g()},Vn=(t,e,n)=>{if(e.tag==="Leaf")return I;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=zo(t,n._3,e);return Wo(Vn(t,r._2,n._5),Vn(t,r._3,n._6))}g()},Ns=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return I;if(r.tag==="Node"){const o=zo(t,r._3,n),i=Ns(t,e,o._2,r._5),s=Ns(t,e,o._3,r._6);if(o._1.tag==="Just")return Ke(r._3,e(o._1._1)(r._4),i,s);if(o._1.tag==="Nothing")return Wo(i,s)}g()},Me=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const o=zo(t,r._3,n),i=Me(t,e,o._2,r._5),s=Me(t,e,o._3,r._6);if(o._1.tag==="Just")return Ke(r._3,e(o._1._1)(r._4),i,s);if(o._1.tag==="Nothing")return Ke(r._3,r._4,i,s)}g()},J_=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return I;if(o.tag==="Node"){const i=t.compare(n)(o._3);if(i==="LT")return Ke(o._3,o._4,r(o._5),o._6);if(i==="GT")return Ke(o._3,o._4,o._5,r(o._6));if(i==="EQ"){const s=e(o._4);if(s.tag==="Nothing")return Wo(o._5,o._6);if(s.tag==="Just")return te("Node",o._1,o._2,o._3,s._1,o._5,o._6)}}g()};return r},Z0=t=>e=>{const n=r=>{if(r.tag==="Leaf")return I;if(r.tag==="Node"){const o=e(r._3)(r._4);if(o.tag==="Just")return Ke(r._3,o._1,n(r._5),n(r._6));if(o.tag==="Nothing")return Wo(n(r._5),n(r._6))}g()};return n},Qn=(t=>e=>n=>{let r=n,o=!0,i;for(;o;){const s=r;if(s.tag==="IterLeaf"){o=!1,i=e();continue}if(s.tag==="IterEmit"){o=!1,i=t(s._1,s._2,s._3);continue}if(s.tag==="IterNode"){r=(a=>u=>{let c=a,_=u,d=!0,l;for(;d;){const f=c,h=_;if(h.tag==="Leaf"){d=!1,l=f;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){c=rn("IterEmit",h._3,h._4,f),_=h._5;continue}c=rn("IterEmit",h._3,h._4,rn("IterNode",h._6,f)),_=h._5;continue}g()}return l})(s._2)(s._1);continue}g()}return i})((t,e,n)=>N("Just",b(b(t,e),n)))(t=>J),Qt=t=>e=>n=>r=>{const o=i=>{if(i.tag==="Leaf")return te("Node",1,1,n,r,I,I);if(i.tag==="Node"){const s=t.compare(n)(i._3);if(s==="LT")return Ke(i._3,i._4,o(i._5),i._6);if(s==="GT")return Ke(i._3,i._4,i._5,o(i._6));if(s==="EQ")return te("Node",i._1,i._2,n,e(i._4)(r),i._5,i._6)}g()};return o},rt=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return te("Node",1,1,e,n,I,I);if(o.tag==="Node"){const i=t.compare(e)(o._3);if(i==="LT")return Ke(o._3,o._4,r(o._5),o._6);if(i==="GT")return Ke(o._3,o._4,o._5,r(o._6));if(i==="EQ")return te("Node",o._1,o._2,e,n,o._5,o._6)}g()};return r},ce=t=>e=>e.foldl(n=>r=>rt(t)(r._1)(r._2)(n))(I),qo=t=>e=>{const n=r=>{if(r.tag==="Leaf")return I;if(r.tag==="Node"){const o=t.compare(e)(r._3);if(o==="LT")return Ke(r._3,r._4,n(r._5),r._6);if(o==="GT")return Ke(r._3,r._4,r._5,n(r._6));if(o==="EQ")return Wo(r._5,r._6)}g()};return n},N_=t=>{const e=t.compare;return n=>r=>o=>{const i=zo(e,r,o),s=n(i._1);if(s.tag==="Nothing")return Wo(i._2,i._3);if(s.tag==="Just")return Ke(r,s._1,i._2,i._3);g()}},we=function(t){return function(e){return t+e|0}},nr=function(t){return function(e){return t+e}},Hr=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},tm=function(t){return function(e){return t+e}},le=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},em={append:tm},nm={append:le},rm={mempty:"",Semigroup0:()=>em},om={mempty:[],Semigroup0:()=>nm},ki=null;function mn(t,e,n){return t==null?e:n(t)}function C4(t){return t}function xu(t){return function(e){return function(n){return t.apply(n,[e])}}}const im=xu(Number.prototype.toPrecision),sm=xu(Number.prototype.toFixed),am=xu(Number.prototype.toExponential),Oo=(t,e)=>({tag:t,_1:e}),Ho=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},$o=t=>{if(t.tag==="Precision")return im(t._1);if(t.tag==="Fixed")return sm(t._1);if(t.tag==="Exponential")return am(t._1);g()},T_=function(t){return function(){console.log(t)}};function um(){return Date.now()}function v_(t){return function(){return t.getContext("2d")}}function C_(t){return function(){return t.width}}function b_(t){return function(){return t.height}}function k_(t){return function(e){return function(){t.width=e}}}function L_(t){return function(e){return function(){t.height=e}}}function wu(t){return function(e){return function(){t.lineWidth=e}}}function cm(t){return function(e){return function(){t.fillStyle=e}}}function gm(t){return function(e){return function(){t.strokeStyle=e}}}function Ju(t){return function(e){return function(){t.lineCap=e}}}function Nu(t){return function(e){return function(){t.lineJoin=e}}}function _m(t){return function(e){return function(){t.globalCompositeOperation=e}}}function fm(t){return function(e){return function(){t.globalAlpha=e}}}function S_(t){return function(){t.beginPath()}}function Tu(t){return function(){t.stroke()}}function vu(t){return function(){t.fill()}}function dm(t){return function(){t.clip()}}function Li(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function E_(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function G_(t){return function(){t.closePath()}}function lm(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function hm(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function Ts(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function P_(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function pm(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function mm(t){return function(e){return function(){t.textAlign=e}}}function ym(t){return function(e){return function(){t.textBaseline=e}}}function xm(t){return function(e){return function(){t.font=e}}}function wm(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function rr(t){return function(){t.save()}}function or(t){return function(){t.restore()}}function Si(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function Jm(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const B_=t=>t,Cu=t=>t,bu=t=>t,ku=t=>t,vs=t=>t,Nm=vs("BaselineTop"),Tm=vs("BaselineMiddle"),vm=vs("BaselineAlphabetic"),Cm=vs("BaselineBottom"),bm=ku("AlignLeft"),km=ku("AlignRight"),Lm=ku("AlignCenter"),Lu=bu("BevelJoin"),Su=bu("RoundJoin"),Eu=bu("MiterJoin"),Gu=Cu("Round"),Pu=Cu("Square"),Bu=Cu("Butt"),Sm=B_("SourceOver"),Em=B_("Difference"),Gm=t=>e=>ym(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()})()),Pm=t=>e=>mm(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()})()),Du=t=>e=>{if(e==="BevelJoin")return Nu(t)("bevel");if(e==="RoundJoin")return Nu(t)("round");if(e==="MiterJoin")return Nu(t)("miter");g()},Ru=t=>e=>{if(e==="Round")return Ju(t)("round");if(e==="Square")return Ju(t)("square");if(e==="Butt")return Ju(t)("butt");g()},D_=t=>e=>_m(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()})()),R_={foldrWithIndex:t=>e=>{const n=Io(o=>{const i=o._1,s=o._2;return a=>t(i)(s)(a)})(e),r=Ht(An);return o=>n(r(o))},foldlWithIndex:t=>e=>{const n=T(o=>i=>t(i._1)(o)(i._2))(e),r=Ht(An);return o=>n(r(o))},foldMapWithIndex:t=>{const e=t.mempty;return n=>R_.foldrWithIndex(r=>o=>i=>t.Semigroup0().append(n(r)(o))(i))(e)},Foldable0:()=>zt},fn={foldr:t=>e=>{const n=de.foldr(t)(e);return r=>n((()=>{const o=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return o(i._5,Lt("Cons",i._3,o(i._6,s)));g()};return o(r,$)})())}},Bm=t=>{const e={append:(()=>{const n=t.compare;return r=>o=>Me(n,Ie,r,o)})()};return{mempty:I,Semigroup0:()=>e}},Ei=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},$r=function(t){return t.join("")},br=function(t){return t.split("")},Gi=function(t){return t},ir=function(t){return t.length},A_=function(t){return function(e){return e.substr(0,t)}},Vo=function(t){return function(e){return e.substring(t)}},I_=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},Dm=t=>e=>{const n=I_(ir(e)-ir(t)|0)(e);return n.after===t?N("Just",n.before):J},go=t=>e=>{const n=I_(ir(t))(e);return n.before===t?N("Just",n.after):J},Rm=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},Am=function(t){return t()},Im=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},Fm=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},_o=t=>BigInt(t),Qm=t=>Number(t),Cs=t=>e=>t+e,bs=t=>e=>t*e,Au=t=>e=>t-e,F_=0n,ks=1n,Q_=t=>e=>t^e,Pi=t=>e=>t&e,Iu=t=>e=>t<<e,Fu=t=>e=>t>>e,Mm=t=>e=>t==e,zm=t=>e=>t===e?0:t>e?1:-1,Wm={eq:Mm},M_={compare:t=>e=>{const n=zm(t)(e);return n===1?De:n===0?Ye:Be},Eq0:()=>Wm},qm=Im(Ut)(J),Om=Fm(Ut)(J),z_=function(t){throw new Error(t)},W_=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=ot.compare(e._1)(n._1);return r==="LT"?Be:r==="GT"?De:ot.compare(e._2)(n._2)},Eq0:()=>t}})(),Hm=t=>e=>Qe(t._1-e._1)+Qe(t._2-e._2),fo=t=>t,Ls=t=>t,Le=Ls("North"),Se=Ls("South"),kr=Ls("East"),Lr=Ls("West"),Vr=fo("Rectangle"),$m=fo("Cylinder"),Vm=fo("Parallelogram"),Um=fo("Diamond"),Xm=fo("Ellipse"),Ym=fo("Document"),Km=fo("Cloud"),q_=T(nr)(0),jm=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Ur=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ss=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},O_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Zm=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}]},lo=t=>e=>{const n=Fe(s=>a=>({a:s,b:a,len:(()=>{const u=a.y-s.y,c=a.x-s.x;return Ve(c*c+u*u)})()}),t,Bt(1,t.length,t)),r=q_(O(s=>s.len)(n)),o=jm(0)(r)(e*r),i=s=>a=>u=>{let c=s,_=a,d=u,l=!0,f;for(;l;){const h=c,p=_,m=d,w=Ft(y=>J,y=>x=>N("Just",{head:y,tail:x}),h);if(w.tag==="Nothing"){const y=t.length-1|0;if(y>=0&&y<t.length){l=!1,f=t[y];continue}l=!1,f=m;continue}if(w.tag==="Just"){if(p<=w._1.head.len){const y=w._1.head.len<=0?0:p/w._1.head.len;l=!1,f={x:w._1.head.a.x+(w._1.head.b.x-w._1.head.a.x)*y,y:w._1.head.a.y+(w._1.head.b.y-w._1.head.a.y)*y};continue}c=w._1.tail,_=p-w._1.head.len,d=m;continue}g()}return f};return 0<t.length?N("Just",i(n)(o)(t[0])):J},t2=t=>e=>{const n=Ur(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}},Bi=t=>q_(Fe(e=>n=>{const r=n.y-e.y,o=n.x-e.x;return Ve(o*o+r*r)},t,Bt(1,t.length,t))),e2=t=>e=>{const n=Ur(4)(.15*Ss(e.w)(e.h)),r=Ur(1)(t.w),o=Ur(1)(t.h),i=Ur(1)(e.w-2*n),s=Ur(1)(e.h-2*n),a=Ss(i/r)(s/o);return{scale:a,tx:e.x+n+(i-r*a)/2-t.x*a,ty:e.y+n+(s-o*a)/2-t.y*a}},Qu={scale:1,tx:0,ty:0},he=t=>{const e=Ft(n=>J,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,Lt("Cons",r._4,n(r._6,o)));g()};return St(Zt(de.foldr,n(t.nodes,$)))(Zm)})(),...hn((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Lt("Cons",r._4,n(r._6,o)));g()};return Zt(de.foldr,n(t.edges,$))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=T(r=>o=>({minX:Ss(r.minX)(o.x),minY:Ss(r.minY)(o.y),maxX:Ur(r.maxX)(o.x),maxY:Ur(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()},n2=t=>e=>(n=>r=>o=>{let i=n,s=r,a=o,u=!0,c;for(;u;){const _=i,d=s,l=a,f=Ft(h=>J,h=>p=>N("Just",{head:h,tail:p}),d);if(f.tag==="Nothing"){u=!1,c=l;continue}if(f.tag==="Just"){const h=O_(f._1.head)(_.interiors);if(h.tag==="Nothing"){u=!1,c=l;continue}if(h.tag==="Just"){i=h._1,s=f._1.tail,a=(()=>{const p=e2(he(h._1.layout))((()=>{const m=O_(f._1.head)(_.layout.nodes);if(m.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:Vr};if(m.tag==="Just")return m._1;g()})());return{scale:l.scale*p.scale,tx:l.scale*p.tx+l.tx,ty:l.scale*p.ty+l.ty}})();continue}}g()}return c})(t)(e)(Qu),r2=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},o2=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Es=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},i2=t=>e=>n=>r=>{const o=he(e);return n<=0||r<=0||o.w<=0||o.h<=0?1:t?r2(o.w/n)(o.h/r):o2(o.w/n)(o.h/r)},H_=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;if(t.widthPx<=0||t.heightPx<=0){const s=1/Es(.05)(1)(e);return{w:n.w*s,h:n.h*s}}if(r>o){const s=1/Es(.05)(1)(e);return{w:n.h*r*s,h:n.h*s}}const i=1/Es(.05)(1)(e);return{w:n.w*i,h:n.w/r*i}},$_=t=>e=>n=>r=>o=>{const i=t+o/2,s=t+e-o/2,a=t+e/2,u=n+r/2;return o>=e?a:Es(i)(s)(u)},V_=t=>e=>n=>r=>{const o=he(t);return{x:$_(o.x)(o.w)(e.x)(e.w)(n),y:$_(o.y)(o.h)(e.y)(e.h)(r)}},U_=t=>e=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:i2(t)(e)(n.w)(n.h)}),s2=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=H_(e)(.65)(o),s=V_(n)(o)(i.w)(i.h),a={x:s.x-i.w/2,y:s.y-i.h/2,w:i.w,h:i.h};return{focus:r,paddedFocus:o,viewport:a,camera:U_(e.widthPx>0&&e.heightPx>0)(n)(a)}},a2=t=>e=>n=>r=>o=>i=>{const s=he(r),a={x:s.x*o.scale+o.tx,y:s.y*o.scale+o.ty,w:s.w*o.scale,h:s.h*o.scale},u=t.padding*o.scale,c={x:a.x-u,y:a.y-u,w:a.w+u*2,h:a.h+u*2},_=H_(e)(.7)(c),d=V_(n)(c)(_.w)(_.h),l={x:d.x-_.w/2,y:d.y-_.h/2,w:_.w,h:_.h};return{footprint:a,viewport:l,camera:U_(e.widthPx>0&&e.heightPx>0)(n)(l)}},X_=t=>t,u2=(t,e)=>({tag:t,_1:e}),Mu=t=>t,Uo=(t,e)=>({tag:t,_1:e}),zu=(t,e)=>({tag:t,_1:e}),Di=Mu("Animated"),c2=Mu("StaticStill"),g2=Mu("TitleCard"),_2=zu("First"),Y_=X_("Forward"),K_=X_("Backward"),f2=Uo("ExitNode"),j_=ce(P)(zt),d2=t=>Io(e=>n=>({nodes:Me(P.compare,Ie,e.nodes,n.nodes),edges:Me(P.compare,Ie,e.edges,n.edges)}))({nodes:I,edges:I})(t.keyframes),l2=t=>e=>({entering:{nodes:Vn(P.compare,e.nodes,t.nodes),edges:Vn(P.compare,e.edges,t.edges)},leaving:{nodes:Vn(P.compare,t.nodes,e.nodes),edges:Vn(P.compare,t.edges,e.edges)},surviving:{nodes:Ns(P.compare,Ie,t.nodes,e.nodes),edges:Ns(P.compare,Ie,t.edges,e.edges)}}),Gs=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Xo=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ps=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Wu=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},h2=T(t=>e=>rt(P)(e)()(t))(I),p2=T(t=>e=>rt(P)(e)()(t))(I),m2=(()=>{const t=nn.unfoldr(Qn);return e=>t(rn("IterNode",e,Fn))})(),Z_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},tf=ce(P)(zt),qu=t=>{const e=Ft(n=>J,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=T(r=>o=>({minX:Gs(r.minX)(o.x),minY:Gs(r.minY)(o.y),maxX:Xo(r.maxX)(o.x),maxY:Xo(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()},y2=t=>e=>n=>h2(St(Zt(fn.foldr,n))(r=>{const o=Ps(r)(t);if(o.tag==="Just")return ft(i=>!Wu(i)(e),[o._1.source,o._1.target]);if(o.tag==="Nothing")return[];g()})),x2=t=>t.kind.tag==="SendToken"?N("Just",b(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):J,w2=t=>t.tag==="DataFlow"?Tt(x2)(t._1.events):[],J2=t=>e=>p2(Tt(n=>Wu(n._2.source)(e)||Wu(n._2.target)(e)?N("Just",n._1):J)(m2(t))),sr=t=>{const e=Ft(n=>J,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=T(r=>o=>({minX:Gs(r.minX)(o.x),minY:Gs(r.minY)(o.y),maxX:Xo(r.maxX)(o.x+o.w),maxY:Xo(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()},Ou=t=>e=>n=>{if(n.tag==="Leaf")return he(t);const r=J2(e)(n),o=[...Tt(i=>{const s=Z_(i)(t.nodes);return s.tag==="Just"?N("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):J})(Zt(fn.foldr,Me(P.compare,Ie,n,y2(e)(n)(r)))),...Tt(i=>{const s=Ps(i)(t.edges);return s.tag==="Just"?N("Just",qu(s._1)):J})(Zt(fn.foldr,r))];return o.length===0?he(t):sr(o)},Bs=t=>e=>n=>{const r=[...Tt(o=>o)([(()=>{const o=Ps(n)(t.edges);return o.tag==="Just"?N("Just",qu(o._1)):J})()]),...(()=>{const o=Ps(n)(e);if(o.tag==="Just")return Tt(i=>{const s=Z_(i)(t.nodes);return s.tag==="Just"?N("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):J})([o._1.source,o._1.target]);if(o.tag==="Nothing")return[];g()})()];return r.length===0?Ou(t)(e)(I):sr(r)},Xr=t=>e=>{const n=he(t),r=n.w/Xo(1e-4)(e.zoom),o=n.h/Xo(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-o/2,w:r,h:o}},N2=t=>Me(P.compare,Ie,tf(O(e=>b(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),tf(St(t.scenes)(w2))),Hu=t=>t,T2=t=>t,ef=Hu("Linear"),Yr=Hu("EaseInOutQuad"),v2=Hu("SpringBouncy"),Ri=t=>e=>n=>{const r=Ve(1-e*e),o=t*r;return 1-Mo(-e*t*n)*(Ln(o*n)+e/r*pn(o*n))},C2=t=>{const e=ot.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ot.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Kr=t=>e=>(()=>{if(t==="Linear")return T2;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-yu(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*Mo(-6*n);if(t==="SpringBouncy")return Ri(6)(.7);g()})()(C2(e)),Ds=t=>t,nf=t=>t,rf=t=>t,yn=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ai=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Rs=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},b2=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?Be:n==="GT"?De:ot.compare(t._2)(e._2)},k2=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},L2=rf("Hold"),S2=rf("Gap"),ar=nf("LinearLerp"),of=nf("StagedLogLerp"),$u=Ds("Overview"),sf=Ds("DiveHome"),af=Ds("DiveTransition"),As=Ds("ActionFocus"),E2=t=>e=>n=>{const r=t.widthPx>0&&t.heightPx>0,o=t.widthPx/yn(1e-6)(t.heightPx),i=he(e),s=i.w/yn(1e-6)(n.zoom),a=i.h/yn(1e-6)(n.zoom),u=s/yn(1e-6)(a),c=r&&o<u?s/o:a,_=r&&o>u?a*o:s;return{x:n.center.x-_/2,y:n.center.y-c/2,w:_,h:c}},Vu=t=>e=>n=>{const r=n.center.y-e.center.y,o=n.center.x-e.center.x,i=Ve(o*o+r*r),s=n.zoom-e.zoom,a=s<0?-s:s;return Ai(t.minTransition)(t.maxTransition)(yn(t.panSpeed<=0?t.minTransition:i/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:a/t.zoomSpeed))},G2=t=>({startT:t.startT,endT:t.endT,fromCam:t.fromCam,toCam:t.toCam,easing:t.easing,interp:t.interp,intent:t.intent}),uf=t=>e=>Kr(Yr)(Ai(0)(1)((e-t)/yn(1e-4)(1-t))),cf=t=>e=>Kr(Yr)(Ai(0)(1)(e/yn(1e-4)(t))),P2=T(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:kt(t)(e)})([]),B2=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})()})()})()},D2=t=>e=>t.tag==="Just"?e.tag==="Just"&&B2(t._1)(e._1):t.tag==="Nothing"&&e.tag==="Nothing",gf=t=>e=>n=>r=>({center:{x:r.center.x*n.scale+n.tx,y:r.center.y*n.scale+n.ty},zoom:r.zoom*he(t).w/yn(1e-6)(n.scale*he(e).w)}),_f=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:Mo((()=>{const o=ws(yn(1e-6)(t.zoom));return o+(ws(yn(1e-6)(e.zoom))-o)*r})())}),R2=T(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()})(J),A2=t=>e=>n=>r=>{if(t<=0)return r;const o=Mo(-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:Mo((()=>{const i=ws(yn(1e-6)(r.zoom));return i+(ws(yn(1e-6)(n.zoom))-i)*o})())}},I2=t=>e=>n=>e.zoom>=t.zoom?uf(.18000000000000005)(n):cf(.82)(n),F2=t=>e=>n=>e.zoom>=t.zoom?cf(.28)(n):uf(.72)(n),Q2=t=>e=>n=>_f(t)(e)(F2(t)(e)(n))(I2(t)(e)(n)),M2=t=>e=>n=>{const r=n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT),o=Kr(n.easing)(Ai(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 _f(n.fromCam)(n.toCam)(o)(o);if(n.interp==="StagedLogLerp")return Q2(n.fromCam)(n.toCam)(r);g()},z2={widthPx:0,heightPx:0},W2={padding:24,easing:Yr,minimumReadableLabelPx:11,minimumVisibleLabelPx:5,labelBasePx:11,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:0},Yo=t=>e=>n=>r=>o=>{const i=E2(e)(n)(r),s=o.x-t.padding,a=o.y-t.padding;return s>=i.x&&a>=i.y&&s+o.w+t.padding*2<=i.x+i.w&&a+o.h+t.padding*2<=i.y+i.h},q2=t=>e=>n=>r=>o=>R_.foldlWithIndex(i=>s=>a=>{const u=(()=>{if(a.kind==="Hold"){const c=(()=>{if(i===0)return a.toCam;if(a.focus.tag==="Just"){if(a.intent==="ActionFocus")return Yo(t)(e)(n)(s.prev)(a.focus._1)?s.prev:Yo(t)(e)(n)({center:s.prev.center,zoom:a.toCam.zoom})(a.focus._1)?{...a.toCam,center:s.prev.center}:{...a.toCam,center:{...a.toCam.center,x:(()=>{const _=he(n).w/yn(1e-6)(a.toCam.zoom);if(_<=0)return a.toCam.center.x;const d=a.focus._1.x+a.focus._1.w/2,l=e.widthPx<=0?0:Rs(_/4)(6*_/e.widthPx),f=s.prev.center.x+_/2-l,h=d<s.prev.center.x-_/2+l?d-l+_/2:d>f?d+l-_/2:s.prev.center.x,p=he(n);return _>=p.w?p.x+p.w/2:Ai(p.x+_/2)(p.x+p.w-_/2)(h)})()}};if(Yo(t)(e)(n)(s.prev)(a.focus._1))return s.prev;if(Yo(t)(e)(n)({center:s.prev.center,zoom:a.toCam.zoom})(a.focus._1))return{...a.toCam,center:s.prev.center}}return a.toCam})();return{startT:a.startT,endT:a.endT,fromCam:c,toCam:c,easing:a.easing,interp:ar,focus:a.focus,intent:a.intent}}if(a.kind==="Gap")return{startT:a.startT,endT:a.endT,fromCam:s.prev,toCam:(()=>{const c=i+1|0,_=vr(Ut,J,d=>d.kind==="Hold",c<1?o:Bt(c,o.length,o));if(_.tag==="Just"){const d=(i+1|0)+_._1|0;return d>=0&&d<o.length?(()=>{if(o[d].focus.tag==="Just")return Yo(t)(e)(n)(s.prev)(o[d].focus._1);if(o[d].focus.tag==="Nothing")return!1;g()})()?s.prev:o[d].fromCam:s.prev}if(_.tag==="Nothing")return s.prev;g()})(),easing:a.easing,interp:ar,focus:J,intent:a.intent};g()})();return{acc:kt(s.acc)(u),prev:u.toCam}})({acc:[],prev:r})(o).acc,O2=t=>e=>n=>r=>o=>i=>{const s=(u,c)=>Rs(Vu(t)(u.toCam)(c.toCam))(u.endT-u.startT),a=T(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 Yo(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 d=u.pending._1.toCam.center.y-c.toCam.center.y;return(d<0?-d<8:d<8)&&(()=>{const l=u.pending._1.toCam.zoom-c.toCam.zoom;return l<0?-l<.08:l<.08})()})()})()||s(u.pending._1,c)<=0)return{acc:kt(u.acc)(u.pending._1),pending:N("Just",c)};if((()=>{const _=c.startT;return xe(d=>Qe(d-_)<1e-4,o)})()){const _={startT:c.startT,endT:c.startT+Rs(Vu(t)(u.pending._1.toCam)(c.toCam))(c.endT-c.startT),fromCam:u.pending._1.toCam,toCam:c.toCam,easing:c.easing,interp:ar,focus:c.focus,intent:c.intent},d={...c,startT:_.endT,fromCam:c.toCam};return d.startT<d.endT?{acc:kt(kt(u.acc)(u.pending._1))(_),pending:N("Just",d)}:{acc:kt(u.acc)(u.pending._1),pending:N("Just",_)}}return{acc:kt(kt(u.acc)({...u.pending._1,endT:c.startT-s(u.pending._1,c)}))({startT:c.startT-s(u.pending._1,c),endT:c.startT,fromCam:u.pending._1.toCam,toCam:c.toCam,easing:c.easing,interp:ar,focus:c.focus,intent:c.intent}),pending:N("Just",c)}}g()})({acc:[],pending:J})(i);if(a.pending.tag==="Nothing")return a.acc;if(a.pending.tag==="Just")return kt(a.acc)(a.pending._1);g()},H2=t=>e=>n=>{const r=e.w+n*2,o=e.h+n*2,i=he(t);return r<=0||o<=0||i.w<=0||i.h<=0?1:Rs(i.w/r)(i.h/o)},$2=t=>e=>{if(t.tag==="Just"){if(e.tag==="Just")return N("Just",sr([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 J}g()},V2=T(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?N("Just",t[n]):J;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")&&D2(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 s=r._1.toCam.zoom-e.toCam.zoom;return s<0?-s<.08:s<.08})()})()})()?kt((()=>{const o=t.length-1|0;return o<1?[]:Bt(0,o,t)})())({...r._1,endT:e.endT,focus:$2(r._1.focus)(e.focus)}):kt(t)(e)})([]),U2=t=>{const e=Pt(n=>r=>b2(b((()=>{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))(b((()=>{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]):J},Uu=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:yn(r)(H2(e)(n)(t.padding))}),X2=t=>e=>n=>r=>o=>i=>{const s=Uu(t)(n)(he(n))(0),a=ft(c=>c>=0&&c<=r,P2(Pt(ot.compare)([0,r,...o,...St(i)(c=>[c.startT,c.endT])]))),u=(c,_)=>xe(d=>d.priority>=1,ft(d=>d.startT<=_&&_<d.endT,i))?s2(t)(e)(n)(sr(c)).camera:Uu(t)(n)(sr(c))(0);return O(G2)(O2(t)(e)(n)(s)(o)(V2(q2(t)(e)(n)(s)(Tt(c=>{const _=(c._1+c._2)/2;if(c._2<=c._1)return J;const d=O(l=>l.bbox)(ft(l=>l.priority===T(k2)(0)(O(f=>f.priority)(ft(f=>f.startT<=_&&_<f.endT,i))),ft(l=>l.startT<=_&&_<l.endT,i)));return d.length===0?N("Just",{kind:S2,startT:c._1,endT:c._2,fromCam:s,toCam:s,easing:t.easing,focus:J,intent:$u}):N("Just",{kind:L2,startT:c._1,endT:c._2,fromCam:u(d,_),toCam:u(d,_),easing:t.easing,focus:N("Just",sr(d)),intent:xe(l=>l.priority>=1,ft(l=>l.startT<=_&&_<l.endT,i))?As:$u})})(Fe(An,a,Bt(1,a.length,a)))))))},Ii=t=>e=>n=>r=>{const o=U2(ft(i=>r>=i.startT&&r<i.endT,n));if(o.tag==="Just")return{camera:M2()(r)(o._1),intent:o._1.intent};if(o.tag==="Nothing"){const i=R2(n);return i.tag==="Just"&&r>=i._1.endT?{camera:i._1.toCam,intent:i._1.intent}:{camera:(()=>{const s=Uu(t)(e)(he(e))(0);return 0<n.length?n[0].fromCam:s})(),intent:0<n.length?n[0].intent:$u}}g()};function jr(t){return t.charCodeAt(0)}function ff(t){return String.fromCharCode(t)}const Mn=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},Sr=function(t){return function(e){return e.split(t)}},Is=function(t){return t.trim()},ur=function(t){return function(e){return e.join(t)}};var Y2=typeof Array.from=="function",K2=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",j2=typeof String.prototype.fromCodePoint=="function",Z2=typeof String.prototype.codePointAt=="function";const ty=function(t){return Z2?function(e){return e.codePointAt(0)}:t},ey=function(t){return j2?String.fromCodePoint:t},ny=function(t){return function(e){return K2?function(n){for(var r="",o=n[Symbol.iterator](),i=0;i<e;++i){var s=o.next();if(s.done)return r;r+=s.value}return r}:t(e)}},ry=function(t){return function(e){return Y2?function(n){return Array.from(n,e)}:t}},Fs=t=>{const e=ir(t);if(e===0)return J;if(e===1)return N("Just",{head:jr(Ei(0)(t)),tail:""});const n=jr(Ei(1)(t)),r=jr(Ei(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:Vo(2)(t)}):N("Just",{head:r,tail:Vo(1)(t)})},oy=t=>{const e=Fs(t);return e.tag==="Just"?N("Just",b(e._1.head,e._1.tail)):J},iy=t=>nn.unfoldr(oy)(t),df=ty(t=>{const e=jr(Ei(0)(t));if(55296<=e&&e<=56319&&ir(t)>1){const n=jr(Ei(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),Ko=ry(iy)(df),lf=t=>Ko(t).length,Xu=t=>Gi(t>=0&&t<=65535?ff(t):t<0?"\0":"\uFFFF"),sy=ey(t=>t<=65535?Xu(t):Xu(Tr(t-65536|0,1024)+55296|0)+Xu(Hr(t-65536|0)(1024)+56320|0)),hf=t=>e=>{if(t<1)return"";const n=Fs(e);return n.tag==="Just"?sy(n._1.head)+hf(t-1|0)(n._1.tail):e},Re=ny(hf),ay=t=>e=>e===""?J:N("Just",df(e)),pf=t=>t,Qs=(t,e)=>({tag:t,_1:e}),zn=(t,e,n)=>({tag:t,_1:e,_2:n}),mf=t=>t,jo=(t,e,n,r,o,i,s,a,u)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:s,_7:a,_8:u}),Yu=mf("PlopIn"),uy=mf("PlopOut"),cy=pf("DiveIn"),gy=pf("DiveOut"),Zo=(t,e,n)=>({tag:t,_1:e,_2:n}),_y=t=>t,ti=(t,e)=>({tag:t,_1:e}),Ku=t=>t,Ms=(t,e)=>({tag:t,_1:e}),ju=Ms("NotYet"),yf=Ms("Consumed"),fy=Ku("FromSource"),xf=Ku("FromTarget"),dy=Ku("FromBoth"),Zu=ti("Hidden"),ly=ti("Visible"),tc=_y("ExtendFromSource"),ec=Zo("Retracted"),wf=Zo("Extended"),hy={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},nc=t=>t,Jf=ce(P)(zt),Fi={eq:pu(vi)},rc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Er=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Nf=zt.foldMap(Bm(P)),py=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},my=(()=>{const t=nn.unfoldr(Qn);return e=>t(rn("IterNode",e,Fn))})(),ei=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},yy=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},xy=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},wy=ce(P)(zt),Jy=ce(P)(zt),Ny=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Tf=nc("Backdrop"),Ty=nc("FlyThrough"),dn=nc("Active"),vy=t=>e=>n=>({...n,state:{...n.state,edgeFadeAlpha:Jf(O(r=>b(r,e))(t))}}),vf=t=>e=>n=>{const r=(t+e)/2,o=n-r,i=o<0?-1:1,s=(e-t)/2,a=s*.15,u=s-a,c=o<0?-o:o;return e<=t?(t+e)/2:c<=u?n:r+i*(s-a*Mo(-(c-u)/a))},zs=t=>e=>n=>{const r=re(o=>Fi.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 re(o=>Fi.eq(o.path)(e))(t.segments);g()},Cy=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()},by=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:Qu,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:I}),ky=t=>O(e=>e<1?[]:Bt(0,e,t))(Kt(0,t.length-1|0)),oc=t=>e=>{const n=rc(e)(t.keyframes);if(n.tag==="Nothing")return I;if(n.tag==="Just")return n._1.nodes;g()},ic=t=>e=>{const n=rc(e)(t.keyframes);if(n.tag==="Nothing")return I;if(n.tag==="Just")return n._1.edges;g()},Ly=T(t=>e=>{const n=Cr(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?kt(n._1.init)({...n._1.last,endT:Er(n._1.last.endT)(e.endT),windows:kt(n._1.last.windows)(e)}):kt(t)({endT:e.endT,windows:[e]})})([]),Sy=t=>e=>n=>Nf(r=>Nf(o=>o.target.tag==="FillWindow"?o.startT<=n?te("Node",1,1,o.target._2,void 0,I,I):I:o.target.tag==="TokenWindow"&&o.startT+(o.endT-o.startT)*.25<=n?te("Node",1,1,o.target._4,void 0,I,I):I)(r.windows))(ft(r=>n<=r.endT+t,Ly(Pt(r=>o=>ot.compare(r.startT)(o.startT))(ft(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),Ey=t=>e=>n=>xe(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),Gy=t=>e=>n=>xe(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),Py=t=>e=>n=>xe(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),By=t=>e=>n=>xe(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),Ws=t=>e=>n=>re(r=>n(r)&&e>=r.startT&&e<r.endT)(t),qs=t=>e=>{if(e<t.startT)return zn("AtKeyframe",t.initialKeyframe);const n=re(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);g()}if(n.tag==="Nothing")return zn("AtKeyframe",T(Cy)(t.initialKeyframe)(t.spans));g()},Dy=t=>e=>{const n=qs(t)(e),r=rc((()=>{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 Di;g()},Ry=t=>e=>{const n=qs(t)(e);if(n.tag==="AtKeyframe")return Re(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return Re(3)(n._2)==="kf-"?"":n._2;g()},Ay={segment:{startT:0,endT:0,path:[],layout:{nodes:I,edges:I,chipExtras:I,edgeLabels:I},placement:Qu,windows:[],spans:[],keyframes:I,initialKeyframe:"",edgeEndpoints:I},state:{nodes:I,edges:I,tokens:I,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:Di,visited:I,nodeFadeAlpha:I,nodeLabelFadeAlpha:I,edgeFadeAlpha:I,nodeInvert:I},bgAlpha:1,blur:0,minis:[],role:dn},Os=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:Ay},Iy=t=>e=>{const n=py(e)(t.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1,o=i=>i.x>=r.x-1&&i.x<=r.x+r.w+1&&i.y>=r.y-1&&i.y<=r.y+r.h+1;return Tt(i=>(()=>{if(0<i._2.length){const a=i._2.length-1|0;return o(i._2[0])||a>=0&&a<i._2.length&&o(i._2[a])}const s=i._2.length-1|0;return s>=0&&s<i._2.length&&o(i._2[s])})()?N("Just",i._1):J)(my(t.edges))}g()},Fy=t=>e=>{const n=qs(t)(e);if(n.tag==="AtKeyframe")return oc(t)(n._1);if(n.tag==="InTransition")return Me(P.compare,Ie,oc(t)(n._1),oc(t)(n._2));g()},Qy=t=>e=>{const n=qs(t)(e);if(n.tag==="AtKeyframe")return ic(t)(n._1);if(n.tag==="InTransition")return Me(P.compare,Ie,ic(t)(n._1),ic(t)(n._2));g()},My=t=>e=>n=>{const r=he(t),o=r.h/Er(1e-4)(n.zoom),i=r.w/Er(1e-4)(n.zoom);return{...n,center:{x:i>=e.w?e.x+e.w/2:vf(e.x+i/2)(e.x+e.w-i/2)(n.center.x),y:o>=e.h?e.y+e.h/2:vf(e.y+o/2)(e.y+e.h-o/2)(n.center.y)}}},zy=t=>e=>n=>My(t)((()=>{const r=e*n.placement.scale,o=he(n.layout),i=(()=>{const s=o.x*n.placement.scale+n.placement.tx,a=o.y*n.placement.scale+n.placement.ty;return{x:s,y:a,w:(o.x+o.w)*n.placement.scale+n.placement.tx-s,h:(o.y+o.h)*n.placement.scale+n.placement.ty-a}})();return{x:i.x-r,y:i.y-r,w:i.w+r*2,h:i.h+r*2}})()),Wy=t=>e=>{const n=t.endT-t.startT;return n<=0?1:Er(0)(ei(1)((e-t.startT)/n))},ni=t=>e=>{const n=t.endT-t.startT;return n<=0?1:Er(0)(ei(1)((e-t.startT)/n))},qy=t=>e=>n=>r=>o=>{const i=Ws(e)(n)(s=>s.target.tag==="EdgeWindow"&&s.target._2.tag==="Retract"&&s.target._1===o);if(i.tag==="Just"){const s=Kr(t.timing.edgeEasing)(ni(i._1)(n)),a=i._1.target.tag==="EdgeWindow"?i._1.target._2:Qs("Extend",tc);if(a.tag==="Retract")return Zo("Retracting",a._1,s);if(a.tag==="Extend")return Zo("Extending",a._1,s);g()}if(i.tag==="Nothing"){if(Ey(e)(n)(o))return ec;const s=Ws(e)(n)(a=>a.target.tag==="EdgeWindow"&&a.target._1===o);if(s.tag==="Just"){const a=Kr(t.timing.edgeEasing)(ni(s._1)(n)),u=s._1.target.tag==="EdgeWindow"?s._1.target._2:Qs("Extend",tc);if(u.tag==="Retract")return Zo("Retracting",u._1,a);if(u.tag==="Extend")return Zo("Extending",u._1,a);g()}if(s.tag==="Nothing")return By(e)(n)(o)?ec:yy(o)(r)?wf:ec}g()},Oy=t=>e=>n=>{const r=Qy(e)(n);return Jf(O(o=>b(o,qy(t)(e.windows)(n)(r)(o)))((()=>{const o=i=>{if(i.tag==="Leaf")return I;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,void 0,o(i._5),o(i._6));g()};return Zt(fn.foldr,o(e.layout.edges))})()))},Hy=t=>e=>n=>r=>{const o=Ws(t)(e)(i=>i.target.tag==="NodeWindow"&&i.target._1===r&&i.target._2==="PlopOut");if(o.tag==="Just"){const i=ni(o._1)(e),s=o._1.target.tag==="NodeWindow"?o._1.target._2:Yu;if(s==="PlopIn")return ti("PloppingIn",i);if(s==="PlopOut")return ti("PloppingOut",i);g()}if(o.tag==="Nothing"){if(Gy(t)(e)(r))return Zu;const i=Ws(t)(e)(s=>s.target.tag==="NodeWindow"&&s.target._1===r);if(i.tag==="Just"){const s=ni(i._1)(e),a=i._1.target.tag==="NodeWindow"?i._1.target._2:Yu;if(a==="PlopIn")return ti("PloppingIn",s);if(a==="PlopOut")return ti("PloppingOut",s);g()}if(i.tag==="Nothing")return Py(t)(e)(r)?Zu:xy(r)(n)?ly:Zu}g()},$y=t=>e=>{const n=Fy(t)(e);return wy(O(r=>b(r,Hy(t.windows)(e)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return I;if(o.tag==="Node")return te("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));g()};return Zt(fn.foldr,r(t.layout.nodes))})()))},Vy=t=>e=>n=>e.target.tag==="TokenWindow"?b(e.target._1,n<e.startT?ju:n>=e.endT?yf:Ms("Travelling",{edge:e.target._2,direction:e.target._3,progress:Kr(t.timing.tokenEasing)(ni(e)(n)),labels:e.target._6,source:e.target._4,target:e.target._5,holdPre:e.target._7,holdPost:e.target._8})):e.target.tag==="FillWindow"?b(e.target._1,n<e.startT?ju:n>=e.endT?yf:Ms("Filling",{node:e.target._2,progress:ni(e)(n),labels:e.target._3})):b("",ju),Uy=t=>e=>n=>Jy(O(r=>Vy(t)(r)(n))(ft(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),Xy=t=>e=>n=>({nodes:$y(e)(n),edges:Oy(t)(e)(n),tokens:Uy(t)(e.windows)(n),camera:Ii(t.cameraConfig)(e.layout)(t.cameraSpans)(n).camera,frameTitle:Ry(e)(n),staticKind:Dy(e)(n),visited:Sy(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:I,nodeLabelFadeAlpha:I,edgeFadeAlpha:I,nodeInvert:I}),ri=t=>e=>n=>r=>({segment:n,state:Xy(t)(n)(e),bgAlpha:1,blur:0,minis:Yy(t)(e)(n),role:r}),Yy=t=>e=>n=>Tt(r=>{const o=zs(t)(kt(n.path)(r))(e);if(o.tag==="Just")return N("Just",{...ri(t)(Ny(o._1.startT)(o._1.endT-1e-4)(e))(o._1)(Tf),bgAlpha:0});if(o.tag==="Nothing")return J;g()})((()=>{const r=o=>{if(o.tag==="Leaf")return I;if(o.tag==="Node")return te("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));g()};return Zt(fn.foldr,r(n.layout.nodes))})()),Ky=t=>e=>n=>d_(J,a_,r=>r.direction==="DiveIn"&&Fi.eq(r.parentPath)(e.path)&&n>=r.startT-.7&&n<r.startT?N("Just",{node:r.node,phase:(n-(r.startT-.7))/.7}):J,t.dives),jy=t=>e=>n=>r=>{const o=Ky(t)(e)(n);if(o.tag==="Just"){const i=pn(3.141592653589793*o._1.phase*3);return{...r,state:{...r.state,nodeInvert:te("Node",1,1,o._1.node,1*i*i,I,I)}}}if(o.tag==="Nothing")return r;g()},Cf=t=>e=>Tt(n=>{const r=re(o=>o.direction==="DiveIn"&&Fi.eq(o.childPath)((()=>{const i=n.length+1|0;return i<1?[]:Bt(0,i,e)})()))(t.dives);if(r.tag==="Just"){const o=zs(t)(n)(r._1.startT-1e-4);if(o.tag==="Just")return N("Just",(()=>{const i=ri(t)(r._1.startT-1e-4)(o._1)(Tf);return{...i,state:{...i.state,nodeFadeAlpha:te("Node",1,1,r._1.node,0,I,I)}}})());if(o.tag==="Nothing")return J;g()}if(r.tag==="Nothing")return J;g()})(ky(e)),bf=t=>e=>{const n=ft(o=>e>=o.startT&&e<o.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:by(t)},Zy=t=>e=>n=>{const r=Wy(n)(e),o=zs(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),i=zs(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),s=(()=>{if(n.direction==="DiveIn")return Kr(Yr)(r);if(n.direction==="DiveOut")return 1-Kr(Yr)(r);g()})(),a=1-Er(0)(ei(1)((s-.1)/.25)),u=1-Er(0)(ei(1)((s-.1)/.25)),c=1-Er(0)(ei(1)((s-.8)/.2)),_=l=>{const f=ri(t)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})())(l)(Ty);return{...vy(Iy(l.layout)(n.node))(u)({...f,state:{...f.state,nodeFadeAlpha:te("Node",1,1,n.node,a,I,I),nodeLabelFadeAlpha:te("Node",1,1,n.node,u,I,I)}}),minis:ft(h=>!Fi.eq(h.segment.path)(n.childPath),f.minis),bgAlpha:c}},d=0+1*Er(0)(ei(1)((s-.1)/.5));return[...Cf(t)(n.parentPath),...(()=>{if(o.tag==="Just"){if(i.tag==="Just")return[_(o._1),{...ri(t)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})())(i._1)(dn),bgAlpha:d}];if(i.tag==="Nothing")return[_(o._1)];g()}if(o.tag==="Nothing")return[ri(t)(e)(bf(t)(e))(dn)];g()})()]},tx=t=>e=>re(n=>e>=n.startT&&e<n.endT)(t.dives),ex=t=>e=>{const n=bf(t)(e),r=ri(t)(e)(n)(dn),o=t.dives.length!==0,i=Ii(t.cameraConfig)(t.layout)(t.cameraSpans)(e).camera,s=zy(t.layout)(t.cameraConfig.padding)(n)(i),a=jy(t)(n)(e)({...r,state:{...r.state,camera:s}}),u=Cf(t)(n.path),c=tx(t)(e);if(c.tag==="Just")return{levels:Zy(t)(e)(c._1),camera:i,rootLayout:t.layout,hasDives:o,diving:!0};if(c.tag==="Nothing")return{levels:kt(u)(a),camera:s,rootLayout:t.layout,hasDives:o,diving:!1};g()},nx=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},rx=t=>{const e=t.length;return(n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=i;if(u>=e){s=!1,a=c;continue}const _=d=>l=>{let f=d,h=l,p=!0,m;for(;p;){const w=f,y=h;if(w>=e){p=!1,m=y;continue}if(u>=0&&u<t.length){if(w>=0&&w<t.length){f=w+1|0,h=(()=>{const x=t[u].position,v=t[u].size,C=t[w].position,L=t[w].size;return x._1<C._1+L._1&&C._1<x._1+v._1&&x._2<C._2+L._2&&C._2<x._2+v._2})()?y+1|0:y;continue}f=w+1|0,h=y;continue}p=!1,m=y}return m};o=u+1|0,i=_(u+1|0)(c)}return a})(0)(0)},kf=t=>T(e=>n=>e+Hm(n.start)(n.end))(0)(t.segments),ox=t=>e=>n=>({crossingCount:T(r=>o=>r+o.jumps.length|0)(0)(e),bendCount:T(r=>o=>r+o.bends.length|0)(0)(e),totalEdgeLength:T(r=>o=>r+kf(o))(0)(e),maxEdgeLength:T(r=>o=>nx(r)(kf(o)))(0)(e),nodeOverlapCount:rx(t),constraintViolations:n,jumpCount:T(r=>o=>r+o.jumps.length|0)(0)(e)}),sc=t=>t,ue=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ac=sc("LEFT"),ix=sc("RIGHT"),Lf=sc("UNDEFINED"),sx={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},ax={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?Ye:Be;if(e==="LEFT")return De;if(t==="RIGHT")return e==="RIGHT"?Ye:Be;if(e==="RIGHT")return De;if(t==="UP")return e==="UP"?Ye:Be;if(e==="UP")return De;if(t==="DOWN")return e==="DOWN"?Ye:Be;if(e==="DOWN")return De;if(t==="UNDEFINED"&&e==="UNDEFINED")return Ye;g()},Eq0:()=>sx},ux=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},cx={x:0,y:0},xn=t=>e=>n=>{const r=ue(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:rt(it)(t)(e(r._1))(n.cNodes)};g()},Qi=t=>e=>n=>{const r=ue(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:rt(it)(t)(e(r._1))(n.cGroups)};g()},gx=t=>T(e=>n=>xn(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),_x=t=>{const e=T(n=>r=>{const o=ue(r)(t.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just")return T(i=>s=>Qt(it)(le)(s)([r])(i))(n)(o._1.constraints);g()})(I)(t.cNodeOrder);return T(n=>r=>xn(r)(o=>({...o,constraints:(()=>{const i=ue(r)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;g()})()}))(n))(t)(t.cNodeOrder)},fx=t=>e=>xn(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}})),dx=t=>{const e=T(n=>r=>Qi(r)(o=>({...o,outDegree:o.outDegreeReal}))(n))(t)(t.cGroupOrder);return T(n=>r=>xn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder)},Wn={left:!1,right:!1,up:!1,down:!1},lx={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},uc=t=>T(e=>n=>{const r=ue(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const o=T(s=>a=>{const u=ue(a)(e.cNodes);if(u.tag==="Nothing")return s;if(u.tag==="Just"){if(s.tag==="Nothing")return N("Just",a);if(s.tag==="Just"){const c=ue(s._1)(e.cNodes);if(c.tag==="Nothing")return N("Just",a);if(c.tag==="Just")return u._1.hitbox.x<c._1.hitbox.x?N("Just",a):N("Just",s._1)}}g()})(J)(r._1.cNodes),i=Qi(n)(s=>({...s,reference:o}))(e);if(o.tag==="Nothing")return i;if(o.tag==="Just"){const s=ue(o._1)(i.cNodes);if(s.tag==="Nothing")return i;if(s.tag==="Just"){const a=s._1;return T(u=>c=>xn(c)(_=>({..._,cGroupOffset:{x:_.hitbox.x-a.hitbox.x,y:_.hitbox.y-a.hitbox.y}}))(u))(i)(r._1.cNodes)}}}g()})(t)(t.cGroupOrder),wn=t=>uc({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return I;if(n.tag==="Node")return te("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)})()}),cr=t=>uc({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return I;if(n.tag==="Node")return te("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)})()}),Sf=t=>{const e=T(n=>r=>Qi(r)(o=>({...o,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return T(n=>r=>{const o=ue(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 T(s=>a=>{const u=ue(a)(s.cNodes);if(u.tag==="Nothing")return s;if(u.tag==="Just")return u._1.cGroup.tag==="Just"&&u._1.cGroup._1!==i?Qi(u._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(Qi(i)(c=>en(qr)(a)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,a]})(s)):s;g()})(n)(o._1.constraints)}}g()})(e)(e.cNodeOrder)},Hs=t=>{const e=_x(t.cGraph);return{...t,cGraph:Sf(T(n=>r=>xn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},hx=t=>e=>T(n=>r=>{if(t==="LEFT"||t==="UP"){const i=r._2;return xn(r._1)(s=>({...s,constraints:[...s.constraints,i]}))(n)}const o=r._1;return xn(r._2)(i=>({...i,constraints:[...i.constraints,o]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),qn=t=>{const e={...t,cGraph:hx(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return I;if(r.tag==="Node")return te("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:Sf((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);g()})())}},px=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?qn(r):e==="RIGHT"?qn({...r,cGraph:wn(r.cGraph)}):e==="UP"?qn({...r,cGraph:cr(r.cGraph)}):e==="DOWN"?qn({...r,cGraph:wn(cr(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?Hs({...r,cGraph:wn(r.cGraph)}):e==="UP"?qn({...r,cGraph:cr(r.cGraph)}):e==="DOWN"?qn({...r,cGraph:wn(cr(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?Hs({...r,cGraph:wn(r.cGraph)}):e==="UP"?qn({...r,cGraph:cr(wn(r.cGraph))}):e==="DOWN"?qn({...r,cGraph:wn(cr(wn(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?qn({...r,cGraph:cr(r.cGraph)}):e==="RIGHT"?qn({...r,cGraph:wn(cr(r.cGraph))}):e==="DOWN"?Hs({...r,cGraph:wn(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?qn({...r,cGraph:cr(wn(r.cGraph))}):e==="RIGHT"?qn({...r,cGraph:wn(cr(wn(r.cGraph)))}):e==="UP"?Hs({...r,cGraph:wn(r.cGraph)}):r;g()},Ef=t=>e=>e.finished||!ux(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:px(e.direction)(t)(e),mx=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?Ef(ac)(t):t,n={...e,cGraph:dx(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},Gf=t=>e=>n=>{const r=ue(t)(n.cNodes),o=ue(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:rt(it)(t)({...r._1,cGroup:N("Just",e)})(n.cNodes),cGroups:rt(it)(e)({...o._1,cNodes:en(qr)(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},Pf=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:rt(it)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:J,cGroupOffset:cx,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:Wn})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),cc=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:T(r=>o=>Gf(o)(n)(r))({...e,cGroups:rt(it)(n)({id:n,master:t.master,cNodes:[],startPos:-1e308,incomingConstraints:[],outDegree:0,outDegreeReal:0,reference:J,delta:0,deltaNormalized:0})(e.cGroups),cGroupOrder:[...e.cGroupOrder,n],nextCGroupId:n+1|0})(t.nodes)}},yx=t=>T(e=>n=>{const r=ue(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?cc({master:J,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),xx=t=>({cGraph:gx(yx(uc(t))),direction:Lf,compactionAlgorithm:J,constraintAlgorithm:J,spacingsHandler:lx,lockFun:J,finished:!1}),wx=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jx=t=>e=>{const n=ot.compare(t._1)(e._1);return n==="LT"?Be:n==="GT"?De:it.compare(t._2)(e._2)},Nx=(()=>{const t=nn.unfoldr(Qn);return e=>t(rn("IterNode",e,Fn))})(),Bf=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Df=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",Rf=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),$s=t=>e=>Jx(b(t.hitbox.x+t.hitbox.width/2,t.id))(b(e.hitbox.x+e.hitbox.width/2,e.id)),Tx=t=>e=>{const n=vr(Ut,J,r=>$s(t)(r)==="LT",e);if(n.tag==="Just"){const r=l_(Ut,J,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return kt(e)(t);g()},Af=t=>e=>{const n=ft(o=>$s(o)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?N("Just",n[r]):J},vx=t=>e=>{const n=Tx(e)(t.intervals),r=re(i=>$s(e)(i)==="LT")(n),o=rt(it)(e.id)((()=>{const i=Af(e)(n);return i.tag==="Just"?N("Just",i._1.id):J})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return rt(it)(r._1.id)(N("Just",e.id))(o);if(r.tag==="Nothing")return o;g()})()}},Cx=t=>e=>{const n=ot.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?De:Ye:e.low?Be:Ye:n},bx=t=>T(e=>n=>xn(n.id)(r=>({...r,constraints:[]}))(e))(t)(Tt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),gc=t=>e=>T(n=>r=>{const o=ue(r._1)(n.cNodes);if(o.tag==="Just")return xn(r._1)(i=>({...i,constraints:[...i.constraints,...r._2]}))(n);if(o.tag==="Nothing")return n;g()})(e)(Nx(t)),If=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}},Ff=t=>e=>n=>T(r=>o=>n(o)?xn(o.id)(If(t))(r):r)(e)(Tt(r=>ue(r)(e.cNodes))(e.cNodeOrder)),kx=t=>e=>{const n=(r,o,i)=>{const s=xn(i)(If(t))(r);return o.length<=1?s:T(a=>u=>u===i?a:xn(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)(a))(s)(o)};return T(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)(Tt(r=>ue(r)(e.cGroups))(e.cGroupOrder))},Lx=t=>e=>{const n=Af(e)(t.intervals),r=re(i=>$s(e)(i)==="LT")(t.intervals),o=n.tag==="Just"&&(()=>{const i=Bf(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})()?Qt(it)(le)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const i=Bf(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})()?Qt(it)(le)(e.id)([r._1.id])(o):o,intervals:ft(i=>i.id!==e.id,t.intervals)}},Sx=t=>e=>e.low?vx(t)(e.node):Lx(t)(e.node),_c=t=>e=>T(Sx)({intervals:[],cand:I,constraints:I})(Pt(Cx)(St(ft(t,Tt(n=>ue(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,Ex=t=>e=>{const n=wx(0)(t/2-.5),r=gc(_c(Df)(Ff(n)(e)(Df)))(e),o=gc(_c(Rf)(Ff(n)(r)(Rf)))(r);return gc(_c(i=>!0)(kx(n)(o)))(o)},Gx=t=>e=>Ex(t)(bx(e.cGraph)),Vs=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Qf=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fc=t=>e=>n=>r=>o=>({id:t,representedEdges:[o],affectedBends:[e,n],hitbox:{x:Vs(e._1)(n._1),y:Vs(e._2)(n._2),width:Qe(e._1-n._1),height:Qe(e._2-n._2)},ignoreSpacing:Wn,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:J}),Px=t=>e=>{const n=Vs(t.hitbox.x)(e.hitbox.x),r=Vs(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:Qf(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Qf(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()})()}},Bx=t=>e=>Qe(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,Dx=t=>e=>Qe(t.hitbox.x-e.hitbox.x)<=1e-4?ot.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?Be:De,Mf=(t,e)=>({tag:t,_1:e}),dc=ce(P)(zt),Us=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},zf=(()=>{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 Be;if(o==="GT")return De;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?Ye:Be;if(r._2.tag==="Nothing")return De;if(n._2.tag==="Just"&&r._2.tag==="Just")return P.compare(n._2._1)(r._2._1);g()},Eq0:()=>t};return T(n=>r=>rt(e)(r)()(n))(I)})(),Gr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Rx=T(t=>e=>rt(ax)(e)()(t))(I),lc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=W_.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Ax=t=>e=>{const n=dc(O(i=>b(i.id,i))(t)),r=Tt(i=>Us(i)(n))(e),o=it.compare((()=>{const i=zf(O(s=>b(s.from.node,s.from.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;g()})())((()=>{const i=zf(O(s=>b(s.to.node,s.to.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;g()})());if(o==="LT")return{...Wn,left:!0,right:!1};if(o==="GT")return{...Wn,left:!1,right:!0};if(o==="EQ")return Wn;g()},Ix=t=>Tt(e=>{if(e.direction==="V")return N("Just",{start:e.start,end:e.end});if(e.direction==="H")return J;g()})(t.segments),Xs=t=>e=>n=>r=>{if(r.tag==="Just"){const o=Gr(n)(e);if(o.tag==="Just"){const i=re(s=>s.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()},Fx=t=>e=>n=>{const r=Pf({origin:N("Just",Mf("SegmentOrigin",n)),kind:N("Just","vs"),hitbox:n.hitbox})(e.cGraph),o=fx(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const i=ue(n.potentialGroupParents[0])(o.cNodes);if(i.tag==="Just"){if(i._1.cGroup.tag==="Just")return Gf(r.id)(i._1.cGroup._1)(o);if(i._1.cGroup.tag==="Nothing")return o;g()}if(i.tag==="Nothing")return o;g()}return cc({master:N("Just",r.id),nodes:[r.id]})(o).graph})(),edgeToCs:T(i=>s=>Qt(P)(le)(s)([r.id])(i))(e.edgeToCs)(n.representedEdges),lockMap:rt(it)(r.id)(Ax(t)(n.representedEdges))(e.lockMap)}},Qx=t=>e=>n=>{const r=Ft(o=>J,o=>i=>N("Just",{head:o,tail:i}),Pt(Dx)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const o=T(i=>s=>Bx(i.survivor)(s)?{...i,survivor:Px(i.survivor)(s)}:{survivor:s,merged:[...i.merged,i.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return T(Fx(t))(n)([...o.merged,o.survivor])}g()},Mx=t=>({cGraph:{cNodes:I,cNodeOrder:[],cGroups:I,cGroupOrder:[],supportedDirections:Rx([Lf,ac,ix]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:I,edgeToCs:I,lockMap:I}),zx=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}},Wx=t=>e=>n=>T(r=>o=>{const i=Pf({origin:N("Just",Mf("NodeOrigin",o.node)),kind:J,hitbox:zx(o)})(r.cGraph),s=Gr(o.node)(t),a=(()=>{if(s.tag==="Nothing")return b(0,0);if(s.tag==="Just")return s._1;g()})();return{...r,cGraph:cc({master:N("Just",i.id),nodes:[i.id]})(i.graph).graph,nodeToC:rt(P)(o.node)(i.id)(r.nodeToC),lockMap:rt(it)(i.id)((()=>{const u=a._1-a._2|0;return u<0?{...Wn,left:!0}:u>0?{...Wn,right:!0}:Wn})())(r.lockMap)}})(n)(e),qx=t=>T(e=>n=>Qt(P)(r=>o=>b(r._1+o._1|0,r._2+o._2|0))(n.to.node)(b(1,0))(Qt(P)(r=>o=>b(r._1+o._1|0,r._2+o._2|0))(n.from.node)(b(0,1))(e)))(I)(t),Ox=t=>T(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?rt(P)(n.origin._1._1)(n.hitbox.x)(e):e)(I)(Tt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),Hx=t=>T(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?rt(P)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(I)(Tt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),$x=t=>T(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return T(o=>i=>rt(W_)(i)(r)(o))(e)(n.origin._1._1.affectedBends)}return e})(I)(Tt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),Wf=t=>{const e=dc(O(n=>b(n.id,n))(t.edges));return Tt(n=>{const r=Us(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:Xs(kr)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:Xs(Lr)(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:Xs(kr)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:Xs(Lr)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return J;g()})(t.paths)},Vx=t=>e=>{const n=St(e)(r=>{if(r.src===r.tgt)return[];if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return[];const o=Gr(r.tgt)(t.nodeToC),i=(()=>{if(o.tag==="Just")return ue(o._1)(t.cGraph.cNodes);if(o.tag==="Nothing")return J;g()})(),s=Gr(r.src)(t.nodeToC),a=(()=>{if(s.tag==="Just")return ue(s._1)(t.cGraph.cNodes);if(s.tag==="Nothing")return J;g()})(),u=(()=>{if(a.tag==="Just"){if(i.tag==="Just"){if(a._1.cGroup.tag==="Just"){if(i._1.cGroup.tag==="Just")return N("Just",{srcGroup:a._1.cGroup._1,tgtGroup:i._1.cGroup._1,delta:0,weight:100});if(i._1.cGroup.tag==="Nothing")return J;g()}if(a._1.cGroup.tag==="Nothing")return J;g()}if(i.tag==="Nothing")return J;g()}if(a.tag==="Nothing")return J;g()})(),c=f=>h=>p=>{if(a.tag==="Just"){if(a._1.cGroup.tag==="Just"){if(p.cGroup.tag==="Just")return f(p.hitbox.x)&&p.cGroup._1!==a._1.cGroup._1?N("Just",h(p.cGroup._1)(a._1.cGroup._1)):J;if(p.cGroup.tag==="Nothing")return J;g()}if(a._1.cGroup.tag==="Nothing")return J;g()}if(a.tag==="Nothing")return J;g()},_=Tt(f=>ue(f)(t.cGraph.cNodes))((()=>{const f=Us(r.edgeId)(t.edgeToCs);if(f.tag==="Nothing")return[];if(f.tag==="Just")return f._1;g()})()),d=(()=>{if(a.tag==="Just"&&r.srcSide==="West"){const f=a._1;return Tt(c(h=>h<f.hitbox.x)(h=>p=>({srcGroup:h,tgtGroup:p,delta:1,weight:100})))(_)}return[]})(),l=(()=>{if(a.tag==="Just"&&r.tgtSide==="East"){const f=a._1;return Tt(c(h=>h>f.hitbox.x)(h=>p=>({srcGroup:p,tgtGroup:h,delta:1,weight:100})))(_)}return[]})();if(u.tag==="Nothing")return[];if(u.tag==="Just")return[u._1,...d,...l];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 xe(s=>en(tr)(s)(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}},Ux=t=>e=>{const n=nt(4),r=Ox(t),o=Hx(t),i=dc(O(a=>b(a.id,b(a.from.node,a.to.node)))(e.edges)),s=$x(t);return{nodes:O(a=>{const u=Gr(a.node)(r);if(u.tag==="Just")return{...a,position:b(u._1/n,a.position._2)};if(u.tag==="Nothing")return a;g()})(e.nodes),edges:O(a=>{const u=Us(a.edge)(i),c=(()=>{if(u.tag==="Nothing")return a.segments;if(u.tag==="Just"){const _=Gr(u._1._1)(o),d=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;g()})(),l=Gr(u._1._2)(o),f=(()=>{if(l.tag==="Nothing")return 0;if(l.tag==="Just")return l._1;g()})();return Ht((()=>{const h=a.reversed?f:d,p=a.reversed?d:f,m=a.segments.length;return w=>y=>{if(y.direction==="V"){const x=(()=>{if(w===0)return h;if(w===(m-1|0))return p;const v=lc(y.start)(s);if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})();return{...y,start:b(y.start._1+x,y.start._2),end:b(y.end._1+x,y.end._2)}}if(y.direction==="H")return{...y,start:b((()=>{if(w===0)return y.start._1+h;const x=lc(y.start)(s);if(x.tag==="Nothing")return y.start._1+0;if(x.tag==="Just")return y.start._1+x._1;g()})(),y.start._2),end:b((()=>{if(w===(m-1|0))return y.end._1+p;const x=lc(y.end)(s);if(x.tag==="Nothing")return y.end._1+0;if(x.tag==="Just")return y.end._1+x._1;g()})(),y.end._2)};g()}})())(a.segments)}g()})();return{...a,segments:c,bends:Fe(_=>d=>_.end,c,Bt(1,c.length,c))}})(e.paths)}},Xx=t=>e=>n=>r=>o=>i=>{const s=fc(o.nextId)(i._2.start)(i._2.end)(J)(t.edgeId),a=(()=>{if(i._1===0){if(e.tag==="Nothing")return s;if(e.tag==="Just")return{...s,ignoreSpacing:i._2.end._2<e._1.y?{...s.ignoreSpacing,down:!0}:i._2.end._2>e._1.y+e._1.height?{...s.ignoreSpacing,up:!0}:{...s.ignoreSpacing,up:!0,down:!0}};g()}return s})();return{nextId:o.nextId+1|0,segments:[...o.segments,(()=>{if(i._1===r){if(n.tag==="Nothing")return a;if(n.tag==="Just")return{...a,ignoreSpacing:i._2.start._2<n._1.y?{...a.ignoreSpacing,down:!0}:i._2.start._2>n._1.y+n._1.height?{...a.ignoreSpacing,up:!0}:{...a.ignoreSpacing,up:!0,down:!0}};g()}return a})()]}},qf=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...fc(i.nextId)(r.start)(b(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?{...Wn,down:!0}:{...Wn,up:!0}}]}),Ys=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...fc(i.nextId)(r.end)(b(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?{...Wn,down:!0}:{...Wn,up:!0}}]}),Yx=t=>e=>n=>{if(n.src===n.tgt)return e;const r=Gr(n.src)(t.nodeToC),o=Gr(n.tgt)(t.nodeToC),i=(()=>{if(r.tag==="Just"){const _=ue(r._1)(t.cGraph.cNodes);return _.tag==="Just"?N("Just",_._1.hitbox):J}if(r.tag==="Nothing")return J;g()})(),s=(()=>{if(o.tag==="Just"){const _=ue(o._1)(t.cGraph.cNodes);return _.tag==="Just"?N("Just",_._1.hitbox):J}if(o.tag==="Nothing")return J;g()})(),a=Ix(n.path),u=T(Xx(n)(i)(s)(a.length-1|0))(e)(Ht(_=>d=>b(_,d))(a));if(0<a.length){const _=(()=>{if(r.tag==="Just"&&i.tag==="Just"){if(n.srcSide==="North")return qf(n)(r._1)(i._1)(a[0])({side:Le,down:!0})(u);if(n.srcSide==="South")return qf(n)(r._1)(i._1)(a[0])({side:Se,down:!1})(u)}return u})(),d=a.length-1|0;if(d>=0&&d<a.length&&o.tag==="Just"&&s.tag==="Just"){if(n.tgtSide==="North")return Ys(n)(o._1)(s._1)(a[d])({side:Le,down:!0})(_);if(n.tgtSide==="South")return Ys(n)(o._1)(s._1)(a[d])({side:Se,down:!1})(_)}return _}const c=a.length-1|0;if(c>=0&&c<a.length&&o.tag==="Just"&&s.tag==="Just"){if(n.tgtSide==="North")return Ys(n)(o._1)(s._1)(a[c])({side:Le,down:!0})(u);if(n.tgtSide==="South")return Ys(n)(o._1)(s._1)(a[c])({side:Se,down:!1})(u)}return u},Kx=t=>e=>n=>Qx(t)(T(Yx(n))({nextId:0,segments:[]})(e).segments)(n),jx=t=>Kx(t.edges)(Wf(t))(Wx(qx(t.edges))(t.nodes)(Mx())),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 s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},hc=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},pc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Zx=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},tw=t=>{const e=t.Eq0();return n=>r=>{const o=a=>{let u=a,c=!0,_;for(;c;){const d=u,l=Ft(f=>J,f=>h=>N("Just",{head:f,tail:h}),d.queue);if(l.tag==="Nothing"){c=!1,_=d;continue}if(l.tag==="Just"){const f=l._1.head;if((p=>{let m=p,w=!0,y;for(;w;){const x=m;if(x.tag==="Leaf"){w=!1,y=!1;continue}if(x.tag==="Node"){const v=t.compare(f)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){w=!1,y=!0;continue}}g()}return y})(d.removedNodes)){u={...d,queue:l._1.tail};continue}const h=re(p=>!Pr(p.eid)(d.removedEdges)&&(e.eq(p.src)(f)||e.eq(p.tgt)(f)))(r);if(h.tag==="Nothing"){u={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const p=e.eq(h._1.src)(f)?h._1.tgt:h._1.src,m={...d,degree:rt(t)(p)((()=>{const w=(y=>{let x=y,v=!0,C;for(;v;){const L=x;if(L.tag==="Leaf"){v=!1,C=J;continue}if(L.tag==="Node"){const E=t.compare(p)(L._3);if(E==="LT"){x=L._5;continue}if(E==="GT"){x=L._6;continue}if(E==="EQ"){v=!1,C=N("Just",L._4);continue}}g()}return C})(d.degree);if(w.tag==="Nothing")return-1;if(w.tag==="Just")return w._1-1|0;g()})())(d.degree),removedNodes:rt(t)(f)()(d.removedNodes),removedEdges:rt(it)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:f,neighbour:p,viaSrc:e.eq(h._1.src)(f)}],queue:l._1.tail};if((()=>{const w=(x=>{let v=x,C=!0,L;for(;C;){const E=v;if(E.tag==="Leaf"){C=!1,L=J;continue}if(E.tag==="Node"){const B=t.compare(p)(E._3);if(B==="LT"){v=E._5;continue}if(B==="GT"){v=E._6;continue}if(B==="EQ"){C=!1,L=N("Just",E._4);continue}}g()}return L})(m.degree),y=x=>{let v=x,C=!0,L;for(;C;){const E=v;if(E.tag==="Leaf"){C=!1,L=!1;continue}if(E.tag==="Node"){const B=t.compare(p)(E._3);if(B==="LT"){v=E._5;continue}if(B==="GT"){v=E._6;continue}if(B==="EQ"){C=!1,L=!0;continue}}g()}return L};return(()=>{if(w.tag==="Nothing")return!1;if(w.tag==="Just")return w._1===1;g()})()&&!y(m.removedNodes)})()){u={...m,queue:[...m.queue,p]};continue}u=m;continue}}g()}return _},i=T(a=>u=>Qt(t)(we)(u.src)(1)(Qt(t)(we)(u.tgt)(1)(a)))(I)(r),s=o({degree:i,removedNodes:I,removedEdges:I,record:[],queue:ft(a=>{const u=(c=>{let _=c,d=!0,l;for(;d;){const f=_;if(f.tag==="Leaf"){d=!1,l=J;continue}if(f.tag==="Node"){const h=t.compare(a)(f._3);if(h==="LT"){_=f._5;continue}if(h==="GT"){_=f._6;continue}if(h==="EQ"){d=!1,l=N("Just",f._4);continue}}g()}return l})(i);if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1===1;g()},n)});return{coreNodes:ft(a=>!(u=>{let c=u,_=!0,d;for(;_;){const l=c;if(l.tag==="Leaf"){_=!1,d=!1;continue}if(l.tag==="Node"){const f=t.compare(a)(l._3);if(f==="LT"){c=l._5;continue}if(f==="GT"){c=l._6;continue}if(f==="EQ"){_=!1,d=!0;continue}}g()}return d})(s.removedNodes),n),coreEdges:ft(a=>!Pr(a.eid)(s.removedEdges),r),removed:s.record}}},ew=t=>e=>n=>T(r=>o=>{const i=o.neighbour,s=(()=>{const a=(u=>{let c=u,_=!0,d;for(;_;){const l=c;if(l.tag==="Leaf"){_=!1,d=J;continue}if(l.tag==="Node"){const f=t.compare(i)(l._3);if(f==="LT"){c=l._5;continue}if(f==="GT"){c=l._6;continue}if(f==="EQ"){_=!1,d=N("Just",l._4);continue}}g()}return d})(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})();return rt(t)(o.node)(o.viaSrc?s-1|0:s+1|0)(r)})(n)(se(e)),mc=t=>{const e=t.Eq0();return n=>r=>o=>{const i={...o,treeNode:rt(t)(r)()(o.treeNode)};return T(s=>a=>{if(Pr(a.eid)(s.st.edgeVisited))return s;const u={...s.st,edgeVisited:rt(it)(a.eid)()(s.st.edgeVisited)},c=e.eq(a.src)((()=>{const _=a.src,d=f=>{let h=f,p=!0,m;for(;p;){const w=h;if(w.tag==="Leaf"){p=!1,m=!1;continue}if(w.tag==="Node"){const y=t.compare(_)(w._3);if(y==="LT"){h=w._5;continue}if(y==="GT"){h=w._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}g()}return m},l=a.tgt;return d(u.treeNode)&&!(f=>{let h=f,p=!0,m;for(;p;){const w=h;if(w.tag==="Leaf"){p=!1,m=!1;continue}if(w.tag==="Node"){const y=t.compare(l)(w._3);if(y==="LT"){h=w._5;continue}if(y==="GT"){h=w._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}g()}return m})(u.treeNode)})()?a.src:(()=>{const _=a.tgt,d=f=>{let h=f,p=!0,m;for(;p;){const w=h;if(w.tag==="Leaf"){p=!1,m=!1;continue}if(w.tag==="Node"){const y=t.compare(_)(w._3);if(y==="LT"){h=w._5;continue}if(y==="GT"){h=w._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}g()}return m},l=a.src;return d(u.treeNode)&&!(f=>{let h=f,p=!0,m;for(;p;){const w=h;if(w.tag==="Leaf"){p=!1,m=!1;continue}if(w.tag==="Node"){const y=t.compare(l)(w._3);if(y==="LT"){h=w._5;continue}if(y==="GT"){h=w._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}g()}return m})(u.treeNode)})()?a.tgt:a.src)?a.tgt:a.src;if(Pr(a.eid)(u.treeEdge)){if((d=>{let l=d,f=!0,h;for(;f;){const p=l;if(p.tag==="Leaf"){f=!1,h=!1;continue}if(p.tag==="Node"){const m=t.compare(c)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){f=!1,h=!0;continue}}g()}return h})(u.treeNode))return{...s,st:u};const _=mc(t)(n)(c)(u);return{count:s.count+_.count|0,st:_.st}}if((()=>{const _=l=>{let f=l,h=!0,p;for(;h;){const m=f;if(m.tag==="Leaf"){h=!1,p=!1;continue}if(m.tag==="Node"){const w=t.compare(c)(m._3);if(w==="LT"){f=m._5;continue}if(w==="GT"){f=m._6;continue}if(w==="EQ"){h=!1,p=!0;continue}}g()}return p},d=a.tgt;return!_(u.treeNode)&&(()=>{const l=(p=>{let m=p,w=!0,y;for(;w;){const x=m;if(x.tag==="Leaf"){w=!1,y=J;continue}if(x.tag==="Node"){const v=t.compare(d)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){w=!1,y=N("Just",x._4);continue}}g()}return y})(u.layer),f=a.src,h=(p=>{let m=p,w=!0,y;for(;w;){const x=m;if(x.tag==="Leaf"){w=!1,y=J;continue}if(x.tag==="Node"){const v=t.compare(f)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){w=!1,y=N("Just",x._4);continue}}g()}return y})(u.layer);if(l.tag==="Nothing"){if(h.tag==="Nothing")return a.delta===0;if(h.tag==="Just")return a.delta===-h._1;g()}if(l.tag==="Just"){if(h.tag==="Nothing")return a.delta===(l._1-0|0);if(h.tag==="Just")return a.delta===(l._1-h._1|0)}g()})()})()){const _=mc(t)(n)(c)({...u,treeEdge:rt(it)(a.eid)()(u.treeEdge)});return{count:s.count+_.count|0,st:_.st}}return{...s,st:u}})({count:1,st:i})(ft(s=>(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!Pr(s.eid)(i.edgeVisited),n))}},Ks=t=>e=>n=>r=>{const o=r.src,i=(l=>{let f=l,h=!0,p;for(;h;){const m=f;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const w=t.compare(o)(m._3);if(w==="LT"){f=m._5;continue}if(w==="GT"){f=m._6;continue}if(w==="EQ"){h=!1,p=N("Just",m._4);continue}}g()}return p})(e.poID),s=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})(),a=r.tgt,u=(l=>{let f=l,h=!0,p;for(;h;){const m=f;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const w=t.compare(a)(m._3);if(w==="LT"){f=m._5;continue}if(w==="GT"){f=m._6;continue}if(w==="EQ"){h=!1,p=N("Just",m._4);continue}}g()}return p})(e.poID),c=(()=>{if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()})(),_=(l=>{let f=l,h=!0,p;for(;h;){const m=f;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const w=t.compare(n)(m._3);if(w==="LT"){f=m._5;continue}if(w==="GT"){f=m._6;continue}if(w==="EQ"){h=!1,p=N("Just",m._4);continue}}g()}return p})(e.poID),d=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;g()})();return(()=>{const l=r.src,f=(h=>{let p=h,m=!0,w;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,w=J;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,w=N("Just",y._4);continue}}g()}return w})(e.lowestPoID);return(()=>{if(f.tag==="Nothing")return 0<=d;if(f.tag==="Just")return f._1<=d;g()})()&&(()=>{const h=r.tgt;return d<=s&&(()=>{const p=(m=>{let w=m,y=!0,x;for(;y;){const v=w;if(v.tag==="Leaf"){y=!1,x=J;continue}if(v.tag==="Node"){const C=t.compare(h)(v._3);if(C==="LT"){w=v._5;continue}if(C==="GT"){w=v._6;continue}if(C==="EQ"){y=!1,x=N("Just",v._4);continue}}g()}return x})(e.lowestPoID);return(()=>{if(p.tag==="Nothing")return 0<=d;if(p.tag==="Just")return p._1<=d;g()})()&&d<=c})()})()})()?s>=c:s<c},nw=t=>{const e=ce(t)(zt);return n=>({layer:e(O(r=>b(r,0))(n)),treeNode:I,treeEdge:I,poID:I,lowestPoID:I,cutvalue:I,postOrder:1,edgeVisited:I})},rw=t=>e=>n=>T(r=>o=>{if((()=>{const _=o.src,d=h=>{let p=h,m=!0,w;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,w=!1;continue}if(y.tag==="Node"){const x=t.compare(_)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,w=!0;continue}}g()}return w},l=o.tgt,f=h=>{let p=h,m=!0,w;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,w=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,w=!0;continue}}g()}return w};return d(n.treeNode)===f(n.treeNode)})())return r;const i=o.tgt,s=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=J;continue}if(h.tag==="Node"){const p=t.compare(i)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(n.layer),a=o.src,u=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=J;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(n.layer),c=(()=>{if(s.tag==="Nothing"){if(u.tag==="Nothing")return-o.delta;if(u.tag==="Just")return-u._1-o.delta|0;g()}if(s.tag==="Just"){if(u.tag==="Nothing")return(s._1-0|0)-o.delta|0;if(u.tag==="Just")return(s._1-u._1|0)-o.delta|0}g()})();return c<r.slack?{edge:N("Just",o),slack:c}:r})({edge:J,slack:1e9})(e).edge,ow=t=>{const e=ce(t)(zt);return n=>r=>{const o=T(i=>s=>hc(i)((()=>{const a=(u=>{let c=u,_=!0,d;for(;_;){const l=c;if(l.tag==="Leaf"){_=!1,d=J;continue}if(l.tag==="Node"){const f=t.compare(s)(l._3);if(f==="LT"){c=l._5;continue}if(f==="GT"){c=l._6;continue}if(f==="EQ"){_=!1,d=N("Just",l._4);continue}}g()}return d})(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})()))(1e9)(n);return e(O(i=>b(i,(()=>{const s=(a=>{let u=a,c=!0,_;for(;c;){const d=u;if(d.tag==="Leaf"){c=!1,_=J;continue}if(d.tag==="Node"){const l=t.compare(i)(d._3);if(l==="LT"){u=d._5;continue}if(l==="GT"){u=d._6;continue}if(l==="EQ"){c=!1,_=N("Just",d._4);continue}}g()}return _})(r);if(s.tag==="Nothing")return-o;if(s.tag==="Just")return s._1-o|0;g()})()))(n))}},Of=t=>{const e=t.Eq0();return n=>r=>o=>{const i=T(a=>u=>{const c=Of(t)(n)(e.eq(u.src)(r)?u.tgt:u.src)({...a.st,edgeVisited:rt(it)(u.eid)()(a.st.edgeVisited)});return{lowest:hc(a.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:o})(ft(a=>Pr(a.eid)(o.treeEdge)&&(e.eq(a.src)(r)||e.eq(a.tgt)(r))&&!Pr(a.eid)(o.edgeVisited),n)),s=hc(i.lowest)(i.st.postOrder);return{lowest:s,st:{...i.st,poID:rt(t)(r)(i.st.postOrder)(i.st.poID),lowestPoID:rt(t)(r)(s)(i.st.lowestPoID),postOrder:i.st.postOrder+1|0}}}},Hf=t=>{const e=Of(t);return n=>r=>o=>0<n.length?e(r)(n[0])({...o,edgeVisited:I,postOrder:1,poID:I,lowestPoID:I}).st:o},iw=t=>{const e=t.Eq0();return n=>r=>o=>ft(i=>Pr(i.eid)(r.treeEdge)&&(e.eq(i.src)(o)||e.eq(i.tgt)(o)),n)},sw=t=>e=>re(n=>{const r=pc(n.eid)(e.cutvalue);return Pr(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),$f=t=>{const e=mc(t);return n=>r=>o=>{const i=0<n.length?N("Just",n[0]):J;if(i.tag==="Nothing")return o;if(i.tag==="Just"){const s=e(r)(i._1)({...o,edgeVisited:I,treeNode:I,treeEdge:I});if(s.count>=n.length)return s.st;const a=rw(t)(r)(s.st);if(a.tag==="Nothing")return s.st;if(a.tag==="Just"){const u=a._1.tgt,c=(h=>{let p=h,m=!0,w;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,w=J;continue}if(y.tag==="Node"){const x=t.compare(u)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,w=N("Just",y._4);continue}}g()}return w})(s.st.layer),_=a._1.src,d=(h=>{let p=h,m=!0,w;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,w=J;continue}if(y.tag==="Node"){const x=t.compare(_)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,w=N("Just",y._4);continue}}g()}return w})(s.st.layer),l=(()=>{if(c.tag==="Nothing"){if(d.tag==="Nothing")return-a._1.delta;if(d.tag==="Just")return-d._1-a._1.delta|0;g()}if(c.tag==="Just"){if(d.tag==="Nothing")return(c._1-0|0)-a._1.delta|0;if(d.tag==="Just")return(c._1-d._1|0)-a._1.delta|0}g()})(),f=(()=>{const h=a._1.tgt;return(p=>{let m=p,w=!0,y;for(;w;){const x=m;if(x.tag==="Leaf"){w=!1,y=!1;continue}if(x.tag==="Node"){const v=t.compare(h)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){w=!1,y=!0;continue}}g()}return y})(s.st.treeNode)})()?-l:l;return $f(t)(n)(r)({...s.st,layer:T(h=>p=>(m=>{let w=m,y=!0,x;for(;y;){const v=w;if(v.tag==="Leaf"){y=!1,x=!1;continue}if(v.tag==="Node"){const C=t.compare(p)(v._3);if(C==="LT"){w=v._5;continue}if(C==="GT"){w=v._6;continue}if(C==="EQ"){y=!1,x=!0;continue}}g()}return x})(s.st.treeNode)?rt(t)(p)((()=>{const m=(w=>{let y=w,x=!0,v;for(;x;){const C=y;if(C.tag==="Leaf"){x=!1,v=J;continue}if(C.tag==="Node"){const L=t.compare(p)(C._3);if(L==="LT"){y=C._5;continue}if(L==="GT"){y=C._6;continue}if(L==="EQ"){x=!1,v=N("Just",C._4);continue}}g()}return v})(s.st.layer);if(m.tag==="Nothing")return 0+f|0;if(m.tag==="Just")return m._1+f|0;g()})())(h):h)(s.st.layer)(n)})}}g()}},aw=t=>e=>n=>r=>T(o=>i=>{if(Ks(t)(r)(i.src)(n)&&!Ks(t)(r)(i.tgt)(n)){const s=i.tgt,a=(d=>{let l=d,f=!0,h;for(;f;){const p=l;if(p.tag==="Leaf"){f=!1,h=J;continue}if(p.tag==="Node"){const m=t.compare(s)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){f=!1,h=N("Just",p._4);continue}}g()}return h})(r.layer),u=i.src,c=(d=>{let l=d,f=!0,h;for(;f;){const p=l;if(p.tag==="Leaf"){f=!1,h=J;continue}if(p.tag==="Node"){const m=t.compare(u)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){f=!1,h=N("Just",p._4);continue}}g()}return h})(r.layer),_=(()=>{if(a.tag==="Nothing"){if(c.tag==="Nothing")return-i.delta;if(c.tag==="Just")return-c._1-i.delta|0;g()}if(a.tag==="Just"){if(c.tag==="Nothing")return(a._1-0|0)-i.delta|0;if(c.tag==="Just")return(a._1-c._1|0)-i.delta|0}g()})();if(_<o.slack)return{edge:N("Just",i),slack:_}}return o})({edge:J,slack:1e9})(e).edge,uw=t=>{const e=t.Eq0();return n=>r=>o=>i=>{const s=i.tgt,a=i.src;return T(u=>c=>{if((()=>{const _=pc(c.eid)(r.cutvalue);if(_.tag==="Just")return!0;if(_.tag==="Nothing")return!1;g()})()){const _=pc(c.eid)(r.cutvalue),d=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;g()})();return e.eq(a)(c.src)||e.eq(s)(c.tgt)?u-(d-c.weight):u+(d-c.weight)}return e.eq(o)(a)?e.eq(c.src)(o)?u+c.weight:u-c.weight:e.eq(c.src)(o)?u-c.weight:u+c.weight})(i.weight)(ft(u=>u.eid!==i.eid&&(e.eq(u.src)(o)||e.eq(u.tgt)(o)),n))}},cw=t=>{const e=uw(t);return n=>r=>o=>{const i=(s,a,u)=>{const c=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=J;continue}if(h.tag==="Node"){const p=t.compare(s)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(u);if(c.tag==="Just")return rt(t)(s)(ft(_=>_.eid!==a.eid,c._1))(u);if(c.tag==="Nothing")return u;g()};return(s=>a=>{let u=s,c=a,_=!0,d;for(;_;){const l=u,f=c,h=(m=>{let w=m,y=!0,x;for(;y;){const v=w;if(v.tag==="Leaf"){y=!1,x=J;continue}if(v.tag==="Node"){const C=t.compare(f)(v._3);if(C==="LT"){w=v._5;continue}if(C==="GT"){w=v._6;continue}if(C==="EQ"){y=!1,x=N("Just",v._4);continue}}g()}return x})(l.unknown),p=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;g()})();if(p.length===1){const m=t.Eq0().eq(p[0].src)(f)?p[0].tgt:p[0].src;u={unknown:i(f,p[0],i(m,p[0],l.unknown)),cutvalue:rt(it)(p[0].eid)(e(n)(l)(f)(p[0]))(l.cutvalue)},c=m;continue}_=!1,d=l}return d})(r)(o)}},Vf=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 d=it.compare(c.delta)(_.delta);if(d==="LT"||d==="GT"||d!=="EQ")return d;const l=it.compare(c.eid)(_.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const f=t.compare(c.src)(_.src);if(f==="LT"||f==="GT"||f!=="EQ")return f;const h=t.compare(c.tgt)(_.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const p=ot.compare(c.weight)(_.weight);return p==="LT"||p==="GT"||p!=="EQ"?p:Ye},Eq0:()=>r},i=T(c=>_=>rt(o)(_)()(c))(I),s=iw(t),a=ce(t)(zt),u=cw(t);return c=>_=>d=>{const l={unknown:a(O(f=>b(f,Zt(fn.foldr,i(s(_)(d)(f)))))(c)),cutvalue:I};return{...d,cutvalue:T(u(_))(l)(ft(f=>{const h=(p=>{let m=p,w=!0,y;for(;w;){const x=m;if(x.tag==="Leaf"){w=!1,y=J;continue}if(x.tag==="Node"){const v=t.compare(f)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){w=!1,y=N("Just",x._4);continue}}g()}return y})(l.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;g()},c)).cutvalue}}},gw=t=>{const e=Hf(t),n=Vf(t);return r=>o=>i=>s=>a=>{const u={...a,treeEdge:rt(it)(s.eid)()(qo(it)(i.eid)(a.treeEdge))},c=s.tgt,_=(p=>{let m=p,w=!0,y;for(;w;){const x=m;if(x.tag==="Leaf"){w=!1,y=J;continue}if(x.tag==="Node"){const v=t.compare(c)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){w=!1,y=N("Just",x._4);continue}}g()}return y})(u.layer),d=s.src,l=(p=>{let m=p,w=!0,y;for(;w;){const x=m;if(x.tag==="Leaf"){w=!1,y=J;continue}if(x.tag==="Node"){const v=t.compare(d)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){w=!1,y=N("Just",x._4);continue}}g()}return y})(u.layer),f=(()=>{if(_.tag==="Nothing"){if(l.tag==="Nothing")return-s.delta;if(l.tag==="Just")return-l._1-s.delta|0;g()}if(_.tag==="Just"){if(l.tag==="Nothing")return(_._1-0|0)-s.delta|0;if(l.tag==="Just")return(_._1-l._1|0)-s.delta|0}g()})(),h=Ks(t)(u)(s.tgt)(i)?f:-f;return n(r)(o)(e(r)(o)({...u,layer:T(p=>m=>Ks(t)(u)(m)(i)?p:rt(t)(m)((()=>{const w=(y=>{let x=y,v=!0,C;for(;v;){const L=x;if(L.tag==="Leaf"){v=!1,C=J;continue}if(L.tag==="Node"){const E=t.compare(m)(L._3);if(E==="LT"){x=L._5;continue}if(E==="GT"){x=L._6;continue}if(E==="EQ"){v=!1,C=N("Just",L._4);continue}}g()}return C})(u.layer);if(w.tag==="Nothing")return 0+h|0;if(w.tag==="Just")return w._1+h|0;g()})())(p))(u.layer)(r)}))}},_w=t=>{const e=gw(t);return n=>r=>o=>i=>(s=>a=>{let u=s,c=a,_=!0,d;for(;_;){const l=u,f=c;if(l===0){_=!1,d=f;continue}const h=sw(o)(f);if(h.tag==="Nothing"){_=!1,d=f;continue}if(h.tag==="Just"){const p=aw(t)(o)(h._1)(f);if(p.tag==="Nothing"){_=!1,d=f;continue}if(p.tag==="Just"){u=l-1|0,c=e(r)(o)(h._1)(p._1)(f);continue}}g()}return d})(n)(i)},fw=t=>{const e=Vf(t),n=Hf(t),r=$f(t);return o=>i=>s=>e(o)(i)(n(o)(i)(r(o)(i)(s)))},Uf=t=>e=>T(n=>r=>Qt(t)(le)(e(r))([r])(n))(I),dw=t=>{const e=ce(t)(zt);return n=>r=>o=>{const i=u=>c=>_=>d=>{let l=u,f=c,h=_,p=d,m=!0,w;for(;m;){const y=l,x=f,v=h,C=p,L=Ft(E=>J,E=>B=>N("Just",{head:E,tail:B}),v);if(L.tag==="Nothing"){m=!1,w=C;continue}if(L.tag==="Just"){const E=L._1.head,B=(R=>{let A=R,j=!0,Z;for(;j;){const M=A;if(M.tag==="Leaf"){j=!1,Z=J;continue}if(M.tag==="Node"){const W=t.compare(E)(M._3);if(W==="LT"){A=M._5;continue}if(W==="GT"){A=M._6;continue}if(W==="EQ"){j=!1,Z=N("Just",M._4);continue}}g()}return Z})(C.layer),z=(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})(),Y=T(R=>A=>{const j=A.tgt,Z=(W=>{let H=W,D=!0,F;for(;D;){const S=H;if(S.tag==="Leaf"){D=!1,F=J;continue}if(S.tag==="Node"){const G=t.compare(j)(S._3);if(G==="LT"){H=S._5;continue}if(G==="GT"){H=S._6;continue}if(G==="EQ"){D=!1,F=N("Just",S._4);continue}}g()}return F})(R.incident),M=(()=>{if(Z.tag==="Nothing")return-1;if(Z.tag==="Just")return Z._1-1|0;g()})();return{st:{...R.st,layer:rt(t)(A.tgt)(Zx((()=>{const W=A.tgt,H=(D=>{let F=D,S=!0,G;for(;S;){const Q=F;if(Q.tag==="Leaf"){S=!1,G=J;continue}if(Q.tag==="Node"){const V=t.compare(W)(Q._3);if(V==="LT"){F=Q._5;continue}if(V==="GT"){F=Q._6;continue}if(V==="EQ"){S=!1,G=N("Just",Q._4);continue}}g()}return G})(R.st.layer);if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})())(z+A.delta|0))(R.st.layer)},incident:rt(t)(A.tgt)(M)(R.incident),queue:M===0?[...R.queue,A.tgt]:R.queue}})({st:C,incident:x,queue:L._1.tail})((()=>{const R=(A=>{let j=A,Z=!0,M;for(;Z;){const W=j;if(W.tag==="Leaf"){Z=!1,M=J;continue}if(W.tag==="Node"){const H=t.compare(E)(W._3);if(H==="LT"){j=W._5;continue}if(H==="GT"){j=W._6;continue}if(H==="EQ"){Z=!1,M=N("Just",W._4);continue}}g()}return M})(y);if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;g()})());l=y,f=Y.incident,h=Y.queue,p=Y.st;continue}g()}return w},s=Uf(t)(u=>u.tgt)(r),a=e(O(u=>b(u,(()=>{const c=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=J;continue}if(h.tag==="Node"){const p=t.compare(u)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(s);if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1.length;g()})()))(n));return i(Uf(t)(u=>u.src)(r))(a)(ft(u=>{const c=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=J;continue}if(h.tag==="Node"){const p=t.compare(u)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(a);if(c.tag==="Nothing")return!0;if(c.tag==="Just")return c._1===0;g()},n))(o)}},lw=t=>{const e=nw(t),n=dw(t),r=fw(t),o=_w(t);return i=>s=>{const a=n(i)(s)(e(i));return s.length===0?a.layer:o(4*i.length|0)(i)(s)(r(i)(s)(a)).layer}},Xf=t=>{const e=ow(t),n=lw(t),r=tw(t);return o=>i=>{if(o.length===0)return I;if(o.length<40)return e(o)(n(o)(i));const s=r(o)(i);return e(o)(ew(t)(s.removed)(n(s.coreNodes)(s.coreEdges)))}},Yf=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},yc=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},hw=Xf(it),Mi=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}),pw=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=nt((()=>{const o=Yf(n.cGroup._1)(t);if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})());return xn(n.id)(o=>({...o,hitbox:{...o.hitbox,x:r+o.cGroupOffset.x}}))(e)}g()},mw=t=>e=>({...e,cGraph:T(pw(t))(e.cGraph)((()=>{const n=e.cGraph;return Tt(r=>ue(r)(n.cNodes))(n.cNodeOrder)})())}),yw=t=>e=>n=>r=>o=>{const i=fe(xs(e.cGroupOffset.x-t.cGroupOffset.x));return Mi({src:o.nextNodeId,tgt:r,delta:yc(0)(-i),weight:1})(Mi({src:o.nextNodeId,tgt:n,delta:yc(0)(i),weight:1})({...o,nodes:[...o.nodes,o.nextNodeId],nextNodeId:o.nextNodeId+1|0}))},xw=t=>e=>n=>r=>o=>i=>s=>{const a=yc(0)(fe(xs(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)?yw(n)(r)(o)(i)(s):Mi({src:o,tgt:i,delta:a,weight:t.vsLNodePair(n)(r)?2:1})(s)},ww=t=>e=>n=>r=>o=>{const i=ue(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"?xw(t)(e)(n)(i._1)(n.cGroup._1)(i._1.cGroup._1)(r):r;g()},Jw=t=>e=>n=>r=>T(ww(t)(e)(r))(n)(r.constraints),Nw=t=>e=>Mi({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),Tw=t=>{const e=T(o=>i=>Qt(it)(we)(i.tgt)(1)(o))(I)(t.edges),n=ft(o=>{const i=Yf(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 T(o=>i=>Mi({src:r,tgt:i,delta:1,weight:0})(o))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},vw=t=>e=>{const n=Tw(T(Nw)(T(Jw(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return Tt(o=>ue(o)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},Cw=t=>e=>{const n=vw(t)(e);return mw(hw(n.nodes)(n.edges))(e)},Kf=t=>t,pe=Kf("H"),me=Kf("V"),bw=t=>b(t._2,t._1),jf=t=>({...t,position:b(t.position._2,t.position._1),size:b(t.size._2,t.size._1)}),kw=t=>({start:b(t.start._2,t.start._1),end:b(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return me;if(t.direction==="V")return pe;g()})()}),Zf=t=>({...t,segments:O(kw)(t.segments),bends:O(bw)(t.bends)}),Lw=t=>({nodes:O(jf)(t.nodes),edges:t.edges,paths:O(Zf)(t.paths),ports:t.ports}),Sw={nodeNode:8,edgeNode:4,edgeEdge:10},Ew=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}}),Gw=t=>e=>Cw(e),Pw=t=>e=>n=>{const r=Lw(n),o=jx(r),i=Vx(o)(Wf(r)),s=Ux(Ef(ac)(mx({...xx(o.cGraph),compactionAlgorithm:N("Just",Gw()(i)),constraintAlgorithm:N("Just",Gx(e.edgeEdge)),spacingsHandler:Ew(e)(i)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:O(jf)(s.nodes),edges:O(Zf)(s.edges)}},t1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},e1=t=>Re(3)(t)==="$d:",Bw=t=>e=>n=>T(r=>o=>{const i=t1(o.from.node)(t),s=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})(),a=t1(o.to.node)(t),u=(()=>{if(a.tag==="Nothing")return-s;if(a.tag==="Just")return a._1-s|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,_=O(l=>"$d:"+c+":"+ie(l))(Kt(1,u-1|0)),d=[o.from.node,..._,o.to.node];return{...r,layers:T(l=>f=>{const h=f._2,p=M0(s+f._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;g()})(r.layers)(Fe(An,Kt(1,u-1|0),_)),edges:[...r.edges,...Fe(l=>f=>({id:c+":"+l+"->"+f,from:{node:l,port:o.from.port},to:{node:f,port:o.to.port},label:J}),d,Bt(1,d.length,d))],chains:[...r.chains,{edgeId:o.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),n1=t=>t,oi=ce(it)(zt),Xt=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},r1=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jt=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Nt=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ii=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Dw=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?Be:n==="GT"?De:it.compare(t._2)(e._2)},si=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Rw=(()=>{const t=nn.unfoldr(Qn);return e=>t(rn("IterNode",e,Fn))})(),Aw=t=>t,o1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Iw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},js=n1("Regular"),Zs=n1("Critical"),i1=t=>e=>{const n=T(s=>a=>rt(P)(a.node)(a)(s))(I)(e),r=1.25*nt(4),o=(s,a,u)=>(c=>_=>d=>{let l=c,f=_,h=d,p=!0,m;for(;p;){const w=l,y=f,x=h;if(x.critical){p=!1,m=x;continue}const v=Ft(L=>J,L=>E=>N("Just",{head:L,tail:E}),w),C=Ft(L=>J,L=>E=>N("Just",{head:L,tail:E}),y);if(v.tag==="Just"&&C.tag==="Just"){const L=v._1.head>C._1.head-s&&v._1.head<C._1.head+s?{...x,critical:!0}:v._1.head>C._1.head-r&&v._1.head<C._1.head+r?{...x,conflicts:x.conflicts+1|0}:x;if(L.critical){p=!1,m=L;continue}if(v._1.head<=C._1.head){l=v._1.tail,f=y,h=L;continue}l=w,f=C._1.tail,h=L;continue}p=!1,m=x}return m})(a)(u)({conflicts:0,critical:!1}),i=(s,a,u)=>{if(Nt(T(Nt)(-1e18)(a.incoming))(T(Nt)(-1e18)(a.outgoing))-Jt(T(Jt)(1e18)(a.incoming))(T(Jt)(1e18)(a.outgoing))<.001||Nt(T(Nt)(-1e18)(u.incoming))(T(Nt)(-1e18)(u.outgoing))-Jt(T(Jt)(1e18)(u.incoming))(T(Jt)(1e18)(u.outgoing))<.001)return[];const c=o(s,a.outgoing,u.incoming),_=o(s,u.outgoing,a.incoming);if(c.critical||_.critical)return[...c.critical?[{src:u.id,tgt:a.id,weight:1,kind:Zs}]:[],..._.critical?[{src:a.id,tgt:u.id,weight:1,kind:Zs}]:[]];const d=Jt(T(Jt)(1e18)(a.incoming))(T(Jt)(1e18)(a.outgoing)),l=Nt(T(Nt)(-1e18)(a.incoming))(T(Nt)(-1e18)(a.outgoing)),f=Jt(T(Jt)(1e18)(u.incoming))(T(Jt)(1e18)(u.outgoing)),h=Nt(T(Nt)(-1e18)(u.incoming))(T(Nt)(-1e18)(u.outgoing)),p=(1*c.conflicts|0)+(16*(T(w=>y=>y>h?w:y>=f?w+1|0:w)(0)(a.outgoing)+T(w=>y=>y>l?w:y>=d?w+1|0:w)(0)(u.incoming)|0)|0)|0,m=(1*_.conflicts|0)+(16*(T(w=>y=>y>l?w:y>=d?w+1|0:w)(0)(u.outgoing)+T(w=>y=>y>h?w:y>=f?w+1|0:w)(0)(a.incoming)|0)|0)|0;return p<m?[{src:a.id,tgt:u.id,weight:m-p|0,kind:js}]:p>m?[{src:u.id,tgt:a.id,weight:p-m|0,kind:js}]:p>0?[{src:a.id,tgt:u.id,weight:0,kind:js},{src:u.id,tgt:a.id,weight:0,kind:js}]:[]};return T(s=>a=>T(u=>c=>rt(P)(c._1)(c._2)(u))(s)((()=>{const u=T(R=>A=>{const j=A.edge.from.node+"|"+(()=>{if(A.edge.from.port.tag==="Just")return A.edge.from.port._1;if(A.edge.from.port.tag==="Nothing")return"_auto_"+A.edge.id;g()})(),Z=o1(j)(R.entries);if(Z.tag==="Nothing")return{...R,entries:rt(P)(j)({id:0,members:[A.edge.id],incoming:[A.fromPos._1],outgoing:[A.toPos._1],slot:0,mark:0,splitBy:J,splitPartner:J})(R.entries),order:[...R.order,j]};if(Z.tag==="Just")return{...R,entries:rt(P)(j)({...Z._1,members:[...Z._1.members,A.edge.id],incoming:[...er(M=>M<A.fromPos._1)(Z._1.incoming).init,A.fromPos._1,...er(M=>M<=A.fromPos._1)(Z._1.incoming).rest],outgoing:[...er(M=>M<A.toPos._1)(Z._1.outgoing).init,A.toPos._1,...er(M=>M<=A.toPos._1)(Z._1.outgoing).rest]})(R.entries)};g()})({entries:I,order:[]})(a._2),c=Ht(R=>A=>({...A,id:R}))(Tt(R=>o1(R)(u.entries))(u.order));if(c.length===0)return[];const _=T(R=>A=>R.prev.tag==="Just"&&A-R.prev._1<1e-9?R:{prev:N("Just",A),out:[...R.out,A]})({prev:J,out:[]})(Pt(ot.compare)([...St(c)(R=>R.incoming),...St(c)(R=>R.outgoing)])).out,d=_.length<2?.2*r:.2*T(R=>A=>{if(R.prev.tag==="Nothing")return{prev:N("Just",A),mn:R.mn};if(R.prev.tag==="Just")return{prev:N("Just",A),mn:Jt(R.mn)(A-R.prev._1)};g()})({prev:J,mn:1e18})(_).mn,l={segments:c,deps:(()=>{const R=c.length;return St(St(Kt(0,R-2|0))(A=>St(Kt(A+1|0,R-1|0))(j=>[b(A,j)])))(A=>A._1>=0&&A._1<c.length?A._2>=0&&A._2<c.length?i(d,c[A._1],c[A._2]):[]:[])})()},f=ft(R=>{if(R.kind==="Critical")return!0;if(R.kind==="Regular")return!1;g()},l.deps),h=(()=>{if(f.length<2)return l;const R=oi((()=>{const W=l.segments;return O(H=>b(H.id,H.mark))((()=>{const H=W.length,D=S=>{let G=S,Q=!0,V;for(;Q;){const X=G,U=re(q=>{const K=Xt(q)(X.inWeight);if(K.tag==="Nothing")return!0;if(K.tag==="Just")return K._1===0;g()})(X.remaining);if(U.tag==="Nothing"){Q=!1,V=X;continue}if(U.tag==="Just"){const q=U._1;G={...X,inWeight:T(K=>et=>Qt(it)(we)(et.tgt)(-et.weight)(K))(X.inWeight)((()=>{const K=Xt(q)(X.depsBySrc);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),marks:rt(it)(q)(X.nextSource)(X.marks),nextSource:X.nextSource+1|0,outWeight:T(K=>et=>Qt(it)(we)(et.src)(-et.weight)(K))(X.outWeight)((()=>{const K=Xt(q)(X.depsByTgt);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),remaining:ft(K=>K!==q,X.remaining)};continue}g()}return V},F=S=>{let G=S,Q=!0,V;for(;Q;){const X=G,U=re(q=>{const K=Xt(q)(X.outWeight);if(K.tag==="Nothing")return!0;if(K.tag==="Just")return K._1===0;g()})(X.remaining);if(U.tag==="Nothing"){Q=!1,V=X;continue}if(U.tag==="Just"){const q=U._1;G={...X,inWeight:T(K=>et=>Qt(it)(we)(et.tgt)(-et.weight)(K))(X.inWeight)((()=>{const K=Xt(q)(X.depsBySrc);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),marks:rt(it)(q)(X.nextSink)(X.marks),nextSink:X.nextSink-1|0,outWeight:T(K=>et=>Qt(it)(we)(et.src)(-et.weight)(K))(X.outWeight)((()=>{const K=Xt(q)(X.depsByTgt);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),remaining:ft(K=>K!==q,X.remaining)};continue}g()}return V};return(S=>{let G=S,Q=!0,V;for(;Q;){const X=D(F(G));if(X.remaining.length===0){Q=!1,V=O(U=>{const q=Xt(U.id)(X.marks),K=(()=>{if(q.tag==="Nothing")return U.id;if(q.tag==="Just")return q._1;g()})();return{...U,mark:K<H?(K+H|0)+1|0:K}})(W);continue}G=(()=>{const U=K=>{const et=Xt(K)(X.outWeight),lt=Xt(K)(X.inWeight);return(()=>{if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1;g()})()-(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()|0},q=Pt(K=>et=>it.compare(U(et))(U(K)))(X.remaining);if(0<q.length){const K=q[0];return{...X,inWeight:T(et=>lt=>Qt(it)(we)(lt.tgt)(-lt.weight)(et))(X.inWeight)((()=>{const et=Xt(K)(X.depsBySrc);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;g()})()),marks:rt(it)(K)(X.nextSource)(X.marks),nextSource:X.nextSource+1|0,outWeight:T(et=>lt=>Qt(it)(we)(lt.src)(-lt.weight)(et))(X.outWeight)((()=>{const et=Xt(K)(X.depsByTgt);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;g()})()),remaining:ft(et=>et!==K,X.remaining)}}return X})()}return V})({remaining:O(S=>S.id)(W),marks:I,inWeight:T(S=>G=>Qt(it)(we)(G.tgt)(G.weight)(S))(I)(f),outWeight:T(S=>G=>Qt(it)(we)(G.src)(G.weight)(S))(I)(f),depsBySrc:T(S=>G=>Qt(it)(le)(G.src)([G])(S))(I)(f),depsByTgt:T(S=>G=>Qt(it)(le)(G.tgt)([G])(S))(I)(f),nextSink:H-1|0,nextSource:H+1|0})})())})()),A=ft(W=>{const H=Xt(W.src)(R),D=Xt(W.tgt)(R);return(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})()>(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;g()})()},f);if(A.length===0)return l;const j=T(W=>H=>{if(en(qr)(H.src)(W.decisions)||en(qr)(H.tgt)(W.decisions))return W;const D=Xt(H.src)(W.segMap),F=Xt(H.tgt)(W.segMap);if(D.tag==="Just"&&F.tag==="Just"){const S=(D._1.incoming.length+D._1.outgoing.length|0)>2&&(F._1.incoming.length+F._1.outgoing.length|0)<=2,G=S?F._1:D._1;return{decisions:[...W.decisions,G.id],segMap:rt(it)(G.id)({...G,splitBy:N("Just",S?D._1.id:F._1.id)})(W.segMap)}}return W})({decisions:[],segMap:oi(O(W=>b(W.id,W))(l.segments))})(A),Z=j.segMap,M=T(W=>H=>{const D=Jt(T(Jt)(1e18)(H.incoming))(T(Jt)(1e18)(H.outgoing)),F=Nt(T(Nt)(-1e18)(H.incoming))(T(Nt)(-1e18)(H.outgoing)),S=ft(U=>U.a.startPosition<=F&&U.a.endPosition>=D,Ht(U=>q=>({i:U,a:q}))(W.freeAreas));if(S.length===0){const U={...H,incoming:Pt(ot.compare)(H.incoming),outgoing:Pt(ot.compare)([(D+F)/2]),splitPartner:N("Just",W.nextId)},q={id:W.nextId,incoming:Pt(ot.compare)([(D+F)/2]),mark:0,members:H.members,outgoing:Pt(ot.compare)(H.outgoing),slot:0,splitBy:J,splitPartner:N("Just",H.id)};return{segMap:rt(it)(q.id)(q)(rt(it)(U.id)(U)(W.segMap)),freeAreas:W.freeAreas,nextId:W.nextId+1|0}}const G=0<S.length?N("Just",S[0]):J,Q=(()=>{if(G.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(G.tag==="Just"){if(S.length===1)return G._1;const U=O(q=>({c:q,rating:(()=>{const K=(q.a.startPosition+q.a.endPosition)/2,et=[K],lt=[K],bt=T((()=>{const vt=W.segMap;return Gt=>jt=>{const Ct=Xt(jt.tgt)(vt);if(Ct.tag==="Nothing")return Gt;if(Ct.tag==="Just"){const Yt=Jt(T(Jt)(1e18)(Ct._1.incoming))(T(Jt)(1e18)(Ct._1.outgoing)),Rt=Nt(T(Nt)(-1e18)(Ct._1.incoming))(T(Nt)(-1e18)(Ct._1.outgoing)),wt=Jt(T(Jt)(1e18)(H.incoming))(T(Jt)(1e18)(et)),mt=(()=>{const Ot=Nt(T(Nt)(-1e18)(H.incoming))(T(Nt)(-1e18)(et)),qt=T(oe=>_e=>_e>Rt?oe:_e>=Yt?oe+1|0:oe)(0)(et)+T(oe=>_e=>_e>Ot?oe:_e>=wt?oe+1|0:oe)(0)(Ct._1.incoming)|0,Oe=Jt(T(Jt)(1e18)(H.incoming))(T(Jt)(1e18)(et)),bn=Nt(T(Nt)(-1e18)(H.incoming))(T(Nt)(-1e18)(et)),tn=Jt(T(Jt)(1e18)(Ct._1.incoming))(T(Jt)(1e18)(Ct._1.outgoing)),_n=Nt(T(Nt)(-1e18)(Ct._1.incoming))(T(Nt)(-1e18)(Ct._1.outgoing)),Ae=T(oe=>_e=>_e>bn?oe:_e>=Oe?oe+1|0:oe)(0)(Ct._1.outgoing)+T(oe=>_e=>_e>_n?oe:_e>=tn?oe+1|0:oe)(0)(H.incoming)|0;return qt===Ae?qt>0?{...Gt,deps:Gt.deps+2|0,crossings:Gt.crossings+qt|0}:Gt:{...Gt,deps:Gt.deps+1|0,crossings:Gt.crossings+si(qt)(Ae)|0}})(),ct=Jt(T(Jt)(1e18)(Ct._1.incoming))(T(Jt)(1e18)(Ct._1.outgoing)),yt=Nt(T(Nt)(-1e18)(Ct._1.incoming))(T(Nt)(-1e18)(Ct._1.outgoing)),dt=Jt(T(Jt)(1e18)(lt))(T(Jt)(1e18)(H.outgoing)),ht=Nt(T(Nt)(-1e18)(lt))(T(Nt)(-1e18)(H.outgoing)),Et=T(Ot=>qt=>qt>yt?Ot:qt>=ct?Ot+1|0:Ot)(0)(H.outgoing)+T(Ot=>qt=>qt>ht?Ot:qt>=dt?Ot+1|0:Ot)(0)(Ct._1.incoming)|0,Dt=Jt(T(Jt)(1e18)(lt))(T(Jt)(1e18)(H.outgoing)),Mt=Nt(T(Nt)(-1e18)(lt))(T(Nt)(-1e18)(H.outgoing)),ne=Jt(T(Jt)(1e18)(Ct._1.incoming))(T(Jt)(1e18)(Ct._1.outgoing)),Cn=Nt(T(Nt)(-1e18)(Ct._1.incoming))(T(Nt)(-1e18)(Ct._1.outgoing)),qe=T(Ot=>qt=>qt>Mt?Ot:qt>=Dt?Ot+1|0:Ot)(0)(Ct._1.outgoing)+T(Ot=>qt=>qt>Cn?Ot:qt>=ne?Ot+1|0:Ot)(0)(lt)|0;return Et===qe?Et>0?{...mt,deps:mt.deps+2|0,crossings:mt.crossings+Et|0}:mt:{...mt,deps:mt.deps+1|0,crossings:mt.crossings+si(Et)(qe)|0}}g()}})())(T((()=>{const vt=W.segMap;return Gt=>jt=>{const Ct=Xt(jt.src)(vt);if(Ct.tag==="Nothing")return Gt;if(Ct.tag==="Just"){const Yt=Jt(T(Jt)(1e18)(Ct._1.incoming))(T(Jt)(1e18)(Ct._1.outgoing)),Rt=Nt(T(Nt)(-1e18)(Ct._1.incoming))(T(Nt)(-1e18)(Ct._1.outgoing)),wt=Jt(T(Jt)(1e18)(H.incoming))(T(Jt)(1e18)(et)),mt=(()=>{const Ot=Nt(T(Nt)(-1e18)(H.incoming))(T(Nt)(-1e18)(et)),qt=T(oe=>_e=>_e>Rt?oe:_e>=Yt?oe+1|0:oe)(0)(et)+T(oe=>_e=>_e>Ot?oe:_e>=wt?oe+1|0:oe)(0)(Ct._1.incoming)|0,Oe=Jt(T(Jt)(1e18)(H.incoming))(T(Jt)(1e18)(et)),bn=Nt(T(Nt)(-1e18)(H.incoming))(T(Nt)(-1e18)(et)),tn=Jt(T(Jt)(1e18)(Ct._1.incoming))(T(Jt)(1e18)(Ct._1.outgoing)),_n=Nt(T(Nt)(-1e18)(Ct._1.incoming))(T(Nt)(-1e18)(Ct._1.outgoing)),Ae=T(oe=>_e=>_e>bn?oe:_e>=Oe?oe+1|0:oe)(0)(Ct._1.outgoing)+T(oe=>_e=>_e>_n?oe:_e>=tn?oe+1|0:oe)(0)(H.incoming)|0;return qt===Ae?qt>0?{...Gt,deps:Gt.deps+2|0,crossings:Gt.crossings+qt|0}:Gt:{...Gt,deps:Gt.deps+1|0,crossings:Gt.crossings+si(qt)(Ae)|0}})(),ct=Jt(T(Jt)(1e18)(Ct._1.incoming))(T(Jt)(1e18)(Ct._1.outgoing)),yt=Nt(T(Nt)(-1e18)(Ct._1.incoming))(T(Nt)(-1e18)(Ct._1.outgoing)),dt=Jt(T(Jt)(1e18)(lt))(T(Jt)(1e18)(H.outgoing)),ht=Nt(T(Nt)(-1e18)(lt))(T(Nt)(-1e18)(H.outgoing)),Et=T(Ot=>qt=>qt>yt?Ot:qt>=ct?Ot+1|0:Ot)(0)(H.outgoing)+T(Ot=>qt=>qt>ht?Ot:qt>=dt?Ot+1|0:Ot)(0)(Ct._1.incoming)|0,Dt=Jt(T(Jt)(1e18)(lt))(T(Jt)(1e18)(H.outgoing)),Mt=Nt(T(Nt)(-1e18)(lt))(T(Nt)(-1e18)(H.outgoing)),ne=Jt(T(Jt)(1e18)(Ct._1.incoming))(T(Jt)(1e18)(Ct._1.outgoing)),Cn=Nt(T(Nt)(-1e18)(Ct._1.incoming))(T(Nt)(-1e18)(Ct._1.outgoing)),qe=T(Ot=>qt=>qt>Mt?Ot:qt>=Dt?Ot+1|0:Ot)(0)(Ct._1.outgoing)+T(Ot=>qt=>qt>Cn?Ot:qt>=ne?Ot+1|0:Ot)(0)(lt)|0;return Et===qe?Et>0?{...mt,deps:mt.deps+2|0,crossings:mt.crossings+Et|0}:mt:{...mt,deps:mt.deps+1|0,crossings:mt.crossings+si(Et)(qe)|0}}g()}})())({crossings:0,deps:0})(ft(vt=>vt.tgt===H.id,l.deps)))(ft(vt=>vt.src===H.id,l.deps)),pt=(()=>{if(H.splitBy.tag==="Just")return Xt(H.splitBy._1)(W.segMap);if(H.splitBy.tag==="Nothing")return J;g()})();if(pt.tag==="Just")return{...bt,deps:bt.deps+2|0,crossings:(()=>{const vt=Jt(T(Jt)(1e18)(pt._1.incoming))(T(Jt)(1e18)(pt._1.outgoing)),Gt=Jt(T(Jt)(1e18)(lt))(T(Jt)(1e18)(H.outgoing)),jt=Nt(T(Nt)(-1e18)(pt._1.incoming))(T(Nt)(-1e18)(pt._1.outgoing)),Ct=Nt(T(Nt)(-1e18)(lt))(T(Nt)(-1e18)(H.outgoing)),Yt=Jt(T(Jt)(1e18)(H.incoming))(T(Jt)(1e18)(et));return bt.crossings+(()=>{const Rt=Jt(T(Jt)(1e18)(pt._1.incoming))(T(Jt)(1e18)(pt._1.outgoing)),wt=Nt(T(Nt)(-1e18)(H.incoming))(T(Nt)(-1e18)(et)),mt=Nt(T(Nt)(-1e18)(pt._1.incoming))(T(Nt)(-1e18)(pt._1.outgoing));return((T(ct=>yt=>yt>jt?ct:yt>=vt?ct+1|0:ct)(0)(et)+T(ct=>yt=>yt>wt?ct:yt>=Yt?ct+1|0:ct)(0)(pt._1.incoming)|0)+T(ct=>yt=>yt>Ct?ct:yt>=Gt?ct+1|0:ct)(0)(pt._1.outgoing)|0)+T(ct=>yt=>yt>mt?ct:yt>=Rt?ct+1|0:ct)(0)(lt)|0})()|0})()};if(pt.tag==="Nothing")return bt;g()})()}))(S);return T(q=>K=>K.rating.crossings<q.rating.crossings||!(K.rating.crossings>q.rating.crossings)&&(K.rating.deps<q.rating.deps||!(K.rating.deps>q.rating.deps)&&K.c.a.size>q.c.a.size)?K:q)(0<U.length?U[0]:{c:G._1,rating:{crossings:1e6,deps:1e6}})(U).c}g()})(),V={...H,incoming:Pt(ot.compare)(H.incoming),outgoing:Pt(ot.compare)([(Q.a.startPosition+Q.a.endPosition)/2]),splitPartner:N("Just",W.nextId)},X={id:W.nextId,incoming:Pt(ot.compare)([(Q.a.startPosition+Q.a.endPosition)/2]),mark:0,members:H.members,outgoing:Pt(ot.compare)(H.outgoing),slot:0,splitBy:J,splitPartner:N("Just",H.id)};return{segMap:rt(it)(X.id)(X)(rt(it)(V.id)(V)(W.segMap)),freeAreas:(()=>{if(Q.i>=0&&Q.i<W.freeAreas.length){const U=h_(Ut,J,Q.i,W.freeAreas),q=(()=>{if(U.tag==="Nothing")return W.freeAreas;if(U.tag==="Just")return U._1;g()})();if(W.freeAreas[Q.i].size/2<d)return q;const K=(W.freeAreas[Q.i].startPosition+W.freeAreas[Q.i].endPosition)/2,et=K-d,lt=K+d;return[...Q.i<1?[]:Bt(0,Q.i,q),...W.freeAreas[Q.i].startPosition<=et?[{startPosition:W.freeAreas[Q.i].startPosition,endPosition:et,size:et-W.freeAreas[Q.i].startPosition}]:[],...lt<=W.freeAreas[Q.i].endPosition?[{startPosition:lt,endPosition:W.freeAreas[Q.i].endPosition,size:W.freeAreas[Q.i].endPosition-lt}]:[],...Q.i<1?q:Bt(Q.i,q.length,q)]}return W.freeAreas})(),nextId:W.nextId+1|0}})({segMap:Z,freeAreas:(()=>{const W=Pt(ot.compare)([...St(l.segments)(H=>H.incoming),...St(l.segments)(H=>H.outgoing)]);return Tt(Aw)(Fe(H=>D=>D-H>=2*d?N("Just",{startPosition:H+d,endPosition:D-d,size:D-H-2*d}):J,W,Bt(1,W.length,W)))})(),nextId:l.segments.length})(Pt(W=>H=>ot.compare(Nt(T(Nt)(-1e18)(W.incoming))(T(Nt)(-1e18)(W.outgoing))-Jt(T(Jt)(1e18)(W.incoming))(T(Jt)(1e18)(W.outgoing)))(Nt(T(Nt)(-1e18)(H.incoming))(T(Nt)(-1e18)(H.outgoing))-Jt(T(Jt)(1e18)(H.incoming))(T(Jt)(1e18)(H.outgoing))))(Tt(W=>Xt(W)(Z))(j.decisions)));return{segments:(()=>{const W=(H,D)=>{if(H.tag==="Leaf")return D;if(H.tag==="Node")return W(H._5,Lt("Cons",H._4,W(H._6,D)));g()};return Zt(de.foldr,W(M.segMap,$))})(),deps:(()=>{const W=M.segMap,H=(S,G)=>{if(S.tag==="Leaf")return G;if(S.tag==="Node")return H(S._5,Lt("Cons",S._4,H(S._6,G)));g()},D=Zt(de.foldr,H(W,$)),F=D.length;return[...St(St(Kt(0,F-2|0))(S=>St(Kt(S+1|0,F-1|0))(G=>[b(S,G)])))(S=>S._1>=0&&S._1<D.length?S._2>=0&&S._2<D.length?D[S._1].splitPartner.tag!=="Nothing"&&D[S._1].splitPartner.tag==="Just"&&D[S._1].splitPartner._1===D[S._2].id||D[S._2].splitPartner.tag!=="Nothing"&&D[S._2].splitPartner.tag==="Just"&&D[S._2].splitPartner._1===D[S._1].id?[]:i(d,D[S._1],D[S._2]):[]:[]),...St(D)(S=>S.splitBy.tag==="Just"&&S.splitPartner.tag==="Just"&&(()=>{const G=Xt(S.splitPartner._1)(W);if(G.tag==="Nothing")return!1;if(G.tag==="Just")return!0;g()})()&&(()=>{const G=Xt(S.splitBy._1)(W);if(G.tag==="Nothing")return!1;if(G.tag==="Just")return!0;g()})()?[{src:S.id,tgt:S.splitBy._1,weight:1,kind:Zs},{src:S.splitBy._1,tgt:S.splitPartner._1,weight:1,kind:Zs}]:[])]})()}})(),p=h.segments,m=p.length,w=R=>{let A=R,j=!0,Z;for(;j;){const M=A,W=re(H=>{const D=Xt(H)(M.inWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;g()})(M.remaining);if(W.tag==="Nothing"){j=!1,Z=M;continue}if(W.tag==="Just"){const H=W._1;A={...M,inWeight:T(D=>F=>Qt(it)(we)(F.tgt)(-F.weight)(D))(M.inWeight)((()=>{const D=Xt(H)(M.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),marks:rt(it)(H)(M.nextSource)(M.marks),nextSource:M.nextSource+1|0,outWeight:T(D=>F=>Qt(it)(we)(F.src)(-F.weight)(D))(M.outWeight)((()=>{const D=Xt(H)(M.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),remaining:ft(D=>D!==H,M.remaining)};continue}g()}return Z},y=R=>{let A=R,j=!0,Z;for(;j;){const M=A,W=re(H=>{const D=Xt(H)(M.outWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;g()})(M.remaining);if(W.tag==="Nothing"){j=!1,Z=M;continue}if(W.tag==="Just"){const H=W._1;A={...M,inWeight:T(D=>F=>Qt(it)(we)(F.tgt)(-F.weight)(D))(M.inWeight)((()=>{const D=Xt(H)(M.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),marks:rt(it)(H)(M.nextSink)(M.marks),nextSink:M.nextSink-1|0,outWeight:T(D=>F=>Qt(it)(we)(F.src)(-F.weight)(D))(M.outWeight)((()=>{const D=Xt(H)(M.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),remaining:ft(D=>D!==H,M.remaining)};continue}g()}return Z},x=(R=>{let A=R,j=!0,Z;for(;j;){const M=w(y(A));if(M.remaining.length===0){j=!1,Z=O(W=>{const H=Xt(W.id)(M.marks),D=(()=>{if(H.tag==="Nothing")return W.id;if(H.tag==="Just")return H._1;g()})();return{...W,mark:D<m?(D+m|0)+1|0:D}})(p);continue}A=(()=>{const W=D=>{const F=Xt(D)(M.outWeight),S=Xt(D)(M.inWeight);return(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;g()})()-(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;g()})()|0},H=Pt(D=>F=>it.compare(W(F))(W(D)))(M.remaining);if(0<H.length){const D=H[0];return{...M,inWeight:T(F=>S=>Qt(it)(we)(S.tgt)(-S.weight)(F))(M.inWeight)((()=>{const F=Xt(D)(M.depsBySrc);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})()),marks:rt(it)(D)(M.nextSource)(M.marks),nextSource:M.nextSource+1|0,outWeight:T(F=>S=>Qt(it)(we)(S.src)(-S.weight)(F))(M.outWeight)((()=>{const F=Xt(D)(M.depsByTgt);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})()),remaining:ft(F=>F!==D,M.remaining)}}return M})()}return Z})({remaining:O(R=>R.id)(p),marks:I,inWeight:T(R=>A=>Qt(it)(we)(A.tgt)(A.weight)(R))(I)(h.deps),outWeight:T(R=>A=>Qt(it)(we)(A.src)(A.weight)(R))(I)(h.deps),depsBySrc:T(R=>A=>Qt(it)(le)(A.src)([A])(R))(I)(h.deps),depsByTgt:T(R=>A=>Qt(it)(le)(A.tgt)([A])(R))(I)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),v=(()=>{const R=(()=>{const Z=oi(O(M=>b(M.id,M.mark))(x));return{segments:x,deps:Tt(M=>(()=>{if(M.kind==="Critical")return!0;if(M.kind==="Regular")return!1;g()})()?N("Just",M):(()=>{const W=Xt(M.src)(Z),H=Xt(M.tgt)(Z);return(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})()>(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})()})()?M.weight===0?J:N("Just",{src:M.tgt,tgt:M.src,weight:M.weight,kind:M.kind}):N("Just",M))(h.deps)}})(),A=T(Z=>M=>Qt(it)(we)(M.tgt)(1)(Z))(I)(R.deps),j=(Z=>{let M=Z,W=!0,H;for(;W;){const D=M,F=Ft(S=>J,S=>G=>N("Just",{head:S,tail:G}),D.queue);if(F.tag==="Nothing"){W=!1,H=D;continue}if(F.tag==="Just"){M=T((()=>{const S=Xt(F._1.head)(D.slots),G=(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;g()})();return Q=>V=>{const X=Xt(V)(Q.inDegree),U=(()=>{if(X.tag==="Nothing")return-1;if(X.tag==="Just")return X._1-1|0;g()})();return{...Q,slots:rt(it)(V)(r1((()=>{const q=Xt(V)(Q.slots);if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;g()})())(G+1|0))(Q.slots),inDegree:rt(it)(V)(U)(Q.inDegree),queue:U===0?[...Q.queue,V]:Q.queue}}})())({...D,queue:F._1.tail})((()=>{const S=Xt(F._1.head)(D.adj);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})());continue}g()}return H})({slots:oi(O(Z=>b(Z.id,0))(R.segments)),inDegree:A,adj:T(Z=>M=>Qt(it)(le)(M.src)([M.tgt])(Z))(I)(R.deps),queue:O(Z=>Z.id)(ft(Z=>{const M=Xt(Z.id)(A);if(M.tag==="Nothing")return!0;if(M.tag==="Just")return M._1===0;g()},R.segments))});return Pt(Z=>M=>it.compare(Z.slot)(M.slot))(O(Z=>({...Z,slot:(()=>{const M=Xt(Z.id)(j.slots);if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()}))(R.segments))})(),C=1+T(R=>A=>r1(R)(A.slot))(0)(v)|0,L=St(v)(R=>R.members),E=ft(R=>en(tr)(R.edge.id)(L),t),B=T(Nt)(-1e18)(O(R=>R.fromPos._2)(E)),z=T(Jt)(1e18)(O(R=>R.toPos._2)(E));if(B>z){const R=oi(O(A=>b(A.id,A))(v));return hn(O(A=>O(j=>b(j,{slot:A.slot,slotCount:C,gapTop:z,gapBottom:B,partner:(()=>{if(A.splitPartner.tag==="Just"){const Z=Xt(A.splitPartner._1)(R);if(Z.tag==="Just")return N("Just",{slot:Z._1.slot,splitX:0<Z._1.incoming.length?Z._1.incoming[0]:0});if(Z.tag==="Nothing")return J;g()}if(A.splitPartner.tag==="Nothing")return J;g()})()}))(A.members))(ft(A=>{if(A.splitPartner.tag==="Just"){const j=Xt(A.splitPartner._1)(R);return!(j.tag==="Just"&&(()=>{if(j._1.splitBy.tag==="Nothing")return!1;if(j._1.splitBy.tag==="Just")return!0;g()})())}if(A.splitPartner.tag==="Nothing")return!0;g()},v)))}const Y=oi(O(R=>b(R.id,R))(v));return hn(O(R=>O(A=>b(A,{slot:R.slot,slotCount:C,gapTop:B,gapBottom:z,partner:(()=>{if(R.splitPartner.tag==="Just"){const j=Xt(R.splitPartner._1)(Y);if(j.tag==="Just")return N("Just",{slot:j._1.slot,splitX:0<j._1.incoming.length?j._1.incoming[0]:0});if(j.tag==="Nothing")return J;g()}if(R.splitPartner.tag==="Nothing")return J;g()})()}))(R.members))(ft(R=>{if(R.splitPartner.tag==="Just"){const A=Xt(R.splitPartner._1)(Y);return!(A.tag==="Just"&&(()=>{if(A._1.splitBy.tag==="Nothing")return!1;if(A._1.splitBy.tag==="Just")return!0;g()})())}if(R.splitPartner.tag==="Nothing")return!0;g()},v)))})()))(I)(Rw(T(s=>a=>{const u=ii(a.edge.from.node)(n);if(u.tag==="Just"){const c=ii(a.edge.to.node)(n);return c.tag==="Just"&&u._1.layer!==c._1.layer?Qt(it)(le)(si(u._1.layer)(c._1.layer))([a])(s):s}return s})(I)((()=>{const s=a=>b((()=>{const u=ii(a.edge.from.node)(n);return u.tag==="Just"?u._1.layer:1e6})(),(()=>{const u=ii(a.edge.from.node)(n);return u.tag==="Just"?u._1.order:1e6})());return Pt(a=>u=>Dw(s(a))(s(u)))(t)})())))},Fw=t=>e=>{const n=i1(t)(e),r=T(o=>i=>rt(P)(i.node)(i)(o))(I)(e);return T(o=>i=>{const s=ii(i.edge.from.node)(r);if(s.tag==="Just"){const a=ii(i.edge.to.node)(r);if(a.tag==="Just"&&s._1.layer!==a._1.layer){const u=Iw(i.edge.id)(n);if(u.tag==="Just")return rt(it)(si(s._1.layer)(a._1.layer))(u._1.slotCount)(o)}return o}return o})(I)(t)},xc=ce(P)(zt),Br=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},wc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Qw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t._1)(i._3._1);if(s==="LT"){n=i._5;continue}if(s==="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},s1=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 b(o,i*2);if(t==="North")return b(o,e.position._2*2);if(t==="East")return b(n*2,r);if(t==="West")return b(e.position._1*2,r);g()},Jc=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()},a1=t=>e=>T(n=>r=>Qt(t)(le)(e(r))([r])(n))(I),u1=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},c1=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,o=e.length;return o===0?I:xc(o===1?O(i=>b(i,r))(e):Ht(i=>s=>b(s,t.lo+nt(i+1|0)*n/nt(o+1|0)))(e))},g1=t=>e=>n=>r=>o=>{const i=a1(P)(f=>f.to.node)(t),s=a1(P)(f=>f.from.node)(t),a=T(f=>h=>rt(P)(h.node)(h)(f))(I)(e),u=(f,h,p)=>{const m=Br(f)(a);if(m.tag==="Nothing")return b(0,0);if(m.tag==="Just"){const w=Br(f)(n);if(w.tag==="Nothing"){const y=nt(4);if(p==="South")return b(m._1.position._1*y+m._1.size._1*y/2,(m._1.position._2+m._1.size._2)*y);if(p==="North")return b(m._1.position._1*y+m._1.size._1*y/2,m._1.position._2*y);if(p==="East")return b((m._1.position._1+m._1.size._1)*y,m._1.position._2*y+m._1.size._2*y/2);if(p==="West")return b(m._1.position._1*y,m._1.position._2*y+m._1.size._2*y/2);g()}if(w.tag==="Just"){const y=re(x=>x.id===h)(w._1);if(y.tag==="Nothing"){const x=nt(4);if(p==="South")return b(m._1.position._1*x+m._1.size._1*x/2,(m._1.position._2+m._1.size._2)*x);if(p==="North")return b(m._1.position._1*x+m._1.size._1*x/2,m._1.position._2*x);if(p==="East")return b((m._1.position._1+m._1.size._1)*x,m._1.position._2*x+m._1.size._2*x/2);if(p==="West")return b(m._1.position._1*x,m._1.position._2*x+m._1.size._2*x/2);g()}if(y.tag==="Just"){const x=nt(4);if(y._1.side==="North")return b(m._1.position._1*x+nt(y._1.offset)*x,m._1.position._2*x);if(y._1.side==="South")return b(m._1.position._1*x+nt(y._1.offset)*x,(m._1.position._2+m._1.size._2)*x);if(y._1.side==="East")return b((m._1.position._1+m._1.size._1)*x,m._1.position._2*x+nt(y._1.offset)*x);if(y._1.side==="West")return b(m._1.position._1*x,m._1.position._2*x+nt(y._1.offset)*x)}}}g()},c=xc(St(r)(f=>{if(f.nodes.length<=2)return[];const h=nt(4);if(1<f.nodes.length){const p=Br(f.nodes[1])(a);if(p.tag==="Nothing")return[];if(p.tag==="Just"){const m=p._1.position._1*h+p._1.size._1*h/2;return O(w=>b(w,m))(Fe(w=>y=>f.edgeId+":"+w+"->"+y,f.nodes,Bt(1,f.nodes.length,f.nodes)))}g()}return[]})),_=f=>{const h=Br(f.from.node)(a),p=Br(f.to.node)(a);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,w=p._1,y=Pt(x=>v=>it.compare(x.score)(v.score))(O(x=>{const v=x._1,C=x._2;return{from:v,to:C,score:(()=>{const L=(Y,R,A,j,Z)=>{const M=Jc(Y)(R),W=Jc(Y)(A);return M.lo<W.hi&&W.lo<M.hi&&(v==="South"?C==="North"&&Z._2>j._2:v==="North"?C==="South"&&Z._2<j._2:v==="East"?C==="West"&&Z._1>j._1:v==="West"&&C==="East"&&Z._1<j._1)?0:u1(v)(C)(j)(Z)},E=s1(v)(m),B=s1(C)(w),z=u1(v)(C)(E)(B);return(()=>{if(z>0){if(v==="South")return C==="North"?L(Se,m,w,E,B)*10|0:z*10|0;if(v==="North")return C==="South"?L(Le,m,w,E,B)*10|0:z*10|0;if(v==="East")return C==="West"?L(kr,m,w,E,B)*10|0:z*10|0;if(v==="West"&&C==="East")return L(Lr,m,w,E,B)*10|0}return z*10|0})()+(v==="South"?C==="North"?w.layer>=m.layer?0:20:15:v==="North"?C==="South"?w.layer<=m.layer?0:20:15:v==="East"?C==="West"?5:15:v==="West"&&C==="East"?5:15)|0})()}})([b(Se,Le),b(kr,Le),b(Lr,Le),b(Se,kr),b(Se,Lr),b(Le,Se),b(Le,kr),b(Le,Lr),b(kr,Se),b(Lr,Se),b(kr,Lr),b(Lr,kr)]));if(0<y.length)return{from:y[0].from,to:y[0].to}}return{from:Se,to:Le}},d=xc(O(f=>b(f.id,_(f)))(t)),l=(f,h,p,m,w,y)=>{const x=nt(4),v=Br(h)(a);if(v.tag==="Nothing")return b(0,0);if(v.tag==="Just"){const C=Qw(b(p,f))(o);if(C.tag==="Just"){const L=v._1.position._1*x+C._1,E=nt(4);if(f==="South")return b(L,(v._1.position._2+v._1.size._2)*E);if(f==="North")return b(L,v._1.position._2*E);if(f==="East")return b((v._1.position._1+v._1.size._1)*E,L);if(f==="West")return b(v._1.position._1*E,L);g()}if(C.tag==="Nothing"){const L=Jc(f)(v._1),E=(L.lo+L.hi)/2,B=wc(p)(c1(L)(O(R=>R.id)(Pt(R=>A=>ot.compare(w(f)(R))(w(f)(A)))(ft(R=>{const A=wc(R.id)(d);if(A.tag==="Just"){const j=y(A._1);return j==="North"?f==="North":j==="South"?f==="South":j==="East"?f==="East":j==="West"&&f==="West"}if(A.tag==="Nothing")return!0;g()},(()=>{const R=Br(h)(m);if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;g()})()))))),z=(()=>{if(B.tag==="Nothing")return E;if(B.tag==="Just")return B._1;g()})(),Y=nt(4);if(f==="South")return b(z,(v._1.position._2+v._1.size._2)*Y);if(f==="North")return b(z,v._1.position._2*Y);if(f==="East")return b((v._1.position._1+v._1.size._1)*Y,z);if(f==="West")return b(v._1.position._1*Y,z)}}g()};return O(f=>{const h=wc(f.edge.id)(c);if(h.tag==="Nothing")return f;if(h.tag==="Just")return{...f,fromPos:Re(3)(f.edge.from.node)==="$d:"?b(h._1,f.fromPos._2):f.fromPos,toPos:Re(3)(f.edge.to.node)==="$d:"?b(h._1,f.toPos._2):f.toPos};g()})(O(f=>{if(f.from.port.tag==="Just"&&f.to.port.tag==="Just")return{edge:f,fromPos:u(f.from.node,f.from.port._1,Se),toPos:u(f.to.node,f.to.port._1,Le),fromSide:Se,toSide:Le};const h=_(f);return{edge:f,fromPos:l(h.from,f.from.node,f.id,s,p=>m=>{const w=Br(m.to.node)(a);if(w.tag==="Nothing")return 0;if(w.tag==="Just"){const y=nt(4);if(p==="South"||p==="North")return w._1.position._1*y+w._1.size._1*y/2;if(p==="East"||p==="West")return w._1.position._2*y+w._1.size._2*y/2}g()},p=>p.from),toPos:l(h.to,f.to.node,f.id,i,p=>m=>{const w=Br(m.from.node)(a);if(w.tag==="Nothing")return 0;if(w.tag==="Just"){const y=nt(4);if(p==="South"||p==="North")return w._1.position._1*y+w._1.size._1*y/2;if(p==="East"||p==="West")return w._1.position._2*y+w._1.size._2*y/2}g()},p=>p.to),fromSide:h.from,toSide:h.to}})(t))},ta=(()=>{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 Be;if(r==="GT")return De;if(e._2==="North")return n._2==="North"?Ye:Be;if(n._2==="North")return De;if(e._2==="South")return n._2==="South"?Ye:Be;if(n._2==="South")return De;if(e._2==="East")return n._2==="East"?Ye:Be;if(n._2==="East")return De;if(e._2==="West"&&n._2==="West")return Ye;g()},Eq0:()=>t}})(),Mw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=ta.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},zw=ce(P)(zt),Nc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Ww=ce(ta)(zt),_1=(()=>{const t=nn.unfoldr(Qn);return e=>t(rn("IterNode",e,Fn))})(),ai=t=>e=>n=>r=>{const o=Mw(b(e,n))(t);if(o.tag==="Nothing")return r;if(o.tag==="Just")return o._1;g()},f1=t=>e=>n=>{const r=zw(hn(O(s=>Ht(a=>u=>b(u,a))(s))(t))),o=(s,a)=>{if(s==="South"){const u=Nc(a.to.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()}if(s==="North"){const u=Nc(a.from.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()}return 0},i=s=>T(a=>u=>Me(ta.compare,Ie,Ww(O(c=>b(b(c._1,s),c._2))(_1(c1({lo:0,hi:(()=>{const c=Nc(u._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return Re(3)(u._1)==="$d:"?0:1;g()})()})(O(c=>c.id)(Pt(c=>_=>it.compare(o(s,c))(o(s,_)))(u._2)))))),a))(I)(_1(T(a=>u=>u.from.node===u.to.node?a:s==="South"?Qt(P)(le)(u.from.node)([u])(a):s==="North"?Qt(P)(le)(u.to.node)([u])(a):a)(I)(e)));return Me(ta.compare,Ie,i(Le),i(Se))},d1=t=>t,l1=t=>t,h1=t=>t,qw=T(t=>e=>rt(P)(e)()(t))(I),Ow=(()=>{const t=nn.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return N("Just",b(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,Lt("Cons",r._3,n(r._6,o)));g()};return n(e,$)})())})(),gt=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Sn=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},gr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},_r=ce(P)(zt),Tc=N_(P),vc=(()=>{const t=nn.unfoldr(Qn);return e=>t(rn("IterNode",e,Fn))})(),Hw=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},$w=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},p1=h1("VDown"),m1=h1("VUp"),Vw=l1("ForwardPhase"),Uw=l1("StackPhase"),y1=d1("HRight"),x1=d1("HLeft"),w1=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Xw=t=>e=>n=>{const r=T(s=>a=>Qt(P)(we)(a.tgt)(1)(s))(I)(t),o=Ow(qw([...O(s=>s.src)(t),...O(s=>s.tgt)(t),...(()=>{const s=(a,u)=>{if(a.tag==="Leaf")return u;if(a.tag==="Node")return s(a._5,Lt("Cons",a._4,s(a._6,u)));g()};return Zt(de.foldr,s(e,$))})()])),i=T(s=>a=>Qt(P)(le)(a.src)([{target:a.tgt,sep:a.sep}])(s))(I)(t);return(s=>a=>u=>{let c=s,_=a,d=u,l=!0,f;for(;l;){const h=c,p=_,m=d,w=Ft(y=>J,y=>x=>N("Just",{head:y,tail:x}),h);if(w.tag==="Nothing"){l=!1,f=m;continue}if(w.tag==="Just"){const y=gt(w._1.head)(m),x=(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;g()})(),v=T(C=>L=>{const E=gt(L.target)(C.result),B=x+L.sep,z=gt(L.target)(C.indeg),Y=(()=>{if(z.tag==="Nothing")return-1;if(z.tag==="Just")return z._1-1|0;g()})();return{newQueue:Y===0?[...C.newQueue,L.target]:C.newQueue,result:rt(P)(L.target)((()=>{if(E.tag==="Nothing")return B;if(E.tag==="Just"){if(n==="VDown")return Sn(E._1)(B);if(n==="VUp")return gr(E._1)(B)}g()})())(C.result),indeg:rt(P)(L.target)(Y)(C.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const C=gt(w._1.head)(i);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;g()})());c=[...w._1.tail,...v.newQueue],_=v.indeg,d=v.result;continue}g()}return f})(ft(s=>{const a=gt(s)(r);if(a.tag==="Nothing")return!0;if(a.tag==="Just")return a._1===0;g()},o))(r)(T(s=>a=>rt(P)(a)(0)(s))(I)(o))},Yw=t=>{const e=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return e(i._5,Lt("Cons",i._4,e(i._6,s)));g()},n=Zt(de.foldr,e(t,$)),r=T(Sn)(999999)(n);if(r===0||n.length===0)return t;const o=i=>{if(i.tag==="Leaf")return I;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,i._4-r,o(i._5),o(i._6));g()};return o(t)},J1=t=>{const e=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return e(i._5,Lt("Cons",i._4,e(i._6,s)));g()},n=e(t,$),r=i=>s=>{let a=i,u=s,c=!0,_;for(;c;){const d=a,l=u;if(l.tag==="Nil"){c=!1,_=d;continue}if(l.tag==="Cons"){a=gr(d)(l._1),u=l._2;continue}g()}return _},o=i=>s=>{let a=i,u=s,c=!0,_;for(;c;){const d=a,l=u;if(l.tag==="Nil"){c=!1,_=d;continue}if(l.tag==="Cons"){a=Sn(d)(l._1),u=l._2;continue}g()}return _};return r(-999999)(n)-o(999999)(n)},zi=t=>e=>(n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=i;if(u===e){s=!1,a=c;continue}o=(()=>{const _=gt(u)(t.align);if(_.tag==="Nothing")return e;if(_.tag==="Just")return _._1;g()})(),i=[...c,u]}return a})((()=>{const n=gt(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;g()})())([e]),Kw=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>_=>{const d=(D,F,S)=>{const G=D.from.node===F?D.from.port:D.to.node===F?D.to.port:J;if(G.tag==="Just"){const Q=gt(F)(o);if(Q.tag==="Just"){const V=re(X=>X.id===G._1)(Q._1);if(V.tag==="Just"){const X=nt(V._1.offset)*nt(4);return S==="North"||S==="South"?X:0}if(V.tag==="Nothing"){const X=gt(F)(r),U=ai(s)(D.id)(S)((()=>{if(X.tag==="Nothing")return .5;if(X.tag==="Just")return X._1._1/2;g()})());return S==="North"||S==="South"?U:0}g()}if(Q.tag==="Nothing"){const V=gt(F)(r),X=ai(s)(D.id)(S)((()=>{if(V.tag==="Nothing")return .5;if(V.tag==="Just")return V._1._1/2;g()})());return S==="North"||S==="South"?X:0}g()}if(G.tag==="Nothing"){const Q=gt(F)(r),V=ai(s)(D.id)(S)((()=>{if(Q.tag==="Nothing")return .5;if(Q.tag==="Just")return Q._1._1/2;g()})());return S==="North"||S==="South"?V:0}g()},l=(D,F)=>{if(D.from.node===F){if(_==="HRight")return Se;if(_==="HLeft")return Le;g()}if(_==="HRight")return Le;if(_==="HLeft")return Se;g()},f=(D,F,S)=>T(G=>Q=>rt(P)(Q)((()=>{const V=gt(Q)(G);if(V.tag==="Nothing")return 0+F;if(V.tag==="Just")return V._1+F;g()})())(G))(S)(zi(u)(D)),h=(()=>{if(_==="HRight")return n;if(_==="HLeft")return se(n);g()})(),p=D=>{const F=gt(D)(r);if(F.tag==="Nothing")return 1;if(F.tag==="Just")return F._1._1;g()},m=_r(hn(Ht(D=>F=>O(S=>b(S,D))(F))(n))),w=(D,F)=>Re(3)(D)==="$d:"&&Re(3)(F)==="$d:"||Re(3)(D)==="$d:"||Re(3)(F)==="$d:"?10:nt(t.nodeGap),y=T(D=>F=>Tc(S=>N("Just",[...(()=>{if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})(),F]))(F.to.node)(D))(I)(i),x=T(D=>F=>Tc(S=>N("Just",[...(()=>{if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})(),F]))(F.from.node)(D))(I)(i),v=hn(n),C=T(D=>F=>{const S=gt(F)(u.root),G=(()=>{if(S.tag==="Nothing")return F;if(S.tag==="Just")return S._1;g()})();return F===G?D:Tc(Q=>N("Just",(()=>{if(Q.tag==="Nothing")return!0;if(Q.tag==="Just")return Q._1;g()})()&&Re(3)(F)==="$d:"))(G)(D)})(_r(O(D=>b(D,!0))(Qo(P.compare)((()=>{const D=(F,S)=>{if(F.tag==="Leaf")return S;if(F.tag==="Node")return D(F._5,Lt("Cons",F._4,D(F._6,S)));g()};return Zt(de.foldr,D(u.root,$))})()))))(v),L=(D,F)=>{const S=D.free,G=gt(S)(u.root),Q=(()=>{if(G.tag==="Nothing")return S;if(G.tag==="Just")return G._1;g()})(),V=gt(Q)(C),X=(()=>{if(V.tag==="Nothing")return!0;if(V.tag==="Just")return V._1;g()})();return T(U=>q=>{if(U.edge.tag==="Just")return U;if(U.edge.tag==="Nothing"){if((()=>{const pt=gt(Q)(F.su);return!X&&(()=>{const vt=gt(q.from.node)(m);return q.from.node!==q.to.node&&(()=>{const Gt=gt(q.to.node)(m);return(()=>{if(vt.tag==="Nothing")return-1;if(vt.tag==="Just")return vt._1;g()})()===(()=>{if(Gt.tag==="Nothing")return-1;if(Gt.tag==="Just")return Gt._1;g()})()})()})()||(()=>{if(pt.tag==="Nothing")return!1;if(pt.tag==="Just")return pt._1;g()})()})())return U;const K=q.from.node===S?q.to.node:q.from.node,et=gt(K)(u.root),lt=(()=>{if(et.tag==="Nothing")return K;if(et.tag==="Just")return et._1;g()})(),bt=lt!==Q;return bt&&(()=>{const pt=gt(lt)(F.blockFinished);if(pt.tag==="Nothing")return!1;if(pt.tag==="Just")return pt._1;g()})()?{...U,edge:N("Just",q),hasEdges:!0}:{...U,hasEdges:U.hasEdges||bt}}g()})({edge:J,hasEdges:!1})((()=>{if(D.isRoot){if(_==="HRight"){const U=gt(S)(y);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;g()}if(_==="HLeft"){const U=gt(S)(x);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1}g()}if(_==="HRight"){const U=gt(S)(x);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;g()}if(_==="HLeft"){const U=gt(S)(y);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1}g()})())},E=(D,F,S,G)=>{const Q=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),V={free:F,isRoot:S},X=L(V,G);if(X.edge.tag==="Nothing")return X.hasEdges?{thresh:Q,state:{...G,queue:[...G.queue,V]}}:{thresh:Q,state:G};if(X.edge.tag==="Just"){const U=X.edge._1.from.node===F?X.edge._1.to.node:X.edge._1.from.node;return{thresh:(()=>{const q=gt((()=>{const bt=gt(U)(u.root);if(bt.tag==="Nothing")return U;if(bt.tag==="Just")return bt._1;g()})())(G.x),K=gt(U)(a),et=gt(F)(a),lt=(()=>{if(q.tag==="Just")return q._1;if(q.tag==="Nothing")return J;g()})();return(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()+(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+d(X.edge._1,U,(()=>{if(S){if(_==="HRight")return Se;if(_==="HLeft")return Le;g()}if(_==="HRight")return Le;if(_==="HLeft")return Se;g()})())-(()=>{if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1;g()})()-d(X.edge._1,F,(()=>{if(S){if(_==="HRight")return Le;if(_==="HLeft")return Se;g()}if(_==="HRight")return Se;if(_==="HLeft")return Le;g()})())})(),state:{...G,su:rt(P)((()=>{const q=gt(X.edge._1.from.node)(u.root);if(q.tag==="Nothing")return X.edge._1.from.node;if(q.tag==="Just")return q._1;g()})())(!0)(rt(P)((()=>{const q=gt(X.edge._1.to.node)(u.root);if(q.tag==="Nothing")return X.edge._1.to.node;if(q.tag==="Just")return q._1;g()})())(!0)(G.su))}}}g()},B=(D,F,S,G)=>{const Q=F===D,V=gt(F)(u.align),X=(()=>{if(V.tag==="Nothing")return F===D;if(V.tag==="Just")return V._1===D;g()})();if(!(Q||X))return{thresh:S,state:G};const U=(()=>{if(c==="VDown")return Q&&S<=-1e18;if(c==="VUp")return Q&&S>=1e18;g()})()?E(D,F,!0,G):{thresh:S,state:G};return(()=>{if(c==="VDown")return U.thresh<=-1e18&&X;if(c==="VUp")return U.thresh>=1e18&&X;g()})()?E(D,F,!1,U.state):U},z=D=>F=>S=>{const G=gt(S)(e.nodeIndex),Q=(()=>{if(G.tag==="Nothing")return 0;if(G.tag==="Just")return G._1;g()})(),V=re(et=>en(tr)(S)(et))(h),X=(()=>{if(V.tag==="Nothing")return[];if(V.tag==="Just")return V._1;g()})(),U=X.length;if((()=>{if(c==="VDown")return Q<=0;if(c==="VUp")return Q>=(U-1|0);g()})()){const et=B(D,S,F.thresh,F.st);return{...F,st:et.state,thresh:et.thresh}}const q=(()=>{if(c==="VDown")return Q-1|0;if(c==="VUp")return Q+1|0;g()})(),K=q>=0&&q<X.length?N("Just",X[q]):J;if(K.tag==="Nothing")return F;if(K.tag==="Just"){const et=gt(K._1)(u.root),lt=(()=>{if(et.tag==="Nothing")return K._1;if(et.tag==="Just")return et._1;g()})(),bt=B(D,S,F.thresh,Y(lt)(F.st)),pt=(()=>{const Mt=gt(D)(bt.state.sink);if(Mt.tag==="Nothing")return D===D;if(Mt.tag==="Just")return Mt._1===D;g()})()?{...bt.state,sink:rt(P)(D)((()=>{const Mt=gt(lt)(bt.state.sink);if(Mt.tag==="Nothing")return lt;if(Mt.tag==="Just")return Mt._1;g()})())(bt.state.sink)}:bt.state,vt=gt(lt)(pt.sink),Gt=(()=>{if(vt.tag==="Nothing")return lt;if(vt.tag==="Just")return vt._1;g()})(),jt=gt(D)(pt.sink),Ct=(()=>{if(jt.tag==="Nothing")return D;if(jt.tag==="Just")return jt._1;g()})();if(Ct===Gt){const Mt=gt(lt)(pt.x),ne=(()=>{if(Mt.tag==="Just")return Mt._1;if(Mt.tag==="Nothing")return J;g()})(),Cn=(()=>{if(ne.tag==="Nothing")return 0;if(ne.tag==="Just")return ne._1;g()})(),qe=gt(D)(pt.x),Ot=(()=>{if(qe.tag==="Just")return qe._1;if(qe.tag==="Nothing")return J;g()})(),qt=(()=>{if(Ot.tag==="Nothing")return 0;if(Ot.tag==="Just")return Ot._1;g()})(),Oe=w(S,K._1),bn=gt(K._1)(a),tn=gt(S)(a),_n=(()=>{if(bn.tag==="Nothing")return 0;if(bn.tag==="Just")return bn._1;g()})()-(()=>{if(tn.tag==="Nothing")return 0;if(tn.tag==="Just")return tn._1;g()})();if(c==="VDown"){const Ae=gr(Cn+_n+p(K._1)+Oe)(bt.thresh);return{st:{...pt,x:rt(P)(D)(N("Just",F.initial?Ae:gr(qt)(Ae)))(pt.x)},initial:!1,thresh:bt.thresh}}if(c==="VUp"){const Ae=Sn(Cn+_n-Oe-p(S))(bt.thresh);return{st:{...pt,x:rt(P)(D)(N("Just",F.initial?Ae:Sn(qt)(Ae)))(pt.x)},initial:!1,thresh:bt.thresh}}g()}const Yt=gt(lt)(pt.x),Rt=(()=>{if(Yt.tag==="Just")return Yt._1;if(Yt.tag==="Nothing")return J;g()})(),wt=(()=>{if(Rt.tag==="Nothing")return 0;if(Rt.tag==="Just")return Rt._1;g()})(),mt=gt(D)(pt.x),ct=(()=>{if(mt.tag==="Just")return mt._1;if(mt.tag==="Nothing")return J;g()})(),yt=(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})(),dt=nt(t.nodeGap),ht=gt(S)(a),Et=gt(K._1)(a),Dt=(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()-(()=>{if(Et.tag==="Nothing")return 0;if(Et.tag==="Just")return Et._1;g()})();return{st:{...pt,classEdges:[...pt.classEdges,{src:Ct,tgt:Gt,sep:(()=>{if(c==="VDown")return yt+Dt-wt-p(K._1)-dt;if(c==="VUp")return yt+Dt+p(S)+dt-wt;g()})()}]},initial:F.initial,thresh:bt.thresh}}g()},Y=D=>F=>{const S=gt(D)(F.x),G=(()=>{if(S.tag==="Just")return S._1;if(S.tag==="Nothing")return J;g()})();if(G.tag==="Just")return F;if(G.tag==="Nothing"){const Q=T(z(D))({st:{...F,x:rt(P)(D)(N("Just",0))(F.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})()})(zi(u)(D));return{...Q.st,blockFinished:rt(P)(D)(!0)(Q.st.blockFinished)}}g()},R=T(D=>F=>T(S=>G=>{const Q=gt(G)(u.root),V=(()=>{if(Q.tag==="Nothing")return G;if(Q.tag==="Just")return Q._1;g()})();return V===G?Y(V)(S):S})(D)((()=>{if(c==="VDown")return F;if(c==="VUp")return se(F);g()})()))({x:_r(O(D=>b(D,J))(v)),sink:_r(O(D=>b(D,D))(v)),classEdges:[],su:I,blockFinished:I,queue:[]})(h),A=Xw(R.classEdges)(R.sink)(c),j=(D,F,S,G)=>{const Q=gt(F)(G),V=gt(F)(a);return(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;g()})()+(()=>{if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1;g()})()+d(D,F,S)},Z=_r(O(D=>b(D,!0))(Qo(P.compare)((()=>{const D=(F,S)=>{if(F.tag==="Leaf")return S;if(F.tag==="Node")return D(F._5,Lt("Cons",F._4,D(F._6,S)));g()};return Zt(de.foldr,D(u.root,$))})()))),M=D=>F=>S=>{const G=L(S,{su:F.su,blockFinished:Z}),Q={phase:D,ppFree:S.free,ppIsRoot:S.isRoot,edgeId:J,delta:0,avail:0,shift:0,freeSu:(()=>{const V=gt((()=>{const X=gt(S.free)(u.root);if(X.tag==="Nothing")return S.free;if(X.tag==="Just")return X._1;g()})())(F.su);if(V.tag==="Nothing")return!1;if(V.tag==="Just")return V._1;g()})(),hasEdges:G.hasEdges,candCount:(()=>{if(S.isRoot){if(_==="HRight"){const V=gt(S.free)(y);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length;g()}if(_==="HLeft"){const V=gt(S.free)(x);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length}g()}if(_==="HRight"){const V=gt(S.free)(x);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length;g()}if(_==="HLeft"){const V=gt(S.free)(y);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length}g()})()};if(G.edge.tag==="Nothing")return{...F,stack:[...F.stack,S],trace:[...F.trace,Q],x:F.x};if(G.edge.tag==="Just"){const V=G.edge._1.from.node===S.free?b(G.edge._1.from.node,G.edge._1.to.node):b(G.edge._1.to.node,G.edge._1.from.node),X=j(G.edge._1,V._1,l(G.edge._1,V._1),F.x)-j(G.edge._1,V._2,l(G.edge._1,V._2),F.x),U=gt(V._1)(u.root),q=(()=>{if(U.tag==="Nothing")return V._1;if(U.tag==="Just")return U._1;g()})(),K={...Q,edgeId:N("Just",G.edge._1.id),delta:X};if(X>0&&X<1e300){const et=T(pt=>vt=>{const Gt=gt(vt)(m),jt=(()=>{if(Gt.tag==="Nothing")return-1;if(Gt.tag==="Just")return Gt._1;g()})();if(jt>=0&&jt<n.length){const Rt=n[jt],wt=gt(vt)(e.nodeIndex),mt=(()=>{if(wt.tag==="Nothing")return-2;if(wt.tag==="Just")return wt._1-1|0;g()})();return mt>=0&&mt<Rt.length?Sn(pt)((()=>{const ct=gt(vt)(F.x),yt=gt(vt)(a),dt=gt(Rt[mt])(F.x),ht=gt(Rt[mt])(a);return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._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()})()+(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+p(Rt[mt])+w(vt,Rt[mt]))})()):pt}const Ct=gt(vt)(e.nodeIndex),Yt=(()=>{if(Ct.tag==="Nothing")return-2;if(Ct.tag==="Just")return Ct._1-1|0;g()})();return Yt>=0&&Yt<0?Sn(pt)((()=>{const Rt=gt(vt)(F.x),wt=gt(vt)(a),mt=gt([][Yt])(F.x),ct=gt([][Yt])(a);return(()=>{if(Rt.tag==="Nothing")return 0;if(Rt.tag==="Just")return Rt._1;g()})()+(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1;g()})()-((()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()+(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+p([][Yt])+w(vt,[][Yt]))})()):pt})(X)(zi(u)(q)),lt=et>0?-et:0,bt={...F,x:et>0?f(q,lt,F.x):F.x,trace:[...F.trace,{...K,avail:et,shift:lt}]};return et>0?bt:{...bt,stack:[...bt.stack,S]}}if(X<0&&-X<1e300){const et=T(pt=>vt=>{const Gt=gt(vt)(m),jt=(()=>{if(Gt.tag==="Nothing")return-1;if(Gt.tag==="Just")return Gt._1;g()})();if(jt>=0&&jt<n.length){const Rt=n[jt],wt=gt(vt)(e.nodeIndex),mt=(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1+1|0;g()})();return mt>=0&&mt<Rt.length?Sn(pt)((()=>{const ct=gt(Rt[mt])(F.x),yt=gt(Rt[mt])(a),dt=gt(vt)(F.x),ht=gt(vt)(a);return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._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()})()+(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+p(vt)+w(vt,Rt[mt]))})()):pt}const Ct=gt(vt)(e.nodeIndex),Yt=(()=>{if(Ct.tag==="Nothing")return 0;if(Ct.tag==="Just")return Ct._1+1|0;g()})();return Yt>=0&&Yt<0?Sn(pt)((()=>{const Rt=gt([][Yt])(F.x),wt=gt([][Yt])(a),mt=gt(vt)(F.x),ct=gt(vt)(a);return(()=>{if(Rt.tag==="Nothing")return 0;if(Rt.tag==="Just")return Rt._1;g()})()+(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1;g()})()-((()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()+(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+p(vt)+w(vt,[][Yt]))})()):pt})(-X)(zi(u)(q)),lt=et>0?et:0,bt={...F,x:et>0?f(q,lt,F.x):F.x,trace:[...F.trace,{...K,avail:et,shift:lt}]};return et>0?bt:{...bt,stack:[...bt.stack,S]}}return{...F,stack:[...F.stack,S],trace:[...F.trace,K],x:F.x}}g()},W=T(M(Vw))({x:_r(O(D=>b(D,(()=>{const F=gt(D)(u.root),S=(()=>{if(F.tag==="Nothing")return D;if(F.tag==="Just")return F._1;g()})(),G=gt(S)(R.x),Q=gt((()=>{const X=gt(S)(R.sink);if(X.tag==="Nothing")return S;if(X.tag==="Just")return X._1;g()})())(A),V=(()=>{if(G.tag==="Just")return G._1;if(G.tag==="Nothing")return J;g()})();return(()=>{if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1;g()})()+(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;g()})()})()))(v)),su:R.su,stack:[],trace:[]})(R.queue),H=T(M(Uw))({...W,stack:[]})(se(W.stack));return{x:H.x,queue:R.queue,trace:H.trace}},jw=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>_=>Kw(t)(e)(n)(r)(o)(i)(s)(a)(u)(c)(_).x,Zw=t=>e=>n=>r=>o=>i=>{const s=(u,c,_)=>{const d=gt(c)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;g()})(),f=u.from.node===c?u.from.port:u.to.node===c?u.to.port:J;if(f.tag==="Just"){const h=gt(c)(e);if(h.tag==="Just"){const p=re(m=>m.id===f._1)(h._1);if(p.tag==="Just"){const m=nt(p._1.offset)*nt(4);return _==="North"||_==="South"?m:0}if(p.tag==="Nothing"){const m=ai(o)(u.id)(_)(l);return _==="North"||_==="South"?m:0}g()}if(h.tag==="Nothing"){const p=ai(o)(u.id)(_)(l);return _==="North"||_==="South"?p:0}g()}if(f.tag==="Nothing"){const h=ai(o)(u.id)(_)(l);return _==="North"||_==="South"?h:0}g()},a=u=>c=>_=>d=>{let l=u,f=c,h=_,p=d,m=!0,w;for(;m;){const y=l,x=f,v=h,C=Ft(L=>J,L=>E=>N("Just",{head:L,tail:E}),p);if(C.tag==="Nothing"){m=!1,w=y;continue}if(C.tag==="Just"){const L=C._1.head,E=re(z=>z.from.node===v&&z.to.node===L||z.from.node===L&&z.to.node===v)(r),B=(()=>{if(E.tag==="Nothing")return x+0;if(E.tag==="Just")return x+(s(E._1,v,E._1.from.node===v?Se:Le)-s(E._1,L,E._1.from.node===L?Se:Le));g()})();l=rt(P)(L)(B)(y),f=B,h=L,p=C._1.tail;continue}g()}return w};return T(u=>c=>{const _=Ft(f=>J,f=>h=>N("Just",{head:f,tail:h}),zi(t)(c)),d=(()=>{if(_.tag==="Nothing")return rt(P)(c)(0)(I);if(_.tag==="Just")return a(rt(P)(_._1.head)(0)(I))(0)(_._1.head)(_._1.tail);g()})(),l=T(f=>h=>gr(f)(-h._2))(0)(vc(d));return T(f=>h=>rt(P)(h._1)(h._2+l)(f))(u)(vc(d))})(I)(Qo(P.compare)((()=>{const u=(c,_)=>{if(c.tag==="Leaf")return _;if(c.tag==="Node")return u(c._5,Lt("Cons",c._4,u(c._6,_)));g()};return Zt(de.foldr,u(t.root,$))})()))},tJ=t=>e=>{const n=(o,i,s)=>Re(3)(i)==="$d:"&&p_(e1,(()=>{const a=gt(i)(t.preds);if(a.tag==="Nothing")return[];if(a.tag==="Just")return a._1;g()})()),r=o=>i=>s=>a=>u=>c=>_=>{let d=o,l=i,f=a,h=c,p=_,m=!0,w;for(;m;){const y=d,x=l,v=f,C=h,L=p,E=x.length;if(L>=E){m=!1,w=y;continue}const B=L>=0&&L<x.length?N("Just",x[L]):J,z=(()=>{if(B.tag==="Nothing")return"";if(B.tag==="Just")return B._1;g()})(),Y=n(t,z);if(L===(E-1|0)||Y){const R=(()=>{if(Y){const A=gt(z)(t.preds),j=(()=>{if(A.tag==="Nothing")return[];if(A.tag==="Just")return A._1;g()})();if(0<j.length){const Z=v-1|0,M=gt(j[0])(t.nodeIndex);if(M.tag==="Nothing")return Z;if(M.tag==="Just")return M._1;g()}}return v-1|0})();d=T(A=>j=>{if(j>=0&&j<x.length){const Z=x[j];return n(t,Z)?A:T(M=>W=>{const H=gt(W)(t.nodeIndex),D=(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})();return D<C||D>R?rt(P)(W+"\u2192"+Z)()(M):M})(A)((()=>{const M=gt(Z)(t.preds);if(M.tag==="Nothing")return[];if(M.tag==="Just")return M._1;g()})())}return n(t,"")?A:T(Z=>M=>{const W=gt(M)(t.nodeIndex),H=(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})();return H<C||H>R?rt(P)(M+"\u2192")()(Z):Z})(A)((()=>{const Z=gt("")(t.preds);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;g()})())})(y)(Kt(0,L)),l=x,f=v,h=R,p=L+1|0;continue}d=y,l=x,f=v,h=C,p=L+1|0}return w};return e.length<3?I:T(o=>i=>{if(i>=0&&i<e.length){const s=e[i];return r(o)((()=>{const a=i+1|0;return a>=0&&a<e.length?e[a]:[]})())(s)(s.length)(i)(0)(0)}return r(o)((()=>{const s=i+1|0;return s>=0&&s<e.length?e[s]:[]})())([])(0)(i)(0)(0)})(I)(Kt(1,e.length-2|0))},eJ=t=>e=>n=>r=>o=>{const i=hn(e),s=T(a=>u=>{const c=T(_=>d=>{const l=(()=>{if(o==="HRight"){const m=gt(d)(t.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()}if(o==="HLeft"){const m=gt(d)(t.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}g()})(),f=l.length;if(f===0)return _;const h=Tr(f-1|0,2),p=Tr(f,2);return T(m=>w=>{if((()=>{const y=gt(d)(m.align);if(y.tag==="Nothing")return d!==d;if(y.tag==="Just")return y._1!==d;g()})())return m;if(w>=0&&w<l.length){const y=gt(l[w])(t.nodeIndex),x=(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;g()})();if(!(w1(l[w]+"\u2192"+d)(n)||w1(d+"\u2192"+l[w])(n))&&(()=>{if(r==="VDown")return m.r<x;if(r==="VUp")return m.r>x;g()})()){const v=gt(l[w])(m.root),C=(()=>{if(v.tag==="Nothing")return l[w];if(v.tag==="Just")return v._1;g()})();return{root:rt(P)(d)(C)(m.root),align:rt(P)(l[w])(d)(rt(P)(d)(C)(m.align)),r:x}}}return m})(_)((()=>{if(r==="VDown")return Kt(h,p);if(r==="VUp")return se(Kt(h,p));g()})())})({root:a.root,align:a.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;g()})()})((()=>{if(r==="VDown")return u;if(r==="VUp")return se(u);g()})());return{root:c.root,align:c.align}})({root:_r(O(a=>b(a,a))(i)),align:_r(O(a=>b(a,a))(i))})((()=>{if(o==="HRight")return e;if(o==="HLeft")return se(e);g()})());return{root:s.root,align:s.align}},ea=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>{const _=eJ(e)(n)(a)(u)(c),d=Zw(_)(o)(r)(i)(s)(c);return Z0()(l=>f=>N("Just",(()=>{const h=gt(l)(d);if(h.tag==="Nothing")return f+0;if(h.tag==="Just")return f+h._1;g()})()))(jw(t)(e)(n)(r)(o)(i)(s)(d)(_)(u)(c))},N1=t=>e=>Ht(n=>r=>T(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=Kt(0,e.length-1|0);return n<1?[]:Bt(0,n,o)})()))(e),nJ=t=>e=>n=>r=>o=>i=>s=>{const a=Hw(0)(e.length-1|0),u=nt(t.layerGap),c=s(A0(a,u)),_=Fw(g1(o)(c)(r)(i)(I))(c);return O(d=>{const l=$w(d)(_);return l.tag==="Just"&&l._1>0?gr(u)(2+nt(l._1-1|0)*2.5):u})(Kt(0,a-1|0))},T1=t=>e=>n=>r=>p_(o=>T(i=>s=>{if(!i.ok)return i;const a=gt(s)(r),u=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})(),c=gt(s)(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),rJ=t=>e=>n=>r=>{const o=Pt(i=>s=>ot.compare(i.w)(s.w))(O(i=>({l:i,w:J1(i)}))(ft(T1()(e)(n),r)));return 0<o.length?N("Just",o[0].l):J},oJ=t=>e=>{const n=_r(hn(O(Ht(o=>i=>b(i,o)))(t))),r=o=>Pt(i=>s=>it.compare((()=>{const a=gt(i)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})())((()=>{const a=gt(s)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})()))(o);return{preds:(()=>{const o=i=>{if(i.tag==="Leaf")return I;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(T(i=>s=>Qt(P)(le)(s.to.node)([s.from.node])(i))(I)(e))})(),succs:(()=>{const o=i=>{if(i.tag==="Leaf")return I;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(T(i=>s=>Qt(P)(le)(s.from.node)([s.to.node])(i))(I)(e))})(),nodeIndex:n}},iJ=t=>e=>{const n=Pt(d=>l=>ot.compare(d.w)(l.w))(Ht(d=>l=>({i:d,l,w:J1(l)}))(e)),r=0<n.length?N("Just",n[0]):J,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]):J,s=(()=>{if(i.tag==="Just")return(d=>l=>{let f=d,h=l,p=!0,m;for(;p;){const w=f,y=h;if(y.tag==="Nil"){p=!1,m=w;continue}if(y.tag==="Cons"){f=Sn(w)(y._1),h=y._2;continue}g()}return m})(999999)((()=>{const d=(l,f)=>{if(l.tag==="Leaf")return f;if(l.tag==="Node")return d(l._5,Lt("Cons",l._4,d(l._6,f)));g()};return d(i._1,$)})());if(i.tag==="Nothing")return 0;g()})(),a=d=>T(l=>f=>gr(l)((()=>{const h=gt(f._1)(t);if(h.tag==="Nothing")return f._2+1;if(h.tag==="Just")return f._2+h._1._1;g()})()))(-999999)(vc(d)),u=o>=0&&o<e.length?N("Just",e[o]):J,c=(()=>{if(u.tag==="Just")return a(u._1);if(u.tag==="Nothing")return 0;g()})(),_=Fe(d=>l=>{const f=h=>{if(h.tag==="Leaf")return I;if(h.tag==="Node")return te("Node",h._1,h._2,h._3,h._4+l,f(h._5),f(h._6));g()};return f(d)},e,Ht(d=>l=>Hr(d)(2)===0?s-(f=>h=>{let p=f,m=h,w=!0,y;for(;w;){const x=p,v=m;if(v.tag==="Nil"){w=!1,y=x;continue}if(v.tag==="Cons"){p=Sn(x)(v._1),m=v._2;continue}g()}return y})(999999)((()=>{const f=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return f(h._5,Lt("Cons",h._4,f(h._6,p)));g()};return f(l,$)})()):c-a(l))(e));return Yw(T(d=>l=>{const f=Pt(ot.compare)(Tt(gt(l))(_));return rt(P)(l)(f.length===4?1<f.length&&2<f.length?(f[1]+f[2])/2:0:0<f.length?f[0]:0)(d)})(I)(Qo(P.compare)(hn(O(d=>{const l=f=>{if(f.tag==="Leaf")return I;if(f.tag==="Node")return te("Node",f._1,f._2,f._3,void 0,l(f._5),l(f._6));g()};return Zt(fn.foldr,l(d))})(_)))))},sJ=t=>e=>n=>r=>o=>i=>{const s=oJ(e)(o),a=tJ(s)(e),u={nodeGap:t.nodeGap*4|0},c=Me(P.compare,Ie,_r(O(f=>b(f,b(1,1)))(ft(e1,hn(e)))),(()=>{const f=h=>{if(h.tag==="Leaf")return I;if(h.tag==="Node")return te("Node",h._1,h._2,h._3,b(h._4._1*nt(4),h._4._2),f(h._5),f(h._6));g()};return f(n)})()),_=[ea(u)(s)(e)(c)(r)(o)(i)(a)(p1)(y1),ea(u)(s)(e)(c)(r)(o)(i)(a)(m1)(y1),ea(u)(s)(e)(c)(r)(o)(i)(a)(p1)(x1),ea(u)(s)(e)(c)(r)(o)(i)(a)(m1)(x1)],d=iJ(c)(_);if(T1()(e)(c)(d))return d;const l=rJ()(e)(c)(_);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return _[0];g()},aJ=t=>e=>n=>r=>{const o=d_(J,a_,i=>i.node===e?N("Just",i.position):J,t);if(o.tag==="Nothing")return t;if(o.tag==="Just"){const i=o._1;return O(s=>s.node===n?{...s,position:b(i._1+r._1,i._2+r._2)}:s)(t)}g()},uJ=t=>e=>n=>r=>{const o=ft(s=>en(tr)(s.node)(e),t),i=(()=>{if(n==="Vertical"){if(r==="Start")return T(s=>a=>Sn(s)(a.position._1))(99999)(o);if(r==="End")return T(s=>a=>gr(s)(a.position._1))(0)(o);if(r==="Center"){const s=T(a=>u=>a+u.position._1)(0)(o);return o.length===0?0:s/nt(o.length)}g()}if(n==="Horizontal"){if(r==="Start")return T(s=>a=>Sn(s)(a.position._2))(99999)(o);if(r==="End")return T(s=>a=>gr(s)(a.position._2))(0)(o);if(r==="Center"){const s=T(a=>u=>a+u.position._2)(0)(o);return o.length===0?0:s/nt(o.length)}}g()})();return O(s=>{if(en(tr)(s.node)(e)){if(n==="Vertical")return{...s,position:b(i,s.position._2)};if(n==="Horizontal")return{...s,position:b(s.position._1,i)};g()}return s})(t)},cJ=t=>e=>T(n=>r=>r.tag==="AlignGroup"?uJ(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?aJ(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),gJ=t=>e=>n=>r=>o=>i=>s=>a=>{const u=O(d=>T(l=>f=>gr(l)((()=>{const h=gt(f)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;g()})()))(1)(d))(n),c=sJ(t)(n)(r)(o)(i)(a),_=N1(nJ(t)(n)(r)(o)(i)(s)(d=>{const l=N1(d)(u);return hn(Ht(f=>h=>Ht(p=>m=>({node:m,position:b((()=>{const w=gt(m)(c);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;g()})()/nt(4)})(),f>=0&&f<l.length?l[f]:0),size:(()=>{const w=Re(3)(m)==="$d:"?b(0,1):b(1,1),y=gt(m)(r);if(y.tag==="Nothing")return w;if(y.tag==="Just")return y._1;g()})(),layer:f,order:p}))(h))(n))}))(u);return cJ(e)(hn(Ht(d=>l=>Ht(f=>h=>({node:h,position:b((()=>{const p=gt(h)(c);return(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})()/nt(4)})(),d>=0&&d<_.length?_[d]:0),size:(()=>{const p=Re(3)(h)==="$d:"?b(0,1):b(1,1),m=gt(h)(r);if(m.tag==="Nothing")return p;if(m.tag==="Just")return m._1;g()})(),layer:d,order:f}))(l))(n)))},Cc=Iu(ks)(_o(32)),v1=Iu(ks)(_o(31)),Wi=(()=>{const t=qm("25214903917");if(t.tag==="Nothing")return F_;if(t.tag==="Just")return t._1;g()})(),qi=Au(Iu(ks)(_o(48)))(ks),_J=t=>{const e=Om(t);return Pi(Q_((()=>{if(e.tag==="Nothing")return F_;if(e.tag==="Just")return e._1;g()})())(Wi))(qi)},bc=_o(11),na=t=>e=>{const n=Pi(Cs(bs(e)(Wi))(bc))(qi);return b((()=>{const r=y_(Qm(Fu(n)(_o(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},fJ=t=>{const e=na(26)(t),n=na(27)(e._2);return b((nt(e._1)*yu(2)(27)+nt(n._1))/yu(2)(53),n._2)},dJ=t=>e=>{const n=T(r=>o=>{const i=fJ(r.finalR);return{rs:[...r.rs,i._1],finalR:i._2}})({rs:[],finalR:t})(e);return b(O(r=>r.x)(Pt(r=>o=>ot.compare(r.k)(o.k))(Fe(r=>o=>({x:r,k:o}),e,n.rs))),n.finalR)},lJ=t=>{const e=Pi(Cs(bs(t)(Wi))(bc))(qi),n=Pi(Cs(bs(e)(Wi))(bc))(qi);return b(Cs(bs((()=>{const r=Fu(e)(_o(16));return M_.compare(r)(v1)!=="LT"?Au(r)(Cc):r})())(Cc))((()=>{const r=Fu(n)(_o(16));return M_.compare(r)(v1)!=="LT"?Au(r)(Cc):r})()),n)},Oi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ra=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},kc=ce(P)(zt),ui=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},oa=ce(P)(zt),hJ=pu(vi),pJ=T(nr)(0),mJ=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},C1=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},yJ=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const o=Or(Ut,J,t,n[e],n);if(o.tag==="Just")return Or(Ut,J,e,r,o._1);if(o.tag==="Nothing")return J;g()}}return J},xJ=t=>e=>n=>r=>o=>kc(T(i=>s=>{const a=Pt(u=>c=>it.compare((()=>{const _=Oi(u.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;g()})())((()=>{const _=Oi(c.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;g()})()))(ft(u=>ra(u.to.node)(n),ft(u=>u.from.node===s,r)));return{ranks:[...i.ranks,...Ht(u=>c=>b(c.id,nt((i.rankSum+u|0)+1|0)))(a)],rankSum:i.rankSum+a.length|0}})({ranks:[],rankSum:0})(t).ranks),wJ=t=>e=>n=>r=>o=>kc(T(i=>s=>{const a=Pt(c=>_=>{const d=it.compare((()=>{const l=ui(_.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=ui(c.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})());return d==="EQ"?it.compare((()=>{const l=Oi(c.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})())((()=>{const l=Oi(_.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})()):d})(ft(c=>ra(c.from.node)(n),ft(c=>c.to.node===s,r))),u=a.length;return{ranks:[...i.ranks,...Ht(c=>_=>b(_.id,nt((i.rankSum+u|0)-c|0)))(a)],rankSum:i.rankSum+u|0}})({ranks:[],rankSum:0})(t).ranks),Lc=t=>e=>n=>{const r=oa(Ht(a=>u=>b(u,a))(t)),o=oa(Ht(a=>u=>b(u,a))(e)),i=Tt(a=>{const u=ui(a.from.node)(r),c=ui(a.to.node)(o);if(u.tag==="Just"&&c.tag==="Just")return N("Just",b(u._1,c._1));const _=ui(a.from.node)(o),d=ui(a.to.node)(r);return _.tag==="Just"&&d.tag==="Just"?N("Just",b(d._1,_._1)):J})(n),s=i.length;return T(a=>u=>T(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)(a)(Kt(u+1|0,s-1|0)))(0)(Kt(0,s-2|0))},JJ=t=>e=>n=>r=>{const o=i=>s=>{let a=i,u=s,c=!0,_;for(;c;){const d=a,l=u;if(l>=(d.length-1|0)){c=!1,_=d;continue}if(l>=0&&l<d.length){const f=l+1|0;if(f>=0&&f<d.length){const h=d[l],p=d[f];if(xe(x=>x.before===h&&x.after===p,r)){a=d,u=l+1|0;continue}const m=Or(Ut,J,l,p,d),w=(()=>{if(m.tag==="Just")return Or(Ut,J,l+1|0,h,m._1);if(m.tag==="Nothing")return J;g()})(),y=(()=>{if(w.tag==="Nothing")return d;if(w.tag==="Just")return w._1;g()})();if(Lc(e)(y)(n)<Lc(e)(d)(n)){a=y,u=l+1|0;continue}a=d,u=l+1|0;continue}c=!1,_=d;continue}c=!1,_=d}return _};return(i=>{let s=i,a=!0,u;for(;a;){const c=s,_=o(c)(0);if(hJ(_)(c)){a=!1,u=c;continue}s=_}return u})(t)},ia=t=>e=>T(n=>r=>{if(r>=0&&r<t.length){const o=t[r],i=r+1|0;if(i>=0&&i<t.length)return n+Lc(o)(t[i])(e)|0}return n})(0)(Kt(0,t.length-2|0)),NJ=(()=>{const t=e=>{if(e.length<7){const i=s=>a=>{let u=s,c=a,_=!0,d;for(;_;){const l=u,f=c,h=f-1|0;if(h>=0&&h<l.length){if(f>=0&&f<l.length&&f>0&&l[h].key>l[f].key){const p=yJ(f-1|0)(f)(l);if(p.tag==="Just"){u=p._1,c=f-1|0;continue}if(p.tag==="Nothing"){_=!1,d=l;continue}g()}_=!1,d=l;continue}_=!1,d=l}return d};return T(s=>a=>i(s)(a))(e)(Kt(1,e.length-1|0))}const n=Tr(e.length,2),r=t(Bt(0,n,e)),o=t(Bt(n,e.length,e));return(i=>s=>a=>{let u=i,c=s,_=a,d=!0,l;for(;d;){const f=u,h=c,p=_;if(h>=0&&h<r.length){if(p>=0&&p<o.length){if(r[h].key>o[p].key){u=kt(f)(o[p]),c=h,_=p+1|0;continue}u=kt(f)(r[h]),c=h+1|0,_=p;continue}d=!1,l=[...f,...h<1?r:Bt(h,r.length,r)];continue}d=!1,l=[...f,...p<1?o:Bt(p,o.length,o)]}return l})([])(0)(0)};return t})(),TJ=t=>e=>n=>{const r=Tt(c=>c.tag==="OrderConstraint"?N("Just",{before:c._1.before,after:c._1.after}):J)(t.constraints),o=c=>T(_=>d=>{const l=d.after,f=d.before,h=vr(Ut,J,m=>m===f,_),p=vr(Ut,J,m=>m===l,_);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=h_(Ut,J,h._1,_),w=(()=>{if(m.tag==="Nothing")return _;if(m.tag==="Just")return m._1;g()})(),y=l_(Ut,J,p._1,f,w);if(y.tag==="Nothing")return w;if(y.tag==="Just")return y._1;g()}return _})(c)(r),i=kc(Ht(c=>_=>b(_.id,c))(n)),s=(c,_,d)=>{const l=c.length;return T(f=>h=>{const p=_?h-1|0:h+1|0,m=p>=0&&p<f._1.length?N("Just",f._1[p]):J;if(m.tag==="Just"){const w=h>=0&&h<f._1.length?N("Just",f._1[h]):J;if(w.tag==="Just"){const y=oa(Ht(E=>B=>b(B,E))(m._1)),x=oa(Ht(E=>B=>b(B,E))(w._1)),v=_?xJ(m._1)(y)(x)(n)(i):wJ(m._1)(y)(x)(n)(i),C=T(E=>B=>{const z=Tt(R=>Oi(R.id)(v))(ft(_?R=>R.to.node===B._2&&ra(R.from.node)(y):R=>R.from.node===B._2&&ra(R.to.node)(y),n));if(z.length===0)return{...E,items:[...E.items,{n:B._2,key:J,origIdx:B._1}]};const Y=na(24)(E.r);return{items:[...E.items,{n:B._2,key:N("Just",(pJ(z)+(nt(Y._1)*4172325152040912e-24-.03500000014901161))/nt(z.length)),origIdx:B._1}],r:Y._2}})({items:[],r:f._2})(Ht(An)(w._1)),L=Or(Ut,J,h,JJ(o(O(E=>E.n)(NJ((()=>{const E=C.items,B=z=>Y=>{let R=z,A=Y,j=!0,Z;for(;j;){const M=R,W=A;if(M>=0&&M<E.length){if(E[M].key.tag==="Just"){j=!1,Z=E[M].key._1;continue}if(E[M].key.tag==="Nothing"){R=M+1|0,A=W;continue}g()}j=!1,Z=W}return Z};return(z=>Y=>R=>{let A=z,j=Y,Z=R,M=!0,W;for(;M;){const H=A,D=j,F=Z;if(H>=0&&H<E.length){if(E[H].key.tag==="Just"){A=H+1|0,j=E[H].key._1,Z=[...F,{n:E[H].n,key:E[H].key._1,origIdx:E[H].origIdx}];continue}if(E[H].key.tag==="Nothing"){const S=(D+B(H+1|0)(D+1))/2;A=H+1|0,j=S,Z=[...F,{n:E[H].n,key:S,origIdx:E[H].origIdx}];continue}g()}M=!1,W=F}return W})(0)(-1)([])})()))))(m._1)(n)(r),f._1);if(L.tag==="Just")return b(L._1,C.r);if(L.tag==="Nothing")return b(f._1,f._2);g()}if(w.tag==="Nothing")return b(f._1,f._2);g()}if(m.tag==="Nothing")return b(f._1,f._2);g()})(b(c,d))(_?Kt(1,l-1|0):se(Kt(0,l-2|0)))},a=T(c=>_=>rt(P)(_.from.node)()(rt(P)(_.to.node)()(c)))(I)(n),u=T(c=>_=>{if(c.result.crossings===0)return c;const d=y=>x=>v=>C=>{let L=y,E=x,B=v,z=C,Y=!0,R;for(;Y;){const A=L,j=E,Z=B,M=z;if(Z===0){Y=!1,R={layout:A,crossings:0,random:M};continue}const W=s(A,j,M),H=ia(W._1)(n);if(H<Z){L=W._1,E=!j,B=H,z=W._2;continue}Y=!1,R={layout:A,crossings:Z,random:W._2}}return R},l=na(1)(c.result.random),f=l._1!==0,h=t.modelOrder.tag==="Leaf",p=(c.firstTry||c.secondTry)&&!h?c.firstTry:f,m=(()=>{if(!h){const C=s(e,p,l._2);return d(C._1)(!p)(ia(C._1)(n))(C._2)}const y=p?0:mJ(0)(e.length-1|0),x=y>=0&&y<e.length?N("Just",e[y]):J;if(x.tag==="Just"&&x._1.length>1){const C=ft(L=>C1(L)(a),x._1);if(C.length>1){const L=dJ(l._2)(C),E=L._1,B=Or(Ut,J,y,o(T(z=>Y=>C1(Y)(a)?z.idx>=0&&z.idx<E.length?{idx:z.idx+1|0,result:[...z.result,E[z.idx]]}:{idx:z.idx,result:[...z.result,Y]}:{idx:z.idx,result:[...z.result,Y]})({idx:0,result:[]})(x._1).result),e);if(B.tag==="Just"){const z=s(B._1,p,L._2);return d(z._1)(!p)(ia(z._1)(n))(z._2)}}}const v=s(e,p,l._2);return d(v._1)(!p)(ia(v._1)(n))(v._2)})(),w=c.secondTry?!1:c.secondTry;return c.firstTry?{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:c.firstTry,secondTry:w}})({result:{layout:e,crossings:1e9,random:Pi(Q_(lJ(_J(1))._1)(Wi))(qi)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Kt(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:u.layout},vJ=t=>t,b1=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},on=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ci=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Hi=(()=>{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"?Be:r==="GT"?De:P.compare(e._2)(n._2)},Eq0:()=>t}})(),CJ=ce(P)(zt),bJ=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 s=Hi.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},kJ=vJ("Greedy"),Sc=t=>e=>n=>T(r=>o=>{if(o.from.node===o.to.node)return r;if(o.from.node===e&&!b1(o.to.node)(r.marks)){const i=on(o.to.node)(r.inDeg),s=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;g()})(),a=rt(P)(o.to.node)(s)(r.inDeg);return(()=>{const u=on(o.to.node)(r.outDeg);return s<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;g()})()&&!en(tr)(o.to.node)(r.sources)})()?{...r,inDeg:a,sources:[...r.sources,o.to.node]}:{...r,inDeg:a}}if(o.to.node===e&&!b1(o.from.node)(r.marks)){const i=on(o.from.node)(r.outDeg),s=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;g()})(),a=rt(P)(o.from.node)(s)(r.outDeg);return(()=>{const u=on(o.from.node)(r.inDeg);return s<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;g()})()&&!en(tr)(o.from.node)(r.sinks)})()?{...r,outDeg:a,sinks:[...r.sinks,o.from.node]}:{...r,outDeg:a}}return r})({...n,remaining:ft(r=>r!==e,n.remaining)})(t),LJ=T(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return rt(P)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return rt(P)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return rt(P)(e._1.node)(99999)(t)}return t})(I),k1=t=>e=>n=>{const r=on(e)(t),o=on(n)(t);return r.tag==="Just"&&o.tag==="Just"&&r._1>o._1},L1=t=>e=>n=>r=>{if(ci(n)(r.visited)||ci(n)(r.visiting))return r;const o=T(SJ(t)(e)(n))({...r,visiting:rt(P)(n)()(r.visiting)})((()=>{const i=on(n)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;g()})());return{...o,visiting:qo(P)(n)(o.visiting),visited:rt(P)(n)()(o.visited)}},SJ=t=>e=>n=>r=>o=>k1(t)(n)(o)?{...r,backEdges:rt(Hi)(b(n,o))()(r.backEdges)}:ci(o)(r.visiting)?{...r,backEdges:rt(Hi)(b(n,o))()(r.backEdges)}:ci(o)(r.visited)?r:L1(t)(e)(o)(r),EJ=t=>e=>n=>{const r=l=>{let f=l,h=!0,p;for(;h;){const m=f,w=Ft(y=>J,y=>x=>N("Just",{head:y,tail:x}),m.sinks);if(w.tag==="Just"){f=Sc(n)(w._1.head)({...m,sinks:w._1.tail,marks:rt(P)(w._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(w.tag==="Nothing"){const y=Ft(x=>J,x=>v=>N("Just",{head:x,tail:v}),m.sources);if(y.tag==="Just"){f=Sc(n)(y._1.head)({...m,sources:y._1.tail,marks:rt(P)(y._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(y.tag==="Nothing"){const x=C=>{const L=on(C)(m.outDeg),E=on(C)(m.inDeg);return(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;g()})()-(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;g()})()|0},v=Pt(C=>L=>{const E=it.compare(x(L))(x(C));return E==="EQ"?it.compare((()=>{const B=on(C)(e);if(B.tag==="Nothing")return 1e6;if(B.tag==="Just")return B._1;g()})())((()=>{const B=on(L)(e);if(B.tag==="Nothing")return 1e6;if(B.tag==="Just")return B._1;g()})()):E})(m.remaining);if(0<v.length){const C=v[0];f=Sc(n)(C)({...m,remaining:ft(L=>L!==C,m.remaining),marks:rt(P)(C)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}g()}return p},o=Qo(P.compare)([...O(l=>l.from.node)(n),...O(l=>l.to.node)(n)]),i=ft(l=>l.from.node!==l.to.node,n),s=T(l=>f=>Qt(P)(we)(f.to.node)(1)(l))(I)(i),a=T(l=>f=>Qt(P)(we)(f.from.node)(1)(l))(I)(i),u=ft(l=>{const f=on(l)(s);if(f.tag==="Nothing")return!0;if(f.tag==="Just")return f._1===0;g()},o),c=ft(l=>{const f=on(l)(a);if(f.tag==="Nothing")return!0;if(f.tag==="Just")return f._1===0;g()},o),_=o.length+1|0,d=T(l=>f=>{const h=on(f)(l);return h.tag==="Just"&&h._1<0?rt(P)(f)(h._1+_|0)(l):l})(r({remaining:ft(l=>!en(tr)(l)(u)&&!en(tr)(l)(c),o),marks:I,inDeg:s,outDeg:a,sources:u,sinks:c,nextLeft:1,nextRight:-1}).marks)(o);return T(l=>f=>{if(f.from.node===f.to.node)return l;if(k1(t)(f.from.node)(f.to.node))return rt(Hi)(b(f.from.node,f.to.node))()(l);const h=on(f.from.node)(d),p=on(f.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?rt(Hi)(b(f.from.node,f.to.node))()(l):l})(I)(n)},GJ=T(t=>e=>Qt(P)(le)(e.from.node)([e.to.node])(t))(I),PJ=t=>e=>{const n=GJ(e),r=Qo(P.compare)([...O(i=>i.from.node)(e),...O(i=>i.to.node)(e)]),o=T(i=>s=>rt(P)(s.to.node)()(i))(I)(e);return T(i=>s=>L1(t)(n)(s)(i))({visiting:I,visited:I,backEdges:I})([...ft(i=>!ci(i)(o),r),...ft(i=>ci(i)(o),r)]).backEdges},BJ=t=>e=>n=>r=>{const o=CJ(Ht(a=>u=>b(u,a))(e)),i=LJ(n),s=(()=>{if(t==="DepthFirst")return PJ(i)(r);if(t==="Greedy")return EJ(i)(o)(r);g()})();return{edges:O(a=>bJ(b(a.from.node,a.to.node))(s)?{...a,from:a.to,to:a.from}:a)(r),reversedEdges:s}},S1=zt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),ve=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ce=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},$i=t=>e=>n=>r=>S1(o=>n>=o.x&&n<o.x+o.w&&e>o.y&&t<o.y+o.h)(r),sa=t=>e=>n=>r=>$i(ve(e)(n))(Ce(e)(n))(r)(t),aa=nt(4),DJ=ys(t=>{if(t.direction==="H"){const e=ve(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:Ce(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=ve(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:Ce(t.start._2)(t.end._2)-e}]}g()}),Vi=bi(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})())}),RJ=t=>e=>n=>{const r=Ft(o=>J,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=Cr(r._1.tail);if(i.tag==="Nothing"){const s=o.length-1|0;return s>=0&&s<o.length&&(o[s].direction==="H"?n.direction==="H":o[s].direction==="V"&&n.direction==="V")?[...(()=>{const a=o.length-1|0;return a<1?[]:Bt(0,a,o)})(),{start:o[s].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()},Ui=t=>{const e=r=>o=>{const i=Ft(s=>J,s=>a=>N("Just",{head:s,tail:a}),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=Ft(r=>J,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()},Xi=t=>e=>n=>r=>S1(o=>n>=o.y&&n<o.y+o.h&&e>o.x&&t<o.x+o.w)(r),Yi=t=>e=>n=>r=>Xi(ve(e)(n))(Ce(e)(n))(r)(t),AJ=t=>e=>n=>r=>{const o=n+2|0,i=o<1?e:Bt(o,e.length,e),s=n<1?[]:Bt(0,n,e),a=(n+1|0)===(r-1|0),u=n===0,c=n>=0&&n<e.length?N("Just",e[n]):J;if(c.tag==="Just"){const _=n+1|0,d=_>=0&&_<e.length?N("Just",e[_]):J;if(d.tag==="Just"){const l=c._1.start._1===d._1.end._1&&(!u||c._1.direction==="V")&&(!a||d._1.direction==="V")&&!sa(t)(ve(c._1.start._2)(d._1.end._2))(Ce(c._1.start._2)(d._1.end._2))(c._1.start._1)?N("Just",[...s,{start:c._1.start,end:d._1.end,direction:me},...i]):J,f=c._1.start._2===d._1.end._2&&(!u||c._1.direction==="H")&&(!a||d._1.direction==="H")&&!Yi(t)(ve(c._1.start._1)(d._1.end._1))(Ce(c._1.start._1)(d._1.end._1))(c._1.start._2)?N("Just",[...s,{start:c._1.start,end:d._1.end,direction:pe},...i]):J;return l.tag==="Nothing"?f:l}if(d.tag==="Nothing")return J;g()}if(c.tag==="Nothing")return J;g()},IJ=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,s;for(;i;){const a=o;if((a+1|0)>=n){i=!1,s=e;continue}const u=AJ(t)(e)(a)(n);if(u.tag==="Just"){i=!1,s=u._1;continue}if(u.tag==="Nothing"){o=a+1|0;continue}g()}return s})(0)},FJ=t=>e=>n=>r=>{const o=(l,f,h)=>!sa(t)(ve(f)(h))(Ce(f)(h))(l),i=n+3|0,s=i<1?e:Bt(i,e.length,e),a=n<1?[]:Bt(0,n,e),u=(n+2|0)===(r-1|0),c=n===0,_=(l,f,h)=>!Yi(t)(ve(f)(h))(Ce(f)(h))(l),d=n>=0&&n<e.length?N("Just",e[n]):J;if(d.tag==="Just"){const l=n+2|0,f=l>=0&&l<e.length?N("Just",e[l]):J;if(f.tag==="Just"){const h=d._1.start._1===f._1.end._1&&(!c||d._1.direction==="V")&&(!u||f._1.direction==="V")&&o(d._1.start._1,d._1.start._2,f._1.end._2)?N("Just",[...a,{start:d._1.start,end:f._1.end,direction:me},...s]):d._1.start._2===f._1.end._2&&(!c||d._1.direction==="H")&&(!u||f._1.direction==="H")&&_(d._1.start._2,d._1.start._1,f._1.end._1)?N("Just",[...a,{start:d._1.start,end:f._1.end,direction:pe},...s]):J,p=(!c||d._1.direction==="V")&&(!u||f._1.direction==="H")&&o(d._1.start._1,d._1.start._2,f._1.end._2)&&_(f._1.end._2,d._1.start._1,f._1.end._1)?N("Just",[...a,{start:d._1.start,end:b(d._1.start._1,f._1.end._2),direction:me},{start:b(d._1.start._1,f._1.end._2),end:f._1.end,direction:pe},...s]):J,m=(!c||d._1.direction==="H")&&(!u||f._1.direction==="V")&&_(d._1.start._2,d._1.start._1,f._1.end._1)&&o(f._1.end._1,d._1.start._2,f._1.end._2)?N("Just",[...a,{start:d._1.start,end:b(f._1.end._1,d._1.start._2),direction:pe},{start:b(f._1.end._1,d._1.start._2),end:f._1.end,direction:me},...s]):J,w=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?w:h}if(f.tag==="Nothing")return J;g()}if(d.tag==="Nothing")return J;g()},QJ=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,s;for(;i;){const a=o;if((a+2|0)>=n){i=!1,s=e;continue}const u=FJ(t)(e)(a)(n);if(u.tag==="Just"){i=!1,s=u._1;continue}if(u.tag==="Nothing"){o=a+1|0;continue}g()}return s})(0)},MJ=t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const s=r,a=Ui(Vi(IJ(t)(QJ(t)(s))));if(a.length<s.length){r=a;continue}o=!1,i=a}return i};return n=>e(Ui(Vi(n)))},zJ=t=>e=>n=>r=>{const o=ve(n)(r),i=Ce(n)(r),s=ft(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Pt(c=>_=>ot.compare(c.x)(_.x))(s);return 0<u.length?u[0].x-1:(n+r)/2}const a=Pt(u=>c=>ot.compare(c.x)(u.x))(O(u=>({...u,x:u.x+u.w}))(s));return 0<a.length?a[0].x+1:(n+r)/2},WJ=t=>e=>n=>r=>{const o=ve(n)(r),i=Ce(n)(r),s=ft(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Pt(c=>_=>ot.compare(c.y)(_.y))(s);return 0<u.length?u[0].y-1:(n+r)/2}const a=Pt(u=>c=>ot.compare(c.y)(u.y))(O(u=>({...u,y:u.y+u.h}))(s));return 0<a.length?a[0].y+1:(n+r)/2},qJ=t=>e=>n=>r=>{const o=ve(n)(r),i=Ce(n)(r),s=ft(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Pt(c=>_=>ot.compare(_.x)(c.x))(O(c=>({...c,x:c.x+c.w}))(s));return 0<u.length?u[0].x:(n+r)/2}const a=Pt(u=>c=>ot.compare(u.x)(c.x))(s);return 0<a.length?a[0].x-1:(n+r)/2},OJ=t=>e=>n=>r=>{const o=ve(n)(r),i=Ce(n)(r),s=ft(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Pt(c=>_=>ot.compare(_.y)(c.y))(O(c=>({...c,y:c.y+c.h}))(s));return 0<u.length?u[0].y:(n+r)/2}const a=Pt(u=>c=>ot.compare(u.y)(c.y))(s);return 0<a.length?a[0].y-1:(n+r)/2},E1=t=>e=>n=>{let r=t,o=e,i=n,s=!0,a;for(;s;){const u=r,c=o,_=i;if(_>100){s=!1,a=c;continue}if(!u(c+_)){s=!1,a=c+_;continue}if(!u(c-_)){s=!1,a=c-_;continue}r=u,o=c,i=_+1}return a},G1=t=>e=>n=>r=>o=>{const i=ve(e)(n),s=Ce(e)(n);if(!$i(i)(s)(r)(t))return r;if(!$i(i)(s)(o)(t))return o;const a=(r+o)/2;return $i(i)(s)(a)(t)?E1(u=>$i(i)(s)(u)(t))(a)(1):a},HJ=t=>e=>n=>r=>o=>{const i=ve(e)(n),s=Ce(e)(n);if(!Xi(i)(s)(r)(t))return r;if(!Xi(i)(s)(o)(t))return o;const a=(r+o)/2;return Xi(i)(s)(a)(t)?E1(u=>Xi(i)(s)(u)(t))(a)(1):a},$J=t=>e=>n=>r=>{const o=ve(e)(n),i=Ce(e)(n),s=ft(c=>r>=c.x&&r<c.x+c.w&&c.y+c.h>o&&c.y<i,t),a=T(c=>_=>Ce(c)(_.x+_.w+4))(r+4)(s),u=T(c=>_=>ve(c)(_.x-4))(r-4)(s);return(()=>{const c=a-r,_=u-r;return(c<0?-c:c)<=(_<0?-_:_)})()?a:u},VJ=t=>e=>n=>r=>{const o=ve(e)(n),i=Ce(e)(n),s=ft(c=>r>=c.y&&r<c.y+c.h&&c.x+c.w>o&&c.x<i,t),a=T(c=>_=>Ce(c)(_.y+_.h+4))(r+4)(s),u=T(c=>_=>ve(c)(_.y-4))(r-4)(s);return(()=>{const c=a-r,_=u-r;return(c<0?-c:c)<=(_<0?-_:_)})()?a:u},UJ=t=>e=>n=>r=>o=>i=>s=>{const a=(()=>{if(r==="South")return b(o._1,o._2+4);if(r==="North")return b(o._1,o._2-4);if(r==="East")return b(o._1+4,o._2);if(r==="West")return b(o._1-4,o._2);g()})(),u=(()=>{if(i==="South")return b(s._1,s._2+4);if(i==="North")return b(s._1,s._2-4);if(i==="East")return b(s._1+4,s._2);if(i==="West")return b(s._1-4,s._2);g()})(),c=(C,L,E)=>!sa(e)(ve(L)(E))(Ce(L)(E))(C),_=(C,L,E)=>!sa(n)(ve(L)(E))(Ce(L)(E))(C),d=(C,L,E,B)=>t.tag==="Just"&&!Yi(n)(ve(C)(L))(Ce(C)(L))(t._1)?t._1:HJ(e)(C)(L)(E)(B),l=(C,L,E,B)=>{if(C===E){const Y=$J(e)(L)(B)(C),R=WJ(e)(C)(L)(B),A=OJ(e)(C)(L)(B);return[{start:b(C,L),end:b(C,R),direction:me},{start:b(C,R),end:b(Y,R),direction:pe},{start:b(Y,R),end:b(Y,A),direction:me},{start:b(Y,A),end:b(E,A),direction:pe},{start:b(E,A),end:b(E,B),direction:me}]}const z=d(C,E,L,B);return[{start:b(C,L),end:b(C,z),direction:me},{start:b(C,z),end:b(E,z),direction:pe},{start:b(E,z),end:b(E,B),direction:me}]},f=(C,L,E,B)=>{if(L===B){const Y=VJ(e)(C)(E)(L),R=zJ(e)(L)(C)(E),A=qJ(e)(L)(C)(E);return[{start:b(C,L),end:b(R,L),direction:pe},{start:b(R,L),end:b(R,Y),direction:me},{start:b(R,Y),end:b(A,Y),direction:pe},{start:b(A,Y),end:b(A,B),direction:me},{start:b(A,B),end:b(E,B),direction:pe}]}const z=G1(e)(L)(B)(C)(E);return[{start:b(C,L),end:b(z,L),direction:pe},{start:b(z,L),end:b(z,B),direction:me},{start:b(z,B),end:b(E,B),direction:pe}]},h=(C,L,E)=>!Yi(e)(ve(L)(E))(Ce(L)(E))(C),p=(C,L,E)=>!Yi(n)(ve(L)(E))(Ce(L)(E))(C),m=(C,L,E,B)=>{if(p(L,C,E)&&_(E,L,B))return[{start:b(C,L),end:b(E,L),direction:pe},{start:b(E,L),end:b(E,B),direction:me}];const z=G1(e)(L)(B)(C)(E);return[{start:b(C,L),end:b(z,L),direction:pe},{start:b(z,L),end:b(z,B),direction:me},{start:b(z,B),end:b(E,B),direction:pe}]},w=(C,L,E,B)=>{if(_(C,L,B)&&p(B,C,E))return[{start:b(C,L),end:b(C,B),direction:me},{start:b(C,B),end:b(E,B),direction:pe}];const z=d(C,E,L,B);return[{start:b(C,L),end:b(C,z),direction:me},{start:b(C,z),end:b(E,z),direction:pe},{start:b(E,z),end:b(E,B),direction:me}]},y=(()=>{if(r==="South")return i==="North"?a._1===u._1&&c(a._1,a._2,u._2)?[{start:b(a._1,a._2),end:b(u._1,u._2),direction:me}]:l(a._1,a._2,u._1,u._2):i==="East"||i==="West"?w(a._1,a._2,u._1,u._2):l(a._1,a._2,u._1,u._2);if(r==="North")return i==="South"?a._1===u._1&&c(a._1,a._2,u._2)?[{start:b(a._1,a._2),end:b(u._1,u._2),direction:me}]:l(a._1,a._2,u._1,u._2):i==="East"||i==="West"?w(a._1,a._2,u._1,u._2):l(a._1,a._2,u._1,u._2);if(r==="East")return i==="West"?a._2===u._2&&h(a._2,a._1,u._1)?[{start:b(a._1,a._2),end:b(u._1,u._2),direction:pe}]:f(a._1,a._2,u._1,u._2):i==="North"||i==="South"?m(a._1,a._2,u._1,u._2):l(a._1,a._2,u._1,u._2);if(r==="West"){if(i==="East")return a._2===u._2&&h(a._2,a._1,u._1)?[{start:b(a._1,a._2),end:b(u._1,u._2),direction:pe}]:f(a._1,a._2,u._1,u._2);if(i==="North"||i==="South")return m(a._1,a._2,u._1,u._2)}return l(a._1,a._2,u._1,u._2)})(),x=(()=>{if(r==="South"||r==="North")return me;if(r==="East"||r==="West")return pe;g()})(),v={start:b(u._1,u._2),end:b(s._1,s._2),direction:(()=>{if(i==="South"||i==="North")return me;if(i==="East"||i==="West")return pe;g()})()};return a._1===u._1&&a._2===u._2?[{start:b(o._1,o._2),end:b(s._1,s._2),direction:x}]:RJ({start:b(o._1,o._2),end:b(a._1,a._2),direction:x})(y)(v)},XJ=O(t=>({x:t.position._1*aa-2,y:t.position._2*aa-2,w:t.size._1*aa+4,h:t.size._2*aa+4})),P1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},gi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},YJ=(()=>{const t=nn.unfoldr(Qn);return e=>t(rn("IterNode",e,Fn))})(),Ec=t=>e=>t.gapTop+1*nt(4)+nt(e)*2.5*nt(4),KJ=t=>e=>{const n=P1(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return N("Just",{slot1Y:Ec(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Ec(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return J;g()}if(n.tag==="Nothing")return J;g()},jJ=t=>e=>{const n=T(r=>o=>rt(P)(o.node)(o)(r))(I)(e);return hn(Ht(r=>o=>{const i=gi(o.node)(n);if(i.tag==="Nothing")return[];if(i.tag==="Just"){const s=i._1;return Ht(a=>u=>{const c=o.edges.length,_=nt(4),d=s.position._1*_,l=s.position._2*_,f=s.size._2*_,h=nt((2*c|0)+1|0),p=l+f*nt(c-a|0)/h,m=l+f*nt((c+1|0)+a|0)/h,w=d-_*2.5*nt(a+1|0),y=[{start:b(d,p),end:b(w,p),direction:pe},{start:b(w,p),end:b(w,m),direction:me},{start:b(w,m),end:b(d,m),direction:pe}];return{edge:u.id,segments:y,bends:Fe(x=>v=>x.end,y,Bt(1,3,y)),bendType:[],jumps:[],reversed:!1}})(o.edges)}g()})(O(r=>({node:r._1,edges:r._2}))(YJ(T(r=>o=>Qt(P)(le)(o.from.node)([o])(r))(I)(t)))))},ZJ=t=>e=>{const n=T(i=>s=>rt(P)(s.node)(s)(i))(I)(e),r=i=>{const s=gi(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.position._1;g()},o=i=>{const s=gi(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.layer;g()};return Pt(i=>s=>{const a=it.compare(o(i.edge.from.node))(o(s.edge.from.node));if(a==="EQ"){const u=ot.compare(r(i.edge.from.node))(r(s.edge.from.node));return u==="EQ"?ot.compare(r(i.edge.to.node))(r(s.edge.to.node)):u}return a})(t)},sn=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}},tN=t=>t.from.node===t.to.node,eN=t=>e=>n=>r=>{const o=MJ(n)(UJ(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:o,bends:Fe(i=>s=>i.end,o,Bt(1,o.length,o)),bendType:[],jumps:[],reversed:!1}},nN=t=>e=>n=>r=>{const o=[{start:b(r.fromPos._1,r.fromPos._2),end:b(r.fromPos._1,t.slot1Y),direction:me},{start:b(r.fromPos._1,t.slot1Y),end:b(t.splitX,t.slot1Y),direction:pe},{start:b(t.splitX,t.slot1Y),end:b(t.splitX,t.slot2Y),direction:me},{start:b(t.splitX,t.slot2Y),end:b(r.toPos._1,t.slot2Y),direction:pe},{start:b(r.toPos._1,t.slot2Y),end:b(r.toPos._1,r.toPos._2),direction:me}];return{edge:r.edge.id,segments:o,bends:Fe(i=>s=>i.end,o,Bt(1,5,o)),bendType:[],jumps:[],reversed:!1}},rN=t=>e=>n=>{const r=gi(t.edge.from.node)(n);if(r.tag==="Just"){const i=gi(t.edge.to.node)(n);return i.tag==="Just"?ft(s=>!(s.h===sn(r._1).h&&s.w===sn(r._1).w&&s.x===sn(r._1).x&&s.y===sn(r._1).y)&&!(s.h===sn(i._1).h&&s.w===sn(i._1).w&&s.x===sn(i._1).x&&s.y===sn(i._1).y),e):ft(s=>!(s.h===sn(r._1).h&&s.w===sn(r._1).w&&s.x===sn(r._1).x&&s.y===sn(r._1).y),e)}const o=gi(t.edge.to.node)(n);return o.tag==="Just"?ft(i=>!(i.h===sn(o._1).h&&i.w===sn(o._1).w&&i.x===sn(o._1).x&&i.y===sn(o._1).y),e):ft(i=>!0,e)},oN=t=>e=>{const n=P1(e.edge.id)(t);if(n.tag==="Just")return N("Just",Ec(n._1)(n._1.slot));if(n.tag==="Nothing")return J;g()},iN=t=>e=>n=>r=>o=>{const i=T(c=>_=>rt(P)(_.node)(_)(c))(I)(e),s=XJ(e),a=g1(ft(c=>c.from.node!==c.to.node,t))(e)(n)(r)(o),u=i1(a)(e);return[...jJ(ft(tN,t))(e),...T(c=>_=>{const d=rN(_)(s)(i),l=[...d,...c.edgeObstacles],f=KJ(u)(_),h=(()=>{if(f.tag==="Just")return nN(f._1)(d)(l)(_);if(f.tag==="Nothing")return eN(oN(u)(_))(d)(l)(_);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...DJ(h.segments)]}})({results:[],edgeObstacles:[]})(ZJ(a)(e)).results]},Zr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},to=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},sN=t=>e=>n=>{if(t.start._1!==e.start._1)return J;const r=to(Zr(t.start._2)(t.end._2))(Zr(e.start._2)(e.end._2)),o=Zr(to(t.start._2)(t.end._2))(to(e.start._2)(e.end._2));return r<o?N("Just",{position:b(t.start._1,(r+o)/2),crossingEdge:n}):J},aN=t=>e=>n=>{if(t.start._2!==e.start._2)return J;const r=to(Zr(t.start._1)(t.end._1))(Zr(e.start._1)(e.end._1)),o=Zr(to(t.start._1)(t.end._1))(to(e.start._1)(e.end._1));return r<o?N("Just",{position:b((r+o)/2,t.start._2),crossingEdge:n}):J},uN=t=>e=>n=>{if(t.direction==="H")return aN(t)(e)(n);if(t.direction==="V")return sN(t)(e)(n);g()},cN=t=>e=>n=>{const r=t+1|0,o=r<1?n:Bt(r,n.length,n);return St(e.segments)(i=>St(o)(s=>Tt(a=>uN(i)(a)(s.edge))(ft(a=>a.direction==="H"?i.direction==="H":a.direction==="V"&&i.direction==="V",s.segments))))},gN=t=>e=>n=>e.start._1>Zr(t.start._1)(t.end._1)&&e.start._1<to(t.start._1)(t.end._1)&&t.start._2>Zr(e.start._2)(e.end._2)&&t.start._2<to(e.start._2)(e.end._2)?N("Just",{position:b(e.start._1,t.start._2),crossingEdge:n}):J,_N=t=>e=>St(ft(n=>n.direction==="H",t.segments))(n=>St(e)(r=>Tt(o=>gN(n)(o)(r.edge))(ft(o=>o.direction==="V",r.segments)))),fN=t=>e=>n=>[..._N(e)(ft(r=>r.edge!==e.edge,n)),...cN(t)(e)(n)],B1=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},dN=T(t=>e=>rt(P)(e)()(t))(I),ua=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},lN=Xf(P),fr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},D1=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Gc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},hN=ce(it)(zt),pN=t=>e=>Me(P.compare,Ie,t,e),R1=Ht(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),mN=t=>T(e=>n=>({base:(()=>{const r=o=>i=>{let s=o,a=i,u=!0,c;for(;u;){const _=s,d=a;if(d.tag==="Nil"){u=!1,c=_;continue}if(d.tag==="Cons"){s=B1(_)(d._1),a=d._2;continue}g()}return c};return(e.base+r(0)((()=>{const o=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return o(i._5,Lt("Cons",i._4,o(i._6,s)));g()};return o(n,$)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=o=>{if(o.tag==="Leaf")return I;if(o.tag==="Node")return te("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,yN=t=>e=>{const n=dN(t);return lN(t)(R1(ft(r=>ua(r.src)(n)&&ua(r.tgt)(n),e)))},xN=t=>e=>{const n=T(o=>i=>Qt(P)(le)(i.tgt)([i.src])(Qt(P)(le)(i.src)([i.tgt])(o)))(I)(e),r=o=>i=>s=>{let a=o,u=i,c=s,_=!0,d;for(;_;){const l=a,f=u,h=c,p=Ft(m=>J,m=>w=>N("Just",{head:m,tail:w}),l);if(p.tag==="Nothing"){_=!1,d={nodes:h};continue}if(p.tag==="Just"){if(ua(p._1.head)(f)){a=p._1.tail,u=f,c=h;continue}a=[...p._1.tail,...(()=>{const m=fr(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()})()],u=rt(P)(p._1.head)()(f),c=[...h,p._1.head];continue}g()}return d};return T(o=>i=>{if(ua(i)(o.visited))return o;const s=r([i])(o.visited)([]);return{...o,visited:T(a=>u=>rt(P)(u)()(a))(o.visited)(s.nodes),components:[...o.components,s.nodes]}})({visited:I,components:[]})(t).components},wN=t=>e=>n=>{const r=T(i=>s=>Qt(P)(we)(s.tgt)(1)(i))(I)(e),o=T(i=>s=>Qt(P)(we)(s.src)(1)(i))(I)(e);return T(i=>s=>{const a=fr(s)(r),u=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})();if((()=>{const y=fr(s)(o);return(()=>{if(y.tag==="Nothing")return u!==0;if(y.tag==="Just")return u!==y._1;g()})()||u===0})())return i;const c=fr(s)(i.layers),_=(()=>{if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1;g()})(),d=i.layers,l=T(y=>x=>x.tgt===s?{...y,mIn:D1(y.mIn)((()=>{const v=fr(s)(d),C=fr(x.src)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})()-(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;g()})()|0})())}:x.src===s?{...y,mOut:D1(y.mOut)((()=>{const v=fr(x.tgt)(d),C=fr(s)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})()-(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;g()})()|0})())}:y)({mIn:1e9,mOut:1e9})(e),f=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(f<0||h<0)return i;const p=(_-f|0)+1|0,m=(_+h|0)-1|0;if(m<p)return i;const w=T(y=>x=>{const v=Gc(x)(i.filling),C=(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})();return C<y.bestFill?{best:x,bestFill:C}:y})({best:_,bestFill:(()=>{const y=Gc(_)(i.filling);if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;g()})()})(Kt(p,m));return w.best===_?i:{layers:rt(P)(s)(w.best)(i.layers),filling:rt(it)(_)((()=>{const y=Gc(_)(i.filling);if(y.tag==="Nothing")return-1;if(y.tag==="Just")return y._1-1|0;g()})())(rt(it)(w.best)(w.bestFill+1|0)(i.filling))}})({layers:n,filling:hN(O(i=>b(i,T(s=>a=>(()=>{const u=fr(a)(n);return u.tag==="Nothing"?!1:u.tag==="Just"&&u._1===i})()?s+1|0:s)(0)(t)))(Kt(0,T(i=>s=>B1(i)((()=>{const a=fr(s)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})()))(0)(t))))})(t).layers},JN=t=>e=>wN(t)(R1(e))(T(pN)(I)(mN(O(n=>yN(n)(e))(xN(t)(e))))),NN=t=>t,ho=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ca=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},A1=(()=>{const t=nn.unfoldr(Qn);return e=>t(rn("IterNode",e,Fn))})(),TN=NN("NetworkSimplex"),vN=t=>e=>T(n=>r=>{const o=T(ca)(0)(Tt(i=>ho(i)(n))(r));return T(i=>s=>rt(P)(s)(o)(i))(n)(r)})(e)(t),CN=t=>e=>({layers:O(n=>ft(r=>{const o=ho(r)(e);return o.tag==="Nothing"?!1:o.tag==="Just"&&o._1===n},t))(Kt(0,(n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=i;if(c.tag==="Nil"){s=!1,a=u;continue}if(c.tag==="Cons"){o=ca(u)(c._1),i=c._2;continue}g()}return a})(0)((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Lt("Cons",r._4,n(r._6,o)));g()};return n(e,$)})()))),nodeLayer:e}),bN=t=>e=>n=>{const r=T(o=>i=>rt(P)(i)(!0)(o))(I)(e);return T(o=>i=>rt(P)(i._1)(i._2)(o))(JN(e)(Tt(o=>o.from.node===o.to.node||(()=>{const i=ho(o.from.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;g()})()||(()=>{const i=ho(o.to.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;g()})()?J:N("Just",{src:o.from.node,tgt:o.to.node}))(t)))(A1(n))},kN=t=>e=>n=>r=>{const o=a=>u=>{const c=ho(u)(a);if(c.tag==="Just")return a;if(c.tag==="Nothing"){const _=ft(l=>l!==u,(()=>{const l=ho(u)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;g()})()),d=T(o)(a)(_);return rt(P)(u)(1+T(ca)(0)(Tt(l=>ho(l)(d))(_))|0)(d)}g()},i=T(o)(I)(n),s=(a=>u=>{let c=a,_=u,d=!0,l;for(;d;){const f=c,h=_;if(h.tag==="Nil"){d=!1,l=f;continue}if(h.tag==="Cons"){c=ca(f)(h._1),_=h._2;continue}g()}return l})(1)((()=>{const a=(u,c)=>{if(u.tag==="Leaf")return c;if(u.tag==="Node")return a(u._5,Lt("Cons",u._4,a(u._6,c)));g()};return a(i,$)})());return T(a=>u=>rt(P)(u._1)(u._2)(a))((()=>{const a=u=>{if(u.tag==="Leaf")return I;if(u.tag==="Node")return te("Node",u._1,u._2,u._3,s-u._4|0,a(u._5),a(u._6));g()};return a(i)})())(A1(r))},LN=T(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return rt(P)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return rt(P)(e._1.node)(0)(t)}return t})(I),SN=T(t=>e=>Qt(P)(le)(e.to.node)([e.from.node])(t))(I),EN=T(t=>e=>Qt(P)(le)(e.from.node)([e.to.node])(t))(I),GN=t=>e=>n=>r=>{const o=EN(n),i=SN(n),s=LN(e);return CN(r)(vN(Tt(a=>a.tag==="SameLayer"?N("Just",a._1.nodes):J)(e))((()=>{if(t==="LongestPath")return kN(o)(i)(r)(s);if(t==="NetworkSimplex")return bN(n)(r)(s);g()})()))},PN=ce(P)(zt),BN=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},I1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},F1=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ki=ce(P)(zt),DN=ce(P)(zt),Q1=(()=>{const t=O(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>se(t(e))})(),RN=t=>e=>n=>r=>{const o=PN(O(s=>b(s.edge,s))(r)),i=s=>0<s.nodes.length&&(()=>{const a=BN(s.edgeId)(n);return a.tag==="Just"&&s.nodes[0]!==a._1._1})();return O(s=>{if(s.nodes.length<=2){const _=I1(s.edgeId)(o);if(_.tag==="Just"){const d=i(s),l=Ui(Vi(d?Q1(_._1.segments):_._1.segments));return{..._._1,edge:s.edgeId,segments:l,bends:Fe(f=>h=>f.end,l,Bt(1,l.length,l)),reversed:d}}if(_.tag==="Nothing")return{edge:s.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};g()}const a=St(Tt(_=>I1(_)(o))(Fe(_=>d=>s.edgeId+":"+_+"->"+d,s.nodes,Bt(1,s.nodes.length,s.nodes))))(_=>_.segments),u=i(s),c=Ui(Vi(u?Q1(a):a));return{edge:s.edgeId,segments:c,bends:Fe(_=>d=>_.end,c,Bt(1,c.length,c)),bendType:[],jumps:[],reversed:u}})(t)},AN={layers:[],edges:[],chains:[]},IN={nodeGap:3,layerGap:2,iterations:8,layerer:TN,cycleBreaker:kJ,compactPostRouting:!0,compactionSpacings:Sw},FN=t=>({pos:b(0,0),size:b(T(e=>n=>F1(e)(n.position._1+n.size._1))(0)(t),T(e=>n=>F1(e)(n.position._2+n.size._2))(0)(t))}),QN=t=>e=>n=>{const r=Ki(O(c=>b(c.id,c.ports))(e.nodes)),o=ft(c=>Re(3)(c.node)!=="$d:",n.placements),i=RN(n.withDummies.chains)(n.acyclic.reversedEdges)(DN(O(c=>b(c.id,b(c.from.node,c.to.node)))(e.edges)))(iN(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(f1(n.ordered)(ft(c=>c.from.node!==c.to.node,n.withDummies.edges))((()=>{const c=_=>{if(_.tag==="Leaf")return I;if(_.tag==="Node")return te("Node",_._1,_._2,_._3,b(_._4._1*4,_._4._2),c(_._5),c(_._6));g()};return c(Ki(O(_=>b(_.id,_.size))(e.nodes)))})()))),s=t.compactPostRouting?Pw()(t.compactionSpacings)({nodes:o,edges:e.edges,paths:i,ports:r}):{nodes:o,edges:i},a=O(c=>{const _=Ui(Vi(c.segments));return{...c,segments:_,bends:Fe(d=>l=>d.end,_,Bt(1,_.length,_))}})(s.edges),u=Ht(c=>_=>({..._,jumps:fN(c)(_)(a)}))(a);return{nodes:s.nodes,edges:u,boundingBox:FN(s.nodes),metrics:ox(s.nodes)(u)(0)}},MN=t=>e=>n=>{const r=Ki(O(i=>b(i.id,i.size))(e.nodes)),o={...n,placements:gJ({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(Ki(O(i=>b(i.id,i.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(f1(n.ordered)(n.withDummies.edges)((()=>{const i=s=>{if(s.tag==="Leaf")return I;if(s.tag==="Node")return te("Node",s._1,s._2,s._3,b(s._4._1*4,s._4._2),i(s._5),i(s._6));g()};return i(r)})()))};return{pipeline:o,result:QN(t)(e)(o)}},zN=t=>e=>n=>MN(t)(e)({...n,ordered:TJ({iterations:t.iterations,constraints:e.constraints,modelOrder:Ki(Ht(r=>o=>b(o.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),WN=t=>e=>n=>zN(t)(e)({...n,withDummies:Bw(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),qN=t=>e=>{const n=O(o=>o.id)(e.nodes),r=BJ(t.cycleBreaker)(n)(e.constraints)(e.edges);return WN(t)(e)({acyclic:r,layered:GN(t.layerer)(e.constraints)(r.edges)(n),withDummies:AN,ordered:[],placements:[]})},M1=t=>t,z1=M1("RunText"),ON=M1("RunCode"),W1=t=>e=>n=>e.length===0?n:kt(n)({style:t,text:$r(e)}),HN=t=>({style:(()=>{if(t.style==="RunText")return ON;if(t.style==="RunCode")return z1;g()})(),buf:[],runs:W1(t.style)(t.buf)(t.runs)}),$N=t=>e=>0<e.length?{...t,buf:kt(t.buf)(e[0])}:{...t,buf:kt(t.buf)("\\")},VN=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=Ft(u=>J,u=>c=>N("Just",{head:u,tail:c}),r);if(a.tag==="Nothing"){o=!1,i=s;continue}if(a.tag==="Just"){if(a._1.head==="\\"){n=$N(s)(a._1.tail),r=Bt(1,a._1.tail.length,a._1.tail);continue}if(a._1.head==="`"){n=HN(s),r=a._1.tail;continue}n={...s,buf:kt(s.buf)(a._1.head)},r=a._1.tail;continue}g()}return i},q1=t=>{const e=VN({style:z1,buf:[],runs:[]})(br(t));return W1(e.style)(e.buf)(e.runs)};let Pc=null;function UN(){return Pc||(typeof document>"u"?null:(Pc=document.createElement("canvas").getContext("2d"),Pc))}const O1=new Map,XN=t=>e=>n=>r=>()=>{const o=`${n} ${e}px ${t}|${r}`,i=O1.get(o);if(i!==void 0)return i;const s=UN();if(!s)return r.length*e*.62;s.font=`${n} ${e}px ${t}`;const a=s.measureText(r).width;return O1.set(o,a),a},YN=uo.traverse(_u),KN=T(nr)(0),po=(()=>{const t=Mn(`\r
|
|
3
|
+
`)(" "),e=Mn(`
|
|
4
|
+
`)(" "),n=(()=>{const r=Mn("\r")(" "),o=(()=>{const i=Mn(" ")(" ");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),H1=t=>e=>{const n=YN(r=>{const o=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;g()})();return XN(o.family)(o.size)(o.weight)(po(r.text))})(q1(po(e)));return()=>{const r=n();return KN(r)}},$1={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"}},jN=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},_i=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ZN=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},tT=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},eT=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},V1=t=>$r(se(er(e=>e===" ")(se(er(e=>e===" ")(br(t)).rest)).rest)),nT=t=>T(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?N("Just",n._1):e)(J)(Ht(An)(t)),Bc=t=>e=>{if(t<=0)return[e];if(ir(e)<=t)return[e];const n=br(e),r=t<1?[]:Bt(0,t,n),o=nT(r);if(o.tag==="Just"){const i=V1(A_(!(o._1>=0&&o._1<r.length)||r[o._1]===" "?o._1:o._1+1|0)(e)),s=V1(Vo(o._1+1|0)(e));return s===""?[i]:[i,...Bc(t)(s)]}if(o.tag==="Nothing"){const i=A_(t)(e),s=Vo(t)(e);return s===""?[i]:[i,...Bc(t)(s)]}g()},rT={cellW:7,cellH:3,maxLineWidth:20},oT=t=>e=>{const n=O(i=>b((()=>{if(i.label.tag==="Just")return i.label._1;if(i.label.tag==="Nothing")return i.id;g()})(),i))(e.nodes),r=_i(1)(Tr((ZN(t.maxLineWidth)(T(i=>s=>_i(i)(ir(s._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),o=(r*t.cellW|0)-1|0;return{...e,nodes:O(i=>{if(!(i._2.size._1===1&&i._2.size._2===1))return i._2;const s=St(Sr(`
|
|
5
|
+
`)(i._1))(Bc(o)),a=T(c=>_=>_i(c)(ir(_)))(0)(s),u=i._2.shape==="Cylinder"?_i(1)(Tr((a+2|0)+t.cellW|0,t.cellW)):r;return{...i._2,size:b(nt(a>o?Tr((a+2|0)+t.cellW|0,t.cellW):u),nt(_i(1)(Tr(s.length+t.cellH|0,t.cellH))+(i._2.shape==="Cylinder"||i._2.shape==="Document"?1:0)|0))}})(n)}},iT=t=>e=>n=>({...n,nodes:O(r=>{const o=eT(r.id)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just")return{...r,size:b(tT(r.size._1)(nt(_i(1)(fe(xs(r.shape==="Cylinder"?(o._1+0)/t:(o._1+32)/t))))),r.size._2)};g()})(n.nodes)}),ga=t=>t,sT=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},mo=ga("TopSide"),yo=ga("BottomSide"),xo=ga("LeftSide"),wo=ga("RightSide"),aT=t=>{const e=ot.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ot.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},U1=t=>e=>n=>{const r=sT(t.h*.12)(t.w*.2),o=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*Ve(aT((()=>{const i=(n-(t.x+o))/o;return 1-i*i})()))},an=t=>e=>n=>r=>{let o=t,i=e,s=n,a=r,u=!0,c;for(;u;){const _=o,d=i,l=s,f=a;if(_==="Rectangle"){if(l==="TopSide"){u=!1,c=d.y;continue}if(l==="BottomSide"){u=!1,c=d.y+d.h;continue}if(l==="LeftSide"){u=!1,c=d.x;continue}if(l==="RightSide"){u=!1,c=d.x+d.w;continue}o=Vr,i=d,s=l,a=f;continue}if(_==="Cylinder"){if(l==="TopSide"){u=!1,c=U1(d)(-1)(f);continue}if(l==="BottomSide"){u=!1,c=U1(d)(1)(f);continue}if(l==="LeftSide"){u=!1,c=d.x;continue}if(l==="RightSide"){u=!1,c=d.x+d.w;continue}}o=Vr,i=d,s=l,a=f}return c},X1=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,s=e.x-t.x,a=s<0?-s:s,u=e.y-(t.y+t.h),c=u<0?-u:u;return r<=c&&r<=a&&r<=i?mo:c<=a&&c<=i?yo:a<=i?xo:wo},uT=(()=>{const t=nn.unfoldr(Qn);return e=>t(rn("IterNode",e,Fn))})(),Dc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ji=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Zi=ce(P)(zt),cT=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},gT=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},_T=T(t=>e=>rt(P)(e)()(t))(I),fT=T(t=>e=>rt(P)(e)()(t))(I),_a=uo.traverse(_u),fa=ce(P)(zt),dT=t=>e=>Me(P.compare,Ie,t,e),lT=T(t=>e=>rt(P)(e)()(t))(I),hT=ce(P)(zt),pT=t=>e=>Me(P.compare,Ie,t,e),mT=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Y1=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},yT=t=>e=>({...e,edges:Zi(O(n=>b(n._1,(()=>{const r=Dc(n._1)(t);if(r.tag==="Nothing")return n._2;if(r.tag==="Just"){const o=ji(r._1._2)(e.nodes),i=ji(r._1._1)(e.nodes),s=(()=>{if(i.tag==="Nothing")return n._2;if(i.tag==="Just"){const a=Ft(u=>J,u=>c=>N("Just",{head:u,tail:c}),n._2);if(a.tag==="Nothing")return n._2;if(a.tag==="Just")return[(()=>{const u=Ft(l=>J,l=>f=>N("Just",{head:l,tail:f}),a._1.tail),c=u.tag==="Just"?N("Just",u._1.head):J,_={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},d=(()=>{if(c.tag==="Just"){if((c._1.x>a._1.head.x?c._1.x-a._1.head.x<.5:a._1.head.x-c._1.x<.5)&&a._1.head.x>=_.x-.5&&a._1.head.x<=_.x+_.w+.5)return c._1.y>=_.y+_.h?N("Just",yo):c._1.y<=_.y?N("Just",mo):J;if((c._1.y>a._1.head.y?c._1.y-a._1.head.y<.5:a._1.head.y-c._1.y<.5)&&a._1.head.y>=_.y-.5&&a._1.head.y<=_.y+_.h+.5){if(c._1.x>=_.x+_.w)return N("Just",wo);if(c._1.x<=_.x)return N("Just",xo)}return J}if(c.tag==="Nothing")return J;g()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...a._1.head,y:an(i._1.shape)(_)(mo)(a._1.head.x)};if(d._1==="BottomSide")return{...a._1.head,y:an(i._1.shape)(_)(yo)(a._1.head.x)};if(d._1==="LeftSide")return{...a._1.head,x:an(i._1.shape)(_)(xo)(a._1.head.y)};if(d._1==="RightSide")return{...a._1.head,x:an(i._1.shape)(_)(wo)(a._1.head.y)};g()}if(d.tag==="Nothing"){const l={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},f=X1(l)(a._1.head);if(f==="TopSide")return{...a._1.head,y:an(i._1.shape)(l)(mo)(a._1.head.x)};if(f==="BottomSide")return{...a._1.head,y:an(i._1.shape)(l)(yo)(a._1.head.x)};if(f==="LeftSide")return{...a._1.head,x:an(i._1.shape)(l)(xo)(a._1.head.y)};if(f==="RightSide")return{...a._1.head,x:an(i._1.shape)(l)(wo)(a._1.head.y)}}g()})(),...a._1.tail]}g()})();if(o.tag==="Nothing")return s;if(o.tag==="Just"){const a=Cr(s);if(a.tag==="Nothing")return s;if(a.tag==="Just")return kt(a._1.init)((()=>{const u=Cr(a._1.init),c=u.tag==="Just"?N("Just",u._1.last):J,_={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},d=(()=>{if(c.tag==="Just"){if((c._1.x>a._1.last.x?c._1.x-a._1.last.x<.5:a._1.last.x-c._1.x<.5)&&a._1.last.x>=_.x-.5&&a._1.last.x<=_.x+_.w+.5)return c._1.y>=_.y+_.h?N("Just",yo):c._1.y<=_.y?N("Just",mo):J;if((c._1.y>a._1.last.y?c._1.y-a._1.last.y<.5:a._1.last.y-c._1.y<.5)&&a._1.last.y>=_.y-.5&&a._1.last.y<=_.y+_.h+.5){if(c._1.x>=_.x+_.w)return N("Just",wo);if(c._1.x<=_.x)return N("Just",xo)}return J}if(c.tag==="Nothing")return J;g()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...a._1.last,y:an(o._1.shape)(_)(mo)(a._1.last.x)};if(d._1==="BottomSide")return{...a._1.last,y:an(o._1.shape)(_)(yo)(a._1.last.x)};if(d._1==="LeftSide")return{...a._1.last,x:an(o._1.shape)(_)(xo)(a._1.last.y)};if(d._1==="RightSide")return{...a._1.last,x:an(o._1.shape)(_)(wo)(a._1.last.y)};g()}if(d.tag==="Nothing"){const l={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},f=X1(l)(a._1.last);if(f==="TopSide")return{...a._1.last,y:an(o._1.shape)(l)(mo)(a._1.last.x)};if(f==="BottomSide")return{...a._1.last,y:an(o._1.shape)(l)(yo)(a._1.last.x)};if(f==="LeftSide")return{...a._1.last,x:an(o._1.shape)(l)(xo)(a._1.last.y)};if(f==="RightSide")return{...a._1.last,x:an(o._1.shape)(l)(wo)(a._1.last.y)}}g()})())}}g()})()))(uT(e.edges)))}),xT=t=>e=>n=>{const r=re(o=>o.id===n)(t.graph.edges);if(r.tag==="Just")return N("Just",r._1);if(r.tag==="Nothing")return Dc(n)(e);g()},wT=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=ji(r.node)(e);if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return r.node;g()})(),shape:(()=>{const o=ji(r.node)(n);if(o.tag==="Nothing")return Vr;if(o.tag==="Just")return o._1;g()})()}),JT=t=>({id:t,size:b(1,1),ports:[],label:N("Just",t),shape:Vr}),NT=t=>e=>n=>r=>b(r.node,wT(t)(e)(n)(r)),K1=t=>{const e=Sr(`
|
|
6
|
+
`)(t);return e.length===0?[""]:e},j1=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Lt("Cons",n._4,e(n._6,r)));g()};return Zt(de.foldr,e(t.interiors,$))},TT=t=>Zi(Tt(e=>N("Just",b(e.edge,{id:e.edge,from:{node:e.from,port:J},to:{node:e.to,port:J},label:J})))(St(t.scenes)(e=>e.tag==="DataFlow"?Tt(n=>n.kind.tag==="SendToken"?N("Just",n.kind._1):J)(e._1.events):[]))),Z1=t=>{const e=d2(t),n=ft(o=>cT(o.id)(e.nodes),t.graph.nodes),r=ft(o=>gT(o.id)(e.edges),t.graph.edges);return{nodes:[...n,...O(JT)(Zt(fn.foldr,Vn(P.compare,e.nodes,_T(O(o=>o.id)(n)))))],edges:[...r,...Tt(xT(t)(TT(t)))(Zt(fn.foldr,Vn(P.compare,e.edges,fT(O(o=>o.id)(r)))))],constraints:t.graph.constraints}},vT=t=>{const e=_a(n=>{const r=H1($1)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})());return()=>{const o=r();return b(n.id,o)}})(Z1(t).nodes);return()=>{const n=e();return fa(n)}},td=t=>{const e=vT(t);return()=>{const n=e(),r=_a(td)(j1(t))();return T(dT)(n)(r)}},CT=t=>e=>{const n=Ft(r=>J,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},...O(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];g()},bT=t=>e=>b(e.edge,CT(t)(e)),kT=t=>e=>n=>r=>({nodes:fa(O(NT(nt(4)*t)(e)(n))(r.nodes)),edges:Zi(O(bT(t))(r.edges)),chipExtras:I,edgeLabels:I}),LT=t=>e=>({...yT(Zi(O(n=>b(n.id,b(n.from.node,n.to.node)))(e.edges)))(kT(8)(fa(O(n=>b(n.id,(()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})()))(e.nodes)))(fa(O(n=>b(n.id,n.shape))(e.nodes)))(qN(IN)(e).result)),edgeLabels:Zi(Tt(n=>n.label.tag==="Just"?N("Just",b(n.id,n.label._1)):J)(e.edges))}),ST=t=>T(e=>n=>{if(n.tag==="Structural")return e;if(n.tag==="DataFlow")return T(r=>o=>{if(o.kind.tag==="SendToken")return T(i=>s=>rt(P)(s)()(i))(r)(o.kind._1.labels);if(o.kind.tag==="FillNodeWithoutTransition")return T(i=>s=>rt(P)(s)()(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()})(I)(t.scenes),ET=t=>{const e=_a(n=>{const r=H1($1)(n);return()=>{const o=r();return b(n,{labelW:o,charCount:ir(po(n)),lineCount:1})}})(Zt(fn.foldr,lT(St(Zt(fn.foldr,ST(t)))(K1))));return()=>{const n=e();return hT(n)}},ed=t=>{const e=ET(t);return()=>{const n=e(),r=_a(ed)(j1(t))();return T(pT)(n)(r)}},GT=nt(4)*8,PT=t=>St(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()}),BT=t=>e=>n=>{const r=o=>{const i=Tt(s=>{const a=mT(s)(t);return a.tag==="Just"?N("Just",{w:a._1.labelW+28,h:nt(jN(1)(a._1.lineCount))*13.2+12}):J})(St(o)(K1));return i.length===0?J:N("Just",{w:T(Y1)(0)(O(s=>s.w)(i)),h:T(Y1)(0)(O(s=>s.h)(i))})};return T(o=>i=>{if(i.kind.tag==="SendToken"){const s=Dc(i.kind._1.edge)(n.edges),a=r(i.kind._1.labels);if(a.tag==="Just"&&s.tag==="Just"){const u=a._1;return Qt(P)(le)(i.kind._1.edge)(O(c=>({x:c.x+14+u.w,y:c.y-6-8-u.h}))(s._1))(o)}return o}if(i.kind.tag==="FillNodeWithoutTransition"){const s=ji(i.kind._1.node)(n.nodes),a=r(i.kind._1.labels);return a.tag==="Just"&&s.tag==="Just"?Qt(P)(le)("__fill__:"+i.kind._1.node)((()=>{const u=s._1.y-a._1.h-14,c=s._1.x+s._1.w/2,_=c-a._1.w/2,d=c+a._1.w/2,l=s._1.y-14;return[{x:_,y:u},{x:d,y:u},{x:_,y:l},{x:d,y:l}]})())(o):o}g()})(I)(PT(e))},nd=t=>e=>n=>({layout:(()=>{const r=LT()(iT(GT)(t)(oT(rT)(Z1(n))));return{...r,chipExtras:BT(e)(n)(r)}})(),interiors:(()=>{const r=nd(t)(e),o=i=>{if(i.tag==="Leaf")return I;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(n.interiors)})()}),rd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Rc=t=>e=>n=>{const r=t<.05?t:.05,o=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return o((()=>{const u=rd(a._3)(n),c=(()=>{if(u.tag==="Just")return u._1;if(u.tag==="Nothing")return{x:a._4.x,y:a._4.y,vx:0,vy:0};g()})(),_=c.vx+(180*(a._4.x-c.x)-22*c.vx)*r,d=c.vy+(180*(a._4.y-c.y)-22*c.vy)*r;return rt(P)(a._3)({x:c.x+_*r,y:c.y+d*r,vx:_,vy:d})(o(s,a._5))})(),a._6);g()},i=o(I,e);return{springs:i,applied:(()=>{const s=(a,u)=>{if(u.tag==="Leaf")return a;if(u.tag==="Node")return s((()=>{const c=s(a,u._5),_=rd(u._3)(i);if(_.tag==="Just")return rt(P)(u._3)({...u._4,x:_._1.x,y:_._1.y})(c);if(_.tag==="Nothing")return rt(P)(u._3)(u._4)(c);g()})(),u._6);g()};return s(I,e)})()}},st=(t,e)=>({tag:"CatQueue",_1:t,_2:e}),DT=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=J;continue}e=st((i=>s=>{let a=i,u=s,c=!0,_;for(;c;){const d=a,l=u;if(l.tag==="Nil"){c=!1,_=d;continue}if(l.tag==="Cons"){a=Lt("Cons",l._1,d),u=l._2;continue}g()}return _})($)(o._2),$);continue}if(o._1.tag==="Cons"){n=!1,r=N("Just",b(o._1._1,st(o._1._2,o._2)));continue}g()}return r},at=(t,e,n)=>({tag:t,_1:e,_2:n}),_t=at("CatNil"),RT=t=>e=>{if(t.tag==="CatNil")return e;if(e.tag==="CatNil")return t;if(t.tag==="CatCons")return at("CatCons",t._1,st(t._2._1,Lt("Cons",e,t._2._2)));g()},AT=t=>e=>n=>{const r=o=>i=>s=>{let a=o,u=i,c=s,_=!0,d;for(;_;){const l=a,f=u,h=c;if(h.tag==="Nil"){_=!1,d=f;continue}if(h.tag==="Cons"){a=l,u=l(f)(h._1),c=h._2;continue}g()}return d};return(o=>i=>{let s=o,a=i,u=!0,c;for(;u;){const _=s,d=a,l=DT(_);if(l.tag==="Nothing"){u=!1,c=r(f=>h=>h(f))(e)(d);continue}if(l.tag==="Just"){s=l._1._2,a=Lt("Cons",t(l._1._1),d);continue}g()}return c})(n)($)},IT=t=>{if(t.tag==="CatNil")return J;if(t.tag==="CatCons")return N("Just",b(t._1,t._2._1.tag==="Nil"&&t._2._2.tag==="Nil"?_t:AT(RT)(_t)(t._2)));g()},tt=(t,e)=>({tag:"Free",_1:t,_2:e}),ut=(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=IT(o._2);if(i.tag==="Nothing"){n=!1,r=ut("Return",o._1._1);continue}if(i.tag==="Just"){e=(()=>{const s=i._1._1(o._1._1);return tt(s._1,(()=>{if(s._2.tag==="CatNil")return i._1._2;if(i._1._2.tag==="CatNil")return s._2;if(s._2.tag==="CatCons")return at("CatCons",s._2._1,st(s._2._2._1,Lt("Cons",i._1._2,s._2._2._2)));g()})())})();continue}g()}if(o._1.tag==="Bind"){n=!1,r=ut("Bind",o._1._1,i=>{const s=o._1._2(i);return tt(s._1,(()=>{if(s._2.tag==="CatNil")return o._2;if(o._2.tag==="CatNil")return s._2;if(s._2.tag==="CatCons")return at("CatCons",s._2._1,st(s._2._2._1,Lt("Cons",o._2,s._2._2._2)));g()})())});continue}g()}return r},FT=t=>e=>{const n=e.Monad0(),r=n.Bind1().Apply0().Functor0();return o=>e.tailRecM(i=>{const s=od(i);if(s.tag==="Return")return r.map(_0)(n.Applicative0().pure(s._1));if(s.tag==="Bind")return r.map(fu)(o(t.map(s._2)(s._1)));g()})},QT=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);g()},Ac={Applicative0:()=>Jo,Bind1:()=>id},MT={map:t=>e=>id.bind(e)(n=>Jo.pure(t(n)))},id={bind:t=>e=>tt(t._1,(()=>{if(t._2.tag==="CatNil")return at("CatCons",e,st($,$));if(t._2.tag==="CatCons")return at("CatCons",t._2._1,st(t._2._2._1,Lt("Cons",at("CatCons",e,st($,$)),t._2._2._2)));g()})()),Apply0:()=>sd},sd={apply:t=>e=>{const n=r=>tt(e._1,(()=>{if(e._2.tag==="CatNil")return at("CatCons",o=>Jo.pure(r(o)),st($,$));if(e._2.tag==="CatCons")return at("CatCons",e._2._1,st(e._2._2._1,Lt("Cons",at("CatCons",o=>Jo.pure(r(o)),st($,$)),e._2._2._2)));g()})());return tt(t._1,(()=>{if(t._2.tag==="CatNil")return at("CatCons",n,st($,$));if(t._2.tag==="CatCons")return at("CatCons",t._2._1,st(t._2._2._1,Lt("Cons",at("CatCons",n,st($,$)),t._2._2._2)));g()})())},Functor0:()=>MT},Jo={pure:t=>tt(ut("Return",t),_t),Apply0:()=>sd},zT=()=>()=>()=>t=>e=>n=>Kp(n.type)(t)?jp(n.type)(t)(n.value):e(n),WT={map:t=>e=>({type:e.type,value:e.map(t)(e.value),map:e.map})},qT=t=>z_("Data.Functor.Variant: pattern match failure ["+t.type+"]"),OT=()=>()=>()=>t=>zT()()()(t)(qT);(function(){var t={},e="Pure",n="Throw",r="Catch",o="Sync",i="Async",s="Bind",a="Bracket",u="Fork",c="Sequential",_="Map",d="Apply",l="Alt",f="Cons",h="Resume",p="Release",m="Finalizer",w="Finalized",y="Forked";function x(G,Q,V,X){this.tag=G,this._1=Q,this._2=V,this._3=X}function v(G){var Q=function(V,X,U){return new x(G,V,X,U)};return Q.tag=G,Q}function C(G){return new x(e,void 0)}function L(G){try{G()}catch(Q){setTimeout(function(){throw Q},0)}}function E(G,Q,V){try{return Q(V())}catch(X){return G(X)}}function B(G,Q,V){try{return Q(V)()}catch(X){return V(G(X))(),C}}var z=(function(){var G=1024,Q=0,V=0,X=new Array(G),U=!1;function q(){var K;for(U=!0;Q!==0;)Q--,K=X[V],X[V]=void 0,V=(V+1)%G,K();U=!1}return{isDraining:function(){return U},enqueue:function(K){var et;Q===G&&(et=U,q(),U=et),X[(V+Q)%G]=K,Q++,U||q()}}})();function Y(G){var Q={},V=0,X=0;return{register:function(U){var q=V++;U.onComplete({rethrow:!0,handler:function(K){return function(){X--,delete Q[q]}}})(),Q[q]=U,X++},isEmpty:function(){return X===0},killAll:function(U,q){return function(){if(X===0)return q();var K=0,et={};function lt(pt){et[pt]=Q[pt].kill(U,function(vt){return function(){delete et[pt],K--,G.isLeft(vt)&&G.fromLeft(vt)&&setTimeout(function(){throw G.fromLeft(vt)},0),K===0&&q()}})()}for(var bt in Q)Q.hasOwnProperty(bt)&&(K++,lt(bt));return Q={},V=0,X=0,function(pt){return new x(o,function(){for(var vt in et)et.hasOwnProperty(vt)&&et[vt]()})}}}}}var R=0,A=1,j=2,Z=3,M=4,W=5,H=6;function D(G,Q,V){var X=0,U=R,q=V,K=null,et=null,lt=null,bt=null,pt=null,vt=0,Gt=0,jt=null,Ct=!0;function Yt(ct){for(var yt,dt,ht;;)switch(yt=null,dt=null,ht=null,U){case j:U=A;try{q=lt(q),bt===null?lt=null:(lt=bt._1,bt=bt._2)}catch(Dt){U=W,K=G.left(Dt),q=null}break;case Z:G.isLeft(q)?(U=W,K=q,q=null):lt===null?U=W:(U=j,q=G.fromRight(q));break;case A:switch(q.tag){case s:lt&&(bt=new x(f,lt,bt)),lt=q._2,U=A,q=q._1;break;case e:lt===null?(U=W,q=G.right(q._1)):(U=j,q=q._1);break;case o:U=Z,q=E(G.left,G.right,q._1);break;case i:U=M,q=B(G.left,q._1,function(Dt){return function(){X===ct&&(X++,z.enqueue(function(){X===ct+1&&(U=Z,q=Dt,Yt(X))}))}});return;case n:U=W,K=G.left(q._1),q=null;break;case r:lt===null?pt=new x(f,q,pt,et):pt=new x(f,q,new x(f,new x(h,lt,bt),pt,et),et),lt=null,bt=null,U=A,q=q._1;break;case a:vt++,lt===null?pt=new x(f,q,pt,et):pt=new x(f,q,new x(f,new x(h,lt,bt),pt,et),et),lt=null,bt=null,U=A,q=q._1;break;case u:U=Z,yt=D(G,Q,q._2),Q&&Q.register(yt),q._1&&yt.run(),q=G.right(yt);break;case c:U=A,q=S(G,Q,q._1);break}break;case W:if(lt=null,bt=null,pt===null)U=H,q=et||K||q;else switch(yt=pt._3,ht=pt._1,pt=pt._2,ht.tag){case r:et&&et!==yt&&vt===0?U=W:K&&(U=A,q=ht._2(G.fromLeft(K)),K=null);break;case h:et&&et!==yt&&vt===0||K?U=W:(lt=ht._1,bt=ht._2,U=j,q=G.fromRight(q));break;case a:vt--,K===null&&(dt=G.fromRight(q),pt=new x(f,new x(p,ht._2,dt),pt,yt),(et===yt||vt>0)&&(U=A,q=ht._3(dt)));break;case p:pt=new x(f,new x(w,q,K),pt,et),U=A,et&&et!==yt&&vt===0?q=ht._1.killed(G.fromLeft(et))(ht._2):K?q=ht._1.failed(G.fromLeft(K))(ht._2):q=ht._1.completed(G.fromRight(q))(ht._2),K=null,vt++;break;case m:vt++,pt=new x(f,new x(w,q,K),pt,et),U=A,q=ht._1;break;case w:vt--,U=W,q=ht._1,K=ht._2;break}break;case H:for(var Et in jt)jt.hasOwnProperty(Et)&&(Ct=Ct&&jt[Et].rethrow,L(jt[Et].handler(q)));jt=null,et&&K?setTimeout(function(){throw G.fromLeft(K)},0):G.isLeft(q)&&Ct&&setTimeout(function(){if(Ct)throw G.fromLeft(q)},0);return;case R:U=A;break;case M:return}}function Rt(ct){return function(){if(U===H)return Ct=Ct&&ct.rethrow,ct.handler(q)(),function(){};var yt=Gt++;return jt=jt||{},jt[yt]=ct,function(){jt!==null&&delete jt[yt]}}}function wt(ct,yt){return function(){if(U===H)return yt(G.right(void 0))(),function(){};var dt=Rt({rethrow:!1,handler:function(){return yt(G.right(void 0))}})();switch(U){case R:et=G.left(ct),U=H,q=et,Yt(X);break;case M:et===null&&(et=G.left(ct)),vt===0&&(U===M&&(pt=new x(f,new x(m,q(ct)),pt,et)),U=W,q=null,K=null,Yt(++X));break;default:et===null&&(et=G.left(ct)),vt===0&&(U=W,q=null,K=null)}return dt}}function mt(ct){return function(){var yt=Rt({rethrow:!1,handler:ct})();return U===R&&Yt(X),yt}}return{kill:wt,join:mt,onComplete:Rt,isSuspended:function(){return U===R},run:function(){U===R&&(z.isDraining()?Yt(X):z.enqueue(function(){Yt(X)}))}}}function F(G,Q,V,X){var U=0,q={},K=0,et={},lt=new Error("[ParAff] Early exit"),bt=null,pt=t;function vt(Rt,wt,mt){var ct=wt,yt=null,dt=null,ht=0,Et={},Dt,Mt;t:for(;;)switch(Dt=null,ct.tag){case y:if(ct._3===t&&(Dt=q[ct._1],Et[ht++]=Dt.kill(Rt,function(ne){return function(){ht--,ht===0&&mt(ne)()}})),yt===null)break t;ct=yt._2,dt===null?yt=null:(yt=dt._1,dt=dt._2);break;case _:ct=ct._2;break;case d:case l:yt&&(dt=new x(f,yt,dt)),yt=ct,ct=ct._1;break}if(ht===0)mt(G.right(void 0))();else for(Mt=0,Dt=ht;Mt<Dt;Mt++)Et[Mt]=Et[Mt]();return Et}function Gt(Rt,wt,mt){var ct,yt,dt,ht,Et,Dt;for(G.isLeft(Rt)?(ct=Rt,yt=null):(yt=Rt,ct=null);;){if(dt=null,ht=null,Et=null,Dt=null,bt!==null)return;if(wt===null){X(ct||yt)();return}if(wt._3!==t)return;switch(wt.tag){case _:ct===null?(wt._3=G.right(wt._1(G.fromRight(yt))),yt=wt._3):wt._3=ct;break;case d:if(dt=wt._1._3,ht=wt._2._3,ct){if(wt._3=ct,Et=!0,Dt=K++,et[Dt]=vt(lt,ct===dt?wt._2:wt._1,function(){return function(){delete et[Dt],Et?Et=!1:mt===null?Gt(ct,null,null):Gt(ct,mt._1,mt._2)}}),Et){Et=!1;return}}else{if(dt===t||ht===t)return;yt=G.right(G.fromRight(dt)(G.fromRight(ht))),wt._3=yt}break;case l:if(dt=wt._1._3,ht=wt._2._3,dt===t&&G.isLeft(ht)||ht===t&&G.isLeft(dt))return;if(dt!==t&&G.isLeft(dt)&&ht!==t&&G.isLeft(ht))ct=yt===dt?ht:dt,yt=null,wt._3=ct;else if(wt._3=yt,Et=!0,Dt=K++,et[Dt]=vt(lt,yt===dt?wt._2:wt._1,function(){return function(){delete et[Dt],Et?Et=!1:mt===null?Gt(yt,null,null):Gt(yt,mt._1,mt._2)}}),Et){Et=!1;return}break}mt===null?wt=null:(wt=mt._1,mt=mt._2)}}function jt(Rt){return function(wt){return function(){delete q[Rt._1],Rt._3=wt,Gt(wt,Rt._2._1,Rt._2._2)}}}function Ct(){var Rt=A,wt=V,mt=null,ct=null,yt,dt;t:for(;;)switch(yt=null,dt=null,Rt){case A:switch(wt.tag){case _:mt&&(ct=new x(f,mt,ct)),mt=new x(_,wt._1,t,t),wt=wt._2;break;case d:mt&&(ct=new x(f,mt,ct)),mt=new x(d,t,wt._2,t),wt=wt._1;break;case l:mt&&(ct=new x(f,mt,ct)),mt=new x(l,t,wt._2,t),wt=wt._1;break;default:dt=U++,Rt=W,yt=wt,wt=new x(y,dt,new x(f,mt,ct),t),yt=D(G,Q,yt),yt.onComplete({rethrow:!1,handler:jt(wt)})(),q[dt]=yt,Q&&Q.register(yt)}break;case W:if(mt===null)break t;mt._1===t?(mt._1=wt,Rt=A,wt=mt._2,mt._2=t):(mt._2=wt,wt=mt,ct===null?mt=null:(mt=ct._1,ct=ct._2))}for(pt=wt,dt=0;dt<U;dt++)q[dt].run()}function Yt(Rt,wt){bt=G.left(Rt);var mt;for(var ct in et)if(et.hasOwnProperty(ct)){mt=et[ct];for(ct in mt)mt.hasOwnProperty(ct)&&mt[ct]()}et=null;var yt=vt(Rt,pt,wt);return function(dt){return new x(i,function(ht){return function(){for(var Et in yt)yt.hasOwnProperty(Et)&&yt[Et]();return C}})}}return Ct(),function(Rt){return new x(i,function(wt){return function(){return Yt(Rt,wt)}})}}function S(G,Q,V){return new x(i,function(X){return function(){return F(G,Q,V,X)}})}return x.EMPTY=t,x.Pure=v(e),x.Throw=v(n),x.Catch=v(r),x.Sync=v(o),x.Async=v(i),x.Bind=v(s),x.Bracket=v(a),x.Fork=v(u),x.Seq=v(c),x.ParMap=v(_),x.ParApply=v(d),x.ParAlt=v(l),x.Fiber=D,x.Supervisor=Y,x.Scheduler=z,x.nonCanceler=C,x})();const HT=t=>e=>QT(n=>r=>t({type:n.type,value:n.map(o=>r(o))(n.value),map:n.map}))(e),$T=t=>{const e=t.Bind1(),n=t.Applicative0().pure;return r=>{const o=Xp(()=>HT(i=>e.bind(r(i))(o()))(n));return o()}};let ad=null;function VT(){return ad||(typeof document>"u"?null:ad=document.createElement("canvas").getContext("2d"))}const Ic=new Map;function ud(t,e,n,r,o,i){const s=`${n} ${e}px ${t}`,a=s+"|"+r;if(Ic.has(a))return Ic.get(a);const u=VT();if(!u)return i;u.font=s;const c=o(u.measureText(r)),_=typeof document<"u"?document.fonts:null;if(!_||_.check(s))Ic.set(a,c);else if(_&&_.load)try{_.load(s)}catch{}return c}const UT=(t,e,n,r)=>ud(t,e,n,r,o=>o.width,-1),XT=(t,e,n,r)=>ud(t,e,n,r,o=>({ascent:o.actualBoundingBoxAscent,descent:o.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),da=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),cd=t=>t,gd={map:t=>e=>{if(e.tag==="MeasureText")return da("MeasureText",e._1,e._2,n=>t(e._3(n)));if(e.tag==="MeasureInk")return da("MeasureInk",e._1,e._2,n=>t(e._3(n)));g()}},Fc=t=>e=>{const n=UT(t.family,t.size,t.weight,po(e));return n<0?nt(Ko(e).length)*t.size*.62:n},Qc=t=>e=>{const n=XT(t.family,t.size,t.weight,po(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},YT=t=>e=>tt(ut("Bind",{type:"metrics",value:da("MeasureInk",t,e,cd),map:gd.map},n=>tt(ut("Return",n),_t)),_t),ts=t=>e=>tt(ut("Bind",{type:"metrics",value:da("MeasureText",t,e,cd),map:gd.map},n=>tt(ut("Return",n),_t)),_t),_d=t=>t,fd=t=>t,la=t=>t,dd=t=>t,ld=t=>t,$t=(t,e,n,r,o)=>({tag:t,_1:e,_2:n,_3:r,_4:o}),hd=t=>t,Mc=t=>t,KT=Mc("BaselineTop"),En=Mc("BaselineMiddle"),jT=Mc("BaselineBottom"),fi=hd("AlignLeft"),Dr=hd("AlignCenter"),Ue=ld("RoundJoin"),es=ld("MiterJoin"),Gn=dd("ButtCap"),Un=dd("RoundCap"),ZT=la("LayerPolyOut"),tv=la("LayerPolyIn"),ev=la("LayerNodeMask"),nv=la("LayerOverlay"),ns=fd("NonZero"),rv=fd("EvenOdd"),pd=_d("Normal"),ha=_d("Difference"),ye={r:255,g:255,b:255,a:255},rs=[5],Je={map:t=>e=>{if(e.tag==="FillPath")return $t("FillPath",e._1,e._2,t(e._3));if(e.tag==="StrokePath")return $t("StrokePath",e._1,e._2,t(e._3));if(e.tag==="FillStrokePath")return $t("FillStrokePath",e._1,e._2,e._3,t(e._4));if(e.tag==="DrawText")return $t("DrawText",e._1,t(e._2));if(e.tag==="DrawTextAffine")return $t("DrawTextAffine",e._1,e._2,t(e._3));if(e.tag==="PushTransform")return $t("PushTransform",e._1,t(e._2));if(e.tag==="PopTransform")return $t("PopTransform",t(e._1));if(e.tag==="PushClip")return $t("PushClip",e._1,e._2,t(e._3));if(e.tag==="PopClip")return $t("PopClip",t(e._1));if(e.tag==="PushBlend")return $t("PushBlend",e._1,t(e._2));if(e.tag==="PopBlend")return $t("PopBlend",t(e._1));if(e.tag==="PushAlpha")return $t("PushAlpha",e._1,t(e._2));if(e.tag==="PopAlpha")return $t("PopAlpha",t(e._1));if(e.tag==="PushBlur")return $t("PushBlur",e._1,t(e._2));if(e.tag==="PopBlur")return $t("PopBlur",t(e._1));if(e.tag==="PushLayer")return $t("PushLayer",e._1,t(e._2));if(e.tag==="PopLayer")return $t("PopLayer",t(e._1));if(e.tag==="SetViewport")return $t("SetViewport",e._1,t(e._2));if(e.tag==="ClearBackground")return $t("ClearBackground",e._1,t(e._2));if(e.tag==="BackgroundDots")return $t("BackgroundDots",e._1,t(e._2));g()}},Rr={r:26,g:26,b:26,a:255},zc=t=>e=>Math.imul(t,e),di=t=>{const e=t+1831565813|0,n=zc(e^e>>>15)(e|1),r=n^(n+zc(n^n>>>7)(n|61)|0),o=r^r>>>14;return{prng:o,value:o<0?(nt(o)+4294967296)/4294967296:nt(o)/4294967296}},Ee=t=>e=>n=>{const r=di(n);return{prng:r.prng,value:t+r.value*(e-t)}},Wc=t=>e=>T(n=>r=>zc(n^r)(-2048144789))(e)(O(jr)(br(t))),ov=t=>t,md=t=>t,iv=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jn=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},yd=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},qc=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},sv=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},av=md("FlatLevel"),uv=md("NestedLevel"),Oc=ov("GenieSilhouette"),cv=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const o=di(t);return{prng:o.prng,yLift:o.value*n.yJitter*r}},gv=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const o=di(t);return{prng:o.prng,dx:(o.value*2-1)*n.xJitter*r}},xd=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,o=Ve(r*r+n*n),i=(t.r*t.r-e.r*e.r+o*o)/(2*o),s=Ve(iv(0)(t.r*t.r-i*i)),a=t.cx+i*r/o,u=t.cy+i*n/o,c={x:a-s*n/o,y:u+s*r/o},_={x:a+s*n/o,y:u-s*r/o};return o===0||o>t.r+e.r?{x:(t.cx+e.cx)/2,y:t.cy}:c.y<_.y?c:_},li=t=>e=>{const n=Jn(e)(Jn(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]},_v=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 s=di(t);return{prng:s.prng,r:o*(1+s.value*i.rJitter)}},wd=t=>{const e=Jn(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]},fv=t=>e=>n=>{const r=di(t),o=e.length;return o===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const i=yd(0)(o-1|0)(fe(In(r.value*nt(n))));return i>=0&&i<e.length?e[i]:-1})()}},dv=t=>e=>{const n=di(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const o=yd(0)(r-1|0)(fe(In(n.value*nt(r))));return o>=0&&o<e.length?e[o]:-1})()}},Jd=t=>{const e=Jn(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]},Nd=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],Td={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},lv=t=>{const e=Jn(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]},vd=t=>{const e=Jn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+t.h+5,o=t.y+e,i=r-e,s=t.x+n;return[1,t.x,o,4,t.x,o-.5522847498*e,s-.5522847498*n,t.y,s,t.y,4,s+.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,s+.5522847498*n,r,s,r,4,s-.5522847498*n,r,t.x,i+.5522847498*e,t.x,i,5]},Cd=t=>e=>{const n=e.y+e.h,r=O0(t.rBase*e.h)(e.w/(2*(1+(nt(t.minN)-1)*t.stepRatio))),o=e.w-2*r,i=2*r*t.stepRatio,s=qc(t.minN)(o<=0||i<=0?t.minN:fe($n(o/i))+1|0),a=s>=3?Kt(1,s-2|0):[],u=a.length,c=Tr(u+1|0,2),_=c<1?[]:Bt(0,c,a),d=dv(t.seed)((()=>{const m=u-c|0;return m<1?a:Bt(m,a.length,a)})()),l=d.idx,f=fv(d.prng)(ft(m=>m!==l,_))(qc(1)(_.length-(en(qr)(l)(_)?1:0)|0)),h=f.idx,p=s>=2?o/(nt(s)-1):0;return T(m=>w=>{const y=w===h,x=w===l,v=w===0||w===(s-1|0),C=_v(m.prng)(v)(x)(y)(r)(t),L=cv(C.prng)(v)(t)(e.h),E=gv(L.prng)(v)(t)(p);return{prng:E.prng,circles:kt(m.circles)({cx:e.x+sv(C.r)(e.w-C.r)((s>=2?r+nt(w)/(nt(s)-1)*o+E.dx:r+0*o+E.dx)+(x?t.heroShift*p:y?-1*t.smallShift*p:0)),cy:n-L.yLift,r:C.r})}})({prng:f.prng,circles:[]})(Kt(0,s-1|0)).circles},bd=t=>e=>{const n=t.length;return Ht(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?xd(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?xd(o)(t[i]):{x:o.cx+o.r,y:e}})()}))(t)},kd=t=>{const e=Jn(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]},hv=t=>e=>n=>{const r=co(e.y-t.cy)(e.x-t.cx),o=co(n.y-t.cy)(n.x-t.cx),i=o>r?o-r:o+6.283185307179586-r,s=qc(1)(fe(xs(i/1.5707963267948966))),a=i/nt(s),u=1.3333333333333333*H0(a/4);return St(Kt(0,s-1|0))(c=>{const _=r+nt(c+1|0)*a,d=t.cx+t.r*Ln(_),l=t.cy+t.r*pn(_),f=r+nt(c)*a;return[4,t.cx+t.r*Ln(f)-u*t.r*pn(f),t.cy+t.r*pn(f)+u*t.r*Ln(f),d+u*t.r*pn(_),l-u*t.r*Ln(_),d,l]})},Ld=t=>e=>{const n=t.h*.38,r=bd(Cd(Td)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),o=Jn(e)(Jn(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...St(r)(i=>hv(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]:li(t)(e)},pv=t=>e=>n=>r=>o=>i=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(o)(i);if(e==="Cylinder"){const s=vd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Parallelogram"){const s=Jd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Diamond"){const s=kd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Ellipse"){const s=wd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Document"){const s=Nd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Cloud"){const s=Ld(n)(r);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}return t.drawRoundedRect(n)(r)(o)(i)},mv={fillPath:t=>e=>tt(ut("Bind",{type:"render",value:$t("FillPath",t,e,void 0),map:Je.map},n=>tt(ut("Return",n),_t)),_t),strokePath:t=>e=>tt(ut("Bind",{type:"render",value:$t("StrokePath",t,e,void 0),map:Je.map},n=>tt(ut("Return",n),_t)),_t),fillStrokePath:t=>e=>n=>tt(ut("Bind",{type:"render",value:$t("FillStrokePath",t,e,n,void 0),map:Je.map},r=>tt(ut("Return",r),_t)),_t),drawRoundedRect:t=>e=>n=>r=>{if(n.tag==="Just"){if(r.tag==="Just")return tt(ut("Bind",{type:"render",value:$t("FillStrokePath",li(t)(e),n._1,r._1,void 0),map:Je.map},o=>tt(ut("Return",o),_t)),_t);if(r.tag==="Nothing")return tt(ut("Bind",{type:"render",value:$t("FillPath",li(t)(e),n._1,void 0),map:Je.map},o=>tt(ut("Return",o),_t)),_t);g()}if(n.tag==="Nothing"){if(r.tag==="Just")return tt(ut("Bind",{type:"render",value:$t("StrokePath",li(t)(e),r._1,void 0),map:Je.map},o=>tt(ut("Return",o),_t)),_t);if(r.tag==="Nothing")return tt(ut("Return",void 0),_t)}g()},drawText:t=>tt(ut("Bind",{type:"render",value:$t("DrawText",t,void 0),map:Je.map},e=>tt(ut("Return",e),_t)),_t),drawTextAffine:t=>e=>tt(ut("Bind",{type:"render",value:$t("DrawTextAffine",t,e,void 0),map:Je.map},n=>tt(ut("Return",n),_t)),_t),pushTransform:t=>tt(ut("Bind",{type:"render",value:$t("PushTransform",t,void 0),map:Je.map},e=>tt(ut("Return",e),_t)),_t),popTransform:tt(ut("Bind",{type:"render",value:$t("PopTransform",void 0),map:Je.map},t=>tt(ut("Return",t),_t)),_t),pushBakedTransform:t=>tt(ut("Bind",{type:"render",value:$t("PushTransform",t,void 0),map:Je.map},e=>tt(ut("Return",e),_t)),_t),popBakedTransform:tt(ut("Bind",{type:"render",value:$t("PopTransform",void 0),map:Je.map},t=>tt(ut("Return",t),_t)),_t),pushClip:t=>e=>tt(ut("Bind",{type:"render",value:$t("PushClip",t,e,void 0),map:Je.map},n=>tt(ut("Return",n),_t)),_t),popClip:tt(ut("Bind",{type:"render",value:$t("PopClip",void 0),map:Je.map},t=>tt(ut("Return",t),_t)),_t),pushBlend:t=>tt(ut("Bind",{type:"render",value:$t("PushBlend",t,void 0),map:Je.map},e=>tt(ut("Return",e),_t)),_t),popBlend:tt(ut("Bind",{type:"render",value:$t("PopBlend",void 0),map:Je.map},t=>tt(ut("Return",t),_t)),_t),pushAlpha:t=>tt(ut("Bind",{type:"render",value:$t("PushAlpha",t,void 0),map:Je.map},e=>tt(ut("Return",e),_t)),_t),popAlpha:tt(ut("Bind",{type:"render",value:$t("PopAlpha",void 0),map:Je.map},t=>tt(ut("Return",t),_t)),_t),pushBlur:t=>tt(ut("Bind",{type:"render",value:$t("PushBlur",t,void 0),map:Je.map},e=>tt(ut("Return",e),_t)),_t),popBlur:tt(ut("Bind",{type:"render",value:$t("PopBlur",void 0),map:Je.map},t=>tt(ut("Return",t),_t)),_t),pushLayer:t=>tt(ut("Bind",{type:"render",value:$t("PushLayer",t,void 0),map:Je.map},e=>tt(ut("Return",e),_t)),_t),popLayer:tt(ut("Bind",{type:"render",value:$t("PopLayer",void 0),map:Je.map},t=>tt(ut("Return",t),_t)),_t),setViewport:t=>tt(ut("Bind",{type:"render",value:$t("SetViewport",t,void 0),map:Je.map},e=>tt(ut("Return",e),_t)),_t),clearBackground:t=>tt(ut("Bind",{type:"render",value:$t("ClearBackground",t,void 0),map:Je.map},e=>tt(ut("Return",e),_t)),_t),backgroundDots:t=>tt(ut("Bind",{type:"render",value:$t("BackgroundDots",t,void 0),map:Je.map},e=>tt(ut("Return",e),_t)),_t),measureText:t=>e=>ts(t)(e),measureInk:t=>e=>YT(t)(e),insideTokenStyle:t=>tt(ut("Return",Oc),_t),Monad0:()=>Ac},yv=t=>()=>t.clip("evenodd"),xv=t=>e=>()=>{t.filter=`blur(${e}px)`},wv=t=>e=>()=>{const n=e>0?t.canvas.width/e:1;t.setTransform(n,0,0,n,0,0)},Jv=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)},Nv=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 s=t.createPattern(o,"repeat");s&&typeof s.setTransform=="function"&&s.setTransform(new DOMMatrix().translateSelf(e.ox,e.oy).scaleSelf(1/n,1/n)),t.save(),t.fillStyle=s,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},Hc=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},$c=t=>e=>n=>{const r=e.stroke;return()=>{const o=r.value,i=gm(t)(n);if(o!==n)return i(),e.stroke.value=n}},Tv=t=>e=>n=>{const r=e.font;return()=>{const o=r.value,i=xm(t)(n);if(o!==n)return i(),e.font.value=n}},os=t=>e=>n=>{const r=e.fill;return()=>{const o=r.value,i=cm(t)(n);if(o!==n)return i(),e.fill.value=n}},pa=t=>e=>{const n=e.length,r=i=>{if(i>=n)return()=>{};const s=i>=0&&i<e.length?e[i]:0;if(s===1){const a=E_(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()=>(a(),u())}if(s===2){const a=Li(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()=>(a(),u())}if(s===3){const a=Si(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()=>(a(),u())}if(s===4){const a=Jm(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()=>(a(),u())}if(s===5){const a=G_(t),u=r(i+1|0);return()=>(a(),u())}return()=>{}},o=S_(t);return()=>(o(),r(0)())},vv=t=>e=>n=>r=>o=>i=>{const s=Hc(i)(Hc(r/2)(o/2)),a=E_(t)(e+s)(n);return()=>(a(),Li(t)(e+r-s)(n)(),Si(t)({cpx:e+r,cpy:n,x:e+r,y:n+s})(),Li(t)(e+r)(n+o-s)(),Si(t)({cpx:e+r,cpy:n+o,x:e+r-s,y:n+o})(),Li(t)(e+s)(n+o)(),Si(t)({cpx:e,cpy:n+o,x:e,y:n+o-s})(),Li(t)(e)(n+s)(),Si(t)({cpx:e,cpy:n,x:e+s,y:n})(),G_(t)())},Cv=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),Sd=t=>e=>{const n=hm(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=Cv();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0},groupAlpha:{value:1},alphaSaves:{value:[]}}}},bv={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},kv=t=>ie(t.weight)+" "+ao(t.size)+"px "+t.family,dr=t=>{const e=ao(nt(t.a)/255);return t.a>=255?"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")":"rgba("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+","+e+")"},Lv=t=>e=>n=>r=>{const o=rr(t);return()=>(o(),wv(t)(e.width)(),os(t)(n)(dr(r))(),lm(t)({x:0,y:0,width:e.width,height:e.height})(),or(t)(),n.font.value="",n.fill.value="",n.stroke.value="")},Sv=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",Nv(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})())},Ev=t=>e=>n=>r=>{const o=os(t)(e)(dr(r));return()=>(o(),pa(t)(n)(),vu(t)())},Gv=t=>e=>n=>r=>o=>{const i=os(t)(e)(dr(r));return()=>(i(),$c(t)(e)(dr(o.color))(),wu(t)(o.width)(),Du(t)((()=>{if(o.lineJoin==="RoundJoin")return Su;if(o.lineJoin==="BevelJoin")return Lu;if(o.lineJoin==="MiterJoin")return Eu;g()})())(),Ru(t)((()=>{if(o.lineCap==="ButtCap")return Bu;if(o.lineCap==="RoundCap")return Gu;if(o.lineCap==="SquareCap")return Pu;g()})())(),pa(t)(n)(),vu(t)(),Tu(t)())},Pv=t=>e=>n=>r=>o=>i=>{const s=S_(t);return()=>{if(s(),vv(t)(n.x)(n.y)(n.w)(n.h)(r)(),o.tag==="Just"?(os(t)(e)(dr(o._1.color))(),vu(t)()):o.tag==="Nothing"||g(),i.tag==="Just")return $c(t)(e)(dr(i._1.color))(),wu(t)(i._1.width)(),Du(t)((()=>{if(i._1.lineJoin==="RoundJoin")return Su;if(i._1.lineJoin==="BevelJoin")return Lu;if(i._1.lineJoin==="MiterJoin")return Eu;g()})())(),Ru(t)((()=>{if(i._1.lineCap==="ButtCap")return Bu;if(i._1.lineCap==="RoundCap")return Gu;if(i._1.lineCap==="SquareCap")return Pu;g()})())(),Tu(t)();i.tag!=="Nothing"&&g()}},Bv=t=>e=>n=>r=>{const o=$c(t)(e)(dr(r.color));return()=>(o(),wu(t)(r.width)(),Du(t)((()=>{if(r.lineJoin==="RoundJoin")return Su;if(r.lineJoin==="BevelJoin")return Lu;if(r.lineJoin==="MiterJoin")return Eu;g()})())(),Ru(t)((()=>{if(r.lineCap==="ButtCap")return Bu;if(r.lineCap==="RoundCap")return Gu;if(r.lineCap==="SquareCap")return Pu;g()})())(),pa(t)(n)(),Tu(t)())},Ed=t=>e=>n=>{const r=os(t)(e)(dr(n.color));return()=>(r(),Tv(t)(e)(kv(n.font))(),Pm(t)((()=>{if(n.align==="AlignLeft")return bm;if(n.align==="AlignCenter")return Lm;if(n.align==="AlignRight")return km;g()})())(),Gm(t)((()=>{if(n.baseline==="BaselineTop")return Nm;if(n.baseline==="BaselineMiddle")return Tm;if(n.baseline==="BaselineAlphabetic")return vm;if(n.baseline==="BaselineBottom")return Cm;g()})())(),wm(t)(n.content)(n.x)(n.y)())},Gd={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),s=o();return i(s)}},Functor0:()=>bv},Dv={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>Gd},Rv=t=>e=>n=>{const r=Hc(e.width/n.vw)(e.height/n.vh);return Jv(t)(e.width)(r)((e.width-n.vw*r)/2-n.vx*r)((e.height-n.vh*r)/2-n.vy*r)},Av={pure:t=>e=>()=>t,Apply0:()=>Gd},Pd={Applicative0:()=>Av,Bind1:()=>Dv},Vc={fillPath:t=>e=>n=>{const r=Ev(n.ctx)(n.styleCache)(t)(e.color),o=n.maskDepth;return()=>{if(o.value===0)return r()}},strokePath:t=>e=>n=>{const r=Bv(n.ctx)(n.styleCache)(t)(e),o=n.maskDepth;return()=>{if(o.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const o=Gv(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=Pv(o.ctx)(o.styleCache)(t)(e)(n)(r),s=o.maskDepth;return()=>{if(s.value===0)return i()}},drawText:t=>e=>{const n=Ed(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=rr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",pm(n.ctx)(t)(),Ed(n.ctx)(n.styleCache)(e)(),or(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=rr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",P_(e.ctx)({translateX:t.tx,translateY:t.ty})(),Ts(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=or(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=rr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",P_(e.ctx)({translateX:t.tx,translateY:t.ty})(),Ts(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=or(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=rr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",pa(n.ctx)(t)(),e==="NonZero")return dm(n.ctx)();if(e==="EvenOdd")return yv(n.ctx)();g()}}},popClip:t=>{const e=or(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=rr(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 D_(e.ctx)(Sm)();if(t==="Difference")return D_(e.ctx)(Em)();g()}}},popBlend:t=>{const e=or(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=rr(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 s=o*t;return e.groupAlpha.value=s,fm(e.ctx)(s)()}}},popAlpha:t=>{const e=or(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=Cr(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=rr(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=xv(e.ctx)(t);if(t>=.01)return o()}}},popBlur:t=>{const e=or(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=Rv(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=Lv(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=Sv(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=Fc(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Qc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Oc,Monad0:()=>Pd},Iv=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},hi=t=>e=>n=>{const r=Iv(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},Uc=t=>{const e=ot.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ot.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Fv=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:Uc(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()},pi=t=>{if(t.tag==="Hidden")return{alpha:0,scale:0};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:t._1>0?1:0,scale:Ri(8)(.6)(Uc(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:Ri(8)(.6)(Uc(1-t._1))};g()};function Qv(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function Mv(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:Qv(o,i)}}return n}function zv(t,e,n){let r=0;for(let o=0;o<t.length;o++){const i=t[o],s=r,a=s+i.len;if(n<=a){const u=i.len>1e-6?(n-s)/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=a}return e.length>0?e[e.length-1]:{x:0,y:0}}function Bd(t,e){if(e.length===0)return[];const n=Mv(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]=zv(n,e,i*r/t);return o}function Wv(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 qv(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 s=0;for(let a=0;a<n;a++){const u=t[a]||{x:0,y:0},c=e[(a+i)%n]||{x:0,y:0},_=u.x-c.x,d=u.y-c.y;s+=_*_+d*d}s<o&&(o=s,r=i)}return Wv(r,e)}const Dd=t=>e=>n=>{const r=Bd(t,e),o=Bd(t,n),i=qv(r,o);return{from:r,to:i}};function Rd(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 Ov(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 Hv(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],s=e[((o+1)%n+n)%n],a=e[o];r[o]={x:a.x+((i.x+s.x)/2-a.x)*t,y:a.y+((i.y+s.y)/2-a.y)*t}}return r}function $v(t){return t<0?0:t>1?1:t}const Ad=t=>e=>n=>r=>{const o=e.length;if(o===0)return[];const i=Rd(e),s=Rd(n),a=Ov(i,s),u=new Array(o);let c=1/0,_=-1/0;for(let f=0;f<o;f++){const h=e[f],p=(h.x-i.x)*a.x+(h.y-i.y)*a.y;u[f]=p,p<c&&(c=p),p>_&&(_=p)}const d=_-c;let l=new Array(o);for(let f=0;f<o;f++){const h=e[f],p=n[f];if(p===void 0){l[f]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(u[f]-c)/d),w=Math.max(1e-4,1-m),y=$v((t-m)/w),x=y*y*(3-2*y);l[f]={x:h.x+(p.x-h.x)*x,y:h.y+(p.y-h.y)*x}}for(let f=0;f<r.smoothPasses;f++)l=Hv(.5,l);return l},Id=(t,e)=>({tag:t,_1:e}),Fd=(t,e)=>({tag:t,_1:e}),be=(t,e,n)=>({tag:t,_1:e,_2:n}),Qd=t=>t,Xc=(t,e)=>({tag:t,_1:e}),Yc=(t,e)=>({tag:t,_1:e}),Kc=t=>t,ma=(t,e)=>({tag:t,_1:e}),ke=(t,e,n)=>({tag:t,_1:e,_2:n}),No=(t,e)=>({tag:t,_1:e}),is=(t,e)=>({tag:t,_1:e}),Md=(t,e)=>({tag:t,_1:e}),zd=t=>t,Wd=(t,e)=>({tag:t,_1:e}),To=(t,e,n)=>({tag:t,_1:e,_2:n}),qd=t=>t,Vv=t=>t,mi=qd("NormalTransform"),Uv=qd("BakedTransform"),Od=zd("TokenOutside"),Hd=zd("TokenInside"),ya=is("PlainText"),$d=No("FrameTitle"),Xv=No("Watermark"),Yv=Kc("NodeShadow"),Vd=Kc("NodeBody"),Kv=Kc("NodeInversion"),jc=Qd("LabelsShown"),Zc=Qd("LabelsHidden"),On={map:t=>e=>{if(e.tag==="BeginFrame")return ke("BeginFrame",e._1,t(e._2));if(e.tag==="EndFrame")return ke("EndFrame",t(e._1));if(e.tag==="BeginGroup")return ke("BeginGroup",e._1,t(e._2));if(e.tag==="EndGroup")return ke("EndGroup",e._1,t(e._2));if(e.tag==="Background")return ke("Background",e._1,t(e._2));if(e.tag==="Overlay")return ke("Overlay",e._1,t(e._2));if(e.tag==="Node")return ke("Node",e._1,t(e._2));if(e.tag==="Edge")return ke("Edge",e._1,t(e._2));if(e.tag==="Text")return ke("Text",e._1,t(e._2));if(e.tag==="Token")return ke("Token",e._1,t(e._2));if(e.tag==="AskInsideTokenStyle")return ke("AskInsideTokenStyle",e._1,n=>t(e._2(n)));g()}},Ud=t=>e=>ts(t)(e),jv=t=>{const e=t.Bind1().Apply0().Functor0(),n=$T(t);return r=>o=>n(OT()()()({scene:i=>{if(i.tag==="BeginFrame"){const s=i._2;return e.map(a=>s)(r.beginFrame(i._1))}if(i.tag==="EndFrame"){const s=i._1;return e.map(a=>s)(r.endFrame)}if(i.tag==="BeginGroup"){const s=i._2;return e.map(a=>s)(r.beginGroup(i._1))}if(i.tag==="EndGroup"){const s=i._2;return e.map(a=>s)(r.endGroup(i._1))}if(i.tag==="Background"){const s=i._2;return e.map(a=>s)(r.background(i._1))}if(i.tag==="Overlay"){const s=i._2;return e.map(a=>s)(r.overlay(i._1))}if(i.tag==="Node"){const s=i._2;return e.map(a=>s)(r.node(i._1))}if(i.tag==="Edge"){const s=i._2;return e.map(a=>s)(r.edge(i._1))}if(i.tag==="Text"){const s=i._2;return e.map(a=>s)(r.text(i._1))}if(i.tag==="Token"){const s=i._2;return e.map(a=>s)(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)},Zv=t=>tt(ut("Bind",{type:"scene",value:ke("AskInsideTokenStyle",t,Vv),map:On.map},e=>tt(ut("Return",e),_t)),_t),Xd=t=>tt(ut("Bind",{type:"scene",value:ke("Background",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),Yd=t=>tt(ut("Bind",{type:"scene",value:ke("Edge",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),tg=t=>tt(ut("Bind",{type:"scene",value:ke("Node",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),xa=t=>tt(ut("Bind",{type:"scene",value:ke("Overlay",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),ss=t=>tt(ut("Bind",{type:"scene",value:ke("Text",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),Kd=t=>tt(ut("Bind",{type:"scene",value:ke("Token",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),tC=t=>e=>tt(ut("Bind",{type:"scene",value:ke("BeginFrame",t,void 0),map:On.map},n=>tt(ut("Return",n),_t)),at("CatCons",()=>tt(e._1,(()=>{if(e._2.tag==="CatNil")return at("CatCons",()=>tt(ut("Bind",{type:"scene",value:ke("EndFrame",void 0),map:On.map},n=>tt(ut("Return",n),_t)),_t),st($,$));if(e._2.tag==="CatCons")return at("CatCons",e._2._1,st(e._2._2._1,Lt("Cons",at("CatCons",()=>tt(ut("Bind",{type:"scene",value:ke("EndFrame",void 0),map:On.map},n=>tt(ut("Return",n),_t)),_t),st($,$)),e._2._2._2)));g()})()),st($,$))),je=t=>e=>tt(ut("Bind",{type:"scene",value:ke("BeginGroup",t,void 0),map:On.map},n=>tt(ut("Return",n),_t)),at("CatCons",()=>{const n=()=>tt(ut("Bind",{type:"scene",value:ke("EndGroup",t,void 0),map:On.map},r=>tt(ut("Return",r),_t)),_t);return tt(e._1,(()=>{if(e._2.tag==="CatNil")return at("CatCons",n,st($,$));if(e._2.tag==="CatCons")return at("CatCons",e._2._1,st(e._2._2._1,Lt("Cons",at("CatCons",n,st($,$)),e._2._2._2)));g()})())},st($,$))),lr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},jd=T(nr)(0),Zd=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},eC=T(t=>e=>t+e.len)(0),tl=t=>{const e=Ft(n=>J,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,...St(Bt(1,t.length,t))(n=>[2,n.x,n.y]),5];g()},el=t=>e=>{const n=lr(e)(lr(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]},nC=t=>{const e=Ft(n=>J,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,...St(e._1.tail)(n=>[2,n.x,n.y])];g()},eg=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return vd(e);if(t.shape==="Parallelogram")return Jd(e);if(t.shape==="Diamond")return kd(e);if(t.shape==="Ellipse")return wd(e);if(t.shape==="Document")return Nd(e);if(t.shape==="Cloud")return Ld(e)(7);if(t.shape==="Rectangle")return el(e)(7);g()},Ge=t=>e=>n=>O(r=>{const o=nt(r)/nt(n);return{x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o}})(Kt(0,n-1|0)),rC=t=>{const e=Jn(t.w*.18)(t.h*.6);return[...Ge({x:t.x+e,y:t.y})({x:t.x+t.w,y:t.y})(16),...Ge({x:t.x+t.w,y:t.y})({x:t.x+t.w-e,y:t.y+t.h})(16),...Ge({x:t.x+t.w-e,y:t.y+t.h})({x:t.x,y:t.y+t.h})(16),...Ge({x:t.x,y:t.y+t.h})({x:t.x+e,y:t.y})(16)]},as=t=>e=>{const n=lr(t)(lr(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}},ng=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return Ve(r*r+n*n)},oC=t=>Fe(e=>n=>({a:e,b:n,len:ng(e)(n)}),t,Bt(1,t.length,t)),iC=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?N("Just",e[n]):J,o=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];g()})(),i=0<e.length?N("Just",e[0]):J,s=(()=>{if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return{x:0,y:0};g()})(),a=e.length;return a<3?e:[s,...St(Kt(1,a-2|0))(u=>{const c=u+1|0,_=c>=0&&c<e.length?N("Just",e[c]):J,d=u>=0&&u<e.length?N("Just",e[u]):J,l=u-1|0,f=l>=0&&l<e.length?N("Just",e[l]):J;if(f.tag==="Just"&&d.tag==="Just"&&_.tag==="Just"){const h=d._1,p=ng(h)(_._1),m=ng(f._1)(h),w=lr(t)(p/2),y=lr(t)(m/2),x=p>0?w/p:0,v=h.x+(_._1.x-h.x)*x,C=h.y+(_._1.y-h.y)*x,L=m>0?y/m:0,E=h.x+(f._1.x-h.x)*L,B=h.y+(f._1.y-h.y)*L;return O(z=>{const Y=nt(z)/nt(10),R=1-Y;return{x:R*R*E+2*R*Y*h.x+Y*Y*v,y:R*R*B+2*R*Y*h.y+Y*Y*C}})(Kt(0,10))}return[]}),...o]},sC=t=>e=>n=>r=>o=>O(i=>{const s=nt(i)/nt(o),a=1-s,u=s*s*s,c=3*a*s*s,_=3*a*a*s,d=a*a*a;return{x:d*t.x+_*e.x+c*n.x+u*r.x,y:d*t.y+_*e.y+c*n.y+u*r.y}})(Kt(0,o-1|0)),aC=t=>[...Ge({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...Ge({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...sC({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),...Ge({x:t.x,y:t.y+t.h*.85})({x:t.x,y:t.y})(12)],nl=t=>e=>O(n=>{const r=6.283185307179586*nt(n)/nt(64);return{x:t.x+e*Ln(r),y:t.y+e*pn(r)}})(Kt(0,63)),rl=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]},uC=t=>{const e=t.y+t.h/2,n=Jn(t.h*.4)(t.w*.2);return[...Ge({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...Ge({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...Ge({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...Ge({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...Ge({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...Ge({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},rg=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:jd(O(n=>n.x)(t))/nt(e),y:jd(O(n=>n.y)(t))/nt(e)}},wa=t=>e=>n=>r=>o=>O(i=>{const s=n+(r-n)*(nt(i)/nt(o));return{x:t.x+e*Ln(s),y:t.y+e*pn(s)}})(Kt(0,o-1|0)),og=t=>e=>{const n=lr(t)(lr(e.w/2)(e.h/2));return[...Ge({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...wa({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...Ge({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...wa({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...Ge({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...wa({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...Ge({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...wa({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},Ja=t=>e=>n=>r=>o=>i=>O(s=>{const a=r+(o-r)*(nt(s)/nt(i));return{x:t.x+e*Ln(a),y:t.y+n*pn(a)}})(Kt(0,i-1|0)),cC=t=>{const e=t.h*.38;return[...St(bd(Cd(Td)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=co(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),o=co(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return Ja({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(o)(r>o?r:r+6.283185307179586)(16)}),...Ge({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...Ge({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...Ge({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},gC=t=>{const e=lr(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[...Ja({x:i,y:r})(n)(e)(3.141592653589793)(6.283185307179586)(24),...Ge({x:t.x+t.w,y:r})({x:t.x+t.w,y:o})(12),...Ja({x:i,y:o})(n)(e)(0)(3.141592653589793)(24),...Ge({x:t.x,y:o})({x:t.x,y:r})(12)]},vo=t=>e=>e.shape==="Cylinder"?gC(e):e.shape==="Parallelogram"?rC(e):e.shape==="Diamond"?uC(e):e.shape==="Ellipse"?og(Jn(e.w)(e.h)/2)(e):e.shape==="Document"?aC(e):e.shape==="Cloud"?cC(e):og(t)(e),_C=t=>{const e=lr(t.h*.075)(t.w*.075),n=t.w/2;return Ja({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},fC=t=>e=>n=>T(r=>o=>{const i=r.pos+o.len,s=n<i?(n-r.pos)/o.len:1,a={x:o.a.x+(o.b.x-o.a.x)*s,y:o.a.y+(o.b.y-o.a.y)*s},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,d=_>=0&&_<r.points.length?(()=>{const l=r.points[_].x-c.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const f=r.points[_].y-c.y;return f<0?-f<1e-4:f<1e-4})()})()?kt(r.points)(a):[...r.points,c,a]:[c,a];return o.len<=0||i<=e||r.pos>=n?{...r,pos:i}:{pos:i,points:d}})({pos:0,points:[]})(t).points,dC=t=>e=>n=>{const r=Ft(o=>J,o=>i=>N("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const o=oC(t),i=eC(o),s=Zd(0)(i)(e*i),a=Zd(0)(i)(n*i);return a<=s?[]:fC(o)(s)(a)}g()},lC=t=>e=>n=>r=>{const o=r.x-n.x,i=r.y-n.y,s=e.x-t.x,a=e.y-t.y,u=n.x-t.x,c=n.y-t.y,_=s*i-a*o,d=(u*i-c*o)/_,l=(u*a-c*s)/_;return(_<0?-_<1e-9:_<1e-9)?J:d>=0&&d<=1&&l>=0&&l<=1?N("Just",d):J},hC=t=>e=>n=>{const r=Pt(o=>i=>ot.compare(o.t)(i.t))(Tt(o=>{const i=lC(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}}):J})(Fe(An,t,[...Bt(1,t.length,t),...Bt(0,1,t)])));return 0<r.length?N("Just",r[0].p):J},ol=t=>e=>{const n=Cr(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=hC(t)(n._1.init[r])(n._1.last);if(o.tag==="Just")return kt(n._1.init)(o._1);if(o.tag==="Nothing")return e;g()}return e}g()},eo=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ig=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},pC=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},mC=t=>e=>{const n=eo(0)(t.y+4-e.y)+eo(0)(e.y+e.h-(t.y+t.h-4)),r=eo(0)(t.x+4-e.x)+eo(0)(e.x+e.w-(t.x+t.w-4));return r*e.h+n*e.w+r*n},yC=t=>e=>{const n=t.y+t.h-6,r=t.y+6,o=t.x+14,i=t.x+t.w-14,s=T(eo)(0)(O(a=>o-10<a.x+a.w+12&&i+10>a.x-12&&r-10<a.y+a.h+12&&n+10>a.y-12?ig((a.x+a.w+12-(o-10))/.7071067811865476)((n+10-(a.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+s*.7071067811865476,y:t.y-s*.7071067811865476}},xC=t=>e=>{const n=ig(t.x+t.w)(e.x+e.w)-eo(t.x)(e.x),r=ig(t.y+t.h)(e.y+e.h)-eo(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},il=t=>e=>n=>r=>{const o=t+4,i=eo(0)(e-8),s=o+i-n;return n<=i?pC(o)(s)(r):t+(e-n)/2},sg=t=>e=>({...e,x:il(t.x)(t.w)(e.w)(e.x),y:il(t.y)(t.h)(e.h)(e.y)}),wC=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}]},JC=t=>e=>n=>r=>o=>{const i=o.y+o.h/2-n.token.y,s=o.y-r.y;return(()=>{const a=o.x+o.w/2-n.token.x,u=o.x-r.x;return 1e6*mC(t)(o)+1e4*T(c=>_=>c+xC(o)(_))(0)(e)+.05*(u*u+s*s)+.01*(a*a+i*i)})()+(o.y>n.token.y?100:0)},NC=t=>e=>n=>r=>{const o=s=>{const a=sg(t)(s);return{rect:a,score:JC(t)(e)(n)(r)(a)}},i=Ft(s=>J,s=>a=>N("Just",{head:s,tail:a}),[r,n.rect,...wC(n)]);if(i.tag==="Nothing")return sg(t)(r);if(i.tag==="Just")return T(s=>a=>{const u=o(a);return u.score<s.score?u:s})(o(i._1.head))(i._1.tail).rect;g()},TC=t=>e=>n=>T(r=>o=>{const i=yC(o.rect)(r.obstacles),s=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:NC(t)(r.obstacles)(o)(i);return{acc:rt(P)(o.id)(s)(r.acc),obstacles:kt(r.obstacles)(s)}})({acc:I,obstacles:e})(n).acc,ag=t=>t,Ar=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Co=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},vC=Fo(du)(zt),CC=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bC=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},sl=ag("SegMove"),kC=ag("SegLine"),LC=ag("SegQuad"),al={offset:.4,passes:1,rMax:1.5},ul=t=>fe(In(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,Na=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},Ta=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},Ir=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},us=(()=>{const t=T(e=>n=>((e*31|0)+fe(In(n.x*100))|0)+fe(In(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),SC=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const o=n,i=r,s=o>=0&&o<t.length?N("Just",t[o]):J;if(s.tag==="Nothing"){n=t.length;continue}if(s.tag==="Just"){if(s._1===1){const a={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:sl,m:i,c:i,p:a,len:0}),r=a,n=o+3|0;continue}if(s._1===2){const a={x:(()=>{const _=o+1|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+2|0;return _>=0&&_<t.length?t[_]:0})()},u=a.x-i.x,c=a.y-i.y;e.push({kind:kC,m:i,c:i,p:a,len:Ve(u*u+c*c)}),r=a,n=o+3|0;continue}if(s._1===3){const a={x:(()=>{const _=o+3|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+4|0;return _>=0&&_<t.length?t[_]:0})()},u=a.x-i.x,c=a.y-i.y;e.push({kind:LC,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:a,len:Ve(u*u+c*c)*1.05}),r=a,n=o+5|0;continue}if(s._1===5){e.push({kind:sl,m:i,c:i,p:i,len:0}),n=o+1|0;continue}n=t.length;continue}g()}return e},EC=t=>e=>{const n=e.length-1|0,r=n<1?[]:Bt(0,n,e),o=(()=>{const s=r.length-1|0;return s>=0&&s<r.length?N("Just",r[s]):J})(),i=e.length-1|0;if(i>=0&&i<e.length&&o.tag==="Just"){const s=e[i].y-o._1.y,a=e[i].x-o._1.x,u=Ve(a*a+s*s);return u<=1e-4?e:kt((()=>{const c=e.length-1|0;return c<1?[]:Bt(0,c,e)})())({x:e[i].x+a/u*t,y:e[i].y+s/u*t})}return e},GC=t=>e=>n=>se(T(r=>o=>{const i=Ee(0)(t)(r.prng),s=Ee(0)(6.283185307179586)(i.prng);return{prng:s.prng,out:[{x:o.x+i.value*Ln(s.value),y:o.y+i.value*pn(s.value)},...r.out]}})({prng:e,out:[]})(n).out),PC=t=>e=>n=>{if(e.kind==="SegMove")return Ta(t)(e.p);if(e.kind==="SegLine")return Ir(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 Ir(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});g()},BC=t=>e=>{if(e.kind==="SegMove")return Ta(t)(e.p);if(e.kind==="SegLine")return Ir(t)(e.p);if(e.kind==="SegQuad")return Na(t)(e.c)(e.p);g()},cl=t=>e=>{const n=SC(e),r=T(a=>u=>a+u.len)(0)(n)*Ar(0)(Co(1)(t)),o=[];let i=0,s=0;for(;s<n.length;){const a=s,u=i;if(a>=0&&a<n.length){if(u+n[a].len<=r){const c=n[a];BC(o)(c)(),i=u+c.len,s=a+1|0;continue}if(u>=r){s=n.length;continue}PC(o)(n[a])((r-u)/Ar(n[a].len)(1e-4))()}s=n.length}return o},gl={offset:1.5,passes:2,rMax:14,overshoot:2.5},_l=t=>e=>n=>r=>{const o=r.y-n.y,i=n.y-e.y,s=r.x-n.x,a=Ve(s*s+o*o),u=n.x-e.x,c=Ve(u*u+i*i),_=Co(t.rMax*(q0(c>0&&a>0?Ar(-1)(Co(1)((u*s+i*o)/(c*a))):1)/3.141592653589793))(.4*Co(c)(a));return{inP:c>0?{x:n.x-u/c*_,y:n.y-i/c*_}:n,curr:n,outP:a>0?{x:n.x+s/a*_,y:n.y+o/a*_}:n}},fl=t=>e=>{const n=e.length,r=[],o=0<e.length?N("Just",e[0]):J;if(o.tag==="Just"?Ta(r)(o._1)():o.tag==="Nothing"||g(),n>=3){let s=1;for(;s<=(n-2|0);){const a=s,u=a+1|0;if(u>=0&&u<e.length){if(a>=0&&a<e.length){const c=a-1|0;if(c>=0&&c<e.length){const _=_l(t)(e[c])(e[a])(e[u]);Ir(r)(_.inP)(),Na(r)(_.curr)(_.outP)()}}s=a+1|0;continue}s=a+1|0}}const i=e.length-1|0;return i>=0&&i<e.length&&n>=2&&Ir(r)(e[i])(),r},DC=t=>e=>n=>r=>o=>{if(o.length<4)return fl(t)(o);const i=0<o.length?N("Just",o[0]):J,s=(()=>{if(i.tag==="Nothing")return{x:0,y:0};if(i.tag==="Just")return i._1;g()})(),a=o.length-1|0,u=Hr(Hr(e)(a)+a|0)(a),c=f=>{const h=Hr(f+a|0)(a);return h>=0&&h<o.length?o[h]:s},_=O(f=>_l(t)(c((u+f|0)-1|0))(c(u+f|0))(c((u+f|0)+1|0)))(Kt(0,a-1|0)),d=[],l=0<_.length?N("Just",_[0]):J;if(l.tag==="Just")if(Ta(d)(l._1.outP)(),vC((()=>{const f=Ft(h=>J,h=>p=>N("Just",p),_);if(f.tag==="Nothing")return[];if(f.tag==="Just")return f._1;g()})())(f=>{const h=Ir(d)(f.inP);return()=>(h(),Na(d)(f.curr)(f.outP)())})(),n)Ir(d)(l._1.inP)(),Na(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const f=_.length-1|0;f>=0&&f<_.length?Ir(d)((()=>{const h=1-r;return{x:_[f].outP.x+(l._1.inP.x-_[f].outP.x)*h,y:_[f].outP.y+(l._1.inP.y-_[f].outP.y)*h}})())():Ir(d)(l._1.inP)()}else l.tag==="Nothing"||g();return d},yi=t=>e=>n=>r=>{const o=CC(1)(r.length-1|0),i=Ee(0)(nt(o))(Wc("shape")(e)),s=bC(o-1|0)(fe(In(i.value))),a=i.prng;return O(u=>{const c=Ee(0)(1)(Wc(ie(u))(a)),_=Ee(-.18)(.3)(c.prng),d=c.value<.7,l=Ee(.5)(.85)(_.prng),f=GC(t.offset)(l.prng)(r);return{path:n?DC(t)(s)(d)(_.value)(f):fl(t)(f),alpha:l.value}})(Kt(0,t.passes-1|0))},RC=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}]),AC=t=>e=>n=>{const r=Ar(0)(Co(1)(n)),o=e.h/nt(4),i=Ar(6)(o*1.4);return Tt(s=>s)(O(s=>{if(r<Ar(0)(nt(s)/nt(4)-.05))return J;const a=Wc(ie(s))(t),u=Ar(0)(nt(s)/nt(4)-.05),c=Hr(s)(2)===0,_=c?e.x-2:e.x+e.w+2,d=c?e.x+e.w+2:e.x-2,l=e.y+(nt(s)+.5)*o;return N("Just",{path:cl(Ar(0)(Co(1)((r-u)/Ar(1e-4)(Co(1)(nt(s+1|0)/nt(4)+.05)-u))))((()=>{const f={rMax:2,offset:.6,passes:1},h=se(T(m=>w=>{const y=Ee(-o*.08)(o*.08)(m.prng);return{prng:y.prng,out:[{x:_+(d-_)*(nt(w)/nt(4)),y:l+y.value},...m.out]}})({prng:a,out:[]})(Kt(0,4)).out),p=h.length<2?[]:yi(f)(a)(!1)(h);return 0<p.length?p[0].path:[]})()),width:i,alpha:1})})(Kt(0,3)))},ug=(t,e,n)=>({tag:t,_1:e,_2:n}),va=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Pe=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Ze=(()=>{const t=nn.unfoldr(Qn);return e=>t(rn("IterNode",e,Fn))})(),hr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bo=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Fr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},IC=zt.foldMap(om),Ca=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},dl=ce(P)(zt),ll=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},FC=N_(P),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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},ko=t=>{const e=t.Apply0();return n=>T(r=>o=>e.apply(e.Functor0().map(i=>i_)(r))(n(o)))(t.pure())},Qr=ko(Jo),hl=t=>e=>n=>r=>o=>i=>{const s={x:n.x+n.w/2,y:n.y+n.h/2},a={x:e.x+e.w/2,y:e.y+e.h/2},u=hi(o)(i)(r),c=0<t.length?N("Just",t[0]):J,_=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return a;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?N("Just",t[d]):J,f=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return s;g()})(),h=Dd(128)(vo(4)(as(2)(e)))(nl(_)(6)),p=_.x-a.x,m=2*(()=>{const j=_.y-a.y;return(p<0?-p:p)+(j<0?-j:j)})(),w=f.x-s.x,y=2*(()=>{const j=f.y-s.y;return(w<0?-w:w)+(j<0?-j:j)})(),x=m+Bi(t)+y,v=x<=1e-4?1:1-y/x,C=x<=1e-4?0:m/x,L=v-C,E=Dd(128)(nl(f)(6))(vo(4)(as(2)(n))),B={maxDelay:.4,smoothPasses:2},z=lo(t)(va(0)(1)(L<=1e-4?0:(u-C)/L)),Y=(()=>{if(z.tag==="Just")return z._1;if(z.tag==="Nothing")return _;g()})(),R=(()=>{if(v>=1)return 0;const j=(u-v)/(1-v),Z=j<0?0:j>1?1:j;return Z*Z*(3-2*Z)})(),A=(()=>{if(C<=1e-4)return 1;const j=u/C,Z=j<0?0:j>1?1:j;return Z*Z*(3-2*Z)})();return u<C?To("PolyShape",Ad(A)(h.from)(h.to)(B)):u>=v?To("PolyShape",Ad(R)(E.from)(E.to)(B)):To("CircleShape",Y,6)},cg=t=>e=>n=>r=>o=>i=>{const s=hl(t)(e)(n)(r)(o)(i);if(s.tag==="PolyShape")return rg(s._1);if(s.tag==="CircleShape")return s._1;g()},gg=(()=>{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},s={r:42,g:48,b:60,a:255},a={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:Rr,nodeFill:ye,nodeStroke:Rr,text:Rr,edge:Rr,arrowFill:Rr,tokenOutsideFill:Rr,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:ha,tokenInsideAlpha:1,chipPillFill:Rr,chipPillText:ye,chipHairline:{r:26,g:26,b:26,a:90},trailDot:Rr,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:Rr,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:ye,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:ha,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:ye,chip:ye,chipShadow:{r:0,g:0,b:0,a:120},chipText:o,nodeFill:o,nodeStroke:ye,text:ye,edge:ye,arrowFill:ye,tokenOutsideFill:ye,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:pd,tokenInsideAlpha:.35,chipPillFill:ye,chipPillText:o,chipHairline:{r:255,g:255,b:255,a:120},trailDot:ye,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:pd,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:s,chip:{r:255,g:235,b:130,a:255},chipShadow:{r:100,g:110,b:125,a:90},chipText:s,nodeFill:{r:236,g:239,b:244,a:255},nodeStroke:s,text:s,edge:a,arrowFill:a,tokenOutsideFill:s,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:ha,tokenInsideAlpha:1,chipPillFill:s,chipPillText:ye,chipHairline:{r:60,g:66,b:78,a:90},trailDot:s,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};g()}})(),_g=t=>e=>St(Ze(t.nodes))(n=>{const r=Pe(n._1)(e.nodes);return r.tag==="Just"&&pi(r._1).alpha>0?eg(n._2):[]}),MC=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,..._g(e)(n)],zC=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=uo.traverse(r);return i=>s=>{const a=br(s),u=.32*i.size;return o(c=>n.bind(c===0?r.pure(0):t.measureText(i)(Re(c)(s)))(_=>n.bind(t.measureText(i)(Re(c+1|0)(s)))(d=>n.bind(t.measureInk(i)(c>=0&&c<a.length?Gi(a[c]):" "))(l=>r.pure({x:_,w:d-_,up:l.ascent-u,down:l.descent+u})))))(Kt(0,a.length-1|0))}},WC=t=>e=>{const n=o=>(o.x-e.x)*(o.x-e.x)+(o.y-e.y)*(o.y-e.y),r=T(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 O(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])},fg=t=>{const e=Sr(`
|
|
7
|
+
`)(t);return e.length===0?[""]:e},qC=t=>e=>n=>r=>o=>i=>{const s={x:n.x+n.w/2,y:n.y+n.h/2},a={x:e.x+e.w/2,y:e.y+e.h/2},u=hi(o)(i)(r),c=0<t.length?N("Just",t[0]):J,_=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return a;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?N("Just",t[d]):J,f=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return s;g()})(),h=_.x-a.x,p=2*(()=>{const B=_.y-a.y;return(h<0?-h:h)+(B<0?-B:B)})(),m=f.x-s.x,w=2*(()=>{const B=f.y-s.y;return(m<0?-m:m)+(B<0?-B:B)})(),y=p+Bi(t)+w,x=y<=1e-4?1:1-w/y,v=y<=1e-4?0:p/y,C=x-v,L=lo(t)(va(0)(1)(C<=1e-4?0:(u-v)/C)),E=(()=>{if(L.tag==="Just")return L._1;if(L.tag==="Nothing")return _;g()})();return u<v?ug("InsideRect",as(2)(e)):u>=x?ug("InsideRect",as(2)(n)):ug("InsideBall",E,6)},dg=t=>e=>n=>r=>o=>i=>s=>{const a=(u,c)=>Kd({id:u,pass:t,geometry:Md("FlatToken",c),position:(()=>{if(c.tag==="CircleShape")return c._1;if(c.tag==="PolyShape")return rg(c._1);g()})(),plan:Wd("FlatTokenPlan",{wobble:n,fill:i,stroke:s})});return Qr(u=>{if(u._2.tag==="Travelling"){const c=Pe(u._2._1.target)(r.nodes),_=Pe(u._2._1.source)(r.nodes);if(_.tag==="Just"&&c.tag==="Just"){const d=Fr(u._2._1.edge)(r.edges);if(d.tag==="Just"){const l=(()=>{if(u._2._1.direction==="Forward")return d._1;if(u._2._1.direction==="Backward")return se(d._1);g()})();return a(u._1,(()=>{if(e){const f=qC(l)(_._1)(c._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost);if(f.tag==="InsideRect")return To("PolyShape",og(4)(f._1));if(f.tag==="InsideBall")return To("CircleShape",f._1,f._2);g()}return hl(l)(_._1)(c._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost)})())}if(d.tag==="Nothing"){const l=hi(u._2._1.holdPre)(u._2._1.holdPost)(u._2._1.progress),f={x:_._1.x+_._1.w/2,y:_._1.y+_._1.h/2},h={x:c._1.x+c._1.w/2,y:c._1.y+c._1.h/2};return je({path:[],role:dn,layer:J,effects:[be("GroupAlpha",(()=>{if(l<.5){const m=l*2;return 1-hr(0)(bo(1)(m))*hr(0)(bo(1)(m))*(3-2*hr(0)(bo(1)(m)))}const p=(l-.5)*2;return hr(0)(bo(1)(p))*hr(0)(bo(1)(p))*(3-2*hr(0)(bo(1)(p)))})())]})(a(u._1,To("CircleShape",l<.5?f:h,6)))}g()}return tt(ut("Return",void 0),_t)}if(u._2.tag==="Filling"){if(n)return tt(ut("Return",void 0),_t);const c=Pe(u._2._1.node)(r.nodes);if(c.tag==="Just")return a(u._1,To("PolyShape",vo(4)(as(2)(c._1))));if(c.tag==="Nothing")return tt(ut("Return",void 0),_t);g()}return tt(ut("Return",void 0),_t)})(Ze(o.tokens))},OC=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()}))},pl=t=>e=>n=>r=>je({path:[],role:dn,layer:J,effects:[be("GroupAlpha",n.fadeAlpha),be("GroupTransform",mi,{tx:t.x*(1-n.popScale),ty:(t.y+t.h)*(1-n.popScale),sx:n.popScale,sy:n.popScale}),be("GroupTransform",mi,{tx:0,ty:e.y*(1-n.flipY),sx:1,sy:n.flipY})]})(ss(r)),ml=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>{const _=pi(c),d=c.tag==="PloppingOut"&&r.wobble?{alpha:1,scale:1}:_,l=Sr(`
|
|
8
|
+
`)(u.label===""?a:u.label),f=l.length===0?[""]:l,h={family:r.fontFamily,size:r.wobble?15:11,weight:r.wobble?800:500},p=h.size*1.2,m={tx:(u.x+u.w/2)*(1-d.scale),ty:(u.y+u.h/2)*(1-d.scale),sx:d.scale,sy:d.scale},w=(u.shape==="Cylinder"?(u.y+(u.y+u.h+5-2*Jn(u.h*.075)(u.w*.075)))/2:(u.y+u.y+u.h)/2)-nt(f.length)*p/2+p/2,y=tg({id:a,role:t,geometry:Xc("FlatNode",{shape:u.shape,bounds:{x:u.x,y:u.y,w:u.w,h:u.h}}),alpha:o,plan:Yc("FlatNodePlan",{palette:r,label:u.label,labelVisibility:e,inkBoost:n,labelAlpha:i,arrival:s,animState:c})}),x=()=>{if(e==="LabelsHidden")return tt(ut("Return",void 0),_t);if(e==="LabelsShown"){const v=je({path:[],role:dn,layer:J,effects:[be("GroupAlpha",d.alpha*o),be("GroupTransform",mi,m),be("GroupAlpha",i)]})(Qr(C=>ss({owner:No("NodeText",a),text:C._2,spec:{x:u.x+u.w/2,y:w+nt(C._1)*p,content:C._2,font:h,color:r.text,align:Dr,baseline:En},bounds:J,plan:ya}))(Ht(An)(f)));return i>0&&d.alpha*o>0?v:tt(ut("Return",void 0),_t)}g()};return tt(y._1,(()=>{if(y._2.tag==="CatNil")return at("CatCons",x,st($,$));if(y._2.tag==="CatCons")return at("CatCons",y._2._1,st(y._2._2._1,Lt("Cons",at("CatCons",x,st($,$)),y._2._2._2)));g()})())},HC=t=>e=>n=>r=>o=>i=>s=>pl(o)(i)(s)({owner:No("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:Dr,baseline:En},bounds:N("Just",o),plan:is("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:Ue,lineCap:Gn},leader:[1,i.x,o.y+o.h,2,r.x+r.w/2,r.y]})}),$C={offset:.8,passes:2,rMax:5},lg=t=>e=>n=>r=>je({path:[],role:dn,layer:N("Just",ZT),effects:[be("GroupClip",MC(e)(n)(r),rv)]})(dg(Od)(!1)(t.wobble)(n)(r)(t.tokenOutsideFill)(t.tokenOutsideStroke)),yl=t=>e=>n=>r=>{if(e.tokenInsideBlend==="Difference"){const o=Zv(t),i=s=>{const a=je({path:[],role:dn,layer:N("Just",tv),effects:[be("GroupBlend",ha),be("GroupClip",_g(n)(r),ns)]})(dg(Hd)(s==="ConvexAbsorb")(e.wobble)(n)(r)(e.tokenInside)(e.tokenInsideStroke)),u=()=>je({path:[],role:dn,layer:N("Just",ev),effects:[]})(Qr(c=>{const _=Pe(c._1)(r.nodes);return _.tag==="Just"&&pi(_._1).alpha>0?xa(ma("FloorOverlay",{path:eg(c._2),fill:N("Just",{color:ye,flat:!1}),stroke:J})):tt(ut("Return",void 0),_t)})(Ze(n.nodes)));return tt(a._1,(()=>{if(a._2.tag==="CatNil")return at("CatCons",u,st($,$));if(a._2.tag==="CatCons")return at("CatCons",a._2._1,st(a._2._2._1,Lt("Cons",at("CatCons",u,st($,$)),a._2._2._2)));g()})())};return tt(o._1,(()=>{if(o._2.tag==="CatNil")return at("CatCons",i,st($,$));if(o._2.tag==="CatCons")return at("CatCons",o._2._1,st(o._2._2._1,Lt("Cons",at("CatCons",i,st($,$)),o._2._2._2)));g()})())}if(e.tokenInsideBlend==="Normal")return je({path:[],role:dn,layer:J,effects:[be("GroupClip",_g(n)(r),ns),be("GroupAlpha",e.tokenInsideAlpha)]})(dg(Hd)(!1)(e.wobble)(n)(r)(e.tokenInside)(e.tokenInsideStroke));g()},xl=t=>e=>n=>r=>t.strokePath((()=>{const o=Ft(i=>J,i=>s=>N("Just",{head:i,tail:s}),O(i=>i.pt)(I0(i=>s=>{const a=nt(s)/nt(72),u=Ee(-.18)(.18)(i.prng),c=Ee(-.1)(.1)(u.prng),_=Ee(-.07)(.07)(c.prng),d=n*(.05+.55*a)*(1+c.value),l=a*28.274333882308138+u.value;return{prng:_.prng,pt:{x:e.x+Ln(l)*d+_.value*n,y:e.y+pn(l)*d+_.value*n}}},{prng:137,pt:{x:e.x,y:e.y}},Kt(0,72))));if(o.tag==="Just")return[1,o._1.head.x,o._1.head.y,...IC(i=>[2,i.x,i.y])(o._1.tail)];if(o.tag==="Nothing")return[];g()})())({color:r,width:5.5,lineJoin:Ue,lineCap:Un}),VC=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?xl(t)(n.geometry._1._1)(n.geometry._1._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(rl(n.geometry._1._1)(n.geometry._1._2))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:Ue,lineCap:Gn});if(n.geometry._1.tag==="PolyShape")return n.plan._1.wobble&&n.geometry._1._1.length>=3?xl(t)(rg(n.geometry._1._1))(6)({r:200,g:35,b:30,a:220}):n.geometry._1._1.length>=3?t.fillStrokePath(tl(n.geometry._1._1))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:Ue,lineCap:Gn}):e.pure();g()}return e.pure()}},UC=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popClip,i=t.popTransform,s=t.popAlpha;return a=>u=>c=>_=>{const d=pi(_),l={...c,y:c.y+5},f=l.x+l.w/2,h=l.y+l.h/2,p=r.bind(t.pushAlpha(d.alpha))(()=>r.bind(t.pushTransform({tx:f*(1-d.scale),ty:h*(1-d.scale),sx:d.scale,sy:d.scale}))(()=>r.bind(t.drawRoundedRect({x:l.x,y:l.y,w:l.w,h:l.h})(7)(N("Just",{color:a.shadowFill,flat:!0}))(J))(()=>r.bind((()=>{const m=r.bind(t.pushClip(el(l)(7))(ns))(()=>r.bind(t.backgroundDots({viewport:{vx:l.x,vy:l.y,vw:l.w,vh:l.h},bgColor:a.bgTransparent,dotColor:a.shadowDot,tile:1.6,dotRadius:.25,origin:{x:0,y:0}}))(()=>o));return u&&!a.wobble?m:n.pure()})())(()=>r.bind(t.drawRoundedRect({x:l.x,y:l.y,w:l.w,h:l.h})(7)(J)(N("Just",{color:a.nodeStroke,width:1.25,lineJoin:Ue,lineCap:Gn})))(()=>r.bind(i)(()=>s))))));return d.alpha>0&&!a.wobble?p:n.pure()}},wl=t=>e=>n=>r=>Qr(o=>{const i=Pe(o._1)(r.nodes);if(i.tag==="Just")return tg({id:o._1,role:Yv,geometry:Xc("FlatNode",{shape:o._2.shape,bounds:{x:o._2.x,y:o._2.y,w:o._2.w,h:o._2.h}}),alpha:1,plan:Yc("FlatNodePlan",{palette:t,label:o._2.label,labelVisibility:Zc,inkBoost:e?1:0,labelAlpha:0,arrival:J,animState:i._1})});if(i.tag==="Nothing")return tt(ut("Return",void 0),_t);g()})(Ze(n.nodes)),Jl=t=>e=>n=>{const r={...t,nodeFill:t.text,text:t.nodeFill,nodeStroke:t.nodeFill};return Qr(o=>{const i=Pe(o._1)(n.nodes),s=Pe(o._1)(e.nodes),a=s.tag==="Just"&&i.tag==="Just"?je({path:[],role:dn,layer:J,effects:[be("GroupAlpha",o._2)]})(ml(Kv)(jc)(1)(r)(1)(1)(J)(o._1)(s._1)(i._1)):tt(ut("Return",void 0),_t);return o._2>0?a:tt(ut("Return",void 0),_t)})(Ze(n.nodeInvert))},XC=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=ko(e.Applicative0());return i=>s=>a=>o(u=>n.bind(t.pushAlpha(u.alpha))(()=>n.bind(t.strokePath(u.path)({color:i.nodeFill,width:u.width,lineJoin:Ue,lineCap:Un}))(()=>r)))(AC(ul(s)+7777|0)(s)(a))},YC=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=e.Applicative0(),i=ko(o),s=t.popClip,a=ko(o),u=uo.traverse(o),c=zC(t),_=XC(t),d=t.popTransform;return l=>f=>h=>p=>m=>w=>y=>x=>v=>{const C=F=>n.bind(t.pushAlpha(F.alpha))(()=>n.bind(t.strokePath(F.path)({color:h.nodeStroke,width:2,lineJoin:Ue,lineCap:Un}))(()=>r)),L={family:h.fontFamily,size:h.wobble?15:11,weight:h.wobble?800:500},E=Sr(`
|
|
9
|
+
`)(x.label===""?y:x.label),B=E.length===0?[""]:E,z=L.size*1.2,Y=x.shape==="Cylinder"?t.strokePath(lv({x:x.x,y:x.y,w:x.w,h:x.h}))({color:h.nodeStroke,width:1.25,lineJoin:Ue,lineCap:Gn}):o.pure(),R=(x.shape==="Cylinder"?(x.y+(x.y+x.h+5-2*Jn(x.h*.075)(x.w*.075)))/2:(x.y+x.y+x.h)/2)-nt(B.length)*z/2+z/2,A=v.tag==="PloppingOut"&&h.wobble?v._1:-1,j=A>=0,Z=pi(v),M=j?{alpha:1,scale:1}:Z,W=x.x+x.w/2,H=x.y+x.h/2,D=n.bind(t.pushAlpha(M.alpha*p))(()=>n.bind(t.pushTransform({tx:W*(1-M.scale),ty:H*(1-M.scale),sx:M.scale,sy:M.scale}))(()=>{const F={x:x.x,y:x.y,w:x.w,h:x.h},S={color:h.nodeStroke,width:h.wobble?2:1.25*f,lineJoin:Ue,lineCap:h.wobble?Un:Gn};return n.bind((()=>{if(h.wobble){if(x.shape==="Rectangle")return i(C)(RC(gl)(ul(F))(F));const G=vo(7)(x);return n.bind(i(C)((()=>{const Q=us(G);return G.length<4?[]:yi(al)(Q)(!0)(G)})()))(()=>a(Q=>i(C)((()=>{const V=us(Q);return Q.length<2?[]:yi(al)(V)(!1)(Q)})()))(x.shape==="Cylinder"?[_C(x)]:[]))}return n.bind(pv(t)(x.shape)(F)(7)(N("Just",{color:h.nodeFill,flat:!1}))(N("Just",S)))(()=>Y)})())(()=>n.bind((()=>{if(w.tag==="Just"&&h.wobble&&!j){const G=w._1;return n.bind(u(c(L))(B))(Q=>{const V=Pt(dt=>ht=>ot.compare(dt.x)(ht.x)),X=fe(In(x.x*7919+x.y*3001))*-1640531535|0,U=Ee(5)(7.5)(X),q=Ee(0)(U.value)(U.prng),K=-(1+2*Ee(-1)(1)(q.prng).value*3.141592653589793/180),et=(dt,ht,Et,Dt,Mt)=>V(Tt(ne=>ne)([K*ht+dt>=Dt&&K*ht+dt<=Mt?N("Just",{x:ht,y:K*ht+dt}):J,K*Et+dt>=Dt&&K*Et+dt<=Mt?N("Just",{x:Et,y:K*Et+dt}):J,(()=>{const ne=(Dt-dt)/K;return ne>=ht&&ne<=Et?N("Just",{x:ne,y:Dt}):J})(),(()=>{const ne=(Mt-dt)/K;return ne>=ht&&ne<=Et?N("Just",{x:ne,y:Mt}):J})()])),lt=U.value,bt=Hr(G.frameHash)(3),pt=bt===0?{r:200,g:35,b:30,a:220}:bt===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},vt=x.x+x.w/2,Gt=hn(Ht(dt=>ht=>Ht((()=>{const Et=R+nt(dt)*z,Dt=vt-T(Mt=>ne=>Mt+ne.w)(0)(ht)/2;return Mt=>ne=>{const Cn=L.size*.1,qe=Mt-1|0,Ot=qe>=0&&qe<ht.length&&Mt>0?(ht[qe].x+ht[qe].w+ne.x)/2:ne.x-Cn;return{x:Dt+Ot-1,y:Et-ne.up-1,w:hr(0)((()=>{const qt=Mt+1|0;return qt>=0&&qt<ht.length&&Mt<(ht.length-1|0)?(ne.x+ne.w+ht[qt].x)/2-Ot:ne.x+ne.w+Cn-Ot})())+2,h:ne.up+ne.down+2}}})())(ht))(Q)),jt=x.y+4,Ct=x.x+x.w-4,Yt=x.x+4,Rt=jt-K*Yt+q.value,wt=x.y+x.h-4,mt=St(St(Ht(dt=>ht=>{const Et=(ht.from.x+ht.to.x)/2,Dt=(ht.from.y+ht.to.y)/2,Mt=Ee(-1)(1)(X+(911*(dt+1|0)|0)|0),ne=Ee(-3)(5)(Mt.prng),Cn=Mt.value*3.141592653589793/180,qe=Ln(Cn),Ot=pn(Cn),qt=Oe=>({x:Et+(Oe.x-Et)*qe-(Oe.y-Dt)*Ot,y:Dt+(Oe.x-Et)*Ot+(Oe.y-Dt)*qe});return{from:(()=>{const Oe=qt(ht.from),bn=Oe.y-Dt,tn=Oe.x-Et,_n=Ve(tn*tn+bn*bn),Ae=_n<1e-4?1:(_n+ne.value)/_n;return{x:Et+tn*Ae,y:Dt+bn*Ae}})(),to:(()=>{const Oe=qt(ht.to),bn=Ee(-3)(5)(ne.prng).value,tn=Oe.y-Dt,_n=Oe.x-Et,Ae=Ve(_n*_n+tn*tn),oe=Ae<1e-4?1:(Ae+bn)/Ae;return{x:Et+_n*oe,y:Dt+tn*oe}})()}})(Tt(dt=>{const ht=et(Rt+nt(dt)*lt,Yt,Ct,jt,wt);return ht.length===2?N("Just",{from:ht[0],to:ht[1]}):J})(Kt(0,Ca(1)(fe(In((wt-K*Ct-Rt)/lt)))))))(dt=>ft(ht=>ht.to.x-ht.from.x>1,T(ht=>Et=>St(ht)(Dt=>{const Mt=et(Dt.from.y-K*Dt.from.x,Et.x,Et.x+Et.w,Et.y,Et.y+Et.h);return Mt.length===2?Mt[0].x>Dt.from.x+.001&&Mt[1].x<Dt.to.x-.001?[{from:Dt.from,to:Mt[0]},{from:Mt[1],to:Dt.to}]:Mt[0].x<=Dt.from.x+.001&&Mt[1].x<Dt.to.x-.001?[{from:Mt[1],to:Dt.to}]:Mt[0].x>Dt.from.x+.001&&Mt[1].x>=Dt.to.x-.001?[{from:Dt.from,to:Mt[0]}]:[]:[Dt]}))([dt])(Gt))))(dt=>(()=>{const ht=dt.to.x-dt.from.x;return Ve(2)*(ht>=0?ht:-ht)<=28})()?[dt]:[{from:dt.from,to:{x:dt.from.x+(dt.to.x-dt.from.x)*.495,y:dt.from.y+(dt.to.y-dt.from.y)*.495}},{from:{x:dt.from.x+(dt.to.x-dt.from.x)*.505,y:dt.from.y+(dt.to.y-dt.from.y)*.505},to:dt.to}]),ct=mt.length,yt=dt=>hr(0)(bo(1)(G.t*nt(ct)-nt(dt)));return n.bind(t.pushClip(tl(vo(7)(x)))(ns))(()=>n.bind(i(dt=>{const ht=dt._1,Et=Ee(1.4)(1.9)(X+(1303*(ht+1|0)|0)|0),Dt=Ee(.35)(.8)(Et.prng),Mt=i(ne=>n.bind(t.pushAlpha(ne.alpha*Dt.value))(()=>n.bind(t.strokePath(cl(yt(ht))(ne.path))({color:pt,width:Et.value,lineJoin:Ue,lineCap:Un}))(()=>r)))(yi({...gl,rMax:0,offset:.5})(X+(53*(ht+1|0)|0)|0)(!1)([dt._2.from,dt._2.to]));return yt(ht)>0?Mt:o.pure()})(Ht(An)(mt)))(()=>s))})}return o.pure()})())(()=>n.bind((()=>{if(l==="LabelsShown"){const G=n.bind(t.pushAlpha(m))(()=>n.bind(i(Q=>t.drawText({x:x.x+x.w/2,y:R+nt(Q._1)*z,content:Q._2,font:L,color:h.text,align:Dr,baseline:En}))(Ht(An)(B)))(()=>r));return m>0?G:o.pure()}if(l==="LabelsHidden")return o.pure();g()})())(()=>n.bind((()=>{const G=_(h)(F)(A);return j?G:o.pure()})())(()=>n.bind(d)(()=>r)))))}));return M.alpha*p>0?D:o.pure()}},KC=t=>{const e=UC(t),n=YC(t);return r=>{if(r.geometry.tag==="FlatNode"&&r.plan.tag==="FlatNodePlan"){const o={x:r.geometry._1.bounds.x,y:r.geometry._1.bounds.y,w:r.geometry._1.bounds.w,h:r.geometry._1.bounds.h,label:r.plan._1.label,shape:r.geometry._1.shape};if(r.role==="NodeShadow")return e(r.plan._1.palette)(r.plan._1.inkBoost>0)(o)(r.plan._1.animState);if(r.role==="NodeBody"||r.role==="NodeInversion")return n(Zc)(r.plan._1.inkBoost)(r.plan._1.palette)(r.alpha)(0)(r.plan._1.arrival)(r.id)(o)(r.plan._1.animState);g()}return t.Monad0().Applicative0().pure()}},Nl=t=>e=>n=>{const r=o=>{const i=re(s=>o.x>=s._2.x-1&&o.x<=s._2.x+s._2.w+1&&o.y>=s._2.y-1&&o.y<=s._2.y+s._2.h+1)(Ze(e.nodes));return i.tag==="Just"?N("Just",i._1._2):J};return Qr(o=>{const i=Fr(o._1)(n.edges);if(i.tag==="Just"){const s=Fr(o._1)(n.edgeFadeAlpha),a=(()=>{if(s.tag==="Nothing")return 1;if(s.tag==="Just")return s._1;g()})(),u=Yd({id:o._1,geometry:Id("FlatRoute",(()=>{const c=(()=>{if(0<o._2.length){const d=r(o._2[0]);if(d.tag==="Just")return se(ol(vo(7)(d._1))(se(o._2)))}return o._2})(),_=c.length-1|0;if(_>=0&&_<c.length){const d=r(c[_]);if(d.tag==="Just")return ol(vo(7)(d._1))(c)}return c})()),visible:Fv(i._1),arrow:(()=>{const c=go("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:Fd("FlatEdgePlan",t)});return a===1?u:je({path:[],role:dn,layer:J,effects:[be("GroupAlpha",a)]})(u)}if(i.tag==="Nothing")return tt(ut("Return",void 0),_t);g()})(Ze(e.edges))},jC=t=>e=>n=>{const r={family:t.fontFamily,size:11,weight:500};return Qr(o=>{if(o._2===""||(()=>{const a=Fr(o._1)(n.edges);return a.tag==="Nothing"||!(a.tag==="Just"&&hy.eq(a._1)(wf))})())return tt(ut("Return",void 0),_t);const i=Fr(o._1)(e.edges),s=(()=>{if(i.tag==="Just")return lo(i._1)(.5);if(i.tag==="Nothing")return J;g()})();if(s.tag==="Nothing")return tt(ut("Return",void 0),_t);if(s.tag==="Just"){const a=s._1,u=ts(r)(o._2),c=_=>{const d=_+12;return ss({owner:No("EdgeText",o._1),text:o._2,spec:{x:a.x,y:a.y,content:o._2,font:r,color:t.chipPillText,align:Dr,baseline:En},bounds:N("Just",{x:a.x-d/2,y:a.y-8.5,w:d,h:17}),plan:is("RoundedText",{radius:3,fill:N("Just",{color:t.chipPillFill,flat:!0}),stroke:J})})};return tt(u._1,(()=>{if(u._2.tag==="CatNil")return at("CatCons",c,st($,$));if(u._2.tag==="CatCons")return at("CatCons",u._2._1,st(u._2._2._1,Lt("Cons",at("CatCons",c,st($,$)),u._2._2._2)));g()})())}g()})(Ze(e.edgeLabels))},Tl=t=>{const e=n=>{if(n.tag==="Leaf")return I;if(n.tag==="Node")return te("Node",n._1,n._2,n._3,sg({x:t.vx,y:t.vy,w:t.vw,h:t.vh})(n._4),e(n._5),e(n._6));g()};return e},ZC=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=ko(r);return i=>s=>a=>u=>c=>_=>{const d=Ko(_).length,l=nt(d+1|0),f=m=>{const w=(a*l-nt(m))/1.5,y=w<0?0:w>1?1:w;return y*y*(3-2*y)},h=(m=>{let w=m,y=!0,x;for(;y;){const v=w;if(v>=d){y=!1,x=v;continue}if(f(v)>=1){w=v+1|0;continue}y=!1,x=v}return x})(0),p=h>=d?[]:er(m=>f(m)>0)(Kt(h,d-1|0)).init;return n.bind((()=>{const m=t.drawText({x:u,y:c,content:Re(h)(_),font:i,color:s,align:fi,baseline:En});return h>0?m:r.pure()})())(()=>o(m=>n.bind(t.measureText(i)(Re(m)(_)))(w=>{const y=f(m);return t.drawText({x:u+w,y:c-(1-y)*10,content:Re(1)(Vo(ir(Re(m)(_)))(_)),font:i,color:{...s,a:fe(In(y*nt(s.a)))},align:fi,baseline:En})}))(p))}},vl=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=ko(r),i=ZC(t);return s=>{if(s.plan.tag==="PlainText")return t.drawText(s.spec);if(s.plan.tag==="RoundedText")return n.bind((()=>{const a=r.pure();if(s.bounds.tag==="Nothing")return a;if(s.bounds.tag==="Just")return t.drawRoundedRect(s.bounds._1)(s.plan._1.radius)(s.plan._1.fill)(s.plan._1.stroke);g()})())(()=>t.drawText(s.spec));if(s.plan.tag==="TokenTravelText"){const a=s.plan._1;return n.bind(o(u=>t.fillPath(rl(u)(1.5))(a.trailFill))(a.trail))(()=>n.bind((()=>{const u=r.pure();if(s.bounds.tag==="Nothing")return u;if(s.bounds.tag==="Just")return t.drawRoundedRect(s.bounds._1)(a.radius)(N("Just",a.fill))(J);g()})())(()=>i(s.spec.font)(s.spec.color)(a.reveal)(a.textLeft)(s.spec.y)(s.text)))}if(s.plan.tag==="TokenFillingText"){const a=s.plan._1;return n.bind(t.drawRoundedRect(a.shadow)(a.radius)(N("Just",a.shadowFill))(J))(()=>n.bind((()=>{const u=r.pure();if(s.bounds.tag==="Nothing")return u;if(s.bounds.tag==="Just")return t.drawRoundedRect(s.bounds._1)(a.radius)(N("Just",a.fill))(N("Just",a.stroke));g()})())(()=>n.bind(t.strokePath(a.leader)(a.stroke))(()=>t.drawText(s.spec))))}if(s.plan.tag==="AffineText")return t.drawTextAffine(s.plan._1)(s.spec);g()}},tb=t=>e=>n=>r=>o=>i=>s=>pl(r)(o)(i)({owner:No("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:fi,baseline:En},bounds:N("Just",r),plan:is("TokenTravelText",{trail:WC(r)(s),trailFill:{color:e.trailDot,flat:!0},radius:3,fill:{color:e.chipPillFill,flat:!0},textLeft:r.x+14,reveal:(()=>{const a=n.phaseInLabel/.45;return a<0?0:a>1?1:a})()})}),ba=t=>e=>n=>r=>{const o=O(f=>nt(Ca(1)(Ko(f).length)))(r),i=hr(1)(T(nr)(0)(o)),s=hi(e)(n)(t),a=s*i,u=Ca(1)(r.length),c=(f=>h=>p=>{let m=f,w=h,y=p,x=!0,v;for(;x;){const C=m,L=w,E=Ft(B=>J,B=>z=>N("Just",{head:B,tail:z}),y);if(E.tag==="Nothing"){x=!1,v=Ca(0)(u-1|0);continue}if(E.tag==="Just"){if(L+E._1.head>=a){x=!1,v=C;continue}m=C+1|0,w=L+E._1.head,y=E._1.tail;continue}g()}return v})(0)(0)(o),_=T(nr)(0)(c<1?[]:Bt(0,c,o)),d=_/i;if(c>=0&&c<o.length){const f=(_+o[c])/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(f<=d)return 1;const h=(s-d)/(f-d);return h<0?0:h>1?1:h})()}}const l=(_+1)/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(l<=d)return 1;const f=(s-d)/(l-d);return f<0?0:f>1?1:f})()}},Cl=t=>e=>n=>r=>o=>t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(ba(r)(0)(0)(O(Ci)(o)).line))(i=>{const s=i+28;return t.Applicative0().pure({x:n.x+n.w/2-s/2,y:n.y-25.2-14,w:s,h:25.2})}),eb=t=>{const e=t.Bind1(),n=t.Applicative0(),r=uo.traverse(n);return o=>i=>s=>e.Apply0().Functor0().map(a=>dl(Tt(u=>u)(a)))(r(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const u=Pe(a._2._1.node)(i.nodes);if(u.tag==="Just")return e.bind(Cl(t)(o)(u._1)(a._2._1.progress)(a._2._1.labels))(c=>n.pure(N("Just",b(a._1,c))));if(u.tag==="Nothing")return n.pure(J);g()}return n.pure(J)})(Ze(s.tokens)))},nb=t=>e=>n=>r=>o=>i=>s=>a=>u=>{const c=cg(n)(r)(o)(i)(s)(a);return t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(ba(i)(s)(a)(St(u)(fg)).line))(_=>t.Applicative0().pure({x:c.x+14+_/2-_/2-14,y:c.y-6-8-6.6-6,w:_+28,h:25.2}))},rb=t=>{const e=t.Bind1(),n=t.Applicative0(),r=uo.traverse(n);return o=>i=>s=>e.Apply0().Functor0().map(a=>dl(Tt(u=>u)(a)))(r(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const u=Pe(a._2._1.target)(i.nodes),c=Pe(a._2._1.source)(i.nodes),_=Fr(a._2._1.edge)(i.edges);if(_.tag==="Just"&&c.tag==="Just"&&u.tag==="Just"){const d=(()=>{if(a._2._1.direction==="Forward")return _._1;if(a._2._1.direction==="Backward")return se(_._1);g()})(),l=cg(d)(c._1)(u._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);return e.bind(nb(t)(o)(d)(c._1)(u._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(f=>n.pure(N("Just",b(a._1,{id:a._1,rect:f,token:l}))))}}return n.pure(J)})(Ze(s.tokens)))},hg=t=>{const e=t.Bind1(),n=rb(t),r=eb(t);return o=>i=>s=>a=>e.bind(n(o)(s)(a))(u=>e.bind(r(o)(s)(a))(c=>t.Applicative0().pure(TC({x:i.vx,y:i.vy,w:i.vw,h:i.vh})([...Tt(_=>{const d=Pe(_._1)(a.nodes);return d.tag==="Just"&&pi(d._1).alpha>0?N("Just",{x:_._2.x,y:_._2.y,w:_._2.w,h:_._2.h}):J})(Ze(s.nodes)),...(()=>{const _=(d,l)=>{if(d.tag==="Leaf")return l;if(d.tag==="Node")return _(d._5,Lt("Cons",d._4,_(d._6,l)));g()};return Zt(de.foldr,_(c,$))})()])(Tt(_=>ll(_)(u))((()=>{const _=d=>{if(d.tag==="Leaf")return I;if(d.tag==="Node")return te("Node",d._1,d._2,d._3,void 0,_(d._5),_(d._6));g()};return Pt(P.compare)(Zt(fn.foldr,_(u)))})())))))},ob=hg(Ac),bl=t=>e=>n=>{const r=Ri(6)(.55)(va(0)(1)((1-t)/.06)),o=t>.94,i=o&&n>1e-4,s=Ri(6)(.55)(va(0)(1)(t/.06)),a=t<.06,u=a&&e>1e-4,c=o&&n<=1e-4;return{popScale:u?s:i?r:1,flipY:a&&e<=1e-4?s: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})()}},ka=t=>e=>n=>r=>je({path:[],role:dn,layer:N("Just",nv),effects:[]})(Qr(o=>{if(o._2.tag==="Travelling"){if(o._2._1.labels.length!==0){const i=Pe(o._2._1.target)(e.nodes),s=Pe(o._2._1.source)(e.nodes),a=Fr(o._2._1.edge)(e.edges),u=ll(o._1)(r);if(u.tag==="Just"&&a.tag==="Just"&&s.tag==="Just"&&i.tag==="Just")return tb(o._1)(t)(ba(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost)(St(o._2._1.labels)(fg)))(u._1)({x:u._1.x+u._1.w/2,y:u._1.y+u._1.h/2})(bl(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost))(cg((()=>{if(o._2._1.direction==="Forward")return a._1;if(o._2._1.direction==="Backward")return se(a._1);g()})())(s._1)(i._1)(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost))}return tt(ut("Return",void 0),_t)}if(o._2.tag==="Filling"&&o._2._1.labels.length!==0){const i=Pe(o._2._1.node)(e.nodes);if(i.tag==="Just"){const s=i._1,a=Cl(Ac)(Ud)(s)(o._2._1.progress)(o._2._1.labels),u=c=>HC(o._1)(t)(ba(o._2._1.progress)(0)(0)(St(o._2._1.labels)(fg)).line)(s)(c)({x:c.x+c.w/2,y:c.y+c.h/2})(bl(o._2._1.progress)(0)(0));return tt(a._1,(()=>{if(a._2.tag==="CatNil")return at("CatCons",u,st($,$));if(a._2.tag==="CatCons")return at("CatCons",a._2._1,st(a._2._2._1,Lt("Cons",at("CatCons",u,st($,$)),a._2._2._2)));g()})())}if(i.tag==="Nothing")return tt(ut("Return",void 0),_t);g()}return tt(ut("Return",void 0),_t)})(Ze(n.tokens))),kl=t=>e=>n=>r=>{const o=ob(Ud)(e)(n)(r);return tt(o._1,(()=>{if(o._2.tag==="CatNil")return at("CatCons",i=>ka(t)(n)(r)(i),st($,$));if(o._2.tag==="CatCons")return at("CatCons",o._2._1,st(o._2._2._1,Lt("Cons",at("CatCons",i=>ka(t)(n)(r)(i),st($,$)),o._2._2._2)));g()})())},ib=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>o=>{const i=o.length-1|0,s=i<1?[]:Bt(0,i,o),a=s.length-1|0,u=a>=0&&a<s.length?N("Just",s[a]):J,c=o.length-1|0,_=c>=0&&c<o.length?N("Just",o[c]):J;if(_.tag==="Just"&&u.tag==="Just"){const d=Ee(.78)(1.18)(us(o)+19|0),l=Ee(.4)(.62)(d.prng),f=r.wobble?8.75*l.value:4.375,h=Ee(.4)(.62)(l.prng),p=r.wobble?8.75*h.value:4.375,m=_._1.y-u._1.y,w=_._1.x-u._1.x,y=Ve(w*w+m*m),x=m/y,v=-x,C=w/y,L=_._1.x+C*.875,E=_._1.y+x*.875,B=r.wobble?8.75*d.value:8.75,z=L-C*B,Y=E-x*B,R=z+v*f,A=Y+C*f,j=[1,L,E,2,z+v*4.375,Y+C*4.375,2,z-v*4.375,Y-C*4.375,5],Z=z-v*p,M=Y-C*p,W={color:r.arrowFill,width:2,lineJoin:Ue,lineCap:Un};return y<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,R,A,2,L,E])(W))(()=>t.strokePath([1,Z,M,2,L,E])(W)):t.fillPath(j)({color:r.arrowFill,flat:!0})}return n.pure()}},sb=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=ko(n),i=t.popAlpha,s=ib(t);return a=>u=>c=>_=>d=>{const l=iC(8)(_),f=c&&d.hi>=.9&&(1-d.hi)*Bi(l)<=8.75?1:d.hi;if(f<=d.lo)return n.pure();const h=dC(l)(d.lo)(f);if(h.length===0)return n.pure();const p={color:a.edge,width:a.wobble?2:.9375,lineJoin:Ue,lineCap:Un},m=a.wobble?Ee(-10)(4)(us(h)).value:0,w=a.wobble?EC(m)(h):h;return r.bind(a.wobble?o(y=>r.bind(t.pushAlpha(y.alpha))(()=>r.bind(t.strokePath(y.path)(p))(()=>i)))((()=>{const y=us(h);return w.length<2?[]:yi($C)(y)(!1)(w)})()):t.strokePath(nC(h))(p))(()=>{const y=s(a)(w);return u&&f>=.999?y:n.pure()})}},ab=t=>{const e=sb(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()},ub=t=>e=>{const n=i=>{const s=Pe(i)(t.nodes);if(s.tag==="Nothing")return!1;if(s.tag==="Just"){const a=s._1;return!xe(u=>0<u._2.length&&u._2[0].x>=a.x&&u._2[0].x<=a.x+a.w&&u._2[0].y>=a.y&&u._2[0].y<=a.y+a.h,Ze(t.edges))}g()},r=T(i=>s=>(i*31|0)+jr(s)|0)(5381)(br(e.frameTitle)),o=i=>{const s=Pe(i)(t.nodes);if(s.tag==="Nothing")return!1;if(s.tag==="Just"){const a=s._1;return!xe(u=>{const c=u._2.length-1|0;return c>=0&&c<u._2.length&&u._2[c].x>=a.x&&u._2[c].x<=a.x+a.w&&u._2[c].y>=a.y&&u._2[c].y<=a.y+a.h},Ze(t.edges))}g()};return T(i=>s=>{const a=s._2;return FC(u=>{if(u.tag==="Nothing")return N("Just",a);if(u.tag==="Just")return N("Just",{t:hr(u._1.t)(a.t),angle:a.t>=u._1.t?a.angle:u._1.angle,bigCircle:u._1.bigCircle||a.bigCircle,frameHash:u._1.frameHash});g()})(s._1)(i)})(I)(St(Ze(e.tokens))(i=>{if(i._2.tag==="Filling"){const s=i._2._1.node;return[b(s,{t:1,angle:(()=>{const a=Tt(u=>(()=>{const c=Pe(s)(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):J)(Ze(t.edges));if(0<a.length){const u=a[0].length-1|0,c=u<1?[]:Bt(0,u,a[0]),_=c.length-1|0;if(_>=0&&_<c.length){const d=a[0].length-1|0;return d>=0&&d<a[0].length?co(a[0][d].y-c[_].y)(a[0][d].x-c[_].x):0}a[0].length-1|0}return 0})(),bigCircle:n(s)||o(s),frameHash:r})]}if(i._2.tag==="Travelling"){if(i._2._1.progress>=.75)return[b(i._2._1.target,{t:(i._2._1.progress-.75)/.25,angle:(()=>{const s=Fr(i._2._1.edge)(t.edges);if(s.tag==="Just"){const a=s._1.length-1|0,u=a<1?[]:Bt(0,a,s._1),c=u.length-1|0;if(c>=0&&c<u.length){const _=s._1.length-1|0;return _>=0&&_<s._1.length?co(s._1[_].y-u[c].y)(s._1[_].x-u[c].x):0}return s._1.length-1|0,0}if(s.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[b(i._2._1.source,{t:i._2._1.progress/.25,angle:(()=>{const s=Fr(i._2._1.edge)(t.edges);if(s.tag==="Just")return 1<s._1.length&&0<s._1.length?co(s._1[1].y-s._1[0].y)(s._1[1].x-s._1[0].x):0;if(s.tag==="Nothing")return 0;g()})(),bigCircle:n(i._2._1.source)||o(i._2._1.source),frameHash:r})]}return[]}))},cb=t=>T(e=>n=>(e*31|0)+jr(n)|0)(5381)(br(t.frameTitle)),Ll=t=>e=>n=>r=>o=>{const i=cb(o),s=ub(r)(o);return Qr(a=>{const u=Pe(a._1)(o.nodes);if(u.tag==="Just")return ml(Vd)(t)(e)(n)((()=>{const c=Pe(a._1)(o.nodeFadeAlpha);if(c.tag==="Nothing")return 1;if(c.tag==="Just")return c._1;g()})())((()=>{const c=Pe(a._1)(o.nodeLabelFadeAlpha);if(c.tag==="Nothing")return 1;if(c.tag==="Just")return c._1;g()})())((()=>{const c=Pe(a._1)(s);return c.tag==="Just"?N("Just",c._1):c.tag==="Nothing"&&QC(a._1)(o.visited)?N("Just",{t:1,angle:0,bigCircle:!1,frameHash:i}):J})())(a._1)(a._2)(u._1);if(u.tag==="Nothing")return tt(ut("Return",void 0),_t);g()})(Ze(r.nodes))},gb=t=>t,Sl=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,s={...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?s:e},El=t=>e=>t.width<=0||t.height<=0?e:Sl(t.width/t.height)(e),_b=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Gl=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Pl=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},pg=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fb=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},db=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},mg=(()=>{const t=nn.unfoldr(Qn);return e=>t(rn("IterNode",e,Fn))})(),lb=Wr(Jo)(zt),hb=t=>e=>{const n=pn(t.angle),r=Ln(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},pb=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],yg=t=>e=>{const n=r=>_b(0)(255)(fe($n(nt(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},Xe=t=>e=>n=>r=>({x:(e-n)*Ln(t.angle),y:(e+n)*pn(t.angle)-r}),xg=t=>{const e=Ft(n=>J,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,...St(e._1.tail)(n=>[2,n.x,n.y]),5];g()},mb=t=>e=>n=>{const r=n.id,o=n.np,i=tg({id:r,role:Vd,geometry:Xc("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:Yc("IsoNodePlan",{config:t,palette:e})}),s=()=>ss({owner:No("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:Dr,baseline:En},bounds:J,plan:is("AffineText",hb(t)(o.y+o.h))});return tt(i._1,(()=>{if(i._2.tag==="CatNil")return at("CatCons",s,st($,$));if(i._2.tag==="CatCons")return at("CatCons",i._2._1,st(i._2._2._1,Lt("Cons",at("CatCons",s,st($,$)),i._2._2._2)));g()})())},yb=t=>e=>n=>r=>o=>{const i=Fe(An,o,Bt(1,o.length,o)),s=i.length-1|0;return Ht(a=>u=>({depth:(u._1.x+u._1.y+u._2.x+u._2.y)/2,draw:Yd({id:n,geometry:Id("IsoSegments",[[Xe(t)(u._1.x)(u._1.y)(0),Xe(t)(u._2.x)(u._2.y)(0)]]),visible:{lo:0,hi:1},arrow:r&&a===s,settlingAtTarget:!1,plan:Fd("IsoEdgePlan",{config:t,palette:e})})}))(i)},xb=t=>e=>n=>r=>o=>{const i=(()=>{if(t==="Forward")return o;if(t==="Backward")return se(o);g()})();if(0<i.length){const a=lo(i)(Gl(0)(1)(hi(n)(r)(e)));if(a.tag==="Nothing")return i[0];if(a.tag==="Just")return a._1;g()}const s=lo(i)(Gl(0)(1)(hi(n)(r)(e)));if(s.tag==="Nothing")return{x:0,y:0};if(s.tag==="Just")return s._1;g()},wb=t=>{const e=Ft(n=>J,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,...St(e._1.tail)(n=>[2,n.x,n.y])];g()},Jb=t=>{const e=Ft(n=>J,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=T(r=>o=>({minX:Pl(r.minX)(o.x),minY:Pl(r.minY)(o.y),maxX:pg(r.maxX)(o.x),maxY:pg(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()},Nb=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,s=(a,u)=>t.fillStrokePath(xg(a))({color:u,flat:!0})({color:i.nodeStroke,width:1,lineJoin:Ue,lineCap:Gn});return n.bind(s(o.south,yg(.66)(i.nodeFill)))(()=>n.bind(s(o.east,yg(.82)(i.nodeFill)))(()=>s(o.top,i.nodeFill)))}return e.Applicative0().pure()}},Tb=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,s=(a,u)=>t.fillStrokePath(xg(a))({color:yg(u)(i.tokenOutsideFill),flat:!0})({color:i.tokenOutsideStroke,width:1,lineJoin:Ue,lineCap:Gn});return n.bind(s(o.south,.66))(()=>n.bind(s(o.east,.82))(()=>s(o.top,1)))}return e.Applicative0().pure()}},vb={angle:.5235987755982988,boxHeight:26,transparentBg:!0},Cb=t=>e=>n=>{const r=n.x-5.5,o=n.x+5.5,i=n.y-5.5,s=n.y+5.5,a=e+11,u=Xe(t)(o)(i)(a),c=Xe(t)(o)(s)(a),_=Xe(t)(r)(s)(a),d=Xe(t)(o)(s)(e);return{south:[Xe(t)(r)(s)(e),d,c,_],east:[Xe(t)(o)(i)(e),d,c,u],top:[Xe(t)(r)(i)(a),u,c,_]}},bb=t=>e=>n=>r=>{const o=r._1,i=(s,a)=>({depth:a.x+a.y,draw:Kd({id:o,pass:Od,geometry:Md("IsoCube",Cb(t)(s)(a)),position:a,plan:Wd("IsoTokenPlan",{config:t,palette:e,baseZ:s})})});if(r._2.tag==="Travelling"){const s=fb(r._2._1.edge)(n.edges);return s.tag==="Just"?N("Just",i(0,xb(r._2._1.direction)(r._2._1.progress)(r._2._1.holdPre)(r._2._1.holdPost)(s._1))):J}if(r._2.tag==="Filling"){const s=db(r._2._1.node)(n.nodes);if(s.tag==="Just")return N("Just",i(t.boxHeight,{x:s._1.x+s._1.w/2,y:s._1.y+s._1.h/2}))}return J},kb=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:Xe(t)(e.x)(e.y)(0),b:Xe(t)(r)(e.y)(0),c:Xe(t)(r)(n)(0),d:Xe(t)(e.x)(n)(0)},top:{a:Xe(t)(e.x)(e.y)(t.boxHeight),b:Xe(t)(r)(e.y)(t.boxHeight),c:Xe(t)(r)(n)(t.boxHeight),d:Xe(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},Bl=t=>e=>O(n=>({id:n._1,np:n._2,box:kb(t)(n._2)}))(mg(e.nodes)),Lb=t=>e=>[...St(Bl(t)(e))(pb),...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Lt("Cons",r._4,n(r._6,o)));g()};return St(Zt(de.foldr,n(e.edges,$)))(O(r=>Xe(t)(r.x)(r.y)(0)))})()],Sb=t=>e=>n=>r=>{const o=gg(e),i=[...St(mg(n.edges))(u=>yb(t)(o)(u._1)((()=>{const c=go("conn:")(u._1);if(c.tag==="Just")return!1;if(c.tag==="Nothing")return!0;g()})())(u._2)),...O(u=>({depth:u.box.depth,draw:mb(t)(o)(u)}))(Bl(t)(n)),...Tt(bb(t)(o)(n))(mg(r.tokens))],s=Xd({viewport:Jb(Lb(t)(n)),clear:N("Just",t.transparentBg?o.bgTransparent:o.bg),dots:J}),a=()=>lb(u=>u.draw)(Pt(u=>c=>ot.compare(u.depth)(c.depth))(i));return tt(s._1,(()=>{if(s._2.tag==="CatNil")return at("CatCons",a,st($,$));if(s._2.tag==="CatCons")return at("CatCons",s._2._1,st(s._2._2._1,Lt("Cons",at("CatCons",a,st($,$)),s._2._2._2)));g()})())},Eb=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=pg(1e-4)(Ve(n*n+e*e)),o=e/r,i=n/r,s=t.to.y-o*7,a=t.to.x-i*7;return xg([t.to,{x:a-o*3,y:s+i*3},{x:a+o*3,y:s-i*3}])},Gb=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Wr(n)(zt);return o=>{if(o.geometry.tag==="IsoSegments"&&o.plan.tag==="IsoEdgePlan"){const i=o.plan._1.palette,s=o.geometry._1;return e.Bind1().bind(r(a=>t.strokePath(wb(a))({color:i.edge,width:1.5,lineJoin:Ue,lineCap:Un}))(s))(()=>{const a=s.length-1|0;if(a>=0&&a<s.length){const c=s[a],_=c.length-1|0,d=_<1?[]:Bt(0,_,c),l=d.length-1|0;if(l>=0&&l<d.length){const h=s.length-1|0,p=(()=>{if(h>=0&&h<s.length){const m=s[h],w=m.length-1|0;if(w>=0&&w<m.length)return t.fillPath(Eb({from:d[l],to:m[w]}))({color:i.arrowFill,flat:!0})}return n.pure()})();return o.arrow?p:n.pure()}s.length-1|0;const f=n.pure();return o.arrow?f:n.pure()}s.length-1|0;const u=n.pure();return o.arrow?u:n.pure()})}return n.pure()}},Dl=(t,e)=>({tag:t,_1:e}),La=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Pb=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},wg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Bb=Fo(Jo)(zt),Db=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Rb=Dl("ResolvedLabels"),Ab=t=>{const e=re(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return Os(t);g()},xi=t=>e=>{const n=La(1)(he(e.rootLayout).w),r=Xr(e.rootLayout)(e.camera),o=!e.diving&&e.levels.length===1?1:Pb(0)(1)(r.w/n),i=Os(e).state.frameTitle===""?0*o:40*o,s=t.padding*o*o;return(()=>{if(t.outputAspect.tag==="Nothing")return gb;if(t.outputAspect.tag==="Just")return Sl(t.outputAspect._1);g()})()({vx:r.x-s,vy:r.y-s-i,vw:r.w+2*s,vh:r.h+2*s+i})},Ib=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=wg(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,s=n._1.h*t.segment.placement.scale;return[1,r,o,2,r+i,o,2,r+i,o+s,2,r,o+s,5]}}g()},Jg=t=>e=>{const n=t2(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}},Rl=t=>e=>t===""?tt(ut("Return",void 0),_t):ss({owner:Xv,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:fi,baseline:KT},bounds:J,plan:ya}),Al=t=>e=>{if(t==="")return tt(ut("Return",void 0),_t);const n=e.vh/720,r=56*n,o=ts({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:56,weight:700})(t),i=s=>{const a=r+16*n*2,u=s*n+28*n*2,c=e.vy+e.vh/2,_=e.vx+e.vw/2,d={x:_-u/2,y:c-a/2,w:u,h:a};return xa(ma("TitleCardOverlay",{backing:{path:li(d)(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:Ue,lineCap:Un})},text:{owner:$d,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:Dr,baseline:En},bounds:N("Just",d),plan:ya}}))};return tt(o._1,(()=>{if(o._2.tag==="CatNil")return at("CatCons",i,st($,$));if(o._2.tag==="CatCons")return at("CatCons",o._2._1,st(o._2._2._1,Lt("Cons",at("CatCons",i,st($,$)),o._2._2._2)));g()})())},Il=t=>e=>{if(t==="")return tt(ut("Return",void 0),_t);const n=e.vh/720,r=15*n,o=ts({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:15,weight:600})(t),i=s=>{const a=e.vy+12*n,u=r+6*n*2,c=s*n+11*n*2,_=e.vx+e.vw/2,d={x:_-c/2,y:a,w:c,h:u};return xa(ma("FrameTitleOverlay",{backing:N("Just",{path:li(d)(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:Ue,lineCap:Un})}),text:{owner:$d,text:t,spec:{x:_,y:a+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:Dr,baseline:En},bounds:N("Just",d),plan:ya}}))};return tt(o._1,(()=>{if(o._2.tag==="CatNil")return at("CatCons",i,st($,$));if(o._2.tag==="CatCons")return at("CatCons",o._2._1,st(o._2._2._1,Lt("Cons",at("CatCons",i,st($,$)),o._2._2._2)));g()})())},Fb=t=>e=>n=>r=>o=>i=>s=>a=>{const u=gg(t.theme),c=(()=>{if(a.tag==="ResolvedLabels")return kl(u)(o)(i)(s);if(a.tag==="SpringLabels")return ka(u)(i)(s)(Tl(o)(a._1));g()})(),_=Xd({viewport:o,clear:N("Just",t.transparentBg?u.bgTransparent:u.bg),dots:J}),d=()=>{const l=je({path:[],role:dn,layer:J,effects:[...n<1?[be("GroupAlpha",n)]:[],...r>0?[be("GroupBlur",r)]:[]]})((()=>{const f=Nl(u)(i)(s),h=()=>{const p=wl(u)(t.halftoneShadows)(i)(s),m=()=>{const w=Ll(jc)(1)(u)(i)(s),y=()=>{const x=Jl(u)(i)(s),v=()=>{const C=lg(u)(o)(i)(s),L=()=>{const E=yl(av)(u)(i)(s),B=()=>{const z=()=>{const Y=jC(u)(i)(s);return s.staticKind!=="Animated"?Y:tt(ut("Return",void 0),_t)};return tt(c._1,(()=>{if(c._2.tag==="CatNil")return at("CatCons",z,st($,$));if(c._2.tag==="CatCons")return at("CatCons",c._2._1,st(c._2._2._1,Lt("Cons",at("CatCons",z,st($,$)),c._2._2._2)));g()})())};return tt(E._1,(()=>{if(E._2.tag==="CatNil")return at("CatCons",B,st($,$));if(E._2.tag==="CatCons")return at("CatCons",E._2._1,st(E._2._2._1,Lt("Cons",at("CatCons",B,st($,$)),E._2._2._2)));g()})())};return tt(C._1,(()=>{if(C._2.tag==="CatNil")return at("CatCons",L,st($,$));if(C._2.tag==="CatCons")return at("CatCons",C._2._1,st(C._2._2._1,Lt("Cons",at("CatCons",L,st($,$)),C._2._2._2)));g()})())};return tt(x._1,(()=>{if(x._2.tag==="CatNil")return at("CatCons",v,st($,$));if(x._2.tag==="CatCons")return at("CatCons",x._2._1,st(x._2._2._1,Lt("Cons",at("CatCons",v,st($,$)),x._2._2._2)));g()})())};return tt(w._1,(()=>{if(w._2.tag==="CatNil")return at("CatCons",y,st($,$));if(w._2.tag==="CatCons")return at("CatCons",w._2._1,st(w._2._2._1,Lt("Cons",at("CatCons",y,st($,$)),w._2._2._2)));g()})())};return tt(p._1,(()=>{if(p._2.tag==="CatNil")return at("CatCons",m,st($,$));if(p._2.tag==="CatCons")return at("CatCons",p._2._1,st(p._2._2._1,Lt("Cons",at("CatCons",m,st($,$)),p._2._2._2)));g()})())};return tt(f._1,(()=>{if(f._2.tag==="CatNil")return at("CatCons",h,st($,$));if(f._2.tag==="CatCons")return at("CatCons",f._2._1,st(f._2._2._1,Lt("Cons",at("CatCons",h,st($,$)),f._2._2._2)));g()})())})());if(n>0){const f=()=>{const h=Rl(t.watermark)(o),p=()=>s.staticKind==="TitleCard"?Al(s.frameTitle)(o):Il(s.frameTitle)(o);return tt(h._1,(()=>{if(h._2.tag==="CatNil")return at("CatCons",p,st($,$));if(h._2.tag==="CatCons")return at("CatCons",h._2._1,st(h._2._2._1,Lt("Cons",at("CatCons",p,st($,$)),h._2._2._2)));g()})())};return tt(l._1,(()=>{if(l._2.tag==="CatNil")return at("CatCons",f,st($,$));if(l._2.tag==="CatCons")return at("CatCons",l._2._1,st(l._2._2._1,Lt("Cons",at("CatCons",f,st($,$)),l._2._2._2)));g()})())}return tt(ut("Return",void 0),at("CatCons",()=>{const f=Rl(t.watermark)(o),h=()=>s.staticKind==="TitleCard"?Al(s.frameTitle)(o):Il(s.frameTitle)(o);return tt(f._1,(()=>{if(f._2.tag==="CatNil")return at("CatCons",h,st($,$));if(f._2.tag==="CatCons")return at("CatCons",f._2._1,st(f._2._2._1,Lt("Cons",at("CatCons",h,st($,$)),f._2._2._2)));g()})())},st($,$)))};return tt(_._1,(()=>{if(_._2.tag==="CatNil")return at("CatCons",d,st($,$));if(_._2.tag==="CatCons")return at("CatCons",_._2._1,st(_._2._2._1,Lt("Cons",at("CatCons",d,st($,$)),_._2._2._2)));g()})())},Ng=t=>e=>n=>r=>Bb(r.minis)(o=>{const i=Fl(t)(e)(n)(I)(r)(o);return(()=>{const s=o.segment.path.length-1|0;return o.bgAlpha>0&&s>=0&&s<o.segment.path.length&&(()=>{const a=wg(o.segment.path[s])(r.state.nodes);if(a.tag==="Just")return a._1.tag==="Hidden"?!1:a._1.tag!=="PloppingOut";if(a.tag==="Nothing")return!1;g()})()})()?i:tt(ut("Return",void 0),_t)}),Fl=t=>e=>n=>r=>o=>i=>{const s=i.state,a={tx:i.segment.placement.tx,ty:i.segment.placement.ty,sx:i.segment.placement.scale,sy:i.segment.placement.scale},u=gg(t.theme),c=i.segment.layout,_=he(c),d={vx:_.x-1e3,vy:_.y-1e3,vw:_.w+2e3,vh:_.h+2e3},l=i.segment.path.length-1|0,f=l>=0&&l<i.segment.path.length?wg(i.segment.path[l])(o.segment.layout.nodes):J,h=i.segment.placement.scale*n,p=Db(8)(La(1)(1/(1.25*La(1e-6)(h)))),m=11*h>=5?jc:Zc,w=Jg(e.viewport)(i),y=(()=>{if(m==="LabelsHidden")return tt(ut("Return",void 0),_t);if(m==="LabelsShown")return r.tag==="Leaf"?kl(u)(w)(c)(s):ka(u)(c)(s)(Tl(w)(r));g()})();return je({path:i.segment.path,role:i.role,layer:J,effects:[be("GroupAlpha",i.bgAlpha),...i.blur>0?[be("GroupBlur",i.blur*i.segment.placement.scale)]:[]]})((()=>{const x=je({path:i.segment.path,role:i.role,layer:J,effects:[be("GroupClip",Ib(o)((()=>{const C=i.segment.path.length-1|0;return C>=0&&C<i.segment.path.length?N("Just",i.segment.path[C]):J})()),ns)]})((()=>{const C=(()=>{if(f.tag==="Just")return je({path:o.segment.path,role:o.role,layer:J,effects:[be("GroupTransform",mi,{tx:o.segment.placement.tx,ty:o.segment.placement.ty,sx:o.segment.placement.scale,sy:o.segment.placement.scale})]})(xa(ma("FloorOverlay",{path:eg({...f._1,x:f._1.x+1,y:f._1.y+1,w:f._1.w-2,h:f._1.h-2}),fill:N("Just",{color:u.bg,flat:!0}),stroke:J})));if(f.tag==="Nothing")return tt(ut("Return",void 0),_t);g()})(),L=o.role==="Active"||o.role==="FlyThrough"?C:tt(ut("Return",void 0),_t),E=()=>{const B=je({path:i.segment.path,role:i.role,layer:J,effects:[be("GroupTransform",mi,a)]})((()=>{const Y=Nl(u)(c)(s),R=()=>{const A=wl(u)(t.halftoneShadows)(c)(s),j=()=>{const Z=Ll(m)(p)(u)(c)(s),M=()=>{const W=Jl(u)(c)(s);return tt(W._1,(()=>{if(W._2.tag==="CatNil")return at("CatCons",()=>lg(u)(d)(c)(s),st($,$));if(W._2.tag==="CatCons")return at("CatCons",W._2._1,st(W._2._2._1,Lt("Cons",at("CatCons",()=>lg(u)(d)(c)(s),st($,$)),W._2._2._2)));g()})())};return tt(Z._1,(()=>{if(Z._2.tag==="CatNil")return at("CatCons",M,st($,$));if(Z._2.tag==="CatCons")return at("CatCons",Z._2._1,st(Z._2._2._1,Lt("Cons",at("CatCons",M,st($,$)),Z._2._2._2)));g()})())};return tt(A._1,(()=>{if(A._2.tag==="CatNil")return at("CatCons",j,st($,$));if(A._2.tag==="CatCons")return at("CatCons",A._2._1,st(A._2._2._1,Lt("Cons",at("CatCons",j,st($,$)),A._2._2._2)));g()})())};return tt(Y._1,(()=>{if(Y._2.tag==="CatNil")return at("CatCons",R,st($,$));if(Y._2.tag==="CatCons")return at("CatCons",Y._2._1,st(Y._2._2._1,Lt("Cons",at("CatCons",R,st($,$)),Y._2._2._2)));g()})())})()),z=()=>je({path:i.segment.path,role:i.role,layer:J,effects:[be("GroupTransform",Uv,a)]})(yl(uv)(u)(c)(s));return tt(B._1,(()=>{if(B._2.tag==="CatNil")return at("CatCons",z,st($,$));if(B._2.tag==="CatCons")return at("CatCons",B._2._1,st(B._2._2._1,Lt("Cons",at("CatCons",z,st($,$)),B._2._2._2)));g()})())};return tt(L._1,(()=>{if(L._2.tag==="CatNil")return at("CatCons",E,st($,$));if(L._2.tag==="CatCons")return at("CatCons",L._2._1,st(L._2._2._1,Lt("Cons",at("CatCons",E,st($,$)),L._2._2._2)));g()})())})()),v=()=>{const C=je({path:i.segment.path,role:i.role,layer:J,effects:[be("GroupTransform",mi,a)]})(y);return tt(C._1,(()=>{if(C._2.tag==="CatNil")return at("CatCons",()=>Ng(t)(e)(n)(i),st($,$));if(C._2.tag==="CatCons")return at("CatCons",C._2._1,st(C._2._2._1,Lt("Cons",at("CatCons",()=>Ng(t)(e)(n)(i),st($,$)),C._2._2._2)));g()})())};return tt(x._1,(()=>{if(x._2.tag==="CatNil")return at("CatCons",v,st($,$));if(x._2.tag==="CatCons")return at("CatCons",x._2._1,st(x._2._2._1,Lt("Cons",at("CatCons",v,st($,$)),x._2._2._2)));g()})())})())},Qb=t=>e=>n=>{if(t.theme==="Isometric")return Sb({...vb,transparentBg:t.transparentBg})(t.theme)(Os(n).segment.layout)(Os(n).state);const r=xi(t)(n),o=u=>n.hasDives?r.vw/La(1)(he(n.rootLayout).w):1,i={tileScale:o(),viewport:r},s=u=>c=>{if(c.length===0)return tt(ut("Return",void 0),_t);const _=Ft(d=>J,d=>l=>N("Just",{head:d,tail:l}),c);if(_.tag==="Nothing")return tt(ut("Return",void 0),_t);if(_.tag==="Just"){const d=Fl(t)(i)(n.camera.zoom)(_._1.head.role==="Active"?e:I)(u)(_._1.head);return n.diving||_._1.head.role==="Active"?tt(d._1,(()=>{if(d._2.tag==="CatNil")return at("CatCons",()=>s(_._1.head)(_._1.tail),st($,$));if(d._2.tag==="CatCons")return at("CatCons",d._2._1,st(d._2._2._1,Lt("Cons",at("CatCons",()=>s(_._1.head)(_._1.tail),st($,$)),d._2._2._2)));g()})()):tt(ut("Return",void 0),at("CatCons",()=>s(_._1.head)(_._1.tail),st($,$)))}g()},a=Ft(u=>J,u=>c=>N("Just",{head:u,tail:c}),n.levels);if(a.tag==="Nothing")return tt(ut("Return",void 0),_t);if(a.tag==="Just"){const u=a._1.tail,c=a._1.head,_=u.length===0,d=Fb(t)(o())(c.role==="Active"||c.role==="FlyThrough"?c.bgAlpha:0)(c.blur)(r)(c.segment.layout)(Ab(n).state)(_&&e.tag!=="Leaf"?Dl("SpringLabels",e):Rb),l=()=>{const f=Ng(t)(i)(n.camera.zoom)(c);return c.role==="Active"||c.role==="FlyThrough"?tt(f._1,(()=>{if(f._2.tag==="CatNil")return at("CatCons",()=>s(c)(u),st($,$));if(f._2.tag==="CatCons")return at("CatCons",f._2._1,st(f._2._2._1,Lt("Cons",at("CatCons",()=>s(c)(u),st($,$)),f._2._2._2)));g()})()):tt(ut("Return",void 0),at("CatCons",()=>s(c)(u),st($,$)))};return tt(d._1,(()=>{if(d._2.tag==="CatNil")return at("CatCons",l,st($,$));if(d._2.tag==="CatCons")return at("CatCons",d._2._1,st(d._2._2._1,Lt("Cons",at("CatCons",l,st($,$)),d._2._2._2)));g()})())}g()},Tg=t=>e=>n=>tC({viewport:xi(t)(n),camera:n.camera})(Qb(t)(e)(n)),vg=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()},Mb=t=>{const e=t.Monad0(),n=e.Bind1(),r=Wr(e.Applicative0())(f_),o=vl(t);return i=>{if(i.tag==="FrameTitleOverlay"){const s=i._1;return n.bind(r(vg(t))(s.backing))(()=>o(s.text))}if(i.tag==="TitleCardOverlay"){const s=i._1;return n.bind(vg(t)(s.backing))(()=>o(s.text))}if(i.tag==="FloorOverlay")return vg(t)(i._1);g()}},zb=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Wr(n)(zt),o=t.popTransform,i=t.popBakedTransform,s=(()=>{const u=t.popClip,c=t.popAlpha,_=t.popBlend,d=t.popBlur;return l=>{if(l.tag==="GroupTransform"){if(l._1==="NormalTransform")return o;if(l._1==="BakedTransform")return i;g()}if(l.tag==="GroupClip")return u;if(l.tag==="GroupAlpha")return c;if(l.tag==="GroupBlend")return _;if(l.tag==="GroupBlur")return d;g()}})(),a=t.popLayer;return u=>e.Bind1().bind(r(s)(se(u.effects)))(()=>{if(u.layer.tag==="Just")return a;if(u.layer.tag==="Nothing")return n.pure();g()})},Wb=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Wr(n)(zt);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))},Ql=t=>{const e=t.Monad0(),n=KC(t),r=Nb(t),o=ab(t),i=Gb(t),s=VC(t),a=Tb(t);return jv(e)({beginFrame:u=>t.setViewport(u.viewport),endFrame:e.Applicative0().pure(),beginGroup:Wb(t),endGroup:zb(t),background:OC(t),overlay:Mb(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:vl(t),token:u=>{if(u.geometry.tag==="FlatToken")return s(u);if(u.geometry.tag==="IsoCube")return a(u);g()},insideTokenStyle:t.insideTokenStyle,measureText:t.measureText,measureInk:t.measureInk})},qb=hg(Pd)(Vc.measureText),Ml=Ql(Vc),Ob=t=>e=>n=>r=>o=>i=>s=>{const a={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?J:N("Just",r.width/r.height)},u=Sd(n)(r);return()=>{const c=u(),_=o.levels.length-1|0;if(_>=0&&_<o.levels.length){const l=qb(Jg(xi(a)(o))(o.levels[_]))(o.levels[_].segment.layout)(o.levels[_].state)(c)(),f=Rc(i)(l)(s);return Ml(Tg(a)(f.applied)(o))(c)(),f.springs}const d=Rc(i)(I)(s);return Ml(Tg(a)(d.applied)(o))(c)(),d.springs}},cs=t=>"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")",Lo=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,ae=$o(Oo("Fixed",Ho(0)(20)(2))),Cg=t=>{const e=n=>{const r=n>=0&&n<t.length?N("Just",t[n]):J;if(r.tag==="Just")return r._1===1?["M",ae((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===2?["L",ae((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===3?["Q",ae((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+5|0)]:r._1===4?["C",ae((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+5|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{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 ur(" ")(e(0))},Hb=t=>ae(t.vx)+" "+ae(t.vy)+" "+ae(t.vw)+" "+ae(t.vh),Pn=t=>e=>fe(In(e>=0&&e<t.length?t[e]:0)),bg=t=>e=>{const n=Pn(t.ops)(e+1|0);return Bt(n,n+Pn(t.ops)(e+2|0)|0,t.paths)},zl=(()=>{const t=Mn("&")("&"),e=Mn("<")("<"),n=(()=>{const r=Mn(">")(">"),o=(()=>{const i=Mn('"')(""");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),$b={vx:0,vy:0,vw:1,vh:1},Vb=t=>(e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i>=0&&i<t.length){if(t[i]===15){const s=i+1|0;r=!1,o={vx:s>=0&&s<t.length?t[s]:0,vy:(()=>{const a=s+1|0;return a>=0&&a<t.length?t[a]:0})(),vw:(()=>{const a=s+2|0;return a>=0&&a<t.length?t[a]:0})(),vh:(()=>{const a=s+3|0;return a>=0&&a<t.length?t[a]:0})()};continue}n=i+Lo(t[i])|0;continue}r=!1,o=$b}return o})(0),gs=t=>e=>({r:Pn(t)(e),g:Pn(t)(e+1|0),b:Pn(t)(e+2|0),a:Pn(t)(e+3|0)}),Wl=t=>e=>({color:gs(t)(e),width:(()=>{const n=e+4|0;return n>=0&&n<t.length?t[n]:0})(),join:Pn(t)(e+5|0),cap:Pn(t)(e+6|0)}),Ub=t=>e=>'<rect x="'+ae(t.vx)+'" y="'+ae(t.vy)+'" width="'+ae(t.vw)+'" height="'+ae(t.vh)+'" fill="'+cs(e)+'" opacity="'+ae(nt(e.a)/255)+'"/>',Xb=t=>e=>'<path d="'+Cg(t)+'" fill="'+cs(e)+'" fill-opacity="'+ae(nt(e.a)/255)+'"/>',ql=t=>' stroke="'+cs(t.color)+'" stroke-opacity="'+ae(nt(t.color.a)/255)+'" stroke-width="'+ae(t.width)+'" stroke-linejoin="'+(t.join===0?"round":t.join===1?"bevel":"miter")+'" stroke-linecap="'+(t.cap===0?"butt":t.cap===1?"round":"square")+'"',Yb=t=>e=>n=>'<path d="'+Cg(t)+'" fill="'+cs(e)+'" fill-opacity="'+ae(nt(e.a)/255)+'"'+ql(n)+"/>",Kb=t=>e=>'<path d="'+Cg(t)+'" fill="none"'+ql(e)+"/>",jb=t=>e=>{const n=gs(t.ops)(e+7|0),r=Pn(t.ops)(e+12|0),o=Pn(t.ops)(e+11|0);return'<text x="'+ae((()=>{const i=e+1|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" y="'+ae((()=>{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="'+cs(n)+'" fill-opacity="'+ae(nt(n.a)/255)+'" font-size="'+ae((()=>{const i=e+5|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" font-family="'+zl((()=>{const i=Pn(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="'+ie(Pn(t.ops)(e+6|0))+'" text-anchor="'+(o===0?"start":o===1?"middle":"end")+'">'+zl((()=>{const i=Pn(t.ops)(e+3|0);return i>=0&&i<t.strs.length?t.strs[i]:""})())+"</text>"},So=t=>e=>n=>{const r=n>=0&&n<e.ops.length?N("Just",e.ops[n]):J;if(r.tag==="Just")return r._1===1?Xb(bg(e)(n))(gs(e.ops)(n+3|0))+So(t)(e)(n+Lo(r._1)|0):r._1===2?Kb(bg(e)(n))(Wl(e.ops)(n+3|0))+So(t)(e)(n+Lo(r._1)|0):r._1===3?Yb(bg(e)(n))(gs(e.ops)(n+3|0))(Wl(e.ops)(n+7|0))+So(t)(e)(n+Lo(r._1)|0):r._1===4?jb(e)(n)+So(t)(e)(n+Lo(r._1)|0):r._1===16?Ub(t)(gs(e.ops)(n+1|0))+So(t)(e)(n+Lo(r._1)|0):So(t)(e)(n+Lo(r._1)|0);if(r.tag==="Nothing")return"";g()},Zb=t=>{const e=Vb(t.ops);return{viewBox:Hb(e),body:So(e)(t)(0),vx:e.vx,vy:e.vy,vw:e.vw,vh:e.vh}},t3=FT(WT)(x0),Ol=t=>e=>{const n=t.strs;return()=>{const r=lu(n);return t.strs.push(e),r}},Sa=t=>e=>{const n=t.paths;return()=>{const r=lu(n);return t.paths.push(...e),{offset:r,len:e.length}}},e3=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)}},Hl=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)}},Mr=t=>e=>{const n=nt(e),r=t.ops;return()=>{r.push(n)}},Ea=t=>e=>{const n=e.len,r=Mr(t)(e.offset);return()=>(r(),Mr(t)(n)())},n3=()=>{const t=[],e=[],n=[],r=[];return r.push(1),{ops:t,paths:e,strs:n,alphaStack:r}},r3=t=>{if(t.tag==="MeasureText"){const e=t._3(Fc(t._1)(t._2));return()=>e}if(t.tag==="MeasureInk"){const e=t._3(Qc(t._1)(t._2));return()=>e}g()},$l=t=>{const e=t.alphaStack;return()=>{const n=lu(e);if(n===0)return 1;const r=J0(Ut,J,n-1|0,t.alphaStack);if(r.tag==="Nothing")return 1;if(r.tag==="Just")return r._1;g()}},Eo=t=>e=>{const n=$l(t);return()=>{const r=n();return Mr(t)(e.r)(),Mr(t)(e.g)(),Mr(t)(e.b)(),Mr(t)(fe(In(nt(e.a)*r+.5)))()}},Vl=t=>e=>{const n=Eo(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()})())}},o3=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r;if(a.tag==="FillPath"){const u=a._3,c=a._2,_=Sa(s)(a._1);o=!1,i=()=>{const d=_();return s.ops.push(1),Ea(s)(d)(),Eo(s)(c.color)(),u};continue}if(a.tag==="StrokePath"){const u=a._3,c=a._2,_=Sa(s)(a._1);o=!1,i=()=>{const d=_();return s.ops.push(2),Ea(s)(d)(),Vl(s)(c)(),u};continue}if(a.tag==="FillStrokePath"){const u=a._2,c=a._4,_=a._3,d=Sa(s)(a._1);o=!1,i=()=>{const l=d();return s.ops.push(3),Ea(s)(l)(),Eo(s)(u.color)(),Vl(s)(_)(),c};continue}if(a.tag==="DrawText"){const u=a._2,c=a._1,_=Ol(s)(po(c.content));o=!1,i=()=>{const d=_(),l=Ol(s)(c.font.family)();return s.ops.push(4),s.ops.push(c.x),s.ops.push(c.y),Mr(s)(d)(),Mr(s)(l)(),s.ops.push(c.font.size),Mr(s)(c.font.weight)(),Eo(s)(c.color)(),s.ops.push((()=>{if(c.align==="AlignLeft")return 0;if(c.align==="AlignCenter")return 1;if(c.align==="AlignRight")return 2;g()})()),s.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(a.tag==="DrawTextAffine"){n=s,r=$t("DrawText",{...a._2,x:a._1.a*a._2.x+a._1.c*a._2.y+a._1.e,y:a._1.b*a._2.x+a._1.d*a._2.y+a._1.f},a._3);continue}if(a.tag==="PushTransform"){const u=a._2,c=a._1,_=s.ops;o=!1,i=()=>(_.push(5),e3(s)(c)(),u);continue}if(a.tag==="PopTransform"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(6),u);continue}if(a.tag==="PushClip"){const u=a._3,c=a._2,_=Sa(s)(a._1);o=!1,i=()=>{const d=_();return s.ops.push(7),Ea(s)(d)(),s.ops.push((()=>{if(c==="NonZero")return 0;if(c==="EvenOdd")return 1;g()})()),u};continue}if(a.tag==="PopClip"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(8),u);continue}if(a.tag==="PushBlend"){const u=a._1,c=a._2,_=s.ops;o=!1,i=()=>(_.push(9),s.ops.push((()=>{if(u==="Normal")return 0;if(u==="Difference")return 1;g()})()),c);continue}if(a.tag==="PopBlend"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(10),u);continue}if(a.tag==="PushAlpha"){const u=a._1,c=a._2,_=$l(s);o=!1,i=()=>{const d=_();return s.alphaStack.push(d*u),s.ops.push(11),s.ops.push(u),c};continue}if(a.tag==="PopAlpha"){const u=a._1,c=s.alphaStack;o=!1,i=()=>(N0(Ut,J,c),s.ops.push(12),u);continue}if(a.tag==="PushBlur"){const u=a._2,c=a._1,_=s.ops;o=!1,i=()=>(_.push(18),s.ops.push(c),u);continue}if(a.tag==="PopBlur"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(19),u);continue}if(a.tag==="PushLayer"){const u=a._1,c=a._2,_=s.ops;o=!1,i=()=>(_.push(13),s.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(a.tag==="PopLayer"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(14),u);continue}if(a.tag==="SetViewport"){const u=a._2,c=a._1,_=s.ops;o=!1,i=()=>(_.push(15),Hl(s)(c)(),u);continue}if(a.tag==="ClearBackground"){const u=a._1,c=a._2,_=s.ops;o=!1,i=()=>(_.push(16),Eo(s)(u)(),c);continue}if(a.tag==="BackgroundDots"){const u=a._2,c=a._1,_=s.ops;o=!1,i=()=>(_.push(17),Hl(s)(c.viewport)(),Eo(s)(c.bgColor)(),Eo(s)(c.dotColor)(),s.ops.push(c.tile),s.ops.push(c.dotRadius),s.ops.push(c.origin.x),s.ops.push(c.origin.y),u);continue}g()}return i},i3=t=>e=>e.type==="metrics"?r3(e.value):e.type==="render"?o3(t)(e.value):z_("Data.Functor.Variant: pattern match failure ["+e.type+"]"),s3=t=>{const e=n3();return t3(i3(e))(t)(),{ops:e.ops,paths:e.paths,strs:e.strs}},a3=t=>t,_s=t=>t,kg=_s("Light"),u3=_s("Dark"),c3=_s("Blueprint"),g3=_s("Whiteboard"),_3=_s("Isometric"),f3=a3("TransparentBackground"),no=t=>"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")",pr=$o(Oo("Fixed",Ho(0)(20)(4))),d3=t=>"translate("+pr(t.tx)+","+pr(t.ty)+") scale("+pr(t.sx)+","+pr(t.sy)+")",It=$o(Oo("Fixed",Ho(0)(20)(2))),Lg=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,o=r>=0&&r<t.length?N("Just",t[r]):J;if(o.tag==="Nothing"){n=t.length;continue}if(o.tag==="Just"){if(o._1===1){e.push("M"),e.push(It((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{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(It((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{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(It((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{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(It((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+4|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+5|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{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 ur(" ")(e)},l3={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},Sg=(()=>{const t=Mn("&")("&"),e=Mn("<")("<"),n=(()=>{const r=Mn(">")(">"),o=(()=>{const i=Mn('"')(""");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),h3=t=>{if(t.style==="RunText")return"<tspan>"+Sg(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+Sg(t.text)+"</tspan>";g()},He=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},p3=t=>e=>{const n=[];let r=0;const o=i=>{const s=i>=0&&i<e.length?t.sx*e[i]+t.tx:t.sx*0+t.tx;return()=>{n.push(s),n.push((()=>{const a=i+1|0;return a>=0&&a<e.length?t.sy*e[a]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const i=r,s=i>=0&&i<e.length?N("Just",e[i]):J;if(s.tag==="Nothing"){r=e.length;continue}if(s.tag==="Just"){if(s._1===1){n.push(s._1),o(i+1|0)(),r=i+3|0;continue}if(s._1===2){n.push(s._1),o(i+1|0)(),r=i+3|0;continue}if(s._1===3){n.push(s._1),o(i+1|0)(),o(i+3|0)(),r=i+5|0;continue}if(s._1===4){n.push(s._1),o(i+1|0)(),o(i+3|0)(),o(i+5|0)(),r=i+7|0;continue}if(s._1===5){n.push(s._1),r=i+1|0;continue}r=e.length;continue}g()}return n},Ga=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return p3(r._1)(e);g()}},Ul={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),s=o();return i(s)}},Functor0:()=>l3},m3={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>Ul},y3={pure:t=>e=>()=>t,Apply0:()=>Ul},Xl={Applicative0:()=>y3,Bind1:()=>m3},x3=t=>e=>'<defs><pattern id="'+t+'" x="'+It(e.origin.x)+'" y="'+It(e.origin.y)+'" width="'+It(e.tile)+'" height="'+It(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+It(e.tile)+'" height="'+It(e.tile)+'" fill="'+no(e.bgColor)+'" fill-opacity="'+It(nt(e.bgColor.a)/255)+'"/>')+'<circle cx="'+It(e.tile/2)+'" cy="'+It(e.tile/2)+'" r="'+It(e.dotRadius)+'" fill="'+no(e.dotColor)+'"/></pattern></defs><rect x="'+It(e.viewport.vx)+'" y="'+It(e.viewport.vy)+'" width="'+It(e.viewport.vw)+'" height="'+It(e.viewport.vh)+'" fill="url(#'+t+')"/>',Yl=t=>e=>'<path d="'+Lg(t)+'" fill="'+no(e)+'" fill-opacity="'+It(nt(e.a)/255)+'"/>',w3=t=>e=>n=>r=>'<rect x="'+It(t.x)+'" y="'+It(t.y)+'" width="'+It(t.w)+'" height="'+It(t.h)+'" rx="'+It(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+no(n._1.color)+'" fill-opacity="'+It(nt(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';g()})()+(()=>{if(r.tag==="Just")return' stroke="'+no(r._1.color)+'" stroke-opacity="'+It(nt(r._1.color.a)/255)+'" stroke-width="'+It(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()})()+"/>",Kl=t=>e=>'<path d="'+Lg(t)+'" fill="none" stroke="'+no(e.color)+'" stroke-opacity="'+It(nt(e.color.a)/255)+'" stroke-width="'+It(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()})()+'"/>',jl=t=>{const e=q1(po(t.content));return'<text x="'+It(t.x)+'" y="'+It(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="'+no(t.color)+'" fill-opacity="'+It(nt(t.color.a)/255)+'" font-size="'+It(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+ie(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";g()})()+'">'+(e.length===1&&e[0].style==="RunText"?Sg(e[0].text):ur("")(O(h3)(e)))+"</text>"},J3=t=>"matrix("+pr(t.a)+" "+pr(t.b)+" "+pr(t.c)+" "+pr(t.d)+" "+pr(t.e)+" "+pr(t.f)+")",Zl={fillPath:t=>e=>n=>{const r=Ga(n)(t);return()=>{const o=r();return He(Yl(o)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=Ga(n)(t);return()=>{const o=r(),i=n.bake.value;return He(Kl(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=Ga(r)(t);return()=>{const i=o(),s=r.bake.value;return He(Yl(i)(e.color)+Kl(i)((()=>{if(s.tag==="Nothing")return n;if(s.tag==="Just")return{...n,width:s._1.sx*n.width};g()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>o=>{const i=o.bake;return()=>{const s=i.value;return He(w3((()=>{if(s.tag==="Nothing")return t;if(s.tag==="Just")return{x:s._1.sx*t.x+s._1.tx,y:s._1.sy*t.y+s._1.ty,w:s._1.sx*t.w,h:s._1.sy*t.h};g()})())((()=>{if(s.tag==="Nothing")return e;if(s.tag==="Just")return s._1.sx*e;g()})())(n)(r.tag==="Just"?N("Just",(()=>{if(s.tag==="Nothing")return r._1;if(s.tag==="Just")return{...r._1,width:s._1.sx*r._1.width};g()})()):J))(o)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return He(jl((()=>{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=>He((()=>{const n='transform="'+J3(t)+'"';return(n===""?"<g>":"<g "+n+">")+jl(e)+"</g>"})()),pushTransform:t=>He((()=>{const e='transform="'+d3(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:He("</g>"),pushBakedTransform:t=>e=>{const n=e.bake;return()=>{n.value=N("Just",t)}},popBakedTransform:t=>{const e=t.bake;return()=>{e.value=J}},pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const o=r.value;n.clipCounter.value=o+1|0;const i=Ga(n)(t)(),s="clip"+ie(o);return He((()=>{const a='clip-path="url(#'+s+')"';return'<defs><clipPath id="'+s+'"><path d="'+Lg(i)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";g()})()+"/></clipPath></defs>"+(a===""?"<g>":"<g "+a+">")})())(n)()}},popClip:He("</g>"),pushBlend:t=>He((()=>{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:He("</g>"),pushAlpha:t=>He((()=>{const e='opacity="'+It(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:He("</g>"),pushBlur:t=>e=>{if(t<.01)return He("<g>")(e);const n=e.patternCounter;return()=>{const r=n.value;e.patternCounter.value=r+1|0;const o="lvl-blur-"+ie(r);return He((()=>{const i='filter="url(#'+o+')"';return'<defs><filter id="'+o+'" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="'+It(t)+'"/></filter></defs>'+(i===""?"<g>":"<g "+i+">")})())(e)()}},popBlur:He("</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=>He('<rect x="'+It(e.viewport.vx)+'" y="'+It(e.viewport.vy)+'" width="'+It(e.viewport.vw)+'" height="'+It(e.viewport.vh)+'" fill="'+no(t)+'" opacity="'+It(nt(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,He(x3("bg-dots-"+ie(r))(t))(e)()}},measureText:t=>e=>n=>{const r=Fc(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Qc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Oc,Monad0:()=>Xl},N3=Ql(Zl),T3=hg(Xl)(Zl.measureText),v3=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},s=xi(i)(o);return{viewBox:It(s.vx)+" "+It(s.vy)+" "+It(s.vw)+" "+It(s.vh),body:(()=>{const a=[],u={value:0},c={value:0},_={value:0},d={value:J};return N3(Tg(i)(e)(o))({out:a,maskDepth:u,clipCounter:c,patternCounter:_,viewport:s,bake:d})(),ur("")(a)})(),vx:s.vx,vy:s.vy,vw:s.vw,vh:s.vh}},C3=t=>e=>n=>r=>o=>i=>{const s={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;g()})(),outputAspect:t},a=Rc(o)((()=>{const u=[],c={value:0},_={value:0},d={value:0},l={value:J},f=r.levels.length-1|0;if(f>=0&&f<r.levels.length){const h=Jg(xi(s)(r))(r.levels[f]);return T3(h)(r.levels[f].segment.layout)(r.levels[f].state)({out:u,maskDepth:c,clipCounter:_,patternCounter:d,viewport:h,bake:l})()}return I})())(i);return{parts:v3(t)(a.applied)(e)(n)(r),springs:a.springs}},b3=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()},ze=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Bn=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},th=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},eh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Pa=pu(vi),nh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},k3=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},rh=(()=>{const t=nn.unfoldr(Qn);return e=>t(rn("IterNode",e,Fn))})(),L3=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},mr=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},S3=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},E3=t=>t,oh=t=>e=>n=>n<t?0:n>1-e?1:(n-t)/ze(.05)(1-t-e),G3=t=>e=>t.labelBasePx*.62*nt(T(th)(0)(O(lf)(St(e)(n=>Sr(`
|
|
10
|
+
`)(n))))),ih=t=>e=>{if(t.length===0)return e;const n=6.82*nt(T(th)(0)(O(lf)(St(t)(_=>Sr(`
|
|
11
|
+
`)(_))))),r=n/2+14,o=e.y+e.h/2,i=o-5-8,s=ze(e.y+e.h)(i+12.6)-Bn(e.y)(i-12.6),a=e.x+e.w/2,u=a+13+n/2,c=ze(e.x+e.w)(u+r)-Bn(e.x)(u-r);return{x:a-c/2,y:o-s/2,w:c,h:s}},Eg=(()=>{const t=T(e=>n=>{const r=e.previous.tag==="Just"&&Qe(e.previous._1.endT-n.startT)<1e-4?{...n,fromCam:e.previous._1.toCam}:n;return{previous:N("Just",r),spans:kt(e.spans)(r)}})({previous:J,spans:[]});return e=>t(e).spans})(),Gg=t=>e=>{const n=eh(e)(t.keyframes);if(n.tag==="Nothing")return I;if(n.tag==="Just")return n._1.nodes;g()},sh=t=>e=>{if(e<t.startT)return zn("AtKeyframe",t.initialKeyframe);const n=re(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);g()}if(n.tag==="Nothing")return zn("AtKeyframe",T(b3)(t.initialKeyframe)(t.spans));g()},P3=t=>e=>n=>r=>{const o=re(i=>Pa(i.path)(e)&&(Qe(i.endT-n)<1e-4||Qe(i.startT-r)<1e-4))(t.segments);if(o.tag==="Just")return N("Just",o._1);if(o.tag==="Nothing")return re(i=>Pa(i.path)(e))(t.segments);g()},Pg=t=>e=>{const n=eh(e)(t.keyframes);if(n.tag==="Nothing")return I;if(n.tag==="Just")return n._1.edges;g()},ah=(()=>{const t=(n,r,o,i,s)=>{let a=n,u=r,c=o,_=i,d=s,l=!0,f;for(;l;){if(a===0){const h=Ft(p=>J,p=>m=>N("Just",{head:p,tail:m}),u);if(h.tag==="Nothing"){l=!1,f=[];continue}if(h.tag==="Just"){a=1,u=h._1.head,c=h._1.head,_=!1,d=h._1.tail;continue}g()}if(a===1){const h=u,p=c,m=_,w=d,y=Ft(x=>J,x=>v=>N("Just",{head:x,tail:v}),w);if(y.tag==="Just"&&p.intent==="Overview"&&y._1.head.intent==="Overview"&&!(p.fromCam.zoom===p.toCam.zoom&&p.fromCam.center.x===p.toCam.center.x&&p.fromCam.center.y===p.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)&&Qe(p.toCam.center.x-y._1.head.fromCam.center.x)<1e-4&&Qe(p.toCam.center.y-y._1.head.fromCam.center.y)<1e-4&&Qe(p.toCam.zoom-y._1.head.fromCam.zoom)<1e-4&&Qe(p.endT-y._1.head.startT)<1e-4){a=1,u=h,c=y._1.head,_=!0,d=y._1.tail;continue}l=!1,f=[m?{...h,endT:p.endT,toCam:p.toCam,easing:p.easing,interp:ar}:h,...e(w)]}}return f},e=n=>t(0,n);return e})(),B3=t=>e=>{const n=he(e),r=El({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}},uh=t=>e=>n=>r=>{const o=ze(n.center.x-r.x)(r.x+r.w-n.center.x),i=ze(n.center.y-r.y)(r.y+r.h-n.center.y),s=B3(t)(e);return Bn(o<=0?n.zoom:s.w/(o*2))(i<=0?n.zoom:s.h/(i*2))},ch=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r,u=Cr(a);if(u.tag==="Just"&&u._1.last.intent==="Overview"){n=[u._1.last,...s],r=u._1.init;continue}o=!1,i={prefix:a,overview:s}}return i},D3=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r,u=Ft(c=>J,c=>_=>N("Just",{head:c,tail:_}),a);if(u.tag==="Just"&&u._1.head.intent==="Overview"){n=kt(s)(u._1.head),r=u._1.tail;continue}o=!1,i={overview:s,rest:a}}return i},ro=t=>e=>n=>r=>o=>{const i={width:e.widthPx,height:e.heightPx},s=El(i)((()=>{const a=Xr(n)(o);return{vx:a.x,vy:a.y,vw:a.w,vh:a.h}})());return t.labelBasePx*r.placement.scale*(i.width<=0||s.vw<=0?0:i.width/s.vw)},R3=t=>e=>n=>r=>o=>{const i=ro(t)(e)(n)(r)(o);return i<=t.minimumReadableLabelPx?o:{...o,zoom:o.zoom*t.minimumReadableLabelPx/i}},A3=t=>e=>n=>{const r=Tt(o=>o.scene.tag==="StepScene"?N("Just",o.startT):J)(e.spans);return T(o=>i=>{const s=vr(Ut,J,a=>a.startT<i+1e-4&&a.endT>=i-1e-4,o);if(s.tag==="Nothing")return o;if(s.tag==="Just"){const a=s._1>=0&&s._1<o.length?N("Just",o[s._1]):J;if(a.tag==="Nothing")return o;if(a.tag==="Just"){if(a._1.startT>=i-1e-4)return o;const u=re(p=>p>i+1e-4)(r),c=(()=>{if(u.tag==="Nothing")return e.endT;if(u.tag==="Just")return u._1;g()})(),_=Pt(ot.compare)(Tt(p=>p.startT>=i-1e-4&&p.startT<c-1e-4&&(p.target.tag==="EdgeWindow"?p.target._2.tag==="Extend":p.target.tag==="TokenWindow"||p.target.tag==="FillWindow")?N("Just",p.startT):J)(e.windows)),d=0<_.length?_[0]:i,l=s._1+1|0,f=l<1?o:Bt(l,o.length,o),h=vr(Ut,J,p=>p.intent==="ActionFocus"&&p.startT>=d-1e-4&&p.startT<c-1e-4,f);if(h.tag==="Nothing")return o;if(h.tag==="Just"){const p=h._1>=0&&h._1<f.length?N("Just",f[h._1]):J;if(p.tag==="Nothing")return o;if(p.tag==="Just"){const m=(s._1+h._1|0)+2|0,w=m<1?o:Bt(m,o.length,o),y=a._1.toCam.zoom===p._1.toCam.zoom&&a._1.toCam.center.x===p._1.toCam.center.x&&a._1.toCam.center.y===p._1.toCam.center.y?a._1.fromCam:a._1.toCam,x=kt(s._1<1?[]:Bt(0,s._1,o))({...a._1,endT:i,toCam:y}),v=p._1.startT-i;if(v<=1e-4)return[...x,{...p._1,fromCam:y},...w];const C=y.zoom===p._1.toCam.zoom&&y.center.x===p._1.toCam.center.x&&y.center.y===p._1.toCam.center.y,L=C?i+0:i+Bn(v)(Vu(t)(y)(p._1.toCam)),E={...p._1,startT:L,endT:p._1.startT,fromCam:p._1.toCam,toCam:p._1.toCam},B={...p._1,startT:i,endT:L,fromCam:y};return[...x,...C?[]:[B],...E.endT>E.startT+1e-4?[E]:[],{...p._1,fromCam:p._1.toCam},...w]}}}}g()})(n)(r)},I3=t=>e=>n=>r=>({...r,fromCam:gf(t)(e)(n)(r.fromCam),toCam:gf(t)(e)(n)(r.toCam)}),gh=t=>e=>t.widthPx<=0?0:Bn(e/4)(32*e/t.widthPx),F3=t=>e=>n=>r=>o=>{const i=gh(e)(n),s=r+n/2-i;return o.x<r-n/2+i?o.x-i+n/2:o.x+o.w>s?o.x+o.w+i-n/2:r},Q3=t=>e=>n=>xe(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),M3=t=>e=>n=>xe(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),z3=t=>e=>n=>xe(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),W3=t=>e=>n=>xe(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),Ba=t=>e=>n=>xe(r=>n(r)&&e>=r.startT&&e<r.endT,t),q3=t=>e=>n=>{if(e.length===0)return n;const r=Bn(160)(G3(t)(e)+31)/2,o=Bn(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}},O3=t=>e=>n=>{const r=t.padding*.75,o=nt(8);return ys(i=>{if(i.target.tag==="NodeWindow")return[];if(i.target.tag==="EdgeWindow"){if(i.target._2.tag==="Extend")return[{startT:i.startT,endT:i.endT,bbox:Bs(e)(n)(i.target._1),priority:1}];if(i.target._2.tag==="Retract")return[];g()}if(i.target.tag==="TokenWindow"){const s=nh(i.target._2)(e.edges);if(s.tag==="Just"){const a=(()=>{if(i.target._3==="Forward")return s._1;if(i.target._3==="Backward")return se(s._1);g()})();return St(Kt(0,7))(u=>{const c=i.startT+(i.endT-i.startT)*(nt(u)/o),_=(()=>{const d=i.startT+(i.endT-i.startT)*(nt(u+1|0)/o);return{startT:c,endT:d,box:(()=>{const l=lo(a)(oh(i.target._7)(i.target._8)(((c+d)/2-i.startT)/ze(1e-4)(i.endT-i.startT)));if(l.tag==="Just")return{x:l._1.x-r,y:l._1.y-r,w:0+r*2,h:0+r*2};if(l.tag==="Nothing")return{x:0,y:0,w:0,h:0};g()})()}})();return[{startT:_.startT,endT:_.endT,bbox:ih(i.target._6)(_.box),priority:1}]})}if(s.tag==="Nothing")return[{startT:i.startT,endT:i.endT,bbox:ih(i.target._6)(Bs(e)(n)(i.target._2)),priority:1}];g()}if(i.target.tag==="FillWindow")return[{startT:i.startT,endT:i.endT,bbox:q3(t)(i.target._3)(Ou(e)(n)(te("Node",1,1,i.target._2,void 0,I,I))),priority:1}];g()})},H3=t=>e=>n=>r=>o=>i=>{if(o.tag==="Nothing")return i.zoom;if(o.tag==="Just")return ze(0)(uh(e)(n)(i)((()=>{const s=t.padding*r.placement.scale;return{x:o._1.x-s,y:o._1.y-s,w:o._1.w+s*2,h:o._1.h+s*2}})()));g()},$3=t=>e=>n=>r=>o=>{const i=s=>{const a=ro(t)(e)(n)(r)(s);return a<=0||a>=t.minimumReadableLabelPx?s:{...s,zoom:s.zoom*t.minimumReadableLabelPx/a}};return{...o,fromCam:i(o.fromCam),toCam:i(o.toCam)}},V3=t=>e=>{const n=sh(t)(e);if(n.tag==="AtKeyframe")return Gg(t)(n._1);if(n.tag==="InTransition")return Me(P.compare,Ie,Gg(t)(n._1),Gg(t)(n._2));g()},U3=t=>e=>n=>Ba(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n&&r.target._2==="PlopOut")?!0:M3(t.windows)(e)(n)?!1:Ba(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n)?!0:z3(t.windows)(e)(n)?!1:k3(n)(V3(t)(e)),_h=t=>e=>Tt(n=>U3(t)(e)(n._1)?N("Just",{x:n._2.x,y:n._2.y,w:n._2.w,h:n._2.h}):J)(rh(t.layout.nodes)),X3=t=>e=>{const n=_h(t)(e);return n.length===0?J:N("Just",sr(n))},Y3=t=>Tt(e=>{const n=X3(t)(ze(e.startT)(e.endT-1e-4));if(n.tag==="Nothing")return J;if(n.tag==="Just")return N("Just",{startT:e.startT,endT:e.endT,bbox:n._1,priority:0});g()}),K3=t=>e=>n=>r=>o=>[...Y3(o)(ft(i=>i.startT>=o.startT&&i.endT<=o.endT,r.spans)),...O3(t)(o.layout)(n)(o.windows)],j3=t=>e=>n=>r=>o=>i=>X2(t)(e)(i.layout)(o.endT)(Tt(s=>s.scene.tag==="StepScene"?N("Just",s.startT):J)(i.spans))(K3(t)(n)(r)(o)(i)),Z3=t=>e=>{const n=sh(t)(e);if(n.tag==="AtKeyframe")return Pg(t)(n._1);if(n.tag==="InTransition")return Me(P.compare,Ie,Pg(t)(n._1),Pg(t)(n._2));g()},tk=t=>e=>n=>Ba(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n)?!0:Q3(t.windows)(e)(n)?!1:Ba(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._1===n)?!0:W3(t.windows)(e)(n)?!1:L3(n)(Z3(t)(e)),ek=t=>e=>{const n=[..._h(t)(e),...Tt(r=>tk(t)(e)(r._1)?N("Just",qu(r._2)):J)(rh(t.layout.edges))];return n.length===0?J:N("Just",sr(n))},nk=t=>e=>n=>{const r=Xr(t)(n);return e.x>=r.x&&e.x+e.w<=r.x+r.w},rk=t=>e=>n=>r=>o=>i=>s=>{if(o.tag==="Nothing")return s;if(o.tag==="Just"){const a={x:o._1.x-t.padding,y:o._1.y-t.padding,w:o._1.w+t.padding*2,h:o._1.h+t.padding*2},u={x:a.x+a.w/2,y:a.y+a.h/2},c={...s,center:u},_={...c,zoom:uh(e)(n)(c)(a)},d=ro(t)(e)(n)(r)(_),l=d<=0||d>=t.minimumReadableLabelPx?_:{..._,zoom:_.zoom*t.minimumReadableLabelPx/d},f=Xr(n)(l);return i.tag==="Nothing"?{...l,center:{x:f.w>=o._1.w?o._1.x+o._1.w/2:mr(o._1.x+f.w/2)(o._1.x+o._1.w-f.w/2)(u.x),y:f.h>=o._1.h?o._1.y+o._1.h/2:mr(o._1.y+f.h/2)(o._1.y+o._1.h-f.h/2)(u.y)}}:i.tag==="Just"?{...l,center:{x:f.w>=o._1.w?o._1.x+o._1.w/2:mr(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:mr(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()},fh=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=ze(o.lo)(e.x+e.w-n/2),c=Bn(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=ze(o.lo)(i),c=Bn(o.hi)(i);return u<=c?{lo:u,hi:c}:o}const s=ze(o.lo)(e.x+n/2),a=Bn(o.hi)(e.x+e.w-n/2);return s<=a?{lo:s,hi:a}:o},ok=t=>e=>n=>n.endT<=t||n.startT>=e?J:N("Just",{...n,startT:ze(t)(n.startT),endT:Bn(e)(n.endT)}),dh=t=>e=>n=>r=>o=>i=>Tt(ok(i.startT)(i.endT))(O(I3(n)(i.layout)(i.placement))(j3(t)(e)(r)(i.edgeEndpoints)(o)(i))),lh=t=>e=>n=>r=>{const o=he(t),i=Bn(r.zoom)(o.w/ze(1e-4)(e.w));return{...r,center:{...r.center,x:(()=>{const s=fh(o)(e)(o.w/ze(1e-4)(i));return mr(s.lo)(s.hi)(n.center.x)})()},zoom:i}},ik=t=>e=>n=>r=>o=>i=>s=>a=>{const u=gh(e)(a),c=he(n),_={x:c.x-u,y:c.y-u,w:c.w+u*2,h:c.h+u*2},d=(()=>{if(o.tag==="Nothing")return s.center.x;if(o.tag==="Just")return F3()(e)(a)(i.center.x)(o._1);g()})();if(r.tag==="Nothing"){const l=_.x+_.w/2;return a>=_.w?mr(l)(l)(d):mr(_.x+a/2)(_.x+_.w-a/2)(d)}if(r.tag==="Just"){const l={x:r._1.x-u,y:r._1.y-u,w:r._1.w+u*2,h:r._1.h+u*2};if(a<l.w){const h=_.x+_.w/2;return a>=_.w?mr(h)(h)(d):mr(_.x+a/2)(_.x+_.w-a/2)(d)}const f=fh(_)(l)(a);return mr(f.lo)(f.hi)(d)}g()},sk=t=>e=>n=>r=>o=>i=>s=>{const a=Xr(n)(s);return a.w<=0?s:{...s,center:{...s.center,x:ik()(e)(n)(r)(o)(i)(s)(a.w)}}},hh=t=>e=>n=>r=>a2(t)(e)(n)(r.layout)(r.placement)((()=>{if(r.layout.nodes.tag==="Leaf")return 0;if(r.layout.nodes.tag==="Node")return r.layout.nodes._2;g()})()).camera,ph=t=>e=>n=>r=>o=>{const i=Xr(n)(o);return(()=>{const s=he(r.layout),a=s.x*r.placement.scale+r.placement.tx,u=s.y*r.placement.scale+r.placement.ty;return a>=i.x&&u>=i.y&&a+s.w*r.placement.scale<=i.x+i.w&&u+s.h*r.placement.scale<=i.y+i.h})()&&ro(t)(e)(n)(r)(o)>=t.minimumReadableLabelPx},Bg=t=>e=>n=>r=>o=>i=>ph(t)(e)(n)(r)(o)?o:R3(t)(e)(n)(r)(i),ak=t=>e=>n=>{const r=D3([])(n),o=Ft(s=>J,s=>a=>N("Just",{head:s,tail:a}),r.rest),i=r.overview.length-1|0;return i>=0&&i<r.overview.length&&0<r.overview.length&&o.tag==="Just"&&Qe(r.overview[0].startT-e.startT)<1e-4&&o._1.head.intent==="ActionFocus"?[{startT:r.overview[0].startT,endT:r.overview[i].endT,fromCam:t,toCam:t,easing:r.overview[0].easing,interp:ar,intent:sf},{...o._1.head,fromCam:t},...o._1.tail]:n},uk=t=>e=>{const n=Ft(r=>J,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()},ck=t=>e=>{const n=o=>i=>s=>{let a=o,u=i,c=s,_=!0,d;for(;_;){const l=a,f=u,h=Ft(p=>J,p=>m=>N("Just",{head:p,tail:m}),c);if(h.tag==="Nothing"){_=!1,d=kt(l)(f);continue}if(h.tag==="Just"){if(f.intent==="Overview"&&h._1.head.intent==="ActionFocus"&&Qe(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 p=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)&&xe(m=>Qe(m.startT-p)<1e-4&&(m.target.tag==="EdgeWindow"?m.target._2.tag==="Extend":m.target.tag==="TokenWindow"||m.target.tag==="FillWindow"),t.windows)})()){const p=h._1.head.startT,m=Pt(ot.compare)(Tt(v=>v.target.tag==="EdgeWindow"&&v.target._2.tag==="Extend"&&Qe(v.endT-p)<1e-4?N("Just",v.startT):J)(t.windows)),w=0<m.length?m[0]:p,y=ze(f.startT)(w-(h._1.head.endT-h._1.head.startT)),x={...f,endT:y};a=kt(x.endT>x.startT?kt(l)(x):l)({...h._1.head,startT:y,endT:w}),u={...h._1.head,startT:w,fromCam:h._1.head.toCam},c=h._1.tail;continue}a=kt(l)(f),u=h._1.head,c=h._1.tail;continue}g()}return d},r=Ft(o=>J,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()},gk=t=>e=>n=>r=>o=>i=>{const s=he(r.layout),a={x:s.x*r.placement.scale+r.placement.tx,y:s.y*r.placement.scale+r.placement.ty,w:s.w*r.placement.scale,h:s.h*r.placement.scale},u=lh(n)(a)(o)(i);return a.w/ze(1e-4)(a.h)>=.33&&i.zoom/ze(1e-4)(u.zoom)<=1.25&&Xr(n)(u).w>=a.w-.001&&ro(t)(e)(n)(r)(u)>=t.minimumReadableLabelPx*.85?u:i},_k=t=>e=>n=>r=>o=>i=>s=>{const a=he(r.layout),u=a.w*r.placement.scale,c=u/ze(1e-4)(a.h*r.placement.scale);if(o.tag==="Nothing")return s;if(o.tag==="Just"){if(nk(n)(o._1)(s))return s;const _=lh(n)(o._1)(i)(s);return s.zoom/ze(1e-4)(_.zoom)<=1.25&&(ro(t)(e)(n)(r)(_)>=t.minimumReadableLabelPx-.001||o._1.w>=u-.001&&c>=.33&&ro(t)(e)(n)(r)(_)>=t.minimumReadableLabelPx*.85)?_:s}g()},fk=t=>e=>n=>r=>o=>i=>s=>{const a={...s,center:(()=>{if(i.tag==="Nothing")return s.center;if(i.tag==="Just")return{x:i._1.x+i._1.w/2,y:i._1.y+i._1.h/2};g()})()},u=ro(t)(e)(n)(r)(a);return sk()(e)(n)(o)(i)(s)(_k(t)(e)(n)(r)(o)(s)(gk(t)(e)(n)(r)(s)(u<=0?a:{...a,zoom:Bn(a.zoom*t.minimumReadableLabelPx/u)(H3(t)(e)(n)(r)(i)(a))})))},Dg=t=>e=>n=>r=>o=>i=>s=>r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?rk(t)(e)(n)(r)(o)(i)(s):ph(t)(e)(n)(r)(s)?s:fk(t)(e)(n)(r)(o)(i)(s),mh=t=>{const e=n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=i,_=Ft(d=>J,d=>l=>N("Just",{head:d,tail:l}),c);if(_.tag==="Just"&&_._1.head.intent==="Overview"){o=kt(u)(_._1.head),i=_._1.tail;continue}s=!1,a={overview:u,rest:c}}return a};return(n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=Ft(_=>J,_=>d=>N("Just",{head:_,tail:d}),i);if(c.tag==="Nothing"){s=!1,a=u;continue}if(c.tag==="Just"){if(c._1.head.intent==="Overview"){const _=e([c._1.head])(c._1.tail),d=Ft(h=>J,h=>p=>N("Just",{head:h,tail:p}),_.rest),l=u.length-1|0,f=l>=0&&l<u.length?N("Just",u[l]):J;if(f.tag==="Just"&&d.tag==="Just"&&f._1.intent==="ActionFocus"&&(()=>{const h=_.overview.length-1|0;return d._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=kt(u)({startT:_.overview[0].startT,endT:_.overview[h].endT,fromCam:f._1.toCam,toCam:f._1.toCam,easing:_.overview[0].easing,interp:ar,intent:As}),i=[{...d._1.head,fromCam:f._1.toCam},...d._1.tail];continue}}o=[...u,..._.overview],i=_.rest;continue}o=kt(u)(c._1.head),i=c._1.tail;continue}g()}return a})([])(t)},dk=t=>e=>n=>{const r=ch([])(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"&&Qe(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:ar,intent:As}]}return n}return 0<r.overview.length&&r.prefix.length-1|0,n},yh=t=>e=>n=>{const r=ch([])(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 s=r.overview[o].endT;return r.prefix[i].intent==="ActionFocus"&&(()=>{const a=r.overview.length-1|0;return xe(u=>u.direction==="DiveIn"&&Pa(u.parentPath)(t.path)&&Qe(u.startT-s)<1e-4,e)&&(a>=0&&a<r.overview.length&&0<r.overview.length?r.overview[a].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:ar,intent:As}]}return n}return n},lk=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=Tt(o=>o.target.tag==="EdgeWindow"?o.target._2.tag==="Extend"?N("Just",Bs(t.layout)(t.edgeEndpoints)(o.target._1)):J:o.target.tag==="TokenWindow"?N("Just",(()=>{const i=[...Tt(s=>{const a=S3(s)(t.layout.nodes);return a.tag==="Just"?N("Just",{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}):J})([o.target._4,o.target._5]),...(()=>{const s=nh(o.target._2)(t.layout.edges),a=oh(o.target._7)(o.target._8)((n-o.startT)/ze(1e-4)(o.endT-o.startT)),u=(()=>{if(s.tag==="Just")return lo((()=>{if(o.target._3==="Forward")return s._1;if(o.target._3==="Backward")return se(s._1);g()})())(a);if(s.tag==="Nothing")return J;g()})();return u.tag==="Just"?[{x:u._1.x,y:u._1.y,w:0,h:0}]:[]})()];return i.length===0?Bs(t.layout)(t.edgeEndpoints)(o.target._2):sr(i)})()):o.target.tag==="FillWindow"?N("Just",Ou(t.layout)(t.edgeEndpoints)(te("Node",1,1,o.target._2,void 0,I,I))):J)(ft(o=>o.startT<=n&&n<o.endT,t.windows));return r.length===0?J:N("Just",(()=>{const o=sr(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}})())},hk=t=>e=>{const n=ek(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}):J},xh=t=>e=>n=>r=>o=>i=>{const s=o(i.fromCam),a=o(i.toCam),u=lk(r)(i),c=hk(r)(i);return s.zoom===a.zoom&&s.center.x===a.center.x&&s.center.y===a.center.y?{...i,fromCam:Dg(t)(e)(n)(r)(c)(u)(s),toCam:Dg(t)(e)(n)(r)(c)(u)(a)}:{...i,fromCam:s,toCam:Dg(t)(e)(n)(r)(c)(u)(a)}},wh=t=>e=>n=>r=>o=>i=>i.intent==="ActionFocus"?xh(t)(e)(n)(r)(Bg(t)(e)(n)(r)(o))(i):{...i,fromCam:Bg(t)(e)(n)(r)(o)(i.fromCam),toCam:Bg(t)(e)(n)(r)(o)(i.toCam)},Jh=t=>e=>n=>r=>o=>i=>{const s=re(a=>a.intent==="ActionFocus"&&a.startT>=r.startT-1e-4)(i);if(s.tag==="Just"){const a=wh(t)(e)(n)(r)(o)(s._1).toCam;return{...o,center:a.center,zoom:a.zoom<o.zoom?a.zoom:o.zoom}}if(s.tag==="Nothing")return o;g()},pk=t=>e=>n=>r=>o=>Jh(t)(e)(n)(r)(hh(t)(e)(n)(r))(o),mk=t=>e=>n=>r=>o=>o.intent==="ActionFocus"?xh(t)(e)(n)(r)(E3)(o):o,Da=t=>e=>n=>r=>o=>i=>Eg(O($3(t)(e)(n)(i))(A3(t)(i)(ck(i)((()=>{const s=dh(t)(e)(n)(r)(o)(i);if(i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0)return yh(i)(o.dives)(mh(ah(Eg(O(mk(t)(e)(n)(i))(s)))));const a=hh(t)(e)(n)(i),u=Jh(t)(e)(n)(i)(a)(s);return s.length===0?[{startT:i.startT,endT:i.endT,fromCam:u,toCam:u,easing:ef,interp:ar,intent:sf}]:dk()(i)(ak(u)(i)(yh(i)(o.dives)(mh(ah(Eg(uk(u)(O(wh(t)(e)(n)(i)(a))(s))))))))})())))),yk=t=>e=>n=>r=>o=>Pt(i=>s=>ot.compare(i.startT)(s.startT))(St(o.segments)(Da(t)(e)(n)(r)(o))),xk=t=>e=>n=>r=>o=>i=>s=>{if(i.direction==="DiveIn")return Ii(t)(n)(Da(t)(e)(n)(r)(o)(s))(i.startT-1e-4).camera;if(i.direction==="DiveOut")return Ii(t)(n)(Da(t)(e)(n)(r)(o)(s))(i.endT+1e-4).camera;g()},wk=t=>e=>n=>r=>o=>Tt(i=>{const s=P3(o)(i.parentPath)(i.startT)(i.endT);if(s.tag==="Just"){const a=i.childPath,u=re(c=>Pa(c.path)(a))(o.segments);if(u.tag==="Just"){const c=Da(t)(e)(n)(r)(o)(u._1),_=pk(t)(e)(n)(u._1)(dh(t)(e)(n)(r)(o)(u._1)),d=xk(t)(e)(n)(r)(o)(i)(s._1),l=(()=>{if(i.direction==="DiveIn")return _;if(i.direction==="DiveOut")return Ii(t)(n)(c)(i.startT-1e-4).camera;g()})();if(i.direction==="DiveIn")return N("Just",{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:Yr,interp:of,intent:af});if(i.direction==="DiveOut")return N("Just",{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:Yr,interp:of,intent:af});g()}if(u.tag==="Nothing")return J;g()}if(s.tag==="Nothing")return J;g()})(o.dives),Nh=t=>e=>n=>r=>o=>[...wk(t)(e)(n)(r)(o),...yk(t)(e)(n)(r)(o)],oo=(t,e)=>({tag:t,_1:e}),Ra=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Nn=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Th=ce(P)(zt),vh=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Ch=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},bh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},kh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},wi=(()=>{const t=nn.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return N("Just",b(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,Lt("Cons",r._3,n(r._6,o)));g()};return n(e,$)})())})(),Jk=T(t=>e=>rt(P)(e)()(t))(I),Rg=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Lh=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Nk=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Aa=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Tk=oo("NoKeyframes"),vk=t=>oo("DuplicateEventId",t),Ck=t=>oo("UnknownEvent",t),bk=t=>e=>({...e,cameraSpans:Nh(e.cameraConfig)(t)(e.layout)(e.keyframes)({endT:e.totalDuration,spans:e.spans,windows:e.windows,segments:e.segments,dives:e.dives})}),kk=t=>e=>n=>r=>{const o=Ra(r.edge)(e.edges),i=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return Bi(o._1);g()})(),s=Nn(t.minTokenDuration)(Nn(nt(T(a=>u=>a+Ko(u).length|0)(0)(r.labels))*t.tokenReadSecPerChar)(t.tokenSpeed<=0?0:i/t.tokenSpeed))+n.post;return{duration:s,holdPre:0,holdPost:s<=0?0:n.post/s}},Lk=ys(t=>{const e=Sr(`
|
|
12
|
+
`)(t);return e.length===0?[""]:e}),Sk=t=>e=>Th(Tt(n=>{if(n.kind.tag==="SendToken")return N("Just",b(n.id,{post:(()=>{const r=n.id;return(()=>{const o=n.kind._1.to;return xe(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 J;g()})(e)),Ek=t=>{if(t.event.kind.tag==="SendToken")return N("Just",{startT:t.startT,endT:t.endT,target:jo("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:jo("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},Gk=t=>Tt((()=>{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}):J})())(t.windows),Pk=t=>e=>n=>{const r=Ra(n)(t);if(r.tag==="Nothing")return xf;if(r.tag==="Just"){const o=vh(r._1.target)(e);return vh(r._1.source)(e)?o?dy:fy:xf}g()},Sh=t=>e=>{if(t.tag==="Just"&&t._1>e.endT+1e-4){const n=Nn(0)(e.endT-e.startT),r=Nn(e.startT)(t._1-n);return{...e,startT:r,endT:r+n}}return e},Eh=O(Ci),Bk={post:0},Dk=t=>e=>n=>r=>o=>{const i=Ch(o.event.id)(n),s=(()=>{if(i.tag==="Nothing")return Bk;if(i.tag==="Just")return i._1;g()})(),a=(()=>{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,_=re(d=>d.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,_=re(d=>d.event.id===c)(r);if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1.startT}g()})(),u=(()=>{if(o.event.kind.tag==="SendToken")return kk(t)(e)(s)(o.event.kind._1);if(o.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return kt(r)({startT:a,endT:a+u.duration,event:o.event,holdPre:u.holdPre,holdPost:u.holdPost})},Gh=t=>e=>n=>T(Dk(t)(e)(Sk(t)(n)))([])(Ht(r=>o=>({event:o}))(n)),Rk=t=>T(e=>n=>{const r=Cr(e);if(r.tag==="Nothing")return[n];if(r.tag==="Just")return n.startT<=r._1.last.endT+1e-4?kt(r._1.init)({...r._1.last,endT:Nn(r._1.last.endT)(n.endT)}):kt(e)(n);g()})([])(Pt(e=>n=>ot.compare(e.startT)(n.startT))(t)),Ak=t=>e=>{const n=bh(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},Ik=t=>e=>{const n=Pt(ot.compare)(Tt(r=>r.target.tag==="TokenWindow"?r.target._4===e||r.target._5===e?N("Just",r.startT):J:r.target.tag==="FillWindow"&&r.target._2===e?N("Just",r.startT):J)(t));return 0<n.length?N("Just",n[0]):J},Fk=t=>e=>{const n=Pt(ot.compare)(Tt(r=>r.target.tag==="TokenWindow"&&r.target._2===e?N("Just",r.startT):J)(t));return 0<n.length?N("Just",n[0]):J},Qk=t=>e=>e.target.tag==="NodeWindow"?e.target._2==="PlopIn"?Sh(Ik(t.windows)(e.target._1))(e):e:e.target.tag==="EdgeWindow"&&e.target._2.tag==="Extend"?Sh(Fk(t.windows)(e.target._1))(e):e,Mk=t=>({...t,windows:Pt(e=>n=>ot.compare(e.startT)(n.startT))(O(Qk(t))(t.windows))}),zk=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()},Ph={id:"",nodes:I,edges:I,kind:Di},Wk=t=>e=>l2((()=>{const n=kh(e.from)(t);if(n.tag==="Nothing")return Ph;if(n.tag==="Just")return n._1;g()})())((()=>{const n=kh(e.to)(t);if(n.tag==="Nothing")return Ph;if(n.tag==="Just")return n._1;g()})()),qk=t=>e=>{const n=bh(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:I};if(n.tag==="Just")return n._1;g()},Bh={id:"",index:-1,kind:"",name:"",time:0,endTime:0,path:[],tokenIndex:-1,lineIndex:-1,text:"",from:"",to:""},Ok=t=>e=>e.scene.tag==="StepScene"?N("Just",{...Bh,id:"step:"+e.scene._1,kind:"step",name:e.scene._1,time:e.startT,endTime:e.startT,path:Eh(t)}):J,Hk=t=>Tt(Ok(t.path))(t.spans),Ag=t=>e=>n=>r=>{const o=Ra(r)(n.edges);if(o.tag==="Just")return t<=0?e:Nn(e)(Bi(o._1)/t);if(o.tag==="Nothing")return e;g()},Dh=t=>e=>n=>r=>o=>{const i=t.plop,s=Wk(n)(o),a=O(f=>({startT:0,endT:0+Ag(t.edgeSpeed)(t.minEdgeDuration)(e)(f),target:jo("EdgeWindow",f,Qs("Extend",tc))}))(wi(s.entering.edges)),u=O(f=>({startT:0,endT:i,target:jo("NodeWindow",f,Yu)}))(wi(s.entering.nodes)),c=T(Nn)(0)(O(f=>Ag(t.edgeSpeed)(t.minEdgeDuration)(e)(f))(wi(s.leaving.edges))),_=f=>xe(h=>{const p=Ra(h)(r);if(p.tag==="Just")return p._1.source===f||p._1.target===f;if(p.tag==="Nothing")return!1;g()},wi(s.leaving.edges))?c:0,d=O(f=>({startT:_(f),endT:_(f)+t.plop,target:jo("NodeWindow",f,uy)}))(wi(s.leaving.nodes)),l=O(f=>({startT:0,endT:Ag(t.edgeSpeed)(t.minEdgeDuration)(e)(f),target:jo("EdgeWindow",f,Qs("Retract",Pk(r)(s.leaving.nodes)(f)))}))(wi(s.leaving.edges));return{duration:(()=>{const f=Pt(ot.compare)([...O(p=>p.endT)(l),...O(p=>p.endT)(d),...O(p=>p.endT)(u),...O(p=>p.endT)(a)]),h=f.length-1|0;return h>=0&&h<f.length?f[h]+t.gap:t.gap})(),windows:[...l,...d,...u,...a]}},$k=t=>e=>n=>r=>o=>i=>O((()=>{const s=o.startT;return a=>({...a,startT:a.startT+s,endT:a.endT+s})})())(Dh(t)(e)(n)(r)(i).windows),Vk=t=>Tt(e=>Zt(Io,e).length>1?N("Just",(()=>{const n=Ft(r=>J,r=>o=>N("Just",{head:r,tail:o}),Zt(Io,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):J)(z0(vi)(Pt(P.compare)(t))),Uk=t=>{const e=O(r=>r.id)(t),n=Jk(e);return[...O(vk)(Vk(e)),...O(Ck)(ft(r=>!Rg(r)(n),St(t)(zk)))]},Xk=t=>{const e=Th(O(r=>b(r.id,(()=>{if(r.when.tag==="First")return[];if(r.when.tag==="At")return[];if(r.when.tag==="After")return[r.when._1];if(r.when.tag==="With")return[r.when._1];g()})()))(t)),n=r=>o=>i=>{if(Rg(i)(o))return[oo("ScheduleCycle",[...Zt(fn.foldr,o),i])];if(Rg(i)(r))return[];const s=Ch(i)(e);if(s.tag==="Nothing")return[];if(s.tag==="Just")return St(s._1)(n(rt(P)(i)()(r))(rt(P)(i)()(o)));g()};return St(t)(r=>n(I)(I)(r.id))},Yk={plop:.5,gap:0,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:0,stillHold:1.8,hatchHold:0,tokenReadSecPerChar:.06,nodeEasing:v2,edgeEasing:Yr,tokenEasing:ef,diveDur:1.2,retreatDur:1.2},Kk=t=>e=>n=>r=>O((()=>{const o=n.startT;return i=>({...i,startT:i.startT+o,endT:i.endT+o})})())(Tt(Ek)(Gh(t)(e)(r.events))),jk=t=>e=>n=>r=>o=>{if(o.scene.tag==="Structural")return $k(t)(e)(n)(r)(o)(o.scene._1);if(o.scene.tag==="Hold")return[];if(o.scene.tag==="DataFlow")return Kk(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()},Zk=t=>e=>n=>{const r=Gh(t)(e)(n.events);return r.length===0?t.gap:T(Nn)(0)(O(o=>o.endT)(r))+t.gap},t5=t=>e=>n=>r=>o=>{if(o.tag==="Structural")return Dh(t)(e)(n)(r)(o._1).duration;if(o.tag==="Hold")return t.stillHold;if(o.tag==="DataFlow")return Zk(t)(e)(o._1);if(o.tag==="EnterNode"||o.tag==="ExitNode"||o.tag==="StepScene")return 0;g()},Rh=t=>e=>n=>r=>o=>i=>{const s=n2(e)(r),a=n.layout,u=j_(O(p=>b(p.id,p))(o.keyframes)),c=0<o.keyframes.length?N("Just",o.keyframes[0]):J,_=(()=>{if(c.tag==="Just")return c._1.id;if(c.tag==="Nothing")return"";g()})(),d=N2(o),l=p=>({segments:p.runSpans.length===0?p.segments:kt(p.segments)({startT:p.runStart,endT:p.t,path:r,layout:a,placement:s,windows:p.runWindows,spans:p.runSpans,keyframes:u,initialKeyframe:_,edgeEndpoints:d}),spans:p.spans,windows:p.windows,dives:p.dives}),f=T(p=>m=>{if(m.tag==="EnterNode"){const v=l(p),C=p.t+t.diveDur,L=kt(r)(m._1),E=Rh(t)(e)(qk(n)(m._1))(L)(Ak(o)(m._1))(C),B=E.endT+t.retreatDur;return{...p,t:B,runStart:B,runSpans:[],runWindows:[],segments:[...v.segments,...E.segments],spans:[...v.spans,...E.spans],windows:[...v.windows,...E.windows],dives:[...v.dives,{startT:p.t,endT:C,node:m._1,parentPath:r,childPath:L,direction:cy},...E.dives,{startT:E.endT,endT:B,node:m._1,parentPath:r,childPath:L,direction:gy}]}}if(m.tag==="ExitNode")return p;const w=p.t+t5(t)(a)(u)(d)(m),y={startT:p.t,endT:w,scene:m},x=jk(t)(a)(u)(d)(y);return{...p,t:w,runSpans:kt(p.runSpans)(y),runWindows:[...p.runWindows,...x],spans:kt(p.spans)(y),windows:[...p.windows,...x]}})({t:i,runStart:i,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(o.scenes),h=l(f);return{endT:f.t,spans:h.spans,windows:Pt(p=>m=>ot.compare(p.startT)(m.startT))(h.windows),segments:h.segments,dives:h.dives}},e5=t=>e=>{const n=ot.compare(t.time)(e.time);return n==="EQ"?P.compare(t.id)(e.id):n},Dn=t=>e=>e-T(n=>r=>n+Nn(0)(Lh(e)(r.endT)-r.startT))(0)(t),n5=t=>e=>{const n=Nn(t.startT)(e.startT),r=Lh(t.endT)(e.endT);return r>n+1e-4?N("Just",{startT:n,endT:r}):J},r5=t=>e=>{if(e.scene.tag==="Structural"){const n=T(r=>o=>({cursor:Nn(r.cursor)(o.endT),cuts:o.startT>r.cursor+1e-4?kt(r.cuts)({startT:r.cursor,endT:o.startT}):r.cuts}))({cursor:e.startT,cuts:[]})(Pt(r=>o=>ot.compare(r.startT)(o.startT))(Tt(n5(e))(t)));return e.endT>n.cursor+1e-4?kt(n.cuts)({startT:n.cursor,endT:e.endT}):n.cuts}return[]},o5=t=>{const e=Rk(St(t.spans)(r5(t.windows)));return e.length===0?t:{...t,endT:Dn(e)(t.endT),spans:O(n=>({...n,startT:Dn(e)(n.startT),endT:Dn(e)(n.endT)}))(t.spans),windows:Pt(n=>r=>ot.compare(n.startT)(r.startT))(O(n=>({...n,startT:Dn(e)(n.startT),endT:Dn(e)(n.endT)}))(t.windows)),segments:O(n=>({...n,startT:Dn(e)(n.startT),endT:Dn(e)(n.endT),spans:O(r=>({...r,startT:Dn(e)(r.startT),endT:Dn(e)(r.endT)}))(n.spans),windows:Pt(r=>o=>ot.compare(r.startT)(o.startT))(O(r=>({...r,startT:Dn(e)(r.startT),endT:Dn(e)(r.endT)}))(n.windows))}))(t.segments),dives:O(n=>({...n,startT:Dn(e)(n.startT),endT:Dn(e)(n.endT)}))(t.dives)}},i5=t=>{const e=O(Mk)(t.segments);return o5({...t,segments:e,windows:Pt(n=>r=>ot.compare(n.startT)(r.startT))(St(e)(n=>n.windows))})},s5=t=>e=>n=>{const r=Nn(.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=Lk(n),s=O(u=>nt(Nk(1)(Ko(u).length)))(i),a=Nn(1)(T(nr)(0)(s));return Ht(u=>c=>({lineIndex:u,text:c,start:o(T(nr)(0)(u<1?[]:Bt(0,u,s))/a),end:o(u>=0&&u<s.length?(T(nr)(0)(u<1?[]:Bt(0,u,s))+s[u])/a:(T(nr)(0)(u<1?[]:Bt(0,u,s))+1)/a)}))(i)},a5=t=>{const e=Nn(0)(t.window.endT-t.window.startT);return O(n=>({...Bh,id:"token:"+t.eventId+":line:"+ie(n.lineIndex),kind:"tokenLine",time:t.window.startT+n.start*e,endTime:t.window.startT+n.end*e,path:Eh(t.path),tokenIndex:t.tokenIndex,lineIndex:n.lineIndex,text:n.text,from:t.from,to:t.to}))(s5(t.holdPre)(t.holdPost)(t.labels))},u5=t=>St(Ht(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}))(St(t)(Gk)))(a5),c5=t=>Ht(e=>n=>({...n,index:e}))(Pt(e5)([...St(t.segments)(Hk),...u5(t.segments)])),g5=t=>e=>{if(e.tag==="Structural")return Tt(n=>n)([Aa(e._1.from)(t)?J:N("Just",oo("UnknownKeyframe",e._1.from)),Aa(e._1.to)(t)?J:N("Just",oo("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return Tt(n=>n)([Aa(e._1)(t)?J:N("Just",oo("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...Tt(n=>n)([Aa(e._1.keyframe)(t)?J:N("Just",oo("UnknownKeyframe",e._1.keyframe))]),...Uk(e._1.events),...Xk(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];if(e.tag==="StepScene")return[];g()},_5=t=>e=>{const n=St(e)(g5(t));return n.length===0?Wt("Right",void 0):Wt("Left",n)},f5=t=>e=>n=>r=>{if(0<n.keyframes.length){const o=n.keyframes[0],i=j_(O(a=>b(a.id,a))(n.keyframes)),s=_5(i)(n.scenes);return(()=>{if(s.tag==="Left"){const a=s._1;return u=>Wt("Left",a)}if(s.tag==="Right"){const a=s._1;return u=>u(a)}g()})()(()=>{const a=i5(Rh(e)(r)(r)([])(n)(0));return Wt("Right",{totalDuration:a.endT,windows:a.windows,spans:a.spans,keyframes:i,initialKeyframe:o.id,timing:e,layout:r.layout,cameraSpans:Nh(t)(z2)(r.layout)(i)(a),cameraConfig:t,levelTree:r,segments:a.segments,dives:a.dives,cues:c5(a),seed:n.seed})})}return Wt("Left",[Tk])},Go=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(o=>n(o._1)(o._2)),Apply0:()=>Ah(t)}),Ah=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>o=>i=>e.map(s=>b(r(s._1),s._2))(o(i))};return{apply:(()=>{const r=Go(t);return o=>i=>r.bind(o)(s=>r.bind(i)(a=>Po(t).pure(s(a))))})(),Functor0:()=>n}},Po=t=>({pure:e=>n=>t.Applicative0().pure(b(e,n)),Apply0:()=>Ah(t)}),Ih=t=>{const e={Applicative0:()=>Po(t),Bind1:()=>Go(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},Bo=(t,e)=>({tag:t,_1:e}),yr=(t,e)=>({tag:t,_1:e}),Ia=t=>t,Xn=(t,e)=>({tag:t,_1:e}),Ig=t=>t,Ne=Ih(kn),d5=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},l5=ce(P)(zt),Fg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},h5=T(t=>e=>rt(P)(e)()(t))(I),Vt=Go(kn),$e=Ne.state(t=>b(t,t)),ge=Po(kn),Fh=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Qh=Wr(ge),Qg=Qh(zt),p5=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},xr=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},m5=(()=>{const t=nn.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return N("Just",b(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,Lt("Cons",r._3,n(r._6,o)));g()};return n(e,$)})())})(),Yn=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},y5=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Fa=t=>e=>n=>T(r=>o=>t.Bind1().bind(r)(i=>e(i)(o)))(t.Applicative0().pure(n)),x5=T(t=>e=>rt(P)(e)()(t))(I),w5=(()=>{const t=(e=>n=>{let r=e,o=n,i=!0,s;for(;i;){const a=r,u=o;if(u.tag==="Nil"){i=!1,s=a;continue}if(u.tag==="Cons"){r=rt(P)(u._1)()(a),o=u._2;continue}g()}return s})(I);return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Lt("Cons",r._3,n(r._6,o)));g()};return n(e,$)})())})(),J5=Qh(f_),N5=T(t=>e=>rt(P)(e)()(t))(I),T5=Ig("AnimatedSurface"),v5=Ig("StillSurface"),C5=Ig("SequenceSurface"),b5=Xn("Exit"),Qa=Ia("AnimatedKeyframe"),Mg=Ia("Still"),k5=Ia("Title"),Mh=Ia("StepMarker"),L5=t=>yr("Par",t),S5=t=>yr("Seq",t),E5=t=>yr("GroupSeq",t),zh=t=>Bo("StepDive",t),G5={line:0,column:0,endLine:0,endColumn:0},P5=t=>e=>n=>{const r=vr(Ut,J,o=>o._1===t,n);if(r.tag==="Just"){const o=Or(Ut,J,r._1,b(t,e),n);if(o.tag==="Nothing")return n;if(o.tag==="Just")return o._1;g()}if(r.tag==="Nothing")return kt(n)(b(t,e));g()},B5=t=>e=>O(n=>n._1===t?b(n._1,{...n._2,label:N("Just",e)}):b(n._1,n._2)),Wh=t=>{const e=t.compare;return n=>T(r=>o=>Me(e,Ie,r,n(o)))(I)},zg=Wh(P),Wg=Wh(P),D5=t=>{const e=t.span;return Ne.state(n=>b(void 0,{...n,currentSpan:e}))},R5=t=>e=>({structural:[...t.structural,...e.structural],flow:t.flow||e.flow,dives:[...t.dives,...e.dives]}),A5=t=>e=>e.kind==="Animated"||d5(e.id)(t),qh={graphNodes:[],graphEdges:I,currNodes:I,currEdges:I,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:J,currentSpan:G5,error:J,enterStack:[],interiorOf:I,stepNames:I},Oh=t=>e=>n=>{const r=Zt(fn.foldr,n);return ur(", ")(O(e)(Bt(0,6,r)))+(r.length>6?", \u2026":"")},I5=t=>e=>{const n=Fg(e)(l5(O(r=>b(r.id,r))(t.graph.edges)));if(n.tag==="Just")return(()=>{const r=go("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()},F5=t=>e=>n=>{const r=Oh()(Ci)(e),o=Oh()(I5(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."},Q5=t=>{if(t.kind.tag==="SendToken")return h5([t.kind._1.from,t.kind._1.to]);if(t.kind.tag==="FillNodeWithoutTransition")return te("Node",1,1,t.kind._1.node,void 0,I,I);g()},M5=t=>zg(Q5)(t.events),z5=t=>{if(t.kind.tag==="SendToken")return te("Node",1,1,t.kind._1.edge,void 0,I,I);if(t.kind.tag==="FillNodeWithoutTransition")return I;g()},W5=t=>Wg(z5)(t.events),Kn=t=>Ne.state(e=>b(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()})())),q5=Qg(t=>Vt.bind($e)(e=>{if(e.error.tag==="Just")return ge.pure();if(e.error.tag==="Nothing")return Fh(t.node)(e.interiorOf)?Kn("node "+t.node+" has more than one `inside` block"):Ne.state(n=>b(void 0,{...n,interiorOf:rt(P)(t.node)(t.doc)(n.interiorOf)}));g()})),O5=t=>Vt.bind($e)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ie(e.kfCounter);if(xe(o=>o.id===n,e.keyframes))return Kn("duplicate frame name "+n);const r={...e,keyframes:kt(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges,kind:Di}),kfCounter:e.kfCounter+1|0,currentKf:N("Just",n)};return Ne.state(o=>b(void 0,r))}),un=t=>e=>Vt.bind(Ne.state(n=>b(void 0,{...n,currentSpan:t})))(()=>Kn(e)),Hh=t=>e=>Vt.bind($e)(n=>p5(e)(n.stepNames)?un(t)("duplicate step name "+e):Ne.state(r=>b(void 0,{...r,scenes:kt(r.scenes)(Uo("StepScene",e)),stepNames:rt(P)(e)()(r.stepNames)}))),H5=t=>{if(t.ops.tag==="Leaf"){const e=t.ops._1;return Vt.bind((()=>{const n=e.span;return Ne.state(r=>b(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?Hh(e.span)(e.op._1.name):Kn("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 Vt.bind((()=>{const n=e.span;return Ne.state(r=>b(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?Hh(e.span)(e.op._1.name):Kn("step marker frame did not contain a step"))}return Kn("step marker frame did not contain a step")},$5=t=>Vt.bind((()=>{const e=t.span;return Ne.state(n=>b(void 0,{...n,currentSpan:e}))})())(()=>Vt.bind($e)(e=>{if(e.error.tag==="Just")return ge.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!xr(t.op._1.id)(e.currNodes))return un(0<t.operands.length?t.operands[0]:t.span)("cannot dive into node "+t.op._1.id+": does not exist");if(!Fh(t.op._1.id)(e.interiorOf))return un(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
13
|
+ detail: Detail
|
|
13
|
-
}`);const n=t.op._1;return Je.state(r=>C(void 0,{...r,enterStack:Pt(r.enterStack)(n.id),scenes:Pt(r.scenes)($o("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=Qr(e.enterStack);if(n.tag==="Nothing")return Un("`out` without a matching `into`");if(n.tag==="Just"){const r=n._1.init;return Je.state(o=>C(void 0,{...o,enterStack:r,scenes:Pt(o.scenes)(s2)}))}g()}return ge.pure()}g()})),za={structural:[],flow:!1,dives:[]},I5=Vt.bind(Oe)(t=>{if(t.error.tag==="Just")return ge.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return Je.state(n=>C(void 0,{...n,scenes:Pt(n.scenes)($o("Hold",e))}))}if(t.currentKf.tag==="Nothing")return ge.pure()}g()}),A5=t=>e=>Vt.bind(Oe)(n=>{const r="ev-"+ie(n.eventCounter);return Vt.bind((()=>{const o={...n,eventCounter:n.eventCounter+1|0};return Je.state(i=>C(void 0,o))})())(()=>ge.pure({events:[{id:r,kind:e,when:t}],firstId:N("Just",r),lastId:N("Just",r)}))}),R5=t=>t.tag==="DataFlow"?N("Just",t._1):w,F5=t=>vt(e=>Fg(e)(t.graphEdges))(jt(Io,i5(t.currEdges))),Q5=t=>e=>{const n=ft(o=>o.from.node===e.id||o.to.node===e.id,F5(t)),r=Qa(c_)(o=>i=>{const s=i.from+"->"+e.id,a=e.id+"->"+i.to,u=i.from+"->"+i.to,c="via "+i.from+" "+i.to+": no edge "+i.from+"\u2192"+e.id;if(!Yn(s)(t.currEdges))return Wt("Left",c);const _="via "+i.from+" "+i.to+": no edge "+e.id+"\u2192"+i.to;if(!Yn(a)(t.currEdges))return Wt("Left",_);const d="via "+i.from+" "+i.to+": would create "+i.from+"\u2192"+i.to+" but it already exists";return Yn(u)(t.currEdges)||s5(u)(o.synthesized)?Wt("Left",d):Wt("Right",{consumed:rt(P)(s)()(rt(P)(a)()(o.consumed)),synthesized:rt(P)(u)({id:u,from:{node:i.from,port:w},to:{node:i.to,port:w},label:w})(o.synthesized)})})({consumed:R,synthesized:R})(e.via);return(()=>{if(r.tag==="Left"){const o=r._1;return i=>Wt("Left",o)}if(r.tag==="Right"){const o=r._1;return i=>i(o)}g()})()(o=>{const i=o.consumed,s=ft(a=>!Yn(a.id)(i),n);return s.length===0?Wt("Right",{nextCurrEdges:Ae(P.compare,Be,Hn(P.compare,t.currEdges,a5($(a=>a.id)(n))),u5((()=>{const a=u=>{if(u.tag==="Leaf")return R;if(u.tag==="Node")return te("Node",u._1,u._2,u._3,void 0,a(u._5),a(u._6));g()};return a(o.synthesized)})())),synthesized:o.synthesized}):Wt("Left","cannot delete node "+e.id+": still connected ("+rr(", ")($(a=>(()=>{const u=io("conn:")(a.id);if(u.tag==="Just")return!1;if(u.tag==="Nothing")return!0;g()})()?a.from.node+"\u2192"+a.to.node:a.from.node+"--"+a.to.node)(s))+"). Use `- a -> b` or `- a -- b` to drop them, or `via a b` to merge "+e.id+"'s endpoints.")})},Mh=t=>e=>n=>{if(t){if(e){const i=0<n.operands.length?n.operands[0]:n.span,s=1<n.operands.length?n.operands[1]:n.span;return{line:i.line,column:i.column,endLine:s.endLine,endColumn:s.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}},zh=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq"||t.tag==="GroupSeq")return St(t._1)(zh);g()},M5=t=>({nodes:$(ps)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,kt("Cons",n._4,e(n._6,r)));g()};return jt(le.foldr,e(t.graphEdges,H))})(),constraints:[]}),qg=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==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?{...za,structural:[t._1]}:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?{...za,dives:[t._1]}:{...za,flow:!0};if(t.tag==="Seq"||t.tag==="GroupSeq"||t.tag==="Par")return v(v5)(za)($(qg)(t._1));g()},Wa=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==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?[Go("StepStructural",[t._1])]:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?[Go("StepDive",t._1)]:[Go("StepFlow",t)];if(t.tag==="Seq")return St(t._1)(Wa);if(t.tag==="GroupSeq")return W5(t)(t._1);if(t.tag==="Par")return z5(t)(t._1);g()},z5=t=>e=>{const n=qg(t);return n.structural.length!==0&&!n.flow&&n.dives.length===0?[Go("StepStructural",n.structural)]:n.structural.length===0&&n.flow&&n.dives.length===0?[Go("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?$(Ih)(n.dives):St(e)(Wa)},W5=t=>e=>{const n=qg(t);return n.structural.length===0&&n.flow&&n.dives.length===0?[Go("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?$(Ih)(n.dives):St(e)(Wa)},q5=t=>e=>Vt.bind(Oe)(n=>{const r=e.from+"->"+e.to,o=e.newFrom+"->"+e.newTo;return Yn(r)(n.currEdges)?lr(e.newFrom)(n.currNodes)?lr(e.newTo)(n.currNodes)?r!==o&&Yn(o)(n.currEdges)?un((()=>{const i=2<t.operands.length?t.operands[2]:t.span,s=3<t.operands.length?t.operands[3]:t.span;return{line:i.line,column:i.column,endLine:s.endLine,endColumn:s.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists"):Je.state(i=>C(void 0,{...i,currEdges:rt(P)(o)()(zo(P)(r)(i.currEdges)),graphEdges:rt(P)(o)({id:o,from:{node:e.newFrom,port:w},to:{node:e.newTo,port:w},label:w})(i.graphEdges)})):un(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):un(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):un((()=>{const i=0<t.operands.length?t.operands[0]:t.span,s=1<t.operands.length?t.operands[1]:t.span;return{line:i.line,column:i.column,endLine:s.endLine,endColumn:s.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist")}),O5=t=>{if(t.op.tag==="AddNode"){const e=t.op._1;return Vt.bind(Oe)(n=>lr(e.id)(n.currNodes)?un(0<t.operands.length?t.operands[0]:t.span)("cannot add node "+e.id+": already exists"):Je.state(r=>C(void 0,{...r,graphNodes:w5(e.id)({id:e.id,size:C(1,1),ports:[],label:N("Just",e.label),shape:e.shape})(r.graphNodes),currNodes:rt(P)(e.id)()(r.currNodes)})))}if(t.op.tag==="DelNode"){const e=t.op._1;return Vt.bind(Oe)(n=>{if(!lr(e.id)(n.currNodes))return un(0<t.operands.length?t.operands[0]:t.span)("cannot delete node "+e.id+": does not exist");const r=Q5(n)(e);if(r.tag==="Left")return un(0<t.operands.length?t.operands[0]:t.span)(r._1);if(r.tag==="Right"){const o=r._1;return Je.state(i=>C(void 0,{...i,currNodes:zo(P)(e.id)(i.currNodes),currEdges:o.nextCurrEdges,graphEdges:Ae(P.compare,Be,o.synthesized,i.graphEdges)}))}g()})}if(t.op.tag==="ModNode"){const e=t.op._1;return Vt.bind(Oe)(n=>{if(!lr(e.id)(n.currNodes))return un(0<t.operands.length?t.operands[0]:t.span)("cannot modify node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=e.label._1;return Je.state(o=>C(void 0,{...o,graphNodes:J5(e.id)(r)(o.graphNodes)}))}if(e.label.tag==="Nothing")return ge.pure();g()})}if(t.op.tag==="AddEdge"){const e=t.op._1;return Vt.bind(Oe)(n=>{const r=!lr(e.from)(n.currNodes),o=!lr(e.to)(n.currNodes);if(r||o)return un(Mh(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 Yn(i)(n.currEdges)?un((()=>{const s=0<t.operands.length?t.operands[0]:t.span,a=1<t.operands.length?t.operands[1]:t.span;return{line:s.line,column:s.column,endLine:a.endLine,endColumn:a.endColumn}})())((e.directed?"cannot add edge ":"cannot add connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": already exists"):Je.state(s=>C(void 0,{...s,graphEdges:rt(P)(i)({id:i,from:{node:e.from,port:w},to:{node:e.to,port:w},label:e.label})(s.graphEdges),currEdges:rt(P)(i)()(s.currEdges)}))})}if(t.op.tag==="DelEdge"){const e=t.op._1;return Vt.bind(Oe)(n=>{const r=e.directed?e.from+"->"+e.to:e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;return Yn(r)(n.currEdges)?Je.state(o=>C(void 0,{...o,currEdges:zo(P)(r)(o.currEdges)})):un((()=>{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"?q5(t)(t.op._1):ge.pure()},H5=t=>Vt.bind((()=>{const e=t.span;return Je.state(n=>C(void 0,{...n,currentSpan:e}))})())(()=>O5(t)),Wh=t=>e=>n=>Vt.bind(Qg(H5)(n))(()=>Vt.bind(Oe)(r=>{const o=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ie(r.kfCounter);if(Ne(s=>s.id===o,r.keyframes))return Vt.bind(c5(N5)(0<n.length?N("Just",n[0]):w))(()=>Un("duplicate frame name "+o));const i={...r,keyframes:Pt(r.keyframes)({id:o,nodes:r.currNodes,edges:r.currEdges,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 Pt(r.scenes)($o("Structural",{from:r.currentKf._1,to:o,focus:w}));g()})()};return Je.state(s=>C(void 0,i))})),qh=t=>e=>{const n=zh(e.ops),r=ft(i=>i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge",n),o=ft(i=>!(i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge"),n);return 0<o.length?Vt.bind((()=>{const i=o[0].span;return Je.state(s=>C(void 0,{...s,currentSpan:i}))})())(()=>Un("still/title blocks hold a still snapshot; they cannot contain movement tokens (`api ~> db`) or dive commands (`into`/`out`)")):t==="TitleCard"&&r.length===0?Un(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"):Vt.bind(Wh(t)(e.name)(r))(()=>I5)},$5=t=>e=>{const n=vt(R5)(e.scenes),r=ft(T5(g5($(s=>s.keyframe)(n))),e.keyframes),o=Hn(P.compare,zg(s=>s.nodes)(r),zg(L5)(n)),i=Hn(P.compare,Wg(s=>s.edges)(r),Wg(E5)(n));return t!=="AnimatedSurface"||n.length===0||o.tag==="Leaf"&&i.tag==="Leaf"?w:N("Just",C5(e)(o)(i))},V5=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(Yn(r)(t.currEdges))return N("Just",{id:r,direction:Y_});if(Yn(n)(t.currEdges))return N("Just",{id:n,direction:U_});const i=Fg(o)(t.graphEdges);if(i.tag==="Just")return Yn(o)(t.currEdges)?N("Just",{id:o,direction:i._1.from.node===e.from&&i._1.to.node===e.to?Y_:U_}):w;if(i.tag==="Nothing")return w;g()},X5=t=>e=>{if(e.op.tag==="Token"){const n=e.op._1;return Vt.bind(Oe)(r=>{const o=!lr(n.from)(r.currNodes),i=!lr(n.to)(r.currNodes);if(o||i)return Vt.bind(un(Mh(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: "))(()=>ge.pure({events:[],firstId:w,lastId:w}));const s=V5(r)(n);if(s.tag==="Just")return A5(t)(n2("SendToken",{from:n.from,to:n.to,edge:s._1.id,direction:s._1.direction,labels:n.labels}));if(s.tag==="Nothing")return Vt.bind(un((()=>{const a=0<e.operands.length?e.operands[0]:e.span,u=1<e.operands.length?e.operands[1]:e.span;return{line:a.line,column:a.column,endLine:u.endLine,endColumn:u.endColumn}})())("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>ge.pure({events:[],firstId:w,lastId:w}));g()})}return ge.pure({events:[],firstId:w,lastId:w})},Y5=t=>e=>{const n=zt(r=>w,r=>o=>N("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return ge.pure({events:[],firstId:w,lastId:w});if(n.tag==="Just"){const r=n._1.tail;return Vt.bind(fs(t)(n._1.head))(o=>Vt.bind(Qa({Applicative0:()=>Eo(Tn),Bind1:()=>So(Tn)})(i=>s=>Vt.bind(fs((()=>{if(i.lastId.tag==="Just")return zu("After",i.lastId._1);if(i.lastId.tag==="Nothing")return t;g()})())(s))(a=>ge.pure({events:[...i.events,...a.events],firstId:(()=>{if(i.firstId.tag==="Just")return N("Just",i.firstId._1);if(i.firstId.tag==="Nothing")return a.firstId;g()})(),lastId:(()=>{if(a.lastId.tag==="Just")return N("Just",a.lastId._1);if(a.lastId.tag==="Nothing")return i.lastId;g()})()})))(o)(r))(i=>ge.pure(i)))}g()},U5=t=>e=>{const n=zt(r=>w,r=>o=>N("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return ge.pure({events:[],firstId:w,lastId:w});if(n.tag==="Just"){const r=n._1.tail;return Vt.bind(fs(t)(n._1.head))(o=>Vt.bind(K5((()=>{if(o.firstId.tag==="Just")return zu("With",o.firstId._1);if(o.firstId.tag==="Nothing")return t;g()})())(r))(i=>ge.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()},fs=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return Vt.bind((()=>{const r=n.span;return Je.state(o=>C(void 0,{...o,currentSpan:r}))})())(()=>X5(t)(n))}if(e.tag==="Seq"||e.tag==="GroupSeq")return Y5(t)(e._1);if(e.tag==="Par")return U5(t)(e._1);g()},K5=t=>Qa({Applicative0:()=>Eo(Tn),Bind1:()=>So(Tn)})(e=>n=>Vt.bind(fs(t)(n))(r=>ge.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}),j5=t=>Vt.bind(Oe)(e=>{if(e.currentKf.tag==="Nothing")return Un("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return Vt.bind(fs(i2)(t))(r=>Vt.bind(Oe)(o=>{const i={...o,scenes:Pt(o.scenes)($o("DataFlow",{keyframe:n,events:r.events,focus:w}))};return Je.state(s=>C(void 0,i))}))}g()}),Z5=t=>e=>n=>{if(n.tag==="StepStructural")return Vt.bind((()=>{const r=Wh(Di)(e?w:t)(n._1);return n._1.length!==0?r:ge.pure()})())(()=>ge.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 Vt.bind((()=>{const i=P5(t);return o?i:ge.pure()})())(()=>Vt.bind(j5(r))(()=>ge.pure(e||o)))}if(n.tag==="StepDive")return Vt.bind(D5(n._1))(()=>ge.pure(e));g()},Oh=t=>e=>n=>{const r=zt(o=>w,o=>i=>N("Just",{head:o,tail:i}),n);if(r.tag==="Nothing")return ge.pure();if(r.tag==="Just"){const o=r._1.head,i=r._1.tail;return Vt.bind(Oe)(s=>{if(s.error.tag==="Just")return ge.pure();if(s.error.tag==="Nothing")return Vt.bind(Z5(t)(e)(o))(a=>Oh(t)(a)(i));g()})}g()},tL=t=>Vt.bind(Oe)(e=>{if(e.error.tag==="Just")return ge.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return Oh(t.name)(!1)(Wa(t.ops));if(t.kind==="Still")return qh(r2)(t);if(t.kind==="Title")return qh(o2)(t);if(t.kind==="StepMarker")return B5(t)}g()}),Hh=t=>Vt.bind(G5(t.interiors))(()=>Vt.bind(Qg(tL)(t.frames))(()=>Vt.bind(Oe)(e=>{if(e.error.tag==="Just")return ge.pure(Wt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=eL(t.interiors);if(n.tag==="Left")return ge.pure(Wt("Left",n._1));if(n.tag==="Right"){const r={seed:t.seed,graph:M5(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1};return ge.pure((()=>{const o=$5(t.mode)(r);if(o.tag==="Just")return Wt("Left",{msg:o._1,line:0,column:0,endLine:0,endColumn:0});if(o.tag==="Nothing")return Wt("Right",r);g()})())}}g()}))),eL=t=>{const e=Qa(c_)(n=>r=>{const o=Hh(r.doc)(Rh)._1;return(()=>{if(o.tag==="Left"){const i=o._1;return s=>Wt("Left",i)}if(o.tag==="Right"){const i=o._1;return s=>s(i)}g()})()(i=>Wt("Right",rt(P)(r.node)(i)(n)))})(R)(t);if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right")return Wt("Right",e._1);g()},hr=(t,e)=>({tag:"ParseError",_1:t,_2:e}),k=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),qa=(t,e,n)=>({tag:t,_1:e,_2:n}),nL=t=>qa("More",t),rL=t=>qa("Lift",t),oL={defer:t=>{const e=Sm(t);return(n,r,o,i,s)=>Em(e)(n,r,o,i,s)}},$h={map:t=>e=>(n,r,o,i,s)=>r(a=>e(n,r,o,i,(u,c)=>r(_=>s(u,t(c)))))},iL={alt:t=>e=>(n,r,o,i,s)=>{const a=n._1,u=n._2;return r(c=>t(k(a,u,!1),r,o,(_,d)=>{const l=_._3;return r(f=>l?i(_,d):e(n,r,o,i,s))},s))},Functor0:()=>$h},sL=t=>{const e=t.Monad0();return n=>r=>{const o=i=>{let s=i,a=!0,u;for(;a;){const c=s();if(c.tag==="More"){s=c._1;continue}if(c.tag==="Lift"){a=!1,u=e.Bind1().Apply0().Functor0().map(du)(c._1);continue}if(c.tag==="Stop"){a=!1,u=e.Applicative0().pure(Do("Done",C(c._2,c._1)));continue}g()}return u};return t.tailRecM(o)(i=>r(n,nL,rL,(s,a)=>qa("Stop",s,Wt("Left",a)),(s,a)=>qa("Stop",s,Wt("Right",a))))}},Kn=(t,e,n,r,o)=>o(t,t._2),aL={index:0,line:1,column:1},uL=(t=>{const e=sL(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(ms)(e(k(n,aL,!1))(r))})(s0),Oa=(t,e,n,r,o)=>o(k(t._1,t._2,!0),void 0),Vh={apply:t=>e=>(n,r,o,i,s)=>r(a=>t(n,r,o,i,(u,c)=>r(_=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return e(d,r,o,i,(l,f)=>r(h=>s(d._3&&!l._3?k(l._1,l._2,!0):l,c(f))))}))),Functor0:()=>$h},Xh={pure:t=>(e,n,r,o,i)=>i(e,t),Apply0:()=>Vh},cL={bind:t=>e=>(n,r,o,i,s)=>r(a=>t(n,r,o,i,(u,c)=>r(_=>e(c)(n._3&&!u._3?k(u._1,u._2,!0):u,r,o,i,s)))),Apply0:()=>Vh},gL={Applicative0:()=>Xh,Bind1:()=>cL},Ha=t=>(e,n,r,o,i)=>n(s=>Kn(e,n,r,o,(a,u)=>n(c=>o(e._3&&!a._3?k(a._1,a._2,!0):a,hr(t,u))))),_L={empty:Ha("No alternative"),Alt0:()=>iL},fL={Applicative0:()=>Xh,Plus1:()=>_L},En=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return o=>t.tailRecM(i=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(du)(o))(r.pure(Do("Done",void 0))))(s=>r.pure((()=>{if(s.tag==="Loop")return Do("Loop",kt("Cons",s._1,i));if(s.tag==="Done")return Do("Done",(a=>u=>{let c=a,_=u,d=!0,l;for(;d;){const f=c,h=_;if(h.tag==="Nil"){d=!1,l=f;continue}if(h.tag==="Cons"){c=kt("Cons",h._1,f),_=h._2;continue}g()}return l})(H)(i));g()})())))(H)})({tailRecM:t=>e=>(n,r,o,i,s)=>{const a=(u,c,_)=>t(c)(u,r,o,i,(d,l)=>{const f=u._3&&!d._3?k(d._1,d._2,!0):d;if(l.tag==="Loop")return _===0?r(h=>a(f,l._1,30)):a(f,l._1,_-1|0);if(l.tag==="Done")return s(f,l._1);g()});return a(n,e,30)},Monad0:()=>gL})(fL),xt=t=>e=>{const n=Ha("Expected "+e);return(r,o,i,s,a)=>{const u=r._1,c=r._2;return o(_=>t(k(u,c,!1),o,i,(d,l)=>{const f=d._3;return o(h=>f?s(d,l):n(r,o,i,s,a))},a))}},Ji=t=>(e,n,r,o,i)=>{const s=e._3,a=e._1,u=e._2;return n(c=>{const _=(d,l)=>{const f=d._3;return n(h=>f?o(k(d._1,d._2,s),l):i(e,void 0))};return n(d=>n(l=>t(k(a,u,!1),n,r,(f,h)=>_(k(f._1,f._2,!1),h),(f,h)=>n(p=>n(m=>Ha("Negated parser succeeded")(f,n,r,_,(J,x)=>n(y=>i(f._3&&!J._3?k(J._1,J._2,!0):J,x))))))))})},dL=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return N("Just",n);if(r.tag==="Just")return N("Just",(o,i,s,a,u)=>{const c=o._1,_=o._2;return i(d=>n(k(c,_,!1),i,s,(l,f)=>{const h=l._3;return i(p=>h?a(l,f):r._1(o,i,s,a,u))},u))});g()})(w);return n=>{const r=e(n);if(r.tag==="Nothing")return Ha("No alternative");if(r.tag==="Just")return r._1;g()}},Yh=t=>e=>n=>(r,o,i,s,a)=>o(u=>o(c=>o(_=>o(d=>t(r,o,i,s,(l,f)=>o(h=>o(p=>{const m=r._3&&!l._3?k(l._1,l._2,!0):l;return n(m,o,i,s,(J,x)=>o(y=>{const T=m._3&&!J._3?k(J._1,J._2,!0):J;return o(b=>o(L=>{const E=r._3&&!T._3?k(T._1,T._2,!0):T;return e(E,o,i,s,(B,z)=>o(U=>a(E._3&&!B._3?k(B._1,B._2,!0):B,x)))}))}))}))))))),Og=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=ry()(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)-Mr(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},lL=t=>e=>n=>{let r=t,o=e,i=n,s=!0,a;for(;s;){const u=r,c=o,_=i,d=Qs(c);if(d.tag==="Nothing"){s=!1,a=u;continue}if(d.tag==="Just"){r=d._1.tail===""?Og(u)(d._1.head)(_):Og(u)(d._1.head)(d._1.tail),o=d._1.tail,i=_;continue}g()}return a},At=t=>(e,n,r,o,i)=>{const s=Qs(e._1);if(s.tag==="Nothing")return o(e,hr("Unexpected EOF",e._2));if(s.tag==="Just"){if(s._1.head<0||s._1.head>65535)return o(e,hr("Expected Char",e._2));if(s._1.head>=0&&s._1.head<=65535){const a=_f(s._1.head);return t(a)?i(k(s._1.tail,Og(e._2)(s._1.head)(s._1.tail),!0),a):o(e,hr("Predicate unsatisfied",e._2))}}g()},ds=(t,e,n,r,o)=>t._1===""?o(k(t._1,t._2,!0),void 0):r(t,hr("Expected EOF",t._2)),hL=t=>(e,n,r,o,i)=>{const s=t(e._1);if(s.tag==="Left")return o(e,hr(s._1,e._2));if(s.tag==="Right")return i(k(s._1.remainder,lL(e._2)(s._1.consumed)(s._1.remainder),s._1.consumed!==""),s._1.value);g()},cn=t=>hL(e=>{const n=io(t)(e);return n.tag==="Just"?Wt("Right",{value:t,consumed:t,remainder:n._1}):Wt("Left","Expected "+Vp(t))}),pL=At(t=>!0),$a=(t,e)=>({tag:t,_1:e}),Hg=dL(Mt),mL=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},yL=ce(P)(Mt),xL=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},$g=(()=>{const t=xt(At(r=>r==="}"))("'}'"),e=xt(At(r=>r==="#"))("'#'"),n=At(r=>r===`
|
|
14
|
-
`||r==="\r");return(r,o,i,s,a)=>{const u=r._1,c=r._2;return o(_=>o(d=>t(k(u,c,!1),o,i,(l,f)=>o(h=>{const p=r._1,m=r._2;return o(
|
|
15
|
-
`||e==="\r");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>i(e._3&&!a._3?k(a._1,a._2,!0):a,void 0))))})(),
|
|
16
|
-
`)),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>o(_._3&&!l._3?k(l._1,l._2,!0):l,void 0))))}))),
|
|
17
|
-
`||n==="\r");return(n,r,o,i,s)=>{const a=n._1,u=n._2;return r(c=>r(_=>t(k(a,u,!1),r,o,(d,l)=>r(f=>{const h=n._1,p=n._2;return r(m=>r(
|
|
18
|
-
`&&t!=="\r"&&t!=="#"&&t!=="}"&&t!=="{"
|
|
19
|
-
`||t==="\r"||t==="#"||t==="}",
|
|
20
|
-
`||t==="\r"||t==="#"||t==="}"||t==="{",
|
|
21
|
-
`&&t!=="\r",
|
|
22
|
-
`:f==="t"?" ":f==="r"?"\r":f))))})))})(),
|
|
23
|
-
`);return(e,n,r,o,i)=>{const s=e._1,a=e._2;return n(u
|
|
24
|
-
`)(t));return
|
|
25
|
-
`)($(bL)($(Ho(EL(e)))(e)))},QL=(()=>{const t=xt(At(e=>e==="|"))("'|'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=En(JL),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=xt(xt(At(x=>x==="|"))("'|'"))("closing '|'"),J=d._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(J,n,r,o,(y,T)=>n(b=>i(J._3&&!y._3?k(y._1,y._2,!0):y,FL(rr("")(jt(le.foldr,h)))))))})))})))})(),ls=At(t=>t>="0"&&t<="9"),ML=(()=>{const t=xt(At(e=>e==="_"))("'_'");return(e,n,r,o,i)=>{const s=e._1,a=e._2;return n(u=>Va(k(s,a,!1),n,r,(c,_)=>{const d=c._3;return n(l=>{if(d)return o(c,_);const f=e._1,h=e._2;return n(p=>ls(k(f,h,!1),n,r,(m,J)=>{const x=m._3;return n(y=>{if(x)return o(m,J);const T=e._1,b=e._2;return n(L=>t(k(T,b,!1),n,r,(E,B)=>{const z=E._3;return n(U=>z?o(E,B):GL(e,n,r,o,i))},i))})},i))})},i))}})(),Me=(()=>{const t=xt(At(e=>e==="_"))("'_'");return(e,n,r,o,i)=>n(s=>{const a=(_,d)=>n(l=>{const f=En(ML),h=e._3&&!_._3?k(_._1,_._2,!0):_;return n(p=>f(h,n,r,o,(m,J)=>n(x=>i(h._3&&!m._3?k(m._1,m._2,!0):m,Pi(d)+zr(jt(le.foldr,J))))))}),u=e._1,c=e._2;return n(_=>Va(k(u,c,!1),n,r,(d,l)=>{const f=d._3;return n(h=>f?o(d,l):t(e,n,r,o,a))},a))})})(),np=(t,e,n,r,o)=>e(i=>ee(t,e,n,r,(s,a)=>e(u=>{const c=xt(Me)("attribute key"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=_._3&&!l._3?k(l._1,l._2,!0):l;return e(m=>ee(p,e,n,r,(J,x)=>e(y=>{const T=xt(xt(At(L=>L===":"))("':'"))("':'"),b=p._3&&!J._3?k(J._1,J._2,!0):J;return e(L=>T(b,e,n,r,(E,B)=>e(z=>{const U=b._3&&!E._3?k(E._1,E._2,!0):E;return e(I=>ee(U,e,n,r,(A,j)=>e(Z=>{const M=xt(Me)("attribute value"),W=U._3&&!A._3?k(A._1,A._2,!0):A;return e(O=>M(W,e,n,r,(D,F)=>e(S=>{const G=W._3&&!D._3?k(D._1,D._2,!0):D;return e(Q=>ee(G,e,n,r,(V,Y)=>e(X=>o(G._3&&!V._3?k(V._1,V._2,!0):V,C(f,F)))))})))})))})))})))})))}))),zL=Yh((()=>{const t=xt(At(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(s=>n(a=>t(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return ee(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(f._1,f._2,!0):f,h)))})))))})())(xt((()=>{const t=xt(At(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(s=>n(a=>ee(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return t(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(f._1,f._2,!0):f,h)))})))))})())("closing '}' for attributes"))((()=>{const t=xt(At(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(s=>{const a=(_,d)=>n(l=>(()=>{if(d.tag==="Just")return(f,h,p,m,J)=>J(f,R);if(d.tag==="Nothing")return(f,h,p,m,J)=>h(x=>np(f,h,p,m,(y,T)=>h(b=>{const L=En((()=>{const B=xt(At(z=>z===","))("','");return(z,U,I,A,j)=>{const Z=z._3;return U(M=>U(W=>U(O=>U(D=>U(F=>U(S=>ee(z,U,I,(G,Q)=>A(k(G._1,G._2,Z),Q),(G,Q)=>U(V=>U(Y=>{const X=z._3&&!G._3?k(G._1,G._2,!0):G;return B(X,U,I,(q,K)=>A(k(q._1,q._2,Z),K),(q,K)=>U(et=>{const lt=X._3&&!q._3?k(q._1,q._2,!0):q;return U(Ct=>U(pt=>{const Tt=z._3&&!lt._3?k(lt._1,lt._2,!0):lt;return ee(Tt,U,I,(Et,Zt)=>A(k(Et._1,Et._2,Z),Zt),(Et,Zt)=>U(bt=>{const Ut=Tt._3&&!Et._3?k(Et._1,Et._2,!0):Et;return U(Bt=>U(wt=>{const mt=z._3&&!Ut._3?k(Ut._1,Ut._2,!0):Ut;return np(mt,U,I,(ct,yt)=>A(k(ct._1,ct._2,Z),yt),(ct,yt)=>U(dt=>j(mt._3&&!ct._3?k(ct._1,ct._2,!0):ct,yt)))}))}))}))}))})))))))))}})()),E=f._3&&!y._3?k(y._1,y._2,!0):y;return h(B=>L(E,h,p,m,(z,U)=>h(I=>J(E._3&&!z._3?k(z._1,z._2,!0):z,yL([T,...jt(le.foldr,U)])))))})));g()})()(e._3&&!_._3?k(_._1,_._2,!0):_,n,r,o,i)),u=e._1,c=e._2;return n(_=>n(d=>t(k(u,c,!1),n,r,(l,f)=>n(h=>a(e,w)),(l,f)=>n(h=>a(k(u,c,!1),N("Just",f))))))})})()),WL=(t,e,n,r,o)=>e(i=>ee(t,e,n,r,(s,a)=>e(u=>{const c=xt(At(d=>d==="{"))("'{'"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>{const l=(p,m)=>e(J=>(()=>{if(m.tag==="Just")return zL;if(m.tag==="Nothing")return(x,y,T,b,L)=>L(x,R);g()})()(_._3&&!p._3?k(p._1,p._2,!0):p,e,n,r,o)),f=_._1,h=_._2;return e(p=>e(m=>c(k(f,h,!1),e,n,(J,x)=>e(y=>l(_,w)),(J,x)=>e(y=>l(k(f,h,!1),N("Just",x))))))})}))),qL=t=>e=>n=>(r,o,i,s,a)=>o(u=>ee(r,o,i,s,(c,_)=>o(d=>{const l=wn(xt(Me)("target node identifier")),f=r._3&&!c._3?k(c._1,c._2,!0):c;return o(h=>l(f,o,i,s,(p,m)=>o(J=>a(f._3&&!p._3?k(p._1,p._2,!0):p,{op:Xn("DelEdge",{from:t,to:m._1,directed:n}),operands:[e,m._2]}))))}))),OL=(t,e,n,r,o)=>e(i=>Kn(t,e,n,r,(s,a)=>e(u=>{const c=t._3&&!s._3?k(s._1,s._2,!0):s;return e(_=>{const d=c._3;return e(l=>Me(c,e,n,(f,h)=>r(k(f._1,f._2,d),h),(f,h)=>e(p=>{const m=c._3&&!f._3?k(f._1,f._2,!0):f;return e(J=>ee(m,e,n,(x,y)=>r(k(x._1,x._2,d),y),(x,y)=>e(T=>{const b=m._3&&!x._3?k(x._1,x._2,!0):x;return e(L=>{const E=(U,I)=>e(A=>{const j=b._3&&!U._3?k(U._1,U._2,!0):U;return e(Z=>r(c._3&&!j._3?k(j._1,j._2,!0):j,hr("Use `~>` / `<~` for movement tokens.",a)))}),B=b._1,z=b._2;return e(U=>cn("->")(k(B,z,!1),e,n,(I,A)=>{const j=I._3;return e(Z=>j?r(k(I._1,I._2,d),A):cn("<-")(b,e,n,(M,W)=>r(k(M._1,M._2,d),W),E))},E))})})))})))})}))),HL=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>wn(Me)(t,e,n,(u,c)=>r(k(u._1,u._2,s),c),(u,c)=>e(_=>{const d=t._3&&!u._3?k(u._1,u._2,!0):u;return e(l=>ee(d,e,n,(f,h)=>r(k(f._1,f._2,s),h),(f,h)=>e(p=>{const m=xt(At(x=>x==="~"))("'~'"),J=d._3&&!f._3?k(f._1,f._2,!0):f;return e(x=>{const y=(L,E)=>e(B=>{const z=J._3&&!L._3?k(L._1,L._2,!0):L;return e(U=>{const I=c._1,A=c._2,j=t._3&&!z._3?k(z._1,z._2,!0):z;return e(Z=>ee(j,e,n,r,(M,W)=>e(O=>{const D=xt(At(G=>G==="~"))("'~'"),F=xt(At(G=>G==="<"))("'<'"),S=j._3&&!M._3?k(M._1,M._2,!0):M;return e(G=>{const Q=(X,q)=>e(K=>{const et=q==="~"?xt(cn("~>"))("'~>'"):xt(cn("<~"))("'<~'"),lt=S._3&&!X._3?k(X._1,X._2,!0):X;return e(Ct=>et(lt,e,n,r,(pt,Tt)=>e(Et=>o(lt._3&&!pt._3?k(pt._1,pt._2,!0):pt,C(I,C(A,Tt))))))}),V=S._1,Y=S._2;return e(X=>D(k(V,Y,!1),e,n,(q,K)=>{const et=q._3;return e(lt=>et?r(S,K):F(S,e,n,(Ct,pt)=>r(S,pt),(Ct,pt)=>Q(S,pt)))},(q,K)=>Q(S,K)))})})))})}),T=J._1,b=J._2;return e(L=>m(k(T,b,!1),e,n,(E,B)=>{const z=E._3;return e(U=>z?r(k(J._1,J._2,s),B):e(I=>cn("<~")(J,e,n,(A,j)=>r(k(J._1,J._2,s),j),(A,j)=>e(Z=>y(J)))))},(E,B)=>y(J)))})})))})))}),$L=(()=>{const t=xt(At(e=>e==="~"))("'~'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=xt(Zr)("space after '~'"),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=wn(xt(Me)("source node identifier")),J=d._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(J,n,r,o,(y,T)=>n(b=>{const L=T._1,E=T._2,B=J._3&&!y._3?k(y._1,y._2,!0):y;return n(z=>ee(B,n,r,o,(U,I)=>n(A=>{const j=xt(cn("->"))("source edge arrow '->'"),Z=B._3&&!U._3?k(U._1,U._2,!0):U;return n(M=>j(Z,n,r,o,(W,O)=>n(D=>{const F=Z._3&&!W._3?k(W._1,W._2,!0):W;return n(S=>ee(F,n,r,o,(G,Q)=>n(V=>{const Y=wn(xt(Me)("target node identifier")),X=F._3&&!G._3?k(G._1,G._2,!0):G;return n(q=>Y(X,n,r,o,(K,et)=>n(lt=>{const Ct=et._1,pt=et._2,Tt=X._3&&!K._3?k(K._1,K._2,!0):K;return n(Et=>ee(Tt,n,r,o,(Zt,bt)=>n(Ut=>{const Bt=xt(cn("=>"))("repoint separator '=>'"),wt=Tt._3&&!Zt._3?k(Zt._1,Zt._2,!0):Zt;return n(mt=>Bt(wt,n,r,o,(ct,yt)=>n(dt=>{const ht=wt._3&&!ct._3?k(ct._1,ct._2,!0):ct;return n(Lt=>ee(ht,n,r,o,(Gt,Qt)=>n(ne=>{const Nn=wn(xt(Me)("new source node identifier")),ze=ht._3&&!Gt._3?k(Gt._1,Gt._2,!0):Gt;return n(Ot=>Nn(ze,n,r,o,(qt,We)=>n(vn=>{const Ze=We._1,_n=We._2,Fe=ze._3&&!qt._3?k(qt._1,qt._2,!0):qt;return n(oe=>ee(Fe,n,r,o,(fe,l4)=>n(h4=>{const _4=xt(cn("->"))("replacement edge arrow '->'"),Qp=Fe._3&&!fe._3?k(fe._1,fe._2,!0):fe;return n(p4=>_4(Qp,n,r,o,(au,m4)=>n(y4=>{const Mp=Qp._3&&!au._3?k(au._1,au._2,!0):au;return n(x4=>ee(Mp,n,r,o,(uu,w4)=>n(J4=>{const f4=wn(xt(Me)("new target node identifier")),zp=Mp._3&&!uu._3?k(uu._1,uu._2,!0):uu;return n(N4=>f4(zp,n,r,o,(cu,Wp)=>n(v4=>i(zp._3&&!cu._3?k(cu._1,cu._2,!0):cu,{op:Xn("RepointEdge",{from:L,to:Ct,newFrom:Ze,newTo:Wp._1}),operands:[E,pt,_n,Wp._2]}))))})))})))})))})))})))})))})))})))})))})))})))})))})))})))})(),VL=(t,e,n,r,o)=>e(i=>ls(t,e,n,r,(s,a)=>e(u=>{const c=En(ls),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=z0(Pi(a)+zr(jt(le.foldr,f)));return(()=>{if(p.tag==="Just"){const m=p._1;return(J,x,y,T,b)=>b(J,m)}if(p.tag==="Nothing")return(m,J,x,y,T)=>T(m,0);g()})()(_._3&&!l._3?k(l._1,l._2,!0):l,e,n,r,o)})))}))),XL=t=>(e,n,r,o,i)=>{const s=e._3;return n(a=>cn(t)(e,n,r,(u,c)=>o(k(u._1,u._2,s),c),(u,c)=>n(_=>{const d=Ji((()=>{const f=xt(At(p=>p==="_"))("'_'"),h=xt(At(p=>p==="-"))("'-'");return(p,m,J,x,y)=>{const T=p._1,b=p._2;return m(L=>Va(k(T,b,!1),m,J,(E,B)=>{const z=E._3;return m(U=>{if(z)return x(E,B);const I=p._1,A=p._2;return m(j=>ls(k(I,A,!1),m,J,(Z,M)=>{const W=Z._3;return m(O=>{if(W)return x(Z,M);const D=p._1,F=p._2;return m(S=>f(k(D,F,!1),m,J,(G,Q)=>{const V=G._3;return m(Y=>V?x(G,Q):h(p,m,J,x,y))},y))})},y))})},y))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(f=>d(l,n,r,(h,p)=>o(k(h._1,h._2,s),p),(h,p)=>n(m=>{const J=l._3&&!h._3?k(h._1,h._2,!0):h;return n(x=>dn(J,n,r,(y,T)=>o(k(y._1,y._2,s),T),(y,T)=>n(b=>i(J._3&&!y._3?k(y._1,y._2,!0):y,t))))})))})))},Jn=t=>(e,n,r,o,i)=>{const s=e._3;return n(a=>cn(t)(e,n,r,(u,c)=>o(k(u._1,u._2,s),c),(u,c)=>n(_=>{const d=Ji((()=>{const f=xt(At(p=>p==="_"))("'_'"),h=xt(At(p=>p==="-"))("'-'");return(p,m,J,x,y)=>{const T=p._1,b=p._2;return m(L=>Va(k(T,b,!1),m,J,(E,B)=>{const z=E._3;return m(U=>{if(z)return x(E,B);const I=p._1,A=p._2;return m(j=>ls(k(I,A,!1),m,J,(Z,M)=>{const W=Z._3;return m(O=>{if(W)return x(Z,M);const D=p._1,F=p._2;return m(S=>f(k(D,F,!1),m,J,(G,Q)=>{const V=G._3;return m(Y=>V?x(G,Q):h(p,m,J,x,y))},y))})},y))})},y))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(f=>d(l,n,r,(h,p)=>o(k(h._1,h._2,s),p),(h,p)=>n(m=>i(l._3&&!h._3?k(h._1,h._2,!0):h,void 0))))})))},YL=(t,e,n,r,o)=>e(i=>Jn("into")(t,e,n,r,(s,a)=>e(u=>{const c=xt(Zr)("space after 'into'"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=wn(xt(Me)("node identifier after 'into'")),m=_._3&&!l._3?k(l._1,l._2,!0):l;return e(J=>p(m,e,n,r,(x,y)=>e(T=>o(m._3&&!x._3?k(x._1,x._2,!0):x,{op:Xn("Enter",{id:y._1}),operands:[y._2]}))))})))}))),UL=(t,e,n,r,o)=>e(i=>Jn("out")(t,e,n,r,(s,a)=>e(u=>o(t._3&&!s._3?k(s._1,s._2,!0):s,{op:l5,operands:[]})))),KL=(t,e,n,r,o)=>e(i=>Jn("seed")(t,e,n,r,(s,a)=>e(u=>{const c=t._3&&!s._3?k(s._1,s._2,!0):s;return e(_=>ee(c,e,n,r,(d,l)=>e(f=>{const h=xt(VL)("integer (seed value)"),p=c._3&&!d._3?k(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(J,x)=>e(y=>{const T=p._3&&!J._3?k(J._1,J._2,!0):J;return e(b=>dn(T,e,n,r,(L,E)=>e(B=>o(T._3&&!L._3?k(L._1,L._2,!0):L,x))))})))})))}))),rp=(t,e,n,r,o)=>{const i=t._3;return e(s=>Jn("diagram")(t,e,n,(a,u)=>r(k(a._1,a._2,i),u),(a,u)=>e(c=>{const _=xt(Zr)("space after 'diagram'"),d=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>_(d,e,n,(f,h)=>r(k(f._1,f._2,i),h),(f,h)=>e(p=>{const m=xt(Jn("sequence"))("diagram mode"),J=d._3&&!f._3?k(f._1,f._2,!0):f;return e(x=>m(J,e,n,(y,T)=>r(k(y._1,y._2,i),T),(y,T)=>e(b=>{const L=J._3&&!y._3?k(y._1,y._2,!0):y;return e(E=>Zh(L,e,n,(B,z)=>r(k(B._1,B._2,i),z),(B,z)=>e(U=>o(L._3&&!B._3?k(B._1,B._2,!0):B,d5))))})))})))})))},op=(t,e,n,r,o)=>{const i=t._3;return e(s=>Jn("still")(t,e,n,(a,u)=>r(k(a._1,a._2,i),u),(a,u)=>e(c=>{const _=t._3&&!a._3?k(a._1,a._2,!0):a;return e(d=>Zh(_,e,n,(l,f)=>r(k(l._1,l._2,i),f),(l,f)=>e(h=>o(_._3&&!l._3?k(l._1,l._2,!0):l,f5))))})))},ip=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(a=>op(k(i,s,!1),e,n,(u,c)=>{const _=u._3;return e(d=>_?r(u,c):rp(t,e,n,r,o))},o))},jL=t=>(e,n,r,o,i)=>n(s=>Kn(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>{const l=_._3;return ip(_,n,r,(f,h)=>o(k(f._1,f._2,l),h),(f,h)=>n(p=>o(_._3&&!f._3?k(f._1,f._2,!0):f,hr((()=>{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))))})}))),ZL=t=>(e,n,r,o,i)=>n(s=>Kn(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>{const l=(p,m)=>n(J=>(()=>{if(m.tag==="Just"){const x=(()=>{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(y,T,b,L,E)=>L(y,hr(x,u))}if(m.tag==="Nothing")return(x,y,T,b,L)=>L(x,void 0);g()})()(_._3&&!p._3?k(p._1,p._2,!0):p,n,r,o,i)),f=_._1,h=_._2;return n(p=>n(m=>ip(k(f,h,!1),n,r,(J,x)=>{const y=J._3;return n(T=>y?o(J,x):l(_,w))},(J,x)=>n(y=>l(J,N("Just",x))))))})}))),tS=(t,e,n,r,o)=>e(i=>{const s=(c,_)=>e(d=>{const l=t._3&&!c._3?k(c._1,c._2,!0):c;return e(f=>dn(l,e,n,r,(h,p)=>e(m=>{const J=l._3&&!h._3?k(h._1,h._2,!0):h;return e(x=>ZL(_)(J,e,n,r,(y,T)=>e(b=>o(J._3&&!y._3?k(y._1,y._2,!0):y,_))))})))}),a=t._1,u=t._2;return e(c=>op(k(a,u,!1),e,n,(_,d)=>{const l=_._3;return e(f=>l?r(_,d):rp(t,e,n,r,s))},s))}),eS=(t,e,n,r,o)=>e(i=>{const s=(c,_)=>e(d=>o(c,(()=>{if(_.tag==="Nothing")return _5;if(_.tag==="Just")return _._1;g()})())),a=t._1,u=t._2;return e(c=>e(_=>tS(k(a,u,!1),e,n,(d,l)=>{const f=d._3;return e(h=>f?r(d,l):s(t,w))},(d,l)=>e(f=>s(d,N("Just",l))))))}),nS=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>ee(t,e,n,(u,c)=>r(k(u._1,u._2,s),c),(u,c)=>e(_=>Jn("via")(t._3&&!u._3?k(u._1,u._2,!0):u,e,n,(d,l)=>r(k(d._1,d._2,s),l),(d,l)=>e(f=>{const h=t._3&&!d._3?k(d._1,d._2,!0):d;return e(p=>Oa(h,e,n,r,(m,J)=>e(x=>{const y=h._3&&!m._3?k(m._1,m._2,!0):m;return e(T=>Zr(y,e,n,r,(b,L)=>e(E=>{const B=xt(Me)("source node identifier after 'via'"),z=y._3&&!b._3?k(b._1,b._2,!0):b;return e(U=>B(z,e,n,r,(I,A)=>e(j=>{const Z=z._3&&!I._3?k(I._1,I._2,!0):I;return e(M=>ee(Z,e,n,r,(W,O)=>e(D=>{const F=xt(Me)("target node identifier after 'via'"),S=Z._3&&!W._3?k(W._1,W._2,!0):W;return e(G=>F(S,e,n,r,(Q,V)=>e(Y=>o(S._3&&!Q._3?k(Q._1,Q._2,!0):Q,{from:A,to:V}))))})))})))})))})))})))))}),rS=t=>e=>{const n=En(nS);return(r,o,i,s,a)=>o(u=>n(r,o,i,s,(c,_)=>o(d=>a(r._3&&!c._3?k(c._1,c._2,!0):c,{op:Xn("DelNode",{id:t,via:jt(le.foldr,_)}),operands:[e]}))))},oS=(()=>{const t=xt(At(e=>e==="-"))("'-'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=xt(Zr)("space after '-'"),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=wn(xt(Me)("node identifier after '-'")),J=d._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(J,n,r,o,(y,T)=>n(b=>{const L=T._1,E=T._2,B=J._3&&!y._3?k(y._1,y._2,!0):y;return n(z=>tp(B,n,r,o,(U,I)=>n(A=>(()=>{if(I.tag==="Just")return qL(L)(E)(I._1);if(I.tag==="Nothing")return rS(L)(E);g()})()(B._3&&!U._3?k(U._1,U._2,!0):U,n,r,o,i))))})))})))})))})(),jn=t=>e=>(n,r,o,i,s)=>r(a=>Kn(n,r,o,i,(u,c)=>r(_=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return r(l=>Jn(t)(d,r,o,i,(f,h)=>r(p=>i(d._3&&!f._3?k(f._1,f._2,!0):f,hr(e,c)))))}))),iS=t=>t==="AnimatedSurface"?(e,n,r,o,i)=>n(s=>Kn(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>Jn("step")(_,n,r,o,(l,f)=>n(h=>{const p=xt(Zr)("space after 'step'"),m=_._3&&!l._3?k(l._1,l._2,!0):l;return n(J=>p(m,n,r,o,(x,y)=>n(T=>{const b=wn(xt(Me)("step name")),L=m._3&&!x._3?k(x._1,x._2,!0):x;return n(E=>b(L,n,r,o,(B,z)=>n(U=>{const I=z._1,A=z._2,j=L._3&&!B._3?k(B._1,B._2,!0):B;return n(Z=>Kn(j,n,r,o,(M,W)=>n(O=>{const D=j._3&&!M._3?k(M._1,M._2,!0):M;return n(F=>ee(D,n,r,o,(S,G)=>n(Q=>{const V=D._3&&!S._3?k(S._1,S._2,!0):S;return n(Y=>Kh(V,n,r,o,(X,q)=>n(K=>{const et=V._3&&!X._3?k(X._1,X._2,!0):X;return n(lt=>dn(et,n,r,o,(Ct,pt)=>n(Tt=>{const Et={line:u.line,column:u.column,endLine:W.line,endColumn:W.column};return i(et._3&&!Ct._3?k(Ct._1,Ct._2,!0):Ct,{name:N("Just",I),ops:dr("Leaf",{op:Xn("Step",{name:I}),line:Et.line,column:Et.column,endLine:Et.endLine,endColumn:Et.endColumn,span:Et,operands:[A]}),kind:Dh})})))})))})))})))})))})))})))}))):jn("step")("`step` markers are only supported in animated diagrams."),sS=(()=>{const t=xt(At(e=>e===":"))("':'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>ee(_,n,r,o,(l,f)=>n(h=>{const p=En(At(vL)),m=_._3&&!l._3?k(l._1,l._2,!0):l;return n(J=>p(m,n,r,o,(x,y)=>n(T=>i(m._3&&!x._3?k(x._1,x._2,!0):x,Fs(zr(jt(le.foldr,y)))))))})))})))})(),aS=(t,e,n,r,o)=>e(i=>ee(t,e,n,r,(s,a)=>e(u=>xt((c,_,d,l,f)=>{const h=c._1,p=c._2;return _(m=>sS(k(h,p,!1),_,d,(J,x)=>{const y=J._3;return _(T=>{if(y)return l(J,x);const b=c._1,L=c._2;return _(E=>QL(k(b,L,!1),_,d,(B,z)=>{const U=B._3;return _(I=>U?l(B,z):AL(c,_,d,l,f))},f))})},f))})('label ("\u2026", : rest-of-line, or |\u2026|)')(t._3&&!s._3?k(s._1,s._2,!0):s,e,n,r,o)))),Xa=t=>(e,n,r,o,i)=>n(s=>ee(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>{const l=(p,m)=>n(J=>(m?((x,y,T,b,L)=>L(x,w)):(x,y,T,b,L)=>y(E=>aS(x,y,T,b,(B,z)=>y(U=>L(B,N("Just",z))))))(_._3&&!p._3?k(p._1,p._2,!0):p,n,r,o,i)),f=_._1,h=_._2;return n(p=>{const m=(J,x)=>{const y=J._3;return n(T=>y?o(J,x):l(_,!1))};return n(J=>n(x=>n(y=>ds(k(f,h,!1),n,r,(T,b)=>{const L=T._3;return n(E=>L?m(k(f,h,!1),b):n(B=>At(t)(k(f,h,!1),n,r,(z,U)=>m(k(f,h,!1),U),(z,U)=>n(I=>n(A=>l(k(f,h,!1),!0))))))},(T,b)=>n(L=>n(E=>l(k(f,h,!1),!0)))))))})})}))),uS=t=>e=>n=>(r,o,i,s,a)=>o(u=>ee(r,o,i,s,(c,_)=>o(d=>{const l=wn(xt(Me)("target node identifier")),f=r._3&&!c._3?k(c._1,c._2,!0):c;return o(h=>l(f,o,i,s,(p,m)=>o(J=>{const x=m._1,y=m._2,T=f._3&&!p._3?k(p._1,p._2,!0):p;return o(b=>Xa(Vg)(T,o,i,s,(L,E)=>o(B=>a(T._3&&!L._3?k(L._1,L._2,!0):L,{op:Xn("AddEdge",{from:t,to:x,label:E.tag==="Just"?N("Just",E._1):w,directed:n}),operands:[e,y]}))))})))}))),cS=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>wn(Me)(t,e,n,(u,c)=>r(k(u._1,u._2,s),c),(u,c)=>e(_=>{const d=t._3&&!u._3?k(u._1,u._2,!0):u;return e(l=>ee(d,e,n,(f,h)=>r(k(f._1,f._2,s),h),(f,h)=>e(p=>{const m=xt(At(x=>x==="<"))("'<'"),J=d._3&&!f._3?k(f._1,f._2,!0):f;return e(x=>m(J,e,n,(y,T)=>r(k(J._1,J._2,s),T),(y,T)=>e(b=>{const L=Ji((B,z,U,I,A)=>{const j=B._3;return cn("<-")(B,z,U,(Z,M)=>I(k(Z._1,Z._2,j),M),A)}),E=J._3&&!J._3?k(J._1,J._2,!0):J;return e(B=>L(E,e,n,(z,U)=>r(k(z._1,z._2,s),U),(z,U)=>e(I=>{const A=E._3&&!z._3?k(z._1,z._2,!0):z;return e(j=>{const Z=c._1,M=c._2,W=t._3&&!A._3?k(A._1,A._2,!0):A;return e(O=>ee(W,e,n,r,(D,F)=>e(S=>{const G=xt(cn("<~"))("'<~'"),Q=W._3&&!D._3?k(D._1,D._2,!0):D;return e(V=>G(Q,e,n,r,(Y,X)=>e(q=>{const K=Q._3&&!Y._3?k(Y._1,Y._2,!0):Y;return e(et=>ee(K,e,n,r,(lt,Ct)=>e(pt=>{const Tt=wn(xt(Me)("target node identifier")),Et=K._3&&!lt._3?k(lt._1,lt._2,!0):lt;return e(Zt=>Tt(Et,e,n,r,(bt,Ut)=>e(Bt=>{const wt=Ut._1,mt=Ut._2,ct=Et._3&&!bt._3?k(bt._1,bt._2,!0):bt;return e(yt=>Xa(Vg)(ct,e,n,r,(dt,ht)=>e(Lt=>o(ct._3&&!dt._3?k(dt._1,dt._2,!0):dt,{op:Xn("Token",{from:wt,to:Z,labels:(()=>{if(ht.tag==="Nothing")return[];if(ht.tag==="Just")return[ht._1];g()})()}),operands:[mt,M]}))))})))})))})))})))})})))})))})))})))}),gS=(t,e,n,r,o)=>e(i=>HL(t,e,n,r,(s,a)=>e(u=>{const c=a._2._2,_=a._1,d=a._2._1,l=t._3&&!s._3?k(s._1,s._2,!0):s;return e(f=>ee(l,e,n,r,(h,p)=>e(m=>{const J=wn(xt(Me)("target node identifier")),x=l._3&&!h._3?k(h._1,h._2,!0):h;return e(y=>J(x,e,n,r,(T,b)=>e(L=>{const E=b._1,B=b._2,z=x._3&&!T._3?k(T._1,T._2,!0):T;return e(U=>Xa(Vg)(z,e,n,r,(I,A)=>e(j=>(c==="<~"?((Z,M,W,O,D)=>D(Z,{op:Xn("Token",{from:E,to:_,labels:(()=>{if(A.tag==="Nothing")return[];if(A.tag==="Just")return[A._1];g()})()}),operands:c==="<~"?[B,d]:[d,B]})):(Z,M,W,O,D)=>D(Z,{op:Xn("Token",{from:_,to:E,labels:(()=>{if(A.tag==="Nothing")return[];if(A.tag==="Just")return[A._1];g()})()}),operands:c==="<~"?[B,d]:[d,B]}))(z._3&&!I._3?k(I._1,I._2,!0):I,e,n,r,o))))})))})))}))),_S=(t,e,n,r,o)=>e(i=>Xa(CL)(t,e,n,r,(s,a)=>e(u=>o(s,(()=>{if(a.tag==="Nothing")return"";if(a.tag==="Just")return a._1;g()})())))),fS=t=>e=>(n,r,o,i,s)=>r(a=>_S(n,r,o,i,(u,c)=>r(_=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return r(l=>WL(d,r,o,i,(f,h)=>r(p=>s(d._3&&!f._3?k(f._1,f._2,!0):f,{op:Xn("AddNode",{id:t,label:c,shape:(()=>{const m=xL("shape")(h);if(m.tag==="Just")return m._1==="rectangle"||m._1==="rect"?Wr:m._1==="cylinder"||m._1==="cyl"?Mm:m._1==="parallelogram"?zm:m._1==="diamond"?Wm:m._1==="ellipse"?qm:m._1==="document"||m._1==="doc"?Om:m._1==="cloud"?Hm:Wr;if(m.tag==="Nothing")return Wr;g()})()}),operands:[e]}))))}))),dS=(()=>{const t=xt(At(e=>e==="+"))("'+'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=xt(Zr)("space after '+'"),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=wn(xt(Me)("node identifier after '+'")),J=d._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(J,n,r,o,(y,T)=>n(b=>{const L=T._1,E=T._2,B=J._3&&!y._3?k(y._1,y._2,!0):y;return n(z=>tp(B,n,r,o,(U,I)=>n(A=>(()=>{if(I.tag==="Just")return uS(L)(E)(I._1);if(I.tag==="Nothing")return fS(L)(E);g()})()(B._3&&!U._3?k(U._1,U._2,!0):U,n,r,o,i))))})))})))})))})(),lS=(t,e,n,r,o)=>e(i=>Kn(t,e,n,r,(s,a)=>e(u=>{const c=xt(Hg([jn("+node")("Node additions use `+ api: API`."),jn("+edge")("Graph edges use `+ api -> db`."),jn("+conn")("Undirected graph edges use `+ api -- db`."),jn("-node")("Node removals use `- api`."),jn("-edge")("Graph edge removals use `- api -> db`."),jn("-conn")("Undirected graph edge removals use `- api -- db`."),jn("~edge")("Graph edge repoints use `~ api -> db => api -> cache`."),jn("enter")("Dive commands use `into api`."),jn("exit")("Return from a dive with `out`."),OL,dS,oS,$L,gS,cS,YL,UL]))("statement (+ node, - node, + edge, - edge, into, out, or 'a ~> b'/'a <~ b')"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=_._3&&!l._3?k(l._1,l._2,!0):l;return e(m=>Kn(p,e,n,r,(J,x)=>e(y=>{const T={line:a.line,column:a.column,endLine:x.line,endColumn:x.column};return o(p._3&&!J._3?k(J._1,J._2,!0):J,dr("Leaf",{op:f.op,line:T.line,column:T.column,endLine:T.endLine,endColumn:T.endColumn,span:T,operands:f.operands}))})))})))}))),Xg=Yh((()=>{const t=xt(At(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(s=>n(a=>t(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return dn(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(f._1,f._2,!0):f,h)))})))))})())(xt((()=>{const t=xt(At(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(s=>n(a=>dn(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return t(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(f._1,f._2,!0):f,h)))})))))})())("closing '}'")),sp=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>dn(t,e,n,(u,c)=>r(k(u._1,u._2,s),c),(u,c)=>e(_=>{const d=Ji(xt(At(f=>f==="}"))("'}'")),l=t._3&&!u._3?k(u._1,u._2,!0):u;return e(f=>d(l,e,n,(h,p)=>r(k(h._1,h._2,s),p),(h,p)=>e(m=>Ji(ds)(l._3&&!h._3?k(h._1,h._2,!0):h,e,n,(J,x)=>r(k(J._1,J._2,s),x),(J,x)=>e(y=>{const T=t._3&&!J._3?k(J._1,J._2,!0):J;return e(b=>Oa(T,e,n,r,(L,E)=>e(B=>{const z=Hg([pS,hS,lS]),U=T._3&&!L._3?k(L._1,L._2,!0):L;return e(I=>z(U,e,n,r,(A,j)=>e(Z=>{const M=U._3&&!A._3?k(A._1,A._2,!0):A;return e(W=>ee(M,e,n,r,(O,D)=>e(F=>{const S=M._3&&!O._3?k(O._1,O._2,!0):O;return e(G=>Kh(S,e,n,r,(Q,V)=>e(Y=>{const X=S._3&&!Q._3?k(Q._1,Q._2,!0):Q;return e(q=>dn(X,e,n,r,(K,et)=>e(lt=>o(X._3&&!K._3?k(K._1,K._2,!0):K,j))))})))})))})))})))})))))})))}),hS=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(a=>{const u=(c,_)=>{const d=c._3;return e(l=>d?r(c,_):e(f=>{const h=t._3;return e(p=>Jn("seq")(t,e,n,(m,J)=>r(k(m._1,m._2,h),J),(m,J)=>e(x=>{const y=t._3&&!m._3?k(m._1,m._2,!0):m;return e(T=>ee(y,e,n,(b,L)=>r(k(b._1,b._2,h),L),(b,L)=>e(E=>$g(y._3&&!b._3?k(b._1,b._2,!0):b,e,n,(B,z)=>r(k(B._1,B._2,h),z),(B,z)=>e(U=>{const I=t._3&&!B._3?k(B._1,B._2,!0):B;return e(A=>Oa(I,e,n,r,(j,Z)=>e(M=>{const W=xt(xt(At(D=>D==="{"))("'{'"))("'{'"),O=I._3&&!j._3?k(j._1,j._2,!0):j;return e(D=>W(O,e,n,r,(F,S)=>e(G=>o(O._3&&!F._3?k(F._1,F._2,!0):F,dr("GroupSeq",[])))))})))})))))})))}))};return e(c=>e(_=>Jn("seq")(k(i,s,!1),e,n,(d,l)=>u(k(d._1,d._2,!1),l),(d,l)=>e(f=>e(h=>ee(d,e,n,(p,m)=>u(k(p._1,p._2,!1),m),(p,m)=>e(J=>{const x=d._3&&!p._3?k(p._1,p._2,!0):p;return xt(At(y=>y==="{"))("'{'")(x,e,n,(y,T)=>u(k(x._1,x._2,!1),T),(y,T)=>e(b=>Xg(Yg(y5))(x,e,n,u,o)))})))))))})},pS=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(a=>{const u=(c,_)=>{const d=c._3;return e(l=>d?r(c,_):e(f=>{const h=t._3;return e(p=>Jn("par")(t,e,n,(m,J)=>r(k(m._1,m._2,h),J),(m,J)=>e(x=>{const y=t._3&&!m._3?k(m._1,m._2,!0):m;return e(T=>ee(y,e,n,(b,L)=>r(k(b._1,b._2,h),L),(b,L)=>e(E=>$g(y._3&&!b._3?k(b._1,b._2,!0):b,e,n,(B,z)=>r(k(B._1,B._2,h),z),(B,z)=>e(U=>{const I=t._3&&!B._3?k(B._1,B._2,!0):B;return e(A=>Oa(I,e,n,r,(j,Z)=>e(M=>{const W=xt(xt(At(D=>D==="{"))("'{'"))("'{'"),O=I._3&&!j._3?k(j._1,j._2,!0):j;return e(D=>W(O,e,n,r,(F,S)=>e(G=>o(O._3&&!F._3?k(F._1,F._2,!0):F,dr("Par",[])))))})))})))))})))}))};return e(c=>e(_=>Jn("par")(k(i,s,!1),e,n,(d,l)=>u(k(d._1,d._2,!1),l),(d,l)=>e(f=>e(h=>ee(d,e,n,(p,m)=>u(k(p._1,p._2,!1),m),(p,m)=>e(J=>{const x=d._3&&!p._3?k(p._1,p._2,!0):p;return xt(At(y=>y==="{"))("'{'")(x,e,n,(y,T)=>u(k(x._1,x._2,!1),T),(y,T)=>e(b=>Xg(Yg(p5))(x,e,n,u,o)))})))))))})},Yg=t=>{const e=En(sp);return(n,r,o,i,s)=>r(a=>e(n,r,o,i,(u,c)=>r(_=>s(n._3&&!u._3?k(u._1,u._2,!0):u,t(jt(le.foldr,c))))))},Ug=t=>e=>(n,r,o,i,s)=>r(a=>XL(t)(n,r,o,i,(u,c)=>r(_=>{const d=En(At(kL)),l=n._3&&!u._3?k(u._1,u._2,!0):u;return r(f=>d(l,r,o,i,(h,p)=>r(m=>{const J=xt(xt(At(y=>y==="{"))("'{'"))("'{'"),x=l._3&&!h._3?k(h._1,h._2,!0):h;return r(y=>J(x,r,o,i,(T,b)=>r(L=>{const E=x._3&&!T._3?k(T._1,T._2,!0):T;return r(B=>dn(E,r,o,i,(z,U)=>r(I=>{const A=Yg(m5),j=E._3&&!z._3?k(z._1,z._2,!0):z;return r(Z=>A(j,r,o,i,(M,W)=>r(O=>{const D=j._3&&!M._3?k(M._1,M._2,!0):M;return r(F=>dn(D,r,o,i,(S,G)=>r(Q=>{const V=xt(xt(At(X=>X==="}"))("'}'"))("closing '}'"),Y=D._3&&!S._3?k(S._1,S._2,!0):S;return r(X=>V(Y,r,o,i,(q,K)=>r(et=>{const lt=Y._3&&!q._3?k(q._1,q._2,!0):q;return r(Ct=>dn(lt,r,o,i,(pt,Tt)=>r(Et=>s(lt._3&&!pt._3?k(pt._1,pt._2,!0):pt,{name:BL(zr(jt(le.foldr,p))),ops:W,kind:e}))))})))})))})))})))})))})))}))),mS=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(a=>jn("keyframe")("Drop the `keyframe` wrapper; Markgraf animates statements in order.")(k(i,s,!1),e,n,(u,c)=>{const _=u._3;return e(d=>{if(_)return r(u,c);const l=t._1,f=t._2;return e(h=>Ug("scene")(Ma)(k(l,f,!1),e,n,(p,m)=>{const J=p._3;return e(x=>{if(J)return r(p,m);const y=t._1,T=t._2;return e(b=>Ug("still")(Mg)(k(y,T,!1),e,n,(L,E)=>{const B=L._3;return e(z=>B?r(L,E):Ug("title")(h5)(t,e,n,r,o))},o))})},o))})},o))},yS=t=>e=>n=>{if(t==="AnimatedSurface")return{...e,frames:Pt(e.frames)({name:w,ops:n,kind:Ma})};if(t==="StillSurface")return{...e,statements:Pt(e.statements)(n)};if(t==="SequenceSurface")return{...e,statements:Pt(e.statements)(n)};g()},xS=t=>e=>n=>{if(n.tag==="TopFrame"){const r=ep(t)(e);return{...r,frames:Pt(r.frames)((()=>{if(t==="AnimatedSurface")return n._1;if(t==="StillSurface")return{...n._1,kind:n._1.kind==="AnimatedKeyframe"?Mg:n._1.kind==="StepMarker"?Dh:n._1.kind};if(t==="SequenceSurface")return n._1;g()})())}}if(n.tag==="TopStatement")return yS(t)(e)(n._1);if(n.tag==="TopInside")return e;g()},wS=t=>{const e=v(xS(t))(RL);return n=>ep(t)(e(n)).frames},JS=t=>oL.defer(e=>{const n=iS(t);return(r,o,i,s,a)=>{const u=r._1,c=r._2;return o(_=>jL(t)(k(u,c,!1),o,i,(d,l)=>{const f=d._3;return o(h=>{if(f)return s(d,l);const p=r._1,m=r._2;return o(J=>o(x=>NS(k(p,m,!1),o,i,(y,T)=>{const b=y._3;return o(L=>{if(b)return s(y,T);const E=r._1,B=r._2;return o(z=>o(U=>n(k(E,B,!1),o,i,(I,A)=>{const j=I._3;return o(Z=>{if(j)return s(I,A);const M=r._1,W=r._2;return o(O=>o(D=>mS(k(M,W,!1),o,i,(F,S)=>{const G=F._3;return o(Q=>G?s(F,S):o(V=>sp(r,o,i,s,(Y,X)=>o(q=>a(Y,$a("TopStatement",X))))))},(F,S)=>o(G=>a(F,$a("TopFrame",S))))))})},(I,A)=>o(j=>a(I,$a("TopFrame",A))))))})},(y,T)=>o(b=>a(y,$a("TopInside",T))))))})},a))}}),NS=(t,e,n,r,o)=>e(i=>Jn("inside")(t,e,n,r,(s,a)=>e(u=>{const c=xt(Zr)("space after 'inside'"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=xt(Me)("node identifier after 'inside'"),m=_._3&&!l._3?k(l._1,l._2,!0):l;return e(J=>p(m,e,n,r,(x,y)=>e(T=>{const b=m._3&&!x._3?k(x._1,x._2,!0):x;return e(L=>dn(b,e,n,r,(E,B)=>e(z=>{const U=b._3&&!E._3?k(E._1,E._2,!0):E;return e(I=>Xg(ap)(U,e,n,r,(A,j)=>e(Z=>{const M=U._3&&!A._3?k(A._1,A._2,!0):A;return e(W=>dn(M,e,n,r,(O,D)=>e(F=>o(M._3&&!O._3?k(O._1,O._2,!0):O,{node:y,doc:j}))))})))})))})))})))}))),ap=(t,e,n,r,o)=>e(i=>eS(t,e,n,r,(s,a)=>e(u=>{const c=t._3&&!s._3?k(s._1,s._2,!0):s;return e(_=>{const d=(h,p)=>e(m=>{const J=En(JS(a)),x=c._3&&!h._3?k(h._1,h._2,!0):h;return e(y=>J(x,e,n,r,(T,b)=>e(L=>{const E=jt(le.foldr,b);return o(x._3&&!T._3?k(T._1,T._2,!0):T,{seed:(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})(),mode:a,frames:wS(a)(E),interiors:vt(B=>{if(B.tag==="TopInside")return N("Just",B._1);if(B.tag==="TopFrame"||B.tag==="TopStatement")return w;g()})(E)})})))}),l=c._1,f=c._2;return e(h=>e(p=>KL(k(l,f,!1),e,n,(m,J)=>{const x=m._3;return e(y=>x?r(m,J):d(c,w))},(m,J)=>e(x=>d(m,N("Just",J))))))})}))),vS=(()=>{const t=xt((e,n,r,o,i)=>n(s=>n(a=>dn(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return ds(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(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(s=>n(a=>n(u=>n(c=>dn(e,n,r,o,(_,d)=>n(l=>n(f=>{const h=e._3&&!_._3?k(_._1,_._2,!0):_;return ap(h,n,r,o,(p,m)=>n(J=>{const x=h._3&&!p._3?k(p._1,p._2,!0):p;return n(y=>n(T=>{const b=e._3&&!x._3?k(x._1,x._2,!0):x;return t(b,n,r,o,(L,E)=>n(B=>i(b._3&&!L._3?k(L._1,L._2,!0):L,m)))}))}))})))))))})(),TS=t=>{const e=uL(t)(vS);if(e.tag==="Left")return Wt("Left",{msg:PL(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 Wt("Right",e._1);g()},bS=t=>{const e=TS(t);if(e.tag==="Left")return Wt("Left",e._1.msg);if(e.tag==="Right")return Wt("Right",e._1);g()},CS=()=>({tag:"ParFrag"}),up=t=>t,kS=up("Sync"),LS=up("SelfMsg"),SS=CS(),to=Gh(Tn),Ni=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 s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},qn=So(Tn),Ir=to.state(t=>C(t,t)),cp=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ya=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Po=Eo(Tn),ES=t=>e=>v(n=>r=>So(Tn).bind(n)(o=>t(o)(r)))(Eo(Tn).pure(e)),gp=Ar(Po)(Mt),GS=t=>to.state(e=>C(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:N("Just",t)};g()})())),PS=t=>e=>to.state(n=>C(void 0,{...n,lifelines:J_(P)(r=>N("Just",{...r,label:e}))(t)(n.lifelines)})),BS=t=>e=>n=>{const r=Ni(n)(t.lifelines);return Ni(e)(t.lifelines).tag==="Nothing"?r.tag==="Nothing"?e+", "+n:e:r.tag==="Nothing"?n:""},DS={lifelines:R,lifelineOrder:[],messages:[],fragments:[],frameEndRows:[],row:0,error:w},IS=t=>e=>n=>qn.bind(Ir)(r=>{const o=Ni(t)(r.lifelines),i=Ni(e)(r.lifelines);if(o.tag==="Just"&&i.tag==="Just"){const s={...r,messages:[{fromCol:o._1.column,toCol:i._1.column,labels:n,row:r.row,kind:t===e?LS:kS},...r.messages],row:r.row+1|0};return to.state(a=>C(void 0,s))}return GS("token references unknown node: "+BS(r)(t)(e))}),AS=t=>to.state(e=>C(void 0,{...e,lifelines:J_(P)(n=>N("Just",{...n,destroyedAt:N("Just",e.row)}))(t)(e.lifelines)})),RS=t=>e=>{const n=e.lifelineOrder.length,r=zt(o=>w,o=>i=>N("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return{fromCol:0,toCol:Ya(0)(e.lifelineOrder.length-1|0)};if(r.tag==="Just")return v(o=>i=>({fromCol:cp(o.fromCol)(cp(i.fromCol)(i.toCol)),toCol:Ya(o.toCol)(Ya(i.fromCol)(i.toCol))}))({fromCol:n,toCol:0})(t);g()},FS=t=>({lifelines:vt(e=>Ni(e)(t.lifelines))(t.lifelineOrder),messages:se(t.messages),fragments:se(t.fragments),frameEndRows:t.frameEndRows,totalRows:t.row}),QS=t=>e=>qn.bind(Ir)(n=>{const r=Ni(t)(n.lifelines);if(r.tag==="Just")return Po.pure();if(r.tag==="Nothing"){const o={...n,lifelines:rt(P)(t)({id:t,label:e,column:n.lifelineOrder.length,createdAt:n.row,destroyedAt:w})(n.lifelines),lifelineOrder:Pt(n.lifelineOrder)(t),row:n.row>0||n.messages.length!==0?n.row+1|0:n.row};return to.state(i=>C(void 0,o))}g()}),MS=t=>{if(t.tag==="AddNode")return QS(t._1.id)(t._1.label);if(t.tag==="DelNode")return AS(t._1.id);if(t.tag==="ModNode"){if(t._1.label.tag==="Just")return PS(t._1.id)(t._1.label._1);if(t._1.label.tag==="Nothing")return Po.pure();g()}return t.tag==="Token"?IS(t._1.from)(t._1.to)(t._1.labels):Po.pure()},zS=t=>qn.bind(Ir)(e=>{const n=e.row;return qn.bind(ES(r=>o=>qn.bind(Ir)(i=>{const s=r.childMessages.length===0?r.dividers:[i.row,...r.dividers],a=i.messages;return qn.bind(Kg(o))(()=>qn.bind(Ir)(u=>Po.pure({dividers:s,childMessages:[...r.childMessages,...(()=>{const c=u.messages.length-a.length|0;return c<1?[]:Dt(0,c,u.messages)})()]})))}))({dividers:[],childMessages:[]})(t))(r=>qn.bind(Ir)(o=>{const i=RS(r.childMessages)(o),s={kind:SS,label:"par",fromRow:n,toRow:Ya(o.row)(n+1|0),fromCol:i.fromCol,toCol:i.toCol,regionDividers:se(r.dividers)},a=to.state(u=>C(void 0,{...u,fragments:[s,...u.fragments]}));return r.childMessages.length>=2?a:Po.pure()}))}),Kg=t=>{if(t.tag==="Leaf")return MS(t._1.op);if(t.tag==="Seq"||t.tag==="GroupSeq")return gp(Kg)(t._1);if(t.tag==="Par")return zS(t._1);g()},WS=t=>{const e=qn.bind(gp(n=>qn.bind(Ir)(r=>qn.bind(Kg(n.ops))(()=>qn.bind(Ir)(o=>{const i=to.state(s=>C(void 0,{...s,frameEndRows:Pt(s.frameEndRows)(s.row-1|0)}));return(o.messages.length-r.messages.length|0)>0?i:Po.pure()}))))(t.frames))(()=>Ir)(DS)._1;if(e.error.tag==="Just")return Wt("Left",e.error._1);if(e.error.tag==="Nothing")return Wt("Right",FS(e));g()},qS=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},OS={padding:24,headerHeight:36,headerWidth:120,columnSpacing:160,rowHeight:36,topGap:24,bottomGap:24},HS=t=>{const e=84+nt(qS(1)(t.totalRows))*36,n=Ht(r=>o=>({lifeline:o,x:84+nt(r)*160}))(t.lifelines);return{metrics:OS,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}},$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 s=ot.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},_p=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fp=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 s=ot.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},dp=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},VS=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},XS=v(t=>e=>rt(ot)(e)()(t))(R),YS={r:255,g:255,b:255,a:255},Ua={r:26,g:26,b:26,a:255},US={color:{r:232,g:232,b:232,a:255},flat:!0},KS={r:232,g:232,b:232,a:255},Ka=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,...rs],lp=t=>e=>n=>({...n,stack:Pt(n.stack)(t),openedAt:rt(ot)(t)(e)(n.openedAt)}),ja=t=>e=>{const n=e.stack.length-1|0;if(n>=0&&n<e.stack.length){const r=$S(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?[]:Dt(0,e.stack.length-1|0,e.stack),openedAt:zo(ot)(e.stack[n])(e.openedAt),spans:Pt(e.spans)({col:e.stack[n],fromRow:o,toRow:_p(o)(t)})}}return e},hp=t=>e=>n=>{let r=t,o=e,i=n,s=!0,a;for(;s;){const u=r,c=o,_=i,d=_.stack.length-1|0;if(d>=0&&d<_.stack.length){if(u(_.stack[d])){s=!1,a=_;continue}r=u,o=c,i=ja(c)(_);continue}s=!1,a=_}return a},pp=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r,u=a.stack.length-1|0;if(u>=0&&u<a.stack.length){n=s,r=ja(s)(a);continue}o=!1,i=a}return i},jS=t=>e=>{const n=tn(Rr)(e.fromCol)(t.stack)?hp((()=>{const r=e.fromCol;return o=>r===o})())(e.row-1|0)(t):lp(e.fromCol)(e.row)(pp(e.row-1|0)(t));if(tn(Rr)(e.toCol)(n.stack)){const r=hp((()=>{const o=e.toCol;return i=>o===i})())(e.row-1|0)(ja(e.row)(n));return{...r,returnRows:rt(ot)(e.row)()(r.returnRows)}}return lp(e.toCol)(e.row)(n)},ZS=t=>e=>n=>{const r=jS(e)(n);return fp(n.row)(t)?pp(n.row)(r):r},Za={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:es,lineCap:Vn},mp={r:26,g:26,b:26,a:255},tE={color:{r:130,g:130,b:130,a:255},width:1,lineJoin:es,lineCap:Ln},yp={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:es,lineCap:Ln},eE={color:{r:244,g:244,b:244,a:255},flat:!0},xp=t=>e=>n=>Ne(r=>r.col===e&&r.fromRow<=n&&n<=r.toRow,t),wp={color:{r:90,g:90,b:90,a:255},width:1,lineJoin:es,lineCap:Ln},nE={stack:[],openedAt:R,spans:[],returnRows:R},rE={color:{r:150,g:150,b:150,a:255},width:1,lineJoin:es,lineCap:Ln},oE=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])(rE)},iE=t=>{const e=t.Monad0(),n=e.Bind1(),r=Ao(e.Applicative0())(Mt);return o=>i=>{const s=o.bodyTop+(nt(i.fromRow)+.5)*o.metrics.rowHeight-o.metrics.rowHeight/2-6,a=i.fromCol>=0&&i.fromCol<o.columns.length?o.columns[i.fromCol].x-16:o.metrics.padding-16,u=[1,a,s,2,a+38,s,2,a+32,s+14,2,a,s+14,...rs],c=i.toCol>=0&&i.toCol<o.columns.length?o.columns[i.toCol].x+16:o.metrics.padding+16,_=o.bodyTop+(nt(_p(i.toRow)(i.fromRow+1|0)-1|0)+.5)*o.metrics.rowHeight+o.metrics.rowHeight/2+6;return n.bind(t.strokePath([1,a,s,2,c,s,2,c,_,2,a,_,...rs])(wp))(()=>n.bind(t.fillStrokePath(u)(US)(wp))(()=>n.bind(t.drawText({x:a+6,y:s+7,content:"par",font:{family:"Inter",size:11,weight:700},color:Ua,align:ci,baseline:kn}))(()=>r(i.regionDividers)(oE(t)(o)(a)(c)))))}},Jp=t=>e=>t>=e?[]:[C(t,dp(e)(t+6)),...Jp(t+10)(e)],sE=t=>e=>{if(e<=t)return[];const n=r=>r>=e?[]:[C(r,dp(e)(r+6)),...n(r+10)];return n(t)},aE=t=>{const e=Ao(t.Monad0().Applicative0())(Mt);return n=>r=>e(sE(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])(tE))},Np=t=>e=>t<=e?[]:[C(t,VS(e)(t-6)),...Np(t-6-4)(e)],uE=t=>e=>t===e?[]:t<e?Jp(t)(e):Np(t)(e),cE=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,s=o+n.metrics.headerHeight,a=Ka(r.x-i)(o)(r.x+i)(s)(6);return e.bind(t.fillStrokePath(Ka(r.x-i)(o+5)(r.x+i)(s+5)(6))({color:KS,flat:!0})(yp))(()=>e.bind(t.fillStrokePath(a)(eE)(yp))(()=>t.drawText({x:r.x,y:o+n.metrics.headerHeight/2,content:r.lifeline.label,font:{family:"Inter",size:14,weight:600},color:Ua,align:Lr,baseline:kn})))}},gE=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r,u=a.stack.length-1|0;if(u>=0&&u<a.stack.length){n=s,r=ja(s)(a);continue}o=!1,i=a}return i},_E=t=>gE((()=>{const e=t.diagram.messages.length-1|0;return e>=0&&e<t.diagram.messages.length?t.diagram.messages[e].row:0})())(v(ZS(XS(t.diagram.frameEndRows)))(nE)(ft(e=>e.kind==="Sync"||e.kind!=="SelfMsg",t.diagram.messages))),fE=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,s=o-n.metrics.rowHeight*.3,a=i+36,u=o+n.metrics.rowHeight*.3,c=i+10,_=[1,i,u,2,c,u-5,2,c,u+5,...rs];return e.bind(t.strokePath([1,i,s,2,a,s,2,a,u,2,i,u])(Za))(()=>e.bind(t.fillPath(_)({color:mp,flat:!0}))(()=>t.drawText({x:i+42,y:o,content:rr(" ")($(bi)(r.labels)),font:{family:"Inter",size:12,weight:400},color:Ua,align:ci,baseline:kn})))}},dE=t=>{const e=t.Monad0(),n=e.Bind1(),r=Ao(e.Applicative0())(Mt);return o=>i=>s=>a=>{const u=s?o.bodyTop+(nt(a.row)+.5)*o.metrics.rowHeight+o.metrics.rowHeight*.5:o.bodyTop+(nt(a.row)+.5)*o.metrics.rowHeight,c=a.toCol>=a.fromCol?1:-1,_=(a.fromCol>=0&&a.fromCol<o.columns.length?o.columns[a.fromCol].x:o.metrics.padding)+(xp(i)(a.fromCol)(a.row)?c*6:c*0),d=(a.toCol>=0&&a.toCol<o.columns.length?o.columns[a.toCol].x:o.metrics.padding)-(xp(i)(a.toCol)(a.row)?c*6:c*0),l=d-c*10,f=s?t.strokePath([1,l,u-5,2,d,u,2,l,u+5])(Za):t.fillPath([1,d,u,2,l,u-5,2,l,u+5,...rs])({color:mp,flat:!0});return n.bind(s?r(uE(_)(d))(h=>t.strokePath([1,h._1,u,2,h._2,u])(Za)):t.strokePath([1,_,u,2,d,u])(Za))(()=>n.bind(f)(()=>t.drawText({x:(_+d)/2,y:u-6,content:rr(" ")($(bi)(a.labels)),font:{family:"Inter",size:12,weight:400},color:Ua,align:Lr,baseline:Yv})))}},lE=t=>{const e=fE(t),n=dE(t);return r=>o=>i=>s=>{if(s.kind==="SelfMsg")return e(r)(s);if(s.kind==="Sync")return n(r)(o)(fp(s.row)(i))(s);g()}},vp={color:{r:26,g:26,b:26,a:255},width:1.25,lineJoin:$e,lineCap:Ln},hE={color:{r:232,g:232,b:232,a:255},flat:!0},pE={color:{r:252,g:252,b:252,a:255},flat:!0},mE=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,s=Ka(r-6)(o)(r+6)(i)(3);return t.Monad0().Bind1().bind(t.fillStrokePath(Ka(r-6)(o+5)(r+6)(i+5)(3))(hE)(vp))(()=>t.fillStrokePath(s)(pE)(vp))},Tp=t=>{const e=t.Monad0(),n=e.Bind1(),r=Ao(e.Applicative0())(Mt),o=cE(t),i=aE(t),s=iE(t),a=lE(t);return u=>{const c=_E(u);return n.bind(t.setViewport({vx:0,vy:0,vw:u.width,vh:u.height}))(()=>n.bind(t.clearBackground(YS))(()=>n.bind(r(u.columns)(o(u)))(()=>n.bind(r(u.columns)(i(u)))(()=>n.bind(r(c.spans)(mE(t)(u)))(()=>n.bind(r(u.diagram.fragments)(s(u)))(()=>r(u.diagram.messages)(a(u)(c.spans)(c.returnRows))))))))}},yE=Tp(lT);function jg(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 s=Object.getPrototypeOf(i),a=s.constructor.name;if(a===n)return e(r);if(a==="Object")return t;i=s}return t}function gn(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function xE(t){return function(e){return function(){return e.getAttribute(t)}}}const bp=t=>{const e=xE(t);return n=>{const r=e(n);return()=>{const o=r();return pn(o,w,Yt)}}};function wE(t){return function(e){return function(){e.textContent=t}}}function JE(t){return function(){return function(e){return t(e)()}}}function NE(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const Zg=function(){return window};function vE(t){return function(e){return function(){e.value=t}}}function TE(t){return function(){return t.valueAsNumber}}function bE(t){return function(){return t.value}}function t_(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const Cp=t=>t,tu=t=>()=>{const e=t.getBoundingClientRect?.(),n=e?.width||t.clientWidth||0,r=e?.height||t.clientHeight||0;return{width:n,height:r}},kp=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)}},Lp=()=>window.devicePixelRatio||1,CE=t=>e=>n=>r=>o=>()=>{const i=Math.max(1,e||t.clientWidth||r),s=Math.max(1,n||t.clientHeight||o),a="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} ${s}`),t.setAttribute("preserveAspectRatio","xMidYMid meet"),t.innerHTML=`
|
|
14
|
+
}`);const n=t.op._1;return Ne.state(r=>b(void 0,{...r,enterStack:kt(r.enterStack)(n.id),scenes:kt(r.scenes)(Uo("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=Cr(e.enterStack);if(n.tag==="Nothing")return Kn("`out` without a matching `into`");if(n.tag==="Just"){const r=n._1.init;return Ne.state(o=>b(void 0,{...o,enterStack:r,scenes:kt(o.scenes)(f2)}))}g()}return ge.pure()}g()})),Ma={structural:[],flow:!1,dives:[]},V5=Vt.bind($e)(t=>{if(t.error.tag==="Just")return ge.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return Ne.state(n=>b(void 0,{...n,scenes:kt(n.scenes)(Uo("Hold",e))}))}if(t.currentKf.tag==="Nothing")return ge.pure()}g()}),U5=t=>e=>Vt.bind($e)(n=>{const r="ev-"+ie(n.eventCounter);return Vt.bind((()=>{const o={...n,eventCounter:n.eventCounter+1|0};return Ne.state(i=>b(void 0,o))})())(()=>ge.pure({events:[{id:r,kind:e,when:t}],firstId:N("Just",r),lastId:N("Just",r)}))}),X5=t=>t.tag==="DataFlow"?N("Just",t._1):J,Y5=t=>Tt(e=>Fg(e)(t.graphEdges))(Zt(Io,m5(t.currEdges))),K5=t=>e=>{const n=ft(o=>o.from.node===e.id||o.to.node===e.id,Y5(t)),r=Fa(c_)(o=>i=>{const s=i.from+"->"+e.id,a=e.id+"->"+i.to,u=i.from+"->"+i.to,c="via "+i.from+" "+i.to+": no edge "+i.from+"\u2192"+e.id;if(!Yn(s)(t.currEdges))return Wt("Left",c);const _="via "+i.from+" "+i.to+": no edge "+e.id+"\u2192"+i.to;if(!Yn(a)(t.currEdges))return Wt("Left",_);const d="via "+i.from+" "+i.to+": would create "+i.from+"\u2192"+i.to+" but it already exists";return Yn(u)(t.currEdges)||y5(u)(o.synthesized)?Wt("Left",d):Wt("Right",{consumed:rt(P)(s)()(rt(P)(a)()(o.consumed)),synthesized:rt(P)(u)({id:u,from:{node:i.from,port:J},to:{node:i.to,port:J},label:J})(o.synthesized)})})({consumed:I,synthesized:I})(e.via);return(()=>{if(r.tag==="Left"){const o=r._1;return i=>Wt("Left",o)}if(r.tag==="Right"){const o=r._1;return i=>i(o)}g()})()(o=>{const i=o.consumed,s=ft(a=>!Yn(a.id)(i),n);return s.length===0?Wt("Right",{nextCurrEdges:Me(P.compare,Ie,Vn(P.compare,t.currEdges,x5(O(a=>a.id)(n))),w5((()=>{const a=u=>{if(u.tag==="Leaf")return I;if(u.tag==="Node")return te("Node",u._1,u._2,u._3,void 0,a(u._5),a(u._6));g()};return a(o.synthesized)})())),synthesized:o.synthesized}):Wt("Left","cannot delete node "+e.id+": still connected ("+ur(", ")(O(a=>(()=>{const u=go("conn:")(a.id);if(u.tag==="Just")return!1;if(u.tag==="Nothing")return!0;g()})()?a.from.node+"\u2192"+a.to.node:a.from.node+"--"+a.to.node)(s))+"). Use `- a -> b` or `- a -- b` to drop them, or `via a b` to merge "+e.id+"'s endpoints.")})},$h=t=>e=>n=>{if(t){if(e){const i=0<n.operands.length?n.operands[0]:n.span,s=1<n.operands.length?n.operands[1]:n.span;return{line:i.line,column:i.column,endLine:s.endLine,endColumn:s.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}},Vh=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq"||t.tag==="GroupSeq")return St(t._1)(Vh);g()},j5=t=>({nodes:O(ps)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Lt("Cons",n._4,e(n._6,r)));g()};return Zt(de.foldr,e(t.graphEdges,$))})(),constraints:[]}),qg=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==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?{...Ma,structural:[t._1]}:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?{...Ma,dives:[t._1]}:{...Ma,flow:!0};if(t.tag==="Seq"||t.tag==="GroupSeq"||t.tag==="Par")return T(R5)(Ma)(O(qg)(t._1));g()},za=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==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?[Bo("StepStructural",[t._1])]:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?[Bo("StepDive",t._1)]:[Bo("StepFlow",t)];if(t.tag==="Seq")return St(t._1)(za);if(t.tag==="GroupSeq")return tL(t)(t._1);if(t.tag==="Par")return Z5(t)(t._1);g()},Z5=t=>e=>{const n=qg(t);return n.structural.length!==0&&!n.flow&&n.dives.length===0?[Bo("StepStructural",n.structural)]:n.structural.length===0&&n.flow&&n.dives.length===0?[Bo("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?O(zh)(n.dives):St(e)(za)},tL=t=>e=>{const n=qg(t);return n.structural.length===0&&n.flow&&n.dives.length===0?[Bo("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?O(zh)(n.dives):St(e)(za)},eL=t=>e=>Vt.bind($e)(n=>{const r=e.from+"->"+e.to,o=e.newFrom+"->"+e.newTo;return Yn(r)(n.currEdges)?xr(e.newFrom)(n.currNodes)?xr(e.newTo)(n.currNodes)?r!==o&&Yn(o)(n.currEdges)?un((()=>{const i=2<t.operands.length?t.operands[2]:t.span,s=3<t.operands.length?t.operands[3]:t.span;return{line:i.line,column:i.column,endLine:s.endLine,endColumn:s.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists"):Ne.state(i=>b(void 0,{...i,currEdges:rt(P)(o)()(qo(P)(r)(i.currEdges)),graphEdges:rt(P)(o)({id:o,from:{node:e.newFrom,port:J},to:{node:e.newTo,port:J},label:J})(i.graphEdges)})):un(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):un(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):un((()=>{const i=0<t.operands.length?t.operands[0]:t.span,s=1<t.operands.length?t.operands[1]:t.span;return{line:i.line,column:i.column,endLine:s.endLine,endColumn:s.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist")}),nL=t=>{if(t.op.tag==="AddNode"){const e=t.op._1;return Vt.bind($e)(n=>xr(e.id)(n.currNodes)?un(0<t.operands.length?t.operands[0]:t.span)("cannot add node "+e.id+": already exists"):Ne.state(r=>b(void 0,{...r,graphNodes:P5(e.id)({id:e.id,size:b(1,1),ports:[],label:N("Just",e.label),shape:e.shape})(r.graphNodes),currNodes:rt(P)(e.id)()(r.currNodes)})))}if(t.op.tag==="DelNode"){const e=t.op._1;return Vt.bind($e)(n=>{if(!xr(e.id)(n.currNodes))return un(0<t.operands.length?t.operands[0]:t.span)("cannot delete node "+e.id+": does not exist");const r=K5(n)(e);if(r.tag==="Left")return un(0<t.operands.length?t.operands[0]:t.span)(r._1);if(r.tag==="Right"){const o=r._1;return Ne.state(i=>b(void 0,{...i,currNodes:qo(P)(e.id)(i.currNodes),currEdges:o.nextCurrEdges,graphEdges:Me(P.compare,Ie,o.synthesized,i.graphEdges)}))}g()})}if(t.op.tag==="ModNode"){const e=t.op._1;return Vt.bind($e)(n=>{if(!xr(e.id)(n.currNodes))return un(0<t.operands.length?t.operands[0]:t.span)("cannot modify node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=e.label._1;return Ne.state(o=>b(void 0,{...o,graphNodes:B5(e.id)(r)(o.graphNodes)}))}if(e.label.tag==="Nothing")return ge.pure();g()})}if(t.op.tag==="AddEdge"){const e=t.op._1;return Vt.bind($e)(n=>{const r=!xr(e.from)(n.currNodes),o=!xr(e.to)(n.currNodes);if(r||o)return un($h(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 Yn(i)(n.currEdges)?un((()=>{const s=0<t.operands.length?t.operands[0]:t.span,a=1<t.operands.length?t.operands[1]:t.span;return{line:s.line,column:s.column,endLine:a.endLine,endColumn:a.endColumn}})())((e.directed?"cannot add edge ":"cannot add connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": already exists"):Ne.state(s=>b(void 0,{...s,graphEdges:rt(P)(i)({id:i,from:{node:e.from,port:J},to:{node:e.to,port:J},label:e.label})(s.graphEdges),currEdges:rt(P)(i)()(s.currEdges)}))})}if(t.op.tag==="DelEdge"){const e=t.op._1;return Vt.bind($e)(n=>{const r=e.directed?e.from+"->"+e.to:e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;return Yn(r)(n.currEdges)?Ne.state(o=>b(void 0,{...o,currEdges:qo(P)(r)(o.currEdges)})):un((()=>{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"?eL(t)(t.op._1):ge.pure()},rL=t=>Vt.bind((()=>{const e=t.span;return Ne.state(n=>b(void 0,{...n,currentSpan:e}))})())(()=>nL(t)),Uh=t=>e=>n=>Vt.bind(Qg(rL)(n))(()=>Vt.bind($e)(r=>{const o=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ie(r.kfCounter);if(xe(s=>s.id===o,r.keyframes))return Vt.bind(J5(D5)(0<n.length?N("Just",n[0]):J))(()=>Kn("duplicate frame name "+o));const i={...r,keyframes:kt(r.keyframes)({id:o,nodes:r.currNodes,edges:r.currEdges,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 kt(r.scenes)(Uo("Structural",{from:r.currentKf._1,to:o,focus:J}));g()})()};return Ne.state(s=>b(void 0,i))})),Xh=t=>e=>{const n=Vh(e.ops),r=ft(i=>i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge",n),o=ft(i=>!(i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge"),n);return 0<o.length?Vt.bind((()=>{const i=o[0].span;return Ne.state(s=>b(void 0,{...s,currentSpan:i}))})())(()=>Kn("still/title blocks hold a still snapshot; they cannot contain movement tokens (`api ~> db`) or dive commands (`into`/`out`)")):t==="TitleCard"&&r.length===0?Kn(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"):Vt.bind(Uh(t)(e.name)(r))(()=>V5)},oL=t=>e=>{const n=Tt(X5)(e.scenes),r=ft(A5(N5(O(s=>s.keyframe)(n))),e.keyframes),o=Vn(P.compare,zg(s=>s.nodes)(r),zg(M5)(n)),i=Vn(P.compare,Wg(s=>s.edges)(r),Wg(W5)(n));return t!=="AnimatedSurface"||n.length===0||o.tag==="Leaf"&&i.tag==="Leaf"?J:N("Just",F5(e)(o)(i))},iL=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(Yn(r)(t.currEdges))return N("Just",{id:r,direction:Y_});if(Yn(n)(t.currEdges))return N("Just",{id:n,direction:K_});const i=Fg(o)(t.graphEdges);if(i.tag==="Just")return Yn(o)(t.currEdges)?N("Just",{id:o,direction:i._1.from.node===e.from&&i._1.to.node===e.to?Y_:K_}):J;if(i.tag==="Nothing")return J;g()},sL=t=>e=>{if(e.op.tag==="Token"){const n=e.op._1;return Vt.bind($e)(r=>{const o=!xr(n.from)(r.currNodes),i=!xr(n.to)(r.currNodes);if(o||i)return Vt.bind(un($h(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: "))(()=>ge.pure({events:[],firstId:J,lastId:J}));const s=iL(r)(n);if(s.tag==="Just")return U5(t)(u2("SendToken",{from:n.from,to:n.to,edge:s._1.id,direction:s._1.direction,labels:n.labels}));if(s.tag==="Nothing")return Vt.bind(un((()=>{const a=0<e.operands.length?e.operands[0]:e.span,u=1<e.operands.length?e.operands[1]:e.span;return{line:a.line,column:a.column,endLine:u.endLine,endColumn:u.endColumn}})())("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>ge.pure({events:[],firstId:J,lastId:J}));g()})}return ge.pure({events:[],firstId:J,lastId:J})},aL=t=>e=>{const n=Ft(r=>J,r=>o=>N("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return ge.pure({events:[],firstId:J,lastId:J});if(n.tag==="Just"){const r=n._1.tail;return Vt.bind(fs(t)(n._1.head))(o=>Vt.bind(Fa({Applicative0:()=>Po(kn),Bind1:()=>Go(kn)})(i=>s=>Vt.bind(fs((()=>{if(i.lastId.tag==="Just")return zu("After",i.lastId._1);if(i.lastId.tag==="Nothing")return t;g()})())(s))(a=>ge.pure({events:[...i.events,...a.events],firstId:(()=>{if(i.firstId.tag==="Just")return N("Just",i.firstId._1);if(i.firstId.tag==="Nothing")return a.firstId;g()})(),lastId:(()=>{if(a.lastId.tag==="Just")return N("Just",a.lastId._1);if(a.lastId.tag==="Nothing")return i.lastId;g()})()})))(o)(r))(i=>ge.pure(i)))}g()},uL=t=>e=>{const n=Ft(r=>J,r=>o=>N("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return ge.pure({events:[],firstId:J,lastId:J});if(n.tag==="Just"){const r=n._1.tail;return Vt.bind(fs(t)(n._1.head))(o=>Vt.bind(cL((()=>{if(o.firstId.tag==="Just")return zu("With",o.firstId._1);if(o.firstId.tag==="Nothing")return t;g()})())(r))(i=>ge.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()},fs=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return Vt.bind((()=>{const r=n.span;return Ne.state(o=>b(void 0,{...o,currentSpan:r}))})())(()=>sL(t)(n))}if(e.tag==="Seq"||e.tag==="GroupSeq")return aL(t)(e._1);if(e.tag==="Par")return uL(t)(e._1);g()},cL=t=>Fa({Applicative0:()=>Po(kn),Bind1:()=>Go(kn)})(e=>n=>Vt.bind(fs(t)(n))(r=>ge.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:J,lastId:J}),gL=t=>Vt.bind($e)(e=>{if(e.currentKf.tag==="Nothing")return Kn("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return Vt.bind(fs(_2)(t))(r=>Vt.bind($e)(o=>{const i={...o,scenes:kt(o.scenes)(Uo("DataFlow",{keyframe:n,events:r.events,focus:J}))};return Ne.state(s=>b(void 0,i))}))}g()}),_L=t=>e=>n=>{if(n.tag==="StepStructural")return Vt.bind((()=>{const r=Uh(Di)(e?J:t)(n._1);return n._1.length!==0?r:ge.pure()})())(()=>ge.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 Vt.bind((()=>{const i=O5(t);return o?i:ge.pure()})())(()=>Vt.bind(gL(r))(()=>ge.pure(e||o)))}if(n.tag==="StepDive")return Vt.bind($5(n._1))(()=>ge.pure(e));g()},Yh=t=>e=>n=>{const r=Ft(o=>J,o=>i=>N("Just",{head:o,tail:i}),n);if(r.tag==="Nothing")return ge.pure();if(r.tag==="Just"){const o=r._1.head,i=r._1.tail;return Vt.bind($e)(s=>{if(s.error.tag==="Just")return ge.pure();if(s.error.tag==="Nothing")return Vt.bind(_L(t)(e)(o))(a=>Yh(t)(a)(i));g()})}g()},fL=t=>Vt.bind($e)(e=>{if(e.error.tag==="Just")return ge.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return Yh(t.name)(!1)(za(t.ops));if(t.kind==="Still")return Xh(c2)(t);if(t.kind==="Title")return Xh(g2)(t);if(t.kind==="StepMarker")return H5(t)}g()}),Kh=t=>Vt.bind(q5(t.interiors))(()=>Vt.bind(Qg(fL)(t.frames))(()=>Vt.bind($e)(e=>{if(e.error.tag==="Just")return ge.pure(Wt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=dL(t.interiors);if(n.tag==="Left")return ge.pure(Wt("Left",n._1));if(n.tag==="Right"){const r={seed:t.seed,graph:j5(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1};return ge.pure((()=>{const o=oL(t.mode)(r);if(o.tag==="Just")return Wt("Left",{msg:o._1,line:0,column:0,endLine:0,endColumn:0});if(o.tag==="Nothing")return Wt("Right",r);g()})())}}g()}))),dL=t=>{const e=Fa(c_)(n=>r=>{const o=Kh(r.doc)(qh)._1;return(()=>{if(o.tag==="Left"){const i=o._1;return s=>Wt("Left",i)}if(o.tag==="Right"){const i=o._1;return s=>s(i)}g()})()(i=>Wt("Right",rt(P)(r.node)(i)(n)))})(I)(t);if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right")return Wt("Right",e._1);g()},wr=(t,e)=>({tag:"ParseError",_1:t,_2:e}),k=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),Wa=(t,e,n)=>({tag:t,_1:e,_2:n}),lL=t=>Wa("More",t),hL=t=>Wa("Lift",t),pL={defer:t=>{const e=Rm(t);return(n,r,o,i,s)=>Am(e)(n,r,o,i,s)}},jh={map:t=>e=>(n,r,o,i,s)=>r(a=>e(n,r,o,i,(u,c)=>r(_=>s(u,t(c)))))},mL={alt:t=>e=>(n,r,o,i,s)=>{const a=n._1,u=n._2;return r(c=>t(k(a,u,!1),r,o,(_,d)=>{const l=_._3;return r(f=>l?i(_,d):e(n,r,o,i,s))},s))},Functor0:()=>jh},yL=t=>{const e=t.Monad0();return n=>r=>{const o=i=>{let s=i,a=!0,u;for(;a;){const c=s();if(c.tag==="More"){s=c._1;continue}if(c.tag==="Lift"){a=!1,u=e.Bind1().Apply0().Functor0().map(fu)(c._1);continue}if(c.tag==="Stop"){a=!1,u=e.Applicative0().pure(Ao("Done",b(c._2,c._1)));continue}g()}return u};return t.tailRecM(o)(i=>r(n,lL,hL,(s,a)=>Wa("Stop",s,Wt("Left",a)),(s,a)=>Wa("Stop",s,Wt("Right",a))))}},jn=(t,e,n,r,o)=>o(t,t._2),xL={index:0,line:1,column:1},wL=(t=>{const e=yL(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(ms)(e(k(n,xL,!1))(r))})(f0),qa=(t,e,n,r,o)=>o(k(t._1,t._2,!0),void 0),Zh={apply:t=>e=>(n,r,o,i,s)=>r(a=>t(n,r,o,i,(u,c)=>r(_=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return e(d,r,o,i,(l,f)=>r(h=>s(d._3&&!l._3?k(l._1,l._2,!0):l,c(f))))}))),Functor0:()=>jh},tp={pure:t=>(e,n,r,o,i)=>i(e,t),Apply0:()=>Zh},JL={bind:t=>e=>(n,r,o,i,s)=>r(a=>t(n,r,o,i,(u,c)=>r(_=>e(c)(n._3&&!u._3?k(u._1,u._2,!0):u,r,o,i,s)))),Apply0:()=>Zh},NL={Applicative0:()=>tp,Bind1:()=>JL},Oa=t=>(e,n,r,o,i)=>n(s=>jn(e,n,r,o,(a,u)=>n(c=>o(e._3&&!a._3?k(a._1,a._2,!0):a,wr(t,u))))),TL={empty:Oa("No alternative"),Alt0:()=>mL},vL={Applicative0:()=>tp,Plus1:()=>TL},Rn=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return o=>t.tailRecM(i=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(fu)(o))(r.pure(Ao("Done",void 0))))(s=>r.pure((()=>{if(s.tag==="Loop")return Ao("Loop",Lt("Cons",s._1,i));if(s.tag==="Done")return Ao("Done",(a=>u=>{let c=a,_=u,d=!0,l;for(;d;){const f=c,h=_;if(h.tag==="Nil"){d=!1,l=f;continue}if(h.tag==="Cons"){c=Lt("Cons",h._1,f),_=h._2;continue}g()}return l})($)(i));g()})())))($)})({tailRecM:t=>e=>(n,r,o,i,s)=>{const a=(u,c,_)=>t(c)(u,r,o,i,(d,l)=>{const f=u._3&&!d._3?k(d._1,d._2,!0):d;if(l.tag==="Loop")return _===0?r(h=>a(f,l._1,30)):a(f,l._1,_-1|0);if(l.tag==="Done")return s(f,l._1);g()});return a(n,e,30)},Monad0:()=>NL})(vL),xt=t=>e=>{const n=Oa("Expected "+e);return(r,o,i,s,a)=>{const u=r._1,c=r._2;return o(_=>t(k(u,c,!1),o,i,(d,l)=>{const f=d._3;return o(h=>f?s(d,l):n(r,o,i,s,a))},a))}},Ji=t=>(e,n,r,o,i)=>{const s=e._3,a=e._1,u=e._2;return n(c=>{const _=(d,l)=>{const f=d._3;return n(h=>f?o(k(d._1,d._2,s),l):i(e,void 0))};return n(d=>n(l=>t(k(a,u,!1),n,r,(f,h)=>_(k(f._1,f._2,!1),h),(f,h)=>n(p=>n(m=>Oa("Negated parser succeeded")(f,n,r,_,(w,y)=>n(x=>i(f._3&&!w._3?k(w._1,w._2,!0):w,y))))))))})},CL=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return N("Just",n);if(r.tag==="Just")return N("Just",(o,i,s,a,u)=>{const c=o._1,_=o._2;return i(d=>n(k(c,_,!1),i,s,(l,f)=>{const h=l._3;return i(p=>h?a(l,f):r._1(o,i,s,a,u))},u))});g()})(J);return n=>{const r=e(n);if(r.tag==="Nothing")return Oa("No alternative");if(r.tag==="Just")return r._1;g()}},ep=t=>e=>n=>(r,o,i,s,a)=>o(u=>o(c=>o(_=>o(d=>t(r,o,i,s,(l,f)=>o(h=>o(p=>{const m=r._3&&!l._3?k(l._1,l._2,!0):l;return n(m,o,i,s,(w,y)=>o(x=>{const v=m._3&&!w._3?k(w._1,w._2,!0):w;return o(C=>o(L=>{const E=r._3&&!v._3?k(v._1,v._2,!0):v;return e(E,o,i,s,(B,z)=>o(Y=>a(E._3&&!B._3?k(B._1,B._2,!0):B,y)))}))}))}))))))),Og=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=ay()(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)-Hr(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},bL=t=>e=>n=>{let r=t,o=e,i=n,s=!0,a;for(;s;){const u=r,c=o,_=i,d=Fs(c);if(d.tag==="Nothing"){s=!1,a=u;continue}if(d.tag==="Just"){r=d._1.tail===""?Og(u)(d._1.head)(_):Og(u)(d._1.head)(d._1.tail),o=d._1.tail,i=_;continue}g()}return a},At=t=>(e,n,r,o,i)=>{const s=Fs(e._1);if(s.tag==="Nothing")return o(e,wr("Unexpected EOF",e._2));if(s.tag==="Just"){if(s._1.head<0||s._1.head>65535)return o(e,wr("Expected Char",e._2));if(s._1.head>=0&&s._1.head<=65535){const a=ff(s._1.head);return t(a)?i(k(s._1.tail,Og(e._2)(s._1.head)(s._1.tail),!0),a):o(e,wr("Predicate unsatisfied",e._2))}}g()},ds=(t,e,n,r,o)=>t._1===""?o(k(t._1,t._2,!0),void 0):r(t,wr("Expected EOF",t._2)),kL=t=>(e,n,r,o,i)=>{const s=t(e._1);if(s.tag==="Left")return o(e,wr(s._1,e._2));if(s.tag==="Right")return i(k(s._1.remainder,bL(e._2)(s._1.consumed)(s._1.remainder),s._1.consumed!==""),s._1.value);g()},cn=t=>kL(e=>{const n=go(t)(e);return n.tag==="Just"?Wt("Right",{value:t,consumed:t,remainder:n._1}):Wt("Left","Expected "+Zp(t))}),LL=At(t=>!0),Ha=(t,e)=>({tag:t,_1:e}),Hg=CL(zt),SL=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},EL=ce(P)(zt),GL=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},$g=(()=>{const t=xt(At(r=>r==="}"))("'}'"),e=xt(At(r=>r==="#"))("'#'"),n=At(r=>r===`
|
|
15
|
+
`||r==="\r");return(r,o,i,s,a)=>{const u=r._1,c=r._2;return o(_=>o(d=>t(k(u,c,!1),o,i,(l,f)=>o(h=>{const p=r._1,m=r._2;return o(w=>o(y=>e(k(p,m,!1),o,i,(x,v)=>o(C=>{const L=r._1,E=r._2;return o(B=>o(z=>n(k(L,E,!1),o,i,(Y,R)=>o(A=>ds(r,o,i,s,a)),(Y,R)=>o(A=>a(k(L,E,!1),void 0)))))}),(x,v)=>o(C=>a(k(p,m,!1),void 0)))))}),(l,f)=>o(h=>a(k(u,c,!1),void 0)))))}})(),Tn=t=>(e,n,r,o,i)=>n(s=>jn(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>t(_,n,r,o,(l,f)=>n(h=>{const p=_._3&&!l._3?k(l._1,l._2,!0):l;return n(m=>jn(p,n,r,o,(w,y)=>n(x=>i(p._3&&!w._3?k(w._1,w._2,!0):w,b(f,{line:u.line,column:u.column,endLine:y.line,endColumn:y.column})))))})))}))),PL=(()=>{const t=At(e=>e===" "||e===" "||e===`
|
|
16
|
+
`||e==="\r");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>i(e._3&&!a._3?k(a._1,a._2,!0):a,void 0))))})(),np=(t,e,n,r,o)=>e(i=>cn("#")(t,e,n,r,(s,a)=>e(u=>{const c=Rn(At(d=>d!==`
|
|
17
|
+
`)),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>o(_._3&&!l._3?k(l._1,l._2,!0):l,void 0))))}))),rp=xt((()=>{const t=xt(At(n=>n==="}"))("'}'"),e=At(n=>n===`
|
|
18
|
+
`||n==="\r");return(n,r,o,i,s)=>{const a=n._1,u=n._2;return r(c=>r(_=>t(k(a,u,!1),r,o,(d,l)=>r(f=>{const h=n._1,p=n._2;return r(m=>r(w=>np(k(h,p,!1),r,o,(y,x)=>{const v=y._3;return r(C=>{if(v)return i(y,x);const L=n._1,E=n._2;return r(B=>r(z=>e(k(L,E,!1),r,o,(Y,R)=>{const A=Y._3;return r(j=>A?i(Y,R):ds(n,r,o,i,s))},(Y,R)=>r(A=>s(Y,void 0)))))})},(y,x)=>r(v=>s(y,void 0)))))}),(d,l)=>r(f=>s(k(a,u,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),ln=(()=>{const t=Rn((e,n,r,o,i)=>{const s=e._1,a=e._2;return n(u=>PL(k(s,a,!1),n,r,(c,_)=>{const d=c._3;return n(l=>d?o(c,_):np(e,n,r,o,i))},i))});return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>i(e._3&&!a._3?k(a._1,a._2,!0):a,void 0))))})(),BL=(()=>{const t=At(e=>e!=="|");return(e,n,r,o,i)=>{const s=e._1,a=e._2;return n(u=>n(c=>cn("\\|")(k(s,a,!1),n,r,(_,d)=>n(l=>n(f=>t(e,n,r,o,(h,p)=>n(m=>i(h,Gi(p)))))),(_,d)=>n(l=>i(_,"|")))))}})(),DL=xt(Hg([(t,e,n,r,o)=>e(i=>{const s=t._3;return cn("->")(t,e,n,(a,u)=>r(k(a._1,a._2,s),u),(a,u)=>e(c=>o(a,!0)))}),(t,e,n,r,o)=>e(i=>{const s=t._3;return cn("--")(t,e,n,(a,u)=>r(k(a._1,a._2,s),u),(a,u)=>e(c=>o(a,!1)))})]))("edge arrow '->' or '--'"),RL=t=>t!==`
|
|
19
|
+
`&&t!=="\r"&&t!=="#"&&t!=="}"&&t!=="{",$a=At(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),AL=t=>t===" "||t===" "||t==="\r",IL=t=>$r(se(er(AL)(se(br(t))).rest)),Vg=t=>t===`
|
|
20
|
+
`||t==="\r"||t==="#"||t==="}",FL=t=>t===`
|
|
21
|
+
`||t==="\r"||t==="#"||t==="}"||t==="{",QL=t=>t!=="{"&&t!==`
|
|
22
|
+
`&&t!=="\r",op=t=>Is(t)==="",ML=t=>se(er(op)(se(er(op)(t).rest)).rest),zL=t=>(e=>n=>{let r=e,o=n,i=!0,s;for(;i;){const a=r,u=Ft(c=>J,c=>_=>N("Just",{head:c,tail:_}),o);if(u.tag==="Just"&&(u._1.head===" "||u._1.head===" ")){r=a+1|0,o=u._1.tail;continue}i=!1,s=a}return s})(0)(br(t)),WL=t=>{const e=Ft(n=>J,n=>r=>N("Just",{head:n,tail:r}),O(zL)(ft(n=>Is(n)!=="",t)));if(e.tag==="Nothing")return 0;if(e.tag==="Just")return T(SL)(e._1.head)(e._1.tail);g()},qL=(()=>{const t=xt(At(e=>e==="-"))("'-'");return(e,n,r,o,i)=>{const s=e._3;return n(a=>t(e,n,r,(u,c)=>o(k(u._1,u._2,s),c),(u,c)=>n(_=>{const d=Ji((()=>{const f=xt(At(p=>p===">"))("'>'"),h=xt(At(p=>p==="-"))("'-'");return(p,m,w,y,x)=>{const v=p._1,C=p._2;return m(L=>f(k(v,C,!1),m,w,(E,B)=>{const z=E._3;return m(Y=>z?y(E,B):h(p,m,w,y,x))},x))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(f=>d(l,n,r,(h,p)=>o(k(h._1,h._2,s),p),(h,p)=>n(m=>i(l._3&&!h._3?k(h._1,h._2,!0):h,"-"))))})))}})(),ee=(()=>{const t=Rn(At(e=>e===" "||e===" "));return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>i(e._3&&!a._3?k(a._1,a._2,!0):a,void 0))))})(),io=(()=>{const t=At(e=>e===" "||e===" ");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>ee(e._3&&!a._3?k(a._1,a._2,!0):a,n,r,o,i))))})(),ip=(t,e,n,r,o)=>e(i=>e(s=>ee(t,e,n,r,(a,u)=>e(c=>e(_=>{const d=t._3&&!a._3?k(a._1,a._2,!0):a;return $g(d,e,n,r,(l,f)=>e(h=>o(d._3&&!l._3?k(l._1,l._2,!0):l,f)))}))))),sp=(t,e,n,r,o)=>e(i=>ee(t,e,n,r,(s,a)=>e(u=>{const c=xt(At(d=>d==="-"))("'-'"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>{const l=(p,m)=>e(w=>(()=>{if(m.tag==="Just")return(y,x,v,C,L)=>x(E=>DL(y,x,v,C,(B,z)=>x(Y=>L(B,N("Just",z)))));if(m.tag==="Nothing")return(y,x,v,C,L)=>L(y,J);g()})()(_._3&&!p._3?k(p._1,p._2,!0):p,e,n,r,o)),f=_._1,h=_._2;return e(p=>e(m=>c(k(f,h,!1),e,n,(w,y)=>e(x=>l(_,J)),(w,y)=>e(x=>l(k(f,h,!1),N("Just",y))))))})}))),OL=t=>{const e=go("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 -> db => api -> cache`.":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, 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},HL=t=>{const e=Is(t),n=go('"')(e),r=(()=>{if(n.tag==="Just")return Dm('"')(n._1);if(n.tag==="Nothing")return J;g()})(),o=(()=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()})();return o===""?J:N("Just",o)},ap=t=>e=>t!=="AnimatedSurface"&&e.statements.length!==0?{...e,frames:kt(e.frames)((()=>{if(t==="StillSurface")return{name:J,ops:yr("Seq",e.statements),kind:Mg};if(t==="SequenceSurface")return{name:J,ops:yr("Seq",e.statements),kind:Qa};if(t==="AnimatedSurface")return{name:J,ops:yr("Seq",e.statements),kind:Qa};g()})()),statements:[]}:e,$L=(()=>{const t=xt(At(e=>e==="\\"))("'\\\\'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>LL(_,n,r,o,(l,f)=>n(h=>i(_._3&&!l._3?k(l._1,l._2,!0):l,f==="n"?`
|
|
23
|
+
`:f==="t"?" ":f==="r"?"\r":f))))})))})(),VL=(()=>{const t=At(e=>e!=='"'&&e!=="\\"&&e!==`
|
|
24
|
+
`);return(e,n,r,o,i)=>{const s=e._1,a=e._2;return n(u=>$L(k(s,a,!1),n,r,(c,_)=>n(d=>t(e,n,r,o,i)),i))}})(),UL=(()=>{const t=xt(At(e=>e==='"'))(`'"'`);return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=Rn(VL),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=xt(xt(At(y=>y==='"'))(`'"'`))(`closing '"' (unterminated string)`),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(y=>m(w,n,r,o,(x,v)=>n(C=>i(w._3&&!x._3?k(x._1,x._2,!0):x,$r(Zt(de.foldr,h))))))})))})))})(),XL={frames:[],statements:[]},YL=t=>{const e=ML(Sr(`
|
|
25
|
+
`)(t));return ur(`
|
|
26
|
+
`)(O(IL)(O(Vo(WL(e)))(e)))},KL=(()=>{const t=xt(At(e=>e==="|"))("'|'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=Rn(BL),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=xt(xt(At(y=>y==="|"))("'|'"))("closing '|'"),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(y=>m(w,n,r,o,(x,v)=>n(C=>i(w._3&&!x._3?k(x._1,x._2,!0):x,YL(ur("")(Zt(de.foldr,h)))))))})))})))})(),ls=At(t=>t>="0"&&t<="9"),jL=(()=>{const t=xt(At(e=>e==="_"))("'_'");return(e,n,r,o,i)=>{const s=e._1,a=e._2;return n(u=>$a(k(s,a,!1),n,r,(c,_)=>{const d=c._3;return n(l=>{if(d)return o(c,_);const f=e._1,h=e._2;return n(p=>ls(k(f,h,!1),n,r,(m,w)=>{const y=m._3;return n(x=>{if(y)return o(m,w);const v=e._1,C=e._2;return n(L=>t(k(v,C,!1),n,r,(E,B)=>{const z=E._3;return n(Y=>z?o(E,B):qL(e,n,r,o,i))},i))})},i))})},i))}})(),We=(()=>{const t=xt(At(e=>e==="_"))("'_'");return(e,n,r,o,i)=>n(s=>{const a=(_,d)=>n(l=>{const f=Rn(jL),h=e._3&&!_._3?k(_._1,_._2,!0):_;return n(p=>f(h,n,r,o,(m,w)=>n(y=>i(h._3&&!m._3?k(m._1,m._2,!0):m,Gi(d)+$r(Zt(de.foldr,w))))))}),u=e._1,c=e._2;return n(_=>$a(k(u,c,!1),n,r,(d,l)=>{const f=d._3;return n(h=>f?o(d,l):t(e,n,r,o,a))},a))})})(),up=(t,e,n,r,o)=>e(i=>ee(t,e,n,r,(s,a)=>e(u=>{const c=xt(We)("attribute key"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=_._3&&!l._3?k(l._1,l._2,!0):l;return e(m=>ee(p,e,n,r,(w,y)=>e(x=>{const v=xt(xt(At(L=>L===":"))("':'"))("':'"),C=p._3&&!w._3?k(w._1,w._2,!0):w;return e(L=>v(C,e,n,r,(E,B)=>e(z=>{const Y=C._3&&!E._3?k(E._1,E._2,!0):E;return e(R=>ee(Y,e,n,r,(A,j)=>e(Z=>{const M=xt(We)("attribute value"),W=Y._3&&!A._3?k(A._1,A._2,!0):A;return e(H=>M(W,e,n,r,(D,F)=>e(S=>{const G=W._3&&!D._3?k(D._1,D._2,!0):D;return e(Q=>ee(G,e,n,r,(V,X)=>e(U=>o(G._3&&!V._3?k(V._1,V._2,!0):V,b(f,F)))))})))})))})))})))})))}))),ZL=ep((()=>{const t=xt(At(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(s=>n(a=>t(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return ee(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(f._1,f._2,!0):f,h)))})))))})())(xt((()=>{const t=xt(At(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(s=>n(a=>ee(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return t(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(f._1,f._2,!0):f,h)))})))))})())("closing '}' for attributes"))((()=>{const t=xt(At(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(s=>{const a=(_,d)=>n(l=>(()=>{if(d.tag==="Just")return(f,h,p,m,w)=>w(f,I);if(d.tag==="Nothing")return(f,h,p,m,w)=>h(y=>up(f,h,p,m,(x,v)=>h(C=>{const L=Rn((()=>{const B=xt(At(z=>z===","))("','");return(z,Y,R,A,j)=>{const Z=z._3;return Y(M=>Y(W=>Y(H=>Y(D=>Y(F=>Y(S=>ee(z,Y,R,(G,Q)=>A(k(G._1,G._2,Z),Q),(G,Q)=>Y(V=>Y(X=>{const U=z._3&&!G._3?k(G._1,G._2,!0):G;return B(U,Y,R,(q,K)=>A(k(q._1,q._2,Z),K),(q,K)=>Y(et=>{const lt=U._3&&!q._3?k(q._1,q._2,!0):q;return Y(bt=>Y(pt=>{const vt=z._3&&!lt._3?k(lt._1,lt._2,!0):lt;return ee(vt,Y,R,(Gt,jt)=>A(k(Gt._1,Gt._2,Z),jt),(Gt,jt)=>Y(Ct=>{const Yt=vt._3&&!Gt._3?k(Gt._1,Gt._2,!0):Gt;return Y(Rt=>Y(wt=>{const mt=z._3&&!Yt._3?k(Yt._1,Yt._2,!0):Yt;return up(mt,Y,R,(ct,yt)=>A(k(ct._1,ct._2,Z),yt),(ct,yt)=>Y(dt=>j(mt._3&&!ct._3?k(ct._1,ct._2,!0):ct,yt)))}))}))}))}))})))))))))}})()),E=f._3&&!x._3?k(x._1,x._2,!0):x;return h(B=>L(E,h,p,m,(z,Y)=>h(R=>w(E._3&&!z._3?k(z._1,z._2,!0):z,EL([v,...Zt(de.foldr,Y)])))))})));g()})()(e._3&&!_._3?k(_._1,_._2,!0):_,n,r,o,i)),u=e._1,c=e._2;return n(_=>n(d=>t(k(u,c,!1),n,r,(l,f)=>n(h=>a(e,J)),(l,f)=>n(h=>a(k(u,c,!1),N("Just",f))))))})})()),tS=(t,e,n,r,o)=>e(i=>ee(t,e,n,r,(s,a)=>e(u=>{const c=xt(At(d=>d==="{"))("'{'"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>{const l=(p,m)=>e(w=>(()=>{if(m.tag==="Just")return ZL;if(m.tag==="Nothing")return(y,x,v,C,L)=>L(y,I);g()})()(_._3&&!p._3?k(p._1,p._2,!0):p,e,n,r,o)),f=_._1,h=_._2;return e(p=>e(m=>c(k(f,h,!1),e,n,(w,y)=>e(x=>l(_,J)),(w,y)=>e(x=>l(k(f,h,!1),N("Just",y))))))})}))),eS=t=>e=>n=>(r,o,i,s,a)=>o(u=>ee(r,o,i,s,(c,_)=>o(d=>{const l=Tn(xt(We)("target node identifier")),f=r._3&&!c._3?k(c._1,c._2,!0):c;return o(h=>l(f,o,i,s,(p,m)=>o(w=>a(f._3&&!p._3?k(p._1,p._2,!0):p,{op:Xn("DelEdge",{from:t,to:m._1,directed:n}),operands:[e,m._2]}))))}))),nS=(t,e,n,r,o)=>e(i=>jn(t,e,n,r,(s,a)=>e(u=>{const c=t._3&&!s._3?k(s._1,s._2,!0):s;return e(_=>{const d=c._3;return e(l=>We(c,e,n,(f,h)=>r(k(f._1,f._2,d),h),(f,h)=>e(p=>{const m=c._3&&!f._3?k(f._1,f._2,!0):f;return e(w=>ee(m,e,n,(y,x)=>r(k(y._1,y._2,d),x),(y,x)=>e(v=>{const C=m._3&&!y._3?k(y._1,y._2,!0):y;return e(L=>{const E=(Y,R)=>e(A=>{const j=C._3&&!Y._3?k(Y._1,Y._2,!0):Y;return e(Z=>r(c._3&&!j._3?k(j._1,j._2,!0):j,wr("Use `~>` / `<~` for movement tokens.",a)))}),B=C._1,z=C._2;return e(Y=>cn("->")(k(B,z,!1),e,n,(R,A)=>{const j=R._3;return e(Z=>j?r(k(R._1,R._2,d),A):cn("<-")(C,e,n,(M,W)=>r(k(M._1,M._2,d),W),E))},E))})})))})))})}))),rS=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>Tn(We)(t,e,n,(u,c)=>r(k(u._1,u._2,s),c),(u,c)=>e(_=>{const d=t._3&&!u._3?k(u._1,u._2,!0):u;return e(l=>ee(d,e,n,(f,h)=>r(k(f._1,f._2,s),h),(f,h)=>e(p=>{const m=xt(At(y=>y==="~"))("'~'"),w=d._3&&!f._3?k(f._1,f._2,!0):f;return e(y=>{const x=(L,E)=>e(B=>{const z=w._3&&!L._3?k(L._1,L._2,!0):L;return e(Y=>{const R=c._1,A=c._2,j=t._3&&!z._3?k(z._1,z._2,!0):z;return e(Z=>ee(j,e,n,r,(M,W)=>e(H=>{const D=xt(At(G=>G==="~"))("'~'"),F=xt(At(G=>G==="<"))("'<'"),S=j._3&&!M._3?k(M._1,M._2,!0):M;return e(G=>{const Q=(U,q)=>e(K=>{const et=q==="~"?xt(cn("~>"))("'~>'"):xt(cn("<~"))("'<~'"),lt=S._3&&!U._3?k(U._1,U._2,!0):U;return e(bt=>et(lt,e,n,r,(pt,vt)=>e(Gt=>o(lt._3&&!pt._3?k(pt._1,pt._2,!0):pt,b(R,b(A,vt))))))}),V=S._1,X=S._2;return e(U=>D(k(V,X,!1),e,n,(q,K)=>{const et=q._3;return e(lt=>et?r(S,K):F(S,e,n,(bt,pt)=>r(S,pt),(bt,pt)=>Q(S,pt)))},(q,K)=>Q(S,K)))})})))})}),v=w._1,C=w._2;return e(L=>m(k(v,C,!1),e,n,(E,B)=>{const z=E._3;return e(Y=>z?r(k(w._1,w._2,s),B):e(R=>cn("<~")(w,e,n,(A,j)=>r(k(w._1,w._2,s),j),(A,j)=>e(Z=>x(w)))))},(E,B)=>x(w)))})})))})))}),oS=(()=>{const t=xt(At(e=>e==="~"))("'~'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=xt(io)("space after '~'"),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=Tn(xt(We)("source node identifier")),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(y=>m(w,n,r,o,(x,v)=>n(C=>{const L=v._1,E=v._2,B=w._3&&!x._3?k(x._1,x._2,!0):x;return n(z=>ee(B,n,r,o,(Y,R)=>n(A=>{const j=xt(cn("->"))("source edge arrow '->'"),Z=B._3&&!Y._3?k(Y._1,Y._2,!0):Y;return n(M=>j(Z,n,r,o,(W,H)=>n(D=>{const F=Z._3&&!W._3?k(W._1,W._2,!0):W;return n(S=>ee(F,n,r,o,(G,Q)=>n(V=>{const X=Tn(xt(We)("target node identifier")),U=F._3&&!G._3?k(G._1,G._2,!0):G;return n(q=>X(U,n,r,o,(K,et)=>n(lt=>{const bt=et._1,pt=et._2,vt=U._3&&!K._3?k(K._1,K._2,!0):K;return n(Gt=>ee(vt,n,r,o,(jt,Ct)=>n(Yt=>{const Rt=xt(cn("=>"))("repoint separator '=>'"),wt=vt._3&&!jt._3?k(jt._1,jt._2,!0):jt;return n(mt=>Rt(wt,n,r,o,(ct,yt)=>n(dt=>{const ht=wt._3&&!ct._3?k(ct._1,ct._2,!0):ct;return n(Et=>ee(ht,n,r,o,(Dt,Mt)=>n(ne=>{const Cn=Tn(xt(We)("new source node identifier")),qe=ht._3&&!Dt._3?k(Dt._1,Dt._2,!0):Dt;return n(Ot=>Cn(qe,n,r,o,(qt,Oe)=>n(bn=>{const tn=Oe._1,_n=Oe._2,Ae=qe._3&&!qt._3?k(qt._1,qt._2,!0):qt;return n(oe=>ee(Ae,n,r,o,(_e,b4)=>n(k4=>{const T4=xt(cn("->"))("replacement edge arrow '->'"),Hp=Ae._3&&!_e._3?k(_e._1,_e._2,!0):_e;return n(L4=>T4(Hp,n,r,o,(su,S4)=>n(E4=>{const $p=Hp._3&&!su._3?k(su._1,su._2,!0):su;return n(G4=>ee($p,n,r,o,(au,P4)=>n(B4=>{const v4=Tn(xt(We)("new target node identifier")),Vp=$p._3&&!au._3?k(au._1,au._2,!0):au;return n(D4=>v4(Vp,n,r,o,(uu,Up)=>n(R4=>i(Vp._3&&!uu._3?k(uu._1,uu._2,!0):uu,{op:Xn("RepointEdge",{from:L,to:bt,newFrom:tn,newTo:Up._1}),operands:[E,pt,_n,Up._2]}))))})))})))})))})))})))})))})))})))})))})))})))})))})))})))})(),iS=(t,e,n,r,o)=>e(i=>ls(t,e,n,r,(s,a)=>e(u=>{const c=Rn(ls),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=V0(Gi(a)+$r(Zt(de.foldr,f)));return(()=>{if(p.tag==="Just"){const m=p._1;return(w,y,x,v,C)=>C(w,m)}if(p.tag==="Nothing")return(m,w,y,x,v)=>v(m,0);g()})()(_._3&&!l._3?k(l._1,l._2,!0):l,e,n,r,o)})))}))),sS=t=>(e,n,r,o,i)=>{const s=e._3;return n(a=>cn(t)(e,n,r,(u,c)=>o(k(u._1,u._2,s),c),(u,c)=>n(_=>{const d=Ji((()=>{const f=xt(At(p=>p==="_"))("'_'"),h=xt(At(p=>p==="-"))("'-'");return(p,m,w,y,x)=>{const v=p._1,C=p._2;return m(L=>$a(k(v,C,!1),m,w,(E,B)=>{const z=E._3;return m(Y=>{if(z)return y(E,B);const R=p._1,A=p._2;return m(j=>ls(k(R,A,!1),m,w,(Z,M)=>{const W=Z._3;return m(H=>{if(W)return y(Z,M);const D=p._1,F=p._2;return m(S=>f(k(D,F,!1),m,w,(G,Q)=>{const V=G._3;return m(X=>V?y(G,Q):h(p,m,w,y,x))},x))})},x))})},x))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(f=>d(l,n,r,(h,p)=>o(k(h._1,h._2,s),p),(h,p)=>n(m=>{const w=l._3&&!h._3?k(h._1,h._2,!0):h;return n(y=>ln(w,n,r,(x,v)=>o(k(x._1,x._2,s),v),(x,v)=>n(C=>i(w._3&&!x._3?k(x._1,x._2,!0):x,t))))})))})))},vn=t=>(e,n,r,o,i)=>{const s=e._3;return n(a=>cn(t)(e,n,r,(u,c)=>o(k(u._1,u._2,s),c),(u,c)=>n(_=>{const d=Ji((()=>{const f=xt(At(p=>p==="_"))("'_'"),h=xt(At(p=>p==="-"))("'-'");return(p,m,w,y,x)=>{const v=p._1,C=p._2;return m(L=>$a(k(v,C,!1),m,w,(E,B)=>{const z=E._3;return m(Y=>{if(z)return y(E,B);const R=p._1,A=p._2;return m(j=>ls(k(R,A,!1),m,w,(Z,M)=>{const W=Z._3;return m(H=>{if(W)return y(Z,M);const D=p._1,F=p._2;return m(S=>f(k(D,F,!1),m,w,(G,Q)=>{const V=G._3;return m(X=>V?y(G,Q):h(p,m,w,y,x))},x))})},x))})},x))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(f=>d(l,n,r,(h,p)=>o(k(h._1,h._2,s),p),(h,p)=>n(m=>i(l._3&&!h._3?k(h._1,h._2,!0):h,void 0))))})))},aS=(t,e,n,r,o)=>e(i=>vn("into")(t,e,n,r,(s,a)=>e(u=>{const c=xt(io)("space after 'into'"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=Tn(xt(We)("node identifier after 'into'")),m=_._3&&!l._3?k(l._1,l._2,!0):l;return e(w=>p(m,e,n,r,(y,x)=>e(v=>o(m._3&&!y._3?k(y._1,y._2,!0):y,{op:Xn("Enter",{id:x._1}),operands:[x._2]}))))})))}))),uS=(t,e,n,r,o)=>e(i=>vn("out")(t,e,n,r,(s,a)=>e(u=>o(t._3&&!s._3?k(s._1,s._2,!0):s,{op:b5,operands:[]})))),cS=(t,e,n,r,o)=>e(i=>vn("seed")(t,e,n,r,(s,a)=>e(u=>{const c=t._3&&!s._3?k(s._1,s._2,!0):s;return e(_=>ee(c,e,n,r,(d,l)=>e(f=>{const h=xt(iS)("integer (seed value)"),p=c._3&&!d._3?k(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(w,y)=>e(x=>{const v=p._3&&!w._3?k(w._1,w._2,!0):w;return e(C=>ln(v,e,n,r,(L,E)=>e(B=>o(v._3&&!L._3?k(L._1,L._2,!0):L,y))))})))})))}))),cp=(t,e,n,r,o)=>{const i=t._3;return e(s=>vn("diagram")(t,e,n,(a,u)=>r(k(a._1,a._2,i),u),(a,u)=>e(c=>{const _=xt(io)("space after 'diagram'"),d=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>_(d,e,n,(f,h)=>r(k(f._1,f._2,i),h),(f,h)=>e(p=>{const m=xt(vn("sequence"))("diagram mode"),w=d._3&&!f._3?k(f._1,f._2,!0):f;return e(y=>m(w,e,n,(x,v)=>r(k(x._1,x._2,i),v),(x,v)=>e(C=>{const L=w._3&&!x._3?k(x._1,x._2,!0):x;return e(E=>ip(L,e,n,(B,z)=>r(k(B._1,B._2,i),z),(B,z)=>e(Y=>o(L._3&&!B._3?k(B._1,B._2,!0):B,C5))))})))})))})))},gp=(t,e,n,r,o)=>{const i=t._3;return e(s=>vn("still")(t,e,n,(a,u)=>r(k(a._1,a._2,i),u),(a,u)=>e(c=>{const _=t._3&&!a._3?k(a._1,a._2,!0):a;return e(d=>ip(_,e,n,(l,f)=>r(k(l._1,l._2,i),f),(l,f)=>e(h=>o(_._3&&!l._3?k(l._1,l._2,!0):l,v5))))})))},_p=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(a=>gp(k(i,s,!1),e,n,(u,c)=>{const _=u._3;return e(d=>_?r(u,c):cp(t,e,n,r,o))},o))},gS=t=>(e,n,r,o,i)=>n(s=>jn(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>{const l=_._3;return _p(_,n,r,(f,h)=>o(k(f._1,f._2,l),h),(f,h)=>n(p=>o(_._3&&!f._3?k(f._1,f._2,!0):f,wr((()=>{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))))})}))),_S=t=>(e,n,r,o,i)=>n(s=>jn(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>{const l=(p,m)=>n(w=>(()=>{if(m.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(x,v,C,L,E)=>L(x,wr(y,u))}if(m.tag==="Nothing")return(y,x,v,C,L)=>L(y,void 0);g()})()(_._3&&!p._3?k(p._1,p._2,!0):p,n,r,o,i)),f=_._1,h=_._2;return n(p=>n(m=>_p(k(f,h,!1),n,r,(w,y)=>{const x=w._3;return n(v=>x?o(w,y):l(_,J))},(w,y)=>n(x=>l(w,N("Just",y))))))})}))),fS=(t,e,n,r,o)=>e(i=>{const s=(c,_)=>e(d=>{const l=t._3&&!c._3?k(c._1,c._2,!0):c;return e(f=>ln(l,e,n,r,(h,p)=>e(m=>{const w=l._3&&!h._3?k(h._1,h._2,!0):h;return e(y=>_S(_)(w,e,n,r,(x,v)=>e(C=>o(w._3&&!x._3?k(x._1,x._2,!0):x,_))))})))}),a=t._1,u=t._2;return e(c=>gp(k(a,u,!1),e,n,(_,d)=>{const l=_._3;return e(f=>l?r(_,d):cp(t,e,n,r,s))},s))}),dS=(t,e,n,r,o)=>e(i=>{const s=(c,_)=>e(d=>o(c,(()=>{if(_.tag==="Nothing")return T5;if(_.tag==="Just")return _._1;g()})())),a=t._1,u=t._2;return e(c=>e(_=>fS(k(a,u,!1),e,n,(d,l)=>{const f=d._3;return e(h=>f?r(d,l):s(t,J))},(d,l)=>e(f=>s(d,N("Just",l))))))}),lS=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>ee(t,e,n,(u,c)=>r(k(u._1,u._2,s),c),(u,c)=>e(_=>vn("via")(t._3&&!u._3?k(u._1,u._2,!0):u,e,n,(d,l)=>r(k(d._1,d._2,s),l),(d,l)=>e(f=>{const h=t._3&&!d._3?k(d._1,d._2,!0):d;return e(p=>qa(h,e,n,r,(m,w)=>e(y=>{const x=h._3&&!m._3?k(m._1,m._2,!0):m;return e(v=>io(x,e,n,r,(C,L)=>e(E=>{const B=xt(We)("source node identifier after 'via'"),z=x._3&&!C._3?k(C._1,C._2,!0):C;return e(Y=>B(z,e,n,r,(R,A)=>e(j=>{const Z=z._3&&!R._3?k(R._1,R._2,!0):R;return e(M=>ee(Z,e,n,r,(W,H)=>e(D=>{const F=xt(We)("target node identifier after 'via'"),S=Z._3&&!W._3?k(W._1,W._2,!0):W;return e(G=>F(S,e,n,r,(Q,V)=>e(X=>o(S._3&&!Q._3?k(Q._1,Q._2,!0):Q,{from:A,to:V}))))})))})))})))})))})))))}),hS=t=>e=>{const n=Rn(lS);return(r,o,i,s,a)=>o(u=>n(r,o,i,s,(c,_)=>o(d=>a(r._3&&!c._3?k(c._1,c._2,!0):c,{op:Xn("DelNode",{id:t,via:Zt(de.foldr,_)}),operands:[e]}))))},pS=(()=>{const t=xt(At(e=>e==="-"))("'-'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=xt(io)("space after '-'"),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=Tn(xt(We)("node identifier after '-'")),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(y=>m(w,n,r,o,(x,v)=>n(C=>{const L=v._1,E=v._2,B=w._3&&!x._3?k(x._1,x._2,!0):x;return n(z=>sp(B,n,r,o,(Y,R)=>n(A=>(()=>{if(R.tag==="Just")return eS(L)(E)(R._1);if(R.tag==="Nothing")return hS(L)(E);g()})()(B._3&&!Y._3?k(Y._1,Y._2,!0):Y,n,r,o,i))))})))})))})))})(),Zn=t=>e=>(n,r,o,i,s)=>r(a=>jn(n,r,o,i,(u,c)=>r(_=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return r(l=>vn(t)(d,r,o,i,(f,h)=>r(p=>i(d._3&&!f._3?k(f._1,f._2,!0):f,wr(e,c)))))}))),mS=t=>t==="AnimatedSurface"?(e,n,r,o,i)=>n(s=>jn(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>vn("step")(_,n,r,o,(l,f)=>n(h=>{const p=xt(io)("space after 'step'"),m=_._3&&!l._3?k(l._1,l._2,!0):l;return n(w=>p(m,n,r,o,(y,x)=>n(v=>{const C=Tn(xt(We)("step name")),L=m._3&&!y._3?k(y._1,y._2,!0):y;return n(E=>C(L,n,r,o,(B,z)=>n(Y=>{const R=z._1,A=z._2,j=L._3&&!B._3?k(B._1,B._2,!0):B;return n(Z=>jn(j,n,r,o,(M,W)=>n(H=>{const D=j._3&&!M._3?k(M._1,M._2,!0):M;return n(F=>ee(D,n,r,o,(S,G)=>n(Q=>{const V=D._3&&!S._3?k(S._1,S._2,!0):S;return n(X=>rp(V,n,r,o,(U,q)=>n(K=>{const et=V._3&&!U._3?k(U._1,U._2,!0):U;return n(lt=>ln(et,n,r,o,(bt,pt)=>n(vt=>{const Gt={line:u.line,column:u.column,endLine:W.line,endColumn:W.column};return i(et._3&&!bt._3?k(bt._1,bt._2,!0):bt,{name:N("Just",R),ops:yr("Leaf",{op:Xn("Step",{name:R}),line:Gt.line,column:Gt.column,endLine:Gt.endLine,endColumn:Gt.endColumn,span:Gt,operands:[A]}),kind:Mh})})))})))})))})))})))})))})))}))):Zn("step")("`step` markers are only supported in animated diagrams."),yS=(()=>{const t=xt(At(e=>e===":"))("':'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>ee(_,n,r,o,(l,f)=>n(h=>{const p=Rn(At(RL)),m=_._3&&!l._3?k(l._1,l._2,!0):l;return n(w=>p(m,n,r,o,(y,x)=>n(v=>i(m._3&&!y._3?k(y._1,y._2,!0):y,Is($r(Zt(de.foldr,x)))))))})))})))})(),xS=(t,e,n,r,o)=>e(i=>ee(t,e,n,r,(s,a)=>e(u=>xt((c,_,d,l,f)=>{const h=c._1,p=c._2;return _(m=>yS(k(h,p,!1),_,d,(w,y)=>{const x=w._3;return _(v=>{if(x)return l(w,y);const C=c._1,L=c._2;return _(E=>KL(k(C,L,!1),_,d,(B,z)=>{const Y=B._3;return _(R=>Y?l(B,z):UL(c,_,d,l,f))},f))})},f))})('label ("\u2026", : rest-of-line, or |\u2026|)')(t._3&&!s._3?k(s._1,s._2,!0):s,e,n,r,o)))),Va=t=>(e,n,r,o,i)=>n(s=>ee(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>{const l=(p,m)=>n(w=>(m?((y,x,v,C,L)=>L(y,J)):(y,x,v,C,L)=>x(E=>xS(y,x,v,C,(B,z)=>x(Y=>L(B,N("Just",z))))))(_._3&&!p._3?k(p._1,p._2,!0):p,n,r,o,i)),f=_._1,h=_._2;return n(p=>{const m=(w,y)=>{const x=w._3;return n(v=>x?o(w,y):l(_,!1))};return n(w=>n(y=>n(x=>ds(k(f,h,!1),n,r,(v,C)=>{const L=v._3;return n(E=>L?m(k(f,h,!1),C):n(B=>At(t)(k(f,h,!1),n,r,(z,Y)=>m(k(f,h,!1),Y),(z,Y)=>n(R=>n(A=>l(k(f,h,!1),!0))))))},(v,C)=>n(L=>n(E=>l(k(f,h,!1),!0)))))))})})}))),wS=t=>e=>n=>(r,o,i,s,a)=>o(u=>ee(r,o,i,s,(c,_)=>o(d=>{const l=Tn(xt(We)("target node identifier")),f=r._3&&!c._3?k(c._1,c._2,!0):c;return o(h=>l(f,o,i,s,(p,m)=>o(w=>{const y=m._1,x=m._2,v=f._3&&!p._3?k(p._1,p._2,!0):p;return o(C=>Va(Vg)(v,o,i,s,(L,E)=>o(B=>a(v._3&&!L._3?k(L._1,L._2,!0):L,{op:Xn("AddEdge",{from:t,to:y,label:E.tag==="Just"?N("Just",E._1):J,directed:n}),operands:[e,x]}))))})))}))),JS=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>Tn(We)(t,e,n,(u,c)=>r(k(u._1,u._2,s),c),(u,c)=>e(_=>{const d=t._3&&!u._3?k(u._1,u._2,!0):u;return e(l=>ee(d,e,n,(f,h)=>r(k(f._1,f._2,s),h),(f,h)=>e(p=>{const m=xt(At(y=>y==="<"))("'<'"),w=d._3&&!f._3?k(f._1,f._2,!0):f;return e(y=>m(w,e,n,(x,v)=>r(k(w._1,w._2,s),v),(x,v)=>e(C=>{const L=Ji((B,z,Y,R,A)=>{const j=B._3;return cn("<-")(B,z,Y,(Z,M)=>R(k(Z._1,Z._2,j),M),A)}),E=w._3&&!w._3?k(w._1,w._2,!0):w;return e(B=>L(E,e,n,(z,Y)=>r(k(z._1,z._2,s),Y),(z,Y)=>e(R=>{const A=E._3&&!z._3?k(z._1,z._2,!0):z;return e(j=>{const Z=c._1,M=c._2,W=t._3&&!A._3?k(A._1,A._2,!0):A;return e(H=>ee(W,e,n,r,(D,F)=>e(S=>{const G=xt(cn("<~"))("'<~'"),Q=W._3&&!D._3?k(D._1,D._2,!0):D;return e(V=>G(Q,e,n,r,(X,U)=>e(q=>{const K=Q._3&&!X._3?k(X._1,X._2,!0):X;return e(et=>ee(K,e,n,r,(lt,bt)=>e(pt=>{const vt=Tn(xt(We)("target node identifier")),Gt=K._3&&!lt._3?k(lt._1,lt._2,!0):lt;return e(jt=>vt(Gt,e,n,r,(Ct,Yt)=>e(Rt=>{const wt=Yt._1,mt=Yt._2,ct=Gt._3&&!Ct._3?k(Ct._1,Ct._2,!0):Ct;return e(yt=>Va(Vg)(ct,e,n,r,(dt,ht)=>e(Et=>o(ct._3&&!dt._3?k(dt._1,dt._2,!0):dt,{op:Xn("Token",{from:wt,to:Z,labels:(()=>{if(ht.tag==="Nothing")return[];if(ht.tag==="Just")return[ht._1];g()})()}),operands:[mt,M]}))))})))})))})))})))})})))})))})))})))}),NS=(t,e,n,r,o)=>e(i=>rS(t,e,n,r,(s,a)=>e(u=>{const c=a._2._2,_=a._1,d=a._2._1,l=t._3&&!s._3?k(s._1,s._2,!0):s;return e(f=>ee(l,e,n,r,(h,p)=>e(m=>{const w=Tn(xt(We)("target node identifier")),y=l._3&&!h._3?k(h._1,h._2,!0):h;return e(x=>w(y,e,n,r,(v,C)=>e(L=>{const E=C._1,B=C._2,z=y._3&&!v._3?k(v._1,v._2,!0):v;return e(Y=>Va(Vg)(z,e,n,r,(R,A)=>e(j=>(c==="<~"?((Z,M,W,H,D)=>D(Z,{op:Xn("Token",{from:E,to:_,labels:(()=>{if(A.tag==="Nothing")return[];if(A.tag==="Just")return[A._1];g()})()}),operands:c==="<~"?[B,d]:[d,B]})):(Z,M,W,H,D)=>D(Z,{op:Xn("Token",{from:_,to:E,labels:(()=>{if(A.tag==="Nothing")return[];if(A.tag==="Just")return[A._1];g()})()}),operands:c==="<~"?[B,d]:[d,B]}))(z._3&&!R._3?k(R._1,R._2,!0):R,e,n,r,o))))})))})))}))),TS=(t,e,n,r,o)=>e(i=>Va(FL)(t,e,n,r,(s,a)=>e(u=>o(s,(()=>{if(a.tag==="Nothing")return"";if(a.tag==="Just")return a._1;g()})())))),vS=t=>e=>(n,r,o,i,s)=>r(a=>TS(n,r,o,i,(u,c)=>r(_=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return r(l=>tS(d,r,o,i,(f,h)=>r(p=>s(d._3&&!f._3?k(f._1,f._2,!0):f,{op:Xn("AddNode",{id:t,label:c,shape:(()=>{const m=GL("shape")(h);if(m.tag==="Just")return m._1==="rectangle"||m._1==="rect"?Vr:m._1==="cylinder"||m._1==="cyl"?$m:m._1==="parallelogram"?Vm:m._1==="diamond"?Um:m._1==="ellipse"?Xm:m._1==="document"||m._1==="doc"?Ym:m._1==="cloud"?Km:Vr;if(m.tag==="Nothing")return Vr;g()})()}),operands:[e]}))))}))),CS=(()=>{const t=xt(At(e=>e==="+"))("'+'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=xt(io)("space after '+'"),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=Tn(xt(We)("node identifier after '+'")),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(y=>m(w,n,r,o,(x,v)=>n(C=>{const L=v._1,E=v._2,B=w._3&&!x._3?k(x._1,x._2,!0):x;return n(z=>sp(B,n,r,o,(Y,R)=>n(A=>(()=>{if(R.tag==="Just")return wS(L)(E)(R._1);if(R.tag==="Nothing")return vS(L)(E);g()})()(B._3&&!Y._3?k(Y._1,Y._2,!0):Y,n,r,o,i))))})))})))})))})(),bS=(t,e,n,r,o)=>e(i=>jn(t,e,n,r,(s,a)=>e(u=>{const c=xt(Hg([Zn("+node")("Node additions use `+ api: API`."),Zn("+edge")("Graph edges use `+ api -> db`."),Zn("+conn")("Undirected graph edges use `+ api -- db`."),Zn("-node")("Node removals use `- api`."),Zn("-edge")("Graph edge removals use `- api -> db`."),Zn("-conn")("Undirected graph edge removals use `- api -- db`."),Zn("~edge")("Graph edge repoints use `~ api -> db => api -> cache`."),Zn("enter")("Dive commands use `into api`."),Zn("exit")("Return from a dive with `out`."),nS,CS,pS,oS,NS,JS,aS,uS]))("statement (+ node, - node, + edge, - edge, into, out, or 'a ~> b'/'a <~ b')"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=_._3&&!l._3?k(l._1,l._2,!0):l;return e(m=>jn(p,e,n,r,(w,y)=>e(x=>{const v={line:a.line,column:a.column,endLine:y.line,endColumn:y.column};return o(p._3&&!w._3?k(w._1,w._2,!0):w,yr("Leaf",{op:f.op,line:v.line,column:v.column,endLine:v.endLine,endColumn:v.endColumn,span:v,operands:f.operands}))})))})))}))),Ug=ep((()=>{const t=xt(At(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(s=>n(a=>t(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return ln(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(f._1,f._2,!0):f,h)))})))))})())(xt((()=>{const t=xt(At(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(s=>n(a=>ln(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return t(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(f._1,f._2,!0):f,h)))})))))})())("closing '}'")),fp=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>ln(t,e,n,(u,c)=>r(k(u._1,u._2,s),c),(u,c)=>e(_=>{const d=Ji(xt(At(f=>f==="}"))("'}'")),l=t._3&&!u._3?k(u._1,u._2,!0):u;return e(f=>d(l,e,n,(h,p)=>r(k(h._1,h._2,s),p),(h,p)=>e(m=>Ji(ds)(l._3&&!h._3?k(h._1,h._2,!0):h,e,n,(w,y)=>r(k(w._1,w._2,s),y),(w,y)=>e(x=>{const v=t._3&&!w._3?k(w._1,w._2,!0):w;return e(C=>qa(v,e,n,r,(L,E)=>e(B=>{const z=Hg([LS,kS,bS]),Y=v._3&&!L._3?k(L._1,L._2,!0):L;return e(R=>z(Y,e,n,r,(A,j)=>e(Z=>{const M=Y._3&&!A._3?k(A._1,A._2,!0):A;return e(W=>ee(M,e,n,r,(H,D)=>e(F=>{const S=M._3&&!H._3?k(H._1,H._2,!0):H;return e(G=>rp(S,e,n,r,(Q,V)=>e(X=>{const U=S._3&&!Q._3?k(Q._1,Q._2,!0):Q;return e(q=>ln(U,e,n,r,(K,et)=>e(lt=>o(U._3&&!K._3?k(K._1,K._2,!0):K,j))))})))})))})))})))})))))})))}),kS=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(a=>{const u=(c,_)=>{const d=c._3;return e(l=>d?r(c,_):e(f=>{const h=t._3;return e(p=>vn("seq")(t,e,n,(m,w)=>r(k(m._1,m._2,h),w),(m,w)=>e(y=>{const x=t._3&&!m._3?k(m._1,m._2,!0):m;return e(v=>ee(x,e,n,(C,L)=>r(k(C._1,C._2,h),L),(C,L)=>e(E=>$g(x._3&&!C._3?k(C._1,C._2,!0):C,e,n,(B,z)=>r(k(B._1,B._2,h),z),(B,z)=>e(Y=>{const R=t._3&&!B._3?k(B._1,B._2,!0):B;return e(A=>qa(R,e,n,r,(j,Z)=>e(M=>{const W=xt(xt(At(D=>D==="{"))("'{'"))("'{'"),H=R._3&&!j._3?k(j._1,j._2,!0):j;return e(D=>W(H,e,n,r,(F,S)=>e(G=>o(H._3&&!F._3?k(F._1,F._2,!0):F,yr("GroupSeq",[])))))})))})))))})))}))};return e(c=>e(_=>vn("seq")(k(i,s,!1),e,n,(d,l)=>u(k(d._1,d._2,!1),l),(d,l)=>e(f=>e(h=>ee(d,e,n,(p,m)=>u(k(p._1,p._2,!1),m),(p,m)=>e(w=>{const y=d._3&&!p._3?k(p._1,p._2,!0):p;return xt(At(x=>x==="{"))("'{'")(y,e,n,(x,v)=>u(k(y._1,y._2,!1),v),(x,v)=>e(C=>Ug(Xg(E5))(y,e,n,u,o)))})))))))})},LS=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(a=>{const u=(c,_)=>{const d=c._3;return e(l=>d?r(c,_):e(f=>{const h=t._3;return e(p=>vn("par")(t,e,n,(m,w)=>r(k(m._1,m._2,h),w),(m,w)=>e(y=>{const x=t._3&&!m._3?k(m._1,m._2,!0):m;return e(v=>ee(x,e,n,(C,L)=>r(k(C._1,C._2,h),L),(C,L)=>e(E=>$g(x._3&&!C._3?k(C._1,C._2,!0):C,e,n,(B,z)=>r(k(B._1,B._2,h),z),(B,z)=>e(Y=>{const R=t._3&&!B._3?k(B._1,B._2,!0):B;return e(A=>qa(R,e,n,r,(j,Z)=>e(M=>{const W=xt(xt(At(D=>D==="{"))("'{'"))("'{'"),H=R._3&&!j._3?k(j._1,j._2,!0):j;return e(D=>W(H,e,n,r,(F,S)=>e(G=>o(H._3&&!F._3?k(F._1,F._2,!0):F,yr("Par",[])))))})))})))))})))}))};return e(c=>e(_=>vn("par")(k(i,s,!1),e,n,(d,l)=>u(k(d._1,d._2,!1),l),(d,l)=>e(f=>e(h=>ee(d,e,n,(p,m)=>u(k(p._1,p._2,!1),m),(p,m)=>e(w=>{const y=d._3&&!p._3?k(p._1,p._2,!0):p;return xt(At(x=>x==="{"))("'{'")(y,e,n,(x,v)=>u(k(y._1,y._2,!1),v),(x,v)=>e(C=>Ug(Xg(L5))(y,e,n,u,o)))})))))))})},Xg=t=>{const e=Rn(fp);return(n,r,o,i,s)=>r(a=>e(n,r,o,i,(u,c)=>r(_=>s(n._3&&!u._3?k(u._1,u._2,!0):u,t(Zt(de.foldr,c))))))},Yg=t=>e=>(n,r,o,i,s)=>r(a=>sS(t)(n,r,o,i,(u,c)=>r(_=>{const d=Rn(At(QL)),l=n._3&&!u._3?k(u._1,u._2,!0):u;return r(f=>d(l,r,o,i,(h,p)=>r(m=>{const w=xt(xt(At(x=>x==="{"))("'{'"))("'{'"),y=l._3&&!h._3?k(h._1,h._2,!0):h;return r(x=>w(y,r,o,i,(v,C)=>r(L=>{const E=y._3&&!v._3?k(v._1,v._2,!0):v;return r(B=>ln(E,r,o,i,(z,Y)=>r(R=>{const A=Xg(S5),j=E._3&&!z._3?k(z._1,z._2,!0):z;return r(Z=>A(j,r,o,i,(M,W)=>r(H=>{const D=j._3&&!M._3?k(M._1,M._2,!0):M;return r(F=>ln(D,r,o,i,(S,G)=>r(Q=>{const V=xt(xt(At(U=>U==="}"))("'}'"))("closing '}'"),X=D._3&&!S._3?k(S._1,S._2,!0):S;return r(U=>V(X,r,o,i,(q,K)=>r(et=>{const lt=X._3&&!q._3?k(q._1,q._2,!0):q;return r(bt=>ln(lt,r,o,i,(pt,vt)=>r(Gt=>s(lt._3&&!pt._3?k(pt._1,pt._2,!0):pt,{name:HL($r(Zt(de.foldr,p))),ops:W,kind:e}))))})))})))})))})))})))})))}))),SS=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(a=>Zn("keyframe")("Drop the `keyframe` wrapper; Markgraf animates statements in order.")(k(i,s,!1),e,n,(u,c)=>{const _=u._3;return e(d=>{if(_)return r(u,c);const l=t._1,f=t._2;return e(h=>Yg("scene")(Qa)(k(l,f,!1),e,n,(p,m)=>{const w=p._3;return e(y=>{if(w)return r(p,m);const x=t._1,v=t._2;return e(C=>Yg("still")(Mg)(k(x,v,!1),e,n,(L,E)=>{const B=L._3;return e(z=>B?r(L,E):Yg("title")(k5)(t,e,n,r,o))},o))})},o))})},o))},ES=t=>e=>n=>{if(t==="AnimatedSurface")return{...e,frames:kt(e.frames)({name:J,ops:n,kind:Qa})};if(t==="StillSurface")return{...e,statements:kt(e.statements)(n)};if(t==="SequenceSurface")return{...e,statements:kt(e.statements)(n)};g()},GS=t=>e=>n=>{if(n.tag==="TopFrame"){const r=ap(t)(e);return{...r,frames:kt(r.frames)((()=>{if(t==="AnimatedSurface")return n._1;if(t==="StillSurface")return{...n._1,kind:n._1.kind==="AnimatedKeyframe"?Mg:n._1.kind==="StepMarker"?Mh:n._1.kind};if(t==="SequenceSurface")return n._1;g()})())}}if(n.tag==="TopStatement")return ES(t)(e)(n._1);if(n.tag==="TopInside")return e;g()},PS=t=>{const e=T(GS(t))(XL);return n=>ap(t)(e(n)).frames},BS=t=>pL.defer(e=>{const n=mS(t);return(r,o,i,s,a)=>{const u=r._1,c=r._2;return o(_=>gS(t)(k(u,c,!1),o,i,(d,l)=>{const f=d._3;return o(h=>{if(f)return s(d,l);const p=r._1,m=r._2;return o(w=>o(y=>DS(k(p,m,!1),o,i,(x,v)=>{const C=x._3;return o(L=>{if(C)return s(x,v);const E=r._1,B=r._2;return o(z=>o(Y=>n(k(E,B,!1),o,i,(R,A)=>{const j=R._3;return o(Z=>{if(j)return s(R,A);const M=r._1,W=r._2;return o(H=>o(D=>SS(k(M,W,!1),o,i,(F,S)=>{const G=F._3;return o(Q=>G?s(F,S):o(V=>fp(r,o,i,s,(X,U)=>o(q=>a(X,Ha("TopStatement",U))))))},(F,S)=>o(G=>a(F,Ha("TopFrame",S))))))})},(R,A)=>o(j=>a(R,Ha("TopFrame",A))))))})},(x,v)=>o(C=>a(x,Ha("TopInside",v))))))})},a))}}),DS=(t,e,n,r,o)=>e(i=>vn("inside")(t,e,n,r,(s,a)=>e(u=>{const c=xt(io)("space after 'inside'"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=xt(We)("node identifier after 'inside'"),m=_._3&&!l._3?k(l._1,l._2,!0):l;return e(w=>p(m,e,n,r,(y,x)=>e(v=>{const C=m._3&&!y._3?k(y._1,y._2,!0):y;return e(L=>ln(C,e,n,r,(E,B)=>e(z=>{const Y=C._3&&!E._3?k(E._1,E._2,!0):E;return e(R=>Ug(dp)(Y,e,n,r,(A,j)=>e(Z=>{const M=Y._3&&!A._3?k(A._1,A._2,!0):A;return e(W=>ln(M,e,n,r,(H,D)=>e(F=>o(M._3&&!H._3?k(H._1,H._2,!0):H,{node:x,doc:j}))))})))})))})))})))}))),dp=(t,e,n,r,o)=>e(i=>dS(t,e,n,r,(s,a)=>e(u=>{const c=t._3&&!s._3?k(s._1,s._2,!0):s;return e(_=>{const d=(h,p)=>e(m=>{const w=Rn(BS(a)),y=c._3&&!h._3?k(h._1,h._2,!0):h;return e(x=>w(y,e,n,r,(v,C)=>e(L=>{const E=Zt(de.foldr,C);return o(y._3&&!v._3?k(v._1,v._2,!0):v,{seed:(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})(),mode:a,frames:PS(a)(E),interiors:Tt(B=>{if(B.tag==="TopInside")return N("Just",B._1);if(B.tag==="TopFrame"||B.tag==="TopStatement")return J;g()})(E)})})))}),l=c._1,f=c._2;return e(h=>e(p=>cS(k(l,f,!1),e,n,(m,w)=>{const y=m._3;return e(x=>y?r(m,w):d(c,J))},(m,w)=>e(y=>d(m,N("Just",w))))))})}))),RS=(()=>{const t=xt((e,n,r,o,i)=>n(s=>n(a=>ln(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return ds(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(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(s=>n(a=>n(u=>n(c=>ln(e,n,r,o,(_,d)=>n(l=>n(f=>{const h=e._3&&!_._3?k(_._1,_._2,!0):_;return dp(h,n,r,o,(p,m)=>n(w=>{const y=h._3&&!p._3?k(p._1,p._2,!0):p;return n(x=>n(v=>{const C=e._3&&!y._3?k(y._1,y._2,!0):y;return t(C,n,r,o,(L,E)=>n(B=>i(C._3&&!L._3?k(L._1,L._2,!0):L,m)))}))}))})))))))})(),AS=t=>{const e=wL(t)(RS);if(e.tag==="Left")return Wt("Left",{msg:OL(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 Wt("Right",e._1);g()},IS=t=>{const e=AS(t);if(e.tag==="Left")return Wt("Left",e._1.msg);if(e.tag==="Right")return Wt("Right",e._1);g()},FS=()=>({tag:"ParFrag"}),lp=t=>t,QS=lp("Sync"),MS=lp("SelfMsg"),zS=FS(),so=Ih(kn),Ni=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Hn=Go(kn),zr=so.state(t=>b(t,t)),hp=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ua=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Do=Po(kn),WS=t=>e=>T(n=>r=>Go(kn).bind(n)(o=>t(o)(r)))(Po(kn).pure(e)),pp=Wr(Do)(zt),qS=t=>so.state(e=>b(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:N("Just",t)};g()})())),OS=t=>e=>so.state(n=>b(void 0,{...n,lifelines:J_(P)(r=>N("Just",{...r,label:e}))(t)(n.lifelines)})),HS=t=>e=>n=>{const r=Ni(n)(t.lifelines);return Ni(e)(t.lifelines).tag==="Nothing"?r.tag==="Nothing"?e+", "+n:e:r.tag==="Nothing"?n:""},$S={lifelines:I,lifelineOrder:[],messages:[],fragments:[],frameEndRows:[],row:0,error:J},VS=t=>e=>n=>Hn.bind(zr)(r=>{const o=Ni(t)(r.lifelines),i=Ni(e)(r.lifelines);if(o.tag==="Just"&&i.tag==="Just"){const s={...r,messages:[{fromCol:o._1.column,toCol:i._1.column,labels:n,row:r.row,kind:t===e?MS:QS},...r.messages],row:r.row+1|0};return so.state(a=>b(void 0,s))}return qS("token references unknown node: "+HS(r)(t)(e))}),US=t=>so.state(e=>b(void 0,{...e,lifelines:J_(P)(n=>N("Just",{...n,destroyedAt:N("Just",e.row)}))(t)(e.lifelines)})),XS=t=>e=>{const n=e.lifelineOrder.length,r=Ft(o=>J,o=>i=>N("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return{fromCol:0,toCol:Ua(0)(e.lifelineOrder.length-1|0)};if(r.tag==="Just")return T(o=>i=>({fromCol:hp(o.fromCol)(hp(i.fromCol)(i.toCol)),toCol:Ua(o.toCol)(Ua(i.fromCol)(i.toCol))}))({fromCol:n,toCol:0})(t);g()},YS=t=>({lifelines:Tt(e=>Ni(e)(t.lifelines))(t.lifelineOrder),messages:se(t.messages),fragments:se(t.fragments),frameEndRows:t.frameEndRows,totalRows:t.row}),KS=t=>e=>Hn.bind(zr)(n=>{const r=Ni(t)(n.lifelines);if(r.tag==="Just")return Do.pure();if(r.tag==="Nothing"){const o={...n,lifelines:rt(P)(t)({id:t,label:e,column:n.lifelineOrder.length,createdAt:n.row,destroyedAt:J})(n.lifelines),lifelineOrder:kt(n.lifelineOrder)(t),row:n.row>0||n.messages.length!==0?n.row+1|0:n.row};return so.state(i=>b(void 0,o))}g()}),jS=t=>{if(t.tag==="AddNode")return KS(t._1.id)(t._1.label);if(t.tag==="DelNode")return US(t._1.id);if(t.tag==="ModNode"){if(t._1.label.tag==="Just")return OS(t._1.id)(t._1.label._1);if(t._1.label.tag==="Nothing")return Do.pure();g()}return t.tag==="Token"?VS(t._1.from)(t._1.to)(t._1.labels):Do.pure()},ZS=t=>Hn.bind(zr)(e=>{const n=e.row;return Hn.bind(WS(r=>o=>Hn.bind(zr)(i=>{const s=r.childMessages.length===0?r.dividers:[i.row,...r.dividers],a=i.messages;return Hn.bind(Kg(o))(()=>Hn.bind(zr)(u=>Do.pure({dividers:s,childMessages:[...r.childMessages,...(()=>{const c=u.messages.length-a.length|0;return c<1?[]:Bt(0,c,u.messages)})()]})))}))({dividers:[],childMessages:[]})(t))(r=>Hn.bind(zr)(o=>{const i=XS(r.childMessages)(o),s={kind:zS,label:"par",fromRow:n,toRow:Ua(o.row)(n+1|0),fromCol:i.fromCol,toCol:i.toCol,regionDividers:se(r.dividers)},a=so.state(u=>b(void 0,{...u,fragments:[s,...u.fragments]}));return r.childMessages.length>=2?a:Do.pure()}))}),Kg=t=>{if(t.tag==="Leaf")return jS(t._1.op);if(t.tag==="Seq"||t.tag==="GroupSeq")return pp(Kg)(t._1);if(t.tag==="Par")return ZS(t._1);g()},tE=t=>{const e=Hn.bind(pp(n=>Hn.bind(zr)(r=>Hn.bind(Kg(n.ops))(()=>Hn.bind(zr)(o=>{const i=so.state(s=>b(void 0,{...s,frameEndRows:kt(s.frameEndRows)(s.row-1|0)}));return(o.messages.length-r.messages.length|0)>0?i:Do.pure()}))))(t.frames))(()=>zr)($S)._1;if(e.error.tag==="Just")return Wt("Left",e.error._1);if(e.error.tag==="Nothing")return Wt("Right",YS(e));g()},eE=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},nE={padding:24,headerHeight:36,headerWidth:120,columnSpacing:160,rowHeight:36,topGap:24,bottomGap:24},rE=t=>{const e=84+nt(eE(1)(t.totalRows))*36,n=Ht(r=>o=>({lifeline:o,x:84+nt(r)*160}))(t.lifelines);return{metrics:nE,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}},oE=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},mp=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},yp=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 s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},xp=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},iE=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},sE=T(t=>e=>rt(it)(e)()(t))(I),aE={r:255,g:255,b:255,a:255},Xa={r:26,g:26,b:26,a:255},uE={color:{r:232,g:232,b:232,a:255},flat:!0},cE={r:232,g:232,b:232,a:255},Ya=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,...rs],wp=t=>e=>n=>({...n,stack:kt(n.stack)(t),openedAt:rt(it)(t)(e)(n.openedAt)}),Ka=t=>e=>{const n=e.stack.length-1|0;if(n>=0&&n<e.stack.length){const r=oE(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?[]:Bt(0,e.stack.length-1|0,e.stack),openedAt:qo(it)(e.stack[n])(e.openedAt),spans:kt(e.spans)({col:e.stack[n],fromRow:o,toRow:mp(o)(t)})}}return e},Jp=t=>e=>n=>{let r=t,o=e,i=n,s=!0,a;for(;s;){const u=r,c=o,_=i,d=_.stack.length-1|0;if(d>=0&&d<_.stack.length){if(u(_.stack[d])){s=!1,a=_;continue}r=u,o=c,i=Ka(c)(_);continue}s=!1,a=_}return a},Np=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r,u=a.stack.length-1|0;if(u>=0&&u<a.stack.length){n=s,r=Ka(s)(a);continue}o=!1,i=a}return i},gE=t=>e=>{const n=en(qr)(e.fromCol)(t.stack)?Jp((()=>{const r=e.fromCol;return o=>r===o})())(e.row-1|0)(t):wp(e.fromCol)(e.row)(Np(e.row-1|0)(t));if(en(qr)(e.toCol)(n.stack)){const r=Jp((()=>{const o=e.toCol;return i=>o===i})())(e.row-1|0)(Ka(e.row)(n));return{...r,returnRows:rt(it)(e.row)()(r.returnRows)}}return wp(e.toCol)(e.row)(n)},_E=t=>e=>n=>{const r=gE(e)(n);return yp(n.row)(t)?Np(n.row)(r):r},ja={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:es,lineCap:Un},Tp={r:26,g:26,b:26,a:255},fE={color:{r:130,g:130,b:130,a:255},width:1,lineJoin:es,lineCap:Gn},vp={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:es,lineCap:Gn},dE={color:{r:244,g:244,b:244,a:255},flat:!0},Cp=t=>e=>n=>xe(r=>r.col===e&&r.fromRow<=n&&n<=r.toRow,t),bp={color:{r:90,g:90,b:90,a:255},width:1,lineJoin:es,lineCap:Gn},lE={stack:[],openedAt:I,spans:[],returnRows:I},hE={color:{r:150,g:150,b:150,a:255},width:1,lineJoin:es,lineCap:Gn},pE=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])(hE)},mE=t=>{const e=t.Monad0(),n=e.Bind1(),r=Fo(e.Applicative0())(zt);return o=>i=>{const s=o.bodyTop+(nt(i.fromRow)+.5)*o.metrics.rowHeight-o.metrics.rowHeight/2-6,a=i.fromCol>=0&&i.fromCol<o.columns.length?o.columns[i.fromCol].x-16:o.metrics.padding-16,u=[1,a,s,2,a+38,s,2,a+32,s+14,2,a,s+14,...rs],c=i.toCol>=0&&i.toCol<o.columns.length?o.columns[i.toCol].x+16:o.metrics.padding+16,_=o.bodyTop+(nt(mp(i.toRow)(i.fromRow+1|0)-1|0)+.5)*o.metrics.rowHeight+o.metrics.rowHeight/2+6;return n.bind(t.strokePath([1,a,s,2,c,s,2,c,_,2,a,_,...rs])(bp))(()=>n.bind(t.fillStrokePath(u)(uE)(bp))(()=>n.bind(t.drawText({x:a+6,y:s+7,content:"par",font:{family:"Inter",size:11,weight:700},color:Xa,align:fi,baseline:En}))(()=>r(i.regionDividers)(pE(t)(o)(a)(c)))))}},kp=t=>e=>t>=e?[]:[b(t,xp(e)(t+6)),...kp(t+10)(e)],yE=t=>e=>{if(e<=t)return[];const n=r=>r>=e?[]:[b(r,xp(e)(r+6)),...n(r+10)];return n(t)},xE=t=>{const e=Fo(t.Monad0().Applicative0())(zt);return n=>r=>e(yE(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])(fE))},Lp=t=>e=>t<=e?[]:[b(t,iE(e)(t-6)),...Lp(t-6-4)(e)],wE=t=>e=>t===e?[]:t<e?kp(t)(e):Lp(t)(e),JE=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,s=o+n.metrics.headerHeight,a=Ya(r.x-i)(o)(r.x+i)(s)(6);return e.bind(t.fillStrokePath(Ya(r.x-i)(o+5)(r.x+i)(s+5)(6))({color:cE,flat:!0})(vp))(()=>e.bind(t.fillStrokePath(a)(dE)(vp))(()=>t.drawText({x:r.x,y:o+n.metrics.headerHeight/2,content:r.lifeline.label,font:{family:"Inter",size:14,weight:600},color:Xa,align:Dr,baseline:En})))}},NE=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r,u=a.stack.length-1|0;if(u>=0&&u<a.stack.length){n=s,r=Ka(s)(a);continue}o=!1,i=a}return i},TE=t=>NE((()=>{const e=t.diagram.messages.length-1|0;return e>=0&&e<t.diagram.messages.length?t.diagram.messages[e].row:0})())(T(_E(sE(t.diagram.frameEndRows)))(lE)(ft(e=>e.kind==="Sync"||e.kind!=="SelfMsg",t.diagram.messages))),vE=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,s=o-n.metrics.rowHeight*.3,a=i+36,u=o+n.metrics.rowHeight*.3,c=i+10,_=[1,i,u,2,c,u-5,2,c,u+5,...rs];return e.bind(t.strokePath([1,i,s,2,a,s,2,a,u,2,i,u])(ja))(()=>e.bind(t.fillPath(_)({color:Tp,flat:!0}))(()=>t.drawText({x:i+42,y:o,content:ur(" ")(O(Ci)(r.labels)),font:{family:"Inter",size:12,weight:400},color:Xa,align:fi,baseline:En})))}},CE=t=>{const e=t.Monad0(),n=e.Bind1(),r=Fo(e.Applicative0())(zt);return o=>i=>s=>a=>{const u=s?o.bodyTop+(nt(a.row)+.5)*o.metrics.rowHeight+o.metrics.rowHeight*.5:o.bodyTop+(nt(a.row)+.5)*o.metrics.rowHeight,c=a.toCol>=a.fromCol?1:-1,_=(a.fromCol>=0&&a.fromCol<o.columns.length?o.columns[a.fromCol].x:o.metrics.padding)+(Cp(i)(a.fromCol)(a.row)?c*6:c*0),d=(a.toCol>=0&&a.toCol<o.columns.length?o.columns[a.toCol].x:o.metrics.padding)-(Cp(i)(a.toCol)(a.row)?c*6:c*0),l=d-c*10,f=s?t.strokePath([1,l,u-5,2,d,u,2,l,u+5])(ja):t.fillPath([1,d,u,2,l,u-5,2,l,u+5,...rs])({color:Tp,flat:!0});return n.bind(s?r(wE(_)(d))(h=>t.strokePath([1,h._1,u,2,h._2,u])(ja)):t.strokePath([1,_,u,2,d,u])(ja))(()=>n.bind(f)(()=>t.drawText({x:(_+d)/2,y:u-6,content:ur(" ")(O(Ci)(a.labels)),font:{family:"Inter",size:12,weight:400},color:Xa,align:Dr,baseline:jT})))}},bE=t=>{const e=vE(t),n=CE(t);return r=>o=>i=>s=>{if(s.kind==="SelfMsg")return e(r)(s);if(s.kind==="Sync")return n(r)(o)(yp(s.row)(i))(s);g()}},Sp={color:{r:26,g:26,b:26,a:255},width:1.25,lineJoin:Ue,lineCap:Gn},kE={color:{r:232,g:232,b:232,a:255},flat:!0},LE={color:{r:252,g:252,b:252,a:255},flat:!0},SE=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,s=Ya(r-6)(o)(r+6)(i)(3);return t.Monad0().Bind1().bind(t.fillStrokePath(Ya(r-6)(o+5)(r+6)(i+5)(3))(kE)(Sp))(()=>t.fillStrokePath(s)(LE)(Sp))},Ep=t=>{const e=t.Monad0(),n=e.Bind1(),r=Fo(e.Applicative0())(zt),o=JE(t),i=xE(t),s=mE(t),a=bE(t);return u=>{const c=TE(u);return n.bind(t.setViewport({vx:0,vy:0,vw:u.width,vh:u.height}))(()=>n.bind(t.clearBackground(aE))(()=>n.bind(r(u.columns)(o(u)))(()=>n.bind(r(u.columns)(i(u)))(()=>n.bind(r(c.spans)(SE(t)(u)))(()=>n.bind(r(u.diagram.fragments)(s(u)))(()=>r(u.diagram.messages)(a(u)(c.spans)(c.returnRows))))))))}},EE=Ep(mv);function jg(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 s=Object.getPrototypeOf(i),a=s.constructor.name;if(a===n)return e(r);if(a==="Object")return t;i=s}return t}function gn(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function GE(t){return function(e){return function(){return e.getAttribute(t)}}}const Gp=t=>{const e=GE(t);return n=>{const r=e(n);return()=>{const o=r();return mn(o,J,Ut)}}};function PE(t){return function(e){return function(){e.textContent=t}}}function BE(t){return function(){return function(e){return t(e)()}}}function DE(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const Zg=function(){return window};function RE(t){return function(e){return function(){e.value=t}}}function AE(t){return function(){return t.valueAsNumber}}function IE(t){return function(){return t.value}}function t_(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const Pp=t=>t,Za=t=>()=>{const e=t.getBoundingClientRect?.(),n=e?.width||t.clientWidth||0,r=e?.height||t.clientHeight||0;return{width:n,height:r}},Bp=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)}},Dp=()=>window.devicePixelRatio||1,FE=t=>e=>n=>r=>o=>()=>{const i=Math.max(1,e||t.clientWidth||r),s=Math.max(1,n||t.clientHeight||o),a="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} ${s}`),t.setAttribute("preserveAspectRatio","xMidYMid meet"),t.innerHTML=`
|
|
26
27
|
<rect x="0" y="0" width="${i}" height="${s}" rx="16" fill="#111827"/>
|
|
27
28
|
<text x="${i/2}" y="${s/2-10}" text-anchor="middle" dominant-baseline="middle" fill="#f9fafb" font-family="system-ui, sans-serif" font-size="18" font-weight="700">${a}</text>
|
|
28
29
|
<text x="${i/2}" y="${s/2+18}" text-anchor="middle" dominant-baseline="middle" fill="#cbd5e1" font-family="system-ui, sans-serif" font-size="13">${u}</text>
|
|
29
|
-
`;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(s*c));const _=t.getContext("2d");if(!_)return;_.save(),_.scale(c,c),_.clearRect(0,0,i,s),_.fillStyle="#111827",_.fillRect(0,0,i,s),_.textAlign="center",_.textBaseline="middle",_.fillStyle="#f9fafb",_.font="700 18px system-ui, sans-serif",_.fillText(a,i/2,s/2-10),_.fillStyle="#cbd5e1",_.font="13px system-ui, sans-serif",_.fillText(u,i/2,s/2+18),_.restore();return}t.textContent=`${a}. ${u}.`},hs=(t,e)=>{e.innerHTML=t},
|
|
30
|
+
`;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(s*c));const _=t.getContext("2d");if(!_)return;_.save(),_.scale(c,c),_.clearRect(0,0,i,s),_.fillStyle="#111827",_.fillRect(0,0,i,s),_.textAlign="center",_.textBaseline="middle",_.fillStyle="#f9fafb",_.font="700 18px system-ui, sans-serif",_.fillText(a,i/2,s/2-10),_.fillStyle="#cbd5e1",_.font="13px system-ui, sans-serif",_.fillText(u,i/2,s/2+18),_.restore();return}t.textContent=`${a}. ${u}.`},hs=(t,e)=>{e.innerHTML=t},tu=(t,e,n)=>{t.style.setProperty(e,n)},QE=(t,e)=>t.querySelector(`[data-mg="${e}"]`),eu=t=>e=>t===e,Rp=(t,e)=>({tag:t,_1:e}),Ap=t=>t,ME=(t,e,n)=>({tag:t,_1:e,_2:n}),Ro=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},zE=Ep(Vc),WE=zt.foldMap(rm),nu=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},e_=ME("AutoSize"),qE=Ap("CanvasRenderer"),OE=Ap("SvgRenderer"),HE=t=>e=>{const n=t-e*nt(fe(In(t/e)));return e<=0?0:n<0?n+e:n},Ti=t=>T(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),$E=t=>{const e=Gp("data-markgraf-titles")(t);return()=>{const n=e();return n.tag==="Nothing"||!(n.tag==="Just"&&n._1==="false")}},VE=t=>{const e=Gp("data-markgraf-theme")(t);return()=>{const n=e();if(n.tag==="Just")return n._1==="light"?kg:n._1==="dark"?u3:n._1==="blueprint"?c3:n._1==="whiteboard"?g3:n._1==="isometric"?_3:kg;if(n.tag==="Nothing")return kg;g()}},UE=`
|
|
30
31
|
<canvas data-mg="stage" tabindex="0"></canvas>
|
|
31
32
|
<div data-mg="play-overlay" aria-hidden="true"></div>
|
|
32
33
|
<div data-mg="bar">
|
|
@@ -43,6 +44,6 @@ var T4=(function(gu){"use strict";function qp(t){let e=0,n;return()=>{if(e===2)r
|
|
|
43
44
|
<option value="2">2\xD7</option>
|
|
44
45
|
</select>
|
|
45
46
|
</div>
|
|
46
|
-
`,
|
|
47
|
+
`,Ip=t=>e=>{const n=mn(t,J,Ut);if(n.tag==="Just"){const r=mn(n._1.stopAt,J,Ut);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return e;g()},Fp=t=>e=>({...e,state:{...e.state,camera:t},minis:O(n=>Fp(t)(n))(e.minis)}),XE=t=>e=>n=>{const r=Xr(n.rootLayout)(n.camera),o=gn("data-mg-too-small")("0")(t);return()=>(o(),gn("data-mg-camera-vw")(ao(r.w))(t)(),gn("data-mg-camera-vh")(ao(r.h))(t)(),gn("data-mg-camera-zoom")(ao(n.camera.zoom))(t)(),gn("data-mg-viewport-css-width")(ao(e.w))(t)(),gn("data-mg-viewport-css-height")(ao(e.h))(t)())},YE=t=>{const e=tE(t);if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right")return Wt("Right",rE(e._1));g()},KE=t=>e=>n=>{if(e.tag==="FixedSize")return()=>({w:e._1,h:e._2});if(e.tag==="AutoSize"){const r=Za(t);return()=>{const o=r(),i=o.width<=0?n.width:o.width;return{w:i,h:o.height<=0?i*n.height/Ro(1)(n.width):o.height}}}g()},jE=t=>e=>n=>{const r=Zb(s3(EE(n))),o=gn("viewBox")(r.viewBox)(t);return()=>(o(),gn("preserveAspectRatio")("xMidYMid meet")(t)(),e.tag==="FixedSize"?(gn("width")(ie(fe($n(e._1))))(t)(),gn("height")(ie(fe($n(e._2))))(t)()):e.tag==="AutoSize"||g(),hs(r.body,t))},ZE=t=>e=>n=>{const r=Pp(t),o=KE(t)(e)(n);return()=>{const i=o(),s=Dp(),a=i.w*s,u=i.h*s,c=C_(r)(),_=b_(r)(),d=k_(r)(a);c!==a&&d();const l=L_(r)(u);_!==u&&l(),e.tag==="FixedSize"?(tu(t,"width",ie(fe($n(i.w)))+"px"),tu(t,"height",ie(fe($n(i.h)))+"px")):e.tag==="AutoSize"||g();const f=v_(r)();rr(f)(),Ts(f)({scaleX:s,scaleY:s})();const h=Sd(f)({width:i.w,height:i.h})();return zE(n)(h)(),or(f)()}},t4=t=>e=>n=>r=>{if(e==="CanvasRenderer")return ZE(t)(n)(r);if(e==="SvgRenderer")return jE(t)(n)(r);g()},e4=t=>e=>n=>r=>()=>{let o=!1,i=()=>{},s=[];const a=()=>{const c=o,_=t4(t)(e)(n)(r);if(!c)return _()},u={time:0,keyframe:"sequence",playing:!1};return a(),i=Bp(t)(()=>{a();const c=s;return Ti(_=>_(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=>()=>{s=kt(s)(c),c(u)();const _=bi(d=>!eu(d)(c));return()=>{s=_(s)}},subscribeCue:c=>()=>()=>{},subscribeComplete:c=>()=>()=>{},destroy:()=>(o=!0,i())}},Jr=t=>e=>n=>()=>{const r=QE(t,e),o=mn(r,J,Ut);if(o.tag==="Just")return n(o._1)();o.tag!=="Nothing"&&g()},n4=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=WE(o=>'<span class="mg-tick" style="left:'+$o(Oo("Fixed",Ho(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 Jr(t)("ticks")(o=>()=>hs(r,o))},r4=t=>e=>n=>Jr(t)("scrub")(r=>{const o=jg(J,Ut,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return n<=0?()=>{}:RE(ie(fe($n(e/n*1e3))))(o._1);g()}),n_=t=>e=>n=>{const r=BE(o=>n);return()=>{const o=r();return DE(t)(o)(!1)(e)()}},Qp=()=>um()/1e3,o4=t=>e=>()=>(hs(`
|
|
47
48
|
<svg data-mg="stage" tabindex="0" role="img" aria-label="Markgraf sequence diagram"></svg>
|
|
48
|
-
`,t),pr(t)("stage")(n=>{const r=qE(n)(PE)(e_)(e);return()=>{const o=Zg();t_(()=>{r()})(o)()}})()),VE=t=>e=>{const n=pn(t,w,Yt);if(n.tag==="Just"){const r=pn(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()},r_=t=>e=>{const n=re(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()},XE=t=>e=>pr(t)("speed")(n=>{const r=jg(w,Yt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return n_("change")(n)((()=>{const o=bE(r._1);return()=>{const i=o(),s=A0(i,m_,Yt,w);if(s.tag==="Just")return e(s._1)();s.tag!=="Nothing"&&g()}})());g()}),YE=t=>e=>n=>pr(t)("scrub")(r=>{const o=jg(w,Yt,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return n_("input")(r)((()=>{const i=TE(o._1);return()=>{const s=i();return n.pause(),n.seek(s/1e3*e.totalDuration)()}})());g()}),UE=t=>e=>n=>{const r=OE(t)(e);return()=>{r(),pr(t)("play")(o=>gn("data-mg-playing")("1")(o))(),XE(t)(n.setSpeed)(),pr(t)("play")(o=>n_("click")(o)(n.toggle))(),YE(t)(e)(n)(),n.subscribe(o=>{const i=HE(t)(o.time)(e.totalDuration);return()=>(i(),pr(t)("time")(s=>wE(Oo(Wo("Fixed",qo(0)(20)(2)))(o.time)+" / "+Oo(Wo("Fixed",qo(0)(20)(2)))(e.totalDuration))(s))(),pr(t)("play")(s=>gn("data-mg-playing")(o.playing?"1":"0")(s))())})()}},KE=t=>e=>n=>{const r=td(n);return()=>{const o=r(),i=ed(n)(),s=t5(R2)(Wk)(n)(nd(o)(i)(n));if(s.tag==="Left")return Wt("Left","precompute failed");if(s.tag==="Right")return Wt("Right",{schedule:s._1});g()}},jE=t=>e=>(()=>{const n=pn(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:ki,duration:ki,loop:ki,stopAt:ki};g()})(),Dp=t=>e=>{const n=pn(t,w,Yt);if(n.tag==="Just"){const r=pn(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()},ZE=t=>e=>{const n=ft(o=>o.time<=e+1e-4,t),r=n.length-1|0;return r>=0&&r<n.length?n[r].index:-1},t4=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=tu(t);return()=>{const r=n();return r.width<=0||r.height<=0?w:N("Just",r.width/r.height)}}g()},ou=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>_=>()=>{const d=Bp(),l=c.value;c.value=d;const f=l===0?0:d-l,h=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const b=tu(t)();return{w:b.width<=0?200:b.width,h:b.height<=0?180:b.height}}g()})();if(h.w<200||h.h<180)return CE(t)(h.w)(h.h)(200)(180)();const p=yk({widthPx:h.w,heightPx:h.h})(s),m=jy(p)(ru(_)(p.totalDuration)),J=i?m:{...m,levels:$(b=>({...b,state:{...b.state,frameTitle:""}}))(m.levels)},x=u.value,y=(()=>{if(x.tag==="Nothing")return J.camera;if(x.tag==="Just")return G2(s.cameraConfig.cameraDecay)(f)(x._1)(J.camera);g()})();u.value=N("Just",y);const T={...J,camera:y,levels:$(Pp(y))(J.levels)};if(RE(t)(h)(T)(),e==="CanvasRenderer"){const b=Cp(t),L=pi({padding:8,outputAspect:w})(T),E=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const D=tu(t)();return{w:D.width,h:D.height<=0?L.vw<=0?D.width:D.width*L.vh/L.vw:D.height}}g()})(),B=Lp(),z=E.w*B,U=E.h*B,I=b_(b)(),A=C_(b)(),j=k_(b)(z);I!==z&&j();const Z=L_(b)(U);A!==U&&Z(),n.tag==="FixedSize"?(eu(t,"width",ie(de(On(E.w)))+"px"),eu(t,"height",ie(de(On(E.h)))+"px")):n.tag==="AutoSize"||g();const M=T_(b)();xr(M)(),Si(M)({scaleX:B,scaleY:B})();const W=a.value,O=Qb(r)(o)(M)({width:E.w,height:E.h})(T)(f)(W)();return a.value=O,wr(M)()}if(e==="SvgRenderer"){const b=a.value,L=t4(t)(n)(),E=wC(L)(r)(o)(T)(f)(b);return a.value=E.springs,gn("viewBox")(E.parts.viewBox)(t)(),gn("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(gn("width")(ie(de(On(n._1))))(t)(),gn("height")(ie(de(On(n._2))))(t)()):n.tag==="AutoSize"||g(),hs(E.parts.body,t)}g()},e4=t=>{const e=Hh(t)(Rh)._1;if(e.tag==="Left")return Wt("Left",e._1.msg);if(e.tag==="Right")return Wt("Right",e._1);g()},Ip=t=>{const e=bS(t);if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right"){if(e._1.mode==="SequenceSurface"){const r=FE(e._1);if(r.tag==="Left")return Wt("Left",r._1);if(r.tag==="Right")return Wt("Right",Sp("LoadedSequence",r._1));g()}const n=e4(e._1);if(n.tag==="Left")return Wt("Left",n._1);if(n.tag==="Right")return Wt("Right",Sp("LoadedAnimation",n._1))}g()},n4=t=>{const e=Ip(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return ki;g()},Ap=t=>e=>n=>r=>{const o=n+1e-4>=e?ft(s=>s.time>e+1e-4&&s.time<=n+1e-4,t):[...ft(s=>s.time>e+1e-4,t),...ft(s=>s.time<=n+1e-4,t)],i=n<=e+1e-4?se(ft(s=>s.time<e-1e-4&&s.time>=n-1e-4,t)):[...se(ft(s=>s.time<e-1e-4,t)),...se(ft(s=>s.time>=n-1e-4,t))];return(()=>{const s=n-e;return s<0?-s<=1e-4:s<=1e-4})()?[]:r>=0?o:i},r4=t=>e=>n=>r=>re(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),o4=t=>e=>n=>r=>{const o=ft(s=>Ne(a=>a===s.kind,e)&&(s.time<n-1e-4||(()=>{const a=s.time-n;return(a<0?-a<=1e-4:a<=1e-4)&&s.index<r})()),t),i=o.length-1|0;return i>=0&&i<o.length?N("Just",o[i]):w},o_=t=>e=>n=>{const r=pn(e,w,Yt);if(r.tag==="Just"){const o=pn(r._1.speed,w,Yt);if(o.tag==="Just"){const i=Bo(1e-4)(o._1<0?-o._1:o._1);return()=>t.value=i}if(o.tag==="Nothing"){const i=pn(r._1.duration,w,Yt);if(i.tag==="Just"&&n.tag==="Just"){const s=n._1/i._1,a=Bo(1e-4)(s<0?-s:s);if(i._1>0)return()=>t.value=a}return()=>{}}g()}if(r.tag==="Nothing")return()=>{};g()},i4=t=>e=>n=>r=>{const o=r.time-e,i=o<0?-o<=1e-4:o<=1e-4,s=r.time<e-1e-4||i&&r.index<n,a=s?-1:1,u=r.time>e+1e-4||i&&r.index>n,c=pn(t,w,Yt);if(c.tag==="Just"){const _=pn(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||s?N("Just",-1):w}return N("Just",a)}if(c.tag==="Nothing")return N("Just",a);g()},s4=t=>e=>n=>r=>o=>i=>s=>()=>{const a={value:1};let u=1,c=!0,_=w,d=-1,l=!0,f=!1,h=0,p=0;const m={value:R},J={value:w},x={value:0};let y=!1,T=()=>{},b=[],L=[],E=[];ou(t)(n)(r)(o)(i)(s)(e)(m)(J)(x)(0)();const B=S=>{const G=S.index;return()=>{d=G;const Q=L;return vi(V=>V(S))(Q)()}},z=S=>()=>{const G=b,Q=l,V={time:S,keyframe:r_(e)(S),playing:Q};return vi(Y=>Y(V))(G)()},U=()=>(l=!1,_=w,z(h)()),I=S=>()=>(h=S,ou(t)(n)(r)(o)(i)(s)(e)(m)(J)(x)(S)(),z(S)()),A=S=>{const G=Bo(0)(ru(e.totalDuration)(S));return()=>(h=G,d=ZE(e.cues)(G),p=0,_=w,J.value=w,ou(t)(n)(r)(o)(i)(s)(e)(m)(J)(x)(G)(),z(G)())},j=(S,G,Q,V,Y)=>()=>{l=!1,_=w;const X=h;z(X)();const q={reason:S,direction:G<0?"backward":"forward",targetId:Q,targetStep:V,reached:Y,time:X},K=E;return vi(et=>et(q))(K)()},Z=()=>{if(!y&&(f=!1,l)){const S=Bp(),G=p;p=S;const Q=a.value,V=u,Y=c,X=_,q=h,K=G===0?q+0*Q*V:q+(S-G)*Q*V;if(X.tag==="Just"){const et=V>=0?X._1.cue.time>=q-1e-4&&X._1.cue.time<=K+1e-4:X._1.cue.time<=q+1e-4&&X._1.cue.time>=K-1e-4,lt=et?X._1.cue.time:Bo(0)(ru(e.totalDuration)(K));(V>=0?lt+1e-4<q:lt>q+1e-4)&&(J.value=w),I(lt)(),vi(pt=>B(pt))(Ap(e.cues)(q)(lt)(V))();const Ct=j("target",V,X._1.targetId,X._1.targetStep,!0);return et&&Ct(),et?void 0:M()}if(X.tag==="Nothing"){const et=V>=0?e.totalDuration:0,lt=!Y&&(V>=0?et>=q-1e-4&&et<=K+1e-4:et<=q+1e-4&&et>=K-1e-4),Ct=Y?BE(K)(e.totalDuration+.8):Bo(0)(ru(e.totalDuration)(K));(V>=0?Ct+1e-4<q:Ct>q+1e-4)&&(J.value=w),I(Ct)(),vi(Tt=>B(Tt))(Ap(e.cues)(q)(Ct)(V))();const pt=j("boundary",V,"","",!0);return lt&&pt(),lt?void 0:M()}g()}},M=()=>{if(!y&&!f){f=!0;const S=Zg();t_(Z)(S)()}},W=()=>(p=0,l=!0,M()),O=()=>(u=1,c=!0,_=w,W(),z(h)()),D=(S,G)=>()=>{const Q=h;return u=S,c=!1,_=w,o_(a)(G)(N("Just",S>=0?e.totalDuration-Q:Q))(),W()},F=(S,G)=>()=>{const Q=h,V=d,Y=i4(G)(Q)(V)(S);if(Y.tag==="Nothing")return D(Dp(G)(1),G)();if(Y.tag==="Just"){const X=S.time-Q,q=X<0?-X:X;return u=Y._1,c=!1,_=N("Just",{cue:S,direction:Y._1,targetId:S.id,targetStep:S.name}),o_(a)(G)(N("Just",q))(),q<=1e-4?(A(S.time)(),B(S)(),j("target",Y._1,S.id,S.name,!0)()):W()}g()};return T=kp(t)(()=>{if(!y){const S=h;return ou(t)(n)(r)(o)(i)(s)(e)(m)(J)(x)(S)(),z(S)()}})(),W(),{play:O,playWith:S=>{const G=Dp(S)(1);return()=>(u=G,c=VE(S)(!1),_=w,o_(a)(S)(w)(),W(),z(h)())},pause:U,toggle:()=>l?U():O(),seek:S=>A(S),seekCue:S=>{const G=re(Q=>Q.id===S)(e.cues);if(G.tag==="Nothing")return()=>{};if(G.tag==="Just"){const Q=G._1,V=A(Q.time);return()=>(V(),B(Q)())}g()},seekStep:S=>{const G=re(Q=>Q.kind==="step"&&Q.name===S)(e.cues);if(G.tag==="Nothing")return()=>{};if(G.tag==="Just"){const Q=G._1,V=A(Q.time);return()=>(V(),B(Q)())}g()},playToCue:S=>G=>{const Q=re(V=>V.id===S)(e.cues);if(Q.tag==="Nothing")return()=>{};if(Q.tag==="Just")return F(Q._1,G);g()},playToStep:S=>G=>{const Q=re(V=>V.kind==="step"&&V.name===S)(e.cues);if(Q.tag==="Nothing")return()=>{};if(Q.tag==="Just")return F(Q._1,G);g()},playNext:S=>()=>{const G=h,Q=d,V=r4(e.cues)(Gp(S)(["step"]))(G)(Q);if(V.tag==="Nothing")return D(1,S)();if(V.tag==="Just")return F(V._1,S)();g()},playPrevious:S=>()=>{const G=h,Q=d,V=o4(e.cues)(Gp(S)(["step"]))(G)(Q);if(V.tag==="Nothing")return D(-1,S)();if(V.tag==="Just")return F(V._1,jE(S)(-1))();g()},setSpeed:S=>{const G=Bo(1e-4)(S<0?-S:S);return()=>a.value=G},currentTime:()=>h,currentKeyframe:()=>{const S=h;return r_(e)(S)},isPlaying:()=>l,duration:e.totalDuration,cues:e.cues,steps:ft(S=>S.kind==="step",e.cues),subscribe:S=>()=>{b=Pt(b)(S);const G=h,Q=l;S({time:G,keyframe:r_(e)(G),playing:Q})();const V=Ci(Y=>!nu(Y)(S));return()=>{b=V(b)}},subscribeCue:S=>()=>{L=Pt(L)(S);const G=Ci(Q=>!nu(Q)(S));return()=>{L=G(L)}},subscribeComplete:S=>()=>{E=Pt(E)(S);const G=Ci(Q=>!nu(Q)(S));return()=>{E=G(E)}},destroy:()=>(y=!0,T())}},a4=t=>e=>{const n=DE(t);return()=>{const r=n(),o=IE(t)();return hs(AE,t),pr(t)("stage")(i=>{const s=KE()(e_)(e);return()=>{const a=Zg();t_(()=>{const u=s();if(u.tag==="Left")return v_("[markgraf] precompute failed")();if(u.tag==="Right"){const c=s4(i)(u._1.schedule)(GE)(e_)(o)(aC)(r)();return UE(t)(u._1.schedule)(c)()}g()})(a)()}})()}},Rp=t=>e=>{const n=Ip(e);if(n.tag==="Left")return v_("[markgraf] parse failed: "+n._1);if(n.tag==="Right"){if(n._1.tag==="LoadedAnimation")return a4(t)(n._1._1);if(n._1.tag==="LoadedSequence")return $E(t)(n._1._1)}g()},u4=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 mr=null;const iu=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",c4=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{iu(t)?(mr&&mr!==t&&iu(mr)&&mr.querySelector('[data-mg="play"]').click(),mr=t):mr===t&&(mr=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},g4=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=u4(t),n=t.dataset.markgrafPaused==="true";t.textContent="",Rp(t)(e)(),t.querySelector('[data-mg="play"]')&&(n?iu(t)&&t.querySelector('[data-mg="play"]').click():mr===null?mr=t:iu(t)&&t.querySelector('[data-mg="play"]').click(),c4(t))},su=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(g4)},Fp=()=>{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||mr||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=n4(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>Rp(e)(n)(),mountAll:su,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{su(),Fp()}):(su(),Fp())}return gu.mountAll=su,Object.defineProperty(gu,Symbol.toStringTag,{value:"Module"}),gu})({});
|
|
49
|
+
`,t),Jr(t)("stage")(n=>{const r=e4(n)(OE)(e_)(e);return()=>{const o=Zg();t_(()=>{r()})(o)()}})()),i4=t=>e=>{const n=mn(t,J,Ut);if(n.tag==="Just"){const r=mn(n._1.loop,J,Ut);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return e;g()},r_=t=>e=>{const n=re(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()},s4=t=>e=>Jr(t)("speed")(n=>{const r=jg(J,Ut,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return n_("change")(n)((()=>{const o=IE(r._1);return()=>{const i=o(),s=W0(i,m_,Ut,J);if(s.tag==="Just")return e(s._1)();s.tag!=="Nothing"&&g()}})());g()}),a4=t=>e=>n=>Jr(t)("scrub")(r=>{const o=jg(J,Ut,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return n_("input")(r)((()=>{const i=AE(o._1);return()=>{const s=i();return n.pause(),n.seek(s/1e3*e.totalDuration)()}})());g()}),u4=t=>e=>n=>{const r=n4(t)(e);return()=>{r(),Jr(t)("play")(o=>gn("data-mg-playing")("1")(o))(),s4(t)(n.setSpeed)(),Jr(t)("play")(o=>n_("click")(o)(n.toggle))(),a4(t)(e)(n)(),n.subscribe(o=>{const i=r4(t)(o.time)(e.totalDuration);return()=>(i(),Jr(t)("time")(s=>PE($o(Oo("Fixed",Ho(0)(20)(2)))(o.time)+" / "+$o(Oo("Fixed",Ho(0)(20)(2)))(e.totalDuration))(s))(),Jr(t)("play")(s=>gn("data-mg-playing")(o.playing?"1":"0")(s))())})()}},c4=t=>e=>n=>{const r=td(n);return()=>{const o=r(),i=ed(n)(),s=f5(W2)(Yk)(n)(nd(o)(i)(n));if(s.tag==="Left")return Wt("Left","precompute failed");if(s.tag==="Right")return Wt("Right",{schedule:s._1});g()}},g4=t=>e=>(()=>{const n=mn(t,J,Ut);if(n.tag==="Just")return{...n._1,direction:e<0?"backward":"forward"};if(n.tag==="Nothing")return{direction:e<0?"backward":"forward",speed:ki,duration:ki,loop:ki,stopAt:ki};g()})(),Mp=t=>e=>{const n=mn(t,J,Ut);if(n.tag==="Just"){const r=mn(n._1.direction,J,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;g()},_4=t=>e=>{const n=ft(o=>o.time<=e+1e-4,t),r=n.length-1|0;return r>=0&&r<n.length?n[r].index:-1},f4=t=>e=>{if(e.tag==="FixedSize"){const n=e._1<=0||e._2<=0?J:N("Just",e._1/e._2);return()=>n}if(e.tag==="AutoSize"){const n=Za(t);return()=>{const r=n();return r.width<=0||r.height<=0?J:N("Just",r.width/r.height)}}g()},ru=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>_=>()=>{const d=Qp(),l=c.value;c.value=d;const f=l===0?0:d-l,h=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const C=Za(t)();return{w:C.width<=0?200:C.width,h:C.height<=0?180:C.height}}g()})();if(h.w<200||h.h<180)return FE(t)(h.w)(h.h)(200)(180)();const p=bk({widthPx:h.w,heightPx:h.h})(s),m=ex(p)(nu(_)(p.totalDuration)),w=i?m:{...m,levels:O(C=>({...C,state:{...C.state,frameTitle:""}}))(m.levels)},y=u.value,x=(()=>{if(y.tag==="Nothing")return w.camera;if(y.tag==="Just")return A2(s.cameraConfig.cameraDecay)(f)(y._1)(w.camera);g()})();u.value=N("Just",x);const v={...w,camera:x,levels:O(Fp(x))(w.levels)};if(XE(t)(h)(v)(),e==="CanvasRenderer"){const C=Pp(t),L=xi({padding:8,outputAspect:J})(v),E=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const D=Za(t)();return{w:D.width,h:D.height<=0?L.vw<=0?D.width:D.width*L.vh/L.vw:D.height}}g()})(),B=Dp(),z=E.w*B,Y=E.h*B,R=C_(C)(),A=b_(C)(),j=k_(C)(z);R!==z&&j();const Z=L_(C)(Y);A!==Y&&Z(),n.tag==="FixedSize"?(tu(t,"width",ie(fe($n(E.w)))+"px"),tu(t,"height",ie(fe($n(E.h)))+"px")):n.tag==="AutoSize"||g();const M=v_(C)();rr(M)(),Ts(M)({scaleX:B,scaleY:B})();const W=a.value,H=Ob(r)(o)(M)({width:E.w,height:E.h})(v)(f)(W)();return a.value=H,or(M)()}if(e==="SvgRenderer"){const C=a.value,L=f4(t)(n)(),E=C3(L)(r)(o)(v)(f)(C);return a.value=E.springs,gn("viewBox")(E.parts.viewBox)(t)(),gn("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(gn("width")(ie(fe($n(n._1))))(t)(),gn("height")(ie(fe($n(n._2))))(t)()):n.tag==="AutoSize"||g(),hs(E.parts.body,t)}g()},d4=t=>{const e=Kh(t)(qh)._1;if(e.tag==="Left")return Wt("Left",e._1.msg);if(e.tag==="Right")return Wt("Right",e._1);g()},zp=t=>{const e=IS(t);if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right"){if(e._1.mode==="SequenceSurface"){const r=YE(e._1);if(r.tag==="Left")return Wt("Left",r._1);if(r.tag==="Right")return Wt("Right",Rp("LoadedSequence",r._1));g()}const n=d4(e._1);if(n.tag==="Left")return Wt("Left",n._1);if(n.tag==="Right")return Wt("Right",Rp("LoadedAnimation",n._1))}g()},l4=t=>{const e=zp(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return ki;g()},Wp=t=>e=>n=>r=>{const o=n+1e-4>=e?ft(s=>s.time>e+1e-4&&s.time<=n+1e-4,t):[...ft(s=>s.time>e+1e-4,t),...ft(s=>s.time<=n+1e-4,t)],i=n<=e+1e-4?se(ft(s=>s.time<e-1e-4&&s.time>=n-1e-4,t)):[...se(ft(s=>s.time<e-1e-4,t)),...se(ft(s=>s.time>=n-1e-4,t))];return(()=>{const s=n-e;return s<0?-s<=1e-4:s<=1e-4})()?[]:r>=0?o:i},h4=t=>e=>n=>r=>re(o=>xe(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),p4=t=>e=>n=>r=>{const o=ft(s=>xe(a=>a===s.kind,e)&&(s.time<n-1e-4||(()=>{const a=s.time-n;return(a<0?-a<=1e-4:a<=1e-4)&&s.index<r})()),t),i=o.length-1|0;return i>=0&&i<o.length?N("Just",o[i]):J},o_=t=>e=>n=>{const r=mn(e,J,Ut);if(r.tag==="Just"){const o=mn(r._1.speed,J,Ut);if(o.tag==="Just"){const i=Ro(1e-4)(o._1<0?-o._1:o._1);return()=>t.value=i}if(o.tag==="Nothing"){const i=mn(r._1.duration,J,Ut);if(i.tag==="Just"&&n.tag==="Just"){const s=n._1/i._1,a=Ro(1e-4)(s<0?-s:s);if(i._1>0)return()=>t.value=a}return()=>{}}g()}if(r.tag==="Nothing")return()=>{};g()},m4=t=>e=>n=>r=>{const o=r.time-e,i=o<0?-o<=1e-4:o<=1e-4,s=r.time<e-1e-4||i&&r.index<n,a=s?-1:1,u=r.time>e+1e-4||i&&r.index>n,c=mn(t,J,Ut);if(c.tag==="Just"){const _=mn(c._1.direction,J,Ut);if(_.tag==="Just"){if(_._1==="forward")return i||u?N("Just",1):J;if(_._1==="backward"||_._1==="reverse")return i||s?N("Just",-1):J}return N("Just",a)}if(c.tag==="Nothing")return N("Just",a);g()},y4=t=>e=>n=>r=>o=>i=>s=>()=>{const a={value:1};let u=1,c=!0,_=J,d=-1,l=!0,f=!1,h=0,p=0;const m={value:I},w={value:J},y={value:0};let x=!1,v=()=>{},C=[],L=[],E=[];ru(t)(n)(r)(o)(i)(s)(e)(m)(w)(y)(0)();const B=S=>{const G=S.index;return()=>{d=G;const Q=L;return Ti(V=>V(S))(Q)()}},z=S=>()=>{const G=C,Q=l,V={time:S,keyframe:r_(e)(S),playing:Q};return Ti(X=>X(V))(G)()},Y=()=>(l=!1,_=J,z(h)()),R=S=>()=>(h=S,ru(t)(n)(r)(o)(i)(s)(e)(m)(w)(y)(S)(),z(S)()),A=S=>{const G=Ro(0)(nu(e.totalDuration)(S));return()=>(h=G,d=_4(e.cues)(G),p=0,_=J,w.value=J,ru(t)(n)(r)(o)(i)(s)(e)(m)(w)(y)(G)(),z(G)())},j=(S,G,Q,V,X)=>()=>{l=!1,_=J;const U=h;z(U)();const q={reason:S,direction:G<0?"backward":"forward",targetId:Q,targetStep:V,reached:X,time:U},K=E;return Ti(et=>et(q))(K)()},Z=()=>{if(!x&&(f=!1,l)){const S=Qp(),G=p;p=S;const Q=a.value,V=u,X=c,U=_,q=h,K=G===0?q+0*Q*V:q+(S-G)*Q*V;if(U.tag==="Just"){const et=V>=0?U._1.cue.time>=q-1e-4&&U._1.cue.time<=K+1e-4:U._1.cue.time<=q+1e-4&&U._1.cue.time>=K-1e-4,lt=et?U._1.cue.time:Ro(0)(nu(e.totalDuration)(K));(V>=0?lt+1e-4<q:lt>q+1e-4)&&(w.value=J),R(lt)(),Ti(pt=>B(pt))(Wp(e.cues)(q)(lt)(V))();const bt=j("target",V,U._1.targetId,U._1.targetStep,!0);return et&&bt(),et?void 0:M()}if(U.tag==="Nothing"){const et=V>=0?e.totalDuration:0,lt=!X&&(V>=0?et>=q-1e-4&&et<=K+1e-4:et<=q+1e-4&&et>=K-1e-4),bt=X?HE(K)(e.totalDuration+.8):Ro(0)(nu(e.totalDuration)(K));(V>=0?bt+1e-4<q:bt>q+1e-4)&&(w.value=J),R(bt)(),Ti(vt=>B(vt))(Wp(e.cues)(q)(bt)(V))();const pt=j("boundary",V,"","",!0);return lt&&pt(),lt?void 0:M()}g()}},M=()=>{if(!x&&!f){f=!0;const S=Zg();t_(Z)(S)()}},W=()=>(p=0,l=!0,M()),H=()=>(u=1,c=!0,_=J,W(),z(h)()),D=(S,G)=>()=>{const Q=h;return u=S,c=!1,_=J,o_(a)(G)(N("Just",S>=0?e.totalDuration-Q:Q))(),W()},F=(S,G)=>()=>{const Q=h,V=d,X=m4(G)(Q)(V)(S);if(X.tag==="Nothing")return D(Mp(G)(1),G)();if(X.tag==="Just"){const U=S.time-Q,q=U<0?-U:U;return u=X._1,c=!1,_=N("Just",{cue:S,direction:X._1,targetId:S.id,targetStep:S.name}),o_(a)(G)(N("Just",q))(),q<=1e-4?(A(S.time)(),B(S)(),j("target",X._1,S.id,S.name,!0)()):W()}g()};return v=Bp(t)(()=>{if(!x){const S=h;return ru(t)(n)(r)(o)(i)(s)(e)(m)(w)(y)(S)(),z(S)()}})(),W(),{play:H,playWith:S=>{const G=Mp(S)(1);return()=>(u=G,c=i4(S)(!1),_=J,o_(a)(S)(J)(),W(),z(h)())},pause:Y,toggle:()=>l?Y():H(),seek:S=>A(S),seekCue:S=>{const G=re(Q=>Q.id===S)(e.cues);if(G.tag==="Nothing")return()=>{};if(G.tag==="Just"){const Q=G._1,V=A(Q.time);return()=>(V(),B(Q)())}g()},seekStep:S=>{const G=re(Q=>Q.kind==="step"&&Q.name===S)(e.cues);if(G.tag==="Nothing")return()=>{};if(G.tag==="Just"){const Q=G._1,V=A(Q.time);return()=>(V(),B(Q)())}g()},playToCue:S=>G=>{const Q=re(V=>V.id===S)(e.cues);if(Q.tag==="Nothing")return()=>{};if(Q.tag==="Just")return F(Q._1,G);g()},playToStep:S=>G=>{const Q=re(V=>V.kind==="step"&&V.name===S)(e.cues);if(Q.tag==="Nothing")return()=>{};if(Q.tag==="Just")return F(Q._1,G);g()},playNext:S=>()=>{const G=h,Q=d,V=h4(e.cues)(Ip(S)(["step"]))(G)(Q);if(V.tag==="Nothing")return D(1,S)();if(V.tag==="Just")return F(V._1,S)();g()},playPrevious:S=>()=>{const G=h,Q=d,V=p4(e.cues)(Ip(S)(["step"]))(G)(Q);if(V.tag==="Nothing")return D(-1,S)();if(V.tag==="Just")return F(V._1,g4(S)(-1))();g()},setSpeed:S=>{const G=Ro(1e-4)(S<0?-S:S);return()=>a.value=G},currentTime:()=>h,currentKeyframe:()=>{const S=h;return r_(e)(S)},isPlaying:()=>l,duration:e.totalDuration,cues:e.cues,steps:ft(S=>S.kind==="step",e.cues),subscribe:S=>()=>{C=kt(C)(S);const G=h,Q=l;S({time:G,keyframe:r_(e)(G),playing:Q})();const V=bi(X=>!eu(X)(S));return()=>{C=V(C)}},subscribeCue:S=>()=>{L=kt(L)(S);const G=bi(Q=>!eu(Q)(S));return()=>{L=G(L)}},subscribeComplete:S=>()=>{E=kt(E)(S);const G=bi(Q=>!eu(Q)(S));return()=>{E=G(E)}},destroy:()=>(x=!0,v())}},x4=t=>e=>{const n=$E(t);return()=>{const r=n(),o=VE(t)();return hs(UE,t),Jr(t)("stage")(i=>{const s=c4()(e_)(e);return()=>{const a=Zg();t_(()=>{const u=s();if(u.tag==="Left")return T_("[markgraf] precompute failed")();if(u.tag==="Right"){const c=y4(i)(u._1.schedule)(qE)(e_)(o)(f3)(r)();return u4(t)(u._1.schedule)(c)()}g()})(a)()}})()}},qp=t=>e=>{const n=zp(e);if(n.tag==="Left")return T_("[markgraf] parse failed: "+n._1);if(n.tag==="Right"){if(n._1.tag==="LoadedAnimation")return x4(t)(n._1._1);if(n._1.tag==="LoadedSequence")return o4(t)(n._1._1)}g()},w4=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 Nr=null;const ou=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",J4=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{ou(t)?(Nr&&Nr!==t&&ou(Nr)&&Nr.querySelector('[data-mg="play"]').click(),Nr=t):Nr===t&&(Nr=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},N4=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=w4(t),n=t.dataset.markgrafPaused==="true";t.textContent="",qp(t)(e)(),t.querySelector('[data-mg="play"]')&&(n?ou(t)&&t.querySelector('[data-mg="play"]').click():Nr===null?Nr=t:ou(t)&&t.querySelector('[data-mg="play"]').click(),J4(t))},iu=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(N4)},Op=()=>{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||Nr||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=l4(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>qp(e)(n)(),mountAll:iu,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{iu(),Op()}):(iu(),Op())}return cu.mountAll=iu,Object.defineProperty(cu,Symbol.toStringTag,{value:"Module"}),cu})({});
|