@markgrafhq/markgraf-embed 0.1.20 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @markgrafhq/markgraf-embed might be problematic. Click here for more details.
- package/dist/markgraf-embed.js +259 -30
- package/package.json +1 -1
package/dist/markgraf-embed.js
CHANGED
|
@@ -1,32 +1,261 @@
|
|
|
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})+'"'},cu=t=>t,Be=cu("LT"),De=cu("GT"),Ye=cu("EQ"),N=(t,e)=>({tag:t,_1:e}),J=N("Nothing"),Kt=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}),Yp=t=>Wt("Right",t),Xp={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:()=>Xp},jp={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_},Zp={pure:Yp,Apply0:()=>u_},c_={Applicative0:()=>Zp,Bind1:()=>jp},t0=t=>t,e0={map:t=>e=>t(e)},g_={apply:t=>e=>t(e),Functor0:()=>e0},n0={bind:t=>e=>e(t),Apply0:()=>g_},r0={pure:t0,Apply0:()=>g_},kn={Applicative0:()=>r0,Bind1:()=>n0},o0=function(t){return function(){return t}},i0={apply:t=>e=>()=>{const n=t(),r=e();return gu.pure(n(r))()},Functor0:()=>s0},gu={pure:o0,Apply0:()=>i0},s0={map:t=>e=>()=>{const n=e();return t(n)}},Ro=(t,e)=>({tag:t,_1:e}),_u=t=>Ro("Loop",t),a0=t=>Ro("Done",t),u0={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},c0=function(t){return function(e){return function(){return t(e())}}},g0=function(t){return function(){return t}},_0=function(t){return function(e){return function(){return e(t())()}}},f0={map:c0},d0={Applicative0:()=>fu,Bind1:()=>l0},l0={bind:_0,Apply0:()=>__},__={apply:t=>e=>()=>{const n=t(),r=e();return fu.pure(n(r))()},Functor0:()=>f0},fu={pure:g0,Apply0:()=>__},h0={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:()=>d0},p0=function(t){return function(e){return function(n){return function(){return t(e,n)}}}},m0=function(t,e,n,r){return n>=0&&n<r.length?t(r[n]):e},du=function(t){return t.length},y0=function(t,e,n){return n.length>0?t(n.pop()):e},x0=p0(function(t,e){return e.push(t)}),w0=(t,e)=>({tag:"Iterator",_1:t,_2:e}),J0=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}},N0=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()}},Ao=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}}},Qr=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())},Io=t=>{const e=Qr(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:Ao,foldl:v,foldMap:t=>{const e=t.mempty;return n=>Mt.foldr(r=>o=>t.Semigroup0().append(n(r))(o))(e)}},b=(t,e)=>({tag:"Tuple",_1:t,_2:e}),Rn=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 lu=function(t){return function(e){return t===e}};const v0=lu,T0=lu,Ti=lu,hu=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},C0={eq:T0},zr={eq:v0};var pu=function(t){return function(e){return function(n){return function(r){return function(o){return r<o?t:r===o?e:n}}}}};const b0=pu,k0=pu,P={compare:pu(Be)(Ye)(De),Eq0:()=>Zn},ot={compare:k0(Be)(Ye)(De),Eq0:()=>C0},it={compare:b0(Be)(Ye)(De),Eq0:()=>zr},Ci=function(t){return t},S0=(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)}}}}}})(),L0=t=>t,oo={traverse:t=>{const e=t.Apply0();return S0(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>oo.traverse(t)(L0),Functor0:()=>$p,Foldable1:()=>Mt},Xt=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 E0=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},G0=function(t,e){for(var n=[],r=0,o=0;o<t;o++)n[r++]=e;return n};const P0=typeof Array.prototype.fill=="function"?E0:G0,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},io=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)},Mr=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)},B0=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},D0=(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)}})(),Rt=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},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},Pt=t=>e=>D0(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),R0=t=>e=>Pt(n=>r=>t.compare(e(n))(e(r))),St=t=>e=>(()=>{const n=x0(e);return()=>{const r=[...t];return n(r)(),r}})()(),Nr=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:Rt(0,t.length-1|0,t),last:t[e]}):J},A0=t=>e=>n=>t>=0&&t<n.length?Mr(Kt,J,t,e(n[t]),n):J,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=J}return s})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:Rt(0,n._1,e),rest:Rt(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};g()},Fo=t=>e=>{const n=Pt(r=>o=>t(r._2)(o._2))(Ht(Rn)(e));return 0<n.length?q(ps)(R0(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})())):[]},I0=t=>e=>{const n=[],r=w0(o=>o>=0&&o<e.length?N("Just",e[o]):J,{value:0});return N0(r)(o=>()=>{const i=[];i.push(o),J0(t(o))(r)(i)(),n.push(i)})(),n},re=t=>e=>{const n=io(Kt,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=io(Kt,J,o=>t.eq(o)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},ys=t=>e=>Et(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 F0(t,e,n,r){var o=parseFloat(t);return e(o)?n(o):r}const Oe=Math.abs,Q0=Math.acos,so=function(t){return function(e){return Math.atan2(t,e)}},xs=Math.ceil,Sn=Math.cos,Qo=Math.exp,An=Math.floor,ws=Math.log,z0=function(t){return function(e){return Math.min(t,e)}},mu=function(t){return function(e){return Math.pow(t,e)}},Hn=Math.round,pn=Math.sin,$e=Math.sqrt,M0=Math.tan,W0=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},nt=function(t){return t},O0=(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}}}})(Kt)(J)(10),y_=W0(Kt)(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()},kt=(t,e,n)=>({tag:t,_1:e,_2:n}),$=kt("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=kt("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)}},q0=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)}}}}}}},H0=t=>{if(t.tag==="Just")return t._1;g()},$0={unfoldr1:q0(s_)(H0)(ms)(ps)},V0=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)}}}}}}},U0=t=>{if(t.tag==="Just")return t._1;g()},nn={unfoldr:V0(s_)(U0)(ms)(ps),Unfoldable10:()=>$0},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"),In=rn("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()},Xe=(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()})()?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()},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,Xe(n._3,n._4,o._3,n._6))}if(r==="GT"){const o=zo(t,e,n._6);return Js(o._1,Xe(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,Xe(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 Xe(n._1,n._2,n._3,e)}g()},$n=(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 Mo($n(t,r._2,n._5),$n(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 Xe(r._3,e(o._1._1)(r._4),i,s);if(o._1.tag==="Nothing")return Mo(i,s)}g()},Qe=(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=Qe(t,e,o._2,r._5),s=Qe(t,e,o._3,r._6);if(o._1.tag==="Just")return Xe(r._3,e(o._1._1)(r._4),i,s);if(o._1.tag==="Nothing")return Xe(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 Xe(o._3,o._4,r(o._5),o._6);if(i==="GT")return Xe(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},K0=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 Xe(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},Fn=(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 Xe(i._3,i._4,o(i._5),i._6);if(s==="GT")return Xe(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 Xe(o._3,o._4,r(o._5),o._6);if(i==="GT")return Xe(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),Wo=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 Xe(r._3,r._4,n(r._5),r._6);if(o==="GT")return Xe(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=zo(e,r,o),s=n(i._1);if(s.tag==="Nothing")return Mo(i._2,i._3);if(s.tag==="Just")return Xe(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}},Wr=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},Y0=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)}},X0={append:Y0},j0={append:le},Z0={mempty:"",Semigroup0:()=>X0},tm={mempty:[],Semigroup0:()=>j0},ki=null;function mn(t,e,n){return t==null?e:n(t)}function N4(t){return t}function yu(t){return function(e){return function(n){return t.apply(n,[e])}}}const em=yu(Number.prototype.toPrecision),nm=yu(Number.prototype.toFixed),rm=yu(Number.prototype.toExponential),Oo=(t,e)=>({tag:t,_1:e}),qo=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()},Ho=t=>{if(t.tag==="Precision")return em(t._1);if(t.tag==="Fixed")return nm(t._1);if(t.tag==="Exponential")return rm(t._1);g()},v_=function(t){return function(){console.log(t)}};function om(){return Date.now()}function T_(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 S_(t){return function(e){return function(){t.height=e}}}function xu(t){return function(e){return function(){t.lineWidth=e}}}function im(t){return function(e){return function(){t.fillStyle=e}}}function sm(t){return function(e){return function(){t.strokeStyle=e}}}function wu(t){return function(e){return function(){t.lineCap=e}}}function Ju(t){return function(e){return function(){t.lineJoin=e}}}function am(t){return function(e){return function(){t.globalCompositeOperation=e}}}function um(t){return function(e){return function(){t.globalAlpha=e}}}function L_(t){return function(){t.beginPath()}}function Nu(t){return function(){t.stroke()}}function vu(t){return function(){t.fill()}}function cm(t){return function(){t.clip()}}function Si(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 gm(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function _m(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function vs(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 fm(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function dm(t){return function(e){return function(){t.textAlign=e}}}function lm(t){return function(e){return function(){t.textBaseline=e}}}function hm(t){return function(e){return function(){t.font=e}}}function pm(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function nr(t){return function(){t.save()}}function rr(t){return function(){t.restore()}}function Li(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function mm(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const B_=t=>t,Tu=t=>t,Cu=t=>t,bu=t=>t,Ts=t=>t,ym=Ts("BaselineTop"),xm=Ts("BaselineMiddle"),wm=Ts("BaselineAlphabetic"),Jm=Ts("BaselineBottom"),Nm=bu("AlignLeft"),vm=bu("AlignRight"),Tm=bu("AlignCenter"),ku=Cu("BevelJoin"),Su=Cu("RoundJoin"),Lu=Cu("MiterJoin"),Eu=Tu("Round"),Gu=Tu("Square"),Pu=Tu("Butt"),Cm=B_("SourceOver"),bm=B_("Difference"),km=t=>e=>lm(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()})()),Sm=t=>e=>dm(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()})()),Bu=t=>e=>{if(e==="BevelJoin")return Ju(t)("bevel");if(e==="RoundJoin")return Ju(t)("round");if(e==="MiterJoin")return Ju(t)("miter");g()},Du=t=>e=>{if(e==="Round")return wu(t)("round");if(e==="Square")return wu(t)("square");if(e==="Butt")return wu(t)("butt");g()},D_=t=>e=>am(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=Ao(o=>{const i=o._1,s=o._2;return a=>t(i)(s)(a)})(e),r=Ht(Rn);return o=>n(r(o))},foldlWithIndex:t=>e=>{const n=v(o=>i=>t(i._1)(o)(i._2))(e),r=Ht(Rn);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:()=>Mt},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,kt("Cons",i._3,o(i._6,s)));g()};return o(r,$)})())}},Lm=t=>{const e={append:(()=>{const n=t.compare;return r=>o=>Qe(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.")}},Or=function(t){return t.join("")},vr=function(t){return t.split("")},Gi=function(t){return t},or=function(t){return t.length},A_=function(t){return function(e){return e.substr(0,t)}},$o=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)}}},Em=t=>e=>{const n=I_(or(e)-or(t)|0)(e);return n.after===t?N("Just",n.before):J},ao=t=>e=>{const n=I_(or(t))(e);return n.before===t?N("Just",n.after):J},Gm=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},Pm=function(t){return t()},Bm=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},Dm=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},uo=t=>BigInt(t),Rm=t=>Number(t),Cs=t=>e=>t+e,bs=t=>e=>t*e,Ru=t=>e=>t-e,F_=0n,ks=1n,Q_=t=>e=>t^e,Pi=t=>e=>t&e,Au=t=>e=>t<<e,Iu=t=>e=>t>>e,Am=t=>e=>t==e,Im=t=>e=>t===e?0:t>e?1:-1,Fm={eq:Am},z_={compare:t=>e=>{const n=Im(t)(e);return n===1?De:n===0?Ye:Be},Eq0:()=>Fm},Qm=Bm(Kt)(J),zm=Dm(Kt)(J),M_=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}})(),Mm=t=>e=>Oe(t._1-e._1)+Oe(t._2-e._2),co=t=>t,Ss=t=>t,Se=Ss("North"),Le=Ss("South"),Tr=Ss("East"),Cr=Ss("West"),qr=co("Rectangle"),Wm=co("Cylinder"),Om=co("Parallelogram"),qm=co("Diamond"),Hm=co("Ellipse"),$m=co("Document"),Vm=co("Cloud"),O_=v(er)(0),Um=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()},Hr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ls=t=>e=>{const n=ot.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=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},Km=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}]},go=t=>e=>{const n=Fe(s=>a=>({a:s,b:a,len:(()=>{const u=a.y-s.y,c=a.x-s.x;return $e(c*c+u*u)})()}),t,Rt(1,t.length,t)),r=O_(q(s=>s.len)(n)),o=Um(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(x=>J,x=>y=>N("Just",{head:x,tail:y}),h);if(w.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(w.tag==="Just"){if(p<=w._1.head.len){const x=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)*x,y:w._1.head.a.y+(w._1.head.b.y-w._1.head.a.y)*x};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},Ym=t=>e=>{const n=Hr(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=>O_(Fe(e=>n=>{const r=n.y-e.y,o=n.x-e.x;return $e(o*o+r*r)},t,Rt(1,t.length,t))),Xm=t=>e=>{const n=Hr(4)(.15*Ls(e.w)(e.h)),r=Hr(1)(t.w),o=Hr(1)(t.h),i=Hr(1)(e.w-2*n),s=Hr(1)(e.h-2*n),a=Ls(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}},Fu={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,kt("Cons",r._4,n(r._6,o)));g()};return Et(Zt(de.foldr,n(t.nodes,$)))(Km)})(),...hn((()=>{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 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=v(r=>o=>({minX:Ls(r.minX)(o.x),minY:Ls(r.minY)(o.y),maxX:Hr(r.maxX)(o.x),maxY:Hr(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()},jm=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=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=Xm(he(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:qr};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)(Fu),Zm=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},t2=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()},e2=t=>e=>n=>r=>{const o=he(e);return n<=0||r<=0||o.w<=0||o.h<=0?1:t?Zm(o.w/n)(o.h/r):t2(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:e2(t)(e)(n.w)(n.h)}),n2=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)}},r2=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)}},K_=t=>t,o2=(t,e)=>({tag:t,_1:e}),Qu=t=>t,Vo=(t,e)=>({tag:t,_1:e}),zu=(t,e)=>({tag:t,_1:e}),Di=Qu("Animated"),i2=Qu("StaticStill"),s2=Qu("TitleCard"),a2=zu("First"),Y_=K_("Forward"),X_=K_("Backward"),u2=Vo("ExitNode"),j_=ce(P)(Mt),c2=t=>Ao(e=>n=>({nodes:Qe(P.compare,Ie,e.nodes,n.nodes),edges:Qe(P.compare,Ie,e.edges,n.edges)}))({nodes:I,edges:I})(t.keyframes),g2=t=>e=>({entering:{nodes:$n(P.compare,e.nodes,t.nodes),edges:$n(P.compare,e.edges,t.edges)},leaving:{nodes:$n(P.compare,t.nodes,e.nodes),edges:$n(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()},Uo=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},Mu=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},_2=v(t=>e=>rt(P)(e)()(t))(I),f2=v(t=>e=>rt(P)(e)()(t))(I),d2=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),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)(Mt),Wu=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=v(r=>o=>({minX:Gs(r.minX)(o.x),minY:Gs(r.minY)(o.y),maxX:Uo(r.maxX)(o.x),maxY:Uo(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()},l2=t=>e=>n=>_2(Et(Zt(fn.foldr,n))(r=>{const o=Ps(r)(t);if(o.tag==="Just")return ft(i=>!Mu(i)(e),[o._1.source,o._1.target]);if(o.tag==="Nothing")return[];g()})),h2=t=>t.kind.tag==="SendToken"?N("Just",b(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):J,p2=t=>t.tag==="DataFlow"?vt(h2)(t._1.events):[],m2=t=>e=>f2(vt(n=>Mu(n._2.source)(e)||Mu(n._2.target)(e)?N("Just",n._1):J)(d2(t))),ir=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=v(r=>o=>({minX:Gs(r.minX)(o.x),minY:Gs(r.minY)(o.y),maxX:Uo(r.maxX)(o.x+o.w),maxY:Uo(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=m2(e)(n),o=[...vt(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,Qe(P.compare,Ie,n,l2(e)(n)(r)))),...vt(i=>{const s=Ps(i)(t.edges);return s.tag==="Just"?N("Just",Wu(s._1)):J})(Zt(fn.foldr,r))];return o.length===0?he(t):ir(o)},Bs=t=>e=>n=>{const r=[...vt(o=>o)([(()=>{const o=Ps(n)(t.edges);return o.tag==="Just"?N("Just",Wu(o._1)):J})()]),...(()=>{const o=Ps(n)(e);if(o.tag==="Just")return vt(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):ir(r)},_o=t=>e=>{const n=he(t),r=n.w/Uo(1e-4)(e.zoom),o=n.h/Uo(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-o/2,w:r,h:o}},y2=t=>Qe(P.compare,Ie,tf(q(e=>b(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),tf(Et(t.scenes)(p2))),qu=t=>t,x2=t=>t,ef=qu("Linear"),$r=qu("EaseInOutQuad"),w2=qu("SpringBouncy"),Ri=t=>e=>n=>{const r=$e(1-e*e),o=t*r;return 1-Qo(-e*t*n)*(Sn(o*n)+e/r*pn(o*n))},J2=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()},Vr=t=>e=>(()=>{if(t==="Linear")return x2;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-mu(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*Qo(-6*n);if(t==="SpringBouncy")return Ri(6)(.7);g()})()(J2(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()},Hu=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},N2=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?Be:n==="GT"?De:ot.compare(t._2)(e._2)},v2=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},T2=rf("Hold"),C2=rf("Gap"),br=nf("LinearLerp"),of=nf("StagedLogLerp"),$u=Ds("Overview"),sf=Ds("DiveHome"),af=Ds("DiveTransition"),Rs=Ds("ActionFocus"),b2=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}},k2=t=>e=>n=>{const r=n.center.y-e.center.y,o=n.center.x-e.center.x,i=$e(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))},S2=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=>Vr($r)(Ai(0)(1)((e-t)/yn(1e-4)(1-t))),cf=t=>e=>Vr($r)(Ai(0)(1)(e/yn(1e-4)(t))),L2=v(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:St(t)(e)})([]),E2=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})()})()})()},G2=t=>e=>t.tag==="Just"?e.tag==="Just"&&E2(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:Qo((()=>{const o=ws(yn(1e-6)(t.zoom));return o+(ws(yn(1e-6)(e.zoom))-o)*r})())}),P2=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()})(J),B2=t=>e=>n=>r=>{if(t<=0)return r;const o=Qo(-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:Qo((()=>{const i=ws(yn(1e-6)(r.zoom));return i+(ws(yn(1e-6)(n.zoom))-i)*o})())}},D2=t=>e=>n=>e.zoom>=t.zoom?uf(.18000000000000005)(n):cf(.82)(n),R2=t=>e=>n=>e.zoom>=t.zoom?cf(.28)(n):uf(.72)(n),A2=t=>e=>n=>_f(t)(e)(R2(t)(e)(n))(D2(t)(e)(n)),I2=t=>e=>n=>{const r=n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT),o=Vr(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 A2(n.fromCam)(n.toCam)(r);g()},F2={widthPx:0,heightPx:0},Q2={padding:24,easing:$r,minimumReadableLabelPx:11,minimumVisibleLabelPx:5,labelBasePx:11,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:0},Ko=t=>e=>n=>r=>o=>{const i=b2(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},z2=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 Ko(t)(e)(n)(s.prev)(a.focus._1)?s.prev:Ko(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:Hu(_/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(Ko(t)(e)(n)(s.prev)(a.focus._1))return s.prev;if(Ko(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:br,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,_=io(Kt,J,d=>d.kind==="Hold",c<1?o:Rt(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 Ko(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:br,focus:J,intent:a.intent};g()})();return{acc:St(s.acc)(u),prev:u.toCam}})({acc:[],prev:r})(o).acc,M2=t=>e=>n=>r=>o=>{const i=(a,u)=>Hu(k2(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 Ko(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:St(a.acc)(a.pending._1),pending:N("Just",u)}:{acc:St(St(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:br,focus:u.focus,intent:u.intent}),pending:N("Just",u)};g()})({acc:[],pending:J})(o);if(s.pending.tag==="Nothing")return s.acc;if(s.pending.tag==="Just")return St(s.acc)(s.pending._1);g()},W2=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:Hu(i.w/r)(i.h/o)},O2=t=>e=>{if(t.tag==="Just"){if(e.tag==="Just")return N("Just",ir([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()},q2=v(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")&&G2(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})()})()})()?St((()=>{const o=t.length-1|0;return o<1?[]:Rt(0,o,t)})())({...r._1,endT:e.endT,focus:O2(r._1.focus)(e.focus)}):St(t)(e)})([]),H2=t=>{const e=Pt(n=>r=>N2(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},Vu=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:yn(r)(W2(e)(n)(t.padding))}),$2=t=>e=>n=>r=>o=>{const i=Vu(t)(n)(he(n))(0),s=ft(u=>u>=0&&u<=r,L2(Pt(ot.compare)([0,r,...Et(o)(u=>[u.startT,u.endT])]))),a=(u,c)=>Ne(_=>_.priority>=1,ft(_=>_.startT<=c&&c<_.endT,o))?n2(t)(e)(n)(ir(u)).camera:Vu(t)(n)(ir(u))(0);return q(S2)(M2(t)(e)(n)(i)(q2(z2(t)(e)(n)(i)(vt(u=>{const c=(u._1+u._2)/2;if(u._2<=u._1)return J;const _=q(d=>d.bbox)(ft(d=>d.priority===v(v2)(0)(q(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:C2,startT:u._1,endT:u._2,fromCam:i,toCam:i,easing:t.easing,focus:J,intent:$u}):N("Just",{kind:T2,startT:u._1,endT:u._2,fromCam:a(_,c),toCam:a(_,c),easing:t.easing,focus:N("Just",ir(_)),intent:Ne(d=>d.priority>=1,ft(d=>d.startT<=c&&c<d.endT,o))?Rs:$u})})(Fe(Rn,s,Rt(1,s.length,s)))))))},Ii=t=>e=>n=>r=>{const o=H2(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=P2(n);return i.tag==="Just"&&r>=i._1.endT?{camera:i._1.toCam,intent:i._1.intent}:{camera:(()=>{const s=Vu(t)(e)(he(e))(0);return 0<n.length?n[0].fromCam:s})(),intent:0<n.length?n[0].intent:$u}}g()};function Ur(t){return t.charCodeAt(0)}function ff(t){return String.fromCharCode(t)}const Qn=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},Kr=function(t){return function(e){return e.split(t)}},As=function(t){return t.trim()},sr=function(t){return function(e){return e.join(t)}};var V2=typeof Array.from=="function",U2=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",K2=typeof String.prototype.fromCodePoint=="function",Y2=typeof String.prototype.codePointAt=="function";const X2=function(t){return Y2?function(e){return e.codePointAt(0)}:t},j2=function(t){return K2?String.fromCodePoint:t},Z2=function(t){return function(e){return U2?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)}},ty=function(t){return function(e){return V2?function(n){return Array.from(n,e)}:t}},Is=t=>{const e=or(t);if(e===0)return J;if(e===1)return N("Just",{head:Ur(Ei(0)(t)),tail:""});const n=Ur(Ei(1)(t)),r=Ur(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:$o(2)(t)}):N("Just",{head:r,tail:$o(1)(t)})},ey=t=>{const e=Is(t);return e.tag==="Just"?N("Just",b(e._1.head,e._1.tail)):J},ny=t=>nn.unfoldr(ey)(t),df=X2(t=>{const e=Ur(Ei(0)(t));if(55296<=e&&e<=56319&&or(t)>1){const n=Ur(Ei(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),Yo=ty(ny)(df),ry=t=>Yo(t).length,Uu=t=>Gi(t>=0&&t<=65535?ff(t):t<0?"\0":"\uFFFF"),oy=j2(t=>t<=65535?Uu(t):Uu(Jr(t-65536|0,1024)+55296|0)+Uu(Wr(t-65536|0)(1024)+56320|0)),lf=t=>e=>{if(t<1)return"";const n=Is(e);return n.tag==="Just"?oy(n._1.head)+lf(t-1|0)(n._1.tail):e},Re=Z2(lf),iy=t=>e=>e===""?J:N("Just",df(e)),hf=t=>t,Fs=(t,e)=>({tag:t,_1:e}),zn=(t,e,n)=>({tag:t,_1:e,_2:n}),pf=t=>t,Xo=(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}),Ku=pf("PlopIn"),sy=pf("PlopOut"),ay=hf("DiveIn"),uy=hf("DiveOut"),jo=(t,e,n)=>({tag:t,_1:e,_2:n}),cy=t=>t,Zo=(t,e)=>({tag:t,_1:e}),Yu=t=>t,Qs=(t,e)=>({tag:t,_1:e}),Xu=Qs("NotYet"),mf=Qs("Consumed"),gy=Yu("FromSource"),yf=Yu("FromTarget"),_y=Yu("FromBoth"),ju=Zo("Hidden"),fy=Zo("Visible"),Zu=cy("ExtendFromSource"),tc=jo("Retracted"),xf=jo("Extended"),dy={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},ec=t=>t,wf=ce(P)(Mt),Fi={eq:hu(Ti)},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},kr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jf=Mt.foldMap(Lm(P)),ly=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},hy=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),ti=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},py=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},my=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},yy=ce(P)(Mt),xy=ce(P)(Mt),wy=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()},Nf=ec("Backdrop"),Jy=ec("FlyThrough"),dn=ec("Active"),Ny=t=>e=>n=>({...n,state:{...n.state,edgeFadeAlpha:wf(q(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*Qo(-(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()},vy=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()},Ty=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:Fu,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:I}),Cy=t=>q(e=>e<1?[]:Rt(0,e,t))(Xt(0,t.length-1|0)),rc=t=>e=>{const n=nc(e)(t.keyframes);if(n.tag==="Nothing")return I;if(n.tag==="Just")return n._1.nodes;g()},oc=t=>e=>{const n=nc(e)(t.keyframes);if(n.tag==="Nothing")return I;if(n.tag==="Just")return n._1.edges;g()},by=v(t=>e=>{const n=Nr(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?St(n._1.init)({...n._1.last,endT:kr(n._1.last.endT)(e.endT),windows:St(n._1.last.windows)(e)}):St(t)({endT:e.endT,windows:[e]})})([]),ky=t=>e=>n=>Jf(r=>Jf(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,by(Pt(r=>o=>ot.compare(r.startT)(o.startT))(ft(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),Sy=t=>e=>n=>Ne(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),Ly=t=>e=>n=>Ne(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),Ey=t=>e=>n=>Ne(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),Gy=t=>e=>n=>Ne(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),Ms=t=>e=>n=>re(r=>n(r)&&e>=r.startT&&e<r.endT)(t),Ws=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",v(vy)(t.initialKeyframe)(t.spans));g()},Py=t=>e=>{const n=Ws(t)(e),r=nc((()=>{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()},By=t=>e=>{const n=Ws(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()},Dy={segment:{startT:0,endT:0,path:[],layout:{nodes:I,edges:I,chipExtras:I,edgeLabels:I},placement:Fu,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]:Dy},Ry=t=>e=>{const n=ly(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):J)(hy(t.edges))}g()},Ay=t=>e=>{const n=Ws(t)(e);if(n.tag==="AtKeyframe")return rc(t)(n._1);if(n.tag==="InTransition")return Qe(P.compare,Ie,rc(t)(n._1),rc(t)(n._2));g()},Iy=t=>e=>{const n=Ws(t)(e);if(n.tag==="AtKeyframe")return oc(t)(n._1);if(n.tag==="InTransition")return Qe(P.compare,Ie,oc(t)(n._1),oc(t)(n._2));g()},Fy=t=>e=>n=>{const r=he(t),o=r.h/kr(1e-4)(n.zoom),i=r.w/kr(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)}}},Qy=t=>e=>n=>Fy(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}})()),zy=t=>e=>{const n=t.endT-t.startT;return n<=0?1:kr(0)(ti(1)((e-t.startT)/n))},ei=t=>e=>{const n=t.endT-t.startT;return n<=0?1:kr(0)(ti(1)((e-t.startT)/n))},My=t=>e=>n=>r=>o=>{const i=Ms(e)(n)(s=>s.target.tag==="EdgeWindow"&&s.target._2.tag==="Retract"&&s.target._1===o);if(i.tag==="Just"){const s=Vr(t.timing.edgeEasing)(ei(i._1)(n)),a=i._1.target.tag==="EdgeWindow"?i._1.target._2:Fs("Extend",Zu);if(a.tag==="Retract")return jo("Retracting",a._1,s);if(a.tag==="Extend")return jo("Extending",a._1,s);g()}if(i.tag==="Nothing"){if(Sy(e)(n)(o))return tc;const s=Ms(e)(n)(a=>a.target.tag==="EdgeWindow"&&a.target._1===o);if(s.tag==="Just"){const a=Vr(t.timing.edgeEasing)(ei(s._1)(n)),u=s._1.target.tag==="EdgeWindow"?s._1.target._2:Fs("Extend",Zu);if(u.tag==="Retract")return jo("Retracting",u._1,a);if(u.tag==="Extend")return jo("Extending",u._1,a);g()}if(s.tag==="Nothing")return Gy(e)(n)(o)?tc:py(o)(r)?xf:tc}g()},Wy=t=>e=>n=>{const r=Iy(e)(n);return wf(q(o=>b(o,My(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))})()))},Oy=t=>e=>n=>r=>{const o=Ms(t)(e)(i=>i.target.tag==="NodeWindow"&&i.target._1===r&&i.target._2==="PlopOut");if(o.tag==="Just"){const i=ei(o._1)(e),s=o._1.target.tag==="NodeWindow"?o._1.target._2:Ku;if(s==="PlopIn")return Zo("PloppingIn",i);if(s==="PlopOut")return Zo("PloppingOut",i);g()}if(o.tag==="Nothing"){if(Ly(t)(e)(r))return ju;const i=Ms(t)(e)(s=>s.target.tag==="NodeWindow"&&s.target._1===r);if(i.tag==="Just"){const s=ei(i._1)(e),a=i._1.target.tag==="NodeWindow"?i._1.target._2:Ku;if(a==="PlopIn")return Zo("PloppingIn",s);if(a==="PlopOut")return Zo("PloppingOut",s);g()}if(i.tag==="Nothing")return Ey(t)(e)(r)?ju:my(r)(n)?fy:ju}g()},qy=t=>e=>{const n=Ay(t)(e);return yy(q(r=>b(r,Oy(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))})()))},Hy=t=>e=>n=>e.target.tag==="TokenWindow"?b(e.target._1,n<e.startT?Xu:n>=e.endT?mf:Qs("Travelling",{edge:e.target._2,direction:e.target._3,progress:Vr(t.timing.tokenEasing)(ei(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?Xu:n>=e.endT?mf:Qs("Filling",{node:e.target._2,progress:ei(e)(n),labels:e.target._3})):b("",Xu),$y=t=>e=>n=>xy(q(r=>Hy(t)(r)(n))(ft(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),Vy=t=>e=>n=>({nodes:qy(e)(n),edges:Wy(t)(e)(n),tokens:$y(t)(e.windows)(n),camera:Ii(t.cameraConfig)(e.layout)(t.cameraSpans)(n).camera,frameTitle:By(e)(n),staticKind:Py(e)(n),visited:ky(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:I,nodeLabelFadeAlpha:I,edgeFadeAlpha:I,nodeInvert:I}),ni=t=>e=>n=>r=>({segment:n,state:Vy(t)(n)(e),bgAlpha:1,blur:0,minis:Uy(t)(e)(n),role:r}),Uy=t=>e=>n=>vt(r=>{const o=zs(t)(St(n.path)(r))(e);if(o.tag==="Just")return N("Just",{...ni(t)(wy(o._1.startT)(o._1.endT-1e-4)(e))(o._1)(Nf),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),Yy=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()},Tf=t=>e=>vt(n=>{const r=re(o=>o.direction==="DiveIn"&&Fi.eq(o.childPath)((()=>{const i=n.length+1|0;return i<1?[]:Rt(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=ni(t)(r._1.startT-1e-4)(o._1)(Nf);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()})(Cy(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]:Ty(t)},Xy=t=>e=>n=>{const r=zy(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 Vr($r)(r);if(n.direction==="DiveOut")return 1-Vr($r)(r);g()})(),a=1-kr(0)(ti(1)((s-.1)/.25)),u=1-kr(0)(ti(1)((s-.1)/.25)),c=1-kr(0)(ti(1)((s-.8)/.2)),_=l=>{const f=ni(t)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})())(l)(Jy);return{...Ny(Ry(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*kr(0)(ti(1)((s-.1)/.5));return[...Tf(t)(n.parentPath),...(()=>{if(o.tag==="Just"){if(i.tag==="Just")return[_(o._1),{...ni(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[ni(t)(e)(Cf(t)(e))(dn)];g()})()]},jy=t=>e=>re(n=>e>=n.startT&&e<n.endT)(t.dives),Zy=t=>e=>{const n=Cf(t)(e),r=ni(t)(e)(n)(dn),o=t.dives.length!==0,i=Ii(t.cameraConfig)(t.layout)(t.cameraSpans)(e).camera,s=Qy(t.layout)(t.cameraConfig.padding)(n)(i),a=Yy(t)(n)(e)({...r,state:{...r.state,camera:s}}),u=Tf(t)(n.path),c=jy(t)(e);if(c.tag==="Just")return{levels:Xy(t)(e)(c._1),camera:i,rootLayout:t.layout,hasDives:o,diving:!0};if(c.tag==="Nothing")return{levels:St(u)(a),camera:s,rootLayout:t.layout,hasDives:o,diving:!1};g()},tx=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ex=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,x=h;if(w>=e){p=!1,m=x;continue}if(u>=0&&u<t.length){if(w>=0&&w<t.length){f=w+1|0,h=(()=>{const y=t[u].position,T=t[u].size,C=t[w].position,S=t[w].size;return y._1<C._1+S._1&&C._1<y._1+T._1&&y._2<C._2+S._2&&C._2<y._2+T._2})()?x+1|0:x;continue}f=w+1|0,h=x;continue}p=!1,m=x}return m};o=u+1|0,i=_(u+1|0)(c)}return a})(0)(0)},bf=t=>v(e=>n=>e+Mm(n.start)(n.end))(0)(t.segments),nx=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+bf(o))(0)(e),maxEdgeLength:v(r=>o=>tx(r)(bf(o)))(0)(e),nodeOverlapCount:ex(t),constraintViolations:n,jumpCount:v(r=>o=>r+o.jumps.length|0)(0)(e)}),ic=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},sc=ic("LEFT"),rx=ic("RIGHT"),kf=ic("UNDEFINED"),ox={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},ix={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:()=>ox},sx=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},ax={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()},ux=t=>v(e=>n=>xn(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),cx=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=>Qt(it)(le)(s)([r])(i))(n)(o._1.constraints);g()})(I)(t.cNodeOrder);return v(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)},gx=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}})),_x=t=>{const e=v(n=>r=>Qi(r)(o=>({...o,outDegree:o.outDegreeReal}))(n))(t)(t.cGroupOrder);return v(n=>r=>xn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder)},Mn={left:!1,right:!1,up:!1,down:!1},fx={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},ac=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()})(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 v(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=>ac({...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)})()}),ar=t=>ac({...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=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=>en(zr)(a)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,a]})(s)):s;g()})(n)(o._1.constraints)}}g()})(e)(e.cNodeOrder)},qs=t=>{const e=cx(t.cGraph);return{...t,cGraph:Sf(v(n=>r=>xn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},dx=t=>e=>v(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),Wn=t=>{const e={...t,cGraph:dx(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()})())}},lx=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?Wn(r):e==="RIGHT"?Wn({...r,cGraph:wn(r.cGraph)}):e==="UP"?Wn({...r,cGraph:ar(r.cGraph)}):e==="DOWN"?Wn({...r,cGraph:wn(ar(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?qs({...r,cGraph:wn(r.cGraph)}):e==="UP"?Wn({...r,cGraph:ar(r.cGraph)}):e==="DOWN"?Wn({...r,cGraph:wn(ar(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?qs({...r,cGraph:wn(r.cGraph)}):e==="UP"?Wn({...r,cGraph:ar(wn(r.cGraph))}):e==="DOWN"?Wn({...r,cGraph:wn(ar(wn(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?Wn({...r,cGraph:ar(r.cGraph)}):e==="RIGHT"?Wn({...r,cGraph:wn(ar(r.cGraph))}):e==="DOWN"?qs({...r,cGraph:wn(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?Wn({...r,cGraph:ar(wn(r.cGraph))}):e==="RIGHT"?Wn({...r,cGraph:wn(ar(wn(r.cGraph)))}):e==="UP"?qs({...r,cGraph:wn(r.cGraph)}):r;g()},Lf=t=>e=>e.finished||!sx(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:lx(e.direction)(t)(e),hx=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?Lf(sc)(t):t,n={...e,cGraph:_x(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},Ef=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(zr)(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},Gf=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:rt(it)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:J,cGroupOffset:ax,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:Mn})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),uc=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:v(r=>o=>Ef(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)}},px=t=>v(e=>n=>{const r=ue(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?uc({master:J,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),mx=t=>({cGraph:ux(px(ac(t))),direction:kf,compactionAlgorithm:J,constraintAlgorithm:J,spacingsHandler:fx,lockFun:J,finished:!1}),yx=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},xx=t=>e=>{const n=ot.compare(t._1)(e._1);return n==="LT"?Be:n==="GT"?De:it.compare(t._2)(e._2)},wx=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),Pf=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},Bf=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",Df=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),Hs=t=>e=>xx(b(t.hitbox.x+t.hitbox.width/2,t.id))(b(e.hitbox.x+e.hitbox.width/2,e.id)),Jx=t=>e=>{const n=io(Kt,J,r=>Hs(t)(r)==="LT",e);if(n.tag==="Just"){const r=l_(Kt,J,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return St(e)(t);g()},Rf=t=>e=>{const n=ft(o=>Hs(o)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?N("Just",n[r]):J},Nx=t=>e=>{const n=Jx(e)(t.intervals),r=re(i=>Hs(e)(i)==="LT")(n),o=rt(it)(e.id)((()=>{const i=Rf(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()})()}},vx=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},Tx=t=>v(e=>n=>xn(n.id)(r=>({...r,constraints:[]}))(e))(t)(vt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),cc=t=>e=>v(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)(wx(t)),Af=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}},If=t=>e=>n=>v(r=>o=>n(o)?xn(o.id)(Af(t))(r):r)(e)(vt(r=>ue(r)(e.cNodes))(e.cNodeOrder)),Cx=t=>e=>{const n=(r,o,i)=>{const s=xn(i)(Af(t))(r);return o.length<=1?s:v(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 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=Rf(e)(t.intervals),r=re(i=>Hs(e)(i)==="LT")(t.intervals),o=n.tag==="Just"&&(()=>{const i=Pf(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=Pf(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)}},kx=t=>e=>e.low?Nx(t)(e.node):bx(t)(e.node),gc=t=>e=>v(kx)({intervals:[],cand:I,constraints:I})(Pt(vx)(Et(ft(t,vt(n=>ue(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,Sx=t=>e=>{const n=yx(0)(t/2-.5),r=cc(gc(Bf)(If(n)(e)(Bf)))(e),o=cc(gc(Df)(If(n)(r)(Df)))(r);return cc(gc(i=>!0)(Cx(n)(o)))(o)},Lx=t=>e=>Sx(t)(Tx(e.cGraph)),$s=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ff=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},_c=t=>e=>n=>r=>o=>({id:t,representedEdges:[o],affectedBends:[e,n],hitbox:{x:$s(e._1)(n._1),y:$s(e._2)(n._2),width:Oe(e._1-n._1),height:Oe(e._2-n._2)},ignoreSpacing:Mn,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:J}),Ex=t=>e=>{const n=$s(t.hitbox.x)(e.hitbox.x),r=$s(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:Ff(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Ff(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()})()}},Gx=t=>e=>Oe(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,Px=t=>e=>Oe(t.hitbox.x-e.hitbox.x)<=1e-4?ot.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?Be:De,Qf=(t,e)=>({tag:t,_1:e}),fc=ce(P)(Mt),Vs=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 v(n=>r=>rt(e)(r)()(n))(I)})(),Sr=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},Bx=v(t=>e=>rt(ix)(e)()(t))(I),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=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},Dx=t=>e=>{const n=fc(q(i=>b(i.id,i))(t)),r=vt(i=>Vs(i)(n))(e),o=it.compare((()=>{const i=zf(q(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(q(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{...Mn,left:!0,right:!1};if(o==="GT")return{...Mn,left:!1,right:!0};if(o==="EQ")return Mn;g()},Rx=t=>vt(e=>{if(e.direction==="V")return N("Just",{start:e.start,end:e.end});if(e.direction==="H")return J;g()})(t.segments),Us=t=>e=>n=>r=>{if(r.tag==="Just"){const o=Sr(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()},Ax=t=>e=>n=>{const r=Gf({origin:N("Just",Qf("SegmentOrigin",n)),kind:N("Just","vs"),hitbox:n.hitbox})(e.cGraph),o=gx(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 Ef(r.id)(i._1.cGroup._1)(o);if(i._1.cGroup.tag==="Nothing")return o;g()}if(i.tag==="Nothing")return o;g()}return uc({master:N("Just",r.id),nodes:[r.id]})(o).graph})(),edgeToCs:v(i=>s=>Qt(P)(le)(s)([r.id])(i))(e.edgeToCs)(n.representedEdges),lockMap:rt(it)(r.id)(Dx(t)(n.representedEdges))(e.lockMap)}},Ix=t=>e=>n=>{const r=Ft(o=>J,o=>i=>N("Just",{head:o,tail:i}),Pt(Px)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const o=v(i=>s=>Gx(i.survivor)(s)?{...i,survivor:Ex(i.survivor)(s)}:{survivor:s,merged:[...i.merged,i.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return v(Ax(t))(n)([...o.merged,o.survivor])}g()},Fx=t=>({cGraph:{cNodes:I,cNodeOrder:[],cGroups:I,cGroupOrder:[],supportedDirections:Bx([kf,sc,rx]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:I,edgeToCs:I,lockMap:I}),Qx=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}},zx=t=>e=>n=>v(r=>o=>{const i=Gf({origin:N("Just",Qf("NodeOrigin",o.node)),kind:J,hitbox:Qx(o)})(r.cGraph),s=Sr(o.node)(t),a=(()=>{if(s.tag==="Nothing")return b(0,0);if(s.tag==="Just")return s._1;g()})();return{...r,cGraph:uc({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?{...Mn,left:!0}:u>0?{...Mn,right:!0}:Mn})())(r.lockMap)}})(n)(e),Mx=t=>v(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),Wx=t=>v(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?rt(P)(n.origin._1._1)(n.hitbox.x)(e):e)(I)(vt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),Ox=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)(I)(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(W_)(i)(r)(o))(e)(n.origin._1._1.affectedBends)}return e})(I)(vt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),Mf=t=>{const e=fc(q(n=>b(n.id,n))(t.edges));return vt(n=>{const r=Vs(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(Tr)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:Us(Cr)(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(Tr)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:Us(Cr)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return J;g()})(t.paths)},Hx=t=>e=>{const n=Et(e)(r=>{if(r.src===r.tgt)return[];if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return[];const o=Sr(r.tgt)(t.nodeToC),i=(()=>{if(o.tag==="Just")return ue(o._1)(t.cGraph.cNodes);if(o.tag==="Nothing")return J;g()})(),s=Sr(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()},_=vt(f=>ue(f)(t.cGraph.cNodes))((()=>{const f=Vs(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=>en(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}},$x=t=>e=>{const n=nt(4),r=Wx(t),o=Ox(t),i=fc(q(a=>b(a.id,b(a.from.node,a.to.node)))(e.edges)),s=qx(t);return{nodes:q(a=>{const u=Sr(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:q(a=>{const u=Vs(a.edge)(i),c=(()=>{if(u.tag==="Nothing")return a.segments;if(u.tag==="Just"){const _=Sr(u._1._1)(o),d=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;g()})(),l=Sr(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=>x=>{if(x.direction==="V"){const y=(()=>{if(w===0)return h;if(w===(m-1|0))return p;const T=dc(x.start)(s);if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})();return{...x,start:b(x.start._1+y,x.start._2),end:b(x.end._1+y,x.end._2)}}if(x.direction==="H")return{...x,start:b((()=>{if(w===0)return x.start._1+h;const y=dc(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:b((()=>{if(w===(m-1|0))return x.end._1+p;const y=dc(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:Fe(_=>d=>_.end,c,Rt(1,c.length,c))}})(e.paths)}},Vx=t=>e=>n=>r=>o=>i=>{const s=_c(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})()]}},Wf=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{..._c(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?{...Mn,down:!0}:{...Mn,up:!0}}]}),Ks=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{..._c(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?{...Mn,down:!0}:{...Mn,up:!0}}]}),Ux=t=>e=>n=>{if(n.src===n.tgt)return e;const r=Sr(n.src)(t.nodeToC),o=Sr(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=Rx(n.path),u=v(Vx(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 Wf(n)(r._1)(i._1)(a[0])({side:Se,down:!0})(u);if(n.srcSide==="South")return Wf(n)(r._1)(i._1)(a[0])({side:Le,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:Se,down:!0})(_);if(n.tgtSide==="South")return Ks(n)(o._1)(s._1)(a[d])({side:Le,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:Se,down:!0})(u);if(n.tgtSide==="South")return Ks(n)(o._1)(s._1)(a[c])({side:Le,down:!1})(u)}return u},Kx=t=>e=>n=>Ix(t)(v(Ux(n))({nextId:0,segments:[]})(e).segments)(n),Yx=t=>Kx(t.edges)(Mf(t))(zx(Mx(t.edges))(t.nodes)(Fx())),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=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},lc=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},hc=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},Xx=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},jx=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,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!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"){w=!1,x=!0;continue}}g()}return x})(d.removedNodes)){u={...d,queue:l._1.tail};continue}const h=re(p=>!Lr(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=(x=>{let y=x,T=!0,C;for(;T;){const S=y;if(S.tag==="Leaf"){T=!1,C=J;continue}if(S.tag==="Node"){const E=t.compare(p)(S._3);if(E==="LT"){y=S._5;continue}if(E==="GT"){y=S._6;continue}if(E==="EQ"){T=!1,C=N("Just",S._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=(y=>{let T=y,C=!0,S;for(;C;){const E=T;if(E.tag==="Leaf"){C=!1,S=J;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"){C=!1,S=N("Just",E._4);continue}}g()}return S})(m.degree),x=y=>{let T=y,C=!0,S;for(;C;){const E=T;if(E.tag==="Leaf"){C=!1,S=!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"){C=!1,S=!0;continue}}g()}return S};return(()=>{if(w.tag==="Nothing")return!1;if(w.tag==="Just")return w._1===1;g()})()&&!x(m.removedNodes)})()){u={...m,queue:[...m.queue,p]};continue}u=m;continue}}g()}return _},i=v(a=>u=>Qt(t)(xe)(u.src)(1)(Qt(t)(xe)(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=>!Lr(a.eid)(s.removedEdges),r),removed:s.record}}},Zx=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=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)),pc=t=>{const e=t.Eq0();return n=>r=>o=>{const i={...o,treeNode:rt(t)(r)()(o.treeNode)};return v(s=>a=>{if(Lr(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 x=t.compare(_)(w._3);if(x==="LT"){h=w._5;continue}if(x==="GT"){h=w._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 w=h;if(w.tag==="Leaf"){p=!1,m=!1;continue}if(w.tag==="Node"){const x=t.compare(l)(w._3);if(x==="LT"){h=w._5;continue}if(x==="GT"){h=w._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 w=h;if(w.tag==="Leaf"){p=!1,m=!1;continue}if(w.tag==="Node"){const x=t.compare(_)(w._3);if(x==="LT"){h=w._5;continue}if(x==="GT"){h=w._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 w=h;if(w.tag==="Leaf"){p=!1,m=!1;continue}if(w.tag==="Node"){const x=t.compare(l)(w._3);if(x==="LT"){h=w._5;continue}if(x==="GT"){h=w._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(u.treeNode)})()?a.tgt:a.src)?a.tgt:a.src;if(Lr(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 _=pc(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,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!1,x=J;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"){w=!1,x=N("Just",y._4);continue}}g()}return x})(u.layer),f=a.src,h=(p=>{let m=p,w=!0,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!1,x=J;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"){w=!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 _=pc(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))&&!Lr(s.eid)(i.edgeVisited),n))}},Ys=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 x=p;if(x.tag==="Leaf"){m=!1,w=J;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,w=N("Just",x._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,x=!0,y;for(;x;){const T=w;if(T.tag==="Leaf"){x=!1,y=J;continue}if(T.tag==="Node"){const C=t.compare(h)(T._3);if(C==="LT"){w=T._5;continue}if(C==="GT"){w=T._6;continue}if(C==="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},tw=t=>{const e=ce(t)(Mt);return n=>({layer:e(q(r=>b(r,0))(n)),treeNode:I,treeEdge:I,poID:I,lowestPoID:I,cutvalue:I,postOrder:1,edgeVisited:I})},ew=t=>e=>n=>v(r=>o=>{if((()=>{const _=o.src,d=h=>{let p=h,m=!0,w;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,w=!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,w=!0;continue}}g()}return w},l=o.tgt,f=h=>{let p=h,m=!0,w;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,w=!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,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,nw=t=>{const e=ce(t)(Mt);return n=>r=>{const o=v(i=>s=>lc(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(q(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=v(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:lc(a.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:o})(ft(a=>Lr(a.eid)(o.treeEdge)&&(e.eq(a.src)(r)||e.eq(a.tgt)(r))&&!Lr(a.eid)(o.edgeVisited),n)),s=lc(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}}}},qf=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},rw=t=>{const e=t.Eq0();return n=>r=>o=>ft(i=>Lr(i.eid)(r.treeEdge)&&(e.eq(i.src)(o)||e.eq(i.tgt)(o)),n)},ow=t=>e=>re(n=>{const r=hc(n.eid)(e.cutvalue);return Lr(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),Hf=t=>{const e=pc(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=ew(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 x=p;if(x.tag==="Leaf"){m=!1,w=J;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,w=N("Just",x._4);continue}}g()}return w})(s.st.layer),_=a._1.src,d=(h=>{let p=h,m=!0,w;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,w=J;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,w=N("Just",x._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,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!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"){w=!1,x=!0;continue}}g()}return x})(s.st.treeNode)})()?-l:l;return Hf(t)(n)(r)({...s.st,layer:v(h=>p=>(m=>{let w=m,x=!0,y;for(;x;){const T=w;if(T.tag==="Leaf"){x=!1,y=!1;continue}if(T.tag==="Node"){const C=t.compare(p)(T._3);if(C==="LT"){w=T._5;continue}if(C==="GT"){w=T._6;continue}if(C==="EQ"){x=!1,y=!0;continue}}g()}return y})(s.st.treeNode)?rt(t)(p)((()=>{const m=(w=>{let x=w,y=!0,T;for(;y;){const C=x;if(C.tag==="Leaf"){y=!1,T=J;continue}if(C.tag==="Node"){const S=t.compare(p)(C._3);if(S==="LT"){x=C._5;continue}if(S==="GT"){x=C._6;continue}if(S==="EQ"){y=!1,T=N("Just",C._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()}},iw=t=>e=>n=>r=>v(o=>i=>{if(Ys(t)(r)(i.src)(n)&&!Ys(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,sw=t=>{const e=t.Eq0();return n=>r=>o=>i=>{const s=i.tgt,a=i.src;return v(u=>c=>{if((()=>{const _=hc(c.eid)(r.cutvalue);if(_.tag==="Just")return!0;if(_.tag==="Nothing")return!1;g()})()){const _=hc(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))}},aw=t=>{const e=sw(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,x=!0,y;for(;x;){const T=w;if(T.tag==="Leaf"){x=!1,y=J;continue}if(T.tag==="Node"){const C=t.compare(f)(T._3);if(C==="LT"){w=T._5;continue}if(C==="GT"){w=T._6;continue}if(C==="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(it)(p[0].eid)(e(n)(l)(f)(p[0]))(l.cutvalue)},c=m;continue}_=!1,d=l}return d})(r)(o)}},$f=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=v(c=>_=>rt(o)(_)()(c))(I),s=rw(t),a=ce(t)(Mt),u=aw(t);return c=>_=>d=>{const l={unknown:a(q(f=>b(f,Zt(fn.foldr,i(s(_)(d)(f)))))(c)),cutvalue:I};return{...d,cutvalue:v(u(_))(l)(ft(f=>{const h=(p=>{let m=p,w=!0,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!1,x=J;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"){w=!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}}},uw=t=>{const e=qf(t),n=$f(t);return r=>o=>i=>s=>a=>{const u={...a,treeEdge:rt(it)(s.eid)()(Wo(it)(i.eid)(a.treeEdge))},c=s.tgt,_=(p=>{let m=p,w=!0,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!1,x=J;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"){w=!1,x=N("Just",y._4);continue}}g()}return x})(u.layer),d=s.src,l=(p=>{let m=p,w=!0,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!1,x=J;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"){w=!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=Ys(t)(u)(s.tgt)(i)?f:-f;return n(r)(o)(e(r)(o)({...u,layer:v(p=>m=>Ys(t)(u)(m)(i)?p:rt(t)(m)((()=>{const w=(x=>{let y=x,T=!0,C;for(;T;){const S=y;if(S.tag==="Leaf"){T=!1,C=J;continue}if(S.tag==="Node"){const E=t.compare(m)(S._3);if(E==="LT"){y=S._5;continue}if(E==="GT"){y=S._6;continue}if(E==="EQ"){T=!1,C=N("Just",S._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)}))}},cw=t=>{const e=uw(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=ow(o)(f);if(h.tag==="Nothing"){_=!1,d=f;continue}if(h.tag==="Just"){const p=iw(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)},gw=t=>{const e=$f(t),n=qf(t),r=Hf(t);return o=>i=>s=>e(o)(i)(n(o)(i)(r(o)(i)(s)))},Vf=t=>e=>v(n=>r=>Qt(t)(le)(e(r))([r])(n))(I),_w=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,w;for(;m;){const x=l,y=f,T=h,C=p,S=Ft(E=>J,E=>B=>N("Just",{head:E,tail:B}),T);if(S.tag==="Nothing"){m=!1,w=C;continue}if(S.tag==="Just"){const E=S._1.head,B=(R=>{let A=R,j=!0,Z;for(;j;){const z=A;if(z.tag==="Leaf"){j=!1,Z=J;continue}if(z.tag==="Node"){const W=t.compare(E)(z._3);if(W==="LT"){A=z._5;continue}if(W==="GT"){A=z._6;continue}if(W==="EQ"){j=!1,Z=N("Just",z._4);continue}}g()}return Z})(C.layer),M=(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})(),Y=v(R=>A=>{const j=A.tgt,Z=(W=>{let H=W,D=!0,F;for(;D;){const L=H;if(L.tag==="Leaf"){D=!1,F=J;continue}if(L.tag==="Node"){const G=t.compare(j)(L._3);if(G==="LT"){H=L._5;continue}if(G==="GT"){H=L._6;continue}if(G==="EQ"){D=!1,F=N("Just",L._4);continue}}g()}return F})(R.incident),z=(()=>{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)(Xx((()=>{const W=A.tgt,H=(D=>{let F=D,L=!0,G;for(;L;){const Q=F;if(Q.tag==="Leaf"){L=!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"){L=!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()})())(M+A.delta|0))(R.st.layer)},incident:rt(t)(A.tgt)(z)(R.incident),queue:z===0?[...R.queue,A.tgt]:R.queue}})({st:C,incident:y,queue:S._1.tail})((()=>{const R=(A=>{let j=A,Z=!0,z;for(;Z;){const W=j;if(W.tag==="Leaf"){Z=!1,z=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,z=N("Just",W._4);continue}}g()}return z})(x);if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;g()})());l=x,f=Y.incident,h=Y.queue,p=Y.st;continue}g()}return w},s=Vf(t)(u=>u.tgt)(r),a=e(q(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(Vf(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)}},fw=t=>{const e=tw(t),n=_w(t),r=gw(t),o=cw(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}},Uf=t=>{const e=nw(t),n=fw(t),r=jx(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)(Zx(t)(s.removed)(n(s.coreNodes)(s.coreEdges)))}},Kf=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},mc=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},dw=Uf(it),zi=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}),lw=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=nt((()=>{const o=Kf(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()},hw=t=>e=>({...e,cGraph:v(lw(t))(e.cGraph)((()=>{const n=e.cGraph;return vt(r=>ue(r)(n.cNodes))(n.cNodeOrder)})())}),pw=t=>e=>n=>r=>o=>{const i=fe(xs(e.cGroupOffset.x-t.cGroupOffset.x));return zi({src:o.nextNodeId,tgt:r,delta:mc(0)(-i),weight:1})(zi({src:o.nextNodeId,tgt:n,delta:mc(0)(i),weight:1})({...o,nodes:[...o.nodes,o.nextNodeId],nextNodeId:o.nextNodeId+1|0}))},mw=t=>e=>n=>r=>o=>i=>s=>{const a=mc(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)?pw(n)(r)(o)(i)(s):zi({src:o,tgt:i,delta:a,weight:t.vsLNodePair(n)(r)?2:1})(s)},yw=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"?mw(t)(e)(n)(i._1)(n.cGroup._1)(i._1.cGroup._1)(r):r;g()},xw=t=>e=>n=>r=>v(yw(t)(e)(r))(n)(r.constraints),ww=t=>e=>zi({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),Jw=t=>{const e=v(o=>i=>Qt(it)(xe)(i.tgt)(1)(o))(I)(t.edges),n=ft(o=>{const i=Kf(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=>zi({src:r,tgt:i,delta:1,weight:0})(o))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},Nw=t=>e=>{const n=Jw(v(ww)(v(xw(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}},vw=t=>e=>{const n=Nw(t)(e);return hw(dw(n.nodes)(n.edges))(e)},Yf=t=>t,pe=Yf("H"),me=Yf("V"),Tw=t=>b(t._2,t._1),Xf=t=>({...t,position:b(t.position._2,t.position._1),size:b(t.size._2,t.size._1)}),Cw=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()})()}),jf=t=>({...t,segments:q(Cw)(t.segments),bends:q(Tw)(t.bends)}),bw=t=>({nodes:q(Xf)(t.nodes),edges:t.edges,paths:q(jf)(t.paths),ports:t.ports}),kw={nodeNode:8,edgeNode:4,edgeEdge:10},Sw=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=>vw(e),Ew=t=>e=>n=>{const r=bw(n),o=Yx(r),i=Hx(o)(Mf(r)),s=$x(Lf(sc)(hx({...mx(o.cGraph),compactionAlgorithm:N("Just",Lw()(i)),constraintAlgorithm:N("Just",Lx(e.edgeEdge)),spacingsHandler:Sw(e)(i)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:q(Xf)(s.nodes),edges:q(jf)(s.edges)}},Zf=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},t1=t=>Re(3)(t)==="$d:",Gw=t=>e=>n=>v(r=>o=>{const i=Zf(o.from.node)(t),s=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})(),a=Zf(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,_=q(l=>"$d:"+c+":"+ie(l))(Xt(1,u-1|0)),d=[o.from.node,..._,o.to.node];return{...r,layers:v(l=>f=>{const h=f._2,p=A0(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(Rn,Xt(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,Rt(1,d.length,d))],chains:[...r.chains,{edgeId:o.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),e1=t=>t,ri=ce(it)(Mt),Ut=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},n1=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()},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},Pw=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?Be:n==="GT"?De:it.compare(t._2)(e._2)},ii=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Bw=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),Dw=t=>t,r1=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},Rw=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},Xs=e1("Regular"),js=e1("Critical"),o1=t=>e=>{const n=v(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,x=f,y=h;if(y.critical){p=!1,m=y;continue}const T=Ft(S=>J,S=>E=>N("Just",{head:S,tail:E}),w),C=Ft(S=>J,S=>E=>N("Just",{head:S,tail:E}),x);if(T.tag==="Just"&&C.tag==="Just"){const S=T._1.head>C._1.head-s&&T._1.head<C._1.head+s?{...y,critical:!0}:T._1.head>C._1.head-r&&T._1.head<C._1.head+r?{...y,conflicts:y.conflicts+1|0}:y;if(S.critical){p=!1,m=S;continue}if(T._1.head<=C._1.head){l=T._1.tail,f=x,h=S;continue}l=w,f=C._1.tail,h=S;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:js}]:[],..._.critical?[{src:a.id,tgt:u.id,weight:1,kind:js}]:[]];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(w=>x=>x>h?w:x>=f?w+1|0:w)(0)(a.outgoing)+v(w=>x=>x>l?w:x>=d?w+1|0:w)(0)(u.incoming)|0)|0)|0,m=(1*_.conflicts|0)+(16*(v(w=>x=>x>l?w:x>=d?w+1|0:w)(0)(u.outgoing)+v(w=>x=>x>h?w:x>=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:Xs}]:p>m?[{src:u.id,tgt:a.id,weight:p-m|0,kind:Xs}]:p>0?[{src:a.id,tgt:u.id,weight:0,kind:Xs},{src:u.id,tgt:a.id,weight:0,kind:Xs}]:[]};return v(s=>a=>v(u=>c=>rt(P)(c._1)(c._2)(u))(s)((()=>{const u=v(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=r1(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:[...tr(z=>z<A.fromPos._1)(Z._1.incoming).init,A.fromPos._1,...tr(z=>z<=A.fromPos._1)(Z._1.incoming).rest],outgoing:[...tr(z=>z<A.toPos._1)(Z._1.outgoing).init,A.toPos._1,...tr(z=>z<=A.toPos._1)(Z._1.outgoing).rest]})(R.entries)};g()})({entries:I,order:[]})(a._2),c=Ht(R=>A=>({...A,id:R}))(vt(R=>r1(R)(u.entries))(u.order));if(c.length===0)return[];const _=v(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)([...Et(c)(R=>R.incoming),...Et(c)(R=>R.outgoing)])).out,d=_.length<2?.2*r:.2*v(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 Et(Et(Xt(0,R-2|0))(A=>Et(Xt(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=ri((()=>{const W=l.segments;return q(H=>b(H.id,H.mark))((()=>{const H=W.length,D=L=>{let G=L,Q=!0,V;for(;Q;){const K=G,U=re(O=>{const X=Ut(O)(K.inWeight);if(X.tag==="Nothing")return!0;if(X.tag==="Just")return X._1===0;g()})(K.remaining);if(U.tag==="Nothing"){Q=!1,V=K;continue}if(U.tag==="Just"){const O=U._1;G={...K,inWeight:v(X=>et=>Qt(it)(xe)(et.tgt)(-et.weight)(X))(K.inWeight)((()=>{const X=Ut(O)(K.depsBySrc);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()})()),marks:rt(it)(O)(K.nextSource)(K.marks),nextSource:K.nextSource+1|0,outWeight:v(X=>et=>Qt(it)(xe)(et.src)(-et.weight)(X))(K.outWeight)((()=>{const X=Ut(O)(K.depsByTgt);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()})()),remaining:ft(X=>X!==O,K.remaining)};continue}g()}return V},F=L=>{let G=L,Q=!0,V;for(;Q;){const K=G,U=re(O=>{const X=Ut(O)(K.outWeight);if(X.tag==="Nothing")return!0;if(X.tag==="Just")return X._1===0;g()})(K.remaining);if(U.tag==="Nothing"){Q=!1,V=K;continue}if(U.tag==="Just"){const O=U._1;G={...K,inWeight:v(X=>et=>Qt(it)(xe)(et.tgt)(-et.weight)(X))(K.inWeight)((()=>{const X=Ut(O)(K.depsBySrc);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()})()),marks:rt(it)(O)(K.nextSink)(K.marks),nextSink:K.nextSink-1|0,outWeight:v(X=>et=>Qt(it)(xe)(et.src)(-et.weight)(X))(K.outWeight)((()=>{const X=Ut(O)(K.depsByTgt);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()})()),remaining:ft(X=>X!==O,K.remaining)};continue}g()}return V};return(L=>{let G=L,Q=!0,V;for(;Q;){const K=D(F(G));if(K.remaining.length===0){Q=!1,V=q(U=>{const O=Ut(U.id)(K.marks),X=(()=>{if(O.tag==="Nothing")return U.id;if(O.tag==="Just")return O._1;g()})();return{...U,mark:X<H?(X+H|0)+1|0:X}})(W);continue}G=(()=>{const U=X=>{const et=Ut(X)(K.outWeight),lt=Ut(X)(K.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},O=Pt(X=>et=>it.compare(U(et))(U(X)))(K.remaining);if(0<O.length){const X=O[0];return{...K,inWeight:v(et=>lt=>Qt(it)(xe)(lt.tgt)(-lt.weight)(et))(K.inWeight)((()=>{const et=Ut(X)(K.depsBySrc);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;g()})()),marks:rt(it)(X)(K.nextSource)(K.marks),nextSource:K.nextSource+1|0,outWeight:v(et=>lt=>Qt(it)(xe)(lt.src)(-lt.weight)(et))(K.outWeight)((()=>{const et=Ut(X)(K.depsByTgt);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;g()})()),remaining:ft(et=>et!==X,K.remaining)}}return K})()}return V})({remaining:q(L=>L.id)(W),marks:I,inWeight:v(L=>G=>Qt(it)(xe)(G.tgt)(G.weight)(L))(I)(f),outWeight:v(L=>G=>Qt(it)(xe)(G.src)(G.weight)(L))(I)(f),depsBySrc:v(L=>G=>Qt(it)(le)(G.src)([G])(L))(I)(f),depsByTgt:v(L=>G=>Qt(it)(le)(G.tgt)([G])(L))(I)(f),nextSink:H-1|0,nextSource:H+1|0})})())})()),A=ft(W=>{const H=Ut(W.src)(R),D=Ut(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=v(W=>H=>{if(en(zr)(H.src)(W.decisions)||en(zr)(H.tgt)(W.decisions))return W;const D=Ut(H.src)(W.segMap),F=Ut(H.tgt)(W.segMap);if(D.tag==="Just"&&F.tag==="Just"){const L=(D._1.incoming.length+D._1.outgoing.length|0)>2&&(F._1.incoming.length+F._1.outgoing.length|0)<=2,G=L?F._1:D._1;return{decisions:[...W.decisions,G.id],segMap:rt(it)(G.id)({...G,splitBy:N("Just",L?D._1.id:F._1.id)})(W.segMap)}}return W})({decisions:[],segMap:ri(q(W=>b(W.id,W))(l.segments))})(A),Z=j.segMap,z=v(W=>H=>{const D=Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(H.outgoing)),F=Nt(v(Nt)(-1e18)(H.incoming))(v(Nt)(-1e18)(H.outgoing)),L=ft(U=>U.a.startPosition<=F&&U.a.endPosition>=D,Ht(U=>O=>({i:U,a:O}))(W.freeAreas));if(L.length===0){const U={...H,incoming:Pt(ot.compare)(H.incoming),outgoing:Pt(ot.compare)([(D+F)/2]),splitPartner:N("Just",W.nextId)},O={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)(O.id)(O)(rt(it)(U.id)(U)(W.segMap)),freeAreas:W.freeAreas,nextId:W.nextId+1|0}}const G=0<L.length?N("Just",L[0]):J,Q=(()=>{if(G.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(G.tag==="Just"){if(L.length===1)return G._1;const U=q(O=>({c:O,rating:(()=>{const X=(O.a.startPosition+O.a.endPosition)/2,et=[X],lt=[X],bt=v((()=>{const Tt=W.segMap;return Gt=>jt=>{const Ct=Ut(jt.tgt)(Tt);if(Ct.tag==="Nothing")return Gt;if(Ct.tag==="Just"){const Yt=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),Dt=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),wt=Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(et)),mt=(()=>{const qt=Nt(v(Nt)(-1e18)(H.incoming))(v(Nt)(-1e18)(et)),Ot=v(oe=>_e=>_e>Dt?oe:_e>=Yt?oe+1|0:oe)(0)(et)+v(oe=>_e=>_e>qt?oe:_e>=wt?oe+1|0:oe)(0)(Ct._1.incoming)|0,We=Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(et)),bn=Nt(v(Nt)(-1e18)(H.incoming))(v(Nt)(-1e18)(et)),tn=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),_n=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),Ae=v(oe=>_e=>_e>bn?oe:_e>=We?oe+1|0:oe)(0)(Ct._1.outgoing)+v(oe=>_e=>_e>_n?oe:_e>=tn?oe+1|0:oe)(0)(H.incoming)|0;return Ot===Ae?Ot>0?{...Gt,deps:Gt.deps+2|0,crossings:Gt.crossings+Ot|0}:Gt:{...Gt,deps:Gt.deps+1|0,crossings:Gt.crossings+ii(Ot)(Ae)|0}})(),ct=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),yt=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),dt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(H.outgoing)),ht=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(H.outgoing)),Lt=v(qt=>Ot=>Ot>yt?qt:Ot>=ct?qt+1|0:qt)(0)(H.outgoing)+v(qt=>Ot=>Ot>ht?qt:Ot>=dt?qt+1|0:qt)(0)(Ct._1.incoming)|0,Bt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(H.outgoing)),zt=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(H.outgoing)),ne=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),Cn=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),Me=v(qt=>Ot=>Ot>zt?qt:Ot>=Bt?qt+1|0:qt)(0)(Ct._1.outgoing)+v(qt=>Ot=>Ot>Cn?qt:Ot>=ne?qt+1|0:qt)(0)(lt)|0;return Lt===Me?Lt>0?{...mt,deps:mt.deps+2|0,crossings:mt.crossings+Lt|0}:mt:{...mt,deps:mt.deps+1|0,crossings:mt.crossings+ii(Lt)(Me)|0}}g()}})())(v((()=>{const Tt=W.segMap;return Gt=>jt=>{const Ct=Ut(jt.src)(Tt);if(Ct.tag==="Nothing")return Gt;if(Ct.tag==="Just"){const Yt=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),Dt=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),wt=Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(et)),mt=(()=>{const qt=Nt(v(Nt)(-1e18)(H.incoming))(v(Nt)(-1e18)(et)),Ot=v(oe=>_e=>_e>Dt?oe:_e>=Yt?oe+1|0:oe)(0)(et)+v(oe=>_e=>_e>qt?oe:_e>=wt?oe+1|0:oe)(0)(Ct._1.incoming)|0,We=Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(et)),bn=Nt(v(Nt)(-1e18)(H.incoming))(v(Nt)(-1e18)(et)),tn=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),_n=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),Ae=v(oe=>_e=>_e>bn?oe:_e>=We?oe+1|0:oe)(0)(Ct._1.outgoing)+v(oe=>_e=>_e>_n?oe:_e>=tn?oe+1|0:oe)(0)(H.incoming)|0;return Ot===Ae?Ot>0?{...Gt,deps:Gt.deps+2|0,crossings:Gt.crossings+Ot|0}:Gt:{...Gt,deps:Gt.deps+1|0,crossings:Gt.crossings+ii(Ot)(Ae)|0}})(),ct=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),yt=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),dt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(H.outgoing)),ht=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(H.outgoing)),Lt=v(qt=>Ot=>Ot>yt?qt:Ot>=ct?qt+1|0:qt)(0)(H.outgoing)+v(qt=>Ot=>Ot>ht?qt:Ot>=dt?qt+1|0:qt)(0)(Ct._1.incoming)|0,Bt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(H.outgoing)),zt=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(H.outgoing)),ne=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),Cn=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),Me=v(qt=>Ot=>Ot>zt?qt:Ot>=Bt?qt+1|0:qt)(0)(Ct._1.outgoing)+v(qt=>Ot=>Ot>Cn?qt:Ot>=ne?qt+1|0:qt)(0)(lt)|0;return Lt===Me?Lt>0?{...mt,deps:mt.deps+2|0,crossings:mt.crossings+Lt|0}:mt:{...mt,deps:mt.deps+1|0,crossings:mt.crossings+ii(Lt)(Me)|0}}g()}})())({crossings:0,deps:0})(ft(Tt=>Tt.tgt===H.id,l.deps)))(ft(Tt=>Tt.src===H.id,l.deps)),pt=(()=>{if(H.splitBy.tag==="Just")return Ut(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 Tt=Jt(v(Jt)(1e18)(pt._1.incoming))(v(Jt)(1e18)(pt._1.outgoing)),Gt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(H.outgoing)),jt=Nt(v(Nt)(-1e18)(pt._1.incoming))(v(Nt)(-1e18)(pt._1.outgoing)),Ct=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(H.outgoing)),Yt=Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(et));return bt.crossings+(()=>{const Dt=Jt(v(Jt)(1e18)(pt._1.incoming))(v(Jt)(1e18)(pt._1.outgoing)),wt=Nt(v(Nt)(-1e18)(H.incoming))(v(Nt)(-1e18)(et)),mt=Nt(v(Nt)(-1e18)(pt._1.incoming))(v(Nt)(-1e18)(pt._1.outgoing));return((v(ct=>yt=>yt>jt?ct:yt>=Tt?ct+1|0:ct)(0)(et)+v(ct=>yt=>yt>wt?ct:yt>=Yt?ct+1|0:ct)(0)(pt._1.incoming)|0)+v(ct=>yt=>yt>Ct?ct:yt>=Gt?ct+1|0:ct)(0)(pt._1.outgoing)|0)+v(ct=>yt=>yt>mt?ct:yt>=Dt?ct+1|0:ct)(0)(lt)|0})()|0})()};if(pt.tag==="Nothing")return bt;g()})()}))(L);return v(O=>X=>X.rating.crossings<O.rating.crossings||!(X.rating.crossings>O.rating.crossings)&&(X.rating.deps<O.rating.deps||!(X.rating.deps>O.rating.deps)&&X.c.a.size>O.c.a.size)?X:O)(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)},K={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)(K.id)(K)(rt(it)(V.id)(V)(W.segMap)),freeAreas:(()=>{if(Q.i>=0&&Q.i<W.freeAreas.length){const U=h_(Kt,J,Q.i,W.freeAreas),O=(()=>{if(U.tag==="Nothing")return W.freeAreas;if(U.tag==="Just")return U._1;g()})();if(W.freeAreas[Q.i].size/2<d)return O;const X=(W.freeAreas[Q.i].startPosition+W.freeAreas[Q.i].endPosition)/2,et=X-d,lt=X+d;return[...Q.i<1?[]:Rt(0,Q.i,O),...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?O:Rt(Q.i,O.length,O)]}return W.freeAreas})(),nextId:W.nextId+1|0}})({segMap:Z,freeAreas:(()=>{const W=Pt(ot.compare)([...Et(l.segments)(H=>H.incoming),...Et(l.segments)(H=>H.outgoing)]);return vt(Dw)(Fe(H=>D=>D-H>=2*d?N("Just",{startPosition:H+d,endPosition:D-d,size:D-H-2*d}):J,W,Rt(1,W.length,W)))})(),nextId:l.segments.length})(Pt(W=>H=>ot.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)(H.incoming))(v(Nt)(-1e18)(H.outgoing))-Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(H.outgoing))))(vt(W=>Ut(W)(Z))(j.decisions)));return{segments:(()=>{const W=(H,D)=>{if(H.tag==="Leaf")return D;if(H.tag==="Node")return W(H._5,kt("Cons",H._4,W(H._6,D)));g()};return Zt(de.foldr,W(z.segMap,$))})(),deps:(()=>{const W=z.segMap,H=(L,G)=>{if(L.tag==="Leaf")return G;if(L.tag==="Node")return H(L._5,kt("Cons",L._4,H(L._6,G)));g()},D=Zt(de.foldr,H(W,$)),F=D.length;return[...Et(Et(Xt(0,F-2|0))(L=>Et(Xt(L+1|0,F-1|0))(G=>[b(L,G)])))(L=>L._1>=0&&L._1<D.length?L._2>=0&&L._2<D.length?D[L._1].splitPartner.tag!=="Nothing"&&D[L._1].splitPartner.tag==="Just"&&D[L._1].splitPartner._1===D[L._2].id||D[L._2].splitPartner.tag!=="Nothing"&&D[L._2].splitPartner.tag==="Just"&&D[L._2].splitPartner._1===D[L._1].id?[]:i(d,D[L._1],D[L._2]):[]:[]),...Et(D)(L=>L.splitBy.tag==="Just"&&L.splitPartner.tag==="Just"&&(()=>{const G=Ut(L.splitPartner._1)(W);if(G.tag==="Nothing")return!1;if(G.tag==="Just")return!0;g()})()&&(()=>{const G=Ut(L.splitBy._1)(W);if(G.tag==="Nothing")return!1;if(G.tag==="Just")return!0;g()})()?[{src:L.id,tgt:L.splitBy._1,weight:1,kind:js},{src:L.splitBy._1,tgt:L.splitPartner._1,weight:1,kind:js}]:[])]})()}})(),p=h.segments,m=p.length,w=R=>{let A=R,j=!0,Z;for(;j;){const z=A,W=re(H=>{const D=Ut(H)(z.inWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;g()})(z.remaining);if(W.tag==="Nothing"){j=!1,Z=z;continue}if(W.tag==="Just"){const H=W._1;A={...z,inWeight:v(D=>F=>Qt(it)(xe)(F.tgt)(-F.weight)(D))(z.inWeight)((()=>{const D=Ut(H)(z.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),marks:rt(it)(H)(z.nextSource)(z.marks),nextSource:z.nextSource+1|0,outWeight:v(D=>F=>Qt(it)(xe)(F.src)(-F.weight)(D))(z.outWeight)((()=>{const D=Ut(H)(z.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),remaining:ft(D=>D!==H,z.remaining)};continue}g()}return Z},x=R=>{let A=R,j=!0,Z;for(;j;){const z=A,W=re(H=>{const D=Ut(H)(z.outWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;g()})(z.remaining);if(W.tag==="Nothing"){j=!1,Z=z;continue}if(W.tag==="Just"){const H=W._1;A={...z,inWeight:v(D=>F=>Qt(it)(xe)(F.tgt)(-F.weight)(D))(z.inWeight)((()=>{const D=Ut(H)(z.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),marks:rt(it)(H)(z.nextSink)(z.marks),nextSink:z.nextSink-1|0,outWeight:v(D=>F=>Qt(it)(xe)(F.src)(-F.weight)(D))(z.outWeight)((()=>{const D=Ut(H)(z.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),remaining:ft(D=>D!==H,z.remaining)};continue}g()}return Z},y=(R=>{let A=R,j=!0,Z;for(;j;){const z=w(x(A));if(z.remaining.length===0){j=!1,Z=q(W=>{const H=Ut(W.id)(z.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=Ut(D)(z.outWeight),L=Ut(D)(z.inWeight);return(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;g()})()-(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;g()})()|0},H=Pt(D=>F=>it.compare(W(F))(W(D)))(z.remaining);if(0<H.length){const D=H[0];return{...z,inWeight:v(F=>L=>Qt(it)(xe)(L.tgt)(-L.weight)(F))(z.inWeight)((()=>{const F=Ut(D)(z.depsBySrc);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})()),marks:rt(it)(D)(z.nextSource)(z.marks),nextSource:z.nextSource+1|0,outWeight:v(F=>L=>Qt(it)(xe)(L.src)(-L.weight)(F))(z.outWeight)((()=>{const F=Ut(D)(z.depsByTgt);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})()),remaining:ft(F=>F!==D,z.remaining)}}return z})()}return Z})({remaining:q(R=>R.id)(p),marks:I,inWeight:v(R=>A=>Qt(it)(xe)(A.tgt)(A.weight)(R))(I)(h.deps),outWeight:v(R=>A=>Qt(it)(xe)(A.src)(A.weight)(R))(I)(h.deps),depsBySrc:v(R=>A=>Qt(it)(le)(A.src)([A])(R))(I)(h.deps),depsByTgt:v(R=>A=>Qt(it)(le)(A.tgt)([A])(R))(I)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),T=(()=>{const R=(()=>{const Z=ri(q(z=>b(z.id,z.mark))(y));return{segments:y,deps:vt(z=>(()=>{if(z.kind==="Critical")return!0;if(z.kind==="Regular")return!1;g()})()?N("Just",z):(()=>{const W=Ut(z.src)(Z),H=Ut(z.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()})()})()?z.weight===0?J:N("Just",{src:z.tgt,tgt:z.src,weight:z.weight,kind:z.kind}):N("Just",z))(h.deps)}})(),A=v(Z=>z=>Qt(it)(xe)(z.tgt)(1)(Z))(I)(R.deps),j=(Z=>{let z=Z,W=!0,H;for(;W;){const D=z,F=Ft(L=>J,L=>G=>N("Just",{head:L,tail:G}),D.queue);if(F.tag==="Nothing"){W=!1,H=D;continue}if(F.tag==="Just"){z=v((()=>{const L=Ut(F._1.head)(D.slots),G=(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;g()})();return Q=>V=>{const K=Ut(V)(Q.inDegree),U=(()=>{if(K.tag==="Nothing")return-1;if(K.tag==="Just")return K._1-1|0;g()})();return{...Q,slots:rt(it)(V)(n1((()=>{const O=Ut(V)(Q.slots);if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._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 L=Ut(F._1.head)(D.adj);if(L.tag==="Nothing")return[];if(L.tag==="Just")return L._1;g()})());continue}g()}return H})({slots:ri(q(Z=>b(Z.id,0))(R.segments)),inDegree:A,adj:v(Z=>z=>Qt(it)(le)(z.src)([z.tgt])(Z))(I)(R.deps),queue:q(Z=>Z.id)(ft(Z=>{const z=Ut(Z.id)(A);if(z.tag==="Nothing")return!0;if(z.tag==="Just")return z._1===0;g()},R.segments))});return Pt(Z=>z=>it.compare(Z.slot)(z.slot))(q(Z=>({...Z,slot:(()=>{const z=Ut(Z.id)(j.slots);if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})()}))(R.segments))})(),C=1+v(R=>A=>n1(R)(A.slot))(0)(T)|0,S=Et(T)(R=>R.members),E=ft(R=>en(Zn)(R.edge.id)(S),t),B=v(Nt)(-1e18)(q(R=>R.fromPos._2)(E)),M=v(Jt)(1e18)(q(R=>R.toPos._2)(E));if(B>M){const R=ri(q(A=>b(A.id,A))(T));return hn(q(A=>q(j=>b(j,{slot:A.slot,slotCount:C,gapTop:M,gapBottom:B,partner:(()=>{if(A.splitPartner.tag==="Just"){const Z=Ut(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=Ut(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()},T)))}const Y=ri(q(R=>b(R.id,R))(T));return hn(q(R=>q(A=>b(A,{slot:R.slot,slotCount:C,gapTop:B,gapBottom:M,partner:(()=>{if(R.splitPartner.tag==="Just"){const j=Ut(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=Ut(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()},T)))})()))(I)(Bw(v(s=>a=>{const u=oi(a.edge.from.node)(n);if(u.tag==="Just"){const c=oi(a.edge.to.node)(n);return c.tag==="Just"&&u._1.layer!==c._1.layer?Qt(it)(le)(ii(u._1.layer)(c._1.layer))([a])(s):s}return s})(I)((()=>{const s=a=>b((()=>{const u=oi(a.edge.from.node)(n);return u.tag==="Just"?u._1.layer:1e6})(),(()=>{const u=oi(a.edge.from.node)(n);return u.tag==="Just"?u._1.order:1e6})());return Pt(a=>u=>Pw(s(a))(s(u)))(t)})())))},Aw=t=>e=>{const n=o1(t)(e),r=v(o=>i=>rt(P)(i.node)(i)(o))(I)(e);return v(o=>i=>{const s=oi(i.edge.from.node)(r);if(s.tag==="Just"){const a=oi(i.edge.to.node)(r);if(a.tag==="Just"&&s._1.layer!==a._1.layer){const u=Rw(i.edge.id)(n);if(u.tag==="Just")return rt(it)(ii(s._1.layer)(a._1.layer))(u._1.slotCount)(o)}return o}return o})(I)(t)},yc=ce(P)(Mt),Er=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},xc=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._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},i1=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()},wc=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()},s1=t=>e=>v(n=>r=>Qt(t)(le)(e(r))([r])(n))(I),a1=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},u1=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,o=e.length;return o===0?I:yc(o===1?q(i=>b(i,r))(e):Ht(i=>s=>b(s,t.lo+nt(i+1|0)*n/nt(o+1|0)))(e))},c1=t=>e=>n=>r=>o=>{const i=s1(P)(f=>f.to.node)(t),s=s1(P)(f=>f.from.node)(t),a=v(f=>h=>rt(P)(h.node)(h)(f))(I)(e),u=(f,h,p)=>{const m=Er(f)(a);if(m.tag==="Nothing")return b(0,0);if(m.tag==="Just"){const w=Er(f)(n);if(w.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(w.tag==="Just"){const x=re(y=>y.id===h)(w._1);if(x.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(x.tag==="Just"){const y=nt(4);if(x._1.side==="North")return b(m._1.position._1*y+nt(x._1.offset)*y,m._1.position._2*y);if(x._1.side==="South")return b(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 b((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 b(m._1.position._1*y,m._1.position._2*y+nt(x._1.offset)*y)}}}g()},c=yc(Et(r)(f=>{if(f.nodes.length<=2)return[];const h=nt(4);if(1<f.nodes.length){const p=Er(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 q(w=>b(w,m))(Fe(w=>x=>f.edgeId+":"+w+"->"+x,f.nodes,Rt(1,f.nodes.length,f.nodes)))}g()}return[]})),_=f=>{const h=Er(f.from.node)(a),p=Er(f.to.node)(a);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,w=p._1,x=Pt(y=>T=>it.compare(y.score)(T.score))(q(y=>{const T=y._1,C=y._2;return{from:T,to:C,score:(()=>{const S=(Y,R,A,j,Z)=>{const z=wc(Y)(R),W=wc(Y)(A);return z.lo<W.hi&&W.lo<z.hi&&(T==="South"?C==="North"&&Z._2>j._2:T==="North"?C==="South"&&Z._2<j._2:T==="East"?C==="West"&&Z._1>j._1:T==="West"&&C==="East"&&Z._1<j._1)?0:a1(T)(C)(j)(Z)},E=i1(T)(m),B=i1(C)(w),M=a1(T)(C)(E)(B);return(()=>{if(M>0){if(T==="South")return C==="North"?S(Le,m,w,E,B)*10|0:M*10|0;if(T==="North")return C==="South"?S(Se,m,w,E,B)*10|0:M*10|0;if(T==="East")return C==="West"?S(Tr,m,w,E,B)*10|0:M*10|0;if(T==="West"&&C==="East")return S(Cr,m,w,E,B)*10|0}return M*10|0})()+(T==="South"?C==="North"?w.layer>=m.layer?0:20:15:T==="North"?C==="South"?w.layer<=m.layer?0:20:15:T==="East"?C==="West"?5:15:T==="West"&&C==="East"?5:15)|0})()}})([b(Le,Se),b(Tr,Se),b(Cr,Se),b(Le,Tr),b(Le,Cr),b(Se,Le),b(Se,Tr),b(Se,Cr),b(Tr,Le),b(Cr,Le),b(Tr,Cr),b(Cr,Tr)]));if(0<x.length)return{from:x[0].from,to:x[0].to}}return{from:Le,to:Se}},d=yc(q(f=>b(f.id,_(f)))(t)),l=(f,h,p,m,w,x)=>{const y=nt(4),T=Er(h)(a);if(T.tag==="Nothing")return b(0,0);if(T.tag==="Just"){const C=Iw(b(p,f))(o);if(C.tag==="Just"){const S=T._1.position._1*y+C._1,E=nt(4);if(f==="South")return b(S,(T._1.position._2+T._1.size._2)*E);if(f==="North")return b(S,T._1.position._2*E);if(f==="East")return b((T._1.position._1+T._1.size._1)*E,S);if(f==="West")return b(T._1.position._1*E,S);g()}if(C.tag==="Nothing"){const S=wc(f)(T._1),E=(S.lo+S.hi)/2,B=xc(p)(u1(S)(q(R=>R.id)(Pt(R=>A=>ot.compare(w(f)(R))(w(f)(A)))(ft(R=>{const A=xc(R.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 R=Er(h)(m);if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;g()})()))))),M=(()=>{if(B.tag==="Nothing")return E;if(B.tag==="Just")return B._1;g()})(),Y=nt(4);if(f==="South")return b(M,(T._1.position._2+T._1.size._2)*Y);if(f==="North")return b(M,T._1.position._2*Y);if(f==="East")return b((T._1.position._1+T._1.size._1)*Y,M);if(f==="West")return b(T._1.position._1*Y,M)}}g()};return q(f=>{const h=xc(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()})(q(f=>{if(f.from.port.tag==="Just"&&f.to.port.tag==="Just")return{edge:f,fromPos:u(f.from.node,f.from.port._1,Le),toPos:u(f.to.node,f.to.port._1,Se),fromSide:Le,toSide:Se};const h=_(f);return{edge:f,fromPos:l(h.from,f.from.node,f.id,s,p=>m=>{const w=Er(m.to.node)(a);if(w.tag==="Nothing")return 0;if(w.tag==="Just"){const x=nt(4);if(p==="South"||p==="North")return w._1.position._1*x+w._1.size._1*x/2;if(p==="East"||p==="West")return w._1.position._2*x+w._1.size._2*x/2}g()},p=>p.from),toPos:l(h.to,f.to.node,f.id,i,p=>m=>{const w=Er(m.from.node)(a);if(w.tag==="Nothing")return 0;if(w.tag==="Just"){const x=nt(4);if(p==="South"||p==="North")return w._1.position._1*x+w._1.size._1*x/2;if(p==="East"||p==="West")return w._1.position._2*x+w._1.size._2*x/2}g()},p=>p.to),fromSide:h.from,toSide:h.to}})(t))},Zs=(()=>{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}})(),Fw=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=Zs.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(P)(Mt),Jc=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},zw=ce(Zs)(Mt),g1=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),si=t=>e=>n=>r=>{const o=Fw(b(e,n))(t);if(o.tag==="Nothing")return r;if(o.tag==="Just")return o._1;g()},_1=t=>e=>n=>{const r=Qw(hn(q(s=>Ht(a=>u=>b(u,a))(s))(t))),o=(s,a)=>{if(s==="South"){const u=Jc(a.to.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()}if(s==="North"){const u=Jc(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=>Qe(Zs.compare,Ie,zw(q(c=>b(b(c._1,s),c._2))(g1(u1({lo:0,hi:(()=>{const c=Jc(u._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return Re(3)(u._1)==="$d:"?0:1;g()})()})(q(c=>c.id)(Pt(c=>_=>it.compare(o(s,c))(o(s,_)))(u._2)))))),a))(I)(g1(v(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 Qe(Zs.compare,Ie,i(Se),i(Le))},f1=t=>t,d1=t=>t,l1=t=>t,Mw=v(t=>e=>rt(P)(e)()(t))(I),Ww=(()=>{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,kt("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},Ln=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ur=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},cr=ce(P)(Mt),Nc=N_(P),vc=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),Ow=t=>e=>{const n=it.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=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},h1=l1("VDown"),p1=l1("VUp"),Hw=d1("ForwardPhase"),$w=d1("StackPhase"),m1=f1("HRight"),y1=f1("HLeft"),x1=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},Vw=t=>e=>n=>{const r=v(s=>a=>Qt(P)(xe)(a.tgt)(1)(s))(I)(t),o=Ww(Mw([...q(s=>s.src)(t),...q(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 Zt(de.foldr,s(e,$))})()])),i=v(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(x=>J,x=>y=>N("Just",{head:x,tail:y}),h);if(w.tag==="Nothing"){l=!1,f=m;continue}if(w.tag==="Just"){const x=gt(w._1.head)(m),y=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})(),T=v(C=>S=>{const E=gt(S.target)(C.result),B=y+S.sep,M=gt(S.target)(C.indeg),Y=(()=>{if(M.tag==="Nothing")return-1;if(M.tag==="Just")return M._1-1|0;g()})();return{newQueue:Y===0?[...C.newQueue,S.target]:C.newQueue,result:rt(P)(S.target)((()=>{if(E.tag==="Nothing")return B;if(E.tag==="Just"){if(n==="VDown")return Ln(E._1)(B);if(n==="VUp")return ur(E._1)(B)}g()})())(C.result),indeg:rt(P)(S.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,...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))(I)(o))},Uw=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=Zt(de.foldr,e(t,$)),r=v(Ln)(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)},w1=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,$),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=ur(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=Ln(d)(l._1),u=l._2;continue}g()}return _};return r(-999999)(n)-o(999999)(n)},Mi=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,L)=>{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(K=>K.id===G._1)(Q._1);if(V.tag==="Just"){const K=nt(V._1.offset)*nt(4);return L==="North"||L==="South"?K:0}if(V.tag==="Nothing"){const K=gt(F)(r),U=si(s)(D.id)(L)((()=>{if(K.tag==="Nothing")return .5;if(K.tag==="Just")return K._1._1/2;g()})());return L==="North"||L==="South"?U:0}g()}if(Q.tag==="Nothing"){const V=gt(F)(r),K=si(s)(D.id)(L)((()=>{if(V.tag==="Nothing")return .5;if(V.tag==="Just")return V._1._1/2;g()})());return L==="North"||L==="South"?K:0}g()}if(G.tag==="Nothing"){const Q=gt(F)(r),V=si(s)(D.id)(L)((()=>{if(Q.tag==="Nothing")return .5;if(Q.tag==="Just")return Q._1._1/2;g()})());return L==="North"||L==="South"?V:0}g()},l=(D,F)=>{if(D.from.node===F){if(_==="HRight")return Le;if(_==="HLeft")return Se;g()}if(_==="HRight")return Se;if(_==="HLeft")return Le;g()},f=(D,F,L)=>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))(L)(Mi(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=cr(hn(Ht(D=>F=>q(L=>b(L,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),x=v(D=>F=>Nc(L=>N("Just",[...(()=>{if(L.tag==="Nothing")return[];if(L.tag==="Just")return L._1;g()})(),F]))(F.to.node)(D))(I)(i),y=v(D=>F=>Nc(L=>N("Just",[...(()=>{if(L.tag==="Nothing")return[];if(L.tag==="Just")return L._1;g()})(),F]))(F.from.node)(D))(I)(i),T=hn(n),C=v(D=>F=>{const L=gt(F)(u.root),G=(()=>{if(L.tag==="Nothing")return F;if(L.tag==="Just")return L._1;g()})();return F===G?D:Nc(Q=>N("Just",(()=>{if(Q.tag==="Nothing")return!0;if(Q.tag==="Just")return Q._1;g()})()&&Re(3)(F)==="$d:"))(G)(D)})(cr(q(D=>b(D,!0))(Fo(P.compare)((()=>{const D=(F,L)=>{if(F.tag==="Leaf")return L;if(F.tag==="Node")return D(F._5,kt("Cons",F._4,D(F._6,L)));g()};return Zt(de.foldr,D(u.root,$))})()))))(T),S=(D,F)=>{const L=D.free,G=gt(L)(u.root),Q=(()=>{if(G.tag==="Nothing")return L;if(G.tag==="Just")return G._1;g()})(),V=gt(Q)(C),K=(()=>{if(V.tag==="Nothing")return!0;if(V.tag==="Just")return V._1;g()})();return v(U=>O=>{if(U.edge.tag==="Just")return U;if(U.edge.tag==="Nothing"){if((()=>{const pt=gt(Q)(F.su);return!K&&(()=>{const Tt=gt(O.from.node)(m);return O.from.node!==O.to.node&&(()=>{const Gt=gt(O.to.node)(m);return(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._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 X=O.from.node===L?O.to.node:O.from.node,et=gt(X)(u.root),lt=(()=>{if(et.tag==="Nothing")return X;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",O),hasEdges:!0}:{...U,hasEdges:U.hasEdges||bt}}g()})({edge:J,hasEdges:!1})((()=>{if(D.isRoot){if(_==="HRight"){const U=gt(L)(x);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;g()}if(_==="HLeft"){const U=gt(L)(y);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1}g()}if(_==="HRight"){const U=gt(L)(y);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;g()}if(_==="HLeft"){const U=gt(L)(x);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1}g()})())},E=(D,F,L,G)=>{const Q=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),V={free:F,isRoot:L},K=S(V,G);if(K.edge.tag==="Nothing")return K.hasEdges?{thresh:Q,state:{...G,queue:[...G.queue,V]}}:{thresh:Q,state:G};if(K.edge.tag==="Just"){const U=K.edge._1.from.node===F?K.edge._1.to.node:K.edge._1.from.node;return{thresh:(()=>{const O=gt((()=>{const bt=gt(U)(u.root);if(bt.tag==="Nothing")return U;if(bt.tag==="Just")return bt._1;g()})())(G.x),X=gt(U)(a),et=gt(F)(a),lt=(()=>{if(O.tag==="Just")return O._1;if(O.tag==="Nothing")return J;g()})();return(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()+(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;g()})()+d(K.edge._1,U,(()=>{if(L){if(_==="HRight")return Le;if(_==="HLeft")return Se;g()}if(_==="HRight")return Se;if(_==="HLeft")return Le;g()})())-(()=>{if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1;g()})()-d(K.edge._1,F,(()=>{if(L){if(_==="HRight")return Se;if(_==="HLeft")return Le;g()}if(_==="HRight")return Le;if(_==="HLeft")return Se;g()})())})(),state:{...G,su:rt(P)((()=>{const O=gt(K.edge._1.from.node)(u.root);if(O.tag==="Nothing")return K.edge._1.from.node;if(O.tag==="Just")return O._1;g()})())(!0)(rt(P)((()=>{const O=gt(K.edge._1.to.node)(u.root);if(O.tag==="Nothing")return K.edge._1.to.node;if(O.tag==="Just")return O._1;g()})())(!0)(G.su))}}}g()},B=(D,F,L,G)=>{const Q=F===D,V=gt(F)(u.align),K=(()=>{if(V.tag==="Nothing")return F===D;if(V.tag==="Just")return V._1===D;g()})();if(!(Q||K))return{thresh:L,state:G};const U=(()=>{if(c==="VDown")return Q&&L<=-1e18;if(c==="VUp")return Q&&L>=1e18;g()})()?E(D,F,!0,G):{thresh:L,state:G};return(()=>{if(c==="VDown")return U.thresh<=-1e18&&K;if(c==="VUp")return U.thresh>=1e18&&K;g()})()?E(D,F,!1,U.state):U},M=D=>F=>L=>{const G=gt(L)(e.nodeIndex),Q=(()=>{if(G.tag==="Nothing")return 0;if(G.tag==="Just")return G._1;g()})(),V=re(et=>en(Zn)(L)(et))(h),K=(()=>{if(V.tag==="Nothing")return[];if(V.tag==="Just")return V._1;g()})(),U=K.length;if((()=>{if(c==="VDown")return Q<=0;if(c==="VUp")return Q>=(U-1|0);g()})()){const et=B(D,L,F.thresh,F.st);return{...F,st:et.state,thresh:et.thresh}}const O=(()=>{if(c==="VDown")return Q-1|0;if(c==="VUp")return Q+1|0;g()})(),X=O>=0&&O<K.length?N("Just",K[O]):J;if(X.tag==="Nothing")return F;if(X.tag==="Just"){const et=gt(X._1)(u.root),lt=(()=>{if(et.tag==="Nothing")return X._1;if(et.tag==="Just")return et._1;g()})(),bt=B(D,L,F.thresh,Y(lt)(F.st)),pt=(()=>{const zt=gt(D)(bt.state.sink);if(zt.tag==="Nothing")return D===D;if(zt.tag==="Just")return zt._1===D;g()})()?{...bt.state,sink:rt(P)(D)((()=>{const zt=gt(lt)(bt.state.sink);if(zt.tag==="Nothing")return lt;if(zt.tag==="Just")return zt._1;g()})())(bt.state.sink)}:bt.state,Tt=gt(lt)(pt.sink),Gt=(()=>{if(Tt.tag==="Nothing")return lt;if(Tt.tag==="Just")return Tt._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 zt=gt(lt)(pt.x),ne=(()=>{if(zt.tag==="Just")return zt._1;if(zt.tag==="Nothing")return J;g()})(),Cn=(()=>{if(ne.tag==="Nothing")return 0;if(ne.tag==="Just")return ne._1;g()})(),Me=gt(D)(pt.x),qt=(()=>{if(Me.tag==="Just")return Me._1;if(Me.tag==="Nothing")return J;g()})(),Ot=(()=>{if(qt.tag==="Nothing")return 0;if(qt.tag==="Just")return qt._1;g()})(),We=w(L,X._1),bn=gt(X._1)(a),tn=gt(L)(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=ur(Cn+_n+p(X._1)+We)(bt.thresh);return{st:{...pt,x:rt(P)(D)(N("Just",F.initial?Ae:ur(Ot)(Ae)))(pt.x)},initial:!1,thresh:bt.thresh}}if(c==="VUp"){const Ae=Ln(Cn+_n-We-p(L))(bt.thresh);return{st:{...pt,x:rt(P)(D)(N("Just",F.initial?Ae:Ln(Ot)(Ae)))(pt.x)},initial:!1,thresh:bt.thresh}}g()}const Yt=gt(lt)(pt.x),Dt=(()=>{if(Yt.tag==="Just")return Yt._1;if(Yt.tag==="Nothing")return J;g()})(),wt=(()=>{if(Dt.tag==="Nothing")return 0;if(Dt.tag==="Just")return Dt._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(L)(a),Lt=gt(X._1)(a),Bt=(()=>{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:Ct,tgt:Gt,sep:(()=>{if(c==="VDown")return yt+Bt-wt-p(X._1)-dt;if(c==="VUp")return yt+Bt+p(L)+dt-wt;g()})()}]},initial:F.initial,thresh:bt.thresh}}g()},Y=D=>F=>{const L=gt(D)(F.x),G=(()=>{if(L.tag==="Just")return L._1;if(L.tag==="Nothing")return J;g()})();if(G.tag==="Just")return F;if(G.tag==="Nothing"){const Q=v(M(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()})()})(Mi(u)(D));return{...Q.st,blockFinished:rt(P)(D)(!0)(Q.st.blockFinished)}}g()},R=v(D=>F=>v(L=>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)(L):L})(D)((()=>{if(c==="VDown")return F;if(c==="VUp")return se(F);g()})()))({x:cr(q(D=>b(D,J))(T)),sink:cr(q(D=>b(D,D))(T)),classEdges:[],su:I,blockFinished:I,queue:[]})(h),A=Vw(R.classEdges)(R.sink)(c),j=(D,F,L,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,L)},Z=cr(q(D=>b(D,!0))(Fo(P.compare)((()=>{const D=(F,L)=>{if(F.tag==="Leaf")return L;if(F.tag==="Node")return D(F._5,kt("Cons",F._4,D(F._6,L)));g()};return Zt(de.foldr,D(u.root,$))})()))),z=D=>F=>L=>{const G=S(L,{su:F.su,blockFinished:Z}),Q={phase:D,ppFree:L.free,ppIsRoot:L.isRoot,edgeId:J,delta:0,avail:0,shift:0,freeSu:(()=>{const V=gt((()=>{const K=gt(L.free)(u.root);if(K.tag==="Nothing")return L.free;if(K.tag==="Just")return K._1;g()})())(F.su);if(V.tag==="Nothing")return!1;if(V.tag==="Just")return V._1;g()})(),hasEdges:G.hasEdges,candCount:(()=>{if(L.isRoot){if(_==="HRight"){const V=gt(L.free)(x);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length;g()}if(_==="HLeft"){const V=gt(L.free)(y);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length}g()}if(_==="HRight"){const V=gt(L.free)(y);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length;g()}if(_==="HLeft"){const V=gt(L.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,L],trace:[...F.trace,Q],x:F.x};if(G.edge.tag==="Just"){const V=G.edge._1.from.node===L.free?b(G.edge._1.from.node,G.edge._1.to.node):b(G.edge._1.to.node,G.edge._1.from.node),K=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),O=(()=>{if(U.tag==="Nothing")return V._1;if(U.tag==="Just")return U._1;g()})(),X={...Q,edgeId:N("Just",G.edge._1.id),delta:K};if(K>0&&K<1e300){const et=v(pt=>Tt=>{const Gt=gt(Tt)(m),jt=(()=>{if(Gt.tag==="Nothing")return-1;if(Gt.tag==="Just")return Gt._1;g()})();if(jt>=0&&jt<n.length){const Dt=n[jt],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<Dt.length?Ln(pt)((()=>{const ct=gt(Tt)(F.x),yt=gt(Tt)(a),dt=gt(Dt[mt])(F.x),ht=gt(Dt[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(Dt[mt])+w(Tt,Dt[mt]))})()):pt}const Ct=gt(Tt)(e.nodeIndex),Yt=(()=>{if(Ct.tag==="Nothing")return-2;if(Ct.tag==="Just")return Ct._1-1|0;g()})();return Yt>=0&&Yt<0?Ln(pt)((()=>{const Dt=gt(Tt)(F.x),wt=gt(Tt)(a),mt=gt([][Yt])(F.x),ct=gt([][Yt])(a);return(()=>{if(Dt.tag==="Nothing")return 0;if(Dt.tag==="Just")return Dt._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(Tt,[][Yt]))})()):pt})(K)(Mi(u)(O)),lt=et>0?-et:0,bt={...F,x:et>0?f(O,lt,F.x):F.x,trace:[...F.trace,{...X,avail:et,shift:lt}]};return et>0?bt:{...bt,stack:[...bt.stack,L]}}if(K<0&&-K<1e300){const et=v(pt=>Tt=>{const Gt=gt(Tt)(m),jt=(()=>{if(Gt.tag==="Nothing")return-1;if(Gt.tag==="Just")return Gt._1;g()})();if(jt>=0&&jt<n.length){const Dt=n[jt],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<Dt.length?Ln(pt)((()=>{const ct=gt(Dt[mt])(F.x),yt=gt(Dt[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)+w(Tt,Dt[mt]))})()):pt}const Ct=gt(Tt)(e.nodeIndex),Yt=(()=>{if(Ct.tag==="Nothing")return 0;if(Ct.tag==="Just")return Ct._1+1|0;g()})();return Yt>=0&&Yt<0?Ln(pt)((()=>{const Dt=gt([][Yt])(F.x),wt=gt([][Yt])(a),mt=gt(Tt)(F.x),ct=gt(Tt)(a);return(()=>{if(Dt.tag==="Nothing")return 0;if(Dt.tag==="Just")return Dt._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)+w(Tt,[][Yt]))})()):pt})(-K)(Mi(u)(O)),lt=et>0?et:0,bt={...F,x:et>0?f(O,lt,F.x):F.x,trace:[...F.trace,{...X,avail:et,shift:lt}]};return et>0?bt:{...bt,stack:[...bt.stack,L]}}return{...F,stack:[...F.stack,L],trace:[...F.trace,X],x:F.x}}g()},W=v(z(Hw))({x:cr(q(D=>b(D,(()=>{const F=gt(D)(u.root),L=(()=>{if(F.tag==="Nothing")return D;if(F.tag==="Just")return F._1;g()})(),G=gt(L)(R.x),Q=gt((()=>{const K=gt(L)(R.sink);if(K.tag==="Nothing")return L;if(K.tag==="Just")return K._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()})()})()))(T)),su:R.su,stack:[],trace:[]})(R.queue),H=v(z($w))({...W,stack:[]})(se(W.stack));return{x:H.x,queue:R.queue,trace:H.trace}},Yw=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>_=>Kw(t)(e)(n)(r)(o)(i)(s)(a)(u)(c)(_).x,Xw=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=si(o)(u.id)(_)(l);return _==="North"||_==="South"?m:0}g()}if(h.tag==="Nothing"){const p=si(o)(u.id)(_)(l);return _==="North"||_==="South"?p:0}g()}if(f.tag==="Nothing"){const h=si(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 x=l,y=f,T=h,C=Ft(S=>J,S=>E=>N("Just",{head:S,tail:E}),p);if(C.tag==="Nothing"){m=!1,w=x;continue}if(C.tag==="Just"){const S=C._1.head,E=re(M=>M.from.node===T&&M.to.node===S||M.from.node===S&&M.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?Le:Se)-s(E._1,S,E._1.from.node===S?Le:Se));g()})();l=rt(P)(S)(B)(x),f=B,h=S,p=C._1.tail;continue}g()}return w};return v(u=>c=>{const _=Ft(f=>J,f=>h=>N("Just",{head:f,tail:h}),Mi(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=v(f=>h=>ur(f)(-h._2))(0)(vc(d));return v(f=>h=>rt(P)(h._1)(h._2+l)(f))(u)(vc(d))})(I)(Fo(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 Zt(de.foldr,u(t.root,$))})()))},jw=t=>e=>{const n=(o,i,s)=>Re(3)(i)==="$d:"&&p_(t1,(()=>{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 x=d,y=l,T=f,C=h,S=p,E=y.length;if(S>=E){m=!1,w=x;continue}const B=S>=0&&S<y.length?N("Just",y[S]):J,M=(()=>{if(B.tag==="Nothing")return"";if(B.tag==="Just")return B._1;g()})(),Y=n(t,M);if(S===(E-1|0)||Y){const R=(()=>{if(Y){const A=gt(M)(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,z=gt(j[0])(t.nodeIndex);if(z.tag==="Nothing")return Z;if(z.tag==="Just")return z._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(z=>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)()(z):z})(A)((()=>{const z=gt(Z)(t.preds);if(z.tag==="Nothing")return[];if(z.tag==="Just")return z._1;g()})())}return n(t,"")?A:v(Z=>z=>{const W=gt(z)(t.nodeIndex),H=(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})();return H<C||H>R?rt(P)(z+"\u2192")()(Z):Z})(A)((()=>{const Z=gt("")(t.preds);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;g()})())})(x)(Xt(0,S)),l=y,f=T,h=R,p=S+1|0;continue}d=x,l=y,f=T,h=C,p=S+1|0}return w};return e.length<3?I: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)})(I)(Xt(1,e.length-2|0))},Zw=t=>e=>n=>r=>o=>{const i=hn(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=Jr(f-1|0,2),p=Jr(f,2);return v(m=>w=>{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(w>=0&&w<l.length){const x=gt(l[w])(t.nodeIndex),y=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})();if(!(x1(l[w]+"\u2192"+d)(n)||x1(d+"\u2192"+l[w])(n))&&(()=>{if(r==="VDown")return m.r<y;if(r==="VUp")return m.r>y;g()})()){const T=gt(l[w])(m.root),C=(()=>{if(T.tag==="Nothing")return l[w];if(T.tag==="Just")return T._1;g()})();return{root:rt(P)(d)(C)(m.root),align:rt(P)(l[w])(d)(rt(P)(d)(C)(m.align)),r:y}}}return m})(_)((()=>{if(r==="VDown")return Xt(h,p);if(r==="VUp")return se(Xt(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:cr(q(a=>b(a,a))(i)),align:cr(q(a=>b(a,a))(i))})((()=>{if(o==="HRight")return e;if(o==="HLeft")return se(e);g()})());return{root:s.root,align:s.align}},ta=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>{const _=Zw(e)(n)(a)(u)(c),d=Xw(_)(o)(r)(i)(s)(c);return K0()(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))},J1=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=Xt(0,e.length-1|0);return n<1?[]:Rt(0,n,o)})()))(e),tJ=t=>e=>n=>r=>o=>i=>s=>{const a=Ow(0)(e.length-1|0),u=nt(t.layerGap),c=s(P0(a,u)),_=Aw(c1(o)(c)(r)(i)(I))(c);return q(d=>{const l=qw(d)(_);return l.tag==="Just"&&l._1>0?ur(u)(2+nt(l._1-1|0)*2.5):u})(Xt(0,a-1|0))},N1=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),eJ=t=>e=>n=>r=>{const o=Pt(i=>s=>ot.compare(i.w)(s.w))(q(i=>({l:i,w:w1(i)}))(ft(N1()(e)(n),r)));return 0<o.length?N("Just",o[0].l):J},nJ=t=>e=>{const n=cr(hn(q(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(v(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(v(i=>s=>Qt(P)(le)(s.from.node)([s.to.node])(i))(I)(e))})(),nodeIndex:n}},rJ=t=>e=>{const n=Pt(d=>l=>ot.compare(d.w)(l.w))(Ht(d=>l=>({i:d,l,w:w1(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,x=h;if(x.tag==="Nil"){p=!1,m=w;continue}if(x.tag==="Cons"){f=Ln(w)(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,$)})());if(i.tag==="Nothing")return 0;g()})(),a=d=>v(l=>f=>ur(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=>Wr(d)(2)===0?s-(f=>h=>{let p=f,m=h,w=!0,x;for(;w;){const y=p,T=m;if(T.tag==="Nil"){w=!1,x=y;continue}if(T.tag==="Cons"){p=Ln(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,$)})()):c-a(l))(e));return Uw(v(d=>l=>{const f=Pt(ot.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)})(I)(Fo(P.compare)(hn(q(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))})(_)))))},oJ=t=>e=>n=>r=>o=>i=>{const s=nJ(e)(o),a=jw(s)(e),u={nodeGap:t.nodeGap*4|0},c=Qe(P.compare,Ie,cr(q(f=>b(f,b(1,1)))(ft(t1,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)})()),_=[ta(u)(s)(e)(c)(r)(o)(i)(a)(h1)(m1),ta(u)(s)(e)(c)(r)(o)(i)(a)(p1)(m1),ta(u)(s)(e)(c)(r)(o)(i)(a)(h1)(y1),ta(u)(s)(e)(c)(r)(o)(i)(a)(p1)(y1)],d=rJ(c)(_);if(N1()(e)(c)(d))return d;const l=eJ()(e)(c)(_);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return _[0];g()},iJ=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 q(s=>s.node===n?{...s,position:b(i._1+r._1,i._2+r._2)}:s)(t)}g()},sJ=t=>e=>n=>r=>{const o=ft(s=>en(Zn)(s.node)(e),t),i=(()=>{if(n==="Vertical"){if(r==="Start")return v(s=>a=>Ln(s)(a.position._1))(99999)(o);if(r==="End")return v(s=>a=>ur(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=>Ln(s)(a.position._2))(99999)(o);if(r==="End")return v(s=>a=>ur(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 q(s=>{if(en(Zn)(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)},aJ=t=>e=>v(n=>r=>r.tag==="AlignGroup"?sJ(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?iJ(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),uJ=t=>e=>n=>r=>o=>i=>s=>a=>{const u=q(d=>v(l=>f=>ur(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=oJ(t)(n)(r)(o)(i)(a),_=J1(tJ(t)(n)(r)(o)(i)(s)(d=>{const l=J1(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),x=gt(m)(r);if(x.tag==="Nothing")return w;if(x.tag==="Just")return x._1;g()})(),layer:f,order:p}))(h))(n))}))(u);return aJ(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)))},Tc=Au(ks)(uo(32)),v1=Au(ks)(uo(31)),Wi=(()=>{const t=Qm("25214903917");if(t.tag==="Nothing")return F_;if(t.tag==="Just")return t._1;g()})(),Oi=Ru(Au(ks)(uo(48)))(ks),cJ=t=>{const e=zm(t);return Pi(Q_((()=>{if(e.tag==="Nothing")return F_;if(e.tag==="Just")return e._1;g()})())(Wi))(Oi)},Cc=uo(11),ea=t=>e=>{const n=Pi(Cs(bs(e)(Wi))(Cc))(Oi);return b((()=>{const r=y_(Rm(Iu(n)(uo(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},gJ=t=>{const e=ea(26)(t),n=ea(27)(e._2);return b((nt(e._1)*mu(2)(27)+nt(n._1))/mu(2)(53),n._2)},_J=t=>e=>{const n=v(r=>o=>{const i=gJ(r.finalR);return{rs:[...r.rs,i._1],finalR:i._2}})({rs:[],finalR:t})(e);return b(q(r=>r.x)(Pt(r=>o=>ot.compare(r.k)(o.k))(Fe(r=>o=>({x:r,k:o}),e,n.rs))),n.finalR)},fJ=t=>{const e=Pi(Cs(bs(t)(Wi))(Cc))(Oi),n=Pi(Cs(bs(e)(Wi))(Cc))(Oi);return b(Cs(bs((()=>{const r=Iu(e)(uo(16));return z_.compare(r)(v1)!=="LT"?Ru(r)(Tc):r})())(Tc))((()=>{const r=Iu(n)(uo(16));return z_.compare(r)(v1)!=="LT"?Ru(r)(Tc):r})()),n)},qi=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},na=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=ce(P)(Mt),ai=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=ce(P)(Mt),dJ=hu(Ti),lJ=v(er)(0),hJ=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},T1=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},pJ=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const o=Mr(Kt,J,t,n[e],n);if(o.tag==="Just")return Mr(Kt,J,e,r,o._1);if(o.tag==="Nothing")return J;g()}}return J},mJ=t=>e=>n=>r=>o=>bc(v(i=>s=>{const a=Pt(u=>c=>it.compare((()=>{const _=qi(u.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;g()})())((()=>{const _=qi(c.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;g()})()))(ft(u=>na(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),yJ=t=>e=>n=>r=>o=>bc(v(i=>s=>{const a=Pt(c=>_=>{const d=it.compare((()=>{const l=ai(_.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=ai(c.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})());return d==="EQ"?it.compare((()=>{const l=qi(c.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})())((()=>{const l=qi(_.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})()):d})(ft(c=>na(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),kc=t=>e=>n=>{const r=ra(Ht(a=>u=>b(u,a))(t)),o=ra(Ht(a=>u=>b(u,a))(e)),i=vt(a=>{const u=ai(a.from.node)(r),c=ai(a.to.node)(o);if(u.tag==="Just"&&c.tag==="Just")return N("Just",b(u._1,c._1));const _=ai(a.from.node)(o),d=ai(a.to.node)(r);return _.tag==="Just"&&d.tag==="Just"?N("Just",b(d._1,_._1)):J})(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)(Xt(u+1|0,s-1|0)))(0)(Xt(0,s-2|0))},xJ=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=Mr(Kt,J,l,p,d),w=(()=>{if(m.tag==="Just")return Mr(Kt,J,l+1|0,h,m._1);if(m.tag==="Nothing")return J;g()})(),x=(()=>{if(w.tag==="Nothing")return d;if(w.tag==="Just")return w._1;g()})();if(kc(e)(x)(n)<kc(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(dJ(_)(c)){a=!1,u=c;continue}s=_}return u})(t)},oa=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+kc(o)(t[i])(e)|0}return n})(0)(Xt(0,t.length-2|0)),wJ=(()=>{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=pJ(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)(Xt(1,e.length-1|0))}const n=Jr(e.length,2),r=t(Rt(0,n,e)),o=t(Rt(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=St(f)(o[p]),c=h,_=p+1|0;continue}u=St(f)(r[h]),c=h+1|0,_=p;continue}d=!1,l=[...f,...h<1?r:Rt(h,r.length,r)];continue}d=!1,l=[...f,...p<1?o:Rt(p,o.length,o)]}return l})([])(0)(0)};return t})(),JJ=t=>e=>n=>{const r=vt(c=>c.tag==="OrderConstraint"?N("Just",{before:c._1.before,after:c._1.after}):J)(t.constraints),o=c=>v(_=>d=>{const l=d.after,f=d.before,h=io(Kt,J,m=>m===f,_),p=io(Kt,J,m=>m===l,_);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=h_(Kt,J,h._1,_),w=(()=>{if(m.tag==="Nothing")return _;if(m.tag==="Just")return m._1;g()})(),x=l_(Kt,J,p._1,f,w);if(x.tag==="Nothing")return w;if(x.tag==="Just")return x._1;g()}return _})(c)(r),i=bc(Ht(c=>_=>b(_.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]):J;if(m.tag==="Just"){const w=h>=0&&h<f._1.length?N("Just",f._1[h]):J;if(w.tag==="Just"){const x=ra(Ht(E=>B=>b(B,E))(m._1)),y=ra(Ht(E=>B=>b(B,E))(w._1)),T=_?mJ(m._1)(x)(y)(n)(i):yJ(m._1)(x)(y)(n)(i),C=v(E=>B=>{const M=vt(R=>qi(R.id)(T))(ft(_?R=>R.to.node===B._2&&na(R.from.node)(x):R=>R.from.node===B._2&&na(R.to.node)(x),n));if(M.length===0)return{...E,items:[...E.items,{n:B._2,key:J,origIdx:B._1}]};const Y=ea(24)(E.r);return{items:[...E.items,{n:B._2,key:N("Just",(lJ(M)+(nt(Y._1)*4172325152040912e-24-.03500000014901161))/nt(M.length)),origIdx:B._1}],r:Y._2}})({items:[],r:f._2})(Ht(Rn)(w._1)),S=Mr(Kt,J,h,xJ(o(q(E=>E.n)(wJ((()=>{const E=C.items,B=M=>Y=>{let R=M,A=Y,j=!0,Z;for(;j;){const z=R,W=A;if(z>=0&&z<E.length){if(E[z].key.tag==="Just"){j=!1,Z=E[z].key._1;continue}if(E[z].key.tag==="Nothing"){R=z+1|0,A=W;continue}g()}j=!1,Z=W}return Z};return(M=>Y=>R=>{let A=M,j=Y,Z=R,z=!0,W;for(;z;){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 L=(D+B(H+1|0)(D+1))/2;A=H+1|0,j=L,Z=[...F,{n:E[H].n,key:L,origIdx:E[H].origIdx}];continue}g()}z=!1,W=F}return W})(0)(-1)([])})()))))(m._1)(n)(r),f._1);if(S.tag==="Just")return b(S._1,C.r);if(S.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))(_?Xt(1,l-1|0):se(Xt(0,l-2|0)))},a=v(c=>_=>rt(P)(_.from.node)()(rt(P)(_.to.node)()(c)))(I)(n),u=v(c=>_=>{if(c.result.crossings===0)return c;const d=x=>y=>T=>C=>{let S=x,E=y,B=T,M=C,Y=!0,R;for(;Y;){const A=S,j=E,Z=B,z=M;if(Z===0){Y=!1,R={layout:A,crossings:0,random:z};continue}const W=s(A,j,z),H=oa(W._1)(n);if(H<Z){S=W._1,E=!j,B=H,M=W._2;continue}Y=!1,R={layout:A,crossings:Z,random:W._2}}return R},l=ea(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)(oa(C._1)(n))(C._2)}const x=p?0:hJ(0)(e.length-1|0),y=x>=0&&x<e.length?N("Just",e[x]):J;if(y.tag==="Just"&&y._1.length>1){const C=ft(S=>T1(S)(a),y._1);if(C.length>1){const S=_J(l._2)(C),E=S._1,B=Mr(Kt,J,x,o(v(M=>Y=>T1(Y)(a)?M.idx>=0&&M.idx<E.length?{idx:M.idx+1|0,result:[...M.result,E[M.idx]]}:{idx:M.idx,result:[...M.result,Y]}:{idx:M.idx,result:[...M.result,Y]})({idx:0,result:[]})(y._1).result),e);if(B.tag==="Just"){const M=s(B._1,p,S._2);return d(M._1)(!p)(oa(M._1)(n))(M._2)}}}const T=s(e,p,l._2);return d(T._1)(!p)(oa(T._1)(n))(T._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_(fJ(cJ(1))._1)(Wi))(Oi)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Xt(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:u.layout},NJ=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=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},ui=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}})(),vJ=ce(P)(Mt),TJ=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},CJ=NJ("Greedy"),Sc=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()})()&&!en(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()})()&&!en(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})(I),b1=t=>e=>n=>{const r=on(e)(t),o=on(n)(t);return r.tag==="Just"&&o.tag==="Just"&&r._1>o._1},k1=t=>e=>n=>r=>{if(ui(n)(r.visited)||ui(n)(r.visiting))return r;const o=v(kJ(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:Wo(P)(n)(o.visiting),visited:rt(P)(n)()(o.visited)}},kJ=t=>e=>n=>r=>o=>b1(t)(n)(o)?{...r,backEdges:rt(Hi)(b(n,o))()(r.backEdges)}:ui(o)(r.visiting)?{...r,backEdges:rt(Hi)(b(n,o))()(r.backEdges)}:ui(o)(r.visited)?r:k1(t)(e)(o)(r),SJ=t=>e=>n=>{const r=l=>{let f=l,h=!0,p;for(;h;){const m=f,w=Ft(x=>J,x=>y=>N("Just",{head:x,tail:y}),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 x=Ft(y=>J,y=>T=>N("Just",{head:y,tail:T}),m.sources);if(x.tag==="Just"){f=Sc(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=C=>{const S=on(C)(m.outDeg),E=on(C)(m.inDeg);return(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;g()})()-(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;g()})()|0},T=Pt(C=>S=>{const E=it.compare(y(S))(y(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(S)(e);if(B.tag==="Nothing")return 1e6;if(B.tag==="Just")return B._1;g()})()):E})(m.remaining);if(0<T.length){const C=T[0];f=Sc(n)(C)({...m,remaining:ft(S=>S!==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=Fo(P.compare)([...q(l=>l.from.node)(n),...q(l=>l.to.node)(n)]),i=ft(l=>l.from.node!==l.to.node,n),s=v(l=>f=>Qt(P)(xe)(f.to.node)(1)(l))(I)(i),a=v(l=>f=>Qt(P)(xe)(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=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=>!en(Zn)(l)(u)&&!en(Zn)(l)(c),o),marks:I,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(b1(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)},LJ=v(t=>e=>Qt(P)(le)(e.from.node)([e.to.node])(t))(I),EJ=t=>e=>{const n=LJ(e),r=Fo(P.compare)([...q(i=>i.from.node)(e),...q(i=>i.to.node)(e)]),o=v(i=>s=>rt(P)(s.to.node)()(i))(I)(e);return v(i=>s=>k1(t)(n)(s)(i))({visiting:I,visited:I,backEdges:I})([...ft(i=>!ui(i)(o),r),...ft(i=>ui(i)(o),r)]).backEdges},GJ=t=>e=>n=>r=>{const o=vJ(Ht(a=>u=>b(u,a))(e)),i=bJ(n),s=(()=>{if(t==="DepthFirst")return EJ(i)(r);if(t==="Greedy")return SJ(i)(o)(r);g()})();return{edges:q(a=>TJ(b(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=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),ia=t=>e=>n=>r=>$i(Te(e)(n))(Ce(e)(n))(r)(t),sa=nt(4),PJ=ys(t=>{if(t.direction==="H"){const e=Te(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=Te(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})())}),BJ=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=Nr(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?[]:Rt(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()},Ki=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=>Ki(Te(e)(n))(Ce(e)(n))(r)(t),DJ=t=>e=>n=>r=>{const o=n+2|0,i=o<1?e:Rt(o,e.length,e),s=n<1?[]:Rt(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")&&!ia(t)(Te(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)(Te(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()},RJ=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=DJ(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)},AJ=t=>e=>n=>r=>{const o=(l,f,h)=>!ia(t)(Te(f)(h))(Ce(f)(h))(l),i=n+3|0,s=i<1?e:Rt(i,e.length,e),a=n<1?[]:Rt(0,n,e),u=(n+2|0)===(r-1|0),c=n===0,_=(l,f,h)=>!Yi(t)(Te(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()},IJ=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=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=>{const e=n=>{let r=n,o=!0,i;for(;o;){const s=r,a=Ui(Vi(RJ(t)(IJ(t)(s))));if(a.length<s.length){r=a;continue}o=!1,i=a}return i};return n=>e(Ui(Vi(n)))},QJ=t=>e=>n=>r=>{const o=Te(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))(q(u=>({...u,x:u.x+u.w}))(s));return 0<a.length?a[0].x+1:(n+r)/2},zJ=t=>e=>n=>r=>{const o=Te(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))(q(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=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))(q(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},WJ=t=>e=>n=>r=>{const o=Te(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))(q(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},L1=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},E1=t=>e=>n=>r=>o=>{const i=Te(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)?L1(u=>$i(i)(s)(u)(t))(a)(1):a},OJ=t=>e=>n=>r=>o=>{const i=Te(e)(n),s=Ce(e)(n);if(!Ki(i)(s)(r)(t))return r;if(!Ki(i)(s)(o)(t))return o;const a=(r+o)/2;return Ki(i)(s)(a)(t)?L1(u=>Ki(i)(s)(u)(t))(a)(1):a},qJ=t=>e=>n=>r=>{const o=Te(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=v(c=>_=>Ce(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},HJ=t=>e=>n=>r=>{const o=Te(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=v(c=>_=>Ce(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},$J=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,S,E)=>!ia(e)(Te(S)(E))(Ce(S)(E))(C),_=(C,S,E)=>!ia(n)(Te(S)(E))(Ce(S)(E))(C),d=(C,S,E,B)=>t.tag==="Just"&&!Yi(n)(Te(C)(S))(Ce(C)(S))(t._1)?t._1:OJ(e)(C)(S)(E)(B),l=(C,S,E,B)=>{if(C===E){const Y=qJ(e)(S)(B)(C),R=zJ(e)(C)(S)(B),A=WJ(e)(C)(S)(B);return[{start:b(C,S),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 M=d(C,E,S,B);return[{start:b(C,S),end:b(C,M),direction:me},{start:b(C,M),end:b(E,M),direction:pe},{start:b(E,M),end:b(E,B),direction:me}]},f=(C,S,E,B)=>{if(S===B){const Y=HJ(e)(C)(E)(S),R=QJ(e)(S)(C)(E),A=MJ(e)(S)(C)(E);return[{start:b(C,S),end:b(R,S),direction:pe},{start:b(R,S),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 M=E1(e)(S)(B)(C)(E);return[{start:b(C,S),end:b(M,S),direction:pe},{start:b(M,S),end:b(M,B),direction:me},{start:b(M,B),end:b(E,B),direction:pe}]},h=(C,S,E)=>!Yi(e)(Te(S)(E))(Ce(S)(E))(C),p=(C,S,E)=>!Yi(n)(Te(S)(E))(Ce(S)(E))(C),m=(C,S,E,B)=>{if(p(S,C,E)&&_(E,S,B))return[{start:b(C,S),end:b(E,S),direction:pe},{start:b(E,S),end:b(E,B),direction:me}];const M=E1(e)(S)(B)(C)(E);return[{start:b(C,S),end:b(M,S),direction:pe},{start:b(M,S),end:b(M,B),direction:me},{start:b(M,B),end:b(E,B),direction:pe}]},w=(C,S,E,B)=>{if(_(C,S,B)&&p(B,C,E))return[{start:b(C,S),end:b(C,B),direction:me},{start:b(C,B),end:b(E,B),direction:pe}];const M=d(C,E,S,B);return[{start:b(C,S),end:b(C,M),direction:me},{start:b(C,M),end:b(E,M),direction:pe},{start:b(E,M),end:b(E,B),direction:me}]},x=(()=>{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)})(),y=(()=>{if(r==="South"||r==="North")return me;if(r==="East"||r==="West")return pe;g()})(),T={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:y}]:BJ({start:b(o._1,o._2),end:b(a._1,a._2),direction:y})(x)(T)},VJ=q(t=>({x:t.position._1*sa-2,y:t.position._2*sa-2,w:t.size._1*sa+4,h:t.size._2*sa+4})),G1=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=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},UJ=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),Lc=t=>e=>t.gapTop+1*nt(4)+nt(e)*2.5*nt(4),KJ=t=>e=>{const n=G1(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return N("Just",{slot1Y:Lc(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Lc(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return J;g()}if(n.tag==="Nothing")return J;g()},YJ=t=>e=>{const n=v(r=>o=>rt(P)(o.node)(o)(r))(I)(e);return hn(Ht(r=>o=>{const i=ci(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),x=[{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:x,bends:Fe(y=>T=>y.end,x,Rt(1,3,x)),bendType:[],jumps:[],reversed:!1}})(o.edges)}g()})(q(r=>({node:r._1,edges:r._2}))(UJ(v(r=>o=>Qt(P)(le)(o.from.node)([o])(r))(I)(t)))))},XJ=t=>e=>{const n=v(i=>s=>rt(P)(s.node)(s)(i))(I)(e),r=i=>{const s=ci(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.position._1;g()},o=i=>{const s=ci(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}},jJ=t=>t.from.node===t.to.node,ZJ=t=>e=>n=>r=>{const o=FJ(n)($J(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,Rt(1,o.length,o)),bendType:[],jumps:[],reversed:!1}},tN=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,Rt(1,5,o)),bendType:[],jumps:[],reversed:!1}},eN=t=>e=>n=>{const r=ci(t.edge.from.node)(n);if(r.tag==="Just"){const i=ci(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=ci(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)},nN=t=>e=>{const n=G1(e.edge.id)(t);if(n.tag==="Just")return N("Just",Lc(n._1)(n._1.slot));if(n.tag==="Nothing")return J;g()},rN=t=>e=>n=>r=>o=>{const i=v(c=>_=>rt(P)(_.node)(_)(c))(I)(e),s=VJ(e),a=c1(ft(c=>c.from.node!==c.to.node,t))(e)(n)(r)(o),u=o1(a)(e);return[...YJ(ft(jJ,t))(e),...v(c=>_=>{const d=eN(_)(s)(i),l=[...d,...c.edgeObstacles],f=KJ(u)(_),h=(()=>{if(f.tag==="Just")return tN(f._1)(d)(l)(_);if(f.tag==="Nothing")return ZJ(nN(u)(_))(d)(l)(_);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...PJ(h.segments)]}})({results:[],edgeObstacles:[]})(XJ(a)(e)).results]},Yr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Xr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},oN=t=>e=>n=>{if(t.start._1!==e.start._1)return J;const r=Xr(Yr(t.start._2)(t.end._2))(Yr(e.start._2)(e.end._2)),o=Yr(Xr(t.start._2)(t.end._2))(Xr(e.start._2)(e.end._2));return r<o?N("Just",{position:b(t.start._1,(r+o)/2),crossingEdge:n}):J},iN=t=>e=>n=>{if(t.start._2!==e.start._2)return J;const r=Xr(Yr(t.start._1)(t.end._1))(Yr(e.start._1)(e.end._1)),o=Yr(Xr(t.start._1)(t.end._1))(Xr(e.start._1)(e.end._1));return r<o?N("Just",{position:b((r+o)/2,t.start._2),crossingEdge:n}):J},sN=t=>e=>n=>{if(t.direction==="H")return iN(t)(e)(n);if(t.direction==="V")return oN(t)(e)(n);g()},aN=t=>e=>n=>{const r=t+1|0,o=r<1?n:Rt(r,n.length,n);return Et(e.segments)(i=>Et(o)(s=>vt(a=>sN(i)(a)(s.edge))(ft(a=>a.direction==="H"?i.direction==="H":a.direction==="V"&&i.direction==="V",s.segments))))},uN=t=>e=>n=>e.start._1>Yr(t.start._1)(t.end._1)&&e.start._1<Xr(t.start._1)(t.end._1)&&t.start._2>Yr(e.start._2)(e.end._2)&&t.start._2<Xr(e.start._2)(e.end._2)?N("Just",{position:b(e.start._1,t.start._2),crossingEdge:n}):J,cN=t=>e=>Et(ft(n=>n.direction==="H",t.segments))(n=>Et(e)(r=>vt(o=>uN(n)(o)(r.edge))(ft(o=>o.direction==="V",r.segments)))),gN=t=>e=>n=>[...cN(e)(ft(r=>r.edge!==e.edge,n)),...aN(t)(e)(n)],P1=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},_N=v(t=>e=>rt(P)(e)()(t))(I),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},fN=Uf(P),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},B1=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ec=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},dN=ce(it)(Mt),lN=t=>e=>Qe(P.compare,Ie,t,e),D1=Ht(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),hN=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=P1(_)(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,$)})())|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,pN=t=>e=>{const n=_N(t);return fN(t)(D1(ft(r=>aa(r.src)(n)&&aa(r.tgt)(n),e)))},mN=t=>e=>{const n=v(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(aa(p._1.head)(f)){a=p._1.tail,u=f,c=h;continue}a=[...p._1.tail,...(()=>{const m=gr(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(aa(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:I,components:[]})(t).components},yN=t=>e=>n=>{const r=v(i=>s=>Qt(P)(xe)(s.tgt)(1)(i))(I)(e),o=v(i=>s=>Qt(P)(xe)(s.src)(1)(i))(I)(e);return v(i=>s=>{const a=gr(s)(r),u=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})();if((()=>{const x=gr(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=gr(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:B1(x.mIn)((()=>{const T=gr(s)(d),C=gr(y.src)(d);return(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})()-(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;g()})()|0})())}:y.src===s?{...x,mOut:B1(x.mOut)((()=>{const T=gr(y.tgt)(d),C=gr(s)(d);return(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})()-(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._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 w=v(x=>y=>{const T=Ec(y)(i.filling),C=(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})();return C<x.bestFill?{best:y,bestFill:C}:x})({best:_,bestFill:(()=>{const x=Ec(_)(i.filling);if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})()})(Xt(p,m));return w.best===_?i:{layers:rt(P)(s)(w.best)(i.layers),filling:rt(it)(_)((()=>{const x=Ec(_)(i.filling);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;g()})())(rt(it)(w.best)(w.bestFill+1|0)(i.filling))}})({layers:n,filling:dN(q(i=>b(i,v(s=>a=>(()=>{const u=gr(a)(n);return u.tag==="Nothing"?!1:u.tag==="Just"&&u._1===i})()?s+1|0:s)(0)(t)))(Xt(0,v(i=>s=>P1(i)((()=>{const a=gr(s)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})()))(0)(t))))})(t).layers},xN=t=>e=>yN(t)(D1(e))(v(lN)(I)(hN(q(n=>pN(n)(e))(mN(t)(e))))),wN=t=>t,fo=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},ua=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},R1=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),JN=wN("NetworkSimplex"),NN=t=>e=>v(n=>r=>{const o=v(ua)(0)(vt(i=>fo(i)(n))(r));return v(i=>s=>rt(P)(s)(o)(i))(n)(r)})(e)(t),vN=t=>e=>({layers:q(n=>ft(r=>{const o=fo(r)(e);return o.tag==="Nothing"?!1:o.tag==="Just"&&o._1===n},t))(Xt(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=ua(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,$)})()))),nodeLayer:e}),TN=t=>e=>n=>{const r=v(o=>i=>rt(P)(i)(!0)(o))(I)(e);return v(o=>i=>rt(P)(i._1)(i._2)(o))(xN(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()})()?J:N("Just",{src:o.from.node,tgt:o.to.node}))(t)))(R1(n))},CN=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(ua)(0)(vt(l=>fo(l)(d))(_))|0)(d)}g()},i=v(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=ua(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,$)})());return v(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)})())(R1(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})(I),kN=v(t=>e=>Qt(P)(le)(e.to.node)([e.from.node])(t))(I),SN=v(t=>e=>Qt(P)(le)(e.from.node)([e.to.node])(t))(I),LN=t=>e=>n=>r=>{const o=SN(n),i=kN(n),s=bN(e);return vN(r)(NN(vt(a=>a.tag==="SameLayer"?N("Just",a._1.nodes):J)(e))((()=>{if(t==="LongestPath")return CN(o)(i)(r)(s);if(t==="NetworkSimplex")return TN(n)(r)(s);g()})()))},EN=ce(P)(Mt),GN=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},A1=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=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Xi=ce(P)(Mt),PN=ce(P)(Mt),F1=(()=>{const t=q(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>se(t(e))})(),BN=t=>e=>n=>r=>{const o=EN(q(s=>b(s.edge,s))(r)),i=s=>0<s.nodes.length&&(()=>{const a=GN(s.edgeId)(n);return a.tag==="Just"&&s.nodes[0]!==a._1._1})();return q(s=>{if(s.nodes.length<=2){const _=A1(s.edgeId)(o);if(_.tag==="Just"){const d=i(s),l=Ui(Vi(d?F1(_._1.segments):_._1.segments));return{..._._1,edge:s.edgeId,segments:l,bends:Fe(f=>h=>f.end,l,Rt(1,l.length,l)),reversed:d}}if(_.tag==="Nothing")return{edge:s.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};g()}const a=Et(vt(_=>A1(_)(o))(Fe(_=>d=>s.edgeId+":"+_+"->"+d,s.nodes,Rt(1,s.nodes.length,s.nodes))))(_=>_.segments),u=i(s),c=Ui(Vi(u?F1(a):a));return{edge:s.edgeId,segments:c,bends:Fe(_=>d=>_.end,c,Rt(1,c.length,c)),bendType:[],jumps:[],reversed:u}})(t)},DN={layers:[],edges:[],chains:[]},RN={nodeGap:3,layerGap:2,iterations:8,layerer:JN,cycleBreaker:CJ,compactPostRouting:!0,compactionSpacings:kw},AN=t=>({pos:b(0,0),size:b(v(e=>n=>I1(e)(n.position._1+n.size._1))(0)(t),v(e=>n=>I1(e)(n.position._2+n.size._2))(0)(t))}),IN=t=>e=>n=>{const r=Xi(q(c=>b(c.id,c.ports))(e.nodes)),o=ft(c=>Re(3)(c.node)!=="$d:",n.placements),i=BN(n.withDummies.chains)(n.acyclic.reversedEdges)(PN(q(c=>b(c.id,b(c.from.node,c.to.node)))(e.edges)))(rN(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(_1(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(Xi(q(_=>b(_.id,_.size))(e.nodes)))})()))),s=t.compactPostRouting?Ew()(t.compactionSpacings)({nodes:o,edges:e.edges,paths:i,ports:r}):{nodes:o,edges:i},a=q(c=>{const _=Ui(Vi(c.segments));return{...c,segments:_,bends:Fe(d=>l=>d.end,_,Rt(1,_.length,_))}})(s.edges),u=Ht(c=>_=>({..._,jumps:gN(c)(_)(a)}))(a);return{nodes:s.nodes,edges:u,boundingBox:AN(s.nodes),metrics:nx(s.nodes)(u)(0)}},FN=t=>e=>n=>{const r=Xi(q(i=>b(i.id,i.size))(e.nodes)),o={...n,placements:uJ({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(Xi(q(i=>b(i.id,i.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(_1(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:IN(t)(e)(o)}},QN=t=>e=>n=>FN(t)(e)({...n,ordered:JJ({iterations:t.iterations,constraints:e.constraints,modelOrder:Xi(Ht(r=>o=>b(o.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),zN=t=>e=>n=>QN(t)(e)({...n,withDummies:Gw(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),MN=t=>e=>{const n=q(o=>o.id)(e.nodes),r=GJ(t.cycleBreaker)(n)(e.constraints)(e.edges);return zN(t)(e)({acyclic:r,layered:LN(t.layerer)(e.constraints)(r.edges)(n),withDummies:DN,ordered:[],placements:[]})},Q1=t=>t,z1=Q1("RunText"),WN=Q1("RunCode"),M1=t=>e=>n=>e.length===0?n:St(n)({style:t,text:Or(e)}),ON=t=>({style:(()=>{if(t.style==="RunText")return WN;if(t.style==="RunCode")return z1;g()})(),buf:[],runs:M1(t.style)(t.buf)(t.runs)}),qN=t=>e=>0<e.length?{...t,buf:St(t.buf)(e[0])}:{...t,buf:St(t.buf)("\\")},HN=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=qN(s)(a._1.tail),r=Rt(1,a._1.tail.length,a._1.tail);continue}if(a._1.head==="`"){n=ON(s),r=a._1.tail;continue}n={...s,buf:St(s.buf)(a._1.head)},r=a._1.tail;continue}g()}return i},W1=t=>{const e=HN({style:z1,buf:[],runs:[]})(vr(t));return M1(e.style)(e.buf)(e.runs)};let Gc=null;function $N(){return Gc||(typeof document>"u"?null:(Gc=document.createElement("canvas").getContext("2d"),Gc))}const O1=new Map,VN=t=>e=>n=>r=>()=>{const o=`${n} ${e}px ${t}|${r}`,i=O1.get(o);if(i!==void 0)return i;const s=$N();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},UN=oo.traverse(gu),KN=v(er)(0),lo=(()=>{const t=Qn(`\r
|
|
3
|
-
`)(
|
|
4
|
-
`)(" "),n=(()=>{const r=Qn("\r")(" "),o=(()=>{const i=Qn(" ")(" ");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),q1=t=>e=>{const n=UN(r=>{const o=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;g()})();return VN(o.family)(o.size)(o.weight)(lo(r.text))})(W1(lo(e)));return()=>{const r=n();return KN(r)}},H1={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"}},YN=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},gi=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()},jN=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ZN=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},$1=t=>Or(se(tr(e=>e===" ")(se(tr(e=>e===" ")(vr(t)).rest)).rest)),tv=t=>v(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?N("Just",n._1):e)(J)(Ht(Rn)(t)),Pc=t=>e=>{if(t<=0)return[e];if(or(e)<=t)return[e];const n=vr(e),r=t<1?[]:Rt(0,t,n),o=tv(r);if(o.tag==="Just"){const i=$1(A_(!(o._1>=0&&o._1<r.length)||r[o._1]===" "?o._1:o._1+1|0)(e)),s=$1($o(o._1+1|0)(e));return s===""?[i]:[i,...Pc(t)(s)]}if(o.tag==="Nothing"){const i=A_(t)(e),s=$o(t)(e);return s===""?[i]:[i,...Pc(t)(s)]}g()},ev={cellW:7,cellH:3,maxLineWidth:20},nv=t=>e=>{const n=q(i=>b((()=>{if(i.label.tag==="Just")return i.label._1;if(i.label.tag==="Nothing")return i.id;g()})(),i))(e.nodes),r=gi(1)(Jr((XN(t.maxLineWidth)(v(i=>s=>gi(i)(or(s._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),o=(r*t.cellW|0)-1|0;return{...e,nodes:q(i=>{if(!(i._2.size._1===1&&i._2.size._2===1))return i._2;const s=Et(Kr(`
|
|
5
|
-
`)(
|
|
6
|
-
`)(t);return e.length===0?[""]:e},X1=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 Zt(de.foldr,e(t.interiors,$))},Jv=t=>Zi(vt(e=>N("Just",b(e.edge,{id:e.edge,from:{node:e.from,port:J},to:{node:e.to,port:J},label:J})))(Et(t.scenes)(e=>e.tag==="DataFlow"?vt(n=>n.kind.tag==="SendToken"?N("Just",n.kind._1):J)(e._1.events):[]))),j1=t=>{const e=c2(t),n=ft(o=>av(o.id)(e.nodes),t.graph.nodes),r=ft(o=>uv(o.id)(e.edges),t.graph.edges);return{nodes:[...n,...q(xv)(Zt(fn.foldr,$n(P.compare,e.nodes,cv(q(o=>o.id)(n)))))],edges:[...r,...vt(mv(t)(Jv(t)))(Zt(fn.foldr,$n(P.compare,e.edges,gv(q(o=>o.id)(r)))))],constraints:t.graph.constraints}},Nv=t=>{const e=ga(n=>{const r=q1(H1)((()=>{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)}})(j1(t).nodes);return()=>{const n=e();return _a(n)}},Z1=t=>{const e=Nv(t);return()=>{const n=e(),r=ga(Z1)(X1(t))();return v(_v)(n)(r)}},vv=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},...q(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];g()},Tv=t=>e=>b(e.edge,vv(t)(e)),Cv=t=>e=>n=>r=>({nodes:_a(q(wv(nt(4)*t)(e)(n))(r.nodes)),edges:Zi(q(Tv(t))(r.edges)),chipExtras:I,edgeLabels:I}),bv=t=>e=>({...pv(Zi(q(n=>b(n.id,b(n.from.node,n.to.node)))(e.edges)))(Cv(8)(_a(q(n=>b(n.id,(()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})()))(e.nodes)))(_a(q(n=>b(n.id,n.shape))(e.nodes)))(MN(RN)(e).result)),edgeLabels:Zi(vt(n=>n.label.tag==="Just"?N("Just",b(n.id,n.label._1)):J)(e.edges))}),kv=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()})(I)(t.scenes),Sv=t=>{const e=ga(n=>{const r=q1(H1)(n);return()=>{const o=r();return b(n,{labelW:o,charCount:or(lo(n)),lineCount:1})}})(Zt(fn.foldr,fv(Et(Zt(fn.foldr,kv(t)))(Y1))));return()=>{const n=e();return dv(n)}},td=t=>{const e=Sv(t);return()=>{const n=e(),r=ga(td)(X1(t))();return v(lv)(n)(r)}},Lv=nt(4)*8,Ev=t=>Et(t.scenes)(e=>{if(e.tag==="Structural")return[];if(e.tag==="DataFlow")return e._1.events;if(e.tag==="Hold")return[];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];if(e.tag==="StepScene")return[];g()}),Gv=t=>e=>n=>{const r=o=>{const i=vt(s=>{const a=hv(s)(t);return a.tag==="Just"?N("Just",{w:a._1.labelW+28,h:nt(YN(1)(a._1.lineCount))*13.2+12}):J})(Et(o)(Y1));return i.length===0?J:N("Just",{w:v(K1)(0)(q(s=>s.w)(i)),h:v(K1)(0)(q(s=>s.h)(i))})};return v(o=>i=>{if(i.kind.tag==="SendToken"){const s=Bc(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)(q(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)(Ev(e))},ed=t=>e=>n=>({layout:(()=>{const r=bv()(rv(Lv)(t)(nv(ev)(j1(n))));return{...r,chipExtras:Gv(e)(n)(r)}})(),interiors:(()=>{const r=ed(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)})()}),nd=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},Dc=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=nd(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),_=nd(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}),Pv=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=kt("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"),Bv=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()},Dv=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=Pv(_);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)($)},Rv=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:Dv(Bv)(_t)(t._2)));g()},tt=(t,e)=>({tag:"Free",_1:t,_2:e}),ut=(t,e,n)=>({tag:t,_1:e,_2:n}),rd=t=>{let e=t,n=!0,r;for(;n;){const o=e;if(o._1.tag==="Return"){const i=Rv(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},Av=t=>e=>{const n=e.Monad0(),r=n.Bind1().Apply0().Functor0();return o=>e.tailRecM(i=>{const s=rd(i);if(s.tag==="Return")return r.map(a0)(n.Applicative0().pure(s._1));if(s.tag==="Bind")return r.map(_u)(o(t.map(s._2)(s._1)));g()})},Iv=t=>e=>n=>{const r=rd(n);if(r.tag==="Return")return e(r._1);if(r.tag==="Bind")return t(r._1)(r._2);g()},Rc={Applicative0:()=>xo,Bind1:()=>od},Fv={map:t=>e=>od.bind(e)(n=>xo.pure(t(n)))},od={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,kt("Cons",at("CatCons",e,st($,$)),t._2._2._2)));g()})()),Apply0:()=>id},id={apply:t=>e=>{const n=r=>tt(e._1,(()=>{if(e._2.tag==="CatNil")return at("CatCons",o=>xo.pure(r(o)),st($,$));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($,$)),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,kt("Cons",at("CatCons",n,st($,$)),t._2._2._2)));g()})())},Functor0:()=>Fv},xo={pure:t=>tt(ut("Return",t),_t),Apply0:()=>id},Qv=()=>()=>()=>t=>e=>n=>Vp(n.type)(t)?Up(n.type)(t)(n.value):e(n),zv={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+"]"),Wv=()=>()=>()=>t=>Qv()()()(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",w="Finalized",x="Forked";function y(G,Q,V,K){this.tag=G,this._1=Q,this._2=V,this._3=K}function T(G){var Q=function(V,K,U){return new y(G,V,K,U)};return Q.tag=G,Q}function C(G){return new y(e,void 0)}function S(G){try{G()}catch(Q){setTimeout(function(){throw Q},0)}}function E(G,Q,V){try{return Q(V())}catch(K){return G(K)}}function B(G,Q,V){try{return Q(V)()}catch(K){return V(G(K))(),C}}var M=(function(){var G=1024,Q=0,V=0,K=new Array(G),U=!1;function O(){var X;for(U=!0;Q!==0;)Q--,X=K[V],K[V]=void 0,V=(V+1)%G,X();U=!1}return{isDraining:function(){return U},enqueue:function(X){var et;Q===G&&(et=U,O(),U=et),K[(V+Q)%G]=X,Q++,U||O()}}})();function Y(G){var Q={},V=0,K=0;return{register:function(U){var O=V++;U.onComplete({rethrow:!0,handler:function(X){return function(){K--,delete Q[O]}}})(),Q[O]=U,K++},isEmpty:function(){return K===0},killAll:function(U,O){return function(){if(K===0)return O();var X=0,et={};function lt(pt){et[pt]=Q[pt].kill(U,function(Tt){return function(){delete et[pt],X--,G.isLeft(Tt)&&G.fromLeft(Tt)&&setTimeout(function(){throw G.fromLeft(Tt)},0),X===0&&O()}})()}for(var bt in Q)Q.hasOwnProperty(bt)&&(X++,lt(bt));return Q={},V=0,K=0,function(pt){return new y(o,function(){for(var Tt in et)et.hasOwnProperty(Tt)&&et[Tt]()})}}}}}var R=0,A=1,j=2,Z=3,z=4,W=5,H=6;function D(G,Q,V){var K=0,U=R,O=V,X=null,et=null,lt=null,bt=null,pt=null,Tt=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{O=lt(O),bt===null?lt=null:(lt=bt._1,bt=bt._2)}catch(Bt){U=W,X=G.left(Bt),O=null}break;case Z:G.isLeft(O)?(U=W,X=O,O=null):lt===null?U=W:(U=j,O=G.fromRight(O));break;case A:switch(O.tag){case s:lt&&(bt=new y(f,lt,bt)),lt=O._2,U=A,O=O._1;break;case e:lt===null?(U=W,O=G.right(O._1)):(U=j,O=O._1);break;case o:U=Z,O=E(G.left,G.right,O._1);break;case i:U=z,O=B(G.left,O._1,function(Bt){return function(){K===ct&&(K++,M.enqueue(function(){K===ct+1&&(U=Z,O=Bt,Yt(K))}))}});return;case n:U=W,X=G.left(O._1),O=null;break;case r:lt===null?pt=new y(f,O,pt,et):pt=new y(f,O,new y(f,new y(h,lt,bt),pt,et),et),lt=null,bt=null,U=A,O=O._1;break;case a:Tt++,lt===null?pt=new y(f,O,pt,et):pt=new y(f,O,new y(f,new y(h,lt,bt),pt,et),et),lt=null,bt=null,U=A,O=O._1;break;case u:U=Z,yt=D(G,Q,O._2),Q&&Q.register(yt),O._1&&yt.run(),O=G.right(yt);break;case c:U=A,O=L(G,Q,O._1);break}break;case W:if(lt=null,bt=null,pt===null)U=H,O=et||X||O;else switch(yt=pt._3,ht=pt._1,pt=pt._2,ht.tag){case r:et&&et!==yt&&Tt===0?U=W:X&&(U=A,O=ht._2(G.fromLeft(X)),X=null);break;case h:et&&et!==yt&&Tt===0||X?U=W:(lt=ht._1,bt=ht._2,U=j,O=G.fromRight(O));break;case a:Tt--,X===null&&(dt=G.fromRight(O),pt=new y(f,new y(p,ht._2,dt),pt,yt),(et===yt||Tt>0)&&(U=A,O=ht._3(dt)));break;case p:pt=new y(f,new y(w,O,X),pt,et),U=A,et&&et!==yt&&Tt===0?O=ht._1.killed(G.fromLeft(et))(ht._2):X?O=ht._1.failed(G.fromLeft(X))(ht._2):O=ht._1.completed(G.fromRight(O))(ht._2),X=null,Tt++;break;case m:Tt++,pt=new y(f,new y(w,O,X),pt,et),U=A,O=ht._1;break;case w:Tt--,U=W,O=ht._1,X=ht._2;break}break;case H:for(var Lt in jt)jt.hasOwnProperty(Lt)&&(Ct=Ct&&jt[Lt].rethrow,S(jt[Lt].handler(O)));jt=null,et&&X?setTimeout(function(){throw G.fromLeft(X)},0):G.isLeft(O)&&Ct&&setTimeout(function(){if(Ct)throw G.fromLeft(O)},0);return;case R:U=A;break;case z:return}}function Dt(ct){return function(){if(U===H)return Ct=Ct&&ct.rethrow,ct.handler(O)(),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=Dt({rethrow:!1,handler:function(){return yt(G.right(void 0))}})();switch(U){case R:et=G.left(ct),U=H,O=et,Yt(K);break;case z:et===null&&(et=G.left(ct)),Tt===0&&(U===z&&(pt=new y(f,new y(m,O(ct)),pt,et)),U=W,O=null,X=null,Yt(++K));break;default:et===null&&(et=G.left(ct)),Tt===0&&(U=W,O=null,X=null)}return dt}}function mt(ct){return function(){var yt=Dt({rethrow:!1,handler:ct})();return U===R&&Yt(K),yt}}return{kill:wt,join:mt,onComplete:Dt,isSuspended:function(){return U===R},run:function(){U===R&&(M.isDraining()?Yt(K):M.enqueue(function(){Yt(K)}))}}}function F(G,Q,V,K){var U=0,O={},X=0,et={},lt=new Error("[ParAff] Early exit"),bt=null,pt=t;function Tt(Dt,wt,mt){var ct=wt,yt=null,dt=null,ht=0,Lt={},Bt,zt;t:for(;;)switch(Bt=null,ct.tag){case x:if(ct._3===t&&(Bt=O[ct._1],Lt[ht++]=Bt.kill(Dt,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(zt=0,Bt=ht;zt<Bt;zt++)Lt[zt]=Lt[zt]();return Lt}function Gt(Dt,wt,mt){var ct,yt,dt,ht,Lt,Bt;for(G.isLeft(Dt)?(ct=Dt,yt=null):(yt=Dt,ct=null);;){if(dt=null,ht=null,Lt=null,Bt=null,bt!==null)return;if(wt===null){K(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,Bt=X++,et[Bt]=Tt(lt,ct===dt?wt._2:wt._1,function(){return function(){delete et[Bt],Lt?Lt=!1:mt===null?Gt(ct,null,null):Gt(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,Bt=X++,et[Bt]=Tt(lt,yt===dt?wt._2:wt._1,function(){return function(){delete et[Bt],Lt?Lt=!1:mt===null?Gt(yt,null,null):Gt(yt,mt._1,mt._2)}}),Lt){Lt=!1;return}break}mt===null?wt=null:(wt=mt._1,mt=mt._2)}}function jt(Dt){return function(wt){return function(){delete O[Dt._1],Dt._3=wt,Gt(wt,Dt._2._1,Dt._2._2)}}}function Ct(){var Dt=A,wt=V,mt=null,ct=null,yt,dt;t:for(;;)switch(yt=null,dt=null,Dt){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=U++,Dt=W,yt=wt,wt=new y(x,dt,new y(f,mt,ct),t),yt=D(G,Q,yt),yt.onComplete({rethrow:!1,handler:jt(wt)})(),O[dt]=yt,Q&&Q.register(yt)}break;case W:if(mt===null)break t;mt._1===t?(mt._1=wt,Dt=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++)O[dt].run()}function Yt(Dt,wt){bt=G.left(Dt);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(Dt,pt,wt);return function(dt){return new y(i,function(ht){return function(){for(var Lt in yt)yt.hasOwnProperty(Lt)&&yt[Lt]();return C}})}}return Ct(),function(Dt){return new y(i,function(wt){return function(){return Yt(Dt,wt)}})}}function L(G,Q,V){return new y(i,function(K){return function(){return F(G,Q,V,K)}})}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=Y,y.Scheduler=M,y.nonCanceler=C,y})();const Ov=t=>e=>Iv(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=Hp(()=>Ov(i=>e.bind(r(i))(o()))(n));return o()}};let sd=null;function Hv(){return sd||(typeof document>"u"?null:sd=document.createElement("canvas").getContext("2d"))}const Ac=new Map;function ad(t,e,n,r,o,i){const s=`${n} ${e}px ${t}`,a=s+"|"+r;if(Ac.has(a))return Ac.get(a);const u=Hv();if(!u)return i;u.font=s;const c=o(u.measureText(r)),_=typeof document<"u"?document.fonts:null;if(!_||_.check(s))Ac.set(a,c);else if(_&&_.load)try{_.load(s)}catch{}return c}const $v=(t,e,n,r)=>ad(t,e,n,r,o=>o.width,-1),Vv=(t,e,n,r)=>ad(t,e,n,r,o=>({ascent:o.actualBoundingBoxAscent,descent:o.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),fa=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),ud=t=>t,cd={map:t=>e=>{if(e.tag==="MeasureText")return fa("MeasureText",e._1,e._2,n=>t(e._3(n)));if(e.tag==="MeasureInk")return fa("MeasureInk",e._1,e._2,n=>t(e._3(n)));g()}},Ic=t=>e=>{const n=$v(t.family,t.size,t.weight,lo(e));return n<0?nt(Yo(e).length)*t.size*.62:n},Fc=t=>e=>{const n=Vv(t.family,t.size,t.weight,lo(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},Uv=t=>e=>tt(ut("Bind",{type:"metrics",value:fa("MeasureInk",t,e,ud),map:cd.map},n=>tt(ut("Return",n),_t)),_t),ts=t=>e=>tt(ut("Bind",{type:"metrics",value:fa("MeasureText",t,e,ud),map:cd.map},n=>tt(ut("Return",n),_t)),_t),gd=t=>t,_d=t=>t,da=t=>t,fd=t=>t,dd=t=>t,$t=(t,e,n,r,o)=>({tag:t,_1:e,_2:n,_3:r,_4:o}),ld=t=>t,Qc=t=>t,Kv=Qc("BaselineTop"),En=Qc("BaselineMiddle"),Yv=Qc("BaselineBottom"),_i=ld("AlignLeft"),Gr=ld("AlignCenter"),Ve=dd("RoundJoin"),es=dd("MiterJoin"),Gn=fd("ButtCap"),Vn=fd("RoundCap"),Xv=da("LayerPolyOut"),jv=da("LayerPolyIn"),Zv=da("LayerNodeMask"),tT=da("LayerOverlay"),ns=_d("NonZero"),eT=_d("EvenOdd"),hd=gd("Normal"),la=gd("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()}},Pr={r:26,g:26,b:26,a:255},zc=t=>e=>Math.imul(t,e),fi=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=fi(n);return{prng:r.prng,value:t+r.value*(e-t)}},Mc=t=>e=>v(n=>r=>zc(n^r)(-2048144789))(e)(q(Ur)(vr(t))),nT=t=>t,pd=t=>t,rT=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()},md=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()},Wc=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},oT=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()},iT=pd("FlatLevel"),sT=pd("NestedLevel"),Oc=nT("GenieSilhouette"),aT=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const o=fi(t);return{prng:o.prng,yLift:o.value*n.yJitter*r}},uT=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const o=fi(t);return{prng:o.prng,dx:(o.value*2-1)*n.xJitter*r}},yd=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,o=$e(r*r+n*n),i=(t.r*t.r-e.r*e.r+o*o)/(2*o),s=$e(rT(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:_},di=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]},cT=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=fi(t);return{prng:s.prng,r:o*(1+s.value*i.rJitter)}},xd=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]},gT=t=>e=>n=>{const r=fi(t),o=e.length;return o===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const i=md(0)(o-1|0)(fe(An(r.value*nt(n))));return i>=0&&i<e.length?e[i]:-1})()}},_T=t=>e=>{const n=fi(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const o=md(0)(r-1|0)(fe(An(n.value*nt(r))));return o>=0&&o<e.length?e[o]:-1})()}},wd=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]},Jd=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],Nd={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},fT=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]},Td=t=>e=>{const n=e.y+e.h,r=z0(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=Wc(t.minN)(o<=0||i<=0?t.minN:fe(Hn(o/i))+1|0),a=s>=3?Xt(1,s-2|0):[],u=a.length,c=Jr(u+1|0,2),_=c<1?[]:Rt(0,c,a),d=_T(t.seed)((()=>{const m=u-c|0;return m<1?a:Rt(m,a.length,a)})()),l=d.idx,f=gT(d.prng)(ft(m=>m!==l,_))(Wc(1)(_.length-(en(zr)(l)(_)?1:0)|0)),h=f.idx,p=s>=2?o/(nt(s)-1):0;return v(m=>w=>{const x=w===h,y=w===l,T=w===0||w===(s-1|0),C=cT(m.prng)(T)(y)(x)(r)(t),S=aT(C.prng)(T)(t)(e.h),E=uT(S.prng)(T)(t)(p);return{prng:E.prng,circles:St(m.circles)({cx:e.x+oT(C.r)(e.w-C.r)((s>=2?r+nt(w)/(nt(s)-1)*o+E.dx:r+0*o+E.dx)+(y?t.heroShift*p:x?-1*t.smallShift*p:0)),cy:n-S.yLift,r:C.r})}})({prng:f.prng,circles:[]})(Xt(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?yd(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?yd(o)(t[i]):{x:o.cx+o.r,y:e}})()}))(t)},bd=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]},dT=t=>e=>n=>{const r=so(e.y-t.cy)(e.x-t.cx),o=so(n.y-t.cy)(n.x-t.cx),i=o>r?o-r:o+6.283185307179586-r,s=Wc(1)(fe(xs(i/1.5707963267948966))),a=i/nt(s),u=1.3333333333333333*M0(a/4);return Et(Xt(0,s-1|0))(c=>{const _=r+nt(c+1|0)*a,d=t.cx+t.r*Sn(_),l=t.cy+t.r*pn(_),f=r+nt(c)*a;return[4,t.cx+t.r*Sn(f)-u*t.r*pn(f),t.cy+t.r*pn(f)+u*t.r*Sn(f),d+u*t.r*pn(_),l-u*t.r*Sn(_),d,l]})},kd=t=>e=>{const n=t.h*.38,r=Cd(Td(Nd)({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,...Et(r)(i=>dT(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]:di(t)(e)},lT=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=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==="Diamond"){const s=bd(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=xd(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=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==="Cloud"){const s=kd(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)},hT={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",di(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",di(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",di(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=>Uv(t)(e),insideTokenStyle:t=>tt(ut("Return",Oc),_t),Monad0:()=>Rc},pT=t=>()=>t.clip("evenodd"),mT=t=>e=>()=>{t.filter=`blur(${e}px)`},yT=t=>e=>()=>{const n=e>0?t.canvas.width/e:1;t.setTransform(n,0,0,n,0,0)},xT=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)},wT=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()},qc=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Hc=t=>e=>n=>{const r=e.stroke;return()=>{const o=r.value,i=sm(t)(n);if(o!==n)return i(),e.stroke.value=n}},JT=t=>e=>n=>{const r=e.font;return()=>{const o=r.value,i=hm(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=im(t)(n);if(o!==n)return i(),e.fill.value=n}},ha=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=Si(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=Li(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=mm(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=L_(t);return()=>(o(),r(0)())},NT=t=>e=>n=>r=>o=>i=>{const s=qc(i)(qc(r/2)(o/2)),a=E_(t)(e+s)(n);return()=>(a(),Si(t)(e+r-s)(n)(),Li(t)({cpx:e+r,cpy:n,x:e+r,y:n+s})(),Si(t)(e+r)(n+o-s)(),Li(t)({cpx:e+r,cpy:n+o,x:e+r-s,y:n+o})(),Si(t)(e+s)(n+o)(),Li(t)({cpx:e,cpy:n+o,x:e,y:n+o-s})(),Si(t)(e)(n+s)(),Li(t)({cpx:e,cpy:n,x:e+s,y:n})(),G_(t)())},vT=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),Sd=t=>e=>{const n=_m(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=vT();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0},groupAlpha:{value:1},alphaSaves:{value:[]}}}},TT={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},CT=t=>ie(t.weight)+" "+ro(t.size)+"px "+t.family,_r=t=>{const e=ro(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+")"},bT=t=>e=>n=>r=>{const o=nr(t);return()=>(o(),yT(t)(e.width)(),os(t)(n)(_r(r))(),gm(t)({x:0,y:0,width:e.width,height:e.height})(),rr(t)(),n.font.value="",n.fill.value="",n.stroke.value="")},kT=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",wT(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:_r(n.bgColor),dotCss:_r(n.dotColor),tile:n.tile,dotR:n.dotRadius,ox:n.origin.x,oy:n.origin.y})())},ST=t=>e=>n=>r=>{const o=os(t)(e)(_r(r));return()=>(o(),ha(t)(n)(),vu(t)())},LT=t=>e=>n=>r=>o=>{const i=os(t)(e)(_r(r));return()=>(i(),Hc(t)(e)(_r(o.color))(),xu(t)(o.width)(),Bu(t)((()=>{if(o.lineJoin==="RoundJoin")return Su;if(o.lineJoin==="BevelJoin")return ku;if(o.lineJoin==="MiterJoin")return Lu;g()})())(),Du(t)((()=>{if(o.lineCap==="ButtCap")return Pu;if(o.lineCap==="RoundCap")return Eu;if(o.lineCap==="SquareCap")return Gu;g()})())(),ha(t)(n)(),vu(t)(),Nu(t)())},ET=t=>e=>n=>r=>o=>i=>{const s=L_(t);return()=>{if(s(),NT(t)(n.x)(n.y)(n.w)(n.h)(r)(),o.tag==="Just"?(os(t)(e)(_r(o._1.color))(),vu(t)()):o.tag==="Nothing"||g(),i.tag==="Just")return Hc(t)(e)(_r(i._1.color))(),xu(t)(i._1.width)(),Bu(t)((()=>{if(i._1.lineJoin==="RoundJoin")return Su;if(i._1.lineJoin==="BevelJoin")return ku;if(i._1.lineJoin==="MiterJoin")return Lu;g()})())(),Du(t)((()=>{if(i._1.lineCap==="ButtCap")return Pu;if(i._1.lineCap==="RoundCap")return Eu;if(i._1.lineCap==="SquareCap")return Gu;g()})())(),Nu(t)();i.tag!=="Nothing"&&g()}},GT=t=>e=>n=>r=>{const o=Hc(t)(e)(_r(r.color));return()=>(o(),xu(t)(r.width)(),Bu(t)((()=>{if(r.lineJoin==="RoundJoin")return Su;if(r.lineJoin==="BevelJoin")return ku;if(r.lineJoin==="MiterJoin")return Lu;g()})())(),Du(t)((()=>{if(r.lineCap==="ButtCap")return Pu;if(r.lineCap==="RoundCap")return Eu;if(r.lineCap==="SquareCap")return Gu;g()})())(),ha(t)(n)(),Nu(t)())},Ld=t=>e=>n=>{const r=os(t)(e)(_r(n.color));return()=>(r(),JT(t)(e)(CT(n.font))(),Sm(t)((()=>{if(n.align==="AlignLeft")return Nm;if(n.align==="AlignCenter")return Tm;if(n.align==="AlignRight")return vm;g()})())(),km(t)((()=>{if(n.baseline==="BaselineTop")return ym;if(n.baseline==="BaselineMiddle")return xm;if(n.baseline==="BaselineAlphabetic")return wm;if(n.baseline==="BaselineBottom")return Jm;g()})())(),pm(t)(n.content)(n.x)(n.y)())},Ed={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),s=o();return i(s)}},Functor0:()=>TT},PT={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>Ed},BT=t=>e=>n=>{const r=qc(e.width/n.vw)(e.height/n.vh);return xT(t)(e.width)(r)((e.width-n.vw*r)/2-n.vx*r)((e.height-n.vh*r)/2-n.vy*r)},DT={pure:t=>e=>()=>t,Apply0:()=>Ed},Gd={Applicative0:()=>DT,Bind1:()=>PT},$c={fillPath:t=>e=>n=>{const r=ST(n.ctx)(n.styleCache)(t)(e.color),o=n.maskDepth;return()=>{if(o.value===0)return r()}},strokePath:t=>e=>n=>{const r=GT(n.ctx)(n.styleCache)(t)(e),o=n.maskDepth;return()=>{if(o.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const o=LT(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=ET(o.ctx)(o.styleCache)(t)(e)(n)(r),s=o.maskDepth;return()=>{if(s.value===0)return i()}},drawText:t=>e=>{const n=Ld(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=nr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",fm(n.ctx)(t)(),Ld(n.ctx)(n.styleCache)(e)(),rr(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=nr(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})(),vs(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=rr(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=nr(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})(),vs(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=rr(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=nr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",ha(n.ctx)(t)(),e==="NonZero")return cm(n.ctx)();if(e==="EvenOdd")return pT(n.ctx)();g()}}},popClip:t=>{const e=rr(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=nr(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)(Cm)();if(t==="Difference")return D_(e.ctx)(bm)();g()}}},popBlend:t=>{const e=rr(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=nr(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,um(e.ctx)(s)()}}},popAlpha:t=>{const e=rr(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=Nr(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=nr(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=mT(e.ctx)(t);if(t>=.01)return o()}}},popBlur:t=>{const e=rr(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=BT(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=bT(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=kT(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=Ic(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Fc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Oc,Monad0:()=>Gd},RT=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},li=t=>e=>n=>{const r=RT(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},Vc=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()},AT=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:Vc(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()},hi=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)(Vc(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:Ri(8)(.6)(Vc(1-t._1))};g()};function IT(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function FT(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:IT(o,i)}}return n}function QT(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 Pd(t,e){if(e.length===0)return[];const n=FT(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]=QT(n,e,i*r/t);return o}function zT(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 MT(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 zT(r,e)}const Bd=t=>e=>n=>{const r=Pd(t,e),o=Pd(t,n),i=MT(r,o);return{from:r,to:i}};function Dd(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 WT(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 OT(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 qT(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=Dd(e),s=Dd(n),a=WT(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),x=qT((t-m)/w),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=OT(.5,l);return l},Ad=(t,e)=>({tag:t,_1:e}),Id=(t,e)=>({tag:t,_1:e}),be=(t,e,n)=>({tag:t,_1:e,_2:n}),Fd=t=>t,Uc=(t,e)=>({tag:t,_1:e}),Kc=(t,e)=>({tag:t,_1:e}),Yc=t=>t,pa=(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}),Qd=(t,e)=>({tag:t,_1:e}),zd=t=>t,Md=(t,e)=>({tag:t,_1:e}),Jo=(t,e,n)=>({tag:t,_1:e,_2:n}),Wd=t=>t,HT=t=>t,pi=Wd("NormalTransform"),$T=Wd("BakedTransform"),Od=zd("TokenOutside"),qd=zd("TokenInside"),ma=is("PlainText"),Hd=wo("FrameTitle"),VT=wo("Watermark"),UT=Yc("NodeShadow"),$d=Yc("NodeBody"),KT=Yc("NodeInversion"),Xc=Fd("LabelsShown"),jc=Fd("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()}},Vd=t=>e=>ts(t)(e),YT=t=>{const e=t.Bind1().Apply0().Functor0(),n=qv(t);return r=>o=>n(Wv()()()({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,HT),map:On.map},e=>tt(ut("Return",e),_t)),_t),Ud=t=>tt(ut("Bind",{type:"scene",value:ke("Background",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),Kd=t=>tt(ut("Bind",{type:"scene",value:ke("Edge",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),Zc=t=>tt(ut("Bind",{type:"scene",value:ke("Node",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),ya=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),Yd=t=>tt(ut("Bind",{type:"scene",value:ke("Token",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),jT=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,kt("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,kt("Cons",at("CatCons",n,st($,$)),e._2._2._2)));g()})())},st($,$))),fr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Xd=v(er)(0),jd=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()},ZT=v(t=>e=>t+e.len)(0),Zd=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,...Et(Rt(1,t.length,t))(n=>[2,n.x,n.y]),5];g()},tl=t=>e=>{const n=fr(e)(fr(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},t3=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,...Et(e._1.tail)(n=>[2,n.x,n.y])];g()},tg=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 wd(e);if(t.shape==="Diamond")return bd(e);if(t.shape==="Ellipse")return xd(e);if(t.shape==="Document")return Jd(e);if(t.shape==="Cloud")return kd(e)(7);if(t.shape==="Rectangle")return tl(e)(7);g()},Ge=t=>e=>n=>q(r=>{const o=nt(r)/nt(n);return{x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o}})(Xt(0,n-1|0)),e3=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=fr(t)(fr(e.w/2)(e.h/2));return{...e,x:e.x+n,y:e.y+n,w:e.w-2*n,h:e.h-2*n}},eg=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return $e(r*r+n*n)},n3=t=>Fe(e=>n=>({a:e,b:n,len:eg(e)(n)}),t,Rt(1,t.length,t)),r3=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,...Et(Xt(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=eg(h)(_._1),m=eg(f._1)(h),w=fr(t)(p/2),x=fr(t)(m/2),y=p>0?w/p:0,T=h.x+(_._1.x-h.x)*y,C=h.y+(_._1.y-h.y)*y,S=m>0?x/m:0,E=h.x+(f._1.x-h.x)*S,B=h.y+(f._1.y-h.y)*S;return q(M=>{const Y=nt(M)/nt(10),R=1-Y;return{x:R*R*E+2*R*Y*h.x+Y*Y*T,y:R*R*B+2*R*Y*h.y+Y*Y*C}})(Xt(0,10))}return[]}),...o]},o3=t=>e=>n=>r=>o=>q(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}})(Xt(0,o-1|0)),i3=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),...o3({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)],el=t=>e=>q(n=>{const r=6.283185307179586*nt(n)/nt(64);return{x:t.x+e*Sn(r),y:t.y+e*pn(r)}})(Xt(0,63)),nl=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]},s3=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)]},ng=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:Xd(q(n=>n.x)(t))/nt(e),y:Xd(q(n=>n.y)(t))/nt(e)}},xa=t=>e=>n=>r=>o=>q(i=>{const s=n+(r-n)*(nt(i)/nt(o));return{x:t.x+e*Sn(s),y:t.y+e*pn(s)}})(Xt(0,o-1|0)),rg=t=>e=>{const n=fr(t)(fr(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),...xa({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),...xa({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),...xa({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),...xa({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},wa=t=>e=>n=>r=>o=>i=>q(s=>{const a=r+(o-r)*(nt(s)/nt(i));return{x:t.x+e*Sn(a),y:t.y+n*pn(a)}})(Xt(0,i-1|0)),a3=t=>{const e=t.h*.38;return[...Et(Cd(Td(Nd)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=so(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),o=so(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return wa({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)]},u3=t=>{const e=fr(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,o=t.y+t.h+5-e-2,i=t.x+n;return[...wa({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),...wa({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"?u3(e):e.shape==="Parallelogram"?e3(e):e.shape==="Diamond"?s3(e):e.shape==="Ellipse"?rg(Jn(e.w)(e.h)/2)(e):e.shape==="Document"?i3(e):e.shape==="Cloud"?a3(e):rg(t)(e),c3=t=>{const e=fr(t.h*.075)(t.w*.075),n=t.w/2;return wa({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},g3=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})()})()?St(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,_3=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=n3(t),i=ZT(o),s=jd(0)(i)(e*i),a=jd(0)(i)(n*i);return a<=s?[]:g3(o)(s)(a)}g()},f3=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},d3=t=>e=>n=>{const r=Pt(o=>i=>ot.compare(o.t)(i.t))(vt(o=>{const i=f3(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(Rn,t,[...Rt(1,t.length,t),...Rt(0,1,t)])));return 0<r.length?N("Just",r[0].p):J},rl=t=>e=>{const n=Nr(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=d3(t)(n._1.init[r])(n._1.last);if(o.tag==="Just")return St(n._1.init)(o._1);if(o.tag==="Nothing")return e;g()}return e}g()},jr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},og=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},l3=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()},h3=t=>e=>{const n=jr(0)(t.y+4-e.y)+jr(0)(e.y+e.h-(t.y+t.h-4)),r=jr(0)(t.x+4-e.x)+jr(0)(e.x+e.w-(t.x+t.w-4));return r*e.h+n*e.w+r*n},p3=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(jr)(0)(q(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?og((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}},m3=t=>e=>{const n=og(t.x+t.w)(e.x+e.w)-jr(t.x)(e.x),r=og(t.y+t.h)(e.y+e.h)-jr(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},ol=t=>e=>n=>r=>{const o=t+4,i=jr(0)(e-8),s=o+i-n;return n<=i?l3(o)(s)(r):t+(e-n)/2},ig=t=>e=>({...e,x:ol(t.x)(t.w)(e.w)(e.x),y:ol(t.y)(t.h)(e.h)(e.y)}),y3=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}]},x3=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*h3(t)(o)+1e4*v(c=>_=>c+m3(o)(_))(0)(e)+.05*(u*u+s*s)+.01*(a*a+i*i)})()+(o.y>n.token.y?100:0)},w3=t=>e=>n=>r=>{const o=s=>{const a=ig(t)(s);return{rect:a,score:x3(t)(e)(n)(r)(a)}},i=Ft(s=>J,s=>a=>N("Just",{head:s,tail:a}),[r,n.rect,...y3(n)]);if(i.tag==="Nothing")return ig(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()},J3=t=>e=>n=>v(r=>o=>{const i=p3(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:w3(t)(r.obstacles)(o)(i);return{acc:rt(P)(o.id)(s)(r.acc),obstacles:St(r.obstacles)(s)}})({acc:I,obstacles:e})(n).acc,sg=t=>t,Br=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},vo=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},N3=Io(fu)(Mt),v3=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},T3=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},il=sg("SegMove"),C3=sg("SegLine"),b3=sg("SegQuad"),sl={offset:.4,passes:1,rMax:1.5},al=t=>fe(An(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,Ja=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},Na=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},Dr=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},us=(()=>{const t=v(e=>n=>((e*31|0)+fe(An(n.x*100))|0)+fe(An(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),k3=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:il,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:C3,m:i,c:i,p:a,len:$e(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:b3,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:$e(u*u+c*c)*1.05}),r=a,n=o+5|0;continue}if(s._1===5){e.push({kind:il,m:i,c:i,p:i,len:0}),n=o+1|0;continue}n=t.length;continue}g()}return e},S3=t=>e=>{const n=e.length-1|0,r=n<1?[]:Rt(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=$e(a*a+s*s);return u<=1e-4?e:St((()=>{const c=e.length-1|0;return c<1?[]:Rt(0,c,e)})())({x:e[i].x+a/u*t,y:e[i].y+s/u*t})}return e},L3=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*Sn(s.value),y:o.y+i.value*pn(s.value)},...r.out]}})({prng:e,out:[]})(n).out),E3=t=>e=>n=>{if(e.kind==="SegMove")return Na(t)(e.p);if(e.kind==="SegLine")return Dr(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 Dr(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});g()},G3=t=>e=>{if(e.kind==="SegMove")return Na(t)(e.p);if(e.kind==="SegLine")return Dr(t)(e.p);if(e.kind==="SegQuad")return Ja(t)(e.c)(e.p);g()},ul=t=>e=>{const n=k3(e),r=v(a=>u=>a+u.len)(0)(n)*Br(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];G3(o)(c)(),i=u+c.len,s=a+1|0;continue}if(u>=r){s=n.length;continue}E3(o)(n[a])((r-u)/Br(n[a].len)(1e-4))()}s=n.length}return o},cl={offset:1.5,passes:2,rMax:14,overshoot:2.5},gl=t=>e=>n=>r=>{const o=r.y-n.y,i=n.y-e.y,s=r.x-n.x,a=$e(s*s+o*o),u=n.x-e.x,c=$e(u*u+i*i),_=vo(t.rMax*(Q0(c>0&&a>0?Br(-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}},_l=t=>e=>{const n=e.length,r=[],o=0<e.length?N("Just",e[0]):J;if(o.tag==="Just"?Na(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 _=gl(t)(e[c])(e[a])(e[u]);Dr(r)(_.inP)(),Ja(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&&Dr(r)(e[i])(),r},P3=t=>e=>n=>r=>o=>{if(o.length<4)return _l(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=Wr(Wr(e)(a)+a|0)(a),c=f=>{const h=Wr(f+a|0)(a);return h>=0&&h<o.length?o[h]:s},_=q(f=>gl(t)(c((u+f|0)-1|0))(c(u+f|0))(c((u+f|0)+1|0)))(Xt(0,a-1|0)),d=[],l=0<_.length?N("Just",_[0]):J;if(l.tag==="Just")if(Na(d)(l._1.outP)(),N3((()=>{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=Dr(d)(f.inP);return()=>(h(),Ja(d)(f.curr)(f.outP)())})(),n)Dr(d)(l._1.inP)(),Ja(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const f=_.length-1|0;f>=0&&f<_.length?Dr(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}})())():Dr(d)(l._1.inP)()}else l.tag==="Nothing"||g();return d},mi=t=>e=>n=>r=>{const o=v3(1)(r.length-1|0),i=Ee(0)(nt(o))(Mc("shape")(e)),s=T3(o-1|0)(fe(An(i.value))),a=i.prng;return q(u=>{const c=Ee(0)(1)(Mc(ie(u))(a)),_=Ee(-.18)(.3)(c.prng),d=c.value<.7,l=Ee(.5)(.85)(_.prng),f=L3(t.offset)(l.prng)(r);return{path:n?P3(t)(s)(d)(_.value)(f):_l(t)(f),alpha:l.value}})(Xt(0,t.passes-1|0))},B3=t=>e=>n=>mi(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}]),D3=t=>e=>n=>{const r=Br(0)(vo(1)(n)),o=e.h/nt(4),i=Br(6)(o*1.4);return vt(s=>s)(q(s=>{if(r<Br(0)(nt(s)/nt(4)-.05))return J;const a=Mc(ie(s))(t),u=Br(0)(nt(s)/nt(4)-.05),c=Wr(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:ul(Br(0)(vo(1)((r-u)/Br(1e-4)(vo(1)(nt(s+1|0)/nt(4)+.05)-u))))((()=>{const f={rMax:2,offset:.6,passes:1},h=se(v(m=>w=>{const x=Ee(-o*.08)(o*.08)(m.prng);return{prng:x.prng,out:[{x:_+(d-_)*(nt(w)/nt(4)),y:l+x.value},...m.out]}})({prng:a,out:[]})(Xt(0,4)).out),p=h.length<2?[]:mi(f)(a)(!1)(h);return 0<p.length?p[0].path:[]})()),width:i,alpha:1})})(Xt(0,3)))},ag=(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(Fn);return e=>t(rn("IterNode",e,In))})(),dr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},To=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Rr=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},R3=Mt.foldMap(tm),Ta=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fl=ce(P)(Mt),dl=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},A3=N_(P),I3=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},Co=t=>{const e=t.Apply0();return n=>v(r=>o=>e.apply(e.Functor0().map(i=>i_)(r))(n(o)))(t.pure())},Ar=Co(xo),ll=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=li(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=Bd(128)(No(4)(as(2)(e)))(el(_)(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,x=2*(()=>{const j=f.y-s.y;return(w<0?-w:w)+(j<0?-j:j)})(),y=m+Bi(t)+x,T=y<=1e-4?1:1-x/y,C=y<=1e-4?0:m/y,S=T-C,E=Bd(128)(el(f)(6))(No(4)(as(2)(n))),B={maxDelay:.4,smoothPasses:2},M=go(t)(va(0)(1)(S<=1e-4?0:(u-C)/S)),Y=(()=>{if(M.tag==="Just")return M._1;if(M.tag==="Nothing")return _;g()})(),R=(()=>{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(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?Jo("PolyShape",Rd(A)(h.from)(h.to)(B)):u>=T?Jo("PolyShape",Rd(R)(E.from)(E.to)(B)):Jo("CircleShape",Y,6)},ug=t=>e=>n=>r=>o=>i=>{const s=ll(t)(e)(n)(r)(o)(i);if(s.tag==="PolyShape")return ng(s._1);if(s.tag==="CircleShape")return s._1;g()},cg=(()=>{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:Pr,nodeFill:ye,nodeStroke:Pr,text:Pr,edge:Pr,arrowFill:Pr,tokenOutsideFill:Pr,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:la,tokenInsideAlpha:1,chipPillFill:Pr,chipPillText:ye,chipHairline:{r:26,g:26,b:26,a:90},trailDot:Pr,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:Pr,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:ye,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:la,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:hd,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:hd,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:la,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()}})(),gg=t=>e=>Et(Ze(t.nodes))(n=>{const r=Pe(n._1)(e.nodes);return r.tag==="Just"&&hi(r._1).alpha>0?tg(n._2):[]}),F3=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,...gg(e)(n)],Q3=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=oo.traverse(r);return i=>s=>{const a=vr(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})))))(Xt(0,a.length-1|0))}},z3=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 q(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])},_g=t=>{const e=Kr(`
|
|
7
|
-
`)(t);return
|
|
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,x=Zc({id:a,role:t,geometry:Uc("FlatNode",{shape:u.shape,bounds:{x:u.x,y:u.y,w:u.w,h:u.h}}),alpha:o,plan:Kc("FlatNodePlan",{palette:r,label:u.label,labelVisibility:e,inkBoost:n,labelAlpha:i,arrival:s,animState:c})}),y=()=>{if(e==="LabelsHidden")return tt(ut("Return",void 0),_t);if(e==="LabelsShown"){const T=je({path:[],role:dn,layer:J,effects:[be("GroupAlpha",d.alpha*o),be("GroupTransform",pi,m),be("GroupAlpha",i)]})(Ar(C=>ss({owner:wo("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:Gr,baseline:En},bounds:J,plan:ma}))(Ht(Rn)(f)));return i>0&&d.alpha*o>0?T:tt(ut("Return",void 0),_t)}g()};return tt(x._1,(()=>{if(x._2.tag==="CatNil")return at("CatCons",y,st($,$));if(x._2.tag==="CatCons")return at("CatCons",x._2._1,st(x._2._2._1,kt("Cons",at("CatCons",y,st($,$)),x._2._2._2)));g()})())},O3=t=>e=>n=>r=>o=>i=>s=>hl(o)(i)(s)({owner:wo("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:Gr,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:Ve,lineCap:Gn},leader:[1,i.x,o.y+o.h,2,r.x+r.w/2,r.y]})}),q3={offset:.8,passes:2,rMax:5},dg=t=>e=>n=>r=>je({path:[],role:dn,layer:N("Just",Xv),effects:[be("GroupClip",F3(e)(n)(r),eT)]})(fg(Od)(!1)(t.wobble)(n)(r)(t.tokenOutsideFill)(t.tokenOutsideStroke)),ml=t=>e=>n=>r=>{if(e.tokenInsideBlend==="Difference"){const o=XT(t),i=s=>{const a=je({path:[],role:dn,layer:N("Just",jv),effects:[be("GroupBlend",la),be("GroupClip",gg(n)(r),ns)]})(fg(qd)(s==="ConvexAbsorb")(e.wobble)(n)(r)(e.tokenInside)(e.tokenInsideStroke)),u=()=>je({path:[],role:dn,layer:N("Just",Zv),effects:[]})(Ar(c=>{const _=Pe(c._1)(r.nodes);return _.tag==="Just"&&hi(_._1).alpha>0?ya(pa("FloorOverlay",{path:tg(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,kt("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,kt("Cons",at("CatCons",i,st($,$)),o._2._2._2)));g()})())}if(e.tokenInsideBlend==="Normal")return je({path:[],role:dn,layer:J,effects:[be("GroupClip",gg(n)(r),ns),be("GroupAlpha",e.tokenInsideAlpha)]})(fg(qd)(!1)(e.wobble)(n)(r)(e.tokenInside)(e.tokenInsideStroke));g()},yl=t=>e=>n=>r=>t.strokePath((()=>{const o=Ft(i=>J,i=>s=>N("Just",{head:i,tail:s}),q(i=>i.pt)(B0(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+Sn(l)*d+_.value*n,y:e.y+pn(l)*d+_.value*n}}},{prng:137,pt:{x:e.x,y:e.y}},Xt(0,72))));if(o.tag==="Just")return[1,o._1.head.x,o._1.head.y,...R3(i=>[2,i.x,i.y])(o._1.tail)];if(o.tag==="Nothing")return[];g()})())({color:r,width:5.5,lineJoin:Ve,lineCap:Vn}),H3=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?yl(t)(n.geometry._1._1)(n.geometry._1._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(nl(n.geometry._1._1)(n.geometry._1._2))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:Ve,lineCap:Gn});if(n.geometry._1.tag==="PolyShape")return n.plan._1.wobble&&n.geometry._1._1.length>=3?yl(t)(ng(n.geometry._1._1))(6)({r:200,g:35,b:30,a:220}):n.geometry._1._1.length>=3?t.fillStrokePath(Zd(n.geometry._1._1))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:Ve,lineCap:Gn}):e.pure();g()}return e.pure()}},$3=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=hi(_),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(tl(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:Ve,lineCap:Gn})))(()=>r.bind(i)(()=>s))))));return d.alpha>0&&!a.wobble?p:n.pure()}},xl=t=>e=>n=>r=>Ar(o=>{const i=Pe(o._1)(r.nodes);if(i.tag==="Just")return Zc({id:o._1,role:UT,geometry:Uc("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:Kc("FlatNodePlan",{palette:t,label:o._2.label,labelVisibility:jc,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)),wl=t=>e=>n=>{const r={...t,nodeFill:t.text,text:t.nodeFill,nodeStroke:t.nodeFill};return Ar(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)]})(pl(KT)(Xc)(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))},V3=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=Co(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:Ve,lineCap:Vn}))(()=>r)))(D3(al(s)+7777|0)(s)(a))},U3=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=e.Applicative0(),i=Co(o),s=t.popClip,a=Co(o),u=oo.traverse(o),c=Q3(t),_=V3(t),d=t.popTransform;return l=>f=>h=>p=>m=>w=>x=>y=>T=>{const C=F=>n.bind(t.pushAlpha(F.alpha))(()=>n.bind(t.strokePath(F.path)({color:h.nodeStroke,width:2,lineJoin:Ve,lineCap:Vn}))(()=>r)),S={family:h.fontFamily,size:h.wobble?15:11,weight:h.wobble?800:500},E=Kr(`
|
|
9
|
-
`)(y.label===""?x:y.label),B=E.length===0?[""]:E,M=S.size*1.2,Y=y.shape==="Cylinder"?t.strokePath(fT({x:y.x,y:y.y,w:y.w,h:y.h}))({color:h.nodeStroke,width:1.25,lineJoin:Ve,lineCap:Gn}):o.pure(),R=(y.shape==="Cylinder"?(y.y+(y.y+y.h+5-2*Jn(y.h*.075)(y.w*.075)))/2:(y.y+y.y+y.h)/2)-nt(B.length)*M/2+M/2,A=T.tag==="PloppingOut"&&h.wobble?T._1:-1,j=A>=0,Z=hi(T),z=j?{alpha:1,scale:1}:Z,W=y.x+y.w/2,H=y.y+y.h/2,D=n.bind(t.pushAlpha(z.alpha*p))(()=>n.bind(t.pushTransform({tx:W*(1-z.scale),ty:H*(1-z.scale),sx:z.scale,sy:z.scale}))(()=>{const F={x:y.x,y:y.y,w:y.w,h:y.h},L={color:h.nodeStroke,width:h.wobble?2:1.25*f,lineJoin:Ve,lineCap:h.wobble?Vn:Gn};return n.bind((()=>{if(h.wobble){if(y.shape==="Rectangle")return i(C)(B3(cl)(al(F))(F));const G=No(7)(y);return n.bind(i(C)((()=>{const Q=us(G);return G.length<4?[]:mi(sl)(Q)(!0)(G)})()))(()=>a(Q=>i(C)((()=>{const V=us(Q);return Q.length<2?[]:mi(sl)(V)(!1)(Q)})()))(y.shape==="Cylinder"?[c3(y)]:[]))}return n.bind(lT(t)(y.shape)(F)(7)(N("Just",{color:h.nodeFill,flat:!1}))(N("Just",L)))(()=>Y)})())(()=>n.bind((()=>{if(w.tag==="Just"&&h.wobble&&!j){const G=w._1;return n.bind(u(c(S))(B))(Q=>{const V=Pt(dt=>ht=>ot.compare(dt.x)(ht.x)),K=fe(An(y.x*7919+y.y*3001))*-1640531535|0,U=Ee(5)(7.5)(K),O=Ee(0)(U.value)(U.prng),X=-(1+2*Ee(-1)(1)(O.prng).value*3.141592653589793/180),et=(dt,ht,Lt,Bt,zt)=>V(vt(ne=>ne)([X*ht+dt>=Bt&&X*ht+dt<=zt?N("Just",{x:ht,y:X*ht+dt}):J,X*Lt+dt>=Bt&&X*Lt+dt<=zt?N("Just",{x:Lt,y:X*Lt+dt}):J,(()=>{const ne=(Bt-dt)/X;return ne>=ht&&ne<=Lt?N("Just",{x:ne,y:Bt}):J})(),(()=>{const ne=(zt-dt)/X;return ne>=ht&&ne<=Lt?N("Just",{x:ne,y:zt}):J})()])),lt=U.value,bt=Wr(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},Tt=y.x+y.w/2,Gt=hn(Ht(dt=>ht=>Ht((()=>{const Lt=R+nt(dt)*M,Bt=Tt-v(zt=>ne=>zt+ne.w)(0)(ht)/2;return zt=>ne=>{const Cn=S.size*.1,Me=zt-1|0,qt=Me>=0&&Me<ht.length&&zt>0?(ht[Me].x+ht[Me].w+ne.x)/2:ne.x-Cn;return{x:Bt+qt-1,y:Lt-ne.up-1,w:dr(0)((()=>{const Ot=zt+1|0;return Ot>=0&&Ot<ht.length&&zt<(ht.length-1|0)?(ne.x+ne.w+ht[Ot].x)/2-qt:ne.x+ne.w+Cn-qt})())+2,h:ne.up+ne.down+2}}})())(ht))(Q)),jt=y.y+4,Ct=y.x+y.w-4,Yt=y.x+4,Dt=jt-X*Yt+O.value,wt=y.y+y.h-4,mt=Et(Et(Ht(dt=>ht=>{const Lt=(ht.from.x+ht.to.x)/2,Bt=(ht.from.y+ht.to.y)/2,zt=Ee(-1)(1)(K+(911*(dt+1|0)|0)|0),ne=Ee(-3)(5)(zt.prng),Cn=zt.value*3.141592653589793/180,Me=Sn(Cn),qt=pn(Cn),Ot=We=>({x:Lt+(We.x-Lt)*Me-(We.y-Bt)*qt,y:Bt+(We.x-Lt)*qt+(We.y-Bt)*Me});return{from:(()=>{const We=Ot(ht.from),bn=We.y-Bt,tn=We.x-Lt,_n=$e(tn*tn+bn*bn),Ae=_n<1e-4?1:(_n+ne.value)/_n;return{x:Lt+tn*Ae,y:Bt+bn*Ae}})(),to:(()=>{const We=Ot(ht.to),bn=Ee(-3)(5)(ne.prng).value,tn=We.y-Bt,_n=We.x-Lt,Ae=$e(_n*_n+tn*tn),oe=Ae<1e-4?1:(Ae+bn)/Ae;return{x:Lt+_n*oe,y:Bt+tn*oe}})()}})(vt(dt=>{const ht=et(Dt+nt(dt)*lt,Yt,Ct,jt,wt);return ht.length===2?N("Just",{from:ht[0],to:ht[1]}):J})(Xt(0,Ta(1)(fe(An((wt-X*Ct-Dt)/lt)))))))(dt=>ft(ht=>ht.to.x-ht.from.x>1,v(ht=>Lt=>Et(ht)(Bt=>{const zt=et(Bt.from.y-X*Bt.from.x,Lt.x,Lt.x+Lt.w,Lt.y,Lt.y+Lt.h);return zt.length===2?zt[0].x>Bt.from.x+.001&&zt[1].x<Bt.to.x-.001?[{from:Bt.from,to:zt[0]},{from:zt[1],to:Bt.to}]:zt[0].x<=Bt.from.x+.001&&zt[1].x<Bt.to.x-.001?[{from:zt[1],to:Bt.to}]:zt[0].x>Bt.from.x+.001&&zt[1].x>=Bt.to.x-.001?[{from:Bt.from,to:zt[0]}]:[]:[Bt]}))([dt])(Gt))))(dt=>(()=>{const ht=dt.to.x-dt.from.x;return $e(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=>dr(0)(To(1)(G.t*nt(ct)-nt(dt)));return n.bind(t.pushClip(Zd(No(7)(y)))(ns))(()=>n.bind(i(dt=>{const ht=dt._1,Lt=Ee(1.4)(1.9)(K+(1303*(ht+1|0)|0)|0),Bt=Ee(.35)(.8)(Lt.prng),zt=i(ne=>n.bind(t.pushAlpha(ne.alpha*Bt.value))(()=>n.bind(t.strokePath(ul(yt(ht))(ne.path))({color:pt,width:Lt.value,lineJoin:Ve,lineCap:Vn}))(()=>r)))(mi({...cl,rMax:0,offset:.5})(K+(53*(ht+1|0)|0)|0)(!1)([dt._2.from,dt._2.to]));return yt(ht)>0?zt:o.pure()})(Ht(Rn)(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:R+nt(Q._1)*M,content:Q._2,font:S,color:h.text,align:Gr,baseline:En}))(Ht(Rn)(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 z.alpha*p>0?D:o.pure()}},K3=t=>{const e=$3(t),n=U3(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(jc)(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()}},Jl=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 Ar(o=>{const i=Rr(o._1)(n.edges);if(i.tag==="Just"){const s=Rr(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:Ad("FlatRoute",(()=>{const c=(()=>{if(0<o._2.length){const d=r(o._2[0]);if(d.tag==="Just")return se(rl(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 rl(No(7)(d._1))(c)}return c})()),visible:AT(i._1),arrow:(()=>{const c=ao("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:Id("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))},Y3=t=>e=>n=>{const r={family:t.fontFamily,size:11,weight:500};return Ar(o=>{if(o._2===""||(()=>{const a=Rr(o._1)(n.edges);return a.tag==="Nothing"||!(a.tag==="Just"&&dy.eq(a._1)(xf))})())return tt(ut("Return",void 0),_t);const i=Rr(o._1)(e.edges),s=(()=>{if(i.tag==="Just")return go(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:wo("EdgeText",o._1),text:o._2,spec:{x:a.x,y:a.y,content:o._2,font:r,color:t.chipPillText,align:Gr,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,kt("Cons",at("CatCons",c,st($,$)),u._2._2._2)));g()})())}g()})(Ze(e.edgeLabels))},Nl=t=>{const e=n=>{if(n.tag==="Leaf")return I;if(n.tag==="Node")return te("Node",n._1,n._2,n._3,ig({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=Co(r);return i=>s=>a=>u=>c=>_=>{const d=Yo(_).length,l=nt(d+1|0),f=m=>{const w=(a*l-nt(m))/1.5,x=w<0?0:w>1?1:w;return x*x*(3-2*x)},h=(m=>{let w=m,x=!0,y;for(;x;){const T=w;if(T>=d){x=!1,y=T;continue}if(f(T)>=1){w=T+1|0;continue}x=!1,y=T}return y})(0),p=h>=d?[]:tr(m=>f(m)>0)(Xt(h,d-1|0)).init;return n.bind((()=>{const m=t.drawText({x:u,y:c,content:Re(h)(_),font:i,color:s,align:_i,baseline:En});return h>0?m:r.pure()})())(()=>o(m=>n.bind(t.measureText(i)(Re(m)(_)))(w=>{const x=f(m);return t.drawText({x:u+w,y:c-(1-x)*10,content:Re(1)($o(or(Re(m)(_)))(_)),font:i,color:{...s,a:fe(An(x*nt(s.a)))},align:_i,baseline:En})}))(p))}},vl=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=Co(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(nl(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()}},j3=t=>e=>n=>r=>o=>i=>s=>hl(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:_i,baseline:En},bounds:N("Just",r),plan:is("TokenTravelText",{trail:z3(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})()})}),Ca=t=>e=>n=>r=>{const o=q(f=>nt(Ta(1)(Yo(f).length)))(r),i=dr(1)(v(er)(0)(o)),s=li(e)(n)(t),a=s*i,u=Ta(1)(r.length),c=(f=>h=>p=>{let m=f,w=h,x=p,y=!0,T;for(;y;){const C=m,S=w,E=Ft(B=>J,B=>M=>N("Just",{head:B,tail:M}),x);if(E.tag==="Nothing"){y=!1,T=Ta(0)(u-1|0);continue}if(E.tag==="Just"){if(S+E._1.head>=a){y=!1,T=C;continue}m=C+1|0,w=S+E._1.head,x=E._1.tail;continue}g()}return T})(0)(0)(o),_=v(er)(0)(c<1?[]:Rt(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})()}},Tl=t=>e=>n=>r=>o=>t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Ca(r)(0)(0)(q(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})}),Z3=t=>{const e=t.Bind1(),n=t.Applicative0(),r=oo.traverse(n);return o=>i=>s=>e.Apply0().Functor0().map(a=>fl(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(Tl(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)))},tC=t=>e=>n=>r=>o=>i=>s=>a=>u=>{const c=ug(n)(r)(o)(i)(s)(a);return t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Ca(i)(s)(a)(Et(u)(_g)).line))(_=>t.Applicative0().pure({x:c.x+14+_/2-_/2-14,y:c.y-6-8-6.6-6,w:_+28,h:25.2}))},eC=t=>{const e=t.Bind1(),n=t.Applicative0(),r=oo.traverse(n);return o=>i=>s=>e.Apply0().Functor0().map(a=>fl(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),_=Rr(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=ug(d)(c._1)(u._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);return e.bind(tC(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)))},lg=t=>{const e=t.Bind1(),n=eC(t),r=Z3(t);return o=>i=>s=>a=>e.bind(n(o)(s)(a))(u=>e.bind(r(o)(s)(a))(c=>t.Applicative0().pure(J3({x:i.vx,y:i.vy,w:i.vw,h:i.vh})([...vt(_=>{const d=Pe(_._1)(a.nodes);return d.tag==="Just"&&hi(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,kt("Cons",d._4,_(d._6,l)));g()};return Zt(de.foldr,_(c,$))})()])(vt(_=>dl(_)(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)))})())))))},nC=lg(Rc),Cl=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})()}},ba=t=>e=>n=>r=>je({path:[],role:dn,layer:N("Just",tT),effects:[]})(Ar(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=Rr(o._2._1.edge)(e.edges),u=dl(o._1)(r);if(u.tag==="Just"&&a.tag==="Just"&&s.tag==="Just"&&i.tag==="Just")return j3(o._1)(t)(Ca(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost)(Et(o._2._1.labels)(_g)))(u._1)({x:u._1.x+u._1.w/2,y:u._1.y+u._1.h/2})(Cl(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost))(ug((()=>{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=Tl(Rc)(Vd)(s)(o._2._1.progress)(o._2._1.labels),u=c=>O3(o._1)(t)(Ca(o._2._1.progress)(0)(0)(Et(o._2._1.labels)(_g)).line)(s)(c)({x:c.x+c.w/2,y:c.y+c.h/2})(Cl(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,kt("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))),bl=t=>e=>n=>r=>{const o=nC(Vd)(e)(n)(r);return tt(o._1,(()=>{if(o._2.tag==="CatNil")return at("CatCons",i=>ba(t)(n)(r)(i),st($,$));if(o._2.tag==="CatCons")return at("CatCons",o._2._1,st(o._2._2._1,kt("Cons",at("CatCons",i=>ba(t)(n)(r)(i),st($,$)),o._2._2._2)));g()})())},rC=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>o=>{const i=o.length-1|0,s=i<1?[]:Rt(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,x=$e(w*w+m*m),y=m/x,T=-y,C=w/x,S=_._1.x+C*.875,E=_._1.y+y*.875,B=r.wobble?8.75*d.value:8.75,M=S-C*B,Y=E-y*B,R=M+T*f,A=Y+C*f,j=[1,S,E,2,M+T*4.375,Y+C*4.375,2,M-T*4.375,Y-C*4.375,5],Z=M-T*p,z=Y-C*p,W={color:r.arrowFill,width:2,lineJoin:Ve,lineCap:Vn};return x<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,R,A,2,S,E])(W))(()=>t.strokePath([1,Z,z,2,S,E])(W)):t.fillPath(j)({color:r.arrowFill,flat:!0})}return n.pure()}},oC=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=Co(n),i=t.popAlpha,s=rC(t);return a=>u=>c=>_=>d=>{const l=r3(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=_3(l)(d.lo)(f);if(h.length===0)return n.pure();const p={color:a.edge,width:a.wobble?2:.9375,lineJoin:Ve,lineCap:Vn},m=a.wobble?Ee(-10)(4)(us(h)).value:0,w=a.wobble?S3(m)(h):h;return r.bind(a.wobble?o(x=>r.bind(t.pushAlpha(x.alpha))(()=>r.bind(t.strokePath(x.path)(p))(()=>i)))((()=>{const x=us(h);return w.length<2?[]:mi(q3)(x)(!1)(w)})()):t.strokePath(t3(h))(p))(()=>{const x=s(a)(w);return u&&f>=.999?x:n.pure()})}},iC=t=>{const e=oC(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()},sC=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,Ze(t.edges))}g()},r=v(i=>s=>(i*31|0)+Ur(s)|0)(5381)(vr(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},Ze(t.edges))}g()};return v(i=>s=>{const a=s._2;return A3(u=>{if(u.tag==="Nothing")return N("Just",a);if(u.tag==="Just")return N("Just",{t:dr(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)(Et(Ze(e.tokens))(i=>{if(i._2.tag==="Filling"){const s=i._2._1.node;return[b(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):J)(Ze(t.edges));if(0<a.length){const u=a[0].length-1|0,c=u<1?[]:Rt(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?so(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=Rr(i._2._1.edge)(t.edges);if(s.tag==="Just"){const a=s._1.length-1|0,u=a<1?[]:Rt(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?so(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=Rr(i._2._1.edge)(t.edges);if(s.tag==="Just")return 1<s._1.length&&0<s._1.length?so(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[]}))},aC=t=>v(e=>n=>(e*31|0)+Ur(n)|0)(5381)(vr(t.frameTitle)),kl=t=>e=>n=>r=>o=>{const i=aC(o),s=sC(r)(o);return Ar(a=>{const u=Pe(a._1)(o.nodes);if(u.tag==="Just")return pl($d)(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"&&I3(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))},uC=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},Ll=t=>e=>t.width<=0||t.height<=0?e:Sl(t.width/t.height)(e),cC=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()},El=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()},Gl=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},hg=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;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=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},_C=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},pg=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),fC=Qr(xo)(Mt),dC=t=>e=>{const n=pn(t.angle),r=Sn(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},lC=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],mg=t=>e=>{const n=r=>cC(0)(255)(fe(Hn(nt(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},Ue=t=>e=>n=>r=>({x:(e-n)*Sn(t.angle),y:(e+n)*pn(t.angle)-r}),yg=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,...Et(e._1.tail)(n=>[2,n.x,n.y]),5];g()},hC=t=>e=>n=>{const r=n.id,o=n.np,i=Zc({id:r,role:$d,geometry:Uc("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:Kc("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:Gr,baseline:En},bounds:J,plan:is("AffineText",dC(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,kt("Cons",at("CatCons",s,st($,$)),i._2._2._2)));g()})())},pC=t=>e=>n=>r=>o=>{const i=Fe(Rn,o,Rt(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:Ad("IsoSegments",[[Ue(t)(u._1.x)(u._1.y)(0),Ue(t)(u._2.x)(u._2.y)(0)]]),visible:{lo:0,hi:1},arrow:r&&a===s,settlingAtTarget:!1,plan:Id("IsoEdgePlan",{config:t,palette:e})})}))(i)},mC=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=go(i)(El(0)(1)(li(n)(r)(e)));if(a.tag==="Nothing")return i[0];if(a.tag==="Just")return a._1;g()}const s=go(i)(El(0)(1)(li(n)(r)(e)));if(s.tag==="Nothing")return{x:0,y:0};if(s.tag==="Just")return s._1;g()},yC=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,...Et(e._1.tail)(n=>[2,n.x,n.y])];g()},xC=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=v(r=>o=>({minX:Gl(r.minX)(o.x),minY:Gl(r.minY)(o.y),maxX:hg(r.maxX)(o.x),maxY:hg(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()},wC=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(yg(a))({color:u,flat:!0})({color:i.nodeStroke,width:1,lineJoin:Ve,lineCap:Gn});return n.bind(s(o.south,mg(.66)(i.nodeFill)))(()=>n.bind(s(o.east,mg(.82)(i.nodeFill)))(()=>s(o.top,i.nodeFill)))}return e.Applicative0().pure()}},JC=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(yg(a))({color:mg(u)(i.tokenOutsideFill),flat:!0})({color:i.tokenOutsideStroke,width:1,lineJoin:Ve,lineCap:Gn});return n.bind(s(o.south,.66))(()=>n.bind(s(o.east,.82))(()=>s(o.top,1)))}return e.Applicative0().pure()}},NC={angle:.5235987755982988,boxHeight:26,transparentBg:!0},vC=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=Ue(t)(o)(i)(a),c=Ue(t)(o)(s)(a),_=Ue(t)(r)(s)(a),d=Ue(t)(o)(s)(e);return{south:[Ue(t)(r)(s)(e),d,c,_],east:[Ue(t)(o)(i)(e),d,c,u],top:[Ue(t)(r)(i)(a),u,c,_]}},TC=t=>e=>n=>r=>{const o=r._1,i=(s,a)=>({depth:a.x+a.y,draw:Yd({id:o,pass:Od,geometry:Qd("IsoCube",vC(t)(s)(a)),position:a,plan:Md("IsoTokenPlan",{config:t,palette:e,baseZ:s})})});if(r._2.tag==="Travelling"){const s=gC(r._2._1.edge)(n.edges);return s.tag==="Just"?N("Just",i(0,mC(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=_C(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},CC=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:Ue(t)(e.x)(e.y)(0),b:Ue(t)(r)(e.y)(0),c:Ue(t)(r)(n)(0),d:Ue(t)(e.x)(n)(0)},top:{a:Ue(t)(e.x)(e.y)(t.boxHeight),b:Ue(t)(r)(e.y)(t.boxHeight),c:Ue(t)(r)(n)(t.boxHeight),d:Ue(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},Pl=t=>e=>q(n=>({id:n._1,np:n._2,box:CC(t)(n._2)}))(pg(e.nodes)),bC=t=>e=>[...Et(Pl(t)(e))(lC),...(()=>{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 Et(Zt(de.foldr,n(e.edges,$)))(q(r=>Ue(t)(r.x)(r.y)(0)))})()],kC=t=>e=>n=>r=>{const o=cg(e),i=[...Et(pg(n.edges))(u=>pC(t)(o)(u._1)((()=>{const c=ao("conn:")(u._1);if(c.tag==="Just")return!1;if(c.tag==="Nothing")return!0;g()})())(u._2)),...q(u=>({depth:u.box.depth,draw:hC(t)(o)(u)}))(Pl(t)(n)),...vt(TC(t)(o)(n))(pg(r.tokens))],s=Ud({viewport:xC(bC(t)(n)),clear:N("Just",t.transparentBg?o.bgTransparent:o.bg),dots:J}),a=()=>fC(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,kt("Cons",at("CatCons",a,st($,$)),s._2._2._2)));g()})())},SC=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=hg(1e-4)($e(n*n+e*e)),o=e/r,i=n/r,s=t.to.y-o*7,a=t.to.x-i*7;return yg([t.to,{x:a-o*3,y:s+i*3},{x:a+o*3,y:s-i*3}])},LC=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Qr(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(yC(a))({color:i.edge,width:1.5,lineJoin:Ve,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?[]:Rt(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(SC({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()}},Bl=(t,e)=>({tag:t,_1:e}),ka=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},EC=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()},xg=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},GC=Io(xo)(Mt),PC=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},BC=Bl("ResolvedLabels"),DC=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()},yi=t=>e=>{const n=ka(1)(he(e.rootLayout).w),r=_o(e.rootLayout)(e.camera),o=!e.diving&&e.levels.length===1?1:EC(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 uC;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})},RC=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=xg(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()},wg=t=>e=>{const n=Ym(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}},Dl=t=>e=>t===""?tt(ut("Return",void 0),_t):ss({owner:VT,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:_i,baseline:Kv},bounds:J,plan:ma}),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 ya(pa("TitleCardOverlay",{backing:{path:di(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:Ve,lineCap:Vn})},text:{owner:Hd,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:Gr,baseline:En},bounds:N("Just",d),plan:ma}}))};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,kt("Cons",at("CatCons",i,st($,$)),o._2._2._2)));g()})())},Al=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 ya(pa("FrameTitleOverlay",{backing:N("Just",{path:di(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:Ve,lineCap:Vn})}),text:{owner:Hd,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:Gr,baseline:En},bounds:N("Just",d),plan:ma}}))};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,kt("Cons",at("CatCons",i,st($,$)),o._2._2._2)));g()})())},AC=t=>e=>n=>r=>o=>i=>s=>a=>{const u=cg(t.theme),c=(()=>{if(a.tag==="ResolvedLabels")return bl(u)(o)(i)(s);if(a.tag==="SpringLabels")return ba(u)(i)(s)(Nl(o)(a._1));g()})(),_=Ud({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=Jl(u)(i)(s),h=()=>{const p=xl(u)(t.halftoneShadows)(i)(s),m=()=>{const w=kl(Xc)(1)(u)(i)(s),x=()=>{const y=wl(u)(i)(s),T=()=>{const C=dg(u)(o)(i)(s),S=()=>{const E=ml(iT)(u)(i)(s),B=()=>{const M=()=>{const Y=Y3(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",M,st($,$));if(c._2.tag==="CatCons")return at("CatCons",c._2._1,st(c._2._2._1,kt("Cons",at("CatCons",M,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,kt("Cons",at("CatCons",B,st($,$)),E._2._2._2)));g()})())};return tt(C._1,(()=>{if(C._2.tag==="CatNil")return at("CatCons",S,st($,$));if(C._2.tag==="CatCons")return at("CatCons",C._2._1,st(C._2._2._1,kt("Cons",at("CatCons",S,st($,$)),C._2._2._2)));g()})())};return tt(y._1,(()=>{if(y._2.tag==="CatNil")return at("CatCons",T,st($,$));if(y._2.tag==="CatCons")return at("CatCons",y._2._1,st(y._2._2._1,kt("Cons",at("CatCons",T,st($,$)),y._2._2._2)));g()})())};return tt(w._1,(()=>{if(w._2.tag==="CatNil")return at("CatCons",x,st($,$));if(w._2.tag==="CatCons")return at("CatCons",w._2._1,st(w._2._2._1,kt("Cons",at("CatCons",x,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,kt("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,kt("Cons",at("CatCons",h,st($,$)),f._2._2._2)));g()})())})());if(n>0){const f=()=>{const h=Dl(t.watermark)(o),p=()=>s.staticKind==="TitleCard"?Rl(s.frameTitle)(o):Al(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,kt("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,kt("Cons",at("CatCons",f,st($,$)),l._2._2._2)));g()})())}return tt(ut("Return",void 0),at("CatCons",()=>{const f=Dl(t.watermark)(o),h=()=>s.staticKind==="TitleCard"?Rl(s.frameTitle)(o):Al(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,kt("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,kt("Cons",at("CatCons",d,st($,$)),_._2._2._2)));g()})())},Jg=t=>e=>n=>r=>GC(r.minis)(o=>{const i=Il(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=xg(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)}),Il=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=cg(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?xg(i.segment.path[l])(o.segment.layout.nodes):J,h=i.segment.placement.scale*n,p=PC(8)(ka(1)(1/(1.25*ka(1e-6)(h)))),m=11*h>=5?Xc:jc,w=wg(e.viewport)(i),x=(()=>{if(m==="LabelsHidden")return tt(ut("Return",void 0),_t);if(m==="LabelsShown")return r.tag==="Leaf"?bl(u)(w)(c)(s):ba(u)(c)(s)(Nl(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 y=je({path:i.segment.path,role:i.role,layer:J,effects:[be("GroupClip",RC(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",pi,{tx:o.segment.placement.tx,ty:o.segment.placement.ty,sx:o.segment.placement.scale,sy:o.segment.placement.scale})]})(ya(pa("FloorOverlay",{path:tg({...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()})(),S=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",pi,a)]})((()=>{const Y=Jl(u)(c)(s),R=()=>{const A=xl(u)(t.halftoneShadows)(c)(s),j=()=>{const Z=kl(m)(p)(u)(c)(s),z=()=>{const W=wl(u)(c)(s);return tt(W._1,(()=>{if(W._2.tag==="CatNil")return at("CatCons",()=>dg(u)(d)(c)(s),st($,$));if(W._2.tag==="CatCons")return at("CatCons",W._2._1,st(W._2._2._1,kt("Cons",at("CatCons",()=>dg(u)(d)(c)(s),st($,$)),W._2._2._2)));g()})())};return tt(Z._1,(()=>{if(Z._2.tag==="CatNil")return at("CatCons",z,st($,$));if(Z._2.tag==="CatCons")return at("CatCons",Z._2._1,st(Z._2._2._1,kt("Cons",at("CatCons",z,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,kt("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,kt("Cons",at("CatCons",R,st($,$)),Y._2._2._2)));g()})())})()),M=()=>je({path:i.segment.path,role:i.role,layer:J,effects:[be("GroupTransform",$T,a)]})(ml(sT)(u)(c)(s));return tt(B._1,(()=>{if(B._2.tag==="CatNil")return at("CatCons",M,st($,$));if(B._2.tag==="CatCons")return at("CatCons",B._2._1,st(B._2._2._1,kt("Cons",at("CatCons",M,st($,$)),B._2._2._2)));g()})())};return tt(S._1,(()=>{if(S._2.tag==="CatNil")return at("CatCons",E,st($,$));if(S._2.tag==="CatCons")return at("CatCons",S._2._1,st(S._2._2._1,kt("Cons",at("CatCons",E,st($,$)),S._2._2._2)));g()})())})()),T=()=>{const C=je({path:i.segment.path,role:i.role,layer:J,effects:[be("GroupTransform",pi,a)]})(x);return tt(C._1,(()=>{if(C._2.tag==="CatNil")return at("CatCons",()=>Jg(t)(e)(n)(i),st($,$));if(C._2.tag==="CatCons")return at("CatCons",C._2._1,st(C._2._2._1,kt("Cons",at("CatCons",()=>Jg(t)(e)(n)(i),st($,$)),C._2._2._2)));g()})())};return tt(y._1,(()=>{if(y._2.tag==="CatNil")return at("CatCons",T,st($,$));if(y._2.tag==="CatCons")return at("CatCons",y._2._1,st(y._2._2._1,kt("Cons",at("CatCons",T,st($,$)),y._2._2._2)));g()})())})())},IC=t=>e=>n=>{if(t.theme==="Isometric")return kC({...NC,transparentBg:t.transparentBg})(t.theme)(Os(n).segment.layout)(Os(n).state);const r=yi(t)(n),o=u=>n.hasDives?r.vw/ka(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=Il(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,kt("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=AC(t)(o())(c.role==="Active"||c.role==="FlyThrough"?c.bgAlpha:0)(c.blur)(r)(c.segment.layout)(DC(n).state)(_&&e.tag!=="Leaf"?Bl("SpringLabels",e):BC),l=()=>{const f=Jg(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,kt("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,kt("Cons",at("CatCons",l,st($,$)),d._2._2._2)));g()})())}g()},Ng=t=>e=>n=>jT({viewport:yi(t)(n),camera:n.camera})(IC(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()},FC=t=>{const e=t.Monad0(),n=e.Bind1(),r=Qr(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()}},QC=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Qr(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()})},zC=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Qr(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))},Fl=t=>{const e=t.Monad0(),n=K3(t),r=wC(t),o=iC(t),i=LC(t),s=H3(t),a=JC(t);return YT(e)({beginFrame:u=>t.setViewport(u.viewport),endFrame:e.Applicative0().pure(),beginGroup:zC(t),endGroup:QC(t),background:W3(t),overlay:FC(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})},MC=lg(Gd)($c.measureText),Ql=Fl($c),WC=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=MC(wg(yi(a)(o))(o.levels[_]))(o.levels[_].segment.layout)(o.levels[_].state)(c)(),f=Dc(i)(l)(s);return Ql(Ng(a)(f.applied)(o))(c)(),f.springs}const d=Dc(i)(I)(s);return Ql(Ng(a)(d.applied)(o))(c)(),d.springs}},cs=t=>"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")",bo=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=Ho(Oo("Fixed",qo(0)(20)(2))),Tg=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 sr(" ")(e(0))},OC=t=>ae(t.vx)+" "+ae(t.vy)+" "+ae(t.vw)+" "+ae(t.vh),Pn=t=>e=>fe(An(e>=0&&e<t.length?t[e]:0)),Cg=t=>e=>{const n=Pn(t.ops)(e+1|0);return Rt(n,n+Pn(t.ops)(e+2|0)|0,t.paths)},zl=(()=>{const t=Qn("&")("&"),e=Qn("<")("<"),n=(()=>{const r=Qn(">")(">"),o=(()=>{const i=Qn('"')(""");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),qC={vx:0,vy:0,vw:1,vh:1},HC=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+bo(t[i])|0;continue}r=!1,o=qC}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)}),Ml=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)}),$C=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)+'"/>',VC=t=>e=>'<path d="'+Tg(t)+'" fill="'+cs(e)+'" fill-opacity="'+ae(nt(e.a)/255)+'"/>',Wl=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")+'"',UC=t=>e=>n=>'<path d="'+Tg(t)+'" fill="'+cs(e)+'" fill-opacity="'+ae(nt(e.a)/255)+'"'+Wl(n)+"/>",KC=t=>e=>'<path d="'+Tg(t)+'" fill="none"'+Wl(e)+"/>",YC=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>"},ko=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?VC(Cg(e)(n))(gs(e.ops)(n+3|0))+ko(t)(e)(n+bo(r._1)|0):r._1===2?KC(Cg(e)(n))(Ml(e.ops)(n+3|0))+ko(t)(e)(n+bo(r._1)|0):r._1===3?UC(Cg(e)(n))(gs(e.ops)(n+3|0))(Ml(e.ops)(n+7|0))+ko(t)(e)(n+bo(r._1)|0):r._1===4?YC(e)(n)+ko(t)(e)(n+bo(r._1)|0):r._1===16?$C(t)(gs(e.ops)(n+1|0))+ko(t)(e)(n+bo(r._1)|0):ko(t)(e)(n+bo(r._1)|0);if(r.tag==="Nothing")return"";g()},XC=t=>{const e=HC(t.ops);return{viewBox:OC(e),body:ko(e)(t)(0),vx:e.vx,vy:e.vy,vw:e.vw,vh:e.vh}},jC=Av(zv)(h0),Ol=t=>e=>{const n=t.strs;return()=>{const r=du(n);return t.strs.push(e),r}},Sa=t=>e=>{const n=t.paths;return()=>{const r=du(n);return t.paths.push(...e),{offset:r,len:e.length}}},ZC=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)}},ql=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)}},Ir=t=>e=>{const n=nt(e),r=t.ops;return()=>{r.push(n)}},La=t=>e=>{const n=e.len,r=Ir(t)(e.offset);return()=>(r(),Ir(t)(n)())},tb=()=>{const t=[],e=[],n=[],r=[];return r.push(1),{ops:t,paths:e,strs:n,alphaStack:r}},eb=t=>{if(t.tag==="MeasureText"){const e=t._3(Ic(t._1)(t._2));return()=>e}if(t.tag==="MeasureInk"){const e=t._3(Fc(t._1)(t._2));return()=>e}g()},Hl=t=>{const e=t.alphaStack;return()=>{const n=du(e);if(n===0)return 1;const r=m0(Kt,J,n-1|0,t.alphaStack);if(r.tag==="Nothing")return 1;if(r.tag==="Just")return r._1;g()}},So=t=>e=>{const n=Hl(t);return()=>{const r=n();return Ir(t)(e.r)(),Ir(t)(e.g)(),Ir(t)(e.b)(),Ir(t)(fe(An(nt(e.a)*r+.5)))()}},$l=t=>e=>{const n=So(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()})())}},nb=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),La(s)(d)(),So(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),La(s)(d)(),$l(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),La(s)(l)(),So(s)(u.color)(),$l(s)(_)(),c};continue}if(a.tag==="DrawText"){const u=a._2,c=a._1,_=Ol(s)(lo(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),Ir(s)(d)(),Ir(s)(l)(),s.ops.push(c.font.size),Ir(s)(c.font.weight)(),So(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),ZC(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),La(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,_=Hl(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=()=>(y0(Kt,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),ql(s)(c)(),u);continue}if(a.tag==="ClearBackground"){const u=a._1,c=a._2,_=s.ops;o=!1,i=()=>(_.push(16),So(s)(u)(),c);continue}if(a.tag==="BackgroundDots"){const u=a._2,c=a._1,_=s.ops;o=!1,i=()=>(_.push(17),ql(s)(c.viewport)(),So(s)(c.bgColor)(),So(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},rb=t=>e=>e.type==="metrics"?eb(e.value):e.type==="render"?nb(t)(e.value):M_("Data.Functor.Variant: pattern match failure ["+e.type+"]"),ob=t=>{const e=tb();return jC(rb(e))(t)(),{ops:e.ops,paths:e.paths,strs:e.strs}},ib=t=>t,_s=t=>t,bg=_s("Light"),sb=_s("Dark"),ab=_s("Blueprint"),ub=_s("Whiteboard"),cb=_s("Isometric"),gb=ib("TransparentBackground"),Zr=t=>"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")",lr=Ho(Oo("Fixed",qo(0)(20)(4))),_b=t=>"translate("+lr(t.tx)+","+lr(t.ty)+") scale("+lr(t.sx)+","+lr(t.sy)+")",It=Ho(Oo("Fixed",qo(0)(20)(2))),kg=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 sr(" ")(e)},fb={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},Sg=(()=>{const t=Qn("&")("&"),e=Qn("<")("<"),n=(()=>{const r=Qn(">")(">"),o=(()=>{const i=Qn('"')(""");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),db=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)}},lb=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},Ea=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return lb(r._1)(e);g()}},Vl={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),s=o();return i(s)}},Functor0:()=>fb},hb={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>Vl},pb={pure:t=>e=>()=>t,Apply0:()=>Vl},Ul={Applicative0:()=>pb,Bind1:()=>hb},mb=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="'+Zr(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="'+Zr(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+')"/>',Kl=t=>e=>'<path d="'+kg(t)+'" fill="'+Zr(e)+'" fill-opacity="'+It(nt(e.a)/255)+'"/>',yb=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="'+Zr(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="'+Zr(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()})()+"/>",Yl=t=>e=>'<path d="'+kg(t)+'" fill="none" stroke="'+Zr(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()})()+'"/>',Xl=t=>{const e=W1(lo(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="'+Zr(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):sr("")(q(db)(e)))+"</text>"},xb=t=>"matrix("+lr(t.a)+" "+lr(t.b)+" "+lr(t.c)+" "+lr(t.d)+" "+lr(t.e)+" "+lr(t.f)+")",jl={fillPath:t=>e=>n=>{const r=Ea(n)(t);return()=>{const o=r();return qe(Kl(o)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=Ea(n)(t);return()=>{const o=r(),i=n.bake.value;return qe(Yl(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=Ea(r)(t);return()=>{const i=o(),s=r.bake.value;return qe(Kl(i)(e.color)+Yl(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(yb((()=>{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 qe(Xl((()=>{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="'+xb(t)+'"';return(n===""?"<g>":"<g "+n+">")+Xl(e)+"</g>"})()),pushTransform:t=>qe((()=>{const e='transform="'+_b(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=J}},pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const o=r.value;n.clipCounter.value=o+1|0;const i=Ea(n)(t)(),s="clip"+ie(o);return qe((()=>{const a='clip-path="url(#'+s+')"';return'<defs><clipPath id="'+s+'"><path d="'+kg(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="'+It(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="'+It(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="'+It(e.viewport.vx)+'" y="'+It(e.viewport.vy)+'" width="'+It(e.viewport.vw)+'" height="'+It(e.viewport.vh)+'" fill="'+Zr(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,qe(mb("bg-dots-"+ie(r))(t))(e)()}},measureText:t=>e=>n=>{const r=Ic(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Fc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Oc,Monad0:()=>Ul},wb=Fl(jl),Jb=lg(Ul)(jl.measureText),Nb=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=yi(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 wb(Ng(i)(e)(o))({out:a,maskDepth:u,clipCounter:c,patternCounter:_,viewport:s,bake:d})(),sr("")(a)})(),vx:s.vx,vy:s.vy,vw:s.vw,vh:s.vh}},vb=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=Dc(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=wg(yi(s)(r))(r.levels[f]);return Jb(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:Nb(t)(a.applied)(e)(n)(r),springs:a.springs}},Tb=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()},Ke=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},hr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Cb=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Zl=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},Ga=hu(Ti),th=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=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},eh=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),kb=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},xi=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()},Sb=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},Lb=t=>t,nh=t=>e=>n=>n<t?0:n>1-e?1:(n-t)/Ke(.05)(1-t-e),Eb=t=>e=>t.labelBasePx*.62*nt(v(Cb)(0)(q(ry)(Et(e)(n=>Kr(`
|
|
10
|
-
`)(n))))),Lg=(()=>{const t=v(e=>n=>{const r=e.previous.tag==="Just"&&Oe(e.previous._1.endT-n.startT)<1e-4?{...n,fromCam:e.previous._1.toCam}:n;return{previous:N("Just",r),spans:St(e.spans)(r)}})({previous:J,spans:[]});return e=>t(e).spans})(),Eg=t=>e=>{const n=Zl(e)(t.keyframes);if(n.tag==="Nothing")return I;if(n.tag==="Just")return n._1.nodes;g()},rh=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",v(Tb)(t.initialKeyframe)(t.spans));g()},Gb=t=>e=>n=>r=>{const o=re(i=>Ga(i.path)(e)&&(Oe(i.endT-n)<1e-4||Oe(i.startT-r)<1e-4))(t.segments);if(o.tag==="Just")return N("Just",o._1);if(o.tag==="Nothing")return re(i=>Ga(i.path)(e))(t.segments);g()},Gg=t=>e=>{const n=Zl(e)(t.keyframes);if(n.tag==="Nothing")return I;if(n.tag==="Just")return n._1.edges;g()},oh=(()=>{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,x=Ft(y=>J,y=>T=>N("Just",{head:y,tail:T}),w);if(x.tag==="Just"&&p.intent==="Overview"&&x._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)&&!(x._1.head.fromCam.zoom===x._1.head.toCam.zoom&&x._1.head.fromCam.center.x===x._1.head.toCam.center.x&&x._1.head.fromCam.center.y===x._1.head.toCam.center.y)&&Oe(p.toCam.center.x-x._1.head.fromCam.center.x)<1e-4&&Oe(p.toCam.center.y-x._1.head.fromCam.center.y)<1e-4&&Oe(p.toCam.zoom-x._1.head.fromCam.zoom)<1e-4&&Oe(p.endT-x._1.head.startT)<1e-4){a=1,u=h,c=x._1.head,_=!0,d=x._1.tail;continue}l=!1,f=[m?{...h,endT:p.endT,toCam:p.toCam,easing:p.easing,interp:br}:h,...e(w)]}}return f},e=n=>t(0,n);return e})(),Pb=t=>e=>{const n=he(e),r=Ll({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}},Bb=t=>e=>n=>r=>{const o=Ke(n.center.x-r.x)(r.x+r.w-n.center.x),i=Ke(n.center.y-r.y)(r.y+r.h-n.center.y),s=Pb(t)(e);return hr(o<=0?n.zoom:s.w/(o*2))(i<=0?n.zoom:s.h/(i*2))},ih=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r,u=Nr(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},Db=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=St(s)(u._1.head),r=u._1.tail;continue}o=!1,i={overview:s,rest:a}}return i},Lo=t=>e=>n=>r=>o=>{const i={width:e.widthPx,height:e.heightPx},s=Ll(i)((()=>{const a=_o(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)},Rb=t=>e=>n=>r=>o=>{const i=Lo(t)(e)(n)(r)(o);return i<=t.minimumReadableLabelPx?o:{...o,zoom:o.zoom*t.minimumReadableLabelPx/i}},Ab=t=>e=>n=>r=>({...r,fromCam:gf(t)(e)(n)(r.fromCam),toCam:gf(t)(e)(n)(r.toCam)}),sh=t=>e=>t.widthPx<=0?0:hr(e/4)(32*e/t.widthPx),Ib=t=>e=>n=>r=>o=>{const i=sh(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},Fb=t=>e=>n=>Ne(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),Qb=t=>e=>n=>Ne(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),zb=t=>e=>n=>Ne(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),Mb=t=>e=>n=>Ne(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),Pa=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=hr(160)(Eb(t)(e)+31),o=hr(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}},Wb=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=th(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 Et(Xt(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=go(a)(nh(i.target._7)(i.target._8)(((c+d)/2-i.startT)/Ke(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)(Bs(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)(Ou(e)(n)(te("Node",1,1,i.target._2,void 0,I,I))),priority:1}];g()})},Ob=t=>e=>n=>r=>o=>i=>{if(o.tag==="Nothing")return i.zoom;if(o.tag==="Just")return Ke(0)(Bb(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()},qb=t=>e=>n=>r=>o=>{const i=s=>{const a=Lo(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)}},Hb=t=>e=>{const n=rh(t)(e);if(n.tag==="AtKeyframe")return Eg(t)(n._1);if(n.tag==="InTransition")return Qe(P.compare,Ie,Eg(t)(n._1),Eg(t)(n._2));g()},$b=t=>e=>n=>Pa(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n&&r.target._2==="PlopOut")?!0:Qb(t.windows)(e)(n)?!1:Pa(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n)?!0:zb(t.windows)(e)(n)?!1:bb(n)(Hb(t)(e)),ah=t=>e=>vt(n=>$b(t)(e)(n._1)?N("Just",{x:n._2.x,y:n._2.y,w:n._2.w,h:n._2.h}):J)(eh(t.layout.nodes)),Vb=t=>e=>{const n=ah(t)(e);return n.length===0?J:N("Just",ir(n))},Ub=t=>vt(e=>{const n=Vb(t)(Ke(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()}),Kb=t=>e=>n=>r=>o=>[...Ub(o)(ft(i=>i.startT>=o.startT&&i.endT<=o.endT,r.spans)),...Wb(t)(o.layout)(n)(o.windows)],Yb=t=>e=>n=>r=>o=>i=>$2(t)(e)(i.layout)(o.endT)(Kb(t)(n)(r)(o)(i)),Xb=t=>e=>{const n=rh(t)(e);if(n.tag==="AtKeyframe")return Gg(t)(n._1);if(n.tag==="InTransition")return Qe(P.compare,Ie,Gg(t)(n._1),Gg(t)(n._2));g()},jb=t=>e=>n=>Pa(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n)?!0:Fb(t.windows)(e)(n)?!1:Pa(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._1===n)?!0:Mb(t.windows)(e)(n)?!1:kb(n)(Xb(t)(e)),Zb=t=>e=>{const n=[...ah(t)(e),...vt(r=>jb(t)(e)(r._1)?N("Just",Wu(r._2)):J)(eh(t.layout.edges))];return n.length===0?J:N("Just",ir(n))},tk=t=>e=>n=>{const r=_o(t)(n);return e.x>=r.x&&e.x+e.w<=r.x+r.w},uh=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=Ke(o.lo)(e.x+e.w-n/2),c=hr(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=Ke(o.lo)(i),c=hr(o.hi)(i);return u<=c?{lo:u,hi:c}:o}const s=Ke(o.lo)(e.x+n/2),a=hr(o.hi)(e.x+e.w-n/2);return s<=a?{lo:s,hi:a}:o},ek=t=>e=>n=>n.endT<=t||n.startT>=e?J:N("Just",{...n,startT:Ke(t)(n.startT),endT:hr(e)(n.endT)}),ch=t=>e=>n=>r=>o=>i=>vt(ek(i.startT)(i.endT))(q(Ab(n)(i.layout)(i.placement))(Yb(t)(e)(r)(i.edgeEndpoints)(o)(i))),gh=t=>e=>n=>r=>{const o=he(t),i=hr(r.zoom)(o.w/Ke(1e-4)(e.w));return{...r,center:{...r.center,x:(()=>{const s=uh(o)(e)(o.w/Ke(1e-4)(i));return xi(s.lo)(s.hi)(n.center.x)})()},zoom:i}},nk=t=>e=>n=>r=>o=>i=>s=>a=>{const u=sh(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 Ib()(e)(a)(i.center.x)(o._1);g()})();if(r.tag==="Nothing"){const l=_.x+_.w/2;return a>=_.w?xi(l)(l)(d):xi(_.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?xi(h)(h)(d):xi(_.x+a/2)(_.x+_.w-a/2)(d)}const f=uh(_)(l)(a);return xi(f.lo)(f.hi)(d)}g()},rk=t=>e=>n=>r=>o=>i=>s=>{const a=_o(n)(s);return a.w<=0?s:{...s,center:{...s.center,x:nk()(e)(n)(r)(o)(i)(s)(a.w)}}},_h=t=>e=>n=>r=>r2(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,fh=t=>e=>n=>r=>o=>{const i=_o(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})()&&Lo(t)(e)(n)(r)(o)>=t.minimumReadableLabelPx},Bg=t=>e=>n=>r=>o=>i=>fh(t)(e)(n)(r)(o)?o:Rb(t)(e)(n)(r)(i),ok=t=>e=>n=>{const r=Db([])(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"&&Oe(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:br,intent:sf},{...o._1.head,fromCam:t},...o._1.tail]:n},ik=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()},sk=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=St(l)(f);continue}if(h.tag==="Just"){if(f.intent==="Overview"&&h._1.head.intent==="ActionFocus"&&Oe(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)&&Ne(m=>Oe(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)(vt(T=>T.target.tag==="EdgeWindow"&&T.target._2.tag==="Extend"&&Oe(T.endT-p)<1e-4?N("Just",T.startT):J)(t.windows)),w=0<m.length?m[0]:p,x=Ke(f.startT)(w-(h._1.head.endT-h._1.head.startT)),y={...f,endT:x};a=St(y.endT>y.startT?St(l)(y):l)({...h._1.head,startT:x,endT:w}),u={...h._1.head,startT:w,fromCam:h._1.head.toCam},c=h._1.tail;continue}a=St(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()},ak=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=gh(n)(a)(o)(i);return a.w/Ke(1e-4)(a.h)>=.33&&i.zoom/Ke(1e-4)(u.zoom)<=1.25&&_o(n)(u).w>=a.w-.001&&Lo(t)(e)(n)(r)(u)>=t.minimumReadableLabelPx*.85?u:i},uk=t=>e=>n=>r=>o=>i=>s=>{const a=he(r.layout),u=a.w*r.placement.scale,c=u/Ke(1e-4)(a.h*r.placement.scale);if(o.tag==="Nothing")return s;if(o.tag==="Just"){if(tk(n)(o._1)(s))return s;const _=gh(n)(o._1)(i)(s);return s.zoom/Ke(1e-4)(_.zoom)<=1.25&&(Lo(t)(e)(n)(r)(_)>=t.minimumReadableLabelPx-.001||o._1.w>=u-.001&&c>=.33&&Lo(t)(e)(n)(r)(_)>=t.minimumReadableLabelPx*.85)?_:s}g()},ck=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=Lo(t)(e)(n)(r)(a);return rk()(e)(n)(o)(i)(s)(uk(t)(e)(n)(r)(o)(s)(ak(t)(e)(n)(r)(s)(u<=0?a:{...a,zoom:hr(a.zoom*t.minimumReadableLabelPx/u)(Ob(t)(e)(n)(r)(i)(a))})))},Dg=t=>e=>n=>r=>o=>i=>s=>fh(t)(e)(n)(r)(s)?s:ck(t)(e)(n)(r)(o)(i)(s),dh=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=St(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=St(u)({startT:_.overview[0].startT,endT:_.overview[h].endT,fromCam:f._1.toCam,toCam:f._1.toCam,easing:_.overview[0].easing,interp:br,intent:Rs}),i=[{...d._1.head,fromCam:f._1.toCam},...d._1.tail];continue}}o=[...u,..._.overview],i=_.rest;continue}o=St(u)(c._1.head),i=c._1.tail;continue}g()}return a})([])(t)},gk=t=>e=>n=>{const r=ih([])(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"&&Oe(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:br,intent:Rs}]}return n}return 0<r.overview.length&&r.prefix.length-1|0,n},lh=t=>e=>n=>{const r=ih([])(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"&&Ga(u.parentPath)(t.path)&&Oe(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:br,intent:Rs}]}return n}return n},_k=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==="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=[...vt(s=>{const a=Sb(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=th(o.target._2)(t.layout.edges),a=nh(o.target._7)(o.target._8)((n-o.startT)/Ke(1e-4)(o.endT-o.startT)),u=(()=>{if(s.tag==="Just")return go((()=>{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):ir(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=ir(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}})())},fk=t=>e=>{const n=Zb(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},hh=t=>e=>n=>r=>o=>i=>{const s=o(i.fromCam),a=o(i.toCam),u=_k(r)(i),c=fk(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)}},ph=t=>e=>n=>r=>o=>i=>i.intent==="ActionFocus"?hh(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)},mh=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=ph(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()},dk=t=>e=>n=>r=>o=>mh(t)(e)(n)(r)(_h(t)(e)(n)(r))(o),lk=t=>e=>n=>r=>o=>o.intent==="ActionFocus"?hh(t)(e)(n)(r)(Lb)(o):o,Ba=t=>e=>n=>r=>o=>i=>Lg(q(qb(t)(e)(n)(i))(sk(i)((()=>{const s=ch(t)(e)(n)(r)(o)(i);if(i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0)return lh(i)(o.dives)(dh(oh(Lg(q(lk(t)(e)(n)(i))(s)))));const a=_h(t)(e)(n)(i),u=mh(t)(e)(n)(i)(a)(s);return s.length===0?[{startT:i.startT,endT:i.endT,fromCam:u,toCam:u,easing:ef,interp:br,intent:sf}]:gk()(i)(ok(u)(i)(lh(i)(o.dives)(dh(oh(Lg(ik(u)(q(ph(t)(e)(n)(i)(a))(s))))))))})()))),hk=t=>e=>n=>r=>o=>Pt(i=>s=>ot.compare(i.startT)(s.startT))(Et(o.segments)(Ba(t)(e)(n)(r)(o))),pk=t=>e=>n=>r=>o=>i=>s=>{if(i.direction==="DiveIn")return Ii(t)(n)(Ba(t)(e)(n)(r)(o)(s))(i.startT-1e-4).camera;if(i.direction==="DiveOut")return Ii(t)(n)(Ba(t)(e)(n)(r)(o)(s))(i.endT+1e-4).camera;g()},mk=t=>e=>n=>r=>o=>vt(i=>{const s=Gb(o)(i.parentPath)(i.startT)(i.endT);if(s.tag==="Just"){const a=i.childPath,u=re(c=>Ga(c.path)(a))(o.segments);if(u.tag==="Just"){const c=Ba(t)(e)(n)(r)(o)(u._1),_=dk(t)(e)(n)(u._1)(ch(t)(e)(n)(r)(o)(u._1)),d=pk(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:$r,interp:of,intent:af});if(i.direction==="DiveOut")return N("Just",{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:$r,interp:of,intent:af});g()}if(u.tag==="Nothing")return J;g()}if(s.tag==="Nothing")return J;g()})(o.dives),yh=t=>e=>n=>r=>o=>[...mk(t)(e)(n)(r)(o),...hk(t)(e)(n)(r)(o)],to=(t,e)=>({tag:t,_1:e}),Da=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()},xh=ce(P)(Mt),wh=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},Jh=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},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},vh=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,kt("Cons",r._3,n(r._6,o)));g()};return n(e,$)})())})(),yk=v(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},Th=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},xk=t=>e=>{const n=it.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},wk=to("NoKeyframes"),Jk=t=>to("DuplicateEventId",t),Nk=t=>to("UnknownEvent",t),vk=t=>e=>({...e,cameraSpans:yh(e.cameraConfig)(t)(e.layout)(e.keyframes)({endT:e.totalDuration,spans:e.spans,windows:e.windows,segments:e.segments,dives:e.dives})}),Tk=t=>e=>n=>r=>{const o=Da(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(v(a=>u=>a+Yo(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}},Ck=ys(t=>{const e=Kr(`
|
|
11
|
-
`)(t);return e.length===0?[""]:e}),bk=t=>e=>xh(vt(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 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 J;g()})(e)),kk=t=>{if(t.event.kind.tag==="SendToken")return N("Just",{startT:t.startT,endT:t.endT,target:Xo("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:Xo("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},Sk=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}):J})())(t.windows),Lk=t=>e=>n=>{const r=Da(n)(t);if(r.tag==="Nothing")return yf;if(r.tag==="Just"){const o=wh(r._1.target)(e);return wh(r._1.source)(e)?o?_y:gy:yf}g()},Ch=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},bh=q(Ci),Ek={post:0},Gk=t=>e=>n=>r=>o=>{const i=Jh(o.event.id)(n),s=(()=>{if(i.tag==="Nothing")return Ek;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 Tk(t)(e)(s)(o.event.kind._1);if(o.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return St(r)({startT:a,endT:a+u.duration,event:o.event,holdPre:u.holdPre,holdPost:u.holdPost})},kh=t=>e=>n=>v(Gk(t)(e)(bk(t)(n)))([])(Ht(r=>o=>({event:o}))(n)),Pk=t=>v(e=>n=>{const r=Nr(e);if(r.tag==="Nothing")return[n];if(r.tag==="Just")return n.startT<=r._1.last.endT+1e-4?St(r._1.init)({...r._1.last,endT:Nn(r._1.last.endT)(n.endT)}):St(e)(n);g()})([])(Pt(e=>n=>ot.compare(e.startT)(n.startT))(t)),Bk=t=>e=>{const n=Nh(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},Dk=t=>e=>{const n=Pt(ot.compare)(vt(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},Rk=t=>e=>{const n=Pt(ot.compare)(vt(r=>r.target.tag==="TokenWindow"&&r.target._2===e?N("Just",r.startT):J)(t));return 0<n.length?N("Just",n[0]):J},Ak=t=>e=>e.target.tag==="NodeWindow"?e.target._2==="PlopIn"?Ch(Dk(t.windows)(e.target._1))(e):e:e.target.tag==="EdgeWindow"&&e.target._2.tag==="Extend"?Ch(Rk(t.windows)(e.target._1))(e):e,Ik=t=>({...t,windows:Pt(e=>n=>ot.compare(e.startT)(n.startT))(q(Ak(t))(t.windows))}),Fk=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()},Sh={id:"",nodes:I,edges:I,kind:Di},Qk=t=>e=>g2((()=>{const n=vh(e.from)(t);if(n.tag==="Nothing")return Sh;if(n.tag==="Just")return n._1;g()})())((()=>{const n=vh(e.to)(t);if(n.tag==="Nothing")return Sh;if(n.tag==="Just")return n._1;g()})()),zk=t=>e=>{const n=Nh(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:I};if(n.tag==="Just")return n._1;g()},Lh={id:"",index:-1,kind:"",name:"",time:0,endTime:0,path:[],tokenIndex:-1,lineIndex:-1,text:"",from:"",to:""},Mk=t=>e=>e.scene.tag==="StepScene"?N("Just",{...Lh,id:"step:"+e.scene._1,kind:"step",name:e.scene._1,time:e.startT,endTime:e.startT,path:bh(t)}):J,Wk=t=>vt(Mk(t.path))(t.spans),Ag=t=>e=>n=>r=>{const o=Da(r)(n.edges);if(o.tag==="Just")return t<=0?e:Nn(e)(Bi(o._1)/t);if(o.tag==="Nothing")return e;g()},Eh=t=>e=>n=>r=>o=>{const i=t.plop,s=Qk(n)(o),a=q(f=>({startT:0,endT:0+Ag(t.edgeSpeed)(t.minEdgeDuration)(e)(f),target:Xo("EdgeWindow",f,Fs("Extend",Zu))}))(wi(s.entering.edges)),u=q(f=>({startT:0,endT:i,target:Xo("NodeWindow",f,Ku)}))(wi(s.entering.nodes)),c=v(Nn)(0)(q(f=>Ag(t.edgeSpeed)(t.minEdgeDuration)(e)(f))(wi(s.leaving.edges))),_=f=>Ne(h=>{const p=Da(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=q(f=>({startT:_(f),endT:_(f)+t.plop,target:Xo("NodeWindow",f,sy)}))(wi(s.leaving.nodes)),l=q(f=>({startT:0,endT:Ag(t.edgeSpeed)(t.minEdgeDuration)(e)(f),target:Xo("EdgeWindow",f,Fs("Retract",Lk(r)(s.leaving.nodes)(f)))}))(wi(s.leaving.edges));return{duration:(()=>{const f=Pt(ot.compare)([...q(p=>p.endT)(l),...q(p=>p.endT)(d),...q(p=>p.endT)(u),...q(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]}},Ok=t=>e=>n=>r=>o=>i=>q((()=>{const s=o.startT;return a=>({...a,startT:a.startT+s,endT:a.endT+s})})())(Eh(t)(e)(n)(r)(i).windows),qk=t=>vt(e=>Zt(Ao,e).length>1?N("Just",(()=>{const n=Ft(r=>J,r=>o=>N("Just",{head:r,tail:o}),Zt(Ao,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):J)(I0(Ti)(Pt(P.compare)(t))),Hk=t=>{const e=q(r=>r.id)(t),n=yk(e);return[...q(Jk)(qk(e)),...q(Nk)(ft(r=>!Rg(r)(n),Et(t)(Fk)))]},$k=t=>{const e=xh(q(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[to("ScheduleCycle",[...Zt(fn.foldr,o),i])];if(Rg(i)(r))return[];const s=Jh(i)(e);if(s.tag==="Nothing")return[];if(s.tag==="Just")return Et(s._1)(n(rt(P)(i)()(r))(rt(P)(i)()(o)));g()};return Et(t)(r=>n(I)(I)(r.id))},Vk={plop:.5,gap:0,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:0,stillHold:1.8,hatchHold:0,tokenReadSecPerChar:.06,nodeEasing:w2,edgeEasing:$r,tokenEasing:ef,diveDur:1.2,retreatDur:1.2},Uk=t=>e=>n=>r=>q((()=>{const o=n.startT;return i=>({...i,startT:i.startT+o,endT:i.endT+o})})())(vt(kk)(kh(t)(e)(r.events))),Kk=t=>e=>n=>r=>o=>{if(o.scene.tag==="Structural")return Ok(t)(e)(n)(r)(o)(o.scene._1);if(o.scene.tag==="Hold")return[];if(o.scene.tag==="DataFlow")return Uk(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()},Yk=t=>e=>n=>{const r=kh(t)(e)(n.events);return r.length===0?t.gap:v(Nn)(0)(q(o=>o.endT)(r))+t.gap},Xk=t=>e=>n=>r=>o=>{if(o.tag==="Structural")return Eh(t)(e)(n)(r)(o._1).duration;if(o.tag==="Hold")return t.stillHold;if(o.tag==="DataFlow")return Yk(t)(e)(o._1);if(o.tag==="EnterNode"||o.tag==="ExitNode"||o.tag==="StepScene")return 0;g()},Gh=t=>e=>n=>r=>o=>i=>{const s=jm(e)(r),a=n.layout,u=j_(q(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=y2(o),l=p=>({segments:p.runSpans.length===0?p.segments:St(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),C=p.t+t.diveDur,S=St(r)(m._1),E=Gh(t)(e)(zk(n)(m._1))(S)(Bk(o)(m._1))(C),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:C,node:m._1,parentPath:r,childPath:S,direction:ay},...E.dives,{startT:E.endT,endT:B,node:m._1,parentPath:r,childPath:S,direction:uy}]}}if(m.tag==="ExitNode")return p;const w=p.t+Xk(t)(a)(u)(d)(m),x={startT:p.t,endT:w,scene:m},y=Kk(t)(a)(u)(d)(x);return{...p,t:w,runSpans:St(p.runSpans)(x),runWindows:[...p.runWindows,...y],spans:St(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:Pt(p=>m=>ot.compare(p.startT)(m.startT))(h.windows),segments:h.segments,dives:h.dives}},jk=t=>e=>{const n=ot.compare(t.time)(e.time);return n==="EQ"?P.compare(t.id)(e.id):n},Bn=t=>e=>e-v(n=>r=>n+Nn(0)(Th(e)(r.endT)-r.startT))(0)(t),Zk=t=>e=>{const n=Nn(t.startT)(e.startT),r=Th(t.endT)(e.endT);return r>n+1e-4?N("Just",{startT:n,endT:r}):J},t5=t=>e=>{if(e.scene.tag==="Structural"){const n=v(r=>o=>({cursor:Nn(r.cursor)(o.endT),cuts:o.startT>r.cursor+1e-4?St(r.cuts)({startT:r.cursor,endT:o.startT}):r.cuts}))({cursor:e.startT,cuts:[]})(Pt(r=>o=>ot.compare(r.startT)(o.startT))(vt(Zk(e))(t)));return e.endT>n.cursor+1e-4?St(n.cuts)({startT:n.cursor,endT:e.endT}):n.cuts}return[]},e5=t=>{const e=Pk(Et(t.spans)(t5(t.windows)));return e.length===0?t:{...t,endT:Bn(e)(t.endT),spans:q(n=>({...n,startT:Bn(e)(n.startT),endT:Bn(e)(n.endT)}))(t.spans),windows:Pt(n=>r=>ot.compare(n.startT)(r.startT))(q(n=>({...n,startT:Bn(e)(n.startT),endT:Bn(e)(n.endT)}))(t.windows)),segments:q(n=>({...n,startT:Bn(e)(n.startT),endT:Bn(e)(n.endT),spans:q(r=>({...r,startT:Bn(e)(r.startT),endT:Bn(e)(r.endT)}))(n.spans),windows:Pt(r=>o=>ot.compare(r.startT)(o.startT))(q(r=>({...r,startT:Bn(e)(r.startT),endT:Bn(e)(r.endT)}))(n.windows))}))(t.segments),dives:q(n=>({...n,startT:Bn(e)(n.startT),endT:Bn(e)(n.endT)}))(t.dives)}},n5=t=>{const e=q(Ik)(t.segments);return e5({...t,segments:e,windows:Pt(n=>r=>ot.compare(n.startT)(r.startT))(Et(e)(n=>n.windows))})},r5=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=Ck(n),s=q(u=>nt(xk(1)(Yo(u).length)))(i),a=Nn(1)(v(er)(0)(s));return Ht(u=>c=>({lineIndex:u,text:c,start:o(v(er)(0)(u<1?[]:Rt(0,u,s))/a),end:o(u>=0&&u<s.length?(v(er)(0)(u<1?[]:Rt(0,u,s))+s[u])/a:(v(er)(0)(u<1?[]:Rt(0,u,s))+1)/a)}))(i)},o5=t=>{const e=Nn(0)(t.window.endT-t.window.startT);return q(n=>({...Lh,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:bh(t.path),tokenIndex:t.tokenIndex,lineIndex:n.lineIndex,text:n.text,from:t.from,to:t.to}))(r5(t.holdPre)(t.holdPost)(t.labels))},i5=t=>Et(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}))(Et(t)(Sk)))(o5),s5=t=>Ht(e=>n=>({...n,index:e}))(Pt(jk)([...Et(t.segments)(Wk),...i5(t.segments)])),a5=t=>e=>{if(e.tag==="Structural")return vt(n=>n)([Ra(e._1.from)(t)?J:N("Just",to("UnknownKeyframe",e._1.from)),Ra(e._1.to)(t)?J:N("Just",to("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return vt(n=>n)([Ra(e._1)(t)?J:N("Just",to("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...vt(n=>n)([Ra(e._1.keyframe)(t)?J:N("Just",to("UnknownKeyframe",e._1.keyframe))]),...Hk(e._1.events),...$k(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];if(e.tag==="StepScene")return[];g()},u5=t=>e=>{const n=Et(e)(a5(t));return n.length===0?Wt("Right",void 0):Wt("Left",n)},c5=t=>e=>n=>r=>{if(0<n.keyframes.length){const o=n.keyframes[0],i=j_(q(a=>b(a.id,a))(n.keyframes)),s=u5(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=n5(Gh(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:yh(t)(F2)(r.layout)(i)(a),cameraConfig:t,levelTree:r,segments:a.segments,dives:a.dives,cues:s5(a),seed:n.seed})})}return Wt("Left",[wk])},Eo=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(o=>n(o._1)(o._2)),Apply0:()=>Ph(t)}),Ph=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=Eo(t);return o=>i=>r.bind(o)(s=>r.bind(i)(a=>Go(t).pure(s(a))))})(),Functor0:()=>n}},Go=t=>({pure:e=>n=>t.Applicative0().pure(b(e,n)),Apply0:()=>Ph(t)}),Bh=t=>{const e={Applicative0:()=>Go(t),Bind1:()=>Eo(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},Po=(t,e)=>({tag:t,_1:e}),pr=(t,e)=>({tag:t,_1:e}),Aa=t=>t,Un=(t,e)=>({tag:t,_1:e}),Ig=t=>t,Je=Bh(kn),g5=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},_5=ce(P)(Mt),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},f5=v(t=>e=>rt(P)(e)()(t))(I),Vt=Eo(kn),He=Je.state(t=>b(t,t)),ge=Go(kn),Dh=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=Qr(ge),Qg=Rh(Mt),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},mr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const 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=(()=>{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,kt("Cons",r._3,n(r._6,o)));g()};return n(e,$)})())})(),Kn=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},h5=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},Ia=t=>e=>n=>v(r=>o=>t.Bind1().bind(r)(i=>e(i)(o)))(t.Applicative0().pure(n)),p5=v(t=>e=>rt(P)(e)()(t))(I),m5=(()=>{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,kt("Cons",r._3,n(r._6,o)));g()};return n(e,$)})())})(),y5=Rh(f_),x5=v(t=>e=>rt(P)(e)()(t))(I),w5=Ig("AnimatedSurface"),J5=Ig("StillSurface"),N5=Ig("SequenceSurface"),v5=Un("Exit"),Fa=Aa("AnimatedKeyframe"),zg=Aa("Still"),T5=Aa("Title"),Ah=Aa("StepMarker"),C5=t=>pr("Par",t),b5=t=>pr("Seq",t),k5=t=>pr("GroupSeq",t),Ih=t=>Po("StepDive",t),S5={line:0,column:0,endLine:0,endColumn:0},L5=t=>e=>n=>{const r=io(Kt,J,o=>o._1===t,n);if(r.tag==="Just"){const o=Mr(Kt,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 St(n)(b(t,e));g()},E5=t=>e=>q(n=>n._1===t?b(n._1,{...n._2,label:N("Just",e)}):b(n._1,n._2)),Fh=t=>{const e=t.compare;return n=>v(r=>o=>Qe(e,Ie,r,n(o)))(I)},Mg=Fh(P),Wg=Fh(P),G5=t=>{const e=t.span;return Je.state(n=>b(void 0,{...n,currentSpan:e}))},P5=t=>e=>({structural:[...t.structural,...e.structural],flow:t.flow||e.flow,dives:[...t.dives,...e.dives]}),B5=t=>e=>e.kind==="Animated"||g5(e.id)(t),Qh={graphNodes:[],graphEdges:I,currNodes:I,currEdges:I,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:J,currentSpan:S5,error:J,enterStack:[],interiorOf:I,stepNames:I},zh=t=>e=>n=>{const r=Zt(fn.foldr,n);return sr(", ")(q(e)(Rt(0,6,r)))+(r.length>6?", \u2026":"")},D5=t=>e=>{const n=Fg(e)(_5(q(r=>b(r.id,r))(t.graph.edges)));if(n.tag==="Just")return(()=>{const r=ao("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()},R5=t=>e=>n=>{const r=zh()(Ci)(e),o=zh()(D5(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."},A5=t=>{if(t.kind.tag==="SendToken")return f5([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()},I5=t=>Mg(A5)(t.events),F5=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()},Q5=t=>Wg(F5)(t.events),Yn=t=>Je.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()})())),z5=Qg(t=>Vt.bind(He)(e=>{if(e.error.tag==="Just")return ge.pure();if(e.error.tag==="Nothing")return Dh(t.node)(e.interiorOf)?Yn("node "+t.node+" has more than one `inside` block"):Je.state(n=>b(void 0,{...n,interiorOf:rt(P)(t.node)(t.doc)(n.interiorOf)}));g()})),M5=t=>Vt.bind(He)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ie(e.kfCounter);if(Ne(o=>o.id===n,e.keyframes))return Yn("duplicate frame name "+n);const r={...e,keyframes:St(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=>b(void 0,r))}),un=t=>e=>Vt.bind(Je.state(n=>b(void 0,{...n,currentSpan:t})))(()=>Yn(e)),Mh=t=>e=>Vt.bind(He)(n=>d5(e)(n.stepNames)?un(t)("duplicate step name "+e):Je.state(r=>b(void 0,{...r,scenes:St(r.scenes)(Vo("StepScene",e)),stepNames:rt(P)(e)()(r.stepNames)}))),W5=t=>{if(t.ops.tag==="Leaf"){const e=t.ops._1;return Vt.bind((()=>{const n=e.span;return Je.state(r=>b(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?Mh(e.span)(e.op._1.name):Yn("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=>b(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?Mh(e.span)(e.op._1.name):Yn("step marker frame did not contain a step"))}return Yn("step marker frame did not contain a step")},O5=t=>Vt.bind((()=>{const e=t.span;return Je.state(n=>b(void 0,{...n,currentSpan:e}))})())(()=>Vt.bind(He)(e=>{if(e.error.tag==="Just")return ge.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!mr(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(!Dh(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 iA=(function(qu){"use strict";function Y0(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 f(){throw new Error("Failed pattern match")}function kr(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const Qe=t=>e=>t,U=function(t){return function(e){for(var n=e.length,r=new Array(n),o=0;o<n;o++)r[o]=t(e[o]);return r}},K0={map:U},Yf=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]),a=i.length,s=0;s<a;s++)n.push(i[s]);return n}},j0=function(t){return function(e){return{}.hasOwnProperty.call(e,t)}},Z0=function(t){return function(e){return e[t]}},ue=function(t){return t.toString()},go=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},Kf=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})+'"'},tm=function(t){return function(e){for(var n=[],r=0,o=e.length;r<o;r++)n[r]=t(e[r]);return"["+n.join(",")+"]"}},Hu=t=>t,Fe=Hu("LT"),Me=Hu("GT"),Ze=Hu("EQ"),v=(t,e)=>({tag:t,_1:e}),w=v("Nothing"),Vt=t=>v("Just",t),jf=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;f()},Zf=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;f()},Ot=(t,e)=>({tag:t,_1:e}),em=t=>Ot("Right",t),nm={map:t=>e=>{if(e.tag==="Left")return Ot("Left",e._1);if(e.tag==="Right")return Ot("Right",t(e._1));f()}},t_={apply:t=>e=>{if(t.tag==="Left")return Ot("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Ot("Left",e._1);if(e.tag==="Right")return Ot("Right",t._1(e._1))}f()},Functor0:()=>nm},rm={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Ot("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}f()},Apply0:()=>t_},om={pure:em,Apply0:()=>t_},e_={Applicative0:()=>om,Bind1:()=>rm},im=t=>t,am={map:t=>e=>t(e)},n_={apply:t=>e=>t(e),Functor0:()=>am},sm={bind:t=>e=>e(t),Apply0:()=>n_},um={pure:im,Apply0:()=>n_},Ln={Applicative0:()=>um,Bind1:()=>sm},cm=function(t){return function(){return t}},gm={apply:t=>e=>()=>{const n=t(),r=e();return $u.pure(n(r))()},Functor0:()=>fm},$u={pure:cm,Apply0:()=>gm},fm={map:t=>e=>()=>{const n=e();return t(n)}},Yo=(t,e)=>({tag:t,_1:e}),Uu=t=>Yo("Loop",t),_m=t=>Yo("Done",t),dm={tailRecM:t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const a=r;if(a.tag==="Loop"){r=t(a._1);continue}if(a.tag==="Done"){o=!1,i=a._1;continue}f()}return i};return n=>e(t(n))},Monad0:()=>Ln},lm=function(t){return function(e){return function(){return t(e())}}},hm=function(t){return function(){return t}},pm=function(t){return function(e){return function(){return e(t())()}}},mm={map:lm},ym={Applicative0:()=>Vu,Bind1:()=>xm},xm={bind:pm,Apply0:()=>r_},r_={apply:t=>e=>()=>{const n=t(),r=e();return Vu.pure(n(r))()},Functor0:()=>mm},Vu={pure:hm,Apply0:()=>r_},wm={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"&&f()}const o=r;if(o.tag==="Done")return o._1;f()}},Monad0:()=>ym},Nm=function(t){return function(e){return function(n){return function(){return t(e,n)}}}},vm=function(t,e,n,r){return n>=0&&n<r.length?t(r[n]):e},Xu=function(t){return t.length},Tm=function(t,e,n){return n.length>0?t(n.pop()):e},Jm=Nm(function(t,e){return e.push(t)}),bm=(t,e)=>({tag:"Iterator",_1:t,_2:e}),Cm=t=>e=>n=>()=>{let r=!1;const o=e._2;for(;!r;){const i=o.value,a=e._1(i);if(a.tag==="Just"&&t(a._1)){n.push(a._1),e._2.value;const s=e._2.value;e._2.value=s+1|0;continue}r=!0}},km=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const o=r.value,i=r.value;r.value=i+1|0;const a=t._1(o);if(a.tag==="Just"){e(a._1)();continue}if(a.tag==="Nothing"){n=!0;continue}f()}},Ko=function(t){return function(e){return function(n){for(var r=e,o=n.length,i=o-1;i>=0;i--)r=t(n[i])(r);return r}}},J=function(t){return function(e){return function(n){for(var r=e,o=n.length,i=0;i<o;i++)r=t(r)(n[i]);return r}}},Hr=t=>{const e=t.Apply0();return n=>r=>n.foldr(o=>{const i=r(o);return a=>e.apply(e.Functor0().map(s=>Yf)(i))(a)})(t.pure())},jo=t=>{const e=Hr(t);return n=>{const r=e(n);return o=>i=>r(i)(o)}},o_={foldr:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(n._1)(e);f()},foldl:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(e)(n._1);f()},foldMap:t=>{const e=t.mempty;return n=>r=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return n(r._1);f()}}},Mt={foldr:Ko,foldl:J,foldMap:t=>{const e=t.mempty;return n=>Mt.foldr(r=>o=>t.Semigroup0().append(n(r))(o))(e)}},b=(t,e)=>({tag:"Tuple",_1:t,_2:e}),Bn=t=>e=>b(t,e),Ra=t=>t._2,Ba=t=>t._1,qt=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 Yu=function(t){return function(e){return t===e}};const Lm=Yu,Sm=Yu,Zo=Yu,Fa=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}}},ir={eq:Zo},Em={eq:Sm},$r={eq:Lm};var Ku=function(t){return function(e){return function(n){return function(r){return function(o){return r<o?t:r===o?e:n}}}}};const Pm=Ku,Am=Ku,A={compare:Ku(Fe)(Ze)(Me),Eq0:()=>ir},ot={compare:Am(Fe)(Ze)(Me),Eq0:()=>Em},it={compare:Pm(Fe)(Ze)(Me),Eq0:()=>$r},Bi=function(t){return t},Gm=(function(){function t(o){return[o]}function e(o){return function(i){return[o,i]}}function n(o){return function(i){return function(a){return[o,i,a]}}}function r(o){return function(i){return o.concat(i)}}return function(o){return function(i){return function(a){return function(s){return function(u){function c(g,d){switch(d-g){case 0:return a([]);case 1:return i(t)(s(u[g]));case 2:return o(i(e)(s(u[g])))(s(u[g+1]));case 3:return o(o(i(n)(s(u[g])))(s(u[g+1])))(s(u[g+2]));default:var l=g+Math.floor((d-g)/4)*2;return o(i(r)(c(g,l)))(c(l,d))}}return c(0,u.length)}}}}}})(),Im=t=>t,fo={traverse:t=>{const e=t.Apply0();return Gm(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>fo.traverse(t)(Im),Functor0:()=>K0,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 Dm=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},Rm=function(t,e){for(var n=[],r=0,o=0;o<t;o++)n[r++]=e;return n};const Bm=typeof Array.prototype.fill=="function"?Dm:Rm,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=[],a=0,s=o;s!==e;)i[a++]=s.head,s=s.tail;return i}return function(o,i){return r(o(n)(e)(i))}})(),Rt=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},i_=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},Lr=function(t,e,n,r){for(var o=0,i=r.length;o<i;o++)if(n(r[o]))return t(o);return e},a_=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)},s_=function(t,e,n,r){if(n<0||n>=r.length)return e;var o=r.slice();return o.splice(n,1),t(o)},Ur=function(t,e,n,r,o){if(n<0||n>=o.length)return e;var i=o.slice();return i[n]=r,t(i)},ce=function(t){return t.slice().reverse()},mn=function(t){if(t.length<=1e4)return Array.prototype.concat.apply([],t);for(var e=[],n=0,r=t.length;n<r;n++)for(var o=t[n],i=0,a=o.length;i<a;i++)e.push(o[i]);return e},dt=function(t,e){return e.filter(t)},Fm=function(t,e,n){for(var r=n.length,o=e,i=new Array(r),a=0;a<r;a++)o=t(o)(n[a]),i[a]=o;return i},Mm=(function(){function t(e,n,r,o,i,a){var s,u,c,g,d,l,_;for(s=i+(a-i>>1),s-i>1&&t(e,n,o,r,i,s),a-s>1&&t(e,n,o,r,s,a),u=i,c=s,g=i;u<s&&c<a;)d=o[u],l=o[c],_=n(e(d)(l)),_>0?(r[g++]=l,++c):(r[g++]=d,++u);for(;u<s;)r[g++]=o[u++];for(;c<a;)r[g++]=o[c++]}return function(e,n,r){var o;return r.length<2?r:(o=r.slice(0),t(e,n,o,r.slice(0),0,r.length),o)}})(),It=function(t,e,n){return n.slice(t,e)},We=function(t,e,n){for(var r=e.length<n.length?e.length:n.length,o=new Array(r),i=0;i<r;i++)o[i]=t(e[i])(n[i]);return o},le=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},u_=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Pt=t=>e=>Mm(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;f()},e),zm=t=>e=>Pt(n=>r=>t.compare(e(n))(e(r))),Ct=t=>e=>(()=>{const n=Jm(e);return()=>{const r=[...t];return n(r)(),r}})()(),Sr=t=>{if(t.length===0)return t.length-1|0,w;const e=t.length-1|0;return e>=0&&e<t.length?v("Just",{init:It(0,t.length-1|0,t),last:t[e]}):w},Qm=t=>e=>n=>t>=0&&t<n.length?Ur(Vt,w,t,e(n[t]),n):w,ar=t=>e=>{const n=(r=>{let o=r,i=!0,a;for(;i;){const s=o;if(s>=0&&s<e.length){if(t(e[s])){o=s+1|0;continue}i=!1,a=v("Just",s);continue}i=!1,a=w}return a})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:It(0,n._1,e),rest:It(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};f()},ti=t=>e=>{const n=Pt(r=>o=>t(r._2)(o._2))(qt(Bn)(e));return 0<n.length?U(Ra)(zm(it)(Ba)((()=>{const r=[n[0]];for(const o of n){const i=t((()=>{const a=r.length-1|0;if(a>=0&&a<r.length)return r[a]._2;f()})())(o._2);(i==="LT"||i==="GT"||i!=="EQ")&&r.push(o)}return r})())):[]},Wm=t=>e=>{const n=[],r=bm(o=>o>=0&&o<e.length?v("Just",e[o]):w,{value:0});return km(r)(o=>()=>{const i=[];i.push(o),Cm(t(o))(r)(i)(),n.push(i)})(),n},jt=t=>e=>{const n=Lr(Vt,w,t,e);return n.tag==="Just"?v("Just",e[n._1]):w},Fi=t=>e=>dt(t,e),nn=t=>e=>n=>{const r=Lr(Vt,w,o=>t.eq(o)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;f()},Ma=t=>e=>St(e)(t),vt=t=>Ma(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];f()}),c_=isFinite;function Om(t,e,n,r){var o=parseFloat(t);return e(o)?n(o):r}const Ce=Math.abs,qm=Math.acos,_o=function(t){return function(e){return Math.atan2(t,e)}},za=Math.ceil,Sn=Math.cos,ei=Math.exp,Fn=Math.floor,Qa=Math.log,Hm=function(t){return function(e){return Math.min(t,e)}},ju=function(t){return function(e){return Math.pow(t,e)}},$n=Math.round,yn=Math.sin,Xe=Math.sqrt,$m=Math.tan,Um=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},et=function(t){return t},Vm=(function(t){return function(e){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var o=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(i){if(o.test(i)){var a=parseInt(i,n);return(a|0)===a?t(a):e}else return e}}}})(Vt)(w)(10),g_=Um(Vt)(w),he=t=>{if(!c_(t))return 0;if(t>=et(2147483647))return 2147483647;if(t<=et(-2147483648))return-2147483648;const e=g_(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;f()},kt=(t,e,n)=>({tag:t,_1:e,_2:n}),V=kt("Nil"),ye={foldr:t=>e=>{const n=ye.foldl(o=>i=>t(i)(o))(e),r=(o=>i=>{let a=o,s=i,u=!0,c;for(;u;){const g=a,d=s;if(d.tag==="Nil"){u=!1,c=g;continue}if(d.tag==="Cons"){a=kt("Cons",d._1,g),s=d._2;continue}f()}return c})(V);return o=>n(r(o))},foldl:t=>e=>n=>{let r=e,o=n,i=!0,a;for(;i;){const s=r,u=o;if(u.tag==="Nil"){i=!1,a=s;continue}if(u.tag==="Cons"){r=t(s)(u._1),o=u._2;continue}f()}return a},foldMap:t=>{const e=t.mempty;return n=>ye.foldl(r=>{const o=t.Semigroup0().append(r);return i=>o(n(i))})(e)}},Xm=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var a=[],s=i;;){var u=o(s);a.push(n(u));var c=r(u);if(t(c))return a;s=e(c)}}}}}}},Ym=t=>{if(t.tag==="Just")return t._1;f()},Km={unfoldr1:Xm(jf)(Ym)(Ba)(Ra)},jm=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var a=[],s=i;;){var u=o(s);if(t(u))return a;var c=e(u);a.push(n(c)),s=r(c)}}}}}}},Zm=t=>{if(t.tag==="Just")return t._1;f()},fn={unfoldr:jm(jf)(Zm)(Ba)(Ra),Unfoldable10:()=>Km},oe=(t,e,n,r,o,i,a)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:a}),_n=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Wa=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),f_=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),F=oe("Leaf"),Un=_n("IterLeaf"),ke=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return oe("Node",1,1,t,e,n,r);if(r.tag==="Node")return oe("Node",1+r._1|0,1+r._2|0,t,e,n,r);f()}if(n.tag==="Node"){if(r.tag==="Leaf")return oe("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return oe("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,t,e,n,r)}f()},tn=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?oe("Node",1,1,t,e,F,F):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;f()})()?ke(r._5._3,r._5._4,ke(t,e,n,r._5._5),ke(r._3,r._4,r._5._6,r._6)):ke(r._3,r._4,ke(t,e,n,r._5),r._6):ke(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;f()})()?ke(r._5._3,r._5._4,ke(t,e,n,r._5._5),ke(r._3,r._4,r._5._6,r._6)):ke(r._3,r._4,ke(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;f()})()?ke(n._6._3,n._6._4,ke(n._3,n._4,n._5,n._6._5),ke(t,e,n._6._6,r)):ke(n._3,n._4,n._5,ke(t,e,n._6,r)):ke(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;f()})()?ke(n._6._3,n._6._4,ke(n._3,n._4,n._5,n._6._5),ke(t,e,n._6._6,r)):ke(n._3,n._4,n._5,ke(t,e,n._6,r)):ke(t,e,n,r);f()},ni=(t,e,n)=>{if(n.tag==="Leaf")return Wa(w,F,F);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const o=ni(t,e,n._5);return Wa(o._1,o._2,tn(n._3,n._4,o._3,n._6))}if(r==="GT"){const o=ni(t,e,n._6);return Wa(o._1,tn(n._3,n._4,n._5,o._2),o._3)}if(r==="EQ")return Wa(v("Just",n._4),n._5,n._6)}f()},__=(t,e,n,r)=>{if(r.tag==="Leaf")return f_(t,e,n);if(r.tag==="Node"){const o=__(r._3,r._4,r._5,r._6);return f_(o._1,o._2,tn(t,e,n,o._3))}f()},ri=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=__(t._3,t._4,t._5,t._6);return tn(n._1,n._2,n._3,e)}f()},Vn=(t,e,n)=>{if(e.tag==="Leaf")return F;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=ni(t,n._3,e);return ri(Vn(t,r._2,n._5),Vn(t,r._3,n._6))}f()},Oa=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return F;if(r.tag==="Node"){const o=ni(t,r._3,n),i=Oa(t,e,o._2,r._5),a=Oa(t,e,o._3,r._6);if(o._1.tag==="Just")return tn(r._3,e(o._1._1)(r._4),i,a);if(o._1.tag==="Nothing")return ri(i,a)}f()},Oe=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const o=ni(t,r._3,n),i=Oe(t,e,o._2,r._5),a=Oe(t,e,o._3,r._6);if(o._1.tag==="Just")return tn(r._3,e(o._1._1)(r._4),i,a);if(o._1.tag==="Nothing")return tn(r._3,r._4,i,a)}f()},d_=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return F;if(o.tag==="Node"){const i=t.compare(n)(o._3);if(i==="LT")return tn(o._3,o._4,r(o._5),o._6);if(i==="GT")return tn(o._3,o._4,o._5,r(o._6));if(i==="EQ"){const a=e(o._4);if(a.tag==="Nothing")return ri(o._5,o._6);if(a.tag==="Just")return oe("Node",o._1,o._2,o._3,a._1,o._5,o._6)}}f()};return r},t2=t=>e=>{const n=r=>{if(r.tag==="Leaf")return F;if(r.tag==="Node"){const o=e(r._3)(r._4);if(o.tag==="Just")return tn(r._3,o._1,n(r._5),n(r._6));if(o.tag==="Nothing")return ri(n(r._5),n(r._6))}f()};return n},Xn=(t=>e=>n=>{let r=n,o=!0,i;for(;o;){const a=r;if(a.tag==="IterLeaf"){o=!1,i=e();continue}if(a.tag==="IterEmit"){o=!1,i=t(a._1,a._2,a._3);continue}if(a.tag==="IterNode"){r=(s=>u=>{let c=s,g=u,d=!0,l;for(;d;){const _=c,h=g;if(h.tag==="Leaf"){d=!1,l=_;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){c=_n("IterEmit",h._3,h._4,_),g=h._5;continue}c=_n("IterEmit",h._3,h._4,_n("IterNode",h._6,_)),g=h._5;continue}f()}return l})(a._2)(a._1);continue}f()}return i})((t,e,n)=>v("Just",b(b(t,e),n)))(t=>w),Ft=t=>e=>n=>r=>{const o=i=>{if(i.tag==="Leaf")return oe("Node",1,1,n,r,F,F);if(i.tag==="Node"){const a=t.compare(n)(i._3);if(a==="LT")return tn(i._3,i._4,o(i._5),i._6);if(a==="GT")return tn(i._3,i._4,i._5,o(i._6));if(a==="EQ")return oe("Node",i._1,i._2,n,e(i._4)(r),i._5,i._6)}f()};return o},rt=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return oe("Node",1,1,e,n,F,F);if(o.tag==="Node"){const i=t.compare(e)(o._3);if(i==="LT")return tn(o._3,o._4,r(o._5),o._6);if(i==="GT")return tn(o._3,o._4,o._5,r(o._6));if(i==="EQ")return oe("Node",o._1,o._2,e,n,o._5,o._6)}f()};return r},ge=t=>e=>e.foldl(n=>r=>rt(t)(r._1)(r._2)(n))(F),oi=t=>e=>{const n=r=>{if(r.tag==="Leaf")return F;if(r.tag==="Node"){const o=t.compare(e)(r._3);if(o==="LT")return tn(r._3,r._4,n(r._5),r._6);if(o==="GT")return tn(r._3,r._4,r._5,n(r._6));if(o==="EQ")return ri(r._5,r._6)}f()};return n},l_=t=>{const e=t.compare;return n=>r=>o=>{const i=ni(e,r,o),a=n(i._1);if(a.tag==="Nothing")return ri(i._2,i._3);if(a.tag==="Just")return tn(r,a._1,i._2,i._3);f()}},Te=function(t){return function(e){return t+e|0}},sr=function(t){return function(e){return t+e}},Vr=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},e2=function(t){return function(e){return t+e}},xe=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},n2={append:e2},r2={append:xe},o2={mempty:"",Semigroup0:()=>n2},i2={mempty:[],Semigroup0:()=>r2},Mi=null;function xn(t,e,n){return t==null?e:n(t)}function XP(t){return t}function Zu(t){return function(e){return function(n){return t.apply(n,[e])}}}const a2=Zu(Number.prototype.toPrecision),s2=Zu(Number.prototype.toFixed),u2=Zu(Number.prototype.toExponential),lo=(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;f()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},po=t=>{if(t.tag==="Precision")return a2(t._1);if(t.tag==="Fixed")return s2(t._1);if(t.tag==="Exponential")return u2(t._1);f()},h_=function(t){return function(){console.log(t)}};function c2(){return Date.now()}function p_(t){return function(){return t.getContext("2d")}}function m_(t){return function(){return t.width}}function y_(t){return function(){return t.height}}function x_(t){return function(e){return function(){t.width=e}}}function w_(t){return function(e){return function(){t.height=e}}}function tc(t){return function(e){return function(){t.lineWidth=e}}}function g2(t){return function(e){return function(){t.fillStyle=e}}}function f2(t){return function(e){return function(){t.strokeStyle=e}}}function ec(t){return function(e){return function(){t.lineCap=e}}}function nc(t){return function(e){return function(){t.lineJoin=e}}}function _2(t){return function(e){return function(){t.globalCompositeOperation=e}}}function d2(t){return function(e){return function(){t.globalAlpha=e}}}function N_(t){return function(){t.beginPath()}}function rc(t){return function(){t.stroke()}}function oc(t){return function(){t.fill()}}function l2(t){return function(){t.clip()}}function zi(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function v_(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function T_(t){return function(){t.closePath()}}function h2(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function p2(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function qa(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function J_(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function m2(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function y2(t){return function(e){return function(){t.textAlign=e}}}function x2(t){return function(e){return function(){t.textBaseline=e}}}function w2(t){return function(e){return function(){t.font=e}}}function N2(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function ur(t){return function(){t.save()}}function cr(t){return function(){t.restore()}}function Qi(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function v2(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const b_=t=>t,ic=t=>t,ac=t=>t,sc=t=>t,Ha=t=>t,T2=Ha("BaselineTop"),J2=Ha("BaselineMiddle"),b2=Ha("BaselineAlphabetic"),C2=Ha("BaselineBottom"),k2=sc("AlignLeft"),L2=sc("AlignRight"),S2=sc("AlignCenter"),uc=ac("BevelJoin"),cc=ac("RoundJoin"),gc=ac("MiterJoin"),fc=ic("Round"),_c=ic("Square"),dc=ic("Butt"),E2=b_("SourceOver"),P2=b_("Difference"),A2=t=>e=>x2(t)((()=>{if(e==="BaselineTop")return"top";if(e==="BaselineHanging")return"hanging";if(e==="BaselineMiddle")return"middle";if(e==="BaselineAlphabetic")return"alphabetic";if(e==="BaselineIdeographic")return"ideographic";if(e==="BaselineBottom")return"bottom";f()})()),G2=t=>e=>y2(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";f()})()),lc=t=>e=>{if(e==="BevelJoin")return nc(t)("bevel");if(e==="RoundJoin")return nc(t)("round");if(e==="MiterJoin")return nc(t)("miter");f()},hc=t=>e=>{if(e==="Round")return ec(t)("round");if(e==="Square")return ec(t)("square");if(e==="Butt")return ec(t)("butt");f()},C_=t=>e=>_2(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";f()})()),k_={foldrWithIndex:t=>e=>{const n=Ko(o=>{const i=o._1,a=o._2;return s=>t(i)(a)(s)})(e),r=qt(Bn);return o=>n(r(o))},foldlWithIndex:t=>e=>{const n=J(o=>i=>t(i._1)(o)(i._2))(e),r=qt(Bn);return o=>n(r(o))},foldMapWithIndex:t=>{const e=t.mempty;return n=>k_.foldrWithIndex(r=>o=>i=>t.Semigroup0().append(n(r)(o))(i))(e)},Foldable0:()=>Mt},dn={foldr:t=>e=>{const n=ye.foldr(t)(e);return r=>n((()=>{const o=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return o(i._5,kt("Cons",i._3,o(i._6,a)));f()};return o(r,V)})())}},I2=t=>{const e={append:(()=>{const n=t.compare;return r=>o=>Oe(n,Qe,r,o)})()};return{mempty:F,Semigroup0:()=>e}},Wi=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},Xr=function(t){return t.join("")},Er=function(t){return t.split("")},Oi=function(t){return t},gr=function(t){return t.length},L_=function(t){return function(e){return e.substr(0,t)}},ii=function(t){return function(e){return e.substring(t)}},S_=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},D2=t=>e=>{const n=S_(gr(e)-gr(t)|0)(e);return n.after===t?v("Just",n.before):w},mo=t=>e=>{const n=S_(gr(t))(e);return n.before===t?v("Just",n.after):w},R2=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},B2=function(t){return t()},F2=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},M2=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},yo=t=>BigInt(t),z2=t=>Number(t),$a=t=>e=>t+e,Ua=t=>e=>t*e,pc=t=>e=>t-e,E_=0n,Va=1n,P_=t=>e=>t^e,qi=t=>e=>t&e,mc=t=>e=>t<<e,yc=t=>e=>t>>e,Q2=t=>e=>t==e,W2=t=>e=>t===e?0:t>e?1:-1,O2={eq:Q2},A_={compare:t=>e=>{const n=W2(t)(e);return n===1?Me:n===0?Ze:Fe},Eq0:()=>O2},q2=F2(Vt)(w),H2=M2(Vt)(w),G_=function(t){throw new Error(t)},I_=(()=>{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"?Fe:r==="GT"?Me:ot.compare(e._2)(n._2)},Eq0:()=>t}})(),$2=t=>e=>Ce(t._1-e._1)+Ce(t._2-e._2),xo=t=>t,Xa=t=>t,Ge=Xa("North"),Ie=Xa("South"),Pr=Xa("East"),Ar=Xa("West"),Yr=xo("Rectangle"),U2=xo("Cylinder"),V2=xo("Parallelogram"),X2=xo("Diamond"),Y2=xo("Ellipse"),K2=xo("Document"),j2=xo("Cloud"),D_=J(sr)(0),Z2=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;f()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},Kr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Ya=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},R_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},ty=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}]},wo=t=>e=>{const n=We(a=>s=>({a,b:s,len:(()=>{const u=s.y-a.y,c=s.x-a.x;return Xe(c*c+u*u)})()}),t,It(1,t.length,t)),r=D_(U(a=>a.len)(n)),o=Z2(0)(r)(e*r),i=a=>s=>u=>{let c=a,g=s,d=u,l=!0,_;for(;l;){const h=c,p=g,m=d,y=Rt(x=>w,x=>N=>v("Just",{head:x,tail:N}),h);if(y.tag==="Nothing"){const x=t.length-1|0;if(x>=0&&x<t.length){l=!1,_=t[x];continue}l=!1,_=m;continue}if(y.tag==="Just"){if(p<=y._1.head.len){const x=y._1.head.len<=0?0:p/y._1.head.len;l=!1,_={x:y._1.head.a.x+(y._1.head.b.x-y._1.head.a.x)*x,y:y._1.head.a.y+(y._1.head.b.y-y._1.head.a.y)*x};continue}c=y._1.tail,g=p-y._1.head.len,d=m;continue}f()}return _};return 0<t.length?v("Just",i(n)(o)(t[0])):w},ey=t=>e=>{const n=Kr(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}},Hi=t=>D_(We(e=>n=>{const r=n.y-e.y,o=n.x-e.x;return Xe(o*o+r*r)},t,It(1,t.length,t))),xc={scale:1,tx:0,ty:0},ny=t=>e=>{const n=Kr(4)(.15*Ya(e.w)(e.h)),r=Kr(1)(t.w),o=Kr(1)(t.h),i=Kr(1)(e.w-2*n),a=Kr(1)(e.h-2*n),s=.55*Ya(i/r)(a/o);return{scale:s,tx:e.x+n+(i-r*s)/2-t.x*s,ty:e.y+n+(a-o*s)/2+2.5-t.y*s}},pe=t=>{const e=Rt(n=>w,n=>r=>v("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)));f()};return St(Zt(ye.foldr,n(t.nodes,V)))(ty)})(),...mn((()=>{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)));f()};return Zt(ye.foldr,n(t.edges,V))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>o=>({minX:Ya(r.minX)(o.x),minY:Ya(r.minY)(o.y),maxX:Kr(r.maxX)(o.x),maxY:Kr(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}}f()},ry=t=>e=>(n=>r=>o=>{let i=n,a=r,s=o,u=!0,c;for(;u;){const g=i,d=a,l=s,_=Rt(h=>w,h=>p=>v("Just",{head:h,tail:p}),d);if(_.tag==="Nothing"){u=!1,c=l;continue}if(_.tag==="Just"){const h=R_(_._1.head)(g.interiors);if(h.tag==="Nothing"){u=!1,c=l;continue}if(h.tag==="Just"){i=h._1,a=_._1.tail,s=(()=>{const p=ny(pe(h._1.layout))((()=>{const m=R_(_._1.head)(g.layout.nodes);if(m.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:Yr};if(m.tag==="Just")return m._1;f()})());return{scale:l.scale*p.scale,tx:l.scale*p.tx+l.tx,ty:l.scale*p.ty+l.ty}})();continue}}f()}return c})(t)(e)(xc),oy=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},iy=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},Ka=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;f()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},ay=t=>e=>n=>r=>{const o=pe(e);return n<=0||r<=0||o.w<=0||o.h<=0?1:t?oy(o.w/n)(o.h/r):iy(o.w/n)(o.h/r)},B_=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;if(t.widthPx<=0||t.heightPx<=0){const a=1/Ka(.05)(1)(e);return{w:n.w*a,h:n.h*a}}if(r>o){const a=1/Ka(.05)(1)(e);return{w:n.h*r*a,h:n.h*a}}const i=1/Ka(.05)(1)(e);return{w:n.w*i,h:n.w/r*i}},F_=t=>e=>n=>r=>o=>{const i=t+o/2,a=t+e-o/2,s=t+e/2,u=n+r/2;return o>=e?s:Ka(i)(a)(u)},M_=t=>e=>n=>r=>{const o=pe(t);return{x:F_(o.x)(o.w)(e.x)(e.w)(n),y:F_(o.y)(o.h)(e.y)(e.h)(r)}},$i=t=>e=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:ay(t)(e)(n.w)(n.h)}),sy=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=B_(e)(.65)(o),a=M_(n)(o)(i.w)(i.h),s={x:a.x-i.w/2,y:a.y-i.h/2,w:i.w,h:i.h};return{focus:r,paddedFocus:o,viewport:s,camera:$i(e.widthPx>0&&e.heightPx>0)(n)(s)}},uy=t=>e=>n=>r=>o=>{const i={x:o.x*r.scale+r.tx,y:o.y*r.scale+r.ty,w:o.w*r.scale,h:o.h*r.scale},a=t.padding*r.scale,s={x:i.x-a,y:i.y-a,w:i.w+a*2,h:i.h+a*2},u=B_(e)(.7)(s),c=M_(n)(s)(u.w)(u.h),g={x:c.x-u.w/2,y:c.y-u.h/2,w:u.w,h:u.h};return{footprint:i,viewport:g,camera:$i(e.widthPx>0&&e.heightPx>0)(n)(g)}},cy=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;return t.widthPx<=0||t.heightPx<=0?$i(t.widthPx>0&&t.heightPx>0)(e)((()=>{const i=n.w*.8,a=n.h*.8;return{x:n.x+n.w/2-i/2,y:n.y+n.h/2-a/2,w:i,h:a}})()):r>o?$i(t.widthPx>0&&t.heightPx>0)(e)((()=>{const i=n.w*.8,a=n.w/r*.8;return{x:n.x+n.w/2-i/2,y:n.y+n.h/2-a/2,w:i,h:a}})()):$i(t.widthPx>0&&t.heightPx>0)(e)((()=>{const i=n.h*r*.8,a=n.h*.8;return{x:n.x+n.w/2-i/2,y:n.y+n.h/2-a/2,w:i,h:a}})())},z_=t=>t,gy=(t,e)=>({tag:t,_1:e}),wc=t=>t,ai=(t,e)=>({tag:t,_1:e}),Nc=(t,e)=>({tag:t,_1:e}),Ui=wc("Animated"),fy=wc("StaticStill"),_y=wc("TitleCard"),dy=Nc("First"),Q_=z_("Forward"),W_=z_("Backward"),ly=ai("ExitNode"),O_=ge(A)(Mt),hy=t=>Ko(e=>n=>({nodes:Oe(A.compare,Qe,e.nodes,n.nodes),edges:Oe(A.compare,Qe,e.edges,n.edges)}))({nodes:F,edges:F})(t.keyframes),py=t=>e=>({entering:{nodes:Vn(A.compare,e.nodes,t.nodes),edges:Vn(A.compare,e.edges,t.edges)},leaving:{nodes:Vn(A.compare,t.nodes,e.nodes),edges:Vn(A.compare,t.edges,e.edges)},surviving:{nodes:Oa(A.compare,Qe,t.nodes,e.nodes),edges:Oa(A.compare,Qe,t.edges,e.edges)}}),ja=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},si=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Za=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},vc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},my=J(t=>e=>rt(A)(e)()(t))(F),yy=J(t=>e=>rt(A)(e)()(t))(F),xy=(()=>{const t=fn.unfoldr(Xn);return e=>t(_n("IterNode",e,Un))})(),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 a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},H_=ge(A)(Mt),Tc=t=>{const e=Rt(n=>w,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>o=>({minX:ja(r.minX)(o.x),minY:ja(r.minY)(o.y),maxX:si(r.maxX)(o.x),maxY:si(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}}f()},wy=t=>e=>n=>my(St(Zt(dn.foldr,n))(r=>{const o=Za(r)(t);if(o.tag==="Just")return dt(i=>!vc(i)(e),[o._1.source,o._1.target]);if(o.tag==="Nothing")return[];f()})),Ny=t=>t.kind.tag==="SendToken"?v("Just",b(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):w,vy=t=>t.tag==="DataFlow"?vt(Ny)(t._1.events):[],Ty=t=>e=>yy(vt(n=>vc(n._2.source)(e)||vc(n._2.target)(e)?v("Just",n._1):w)(xy(t))),fr=t=>{const e=Rt(n=>w,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>o=>({minX:ja(r.minX)(o.x),minY:ja(r.minY)(o.y),maxX:si(r.maxX)(o.x+o.w),maxY:si(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}}f()},Jc=t=>e=>n=>{if(n.tag==="Leaf")return pe(t);const r=Ty(e)(n),o=[...vt(i=>{const a=q_(i)(t.nodes);return a.tag==="Just"?v("Just",{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}):w})(Zt(dn.foldr,Oe(A.compare,Qe,n,wy(e)(n)(r)))),...vt(i=>{const a=Za(i)(t.edges);return a.tag==="Just"?v("Just",Tc(a._1)):w})(Zt(dn.foldr,r))];return o.length===0?pe(t):fr(o)},ts=t=>e=>n=>{const r=[...vt(o=>o)([(()=>{const o=Za(n)(t.edges);return o.tag==="Just"?v("Just",Tc(o._1)):w})()]),...(()=>{const o=Za(n)(e);if(o.tag==="Just")return vt(i=>{const a=q_(i)(t.nodes);return a.tag==="Just"?v("Just",{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}):w})([o._1.source,o._1.target]);if(o.tag==="Nothing")return[];f()})()];return r.length===0?Jc(t)(e)(F):fr(r)},Mn=t=>e=>{const n=pe(t),r=n.w/si(1e-4)(e.zoom),o=n.h/si(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-o/2,w:r,h:o}},Jy=t=>Oe(A.compare,Qe,H_(U(e=>b(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),H_(St(t.scenes)(vy))),bc=t=>t,by=t=>t,$_=bc("Linear"),_r=bc("EaseInOutQuad"),Cy=bc("SpringBouncy"),Vi=t=>e=>n=>{const r=Xe(1-e*e),o=t*r;return 1-ei(-e*t*n)*(Sn(o*n)+e/r*yn(o*n))},ky=t=>{const e=ot.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;f()})(),r=ot.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;f()},es=t=>e=>(()=>{if(t==="Linear")return by;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-ju(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*ei(-6*n);if(t==="SpringBouncy")return Vi(6)(.7);f()})()(ky(e)),ns=t=>t,U_=t=>t,V_=t=>t,En=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},rs=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;f()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},os=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},Ly=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?Fe:n==="GT"?Me:ot.compare(t._2)(e._2)},Sy=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Ey=V_("Hold"),Py=V_("Gap"),Pn=U_("LinearLerp"),jr=U_("ComposedLogLerp"),Cc=ns("Overview"),Xi=ns("DiveHome"),Zr=ns("DiveTransition"),is=ns("ActionFocus"),Ay=t=>e=>n=>{const r=t.widthPx>0&&t.heightPx>0,o=t.widthPx/En(1e-6)(t.heightPx),i=pe(e),a=i.w/En(1e-6)(n.zoom),s=i.h/En(1e-6)(n.zoom),u=a/En(1e-6)(s),c=r&&o<u?a/o:s,g=r&&o>u?s*o:a;return{x:n.center.x-g/2,y:n.center.y-c/2,w:g,h:c}},kc=t=>e=>n=>{const r=n.center.y-e.center.y,o=n.center.x-e.center.x,i=Xe(o*o+r*r),a=n.zoom-e.zoom,s=a<0?-a:a;return rs(t.minTransition)(t.maxTransition)(En(t.panSpeed<=0?t.minTransition:i/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:s/t.zoomSpeed))},Gy=t=>({startT:t.startT,endT:t.endT,fromCam:t.fromCam,toCam:t.toCam,easing:t.easing,interp:t.interp,intent:t.intent}),Iy=J(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:Ct(t)(e)})([]),as=t=>e=>n=>{const r=rs(0)(1)((n-t)/En(1e-6)(e-t));return r*r*r*(r*(r*6-15)+10)},Dy=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})()})()})()},Ry=t=>e=>t.tag==="Just"?e.tag==="Just"&&Dy(t._1)(e._1):t.tag==="Nothing"&&e.tag==="Nothing",X_=t=>e=>n=>r=>({center:{x:r.center.x*n.scale+n.tx,y:r.center.y*n.scale+n.ty},zoom:r.zoom*pe(t).w/En(1e-6)(n.scale*pe(e).w)}),Lc=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:ei((()=>{const o=Qa(En(1e-6)(t.zoom));return o+(Qa(En(1e-6)(e.zoom))-o)*r})())}),By=J(t=>e=>{if(t.tag==="Nothing")return v("Just",e);if(t.tag==="Just")return e.endT>t._1.endT?v("Just",e):v("Just",t._1);f()})(w),Fy=t=>e=>n=>r=>{if(t<=0)return r;const o=ei(-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:ei((()=>{const i=Qa(En(1e-6)(r.zoom));return i+(Qa(En(1e-6)(n.zoom))-i)*o})())}},Sc=t=>e=>n=>e.zoom>=t.zoom?as(.3)(1)(n):as(0)(.7)(n),My={widthPx:0,heightPx:0},zy={padding:24,easing:_r,minimumReadableLabelPx:11,minimumVisibleLabelPx:5,labelBasePx:11,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:0},ui=t=>e=>n=>r=>o=>{const i=Ay(e)(n)(r),a=o.x-t.padding,s=o.y-t.padding;return a>=i.x&&s>=i.y&&a+o.w+t.padding*2<=i.x+i.w&&s+o.h+t.padding*2<=i.y+i.h},Qy=t=>e=>n=>r=>o=>k_.foldlWithIndex(i=>a=>s=>{const u=(()=>{if(s.kind==="Hold"){const c=(()=>{if(i===0)return s.toCam;if(s.focus.tag==="Just"){if(s.intent==="ActionFocus")return ui(t)(e)(n)(a.prev)(s.focus._1)?a.prev:ui(t)(e)(n)({center:a.prev.center,zoom:s.toCam.zoom})(s.focus._1)?{...s.toCam,center:a.prev.center}:{...s.toCam,center:{...s.toCam.center,x:(()=>{const g=pe(n).w/En(1e-6)(s.toCam.zoom);if(g<=0)return s.toCam.center.x;const d=s.focus._1.x+s.focus._1.w/2,l=e.widthPx<=0?0:os(g/4)(6*g/e.widthPx),_=a.prev.center.x+g/2-l,h=d<a.prev.center.x-g/2+l?d-l+g/2:d>_?d+l-g/2:a.prev.center.x,p=pe(n);return g>=p.w?p.x+p.w/2:rs(p.x+g/2)(p.x+p.w-g/2)(h)})()}};if(ui(t)(e)(n)(a.prev)(s.focus._1))return a.prev;if(ui(t)(e)(n)({center:a.prev.center,zoom:s.toCam.zoom})(s.focus._1))return{...s.toCam,center:a.prev.center}}return s.toCam})();return{startT:s.startT,endT:s.endT,fromCam:c,toCam:c,easing:s.easing,interp:Pn,focus:s.focus,intent:s.intent}}if(s.kind==="Gap")return{startT:s.startT,endT:s.endT,fromCam:a.prev,toCam:(()=>{const c=i+1|0,g=Lr(Vt,w,d=>d.kind==="Hold",c<1?o:It(c,o.length,o));if(g.tag==="Just"){const d=(i+1|0)+g._1|0;return d>=0&&d<o.length?(()=>{if(o[d].focus.tag==="Just")return ui(t)(e)(n)(a.prev)(o[d].focus._1);if(o[d].focus.tag==="Nothing")return!1;f()})()?a.prev:o[d].fromCam:a.prev}if(g.tag==="Nothing")return a.prev;f()})(),easing:s.easing,interp:Pn,focus:w,intent:s.intent};f()})();return{acc:Ct(a.acc)(u),prev:u.toCam}})({acc:[],prev:r})(o).acc,Wy=t=>e=>n=>r=>o=>i=>{const a=(u,c)=>os(kc(t)(u.toCam)(c.toCam))(u.endT-u.startT),s=J(u=>c=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:v("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 ui(t)(e)(n)(u.pending._1.toCam)(c.focus._1);if(c.focus.tag==="Nothing")return!1;f()})()||(()=>{const g=u.pending._1.toCam.center.x-c.toCam.center.x;return(g<0?-g<8:g<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})()})()})()||a(u.pending._1,c)<=0)return{acc:Ct(u.acc)(u.pending._1),pending:v("Just",c)};if((()=>{const g=c.startT;return le(d=>Ce(d-g)<1e-4,o)})()){const g={startT:c.startT,endT:c.startT+os(kc(t)(u.pending._1.toCam)(c.toCam))(c.endT-c.startT),fromCam:u.pending._1.toCam,toCam:c.toCam,easing:c.easing,interp:Pn,focus:c.focus,intent:c.intent},d={...c,startT:g.endT,fromCam:c.toCam};return d.startT<d.endT?{acc:Ct(Ct(u.acc)(u.pending._1))(g),pending:v("Just",d)}:{acc:Ct(u.acc)(u.pending._1),pending:v("Just",g)}}return{acc:Ct(Ct(u.acc)({...u.pending._1,endT:c.startT-a(u.pending._1,c)}))({startT:c.startT-a(u.pending._1,c),endT:c.startT,fromCam:u.pending._1.toCam,toCam:c.toCam,easing:c.easing,interp:Pn,focus:c.focus,intent:c.intent}),pending:v("Just",c)}}f()})({acc:[],pending:w})(i);if(s.pending.tag==="Nothing")return s.acc;if(s.pending.tag==="Just")return Ct(s.acc)(s.pending._1);f()},Oy=t=>e=>n=>{const r=e.w+n*2,o=e.h+n*2,i=pe(t);return r<=0||o<=0||i.w<=0||i.h<=0?1:os(i.w/r)(i.h/o)},qy=t=>e=>n=>e.zoom>=t.zoom?Lc(t)(e)(as(0)(.45)(n))(Sc(t)(e)(n)):Lc(t)(e)(as(.55)(1)(n))(Sc(t)(e)(n)),Hy=t=>e=>n=>{const r=n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT),o=es(n.easing)(rs(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 Lc(n.fromCam)(n.toCam)(o)(o);if(n.interp==="ComposedLogLerp")return qy(n.fromCam)(n.toCam)(r);f()},$y=t=>e=>{if(t.tag==="Just"){if(e.tag==="Just")return v("Just",fr([t._1,e._1]));if(e.tag==="Nothing")return v("Just",t._1);f()}if(t.tag==="Nothing"){if(e.tag==="Just")return v("Just",e._1);if(e.tag==="Nothing")return w}f()},Uy=J(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?v("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")&&Ry(r._1.focus)(e.focus))&&(()=>{const o=r._1.toCam.center.x-e.toCam.center.x;return(o<0?-o<8:o<8)&&(()=>{const i=r._1.toCam.center.y-e.toCam.center.y;return(i<0?-i<8:i<8)&&(()=>{const a=r._1.toCam.zoom-e.toCam.zoom;return a<0?-a<.08:a<.08})()})()})()?Ct((()=>{const o=t.length-1|0;return o<1?[]:It(0,o,t)})())({...r._1,endT:e.endT,focus:$y(r._1.focus)(e.focus)}):Ct(t)(e)})([]),Vy=t=>{const e=Pt(n=>r=>Ly(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;f()})(),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;f()})(),n.startT)))(t);return 0<e.length?v("Just",e[0]):w},Ec=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:En(r)(Oy(e)(n)(t.padding))}),Xy=t=>e=>n=>r=>o=>i=>{const a=Ec(t)(n)(pe(n))(0),s=dt(c=>c>=0&&c<=r,Iy(Pt(ot.compare)([0,r,...o,...St(i)(c=>[c.startT,c.endT])]))),u=(c,g)=>le(d=>d.priority>=1,dt(d=>d.startT<=g&&g<d.endT,i))?sy(t)(e)(n)(fr(c)).camera:Ec(t)(n)(fr(c))(0);return U(Gy)(Wy(t)(e)(n)(a)(o)(Uy(Qy(t)(e)(n)(a)(vt(c=>{const g=(c._1+c._2)/2;if(c._2<=c._1)return w;const d=U(l=>l.bbox)(dt(l=>l.priority===J(Sy)(0)(U(_=>_.priority)(dt(_=>_.startT<=g&&g<_.endT,i))),dt(l=>l.startT<=g&&g<l.endT,i)));return d.length===0?v("Just",{kind:Py,startT:c._1,endT:c._2,fromCam:a,toCam:a,easing:t.easing,focus:w,intent:Cc}):v("Just",{kind:Ey,startT:c._1,endT:c._2,fromCam:u(d,g),toCam:u(d,g),easing:t.easing,focus:v("Just",fr(d)),intent:le(l=>l.priority>=1,dt(l=>l.startT<=g&&g<l.endT,i))?is:Cc})})(We(Bn,s,It(1,s.length,s)))))))},No=t=>e=>n=>r=>{const o=Vy(dt(i=>r>=i.startT&&r<i.endT,n));if(o.tag==="Just")return{camera:Hy()(r)(o._1),intent:o._1.intent};if(o.tag==="Nothing"){const i=By(n);return i.tag==="Just"&&r>=i._1.endT?{camera:i._1.toCam,intent:i._1.intent}:{camera:(()=>{const a=Ec(t)(e)(pe(e))(0);return 0<n.length?n[0].fromCam:a})(),intent:0<n.length?n[0].intent:Cc}}f()};function to(t){return t.charCodeAt(0)}function Y_(t){return String.fromCharCode(t)}const zn=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},Gr=function(t){return function(e){return e.split(t)}},ss=function(t){return t.trim()},dr=function(t){return function(e){return e.join(t)}};var Yy=typeof Array.from=="function",Ky=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",jy=typeof String.prototype.fromCodePoint=="function",Zy=typeof String.prototype.codePointAt=="function";const tx=function(t){return Zy?function(e){return e.codePointAt(0)}:t},ex=function(t){return jy?String.fromCodePoint:t},nx=function(t){return function(e){return Ky?function(n){for(var r="",o=n[Symbol.iterator](),i=0;i<e;++i){var a=o.next();if(a.done)return r;r+=a.value}return r}:t(e)}},rx=function(t){return function(e){return Yy?function(n){return Array.from(n,e)}:t}},us=t=>{const e=gr(t);if(e===0)return w;if(e===1)return v("Just",{head:to(Wi(0)(t)),tail:""});const n=to(Wi(1)(t)),r=to(Wi(0)(t));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?v("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:ii(2)(t)}):v("Just",{head:r,tail:ii(1)(t)})},ox=t=>{const e=us(t);return e.tag==="Just"?v("Just",b(e._1.head,e._1.tail)):w},ix=t=>fn.unfoldr(ox)(t),K_=tx(t=>{const e=to(Wi(0)(t));if(55296<=e&&e<=56319&&gr(t)>1){const n=to(Wi(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),ci=rx(ix)(K_),j_=t=>ci(t).length,Pc=t=>Oi(t>=0&&t<=65535?Y_(t):t<0?"\0":"\uFFFF"),ax=ex(t=>t<=65535?Pc(t):Pc(kr(t-65536|0,1024)+55296|0)+Pc(Vr(t-65536|0)(1024)+56320|0)),Z_=t=>e=>{if(t<1)return"";const n=us(e);return n.tag==="Just"?ax(n._1.head)+Z_(t-1|0)(n._1.tail):e},ze=nx(Z_),sx=t=>e=>e===""?w:v("Just",K_(e)),ux=t=>t,t1=t=>e=>{const n=e.vw/e.vh,r=e.vh*t,o={...e,vx:e.vx-(r-e.vw)/2,vw:r},i=e.vw/t,a={...e,vy:e.vy-(i-e.vh)/2,vh:i};return t<=0||e.vw<=0||e.vh<=0?e:t>n?o:t<n?a:e},e1=t=>e=>t.width<=0||t.height<=0?e:t1(t.width/t.height)(e),cx=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;f()},n1=t=>t,cs=(t,e)=>({tag:t,_1:e}),Qn=(t,e,n)=>({tag:t,_1:e,_2:n}),r1=t=>t,gi=(t,e,n,r,o,i,a,s,u)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:a,_7:s,_8:u}),Ac=r1("PlopIn"),gx=r1("PlopOut"),fx=n1("DiveIn"),_x=n1("DiveOut"),we=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Ye=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},o1=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},i1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},vo=Fa(Zo),a1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},dx=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},s1=(()=>{const t=fn.unfoldr(Xn);return e=>t(_n("IterNode",e,Un))})(),lx=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},Yn=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;f()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},gs=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},hx=t=>t,u1=t=>e=>n=>n<t?0:n>1-e?1:(n-t)/we(.05)(1-t-e),px=t=>e=>t.labelBasePx*.62*et(J(o1)(0)(U(j_)(St(e)(n=>Gr(`
|
|
3
|
+
`)(n))))),c1=t=>e=>{if(t.length===0)return e;const n=6.82*et(J(o1)(0)(U(j_)(St(t)(g=>Gr(`
|
|
4
|
+
`)(g))))),r=n/2+14,o=e.y+e.h/2,i=o-5-8,a=we(e.y+e.h)(i+12.6)-Ye(e.y)(i-12.6),s=e.x+e.w/2,u=s+13+n/2,c=we(e.x+e.w)(u+r)-Ye(e.x)(u-r);return{x:s-c/2,y:o-a/2,w:c,h:a}},Gc=(()=>{const t=J(e=>n=>{const r=e.previous.tag==="Just"&&Ce(e.previous._1.endT-n.startT)<1e-4?{...n,fromCam:e.previous._1.toCam}:n;return{previous:v("Just",r),spans:Ct(e.spans)(r)}})({previous:w,spans:[]});return e=>t(e).spans})(),g1=t=>e=>n=>{const r=(t+e)/2,o=n-r,i=o<0?-1:1,a=(e-t)/2,s=a*.15,u=a-s,c=o<0?-o:o;return e<=t?(t+e)/2:c<=u?n:r+i*(a-s*ei(-(c-u)/s))},Ic=t=>e=>{const n=i1(e)(t.keyframes);if(n.tag==="Nothing")return F;if(n.tag==="Just")return n._1.nodes;f()},f1=t=>e=>{if(e<t.startT)return Qn("AtKeyframe",t.initialKeyframe);const n=jt(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Qn("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Qn("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return Qn("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode"||n._1.scene.tag==="StepScene")return Qn("AtKeyframe",t.initialKeyframe);f()}if(n.tag==="Nothing")return Qn("AtKeyframe",J(cx)(t.initialKeyframe)(t.spans));f()},fs=t=>e=>n=>r=>{const o=jt(i=>vo(i.path)(e)&&(Ce(i.endT-n)<1e-4||Ce(i.startT-r)<1e-4))(t.segments);if(o.tag==="Just")return v("Just",o._1);if(o.tag==="Nothing")return jt(i=>vo(i.path)(e))(t.segments);f()},Dc=t=>e=>{const n=i1(e)(t.keyframes);if(n.tag==="Nothing")return F;if(n.tag==="Just")return n._1.edges;f()},_1=(()=>{const t=(n,r,o,i,a)=>{let s=n,u=r,c=o,g=i,d=a,l=!0,_;for(;l;){if(s===0){const h=Rt(p=>w,p=>m=>v("Just",{head:p,tail:m}),u);if(h.tag==="Nothing"){l=!1,_=[];continue}if(h.tag==="Just"){s=1,u=h._1.head,c=h._1.head,g=!1,d=h._1.tail;continue}f()}if(s===1){const h=u,p=c,m=g,y=d,x=Rt(N=>w,N=>T=>v("Just",{head:N,tail:T}),y);if(x.tag==="Just"&&p.intent==="Overview"&&x._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)&&!(x._1.head.fromCam.zoom===x._1.head.toCam.zoom&&x._1.head.fromCam.center.x===x._1.head.toCam.center.x&&x._1.head.fromCam.center.y===x._1.head.toCam.center.y)&&Ce(p.toCam.center.x-x._1.head.fromCam.center.x)<1e-4&&Ce(p.toCam.center.y-x._1.head.fromCam.center.y)<1e-4&&Ce(p.toCam.zoom-x._1.head.fromCam.zoom)<1e-4&&Ce(p.endT-x._1.head.startT)<1e-4){s=1,u=h,c=x._1.head,g=!0,d=x._1.tail;continue}l=!1,_=[m?{...h,endT:p.endT,toCam:p.toCam,easing:p.easing,interp:Pn}:h,...e(y)]}}return _},e=n=>t(0,n);return e})(),mx=t=>e=>{const n=pe(e),r=e1({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}},Rc=t=>e=>n=>r=>{const o=we(n.center.x-r.x)(r.x+r.w-n.center.x),i=we(n.center.y-r.y)(r.y+r.h-n.center.y),a=mx(t)(e);return Ye(o<=0?n.zoom:a.w/(o*2))(i<=0?n.zoom:a.h/(i*2))},d1=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r,u=Sr(s);if(u.tag==="Just"&&u._1.last.intent==="Overview"){n=[u._1.last,...a],r=u._1.init;continue}o=!1,i={prefix:s,overview:a}}return i},yx=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r,u=Rt(c=>w,c=>g=>v("Just",{head:c,tail:g}),s);if(u.tag==="Just"&&u._1.head.intent==="Overview"){n=Ct(a)(u._1.head),r=u._1.tail;continue}o=!1,i={overview:a,rest:s}}return i},To=t=>e=>n=>r=>o=>{const i={width:e.widthPx,height:e.heightPx},a=e1(i)((()=>{const s=Mn(n)(o);return{vx:s.x,vy:s.y,vw:s.w,vh:s.h}})());return t.labelBasePx*r.placement.scale*(i.width<=0||a.vw<=0?0:i.width/a.vw)},xx=t=>e=>n=>r=>o=>{const i=To(t)(e)(n)(r)(o);return i<=t.minimumReadableLabelPx?o:{...o,zoom:o.zoom*t.minimumReadableLabelPx/i}},wx=t=>e=>n=>{const r=vt(o=>o.scene.tag==="StepScene"?v("Just",o.startT):w)(e.spans);return J(o=>i=>{const a=Lr(Vt,w,s=>s.startT<i+1e-4&&s.endT>=i-1e-4,o);if(a.tag==="Nothing")return o;if(a.tag==="Just"){const s=a._1>=0&&a._1<o.length?v("Just",o[a._1]):w;if(s.tag==="Nothing")return o;if(s.tag==="Just"){if(s._1.startT>=i-1e-4)return o;const u=jt(p=>p>i+1e-4)(r),c=(()=>{if(u.tag==="Nothing")return e.endT;if(u.tag==="Just")return u._1;f()})(),g=Pt(ot.compare)(vt(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")?v("Just",p.startT):w)(e.windows)),d=0<g.length?g[0]:i,l=a._1+1|0,_=l<1?o:It(l,o.length,o),h=Lr(Vt,w,p=>p.intent==="ActionFocus"&&p.startT>=d-1e-4&&p.startT<c-1e-4,_);if(h.tag==="Nothing")return o;if(h.tag==="Just"){const p=h._1>=0&&h._1<_.length?v("Just",_[h._1]):w;if(p.tag==="Nothing")return o;if(p.tag==="Just"){const m=(a._1+h._1|0)+2|0,y=m<1?o:It(m,o.length,o),x=s._1.toCam.zoom===p._1.toCam.zoom&&s._1.toCam.center.x===p._1.toCam.center.x&&s._1.toCam.center.y===p._1.toCam.center.y?s._1.fromCam:s._1.toCam,N=Ct(a._1<1?[]:It(0,a._1,o))({...s._1,endT:i,toCam:x}),T=p._1.startT-i;if(T<=1e-4)return[...N,{...p._1,fromCam:x},...y];const C=x.zoom===p._1.toCam.zoom&&x.center.x===p._1.toCam.center.x&&x.center.y===p._1.toCam.center.y,L=C?i+0:i+Ye(T)(kc(t)(x)(p._1.toCam)),S={...p._1,startT:L,endT:p._1.startT,fromCam:p._1.toCam,toCam:p._1.toCam},P={...p._1,startT:i,endT:L,fromCam:x};return[...N,...C?[]:[P],...S.endT>S.startT+1e-4?[S]:[],{...p._1,fromCam:p._1.toCam},...y]}}}}f()})(n)(r)},Nx=t=>e=>n=>r=>({...r,fromCam:X_(t)(e)(n)(r.fromCam),toCam:X_(t)(e)(n)(r.toCam)}),l1=t=>e=>t.widthPx<=0?0:Ye(e/4)(32*e/t.widthPx),vx=t=>e=>n=>r=>o=>{const i=l1(e)(n),a=r+n/2-i;return o.x<r-n/2+i?o.x-i+n/2:o.x+o.w>a?o.x+o.w+i-n/2:r},Tx=t=>e=>n=>le(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),Jx=t=>e=>n=>le(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),bx=t=>e=>n=>le(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),Cx=t=>e=>n=>le(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),_s=t=>e=>n=>le(r=>n(r)&&e>=r.startT&&e<r.endT,t),kx=t=>e=>n=>{if(e.length===0)return n;const r=Ye(160)(px(t)(e)+31)/2,o=Ye(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}},Lx=t=>e=>n=>{const r=t.padding*.75,o=et(8);return Ma(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:ts(e)(n)(i.target._1),priority:1}];if(i.target._2.tag==="Retract")return[];f()}if(i.target.tag==="TokenWindow"){const a=a1(i.target._2)(e.edges);if(a.tag==="Just"){const s=(()=>{if(i.target._3==="Forward")return a._1;if(i.target._3==="Backward")return ce(a._1);f()})();return St(Kt(0,7))(u=>{const c=i.startT+(i.endT-i.startT)*(et(u)/o),g=(()=>{const d=i.startT+(i.endT-i.startT)*(et(u+1|0)/o);return{startT:c,endT:d,box:(()=>{const l=wo(s)(u1(i.target._7)(i.target._8)(((c+d)/2-i.startT)/we(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};f()})()}})();return[{startT:g.startT,endT:g.endT,bbox:c1(i.target._6)(g.box),priority:1}]})}if(a.tag==="Nothing")return[{startT:i.startT,endT:i.endT,bbox:c1(i.target._6)(ts(e)(n)(i.target._2)),priority:1}];f()}if(i.target.tag==="FillWindow")return[{startT:i.startT,endT:i.endT,bbox:kx(t)(i.target._3)(Jc(e)(n)(oe("Node",1,1,i.target._2,void 0,F,F))),priority:1}];f()})},Sx=t=>e=>n=>r=>o=>i=>{if(o.tag==="Nothing")return i.zoom;if(o.tag==="Just")return we(0)(Rc(e)(n)(i)((()=>{const a=t.padding*r.placement.scale;return{x:o._1.x-a,y:o._1.y-a,w:o._1.w+a*2,h:o._1.h+a*2}})()));f()},Ex=t=>e=>{const n=f1(t)(e);if(n.tag==="AtKeyframe")return Ic(t)(n._1);if(n.tag==="InTransition")return Oe(A.compare,Qe,Ic(t)(n._1),Ic(t)(n._2));f()},Px=t=>e=>n=>_s(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n&&r.target._2==="PlopOut")?!0:Jx(t.windows)(e)(n)?!1:_s(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n)?!0:bx(t.windows)(e)(n)?!1:dx(n)(Ex(t)(e)),h1=t=>e=>vt(n=>Px(t)(e)(n._1)?v("Just",{x:n._2.x,y:n._2.y,w:n._2.w,h:n._2.h}):w)(s1(t.layout.nodes)),Ax=t=>e=>{const n=h1(t)(e);return n.length===0?w:v("Just",fr(n))},Gx=t=>vt(e=>{const n=Ax(t)(we(e.startT)(e.endT-1e-4));if(n.tag==="Nothing")return w;if(n.tag==="Just")return v("Just",{startT:e.startT,endT:e.endT,bbox:n._1,priority:0});f()}),Ix=t=>e=>n=>r=>o=>[...Gx(o)(dt(i=>i.startT>=o.startT&&i.endT<=o.endT,r.spans)),...Lx(t)(o.layout)(n)(o.windows)],Dx=t=>e=>n=>r=>o=>i=>Xy(t)(e)(i.layout)(o.endT)(vt(a=>a.scene.tag==="StepScene"?v("Just",a.startT):w)(i.spans))(Ix(t)(n)(r)(o)(i)),Rx=t=>e=>{const n=f1(t)(e);if(n.tag==="AtKeyframe")return Dc(t)(n._1);if(n.tag==="InTransition")return Oe(A.compare,Qe,Dc(t)(n._1),Dc(t)(n._2));f()},Bx=t=>e=>n=>_s(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n)?!0:Tx(t.windows)(e)(n)?!1:_s(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._1===n)?!0:Cx(t.windows)(e)(n)?!1:lx(n)(Rx(t)(e)),Fx=t=>e=>{const n=[...h1(t)(e),...vt(r=>Bx(t)(e)(r._1)?v("Just",Tc(r._2)):w)(s1(t.layout.edges))];return n.length===0?w:v("Just",fr(n))},Mx=t=>e=>n=>{const r=Mn(t)(n);return e.x>=r.x&&e.x+e.w<=r.x+r.w},p1=t=>e=>n=>r=>n>=e?Yn(t+e-n/2)(t+n/2)(r):t+e/2,m1=t=>e=>n=>r=>{if((()=>{const a=Mn(e)(n);return r.x>=a.x&&r.y>=a.y&&r.x+r.w<=a.x+a.w&&r.y+r.h<=a.y+a.h})())return n;const o={...n,zoom:Ye(n.zoom)(Rc(t)(e)({...n,center:{x:r.x+r.w/2,y:r.y+r.h/2}})(r))},i=Mn(e)(o);return{...o,center:{x:p1(r.x)(r.w)(i.w)(n.center.x),y:p1(r.y)(r.h)(i.h)(n.center.y)}}},y1=t=>e=>n=>r=>o=>i=>a=>{if(o.tag==="Nothing")return a;if(o.tag==="Just"){const s=t.padding*r.placement.scale,u={x:o._1.x-s,y:o._1.y-s,w:o._1.w+s*2,h:o._1.h+s*2},c={x:u.x+u.w/2,y:u.y+u.h/2},g={...a,center:c},d={...g,zoom:Rc(e)(n)(g)(u)},l=Mn(n)(d);return i.tag==="Nothing"?{...d,center:{x:l.w>=o._1.w?o._1.x+o._1.w/2:Yn(o._1.x+l.w/2)(o._1.x+o._1.w-l.w/2)(c.x),y:l.h>=o._1.h?o._1.y+o._1.h/2:Yn(o._1.y+l.h/2)(o._1.y+o._1.h-l.h/2)(c.y)}}:i.tag==="Just"?{...d,center:{x:l.w>=o._1.w?o._1.x+o._1.w/2:Yn(o._1.x+l.w/2)(o._1.x+o._1.w-l.w/2)(i._1.x+i._1.w/2),y:l.h>=o._1.h?o._1.y+o._1.h/2:Yn(o._1.y+l.h/2)(o._1.y+o._1.h-l.h/2)(i._1.y+i._1.h/2)}}:{...d,center:{x:(()=>{if(l.w>=o._1.w)return o._1.x+o._1.w/2;f()})(),y:(()=>{if(l.h>=o._1.h)return o._1.y+o._1.h/2;f()})()}}}f()},x1=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=we(o.lo)(e.x+e.w-n/2),c=Ye(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=we(o.lo)(i),c=Ye(o.hi)(i);return u<=c?{lo:u,hi:c}:o}const a=we(o.lo)(e.x+n/2),s=Ye(o.hi)(e.x+e.w-n/2);return a<=s?{lo:a,hi:s}:o},zx=t=>e=>n=>n.endT<=t||n.startT>=e?w:v("Just",{...n,startT:we(t)(n.startT),endT:Ye(e)(n.endT)}),Qx=t=>e=>n=>r=>o=>i=>vt(zx(i.startT)(i.endT))(U(Nx(n)(i.layout)(i.placement))(Dx(t)(e)(r)(i.edgeEndpoints)(o)(i))),w1=t=>e=>n=>r=>{const o=pe(t),i=Ye(r.zoom)(o.w/we(1e-4)(e.w));return{...r,center:{...r.center,x:(()=>{const a=x1(o)(e)(o.w/we(1e-4)(i));return Yn(a.lo)(a.hi)(n.center.x)})()},zoom:i}},Wx=t=>e=>n=>r=>o=>i=>a=>s=>{const u=l1(e)(s),c=pe(n),g={x:c.x-u,y:c.y-u,w:c.w+u*2,h:c.h+u*2},d=(()=>{if(o.tag==="Nothing")return a.center.x;if(o.tag==="Just")return vx()(e)(s)(i.center.x)(o._1);f()})();if(r.tag==="Nothing"){const l=g.x+g.w/2;return s>=g.w?Yn(l)(l)(d):Yn(g.x+s/2)(g.x+g.w-s/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(s<l.w){const h=g.x+g.w/2;return s>=g.w?Yn(h)(h)(d):Yn(g.x+s/2)(g.x+g.w-s/2)(d)}const _=x1(g)(l)(s);return Yn(_.lo)(_.hi)(d)}f()},Ox=t=>e=>n=>r=>o=>i=>a=>{const s=Mn(n)(a);return s.w<=0?a:{...a,center:{...a.center,x:Wx()(e)(n)(r)(o)(i)(a)(s.w)}}},qx=t=>e=>n=>{const r=pe(t),o=r.h/we(1e-4)(n.zoom),i=r.w/we(1e-4)(n.zoom);return{...n,center:{x:i>=e.w?e.x+e.w/2:g1(e.x+i/2)(e.x+e.w-i/2)(n.center.x),y:o>=e.h?e.y+e.h/2:g1(e.y+o/2)(e.y+e.h-o/2)(n.center.y)}}},Jo=t=>e=>n=>qx(t)((()=>{const r=e*n.placement.scale,o=pe(n.layout);return{x:o.x*n.placement.scale+n.placement.tx-r,y:o.y*n.placement.scale+n.placement.ty-r,w:o.w*n.placement.scale+r*2,h:o.h*n.placement.scale+r*2}})()),Hx=t=>e=>n=>r=>{const o=Mn(t)(r),i=pe(t),a=s=>{const u=Jo(t)(e)(n)(s);return Jo(t)(e)(n)({...u,zoom:we(u.zoom)(we(i.w/we(1e-4)(2*Ye(u.center.x-o.x)(o.x+o.w-u.center.x)))(i.h/we(1e-4)(2*Ye(u.center.y-o.y)(o.y+o.h-u.center.y))))})};return s=>a(a(s))},$x=t=>e=>n=>r=>Jo(n)(t.padding)(r)(uy(t)(e)(n)(r.placement)(pe(r.layout)).camera),N1=t=>e=>n=>r=>o=>{const i=$x(t)(e)(n)(o),a=jt(s=>s.direction==="DiveIn"&&vo(s.childPath)(o.path))(r.dives);if(a.tag==="Just"){const s=fs(r)(a._1.parentPath)(a._1.startT)(a._1.endT);if(s.tag==="Just"){const u=gs(a._1.node)(s._1.layout.nodes);if(u.tag==="Just"){const c=u._1.w*s._1.placement.scale,g=u._1.h*s._1.placement.scale,d=Ye(c)(g*2),l=cy(e)(n)({h:g,w:d,x:u._1.x*s._1.placement.scale+s._1.placement.tx+(c-d)*.5,y:u._1.y*s._1.placement.scale+s._1.placement.ty});return Hx(n)(t.padding)(o)(l)(l.zoom>i.zoom?l:i)}if(u.tag==="Nothing")return i;f()}if(s.tag==="Nothing")return i;f()}if(a.tag==="Nothing")return i;f()},v1=t=>e=>n=>r=>o=>{const i=Mn(n)(o);return(()=>{const a=pe(r.layout),s=a.x*r.placement.scale+r.placement.tx,u=a.y*r.placement.scale+r.placement.ty;return s>=i.x&&u>=i.y&&s+a.w*r.placement.scale<=i.x+i.w&&u+a.h*r.placement.scale<=i.y+i.h})()&&To(t)(e)(n)(r)(o)>=t.minimumReadableLabelPx},T1=t=>e=>n=>r=>o=>i=>v1(t)(e)(n)(r)(o)?o:xx(t)(e)(n)(r)(i),Ux=t=>e=>n=>{const r=yx([])(n),o=Rt(u=>w,u=>c=>v("Just",{head:u,tail:c}),r.rest),i=r.overview.length-1|0,a=i>=0&&i<r.overview.length?v("Just",r.overview[i]):w,s=0<r.overview.length?v("Just",r.overview[0]):w;if(s.tag==="Just"){if(a.tag==="Just"){if(o.tag==="Just")return Ce(s._1.startT-e.startT)<1e-4&&o._1.head.intent==="ActionFocus"?[{startT:s._1.startT,endT:a._1.endT,fromCam:t,toCam:t,easing:s._1.easing,interp:Pn,intent:Xi},{...o._1.head,fromCam:t},...o._1.tail]:n;if(o.tag==="Nothing"&&Ce(s._1.startT-e.startT)<1e-4)return[{startT:s._1.startT,endT:a._1.endT,fromCam:t,toCam:t,easing:s._1.easing,interp:Pn,intent:Xi}]}return n}if(s.tag==="Nothing"&&a.tag==="Nothing"&&o.tag==="Just"&&Ce(o._1.head.startT-e.startT)<1e-4&&o._1.head.intent==="ActionFocus"){const u=Rt(c=>w,c=>g=>v("Just",{head:c,tail:g}),o._1.tail);if(u.tag==="Nothing")return[{startT:o._1.head.startT,endT:o._1.head.endT,fromCam:t,toCam:t,easing:o._1.head.easing,interp:Pn,intent:Xi}];if(u.tag==="Just")return[{startT:o._1.head.startT,endT:o._1.head.endT,fromCam:t,toCam:t,easing:o._1.head.easing,interp:Pn,intent:Xi},{...u._1.head,fromCam:t},...u._1.tail];f()}return n},Vx=t=>e=>{const n=Rt(r=>w,r=>o=>v("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{...n._1.head,fromCam:t},...n._1.tail];f()},Xx=t=>e=>{const n=o=>i=>a=>{let s=o,u=i,c=a,g=!0,d;for(;g;){const l=s,_=u,h=Rt(p=>w,p=>m=>v("Just",{head:p,tail:m}),c);if(h.tag==="Nothing"){g=!1,d=Ct(l)(_);continue}if(h.tag==="Just"){if(_.intent==="Overview"&&h._1.head.intent==="ActionFocus"&&Ce(_.endT-h._1.head.startT)<1e-4&&_.fromCam.zoom===_.toCam.zoom&&_.fromCam.center.x===_.toCam.center.x&&_.fromCam.center.y===_.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)&&le(m=>Ce(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)(vt(T=>T.target.tag==="EdgeWindow"&&T.target._2.tag==="Extend"&&Ce(T.endT-p)<1e-4?v("Just",T.startT):w)(t.windows)),y=0<m.length?m[0]:p,x=we(_.startT)(y-(h._1.head.endT-h._1.head.startT)),N={..._,endT:x};s=Ct(N.endT>N.startT?Ct(l)(N):l)({...h._1.head,startT:x,endT:y}),u={...h._1.head,startT:y,fromCam:h._1.head.toCam},c=h._1.tail;continue}s=Ct(l)(_),u=h._1.head,c=h._1.tail;continue}f()}return d},r=Rt(o=>w,o=>i=>v("Just",{head:o,tail:i}),e);if(r.tag==="Nothing")return[];if(r.tag==="Just")return n([])(r._1.head)(r._1.tail);f()},Yx=t=>e=>n=>r=>o=>i=>{const a=pe(r.layout),s={x:a.x*r.placement.scale+r.placement.tx,y:a.y*r.placement.scale+r.placement.ty,w:a.w*r.placement.scale,h:a.h*r.placement.scale},u=w1(n)(s)(o)(i);return s.w/we(1e-4)(s.h)>=.33&&i.zoom/we(1e-4)(u.zoom)<=1.25&&Mn(n)(u).w>=s.w-.001&&To(t)(e)(n)(r)(u)>=t.minimumReadableLabelPx*.85?u:i},Kx=t=>e=>n=>r=>o=>i=>a=>{const s=pe(r.layout),u=s.w*r.placement.scale,c=u/we(1e-4)(s.h*r.placement.scale);if(o.tag==="Nothing")return a;if(o.tag==="Just"){if(Mx(n)(o._1)(a))return a;const g=w1(n)(o._1)(i)(a);return a.zoom/we(1e-4)(g.zoom)<=1.25&&(To(t)(e)(n)(r)(g)>=t.minimumReadableLabelPx-.001||o._1.w>=u-.001&&c>=.33&&To(t)(e)(n)(r)(g)>=t.minimumReadableLabelPx*.85)?g:a}f()},jx=t=>e=>n=>r=>o=>i=>a=>{const s={...a,center:(()=>{if(i.tag==="Nothing")return a.center;if(i.tag==="Just")return{x:i._1.x+i._1.w/2,y:i._1.y+i._1.h/2};f()})()},u=To(t)(e)(n)(r)(s);return Ox()(e)(n)(o)(i)(a)(Kx(t)(e)(n)(r)(o)(a)(Yx(t)(e)(n)(r)(a)(u<=0?s:{...s,zoom:Ye(s.zoom*t.minimumReadableLabelPx/u)(Sx(t)(e)(n)(r)(i)(s))})))},Bc=t=>e=>n=>r=>o=>i=>a=>r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?y1(t)(e)(n)(r)(o)(i)(a):v1(t)(e)(n)(r)(a)?a:jx(t)(e)(n)(r)(o)(i)(a),J1=t=>{const e=n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=i,g=Rt(d=>w,d=>l=>v("Just",{head:d,tail:l}),c);if(g.tag==="Just"&&g._1.head.intent==="Overview"){o=Ct(u)(g._1.head),i=g._1.tail;continue}a=!1,s={overview:u,rest:c}}return s};return(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=Rt(g=>w,g=>d=>v("Just",{head:g,tail:d}),i);if(c.tag==="Nothing"){a=!1,s=u;continue}if(c.tag==="Just"){if(c._1.head.intent==="Overview"){const g=e([c._1.head])(c._1.tail),d=Rt(h=>w,h=>p=>v("Just",{head:h,tail:p}),g.rest),l=u.length-1|0,_=l>=0&&l<u.length?v("Just",u[l]):w;if(_.tag==="Just"&&d.tag==="Just"&&_._1.intent==="ActionFocus"&&(()=>{const h=g.overview.length-1|0;return d._1.head.intent==="ActionFocus"&&(h>=0&&h<g.overview.length&&0<g.overview.length?g.overview[h].endT-g.overview[0].startT<=1.0001:!0)})()&&0<g.overview.length){const h=g.overview.length-1|0;if(h>=0&&h<g.overview.length){o=Ct(u)({startT:g.overview[0].startT,endT:g.overview[h].endT,fromCam:_._1.toCam,toCam:_._1.toCam,easing:g.overview[0].easing,interp:Pn,intent:is}),i=[{...d._1.head,fromCam:_._1.toCam},...d._1.tail];continue}}o=[...u,...g.overview],i=g.rest;continue}o=Ct(u)(c._1.head),i=c._1.tail;continue}f()}return s})([])(t)},Zx=t=>e=>n=>{const r=d1([])(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"&&Ce(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:Pn,intent:is}]}return n}return 0<r.overview.length&&r.prefix.length-1|0,n},b1=t=>e=>n=>{const r=d1([])(n),o=r.overview.length-1|0;if(o>=0&&o<r.overview.length){if(0<r.overview.length){const i=r.prefix.length-1|0;if(i>=0&&i<r.prefix.length&&(()=>{const a=r.overview[o].endT;return r.prefix[i].intent==="ActionFocus"&&(()=>{const s=r.overview.length-1|0;return le(u=>u.direction==="DiveIn"&&vo(u.parentPath)(t.path)&&Ce(u.startT-a)<1e-4,e)&&(s>=0&&s<r.overview.length&&0<r.overview.length?r.overview[s].endT-r.overview[0].startT<=1.0001:!0)})()})())return[...r.prefix,{startT:r.overview[0].startT,endT:r.overview[o].endT,fromCam:r.prefix[i].toCam,toCam:r.prefix[i].toCam,easing:r.overview[0].easing,interp:Pn,intent:is}]}return n}return n},C1=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==="EdgeWindow"?o.target._2.tag==="Extend"?v("Just",ts(t.layout)(t.edgeEndpoints)(o.target._1)):w:o.target.tag==="TokenWindow"?v("Just",(()=>{const i=[...vt(a=>{const s=gs(a)(t.layout.nodes);return s.tag==="Just"?v("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):w})([o.target._4,o.target._5]),...(()=>{const a=a1(o.target._2)(t.layout.edges),s=u1(o.target._7)(o.target._8)((n-o.startT)/we(1e-4)(o.endT-o.startT)),u=(()=>{if(a.tag==="Just")return wo((()=>{if(o.target._3==="Forward")return a._1;if(o.target._3==="Backward")return ce(a._1);f()})())(s);if(a.tag==="Nothing")return w;f()})();return u.tag==="Just"?[{x:u._1.x,y:u._1.y,w:0,h:0}]:[]})()];return i.length===0?ts(t.layout)(t.edgeEndpoints)(o.target._2):fr(i)})()):o.target.tag==="FillWindow"?v("Just",Jc(t.layout)(t.edgeEndpoints)(oe("Node",1,1,o.target._2,void 0,F,F))):w)(dt(o=>o.startT<=n&&n<o.endT,t.windows));return r.length===0?w:v("Just",(()=>{const o=fr(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}})())},Fc=t=>e=>{const n=Fx(t)(e.endT+1e-4);return n.tag==="Just"?v("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},tw=t=>e=>n=>r=>o=>{const i=Fc(r)(o),a=s=>{const u=To(t)(e)(n)(r)(s),c=u<=0||u>=t.minimumReadableLabelPx?s:{...s,zoom:s.zoom*t.minimumReadableLabelPx/u};return i.tag==="Just"&&(()=>{const g=Mn(n)(c);return!(i._1.x>=g.x&&i._1.y>=g.y&&i._1.x+i._1.w<=g.x+g.w&&i._1.y+i._1.h<=g.y+g.h)})()?s:c};return o.intent==="DiveHome"||o.intent==="ActionFocus"&&!(r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0)?o:{...o,fromCam:a(o.fromCam),toCam:a(o.toCam)}},ew=t=>e=>n=>r=>o=>i=>{const a=C1(r)(i),s=Fc(r)(i),u=c=>{const g=y1(t)(e)(n)(r)(s)(a)(c);return{...g,zoom:Ye(o.zoom)(g.zoom)}};return{...i,fromCam:u(i.fromCam),toCam:u(i.toCam)}},nw=t=>e=>n=>r=>o=>i=>i.intent==="ActionFocus"?ew(t)(e)(n)(r)(o)(i):{...i,fromCam:T1(t)(e)(n)(r)(o)(i.fromCam),toCam:T1(t)(e)(n)(r)(o)(i.toCam)},rw=t=>e=>n=>r=>o=>i=>{const a=o(i.fromCam),s=o(i.toCam),u=C1(r)(i),c=Fc(r)(i);return a.zoom===s.zoom&&a.center.x===s.center.x&&a.center.y===s.center.y?{...i,fromCam:Bc(t)(e)(n)(r)(c)(u)(a),toCam:Bc(t)(e)(n)(r)(c)(u)(s)}:{...i,fromCam:a,toCam:Bc(t)(e)(n)(r)(c)(u)(s)}},ow=t=>e=>n=>r=>o=>o.intent==="ActionFocus"?rw(t)(e)(n)(r)(hx)(o):o,ds=t=>e=>n=>r=>o=>i=>Gc(U(tw(t)(e)(n)(i))(wx(t)(i)(Xx(i)((()=>{const a=Qx(t)(e)(n)(r)(o)(i);if(i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0)return b1(i)(o.dives)(J1(_1(Gc(U(ow(t)(e)(n)(i))(a)))));const s=N1(t)(e)(n)(o)(i);return a.length===0?[{startT:i.startT,endT:i.endT,fromCam:s,toCam:s,easing:$_,interp:Pn,intent:Xi}]:Zx()(i)(Ux(s)(i)(b1(i)(o.dives)(J1(_1(Gc(Vx(s)(U(nw(t)(e)(n)(i)(s))(a))))))))})())))),iw=t=>e=>n=>r=>o=>Pt(i=>a=>ot.compare(i.startT)(a.startT))(St(o.segments)(ds(t)(e)(n)(r)(o))),Yi=t=>e=>n=>r=>o=>i=>a=>{if(i.direction==="DiveIn"){const s=Jo(n)(t.padding)(a)(No(t)(n)(ds(t)(e)(n)(r)(o)(a))(i.startT-1e-4).camera),u=gs(i.node)(a.layout.nodes);return i.direction==="DiveIn"&&u.tag==="Just"?m1(e)(n)(s)({x:u._1.x*a.placement.scale+a.placement.tx,y:u._1.y*a.placement.scale+a.placement.ty,w:u._1.w*a.placement.scale,h:u._1.h*a.placement.scale}):s}if(i.direction==="DiveOut"){const s=Jo(n)(t.padding)(a)(No(t)(n)(ds(t)(e)(n)(r)(o)(a))(i.endT+1e-4).camera),u=gs(i.node)(a.layout.nodes);return i.direction==="DiveIn"&&u.tag==="Just"?m1(e)(n)(s)({x:u._1.x*a.placement.scale+a.placement.tx,y:u._1.y*a.placement.scale+a.placement.ty,w:u._1.w*a.placement.scale,h:u._1.h*a.placement.scale}):s}f()},aw=t=>e=>n=>r=>o=>St(o.dives)(i=>{const a=fs(o)(i.parentPath)(i.startT)(i.endT);if(a.tag==="Just"){const s=i.childPath,u=jt(c=>vo(c.path)(s))(o.segments);if(u.tag==="Just"){const c=ds(t)(e)(n)(r)(o)(u._1),g=N1(t)(e)(n)(o)(u._1),d=Yi(t)(e)(n)(r)(o)(i)(a._1),l=(()=>{if(i.direction==="DiveIn")return g;if(i.direction==="DiveOut")return Jo(n)(t.padding)(u._1)(No(t)(n)(c)(i.startT-1e-4).camera);f()})();if(i.direction==="DiveIn"){const _=jt(h=>h.direction==="DiveIn"&&vo(h.parentPath)(i.childPath)&&Ce(h.startT-i.endT)<1e-4)(o.dives);if(_.tag==="Just"){const h=fs(o)(_._1.parentPath)(_._1.startT)(_._1.endT);if(h.tag==="Just"){if(i.direction==="DiveIn"&&i.endT-i.startT>.12){const p=i.endT-.12,m={easing:_r,endT:p,fromCam:d,intent:Zr,interp:jr,startT:i.startT,toCam:Yi(t)(e)(n)(r)(o)(_._1)(h._1)};return[m,{...m,startT:p,endT:i.endT,fromCam:Yi(t)(e)(n)(r)(o)(_._1)(h._1)}]}return[{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:_r,interp:jr,intent:Zr}]}if(h.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:_r,interp:jr,intent:Zr}];f()}if(_.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:_r,interp:jr,intent:Zr}];f()}if(i.direction==="DiveOut"){const _=jt(h=>h.direction==="DiveIn"&&vo(h.parentPath)(i.childPath)&&Ce(h.startT-i.endT)<1e-4)(o.dives);if(_.tag==="Just"){const h=fs(o)(_._1.parentPath)(_._1.startT)(_._1.endT);if(h.tag==="Just"){if(i.direction==="DiveIn"&&i.endT-i.startT>.12){const p=i.endT-.12,m={easing:_r,endT:p,fromCam:l,intent:Zr,interp:jr,startT:i.startT,toCam:Yi(t)(e)(n)(r)(o)(_._1)(h._1)};return[m,{...m,startT:p,endT:i.endT,fromCam:Yi(t)(e)(n)(r)(o)(_._1)(h._1)}]}return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:_r,interp:jr,intent:Zr}]}if(h.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:_r,interp:jr,intent:Zr}];f()}if(_.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:_r,interp:jr,intent:Zr}]}f()}if(u.tag==="Nothing")return[];f()}if(a.tag==="Nothing")return[];f()}),k1=t=>e=>n=>r=>o=>[...aw(t)(e)(n)(r)(o),...iw(t)(e)(n)(r)(o)],fi=(t,e,n)=>({tag:t,_1:e,_2:n}),sw=t=>t,_i=(t,e)=>({tag:t,_1:e}),Mc=t=>t,ls=(t,e)=>({tag:t,_1:e}),zc=ls("NotYet"),L1=ls("Consumed"),uw=Mc("FromSource"),S1=Mc("FromTarget"),cw=Mc("FromBoth"),Qc=_i("Hidden"),E1=_i("Visible"),Wc=sw("ExtendFromSource"),Oc=fi("Retracted"),P1=fi("Extended"),gw={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},qc=t=>t,hs={eq:Fa(Zo)},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 a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},bo=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},A1=Mt.foldMap(I2(A)),$c=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},fw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},_w=ge(A)(Mt),dw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},lw=ge(A)(Mt),hw=ge(A)(Mt),pw=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;f()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},G1=qc("Backdrop"),mw=qc("FlyThrough"),ln=qc("Active"),ps=t=>e=>n=>{const r=jt(o=>hs.eq(o.path)(e)&&n>=o.startT&&n<o.endT)(t.segments);if(r.tag==="Just")return v("Just",r._1);if(r.tag==="Nothing")return jt(o=>hs.eq(o.path)(e))(t.segments);f()},yw=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;f()},xw=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:xc,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:F}),ww=t=>U(e=>e<1?[]:It(0,e,t))(Kt(0,t.length-1|0)),ms=t=>e=>{const n=Hc(e)(t.keyframes);if(n.tag==="Nothing")return F;if(n.tag==="Just")return n._1.nodes;f()},Uc=t=>e=>{const n=Hc(e)(t.keyframes);if(n.tag==="Nothing")return F;if(n.tag==="Just")return n._1.edges;f()},Nw=J(t=>e=>{const n=Sr(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?Ct(n._1.init)({...n._1.last,endT:bo(n._1.last.endT)(e.endT),windows:Ct(n._1.last.windows)(e)}):Ct(t)({endT:e.endT,windows:[e]})})([]),vw=t=>e=>n=>A1(r=>A1(o=>o.target.tag==="FillWindow"?o.startT<=n?oe("Node",1,1,o.target._2,void 0,F,F):F:o.target.tag==="TokenWindow"&&o.startT+(o.endT-o.startT)*.25<=n?oe("Node",1,1,o.target._4,void 0,F,F):F)(r.windows))(dt(r=>n<=r.endT+t,Nw(Pt(r=>o=>ot.compare(r.startT)(o.startT))(dt(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),Tw=t=>e=>n=>le(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),Jw=t=>e=>n=>le(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),bw=t=>e=>n=>le(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),Cw=t=>e=>n=>le(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),I1=t=>{const e=i_(w,Zf,o=>ms(t)((()=>{if(o.scene.tag==="Structural")return o.scene._1.to;if(o.scene.tag==="DataFlow")return o.scene._1.keyframe;if(o.scene.tag==="Hold")return o.scene._1;if(o.scene.tag==="EnterNode"||o.scene.tag==="ExitNode"||o.scene.tag==="StepScene")return t.initialKeyframe;f()})()).tag==="Leaf"?w:v("Just",bo(o.startT)(o.endT-1e-4)),t.spans),n=(()=>{if(e.tag==="Nothing")return t.startT;if(e.tag==="Just")return e._1;f()})(),r=jt(o=>o.target.tag==="NodeWindow"&&o.target._2==="PlopIn")(Pt(o=>i=>ot.compare(o.startT)(i.startT))(t.windows));if(r.tag==="Nothing")return n;if(r.tag==="Just")return bo(r._1.startT)(r._1.endT-1e-4);f()},ys=t=>e=>n=>jt(r=>n(r)&&e>=r.startT&&e<r.endT)(t),xs=t=>e=>{if(e<t.startT)return Qn("AtKeyframe",t.initialKeyframe);const n=jt(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Qn("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Qn("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return Qn("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode"||n._1.scene.tag==="StepScene")return Qn("AtKeyframe",t.initialKeyframe);f()}if(n.tag==="Nothing")return Qn("AtKeyframe",J(yw)(t.initialKeyframe)(t.spans));f()},kw=t=>e=>{const n=xs(t)(e),r=Hc((()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;f()})())(t.keyframes);if(r.tag==="Just")return r._1.kind;if(r.tag==="Nothing")return Ui;f()},Lw=t=>e=>{const n=xs(t)(e);if(n.tag==="AtKeyframe")return ze(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return ze(3)(n._2)==="kf-"?"":n._2;f()},Sw={segment:{startT:0,endT:0,path:[],layout:{nodes:F,edges:F,chipExtras:F,edgeLabels:F},placement:xc,windows:[],spans:[],keyframes:F,initialKeyframe:"",edgeEndpoints:F},state:{nodes:F,edges:F,tokens:F,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:Ui,visited:F,nodeFadeAlpha:F,nodeLabelFadeAlpha:F,edgeFadeAlpha:F,nodeInvert:F},bgAlpha:1,minis:[],role:ln},ws=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:Sw},Ew=t=>e=>{const n=xs(t)(e);if(n.tag==="AtKeyframe")return ms(t)(n._1);if(n.tag==="InTransition")return Oe(A.compare,Qe,ms(t)(n._1),ms(t)(n._2));f()},Pw=t=>e=>{const n=xs(t)(e);if(n.tag==="AtKeyframe")return Uc(t)(n._1);if(n.tag==="InTransition")return Oe(A.compare,Qe,Uc(t)(n._1),Uc(t)(n._2));f()},D1=t=>e=>{const n=t.endT-t.startT;return n<=0?1:bo(0)($c(1)((e-t.startT)/n))},Aw=t=>e=>n=>Sc(No(t.cameraConfig)(t.layout)(t.cameraSpans)(n.startT).camera)(No(t.cameraConfig)(t.layout)(t.cameraSpans)(n.endT).camera)(D1(n)(e)),Gw=t=>{const e=bo(0)($c(1)(t));return e<=0||e>=1?0:yn(3.141592653589793*e)},di=t=>e=>{const n=t.endT-t.startT;return n<=0?1:bo(0)($c(1)((e-t.startT)/n))},Iw=t=>e=>n=>r=>o=>{const i=ys(e)(n)(a=>a.target.tag==="EdgeWindow"&&a.target._2.tag==="Retract"&&a.target._1===o);if(i.tag==="Just"){const a=es(t.timing.edgeEasing)(di(i._1)(n)),s=i._1.target.tag==="EdgeWindow"?i._1.target._2:cs("Extend",Wc);if(s.tag==="Retract")return fi("Retracting",s._1,a);if(s.tag==="Extend")return fi("Extending",s._1,a);f()}if(i.tag==="Nothing"){if(Tw(e)(n)(o))return Oc;const a=ys(e)(n)(s=>s.target.tag==="EdgeWindow"&&s.target._1===o);if(a.tag==="Just"){const s=es(t.timing.edgeEasing)(di(a._1)(n)),u=a._1.target.tag==="EdgeWindow"?a._1.target._2:cs("Extend",Wc);if(u.tag==="Retract")return fi("Retracting",u._1,s);if(u.tag==="Extend")return fi("Extending",u._1,s);f()}if(a.tag==="Nothing")return Cw(e)(n)(o)?Oc:fw(o)(r)?P1:Oc}f()},Dw=t=>e=>n=>{const r=Pw(e)(n);return _w(U(o=>b(o,Iw(t)(e.windows)(n)(r)(o)))((()=>{const o=i=>{if(i.tag==="Leaf")return F;if(i.tag==="Node")return oe("Node",i._1,i._2,i._3,void 0,o(i._5),o(i._6));f()};return Zt(dn.foldr,o(e.layout.edges))})()))},Rw=t=>e=>n=>r=>{const o=ys(t)(e)(i=>i.target.tag==="NodeWindow"&&i.target._1===r&&i.target._2==="PlopOut");if(o.tag==="Just"){const i=di(o._1)(e),a=o._1.target.tag==="NodeWindow"?o._1.target._2:Ac;if(a==="PlopIn")return _i("PloppingIn",i);if(a==="PlopOut")return _i("PloppingOut",i);f()}if(o.tag==="Nothing"){if(Jw(t)(e)(r))return Qc;const i=ys(t)(e)(a=>a.target.tag==="NodeWindow"&&a.target._1===r);if(i.tag==="Just"){const a=di(i._1)(e),s=i._1.target.tag==="NodeWindow"?i._1.target._2:Ac;if(s==="PlopIn")return _i("PloppingIn",a);if(s==="PlopOut")return _i("PloppingOut",a);f()}if(i.tag==="Nothing")return bw(t)(e)(r)?Qc:dw(r)(n)?E1:Qc}f()},Bw=t=>e=>{const n=Ew(t)(e);return lw(U(r=>b(r,Rw(t.windows)(e)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return F;if(o.tag==="Node")return oe("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));f()};return Zt(dn.foldr,r(t.layout.nodes))})()))},Fw=t=>e=>n=>e.target.tag==="TokenWindow"?b(e.target._1,n<e.startT?zc:n>=e.endT?L1:ls("Travelling",{edge:e.target._2,direction:e.target._3,progress:es(t.timing.tokenEasing)(di(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?zc:n>=e.endT?L1:ls("Filling",{node:e.target._2,progress:di(e)(n),labels:e.target._3})):b("",zc),Mw=t=>e=>n=>hw(U(r=>Fw(t)(r)(n))(dt(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),zw=t=>e=>n=>({nodes:Bw(e)(n),edges:Dw(t)(e)(n),tokens:Mw(t)(e.windows)(n),camera:No(t.cameraConfig)(e.layout)(t.cameraSpans)(n).camera,frameTitle:Lw(e)(n),staticKind:kw(e)(n),visited:vw(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:F,nodeLabelFadeAlpha:F,edgeFadeAlpha:F,nodeInvert:F}),li=t=>e=>n=>r=>({segment:n,state:zw(t)(n)(e),bgAlpha:1,minis:Qw(t)(e)(n),role:r}),Qw=t=>e=>n=>vt(r=>{const o=ps(t)(Ct(n.path)(r))(e);if(o.tag==="Just")return v("Just",{...li(t)(pw(o._1.startT)(o._1.endT-1e-4)(e))(o._1)(G1),bgAlpha:0});if(o.tag==="Nothing")return w;f()})((()=>{const r=o=>{if(o.tag==="Leaf")return F;if(o.tag==="Node")return oe("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));f()};return Zt(dn.foldr,r(n.layout.nodes))})()),Ww=t=>e=>{if(t.direction==="DiveIn")return I1(e);if(t.direction==="DiveOut")return t.startT-1e-4;f()},R1=t=>e=>vt(n=>{const r=jt(o=>o.direction==="DiveIn"&&hs.eq(o.childPath)((()=>{const i=n.length+1|0;return i<1?[]:It(0,i,e)})()))(t.dives);if(r.tag==="Just"){const o=ps(t)(n)(r._1.startT-1e-4);if(o.tag==="Just")return v("Just",(()=>{const i=li(t)(r._1.startT-1e-4)(o._1)(G1);return{...i,state:{...i.state,nodeFadeAlpha:oe("Node",1,1,r._1.node,0,F,F)}}})());if(o.tag==="Nothing")return w;f()}if(r.tag==="Nothing")return w;f()})(ww(e)),B1=t=>e=>{const n=dt(o=>e>=o.startT&&e<o.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:xw(t)},Ow=t=>e=>n=>r=>{const o=s=>{const u=li(t)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT;f()})())(s)(mw);return{...u,bgAlpha:1,minis:dt(c=>!hs.eq(c.segment.path)(n.childPath),u.minis),state:{...u.state,edgeFadeAlpha:F,nodeFadeAlpha:oe("Node",1,1,n.node,0,F,F),nodeInvert:F,tokens:F}}},i=ps(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT;f()})()),a=ps(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;f()})());return[...R1(t)(n.parentPath),...(()=>{if(i.tag==="Just"){if(a.tag==="Just")return[o(i._1),{...li(t)(Ww(n)(a._1))(a._1)(ln),bgAlpha:1}];if(a.tag==="Nothing")return[o(i._1)];f()}if(i.tag==="Nothing")return[li(t)(e)(B1(t)(e))(ln)];f()})()]},qw=t=>e=>jt(n=>e>=n.startT&&e<n.endT)(t.dives),Hw=t=>e=>{const n=B1(t)(e),r=t.dives.length!==0,o=No(t.cameraConfig)(t.layout)(t.cameraSpans)(e).camera,i=Jo(t.layout)(t.cameraConfig.padding)(n)(o),a=R1(t)(n.path),s=li(t)(n.path.length===0?e:bo(e)(I1(n)))(n)(ln),u={...s,state:{...s.state,camera:i}},c=qw(t)(e);if(c.tag==="Just"){const g=Aw(t)(e)(c._1),d=D1(c._1)(e);return{levels:Ow(t)(e)(c._1)(g),camera:o,rootLayout:t.layout,hasDives:r,diving:!0,zoomStreak:Gw(g),zoomDirection:(()=>{if(c._1.direction==="DiveIn")return-1;if(c._1.direction==="DiveOut")return 1;f()})(),diveDepth:(()=>{if(c._1.direction==="DiveIn")return g;if(c._1.direction==="DiveOut")return 1-g;f()})(),doorProgress:(()=>{if(c._1.direction==="DiveIn")return d;if(c._1.direction==="DiveOut")return 1-g;f()})()}}if(c.tag==="Nothing")return{levels:Ct(a)(u),camera:i,rootLayout:t.layout,hasDives:r,diving:!1,zoomStreak:0,zoomDirection:0,diveDepth:0,doorProgress:0};f()},$w=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Uw=t=>{const e=t.length;return(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=i;if(u>=e){a=!1,s=c;continue}const g=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const y=_,x=h;if(y>=e){p=!1,m=x;continue}if(u>=0&&u<t.length){if(y>=0&&y<t.length){_=y+1|0,h=(()=>{const N=t[u].position,T=t[u].size,C=t[y].position,L=t[y].size;return N._1<C._1+L._1&&C._1<N._1+T._1&&N._2<C._2+L._2&&C._2<N._2+T._2})()?x+1|0:x;continue}_=y+1|0,h=x;continue}p=!1,m=x}return m};o=u+1|0,i=g(u+1|0)(c)}return s})(0)(0)},F1=t=>J(e=>n=>e+$2(n.start)(n.end))(0)(t.segments),M1=t=>e=>n=>({crossingCount:J(r=>o=>r+o.jumps.length|0)(0)(e),bendCount:J(r=>o=>r+o.bends.length|0)(0)(e),totalEdgeLength:J(r=>o=>r+F1(o))(0)(e),maxEdgeLength:J(r=>o=>$w(r)(F1(o)))(0)(e),nodeOverlapCount:Uw(t),constraintViolations:n,jumpCount:J(r=>o=>r+o.jumps.length|0)(0)(e)}),Vc=t=>t,_e=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=it.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Xc=Vc("LEFT"),Vw=Vc("RIGHT"),z1=Vc("UNDEFINED"),Xw={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},Yw={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?Ze:Fe;if(e==="LEFT")return Me;if(t==="RIGHT")return e==="RIGHT"?Ze:Fe;if(e==="RIGHT")return Me;if(t==="UP")return e==="UP"?Ze:Fe;if(e==="UP")return Me;if(t==="DOWN")return e==="DOWN"?Ze:Fe;if(e==="DOWN")return Me;if(t==="UNDEFINED"&&e==="UNDEFINED")return Ze;f()},Eq0:()=>Xw},Kw=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}}f()}return o},jw={x:0,y:0},wn=t=>e=>n=>{const r=_e(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:rt(it)(t)(e(r._1))(n.cNodes)};f()},Ki=t=>e=>n=>{const r=_e(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:rt(it)(t)(e(r._1))(n.cGroups)};f()},Zw=t=>J(e=>n=>wn(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),tN=t=>{const e=J(n=>r=>{const o=_e(r)(t.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just")return J(i=>a=>Ft(it)(xe)(a)([r])(i))(n)(o._1.constraints);f()})(F)(t.cNodeOrder);return J(n=>r=>wn(r)(o=>({...o,constraints:(()=>{const i=_e(r)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;f()})()}))(n))(t)(t.cNodeOrder)},eN=t=>e=>wn(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}})),nN=t=>{const e=J(n=>r=>Ki(r)(o=>({...o,outDegree:o.outDegreeReal}))(n))(t)(t.cGroupOrder);return J(n=>r=>wn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder)},Wn={left:!1,right:!1,up:!1,down:!1},rN={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},Yc=t=>J(e=>n=>{const r=_e(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const o=J(a=>s=>{const u=_e(s)(e.cNodes);if(u.tag==="Nothing")return a;if(u.tag==="Just"){if(a.tag==="Nothing")return v("Just",s);if(a.tag==="Just"){const c=_e(a._1)(e.cNodes);if(c.tag==="Nothing")return v("Just",s);if(c.tag==="Just")return u._1.hitbox.x<c._1.hitbox.x?v("Just",s):v("Just",a._1)}}f()})(w)(r._1.cNodes),i=Ki(n)(a=>({...a,reference:o}))(e);if(o.tag==="Nothing")return i;if(o.tag==="Just"){const a=_e(o._1)(i.cNodes);if(a.tag==="Nothing")return i;if(a.tag==="Just"){const s=a._1;return J(u=>c=>wn(c)(g=>({...g,cGroupOffset:{x:g.hitbox.x-s.hitbox.x,y:g.hitbox.y-s.hitbox.y}}))(u))(i)(r._1.cNodes)}}}f()})(t)(t.cGroupOrder),Nn=t=>Yc({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return F;if(n.tag==="Node")return oe("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));f()};return e(t.cNodes)})()}),lr=t=>Yc({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return F;if(n.tag==="Node")return oe("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));f()};return e(t.cNodes)})()}),Q1=t=>{const e=J(n=>r=>Ki(r)(o=>({...o,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return J(n=>r=>{const o=_e(r)(n.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just"){if(o._1.cGroup.tag==="Nothing")return n;if(o._1.cGroup.tag==="Just"){const i=o._1.cGroup._1;return J(a=>s=>{const u=_e(s)(a.cNodes);if(u.tag==="Nothing")return a;if(u.tag==="Just")return u._1.cGroup.tag==="Just"&&u._1.cGroup._1!==i?Ki(u._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(Ki(i)(c=>nn($r)(s)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,s]})(a)):a;f()})(n)(o._1.constraints)}}f()})(e)(e.cNodeOrder)},Ns=t=>{const e=tN(t.cGraph);return{...t,cGraph:Q1(J(n=>r=>wn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},oN=t=>e=>J(n=>r=>{if(t==="LEFT"||t==="UP"){const i=r._2;return wn(r._1)(a=>({...a,constraints:[...a.constraints,i]}))(n)}const o=r._1;return wn(r._2)(i=>({...i,constraints:[...i.constraints,o]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),On=t=>{const e={...t,cGraph:oN(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return F;if(r.tag==="Node")return oe("Node",r._1,r._2,r._3,{...r._4,constraints:[]},n(r._5),n(r._6));f()};return n(t.cGraph.cNodes)})()})};return{...e,cGraph:Q1((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);f()})())}},iN=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?On(r):e==="RIGHT"?On({...r,cGraph:Nn(r.cGraph)}):e==="UP"?On({...r,cGraph:lr(r.cGraph)}):e==="DOWN"?On({...r,cGraph:Nn(lr(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?Ns({...r,cGraph:Nn(r.cGraph)}):e==="UP"?On({...r,cGraph:lr(r.cGraph)}):e==="DOWN"?On({...r,cGraph:Nn(lr(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?Ns({...r,cGraph:Nn(r.cGraph)}):e==="UP"?On({...r,cGraph:lr(Nn(r.cGraph))}):e==="DOWN"?On({...r,cGraph:Nn(lr(Nn(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?On({...r,cGraph:lr(r.cGraph)}):e==="RIGHT"?On({...r,cGraph:Nn(lr(r.cGraph))}):e==="DOWN"?Ns({...r,cGraph:Nn(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?On({...r,cGraph:lr(Nn(r.cGraph))}):e==="RIGHT"?On({...r,cGraph:Nn(lr(Nn(r.cGraph)))}):e==="UP"?Ns({...r,cGraph:Nn(r.cGraph)}):r;f()},W1=t=>e=>e.finished||!Kw(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:iN(e.direction)(t)(e),aN=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?W1(Xc)(t):t,n={...e,cGraph:nN(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);f()},O1=t=>e=>n=>{const r=_e(t)(n.cNodes),o=_e(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;f()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:rt(it)(t)({...r._1,cGroup:v("Just",e)})(n.cNodes),cGroups:rt(it)(e)({...o._1,cNodes:nn($r)(t)(o._1.cNodes)?o._1.cNodes:[...o._1.cNodes,t],reference:(()=>{if(o._1.reference.tag==="Nothing")return v("Just",t);if(o._1.reference.tag==="Just")return v("Just",o._1.reference._1);f()})()})(n.cGroups)}:n},q1=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:rt(it)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:w,cGroupOffset:jw,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:Wn})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),Kc=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:J(r=>o=>O1(o)(n)(r))({...e,cGroups:rt(it)(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)}},sN=t=>J(e=>n=>{const r=_e(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?Kc({master:w,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),uN=t=>({cGraph:Zw(sN(Yc(t))),direction:z1,compactionAlgorithm:w,constraintAlgorithm:w,spacingsHandler:rN,lockFun:w,finished:!1}),cN=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},gN=t=>e=>{const n=ot.compare(t._1)(e._1);return n==="LT"?Fe:n==="GT"?Me:it.compare(t._2)(e._2)},fN=(()=>{const t=fn.unfoldr(Xn);return e=>t(_n("IterNode",e,Un))})(),H1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=it.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},$1=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",U1=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),vs=t=>e=>gN(b(t.hitbox.x+t.hitbox.width/2,t.id))(b(e.hitbox.x+e.hitbox.width/2,e.id)),_N=t=>e=>{const n=Lr(Vt,w,r=>vs(t)(r)==="LT",e);if(n.tag==="Just"){const r=a_(Vt,w,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;f()}if(n.tag==="Nothing")return Ct(e)(t);f()},V1=t=>e=>{const n=dt(o=>vs(o)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?v("Just",n[r]):w},dN=t=>e=>{const n=_N(e)(t.intervals),r=jt(i=>vs(e)(i)==="LT")(n),o=rt(it)(e.id)((()=>{const i=V1(e)(n);return i.tag==="Just"?v("Just",i._1.id):w})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return rt(it)(r._1.id)(v("Just",e.id))(o);if(r.tag==="Nothing")return o;f()})()}},lN=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?Me:Ze:e.low?Fe:Ze:n},hN=t=>J(e=>n=>wn(n.id)(r=>({...r,constraints:[]}))(e))(t)(vt(e=>_e(e)(t.cNodes))(t.cNodeOrder)),jc=t=>e=>J(n=>r=>{const o=_e(r._1)(n.cNodes);if(o.tag==="Just")return wn(r._1)(i=>({...i,constraints:[...i.constraints,...r._2]}))(n);if(o.tag==="Nothing")return n;f()})(e)(fN(t)),X1=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}},Y1=t=>e=>n=>J(r=>o=>n(o)?wn(o.id)(X1(t))(r):r)(e)(vt(r=>_e(r)(e.cNodes))(e.cNodeOrder)),pN=t=>e=>{const n=(r,o,i)=>{const a=wn(i)(X1(t))(r);return o.length<=1?a:J(s=>u=>u===i?s:wn(u)(c=>c.ignoreSpacing.up?{...c,hitbox:{...c.hitbox,y:c.hitbox.y+t+.01,height:c.hitbox.height-t-.01}}:c.ignoreSpacing.down?{...c,hitbox:{...c.hitbox,height:c.hitbox.height-t-.01}}:c)(s))(a)(o)};return J(r=>o=>{if(o.master.tag==="Nothing")return 0<o.cNodes.length?n(r,o.cNodes,o.cNodes[0]):r;if(o.master.tag==="Just")return n(r,o.cNodes,o.master._1);f()})(e)(vt(r=>_e(r)(e.cGroups))(e.cGroupOrder))},mN=t=>e=>{const n=V1(e)(t.intervals),r=jt(i=>vs(e)(i)==="LT")(t.intervals),o=n.tag==="Just"&&(()=>{const i=H1(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(it)(xe)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const i=H1(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(it)(xe)(e.id)([r._1.id])(o):o,intervals:dt(i=>i.id!==e.id,t.intervals)}},yN=t=>e=>e.low?dN(t)(e.node):mN(t)(e.node),Zc=t=>e=>J(yN)({intervals:[],cand:F,constraints:F})(Pt(lN)(St(dt(t,vt(n=>_e(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,xN=t=>e=>{const n=cN(0)(t/2-.5),r=jc(Zc($1)(Y1(n)(e)($1)))(e),o=jc(Zc(U1)(Y1(n)(r)(U1)))(r);return jc(Zc(i=>!0)(pN(n)(o)))(o)},wN=t=>e=>xN(t)(hN(e.cGraph)),Ts=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},K1=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},tg=t=>e=>n=>r=>o=>({id:t,representedEdges:[o],affectedBends:[e,n],hitbox:{x:Ts(e._1)(n._1),y:Ts(e._2)(n._2),width:Ce(e._1-n._1),height:Ce(e._2-n._2)},ignoreSpacing:Wn,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];f()})(),aPort:w}),NN=t=>e=>{const n=Ts(t.hitbox.x)(e.hitbox.x),r=Ts(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:K1(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:K1(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;f()})()}},vN=t=>e=>Ce(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,TN=t=>e=>Ce(t.hitbox.x-e.hitbox.x)<=1e-4?ot.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?Fe:Me,j1=(t,e)=>({tag:t,_1:e}),eg=ge(A)(Mt),Js=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Z1=(()=>{const t={eq:n=>r=>n._1===r._1&&(n._2.tag==="Nothing"?r._2.tag==="Nothing":n._2.tag==="Just"&&r._2.tag==="Just"&&n._2._1===r._2._1)},e={compare:n=>r=>{const o=A.compare(n._1)(r._1);if(o==="LT")return Fe;if(o==="GT")return Me;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?Ze:Fe;if(r._2.tag==="Nothing")return Me;if(n._2.tag==="Just"&&r._2.tag==="Just")return A.compare(n._2._1)(r._2._1);f()},Eq0:()=>t};return J(n=>r=>rt(e)(r)()(n))(F)})(),Ir=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},JN=J(t=>e=>rt(Yw)(e)()(t))(F),ng=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=I_.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},bN=t=>e=>{const n=eg(U(i=>b(i.id,i))(t)),r=vt(i=>Js(i)(n))(e),o=it.compare((()=>{const i=Z1(U(a=>b(a.from.node,a.from.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;f()})())((()=>{const i=Z1(U(a=>b(a.to.node,a.to.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;f()})());if(o==="LT")return{...Wn,left:!0,right:!1};if(o==="GT")return{...Wn,left:!1,right:!0};if(o==="EQ")return Wn;f()},CN=t=>vt(e=>{if(e.direction==="V")return v("Just",{start:e.start,end:e.end});if(e.direction==="H")return w;f()})(t.segments),bs=t=>e=>n=>r=>{if(r.tag==="Just"){const o=Ir(n)(e);if(o.tag==="Just"){const i=jt(a=>a.id===r._1)(o._1);if(i.tag==="Just")return i._1.side;if(i.tag==="Nothing")return t;f()}if(o.tag==="Nothing")return t;f()}if(r.tag==="Nothing")return t;f()},kN=t=>e=>n=>{const r=q1({origin:v("Just",j1("SegmentOrigin",n)),kind:v("Just","vs"),hitbox:n.hitbox})(e.cGraph),o=eN(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const i=_e(n.potentialGroupParents[0])(o.cNodes);if(i.tag==="Just"){if(i._1.cGroup.tag==="Just")return O1(r.id)(i._1.cGroup._1)(o);if(i._1.cGroup.tag==="Nothing")return o;f()}if(i.tag==="Nothing")return o;f()}return Kc({master:v("Just",r.id),nodes:[r.id]})(o).graph})(),edgeToCs:J(i=>a=>Ft(A)(xe)(a)([r.id])(i))(e.edgeToCs)(n.representedEdges),lockMap:rt(it)(r.id)(bN(t)(n.representedEdges))(e.lockMap)}},LN=t=>e=>n=>{const r=Rt(o=>w,o=>i=>v("Just",{head:o,tail:i}),Pt(TN)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const o=J(i=>a=>vN(i.survivor)(a)?{...i,survivor:NN(i.survivor)(a)}:{survivor:a,merged:[...i.merged,i.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return J(kN(t))(n)([...o.merged,o.survivor])}f()},SN=t=>({cGraph:{cNodes:F,cNodeOrder:[],cGroups:F,cGroupOrder:[],supportedDirections:JN([z1,Xc,Vw]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:F,edgeToCs:F,lockMap:F}),EN=t=>{const e=et(4);return{x:t.position._1*e,y:t.position._2*e,width:t.size._1*e,height:t.size._2*e}},PN=t=>e=>n=>J(r=>o=>{const i=q1({origin:v("Just",j1("NodeOrigin",o.node)),kind:w,hitbox:EN(o)})(r.cGraph),a=Ir(o.node)(t),s=(()=>{if(a.tag==="Nothing")return b(0,0);if(a.tag==="Just")return a._1;f()})();return{...r,cGraph:Kc({master:v("Just",i.id),nodes:[i.id]})(i.graph).graph,nodeToC:rt(A)(o.node)(i.id)(r.nodeToC),lockMap:rt(it)(i.id)((()=>{const u=s._1-s._2|0;return u<0?{...Wn,left:!0}:u>0?{...Wn,right:!0}:Wn})())(r.lockMap)}})(n)(e),AN=t=>J(e=>n=>Ft(A)(r=>o=>b(r._1+o._1|0,r._2+o._2|0))(n.to.node)(b(1,0))(Ft(A)(r=>o=>b(r._1+o._1|0,r._2+o._2|0))(n.from.node)(b(0,1))(e)))(F)(t),GN=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?rt(A)(n.origin._1._1)(n.hitbox.x)(e):e)(F)(vt(e=>_e(e)(t.cNodes))(t.cNodeOrder)),IN=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?rt(A)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(F)(vt(e=>_e(e)(t.cNodes))(t.cNodeOrder)),DN=t=>J(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return J(o=>i=>rt(I_)(i)(r)(o))(e)(n.origin._1._1.affectedBends)}return e})(F)(vt(e=>_e(e)(t.cNodes))(t.cNodeOrder)),td=t=>{const e=eg(U(n=>b(n.id,n))(t.edges));return vt(n=>{const r=Js(n.edge)(e);if(r.tag==="Just")return n.reversed?v("Just",{edgeId:n.edge,src:r._1.to.node,tgt:r._1.from.node,srcSide:bs(Pr)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:bs(Ar)(t.ports)(r._1.from.node)(r._1.from.port),path:n}):v("Just",{edgeId:n.edge,src:r._1.from.node,tgt:r._1.to.node,srcSide:bs(Pr)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:bs(Ar)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return w;f()})(t.paths)},RN=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=Ir(r.tgt)(t.nodeToC),i=(()=>{if(o.tag==="Just")return _e(o._1)(t.cGraph.cNodes);if(o.tag==="Nothing")return w;f()})(),a=Ir(r.src)(t.nodeToC),s=(()=>{if(a.tag==="Just")return _e(a._1)(t.cGraph.cNodes);if(a.tag==="Nothing")return w;f()})(),u=(()=>{if(s.tag==="Just"){if(i.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(i._1.cGroup.tag==="Just")return v("Just",{srcGroup:s._1.cGroup._1,tgtGroup:i._1.cGroup._1,delta:0,weight:100});if(i._1.cGroup.tag==="Nothing")return w;f()}if(s._1.cGroup.tag==="Nothing")return w;f()}if(i.tag==="Nothing")return w;f()}if(s.tag==="Nothing")return w;f()})(),c=_=>h=>p=>{if(s.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(p.cGroup.tag==="Just")return _(p.hitbox.x)&&p.cGroup._1!==s._1.cGroup._1?v("Just",h(p.cGroup._1)(s._1.cGroup._1)):w;if(p.cGroup.tag==="Nothing")return w;f()}if(s._1.cGroup.tag==="Nothing")return w;f()}if(s.tag==="Nothing")return w;f()},g=vt(_=>_e(_)(t.cGraph.cNodes))((()=>{const _=Js(r.edgeId)(t.edgeToCs);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;f()})()),d=(()=>{if(s.tag==="Just"&&r.srcSide==="West"){const _=s._1;return vt(c(h=>h<_.hitbox.x)(h=>p=>({srcGroup:h,tgtGroup:p,delta:1,weight:100})))(g)}return[]})(),l=(()=>{if(s.tag==="Just"&&r.tgtSide==="East"){const _=s._1;return vt(c(h=>h>_.hitbox.x)(h=>p=>({srcGroup:p,tgtGroup:h,delta:1,weight:100})))(g)}return[]})();if(u.tag==="Nothing")return[];if(u.tag==="Just")return[u._1,...d,...l];f()});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 le(a=>nn(ir)(a)(i.representedEdges),r.origin._1._1.representedEdges)})(),vsLNodePair:r=>o=>r.origin.tag==="Just"&&o.origin.tag==="Just"&&(r.origin._1.tag==="SegmentOrigin"?o.origin._1.tag==="NodeOrigin":r.origin._1.tag==="NodeOrigin"&&o.origin._1.tag==="SegmentOrigin"),edgeLengthEdges:r=>n}},BN=t=>e=>{const n=et(4),r=GN(t),o=IN(t),i=eg(U(s=>b(s.id,b(s.from.node,s.to.node)))(e.edges)),a=DN(t);return{nodes:U(s=>{const u=Ir(s.node)(r);if(u.tag==="Just")return{...s,position:b(u._1/n,s.position._2)};if(u.tag==="Nothing")return s;f()})(e.nodes),edges:U(s=>{const u=Js(s.edge)(i),c=(()=>{if(u.tag==="Nothing")return s.segments;if(u.tag==="Just"){const g=Ir(u._1._1)(o),d=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;f()})(),l=Ir(u._1._2)(o),_=(()=>{if(l.tag==="Nothing")return 0;if(l.tag==="Just")return l._1;f()})();return qt((()=>{const h=s.reversed?_:d,p=s.reversed?d:_,m=s.segments.length;return y=>x=>{if(x.direction==="V"){const N=(()=>{if(y===0)return h;if(y===(m-1|0))return p;const T=ng(x.start)(a);if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;f()})();return{...x,start:b(x.start._1+N,x.start._2),end:b(x.end._1+N,x.end._2)}}if(x.direction==="H")return{...x,start:b((()=>{if(y===0)return x.start._1+h;const N=ng(x.start)(a);if(N.tag==="Nothing")return x.start._1+0;if(N.tag==="Just")return x.start._1+N._1;f()})(),x.start._2),end:b((()=>{if(y===(m-1|0))return x.end._1+p;const N=ng(x.end)(a);if(N.tag==="Nothing")return x.end._1+0;if(N.tag==="Just")return x.end._1+N._1;f()})(),x.end._2)};f()}})())(s.segments)}f()})();return{...s,segments:c,bends:We(g=>d=>g.end,c,It(1,c.length,c))}})(e.paths)}},FN=t=>e=>n=>r=>o=>i=>{const a=tg(o.nextId)(i._2.start)(i._2.end)(w)(t.edgeId),s=(()=>{if(i._1===0){if(e.tag==="Nothing")return a;if(e.tag==="Just")return{...a,ignoreSpacing:i._2.end._2<e._1.y?{...a.ignoreSpacing,down:!0}:i._2.end._2>e._1.y+e._1.height?{...a.ignoreSpacing,up:!0}:{...a.ignoreSpacing,up:!0,down:!0}};f()}return a})();return{nextId:o.nextId+1|0,segments:[...o.segments,(()=>{if(i._1===r){if(n.tag==="Nothing")return s;if(n.tag==="Just")return{...s,ignoreSpacing:i._2.start._2<n._1.y?{...s.ignoreSpacing,down:!0}:i._2.start._2>n._1.y+n._1.height?{...s.ignoreSpacing,up:!0}:{...s.ignoreSpacing,up:!0,down:!0}};f()}return s})()]}},ed=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...tg(i.nextId)(r.start)(b(r.start._1,o.down?n.y:n.y+n.height))(v("Just",e))(t.edgeId),aPort:v("Just",{node:t.src,side:o.side}),ignoreSpacing:o.down?{...Wn,down:!0}:{...Wn,up:!0}}]}),Cs=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...tg(i.nextId)(r.end)(b(r.end._1,o.down?n.y:n.y+n.height))(v("Just",e))(t.edgeId),aPort:v("Just",{node:t.tgt,side:o.side}),ignoreSpacing:o.down?{...Wn,down:!0}:{...Wn,up:!0}}]}),MN=t=>e=>n=>{if(n.src===n.tgt)return e;const r=Ir(n.src)(t.nodeToC),o=Ir(n.tgt)(t.nodeToC),i=(()=>{if(r.tag==="Just"){const g=_e(r._1)(t.cGraph.cNodes);return g.tag==="Just"?v("Just",g._1.hitbox):w}if(r.tag==="Nothing")return w;f()})(),a=(()=>{if(o.tag==="Just"){const g=_e(o._1)(t.cGraph.cNodes);return g.tag==="Just"?v("Just",g._1.hitbox):w}if(o.tag==="Nothing")return w;f()})(),s=CN(n.path),u=J(FN(n)(i)(a)(s.length-1|0))(e)(qt(g=>d=>b(g,d))(s));if(0<s.length){const g=(()=>{if(r.tag==="Just"&&i.tag==="Just"){if(n.srcSide==="North")return ed(n)(r._1)(i._1)(s[0])({side:Ge,down:!0})(u);if(n.srcSide==="South")return ed(n)(r._1)(i._1)(s[0])({side:Ie,down:!1})(u)}return u})(),d=s.length-1|0;if(d>=0&&d<s.length&&o.tag==="Just"&&a.tag==="Just"){if(n.tgtSide==="North")return Cs(n)(o._1)(a._1)(s[d])({side:Ge,down:!0})(g);if(n.tgtSide==="South")return Cs(n)(o._1)(a._1)(s[d])({side:Ie,down:!1})(g)}return g}const c=s.length-1|0;if(c>=0&&c<s.length&&o.tag==="Just"&&a.tag==="Just"){if(n.tgtSide==="North")return Cs(n)(o._1)(a._1)(s[c])({side:Ge,down:!0})(u);if(n.tgtSide==="South")return Cs(n)(o._1)(a._1)(s[c])({side:Ie,down:!1})(u)}return u},zN=t=>e=>n=>LN(t)(J(MN(n))({nextId:0,segments:[]})(e).segments)(n),QN=t=>zN(t.edges)(td(t))(PN(AN(t.edges))(t.nodes)(SN())),Dr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=it.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},rg=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},og=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=it.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},WN=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},ON=t=>{const e=t.Eq0();return n=>r=>{const o=s=>{let u=s,c=!0,g;for(;c;){const d=u,l=Rt(_=>w,_=>h=>v("Just",{head:_,tail:h}),d.queue);if(l.tag==="Nothing"){c=!1,g=d;continue}if(l.tag==="Just"){const _=l._1.head;if((p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=!1;continue}if(N.tag==="Node"){const T=t.compare(_)(N._3);if(T==="LT"){m=N._5;continue}if(T==="GT"){m=N._6;continue}if(T==="EQ"){y=!1,x=!0;continue}}f()}return x})(d.removedNodes)){u={...d,queue:l._1.tail};continue}const h=jt(p=>!Dr(p.eid)(d.removedEdges)&&(e.eq(p.src)(_)||e.eq(p.tgt)(_)))(r);if(h.tag==="Nothing"){u={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const p=e.eq(h._1.src)(_)?h._1.tgt:h._1.src,m={...d,degree:rt(t)(p)((()=>{const y=(x=>{let N=x,T=!0,C;for(;T;){const L=N;if(L.tag==="Leaf"){T=!1,C=w;continue}if(L.tag==="Node"){const S=t.compare(p)(L._3);if(S==="LT"){N=L._5;continue}if(S==="GT"){N=L._6;continue}if(S==="EQ"){T=!1,C=v("Just",L._4);continue}}f()}return C})(d.degree);if(y.tag==="Nothing")return-1;if(y.tag==="Just")return y._1-1|0;f()})())(d.degree),removedNodes:rt(t)(_)()(d.removedNodes),removedEdges:rt(it)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:_,neighbour:p,viaSrc:e.eq(h._1.src)(_)}],queue:l._1.tail};if((()=>{const y=(N=>{let T=N,C=!0,L;for(;C;){const S=T;if(S.tag==="Leaf"){C=!1,L=w;continue}if(S.tag==="Node"){const P=t.compare(p)(S._3);if(P==="LT"){T=S._5;continue}if(P==="GT"){T=S._6;continue}if(P==="EQ"){C=!1,L=v("Just",S._4);continue}}f()}return L})(m.degree),x=N=>{let T=N,C=!0,L;for(;C;){const S=T;if(S.tag==="Leaf"){C=!1,L=!1;continue}if(S.tag==="Node"){const P=t.compare(p)(S._3);if(P==="LT"){T=S._5;continue}if(P==="GT"){T=S._6;continue}if(P==="EQ"){C=!1,L=!0;continue}}f()}return L};return(()=>{if(y.tag==="Nothing")return!1;if(y.tag==="Just")return y._1===1;f()})()&&!x(m.removedNodes)})()){u={...m,queue:[...m.queue,p]};continue}u=m;continue}}f()}return g},i=J(s=>u=>Ft(t)(Te)(u.src)(1)(Ft(t)(Te)(u.tgt)(1)(s)))(F)(r),a=o({degree:i,removedNodes:F,removedEdges:F,record:[],queue:dt(s=>{const u=(c=>{let g=c,d=!0,l;for(;d;){const _=g;if(_.tag==="Leaf"){d=!1,l=w;continue}if(_.tag==="Node"){const h=t.compare(s)(_._3);if(h==="LT"){g=_._5;continue}if(h==="GT"){g=_._6;continue}if(h==="EQ"){d=!1,l=v("Just",_._4);continue}}f()}return l})(i);if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1===1;f()},n)});return{coreNodes:dt(s=>!(u=>{let c=u,g=!0,d;for(;g;){const l=c;if(l.tag==="Leaf"){g=!1,d=!1;continue}if(l.tag==="Node"){const _=t.compare(s)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){g=!1,d=!0;continue}}f()}return d})(a.removedNodes),n),coreEdges:dt(s=>!Dr(s.eid)(a.removedEdges),r),removed:a.record}}},qN=t=>e=>n=>J(r=>o=>{const i=o.neighbour,a=(()=>{const s=(u=>{let c=u,g=!0,d;for(;g;){const l=c;if(l.tag==="Leaf"){g=!1,d=w;continue}if(l.tag==="Node"){const _=t.compare(i)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){g=!1,d=v("Just",l._4);continue}}f()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;f()})();return rt(t)(o.node)(o.viaSrc?a-1|0:a+1|0)(r)})(n)(ce(e)),ig=t=>{const e=t.Eq0();return n=>r=>o=>{const i={...o,treeNode:rt(t)(r)()(o.treeNode)};return J(a=>s=>{if(Dr(s.eid)(a.st.edgeVisited))return a;const u={...a.st,edgeVisited:rt(it)(s.eid)()(a.st.edgeVisited)},c=e.eq(s.src)((()=>{const g=s.src,d=_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(g)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}f()}return m},l=s.tgt;return d(u.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}f()}return m})(u.treeNode)})()?s.src:(()=>{const g=s.tgt,d=_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(g)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}f()}return m},l=s.src;return d(u.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}f()}return m})(u.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(Dr(s.eid)(u.treeEdge)){if((d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=!1;continue}if(p.tag==="Node"){const m=t.compare(c)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=!0;continue}}f()}return h})(u.treeNode))return{...a,st:u};const g=ig(t)(n)(c)(u);return{count:a.count+g.count|0,st:g.st}}if((()=>{const g=l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=!1;continue}if(m.tag==="Node"){const y=t.compare(c)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=!0;continue}}f()}return p},d=s.tgt;return!g(u.treeNode)&&(()=>{const l=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=w;continue}if(N.tag==="Node"){const T=t.compare(d)(N._3);if(T==="LT"){m=N._5;continue}if(T==="GT"){m=N._6;continue}if(T==="EQ"){y=!1,x=v("Just",N._4);continue}}f()}return x})(u.layer),_=s.src,h=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=w;continue}if(N.tag==="Node"){const T=t.compare(_)(N._3);if(T==="LT"){m=N._5;continue}if(T==="GT"){m=N._6;continue}if(T==="EQ"){y=!1,x=v("Just",N._4);continue}}f()}return x})(u.layer);if(l.tag==="Nothing"){if(h.tag==="Nothing")return s.delta===0;if(h.tag==="Just")return s.delta===-h._1;f()}if(l.tag==="Just"){if(h.tag==="Nothing")return s.delta===(l._1-0|0);if(h.tag==="Just")return s.delta===(l._1-h._1|0)}f()})()})()){const g=ig(t)(n)(c)({...u,treeEdge:rt(it)(s.eid)()(u.treeEdge)});return{count:a.count+g.count|0,st:g.st}}return{...a,st:u}})({count:1,st:i})(dt(a=>(e.eq(a.src)(r)||e.eq(a.tgt)(r))&&!Dr(a.eid)(i.edgeVisited),n))}},ks=t=>e=>n=>r=>{const o=r.src,i=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=w;continue}if(m.tag==="Node"){const y=t.compare(o)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=v("Just",m._4);continue}}f()}return p})(e.poID),a=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;f()})(),s=r.tgt,u=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=w;continue}if(m.tag==="Node"){const y=t.compare(s)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=v("Just",m._4);continue}}f()}return p})(e.poID),c=(()=>{if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;f()})(),g=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=w;continue}if(m.tag==="Node"){const y=t.compare(n)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=v("Just",m._4);continue}}f()}return p})(e.poID),d=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;f()})();return(()=>{const l=r.src,_=(h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=w;continue}if(x.tag==="Node"){const N=t.compare(l)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=v("Just",x._4);continue}}f()}return y})(e.lowestPoID);return(()=>{if(_.tag==="Nothing")return 0<=d;if(_.tag==="Just")return _._1<=d;f()})()&&(()=>{const h=r.tgt;return d<=a&&(()=>{const p=(m=>{let y=m,x=!0,N;for(;x;){const T=y;if(T.tag==="Leaf"){x=!1,N=w;continue}if(T.tag==="Node"){const C=t.compare(h)(T._3);if(C==="LT"){y=T._5;continue}if(C==="GT"){y=T._6;continue}if(C==="EQ"){x=!1,N=v("Just",T._4);continue}}f()}return N})(e.lowestPoID);return(()=>{if(p.tag==="Nothing")return 0<=d;if(p.tag==="Just")return p._1<=d;f()})()&&d<=c})()})()})()?a>=c:a<c},HN=t=>{const e=ge(t)(Mt);return n=>({layer:e(U(r=>b(r,0))(n)),treeNode:F,treeEdge:F,poID:F,lowestPoID:F,cutvalue:F,postOrder:1,edgeVisited:F})},$N=t=>e=>n=>J(r=>o=>{if((()=>{const g=o.src,d=h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=!1;continue}if(x.tag==="Node"){const N=t.compare(g)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=!0;continue}}f()}return y},l=o.tgt,_=h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=!1;continue}if(x.tag==="Node"){const N=t.compare(l)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=!0;continue}}f()}return y};return d(n.treeNode)===_(n.treeNode)})())return r;const i=o.tgt,a=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=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,_=v("Just",h._4);continue}}f()}return _})(n.layer),s=o.src,u=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=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,_=v("Just",h._4);continue}}f()}return _})(n.layer),c=(()=>{if(a.tag==="Nothing"){if(u.tag==="Nothing")return-o.delta;if(u.tag==="Just")return-u._1-o.delta|0;f()}if(a.tag==="Just"){if(u.tag==="Nothing")return(a._1-0|0)-o.delta|0;if(u.tag==="Just")return(a._1-u._1|0)-o.delta|0}f()})();return c<r.slack?{edge:v("Just",o),slack:c}:r})({edge:w,slack:1e9})(e).edge,UN=t=>{const e=ge(t)(Mt);return n=>r=>{const o=J(i=>a=>rg(i)((()=>{const s=(u=>{let c=u,g=!0,d;for(;g;){const l=c;if(l.tag==="Leaf"){g=!1,d=w;continue}if(l.tag==="Node"){const _=t.compare(a)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){g=!1,d=v("Just",l._4);continue}}f()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;f()})()))(1e9)(n);return e(U(i=>b(i,(()=>{const a=(s=>{let u=s,c=!0,g;for(;c;){const d=u;if(d.tag==="Leaf"){c=!1,g=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,g=v("Just",d._4);continue}}f()}return g})(r);if(a.tag==="Nothing")return-o;if(a.tag==="Just")return a._1-o|0;f()})()))(n))}},nd=t=>{const e=t.Eq0();return n=>r=>o=>{const i=J(s=>u=>{const c=nd(t)(n)(e.eq(u.src)(r)?u.tgt:u.src)({...s.st,edgeVisited:rt(it)(u.eid)()(s.st.edgeVisited)});return{lowest:rg(s.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:o})(dt(s=>Dr(s.eid)(o.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!Dr(s.eid)(o.edgeVisited),n)),a=rg(i.lowest)(i.st.postOrder);return{lowest:a,st:{...i.st,poID:rt(t)(r)(i.st.postOrder)(i.st.poID),lowestPoID:rt(t)(r)(a)(i.st.lowestPoID),postOrder:i.st.postOrder+1|0}}}},rd=t=>{const e=nd(t);return n=>r=>o=>0<n.length?e(r)(n[0])({...o,edgeVisited:F,postOrder:1,poID:F,lowestPoID:F}).st:o},VN=t=>{const e=t.Eq0();return n=>r=>o=>dt(i=>Dr(i.eid)(r.treeEdge)&&(e.eq(i.src)(o)||e.eq(i.tgt)(o)),n)},XN=t=>e=>jt(n=>{const r=og(n.eid)(e.cutvalue);return Dr(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;f()})()})(t),od=t=>{const e=ig(t);return n=>r=>o=>{const i=0<n.length?v("Just",n[0]):w;if(i.tag==="Nothing")return o;if(i.tag==="Just"){const a=e(r)(i._1)({...o,edgeVisited:F,treeNode:F,treeEdge:F});if(a.count>=n.length)return a.st;const s=$N(t)(r)(a.st);if(s.tag==="Nothing")return a.st;if(s.tag==="Just"){const u=s._1.tgt,c=(h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=w;continue}if(x.tag==="Node"){const N=t.compare(u)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=v("Just",x._4);continue}}f()}return y})(a.st.layer),g=s._1.src,d=(h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=w;continue}if(x.tag==="Node"){const N=t.compare(g)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=v("Just",x._4);continue}}f()}return y})(a.st.layer),l=(()=>{if(c.tag==="Nothing"){if(d.tag==="Nothing")return-s._1.delta;if(d.tag==="Just")return-d._1-s._1.delta|0;f()}if(c.tag==="Just"){if(d.tag==="Nothing")return(c._1-0|0)-s._1.delta|0;if(d.tag==="Just")return(c._1-d._1|0)-s._1.delta|0}f()})(),_=(()=>{const h=s._1.tgt;return(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=!1;continue}if(N.tag==="Node"){const T=t.compare(h)(N._3);if(T==="LT"){m=N._5;continue}if(T==="GT"){m=N._6;continue}if(T==="EQ"){y=!1,x=!0;continue}}f()}return x})(a.st.treeNode)})()?-l:l;return od(t)(n)(r)({...a.st,layer:J(h=>p=>(m=>{let y=m,x=!0,N;for(;x;){const T=y;if(T.tag==="Leaf"){x=!1,N=!1;continue}if(T.tag==="Node"){const C=t.compare(p)(T._3);if(C==="LT"){y=T._5;continue}if(C==="GT"){y=T._6;continue}if(C==="EQ"){x=!1,N=!0;continue}}f()}return N})(a.st.treeNode)?rt(t)(p)((()=>{const m=(y=>{let x=y,N=!0,T;for(;N;){const C=x;if(C.tag==="Leaf"){N=!1,T=w;continue}if(C.tag==="Node"){const L=t.compare(p)(C._3);if(L==="LT"){x=C._5;continue}if(L==="GT"){x=C._6;continue}if(L==="EQ"){N=!1,T=v("Just",C._4);continue}}f()}return T})(a.st.layer);if(m.tag==="Nothing")return 0+_|0;if(m.tag==="Just")return m._1+_|0;f()})())(h):h)(a.st.layer)(n)})}}f()}},YN=t=>e=>n=>r=>J(o=>i=>{if(ks(t)(r)(i.src)(n)&&!ks(t)(r)(i.tgt)(n)){const a=i.tgt,s=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=w;continue}if(p.tag==="Node"){const m=t.compare(a)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=v("Just",p._4);continue}}f()}return h})(r.layer),u=i.src,c=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!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"){_=!1,h=v("Just",p._4);continue}}f()}return h})(r.layer),g=(()=>{if(s.tag==="Nothing"){if(c.tag==="Nothing")return-i.delta;if(c.tag==="Just")return-c._1-i.delta|0;f()}if(s.tag==="Just"){if(c.tag==="Nothing")return(s._1-0|0)-i.delta|0;if(c.tag==="Just")return(s._1-c._1|0)-i.delta|0}f()})();if(g<o.slack)return{edge:v("Just",i),slack:g}}return o})({edge:w,slack:1e9})(e).edge,KN=t=>{const e=t.Eq0();return n=>r=>o=>i=>{const a=i.tgt,s=i.src;return J(u=>c=>{if((()=>{const g=og(c.eid)(r.cutvalue);if(g.tag==="Just")return!0;if(g.tag==="Nothing")return!1;f()})()){const g=og(c.eid)(r.cutvalue),d=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;f()})();return e.eq(s)(c.src)||e.eq(a)(c.tgt)?u-(d-c.weight):u+(d-c.weight)}return e.eq(o)(s)?e.eq(c.src)(o)?u+c.weight:u-c.weight:e.eq(c.src)(o)?u-c.weight:u+c.weight})(i.weight)(dt(u=>u.eid!==i.eid&&(e.eq(u.src)(o)||e.eq(u.tgt)(o)),n))}},jN=t=>{const e=KN(t);return n=>r=>o=>{const i=(a,s,u)=>{const c=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=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,_=v("Just",h._4);continue}}f()}return _})(u);if(c.tag==="Just")return rt(t)(a)(dt(g=>g.eid!==s.eid,c._1))(u);if(c.tag==="Nothing")return u;f()};return(a=>s=>{let u=a,c=s,g=!0,d;for(;g;){const l=u,_=c,h=(m=>{let y=m,x=!0,N;for(;x;){const T=y;if(T.tag==="Leaf"){x=!1,N=w;continue}if(T.tag==="Node"){const C=t.compare(_)(T._3);if(C==="LT"){y=T._5;continue}if(C==="GT"){y=T._6;continue}if(C==="EQ"){x=!1,N=v("Just",T._4);continue}}f()}return N})(l.unknown),p=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;f()})();if(p.length===1){const m=t.Eq0().eq(p[0].src)(_)?p[0].tgt:p[0].src;u={unknown:i(_,p[0],i(m,p[0],l.unknown)),cutvalue:rt(it)(p[0].eid)(e(n)(l)(_)(p[0]))(l.cutvalue)},c=m;continue}g=!1,d=l}return d})(r)(o)}},id=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:c=>g=>c.delta===g.delta&&c.eid===g.eid&&n.eq(c.src)(g.src)&&e.eq(c.tgt)(g.tgt)&&c.weight===g.weight},o={compare:c=>g=>{const d=it.compare(c.delta)(g.delta);if(d==="LT"||d==="GT"||d!=="EQ")return d;const l=it.compare(c.eid)(g.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const _=t.compare(c.src)(g.src);if(_==="LT"||_==="GT"||_!=="EQ")return _;const h=t.compare(c.tgt)(g.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const p=ot.compare(c.weight)(g.weight);return p==="LT"||p==="GT"||p!=="EQ"?p:Ze},Eq0:()=>r},i=J(c=>g=>rt(o)(g)()(c))(F),a=VN(t),s=ge(t)(Mt),u=jN(t);return c=>g=>d=>{const l={unknown:s(U(_=>b(_,Zt(dn.foldr,i(a(g)(d)(_)))))(c)),cutvalue:F};return{...d,cutvalue:J(u(g))(l)(dt(_=>{const h=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=w;continue}if(N.tag==="Node"){const T=t.compare(_)(N._3);if(T==="LT"){m=N._5;continue}if(T==="GT"){m=N._6;continue}if(T==="EQ"){y=!1,x=v("Just",N._4);continue}}f()}return x})(l.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;f()},c)).cutvalue}}},ZN=t=>{const e=rd(t),n=id(t);return r=>o=>i=>a=>s=>{const u={...s,treeEdge:rt(it)(a.eid)()(oi(it)(i.eid)(s.treeEdge))},c=a.tgt,g=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=w;continue}if(N.tag==="Node"){const T=t.compare(c)(N._3);if(T==="LT"){m=N._5;continue}if(T==="GT"){m=N._6;continue}if(T==="EQ"){y=!1,x=v("Just",N._4);continue}}f()}return x})(u.layer),d=a.src,l=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=w;continue}if(N.tag==="Node"){const T=t.compare(d)(N._3);if(T==="LT"){m=N._5;continue}if(T==="GT"){m=N._6;continue}if(T==="EQ"){y=!1,x=v("Just",N._4);continue}}f()}return x})(u.layer),_=(()=>{if(g.tag==="Nothing"){if(l.tag==="Nothing")return-a.delta;if(l.tag==="Just")return-l._1-a.delta|0;f()}if(g.tag==="Just"){if(l.tag==="Nothing")return(g._1-0|0)-a.delta|0;if(l.tag==="Just")return(g._1-l._1|0)-a.delta|0}f()})(),h=ks(t)(u)(a.tgt)(i)?_:-_;return n(r)(o)(e(r)(o)({...u,layer:J(p=>m=>ks(t)(u)(m)(i)?p:rt(t)(m)((()=>{const y=(x=>{let N=x,T=!0,C;for(;T;){const L=N;if(L.tag==="Leaf"){T=!1,C=w;continue}if(L.tag==="Node"){const S=t.compare(m)(L._3);if(S==="LT"){N=L._5;continue}if(S==="GT"){N=L._6;continue}if(S==="EQ"){T=!1,C=v("Just",L._4);continue}}f()}return C})(u.layer);if(y.tag==="Nothing")return 0+h|0;if(y.tag==="Just")return y._1+h|0;f()})())(p))(u.layer)(r)}))}},tv=t=>{const e=ZN(t);return n=>r=>o=>i=>(a=>s=>{let u=a,c=s,g=!0,d;for(;g;){const l=u,_=c;if(l===0){g=!1,d=_;continue}const h=XN(o)(_);if(h.tag==="Nothing"){g=!1,d=_;continue}if(h.tag==="Just"){const p=YN(t)(o)(h._1)(_);if(p.tag==="Nothing"){g=!1,d=_;continue}if(p.tag==="Just"){u=l-1|0,c=e(r)(o)(h._1)(p._1)(_);continue}}f()}return d})(n)(i)},ev=t=>{const e=id(t),n=rd(t),r=od(t);return o=>i=>a=>e(o)(i)(n(o)(i)(r(o)(i)(a)))},ad=t=>e=>J(n=>r=>Ft(t)(xe)(e(r))([r])(n))(F),nv=t=>{const e=ge(t)(Mt);return n=>r=>o=>{const i=u=>c=>g=>d=>{let l=u,_=c,h=g,p=d,m=!0,y;for(;m;){const x=l,N=_,T=h,C=p,L=Rt(S=>w,S=>P=>v("Just",{head:S,tail:P}),T);if(L.tag==="Nothing"){m=!1,y=C;continue}if(L.tag==="Just"){const S=L._1.head,P=(G=>{let I=G,j=!0,O;for(;j;){const z=I;if(z.tag==="Leaf"){j=!1,O=w;continue}if(z.tag==="Node"){const $=t.compare(S)(z._3);if($==="LT"){I=z._5;continue}if($==="GT"){I=z._6;continue}if($==="EQ"){j=!1,O=v("Just",z._4);continue}}f()}return O})(C.layer),M=(()=>{if(P.tag==="Nothing")return 0;if(P.tag==="Just")return P._1;f()})(),W=J(G=>I=>{const j=I.tgt,O=($=>{let q=$,D=!0,B;for(;D;){const R=q;if(R.tag==="Leaf"){D=!1,B=w;continue}if(R.tag==="Node"){const E=t.compare(j)(R._3);if(E==="LT"){q=R._5;continue}if(E==="GT"){q=R._6;continue}if(E==="EQ"){D=!1,B=v("Just",R._4);continue}}f()}return B})(G.incident),z=(()=>{if(O.tag==="Nothing")return-1;if(O.tag==="Just")return O._1-1|0;f()})();return{st:{...G.st,layer:rt(t)(I.tgt)(WN((()=>{const $=I.tgt,q=(D=>{let B=D,R=!0,E;for(;R;){const Q=B;if(Q.tag==="Leaf"){R=!1,E=w;continue}if(Q.tag==="Node"){const Y=t.compare($)(Q._3);if(Y==="LT"){B=Q._5;continue}if(Y==="GT"){B=Q._6;continue}if(Y==="EQ"){R=!1,E=v("Just",Q._4);continue}}f()}return E})(G.st.layer);if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;f()})())(M+I.delta|0))(G.st.layer)},incident:rt(t)(I.tgt)(z)(G.incident),queue:z===0?[...G.queue,I.tgt]:G.queue}})({st:C,incident:N,queue:L._1.tail})((()=>{const G=(I=>{let j=I,O=!0,z;for(;O;){const $=j;if($.tag==="Leaf"){O=!1,z=w;continue}if($.tag==="Node"){const q=t.compare(S)($._3);if(q==="LT"){j=$._5;continue}if(q==="GT"){j=$._6;continue}if(q==="EQ"){O=!1,z=v("Just",$._4);continue}}f()}return z})(x);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;f()})());l=x,_=W.incident,h=W.queue,p=W.st;continue}f()}return y},a=ad(t)(u=>u.tgt)(r),s=e(U(u=>b(u,(()=>{const c=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=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,_=v("Just",h._4);continue}}f()}return _})(a);if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1.length;f()})()))(n));return i(ad(t)(u=>u.src)(r))(s)(dt(u=>{const c=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=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,_=v("Just",h._4);continue}}f()}return _})(s);if(c.tag==="Nothing")return!0;if(c.tag==="Just")return c._1===0;f()},n))(o)}},rv=t=>{const e=HN(t),n=nv(t),r=ev(t),o=tv(t);return i=>a=>{const s=n(i)(a)(e(i));return a.length===0?s.layer:o(4*i.length|0)(i)(a)(r(i)(a)(s)).layer}},sd=t=>{const e=UN(t),n=rv(t),r=ON(t);return o=>i=>{if(o.length===0)return F;if(o.length<40)return e(o)(n(o)(i));const a=r(o)(i);return e(o)(qN(t)(a.removed)(n(a.coreNodes)(a.coreEdges)))}},ud=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=it.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},ag=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},ov=sd(it),ji=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}),iv=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=et((()=>{const o=ud(n.cGroup._1)(t);if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;f()})());return wn(n.id)(o=>({...o,hitbox:{...o.hitbox,x:r+o.cGroupOffset.x}}))(e)}f()},av=t=>e=>({...e,cGraph:J(iv(t))(e.cGraph)((()=>{const n=e.cGraph;return vt(r=>_e(r)(n.cNodes))(n.cNodeOrder)})())}),sv=t=>e=>n=>r=>o=>{const i=he(za(e.cGroupOffset.x-t.cGroupOffset.x));return ji({src:o.nextNodeId,tgt:r,delta:ag(0)(-i),weight:1})(ji({src:o.nextNodeId,tgt:n,delta:ag(0)(i),weight:1})({...o,nodes:[...o.nodes,o.nextNodeId],nextNodeId:o.nextNodeId+1|0}))},uv=t=>e=>n=>r=>o=>i=>a=>{const s=ag(0)(he(za(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)?sv(n)(r)(o)(i)(a):ji({src:o,tgt:i,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(a)},cv=t=>e=>n=>r=>o=>{const i=_e(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"?uv(t)(e)(n)(i._1)(n.cGroup._1)(i._1.cGroup._1)(r):r;f()},gv=t=>e=>n=>r=>J(cv(t)(e)(r))(n)(r.constraints),fv=t=>e=>ji({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),_v=t=>{const e=J(o=>i=>Ft(it)(Te)(i.tgt)(1)(o))(F)(t.edges),n=dt(o=>{const i=ud(o)(e);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return i._1===0;f()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return J(o=>i=>ji({src:r,tgt:i,delta:1,weight:0})(o))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},dv=t=>e=>{const n=_v(J(fv)(J(gv(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return vt(o=>_e(o)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},lv=t=>e=>{const n=dv(t)(e);return av(ov(n.nodes)(n.edges))(e)},cd=t=>t,Ne=cd("H"),me=cd("V"),hv=t=>b(t._2,t._1),gd=t=>({...t,position:b(t.position._2,t.position._1),size:b(t.size._2,t.size._1)}),pv=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 Ne;f()})()}),fd=t=>({...t,segments:U(pv)(t.segments),bends:U(hv)(t.bends)}),mv=t=>({nodes:U(gd)(t.nodes),edges:t.edges,paths:U(fd)(t.paths),ports:t.ports}),yv={nodeNode:8,edgeNode:4,edgeEdge:10},xv=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}}),wv=t=>e=>lv(e),Nv=t=>e=>n=>{const r=mv(n),o=QN(r),i=RN(o)(td(r)),a=BN(W1(Xc)(aN({...uN(o.cGraph),compactionAlgorithm:v("Just",wv()(i)),constraintAlgorithm:v("Just",wN(e.edgeEdge)),spacingsHandler:xv(e)(i)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:U(gd)(a.nodes),edges:U(fd)(a.edges)}},_d=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},dd=t=>ze(3)(t)==="$d:",vv=t=>e=>n=>J(r=>o=>{const i=_d(o.from.node)(t),a=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;f()})(),s=_d(o.to.node)(t),u=(()=>{if(s.tag==="Nothing")return-a;if(s.tag==="Just")return s._1-a|0;f()})();if(u<=1)return{...r,edges:[...r.edges,o],chains:[...r.chains,{edgeId:o.id,nodes:[o.from.node,o.to.node]}]};const c=o.id,g=U(l=>"$d:"+c+":"+ue(l))(Kt(1,u-1|0)),d=[o.from.node,...g,o.to.node];return{...r,layers:J(l=>_=>{const h=_._2,p=Qm(a+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;f()})(r.layers)(We(Bn,Kt(1,u-1|0),g)),edges:[...r.edges,...We(l=>_=>({id:c+":"+l+"->"+_,from:{node:l,port:o.from.port},to:{node:_,port:o.to.port},label:w}),d,It(1,d.length,d))],chains:[...r.chains,{edgeId:o.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),ld=t=>t,hi=ge(it)(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 a=it.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},hd=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},xt=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},wt=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},pi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Tv=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?Fe:n==="GT"?Me:it.compare(t._2)(e._2)},mi=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},Jv=(()=>{const t=fn.unfoldr(Xn);return e=>t(_n("IterNode",e,Un))})(),bv=t=>t,pd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Cv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Ls=ld("Regular"),Ss=ld("Critical"),md=t=>e=>{const n=J(a=>s=>rt(A)(s.node)(s)(a))(F)(e),r=1.25*et(4),o=(a,s,u)=>(c=>g=>d=>{let l=c,_=g,h=d,p=!0,m;for(;p;){const y=l,x=_,N=h;if(N.critical){p=!1,m=N;continue}const T=Rt(L=>w,L=>S=>v("Just",{head:L,tail:S}),y),C=Rt(L=>w,L=>S=>v("Just",{head:L,tail:S}),x);if(T.tag==="Just"&&C.tag==="Just"){const L=T._1.head>C._1.head-a&&T._1.head<C._1.head+a?{...N,critical:!0}:T._1.head>C._1.head-r&&T._1.head<C._1.head+r?{...N,conflicts:N.conflicts+1|0}:N;if(L.critical){p=!1,m=L;continue}if(T._1.head<=C._1.head){l=T._1.tail,_=x,h=L;continue}l=y,_=C._1.tail,h=L;continue}p=!1,m=N}return m})(s)(u)({conflicts:0,critical:!1}),i=(a,s,u)=>{if(wt(J(wt)(-1e18)(s.incoming))(J(wt)(-1e18)(s.outgoing))-xt(J(xt)(1e18)(s.incoming))(J(xt)(1e18)(s.outgoing))<.001||wt(J(wt)(-1e18)(u.incoming))(J(wt)(-1e18)(u.outgoing))-xt(J(xt)(1e18)(u.incoming))(J(xt)(1e18)(u.outgoing))<.001)return[];const c=o(a,s.outgoing,u.incoming),g=o(a,u.outgoing,s.incoming);if(c.critical||g.critical)return[...c.critical?[{src:u.id,tgt:s.id,weight:1,kind:Ss}]:[],...g.critical?[{src:s.id,tgt:u.id,weight:1,kind:Ss}]:[]];const d=xt(J(xt)(1e18)(s.incoming))(J(xt)(1e18)(s.outgoing)),l=wt(J(wt)(-1e18)(s.incoming))(J(wt)(-1e18)(s.outgoing)),_=xt(J(xt)(1e18)(u.incoming))(J(xt)(1e18)(u.outgoing)),h=wt(J(wt)(-1e18)(u.incoming))(J(wt)(-1e18)(u.outgoing)),p=(1*c.conflicts|0)+(16*(J(y=>x=>x>h?y:x>=_?y+1|0:y)(0)(s.outgoing)+J(y=>x=>x>l?y:x>=d?y+1|0:y)(0)(u.incoming)|0)|0)|0,m=(1*g.conflicts|0)+(16*(J(y=>x=>x>l?y:x>=d?y+1|0:y)(0)(u.outgoing)+J(y=>x=>x>h?y:x>=_?y+1|0:y)(0)(s.incoming)|0)|0)|0;return p<m?[{src:s.id,tgt:u.id,weight:m-p|0,kind:Ls}]:p>m?[{src:u.id,tgt:s.id,weight:p-m|0,kind:Ls}]:p>0?[{src:s.id,tgt:u.id,weight:0,kind:Ls},{src:u.id,tgt:s.id,weight:0,kind:Ls}]:[]};return J(a=>s=>J(u=>c=>rt(A)(c._1)(c._2)(u))(a)((()=>{const u=J(G=>I=>{const j=I.edge.from.node+"|"+(()=>{if(I.edge.from.port.tag==="Just")return I.edge.from.port._1;if(I.edge.from.port.tag==="Nothing")return"_auto_"+I.edge.id;f()})(),O=pd(j)(G.entries);if(O.tag==="Nothing")return{...G,entries:rt(A)(j)({id:0,members:[I.edge.id],incoming:[I.fromPos._1],outgoing:[I.toPos._1],slot:0,mark:0,splitBy:w,splitPartner:w})(G.entries),order:[...G.order,j]};if(O.tag==="Just")return{...G,entries:rt(A)(j)({...O._1,members:[...O._1.members,I.edge.id],incoming:[...ar(z=>z<I.fromPos._1)(O._1.incoming).init,I.fromPos._1,...ar(z=>z<=I.fromPos._1)(O._1.incoming).rest],outgoing:[...ar(z=>z<I.toPos._1)(O._1.outgoing).init,I.toPos._1,...ar(z=>z<=I.toPos._1)(O._1.outgoing).rest]})(G.entries)};f()})({entries:F,order:[]})(s._2),c=qt(G=>I=>({...I,id:G}))(vt(G=>pd(G)(u.entries))(u.order));if(c.length===0)return[];const g=J(G=>I=>G.prev.tag==="Just"&&I-G.prev._1<1e-9?G:{prev:v("Just",I),out:[...G.out,I]})({prev:w,out:[]})(Pt(ot.compare)([...St(c)(G=>G.incoming),...St(c)(G=>G.outgoing)])).out,d=g.length<2?.2*r:.2*J(G=>I=>{if(G.prev.tag==="Nothing")return{prev:v("Just",I),mn:G.mn};if(G.prev.tag==="Just")return{prev:v("Just",I),mn:xt(G.mn)(I-G.prev._1)};f()})({prev:w,mn:1e18})(g).mn,l={segments:c,deps:(()=>{const G=c.length;return St(St(Kt(0,G-2|0))(I=>St(Kt(I+1|0,G-1|0))(j=>[b(I,j)])))(I=>I._1>=0&&I._1<c.length?I._2>=0&&I._2<c.length?i(d,c[I._1],c[I._2]):[]:[])})()},_=dt(G=>{if(G.kind==="Critical")return!0;if(G.kind==="Regular")return!1;f()},l.deps),h=(()=>{if(_.length<2)return l;const G=hi((()=>{const $=l.segments;return U(q=>b(q.id,q.mark))((()=>{const q=$.length,D=R=>{let E=R,Q=!0,Y;for(;Q;){const H=E,K=jt(X=>{const Z=Xt(X)(H.inWeight);if(Z.tag==="Nothing")return!0;if(Z.tag==="Just")return Z._1===0;f()})(H.remaining);if(K.tag==="Nothing"){Q=!1,Y=H;continue}if(K.tag==="Just"){const X=K._1;E={...H,inWeight:J(Z=>nt=>Ft(it)(Te)(nt.tgt)(-nt.weight)(Z))(H.inWeight)((()=>{const Z=Xt(X)(H.depsBySrc);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;f()})()),marks:rt(it)(X)(H.nextSource)(H.marks),nextSource:H.nextSource+1|0,outWeight:J(Z=>nt=>Ft(it)(Te)(nt.src)(-nt.weight)(Z))(H.outWeight)((()=>{const Z=Xt(X)(H.depsByTgt);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;f()})()),remaining:dt(Z=>Z!==X,H.remaining)};continue}f()}return Y},B=R=>{let E=R,Q=!0,Y;for(;Q;){const H=E,K=jt(X=>{const Z=Xt(X)(H.outWeight);if(Z.tag==="Nothing")return!0;if(Z.tag==="Just")return Z._1===0;f()})(H.remaining);if(K.tag==="Nothing"){Q=!1,Y=H;continue}if(K.tag==="Just"){const X=K._1;E={...H,inWeight:J(Z=>nt=>Ft(it)(Te)(nt.tgt)(-nt.weight)(Z))(H.inWeight)((()=>{const Z=Xt(X)(H.depsBySrc);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;f()})()),marks:rt(it)(X)(H.nextSink)(H.marks),nextSink:H.nextSink-1|0,outWeight:J(Z=>nt=>Ft(it)(Te)(nt.src)(-nt.weight)(Z))(H.outWeight)((()=>{const Z=Xt(X)(H.depsByTgt);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;f()})()),remaining:dt(Z=>Z!==X,H.remaining)};continue}f()}return Y};return(R=>{let E=R,Q=!0,Y;for(;Q;){const H=D(B(E));if(H.remaining.length===0){Q=!1,Y=U(K=>{const X=Xt(K.id)(H.marks),Z=(()=>{if(X.tag==="Nothing")return K.id;if(X.tag==="Just")return X._1;f()})();return{...K,mark:Z<q?(Z+q|0)+1|0:Z}})($);continue}E=(()=>{const K=Z=>{const nt=Xt(Z)(H.outWeight),gt=Xt(Z)(H.inWeight);return(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;f()})()-(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;f()})()|0},X=Pt(Z=>nt=>it.compare(K(nt))(K(Z)))(H.remaining);if(0<X.length){const Z=X[0];return{...H,inWeight:J(nt=>gt=>Ft(it)(Te)(gt.tgt)(-gt.weight)(nt))(H.inWeight)((()=>{const nt=Xt(Z)(H.depsBySrc);if(nt.tag==="Nothing")return[];if(nt.tag==="Just")return nt._1;f()})()),marks:rt(it)(Z)(H.nextSource)(H.marks),nextSource:H.nextSource+1|0,outWeight:J(nt=>gt=>Ft(it)(Te)(gt.src)(-gt.weight)(nt))(H.outWeight)((()=>{const nt=Xt(Z)(H.depsByTgt);if(nt.tag==="Nothing")return[];if(nt.tag==="Just")return nt._1;f()})()),remaining:dt(nt=>nt!==Z,H.remaining)}}return H})()}return Y})({remaining:U(R=>R.id)($),marks:F,inWeight:J(R=>E=>Ft(it)(Te)(E.tgt)(E.weight)(R))(F)(_),outWeight:J(R=>E=>Ft(it)(Te)(E.src)(E.weight)(R))(F)(_),depsBySrc:J(R=>E=>Ft(it)(xe)(E.src)([E])(R))(F)(_),depsByTgt:J(R=>E=>Ft(it)(xe)(E.tgt)([E])(R))(F)(_),nextSink:q-1|0,nextSource:q+1|0})})())})()),I=dt($=>{const q=Xt($.src)(G),D=Xt($.tgt)(G);return(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;f()})()>(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;f()})()},_);if(I.length===0)return l;const j=J($=>q=>{if(nn($r)(q.src)($.decisions)||nn($r)(q.tgt)($.decisions))return $;const D=Xt(q.src)($.segMap),B=Xt(q.tgt)($.segMap);if(D.tag==="Just"&&B.tag==="Just"){const R=(D._1.incoming.length+D._1.outgoing.length|0)>2&&(B._1.incoming.length+B._1.outgoing.length|0)<=2,E=R?B._1:D._1;return{decisions:[...$.decisions,E.id],segMap:rt(it)(E.id)({...E,splitBy:v("Just",R?D._1.id:B._1.id)})($.segMap)}}return $})({decisions:[],segMap:hi(U($=>b($.id,$))(l.segments))})(I),O=j.segMap,z=J($=>q=>{const D=xt(J(xt)(1e18)(q.incoming))(J(xt)(1e18)(q.outgoing)),B=wt(J(wt)(-1e18)(q.incoming))(J(wt)(-1e18)(q.outgoing)),R=dt(K=>K.a.startPosition<=B&&K.a.endPosition>=D,qt(K=>X=>({i:K,a:X}))($.freeAreas));if(R.length===0){const K={...q,incoming:Pt(ot.compare)(q.incoming),outgoing:Pt(ot.compare)([(D+B)/2]),splitPartner:v("Just",$.nextId)},X={id:$.nextId,incoming:Pt(ot.compare)([(D+B)/2]),mark:0,members:q.members,outgoing:Pt(ot.compare)(q.outgoing),slot:0,splitBy:w,splitPartner:v("Just",q.id)};return{segMap:rt(it)(X.id)(X)(rt(it)(K.id)(K)($.segMap)),freeAreas:$.freeAreas,nextId:$.nextId+1|0}}const E=0<R.length?v("Just",R[0]):w,Q=(()=>{if(E.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(E.tag==="Just"){if(R.length===1)return E._1;const K=U(X=>({c:X,rating:(()=>{const Z=(X.a.startPosition+X.a.endPosition)/2,nt=[Z],gt=[Z],bt=J((()=>{const Tt=$.segMap;return Et=>te=>{const Jt=Xt(te.tgt)(Tt);if(Jt.tag==="Nothing")return Et;if(Jt.tag==="Just"){const Yt=xt(J(xt)(1e18)(Jt._1.incoming))(J(xt)(1e18)(Jt._1.outgoing)),Dt=wt(J(wt)(-1e18)(Jt._1.incoming))(J(wt)(-1e18)(Jt._1.outgoing)),yt=xt(J(xt)(1e18)(q.incoming))(J(xt)(1e18)(nt)),ht=(()=>{const Ut=wt(J(wt)(-1e18)(q.incoming))(J(wt)(-1e18)(nt)),Wt=J(re=>se=>se>Dt?re:se>=Yt?re+1|0:re)(0)(nt)+J(re=>se=>se>Ut?re:se>=yt?re+1|0:re)(0)(Jt._1.incoming)|0,gn=xt(J(xt)(1e18)(q.incoming))(J(xt)(1e18)(nt)),pn=wt(J(wt)(-1e18)(q.incoming))(J(wt)(-1e18)(nt)),He=xt(J(xt)(1e18)(Jt._1.incoming))(J(xt)(1e18)(Jt._1.outgoing)),kn=wt(J(wt)(-1e18)(Jt._1.incoming))(J(wt)(-1e18)(Jt._1.outgoing)),Be=J(re=>se=>se>pn?re:se>=gn?re+1|0:re)(0)(Jt._1.outgoing)+J(re=>se=>se>kn?re:se>=He?re+1|0:re)(0)(q.incoming)|0;return Wt===Be?Wt>0?{...Et,deps:Et.deps+2|0,crossings:Et.crossings+Wt|0}:Et:{...Et,deps:Et.deps+1|0,crossings:Et.crossings+mi(Wt)(Be)|0}})(),ft=xt(J(xt)(1e18)(Jt._1.incoming))(J(xt)(1e18)(Jt._1.outgoing)),pt=wt(J(wt)(-1e18)(Jt._1.incoming))(J(wt)(-1e18)(Jt._1.outgoing)),At=xt(J(xt)(1e18)(gt))(J(xt)(1e18)(q.outgoing)),Gt=wt(J(wt)(-1e18)(gt))(J(wt)(-1e18)(q.outgoing)),Nt=J(Ut=>Wt=>Wt>pt?Ut:Wt>=ft?Ut+1|0:Ut)(0)(q.outgoing)+J(Ut=>Wt=>Wt>Gt?Ut:Wt>=At?Ut+1|0:Ut)(0)(Jt._1.incoming)|0,Lt=xt(J(xt)(1e18)(gt))(J(xt)(1e18)(q.outgoing)),Qt=wt(J(wt)(-1e18)(gt))(J(wt)(-1e18)(q.outgoing)),ee=xt(J(xt)(1e18)(Jt._1.incoming))(J(xt)(1e18)(Jt._1.outgoing)),ae=wt(J(wt)(-1e18)(Jt._1.incoming))(J(wt)(-1e18)(Jt._1.outgoing)),ne=J(Ut=>Wt=>Wt>Qt?Ut:Wt>=Lt?Ut+1|0:Ut)(0)(Jt._1.outgoing)+J(Ut=>Wt=>Wt>ae?Ut:Wt>=ee?Ut+1|0:Ut)(0)(gt)|0;return Nt===ne?Nt>0?{...ht,deps:ht.deps+2|0,crossings:ht.crossings+Nt|0}:ht:{...ht,deps:ht.deps+1|0,crossings:ht.crossings+mi(Nt)(ne)|0}}f()}})())(J((()=>{const Tt=$.segMap;return Et=>te=>{const Jt=Xt(te.src)(Tt);if(Jt.tag==="Nothing")return Et;if(Jt.tag==="Just"){const Yt=xt(J(xt)(1e18)(Jt._1.incoming))(J(xt)(1e18)(Jt._1.outgoing)),Dt=wt(J(wt)(-1e18)(Jt._1.incoming))(J(wt)(-1e18)(Jt._1.outgoing)),yt=xt(J(xt)(1e18)(q.incoming))(J(xt)(1e18)(nt)),ht=(()=>{const Ut=wt(J(wt)(-1e18)(q.incoming))(J(wt)(-1e18)(nt)),Wt=J(re=>se=>se>Dt?re:se>=Yt?re+1|0:re)(0)(nt)+J(re=>se=>se>Ut?re:se>=yt?re+1|0:re)(0)(Jt._1.incoming)|0,gn=xt(J(xt)(1e18)(q.incoming))(J(xt)(1e18)(nt)),pn=wt(J(wt)(-1e18)(q.incoming))(J(wt)(-1e18)(nt)),He=xt(J(xt)(1e18)(Jt._1.incoming))(J(xt)(1e18)(Jt._1.outgoing)),kn=wt(J(wt)(-1e18)(Jt._1.incoming))(J(wt)(-1e18)(Jt._1.outgoing)),Be=J(re=>se=>se>pn?re:se>=gn?re+1|0:re)(0)(Jt._1.outgoing)+J(re=>se=>se>kn?re:se>=He?re+1|0:re)(0)(q.incoming)|0;return Wt===Be?Wt>0?{...Et,deps:Et.deps+2|0,crossings:Et.crossings+Wt|0}:Et:{...Et,deps:Et.deps+1|0,crossings:Et.crossings+mi(Wt)(Be)|0}})(),ft=xt(J(xt)(1e18)(Jt._1.incoming))(J(xt)(1e18)(Jt._1.outgoing)),pt=wt(J(wt)(-1e18)(Jt._1.incoming))(J(wt)(-1e18)(Jt._1.outgoing)),At=xt(J(xt)(1e18)(gt))(J(xt)(1e18)(q.outgoing)),Gt=wt(J(wt)(-1e18)(gt))(J(wt)(-1e18)(q.outgoing)),Nt=J(Ut=>Wt=>Wt>pt?Ut:Wt>=ft?Ut+1|0:Ut)(0)(q.outgoing)+J(Ut=>Wt=>Wt>Gt?Ut:Wt>=At?Ut+1|0:Ut)(0)(Jt._1.incoming)|0,Lt=xt(J(xt)(1e18)(gt))(J(xt)(1e18)(q.outgoing)),Qt=wt(J(wt)(-1e18)(gt))(J(wt)(-1e18)(q.outgoing)),ee=xt(J(xt)(1e18)(Jt._1.incoming))(J(xt)(1e18)(Jt._1.outgoing)),ae=wt(J(wt)(-1e18)(Jt._1.incoming))(J(wt)(-1e18)(Jt._1.outgoing)),ne=J(Ut=>Wt=>Wt>Qt?Ut:Wt>=Lt?Ut+1|0:Ut)(0)(Jt._1.outgoing)+J(Ut=>Wt=>Wt>ae?Ut:Wt>=ee?Ut+1|0:Ut)(0)(gt)|0;return Nt===ne?Nt>0?{...ht,deps:ht.deps+2|0,crossings:ht.crossings+Nt|0}:ht:{...ht,deps:ht.deps+1|0,crossings:ht.crossings+mi(Nt)(ne)|0}}f()}})())({crossings:0,deps:0})(dt(Tt=>Tt.tgt===q.id,l.deps)))(dt(Tt=>Tt.src===q.id,l.deps)),lt=(()=>{if(q.splitBy.tag==="Just")return Xt(q.splitBy._1)($.segMap);if(q.splitBy.tag==="Nothing")return w;f()})();if(lt.tag==="Just")return{...bt,deps:bt.deps+2|0,crossings:(()=>{const Tt=xt(J(xt)(1e18)(lt._1.incoming))(J(xt)(1e18)(lt._1.outgoing)),Et=xt(J(xt)(1e18)(gt))(J(xt)(1e18)(q.outgoing)),te=wt(J(wt)(-1e18)(lt._1.incoming))(J(wt)(-1e18)(lt._1.outgoing)),Jt=wt(J(wt)(-1e18)(gt))(J(wt)(-1e18)(q.outgoing)),Yt=xt(J(xt)(1e18)(q.incoming))(J(xt)(1e18)(nt));return bt.crossings+(()=>{const Dt=xt(J(xt)(1e18)(lt._1.incoming))(J(xt)(1e18)(lt._1.outgoing)),yt=wt(J(wt)(-1e18)(q.incoming))(J(wt)(-1e18)(nt)),ht=wt(J(wt)(-1e18)(lt._1.incoming))(J(wt)(-1e18)(lt._1.outgoing));return((J(ft=>pt=>pt>te?ft:pt>=Tt?ft+1|0:ft)(0)(nt)+J(ft=>pt=>pt>yt?ft:pt>=Yt?ft+1|0:ft)(0)(lt._1.incoming)|0)+J(ft=>pt=>pt>Jt?ft:pt>=Et?ft+1|0:ft)(0)(lt._1.outgoing)|0)+J(ft=>pt=>pt>ht?ft:pt>=Dt?ft+1|0:ft)(0)(gt)|0})()|0})()};if(lt.tag==="Nothing")return bt;f()})()}))(R);return J(X=>Z=>Z.rating.crossings<X.rating.crossings||!(Z.rating.crossings>X.rating.crossings)&&(Z.rating.deps<X.rating.deps||!(Z.rating.deps>X.rating.deps)&&Z.c.a.size>X.c.a.size)?Z:X)(0<K.length?K[0]:{c:E._1,rating:{crossings:1e6,deps:1e6}})(K).c}f()})(),Y={...q,incoming:Pt(ot.compare)(q.incoming),outgoing:Pt(ot.compare)([(Q.a.startPosition+Q.a.endPosition)/2]),splitPartner:v("Just",$.nextId)},H={id:$.nextId,incoming:Pt(ot.compare)([(Q.a.startPosition+Q.a.endPosition)/2]),mark:0,members:q.members,outgoing:Pt(ot.compare)(q.outgoing),slot:0,splitBy:w,splitPartner:v("Just",q.id)};return{segMap:rt(it)(H.id)(H)(rt(it)(Y.id)(Y)($.segMap)),freeAreas:(()=>{if(Q.i>=0&&Q.i<$.freeAreas.length){const K=s_(Vt,w,Q.i,$.freeAreas),X=(()=>{if(K.tag==="Nothing")return $.freeAreas;if(K.tag==="Just")return K._1;f()})();if($.freeAreas[Q.i].size/2<d)return X;const Z=($.freeAreas[Q.i].startPosition+$.freeAreas[Q.i].endPosition)/2,nt=Z-d,gt=Z+d;return[...Q.i<1?[]:It(0,Q.i,X),...$.freeAreas[Q.i].startPosition<=nt?[{startPosition:$.freeAreas[Q.i].startPosition,endPosition:nt,size:nt-$.freeAreas[Q.i].startPosition}]:[],...gt<=$.freeAreas[Q.i].endPosition?[{startPosition:gt,endPosition:$.freeAreas[Q.i].endPosition,size:$.freeAreas[Q.i].endPosition-gt}]:[],...Q.i<1?X:It(Q.i,X.length,X)]}return $.freeAreas})(),nextId:$.nextId+1|0}})({segMap:O,freeAreas:(()=>{const $=Pt(ot.compare)([...St(l.segments)(q=>q.incoming),...St(l.segments)(q=>q.outgoing)]);return vt(bv)(We(q=>D=>D-q>=2*d?v("Just",{startPosition:q+d,endPosition:D-d,size:D-q-2*d}):w,$,It(1,$.length,$)))})(),nextId:l.segments.length})(Pt($=>q=>ot.compare(wt(J(wt)(-1e18)($.incoming))(J(wt)(-1e18)($.outgoing))-xt(J(xt)(1e18)($.incoming))(J(xt)(1e18)($.outgoing)))(wt(J(wt)(-1e18)(q.incoming))(J(wt)(-1e18)(q.outgoing))-xt(J(xt)(1e18)(q.incoming))(J(xt)(1e18)(q.outgoing))))(vt($=>Xt($)(O))(j.decisions)));return{segments:(()=>{const $=(q,D)=>{if(q.tag==="Leaf")return D;if(q.tag==="Node")return $(q._5,kt("Cons",q._4,$(q._6,D)));f()};return Zt(ye.foldr,$(z.segMap,V))})(),deps:(()=>{const $=z.segMap,q=(R,E)=>{if(R.tag==="Leaf")return E;if(R.tag==="Node")return q(R._5,kt("Cons",R._4,q(R._6,E)));f()},D=Zt(ye.foldr,q($,V)),B=D.length;return[...St(St(Kt(0,B-2|0))(R=>St(Kt(R+1|0,B-1|0))(E=>[b(R,E)])))(R=>R._1>=0&&R._1<D.length?R._2>=0&&R._2<D.length?D[R._1].splitPartner.tag!=="Nothing"&&D[R._1].splitPartner.tag==="Just"&&D[R._1].splitPartner._1===D[R._2].id||D[R._2].splitPartner.tag!=="Nothing"&&D[R._2].splitPartner.tag==="Just"&&D[R._2].splitPartner._1===D[R._1].id?[]:i(d,D[R._1],D[R._2]):[]:[]),...St(D)(R=>R.splitBy.tag==="Just"&&R.splitPartner.tag==="Just"&&(()=>{const E=Xt(R.splitPartner._1)($);if(E.tag==="Nothing")return!1;if(E.tag==="Just")return!0;f()})()&&(()=>{const E=Xt(R.splitBy._1)($);if(E.tag==="Nothing")return!1;if(E.tag==="Just")return!0;f()})()?[{src:R.id,tgt:R.splitBy._1,weight:1,kind:Ss},{src:R.splitBy._1,tgt:R.splitPartner._1,weight:1,kind:Ss}]:[])]})()}})(),p=h.segments,m=p.length,y=G=>{let I=G,j=!0,O;for(;j;){const z=I,$=jt(q=>{const D=Xt(q)(z.inWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;f()})(z.remaining);if($.tag==="Nothing"){j=!1,O=z;continue}if($.tag==="Just"){const q=$._1;I={...z,inWeight:J(D=>B=>Ft(it)(Te)(B.tgt)(-B.weight)(D))(z.inWeight)((()=>{const D=Xt(q)(z.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;f()})()),marks:rt(it)(q)(z.nextSource)(z.marks),nextSource:z.nextSource+1|0,outWeight:J(D=>B=>Ft(it)(Te)(B.src)(-B.weight)(D))(z.outWeight)((()=>{const D=Xt(q)(z.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;f()})()),remaining:dt(D=>D!==q,z.remaining)};continue}f()}return O},x=G=>{let I=G,j=!0,O;for(;j;){const z=I,$=jt(q=>{const D=Xt(q)(z.outWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;f()})(z.remaining);if($.tag==="Nothing"){j=!1,O=z;continue}if($.tag==="Just"){const q=$._1;I={...z,inWeight:J(D=>B=>Ft(it)(Te)(B.tgt)(-B.weight)(D))(z.inWeight)((()=>{const D=Xt(q)(z.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;f()})()),marks:rt(it)(q)(z.nextSink)(z.marks),nextSink:z.nextSink-1|0,outWeight:J(D=>B=>Ft(it)(Te)(B.src)(-B.weight)(D))(z.outWeight)((()=>{const D=Xt(q)(z.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;f()})()),remaining:dt(D=>D!==q,z.remaining)};continue}f()}return O},N=(G=>{let I=G,j=!0,O;for(;j;){const z=y(x(I));if(z.remaining.length===0){j=!1,O=U($=>{const q=Xt($.id)(z.marks),D=(()=>{if(q.tag==="Nothing")return $.id;if(q.tag==="Just")return q._1;f()})();return{...$,mark:D<m?(D+m|0)+1|0:D}})(p);continue}I=(()=>{const $=D=>{const B=Xt(D)(z.outWeight),R=Xt(D)(z.inWeight);return(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;f()})()-(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;f()})()|0},q=Pt(D=>B=>it.compare($(B))($(D)))(z.remaining);if(0<q.length){const D=q[0];return{...z,inWeight:J(B=>R=>Ft(it)(Te)(R.tgt)(-R.weight)(B))(z.inWeight)((()=>{const B=Xt(D)(z.depsBySrc);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;f()})()),marks:rt(it)(D)(z.nextSource)(z.marks),nextSource:z.nextSource+1|0,outWeight:J(B=>R=>Ft(it)(Te)(R.src)(-R.weight)(B))(z.outWeight)((()=>{const B=Xt(D)(z.depsByTgt);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;f()})()),remaining:dt(B=>B!==D,z.remaining)}}return z})()}return O})({remaining:U(G=>G.id)(p),marks:F,inWeight:J(G=>I=>Ft(it)(Te)(I.tgt)(I.weight)(G))(F)(h.deps),outWeight:J(G=>I=>Ft(it)(Te)(I.src)(I.weight)(G))(F)(h.deps),depsBySrc:J(G=>I=>Ft(it)(xe)(I.src)([I])(G))(F)(h.deps),depsByTgt:J(G=>I=>Ft(it)(xe)(I.tgt)([I])(G))(F)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),T=(()=>{const G=(()=>{const O=hi(U(z=>b(z.id,z.mark))(N));return{segments:N,deps:vt(z=>(()=>{if(z.kind==="Critical")return!0;if(z.kind==="Regular")return!1;f()})()?v("Just",z):(()=>{const $=Xt(z.src)(O),q=Xt(z.tgt)(O);return(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;f()})()>(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;f()})()})()?z.weight===0?w:v("Just",{src:z.tgt,tgt:z.src,weight:z.weight,kind:z.kind}):v("Just",z))(h.deps)}})(),I=J(O=>z=>Ft(it)(Te)(z.tgt)(1)(O))(F)(G.deps),j=(O=>{let z=O,$=!0,q;for(;$;){const D=z,B=Rt(R=>w,R=>E=>v("Just",{head:R,tail:E}),D.queue);if(B.tag==="Nothing"){$=!1,q=D;continue}if(B.tag==="Just"){z=J((()=>{const R=Xt(B._1.head)(D.slots),E=(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;f()})();return Q=>Y=>{const H=Xt(Y)(Q.inDegree),K=(()=>{if(H.tag==="Nothing")return-1;if(H.tag==="Just")return H._1-1|0;f()})();return{...Q,slots:rt(it)(Y)(hd((()=>{const X=Xt(Y)(Q.slots);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;f()})())(E+1|0))(Q.slots),inDegree:rt(it)(Y)(K)(Q.inDegree),queue:K===0?[...Q.queue,Y]:Q.queue}}})())({...D,queue:B._1.tail})((()=>{const R=Xt(B._1.head)(D.adj);if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;f()})());continue}f()}return q})({slots:hi(U(O=>b(O.id,0))(G.segments)),inDegree:I,adj:J(O=>z=>Ft(it)(xe)(z.src)([z.tgt])(O))(F)(G.deps),queue:U(O=>O.id)(dt(O=>{const z=Xt(O.id)(I);if(z.tag==="Nothing")return!0;if(z.tag==="Just")return z._1===0;f()},G.segments))});return Pt(O=>z=>it.compare(O.slot)(z.slot))(U(O=>({...O,slot:(()=>{const z=Xt(O.id)(j.slots);if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;f()})()}))(G.segments))})(),C=1+J(G=>I=>hd(G)(I.slot))(0)(T)|0,L=St(T)(G=>G.members),S=dt(G=>nn(ir)(G.edge.id)(L),t),P=J(wt)(-1e18)(U(G=>G.fromPos._2)(S)),M=J(xt)(1e18)(U(G=>G.toPos._2)(S));if(P>M){const G=hi(U(I=>b(I.id,I))(T));return mn(U(I=>U(j=>b(j,{slot:I.slot,slotCount:C,gapTop:M,gapBottom:P,partner:(()=>{if(I.splitPartner.tag==="Just"){const O=Xt(I.splitPartner._1)(G);if(O.tag==="Just")return v("Just",{slot:O._1.slot,splitX:0<O._1.incoming.length?O._1.incoming[0]:0});if(O.tag==="Nothing")return w;f()}if(I.splitPartner.tag==="Nothing")return w;f()})()}))(I.members))(dt(I=>{if(I.splitPartner.tag==="Just"){const j=Xt(I.splitPartner._1)(G);return!(j.tag==="Just"&&(()=>{if(j._1.splitBy.tag==="Nothing")return!1;if(j._1.splitBy.tag==="Just")return!0;f()})())}if(I.splitPartner.tag==="Nothing")return!0;f()},T)))}const W=hi(U(G=>b(G.id,G))(T));return mn(U(G=>U(I=>b(I,{slot:G.slot,slotCount:C,gapTop:P,gapBottom:M,partner:(()=>{if(G.splitPartner.tag==="Just"){const j=Xt(G.splitPartner._1)(W);if(j.tag==="Just")return v("Just",{slot:j._1.slot,splitX:0<j._1.incoming.length?j._1.incoming[0]:0});if(j.tag==="Nothing")return w;f()}if(G.splitPartner.tag==="Nothing")return w;f()})()}))(G.members))(dt(G=>{if(G.splitPartner.tag==="Just"){const I=Xt(G.splitPartner._1)(W);return!(I.tag==="Just"&&(()=>{if(I._1.splitBy.tag==="Nothing")return!1;if(I._1.splitBy.tag==="Just")return!0;f()})())}if(G.splitPartner.tag==="Nothing")return!0;f()},T)))})()))(F)(Jv(J(a=>s=>{const u=pi(s.edge.from.node)(n);if(u.tag==="Just"){const c=pi(s.edge.to.node)(n);return c.tag==="Just"&&u._1.layer!==c._1.layer?Ft(it)(xe)(mi(u._1.layer)(c._1.layer))([s])(a):a}return a})(F)((()=>{const a=s=>b((()=>{const u=pi(s.edge.from.node)(n);return u.tag==="Just"?u._1.layer:1e6})(),(()=>{const u=pi(s.edge.from.node)(n);return u.tag==="Just"?u._1.order:1e6})());return Pt(s=>u=>Tv(a(s))(a(u)))(t)})())))},kv=t=>e=>{const n=md(t)(e),r=J(o=>i=>rt(A)(i.node)(i)(o))(F)(e);return J(o=>i=>{const a=pi(i.edge.from.node)(r);if(a.tag==="Just"){const s=pi(i.edge.to.node)(r);if(s.tag==="Just"&&a._1.layer!==s._1.layer){const u=Cv(i.edge.id)(n);if(u.tag==="Just")return rt(it)(mi(a._1.layer)(s._1.layer))(u._1.slotCount)(o)}return o}return o})(F)(t)},sg=ge(A)(Mt),Rr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},ug=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Lv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t._1)(i._3._1);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(t._2==="North"){if(i._3._2==="North"){r=!1,o=v("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=v("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=v("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=v("Just",i._4);continue}}f()}return o},yd=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);f()},cg=t=>e=>{const n=et(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};f()},xd=t=>e=>J(n=>r=>Ft(t)(xe)(e(r))([r])(n))(F),wd=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;f()})()&&(()=>{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;f()})(),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;f()})()&&(()=>{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;f()})();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},Nd=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,o=e.length;return o===0?F:sg(o===1?U(i=>b(i,r))(e):qt(i=>a=>b(a,t.lo+et(i+1|0)*n/et(o+1|0)))(e))},vd=t=>e=>n=>r=>o=>{const i=xd(A)(_=>_.to.node)(t),a=xd(A)(_=>_.from.node)(t),s=J(_=>h=>rt(A)(h.node)(h)(_))(F)(e),u=(_,h,p)=>{const m=Rr(_)(s);if(m.tag==="Nothing")return b(0,0);if(m.tag==="Just"){const y=Rr(_)(n);if(y.tag==="Nothing"){const x=et(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);f()}if(y.tag==="Just"){const x=jt(N=>N.id===h)(y._1);if(x.tag==="Nothing"){const N=et(4);if(p==="South")return b(m._1.position._1*N+m._1.size._1*N/2,(m._1.position._2+m._1.size._2)*N);if(p==="North")return b(m._1.position._1*N+m._1.size._1*N/2,m._1.position._2*N);if(p==="East")return b((m._1.position._1+m._1.size._1)*N,m._1.position._2*N+m._1.size._2*N/2);if(p==="West")return b(m._1.position._1*N,m._1.position._2*N+m._1.size._2*N/2);f()}if(x.tag==="Just"){const N=et(4);if(x._1.side==="North")return b(m._1.position._1*N+et(x._1.offset)*N,m._1.position._2*N);if(x._1.side==="South")return b(m._1.position._1*N+et(x._1.offset)*N,(m._1.position._2+m._1.size._2)*N);if(x._1.side==="East")return b((m._1.position._1+m._1.size._1)*N,m._1.position._2*N+et(x._1.offset)*N);if(x._1.side==="West")return b(m._1.position._1*N,m._1.position._2*N+et(x._1.offset)*N)}}}f()},c=sg(St(r)(_=>{if(_.nodes.length<=2)return[];const h=et(4);if(1<_.nodes.length){const p=Rr(_.nodes[1])(s);if(p.tag==="Nothing")return[];if(p.tag==="Just"){const m=p._1.position._1*h+p._1.size._1*h/2;return U(y=>b(y,m))(We(y=>x=>_.edgeId+":"+y+"->"+x,_.nodes,It(1,_.nodes.length,_.nodes)))}f()}return[]})),g=_=>{const h=Rr(_.from.node)(s),p=Rr(_.to.node)(s);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,y=p._1,x=Pt(N=>T=>it.compare(N.score)(T.score))(U(N=>{const T=N._1,C=N._2;return{from:T,to:C,score:(()=>{const L=(W,G,I,j,O)=>{const z=cg(W)(G),$=cg(W)(I);return z.lo<$.hi&&$.lo<z.hi&&(T==="South"?C==="North"&&O._2>j._2:T==="North"?C==="South"&&O._2<j._2:T==="East"?C==="West"&&O._1>j._1:T==="West"&&C==="East"&&O._1<j._1)?0:wd(T)(C)(j)(O)},S=yd(T)(m),P=yd(C)(y),M=wd(T)(C)(S)(P);return(()=>{if(M>0){if(T==="South")return C==="North"?L(Ie,m,y,S,P)*10|0:M*10|0;if(T==="North")return C==="South"?L(Ge,m,y,S,P)*10|0:M*10|0;if(T==="East")return C==="West"?L(Pr,m,y,S,P)*10|0:M*10|0;if(T==="West"&&C==="East")return L(Ar,m,y,S,P)*10|0}return M*10|0})()+(T==="South"?C==="North"?y.layer>=m.layer?0:20:15:T==="North"?C==="South"?y.layer<=m.layer?0:20:15:T==="East"?C==="West"?5:15:T==="West"&&C==="East"?5:15)|0})()}})([b(Ie,Ge),b(Pr,Ge),b(Ar,Ge),b(Ie,Pr),b(Ie,Ar),b(Ge,Ie),b(Ge,Pr),b(Ge,Ar),b(Pr,Ie),b(Ar,Ie),b(Pr,Ar),b(Ar,Pr)]));if(0<x.length)return{from:x[0].from,to:x[0].to}}return{from:Ie,to:Ge}},d=sg(U(_=>b(_.id,g(_)))(t)),l=(_,h,p,m,y,x)=>{const N=et(4),T=Rr(h)(s);if(T.tag==="Nothing")return b(0,0);if(T.tag==="Just"){const C=Lv(b(p,_))(o);if(C.tag==="Just"){const L=T._1.position._1*N+C._1,S=et(4);if(_==="South")return b(L,(T._1.position._2+T._1.size._2)*S);if(_==="North")return b(L,T._1.position._2*S);if(_==="East")return b((T._1.position._1+T._1.size._1)*S,L);if(_==="West")return b(T._1.position._1*S,L);f()}if(C.tag==="Nothing"){const L=cg(_)(T._1),S=(L.lo+L.hi)/2,P=ug(p)(Nd(L)(U(G=>G.id)(Pt(G=>I=>ot.compare(y(_)(G))(y(_)(I)))(dt(G=>{const I=ug(G.id)(d);if(I.tag==="Just"){const j=x(I._1);return j==="North"?_==="North":j==="South"?_==="South":j==="East"?_==="East":j==="West"&&_==="West"}if(I.tag==="Nothing")return!0;f()},(()=>{const G=Rr(h)(m);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;f()})()))))),M=(()=>{if(P.tag==="Nothing")return S;if(P.tag==="Just")return P._1;f()})(),W=et(4);if(_==="South")return b(M,(T._1.position._2+T._1.size._2)*W);if(_==="North")return b(M,T._1.position._2*W);if(_==="East")return b((T._1.position._1+T._1.size._1)*W,M);if(_==="West")return b(T._1.position._1*W,M)}}f()};return U(_=>{const h=ug(_.edge.id)(c);if(h.tag==="Nothing")return _;if(h.tag==="Just")return{..._,fromPos:ze(3)(_.edge.from.node)==="$d:"?b(h._1,_.fromPos._2):_.fromPos,toPos:ze(3)(_.edge.to.node)==="$d:"?b(h._1,_.toPos._2):_.toPos};f()})(U(_=>{if(_.from.port.tag==="Just"&&_.to.port.tag==="Just")return{edge:_,fromPos:u(_.from.node,_.from.port._1,Ie),toPos:u(_.to.node,_.to.port._1,Ge),fromSide:Ie,toSide:Ge};const h=g(_);return{edge:_,fromPos:l(h.from,_.from.node,_.id,a,p=>m=>{const y=Rr(m.to.node)(s);if(y.tag==="Nothing")return 0;if(y.tag==="Just"){const x=et(4);if(p==="South"||p==="North")return y._1.position._1*x+y._1.size._1*x/2;if(p==="East"||p==="West")return y._1.position._2*x+y._1.size._2*x/2}f()},p=>p.from),toPos:l(h.to,_.to.node,_.id,i,p=>m=>{const y=Rr(m.from.node)(s);if(y.tag==="Nothing")return 0;if(y.tag==="Just"){const x=et(4);if(p==="South"||p==="North")return y._1.position._1*x+y._1.size._1*x/2;if(p==="East"||p==="West")return y._1.position._2*x+y._1.size._2*x/2}f()},p=>p.to),fromSide:h.from,toSide:h.to}})(t))},Es=(()=>{const t={eq:e=>n=>e._1===n._1&&(e._2==="North"?n._2==="North":e._2==="South"?n._2==="South":e._2==="East"?n._2==="East":e._2==="West"&&n._2==="West")};return{compare:e=>n=>{const r=A.compare(e._1)(n._1);if(r==="LT")return Fe;if(r==="GT")return Me;if(e._2==="North")return n._2==="North"?Ze:Fe;if(n._2==="North")return Me;if(e._2==="South")return n._2==="South"?Ze:Fe;if(n._2==="South")return Me;if(e._2==="East")return n._2==="East"?Ze:Fe;if(n._2==="East")return Me;if(e._2==="West"&&n._2==="West")return Ze;f()},Eq0:()=>t}})(),Sv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=Es.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Ev=ge(A)(Mt),gg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Pv=ge(Es)(Mt),Td=(()=>{const t=fn.unfoldr(Xn);return e=>t(_n("IterNode",e,Un))})(),yi=t=>e=>n=>r=>{const o=Sv(b(e,n))(t);if(o.tag==="Nothing")return r;if(o.tag==="Just")return o._1;f()},Jd=t=>e=>n=>{const r=Ev(mn(U(a=>qt(s=>u=>b(u,s))(a))(t))),o=(a,s)=>{if(a==="South"){const u=gg(s.to.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;f()}if(a==="North"){const u=gg(s.from.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;f()}return 0},i=a=>J(s=>u=>Oe(Es.compare,Qe,Pv(U(c=>b(b(c._1,a),c._2))(Td(Nd({lo:0,hi:(()=>{const c=gg(u._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return ze(3)(u._1)==="$d:"?0:1;f()})()})(U(c=>c.id)(Pt(c=>g=>it.compare(o(a,c))(o(a,g)))(u._2)))))),s))(F)(Td(J(s=>u=>u.from.node===u.to.node?s:a==="South"?Ft(A)(xe)(u.from.node)([u])(s):a==="North"?Ft(A)(xe)(u.to.node)([u])(s):s)(F)(e)));return Oe(Es.compare,Qe,i(Ge),i(Ie))},bd=t=>t,Cd=t=>t,kd=t=>t,Av=J(t=>e=>rt(A)(e)()(t))(F),Gv=(()=>{const t=fn.unfoldr(e=>{if(e.tag==="Nil")return w;if(e.tag==="Cons")return v("Just",b(e._1,e._2));f()});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)));f()};return n(e,V)})())})(),_t=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},An=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},hr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},pr=ge(A)(Mt),fg=l_(A),_g=(()=>{const t=fn.unfoldr(Xn);return e=>t(_n("IterNode",e,Un))})(),Iv=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Dv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=it.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Ld=kd("VDown"),Sd=kd("VUp"),Rv=Cd("ForwardPhase"),Bv=Cd("StackPhase"),Ed=bd("HRight"),Pd=bd("HLeft"),Ad=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},Fv=t=>e=>n=>{const r=J(a=>s=>Ft(A)(Te)(s.tgt)(1)(a))(F)(t),o=Gv(Av([...U(a=>a.src)(t),...U(a=>a.tgt)(t),...(()=>{const a=(s,u)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return a(s._5,kt("Cons",s._4,a(s._6,u)));f()};return Zt(ye.foldr,a(e,V))})()])),i=J(a=>s=>Ft(A)(xe)(s.src)([{target:s.tgt,sep:s.sep}])(a))(F)(t);return(a=>s=>u=>{let c=a,g=s,d=u,l=!0,_;for(;l;){const h=c,p=g,m=d,y=Rt(x=>w,x=>N=>v("Just",{head:x,tail:N}),h);if(y.tag==="Nothing"){l=!1,_=m;continue}if(y.tag==="Just"){const x=_t(y._1.head)(m),N=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;f()})(),T=J(C=>L=>{const S=_t(L.target)(C.result),P=N+L.sep,M=_t(L.target)(C.indeg),W=(()=>{if(M.tag==="Nothing")return-1;if(M.tag==="Just")return M._1-1|0;f()})();return{newQueue:W===0?[...C.newQueue,L.target]:C.newQueue,result:rt(A)(L.target)((()=>{if(S.tag==="Nothing")return P;if(S.tag==="Just"){if(n==="VDown")return An(S._1)(P);if(n==="VUp")return hr(S._1)(P)}f()})())(C.result),indeg:rt(A)(L.target)(W)(C.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const C=_t(y._1.head)(i);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;f()})());c=[...y._1.tail,...T.newQueue],g=T.indeg,d=T.result;continue}f()}return _})(dt(a=>{const s=_t(a)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;f()},o))(r)(J(a=>s=>rt(A)(s)(0)(a))(F)(o))},Mv=t=>{const e=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return e(i._5,kt("Cons",i._4,e(i._6,a)));f()},n=Zt(ye.foldr,e(t,V)),r=J(An)(999999)(n);if(r===0||n.length===0)return t;const o=i=>{if(i.tag==="Leaf")return F;if(i.tag==="Node")return oe("Node",i._1,i._2,i._3,i._4-r,o(i._5),o(i._6));f()};return o(t)},Gd=t=>{const e=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return e(i._5,kt("Cons",i._4,e(i._6,a)));f()},n=e(t,V),r=i=>a=>{let s=i,u=a,c=!0,g;for(;c;){const d=s,l=u;if(l.tag==="Nil"){c=!1,g=d;continue}if(l.tag==="Cons"){s=hr(d)(l._1),u=l._2;continue}f()}return g},o=i=>a=>{let s=i,u=a,c=!0,g;for(;c;){const d=s,l=u;if(l.tag==="Nil"){c=!1,g=d;continue}if(l.tag==="Cons"){s=An(d)(l._1),u=l._2;continue}f()}return g};return r(-999999)(n)-o(999999)(n)},Zi=t=>e=>(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=i;if(u===e){a=!1,s=c;continue}o=(()=>{const g=_t(u)(t.align);if(g.tag==="Nothing")return e;if(g.tag==="Just")return g._1;f()})(),i=[...c,u]}return s})((()=>{const n=_t(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;f()})())([e]),zv=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>g=>{const d=(D,B,R)=>{const E=D.from.node===B?D.from.port:D.to.node===B?D.to.port:w;if(E.tag==="Just"){const Q=_t(B)(o);if(Q.tag==="Just"){const Y=jt(H=>H.id===E._1)(Q._1);if(Y.tag==="Just"){const H=et(Y._1.offset)*et(4);return R==="North"||R==="South"?H:0}if(Y.tag==="Nothing"){const H=_t(B)(r),K=yi(a)(D.id)(R)((()=>{if(H.tag==="Nothing")return .5;if(H.tag==="Just")return H._1._1/2;f()})());return R==="North"||R==="South"?K:0}f()}if(Q.tag==="Nothing"){const Y=_t(B)(r),H=yi(a)(D.id)(R)((()=>{if(Y.tag==="Nothing")return .5;if(Y.tag==="Just")return Y._1._1/2;f()})());return R==="North"||R==="South"?H:0}f()}if(E.tag==="Nothing"){const Q=_t(B)(r),Y=yi(a)(D.id)(R)((()=>{if(Q.tag==="Nothing")return .5;if(Q.tag==="Just")return Q._1._1/2;f()})());return R==="North"||R==="South"?Y:0}f()},l=(D,B)=>{if(D.from.node===B){if(g==="HRight")return Ie;if(g==="HLeft")return Ge;f()}if(g==="HRight")return Ge;if(g==="HLeft")return Ie;f()},_=(D,B,R)=>J(E=>Q=>rt(A)(Q)((()=>{const Y=_t(Q)(E);if(Y.tag==="Nothing")return 0+B;if(Y.tag==="Just")return Y._1+B;f()})())(E))(R)(Zi(u)(D)),h=(()=>{if(g==="HRight")return n;if(g==="HLeft")return ce(n);f()})(),p=D=>{const B=_t(D)(r);if(B.tag==="Nothing")return 1;if(B.tag==="Just")return B._1._1;f()},m=pr(mn(qt(D=>B=>U(R=>b(R,D))(B))(n))),y=(D,B)=>ze(3)(D)==="$d:"&&ze(3)(B)==="$d:"||ze(3)(D)==="$d:"||ze(3)(B)==="$d:"?10:et(t.nodeGap),x=J(D=>B=>fg(R=>v("Just",[...(()=>{if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;f()})(),B]))(B.to.node)(D))(F)(i),N=J(D=>B=>fg(R=>v("Just",[...(()=>{if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;f()})(),B]))(B.from.node)(D))(F)(i),T=mn(n),C=J(D=>B=>{const R=_t(B)(u.root),E=(()=>{if(R.tag==="Nothing")return B;if(R.tag==="Just")return R._1;f()})();return B===E?D:fg(Q=>v("Just",(()=>{if(Q.tag==="Nothing")return!0;if(Q.tag==="Just")return Q._1;f()})()&&ze(3)(B)==="$d:"))(E)(D)})(pr(U(D=>b(D,!0))(ti(A.compare)((()=>{const D=(B,R)=>{if(B.tag==="Leaf")return R;if(B.tag==="Node")return D(B._5,kt("Cons",B._4,D(B._6,R)));f()};return Zt(ye.foldr,D(u.root,V))})()))))(T),L=(D,B)=>{const R=D.free,E=_t(R)(u.root),Q=(()=>{if(E.tag==="Nothing")return R;if(E.tag==="Just")return E._1;f()})(),Y=_t(Q)(C),H=(()=>{if(Y.tag==="Nothing")return!0;if(Y.tag==="Just")return Y._1;f()})();return J(K=>X=>{if(K.edge.tag==="Just")return K;if(K.edge.tag==="Nothing"){if((()=>{const lt=_t(Q)(B.su);return!H&&(()=>{const Tt=_t(X.from.node)(m);return X.from.node!==X.to.node&&(()=>{const Et=_t(X.to.node)(m);return(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._1;f()})()===(()=>{if(Et.tag==="Nothing")return-1;if(Et.tag==="Just")return Et._1;f()})()})()})()||(()=>{if(lt.tag==="Nothing")return!1;if(lt.tag==="Just")return lt._1;f()})()})())return K;const Z=X.from.node===R?X.to.node:X.from.node,nt=_t(Z)(u.root),gt=(()=>{if(nt.tag==="Nothing")return Z;if(nt.tag==="Just")return nt._1;f()})(),bt=gt!==Q;return bt&&(()=>{const lt=_t(gt)(B.blockFinished);if(lt.tag==="Nothing")return!1;if(lt.tag==="Just")return lt._1;f()})()?{...K,edge:v("Just",X),hasEdges:!0}:{...K,hasEdges:K.hasEdges||bt}}f()})({edge:w,hasEdges:!1})((()=>{if(D.isRoot){if(g==="HRight"){const K=_t(R)(x);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;f()}if(g==="HLeft"){const K=_t(R)(N);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1}f()}if(g==="HRight"){const K=_t(R)(N);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;f()}if(g==="HLeft"){const K=_t(R)(x);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1}f()})())},S=(D,B,R,E)=>{const Q=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;f()})(),Y={free:B,isRoot:R},H=L(Y,E);if(H.edge.tag==="Nothing")return H.hasEdges?{thresh:Q,state:{...E,queue:[...E.queue,Y]}}:{thresh:Q,state:E};if(H.edge.tag==="Just"){const K=H.edge._1.from.node===B?H.edge._1.to.node:H.edge._1.from.node;return{thresh:(()=>{const X=_t((()=>{const bt=_t(K)(u.root);if(bt.tag==="Nothing")return K;if(bt.tag==="Just")return bt._1;f()})())(E.x),Z=_t(K)(s),nt=_t(B)(s),gt=(()=>{if(X.tag==="Just")return X._1;if(X.tag==="Nothing")return w;f()})();return(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;f()})()+(()=>{if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;f()})()+d(H.edge._1,K,(()=>{if(R){if(g==="HRight")return Ie;if(g==="HLeft")return Ge;f()}if(g==="HRight")return Ge;if(g==="HLeft")return Ie;f()})())-(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;f()})()-d(H.edge._1,B,(()=>{if(R){if(g==="HRight")return Ge;if(g==="HLeft")return Ie;f()}if(g==="HRight")return Ie;if(g==="HLeft")return Ge;f()})())})(),state:{...E,su:rt(A)((()=>{const X=_t(H.edge._1.from.node)(u.root);if(X.tag==="Nothing")return H.edge._1.from.node;if(X.tag==="Just")return X._1;f()})())(!0)(rt(A)((()=>{const X=_t(H.edge._1.to.node)(u.root);if(X.tag==="Nothing")return H.edge._1.to.node;if(X.tag==="Just")return X._1;f()})())(!0)(E.su))}}}f()},P=(D,B,R,E)=>{const Q=B===D,Y=_t(B)(u.align),H=(()=>{if(Y.tag==="Nothing")return B===D;if(Y.tag==="Just")return Y._1===D;f()})();if(!(Q||H))return{thresh:R,state:E};const K=(()=>{if(c==="VDown")return Q&&R<=-1e18;if(c==="VUp")return Q&&R>=1e18;f()})()?S(D,B,!0,E):{thresh:R,state:E};return(()=>{if(c==="VDown")return K.thresh<=-1e18&&H;if(c==="VUp")return K.thresh>=1e18&&H;f()})()?S(D,B,!1,K.state):K},M=D=>B=>R=>{const E=_t(R)(e.nodeIndex),Q=(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;f()})(),Y=jt(nt=>nn(ir)(R)(nt))(h),H=(()=>{if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1;f()})(),K=H.length;if((()=>{if(c==="VDown")return Q<=0;if(c==="VUp")return Q>=(K-1|0);f()})()){const nt=P(D,R,B.thresh,B.st);return{...B,st:nt.state,thresh:nt.thresh}}const X=(()=>{if(c==="VDown")return Q-1|0;if(c==="VUp")return Q+1|0;f()})(),Z=X>=0&&X<H.length?v("Just",H[X]):w;if(Z.tag==="Nothing")return B;if(Z.tag==="Just"){const nt=_t(Z._1)(u.root),gt=(()=>{if(nt.tag==="Nothing")return Z._1;if(nt.tag==="Just")return nt._1;f()})(),bt=P(D,R,B.thresh,W(gt)(B.st)),lt=(()=>{const Qt=_t(D)(bt.state.sink);if(Qt.tag==="Nothing")return D===D;if(Qt.tag==="Just")return Qt._1===D;f()})()?{...bt.state,sink:rt(A)(D)((()=>{const Qt=_t(gt)(bt.state.sink);if(Qt.tag==="Nothing")return gt;if(Qt.tag==="Just")return Qt._1;f()})())(bt.state.sink)}:bt.state,Tt=_t(gt)(lt.sink),Et=(()=>{if(Tt.tag==="Nothing")return gt;if(Tt.tag==="Just")return Tt._1;f()})(),te=_t(D)(lt.sink),Jt=(()=>{if(te.tag==="Nothing")return D;if(te.tag==="Just")return te._1;f()})();if(Jt===Et){const Qt=_t(gt)(lt.x),ee=(()=>{if(Qt.tag==="Just")return Qt._1;if(Qt.tag==="Nothing")return w;f()})(),ae=(()=>{if(ee.tag==="Nothing")return 0;if(ee.tag==="Just")return ee._1;f()})(),ne=_t(D)(lt.x),Ut=(()=>{if(ne.tag==="Just")return ne._1;if(ne.tag==="Nothing")return w;f()})(),Wt=(()=>{if(Ut.tag==="Nothing")return 0;if(Ut.tag==="Just")return Ut._1;f()})(),gn=y(R,Z._1),pn=_t(Z._1)(s),He=_t(R)(s),kn=(()=>{if(pn.tag==="Nothing")return 0;if(pn.tag==="Just")return pn._1;f()})()-(()=>{if(He.tag==="Nothing")return 0;if(He.tag==="Just")return He._1;f()})();if(c==="VDown"){const Be=hr(ae+kn+p(Z._1)+gn)(bt.thresh);return{st:{...lt,x:rt(A)(D)(v("Just",B.initial?Be:hr(Wt)(Be)))(lt.x)},initial:!1,thresh:bt.thresh}}if(c==="VUp"){const Be=An(ae+kn-gn-p(R))(bt.thresh);return{st:{...lt,x:rt(A)(D)(v("Just",B.initial?Be:An(Wt)(Be)))(lt.x)},initial:!1,thresh:bt.thresh}}f()}const Yt=_t(gt)(lt.x),Dt=(()=>{if(Yt.tag==="Just")return Yt._1;if(Yt.tag==="Nothing")return w;f()})(),yt=(()=>{if(Dt.tag==="Nothing")return 0;if(Dt.tag==="Just")return Dt._1;f()})(),ht=_t(D)(lt.x),ft=(()=>{if(ht.tag==="Just")return ht._1;if(ht.tag==="Nothing")return w;f()})(),pt=(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;f()})(),At=et(t.nodeGap),Gt=_t(R)(s),Nt=_t(Z._1)(s),Lt=(()=>{if(Gt.tag==="Nothing")return 0;if(Gt.tag==="Just")return Gt._1;f()})()-(()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1;f()})();return{st:{...lt,classEdges:[...lt.classEdges,{src:Jt,tgt:Et,sep:(()=>{if(c==="VDown")return pt+Lt-yt-p(Z._1)-At;if(c==="VUp")return pt+Lt+p(R)+At-yt;f()})()}]},initial:B.initial,thresh:bt.thresh}}f()},W=D=>B=>{const R=_t(D)(B.x),E=(()=>{if(R.tag==="Just")return R._1;if(R.tag==="Nothing")return w;f()})();if(E.tag==="Just")return B;if(E.tag==="Nothing"){const Q=J(M(D))({st:{...B,x:rt(A)(D)(v("Just",0))(B.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;f()})()})(Zi(u)(D));return{...Q.st,blockFinished:rt(A)(D)(!0)(Q.st.blockFinished)}}f()},G=J(D=>B=>J(R=>E=>{const Q=_t(E)(u.root),Y=(()=>{if(Q.tag==="Nothing")return E;if(Q.tag==="Just")return Q._1;f()})();return Y===E?W(Y)(R):R})(D)((()=>{if(c==="VDown")return B;if(c==="VUp")return ce(B);f()})()))({x:pr(U(D=>b(D,w))(T)),sink:pr(U(D=>b(D,D))(T)),classEdges:[],su:F,blockFinished:F,queue:[]})(h),I=Fv(G.classEdges)(G.sink)(c),j=(D,B,R,E)=>{const Q=_t(B)(E),Y=_t(B)(s);return(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;f()})()+(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;f()})()+d(D,B,R)},O=pr(U(D=>b(D,!0))(ti(A.compare)((()=>{const D=(B,R)=>{if(B.tag==="Leaf")return R;if(B.tag==="Node")return D(B._5,kt("Cons",B._4,D(B._6,R)));f()};return Zt(ye.foldr,D(u.root,V))})()))),z=D=>B=>R=>{const E=L(R,{su:B.su,blockFinished:O}),Q={phase:D,ppFree:R.free,ppIsRoot:R.isRoot,edgeId:w,delta:0,avail:0,shift:0,freeSu:(()=>{const Y=_t((()=>{const H=_t(R.free)(u.root);if(H.tag==="Nothing")return R.free;if(H.tag==="Just")return H._1;f()})())(B.su);if(Y.tag==="Nothing")return!1;if(Y.tag==="Just")return Y._1;f()})(),hasEdges:E.hasEdges,candCount:(()=>{if(R.isRoot){if(g==="HRight"){const Y=_t(R.free)(x);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length;f()}if(g==="HLeft"){const Y=_t(R.free)(N);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length}f()}if(g==="HRight"){const Y=_t(R.free)(N);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length;f()}if(g==="HLeft"){const Y=_t(R.free)(x);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length}f()})()};if(E.edge.tag==="Nothing")return{...B,stack:[...B.stack,R],trace:[...B.trace,Q],x:B.x};if(E.edge.tag==="Just"){const Y=E.edge._1.from.node===R.free?b(E.edge._1.from.node,E.edge._1.to.node):b(E.edge._1.to.node,E.edge._1.from.node),H=j(E.edge._1,Y._1,l(E.edge._1,Y._1),B.x)-j(E.edge._1,Y._2,l(E.edge._1,Y._2),B.x),K=_t(Y._1)(u.root),X=(()=>{if(K.tag==="Nothing")return Y._1;if(K.tag==="Just")return K._1;f()})(),Z={...Q,edgeId:v("Just",E.edge._1.id),delta:H};if(H>0&&H<1e300){const nt=J(lt=>Tt=>{const Et=_t(Tt)(m),te=(()=>{if(Et.tag==="Nothing")return-1;if(Et.tag==="Just")return Et._1;f()})();if(te>=0&&te<n.length){const Dt=n[te],yt=_t(Tt)(e.nodeIndex),ht=(()=>{if(yt.tag==="Nothing")return-2;if(yt.tag==="Just")return yt._1-1|0;f()})();return ht>=0&&ht<Dt.length?An(lt)((()=>{const ft=_t(Tt)(B.x),pt=_t(Tt)(s),At=_t(Dt[ht])(B.x),Gt=_t(Dt[ht])(s);return(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;f()})()+(()=>{if(pt.tag==="Nothing")return 0;if(pt.tag==="Just")return pt._1;f()})()-((()=>{if(At.tag==="Nothing")return 0;if(At.tag==="Just")return At._1;f()})()+(()=>{if(Gt.tag==="Nothing")return 0;if(Gt.tag==="Just")return Gt._1;f()})()+p(Dt[ht])+y(Tt,Dt[ht]))})()):lt}const Jt=_t(Tt)(e.nodeIndex),Yt=(()=>{if(Jt.tag==="Nothing")return-2;if(Jt.tag==="Just")return Jt._1-1|0;f()})();return Yt>=0&&Yt<0?An(lt)((()=>{const Dt=_t(Tt)(B.x),yt=_t(Tt)(s),ht=_t([][Yt])(B.x),ft=_t([][Yt])(s);return(()=>{if(Dt.tag==="Nothing")return 0;if(Dt.tag==="Just")return Dt._1;f()})()+(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;f()})()-((()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;f()})()+(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;f()})()+p([][Yt])+y(Tt,[][Yt]))})()):lt})(H)(Zi(u)(X)),gt=nt>0?-nt:0,bt={...B,x:nt>0?_(X,gt,B.x):B.x,trace:[...B.trace,{...Z,avail:nt,shift:gt}]};return nt>0?bt:{...bt,stack:[...bt.stack,R]}}if(H<0&&-H<1e300){const nt=J(lt=>Tt=>{const Et=_t(Tt)(m),te=(()=>{if(Et.tag==="Nothing")return-1;if(Et.tag==="Just")return Et._1;f()})();if(te>=0&&te<n.length){const Dt=n[te],yt=_t(Tt)(e.nodeIndex),ht=(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1+1|0;f()})();return ht>=0&&ht<Dt.length?An(lt)((()=>{const ft=_t(Dt[ht])(B.x),pt=_t(Dt[ht])(s),At=_t(Tt)(B.x),Gt=_t(Tt)(s);return(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;f()})()+(()=>{if(pt.tag==="Nothing")return 0;if(pt.tag==="Just")return pt._1;f()})()-((()=>{if(At.tag==="Nothing")return 0;if(At.tag==="Just")return At._1;f()})()+(()=>{if(Gt.tag==="Nothing")return 0;if(Gt.tag==="Just")return Gt._1;f()})()+p(Tt)+y(Tt,Dt[ht]))})()):lt}const Jt=_t(Tt)(e.nodeIndex),Yt=(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1+1|0;f()})();return Yt>=0&&Yt<0?An(lt)((()=>{const Dt=_t([][Yt])(B.x),yt=_t([][Yt])(s),ht=_t(Tt)(B.x),ft=_t(Tt)(s);return(()=>{if(Dt.tag==="Nothing")return 0;if(Dt.tag==="Just")return Dt._1;f()})()+(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;f()})()-((()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;f()})()+(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;f()})()+p(Tt)+y(Tt,[][Yt]))})()):lt})(-H)(Zi(u)(X)),gt=nt>0?nt:0,bt={...B,x:nt>0?_(X,gt,B.x):B.x,trace:[...B.trace,{...Z,avail:nt,shift:gt}]};return nt>0?bt:{...bt,stack:[...bt.stack,R]}}return{...B,stack:[...B.stack,R],trace:[...B.trace,Z],x:B.x}}f()},$=J(z(Rv))({x:pr(U(D=>b(D,(()=>{const B=_t(D)(u.root),R=(()=>{if(B.tag==="Nothing")return D;if(B.tag==="Just")return B._1;f()})(),E=_t(R)(G.x),Q=_t((()=>{const H=_t(R)(G.sink);if(H.tag==="Nothing")return R;if(H.tag==="Just")return H._1;f()})())(I),Y=(()=>{if(E.tag==="Just")return E._1;if(E.tag==="Nothing")return w;f()})();return(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;f()})()+(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;f()})()})()))(T)),su:G.su,stack:[],trace:[]})(G.queue),q=J(z(Bv))({...$,stack:[]})(ce($.stack));return{x:q.x,queue:G.queue,trace:q.trace}},Qv=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>g=>zv(t)(e)(n)(r)(o)(i)(a)(s)(u)(c)(g).x,Wv=t=>e=>n=>r=>o=>i=>{const a=(u,c,g)=>{const d=_t(c)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;f()})(),_=u.from.node===c?u.from.port:u.to.node===c?u.to.port:w;if(_.tag==="Just"){const h=_t(c)(e);if(h.tag==="Just"){const p=jt(m=>m.id===_._1)(h._1);if(p.tag==="Just"){const m=et(p._1.offset)*et(4);return g==="North"||g==="South"?m:0}if(p.tag==="Nothing"){const m=yi(o)(u.id)(g)(l);return g==="North"||g==="South"?m:0}f()}if(h.tag==="Nothing"){const p=yi(o)(u.id)(g)(l);return g==="North"||g==="South"?p:0}f()}if(_.tag==="Nothing"){const h=yi(o)(u.id)(g)(l);return g==="North"||g==="South"?h:0}f()},s=u=>c=>g=>d=>{let l=u,_=c,h=g,p=d,m=!0,y;for(;m;){const x=l,N=_,T=h,C=Rt(L=>w,L=>S=>v("Just",{head:L,tail:S}),p);if(C.tag==="Nothing"){m=!1,y=x;continue}if(C.tag==="Just"){const L=C._1.head,S=jt(M=>M.from.node===T&&M.to.node===L||M.from.node===L&&M.to.node===T)(r),P=(()=>{if(S.tag==="Nothing")return N+0;if(S.tag==="Just")return N+(a(S._1,T,S._1.from.node===T?Ie:Ge)-a(S._1,L,S._1.from.node===L?Ie:Ge));f()})();l=rt(A)(L)(P)(x),_=P,h=L,p=C._1.tail;continue}f()}return y};return J(u=>c=>{const g=Rt(_=>w,_=>h=>v("Just",{head:_,tail:h}),Zi(t)(c)),d=(()=>{if(g.tag==="Nothing")return rt(A)(c)(0)(F);if(g.tag==="Just")return s(rt(A)(g._1.head)(0)(F))(0)(g._1.head)(g._1.tail);f()})(),l=J(_=>h=>hr(_)(-h._2))(0)(_g(d));return J(_=>h=>rt(A)(h._1)(h._2+l)(_))(u)(_g(d))})(F)(ti(A.compare)((()=>{const u=(c,g)=>{if(c.tag==="Leaf")return g;if(c.tag==="Node")return u(c._5,kt("Cons",c._4,u(c._6,g)));f()};return Zt(ye.foldr,u(t.root,V))})()))},Ov=t=>e=>{const n=(o,i,a)=>ze(3)(i)==="$d:"&&u_(dd,(()=>{const s=_t(i)(t.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;f()})()),r=o=>i=>a=>s=>u=>c=>g=>{let d=o,l=i,_=s,h=c,p=g,m=!0,y;for(;m;){const x=d,N=l,T=_,C=h,L=p,S=N.length;if(L>=S){m=!1,y=x;continue}const P=L>=0&&L<N.length?v("Just",N[L]):w,M=(()=>{if(P.tag==="Nothing")return"";if(P.tag==="Just")return P._1;f()})(),W=n(t,M);if(L===(S-1|0)||W){const G=(()=>{if(W){const I=_t(M)(t.preds),j=(()=>{if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;f()})();if(0<j.length){const O=T-1|0,z=_t(j[0])(t.nodeIndex);if(z.tag==="Nothing")return O;if(z.tag==="Just")return z._1;f()}}return T-1|0})();d=J(I=>j=>{if(j>=0&&j<N.length){const O=N[j];return n(t,O)?I:J(z=>$=>{const q=_t($)(t.nodeIndex),D=(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;f()})();return D<C||D>G?rt(A)($+"\u2192"+O)()(z):z})(I)((()=>{const z=_t(O)(t.preds);if(z.tag==="Nothing")return[];if(z.tag==="Just")return z._1;f()})())}return n(t,"")?I:J(O=>z=>{const $=_t(z)(t.nodeIndex),q=(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;f()})();return q<C||q>G?rt(A)(z+"\u2192")()(O):O})(I)((()=>{const O=_t("")(t.preds);if(O.tag==="Nothing")return[];if(O.tag==="Just")return O._1;f()})())})(x)(Kt(0,L)),l=N,_=T,h=G,p=L+1|0;continue}d=x,l=N,_=T,h=C,p=L+1|0}return y};return e.length<3?F:J(o=>i=>{if(i>=0&&i<e.length){const a=e[i];return r(o)((()=>{const s=i+1|0;return s>=0&&s<e.length?e[s]:[]})())(a)(a.length)(i)(0)(0)}return r(o)((()=>{const a=i+1|0;return a>=0&&a<e.length?e[a]:[]})())([])(0)(i)(0)(0)})(F)(Kt(1,e.length-2|0))},qv=t=>e=>n=>r=>o=>{const i=mn(e),a=J(s=>u=>{const c=J(g=>d=>{const l=(()=>{if(o==="HRight"){const m=_t(d)(t.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;f()}if(o==="HLeft"){const m=_t(d)(t.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}f()})(),_=l.length;if(_===0)return g;const h=kr(_-1|0,2),p=kr(_,2);return J(m=>y=>{if((()=>{const x=_t(d)(m.align);if(x.tag==="Nothing")return d!==d;if(x.tag==="Just")return x._1!==d;f()})())return m;if(y>=0&&y<l.length){const x=_t(l[y])(t.nodeIndex),N=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;f()})();if(!(Ad(l[y]+"\u2192"+d)(n)||Ad(d+"\u2192"+l[y])(n))&&(()=>{if(r==="VDown")return m.r<N;if(r==="VUp")return m.r>N;f()})()){const T=_t(l[y])(m.root),C=(()=>{if(T.tag==="Nothing")return l[y];if(T.tag==="Just")return T._1;f()})();return{root:rt(A)(d)(C)(m.root),align:rt(A)(l[y])(d)(rt(A)(d)(C)(m.align)),r:N}}}return m})(g)((()=>{if(r==="VDown")return Kt(h,p);if(r==="VUp")return ce(Kt(h,p));f()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;f()})()})((()=>{if(r==="VDown")return u;if(r==="VUp")return ce(u);f()})());return{root:c.root,align:c.align}})({root:pr(U(s=>b(s,s))(i)),align:pr(U(s=>b(s,s))(i))})((()=>{if(o==="HRight")return e;if(o==="HLeft")return ce(e);f()})());return{root:a.root,align:a.align}},Ps=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>{const g=qv(e)(n)(s)(u)(c),d=Wv(g)(o)(r)(i)(a)(c);return t2()(l=>_=>v("Just",(()=>{const h=_t(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;f()})()))(Qv(t)(e)(n)(r)(o)(i)(a)(d)(g)(u)(c))},Id=t=>e=>qt(n=>r=>J(o=>i=>i>=0&&i<e.length?i>=0&&i<t.length?o+e[i]+t[i]:o+e[i]+0:i>=0&&i<t.length?o+1+t[i]:o+1)(0)((()=>{const o=Kt(0,e.length-1|0);return n<1?[]:It(0,n,o)})()))(e),Hv=t=>e=>n=>r=>o=>i=>a=>{const s=Iv(0)(e.length-1|0),u=et(t.layerGap),c=a(Bm(s,u)),g=kv(vd(o)(c)(r)(i)(F))(c);return U(d=>{const l=Dv(d)(g);return l.tag==="Just"&&l._1>0?hr(u)(2+et(l._1-1|0)*2.5):u})(Kt(0,s-1|0))},Dd=t=>e=>n=>r=>u_(o=>J(i=>a=>{if(!i.ok)return i;const s=_t(a)(r),u=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;f()})(),c=_t(a)(n),g=(()=>{if(c.tag==="Nothing")return u+1;if(c.tag==="Just")return u+c._1._1;f()})();return u+1e-4>i.pos&&g+1e-4>i.pos?{ok:!0,pos:g}:{ok:!1,pos:i.pos}})({ok:!0,pos:-1e18})(o).ok,e),$v=t=>e=>n=>r=>{const o=Pt(i=>a=>ot.compare(i.w)(a.w))(U(i=>({l:i,w:Gd(i)}))(dt(Dd()(e)(n),r)));return 0<o.length?v("Just",o[0].l):w},Uv=t=>e=>{const n=pr(mn(U(qt(o=>i=>b(i,o)))(t))),r=o=>Pt(i=>a=>it.compare((()=>{const s=_t(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;f()})())((()=>{const s=_t(a)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;f()})()))(o);return{preds:(()=>{const o=i=>{if(i.tag==="Leaf")return F;if(i.tag==="Node")return oe("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));f()};return o(J(i=>a=>Ft(A)(xe)(a.to.node)([a.from.node])(i))(F)(e))})(),succs:(()=>{const o=i=>{if(i.tag==="Leaf")return F;if(i.tag==="Node")return oe("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));f()};return o(J(i=>a=>Ft(A)(xe)(a.from.node)([a.to.node])(i))(F)(e))})(),nodeIndex:n}},Vv=t=>e=>{const n=Pt(d=>l=>ot.compare(d.w)(l.w))(qt(d=>l=>({i:d,l,w:Gd(l)}))(e)),r=0<n.length?v("Just",n[0]):w,o=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;f()})(),i=o>=0&&o<e.length?v("Just",e[o]):w,a=(()=>{if(i.tag==="Just")return(d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const y=_,x=h;if(x.tag==="Nil"){p=!1,m=y;continue}if(x.tag==="Cons"){_=An(y)(x._1),h=x._2;continue}f()}return m})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,kt("Cons",l._4,d(l._6,_)));f()};return d(i._1,V)})());if(i.tag==="Nothing")return 0;f()})(),s=d=>J(l=>_=>hr(l)((()=>{const h=_t(_._1)(t);if(h.tag==="Nothing")return _._2+1;if(h.tag==="Just")return _._2+h._1._1;f()})()))(-999999)(_g(d)),u=o>=0&&o<e.length?v("Just",e[o]):w,c=(()=>{if(u.tag==="Just")return s(u._1);if(u.tag==="Nothing")return 0;f()})(),g=We(d=>l=>{const _=h=>{if(h.tag==="Leaf")return F;if(h.tag==="Node")return oe("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));f()};return _(d)},e,qt(d=>l=>Vr(d)(2)===0?a-(_=>h=>{let p=_,m=h,y=!0,x;for(;y;){const N=p,T=m;if(T.tag==="Nil"){y=!1,x=N;continue}if(T.tag==="Cons"){p=An(N)(T._1),m=T._2;continue}f()}return x})(999999)((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,kt("Cons",h._4,_(h._6,p)));f()};return _(l,V)})()):c-s(l))(e));return Mv(J(d=>l=>{const _=Pt(ot.compare)(vt(_t(l))(g));return rt(A)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(F)(ti(A.compare)(mn(U(d=>{const l=_=>{if(_.tag==="Leaf")return F;if(_.tag==="Node")return oe("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));f()};return Zt(dn.foldr,l(d))})(g)))))},Xv=t=>e=>n=>r=>o=>i=>{const a=Uv(e)(o),s=Ov(a)(e),u={nodeGap:t.nodeGap*4|0},c=Oe(A.compare,Qe,pr(U(_=>b(_,b(1,1)))(dt(dd,mn(e)))),(()=>{const _=h=>{if(h.tag==="Leaf")return F;if(h.tag==="Node")return oe("Node",h._1,h._2,h._3,b(h._4._1*et(4),h._4._2),_(h._5),_(h._6));f()};return _(n)})()),g=[Ps(u)(a)(e)(c)(r)(o)(i)(s)(Ld)(Ed),Ps(u)(a)(e)(c)(r)(o)(i)(s)(Sd)(Ed),Ps(u)(a)(e)(c)(r)(o)(i)(s)(Ld)(Pd),Ps(u)(a)(e)(c)(r)(o)(i)(s)(Sd)(Pd)],d=Vv(c)(g);if(Dd()(e)(c)(d))return d;const l=$v()(e)(c)(g);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return g[0];f()},Yv=t=>e=>n=>r=>{const o=i_(w,Zf,i=>i.node===e?v("Just",i.position):w,t);if(o.tag==="Nothing")return t;if(o.tag==="Just"){const i=o._1;return U(a=>a.node===n?{...a,position:b(i._1+r._1,i._2+r._2)}:a)(t)}f()},Kv=t=>e=>n=>r=>{const o=dt(a=>nn(ir)(a.node)(e),t),i=(()=>{if(n==="Vertical"){if(r==="Start")return J(a=>s=>An(a)(s.position._1))(99999)(o);if(r==="End")return J(a=>s=>hr(a)(s.position._1))(0)(o);if(r==="Center"){const a=J(s=>u=>s+u.position._1)(0)(o);return o.length===0?0:a/et(o.length)}f()}if(n==="Horizontal"){if(r==="Start")return J(a=>s=>An(a)(s.position._2))(99999)(o);if(r==="End")return J(a=>s=>hr(a)(s.position._2))(0)(o);if(r==="Center"){const a=J(s=>u=>s+u.position._2)(0)(o);return o.length===0?0:a/et(o.length)}}f()})();return U(a=>{if(nn(ir)(a.node)(e)){if(n==="Vertical")return{...a,position:b(i,a.position._2)};if(n==="Horizontal")return{...a,position:b(a.position._1,i)};f()}return a})(t)},jv=t=>e=>J(n=>r=>r.tag==="AlignGroup"?Kv(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?Yv(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),Zv=t=>e=>n=>r=>o=>i=>a=>s=>{const u=U(d=>J(l=>_=>hr(l)((()=>{const h=_t(_)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;f()})()))(1)(d))(n),c=Xv(t)(n)(r)(o)(i)(s),g=Id(Hv(t)(n)(r)(o)(i)(a)(d=>{const l=Id(d)(u);return mn(qt(_=>h=>qt(p=>m=>({node:m,position:b((()=>{const y=_t(m)(c);return(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;f()})()/et(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const y=ze(3)(m)==="$d:"?b(0,1):b(1,1),x=_t(m)(r);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;f()})(),layer:_,order:p}))(h))(n))}))(u);return jv(e)(mn(qt(d=>l=>qt(_=>h=>({node:h,position:b((()=>{const p=_t(h)(c);return(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;f()})()/et(4)})(),d>=0&&d<g.length?g[d]:0),size:(()=>{const p=ze(3)(h)==="$d:"?b(0,1):b(1,1),m=_t(h)(r);if(m.tag==="Nothing")return p;if(m.tag==="Just")return m._1;f()})(),layer:d,order:_}))(l))(n)))},dg=mc(Va)(yo(32)),Rd=mc(Va)(yo(31)),ta=(()=>{const t=q2("25214903917");if(t.tag==="Nothing")return E_;if(t.tag==="Just")return t._1;f()})(),ea=pc(mc(Va)(yo(48)))(Va),tT=t=>{const e=H2(t);return qi(P_((()=>{if(e.tag==="Nothing")return E_;if(e.tag==="Just")return e._1;f()})())(ta))(ea)},lg=yo(11),As=t=>e=>{const n=qi($a(Ua(e)(ta))(lg))(ea);return b((()=>{const r=g_(z2(yc(n)(yo(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;f()})(),n)},eT=t=>{const e=As(26)(t),n=As(27)(e._2);return b((et(e._1)*ju(2)(27)+et(n._1))/ju(2)(53),n._2)},nT=t=>e=>{const n=J(r=>o=>{const i=eT(r.finalR);return{rs:[...r.rs,i._1],finalR:i._2}})({rs:[],finalR:t})(e);return b(U(r=>r.x)(Pt(r=>o=>ot.compare(r.k)(o.k))(We(r=>o=>({x:r,k:o}),e,n.rs))),n.finalR)},rT=t=>{const e=qi($a(Ua(t)(ta))(lg))(ea),n=qi($a(Ua(e)(ta))(lg))(ea);return b($a(Ua((()=>{const r=yc(e)(yo(16));return A_.compare(r)(Rd)!=="LT"?pc(r)(dg):r})())(dg))((()=>{const r=yc(n)(yo(16));return A_.compare(r)(Rd)!=="LT"?pc(r)(dg):r})()),n)},na=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Gs=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},hg=ge(A)(Mt),xi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Is=ge(A)(Mt),oT=Fa(Zo),iT=J(sr)(0),aT=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Bd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},sT=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const o=Ur(Vt,w,t,n[e],n);if(o.tag==="Just")return Ur(Vt,w,e,r,o._1);if(o.tag==="Nothing")return w;f()}}return w},uT=t=>e=>n=>r=>o=>hg(J(i=>a=>{const s=Pt(u=>c=>it.compare((()=>{const g=na(u.id)(o);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;f()})())((()=>{const g=na(c.id)(o);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;f()})()))(dt(u=>Gs(u.to.node)(n),dt(u=>u.from.node===a,r)));return{ranks:[...i.ranks,...qt(u=>c=>b(c.id,et((i.rankSum+u|0)+1|0)))(s)],rankSum:i.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),cT=t=>e=>n=>r=>o=>hg(J(i=>a=>{const s=Pt(c=>g=>{const d=it.compare((()=>{const l=xi(g.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;f()})())((()=>{const l=xi(c.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;f()})());return d==="EQ"?it.compare((()=>{const l=na(c.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;f()})())((()=>{const l=na(g.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;f()})()):d})(dt(c=>Gs(c.from.node)(n),dt(c=>c.to.node===a,r))),u=s.length;return{ranks:[...i.ranks,...qt(c=>g=>b(g.id,et((i.rankSum+u|0)-c|0)))(s)],rankSum:i.rankSum+u|0}})({ranks:[],rankSum:0})(t).ranks),pg=t=>e=>n=>{const r=Is(qt(s=>u=>b(u,s))(t)),o=Is(qt(s=>u=>b(u,s))(e)),i=vt(s=>{const u=xi(s.from.node)(r),c=xi(s.to.node)(o);if(u.tag==="Just"&&c.tag==="Just")return v("Just",b(u._1,c._1));const g=xi(s.from.node)(o),d=xi(s.to.node)(r);return g.tag==="Just"&&d.tag==="Just"?v("Just",b(d._1,g._1)):w})(n),a=i.length;return J(s=>u=>J(c=>g=>u>=0&&u<i.length&&g>=0&&g<i.length&&((i[u]._1-i[g]._1|0)*(i[u]._2-i[g]._2|0)|0)<0?c+1|0:c)(s)(Kt(u+1|0,a-1|0)))(0)(Kt(0,a-2|0))},gT=t=>e=>n=>r=>{const o=i=>a=>{let s=i,u=a,c=!0,g;for(;c;){const d=s,l=u;if(l>=(d.length-1|0)){c=!1,g=d;continue}if(l>=0&&l<d.length){const _=l+1|0;if(_>=0&&_<d.length){const h=d[l],p=d[_];if(le(N=>N.before===h&&N.after===p,r)){s=d,u=l+1|0;continue}const m=Ur(Vt,w,l,p,d),y=(()=>{if(m.tag==="Just")return Ur(Vt,w,l+1|0,h,m._1);if(m.tag==="Nothing")return w;f()})(),x=(()=>{if(y.tag==="Nothing")return d;if(y.tag==="Just")return y._1;f()})();if(pg(e)(x)(n)<pg(e)(d)(n)){s=x,u=l+1|0;continue}s=d,u=l+1|0;continue}c=!1,g=d;continue}c=!1,g=d}return g};return(i=>{let a=i,s=!0,u;for(;s;){const c=a,g=o(c)(0);if(oT(g)(c)){s=!1,u=c;continue}a=g}return u})(t)},Ds=t=>e=>J(n=>r=>{if(r>=0&&r<t.length){const o=t[r],i=r+1|0;if(i>=0&&i<t.length)return n+pg(o)(t[i])(e)|0}return n})(0)(Kt(0,t.length-2|0)),fT=(()=>{const t=e=>{if(e.length<7){const i=a=>s=>{let u=a,c=s,g=!0,d;for(;g;){const l=u,_=c,h=_-1|0;if(h>=0&&h<l.length){if(_>=0&&_<l.length&&_>0&&l[h].key>l[_].key){const p=sT(_-1|0)(_)(l);if(p.tag==="Just"){u=p._1,c=_-1|0;continue}if(p.tag==="Nothing"){g=!1,d=l;continue}f()}g=!1,d=l;continue}g=!1,d=l}return d};return J(a=>s=>i(a)(s))(e)(Kt(1,e.length-1|0))}const n=kr(e.length,2),r=t(It(0,n,e)),o=t(It(n,e.length,e));return(i=>a=>s=>{let u=i,c=a,g=s,d=!0,l;for(;d;){const _=u,h=c,p=g;if(h>=0&&h<r.length){if(p>=0&&p<o.length){if(r[h].key>o[p].key){u=Ct(_)(o[p]),c=h,g=p+1|0;continue}u=Ct(_)(r[h]),c=h+1|0,g=p;continue}d=!1,l=[..._,...h<1?r:It(h,r.length,r)];continue}d=!1,l=[..._,...p<1?o:It(p,o.length,o)]}return l})([])(0)(0)};return t})(),_T=t=>e=>n=>{const r=vt(c=>c.tag==="OrderConstraint"?v("Just",{before:c._1.before,after:c._1.after}):w)(t.constraints),o=c=>J(g=>d=>{const l=d.after,_=d.before,h=Lr(Vt,w,m=>m===_,g),p=Lr(Vt,w,m=>m===l,g);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=s_(Vt,w,h._1,g),y=(()=>{if(m.tag==="Nothing")return g;if(m.tag==="Just")return m._1;f()})(),x=a_(Vt,w,p._1,_,y);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;f()}return g})(c)(r),i=hg(qt(c=>g=>b(g.id,c))(n)),a=(c,g,d)=>{const l=c.length;return J(_=>h=>{const p=g?h-1|0:h+1|0,m=p>=0&&p<_._1.length?v("Just",_._1[p]):w;if(m.tag==="Just"){const y=h>=0&&h<_._1.length?v("Just",_._1[h]):w;if(y.tag==="Just"){const x=Is(qt(S=>P=>b(P,S))(m._1)),N=Is(qt(S=>P=>b(P,S))(y._1)),T=g?uT(m._1)(x)(N)(n)(i):cT(m._1)(x)(N)(n)(i),C=J(S=>P=>{const M=vt(G=>na(G.id)(T))(dt(g?G=>G.to.node===P._2&&Gs(G.from.node)(x):G=>G.from.node===P._2&&Gs(G.to.node)(x),n));if(M.length===0)return{...S,items:[...S.items,{n:P._2,key:w,origIdx:P._1}]};const W=As(24)(S.r);return{items:[...S.items,{n:P._2,key:v("Just",(iT(M)+(et(W._1)*4172325152040912e-24-.03500000014901161))/et(M.length)),origIdx:P._1}],r:W._2}})({items:[],r:_._2})(qt(Bn)(y._1)),L=Ur(Vt,w,h,gT(o(U(S=>S.n)(fT((()=>{const S=C.items,P=M=>W=>{let G=M,I=W,j=!0,O;for(;j;){const z=G,$=I;if(z>=0&&z<S.length){if(S[z].key.tag==="Just"){j=!1,O=S[z].key._1;continue}if(S[z].key.tag==="Nothing"){G=z+1|0,I=$;continue}f()}j=!1,O=$}return O};return(M=>W=>G=>{let I=M,j=W,O=G,z=!0,$;for(;z;){const q=I,D=j,B=O;if(q>=0&&q<S.length){if(S[q].key.tag==="Just"){I=q+1|0,j=S[q].key._1,O=[...B,{n:S[q].n,key:S[q].key._1,origIdx:S[q].origIdx}];continue}if(S[q].key.tag==="Nothing"){const R=(D+P(q+1|0)(D+1))/2;I=q+1|0,j=R,O=[...B,{n:S[q].n,key:R,origIdx:S[q].origIdx}];continue}f()}z=!1,$=B}return $})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(L.tag==="Just")return b(L._1,C.r);if(L.tag==="Nothing")return b(_._1,_._2);f()}if(y.tag==="Nothing")return b(_._1,_._2);f()}if(m.tag==="Nothing")return b(_._1,_._2);f()})(b(c,d))(g?Kt(1,l-1|0):ce(Kt(0,l-2|0)))},s=J(c=>g=>rt(A)(g.from.node)()(rt(A)(g.to.node)()(c)))(F)(n),u=J(c=>g=>{if(c.result.crossings===0)return c;const d=x=>N=>T=>C=>{let L=x,S=N,P=T,M=C,W=!0,G;for(;W;){const I=L,j=S,O=P,z=M;if(O===0){W=!1,G={layout:I,crossings:0,random:z};continue}const $=a(I,j,z),q=Ds($._1)(n);if(q<O){L=$._1,S=!j,P=q,M=$._2;continue}W=!1,G={layout:I,crossings:O,random:$._2}}return G},l=As(1)(c.result.random),_=l._1!==0,h=t.modelOrder.tag==="Leaf",p=(c.firstTry||c.secondTry)&&!h?c.firstTry:_,m=(()=>{if(!h){const C=a(e,p,l._2);return d(C._1)(!p)(Ds(C._1)(n))(C._2)}const x=p?0:aT(0)(e.length-1|0),N=x>=0&&x<e.length?v("Just",e[x]):w;if(N.tag==="Just"&&N._1.length>1){const C=dt(L=>Bd(L)(s),N._1);if(C.length>1){const L=nT(l._2)(C),S=L._1,P=Ur(Vt,w,x,o(J(M=>W=>Bd(W)(s)?M.idx>=0&&M.idx<S.length?{idx:M.idx+1|0,result:[...M.result,S[M.idx]]}:{idx:M.idx,result:[...M.result,W]}:{idx:M.idx,result:[...M.result,W]})({idx:0,result:[]})(N._1).result),e);if(P.tag==="Just"){const M=a(P._1,p,L._2);return d(M._1)(!p)(Ds(M._1)(n))(M._2)}}}const T=a(e,p,l._2);return d(T._1)(!p)(Ds(T._1)(n))(T._2)})(),y=c.secondTry?!1:c.secondTry;return c.firstTry?{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:c.firstTry,secondTry:y}})({result:{layout:e,crossings:1e9,random:qi(P_(rT(tT(1))._1)(ta))(ea)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Kt(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:u.layout},dT=t=>t,Fd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},rn=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},wi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},ra=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=A.compare(e._1)(n._1);return r==="LT"?Fe:r==="GT"?Me:A.compare(e._2)(n._2)},Eq0:()=>t}})(),lT=ge(A)(Mt),hT=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=ra.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},pT=dT("Greedy"),mg=t=>e=>n=>J(r=>o=>{if(o.from.node===o.to.node)return r;if(o.from.node===e&&!Fd(o.to.node)(r.marks)){const i=rn(o.to.node)(r.inDeg),a=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;f()})(),s=rt(A)(o.to.node)(a)(r.inDeg);return(()=>{const u=rn(o.to.node)(r.outDeg);return a<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;f()})()&&!nn(ir)(o.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,o.to.node]}:{...r,inDeg:s}}if(o.to.node===e&&!Fd(o.from.node)(r.marks)){const i=rn(o.from.node)(r.outDeg),a=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;f()})(),s=rt(A)(o.from.node)(a)(r.outDeg);return(()=>{const u=rn(o.from.node)(r.inDeg);return a<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;f()})()&&!nn(ir)(o.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,o.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:dt(r=>r!==e,n.remaining)})(t),mT=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return rt(A)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return rt(A)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return rt(A)(e._1.node)(99999)(t)}return t})(F),Md=t=>e=>n=>{const r=rn(e)(t),o=rn(n)(t);return r.tag==="Just"&&o.tag==="Just"&&r._1>o._1},zd=t=>e=>n=>r=>{if(wi(n)(r.visited)||wi(n)(r.visiting))return r;const o=J(yT(t)(e)(n))({...r,visiting:rt(A)(n)()(r.visiting)})((()=>{const i=rn(n)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;f()})());return{...o,visiting:oi(A)(n)(o.visiting),visited:rt(A)(n)()(o.visited)}},yT=t=>e=>n=>r=>o=>Md(t)(n)(o)?{...r,backEdges:rt(ra)(b(n,o))()(r.backEdges)}:wi(o)(r.visiting)?{...r,backEdges:rt(ra)(b(n,o))()(r.backEdges)}:wi(o)(r.visited)?r:zd(t)(e)(o)(r),xT=t=>e=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,y=Rt(x=>w,x=>N=>v("Just",{head:x,tail:N}),m.sinks);if(y.tag==="Just"){_=mg(n)(y._1.head)({...m,sinks:y._1.tail,marks:rt(A)(y._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(y.tag==="Nothing"){const x=Rt(N=>w,N=>T=>v("Just",{head:N,tail:T}),m.sources);if(x.tag==="Just"){_=mg(n)(x._1.head)({...m,sources:x._1.tail,marks:rt(A)(x._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(x.tag==="Nothing"){const N=C=>{const L=rn(C)(m.outDeg),S=rn(C)(m.inDeg);return(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;f()})()-(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;f()})()|0},T=Pt(C=>L=>{const S=it.compare(N(L))(N(C));return S==="EQ"?it.compare((()=>{const P=rn(C)(e);if(P.tag==="Nothing")return 1e6;if(P.tag==="Just")return P._1;f()})())((()=>{const P=rn(L)(e);if(P.tag==="Nothing")return 1e6;if(P.tag==="Just")return P._1;f()})()):S})(m.remaining);if(0<T.length){const C=T[0];_=mg(n)(C)({...m,remaining:dt(L=>L!==C,m.remaining),marks:rt(A)(C)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}f()}return p},o=ti(A.compare)([...U(l=>l.from.node)(n),...U(l=>l.to.node)(n)]),i=dt(l=>l.from.node!==l.to.node,n),a=J(l=>_=>Ft(A)(Te)(_.to.node)(1)(l))(F)(i),s=J(l=>_=>Ft(A)(Te)(_.from.node)(1)(l))(F)(i),u=dt(l=>{const _=rn(l)(a);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;f()},o),c=dt(l=>{const _=rn(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;f()},o),g=o.length+1|0,d=J(l=>_=>{const h=rn(_)(l);return h.tag==="Just"&&h._1<0?rt(A)(_)(h._1+g|0)(l):l})(r({remaining:dt(l=>!nn(ir)(l)(u)&&!nn(ir)(l)(c),o),marks:F,inDeg:a,outDeg:s,sources:u,sinks:c,nextLeft:1,nextRight:-1}).marks)(o);return J(l=>_=>{if(_.from.node===_.to.node)return l;if(Md(t)(_.from.node)(_.to.node))return rt(ra)(b(_.from.node,_.to.node))()(l);const h=rn(_.from.node)(d),p=rn(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?rt(ra)(b(_.from.node,_.to.node))()(l):l})(F)(n)},wT=J(t=>e=>Ft(A)(xe)(e.from.node)([e.to.node])(t))(F),NT=t=>e=>{const n=wT(e),r=ti(A.compare)([...U(i=>i.from.node)(e),...U(i=>i.to.node)(e)]),o=J(i=>a=>rt(A)(a.to.node)()(i))(F)(e);return J(i=>a=>zd(t)(n)(a)(i))({visiting:F,visited:F,backEdges:F})([...dt(i=>!wi(i)(o),r),...dt(i=>wi(i)(o),r)]).backEdges},vT=t=>e=>n=>r=>{const o=lT(qt(s=>u=>b(u,s))(e)),i=mT(n),a=(()=>{if(t==="DepthFirst")return NT(i)(r);if(t==="Greedy")return xT(i)(o)(r);f()})();return{edges:U(s=>hT(b(s.from.node,s.to.node))(a)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:a}},Qd=Mt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),Le=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},Se=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},oa=t=>e=>n=>r=>Qd(o=>n>=o.x&&n<o.x+o.w&&e>o.y&&t<o.y+o.h)(r),Rs=t=>e=>n=>r=>oa(Le(e)(n))(Se(e)(n))(r)(t),Bs=et(4),TT=Ma(t=>{if(t.direction==="H"){const e=Le(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:Se(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=Le(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:Se(t.start._2)(t.end._2)-e}]}f()}),ia=Fi(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})())}),JT=t=>e=>n=>{const r=Rt(o=>w,o=>i=>v("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=Sr(r._1.tail);if(i.tag==="Nothing"){const a=o.length-1|0;return a>=0&&a<o.length&&(o[a].direction==="H"?n.direction==="H":o[a].direction==="V"&&n.direction==="V")?[...(()=>{const s=o.length-1|0;return s<1?[]:It(0,s,o)})(),{start:o[a].start,end:n.end,direction:n.direction}]:[...o,n]}if(i.tag==="Just")return(i._1.last.direction==="H"?n.direction==="H":i._1.last.direction==="V"&&n.direction==="V")?[...o,...i._1.init,{start:i._1.last.start,end:n.end,direction:n.direction}]:[...o,...r._1.tail,n]}f()},aa=t=>{const e=r=>o=>{const i=Rt(a=>w,a=>s=>v("Just",{head:a,tail:s}),o);if(i.tag==="Nothing")return[r];if(i.tag==="Just")return(r.direction==="H"?i._1.head.direction==="H":r.direction==="V"&&i._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==i._1.head.end._1-i._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==i._1.head.end._2-i._1.head.start._2>=0;f()})()?e({start:r.start,end:i._1.head.end,direction:r.direction})(i._1.tail):[r,...e(i._1.head)(i._1.tail)];f()},n=Rt(r=>w,r=>o=>v("Just",{head:r,tail:o}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);f()},sa=t=>e=>n=>r=>Qd(o=>n>=o.y&&n<o.y+o.h&&e>o.x&&t<o.x+o.w)(r),ua=t=>e=>n=>r=>sa(Le(e)(n))(Se(e)(n))(r)(t),bT=t=>e=>n=>r=>{const o=n+2|0,i=o<1?e:It(o,e.length,e),a=n<1?[]:It(0,n,e),s=(n+1|0)===(r-1|0),u=n===0,c=n>=0&&n<e.length?v("Just",e[n]):w;if(c.tag==="Just"){const g=n+1|0,d=g>=0&&g<e.length?v("Just",e[g]):w;if(d.tag==="Just"){const l=c._1.start._1===d._1.end._1&&(!u||c._1.direction==="V")&&(!s||d._1.direction==="V")&&!Rs(t)(Le(c._1.start._2)(d._1.end._2))(Se(c._1.start._2)(d._1.end._2))(c._1.start._1)?v("Just",[...a,{start:c._1.start,end:d._1.end,direction:me},...i]):w,_=c._1.start._2===d._1.end._2&&(!u||c._1.direction==="H")&&(!s||d._1.direction==="H")&&!ua(t)(Le(c._1.start._1)(d._1.end._1))(Se(c._1.start._1)(d._1.end._1))(c._1.start._2)?v("Just",[...a,{start:c._1.start,end:d._1.end,direction:Ne},...i]):w;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return w;f()}if(c.tag==="Nothing")return w;f()},CT=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,a;for(;i;){const s=o;if((s+1|0)>=n){i=!1,a=e;continue}const u=bT(t)(e)(s)(n);if(u.tag==="Just"){i=!1,a=u._1;continue}if(u.tag==="Nothing"){o=s+1|0;continue}f()}return a})(0)},kT=t=>e=>n=>r=>{const o=(l,_,h)=>!Rs(t)(Le(_)(h))(Se(_)(h))(l),i=n+3|0,a=i<1?e:It(i,e.length,e),s=n<1?[]:It(0,n,e),u=(n+2|0)===(r-1|0),c=n===0,g=(l,_,h)=>!ua(t)(Le(_)(h))(Se(_)(h))(l),d=n>=0&&n<e.length?v("Just",e[n]):w;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<e.length?v("Just",e[l]):w;if(_.tag==="Just"){const h=d._1.start._1===_._1.end._1&&(!c||d._1.direction==="V")&&(!u||_._1.direction==="V")&&o(d._1.start._1,d._1.start._2,_._1.end._2)?v("Just",[...s,{start:d._1.start,end:_._1.end,direction:me},...a]):d._1.start._2===_._1.end._2&&(!c||d._1.direction==="H")&&(!u||_._1.direction==="H")&&g(d._1.start._2,d._1.start._1,_._1.end._1)?v("Just",[...s,{start:d._1.start,end:_._1.end,direction:Ne},...a]):w,p=(!c||d._1.direction==="V")&&(!u||_._1.direction==="H")&&o(d._1.start._1,d._1.start._2,_._1.end._2)&&g(_._1.end._2,d._1.start._1,_._1.end._1)?v("Just",[...s,{start:d._1.start,end:b(d._1.start._1,_._1.end._2),direction:me},{start:b(d._1.start._1,_._1.end._2),end:_._1.end,direction:Ne},...a]):w,m=(!c||d._1.direction==="H")&&(!u||_._1.direction==="V")&&g(d._1.start._2,d._1.start._1,_._1.end._1)&&o(_._1.end._1,d._1.start._2,_._1.end._2)?v("Just",[...s,{start:d._1.start,end:b(_._1.end._1,d._1.start._2),direction:Ne},{start:b(_._1.end._1,d._1.start._2),end:_._1.end,direction:me},...a]):w,y=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?y:h}if(_.tag==="Nothing")return w;f()}if(d.tag==="Nothing")return w;f()},LT=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,a;for(;i;){const s=o;if((s+2|0)>=n){i=!1,a=e;continue}const u=kT(t)(e)(s)(n);if(u.tag==="Just"){i=!1,a=u._1;continue}if(u.tag==="Nothing"){o=s+1|0;continue}f()}return a})(0)},ST=t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const a=r,s=aa(ia(CT(t)(LT(t)(a))));if(s.length<a.length){r=s;continue}o=!1,i=s}return i};return n=>e(aa(ia(n)))},ET=t=>e=>n=>r=>{const o=Le(n)(r),i=Se(n)(r),a=dt(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Pt(c=>g=>ot.compare(c.x)(g.x))(a);return 0<u.length?u[0].x-1:(n+r)/2}const s=Pt(u=>c=>ot.compare(c.x)(u.x))(U(u=>({...u,x:u.x+u.w}))(a));return 0<s.length?s[0].x+1:(n+r)/2},PT=t=>e=>n=>r=>{const o=Le(n)(r),i=Se(n)(r),a=dt(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Pt(c=>g=>ot.compare(c.y)(g.y))(a);return 0<u.length?u[0].y-1:(n+r)/2}const s=Pt(u=>c=>ot.compare(c.y)(u.y))(U(u=>({...u,y:u.y+u.h}))(a));return 0<s.length?s[0].y+1:(n+r)/2},AT=t=>e=>n=>r=>{const o=Le(n)(r),i=Se(n)(r),a=dt(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Pt(c=>g=>ot.compare(g.x)(c.x))(U(c=>({...c,x:c.x+c.w}))(a));return 0<u.length?u[0].x:(n+r)/2}const s=Pt(u=>c=>ot.compare(u.x)(c.x))(a);return 0<s.length?s[0].x-1:(n+r)/2},GT=t=>e=>n=>r=>{const o=Le(n)(r),i=Se(n)(r),a=dt(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Pt(c=>g=>ot.compare(g.y)(c.y))(U(c=>({...c,y:c.y+c.h}))(a));return 0<u.length?u[0].y:(n+r)/2}const s=Pt(u=>c=>ot.compare(u.y)(c.y))(a);return 0<s.length?s[0].y-1:(n+r)/2},Wd=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,c=o,g=i;if(g>100){a=!1,s=c;continue}if(!u(c+g)){a=!1,s=c+g;continue}if(!u(c-g)){a=!1,s=c-g;continue}r=u,o=c,i=g+1}return s},Od=t=>e=>n=>r=>o=>{const i=Le(e)(n),a=Se(e)(n);if(!oa(i)(a)(r)(t))return r;if(!oa(i)(a)(o)(t))return o;const s=(r+o)/2;return oa(i)(a)(s)(t)?Wd(u=>oa(i)(a)(u)(t))(s)(1):s},IT=t=>e=>n=>r=>o=>{const i=Le(e)(n),a=Se(e)(n);if(!sa(i)(a)(r)(t))return r;if(!sa(i)(a)(o)(t))return o;const s=(r+o)/2;return sa(i)(a)(s)(t)?Wd(u=>sa(i)(a)(u)(t))(s)(1):s},DT=t=>e=>n=>r=>{const o=Le(e)(n),i=Se(e)(n),a=dt(c=>r>=c.x&&r<c.x+c.w&&c.y+c.h>o&&c.y<i,t),s=J(c=>g=>Se(c)(g.x+g.w+4))(r+4)(a),u=J(c=>g=>Le(c)(g.x-4))(r-4)(a);return(()=>{const c=s-r,g=u-r;return(c<0?-c:c)<=(g<0?-g:g)})()?s:u},RT=t=>e=>n=>r=>{const o=Le(e)(n),i=Se(e)(n),a=dt(c=>r>=c.y&&r<c.y+c.h&&c.x+c.w>o&&c.x<i,t),s=J(c=>g=>Se(c)(g.y+g.h+4))(r+4)(a),u=J(c=>g=>Le(c)(g.y-4))(r-4)(a);return(()=>{const c=s-r,g=u-r;return(c<0?-c:c)<=(g<0?-g:g)})()?s:u},BT=t=>e=>n=>r=>o=>i=>a=>{const s=(()=>{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);f()})(),u=(()=>{if(i==="South")return b(a._1,a._2+4);if(i==="North")return b(a._1,a._2-4);if(i==="East")return b(a._1+4,a._2);if(i==="West")return b(a._1-4,a._2);f()})(),c=(C,L,S)=>!Rs(e)(Le(L)(S))(Se(L)(S))(C),g=(C,L,S)=>!Rs(n)(Le(L)(S))(Se(L)(S))(C),d=(C,L,S,P)=>t.tag==="Just"&&!ua(n)(Le(C)(L))(Se(C)(L))(t._1)?t._1:IT(e)(C)(L)(S)(P),l=(C,L,S,P)=>{if(C===S){const W=DT(e)(L)(P)(C),G=PT(e)(C)(L)(P),I=GT(e)(C)(L)(P);return[{start:b(C,L),end:b(C,G),direction:me},{start:b(C,G),end:b(W,G),direction:Ne},{start:b(W,G),end:b(W,I),direction:me},{start:b(W,I),end:b(S,I),direction:Ne},{start:b(S,I),end:b(S,P),direction:me}]}const M=d(C,S,L,P);return[{start:b(C,L),end:b(C,M),direction:me},{start:b(C,M),end:b(S,M),direction:Ne},{start:b(S,M),end:b(S,P),direction:me}]},_=(C,L,S,P)=>{if(L===P){const W=RT(e)(C)(S)(L),G=ET(e)(L)(C)(S),I=AT(e)(L)(C)(S);return[{start:b(C,L),end:b(G,L),direction:Ne},{start:b(G,L),end:b(G,W),direction:me},{start:b(G,W),end:b(I,W),direction:Ne},{start:b(I,W),end:b(I,P),direction:me},{start:b(I,P),end:b(S,P),direction:Ne}]}const M=Od(e)(L)(P)(C)(S);return[{start:b(C,L),end:b(M,L),direction:Ne},{start:b(M,L),end:b(M,P),direction:me},{start:b(M,P),end:b(S,P),direction:Ne}]},h=(C,L,S)=>!ua(e)(Le(L)(S))(Se(L)(S))(C),p=(C,L,S)=>!ua(n)(Le(L)(S))(Se(L)(S))(C),m=(C,L,S,P)=>{if(p(L,C,S)&&g(S,L,P))return[{start:b(C,L),end:b(S,L),direction:Ne},{start:b(S,L),end:b(S,P),direction:me}];const M=Od(e)(L)(P)(C)(S);return[{start:b(C,L),end:b(M,L),direction:Ne},{start:b(M,L),end:b(M,P),direction:me},{start:b(M,P),end:b(S,P),direction:Ne}]},y=(C,L,S,P)=>{if(g(C,L,P)&&p(P,C,S))return[{start:b(C,L),end:b(C,P),direction:me},{start:b(C,P),end:b(S,P),direction:Ne}];const M=d(C,S,L,P);return[{start:b(C,L),end:b(C,M),direction:me},{start:b(C,M),end:b(S,M),direction:Ne},{start:b(S,M),end:b(S,P),direction:me}]},x=(()=>{if(r==="South")return i==="North"?s._1===u._1&&c(s._1,s._2,u._2)?[{start:b(s._1,s._2),end:b(u._1,u._2),direction:me}]:l(s._1,s._2,u._1,u._2):i==="East"||i==="West"?y(s._1,s._2,u._1,u._2):l(s._1,s._2,u._1,u._2);if(r==="North")return i==="South"?s._1===u._1&&c(s._1,s._2,u._2)?[{start:b(s._1,s._2),end:b(u._1,u._2),direction:me}]:l(s._1,s._2,u._1,u._2):i==="East"||i==="West"?y(s._1,s._2,u._1,u._2):l(s._1,s._2,u._1,u._2);if(r==="East")return i==="West"?s._2===u._2&&h(s._2,s._1,u._1)?[{start:b(s._1,s._2),end:b(u._1,u._2),direction:Ne}]:_(s._1,s._2,u._1,u._2):i==="North"||i==="South"?m(s._1,s._2,u._1,u._2):l(s._1,s._2,u._1,u._2);if(r==="West"){if(i==="East")return s._2===u._2&&h(s._2,s._1,u._1)?[{start:b(s._1,s._2),end:b(u._1,u._2),direction:Ne}]:_(s._1,s._2,u._1,u._2);if(i==="North"||i==="South")return m(s._1,s._2,u._1,u._2)}return l(s._1,s._2,u._1,u._2)})(),N=(()=>{if(r==="South"||r==="North")return me;if(r==="East"||r==="West")return Ne;f()})(),T={start:b(u._1,u._2),end:b(a._1,a._2),direction:(()=>{if(i==="South"||i==="North")return me;if(i==="East"||i==="West")return Ne;f()})()};return s._1===u._1&&s._2===u._2?[{start:b(o._1,o._2),end:b(a._1,a._2),direction:N}]:JT({start:b(o._1,o._2),end:b(s._1,s._2),direction:N})(x)(T)},FT=U(t=>({x:t.position._1*Bs-2,y:t.position._2*Bs-2,w:t.size._1*Bs+4,h:t.size._2*Bs+4})),qd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},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 a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},MT=(()=>{const t=fn.unfoldr(Xn);return e=>t(_n("IterNode",e,Un))})(),yg=t=>e=>t.gapTop+1*et(4)+et(e)*2.5*et(4),zT=t=>e=>{const n=qd(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return v("Just",{slot1Y:yg(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:yg(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return w;f()}if(n.tag==="Nothing")return w;f()},QT=t=>e=>{const n=J(r=>o=>rt(A)(o.node)(o)(r))(F)(e);return mn(qt(r=>o=>{const i=Ni(o.node)(n);if(i.tag==="Nothing")return[];if(i.tag==="Just"){const a=i._1;return qt(s=>u=>{const c=o.edges.length,g=et(4),d=a.position._1*g,l=a.position._2*g,_=a.size._2*g,h=et((2*c|0)+1|0),p=l+_*et(c-s|0)/h,m=l+_*et((c+1|0)+s|0)/h,y=d-g*2.5*et(s+1|0),x=[{start:b(d,p),end:b(y,p),direction:Ne},{start:b(y,p),end:b(y,m),direction:me},{start:b(y,m),end:b(d,m),direction:Ne}];return{edge:u.id,segments:x,bends:We(N=>T=>N.end,x,It(1,3,x)),bendType:[],jumps:[],reversed:!1}})(o.edges)}f()})(U(r=>({node:r._1,edges:r._2}))(MT(J(r=>o=>Ft(A)(xe)(o.from.node)([o])(r))(F)(t)))))},WT=t=>e=>{const n=J(i=>a=>rt(A)(a.node)(a)(i))(F)(e),r=i=>{const a=Ni(i)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1.position._1;f()},o=i=>{const a=Ni(i)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1.layer;f()};return Pt(i=>a=>{const s=it.compare(o(i.edge.from.node))(o(a.edge.from.node));if(s==="EQ"){const u=ot.compare(r(i.edge.from.node))(r(a.edge.from.node));return u==="EQ"?ot.compare(r(i.edge.to.node))(r(a.edge.to.node)):u}return s})(t)},on=t=>{const e=et(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}},OT=t=>t.from.node===t.to.node,qT=t=>e=>n=>r=>{const o=ST(n)(BT(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:o,bends:We(i=>a=>i.end,o,It(1,o.length,o)),bendType:[],jumps:[],reversed:!1}},HT=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:Ne},{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:Ne},{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:We(i=>a=>i.end,o,It(1,5,o)),bendType:[],jumps:[],reversed:!1}},$T=t=>e=>n=>{const r=Ni(t.edge.from.node)(n);if(r.tag==="Just"){const i=Ni(t.edge.to.node)(n);return i.tag==="Just"?dt(a=>!(a.h===on(r._1).h&&a.w===on(r._1).w&&a.x===on(r._1).x&&a.y===on(r._1).y)&&!(a.h===on(i._1).h&&a.w===on(i._1).w&&a.x===on(i._1).x&&a.y===on(i._1).y),e):dt(a=>!(a.h===on(r._1).h&&a.w===on(r._1).w&&a.x===on(r._1).x&&a.y===on(r._1).y),e)}const o=Ni(t.edge.to.node)(n);return o.tag==="Just"?dt(i=>!(i.h===on(o._1).h&&i.w===on(o._1).w&&i.x===on(o._1).x&&i.y===on(o._1).y),e):dt(i=>!0,e)},UT=t=>e=>{const n=qd(e.edge.id)(t);if(n.tag==="Just")return v("Just",yg(n._1)(n._1.slot));if(n.tag==="Nothing")return w;f()},VT=t=>e=>n=>r=>o=>{const i=J(c=>g=>rt(A)(g.node)(g)(c))(F)(e),a=FT(e),s=vd(dt(c=>c.from.node!==c.to.node,t))(e)(n)(r)(o),u=md(s)(e);return[...QT(dt(OT,t))(e),...J(c=>g=>{const d=$T(g)(a)(i),l=[...d,...c.edgeObstacles],_=zT(u)(g),h=(()=>{if(_.tag==="Just")return HT(_._1)(d)(l)(g);if(_.tag==="Nothing")return qT(UT(u)(g))(d)(l)(g);f()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...TT(h.segments)]}})({results:[],edgeObstacles:[]})(WT(s)(e)).results]},eo=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},no=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},XT=t=>e=>n=>{if(t.start._1!==e.start._1)return w;const r=no(eo(t.start._2)(t.end._2))(eo(e.start._2)(e.end._2)),o=eo(no(t.start._2)(t.end._2))(no(e.start._2)(e.end._2));return r<o?v("Just",{position:b(t.start._1,(r+o)/2),crossingEdge:n}):w},YT=t=>e=>n=>{if(t.start._2!==e.start._2)return w;const r=no(eo(t.start._1)(t.end._1))(eo(e.start._1)(e.end._1)),o=eo(no(t.start._1)(t.end._1))(no(e.start._1)(e.end._1));return r<o?v("Just",{position:b((r+o)/2,t.start._2),crossingEdge:n}):w},KT=t=>e=>n=>{if(t.direction==="H")return YT(t)(e)(n);if(t.direction==="V")return XT(t)(e)(n);f()},jT=t=>e=>n=>{const r=t+1|0,o=r<1?n:It(r,n.length,n);return St(e.segments)(i=>St(o)(a=>vt(s=>KT(i)(s)(a.edge))(dt(s=>s.direction==="H"?i.direction==="H":s.direction==="V"&&i.direction==="V",a.segments))))},ZT=t=>e=>n=>e.start._1>eo(t.start._1)(t.end._1)&&e.start._1<no(t.start._1)(t.end._1)&&t.start._2>eo(e.start._2)(e.end._2)&&t.start._2<no(e.start._2)(e.end._2)?v("Just",{position:b(e.start._1,t.start._2),crossingEdge:n}):w,tJ=t=>e=>St(dt(n=>n.direction==="H",t.segments))(n=>St(e)(r=>vt(o=>ZT(n)(o)(r.edge))(dt(o=>o.direction==="V",r.segments)))),Hd=t=>e=>n=>[...tJ(e)(dt(r=>r.edge!==e.edge,n)),...jT(t)(e)(n)],$d=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},eJ=J(t=>e=>rt(A)(e)()(t))(F),Fs=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},nJ=sd(A),mr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Ud=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},xg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=it.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},rJ=ge(it)(Mt),oJ=t=>e=>Oe(A.compare,Qe,t,e),Vd=qt(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),iJ=t=>J(e=>n=>({base:(()=>{const r=o=>i=>{let a=o,s=i,u=!0,c;for(;u;){const g=a,d=s;if(d.tag==="Nil"){u=!1,c=g;continue}if(d.tag==="Cons"){a=$d(g)(d._1),s=d._2;continue}f()}return c};return(e.base+r(0)((()=>{const o=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return o(i._5,kt("Cons",i._4,o(i._6,a)));f()};return o(n,V)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=o=>{if(o.tag==="Leaf")return F;if(o.tag==="Node")return oe("Node",o._1,o._2,o._3,o._4+e.base|0,r(o._5),r(o._6));f()};return r(n)})()]}))({base:0,result:[]})(t).result,aJ=t=>e=>{const n=eJ(t);return nJ(t)(Vd(dt(r=>Fs(r.src)(n)&&Fs(r.tgt)(n),e)))},sJ=t=>e=>{const n=J(o=>i=>Ft(A)(xe)(i.tgt)([i.src])(Ft(A)(xe)(i.src)([i.tgt])(o)))(F)(e),r=o=>i=>a=>{let s=o,u=i,c=a,g=!0,d;for(;g;){const l=s,_=u,h=c,p=Rt(m=>w,m=>y=>v("Just",{head:m,tail:y}),l);if(p.tag==="Nothing"){g=!1,d={nodes:h};continue}if(p.tag==="Just"){if(Fs(p._1.head)(_)){s=p._1.tail,u=_,c=h;continue}s=[...p._1.tail,...(()=>{const m=mr(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;f()})()],u=rt(A)(p._1.head)()(_),c=[...h,p._1.head];continue}f()}return d};return J(o=>i=>{if(Fs(i)(o.visited))return o;const a=r([i])(o.visited)([]);return{...o,visited:J(s=>u=>rt(A)(u)()(s))(o.visited)(a.nodes),components:[...o.components,a.nodes]}})({visited:F,components:[]})(t).components},uJ=t=>e=>n=>{const r=J(i=>a=>Ft(A)(Te)(a.tgt)(1)(i))(F)(e),o=J(i=>a=>Ft(A)(Te)(a.src)(1)(i))(F)(e);return J(i=>a=>{const s=mr(a)(r),u=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;f()})();if((()=>{const x=mr(a)(o);return(()=>{if(x.tag==="Nothing")return u!==0;if(x.tag==="Just")return u!==x._1;f()})()||u===0})())return i;const c=mr(a)(i.layers),g=(()=>{if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1;f()})(),d=i.layers,l=J(x=>N=>N.tgt===a?{...x,mIn:Ud(x.mIn)((()=>{const T=mr(a)(d),C=mr(N.src)(d);return(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;f()})()-(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;f()})()|0})())}:N.src===a?{...x,mOut:Ud(x.mOut)((()=>{const T=mr(N.tgt)(d),C=mr(a)(d);return(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;f()})()-(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;f()})()|0})())}:x)({mIn:1e9,mOut:1e9})(e),_=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(_<0||h<0)return i;const p=(g-_|0)+1|0,m=(g+h|0)-1|0;if(m<p)return i;const y=J(x=>N=>{const T=xg(N)(i.filling),C=(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;f()})();return C<x.bestFill?{best:N,bestFill:C}:x})({best:g,bestFill:(()=>{const x=xg(g)(i.filling);if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;f()})()})(Kt(p,m));return y.best===g?i:{layers:rt(A)(a)(y.best)(i.layers),filling:rt(it)(g)((()=>{const x=xg(g)(i.filling);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;f()})())(rt(it)(y.best)(y.bestFill+1|0)(i.filling))}})({layers:n,filling:rJ(U(i=>b(i,J(a=>s=>(()=>{const u=mr(s)(n);return u.tag==="Nothing"?!1:u.tag==="Just"&&u._1===i})()?a+1|0:a)(0)(t)))(Kt(0,J(i=>a=>$d(i)((()=>{const s=mr(a)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;f()})()))(0)(t))))})(t).layers},cJ=t=>e=>uJ(t)(Vd(e))(J(oJ)(F)(iJ(U(n=>aJ(n)(e))(sJ(t)(e))))),gJ=t=>t,Co=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Ms=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Xd=(()=>{const t=fn.unfoldr(Xn);return e=>t(_n("IterNode",e,Un))})(),fJ=gJ("NetworkSimplex"),_J=t=>e=>J(n=>r=>{const o=J(Ms)(0)(vt(i=>Co(i)(n))(r));return J(i=>a=>rt(A)(a)(o)(i))(n)(r)})(e)(t),dJ=t=>e=>({layers:U(n=>dt(r=>{const o=Co(r)(e);return o.tag==="Nothing"?!1:o.tag==="Just"&&o._1===n},t))(Kt(0,(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,c=i;if(c.tag==="Nil"){a=!1,s=u;continue}if(c.tag==="Cons"){o=Ms(u)(c._1),i=c._2;continue}f()}return s})(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)));f()};return n(e,V)})()))),nodeLayer:e}),lJ=t=>e=>n=>{const r=J(o=>i=>rt(A)(i)(!0)(o))(F)(e);return J(o=>i=>rt(A)(i._1)(i._2)(o))(cJ(e)(vt(o=>o.from.node===o.to.node||(()=>{const i=Co(o.from.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;f()})()||(()=>{const i=Co(o.to.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;f()})()?w:v("Just",{src:o.from.node,tgt:o.to.node}))(t)))(Xd(n))},hJ=t=>e=>n=>r=>{const o=s=>u=>{const c=Co(u)(s);if(c.tag==="Just")return s;if(c.tag==="Nothing"){const g=dt(l=>l!==u,(()=>{const l=Co(u)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;f()})()),d=J(o)(s)(g);return rt(A)(u)(1+J(Ms)(0)(vt(l=>Co(l)(d))(g))|0)(d)}f()},i=J(o)(F)(n),a=(s=>u=>{let c=s,g=u,d=!0,l;for(;d;){const _=c,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=Ms(_)(h._1),g=h._2;continue}f()}return l})(1)((()=>{const s=(u,c)=>{if(u.tag==="Leaf")return c;if(u.tag==="Node")return s(u._5,kt("Cons",u._4,s(u._6,c)));f()};return s(i,V)})());return J(s=>u=>rt(A)(u._1)(u._2)(s))((()=>{const s=u=>{if(u.tag==="Leaf")return F;if(u.tag==="Node")return oe("Node",u._1,u._2,u._3,a-u._4|0,s(u._5),s(u._6));f()};return s(i)})())(Xd(r))},pJ=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return rt(A)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return rt(A)(e._1.node)(0)(t)}return t})(F),mJ=J(t=>e=>Ft(A)(xe)(e.to.node)([e.from.node])(t))(F),yJ=J(t=>e=>Ft(A)(xe)(e.from.node)([e.to.node])(t))(F),xJ=t=>e=>n=>r=>{const o=yJ(n),i=mJ(n),a=pJ(e);return dJ(r)(_J(vt(s=>s.tag==="SameLayer"?v("Just",s._1.nodes):w)(e))((()=>{if(t==="LongestPath")return hJ(o)(i)(r)(a);if(t==="NetworkSimplex")return lJ(n)(r)(a);f()})()))},wJ=ge(A)(Mt),NJ=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Yd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Kd=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},ca=ge(A)(Mt),vJ=ge(A)(Mt),jd=(()=>{const t=U(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>ce(t(e))})(),TJ=t=>e=>n=>r=>{const o=wJ(U(a=>b(a.edge,a))(r)),i=a=>0<a.nodes.length&&(()=>{const s=NJ(a.edgeId)(n);return s.tag==="Just"&&a.nodes[0]!==s._1._1})();return U(a=>{if(a.nodes.length<=2){const g=Yd(a.edgeId)(o);if(g.tag==="Just"){const d=i(a),l=aa(ia(d?jd(g._1.segments):g._1.segments));return{...g._1,edge:a.edgeId,segments:l,bends:We(_=>h=>_.end,l,It(1,l.length,l)),reversed:d}}if(g.tag==="Nothing")return{edge:a.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};f()}const s=St(vt(g=>Yd(g)(o))(We(g=>d=>a.edgeId+":"+g+"->"+d,a.nodes,It(1,a.nodes.length,a.nodes))))(g=>g.segments),u=i(a),c=aa(ia(u?jd(s):s));return{edge:a.edgeId,segments:c,bends:We(g=>d=>g.end,c,It(1,c.length,c)),bendType:[],jumps:[],reversed:u}})(t)},JJ={layers:[],edges:[],chains:[]},bJ={nodeGap:3,layerGap:2,iterations:8,layerer:fJ,cycleBreaker:pT,compactPostRouting:!0,compactionSpacings:yv},CJ=t=>({pos:b(0,0),size:b(J(e=>n=>Kd(e)(n.position._1+n.size._1))(0)(t),J(e=>n=>Kd(e)(n.position._2+n.size._2))(0)(t))}),kJ=t=>e=>n=>{const r=ca(U(c=>b(c.id,c.ports))(e.nodes)),o=dt(c=>ze(3)(c.node)!=="$d:",n.placements),i=TJ(n.withDummies.chains)(n.acyclic.reversedEdges)(vJ(U(c=>b(c.id,b(c.from.node,c.to.node)))(e.edges)))(VT(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(Jd(n.ordered)(dt(c=>c.from.node!==c.to.node,n.withDummies.edges))((()=>{const c=g=>{if(g.tag==="Leaf")return F;if(g.tag==="Node")return oe("Node",g._1,g._2,g._3,b(g._4._1*4,g._4._2),c(g._5),c(g._6));f()};return c(ca(U(g=>b(g.id,g.size))(e.nodes)))})()))),a=t.compactPostRouting?Nv()(t.compactionSpacings)({nodes:o,edges:e.edges,paths:i,ports:r}):{nodes:o,edges:i},s=U(c=>{const g=aa(ia(c.segments));return{...c,segments:g,bends:We(d=>l=>d.end,g,It(1,g.length,g))}})(a.edges),u=qt(c=>g=>({...g,jumps:Hd(c)(g)(s)}))(s);return{nodes:a.nodes,edges:u,boundingBox:CJ(a.nodes),metrics:M1(a.nodes)(u)(0)}},Zd=t=>e=>n=>{const r=ca(U(i=>b(i.id,i.size))(e.nodes)),o={...n,placements:Zv({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(ca(U(i=>b(i.id,i.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(Jd(n.ordered)(n.withDummies.edges)((()=>{const i=a=>{if(a.tag==="Leaf")return F;if(a.tag==="Node")return oe("Node",a._1,a._2,a._3,b(a._4._1*4,a._4._2),i(a._5),i(a._6));f()};return i(r)})()))};return{pipeline:o,result:kJ(t)(e)(o)}},LJ=t=>e=>n=>Zd(t)(e)({...n,ordered:_T({iterations:t.iterations,constraints:e.constraints,modelOrder:ca(qt(r=>o=>b(o.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),SJ=t=>e=>n=>LJ(t)(e)({...n,withDummies:vv(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),EJ=t=>e=>{const n=U(o=>o.id)(e.nodes),r=vT(t.cycleBreaker)(n)(e.constraints)(e.edges);return SJ(t)(e)({acyclic:r,layered:xJ(t.layerer)(e.constraints)(r.edges)(n),withDummies:JJ,ordered:[],placements:[]})},wg=ge(A)(Mt),PJ=ge(A)(Mt),AJ=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},yr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},ga=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},zs=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},GJ=t=>e=>{const n=e.result.nodes,r=wg(U(s=>b(s.node,s))(n)),o=PJ(U(s=>b(s.id,s))(t.edges)),i=U(s=>{const u=AJ(s.edge)(o);if(u.tag==="Just"){const c=yr(u._1.from.node)(r);if(c.tag==="Just"){const g=yr(u._1.to.node)(r);if(g.tag==="Just"){if(c._1.layer>=g._1.layer||s.jumps.length!==0)return s;const d=et(4),l=c._1.position._1*d,_=(c._1.position._1+c._1.size._1)*d,h=g._1.position._1*d,p=(g._1.position._1+g._1.size._1)*d,m=ga(l)(h),y=zs(_)(p);if(m>y)return s;const x=(l+_)*.5,N=(h+p)*.5,T=zs(y)(ga(m)(c._1.size._1<=g._1.size._1?x:N)),C=(c._1.position._2+c._1.size._2)*d,L=g._1.position._2*d;return(()=>{const S=u._1.from.node,P=u._1.to.node;return le(M=>{const W=et(4);return M.node!==S&&M.node!==P&&T>M.position._1*W&&T<(M.position._1+M.size._1)*W&&M.position._2*W<L&&(M.position._2+M.size._2)*W>C},n)})()?s:{...s,segments:[{start:b(T,C),end:b(T,L),direction:me}],bends:[],bendType:[],jumps:[]}}if(g.tag==="Nothing")return s;f()}if(c.tag==="Nothing")return s;f()}if(u.tag==="Nothing")return s;f()})(e.result.edges),a=qt(s=>u=>({...u,jumps:Hd(s)(u)(i)}))(i);return{...e,result:{...e.result,edges:a,metrics:M1(e.result.nodes)(a)(e.result.metrics.constraintViolations)}}},IJ=t=>e=>n=>{const r=n.result.nodes,o=wg(U(a=>b(a.node,a))(r)),i=n.result.boundingBox.size._1;return wg(vt(a=>{const s=yr(a.id)(o);if(s.tag==="Just"){const u=yr(a.id)(n.pipeline.layered.nodeLayer);if(u.tag==="Just"){const c=u._1,g=vt(l=>{if(l.from.node===a.id){const _=yr(l.to.node)(n.pipeline.layered.nodeLayer);if(_.tag==="Just")return _._1<=c?w:yr(l.to.node)(o);if(_.tag==="Nothing")return w;f()}if(l.to.node===a.id){const _=yr(l.from.node)(n.pipeline.layered.nodeLayer);if(_.tag==="Just")return _._1>=c?w:yr(l.from.node)(o);if(_.tag==="Nothing")return w;f()}return w})(e.edges);if(g.length<2)return w;const d=Rt(l=>w,l=>_=>v("Just",{head:l,tail:_}),U(l=>l.position._1+l.size._1*.5)(g));if(d.tag==="Just"){const l=ga(a.size._1)(J(ga)(d._1.head)(d._1.tail)-J(zs)(d._1.head)(d._1.tail)+2),_=s._1.position._1,h=_+s._1.size._1,p=dt(m=>{const y=yr(m.node)(n.pipeline.layered.nodeLayer);return m.node!==a.id&&(y.tag==="Nothing"?!1:y.tag==="Just"&&y._1===c)},r);return l>a.size._1+.5&&l<=J(m=>y=>y.position._1>=h?zs(m)(y.position._1-et(t.nodeGap)):m)(i)(p)-J(m=>y=>y.position._1+y.size._1<=_?ga(m)(y.position._1+y.size._1+et(t.nodeGap)):m)(0)(p)?v("Just",b(a.id,b(l,a.size._2))):w}if(d.tag==="Nothing")return w;f()}if(u.tag==="Nothing")return w;f()}if(s.tag==="Nothing")return w;f()})(e.nodes))},DJ=t=>e=>{const n=EJ(t)(e),r=IJ(t)(e)(n),o=GJ(e)(Zd(t)({...e,nodes:U(i=>{const a=yr(i.id)(r);if(a.tag==="Just")return{...i,size:a._1};if(a.tag==="Nothing")return i;f()})(e.nodes)})(n.pipeline));return r.tag==="Leaf"||J(i=>a=>i+a.bends.length|0)(0)(o.result.edges)>=J(i=>a=>i+a.bends.length|0)(0)(n.result.edges)?n:o},tl=t=>t,el=tl("RunText"),RJ=tl("RunCode"),nl=t=>e=>n=>e.length===0?n:Ct(n)({style:t,text:Xr(e)}),BJ=t=>({style:(()=>{if(t.style==="RunText")return RJ;if(t.style==="RunCode")return el;f()})(),buf:[],runs:nl(t.style)(t.buf)(t.runs)}),FJ=t=>e=>0<e.length?{...t,buf:Ct(t.buf)(e[0])}:{...t,buf:Ct(t.buf)("\\")},MJ=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=Rt(u=>w,u=>c=>v("Just",{head:u,tail:c}),r);if(s.tag==="Nothing"){o=!1,i=a;continue}if(s.tag==="Just"){if(s._1.head==="\\"){n=FJ(a)(s._1.tail),r=It(1,s._1.tail.length,s._1.tail);continue}if(s._1.head==="`"){n=BJ(a),r=s._1.tail;continue}n={...a,buf:Ct(a.buf)(s._1.head)},r=s._1.tail;continue}f()}return i},rl=t=>{const e=MJ({style:el,buf:[],runs:[]})(Er(t));return nl(e.style)(e.buf)(e.runs)};let Ng=null;function zJ(){return Ng||(typeof document>"u"?null:(Ng=document.createElement("canvas").getContext("2d"),Ng))}const ol=new Map,QJ=t=>e=>n=>r=>()=>{const o=`${n} ${e}px ${t}|${r}`,i=ol.get(o);if(i!==void 0)return i;const a=zJ();if(!a)return r.length*e*.62;a.font=`${n} ${e}px ${t}`;const s=a.measureText(r).width;return ol.set(o,s),s},WJ=fo.traverse($u),OJ=J(sr)(0),ko=(()=>{const t=zn(`\r
|
|
5
|
+
`)(" "),e=zn(`
|
|
6
|
+
`)(" "),n=(()=>{const r=zn("\r")(" "),o=(()=>{const i=zn(" ")(" ");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),il=t=>e=>{const n=WJ(r=>{const o=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;f()})();return QJ(o.family)(o.size)(o.weight)(ko(r.text))})(rl(ko(e)));return()=>{const r=n();return OJ(r)}},al={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"}},qJ=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},vi=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},HJ=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},$J=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},UJ=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},sl=t=>Xr(ce(ar(e=>e===" ")(ce(ar(e=>e===" ")(Er(t)).rest)).rest)),VJ=t=>J(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?v("Just",n._1):e)(w)(qt(Bn)(t)),vg=t=>e=>{if(t<=0)return[e];if(gr(e)<=t)return[e];const n=Er(e),r=t<1?[]:It(0,t,n),o=VJ(r);if(o.tag==="Just"){const i=sl(L_(!(o._1>=0&&o._1<r.length)||r[o._1]===" "?o._1:o._1+1|0)(e)),a=sl(ii(o._1+1|0)(e));return a===""?[i]:[i,...vg(t)(a)]}if(o.tag==="Nothing"){const i=L_(t)(e),a=ii(t)(e);return a===""?[i]:[i,...vg(t)(a)]}f()},XJ={cellW:7,cellH:3,maxLineWidth:20},YJ=t=>e=>{const n=U(i=>b((()=>{if(i.label.tag==="Just")return i.label._1;if(i.label.tag==="Nothing")return i.id;f()})(),i))(e.nodes),r=vi(1)(kr((HJ(t.maxLineWidth)(J(i=>a=>vi(i)(gr(a._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),o=(r*t.cellW|0)-1|0;return{...e,nodes:U(i=>{if(!(i._2.size._1===1&&i._2.size._2===1))return i._2;const a=St(Gr(`
|
|
7
|
+
`)(i._1))(vg(o)),s=J(c=>g=>vi(c)(gr(g)))(0)(a),u=i._2.shape==="Cylinder"?vi(1)(kr((s+2|0)+t.cellW|0,t.cellW)):r;return{...i._2,size:b(et(s>o?kr((s+2|0)+t.cellW|0,t.cellW):u),et(vi(1)(kr(a.length+t.cellH|0,t.cellH))+(i._2.shape==="Cylinder"||i._2.shape==="Document"?1:0)|0))}})(n)}},KJ=t=>e=>n=>({...n,nodes:U(r=>{const o=UJ(r.id)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just")return{...r,size:b($J(r.size._1)(et(vi(1)(he(za(r.shape==="Cylinder"?(o._1+0)/t:(o._1+32)/t))))),r.size._2)};f()})(n.nodes)}),Qs=t=>t,jJ=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},Lo=Qs("TopSide"),So=Qs("BottomSide"),Eo=Qs("LeftSide"),Po=Qs("RightSide"),ZJ=t=>{const e=ot.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;f()})(),r=ot.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;f()},ul=t=>e=>n=>{const r=jJ(t.h*.12)(t.w*.2),o=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*Xe(ZJ((()=>{const i=(n-(t.x+o))/o;return 1-i*i})()))},an=t=>e=>n=>r=>{let o=t,i=e,a=n,s=r,u=!0,c;for(;u;){const g=o,d=i,l=a,_=s;if(g==="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=Yr,i=d,a=l,s=_;continue}if(g==="Cylinder"){if(l==="TopSide"){u=!1,c=ul(d)(-1)(_);continue}if(l==="BottomSide"){u=!1,c=ul(d)(1)(_);continue}if(l==="LeftSide"){u=!1,c=d.x;continue}if(l==="RightSide"){u=!1,c=d.x+d.w;continue}}o=Yr,i=d,a=l,s=_}return c},cl=t=>e=>{const n=e.y-t.y,r=n<0?-n:n,o=e.x-(t.x+t.w),i=o<0?-o:o,a=e.x-t.x,s=a<0?-a:a,u=e.y-(t.y+t.h),c=u<0?-u:u;return r<=c&&r<=s&&r<=i?Lo:c<=s&&c<=i?So:s<=i?Eo:Po},tb=(()=>{const t=fn.unfoldr(Xn);return e=>t(_n("IterNode",e,Un))})(),Tg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},fa=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},_a=ge(A)(Mt),eb=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},nb=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},rb=J(t=>e=>rt(A)(e)()(t))(F),ob=J(t=>e=>rt(A)(e)()(t))(F),Ws=fo.traverse($u),Os=ge(A)(Mt),ib=t=>e=>Oe(A.compare,Qe,t,e),ab=J(t=>e=>rt(A)(e)()(t))(F),sb=ge(A)(Mt),ub=t=>e=>Oe(A.compare,Qe,t,e),cb=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},gl=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},gb=t=>e=>({...e,edges:_a(U(n=>b(n._1,(()=>{const r=Tg(n._1)(t);if(r.tag==="Nothing")return n._2;if(r.tag==="Just"){const o=fa(r._1._2)(e.nodes),i=fa(r._1._1)(e.nodes),a=(()=>{if(i.tag==="Nothing")return n._2;if(i.tag==="Just"){const s=Rt(u=>w,u=>c=>v("Just",{head:u,tail:c}),n._2);if(s.tag==="Nothing")return n._2;if(s.tag==="Just")return[(()=>{const u=Rt(l=>w,l=>_=>v("Just",{head:l,tail:_}),s._1.tail),c=u.tag==="Just"?v("Just",u._1.head):w,g={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>s._1.head.x?c._1.x-s._1.head.x<.5:s._1.head.x-c._1.x<.5)&&s._1.head.x>=g.x-.5&&s._1.head.x<=g.x+g.w+.5)return c._1.y>=g.y+g.h?v("Just",So):c._1.y<=g.y?v("Just",Lo):w;if((c._1.y>s._1.head.y?c._1.y-s._1.head.y<.5:s._1.head.y-c._1.y<.5)&&s._1.head.y>=g.y-.5&&s._1.head.y<=g.y+g.h+.5){if(c._1.x>=g.x+g.w)return v("Just",Po);if(c._1.x<=g.x)return v("Just",Eo)}return w}if(c.tag==="Nothing")return w;f()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...s._1.head,y:an(i._1.shape)(g)(Lo)(s._1.head.x)};if(d._1==="BottomSide")return{...s._1.head,y:an(i._1.shape)(g)(So)(s._1.head.x)};if(d._1==="LeftSide")return{...s._1.head,x:an(i._1.shape)(g)(Eo)(s._1.head.y)};if(d._1==="RightSide")return{...s._1.head,x:an(i._1.shape)(g)(Po)(s._1.head.y)};f()}if(d.tag==="Nothing"){const l={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},_=cl(l)(s._1.head);if(_==="TopSide")return{...s._1.head,y:an(i._1.shape)(l)(Lo)(s._1.head.x)};if(_==="BottomSide")return{...s._1.head,y:an(i._1.shape)(l)(So)(s._1.head.x)};if(_==="LeftSide")return{...s._1.head,x:an(i._1.shape)(l)(Eo)(s._1.head.y)};if(_==="RightSide")return{...s._1.head,x:an(i._1.shape)(l)(Po)(s._1.head.y)}}f()})(),...s._1.tail]}f()})();if(o.tag==="Nothing")return a;if(o.tag==="Just"){const s=Sr(a);if(s.tag==="Nothing")return a;if(s.tag==="Just")return Ct(s._1.init)((()=>{const u=Sr(s._1.init),c=u.tag==="Just"?v("Just",u._1.last):w,g={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>s._1.last.x?c._1.x-s._1.last.x<.5:s._1.last.x-c._1.x<.5)&&s._1.last.x>=g.x-.5&&s._1.last.x<=g.x+g.w+.5)return c._1.y>=g.y+g.h?v("Just",So):c._1.y<=g.y?v("Just",Lo):w;if((c._1.y>s._1.last.y?c._1.y-s._1.last.y<.5:s._1.last.y-c._1.y<.5)&&s._1.last.y>=g.y-.5&&s._1.last.y<=g.y+g.h+.5){if(c._1.x>=g.x+g.w)return v("Just",Po);if(c._1.x<=g.x)return v("Just",Eo)}return w}if(c.tag==="Nothing")return w;f()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...s._1.last,y:an(o._1.shape)(g)(Lo)(s._1.last.x)};if(d._1==="BottomSide")return{...s._1.last,y:an(o._1.shape)(g)(So)(s._1.last.x)};if(d._1==="LeftSide")return{...s._1.last,x:an(o._1.shape)(g)(Eo)(s._1.last.y)};if(d._1==="RightSide")return{...s._1.last,x:an(o._1.shape)(g)(Po)(s._1.last.y)};f()}if(d.tag==="Nothing"){const l={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},_=cl(l)(s._1.last);if(_==="TopSide")return{...s._1.last,y:an(o._1.shape)(l)(Lo)(s._1.last.x)};if(_==="BottomSide")return{...s._1.last,y:an(o._1.shape)(l)(So)(s._1.last.x)};if(_==="LeftSide")return{...s._1.last,x:an(o._1.shape)(l)(Eo)(s._1.last.y)};if(_==="RightSide")return{...s._1.last,x:an(o._1.shape)(l)(Po)(s._1.last.y)}}f()})())}}f()})()))(tb(e.edges)))}),fb=t=>e=>n=>{const r=jt(o=>o.id===n)(t.graph.edges);if(r.tag==="Just")return v("Just",r._1);if(r.tag==="Nothing")return Tg(n)(e);f()},_b=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=fa(r.node)(e);if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return r.node;f()})(),shape:(()=>{const o=fa(r.node)(n);if(o.tag==="Nothing")return Yr;if(o.tag==="Just")return o._1;f()})()}),db=t=>({id:t,size:b(1,1),ports:[],label:v("Just",t),shape:Yr}),lb=t=>e=>n=>r=>b(r.node,_b(t)(e)(n)(r)),fl=t=>{const e=Gr(`
|
|
8
|
+
`)(t);return e.length===0?[""]:e},_l=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)));f()};return Zt(ye.foldr,e(t.interiors,V))},hb=t=>_a(vt(e=>v("Just",b(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"?v("Just",n.kind._1):w)(e._1.events):[]))),dl=t=>{const e=hy(t),n=dt(o=>eb(o.id)(e.nodes),t.graph.nodes),r=dt(o=>nb(o.id)(e.edges),t.graph.edges);return{nodes:[...n,...U(db)(Zt(dn.foldr,Vn(A.compare,e.nodes,rb(U(o=>o.id)(n)))))],edges:[...r,...vt(fb(t)(hb(t)))(Zt(dn.foldr,Vn(A.compare,e.edges,ob(U(o=>o.id)(r)))))],constraints:t.graph.constraints}},pb=t=>{const e=Ws(n=>{const r=il(al)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;f()})());return()=>{const o=r();return b(n.id,o)}})(dl(t).nodes);return()=>{const n=e();return Os(n)}},ll=t=>{const e=pb(t);return()=>{const n=e(),r=Ws(ll)(_l(t))();return J(ib)(n)(r)}},mb=t=>e=>{const n=Rt(r=>w,r=>o=>v("Just",{head:r,tail:o}),e.segments);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{x:n._1.head.start._1*t,y:n._1.head.start._2*t},...U(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];f()},yb=t=>e=>b(e.edge,mb(t)(e)),xb=t=>e=>n=>r=>({nodes:Os(U(lb(et(4)*t)(e)(n))(r.nodes)),edges:_a(U(yb(t))(r.edges)),chipExtras:F,edgeLabels:F}),wb=t=>e=>({...gb(_a(U(n=>b(n.id,b(n.from.node,n.to.node)))(e.edges)))(xb(8)(Os(U(n=>b(n.id,(()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;f()})()))(e.nodes)))(Os(U(n=>b(n.id,n.shape))(e.nodes)))(DJ(bJ)(e).result)),edgeLabels:_a(vt(n=>n.label.tag==="Just"?v("Just",b(n.id,n.label._1)):w)(e.edges))}),Nb=t=>J(e=>n=>{if(n.tag==="Structural")return e;if(n.tag==="DataFlow")return J(r=>o=>{if(o.kind.tag==="SendToken")return J(i=>a=>rt(A)(a)()(i))(r)(o.kind._1.labels);if(o.kind.tag==="FillNodeWithoutTransition")return J(i=>a=>rt(A)(a)()(i))(r)(o.kind._1.labels);f()})(e)(n._1.events);if(n.tag==="Hold"||n.tag==="EnterNode"||n.tag==="ExitNode"||n.tag==="StepScene")return e;f()})(F)(t.scenes),vb=t=>{const e=Ws(n=>{const r=il(al)(n);return()=>{const o=r();return b(n,{labelW:o,charCount:gr(ko(n)),lineCount:1})}})(Zt(dn.foldr,ab(St(Zt(dn.foldr,Nb(t)))(fl))));return()=>{const n=e();return sb(n)}},hl=t=>{const e=vb(t);return()=>{const n=e(),r=Ws(hl)(_l(t))();return J(ub)(n)(r)}},Tb=et(4)*8,Jb=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[];f()}),bb=t=>e=>n=>{const r=o=>{const i=vt(a=>{const s=cb(a)(t);return s.tag==="Just"?v("Just",{w:s._1.labelW+28,h:et(qJ(1)(s._1.lineCount))*13.2+12}):w})(St(o)(fl));return i.length===0?w:v("Just",{w:J(gl)(0)(U(a=>a.w)(i)),h:J(gl)(0)(U(a=>a.h)(i))})};return J(o=>i=>{if(i.kind.tag==="SendToken"){const a=Tg(i.kind._1.edge)(n.edges),s=r(i.kind._1.labels);if(s.tag==="Just"&&a.tag==="Just"){const u=s._1;return Ft(A)(xe)(i.kind._1.edge)(U(c=>({x:c.x+14+u.w,y:c.y-6-8-u.h}))(a._1))(o)}return o}if(i.kind.tag==="FillNodeWithoutTransition"){const a=fa(i.kind._1.node)(n.nodes),s=r(i.kind._1.labels);return s.tag==="Just"&&a.tag==="Just"?Ft(A)(xe)("__fill__:"+i.kind._1.node)((()=>{const u=a._1.y-s._1.h-14,c=a._1.x+a._1.w/2,g=c-s._1.w/2,d=c+s._1.w/2,l=a._1.y-14;return[{x:g,y:u},{x:d,y:u},{x:g,y:l},{x:d,y:l}]})())(o):o}f()})(F)(Jb(e))},pl=t=>e=>n=>({layout:(()=>{const r=wb()(KJ(Tb)(t)(YJ(XJ)(dl(n))));return{...r,chipExtras:bb(e)(n)(r)}})(),interiors:(()=>{const r=pl(t)(e),o=i=>{if(i.tag==="Leaf")return F;if(i.tag==="Node")return oe("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));f()};return o(n.interiors)})()}),ml=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Jg=t=>e=>n=>{const r=t<.05?t:.05,o=(a,s)=>{if(s.tag==="Leaf")return a;if(s.tag==="Node")return o((()=>{const u=ml(s._3)(n),c=(()=>{if(u.tag==="Just")return u._1;if(u.tag==="Nothing")return{x:s._4.x,y:s._4.y,vx:0,vy:0};f()})(),g=c.vx+(180*(s._4.x-c.x)-22*c.vx)*r,d=c.vy+(180*(s._4.y-c.y)-22*c.vy)*r;return rt(A)(s._3)({x:c.x+g*r,y:c.y+d*r,vx:g,vy:d})(o(a,s._5))})(),s._6);f()},i=o(F,e);return{springs:i,applied:(()=>{const a=(s,u)=>{if(u.tag==="Leaf")return s;if(u.tag==="Node")return a((()=>{const c=a(s,u._5),g=ml(u._3)(i);if(g.tag==="Just")return rt(A)(u._3)({...u._4,x:g._1.x,y:g._1.y})(c);if(g.tag==="Nothing")return rt(A)(u._3)(u._4)(c);f()})(),u._6);f()};return a(F,e)})()}},at=(t,e)=>({tag:"CatQueue",_1:t,_2:e}),Cb=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=at((i=>a=>{let s=i,u=a,c=!0,g;for(;c;){const d=s,l=u;if(l.tag==="Nil"){c=!1,g=d;continue}if(l.tag==="Cons"){s=kt("Cons",l._1,d),u=l._2;continue}f()}return g})(V)(o._2),V);continue}if(o._1.tag==="Cons"){n=!1,r=v("Just",b(o._1._1,at(o._1._2,o._2)));continue}f()}return r},st=(t,e,n)=>({tag:t,_1:e,_2:n}),ct=st("CatNil"),kb=t=>e=>{if(t.tag==="CatNil")return e;if(e.tag==="CatNil")return t;if(t.tag==="CatCons")return st("CatCons",t._1,at(t._2._1,kt("Cons",e,t._2._2)));f()},Lb=t=>e=>n=>{const r=o=>i=>a=>{let s=o,u=i,c=a,g=!0,d;for(;g;){const l=s,_=u,h=c;if(h.tag==="Nil"){g=!1,d=_;continue}if(h.tag==="Cons"){s=l,u=l(_)(h._1),c=h._2;continue}f()}return d};return(o=>i=>{let a=o,s=i,u=!0,c;for(;u;){const g=a,d=s,l=Cb(g);if(l.tag==="Nothing"){u=!1,c=r(_=>h=>h(_))(e)(d);continue}if(l.tag==="Just"){a=l._1._2,s=kt("Cons",t(l._1._1),d);continue}f()}return c})(n)(V)},Sb=t=>{if(t.tag==="CatNil")return w;if(t.tag==="CatCons")return v("Just",b(t._1,t._2._1.tag==="Nil"&&t._2._2.tag==="Nil"?ct:Lb(kb)(ct)(t._2)));f()},tt=(t,e)=>({tag:"Free",_1:t,_2:e}),ut=(t,e,n)=>({tag:t,_1:e,_2:n}),yl=t=>{let e=t,n=!0,r;for(;n;){const o=e;if(o._1.tag==="Return"){const i=Sb(o._2);if(i.tag==="Nothing"){n=!1,r=ut("Return",o._1._1);continue}if(i.tag==="Just"){e=(()=>{const a=i._1._1(o._1._1);return tt(a._1,(()=>{if(a._2.tag==="CatNil")return i._1._2;if(i._1._2.tag==="CatNil")return a._2;if(a._2.tag==="CatCons")return st("CatCons",a._2._1,at(a._2._2._1,kt("Cons",i._1._2,a._2._2._2)));f()})())})();continue}f()}if(o._1.tag==="Bind"){n=!1,r=ut("Bind",o._1._1,i=>{const a=o._1._2(i);return tt(a._1,(()=>{if(a._2.tag==="CatNil")return o._2;if(o._2.tag==="CatNil")return a._2;if(a._2.tag==="CatCons")return st("CatCons",a._2._1,at(a._2._2._1,kt("Cons",o._2,a._2._2._2)));f()})())});continue}f()}return r},Eb=t=>e=>{const n=e.Monad0(),r=n.Bind1().Apply0().Functor0();return o=>e.tailRecM(i=>{const a=yl(i);if(a.tag==="Return")return r.map(_m)(n.Applicative0().pure(a._1));if(a.tag==="Bind")return r.map(Uu)(o(t.map(a._2)(a._1)));f()})},Pb=t=>e=>n=>{const r=yl(n);if(r.tag==="Return")return e(r._1);if(r.tag==="Bind")return t(r._1)(r._2);f()},bg={Applicative0:()=>Ao,Bind1:()=>xl},Ab={map:t=>e=>xl.bind(e)(n=>Ao.pure(t(n)))},xl={bind:t=>e=>tt(t._1,(()=>{if(t._2.tag==="CatNil")return st("CatCons",e,at(V,V));if(t._2.tag==="CatCons")return st("CatCons",t._2._1,at(t._2._2._1,kt("Cons",st("CatCons",e,at(V,V)),t._2._2._2)));f()})()),Apply0:()=>wl},wl={apply:t=>e=>{const n=r=>tt(e._1,(()=>{if(e._2.tag==="CatNil")return st("CatCons",o=>Ao.pure(r(o)),at(V,V));if(e._2.tag==="CatCons")return st("CatCons",e._2._1,at(e._2._2._1,kt("Cons",st("CatCons",o=>Ao.pure(r(o)),at(V,V)),e._2._2._2)));f()})());return tt(t._1,(()=>{if(t._2.tag==="CatNil")return st("CatCons",n,at(V,V));if(t._2.tag==="CatCons")return st("CatCons",t._2._1,at(t._2._2._1,kt("Cons",st("CatCons",n,at(V,V)),t._2._2._2)));f()})())},Functor0:()=>Ab},Ao={pure:t=>tt(ut("Return",t),ct),Apply0:()=>wl},Gb=()=>()=>()=>t=>e=>n=>j0(n.type)(t)?Z0(n.type)(t)(n.value):e(n),Ib={map:t=>e=>({type:e.type,value:e.map(t)(e.value),map:e.map})},Db=t=>G_("Data.Functor.Variant: pattern match failure ["+t.type+"]"),Rb=()=>()=>()=>t=>Gb()()()(t)(Db);(function(){var t={},e="Pure",n="Throw",r="Catch",o="Sync",i="Async",a="Bind",s="Bracket",u="Fork",c="Sequential",g="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",y="Finalized",x="Forked";function N(E,Q,Y,H){this.tag=E,this._1=Q,this._2=Y,this._3=H}function T(E){var Q=function(Y,H,K){return new N(E,Y,H,K)};return Q.tag=E,Q}function C(E){return new N(e,void 0)}function L(E){try{E()}catch(Q){setTimeout(function(){throw Q},0)}}function S(E,Q,Y){try{return Q(Y())}catch(H){return E(H)}}function P(E,Q,Y){try{return Q(Y)()}catch(H){return Y(E(H))(),C}}var M=(function(){var E=1024,Q=0,Y=0,H=new Array(E),K=!1;function X(){var Z;for(K=!0;Q!==0;)Q--,Z=H[Y],H[Y]=void 0,Y=(Y+1)%E,Z();K=!1}return{isDraining:function(){return K},enqueue:function(Z){var nt;Q===E&&(nt=K,X(),K=nt),H[(Y+Q)%E]=Z,Q++,K||X()}}})();function W(E){var Q={},Y=0,H=0;return{register:function(K){var X=Y++;K.onComplete({rethrow:!0,handler:function(Z){return function(){H--,delete Q[X]}}})(),Q[X]=K,H++},isEmpty:function(){return H===0},killAll:function(K,X){return function(){if(H===0)return X();var Z=0,nt={};function gt(lt){nt[lt]=Q[lt].kill(K,function(Tt){return function(){delete nt[lt],Z--,E.isLeft(Tt)&&E.fromLeft(Tt)&&setTimeout(function(){throw E.fromLeft(Tt)},0),Z===0&&X()}})()}for(var bt in Q)Q.hasOwnProperty(bt)&&(Z++,gt(bt));return Q={},Y=0,H=0,function(lt){return new N(o,function(){for(var Tt in nt)nt.hasOwnProperty(Tt)&&nt[Tt]()})}}}}}var G=0,I=1,j=2,O=3,z=4,$=5,q=6;function D(E,Q,Y){var H=0,K=G,X=Y,Z=null,nt=null,gt=null,bt=null,lt=null,Tt=0,Et=0,te=null,Jt=!0;function Yt(ft){for(var pt,At,Gt;;)switch(pt=null,At=null,Gt=null,K){case j:K=I;try{X=gt(X),bt===null?gt=null:(gt=bt._1,bt=bt._2)}catch(Lt){K=$,Z=E.left(Lt),X=null}break;case O:E.isLeft(X)?(K=$,Z=X,X=null):gt===null?K=$:(K=j,X=E.fromRight(X));break;case I:switch(X.tag){case a:gt&&(bt=new N(_,gt,bt)),gt=X._2,K=I,X=X._1;break;case e:gt===null?(K=$,X=E.right(X._1)):(K=j,X=X._1);break;case o:K=O,X=S(E.left,E.right,X._1);break;case i:K=z,X=P(E.left,X._1,function(Lt){return function(){H===ft&&(H++,M.enqueue(function(){H===ft+1&&(K=O,X=Lt,Yt(H))}))}});return;case n:K=$,Z=E.left(X._1),X=null;break;case r:gt===null?lt=new N(_,X,lt,nt):lt=new N(_,X,new N(_,new N(h,gt,bt),lt,nt),nt),gt=null,bt=null,K=I,X=X._1;break;case s:Tt++,gt===null?lt=new N(_,X,lt,nt):lt=new N(_,X,new N(_,new N(h,gt,bt),lt,nt),nt),gt=null,bt=null,K=I,X=X._1;break;case u:K=O,pt=D(E,Q,X._2),Q&&Q.register(pt),X._1&&pt.run(),X=E.right(pt);break;case c:K=I,X=R(E,Q,X._1);break}break;case $:if(gt=null,bt=null,lt===null)K=q,X=nt||Z||X;else switch(pt=lt._3,Gt=lt._1,lt=lt._2,Gt.tag){case r:nt&&nt!==pt&&Tt===0?K=$:Z&&(K=I,X=Gt._2(E.fromLeft(Z)),Z=null);break;case h:nt&&nt!==pt&&Tt===0||Z?K=$:(gt=Gt._1,bt=Gt._2,K=j,X=E.fromRight(X));break;case s:Tt--,Z===null&&(At=E.fromRight(X),lt=new N(_,new N(p,Gt._2,At),lt,pt),(nt===pt||Tt>0)&&(K=I,X=Gt._3(At)));break;case p:lt=new N(_,new N(y,X,Z),lt,nt),K=I,nt&&nt!==pt&&Tt===0?X=Gt._1.killed(E.fromLeft(nt))(Gt._2):Z?X=Gt._1.failed(E.fromLeft(Z))(Gt._2):X=Gt._1.completed(E.fromRight(X))(Gt._2),Z=null,Tt++;break;case m:Tt++,lt=new N(_,new N(y,X,Z),lt,nt),K=I,X=Gt._1;break;case y:Tt--,K=$,X=Gt._1,Z=Gt._2;break}break;case q:for(var Nt in te)te.hasOwnProperty(Nt)&&(Jt=Jt&&te[Nt].rethrow,L(te[Nt].handler(X)));te=null,nt&&Z?setTimeout(function(){throw E.fromLeft(Z)},0):E.isLeft(X)&&Jt&&setTimeout(function(){if(Jt)throw E.fromLeft(X)},0);return;case G:K=I;break;case z:return}}function Dt(ft){return function(){if(K===q)return Jt=Jt&&ft.rethrow,ft.handler(X)(),function(){};var pt=Et++;return te=te||{},te[pt]=ft,function(){te!==null&&delete te[pt]}}}function yt(ft,pt){return function(){if(K===q)return pt(E.right(void 0))(),function(){};var At=Dt({rethrow:!1,handler:function(){return pt(E.right(void 0))}})();switch(K){case G:nt=E.left(ft),K=q,X=nt,Yt(H);break;case z:nt===null&&(nt=E.left(ft)),Tt===0&&(K===z&&(lt=new N(_,new N(m,X(ft)),lt,nt)),K=$,X=null,Z=null,Yt(++H));break;default:nt===null&&(nt=E.left(ft)),Tt===0&&(K=$,X=null,Z=null)}return At}}function ht(ft){return function(){var pt=Dt({rethrow:!1,handler:ft})();return K===G&&Yt(H),pt}}return{kill:yt,join:ht,onComplete:Dt,isSuspended:function(){return K===G},run:function(){K===G&&(M.isDraining()?Yt(H):M.enqueue(function(){Yt(H)}))}}}function B(E,Q,Y,H){var K=0,X={},Z=0,nt={},gt=new Error("[ParAff] Early exit"),bt=null,lt=t;function Tt(Dt,yt,ht){var ft=yt,pt=null,At=null,Gt=0,Nt={},Lt,Qt;t:for(;;)switch(Lt=null,ft.tag){case x:if(ft._3===t&&(Lt=X[ft._1],Nt[Gt++]=Lt.kill(Dt,function(ee){return function(){Gt--,Gt===0&&ht(ee)()}})),pt===null)break t;ft=pt._2,At===null?pt=null:(pt=At._1,At=At._2);break;case g:ft=ft._2;break;case d:case l:pt&&(At=new N(_,pt,At)),pt=ft,ft=ft._1;break}if(Gt===0)ht(E.right(void 0))();else for(Qt=0,Lt=Gt;Qt<Lt;Qt++)Nt[Qt]=Nt[Qt]();return Nt}function Et(Dt,yt,ht){var ft,pt,At,Gt,Nt,Lt;for(E.isLeft(Dt)?(ft=Dt,pt=null):(pt=Dt,ft=null);;){if(At=null,Gt=null,Nt=null,Lt=null,bt!==null)return;if(yt===null){H(ft||pt)();return}if(yt._3!==t)return;switch(yt.tag){case g:ft===null?(yt._3=E.right(yt._1(E.fromRight(pt))),pt=yt._3):yt._3=ft;break;case d:if(At=yt._1._3,Gt=yt._2._3,ft){if(yt._3=ft,Nt=!0,Lt=Z++,nt[Lt]=Tt(gt,ft===At?yt._2:yt._1,function(){return function(){delete nt[Lt],Nt?Nt=!1:ht===null?Et(ft,null,null):Et(ft,ht._1,ht._2)}}),Nt){Nt=!1;return}}else{if(At===t||Gt===t)return;pt=E.right(E.fromRight(At)(E.fromRight(Gt))),yt._3=pt}break;case l:if(At=yt._1._3,Gt=yt._2._3,At===t&&E.isLeft(Gt)||Gt===t&&E.isLeft(At))return;if(At!==t&&E.isLeft(At)&&Gt!==t&&E.isLeft(Gt))ft=pt===At?Gt:At,pt=null,yt._3=ft;else if(yt._3=pt,Nt=!0,Lt=Z++,nt[Lt]=Tt(gt,pt===At?yt._2:yt._1,function(){return function(){delete nt[Lt],Nt?Nt=!1:ht===null?Et(pt,null,null):Et(pt,ht._1,ht._2)}}),Nt){Nt=!1;return}break}ht===null?yt=null:(yt=ht._1,ht=ht._2)}}function te(Dt){return function(yt){return function(){delete X[Dt._1],Dt._3=yt,Et(yt,Dt._2._1,Dt._2._2)}}}function Jt(){var Dt=I,yt=Y,ht=null,ft=null,pt,At;t:for(;;)switch(pt=null,At=null,Dt){case I:switch(yt.tag){case g:ht&&(ft=new N(_,ht,ft)),ht=new N(g,yt._1,t,t),yt=yt._2;break;case d:ht&&(ft=new N(_,ht,ft)),ht=new N(d,t,yt._2,t),yt=yt._1;break;case l:ht&&(ft=new N(_,ht,ft)),ht=new N(l,t,yt._2,t),yt=yt._1;break;default:At=K++,Dt=$,pt=yt,yt=new N(x,At,new N(_,ht,ft),t),pt=D(E,Q,pt),pt.onComplete({rethrow:!1,handler:te(yt)})(),X[At]=pt,Q&&Q.register(pt)}break;case $:if(ht===null)break t;ht._1===t?(ht._1=yt,Dt=I,yt=ht._2,ht._2=t):(ht._2=yt,yt=ht,ft===null?ht=null:(ht=ft._1,ft=ft._2))}for(lt=yt,At=0;At<K;At++)X[At].run()}function Yt(Dt,yt){bt=E.left(Dt);var ht;for(var ft in nt)if(nt.hasOwnProperty(ft)){ht=nt[ft];for(ft in ht)ht.hasOwnProperty(ft)&&ht[ft]()}nt=null;var pt=Tt(Dt,lt,yt);return function(At){return new N(i,function(Gt){return function(){for(var Nt in pt)pt.hasOwnProperty(Nt)&&pt[Nt]();return C}})}}return Jt(),function(Dt){return new N(i,function(yt){return function(){return Yt(Dt,yt)}})}}function R(E,Q,Y){return new N(i,function(H){return function(){return B(E,Q,Y,H)}})}return N.EMPTY=t,N.Pure=T(e),N.Throw=T(n),N.Catch=T(r),N.Sync=T(o),N.Async=T(i),N.Bind=T(a),N.Bracket=T(s),N.Fork=T(u),N.Seq=T(c),N.ParMap=T(g),N.ParApply=T(d),N.ParAlt=T(l),N.Fiber=D,N.Supervisor=W,N.Scheduler=M,N.nonCanceler=C,N})();const Bb=t=>e=>Pb(n=>r=>t({type:n.type,value:n.map(o=>r(o))(n.value),map:n.map}))(e),Fb=t=>{const e=t.Bind1(),n=t.Applicative0().pure;return r=>{const o=Y0(()=>Bb(i=>e.bind(r(i))(o()))(n));return o()}};let Nl=null;function Mb(){return Nl||(typeof document>"u"?null:Nl=document.createElement("canvas").getContext("2d"))}const Cg=new Map;function vl(t,e,n,r,o,i){const a=`${n} ${e}px ${t}`,s=a+"|"+r;if(Cg.has(s))return Cg.get(s);const u=Mb();if(!u)return i;u.font=a;const c=o(u.measureText(r)),g=typeof document<"u"?document.fonts:null;if(!g||g.check(a))Cg.set(s,c);else if(g&&g.load)try{g.load(a)}catch{}return c}const zb=(t,e,n,r)=>vl(t,e,n,r,o=>o.width,-1),Qb=(t,e,n,r)=>vl(t,e,n,r,o=>({ascent:o.actualBoundingBoxAscent,descent:o.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),qs=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Tl=t=>t,Jl={map:t=>e=>{if(e.tag==="MeasureText")return qs("MeasureText",e._1,e._2,n=>t(e._3(n)));if(e.tag==="MeasureInk")return qs("MeasureInk",e._1,e._2,n=>t(e._3(n)));f()}},kg=t=>e=>{const n=zb(t.family,t.size,t.weight,ko(e));return n<0?et(ci(e).length)*t.size*.62:n},Lg=t=>e=>{const n=Qb(t.family,t.size,t.weight,ko(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},Wb=t=>e=>tt(ut("Bind",{type:"metrics",value:qs("MeasureInk",t,e,Tl),map:Jl.map},n=>tt(ut("Return",n),ct)),ct),da=t=>e=>tt(ut("Bind",{type:"metrics",value:qs("MeasureText",t,e,Tl),map:Jl.map},n=>tt(ut("Return",n),ct)),ct),bl=t=>t,Cl=t=>t,Hs=t=>t,kl=t=>t,Ll=t=>t,Ht=(t,e,n,r,o)=>({tag:t,_1:e,_2:n,_3:r,_4:o}),Sl=t=>t,Sg=t=>t,Ob=Sg("BaselineTop"),Gn=Sg("BaselineMiddle"),qb=Sg("BaselineBottom"),Ti=Sl("AlignLeft"),Br=Sl("AlignCenter"),$e=Ll("RoundJoin"),la=Ll("MiterJoin"),vn=kl("ButtCap"),Kn=kl("RoundCap"),Hb=Hs("LayerPolyOut"),$b=Hs("LayerPolyIn"),Ub=Hs("LayerNodeMask"),Vb=Hs("LayerOverlay"),Ji=Cl("NonZero"),Eg=Cl("EvenOdd"),El=bl("Normal"),$s=bl("Difference"),ve={r:255,g:255,b:255,a:255},ha=[5],Je={map:t=>e=>{if(e.tag==="FillPath")return Ht("FillPath",e._1,e._2,t(e._3));if(e.tag==="StrokePath")return Ht("StrokePath",e._1,e._2,t(e._3));if(e.tag==="FillStrokePath")return Ht("FillStrokePath",e._1,e._2,e._3,t(e._4));if(e.tag==="DrawText")return Ht("DrawText",e._1,t(e._2));if(e.tag==="DrawTextAffine")return Ht("DrawTextAffine",e._1,e._2,t(e._3));if(e.tag==="PushTransform")return Ht("PushTransform",e._1,t(e._2));if(e.tag==="PopTransform")return Ht("PopTransform",t(e._1));if(e.tag==="PushClip")return Ht("PushClip",e._1,e._2,t(e._3));if(e.tag==="PopClip")return Ht("PopClip",t(e._1));if(e.tag==="PushBlend")return Ht("PushBlend",e._1,t(e._2));if(e.tag==="PopBlend")return Ht("PopBlend",t(e._1));if(e.tag==="PushAlpha")return Ht("PushAlpha",e._1,t(e._2));if(e.tag==="PopAlpha")return Ht("PopAlpha",t(e._1));if(e.tag==="PushBlur")return Ht("PushBlur",e._1,t(e._2));if(e.tag==="PopBlur")return Ht("PopBlur",t(e._1));if(e.tag==="PushLayer")return Ht("PushLayer",e._1,t(e._2));if(e.tag==="PopLayer")return Ht("PopLayer",t(e._1));if(e.tag==="SetViewport")return Ht("SetViewport",e._1,t(e._2));if(e.tag==="ClearBackground")return Ht("ClearBackground",e._1,t(e._2));if(e.tag==="BackgroundDots")return Ht("BackgroundDots",e._1,t(e._2));f()}},Fr={r:26,g:26,b:26,a:255},Pg=t=>e=>Math.imul(t,e),bi=t=>{const e=t+1831565813|0,n=Pg(e^e>>>15)(e|1),r=n^(n+Pg(n^n>>>7)(n|61)|0),o=r^r>>>14;return{prng:o,value:o<0?(et(o)+4294967296)/4294967296:et(o)/4294967296}},De=t=>e=>n=>{const r=bi(n);return{prng:r.prng,value:t+r.value*(e-t)}},Ag=t=>e=>J(n=>r=>Pg(n^r)(-2048144789))(e)(U(to)(Er(t))),Xb=t=>t,Pl=t=>t,Yb=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Tn=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},Al=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;f()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},Gg=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Kb=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;f()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},jb=Pl("FlatLevel"),Zb=Pl("NestedLevel"),Ig=Xb("GenieSilhouette"),tC=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const o=bi(t);return{prng:o.prng,yLift:o.value*n.yJitter*r}},eC=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const o=bi(t);return{prng:o.prng,dx:(o.value*2-1)*n.xJitter*r}},Gl=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,o=Xe(r*r+n*n),i=(t.r*t.r-e.r*e.r+o*o)/(2*o),a=Xe(Yb(0)(t.r*t.r-i*i)),s=t.cx+i*r/o,u=t.cy+i*n/o,c={x:s-a*n/o,y:u+a*r/o},g={x:s+a*n/o,y:u-a*r/o};return o===0||o>t.r+e.r?{x:(t.cx+e.cx)/2,y:t.cy}:c.y<g.y?c:g},Ci=t=>e=>{const n=Tn(e)(Tn(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=>e=>n=>r=>o=>i=>{if(e)return{prng:t,r:o};if(n)return{prng:t,r:o*(1+i.rJitter)};if(r)return{prng:t,r:o*i.smallScale};const a=bi(t);return{prng:a.prng,r:o*(1+a.value*i.rJitter)}},Il=t=>{const e=Tn(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]},rC=t=>e=>n=>{const r=bi(t),o=e.length;return o===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const i=Al(0)(o-1|0)(he(Fn(r.value*et(n))));return i>=0&&i<e.length?e[i]:-1})()}},oC=t=>e=>{const n=bi(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const o=Al(0)(r-1|0)(he(Fn(n.value*et(r))));return o>=0&&o<e.length?e[o]:-1})()}},Dl=t=>{const e=Tn(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]},Rl=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],Bl={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},iC=t=>{const e=Tn(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]},Fl=t=>{const e=Tn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+t.h+5,o=t.y+e,i=r-e,a=t.x+n;return[1,t.x,o,4,t.x,o-.5522847498*e,a-.5522847498*n,t.y,a,t.y,4,a+.5522847498*n,t.y,t.x+t.w,o-.5522847498*e,t.x+t.w,o,2,t.x+t.w,i,4,t.x+t.w,i+.5522847498*e,a+.5522847498*n,r,a,r,4,a-.5522847498*n,r,t.x,i+.5522847498*e,t.x,i,5]},Ml=t=>e=>{const n=e.y+e.h,r=Hm(t.rBase*e.h)(e.w/(2*(1+(et(t.minN)-1)*t.stepRatio))),o=e.w-2*r,i=2*r*t.stepRatio,a=Gg(t.minN)(o<=0||i<=0?t.minN:he($n(o/i))+1|0),s=a>=3?Kt(1,a-2|0):[],u=s.length,c=kr(u+1|0,2),g=c<1?[]:It(0,c,s),d=oC(t.seed)((()=>{const m=u-c|0;return m<1?s:It(m,s.length,s)})()),l=d.idx,_=rC(d.prng)(dt(m=>m!==l,g))(Gg(1)(g.length-(nn($r)(l)(g)?1:0)|0)),h=_.idx,p=a>=2?o/(et(a)-1):0;return J(m=>y=>{const x=y===h,N=y===l,T=y===0||y===(a-1|0),C=nC(m.prng)(T)(N)(x)(r)(t),L=tC(C.prng)(T)(t)(e.h),S=eC(L.prng)(T)(t)(p);return{prng:S.prng,circles:Ct(m.circles)({cx:e.x+Kb(C.r)(e.w-C.r)((a>=2?r+et(y)/(et(a)-1)*o+S.dx:r+0*o+S.dx)+(N?t.heroShift*p:x?-1*t.smallShift*p:0)),cy:n-L.yLift,r:C.r})}})({prng:_.prng,circles:[]})(Kt(0,a-1|0)).circles},zl=t=>e=>{const n=t.length;return qt(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?Gl(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?Gl(o)(t[i]):{x:o.cx+o.r,y:e}})()}))(t)},Ql=t=>{const e=Tn(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]},aC=t=>e=>n=>{const r=_o(e.y-t.cy)(e.x-t.cx),o=_o(n.y-t.cy)(n.x-t.cx),i=o>r?o-r:o+6.283185307179586-r,a=Gg(1)(he(za(i/1.5707963267948966))),s=i/et(a),u=1.3333333333333333*$m(s/4);return St(Kt(0,a-1|0))(c=>{const g=r+et(c+1|0)*s,d=t.cx+t.r*Sn(g),l=t.cy+t.r*yn(g),_=r+et(c)*s;return[4,t.cx+t.r*Sn(_)-u*t.r*yn(_),t.cy+t.r*yn(_)+u*t.r*Sn(_),d+u*t.r*yn(g),l-u*t.r*Sn(g),d,l]})},Wl=t=>e=>{const n=t.h*.38,r=zl(Ml(Bl)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),o=Tn(e)(Tn(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...St(r)(i=>aC(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]:Ci(t)(e)},Dg=t=>e=>n=>r=>o=>i=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(o)(i);if(e==="Cylinder"){const a=Fl(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);f()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}f()}if(e==="Parallelogram"){const a=Dl(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);f()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}f()}if(e==="Diamond"){const a=Ql(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);f()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}f()}if(e==="Ellipse"){const a=Il(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);f()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}f()}if(e==="Document"){const a=Rl(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);f()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}f()}if(e==="Cloud"){const a=Wl(n)(r);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(a)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(a)(o._1);f()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}f()}return t.drawRoundedRect(n)(r)(o)(i)},sC={fillPath:t=>e=>tt(ut("Bind",{type:"render",value:Ht("FillPath",t,e,void 0),map:Je.map},n=>tt(ut("Return",n),ct)),ct),strokePath:t=>e=>tt(ut("Bind",{type:"render",value:Ht("StrokePath",t,e,void 0),map:Je.map},n=>tt(ut("Return",n),ct)),ct),fillStrokePath:t=>e=>n=>tt(ut("Bind",{type:"render",value:Ht("FillStrokePath",t,e,n,void 0),map:Je.map},r=>tt(ut("Return",r),ct)),ct),drawRoundedRect:t=>e=>n=>r=>{if(n.tag==="Just"){if(r.tag==="Just")return tt(ut("Bind",{type:"render",value:Ht("FillStrokePath",Ci(t)(e),n._1,r._1,void 0),map:Je.map},o=>tt(ut("Return",o),ct)),ct);if(r.tag==="Nothing")return tt(ut("Bind",{type:"render",value:Ht("FillPath",Ci(t)(e),n._1,void 0),map:Je.map},o=>tt(ut("Return",o),ct)),ct);f()}if(n.tag==="Nothing"){if(r.tag==="Just")return tt(ut("Bind",{type:"render",value:Ht("StrokePath",Ci(t)(e),r._1,void 0),map:Je.map},o=>tt(ut("Return",o),ct)),ct);if(r.tag==="Nothing")return tt(ut("Return",void 0),ct)}f()},drawText:t=>tt(ut("Bind",{type:"render",value:Ht("DrawText",t,void 0),map:Je.map},e=>tt(ut("Return",e),ct)),ct),drawTextAffine:t=>e=>tt(ut("Bind",{type:"render",value:Ht("DrawTextAffine",t,e,void 0),map:Je.map},n=>tt(ut("Return",n),ct)),ct),pushTransform:t=>tt(ut("Bind",{type:"render",value:Ht("PushTransform",t,void 0),map:Je.map},e=>tt(ut("Return",e),ct)),ct),popTransform:tt(ut("Bind",{type:"render",value:Ht("PopTransform",void 0),map:Je.map},t=>tt(ut("Return",t),ct)),ct),pushBakedTransform:t=>tt(ut("Bind",{type:"render",value:Ht("PushTransform",t,void 0),map:Je.map},e=>tt(ut("Return",e),ct)),ct),popBakedTransform:tt(ut("Bind",{type:"render",value:Ht("PopTransform",void 0),map:Je.map},t=>tt(ut("Return",t),ct)),ct),pushClip:t=>e=>tt(ut("Bind",{type:"render",value:Ht("PushClip",t,e,void 0),map:Je.map},n=>tt(ut("Return",n),ct)),ct),popClip:tt(ut("Bind",{type:"render",value:Ht("PopClip",void 0),map:Je.map},t=>tt(ut("Return",t),ct)),ct),pushBlend:t=>tt(ut("Bind",{type:"render",value:Ht("PushBlend",t,void 0),map:Je.map},e=>tt(ut("Return",e),ct)),ct),popBlend:tt(ut("Bind",{type:"render",value:Ht("PopBlend",void 0),map:Je.map},t=>tt(ut("Return",t),ct)),ct),pushAlpha:t=>tt(ut("Bind",{type:"render",value:Ht("PushAlpha",t,void 0),map:Je.map},e=>tt(ut("Return",e),ct)),ct),popAlpha:tt(ut("Bind",{type:"render",value:Ht("PopAlpha",void 0),map:Je.map},t=>tt(ut("Return",t),ct)),ct),pushBlur:t=>tt(ut("Bind",{type:"render",value:Ht("PushBlur",t,void 0),map:Je.map},e=>tt(ut("Return",e),ct)),ct),popBlur:tt(ut("Bind",{type:"render",value:Ht("PopBlur",void 0),map:Je.map},t=>tt(ut("Return",t),ct)),ct),pushLayer:t=>tt(ut("Bind",{type:"render",value:Ht("PushLayer",t,void 0),map:Je.map},e=>tt(ut("Return",e),ct)),ct),popLayer:tt(ut("Bind",{type:"render",value:Ht("PopLayer",void 0),map:Je.map},t=>tt(ut("Return",t),ct)),ct),setViewport:t=>tt(ut("Bind",{type:"render",value:Ht("SetViewport",t,void 0),map:Je.map},e=>tt(ut("Return",e),ct)),ct),clearBackground:t=>tt(ut("Bind",{type:"render",value:Ht("ClearBackground",t,void 0),map:Je.map},e=>tt(ut("Return",e),ct)),ct),backgroundDots:t=>tt(ut("Bind",{type:"render",value:Ht("BackgroundDots",t,void 0),map:Je.map},e=>tt(ut("Return",e),ct)),ct),measureText:t=>e=>da(t)(e),measureInk:t=>e=>Wb(t)(e),insideTokenStyle:t=>tt(ut("Return",Ig),ct),Monad0:()=>bg},uC=t=>()=>t.clip("evenodd"),cC=t=>e=>()=>{t.filter=`blur(${e}px)`},gC=t=>e=>()=>{const n=e>0?t.canvas.width/e:1;t.setTransform(n,0,0,n,0,0)},fC=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)},_C=t=>e=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(e.tile,.001))),r=Math.max(2,Math.round(e.tile*n)),o=document.createElement("canvas");o.width=r,o.height=r;const i=o.getContext("2d");i.scale(n,n),i.fillStyle=e.bgCss,i.fillRect(0,0,e.tile,e.tile),i.fillStyle=e.dotCss,i.beginPath(),i.arc(e.tile/2,e.tile/2,e.dotR,0,2*Math.PI),i.fill();const a=t.createPattern(o,"repeat");a&&typeof a.setTransform=="function"&&a.setTransform(new DOMMatrix().translateSelf(e.ox,e.oy).scaleSelf(1/n,1/n)),t.save(),t.fillStyle=a,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},Rg=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},Bg=t=>e=>n=>{const r=e.stroke;return()=>{const o=r.value,i=f2(t)(n);if(o!==n)return i(),e.stroke.value=n}},dC=t=>e=>n=>{const r=e.font;return()=>{const o=r.value,i=w2(t)(n);if(o!==n)return i(),e.font.value=n}},pa=t=>e=>n=>{const r=e.fill;return()=>{const o=r.value,i=g2(t)(n);if(o!==n)return i(),e.fill.value=n}},Us=t=>e=>{const n=e.length,r=i=>{if(i>=n)return()=>{};const a=i>=0&&i<e.length?e[i]:0;if(a===1){const s=v_(t)((()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})()),u=r(i+3|0);return()=>(s(),u())}if(a===2){const s=zi(t)((()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})()),u=r(i+3|0);return()=>(s(),u())}if(a===3){const s=Qi(t)({cpx:(()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})(),cpy:(()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=i+3|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=i+4|0;return c>=0&&c<e.length?e[c]:0})()}),u=r(i+5|0);return()=>(s(),u())}if(a===4){const s=v2(t)({cp1x:(()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})(),cp1y:(()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})(),cp2x:(()=>{const c=i+3|0;return c>=0&&c<e.length?e[c]:0})(),cp2y:(()=>{const c=i+4|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=i+5|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=i+6|0;return c>=0&&c<e.length?e[c]:0})()}),u=r(i+7|0);return()=>(s(),u())}if(a===5){const s=T_(t),u=r(i+1|0);return()=>(s(),u())}return()=>{}},o=N_(t);return()=>(o(),r(0)())},lC=t=>e=>n=>r=>o=>i=>{const a=Rg(i)(Rg(r/2)(o/2)),s=v_(t)(e+a)(n);return()=>(s(),zi(t)(e+r-a)(n)(),Qi(t)({cpx:e+r,cpy:n,x:e+r,y:n+a})(),zi(t)(e+r)(n+o-a)(),Qi(t)({cpx:e+r,cpy:n+o,x:e+r-a,y:n+o})(),zi(t)(e+a)(n+o)(),Qi(t)({cpx:e,cpy:n+o,x:e,y:n+o-a})(),zi(t)(e)(n+a)(),Qi(t)({cpx:e,cpy:n,x:e+a,y:n})(),T_(t)())},hC=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),Ol=t=>e=>{const n=p2(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=hC();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0},groupAlpha:{value:1},alphaSaves:{value:[]}}}},pC={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},mC=t=>ue(t.weight)+" "+go(t.size)+"px "+t.family,xr=t=>{const e=go(et(t.a)/255);return t.a>=255?"rgb("+ue(t.r)+","+ue(t.g)+","+ue(t.b)+")":"rgba("+ue(t.r)+","+ue(t.g)+","+ue(t.b)+","+e+")"},yC=t=>e=>n=>r=>{const o=ur(t);return()=>(o(),gC(t)(e.width)(),pa(t)(n)(xr(r))(),h2(t)({x:0,y:0,width:e.width,height:e.height})(),cr(t)(),n.font.value="",n.fill.value="",n.stroke.value="")},xC=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",_C(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:xr(n.bgColor),dotCss:xr(n.dotColor),tile:n.tile,dotR:n.dotRadius,ox:n.origin.x,oy:n.origin.y})())},wC=t=>e=>n=>r=>{const o=pa(t)(e)(xr(r));return()=>(o(),Us(t)(n)(),oc(t)())},NC=t=>e=>n=>r=>o=>{const i=pa(t)(e)(xr(r));return()=>(i(),Bg(t)(e)(xr(o.color))(),tc(t)(o.width)(),lc(t)((()=>{if(o.lineJoin==="RoundJoin")return cc;if(o.lineJoin==="BevelJoin")return uc;if(o.lineJoin==="MiterJoin")return gc;f()})())(),hc(t)((()=>{if(o.lineCap==="ButtCap")return dc;if(o.lineCap==="RoundCap")return fc;if(o.lineCap==="SquareCap")return _c;f()})())(),Us(t)(n)(),oc(t)(),rc(t)())},vC=t=>e=>n=>r=>o=>i=>{const a=N_(t);return()=>{if(a(),lC(t)(n.x)(n.y)(n.w)(n.h)(r)(),o.tag==="Just"?(pa(t)(e)(xr(o._1.color))(),oc(t)()):o.tag==="Nothing"||f(),i.tag==="Just")return Bg(t)(e)(xr(i._1.color))(),tc(t)(i._1.width)(),lc(t)((()=>{if(i._1.lineJoin==="RoundJoin")return cc;if(i._1.lineJoin==="BevelJoin")return uc;if(i._1.lineJoin==="MiterJoin")return gc;f()})())(),hc(t)((()=>{if(i._1.lineCap==="ButtCap")return dc;if(i._1.lineCap==="RoundCap")return fc;if(i._1.lineCap==="SquareCap")return _c;f()})())(),rc(t)();i.tag!=="Nothing"&&f()}},TC=t=>e=>n=>r=>{const o=Bg(t)(e)(xr(r.color));return()=>(o(),tc(t)(r.width)(),lc(t)((()=>{if(r.lineJoin==="RoundJoin")return cc;if(r.lineJoin==="BevelJoin")return uc;if(r.lineJoin==="MiterJoin")return gc;f()})())(),hc(t)((()=>{if(r.lineCap==="ButtCap")return dc;if(r.lineCap==="RoundCap")return fc;if(r.lineCap==="SquareCap")return _c;f()})())(),Us(t)(n)(),rc(t)())},ql=t=>e=>n=>{const r=pa(t)(e)(xr(n.color));return()=>(r(),dC(t)(e)(mC(n.font))(),G2(t)((()=>{if(n.align==="AlignLeft")return k2;if(n.align==="AlignCenter")return S2;if(n.align==="AlignRight")return L2;f()})())(),A2(t)((()=>{if(n.baseline==="BaselineTop")return T2;if(n.baseline==="BaselineMiddle")return J2;if(n.baseline==="BaselineAlphabetic")return b2;if(n.baseline==="BaselineBottom")return C2;f()})())(),N2(t)(n.content)(n.x)(n.y)())},Hl={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),a=o();return i(a)}},Functor0:()=>pC},JC={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>Hl},bC=t=>e=>n=>{const r=Rg(e.width/n.vw)(e.height/n.vh);return fC(t)(e.width)(r)((e.width-n.vw*r)/2-n.vx*r)((e.height-n.vh*r)/2-n.vy*r)},CC={pure:t=>e=>()=>t,Apply0:()=>Hl},$l={Applicative0:()=>CC,Bind1:()=>JC},Fg={fillPath:t=>e=>n=>{const r=wC(n.ctx)(n.styleCache)(t)(e.color),o=n.maskDepth;return()=>{if(o.value===0)return r()}},strokePath:t=>e=>n=>{const r=TC(n.ctx)(n.styleCache)(t)(e),o=n.maskDepth;return()=>{if(o.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const o=NC(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=vC(o.ctx)(o.styleCache)(t)(e)(n)(r),a=o.maskDepth;return()=>{if(a.value===0)return i()}},drawText:t=>e=>{const n=ql(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=ur(n.ctx),o=n.maskDepth;return()=>{if(o.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",m2(n.ctx)(t)(),ql(n.ctx)(n.styleCache)(e)(),cr(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=ur(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",J_(e.ctx)({translateX:t.tx,translateY:t.ty})(),qa(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=cr(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=ur(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",J_(e.ctx)({translateX:t.tx,translateY:t.ty})(),qa(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=cr(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=ur(n.ctx),o=n.maskDepth;return()=>{if(o.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Us(n.ctx)(t)(),e==="NonZero")return l2(n.ctx)();if(e==="EvenOdd")return uC(n.ctx)();f()}}},popClip:t=>{const e=cr(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=ur(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){if(n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",t==="Normal")return C_(e.ctx)(E2)();if(t==="Difference")return C_(e.ctx)(P2)();f()}}},popBlend:t=>{const e=cr(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=ur(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="";const o=e.groupAlpha.value,i=e.alphaSaves.value;e.alphaSaves.value=[...i,o];const a=o*t;return e.groupAlpha.value=a,d2(e.ctx)(a)()}}},popAlpha:t=>{const e=cr(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=Sr(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;f()}}},pushBlur:t=>e=>{const n=ur(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=cC(e.ctx)(t);if(t>=.01)return o()}}},popBlur:t=>{const e=cr(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=bC(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=yC(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=xC(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=kg(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Lg(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Ig,Monad0:()=>$l},kC=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},ki=t=>e=>n=>{const r=kC(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},Mg=t=>{const e=ot.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;f()})(),r=ot.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;f()},LC=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:Mg(t._2)};if(t._1==="ExtendFromTarget")return{lo:1-t._2,hi:1};f()}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}}f()},ro=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:Vi(8)(.6)(Mg(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:Vi(8)(.6)(Mg(1-t._1))};f()};function SC(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function EC(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:SC(o,i)}}return n}function PC(t,e,n){let r=0;for(let o=0;o<t.length;o++){const i=t[o],a=r,s=a+i.len;if(n<=s){const u=i.len>1e-6?(n-a)/i.len:0;return{x:i.a.x+(i.b.x-i.a.x)*u,y:i.a.y+(i.b.y-i.a.y)*u}}r=s}return e.length>0?e[e.length-1]:{x:0,y:0}}function Ul(t,e){if(e.length===0)return[];const n=EC(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]=PC(n,e,i*r/t);return o}function AC(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 GC(t,e){const n=e.length;if(n===0)return e;let r=0,o=1/0;for(let i=0;i<n;i++){let a=0;for(let s=0;s<n;s++){const u=t[s]||{x:0,y:0},c=e[(s+i)%n]||{x:0,y:0},g=u.x-c.x,d=u.y-c.y;a+=g*g+d*d}a<o&&(o=a,r=i)}return AC(r,e)}const Vl=t=>e=>n=>{const r=Ul(t,e),o=Ul(t,n),i=GC(r,o);return{from:r,to:i}};function Xl(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 IC(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 DC(t,e){const n=e.length;if(n===0)return e;const r=new Array(n);for(let o=0;o<n;o++){const i=e[((o-1)%n+n)%n],a=e[((o+1)%n+n)%n],s=e[o];r[o]={x:s.x+((i.x+a.x)/2-s.x)*t,y:s.y+((i.y+a.y)/2-s.y)*t}}return r}function RC(t){return t<0?0:t>1?1:t}const Yl=t=>e=>n=>r=>{const o=e.length;if(o===0)return[];const i=Xl(e),a=Xl(n),s=IC(i,a),u=new Array(o);let c=1/0,g=-1/0;for(let _=0;_<o;_++){const h=e[_],p=(h.x-i.x)*s.x+(h.y-i.y)*s.y;u[_]=p,p<c&&(c=p),p>g&&(g=p)}const d=g-c;let l=new Array(o);for(let _=0;_<o;_++){const h=e[_],p=n[_];if(p===void 0){l[_]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(u[_]-c)/d),y=Math.max(1e-4,1-m),x=RC((t-m)/y),N=x*x*(3-2*x);l[_]={x:h.x+(p.x-h.x)*N,y:h.y+(p.y-h.y)*N}}for(let _=0;_<r.smoothPasses;_++)l=DC(.5,l);return l},Kl=(t,e)=>({tag:t,_1:e}),jl=(t,e)=>({tag:t,_1:e}),Ee=(t,e,n)=>({tag:t,_1:e,_2:n}),Zl=t=>t,ma=(t,e)=>({tag:t,_1:e}),ya=(t,e)=>({tag:t,_1:e}),Vs=t=>t,Xs=(t,e)=>({tag:t,_1:e}),Pe=(t,e,n)=>({tag:t,_1:e,_2:n}),Go=(t,e)=>({tag:t,_1:e}),xa=(t,e)=>({tag:t,_1:e}),th=(t,e)=>({tag:t,_1:e}),eh=t=>t,nh=(t,e)=>({tag:t,_1:e}),Io=(t,e,n)=>({tag:t,_1:e,_2:n}),rh=t=>t,BC=t=>t,Do=rh("NormalTransform"),FC=rh("BakedTransform"),oh=eh("TokenOutside"),ih=eh("TokenInside"),Ys=xa("PlainText"),ah=Go("FrameTitle"),MC=Go("Watermark"),zC=Vs("NodeShadow"),QC=Vs("NodeDoorwayFrame"),zg=Vs("NodeBody"),WC=Vs("NodeInversion"),Qg=Zl("LabelsShown"),wa=Zl("LabelsHidden"),qn={map:t=>e=>{if(e.tag==="BeginFrame")return Pe("BeginFrame",e._1,t(e._2));if(e.tag==="EndFrame")return Pe("EndFrame",t(e._1));if(e.tag==="BeginGroup")return Pe("BeginGroup",e._1,t(e._2));if(e.tag==="EndGroup")return Pe("EndGroup",e._1,t(e._2));if(e.tag==="Background")return Pe("Background",e._1,t(e._2));if(e.tag==="Overlay")return Pe("Overlay",e._1,t(e._2));if(e.tag==="Node")return Pe("Node",e._1,t(e._2));if(e.tag==="Edge")return Pe("Edge",e._1,t(e._2));if(e.tag==="Text")return Pe("Text",e._1,t(e._2));if(e.tag==="Token")return Pe("Token",e._1,t(e._2));if(e.tag==="AskInsideTokenStyle")return Pe("AskInsideTokenStyle",e._1,n=>t(e._2(n)));f()}},sh=t=>e=>da(t)(e),OC=t=>{const e=t.Bind1().Apply0().Functor0(),n=Fb(t);return r=>o=>n(Rb()()()({scene:i=>{if(i.tag==="BeginFrame"){const a=i._2;return e.map(s=>a)(r.beginFrame(i._1))}if(i.tag==="EndFrame"){const a=i._1;return e.map(s=>a)(r.endFrame)}if(i.tag==="BeginGroup"){const a=i._2;return e.map(s=>a)(r.beginGroup(i._1))}if(i.tag==="EndGroup"){const a=i._2;return e.map(s=>a)(r.endGroup(i._1))}if(i.tag==="Background"){const a=i._2;return e.map(s=>a)(r.background(i._1))}if(i.tag==="Overlay"){const a=i._2;return e.map(s=>a)(r.overlay(i._1))}if(i.tag==="Node"){const a=i._2;return e.map(s=>a)(r.node(i._1))}if(i.tag==="Edge"){const a=i._2;return e.map(s=>a)(r.edge(i._1))}if(i.tag==="Text"){const a=i._2;return e.map(s=>a)(r.text(i._1))}if(i.tag==="Token"){const a=i._2;return e.map(s=>a)(r.token(i._1))}if(i.tag==="AskInsideTokenStyle")return e.map(i._2)(r.insideTokenStyle(i._1));f()},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));f()}}))(o)},qC=t=>tt(ut("Bind",{type:"scene",value:Pe("AskInsideTokenStyle",t,BC),map:qn.map},e=>tt(ut("Return",e),ct)),ct),uh=t=>tt(ut("Bind",{type:"scene",value:Pe("Background",t,void 0),map:qn.map},e=>tt(ut("Return",e),ct)),ct),ch=t=>tt(ut("Bind",{type:"scene",value:Pe("Edge",t,void 0),map:qn.map},e=>tt(ut("Return",e),ct)),ct),Na=t=>tt(ut("Bind",{type:"scene",value:Pe("Node",t,void 0),map:qn.map},e=>tt(ut("Return",e),ct)),ct),Ks=t=>tt(ut("Bind",{type:"scene",value:Pe("Overlay",t,void 0),map:qn.map},e=>tt(ut("Return",e),ct)),ct),va=t=>tt(ut("Bind",{type:"scene",value:Pe("Text",t,void 0),map:qn.map},e=>tt(ut("Return",e),ct)),ct),gh=t=>tt(ut("Bind",{type:"scene",value:Pe("Token",t,void 0),map:qn.map},e=>tt(ut("Return",e),ct)),ct),HC=t=>e=>tt(ut("Bind",{type:"scene",value:Pe("BeginFrame",t,void 0),map:qn.map},n=>tt(ut("Return",n),ct)),st("CatCons",()=>tt(e._1,(()=>{if(e._2.tag==="CatNil")return st("CatCons",()=>tt(ut("Bind",{type:"scene",value:Pe("EndFrame",void 0),map:qn.map},n=>tt(ut("Return",n),ct)),ct),at(V,V));if(e._2.tag==="CatCons")return st("CatCons",e._2._1,at(e._2._2._1,kt("Cons",st("CatCons",()=>tt(ut("Bind",{type:"scene",value:Pe("EndFrame",void 0),map:qn.map},n=>tt(ut("Return",n),ct)),ct),at(V,V)),e._2._2._2)));f()})()),at(V,V))),Ke=t=>e=>tt(ut("Bind",{type:"scene",value:Pe("BeginGroup",t,void 0),map:qn.map},n=>tt(ut("Return",n),ct)),st("CatCons",()=>{const n=()=>tt(ut("Bind",{type:"scene",value:Pe("EndGroup",t,void 0),map:qn.map},r=>tt(ut("Return",r),ct)),ct);return tt(e._1,(()=>{if(e._2.tag==="CatNil")return st("CatCons",n,at(V,V));if(e._2.tag==="CatCons")return st("CatCons",e._2._1,at(e._2._2._1,kt("Cons",st("CatCons",n,at(V,V)),e._2._2._2)));f()})())},at(V,V))),wr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},fh=J(sr)(0),_h=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;f()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},$C=J(t=>e=>t+e.len)(0),dh=t=>{const e=Rt(n=>w,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(It(1,t.length,t))(n=>[2,n.x,n.y]),5];f()},Ta=t=>e=>{const n=wr(e)(wr(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]},UC=t=>{const e=Rt(n=>w,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(e._1.tail)(n=>[2,n.x,n.y])];f()},Wg=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return Fl(e);if(t.shape==="Parallelogram")return Dl(e);if(t.shape==="Diamond")return Ql(e);if(t.shape==="Ellipse")return Il(e);if(t.shape==="Document")return Rl(e);if(t.shape==="Cloud")return Wl(e)(7);if(t.shape==="Rectangle")return Ta(e)(7);f()},Re=t=>e=>n=>U(r=>{const o=et(r)/et(n);return{x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o}})(Kt(0,n-1|0)),VC=t=>{const e=Tn(t.w*.18)(t.h*.6);return[...Re({x:t.x+e,y:t.y})({x:t.x+t.w,y:t.y})(16),...Re({x:t.x+t.w,y:t.y})({x:t.x+t.w-e,y:t.y+t.h})(16),...Re({x:t.x+t.w-e,y:t.y+t.h})({x:t.x,y:t.y+t.h})(16),...Re({x:t.x,y:t.y+t.h})({x:t.x+e,y:t.y})(16)]},Og=t=>e=>{const n=wr(t)(wr(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}},qg=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return Xe(r*r+n*n)},XC=t=>We(e=>n=>({a:e,b:n,len:qg(e)(n)}),t,It(1,t.length,t)),YC=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?v("Just",e[n]):w,o=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];f()})(),i=0<e.length?v("Just",e[0]):w,a=(()=>{if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return{x:0,y:0};f()})(),s=e.length;return s<3?e:[a,...St(Kt(1,s-2|0))(u=>{const c=u+1|0,g=c>=0&&c<e.length?v("Just",e[c]):w,d=u>=0&&u<e.length?v("Just",e[u]):w,l=u-1|0,_=l>=0&&l<e.length?v("Just",e[l]):w;if(_.tag==="Just"&&d.tag==="Just"&&g.tag==="Just"){const h=d._1,p=qg(h)(g._1),m=qg(_._1)(h),y=wr(t)(p/2),x=wr(t)(m/2),N=p>0?y/p:0,T=h.x+(g._1.x-h.x)*N,C=h.y+(g._1.y-h.y)*N,L=m>0?x/m:0,S=h.x+(_._1.x-h.x)*L,P=h.y+(_._1.y-h.y)*L;return U(M=>{const W=et(M)/et(10),G=1-W;return{x:G*G*S+2*G*W*h.x+W*W*T,y:G*G*P+2*G*W*h.y+W*W*C}})(Kt(0,10))}return[]}),...o]},KC=t=>e=>n=>r=>o=>U(i=>{const a=et(i)/et(o),s=1-a,u=a*a*a,c=3*s*a*a,g=3*s*s*a,d=s*s*s;return{x:d*t.x+g*e.x+c*n.x+u*r.x,y:d*t.y+g*e.y+c*n.y+u*r.y}})(Kt(0,o-1|0)),jC=t=>[...Re({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...Re({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...KC({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),...Re({x:t.x,y:t.y+t.h*.85})({x:t.x,y:t.y})(12)],lh=t=>e=>U(n=>{const r=6.283185307179586*et(n)/et(64);return{x:t.x+e*Sn(r),y:t.y+e*yn(r)}})(Kt(0,63)),hh=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]},ZC=t=>{const e=t.y+t.h/2,n=Tn(t.h*.4)(t.w*.2);return[...Re({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...Re({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...Re({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...Re({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...Re({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...Re({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},Hg=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:fh(U(n=>n.x)(t))/et(e),y:fh(U(n=>n.y)(t))/et(e)}},js=t=>e=>n=>r=>o=>U(i=>{const a=n+(r-n)*(et(i)/et(o));return{x:t.x+e*Sn(a),y:t.y+e*yn(a)}})(Kt(0,o-1|0)),$g=t=>e=>{const n=wr(t)(wr(e.w/2)(e.h/2));return[...Re({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...js({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...Re({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...js({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...Re({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...js({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...Re({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...js({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},Zs=t=>e=>n=>r=>o=>i=>U(a=>{const s=r+(o-r)*(et(a)/et(i));return{x:t.x+e*Sn(s),y:t.y+n*yn(s)}})(Kt(0,i-1|0)),t3=t=>{const e=t.h*.38;return[...St(zl(Ml(Bl)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=_o(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),o=_o(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return Zs({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(o)(r>o?r:r+6.283185307179586)(16)}),...Re({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...Re({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...Re({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},e3=t=>{const e=wr(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[...Zs({x:i,y:r})(n)(e)(3.141592653589793)(6.283185307179586)(24),...Re({x:t.x+t.w,y:r})({x:t.x+t.w,y:o})(12),...Zs({x:i,y:o})(n)(e)(0)(3.141592653589793)(24),...Re({x:t.x,y:o})({x:t.x,y:r})(12)]},Ro=t=>e=>e.shape==="Cylinder"?e3(e):e.shape==="Parallelogram"?VC(e):e.shape==="Diamond"?ZC(e):e.shape==="Ellipse"?$g(Tn(e.w)(e.h)/2)(e):e.shape==="Document"?jC(e):e.shape==="Cloud"?t3(e):$g(t)(e),n3=t=>{const e=wr(t.h*.075)(t.w*.075),n=t.w/2;return Zs({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},r3=t=>e=>n=>J(r=>o=>{const i=r.pos+o.len,a=n<i?(n-r.pos)/o.len:1,s={x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a},u=e>r.pos?(e-r.pos)/o.len:0,c={x:o.a.x+(o.b.x-o.a.x)*u,y:o.a.y+(o.b.y-o.a.y)*u},g=r.points.length-1|0,d=g>=0&&g<r.points.length?(()=>{const l=r.points[g].x-c.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const _=r.points[g].y-c.y;return _<0?-_<1e-4:_<1e-4})()})()?Ct(r.points)(s):[...r.points,c,s]:[c,s];return o.len<=0||i<=e||r.pos>=n?{...r,pos:i}:{pos:i,points:d}})({pos:0,points:[]})(t).points,o3=t=>e=>n=>{const r=Rt(o=>w,o=>i=>v("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const o=XC(t),i=$C(o),a=_h(0)(i)(e*i),s=_h(0)(i)(n*i);return s<=a?[]:r3(o)(a)(s)}f()},i3=t=>e=>n=>r=>{const o=r.x-n.x,i=r.y-n.y,a=e.x-t.x,s=e.y-t.y,u=n.x-t.x,c=n.y-t.y,g=a*i-s*o,d=(u*i-c*o)/g,l=(u*s-c*a)/g;return(g<0?-g<1e-9:g<1e-9)?w:d>=0&&d<=1&&l>=0&&l<=1?v("Just",d):w},a3=t=>e=>n=>{const r=Pt(o=>i=>ot.compare(o.t)(i.t))(vt(o=>{const i=i3(e)(n)(o._1)(o._2);return i.tag==="Just"?v("Just",{t:i._1,p:{x:e.x+(n.x-e.x)*i._1,y:e.y+(n.y-e.y)*i._1}}):w})(We(Bn,t,[...It(1,t.length,t),...It(0,1,t)])));return 0<r.length?v("Just",r[0].p):w},ph=t=>e=>{const n=Sr(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=a3(t)(n._1.init[r])(n._1.last);if(o.tag==="Just")return Ct(n._1.init)(o._1);if(o.tag==="Nothing")return e;f()}return e}f()},oo=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Ug=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},s3=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;f()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},u3=t=>e=>{const n=oo(0)(t.y+4-e.y)+oo(0)(e.y+e.h-(t.y+t.h-4)),r=oo(0)(t.x+4-e.x)+oo(0)(e.x+e.w-(t.x+t.w-4));return r*e.h+n*e.w+r*n},c3=t=>e=>{const n=t.y+t.h-6,r=t.y+6,o=t.x+14,i=t.x+t.w-14,a=J(oo)(0)(U(s=>o-10<s.x+s.w+12&&i+10>s.x-12&&r-10<s.y+s.h+12&&n+10>s.y-12?Ug((s.x+s.w+12-(o-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+a*.7071067811865476,y:t.y-a*.7071067811865476}},g3=t=>e=>{const n=Ug(t.x+t.w)(e.x+e.w)-oo(t.x)(e.x),r=Ug(t.y+t.h)(e.y+e.h)-oo(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},mh=t=>e=>n=>r=>{const o=t+4,i=oo(0)(e-8),a=o+i-n;return n<=i?s3(o)(a)(r):t+(e-n)/2},Vg=t=>e=>({...e,x:mh(t.x)(t.w)(e.w)(e.x),y:mh(t.y)(t.h)(e.h)(e.y)}),f3=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}]},_3=t=>e=>n=>r=>o=>{const i=o.y+o.h/2-n.token.y,a=o.y-r.y;return(()=>{const s=o.x+o.w/2-n.token.x,u=o.x-r.x;return 1e6*u3(t)(o)+1e4*J(c=>g=>c+g3(o)(g))(0)(e)+.05*(u*u+a*a)+.01*(s*s+i*i)})()+(o.y>n.token.y?100:0)},d3=t=>e=>n=>r=>{const o=a=>{const s=Vg(t)(a);return{rect:s,score:_3(t)(e)(n)(r)(s)}},i=Rt(a=>w,a=>s=>v("Just",{head:a,tail:s}),[r,n.rect,...f3(n)]);if(i.tag==="Nothing")return Vg(t)(r);if(i.tag==="Just")return J(a=>s=>{const u=o(s);return u.score<a.score?u:a})(o(i._1.head))(i._1.tail).rect;f()},l3=t=>e=>n=>J(r=>o=>{const i=c3(o.rect)(r.obstacles),a=i.x>=t.x+4&&i.y>=t.y+4&&i.x+i.w<=t.x+t.w-4&&i.y+i.h<=t.y+t.h-4?i:d3(t)(r.obstacles)(o)(i);return{acc:rt(A)(o.id)(a)(r.acc),obstacles:Ct(r.obstacles)(a)}})({acc:F,obstacles:e})(n).acc,Xg=t=>t,Mr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Bo=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},h3=jo(Vu)(Mt),p3=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},m3=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},yh=Xg("SegMove"),y3=Xg("SegLine"),x3=Xg("SegQuad"),xh={offset:.4,passes:1,rMax:1.5},wh=t=>he(Fn(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,tu=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},eu=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},zr=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},Ja=(()=>{const t=J(e=>n=>((e*31|0)+he(Fn(n.x*100))|0)+he(Fn(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),w3=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const o=n,i=r,a=o>=0&&o<t.length?v("Just",t[o]):w;if(a.tag==="Nothing"){n=t.length;continue}if(a.tag==="Just"){if(a._1===1){const s={x:(()=>{const u=o+1|0;return u>=0&&u<t.length?t[u]:0})(),y:(()=>{const u=o+2|0;return u>=0&&u<t.length?t[u]:0})()};e.push({kind:yh,m:i,c:i,p:s,len:0}),r=s,n=o+3|0;continue}if(a._1===2){const s={x:(()=>{const g=o+1|0;return g>=0&&g<t.length?t[g]:0})(),y:(()=>{const g=o+2|0;return g>=0&&g<t.length?t[g]:0})()},u=s.x-i.x,c=s.y-i.y;e.push({kind:y3,m:i,c:i,p:s,len:Xe(u*u+c*c)}),r=s,n=o+3|0;continue}if(a._1===3){const s={x:(()=>{const g=o+3|0;return g>=0&&g<t.length?t[g]:0})(),y:(()=>{const g=o+4|0;return g>=0&&g<t.length?t[g]:0})()},u=s.x-i.x,c=s.y-i.y;e.push({kind:x3,m:i,c:{x:(()=>{const g=o+1|0;return g>=0&&g<t.length?t[g]:0})(),y:(()=>{const g=o+2|0;return g>=0&&g<t.length?t[g]:0})()},p:s,len:Xe(u*u+c*c)*1.05}),r=s,n=o+5|0;continue}if(a._1===5){e.push({kind:yh,m:i,c:i,p:i,len:0}),n=o+1|0;continue}n=t.length;continue}f()}return e},N3=t=>e=>{const n=e.length-1|0,r=n<1?[]:It(0,n,e),o=(()=>{const a=r.length-1|0;return a>=0&&a<r.length?v("Just",r[a]):w})(),i=e.length-1|0;if(i>=0&&i<e.length&&o.tag==="Just"){const a=e[i].y-o._1.y,s=e[i].x-o._1.x,u=Xe(s*s+a*a);return u<=1e-4?e:Ct((()=>{const c=e.length-1|0;return c<1?[]:It(0,c,e)})())({x:e[i].x+s/u*t,y:e[i].y+a/u*t})}return e},v3=t=>e=>n=>ce(J(r=>o=>{const i=De(0)(t)(r.prng),a=De(0)(6.283185307179586)(i.prng);return{prng:a.prng,out:[{x:o.x+i.value*Sn(a.value),y:o.y+i.value*yn(a.value)},...r.out]}})({prng:e,out:[]})(n).out),T3=t=>e=>n=>{if(e.kind==="SegMove")return eu(t)(e.p);if(e.kind==="SegLine")return zr(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 zr(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});f()},J3=t=>e=>{if(e.kind==="SegMove")return eu(t)(e.p);if(e.kind==="SegLine")return zr(t)(e.p);if(e.kind==="SegQuad")return tu(t)(e.c)(e.p);f()},Nh=t=>e=>{const n=w3(e),r=J(s=>u=>s+u.len)(0)(n)*Mr(0)(Bo(1)(t)),o=[];let i=0,a=0;for(;a<n.length;){const s=a,u=i;if(s>=0&&s<n.length){if(u+n[s].len<=r){const c=n[s];J3(o)(c)(),i=u+c.len,a=s+1|0;continue}if(u>=r){a=n.length;continue}T3(o)(n[s])((r-u)/Mr(n[s].len)(1e-4))()}a=n.length}return o},vh={offset:1.5,passes:2,rMax:14,overshoot:2.5},Th=t=>e=>n=>r=>{const o=r.y-n.y,i=n.y-e.y,a=r.x-n.x,s=Xe(a*a+o*o),u=n.x-e.x,c=Xe(u*u+i*i),g=Bo(t.rMax*(qm(c>0&&s>0?Mr(-1)(Bo(1)((u*a+i*o)/(c*s))):1)/3.141592653589793))(.4*Bo(c)(s));return{inP:c>0?{x:n.x-u/c*g,y:n.y-i/c*g}:n,curr:n,outP:s>0?{x:n.x+a/s*g,y:n.y+o/s*g}:n}},Jh=t=>e=>{const n=e.length,r=[],o=0<e.length?v("Just",e[0]):w;if(o.tag==="Just"?eu(r)(o._1)():o.tag==="Nothing"||f(),n>=3){let a=1;for(;a<=(n-2|0);){const s=a,u=s+1|0;if(u>=0&&u<e.length){if(s>=0&&s<e.length){const c=s-1|0;if(c>=0&&c<e.length){const g=Th(t)(e[c])(e[s])(e[u]);zr(r)(g.inP)(),tu(r)(g.curr)(g.outP)()}}a=s+1|0;continue}a=s+1|0}}const i=e.length-1|0;return i>=0&&i<e.length&&n>=2&&zr(r)(e[i])(),r},b3=t=>e=>n=>r=>o=>{if(o.length<4)return Jh(t)(o);const i=0<o.length?v("Just",o[0]):w,a=(()=>{if(i.tag==="Nothing")return{x:0,y:0};if(i.tag==="Just")return i._1;f()})(),s=o.length-1|0,u=Vr(Vr(e)(s)+s|0)(s),c=_=>{const h=Vr(_+s|0)(s);return h>=0&&h<o.length?o[h]:a},g=U(_=>Th(t)(c((u+_|0)-1|0))(c(u+_|0))(c((u+_|0)+1|0)))(Kt(0,s-1|0)),d=[],l=0<g.length?v("Just",g[0]):w;if(l.tag==="Just")if(eu(d)(l._1.outP)(),h3((()=>{const _=Rt(h=>w,h=>p=>v("Just",p),g);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;f()})())(_=>{const h=zr(d)(_.inP);return()=>(h(),tu(d)(_.curr)(_.outP)())})(),n)zr(d)(l._1.inP)(),tu(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const _=g.length-1|0;_>=0&&_<g.length?zr(d)((()=>{const h=1-r;return{x:g[_].outP.x+(l._1.inP.x-g[_].outP.x)*h,y:g[_].outP.y+(l._1.inP.y-g[_].outP.y)*h}})())():zr(d)(l._1.inP)()}else l.tag==="Nothing"||f();return d},Li=t=>e=>n=>r=>{const o=p3(1)(r.length-1|0),i=De(0)(et(o))(Ag("shape")(e)),a=m3(o-1|0)(he(Fn(i.value))),s=i.prng;return U(u=>{const c=De(0)(1)(Ag(ue(u))(s)),g=De(-.18)(.3)(c.prng),d=c.value<.7,l=De(.5)(.85)(g.prng),_=v3(t.offset)(l.prng)(r);return{path:n?b3(t)(a)(d)(g.value)(_):Jh(t)(_),alpha:l.value}})(Kt(0,t.passes-1|0))},C3=t=>e=>n=>Li(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}]),k3=t=>e=>n=>{const r=Mr(0)(Bo(1)(n)),o=e.h/et(4),i=Mr(6)(o*1.4);return vt(a=>a)(U(a=>{if(r<Mr(0)(et(a)/et(4)-.05))return w;const s=Ag(ue(a))(t),u=Mr(0)(et(a)/et(4)-.05),c=Vr(a)(2)===0,g=c?e.x-2:e.x+e.w+2,d=c?e.x+e.w+2:e.x-2,l=e.y+(et(a)+.5)*o;return v("Just",{path:Nh(Mr(0)(Bo(1)((r-u)/Mr(1e-4)(Bo(1)(et(a+1|0)/et(4)+.05)-u))))((()=>{const _={rMax:2,offset:.6,passes:1},h=ce(J(m=>y=>{const x=De(-o*.08)(o*.08)(m.prng);return{prng:x.prng,out:[{x:g+(d-g)*(et(y)/et(4)),y:l+x.value},...m.out]}})({prng:s,out:[]})(Kt(0,4)).out),p=h.length<2?[]:Li(_)(s)(!1)(h);return 0<p.length?p[0].path:[]})()),width:i,alpha:1})})(Kt(0,3)))},Yg=(t,e,n)=>({tag:t,_1:e,_2:n}),nu=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;f()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},Ae=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},en=(()=>{const t=fn.unfoldr(Xn);return e=>t(_n("IterNode",e,Un))})(),jn=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Fo=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},Qr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},L3=Mt.foldMap(i2),ru=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},bh=ge(A)(Mt),Ch=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},S3=l_(A),E3=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},Mo=t=>{const e=t.Apply0();return n=>J(r=>o=>e.apply(e.Functor0().map(i=>Yf)(r))(n(o)))(t.pure())},Wr=Mo(Ao),kh=t=>e=>n=>r=>o=>i=>{const a={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},u=ki(o)(i)(r),c=0<t.length?v("Just",t[0]):w,g=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return s;f()})(),d=t.length-1|0,l=d>=0&&d<t.length?v("Just",t[d]):w,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return a;f()})(),h=Vl(128)(Ro(4)(e))(lh(g)(6)),p=g.x-s.x,m=2*(()=>{const j=g.y-s.y;return(p<0?-p:p)+(j<0?-j:j)})(),y=_.x-a.x,x=2*(()=>{const j=_.y-a.y;return(y<0?-y:y)+(j<0?-j:j)})(),N=m+Hi(t)+x,T=N<=1e-4?1:1-x/N,C=N<=1e-4?0:m/N,L=T-C,S=Vl(128)(lh(_)(6))(Ro(4)(n)),P={maxDelay:.4,smoothPasses:2},M=wo(t)(nu(0)(1)(L<=1e-4?0:(u-C)/L)),W=(()=>{if(M.tag==="Just")return M._1;if(M.tag==="Nothing")return g;f()})(),G=(()=>{if(T>=1)return 0;const j=(u-T)/(1-T),O=j<0?0:j>1?1:j;return O*O*(3-2*O)})(),I=(()=>{if(C<=1e-4)return 1;const j=u/C,O=j<0?0:j>1?1:j;return O*O*(3-2*O)})();return u<C?Io("PolyShape",Yl(I)(h.from)(h.to)(P)):u>=T?Io("PolyShape",Yl(G)(S.from)(S.to)(P)):Io("CircleShape",W,6)},Kg=t=>e=>n=>r=>o=>i=>{const a=kh(t)(e)(n)(r)(o)(i);if(a.tag==="PolyShape")return Hg(a._1);if(a.tag==="CircleShape")return a._1;f()},jg=(()=>{const t={r:24,g:24,b:27,a:255},e={r:244,g:244,b:245,a:255},n={r:248,g:249,b:246,a:255},r={r:26,g:26,b:26,a:255},o={r:28,g:101,b:192,a:255},i={r:247,g:248,b:250,a:255},a={r:42,g:48,b:60,a:255},s={r:120,g:130,b:146,a:255};return u=>{if(u==="Light")return{bg:{r:255,g:255,b:255,a:255},bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:211,b:209,a:255},shadowFill:{r:255,g:255,b:255,a:255},shadowDot:{r:26,g:26,b:26,a:255},chip:{r:255,g:235,b:130,a:255},chipShadow:{r:214,g:211,b:209,a:255},chipText:Fr,nodeFill:ve,nodeStroke:Fr,text:Fr,edge:Fr,arrowFill:Fr,tokenOutsideFill:Fr,tokenOutsideStroke:ve,tokenInside:ve,tokenInsideStroke:ve,tokenInsideBlend:$s,tokenInsideAlpha:1,chipPillFill:Fr,chipPillText:ve,chipHairline:{r:26,g:26,b:26,a:90},trailDot:Fr,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:Fr,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:ve,tokenOutsideStroke:ve,tokenInside:ve,tokenInsideStroke:ve,tokenInsideBlend:$s,tokenInsideAlpha:1,chipPillFill:e,chipPillText:t,chipHairline:{r:244,g:244,b:245,a:120},trailDot:e,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(u==="Blueprint")return{bg:o,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:90,g:160,b:230,a:255},shadowFill:o,shadowDot:ve,chip:ve,chipShadow:{r:0,g:0,b:0,a:120},chipText:o,nodeFill:o,nodeStroke:ve,text:ve,edge:ve,arrowFill:ve,tokenOutsideFill:ve,tokenOutsideStroke:ve,tokenInside:ve,tokenInsideStroke:ve,tokenInsideBlend:El,tokenInsideAlpha:.35,chipPillFill:ve,chipPillText:o,chipHairline:{r:255,g:255,b:255,a:120},trailDot:ve,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(u==="Whiteboard")return{bg:n,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:0,g:0,b:0,a:0},shadowFill:n,shadowDot:r,chip:{r:217,g:74,b:56,a:255},chipShadow:{r:26,g:26,b:26,a:60},chipText:n,nodeFill:n,nodeStroke:r,text:r,edge:r,arrowFill:r,tokenOutsideFill:r,tokenOutsideStroke:n,tokenInside:n,tokenInsideStroke:n,tokenInsideBlend:El,tokenInsideAlpha:1,chipPillFill:r,chipPillText:n,chipHairline:{r:26,g:26,b:26,a:90},trailDot:r,wobble:!0,fontFamily:"Supermarker, Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(u==="Isometric")return{bg:i,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:218,b:224,a:255},shadowFill:i,shadowDot:a,chip:{r:255,g:235,b:130,a:255},chipShadow:{r:100,g:110,b:125,a:90},chipText:a,nodeFill:{r:236,g:239,b:244,a:255},nodeStroke:a,text:a,edge:s,arrowFill:s,tokenOutsideFill:a,tokenOutsideStroke:ve,tokenInside:ve,tokenInsideStroke:ve,tokenInsideBlend:$s,tokenInsideAlpha:1,chipPillFill:a,chipPillText:ve,chipHairline:{r:60,g:66,b:78,a:90},trailDot:a,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};f()}})(),Zg=t=>e=>St(en(t.nodes))(n=>{const r=Ae(n._1)(e.nodes);return r.tag==="Just"&&ro(r._1).alpha>0?Wg(n._2):[]}),P3=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,...Zg(e)(n)],A3=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=fo.traverse(r);return i=>a=>{const s=Er(a),u=.32*i.size;return o(c=>n.bind(c===0?r.pure(0):t.measureText(i)(ze(c)(a)))(g=>n.bind(t.measureText(i)(ze(c+1|0)(a)))(d=>n.bind(t.measureInk(i)(c>=0&&c<s.length?Oi(s[c]):" "))(l=>r.pure({x:g,w:d-g,up:l.ascent-u,down:l.descent+u})))))(Kt(0,s.length-1|0))}},Lh=t=>[...Ta({...t,x:t.x-1.25,y:t.y-1.25,w:t.w+2.5,h:t.h+2.5})(8.25),...Ta({...t,y:t.y-5})(7)],G3=t=>e=>{const n=o=>(o.x-e.x)*(o.x-e.x)+(o.y-e.y)*(o.y-e.y),r=J(o=>i=>n(i)<n(o)?i:o)({x:t.x,y:t.y})([{x:t.x,y:t.y},{x:t.x+t.w,y:t.y},{x:t.x,y:t.y+t.h},{x:t.x+t.w,y:t.y+t.h}]);return U(o=>{const i=et(o)/5;return{x:r.x+(e.x-r.x)*i,y:r.y+(e.y-r.y)*i}})([1,2,3,4])},tf=t=>{const e=Gr(`
|
|
9
|
+
`)(t);return e.length===0?[""]:e},I3=t=>e=>n=>r=>o=>i=>{const a={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},u=ki(o)(i)(r),c=0<t.length?v("Just",t[0]):w,g=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return s;f()})(),d=t.length-1|0,l=d>=0&&d<t.length?v("Just",t[d]):w,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return a;f()})(),h=g.x-s.x,p=2*(()=>{const P=g.y-s.y;return(h<0?-h:h)+(P<0?-P:P)})(),m=_.x-a.x,y=2*(()=>{const P=_.y-a.y;return(m<0?-m:m)+(P<0?-P:P)})(),x=p+Hi(t)+y,N=x<=1e-4?1:1-y/x,T=x<=1e-4?0:p/x,C=N-T,L=wo(t)(nu(0)(1)(C<=1e-4?0:(u-T)/C)),S=(()=>{if(L.tag==="Just")return L._1;if(L.tag==="Nothing")return g;f()})();return u<T?Yg("InsideRect",Og(2)(e)):u>=N?Yg("InsideRect",Og(2)(n)):Yg("InsideBall",S,6)},ef=t=>e=>n=>r=>o=>i=>a=>{const s=(u,c)=>gh({id:u,pass:t,geometry:th("FlatToken",c),position:(()=>{if(c.tag==="CircleShape")return c._1;if(c.tag==="PolyShape")return Hg(c._1);f()})(),plan:nh("FlatTokenPlan",{wobble:n,fill:i,stroke:a})});return Wr(u=>{if(u._2.tag==="Travelling"){const c=Ae(u._2._1.target)(r.nodes),g=Ae(u._2._1.source)(r.nodes);if(g.tag==="Just"&&c.tag==="Just"){const d=Qr(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 ce(d._1);f()})();return s(u._1,(()=>{if(e){const _=I3(l)(g._1)(c._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost);if(_.tag==="InsideRect")return Io("PolyShape",$g(4)(_._1));if(_.tag==="InsideBall")return Io("CircleShape",_._1,_._2);f()}return kh(l)(g._1)(c._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost)})())}if(d.tag==="Nothing"){const l=ki(u._2._1.holdPre)(u._2._1.holdPost)(u._2._1.progress),_={x:g._1.x+g._1.w/2,y:g._1.y+g._1.h/2},h={x:c._1.x+c._1.w/2,y:c._1.y+c._1.h/2};return Ke({path:[],role:ln,layer:w,effects:[Ee("GroupAlpha",(()=>{if(l<.5){const m=l*2;return 1-jn(0)(Fo(1)(m))*jn(0)(Fo(1)(m))*(3-2*jn(0)(Fo(1)(m)))}const p=(l-.5)*2;return jn(0)(Fo(1)(p))*jn(0)(Fo(1)(p))*(3-2*jn(0)(Fo(1)(p)))})())]})(s(u._1,Io("CircleShape",l<.5?_:h,6)))}f()}return tt(ut("Return",void 0),ct)}if(u._2.tag==="Filling"){if(n)return tt(ut("Return",void 0),ct);const c=Ae(u._2._1.node)(r.nodes);if(c.tag==="Just")return s(u._1,Io("PolyShape",Ro(4)(e?Og(2)(c._1):c._1)));if(c.tag==="Nothing")return tt(ut("Return",void 0),ct);f()}return tt(ut("Return",void 0),ct)})(en(o.tokens))},D3=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);f()})())(()=>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);f()}))},Sh=t=>e=>n=>r=>Ke({path:[],role:ln,layer:w,effects:[Ee("GroupAlpha",n.fadeAlpha),Ee("GroupTransform",Do,{tx:t.x*(1-n.popScale),ty:(t.y+t.h)*(1-n.popScale),sx:n.popScale,sy:n.popScale}),Ee("GroupTransform",Do,{tx:0,ty:e.y*(1-n.flipY),sx:1,sy:n.flipY})]})(va(r)),nf=t=>e=>n=>r=>o=>i=>{const a=ro(i),s=i.tag==="PloppingOut"&&t.wobble?{alpha:1,scale:1}:a,u=Gr(`
|
|
10
|
+
`)(o.label===""?r:o.label),c=u.length===0?[""]:u,g={family:t.fontFamily,size:t.wobble?15:11,weight:t.wobble?800:500},d=g.size*1.2,l=(o.shape==="Cylinder"?(o.y+(o.y+o.h+5-2*Tn(o.h*.075)(o.w*.075)))/2:(o.y+o.y+o.h)/2)-et(c.length)*d/2+d/2,_=Ke({path:[],role:ln,layer:w,effects:[Ee("GroupAlpha",s.alpha*e),Ee("GroupTransform",Do,{tx:(o.x+o.w/2)*(1-s.scale),ty:(o.y+o.h/2)*(1-s.scale),sx:s.scale,sy:s.scale}),Ee("GroupAlpha",n)]})(Wr(h=>va({owner:Go("NodeText",r),text:h._2,spec:{x:o.x+o.w/2,y:l+et(h._1)*d,content:h._2,font:g,color:t.text,align:Br,baseline:Gn},bounds:w,plan:Ys}))(qt(Bn)(c)));return n>0&&s.alpha*e>0?_:tt(ut("Return",void 0),ct)},Eh=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>g=>{const d=Na({id:u,role:t,geometry:ma("FlatNode",{shape:c.shape,bounds:{x:c.x,y:c.y,w:c.w,h:c.h}}),alpha:o,plan:ya("FlatNodePlan",{palette:r,label:c.label,labelVisibility:e,inkBoost:n,labelAlpha:a,outlineAlpha:i,arrival:s,animState:g})}),l=()=>{if(e==="LabelsHidden")return tt(ut("Return",void 0),ct);if(e==="LabelsShown")return nf(r)(o)(a)(u)(c)(g);f()};return tt(d._1,(()=>{if(d._2.tag==="CatNil")return st("CatCons",l,at(V,V));if(d._2.tag==="CatCons")return st("CatCons",d._2._1,at(d._2._2._1,kt("Cons",st("CatCons",l,at(V,V)),d._2._2._2)));f()})())},R3=t=>e=>n=>r=>o=>i=>a=>Sh(o)(i)(a)({owner:Go("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:Br,baseline:Gn},bounds:v("Just",o),plan:xa("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:$e,lineCap:vn},leader:[1,i.x,o.y+o.h,2,r.x+r.w/2,r.y]})}),B3={offset:.8,passes:2,rMax:5},rf=t=>e=>n=>r=>Ke({path:[],role:ln,layer:v("Just",Hb),effects:[Ee("GroupClip",P3(e)(n)(r),Eg)]})(ef(oh)(!0)(t.wobble)(n)(r)(t.tokenOutsideFill)(t.tokenOutsideStroke)),Ph=t=>e=>n=>r=>{if(e.tokenInsideBlend==="Difference"){const o=qC(t),i=a=>{const s=Ke({path:[],role:ln,layer:v("Just",$b),effects:[Ee("GroupBlend",$s),Ee("GroupClip",Zg(n)(r),Ji)]})(ef(ih)(a==="ConvexAbsorb")(e.wobble)(n)(r)(e.tokenInside)(e.tokenInsideStroke)),u=()=>Ke({path:[],role:ln,layer:v("Just",Ub),effects:[]})(Wr(c=>{const g=Ae(c._1)(r.nodes);return g.tag==="Just"&&ro(g._1).alpha>0?Ks(Xs("FloorOverlay",{path:Wg(c._2),fill:v("Just",{color:ve,flat:!1}),stroke:w})):tt(ut("Return",void 0),ct)})(en(n.nodes)));return tt(s._1,(()=>{if(s._2.tag==="CatNil")return st("CatCons",u,at(V,V));if(s._2.tag==="CatCons")return st("CatCons",s._2._1,at(s._2._2._1,kt("Cons",st("CatCons",u,at(V,V)),s._2._2._2)));f()})())};return tt(o._1,(()=>{if(o._2.tag==="CatNil")return st("CatCons",i,at(V,V));if(o._2.tag==="CatCons")return st("CatCons",o._2._1,at(o._2._2._1,kt("Cons",st("CatCons",i,at(V,V)),o._2._2._2)));f()})())}if(e.tokenInsideBlend==="Normal")return Ke({path:[],role:ln,layer:w,effects:[Ee("GroupClip",Zg(n)(r),Ji),Ee("GroupAlpha",e.tokenInsideAlpha)]})(ef(ih)(!1)(e.wobble)(n)(r)(e.tokenInside)(e.tokenInsideStroke));f()},Ah=t=>e=>n=>r=>t.strokePath((()=>{const o=Rt(i=>w,i=>a=>v("Just",{head:i,tail:a}),U(i=>i.pt)(Fm(i=>a=>{const s=et(a)/et(72),u=De(-.18)(.18)(i.prng),c=De(-.1)(.1)(u.prng),g=De(-.07)(.07)(c.prng),d=n*(.05+.55*s)*(1+c.value),l=s*28.274333882308138+u.value;return{prng:g.prng,pt:{x:e.x+Sn(l)*d+g.value*n,y:e.y+yn(l)*d+g.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,...L3(i=>[2,i.x,i.y])(o._1.tail)];if(o.tag==="Nothing")return[];f()})())({color:r,width:5.5,lineJoin:$e,lineCap:Kn}),F3=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?Ah(t)(n.geometry._1._1)(n.geometry._1._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(hh(n.geometry._1._1)(n.geometry._1._2))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:$e,lineCap:vn});if(n.geometry._1.tag==="PolyShape")return n.plan._1.wobble&&n.geometry._1._1.length>=3?Ah(t)(Hg(n.geometry._1._1))(6)({r:200,g:35,b:30,a:220}):n.geometry._1._1.length>=3?t.fillStrokePath(dh(n.geometry._1._1))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:$e,lineCap:vn}):e.pure();f()}return e.pure()}},M3=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popClip,i=t.popTransform,a=t.popAlpha;return s=>u=>c=>g=>d=>{const l=ro(d),_=c*l.alpha,h={...g,y:g.y+5},p=g.x+g.w/2,m=g.y+g.h/2,y=Lh(h),x=r.bind(t.pushAlpha(_))(()=>r.bind(t.pushTransform({tx:p*(1-l.scale),ty:m*(1-l.scale),sx:l.scale,sy:l.scale}))(()=>r.bind(t.pushClip(y)(Eg))(()=>r.bind(t.drawRoundedRect({x:h.x,y:h.y,w:h.w,h:h.h})(7)(v("Just",{color:s.shadowFill,flat:!0}))(w))(()=>r.bind((()=>{const N=r.bind(t.pushClip(Ta(h)(7))(Ji))(()=>r.bind(t.backgroundDots({viewport:{vx:h.x,vy:h.y,vw:h.w,vh:h.h},bgColor:s.bgTransparent,dotColor:s.shadowDot,tile:1.6,dotRadius:.25,origin:{x:0,y:0}}))(()=>o));return u&&!s.wobble?N:n.pure()})())(()=>r.bind(t.drawRoundedRect({x:h.x,y:h.y,w:h.w,h:h.h})(7)(w)(v("Just",{color:s.nodeStroke,width:1.25,lineJoin:$e,lineCap:vn})))(()=>r.bind(o)(()=>r.bind(i)(()=>a))))))));return _>0&&!s.wobble?x:n.pure()}},Gh=t=>e=>n=>r=>o=>Wr(i=>{if(t.tag==="Just"&&i._1===t._1)return tt(ut("Return",void 0),ct);const a=Ae(i._1)(o.nodes);if(a.tag==="Just")return Na({id:i._1,role:zC,geometry:ma("FlatNode",{shape:i._2.shape,bounds:{x:i._2.x,y:i._2.y,w:i._2.w,h:i._2.h}}),alpha:(()=>{const s=Ae(i._1)(o.nodeFadeAlpha),u=(()=>{if(s.tag==="Nothing")return 1;if(s.tag==="Just")return s._1;f()})();return u<1?0:u})(),plan:ya("FlatNodePlan",{palette:e,label:i._2.label,labelVisibility:wa,inkBoost:n?1:0,labelAlpha:0,outlineAlpha:w,arrival:w,animState:a._1})});if(a.tag==="Nothing")return tt(ut("Return",void 0),ct);f()})(en(r.nodes)),Ih=t=>e=>n=>{const r={...t,nodeFill:t.text,text:t.nodeFill,nodeStroke:t.nodeFill};return Wr(o=>{const i=Ae(o._1)(n.nodes),a=Ae(o._1)(e.nodes),s=a.tag==="Just"&&i.tag==="Just"?Ke({path:[],role:ln,layer:w,effects:[Ee("GroupAlpha",o._2)]})(Eh(WC)(Qg)(1)(r)(1)(w)(1)(w)(o._1)(a._1)(i._1)):tt(ut("Return",void 0),ct);return o._2>0?s:tt(ut("Return",void 0),ct)})(en(n.nodeInvert))},z3=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=Mo(e.Applicative0());return i=>a=>s=>o(u=>n.bind(t.pushAlpha(u.alpha))(()=>n.bind(t.strokePath(u.path)({color:i.nodeFill,width:u.width,lineJoin:$e,lineCap:Kn}))(()=>r)))(k3(wh(a)+7777|0)(a)(s))},Q3=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=e.Applicative0(),i=Mo(o),a=t.popClip,s=Mo(o),u=fo.traverse(o),c=A3(t),g=z3(t),d=t.popTransform;return l=>_=>h=>p=>m=>y=>x=>N=>T=>C=>{const L=R=>n.bind(t.pushAlpha(R.alpha))(()=>n.bind(t.strokePath(R.path)({color:h.nodeStroke,width:2,lineJoin:$e,lineCap:Kn}))(()=>r)),S={family:h.fontFamily,size:h.wobble?15:11,weight:h.wobble?800:500},P=Gr(`
|
|
11
|
+
`)(T.label===""?N:T.label),M=P.length===0?[""]:P,W=S.size*1.2,G=T.shape==="Cylinder"?t.strokePath(iC({x:T.x,y:T.y,w:T.w,h:T.h}))({color:h.nodeStroke,width:1.25,lineJoin:$e,lineCap:vn}):o.pure(),I=(T.shape==="Cylinder"?(T.y+(T.y+T.h+5-2*Tn(T.h*.075)(T.w*.075)))/2:(T.y+T.y+T.h)/2)-et(M.length)*W/2+W/2,j=C.tag==="PloppingOut"&&h.wobble?C._1:-1,O=j>=0,z=ro(C),$=O?{alpha:1,scale:1}:z,q=T.x+T.w/2,D=T.y+T.h/2,B=n.bind(t.pushAlpha($.alpha))(()=>n.bind(t.pushTransform({tx:q*(1-$.scale),ty:D*(1-$.scale),sx:$.scale,sy:$.scale}))(()=>{const R={x:T.x,y:T.y,w:T.w,h:T.h},E={color:h.nodeStroke,width:h.wobble?2:1.25*_,lineJoin:$e,lineCap:h.wobble?Kn:vn},Q=(()=>{if(h.wobble){if(T.shape==="Rectangle")return i(L)(C3(vh)(wh(R))(R));const Y=Ro(7)(T);return n.bind(i(L)((()=>{const H=Ja(Y);return Y.length<4?[]:Li(xh)(H)(!0)(Y)})()))(()=>s(H=>i(L)((()=>{const K=Ja(H);return H.length<2?[]:Li(xh)(K)(!1)(H)})()))(T.shape==="Cylinder"?[n3(T)]:[]))}return n.bind(Dg(t)(T.shape)(R)(7)(w)(v("Just",E)))(()=>G)})();return n.bind((()=>{if(m.tag==="Nothing")return n.bind(t.pushAlpha(p))(()=>n.bind(h.wobble?Q:n.bind(Dg(t)(T.shape)(R)(7)(v("Just",{color:h.nodeFill,flat:!1}))(v("Just",E)))(()=>G))(()=>n.bind((()=>{if(x.tag==="Just"&&h.wobble&&!O){const Y=x._1;return n.bind(u(c(S))(M))(H=>{const K=Pt(Nt=>Lt=>ot.compare(Nt.x)(Lt.x)),X=he(Fn(T.x*7919+T.y*3001))*-1640531535|0,Z=De(5)(7.5)(X),nt=De(0)(Z.value)(Z.prng),gt=-(1+2*De(-1)(1)(nt.prng).value*3.141592653589793/180),bt=(Nt,Lt,Qt,ee,ae)=>K(vt(ne=>ne)([gt*Lt+Nt>=ee&>*Lt+Nt<=ae?v("Just",{x:Lt,y:gt*Lt+Nt}):w,gt*Qt+Nt>=ee&>*Qt+Nt<=ae?v("Just",{x:Qt,y:gt*Qt+Nt}):w,(()=>{const ne=(ee-Nt)/gt;return ne>=Lt&&ne<=Qt?v("Just",{x:ne,y:ee}):w})(),(()=>{const ne=(ae-Nt)/gt;return ne>=Lt&&ne<=Qt?v("Just",{x:ne,y:ae}):w})()])),lt=Z.value,Tt=Vr(Y.frameHash)(3),Et=Tt===0?{r:200,g:35,b:30,a:220}:Tt===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},te=T.x+T.w/2,Jt=mn(qt(Nt=>Lt=>qt((()=>{const Qt=I+et(Nt)*W,ee=te-J(ae=>ne=>ae+ne.w)(0)(Lt)/2;return ae=>ne=>{const Ut=S.size*.1,Wt=ae-1|0,gn=Wt>=0&&Wt<Lt.length&&ae>0?(Lt[Wt].x+Lt[Wt].w+ne.x)/2:ne.x-Ut;return{x:ee+gn-1,y:Qt-ne.up-1,w:jn(0)((()=>{const pn=ae+1|0;return pn>=0&&pn<Lt.length&&ae<(Lt.length-1|0)?(ne.x+ne.w+Lt[pn].x)/2-gn:ne.x+ne.w+Ut-gn})())+2,h:ne.up+ne.down+2}}})())(Lt))(H)),Yt=T.y+4,Dt=T.x+T.w-4,yt=T.x+4,ht=Yt-gt*yt+nt.value,ft=T.y+T.h-4,pt=St(St(qt(Nt=>Lt=>{const Qt=(Lt.from.x+Lt.to.x)/2,ee=(Lt.from.y+Lt.to.y)/2,ae=De(-1)(1)(X+(911*(Nt+1|0)|0)|0),ne=De(-3)(5)(ae.prng),Ut=ae.value*3.141592653589793/180,Wt=Sn(Ut),gn=yn(Ut),pn=He=>({x:Qt+(He.x-Qt)*Wt-(He.y-ee)*gn,y:ee+(He.x-Qt)*gn+(He.y-ee)*Wt});return{from:(()=>{const He=pn(Lt.from),kn=He.y-ee,Be=He.x-Qt,re=Xe(Be*Be+kn*kn),se=re<1e-4?1:(re+ne.value)/re;return{x:Qt+Be*se,y:ee+kn*se}})(),to:(()=>{const He=pn(Lt.to),kn=De(-3)(5)(ne.prng).value,Be=He.y-ee,re=He.x-Qt,se=Xe(re*re+Be*Be),Xf=se<1e-4?1:(se+kn)/se;return{x:Qt+re*Xf,y:ee+Be*Xf}})()}})(vt(Nt=>{const Lt=bt(ht+et(Nt)*lt,yt,Dt,Yt,ft);return Lt.length===2?v("Just",{from:Lt[0],to:Lt[1]}):w})(Kt(0,ru(1)(he(Fn((ft-gt*Dt-ht)/lt)))))))(Nt=>dt(Lt=>Lt.to.x-Lt.from.x>1,J(Lt=>Qt=>St(Lt)(ee=>{const ae=bt(ee.from.y-gt*ee.from.x,Qt.x,Qt.x+Qt.w,Qt.y,Qt.y+Qt.h);return ae.length===2?ae[0].x>ee.from.x+.001&&ae[1].x<ee.to.x-.001?[{from:ee.from,to:ae[0]},{from:ae[1],to:ee.to}]:ae[0].x<=ee.from.x+.001&&ae[1].x<ee.to.x-.001?[{from:ae[1],to:ee.to}]:ae[0].x>ee.from.x+.001&&ae[1].x>=ee.to.x-.001?[{from:ee.from,to:ae[0]}]:[]:[ee]}))([Nt])(Jt))))(Nt=>(()=>{const Lt=Nt.to.x-Nt.from.x;return Xe(2)*(Lt>=0?Lt:-Lt)<=28})()?[Nt]:[{from:Nt.from,to:{x:Nt.from.x+(Nt.to.x-Nt.from.x)*.495,y:Nt.from.y+(Nt.to.y-Nt.from.y)*.495}},{from:{x:Nt.from.x+(Nt.to.x-Nt.from.x)*.505,y:Nt.from.y+(Nt.to.y-Nt.from.y)*.505},to:Nt.to}]),At=pt.length,Gt=Nt=>jn(0)(Fo(1)(Y.t*et(At)-et(Nt)));return n.bind(t.pushClip(dh(Ro(7)(T)))(Ji))(()=>n.bind(i(Nt=>{const Lt=Nt._1,Qt=De(1.4)(1.9)(X+(1303*(Lt+1|0)|0)|0),ee=De(.35)(.8)(Qt.prng),ae=i(ne=>n.bind(t.pushAlpha(ne.alpha*ee.value))(()=>n.bind(t.strokePath(Nh(Gt(Lt))(ne.path))({color:Et,width:Qt.value,lineJoin:$e,lineCap:Kn}))(()=>r)))(Li({...vh,rMax:0,offset:.5})(X+(53*(Lt+1|0)|0)|0)(!1)([Nt._2.from,Nt._2.to]));return Gt(Lt)>0?ae:o.pure()})(qt(Bn)(pt)))(()=>a))})}return o.pure()})())(()=>n.bind((()=>{if(l==="LabelsShown"){const Y=n.bind(t.pushAlpha(y))(()=>n.bind(i(H=>t.drawText({x:T.x+T.w/2,y:I+et(H._1)*W,content:H._2,font:S,color:h.text,align:Br,baseline:Gn}))(qt(Bn)(M)))(()=>r));return y>0?Y:o.pure()}if(l==="LabelsHidden")return o.pure();f()})())(()=>n.bind((()=>{const Y=g(h)(R)(j);return O?Y:o.pure()})())(()=>r)))));if(m.tag==="Just"){const Y=m._1;return n.bind((()=>{const H=n.bind(t.pushAlpha(p))(()=>n.bind(Dg(t)(T.shape)(R)(7)(v("Just",{color:h.nodeFill,flat:!1}))(w))(()=>r));return p>0&&!h.wobble?H:o.pure()})())(()=>{const H=n.bind(t.pushAlpha(Y))(()=>n.bind(Q)(()=>r));return Y>0?H:o.pure()})}f()})())(()=>n.bind(d)(()=>r))}));return $.alpha*jn(p)((()=>{if(m.tag==="Nothing")return p;if(m.tag==="Just")return m._1;f()})())>0?B:o.pure()}},Dh=t=>e=>n=>{const r=o=>{const i=jt(a=>o.x>=a._2.x-1&&o.x<=a._2.x+a._2.w+1&&o.y>=a._2.y-1&&o.y<=a._2.y+a._2.h+1)(en(e.nodes));return i.tag==="Just"?v("Just",i._1._2):w};return Wr(o=>{const i=Qr(o._1)(n.edges);if(i.tag==="Just"){const a=Qr(o._1)(n.edgeFadeAlpha),s=(()=>{if(a.tag==="Nothing")return 1;if(a.tag==="Just")return a._1;f()})(),u=ch({id:o._1,geometry:Kl("FlatRoute",(()=>{const c=(()=>{if(0<o._2.length){const d=r(o._2[0]);if(d.tag==="Just")return ce(ph(Ro(7)(d._1))(ce(o._2)))}return o._2})(),g=c.length-1|0;if(g>=0&&g<c.length){const d=r(c[g]);if(d.tag==="Just")return ph(Ro(7)(d._1))(c)}return c})()),visible:LC(i._1),arrow:(()=>{const c=mo("conn:")(o._1);if(c.tag==="Just")return!1;if(c.tag==="Nothing")return!0;f()})(),settlingAtTarget:i._1.tag==="Extending"&&i._1._1==="ExtendFromSource",plan:jl("FlatEdgePlan",t)});return s===1?u:Ke({path:[],role:ln,layer:w,effects:[Ee("GroupAlpha",s)]})(u)}if(i.tag==="Nothing")return tt(ut("Return",void 0),ct);f()})(en(e.edges))},W3=t=>e=>n=>{const r={family:t.fontFamily,size:11,weight:500};return Wr(o=>{if(o._2===""||(()=>{const s=Qr(o._1)(n.edges);return s.tag==="Nothing"||!(s.tag==="Just"&&gw.eq(s._1)(P1))})())return tt(ut("Return",void 0),ct);const i=Qr(o._1)(e.edges),a=(()=>{if(i.tag==="Just")return wo(i._1)(.5);if(i.tag==="Nothing")return w;f()})();if(a.tag==="Nothing")return tt(ut("Return",void 0),ct);if(a.tag==="Just"){const s=a._1,u=da(r)(o._2),c=g=>{const d=g+12;return va({owner:Go("EdgeText",o._1),text:o._2,spec:{x:s.x,y:s.y,content:o._2,font:r,color:t.chipPillText,align:Br,baseline:Gn},bounds:v("Just",{x:s.x-d/2,y:s.y-8.5,w:d,h:17}),plan:xa("RoundedText",{radius:3,fill:v("Just",{color:t.chipPillFill,flat:!0}),stroke:w})})};return tt(u._1,(()=>{if(u._2.tag==="CatNil")return st("CatCons",c,at(V,V));if(u._2.tag==="CatCons")return st("CatCons",u._2._1,at(u._2._2._1,kt("Cons",st("CatCons",c,at(V,V)),u._2._2._2)));f()})())}f()})(en(e.edgeLabels))},O3=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popClip,i=t.popTransform,a=t.popAlpha;return s=>u=>c=>g=>d=>{const l=ro(d),_=c*l.alpha,h=g.x+g.w/2,p=g.y-5+g.h/2,m=Lh(g),y=r.bind(t.pushAlpha(_))(()=>r.bind(t.pushTransform({tx:h*(1-l.scale),ty:p*(1-l.scale),sx:l.scale,sy:l.scale}))(()=>r.bind(t.pushClip(m)(Eg))(()=>r.bind(t.drawRoundedRect({x:g.x,y:g.y,w:g.w,h:g.h})(7)(v("Just",{color:s.shadowFill,flat:!0}))(w))(()=>r.bind((()=>{const x=r.bind(t.pushClip(Ta(g)(7))(Ji))(()=>r.bind(t.backgroundDots({viewport:{vx:g.x,vy:g.y,vw:g.w,vh:g.h},bgColor:s.bgTransparent,dotColor:s.shadowDot,tile:1.6,dotRadius:.25,origin:{x:0,y:0}}))(()=>o));return u?x:n.pure()})())(()=>r.bind(t.drawRoundedRect({x:g.x,y:g.y,w:g.w,h:g.h})(7)(w)(v("Just",{color:s.nodeStroke,width:1.25,lineJoin:$e,lineCap:vn})))(()=>r.bind(o)(()=>r.bind(i)(()=>a))))))));return _>0&&!s.wobble?y:n.pure()}},q3=t=>{const e=M3(t),n=O3(t),r=Q3(t);return o=>{if(o.geometry.tag==="FlatNode"&&o.plan.tag==="FlatNodePlan"){const i={x:o.geometry._1.bounds.x,y:o.geometry._1.bounds.y,w:o.geometry._1.bounds.w,h:o.geometry._1.bounds.h,label:o.plan._1.label,shape:o.geometry._1.shape};if(o.role==="NodeShadow")return e(o.plan._1.palette)(o.plan._1.inkBoost>0)(o.alpha)(i)(o.plan._1.animState);if(o.role==="NodeDoorwayFrame")return n(o.plan._1.palette)(o.plan._1.inkBoost>0)(o.alpha)(i)(o.plan._1.animState);if(o.role==="NodeBody"||o.role==="NodeInversion")return r(wa)(o.plan._1.inkBoost)(o.plan._1.palette)(o.alpha)(o.plan._1.outlineAlpha)(0)(o.plan._1.arrival)(o.id)(i)(o.plan._1.animState);f()}return t.Monad0().Applicative0().pure()}},Rh=t=>{const e=n=>{if(n.tag==="Leaf")return F;if(n.tag==="Node")return oe("Node",n._1,n._2,n._3,Vg({x:t.vx,y:t.vy,w:t.vw,h:t.vh})(n._4),e(n._5),e(n._6));f()};return e},H3=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=Mo(r);return i=>a=>s=>u=>c=>g=>{const d=ci(g).length,l=et(d+1|0),_=m=>{const y=(s*l-et(m))/1.5,x=y<0?0:y>1?1:y;return x*x*(3-2*x)},h=(m=>{let y=m,x=!0,N;for(;x;){const T=y;if(T>=d){x=!1,N=T;continue}if(_(T)>=1){y=T+1|0;continue}x=!1,N=T}return N})(0),p=h>=d?[]:ar(m=>_(m)>0)(Kt(h,d-1|0)).init;return n.bind((()=>{const m=t.drawText({x:u,y:c,content:ze(h)(g),font:i,color:a,align:Ti,baseline:Gn});return h>0?m:r.pure()})())(()=>o(m=>n.bind(t.measureText(i)(ze(m)(g)))(y=>{const x=_(m);return t.drawText({x:u+y,y:c-(1-x)*10,content:ze(1)(ii(gr(ze(m)(g)))(g)),font:i,color:{...a,a:he(Fn(x*et(a.a)))},align:Ti,baseline:Gn})}))(p))}},Bh=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=Mo(r),i=H3(t);return a=>{if(a.plan.tag==="PlainText")return t.drawText(a.spec);if(a.plan.tag==="RoundedText")return n.bind((()=>{const s=r.pure();if(a.bounds.tag==="Nothing")return s;if(a.bounds.tag==="Just")return t.drawRoundedRect(a.bounds._1)(a.plan._1.radius)(a.plan._1.fill)(a.plan._1.stroke);f()})())(()=>t.drawText(a.spec));if(a.plan.tag==="TokenTravelText"){const s=a.plan._1;return n.bind(o(u=>t.fillPath(hh(u)(1.5))(s.trailFill))(s.trail))(()=>n.bind((()=>{const u=r.pure();if(a.bounds.tag==="Nothing")return u;if(a.bounds.tag==="Just")return t.drawRoundedRect(a.bounds._1)(s.radius)(v("Just",s.fill))(w);f()})())(()=>i(a.spec.font)(a.spec.color)(s.reveal)(s.textLeft)(a.spec.y)(a.text)))}if(a.plan.tag==="TokenFillingText"){const s=a.plan._1;return n.bind(t.drawRoundedRect(s.shadow)(s.radius)(v("Just",s.shadowFill))(w))(()=>n.bind((()=>{const u=r.pure();if(a.bounds.tag==="Nothing")return u;if(a.bounds.tag==="Just")return t.drawRoundedRect(a.bounds._1)(s.radius)(v("Just",s.fill))(v("Just",s.stroke));f()})())(()=>n.bind(t.strokePath(s.leader)(s.stroke))(()=>t.drawText(a.spec))))}if(a.plan.tag==="AffineText")return t.drawTextAffine(a.plan._1)(a.spec);f()}},$3=t=>e=>n=>r=>o=>i=>a=>Sh(r)(o)(i)({owner:Go("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:Ti,baseline:Gn},bounds:v("Just",r),plan:xa("TokenTravelText",{trail:G3(r)(a),trailFill:{color:e.trailDot,flat:!0},radius:3,fill:{color:e.chipPillFill,flat:!0},textLeft:r.x+14,reveal:(()=>{const s=n.phaseInLabel/.45;return s<0?0:s>1?1:s})()})}),ou=t=>e=>n=>r=>{const o=U(_=>et(ru(1)(ci(_).length)))(r),i=jn(1)(J(sr)(0)(o)),a=ki(e)(n)(t),s=a*i,u=ru(1)(r.length),c=(_=>h=>p=>{let m=_,y=h,x=p,N=!0,T;for(;N;){const C=m,L=y,S=Rt(P=>w,P=>M=>v("Just",{head:P,tail:M}),x);if(S.tag==="Nothing"){N=!1,T=ru(0)(u-1|0);continue}if(S.tag==="Just"){if(L+S._1.head>=s){N=!1,T=C;continue}m=C+1|0,y=L+S._1.head,x=S._1.tail;continue}f()}return T})(0)(0)(o),g=J(sr)(0)(c<1?[]:It(0,c,o)),d=g/i;if(c>=0&&c<o.length){const _=(g+o[c])/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(_<=d)return 1;const h=(a-d)/(_-d);return h<0?0:h>1?1:h})()}}const l=(g+1)/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(l<=d)return 1;const _=(a-d)/(l-d);return _<0?0:_>1?1:_})()}},Fh=t=>e=>n=>r=>o=>t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(ou(r)(0)(0)(U(Bi)(o)).line))(i=>{const a=i+28;return t.Applicative0().pure({x:n.x+n.w/2-a/2,y:n.y-25.2-14,w:a,h:25.2})}),U3=t=>{const e=t.Bind1(),n=t.Applicative0(),r=fo.traverse(n);return o=>i=>a=>e.Apply0().Functor0().map(s=>bh(vt(u=>u)(s)))(r(s=>{if(s._2.tag==="Filling"&&s._2._1.labels.length!==0){const u=Ae(s._2._1.node)(i.nodes);if(u.tag==="Just")return e.bind(Fh(t)(o)(u._1)(s._2._1.progress)(s._2._1.labels))(c=>n.pure(v("Just",b(s._1,c))));if(u.tag==="Nothing")return n.pure(w);f()}return n.pure(w)})(en(a.tokens)))},V3=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const c=Kg(n)(r)(o)(i)(a)(s);return t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(ou(i)(a)(s)(St(u)(tf)).line))(g=>t.Applicative0().pure({x:c.x+14+g/2-g/2-14,y:c.y-6-8-6.6-6,w:g+28,h:25.2}))},X3=t=>{const e=t.Bind1(),n=t.Applicative0(),r=fo.traverse(n);return o=>i=>a=>e.Apply0().Functor0().map(s=>bh(vt(u=>u)(s)))(r(s=>{if(s._2.tag==="Travelling"&&s._2._1.labels.length!==0){const u=Ae(s._2._1.target)(i.nodes),c=Ae(s._2._1.source)(i.nodes),g=Qr(s._2._1.edge)(i.edges);if(g.tag==="Just"&&c.tag==="Just"&&u.tag==="Just"){const d=(()=>{if(s._2._1.direction==="Forward")return g._1;if(s._2._1.direction==="Backward")return ce(g._1);f()})(),l=Kg(d)(c._1)(u._1)(s._2._1.progress)(s._2._1.holdPre)(s._2._1.holdPost);return e.bind(V3(t)(o)(d)(c._1)(u._1)(s._2._1.progress)(s._2._1.holdPre)(s._2._1.holdPost)(s._2._1.labels))(_=>n.pure(v("Just",b(s._1,{id:s._1,rect:_,token:l}))))}}return n.pure(w)})(en(a.tokens)))},of=t=>{const e=t.Bind1(),n=X3(t),r=U3(t);return o=>i=>a=>s=>e.bind(n(o)(a)(s))(u=>e.bind(r(o)(a)(s))(c=>t.Applicative0().pure(l3({x:i.vx,y:i.vy,w:i.vw,h:i.vh})([...vt(g=>{const d=Ae(g._1)(s.nodes);return d.tag==="Just"&&ro(d._1).alpha>0?v("Just",{x:g._2.x,y:g._2.y,w:g._2.w,h:g._2.h}):w})(en(a.nodes)),...(()=>{const g=(d,l)=>{if(d.tag==="Leaf")return l;if(d.tag==="Node")return g(d._5,kt("Cons",d._4,g(d._6,l)));f()};return Zt(ye.foldr,g(c,V))})()])(vt(g=>Ch(g)(u))((()=>{const g=d=>{if(d.tag==="Leaf")return F;if(d.tag==="Node")return oe("Node",d._1,d._2,d._3,void 0,g(d._5),g(d._6));f()};return Pt(A.compare)(Zt(dn.foldr,g(u)))})())))))},Y3=of(bg),Mh=t=>e=>n=>{const r=Vi(6)(.55)(nu(0)(1)((1-t)/.06)),o=t>.94,i=o&&n>1e-4,a=Vi(6)(.55)(nu(0)(1)(t/.06)),s=t<.06,u=s&&e>1e-4,c=o&&n<=1e-4;return{popScale:u?a:i?r:1,flipY:s&&e<=1e-4?a:c?r:1,fadeAlpha:(()=>{if(u){const g=t/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}if(i){const g=(1-t)/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}return 1})()}},iu=t=>e=>n=>r=>Ke({path:[],role:ln,layer:v("Just",Vb),effects:[]})(Wr(o=>{if(o._2.tag==="Travelling"){if(o._2._1.labels.length!==0){const i=Ae(o._2._1.target)(e.nodes),a=Ae(o._2._1.source)(e.nodes),s=Qr(o._2._1.edge)(e.edges),u=Ch(o._1)(r);if(u.tag==="Just"&&s.tag==="Just"&&a.tag==="Just"&&i.tag==="Just")return $3(o._1)(t)(ou(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost)(St(o._2._1.labels)(tf)))(u._1)({x:u._1.x+u._1.w/2,y:u._1.y+u._1.h/2})(Mh(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost))(Kg((()=>{if(o._2._1.direction==="Forward")return s._1;if(o._2._1.direction==="Backward")return ce(s._1);f()})())(a._1)(i._1)(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost))}return tt(ut("Return",void 0),ct)}if(o._2.tag==="Filling"&&o._2._1.labels.length!==0){const i=Ae(o._2._1.node)(e.nodes);if(i.tag==="Just"){const a=i._1,s=Fh(bg)(sh)(a)(o._2._1.progress)(o._2._1.labels),u=c=>R3(o._1)(t)(ou(o._2._1.progress)(0)(0)(St(o._2._1.labels)(tf)).line)(a)(c)({x:c.x+c.w/2,y:c.y+c.h/2})(Mh(o._2._1.progress)(0)(0));return tt(s._1,(()=>{if(s._2.tag==="CatNil")return st("CatCons",u,at(V,V));if(s._2.tag==="CatCons")return st("CatCons",s._2._1,at(s._2._2._1,kt("Cons",st("CatCons",u,at(V,V)),s._2._2._2)));f()})())}if(i.tag==="Nothing")return tt(ut("Return",void 0),ct);f()}return tt(ut("Return",void 0),ct)})(en(n.tokens))),zh=t=>e=>n=>r=>{const o=Y3(sh)(e)(n)(r);return tt(o._1,(()=>{if(o._2.tag==="CatNil")return st("CatCons",i=>iu(t)(n)(r)(i),at(V,V));if(o._2.tag==="CatCons")return st("CatCons",o._2._1,at(o._2._2._1,kt("Cons",st("CatCons",i=>iu(t)(n)(r)(i),at(V,V)),o._2._2._2)));f()})())},K3=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>o=>{const i=o.length-1|0,a=i<1?[]:It(0,i,o),s=a.length-1|0,u=s>=0&&s<a.length?v("Just",a[s]):w,c=o.length-1|0,g=c>=0&&c<o.length?v("Just",o[c]):w;if(g.tag==="Just"&&u.tag==="Just"){const d=De(.78)(1.18)(Ja(o)+19|0),l=De(.4)(.62)(d.prng),_=r.wobble?8.75*l.value:4.375,h=De(.4)(.62)(l.prng),p=r.wobble?8.75*h.value:4.375,m=g._1.y-u._1.y,y=g._1.x-u._1.x,x=Xe(y*y+m*m),N=m/x,T=-N,C=y/x,L=g._1.x+C*.875,S=g._1.y+N*.875,P=r.wobble?8.75*d.value:8.75,M=L-C*P,W=S-N*P,G=M+T*_,I=W+C*_,j=[1,L,S,2,M+T*4.375,W+C*4.375,2,M-T*4.375,W-C*4.375,5],O=M-T*p,z=W-C*p,$={color:r.arrowFill,width:2,lineJoin:$e,lineCap:Kn};return x<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,G,I,2,L,S])($))(()=>t.strokePath([1,O,z,2,L,S])($)):t.fillPath(j)({color:r.arrowFill,flat:!0})}return n.pure()}},j3=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=Mo(n),i=t.popAlpha,a=K3(t);return s=>u=>c=>g=>d=>{const l=YC(8)(g),_=c&&d.hi>=.9&&(1-d.hi)*Hi(l)<=8.75?1:d.hi;if(_<=d.lo)return n.pure();const h=o3(l)(d.lo)(_);if(h.length===0)return n.pure();const p={color:s.edge,width:s.wobble?2:.9375,lineJoin:$e,lineCap:Kn},m=s.wobble?De(-10)(4)(Ja(h)).value:0,y=s.wobble?N3(m)(h):h;return r.bind(s.wobble?o(x=>r.bind(t.pushAlpha(x.alpha))(()=>r.bind(t.strokePath(x.path)(p))(()=>i)))((()=>{const x=Ja(h);return y.length<2?[]:Li(B3)(x)(!1)(y)})()):t.strokePath(UC(h))(p))(()=>{const x=a(s)(y);return u&&_>=.999?x:n.pure()})}},Z3=t=>{const e=j3(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()},tk=t=>e=>{const n=i=>{const a=Ae(i)(t.nodes);if(a.tag==="Nothing")return!1;if(a.tag==="Just"){const s=a._1;return!le(u=>0<u._2.length&&u._2[0].x>=s.x&&u._2[0].x<=s.x+s.w&&u._2[0].y>=s.y&&u._2[0].y<=s.y+s.h,en(t.edges))}f()},r=J(i=>a=>(i*31|0)+to(a)|0)(5381)(Er(e.frameTitle)),o=i=>{const a=Ae(i)(t.nodes);if(a.tag==="Nothing")return!1;if(a.tag==="Just"){const s=a._1;return!le(u=>{const c=u._2.length-1|0;return c>=0&&c<u._2.length&&u._2[c].x>=s.x&&u._2[c].x<=s.x+s.w&&u._2[c].y>=s.y&&u._2[c].y<=s.y+s.h},en(t.edges))}f()};return J(i=>a=>{const s=a._2;return S3(u=>{if(u.tag==="Nothing")return v("Just",s);if(u.tag==="Just")return v("Just",{t:jn(u._1.t)(s.t),angle:s.t>=u._1.t?s.angle:u._1.angle,bigCircle:u._1.bigCircle||s.bigCircle,frameHash:u._1.frameHash});f()})(a._1)(i)})(F)(St(en(e.tokens))(i=>{if(i._2.tag==="Filling"){const a=i._2._1.node;return[b(a,{t:1,angle:(()=>{const s=vt(u=>(()=>{const c=Ae(a)(t.nodes),g=u._2.length-1|0;return g>=0&&g<u._2.length&&c.tag==="Just"&&u._2[g].x>=c._1.x&&u._2[g].x<=c._1.x+c._1.w&&u._2[g].y>=c._1.y&&u._2[g].y<=c._1.y+c._1.h})()?v("Just",u._2):w)(en(t.edges));if(0<s.length){const u=s[0].length-1|0,c=u<1?[]:It(0,u,s[0]),g=c.length-1|0;if(g>=0&&g<c.length){const d=s[0].length-1|0;return d>=0&&d<s[0].length?_o(s[0][d].y-c[g].y)(s[0][d].x-c[g].x):0}s[0].length-1|0}return 0})(),bigCircle:n(a)||o(a),frameHash:r})]}if(i._2.tag==="Travelling"){if(i._2._1.progress>=.75)return[b(i._2._1.target,{t:(i._2._1.progress-.75)/.25,angle:(()=>{const a=Qr(i._2._1.edge)(t.edges);if(a.tag==="Just"){const s=a._1.length-1|0,u=s<1?[]:It(0,s,a._1),c=u.length-1|0;if(c>=0&&c<u.length){const g=a._1.length-1|0;return g>=0&&g<a._1.length?_o(a._1[g].y-u[c].y)(a._1[g].x-u[c].x):0}return a._1.length-1|0,0}if(a.tag==="Nothing")return 0;f()})(),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 a=Qr(i._2._1.edge)(t.edges);if(a.tag==="Just")return 1<a._1.length&&0<a._1.length?_o(a._1[1].y-a._1[0].y)(a._1[1].x-a._1[0].x):0;if(a.tag==="Nothing")return 0;f()})(),bigCircle:n(i._2._1.source)||o(i._2._1.source),frameHash:r})]}return[]}))},ek=t=>J(e=>n=>(e*31|0)+to(n)|0)(5381)(Er(t.frameTitle)),Qh=t=>e=>n=>r=>o=>i=>{const a=ek(i),s=tk(o)(i);return Wr(u=>{const c=Ae(u._1)(i.nodes);if(c.tag==="Just")return Eh(zg)(e)(n)(r)((()=>{const g=Ae(u._1)(i.nodeFadeAlpha);if(g.tag==="Nothing")return 1;if(g.tag==="Just")return g._1;f()})())(t(u._1))((()=>{const g=Ae(u._1)(i.nodeLabelFadeAlpha);if(g.tag==="Nothing")return 1;if(g.tag==="Just")return g._1;f()})())((()=>{const g=Ae(u._1)(s);return g.tag==="Just"?v("Just",g._1):g.tag==="Nothing"&&E3(u._1)(i.visited)?v("Just",{t:1,angle:0,bigCircle:!1,frameHash:a}):w})())(u._1)(u._2)(c._1);if(c.tag==="Nothing")return tt(ut("Return",void 0),ct);f()})(en(o.nodes))},nk=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;f()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},Wh=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;f()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},Oh=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},af=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},rk=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},ok=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},sf=(()=>{const t=fn.unfoldr(Xn);return e=>t(_n("IterNode",e,Un))})(),ik=Hr(Ao)(Mt),ak=t=>e=>{const n=yn(t.angle),r=Sn(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},sk=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],uf=t=>e=>{const n=r=>nk(0)(255)(he($n(et(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},je=t=>e=>n=>r=>({x:(e-n)*Sn(t.angle),y:(e+n)*yn(t.angle)-r}),cf=t=>{const e=Rt(n=>w,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(e._1.tail)(n=>[2,n.x,n.y]),5];f()},uk=t=>e=>n=>{const r=n.id,o=n.np,i=Na({id:r,role:zg,geometry:ma("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:ya("IsoNodePlan",{config:t,palette:e})}),a=()=>va({owner:Go("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:Br,baseline:Gn},bounds:w,plan:xa("AffineText",ak(t)(o.y+o.h))});return tt(i._1,(()=>{if(i._2.tag==="CatNil")return st("CatCons",a,at(V,V));if(i._2.tag==="CatCons")return st("CatCons",i._2._1,at(i._2._2._1,kt("Cons",st("CatCons",a,at(V,V)),i._2._2._2)));f()})())},ck=t=>e=>n=>r=>o=>{const i=We(Bn,o,It(1,o.length,o)),a=i.length-1|0;return qt(s=>u=>({depth:(u._1.x+u._1.y+u._2.x+u._2.y)/2,draw:ch({id:n,geometry:Kl("IsoSegments",[[je(t)(u._1.x)(u._1.y)(0),je(t)(u._2.x)(u._2.y)(0)]]),visible:{lo:0,hi:1},arrow:r&&s===a,settlingAtTarget:!1,plan:jl("IsoEdgePlan",{config:t,palette:e})})}))(i)},gk=t=>e=>n=>r=>o=>{const i=(()=>{if(t==="Forward")return o;if(t==="Backward")return ce(o);f()})();if(0<i.length){const s=wo(i)(Wh(0)(1)(ki(n)(r)(e)));if(s.tag==="Nothing")return i[0];if(s.tag==="Just")return s._1;f()}const a=wo(i)(Wh(0)(1)(ki(n)(r)(e)));if(a.tag==="Nothing")return{x:0,y:0};if(a.tag==="Just")return a._1;f()},fk=t=>{const e=Rt(n=>w,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(e._1.tail)(n=>[2,n.x,n.y])];f()},_k=t=>{const e=Rt(n=>w,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{vx:0,vy:0,vw:0,vh:0};if(e.tag==="Just"){const n=J(r=>o=>({minX:Oh(r.minX)(o.x),minY:Oh(r.minY)(o.y),maxX:af(r.maxX)(o.x),maxY:af(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}}f()},dk=t=>{const e=t.Monad0(),n=e.Bind1();return r=>{if(r.geometry.tag==="IsoSlab"&&r.plan.tag==="IsoNodePlan"){const o=r.geometry._1,i=r.plan._1.palette,a=(s,u)=>t.fillStrokePath(cf(s))({color:u,flat:!0})({color:i.nodeStroke,width:1,lineJoin:$e,lineCap:vn});return n.bind(a(o.south,uf(.66)(i.nodeFill)))(()=>n.bind(a(o.east,uf(.82)(i.nodeFill)))(()=>a(o.top,i.nodeFill)))}return e.Applicative0().pure()}},lk=t=>{const e=t.Monad0(),n=e.Bind1();return r=>{if(r.geometry.tag==="IsoCube"&&r.plan.tag==="IsoTokenPlan"){const o=r.geometry._1,i=r.plan._1.palette,a=(s,u)=>t.fillStrokePath(cf(s))({color:uf(u)(i.tokenOutsideFill),flat:!0})({color:i.tokenOutsideStroke,width:1,lineJoin:$e,lineCap:vn});return n.bind(a(o.south,.66))(()=>n.bind(a(o.east,.82))(()=>a(o.top,1)))}return e.Applicative0().pure()}},hk={angle:.5235987755982988,boxHeight:26,transparentBg:!0},pk=t=>e=>n=>{const r=n.x-5.5,o=n.x+5.5,i=n.y-5.5,a=n.y+5.5,s=e+11,u=je(t)(o)(i)(s),c=je(t)(o)(a)(s),g=je(t)(r)(a)(s),d=je(t)(o)(a)(e);return{south:[je(t)(r)(a)(e),d,c,g],east:[je(t)(o)(i)(e),d,c,u],top:[je(t)(r)(i)(s),u,c,g]}},mk=t=>e=>n=>r=>{const o=r._1,i=(a,s)=>({depth:s.x+s.y,draw:gh({id:o,pass:oh,geometry:th("IsoCube",pk(t)(a)(s)),position:s,plan:nh("IsoTokenPlan",{config:t,palette:e,baseZ:a})})});if(r._2.tag==="Travelling"){const a=rk(r._2._1.edge)(n.edges);return a.tag==="Just"?v("Just",i(0,gk(r._2._1.direction)(r._2._1.progress)(r._2._1.holdPre)(r._2._1.holdPost)(a._1))):w}if(r._2.tag==="Filling"){const a=ok(r._2._1.node)(n.nodes);if(a.tag==="Just")return v("Just",i(t.boxHeight,{x:a._1.x+a._1.w/2,y:a._1.y+a._1.h/2}))}return w},yk=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:je(t)(e.x)(e.y)(0),b:je(t)(r)(e.y)(0),c:je(t)(r)(n)(0),d:je(t)(e.x)(n)(0)},top:{a:je(t)(e.x)(e.y)(t.boxHeight),b:je(t)(r)(e.y)(t.boxHeight),c:je(t)(r)(n)(t.boxHeight),d:je(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},qh=t=>e=>U(n=>({id:n._1,np:n._2,box:yk(t)(n._2)}))(sf(e.nodes)),xk=t=>e=>[...St(qh(t)(e))(sk),...(()=>{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)));f()};return St(Zt(ye.foldr,n(e.edges,V)))(U(r=>je(t)(r.x)(r.y)(0)))})()],wk=t=>e=>n=>r=>{const o=jg(e),i=[...St(sf(n.edges))(u=>ck(t)(o)(u._1)((()=>{const c=mo("conn:")(u._1);if(c.tag==="Just")return!1;if(c.tag==="Nothing")return!0;f()})())(u._2)),...U(u=>({depth:u.box.depth,draw:uk(t)(o)(u)}))(qh(t)(n)),...vt(mk(t)(o)(n))(sf(r.tokens))],a=uh({viewport:_k(xk(t)(n)),clear:v("Just",t.transparentBg?o.bgTransparent:o.bg),dots:w}),s=()=>ik(u=>u.draw)(Pt(u=>c=>ot.compare(u.depth)(c.depth))(i));return tt(a._1,(()=>{if(a._2.tag==="CatNil")return st("CatCons",s,at(V,V));if(a._2.tag==="CatCons")return st("CatCons",a._2._1,at(a._2._2._1,kt("Cons",st("CatCons",s,at(V,V)),a._2._2._2)));f()})())},Nk=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=af(1e-4)(Xe(n*n+e*e)),o=e/r,i=n/r,a=t.to.y-o*7,s=t.to.x-i*7;return cf([t.to,{x:s-o*3,y:a+i*3},{x:s+o*3,y:a-i*3}])},vk=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Hr(n)(Mt);return o=>{if(o.geometry.tag==="IsoSegments"&&o.plan.tag==="IsoEdgePlan"){const i=o.plan._1.palette,a=o.geometry._1;return e.Bind1().bind(r(s=>t.strokePath(fk(s))({color:i.edge,width:1.5,lineJoin:$e,lineCap:Kn}))(a))(()=>{const s=a.length-1|0;if(s>=0&&s<a.length){const c=a[s],g=c.length-1|0,d=g<1?[]:It(0,g,c),l=d.length-1|0;if(l>=0&&l<d.length){const h=a.length-1|0,p=(()=>{if(h>=0&&h<a.length){const m=a[h],y=m.length-1|0;if(y>=0&&y<m.length)return t.fillPath(Nk({from:d[l],to:m[y]}))({color:i.arrowFill,flat:!0})}return n.pure()})();return o.arrow?p:n.pure()}a.length-1|0;const _=n.pure();return o.arrow?_:n.pure()}a.length-1|0;const u=n.pure();return o.arrow?u:n.pure()})}return n.pure()}},Hh=(t,e)=>({tag:t,_1:e}),gf=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;f()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;f()},ff=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},Si=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Tk=jo(Ao)(Mt),Jk=Hh("ResolvedLabels"),bk=t=>{const e=jt(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return ws(t);f()},Ck=t=>e=>n=>{const r=gf(0)(1)((n-t)/ff(1e-6)(e-t));return r*r*(3-2*r)},ba=t=>e=>{const n=ff(1)(pe(e.rootLayout).w),r=!e.diving&&e.levels.length===1,o=r?1:e.diving?1-gf(0)(1)(e.doorProgress):0,i=Mn(e.rootLayout)(e.camera),a=r?1:gf(0)(1)(i.w/n),s=ws(e).state.frameTitle===""?0*a*o:40*a*o,u=t.padding*a*a*o;return(()=>{if(t.outputAspect.tag==="Nothing")return ux;if(t.outputAspect.tag==="Just")return t1(t.outputAspect._1);f()})()({vx:i.x-u,vy:i.y-u-s,vw:i.w+2*u,vh:i.h+2*u+s})},kk=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=Si(e._1)(t.segment.layout.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1.x*t.segment.placement.scale+t.segment.placement.tx,o=n._1.y*t.segment.placement.scale+t.segment.placement.ty,i=n._1.w*t.segment.placement.scale,a=n._1.h*t.segment.placement.scale;return[1,r,o,2,r+i,o,2,r+i,o+a,2,r,o+a,5]}}f()},_f=t=>e=>{const n=ey(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}},$h=t=>e=>t===""?tt(ut("Return",void 0),ct):va({owner:MC,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:Ti,baseline:Ob},bounds:w,plan:Ys}),Uh=t=>e=>{if(t==="")return tt(ut("Return",void 0),ct);const n=e.vh/720,r=56*n,o=da({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:56,weight:700})(t),i=a=>{const s=r+16*n*2,u=a*n+28*n*2,c=e.vy+e.vh/2,g=e.vx+e.vw/2,d={x:g-u/2,y:c-s/2,w:u,h:s};return Ks(Xs("TitleCardOverlay",{backing:{path:Ci(d)(16*n),fill:v("Just",{color:{r:255,g:255,b:255,a:235},flat:!0}),stroke:v("Just",{color:{r:0,g:0,b:0,a:255},width:1.5*n,lineJoin:$e,lineCap:Kn})},text:{owner:ah,text:t,spec:{x:g,y:c,content:t,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:r,weight:700},color:{r:28,g:30,b:36,a:255},align:Br,baseline:Gn},bounds:v("Just",d),plan:Ys}}))};return tt(o._1,(()=>{if(o._2.tag==="CatNil")return st("CatCons",i,at(V,V));if(o._2.tag==="CatCons")return st("CatCons",o._2._1,at(o._2._2._1,kt("Cons",st("CatCons",i,at(V,V)),o._2._2._2)));f()})())},Vh=t=>e=>{if(t==="")return tt(ut("Return",void 0),ct);const n=e.vh/720,r=15*n,o=da({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:15,weight:600})(t),i=a=>{const s=e.vy+12*n,u=r+6*n*2,c=a*n+11*n*2,g=e.vx+e.vw/2,d={x:g-c/2,y:s,w:c,h:u};return Ks(Xs("FrameTitleOverlay",{backing:v("Just",{path:Ci(d)(u/2),fill:v("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}),stroke:v("Just",{color:{r:0,g:0,b:0,a:255},width:1*n,lineJoin:$e,lineCap:Kn})}),text:{owner:ah,text:t,spec:{x:g,y:s+u/2,content:t,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:r,weight:600},color:{r:28,g:30,b:36,a:255},align:Br,baseline:Gn},bounds:v("Just",d),plan:Ys}}))};return tt(o._1,(()=>{if(o._2.tag==="CatNil")return st("CatCons",i,at(V,V));if(o._2.tag==="CatCons")return st("CatCons",o._2._1,at(o._2._2._1,kt("Cons",st("CatCons",i,at(V,V)),o._2._2._2)));f()})())},Lk=t=>e=>n=>r=>o=>i=>a=>s=>{const u=jg(t.theme),c=(()=>{if(s.tag==="ResolvedLabels")return zh(u)(o)(i)(a);if(s.tag==="SpringLabels")return iu(u)(i)(a)(Rh(o)(s._1));f()})(),g=uh({viewport:o,clear:v("Just",t.transparentBg?u.bgTransparent:u.bg),dots:w}),d=()=>{const l=Ke({path:[],role:ln,layer:w,effects:n<1?[Ee("GroupAlpha",n)]:[]})((()=>{const _=Dh(u)(i)(a),h=()=>{const p=Gh(r)(u)(t.halftoneShadows)(i)(a),m=()=>{const y=Qh(N=>r.tag!=="Nothing"&&r.tag==="Just"&&r._1===N?v("Just",0):w)(Qg)(1)(u)(i)(a),x=()=>{const N=Ih(u)(i)(a),T=()=>{const C=rf(u)(o)(i)(a),L=()=>{const S=Ph(jb)(u)(i)(a),P=()=>{const M=()=>{const W=W3(u)(i)(a);return a.staticKind!=="Animated"?W:tt(ut("Return",void 0),ct)};return tt(c._1,(()=>{if(c._2.tag==="CatNil")return st("CatCons",M,at(V,V));if(c._2.tag==="CatCons")return st("CatCons",c._2._1,at(c._2._2._1,kt("Cons",st("CatCons",M,at(V,V)),c._2._2._2)));f()})())};return tt(S._1,(()=>{if(S._2.tag==="CatNil")return st("CatCons",P,at(V,V));if(S._2.tag==="CatCons")return st("CatCons",S._2._1,at(S._2._2._1,kt("Cons",st("CatCons",P,at(V,V)),S._2._2._2)));f()})())};return tt(C._1,(()=>{if(C._2.tag==="CatNil")return st("CatCons",L,at(V,V));if(C._2.tag==="CatCons")return st("CatCons",C._2._1,at(C._2._2._1,kt("Cons",st("CatCons",L,at(V,V)),C._2._2._2)));f()})())};return tt(N._1,(()=>{if(N._2.tag==="CatNil")return st("CatCons",T,at(V,V));if(N._2.tag==="CatCons")return st("CatCons",N._2._1,at(N._2._2._1,kt("Cons",st("CatCons",T,at(V,V)),N._2._2._2)));f()})())};return tt(y._1,(()=>{if(y._2.tag==="CatNil")return st("CatCons",x,at(V,V));if(y._2.tag==="CatCons")return st("CatCons",y._2._1,at(y._2._2._1,kt("Cons",st("CatCons",x,at(V,V)),y._2._2._2)));f()})())};return tt(p._1,(()=>{if(p._2.tag==="CatNil")return st("CatCons",m,at(V,V));if(p._2.tag==="CatCons")return st("CatCons",p._2._1,at(p._2._2._1,kt("Cons",st("CatCons",m,at(V,V)),p._2._2._2)));f()})())};return tt(_._1,(()=>{if(_._2.tag==="CatNil")return st("CatCons",h,at(V,V));if(_._2.tag==="CatCons")return st("CatCons",_._2._1,at(_._2._2._1,kt("Cons",st("CatCons",h,at(V,V)),_._2._2._2)));f()})())})());if(n>0){const _=()=>{const h=$h(t.watermark)(o),p=()=>a.staticKind==="TitleCard"?Uh(a.frameTitle)(o):Vh(a.frameTitle)(o);return tt(h._1,(()=>{if(h._2.tag==="CatNil")return st("CatCons",p,at(V,V));if(h._2.tag==="CatCons")return st("CatCons",h._2._1,at(h._2._2._1,kt("Cons",st("CatCons",p,at(V,V)),h._2._2._2)));f()})())};return tt(l._1,(()=>{if(l._2.tag==="CatNil")return st("CatCons",_,at(V,V));if(l._2.tag==="CatCons")return st("CatCons",l._2._1,at(l._2._2._1,kt("Cons",st("CatCons",_,at(V,V)),l._2._2._2)));f()})())}return tt(ut("Return",void 0),st("CatCons",()=>{const _=$h(t.watermark)(o),h=()=>a.staticKind==="TitleCard"?Uh(a.frameTitle)(o):Vh(a.frameTitle)(o);return tt(_._1,(()=>{if(_._2.tag==="CatNil")return st("CatCons",h,at(V,V));if(_._2.tag==="CatCons")return st("CatCons",_._2._1,at(_._2._2._1,kt("Cons",st("CatCons",h,at(V,V)),_._2._2._2)));f()})())},at(V,V)))};return tt(g._1,(()=>{if(g._2.tag==="CatNil")return st("CatCons",d,at(V,V));if(g._2.tag==="CatCons")return st("CatCons",g._2._1,at(g._2._2._1,kt("Cons",st("CatCons",d,at(V,V)),g._2._2._2)));f()})())},Sk=t=>e=>n=>r=>o=>i=>{const a=i.segment.path.length-1|0,s=a>=0&&a<i.segment.path.length?v("Just",i.segment.path[a]):w;if(s.tag==="Nothing")return tt(ut("Return",void 0),ct);if(s.tag==="Just"){const u=Si(s._1)(o.segment.layout.nodes);if(u.tag==="Nothing")return tt(ut("Return",void 0),ct);if(u.tag==="Just"){const c=u._1,g=Si(s._1)(o.state.nodes),d=(()=>{if(g.tag==="Nothing")return E1;if(g.tag==="Just")return g._1;f()})(),l=Si(s._1)(o.state.nodeInvert),_=(1-Ck(.08)(.14)(r))*(()=>{if(l.tag==="Nothing")return 1;if(l.tag==="Just")return 1-l._1;f()})();return Ke({path:o.segment.path,role:o.role,layer:w,effects:[Ee("GroupAlpha",o.bgAlpha),Ee("GroupTransform",Do,n)]})((()=>{const h=Na({id:s._1,role:QC,geometry:ma("FlatNode",{shape:c.shape,bounds:{x:c.x,y:c.y+5,w:c.w,h:c.h}}),alpha:1,plan:ya("FlatNodePlan",{palette:t,label:c.label,labelVisibility:wa,inkBoost:e?1:0,labelAlpha:0,outlineAlpha:v("Just",1),arrival:w,animState:d})}),p=()=>{const m=Na({id:s._1,role:zg,geometry:ma("FlatNode",{shape:c.shape,bounds:{x:c.x,y:c.y,w:c.w,h:c.h}}),alpha:_,plan:ya("FlatNodePlan",{palette:t,label:c.label,labelVisibility:wa,inkBoost:1,labelAlpha:0,outlineAlpha:v("Just",1),arrival:w,animState:d})});return tt(m._1,(()=>{if(m._2.tag==="CatNil")return st("CatCons",()=>nf(t)(1)(_)(s._1)(c)(d),at(V,V));if(m._2.tag==="CatCons")return st("CatCons",m._2._1,at(m._2._2._1,kt("Cons",st("CatCons",()=>nf(t)(1)(_)(s._1)(c)(d),at(V,V)),m._2._2._2)));f()})())};return tt(h._1,(()=>{if(h._2.tag==="CatNil")return st("CatCons",p,at(V,V));if(h._2.tag==="CatCons")return st("CatCons",h._2._1,at(h._2._2._1,kt("Cons",st("CatCons",p,at(V,V)),h._2._2._2)));f()})())})())}}f()},Xh=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const c=[1,e.viewport.vx,e.viewport.vy,2,e.viewport.vx+e.viewport.vw,e.viewport.vy,2,e.viewport.vx+e.viewport.vw,e.viewport.vy+e.viewport.vh,2,e.viewport.vx,e.viewport.vy+e.viewport.vh,5],g=u.state,d={tx:s.segment.placement.tx,ty:s.segment.placement.ty,sx:s.segment.placement.scale,sy:s.segment.placement.scale},l=jg(t.theme),_=u.segment.layout,h=pe(_),p={vx:h.x-1e3,vy:h.y-1e3,vw:h.w+2e3,vh:h.h+2e3},m=u.segment.path.length-1|0,y=m>=0&&m<u.segment.path.length?Si(u.segment.path[m])(s.segment.layout.nodes):w,x=u.role==="Active"||11*u.segment.placement.scale*n>=5?Qg:wa,N=_f(e.viewport)(u),T=(()=>{if(x==="LabelsHidden")return tt(ut("Return",void 0),ct);if(x==="LabelsShown")return i.tag==="Leaf"?zh(l)(N)(_)(g):iu(l)(_)(g)(Rh(N)(i));f()})(),C={tx:u.segment.placement.tx,ty:u.segment.placement.ty,sx:u.segment.placement.scale,sy:u.segment.placement.scale},L=Ke({path:u.segment.path,role:u.role,layer:w,effects:[Ee("GroupAlpha",u.bgAlpha)]})((()=>{const P=Ke({path:u.segment.path,role:u.role,layer:w,effects:[Ee("GroupClip",(()=>{if(r>=.52)return c;const W=kk(s)((()=>{const G=u.segment.path.length-1|0;return G>=0&&G<u.segment.path.length?v("Just",u.segment.path[G]):w})());return W.length===0?c:W})(),Ji)]})((()=>{const W=(()=>{if(y.tag==="Just")return Ke({path:s.segment.path,role:s.role,layer:w,effects:[Ee("GroupTransform",Do,d)]})(Ks(Xs("FloorOverlay",{path:Wg({...y._1,x:y._1.x+1,y:y._1.y+1,w:y._1.w-2,h:y._1.h-2}),fill:v("Just",{color:l.bg,flat:!0}),stroke:w})));if(y.tag==="Nothing")return tt(ut("Return",void 0),ct);f()})(),G=(s.role==="Active"||s.role==="FlyThrough")&&!t.transparentBg?W:tt(ut("Return",void 0),ct),I=()=>{const j=Ke({path:u.segment.path,role:u.role,layer:w,effects:[Ee("GroupTransform",Do,C)]})((()=>{const z=Dh(l)(_)(g),$=()=>{const q=Gh(a)(l)(t.halftoneShadows)(_)(g),D=()=>{const B=Qh(E=>a.tag!=="Nothing"&&a.tag==="Just"&&a._1===E?v("Just",0):w)(x)(1)(l)(_)(g),R=()=>{const E=Ih(l)(_)(g);return tt(E._1,(()=>{if(E._2.tag==="CatNil")return st("CatCons",()=>rf(l)(p)(_)(g),at(V,V));if(E._2.tag==="CatCons")return st("CatCons",E._2._1,at(E._2._2._1,kt("Cons",st("CatCons",()=>rf(l)(p)(_)(g),at(V,V)),E._2._2._2)));f()})())};return tt(B._1,(()=>{if(B._2.tag==="CatNil")return st("CatCons",R,at(V,V));if(B._2.tag==="CatCons")return st("CatCons",B._2._1,at(B._2._2._1,kt("Cons",st("CatCons",R,at(V,V)),B._2._2._2)));f()})())};return tt(q._1,(()=>{if(q._2.tag==="CatNil")return st("CatCons",D,at(V,V));if(q._2.tag==="CatCons")return st("CatCons",q._2._1,at(q._2._2._1,kt("Cons",st("CatCons",D,at(V,V)),q._2._2._2)));f()})())};return tt(z._1,(()=>{if(z._2.tag==="CatNil")return st("CatCons",$,at(V,V));if(z._2.tag==="CatCons")return st("CatCons",z._2._1,at(z._2._2._1,kt("Cons",st("CatCons",$,at(V,V)),z._2._2._2)));f()})())})()),O=()=>Ke({path:u.segment.path,role:u.role,layer:w,effects:[Ee("GroupTransform",FC,C)]})(Ph(Zb)(l)(_)(g));return tt(j._1,(()=>{if(j._2.tag==="CatNil")return st("CatCons",O,at(V,V));if(j._2.tag==="CatCons")return st("CatCons",j._2._1,at(j._2._2._1,kt("Cons",st("CatCons",O,at(V,V)),j._2._2._2)));f()})())};return tt(G._1,(()=>{if(G._2.tag==="CatNil")return st("CatCons",I,at(V,V));if(G._2.tag==="CatCons")return st("CatCons",G._2._1,at(G._2._2._1,kt("Cons",st("CatCons",I,at(V,V)),G._2._2._2)));f()})())})()),M=()=>Ke({path:u.segment.path,role:u.role,layer:w,effects:[Ee("GroupTransform",Do,C)]})(T);return tt(P._1,(()=>{if(P._2.tag==="CatNil")return st("CatCons",M,at(V,V));if(P._2.tag==="CatCons")return st("CatCons",P._2._1,at(P._2._2._1,kt("Cons",st("CatCons",M,at(V,V)),P._2._2._2)));f()})())})()),S=()=>s.role==="FlyThrough"?Sk(l)(t.halftoneShadows)(d)(o)(s)(u):tt(ut("Return",void 0),ct);return tt(L._1,(()=>{if(L._2.tag==="CatNil")return st("CatCons",S,at(V,V));if(L._2.tag==="CatCons")return st("CatCons",L._2._1,at(L._2._2._1,kt("Cons",st("CatCons",S,at(V,V)),L._2._2._2)));f()})())},Ek=t=>e=>n=>r=>Tk(r.minis)(o=>{const i=Xh(t)(e)(n)(0)(0)(F)(w)(r)(o);return(()=>{const a=o.segment.path.length-1|0;return o.bgAlpha>0&&a>=0&&a<o.segment.path.length&&(()=>{const s=Si(o.segment.path[a])(r.state.nodes);if(s.tag==="Just")return s._1.tag==="Hidden"?!1:s._1.tag!=="PloppingOut";if(s.tag==="Nothing")return!1;f()})()})()?i:tt(ut("Return",void 0),ct)}),Pk=t=>e=>n=>{if(t.theme==="Isometric")return wk({...hk,transparentBg:t.transparentBg})(t.theme)(ws(n).segment.layout)(ws(n).state);const r=ba(t)(n),o=u=>n.hasDives?r.vw/ff(1)(pe(n.rootLayout).w):1,i={tileScale:o(),viewport:r},a=u=>c=>{if(c.length===0)return tt(ut("Return",void 0),ct);const g=Rt(d=>w,d=>l=>v("Just",{head:d,tail:l}),c);if(g.tag==="Nothing")return tt(ut("Return",void 0),ct);if(g.tag==="Just"){const d=Xh(t)(i)(n.camera.zoom)(n.diveDepth)(n.doorProgress)(g._1.head.role==="Active"?e:F)((()=>{if(g._1.head.role==="FlyThrough"&&0<g._1.tail.length){const l=g._1.tail[0].segment.path.length-1|0;if(l>=0&&l<g._1.tail[0].segment.path.length)return v("Just",g._1.tail[0].segment.path[l])}return w})())(u)(g._1.head);return g._1.head.role==="Active"||g._1.head.role==="FlyThrough"?tt(d._1,(()=>{if(d._2.tag==="CatNil")return st("CatCons",()=>a(g._1.head)(g._1.tail),at(V,V));if(d._2.tag==="CatCons")return st("CatCons",d._2._1,at(d._2._2._1,kt("Cons",st("CatCons",()=>a(g._1.head)(g._1.tail),at(V,V)),d._2._2._2)));f()})()):tt(ut("Return",void 0),st("CatCons",()=>a(g._1.head)(g._1.tail),at(V,V)))}f()},s=Rt(u=>w,u=>c=>v("Just",{head:u,tail:c}),n.levels);if(s.tag==="Nothing")return tt(ut("Return",void 0),ct);if(s.tag==="Just"){const u=s._1.tail,c=s._1.head,g=u.length===0,d=Lk(t)(o())(c.role==="Active"||c.role==="FlyThrough"?c.bgAlpha:0)((()=>{if(c.role==="FlyThrough"&&0<u.length){const _=u[0].segment.path.length-1|0;if(_>=0&&_<u[0].segment.path.length)return v("Just",u[0].segment.path[_])}return w})())(r)(c.segment.layout)(bk(n).state)(g&&e.tag!=="Leaf"?Hh("SpringLabels",e):Jk),l=()=>{const _=Ek(t)(i)(n.camera.zoom)(c);return c.role==="Active"||c.role==="FlyThrough"?tt(_._1,(()=>{if(_._2.tag==="CatNil")return st("CatCons",()=>a(c)(u),at(V,V));if(_._2.tag==="CatCons")return st("CatCons",_._2._1,at(_._2._2._1,kt("Cons",st("CatCons",()=>a(c)(u),at(V,V)),_._2._2._2)));f()})()):tt(ut("Return",void 0),st("CatCons",()=>a(c)(u),at(V,V)))};return tt(d._1,(()=>{if(d._2.tag==="CatNil")return st("CatCons",l,at(V,V));if(d._2.tag==="CatCons")return st("CatCons",d._2._1,at(d._2._2._1,kt("Cons",st("CatCons",l,at(V,V)),d._2._2._2)));f()})())}f()},df=t=>e=>n=>HC({viewport:ba(t)(n),camera:n.camera})(Pk(t)(e)(n)),lf=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);f()}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()}f()},Ak=t=>{const e=t.Monad0(),n=e.Bind1(),r=Hr(e.Applicative0())(o_),o=Bh(t);return i=>{if(i.tag==="FrameTitleOverlay"){const a=i._1;return n.bind(r(lf(t))(a.backing))(()=>o(a.text))}if(i.tag==="TitleCardOverlay"){const a=i._1;return n.bind(lf(t)(a.backing))(()=>o(a.text))}if(i.tag==="FloorOverlay")return lf(t)(i._1);f()}},Gk=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Hr(n)(Mt),o=t.popTransform,i=t.popBakedTransform,a=(()=>{const u=t.popClip,c=t.popAlpha,g=t.popBlend,d=t.popBlur;return l=>{if(l.tag==="GroupTransform"){if(l._1==="NormalTransform")return o;if(l._1==="BakedTransform")return i;f()}if(l.tag==="GroupClip")return u;if(l.tag==="GroupAlpha")return c;if(l.tag==="GroupBlend")return g;if(l.tag==="GroupBlur")return d;f()}})(),s=t.popLayer;return u=>e.Bind1().bind(r(a)(ce(u.effects)))(()=>{if(u.layer.tag==="Just")return s;if(u.layer.tag==="Nothing")return n.pure();f()})},Ik=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Hr(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();f()})())(()=>r(i=>{if(i.tag==="GroupTransform"){if(i._1==="NormalTransform")return t.pushTransform(i._2);if(i._1==="BakedTransform")return t.pushBakedTransform(i._2);f()}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);f()})(o.effects))},Yh=t=>{const e=t.Monad0(),n=q3(t),r=dk(t),o=Z3(t),i=vk(t),a=F3(t),s=lk(t);return OC(e)({beginFrame:u=>t.setViewport(u.viewport),endFrame:e.Applicative0().pure(),beginGroup:Ik(t),endGroup:Gk(t),background:D3(t),overlay:Ak(t),node:u=>{if(u.geometry.tag==="FlatNode")return n(u);if(u.geometry.tag==="IsoSlab")return r(u);f()},edge:u=>{if(u.geometry.tag==="FlatRoute")return o(u);if(u.geometry.tag==="IsoSegments")return i(u);f()},text:Bh(t),token:u=>{if(u.geometry.tag==="FlatToken")return a(u);if(u.geometry.tag==="IsoCube")return s(u);f()},insideTokenStyle:t.insideTokenStyle,measureText:t.measureText,measureInk:t.measureInk})},Dk=of($l)(Fg.measureText),Kh=Yh(Fg),au=t=>ba({padding:24,outputAspect:t.width<=0||t.height<=0?w:v("Just",t.width/t.height)}),Rk=t=>e=>n=>r=>o=>i=>a=>{const s={padding:24,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;f()})(),halftoneShadows:!1,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?w:v("Just",r.width/r.height)},u=Ol(n)(r);return()=>{const c=u(),g=o.levels.length-1|0;if(g>=0&&g<o.levels.length){const l=Dk(_f(au(r)(o))(o.levels[g]))(o.levels[g].segment.layout)(o.levels[g].state)(c)(),_=Jg(i)(l)(a);return Kh(df(s)(_.applied)(o))(c)(),_.springs}const d=Jg(i)(F)(a);return Kh(df(s)(d.applied)(o))(c)(),d.springs}},Ca=t=>"rgb("+ue(t.r)+","+ue(t.g)+","+ue(t.b)+")",zo=t=>t===1?7:t===2?10:t===3?14:t===4?13:t===5?5:t===6?1:t===7?4:t===8?1:t===9?2:t===10?1:t===11?2:t===12?1:t===18?2:t===19?1:t===13?2:t===14?1:t===15||t===16?5:1,fe=po(lo("Fixed",ho(0)(20)(2))),hf=t=>{const e=n=>{const r=n>=0&&n<t.length?v("Just",t[n]):w;if(r.tag==="Just")return r._1===1?["M",fe((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===2?["L",fe((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===3?["Q",fe((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+5|0)]:r._1===4?["C",fe((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+5|0;return o>=0&&o<t.length?t[o]:0})()),fe((()=>{const o=n+6|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+7|0)]:r._1===5?["Z",...e(n+1|0)]:[];if(r.tag==="Nothing")return[];f()};return dr(" ")(e(0))},Bk=t=>fe(t.vx)+" "+fe(t.vy)+" "+fe(t.vw)+" "+fe(t.vh),In=t=>e=>he(Fn(e>=0&&e<t.length?t[e]:0)),pf=t=>e=>{const n=In(t.ops)(e+1|0);return It(n,n+In(t.ops)(e+2|0)|0,t.paths)},jh=(()=>{const t=zn("&")("&"),e=zn("<")("<"),n=(()=>{const r=zn(">")(">"),o=(()=>{const i=zn('"')(""");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),Fk={vx:0,vy:0,vw:1,vh:1},Mk=t=>(e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i>=0&&i<t.length){if(t[i]===15){const a=i+1|0;r=!1,o={vx:a>=0&&a<t.length?t[a]:0,vy:(()=>{const s=a+1|0;return s>=0&&s<t.length?t[s]:0})(),vw:(()=>{const s=a+2|0;return s>=0&&s<t.length?t[s]:0})(),vh:(()=>{const s=a+3|0;return s>=0&&s<t.length?t[s]:0})()};continue}n=i+zo(t[i])|0;continue}r=!1,o=Fk}return o})(0),ka=t=>e=>({r:In(t)(e),g:In(t)(e+1|0),b:In(t)(e+2|0),a:In(t)(e+3|0)}),Zh=t=>e=>({color:ka(t)(e),width:(()=>{const n=e+4|0;return n>=0&&n<t.length?t[n]:0})(),join:In(t)(e+5|0),cap:In(t)(e+6|0)}),zk=t=>e=>'<rect x="'+fe(t.vx)+'" y="'+fe(t.vy)+'" width="'+fe(t.vw)+'" height="'+fe(t.vh)+'" fill="'+Ca(e)+'" opacity="'+fe(et(e.a)/255)+'"/>',Qk=t=>e=>'<path d="'+hf(t)+'" fill="'+Ca(e)+'" fill-opacity="'+fe(et(e.a)/255)+'"/>',tp=t=>' stroke="'+Ca(t.color)+'" stroke-opacity="'+fe(et(t.color.a)/255)+'" stroke-width="'+fe(t.width)+'" stroke-linejoin="'+(t.join===0?"round":t.join===1?"bevel":"miter")+'" stroke-linecap="'+(t.cap===0?"butt":t.cap===1?"round":"square")+'"',Wk=t=>e=>n=>'<path d="'+hf(t)+'" fill="'+Ca(e)+'" fill-opacity="'+fe(et(e.a)/255)+'"'+tp(n)+"/>",Ok=t=>e=>'<path d="'+hf(t)+'" fill="none"'+tp(e)+"/>",qk=t=>e=>{const n=ka(t.ops)(e+7|0),r=In(t.ops)(e+12|0),o=In(t.ops)(e+11|0);return'<text x="'+fe((()=>{const i=e+1|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" y="'+fe((()=>{const i=e+2|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'"'+(r===0?' dy="0.8em"':r===1?' dy="0.32em"':"")+' fill="'+Ca(n)+'" fill-opacity="'+fe(et(n.a)/255)+'" font-size="'+fe((()=>{const i=e+5|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" font-family="'+jh((()=>{const i=In(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="'+ue(In(t.ops)(e+6|0))+'" text-anchor="'+(o===0?"start":o===1?"middle":"end")+'">'+jh((()=>{const i=In(t.ops)(e+3|0);return i>=0&&i<t.strs.length?t.strs[i]:""})())+"</text>"},Qo=t=>e=>n=>{const r=n>=0&&n<e.ops.length?v("Just",e.ops[n]):w;if(r.tag==="Just")return r._1===1?Qk(pf(e)(n))(ka(e.ops)(n+3|0))+Qo(t)(e)(n+zo(r._1)|0):r._1===2?Ok(pf(e)(n))(Zh(e.ops)(n+3|0))+Qo(t)(e)(n+zo(r._1)|0):r._1===3?Wk(pf(e)(n))(ka(e.ops)(n+3|0))(Zh(e.ops)(n+7|0))+Qo(t)(e)(n+zo(r._1)|0):r._1===4?qk(e)(n)+Qo(t)(e)(n+zo(r._1)|0):r._1===16?zk(t)(ka(e.ops)(n+1|0))+Qo(t)(e)(n+zo(r._1)|0):Qo(t)(e)(n+zo(r._1)|0);if(r.tag==="Nothing")return"";f()},Hk=t=>{const e=Mk(t.ops);return{viewBox:Bk(e),body:Qo(e)(t)(0),vx:e.vx,vy:e.vy,vw:e.vw,vh:e.vh}},$k=Eb(Ib)(wm),ep=t=>e=>{const n=t.strs;return()=>{const r=Xu(n);return t.strs.push(e),r}},su=t=>e=>{const n=t.paths;return()=>{const r=Xu(n);return t.paths.push(...e),{offset:r,len:e.length}}},Uk=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)}},np=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)}},Or=t=>e=>{const n=et(e),r=t.ops;return()=>{r.push(n)}},uu=t=>e=>{const n=e.len,r=Or(t)(e.offset);return()=>(r(),Or(t)(n)())},Vk=()=>{const t=[],e=[],n=[],r=[];return r.push(1),{ops:t,paths:e,strs:n,alphaStack:r}},Xk=t=>{if(t.tag==="MeasureText"){const e=t._3(kg(t._1)(t._2));return()=>e}if(t.tag==="MeasureInk"){const e=t._3(Lg(t._1)(t._2));return()=>e}f()},rp=t=>{const e=t.alphaStack;return()=>{const n=Xu(e);if(n===0)return 1;const r=vm(Vt,w,n-1|0,t.alphaStack);if(r.tag==="Nothing")return 1;if(r.tag==="Just")return r._1;f()}},Wo=t=>e=>{const n=rp(t);return()=>{const r=n();return Or(t)(e.r)(),Or(t)(e.g)(),Or(t)(e.b)(),Or(t)(he(Fn(et(e.a)*r+.5)))()}},op=t=>e=>{const n=Wo(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;f()})()),t.ops.push((()=>{if(e.lineCap==="ButtCap")return 0;if(e.lineCap==="RoundCap")return 1;if(e.lineCap==="SquareCap")return 2;f()})())}},Yk=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r;if(s.tag==="FillPath"){const u=s._3,c=s._2,g=su(a)(s._1);o=!1,i=()=>{const d=g();return a.ops.push(1),uu(a)(d)(),Wo(a)(c.color)(),u};continue}if(s.tag==="StrokePath"){const u=s._3,c=s._2,g=su(a)(s._1);o=!1,i=()=>{const d=g();return a.ops.push(2),uu(a)(d)(),op(a)(c)(),u};continue}if(s.tag==="FillStrokePath"){const u=s._2,c=s._4,g=s._3,d=su(a)(s._1);o=!1,i=()=>{const l=d();return a.ops.push(3),uu(a)(l)(),Wo(a)(u.color)(),op(a)(g)(),c};continue}if(s.tag==="DrawText"){const u=s._2,c=s._1,g=ep(a)(ko(c.content));o=!1,i=()=>{const d=g(),l=ep(a)(c.font.family)();return a.ops.push(4),a.ops.push(c.x),a.ops.push(c.y),Or(a)(d)(),Or(a)(l)(),a.ops.push(c.font.size),Or(a)(c.font.weight)(),Wo(a)(c.color)(),a.ops.push((()=>{if(c.align==="AlignLeft")return 0;if(c.align==="AlignCenter")return 1;if(c.align==="AlignRight")return 2;f()})()),a.ops.push((()=>{if(c.baseline==="BaselineTop")return 0;if(c.baseline==="BaselineMiddle")return 1;if(c.baseline==="BaselineAlphabetic")return 2;if(c.baseline==="BaselineBottom")return 3;f()})()),u};continue}if(s.tag==="DrawTextAffine"){n=a,r=Ht("DrawText",{...s._2,x:s._1.a*s._2.x+s._1.c*s._2.y+s._1.e,y:s._1.b*s._2.x+s._1.d*s._2.y+s._1.f},s._3);continue}if(s.tag==="PushTransform"){const u=s._2,c=s._1,g=a.ops;o=!1,i=()=>(g.push(5),Uk(a)(c)(),u);continue}if(s.tag==="PopTransform"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(6),u);continue}if(s.tag==="PushClip"){const u=s._3,c=s._2,g=su(a)(s._1);o=!1,i=()=>{const d=g();return a.ops.push(7),uu(a)(d)(),a.ops.push((()=>{if(c==="NonZero")return 0;if(c==="EvenOdd")return 1;f()})()),u};continue}if(s.tag==="PopClip"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(8),u);continue}if(s.tag==="PushBlend"){const u=s._1,c=s._2,g=a.ops;o=!1,i=()=>(g.push(9),a.ops.push((()=>{if(u==="Normal")return 0;if(u==="Difference")return 1;f()})()),c);continue}if(s.tag==="PopBlend"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(10),u);continue}if(s.tag==="PushAlpha"){const u=s._1,c=s._2,g=rp(a);o=!1,i=()=>{const d=g();return a.alphaStack.push(d*u),a.ops.push(11),a.ops.push(u),c};continue}if(s.tag==="PopAlpha"){const u=s._1,c=a.alphaStack;o=!1,i=()=>(Tm(Vt,w,c),a.ops.push(12),u);continue}if(s.tag==="PushBlur"){const u=s._2,c=s._1,g=a.ops;o=!1,i=()=>(g.push(18),a.ops.push(c),u);continue}if(s.tag==="PopBlur"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(19),u);continue}if(s.tag==="PushLayer"){const u=s._1,c=s._2,g=a.ops;o=!1,i=()=>(g.push(13),a.ops.push((()=>{if(u==="LayerBase")return 0;if(u==="LayerPolyOut")return 1;if(u==="LayerPolyIn")return 2;if(u==="LayerNodeMask")return 3;if(u==="LayerOverlay")return 4;f()})()),c);continue}if(s.tag==="PopLayer"){const u=s._1,c=a.ops;o=!1,i=()=>(c.push(14),u);continue}if(s.tag==="SetViewport"){const u=s._2,c=s._1,g=a.ops;o=!1,i=()=>(g.push(15),np(a)(c)(),u);continue}if(s.tag==="ClearBackground"){const u=s._1,c=s._2,g=a.ops;o=!1,i=()=>(g.push(16),Wo(a)(u)(),c);continue}if(s.tag==="BackgroundDots"){const u=s._2,c=s._1,g=a.ops;o=!1,i=()=>(g.push(17),np(a)(c.viewport)(),Wo(a)(c.bgColor)(),Wo(a)(c.dotColor)(),a.ops.push(c.tile),a.ops.push(c.dotRadius),a.ops.push(c.origin.x),a.ops.push(c.origin.y),u);continue}f()}return i},Kk=t=>e=>e.type==="metrics"?Xk(e.value):e.type==="render"?Yk(t)(e.value):G_("Data.Functor.Variant: pattern match failure ["+e.type+"]"),jk=t=>{const e=Vk();return $k(Kk(e))(t)(),{ops:e.ops,paths:e.paths,strs:e.strs}},Zk=t=>t,La=t=>t,mf=La("Light"),t5=La("Dark"),e5=La("Blueprint"),n5=La("Whiteboard"),r5=La("Isometric"),o5=Zk("TransparentBackground"),io=t=>"rgb("+ue(t.r)+","+ue(t.g)+","+ue(t.b)+")",cu=po(lo("Fixed",ho(0)(20)(6))),Nr=po(lo("Fixed",ho(0)(20)(4))),i5=t=>"translate("+Nr(t.tx)+","+Nr(t.ty)+") scale("+Nr(t.sx)+","+Nr(t.sy)+")",zt=po(lo("Fixed",ho(0)(20)(2))),yf=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,o=r>=0&&r<t.length?v("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(zt((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(zt((()=>{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(zt((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(zt((()=>{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(zt((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(zt((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(zt((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(zt((()=>{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(zt((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(zt((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(zt((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(zt((()=>{const i=r+4|0;return i>=0&&i<t.length?t[i]:0})())),e.push(zt((()=>{const i=r+5|0;return i>=0&&i<t.length?t[i]:0})())),e.push(zt((()=>{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}f()}return dr(" ")(e)},a5={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},xf=(()=>{const t=zn("&")("&"),e=zn("<")("<"),n=(()=>{const r=zn(">")(">"),o=(()=>{const i=zn('"')(""");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),s5=t=>{if(t.style==="RunText")return"<tspan>"+xf(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+xf(t.text)+"</tspan>";f()},Ue=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},u5=t=>e=>{const n=[];let r=0;const o=i=>{const a=i>=0&&i<e.length?t.sx*e[i]+t.tx:t.sx*0+t.tx;return()=>{n.push(a),n.push((()=>{const s=i+1|0;return s>=0&&s<e.length?t.sy*e[s]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const i=r,a=i>=0&&i<e.length?v("Just",e[i]):w;if(a.tag==="Nothing"){r=e.length;continue}if(a.tag==="Just"){if(a._1===1){n.push(a._1),o(i+1|0)(),r=i+3|0;continue}if(a._1===2){n.push(a._1),o(i+1|0)(),r=i+3|0;continue}if(a._1===3){n.push(a._1),o(i+1|0)(),o(i+3|0)(),r=i+5|0;continue}if(a._1===4){n.push(a._1),o(i+1|0)(),o(i+3|0)(),o(i+5|0)(),r=i+7|0;continue}if(a._1===5){n.push(a._1),r=i+1|0;continue}r=e.length;continue}f()}return n},gu=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return u5(r._1)(e);f()}},ip={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),a=o();return i(a)}},Functor0:()=>a5},c5={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>ip},g5={pure:t=>e=>()=>t,Apply0:()=>ip},ap={Applicative0:()=>g5,Bind1:()=>c5},f5=t=>e=>'<defs><pattern id="'+t+'" x="'+zt(e.origin.x)+'" y="'+zt(e.origin.y)+'" width="'+zt(e.tile)+'" height="'+zt(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+zt(e.tile)+'" height="'+zt(e.tile)+'" fill="'+io(e.bgColor)+'" fill-opacity="'+zt(et(e.bgColor.a)/255)+'"/>')+'<circle cx="'+zt(e.tile/2)+'" cy="'+zt(e.tile/2)+'" r="'+zt(e.dotRadius)+'" fill="'+io(e.dotColor)+'"/></pattern></defs><rect x="'+zt(e.viewport.vx)+'" y="'+zt(e.viewport.vy)+'" width="'+zt(e.viewport.vw)+'" height="'+zt(e.viewport.vh)+'" fill="url(#'+t+')"/>',sp=t=>e=>'<path d="'+yf(t)+'" fill="'+io(e)+'" fill-opacity="'+zt(et(e.a)/255)+'"/>',_5=t=>e=>n=>r=>'<rect x="'+zt(t.x)+'" y="'+zt(t.y)+'" width="'+zt(t.w)+'" height="'+zt(t.h)+'" rx="'+zt(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+io(n._1.color)+'" fill-opacity="'+zt(et(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';f()})()+(()=>{if(r.tag==="Just")return' stroke="'+io(r._1.color)+'" stroke-opacity="'+zt(et(r._1.color.a)/255)+'" stroke-width="'+zt(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";f()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";f()})()+'"';if(r.tag==="Nothing")return"";f()})()+"/>",up=t=>e=>'<path d="'+yf(t)+'" fill="none" stroke="'+io(e.color)+'" stroke-opacity="'+zt(et(e.color.a)/255)+'" stroke-width="'+zt(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";f()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";f()})()+'"/>',cp=t=>{const e=rl(ko(t.content));return'<text x="'+zt(t.x)+'" y="'+zt(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"";f()})()+' fill="'+io(t.color)+'" fill-opacity="'+zt(et(t.color.a)/255)+'" font-size="'+zt(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+ue(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";f()})()+'">'+(e.length===1&&e[0].style==="RunText"?xf(e[0].text):dr("")(U(s5)(e)))+"</text>"},d5=t=>"matrix("+Nr(t.a)+" "+Nr(t.b)+" "+Nr(t.c)+" "+Nr(t.d)+" "+Nr(t.e)+" "+Nr(t.f)+")",gp={fillPath:t=>e=>n=>{const r=gu(n)(t);return()=>{const o=r();return Ue(sp(o)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=gu(n)(t);return()=>{const o=r(),i=n.bake.value;return Ue(up(o)((()=>{if(i.tag==="Nothing")return e;if(i.tag==="Just")return{...e,width:i._1.sx*e.width};f()})()))(n)()}},fillStrokePath:t=>e=>n=>r=>{const o=gu(r)(t);return()=>{const i=o(),a=r.bake.value;return Ue(sp(i)(e.color)+up(i)((()=>{if(a.tag==="Nothing")return n;if(a.tag==="Just")return{...n,width:a._1.sx*n.width};f()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>o=>{const i=o.bake;return()=>{const a=i.value;return Ue(_5((()=>{if(a.tag==="Nothing")return t;if(a.tag==="Just")return{x:a._1.sx*t.x+a._1.tx,y:a._1.sy*t.y+a._1.ty,w:a._1.sx*t.w,h:a._1.sy*t.h};f()})())((()=>{if(a.tag==="Nothing")return e;if(a.tag==="Just")return a._1.sx*e;f()})())(n)(r.tag==="Just"?v("Just",(()=>{if(a.tag==="Nothing")return r._1;if(a.tag==="Just")return{...r._1,width:a._1.sx*r._1.width};f()})()):w))(o)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return Ue(cp((()=>{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}};f()})()))(e)()}},drawTextAffine:t=>e=>Ue((()=>{const n='transform="'+d5(t)+'"';return(n===""?"<g>":"<g "+n+">")+cp(e)+"</g>"})()),pushTransform:t=>Ue((()=>{const e='transform="'+i5(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:Ue("</g>"),pushBakedTransform:t=>e=>{const n=e.bake;return()=>{n.value=v("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=gu(n)(t)(),a="clip"+ue(o);return Ue((()=>{const s='clip-path="url(#'+a+')"';return'<defs><clipPath id="'+a+'"><path d="'+yf(i)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";f()})()+"/></clipPath></defs>"+(s===""?"<g>":"<g "+s+">")})())(n)()}},popClip:Ue("</g>"),pushBlend:t=>Ue((()=>{const e=(()=>{if(t==="Normal")return'style="mix-blend-mode: normal"';if(t==="Difference")return'style="mix-blend-mode: difference"';f()})();return e===""?"<g>":"<g "+e+">"})()),popBlend:Ue("</g>"),pushAlpha:t=>Ue((()=>{const e='opacity="'+zt(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:Ue("</g>"),pushBlur:t=>e=>{if(t<.01)return Ue("<g>")(e);const n=e.patternCounter;return()=>{const r=n.value;e.patternCounter.value=r+1|0;const o="lvl-blur-"+ue(r);return Ue((()=>{const i='filter="url(#'+o+')"';return'<defs><filter id="'+o+'" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="'+zt(t)+'"/></filter></defs>'+(i===""?"<g>":"<g "+i+">")})())(e)()}},popBlur:Ue("</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=>Ue('<rect x="'+zt(e.viewport.vx)+'" y="'+zt(e.viewport.vy)+'" width="'+zt(e.viewport.vw)+'" height="'+zt(e.viewport.vh)+'" fill="'+io(t)+'" opacity="'+zt(et(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,Ue(f5("bg-dots-"+ue(r))(t))(e)()}},measureText:t=>e=>n=>{const r=kg(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Lg(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Ig,Monad0:()=>ap},l5=Yh(gp),h5=of(ap)(gp.measureText),p5=t=>e=>n=>r=>o=>{const i={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;f()})(),halftoneShadows:!1,watermark:"",theme:n,outputAspect:t},a=ba(i)(o);return{viewBox:cu(a.vx)+" "+cu(a.vy)+" "+cu(a.vw)+" "+cu(a.vh),body:(()=>{const s=[],u={value:0},c={value:0},g={value:0},d={value:w};return l5(df(i)(e)(o))({out:s,maskDepth:u,clipCounter:c,patternCounter:g,viewport:a,bake:d})(),dr("")(s)})(),vx:a.vx,vy:a.vy,vw:a.vw,vh:a.vh}},m5=t=>e=>n=>r=>o=>i=>{const a={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;f()})(),outputAspect:t},s=Jg(o)((()=>{const u=[],c={value:0},g={value:0},d={value:0},l={value:w},_=r.levels.length-1|0;if(_>=0&&_<r.levels.length){const h=_f(ba(a)(r))(r.levels[_]);return h5(h)(r.levels[_].segment.layout)(r.levels[_].state)({out:u,maskDepth:c,clipCounter:g,patternCounter:d,viewport:h,bake:l})()}return F})())(i);return{parts:p5(t)(s.applied)(e)(n)(r),springs:s.springs}},ao=(t,e)=>({tag:t,_1:e}),fu=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Jn=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},fp=ge(A)(Mt),_p=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},dp=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},lp=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},hp=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Ei=(()=>{const t=fn.unfoldr(e=>{if(e.tag==="Nil")return w;if(e.tag==="Cons")return v("Just",b(e._1,e._2));f()});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)));f()};return n(e,V)})())})(),y5=J(t=>e=>rt(A)(e)()(t))(F),wf=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},pp=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},x5=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},_u=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},w5=ao("NoKeyframes"),N5=t=>ao("DuplicateEventId",t),v5=t=>ao("UnknownEvent",t),T5=t=>e=>({...e,cameraSpans:k1(e.cameraConfig)(t)(e.layout)(e.keyframes)({endT:e.totalDuration,spans:e.spans,windows:e.windows,segments:e.segments,dives:e.dives})}),J5=t=>e=>n=>r=>{const o=fu(r.edge)(e.edges),i=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return Hi(o._1);f()})(),a=Jn(t.minTokenDuration)(Jn(et(J(s=>u=>s+ci(u).length|0)(0)(r.labels))*t.tokenReadSecPerChar)(t.tokenSpeed<=0?0:i/t.tokenSpeed))+n.post;return{duration:a,holdPre:0,holdPost:a<=0?0:n.post/a}},b5=Ma(t=>{const e=Gr(`
|
|
12
|
+
`)(t);return e.length===0?[""]:e}),C5=t=>e=>fp(vt(n=>{if(n.kind.tag==="SendToken")return v("Just",b(n.id,{post:(()=>{const r=n.id;return(()=>{const o=n.kind._1.to;return le(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;f()},e)})()?0:t.tokenHold})()}));if(n.kind.tag==="FillNodeWithoutTransition")return w;f()})(e)),k5=t=>{if(t.event.kind.tag==="SendToken")return v("Just",{startT:t.startT,endT:t.endT,target:gi("TokenWindow",t.event.id,t.event.kind._1.edge,t.event.kind._1.direction,t.event.kind._1.from,t.event.kind._1.to,t.event.kind._1.labels,t.holdPre,t.holdPost)});if(t.event.kind.tag==="FillNodeWithoutTransition")return v("Just",{startT:t.startT,endT:t.endT,target:gi("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});f()},L5=t=>vt((()=>{const e=t.path;return n=>n.target.tag==="TokenWindow"?v("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),S5=t=>e=>n=>{const r=fu(n)(t);if(r.tag==="Nothing")return S1;if(r.tag==="Just"){const o=_p(r._1.target)(e);return _p(r._1.source)(e)?o?cw:uw:S1}f()},mp=t=>e=>{if(t.tag==="Just"&&t._1>e.endT+1e-4){const n=Jn(0)(e.endT-e.startT),r=Jn(e.startT)(t._1-n);return{...e,startT:r,endT:r+n}}return e},yp=U(Bi),E5={post:0},P5=t=>e=>n=>r=>o=>{const i=dp(o.event.id)(n),a=(()=>{if(i.tag==="Nothing")return E5;if(i.tag==="Just")return i._1;f()})(),s=(()=>{if(o.event.when.tag==="First")return 0;if(o.event.when.tag==="At")return o.event.when._1;if(o.event.when.tag==="After"){const c=o.event.when._1,g=jt(d=>d.event.id===c)(r);if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1.endT;f()}if(o.event.when.tag==="With"){const c=o.event.when._1,g=jt(d=>d.event.id===c)(r);if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1.startT}f()})(),u=(()=>{if(o.event.kind.tag==="SendToken")return J5(t)(e)(a)(o.event.kind._1);if(o.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};f()})();return Ct(r)({startT:s,endT:s+u.duration,event:o.event,holdPre:u.holdPre,holdPost:u.holdPost})},xp=t=>e=>n=>J(P5(t)(e)(C5(t)(n)))([])(qt(r=>o=>({event:o}))(n)),A5=t=>J(e=>n=>{const r=Sr(e);if(r.tag==="Nothing")return[n];if(r.tag==="Just")return n.startT<=r._1.last.endT+1e-4?Ct(r._1.init)({...r._1.last,endT:Jn(r._1.last.endT)(n.endT)}):Ct(e)(n);f()})([])(Pt(e=>n=>ot.compare(e.startT)(n.startT))(t)),G5=t=>e=>{const n=lp(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;f()},I5=t=>e=>{const n=Pt(ot.compare)(vt(r=>r.target.tag==="TokenWindow"?r.target._4===e||r.target._5===e?v("Just",r.startT):w:r.target.tag==="FillWindow"&&r.target._2===e?v("Just",r.startT):w)(t));return 0<n.length?v("Just",n[0]):w},D5=t=>e=>{const n=Pt(ot.compare)(vt(r=>r.target.tag==="TokenWindow"&&r.target._2===e?v("Just",r.startT):w)(t));return 0<n.length?v("Just",n[0]):w},R5=t=>e=>e.target.tag==="NodeWindow"?e.target._2==="PlopIn"?mp(I5(t.windows)(e.target._1))(e):e:e.target.tag==="EdgeWindow"&&e.target._2.tag==="Extend"?mp(D5(t.windows)(e.target._1))(e):e,B5=t=>({...t,windows:Pt(e=>n=>ot.compare(e.startT)(n.startT))(U(R5(t))(t.windows))}),F5=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];f()},wp={id:"",nodes:F,edges:F,kind:Ui},M5=t=>e=>py((()=>{const n=hp(e.from)(t);if(n.tag==="Nothing")return wp;if(n.tag==="Just")return n._1;f()})())((()=>{const n=hp(e.to)(t);if(n.tag==="Nothing")return wp;if(n.tag==="Just")return n._1;f()})()),z5=t=>e=>{const n=lp(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:F};if(n.tag==="Just")return n._1;f()},Np={id:"",index:-1,kind:"",name:"",time:0,endTime:0,path:[],tokenIndex:-1,lineIndex:-1,text:"",from:"",to:""},Q5=t=>e=>e.scene.tag==="StepScene"?v("Just",{...Np,id:"step:"+e.scene._1,kind:"step",name:e.scene._1,time:e.startT,endTime:e.startT,path:yp(t)}):w,W5=t=>vt(Q5(t.path))(t.spans),Nf=t=>e=>n=>r=>{const o=fu(r)(n.edges);if(o.tag==="Just")return t<=0?e:Jn(e)(Hi(o._1)/t);if(o.tag==="Nothing")return e;f()},vp=t=>e=>n=>r=>o=>{const i=t.plop,a=M5(n)(o),s=U(_=>({startT:0,endT:0+Nf(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:gi("EdgeWindow",_,cs("Extend",Wc))}))(Ei(a.entering.edges)),u=U(_=>({startT:0,endT:i,target:gi("NodeWindow",_,Ac)}))(Ei(a.entering.nodes)),c=J(Jn)(0)(U(_=>Nf(t.edgeSpeed)(t.minEdgeDuration)(e)(_))(Ei(a.leaving.edges))),g=_=>le(h=>{const p=fu(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;f()},Ei(a.leaving.edges))?c:0,d=U(_=>({startT:g(_),endT:g(_)+t.plop,target:gi("NodeWindow",_,gx)}))(Ei(a.leaving.nodes)),l=U(_=>({startT:0,endT:Nf(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:gi("EdgeWindow",_,cs("Retract",S5(r)(a.leaving.nodes)(_)))}))(Ei(a.leaving.edges));return{duration:(()=>{const _=Pt(ot.compare)([...U(p=>p.endT)(l),...U(p=>p.endT)(d),...U(p=>p.endT)(u),...U(p=>p.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+t.gap:t.gap})(),windows:[...l,...d,...u,...s]}},O5=t=>e=>n=>r=>o=>i=>U((()=>{const a=o.startT;return s=>({...s,startT:s.startT+a,endT:s.endT+a})})())(vp(t)(e)(n)(r)(i).windows),q5=t=>vt(e=>Zt(Ko,e).length>1?v("Just",(()=>{const n=Rt(r=>w,r=>o=>v("Just",{head:r,tail:o}),Zt(Ko,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";f()})()):w)(Wm(Zo)(Pt(A.compare)(t))),H5=t=>{const e=U(r=>r.id)(t),n=y5(e);return[...U(N5)(q5(e)),...U(v5)(dt(r=>!wf(r)(n),St(t)(F5)))]},$5=t=>{const e=fp(U(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];f()})()))(t)),n=r=>o=>i=>{if(wf(i)(o))return[ao("ScheduleCycle",[...Zt(dn.foldr,o),i])];if(wf(i)(r))return[];const a=dp(i)(e);if(a.tag==="Nothing")return[];if(a.tag==="Just")return St(a._1)(n(rt(A)(i)()(r))(rt(A)(i)()(o)));f()};return St(t)(r=>n(F)(F)(r.id))},U5={plop:.5,gap:0,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:0,stillHold:1.8,hatchHold:0,tokenReadSecPerChar:.06,nodeEasing:Cy,edgeEasing:_r,tokenEasing:$_,diveDur:2.45,retreatDur:2.45},V5=t=>e=>n=>r=>U((()=>{const o=n.startT;return i=>({...i,startT:i.startT+o,endT:i.endT+o})})())(vt(k5)(xp(t)(e)(r.events))),X5=t=>e=>n=>r=>o=>{if(o.scene.tag==="Structural")return O5(t)(e)(n)(r)(o)(o.scene._1);if(o.scene.tag==="Hold")return[];if(o.scene.tag==="DataFlow")return V5(t)(e)(o)(o.scene._1);if(o.scene.tag==="EnterNode")return[];if(o.scene.tag==="ExitNode")return[];if(o.scene.tag==="StepScene")return[];f()},Y5=t=>e=>n=>{const r=xp(t)(e)(n.events);return r.length===0?t.gap:J(Jn)(0)(U(o=>o.endT)(r))+t.gap},K5=t=>e=>n=>r=>o=>{if(o.tag==="Structural")return vp(t)(e)(n)(r)(o._1).duration;if(o.tag==="Hold")return t.stillHold;if(o.tag==="DataFlow")return Y5(t)(e)(o._1);if(o.tag==="EnterNode"||o.tag==="ExitNode"||o.tag==="StepScene")return 0;f()},Tp=t=>e=>n=>r=>o=>i=>{const a=ry(e)(r),s=n.layout,u=O_(U(m=>b(m.id,m))(o.keyframes)),c=0<o.keyframes.length?v("Just",o.keyframes[0]):w,g=(()=>{if(c.tag==="Just")return c._1.id;if(c.tag==="Nothing")return"";f()})(),d=Jy(o),l=m=>({startT:m.runStart,endT:m.t,path:r,layout:s,placement:a,windows:m.runWindows,spans:m.runSpans,keyframes:u,initialKeyframe:g,edgeEndpoints:d}),_=m=>({segments:m.runSpans.length===0?m.segments:Ct(m.segments)(l(m)),spans:m.spans,windows:m.windows,dives:m.dives}),h=J(m=>y=>{if(y.tag==="EnterNode"){const C=_(m),L=m.runSpans.length===0?{...C,segments:Ct(C.segments)(l(m))}:C,S=m.t+t.diveDur,P=Ct(r)(y._1),M=Tp(t)(e)(z5(n)(y._1))(P)(G5(o)(y._1))(S),W=M.endT+t.retreatDur;return{...m,t:W,runStart:W,runSpans:[],runWindows:[],segments:[...L.segments,...M.segments],spans:[...L.spans,...M.spans],windows:[...L.windows,...M.windows],dives:[...L.dives,{startT:m.t,endT:S,node:y._1,parentPath:r,childPath:P,direction:fx},...M.dives,{startT:M.endT,endT:W,node:y._1,parentPath:r,childPath:P,direction:_x}]}}if(y.tag==="ExitNode")return m;const x=m.t+K5(t)(s)(u)(d)(y),N={startT:m.t,endT:x,scene:y},T=X5(t)(s)(u)(d)(N);return{...m,t:x,runSpans:Ct(m.runSpans)(N),runWindows:[...m.runWindows,...T],spans:Ct(m.spans)(N),windows:[...m.windows,...T]}})({t:i,runStart:i,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(o.scenes),p=_(h);return{endT:h.t,spans:p.spans,windows:Pt(m=>y=>ot.compare(m.startT)(y.startT))(p.windows),segments:p.segments,dives:p.dives}},j5=t=>e=>{const n=ot.compare(t.time)(e.time);return n==="EQ"?A.compare(t.id)(e.id):n},Dn=t=>e=>e-J(n=>r=>n+Jn(0)(pp(e)(r.endT)-r.startT))(0)(t),Z5=t=>e=>{const n=Jn(t.startT)(e.startT),r=pp(t.endT)(e.endT);return r>n+1e-4?v("Just",{startT:n,endT:r}):w},tL=t=>e=>{if(e.scene.tag==="Structural"){const n=J(r=>o=>({cursor:Jn(r.cursor)(o.endT),cuts:o.startT>r.cursor+1e-4?Ct(r.cuts)({startT:r.cursor,endT:o.startT}):r.cuts}))({cursor:e.startT,cuts:[]})(Pt(r=>o=>ot.compare(r.startT)(o.startT))(vt(Z5(e))(t)));return e.endT>n.cursor+1e-4?Ct(n.cuts)({startT:n.cursor,endT:e.endT}):n.cuts}return[]},eL=t=>{const e=A5(St(t.spans)(tL(t.windows)));return e.length===0?t:{...t,endT:Dn(e)(t.endT),spans:U(n=>({...n,startT:Dn(e)(n.startT),endT:Dn(e)(n.endT)}))(t.spans),windows:Pt(n=>r=>ot.compare(n.startT)(r.startT))(U(n=>({...n,startT:Dn(e)(n.startT),endT:Dn(e)(n.endT)}))(t.windows)),segments:U(n=>({...n,startT:Dn(e)(n.startT),endT:Dn(e)(n.endT),spans:U(r=>({...r,startT:Dn(e)(r.startT),endT:Dn(e)(r.endT)}))(n.spans),windows:Pt(r=>o=>ot.compare(r.startT)(o.startT))(U(r=>({...r,startT:Dn(e)(r.startT),endT:Dn(e)(r.endT)}))(n.windows))}))(t.segments),dives:U(n=>({...n,startT:Dn(e)(n.startT),endT:Dn(e)(n.endT)}))(t.dives)}},nL=t=>{const e=U(B5)(t.segments);return eL({...t,segments:e,windows:Pt(n=>r=>ot.compare(n.startT)(r.startT))(St(e)(n=>n.windows))})},rL=t=>e=>n=>{const r=Jn(.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=b5(n),a=U(u=>et(x5(1)(ci(u).length)))(i),s=Jn(1)(J(sr)(0)(a));return qt(u=>c=>({lineIndex:u,text:c,start:o(J(sr)(0)(u<1?[]:It(0,u,a))/s),end:o(u>=0&&u<a.length?(J(sr)(0)(u<1?[]:It(0,u,a))+a[u])/s:(J(sr)(0)(u<1?[]:It(0,u,a))+1)/s)}))(i)},oL=t=>{const e=Jn(0)(t.window.endT-t.window.startT);return U(n=>({...Np,id:"token:"+t.eventId+":line:"+ue(n.lineIndex),kind:"tokenLine",time:t.window.startT+n.start*e,endTime:t.window.startT+n.end*e,path:yp(t.path),tokenIndex:t.tokenIndex,lineIndex:n.lineIndex,text:n.text,from:t.from,to:t.to}))(rL(t.holdPre)(t.holdPost)(t.labels))},iL=t=>St(qt(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)(L5)))(oL),aL=t=>qt(e=>n=>({...n,index:e}))(Pt(j5)([...St(t.segments)(W5),...iL(t.segments)])),sL=t=>e=>{if(e.tag==="Structural")return vt(n=>n)([_u(e._1.from)(t)?w:v("Just",ao("UnknownKeyframe",e._1.from)),_u(e._1.to)(t)?w:v("Just",ao("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return vt(n=>n)([_u(e._1)(t)?w:v("Just",ao("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...vt(n=>n)([_u(e._1.keyframe)(t)?w:v("Just",ao("UnknownKeyframe",e._1.keyframe))]),...H5(e._1.events),...$5(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];if(e.tag==="StepScene")return[];f()},uL=t=>e=>{const n=St(e)(sL(t));return n.length===0?Ot("Right",void 0):Ot("Left",n)},cL=t=>e=>n=>r=>{if(0<n.keyframes.length){const o=n.keyframes[0],i=O_(U(s=>b(s.id,s))(n.keyframes)),a=uL(i)(n.scenes);return(()=>{if(a.tag==="Left"){const s=a._1;return u=>Ot("Left",s)}if(a.tag==="Right"){const s=a._1;return u=>u(s)}f()})()(()=>{const s=nL(Tp(e)(r)(r)([])(n)(0));return Ot("Right",{totalDuration:s.endT,windows:s.windows,spans:s.spans,keyframes:i,initialKeyframe:o.id,timing:e,layout:r.layout,cameraSpans:k1(t)(My)(r.layout)(i)(s),cameraConfig:t,levelTree:r,segments:s.segments,dives:s.dives,cues:aL(s),seed:n.seed})})}return Ot("Left",[w5])},Oo=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(o=>n(o._1)(o._2)),Apply0:()=>Jp(t)}),Jp=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>o=>i=>e.map(a=>b(r(a._1),a._2))(o(i))};return{apply:(()=>{const r=Oo(t);return o=>i=>r.bind(o)(a=>r.bind(i)(s=>qo(t).pure(a(s))))})(),Functor0:()=>n}},qo=t=>({pure:e=>n=>t.Applicative0().pure(b(e,n)),Apply0:()=>Jp(t)}),bp=t=>{const e={Applicative0:()=>qo(t),Bind1:()=>Oo(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},Ho=(t,e)=>({tag:t,_1:e}),vr=(t,e)=>({tag:t,_1:e}),du=t=>t,Zn=(t,e)=>({tag:t,_1:e}),vf=t=>t,be=bp(Ln),gL=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},fL=ge(A)(Mt),Tf=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},_L=J(t=>e=>rt(A)(e)()(t))(F),$t=Oo(Ln),Ve=be.state(t=>b(t,t)),de=qo(Ln),Cp=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},kp=Hr(de),Jf=kp(Mt),dL=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},Tr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},lL=(()=>{const t=fn.unfoldr(e=>{if(e.tag==="Nil")return w;if(e.tag==="Cons")return v("Just",b(e._1,e._2));f()});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)));f()};return n(e,V)})())})(),tr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},hL=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},lu=t=>e=>n=>J(r=>o=>t.Bind1().bind(r)(i=>e(i)(o)))(t.Applicative0().pure(n)),pL=J(t=>e=>rt(A)(e)()(t))(F),mL=(()=>{const t=(e=>n=>{let r=e,o=n,i=!0,a;for(;i;){const s=r,u=o;if(u.tag==="Nil"){i=!1,a=s;continue}if(u.tag==="Cons"){r=rt(A)(u._1)()(s),o=u._2;continue}f()}return a})(F);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)));f()};return n(e,V)})())})(),yL=kp(o_),xL=J(t=>e=>rt(A)(e)()(t))(F),wL=vf("AnimatedSurface"),NL=vf("StillSurface"),vL=vf("SequenceSurface"),TL=Zn("Exit"),hu=du("AnimatedKeyframe"),bf=du("Still"),JL=du("Title"),Lp=du("StepMarker"),bL=t=>vr("Par",t),CL=t=>vr("Seq",t),kL=t=>vr("GroupSeq",t),Sp=t=>Ho("StepDive",t),LL={line:0,column:0,endLine:0,endColumn:0},SL=t=>e=>n=>{const r=Lr(Vt,w,o=>o._1===t,n);if(r.tag==="Just"){const o=Ur(Vt,w,r._1,b(t,e),n);if(o.tag==="Nothing")return n;if(o.tag==="Just")return o._1;f()}if(r.tag==="Nothing")return Ct(n)(b(t,e));f()},EL=t=>e=>U(n=>n._1===t?b(n._1,{...n._2,label:v("Just",e)}):b(n._1,n._2)),Ep=t=>{const e=t.compare;return n=>J(r=>o=>Oe(e,Qe,r,n(o)))(F)},Cf=Ep(A),kf=Ep(A),PL=t=>{const e=t.span;return be.state(n=>b(void 0,{...n,currentSpan:e}))},AL=t=>e=>({structural:[...t.structural,...e.structural],flow:t.flow||e.flow,dives:[...t.dives,...e.dives]}),GL=t=>e=>e.kind==="Animated"||gL(e.id)(t),Pp={graphNodes:[],graphEdges:F,currNodes:F,currEdges:F,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:w,currentSpan:LL,error:w,enterStack:[],interiorOf:F,stepNames:F},Ap=t=>e=>n=>{const r=Zt(dn.foldr,n);return dr(", ")(U(e)(It(0,6,r)))+(r.length>6?", \u2026":"")},IL=t=>e=>{const n=Tf(e)(fL(U(r=>b(r.id,r))(t.graph.edges)));if(n.tag==="Just")return(()=>{const r=mo("conn:")(n._1.id);if(r.tag==="Just")return!1;if(r.tag==="Nothing")return!0;f()})()?n._1.from.node+" -> "+n._1.to.node:n._1.from.node+" -- "+n._1.to.node;if(n.tag==="Nothing")return e;f()},DL=t=>e=>n=>{const r=Ap()(Bi)(e),o=Ap()(IL(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."},RL=t=>{if(t.kind.tag==="SendToken")return _L([t.kind._1.from,t.kind._1.to]);if(t.kind.tag==="FillNodeWithoutTransition")return oe("Node",1,1,t.kind._1.node,void 0,F,F);f()},BL=t=>Cf(RL)(t.events),FL=t=>{if(t.kind.tag==="SendToken")return oe("Node",1,1,t.kind._1.edge,void 0,F,F);if(t.kind.tag==="FillNodeWithoutTransition")return F;f()},ML=t=>kf(FL)(t.events),er=t=>be.state(e=>b(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:v("Just",{msg:t,line:e.currentSpan.line,column:e.currentSpan.column,endLine:e.currentSpan.endLine,endColumn:e.currentSpan.endColumn})};f()})())),zL=Jf(t=>$t.bind(Ve)(e=>{if(e.error.tag==="Just")return de.pure();if(e.error.tag==="Nothing")return Cp(t.node)(e.interiorOf)?er("node "+t.node+" has more than one `inside` block"):be.state(n=>b(void 0,{...n,interiorOf:rt(A)(t.node)(t.doc)(n.interiorOf)}));f()})),QL=t=>$t.bind(Ve)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ue(e.kfCounter);if(le(o=>o.id===n,e.keyframes))return er("duplicate frame name "+n);const r={...e,keyframes:Ct(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges,kind:Ui}),kfCounter:e.kfCounter+1|0,currentKf:v("Just",n)};return be.state(o=>b(void 0,r))}),sn=t=>e=>$t.bind(be.state(n=>b(void 0,{...n,currentSpan:t})))(()=>er(e)),Gp=t=>e=>$t.bind(Ve)(n=>dL(e)(n.stepNames)?sn(t)("duplicate step name "+e):be.state(r=>b(void 0,{...r,scenes:Ct(r.scenes)(ai("StepScene",e)),stepNames:rt(A)(e)()(r.stepNames)}))),WL=t=>{if(t.ops.tag==="Leaf"){const e=t.ops._1;return $t.bind((()=>{const n=e.span;return be.state(r=>b(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?Gp(e.span)(e.op._1.name):er("step marker frame did not contain a step"))}if(t.ops.tag==="Seq"&&t.ops._1.length===1&&t.ops._1[0].tag==="Leaf"){const e=t.ops._1[0]._1;return $t.bind((()=>{const n=e.span;return be.state(r=>b(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?Gp(e.span)(e.op._1.name):er("step marker frame did not contain a step"))}return er("step marker frame did not contain a step")},OL=t=>$t.bind((()=>{const e=t.span;return be.state(n=>b(void 0,{...n,currentSpan:e}))})())(()=>$t.bind(Ve)(e=>{if(e.error.tag==="Just")return de.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!Tr(t.op._1.id)(e.currNodes))return sn(0<t.operands.length?t.operands[0]:t.span)("cannot dive into node "+t.op._1.id+": does not exist");if(!Cp(t.op._1.id)(e.interiorOf))return sn(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=>b(void 0,{...r,enterStack:St(r.enterStack)(n.id),scenes:St(r.scenes)(Vo("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=Nr(e.enterStack);if(n.tag==="Nothing")return Yn("`out` without a matching `into`");if(n.tag==="Just"){const r=n._1.init;return Je.state(o=>b(void 0,{...o,enterStack:r,scenes:St(o.scenes)(u2)}))}g()}return ge.pure()}g()})),Qa={structural:[],flow:!1,dives:[]},q5=Vt.bind(He)(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=>b(void 0,{...n,scenes:St(n.scenes)(Vo("Hold",e))}))}if(t.currentKf.tag==="Nothing")return ge.pure()}g()}),H5=t=>e=>Vt.bind(He)(n=>{const r="ev-"+ie(n.eventCounter);return Vt.bind((()=>{const o={...n,eventCounter:n.eventCounter+1|0};return Je.state(i=>b(void 0,o))})())(()=>ge.pure({events:[{id:r,kind:e,when:t}],firstId:N("Just",r),lastId:N("Just",r)}))}),$5=t=>t.tag==="DataFlow"?N("Just",t._1):J,V5=t=>vt(e=>Fg(e)(t.graphEdges))(Zt(Ao,l5(t.currEdges))),U5=t=>e=>{const n=ft(o=>o.from.node===e.id||o.to.node===e.id,V5(t)),r=Ia(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(!Kn(s)(t.currEdges))return Wt("Left",c);const _="via "+i.from+" "+i.to+": no edge "+e.id+"\u2192"+i.to;if(!Kn(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 Kn(u)(t.currEdges)||h5(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=>!Kn(a.id)(i),n);return s.length===0?Wt("Right",{nextCurrEdges:Qe(P.compare,Ie,$n(P.compare,t.currEdges,p5(q(a=>a.id)(n))),m5((()=>{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 ("+sr(", ")(q(a=>(()=>{const u=ao("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.")})},Wh=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}},Oh=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq"||t.tag==="GroupSeq")return Et(t._1)(Oh);g()},K5=t=>({nodes:q(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 Zt(de.foldr,e(t.graphEdges,$))})(),constraints:[]}),Og=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"?{...Qa,structural:[t._1]}:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?{...Qa,dives:[t._1]}:{...Qa,flow:!0};if(t.tag==="Seq"||t.tag==="GroupSeq"||t.tag==="Par")return v(P5)(Qa)(q(Og)(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"?[Po("StepStructural",[t._1])]:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?[Po("StepDive",t._1)]:[Po("StepFlow",t)];if(t.tag==="Seq")return Et(t._1)(za);if(t.tag==="GroupSeq")return X5(t)(t._1);if(t.tag==="Par")return Y5(t)(t._1);g()},Y5=t=>e=>{const n=Og(t);return n.structural.length!==0&&!n.flow&&n.dives.length===0?[Po("StepStructural",n.structural)]:n.structural.length===0&&n.flow&&n.dives.length===0?[Po("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?q(Ih)(n.dives):Et(e)(za)},X5=t=>e=>{const n=Og(t);return n.structural.length===0&&n.flow&&n.dives.length===0?[Po("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?q(Ih)(n.dives):Et(e)(za)},j5=t=>e=>Vt.bind(He)(n=>{const r=e.from+"->"+e.to,o=e.newFrom+"->"+e.newTo;return Kn(r)(n.currEdges)?mr(e.newFrom)(n.currNodes)?mr(e.newTo)(n.currNodes)?r!==o&&Kn(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=>b(void 0,{...i,currEdges:rt(P)(o)()(Wo(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")}),Z5=t=>{if(t.op.tag==="AddNode"){const e=t.op._1;return Vt.bind(He)(n=>mr(e.id)(n.currNodes)?un(0<t.operands.length?t.operands[0]:t.span)("cannot add node "+e.id+": already exists"):Je.state(r=>b(void 0,{...r,graphNodes:L5(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(He)(n=>{if(!mr(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=U5(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=>b(void 0,{...i,currNodes:Wo(P)(e.id)(i.currNodes),currEdges:o.nextCurrEdges,graphEdges:Qe(P.compare,Ie,o.synthesized,i.graphEdges)}))}g()})}if(t.op.tag==="ModNode"){const e=t.op._1;return Vt.bind(He)(n=>{if(!mr(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=>b(void 0,{...o,graphNodes:E5(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(He)(n=>{const r=!mr(e.from)(n.currNodes),o=!mr(e.to)(n.currNodes);if(r||o)return un(Wh(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 Kn(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=>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(He)(n=>{const r=e.directed?e.from+"->"+e.to:e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;return Kn(r)(n.currEdges)?Je.state(o=>b(void 0,{...o,currEdges:Wo(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"?j5(t)(t.op._1):ge.pure()},tS=t=>Vt.bind((()=>{const e=t.span;return Je.state(n=>b(void 0,{...n,currentSpan:e}))})())(()=>Z5(t)),qh=t=>e=>n=>Vt.bind(Qg(tS)(n))(()=>Vt.bind(He)(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(y5(G5)(0<n.length?N("Just",n[0]):J))(()=>Yn("duplicate frame name "+o));const i={...r,keyframes:St(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 St(r.scenes)(Vo("Structural",{from:r.currentKf._1,to:o,focus:J}));g()})()};return Je.state(s=>b(void 0,i))})),Hh=t=>e=>{const n=Oh(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=>b(void 0,{...s,currentSpan:i}))})())(()=>Yn("still/title blocks hold a still snapshot; they cannot contain movement tokens (`api ~> db`) or dive commands (`into`/`out`)")):t==="TitleCard"&&r.length===0?Yn(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(qh(t)(e.name)(r))(()=>q5)},eS=t=>e=>{const n=vt($5)(e.scenes),r=ft(B5(x5(q(s=>s.keyframe)(n))),e.keyframes),o=$n(P.compare,Mg(s=>s.nodes)(r),Mg(I5)(n)),i=$n(P.compare,Wg(s=>s.edges)(r),Wg(Q5)(n));return t!=="AnimatedSurface"||n.length===0||o.tag==="Leaf"&&i.tag==="Leaf"?J:N("Just",R5(e)(o)(i))},nS=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(Kn(r)(t.currEdges))return N("Just",{id:r,direction:Y_});if(Kn(n)(t.currEdges))return N("Just",{id:n,direction:X_});const i=Fg(o)(t.graphEdges);if(i.tag==="Just")return Kn(o)(t.currEdges)?N("Just",{id:o,direction:i._1.from.node===e.from&&i._1.to.node===e.to?Y_:X_}):J;if(i.tag==="Nothing")return J;g()},rS=t=>e=>{if(e.op.tag==="Token"){const n=e.op._1;return Vt.bind(He)(r=>{const o=!mr(n.from)(r.currNodes),i=!mr(n.to)(r.currNodes);if(o||i)return Vt.bind(un(Wh(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=nS(r)(n);if(s.tag==="Just")return H5(t)(o2("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})},oS=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(Ia({Applicative0:()=>Go(kn),Bind1:()=>Eo(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()},iS=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(sS((()=>{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=>b(void 0,{...o,currentSpan:r}))})())(()=>rS(t)(n))}if(e.tag==="Seq"||e.tag==="GroupSeq")return oS(t)(e._1);if(e.tag==="Par")return iS(t)(e._1);g()},sS=t=>Ia({Applicative0:()=>Go(kn),Bind1:()=>Eo(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}),aS=t=>Vt.bind(He)(e=>{if(e.currentKf.tag==="Nothing")return Yn("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return Vt.bind(fs(a2)(t))(r=>Vt.bind(He)(o=>{const i={...o,scenes:St(o.scenes)(Vo("DataFlow",{keyframe:n,events:r.events,focus:J}))};return Je.state(s=>b(void 0,i))}))}g()}),uS=t=>e=>n=>{if(n.tag==="StepStructural")return Vt.bind((()=>{const r=qh(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=M5(t);return o?i:ge.pure()})())(()=>Vt.bind(aS(r))(()=>ge.pure(e||o)))}if(n.tag==="StepDive")return Vt.bind(O5(n._1))(()=>ge.pure(e));g()},$h=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(He)(s=>{if(s.error.tag==="Just")return ge.pure();if(s.error.tag==="Nothing")return Vt.bind(uS(t)(e)(o))(a=>$h(t)(a)(i));g()})}g()},cS=t=>Vt.bind(He)(e=>{if(e.error.tag==="Just")return ge.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return $h(t.name)(!1)(za(t.ops));if(t.kind==="Still")return Hh(i2)(t);if(t.kind==="Title")return Hh(s2)(t);if(t.kind==="StepMarker")return W5(t)}g()}),Vh=t=>Vt.bind(z5(t.interiors))(()=>Vt.bind(Qg(cS)(t.frames))(()=>Vt.bind(He)(e=>{if(e.error.tag==="Just")return ge.pure(Wt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=gS(t.interiors);if(n.tag==="Left")return ge.pure(Wt("Left",n._1));if(n.tag==="Right"){const r={seed:t.seed,graph:K5(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1};return ge.pure((()=>{const o=eS(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()}))),gS=t=>{const e=Ia(c_)(n=>r=>{const o=Vh(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()},yr=(t,e)=>({tag:"ParseError",_1:t,_2:e}),k=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),Ma=(t,e,n)=>({tag:t,_1:e,_2:n}),_S=t=>Ma("More",t),fS=t=>Ma("Lift",t),dS={defer:t=>{const e=Gm(t);return(n,r,o,i,s)=>Pm(e)(n,r,o,i,s)}},Uh={map:t=>e=>(n,r,o,i,s)=>r(a=>e(n,r,o,i,(u,c)=>r(_=>s(u,t(c)))))},lS={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:()=>Uh},hS=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(_u)(c._1);continue}if(c.tag==="Stop"){a=!1,u=e.Applicative0().pure(Ro("Done",b(c._2,c._1)));continue}g()}return u};return t.tailRecM(o)(i=>r(n,_S,fS,(s,a)=>Ma("Stop",s,Wt("Left",a)),(s,a)=>Ma("Stop",s,Wt("Right",a))))}},Xn=(t,e,n,r,o)=>o(t,t._2),pS={index:0,line:1,column:1},mS=(t=>{const e=hS(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(ms)(e(k(n,pS,!1))(r))})(u0),Wa=(t,e,n,r,o)=>o(k(t._1,t._2,!0),void 0),Kh={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:()=>Uh},Yh={pure:t=>(e,n,r,o,i)=>i(e,t),Apply0:()=>Kh},yS={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:()=>Kh},xS={Applicative0:()=>Yh,Bind1:()=>yS},Oa=t=>(e,n,r,o,i)=>n(s=>Xn(e,n,r,o,(a,u)=>n(c=>o(e._3&&!a._3?k(a._1,a._2,!0):a,yr(t,u))))),wS={empty:Oa("No alternative"),Alt0:()=>lS},JS={Applicative0:()=>Yh,Plus1:()=>wS},Dn=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return o=>t.tailRecM(i=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(_u)(o))(r.pure(Ro("Done",void 0))))(s=>r.pure((()=>{if(s.tag==="Loop")return Ro("Loop",kt("Cons",s._1,i));if(s.tag==="Done")return Ro("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})($)(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:()=>xS})(JS),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,x)=>n(y=>i(f._3&&!w._3?k(w._1,w._2,!0):w,x))))))))})},NS=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()}},Xh=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,x)=>o(y=>{const T=m._3&&!w._3?k(w._1,w._2,!0):w;return o(C=>o(S=>{const E=r._3&&!T._3?k(T._1,T._2,!0):T;return e(E,o,i,s,(B,M)=>o(Y=>a(E._3&&!B._3?k(B._1,B._2,!0):B,x)))}))}))}))))))),qg=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=iy()(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)-Wr(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},vS=t=>e=>n=>{let r=t,o=e,i=n,s=!0,a;for(;s;){const u=r,c=o,_=i,d=Is(c);if(d.tag==="Nothing"){s=!1,a=u;continue}if(d.tag==="Just"){r=d._1.tail===""?qg(u)(d._1.head)(_):qg(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=Is(e._1);if(s.tag==="Nothing")return o(e,yr("Unexpected EOF",e._2));if(s.tag==="Just"){if(s._1.head<0||s._1.head>65535)return o(e,yr("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,qg(e._2)(s._1.head)(s._1.tail),!0),a):o(e,yr("Predicate unsatisfied",e._2))}}g()},ds=(t,e,n,r,o)=>t._1===""?o(k(t._1,t._2,!0),void 0):r(t,yr("Expected EOF",t._2)),TS=t=>(e,n,r,o,i)=>{const s=t(e._1);if(s.tag==="Left")return o(e,yr(s._1,e._2));if(s.tag==="Right")return i(k(s._1.remainder,vS(e._2)(s._1.consumed)(s._1.remainder),s._1.consumed!==""),s._1.value);g()},cn=t=>TS(e=>{const n=ao(t)(e);return n.tag==="Just"?Wt("Right",{value:t,consumed:t,remainder:n._1}):Wt("Left","Expected "+Kp(t))}),CS=At(t=>!0),qa=(t,e)=>({tag:t,_1:e}),Hg=NS(Mt),bS=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},kS=ce(P)(Mt),SS=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===`
|
|
14
|
-
`||r==="\r");return(r,o,i,s
|
|
15
|
-
`||e==="\r");return(e,n,r,o,i)=>n(
|
|
16
|
-
`)),
|
|
17
|
-
`||n==="\r");return(n,r,o,i,
|
|
18
|
-
`&&t!=="\r"&&t!=="#"&&t!=="}"&&t!=="{",
|
|
19
|
-
`||t==="\r"||t==="#"||t==="}",
|
|
20
|
-
`||t==="\r"||t==="#"||t==="}"||t==="{",
|
|
21
|
-
`&&t!=="\r"
|
|
22
|
-
`:
|
|
23
|
-
`);return(e,n,r,o,i)=>{const
|
|
24
|
-
`)(t));return
|
|
25
|
-
`)(q(DS)(q($o(QS(e)))(e)))},US=(()=>{const t=xt(At(e=>e==="|"))("'|'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=Dn(ES),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 '|'"),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(w,n,r,o,(y,T)=>n(C=>i(w._3&&!y._3?k(y._1,y._2,!0):y,VS(sr("")(Zt(de.foldr,h)))))))})))})))})(),ls=At(t=>t>="0"&&t<="9"),KS=(()=>{const t=xt(At(e=>e==="_"))("'_'");return(e,n,r,o,i)=>{const s=e._1,a=e._2;return n(u=>Ha(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 x=m._3;return n(y=>{if(x)return o(m,w);const T=e._1,C=e._2;return n(S=>t(k(T,C,!1),n,r,(E,B)=>{const M=E._3;return n(Y=>M?o(E,B):zS(e,n,r,o,i))},i))})},i))})},i))}})(),ze=(()=>{const t=xt(At(e=>e==="_"))("'_'");return(e,n,r,o,i)=>n(s=>{const a=(_,d)=>n(l=>{const f=Dn(KS),h=e._3&&!_._3?k(_._1,_._2,!0):_;return n(p=>f(h,n,r,o,(m,w)=>n(x=>i(h._3&&!m._3?k(m._1,m._2,!0):m,Gi(d)+Or(Zt(de.foldr,w))))))}),u=e._1,c=e._2;return n(_=>Ha(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))})})(),op=(t,e,n,r,o)=>e(i=>ee(t,e,n,r,(s,a)=>e(u=>{const c=xt(ze)("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,x)=>e(y=>{const T=xt(xt(At(S=>S===":"))("':'"))("':'"),C=p._3&&!w._3?k(w._1,w._2,!0):w;return e(S=>T(C,e,n,r,(E,B)=>e(M=>{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 z=xt(ze)("attribute value"),W=Y._3&&!A._3?k(A._1,A._2,!0):A;return e(H=>z(W,e,n,r,(D,F)=>e(L=>{const G=W._3&&!D._3?k(D._1,D._2,!0):D;return e(Q=>ee(G,e,n,r,(V,K)=>e(U=>o(G._3&&!V._3?k(V._1,V._2,!0):V,b(f,F)))))})))})))})))})))})))}))),YS=Xh((()=>{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(x=>op(f,h,p,m,(y,T)=>h(C=>{const S=Dn((()=>{const B=xt(At(M=>M===","))("','");return(M,Y,R,A,j)=>{const Z=M._3;return Y(z=>Y(W=>Y(H=>Y(D=>Y(F=>Y(L=>ee(M,Y,R,(G,Q)=>A(k(G._1,G._2,Z),Q),(G,Q)=>Y(V=>Y(K=>{const U=M._3&&!G._3?k(G._1,G._2,!0):G;return B(U,Y,R,(O,X)=>A(k(O._1,O._2,Z),X),(O,X)=>Y(et=>{const lt=U._3&&!O._3?k(O._1,O._2,!0):O;return Y(bt=>Y(pt=>{const Tt=M._3&&!lt._3?k(lt._1,lt._2,!0):lt;return ee(Tt,Y,R,(Gt,jt)=>A(k(Gt._1,Gt._2,Z),jt),(Gt,jt)=>Y(Ct=>{const Yt=Tt._3&&!Gt._3?k(Gt._1,Gt._2,!0):Gt;return Y(Dt=>Y(wt=>{const mt=M._3&&!Yt._3?k(Yt._1,Yt._2,!0):Yt;return op(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&&!y._3?k(y._1,y._2,!0):y;return h(B=>S(E,h,p,m,(M,Y)=>h(R=>w(E._3&&!M._3?k(M._1,M._2,!0):M,kS([T,...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))))))})})()),XS=(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 YS;if(m.tag==="Nothing")return(x,y,T,C,S)=>S(x,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,x)=>e(y=>l(_,J)),(w,x)=>e(y=>l(k(f,h,!1),N("Just",x))))))})}))),jS=t=>e=>n=>(r,o,i,s,a)=>o(u=>ee(r,o,i,s,(c,_)=>o(d=>{const l=vn(xt(ze)("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:Un("DelEdge",{from:t,to:m._1,directed:n}),operands:[e,m._2]}))))}))),ZS=(t,e,n,r,o)=>e(i=>Xn(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=>ze(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,(x,y)=>r(k(x._1,x._2,d),y),(x,y)=>e(T=>{const C=m._3&&!x._3?k(x._1,x._2,!0):x;return e(S=>{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,yr("Use `~>` / `<~` for movement tokens.",a)))}),B=C._1,M=C._2;return e(Y=>cn("->")(k(B,M,!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,(z,W)=>r(k(z._1,z._2,d),W),E))},E))})})))})))})}))),tL=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>vn(ze)(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==="~"))("'~'"),w=d._3&&!f._3?k(f._1,f._2,!0):f;return e(x=>{const y=(S,E)=>e(B=>{const M=w._3&&!S._3?k(S._1,S._2,!0):S;return e(Y=>{const R=c._1,A=c._2,j=t._3&&!M._3?k(M._1,M._2,!0):M;return e(Z=>ee(j,e,n,r,(z,W)=>e(H=>{const D=xt(At(G=>G==="~"))("'~'"),F=xt(At(G=>G==="<"))("'<'"),L=j._3&&!z._3?k(z._1,z._2,!0):z;return e(G=>{const Q=(U,O)=>e(X=>{const et=O==="~"?xt(cn("~>"))("'~>'"):xt(cn("<~"))("'<~'"),lt=L._3&&!U._3?k(U._1,U._2,!0):U;return e(bt=>et(lt,e,n,r,(pt,Tt)=>e(Gt=>o(lt._3&&!pt._3?k(pt._1,pt._2,!0):pt,b(R,b(A,Tt))))))}),V=L._1,K=L._2;return e(U=>D(k(V,K,!1),e,n,(O,X)=>{const et=O._3;return e(lt=>et?r(L,X):F(L,e,n,(bt,pt)=>r(L,pt),(bt,pt)=>Q(L,pt)))},(O,X)=>Q(L,X)))})})))})}),T=w._1,C=w._2;return e(S=>m(k(T,C,!1),e,n,(E,B)=>{const M=E._3;return e(Y=>M?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=>y(w)))))},(E,B)=>y(w)))})})))})))}),eL=(()=>{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(eo)("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=vn(xt(ze)("source node identifier")),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(w,n,r,o,(y,T)=>n(C=>{const S=T._1,E=T._2,B=w._3&&!y._3?k(y._1,y._2,!0):y;return n(M=>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(z=>j(Z,n,r,o,(W,H)=>n(D=>{const F=Z._3&&!W._3?k(W._1,W._2,!0):W;return n(L=>ee(F,n,r,o,(G,Q)=>n(V=>{const K=vn(xt(ze)("target node identifier")),U=F._3&&!G._3?k(G._1,G._2,!0):G;return n(O=>K(U,n,r,o,(X,et)=>n(lt=>{const bt=et._1,pt=et._2,Tt=U._3&&!X._3?k(X._1,X._2,!0):X;return n(Gt=>ee(Tt,n,r,o,(jt,Ct)=>n(Yt=>{const Dt=xt(cn("=>"))("repoint separator '=>'"),wt=Tt._3&&!jt._3?k(jt._1,jt._2,!0):jt;return n(mt=>Dt(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,(Bt,zt)=>n(ne=>{const Cn=vn(xt(ze)("new source node identifier")),Me=ht._3&&!Bt._3?k(Bt._1,Bt._2,!0):Bt;return n(qt=>Cn(Me,n,r,o,(Ot,We)=>n(bn=>{const tn=We._1,_n=We._2,Ae=Me._3&&!Ot._3?k(Ot._1,Ot._2,!0):Ot;return n(oe=>ee(Ae,n,r,o,(_e,v4)=>n(T4=>{const w4=xt(cn("->"))("replacement edge arrow '->'"),Mp=Ae._3&&!_e._3?k(_e._1,_e._2,!0):_e;return n(C4=>w4(Mp,n,r,o,(iu,b4)=>n(k4=>{const Wp=Mp._3&&!iu._3?k(iu._1,iu._2,!0):iu;return n(S4=>ee(Wp,n,r,o,(su,L4)=>n(E4=>{const J4=vn(xt(ze)("new target node identifier")),Op=Wp._3&&!su._3?k(su._1,su._2,!0):su;return n(G4=>J4(Op,n,r,o,(au,qp)=>n(P4=>i(Op._3&&!au._3?k(au._1,au._2,!0):au,{op:Un("RepointEdge",{from:S,to:bt,newFrom:tn,newTo:qp._1}),operands:[E,pt,_n,qp._2]}))))})))})))})))})))})))})))})))})))})))})))})))})))})))})))})(),nL=(t,e,n,r,o)=>e(i=>ls(t,e,n,r,(s,a)=>e(u=>{const c=Dn(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=O0(Gi(a)+Or(Zt(de.foldr,f)));return(()=>{if(p.tag==="Just"){const m=p._1;return(w,x,y,T,C)=>C(w,m)}if(p.tag==="Nothing")return(m,w,x,y,T)=>T(m,0);g()})()(_._3&&!l._3?k(l._1,l._2,!0):l,e,n,r,o)})))}))),rL=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,x,y)=>{const T=p._1,C=p._2;return m(S=>Ha(k(T,C,!1),m,w,(E,B)=>{const M=E._3;return m(Y=>{if(M)return x(E,B);const R=p._1,A=p._2;return m(j=>ls(k(R,A,!1),m,w,(Z,z)=>{const W=Z._3;return m(H=>{if(W)return x(Z,z);const D=p._1,F=p._2;return m(L=>f(k(D,F,!1),m,w,(G,Q)=>{const V=G._3;return m(K=>V?x(G,Q):h(p,m,w,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 w=l._3&&!h._3?k(h._1,h._2,!0):h;return n(x=>ln(w,n,r,(y,T)=>o(k(y._1,y._2,s),T),(y,T)=>n(C=>i(w._3&&!y._3?k(y._1,y._2,!0):y,t))))})))})))},Tn=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,x,y)=>{const T=p._1,C=p._2;return m(S=>Ha(k(T,C,!1),m,w,(E,B)=>{const M=E._3;return m(Y=>{if(M)return x(E,B);const R=p._1,A=p._2;return m(j=>ls(k(R,A,!1),m,w,(Z,z)=>{const W=Z._3;return m(H=>{if(W)return x(Z,z);const D=p._1,F=p._2;return m(L=>f(k(D,F,!1),m,w,(G,Q)=>{const V=G._3;return m(K=>V?x(G,Q):h(p,m,w,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))))})))},oL=(t,e,n,r,o)=>e(i=>Tn("into")(t,e,n,r,(s,a)=>e(u=>{const c=xt(eo)("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=vn(xt(ze)("node identifier after 'into'")),m=_._3&&!l._3?k(l._1,l._2,!0):l;return e(w=>p(m,e,n,r,(x,y)=>e(T=>o(m._3&&!x._3?k(x._1,x._2,!0):x,{op:Un("Enter",{id:y._1}),operands:[y._2]}))))})))}))),iL=(t,e,n,r,o)=>e(i=>Tn("out")(t,e,n,r,(s,a)=>e(u=>o(t._3&&!s._3?k(s._1,s._2,!0):s,{op:v5,operands:[]})))),sL=(t,e,n,r,o)=>e(i=>Tn("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(nL)("integer (seed value)"),p=c._3&&!d._3?k(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(w,x)=>e(y=>{const T=p._3&&!w._3?k(w._1,w._2,!0):w;return e(C=>ln(T,e,n,r,(S,E)=>e(B=>o(T._3&&!S._3?k(S._1,S._2,!0):S,x))))})))})))}))),ip=(t,e,n,r,o)=>{const i=t._3;return e(s=>Tn("diagram")(t,e,n,(a,u)=>r(k(a._1,a._2,i),u),(a,u)=>e(c=>{const _=xt(eo)("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(Tn("sequence"))("diagram mode"),w=d._3&&!f._3?k(f._1,f._2,!0):f;return e(x=>m(w,e,n,(y,T)=>r(k(y._1,y._2,i),T),(y,T)=>e(C=>{const S=w._3&&!y._3?k(y._1,y._2,!0):y;return e(E=>ep(S,e,n,(B,M)=>r(k(B._1,B._2,i),M),(B,M)=>e(Y=>o(S._3&&!B._3?k(B._1,B._2,!0):B,N5))))})))})))})))},sp=(t,e,n,r,o)=>{const i=t._3;return e(s=>Tn("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=>ep(_,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,J5))))})))},ap=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(a=>sp(k(i,s,!1),e,n,(u,c)=>{const _=u._3;return e(d=>_?r(u,c):ip(t,e,n,r,o))},o))},aL=t=>(e,n,r,o,i)=>n(s=>Xn(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 ap(_,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,yr((()=>{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))))})}))),uL=t=>(e,n,r,o,i)=>n(s=>Xn(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 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,C,S,E)=>S(y,yr(x,u))}if(m.tag==="Nothing")return(x,y,T,C,S)=>S(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=>ap(k(f,h,!1),n,r,(w,x)=>{const y=w._3;return n(T=>y?o(w,x):l(_,J))},(w,x)=>n(y=>l(w,N("Just",x))))))})}))),cL=(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(x=>uL(_)(w,e,n,r,(y,T)=>e(C=>o(w._3&&!y._3?k(y._1,y._2,!0):y,_))))})))}),a=t._1,u=t._2;return e(c=>sp(k(a,u,!1),e,n,(_,d)=>{const l=_._3;return e(f=>l?r(_,d):ip(t,e,n,r,s))},s))}),gL=(t,e,n,r,o)=>e(i=>{const s=(c,_)=>e(d=>o(c,(()=>{if(_.tag==="Nothing")return w5;if(_.tag==="Just")return _._1;g()})())),a=t._1,u=t._2;return e(c=>e(_=>cL(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))))))}),_L=(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(_=>Tn("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=>Wa(h,e,n,r,(m,w)=>e(x=>{const y=h._3&&!m._3?k(m._1,m._2,!0):m;return e(T=>eo(y,e,n,r,(C,S)=>e(E=>{const B=xt(ze)("source node identifier after 'via'"),M=y._3&&!C._3?k(C._1,C._2,!0):C;return e(Y=>B(M,e,n,r,(R,A)=>e(j=>{const Z=M._3&&!R._3?k(R._1,R._2,!0):R;return e(z=>ee(Z,e,n,r,(W,H)=>e(D=>{const F=xt(ze)("target node identifier after 'via'"),L=Z._3&&!W._3?k(W._1,W._2,!0):W;return e(G=>F(L,e,n,r,(Q,V)=>e(K=>o(L._3&&!Q._3?k(Q._1,Q._2,!0):Q,{from:A,to:V}))))})))})))})))})))})))))}),fL=t=>e=>{const n=Dn(_L);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:Un("DelNode",{id:t,via:Zt(de.foldr,_)}),operands:[e]}))))},dL=(()=>{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(eo)("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=vn(xt(ze)("node identifier after '-'")),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(w,n,r,o,(y,T)=>n(C=>{const S=T._1,E=T._2,B=w._3&&!y._3?k(y._1,y._2,!0):y;return n(M=>np(B,n,r,o,(Y,R)=>n(A=>(()=>{if(R.tag==="Just")return jS(S)(E)(R._1);if(R.tag==="Nothing")return fL(S)(E);g()})()(B._3&&!Y._3?k(Y._1,Y._2,!0):Y,n,r,o,i))))})))})))})))})(),jn=t=>e=>(n,r,o,i,s)=>r(a=>Xn(n,r,o,i,(u,c)=>r(_=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return r(l=>Tn(t)(d,r,o,i,(f,h)=>r(p=>i(d._3&&!f._3?k(f._1,f._2,!0):f,yr(e,c)))))}))),lL=t=>t==="AnimatedSurface"?(e,n,r,o,i)=>n(s=>Xn(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>Tn("step")(_,n,r,o,(l,f)=>n(h=>{const p=xt(eo)("space after 'step'"),m=_._3&&!l._3?k(l._1,l._2,!0):l;return n(w=>p(m,n,r,o,(x,y)=>n(T=>{const C=vn(xt(ze)("step name")),S=m._3&&!x._3?k(x._1,x._2,!0):x;return n(E=>C(S,n,r,o,(B,M)=>n(Y=>{const R=M._1,A=M._2,j=S._3&&!B._3?k(B._1,B._2,!0):B;return n(Z=>Xn(j,n,r,o,(z,W)=>n(H=>{const D=j._3&&!z._3?k(z._1,z._2,!0):z;return n(F=>ee(D,n,r,o,(L,G)=>n(Q=>{const V=D._3&&!L._3?k(L._1,L._2,!0):L;return n(K=>Zh(V,n,r,o,(U,O)=>n(X=>{const et=V._3&&!U._3?k(U._1,U._2,!0):U;return n(lt=>ln(et,n,r,o,(bt,pt)=>n(Tt=>{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:pr("Leaf",{op:Un("Step",{name:R}),line:Gt.line,column:Gt.column,endLine:Gt.endLine,endColumn:Gt.endColumn,span:Gt,operands:[A]}),kind:Ah})})))})))})))})))})))})))})))}))):jn("step")("`step` markers are only supported in animated diagrams."),hL=(()=>{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=Dn(At(PS)),m=_._3&&!l._3?k(l._1,l._2,!0):l;return n(w=>p(m,n,r,o,(x,y)=>n(T=>i(m._3&&!x._3?k(x._1,x._2,!0):x,As(Or(Zt(de.foldr,y)))))))})))})))})(),pL=(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=>hL(k(h,p,!1),_,d,(w,x)=>{const y=w._3;return _(T=>{if(y)return l(w,x);const C=c._1,S=c._2;return _(E=>US(k(C,S,!1),_,d,(B,M)=>{const Y=B._3;return _(R=>Y?l(B,M):HS(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)))),$a=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?((x,y,T,C,S)=>S(x,J)):(x,y,T,C,S)=>y(E=>pL(x,y,T,C,(B,M)=>y(Y=>S(B,N("Just",M))))))(_._3&&!p._3?k(p._1,p._2,!0):p,n,r,o,i)),f=_._1,h=_._2;return n(p=>{const m=(w,x)=>{const y=w._3;return n(T=>y?o(w,x):l(_,!1))};return n(w=>n(x=>n(y=>ds(k(f,h,!1),n,r,(T,C)=>{const S=T._3;return n(E=>S?m(k(f,h,!1),C):n(B=>At(t)(k(f,h,!1),n,r,(M,Y)=>m(k(f,h,!1),Y),(M,Y)=>n(R=>n(A=>l(k(f,h,!1),!0))))))},(T,C)=>n(S=>n(E=>l(k(f,h,!1),!0)))))))})})}))),mL=t=>e=>n=>(r,o,i,s,a)=>o(u=>ee(r,o,i,s,(c,_)=>o(d=>{const l=vn(xt(ze)("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 x=m._1,y=m._2,T=f._3&&!p._3?k(p._1,p._2,!0):p;return o(C=>$a(Vg)(T,o,i,s,(S,E)=>o(B=>a(T._3&&!S._3?k(S._1,S._2,!0):S,{op:Un("AddEdge",{from:t,to:x,label:E.tag==="Just"?N("Just",E._1):J,directed:n}),operands:[e,y]}))))})))}))),yL=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>vn(ze)(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==="<"))("'<'"),w=d._3&&!f._3?k(f._1,f._2,!0):f;return e(x=>m(w,e,n,(y,T)=>r(k(w._1,w._2,s),T),(y,T)=>e(C=>{const S=Ji((B,M,Y,R,A)=>{const j=B._3;return cn("<-")(B,M,Y,(Z,z)=>R(k(Z._1,Z._2,j),z),A)}),E=w._3&&!w._3?k(w._1,w._2,!0):w;return e(B=>S(E,e,n,(M,Y)=>r(k(M._1,M._2,s),Y),(M,Y)=>e(R=>{const A=E._3&&!M._3?k(M._1,M._2,!0):M;return e(j=>{const Z=c._1,z=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(L=>{const G=xt(cn("<~"))("'<~'"),Q=W._3&&!D._3?k(D._1,D._2,!0):D;return e(V=>G(Q,e,n,r,(K,U)=>e(O=>{const X=Q._3&&!K._3?k(K._1,K._2,!0):K;return e(et=>ee(X,e,n,r,(lt,bt)=>e(pt=>{const Tt=vn(xt(ze)("target node identifier")),Gt=X._3&&!lt._3?k(lt._1,lt._2,!0):lt;return e(jt=>Tt(Gt,e,n,r,(Ct,Yt)=>e(Dt=>{const wt=Yt._1,mt=Yt._2,ct=Gt._3&&!Ct._3?k(Ct._1,Ct._2,!0):Ct;return e(yt=>$a(Vg)(ct,e,n,r,(dt,ht)=>e(Lt=>o(ct._3&&!dt._3?k(dt._1,dt._2,!0):dt,{op:Un("Token",{from:wt,to:Z,labels:(()=>{if(ht.tag==="Nothing")return[];if(ht.tag==="Just")return[ht._1];g()})()}),operands:[mt,z]}))))})))})))})))})))})})))})))})))})))}),xL=(t,e,n,r,o)=>e(i=>tL(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=vn(xt(ze)("target node identifier")),x=l._3&&!h._3?k(h._1,h._2,!0):h;return e(y=>w(x,e,n,r,(T,C)=>e(S=>{const E=C._1,B=C._2,M=x._3&&!T._3?k(T._1,T._2,!0):T;return e(Y=>$a(Vg)(M,e,n,r,(R,A)=>e(j=>(c==="<~"?((Z,z,W,H,D)=>D(Z,{op:Un("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,z,W,H,D)=>D(Z,{op:Un("Token",{from:_,to:E,labels:(()=>{if(A.tag==="Nothing")return[];if(A.tag==="Just")return[A._1];g()})()}),operands:c==="<~"?[B,d]:[d,B]}))(M._3&&!R._3?k(R._1,R._2,!0):R,e,n,r,o))))})))})))}))),wL=(t,e,n,r,o)=>e(i=>$a(RS)(t,e,n,r,(s,a)=>e(u=>o(s,(()=>{if(a.tag==="Nothing")return"";if(a.tag==="Just")return a._1;g()})())))),JL=t=>e=>(n,r,o,i,s)=>r(a=>wL(n,r,o,i,(u,c)=>r(_=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return r(l=>XS(d,r,o,i,(f,h)=>r(p=>s(d._3&&!f._3?k(f._1,f._2,!0):f,{op:Un("AddNode",{id:t,label:c,shape:(()=>{const m=SS("shape")(h);if(m.tag==="Just")return m._1==="rectangle"||m._1==="rect"?qr:m._1==="cylinder"||m._1==="cyl"?Wm:m._1==="parallelogram"?Om:m._1==="diamond"?qm:m._1==="ellipse"?Hm:m._1==="document"||m._1==="doc"?$m:m._1==="cloud"?Vm:qr;if(m.tag==="Nothing")return qr;g()})()}),operands:[e]}))))}))),NL=(()=>{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(eo)("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=vn(xt(ze)("node identifier after '+'")),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(w,n,r,o,(y,T)=>n(C=>{const S=T._1,E=T._2,B=w._3&&!y._3?k(y._1,y._2,!0):y;return n(M=>np(B,n,r,o,(Y,R)=>n(A=>(()=>{if(R.tag==="Just")return mL(S)(E)(R._1);if(R.tag==="Nothing")return JL(S)(E);g()})()(B._3&&!Y._3?k(Y._1,Y._2,!0):Y,n,r,o,i))))})))})))})))})(),vL=(t,e,n,r,o)=>e(i=>Xn(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`."),ZS,NL,dL,eL,xL,yL,oL,iL]))("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=>Xn(p,e,n,r,(w,x)=>e(y=>{const T={line:a.line,column:a.column,endLine:x.line,endColumn:x.column};return o(p._3&&!w._3?k(w._1,w._2,!0):w,pr("Leaf",{op:f.op,line:T.line,column:T.column,endLine:T.endLine,endColumn:T.endColumn,span:T,operands:f.operands}))})))})))}))),Ug=Xh((()=>{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 '}'")),up=(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,x)=>r(k(w._1,w._2,s),x),(w,x)=>e(y=>{const T=t._3&&!w._3?k(w._1,w._2,!0):w;return e(C=>Wa(T,e,n,r,(S,E)=>e(B=>{const M=Hg([CL,TL,vL]),Y=T._3&&!S._3?k(S._1,S._2,!0):S;return e(R=>M(Y,e,n,r,(A,j)=>e(Z=>{const z=Y._3&&!A._3?k(A._1,A._2,!0):A;return e(W=>ee(z,e,n,r,(H,D)=>e(F=>{const L=z._3&&!H._3?k(H._1,H._2,!0):H;return e(G=>Zh(L,e,n,r,(Q,V)=>e(K=>{const U=L._3&&!Q._3?k(Q._1,Q._2,!0):Q;return e(O=>ln(U,e,n,r,(X,et)=>e(lt=>o(U._3&&!X._3?k(X._1,X._2,!0):X,j))))})))})))})))})))})))))})))}),TL=(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=>Tn("seq")(t,e,n,(m,w)=>r(k(m._1,m._2,h),w),(m,w)=>e(x=>{const y=t._3&&!m._3?k(m._1,m._2,!0):m;return e(T=>ee(y,e,n,(C,S)=>r(k(C._1,C._2,h),S),(C,S)=>e(E=>$g(y._3&&!C._3?k(C._1,C._2,!0):C,e,n,(B,M)=>r(k(B._1,B._2,h),M),(B,M)=>e(Y=>{const R=t._3&&!B._3?k(B._1,B._2,!0):B;return e(A=>Wa(R,e,n,r,(j,Z)=>e(z=>{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,L)=>e(G=>o(H._3&&!F._3?k(F._1,F._2,!0):F,pr("GroupSeq",[])))))})))})))))})))}))};return e(c=>e(_=>Tn("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 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(C=>Ug(Kg(k5))(x,e,n,u,o)))})))))))})},CL=(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=>Tn("par")(t,e,n,(m,w)=>r(k(m._1,m._2,h),w),(m,w)=>e(x=>{const y=t._3&&!m._3?k(m._1,m._2,!0):m;return e(T=>ee(y,e,n,(C,S)=>r(k(C._1,C._2,h),S),(C,S)=>e(E=>$g(y._3&&!C._3?k(C._1,C._2,!0):C,e,n,(B,M)=>r(k(B._1,B._2,h),M),(B,M)=>e(Y=>{const R=t._3&&!B._3?k(B._1,B._2,!0):B;return e(A=>Wa(R,e,n,r,(j,Z)=>e(z=>{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,L)=>e(G=>o(H._3&&!F._3?k(F._1,F._2,!0):F,pr("Par",[])))))})))})))))})))}))};return e(c=>e(_=>Tn("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 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(C=>Ug(Kg(C5))(x,e,n,u,o)))})))))))})},Kg=t=>{const e=Dn(up);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=>rL(t)(n,r,o,i,(u,c)=>r(_=>{const d=Dn(At(AS)),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(y=>y==="{"))("'{'"))("'{'"),x=l._3&&!h._3?k(h._1,h._2,!0):h;return r(y=>w(x,r,o,i,(T,C)=>r(S=>{const E=x._3&&!T._3?k(T._1,T._2,!0):T;return r(B=>ln(E,r,o,i,(M,Y)=>r(R=>{const A=Kg(b5),j=E._3&&!M._3?k(M._1,M._2,!0):M;return r(Z=>A(j,r,o,i,(z,W)=>r(H=>{const D=j._3&&!z._3?k(z._1,z._2,!0):z;return r(F=>ln(D,r,o,i,(L,G)=>r(Q=>{const V=xt(xt(At(U=>U==="}"))("'}'"))("closing '}'"),K=D._3&&!L._3?k(L._1,L._2,!0):L;return r(U=>V(K,r,o,i,(O,X)=>r(et=>{const lt=K._3&&!O._3?k(O._1,O._2,!0):O;return r(bt=>ln(lt,r,o,i,(pt,Tt)=>r(Gt=>s(lt._3&&!pt._3?k(pt._1,pt._2,!0):pt,{name:WS(Or(Zt(de.foldr,p))),ops:W,kind:e}))))})))})))})))})))})))})))}))),bL=(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=>Yg("scene")(Fa)(k(l,f,!1),e,n,(p,m)=>{const w=p._3;return e(x=>{if(w)return r(p,m);const y=t._1,T=t._2;return e(C=>Yg("still")(zg)(k(y,T,!1),e,n,(S,E)=>{const B=S._3;return e(M=>B?r(S,E):Yg("title")(T5)(t,e,n,r,o))},o))})},o))})},o))},kL=t=>e=>n=>{if(t==="AnimatedSurface")return{...e,frames:St(e.frames)({name:J,ops:n,kind:Fa})};if(t==="StillSurface")return{...e,statements:St(e.statements)(n)};if(t==="SequenceSurface")return{...e,statements:St(e.statements)(n)};g()},SL=t=>e=>n=>{if(n.tag==="TopFrame"){const r=rp(t)(e);return{...r,frames:St(r.frames)((()=>{if(t==="AnimatedSurface")return n._1;if(t==="StillSurface")return{...n._1,kind:n._1.kind==="AnimatedKeyframe"?zg:n._1.kind==="StepMarker"?Ah:n._1.kind};if(t==="SequenceSurface")return n._1;g()})())}}if(n.tag==="TopStatement")return kL(t)(e)(n._1);if(n.tag==="TopInside")return e;g()},LL=t=>{const e=v(SL(t))($S);return n=>rp(t)(e(n)).frames},EL=t=>dS.defer(e=>{const n=lL(t);return(r,o,i,s,a)=>{const u=r._1,c=r._2;return o(_=>aL(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(x=>GL(k(p,m,!1),o,i,(y,T)=>{const C=y._3;return o(S=>{if(C)return s(y,T);const E=r._1,B=r._2;return o(M=>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 z=r._1,W=r._2;return o(H=>o(D=>bL(k(z,W,!1),o,i,(F,L)=>{const G=F._3;return o(Q=>G?s(F,L):o(V=>up(r,o,i,s,(K,U)=>o(O=>a(K,qa("TopStatement",U))))))},(F,L)=>o(G=>a(F,qa("TopFrame",L))))))})},(R,A)=>o(j=>a(R,qa("TopFrame",A))))))})},(y,T)=>o(C=>a(y,qa("TopInside",T))))))})},a))}}),GL=(t,e,n,r,o)=>e(i=>Tn("inside")(t,e,n,r,(s,a)=>e(u=>{const c=xt(eo)("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(ze)("node identifier after 'inside'"),m=_._3&&!l._3?k(l._1,l._2,!0):l;return e(w=>p(m,e,n,r,(x,y)=>e(T=>{const C=m._3&&!x._3?k(x._1,x._2,!0):x;return e(S=>ln(C,e,n,r,(E,B)=>e(M=>{const Y=C._3&&!E._3?k(E._1,E._2,!0):E;return e(R=>Ug(cp)(Y,e,n,r,(A,j)=>e(Z=>{const z=Y._3&&!A._3?k(A._1,A._2,!0):A;return e(W=>ln(z,e,n,r,(H,D)=>e(F=>o(z._3&&!H._3?k(H._1,H._2,!0):H,{node:y,doc:j}))))})))})))})))})))}))),cp=(t,e,n,r,o)=>e(i=>gL(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=Dn(EL(a)),x=c._3&&!h._3?k(h._1,h._2,!0):h;return e(y=>w(x,e,n,r,(T,C)=>e(S=>{const E=Zt(de.foldr,C);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:LL(a)(E),interiors:vt(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=>sL(k(l,f,!1),e,n,(m,w)=>{const x=m._3;return e(y=>x?r(m,w):d(c,J))},(m,w)=>e(x=>d(m,N("Just",w))))))})}))),PL=(()=>{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 cp(h,n,r,o,(p,m)=>n(w=>{const x=h._3&&!p._3?k(p._1,p._2,!0):p;return n(y=>n(T=>{const C=e._3&&!x._3?k(x._1,x._2,!0):x;return t(C,n,r,o,(S,E)=>n(B=>i(C._3&&!S._3?k(S._1,S._2,!0):S,m)))}))}))})))))))})(),BL=t=>{const e=mS(t)(PL);if(e.tag==="Left")return Wt("Left",{msg:MS(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()},DL=t=>{const e=BL(t);if(e.tag==="Left")return Wt("Left",e._1.msg);if(e.tag==="Right")return Wt("Right",e._1);g()},RL=()=>({tag:"ParFrag"}),gp=t=>t,AL=gp("Sync"),IL=gp("SelfMsg"),FL=RL(),no=Bh(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},qn=Eo(kn),Fr=no.state(t=>b(t,t)),_p=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Va=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Bo=Go(kn),QL=t=>e=>v(n=>r=>Eo(kn).bind(n)(o=>t(o)(r)))(Go(kn).pure(e)),fp=Qr(Bo)(Mt),zL=t=>no.state(e=>b(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:N("Just",t)};g()})())),ML=t=>e=>no.state(n=>b(void 0,{...n,lifelines:J_(P)(r=>N("Just",{...r,label:e}))(t)(n.lifelines)})),WL=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:""},OL={lifelines:I,lifelineOrder:[],messages:[],fragments:[],frameEndRows:[],row:0,error:J},qL=t=>e=>n=>qn.bind(Fr)(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?IL:AL},...r.messages],row:r.row+1|0};return no.state(a=>b(void 0,s))}return zL("token references unknown node: "+WL(r)(t)(e))}),HL=t=>no.state(e=>b(void 0,{...e,lifelines:J_(P)(n=>N("Just",{...n,destroyedAt:N("Just",e.row)}))(t)(e.lifelines)})),$L=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:Va(0)(e.lifelineOrder.length-1|0)};if(r.tag==="Just")return v(o=>i=>({fromCol:_p(o.fromCol)(_p(i.fromCol)(i.toCol)),toCol:Va(o.toCol)(Va(i.fromCol)(i.toCol))}))({fromCol:n,toCol:0})(t);g()},VL=t=>({lifelines:vt(e=>Ni(e)(t.lifelines))(t.lifelineOrder),messages:se(t.messages),fragments:se(t.fragments),frameEndRows:t.frameEndRows,totalRows:t.row}),UL=t=>e=>qn.bind(Fr)(n=>{const r=Ni(t)(n.lifelines);if(r.tag==="Just")return Bo.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:St(n.lifelineOrder)(t),row:n.row>0||n.messages.length!==0?n.row+1|0:n.row};return no.state(i=>b(void 0,o))}g()}),KL=t=>{if(t.tag==="AddNode")return UL(t._1.id)(t._1.label);if(t.tag==="DelNode")return HL(t._1.id);if(t.tag==="ModNode"){if(t._1.label.tag==="Just")return ML(t._1.id)(t._1.label._1);if(t._1.label.tag==="Nothing")return Bo.pure();g()}return t.tag==="Token"?qL(t._1.from)(t._1.to)(t._1.labels):Bo.pure()},YL=t=>qn.bind(Fr)(e=>{const n=e.row;return qn.bind(QL(r=>o=>qn.bind(Fr)(i=>{const s=r.childMessages.length===0?r.dividers:[i.row,...r.dividers],a=i.messages;return qn.bind(Xg(o))(()=>qn.bind(Fr)(u=>Bo.pure({dividers:s,childMessages:[...r.childMessages,...(()=>{const c=u.messages.length-a.length|0;return c<1?[]:Rt(0,c,u.messages)})()]})))}))({dividers:[],childMessages:[]})(t))(r=>qn.bind(Fr)(o=>{const i=$L(r.childMessages)(o),s={kind:FL,label:"par",fromRow:n,toRow:Va(o.row)(n+1|0),fromCol:i.fromCol,toCol:i.toCol,regionDividers:se(r.dividers)},a=no.state(u=>b(void 0,{...u,fragments:[s,...u.fragments]}));return r.childMessages.length>=2?a:Bo.pure()}))}),Xg=t=>{if(t.tag==="Leaf")return KL(t._1.op);if(t.tag==="Seq"||t.tag==="GroupSeq")return fp(Xg)(t._1);if(t.tag==="Par")return YL(t._1);g()},XL=t=>{const e=qn.bind(fp(n=>qn.bind(Fr)(r=>qn.bind(Xg(n.ops))(()=>qn.bind(Fr)(o=>{const i=no.state(s=>b(void 0,{...s,frameEndRows:St(s.frameEndRows)(s.row-1|0)}));return(o.messages.length-r.messages.length|0)>0?i:Bo.pure()}))))(t.frames))(()=>Fr)(OL)._1;if(e.error.tag==="Just")return Wt("Left",e.error._1);if(e.error.tag==="Nothing")return Wt("Right",VL(e));g()},jL=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ZL={padding:24,headerHeight:36,headerWidth:120,columnSpacing:160,rowHeight:36,topGap:24,bottomGap:24},tE=t=>{const e=84+nt(jL(1)(t.totalRows))*36,n=Ht(r=>o=>({lifeline:o,x:84+nt(r)*160}))(t.lifelines);return{metrics:ZL,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}},eE=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},dp=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},lp=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},hp=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},nE=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},rE=v(t=>e=>rt(it)(e)()(t))(I),oE={r:255,g:255,b:255,a:255},Ua={r:26,g:26,b:26,a:255},iE={color:{r:232,g:232,b:232,a:255},flat:!0},sE={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],pp=t=>e=>n=>({...n,stack:St(n.stack)(t),openedAt:rt(it)(t)(e)(n.openedAt)}),Ya=t=>e=>{const n=e.stack.length-1|0;if(n>=0&&n<e.stack.length){const r=eE(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?[]:Rt(0,e.stack.length-1|0,e.stack),openedAt:Wo(it)(e.stack[n])(e.openedAt),spans:St(e.spans)({col:e.stack[n],fromRow:o,toRow:dp(o)(t)})}}return e},mp=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=Ya(c)(_);continue}s=!1,a=_}return a},yp=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=Ya(s)(a);continue}o=!1,i=a}return i},aE=t=>e=>{const n=en(zr)(e.fromCol)(t.stack)?mp((()=>{const r=e.fromCol;return o=>r===o})())(e.row-1|0)(t):pp(e.fromCol)(e.row)(yp(e.row-1|0)(t));if(en(zr)(e.toCol)(n.stack)){const r=mp((()=>{const o=e.toCol;return i=>o===i})())(e.row-1|0)(Ya(e.row)(n));return{...r,returnRows:rt(it)(e.row)()(r.returnRows)}}return pp(e.toCol)(e.row)(n)},uE=t=>e=>n=>{const r=aE(e)(n);return lp(n.row)(t)?yp(n.row)(r):r},Xa={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:es,lineCap:Vn},xp={r:26,g:26,b:26,a:255},cE={color:{r:130,g:130,b:130,a:255},width:1,lineJoin:es,lineCap:Gn},wp={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:es,lineCap:Gn},gE={color:{r:244,g:244,b:244,a:255},flat:!0},Jp=t=>e=>n=>Ne(r=>r.col===e&&r.fromRow<=n&&n<=r.toRow,t),Np={color:{r:90,g:90,b:90,a:255},width:1,lineJoin:es,lineCap:Gn},_E={stack:[],openedAt:I,spans:[],returnRows:I},fE={color:{r:150,g:150,b:150,a:255},width:1,lineJoin:es,lineCap:Gn},dE=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])(fE)},lE=t=>{const e=t.Monad0(),n=e.Bind1(),r=Io(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(dp(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])(Np))(()=>n.bind(t.fillStrokePath(u)(iE)(Np))(()=>n.bind(t.drawText({x:a+6,y:s+7,content:"par",font:{family:"Inter",size:11,weight:700},color:Ua,align:_i,baseline:En}))(()=>r(i.regionDividers)(dE(t)(o)(a)(c)))))}},vp=t=>e=>t>=e?[]:[b(t,hp(e)(t+6)),...vp(t+10)(e)],hE=t=>e=>{if(e<=t)return[];const n=r=>r>=e?[]:[b(r,hp(e)(r+6)),...n(r+10)];return n(t)},pE=t=>{const e=Io(t.Monad0().Applicative0())(Mt);return n=>r=>e(hE(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])(cE))},Tp=t=>e=>t<=e?[]:[b(t,nE(e)(t-6)),...Tp(t-6-4)(e)],mE=t=>e=>t===e?[]:t<e?vp(t)(e):Tp(t)(e),yE=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:sE,flat:!0})(wp))(()=>e.bind(t.fillStrokePath(a)(gE)(wp))(()=>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:Gr,baseline:En})))}},xE=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=Ya(s)(a);continue}o=!1,i=a}return i},wE=t=>xE((()=>{const e=t.diagram.messages.length-1|0;return e>=0&&e<t.diagram.messages.length?t.diagram.messages[e].row:0})())(v(uE(rE(t.diagram.frameEndRows)))(_E)(ft(e=>e.kind==="Sync"||e.kind!=="SelfMsg",t.diagram.messages))),JE=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])(Xa))(()=>e.bind(t.fillPath(_)({color:xp,flat:!0}))(()=>t.drawText({x:i+42,y:o,content:sr(" ")(q(Ci)(r.labels)),font:{family:"Inter",size:12,weight:400},color:Ua,align:_i,baseline:En})))}},NE=t=>{const e=t.Monad0(),n=e.Bind1(),r=Io(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)+(Jp(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)-(Jp(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])(Xa):t.fillPath([1,d,u,2,l,u-5,2,l,u+5,...rs])({color:xp,flat:!0});return n.bind(s?r(mE(_)(d))(h=>t.strokePath([1,h._1,u,2,h._2,u])(Xa)):t.strokePath([1,_,u,2,d,u])(Xa))(()=>n.bind(f)(()=>t.drawText({x:(_+d)/2,y:u-6,content:sr(" ")(q(Ci)(a.labels)),font:{family:"Inter",size:12,weight:400},color:Ua,align:Gr,baseline:Yv})))}},vE=t=>{const e=JE(t),n=NE(t);return r=>o=>i=>s=>{if(s.kind==="SelfMsg")return e(r)(s);if(s.kind==="Sync")return n(r)(o)(lp(s.row)(i))(s);g()}},Cp={color:{r:26,g:26,b:26,a:255},width:1.25,lineJoin:Ve,lineCap:Gn},TE={color:{r:232,g:232,b:232,a:255},flat:!0},CE={color:{r:252,g:252,b:252,a:255},flat:!0},bE=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))(TE)(Cp))(()=>t.fillStrokePath(s)(CE)(Cp))},bp=t=>{const e=t.Monad0(),n=e.Bind1(),r=Io(e.Applicative0())(Mt),o=yE(t),i=pE(t),s=lE(t),a=vE(t);return u=>{const c=wE(u);return n.bind(t.setViewport({vx:0,vy:0,vw:u.width,vh:u.height}))(()=>n.bind(t.clearBackground(oE))(()=>n.bind(r(u.columns)(o(u)))(()=>n.bind(r(u.columns)(i(u)))(()=>n.bind(r(c.spans)(bE(t)(u)))(()=>n.bind(r(u.diagram.fragments)(s(u)))(()=>r(u.diagram.messages)(a(u)(c.spans)(c.returnRows))))))))}},kE=bp(hT);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 SE(t){return function(e){return function(){return e.getAttribute(t)}}}const kp=t=>{const e=SE(t);return n=>{const r=e(n);return()=>{const o=r();return mn(o,J,Kt)}}};function LE(t){return function(e){return function(){e.textContent=t}}}function EE(t){return function(){return function(e){return t(e)()}}}function GE(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const Zg=function(){return window};function PE(t){return function(e){return function(){e.value=t}}}function BE(t){return function(){return t.valueAsNumber}}function DE(t){return function(){return t.value}}function t_(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const Sp=t=>t,ja=t=>()=>{const e=t.getBoundingClientRect?.(),n=e?.width||t.clientWidth||0,r=e?.height||t.clientHeight||0;return{width:n,height:r}},Lp=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)}},Ep=()=>window.devicePixelRatio||1,RE=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
|
-
<rect x="0" y="0" width="${i}" height="${
|
|
27
|
-
<text x="${i/2}" y="${
|
|
28
|
-
<text x="${i/2}" y="${
|
|
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(
|
|
14
|
+
}`);const n=t.op._1;return be.state(r=>b(void 0,{...r,enterStack:Ct(r.enterStack)(n.id),scenes:Ct(r.scenes)(ai("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=Sr(e.enterStack);if(n.tag==="Nothing")return er("`out` without a matching `into`");if(n.tag==="Just"){const r=n._1.init;return be.state(o=>b(void 0,{...o,enterStack:r,scenes:Ct(o.scenes)(ly)}))}f()}return de.pure()}f()})),pu={structural:[],flow:!1,dives:[]},qL=$t.bind(Ve)(t=>{if(t.error.tag==="Just")return de.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return be.state(n=>b(void 0,{...n,scenes:Ct(n.scenes)(ai("Hold",e))}))}if(t.currentKf.tag==="Nothing")return de.pure()}f()}),HL=t=>e=>$t.bind(Ve)(n=>{const r="ev-"+ue(n.eventCounter);return $t.bind((()=>{const o={...n,eventCounter:n.eventCounter+1|0};return be.state(i=>b(void 0,o))})())(()=>de.pure({events:[{id:r,kind:e,when:t}],firstId:v("Just",r),lastId:v("Just",r)}))}),$L=t=>t.tag==="DataFlow"?v("Just",t._1):w,UL=t=>vt(e=>Tf(e)(t.graphEdges))(Zt(Ko,lL(t.currEdges))),VL=t=>e=>{const n=dt(o=>o.from.node===e.id||o.to.node===e.id,UL(t)),r=lu(e_)(o=>i=>{const a=i.from+"->"+e.id,s=e.id+"->"+i.to,u=i.from+"->"+i.to,c="via "+i.from+" "+i.to+": no edge "+i.from+"\u2192"+e.id;if(!tr(a)(t.currEdges))return Ot("Left",c);const g="via "+i.from+" "+i.to+": no edge "+e.id+"\u2192"+i.to;if(!tr(s)(t.currEdges))return Ot("Left",g);const d="via "+i.from+" "+i.to+": would create "+i.from+"\u2192"+i.to+" but it already exists";return tr(u)(t.currEdges)||hL(u)(o.synthesized)?Ot("Left",d):Ot("Right",{consumed:rt(A)(a)()(rt(A)(s)()(o.consumed)),synthesized:rt(A)(u)({id:u,from:{node:i.from,port:w},to:{node:i.to,port:w},label:w})(o.synthesized)})})({consumed:F,synthesized:F})(e.via);return(()=>{if(r.tag==="Left"){const o=r._1;return i=>Ot("Left",o)}if(r.tag==="Right"){const o=r._1;return i=>i(o)}f()})()(o=>{const i=o.consumed,a=dt(s=>!tr(s.id)(i),n);return a.length===0?Ot("Right",{nextCurrEdges:Oe(A.compare,Qe,Vn(A.compare,t.currEdges,pL(U(s=>s.id)(n))),mL((()=>{const s=u=>{if(u.tag==="Leaf")return F;if(u.tag==="Node")return oe("Node",u._1,u._2,u._3,void 0,s(u._5),s(u._6));f()};return s(o.synthesized)})())),synthesized:o.synthesized}):Ot("Left","cannot delete node "+e.id+": still connected ("+dr(", ")(U(s=>(()=>{const u=mo("conn:")(s.id);if(u.tag==="Just")return!1;if(u.tag==="Nothing")return!0;f()})()?s.from.node+"\u2192"+s.to.node:s.from.node+"--"+s.to.node)(a))+"). Use `- a -> b` or `- a -- b` to drop them, or `via a b` to merge "+e.id+"'s endpoints.")})},Ip=t=>e=>n=>{if(t){if(e){const i=0<n.operands.length?n.operands[0]:n.span,a=1<n.operands.length?n.operands[1]:n.span;return{line:i.line,column:i.column,endLine:a.endLine,endColumn:a.endColumn}}return 0<n.operands.length?n.operands[0]:n.span}if(e)return 1<n.operands.length?n.operands[1]:n.span;const r=0<n.operands.length?n.operands[0]:n.span,o=1<n.operands.length?n.operands[1]:n.span;return{line:r.line,column:r.column,endLine:o.endLine,endColumn:o.endColumn}},Dp=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq"||t.tag==="GroupSeq")return St(t._1)(Dp);f()},XL=t=>({nodes:U(Ra)(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)));f()};return Zt(ye.foldr,e(t.graphEdges,V))})(),constraints:[]}),Lf=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"?{...pu,structural:[t._1]}:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?{...pu,dives:[t._1]}:{...pu,flow:!0};if(t.tag==="Seq"||t.tag==="GroupSeq"||t.tag==="Par")return J(AL)(pu)(U(Lf)(t._1));f()},mu=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"?[Ho("StepStructural",[t._1])]:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?[Ho("StepDive",t._1)]:[Ho("StepFlow",t)];if(t.tag==="Seq")return St(t._1)(mu);if(t.tag==="GroupSeq")return KL(t)(t._1);if(t.tag==="Par")return YL(t)(t._1);f()},YL=t=>e=>{const n=Lf(t);return n.structural.length!==0&&!n.flow&&n.dives.length===0?[Ho("StepStructural",n.structural)]:n.structural.length===0&&n.flow&&n.dives.length===0?[Ho("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?U(Sp)(n.dives):St(e)(mu)},KL=t=>e=>{const n=Lf(t);return n.structural.length===0&&n.flow&&n.dives.length===0?[Ho("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?U(Sp)(n.dives):St(e)(mu)},jL=t=>e=>$t.bind(Ve)(n=>{const r=e.from+"->"+e.to,o=e.newFrom+"->"+e.newTo;return tr(r)(n.currEdges)?Tr(e.newFrom)(n.currNodes)?Tr(e.newTo)(n.currNodes)?r!==o&&tr(o)(n.currEdges)?sn((()=>{const i=2<t.operands.length?t.operands[2]:t.span,a=3<t.operands.length?t.operands[3]:t.span;return{line:i.line,column:i.column,endLine:a.endLine,endColumn:a.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists"):be.state(i=>b(void 0,{...i,currEdges:rt(A)(o)()(oi(A)(r)(i.currEdges)),graphEdges:rt(A)(o)({id:o,from:{node:e.newFrom,port:w},to:{node:e.newTo,port:w},label:w})(i.graphEdges)})):sn(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):sn(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):sn((()=>{const i=0<t.operands.length?t.operands[0]:t.span,a=1<t.operands.length?t.operands[1]:t.span;return{line:i.line,column:i.column,endLine:a.endLine,endColumn:a.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist")}),ZL=t=>{if(t.op.tag==="AddNode"){const e=t.op._1;return $t.bind(Ve)(n=>Tr(e.id)(n.currNodes)?sn(0<t.operands.length?t.operands[0]:t.span)("cannot add node "+e.id+": already exists"):be.state(r=>b(void 0,{...r,graphNodes:SL(e.id)({id:e.id,size:b(1,1),ports:[],label:v("Just",e.label),shape:e.shape})(r.graphNodes),currNodes:rt(A)(e.id)()(r.currNodes)})))}if(t.op.tag==="DelNode"){const e=t.op._1;return $t.bind(Ve)(n=>{if(!Tr(e.id)(n.currNodes))return sn(0<t.operands.length?t.operands[0]:t.span)("cannot delete node "+e.id+": does not exist");const r=VL(n)(e);if(r.tag==="Left")return sn(0<t.operands.length?t.operands[0]:t.span)(r._1);if(r.tag==="Right"){const o=r._1;return be.state(i=>b(void 0,{...i,currNodes:oi(A)(e.id)(i.currNodes),currEdges:o.nextCurrEdges,graphEdges:Oe(A.compare,Qe,o.synthesized,i.graphEdges)}))}f()})}if(t.op.tag==="ModNode"){const e=t.op._1;return $t.bind(Ve)(n=>{if(!Tr(e.id)(n.currNodes))return sn(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 be.state(o=>b(void 0,{...o,graphNodes:EL(e.id)(r)(o.graphNodes)}))}if(e.label.tag==="Nothing")return de.pure();f()})}if(t.op.tag==="AddEdge"){const e=t.op._1;return $t.bind(Ve)(n=>{const r=!Tr(e.from)(n.currNodes),o=!Tr(e.to)(n.currNodes);if(r||o)return sn(Ip(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 tr(i)(n.currEdges)?sn((()=>{const a=0<t.operands.length?t.operands[0]:t.span,s=1<t.operands.length?t.operands[1]:t.span;return{line:a.line,column:a.column,endLine:s.endLine,endColumn:s.endColumn}})())((e.directed?"cannot add edge ":"cannot add connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": already exists"):be.state(a=>b(void 0,{...a,graphEdges:rt(A)(i)({id:i,from:{node:e.from,port:w},to:{node:e.to,port:w},label:e.label})(a.graphEdges),currEdges:rt(A)(i)()(a.currEdges)}))})}if(t.op.tag==="DelEdge"){const e=t.op._1;return $t.bind(Ve)(n=>{const r=e.directed?e.from+"->"+e.to:e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;return tr(r)(n.currEdges)?be.state(o=>b(void 0,{...o,currEdges:oi(A)(r)(o.currEdges)})):sn((()=>{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"?jL(t)(t.op._1):de.pure()},tS=t=>$t.bind((()=>{const e=t.span;return be.state(n=>b(void 0,{...n,currentSpan:e}))})())(()=>ZL(t)),Rp=t=>e=>n=>$t.bind(Jf(tS)(n))(()=>$t.bind(Ve)(r=>{const o=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ue(r.kfCounter);if(le(a=>a.id===o,r.keyframes))return $t.bind(yL(PL)(0<n.length?v("Just",n[0]):w))(()=>er("duplicate frame name "+o));const i={...r,keyframes:Ct(r.keyframes)({id:o,nodes:r.currNodes,edges:r.currEdges,kind:t}),kfCounter:r.kfCounter+1|0,currentKf:v("Just",o),scenes:(()=>{if(r.currentKf.tag==="Nothing")return r.scenes;if(r.currentKf.tag==="Just")return Ct(r.scenes)(ai("Structural",{from:r.currentKf._1,to:o,focus:w}));f()})()};return be.state(a=>b(void 0,i))})),Bp=t=>e=>{const n=Dp(e.ops),r=dt(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=dt(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?$t.bind((()=>{const i=o[0].span;return be.state(a=>b(void 0,{...a,currentSpan:i}))})())(()=>er("still/title blocks hold a still snapshot; they cannot contain movement tokens (`api ~> db`) or dive commands (`into`/`out`)")):t==="TitleCard"&&r.length===0?er(e.name.tag==="Just"&&e.name._1!==""?'title "'+e.name._1+'" has an empty body; give it nodes/edges to title, or use a still':"title has an empty body; give it nodes/edges to title, or use a still"):$t.bind(Rp(t)(e.name)(r))(()=>qL)},eS=t=>e=>{const n=vt($L)(e.scenes),r=dt(GL(xL(U(a=>a.keyframe)(n))),e.keyframes),o=Vn(A.compare,Cf(a=>a.nodes)(r),Cf(BL)(n)),i=Vn(A.compare,kf(a=>a.edges)(r),kf(ML)(n));return t!=="AnimatedSurface"||n.length===0||o.tag==="Leaf"&&i.tag==="Leaf"?w:v("Just",DL(e)(o)(i))},nS=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(tr(r)(t.currEdges))return v("Just",{id:r,direction:Q_});if(tr(n)(t.currEdges))return v("Just",{id:n,direction:W_});const i=Tf(o)(t.graphEdges);if(i.tag==="Just")return tr(o)(t.currEdges)?v("Just",{id:o,direction:i._1.from.node===e.from&&i._1.to.node===e.to?Q_:W_}):w;if(i.tag==="Nothing")return w;f()},rS=t=>e=>{if(e.op.tag==="Token"){const n=e.op._1;return $t.bind(Ve)(r=>{const o=!Tr(n.from)(r.currNodes),i=!Tr(n.to)(r.currNodes);if(o||i)return $t.bind(sn(Ip(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: "))(()=>de.pure({events:[],firstId:w,lastId:w}));const a=nS(r)(n);if(a.tag==="Just")return HL(t)(gy("SendToken",{from:n.from,to:n.to,edge:a._1.id,direction:a._1.direction,labels:n.labels}));if(a.tag==="Nothing")return $t.bind(sn((()=>{const s=0<e.operands.length?e.operands[0]:e.span,u=1<e.operands.length?e.operands[1]:e.span;return{line:s.line,column:s.column,endLine:u.endLine,endColumn:u.endColumn}})())("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>de.pure({events:[],firstId:w,lastId:w}));f()})}return de.pure({events:[],firstId:w,lastId:w})},oS=t=>e=>{const n=Rt(r=>w,r=>o=>v("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return de.pure({events:[],firstId:w,lastId:w});if(n.tag==="Just"){const r=n._1.tail;return $t.bind(Sa(t)(n._1.head))(o=>$t.bind(lu({Applicative0:()=>qo(Ln),Bind1:()=>Oo(Ln)})(i=>a=>$t.bind(Sa((()=>{if(i.lastId.tag==="Just")return Nc("After",i.lastId._1);if(i.lastId.tag==="Nothing")return t;f()})())(a))(s=>de.pure({events:[...i.events,...s.events],firstId:(()=>{if(i.firstId.tag==="Just")return v("Just",i.firstId._1);if(i.firstId.tag==="Nothing")return s.firstId;f()})(),lastId:(()=>{if(s.lastId.tag==="Just")return v("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return i.lastId;f()})()})))(o)(r))(i=>de.pure(i)))}f()},iS=t=>e=>{const n=Rt(r=>w,r=>o=>v("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return de.pure({events:[],firstId:w,lastId:w});if(n.tag==="Just"){const r=n._1.tail;return $t.bind(Sa(t)(n._1.head))(o=>$t.bind(aS((()=>{if(o.firstId.tag==="Just")return Nc("With",o.firstId._1);if(o.firstId.tag==="Nothing")return t;f()})())(r))(i=>de.pure({events:[...o.events,...i.events],firstId:o.firstId,lastId:(()=>{if(o.lastId.tag==="Just")return v("Just",o.lastId._1);if(o.lastId.tag==="Nothing")return i.lastId;f()})()})))}f()},Sa=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return $t.bind((()=>{const r=n.span;return be.state(o=>b(void 0,{...o,currentSpan:r}))})())(()=>rS(t)(n))}if(e.tag==="Seq"||e.tag==="GroupSeq")return oS(t)(e._1);if(e.tag==="Par")return iS(t)(e._1);f()},aS=t=>lu({Applicative0:()=>qo(Ln),Bind1:()=>Oo(Ln)})(e=>n=>$t.bind(Sa(t)(n))(r=>de.pure({events:[...e.events,...r.events],firstId:(()=>{if(e.firstId.tag==="Just")return v("Just",e.firstId._1);if(e.firstId.tag==="Nothing")return r.firstId;f()})(),lastId:(()=>{if(r.lastId.tag==="Just")return v("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;f()})()})))({events:[],firstId:w,lastId:w}),sS=t=>$t.bind(Ve)(e=>{if(e.currentKf.tag==="Nothing")return er("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return $t.bind(Sa(dy)(t))(r=>$t.bind(Ve)(o=>{const i={...o,scenes:Ct(o.scenes)(ai("DataFlow",{keyframe:n,events:r.events,focus:w}))};return be.state(a=>b(void 0,i))}))}f()}),uS=t=>e=>n=>{if(n.tag==="StepStructural")return $t.bind((()=>{const r=Rp(Ui)(e?w:t)(n._1);return n._1.length!==0?r:de.pure()})())(()=>de.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;f()})();return $t.bind((()=>{const i=QL(t);return o?i:de.pure()})())(()=>$t.bind(sS(r))(()=>de.pure(e||o)))}if(n.tag==="StepDive")return $t.bind(OL(n._1))(()=>de.pure(e));f()},Fp=t=>e=>n=>{const r=Rt(o=>w,o=>i=>v("Just",{head:o,tail:i}),n);if(r.tag==="Nothing")return de.pure();if(r.tag==="Just"){const o=r._1.head,i=r._1.tail;return $t.bind(Ve)(a=>{if(a.error.tag==="Just")return de.pure();if(a.error.tag==="Nothing")return $t.bind(uS(t)(e)(o))(s=>Fp(t)(s)(i));f()})}f()},cS=t=>$t.bind(Ve)(e=>{if(e.error.tag==="Just")return de.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return Fp(t.name)(!1)(mu(t.ops));if(t.kind==="Still")return Bp(fy)(t);if(t.kind==="Title")return Bp(_y)(t);if(t.kind==="StepMarker")return WL(t)}f()}),Mp=t=>$t.bind(zL(t.interiors))(()=>$t.bind(Jf(cS)(t.frames))(()=>$t.bind(Ve)(e=>{if(e.error.tag==="Just")return de.pure(Ot("Left",e.error._1));if(e.error.tag==="Nothing"){const n=gS(t.interiors);if(n.tag==="Left")return de.pure(Ot("Left",n._1));if(n.tag==="Right"){const r={seed:t.seed,graph:XL(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1};return de.pure((()=>{const o=eS(t.mode)(r);if(o.tag==="Just")return Ot("Left",{msg:o._1,line:0,column:0,endLine:0,endColumn:0});if(o.tag==="Nothing")return Ot("Right",r);f()})())}}f()}))),gS=t=>{const e=lu(e_)(n=>r=>{const o=Mp(r.doc)(Pp)._1;return(()=>{if(o.tag==="Left"){const i=o._1;return a=>Ot("Left",i)}if(o.tag==="Right"){const i=o._1;return a=>a(i)}f()})()(i=>Ot("Right",rt(A)(r.node)(i)(n)))})(F)(t);if(e.tag==="Left")return Ot("Left",e._1);if(e.tag==="Right")return Ot("Right",e._1);f()},Jr=(t,e)=>({tag:"ParseError",_1:t,_2:e}),k=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),yu=(t,e,n)=>({tag:t,_1:e,_2:n}),fS=t=>yu("More",t),_S=t=>yu("Lift",t),dS={defer:t=>{const e=R2(t);return(n,r,o,i,a)=>B2(e)(n,r,o,i,a)}},zp={map:t=>e=>(n,r,o,i,a)=>r(s=>e(n,r,o,i,(u,c)=>r(g=>a(u,t(c)))))},lS={alt:t=>e=>(n,r,o,i,a)=>{const s=n._1,u=n._2;return r(c=>t(k(s,u,!1),r,o,(g,d)=>{const l=g._3;return r(_=>l?i(g,d):e(n,r,o,i,a))},a))},Functor0:()=>zp},hS=t=>{const e=t.Monad0();return n=>r=>{const o=i=>{let a=i,s=!0,u;for(;s;){const c=a();if(c.tag==="More"){a=c._1;continue}if(c.tag==="Lift"){s=!1,u=e.Bind1().Apply0().Functor0().map(Uu)(c._1);continue}if(c.tag==="Stop"){s=!1,u=e.Applicative0().pure(Yo("Done",b(c._2,c._1)));continue}f()}return u};return t.tailRecM(o)(i=>r(n,fS,_S,(a,s)=>yu("Stop",a,Ot("Left",s)),(a,s)=>yu("Stop",a,Ot("Right",s))))}},nr=(t,e,n,r,o)=>o(t,t._2),pS={index:0,line:1,column:1},mS=(t=>{const e=hS(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(Ba)(e(k(n,pS,!1))(r))})(dm),xu=(t,e,n,r,o)=>o(k(t._1,t._2,!0),void 0),Qp={apply:t=>e=>(n,r,o,i,a)=>r(s=>t(n,r,o,i,(u,c)=>r(g=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return e(d,r,o,i,(l,_)=>r(h=>a(d._3&&!l._3?k(l._1,l._2,!0):l,c(_))))}))),Functor0:()=>zp},Wp={pure:t=>(e,n,r,o,i)=>i(e,t),Apply0:()=>Qp},yS={bind:t=>e=>(n,r,o,i,a)=>r(s=>t(n,r,o,i,(u,c)=>r(g=>e(c)(n._3&&!u._3?k(u._1,u._2,!0):u,r,o,i,a)))),Apply0:()=>Qp},xS={Applicative0:()=>Wp,Bind1:()=>yS},wu=t=>(e,n,r,o,i)=>n(a=>nr(e,n,r,o,(s,u)=>n(c=>o(e._3&&!s._3?k(s._1,s._2,!0):s,Jr(t,u))))),wS={empty:wu("No alternative"),Alt0:()=>lS},NS={Applicative0:()=>Wp,Plus1:()=>wS},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(Uu)(o))(r.pure(Yo("Done",void 0))))(a=>r.pure((()=>{if(a.tag==="Loop")return Yo("Loop",kt("Cons",a._1,i));if(a.tag==="Done")return Yo("Done",(s=>u=>{let c=s,g=u,d=!0,l;for(;d;){const _=c,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=kt("Cons",h._1,_),g=h._2;continue}f()}return l})(V)(i));f()})())))(V)})({tailRecM:t=>e=>(n,r,o,i,a)=>{const s=(u,c,g)=>t(c)(u,r,o,i,(d,l)=>{const _=u._3&&!d._3?k(d._1,d._2,!0):d;if(l.tag==="Loop")return g===0?r(h=>s(_,l._1,30)):s(_,l._1,g-1|0);if(l.tag==="Done")return a(_,l._1);f()});return s(n,e,30)},Monad0:()=>xS})(NS),mt=t=>e=>{const n=wu("Expected "+e);return(r,o,i,a,s)=>{const u=r._1,c=r._2;return o(g=>t(k(u,c,!1),o,i,(d,l)=>{const _=d._3;return o(h=>_?a(d,l):n(r,o,i,a,s))},s))}},Pi=t=>(e,n,r,o,i)=>{const a=e._3,s=e._1,u=e._2;return n(c=>{const g=(d,l)=>{const _=d._3;return n(h=>_?o(k(d._1,d._2,a),l):i(e,void 0))};return n(d=>n(l=>t(k(s,u,!1),n,r,(_,h)=>g(k(_._1,_._2,!1),h),(_,h)=>n(p=>n(m=>wu("Negated parser succeeded")(_,n,r,g,(y,x)=>n(N=>i(_._3&&!y._3?k(y._1,y._2,!0):y,x))))))))})},vS=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return v("Just",n);if(r.tag==="Just")return v("Just",(o,i,a,s,u)=>{const c=o._1,g=o._2;return i(d=>n(k(c,g,!1),i,a,(l,_)=>{const h=l._3;return i(p=>h?s(l,_):r._1(o,i,a,s,u))},u))});f()})(w);return n=>{const r=e(n);if(r.tag==="Nothing")return wu("No alternative");if(r.tag==="Just")return r._1;f()}},Op=t=>e=>n=>(r,o,i,a,s)=>o(u=>o(c=>o(g=>o(d=>t(r,o,i,a,(l,_)=>o(h=>o(p=>{const m=r._3&&!l._3?k(l._1,l._2,!0):l;return n(m,o,i,a,(y,x)=>o(N=>{const T=m._3&&!y._3?k(y._1,y._2,!0):y;return o(C=>o(L=>{const S=r._3&&!T._3?k(T._1,T._2,!0):T;return e(S,o,i,a,(P,M)=>o(W=>s(S._3&&!P._3?k(P._1,P._2,!0):P,x)))}))}))}))))))),Sf=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=sx()(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)-Vr(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},TS=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,c=o,g=i,d=us(c);if(d.tag==="Nothing"){a=!1,s=u;continue}if(d.tag==="Just"){r=d._1.tail===""?Sf(u)(d._1.head)(g):Sf(u)(d._1.head)(d._1.tail),o=d._1.tail,i=g;continue}f()}return s},Bt=t=>(e,n,r,o,i)=>{const a=us(e._1);if(a.tag==="Nothing")return o(e,Jr("Unexpected EOF",e._2));if(a.tag==="Just"){if(a._1.head<0||a._1.head>65535)return o(e,Jr("Expected Char",e._2));if(a._1.head>=0&&a._1.head<=65535){const s=Y_(a._1.head);return t(s)?i(k(a._1.tail,Sf(e._2)(a._1.head)(a._1.tail),!0),s):o(e,Jr("Predicate unsatisfied",e._2))}}f()},Ea=(t,e,n,r,o)=>t._1===""?o(k(t._1,t._2,!0),void 0):r(t,Jr("Expected EOF",t._2)),JS=t=>(e,n,r,o,i)=>{const a=t(e._1);if(a.tag==="Left")return o(e,Jr(a._1,e._2));if(a.tag==="Right")return i(k(a._1.remainder,TS(e._2)(a._1.consumed)(a._1.remainder),a._1.consumed!==""),a._1.value);f()},un=t=>JS(e=>{const n=mo(t)(e);return n.tag==="Just"?Ot("Right",{value:t,consumed:t,remainder:n._1}):Ot("Left","Expected "+Kf(t))}),bS=Bt(t=>!0),Nu=(t,e)=>({tag:t,_1:e}),Ef=vS(Mt),CS=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},kS=ge(A)(Mt),LS=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Pf=(()=>{const t=mt(Bt(r=>r==="}"))("'}'"),e=mt(Bt(r=>r==="#"))("'#'"),n=Bt(r=>r===`
|
|
15
|
+
`||r==="\r");return(r,o,i,a,s)=>{const u=r._1,c=r._2;return o(g=>o(d=>t(k(u,c,!1),o,i,(l,_)=>o(h=>{const p=r._1,m=r._2;return o(y=>o(x=>e(k(p,m,!1),o,i,(N,T)=>o(C=>{const L=r._1,S=r._2;return o(P=>o(M=>n(k(L,S,!1),o,i,(W,G)=>o(I=>Ea(r,o,i,a,s)),(W,G)=>o(I=>s(k(L,S,!1),void 0)))))}),(N,T)=>o(C=>s(k(p,m,!1),void 0)))))}),(l,_)=>o(h=>s(k(u,c,!1),void 0)))))}})(),bn=t=>(e,n,r,o,i)=>n(a=>nr(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?k(s._1,s._2,!0):s;return n(d=>t(g,n,r,o,(l,_)=>n(h=>{const p=g._3&&!l._3?k(l._1,l._2,!0):l;return n(m=>nr(p,n,r,o,(y,x)=>n(N=>i(p._3&&!y._3?k(y._1,y._2,!0):y,b(_,{line:u.line,column:u.column,endLine:x.line,endColumn:x.column})))))})))}))),SS=(()=>{const t=Bt(e=>e===" "||e===" "||e===`
|
|
16
|
+
`||e==="\r");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>i(e._3&&!s._3?k(s._1,s._2,!0):s,void 0))))})(),qp=(t,e,n,r,o)=>e(i=>un("#")(t,e,n,r,(a,s)=>e(u=>{const c=Rn(Bt(d=>d!==`
|
|
17
|
+
`)),g=t._3&&!a._3?k(a._1,a._2,!0):a;return e(d=>c(g,e,n,r,(l,_)=>e(h=>o(g._3&&!l._3?k(l._1,l._2,!0):l,void 0))))}))),Hp=mt((()=>{const t=mt(Bt(n=>n==="}"))("'}'"),e=Bt(n=>n===`
|
|
18
|
+
`||n==="\r");return(n,r,o,i,a)=>{const s=n._1,u=n._2;return r(c=>r(g=>t(k(s,u,!1),r,o,(d,l)=>r(_=>{const h=n._1,p=n._2;return r(m=>r(y=>qp(k(h,p,!1),r,o,(x,N)=>{const T=x._3;return r(C=>{if(T)return i(x,N);const L=n._1,S=n._2;return r(P=>r(M=>e(k(L,S,!1),r,o,(W,G)=>{const I=W._3;return r(j=>I?i(W,G):Ea(n,r,o,i,a))},(W,G)=>r(I=>a(W,void 0)))))})},(x,N)=>r(T=>a(x,void 0)))))}),(d,l)=>r(_=>a(k(s,u,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),hn=(()=>{const t=Rn((e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>SS(k(a,s,!1),n,r,(c,g)=>{const d=c._3;return n(l=>d?o(c,g):qp(e,n,r,o,i))},i))});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>i(e._3&&!s._3?k(s._1,s._2,!0):s,void 0))))})(),ES=(()=>{const t=Bt(e=>e!=="|");return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>n(c=>un("\\|")(k(a,s,!1),n,r,(g,d)=>n(l=>n(_=>t(e,n,r,o,(h,p)=>n(m=>i(h,Oi(p)))))),(g,d)=>n(l=>i(g,"|")))))}})(),PS=mt(Ef([(t,e,n,r,o)=>e(i=>{const a=t._3;return un("->")(t,e,n,(s,u)=>r(k(s._1,s._2,a),u),(s,u)=>e(c=>o(s,!0)))}),(t,e,n,r,o)=>e(i=>{const a=t._3;return un("--")(t,e,n,(s,u)=>r(k(s._1,s._2,a),u),(s,u)=>e(c=>o(s,!1)))})]))("edge arrow '->' or '--'"),AS=t=>t!==`
|
|
19
|
+
`&&t!=="\r"&&t!=="#"&&t!=="}"&&t!=="{",vu=Bt(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),GS=t=>t===" "||t===" "||t==="\r",IS=t=>Xr(ce(ar(GS)(ce(Er(t))).rest)),Af=t=>t===`
|
|
20
|
+
`||t==="\r"||t==="#"||t==="}",DS=t=>t===`
|
|
21
|
+
`||t==="\r"||t==="#"||t==="}"||t==="{",RS=t=>t!=="{"&&t!==`
|
|
22
|
+
`&&t!=="\r",$p=t=>ss(t)==="",BS=t=>ce(ar($p)(ce(ar($p)(t).rest)).rest),FS=t=>(e=>n=>{let r=e,o=n,i=!0,a;for(;i;){const s=r,u=Rt(c=>w,c=>g=>v("Just",{head:c,tail:g}),o);if(u.tag==="Just"&&(u._1.head===" "||u._1.head===" ")){r=s+1|0,o=u._1.tail;continue}i=!1,a=s}return a})(0)(Er(t)),MS=t=>{const e=Rt(n=>w,n=>r=>v("Just",{head:n,tail:r}),U(FS)(dt(n=>ss(n)!=="",t)));if(e.tag==="Nothing")return 0;if(e.tag==="Just")return J(CS)(e._1.head)(e._1.tail);f()},zS=(()=>{const t=mt(Bt(e=>e==="-"))("'-'");return(e,n,r,o,i)=>{const a=e._3;return n(s=>t(e,n,r,(u,c)=>o(k(u._1,u._2,a),c),(u,c)=>n(g=>{const d=Pi((()=>{const _=mt(Bt(p=>p===">"))("'>'"),h=mt(Bt(p=>p==="-"))("'-'");return(p,m,y,x,N)=>{const T=p._1,C=p._2;return m(L=>_(k(T,C,!1),m,y,(S,P)=>{const M=S._3;return m(W=>M?x(S,P):h(p,m,y,x,N))},N))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(_=>d(l,n,r,(h,p)=>o(k(h._1,h._2,a),p),(h,p)=>n(m=>i(l._3&&!h._3?k(h._1,h._2,!0):h,"-"))))})))}})(),ie=(()=>{const t=Rn(Bt(e=>e===" "||e===" "));return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>i(e._3&&!s._3?k(s._1,s._2,!0):s,void 0))))})(),so=(()=>{const t=Bt(e=>e===" "||e===" ");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>ie(e._3&&!s._3?k(s._1,s._2,!0):s,n,r,o,i))))})(),Up=(t,e,n,r,o)=>e(i=>e(a=>ie(t,e,n,r,(s,u)=>e(c=>e(g=>{const d=t._3&&!s._3?k(s._1,s._2,!0):s;return Pf(d,e,n,r,(l,_)=>e(h=>o(d._3&&!l._3?k(l._1,l._2,!0):l,_)))}))))),Vp=(t,e,n,r,o)=>e(i=>ie(t,e,n,r,(a,s)=>e(u=>{const c=mt(Bt(d=>d==="-"))("'-'"),g=t._3&&!a._3?k(a._1,a._2,!0):a;return e(d=>{const l=(p,m)=>e(y=>(()=>{if(m.tag==="Just")return(x,N,T,C,L)=>N(S=>PS(x,N,T,C,(P,M)=>N(W=>L(P,v("Just",M)))));if(m.tag==="Nothing")return(x,N,T,C,L)=>L(x,w);f()})()(g._3&&!p._3?k(p._1,p._2,!0):p,e,n,r,o)),_=g._1,h=g._2;return e(p=>e(m=>c(k(_,h,!1),e,n,(y,x)=>e(N=>l(g,w)),(y,x)=>e(N=>l(k(_,h,!1),v("Just",x))))))})}))),QS=t=>{const e=mo("Expected ")(t),n=(()=>{if(e.tag==="Nothing")return t;if(e.tag==="Just")return e._1;f()})();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},WS=t=>{const e=ss(t),n=mo('"')(e),r=(()=>{if(n.tag==="Just")return D2('"')(n._1);if(n.tag==="Nothing")return w;f()})(),o=(()=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;f()})();return o===""?w:v("Just",o)},Xp=t=>e=>t!=="AnimatedSurface"&&e.statements.length!==0?{...e,frames:Ct(e.frames)((()=>{if(t==="StillSurface")return{name:w,ops:vr("Seq",e.statements),kind:bf};if(t==="SequenceSurface")return{name:w,ops:vr("Seq",e.statements),kind:hu};if(t==="AnimatedSurface")return{name:w,ops:vr("Seq",e.statements),kind:hu};f()})()),statements:[]}:e,OS=(()=>{const t=mt(Bt(e=>e==="\\"))("'\\\\'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?k(s._1,s._2,!0):s;return n(d=>bS(g,n,r,o,(l,_)=>n(h=>i(g._3&&!l._3?k(l._1,l._2,!0):l,_==="n"?`
|
|
23
|
+
`:_==="t"?" ":_==="r"?"\r":_))))})))})(),qS=(()=>{const t=Bt(e=>e!=='"'&&e!=="\\"&&e!==`
|
|
24
|
+
`);return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>OS(k(a,s,!1),n,r,(c,g)=>n(d=>t(e,n,r,o,i)),i))}})(),HS=(()=>{const t=mt(Bt(e=>e==='"'))(`'"'`);return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=Rn(qS),d=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>g(d,n,r,o,(_,h)=>n(p=>{const m=mt(mt(Bt(x=>x==='"'))(`'"'`))(`closing '"' (unterminated string)`),y=d._3&&!_._3?k(_._1,_._2,!0):_;return n(x=>m(y,n,r,o,(N,T)=>n(C=>i(y._3&&!N._3?k(N._1,N._2,!0):N,Xr(Zt(ye.foldr,h))))))})))})))})(),$S={frames:[],statements:[]},US=t=>{const e=BS(Gr(`
|
|
25
|
+
`)(t));return dr(`
|
|
26
|
+
`)(U(IS)(U(ii(MS(e)))(e)))},VS=(()=>{const t=mt(Bt(e=>e==="|"))("'|'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=Rn(ES),d=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>g(d,n,r,o,(_,h)=>n(p=>{const m=mt(mt(Bt(x=>x==="|"))("'|'"))("closing '|'"),y=d._3&&!_._3?k(_._1,_._2,!0):_;return n(x=>m(y,n,r,o,(N,T)=>n(C=>i(y._3&&!N._3?k(N._1,N._2,!0):N,US(dr("")(Zt(ye.foldr,h)))))))})))})))})(),Pa=Bt(t=>t>="0"&&t<="9"),XS=(()=>{const t=mt(Bt(e=>e==="_"))("'_'");return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>vu(k(a,s,!1),n,r,(c,g)=>{const d=c._3;return n(l=>{if(d)return o(c,g);const _=e._1,h=e._2;return n(p=>Pa(k(_,h,!1),n,r,(m,y)=>{const x=m._3;return n(N=>{if(x)return o(m,y);const T=e._1,C=e._2;return n(L=>t(k(T,C,!1),n,r,(S,P)=>{const M=S._3;return n(W=>M?o(S,P):zS(e,n,r,o,i))},i))})},i))})},i))}})(),qe=(()=>{const t=mt(Bt(e=>e==="_"))("'_'");return(e,n,r,o,i)=>n(a=>{const s=(g,d)=>n(l=>{const _=Rn(XS),h=e._3&&!g._3?k(g._1,g._2,!0):g;return n(p=>_(h,n,r,o,(m,y)=>n(x=>i(h._3&&!m._3?k(m._1,m._2,!0):m,Oi(d)+Xr(Zt(ye.foldr,y))))))}),u=e._1,c=e._2;return n(g=>vu(k(u,c,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?o(d,l):t(e,n,r,o,s))},s))})})(),Yp=(t,e,n,r,o)=>e(i=>ie(t,e,n,r,(a,s)=>e(u=>{const c=mt(qe)("attribute key"),g=t._3&&!a._3?k(a._1,a._2,!0):a;return e(d=>c(g,e,n,r,(l,_)=>e(h=>{const p=g._3&&!l._3?k(l._1,l._2,!0):l;return e(m=>ie(p,e,n,r,(y,x)=>e(N=>{const T=mt(mt(Bt(L=>L===":"))("':'"))("':'"),C=p._3&&!y._3?k(y._1,y._2,!0):y;return e(L=>T(C,e,n,r,(S,P)=>e(M=>{const W=C._3&&!S._3?k(S._1,S._2,!0):S;return e(G=>ie(W,e,n,r,(I,j)=>e(O=>{const z=mt(qe)("attribute value"),$=W._3&&!I._3?k(I._1,I._2,!0):I;return e(q=>z($,e,n,r,(D,B)=>e(R=>{const E=$._3&&!D._3?k(D._1,D._2,!0):D;return e(Q=>ie(E,e,n,r,(Y,H)=>e(K=>o(E._3&&!Y._3?k(Y._1,Y._2,!0):Y,b(_,B)))))})))})))})))})))})))}))),YS=Op((()=>{const t=mt(Bt(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(a=>n(s=>t(e,n,r,o,(u,c)=>n(g=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return ie(l,n,r,o,(_,h)=>n(p=>i(l._3&&!_._3?k(_._1,_._2,!0):_,h)))})))))})())(mt((()=>{const t=mt(Bt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>n(s=>ie(e,n,r,o,(u,c)=>n(g=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return t(l,n,r,o,(_,h)=>n(p=>i(l._3&&!_._3?k(_._1,_._2,!0):_,h)))})))))})())("closing '}' for attributes"))((()=>{const t=mt(Bt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>{const s=(g,d)=>n(l=>(()=>{if(d.tag==="Just")return(_,h,p,m,y)=>y(_,F);if(d.tag==="Nothing")return(_,h,p,m,y)=>h(x=>Yp(_,h,p,m,(N,T)=>h(C=>{const L=Rn((()=>{const P=mt(Bt(M=>M===","))("','");return(M,W,G,I,j)=>{const O=M._3;return W(z=>W($=>W(q=>W(D=>W(B=>W(R=>ie(M,W,G,(E,Q)=>I(k(E._1,E._2,O),Q),(E,Q)=>W(Y=>W(H=>{const K=M._3&&!E._3?k(E._1,E._2,!0):E;return P(K,W,G,(X,Z)=>I(k(X._1,X._2,O),Z),(X,Z)=>W(nt=>{const gt=K._3&&!X._3?k(X._1,X._2,!0):X;return W(bt=>W(lt=>{const Tt=M._3&&!gt._3?k(gt._1,gt._2,!0):gt;return ie(Tt,W,G,(Et,te)=>I(k(Et._1,Et._2,O),te),(Et,te)=>W(Jt=>{const Yt=Tt._3&&!Et._3?k(Et._1,Et._2,!0):Et;return W(Dt=>W(yt=>{const ht=M._3&&!Yt._3?k(Yt._1,Yt._2,!0):Yt;return Yp(ht,W,G,(ft,pt)=>I(k(ft._1,ft._2,O),pt),(ft,pt)=>W(At=>j(ht._3&&!ft._3?k(ft._1,ft._2,!0):ft,pt)))}))}))}))}))})))))))))}})()),S=_._3&&!N._3?k(N._1,N._2,!0):N;return h(P=>L(S,h,p,m,(M,W)=>h(G=>y(S._3&&!M._3?k(M._1,M._2,!0):M,kS([T,...Zt(ye.foldr,W)])))))})));f()})()(e._3&&!g._3?k(g._1,g._2,!0):g,n,r,o,i)),u=e._1,c=e._2;return n(g=>n(d=>t(k(u,c,!1),n,r,(l,_)=>n(h=>s(e,w)),(l,_)=>n(h=>s(k(u,c,!1),v("Just",_))))))})})()),KS=(t,e,n,r,o)=>e(i=>ie(t,e,n,r,(a,s)=>e(u=>{const c=mt(Bt(d=>d==="{"))("'{'"),g=t._3&&!a._3?k(a._1,a._2,!0):a;return e(d=>{const l=(p,m)=>e(y=>(()=>{if(m.tag==="Just")return YS;if(m.tag==="Nothing")return(x,N,T,C,L)=>L(x,F);f()})()(g._3&&!p._3?k(p._1,p._2,!0):p,e,n,r,o)),_=g._1,h=g._2;return e(p=>e(m=>c(k(_,h,!1),e,n,(y,x)=>e(N=>l(g,w)),(y,x)=>e(N=>l(k(_,h,!1),v("Just",x))))))})}))),jS=t=>e=>n=>(r,o,i,a,s)=>o(u=>ie(r,o,i,a,(c,g)=>o(d=>{const l=bn(mt(qe)("target node identifier")),_=r._3&&!c._3?k(c._1,c._2,!0):c;return o(h=>l(_,o,i,a,(p,m)=>o(y=>s(_._3&&!p._3?k(p._1,p._2,!0):p,{op:Zn("DelEdge",{from:t,to:m._1,directed:n}),operands:[e,m._2]}))))}))),ZS=(t,e,n,r,o)=>e(i=>nr(t,e,n,r,(a,s)=>e(u=>{const c=t._3&&!a._3?k(a._1,a._2,!0):a;return e(g=>{const d=c._3;return e(l=>qe(c,e,n,(_,h)=>r(k(_._1,_._2,d),h),(_,h)=>e(p=>{const m=c._3&&!_._3?k(_._1,_._2,!0):_;return e(y=>ie(m,e,n,(x,N)=>r(k(x._1,x._2,d),N),(x,N)=>e(T=>{const C=m._3&&!x._3?k(x._1,x._2,!0):x;return e(L=>{const S=(W,G)=>e(I=>{const j=C._3&&!W._3?k(W._1,W._2,!0):W;return e(O=>r(c._3&&!j._3?k(j._1,j._2,!0):j,Jr("Use `~>` / `<~` for movement tokens.",s)))}),P=C._1,M=C._2;return e(W=>un("->")(k(P,M,!1),e,n,(G,I)=>{const j=G._3;return e(O=>j?r(k(G._1,G._2,d),I):un("<-")(C,e,n,(z,$)=>r(k(z._1,z._2,d),$),S))},S))})})))})))})}))),tE=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>bn(qe)(t,e,n,(u,c)=>r(k(u._1,u._2,a),c),(u,c)=>e(g=>{const d=t._3&&!u._3?k(u._1,u._2,!0):u;return e(l=>ie(d,e,n,(_,h)=>r(k(_._1,_._2,a),h),(_,h)=>e(p=>{const m=mt(Bt(x=>x==="~"))("'~'"),y=d._3&&!_._3?k(_._1,_._2,!0):_;return e(x=>{const N=(L,S)=>e(P=>{const M=y._3&&!L._3?k(L._1,L._2,!0):L;return e(W=>{const G=c._1,I=c._2,j=t._3&&!M._3?k(M._1,M._2,!0):M;return e(O=>ie(j,e,n,r,(z,$)=>e(q=>{const D=mt(Bt(E=>E==="~"))("'~'"),B=mt(Bt(E=>E==="<"))("'<'"),R=j._3&&!z._3?k(z._1,z._2,!0):z;return e(E=>{const Q=(K,X)=>e(Z=>{const nt=X==="~"?mt(un("~>"))("'~>'"):mt(un("<~"))("'<~'"),gt=R._3&&!K._3?k(K._1,K._2,!0):K;return e(bt=>nt(gt,e,n,r,(lt,Tt)=>e(Et=>o(gt._3&&!lt._3?k(lt._1,lt._2,!0):lt,b(G,b(I,Tt))))))}),Y=R._1,H=R._2;return e(K=>D(k(Y,H,!1),e,n,(X,Z)=>{const nt=X._3;return e(gt=>nt?r(R,Z):B(R,e,n,(bt,lt)=>r(R,lt),(bt,lt)=>Q(R,lt)))},(X,Z)=>Q(R,Z)))})})))})}),T=y._1,C=y._2;return e(L=>m(k(T,C,!1),e,n,(S,P)=>{const M=S._3;return e(W=>M?r(k(y._1,y._2,a),P):e(G=>un("<~")(y,e,n,(I,j)=>r(k(y._1,y._2,a),j),(I,j)=>e(O=>N(y)))))},(S,P)=>N(y)))})})))})))}),eE=(()=>{const t=mt(Bt(e=>e==="~"))("'~'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=mt(so)("space after '~'"),d=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>g(d,n,r,o,(_,h)=>n(p=>{const m=bn(mt(qe)("source node identifier")),y=d._3&&!_._3?k(_._1,_._2,!0):_;return n(x=>m(y,n,r,o,(N,T)=>n(C=>{const L=T._1,S=T._2,P=y._3&&!N._3?k(N._1,N._2,!0):N;return n(M=>ie(P,n,r,o,(W,G)=>n(I=>{const j=mt(un("->"))("source edge arrow '->'"),O=P._3&&!W._3?k(W._1,W._2,!0):W;return n(z=>j(O,n,r,o,($,q)=>n(D=>{const B=O._3&&!$._3?k($._1,$._2,!0):$;return n(R=>ie(B,n,r,o,(E,Q)=>n(Y=>{const H=bn(mt(qe)("target node identifier")),K=B._3&&!E._3?k(E._1,E._2,!0):E;return n(X=>H(K,n,r,o,(Z,nt)=>n(gt=>{const bt=nt._1,lt=nt._2,Tt=K._3&&!Z._3?k(Z._1,Z._2,!0):Z;return n(Et=>ie(Tt,n,r,o,(te,Jt)=>n(Yt=>{const Dt=mt(un("=>"))("repoint separator '=>'"),yt=Tt._3&&!te._3?k(te._1,te._2,!0):te;return n(ht=>Dt(yt,n,r,o,(ft,pt)=>n(At=>{const Gt=yt._3&&!ft._3?k(ft._1,ft._2,!0):ft;return n(Nt=>ie(Gt,n,r,o,(Lt,Qt)=>n(ee=>{const ae=bn(mt(qe)("new source node identifier")),ne=Gt._3&&!Lt._3?k(Lt._1,Lt._2,!0):Lt;return n(Ut=>ae(ne,n,r,o,(Wt,gn)=>n(pn=>{const He=gn._1,kn=gn._2,Be=ne._3&&!Wt._3?k(Wt._1,Wt._2,!0):Wt;return n(re=>ie(Be,n,r,o,(se,Xf)=>n(YP=>{const UP=mt(un("->"))("replacement edge arrow '->'"),$0=Be._3&&!se._3?k(se._1,se._2,!0):se;return n(KP=>UP($0,n,r,o,(Qu,jP)=>n(ZP=>{const U0=$0._3&&!Qu._3?k(Qu._1,Qu._2,!0):Qu;return n(tA=>ie(U0,n,r,o,(Wu,eA)=>n(nA=>{const VP=bn(mt(qe)("new target node identifier")),V0=U0._3&&!Wu._3?k(Wu._1,Wu._2,!0):Wu;return n(rA=>VP(V0,n,r,o,(Ou,X0)=>n(oA=>i(V0._3&&!Ou._3?k(Ou._1,Ou._2,!0):Ou,{op:Zn("RepointEdge",{from:L,to:bt,newFrom:He,newTo:X0._1}),operands:[S,lt,kn,X0._2]}))))})))})))})))})))})))})))})))})))})))})))})))})))})))})))})(),nE=(t,e,n,r,o)=>e(i=>Pa(t,e,n,r,(a,s)=>e(u=>{const c=Rn(Pa),g=t._3&&!a._3?k(a._1,a._2,!0):a;return e(d=>c(g,e,n,r,(l,_)=>e(h=>{const p=Vm(Oi(s)+Xr(Zt(ye.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(y,x,N,T,C)=>C(y,m)}if(p.tag==="Nothing")return(m,y,x,N,T)=>T(m,0);f()})()(g._3&&!l._3?k(l._1,l._2,!0):l,e,n,r,o)})))}))),rE=t=>(e,n,r,o,i)=>{const a=e._3;return n(s=>un(t)(e,n,r,(u,c)=>o(k(u._1,u._2,a),c),(u,c)=>n(g=>{const d=Pi((()=>{const _=mt(Bt(p=>p==="_"))("'_'"),h=mt(Bt(p=>p==="-"))("'-'");return(p,m,y,x,N)=>{const T=p._1,C=p._2;return m(L=>vu(k(T,C,!1),m,y,(S,P)=>{const M=S._3;return m(W=>{if(M)return x(S,P);const G=p._1,I=p._2;return m(j=>Pa(k(G,I,!1),m,y,(O,z)=>{const $=O._3;return m(q=>{if($)return x(O,z);const D=p._1,B=p._2;return m(R=>_(k(D,B,!1),m,y,(E,Q)=>{const Y=E._3;return m(H=>Y?x(E,Q):h(p,m,y,x,N))},N))})},N))})},N))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(_=>d(l,n,r,(h,p)=>o(k(h._1,h._2,a),p),(h,p)=>n(m=>{const y=l._3&&!h._3?k(h._1,h._2,!0):h;return n(x=>hn(y,n,r,(N,T)=>o(k(N._1,N._2,a),T),(N,T)=>n(C=>i(y._3&&!N._3?k(N._1,N._2,!0):N,t))))})))})))},Cn=t=>(e,n,r,o,i)=>{const a=e._3;return n(s=>un(t)(e,n,r,(u,c)=>o(k(u._1,u._2,a),c),(u,c)=>n(g=>{const d=Pi((()=>{const _=mt(Bt(p=>p==="_"))("'_'"),h=mt(Bt(p=>p==="-"))("'-'");return(p,m,y,x,N)=>{const T=p._1,C=p._2;return m(L=>vu(k(T,C,!1),m,y,(S,P)=>{const M=S._3;return m(W=>{if(M)return x(S,P);const G=p._1,I=p._2;return m(j=>Pa(k(G,I,!1),m,y,(O,z)=>{const $=O._3;return m(q=>{if($)return x(O,z);const D=p._1,B=p._2;return m(R=>_(k(D,B,!1),m,y,(E,Q)=>{const Y=E._3;return m(H=>Y?x(E,Q):h(p,m,y,x,N))},N))})},N))})},N))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(_=>d(l,n,r,(h,p)=>o(k(h._1,h._2,a),p),(h,p)=>n(m=>i(l._3&&!h._3?k(h._1,h._2,!0):h,void 0))))})))},oE=(t,e,n,r,o)=>e(i=>Cn("into")(t,e,n,r,(a,s)=>e(u=>{const c=mt(so)("space after 'into'"),g=t._3&&!a._3?k(a._1,a._2,!0):a;return e(d=>c(g,e,n,r,(l,_)=>e(h=>{const p=bn(mt(qe)("node identifier after 'into'")),m=g._3&&!l._3?k(l._1,l._2,!0):l;return e(y=>p(m,e,n,r,(x,N)=>e(T=>o(m._3&&!x._3?k(x._1,x._2,!0):x,{op:Zn("Enter",{id:N._1}),operands:[N._2]}))))})))}))),iE=(t,e,n,r,o)=>e(i=>Cn("out")(t,e,n,r,(a,s)=>e(u=>o(t._3&&!a._3?k(a._1,a._2,!0):a,{op:TL,operands:[]})))),aE=(t,e,n,r,o)=>e(i=>Cn("seed")(t,e,n,r,(a,s)=>e(u=>{const c=t._3&&!a._3?k(a._1,a._2,!0):a;return e(g=>ie(c,e,n,r,(d,l)=>e(_=>{const h=mt(nE)("integer (seed value)"),p=c._3&&!d._3?k(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const T=p._3&&!y._3?k(y._1,y._2,!0):y;return e(C=>hn(T,e,n,r,(L,S)=>e(P=>o(T._3&&!L._3?k(L._1,L._2,!0):L,x))))})))})))}))),Kp=(t,e,n,r,o)=>{const i=t._3;return e(a=>Cn("diagram")(t,e,n,(s,u)=>r(k(s._1,s._2,i),u),(s,u)=>e(c=>{const g=mt(so)("space after 'diagram'"),d=t._3&&!s._3?k(s._1,s._2,!0):s;return e(l=>g(d,e,n,(_,h)=>r(k(_._1,_._2,i),h),(_,h)=>e(p=>{const m=mt(Cn("sequence"))("diagram mode"),y=d._3&&!_._3?k(_._1,_._2,!0):_;return e(x=>m(y,e,n,(N,T)=>r(k(N._1,N._2,i),T),(N,T)=>e(C=>{const L=y._3&&!N._3?k(N._1,N._2,!0):N;return e(S=>Up(L,e,n,(P,M)=>r(k(P._1,P._2,i),M),(P,M)=>e(W=>o(L._3&&!P._3?k(P._1,P._2,!0):P,vL))))})))})))})))},jp=(t,e,n,r,o)=>{const i=t._3;return e(a=>Cn("still")(t,e,n,(s,u)=>r(k(s._1,s._2,i),u),(s,u)=>e(c=>{const g=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>Up(g,e,n,(l,_)=>r(k(l._1,l._2,i),_),(l,_)=>e(h=>o(g._3&&!l._3?k(l._1,l._2,!0):l,NL))))})))},Zp=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>jp(k(i,a,!1),e,n,(u,c)=>{const g=u._3;return e(d=>g?r(u,c):Kp(t,e,n,r,o))},o))},sE=t=>(e,n,r,o,i)=>n(a=>nr(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?k(s._1,s._2,!0):s;return n(d=>{const l=g._3;return Zp(g,n,r,(_,h)=>o(k(_._1,_._2,l),h),(_,h)=>n(p=>o(g._3&&!_._3?k(_._1,_._2,!0):_,Jr((()=>{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.";f()})(),u))))})}))),uE=t=>(e,n,r,o,i)=>n(a=>nr(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?k(s._1,s._2,!0):s;return n(d=>{const l=(p,m)=>n(y=>(()=>{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.";f()})();return(N,T,C,L,S)=>L(N,Jr(x,u))}if(m.tag==="Nothing")return(x,N,T,C,L)=>L(x,void 0);f()})()(g._3&&!p._3?k(p._1,p._2,!0):p,n,r,o,i)),_=g._1,h=g._2;return n(p=>n(m=>Zp(k(_,h,!1),n,r,(y,x)=>{const N=y._3;return n(T=>N?o(y,x):l(g,w))},(y,x)=>n(N=>l(y,v("Just",x))))))})}))),cE=(t,e,n,r,o)=>e(i=>{const a=(c,g)=>e(d=>{const l=t._3&&!c._3?k(c._1,c._2,!0):c;return e(_=>hn(l,e,n,r,(h,p)=>e(m=>{const y=l._3&&!h._3?k(h._1,h._2,!0):h;return e(x=>uE(g)(y,e,n,r,(N,T)=>e(C=>o(y._3&&!N._3?k(N._1,N._2,!0):N,g))))})))}),s=t._1,u=t._2;return e(c=>jp(k(s,u,!1),e,n,(g,d)=>{const l=g._3;return e(_=>l?r(g,d):Kp(t,e,n,r,a))},a))}),gE=(t,e,n,r,o)=>e(i=>{const a=(c,g)=>e(d=>o(c,(()=>{if(g.tag==="Nothing")return wL;if(g.tag==="Just")return g._1;f()})())),s=t._1,u=t._2;return e(c=>e(g=>cE(k(s,u,!1),e,n,(d,l)=>{const _=d._3;return e(h=>_?r(d,l):a(t,w))},(d,l)=>e(_=>a(d,v("Just",l))))))}),fE=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>ie(t,e,n,(u,c)=>r(k(u._1,u._2,a),c),(u,c)=>e(g=>Cn("via")(t._3&&!u._3?k(u._1,u._2,!0):u,e,n,(d,l)=>r(k(d._1,d._2,a),l),(d,l)=>e(_=>{const h=t._3&&!d._3?k(d._1,d._2,!0):d;return e(p=>xu(h,e,n,r,(m,y)=>e(x=>{const N=h._3&&!m._3?k(m._1,m._2,!0):m;return e(T=>so(N,e,n,r,(C,L)=>e(S=>{const P=mt(qe)("source node identifier after 'via'"),M=N._3&&!C._3?k(C._1,C._2,!0):C;return e(W=>P(M,e,n,r,(G,I)=>e(j=>{const O=M._3&&!G._3?k(G._1,G._2,!0):G;return e(z=>ie(O,e,n,r,($,q)=>e(D=>{const B=mt(qe)("target node identifier after 'via'"),R=O._3&&!$._3?k($._1,$._2,!0):$;return e(E=>B(R,e,n,r,(Q,Y)=>e(H=>o(R._3&&!Q._3?k(Q._1,Q._2,!0):Q,{from:I,to:Y}))))})))})))})))})))})))))}),_E=t=>e=>{const n=Rn(fE);return(r,o,i,a,s)=>o(u=>n(r,o,i,a,(c,g)=>o(d=>s(r._3&&!c._3?k(c._1,c._2,!0):c,{op:Zn("DelNode",{id:t,via:Zt(ye.foldr,g)}),operands:[e]}))))},dE=(()=>{const t=mt(Bt(e=>e==="-"))("'-'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=mt(so)("space after '-'"),d=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>g(d,n,r,o,(_,h)=>n(p=>{const m=bn(mt(qe)("node identifier after '-'")),y=d._3&&!_._3?k(_._1,_._2,!0):_;return n(x=>m(y,n,r,o,(N,T)=>n(C=>{const L=T._1,S=T._2,P=y._3&&!N._3?k(N._1,N._2,!0):N;return n(M=>Vp(P,n,r,o,(W,G)=>n(I=>(()=>{if(G.tag==="Just")return jS(L)(S)(G._1);if(G.tag==="Nothing")return _E(L)(S);f()})()(P._3&&!W._3?k(W._1,W._2,!0):W,n,r,o,i))))})))})))})))})(),rr=t=>e=>(n,r,o,i,a)=>r(s=>nr(n,r,o,i,(u,c)=>r(g=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return r(l=>Cn(t)(d,r,o,i,(_,h)=>r(p=>i(d._3&&!_._3?k(_._1,_._2,!0):_,Jr(e,c)))))}))),lE=t=>t==="AnimatedSurface"?(e,n,r,o,i)=>n(a=>nr(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?k(s._1,s._2,!0):s;return n(d=>Cn("step")(g,n,r,o,(l,_)=>n(h=>{const p=mt(so)("space after 'step'"),m=g._3&&!l._3?k(l._1,l._2,!0):l;return n(y=>p(m,n,r,o,(x,N)=>n(T=>{const C=bn(mt(qe)("step name")),L=m._3&&!x._3?k(x._1,x._2,!0):x;return n(S=>C(L,n,r,o,(P,M)=>n(W=>{const G=M._1,I=M._2,j=L._3&&!P._3?k(P._1,P._2,!0):P;return n(O=>nr(j,n,r,o,(z,$)=>n(q=>{const D=j._3&&!z._3?k(z._1,z._2,!0):z;return n(B=>ie(D,n,r,o,(R,E)=>n(Q=>{const Y=D._3&&!R._3?k(R._1,R._2,!0):R;return n(H=>Hp(Y,n,r,o,(K,X)=>n(Z=>{const nt=Y._3&&!K._3?k(K._1,K._2,!0):K;return n(gt=>hn(nt,n,r,o,(bt,lt)=>n(Tt=>{const Et={line:u.line,column:u.column,endLine:$.line,endColumn:$.column};return i(nt._3&&!bt._3?k(bt._1,bt._2,!0):bt,{name:v("Just",G),ops:vr("Leaf",{op:Zn("Step",{name:G}),line:Et.line,column:Et.column,endLine:Et.endLine,endColumn:Et.endColumn,span:Et,operands:[I]}),kind:Lp})})))})))})))})))})))})))})))}))):rr("step")("`step` markers are only supported in animated diagrams."),hE=(()=>{const t=mt(Bt(e=>e===":"))("':'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?k(s._1,s._2,!0):s;return n(d=>ie(g,n,r,o,(l,_)=>n(h=>{const p=Rn(Bt(AS)),m=g._3&&!l._3?k(l._1,l._2,!0):l;return n(y=>p(m,n,r,o,(x,N)=>n(T=>i(m._3&&!x._3?k(x._1,x._2,!0):x,ss(Xr(Zt(ye.foldr,N)))))))})))})))})(),pE=(t,e,n,r,o)=>e(i=>ie(t,e,n,r,(a,s)=>e(u=>mt((c,g,d,l,_)=>{const h=c._1,p=c._2;return g(m=>hE(k(h,p,!1),g,d,(y,x)=>{const N=y._3;return g(T=>{if(N)return l(y,x);const C=c._1,L=c._2;return g(S=>VS(k(C,L,!1),g,d,(P,M)=>{const W=P._3;return g(G=>W?l(P,M):HS(c,g,d,l,_))},_))})},_))})('label ("\u2026", : rest-of-line, or |\u2026|)')(t._3&&!a._3?k(a._1,a._2,!0):a,e,n,r,o)))),Tu=t=>(e,n,r,o,i)=>n(a=>ie(e,n,r,o,(s,u)=>n(c=>{const g=e._3&&!s._3?k(s._1,s._2,!0):s;return n(d=>{const l=(p,m)=>n(y=>(m?((x,N,T,C,L)=>L(x,w)):(x,N,T,C,L)=>N(S=>pE(x,N,T,C,(P,M)=>N(W=>L(P,v("Just",M))))))(g._3&&!p._3?k(p._1,p._2,!0):p,n,r,o,i)),_=g._1,h=g._2;return n(p=>{const m=(y,x)=>{const N=y._3;return n(T=>N?o(y,x):l(g,!1))};return n(y=>n(x=>n(N=>Ea(k(_,h,!1),n,r,(T,C)=>{const L=T._3;return n(S=>L?m(k(_,h,!1),C):n(P=>Bt(t)(k(_,h,!1),n,r,(M,W)=>m(k(_,h,!1),W),(M,W)=>n(G=>n(I=>l(k(_,h,!1),!0))))))},(T,C)=>n(L=>n(S=>l(k(_,h,!1),!0)))))))})})}))),mE=t=>e=>n=>(r,o,i,a,s)=>o(u=>ie(r,o,i,a,(c,g)=>o(d=>{const l=bn(mt(qe)("target node identifier")),_=r._3&&!c._3?k(c._1,c._2,!0):c;return o(h=>l(_,o,i,a,(p,m)=>o(y=>{const x=m._1,N=m._2,T=_._3&&!p._3?k(p._1,p._2,!0):p;return o(C=>Tu(Af)(T,o,i,a,(L,S)=>o(P=>s(T._3&&!L._3?k(L._1,L._2,!0):L,{op:Zn("AddEdge",{from:t,to:x,label:S.tag==="Just"?v("Just",S._1):w,directed:n}),operands:[e,N]}))))})))}))),yE=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>bn(qe)(t,e,n,(u,c)=>r(k(u._1,u._2,a),c),(u,c)=>e(g=>{const d=t._3&&!u._3?k(u._1,u._2,!0):u;return e(l=>ie(d,e,n,(_,h)=>r(k(_._1,_._2,a),h),(_,h)=>e(p=>{const m=mt(Bt(x=>x==="<"))("'<'"),y=d._3&&!_._3?k(_._1,_._2,!0):_;return e(x=>m(y,e,n,(N,T)=>r(k(y._1,y._2,a),T),(N,T)=>e(C=>{const L=Pi((P,M,W,G,I)=>{const j=P._3;return un("<-")(P,M,W,(O,z)=>G(k(O._1,O._2,j),z),I)}),S=y._3&&!y._3?k(y._1,y._2,!0):y;return e(P=>L(S,e,n,(M,W)=>r(k(M._1,M._2,a),W),(M,W)=>e(G=>{const I=S._3&&!M._3?k(M._1,M._2,!0):M;return e(j=>{const O=c._1,z=c._2,$=t._3&&!I._3?k(I._1,I._2,!0):I;return e(q=>ie($,e,n,r,(D,B)=>e(R=>{const E=mt(un("<~"))("'<~'"),Q=$._3&&!D._3?k(D._1,D._2,!0):D;return e(Y=>E(Q,e,n,r,(H,K)=>e(X=>{const Z=Q._3&&!H._3?k(H._1,H._2,!0):H;return e(nt=>ie(Z,e,n,r,(gt,bt)=>e(lt=>{const Tt=bn(mt(qe)("target node identifier")),Et=Z._3&&!gt._3?k(gt._1,gt._2,!0):gt;return e(te=>Tt(Et,e,n,r,(Jt,Yt)=>e(Dt=>{const yt=Yt._1,ht=Yt._2,ft=Et._3&&!Jt._3?k(Jt._1,Jt._2,!0):Jt;return e(pt=>Tu(Af)(ft,e,n,r,(At,Gt)=>e(Nt=>o(ft._3&&!At._3?k(At._1,At._2,!0):At,{op:Zn("Token",{from:yt,to:O,labels:(()=>{if(Gt.tag==="Nothing")return[];if(Gt.tag==="Just")return[Gt._1];f()})()}),operands:[ht,z]}))))})))})))})))})))})})))})))})))})))}),xE=(t,e,n,r,o)=>e(i=>tE(t,e,n,r,(a,s)=>e(u=>{const c=s._2._2,g=s._1,d=s._2._1,l=t._3&&!a._3?k(a._1,a._2,!0):a;return e(_=>ie(l,e,n,r,(h,p)=>e(m=>{const y=bn(mt(qe)("target node identifier")),x=l._3&&!h._3?k(h._1,h._2,!0):h;return e(N=>y(x,e,n,r,(T,C)=>e(L=>{const S=C._1,P=C._2,M=x._3&&!T._3?k(T._1,T._2,!0):T;return e(W=>Tu(Af)(M,e,n,r,(G,I)=>e(j=>(c==="<~"?((O,z,$,q,D)=>D(O,{op:Zn("Token",{from:S,to:g,labels:(()=>{if(I.tag==="Nothing")return[];if(I.tag==="Just")return[I._1];f()})()}),operands:c==="<~"?[P,d]:[d,P]})):(O,z,$,q,D)=>D(O,{op:Zn("Token",{from:g,to:S,labels:(()=>{if(I.tag==="Nothing")return[];if(I.tag==="Just")return[I._1];f()})()}),operands:c==="<~"?[P,d]:[d,P]}))(M._3&&!G._3?k(G._1,G._2,!0):G,e,n,r,o))))})))})))}))),wE=(t,e,n,r,o)=>e(i=>Tu(DS)(t,e,n,r,(a,s)=>e(u=>o(a,(()=>{if(s.tag==="Nothing")return"";if(s.tag==="Just")return s._1;f()})())))),NE=t=>e=>(n,r,o,i,a)=>r(s=>wE(n,r,o,i,(u,c)=>r(g=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return r(l=>KS(d,r,o,i,(_,h)=>r(p=>a(d._3&&!_._3?k(_._1,_._2,!0):_,{op:Zn("AddNode",{id:t,label:c,shape:(()=>{const m=LS("shape")(h);if(m.tag==="Just")return m._1==="rectangle"||m._1==="rect"?Yr:m._1==="cylinder"||m._1==="cyl"?U2:m._1==="parallelogram"?V2:m._1==="diamond"?X2:m._1==="ellipse"?Y2:m._1==="document"||m._1==="doc"?K2:m._1==="cloud"?j2:Yr;if(m.tag==="Nothing")return Yr;f()})()}),operands:[e]}))))}))),vE=(()=>{const t=mt(Bt(e=>e==="+"))("'+'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(c=>{const g=mt(so)("space after '+'"),d=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>g(d,n,r,o,(_,h)=>n(p=>{const m=bn(mt(qe)("node identifier after '+'")),y=d._3&&!_._3?k(_._1,_._2,!0):_;return n(x=>m(y,n,r,o,(N,T)=>n(C=>{const L=T._1,S=T._2,P=y._3&&!N._3?k(N._1,N._2,!0):N;return n(M=>Vp(P,n,r,o,(W,G)=>n(I=>(()=>{if(G.tag==="Just")return mE(L)(S)(G._1);if(G.tag==="Nothing")return NE(L)(S);f()})()(P._3&&!W._3?k(W._1,W._2,!0):W,n,r,o,i))))})))})))})))})(),TE=(t,e,n,r,o)=>e(i=>nr(t,e,n,r,(a,s)=>e(u=>{const c=mt(Ef([rr("+node")("Node additions use `+ api: API`."),rr("+edge")("Graph edges use `+ api -> db`."),rr("+conn")("Undirected graph edges use `+ api -- db`."),rr("-node")("Node removals use `- api`."),rr("-edge")("Graph edge removals use `- api -> db`."),rr("-conn")("Undirected graph edge removals use `- api -- db`."),rr("~edge")("Graph edge repoints use `~ api -> db => api -> cache`."),rr("enter")("Dive commands use `into api`."),rr("exit")("Return from a dive with `out`."),ZS,vE,dE,eE,xE,yE,oE,iE]))("statement (+ node, - node, + edge, - edge, into, out, or 'a ~> b'/'a <~ b')"),g=t._3&&!a._3?k(a._1,a._2,!0):a;return e(d=>c(g,e,n,r,(l,_)=>e(h=>{const p=g._3&&!l._3?k(l._1,l._2,!0):l;return e(m=>nr(p,e,n,r,(y,x)=>e(N=>{const T={line:s.line,column:s.column,endLine:x.line,endColumn:x.column};return o(p._3&&!y._3?k(y._1,y._2,!0):y,vr("Leaf",{op:_.op,line:T.line,column:T.column,endLine:T.endLine,endColumn:T.endColumn,span:T,operands:_.operands}))})))})))}))),Gf=Op((()=>{const t=mt(Bt(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(a=>n(s=>t(e,n,r,o,(u,c)=>n(g=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return hn(l,n,r,o,(_,h)=>n(p=>i(l._3&&!_._3?k(_._1,_._2,!0):_,h)))})))))})())(mt((()=>{const t=mt(Bt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>n(s=>hn(e,n,r,o,(u,c)=>n(g=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return t(l,n,r,o,(_,h)=>n(p=>i(l._3&&!_._3?k(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),t0=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>hn(t,e,n,(u,c)=>r(k(u._1,u._2,a),c),(u,c)=>e(g=>{const d=Pi(mt(Bt(_=>_==="}"))("'}'")),l=t._3&&!u._3?k(u._1,u._2,!0):u;return e(_=>d(l,e,n,(h,p)=>r(k(h._1,h._2,a),p),(h,p)=>e(m=>Pi(Ea)(l._3&&!h._3?k(h._1,h._2,!0):h,e,n,(y,x)=>r(k(y._1,y._2,a),x),(y,x)=>e(N=>{const T=t._3&&!y._3?k(y._1,y._2,!0):y;return e(C=>xu(T,e,n,r,(L,S)=>e(P=>{const M=Ef([bE,JE,TE]),W=T._3&&!L._3?k(L._1,L._2,!0):L;return e(G=>M(W,e,n,r,(I,j)=>e(O=>{const z=W._3&&!I._3?k(I._1,I._2,!0):I;return e($=>ie(z,e,n,r,(q,D)=>e(B=>{const R=z._3&&!q._3?k(q._1,q._2,!0):q;return e(E=>Hp(R,e,n,r,(Q,Y)=>e(H=>{const K=R._3&&!Q._3?k(Q._1,Q._2,!0):Q;return e(X=>hn(K,e,n,r,(Z,nt)=>e(gt=>o(K._3&&!Z._3?k(Z._1,Z._2,!0):Z,j))))})))})))})))})))})))))})))}),JE=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>{const u=(c,g)=>{const d=c._3;return e(l=>d?r(c,g):e(_=>{const h=t._3;return e(p=>Cn("seq")(t,e,n,(m,y)=>r(k(m._1,m._2,h),y),(m,y)=>e(x=>{const N=t._3&&!m._3?k(m._1,m._2,!0):m;return e(T=>ie(N,e,n,(C,L)=>r(k(C._1,C._2,h),L),(C,L)=>e(S=>Pf(N._3&&!C._3?k(C._1,C._2,!0):C,e,n,(P,M)=>r(k(P._1,P._2,h),M),(P,M)=>e(W=>{const G=t._3&&!P._3?k(P._1,P._2,!0):P;return e(I=>xu(G,e,n,r,(j,O)=>e(z=>{const $=mt(mt(Bt(D=>D==="{"))("'{'"))("'{'"),q=G._3&&!j._3?k(j._1,j._2,!0):j;return e(D=>$(q,e,n,r,(B,R)=>e(E=>o(q._3&&!B._3?k(B._1,B._2,!0):B,vr("GroupSeq",[])))))})))})))))})))}))};return e(c=>e(g=>Cn("seq")(k(i,a,!1),e,n,(d,l)=>u(k(d._1,d._2,!1),l),(d,l)=>e(_=>e(h=>ie(d,e,n,(p,m)=>u(k(p._1,p._2,!1),m),(p,m)=>e(y=>{const x=d._3&&!p._3?k(p._1,p._2,!0):p;return mt(Bt(N=>N==="{"))("'{'")(x,e,n,(N,T)=>u(k(x._1,x._2,!1),T),(N,T)=>e(C=>Gf(If(kL))(x,e,n,u,o)))})))))))})},bE=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>{const u=(c,g)=>{const d=c._3;return e(l=>d?r(c,g):e(_=>{const h=t._3;return e(p=>Cn("par")(t,e,n,(m,y)=>r(k(m._1,m._2,h),y),(m,y)=>e(x=>{const N=t._3&&!m._3?k(m._1,m._2,!0):m;return e(T=>ie(N,e,n,(C,L)=>r(k(C._1,C._2,h),L),(C,L)=>e(S=>Pf(N._3&&!C._3?k(C._1,C._2,!0):C,e,n,(P,M)=>r(k(P._1,P._2,h),M),(P,M)=>e(W=>{const G=t._3&&!P._3?k(P._1,P._2,!0):P;return e(I=>xu(G,e,n,r,(j,O)=>e(z=>{const $=mt(mt(Bt(D=>D==="{"))("'{'"))("'{'"),q=G._3&&!j._3?k(j._1,j._2,!0):j;return e(D=>$(q,e,n,r,(B,R)=>e(E=>o(q._3&&!B._3?k(B._1,B._2,!0):B,vr("Par",[])))))})))})))))})))}))};return e(c=>e(g=>Cn("par")(k(i,a,!1),e,n,(d,l)=>u(k(d._1,d._2,!1),l),(d,l)=>e(_=>e(h=>ie(d,e,n,(p,m)=>u(k(p._1,p._2,!1),m),(p,m)=>e(y=>{const x=d._3&&!p._3?k(p._1,p._2,!0):p;return mt(Bt(N=>N==="{"))("'{'")(x,e,n,(N,T)=>u(k(x._1,x._2,!1),T),(N,T)=>e(C=>Gf(If(bL))(x,e,n,u,o)))})))))))})},If=t=>{const e=Rn(t0);return(n,r,o,i,a)=>r(s=>e(n,r,o,i,(u,c)=>r(g=>a(n._3&&!u._3?k(u._1,u._2,!0):u,t(Zt(ye.foldr,c))))))},Df=t=>e=>(n,r,o,i,a)=>r(s=>rE(t)(n,r,o,i,(u,c)=>r(g=>{const d=Rn(Bt(RS)),l=n._3&&!u._3?k(u._1,u._2,!0):u;return r(_=>d(l,r,o,i,(h,p)=>r(m=>{const y=mt(mt(Bt(N=>N==="{"))("'{'"))("'{'"),x=l._3&&!h._3?k(h._1,h._2,!0):h;return r(N=>y(x,r,o,i,(T,C)=>r(L=>{const S=x._3&&!T._3?k(T._1,T._2,!0):T;return r(P=>hn(S,r,o,i,(M,W)=>r(G=>{const I=If(CL),j=S._3&&!M._3?k(M._1,M._2,!0):M;return r(O=>I(j,r,o,i,(z,$)=>r(q=>{const D=j._3&&!z._3?k(z._1,z._2,!0):z;return r(B=>hn(D,r,o,i,(R,E)=>r(Q=>{const Y=mt(mt(Bt(K=>K==="}"))("'}'"))("closing '}'"),H=D._3&&!R._3?k(R._1,R._2,!0):R;return r(K=>Y(H,r,o,i,(X,Z)=>r(nt=>{const gt=H._3&&!X._3?k(X._1,X._2,!0):X;return r(bt=>hn(gt,r,o,i,(lt,Tt)=>r(Et=>a(gt._3&&!lt._3?k(lt._1,lt._2,!0):lt,{name:WS(Xr(Zt(ye.foldr,p))),ops:$,kind:e}))))})))})))})))})))})))})))}))),CE=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>rr("keyframe")("Drop the `keyframe` wrapper; Markgraf animates statements in order.")(k(i,a,!1),e,n,(u,c)=>{const g=u._3;return e(d=>{if(g)return r(u,c);const l=t._1,_=t._2;return e(h=>Df("scene")(hu)(k(l,_,!1),e,n,(p,m)=>{const y=p._3;return e(x=>{if(y)return r(p,m);const N=t._1,T=t._2;return e(C=>Df("still")(bf)(k(N,T,!1),e,n,(L,S)=>{const P=L._3;return e(M=>P?r(L,S):Df("title")(JL)(t,e,n,r,o))},o))})},o))})},o))},kE=t=>e=>n=>{if(t==="AnimatedSurface")return{...e,frames:Ct(e.frames)({name:w,ops:n,kind:hu})};if(t==="StillSurface")return{...e,statements:Ct(e.statements)(n)};if(t==="SequenceSurface")return{...e,statements:Ct(e.statements)(n)};f()},LE=t=>e=>n=>{if(n.tag==="TopFrame"){const r=Xp(t)(e);return{...r,frames:Ct(r.frames)((()=>{if(t==="AnimatedSurface")return n._1;if(t==="StillSurface")return{...n._1,kind:n._1.kind==="AnimatedKeyframe"?bf:n._1.kind==="StepMarker"?Lp:n._1.kind};if(t==="SequenceSurface")return n._1;f()})())}}if(n.tag==="TopStatement")return kE(t)(e)(n._1);if(n.tag==="TopInside")return e;f()},SE=t=>{const e=J(LE(t))($S);return n=>Xp(t)(e(n)).frames},EE=t=>dS.defer(e=>{const n=lE(t);return(r,o,i,a,s)=>{const u=r._1,c=r._2;return o(g=>sE(t)(k(u,c,!1),o,i,(d,l)=>{const _=d._3;return o(h=>{if(_)return a(d,l);const p=r._1,m=r._2;return o(y=>o(x=>PE(k(p,m,!1),o,i,(N,T)=>{const C=N._3;return o(L=>{if(C)return a(N,T);const S=r._1,P=r._2;return o(M=>o(W=>n(k(S,P,!1),o,i,(G,I)=>{const j=G._3;return o(O=>{if(j)return a(G,I);const z=r._1,$=r._2;return o(q=>o(D=>CE(k(z,$,!1),o,i,(B,R)=>{const E=B._3;return o(Q=>E?a(B,R):o(Y=>t0(r,o,i,a,(H,K)=>o(X=>s(H,Nu("TopStatement",K))))))},(B,R)=>o(E=>s(B,Nu("TopFrame",R))))))})},(G,I)=>o(j=>s(G,Nu("TopFrame",I))))))})},(N,T)=>o(C=>s(N,Nu("TopInside",T))))))})},s))}}),PE=(t,e,n,r,o)=>e(i=>Cn("inside")(t,e,n,r,(a,s)=>e(u=>{const c=mt(so)("space after 'inside'"),g=t._3&&!a._3?k(a._1,a._2,!0):a;return e(d=>c(g,e,n,r,(l,_)=>e(h=>{const p=mt(qe)("node identifier after 'inside'"),m=g._3&&!l._3?k(l._1,l._2,!0):l;return e(y=>p(m,e,n,r,(x,N)=>e(T=>{const C=m._3&&!x._3?k(x._1,x._2,!0):x;return e(L=>hn(C,e,n,r,(S,P)=>e(M=>{const W=C._3&&!S._3?k(S._1,S._2,!0):S;return e(G=>Gf(e0)(W,e,n,r,(I,j)=>e(O=>{const z=W._3&&!I._3?k(I._1,I._2,!0):I;return e($=>hn(z,e,n,r,(q,D)=>e(B=>o(z._3&&!q._3?k(q._1,q._2,!0):q,{node:N,doc:j}))))})))})))})))})))}))),e0=(t,e,n,r,o)=>e(i=>gE(t,e,n,r,(a,s)=>e(u=>{const c=t._3&&!a._3?k(a._1,a._2,!0):a;return e(g=>{const d=(h,p)=>e(m=>{const y=Rn(EE(s)),x=c._3&&!h._3?k(h._1,h._2,!0):h;return e(N=>y(x,e,n,r,(T,C)=>e(L=>{const S=Zt(ye.foldr,C);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;f()})(),mode:s,frames:SE(s)(S),interiors:vt(P=>{if(P.tag==="TopInside")return v("Just",P._1);if(P.tag==="TopFrame"||P.tag==="TopStatement")return w;f()})(S)})})))}),l=c._1,_=c._2;return e(h=>e(p=>aE(k(l,_,!1),e,n,(m,y)=>{const x=m._3;return e(N=>x?r(m,y):d(c,w))},(m,y)=>e(x=>d(m,v("Just",y))))))})}))),AE=(()=>{const t=mt((e,n,r,o,i)=>n(a=>n(s=>hn(e,n,r,o,(u,c)=>n(g=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return Ea(l,n,r,o,(_,h)=>n(p=>i(l._3&&!_._3?k(_._1,_._2,!0):_,h)))}))))))("'scene', 'still', 'title', 'step', 'inside', a statement, or end of input");return(e,n,r,o,i)=>n(a=>n(s=>n(u=>n(c=>hn(e,n,r,o,(g,d)=>n(l=>n(_=>{const h=e._3&&!g._3?k(g._1,g._2,!0):g;return e0(h,n,r,o,(p,m)=>n(y=>{const x=h._3&&!p._3?k(p._1,p._2,!0):p;return n(N=>n(T=>{const C=e._3&&!x._3?k(x._1,x._2,!0):x;return t(C,n,r,o,(L,S)=>n(P=>i(C._3&&!L._3?k(L._1,L._2,!0):L,m)))}))}))})))))))})(),GE=t=>{const e=mS(t)(AE);if(e.tag==="Left")return Ot("Left",{msg:QS(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 Ot("Right",e._1);f()},IE=t=>{const e=GE(t);if(e.tag==="Left")return Ot("Left",e._1.msg);if(e.tag==="Right")return Ot("Right",e._1);f()},DE=()=>({tag:"ParFrag"}),n0=t=>t,RE=n0("Sync"),BE=n0("SelfMsg"),FE=DE(),uo=bp(Ln),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 a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},Hn=Oo(Ln),qr=uo.state(t=>b(t,t)),r0=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},Ju=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},$o=qo(Ln),ME=t=>e=>J(n=>r=>Oo(Ln).bind(n)(o=>t(o)(r)))(qo(Ln).pure(e)),o0=Hr($o)(Mt),zE=t=>uo.state(e=>b(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:v("Just",t)};f()})())),QE=t=>e=>uo.state(n=>b(void 0,{...n,lifelines:d_(A)(r=>v("Just",{...r,label:e}))(t)(n.lifelines)})),WE=t=>e=>n=>{const r=Ai(n)(t.lifelines);return Ai(e)(t.lifelines).tag==="Nothing"?r.tag==="Nothing"?e+", "+n:e:r.tag==="Nothing"?n:""},OE={lifelines:F,lifelineOrder:[],messages:[],fragments:[],frameEndRows:[],row:0,error:w},qE=t=>e=>n=>Hn.bind(qr)(r=>{const o=Ai(t)(r.lifelines),i=Ai(e)(r.lifelines);if(o.tag==="Just"&&i.tag==="Just"){const a={...r,messages:[{fromCol:o._1.column,toCol:i._1.column,labels:n,row:r.row,kind:t===e?BE:RE},...r.messages],row:r.row+1|0};return uo.state(s=>b(void 0,a))}return zE("token references unknown node: "+WE(r)(t)(e))}),HE=t=>uo.state(e=>b(void 0,{...e,lifelines:d_(A)(n=>v("Just",{...n,destroyedAt:v("Just",e.row)}))(t)(e.lifelines)})),$E=t=>e=>{const n=e.lifelineOrder.length,r=Rt(o=>w,o=>i=>v("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return{fromCol:0,toCol:Ju(0)(e.lifelineOrder.length-1|0)};if(r.tag==="Just")return J(o=>i=>({fromCol:r0(o.fromCol)(r0(i.fromCol)(i.toCol)),toCol:Ju(o.toCol)(Ju(i.fromCol)(i.toCol))}))({fromCol:n,toCol:0})(t);f()},UE=t=>({lifelines:vt(e=>Ai(e)(t.lifelines))(t.lifelineOrder),messages:ce(t.messages),fragments:ce(t.fragments),frameEndRows:t.frameEndRows,totalRows:t.row}),VE=t=>e=>Hn.bind(qr)(n=>{const r=Ai(t)(n.lifelines);if(r.tag==="Just")return $o.pure();if(r.tag==="Nothing"){const o={...n,lifelines:rt(A)(t)({id:t,label:e,column:n.lifelineOrder.length,createdAt:n.row,destroyedAt:w})(n.lifelines),lifelineOrder:Ct(n.lifelineOrder)(t),row:n.row>0||n.messages.length!==0?n.row+1|0:n.row};return uo.state(i=>b(void 0,o))}f()}),XE=t=>{if(t.tag==="AddNode")return VE(t._1.id)(t._1.label);if(t.tag==="DelNode")return HE(t._1.id);if(t.tag==="ModNode"){if(t._1.label.tag==="Just")return QE(t._1.id)(t._1.label._1);if(t._1.label.tag==="Nothing")return $o.pure();f()}return t.tag==="Token"?qE(t._1.from)(t._1.to)(t._1.labels):$o.pure()},YE=t=>Hn.bind(qr)(e=>{const n=e.row;return Hn.bind(ME(r=>o=>Hn.bind(qr)(i=>{const a=r.childMessages.length===0?r.dividers:[i.row,...r.dividers],s=i.messages;return Hn.bind(Rf(o))(()=>Hn.bind(qr)(u=>$o.pure({dividers:a,childMessages:[...r.childMessages,...(()=>{const c=u.messages.length-s.length|0;return c<1?[]:It(0,c,u.messages)})()]})))}))({dividers:[],childMessages:[]})(t))(r=>Hn.bind(qr)(o=>{const i=$E(r.childMessages)(o),a={kind:FE,label:"par",fromRow:n,toRow:Ju(o.row)(n+1|0),fromCol:i.fromCol,toCol:i.toCol,regionDividers:ce(r.dividers)},s=uo.state(u=>b(void 0,{...u,fragments:[a,...u.fragments]}));return r.childMessages.length>=2?s:$o.pure()}))}),Rf=t=>{if(t.tag==="Leaf")return XE(t._1.op);if(t.tag==="Seq"||t.tag==="GroupSeq")return o0(Rf)(t._1);if(t.tag==="Par")return YE(t._1);f()},KE=t=>{const e=Hn.bind(o0(n=>Hn.bind(qr)(r=>Hn.bind(Rf(n.ops))(()=>Hn.bind(qr)(o=>{const i=uo.state(a=>b(void 0,{...a,frameEndRows:Ct(a.frameEndRows)(a.row-1|0)}));return(o.messages.length-r.messages.length|0)>0?i:$o.pure()}))))(t.frames))(()=>qr)(OE)._1;if(e.error.tag==="Just")return Ot("Left",e.error._1);if(e.error.tag==="Nothing")return Ot("Right",UE(e));f()},jE=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},ZE={padding:24,headerHeight:36,headerWidth:120,columnSpacing:160,rowHeight:36,topGap:24,bottomGap:24},t4=t=>{const e=84+et(jE(1)(t.totalRows))*36,n=qt(r=>o=>({lifeline:o,x:84+et(r)*160}))(t.lifelines);return{metrics:ZE,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}},e4=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=it.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},i0=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},a0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=it.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}f()}return o},s0=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},n4=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},r4=J(t=>e=>rt(it)(e)()(t))(F),o4={r:255,g:255,b:255,a:255},bu={r:26,g:26,b:26,a:255},i4={color:{r:232,g:232,b:232,a:255},flat:!0},a4={r:232,g:232,b:232,a:255},Cu=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,...ha],u0=t=>e=>n=>({...n,stack:Ct(n.stack)(t),openedAt:rt(it)(t)(e)(n.openedAt)}),ku=t=>e=>{const n=e.stack.length-1|0;if(n>=0&&n<e.stack.length){const r=e4(e.stack[n])(e.openedAt),o=(()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return r._1;f()})();return{...e,stack:e.stack.length===0?[]:It(0,e.stack.length-1|0,e.stack),openedAt:oi(it)(e.stack[n])(e.openedAt),spans:Ct(e.spans)({col:e.stack[n],fromRow:o,toRow:i0(o)(t)})}}return e},c0=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,c=o,g=i,d=g.stack.length-1|0;if(d>=0&&d<g.stack.length){if(u(g.stack[d])){a=!1,s=g;continue}r=u,o=c,i=ku(c)(g);continue}a=!1,s=g}return s},g0=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r,u=s.stack.length-1|0;if(u>=0&&u<s.stack.length){n=a,r=ku(a)(s);continue}o=!1,i=s}return i},s4=t=>e=>{const n=nn($r)(e.fromCol)(t.stack)?c0((()=>{const r=e.fromCol;return o=>r===o})())(e.row-1|0)(t):u0(e.fromCol)(e.row)(g0(e.row-1|0)(t));if(nn($r)(e.toCol)(n.stack)){const r=c0((()=>{const o=e.toCol;return i=>o===i})())(e.row-1|0)(ku(e.row)(n));return{...r,returnRows:rt(it)(e.row)()(r.returnRows)}}return u0(e.toCol)(e.row)(n)},u4=t=>e=>n=>{const r=s4(e)(n);return a0(n.row)(t)?g0(n.row)(r):r},Lu={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:la,lineCap:Kn},f0={r:26,g:26,b:26,a:255},c4={color:{r:130,g:130,b:130,a:255},width:1,lineJoin:la,lineCap:vn},_0={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:la,lineCap:vn},g4={color:{r:244,g:244,b:244,a:255},flat:!0},d0=t=>e=>n=>le(r=>r.col===e&&r.fromRow<=n&&n<=r.toRow,t),l0={color:{r:90,g:90,b:90,a:255},width:1,lineJoin:la,lineCap:vn},f4={stack:[],openedAt:F,spans:[],returnRows:F},_4={color:{r:150,g:150,b:150,a:255},width:1,lineJoin:la,lineCap:vn},d4=t=>e=>n=>r=>o=>{const i=e.bodyTop+(et(o)+.5)*e.metrics.rowHeight-e.metrics.rowHeight/2;return t.strokePath([1,n,i,2,r,i])(_4)},l4=t=>{const e=t.Monad0(),n=e.Bind1(),r=jo(e.Applicative0())(Mt);return o=>i=>{const a=o.bodyTop+(et(i.fromRow)+.5)*o.metrics.rowHeight-o.metrics.rowHeight/2-6,s=i.fromCol>=0&&i.fromCol<o.columns.length?o.columns[i.fromCol].x-16:o.metrics.padding-16,u=[1,s,a,2,s+38,a,2,s+32,a+14,2,s,a+14,...ha],c=i.toCol>=0&&i.toCol<o.columns.length?o.columns[i.toCol].x+16:o.metrics.padding+16,g=o.bodyTop+(et(i0(i.toRow)(i.fromRow+1|0)-1|0)+.5)*o.metrics.rowHeight+o.metrics.rowHeight/2+6;return n.bind(t.strokePath([1,s,a,2,c,a,2,c,g,2,s,g,...ha])(l0))(()=>n.bind(t.fillStrokePath(u)(i4)(l0))(()=>n.bind(t.drawText({x:s+6,y:a+7,content:"par",font:{family:"Inter",size:11,weight:700},color:bu,align:Ti,baseline:Gn}))(()=>r(i.regionDividers)(d4(t)(o)(s)(c)))))}},h0=t=>e=>t>=e?[]:[b(t,s0(e)(t+6)),...h0(t+10)(e)],h4=t=>e=>{if(e<=t)return[];const n=r=>r>=e?[]:[b(r,s0(e)(r+6)),...n(r+10)];return n(t)},p4=t=>{const e=jo(t.Monad0().Applicative0())(Mt);return n=>r=>e(h4(n.headerTop+n.metrics.headerHeight+et(r.lifeline.createdAt)*n.metrics.rowHeight+4)((()=>{if(r.lifeline.destroyedAt.tag==="Just")return n.bodyTop+(et(r.lifeline.destroyedAt._1)+.5)*n.metrics.rowHeight;if(r.lifeline.destroyedAt.tag==="Nothing")return n.bodyBottom;f()})()))(o=>t.strokePath([1,r.x,o._1,2,r.x,o._2])(c4))},p0=t=>e=>t<=e?[]:[b(t,n4(e)(t-6)),...p0(t-6-4)(e)],m4=t=>e=>t===e?[]:t<e?h0(t)(e):p0(t)(e),y4=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.headerTop+et(r.lifeline.createdAt)*n.metrics.rowHeight,i=n.metrics.headerWidth/2,a=o+n.metrics.headerHeight,s=Cu(r.x-i)(o)(r.x+i)(a)(6);return e.bind(t.fillStrokePath(Cu(r.x-i)(o+5)(r.x+i)(a+5)(6))({color:a4,flat:!0})(_0))(()=>e.bind(t.fillStrokePath(s)(g4)(_0))(()=>t.drawText({x:r.x,y:o+n.metrics.headerHeight/2,content:r.lifeline.label,font:{family:"Inter",size:14,weight:600},color:bu,align:Br,baseline:Gn})))}},x4=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const a=n,s=r,u=s.stack.length-1|0;if(u>=0&&u<s.stack.length){n=a,r=ku(a)(s);continue}o=!1,i=s}return i},w4=t=>x4((()=>{const e=t.diagram.messages.length-1|0;return e>=0&&e<t.diagram.messages.length?t.diagram.messages[e].row:0})())(J(u4(r4(t.diagram.frameEndRows)))(f4)(dt(e=>e.kind==="Sync"||e.kind!=="SelfMsg",t.diagram.messages))),N4=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.bodyTop+(et(r.row)+.5)*n.metrics.rowHeight,i=r.fromCol>=0&&r.fromCol<n.columns.length?n.columns[r.fromCol].x:n.metrics.padding,a=o-n.metrics.rowHeight*.3,s=i+36,u=o+n.metrics.rowHeight*.3,c=i+10,g=[1,i,u,2,c,u-5,2,c,u+5,...ha];return e.bind(t.strokePath([1,i,a,2,s,a,2,s,u,2,i,u])(Lu))(()=>e.bind(t.fillPath(g)({color:f0,flat:!0}))(()=>t.drawText({x:i+42,y:o,content:dr(" ")(U(Bi)(r.labels)),font:{family:"Inter",size:12,weight:400},color:bu,align:Ti,baseline:Gn})))}},v4=t=>{const e=t.Monad0(),n=e.Bind1(),r=jo(e.Applicative0())(Mt);return o=>i=>a=>s=>{const u=a?o.bodyTop+(et(s.row)+.5)*o.metrics.rowHeight+o.metrics.rowHeight*.5:o.bodyTop+(et(s.row)+.5)*o.metrics.rowHeight,c=s.toCol>=s.fromCol?1:-1,g=(s.fromCol>=0&&s.fromCol<o.columns.length?o.columns[s.fromCol].x:o.metrics.padding)+(d0(i)(s.fromCol)(s.row)?c*6:c*0),d=(s.toCol>=0&&s.toCol<o.columns.length?o.columns[s.toCol].x:o.metrics.padding)-(d0(i)(s.toCol)(s.row)?c*6:c*0),l=d-c*10,_=a?t.strokePath([1,l,u-5,2,d,u,2,l,u+5])(Lu):t.fillPath([1,d,u,2,l,u-5,2,l,u+5,...ha])({color:f0,flat:!0});return n.bind(a?r(m4(g)(d))(h=>t.strokePath([1,h._1,u,2,h._2,u])(Lu)):t.strokePath([1,g,u,2,d,u])(Lu))(()=>n.bind(_)(()=>t.drawText({x:(g+d)/2,y:u-6,content:dr(" ")(U(Bi)(s.labels)),font:{family:"Inter",size:12,weight:400},color:bu,align:Br,baseline:qb})))}},T4=t=>{const e=N4(t),n=v4(t);return r=>o=>i=>a=>{if(a.kind==="SelfMsg")return e(r)(a);if(a.kind==="Sync")return n(r)(o)(a0(a.row)(i))(a);f()}},m0={color:{r:26,g:26,b:26,a:255},width:1.25,lineJoin:$e,lineCap:vn},J4={color:{r:232,g:232,b:232,a:255},flat:!0},b4={color:{r:252,g:252,b:252,a:255},flat:!0},C4=t=>e=>n=>{const r=n.col>=0&&n.col<e.columns.length?e.columns[n.col].x:e.metrics.padding,o=e.bodyTop+(et(n.fromRow)+.5)*e.metrics.rowHeight,i=e.bodyTop+(et(n.toRow)+.5)*e.metrics.rowHeight+e.metrics.rowHeight*.5,a=Cu(r-6)(o)(r+6)(i)(3);return t.Monad0().Bind1().bind(t.fillStrokePath(Cu(r-6)(o+5)(r+6)(i+5)(3))(J4)(m0))(()=>t.fillStrokePath(a)(b4)(m0))},y0=t=>{const e=t.Monad0(),n=e.Bind1(),r=jo(e.Applicative0())(Mt),o=y4(t),i=p4(t),a=l4(t),s=T4(t);return u=>{const c=w4(u);return n.bind(t.setViewport({vx:0,vy:0,vw:u.width,vh:u.height}))(()=>n.bind(t.clearBackground(o4))(()=>n.bind(r(u.columns)(o(u)))(()=>n.bind(r(u.columns)(i(u)))(()=>n.bind(r(c.spans)(C4(t)(u)))(()=>n.bind(r(u.diagram.fragments)(a(u)))(()=>r(u.diagram.messages)(s(u)(c.spans)(c.returnRows))))))))}},k4=y0(sC);function Bf(t,e,n,r){if(typeof window<"u"){var o=window[n];if(o!=null&&r instanceof o)return e(r)}for(var i=r;i!=null;){var a=Object.getPrototypeOf(i),s=a.constructor.name;if(s===n)return e(r);if(s==="Object")return t;i=a}return t}function cn(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function L4(t){return function(e){return function(){return e.getAttribute(t)}}}const x0=t=>{const e=L4(t);return n=>{const r=e(n);return()=>{const o=r();return xn(o,w,Vt)}}};function S4(t){return function(e){return function(){e.textContent=t}}}function E4(t){return function(){return function(e){return t(e)()}}}function P4(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const Ff=function(){return window};function A4(t){return function(e){return function(){e.value=t}}}function G4(t){return function(){return t.valueAsNumber}}function I4(t){return function(){return t.value}}function Mf(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const Su=t=>t,Eu=t=>()=>{const e=t.getBoundingClientRect?.(),n=e?.width||t.clientWidth||0,r=e?.height||t.clientHeight||0;return{width:n,height:r}},w0=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)}},N0=()=>window.devicePixelRatio||1,D4=t=>e=>n=>r=>o=>()=>{const i=Math.max(1,e||t.clientWidth||r),a=Math.max(1,n||t.clientHeight||o),s="Markgraf needs more room",u=`Resize to at least ${Math.round(r)} \xD7 ${Math.round(o)} px`;if(t.setAttribute("data-mg-too-small","1"),t.setAttribute("data-mg-viewport-css-width",String(e||0)),t.setAttribute("data-mg-viewport-css-height",String(n||0)),t.setAttribute("data-mg-camera-vw","0"),t.setAttribute("data-mg-camera-vh","0"),t.setAttribute("data-mg-camera-zoom","0"),t instanceof SVGElement){t.setAttribute("viewBox",`0 0 ${i} ${a}`),t.setAttribute("preserveAspectRatio","xMidYMid meet"),t.innerHTML=`
|
|
27
|
+
<rect x="0" y="0" width="${i}" height="${a}" rx="16" fill="#111827"/>
|
|
28
|
+
<text x="${i/2}" y="${a/2-10}" text-anchor="middle" dominant-baseline="middle" fill="#f9fafb" font-family="system-ui, sans-serif" font-size="18" font-weight="700">${s}</text>
|
|
29
|
+
<text x="${i/2}" y="${a/2+18}" text-anchor="middle" dominant-baseline="middle" fill="#cbd5e1" font-family="system-ui, sans-serif" font-size="13">${u}</text>
|
|
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(a*c));const g=t.getContext("2d");if(!g)return;g.save(),g.scale(c,c),g.clearRect(0,0,i,a),g.fillStyle="#111827",g.fillRect(0,0,i,a),g.textAlign="center",g.textBaseline="middle",g.fillStyle="#f9fafb",g.font="700 18px system-ui, sans-serif",g.fillText(s,i/2,a/2-10),g.fillStyle="#cbd5e1",g.font="13px system-ui, sans-serif",g.fillText(u,i/2,a/2+18),g.restore();return}t.textContent=`${s}. ${u}.`},Aa=(t,e)=>{e.innerHTML=t},Pu=(t,e,n)=>{t.style.setProperty(e,n)},R4=(t,e)=>t.querySelector(`[data-mg="${e}"]`),Au=t=>e=>t===e,Uo=new WeakMap,Ga=new WeakSet,Ia=new WeakMap,Gu=new WeakMap,Iu=new WeakSet,Gi=new WeakMap,Du=new WeakMap,Ru=new WeakMap;let B4=0;const F4=`#version 300 es
|
|
31
|
+
precision highp float;
|
|
32
|
+
out vec2 vUv;
|
|
33
|
+
void main() {
|
|
34
|
+
vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
|
|
35
|
+
vUv = p;
|
|
36
|
+
gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
|
37
|
+
}`,M4=`#version 300 es
|
|
38
|
+
precision highp float;
|
|
39
|
+
uniform sampler2D uScene;
|
|
40
|
+
uniform float uStrength;
|
|
41
|
+
uniform float uFilmAmount;
|
|
42
|
+
uniform float uTime;
|
|
43
|
+
in vec2 vUv;
|
|
44
|
+
out vec4 fragColor;
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
float grain(vec2 pixel, float frame) {
|
|
48
|
+
vec2 cell = floor(pixel);
|
|
49
|
+
return fract(sin(dot(cell + vec2(frame * 17.0, frame * 31.0), vec2(12.9898, 78.233))) * 43758.5453);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void main() {
|
|
53
|
+
float film = clamp(uFilmAmount, 0.0, 1.0);
|
|
54
|
+
vec4 color = texture(uScene, vUv);
|
|
55
|
+
float strength = clamp(uStrength, 0.0, 1.0);
|
|
56
|
+
// Non-spatial film character only: never shift, resample, or shade scene
|
|
57
|
+
// pixels. Spatial vignettes read as muddy gradients on flat diagram fills.
|
|
58
|
+
float frame = floor(uTime * 18.0);
|
|
59
|
+
float grainValue = grain(gl_FragCoord.xy, frame) - 0.5;
|
|
60
|
+
color.rgb += grainValue * (0.026 + 0.014 * strength) * film;
|
|
61
|
+
float flicker = sin(uTime * 21.7) * 0.004 + sin(uTime * 7.1) * 0.003;
|
|
62
|
+
color.rgb *= 1.0 + flicker * film;
|
|
63
|
+
fragColor = color;
|
|
64
|
+
}`,z4=`#version 300 es
|
|
65
|
+
precision highp float;
|
|
66
|
+
uniform vec4 uDestRect;
|
|
67
|
+
uniform float uOpen;
|
|
68
|
+
uniform float uPanel;
|
|
69
|
+
uniform float uFall;
|
|
70
|
+
out vec2 vLocal;
|
|
71
|
+
out float vSurface;
|
|
72
|
+
out float vThickness;
|
|
73
|
+
|
|
74
|
+
void main() {
|
|
75
|
+
vec2 corners[6] = vec2[6](
|
|
76
|
+
vec2(0.0, 0.0), vec2(1.0, 0.0), vec2(0.0, 1.0),
|
|
77
|
+
vec2(0.0, 1.0), vec2(1.0, 0.0), vec2(1.0, 1.0)
|
|
78
|
+
);
|
|
79
|
+
int surface = gl_VertexID / 6;
|
|
80
|
+
vec2 p = corners[gl_VertexID - surface * 6];
|
|
81
|
+
bool falling = uFall > 0.5;
|
|
82
|
+
bool left = uPanel < 0.0;
|
|
83
|
+
if (surface == 3 || (!falling && surface == 0 && !left)) p.x = 1.0 - p.x;
|
|
84
|
+
float closedX;
|
|
85
|
+
float localY;
|
|
86
|
+
float thickness;
|
|
87
|
+
if (falling) {
|
|
88
|
+
if (surface == 0) {
|
|
89
|
+
// The top edge of a single panel hinged along its bottom.
|
|
90
|
+
closedX = p.x;
|
|
91
|
+
localY = 0.0;
|
|
92
|
+
thickness = p.y;
|
|
93
|
+
} else if (surface == 1 || surface == 2) {
|
|
94
|
+
// Left and right edges.
|
|
95
|
+
closedX = surface == 1 ? 0.0 : 1.0;
|
|
96
|
+
localY = p.x;
|
|
97
|
+
thickness = p.y;
|
|
98
|
+
} else {
|
|
99
|
+
closedX = p.x;
|
|
100
|
+
localY = p.y;
|
|
101
|
+
thickness = surface == 3 ? 1.0 : 0.0;
|
|
102
|
+
}
|
|
103
|
+
} else if (surface == 0) {
|
|
104
|
+
// The unhinged vertical edge.
|
|
105
|
+
closedX = 0.5;
|
|
106
|
+
localY = p.y;
|
|
107
|
+
thickness = p.x;
|
|
108
|
+
} else if (surface == 1 || surface == 2) {
|
|
109
|
+
// Top and bottom edges.
|
|
110
|
+
closedX = left ? p.x * 0.5 : 0.5 + p.x * 0.5;
|
|
111
|
+
localY = surface == 1 ? 0.0 : 1.0;
|
|
112
|
+
thickness = p.y;
|
|
113
|
+
} else {
|
|
114
|
+
closedX = left ? p.x * 0.5 : 0.5 + p.x * 0.5;
|
|
115
|
+
localY = p.y;
|
|
116
|
+
thickness = surface == 3 ? 1.0 : 0.0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
float slabDepth = 0.032;
|
|
120
|
+
float projectedW;
|
|
121
|
+
vec2 projectedLocal;
|
|
122
|
+
if (falling) {
|
|
123
|
+
float angle = max(0.0, uOpen) * 3.05;
|
|
124
|
+
float towardViewer = (1.0 - localY) * sin(angle);
|
|
125
|
+
float rotatedY = 1.0 + (localY - 1.0) * cos(angle);
|
|
126
|
+
rotatedY += slabDepth * sin(angle) * thickness;
|
|
127
|
+
towardViewer -= slabDepth * cos(angle) * thickness;
|
|
128
|
+
projectedW = 1.0 - towardViewer * 0.22;
|
|
129
|
+
projectedLocal = vec2(closedX, rotatedY);
|
|
130
|
+
} else {
|
|
131
|
+
float hingeX = left ? 0.0 : 1.0;
|
|
132
|
+
float angle = max(0.0, uOpen) * 1.91986;
|
|
133
|
+
float towardViewer = abs(closedX - hingeX) * sin(angle);
|
|
134
|
+
float rotatedX = hingeX + (closedX - hingeX) * cos(angle);
|
|
135
|
+
// The authored face is the front of a shallow slab. Its body extends away
|
|
136
|
+
// from the viewer, rotated about the same border-welded vertical hinge.
|
|
137
|
+
float panelSide = left ? 1.0 : -1.0;
|
|
138
|
+
rotatedX += panelSide * slabDepth * sin(angle) * thickness;
|
|
139
|
+
towardViewer -= slabDepth * cos(angle) * thickness;
|
|
140
|
+
projectedW = 1.0 - towardViewer * 1.1;
|
|
141
|
+
projectedLocal = vec2(rotatedX, localY);
|
|
142
|
+
}
|
|
143
|
+
vec2 center = uDestRect.xy + uDestRect.zw * 0.5;
|
|
144
|
+
vec2 world = uDestRect.xy + projectedLocal * uDestRect.zw;
|
|
145
|
+
vec2 projected = center + (world - center) / projectedW;
|
|
146
|
+
vec2 ndc = vec2(projected.x * 2.0 - 1.0, 1.0 - projected.y * 2.0);
|
|
147
|
+
gl_Position = vec4(ndc * projectedW, 0.0, projectedW);
|
|
148
|
+
vLocal = vec2(closedX, localY);
|
|
149
|
+
vSurface = float(surface);
|
|
150
|
+
vThickness = thickness;
|
|
151
|
+
}`,Q4=`#version 300 es
|
|
152
|
+
precision highp float;
|
|
153
|
+
uniform sampler2D uDoor;
|
|
154
|
+
uniform vec4 uCaptureRect;
|
|
155
|
+
uniform vec2 uFaceSize;
|
|
156
|
+
uniform float uOpen;
|
|
157
|
+
uniform float uAttention;
|
|
158
|
+
uniform float uPanel;
|
|
159
|
+
uniform float uFall;
|
|
160
|
+
uniform float uRadius;
|
|
161
|
+
in vec2 vLocal;
|
|
162
|
+
in float vSurface;
|
|
163
|
+
in float vThickness;
|
|
164
|
+
out vec4 fragColor;
|
|
165
|
+
|
|
166
|
+
float roundedPanel(vec2 local) {
|
|
167
|
+
bool falling = uFall > 0.5;
|
|
168
|
+
bool left = uPanel < 0.0;
|
|
169
|
+
vec2 panelLocal = falling
|
|
170
|
+
? local
|
|
171
|
+
: vec2(left ? local.x * 2.0 : (local.x - 0.5) * 2.0, local.y);
|
|
172
|
+
vec2 panelSize = vec2(falling ? uFaceSize.x : uFaceSize.x * 0.5, uFaceSize.y);
|
|
173
|
+
vec2 halfSize = panelSize * 0.5;
|
|
174
|
+
float radius = min(uRadius, min(halfSize.x, halfSize.y));
|
|
175
|
+
bool innerCorner = !falling && (left ? panelLocal.x > 0.5 : panelLocal.x < 0.5);
|
|
176
|
+
float innerReveal = smoothstep(0.08, 0.20, uOpen);
|
|
177
|
+
float cornerRadius = innerCorner ? radius * innerReveal : radius;
|
|
178
|
+
vec2 q =
|
|
179
|
+
abs((panelLocal - 0.5) * panelSize) -
|
|
180
|
+
(halfSize - vec2(cornerRadius));
|
|
181
|
+
return
|
|
182
|
+
length(max(q, 0.0)) +
|
|
183
|
+
min(max(q.x, q.y), 0.0) -
|
|
184
|
+
cornerRadius;
|
|
185
|
+
}
|
|
186
|
+
vec2 doorUv(vec2 local) {
|
|
187
|
+
return vec2(
|
|
188
|
+
uCaptureRect.x + local.x * uCaptureRect.z,
|
|
189
|
+
1.0 - (uCaptureRect.y + local.y * uCaptureRect.w)
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
float bayer4(vec2 pixel) {
|
|
193
|
+
float thresholds[16] = float[16](
|
|
194
|
+
0.0, 8.0, 2.0, 10.0,
|
|
195
|
+
12.0, 4.0, 14.0, 6.0,
|
|
196
|
+
3.0, 11.0, 1.0, 9.0,
|
|
197
|
+
15.0, 7.0, 13.0, 5.0
|
|
198
|
+
);
|
|
199
|
+
ivec2 cell = ivec2(mod(floor(pixel), 4.0));
|
|
200
|
+
return (thresholds[cell.y * 4 + cell.x] + 0.5) / 16.0;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
void main() {
|
|
206
|
+
// Each moving half keeps the authored outer radius. Its cut-edge corners
|
|
207
|
+
// round only after the split opens, so the closed leaves still form one
|
|
208
|
+
// continuous rounded face without a notched centre seam.
|
|
209
|
+
if (roundedPanel(vLocal) > 0.0) discard;
|
|
210
|
+
if (uOpen < 0.08 && vSurface < 3.5) discard;
|
|
211
|
+
vec4 material = texture(uDoor, doorUv(vLocal));
|
|
212
|
+
if (vSurface > 3.5) {
|
|
213
|
+
material.rgb *= 1.0 - 0.20 * uOpen;
|
|
214
|
+
} else if (vSurface > 2.5) {
|
|
215
|
+
// Recover a label-free base color, then use a uniform two-tone stipple.
|
|
216
|
+
// Spatial lighting ramps looked like accidental gradients on flat nodes.
|
|
217
|
+
vec4 back0 = texture(uDoor, doorUv(vec2(0.34, 0.30)));
|
|
218
|
+
vec4 back1 = texture(uDoor, doorUv(vec2(0.66, 0.30)));
|
|
219
|
+
vec4 back2 = texture(uDoor, doorUv(vec2(0.34, 0.70)));
|
|
220
|
+
vec4 back3 = texture(uDoor, doorUv(vec2(0.66, 0.70)));
|
|
221
|
+
float backWeight = back0.a + back1.a + back2.a + back3.a;
|
|
222
|
+
vec3 backMaterial =
|
|
223
|
+
(
|
|
224
|
+
back0.rgb * back0.a +
|
|
225
|
+
back1.rgb * back1.a +
|
|
226
|
+
back2.rgb * back2.a +
|
|
227
|
+
back3.rgb * back3.a
|
|
228
|
+
) / max(0.001, backWeight);
|
|
229
|
+
if (backWeight < 0.1) backMaterial = material.rgb;
|
|
230
|
+
float angle = smoothstep(0.08, 0.18, uOpen) * 1.91986;
|
|
231
|
+
float facing = abs(cos(angle));
|
|
232
|
+
float density = mix(0.46, 0.66, facing);
|
|
233
|
+
float dither = bayer4(gl_FragCoord.xy * 0.5);
|
|
234
|
+
vec3 darkInk = backMaterial * 0.48;
|
|
235
|
+
vec3 lightInk = min(vec3(1.0), backMaterial * 0.96 + vec3(0.025));
|
|
236
|
+
material.rgb = mix(darkInk, lightInk, step(dither, density));
|
|
237
|
+
} else {
|
|
238
|
+
if (vSurface > 0.5 && vSurface < 1.5) {
|
|
239
|
+
float ledgeDither = bayer4(gl_FragCoord.xy * 0.5);
|
|
240
|
+
material.rgb = mix(vec3(0.11), vec3(0.46), step(ledgeDither, 0.44));
|
|
241
|
+
} else {
|
|
242
|
+
material.rgb = vec3(vSurface < 0.5 ? 0.18 : 0.24);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (vSurface > 2.5) {
|
|
246
|
+
float splitReveal = smoothstep(0.18, 0.34, uOpen);
|
|
247
|
+
float edgeDistance = abs(roundedPanel(vLocal));
|
|
248
|
+
float screenPixel = max(fwidth(edgeDistance), 0.0001);
|
|
249
|
+
float outline = splitReveal
|
|
250
|
+
* (1.0 - smoothstep(0.35 * screenPixel, 3.5 * screenPixel, edgeDistance));
|
|
251
|
+
float outlineX = uPanel < 0.0 ? 0.0 : 1.0;
|
|
252
|
+
vec4 outlineMaterial = texture(uDoor, doorUv(vec2(outlineX, 0.5)));
|
|
253
|
+
material.rgb = mix(material.rgb, outlineMaterial.rgb, outline);
|
|
254
|
+
material.a = max(material.a, outline * outlineMaterial.a);
|
|
255
|
+
}
|
|
256
|
+
material.a = 1.0;
|
|
257
|
+
fragColor = material;
|
|
258
|
+
}`,v0=(t,e,n)=>{const r=t.createShader(e);if(!r)throw new Error("Unable to allocate zoom shader");if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS)){const o=t.getShaderInfoLog(r)||"Zoom shader compilation failed";throw t.deleteShader(r),new Error(o)}return r},T0=(t,e,n,r)=>{const o=v0(t,t.VERTEX_SHADER,e),i=v0(t,t.FRAGMENT_SHADER,n),a=t.createProgram();if(!a)throw new Error(`Unable to allocate ${r} program`);if(t.attachShader(a,o),t.attachShader(a,i),t.linkProgram(a),t.deleteShader(o),t.deleteShader(i),!t.getProgramParameter(a,t.LINK_STATUS)){const s=t.getProgramInfoLog(a)||`${r} shader link failed`;throw t.deleteProgram(a),new Error(s)}return a},J0=t=>{if(typeof document>"u"||typeof t?.getContext!="function"||!t.parentElement)return null;const e=document.createElement("canvas"),n=e.getContext("webgl2",{alpha:!0,antialias:!1,depth:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,stencil:!1});if(!n)return null;const r=t.parentElement,o=r.style.position,i=getComputedStyle(r).position==="static";i&&(r.style.position="relative"),e.dataset.mg="velocity-pass",e.setAttribute("aria-hidden","true"),Object.assign(e.style,{display:"none",left:`${t.offsetLeft}px`,pointerEvents:"none",position:"absolute",top:`${t.offsetTop}px`,zIndex:"1"}),t.insertAdjacentElement("afterend",e);try{const a=T0(n,F4,M4,"zoom"),s=T0(n,z4,Q4,"door"),u=n.createTexture();if(!u)throw new Error("Unable to allocate zoom texture");return n.bindTexture(n.TEXTURE_2D,u),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!0),n.useProgram(a),n.uniform1i(n.getUniformLocation(a,"uScene"),0),n.useProgram(s),n.uniform1i(n.getUniformLocation(s,"uDoor"),1),{changedPosition:i,doorAttentionLocation:n.getUniformLocation(s,"uAttention"),doorCaptureLocation:n.getUniformLocation(s,"uCaptureRect"),doorDestLocation:n.getUniformLocation(s,"uDestRect"),doorFaceSizeLocation:n.getUniformLocation(s,"uFaceSize"),doorRadiusLocation:n.getUniformLocation(s,"uRadius"),doorFallLocation:n.getUniformLocation(s,"uFall"),doorOpenLocation:n.getUniformLocation(s,"uOpen"),doorPanelLocation:n.getUniformLocation(s,"uPanel"),doorProgram:s,doorTextures:new Map,gl:n,overlay:e,overlayHeight:-1,overlayLeft:-1,overlayTop:-1,overlayWidth:-1,parent:r,program:a,restorePosition:o,restoreVisibility:t.style.visibility,sceneTextureHeight:0,sceneTextureWidth:0,source:t,texture:u,zoomFilmAmountLocation:n.getUniformLocation(a,"uFilmAmount"),zoomStrengthLocation:n.getUniformLocation(a,"uStrength"),zoomTimeLocation:n.getUniformLocation(a,"uTime")}}catch{return e.remove(),i&&r.style.position==="relative"&&(r.style.position=o),null}},b0=t=>{const e=Gi.get(t);e&&e(),Gi.delete(t)},W4=t=>{if(Uo.has(t)||Ga.has(t)||Gi.has(t))return;const e=()=>{if(Gi.delete(t),!t.isConnected||Uo.has(t))return;let n=null;try{n=J0(t)}catch{n=null}n?Uo.set(t,n):(Ga.add(t),t.setAttribute("data-mg-gpu-pass","unavailable"))};if(typeof requestIdleCallback=="function"){const n=requestIdleCallback(e,{timeout:50});Gi.set(t,()=>cancelIdleCallback(n))}else{const n=setTimeout(e,0);Gi.set(t,()=>clearTimeout(n))}},O4=(t,e)=>{e&&(e.overlay.style.display!=="none"&&(e.overlay.style.display="none"),t.style.visibility!==e.restoreVisibility&&(t.style.visibility=e.restoreVisibility)),t.getAttribute("data-mg-gpu-pass")!=="idle"&&t.setAttribute("data-mg-gpu-pass","idle"),t.removeAttribute("data-mg-door-motion")},q4=(t,e)=>{const n=Ia.get(t),r=n?.canvas||document.createElement("canvas");r.width!==t.width&&(r.width=t.width),r.height!==t.height&&(r.height=t.height);const o=r.getContext("2d");o&&(o.clearRect(0,0,r.width,r.height),o.drawImage(t,0,0),Ia.set(t,{canvas:r,capture:[e.x,e.y,e.w,e.h],faceSize:[e.w*t.width,e.h*t.height],key:String(e.key),radius:e.r*t.width,version:(n?.version||0)+1}))},zf=(t,e,n)=>{const r=Math.max(0,Math.min(1,(n-t)/Math.max(1e-6,e-t)));return r*r*(3-2*r)},H4=(t,e,n)=>Math.max(0,Math.min(Number(t)||0,Math.max(0,Number(e)||0)*.5,Math.max(0,Number(n)||0)*.5)),$4=4,U4=(t,e)=>Math.max(0,Number(t)||0)/Math.max(1e-6,Math.max(0,Number(e)||0))>=$4,V4=(t,e)=>{let n=(Number(t)|0)^2166136261;for(let r=0;r<String(e).length;r+=1)n=Math.imul(n^String(e).charCodeAt(r),16777619);return n>>>0},C0=(t,e,n,r)=>U4(n,r)||V4(t,e)%3===0,Ii=.48,Di=10.8,k0=Math.sqrt(1-Ii*Ii),Bu=Di*k0,L0=Ii/k0,X4=1-Math.exp(-Ii*Di)*(Math.cos(Bu)+L0*Math.sin(Bu)),Qf=t=>{const e=Math.max(0,Math.min(1,t));return(1-Math.exp(-Ii*Di*e)*(Math.cos(Bu*e)+L0*Math.sin(Bu*e)))/X4},Y4=(t,e,n)=>{let r=Number.isFinite(t.value)?t.value:0,o=Number.isFinite(t.velocity)?t.velocity:0,i=Math.max(0,Math.min(.1,Number(n)||0));const a=Number(e)>=.5?1:0;for(;i>0;){const s=Math.min(i,.008333333333333333),u=Di*Di*(a-r)-2*Ii*Di*o;o+=u*s,r+=o*s,i-=s}return{value:r,velocity:o}},S0=(t,e,n,r)=>{const o=String(e.key),i=Number(e.progress)||0,a=Number(e.depth)||0,s=Gu.get(t),u=s&&s.key===o&&s.direction===n,c=u&&Math.abs(i-s.progress)>.12;let g=u?s:{direction:n,key:o,progress:i,value:E0(a,i,n),velocity:0};if(c)g={...g,value:E0(a,i,n),velocity:0};else{const d=1-Math.max(0,Math.min(1,a)),l=(n<0?i>=.25:d<.48)?1:0;g={...g,...Y4(g,l,r)}}return g.progress=i,Gu.set(t,g),g.value},E0=(t,e,n)=>{if(n<0){const s=Math.max(0,Math.min(1,(e-.25)/.28));return Qf(s*s*s)}const r=1-Math.max(0,Math.min(1,t)),o=Math.max(0,Math.min(1,(r-.48)/.5)),i=.48,a=Qf(o*i)/Qf(i);return Math.min(1,Math.abs(1-a))},Vo="http://www.w3.org/2000/svg",K4=t=>{if(!t.parentElement)return null;const e=t.parentElement,n=e.style.position,r=getComputedStyle(e).position==="static";r&&(e.style.position="relative");const o=document.createElementNS(Vo,"svg");o.dataset.mg="svg-door-pass",o.setAttribute("aria-hidden","true"),o.setAttribute("viewBox","0 0 1 1"),o.setAttribute("preserveAspectRatio","none");const i=document.createElementNS(Vo,"defs");o.appendChild(i);const a=h=>{const p=document.createElementNS(Vo,"path");p.dataset.mgDoorLeaf=h;const m=`mg-door-${h}-${++B4}`;p.setAttribute("id",m),p.setAttribute("vector-effect","non-scaling-stroke"),p.setAttribute("stroke-linejoin","round"),o.appendChild(p);const y=document.createElementNS(Vo,"clipPath"),x=`${m}-clip`;y.setAttribute("id",x),y.setAttribute("clipPathUnits","userSpaceOnUse");const N=document.createElementNS(Vo,"use");N.setAttribute("href",`#${m}`),y.appendChild(N),i.appendChild(y);const T=document.createElementNS(Vo,"text");return T.dataset.mgDoorLabelClip=`url(#${x})`,T.dataset.mgDoorLabelHalf=h,T.setAttribute("clip-path",`url(#${x})`),T.setAttribute("text-anchor","middle"),T.setAttribute("stroke","none"),{label:T,leaf:p}},s=a("left"),u=a("right"),c=(h,p)=>{const m=document.createElementNS(Vo,"path");return m.dataset[h==="outer"?"mgDoorOuter":"mgDoorSeam"]=p,m.setAttribute("fill","none"),m.setAttribute("stroke-linejoin","round"),m.setAttribute("vector-effect","non-scaling-stroke"),o.appendChild(m),m},g=c("outer","left"),d=c("outer","right"),l=c("seam","left"),_=c("seam","right");return o.appendChild(s.label),o.appendChild(u.label),Object.assign(o.style,{display:"none",pointerEvents:"none",position:"absolute",zIndex:"1"}),t.insertAdjacentElement("afterend",o),{changedPosition:r,left:s.leaf,leftLabel:s.label,overlay:o,leftOuter:g,leftSeam:l,parent:e,restorePosition:n,right:u.leaf,rightLabel:u.label,rightOuter:d,rightSeam:_}},co=(t,e,n,r,o)=>{const i=n?0:1,a=Math.abs(r-i)*Math.sin(e),s=i+(r-i)*Math.cos(e),u=1-a*1.1,c=Number(t.x)+Number(t.w)*.5,g=Number(t.y)+Number(t.h)*.5,d=Number(t.x)+s*Number(t.w),l=Number(t.y)+o*Number(t.h);return[c+(d-c)/u,g+(l-g)/u]},P0=(t,e,n,r)=>{const o=Math.max(0,e)*1.91986,i=Math.max(0,Math.min(.5,Number(t.r)/Math.max(1e-6,Number(t.w)))),a=Math.max(0,Math.min(.5,Number(t.r)*r/Math.max(1e-6,Number(t.h)))),s=m=>co(t,o,n,m[0],m[1]),u=(m,...y)=>`${m}${y.map(s).map(x=>`${x[0]},${x[1]}`).join(" ")}`,c=.5522847498307936,g=zf(.08,.2,e),d=i*g,l=a*g,_=[u("M",[.5,l]),u("L",[.5,1-l])].join(" ");if(n){const m=[u("M",[i,0]),u("C",[i*(1-c),0],[0,a*(1-c)],[0,a]),u("L",[0,1-a]),u("C",[0,1-a*(1-c)],[i*(1-c),1],[i,1]),u("L",[.5-d,1]),u("C",[.5-d*(1-c),1],[.5,1-l*(1-c)],[.5,1-l]),u("L",[.5,l]),u("C",[.5,l*(1-c)],[.5-d*(1-c),0],[.5-d,0]),"Z"].join(" "),y=[u("M",[.5,l]),u("C",[.5,l*(1-c)],[.5-d*(1-c),0],[.5-d,0]),u("L",[i,0]),u("C",[i*(1-c),0],[0,a*(1-c)],[0,a]),u("L",[0,1-a]),u("C",[0,1-a*(1-c)],[i*(1-c),1],[i,1]),u("L",[.5-d,1]),u("C",[.5-d*(1-c),1],[.5,1-l*(1-c)],[.5,1-l])].join(" ");return{fill:m,outer:y,seam:_}}const h=[u("M",[.5+d,0]),u("L",[1-i,0]),u("C",[1-i*(1-c),0],[1,a*(1-c)],[1,a]),u("L",[1,1-a]),u("C",[1,1-a*(1-c)],[1-i*(1-c),1],[1-i,1]),u("L",[.5+d,1]),u("C",[.5+d*(1-c),1],[.5,1-l*(1-c)],[.5,1-l]),u("L",[.5,l]),u("C",[.5,l*(1-c)],[.5+d*(1-c),0],[.5+d,0]),"Z"].join(" "),p=[u("M",[.5,l]),u("C",[.5,l*(1-c)],[.5+d*(1-c),0],[.5+d,0]),u("L",[1-i,0]),u("C",[1-i*(1-c),0],[1,a*(1-c)],[1,a]),u("L",[1,1-a]),u("C",[1,1-a*(1-c)],[1-i*(1-c),1],[1-i,1]),u("L",[.5+d,1]),u("C",[.5+d*(1-c),1],[.5,1-l*(1-c)],[.5,1-l])].join(" ");return{fill:h,outer:p,seam:_}},Wf=(t,e)=>{const n=Math.max(0,e)*3.05,r=Math.cos(n);return{expansion:1+Math.sin(n)*.16,verticalScale:Math.abs(r)<.06?r<0?-.06:.06:r}},Of=(t,e,n,r)=>{const{expansion:o,verticalScale:i}=Wf(t,e),a=Number(t.x)+Number(t.w)*.5,s=Number(t.y)+Number(t.h),u=Number(t.x)+n*Number(t.w),c=Number(t.y)+r*Number(t.h);return[a+(u-a)*o,s+(c-s)*i]},j4=(t,e,n)=>{const r=Math.max(0,Math.min(.5,Number(t.r)/Math.max(1e-6,Number(t.w)))),o=Math.max(0,Math.min(.5,Number(t.r)*n/Math.max(1e-6,Number(t.h)))),i=c=>Of(t,e,c[0],c[1]),a=(c,...g)=>`${c}${g.map(i).map(d=>`${d[0]},${d[1]}`).join(" ")}`,s=.5522847498307936,u=[a("M",[r,0]),a("C",[r*(1-s),0],[0,o*(1-s)],[0,o]),a("L",[0,1-o]),a("C",[0,1-o*(1-s)],[r*(1-s),1],[r,1]),a("L",[1-r,1]),a("C",[1-r*(1-s),1],[1,1-o*(1-s)],[1,1-o]),a("L",[1,o]),a("C",[1,o*(1-s)],[1-r*(1-s),0],[1-r,0]),"Z"].join(" ");return{fill:u,outer:u,seam:""}},Z4=(t,e,n)=>{const{expansion:r,verticalScale:o}=Wf(t,e),i=Number(t.x)+Number(t.w)*.5,a=Number(t.y)+Number(t.h)*.5,s=Of(t,e,.5,.5),u=r*n,c=o*n;return`matrix(${u} 0 0 ${c} ${s[0]-u*i} ${s[1]-c*a})`},tP=(t,e,n)=>{const r=n.left+(Number(e.x)+Number(e.w)*.5)*n.width,o=n.top+(Number(e.y)+Number(e.h)*.5)*n.height,i=_=>String(_||"").replace(/\s+/g," ").trim(),a=i(e.label);let s=null,u=null,c=1/0,g=!1;for(const _ of t.querySelectorAll("text")){const h=i(_.textContent);if(!h)continue;const p=_.getBoundingClientRect();if(p.width<=0||p.height<=0)continue;const m=a!==""&&h===a;if(m&&!g&&(c=1/0,s=null,u=null,g=!0),g&&!m)continue;const y=Math.abs(p.left+p.width*.5-r)+Math.abs(p.top+p.height*.5-o);y<c&&(c=y,s=_,u=p)}if(!s||!u)return null;const d=getComputedStyle(s),l=Number.parseFloat(d.fontSize)||Number.parseFloat(s.getAttribute("font-size"))||u.height*.8;return{dominantBaseline:s.getAttribute("dominant-baseline"),dy:s.getAttribute("dy"),fill:s.getAttribute("fill")||d.fill||"rgb(244,244,245)",fontFamily:s.getAttribute("font-family")||d.fontFamily||"sans-serif",doorHeight:Math.max(1e-6,Math.abs(Number(e.h))),fontSize:l/Math.max(1,n.height),fontStyle:s.getAttribute("font-style")||d.fontStyle||"normal",fontWeight:s.getAttribute("font-weight")||d.fontWeight||"400",opacity:s.getAttribute("fill-opacity")||d.fillOpacity||"1",text:a||s.textContent.trim()}},eP=(t,e,n,r,o)=>{const i=Math.max(0,e)*1.91986,a=Number(t.x),s=Number(t.y),u=Number(t.w),c=Number(t.h),g=n?0:1,d=.5,l=[a+g*u,s],_=[a+d*u,s],h=co(t,i,n,g,0),p=co(t,i,n,d,0),m=co(t,i,n,g,1);let y=(p[0]-h[0])/(_[0]-l[0]),x=(p[1]-h[1])/(_[0]-l[0]),N=(m[0]-h[0])/c,T=(m[1]-h[1])/c;const C=Math.hypot(y*r.width,x*r.height),L=(y<0?-1:1)*r.height/Math.max(1e-6,C);y*=L*o,x*=L*o,N*=o,T*=o;const S=.5,P=a+S*u,M=s+c*.5,W=co(t,i,n,S,.5),G=W[0]-y*P-N*M,I=W[1]-x*P-T*M;return`matrix(${y} ${x} ${N} ${T} ${G} ${I})`},nP=(t,e,n)=>{const r=Array.from(t.querySelectorAll("rect[fill][stroke]")).filter(c=>c.getAttribute("fill")!=="none"&&c.getAttribute("stroke")!=="none"),o={x:n.left+Number(e.x)*n.width,y:n.top+Number(e.y)*n.height,w:Number(e.w)*n.width,h:Number(e.h)*n.height},i=o.x+o.w*.5,a=o.y+o.h*.5;let s=null,u=1/0;for(const c of r){const g=c.getBoundingClientRect();if(g.width<=0||g.height<=0)continue;const d=Math.abs(g.left+g.width*.5-i)/Math.max(1,o.w)+Math.abs(g.top+g.height*.5-a)/Math.max(1,o.h),l=Math.abs(Math.log(g.width/Math.max(1,o.w)))+Math.abs(Math.log(g.height/Math.max(1,o.h))),_=d+l;_<u&&(u=_,s=c)}return s||(s=r[0]||null),{fill:s?.getAttribute("fill")||"rgb(24,24,27)",stroke:s?.getAttribute("stroke")||"rgb(244,244,245)"}},A0=(t,e,n,r)=>{const o=n?.armed>0&&Number(n.w)>0&&Number(n.h)>0,i=o&&n?.active>0,a=String(n?.key||"");let s=null,u=Ru.get(t);if(o&&u?.key!==a){Ru.delete(t),s=t.getBoundingClientRect();const O=tP(t,n,s);O?(u={key:a,label:O},Ru.set(t,u)):u=null}const c=i?S0(t,n,e,r):0,g=i&&(c>.08||Number(n?.faceAlpha)<.999);let d=Du.get(t);if(!g){d&&(d.overlay.style.display="none"),t.setAttribute("data-mg-svg-door-pass","idle"),t.removeAttribute("data-mg-door-motion");return}if(!d){if(d=K4(t),!d)return;Du.set(t,d)}s||(s=t.getBoundingClientRect());const l=C0(n.seed,n.key,Number(n.w)*s.width,Number(n.h)*s.height);t.setAttribute("data-mg-door-motion",l?"fall":"split");const{fill:_,stroke:h}=nP(t,n,s);for(const O of[d.left,d.right])O.setAttribute("fill",_),O.setAttribute("stroke","none"),O.setAttribute("fill-opacity","1");for(const O of[d.leftOuter,d.rightOuter])O.setAttribute("stroke",h),O.setAttribute("stroke-width","1.25"),O.setAttribute("stroke-opacity","1");const p=l?0:zf(.08,.26,c);for(const O of[d.leftSeam,d.rightSeam])O.setAttribute("stroke",h),O.setAttribute("stroke-width","1.25"),O.setAttribute("stroke-opacity",String(p));const m=s.width/Math.max(1e-6,s.height),y=l?j4(n,c,m):P0(n,c,!0,m),x=l?{fill:"",outer:"",seam:""}:P0(n,c,!1,m);d.left.setAttribute("d",y.fill),d.leftOuter.setAttribute("d",y.outer),d.leftSeam.setAttribute("d",y.seam),d.right.setAttribute("d",x.fill),d.rightOuter.setAttribute("d",x.outer),d.rightSeam.setAttribute("d",x.seam);const N=u?.key===a?u.label:null,T=Math.max(0,c)*1.91986,C=Wf(n,c),L=l?C.verticalScale>0:co(n,T,!0,.5,0)[0]>co(n,T,!0,0,0)[0],S=N?Math.abs(Number(n.h))/Math.max(1e-6,N.doorHeight):0,P=N?N.fontSize*s.height*S*(l?C.verticalScale:1):0,M=l?[Of(n,c,.5,.5)].some(([O,z])=>O>=0&&O<=1&&z>=0&&z<=1):[!0,!1].map(O=>co(n,T,O,.5,.5)).some(([O,z])=>O>=0&&O<=1&&z>=0&&z<=1),W=L&&P>=8&&M,G=[[d.leftLabel,!0],[d.rightLabel,!1]];for(const[O,z]of G){if(!N){O.setAttribute("display","none");continue}if(!W&&!z||l&&!z){O.setAttribute("display","none"),O.textContent="";continue}O.removeAttribute("display"),O.textContent=N.text,O.setAttribute("fill",N.fill),O.setAttribute("fill-opacity",N.opacity),O.setAttribute("font-family",N.fontFamily),O.setAttribute("font-size",String(N.fontSize)),O.setAttribute("font-style",N.fontStyle),O.setAttribute("font-weight",N.fontWeight),N.dominantBaseline==null?O.removeAttribute("dominant-baseline"):O.setAttribute("dominant-baseline",N.dominantBaseline),N.dy==null?O.removeAttribute("dy"):O.setAttribute("dy",N.dy);const $=Math.max(.04,Math.min(.96,Number(n.x)+Number(n.w)*.5)),q=Math.max(.04,Math.min(.96,Number(n.y)+Number(n.h)*.5));O.setAttribute("x",String(W?Number(n.x)+Number(n.w)*.5:$)),O.setAttribute("y",String(W?Number(n.y)+Number(n.h)*.5:q)),W?(O.setAttribute("clip-path",O.dataset.mgDoorLabelClip),O.setAttribute("transform",l?Z4(n,c,S):eP(n,c,z,s,S))):(O.removeAttribute("clip-path"),O.removeAttribute("transform"))}const{overlay:I}=d,j=d.parent.getBoundingClientRect();I.style.left=`${s.left-j.left-d.parent.clientLeft}px`,I.style.top=`${s.top-j.top-d.parent.clientTop}px`,I.style.width=`${s.width}px`,I.style.height=`${s.height}px`,I.style.display="block",t.setAttribute("data-mg-svg-door-pass","active")},rP=t=>{const e=Du.get(t);e&&(e.overlay.remove(),e.changedPosition&&e.parent.style.position==="relative"&&(e.parent.style.position=e.restorePosition)),Du.delete(t),Gu.delete(t),Ru.delete(t),t.removeAttribute("data-mg-svg-door-pass"),t.removeAttribute("data-mg-door-motion")},oP=(t,e,n)=>{const{gl:r}=t,o=Ia.get(e),i=o?.key===String(n.key)?o:null,a=i?.canvas||e,s=r.createTexture();return s?(r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,s),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR_MIPMAP_LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,a),r.generateMipmap(r.TEXTURE_2D),{capture:i?.capture||[n.x,n.y,n.w,n.h],faceSize:i?.faceSize||[n.w*a.width,n.h*a.height],radius:i?.radius||n.r*a.width,version:i?.version||0,texture:s}):null},G0=(t,e,n,r,o)=>{const i=r?.active>0&&Number(r.w)>0&&Number(r.h)>0,a=i?S0(t,r,n,o):0,s=i&&(a>.08||Number(r?.faceAlpha)<.999),u=i&&(s||Number(e)>=.008);let c=Uo.get(t);if(r?.prewarm>0&&!c&&W4(t),!u){r?.armed>0?Iu.has(t)||(q4(t,r),Iu.add(t)):Iu.delete(t),O4(t,c);return}if(Ga.has(t)){t.setAttribute("data-mg-gpu-pass","unavailable");return}if(!c){b0(t);try{c=J0(t)}catch{c=null}if(!c){Ga.add(t),t.setAttribute("data-mg-gpu-pass","unavailable");return}Uo.set(t,c)}const{gl:g,overlay:d,program:l,texture:_}=c,h=Math.max(1,t.width),p=Math.max(1,t.height),m=h,y=p;d.width!==m&&(d.width=m),d.height!==y&&(d.height=y);const x=t.offsetLeft,N=t.offsetTop,T=t.clientWidth,C=t.clientHeight;c.overlayLeft!==x&&(d.style.left=`${x}px`,c.overlayLeft=x),c.overlayTop!==N&&(d.style.top=`${N}px`,c.overlayTop=N),c.overlayWidth!==T&&(d.style.width=`${T}px`,c.overlayWidth=T),c.overlayHeight!==C&&(d.style.height=`${C}px`,c.overlayHeight=C),d.style.display!=="block"&&(d.style.display="block"),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,_),c.sceneTextureWidth!==h||c.sceneTextureHeight!==p?(g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,t),c.sceneTextureWidth=h,c.sceneTextureHeight=p):g.texSubImage2D(g.TEXTURE_2D,0,0,0,g.RGBA,g.UNSIGNED_BYTE,t),g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,m,y),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,_),g.useProgram(l),g.uniform1f(c.zoomFilmAmountLocation,Math.sqrt(Math.max(0,Math.min(1,Number(e)||0)))),g.uniform1f(c.zoomTimeLocation,performance.now()/1e3),g.uniform1f(c.zoomStrengthLocation,Math.max(0,Math.min(1,Number(e)||0))),g.drawArrays(g.TRIANGLES,0,3);const L=i?Ia.get(t):null,S=L?.key===String(r.key)?L.version:null;let P=i?c.doorTextures.get(String(r.key)):null;i&&(!P||S!==null&&P.version!==S)&&(P&&g.deleteTexture(P.texture),P=oP(c,t,r),P&&c.doorTextures.set(String(r.key),P));const M=zf(.08,.18,a),W=Number(r.faceAlpha)<.999;if(i&&P&&(M>.001||W)){g.enable(g.BLEND),g.blendFunc(g.SRC_ALPHA,g.ONE_MINUS_SRC_ALPHA),g.enable(g.CULL_FACE),g.frontFace(g.CW),g.activeTexture(g.TEXTURE1),g.bindTexture(g.TEXTURE_2D,P.texture),g.useProgram(c.doorProgram),g.uniform4fv(c.doorCaptureLocation,P.capture),g.uniform2fv(c.doorFaceSizeLocation,P.faceSize),g.uniform1f(c.doorRadiusLocation,H4(P.radius,P.faceSize[0],P.faceSize[1]));const G=Number(r.x),I=Number(r.y),j=Number(r.w),O=Number(r.h);g.uniform4f(c.doorDestLocation,G,I,j,O),g.uniform1f(c.doorAttentionLocation,0),g.uniform1f(c.doorOpenLocation,a);const z=C0(r.seed,r.key,P.faceSize[0],P.faceSize[1]);t.setAttribute("data-mg-door-motion",z?"fall":"split"),g.uniform1f(c.doorFallLocation,z?1:0),z?(g.uniform1f(c.doorPanelLocation,0),g.drawArrays(g.TRIANGLES,0,30)):(g.uniform1f(c.doorPanelLocation,-1),g.drawArrays(g.TRIANGLES,0,30),g.uniform1f(c.doorPanelLocation,1),g.drawArrays(g.TRIANGLES,0,30)),g.disable(g.BLEND),g.disable(g.CULL_FACE)}t.getAttribute("data-mg-gpu-pass")!=="active"&&t.setAttribute("data-mg-gpu-pass","active"),t.style.visibility!=="hidden"&&(t.style.visibility="hidden")},iP=t=>{b0(t);const e=Uo.get(t);if(e){e.gl.deleteTexture(e.texture);for(const n of e.doorTextures.values())e.gl.deleteTexture(n.texture);e.gl.deleteProgram(e.doorProgram),e.gl.deleteProgram(e.program),e.overlay.remove(),t.style.visibility=e.restoreVisibility,e.changedPosition&&e.parent.style.position==="relative"&&(e.parent.style.position=e.restorePosition)}Uo.delete(t),Ga.delete(t),Ia.delete(t),Iu.delete(t),t.removeAttribute("data-mg-gpu-pass"),t.removeAttribute("data-mg-door-motion"),Gu.delete(t)},I0=(t,e)=>({tag:t,_1:e}),D0=t=>t,aP=(t,e,n)=>({tag:t,_1:e,_2:n}),or=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;f()},sP=y0(Fg),uP=Mt.foldMap(o2),cP=Fa(Zo),Da=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=w;continue}if(i.tag==="Node"){const a=A.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=v("Just",i._4);continue}}f()}return o},R0=tm(Kf),Xo=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;f()},qf=aP("AutoSize"),gP=D0("CanvasRenderer"),fP=D0("SvgRenderer"),_P=t=>e=>{const n=t-e*et(he(Fn(t/e)));return e<=0?0:n<0?n+e:n},Ri=t=>J(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),dP=t=>{const e=x0("data-markgraf-titles")(t);return()=>{const n=e();return n.tag==="Nothing"||!(n.tag==="Just"&&n._1==="false")}},lP=t=>{const e=x0("data-markgraf-theme")(t);return()=>{const n=e();if(n.tag==="Just")return n._1==="light"?mf:n._1==="dark"?t5:n._1==="blueprint"?e5:n._1==="whiteboard"?n5:n._1==="isometric"?r5:mf;if(n.tag==="Nothing")return mf;f()}},hP=`
|
|
30
259
|
<canvas data-mg="stage" tabindex="0"></canvas>
|
|
31
260
|
<div data-mg="play-overlay" aria-hidden="true"></div>
|
|
32
261
|
<div data-mg="bar">
|
|
@@ -43,6 +272,6 @@ var B4=(function(uu){"use strict";function Hp(t){let e=0,n;return()=>{if(e===2)r
|
|
|
43
272
|
<option value="2">2\xD7</option>
|
|
44
273
|
</select>
|
|
45
274
|
</div>
|
|
46
|
-
`,
|
|
275
|
+
`,B0=t=>e=>{const n=xn(t,w,Vt);if(n.tag==="Just"){const r=xn(n._1.stopAt,w,Vt);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;f()}if(n.tag==="Nothing")return e;f()},pP=t=>e=>le(n=>n.direction==="DiveIn"&&n.startT>=e&&n.startT-e<=1,t.dives),F0=t=>e=>({...e,state:{...e.state,camera:t},minis:U(n=>F0(t)(n))(e.minis)}),mP=t=>e=>n=>{const r=Mn(n.rootLayout)(n.camera),o=cn("data-mg-too-small")("0")(t);return()=>(o(),cn("data-mg-camera-vw")(go(r.w))(t)(),cn("data-mg-camera-vh")(go(r.h))(t)(),cn("data-mg-camera-zoom")(go(n.camera.zoom))(t)(),cn("data-mg-viewport-css-width")(go(e.w))(t)(),cn("data-mg-viewport-css-height")(go(e.h))(t)())},yP=t=>{const e=KE(t);if(e.tag==="Left")return Ot("Left",e._1);if(e.tag==="Right")return Ot("Right",t4(e._1));f()},xP=t=>e=>n=>{if(e.tag==="FixedSize")return()=>({w:e._1,h:e._2});if(e.tag==="AutoSize"){const r=Eu(t);return()=>{const o=r(),i=o.width<=0?n.width:o.width;return{w:i,h:o.height<=0?i*n.height/or(1)(n.width):o.height}}}f()},wP=t=>e=>n=>{const r=Hk(jk(k4(n))),o=cn("viewBox")(r.viewBox)(t);return()=>(o(),cn("preserveAspectRatio")("xMidYMid meet")(t)(),e.tag==="FixedSize"?(cn("width")(ue(he($n(e._1))))(t)(),cn("height")(ue(he($n(e._2))))(t)()):e.tag==="AutoSize"||f(),Aa(r.body,t))},NP=t=>e=>n=>{const r=Su(t),o=xP(t)(e)(n);return()=>{const i=o(),a=N0(),s=i.w*a,u=i.h*a,c=m_(r)(),g=y_(r)(),d=x_(r)(s);c!==s&&d();const l=w_(r)(u);g!==u&&l(),e.tag==="FixedSize"?(Pu(t,"width",ue(he($n(i.w)))+"px"),Pu(t,"height",ue(he($n(i.h)))+"px")):e.tag==="AutoSize"||f();const _=p_(r)();ur(_)(),qa(_)({scaleX:a,scaleY:a})();const h=Ol(_)({width:i.w,height:i.h})();return sP(n)(h)(),cr(_)()}},vP=t=>e=>n=>r=>{if(e==="CanvasRenderer")return NP(t)(n)(r);if(e==="SvgRenderer")return wP(t)(n)(r);f()},TP=t=>e=>n=>r=>()=>{let o=!1,i=()=>{},a=[];const s=()=>{const c=o,g=vP(t)(e)(n)(r);if(!c)return g()},u={time:0,keyframe:"sequence",playing:!1};return s(),i=w0(t)(()=>{s();const c=a;return Ri(g=>g(u))(c)()})(),{play:()=>{},playWith:c=>()=>{},pause:()=>{},toggle:()=>{},seek:c=>()=>{},seekCue:c=>()=>{},seekStep:c=>()=>{},playToCue:c=>g=>()=>{},playToStep:c=>g=>()=>{},playNext:c=>()=>{},playPrevious:c=>()=>{},setSpeed:c=>()=>{},currentTime:(()=>{const c=u.time;return()=>c})(),currentKeyframe:(()=>{const c=u.keyframe;return()=>c})(),isPlaying:()=>!1,duration:0,cues:[],steps:[],subscribe:c=>()=>{a=Ct(a)(c),c(u)();const g=Fi(d=>!Au(d)(c));return()=>{a=g(a)}},subscribeCue:c=>()=>()=>{},subscribeComplete:c=>()=>()=>{},destroy:()=>(o=!0,i())}},br=t=>e=>n=>()=>{const r=R4(t,e),o=xn(r,w,Vt);if(o.tag==="Just")return n(o._1)();o.tag!=="Nothing"&&f()},JP=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=uP(o=>'<span class="mg-tick" style="left:'+po(lo("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;f()})()+'"></span>')(e.spans);return br(t)("ticks")(o=>()=>Aa(r,o))},bP=t=>e=>n=>br(t)("scrub")(r=>{const o=Bf(w,Vt,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return n<=0?()=>{}:A4(ue(he($n(e/n*1e3))))(o._1);f()}),CP=t=>e=>{const n=jt(r=>r.direction==="DiveIn"&&r.startT>=e&&r.startT-e<=.12)(t.dives);if(n.tag==="Just"){const r=n._1,o=jt(i=>cP(i.path)(r.parentPath)&&i.startT<=e&&r.startT<=i.endT+1e-4)(t.segments);if(o.tag==="Just"){const i=Da(r.node)(o._1.layout.nodes);if(i.tag==="Just")return v("Just",{box:{x:i._1.x*o._1.placement.scale+o._1.placement.tx,y:i._1.y*o._1.placement.scale+o._1.placement.ty,w:i._1.w*o._1.placement.scale,h:i._1.h*o._1.placement.scale},faceAlpha:1,label:i._1.label,radius:7*o._1.placement.scale,key:R0(r.childPath)});if(i.tag==="Nothing")return w;f()}if(o.tag==="Nothing")return w;f()}if(n.tag==="Nothing")return w;f()},Hf=t=>e=>n=>{const r=E4(o=>n);return()=>{const o=r();return P4(t)(o)(!1)(e)()}},M0=()=>c2()/1e3,kP=t=>e=>()=>(Aa(`
|
|
47
276
|
<svg data-mg="stage" tabindex="0" role="img" aria-label="Markgraf sequence diagram"></svg>
|
|
48
|
-
`,t),xr(t)("stage")(n=>{const r=jE(n)(ME)(e_)(e);return()=>{const o=Zg();t_(()=>{r()})(o)()}})()),n4=t=>e=>{const n=mn(t,J,Kt);if(n.tag==="Just"){const r=mn(n._1.loop,J,Kt);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()},r4=t=>e=>xr(t)("speed")(n=>{const r=jg(J,Kt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return n_("change")(n)((()=>{const o=DE(r._1);return()=>{const i=o(),s=F0(i,m_,Kt,J);if(s.tag==="Just")return e(s._1)();s.tag!=="Nothing"&&g()}})());g()}),o4=t=>e=>n=>xr(t)("scrub")(r=>{const o=jg(J,Kt,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return n_("input")(r)((()=>{const i=BE(o._1);return()=>{const s=i();return n.pause(),n.seek(s/1e3*e.totalDuration)()}})());g()}),i4=t=>e=>n=>{const r=ZE(t)(e);return()=>{r(),xr(t)("play")(o=>gn("data-mg-playing")("1")(o))(),r4(t)(n.setSpeed)(),xr(t)("play")(o=>n_("click")(o)(n.toggle))(),o4(t)(e)(n)(),n.subscribe(o=>{const i=t4(t)(o.time)(e.totalDuration);return()=>(i(),xr(t)("time")(s=>LE(Ho(Oo("Fixed",qo(0)(20)(2)))(o.time)+" / "+Ho(Oo("Fixed",qo(0)(20)(2)))(e.totalDuration))(s))(),xr(t)("play")(s=>gn("data-mg-playing")(o.playing?"1":"0")(s))())})()}},s4=t=>e=>n=>{const r=Z1(n);return()=>{const o=r(),i=td(n)(),s=c5(Q2)(Vk)(n)(ed(o)(i)(n));if(s.tag==="Left")return Wt("Left","precompute failed");if(s.tag==="Right")return Wt("Right",{schedule:s._1});g()}},a4=t=>e=>(()=>{const n=mn(t,J,Kt);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()})(),Ap=t=>e=>{const n=mn(t,J,Kt);if(n.tag==="Just"){const r=mn(n._1.direction,J,Kt);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()},u4=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},c4=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=ja(t);return()=>{const r=n();return r.width<=0||r.height<=0?J:N("Just",r.width/r.height)}}g()},nu=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>_=>()=>{const d=Rp(),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=ja(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 RE(t)(h.w)(h.h)(200)(180)();const p=vk({widthPx:h.w,heightPx:h.h})(s),m=Zy(p)(eu(_)(p.totalDuration)),w=i?m:{...m,levels:q(C=>({...C,state:{...C.state,frameTitle:""}}))(m.levels)},x=u.value,y=(()=>{if(x.tag==="Nothing")return w.camera;if(x.tag==="Just")return B2(s.cameraConfig.cameraDecay)(f)(x._1)(w.camera);g()})();u.value=N("Just",y);const T={...w,camera:y,levels:q(Dp(y))(w.levels)};if($E(t)(h)(T)(),e==="CanvasRenderer"){const C=Sp(t),S=yi({padding:8,outputAspect:J})(T),E=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const D=ja(t)();return{w:D.width,h:D.height<=0?S.vw<=0?D.width:D.width*S.vh/S.vw:D.height}}g()})(),B=Ep(),M=E.w*B,Y=E.h*B,R=C_(C)(),A=b_(C)(),j=k_(C)(M);R!==M&&j();const Z=S_(C)(Y);A!==Y&&Z(),n.tag==="FixedSize"?(Za(t,"width",ie(fe(Hn(E.w)))+"px"),Za(t,"height",ie(fe(Hn(E.h)))+"px")):n.tag==="AutoSize"||g();const z=T_(C)();nr(z)(),vs(z)({scaleX:B,scaleY:B})();const W=a.value,H=WC(r)(o)(z)({width:E.w,height:E.h})(T)(f)(W)();return a.value=H,rr(z)()}if(e==="SvgRenderer"){const C=a.value,S=c4(t)(n)(),E=vb(S)(r)(o)(T)(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(Hn(n._1))))(t)(),gn("height")(ie(fe(Hn(n._2))))(t)()):n.tag==="AutoSize"||g(),hs(E.parts.body,t)}g()},g4=t=>{const e=Vh(t)(Qh)._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=DL(t);if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right"){if(e._1.mode==="SequenceSurface"){const r=VE(e._1);if(r.tag==="Left")return Wt("Left",r._1);if(r.tag==="Right")return Wt("Right",Gp("LoadedSequence",r._1));g()}const n=g4(e._1);if(n.tag==="Left")return Wt("Left",n._1);if(n.tag==="Right")return Wt("Right",Gp("LoadedAnimation",n._1))}g()},_4=t=>{const e=Ip(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return ki;g()},Fp=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},f4=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),d4=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]):J},o_=t=>e=>n=>{const r=mn(e,J,Kt);if(r.tag==="Just"){const o=mn(r._1.speed,J,Kt);if(o.tag==="Just"){const i=Do(1e-4)(o._1<0?-o._1:o._1);return()=>t.value=i}if(o.tag==="Nothing"){const i=mn(r._1.duration,J,Kt);if(i.tag==="Just"&&n.tag==="Just"){const s=n._1/i._1,a=Do(1e-4)(s<0?-s:s);if(i._1>0)return()=>t.value=a}return()=>{}}g()}if(r.tag==="Nothing")return()=>{};g()},l4=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,Kt);if(c.tag==="Just"){const _=mn(c._1.direction,J,Kt);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()},h4=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},x={value:0};let y=!1,T=()=>{},C=[],S=[],E=[];nu(t)(n)(r)(o)(i)(s)(e)(m)(w)(x)(0)();const B=L=>{const G=L.index;return()=>{d=G;const Q=S;return vi(V=>V(L))(Q)()}},M=L=>()=>{const G=C,Q=l,V={time:L,keyframe:r_(e)(L),playing:Q};return vi(K=>K(V))(G)()},Y=()=>(l=!1,_=J,M(h)()),R=L=>()=>(h=L,nu(t)(n)(r)(o)(i)(s)(e)(m)(w)(x)(L)(),M(L)()),A=L=>{const G=Do(0)(eu(e.totalDuration)(L));return()=>(h=G,d=u4(e.cues)(G),p=0,_=J,w.value=J,nu(t)(n)(r)(o)(i)(s)(e)(m)(w)(x)(G)(),M(G)())},j=(L,G,Q,V,K)=>()=>{l=!1,_=J;const U=h;M(U)();const O={reason:L,direction:G<0?"backward":"forward",targetId:Q,targetStep:V,reached:K,time:U},X=E;return vi(et=>et(O))(X)()},Z=()=>{if(!y&&(f=!1,l)){const L=Rp(),G=p;p=L;const Q=a.value,V=u,K=c,U=_,O=h,X=G===0?O+0*Q*V:O+(L-G)*Q*V;if(U.tag==="Just"){const et=V>=0?U._1.cue.time>=O-1e-4&&U._1.cue.time<=X+1e-4:U._1.cue.time<=O+1e-4&&U._1.cue.time>=X-1e-4,lt=et?U._1.cue.time:Do(0)(eu(e.totalDuration)(X));(V>=0?lt+1e-4<O:lt>O+1e-4)&&(w.value=J),R(lt)(),vi(pt=>B(pt))(Fp(e.cues)(O)(lt)(V))();const bt=j("target",V,U._1.targetId,U._1.targetStep,!0);return et&&bt(),et?void 0:z()}if(U.tag==="Nothing"){const et=V>=0?e.totalDuration:0,lt=!K&&(V>=0?et>=O-1e-4&&et<=X+1e-4:et<=O+1e-4&&et>=X-1e-4),bt=K?WE(X)(e.totalDuration+.8):Do(0)(eu(e.totalDuration)(X));(V>=0?bt+1e-4<O:bt>O+1e-4)&&(w.value=J),R(bt)(),vi(Tt=>B(Tt))(Fp(e.cues)(O)(bt)(V))();const pt=j("boundary",V,"","",!0);return lt&&pt(),lt?void 0:z()}g()}},z=()=>{if(!y&&!f){f=!0;const L=Zg();t_(Z)(L)()}},W=()=>(p=0,l=!0,z()),H=()=>(u=1,c=!0,_=J,W(),M(h)()),D=(L,G)=>()=>{const Q=h;return u=L,c=!1,_=J,o_(a)(G)(N("Just",L>=0?e.totalDuration-Q:Q))(),W()},F=(L,G)=>()=>{const Q=h,V=d,K=l4(G)(Q)(V)(L);if(K.tag==="Nothing")return D(Ap(G)(1),G)();if(K.tag==="Just"){const U=L.time-Q,O=U<0?-U:U;return u=K._1,c=!1,_=N("Just",{cue:L,direction:K._1,targetId:L.id,targetStep:L.name}),o_(a)(G)(N("Just",O))(),O<=1e-4?(A(L.time)(),B(L)(),j("target",K._1,L.id,L.name,!0)()):W()}g()};return T=Lp(t)(()=>{if(!y){const L=h;return nu(t)(n)(r)(o)(i)(s)(e)(m)(w)(x)(L)(),M(L)()}})(),W(),{play:H,playWith:L=>{const G=Ap(L)(1);return()=>(u=G,c=n4(L)(!1),_=J,o_(a)(L)(J)(),W(),M(h)())},pause:Y,toggle:()=>l?Y():H(),seek:L=>A(L),seekCue:L=>{const G=re(Q=>Q.id===L)(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:L=>{const G=re(Q=>Q.kind==="step"&&Q.name===L)(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:L=>G=>{const Q=re(V=>V.id===L)(e.cues);if(Q.tag==="Nothing")return()=>{};if(Q.tag==="Just")return F(Q._1,G);g()},playToStep:L=>G=>{const Q=re(V=>V.kind==="step"&&V.name===L)(e.cues);if(Q.tag==="Nothing")return()=>{};if(Q.tag==="Just")return F(Q._1,G);g()},playNext:L=>()=>{const G=h,Q=d,V=f4(e.cues)(Bp(L)(["step"]))(G)(Q);if(V.tag==="Nothing")return D(1,L)();if(V.tag==="Just")return F(V._1,L)();g()},playPrevious:L=>()=>{const G=h,Q=d,V=d4(e.cues)(Bp(L)(["step"]))(G)(Q);if(V.tag==="Nothing")return D(-1,L)();if(V.tag==="Just")return F(V._1,a4(L)(-1))();g()},setSpeed:L=>{const G=Do(1e-4)(L<0?-L:L);return()=>a.value=G},currentTime:()=>h,currentKeyframe:()=>{const L=h;return r_(e)(L)},isPlaying:()=>l,duration:e.totalDuration,cues:e.cues,steps:ft(L=>L.kind==="step",e.cues),subscribe:L=>()=>{C=St(C)(L);const G=h,Q=l;L({time:G,keyframe:r_(e)(G),playing:Q})();const V=bi(K=>!tu(K)(L));return()=>{C=V(C)}},subscribeCue:L=>()=>{S=St(S)(L);const G=bi(Q=>!tu(Q)(L));return()=>{S=G(S)}},subscribeComplete:L=>()=>{E=St(E)(L);const G=bi(Q=>!tu(Q)(L));return()=>{E=G(E)}},destroy:()=>(y=!0,T())}},p4=t=>e=>{const n=OE(t);return()=>{const r=n(),o=qE(t)();return hs(HE,t),xr(t)("stage")(i=>{const s=s4()(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=h4(i)(u._1.schedule)(zE)(e_)(o)(gb)(r)();return i4(t)(u._1.schedule)(c)()}g()})(a)()}})()}},Qp=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 p4(t)(n._1._1);if(n._1.tag==="LoadedSequence")return e4(t)(n._1._1)}g()},m4=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 wr=null;const ru=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",y4=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{ru(t)?(wr&&wr!==t&&ru(wr)&&wr.querySelector('[data-mg="play"]').click(),wr=t):wr===t&&(wr=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},x4=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=m4(t),n=t.dataset.markgrafPaused==="true";t.textContent="",Qp(t)(e)(),t.querySelector('[data-mg="play"]')&&(n?ru(t)&&t.querySelector('[data-mg="play"]').click():wr===null?wr=t:ru(t)&&t.querySelector('[data-mg="play"]').click(),y4(t))},ou=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(x4)},zp=()=>{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||wr||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=_4(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>Qp(e)(n)(),mountAll:ou,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{ou(),zp()}):(ou(),zp())}return uu.mountAll=ou,Object.defineProperty(uu,Symbol.toStringTag,{value:"Module"}),uu})({});
|
|
277
|
+
`,t),br(t)("stage")(n=>{const r=TP(n)(fP)(qf)(e);return()=>{const o=Ff();Mf(()=>{r()})(o)()}})()),LP=t=>e=>{const n=xn(t,w,Vt);if(n.tag==="Just"){const r=xn(n._1.loop,w,Vt);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;f()}if(n.tag==="Nothing")return e;f()},$f=t=>e=>{const n=jt(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;f()}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;f()}return""}f()},SP=t=>e=>br(t)("speed")(n=>{const r=Bf(w,Vt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return Hf("change")(n)((()=>{const o=I4(r._1);return()=>{const i=o(),a=Om(i,c_,Vt,w);if(a.tag==="Just")return e(a._1)();a.tag!=="Nothing"&&f()}})());f()}),EP=t=>e=>n=>br(t)("scrub")(r=>{const o=Bf(w,Vt,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return Hf("input")(r)((()=>{const i=G4(o._1);return()=>{const a=i();return n.pause(),n.seek(a/1e3*e.totalDuration)()}})());f()}),PP=t=>e=>n=>{const r=JP(t)(e);return()=>{r(),br(t)("play")(o=>cn("data-mg-playing")("1")(o))(),SP(t)(n.setSpeed)(),br(t)("play")(o=>Hf("click")(o)(n.toggle))(),EP(t)(e)(n)(),n.subscribe(o=>{const i=bP(t)(o.time)(e.totalDuration);return()=>(i(),br(t)("time")(a=>S4(po(lo("Fixed",ho(0)(20)(2)))(o.time)+" / "+po(lo("Fixed",ho(0)(20)(2)))(e.totalDuration))(a))(),br(t)("play")(a=>cn("data-mg-playing")(o.playing?"1":"0")(a))())})()}},Uf={active:0,armed:0,depth:0,faceAlpha:1,progress:0,h:0,key:"",label:"",prewarm:0,r:0,seed:0,w:0,x:0,y:0},AP=t=>e=>n=>{const r=ll(n);return()=>{const o=r(),i=hl(n)(),a=cL(zy)(U5)(n)(pl(o)(i)(n));if(a.tag==="Left")return Ot("Left","precompute failed");if(a.tag==="Right")return Ot("Right",{schedule:a._1});f()}},GP=t=>{let e=t,n=!0,r;for(;n;){const o=Rt(i=>w,i=>a=>v("Just",{head:i,tail:a}),e);if(o.tag==="Nothing"){n=!1,r=w;continue}if(o.tag==="Just"){const i=0<o._1.tail.length?v("Just",o._1.tail[0]):w;if(i.tag==="Just"&&o._1.head.role==="FlyThrough"){const a=i._1.segment.path.length-1|0,s=a>=0&&a<i._1.segment.path.length?v("Just",i._1.segment.path[a]):w;if(s.tag==="Just"){const u=Da(s._1)(o._1.head.segment.layout.nodes);if(u.tag==="Just"){n=!1,r=v("Just",{box:(()=>{const c=o._1.head.segment.placement;return{x:u._1.x*c.scale+c.tx,y:u._1.y*c.scale+c.ty,w:u._1.w*c.scale,h:u._1.h*c.scale}})(),faceAlpha:Xo((()=>{const c=Da(s._1)(o._1.head.state.nodes);return c.tag==="Just"?ro(c._1).alpha:0})())(Xo((()=>{const c=Da(s._1)(o._1.head.state.nodeFadeAlpha);if(c.tag==="Nothing")return 1;if(c.tag==="Just")return c._1;f()})())((()=>{const c=Da(s._1)(o._1.head.state.nodeLabelFadeAlpha);if(c.tag==="Nothing")return 1;if(c.tag==="Just")return c._1;f()})())),label:u._1.label,key:R0(i._1.segment.path),radius:7*o._1.head.segment.placement.scale});continue}if(u.tag==="Nothing"){n=!1,r=w;continue}f()}if(s.tag==="Nothing"){n=!1,r=w;continue}f()}e=o._1.tail;continue}f()}return r},z0=t=>e=>n=>r=>o=>i=>{const a=or(1)(n),s=or(1)(r),u=Xo(a/or(1e-6)(o.vw))(s/or(1e-6)(o.vh)),c=(s-o.vh*u)/2,g=(a-o.vw*u)/2,d=(_,h,p,m)=>({active:_,armed:1,depth:h,faceAlpha:m.faceAlpha,progress:p,h:m.box.h*u/s,key:m.key,label:m.label,prewarm:1,r:m.radius*u/a,seed:et(t.seed),w:m.box.w*u/a,x:(g+(m.box.x-o.vx)*u)/a,y:(c+(m.box.y-o.vy)*u)/s}),l=GP(i.levels);if(l.tag==="Just")return d(1,i.diveDepth,i.doorProgress,l._1);if(l.tag==="Nothing"){const _=CP(t)(e);if(_.tag==="Just")return d(0,0,0,_._1);if(_.tag==="Nothing")return{...Uf,prewarm:pP(t)(e)?1:0}}f()},IP=t=>e=>(()=>{const n=xn(t,w,Vt);if(n.tag==="Just")return{...n._1,direction:e<0?"backward":"forward"};if(n.tag==="Nothing")return{direction:e<0?"backward":"forward",speed:Mi,duration:Mi,loop:Mi,stopAt:Mi};f()})(),Q0=t=>e=>{const n=xn(t,w,Vt);if(n.tag==="Just"){const r=xn(n._1.direction,w,Vt);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;f()},DP=t=>e=>{const n=dt(o=>o.time<=e+1e-4,t),r=n.length-1|0;return r>=0&&r<n.length?n[r].index:-1},RP=t=>e=>{if(e.tag==="FixedSize"){const n=e._1<=0||e._2<=0?w:v("Just",e._1/e._2);return()=>n}if(e.tag==="AutoSize"){const n=Eu(t);return()=>{const r=n();return r.width<=0||r.height<=0?w:v("Just",r.width/r.height)}}f()},Fu=t=>e=>n=>r=>o=>i=>a=>s=>u=>c=>g=>d=>()=>{const l=M0(),_=g.value;g.value=l;const h=_===0?0:l-_,p=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const P=Eu(t)();return{w:P.width<=0?200:P.width,h:P.height<=0?180:P.height}}f()})();if(p.w<200||p.h<180){if(D4(t)(p.w)(p.h)(200)(180)(),e==="CanvasRenderer")return G0(Su(t),0,0,Uf,h);if(e==="SvgRenderer")return A0(t,0,Uf,h);f()}const m=s.value,y=(()=>{if(m.tag==="Just"&&m._1.w===p.w&&m._1.h===p.h)return m._1.schedule;const P=T5({widthPx:p.w,heightPx:p.h})(a);return s.value=v("Just",{w:p.w,h:p.h,schedule:P}),P})(),x=Xo(d)(y.totalDuration),N=Hw(y)(x),T=i?N:{...N,levels:U(P=>({...P,state:{...P.state,frameTitle:""}}))(N.levels)},C=c.value,L=(()=>{if(C.tag==="Nothing")return T.camera;if(C.tag==="Just")return Fy(a.cameraConfig.cameraDecay)(h)(C._1)(T.camera);f()})();c.value=v("Just",L);const S={...T,camera:L,levels:U(F0(L))(T.levels)};if(mP(t)(p)(S)(),e==="CanvasRenderer"){const P=Su(t),M=au({width:0,height:0})(S),W=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const E=Eu(t)();return{w:E.width,h:E.height<=0?M.vw<=0?E.width:E.width*M.vh/M.vw:E.height}}f()})(),G=N0(),I=W.w*G,j=W.h*G,O=m_(P)(),z=y_(P)(),$=x_(P)(I);O!==I&&$();const q=w_(P)(j);z!==j&&q(),n.tag==="FixedSize"?(Pu(t,"width",ue(he($n(W.w)))+"px"),Pu(t,"height",ue(he($n(W.h)))+"px")):n.tag==="AutoSize"||f();const D=p_(P)();ur(D)(),qa(D)({scaleX:G,scaleY:G})();const B=u.value,R=Rk(r)(o)(D)({width:W.w,height:W.h})(S)(h)(B)();return u.value=R,cr(D)(),G0(P,S.zoomStreak,S.zoomDirection,z0(y)(x)(W.w)(W.h)(au({width:W.w,height:W.h})(S))(S),h)}if(e==="SvgRenderer"){const P=u.value,M=RP(t)(n)(),W=m5(M)(r)(o)(S)(h)(P);return u.value=W.springs,cn("viewBox")(W.parts.viewBox)(t)(),cn("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(cn("width")(ue(he($n(n._1))))(t)(),cn("height")(ue(he($n(n._2))))(t)()):n.tag==="AutoSize"||f(),Aa(W.parts.body,t),A0(t,S.zoomDirection,z0(y)(x)(p.w)(p.h)(au({width:p.w,height:p.h})(S))(S),h)}f()},BP=t=>{const e=Mp(t)(Pp)._1;if(e.tag==="Left")return Ot("Left",e._1.msg);if(e.tag==="Right")return Ot("Right",e._1);f()},W0=t=>{const e=IE(t);if(e.tag==="Left")return Ot("Left",e._1);if(e.tag==="Right"){if(e._1.mode==="SequenceSurface"){const r=yP(e._1);if(r.tag==="Left")return Ot("Left",r._1);if(r.tag==="Right")return Ot("Right",I0("LoadedSequence",r._1));f()}const n=BP(e._1);if(n.tag==="Left")return Ot("Left",n._1);if(n.tag==="Right")return Ot("Right",I0("LoadedAnimation",n._1))}f()},FP=t=>{const e=W0(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return Mi;f()},O0=t=>e=>n=>r=>{const o=n+1e-4>=e?dt(a=>a.time>e+1e-4&&a.time<=n+1e-4,t):[...dt(a=>a.time>e+1e-4,t),...dt(a=>a.time<=n+1e-4,t)],i=n<=e+1e-4?ce(dt(a=>a.time<e-1e-4&&a.time>=n-1e-4,t)):[...ce(dt(a=>a.time<e-1e-4,t)),...ce(dt(a=>a.time>=n-1e-4,t))];return(()=>{const a=n-e;return a<0?-a<=1e-4:a<=1e-4})()?[]:r>=0?o:i},MP=t=>e=>n=>r=>jt(o=>le(i=>i===o.kind,e)&&(o.time>n+1e-4||(()=>{const i=o.time-n;return(i<0?-i<=1e-4:i<=1e-4)&&o.index>r})()))(t),zP=t=>e=>n=>r=>{const o=dt(a=>le(s=>s===a.kind,e)&&(a.time<n-1e-4||(()=>{const s=a.time-n;return(s<0?-s<=1e-4:s<=1e-4)&&a.index<r})()),t),i=o.length-1|0;return i>=0&&i<o.length?v("Just",o[i]):w},Vf=t=>e=>n=>{const r=xn(e,w,Vt);if(r.tag==="Just"){const o=xn(r._1.speed,w,Vt);if(o.tag==="Just"){const i=or(1e-4)(o._1<0?-o._1:o._1);return()=>t.value=i}if(o.tag==="Nothing"){const i=xn(r._1.duration,w,Vt);if(i.tag==="Just"&&n.tag==="Just"){const a=n._1/i._1,s=or(1e-4)(a<0?-a:a);if(i._1>0)return()=>t.value=s}return()=>{}}f()}if(r.tag==="Nothing")return()=>{};f()},QP=t=>e=>n=>r=>{const o=r.time-e,i=o<0?-o<=1e-4:o<=1e-4,a=r.time<e-1e-4||i&&r.index<n,s=a?-1:1,u=r.time>e+1e-4||i&&r.index>n,c=xn(t,w,Vt);if(c.tag==="Just"){const g=xn(c._1.direction,w,Vt);if(g.tag==="Just"){if(g._1==="forward")return i||u?v("Just",1):w;if(g._1==="backward"||g._1==="reverse")return i||a?v("Just",-1):w}return v("Just",s)}if(c.tag==="Nothing")return v("Just",s);f()},WP=t=>e=>n=>r=>o=>i=>a=>()=>{const s={value:1};let u=1,c=!0,g=w,d=-1,l=!0,_=!1,h=0,p=0;const m={value:F},y={value:w},x={value:0},N={value:w};let T=!1,C=()=>{},L=[],S=[],P=[];Fu(t)(n)(r)(o)(i)(a)(e)(N)(m)(y)(x)(0)();const M=E=>{const Q=E.index;return()=>{d=Q;const Y=S;return Ri(H=>H(E))(Y)()}},W=E=>()=>{const Q=L,Y=l,H={time:E,keyframe:$f(e)(E),playing:Y};return Ri(K=>K(H))(Q)()},G=()=>(l=!1,g=w,W(h)()),I=E=>()=>(h=E,Fu(t)(n)(r)(o)(i)(a)(e)(N)(m)(y)(x)(E)(),W(E)()),j=E=>{const Q=or(0)(Xo(e.totalDuration)(E));return()=>(h=Q,d=DP(e.cues)(Q),p=0,g=w,y.value=w,Fu(t)(n)(r)(o)(i)(a)(e)(N)(m)(y)(x)(Q)(),W(Q)())},O=(E,Q,Y,H,K)=>()=>{l=!1,g=w;const X=h;W(X)();const Z={reason:E,direction:Q<0?"backward":"forward",targetId:Y,targetStep:H,reached:K,time:X},nt=P;return Ri(gt=>gt(Z))(nt)()},z=()=>{if(!T&&(_=!1,l)){const E=M0(),Q=p;p=E;const Y=s.value,H=u,K=c,X=g,Z=h,nt=Q===0?Z+0*Y*H:Z+(E-Q)*Y*H;if(X.tag==="Just"){const gt=H>=0?X._1.cue.time>=Z-1e-4&&X._1.cue.time<=nt+1e-4:X._1.cue.time<=Z+1e-4&&X._1.cue.time>=nt-1e-4,bt=gt?X._1.cue.time:or(0)(Xo(e.totalDuration)(nt));(H>=0?bt+1e-4<Z:bt>Z+1e-4)&&(y.value=w),I(bt)(),Ri(Tt=>M(Tt))(O0(e.cues)(Z)(bt)(H))();const lt=O("target",H,X._1.targetId,X._1.targetStep,!0);return gt&<(),gt?void 0:$()}if(X.tag==="Nothing"){const gt=H>=0?e.totalDuration:0,bt=!K&&(H>=0?gt>=Z-1e-4&><=nt+1e-4:gt<=Z+1e-4&>>=nt-1e-4),lt=K?_P(nt)(e.totalDuration+.8):or(0)(Xo(e.totalDuration)(nt));(H>=0?lt+1e-4<Z:lt>Z+1e-4)&&(y.value=w),I(lt)(),Ri(Et=>M(Et))(O0(e.cues)(Z)(lt)(H))();const Tt=O("boundary",H,"","",!0);return bt&&Tt(),bt?void 0:$()}f()}},$=()=>{if(!T&&!_){_=!0;const E=Ff();Mf(z)(E)()}},q=()=>(p=0,l=!0,$()),D=()=>(u=1,c=!0,g=w,q(),W(h)()),B=(E,Q)=>()=>{const Y=h;return u=E,c=!1,g=w,Vf(s)(Q)(v("Just",E>=0?e.totalDuration-Y:Y))(),q()},R=(E,Q)=>()=>{const Y=h,H=d,K=QP(Q)(Y)(H)(E);if(K.tag==="Nothing")return B(Q0(Q)(1),Q)();if(K.tag==="Just"){const X=E.time-Y,Z=X<0?-X:X;return u=K._1,c=!1,g=v("Just",{cue:E,direction:K._1,targetId:E.id,targetStep:E.name}),Vf(s)(Q)(v("Just",Z))(),Z<=1e-4?(j(E.time)(),M(E)(),O("target",K._1,E.id,E.name,!0)()):q()}f()};return C=w0(t)(()=>{if(!T){const E=h;return Fu(t)(n)(r)(o)(i)(a)(e)(N)(m)(y)(x)(E)(),W(E)()}})(),q(),{play:D,playWith:E=>{const Q=Q0(E)(1);return()=>(u=Q,c=LP(E)(!1),g=w,Vf(s)(E)(w)(),q(),W(h)())},pause:G,toggle:()=>l?G():D(),seek:E=>j(E),seekCue:E=>{const Q=jt(Y=>Y.id===E)(e.cues);if(Q.tag==="Nothing")return()=>{};if(Q.tag==="Just"){const Y=Q._1,H=j(Y.time);return()=>(H(),M(Y)())}f()},seekStep:E=>{const Q=jt(Y=>Y.kind==="step"&&Y.name===E)(e.cues);if(Q.tag==="Nothing")return()=>{};if(Q.tag==="Just"){const Y=Q._1,H=j(Y.time);return()=>(H(),M(Y)())}f()},playToCue:E=>Q=>{const Y=jt(H=>H.id===E)(e.cues);if(Y.tag==="Nothing")return()=>{};if(Y.tag==="Just")return R(Y._1,Q);f()},playToStep:E=>Q=>{const Y=jt(H=>H.kind==="step"&&H.name===E)(e.cues);if(Y.tag==="Nothing")return()=>{};if(Y.tag==="Just")return R(Y._1,Q);f()},playNext:E=>()=>{const Q=h,Y=d,H=MP(e.cues)(B0(E)(["step"]))(Q)(Y);if(H.tag==="Nothing")return B(1,E)();if(H.tag==="Just")return R(H._1,E)();f()},playPrevious:E=>()=>{const Q=h,Y=d,H=zP(e.cues)(B0(E)(["step"]))(Q)(Y);if(H.tag==="Nothing")return B(-1,E)();if(H.tag==="Just")return R(H._1,IP(E)(-1))();f()},setSpeed:E=>{const Q=or(1e-4)(E<0?-E:E);return()=>s.value=Q},currentTime:()=>h,currentKeyframe:()=>{const E=h;return $f(e)(E)},isPlaying:()=>l,duration:e.totalDuration,cues:e.cues,steps:dt(E=>E.kind==="step",e.cues),subscribe:E=>()=>{L=Ct(L)(E);const Q=h,Y=l;E({time:Q,keyframe:$f(e)(Q),playing:Y})();const H=Fi(K=>!Au(K)(E));return()=>{L=H(L)}},subscribeCue:E=>()=>{S=Ct(S)(E);const Q=Fi(Y=>!Au(Y)(E));return()=>{S=Q(S)}},subscribeComplete:E=>()=>{P=Ct(P)(E);const Q=Fi(Y=>!Au(Y)(E));return()=>{P=Q(P)}},destroy:()=>{if(T=!0,C(),n==="CanvasRenderer")return iP(Su(t));if(n==="SvgRenderer")return rP(t);f()}}},OP=t=>e=>{const n=dP(t);return()=>{const r=n(),o=lP(t)();return Aa(hP,t),br(t)("stage")(i=>{const a=AP()(qf)(e);return()=>{const s=Ff();Mf(()=>{const u=a();if(u.tag==="Left")return h_("[markgraf] precompute failed")();if(u.tag==="Right"){const c=WP(i)(u._1.schedule)(gP)(qf)(o)(o5)(r)();return PP(t)(u._1.schedule)(c)()}f()})(s)()}})()}},q0=t=>e=>{const n=W0(e);if(n.tag==="Left")return h_("[markgraf] parse failed: "+n._1);if(n.tag==="Right"){if(n._1.tag==="LoadedAnimation")return OP(t)(n._1._1);if(n._1.tag==="LoadedSequence")return kP(t)(n._1._1)}f()},qP=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 Cr=null;const Mu=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",HP=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{Mu(t)?(Cr&&Cr!==t&&Mu(Cr)&&Cr.querySelector('[data-mg="play"]').click(),Cr=t):Cr===t&&(Cr=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},$P=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=qP(t),n=t.dataset.markgrafPaused==="true";t.textContent="",q0(t)(e)(),t.querySelector('[data-mg="play"]')&&(n?Mu(t)&&t.querySelector('[data-mg="play"]').click():Cr===null?Cr=t:Mu(t)&&t.querySelector('[data-mg="play"]').click(),HP(t))},zu=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach($P)},H0=()=>{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||Cr||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=FP(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>q0(e)(n)(),mountAll:zu,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{zu(),H0()}):(zu(),H0())}return qu.mountAll=zu,Object.defineProperty(qu,Symbol.toStringTag,{value:"Module"}),qu})({});
|