@markgrafhq/markgraf-embed 0.1.27 → 0.1.28
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 +28 -28
- package/package.json +1 -1
package/dist/markgraf-embed.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
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})+'"'},Ag=t=>t,Me=Ag("LT"),Qe=Ag("GT"),sn=Ag("EQ"),T=(t,e)=>({tag:t,_1:e}),y=T("Nothing"),Xt=t=>T("Just",t),V1=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;c()},U1=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;c()},zt=(t,e)=>({tag:t,_1:e}),N2=t=>zt("Right",t),b2={map:t=>e=>{if(e.tag==="Left")return zt("Left",e._1);if(e.tag==="Right")return zt("Right",t(e._1));c()}},K1={apply:t=>e=>{if(t.tag==="Left")return zt("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return zt("Left",e._1);if(e.tag==="Right")return zt("Right",t._1(e._1))}c()},Functor0:()=>b2},v2={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>zt("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}c()},Apply0:()=>K1},C2={pure:N2,Apply0:()=>K1},Y1={Applicative0:()=>C2,Bind1:()=>v2},L2=t=>t,k2={map:t=>e=>t(e)},X1={apply:t=>e=>t(e),Functor0:()=>k2},S2={bind:t=>e=>e(t),Apply0:()=>X1},E2={pure:L2,Apply0:()=>X1},qn={Applicative0:()=>E2,Bind1:()=>S2},R2=function(t){return function(){return t}},P2={apply:t=>e=>()=>{const n=t(),r=e();return Ig.pure(n(r))()},Functor0:()=>G2},Ig={pure:R2,Apply0:()=>P2},G2={map:t=>e=>()=>{const n=e();return t(n)}},Bi=(t,e)=>({tag:t,_1:e}),zg=t=>Bi("Loop",t),B2=t=>Bi("Done",t),A2={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}c()}return i};return n=>e(t(n))},Monad0:()=>qn},I2=function(t){return function(e){return function(){return t(e())}}},z2=function(t){return function(){return t}},F2=function(t){return function(e){return function(){return e(t())()}}},D2={map:I2},M2={Applicative0:()=>Fg,Bind1:()=>Q2},Q2={bind:F2,Apply0:()=>Z1},Z1={apply:t=>e=>()=>{const n=t(),r=e();return Fg.pure(n(r))()},Functor0:()=>D2},Fg={pure:z2,Apply0:()=>Z1},H2={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"&&c()}const o=r;if(o.tag==="Done")return o._1;c()}},Monad0:()=>M2},O2=function(t){return function(e){return function(n){return function(){return t(e,n)}}}},W2=function(t,e,n,r){return n>=0&&n<r.length?t(r[n]):e},Dg=function(t){return t.length},$2=function(t,e,n){return n.length>0?t(n.pop()):e},q2=O2(function(t,e){return e.push(t)}),V2=(t,e)=>({tag:"Iterator",_1:t,_2:e}),U2=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}},K2=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}c()}},Ai=function(t){return function(e){return function(n){for(var r=e,o=n.length,i=o-1;i>=0;i--)r=t(n[i])(r);return r}}},b=function(t){return function(e){return function(n){for(var r=e,o=n.length,i=0;i<o;i++)r=t(r)(n[i]);return r}}},Fo=t=>{const e=t.Apply0();return n=>r=>n.foldr(o=>{const i=r(o);return a=>e.apply(e.Functor0().map(s=>q1)(i))(a)})(t.pure())},Ii=t=>{const e=Fo(t);return n=>{const r=e(n);return o=>i=>r(i)(o)}},Y2={foldr:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(n._1)(e);c()},foldl:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(e)(n._1);c()},foldMap:t=>{const e=t.mempty;return n=>r=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return n(r._1);c()}}},Qt={foldr:Ai,foldl:b,foldMap:t=>{const e=t.mempty;return n=>Qt.foldr(r=>o=>t.Semigroup0().append(n(r))(o))(e)}},E=(t,e)=>({tag:"Tuple",_1:t,_2:e}),mn=t=>e=>E(t,e),Ts=t=>t._2,Ns=t=>t._1,Dt=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 Mg=function(t){return function(e){return t===e}};const X2=Mg,Z2=Mg,zi=Mg,bs=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}}},kr={eq:zi},j2={eq:Z2},uo={eq:X2};var Qg=function(t){return function(e){return function(n){return function(r){return function(o){return r<o?t:r===o?e:n}}}}};const ty=Qg,ey=Qg,B={compare:Qg(Me)(sn)(Qe),Eq0:()=>kr},at={compare:ey(Me)(sn)(Qe),Eq0:()=>j2},ut={compare:ty(Me)(sn)(Qe),Eq0:()=>uo},Ja=function(t){return t},ny=(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 g(_,f){switch(f-_){case 0:return a([]);case 1:return i(t)(s(u[_]));case 2:return o(i(e)(s(u[_])))(s(u[_+1]));case 3:return o(o(i(n)(s(u[_])))(s(u[_+1])))(s(u[_+2]));default:var l=_+Math.floor((f-_)/4)*2;return o(i(r)(g(_,l)))(g(l,f))}}return g(0,u.length)}}}}}})(),ry=t=>t,Vr={traverse:t=>{const e=t.Apply0();return ny(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>Vr.traverse(t)(ry),Functor0:()=>x2,Foldable1:()=>Qt},Ut=function(t,e){for(var n=t>e?-1:1,r=new Array(n*(e-t)+1),o=t,i=0;o!==e;)r[i++]=o,o+=n;return r[i]=o,r};var oy=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},iy=function(t,e){for(var n=[],r=0,o=0;o<t;o++)n[r++]=e;return n};const Do=typeof Array.prototype.fill=="function"?oy:iy,Mt=(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))}})(),ay=function(t){return t.length},It=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},j1=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},Mo=function(t,e,n,r){for(var o=0,i=r.length;o<i;o++)if(n(r[o]))return t(o);return e},tf=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)},ef=function(t,e,n,r){if(n<0||n>=r.length)return e;var o=r.slice();return o.splice(n,1),t(o)},go=function(t,e,n,r,o){if(n<0||n>=o.length)return e;var i=o.slice();return i[n]=r,t(i)},re=function(t){return t.slice().reverse()},kn=function(t){if(t.length<=1e4)return Array.prototype.concat.apply([],t);for(var e=[],n=0,r=t.length;n<r;n++)for(var o=t[n],i=0,a=o.length;i<a;i++)e.push(o[i]);return e},_t=function(t,e){return e.filter(t)},sy=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},uy=(function(){function t(e,n,r,o,i,a){var s,u,g,_,f,l,d;for(s=i+(a-i>>1),s-i>1&&t(e,n,o,r,i,s),a-s>1&&t(e,n,o,r,s,a),u=i,g=s,_=i;u<s&&g<a;)f=o[u],l=o[g],d=n(e(f)(l)),d>0?(r[_++]=l,++g):(r[_++]=f,++u);for(;u<s;)r[_++]=o[u++];for(;g<a;)r[_++]=o[g++]}return function(e,n,r){var o;return r.length<2?r:(o=r.slice(0),t(e,n,o,r.slice(0),0,r.length),o)}})(),Bt=function(t,e,n){return n.slice(t,e)},He=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},oe=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},Hg=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Rt=t=>e=>uy(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;c()},e),gy=t=>e=>Rt(n=>r=>t.compare(e(n))(e(r))),Et=t=>e=>(()=>{const n=q2(e);return()=>{const r=[...t];return n(r)(),r}})()(),Sr=t=>{if(t.length===0)return t.length-1|0,y;const e=t.length-1|0;return e>=0&&e<t.length?T("Just",{init:Bt(0,t.length-1|0,t),last:t[e]}):y},cy=t=>e=>n=>t>=0&&t<n.length?go(Xt,y,t,e(n[t]),n):y,Er=t=>e=>{const n=(r=>{let o=r,i=!0,a;for(;i;){const s=o;if(s>=0&&s<e.length){if(t(e[s])){o=s+1|0;continue}i=!1,a=T("Just",s);continue}i=!1,a=y}return a})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:Bt(0,n._1,e),rest:Bt(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};c()},Ur=t=>e=>{const n=Rt(r=>o=>t(r._2)(o._2))(Dt(mn)(e));return 0<n.length?Y(Ts)(gy(ut)(Ns)((()=>{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;c()})())(o._2);(i==="LT"||i==="GT"||i!=="EQ")&&r.push(o)}return r})())):[]},_y=t=>e=>{const n=[],r=V2(o=>o>=0&&o<e.length?T("Just",e[o]):y,{value:0});return K2(r)(o=>()=>{const i=[];i.push(o),U2(t(o))(r)(i)(),n.push(i)})(),n},te=t=>e=>{const n=Mo(Xt,y,t,e);return n.tag==="Just"?T("Just",e[n._1]):y},Ta=t=>e=>_t(t,e),yn=t=>e=>n=>{const r=Mo(Xt,y,o=>t.eq(o)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;c()},vs=t=>e=>St(e)(t),ht=t=>vs(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];c()}),Na=isFinite;function Og(t,e,n,r){var o=parseFloat(t);return e(o)?n(o):r}const xe=Math.abs,fy=Math.acos,Qo=function(t){return function(e){return Math.atan2(t,e)}},Cs=Math.ceil,xn=Math.cos,co=Math.exp,sr=Math.floor,_o=Math.log,ly=function(t){return function(e){return Math.min(t,e)}},Wg=function(t){return function(e){return Math.pow(t,e)}},Vn=Math.round,tn=Math.sin,qe=Math.sqrt,dy=Math.tan,hy=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},ot=function(t){return t},py=(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}}}})(Xt)(y)(10),nf=hy(Xt)(y),he=t=>{if(!Na(t))return 0;if(t>=ot(2147483647))return 2147483647;if(t<=ot(-2147483648))return-2147483648;const e=nf(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;c()},wt=(t,e,n)=>({tag:t,_1:e,_2:n}),A=wt("Nil"),ce={foldr:t=>e=>{const n=ce.foldl(o=>i=>t(i)(o))(e),r=(o=>i=>{let a=o,s=i,u=!0,g;for(;u;){const _=a,f=s;if(f.tag==="Nil"){u=!1,g=_;continue}if(f.tag==="Cons"){a=wt("Cons",f._1,_),s=f._2;continue}c()}return g})(A);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}c()}return a},foldMap:t=>{const e=t.mempty;return n=>ce.foldl(r=>{const o=t.Semigroup0().append(r);return i=>o(n(i))})(e)}},my=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 g=r(u);if(t(g))return a;s=e(g)}}}}}}},yy=t=>{if(t.tag==="Just")return t._1;c()},xy={unfoldr1:my(V1)(yy)(Ns)(Ts)},wy=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 g=e(u);a.push(n(g)),s=r(g)}}}}}}},Jy=t=>{if(t.tag==="Just")return t._1;c()},un={unfoldr:wy(V1)(Jy)(Ns)(Ts),Unfoldable10:()=>xy},ee=(t,e,n,r,o,i,a)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:a}),gn=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Ls=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),rf=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),H=ee("Leaf"),Un=gn("IterLeaf"),Re=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return ee("Node",1,1,t,e,n,r);if(r.tag==="Node")return ee("Node",1+r._1|0,1+r._2|0,t,e,n,r);c()}if(n.tag==="Node"){if(r.tag==="Leaf")return ee("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return ee("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,t,e,n,r)}c()},cn=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?ee("Node",1,1,t,e,H,H):r.tag==="Node"&&r._1>1?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;c()})()?Re(r._5._3,r._5._4,Re(t,e,n,r._5._5),Re(r._3,r._4,r._5._6,r._6)):Re(r._3,r._4,Re(t,e,n,r._5),r._6):Re(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;c()})()?Re(r._5._3,r._5._4,Re(t,e,n,r._5._5),Re(r._3,r._4,r._5._6,r._6)):Re(r._3,r._4,Re(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;c()})()?Re(n._6._3,n._6._4,Re(n._3,n._4,n._5,n._6._5),Re(t,e,n._6._6,r)):Re(n._3,n._4,n._5,Re(t,e,n._6,r)):Re(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;c()})()?Re(n._6._3,n._6._4,Re(n._3,n._4,n._5,n._6._5),Re(t,e,n._6._6,r)):Re(n._3,n._4,n._5,Re(t,e,n._6,r)):Re(t,e,n,r);c()},Fi=(t,e,n)=>{if(n.tag==="Leaf")return Ls(y,H,H);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const o=Fi(t,e,n._5);return Ls(o._1,o._2,cn(n._3,n._4,o._3,n._6))}if(r==="GT"){const o=Fi(t,e,n._6);return Ls(o._1,cn(n._3,n._4,n._5,o._2),o._3)}if(r==="EQ")return Ls(T("Just",n._4),n._5,n._6)}c()},of=(t,e,n,r)=>{if(r.tag==="Leaf")return rf(t,e,n);if(r.tag==="Node"){const o=of(r._3,r._4,r._5,r._6);return rf(o._1,o._2,cn(t,e,n,o._3))}c()},Di=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=of(t._3,t._4,t._5,t._6);return cn(n._1,n._2,n._3,e)}c()},Kn=(t,e,n)=>{if(e.tag==="Leaf")return H;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=Fi(t,n._3,e);return Di(Kn(t,r._2,n._5),Kn(t,r._3,n._6))}c()},ks=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return H;if(r.tag==="Node"){const o=Fi(t,r._3,n),i=ks(t,e,o._2,r._5),a=ks(t,e,o._3,r._6);if(o._1.tag==="Just")return cn(r._3,e(o._1._1)(r._4),i,a);if(o._1.tag==="Nothing")return Di(i,a)}c()},en=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const o=Fi(t,r._3,n),i=en(t,e,o._2,r._5),a=en(t,e,o._3,r._6);if(o._1.tag==="Just")return cn(r._3,e(o._1._1)(r._4),i,a);if(o._1.tag==="Nothing")return cn(r._3,r._4,i,a)}c()},af=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return H;if(o.tag==="Node"){const i=t.compare(n)(o._3);if(i==="LT")return cn(o._3,o._4,r(o._5),o._6);if(i==="GT")return cn(o._3,o._4,o._5,r(o._6));if(i==="EQ"){const a=e(o._4);if(a.tag==="Nothing")return Di(o._5,o._6);if(a.tag==="Just")return ee("Node",o._1,o._2,o._3,a._1,o._5,o._6)}}c()};return r},$g=t=>e=>{const n=r=>{if(r.tag==="Leaf")return H;if(r.tag==="Node"){const o=e(r._3)(r._4);if(o.tag==="Just")return cn(r._3,o._1,n(r._5),n(r._6));if(o.tag==="Nothing")return Di(n(r._5),n(r._6))}c()};return n},Yn=(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 g=s,_=u,f=!0,l;for(;f;){const d=g,h=_;if(h.tag==="Leaf"){f=!1,l=d;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){g=gn("IterEmit",h._3,h._4,d),_=h._5;continue}g=gn("IterEmit",h._3,h._4,gn("IterNode",h._6,d)),_=h._5;continue}c()}return l})(a._2)(a._1);continue}c()}return i})((t,e,n)=>T("Just",E(E(t,e),n)))(t=>y),Ht=t=>e=>n=>r=>{const o=i=>{if(i.tag==="Leaf")return ee("Node",1,1,n,r,H,H);if(i.tag==="Node"){const a=t.compare(n)(i._3);if(a==="LT")return cn(i._3,i._4,o(i._5),i._6);if(a==="GT")return cn(i._3,i._4,i._5,o(i._6));if(a==="EQ")return ee("Node",i._1,i._2,n,e(i._4)(r),i._5,i._6)}c()};return o},it=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return ee("Node",1,1,e,n,H,H);if(o.tag==="Node"){const i=t.compare(e)(o._3);if(i==="LT")return cn(o._3,o._4,r(o._5),o._6);if(i==="GT")return cn(o._3,o._4,o._5,r(o._6));if(i==="EQ")return ee("Node",o._1,o._2,e,n,o._5,o._6)}c()};return r},fe=t=>e=>e.foldl(n=>r=>it(t)(r._1)(r._2)(n))(H),Mi=t=>e=>{const n=r=>{if(r.tag==="Leaf")return H;if(r.tag==="Node"){const o=t.compare(e)(r._3);if(o==="LT")return cn(r._3,r._4,n(r._5),r._6);if(o==="GT")return cn(r._3,r._4,r._5,n(r._6));if(o==="EQ")return Di(r._5,r._6)}c()};return n},sf=t=>{const e=t.compare;return n=>r=>o=>{const i=Fi(e,r,o),a=n(i._1);if(a.tag==="Nothing")return Di(i._2,i._3);if(a.tag==="Just")return cn(r,a._1,i._2,i._3);c()}},ve=function(t){return function(e){return t+e|0}},ur=function(t){return function(e){return t+e}},fo=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},Ty=function(t){return function(e){return t+e}},we=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},Ny={append:Ty},by={append:we},uf={mempty:"",Semigroup0:()=>Ny},vy={mempty:[],Semigroup0:()=>by},ba=null;function Gn(t,e,n){return t==null?e:n(t)}function cG(t){return t}function qg(t){return function(e){return function(n){return t.apply(n,[e])}}}const Cy=qg(Number.prototype.toPrecision),Ly=qg(Number.prototype.toFixed),ky=qg(Number.prototype.toExponential),Ho=(t,e)=>({tag:t,_1:e}),Oo=t=>e=>n=>{const r=ut.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=ut.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},Wo=t=>{if(t.tag==="Precision")return Cy(t._1);if(t.tag==="Fixed")return Ly(t._1);if(t.tag==="Exponential")return ky(t._1);c()},gf=function(t){return function(){console.log(t)}};function cf(t){return function(){return t.getContext("2d")}}function _f(t){return function(){return t.width}}function ff(t){return function(){return t.height}}function lf(t){return function(e){return function(){t.width=e}}}function df(t){return function(e){return function(){t.height=e}}}function Ss(t){return function(e){return function(){t.lineWidth=e}}}function Sy(t){return function(e){return function(){t.setLineDash(e)}}}function hf(t){return function(e){return function(){t.fillStyle=e}}}function pf(t){return function(e){return function(){t.strokeStyle=e}}}function Vg(t){return function(e){return function(){t.lineCap=e}}}function Ug(t){return function(e){return function(){t.lineJoin=e}}}function Ey(t){return function(e){return function(){t.globalCompositeOperation=e}}}function Ry(t){return function(e){return function(){t.globalAlpha=e}}}function mf(t){return function(){t.beginPath()}}function Kg(t){return function(){t.stroke()}}function Yg(t){return function(){t.fill()}}function Py(t){return function(){t.clip()}}function va(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function yf(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function xf(t){return function(){t.closePath()}}function Gy(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function By(t){return function(e){return function(){t.strokeRect(e.x,e.y,e.width,e.height)}}}function Ay(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function Ca(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function wf(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function Iy(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function zy(t){return function(e){return function(){t.textAlign=e}}}function Fy(t){return function(e){return function(){t.textBaseline=e}}}function Jf(t){return function(e){return function(){t.font=e}}}function Tf(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function gr(t){return function(){t.save()}}function cr(t){return function(){t.restore()}}function La(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function Dy(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const Nf=t=>t,Xg=t=>t,Zg=t=>t,jg=t=>t,Es=t=>t,My=Es("BaselineTop"),Qy=Es("BaselineMiddle"),Hy=Es("BaselineAlphabetic"),Oy=Es("BaselineBottom"),Wy=jg("AlignLeft"),$y=jg("AlignRight"),qy=jg("AlignCenter"),tc=Zg("BevelJoin"),ec=Zg("RoundJoin"),nc=Zg("MiterJoin"),rc=Xg("Round"),oc=Xg("Square"),ic=Xg("Butt"),Vy=Nf("SourceOver"),Uy=Nf("Difference"),Ky=t=>e=>Fy(t)((()=>{if(e==="BaselineTop")return"top";if(e==="BaselineHanging")return"hanging";if(e==="BaselineMiddle")return"middle";if(e==="BaselineAlphabetic")return"alphabetic";if(e==="BaselineIdeographic")return"ideographic";if(e==="BaselineBottom")return"bottom";c()})()),Yy=t=>e=>zy(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";c()})()),ac=t=>e=>{if(e==="BevelJoin")return Ug(t)("bevel");if(e==="RoundJoin")return Ug(t)("round");if(e==="MiterJoin")return Ug(t)("miter");c()},sc=t=>e=>{if(e==="Round")return Vg(t)("round");if(e==="Square")return Vg(t)("square");if(e==="Butt")return Vg(t)("butt");c()},bf=t=>e=>Ey(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";c()})()),vf={foldrWithIndex:t=>e=>{const n=Ai(o=>{const i=o._1,a=o._2;return s=>t(i)(a)(s)})(e),r=Dt(mn);return o=>n(r(o))},foldlWithIndex:t=>e=>{const n=b(o=>i=>t(i._1)(o)(i._2))(e),r=Dt(mn);return o=>n(r(o))},foldMapWithIndex:t=>{const e=t.mempty;return n=>vf.foldrWithIndex(r=>o=>i=>t.Semigroup0().append(n(r)(o))(i))(e)},Foldable0:()=>Qt},Xy=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Zy=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Rs=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},jy=t=>e=>n=>r=>n<=0||r<=0||e.bounds.w<=0||e.bounds.h<=0?1:t?Xy(e.bounds.w/n)(e.bounds.h/r):Zy(e.bounds.w/n)(e.bounds.h/r),Cf=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;if(t.widthPx<=0||t.heightPx<=0){const a=1/Rs(.05)(1)(e);return{w:n.w*a,h:n.h*a}}if(r>o){const a=1/Rs(.05)(1)(e);return{w:n.h*r*a,h:n.h*a}}const i=1/Rs(.05)(1)(e);return{w:n.w*i,h:n.w/r*i}},Lf=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:Rs(i)(a)(u)},kf=t=>e=>n=>r=>({x:Lf(t.bounds.x)(t.bounds.w)(e.x)(e.w)(n),y:Lf(t.bounds.y)(t.bounds.h)(e.y)(e.h)(r)}),ka=t=>e=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:jy(t)(e)(n.w)(n.h)}),Sf=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=Cf(e)(.65)(o),a=kf(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:ka(e.widthPx>0&&e.heightPx>0)(n)(s)}},tx=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=Cf(e)(1)(s),g=kf(n)(s)(u.w)(u.h),_={x:g.x-u.w/2,y:g.y-u.h/2,w:u.w,h:u.h};return{footprint:i,viewport:_,camera:ka(e.widthPx>0&&e.heightPx>0)(n)(_)}},ex=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;return t.widthPx<=0||t.heightPx<=0?ka(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?ka(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}})()):ka(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}})())},wn={foldr:t=>e=>{const n=ce.foldr(t)(e);return r=>n((()=>{const o=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return o(i._5,wt("Cons",i._3,o(i._6,a)));c()};return o(r,A)})())}},nx=t=>{const e={append:(()=>{const n=t.compare;return r=>o=>en(n,je,r,o)})()};return{mempty:H,Semigroup0:()=>e}},Sa=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},Bn=function(t){return t.join("")},Xn=function(t){return t.split("")},An=function(t){return t},In=function(t){return t.length},Ef=function(t){return function(e){return e.substr(0,t)}},Qi=function(t){return function(e){return e.substring(t)}},Rf=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},rx=t=>e=>{const n=Rf(In(e)-In(t)|0)(e);return n.after===t?T("Just",n.before):y},xr=t=>e=>{const n=Rf(In(t))(e);return n.before===t?T("Just",n.after):y},ox=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},ix=function(t){return t()},ax=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},sx=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},$o=t=>BigInt(t),ux=t=>Number(t),Ps=t=>e=>t+e,Gs=t=>e=>t*e,uc=t=>e=>t-e,Pf=0n,Bs=1n,Gf=t=>e=>t^e,Ea=t=>e=>t&e,gc=t=>e=>t<<e,cc=t=>e=>t>>e,gx=t=>e=>t==e,cx=t=>e=>t===e?0:t>e?1:-1,_x={eq:gx},Bf={compare:t=>e=>{const n=cx(t)(e);return n===1?Qe:n===0?sn:Me},Eq0:()=>_x},fx=ax(Xt)(y),lx=sx(Xt)(y),Af=function(t){throw new Error(t)},If=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=at.compare(e._1)(n._1);return r==="LT"?Me:r==="GT"?Qe:at.compare(e._2)(n._2)},Eq0:()=>t}})(),dx=t=>e=>xe(t._1-e._1)+xe(t._2-e._2),qo=t=>t,As=t=>t,Ie=As("North"),ze=As("South"),Kr=As("East"),Yr=As("West"),lo=qo("Rectangle"),hx=qo("Cylinder"),px=qo("Parallelogram"),mx=qo("Diamond"),yx=qo("Ellipse"),xx=qo("Document"),wx=qo("Cloud"),zf=t=>t,Jx=(t,e)=>({tag:t,_1:e}),_c=t=>t,Hi=(t,e)=>({tag:t,_1:e}),fc=(t,e)=>({tag:t,_1:e}),Ra=_c("Animated"),Tx=_c("StaticStill"),Nx=_c("TitleCard"),bx=fc("First"),Ff=zf("Forward"),Df=zf("Backward"),vx=Hi("ExitNode"),Mf=fe(B)(Qt),Cx=t=>Ai(e=>n=>({nodes:en(B.compare,je,e.nodes,n.nodes),edges:en(B.compare,je,e.edges,n.edges)}))({nodes:H,edges:H})(t.keyframes),Lx=t=>e=>({entering:{nodes:Kn(B.compare,e.nodes,t.nodes),edges:Kn(B.compare,e.edges,t.edges)},leaving:{nodes:Kn(B.compare,t.nodes,e.nodes),edges:Kn(B.compare,t.edges,e.edges)},surviving:{nodes:ks(B.compare,je,t.nodes,e.nodes),edges:ks(B.compare,je,t.edges,e.edges)}}),Is=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Oi=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},zs=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},lc=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=B.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}}c()}return o},kx=b(t=>e=>it(B)(e)()(t))(H),Sx=b(t=>e=>it(B)(e)()(t))(H),Ex=(()=>{const t=un.unfoldr(Yn);return e=>t(gn("IterNode",e,Un))})(),Qf=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Hf=fe(B)(Qt),Pa=t=>{const e=It(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=b(r=>o=>({minX:Is(r.minX)(o.x),minY:Is(r.minY)(o.y),maxX:Oi(r.maxX)(o.x),maxY:Oi(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}}c()},Rx=t=>e=>n=>kx(St(Mt(wn.foldr,n))(r=>{const o=zs(r)(t);if(o.tag==="Just")return _t(i=>!lc(i)(e),[o._1.source,o._1.target]);if(o.tag==="Nothing")return[];c()})),Px=t=>t.kind.tag==="SendToken"?T("Just",E(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):y,Gx=t=>t.tag==="DataFlow"?ht(Px)(t._1.events):[],Bx=t=>e=>Sx(ht(n=>lc(n._2.source)(e)||lc(n._2.target)(e)?T("Just",n._1):y)(Ex(t))),ae=t=>{const e=It(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=b(r=>o=>({minX:Is(r.minX)(o.x),minY:Is(r.minY)(o.y),maxX:Oi(r.maxX)(o.x+o.w),maxY:Oi(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}}c()},dc=t=>e=>n=>{if(n.tag==="Leaf")return t.bounds;const r=Bx(e)(n),o=[...ht(i=>{const a=Qf(i)(t.nodes);return a.tag==="Just"?T("Just",{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}):y})(Mt(wn.foldr,en(B.compare,je,n,Rx(e)(n)(r)))),...ht(i=>{const a=zs(i)(t.edges);return a.tag==="Just"?T("Just",Pa(a._1)):y})(Mt(wn.foldr,r))];return o.length===0?t.bounds:ae(o)},Vo=t=>e=>n=>{const r=[...ht(o=>o)([(()=>{const o=zs(n)(t.edges);return o.tag==="Just"?T("Just",Pa(o._1)):y})()]),...(()=>{const o=zs(n)(e);if(o.tag==="Just")return ht(i=>{const a=Qf(i)(t.nodes);return a.tag==="Just"?T("Just",{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}):y})([o._1.source,o._1.target]);if(o.tag==="Nothing")return[];c()})()];return r.length===0?dc(t)(e)(H):ae(r)},_r=t=>e=>{const n=t.bounds.w/Oi(1e-4)(e.zoom),r=t.bounds.h/Oi(1e-4)(e.zoom);return{x:e.center.x-n/2,y:e.center.y-r/2,w:n,h:r}},Ax=t=>en(B.compare,je,Hf(Y(e=>E(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),Hf(St(t.scenes)(Gx))),hc=t=>e=>n=>r=>{if(e<=0)return r;if(t<=0)return{position:r.position+r.velocity*e,velocity:r.velocity};const o=r.velocity-n.velocity,i=r.position-n.position,a=co(-t*e),s=o+t*i;return{position:n.position+n.velocity*e+(i+s*e)*a,velocity:n.velocity+(o-t*s*e)*a}},pc=t=>t,Ix=t=>t,mc=pc("Linear"),fr=pc("EaseInOutQuad"),zx=pc("SpringBouncy"),Uo=t=>e=>n=>{const r=qe(1-e*e),o=t*r;return 1-co(-e*t*n)*(xn(o*n)+e/r*tn(o*n))},Fx=t=>{const e=at.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;c()})(),r=at.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;c()},Wi=t=>e=>(()=>{if(t==="Linear")return Ix;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-Wg(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*co(-6*n);if(t==="SpringBouncy")return Uo(6)(.7);c()})()(Fx(e)),Fs=t=>t,Ds=(t,e)=>({tag:t,_1:e}),Of=t=>t,ke=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ms=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},Qs=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Dx=t=>e=>{const n=ut.compare(t._1)(e._1);return n==="LT"?Me:n==="GT"?Qe:at.compare(t._2)(e._2)},Mx=Of("Hold"),Qx=Of("Gap"),Hx=Ds("LinearLerp"),Ko=Ds("LogLerp"),ho=Ds("ComposedLogLerp"),Wf=Ds("StationaryShot"),Hs=Fs("Overview"),$f=Fs("DiveHome"),po=Fs("DiveTransition"),Ox=Fs("ActionFocus"),Wx={eq:t=>e=>t.tag==="LinearLerp"?e.tag==="LinearLerp":t.tag==="LogLerp"?e.tag==="LogLerp":t.tag==="ComposedLogLerp"?e.tag==="ComposedLogLerp":t.tag==="StationaryShot"?e.tag==="StationaryShot":t.tag==="SpringInterp"&&e.tag==="SpringInterp"&&t._1.frequency===e._1.frequency&&t._1.initialVelocity.center.x===e._1.initialVelocity.center.x&&t._1.initialVelocity.center.y===e._1.initialVelocity.center.y&&t._1.initialVelocity.zoomLog===e._1.initialVelocity.zoomLog&&t._1.target.center.x===e._1.target.center.x&&t._1.target.center.y===e._1.target.center.y&&t._1.target.zoom===e._1.target.zoom&&t._1.targetVelocity.center.x===e._1.targetVelocity.center.x&&t._1.targetVelocity.center.y===e._1.targetVelocity.center.y&&t._1.targetVelocity.zoomLog===e._1.targetVelocity.zoomLog},Os={center:{x:0,y:0},zoomLog:0},qf=t=>e=>n=>{const r=t.widthPx>0&&t.heightPx>0,o=t.widthPx/ke(1e-6)(t.heightPx),i=e.bounds.w/ke(1e-6)(n.zoom),a=e.bounds.h/ke(1e-6)(n.zoom),s=i/ke(1e-6)(a),u=r&&o<s?i/o:a,g=r&&o>s?a*o:i;return{x:n.center.x-g/2,y:n.center.y-u/2,w:g,h:u}},$x=t=>({startT:t.startT,endT:t.endT,fromCam:t.fromCam,toCam:t.toCam,easing:t.easing,interp:t.interp,intent:t.intent}),qx=b(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:Et(t)(e)})([]),Ws=t=>e=>n=>{const r=Ms(0)(1)((n-t)/ke(1e-6)(e-t));return r*r*r*(r*(r*6-15)+10)},Vf=t=>e=>n=>r=>o=>{const i=xe(_o(ke(1e-6)(o.zoom))-_o(ke(1e-6)(r.zoom))),a=qf(e)(n)({...r,zoom:ke(ke(1e-6)(r.zoom))(ke(1e-6)(o.zoom))}),s=(o.center.y-r.center.y)*e.heightPx/ke(1e-6)(a.h),u=(o.center.x-r.center.x)*e.widthPx/ke(1e-6)(a.w),g=qe(u*u+s*s);return ke(t.minTransition)(ke(t.panSpeed<=0?t.minTransition:2*g/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:2*i/t.zoomSpeed))},Vx=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})()})()})()},Ux=t=>e=>t.tag==="Just"?e.tag==="Just"&&Vx(t._1)(e._1):t.tag==="Nothing"&&e.tag==="Nothing",yc=t=>e=>n=>r=>({center:{x:r.center.x*n.scale+n.tx,y:r.center.y*n.scale+n.ty},zoom:r.zoom*t.bounds.w/ke(1e-6)(n.scale*e.bounds.w)}),$s=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:co((()=>{const o=_o(ke(1e-6)(t.zoom));return o+(_o(ke(1e-6)(e.zoom))-o)*r})())}),Kx=t=>b(e=>n=>{if(n.endT>t)return e;if(e.tag==="Nothing")return T("Just",n);if(e.tag==="Just")return n.endT>e._1.endT?T("Just",n):T("Just",e._1);c()})(y),Yx=t=>e=>n=>r=>{if(t<=0)return r;const o=co(-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:co((()=>{const i=_o(ke(1e-6)(r.zoom));return i+(_o(ke(1e-6)(n.zoom))-i)*o})())}},xc=t=>e=>n=>e.zoom>=t.zoom?Ws(.3)(1)(n):Ws(0)(.7)(n),Xx={padding:24,easing:fr,minimumReadableLabelPx:12,minimumVisibleLabelPx:5,labelBasePx:11,panSpeed:420,zoomSpeed:1.4,minTransition:.25,maxTransition:.6,cameraDecay:0},Yo=t=>e=>n=>r=>o=>{const i=qf(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},Zx=t=>e=>n=>r=>o=>vf.foldlWithIndex(i=>a=>s=>{const u=(()=>{if(s.kind==="Hold"){const g=(()=>{if(i===0)return s.toCam;if(s.focus.tag==="Just"){if(s.intent==="ActionFocus")return(e.widthPx<=0||e.heightPx<=0)&&Yo(t)(e)(n)(a.prev)(s.focus._1)||a.prev.zoom>=s.toCam.zoom*.995&&Yo(t)(e)(n)(a.prev)(s.focus._1)?a.prev:Yo(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 _=n.bounds.w/ke(1e-6)(s.toCam.zoom);if(_<=0)return s.toCam.center.x;const f=s.focus._1.x+s.focus._1.w/2,l=e.widthPx<=0?0:Qs(_/4)(6*_/e.widthPx),d=a.prev.center.x+_/2-l,h=f<a.prev.center.x-_/2+l?f-l+_/2:f>d?f+l-_/2:a.prev.center.x;return _>=n.bounds.w?n.bounds.x+n.bounds.w/2:Ms(n.bounds.x+_/2)(n.bounds.x+n.bounds.w-_/2)(h)})()}};if(Yo(t)(e)(n)(a.prev)(s.focus._1))return a.prev;if(Yo(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:g,toCam:g,easing:s.easing,interp:s.stationary?Wf:Hx,focus:s.focus,intent:s.intent}}if(s.kind==="Gap")return{startT:s.startT,endT:s.endT,fromCam:a.prev,toCam:(()=>{const g=i+1|0,_=Mo(Xt,y,f=>f.kind==="Hold",g<1?o:Bt(g,o.length,o));if(_.tag==="Just"){const f=(i+1|0)+_._1|0;return f>=0&&f<o.length?(()=>{if(o[f].focus.tag==="Just")return Yo(t)(e)(n)(a.prev)(o[f].focus._1);if(o[f].focus.tag==="Nothing")return!1;c()})()?a.prev:o[f].fromCam:a.prev}if(_.tag==="Nothing")return a.prev;c()})(),easing:s.easing,interp:Ko,focus:y,intent:s.intent};c()})();return{acc:Et(a.acc)(u),prev:u.toCam}})({acc:[],prev:r})(o).acc,jx=t=>e=>n=>r=>o=>i=>{const a=(u,g)=>Qs(Vf(t)(e)(n)(u.toCam)(g.toCam))(u.endT-u.startT),s=b(u=>g=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:T("Just",g)};if(u.pending.tag==="Just"){if(!(g.fromCam.zoom===g.toCam.zoom&&g.fromCam.center.x===g.toCam.center.x&&g.fromCam.center.y===g.toCam.center.y)||(()=>{if(g.focus.tag==="Just")return Yo(t)(e)(n)(u.pending._1.toCam)(g.focus._1);if(g.focus.tag==="Nothing")return!1;c()})()||(()=>{const _=u.pending._1.toCam.center.x-g.toCam.center.x;return(_<0?-_<8:_<8)&&(()=>{const f=u.pending._1.toCam.center.y-g.toCam.center.y;return(f<0?-f<8:f<8)&&(()=>{const l=u.pending._1.toCam.zoom-g.toCam.zoom;return l<0?-l<.08:l<.08})()})()})()||a(u.pending._1,g)<=0)return{acc:Et(u.acc)(u.pending._1),pending:T("Just",g)};if((()=>{const _=g.startT;return oe(f=>xe(f-_)<1e-4,o)})()){const _={startT:g.startT,endT:g.startT+Qs(Vf(t)(e)(n)(u.pending._1.toCam)(g.toCam))(g.endT-g.startT),fromCam:u.pending._1.toCam,toCam:g.toCam,easing:g.easing,interp:Ko,focus:g.focus,intent:g.intent},f={...g,startT:_.endT,fromCam:g.toCam};return f.startT<f.endT?{acc:Et(Et(u.acc)(u.pending._1))(_),pending:T("Just",f)}:{acc:Et(u.acc)(u.pending._1),pending:T("Just",_)}}return{acc:Et(Et(u.acc)({...u.pending._1,endT:g.startT-a(u.pending._1,g)}))({startT:g.startT-a(u.pending._1,g),endT:g.startT,fromCam:u.pending._1.toCam,toCam:g.toCam,easing:g.easing,interp:Ko,focus:g.focus,intent:g.intent}),pending:T("Just",g)}}c()})({acc:[],pending:y})(i);if(s.pending.tag==="Nothing")return s.acc;if(s.pending.tag==="Just")return Et(s.acc)(s.pending._1);c()},tw=t=>e=>n=>{const r=e.w+n*2,o=e.h+n*2;return r<=0||o<=0||t.bounds.w<=0||t.bounds.h<=0?1:Qs(t.bounds.w/r)(t.bounds.h/o)},ew=t=>e=>n=>e.zoom>=t.zoom?$s(t)(e)(Ws(0)(.45)(n))(xc(t)(e)(n)):$s(t)(e)(Ws(.55)(1)(n))(xc(t)(e)(n)),nw=t=>e=>{if(t.tag==="Just"){if(e.tag==="Just")return T("Just",ae([t._1,e._1]));if(e.tag==="Nothing")return T("Just",t._1);c()}if(t.tag==="Nothing"){if(e.tag==="Just")return T("Just",e._1);if(e.tag==="Nothing")return y}c()},rw=b(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?T("Just",t[n]):y;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.toCam.zoom===e.toCam.zoom&&r._1.toCam.center.x===e.toCam.center.x&&r._1.toCam.center.y===e.toCam.center.y?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":!(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")&&Ux(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})()})()})()?Et((()=>{const o=t.length-1|0;return o<1?[]:Bt(0,o,t)})())({...r._1,endT:e.endT,focus:nw(r._1.focus)(e.focus)}):Et(t)(e)})([]),ow=t=>{const e=Rt(n=>r=>Dx(E((()=>{if(r.intent==="DiveTransition")return 3;if(r.intent==="ActionFocus")return 2;if(r.intent==="DiveHome")return 1;if(r.intent==="Overview")return 0;c()})(),r.startT))(E((()=>{if(n.intent==="DiveTransition")return 3;if(n.intent==="ActionFocus")return 2;if(n.intent==="DiveHome")return 1;if(n.intent==="Overview")return 0;c()})(),n.startT)))(t);return 0<e.length?T("Just",e[0]):y},iw=t=>e=>{const n=e.endT<=e.startT?1:(t-e.startT)/(e.endT-e.startT),r=Wi(e.easing)(Ms(0)(1)(n));if(e.interp.tag==="SpringInterp"){const o=Ms(0)(ke(0)(e.endT-e.startT))(t-e.startT),i=hc(e.interp._1.frequency)(o)({position:e.interp._1.target.center.x,velocity:e.interp._1.targetVelocity.center.x})({position:e.fromCam.center.x,velocity:e.interp._1.initialVelocity.center.x}),a=hc(e.interp._1.frequency)(o)({position:e.interp._1.target.center.y,velocity:e.interp._1.targetVelocity.center.y})({position:e.fromCam.center.y,velocity:e.interp._1.initialVelocity.center.y}),s=hc(e.interp._1.frequency)(o)({position:_o(ke(1e-6)(e.interp._1.target.zoom)),velocity:e.interp._1.targetVelocity.zoomLog})({position:_o(ke(1e-6)(e.fromCam.zoom)),velocity:e.interp._1.initialVelocity.zoomLog});return{camera:{center:{x:i.position,y:a.position},zoom:co(s.position)},velocity:{center:{x:i.velocity,y:a.velocity},zoomLog:s.velocity}}}if(e.interp.tag==="LinearLerp")return{camera:{center:{x:e.fromCam.center.x+(e.toCam.center.x-e.fromCam.center.x)*r,y:e.fromCam.center.y+(e.toCam.center.y-e.fromCam.center.y)*r},zoom:e.fromCam.zoom+(e.toCam.zoom-e.fromCam.zoom)*r},velocity:Os};if(e.interp.tag==="LogLerp")return{camera:$s(e.fromCam)(e.toCam)(r)(r),velocity:Os};if(e.interp.tag==="ComposedLogLerp")return{camera:ew(e.fromCam)(e.toCam)(n),velocity:Os};if(e.interp.tag==="StationaryShot")return{camera:$s(e.fromCam)(e.toCam)(r)(r),velocity:Os};c()},wc=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:ke(r)(tw(e)(n)(t.padding))}),aw=t=>e=>n=>r=>o=>i=>{const a=wc(t)(n)(n.bounds)(0),s=_t(u=>u>=0&&u<=r,qx(Rt(at.compare)([0,r,...o,...St(i)(u=>[u.startT,u.endT])])));return Y($x)(jx(t)(e)(n)(a)(o)(rw(Zx(t)(e)(n)(a)(ht(u=>{const g=(u._1+u._2)/2,_=b(d=>h=>h.startT>g||g>=h.endT?d:h.priority>d.topPriority?{topPriority:h.priority,bboxes:[h.bbox],actionActive:d.actionActive||h.priority>=1,continuous:h.continuous,stationary:h.stationary}:h.priority===d.topPriority?{...d,bboxes:Et(d.bboxes)(h.bbox),actionActive:d.actionActive||h.priority>=1,continuous:d.continuous||h.continuous,stationary:d.stationary||h.stationary}:{...d,actionActive:d.actionActive||h.priority>=1})({topPriority:0,bboxes:[],actionActive:!1,continuous:!1,stationary:!1})(i);if(u._2<=u._1)return y;if(_.bboxes.length===0)return T("Just",{kind:Qx,startT:u._1,endT:u._2,fromCam:a,toCam:a,easing:t.easing,focus:y,stationary:!1,intent:Hs});const f=ae(_.bboxes),l=_.actionActive?Sf(t)(e)(n)(f).camera:wc(t)(n)(f)(0);return T("Just",{kind:Mx,startT:u._1,endT:u._2,fromCam:l,toCam:l,easing:_.continuous?mc:t.easing,focus:T("Just",f),intent:_.actionActive?Ox:Hs,stationary:_.stationary})})(He(mn,s,Bt(1,s.length,s)))))))},Xo=t=>e=>n=>r=>{const o=ow(_t(i=>r>=i.startT&&r<i.endT,n));if(o.tag==="Just")return{camera:iw(r)(o._1).camera,intent:o._1.intent};if(o.tag==="Nothing"){const i=Kx(r)(n);if(i.tag==="Just")return{camera:i._1.toCam,intent:i._1.intent};if(i.tag==="Nothing")return{camera:(()=>{const a=wc(t)(e)(e.bounds)(0);return 0<n.length?n[0].fromCam:a})(),intent:0<n.length?n[0].intent:Hs}}c()};function Xr(t){return t.charCodeAt(0)}function Uf(t){return String.fromCharCode(t)}const lr=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},$i=function(t){return function(e){return e.split(t)}},Ga=function(t){return t.trim()},dr=function(t){return function(e){return e.join(t)}};var sw=typeof Array.from=="function",uw=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",gw=typeof String.prototype.fromCodePoint=="function",cw=typeof String.prototype.codePointAt=="function";const _w=function(t){return cw?function(e){return e.codePointAt(0)}:t},fw=function(t){return gw?String.fromCodePoint:t},lw=function(t){return function(e){return uw?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)}},dw=function(t){return function(e){return sw?function(n){return Array.from(n,e)}:t}},qs=t=>{const e=In(t);if(e===0)return y;if(e===1)return T("Just",{head:Xr(Sa(0)(t)),tail:""});const n=Xr(Sa(1)(t)),r=Xr(Sa(0)(t));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?T("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:Qi(2)(t)}):T("Just",{head:r,tail:Qi(1)(t)})},hw=t=>{const e=qs(t);return e.tag==="Just"?T("Just",E(e._1.head,e._1.tail)):y},pw=t=>un.unfoldr(hw)(t),Kf=_w(t=>{const e=Xr(Sa(0)(t));if(55296<=e&&e<=56319&&In(t)>1){const n=Xr(Sa(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),_n=dw(pw)(Kf),mw=t=>_n(t).length,Jc=t=>An(t>=0&&t<=65535?Uf(t):t<0?"\0":"\uFFFF"),yw=fw(t=>t<=65535?Jc(t):Jc(Lr(t-65536|0,1024)+55296|0)+Jc(fo(t-65536|0)(1024)+56320|0)),Yf=t=>e=>{if(t<1)return"";const n=qs(e);return n.tag==="Just"?yw(n._1.head)+Yf(t-1|0)(n._1.tail):e},Ve=lw(Yf),xw=t=>e=>e===""?y:T("Just",Kf(e)),Xf=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Vs=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Zf=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},qi=t=>e=>Xf(t.w/Vs(1e-6)(e.w))(t.h/Vs(1e-6)(e.h)),jf=t=>e=>n=>r=>n<e?t+e/2:Zf(t+e-n/2)(t+n/2)(r),tl=t=>e=>n=>r=>n>=e?t+e/2:Zf(t+n/2)(t+e-n/2)(r),el=t=>e=>n=>({x:tl(t.x)(t.w)(e.w)(n.x),y:tl(t.y)(t.h)(e.h)(n.y)}),nl=t=>e=>n=>({x:jf(t.x)(t.w)(e.w)(n.x),y:jf(t.y)(t.h)(e.h)(n.y)}),Vi=t=>{const e=t.visibleBounds.tag==="Just"?T("Just",{x:t.visibleBounds._1.x-t.padding,y:t.visibleBounds._1.y-t.padding,w:t.visibleBounds._1.w+2*t.padding,h:t.visibleBounds._1.h+2*t.padding}):y,n=e.tag==="Just"?T("Just",qi(t.frameAtUnitZoom)(e._1)):y,r=t.fallbackActionBounds.tag==="Just"?T("Just",{x:t.fallbackActionBounds._1.x-t.padding,y:t.fallbackActionBounds._1.y-t.padding,w:t.fallbackActionBounds._1.w+2*t.padding,h:t.fallbackActionBounds._1.h+2*t.padding}):y,o=Vs(1e-6)(t.zoomCap),i=(()=>{if(n.tag==="Nothing")return!1;if(n.tag==="Just")return n._1>=o;c()})(),a=t.actionBounds.tag==="Just"?T("Just",{x:t.actionBounds._1.x-t.padding,y:t.actionBounds._1.y-t.padding,w:t.actionBounds._1.w+2*t.padding,h:t.actionBounds._1.h+2*t.padding}):y,s=a.tag==="Just"&&qi(t.frameAtUnitZoom)(a._1)>=o,u=(()=>{if(e.tag==="Nothing")return t.worldBounds;if(e.tag==="Just")return e._1;c()})(),g=(()=>{if(r.tag==="Just")return r._1;if(r.tag==="Nothing"){if(a.tag==="Nothing")return u;if(a.tag==="Just")return a._1}c()})(),_=(()=>{if(i){if(e.tag==="Nothing")return t.worldBounds;if(e.tag==="Just")return e._1;c()}if(s){if(a.tag==="Nothing")return g;if(a.tag==="Just")return a._1;c()}return g})(),f=(()=>{if(i){if(n.tag==="Nothing")return o;if(n.tag==="Just")return n._1;c()}return Xf(o)(qi(t.frameAtUnitZoom)(_))})(),l={w:t.frameAtUnitZoom.w/f,h:t.frameAtUnitZoom.h/f};return{center:el(t.worldBounds)(l)(i||s?{x:_.x+_.w/2,y:_.y+_.h/2}:nl(_)(l)((()=>{const d={x:_.x+_.w/2,y:_.y+_.h/2};if(t.actionGuideBounds.tag==="Nothing")return d;if(t.actionGuideBounds.tag==="Just")return{x:t.actionGuideBounds._1.x+t.actionGuideBounds._1.w/2,y:t.actionGuideBounds._1.y+t.actionGuideBounds._1.h/2};c()})())),zoom:f}},Ui=t=>{const e=(()=>{if(t.bounds.tag==="Nothing")return t.worldBounds;if(t.bounds.tag==="Just")return{x:t.bounds._1.x-t.padding,y:t.bounds._1.y-t.padding,w:t.bounds._1.w+2*t.padding,h:t.bounds._1.h+2*t.padding};c()})(),n=qi(t.frameAtUnitZoom)(e),r=Vs(1e-6)(t.zoomFloor),o=n>=r,i=o?n:r,a={w:t.frameAtUnitZoom.w/i,h:t.frameAtUnitZoom.h/i},s=t.actionTextBounds.tag==="Just"?T("Just",{x:t.actionTextBounds._1.x-t.padding,y:t.actionTextBounds._1.y-t.padding,w:t.actionTextBounds._1.w+2*t.padding,h:t.actionTextBounds._1.h+2*t.padding}):y,u=(()=>{if(s.tag==="Nothing")return!1;if(s.tag==="Just")return qi(t.frameAtUnitZoom)(s._1)>=r;c()})(),g=t.actionGuideBounds.tag==="Just"?T("Just",{x:t.actionGuideBounds._1.x-t.padding,y:t.actionGuideBounds._1.y-t.padding,w:t.actionGuideBounds._1.w+2*t.padding,h:t.actionGuideBounds._1.h+2*t.padding}):y,_=t.actionBounds.tag==="Just"?T("Just",{x:t.actionBounds._1.x-t.padding,y:t.actionBounds._1.y-t.padding,w:t.actionBounds._1.w+2*t.padding,h:t.actionBounds._1.h+2*t.padding}):y,f=(()=>{if(_.tag==="Nothing")return!1;if(_.tag==="Just")return qi(t.frameAtUnitZoom)(_._1)>=r;c()})(),l=(()=>{if(o)return e;if(f){if(_.tag==="Nothing")return e;if(_.tag==="Just")return _._1;c()}if(u){if(s.tag==="Nothing")return e;if(s.tag==="Just")return s._1;c()}const m=(()=>{if(_.tag==="Nothing")return e;if(_.tag==="Just")return _._1;c()})(),p=(()=>{if(s.tag==="Nothing")return m;if(s.tag==="Just")return s._1;c()})();if(g.tag==="Nothing")return p;if(g.tag==="Just")return g._1;c()})(),d={x:l.x+l.w/2,y:l.y+l.h/2},h=(()=>{if(g.tag==="Nothing")return d;if(g.tag==="Just")return{x:g._1.x+g._1.w/2,y:g._1.y+g._1.h/2};c()})();return{center:el(t.worldBounds)(a)(o?{x:l.x+l.w/2,y:l.y+l.h/2}:f||u?nl(l)(a)(h):{x:l.x+l.w/2,y:l.y+l.h/2}),zoom:i}},rl=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},ol=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Us=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},il=t=>e=>rl(t.lo)(e.lo)<=ol(t.hi)(e.hi)?T("Just",{lo:rl(t.lo)(e.lo),hi:ol(t.hi)(e.hi)}):y,Tc=t=>e=>{const n=(()=>{if(e.tag==="Just")return il(t)(e._1);if(e.tag==="Nothing")return y;c()})();if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;c()},Nc={deadZoneWidth:.85,deadZoneHeight:1,hardZoneWidth:.85,hardZoneHeight:.8},al=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>_=>{const f=r<=o?{lo:n+r-o/2,hi:n+o/2}:{lo:n+o/2,hi:n+r-o/2},l=a.tag==="Just"?T("Just",a._1.size<=o?{lo:a._1.lo+a._1.size-o/2,hi:a._1.lo+o/2}:{lo:a._1.lo+o/2,hi:a._1.lo+a._1.size-o/2}):y,d=(()=>{if(a.tag==="Just")return a._1.size<=o;if(a.tag==="Nothing")return!1;c()})(),h=(()=>{if(d){if(l.tag==="Nothing")return f;if(l.tag==="Just")return l._1;c()}const w=(()=>{if(l.tag==="Just")return il(f)(l._1);if(l.tag==="Nothing")return y;c()})();if(w.tag==="Nothing")return f;if(w.tag==="Just")return w._1;c()})(),m=Tc(h)(s.tag==="Just"?T("Just",(()=>{const w=o*e;if(w<s._1.size){const J=s._1.lo+s._1.size/2;return{lo:J,hi:J}}return{lo:s._1.lo+s._1.size-w/2,hi:s._1.lo+w/2}})()):y),p=(()=>{if(a.tag==="Just")return Us(h.lo)(h.hi)(a._1.lo+a._1.size/2);if(a.tag==="Nothing")return Us(h.lo)(h.hi)(i);c()})(),x=Tc(g.tag==="Just"&&g._1.size<=o?Tc(m)(T("Just",(()=>{if(o<g._1.size){const w=g._1.lo+g._1.size/2;return{lo:w,hi:w}}return{lo:g._1.lo+g._1.size-o/2,hi:g._1.lo+o/2}})())):m)(s.tag==="Just"?T("Just",(()=>{const w=o*t;if(w<s._1.size){const J=s._1.lo+s._1.size/2;return{lo:J,hi:J}}return{lo:s._1.lo+s._1.size-w/2,hi:s._1.lo+w/2}})()):y);if(u.tag==="Just"){const w=u.tag==="Just"&&_.tag==="Just"&&xe(_._1)>.001?u._1.lo+u._1.size/2+_._1*o/6:i;return d?p:Us(x.lo)(x.hi)(w)}if(u.tag==="Nothing"){const w=s.tag==="Just"&&_.tag==="Just"&&xe(_._1)>.001?s._1.lo+s._1.size/2+_._1*o/6:i;return d?p:Us(x.lo)(x.hi)(w)}c()},bc=t=>e=>n=>r=>o=>({x:al(t.deadZoneWidth)(t.hardZoneWidth)(e.x)(e.w)(n.w)(r.x)(o.visibleBounds.tag==="Just"?T("Just",{lo:o.visibleBounds._1.x,size:o.visibleBounds._1.w}):y)(o.subject.tag==="Just"?T("Just",{lo:o.subject._1.x,size:o.subject._1.w}):y)(o.guide.tag==="Just"?T("Just",{lo:o.guide._1.x,size:o.guide._1.w}):y)(o.mustSee.tag==="Just"?T("Just",{lo:o.mustSee._1.x,size:o.mustSee._1.w}):y)(o.lookAhead.tag==="Just"?T("Just",o.lookAhead._1.x):y),y:al(t.deadZoneHeight)(t.hardZoneHeight)(e.y)(e.h)(n.h)(r.y)(o.visibleBounds.tag==="Just"?T("Just",{lo:o.visibleBounds._1.y,size:o.visibleBounds._1.h}):y)(o.subject.tag==="Just"?T("Just",{lo:o.subject._1.y,size:o.subject._1.h}):y)(o.guide.tag==="Just"?T("Just",{lo:o.guide._1.y,size:o.guide._1.h}):y)(o.mustSee.tag==="Just"?T("Just",{lo:o.mustSee._1.y,size:o.mustSee._1.h}):y)(o.lookAhead.tag==="Just"?T("Just",o.lookAhead._1.y):y)}),sl=b(ur)(0),ww=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},Rr=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ks=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},ul=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Jw=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}]},Zo=t=>e=>{const n=He(a=>s=>({a,b:s,len:(()=>{const u=s.y-a.y,g=s.x-a.x;return qe(g*g+u*u)})()}),t,Bt(1,t.length,t)),r=sl(Y(a=>a.len)(n)),o=ww(0)(r)(e*r),i=a=>s=>u=>{let g=a,_=s,f=u,l=!0,d;for(;l;){const h=g,m=_,p=f,x=It(w=>y,w=>J=>T("Just",{head:w,tail:J}),h);if(x.tag==="Nothing"){const w=t.length-1|0;if(w>=0&&w<t.length){l=!1,d=t[w];continue}l=!1,d=p;continue}if(x.tag==="Just"){if(m<=x._1.head.len){const w=x._1.head.len<=0?0:m/x._1.head.len;l=!1,d={x:x._1.head.a.x+(x._1.head.b.x-x._1.head.a.x)*w,y:x._1.head.a.y+(x._1.head.b.y-x._1.head.a.y)*w};continue}g=x._1.tail,_=m-x._1.head.len,f=p;continue}c()}return d};return 0<t.length?T("Just",i(n)(o)(t[0])):y},Tw=t=>e=>{const n=Rr(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}},Ba=t=>sl(He(e=>n=>{const r=n.y-e.y,o=n.x-e.x;return qe(o*o+r*r)},t,Bt(1,t.length,t))),Nw=t=>e=>n=>r=>o=>{const i=0<t.length?T("Just",t[0]):y,a=(()=>{if(i.tag==="Nothing")return e;if(i.tag==="Just")return i._1;c()})(),s=t.length-1|0,u=s>=0&&s<t.length?T("Just",t[s]):y,g=(()=>{if(u.tag==="Nothing")return n;if(u.tag==="Just")return u._1;c()})(),_=Rr(.05)(1-o.pre-o.post),f=r<o.pre?0:r>1-o.post?1:(r-o.pre)/_,l=g.x-n.x,d=2*(()=>{const N=g.y-n.y;return(l<0?-l:l)+(N<0?-N:N)})(),h=a.x-e.x,m=2*(()=>{const N=a.y-e.y;return(h<0?-h:h)+(N<0?-N:N)})(),p=m+Ba(t)+d,x=p<=1e-4?1:1-d/p,w=p<=1e-4?0:m/p;if(f<=w){const N=w<=1e-4?1:f/w;return{x:e.x+(a.x-e.x)*N,y:e.y+(a.y-e.y)*N}}if(f>=x){const N=x>=1?0:(f-x)/(1-x);return{x:g.x+(n.x-g.x)*N,y:g.y+(n.y-g.y)*N}}const J=Zo(t)((f-w)/Rr(1e-4)(x-w));if(J.tag==="Nothing")return a;if(J.tag==="Just")return J._1;c()},gl=t=>e=>{const n=It(r=>y,r=>o=>T("Just",{head:r,tail:o}),[...(()=>{const r=(o,i)=>{if(o.tag==="Leaf")return i;if(o.tag==="Node")return r(o._5,wt("Cons",o._4,r(o._6,i)));c()};return St(Mt(ce.foldr,r(t,A)))(Jw)})(),...kn((()=>{const r=(o,i)=>{if(o.tag==="Leaf")return i;if(o.tag==="Node")return r(o._5,wt("Cons",o._4,r(o._6,i)));c()};return Mt(ce.foldr,r(e,A))})())]);if(n.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(n.tag==="Just"){const r=b(o=>i=>({minX:Ks(o.minX)(i.x),minY:Ks(o.minY)(i.y),maxX:Rr(o.maxX)(i.x),maxY:Rr(o.maxY)(i.y)}))({minX:n._1.head.x,minY:n._1.head.y,maxX:n._1.head.x,maxY:n._1.head.y})(n._1.tail);return{x:r.minX,y:r.minY,w:r.maxX-r.minX,h:r.maxY-r.minY}}c()},vc={scale:1,tx:0,ty:0},bw=t=>e=>{const n=Rr(4)(.15*Ks(e.w)(e.h)),r=Rr(1)(t.w),o=Rr(1)(t.h),i=Rr(1)(e.w-2*n),a=Rr(1)(e.h-2*n),s=.55*Ks(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}},vw=t=>e=>(n=>r=>o=>{let i=n,a=r,s=o,u=!0,g;for(;u;){const _=i,f=a,l=s,d=It(h=>y,h=>m=>T("Just",{head:h,tail:m}),f);if(d.tag==="Nothing"){u=!1,g=l;continue}if(d.tag==="Just"){const h=ul(d._1.head)(_.interiors);if(h.tag==="Nothing"){u=!1,g=l;continue}if(h.tag==="Just"){i=h._1,a=d._1.tail,s=(()=>{const m=bw(h._1.layout.bounds)((()=>{const p=ul(d._1.head)(_.layout.nodes);if(p.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:lo};if(p.tag==="Just")return p._1;c()})());return{scale:l.scale*m.scale,tx:l.scale*m.tx+l.tx,ty:l.scale*m.ty+l.ty}})();continue}}c()}return g})(t)(e)(vc),Cw=t=>t,cl=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},Cc=t=>e=>t.width<=0||t.height<=0?e:cl(t.width/t.height)(e),tt=(t,e)=>({tag:"CatQueue",_1:t,_2:e}),Lw=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=y;continue}e=tt((i=>a=>{let s=i,u=a,g=!0,_;for(;g;){const f=s,l=u;if(l.tag==="Nil"){g=!1,_=f;continue}if(l.tag==="Cons"){s=wt("Cons",l._1,f),u=l._2;continue}c()}return _})(A)(o._2),A);continue}if(o._1.tag==="Cons"){n=!1,r=T("Just",E(o._1._1,tt(o._1._2,o._2)));continue}c()}return r},et=(t,e,n)=>({tag:t,_1:e,_2:n}),gt=et("CatNil"),kw=t=>e=>{if(t.tag==="CatNil")return e;if(e.tag==="CatNil")return t;if(t.tag==="CatCons")return et("CatCons",t._1,tt(t._2._1,wt("Cons",e,t._2._2)));c()},Sw=t=>e=>n=>{const r=o=>i=>a=>{let s=o,u=i,g=a,_=!0,f;for(;_;){const l=s,d=u,h=g;if(h.tag==="Nil"){_=!1,f=d;continue}if(h.tag==="Cons"){s=l,u=l(d)(h._1),g=h._2;continue}c()}return f};return(o=>i=>{let a=o,s=i,u=!0,g;for(;u;){const _=a,f=s,l=Lw(_);if(l.tag==="Nothing"){u=!1,g=r(d=>h=>h(d))(e)(f);continue}if(l.tag==="Just"){a=l._1._2,s=wt("Cons",t(l._1._1),f);continue}c()}return g})(n)(A)},Ew=t=>{if(t.tag==="CatNil")return y;if(t.tag==="CatCons")return T("Just",E(t._1,t._2._1.tag==="Nil"&&t._2._2.tag==="Nil"?gt:Sw(kw)(gt)(t._2)));c()},j=(t,e)=>({tag:"Free",_1:t,_2:e}),st=(t,e,n)=>({tag:t,_1:e,_2:n}),_l=t=>{let e=t,n=!0,r;for(;n;){const o=e;if(o._1.tag==="Return"){const i=Ew(o._2);if(i.tag==="Nothing"){n=!1,r=st("Return",o._1._1);continue}if(i.tag==="Just"){e=(()=>{const a=i._1._1(o._1._1);return j(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 et("CatCons",a._2._1,tt(a._2._2._1,wt("Cons",i._1._2,a._2._2._2)));c()})())})();continue}c()}if(o._1.tag==="Bind"){n=!1,r=st("Bind",o._1._1,i=>{const a=o._1._2(i);return j(a._1,(()=>{if(a._2.tag==="CatNil")return o._2;if(o._2.tag==="CatNil")return a._2;if(a._2.tag==="CatCons")return et("CatCons",a._2._1,tt(a._2._2._1,wt("Cons",o._2,a._2._2._2)));c()})())});continue}c()}return r},Rw=t=>e=>{const n=e.Monad0(),r=n.Bind1().Apply0().Functor0();return o=>e.tailRecM(i=>{const a=_l(i);if(a.tag==="Return")return r.map(B2)(n.Applicative0().pure(a._1));if(a.tag==="Bind")return r.map(zg)(o(t.map(a._2)(a._1)));c()})},Pw=t=>e=>n=>{const r=_l(n);if(r.tag==="Return")return e(r._1);if(r.tag==="Bind")return t(r._1)(r._2);c()},Lc={Applicative0:()=>Zr,Bind1:()=>fl},Gw={map:t=>e=>fl.bind(e)(n=>Zr.pure(t(n)))},fl={bind:t=>e=>j(t._1,(()=>{if(t._2.tag==="CatNil")return et("CatCons",e,tt(A,A));if(t._2.tag==="CatCons")return et("CatCons",t._2._1,tt(t._2._2._1,wt("Cons",et("CatCons",e,tt(A,A)),t._2._2._2)));c()})()),Apply0:()=>ll},ll={apply:t=>e=>{const n=r=>j(e._1,(()=>{if(e._2.tag==="CatNil")return et("CatCons",o=>Zr.pure(r(o)),tt(A,A));if(e._2.tag==="CatCons")return et("CatCons",e._2._1,tt(e._2._2._1,wt("Cons",et("CatCons",o=>Zr.pure(r(o)),tt(A,A)),e._2._2._2)));c()})());return j(t._1,(()=>{if(t._2.tag==="CatNil")return et("CatCons",n,tt(A,A));if(t._2.tag==="CatCons")return et("CatCons",t._2._1,tt(t._2._2._1,wt("Cons",et("CatCons",n,tt(A,A)),t._2._2._2)));c()})())},Functor0:()=>Gw},Zr={pure:t=>j(st("Return",t),gt),Apply0:()=>ll},mo=t=>t,Bw=t=>t,Pr=mo("RunText"),Ys=mo("RunBold"),Xs=mo("RunCode"),Zs=mo("RunCodeBold"),js=mo("RunHighlight"),tu=mo("RunBoldHighlight"),eu=mo("RunCodeHighlight"),nu=mo("RunCodeBoldHighlight"),Aw=t=>"md:"+t,Jn=t=>{const e=(()=>{const r=xr("md:")(t);if(r.tag==="Just")return!0;if(r.tag==="Nothing")return!1;c()})()?Aw:Bw,n=$i(`
|
|
3
|
-
`)((()=>{const r=
|
|
1
|
+
var lB=(function(Gg){"use strict";function y2(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 c(){throw new Error("Failed pattern match")}function Sr(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const tn=t=>e=>t,K=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}},x2={map:K},q1=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}},J2=function(t){return function(e){return{}.hasOwnProperty.call(e,t)}},w2=function(t){return function(e){return e[t]}},ue=function(t){return t.toString()},Ln=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},T2=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})+'"'},Ag=t=>t,Me=Ag("LT"),Qe=Ag("GT"),un=Ag("EQ"),T=(t,e)=>({tag:t,_1:e}),y=T("Nothing"),Yt=t=>T("Just",t),V1=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;c()},U1=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;c()},zt=(t,e)=>({tag:t,_1:e}),N2=t=>zt("Right",t),b2={map:t=>e=>{if(e.tag==="Left")return zt("Left",e._1);if(e.tag==="Right")return zt("Right",t(e._1));c()}},X1={apply:t=>e=>{if(t.tag==="Left")return zt("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return zt("Left",e._1);if(e.tag==="Right")return zt("Right",t._1(e._1))}c()},Functor0:()=>b2},v2={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>zt("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}c()},Apply0:()=>X1},C2={pure:N2,Apply0:()=>X1},K1={Applicative0:()=>C2,Bind1:()=>v2},L2=t=>t,k2={map:t=>e=>t(e)},Y1={apply:t=>e=>t(e),Functor0:()=>k2},S2={bind:t=>e=>e(t),Apply0:()=>Y1},E2={pure:L2,Apply0:()=>Y1},Xn={Applicative0:()=>E2,Bind1:()=>S2},R2=function(t){return function(){return t}},P2={apply:t=>e=>()=>{const n=t(),r=e();return Ig.pure(n(r))()},Functor0:()=>B2},Ig={pure:R2,Apply0:()=>P2},B2={map:t=>e=>()=>{const n=e();return t(n)}},Gi=(t,e)=>({tag:t,_1:e}),zg=t=>Gi("Loop",t),G2=t=>Gi("Done",t),A2={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}c()}return i};return n=>e(t(n))},Monad0:()=>Xn},I2=function(t){return function(e){return function(){return t(e())}}},z2=function(t){return function(){return t}},D2=function(t){return function(e){return function(){return e(t())()}}},F2={map:I2},M2={Applicative0:()=>Dg,Bind1:()=>Q2},Q2={bind:D2,Apply0:()=>Z1},Z1={apply:t=>e=>()=>{const n=t(),r=e();return Dg.pure(n(r))()},Functor0:()=>F2},Dg={pure:z2,Apply0:()=>Z1},W2={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"&&c()}const o=r;if(o.tag==="Done")return o._1;c()}},Monad0:()=>M2},O2=function(t){return function(e){return function(n){return function(){return t(e,n)}}}},H2=function(t,e,n,r){return n>=0&&n<r.length?t(r[n]):e},Fg=function(t){return t.length},$2=function(t,e,n){return n.length>0?t(n.pop()):e},q2=O2(function(t,e){return e.push(t)}),V2=(t,e)=>({tag:"Iterator",_1:t,_2:e}),U2=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}},X2=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}c()}},Ai=function(t){return function(e){return function(n){for(var r=e,o=n.length,i=o-1;i>=0;i--)r=t(n[i])(r);return r}}},b=function(t){return function(e){return function(n){for(var r=e,o=n.length,i=0;i<o;i++)r=t(r)(n[i]);return r}}},Mo=t=>{const e=t.Apply0();return n=>r=>n.foldr(o=>{const i=r(o);return a=>e.apply(e.Functor0().map(s=>q1)(i))(a)})(t.pure())},Ii=t=>{const e=Mo(t);return n=>{const r=e(n);return o=>i=>r(i)(o)}},K2={foldr:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(n._1)(e);c()},foldl:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(e)(n._1);c()},foldMap:t=>{const e=t.mempty;return n=>r=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return n(r._1);c()}}},Qt={foldr:Ai,foldl:b,foldMap:t=>{const e=t.mempty;return n=>Qt.foldr(r=>o=>t.Semigroup0().append(n(r))(o))(e)}},E=(t,e)=>({tag:"Tuple",_1:t,_2:e}),mn=t=>e=>E(t,e),Ts=t=>t._2,Ns=t=>t._1,Ft=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 Mg=function(t){return function(e){return t===e}};const Y2=Mg,Z2=Mg,zi=Mg,bs=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}}},Er={eq:zi},j2={eq:Z2},go={eq:Y2};var Qg=function(t){return function(e){return function(n){return function(r){return function(o){return r<o?t:r===o?e:n}}}}};const ty=Qg,ey=Qg,G={compare:Qg(Me)(un)(Qe),Eq0:()=>Er},at={compare:ey(Me)(un)(Qe),Eq0:()=>j2},ut={compare:ty(Me)(un)(Qe),Eq0:()=>go},wa=function(t){return t},ny=(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 g(_,f){switch(f-_){case 0:return a([]);case 1:return i(t)(s(u[_]));case 2:return o(i(e)(s(u[_])))(s(u[_+1]));case 3:return o(o(i(n)(s(u[_])))(s(u[_+1])))(s(u[_+2]));default:var l=_+Math.floor((f-_)/4)*2;return o(i(r)(g(_,l)))(g(l,f))}}return g(0,u.length)}}}}}})(),ry=t=>t,xr={traverse:t=>{const e=t.Apply0();return ny(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>xr.traverse(t)(ry),Functor0:()=>x2,Foldable1:()=>Qt},Ut=function(t,e){for(var n=t>e?-1:1,r=new Array(n*(e-t)+1),o=t,i=0;o!==e;)r[i++]=o,o+=n;return r[i]=o,r};var oy=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},iy=function(t,e){for(var n=[],r=0,o=0;o<t;o++)n[r++]=e;return n};const Qo=typeof Array.prototype.fill=="function"?oy:iy,Mt=(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))}})(),ay=function(t){return t.length},Bt=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},j1=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},Wo=function(t,e,n,r){for(var o=0,i=r.length;o<i;o++)if(n(r[o]))return t(o);return e},tf=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)},ef=function(t,e,n,r){if(n<0||n>=r.length)return e;var o=r.slice();return o.splice(n,1),t(o)},co=function(t,e,n,r,o){if(n<0||n>=o.length)return e;var i=o.slice();return i[n]=r,t(i)},re=function(t){return t.slice().reverse()},kn=function(t){if(t.length<=1e4)return Array.prototype.concat.apply([],t);for(var e=[],n=0,r=t.length;n<r;n++)for(var o=t[n],i=0,a=o.length;i<a;i++)e.push(o[i]);return e},_t=function(t,e){return e.filter(t)},sy=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},uy=(function(){function t(e,n,r,o,i,a){var s,u,g,_,f,l,d;for(s=i+(a-i>>1),s-i>1&&t(e,n,o,r,i,s),a-s>1&&t(e,n,o,r,s,a),u=i,g=s,_=i;u<s&&g<a;)f=o[u],l=o[g],d=n(e(f)(l)),d>0?(r[_++]=l,++g):(r[_++]=f,++u);for(;u<s;)r[_++]=o[u++];for(;g<a;)r[_++]=o[g++]}return function(e,n,r){var o;return r.length<2?r:(o=r.slice(0),t(e,n,o,r.slice(0),0,r.length),o)}})(),At=function(t,e,n){return n.slice(t,e)},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},oe=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},Wg=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Rt=t=>e=>uy(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;c()},e),gy=t=>e=>Rt(n=>r=>t.compare(e(n))(e(r))),Et=t=>e=>(()=>{const n=q2(e);return()=>{const r=[...t];return n(r)(),r}})()(),Rr=t=>{if(t.length===0)return t.length-1|0,y;const e=t.length-1|0;return e>=0&&e<t.length?T("Just",{init:At(0,t.length-1|0,t),last:t[e]}):y},cy=t=>e=>n=>t>=0&&t<n.length?co(Yt,y,t,e(n[t]),n):y,Pr=t=>e=>{const n=(r=>{let o=r,i=!0,a;for(;i;){const s=o;if(s>=0&&s<e.length){if(t(e[s])){o=s+1|0;continue}i=!1,a=T("Just",s);continue}i=!1,a=y}return a})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:At(0,n._1,e),rest:At(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};c()},Ur=t=>e=>{const n=Rt(r=>o=>t(r._2)(o._2))(Ft(mn)(e));return 0<n.length?K(Ts)(gy(ut)(Ns)((()=>{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;c()})())(o._2);(i==="LT"||i==="GT"||i!=="EQ")&&r.push(o)}return r})())):[]},_y=t=>e=>{const n=[],r=V2(o=>o>=0&&o<e.length?T("Just",e[o]):y,{value:0});return X2(r)(o=>()=>{const i=[];i.push(o),U2(t(o))(r)(i)(),n.push(i)})(),n},te=t=>e=>{const n=Wo(Yt,y,t,e);return n.tag==="Just"?T("Just",e[n._1]):y},Ta=t=>e=>_t(t,e),yn=t=>e=>n=>{const r=Wo(Yt,y,o=>t.eq(o)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;c()},vs=t=>e=>St(e)(t),ht=t=>vs(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];c()}),Na=isFinite;function Og(t,e,n,r){var o=parseFloat(t);return e(o)?n(o):r}const xe=Math.abs,fy=Math.acos,Oo=function(t){return function(e){return Math.atan2(t,e)}},Cs=Math.ceil,xn=Math.cos,_o=Math.exp,sr=Math.floor,fo=Math.log,ly=function(t){return function(e){return Math.min(t,e)}},Hg=function(t){return function(e){return Math.pow(t,e)}},Kn=Math.round,en=Math.sin,qe=Math.sqrt,dy=Math.tan,hy=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},ot=function(t){return t},py=(function(t){return function(e){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var o=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(i){if(o.test(i)){var a=parseInt(i,n);return(a|0)===a?t(a):e}else return e}}}})(Yt)(y)(10),nf=hy(Yt)(y),he=t=>{if(!Na(t))return 0;if(t>=ot(2147483647))return 2147483647;if(t<=ot(-2147483648))return-2147483648;const e=nf(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;c()},Jt=(t,e,n)=>({tag:t,_1:e,_2:n}),A=Jt("Nil"),ce={foldr:t=>e=>{const n=ce.foldl(o=>i=>t(i)(o))(e),r=(o=>i=>{let a=o,s=i,u=!0,g;for(;u;){const _=a,f=s;if(f.tag==="Nil"){u=!1,g=_;continue}if(f.tag==="Cons"){a=Jt("Cons",f._1,_),s=f._2;continue}c()}return g})(A);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}c()}return a},foldMap:t=>{const e=t.mempty;return n=>ce.foldl(r=>{const o=t.Semigroup0().append(r);return i=>o(n(i))})(e)}},my=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 g=r(u);if(t(g))return a;s=e(g)}}}}}}},yy=t=>{if(t.tag==="Just")return t._1;c()},xy={unfoldr1:my(V1)(yy)(Ns)(Ts)},Jy=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 g=e(u);a.push(n(g)),s=r(g)}}}}}}},wy=t=>{if(t.tag==="Just")return t._1;c()},gn={unfoldr:Jy(V1)(wy)(Ns)(Ts),Unfoldable10:()=>xy},ee=(t,e,n,r,o,i,a)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:a}),cn=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Ls=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),rf=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),W=ee("Leaf"),Yn=cn("IterLeaf"),Re=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return ee("Node",1,1,t,e,n,r);if(r.tag==="Node")return ee("Node",1+r._1|0,1+r._2|0,t,e,n,r);c()}if(n.tag==="Node"){if(r.tag==="Leaf")return ee("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return ee("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,t,e,n,r)}c()},_n=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?ee("Node",1,1,t,e,W,W):r.tag==="Node"&&r._1>1?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;c()})()?Re(r._5._3,r._5._4,Re(t,e,n,r._5._5),Re(r._3,r._4,r._5._6,r._6)):Re(r._3,r._4,Re(t,e,n,r._5),r._6):Re(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;c()})()?Re(r._5._3,r._5._4,Re(t,e,n,r._5._5),Re(r._3,r._4,r._5._6,r._6)):Re(r._3,r._4,Re(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;c()})()?Re(n._6._3,n._6._4,Re(n._3,n._4,n._5,n._6._5),Re(t,e,n._6._6,r)):Re(n._3,n._4,n._5,Re(t,e,n._6,r)):Re(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;c()})()?Re(n._6._3,n._6._4,Re(n._3,n._4,n._5,n._6._5),Re(t,e,n._6._6,r)):Re(n._3,n._4,n._5,Re(t,e,n._6,r)):Re(t,e,n,r);c()},Di=(t,e,n)=>{if(n.tag==="Leaf")return Ls(y,W,W);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const o=Di(t,e,n._5);return Ls(o._1,o._2,_n(n._3,n._4,o._3,n._6))}if(r==="GT"){const o=Di(t,e,n._6);return Ls(o._1,_n(n._3,n._4,n._5,o._2),o._3)}if(r==="EQ")return Ls(T("Just",n._4),n._5,n._6)}c()},of=(t,e,n,r)=>{if(r.tag==="Leaf")return rf(t,e,n);if(r.tag==="Node"){const o=of(r._3,r._4,r._5,r._6);return rf(o._1,o._2,_n(t,e,n,o._3))}c()},Fi=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=of(t._3,t._4,t._5,t._6);return _n(n._1,n._2,n._3,e)}c()},Zn=(t,e,n)=>{if(e.tag==="Leaf")return W;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=Di(t,n._3,e);return Fi(Zn(t,r._2,n._5),Zn(t,r._3,n._6))}c()},ks=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return W;if(r.tag==="Node"){const o=Di(t,r._3,n),i=ks(t,e,o._2,r._5),a=ks(t,e,o._3,r._6);if(o._1.tag==="Just")return _n(r._3,e(o._1._1)(r._4),i,a);if(o._1.tag==="Nothing")return Fi(i,a)}c()},nn=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const o=Di(t,r._3,n),i=nn(t,e,o._2,r._5),a=nn(t,e,o._3,r._6);if(o._1.tag==="Just")return _n(r._3,e(o._1._1)(r._4),i,a);if(o._1.tag==="Nothing")return _n(r._3,r._4,i,a)}c()},af=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return W;if(o.tag==="Node"){const i=t.compare(n)(o._3);if(i==="LT")return _n(o._3,o._4,r(o._5),o._6);if(i==="GT")return _n(o._3,o._4,o._5,r(o._6));if(i==="EQ"){const a=e(o._4);if(a.tag==="Nothing")return Fi(o._5,o._6);if(a.tag==="Just")return ee("Node",o._1,o._2,o._3,a._1,o._5,o._6)}}c()};return r},$g=t=>e=>{const n=r=>{if(r.tag==="Leaf")return W;if(r.tag==="Node"){const o=e(r._3)(r._4);if(o.tag==="Just")return _n(r._3,o._1,n(r._5),n(r._6));if(o.tag==="Nothing")return Fi(n(r._5),n(r._6))}c()};return n},jn=(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 g=s,_=u,f=!0,l;for(;f;){const d=g,h=_;if(h.tag==="Leaf"){f=!1,l=d;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){g=cn("IterEmit",h._3,h._4,d),_=h._5;continue}g=cn("IterEmit",h._3,h._4,cn("IterNode",h._6,d)),_=h._5;continue}c()}return l})(a._2)(a._1);continue}c()}return i})((t,e,n)=>T("Just",E(E(t,e),n)))(t=>y),Wt=t=>e=>n=>r=>{const o=i=>{if(i.tag==="Leaf")return ee("Node",1,1,n,r,W,W);if(i.tag==="Node"){const a=t.compare(n)(i._3);if(a==="LT")return _n(i._3,i._4,o(i._5),i._6);if(a==="GT")return _n(i._3,i._4,i._5,o(i._6));if(a==="EQ")return ee("Node",i._1,i._2,n,e(i._4)(r),i._5,i._6)}c()};return o},it=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return ee("Node",1,1,e,n,W,W);if(o.tag==="Node"){const i=t.compare(e)(o._3);if(i==="LT")return _n(o._3,o._4,r(o._5),o._6);if(i==="GT")return _n(o._3,o._4,o._5,r(o._6));if(i==="EQ")return ee("Node",o._1,o._2,e,n,o._5,o._6)}c()};return r},fe=t=>e=>e.foldl(n=>r=>it(t)(r._1)(r._2)(n))(W),Mi=t=>e=>{const n=r=>{if(r.tag==="Leaf")return W;if(r.tag==="Node"){const o=t.compare(e)(r._3);if(o==="LT")return _n(r._3,r._4,n(r._5),r._6);if(o==="GT")return _n(r._3,r._4,r._5,n(r._6));if(o==="EQ")return Fi(r._5,r._6)}c()};return n},sf=t=>{const e=t.compare;return n=>r=>o=>{const i=Di(e,r,o),a=n(i._1);if(a.tag==="Nothing")return Fi(i._2,i._3);if(a.tag==="Just")return _n(r,a._1,i._2,i._3);c()}},ve=function(t){return function(e){return t+e|0}},ur=function(t){return function(e){return t+e}},lo=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},Ty=function(t){return function(e){return t+e}},Je=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},Ny={append:Ty},by={append:Je},uf={mempty:"",Semigroup0:()=>Ny},vy={mempty:[],Semigroup0:()=>by},ba=null;function Gn(t,e,n){return t==null?e:n(t)}function fB(t){return t}function qg(t){return function(e){return function(n){return t.apply(n,[e])}}}const Cy=qg(Number.prototype.toPrecision),Ly=qg(Number.prototype.toFixed),ky=qg(Number.prototype.toExponential),Ho=(t,e)=>({tag:t,_1:e}),$o=t=>e=>n=>{const r=ut.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=ut.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},qo=t=>{if(t.tag==="Precision")return Cy(t._1);if(t.tag==="Fixed")return Ly(t._1);if(t.tag==="Exponential")return ky(t._1);c()},gf=function(t){return function(){console.log(t)}};function cf(t){return function(){return t.getContext("2d")}}function _f(t){return function(){return t.width}}function ff(t){return function(){return t.height}}function lf(t){return function(e){return function(){t.width=e}}}function df(t){return function(e){return function(){t.height=e}}}function Ss(t){return function(e){return function(){t.lineWidth=e}}}function Sy(t){return function(e){return function(){t.setLineDash(e)}}}function hf(t){return function(e){return function(){t.fillStyle=e}}}function pf(t){return function(e){return function(){t.strokeStyle=e}}}function Vg(t){return function(e){return function(){t.lineCap=e}}}function Ug(t){return function(e){return function(){t.lineJoin=e}}}function Ey(t){return function(e){return function(){t.globalCompositeOperation=e}}}function Ry(t){return function(e){return function(){t.globalAlpha=e}}}function mf(t){return function(){t.beginPath()}}function Xg(t){return function(){t.stroke()}}function Kg(t){return function(){t.fill()}}function Py(t){return function(){t.clip()}}function va(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function yf(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function xf(t){return function(){t.closePath()}}function By(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function Gy(t){return function(e){return function(){t.strokeRect(e.x,e.y,e.width,e.height)}}}function Ay(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function Ca(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function Jf(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function Iy(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function zy(t){return function(e){return function(){t.textAlign=e}}}function Dy(t){return function(e){return function(){t.textBaseline=e}}}function wf(t){return function(e){return function(){t.font=e}}}function Tf(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function gr(t){return function(){t.save()}}function cr(t){return function(){t.restore()}}function La(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function Fy(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const Nf=t=>t,Yg=t=>t,Zg=t=>t,jg=t=>t,Es=t=>t,My=Es("BaselineTop"),Qy=Es("BaselineMiddle"),Wy=Es("BaselineAlphabetic"),Oy=Es("BaselineBottom"),Hy=jg("AlignLeft"),$y=jg("AlignRight"),qy=jg("AlignCenter"),tc=Zg("BevelJoin"),ec=Zg("RoundJoin"),nc=Zg("MiterJoin"),rc=Yg("Round"),oc=Yg("Square"),ic=Yg("Butt"),Vy=Nf("SourceOver"),Uy=Nf("Difference"),Xy=t=>e=>Dy(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";c()})()),Ky=t=>e=>zy(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";c()})()),ac=t=>e=>{if(e==="BevelJoin")return Ug(t)("bevel");if(e==="RoundJoin")return Ug(t)("round");if(e==="MiterJoin")return Ug(t)("miter");c()},sc=t=>e=>{if(e==="Round")return Vg(t)("round");if(e==="Square")return Vg(t)("square");if(e==="Butt")return Vg(t)("butt");c()},bf=t=>e=>Ey(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";c()})()),vf={foldrWithIndex:t=>e=>{const n=Ai(o=>{const i=o._1,a=o._2;return s=>t(i)(a)(s)})(e),r=Ft(mn);return o=>n(r(o))},foldlWithIndex:t=>e=>{const n=b(o=>i=>t(i._1)(o)(i._2))(e),r=Ft(mn);return o=>n(r(o))},foldMapWithIndex:t=>{const e=t.mempty;return n=>vf.foldrWithIndex(r=>o=>i=>t.Semigroup0().append(n(r)(o))(i))(e)},Foldable0:()=>Qt},Yy=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Zy=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Rs=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},jy=t=>e=>n=>r=>n<=0||r<=0||e.bounds.w<=0||e.bounds.h<=0?1:t?Yy(e.bounds.w/n)(e.bounds.h/r):Zy(e.bounds.w/n)(e.bounds.h/r),Cf=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;if(t.widthPx<=0||t.heightPx<=0){const a=1/Rs(.05)(1)(e);return{w:n.w*a,h:n.h*a}}if(r>o){const a=1/Rs(.05)(1)(e);return{w:n.h*r*a,h:n.h*a}}const i=1/Rs(.05)(1)(e);return{w:n.w*i,h:n.w/r*i}},Lf=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:Rs(i)(a)(u)},kf=t=>e=>n=>r=>({x:Lf(t.bounds.x)(t.bounds.w)(e.x)(e.w)(n),y:Lf(t.bounds.y)(t.bounds.h)(e.y)(e.h)(r)}),ka=t=>e=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:jy(t)(e)(n.w)(n.h)}),Sf=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=Cf(e)(.65)(o),a=kf(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:ka(e.widthPx>0&&e.heightPx>0)(n)(s)}},tx=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=Cf(e)(1)(s),g=kf(n)(s)(u.w)(u.h),_={x:g.x-u.w/2,y:g.y-u.h/2,w:u.w,h:u.h};return{footprint:i,viewport:_,camera:ka(e.widthPx>0&&e.heightPx>0)(n)(_)}},ex=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;return t.widthPx<=0||t.heightPx<=0?ka(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?ka(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}})()):ka(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}})())},Jn={foldr:t=>e=>{const n=ce.foldr(t)(e);return r=>n((()=>{const o=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return o(i._5,Jt("Cons",i._3,o(i._6,a)));c()};return o(r,A)})())}},nx=t=>{const e={append:(()=>{const n=t.compare;return r=>o=>nn(n,tn,r,o)})()};return{mempty:W,Semigroup0:()=>e}},Sa=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},An=function(t){return t.join("")},tr=function(t){return t.split("")},In=function(t){return t},zn=function(t){return t.length},Ef=function(t){return function(e){return e.substr(0,t)}},Qi=function(t){return function(e){return e.substring(t)}},Rf=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},rx=t=>e=>{const n=Rf(zn(e)-zn(t)|0)(e);return n.after===t?T("Just",n.before):y},Jr=t=>e=>{const n=Rf(zn(t))(e);return n.before===t?T("Just",n.after):y},ox=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},ix=function(t){return t()},ax=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},sx=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},Vo=t=>BigInt(t),ux=t=>Number(t),Ps=t=>e=>t+e,Bs=t=>e=>t*e,uc=t=>e=>t-e,Pf=0n,Gs=1n,Bf=t=>e=>t^e,Ea=t=>e=>t&e,gc=t=>e=>t<<e,cc=t=>e=>t>>e,gx=t=>e=>t==e,cx=t=>e=>t===e?0:t>e?1:-1,_x={eq:gx},Gf={compare:t=>e=>{const n=cx(t)(e);return n===1?Qe:n===0?un:Me},Eq0:()=>_x},fx=ax(Yt)(y),lx=sx(Yt)(y),Af=function(t){throw new Error(t)},If=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=at.compare(e._1)(n._1);return r==="LT"?Me:r==="GT"?Qe:at.compare(e._2)(n._2)},Eq0:()=>t}})(),dx=t=>e=>xe(t._1-e._1)+xe(t._2-e._2),Uo=t=>t,As=t=>t,Ie=As("North"),ze=As("South"),Xr=As("East"),Kr=As("West"),ho=Uo("Rectangle"),hx=Uo("Cylinder"),px=Uo("Parallelogram"),mx=Uo("Diamond"),yx=Uo("Ellipse"),xx=Uo("Document"),Jx=Uo("Cloud"),zf=t=>t,wx=(t,e)=>({tag:t,_1:e}),_c=t=>t,Wi=(t,e)=>({tag:t,_1:e}),fc=(t,e)=>({tag:t,_1:e}),Ra=_c("Animated"),Tx=_c("StaticStill"),Nx=_c("TitleCard"),bx=fc("First"),Df=zf("Forward"),Ff=zf("Backward"),vx=Wi("ExitNode"),Mf=fe(G)(Qt),Cx=t=>Ai(e=>n=>({nodes:nn(G.compare,tn,e.nodes,n.nodes),edges:nn(G.compare,tn,e.edges,n.edges)}))({nodes:W,edges:W})(t.keyframes),Lx=t=>e=>({entering:{nodes:Zn(G.compare,e.nodes,t.nodes),edges:Zn(G.compare,e.edges,t.edges)},leaving:{nodes:Zn(G.compare,t.nodes,e.nodes),edges:Zn(G.compare,t.edges,e.edges)},surviving:{nodes:ks(G.compare,tn,t.nodes,e.nodes),edges:ks(G.compare,tn,t.edges,e.edges)}}),Is=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Oi=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},zs=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},lc=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=G.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}}c()}return o},kx=b(t=>e=>it(G)(e)()(t))(W),Sx=b(t=>e=>it(G)(e)()(t))(W),Ex=(()=>{const t=gn.unfoldr(jn);return e=>t(cn("IterNode",e,Yn))})(),Qf=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Wf=fe(G)(Qt),Pa=t=>{const e=Bt(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=b(r=>o=>({minX:Is(r.minX)(o.x),minY:Is(r.minY)(o.y),maxX:Oi(r.maxX)(o.x),maxY:Oi(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}}c()},Rx=t=>e=>n=>kx(St(Mt(Jn.foldr,n))(r=>{const o=zs(r)(t);if(o.tag==="Just")return _t(i=>!lc(i)(e),[o._1.source,o._1.target]);if(o.tag==="Nothing")return[];c()})),Px=t=>t.kind.tag==="SendToken"?T("Just",E(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):y,Bx=t=>t.tag==="DataFlow"?ht(Px)(t._1.events):[],Gx=t=>e=>Sx(ht(n=>lc(n._2.source)(e)||lc(n._2.target)(e)?T("Just",n._1):y)(Ex(t))),ae=t=>{const e=Bt(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=b(r=>o=>({minX:Is(r.minX)(o.x),minY:Is(r.minY)(o.y),maxX:Oi(r.maxX)(o.x+o.w),maxY:Oi(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}}c()},dc=t=>e=>n=>{if(n.tag==="Leaf")return t.bounds;const r=Gx(e)(n),o=[...ht(i=>{const a=Qf(i)(t.nodes);return a.tag==="Just"?T("Just",{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}):y})(Mt(Jn.foldr,nn(G.compare,tn,n,Rx(e)(n)(r)))),...ht(i=>{const a=zs(i)(t.edges);return a.tag==="Just"?T("Just",Pa(a._1)):y})(Mt(Jn.foldr,r))];return o.length===0?t.bounds:ae(o)},Xo=t=>e=>n=>{const r=[...ht(o=>o)([(()=>{const o=zs(n)(t.edges);return o.tag==="Just"?T("Just",Pa(o._1)):y})()]),...(()=>{const o=zs(n)(e);if(o.tag==="Just")return ht(i=>{const a=Qf(i)(t.nodes);return a.tag==="Just"?T("Just",{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}):y})([o._1.source,o._1.target]);if(o.tag==="Nothing")return[];c()})()];return r.length===0?dc(t)(e)(W):ae(r)},_r=t=>e=>{const n=t.bounds.w/Oi(1e-4)(e.zoom),r=t.bounds.h/Oi(1e-4)(e.zoom);return{x:e.center.x-n/2,y:e.center.y-r/2,w:n,h:r}},Ax=t=>nn(G.compare,tn,Wf(K(e=>E(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),Wf(St(t.scenes)(Bx))),hc=t=>e=>n=>r=>{if(e<=0)return r;if(t<=0)return{position:r.position+r.velocity*e,velocity:r.velocity};const o=r.velocity-n.velocity,i=r.position-n.position,a=_o(-t*e),s=o+t*i;return{position:n.position+n.velocity*e+(i+s*e)*a,velocity:n.velocity+(o-t*s*e)*a}},pc=t=>t,Ix=t=>t,mc=pc("Linear"),fr=pc("EaseInOutQuad"),zx=pc("SpringBouncy"),Ko=t=>e=>n=>{const r=qe(1-e*e),o=t*r;return 1-_o(-e*t*n)*(xn(o*n)+e/r*en(o*n))},Dx=t=>{const e=at.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;c()})(),r=at.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;c()},Hi=t=>e=>(()=>{if(t==="Linear")return Ix;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-Hg(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*_o(-6*n);if(t==="SpringBouncy")return Ko(6)(.7);c()})()(Dx(e)),Ds=t=>t,Fs=(t,e)=>({tag:t,_1:e}),Of=t=>t,ke=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ms=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},Qs=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Fx=t=>e=>{const n=ut.compare(t._1)(e._1);return n==="LT"?Me:n==="GT"?Qe:at.compare(t._2)(e._2)},Mx=Of("Hold"),Qx=Of("Gap"),Wx=Fs("LinearLerp"),Yo=Fs("LogLerp"),po=Fs("ComposedLogLerp"),Hf=Fs("StationaryShot"),Ws=Ds("Overview"),$f=Ds("DiveHome"),mo=Ds("DiveTransition"),Ox=Ds("ActionFocus"),Hx={eq:t=>e=>t.tag==="LinearLerp"?e.tag==="LinearLerp":t.tag==="LogLerp"?e.tag==="LogLerp":t.tag==="ComposedLogLerp"?e.tag==="ComposedLogLerp":t.tag==="StationaryShot"?e.tag==="StationaryShot":t.tag==="SpringInterp"&&e.tag==="SpringInterp"&&t._1.frequency===e._1.frequency&&t._1.initialVelocity.center.x===e._1.initialVelocity.center.x&&t._1.initialVelocity.center.y===e._1.initialVelocity.center.y&&t._1.initialVelocity.zoomLog===e._1.initialVelocity.zoomLog&&t._1.target.center.x===e._1.target.center.x&&t._1.target.center.y===e._1.target.center.y&&t._1.target.zoom===e._1.target.zoom&&t._1.targetVelocity.center.x===e._1.targetVelocity.center.x&&t._1.targetVelocity.center.y===e._1.targetVelocity.center.y&&t._1.targetVelocity.zoomLog===e._1.targetVelocity.zoomLog},Os={center:{x:0,y:0},zoomLog:0},qf=t=>e=>n=>{const r=t.widthPx>0&&t.heightPx>0,o=t.widthPx/ke(1e-6)(t.heightPx),i=e.bounds.w/ke(1e-6)(n.zoom),a=e.bounds.h/ke(1e-6)(n.zoom),s=i/ke(1e-6)(a),u=r&&o<s?i/o:a,g=r&&o>s?a*o:i;return{x:n.center.x-g/2,y:n.center.y-u/2,w:g,h:u}},$x=t=>({startT:t.startT,endT:t.endT,fromCam:t.fromCam,toCam:t.toCam,easing:t.easing,interp:t.interp,intent:t.intent}),qx=b(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:Et(t)(e)})([]),Hs=t=>e=>n=>{const r=Ms(0)(1)((n-t)/ke(1e-6)(e-t));return r*r*r*(r*(r*6-15)+10)},Vf=t=>e=>n=>r=>o=>{const i=xe(fo(ke(1e-6)(o.zoom))-fo(ke(1e-6)(r.zoom))),a=qf(e)(n)({...r,zoom:ke(ke(1e-6)(r.zoom))(ke(1e-6)(o.zoom))}),s=(o.center.y-r.center.y)*e.heightPx/ke(1e-6)(a.h),u=(o.center.x-r.center.x)*e.widthPx/ke(1e-6)(a.w),g=qe(u*u+s*s);return ke(t.minTransition)(ke(t.panSpeed<=0?t.minTransition:2*g/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:2*i/t.zoomSpeed))},Vx=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})()})()})()},Ux=t=>e=>t.tag==="Just"?e.tag==="Just"&&Vx(t._1)(e._1):t.tag==="Nothing"&&e.tag==="Nothing",yc=t=>e=>n=>r=>({center:{x:r.center.x*n.scale+n.tx,y:r.center.y*n.scale+n.ty},zoom:r.zoom*t.bounds.w/ke(1e-6)(n.scale*e.bounds.w)}),$s=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:_o((()=>{const o=fo(ke(1e-6)(t.zoom));return o+(fo(ke(1e-6)(e.zoom))-o)*r})())}),Xx=t=>b(e=>n=>{if(n.endT>t)return e;if(e.tag==="Nothing")return T("Just",n);if(e.tag==="Just")return n.endT>e._1.endT?T("Just",n):T("Just",e._1);c()})(y),Kx=t=>e=>n=>r=>{if(t<=0)return r;const o=_o(-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:_o((()=>{const i=fo(ke(1e-6)(r.zoom));return i+(fo(ke(1e-6)(n.zoom))-i)*o})())}},xc=t=>e=>n=>e.zoom>=t.zoom?Hs(.3)(1)(n):Hs(0)(.7)(n),Yx={padding:24,easing:fr,minimumReadableLabelPx:12,minimumVisibleLabelPx:5,labelBasePx:11,panSpeed:420,zoomSpeed:1.4,minTransition:.25,maxTransition:.6,cameraDecay:0},Zo=t=>e=>n=>r=>o=>{const i=qf(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},Zx=t=>e=>n=>r=>o=>vf.foldlWithIndex(i=>a=>s=>{const u=(()=>{if(s.kind==="Hold"){const g=(()=>{if(i===0)return s.toCam;if(s.focus.tag==="Just"){if(s.intent==="ActionFocus")return(e.widthPx<=0||e.heightPx<=0)&&Zo(t)(e)(n)(a.prev)(s.focus._1)||a.prev.zoom>=s.toCam.zoom*.995&&Zo(t)(e)(n)(a.prev)(s.focus._1)?a.prev:Zo(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 _=n.bounds.w/ke(1e-6)(s.toCam.zoom);if(_<=0)return s.toCam.center.x;const f=s.focus._1.x+s.focus._1.w/2,l=e.widthPx<=0?0:Qs(_/4)(6*_/e.widthPx),d=a.prev.center.x+_/2-l,h=f<a.prev.center.x-_/2+l?f-l+_/2:f>d?f+l-_/2:a.prev.center.x;return _>=n.bounds.w?n.bounds.x+n.bounds.w/2:Ms(n.bounds.x+_/2)(n.bounds.x+n.bounds.w-_/2)(h)})()}};if(Zo(t)(e)(n)(a.prev)(s.focus._1))return a.prev;if(Zo(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:g,toCam:g,easing:s.easing,interp:s.stationary?Hf:Wx,focus:s.focus,intent:s.intent}}if(s.kind==="Gap")return{startT:s.startT,endT:s.endT,fromCam:a.prev,toCam:(()=>{const g=i+1|0,_=Wo(Yt,y,f=>f.kind==="Hold",g<1?o:At(g,o.length,o));if(_.tag==="Just"){const f=(i+1|0)+_._1|0;return f>=0&&f<o.length?(()=>{if(o[f].focus.tag==="Just")return Zo(t)(e)(n)(a.prev)(o[f].focus._1);if(o[f].focus.tag==="Nothing")return!1;c()})()?a.prev:o[f].fromCam:a.prev}if(_.tag==="Nothing")return a.prev;c()})(),easing:s.easing,interp:Yo,focus:y,intent:s.intent};c()})();return{acc:Et(a.acc)(u),prev:u.toCam}})({acc:[],prev:r})(o).acc,jx=t=>e=>n=>r=>o=>i=>{const a=(u,g)=>Qs(Vf(t)(e)(n)(u.toCam)(g.toCam))(u.endT-u.startT),s=b(u=>g=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:T("Just",g)};if(u.pending.tag==="Just"){if(!(g.fromCam.zoom===g.toCam.zoom&&g.fromCam.center.x===g.toCam.center.x&&g.fromCam.center.y===g.toCam.center.y)||(()=>{if(g.focus.tag==="Just")return Zo(t)(e)(n)(u.pending._1.toCam)(g.focus._1);if(g.focus.tag==="Nothing")return!1;c()})()||(()=>{const _=u.pending._1.toCam.center.x-g.toCam.center.x;return(_<0?-_<8:_<8)&&(()=>{const f=u.pending._1.toCam.center.y-g.toCam.center.y;return(f<0?-f<8:f<8)&&(()=>{const l=u.pending._1.toCam.zoom-g.toCam.zoom;return l<0?-l<.08:l<.08})()})()})()||a(u.pending._1,g)<=0)return{acc:Et(u.acc)(u.pending._1),pending:T("Just",g)};if((()=>{const _=g.startT;return oe(f=>xe(f-_)<1e-4,o)})()){const _={startT:g.startT,endT:g.startT+Qs(Vf(t)(e)(n)(u.pending._1.toCam)(g.toCam))(g.endT-g.startT),fromCam:u.pending._1.toCam,toCam:g.toCam,easing:g.easing,interp:Yo,focus:g.focus,intent:g.intent},f={...g,startT:_.endT,fromCam:g.toCam};return f.startT<f.endT?{acc:Et(Et(u.acc)(u.pending._1))(_),pending:T("Just",f)}:{acc:Et(u.acc)(u.pending._1),pending:T("Just",_)}}return{acc:Et(Et(u.acc)({...u.pending._1,endT:g.startT-a(u.pending._1,g)}))({startT:g.startT-a(u.pending._1,g),endT:g.startT,fromCam:u.pending._1.toCam,toCam:g.toCam,easing:g.easing,interp:Yo,focus:g.focus,intent:g.intent}),pending:T("Just",g)}}c()})({acc:[],pending:y})(i);if(s.pending.tag==="Nothing")return s.acc;if(s.pending.tag==="Just")return Et(s.acc)(s.pending._1);c()},tJ=t=>e=>n=>{const r=e.w+n*2,o=e.h+n*2;return r<=0||o<=0||t.bounds.w<=0||t.bounds.h<=0?1:Qs(t.bounds.w/r)(t.bounds.h/o)},eJ=t=>e=>n=>e.zoom>=t.zoom?$s(t)(e)(Hs(0)(.45)(n))(xc(t)(e)(n)):$s(t)(e)(Hs(.55)(1)(n))(xc(t)(e)(n)),nJ=t=>e=>{if(t.tag==="Just"){if(e.tag==="Just")return T("Just",ae([t._1,e._1]));if(e.tag==="Nothing")return T("Just",t._1);c()}if(t.tag==="Nothing"){if(e.tag==="Just")return T("Just",e._1);if(e.tag==="Nothing")return y}c()},rJ=b(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?T("Just",t[n]):y;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.toCam.zoom===e.toCam.zoom&&r._1.toCam.center.x===e.toCam.center.x&&r._1.toCam.center.y===e.toCam.center.y?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":!(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")&&Ux(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})()})()})()?Et((()=>{const o=t.length-1|0;return o<1?[]:At(0,o,t)})())({...r._1,endT:e.endT,focus:nJ(r._1.focus)(e.focus)}):Et(t)(e)})([]),oJ=t=>{const e=Rt(n=>r=>Fx(E((()=>{if(r.intent==="DiveTransition")return 3;if(r.intent==="ActionFocus")return 2;if(r.intent==="DiveHome")return 1;if(r.intent==="Overview")return 0;c()})(),r.startT))(E((()=>{if(n.intent==="DiveTransition")return 3;if(n.intent==="ActionFocus")return 2;if(n.intent==="DiveHome")return 1;if(n.intent==="Overview")return 0;c()})(),n.startT)))(t);return 0<e.length?T("Just",e[0]):y},iJ=t=>e=>{const n=e.endT<=e.startT?1:(t-e.startT)/(e.endT-e.startT),r=Hi(e.easing)(Ms(0)(1)(n));if(e.interp.tag==="SpringInterp"){const o=Ms(0)(ke(0)(e.endT-e.startT))(t-e.startT),i=hc(e.interp._1.frequency)(o)({position:e.interp._1.target.center.x,velocity:e.interp._1.targetVelocity.center.x})({position:e.fromCam.center.x,velocity:e.interp._1.initialVelocity.center.x}),a=hc(e.interp._1.frequency)(o)({position:e.interp._1.target.center.y,velocity:e.interp._1.targetVelocity.center.y})({position:e.fromCam.center.y,velocity:e.interp._1.initialVelocity.center.y}),s=hc(e.interp._1.frequency)(o)({position:fo(ke(1e-6)(e.interp._1.target.zoom)),velocity:e.interp._1.targetVelocity.zoomLog})({position:fo(ke(1e-6)(e.fromCam.zoom)),velocity:e.interp._1.initialVelocity.zoomLog});return{camera:{center:{x:i.position,y:a.position},zoom:_o(s.position)},velocity:{center:{x:i.velocity,y:a.velocity},zoomLog:s.velocity}}}if(e.interp.tag==="LinearLerp")return{camera:{center:{x:e.fromCam.center.x+(e.toCam.center.x-e.fromCam.center.x)*r,y:e.fromCam.center.y+(e.toCam.center.y-e.fromCam.center.y)*r},zoom:e.fromCam.zoom+(e.toCam.zoom-e.fromCam.zoom)*r},velocity:Os};if(e.interp.tag==="LogLerp")return{camera:$s(e.fromCam)(e.toCam)(r)(r),velocity:Os};if(e.interp.tag==="ComposedLogLerp")return{camera:eJ(e.fromCam)(e.toCam)(n),velocity:Os};if(e.interp.tag==="StationaryShot")return{camera:$s(e.fromCam)(e.toCam)(r)(r),velocity:Os};c()},Jc=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:ke(r)(tJ(e)(n)(t.padding))}),aJ=t=>e=>n=>r=>o=>i=>{const a=Jc(t)(n)(n.bounds)(0),s=_t(u=>u>=0&&u<=r,qx(Rt(at.compare)([0,r,...o,...St(i)(u=>[u.startT,u.endT])])));return K($x)(jx(t)(e)(n)(a)(o)(rJ(Zx(t)(e)(n)(a)(ht(u=>{const g=(u._1+u._2)/2,_=b(d=>h=>h.startT>g||g>=h.endT?d:h.priority>d.topPriority?{topPriority:h.priority,bboxes:[h.bbox],actionActive:d.actionActive||h.priority>=1,continuous:h.continuous,stationary:h.stationary}:h.priority===d.topPriority?{...d,bboxes:Et(d.bboxes)(h.bbox),actionActive:d.actionActive||h.priority>=1,continuous:d.continuous||h.continuous,stationary:d.stationary||h.stationary}:{...d,actionActive:d.actionActive||h.priority>=1})({topPriority:0,bboxes:[],actionActive:!1,continuous:!1,stationary:!1})(i);if(u._2<=u._1)return y;if(_.bboxes.length===0)return T("Just",{kind:Qx,startT:u._1,endT:u._2,fromCam:a,toCam:a,easing:t.easing,focus:y,stationary:!1,intent:Ws});const f=ae(_.bboxes),l=_.actionActive?Sf(t)(e)(n)(f).camera:Jc(t)(n)(f)(0);return T("Just",{kind:Mx,startT:u._1,endT:u._2,fromCam:l,toCam:l,easing:_.continuous?mc:t.easing,focus:T("Just",f),intent:_.actionActive?Ox:Ws,stationary:_.stationary})})(We(mn,s,At(1,s.length,s)))))))},jo=t=>e=>n=>r=>{const o=oJ(_t(i=>r>=i.startT&&r<i.endT,n));if(o.tag==="Just")return{camera:iJ(r)(o._1).camera,intent:o._1.intent};if(o.tag==="Nothing"){const i=Xx(r)(n);if(i.tag==="Just")return{camera:i._1.toCam,intent:i._1.intent};if(i.tag==="Nothing")return{camera:(()=>{const a=Jc(t)(e)(e.bounds)(0);return 0<n.length?n[0].fromCam:a})(),intent:0<n.length?n[0].intent:Ws}}c()};function Yr(t){return t.charCodeAt(0)}function Uf(t){return String.fromCharCode(t)}const lr=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},$i=function(t){return function(e){return e.split(t)}},Ba=function(t){return t.trim()},dr=function(t){return function(e){return e.join(t)}};var sJ=typeof Array.from=="function",uJ=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",gJ=typeof String.prototype.fromCodePoint=="function",cJ=typeof String.prototype.codePointAt=="function";const _J=function(t){return cJ?function(e){return e.codePointAt(0)}:t},fJ=function(t){return gJ?String.fromCodePoint:t},lJ=function(t){return function(e){return uJ?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)}},dJ=function(t){return function(e){return sJ?function(n){return Array.from(n,e)}:t}},qs=t=>{const e=zn(t);if(e===0)return y;if(e===1)return T("Just",{head:Yr(Sa(0)(t)),tail:""});const n=Yr(Sa(1)(t)),r=Yr(Sa(0)(t));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?T("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:Qi(2)(t)}):T("Just",{head:r,tail:Qi(1)(t)})},hJ=t=>{const e=qs(t);return e.tag==="Just"?T("Just",E(e._1.head,e._1.tail)):y},pJ=t=>gn.unfoldr(hJ)(t),Xf=_J(t=>{const e=Yr(Sa(0)(t));if(55296<=e&&e<=56319&&zn(t)>1){const n=Yr(Sa(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),Ke=dJ(pJ)(Xf),mJ=t=>Ke(t).length,wc=t=>In(t>=0&&t<=65535?Uf(t):t<0?"\0":"\uFFFF"),yJ=fJ(t=>t<=65535?wc(t):wc(Sr(t-65536|0,1024)+55296|0)+wc(lo(t-65536|0)(1024)+56320|0)),Kf=t=>e=>{if(t<1)return"";const n=qs(e);return n.tag==="Just"?yJ(n._1.head)+Kf(t-1|0)(n._1.tail):e},Ve=lJ(Kf),xJ=t=>e=>e===""?y:T("Just",Xf(e)),Yf=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Vs=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Zf=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},qi=t=>e=>Yf(t.w/Vs(1e-6)(e.w))(t.h/Vs(1e-6)(e.h)),jf=t=>e=>n=>r=>n<e?t+e/2:Zf(t+e-n/2)(t+n/2)(r),tl=t=>e=>n=>r=>n>=e?t+e/2:Zf(t+n/2)(t+e-n/2)(r),el=t=>e=>n=>({x:tl(t.x)(t.w)(e.w)(n.x),y:tl(t.y)(t.h)(e.h)(n.y)}),nl=t=>e=>n=>({x:jf(t.x)(t.w)(e.w)(n.x),y:jf(t.y)(t.h)(e.h)(n.y)}),Vi=t=>{const e=t.visibleBounds.tag==="Just"?T("Just",{x:t.visibleBounds._1.x-t.padding,y:t.visibleBounds._1.y-t.padding,w:t.visibleBounds._1.w+2*t.padding,h:t.visibleBounds._1.h+2*t.padding}):y,n=e.tag==="Just"?T("Just",qi(t.frameAtUnitZoom)(e._1)):y,r=t.fallbackActionBounds.tag==="Just"?T("Just",{x:t.fallbackActionBounds._1.x-t.padding,y:t.fallbackActionBounds._1.y-t.padding,w:t.fallbackActionBounds._1.w+2*t.padding,h:t.fallbackActionBounds._1.h+2*t.padding}):y,o=Vs(1e-6)(t.zoomCap),i=(()=>{if(n.tag==="Nothing")return!1;if(n.tag==="Just")return n._1>=o;c()})(),a=t.actionBounds.tag==="Just"?T("Just",{x:t.actionBounds._1.x-t.padding,y:t.actionBounds._1.y-t.padding,w:t.actionBounds._1.w+2*t.padding,h:t.actionBounds._1.h+2*t.padding}):y,s=a.tag==="Just"&&qi(t.frameAtUnitZoom)(a._1)>=o,u=(()=>{if(e.tag==="Nothing")return t.worldBounds;if(e.tag==="Just")return e._1;c()})(),g=(()=>{if(r.tag==="Just")return r._1;if(r.tag==="Nothing"){if(a.tag==="Nothing")return u;if(a.tag==="Just")return a._1}c()})(),_=(()=>{if(i){if(e.tag==="Nothing")return t.worldBounds;if(e.tag==="Just")return e._1;c()}if(s){if(a.tag==="Nothing")return g;if(a.tag==="Just")return a._1;c()}return g})(),f=(()=>{if(i){if(n.tag==="Nothing")return o;if(n.tag==="Just")return n._1;c()}return Yf(o)(qi(t.frameAtUnitZoom)(_))})(),l={w:t.frameAtUnitZoom.w/f,h:t.frameAtUnitZoom.h/f};return{center:el(t.worldBounds)(l)(i||s?{x:_.x+_.w/2,y:_.y+_.h/2}:nl(_)(l)((()=>{const d={x:_.x+_.w/2,y:_.y+_.h/2};if(t.actionGuideBounds.tag==="Nothing")return d;if(t.actionGuideBounds.tag==="Just")return{x:t.actionGuideBounds._1.x+t.actionGuideBounds._1.w/2,y:t.actionGuideBounds._1.y+t.actionGuideBounds._1.h/2};c()})())),zoom:f}},Ui=t=>{const e=(()=>{if(t.bounds.tag==="Nothing")return t.worldBounds;if(t.bounds.tag==="Just")return{x:t.bounds._1.x-t.padding,y:t.bounds._1.y-t.padding,w:t.bounds._1.w+2*t.padding,h:t.bounds._1.h+2*t.padding};c()})(),n=qi(t.frameAtUnitZoom)(e),r=Vs(1e-6)(t.zoomFloor),o=n>=r,i=o?n:r,a={w:t.frameAtUnitZoom.w/i,h:t.frameAtUnitZoom.h/i},s=t.actionTextBounds.tag==="Just"?T("Just",{x:t.actionTextBounds._1.x-t.padding,y:t.actionTextBounds._1.y-t.padding,w:t.actionTextBounds._1.w+2*t.padding,h:t.actionTextBounds._1.h+2*t.padding}):y,u=(()=>{if(s.tag==="Nothing")return!1;if(s.tag==="Just")return qi(t.frameAtUnitZoom)(s._1)>=r;c()})(),g=t.actionGuideBounds.tag==="Just"?T("Just",{x:t.actionGuideBounds._1.x-t.padding,y:t.actionGuideBounds._1.y-t.padding,w:t.actionGuideBounds._1.w+2*t.padding,h:t.actionGuideBounds._1.h+2*t.padding}):y,_=t.actionBounds.tag==="Just"?T("Just",{x:t.actionBounds._1.x-t.padding,y:t.actionBounds._1.y-t.padding,w:t.actionBounds._1.w+2*t.padding,h:t.actionBounds._1.h+2*t.padding}):y,f=(()=>{if(_.tag==="Nothing")return!1;if(_.tag==="Just")return qi(t.frameAtUnitZoom)(_._1)>=r;c()})(),l=(()=>{if(o)return e;if(f){if(_.tag==="Nothing")return e;if(_.tag==="Just")return _._1;c()}if(u){if(s.tag==="Nothing")return e;if(s.tag==="Just")return s._1;c()}const m=(()=>{if(_.tag==="Nothing")return e;if(_.tag==="Just")return _._1;c()})(),p=(()=>{if(s.tag==="Nothing")return m;if(s.tag==="Just")return s._1;c()})();if(g.tag==="Nothing")return p;if(g.tag==="Just")return g._1;c()})(),d={x:l.x+l.w/2,y:l.y+l.h/2},h=(()=>{if(g.tag==="Nothing")return d;if(g.tag==="Just")return{x:g._1.x+g._1.w/2,y:g._1.y+g._1.h/2};c()})();return{center:el(t.worldBounds)(a)(o?{x:l.x+l.w/2,y:l.y+l.h/2}:f||u?nl(l)(a)(h):{x:l.x+l.w/2,y:l.y+l.h/2}),zoom:i}},rl=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},ol=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Us=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},il=t=>e=>rl(t.lo)(e.lo)<=ol(t.hi)(e.hi)?T("Just",{lo:rl(t.lo)(e.lo),hi:ol(t.hi)(e.hi)}):y,Tc=t=>e=>{const n=(()=>{if(e.tag==="Just")return il(t)(e._1);if(e.tag==="Nothing")return y;c()})();if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;c()},Nc={deadZoneWidth:.85,deadZoneHeight:1,hardZoneWidth:.85,hardZoneHeight:.8},al=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>_=>{const f=r<=o?{lo:n+r-o/2,hi:n+o/2}:{lo:n+o/2,hi:n+r-o/2},l=a.tag==="Just"?T("Just",a._1.size<=o?{lo:a._1.lo+a._1.size-o/2,hi:a._1.lo+o/2}:{lo:a._1.lo+o/2,hi:a._1.lo+a._1.size-o/2}):y,d=(()=>{if(a.tag==="Just")return a._1.size<=o;if(a.tag==="Nothing")return!1;c()})(),h=(()=>{if(d){if(l.tag==="Nothing")return f;if(l.tag==="Just")return l._1;c()}const J=(()=>{if(l.tag==="Just")return il(f)(l._1);if(l.tag==="Nothing")return y;c()})();if(J.tag==="Nothing")return f;if(J.tag==="Just")return J._1;c()})(),m=Tc(h)(s.tag==="Just"?T("Just",(()=>{const J=o*e;if(J<s._1.size){const w=s._1.lo+s._1.size/2;return{lo:w,hi:w}}return{lo:s._1.lo+s._1.size-J/2,hi:s._1.lo+J/2}})()):y),p=(()=>{if(a.tag==="Just")return Us(h.lo)(h.hi)(a._1.lo+a._1.size/2);if(a.tag==="Nothing")return Us(h.lo)(h.hi)(i);c()})(),x=Tc(g.tag==="Just"&&g._1.size<=o?Tc(m)(T("Just",(()=>{if(o<g._1.size){const J=g._1.lo+g._1.size/2;return{lo:J,hi:J}}return{lo:g._1.lo+g._1.size-o/2,hi:g._1.lo+o/2}})())):m)(s.tag==="Just"?T("Just",(()=>{const J=o*t;if(J<s._1.size){const w=s._1.lo+s._1.size/2;return{lo:w,hi:w}}return{lo:s._1.lo+s._1.size-J/2,hi:s._1.lo+J/2}})()):y);if(u.tag==="Just"){const J=u.tag==="Just"&&_.tag==="Just"&&xe(_._1)>.001?u._1.lo+u._1.size/2+_._1*o/6:i;return d?p:Us(x.lo)(x.hi)(J)}if(u.tag==="Nothing"){const J=s.tag==="Just"&&_.tag==="Just"&&xe(_._1)>.001?s._1.lo+s._1.size/2+_._1*o/6:i;return d?p:Us(x.lo)(x.hi)(J)}c()},bc=t=>e=>n=>r=>o=>({x:al(t.deadZoneWidth)(t.hardZoneWidth)(e.x)(e.w)(n.w)(r.x)(o.visibleBounds.tag==="Just"?T("Just",{lo:o.visibleBounds._1.x,size:o.visibleBounds._1.w}):y)(o.subject.tag==="Just"?T("Just",{lo:o.subject._1.x,size:o.subject._1.w}):y)(o.guide.tag==="Just"?T("Just",{lo:o.guide._1.x,size:o.guide._1.w}):y)(o.mustSee.tag==="Just"?T("Just",{lo:o.mustSee._1.x,size:o.mustSee._1.w}):y)(o.lookAhead.tag==="Just"?T("Just",o.lookAhead._1.x):y),y:al(t.deadZoneHeight)(t.hardZoneHeight)(e.y)(e.h)(n.h)(r.y)(o.visibleBounds.tag==="Just"?T("Just",{lo:o.visibleBounds._1.y,size:o.visibleBounds._1.h}):y)(o.subject.tag==="Just"?T("Just",{lo:o.subject._1.y,size:o.subject._1.h}):y)(o.guide.tag==="Just"?T("Just",{lo:o.guide._1.y,size:o.guide._1.h}):y)(o.mustSee.tag==="Just"?T("Just",{lo:o.mustSee._1.y,size:o.mustSee._1.h}):y)(o.lookAhead.tag==="Just"?T("Just",o.lookAhead._1.y):y)}),sl=b(ur)(0),JJ=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},Br=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Xs=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},ul=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},wJ=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}]},ti=t=>e=>{const n=We(a=>s=>({a,b:s,len:(()=>{const u=s.y-a.y,g=s.x-a.x;return qe(g*g+u*u)})()}),t,At(1,t.length,t)),r=sl(K(a=>a.len)(n)),o=JJ(0)(r)(e*r),i=a=>s=>u=>{let g=a,_=s,f=u,l=!0,d;for(;l;){const h=g,m=_,p=f,x=Bt(J=>y,J=>w=>T("Just",{head:J,tail:w}),h);if(x.tag==="Nothing"){const J=t.length-1|0;if(J>=0&&J<t.length){l=!1,d=t[J];continue}l=!1,d=p;continue}if(x.tag==="Just"){if(m<=x._1.head.len){const J=x._1.head.len<=0?0:m/x._1.head.len;l=!1,d={x:x._1.head.a.x+(x._1.head.b.x-x._1.head.a.x)*J,y:x._1.head.a.y+(x._1.head.b.y-x._1.head.a.y)*J};continue}g=x._1.tail,_=m-x._1.head.len,f=p;continue}c()}return d};return 0<t.length?T("Just",i(n)(o)(t[0])):y},TJ=t=>e=>{const n=Br(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}},Ga=t=>sl(We(e=>n=>{const r=n.y-e.y,o=n.x-e.x;return qe(o*o+r*r)},t,At(1,t.length,t))),NJ=t=>e=>n=>r=>o=>{const i=0<t.length?T("Just",t[0]):y,a=(()=>{if(i.tag==="Nothing")return e;if(i.tag==="Just")return i._1;c()})(),s=t.length-1|0,u=s>=0&&s<t.length?T("Just",t[s]):y,g=(()=>{if(u.tag==="Nothing")return n;if(u.tag==="Just")return u._1;c()})(),_=Br(.05)(1-o.pre-o.post),f=r<o.pre?0:r>1-o.post?1:(r-o.pre)/_,l=g.x-n.x,d=2*(()=>{const N=g.y-n.y;return(l<0?-l:l)+(N<0?-N:N)})(),h=a.x-e.x,m=2*(()=>{const N=a.y-e.y;return(h<0?-h:h)+(N<0?-N:N)})(),p=m+Ga(t)+d,x=p<=1e-4?1:1-d/p,J=p<=1e-4?0:m/p;if(f<=J){const N=J<=1e-4?1:f/J;return{x:e.x+(a.x-e.x)*N,y:e.y+(a.y-e.y)*N}}if(f>=x){const N=x>=1?0:(f-x)/(1-x);return{x:g.x+(n.x-g.x)*N,y:g.y+(n.y-g.y)*N}}const w=ti(t)((f-J)/Br(1e-4)(x-J));if(w.tag==="Nothing")return a;if(w.tag==="Just")return w._1;c()},gl=t=>e=>{const n=Bt(r=>y,r=>o=>T("Just",{head:r,tail:o}),[...(()=>{const r=(o,i)=>{if(o.tag==="Leaf")return i;if(o.tag==="Node")return r(o._5,Jt("Cons",o._4,r(o._6,i)));c()};return St(Mt(ce.foldr,r(t,A)))(wJ)})(),...kn((()=>{const r=(o,i)=>{if(o.tag==="Leaf")return i;if(o.tag==="Node")return r(o._5,Jt("Cons",o._4,r(o._6,i)));c()};return Mt(ce.foldr,r(e,A))})())]);if(n.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(n.tag==="Just"){const r=b(o=>i=>({minX:Xs(o.minX)(i.x),minY:Xs(o.minY)(i.y),maxX:Br(o.maxX)(i.x),maxY:Br(o.maxY)(i.y)}))({minX:n._1.head.x,minY:n._1.head.y,maxX:n._1.head.x,maxY:n._1.head.y})(n._1.tail);return{x:r.minX,y:r.minY,w:r.maxX-r.minX,h:r.maxY-r.minY}}c()},vc={scale:1,tx:0,ty:0},bJ=t=>e=>{const n=Br(4)(.15*Xs(e.w)(e.h)),r=Br(1)(t.w),o=Br(1)(t.h),i=Br(1)(e.w-2*n),a=Br(1)(e.h-2*n),s=.55*Xs(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}},vJ=t=>e=>(n=>r=>o=>{let i=n,a=r,s=o,u=!0,g;for(;u;){const _=i,f=a,l=s,d=Bt(h=>y,h=>m=>T("Just",{head:h,tail:m}),f);if(d.tag==="Nothing"){u=!1,g=l;continue}if(d.tag==="Just"){const h=ul(d._1.head)(_.interiors);if(h.tag==="Nothing"){u=!1,g=l;continue}if(h.tag==="Just"){i=h._1,a=d._1.tail,s=(()=>{const m=bJ(h._1.layout.bounds)((()=>{const p=ul(d._1.head)(_.layout.nodes);if(p.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:ho};if(p.tag==="Just")return p._1;c()})());return{scale:l.scale*m.scale,tx:l.scale*m.tx+l.tx,ty:l.scale*m.ty+l.ty}})();continue}}c()}return g})(t)(e)(vc),CJ=t=>t,cl=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},Cc=t=>e=>t.width<=0||t.height<=0?e:cl(t.width/t.height)(e),tt=(t,e)=>({tag:"CatQueue",_1:t,_2:e}),LJ=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=y;continue}e=tt((i=>a=>{let s=i,u=a,g=!0,_;for(;g;){const f=s,l=u;if(l.tag==="Nil"){g=!1,_=f;continue}if(l.tag==="Cons"){s=Jt("Cons",l._1,f),u=l._2;continue}c()}return _})(A)(o._2),A);continue}if(o._1.tag==="Cons"){n=!1,r=T("Just",E(o._1._1,tt(o._1._2,o._2)));continue}c()}return r},et=(t,e,n)=>({tag:t,_1:e,_2:n}),gt=et("CatNil"),kJ=t=>e=>{if(t.tag==="CatNil")return e;if(e.tag==="CatNil")return t;if(t.tag==="CatCons")return et("CatCons",t._1,tt(t._2._1,Jt("Cons",e,t._2._2)));c()},SJ=t=>e=>n=>{const r=o=>i=>a=>{let s=o,u=i,g=a,_=!0,f;for(;_;){const l=s,d=u,h=g;if(h.tag==="Nil"){_=!1,f=d;continue}if(h.tag==="Cons"){s=l,u=l(d)(h._1),g=h._2;continue}c()}return f};return(o=>i=>{let a=o,s=i,u=!0,g;for(;u;){const _=a,f=s,l=LJ(_);if(l.tag==="Nothing"){u=!1,g=r(d=>h=>h(d))(e)(f);continue}if(l.tag==="Just"){a=l._1._2,s=Jt("Cons",t(l._1._1),f);continue}c()}return g})(n)(A)},EJ=t=>{if(t.tag==="CatNil")return y;if(t.tag==="CatCons")return T("Just",E(t._1,t._2._1.tag==="Nil"&&t._2._2.tag==="Nil"?gt:SJ(kJ)(gt)(t._2)));c()},j=(t,e)=>({tag:"Free",_1:t,_2:e}),st=(t,e,n)=>({tag:t,_1:e,_2:n}),_l=t=>{let e=t,n=!0,r;for(;n;){const o=e;if(o._1.tag==="Return"){const i=EJ(o._2);if(i.tag==="Nothing"){n=!1,r=st("Return",o._1._1);continue}if(i.tag==="Just"){e=(()=>{const a=i._1._1(o._1._1);return j(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 et("CatCons",a._2._1,tt(a._2._2._1,Jt("Cons",i._1._2,a._2._2._2)));c()})())})();continue}c()}if(o._1.tag==="Bind"){n=!1,r=st("Bind",o._1._1,i=>{const a=o._1._2(i);return j(a._1,(()=>{if(a._2.tag==="CatNil")return o._2;if(o._2.tag==="CatNil")return a._2;if(a._2.tag==="CatCons")return et("CatCons",a._2._1,tt(a._2._2._1,Jt("Cons",o._2,a._2._2._2)));c()})())});continue}c()}return r},RJ=t=>e=>{const n=e.Monad0(),r=n.Bind1().Apply0().Functor0();return o=>e.tailRecM(i=>{const a=_l(i);if(a.tag==="Return")return r.map(G2)(n.Applicative0().pure(a._1));if(a.tag==="Bind")return r.map(zg)(o(t.map(a._2)(a._1)));c()})},PJ=t=>e=>n=>{const r=_l(n);if(r.tag==="Return")return e(r._1);if(r.tag==="Bind")return t(r._1)(r._2);c()},Lc={Applicative0:()=>Zr,Bind1:()=>fl},BJ={map:t=>e=>fl.bind(e)(n=>Zr.pure(t(n)))},fl={bind:t=>e=>j(t._1,(()=>{if(t._2.tag==="CatNil")return et("CatCons",e,tt(A,A));if(t._2.tag==="CatCons")return et("CatCons",t._2._1,tt(t._2._2._1,Jt("Cons",et("CatCons",e,tt(A,A)),t._2._2._2)));c()})()),Apply0:()=>ll},ll={apply:t=>e=>{const n=r=>j(e._1,(()=>{if(e._2.tag==="CatNil")return et("CatCons",o=>Zr.pure(r(o)),tt(A,A));if(e._2.tag==="CatCons")return et("CatCons",e._2._1,tt(e._2._2._1,Jt("Cons",et("CatCons",o=>Zr.pure(r(o)),tt(A,A)),e._2._2._2)));c()})());return j(t._1,(()=>{if(t._2.tag==="CatNil")return et("CatCons",n,tt(A,A));if(t._2.tag==="CatCons")return et("CatCons",t._2._1,tt(t._2._2._1,Jt("Cons",et("CatCons",n,tt(A,A)),t._2._2._2)));c()})())},Functor0:()=>BJ},Zr={pure:t=>j(st("Return",t),gt),Apply0:()=>ll},yo=t=>t,GJ=t=>t,Gr=yo("RunText"),Ks=yo("RunBold"),Ys=yo("RunCode"),Zs=yo("RunCodeBold"),js=yo("RunHighlight"),tu=yo("RunBoldHighlight"),eu=yo("RunCodeHighlight"),nu=yo("RunCodeBoldHighlight"),AJ=t=>"md:"+t,wn=t=>{const e=(()=>{const r=Jr("md:")(t);if(r.tag==="Just")return!0;if(r.tag==="Nothing")return!1;c()})()?AJ:GJ,n=$i(`
|
|
3
|
+
`)((()=>{const r=Jr("md:")(t);if(r.tag==="Just")return r._1;if(r.tag==="Nothing")return t;c()})());return n.length===0?[e("")]:K(e)(n)},ru=t=>e=>n=>e.length===0?n:Et(n)({style:t,text:An(e)}),IJ=t=>({code:t.code,bold:!t.bold,highlight:t.highlight,buf:[],runs:ru((()=>{if(!t.highlight){if(!t.code){if(!t.bold)return Gr;if(t.bold)return Ks;c()}if(t.code){if(!t.bold)return Ys;if(t.bold)return Zs}c()}if(t.highlight){if(!t.code){if(!t.bold)return js;if(t.bold)return tu;c()}if(t.code){if(!t.bold)return eu;if(t.bold)return nu}}c()})())(t.buf)(t.runs)}),zJ=t=>({code:!t.code,bold:t.bold,highlight:t.highlight,buf:[],runs:ru((()=>{if(!t.highlight){if(!t.code){if(!t.bold)return Gr;if(t.bold)return Ks;c()}if(t.code){if(!t.bold)return Ys;if(t.bold)return Zs}c()}if(t.highlight){if(!t.code){if(!t.bold)return js;if(t.bold)return tu;c()}if(t.code){if(!t.bold)return eu;if(t.bold)return nu}}c()})())(t.buf)(t.runs)}),DJ=t=>({code:t.code,bold:t.bold,highlight:!t.highlight,buf:[],runs:ru((()=>{if(!t.highlight){if(!t.code){if(!t.bold)return Gr;if(t.bold)return Ks;c()}if(t.code){if(!t.bold)return Ys;if(t.bold)return Zs}c()}if(t.highlight){if(!t.code){if(!t.bold)return js;if(t.bold)return tu;c()}if(t.code){if(!t.bold)return eu;if(t.bold)return nu}}c()})())(t.buf)(t.runs)}),FJ=t=>e=>0<e.length?{...t,buf:Et(t.buf)(e[0])}:{...t,buf:Et(t.buf)("\\")},MJ=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,g=o,_=Bt(f=>y,f=>l=>T("Just",{head:f,tail:l}),i);if(_.tag==="Nothing"){a=!1,s=g;continue}if(_.tag==="Just"){if(_._1.head==="\\"){r=u,o=FJ(g)(_._1.tail),i=At(1,_._1.tail.length,_._1.tail);continue}if(_._1.head==="`"){r=u,o=zJ(g),i=_._1.tail;continue}if(_._1.head==="*"&&0<_._1.tail.length&&_._1.tail[0]==="*"){r=u,o=IJ(g),i=At(1,_._1.tail.length,_._1.tail);continue}if(u&&_._1.head==="="&&0<_._1.tail.length&&_._1.tail[0]==="="){r=u,o=DJ(g),i=At(1,_._1.tail.length,_._1.tail);continue}r=u,o={...g,buf:Et(g.buf)(_._1.head)},i=_._1.tail;continue}c()}return s},Sn=t=>{const e=MJ((()=>{const n=Jr("md:")(t);if(n.tag==="Just")return!0;if(n.tag==="Nothing")return!1;c()})())({code:!1,bold:!1,highlight:!1,buf:[],runs:[]})(tr((()=>{const n=Jr("md:")(t);if(n.tag==="Just")return n._1;if(n.tag==="Nothing")return t;c()})()));return ru((()=>{if(!e.highlight){if(!e.code){if(!e.bold)return Gr;if(e.bold)return Ks;c()}if(e.code){if(!e.bold)return Ys;if(e.bold)return Zs}c()}if(e.highlight){if(!e.code){if(!e.bold)return js;if(e.bold)return tu;c()}if(e.code){if(!e.bold)return eu;if(e.bold)return nu}}c()})())(e.buf)(e.runs)},Dn=(()=>{const t=dr(""),e=K(n=>n.text);return n=>t(e(Sn(n)))})();let kc=null;function QJ(){return kc||(typeof document>"u"?null:(kc=document.createElement("canvas").getContext("2d"),kc))}const dl=new Map,WJ=t=>e=>n=>r=>()=>{const o=`${n} ${e}px ${t}|${r}`,i=dl.get(o);if(i!==void 0)return i;const a=QJ();if(!a)return r.length*e*.62;a.font=`${n} ${e}px ${t}`;const s=a.measureText(r).width;return dl.set(o,s),s},OJ=b(ur)(0),hl=xr.traverse(Ig),HJ=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Xi=(()=>{const t=lr(`\r
|
|
4
4
|
`)(" "),e=lr(`
|
|
5
|
-
`)(" "),n=(()=>{const r=lr("\r")(" "),o=(()=>{const i=lr(" ")(" ");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),pl={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"}},ml=t=>e=>{const n=hl(r=>{const o=hl(i=>{const a=(()=>{if(i.style==="RunText")return t.text;if(i.style==="RunBold")return{...t.text,weight:"700"};if(i.style==="RunCode")return t.code;if(i.style==="RunCodeBold")return{...t.code,weight:"700"};if(i.style==="RunHighlight")return t.text;if(i.style==="RunBoldHighlight")return{...t.text,weight:"700"};if(i.style==="RunCodeHighlight")return t.code;if(i.style==="RunCodeBoldHighlight")return{...t.code,weight:"700"};c()})();return Hw(a.family)(a.size)(a.weight)(Ki(i.text))})(Zn(r));return()=>{const i=o();return Ow(i)}})(Jn(e));return()=>{const r=n();return b(Ww)(0)(r)}},$w=()=>()=>()=>t=>e=>n=>w2(n.type)(t)?J2(n.type)(t)(n.value):e(n),qw={map:t=>e=>({type:e.type,value:e.map(t)(e.value),map:e.map})},Vw=t=>Af("Data.Functor.Variant: pattern match failure ["+t.type+"]"),Uw=()=>()=>()=>t=>$w()()()(t)(Vw);(function(){var t={},e="Pure",n="Throw",r="Catch",o="Sync",i="Async",a="Bind",s="Bracket",u="Fork",g="Sequential",_="Map",f="Apply",l="Alt",d="Cons",h="Resume",m="Release",p="Finalizer",x="Finalized",w="Forked";function J(O,z,X,V){this.tag=O,this._1=z,this._2=X,this._3=V}function N(O){var z=function(X,V,K){return new J(O,X,V,K)};return z.tag=O,z}function k(O){return new J(e,void 0)}function C(O){try{O()}catch(z){setTimeout(function(){throw z},0)}}function R(O,z,X){try{return z(X())}catch(V){return O(V)}}function P(O,z,X){try{return z(X)()}catch(V){return X(O(V))(),k}}var I=(function(){var O=1024,z=0,X=0,V=new Array(O),K=!1;function Z(){var nt;for(K=!0;z!==0;)z--,nt=V[X],V[X]=void 0,X=(X+1)%O,nt();K=!1}return{isDraining:function(){return K},enqueue:function(nt){var rt;z===O&&(rt=K,Z(),K=rt),V[(X+z)%O]=nt,z++,K||Z()}}})();function U(O){var z={},X=0,V=0;return{register:function(K){var Z=X++;K.onComplete({rethrow:!0,handler:function(nt){return function(){V--,delete z[Z]}}})(),z[Z]=K,V++},isEmpty:function(){return V===0},killAll:function(K,Z){return function(){if(V===0)return Z();var nt=0,rt={};function ft(lt){rt[lt]=z[lt].kill(K,function(mt){return function(){delete rt[lt],nt--,O.isLeft(mt)&&O.fromLeft(mt)&&setTimeout(function(){throw O.fromLeft(mt)},0),nt===0&&Z()}})()}for(var Nt in z)z.hasOwnProperty(Nt)&&(nt++,ft(Nt));return z={},X=0,V=0,function(lt){return new J(o,function(){for(var mt in rt)rt.hasOwnProperty(mt)&&rt[mt]()})}}}}}var S=0,v=1,D=2,W=3,M=4,q=5,$=6;function G(O,z,X){var V=0,K=S,Z=X,nt=null,rt=null,ft=null,Nt=null,lt=null,mt=0,vt=0,Wt=null,Tt=!0;function Vt(ct){for(var Jt,At,yt;;)switch(Jt=null,At=null,yt=null,K){case D:K=v;try{Z=ft(Z),Nt===null?ft=null:(ft=Nt._1,Nt=Nt._2)}catch(Ot){K=q,nt=O.left(Ot),Z=null}break;case W:O.isLeft(Z)?(K=q,nt=Z,Z=null):ft===null?K=q:(K=D,Z=O.fromRight(Z));break;case v:switch(Z.tag){case a:ft&&(Nt=new J(d,ft,Nt)),ft=Z._2,K=v,Z=Z._1;break;case e:ft===null?(K=q,Z=O.right(Z._1)):(K=D,Z=Z._1);break;case o:K=W,Z=R(O.left,O.right,Z._1);break;case i:K=M,Z=P(O.left,Z._1,function(Ot){return function(){V===ct&&(V++,I.enqueue(function(){V===ct+1&&(K=W,Z=Ot,Vt(V))}))}});return;case n:K=q,nt=O.left(Z._1),Z=null;break;case r:ft===null?lt=new J(d,Z,lt,rt):lt=new J(d,Z,new J(d,new J(h,ft,Nt),lt,rt),rt),ft=null,Nt=null,K=v,Z=Z._1;break;case s:mt++,ft===null?lt=new J(d,Z,lt,rt):lt=new J(d,Z,new J(d,new J(h,ft,Nt),lt,rt),rt),ft=null,Nt=null,K=v,Z=Z._1;break;case u:K=W,Jt=G(O,z,Z._2),z&&z.register(Jt),Z._1&&Jt.run(),Z=O.right(Jt);break;case g:K=v,Z=Q(O,z,Z._1);break}break;case q:if(ft=null,Nt=null,lt===null)K=$,Z=rt||nt||Z;else switch(Jt=lt._3,yt=lt._1,lt=lt._2,yt.tag){case r:rt&&rt!==Jt&&mt===0?K=q:nt&&(K=v,Z=yt._2(O.fromLeft(nt)),nt=null);break;case h:rt&&rt!==Jt&&mt===0||nt?K=q:(ft=yt._1,Nt=yt._2,K=D,Z=O.fromRight(Z));break;case s:mt--,nt===null&&(At=O.fromRight(Z),lt=new J(d,new J(m,yt._2,At),lt,Jt),(rt===Jt||mt>0)&&(K=v,Z=yt._3(At)));break;case m:lt=new J(d,new J(x,Z,nt),lt,rt),K=v,rt&&rt!==Jt&&mt===0?Z=yt._1.killed(O.fromLeft(rt))(yt._2):nt?Z=yt._1.failed(O.fromLeft(nt))(yt._2):Z=yt._1.completed(O.fromRight(Z))(yt._2),nt=null,mt++;break;case p:mt++,lt=new J(d,new J(x,Z,nt),lt,rt),K=v,Z=yt._1;break;case x:mt--,K=q,Z=yt._1,nt=yt._2;break}break;case $:for(var Ct in Wt)Wt.hasOwnProperty(Ct)&&(Tt=Tt&&Wt[Ct].rethrow,C(Wt[Ct].handler(Z)));Wt=null,rt&&nt?setTimeout(function(){throw O.fromLeft(nt)},0):O.isLeft(Z)&&Tt&&setTimeout(function(){if(Tt)throw O.fromLeft(Z)},0);return;case S:K=v;break;case M:return}}function Gt(ct){return function(){if(K===$)return Tt=Tt&&ct.rethrow,ct.handler(Z)(),function(){};var Jt=vt++;return Wt=Wt||{},Wt[Jt]=ct,function(){Wt!==null&&delete Wt[Jt]}}}function bt(ct,Jt){return function(){if(K===$)return Jt(O.right(void 0))(),function(){};var At=Gt({rethrow:!1,handler:function(){return Jt(O.right(void 0))}})();switch(K){case S:rt=O.left(ct),K=$,Z=rt,Vt(V);break;case M:rt===null&&(rt=O.left(ct)),mt===0&&(K===M&&(lt=new J(d,new J(p,Z(ct)),lt,rt)),K=q,Z=null,nt=null,Vt(++V));break;default:rt===null&&(rt=O.left(ct)),mt===0&&(K=q,Z=null,nt=null)}return At}}function pt(ct){return function(){var Jt=Gt({rethrow:!1,handler:ct})();return K===S&&Vt(V),Jt}}return{kill:bt,join:pt,onComplete:Gt,isSuspended:function(){return K===S},run:function(){K===S&&(I.isDraining()?Vt(V):I.enqueue(function(){Vt(V)}))}}}function F(O,z,X,V){var K=0,Z={},nt=0,rt={},ft=new Error("[ParAff] Early exit"),Nt=null,lt=t;function mt(Gt,bt,pt){var ct=bt,Jt=null,At=null,yt=0,Ct={},Ot,Ft;t:for(;;)switch(Ot=null,ct.tag){case w:if(ct._3===t&&(Ot=Z[ct._1],Ct[yt++]=Ot.kill(Gt,function(se){return function(){yt--,yt===0&&pt(se)()}})),Jt===null)break t;ct=Jt._2,At===null?Jt=null:(Jt=At._1,At=At._2);break;case _:ct=ct._2;break;case f:case l:Jt&&(At=new J(d,Jt,At)),Jt=ct,ct=ct._1;break}if(yt===0)pt(O.right(void 0))();else for(Ft=0,Ot=yt;Ft<Ot;Ft++)Ct[Ft]=Ct[Ft]();return Ct}function vt(Gt,bt,pt){var ct,Jt,At,yt,Ct,Ot;for(O.isLeft(Gt)?(ct=Gt,Jt=null):(Jt=Gt,ct=null);;){if(At=null,yt=null,Ct=null,Ot=null,Nt!==null)return;if(bt===null){V(ct||Jt)();return}if(bt._3!==t)return;switch(bt.tag){case _:ct===null?(bt._3=O.right(bt._1(O.fromRight(Jt))),Jt=bt._3):bt._3=ct;break;case f:if(At=bt._1._3,yt=bt._2._3,ct){if(bt._3=ct,Ct=!0,Ot=nt++,rt[Ot]=mt(ft,ct===At?bt._2:bt._1,function(){return function(){delete rt[Ot],Ct?Ct=!1:pt===null?vt(ct,null,null):vt(ct,pt._1,pt._2)}}),Ct){Ct=!1;return}}else{if(At===t||yt===t)return;Jt=O.right(O.fromRight(At)(O.fromRight(yt))),bt._3=Jt}break;case l:if(At=bt._1._3,yt=bt._2._3,At===t&&O.isLeft(yt)||yt===t&&O.isLeft(At))return;if(At!==t&&O.isLeft(At)&&yt!==t&&O.isLeft(yt))ct=Jt===At?yt:At,Jt=null,bt._3=ct;else if(bt._3=Jt,Ct=!0,Ot=nt++,rt[Ot]=mt(ft,Jt===At?bt._2:bt._1,function(){return function(){delete rt[Ot],Ct?Ct=!1:pt===null?vt(Jt,null,null):vt(Jt,pt._1,pt._2)}}),Ct){Ct=!1;return}break}pt===null?bt=null:(bt=pt._1,pt=pt._2)}}function Wt(Gt){return function(bt){return function(){delete Z[Gt._1],Gt._3=bt,vt(bt,Gt._2._1,Gt._2._2)}}}function Tt(){var Gt=v,bt=X,pt=null,ct=null,Jt,At;t:for(;;)switch(Jt=null,At=null,Gt){case v:switch(bt.tag){case _:pt&&(ct=new J(d,pt,ct)),pt=new J(_,bt._1,t,t),bt=bt._2;break;case f:pt&&(ct=new J(d,pt,ct)),pt=new J(f,t,bt._2,t),bt=bt._1;break;case l:pt&&(ct=new J(d,pt,ct)),pt=new J(l,t,bt._2,t),bt=bt._1;break;default:At=K++,Gt=q,Jt=bt,bt=new J(w,At,new J(d,pt,ct),t),Jt=G(O,z,Jt),Jt.onComplete({rethrow:!1,handler:Wt(bt)})(),Z[At]=Jt,z&&z.register(Jt)}break;case q:if(pt===null)break t;pt._1===t?(pt._1=bt,Gt=v,bt=pt._2,pt._2=t):(pt._2=bt,bt=pt,ct===null?pt=null:(pt=ct._1,ct=ct._2))}for(lt=bt,At=0;At<K;At++)Z[At].run()}function Vt(Gt,bt){Nt=O.left(Gt);var pt;for(var ct in rt)if(rt.hasOwnProperty(ct)){pt=rt[ct];for(ct in pt)pt.hasOwnProperty(ct)&&pt[ct]()}rt=null;var Jt=mt(Gt,lt,bt);return function(At){return new J(i,function(yt){return function(){for(var Ct in Jt)Jt.hasOwnProperty(Ct)&&Jt[Ct]();return k}})}}return Tt(),function(Gt){return new J(i,function(bt){return function(){return Vt(Gt,bt)}})}}function Q(O,z,X){return new J(i,function(V){return function(){return F(O,z,X,V)}})}return J.EMPTY=t,J.Pure=N(e),J.Throw=N(n),J.Catch=N(r),J.Sync=N(o),J.Async=N(i),J.Bind=N(a),J.Bracket=N(s),J.Fork=N(u),J.Seq=N(g),J.ParMap=N(_),J.ParApply=N(f),J.ParAlt=N(l),J.Fiber=G,J.Supervisor=U,J.Scheduler=I,J.nonCanceler=k,J})();const Kw=t=>e=>Pw(n=>r=>t({type:n.type,value:n.map(o=>r(o))(n.value),map:n.map}))(e),Yw=t=>{const e=t.Bind1(),n=t.Applicative0().pure;return r=>{const o=y2(()=>Kw(i=>e.bind(r(i))(o()))(n));return o()}};let yl=null;function Xw(){return yl||(typeof document>"u"?null:yl=document.createElement("canvas").getContext("2d"))}const Sc=new Map;function xl(t,e,n,r,o,i){const a=`${n} ${e}px ${t}`,s=a+"|"+r;if(Sc.has(s))return Sc.get(s);const u=Xw();if(!u)return i;u.font=a;const g=o(u.measureText(r)),_=typeof document<"u"?document.fonts:null;if(!_||_.check(a))Sc.set(s,g);else if(_&&_.load)try{_.load(a)}catch{}return g}const Zw=(t,e,n,r)=>xl(t,e,n,r,o=>o.width,-1),jw=(t,e,n,r)=>xl(t,e,n,r,o=>({ascent:o.actualBoundingBoxAscent,descent:o.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),ou=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),wl=t=>t,Jl={map:t=>e=>{if(e.tag==="MeasureText")return ou("MeasureText",e._1,e._2,n=>t(e._3(n)));if(e.tag==="MeasureInk")return ou("MeasureInk",e._1,e._2,n=>t(e._3(n)));c()}},Ec=t=>e=>{const n=Zw(t.family,t.size,t.weight,Ki(e));return n<0?ot(_n(e).length)*t.size*.62:n},Rc=t=>e=>{const n=jw(t.family,t.size,t.weight,Ki(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},tJ=t=>e=>j(st("Bind",{type:"metrics",value:ou("MeasureInk",t,e,wl),map:Jl.map},n=>j(st("Return",n),gt)),gt),yo=t=>e=>j(st("Bind",{type:"metrics",value:ou("MeasureText",t,e,wl),map:Jl.map},n=>j(st("Return",n),gt)),gt),Tl=t=>t,Nl=t=>t,iu=t=>t,bl=t=>t,vl=t=>t,Yt=(t,e,n,r,o)=>({tag:t,_1:e,_2:n,_3:r,_4:o}),Cl=t=>t,Pc=t=>t,eJ=Pc("BaselineTop"),tr=Pc("BaselineMiddle"),nJ=Pc("BaselineBottom"),Gr=Cl("AlignLeft"),Aa=Cl("AlignCenter"),nn=vl("RoundJoin"),Ia=vl("MiterJoin"),zn=bl("ButtCap"),Br=bl("RoundCap"),rJ=iu("LayerPolyOut"),oJ=iu("LayerPolyIn"),iJ=iu("LayerNodeMask"),aJ=iu("LayerOverlay"),jo=Nl("NonZero"),Gc=Nl("EvenOdd"),Ll=Tl("Normal"),au=Tl("Difference"),Je={r:255,g:255,b:255,a:255},xo=[5],Ce={map:t=>e=>{if(e.tag==="FillPath")return Yt("FillPath",e._1,e._2,t(e._3));if(e.tag==="StrokePath")return Yt("StrokePath",e._1,e._2,t(e._3));if(e.tag==="FillStrokePath")return Yt("FillStrokePath",e._1,e._2,e._3,t(e._4));if(e.tag==="DrawText")return Yt("DrawText",e._1,t(e._2));if(e.tag==="DrawTextAffine")return Yt("DrawTextAffine",e._1,e._2,t(e._3));if(e.tag==="PushTransform")return Yt("PushTransform",e._1,t(e._2));if(e.tag==="PopTransform")return Yt("PopTransform",t(e._1));if(e.tag==="PushClip")return Yt("PushClip",e._1,e._2,t(e._3));if(e.tag==="PopClip")return Yt("PopClip",t(e._1));if(e.tag==="PushBlend")return Yt("PushBlend",e._1,t(e._2));if(e.tag==="PopBlend")return Yt("PopBlend",t(e._1));if(e.tag==="PushAlpha")return Yt("PushAlpha",e._1,t(e._2));if(e.tag==="PopAlpha")return Yt("PopAlpha",t(e._1));if(e.tag==="PushBlur")return Yt("PushBlur",e._1,t(e._2));if(e.tag==="PopBlur")return Yt("PopBlur",t(e._1));if(e.tag==="PushLayer")return Yt("PushLayer",e._1,t(e._2));if(e.tag==="PopLayer")return Yt("PopLayer",t(e._1));if(e.tag==="SetViewport")return Yt("SetViewport",e._1,t(e._2));if(e.tag==="ClearBackground")return Yt("ClearBackground",e._1,t(e._2));if(e.tag==="BackgroundDots")return Yt("BackgroundDots",e._1,t(e._2));c()}},jr={r:26,g:26,b:26,a:255},Bc=t=>e=>Math.imul(t,e),Yi=t=>{const e=t+1831565813|0,n=Bc(e^e>>>15)(e|1),r=n^(n+Bc(n^n>>>7)(n|61)|0),o=r^r>>>14;return{prng:o,value:o<0?(ot(o)+4294967296)/4294967296:ot(o)/4294967296}},Pe=t=>e=>n=>{const r=Yi(n);return{prng:r.prng,value:t+r.value*(e-t)}},Ac=t=>e=>b(n=>r=>Bc(n^r)(-2048144789))(e)(Y(Xr)(Xn(t))),sJ=t=>t,kl=t=>t,uJ=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Sn=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Sl=t=>e=>n=>{const r=ut.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=ut.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},Ic=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},gJ=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},cJ=kl("FlatLevel"),_J=kl("NestedLevel"),zc=sJ("GenieSilhouette"),fJ=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const o=Yi(t);return{prng:o.prng,yLift:o.value*n.yJitter*r}},lJ=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const o=Yi(t);return{prng:o.prng,dx:(o.value*2-1)*n.xJitter*r}},El=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,o=qe(r*r+n*n),i=(t.r*t.r-e.r*e.r+o*o)/(2*o),a=qe(uJ(0)(t.r*t.r-i*i)),s=t.cx+i*r/o,u=t.cy+i*n/o,g={x:s-a*n/o,y:u+a*r/o},_={x:s+a*n/o,y:u-a*r/o};return o===0||o>t.r+e.r?{x:(t.cx+e.cx)/2,y:t.cy}:g.y<_.y?g:_},su=t=>e=>{const n=Sn(e)(Sn(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]},dJ=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=Yi(t);return{prng:a.prng,r:o*(1+a.value*i.rJitter)}},Rl=t=>{const e=Sn(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]},hJ=t=>e=>n=>{const r=Yi(t),o=e.length;return o===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const i=Sl(0)(o-1|0)(he(sr(r.value*ot(n))));return i>=0&&i<e.length?e[i]:-1})()}},pJ=t=>e=>{const n=Yi(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const o=Sl(0)(r-1|0)(he(sr(n.value*ot(r))));return o>=0&&o<e.length?e[o]:-1})()}},Pl=t=>{const e=Sn(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]},Gl=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},mJ=t=>{const e=Sn(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]},Al=t=>{const e=Sn(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]},Il=t=>e=>{const n=e.y+e.h,r=ly(t.rBase*e.h)(e.w/(2*(1+(ot(t.minN)-1)*t.stepRatio))),o=e.w-2*r,i=2*r*t.stepRatio,a=Ic(t.minN)(o<=0||i<=0?t.minN:he(Vn(o/i))+1|0),s=a>=3?Ut(1,a-2|0):[],u=s.length,g=Lr(u+1|0,2),_=g<1?[]:Bt(0,g,s),f=pJ(t.seed)((()=>{const p=u-g|0;return p<1?s:Bt(p,s.length,s)})()),l=f.idx,d=hJ(f.prng)(_t(p=>p!==l,_))(Ic(1)(_.length-(yn(uo)(l)(_)?1:0)|0)),h=d.idx,m=a>=2?o/(ot(a)-1):0;return b(p=>x=>{const w=x===h,J=x===l,N=x===0||x===(a-1|0),k=dJ(p.prng)(N)(J)(w)(r)(t),C=fJ(k.prng)(N)(t)(e.h),R=lJ(C.prng)(N)(t)(m);return{prng:R.prng,circles:Et(p.circles)({cx:e.x+gJ(k.r)(e.w-k.r)((a>=2?r+ot(x)/(ot(a)-1)*o+R.dx:r+0*o+R.dx)+(J?t.heroShift*m:w?-1*t.smallShift*m:0)),cy:n-C.yLift,r:k.r})}})({prng:d.prng,circles:[]})(Ut(0,a-1|0)).circles},zl=t=>e=>{const n=t.length;return Dt(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?El(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?El(o)(t[i]):{x:o.cx+o.r,y:e}})()}))(t)},Fl=t=>{const e=Sn(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]},yJ=t=>e=>n=>{const r=Qo(e.y-t.cy)(e.x-t.cx),o=Qo(n.y-t.cy)(n.x-t.cx),i=o>r?o-r:o+6.283185307179586-r,a=Ic(1)(he(Cs(i/1.5707963267948966))),s=i/ot(a),u=1.3333333333333333*dy(s/4);return St(Ut(0,a-1|0))(g=>{const _=r+ot(g+1|0)*s,f=t.cx+t.r*xn(_),l=t.cy+t.r*tn(_),d=r+ot(g)*s;return[4,t.cx+t.r*xn(d)-u*t.r*tn(d),t.cy+t.r*tn(d)+u*t.r*xn(d),f+u*t.r*tn(_),l-u*t.r*xn(_),f,l]})},Dl=t=>e=>{const n=t.h*.38,r=zl(Il(Bl)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),o=Sn(e)(Sn(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...St(r)(i=>yJ(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]:su(t)(e)},ti=t=>e=>n=>r=>o=>i=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(o)(i);if(e==="Cylinder"){const a=Al(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);c()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}c()}if(e==="Parallelogram"){const a=Pl(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);c()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}c()}if(e==="Diamond"){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);c()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}c()}if(e==="Ellipse"){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);c()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}c()}if(e==="Document"){const a=Gl(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);c()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}c()}if(e==="Cloud"){const a=Dl(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);c()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}c()}return t.drawRoundedRect(n)(r)(o)(i)},xJ={fillPath:t=>e=>j(st("Bind",{type:"render",value:Yt("FillPath",t,e,void 0),map:Ce.map},n=>j(st("Return",n),gt)),gt),strokePath:t=>e=>j(st("Bind",{type:"render",value:Yt("StrokePath",t,e,void 0),map:Ce.map},n=>j(st("Return",n),gt)),gt),fillStrokePath:t=>e=>n=>j(st("Bind",{type:"render",value:Yt("FillStrokePath",t,e,n,void 0),map:Ce.map},r=>j(st("Return",r),gt)),gt),drawRoundedRect:t=>e=>n=>r=>{if(n.tag==="Just"){if(r.tag==="Just")return j(st("Bind",{type:"render",value:Yt("FillStrokePath",su(t)(e),n._1,r._1,void 0),map:Ce.map},o=>j(st("Return",o),gt)),gt);if(r.tag==="Nothing")return j(st("Bind",{type:"render",value:Yt("FillPath",su(t)(e),n._1,void 0),map:Ce.map},o=>j(st("Return",o),gt)),gt);c()}if(n.tag==="Nothing"){if(r.tag==="Just")return j(st("Bind",{type:"render",value:Yt("StrokePath",su(t)(e),r._1,void 0),map:Ce.map},o=>j(st("Return",o),gt)),gt);if(r.tag==="Nothing")return j(st("Return",void 0),gt)}c()},drawText:t=>j(st("Bind",{type:"render",value:Yt("DrawText",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),drawTextAffine:t=>e=>j(st("Bind",{type:"render",value:Yt("DrawTextAffine",t,e,void 0),map:Ce.map},n=>j(st("Return",n),gt)),gt),pushTransform:t=>j(st("Bind",{type:"render",value:Yt("PushTransform",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),popTransform:j(st("Bind",{type:"render",value:Yt("PopTransform",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),pushBakedTransform:t=>j(st("Bind",{type:"render",value:Yt("PushTransform",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),popBakedTransform:j(st("Bind",{type:"render",value:Yt("PopTransform",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),pushClip:t=>e=>j(st("Bind",{type:"render",value:Yt("PushClip",t,e,void 0),map:Ce.map},n=>j(st("Return",n),gt)),gt),popClip:j(st("Bind",{type:"render",value:Yt("PopClip",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),pushBlend:t=>j(st("Bind",{type:"render",value:Yt("PushBlend",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),popBlend:j(st("Bind",{type:"render",value:Yt("PopBlend",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),pushAlpha:t=>j(st("Bind",{type:"render",value:Yt("PushAlpha",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),popAlpha:j(st("Bind",{type:"render",value:Yt("PopAlpha",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),pushBlur:t=>j(st("Bind",{type:"render",value:Yt("PushBlur",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),popBlur:j(st("Bind",{type:"render",value:Yt("PopBlur",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),pushLayer:t=>j(st("Bind",{type:"render",value:Yt("PushLayer",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),popLayer:j(st("Bind",{type:"render",value:Yt("PopLayer",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),setViewport:t=>j(st("Bind",{type:"render",value:Yt("SetViewport",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),clearBackground:t=>j(st("Bind",{type:"render",value:Yt("ClearBackground",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),backgroundDots:t=>j(st("Bind",{type:"render",value:Yt("BackgroundDots",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),measureText:t=>e=>yo(t)(e),measureInk:t=>e=>tJ(t)(e),insideTokenStyle:t=>j(st("Return",zc),gt),Monad0:()=>Lc},Ar=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Ml=b(ur)(0),Ql=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},wJ=b(t=>e=>t+e.len)(0),Hl=t=>{const e=It(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(Bt(1,t.length,t))(n=>[2,n.x,n.y]),5];c()},JJ=t=>e=>{const n=Ar(e)(Ar(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]},TJ=t=>{const e=It(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(e._1.tail)(n=>[2,n.x,n.y])];c()},wo=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return Al(e);if(t.shape==="Parallelogram")return Pl(e);if(t.shape==="Diamond")return Fl(e);if(t.shape==="Ellipse")return Rl(e);if(t.shape==="Document")return Gl(e);if(t.shape==="Cloud")return Dl(e)(7);if(t.shape==="Rectangle")return JJ(e)(7);c()},Fe=t=>e=>n=>Y(r=>{const o=ot(r)/ot(n);return{x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o}})(Ut(0,n-1|0)),NJ=t=>{const e=Sn(t.w*.18)(t.h*.6);return[...Fe({x:t.x+e,y:t.y})({x:t.x+t.w,y:t.y})(16),...Fe({x:t.x+t.w,y:t.y})({x:t.x+t.w-e,y:t.y+t.h})(16),...Fe({x:t.x+t.w-e,y:t.y+t.h})({x:t.x,y:t.y+t.h})(16),...Fe({x:t.x,y:t.y+t.h})({x:t.x+e,y:t.y})(16)]},Fc=t=>e=>{const n=Ar(t)(Ar(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}},Dc=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return qe(r*r+n*n)},bJ=t=>He(e=>n=>({a:e,b:n,len:Dc(e)(n)}),t,Bt(1,t.length,t)),Ol=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?T("Just",e[n]):y,o=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];c()})(),i=0<e.length?T("Just",e[0]):y,a=(()=>{if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return{x:0,y:0};c()})(),s=e.length;return s<3?e:[a,...St(Ut(1,s-2|0))(u=>{const g=u+1|0,_=g>=0&&g<e.length?T("Just",e[g]):y,f=u>=0&&u<e.length?T("Just",e[u]):y,l=u-1|0,d=l>=0&&l<e.length?T("Just",e[l]):y;if(d.tag==="Just"&&f.tag==="Just"&&_.tag==="Just"){const h=f._1,m=Dc(h)(_._1),p=Dc(d._1)(h),x=Ar(t)(m/2),w=Ar(t)(p/2),J=m>0?x/m:0,N=h.x+(_._1.x-h.x)*J,k=h.y+(_._1.y-h.y)*J,C=p>0?w/p:0,R=h.x+(d._1.x-h.x)*C,P=h.y+(d._1.y-h.y)*C;return Y(I=>{const U=ot(I)/ot(10),S=1-U;return{x:S*S*R+2*S*U*h.x+U*U*N,y:S*S*P+2*S*U*h.y+U*U*k}})(Ut(0,10))}return[]}),...o]},vJ=t=>e=>n=>r=>o=>Y(i=>{const a=ot(i)/ot(o),s=1-a,u=a*a*a,g=3*s*a*a,_=3*s*s*a,f=s*s*s;return{x:f*t.x+_*e.x+g*n.x+u*r.x,y:f*t.y+_*e.y+g*n.y+u*r.y}})(Ut(0,o-1|0)),CJ=t=>[...Fe({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...Fe({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...vJ({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),...Fe({x:t.x,y:t.y+t.h*.85})({x:t.x,y:t.y})(12)],Wl=t=>e=>Y(n=>{const r=6.283185307179586*ot(n)/ot(64);return{x:t.x+e*xn(r),y:t.y+e*tn(r)}})(Ut(0,63)),$l=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]},LJ=t=>{const e=t.y+t.h/2,n=Sn(t.h*.4)(t.w*.2);return[...Fe({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...Fe({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...Fe({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...Fe({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...Fe({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...Fe({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},Mc=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:Ml(Y(n=>n.x)(t))/ot(e),y:Ml(Y(n=>n.y)(t))/ot(e)}},uu=t=>e=>n=>r=>o=>Y(i=>{const a=n+(r-n)*(ot(i)/ot(o));return{x:t.x+e*xn(a),y:t.y+e*tn(a)}})(Ut(0,o-1|0)),Qc=t=>e=>{const n=Ar(t)(Ar(e.w/2)(e.h/2));return[...Fe({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...uu({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...Fe({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...uu({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...Fe({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...uu({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...Fe({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...uu({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},gu=t=>e=>n=>r=>o=>i=>Y(a=>{const s=r+(o-r)*(ot(a)/ot(i));return{x:t.x+e*xn(s),y:t.y+n*tn(s)}})(Ut(0,i-1|0)),kJ=t=>{const e=t.h*.38;return[...St(zl(Il(Bl)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=Qo(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),o=Qo(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return gu({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(o)(r>o?r:r+6.283185307179586)(16)}),...Fe({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...Fe({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...Fe({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},SJ=t=>{const e=Ar(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[...gu({x:i,y:r})(n)(e)(3.141592653589793)(6.283185307179586)(24),...Fe({x:t.x+t.w,y:r})({x:t.x+t.w,y:o})(12),...gu({x:i,y:o})(n)(e)(0)(3.141592653589793)(24),...Fe({x:t.x,y:o})({x:t.x,y:r})(12)]},ei=t=>e=>e.shape==="Cylinder"?SJ(e):e.shape==="Parallelogram"?NJ(e):e.shape==="Diamond"?LJ(e):e.shape==="Ellipse"?Qc(Sn(e.w)(e.h)/2)(e):e.shape==="Document"?CJ(e):e.shape==="Cloud"?kJ(e):Qc(t)(e),EJ=t=>{const e=Ar(t.h*.075)(t.w*.075),n=t.w/2;return gu({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},RJ=t=>e=>n=>b(r=>o=>{const i=r.pos+o.len,a=n<i?(n-r.pos)/o.len:1,s={x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a},u=e>r.pos?(e-r.pos)/o.len:0,g={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,f=_>=0&&_<r.points.length?(()=>{const l=r.points[_].x-g.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const d=r.points[_].y-g.y;return d<0?-d<1e-4:d<1e-4})()})()?Et(r.points)(s):[...r.points,g,s]:[g,s];return o.len<=0||i<=e||r.pos>=n?{...r,pos:i}:{pos:i,points:f}})({pos:0,points:[]})(t).points,PJ=t=>e=>n=>{const r=It(o=>y,o=>i=>T("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const o=bJ(t),i=wJ(o),a=Ql(0)(i)(e*i),s=Ql(0)(i)(n*i);return s<=a?[]:RJ(o)(a)(s)}c()},GJ=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,g=n.y-t.y,_=a*i-s*o,f=(u*i-g*o)/_,l=(u*s-g*a)/_;return(_<0?-_<1e-9:_<1e-9)?y:f>=0&&f<=1&&l>=0&&l<=1?T("Just",f):y},BJ=t=>e=>n=>{const r=Rt(o=>i=>at.compare(o.t)(i.t))(ht(o=>{const i=GJ(e)(n)(o._1)(o._2);return i.tag==="Just"?T("Just",{t:i._1,p:{x:e.x+(n.x-e.x)*i._1,y:e.y+(n.y-e.y)*i._1}}):y})(He(mn,t,[...Bt(1,t.length,t),...Bt(0,1,t)])));return 0<r.length?T("Just",r[0].p):y},ql=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=BJ(t)(n._1.init[r])(n._1.last);if(o.tag==="Just")return Et(n._1.init)(o._1);if(o.tag==="Nothing")return e;c()}return e}c()},Vl=t=>t,cu=(t,e)=>({tag:t,_1:e}),Xi=(t,e,n)=>({tag:t,_1:e,_2:n}),Ul=t=>t,ni=(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}),Hc=Ul("PlopIn"),AJ=Ul("PlopOut"),IJ=Vl("DiveIn"),zJ=Vl("DiveOut"),Kl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Zi=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=B.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}}c()}return o},ji=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=B.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}}c()}return o},Oc=(()=>{const t=un.unfoldr(Yn);return e=>t(gn("IterNode",e,Un))})(),FJ=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;c()},Wc=t=>e=>{const n=Kl(e)(t.keyframes);if(n.tag==="Nothing")return H;if(n.tag==="Just")return n._1.nodes;c()},Yl=t=>e=>Zi(e)(t.activePlopOuts)?!0:Zi(e)(t.pastPlopOuts)?!1:Zi(e)(t.activeNodes)?!0:Zi(e)(t.futurePlopIns)?!1:Zi(e)(t.currentNodes),DJ=t=>e=>n=>oe(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),MJ=t=>e=>n=>oe(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),QJ=t=>e=>n=>oe(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),HJ=t=>e=>n=>oe(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),_u=t=>e=>n=>oe(r=>n(r)&&e>=r.startT&&e<r.endT,t),OJ=b(FJ),ta=t=>e=>{if(e<t.startT)return Xi("AtKeyframe",t.initialKeyframe);const n=te(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Xi("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Xi("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return Xi("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode"||n._1.scene.tag==="StepScene")return Xi("AtKeyframe",t.initialKeyframe);c()}if(n.tag==="Nothing")return Xi("AtKeyframe",OJ(t.initialKeyframe)(t.spans));c()},$c=t=>e=>{const n=Kl(e)(t.keyframes);if(n.tag==="Nothing")return H;if(n.tag==="Just")return n._1.edges;c()},WJ=t=>e=>ji(e)(t.activeRetracts)?!0:ji(e)(t.pastRetracts)?!1:ji(e)(t.activeEdges)?!0:ji(e)(t.futureExtends)?!1:ji(e)(t.currentEdges),qc=t=>e=>{const n=ta(t)(e);if(n.tag==="AtKeyframe")return Wc(t)(n._1);if(n.tag==="InTransition")return en(B.compare,je,Wc(t)(n._1),Wc(t)(n._2));c()},Xl=t=>e=>n=>_u(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n&&r.target._2==="PlopOut")?!0:MJ(t.windows)(e)(n)?!1:_u(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n)?!0:QJ(t.windows)(e)(n)?!1:Zi(n)(qc(t)(e)),Vc=t=>e=>{const n=ta(t)(e);if(n.tag==="AtKeyframe")return $c(t)(n._1);if(n.tag==="InTransition")return en(B.compare,je,$c(t)(n._1),$c(t)(n._2));c()},$J=t=>e=>n=>_u(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n)?!0:DJ(t.windows)(e)(n)?!1:_u(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._1===n)?!0:HJ(t.windows)(e)(n)?!1:ji(n)(Vc(t)(e)),Zl=t=>e=>b(n=>r=>{const o=e>=r.startT&&e<r.endT;return r.target.tag==="NodeWindow"?{...n,activeNodes:o?it(B)(r.target._1)()(n.activeNodes):n.activeNodes,activePlopOuts:o&&r.target._2==="PlopOut"?it(B)(r.target._1)()(n.activePlopOuts):n.activePlopOuts,pastPlopOuts:r.endT<=e&&r.target._2==="PlopOut"?it(B)(r.target._1)()(n.pastPlopOuts):n.pastPlopOuts,futurePlopIns:r.startT>e&&r.target._2==="PlopIn"?it(B)(r.target._1)()(n.futurePlopIns):n.futurePlopIns}:r.target.tag==="EdgeWindow"?{...n,activeEdges:o?it(B)(r.target._1)()(n.activeEdges):n.activeEdges,activeRetracts:o&&r.target._2.tag==="Retract"?it(B)(r.target._1)()(n.activeRetracts):n.activeRetracts,pastRetracts:r.endT<=e&&r.target._2.tag==="Retract"?it(B)(r.target._1)()(n.pastRetracts):n.pastRetracts,futureExtends:r.startT>e&&r.target._2.tag==="Extend"?it(B)(r.target._1)()(n.futureExtends):n.futureExtends}:n})({currentNodes:qc(t)(e),currentEdges:Vc(t)(e),activeNodes:H,activePlopOuts:H,pastPlopOuts:H,futurePlopIns:H,activeEdges:H,activeRetracts:H,pastRetracts:H,futureExtends:H})(t.windows),qJ=t=>e=>{const n=Zl(t)(e);return ht(r=>Yl(n)(r._1)?T("Just",{x:r._2.x,y:r._2.y,w:r._2.w,h:r._2.h}):y)(Oc(t.layout.nodes))},VJ=t=>e=>{const n=qJ(t)(e);return n.length===0?y:T("Just",ae(n))},za=t=>e=>{const n=Zl(t)(e),r=[...ht(o=>Yl(n)(o._1)?T("Just",{x:o._2.x,y:o._2.y,w:o._2.w,h:o._2.h}):y)(Oc(t.layout.nodes)),...ht(o=>WJ(n)(o._1)?T("Just",Pa(o._2)):y)(Oc(t.layout.edges))];return r.length===0?y:T("Just",ae(r))},UJ=t=>e=>e.map(t),ne=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},rn=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},Ye=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},KJ=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},En=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Jo=bs(zi),ri=t=>t,jl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},wr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},YJ=(()=>{const t=un.unfoldr(Yn);return e=>t(gn("IterNode",e,Un))})(),XJ=t=>e=>rn(0)(1)((t-e.pre)/ne(.05)(1-e.pre-e.post)),td=t=>e=>n=>{const r=Ye(n)(t.nodes),o=Ye(e)(t.nodes);if(o.tag==="Just"&&r.tag==="Just"){const i=r._1.x+r._1.w/2-(o._1.x+o._1.w/2),a=r._1.y+r._1.h/2-(o._1.y+o._1.h/2),s=ne(xe(i))(xe(a));return s<=.001?{x:0,y:0}:{x:i/s,y:a/s}}return{x:0,y:0}},Uc=t=>e=>n=>r=>o=>i=>{const a=s=>{if(s)return 0<e.length?e[0]:{x:0,y:0};const u=e.length-1|0;return u>=0&&u<e.length?e[u]:{x:0,y:0}};return Nw(e)((()=>{const s=a(!0),u=Ye(n)(t.nodes);return u.tag==="Just"?{x:u._1.x+u._1.w/2,y:u._1.y+u._1.h/2}:s})())((()=>{const s=a(!1),u=Ye(r)(t.nodes);return u.tag==="Just"?{x:u._1.x+u._1.w/2,y:u._1.y+u._1.h/2}:s})())(o)(i)},ZJ=t=>e=>t.labelBasePx*.62*ot(b(KJ)(0)(Y(mw)(St(e)(n=>$i(`
|
|
6
|
-
`)(n))))),fu=t=>e=>n=>rn(0)(1)((n-t)/ne(1e-4)(e-t)),jJ=t=>e=>ot(In(jn(e)))*t*.62,ed=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,g=o<0?-o:o;return e<=t?(t+e)/2:g<=u?n:r+i*(a-s*co(-(g-u)/s))},Kc=t=>e=>n=>({...n,center:{x:e.w>t.w?n.center.x+(e.x+e.w/2-(t.x+t.w/2)):e.x<t.x?n.center.x+(e.x-t.x):e.x+e.w>t.x+t.w?n.center.x+(e.x+e.w-t.x-t.w):n.center.x+0,y:e.h>t.h?n.center.y+(e.y+e.h/2-(t.y+t.h/2)):e.y<t.y?n.center.y+(e.y-t.y):e.y+e.h>t.y+t.h?n.center.y+(e.y+e.h-t.y-t.h):n.center.y+0}}),Fa=t=>e=>n=>r=>{const o=te(i=>Jo(i.path)(e)&&(xe(i.endT-n)<1e-4||xe(i.startT-r)<1e-4))(t.segments);if(o.tag==="Just")return T("Just",o._1);if(o.tag==="Nothing")return te(i=>Jo(i.path)(e))(t.segments);c()},tT=t=>ht(e=>{const n=VJ(t)(ne(e.startT)(e.endT-1e-4));if(n.tag==="Nothing")return y;if(n.tag==="Just")return T("Just",{startT:e.startT,endT:e.endT,bbox:n._1,priority:0,continuous:!1,stationary:!1});c()}),eT=t=>e=>{const n=Cc({width:t.widthPx,height:t.heightPx})({vx:e.bounds.x,vy:e.bounds.y,vw:e.bounds.w,vh:e.bounds.h});return{w:n.vw,h:n.vh}},nT=t=>e=>n=>r=>{const o=ne(n.center.x-r.x)(r.x+r.w-n.center.x),i=ne(n.center.y-r.y)(r.y+r.h-n.center.y),a=eT(t)(e);return En(o<=0?n.zoom:a.w/(o*2))(i<=0?n.zoom:a.h/(i*2))},nd=t=>e=>n=>r=>o=>{const i=(s,u)=>{const g=Jn(u);return kn(Dt(_=>f=>{const l=t*1.2,d=s.y+s.h/2-ot(g.length)*l/2+ot(_)*l;return b(h=>m=>{const p=ot(In(jn(m.text)))*t*.62;return{x:h.x+p,boxes:m.style==="RunHighlight"||m.style==="RunBoldHighlight"||m.style==="RunCodeHighlight"||m.style==="RunCodeBoldHighlight"?Et(h.boxes)({x:h.x,y:d,w:p,h:l}):h.boxes}})({x:s.x+s.w/2-ot(In(jn(f)))*t*.62/2,boxes:[]})(Zn(f)).boxes})(g))},a=Ye(n)(e.layout.nodes);if(a.tag==="Just"){const s=[...i(a._1,r),...i(a._1,o)];return s.length===0?y:T("Just",ae(s))}if(a.tag==="Nothing")return y;c()},Yc=t=>e=>n=>{const r=Jn(n),o=b(ne)(t)(Y(jJ(t))(r)),i=ne(t)(ot(r.length)*t*1.2);return T("Just",{x:e.x+e.w/2-o/2,y:e.y+e.h/2-i/2,w:o,h:i})},rT=t=>e=>n=>r=>{const o=b(ne)(r.startT-t.maxTransition)(ht(i=>i.startT>r.startT+1e-4?y:i.target.tag==="NodeWindow"&&i.target._2==="PlopIn"&&i.target._1===r.target?T("Just",i.startT):y)(e.windows));return rn(0)(1)((n-o)/ne(1e-4)(r.startT-o))},rd=t=>{const e=It(n=>y,n=>r=>T("Just",{head:n,tail:r}),ht(ri)(t));if(e.tag==="Nothing")return y;if(e.tag==="Just")return T("Just",b(n=>r=>({whole:ae([n.whole,r.whole]),text:(()=>{if(n.text.tag==="Just"){if(r.text.tag==="Just")return T("Just",ae([n.text._1,r.text._1]));if(r.text.tag==="Nothing")return T("Just",n.text._1);c()}if(n.text.tag==="Nothing"){if(r.text.tag==="Just")return T("Just",r.text._1);if(r.text.tag==="Nothing")return y}c()})(),guide:(()=>{if(n.guide.tag==="Just"){if(r.guide.tag==="Just")return T("Just",ae([n.guide._1,r.guide._1]));if(r.guide.tag==="Nothing")return T("Just",n.guide._1);c()}if(n.guide.tag==="Nothing"){if(r.guide.tag==="Just")return T("Just",r.guide._1);if(r.guide.tag==="Nothing")return y}c()})()}))(e._1.head)(e._1.tail));c()},oT=t=>e=>n=>r=>({...r,fromCam:yc(t)(e)(n)(r.fromCam),toCam:yc(t)(e)(n)(r.toCam)}),iT=t=>e=>n=>r=>o=>i=>a=>{const s=a*a*(3-2*a),u=td(t)(e)(n),g=(()=>{if(r)return 1;const f=rn(0)(1)(i/.12);return f*f*(3-2*f)})(),_={x:0+(u.x-0)*g,y:0+(u.y-0)*g};if(o.tag==="Just"){const f=td(t)(o._1.source)(o._1.target);return{x:_.x+(f.x-_.x)*s,y:_.y+(f.y-_.y)*s}}if(o.tag==="Nothing")return _;c()},aT=t=>e=>n=>oe(r=>r.endT<=e&&r.target.tag==="RelabelWindow"&&r.target._1===n,t),sT=t=>e=>n=>{const r=Ye(n)(t.layout.nodes),o=r.tag==="Just"&&r._1.label!==""?r._1.label:n,i=ta(t)(e),a=(()=>{if(i.tag==="AtKeyframe")return jl(i._1)(t.keyframes);if(i.tag==="InTransition")return jl(aT(t.windows)(e)(n)?i._2:i._1)(t.keyframes);c()})(),s=(()=>{if(a.tag==="Just")return Ye(n)(a._1.labels);if(a.tag==="Nothing")return y;c()})();if(s.tag==="Nothing")return o;if(s.tag==="Just")return s._1;c()},lu=t=>e=>n=>r=>{const o=Ye(r)(e.layout.nodes);if(o.tag==="Just")return Yc(t)(o._1)(sT(e)(n)(r));if(o.tag==="Nothing")return y;c()},uT=t=>e=>n=>{if(e.length===0)return n;const r=En(160)(ZJ(t)(e)+32)/2;return{x:n.x-r,y:n.y-30.6,w:n.w+r+r,h:n.h+40.6}},oi=t=>e=>n=>r=>o=>{const i={width:e.widthPx,height:e.heightPx},a=Cc(i)((()=>{if(r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0){const s=_r(n)(o);return{vx:s.x-t.padding,vy:s.y-t.padding,vw:s.w+t.padding*2,vh:s.h+t.padding*2}}return{vx:_r(n)(o).x,vy:_r(n)(o).y,vw:_r(n)(o).w,vh:_r(n)(o).h}})());return t.labelBasePx*r.placement.scale*(i.width<=0||a.vw<=0?0:i.width/a.vw)},od=t=>e=>n=>r=>(o=>i=>{let a=o,s=i,u=!0,g;for(;u;){const _=a,f=s,l=oi(t)(e)(n)(r)(f);if(e.widthPx<=0||e.heightPx<=0||l<=0||l>=t.minimumReadableLabelPx){u=!1,g=f;continue}if(_<=0){u=!1,g=f;continue}a=_-1|0,s={...f,zoom:f.zoom*t.minimumReadableLabelPx/l}}return g})(8),fn=t=>e=>n=>r=>{const o=Cc({width:t.widthPx,height:t.heightPx})((()=>{const i=_r(n)(r);return{vx:i.x-e,vy:i.y-e,vw:i.w+e*2,vh:i.h+e*2}})());return{x:o.vx,y:o.vy,w:o.vw,h:o.vh}},gT=t=>e=>n=>r=>{const o=Ye(e)(t.nodes);if(o.tag==="Just"){const i=o._1.x+o._1.w/2,a=o._1.y+o._1.h/2,s=Ye(n)(t.nodes);if(s.tag==="Just")return T("Just",{x:i+(s._1.x+s._1.w/2-i)*r-6,y:a+(s._1.y+s._1.h/2-a)*r-6,w:12,h:12})}return y},Xc=t=>e=>n=>r=>o=>i=>{const a=Y((()=>{const s=t.padding;return u=>({x:u.x-s,y:u.y-s,w:u.w+s*2,h:u.h+s*2})})())(ht(lu(t.labelBasePx)(e)(n))([r,o]));return a.length===0?i:ae([i,...a])},cT=t=>e=>n=>r=>o=>i=>a=>s=>{const u=Xc(t)(e)(n)(r)(o)(s);if(i.tag==="Nothing")return u;if(i.tag==="Just"){const g=Xc(t)(e)(n)(i._1.source)(i._1.target)(s),_=a*a*(3-2*a);return{x:u.x+(g.x-u.x)*_,y:u.y+(g.y-u.y)*_,w:u.w+(g.w-u.w)*_,h:u.h+(g.h-u.h)*_}}c()},id=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>{const _=i.x-6,f=i.y-6;return T("Just",{visibleBounds:(()=>{const l=za(e)(n);return l.tag==="Just"?T("Just",{x:l._1.x*e.placement.scale+e.placement.tx,y:l._1.y*e.placement.scale+e.placement.ty,w:l._1.w*e.placement.scale,h:l._1.h*e.placement.scale}):y})(),subject:T("Just",{x:_*e.placement.scale+e.placement.tx,y:f*e.placement.scale+e.placement.ty,w:12*e.placement.scale,h:12*e.placement.scale}),guide:(()=>{const l=gT(e.layout)(r)(o)(a);return l.tag==="Just"?T("Just",{x:l._1.x*e.placement.scale+e.placement.tx,y:l._1.y*e.placement.scale+e.placement.ty,w:l._1.w*e.placement.scale,h:l._1.h*e.placement.scale}):y})(),mustSee:T("Just",(()=>{const l=cT(t)(e)(n)(r)(o)(g)(s)({x:_-t.padding,y:f-t.padding,w:12+t.padding*2,h:12+t.padding*2});return{x:l.x*e.placement.scale+e.placement.tx,y:l.y*e.placement.scale+e.placement.ty,w:l.w*e.placement.scale,h:l.h*e.placement.scale}})()),lookAhead:T("Just",iT(e.layout)(r)(o)(u)(g)(a)(s))})},du=t=>e=>n=>r=>o=>i=>{const a=Xc(t)(e)(n)(r)(o)(i);return{x:a.x,y:i.y,w:a.w,h:i.h}},_T=t=>e=>n=>r=>o=>i=>a=>s=>{let u=t,g=e,_=n,f=r,l=o,d=i,h=a,m=s,p=!0,x;for(;p;){const w=u,J=g,N=_,k=f,C=l,R=d,P=h,I=m,U=N.path.length!==0,S=fn(w)(N.path.length===0||N.placement.scale===1&&N.placement.tx===0&&N.placement.ty===0?k.padding:0)(J)(I),v=ne(R)(I.zoom*En(S.w/ne(1e-4)(C.w))(S.h/ne(1e-4)(C.h)));if(P<=0){p=!1,x=I;continue}if(U&&xe(v-I.zoom)<1e-6){p=!1,x=I;continue}if(U){u=w,g=J,_=N,f=k,l=C,d=R,h=P-1|0,m={...I,zoom:v};continue}if(C.w<=S.w+.001&&C.h<=S.h+.001){p=!1,x=I;continue}if(v>=I.zoom-1e-6){p=!1,x=I;continue}u=w,g=J,_=N,f=k,l=C,d=R,h=P-1|0,m={...I,zoom:v}}return x},fT=t=>e=>n=>r=>{const o=wr(r)(e.edgeEndpoints),i=wr(r)(e.layout.edges);if(i.tag==="Just"&&o.tag==="Just"){const a=Vo(e.layout)(e.edgeEndpoints)(r),s=du(t)(e)(n)(o._1.source)(o._1.target)(Pa(i._1));return{x:s.x,y:a.y,w:s.w,h:a.h}}return Vo(e.layout)(e.edgeEndpoints)(r)},ad=t=>e=>n=>r=>{const o=Ol(8)(t);if(n==="ExtendFromSource")return{path:o,source:e.source,target:e.target,progress:rn(0)(1)(r)};if(n==="ExtendFromTarget")return{path:re(o),source:e.target,target:e.source,progress:rn(0)(1)(r)};c()},lT=t=>e=>n=>r=>o=>i=>{const a=t.padding*.75,s=ot(48),u=o.layout;return vs(g=>{if(g.target.tag==="NodeWindow")return[];if(g.target.tag==="RelabelWindow")return[(()=>{const _=dc(u)(i)(ee("Node",1,1,g.target._1,void 0,H,H));return{startT:g.startT,endT:g.endT,bbox:(()=>{const f=nd(t.labelBasePx)(o)(g.target._1)(g.target._2)(g.target._3);if(f.tag==="Nothing")return _;if(f.tag==="Just")return f._1;c()})(),priority:1,continuous:!1,stationary:!1}})()];if(g.target.tag==="EdgeWindow"){if(g.target._2.tag==="Extend"){const _=wr(g.target._1)(i),f=wr(g.target._1)(u.edges);if(f.tag==="Just"&&_.tag==="Just"){const l=_._1,d=f._1;return St(Ut(0,47))(h=>{const m=g.startT+(g.endT-g.startT)*(ot(h)/s),p=g.startT+(g.endT-g.startT)*(ot(h+1|0)/s),x=ad(d)(l)(g.target._2._1)(Wi(r)(((m+p)/2-g.startT)/ne(1e-4)(g.endT-g.startT))),w=0<x.path.length?x.path[0]:{x:0,y:0},J=Zo(x.path)(x.progress),N=(()=>{if(J.tag==="Nothing")return w;if(J.tag==="Just")return J._1;c()})();return[{startT:m,endT:p,bbox:du(t)(o)((m+p)/2)(x.source)(x.target)({x:N.x-6,y:N.y-6,w:12,h:12}),priority:1,continuous:!0,stationary:!1}]})}return[{startT:g.startT,endT:g.endT,bbox:Vo(u)(i)(g.target._1),priority:1,continuous:!1,stationary:!1}]}if(g.target._2.tag==="Retract")return[];c()}if(g.target.tag==="TokenWindow"){if(e.widthPx>=e.heightPx*1.5&&o.path.length===0)return[{startT:g.startT,endT:g.endT,bbox:du(t)(o)((g.startT+g.endT)/2)(g.target._4)(g.target._5)((()=>{const f=ht(l=>{const d=Ye(l)(u.nodes);return d.tag==="Just"?T("Just",{x:d._1.x,y:d._1.y,w:d._1.w,h:d._1.h}):y})([g.target._4,g.target._5]);return f.length===0?Vo(u)(i)(g.target._2):ae(f)})()),priority:1,continuous:!1,stationary:!1}];const _=wr(g.target._2)(u.edges);if(_.tag==="Just"){const f=(()=>{if(g.target._3==="Forward")return _._1;if(g.target._3==="Backward")return re(_._1);c()})(),l=St(Ut(0,47))(h=>{const m=g.startT+(g.endT-g.startT)*(ot(h)/s),p=g.startT+(g.endT-g.startT)*(ot(h+1|0)/s),x=Uc(u)(f)(g.target._4)(g.target._5)(((m+p)/2-g.startT)/ne(1e-4)(g.endT-g.startT))({pre:g.target._7,post:g.target._8});return[{startT:m,endT:p,bbox:du(t)(o)((m+p)/2)(g.target._4)(g.target._5)({x:x.x-a,y:x.y-a,w:0+a*2,h:0+a*2}),priority:1,continuous:!0,stationary:!1}]}),d=ae(Y(h=>h.bbox)(l));return(()=>{const h=yc(n)(u)(o.placement)(Sf(t)(e)(u)(d).camera),m=fn(e)(o.path.length===0||o.placement.scale===1&&o.placement.tx===0&&o.placement.ty===0?t.padding:0)(n)(h);return oi(t)(e)(n)(o)(h)>=t.minimumReadableLabelPx-.001&&(()=>{const p=d.x*o.placement.scale+o.placement.tx,x=d.y*o.placement.scale+o.placement.ty;return p>=m.x-.001&&x>=m.y-.001&&p+d.w*o.placement.scale<=m.x+m.w+.001&&x+d.h*o.placement.scale<=m.y+m.h+.001})()})()?[{startT:g.startT,endT:g.endT,bbox:d,priority:1,continuous:!1,stationary:!0}]:l}if(_.tag==="Nothing")return[{startT:g.startT,endT:g.endT,bbox:Vo(u)(i)(g.target._2),priority:1,continuous:!1,stationary:!1}];c()}if(g.target.tag==="FillWindow")return[{startT:g.startT,endT:g.endT,bbox:uT(t)(g.target._3)(dc(u)(i)(ee("Node",1,1,g.target._2,void 0,H,H))),priority:1,continuous:!1,stationary:!1}];c()})},dT=t=>e=>n=>r=>o=>i=>a=>s=>[...tT(s)(_t(u=>u.startT>=s.startT&&u.endT<=s.endT,a.spans)),...lT(t)(e)(n)(r)(s)(i)(s.windows)],hT=t=>e=>n=>r=>o=>i=>a=>s=>aw(t)(e)(s.layout)(a.endT)(ht(u=>u.scene.tag==="StepScene"?T("Just",u.startT):y)(s.spans))(dT(t)(e)(n)(r)(o)(i)(a)(s)),sd=t=>e=>(()=>{if(e.subject.tag==="Nothing")return!0;if(e.subject.tag==="Just")return e.subject._1.x>=t.x&&e.subject._1.y>=t.y&&e.subject._1.x+e.subject._1.w<=t.x+t.w&&e.subject._1.y+e.subject._1.h<=t.y+t.h;c()})()&&(()=>{if(e.mustSee.tag==="Nothing")return!0;if(e.mustSee.tag==="Just")return e.mustSee._1.x>=t.x&&e.mustSee._1.y>=t.y&&e.mustSee._1.x+e.mustSee._1.w<=t.x+t.w&&e.mustSee._1.y+e.mustSee._1.h<=t.y+t.h;c()})(),ud=t=>e=>n=>r=>n>=e?rn(t+e-n/2)(t+n/2)(r):t+e/2,gd=t=>e=>n=>r=>{if((()=>{const a=_r(e)(n);return r.x>=a.x&&r.y>=a.y&&r.x+r.w<=a.x+a.w&&r.y+r.h<=a.y+a.h})())return n;const o={...n,zoom:En(n.zoom)(nT(t)(e)({...n,center:{x:r.x+r.w/2,y:r.y+r.h/2}})(r))},i=_r(e)(o);return{...o,center:{x:ud(r.x)(r.w)(i.w)(n.center.x),y:ud(r.y)(r.h)(i.h)(n.center.y)}}},pT=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=ne(o.lo)(e.x+e.w-n/2),g=En(o.hi)(e.x+n/2);return u<=g?{lo:u,hi:g}:o}const i=e.x+e.w/2;if(n>=e.w){const u=ne(o.lo)(i),g=En(o.hi)(i);return u<=g?{lo:u,hi:g}:o}const a=ne(o.lo)(e.x+n/2),s=En(o.hi)(e.x+e.w-n/2);return a<=s?{lo:a,hi:s}:o},hu=t=>e=>{if(t.tag==="Just"){if(e.tag==="Just")return T("Just",ae([t._1,e._1]));if(e.tag==="Nothing")return T("Just",t._1);c()}if(t.tag==="Nothing"){if(e.tag==="Just")return T("Just",e._1);if(e.tag==="Nothing")return y}c()},mT=t=>e=>n=>n.endT<=t||n.startT>=e?y:T("Just",{...n,startT:ne(t)(n.startT),endT:En(e)(n.endT)}),yT=t=>e=>n=>r=>o=>i=>a=>ht(mT(a.startT)(a.endT))(Y(oT(r)(a.layout)(a.placement))(hT(t)(e)(r)(n)(o)(a.edgeEndpoints)(i)(a))),xT=t=>e=>n=>r=>{const o=En(r.zoom)(t.bounds.w/ne(1e-4)(e.w));return{...r,center:{...r.center,x:(()=>{const i=pT(t.bounds)(e)(t.bounds.w/ne(1e-4)(o));return rn(i.lo)(i.hi)(n.center.x)})()},zoom:o}},wT=t=>e=>n=>{const r=t.bounds.h/ne(1e-4)(n.zoom),o=t.bounds.w/ne(1e-4)(n.zoom);return{...n,center:{x:o>=e.w?e.x+e.w/2:ed(e.x+o/2)(e.x+e.w-o/2)(n.center.x),y:r>=e.h?e.y+e.h/2:ed(e.y+r/2)(e.y+e.h-r/2)(n.center.y)}}},ea=t=>e=>n=>wT(t)((()=>{const r=e*n.placement.scale;return{x:n.layout.bounds.x*n.placement.scale+n.placement.tx-r,y:n.layout.bounds.y*n.placement.scale+n.placement.ty-r,w:n.layout.bounds.w*n.placement.scale+r*2,h:n.layout.bounds.h*n.placement.scale+r*2}})()),JT=t=>e=>n=>r=>{const o=_r(t)(r),i=t.bounds,a=s=>{const u=ea(t)(e)(n)(s);return ea(t)(e)(n)({...u,zoom:ne(u.zoom)(ne(i.w/ne(1e-4)(2*En(u.center.x-o.x)(o.x+o.w-u.center.x)))(i.h/ne(1e-4)(2*En(u.center.y-o.y)(o.y+o.h-u.center.y))))})};return s=>a(a(s))},TT=t=>e=>n=>r=>ea(n)(t.padding)(r)(tx(t)(e)(n)(r.placement)(r.layout.bounds).camera),NT=t=>e=>n=>r=>o=>{const i=TT(t)(e)(n)(o),a=te(s=>s.direction==="DiveIn"&&Jo(s.childPath)(o.path))(r.dives);if(a.tag==="Just"){const s=Fa(r)(a._1.parentPath)(a._1.startT)(a._1.endT);if(s.tag==="Just"){const u=Ye(a._1.node)(s._1.layout.nodes);if(u.tag==="Just"){const g=u._1.w*s._1.placement.scale,_=u._1.h*s._1.placement.scale,f=En(g)(_*2),l=ex(e)(n)({h:_,w:f,x:u._1.x*s._1.placement.scale+s._1.placement.tx+(g-f)*.5,y:u._1.y*s._1.placement.scale+s._1.placement.ty});return JT(n)(t.padding)(o)(l)(l.zoom>i.zoom?l:i)}if(u.tag==="Nothing")return i;c()}if(s.tag==="Nothing")return i;c()}if(a.tag==="Nothing")return i;c()},na=t=>e=>n=>r=>o=>i=>{if(r.direction==="DiveIn"){const a=ea(n)(t.padding)(o)(Xo(t)(n)(i)(r.startT-1e-4).camera),s=od(t)(e)(n)(o)(a),u=Ye(r.node)(o.layout.nodes);return r.direction==="DiveIn"&&u.tag==="Just"?gd(e)(n)(s)({x:u._1.x*o.placement.scale+o.placement.tx+u._1.w*o.placement.scale/2-.5,y:u._1.y*o.placement.scale+o.placement.ty+u._1.h*o.placement.scale/2-.5,w:1,h:1}):a}if(r.direction==="DiveOut"){const a=ea(n)(t.padding)(o)(Xo(t)(n)(i)(r.endT+1e-4).camera),s=od(t)(e)(n)(o)(a),u=Ye(r.node)(o.layout.nodes);return r.direction==="DiveIn"&&u.tag==="Just"?gd(e)(n)(s)({x:u._1.x*o.placement.scale+o.placement.tx+u._1.w*o.placement.scale/2-.5,y:u._1.y*o.placement.scale+o.placement.ty+u._1.h*o.placement.scale/2-.5,w:1,h:1}):a}c()},bT=t=>t.target.tag==="NodeWindow"||t.target.tag==="RelabelWindow"||t.target.tag==="EdgeWindow"||t.target.tag==="TokenWindow"||t.target.tag==="FillWindow",cd=t=>Rt(at.compare)(Ur(at.compare)(St(_t(bT,t.windows))(e=>[e.startT,e.endT]))),_d=t=>e=>n=>r=>o=>i=>{if(o.tag==="Just"){if(i.tag==="Just"){const a=ae([o._1,i._1]);return r<e?T("Just",(()=>{const s=fu(t)(e)(r);return{x:o._1.x+(a.x-o._1.x)*s,y:o._1.y+(a.y-o._1.y)*s,w:o._1.w+(a.w-o._1.w)*s,h:o._1.h+(a.h-o._1.h)*s}})()):T("Just",(()=>{const s=fu(e)(n)(r);return{x:a.x+(i._1.x-a.x)*s,y:a.y+(i._1.y-a.y)*s,w:a.w+(i._1.w-a.w)*s,h:a.h+(i._1.h-a.h)*s}})())}if(i.tag==="Nothing")return T("Just",(()=>{const a=fu(t)(n)(r);return{x:o._1.x+(o._1.x+o._1.w/2-o._1.x)*a,y:o._1.y+(o._1.y+o._1.h/2-o._1.y)*a,w:o._1.w+-o._1.w*a,h:o._1.h+-o._1.h*a}})());c()}if(o.tag==="Nothing"){if(i.tag==="Just")return T("Just",(()=>{const a=i._1.x+i._1.w/2,s=i._1.y+i._1.h/2,u=fu(t)(n)(r);return{x:a+(i._1.x-a)*u,y:s+(i._1.y-s)*u,w:0+(i._1.w-0)*u,h:0+(i._1.h-0)*u}})());if(i.tag==="Nothing")return y}c()},fd=t=>e=>n=>r=>{const o=r.path.length===0?t.minimumReadableLabelPx*1:t.minimumReadableLabelPx*1.8;return(i=>a=>{let s=i,u=a,g=!0,_;for(;g;){const f=s,l=u,d=oi(t)(e)(n)(r)(l);if(f<=0){g=!1,_=l.zoom;continue}if(e.widthPx<=0||e.heightPx<=0){g=!1,_=l.zoom;continue}if(d<=0){g=!1,_=l.zoom;continue}if(xe(d-o)<.001){g=!1,_=l.zoom;continue}s=f-1|0,u={...l,zoom:l.zoom*o/d}}return _})(12)({center:(()=>{const i=t.padding*r.placement.scale;return{x:r.layout.bounds.x*r.placement.scale+r.placement.tx-i+(r.layout.bounds.w*r.placement.scale+i*2)/2,y:r.layout.bounds.y*r.placement.scale+r.placement.ty-i+(r.layout.bounds.h*r.placement.scale+i*2)/2}})(),zoom:1})},Zc=t=>e=>n=>r=>o=>{const i=fn(t)(e)(n)(o);return{...o,center:{x:i.w>r.w+ne(1)(xe(r.w))*1e-9?o.center.x+(r.x+r.w/2-(i.x+i.w/2)):i.x<r.x?o.center.x+(r.x-i.x):i.x+i.w>r.x+r.w?o.center.x+(r.x+r.w-i.x-i.w):o.center.x+0,y:i.h>r.h+ne(1)(xe(r.h))*1e-9?o.center.y+(r.y+r.h/2-(i.y+i.h/2)):i.y<r.y?o.center.y+(r.y-i.y):i.y+i.h>r.y+r.h?o.center.y+(r.y+r.h-i.y-i.h):o.center.y+0}}},vT=t=>e=>n=>r=>Zc(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)((()=>{const o=t.padding*r.placement.scale;return{x:r.layout.bounds.x*r.placement.scale+r.placement.tx-o,y:r.layout.bounds.y*r.placement.scale+r.placement.ty-o,w:r.layout.bounds.w*r.placement.scale+o*2,h:r.layout.bounds.h*r.placement.scale+o*2}})()),To=t=>e=>n=>r=>o=>i=>{const a=fd(t)(e)(n)(r),s=(()=>{if(r.path.length===0)return{x:n.bounds.x-t.padding,y:n.bounds.y-t.padding,w:n.bounds.w+t.padding*2,h:n.bounds.h+t.padding*2};const m=t.padding*r.placement.scale;return{x:r.layout.bounds.x*r.placement.scale+r.placement.tx-m,y:r.layout.bounds.y*r.placement.scale+r.placement.ty-m,w:r.layout.bounds.w*r.placement.scale+m*2,h:r.layout.bounds.h*r.placement.scale+m*2}})(),u=r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0,g=r.path.length!==0,_=r.path.length===0?a:0,f=Zc(e)(u)(n)(s)({...i,zoom:ne(a)(i.zoom)}),l=fn(e)(u)(n)(f),d=(()=>{if(o.tag==="Nothing")return f;if(o.tag==="Just")return _T(e)(n)(r)(t)(o._1)(_)(12)(f);c()})(),h=fn(e)(u)(n)(d);if(o.tag==="Nothing")return f;if(o.tag==="Just")return g?Kc(h)(o._1)(d):o._1.x>=l.x-.001&&o._1.y>=l.y-.001&&o._1.x+o._1.w<=l.x+l.w+.001&&o._1.y+o._1.h<=l.y+l.h+.001?f:o._1.w<=h.w+.001&&o._1.h<=h.h+.001?Kc(h)(o._1)(d):Zc(e)(u)(n)(ae([s,o._1]))(Kc(h)(o._1)(d));c()},CT=t=>e=>n=>r=>o=>i=>a=>{const s=t.padding*r.placement.scale,u={x:r.layout.bounds.x*r.placement.scale+r.placement.tx-s,y:r.layout.bounds.y*r.placement.scale+r.placement.ty-s,w:r.layout.bounds.w*r.placement.scale+s*2,h:r.layout.bounds.h*r.placement.scale+s*2},g=x=>sd(fn(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)(x))(i),_=x=>w=>J=>N=>{let k=x,C=w,R=J,P=N,I=!0,U;for(;I;){const S=k,v=C,D=R,W=P;if(S<=0){I=!1,U=W;continue}const M={...o,zoom:(v+D)/2},q=fn(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)(M),$={...M,center:bc(Nc)(u)({w:q.w,h:q.h})(o.center)(i)};if(g($)){k=S-1|0,C=$.zoom,R=D,P=$;continue}k=S-1|0,C=v,R=$.zoom,P=W}return U},f=fn(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)(a),l=fn(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)(o),d=oi(t)(e)(n)(r)(o)>=t.minimumReadableLabelPx-.001,h={...o,center:bc(Nc)(u)({w:l.w,h:l.h})(o.center)(i)},m=sd(fn(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)(h))(i),p={...a,center:bc(Nc)(u)({w:f.w,h:f.h})(o.center)(i)};return p.zoom>h.zoom&&g(p)?p:d&&m?h:p.zoom>=h.zoom||!g(p)?p:_(12)(p.zoom)(o.zoom)(p)},LT=t=>Y(e=>{const n=te(i=>e.startT<i.startT&&e.endT>=i.startT-1e-4)(t),r=(()=>{if(n.tag==="Just")return{...e,endT:n._1.startT,toCam:n._1.fromCam,easing:fr,interp:Ko,intent:$f};if(n.tag==="Nothing")return e;c()})(),o=te(i=>r.startT<=i.endT+1e-4&&r.endT>i.endT)(t);if(o.tag==="Just")return{...r,startT:o._1.endT,fromCam:o._1.toCam,easing:fr,interp:Ko,intent:$f};if(o.tag==="Nothing")return r;c()}),kT=t=>e=>n=>r=>o=>i=>a=>{const s=r.layout.bounds.w*r.placement.scale,u=s/ne(1e-4)(r.layout.bounds.h*r.placement.scale);if(o.tag==="Nothing")return a;if(o.tag==="Just"){const g=xT(n)(o._1)(i)(a);return oi(t)(e)(n)(r)(g)>=t.minimumReadableLabelPx-.001||o._1.w>=s-.001&&u>=.33&&oi(t)(e)(n)(r)(g)>=t.minimumReadableLabelPx*1?g:a}c()},ST=t=>e=>n=>{const r=Rt(o=>i=>at.compare(o.startT)(i.startT))(_t(o=>o.startT>=e.endT-1e-4&&o.startT-e.endT<=1.1001&&o.target.tag==="TokenWindow",t.windows));return 0<r.length&&r[0].target.tag==="TokenWindow"&&r[0].target._4===n?T("Just",{source:r[0].target._4,target:r[0].target._5,startT:r[0].startT}):y},ET=t=>e=>n=>{const r=Rt(i=>a=>at.compare(i.endT)(a.endT))(_t(i=>i.endT<=e.startT+1e-4&&e.startT-i.endT<=1.1001&&i.target.tag==="TokenWindow",t.windows)),o=r.length-1|0;return o>=0&&o<r.length&&r[o].target.tag==="TokenWindow"&&r[o].target._5===n},RT=t=>e=>n=>r=>o=>{if(r.target.tag==="TokenWindow"){const i=wr(r.target._2)(n.layout.edges);if(i.tag==="Just"){const a=(o-r.startT)/ne(1e-4)(r.endT-r.startT),s=ST(n)(r)(r.target._5);return id(t)(n)(o)(r.target._4)(r.target._5)(Uc(n.layout)((()=>{if(r.target._3==="Forward")return i._1;if(r.target._3==="Backward")return re(i._1);c()})())(r.target._4)(r.target._5)(a)({pre:r.target._7,post:r.target._8}))(XJ(a)({pre:r.target._7,post:r.target._8}))(s.tag==="Just"?rT(t)(n)(o)(s._1):0)(ET(n)(r)(r.target._4))(s)}if(i.tag==="Nothing")return y;c()}if(r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"){const i=wr(r.target._1)(n.layout.edges);if(i.tag==="Just"){const a=wr(r.target._1)(n.edgeEndpoints);if(a.tag==="Just"){const s=ad(i._1)(a._1)(r.target._2._1)(Wi(e)((o-r.startT)/ne(1e-4)(r.endT-r.startT)));return id(t)(n)(o)(s.source)(s.target)((()=>{const u=0<s.path.length?s.path[0]:{x:0,y:0},g=Zo(s.path)(s.progress);if(g.tag==="Nothing")return u;if(g.tag==="Just")return g._1;c()})())(s.progress)(0)(!1)(y)}if(a.tag==="Nothing")return y;c()}if(i.tag==="Nothing")return y;c()}return y},PT=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=i=>n<i.startT?i.startT-n:n>i.endT?n-i.endT:0,o=Rt(i=>a=>{const s=at.compare(r(i))(r(a));return s==="EQ"?at.compare(a.startT)(i.startT):s})(_t(i=>e.startT<i.endT-1e-4&&e.endT>i.startT+1e-4&&(i.target.tag==="RelabelWindow"?!0:i.target.tag==="EdgeWindow"?i.target._2.tag==="Extend":i.target.tag==="TokenWindow"||i.target.tag==="FillWindow"),t.windows));return 0<o.length?rn(o[0].startT+1e-4)(o[0].endT-1e-4)(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):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},GT=t=>e=>n=>{const r=n.fromCam.zoom===n.toCam.zoom&&n.fromCam.center.x===n.toCam.center.x&&n.fromCam.center.y===n.toCam.center.y?(n.startT+n.endT)/2:n.endT+1e-4,o=a=>r<a.startT?a.startT-r:r>a.endT?r-a.endT:0,i=Rt(a=>s=>at.compare(o(a))(o(s)))(_t(a=>n.startT<a.endT-1e-4&&n.endT>a.startT+1e-4&&a.target.tag==="TokenWindow",e.windows));return 0<i.length?RT(t)(mc)(e)(i[0])(rn(i[0].startT+1e-4)(i[0].endT-1e-4)(PT(e)(n))):y},Ir=t=>e=>n=>{const r=(i,a)=>{const s=ht(lu(t.labelBasePx)(e)(n))([i,a]);return s.length===0?y:T("Just",ae(s))},o=It(i=>y,i=>a=>T("Just",{head:i,tail:a}),ht(i=>{if(i.startT<=n&&n<i.endT){if(i.target.tag==="NodeWindow"){const a=Ye(i.target._1)(e.layout.nodes);if(a.tag==="Just")return T("Just",{whole:(()=>{const s=_t(g=>(g._2.source===i.target._1||g._2.target===i.target._1)&&Xl(e)(n)(g._2.source)&&Xl(e)(n)(g._2.target)&&$J(e)(n)(g._1),YJ(e.edgeEndpoints)),u=[...ht(g=>{const _=Ye(g)(e.layout.nodes);return _.tag==="Just"?T("Just",{x:_._1.x,y:_._1.y,w:_._1.w,h:_._1.h}):y})(Ur(B.compare)([...St(s)(g=>[g._2.source,g._2.target]),i.target._1])),...ht(g=>{const _=wr(g._1)(e.layout.edges);return _.tag==="Just"?T("Just",Pa(_._1)):y})(s)];return u.length===0?{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}:ae(u)})(),text:lu(t.labelBasePx)(e)(n)(i.target._1),guide:y});if(a.tag==="Nothing")return y;c()}if(i.target.tag==="RelabelWindow"){const a=Ye(i.target._1)(e.layout.nodes);if(a.tag==="Just"){const s=ht(ri)([Yc(t.labelBasePx)(a._1)(i.target._2),Yc(t.labelBasePx)(a._1)(i.target._3)]),u=s.length===0?y:T("Just",ae(s)),g={x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h};return T("Just",{whole:(()=>{if(u.tag==="Just")return ae([g,u._1]);if(u.tag==="Nothing")return g;c()})(),text:u,guide:nd(t.labelBasePx)(e)(i.target._1)(i.target._2)(i.target._3)})}if(a.tag==="Nothing")return y;c()}if(i.target.tag==="EdgeWindow")return T("Just",(()=>{const a=fT(t)(e)(n)(i.target._1),s=wr(i.target._1)(e.edgeEndpoints);if(s.tag==="Just"){const u=r(s._1.source,s._1.target);return{whole:(()=>{if(u.tag==="Nothing")return a;if(u.tag==="Just")return u._1;c()})(),text:u,guide:T("Just",a)}}if(s.tag==="Nothing")return{whole:Vo(e.layout)(e.edgeEndpoints)(i.target._1),text:y,guide:T("Just",a)};c()})());if(i.target.tag==="TokenWindow")return T("Just",(()=>{const a=r(i.target._4,i.target._5),s=wr(i.target._2)(e.layout.edges),u=(()=>{if(s.tag==="Nothing")return Vo(e.layout)(e.edgeEndpoints)(i.target._2);if(s.tag==="Just"){const g=Uc(e.layout)((()=>{if(i.target._3==="Forward")return s._1;if(i.target._3==="Backward")return re(s._1);c()})())(i.target._4)(i.target._5)((n-i.startT)/ne(1e-4)(i.endT-i.startT))({pre:i.target._7,post:i.target._8});return{x:g.x-6,y:g.y-6,w:12,h:12}}c()})();return{whole:(()=>{const g=ht(ri)([(()=>{const _=ht(f=>{const l=Ye(f)(e.layout.nodes);return l.tag==="Just"?T("Just",{x:l._1.x,y:l._1.y,w:l._1.w,h:l._1.h}):y})([i.target._4,i.target._5]);return _.length===0?y:T("Just",ae(_))})(),a]);return g.length===0?u:ae(g)})(),text:a,guide:T("Just",u)}})());if(i.target.tag==="FillWindow"){const a=Ye(i.target._2)(e.layout.nodes);if(a.tag==="Just")return T("Just",{whole:{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h},text:lu(t.labelBasePx)(e)(n)(i.target._2),guide:y});if(a.tag==="Nothing")return y;c()}}return y})(e.windows));return o.tag==="Just"?T("Just",(()=>{const i=ae(Y(g=>g.whole)([o._1.head,...o._1.tail])),a=ht(ri)(Y(g=>g.text)([o._1.head,...o._1.tail])),s=a.length===0?y:T("Just",ae(a)),u=ht(ri)(Y(g=>g.guide)([o._1.head,...o._1.tail]));return u.length===0?{whole:{x:i.x*e.placement.scale+e.placement.tx,y:i.y*e.placement.scale+e.placement.ty,w:i.w*e.placement.scale,h:i.h*e.placement.scale},text:s.tag==="Just"?T("Just",{x:s._1.x*e.placement.scale+e.placement.tx,y:s._1.y*e.placement.scale+e.placement.ty,w:s._1.w*e.placement.scale,h:s._1.h*e.placement.scale}):y,guide:y}:{whole:{x:i.x*e.placement.scale+e.placement.tx,y:i.y*e.placement.scale+e.placement.ty,w:i.w*e.placement.scale,h:i.h*e.placement.scale},text:s.tag==="Just"?T("Just",{x:s._1.x*e.placement.scale+e.placement.tx,y:s._1.y*e.placement.scale+e.placement.ty,w:s._1.w*e.placement.scale,h:s._1.h*e.placement.scale}):y,guide:T("Just",{x:ae(u).x*e.placement.scale+e.placement.tx,y:ae(u).y*e.placement.scale+e.placement.ty,w:ae(u).w*e.placement.scale,h:ae(u).h*e.placement.scale})}})()):y},Da=t=>e=>n=>r=>o=>{const i=t.padding*r.placement.scale;return hu((()=>{const a=Ir(t)(r)(o);return a.tag==="Just"?T("Just",{x:a._1.whole.x-i,y:a._1.whole.y-i,w:a._1.whole.w+i*2,h:a._1.whole.h+i*2}):y})())(T("Just",(()=>{const a={x:r.layout.bounds.x*r.placement.scale+r.placement.tx-i,y:r.layout.bounds.y*r.placement.scale+r.placement.ty-i,w:r.layout.bounds.w*r.placement.scale+i*2,h:r.layout.bounds.h*r.placement.scale+i*2},s=za(r)(o);return s.tag==="Just"?{x:s._1.x*r.placement.scale+r.placement.tx-i,y:s._1.y*r.placement.scale+r.placement.ty-i,w:s._1.w*r.placement.scale+i*2,h:s._1.h*r.placement.scale+i*2}:a})()))},BT=t=>e=>n=>r=>o=>St(r.dives)(i=>{const a=Fa(r)(i.parentPath)(i.startT)(i.endT);if(a.tag==="Just"){const s=i.childPath,u=te(g=>Jo(g.path)(s))(r.segments);if(u.tag==="Just"){const g=o(u._1),_=To(t)(e)(n)(u._1)(Da(t)(e)(n)(u._1)(u._1.startT+2e-4))(NT(t)(e)(n)(r)(u._1)),f=g.length===0?_:ea(n)(t.padding)(u._1)(Xo(t)(n)(g)(i.startT-1e-4).camera),l=na(t)(e)(n)(i)(a._1)(o(a._1)),d=(()=>{if(i.direction==="DiveIn")return _;if(i.direction==="DiveOut"){const h=te(m=>m.direction==="DiveOut"&&Jo(m.parentPath)(i.childPath)&&xe(m.endT-i.startT)<1e-4)(r.dives);if(h.tag==="Just"){const m=Fa(r)(h._1.parentPath)(h._1.startT)(h._1.endT);if(m.tag==="Just")return na(t)(e)(n)(h._1)(m._1)(o(m._1));if(m.tag==="Nothing")return f;c()}if(h.tag==="Nothing")return f}c()})();if(i.direction==="DiveIn"){const h=te(m=>m.direction==="DiveIn"&&Jo(m.parentPath)(i.childPath)&&xe(m.startT-i.endT)<1e-4)(r.dives);if(h.tag==="Just"){const m=Fa(r)(h._1.parentPath)(h._1.startT)(h._1.endT);if(m.tag==="Just"){if(i.direction==="DiveIn"&&i.endT-i.startT>.12){const p=i.endT-.12,x={easing:fr,endT:p,fromCam:l,intent:po,interp:ho,startT:i.startT,toCam:na(t)(e)(n)(h._1)(m._1)(o(m._1))};return[x,{...x,startT:p,endT:i.endT,fromCam:na(t)(e)(n)(h._1)(m._1)(o(m._1))}]}return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:fr,interp:ho,intent:po}]}if(m.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:fr,interp:ho,intent:po}];c()}if(h.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:fr,interp:ho,intent:po}];c()}if(i.direction==="DiveOut"){const h=te(m=>m.direction==="DiveIn"&&Jo(m.parentPath)(i.childPath)&&xe(m.startT-i.endT)<1e-4)(r.dives);if(h.tag==="Just"){const m=Fa(r)(h._1.parentPath)(h._1.startT)(h._1.endT);if(m.tag==="Just"){if(i.direction==="DiveIn"&&i.endT-i.startT>.12){const p=i.endT-.12,x={easing:fr,endT:p,fromCam:d,intent:po,interp:ho,startT:i.startT,toCam:na(t)(e)(n)(h._1)(m._1)(o(m._1))};return[x,{...x,startT:p,endT:i.endT,fromCam:na(t)(e)(n)(h._1)(m._1)(o(m._1))}]}return[{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:fr,interp:ho,intent:po}]}if(m.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:fr,interp:ho,intent:po}];c()}if(h.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:fr,interp:ho,intent:po}]}c()}if(u.tag==="Nothing")return[];c()}if(a.tag==="Nothing")return[];c()}),Ma=t=>e=>n=>r=>o=>{const i=t.padding*r.placement.scale,a=fn(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)({center:(()=>{const h=t.padding*r.placement.scale;return{x:r.layout.bounds.x*r.placement.scale+r.placement.tx-h+(r.layout.bounds.w*r.placement.scale+h*2)/2,y:r.layout.bounds.y*r.placement.scale+r.placement.ty-h+(r.layout.bounds.h*r.placement.scale+h*2)/2}})(),zoom:fd(t)(e)(n)(r)}),s=h=>h.w<=a.w+.001&&h.h<=a.h+.001,u=Ir(t)(r)(o),g=(()=>{const h=hu(u.tag==="Just"?T("Just",{x:u._1.whole.x-i,y:u._1.whole.y-i,w:u._1.whole.w+i*2,h:u._1.whole.h+i*2}):y)((()=>{const m=za(r)(o);return m.tag==="Just"?T("Just",{x:m._1.x*r.placement.scale+r.placement.tx-i,y:m._1.y*r.placement.scale+r.placement.ty-i,w:m._1.w*r.placement.scale+i*2,h:m._1.h*r.placement.scale+i*2}):y})());if(h.tag==="Nothing")return!1;if(h.tag==="Just")return s(h._1);c()})()?i/2:i,_=u.tag==="Just"?T("Just",{x:u._1.whole.x-g,y:u._1.whole.y-g,w:u._1.whole.w+g*2,h:u._1.whole.h+g*2}):y,f=h=>{if(_.tag==="Nothing")return h;if(_.tag==="Just")return ae([h,{x:_._1.x+_._1.w/2,y:_._1.y+_._1.h/2,w:0,h:0}]);c()},l=(()=>{if(u.tag==="Just")return u._1.guide;if(u.tag==="Nothing")return y;c()})();if(l.tag==="Just"){const h=(()=>{if(u.tag==="Just")return u._1.text;if(u.tag==="Nothing")return y;c()})();return h.tag==="Just"&&s({x:h._1.x-g,y:h._1.y-g,w:h._1.w+g*2,h:h._1.h+g*2})?r.path.length!==0?Da(t)(e)(n)(r)(o):_.tag==="Just"&&s(_._1)?T("Just",_._1):T("Just",f({x:h._1.x-g,y:h._1.y-g,w:h._1.w+g*2,h:h._1.h+g*2})):r.path.length!==0?Da(t)(e)(n)(r)(o):_.tag==="Just"&&s(_._1)?T("Just",_._1):T("Just",f({x:l._1.x-g,y:l._1.y-g,w:l._1.w+g*2,h:l._1.h+g*2}))}const d=(()=>{if(u.tag==="Just")return u._1.text;if(u.tag==="Nothing")return y;c()})();return d.tag==="Just"?r.path.length!==0?Da(t)(e)(n)(r)(o):_.tag==="Just"&&s(_._1)?T("Just",_._1):T("Just",f({x:d._1.x-g,y:d._1.y-g,w:d._1.w+g*2,h:d._1.h+g*2})):r.path.length!==0?Da(t)(e)(n)(r)(o):_.tag==="Just"&&s(_._1)?T("Just",_._1):_.tag==="Just"?T("Just",f(_._1)):y},AT=t=>e=>n=>r=>o=>i=>{const a=Ma(t)(e)(n)(r)(i),s=u=>Ma(t)(e)(n)(r)(rn(r.startT)(r.endT)(u));return hu(a)((()=>{const u=ht(ri)(Dt(g=>_=>{const f=ne(_-t.maxTransition)((()=>{const m=g-1|0;return m>=0&&m<o.length?(o[m]+_)/2:r.startT})()),l=En(_+t.maxTransition)((()=>{const m=g+1|0;return m>=0&&m<o.length?(o[m]+_)/2:r.endT})());if(i<f-1e-4||i>l+1e-4)return y;const d=s(_-1e-4),h=s(_+1e-4);return _d(f)(_)(l)(i)(i<_?a:d)(i<_?h:a)})(o));return u.length===0?y:T("Just",ae(u))})())},IT=t=>e=>n=>r=>o=>i=>o<=r.startT+1e-4?vT(t)(e)(n)(r)(i):To(t)(e)(n)(r)(AT(t)(e)(n)(r)(cd(r))(o))(i),zT=t=>e=>n=>r=>o=>i=>{const a=Ma(t)(e)(n)(r)(i);return hu(a)((()=>{const s=ht(u=>i<u.left-1e-4||i>u.right+1e-4?y:_d(u.left)(u.boundary)(u.right)(i)(i<u.boundary?a:u.before)(i<u.boundary?u.after:a))(o);return s.length===0?y:T("Just",ae(s))})())},FT=t=>e=>n=>r=>o=>{const i=a=>Ma(t)(e)(n)(r)(rn(r.startT)(r.endT)(a));return Dt(a=>s=>({boundary:s,left:ne(s-t.maxTransition)((()=>{const u=a-1|0;return u>=0&&u<o.length?(o[u]+s)/2:r.startT})()),right:En(s+t.maxTransition)((()=>{const u=a+1|0;return u>=0&&u<o.length?(o[u]+s)/2:r.endT})()),before:i(s-1e-4),after:i(s+1e-4)}))(o)},DT=t=>e=>n=>r=>o=>i=>a=>{const s=e.widthPx>=e.heightPx*1.5&&a.path.length===0,u=S=>s&&oe(v=>v.startT<=S&&S<v.endT&&(v.target.tag==="TokenWindow"||v.target.tag==="FillWindow"),a.windows),g=S=>v=>{let D=S,W=v,M=!0,q;for(;M;){const $=D,G=W,F=oi(t)(e)(r)(a)(G);if($<=0){M=!1,q=G.zoom;continue}if(e.widthPx<=0||e.heightPx<=0){M=!1,q=G.zoom;continue}if(F<=0){M=!1,q=G.zoom;continue}if(xe(F-t.minimumReadableLabelPx)<.001){M=!1,q=G.zoom;continue}D=$-1|0,W={...G,zoom:G.zoom*t.minimumReadableLabelPx/F}}return q},_=t.padding*a.placement.scale/2,f=s?.016666666666666666:1e-4,l=t.padding*a.placement.scale,d={x:a.layout.bounds.x*a.placement.scale+a.placement.tx-l,y:a.layout.bounds.y*a.placement.scale+a.placement.ty-l,w:a.layout.bounds.w*a.placement.scale+l*2,h:a.layout.bounds.h*a.placement.scale+l*2},h={center:{x:d.x+d.w/2,y:d.y+d.h/2},zoom:1},m=g(12)(h),p=fn(e)(a.path.length===0||a.placement.scale===1&&a.placement.tx===0&&a.placement.ty===0?t.padding:0)(r)(h),x=fn(e)(a.path.length===0||a.placement.scale===1&&a.placement.tx===0&&a.placement.ty===0?t.padding:0)(r)({...h,zoom:m}),w={w:x.w*m,h:x.h*m},J=(S,v)=>{const D=fn(e)(a.path.length===0||a.placement.scale===1&&a.placement.tx===0&&a.placement.ty===0?t.padding:0)(r)(v);return Hg(W=>{if(W.tag==="Nothing")return!0;if(W.tag==="Just")return W._1.x>=D.x-.001&&W._1.y>=D.y-.001&&W._1.x+W._1.w<=D.x+D.w+.001&&W._1.y+W._1.h<=D.y+D.h+.001;c()},S)},N=ht(S=>{if(S.target.tag==="RelabelWindow"){const v=Ir(t)(a)((S.startT+S.endT)/2);if(v.tag==="Just")return T("Just",{window:S,bounds:(()=>{if(v._1.text.tag==="Just")return ae([v._1.whole,v._1.text._1]);if(v._1.text.tag==="Nothing")return v._1.whole;c()})(),preparers:(()=>{const D=S.startT;return _t(W=>D>=W.endT-1e-4&&D<=W.endT+t.maxTransition&&W.target.tag==="TokenWindow"&&W.target._5===S.target._1,a.windows)})()})}return y})(a.windows),k=ht(S=>S.target.tag==="NodeWindow"||S.target.tag==="RelabelWindow"||S.target.tag==="EdgeWindow"||S.target.tag==="TokenWindow"||S.target.tag==="FillWindow"?T("Just",{window:S,afterStart:Ir(t)(a)(S.startT+1e-4),beforeEnd:Ir(t)(a)(S.endT-1e-4)}):y)(a.windows),C=S=>u(S)?Ir(t)(a)(S):rd([(()=>{const v=b(D=>W=>W.window.endT>S+1e-4||W.window.endT<S-t.maxTransition||D.tag==="Just"&&D._1.window.endT>=W.window.endT?D:T("Just",W))(y)(k);if(v.tag==="Just")return v._1.beforeEnd;if(v.tag==="Nothing")return y;c()})(),Ir(t)(a)(S),(()=>{const v=b(D=>W=>W.window.startT<S-1e-4||W.window.startT>S+t.maxTransition||D.tag==="Just"&&D._1.window.startT<=W.window.startT?D:T("Just",W))(y)(k);if(v.tag==="Just")return v._1.afterStart;if(v.tag==="Nothing")return y;c()})()]),R=(S,v)=>{const D=za(a)(S),W=D.tag==="Just"?T("Just",{x:D._1.x*a.placement.scale+a.placement.tx,y:D._1.y*a.placement.scale+a.placement.ty,w:D._1.w*a.placement.scale,h:D._1.h*a.placement.scale}):y,M=ht(G=>G.window.endT>=S-1e-4&&G.window.startT<=S+t.maxTransition&&G.window.target.tag==="RelabelWindow"||oe(F=>F.startT<=S+1e-4&&F.endT>=S-1e-4,G.preparers)?T("Just",G.bounds):y)(N),q=M.length===0?y:T("Just",ae(M));if(v.tag==="Just"){if(q.tag==="Just"){const F=(()=>{if(W.tag==="Just")return T("Just",ae([W._1,ae([q._1,v._1.whole])]));if(W.tag==="Nothing")return T("Just",ae([q._1,v._1.whole]));c()})();return a.path.length===0?Ui({worldBounds:d,bounds:F,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,actionTextBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:{w:p.w,h:p.h},padding:_,zoomFloor:m}):Vi({worldBounds:d,visibleBounds:W,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,fallbackActionBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:w,zoomCap:m,padding:_})}if(q.tag==="Nothing"){const F=(()=>{if(W.tag==="Just")return T("Just",ae([W._1,v._1.whole]));if(W.tag==="Nothing")return T("Just",v._1.whole);c()})();return a.path.length===0?Ui({worldBounds:d,bounds:F,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,actionTextBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:{w:p.w,h:p.h},padding:_,zoomFloor:m}):Vi({worldBounds:d,visibleBounds:W,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,fallbackActionBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:w,zoomCap:m,padding:_})}const G=(W.tag==="Just"&&c(),void c());return a.path.length===0?Ui({worldBounds:d,bounds:G,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,actionTextBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:{w:p.w,h:p.h},padding:_,zoomFloor:m}):Vi({worldBounds:d,visibleBounds:W,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,fallbackActionBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:w,zoomCap:m,padding:_})}if(q.tag==="Just"){const G=(()=>{if(W.tag==="Just")return T("Just",ae([W._1,q._1]));if(W.tag==="Nothing")return T("Just",q._1);c()})();return a.path.length===0?Ui({worldBounds:d,bounds:G,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,actionTextBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:{w:p.w,h:p.h},padding:_,zoomFloor:m}):Vi({worldBounds:d,visibleBounds:W,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,fallbackActionBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:w,zoomCap:m,padding:_})}if(q.tag==="Nothing"){const G=(()=>{if(W.tag==="Just")return T("Just",W._1);if(W.tag==="Nothing")return y;c()})();return a.path.length===0?Ui({worldBounds:d,bounds:G,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,actionTextBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:{w:p.w,h:p.h},padding:_,zoomFloor:m}):Vi({worldBounds:d,visibleBounds:W,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,fallbackActionBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:w,zoomCap:m,padding:_})}const $=(W.tag==="Just"&&c(),void c());return a.path.length===0?Ui({worldBounds:d,bounds:$,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,actionTextBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:{w:p.w,h:p.h},padding:_,zoomFloor:m}):Vi({worldBounds:d,visibleBounds:W,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,fallbackActionBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:w,zoomCap:m,padding:_})},P=cd(a),I=FT(t)(e)(r)(a)(P),U=S=>u(S)?Ma(t)(e)(r)(a)(S):zT(t)(e)(r)(a)(I)(S);return b(S=>v=>{const D=rn(a.startT)(a.endT)(v.startT+1e-4),W=rn(a.startT)(a.endT)(v.endT+1e-4),M=(D+W)/2,q=v.intent==="ActionFocus"&&u(M),$=v.intent==="ActionFocus"?M:W,G=q?[U(M)]:Y(mt=>U(mt))((()=>{const mt=v.easing==="Linear"?6:2,vt=v.endT-v.startT;return Y(Wt=>rn(a.startT)(a.endT)(v.startT+vt*ot(Wt)/ot(mt)+1e-4))(Ut(0,mt))})()),F=ht(ri)(G),Q=F.length===0?y:T("Just",ae(F)),O=G.length-1|0,z=O>=0&&O<G.length?T("Just",G[O]):y,X=(()=>{if(z.tag==="Just")return z._1;if(z.tag==="Nothing")return U(W);c()})(),V=Wx.eq(v.interp)(Wf)&&J(G,v.toCam),K=V&&!q?v.toCam:R(W,C($)),Z=0<G.length?To(t)(e)(r)(a)(G[0])(R(D,C(D))):To(t)(e)(r)(a)(U(D))(R(D,C(D))),nt=(()=>{if(S.previous.tag==="Nothing")return Z;if(S.previous.tag==="Just")return S.previous._1;c()})(),rt=(()=>{if(s)return K;const mt=GT(t)(a)(v);return mt.tag==="Just"&&v.easing==="Linear"?CT(t)(e)(r)(a)(nt)(mt._1)(K):K})(),ft=To(t)(e)(r)(a)(X)(nt),Nt=To(t)(e)(r)(a)(Q)(kT(t)(e)(r)(a)(Q)(nt)(q&&K.zoom>nt.zoom+1e-4||!V&&q?To(t)(e)(r)(a)(X)(rt):J(G,nt)&&(!q||nt.zoom>=K.zoom-1e-4)?nt:(()=>{const mt=fn(e)(a.path.length===0||a.placement.scale===1&&a.placement.tx===0&&a.placement.ty===0?t.padding:0)(r)(nt),vt=(ft.center.y-nt.center.y)*e.heightPx/ne(1e-4)(mt.h),Wt=(ft.center.x-nt.center.x)*e.widthPx/ne(1e-4)(mt.w);return qe(Wt*Wt+vt*vt)<=12})()?ft:To(t)(e)(r)(a)(X)(rt))),lt=(()=>{if(v.easing==="Linear"){const mt=fn(e)(a.path.length===0||a.placement.scale===1&&a.placement.tx===0&&a.placement.ty===0?t.padding:0)(r)(nt),vt=(Nt.center.y-nt.center.y)*e.heightPx/ne(1e-4)(mt.h),Wt=(Nt.center.x-nt.center.x)*e.widthPx/ne(1e-4)(mt.w),Tt=qe(Wt*Wt+vt*vt),Vt=t.panSpeed*ne(0)(v.endT-v.startT),Gt=Tt<=Vt||Tt<=1e-4?1:Vt/Tt,bt={...Nt,center:{x:nt.center.x+(Nt.center.x-nt.center.x)*Gt,y:nt.center.y+(Nt.center.y-nt.center.y)*Gt}};if((()=>{const pt=U(rn(a.startT)(a.endT)(v.endT+1e-4));if(pt.tag==="Nothing")return!0;if(pt.tag==="Just"){const ct=fn(e)(a.path.length===0||a.placement.scale===1&&a.placement.tx===0&&a.placement.ty===0?t.padding:0)(r)(bt);return pt._1.x>=ct.x-.001&&pt._1.y>=ct.y-.001&&pt._1.x+pt._1.w<=ct.x+ct.w+.001&&pt._1.y+pt._1.h<=ct.y+ct.h+.001}c()})())return bt}return Nt})();return{previous:T("Just",lt),spans:Et(S.spans)({startT:v.startT,endT:v.endT,fromCam:nt,toCam:lt,easing:v.easing,interp:Ko,intent:v.intent})}})({previous:y,spans:[]})(_t(S=>S.endT-S.startT>=f,(()=>{const S=Rt(at.compare)(Ur(at.compare)(St(P)(D=>[ne(D-t.maxTransition)((()=>{const W=_t(q=>q<D,P),M=W.length-1|0;return M>=0&&M<W.length?(W[M]+D)/2:a.startT})()),D,En(D+t.maxTransition)((()=>{const W=_t(M=>M>D,P);return 0<W.length?(W[0]+D)/2:a.endT})())]))),v=yT(t)(e)(n)(r)(o)(i)(a);return St((()=>{if(v.length===0){const D=R(rn(a.startT)(a.endT)(a.startT+1e-4),C(rn(a.startT)(a.endT)(a.startT+1e-4)));return[{startT:a.startT,endT:a.endT,fromCam:D,toCam:D,easing:t.easing,interp:Ko,intent:Hs}]}return v})())(D=>{const W=[D.startT,...Et(_t(M=>M>D.startT+1e-4&&M<D.endT-1e-4,S))(D.endT)];return Y(M=>({...D,startT:M._1,endT:M._2}))(He(mn,W,Bt(1,W.length,W)))})})())).spans},MT=t=>e=>n=>r=>o=>i=>UJ(a=>({segment:a,spans:DT(t)(e)(n)(r)(o)(i)(a)}))(i.segments),ld=t=>e=>n=>r=>o=>i=>{const a=MT(t)(e)(n)(r)(o)(i),s=Rt(g=>_=>at.compare(g.startT)(_.startT))(St(a)(g=>g.spans)),u=BT(t)(e)(r)(i)(g=>{const _=te(f=>Jo(f.segment.path)(g.path)&&f.segment.startT===g.startT&&f.segment.endT===g.endT)(a);return _.tag==="Just"?_._1.spans:[]});return[...u,...u.length===0?s:LT(u)(s)]},QT=t=>e=>n=>{const r=b(o=>i=>!(i.target.tag==="NodeWindow"||i.target.tag==="RelabelWindow"||i.target.tag==="EdgeWindow"||i.target.tag==="TokenWindow"||i.target.tag==="FillWindow")||i.endT>n+1e-4||i.endT<n-t.maxTransition||o.tag==="Just"&&o._1.endT>=i.endT?o:T("Just",i))(y)(e.windows);if(r.tag==="Just")return Ir(t)(e)(r._1.endT-1e-4);if(r.tag==="Nothing")return y;c()},HT=t=>e=>n=>{const r=b(o=>i=>!(i.target.tag==="NodeWindow"||i.target.tag==="RelabelWindow"||i.target.tag==="EdgeWindow"||i.target.tag==="TokenWindow"||i.target.tag==="FillWindow")||i.startT<n-1e-4||i.startT>n+t.maxTransition||o.tag==="Just"&&o._1.startT<=i.startT?o:T("Just",i))(y)(e.windows);if(r.tag==="Just")return Ir(t)(e)(r._1.startT+1e-4);if(r.tag==="Nothing")return y;c()},OT=t=>e=>n=>rd([QT(t)(e)(n),Ir(t)(e)(n),HT(t)(e)(n)]),WT=t=>e=>n=>{const r=OT(t)(e)(n);return{level:(()=>{const o=t.padding*e.placement.scale;return{x:e.layout.bounds.x*e.placement.scale+e.placement.tx-o,y:e.layout.bounds.y*e.placement.scale+e.placement.ty-o,w:e.layout.bounds.w*e.placement.scale+o*2,h:e.layout.bounds.h*e.placement.scale+o*2}})(),visible:(()=>{const o=za(e)(n);return o.tag==="Just"?T("Just",{x:o._1.x*e.placement.scale+e.placement.tx,y:o._1.y*e.placement.scale+e.placement.ty,w:o._1.w*e.placement.scale,h:o._1.h*e.placement.scale}):y})(),action:r.tag==="Just"?T("Just",r._1.whole):y,actionText:(()=>{if(r.tag==="Just")return r._1.text;if(r.tag==="Nothing")return y;c()})(),actionGuide:(()=>{if(r.tag==="Just")return r._1.guide;if(r.tag==="Nothing")return y;c()})()}},ra=(t,e,n)=>({tag:t,_1:e,_2:n}),$T=t=>t,ii=(t,e)=>({tag:t,_1:e}),dd=(t,e)=>({tag:t,_1:e}),jc=t=>t,pu=(t,e)=>({tag:t,_1:e}),t_=pu("NotYet"),hd=pu("Consumed"),qT=jc("FromSource"),pd=jc("FromTarget"),VT=jc("FromBoth"),mu=ii("Hidden"),e_=ii("Visible"),n_=$T("ExtendFromSource"),yu=ra("Retracted"),xu=ra("Extended"),UT={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},r_=t=>t,wu=(t,e)=>({tag:t,_1:e}),oa={eq:bs(zi)},KT=(()=>{const t=un.unfoldr(Yn);return e=>t(gn("IterNode",e,Un))})(),o_=fe(B)(Qt),to=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},md=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Fn=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},i_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=B.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}}c()}return o},a_=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=B.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}}c()}return o},yd=Qt.foldMap(nx(B)),ai=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},YT=fe(B)(Qt),XT=fe(B)(Qt),ZT=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},xd=wu("Closed"),jT=wu("Open"),wd=r_("Backdrop"),tN=r_("FlyThrough"),ln=r_("Active"),Ju=t=>e=>n=>{const r=te(o=>oa.eq(o.path)(e)&&n>=o.startT&&n<o.endT)(t.segments);if(r.tag==="Just")return T("Just",r._1);if(r.tag==="Nothing")return te(o=>oa.eq(o.path)(e))(t.segments);c()},eN=t=>{const e=te(n=>n.path.length===0)(t.segments);if(e.tag==="Just")return e._1.edgeEndpoints;if(e.tag==="Nothing")return H;c()},nN=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:vc,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:eN(t)}),Tu=t=>e=>n=>({...n,minis:Y(r=>{const o=Tu(t)(e)({...r,state:{...r.state,tokens:H,nodeInvert:H,visited:H}});return(()=>{const i=r.segment.path;return oe(a=>a.direction==="DiveOut"&&oa.eq(a.childPath)(i)&&a.endT<=e+1e-4,t.dives)})()?{...o,bgAlpha:1}:o})(n.minis)}),rN=t=>Y(e=>e<1?[]:Bt(0,e,t))(Ut(0,t.length-1|0)),oN=t=>e=>Y(n=>oa.eq(n.segment.path)(t)?{...n,bgAlpha:e,state:{...n.state,tokens:H,nodeInvert:H,visited:H}}:n),iN=t=>b(e=>n=>(e*31|0)+Xr(n)|0)(7)(Xn(t)),aN=t=>e=>n=>({...n,state:{...n.state,nodes:o_(Y(r=>E(r._1,t(r._1)(r._2)))(KT(n.state.nodes))),edges:(()=>{const r=o=>{if(o.tag==="Leaf")return H;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,e(o._4),r(o._5),r(o._6));c()};return r(n.state.edges)})()}}),s_=t=>e=>n=>{const r=to(e)(t.keyframes);if(r.tag==="Just")return md(n)(r._1.labels);if(r.tag==="Nothing")return y;c()},sN=t=>e=>ht(n=>md(e)(n.labels))((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,wt("Cons",r._4,n(r._6,o)));c()};return Mt(ce.foldr,n(t.keyframes,A))})()),uN=b(t=>e=>{const n=Sr(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?Et(n._1.init)({...n._1.last,endT:Fn(n._1.last.endT)(e.endT),windows:Et(n._1.last.windows)(e)}):Et(t)({endT:e.endT,windows:[e]})})([]),gN=t=>b(e=>n=>{if(!e.leading)return e;if(n.scene.tag==="Structural"){if((()=>{const r=to(n.scene._1.to)(t.keyframes),o=to(e.keyframe)(t.keyframes);return!(o.tag==="Just"&&r.tag==="Just"&&Kn(B.compare,o._1.nodes,r._1.nodes).tag==="Leaf"&&Kn(B.compare,o._1.edges,r._1.edges).tag==="Leaf")})())return{...e,leading:!1};if((()=>{const r=to(n.scene._1.to)(t.keyframes);if(r.tag==="Nothing")return!0;if(r.tag==="Just")return!r._1.authored;c()})())return{...e,keyframe:n.scene._1.to};if(!e.namedSceneSeen)return{...e,keyframe:n.scene._1.to,namedSceneSeen:!0}}return{...e,leading:!1}})({keyframe:t.initialKeyframe,leading:!0,namedSceneSeen:(()=>{const e=to(t.initialKeyframe)(t.keyframes);if(e.tag==="Just")return!(e._1.nodes.tag==="Leaf"&&e._1.edges.tag==="Leaf");if(e.tag==="Nothing")return!1;c()})()})(t.spans).keyframe,Jd=t=>{const e=to(gN(t))(t.keyframes);if(e.tag==="Just")return{nodes:e._1.nodes,edges:e._1.edges};if(e.tag==="Nothing")return{nodes:H,edges:H};c()},cN=t=>{const e=Jd(t);return b(Fn)(t.startT)(ht(n=>n.target.tag==="NodeWindow"?n.target._2==="PlopIn"&&i_(n.target._1)(e.nodes)?T("Just",n.endT):y:n.target.tag==="EdgeWindow"&&n.target._2.tag==="Extend"&&a_(n.target._1)(e.edges)?T("Just",n.endT):y)(t.windows))},Td=t=>e=>{const n=Jd(t);return{...e,state:{...e.state,nodes:$g()(r=>o=>T("Just",i_(r)(n.nodes)?e_:o))(e.state.nodes),edges:$g()(r=>o=>T("Just",a_(r)(n.edges)?xu:o))(e.state.edges)}}},_N=t=>e=>n=>e.path.length===0||t>=cN(e)?n:Td(e)(n),fN=t=>e=>n=>yd(r=>yd(o=>o.target.tag==="FillWindow"?o.startT<=n?ee("Node",1,1,o.target._2,void 0,H,H):H:o.target.tag==="TokenWindow"&&o.startT+(o.endT-o.startT)*.25<=n?ee("Node",1,1,o.target._4,void 0,H,H):H)(r.windows))(_t(r=>n<=r.endT+t,uN(Rt(r=>o=>at.compare(r.startT)(o.startT))(_t(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),lN=t=>e=>{const n=It(r=>y,r=>o=>T("Just",{head:r,tail:o}),sN(t)(e));if(n.tag==="Nothing")return!1;if(n.tag==="Just"){const r=n._1.head;return oe(o=>o!==r,n._1.tail)}c()},dN=t=>e=>n=>oe(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),hN=t=>e=>n=>oe(r=>r.endT<=e&&r.target.tag==="RelabelWindow"&&r.target._1===n,t),pN=t=>e=>n=>{const r=ta(t)(e);if(r.tag==="AtKeyframe")return s_(t)(r._1)(n);if(r.tag==="InTransition")return hN(t.windows)(e)(n)?s_(t)(r._2)(n):s_(t)(r._1)(n);c()},mN=t=>e=>n=>oe(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),yN=t=>e=>n=>oe(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),xN=t=>e=>n=>oe(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),wN=t=>e=>{const n=ta(t)(e),r=(()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;c()})(),o=to(r)(t.keyframes);return o.tag==="Just"&&o._1.authored?r:""},JN=t=>e=>{const n=ta(t)(e),r=to((()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;c()})())(t.keyframes);if(r.tag==="Just")return r._1.kind;if(r.tag==="Nothing")return Ra;c()},Nd=t=>{const e=j1(y,U1,o=>(()=>{const i=to((()=>{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;c()})())(t.keyframes);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return i._1.nodes.tag==="Leaf";c()})()?y:T("Just",Fn(o.startT)(o.endT-1e-4)),t.spans),n=(()=>{if(e.tag==="Nothing")return t.startT;if(e.tag==="Just")return e._1;c()})(),r=te(o=>o.target.tag==="NodeWindow"&&o.target._2==="PlopIn")(Rt(o=>i=>at.compare(o.startT)(i.startT))(t.windows));if(r.tag==="Nothing")return n;if(r.tag==="Just")return Fn(r._1.startT)(r._1.endT-1e-4);c()},Qa=t=>e=>n=>te(r=>n(r)&&e>=r.startT&&e<r.endT)(t),TN={segment:{startT:0,endT:0,path:[],layout:{nodes:H,edges:H,bounds:{x:0,y:0,w:0,h:0},chipExtras:H,edgeLabels:H},placement:vc,windows:[],spans:[],keyframes:H,initialKeyframe:"",edgeEndpoints:H},state:{animationTime:0,nodes:H,nodeLabels:H,edgeEndpoints:H,edges:H,tokens:H,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:Ra,visited:H,nodeFadeAlpha:H,nodeLabelFadeAlpha:H,edgeFadeAlpha:H,nodeInvert:H},bgAlpha:1,minis:[],role:ln},bd=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:TN},Ha=t=>e=>{const n=t.endT-t.startT;return n<=0?1:Fn(0)(ai(1)((e-t.startT)/n))},NN=t=>e=>n=>xc(Xo(t.cameraConfig)(t.layout)(t.cameraSpans)(n.startT).camera)(Xo(t.cameraConfig)(t.layout)(t.cameraSpans)(n.endT).camera)(Ha(n)(e)),vd=t=>e=>n=>{const r=Fn(0)(ai(1)((n-t)/Fn(1e-6)(e-t)));return r*r*r*(r*(r*6-15)+10)},Cd=t=>{if(t.tag==="Closed")return 0;if(t.tag==="Opening")return vd(.3)(1)(t._1);if(t.tag==="Open")return 1;if(t.tag==="Closing")return 1-vd(0)(.7)(t._1);c()},bN=t=>{const e=Cd(t);return e<=0||e>=1?0:tn(3.141592653589793*e)},vN=t=>e=>n=>Fn(0)(ai(1)((n-Pe(0)(.3)(t+iN(e)|0).value)/.7)),si=t=>e=>{const n=t.endT-t.startT;return n<=0?1:Fn(0)(ai(1)((e-t.startT)/n))},CN=t=>e=>o_(ht(n=>{const r=Qa(t.windows)(e)(o=>o.target.tag==="RelabelWindow"&&o.target._1===n);if(r.tag==="Just")return r._1.target.tag==="RelabelWindow"?T("Just",E(n,dd("RelabelingNode",{oldLabel:r._1.target._2,newLabel:r._1.target._3,progress:si(r._1)(e)}))):y;if(r.tag==="Nothing"){if(lN(t)(n)){const o=pN(t)(e)(n);if(o.tag==="Just")return T("Just",E(n,dd("StaticNodeLabel",o._1)));if(o.tag==="Nothing")return y;c()}return y}c()})((()=>{const n=r=>{if(r.tag==="Leaf")return H;if(r.tag==="Node")return ee("Node",r._1,r._2,r._3,void 0,n(r._5),n(r._6));c()};return Mt(wn.foldr,n(t.layout.nodes))})())),LN=t=>e=>n=>r=>o=>{const i=Qa(e)(n)(a=>a.target.tag==="EdgeWindow"&&a.target._2.tag==="Retract"&&a.target._1===o);if(i.tag==="Just"){const a=Wi(t.timing.edgeEasing)(si(i._1)(n)),s=i._1.target.tag==="EdgeWindow"?i._1.target._2:cu("Extend",n_);if(s.tag==="Retract")return ra("Retracting",s._1,a);if(s.tag==="Extend")return ra("Extending",s._1,a);c()}if(i.tag==="Nothing"){if(dN(e)(n)(o))return yu;const a=Qa(e)(n)(s=>s.target.tag==="EdgeWindow"&&s.target._1===o);if(a.tag==="Just"){const s=Wi(t.timing.edgeEasing)(si(a._1)(n)),u=a._1.target.tag==="EdgeWindow"?a._1.target._2:cu("Extend",n_);if(u.tag==="Retract")return ra("Retracting",u._1,s);if(u.tag==="Extend")return ra("Extending",u._1,s);c()}if(a.tag==="Nothing")return xN(e)(n)(o)?yu:a_(o)(r)?xu:yu}c()},kN=t=>e=>n=>{const r=Vc(e)(n);return YT(Y(o=>E(o,LN(t)(e.windows)(n)(r)(o)))((()=>{const o=i=>{if(i.tag==="Leaf")return H;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,void 0,o(i._5),o(i._6));c()};return Mt(wn.foldr,o(e.layout.edges))})()))},SN=t=>e=>n=>r=>{const o=Qa(t)(e)(i=>i.target.tag==="NodeWindow"&&i.target._1===r&&i.target._2==="PlopOut");if(o.tag==="Just"){const i=si(o._1)(e),a=o._1.target.tag==="NodeWindow"?o._1.target._2:Hc;if(a==="PlopIn")return ii("PloppingIn",i);if(a==="PlopOut")return ii("PloppingOut",i);c()}if(o.tag==="Nothing"){if(mN(t)(e)(r))return mu;const i=Qa(t)(e)(a=>a.target.tag==="NodeWindow"&&a.target._1===r);if(i.tag==="Just"){const a=si(i._1)(e),s=i._1.target.tag==="NodeWindow"?i._1.target._2:Hc;if(s==="PlopIn")return ii("PloppingIn",a);if(s==="PlopOut")return ii("PloppingOut",a);c()}if(i.tag==="Nothing")return yN(t)(e)(r)?mu:i_(r)(n)?e_:mu}c()},EN=t=>e=>{const n=qc(t)(e);return o_(Y(r=>E(r,SN(t.windows)(e)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return H;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));c()};return Mt(wn.foldr,r(t.layout.nodes))})()))},RN=t=>e=>n=>e.target.tag==="TokenWindow"?E(e.target._1,n<e.startT?t_:n>=e.endT?hd:pu("Travelling",{edge:e.target._2,direction:e.target._3,progress:Wi(t.timing.tokenEasing)(si(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"?E(e.target._1,n<e.startT?t_:n>=e.endT?hd:pu("Filling",{node:e.target._2,progress:si(e)(n),labels:e.target._3})):E("",t_),PN=t=>e=>n=>XT(Y(r=>RN(t)(r)(n))(_t(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),GN=t=>e=>n=>({animationTime:n,nodes:EN(e)(n),nodeLabels:CN(e)(n),edgeEndpoints:e.edgeEndpoints,edges:kN(t)(e)(n),tokens:PN(t)(e.windows)(n),camera:Xo(t.cameraConfig)(e.layout)(t.cameraSpans)(n).camera,frameTitle:wN(e)(n),staticKind:JN(e)(n),visited:fN(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:H,nodeLabelFadeAlpha:H,edgeFadeAlpha:H,nodeInvert:H}),ia=t=>e=>n=>r=>({segment:n,state:GN(t)(n)(e),bgAlpha:1,minis:BN(t)(e)(n),role:r}),BN=t=>e=>n=>ht(r=>{const o=Ju(t)(Et(n.path)(r))(e);if(o.tag==="Just")return T("Just",{...ia(t)(ZT(o._1.startT)(o._1.endT-1e-4)(e))(o._1)(wd),bgAlpha:0});if(o.tag==="Nothing")return y;c()})((()=>{const r=o=>{if(o.tag==="Leaf")return H;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));c()};return Mt(wn.foldr,r(n.layout.nodes))})()),AN=t=>e=>{if(t.direction==="DiveIn")return Nd(e);if(t.direction==="DiveOut")return t.startT-1e-4;c()},IN=t=>e=>n=>e>=1?n:aN(r=>o=>o.tag==="Hidden"?mu:ii("PloppingIn",Fn(.4)(vN(t)(r)(e))))(r=>r.tag==="Retracted"?yu:xu)(n),Ld=t=>e=>ht(n=>{const r=te(o=>o.direction==="DiveIn"&&oa.eq(o.childPath)((()=>{const i=n.length+1|0;return i<1?[]:Bt(0,i,e)})()))(t.dives);if(r.tag==="Just"){const o=Ju(t)(n)(r._1.startT-1e-4);if(o.tag==="Just")return T("Just",(()=>{const i=ia(t)(r._1.startT-1e-4)(o._1)(wd);return{...i,state:{...i.state,nodeFadeAlpha:ee("Node",1,1,r._1.node,0,H,H)}}})());if(o.tag==="Nothing")return y;c()}if(r.tag==="Nothing")return y;c()})(rN(e)),kd=t=>e=>{const n=_t(o=>e>=o.startT&&e<o.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:nN(t)},zN=t=>e=>n=>r=>{const o=g=>{const _=ia(t)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT;c()})())(g)(tN);return{..._,bgAlpha:1,minis:(()=>{if(n.direction==="DiveIn")return _t(f=>!oa.eq(f.segment.path)(n.childPath),_.minis);if(n.direction==="DiveOut")return n.childPath.length>1?oN(n.childPath)(Ha(n)(e))(Tu(t)(n.startT)(_).minis):Tu(t)(n.startT)(_).minis;c()})(),state:{..._.state,edgeFadeAlpha:H,nodeFadeAlpha:ee("Node",1,1,n.node,0,H,H),nodeInvert:H,tokens:H}}},i=Ju(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT;c()})()),a=Ju(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;c()})()),s=n.direction==="DiveOut"&&n.childPath.length>1?1-Ha(n)(e):1,u=Fn(0)(ai(1)((Ha(n)(e)-.25)/.55));return[...Ld(t)(n.parentPath),...(()=>{if(i.tag==="Just"){if(a.tag==="Just")return[o(i._1),(()=>{const g=Td(a._1)(ia(t)(AN(n)(a._1))(a._1)(ln)),_={...g,bgAlpha:s,state:{...g.state,tokens:H,nodeInvert:H,visited:H}};if(n.direction==="DiveIn")return IN(t.seed)(u)(_);if(n.direction==="DiveOut")return Tu(t)(n.startT)(_);c()})()];if(a.tag==="Nothing")return[o(i._1)];c()}if(i.tag==="Nothing")return[ia(t)(e)(kd(t)(e))(ln)];c()})()]},FN=t=>e=>te(n=>e>=n.startT&&e<n.endT)(t.dives),DN=t=>e=>{const n=kd(t)(e),r=t.dives.length!==0,o=Xo(t.cameraConfig)(t.layout)(t.cameraSpans)(e).camera,i=IT(t.cameraConfig)(t.cameraViewport)(t.layout)(n)(e)(o),a=Ld(t)(n.path),s=_N(e)(n)(ia(t)(n.path.length===0?e:Fn(e)(Nd(n)))(n)(ln)),u={...s,state:{...s.state,camera:i}},g=FN(t)(e);if(g.tag==="Just"){const _=Ha(g._1)(e);return{levels:zN(t)(e)(g._1)(NN(t)(e)(g._1)),camera:o,rootLayout:t.layout,hasDives:r,portalState:(()=>{if(g._1.direction==="DiveIn")return wu("Opening",Fn(0)(ai(1)(_)));if(g._1.direction==="DiveOut")return wu("Closing",Fn(0)(ai(1)(_)));c()})()}}if(g.tag==="Nothing")return{levels:Et(a)(u),camera:i,rootLayout:t.layout,hasDives:r,portalState:n.path.length===0?xd:jT};c()},MN=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},QN=t=>{const e=t.length;return(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,g=i;if(u>=e){a=!1,s=g;continue}const _=f=>l=>{let d=f,h=l,m=!0,p;for(;m;){const x=d,w=h;if(x>=e){m=!1,p=w;continue}if(u>=0&&u<t.length){if(x>=0&&x<t.length){d=x+1|0,h=(()=>{const J=t[u].position,N=t[u].size,k=t[x].position,C=t[x].size;return J._1<k._1+C._1&&k._1<J._1+N._1&&J._2<k._2+C._2&&k._2<J._2+N._2})()?w+1|0:w;continue}d=x+1|0,h=w;continue}m=!1,p=w}return p};o=u+1|0,i=_(u+1|0)(g)}return s})(0)(0)},Sd=t=>b(e=>n=>e+dx(n.start)(n.end))(0)(t.segments),HN=t=>e=>n=>({crossingCount:b(r=>o=>r+o.jumps.length|0)(0)(e),bendCount:b(r=>o=>r+o.bends.length|0)(0)(e),totalEdgeLength:b(r=>o=>r+Sd(o))(0)(e),maxEdgeLength:b(r=>o=>MN(r)(Sd(o)))(0)(e),nodeOverlapCount:QN(t),constraintViolations:n,jumpCount:b(r=>o=>r+o.jumps.length|0)(0)(e)}),u_=t=>t,de=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},g_=u_("LEFT"),ON=u_("RIGHT"),Ed=u_("UNDEFINED"),WN={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},$N={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?sn:Me;if(e==="LEFT")return Qe;if(t==="RIGHT")return e==="RIGHT"?sn:Me;if(e==="RIGHT")return Qe;if(t==="UP")return e==="UP"?sn:Me;if(e==="UP")return Qe;if(t==="DOWN")return e==="DOWN"?sn:Me;if(e==="DOWN")return Qe;if(t==="UNDEFINED"&&e==="UNDEFINED")return sn;c()},Eq0:()=>WN},qN=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}}c()}return o},VN={x:0,y:0},Dn=t=>e=>n=>{const r=de(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:it(ut)(t)(e(r._1))(n.cNodes)};c()},Oa=t=>e=>n=>{const r=de(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:it(ut)(t)(e(r._1))(n.cGroups)};c()},UN=t=>b(e=>n=>Dn(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),KN=t=>{const e=b(n=>r=>{const o=de(r)(t.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just")return b(i=>a=>Ht(ut)(we)(a)([r])(i))(n)(o._1.constraints);c()})(H)(t.cNodeOrder);return b(n=>r=>Dn(r)(o=>({...o,constraints:(()=>{const i=de(r)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;c()})()}))(n))(t)(t.cNodeOrder)},YN=t=>e=>Dn(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}})),XN=t=>{const e=b(n=>r=>Oa(r)(o=>({...o,outDegree:o.outDegreeReal}))(n))(t)(t.cGroupOrder);return b(n=>r=>Dn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder)},hr={left:!1,right:!1,up:!1,down:!1},ZN={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},c_=t=>b(e=>n=>{const r=de(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const o=b(a=>s=>{const u=de(s)(e.cNodes);if(u.tag==="Nothing")return a;if(u.tag==="Just"){if(a.tag==="Nothing")return T("Just",s);if(a.tag==="Just"){const g=de(a._1)(e.cNodes);if(g.tag==="Nothing")return T("Just",s);if(g.tag==="Just")return u._1.hitbox.x<g._1.hitbox.x?T("Just",s):T("Just",a._1)}}c()})(y)(r._1.cNodes),i=Oa(n)(a=>({...a,reference:o}))(e);if(o.tag==="Nothing")return i;if(o.tag==="Just"){const a=de(o._1)(i.cNodes);if(a.tag==="Nothing")return i;if(a.tag==="Just"){const s=a._1;return b(u=>g=>Dn(g)(_=>({..._,cGroupOffset:{x:_.hitbox.x-s.hitbox.x,y:_.hitbox.y-s.hitbox.y}}))(u))(i)(r._1.cNodes)}}}c()})(t)(t.cGroupOrder),Mn=t=>c_({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return H;if(n.tag==="Node")return ee("Node",n._1,n._2,n._3,{...n._4,hitbox:{...n._4.hitbox,x:-n._4.hitbox.x-n._4.hitbox.width}},e(n._5),e(n._6));c()};return e(t.cNodes)})()}),zr=t=>c_({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return H;if(n.tag==="Node")return ee("Node",n._1,n._2,n._3,{...n._4,hitbox:{x:n._4.hitbox.y,y:n._4.hitbox.x,width:n._4.hitbox.height,height:n._4.hitbox.width},cGroupOffset:{x:n._4.cGroupOffset.y,y:n._4.cGroupOffset.x}},e(n._5),e(n._6));c()};return e(t.cNodes)})()}),Rd=t=>{const e=b(n=>r=>Oa(r)(o=>({...o,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return b(n=>r=>{const o=de(r)(n.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just"){if(o._1.cGroup.tag==="Nothing")return n;if(o._1.cGroup.tag==="Just"){const i=o._1.cGroup._1;return b(a=>s=>{const u=de(s)(a.cNodes);if(u.tag==="Nothing")return a;if(u.tag==="Just")return u._1.cGroup.tag==="Just"&&u._1.cGroup._1!==i?Oa(u._1.cGroup._1)(g=>({...g,outDegree:g.outDegree+1|0,outDegreeReal:g.outDegreeReal+1|0}))(Oa(i)(g=>yn(uo)(s)(g.incomingConstraints)?g:{...g,incomingConstraints:[...g.incomingConstraints,s]})(a)):a;c()})(n)(o._1.constraints)}}c()})(e)(e.cNodeOrder)},Nu=t=>{const e=KN(t.cGraph);return{...t,cGraph:Rd(b(n=>r=>Dn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},jN=t=>e=>b(n=>r=>{if(t==="LEFT"||t==="UP"){const i=r._2;return Dn(r._1)(a=>({...a,constraints:[...a.constraints,i]}))(n)}const o=r._1;return Dn(r._2)(i=>({...i,constraints:[...i.constraints,o]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),pr=t=>{const e={...t,cGraph:jN(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return H;if(r.tag==="Node")return ee("Node",r._1,r._2,r._3,{...r._4,constraints:[]},n(r._5),n(r._6));c()};return n(t.cGraph.cNodes)})()})};return{...e,cGraph:Rd((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);c()})())}},tb=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?pr(r):e==="RIGHT"?pr({...r,cGraph:Mn(r.cGraph)}):e==="UP"?pr({...r,cGraph:zr(r.cGraph)}):e==="DOWN"?pr({...r,cGraph:Mn(zr(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?Nu({...r,cGraph:Mn(r.cGraph)}):e==="UP"?pr({...r,cGraph:zr(r.cGraph)}):e==="DOWN"?pr({...r,cGraph:Mn(zr(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?Nu({...r,cGraph:Mn(r.cGraph)}):e==="UP"?pr({...r,cGraph:zr(Mn(r.cGraph))}):e==="DOWN"?pr({...r,cGraph:Mn(zr(Mn(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?pr({...r,cGraph:zr(r.cGraph)}):e==="RIGHT"?pr({...r,cGraph:Mn(zr(r.cGraph))}):e==="DOWN"?Nu({...r,cGraph:Mn(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?pr({...r,cGraph:zr(Mn(r.cGraph))}):e==="RIGHT"?pr({...r,cGraph:Mn(zr(Mn(r.cGraph)))}):e==="UP"?Nu({...r,cGraph:Mn(r.cGraph)}):r;c()},Pd=t=>e=>e.finished||!qN(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:tb(e.direction)(t)(e),eb=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?Pd(g_)(t):t,n={...e,cGraph:XN(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);c()},Gd=t=>e=>n=>{const r=de(t)(n.cNodes),o=de(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;c()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:it(ut)(t)({...r._1,cGroup:T("Just",e)})(n.cNodes),cGroups:it(ut)(e)({...o._1,cNodes:yn(uo)(t)(o._1.cNodes)?o._1.cNodes:[...o._1.cNodes,t],reference:(()=>{if(o._1.reference.tag==="Nothing")return T("Just",t);if(o._1.reference.tag==="Just")return T("Just",o._1.reference._1);c()})()})(n.cGroups)}:n},Bd=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:it(ut)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:y,cGroupOffset:VN,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:hr})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),__=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:b(r=>o=>Gd(o)(n)(r))({...e,cGroups:it(ut)(n)({id:n,master:t.master,cNodes:[],startPos:-1e308,incomingConstraints:[],outDegree:0,outDegreeReal:0,reference:y,delta:0,deltaNormalized:0})(e.cGroups),cGroupOrder:[...e.cGroupOrder,n],nextCGroupId:n+1|0})(t.nodes)}},nb=t=>b(e=>n=>{const r=de(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?__({master:y,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),rb=t=>({cGraph:UN(nb(c_(t))),direction:Ed,compactionAlgorithm:y,constraintAlgorithm:y,spacingsHandler:ZN,lockFun:y,finished:!1}),ob=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},ib=t=>e=>{const n=at.compare(t._1)(e._1);return n==="LT"?Me:n==="GT"?Qe:ut.compare(t._2)(e._2)},ab=(()=>{const t=un.unfoldr(Yn);return e=>t(gn("IterNode",e,Un))})(),Ad=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Id=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",zd=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),bu=t=>e=>ib(E(t.hitbox.x+t.hitbox.width/2,t.id))(E(e.hitbox.x+e.hitbox.width/2,e.id)),sb=t=>e=>{const n=Mo(Xt,y,r=>bu(t)(r)==="LT",e);if(n.tag==="Just"){const r=tf(Xt,y,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;c()}if(n.tag==="Nothing")return Et(e)(t);c()},Fd=t=>e=>{const n=_t(o=>bu(o)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?T("Just",n[r]):y},ub=t=>e=>{const n=sb(e)(t.intervals),r=te(i=>bu(e)(i)==="LT")(n),o=it(ut)(e.id)((()=>{const i=Fd(e)(n);return i.tag==="Just"?T("Just",i._1.id):y})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return it(ut)(r._1.id)(T("Just",e.id))(o);if(r.tag==="Nothing")return o;c()})()}},gb=t=>e=>{const n=at.compare(t.low?t.node.hitbox.y:t.node.hitbox.y+t.node.hitbox.height)(e.low?e.node.hitbox.y:e.node.hitbox.y+e.node.hitbox.height);return n==="EQ"?t.low?t.low&&!e.low?Qe:sn:e.low?Me:sn:n},cb=t=>b(e=>n=>Dn(n.id)(r=>({...r,constraints:[]}))(e))(t)(ht(e=>de(e)(t.cNodes))(t.cNodeOrder)),f_=t=>e=>b(n=>r=>{const o=de(r._1)(n.cNodes);if(o.tag==="Just")return Dn(r._1)(i=>({...i,constraints:[...i.constraints,...r._2]}))(n);if(o.tag==="Nothing")return n;c()})(e)(ab(t)),Dd=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}},Md=t=>e=>n=>b(r=>o=>n(o)?Dn(o.id)(Dd(t))(r):r)(e)(ht(r=>de(r)(e.cNodes))(e.cNodeOrder)),_b=t=>e=>{const n=(r,o,i)=>{const a=Dn(i)(Dd(t))(r);return o.length<=1?a:b(s=>u=>u===i?s:Dn(u)(g=>g.ignoreSpacing.up?{...g,hitbox:{...g.hitbox,y:g.hitbox.y+t+.01,height:g.hitbox.height-t-.01}}:g.ignoreSpacing.down?{...g,hitbox:{...g.hitbox,height:g.hitbox.height-t-.01}}:g)(s))(a)(o)};return b(r=>o=>{if(o.master.tag==="Nothing")return 0<o.cNodes.length?n(r,o.cNodes,o.cNodes[0]):r;if(o.master.tag==="Just")return n(r,o.cNodes,o.master._1);c()})(e)(ht(r=>de(r)(e.cGroups))(e.cGroupOrder))},fb=t=>e=>{const n=Fd(e)(t.intervals),r=te(i=>bu(e)(i)==="LT")(t.intervals),o=n.tag==="Just"&&(()=>{const i=Ad(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})()?Ht(ut)(we)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const i=Ad(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})()?Ht(ut)(we)(e.id)([r._1.id])(o):o,intervals:_t(i=>i.id!==e.id,t.intervals)}},lb=t=>e=>e.low?ub(t)(e.node):fb(t)(e.node),l_=t=>e=>b(lb)({intervals:[],cand:H,constraints:H})(Rt(gb)(St(_t(t,ht(n=>de(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,db=t=>e=>{const n=ob(0)(t/2-.5),r=f_(l_(Id)(Md(n)(e)(Id)))(e),o=f_(l_(zd)(Md(n)(r)(zd)))(r);return f_(l_(i=>!0)(_b(n)(o)))(o)},hb=t=>e=>db(t)(cb(e.cGraph)),vu=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Qd=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},d_=t=>e=>n=>r=>o=>({id:t,representedEdges:[o],affectedBends:[e,n],hitbox:{x:vu(e._1)(n._1),y:vu(e._2)(n._2),width:xe(e._1-n._1),height:xe(e._2-n._2)},ignoreSpacing:hr,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];c()})(),aPort:y}),pb=t=>e=>{const n=vu(t.hitbox.x)(e.hitbox.x),r=vu(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:Qd(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Qd(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;c()})()}},mb=t=>e=>xe(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,yb=t=>e=>xe(t.hitbox.x-e.hitbox.x)<=1e-4?at.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?Me:Qe,Hd=(t,e)=>({tag:t,_1:e}),h_=fe(B)(Qt),Cu=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Od=(()=>{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=B.compare(n._1)(r._1);if(o==="LT")return Me;if(o==="GT")return Qe;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?sn:Me;if(r._2.tag==="Nothing")return Qe;if(n._2.tag==="Just"&&r._2.tag==="Just")return B.compare(n._2._1)(r._2._1);c()},Eq0:()=>t};return b(n=>r=>it(e)(r)()(n))(H)})(),eo=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},xb=b(t=>e=>it($N)(e)()(t))(H),p_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=If.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},wb=t=>e=>{const n=h_(Y(i=>E(i.id,i))(t)),r=ht(i=>Cu(i)(n))(e),o=ut.compare((()=>{const i=Od(Y(a=>E(a.from.node,a.from.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;c()})())((()=>{const i=Od(Y(a=>E(a.to.node,a.to.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;c()})());if(o==="LT")return{...hr,left:!0,right:!1};if(o==="GT")return{...hr,left:!1,right:!0};if(o==="EQ")return hr;c()},Jb=t=>ht(e=>{if(e.direction==="V")return T("Just",{start:e.start,end:e.end});if(e.direction==="H")return y;c()})(t.segments),Lu=t=>e=>n=>r=>{if(r.tag==="Just"){const o=eo(n)(e);if(o.tag==="Just"){const i=te(a=>a.id===r._1)(o._1);if(i.tag==="Just")return i._1.side;if(i.tag==="Nothing")return t;c()}if(o.tag==="Nothing")return t;c()}if(r.tag==="Nothing")return t;c()},Tb=t=>e=>n=>{const r=Bd({origin:T("Just",Hd("SegmentOrigin",n)),kind:T("Just","vs"),hitbox:n.hitbox})(e.cGraph),o=YN(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const i=de(n.potentialGroupParents[0])(o.cNodes);if(i.tag==="Just"){if(i._1.cGroup.tag==="Just")return Gd(r.id)(i._1.cGroup._1)(o);if(i._1.cGroup.tag==="Nothing")return o;c()}if(i.tag==="Nothing")return o;c()}return __({master:T("Just",r.id),nodes:[r.id]})(o).graph})(),edgeToCs:b(i=>a=>Ht(B)(we)(a)([r.id])(i))(e.edgeToCs)(n.representedEdges),lockMap:it(ut)(r.id)(wb(t)(n.representedEdges))(e.lockMap)}},Nb=t=>e=>n=>{const r=It(o=>y,o=>i=>T("Just",{head:o,tail:i}),Rt(yb)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const o=b(i=>a=>mb(i.survivor)(a)?{...i,survivor:pb(i.survivor)(a)}:{survivor:a,merged:[...i.merged,i.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return b(Tb(t))(n)([...o.merged,o.survivor])}c()},bb=t=>({cGraph:{cNodes:H,cNodeOrder:[],cGroups:H,cGroupOrder:[],supportedDirections:xb([Ed,g_,ON]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:H,edgeToCs:H,lockMap:H}),vb=t=>{const e=ot(4);return{x:t.position._1*e,y:t.position._2*e,width:t.size._1*e,height:t.size._2*e}},Cb=t=>e=>n=>b(r=>o=>{const i=Bd({origin:T("Just",Hd("NodeOrigin",o.node)),kind:y,hitbox:vb(o)})(r.cGraph),a=eo(o.node)(t),s=(()=>{if(a.tag==="Nothing")return E(0,0);if(a.tag==="Just")return a._1;c()})();return{...r,cGraph:__({master:T("Just",i.id),nodes:[i.id]})(i.graph).graph,nodeToC:it(B)(o.node)(i.id)(r.nodeToC),lockMap:it(ut)(i.id)((()=>{const u=s._1-s._2|0;return u<0?{...hr,left:!0}:u>0?{...hr,right:!0}:hr})())(r.lockMap)}})(n)(e),Lb=t=>b(e=>n=>Ht(B)(r=>o=>E(r._1+o._1|0,r._2+o._2|0))(n.to.node)(E(1,0))(Ht(B)(r=>o=>E(r._1+o._1|0,r._2+o._2|0))(n.from.node)(E(0,1))(e)))(H)(t),kb=t=>b(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?it(B)(n.origin._1._1)(n.hitbox.x)(e):e)(H)(ht(e=>de(e)(t.cNodes))(t.cNodeOrder)),Sb=t=>b(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?it(B)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(H)(ht(e=>de(e)(t.cNodes))(t.cNodeOrder)),Eb=t=>b(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return b(o=>i=>it(If)(i)(r)(o))(e)(n.origin._1._1.affectedBends)}return e})(H)(ht(e=>de(e)(t.cNodes))(t.cNodeOrder)),Wd=t=>{const e=h_(Y(n=>E(n.id,n))(t.edges));return ht(n=>{const r=Cu(n.edge)(e);if(r.tag==="Just")return n.reversed?T("Just",{edgeId:n.edge,src:r._1.to.node,tgt:r._1.from.node,srcSide:Lu(Kr)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:Lu(Yr)(t.ports)(r._1.from.node)(r._1.from.port),path:n}):T("Just",{edgeId:n.edge,src:r._1.from.node,tgt:r._1.to.node,srcSide:Lu(Kr)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:Lu(Yr)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return y;c()})(t.paths)},Rb=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=eo(r.tgt)(t.nodeToC),i=(()=>{if(o.tag==="Just")return de(o._1)(t.cGraph.cNodes);if(o.tag==="Nothing")return y;c()})(),a=eo(r.src)(t.nodeToC),s=(()=>{if(a.tag==="Just")return de(a._1)(t.cGraph.cNodes);if(a.tag==="Nothing")return y;c()})(),u=(()=>{if(s.tag==="Just"){if(i.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(i._1.cGroup.tag==="Just")return T("Just",{srcGroup:s._1.cGroup._1,tgtGroup:i._1.cGroup._1,delta:0,weight:100});if(i._1.cGroup.tag==="Nothing")return y;c()}if(s._1.cGroup.tag==="Nothing")return y;c()}if(i.tag==="Nothing")return y;c()}if(s.tag==="Nothing")return y;c()})(),g=d=>h=>m=>{if(s.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(m.cGroup.tag==="Just")return d(m.hitbox.x)&&m.cGroup._1!==s._1.cGroup._1?T("Just",h(m.cGroup._1)(s._1.cGroup._1)):y;if(m.cGroup.tag==="Nothing")return y;c()}if(s._1.cGroup.tag==="Nothing")return y;c()}if(s.tag==="Nothing")return y;c()},_=ht(d=>de(d)(t.cGraph.cNodes))((()=>{const d=Cu(r.edgeId)(t.edgeToCs);if(d.tag==="Nothing")return[];if(d.tag==="Just")return d._1;c()})()),f=(()=>{if(s.tag==="Just"&&r.srcSide==="West"){const d=s._1;return ht(g(h=>h<d.hitbox.x)(h=>m=>({srcGroup:h,tgtGroup:m,delta:1,weight:100})))(_)}return[]})(),l=(()=>{if(s.tag==="Just"&&r.tgtSide==="East"){const d=s._1;return ht(g(h=>h>d.hitbox.x)(h=>m=>({srcGroup:m,tgtGroup:h,delta:1,weight:100})))(_)}return[]})();if(u.tag==="Nothing")return[];if(u.tag==="Just")return[u._1,...f,...l];c()});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 oe(a=>yn(kr)(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}},Pb=t=>e=>{const n=ot(4),r=kb(t),o=Sb(t),i=h_(Y(s=>E(s.id,E(s.from.node,s.to.node)))(e.edges)),a=Eb(t);return{nodes:Y(s=>{const u=eo(s.node)(r);if(u.tag==="Just")return{...s,position:E(u._1/n,s.position._2)};if(u.tag==="Nothing")return s;c()})(e.nodes),edges:Y(s=>{const u=Cu(s.edge)(i),g=(()=>{if(u.tag==="Nothing")return s.segments;if(u.tag==="Just"){const _=eo(u._1._1)(o),f=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;c()})(),l=eo(u._1._2)(o),d=(()=>{if(l.tag==="Nothing")return 0;if(l.tag==="Just")return l._1;c()})();return Dt((()=>{const h=s.reversed?d:f,m=s.reversed?f:d,p=s.segments.length;return x=>w=>{if(w.direction==="V"){const J=(()=>{if(x===0)return h;if(x===(p-1|0))return m;const N=p_(w.start)(a);if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})();return{...w,start:E(w.start._1+J,w.start._2),end:E(w.end._1+J,w.end._2)}}if(w.direction==="H")return{...w,start:E((()=>{if(x===0)return w.start._1+h;const J=p_(w.start)(a);if(J.tag==="Nothing")return w.start._1+0;if(J.tag==="Just")return w.start._1+J._1;c()})(),w.start._2),end:E((()=>{if(x===(p-1|0))return w.end._1+m;const J=p_(w.end)(a);if(J.tag==="Nothing")return w.end._1+0;if(J.tag==="Just")return w.end._1+J._1;c()})(),w.end._2)};c()}})())(s.segments)}c()})();return{...s,segments:g,bends:He(_=>f=>_.end,g,Bt(1,g.length,g))}})(e.paths)}},Gb=t=>e=>n=>r=>o=>i=>{const a=d_(o.nextId)(i._2.start)(i._2.end)(y)(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}};c()}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}};c()}return s})()]}},$d=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...d_(i.nextId)(r.start)(E(r.start._1,o.down?n.y:n.y+n.height))(T("Just",e))(t.edgeId),aPort:T("Just",{node:t.src,side:o.side}),ignoreSpacing:o.down?{...hr,down:!0}:{...hr,up:!0}}]}),ku=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...d_(i.nextId)(r.end)(E(r.end._1,o.down?n.y:n.y+n.height))(T("Just",e))(t.edgeId),aPort:T("Just",{node:t.tgt,side:o.side}),ignoreSpacing:o.down?{...hr,down:!0}:{...hr,up:!0}}]}),Bb=t=>e=>n=>{if(n.src===n.tgt)return e;const r=eo(n.src)(t.nodeToC),o=eo(n.tgt)(t.nodeToC),i=(()=>{if(r.tag==="Just"){const _=de(r._1)(t.cGraph.cNodes);return _.tag==="Just"?T("Just",_._1.hitbox):y}if(r.tag==="Nothing")return y;c()})(),a=(()=>{if(o.tag==="Just"){const _=de(o._1)(t.cGraph.cNodes);return _.tag==="Just"?T("Just",_._1.hitbox):y}if(o.tag==="Nothing")return y;c()})(),s=Jb(n.path),u=b(Gb(n)(i)(a)(s.length-1|0))(e)(Dt(_=>f=>E(_,f))(s));if(0<s.length){const _=(()=>{if(r.tag==="Just"&&i.tag==="Just"){if(n.srcSide==="North")return $d(n)(r._1)(i._1)(s[0])({side:Ie,down:!0})(u);if(n.srcSide==="South")return $d(n)(r._1)(i._1)(s[0])({side:ze,down:!1})(u)}return u})(),f=s.length-1|0;if(f>=0&&f<s.length&&o.tag==="Just"&&a.tag==="Just"){if(n.tgtSide==="North")return ku(n)(o._1)(a._1)(s[f])({side:Ie,down:!0})(_);if(n.tgtSide==="South")return ku(n)(o._1)(a._1)(s[f])({side:ze,down:!1})(_)}return _}const g=s.length-1|0;if(g>=0&&g<s.length&&o.tag==="Just"&&a.tag==="Just"){if(n.tgtSide==="North")return ku(n)(o._1)(a._1)(s[g])({side:Ie,down:!0})(u);if(n.tgtSide==="South")return ku(n)(o._1)(a._1)(s[g])({side:ze,down:!1})(u)}return u},Ab=t=>e=>n=>Nb(t)(b(Bb(n))({nextId:0,segments:[]})(e).segments)(n),Ib=t=>Ab(t.edges)(Wd(t))(Cb(Lb(t.edges))(t.nodes)(bb())),no=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}c()}return o},m_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},y_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},zb=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Fb=t=>{const e=t.Eq0();return n=>r=>{const o=s=>{let u=s,g=!0,_;for(;g;){const f=u,l=It(d=>y,d=>h=>T("Just",{head:d,tail:h}),f.queue);if(l.tag==="Nothing"){g=!1,_=f;continue}if(l.tag==="Just"){const d=l._1.head;if((m=>{let p=m,x=!0,w;for(;x;){const J=p;if(J.tag==="Leaf"){x=!1,w=!1;continue}if(J.tag==="Node"){const N=t.compare(d)(J._3);if(N==="LT"){p=J._5;continue}if(N==="GT"){p=J._6;continue}if(N==="EQ"){x=!1,w=!0;continue}}c()}return w})(f.removedNodes)){u={...f,queue:l._1.tail};continue}const h=te(m=>!no(m.eid)(f.removedEdges)&&(e.eq(m.src)(d)||e.eq(m.tgt)(d)))(r);if(h.tag==="Nothing"){u={...f,queue:l._1.tail};continue}if(h.tag==="Just"){const m=e.eq(h._1.src)(d)?h._1.tgt:h._1.src,p={...f,degree:it(t)(m)((()=>{const x=(w=>{let J=w,N=!0,k;for(;N;){const C=J;if(C.tag==="Leaf"){N=!1,k=y;continue}if(C.tag==="Node"){const R=t.compare(m)(C._3);if(R==="LT"){J=C._5;continue}if(R==="GT"){J=C._6;continue}if(R==="EQ"){N=!1,k=T("Just",C._4);continue}}c()}return k})(f.degree);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;c()})())(f.degree),removedNodes:it(t)(d)()(f.removedNodes),removedEdges:it(ut)(h._1.eid)()(f.removedEdges),record:[...f.record,{node:d,neighbour:m,viaSrc:e.eq(h._1.src)(d)}],queue:l._1.tail};if((()=>{const x=(J=>{let N=J,k=!0,C;for(;k;){const R=N;if(R.tag==="Leaf"){k=!1,C=y;continue}if(R.tag==="Node"){const P=t.compare(m)(R._3);if(P==="LT"){N=R._5;continue}if(P==="GT"){N=R._6;continue}if(P==="EQ"){k=!1,C=T("Just",R._4);continue}}c()}return C})(p.degree),w=J=>{let N=J,k=!0,C;for(;k;){const R=N;if(R.tag==="Leaf"){k=!1,C=!1;continue}if(R.tag==="Node"){const P=t.compare(m)(R._3);if(P==="LT"){N=R._5;continue}if(P==="GT"){N=R._6;continue}if(P==="EQ"){k=!1,C=!0;continue}}c()}return C};return(()=>{if(x.tag==="Nothing")return!1;if(x.tag==="Just")return x._1===1;c()})()&&!w(p.removedNodes)})()){u={...p,queue:[...p.queue,m]};continue}u=p;continue}}c()}return _},i=b(s=>u=>Ht(t)(ve)(u.src)(1)(Ht(t)(ve)(u.tgt)(1)(s)))(H)(r),a=o({degree:i,removedNodes:H,removedEdges:H,record:[],queue:_t(s=>{const u=(g=>{let _=g,f=!0,l;for(;f;){const d=_;if(d.tag==="Leaf"){f=!1,l=y;continue}if(d.tag==="Node"){const h=t.compare(s)(d._3);if(h==="LT"){_=d._5;continue}if(h==="GT"){_=d._6;continue}if(h==="EQ"){f=!1,l=T("Just",d._4);continue}}c()}return l})(i);if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1===1;c()},n)});return{coreNodes:_t(s=>!(u=>{let g=u,_=!0,f;for(;_;){const l=g;if(l.tag==="Leaf"){_=!1,f=!1;continue}if(l.tag==="Node"){const d=t.compare(s)(l._3);if(d==="LT"){g=l._5;continue}if(d==="GT"){g=l._6;continue}if(d==="EQ"){_=!1,f=!0;continue}}c()}return f})(a.removedNodes),n),coreEdges:_t(s=>!no(s.eid)(a.removedEdges),r),removed:a.record}}},Db=t=>e=>n=>b(r=>o=>{const i=o.neighbour,a=(()=>{const s=(u=>{let g=u,_=!0,f;for(;_;){const l=g;if(l.tag==="Leaf"){_=!1,f=y;continue}if(l.tag==="Node"){const d=t.compare(i)(l._3);if(d==="LT"){g=l._5;continue}if(d==="GT"){g=l._6;continue}if(d==="EQ"){_=!1,f=T("Just",l._4);continue}}c()}return f})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})();return it(t)(o.node)(o.viaSrc?a-1|0:a+1|0)(r)})(n)(re(e)),x_=t=>{const e=t.Eq0();return n=>r=>o=>{const i={...o,treeNode:it(t)(r)()(o.treeNode)};return b(a=>s=>{if(no(s.eid)(a.st.edgeVisited))return a;const u={...a.st,edgeVisited:it(ut)(s.eid)()(a.st.edgeVisited)},g=e.eq(s.src)((()=>{const _=s.src,f=d=>{let h=d,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const w=t.compare(_)(x._3);if(w==="LT"){h=x._5;continue}if(w==="GT"){h=x._6;continue}if(w==="EQ"){m=!1,p=!0;continue}}c()}return p},l=s.tgt;return f(u.treeNode)&&!(d=>{let h=d,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const w=t.compare(l)(x._3);if(w==="LT"){h=x._5;continue}if(w==="GT"){h=x._6;continue}if(w==="EQ"){m=!1,p=!0;continue}}c()}return p})(u.treeNode)})()?s.src:(()=>{const _=s.tgt,f=d=>{let h=d,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const w=t.compare(_)(x._3);if(w==="LT"){h=x._5;continue}if(w==="GT"){h=x._6;continue}if(w==="EQ"){m=!1,p=!0;continue}}c()}return p},l=s.src;return f(u.treeNode)&&!(d=>{let h=d,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const w=t.compare(l)(x._3);if(w==="LT"){h=x._5;continue}if(w==="GT"){h=x._6;continue}if(w==="EQ"){m=!1,p=!0;continue}}c()}return p})(u.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(no(s.eid)(u.treeEdge)){if((f=>{let l=f,d=!0,h;for(;d;){const m=l;if(m.tag==="Leaf"){d=!1,h=!1;continue}if(m.tag==="Node"){const p=t.compare(g)(m._3);if(p==="LT"){l=m._5;continue}if(p==="GT"){l=m._6;continue}if(p==="EQ"){d=!1,h=!0;continue}}c()}return h})(u.treeNode))return{...a,st:u};const _=x_(t)(n)(g)(u);return{count:a.count+_.count|0,st:_.st}}if((()=>{const _=l=>{let d=l,h=!0,m;for(;h;){const p=d;if(p.tag==="Leaf"){h=!1,m=!1;continue}if(p.tag==="Node"){const x=t.compare(g)(p._3);if(x==="LT"){d=p._5;continue}if(x==="GT"){d=p._6;continue}if(x==="EQ"){h=!1,m=!0;continue}}c()}return m},f=s.tgt;return!_(u.treeNode)&&(()=>{const l=(m=>{let p=m,x=!0,w;for(;x;){const J=p;if(J.tag==="Leaf"){x=!1,w=y;continue}if(J.tag==="Node"){const N=t.compare(f)(J._3);if(N==="LT"){p=J._5;continue}if(N==="GT"){p=J._6;continue}if(N==="EQ"){x=!1,w=T("Just",J._4);continue}}c()}return w})(u.layer),d=s.src,h=(m=>{let p=m,x=!0,w;for(;x;){const J=p;if(J.tag==="Leaf"){x=!1,w=y;continue}if(J.tag==="Node"){const N=t.compare(d)(J._3);if(N==="LT"){p=J._5;continue}if(N==="GT"){p=J._6;continue}if(N==="EQ"){x=!1,w=T("Just",J._4);continue}}c()}return w})(u.layer);if(l.tag==="Nothing"){if(h.tag==="Nothing")return s.delta===0;if(h.tag==="Just")return s.delta===-h._1;c()}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)}c()})()})()){const _=x_(t)(n)(g)({...u,treeEdge:it(ut)(s.eid)()(u.treeEdge)});return{count:a.count+_.count|0,st:_.st}}return{...a,st:u}})({count:1,st:i})(_t(a=>(e.eq(a.src)(r)||e.eq(a.tgt)(r))&&!no(a.eid)(i.edgeVisited),n))}},Su=t=>e=>n=>r=>{const o=r.src,i=(l=>{let d=l,h=!0,m;for(;h;){const p=d;if(p.tag==="Leaf"){h=!1,m=y;continue}if(p.tag==="Node"){const x=t.compare(o)(p._3);if(x==="LT"){d=p._5;continue}if(x==="GT"){d=p._6;continue}if(x==="EQ"){h=!1,m=T("Just",p._4);continue}}c()}return m})(e.poID),a=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;c()})(),s=r.tgt,u=(l=>{let d=l,h=!0,m;for(;h;){const p=d;if(p.tag==="Leaf"){h=!1,m=y;continue}if(p.tag==="Node"){const x=t.compare(s)(p._3);if(x==="LT"){d=p._5;continue}if(x==="GT"){d=p._6;continue}if(x==="EQ"){h=!1,m=T("Just",p._4);continue}}c()}return m})(e.poID),g=(()=>{if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;c()})(),_=(l=>{let d=l,h=!0,m;for(;h;){const p=d;if(p.tag==="Leaf"){h=!1,m=y;continue}if(p.tag==="Node"){const x=t.compare(n)(p._3);if(x==="LT"){d=p._5;continue}if(x==="GT"){d=p._6;continue}if(x==="EQ"){h=!1,m=T("Just",p._4);continue}}c()}return m})(e.poID),f=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;c()})();return(()=>{const l=r.src,d=(h=>{let m=h,p=!0,x;for(;p;){const w=m;if(w.tag==="Leaf"){p=!1,x=y;continue}if(w.tag==="Node"){const J=t.compare(l)(w._3);if(J==="LT"){m=w._5;continue}if(J==="GT"){m=w._6;continue}if(J==="EQ"){p=!1,x=T("Just",w._4);continue}}c()}return x})(e.lowestPoID);return(()=>{if(d.tag==="Nothing")return 0<=f;if(d.tag==="Just")return d._1<=f;c()})()&&(()=>{const h=r.tgt;return f<=a&&(()=>{const m=(p=>{let x=p,w=!0,J;for(;w;){const N=x;if(N.tag==="Leaf"){w=!1,J=y;continue}if(N.tag==="Node"){const k=t.compare(h)(N._3);if(k==="LT"){x=N._5;continue}if(k==="GT"){x=N._6;continue}if(k==="EQ"){w=!1,J=T("Just",N._4);continue}}c()}return J})(e.lowestPoID);return(()=>{if(m.tag==="Nothing")return 0<=f;if(m.tag==="Just")return m._1<=f;c()})()&&f<=g})()})()})()?a>=g:a<g},Mb=t=>{const e=fe(t)(Qt);return n=>({layer:e(Y(r=>E(r,0))(n)),treeNode:H,treeEdge:H,poID:H,lowestPoID:H,cutvalue:H,postOrder:1,edgeVisited:H})},Qb=t=>e=>n=>b(r=>o=>{if((()=>{const _=o.src,f=h=>{let m=h,p=!0,x;for(;p;){const w=m;if(w.tag==="Leaf"){p=!1,x=!1;continue}if(w.tag==="Node"){const J=t.compare(_)(w._3);if(J==="LT"){m=w._5;continue}if(J==="GT"){m=w._6;continue}if(J==="EQ"){p=!1,x=!0;continue}}c()}return x},l=o.tgt,d=h=>{let m=h,p=!0,x;for(;p;){const w=m;if(w.tag==="Leaf"){p=!1,x=!1;continue}if(w.tag==="Node"){const J=t.compare(l)(w._3);if(J==="LT"){m=w._5;continue}if(J==="GT"){m=w._6;continue}if(J==="EQ"){p=!1,x=!0;continue}}c()}return x};return f(n.treeNode)===d(n.treeNode)})())return r;const i=o.tgt,a=(_=>{let f=_,l=!0,d;for(;l;){const h=f;if(h.tag==="Leaf"){l=!1,d=y;continue}if(h.tag==="Node"){const m=t.compare(i)(h._3);if(m==="LT"){f=h._5;continue}if(m==="GT"){f=h._6;continue}if(m==="EQ"){l=!1,d=T("Just",h._4);continue}}c()}return d})(n.layer),s=o.src,u=(_=>{let f=_,l=!0,d;for(;l;){const h=f;if(h.tag==="Leaf"){l=!1,d=y;continue}if(h.tag==="Node"){const m=t.compare(s)(h._3);if(m==="LT"){f=h._5;continue}if(m==="GT"){f=h._6;continue}if(m==="EQ"){l=!1,d=T("Just",h._4);continue}}c()}return d})(n.layer),g=(()=>{if(a.tag==="Nothing"){if(u.tag==="Nothing")return-o.delta;if(u.tag==="Just")return-u._1-o.delta|0;c()}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}c()})();return g<r.slack?{edge:T("Just",o),slack:g}:r})({edge:y,slack:1e9})(e).edge,Hb=t=>{const e=fe(t)(Qt);return n=>r=>{const o=b(i=>a=>m_(i)((()=>{const s=(u=>{let g=u,_=!0,f;for(;_;){const l=g;if(l.tag==="Leaf"){_=!1,f=y;continue}if(l.tag==="Node"){const d=t.compare(a)(l._3);if(d==="LT"){g=l._5;continue}if(d==="GT"){g=l._6;continue}if(d==="EQ"){_=!1,f=T("Just",l._4);continue}}c()}return f})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(1e9)(n);return e(Y(i=>E(i,(()=>{const a=(s=>{let u=s,g=!0,_;for(;g;){const f=u;if(f.tag==="Leaf"){g=!1,_=y;continue}if(f.tag==="Node"){const l=t.compare(i)(f._3);if(l==="LT"){u=f._5;continue}if(l==="GT"){u=f._6;continue}if(l==="EQ"){g=!1,_=T("Just",f._4);continue}}c()}return _})(r);if(a.tag==="Nothing")return-o;if(a.tag==="Just")return a._1-o|0;c()})()))(n))}},qd=t=>{const e=t.Eq0();return n=>r=>o=>{const i=b(s=>u=>{const g=qd(t)(n)(e.eq(u.src)(r)?u.tgt:u.src)({...s.st,edgeVisited:it(ut)(u.eid)()(s.st.edgeVisited)});return{lowest:m_(s.lowest)(g.lowest),st:g.st}})({lowest:1e9,st:o})(_t(s=>no(s.eid)(o.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!no(s.eid)(o.edgeVisited),n)),a=m_(i.lowest)(i.st.postOrder);return{lowest:a,st:{...i.st,poID:it(t)(r)(i.st.postOrder)(i.st.poID),lowestPoID:it(t)(r)(a)(i.st.lowestPoID),postOrder:i.st.postOrder+1|0}}}},Vd=t=>{const e=qd(t);return n=>r=>o=>0<n.length?e(r)(n[0])({...o,edgeVisited:H,postOrder:1,poID:H,lowestPoID:H}).st:o},Ob=t=>{const e=t.Eq0();return n=>r=>o=>_t(i=>no(i.eid)(r.treeEdge)&&(e.eq(i.src)(o)||e.eq(i.tgt)(o)),n)},Wb=t=>e=>te(n=>{const r=y_(n.eid)(e.cutvalue);return no(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;c()})()})(t),Ud=t=>{const e=x_(t);return n=>r=>o=>{const i=0<n.length?T("Just",n[0]):y;if(i.tag==="Nothing")return o;if(i.tag==="Just"){const a=e(r)(i._1)({...o,edgeVisited:H,treeNode:H,treeEdge:H});if(a.count>=n.length)return a.st;const s=Qb(t)(r)(a.st);if(s.tag==="Nothing")return a.st;if(s.tag==="Just"){const u=s._1.tgt,g=(h=>{let m=h,p=!0,x;for(;p;){const w=m;if(w.tag==="Leaf"){p=!1,x=y;continue}if(w.tag==="Node"){const J=t.compare(u)(w._3);if(J==="LT"){m=w._5;continue}if(J==="GT"){m=w._6;continue}if(J==="EQ"){p=!1,x=T("Just",w._4);continue}}c()}return x})(a.st.layer),_=s._1.src,f=(h=>{let m=h,p=!0,x;for(;p;){const w=m;if(w.tag==="Leaf"){p=!1,x=y;continue}if(w.tag==="Node"){const J=t.compare(_)(w._3);if(J==="LT"){m=w._5;continue}if(J==="GT"){m=w._6;continue}if(J==="EQ"){p=!1,x=T("Just",w._4);continue}}c()}return x})(a.st.layer),l=(()=>{if(g.tag==="Nothing"){if(f.tag==="Nothing")return-s._1.delta;if(f.tag==="Just")return-f._1-s._1.delta|0;c()}if(g.tag==="Just"){if(f.tag==="Nothing")return(g._1-0|0)-s._1.delta|0;if(f.tag==="Just")return(g._1-f._1|0)-s._1.delta|0}c()})(),d=(()=>{const h=s._1.tgt;return(m=>{let p=m,x=!0,w;for(;x;){const J=p;if(J.tag==="Leaf"){x=!1,w=!1;continue}if(J.tag==="Node"){const N=t.compare(h)(J._3);if(N==="LT"){p=J._5;continue}if(N==="GT"){p=J._6;continue}if(N==="EQ"){x=!1,w=!0;continue}}c()}return w})(a.st.treeNode)})()?-l:l;return Ud(t)(n)(r)({...a.st,layer:b(h=>m=>(p=>{let x=p,w=!0,J;for(;w;){const N=x;if(N.tag==="Leaf"){w=!1,J=!1;continue}if(N.tag==="Node"){const k=t.compare(m)(N._3);if(k==="LT"){x=N._5;continue}if(k==="GT"){x=N._6;continue}if(k==="EQ"){w=!1,J=!0;continue}}c()}return J})(a.st.treeNode)?it(t)(m)((()=>{const p=(x=>{let w=x,J=!0,N;for(;J;){const k=w;if(k.tag==="Leaf"){J=!1,N=y;continue}if(k.tag==="Node"){const C=t.compare(m)(k._3);if(C==="LT"){w=k._5;continue}if(C==="GT"){w=k._6;continue}if(C==="EQ"){J=!1,N=T("Just",k._4);continue}}c()}return N})(a.st.layer);if(p.tag==="Nothing")return 0+d|0;if(p.tag==="Just")return p._1+d|0;c()})())(h):h)(a.st.layer)(n)})}}c()}},$b=t=>e=>n=>r=>b(o=>i=>{if(Su(t)(r)(i.src)(n)&&!Su(t)(r)(i.tgt)(n)){const a=i.tgt,s=(f=>{let l=f,d=!0,h;for(;d;){const m=l;if(m.tag==="Leaf"){d=!1,h=y;continue}if(m.tag==="Node"){const p=t.compare(a)(m._3);if(p==="LT"){l=m._5;continue}if(p==="GT"){l=m._6;continue}if(p==="EQ"){d=!1,h=T("Just",m._4);continue}}c()}return h})(r.layer),u=i.src,g=(f=>{let l=f,d=!0,h;for(;d;){const m=l;if(m.tag==="Leaf"){d=!1,h=y;continue}if(m.tag==="Node"){const p=t.compare(u)(m._3);if(p==="LT"){l=m._5;continue}if(p==="GT"){l=m._6;continue}if(p==="EQ"){d=!1,h=T("Just",m._4);continue}}c()}return h})(r.layer),_=(()=>{if(s.tag==="Nothing"){if(g.tag==="Nothing")return-i.delta;if(g.tag==="Just")return-g._1-i.delta|0;c()}if(s.tag==="Just"){if(g.tag==="Nothing")return(s._1-0|0)-i.delta|0;if(g.tag==="Just")return(s._1-g._1|0)-i.delta|0}c()})();if(_<o.slack)return{edge:T("Just",i),slack:_}}return o})({edge:y,slack:1e9})(e).edge,qb=t=>{const e=t.Eq0();return n=>r=>o=>i=>{const a=i.tgt,s=i.src;return b(u=>g=>{if((()=>{const _=y_(g.eid)(r.cutvalue);if(_.tag==="Just")return!0;if(_.tag==="Nothing")return!1;c()})()){const _=y_(g.eid)(r.cutvalue),f=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;c()})();return e.eq(s)(g.src)||e.eq(a)(g.tgt)?u-(f-g.weight):u+(f-g.weight)}return e.eq(o)(s)?e.eq(g.src)(o)?u+g.weight:u-g.weight:e.eq(g.src)(o)?u-g.weight:u+g.weight})(i.weight)(_t(u=>u.eid!==i.eid&&(e.eq(u.src)(o)||e.eq(u.tgt)(o)),n))}},Vb=t=>{const e=qb(t);return n=>r=>o=>{const i=(a,s,u)=>{const g=(_=>{let f=_,l=!0,d;for(;l;){const h=f;if(h.tag==="Leaf"){l=!1,d=y;continue}if(h.tag==="Node"){const m=t.compare(a)(h._3);if(m==="LT"){f=h._5;continue}if(m==="GT"){f=h._6;continue}if(m==="EQ"){l=!1,d=T("Just",h._4);continue}}c()}return d})(u);if(g.tag==="Just")return it(t)(a)(_t(_=>_.eid!==s.eid,g._1))(u);if(g.tag==="Nothing")return u;c()};return(a=>s=>{let u=a,g=s,_=!0,f;for(;_;){const l=u,d=g,h=(p=>{let x=p,w=!0,J;for(;w;){const N=x;if(N.tag==="Leaf"){w=!1,J=y;continue}if(N.tag==="Node"){const k=t.compare(d)(N._3);if(k==="LT"){x=N._5;continue}if(k==="GT"){x=N._6;continue}if(k==="EQ"){w=!1,J=T("Just",N._4);continue}}c()}return J})(l.unknown),m=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;c()})();if(m.length===1){const p=t.Eq0().eq(m[0].src)(d)?m[0].tgt:m[0].src;u={unknown:i(d,m[0],i(p,m[0],l.unknown)),cutvalue:it(ut)(m[0].eid)(e(n)(l)(d)(m[0]))(l.cutvalue)},g=p;continue}_=!1,f=l}return f})(r)(o)}},Kd=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:g=>_=>g.delta===_.delta&&g.eid===_.eid&&n.eq(g.src)(_.src)&&e.eq(g.tgt)(_.tgt)&&g.weight===_.weight},o={compare:g=>_=>{const f=ut.compare(g.delta)(_.delta);if(f==="LT"||f==="GT"||f!=="EQ")return f;const l=ut.compare(g.eid)(_.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const d=t.compare(g.src)(_.src);if(d==="LT"||d==="GT"||d!=="EQ")return d;const h=t.compare(g.tgt)(_.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const m=at.compare(g.weight)(_.weight);return m==="LT"||m==="GT"||m!=="EQ"?m:sn},Eq0:()=>r},i=b(g=>_=>it(o)(_)()(g))(H),a=Ob(t),s=fe(t)(Qt),u=Vb(t);return g=>_=>f=>{const l={unknown:s(Y(d=>E(d,Mt(wn.foldr,i(a(_)(f)(d)))))(g)),cutvalue:H};return{...f,cutvalue:b(u(_))(l)(_t(d=>{const h=(m=>{let p=m,x=!0,w;for(;x;){const J=p;if(J.tag==="Leaf"){x=!1,w=y;continue}if(J.tag==="Node"){const N=t.compare(d)(J._3);if(N==="LT"){p=J._5;continue}if(N==="GT"){p=J._6;continue}if(N==="EQ"){x=!1,w=T("Just",J._4);continue}}c()}return w})(l.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;c()},g)).cutvalue}}},Ub=t=>{const e=Vd(t),n=Kd(t);return r=>o=>i=>a=>s=>{const u={...s,treeEdge:it(ut)(a.eid)()(Mi(ut)(i.eid)(s.treeEdge))},g=a.tgt,_=(m=>{let p=m,x=!0,w;for(;x;){const J=p;if(J.tag==="Leaf"){x=!1,w=y;continue}if(J.tag==="Node"){const N=t.compare(g)(J._3);if(N==="LT"){p=J._5;continue}if(N==="GT"){p=J._6;continue}if(N==="EQ"){x=!1,w=T("Just",J._4);continue}}c()}return w})(u.layer),f=a.src,l=(m=>{let p=m,x=!0,w;for(;x;){const J=p;if(J.tag==="Leaf"){x=!1,w=y;continue}if(J.tag==="Node"){const N=t.compare(f)(J._3);if(N==="LT"){p=J._5;continue}if(N==="GT"){p=J._6;continue}if(N==="EQ"){x=!1,w=T("Just",J._4);continue}}c()}return w})(u.layer),d=(()=>{if(_.tag==="Nothing"){if(l.tag==="Nothing")return-a.delta;if(l.tag==="Just")return-l._1-a.delta|0;c()}if(_.tag==="Just"){if(l.tag==="Nothing")return(_._1-0|0)-a.delta|0;if(l.tag==="Just")return(_._1-l._1|0)-a.delta|0}c()})(),h=Su(t)(u)(a.tgt)(i)?d:-d;return n(r)(o)(e(r)(o)({...u,layer:b(m=>p=>Su(t)(u)(p)(i)?m:it(t)(p)((()=>{const x=(w=>{let J=w,N=!0,k;for(;N;){const C=J;if(C.tag==="Leaf"){N=!1,k=y;continue}if(C.tag==="Node"){const R=t.compare(p)(C._3);if(R==="LT"){J=C._5;continue}if(R==="GT"){J=C._6;continue}if(R==="EQ"){N=!1,k=T("Just",C._4);continue}}c()}return k})(u.layer);if(x.tag==="Nothing")return 0+h|0;if(x.tag==="Just")return x._1+h|0;c()})())(m))(u.layer)(r)}))}},Kb=t=>{const e=Ub(t);return n=>r=>o=>i=>(a=>s=>{let u=a,g=s,_=!0,f;for(;_;){const l=u,d=g;if(l===0){_=!1,f=d;continue}const h=Wb(o)(d);if(h.tag==="Nothing"){_=!1,f=d;continue}if(h.tag==="Just"){const m=$b(t)(o)(h._1)(d);if(m.tag==="Nothing"){_=!1,f=d;continue}if(m.tag==="Just"){u=l-1|0,g=e(r)(o)(h._1)(m._1)(d);continue}}c()}return f})(n)(i)},Yb=t=>{const e=Kd(t),n=Vd(t),r=Ud(t);return o=>i=>a=>e(o)(i)(n(o)(i)(r(o)(i)(a)))},Yd=t=>e=>b(n=>r=>Ht(t)(we)(e(r))([r])(n))(H),Xb=t=>{const e=fe(t)(Qt);return n=>r=>o=>{const i=u=>g=>_=>f=>{let l=u,d=g,h=_,m=f,p=!0,x;for(;p;){const w=l,J=d,N=h,k=m,C=It(R=>y,R=>P=>T("Just",{head:R,tail:P}),N);if(C.tag==="Nothing"){p=!1,x=k;continue}if(C.tag==="Just"){const R=C._1.head,P=(S=>{let v=S,D=!0,W;for(;D;){const M=v;if(M.tag==="Leaf"){D=!1,W=y;continue}if(M.tag==="Node"){const q=t.compare(R)(M._3);if(q==="LT"){v=M._5;continue}if(q==="GT"){v=M._6;continue}if(q==="EQ"){D=!1,W=T("Just",M._4);continue}}c()}return W})(k.layer),I=(()=>{if(P.tag==="Nothing")return 0;if(P.tag==="Just")return P._1;c()})(),U=b(S=>v=>{const D=v.tgt,W=(q=>{let $=q,G=!0,F;for(;G;){const Q=$;if(Q.tag==="Leaf"){G=!1,F=y;continue}if(Q.tag==="Node"){const O=t.compare(D)(Q._3);if(O==="LT"){$=Q._5;continue}if(O==="GT"){$=Q._6;continue}if(O==="EQ"){G=!1,F=T("Just",Q._4);continue}}c()}return F})(S.incident),M=(()=>{if(W.tag==="Nothing")return-1;if(W.tag==="Just")return W._1-1|0;c()})();return{st:{...S.st,layer:it(t)(v.tgt)(zb((()=>{const q=v.tgt,$=(G=>{let F=G,Q=!0,O;for(;Q;){const z=F;if(z.tag==="Leaf"){Q=!1,O=y;continue}if(z.tag==="Node"){const X=t.compare(q)(z._3);if(X==="LT"){F=z._5;continue}if(X==="GT"){F=z._6;continue}if(X==="EQ"){Q=!1,O=T("Just",z._4);continue}}c()}return O})(S.st.layer);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;c()})())(I+v.delta|0))(S.st.layer)},incident:it(t)(v.tgt)(M)(S.incident),queue:M===0?[...S.queue,v.tgt]:S.queue}})({st:k,incident:J,queue:C._1.tail})((()=>{const S=(v=>{let D=v,W=!0,M;for(;W;){const q=D;if(q.tag==="Leaf"){W=!1,M=y;continue}if(q.tag==="Node"){const $=t.compare(R)(q._3);if($==="LT"){D=q._5;continue}if($==="GT"){D=q._6;continue}if($==="EQ"){W=!1,M=T("Just",q._4);continue}}c()}return M})(w);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;c()})());l=w,d=U.incident,h=U.queue,m=U.st;continue}c()}return x},a=Yd(t)(u=>u.tgt)(r),s=e(Y(u=>E(u,(()=>{const g=(_=>{let f=_,l=!0,d;for(;l;){const h=f;if(h.tag==="Leaf"){l=!1,d=y;continue}if(h.tag==="Node"){const m=t.compare(u)(h._3);if(m==="LT"){f=h._5;continue}if(m==="GT"){f=h._6;continue}if(m==="EQ"){l=!1,d=T("Just",h._4);continue}}c()}return d})(a);if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1.length;c()})()))(n));return i(Yd(t)(u=>u.src)(r))(s)(_t(u=>{const g=(_=>{let f=_,l=!0,d;for(;l;){const h=f;if(h.tag==="Leaf"){l=!1,d=y;continue}if(h.tag==="Node"){const m=t.compare(u)(h._3);if(m==="LT"){f=h._5;continue}if(m==="GT"){f=h._6;continue}if(m==="EQ"){l=!1,d=T("Just",h._4);continue}}c()}return d})(s);if(g.tag==="Nothing")return!0;if(g.tag==="Just")return g._1===0;c()},n))(o)}},Zb=t=>{const e=Mb(t),n=Xb(t),r=Yb(t),o=Kb(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}},Xd=t=>{const e=Hb(t),n=Zb(t),r=Fb(t);return o=>i=>{if(o.length===0)return H;if(o.length<40)return e(o)(n(o)(i));const a=r(o)(i);return e(o)(Db(t)(a.removed)(n(a.coreNodes)(a.coreEdges)))}},Zd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},w_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},jb=Xd(ut),Wa=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}),tv=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=ot((()=>{const o=Zd(n.cGroup._1)(t);if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;c()})());return Dn(n.id)(o=>({...o,hitbox:{...o.hitbox,x:r+o.cGroupOffset.x}}))(e)}c()},ev=t=>e=>({...e,cGraph:b(tv(t))(e.cGraph)((()=>{const n=e.cGraph;return ht(r=>de(r)(n.cNodes))(n.cNodeOrder)})())}),nv=t=>e=>n=>r=>o=>{const i=he(Cs(e.cGroupOffset.x-t.cGroupOffset.x));return Wa({src:o.nextNodeId,tgt:r,delta:w_(0)(-i),weight:1})(Wa({src:o.nextNodeId,tgt:n,delta:w_(0)(i),weight:1})({...o,nodes:[...o.nodes,o.nextNodeId],nextNodeId:o.nextNodeId+1|0}))},rv=t=>e=>n=>r=>o=>i=>a=>{const s=w_(0)(he(Cs(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)?nv(n)(r)(o)(i)(a):Wa({src:o,tgt:i,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(a)},ov=t=>e=>n=>r=>o=>{const i=de(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"?rv(t)(e)(n)(i._1)(n.cGroup._1)(i._1.cGroup._1)(r):r;c()},iv=t=>e=>n=>r=>b(ov(t)(e)(r))(n)(r.constraints),av=t=>e=>Wa({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),sv=t=>{const e=b(o=>i=>Ht(ut)(ve)(i.tgt)(1)(o))(H)(t.edges),n=_t(o=>{const i=Zd(o)(e);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return i._1===0;c()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return b(o=>i=>Wa({src:r,tgt:i,delta:1,weight:0})(o))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},uv=t=>e=>{const n=sv(b(av)(b(iv(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return ht(o=>de(o)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},gv=t=>e=>{const n=uv(t)(e);return ev(jb(n.nodes)(n.edges))(e)},jd=t=>t,Te=jd("H"),Ne=jd("V"),cv=t=>E(t._2,t._1),th=t=>({...t,position:E(t.position._2,t.position._1),size:E(t.size._2,t.size._1)}),_v=t=>({start:E(t.start._2,t.start._1),end:E(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return Ne;if(t.direction==="V")return Te;c()})()}),eh=t=>({...t,segments:Y(_v)(t.segments),bends:Y(cv)(t.bends)}),fv=t=>({nodes:Y(th)(t.nodes),edges:t.edges,paths:Y(eh)(t.paths),ports:t.ports}),lv={nodeNode:8,edgeNode:4,edgeEdge:10},dv=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}}),hv=t=>e=>gv(e),pv=t=>e=>n=>{const r=fv(n),o=Ib(r),i=Rb(o)(Wd(r)),a=Pb(Pd(g_)(eb({...rb(o.cGraph),compactionAlgorithm:T("Just",hv()(i)),constraintAlgorithm:T("Just",hb(e.edgeEdge)),spacingsHandler:dv(e)(i)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:Y(th)(a.nodes),edges:Y(eh)(a.edges)}},nh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},rh=t=>Ve(3)(t)==="$d:",mv=t=>e=>n=>b(r=>o=>{const i=nh(o.from.node)(t),a=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;c()})(),s=nh(o.to.node)(t),u=(()=>{if(s.tag==="Nothing")return-a;if(s.tag==="Just")return s._1-a|0;c()})();if(u<=1)return{...r,edges:[...r.edges,o],chains:[...r.chains,{edgeId:o.id,nodes:[o.from.node,o.to.node]}]};const g=o.id,_=Y(l=>"$d:"+g+":"+ue(l))(Ut(1,u-1|0)),f=[o.from.node,..._,o.to.node];return{...r,layers:b(l=>d=>{const h=d._2,m=cy(a+d._1|0)(p=>[...p,h])(l);if(m.tag==="Nothing")return l;if(m.tag==="Just")return m._1;c()})(r.layers)(He(mn,Ut(1,u-1|0),_)),edges:[...r.edges,...He(l=>d=>({id:g+":"+l+"->"+d,from:{node:l,port:o.from.port},to:{node:d,port:o.to.port},label:y}),f,Bt(1,f.length,f))],chains:[...r.chains,{edgeId:o.id,nodes:f}]}})({layers:n,edges:[],chains:[]})(e),oh=t=>t,aa=fe(ut)(Qt),Zt=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},ih=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Lt=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},kt=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},sa=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},yv=t=>e=>{const n=ut.compare(t._1)(e._1);return n==="LT"?Me:n==="GT"?Qe:ut.compare(t._2)(e._2)},ua=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},xv=(()=>{const t=un.unfoldr(Yn);return e=>t(gn("IterNode",e,Un))})(),wv=t=>t,ah=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Jv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Eu=oh("Regular"),Ru=oh("Critical"),sh=t=>e=>{const n=b(a=>s=>it(B)(s.node)(s)(a))(H)(e),r=1.25*ot(4),o=(a,s,u)=>(g=>_=>f=>{let l=g,d=_,h=f,m=!0,p;for(;m;){const x=l,w=d,J=h;if(J.critical){m=!1,p=J;continue}const N=It(C=>y,C=>R=>T("Just",{head:C,tail:R}),x),k=It(C=>y,C=>R=>T("Just",{head:C,tail:R}),w);if(N.tag==="Just"&&k.tag==="Just"){const C=N._1.head>k._1.head-a&&N._1.head<k._1.head+a?{...J,critical:!0}:N._1.head>k._1.head-r&&N._1.head<k._1.head+r?{...J,conflicts:J.conflicts+1|0}:J;if(C.critical){m=!1,p=C;continue}if(N._1.head<=k._1.head){l=N._1.tail,d=w,h=C;continue}l=x,d=k._1.tail,h=C;continue}m=!1,p=J}return p})(s)(u)({conflicts:0,critical:!1}),i=(a,s,u)=>{if(kt(b(kt)(-1e18)(s.incoming))(b(kt)(-1e18)(s.outgoing))-Lt(b(Lt)(1e18)(s.incoming))(b(Lt)(1e18)(s.outgoing))<.001||kt(b(kt)(-1e18)(u.incoming))(b(kt)(-1e18)(u.outgoing))-Lt(b(Lt)(1e18)(u.incoming))(b(Lt)(1e18)(u.outgoing))<.001)return[];const g=o(a,s.outgoing,u.incoming),_=o(a,u.outgoing,s.incoming);if(g.critical||_.critical)return[...g.critical?[{src:u.id,tgt:s.id,weight:1,kind:Ru}]:[],..._.critical?[{src:s.id,tgt:u.id,weight:1,kind:Ru}]:[]];const f=Lt(b(Lt)(1e18)(s.incoming))(b(Lt)(1e18)(s.outgoing)),l=kt(b(kt)(-1e18)(s.incoming))(b(kt)(-1e18)(s.outgoing)),d=Lt(b(Lt)(1e18)(u.incoming))(b(Lt)(1e18)(u.outgoing)),h=kt(b(kt)(-1e18)(u.incoming))(b(kt)(-1e18)(u.outgoing)),m=(1*g.conflicts|0)+(16*(b(x=>w=>w>h?x:w>=d?x+1|0:x)(0)(s.outgoing)+b(x=>w=>w>l?x:w>=f?x+1|0:x)(0)(u.incoming)|0)|0)|0,p=(1*_.conflicts|0)+(16*(b(x=>w=>w>l?x:w>=f?x+1|0:x)(0)(u.outgoing)+b(x=>w=>w>h?x:w>=d?x+1|0:x)(0)(s.incoming)|0)|0)|0;return m<p?[{src:s.id,tgt:u.id,weight:p-m|0,kind:Eu}]:m>p?[{src:u.id,tgt:s.id,weight:m-p|0,kind:Eu}]:m>0?[{src:s.id,tgt:u.id,weight:0,kind:Eu},{src:u.id,tgt:s.id,weight:0,kind:Eu}]:[]};return b(a=>s=>b(u=>g=>it(B)(g._1)(g._2)(u))(a)((()=>{const u=b(S=>v=>{const D=v.edge.from.node+"|"+(()=>{if(v.edge.from.port.tag==="Just")return v.edge.from.port._1;if(v.edge.from.port.tag==="Nothing")return"_auto_"+v.edge.id;c()})(),W=ah(D)(S.entries);if(W.tag==="Nothing")return{...S,entries:it(B)(D)({id:0,members:[v.edge.id],incoming:[v.fromPos._1],outgoing:[v.toPos._1],slot:0,mark:0,splitBy:y,splitPartner:y})(S.entries),order:[...S.order,D]};if(W.tag==="Just")return{...S,entries:it(B)(D)({...W._1,members:[...W._1.members,v.edge.id],incoming:[...Er(M=>M<v.fromPos._1)(W._1.incoming).init,v.fromPos._1,...Er(M=>M<=v.fromPos._1)(W._1.incoming).rest],outgoing:[...Er(M=>M<v.toPos._1)(W._1.outgoing).init,v.toPos._1,...Er(M=>M<=v.toPos._1)(W._1.outgoing).rest]})(S.entries)};c()})({entries:H,order:[]})(s._2),g=Dt(S=>v=>({...v,id:S}))(ht(S=>ah(S)(u.entries))(u.order));if(g.length===0)return[];const _=b(S=>v=>S.prev.tag==="Just"&&v-S.prev._1<1e-9?S:{prev:T("Just",v),out:[...S.out,v]})({prev:y,out:[]})(Rt(at.compare)([...St(g)(S=>S.incoming),...St(g)(S=>S.outgoing)])).out,f=_.length<2?.2*r:.2*b(S=>v=>{if(S.prev.tag==="Nothing")return{prev:T("Just",v),mn:S.mn};if(S.prev.tag==="Just")return{prev:T("Just",v),mn:Lt(S.mn)(v-S.prev._1)};c()})({prev:y,mn:1e18})(_).mn,l={segments:g,deps:(()=>{const S=g.length;return St(St(Ut(0,S-2|0))(v=>St(Ut(v+1|0,S-1|0))(D=>[E(v,D)])))(v=>v._1>=0&&v._1<g.length?v._2>=0&&v._2<g.length?i(f,g[v._1],g[v._2]):[]:[])})()},d=_t(S=>{if(S.kind==="Critical")return!0;if(S.kind==="Regular")return!1;c()},l.deps),h=(()=>{if(d.length<2)return l;const S=aa((()=>{const q=l.segments;return Y($=>E($.id,$.mark))((()=>{const $=q.length,G=Q=>{let O=Q,z=!0,X;for(;z;){const V=O,K=te(Z=>{const nt=Zt(Z)(V.inWeight);if(nt.tag==="Nothing")return!0;if(nt.tag==="Just")return nt._1===0;c()})(V.remaining);if(K.tag==="Nothing"){z=!1,X=V;continue}if(K.tag==="Just"){const Z=K._1;O={...V,inWeight:b(nt=>rt=>Ht(ut)(ve)(rt.tgt)(-rt.weight)(nt))(V.inWeight)((()=>{const nt=Zt(Z)(V.depsBySrc);if(nt.tag==="Nothing")return[];if(nt.tag==="Just")return nt._1;c()})()),marks:it(ut)(Z)(V.nextSource)(V.marks),nextSource:V.nextSource+1|0,outWeight:b(nt=>rt=>Ht(ut)(ve)(rt.src)(-rt.weight)(nt))(V.outWeight)((()=>{const nt=Zt(Z)(V.depsByTgt);if(nt.tag==="Nothing")return[];if(nt.tag==="Just")return nt._1;c()})()),remaining:_t(nt=>nt!==Z,V.remaining)};continue}c()}return X},F=Q=>{let O=Q,z=!0,X;for(;z;){const V=O,K=te(Z=>{const nt=Zt(Z)(V.outWeight);if(nt.tag==="Nothing")return!0;if(nt.tag==="Just")return nt._1===0;c()})(V.remaining);if(K.tag==="Nothing"){z=!1,X=V;continue}if(K.tag==="Just"){const Z=K._1;O={...V,inWeight:b(nt=>rt=>Ht(ut)(ve)(rt.tgt)(-rt.weight)(nt))(V.inWeight)((()=>{const nt=Zt(Z)(V.depsBySrc);if(nt.tag==="Nothing")return[];if(nt.tag==="Just")return nt._1;c()})()),marks:it(ut)(Z)(V.nextSink)(V.marks),nextSink:V.nextSink-1|0,outWeight:b(nt=>rt=>Ht(ut)(ve)(rt.src)(-rt.weight)(nt))(V.outWeight)((()=>{const nt=Zt(Z)(V.depsByTgt);if(nt.tag==="Nothing")return[];if(nt.tag==="Just")return nt._1;c()})()),remaining:_t(nt=>nt!==Z,V.remaining)};continue}c()}return X};return(Q=>{let O=Q,z=!0,X;for(;z;){const V=G(F(O));if(V.remaining.length===0){z=!1,X=Y(K=>{const Z=Zt(K.id)(V.marks),nt=(()=>{if(Z.tag==="Nothing")return K.id;if(Z.tag==="Just")return Z._1;c()})();return{...K,mark:nt<$?(nt+$|0)+1|0:nt}})(q);continue}O=(()=>{const K=nt=>{const rt=Zt(nt)(V.outWeight),ft=Zt(nt)(V.inWeight);return(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()-(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;c()})()|0},Z=Rt(nt=>rt=>ut.compare(K(rt))(K(nt)))(V.remaining);if(0<Z.length){const nt=Z[0];return{...V,inWeight:b(rt=>ft=>Ht(ut)(ve)(ft.tgt)(-ft.weight)(rt))(V.inWeight)((()=>{const rt=Zt(nt)(V.depsBySrc);if(rt.tag==="Nothing")return[];if(rt.tag==="Just")return rt._1;c()})()),marks:it(ut)(nt)(V.nextSource)(V.marks),nextSource:V.nextSource+1|0,outWeight:b(rt=>ft=>Ht(ut)(ve)(ft.src)(-ft.weight)(rt))(V.outWeight)((()=>{const rt=Zt(nt)(V.depsByTgt);if(rt.tag==="Nothing")return[];if(rt.tag==="Just")return rt._1;c()})()),remaining:_t(rt=>rt!==nt,V.remaining)}}return V})()}return X})({remaining:Y(Q=>Q.id)(q),marks:H,inWeight:b(Q=>O=>Ht(ut)(ve)(O.tgt)(O.weight)(Q))(H)(d),outWeight:b(Q=>O=>Ht(ut)(ve)(O.src)(O.weight)(Q))(H)(d),depsBySrc:b(Q=>O=>Ht(ut)(we)(O.src)([O])(Q))(H)(d),depsByTgt:b(Q=>O=>Ht(ut)(we)(O.tgt)([O])(Q))(H)(d),nextSink:$-1|0,nextSource:$+1|0})})())})()),v=_t(q=>{const $=Zt(q.src)(S),G=Zt(q.tgt)(S);return(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;c()})()>(()=>{if(G.tag==="Nothing")return 0;if(G.tag==="Just")return G._1;c()})()},d);if(v.length===0)return l;const D=b(q=>$=>{if(yn(uo)($.src)(q.decisions)||yn(uo)($.tgt)(q.decisions))return q;const G=Zt($.src)(q.segMap),F=Zt($.tgt)(q.segMap);if(G.tag==="Just"&&F.tag==="Just"){const Q=(G._1.incoming.length+G._1.outgoing.length|0)>2&&(F._1.incoming.length+F._1.outgoing.length|0)<=2,O=Q?F._1:G._1;return{decisions:[...q.decisions,O.id],segMap:it(ut)(O.id)({...O,splitBy:T("Just",Q?G._1.id:F._1.id)})(q.segMap)}}return q})({decisions:[],segMap:aa(Y(q=>E(q.id,q))(l.segments))})(v),W=D.segMap,M=b(q=>$=>{const G=Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)($.outgoing)),F=kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)($.outgoing)),Q=_t(K=>K.a.startPosition<=F&&K.a.endPosition>=G,Dt(K=>Z=>({i:K,a:Z}))(q.freeAreas));if(Q.length===0){const K={...$,incoming:Rt(at.compare)($.incoming),outgoing:Rt(at.compare)([(G+F)/2]),splitPartner:T("Just",q.nextId)},Z={id:q.nextId,incoming:Rt(at.compare)([(G+F)/2]),mark:0,members:$.members,outgoing:Rt(at.compare)($.outgoing),slot:0,splitBy:y,splitPartner:T("Just",$.id)};return{segMap:it(ut)(Z.id)(Z)(it(ut)(K.id)(K)(q.segMap)),freeAreas:q.freeAreas,nextId:q.nextId+1|0}}const O=0<Q.length?T("Just",Q[0]):y,z=(()=>{if(O.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(O.tag==="Just"){if(Q.length===1)return O._1;const K=Y(Z=>({c:Z,rating:(()=>{const nt=(Z.a.startPosition+Z.a.endPosition)/2,rt=[nt],ft=[nt],Nt=b((()=>{const mt=q.segMap;return vt=>Wt=>{const Tt=Zt(Wt.tgt)(mt);if(Tt.tag==="Nothing")return vt;if(Tt.tag==="Just"){const Vt=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),Gt=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),bt=Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)(rt)),pt=(()=>{const qt=kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)(rt)),jt=b(ge=>be=>be>Gt?ge:be>=Vt?ge+1|0:ge)(0)(rt)+b(ge=>be=>be>qt?ge:be>=bt?ge+1|0:ge)(0)(Tt._1.incoming)|0,an=Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)(rt)),$e=kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)(rt)),Wn=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),$n=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),Ze=b(ge=>be=>be>$e?ge:be>=an?ge+1|0:ge)(0)(Tt._1.outgoing)+b(ge=>be=>be>$n?ge:be>=Wn?ge+1|0:ge)(0)($.incoming)|0;return jt===Ze?jt>0?{...vt,deps:vt.deps+2|0,crossings:vt.crossings+jt|0}:vt:{...vt,deps:vt.deps+1|0,crossings:vt.crossings+ua(jt)(Ze)|0}})(),ct=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),Jt=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),At=Lt(b(Lt)(1e18)(ft))(b(Lt)(1e18)($.outgoing)),yt=kt(b(kt)(-1e18)(ft))(b(kt)(-1e18)($.outgoing)),Ct=b(qt=>jt=>jt>Jt?qt:jt>=ct?qt+1|0:qt)(0)($.outgoing)+b(qt=>jt=>jt>yt?qt:jt>=At?qt+1|0:qt)(0)(Tt._1.incoming)|0,Ot=Lt(b(Lt)(1e18)(ft))(b(Lt)(1e18)($.outgoing)),Ft=kt(b(kt)(-1e18)(ft))(b(kt)(-1e18)($.outgoing)),se=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),_e=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),pn=b(qt=>jt=>jt>Ft?qt:jt>=Ot?qt+1|0:qt)(0)(Tt._1.outgoing)+b(qt=>jt=>jt>_e?qt:jt>=se?qt+1|0:qt)(0)(ft)|0;return Ct===pn?Ct>0?{...pt,deps:pt.deps+2|0,crossings:pt.crossings+Ct|0}:pt:{...pt,deps:pt.deps+1|0,crossings:pt.crossings+ua(Ct)(pn)|0}}c()}})())(b((()=>{const mt=q.segMap;return vt=>Wt=>{const Tt=Zt(Wt.src)(mt);if(Tt.tag==="Nothing")return vt;if(Tt.tag==="Just"){const Vt=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),Gt=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),bt=Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)(rt)),pt=(()=>{const qt=kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)(rt)),jt=b(ge=>be=>be>Gt?ge:be>=Vt?ge+1|0:ge)(0)(rt)+b(ge=>be=>be>qt?ge:be>=bt?ge+1|0:ge)(0)(Tt._1.incoming)|0,an=Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)(rt)),$e=kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)(rt)),Wn=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),$n=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),Ze=b(ge=>be=>be>$e?ge:be>=an?ge+1|0:ge)(0)(Tt._1.outgoing)+b(ge=>be=>be>$n?ge:be>=Wn?ge+1|0:ge)(0)($.incoming)|0;return jt===Ze?jt>0?{...vt,deps:vt.deps+2|0,crossings:vt.crossings+jt|0}:vt:{...vt,deps:vt.deps+1|0,crossings:vt.crossings+ua(jt)(Ze)|0}})(),ct=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),Jt=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),At=Lt(b(Lt)(1e18)(ft))(b(Lt)(1e18)($.outgoing)),yt=kt(b(kt)(-1e18)(ft))(b(kt)(-1e18)($.outgoing)),Ct=b(qt=>jt=>jt>Jt?qt:jt>=ct?qt+1|0:qt)(0)($.outgoing)+b(qt=>jt=>jt>yt?qt:jt>=At?qt+1|0:qt)(0)(Tt._1.incoming)|0,Ot=Lt(b(Lt)(1e18)(ft))(b(Lt)(1e18)($.outgoing)),Ft=kt(b(kt)(-1e18)(ft))(b(kt)(-1e18)($.outgoing)),se=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),_e=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),pn=b(qt=>jt=>jt>Ft?qt:jt>=Ot?qt+1|0:qt)(0)(Tt._1.outgoing)+b(qt=>jt=>jt>_e?qt:jt>=se?qt+1|0:qt)(0)(ft)|0;return Ct===pn?Ct>0?{...pt,deps:pt.deps+2|0,crossings:pt.crossings+Ct|0}:pt:{...pt,deps:pt.deps+1|0,crossings:pt.crossings+ua(Ct)(pn)|0}}c()}})())({crossings:0,deps:0})(_t(mt=>mt.tgt===$.id,l.deps)))(_t(mt=>mt.src===$.id,l.deps)),lt=(()=>{if($.splitBy.tag==="Just")return Zt($.splitBy._1)(q.segMap);if($.splitBy.tag==="Nothing")return y;c()})();if(lt.tag==="Just")return{...Nt,deps:Nt.deps+2|0,crossings:(()=>{const mt=Lt(b(Lt)(1e18)(lt._1.incoming))(b(Lt)(1e18)(lt._1.outgoing)),vt=Lt(b(Lt)(1e18)(ft))(b(Lt)(1e18)($.outgoing)),Wt=kt(b(kt)(-1e18)(lt._1.incoming))(b(kt)(-1e18)(lt._1.outgoing)),Tt=kt(b(kt)(-1e18)(ft))(b(kt)(-1e18)($.outgoing)),Vt=Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)(rt));return Nt.crossings+(()=>{const Gt=Lt(b(Lt)(1e18)(lt._1.incoming))(b(Lt)(1e18)(lt._1.outgoing)),bt=kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)(rt)),pt=kt(b(kt)(-1e18)(lt._1.incoming))(b(kt)(-1e18)(lt._1.outgoing));return((b(ct=>Jt=>Jt>Wt?ct:Jt>=mt?ct+1|0:ct)(0)(rt)+b(ct=>Jt=>Jt>bt?ct:Jt>=Vt?ct+1|0:ct)(0)(lt._1.incoming)|0)+b(ct=>Jt=>Jt>Tt?ct:Jt>=vt?ct+1|0:ct)(0)(lt._1.outgoing)|0)+b(ct=>Jt=>Jt>pt?ct:Jt>=Gt?ct+1|0:ct)(0)(ft)|0})()|0})()};if(lt.tag==="Nothing")return Nt;c()})()}))(Q);return b(Z=>nt=>nt.rating.crossings<Z.rating.crossings||!(nt.rating.crossings>Z.rating.crossings)&&(nt.rating.deps<Z.rating.deps||!(nt.rating.deps>Z.rating.deps)&&nt.c.a.size>Z.c.a.size)?nt:Z)(0<K.length?K[0]:{c:O._1,rating:{crossings:1e6,deps:1e6}})(K).c}c()})(),X={...$,incoming:Rt(at.compare)($.incoming),outgoing:Rt(at.compare)([(z.a.startPosition+z.a.endPosition)/2]),splitPartner:T("Just",q.nextId)},V={id:q.nextId,incoming:Rt(at.compare)([(z.a.startPosition+z.a.endPosition)/2]),mark:0,members:$.members,outgoing:Rt(at.compare)($.outgoing),slot:0,splitBy:y,splitPartner:T("Just",$.id)};return{segMap:it(ut)(V.id)(V)(it(ut)(X.id)(X)(q.segMap)),freeAreas:(()=>{if(z.i>=0&&z.i<q.freeAreas.length){const K=ef(Xt,y,z.i,q.freeAreas),Z=(()=>{if(K.tag==="Nothing")return q.freeAreas;if(K.tag==="Just")return K._1;c()})();if(q.freeAreas[z.i].size/2<f)return Z;const nt=(q.freeAreas[z.i].startPosition+q.freeAreas[z.i].endPosition)/2,rt=nt-f,ft=nt+f;return[...z.i<1?[]:Bt(0,z.i,Z),...q.freeAreas[z.i].startPosition<=rt?[{startPosition:q.freeAreas[z.i].startPosition,endPosition:rt,size:rt-q.freeAreas[z.i].startPosition}]:[],...ft<=q.freeAreas[z.i].endPosition?[{startPosition:ft,endPosition:q.freeAreas[z.i].endPosition,size:q.freeAreas[z.i].endPosition-ft}]:[],...z.i<1?Z:Bt(z.i,Z.length,Z)]}return q.freeAreas})(),nextId:q.nextId+1|0}})({segMap:W,freeAreas:(()=>{const q=Rt(at.compare)([...St(l.segments)($=>$.incoming),...St(l.segments)($=>$.outgoing)]);return ht(wv)(He($=>G=>G-$>=2*f?T("Just",{startPosition:$+f,endPosition:G-f,size:G-$-2*f}):y,q,Bt(1,q.length,q)))})(),nextId:l.segments.length})(Rt(q=>$=>at.compare(kt(b(kt)(-1e18)(q.incoming))(b(kt)(-1e18)(q.outgoing))-Lt(b(Lt)(1e18)(q.incoming))(b(Lt)(1e18)(q.outgoing)))(kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)($.outgoing))-Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)($.outgoing))))(ht(q=>Zt(q)(W))(D.decisions)));return{segments:(()=>{const q=($,G)=>{if($.tag==="Leaf")return G;if($.tag==="Node")return q($._5,wt("Cons",$._4,q($._6,G)));c()};return Mt(ce.foldr,q(M.segMap,A))})(),deps:(()=>{const q=M.segMap,$=(Q,O)=>{if(Q.tag==="Leaf")return O;if(Q.tag==="Node")return $(Q._5,wt("Cons",Q._4,$(Q._6,O)));c()},G=Mt(ce.foldr,$(q,A)),F=G.length;return[...St(St(Ut(0,F-2|0))(Q=>St(Ut(Q+1|0,F-1|0))(O=>[E(Q,O)])))(Q=>Q._1>=0&&Q._1<G.length?Q._2>=0&&Q._2<G.length?G[Q._1].splitPartner.tag!=="Nothing"&&G[Q._1].splitPartner.tag==="Just"&&G[Q._1].splitPartner._1===G[Q._2].id||G[Q._2].splitPartner.tag!=="Nothing"&&G[Q._2].splitPartner.tag==="Just"&&G[Q._2].splitPartner._1===G[Q._1].id?[]:i(f,G[Q._1],G[Q._2]):[]:[]),...St(G)(Q=>Q.splitBy.tag==="Just"&&Q.splitPartner.tag==="Just"&&(()=>{const O=Zt(Q.splitPartner._1)(q);if(O.tag==="Nothing")return!1;if(O.tag==="Just")return!0;c()})()&&(()=>{const O=Zt(Q.splitBy._1)(q);if(O.tag==="Nothing")return!1;if(O.tag==="Just")return!0;c()})()?[{src:Q.id,tgt:Q.splitBy._1,weight:1,kind:Ru},{src:Q.splitBy._1,tgt:Q.splitPartner._1,weight:1,kind:Ru}]:[])]})()}})(),m=h.segments,p=m.length,x=S=>{let v=S,D=!0,W;for(;D;){const M=v,q=te($=>{const G=Zt($)(M.inWeight);if(G.tag==="Nothing")return!0;if(G.tag==="Just")return G._1===0;c()})(M.remaining);if(q.tag==="Nothing"){D=!1,W=M;continue}if(q.tag==="Just"){const $=q._1;v={...M,inWeight:b(G=>F=>Ht(ut)(ve)(F.tgt)(-F.weight)(G))(M.inWeight)((()=>{const G=Zt($)(M.depsBySrc);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()),marks:it(ut)($)(M.nextSource)(M.marks),nextSource:M.nextSource+1|0,outWeight:b(G=>F=>Ht(ut)(ve)(F.src)(-F.weight)(G))(M.outWeight)((()=>{const G=Zt($)(M.depsByTgt);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()),remaining:_t(G=>G!==$,M.remaining)};continue}c()}return W},w=S=>{let v=S,D=!0,W;for(;D;){const M=v,q=te($=>{const G=Zt($)(M.outWeight);if(G.tag==="Nothing")return!0;if(G.tag==="Just")return G._1===0;c()})(M.remaining);if(q.tag==="Nothing"){D=!1,W=M;continue}if(q.tag==="Just"){const $=q._1;v={...M,inWeight:b(G=>F=>Ht(ut)(ve)(F.tgt)(-F.weight)(G))(M.inWeight)((()=>{const G=Zt($)(M.depsBySrc);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()),marks:it(ut)($)(M.nextSink)(M.marks),nextSink:M.nextSink-1|0,outWeight:b(G=>F=>Ht(ut)(ve)(F.src)(-F.weight)(G))(M.outWeight)((()=>{const G=Zt($)(M.depsByTgt);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()),remaining:_t(G=>G!==$,M.remaining)};continue}c()}return W},J=(S=>{let v=S,D=!0,W;for(;D;){const M=x(w(v));if(M.remaining.length===0){D=!1,W=Y(q=>{const $=Zt(q.id)(M.marks),G=(()=>{if($.tag==="Nothing")return q.id;if($.tag==="Just")return $._1;c()})();return{...q,mark:G<p?(G+p|0)+1|0:G}})(m);continue}v=(()=>{const q=G=>{const F=Zt(G)(M.outWeight),Q=Zt(G)(M.inWeight);return(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;c()})()-(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;c()})()|0},$=Rt(G=>F=>ut.compare(q(F))(q(G)))(M.remaining);if(0<$.length){const G=$[0];return{...M,inWeight:b(F=>Q=>Ht(ut)(ve)(Q.tgt)(-Q.weight)(F))(M.inWeight)((()=>{const F=Zt(G)(M.depsBySrc);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;c()})()),marks:it(ut)(G)(M.nextSource)(M.marks),nextSource:M.nextSource+1|0,outWeight:b(F=>Q=>Ht(ut)(ve)(Q.src)(-Q.weight)(F))(M.outWeight)((()=>{const F=Zt(G)(M.depsByTgt);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;c()})()),remaining:_t(F=>F!==G,M.remaining)}}return M})()}return W})({remaining:Y(S=>S.id)(m),marks:H,inWeight:b(S=>v=>Ht(ut)(ve)(v.tgt)(v.weight)(S))(H)(h.deps),outWeight:b(S=>v=>Ht(ut)(ve)(v.src)(v.weight)(S))(H)(h.deps),depsBySrc:b(S=>v=>Ht(ut)(we)(v.src)([v])(S))(H)(h.deps),depsByTgt:b(S=>v=>Ht(ut)(we)(v.tgt)([v])(S))(H)(h.deps),nextSink:p-1|0,nextSource:p+1|0}),N=(()=>{const S=(()=>{const W=aa(Y(M=>E(M.id,M.mark))(J));return{segments:J,deps:ht(M=>(()=>{if(M.kind==="Critical")return!0;if(M.kind==="Regular")return!1;c()})()?T("Just",M):(()=>{const q=Zt(M.src)(W),$=Zt(M.tgt)(W);return(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;c()})()>(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;c()})()})()?M.weight===0?y:T("Just",{src:M.tgt,tgt:M.src,weight:M.weight,kind:M.kind}):T("Just",M))(h.deps)}})(),v=b(W=>M=>Ht(ut)(ve)(M.tgt)(1)(W))(H)(S.deps),D=(W=>{let M=W,q=!0,$;for(;q;){const G=M,F=It(Q=>y,Q=>O=>T("Just",{head:Q,tail:O}),G.queue);if(F.tag==="Nothing"){q=!1,$=G;continue}if(F.tag==="Just"){M=b((()=>{const Q=Zt(F._1.head)(G.slots),O=(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;c()})();return z=>X=>{const V=Zt(X)(z.inDegree),K=(()=>{if(V.tag==="Nothing")return-1;if(V.tag==="Just")return V._1-1|0;c()})();return{...z,slots:it(ut)(X)(ih((()=>{const Z=Zt(X)(z.slots);if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;c()})())(O+1|0))(z.slots),inDegree:it(ut)(X)(K)(z.inDegree),queue:K===0?[...z.queue,X]:z.queue}}})())({...G,queue:F._1.tail})((()=>{const Q=Zt(F._1.head)(G.adj);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()})());continue}c()}return $})({slots:aa(Y(W=>E(W.id,0))(S.segments)),inDegree:v,adj:b(W=>M=>Ht(ut)(we)(M.src)([M.tgt])(W))(H)(S.deps),queue:Y(W=>W.id)(_t(W=>{const M=Zt(W.id)(v);if(M.tag==="Nothing")return!0;if(M.tag==="Just")return M._1===0;c()},S.segments))});return Rt(W=>M=>ut.compare(W.slot)(M.slot))(Y(W=>({...W,slot:(()=>{const M=Zt(W.id)(D.slots);if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;c()})()}))(S.segments))})(),k=1+b(S=>v=>ih(S)(v.slot))(0)(N)|0,C=St(N)(S=>S.members),R=_t(S=>yn(kr)(S.edge.id)(C),t),P=b(kt)(-1e18)(Y(S=>S.fromPos._2)(R)),I=b(Lt)(1e18)(Y(S=>S.toPos._2)(R));if(P>I){const S=aa(Y(v=>E(v.id,v))(N));return kn(Y(v=>Y(D=>E(D,{slot:v.slot,slotCount:k,gapTop:I,gapBottom:P,partner:(()=>{if(v.splitPartner.tag==="Just"){const W=Zt(v.splitPartner._1)(S);if(W.tag==="Just")return T("Just",{slot:W._1.slot,splitX:0<W._1.incoming.length?W._1.incoming[0]:0});if(W.tag==="Nothing")return y;c()}if(v.splitPartner.tag==="Nothing")return y;c()})()}))(v.members))(_t(v=>{if(v.splitPartner.tag==="Just"){const D=Zt(v.splitPartner._1)(S);return!(D.tag==="Just"&&(()=>{if(D._1.splitBy.tag==="Nothing")return!1;if(D._1.splitBy.tag==="Just")return!0;c()})())}if(v.splitPartner.tag==="Nothing")return!0;c()},N)))}const U=aa(Y(S=>E(S.id,S))(N));return kn(Y(S=>Y(v=>E(v,{slot:S.slot,slotCount:k,gapTop:P,gapBottom:I,partner:(()=>{if(S.splitPartner.tag==="Just"){const D=Zt(S.splitPartner._1)(U);if(D.tag==="Just")return T("Just",{slot:D._1.slot,splitX:0<D._1.incoming.length?D._1.incoming[0]:0});if(D.tag==="Nothing")return y;c()}if(S.splitPartner.tag==="Nothing")return y;c()})()}))(S.members))(_t(S=>{if(S.splitPartner.tag==="Just"){const v=Zt(S.splitPartner._1)(U);return!(v.tag==="Just"&&(()=>{if(v._1.splitBy.tag==="Nothing")return!1;if(v._1.splitBy.tag==="Just")return!0;c()})())}if(S.splitPartner.tag==="Nothing")return!0;c()},N)))})()))(H)(xv(b(a=>s=>{const u=sa(s.edge.from.node)(n);if(u.tag==="Just"){const g=sa(s.edge.to.node)(n);return g.tag==="Just"&&u._1.layer!==g._1.layer?Ht(ut)(we)(ua(u._1.layer)(g._1.layer))([s])(a):a}return a})(H)((()=>{const a=s=>E((()=>{const u=sa(s.edge.from.node)(n);return u.tag==="Just"?u._1.layer:1e6})(),(()=>{const u=sa(s.edge.from.node)(n);return u.tag==="Just"?u._1.order:1e6})());return Rt(s=>u=>yv(a(s))(a(u)))(t)})())))},Tv=t=>e=>{const n=sh(t)(e),r=b(o=>i=>it(B)(i.node)(i)(o))(H)(e);return b(o=>i=>{const a=sa(i.edge.from.node)(r);if(a.tag==="Just"){const s=sa(i.edge.to.node)(r);if(s.tag==="Just"&&a._1.layer!==s._1.layer){const u=Jv(i.edge.id)(n);if(u.tag==="Just")return it(ut)(ua(a._1.layer)(s._1.layer))(u._1.slotCount)(o)}return o}return o})(H)(t)},J_=fe(B)(Qt),ro=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},T_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Nv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t._1)(i._3._1);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(t._2==="North"){if(i._3._2==="North"){r=!1,o=T("Just",i._4);continue}n=i._5;continue}if(i._3._2==="North"){n=i._6;continue}if(t._2==="South"){if(i._3._2==="South"){r=!1,o=T("Just",i._4);continue}n=i._5;continue}if(i._3._2==="South"){n=i._6;continue}if(t._2==="East"){if(i._3._2==="East"){r=!1,o=T("Just",i._4);continue}n=i._5;continue}if(i._3._2==="East"){n=i._6;continue}if(t._2==="West"&&i._3._2==="West"){r=!1,o=T("Just",i._4);continue}}c()}return o},uh=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 E(o,i*2);if(t==="North")return E(o,e.position._2*2);if(t==="East")return E(n*2,r);if(t==="West")return E(e.position._1*2,r);c()},N_=t=>e=>{const n=ot(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};c()},gh=t=>e=>b(n=>r=>Ht(t)(we)(e(r))([r])(n))(H),ch=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;c()})()&&(()=>{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;c()})(),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;c()})()&&(()=>{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;c()})();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},_h=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,o=e.length;return o===0?H:J_(o===1?Y(i=>E(i,r))(e):Dt(i=>a=>E(a,t.lo+ot(i+1|0)*n/ot(o+1|0)))(e))},fh=t=>e=>n=>r=>o=>{const i=gh(B)(d=>d.to.node)(t),a=gh(B)(d=>d.from.node)(t),s=b(d=>h=>it(B)(h.node)(h)(d))(H)(e),u=(d,h,m)=>{const p=ro(d)(s);if(p.tag==="Nothing")return E(0,0);if(p.tag==="Just"){const x=ro(d)(n);if(x.tag==="Nothing"){const w=ot(4);if(m==="South")return E(p._1.position._1*w+p._1.size._1*w/2,(p._1.position._2+p._1.size._2)*w);if(m==="North")return E(p._1.position._1*w+p._1.size._1*w/2,p._1.position._2*w);if(m==="East")return E((p._1.position._1+p._1.size._1)*w,p._1.position._2*w+p._1.size._2*w/2);if(m==="West")return E(p._1.position._1*w,p._1.position._2*w+p._1.size._2*w/2);c()}if(x.tag==="Just"){const w=te(J=>J.id===h)(x._1);if(w.tag==="Nothing"){const J=ot(4);if(m==="South")return E(p._1.position._1*J+p._1.size._1*J/2,(p._1.position._2+p._1.size._2)*J);if(m==="North")return E(p._1.position._1*J+p._1.size._1*J/2,p._1.position._2*J);if(m==="East")return E((p._1.position._1+p._1.size._1)*J,p._1.position._2*J+p._1.size._2*J/2);if(m==="West")return E(p._1.position._1*J,p._1.position._2*J+p._1.size._2*J/2);c()}if(w.tag==="Just"){const J=ot(4);if(w._1.side==="North")return E(p._1.position._1*J+ot(w._1.offset)*J,p._1.position._2*J);if(w._1.side==="South")return E(p._1.position._1*J+ot(w._1.offset)*J,(p._1.position._2+p._1.size._2)*J);if(w._1.side==="East")return E((p._1.position._1+p._1.size._1)*J,p._1.position._2*J+ot(w._1.offset)*J);if(w._1.side==="West")return E(p._1.position._1*J,p._1.position._2*J+ot(w._1.offset)*J)}}}c()},g=J_(St(r)(d=>{if(d.nodes.length<=2)return[];const h=ot(4);if(1<d.nodes.length){const m=ro(d.nodes[1])(s);if(m.tag==="Nothing")return[];if(m.tag==="Just"){const p=m._1.position._1*h+m._1.size._1*h/2;return Y(x=>E(x,p))(He(x=>w=>d.edgeId+":"+x+"->"+w,d.nodes,Bt(1,d.nodes.length,d.nodes)))}c()}return[]})),_=d=>{const h=ro(d.from.node)(s),m=ro(d.to.node)(s);if(h.tag==="Just"&&m.tag==="Just"){const p=h._1,x=m._1,w=Rt(J=>N=>ut.compare(J.score)(N.score))(Y(J=>{const N=J._1,k=J._2;return{from:N,to:k,score:(()=>{const C=(U,S,v,D,W)=>{const M=N_(U)(S),q=N_(U)(v);return M.lo<q.hi&&q.lo<M.hi&&(N==="South"?k==="North"&&W._2>D._2:N==="North"?k==="South"&&W._2<D._2:N==="East"?k==="West"&&W._1>D._1:N==="West"&&k==="East"&&W._1<D._1)?0:ch(N)(k)(D)(W)},R=uh(N)(p),P=uh(k)(x),I=ch(N)(k)(R)(P);return(()=>{if(I>0){if(N==="South")return k==="North"?C(ze,p,x,R,P)*10|0:I*10|0;if(N==="North")return k==="South"?C(Ie,p,x,R,P)*10|0:I*10|0;if(N==="East")return k==="West"?C(Kr,p,x,R,P)*10|0:I*10|0;if(N==="West"&&k==="East")return C(Yr,p,x,R,P)*10|0}return I*10|0})()+(N==="South"?k==="North"?x.layer>=p.layer?0:20:15:N==="North"?k==="South"?x.layer<=p.layer?0:20:15:N==="East"?k==="West"?5:15:N==="West"&&k==="East"?5:15)|0})()}})([E(ze,Ie),E(Kr,Ie),E(Yr,Ie),E(ze,Kr),E(ze,Yr),E(Ie,ze),E(Ie,Kr),E(Ie,Yr),E(Kr,ze),E(Yr,ze),E(Kr,Yr),E(Yr,Kr)]));if(0<w.length)return{from:w[0].from,to:w[0].to}}return{from:ze,to:Ie}},f=J_(Y(d=>E(d.id,_(d)))(t)),l=(d,h,m,p,x,w)=>{const J=ot(4),N=ro(h)(s);if(N.tag==="Nothing")return E(0,0);if(N.tag==="Just"){const k=Nv(E(m,d))(o);if(k.tag==="Just"){const C=N._1.position._1*J+k._1,R=ot(4);if(d==="South")return E(C,(N._1.position._2+N._1.size._2)*R);if(d==="North")return E(C,N._1.position._2*R);if(d==="East")return E((N._1.position._1+N._1.size._1)*R,C);if(d==="West")return E(N._1.position._1*R,C);c()}if(k.tag==="Nothing"){const C=N_(d)(N._1),R=(C.lo+C.hi)/2,P=T_(m)(_h(C)(Y(S=>S.id)(Rt(S=>v=>at.compare(x(d)(S))(x(d)(v)))(_t(S=>{const v=T_(S.id)(f);if(v.tag==="Just"){const D=w(v._1);return D==="North"?d==="North":D==="South"?d==="South":D==="East"?d==="East":D==="West"&&d==="West"}if(v.tag==="Nothing")return!0;c()},(()=>{const S=ro(h)(p);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;c()})()))))),I=(()=>{if(P.tag==="Nothing")return R;if(P.tag==="Just")return P._1;c()})(),U=ot(4);if(d==="South")return E(I,(N._1.position._2+N._1.size._2)*U);if(d==="North")return E(I,N._1.position._2*U);if(d==="East")return E((N._1.position._1+N._1.size._1)*U,I);if(d==="West")return E(N._1.position._1*U,I)}}c()};return Y(d=>{const h=T_(d.edge.id)(g);if(h.tag==="Nothing")return d;if(h.tag==="Just")return{...d,fromPos:Ve(3)(d.edge.from.node)==="$d:"?E(h._1,d.fromPos._2):d.fromPos,toPos:Ve(3)(d.edge.to.node)==="$d:"?E(h._1,d.toPos._2):d.toPos};c()})(Y(d=>{if(d.from.port.tag==="Just"&&d.to.port.tag==="Just")return{edge:d,fromPos:u(d.from.node,d.from.port._1,ze),toPos:u(d.to.node,d.to.port._1,Ie),fromSide:ze,toSide:Ie};const h=_(d);return{edge:d,fromPos:l(h.from,d.from.node,d.id,a,m=>p=>{const x=ro(p.to.node)(s);if(x.tag==="Nothing")return 0;if(x.tag==="Just"){const w=ot(4);if(m==="South"||m==="North")return x._1.position._1*w+x._1.size._1*w/2;if(m==="East"||m==="West")return x._1.position._2*w+x._1.size._2*w/2}c()},m=>m.from),toPos:l(h.to,d.to.node,d.id,i,m=>p=>{const x=ro(p.from.node)(s);if(x.tag==="Nothing")return 0;if(x.tag==="Just"){const w=ot(4);if(m==="South"||m==="North")return x._1.position._1*w+x._1.size._1*w/2;if(m==="East"||m==="West")return x._1.position._2*w+x._1.size._2*w/2}c()},m=>m.to),fromSide:h.from,toSide:h.to}})(t))},Pu=(()=>{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=B.compare(e._1)(n._1);if(r==="LT")return Me;if(r==="GT")return Qe;if(e._2==="North")return n._2==="North"?sn:Me;if(n._2==="North")return Qe;if(e._2==="South")return n._2==="South"?sn:Me;if(n._2==="South")return Qe;if(e._2==="East")return n._2==="East"?sn:Me;if(n._2==="East")return Qe;if(e._2==="West"&&n._2==="West")return sn;c()},Eq0:()=>t}})(),bv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=Pu.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},vv=fe(B)(Qt),b_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Cv=fe(Pu)(Qt),lh=(()=>{const t=un.unfoldr(Yn);return e=>t(gn("IterNode",e,Un))})(),ga=t=>e=>n=>r=>{const o=bv(E(e,n))(t);if(o.tag==="Nothing")return r;if(o.tag==="Just")return o._1;c()},dh=t=>e=>n=>{const r=vv(kn(Y(a=>Dt(s=>u=>E(u,s))(a))(t))),o=(a,s)=>{if(a==="South"){const u=b_(s.to.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;c()}if(a==="North"){const u=b_(s.from.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;c()}return 0},i=a=>b(s=>u=>en(Pu.compare,je,Cv(Y(g=>E(E(g._1,a),g._2))(lh(_h({lo:0,hi:(()=>{const g=b_(u._1)(n);if(g.tag==="Just")return g._1._1;if(g.tag==="Nothing")return Ve(3)(u._1)==="$d:"?0:1;c()})()})(Y(g=>g.id)(Rt(g=>_=>ut.compare(o(a,g))(o(a,_)))(u._2)))))),s))(H)(lh(b(s=>u=>u.from.node===u.to.node?s:a==="South"?Ht(B)(we)(u.from.node)([u])(s):a==="North"?Ht(B)(we)(u.to.node)([u])(s):s)(H)(e)));return en(Pu.compare,je,i(Ie),i(ze))},hh=t=>t,ph=t=>t,mh=t=>t,Lv=b(t=>e=>it(B)(e)()(t))(H),kv=(()=>{const t=un.unfoldr(e=>{if(e.tag==="Nil")return y;if(e.tag==="Cons")return T("Just",E(e._1,e._2));c()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,wt("Cons",r._3,n(r._6,o)));c()};return n(e,A)})())})(),dt=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},er=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Fr=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Dr=fe(B)(Qt),v_=sf(B),C_=(()=>{const t=un.unfoldr(Yn);return e=>t(gn("IterNode",e,Un))})(),Sv=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ev=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},yh=mh("VDown"),xh=mh("VUp"),Rv=ph("ForwardPhase"),Pv=ph("StackPhase"),wh=hh("HRight"),Jh=hh("HLeft"),Th=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=B.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}}c()}return o},Gv=t=>e=>n=>{const r=b(a=>s=>Ht(B)(ve)(s.tgt)(1)(a))(H)(t),o=kv(Lv([...Y(a=>a.src)(t),...Y(a=>a.tgt)(t),...(()=>{const a=(s,u)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return a(s._5,wt("Cons",s._4,a(s._6,u)));c()};return Mt(ce.foldr,a(e,A))})()])),i=b(a=>s=>Ht(B)(we)(s.src)([{target:s.tgt,sep:s.sep}])(a))(H)(t);return(a=>s=>u=>{let g=a,_=s,f=u,l=!0,d;for(;l;){const h=g,m=_,p=f,x=It(w=>y,w=>J=>T("Just",{head:w,tail:J}),h);if(x.tag==="Nothing"){l=!1,d=p;continue}if(x.tag==="Just"){const w=dt(x._1.head)(p),J=(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})(),N=b(k=>C=>{const R=dt(C.target)(k.result),P=J+C.sep,I=dt(C.target)(k.indeg),U=(()=>{if(I.tag==="Nothing")return-1;if(I.tag==="Just")return I._1-1|0;c()})();return{newQueue:U===0?[...k.newQueue,C.target]:k.newQueue,result:it(B)(C.target)((()=>{if(R.tag==="Nothing")return P;if(R.tag==="Just"){if(n==="VDown")return er(R._1)(P);if(n==="VUp")return Fr(R._1)(P)}c()})())(k.result),indeg:it(B)(C.target)(U)(k.indeg)}})({newQueue:[],result:p,indeg:m})((()=>{const k=dt(x._1.head)(i);if(k.tag==="Nothing")return[];if(k.tag==="Just")return k._1;c()})());g=[...x._1.tail,...N.newQueue],_=N.indeg,f=N.result;continue}c()}return d})(_t(a=>{const s=dt(a)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;c()},o))(r)(b(a=>s=>it(B)(s)(0)(a))(H)(o))},Bv=t=>{const e=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return e(i._5,wt("Cons",i._4,e(i._6,a)));c()},n=Mt(ce.foldr,e(t,A)),r=b(er)(999999)(n);if(r===0||n.length===0)return t;const o=i=>{if(i.tag==="Leaf")return H;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,i._4-r,o(i._5),o(i._6));c()};return o(t)},Nh=t=>{const e=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return e(i._5,wt("Cons",i._4,e(i._6,a)));c()},n=e(t,A),r=i=>a=>{let s=i,u=a,g=!0,_;for(;g;){const f=s,l=u;if(l.tag==="Nil"){g=!1,_=f;continue}if(l.tag==="Cons"){s=Fr(f)(l._1),u=l._2;continue}c()}return _},o=i=>a=>{let s=i,u=a,g=!0,_;for(;g;){const f=s,l=u;if(l.tag==="Nil"){g=!1,_=f;continue}if(l.tag==="Cons"){s=er(f)(l._1),u=l._2;continue}c()}return _};return r(-999999)(n)-o(999999)(n)},$a=t=>e=>(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,g=i;if(u===e){a=!1,s=g;continue}o=(()=>{const _=dt(u)(t.align);if(_.tag==="Nothing")return e;if(_.tag==="Just")return _._1;c()})(),i=[...g,u]}return s})((()=>{const n=dt(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;c()})())([e]),Av=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>_=>{const f=(G,F,Q)=>{const O=G.from.node===F?G.from.port:G.to.node===F?G.to.port:y;if(O.tag==="Just"){const z=dt(F)(o);if(z.tag==="Just"){const X=te(V=>V.id===O._1)(z._1);if(X.tag==="Just"){const V=ot(X._1.offset)*ot(4);return Q==="North"||Q==="South"?V:0}if(X.tag==="Nothing"){const V=dt(F)(r),K=ga(a)(G.id)(Q)((()=>{if(V.tag==="Nothing")return .5;if(V.tag==="Just")return V._1._1/2;c()})());return Q==="North"||Q==="South"?K:0}c()}if(z.tag==="Nothing"){const X=dt(F)(r),V=ga(a)(G.id)(Q)((()=>{if(X.tag==="Nothing")return .5;if(X.tag==="Just")return X._1._1/2;c()})());return Q==="North"||Q==="South"?V:0}c()}if(O.tag==="Nothing"){const z=dt(F)(r),X=ga(a)(G.id)(Q)((()=>{if(z.tag==="Nothing")return .5;if(z.tag==="Just")return z._1._1/2;c()})());return Q==="North"||Q==="South"?X:0}c()},l=(G,F)=>{if(G.from.node===F){if(_==="HRight")return ze;if(_==="HLeft")return Ie;c()}if(_==="HRight")return Ie;if(_==="HLeft")return ze;c()},d=(G,F,Q)=>b(O=>z=>it(B)(z)((()=>{const X=dt(z)(O);if(X.tag==="Nothing")return 0+F;if(X.tag==="Just")return X._1+F;c()})())(O))(Q)($a(u)(G)),h=(()=>{if(_==="HRight")return n;if(_==="HLeft")return re(n);c()})(),m=G=>{const F=dt(G)(r);if(F.tag==="Nothing")return 1;if(F.tag==="Just")return F._1._1;c()},p=Dr(kn(Dt(G=>F=>Y(Q=>E(Q,G))(F))(n))),x=(G,F)=>Ve(3)(G)==="$d:"&&Ve(3)(F)==="$d:"||Ve(3)(G)==="$d:"||Ve(3)(F)==="$d:"?10:ot(t.nodeGap),w=b(G=>F=>v_(Q=>T("Just",[...(()=>{if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()})(),F]))(F.to.node)(G))(H)(i),J=b(G=>F=>v_(Q=>T("Just",[...(()=>{if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()})(),F]))(F.from.node)(G))(H)(i),N=kn(n),k=b(G=>F=>{const Q=dt(F)(u.root),O=(()=>{if(Q.tag==="Nothing")return F;if(Q.tag==="Just")return Q._1;c()})();return F===O?G:v_(z=>T("Just",(()=>{if(z.tag==="Nothing")return!0;if(z.tag==="Just")return z._1;c()})()&&Ve(3)(F)==="$d:"))(O)(G)})(Dr(Y(G=>E(G,!0))(Ur(B.compare)((()=>{const G=(F,Q)=>{if(F.tag==="Leaf")return Q;if(F.tag==="Node")return G(F._5,wt("Cons",F._4,G(F._6,Q)));c()};return Mt(ce.foldr,G(u.root,A))})()))))(N),C=(G,F)=>{const Q=G.free,O=dt(Q)(u.root),z=(()=>{if(O.tag==="Nothing")return Q;if(O.tag==="Just")return O._1;c()})(),X=dt(z)(k),V=(()=>{if(X.tag==="Nothing")return!0;if(X.tag==="Just")return X._1;c()})();return b(K=>Z=>{if(K.edge.tag==="Just")return K;if(K.edge.tag==="Nothing"){if((()=>{const lt=dt(z)(F.su);return!V&&(()=>{const mt=dt(Z.from.node)(p);return Z.from.node!==Z.to.node&&(()=>{const vt=dt(Z.to.node)(p);return(()=>{if(mt.tag==="Nothing")return-1;if(mt.tag==="Just")return mt._1;c()})()===(()=>{if(vt.tag==="Nothing")return-1;if(vt.tag==="Just")return vt._1;c()})()})()})()||(()=>{if(lt.tag==="Nothing")return!1;if(lt.tag==="Just")return lt._1;c()})()})())return K;const nt=Z.from.node===Q?Z.to.node:Z.from.node,rt=dt(nt)(u.root),ft=(()=>{if(rt.tag==="Nothing")return nt;if(rt.tag==="Just")return rt._1;c()})(),Nt=ft!==z;return Nt&&(()=>{const lt=dt(ft)(F.blockFinished);if(lt.tag==="Nothing")return!1;if(lt.tag==="Just")return lt._1;c()})()?{...K,edge:T("Just",Z),hasEdges:!0}:{...K,hasEdges:K.hasEdges||Nt}}c()})({edge:y,hasEdges:!1})((()=>{if(G.isRoot){if(_==="HRight"){const K=dt(Q)(w);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;c()}if(_==="HLeft"){const K=dt(Q)(J);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1}c()}if(_==="HRight"){const K=dt(Q)(J);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;c()}if(_==="HLeft"){const K=dt(Q)(w);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1}c()})())},R=(G,F,Q,O)=>{const z=(()=>{if(g==="VDown")return-1e18;if(g==="VUp")return 1e18;c()})(),X={free:F,isRoot:Q},V=C(X,O);if(V.edge.tag==="Nothing")return V.hasEdges?{thresh:z,state:{...O,queue:[...O.queue,X]}}:{thresh:z,state:O};if(V.edge.tag==="Just"){const K=V.edge._1.from.node===F?V.edge._1.to.node:V.edge._1.from.node;return{thresh:(()=>{const Z=dt((()=>{const Nt=dt(K)(u.root);if(Nt.tag==="Nothing")return K;if(Nt.tag==="Just")return Nt._1;c()})())(O.x),nt=dt(K)(s),rt=dt(F)(s),ft=(()=>{if(Z.tag==="Just")return Z._1;if(Z.tag==="Nothing")return y;c()})();return(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;c()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+f(V.edge._1,K,(()=>{if(Q){if(_==="HRight")return ze;if(_==="HLeft")return Ie;c()}if(_==="HRight")return Ie;if(_==="HLeft")return ze;c()})())-(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()-f(V.edge._1,F,(()=>{if(Q){if(_==="HRight")return Ie;if(_==="HLeft")return ze;c()}if(_==="HRight")return ze;if(_==="HLeft")return Ie;c()})())})(),state:{...O,su:it(B)((()=>{const Z=dt(V.edge._1.from.node)(u.root);if(Z.tag==="Nothing")return V.edge._1.from.node;if(Z.tag==="Just")return Z._1;c()})())(!0)(it(B)((()=>{const Z=dt(V.edge._1.to.node)(u.root);if(Z.tag==="Nothing")return V.edge._1.to.node;if(Z.tag==="Just")return Z._1;c()})())(!0)(O.su))}}}c()},P=(G,F,Q,O)=>{const z=F===G,X=dt(F)(u.align),V=(()=>{if(X.tag==="Nothing")return F===G;if(X.tag==="Just")return X._1===G;c()})();if(!(z||V))return{thresh:Q,state:O};const K=(()=>{if(g==="VDown")return z&&Q<=-1e18;if(g==="VUp")return z&&Q>=1e18;c()})()?R(G,F,!0,O):{thresh:Q,state:O};return(()=>{if(g==="VDown")return K.thresh<=-1e18&&V;if(g==="VUp")return K.thresh>=1e18&&V;c()})()?R(G,F,!1,K.state):K},I=G=>F=>Q=>{const O=dt(Q)(e.nodeIndex),z=(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;c()})(),X=te(rt=>yn(kr)(Q)(rt))(h),V=(()=>{if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;c()})(),K=V.length;if((()=>{if(g==="VDown")return z<=0;if(g==="VUp")return z>=(K-1|0);c()})()){const rt=P(G,Q,F.thresh,F.st);return{...F,st:rt.state,thresh:rt.thresh}}const Z=(()=>{if(g==="VDown")return z-1|0;if(g==="VUp")return z+1|0;c()})(),nt=Z>=0&&Z<V.length?T("Just",V[Z]):y;if(nt.tag==="Nothing")return F;if(nt.tag==="Just"){const rt=dt(nt._1)(u.root),ft=(()=>{if(rt.tag==="Nothing")return nt._1;if(rt.tag==="Just")return rt._1;c()})(),Nt=P(G,Q,F.thresh,U(ft)(F.st)),lt=(()=>{const Ft=dt(G)(Nt.state.sink);if(Ft.tag==="Nothing")return G===G;if(Ft.tag==="Just")return Ft._1===G;c()})()?{...Nt.state,sink:it(B)(G)((()=>{const Ft=dt(ft)(Nt.state.sink);if(Ft.tag==="Nothing")return ft;if(Ft.tag==="Just")return Ft._1;c()})())(Nt.state.sink)}:Nt.state,mt=dt(ft)(lt.sink),vt=(()=>{if(mt.tag==="Nothing")return ft;if(mt.tag==="Just")return mt._1;c()})(),Wt=dt(G)(lt.sink),Tt=(()=>{if(Wt.tag==="Nothing")return G;if(Wt.tag==="Just")return Wt._1;c()})();if(Tt===vt){const Ft=dt(ft)(lt.x),se=(()=>{if(Ft.tag==="Just")return Ft._1;if(Ft.tag==="Nothing")return y;c()})(),_e=(()=>{if(se.tag==="Nothing")return 0;if(se.tag==="Just")return se._1;c()})(),pn=dt(G)(lt.x),qt=(()=>{if(pn.tag==="Just")return pn._1;if(pn.tag==="Nothing")return y;c()})(),jt=(()=>{if(qt.tag==="Nothing")return 0;if(qt.tag==="Just")return qt._1;c()})(),an=x(Q,nt._1),$e=dt(nt._1)(s),Wn=dt(Q)(s),$n=(()=>{if($e.tag==="Nothing")return 0;if($e.tag==="Just")return $e._1;c()})()-(()=>{if(Wn.tag==="Nothing")return 0;if(Wn.tag==="Just")return Wn._1;c()})();if(g==="VDown"){const Ze=Fr(_e+$n+m(nt._1)+an)(Nt.thresh);return{st:{...lt,x:it(B)(G)(T("Just",F.initial?Ze:Fr(jt)(Ze)))(lt.x)},initial:!1,thresh:Nt.thresh}}if(g==="VUp"){const Ze=er(_e+$n-an-m(Q))(Nt.thresh);return{st:{...lt,x:it(B)(G)(T("Just",F.initial?Ze:er(jt)(Ze)))(lt.x)},initial:!1,thresh:Nt.thresh}}c()}const Vt=dt(ft)(lt.x),Gt=(()=>{if(Vt.tag==="Just")return Vt._1;if(Vt.tag==="Nothing")return y;c()})(),bt=(()=>{if(Gt.tag==="Nothing")return 0;if(Gt.tag==="Just")return Gt._1;c()})(),pt=dt(G)(lt.x),ct=(()=>{if(pt.tag==="Just")return pt._1;if(pt.tag==="Nothing")return y;c()})(),Jt=(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;c()})(),At=ot(t.nodeGap),yt=dt(Q)(s),Ct=dt(nt._1)(s),Ot=(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()-(()=>{if(Ct.tag==="Nothing")return 0;if(Ct.tag==="Just")return Ct._1;c()})();return{st:{...lt,classEdges:[...lt.classEdges,{src:Tt,tgt:vt,sep:(()=>{if(g==="VDown")return Jt+Ot-bt-m(nt._1)-At;if(g==="VUp")return Jt+Ot+m(Q)+At-bt;c()})()}]},initial:F.initial,thresh:Nt.thresh}}c()},U=G=>F=>{const Q=dt(G)(F.x),O=(()=>{if(Q.tag==="Just")return Q._1;if(Q.tag==="Nothing")return y;c()})();if(O.tag==="Just")return F;if(O.tag==="Nothing"){const z=b(I(G))({st:{...F,x:it(B)(G)(T("Just",0))(F.x)},initial:!0,thresh:(()=>{if(g==="VDown")return-1e18;if(g==="VUp")return 1e18;c()})()})($a(u)(G));return{...z.st,blockFinished:it(B)(G)(!0)(z.st.blockFinished)}}c()},S=b(G=>F=>b(Q=>O=>{const z=dt(O)(u.root),X=(()=>{if(z.tag==="Nothing")return O;if(z.tag==="Just")return z._1;c()})();return X===O?U(X)(Q):Q})(G)((()=>{if(g==="VDown")return F;if(g==="VUp")return re(F);c()})()))({x:Dr(Y(G=>E(G,y))(N)),sink:Dr(Y(G=>E(G,G))(N)),classEdges:[],su:H,blockFinished:H,queue:[]})(h),v=Gv(S.classEdges)(S.sink)(g),D=(G,F,Q,O)=>{const z=dt(F)(O),X=dt(F)(s);return(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;c()})()+(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;c()})()+f(G,F,Q)},W=Dr(Y(G=>E(G,!0))(Ur(B.compare)((()=>{const G=(F,Q)=>{if(F.tag==="Leaf")return Q;if(F.tag==="Node")return G(F._5,wt("Cons",F._4,G(F._6,Q)));c()};return Mt(ce.foldr,G(u.root,A))})()))),M=G=>F=>Q=>{const O=C(Q,{su:F.su,blockFinished:W}),z={phase:G,ppFree:Q.free,ppIsRoot:Q.isRoot,edgeId:y,delta:0,avail:0,shift:0,freeSu:(()=>{const X=dt((()=>{const V=dt(Q.free)(u.root);if(V.tag==="Nothing")return Q.free;if(V.tag==="Just")return V._1;c()})())(F.su);if(X.tag==="Nothing")return!1;if(X.tag==="Just")return X._1;c()})(),hasEdges:O.hasEdges,candCount:(()=>{if(Q.isRoot){if(_==="HRight"){const X=dt(Q.free)(w);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length;c()}if(_==="HLeft"){const X=dt(Q.free)(J);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length}c()}if(_==="HRight"){const X=dt(Q.free)(J);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length;c()}if(_==="HLeft"){const X=dt(Q.free)(w);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length}c()})()};if(O.edge.tag==="Nothing")return{...F,stack:[...F.stack,Q],trace:[...F.trace,z],x:F.x};if(O.edge.tag==="Just"){const X=O.edge._1.from.node===Q.free?E(O.edge._1.from.node,O.edge._1.to.node):E(O.edge._1.to.node,O.edge._1.from.node),V=D(O.edge._1,X._1,l(O.edge._1,X._1),F.x)-D(O.edge._1,X._2,l(O.edge._1,X._2),F.x),K=dt(X._1)(u.root),Z=(()=>{if(K.tag==="Nothing")return X._1;if(K.tag==="Just")return K._1;c()})(),nt={...z,edgeId:T("Just",O.edge._1.id),delta:V};if(V>0&&V<1e300){const rt=b(lt=>mt=>{const vt=dt(mt)(p),Wt=(()=>{if(vt.tag==="Nothing")return-1;if(vt.tag==="Just")return vt._1;c()})();if(Wt>=0&&Wt<n.length){const Gt=n[Wt],bt=dt(mt)(e.nodeIndex),pt=(()=>{if(bt.tag==="Nothing")return-2;if(bt.tag==="Just")return bt._1-1|0;c()})();return pt>=0&&pt<Gt.length?er(lt)((()=>{const ct=dt(mt)(F.x),Jt=dt(mt)(s),At=dt(Gt[pt])(F.x),yt=dt(Gt[pt])(s);return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;c()})()+(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;c()})()-((()=>{if(At.tag==="Nothing")return 0;if(At.tag==="Just")return At._1;c()})()+(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+m(Gt[pt])+x(mt,Gt[pt]))})()):lt}const Tt=dt(mt)(e.nodeIndex),Vt=(()=>{if(Tt.tag==="Nothing")return-2;if(Tt.tag==="Just")return Tt._1-1|0;c()})();return Vt>=0&&Vt<0?er(lt)((()=>{const Gt=dt(mt)(F.x),bt=dt(mt)(s),pt=dt([][Vt])(F.x),ct=dt([][Vt])(s);return(()=>{if(Gt.tag==="Nothing")return 0;if(Gt.tag==="Just")return Gt._1;c()})()+(()=>{if(bt.tag==="Nothing")return 0;if(bt.tag==="Just")return bt._1;c()})()-((()=>{if(pt.tag==="Nothing")return 0;if(pt.tag==="Just")return pt._1;c()})()+(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;c()})()+m([][Vt])+x(mt,[][Vt]))})()):lt})(V)($a(u)(Z)),ft=rt>0?-rt:0,Nt={...F,x:rt>0?d(Z,ft,F.x):F.x,trace:[...F.trace,{...nt,avail:rt,shift:ft}]};return rt>0?Nt:{...Nt,stack:[...Nt.stack,Q]}}if(V<0&&-V<1e300){const rt=b(lt=>mt=>{const vt=dt(mt)(p),Wt=(()=>{if(vt.tag==="Nothing")return-1;if(vt.tag==="Just")return vt._1;c()})();if(Wt>=0&&Wt<n.length){const Gt=n[Wt],bt=dt(mt)(e.nodeIndex),pt=(()=>{if(bt.tag==="Nothing")return 0;if(bt.tag==="Just")return bt._1+1|0;c()})();return pt>=0&&pt<Gt.length?er(lt)((()=>{const ct=dt(Gt[pt])(F.x),Jt=dt(Gt[pt])(s),At=dt(mt)(F.x),yt=dt(mt)(s);return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;c()})()+(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;c()})()-((()=>{if(At.tag==="Nothing")return 0;if(At.tag==="Just")return At._1;c()})()+(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+m(mt)+x(mt,Gt[pt]))})()):lt}const Tt=dt(mt)(e.nodeIndex),Vt=(()=>{if(Tt.tag==="Nothing")return 0;if(Tt.tag==="Just")return Tt._1+1|0;c()})();return Vt>=0&&Vt<0?er(lt)((()=>{const Gt=dt([][Vt])(F.x),bt=dt([][Vt])(s),pt=dt(mt)(F.x),ct=dt(mt)(s);return(()=>{if(Gt.tag==="Nothing")return 0;if(Gt.tag==="Just")return Gt._1;c()})()+(()=>{if(bt.tag==="Nothing")return 0;if(bt.tag==="Just")return bt._1;c()})()-((()=>{if(pt.tag==="Nothing")return 0;if(pt.tag==="Just")return pt._1;c()})()+(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;c()})()+m(mt)+x(mt,[][Vt]))})()):lt})(-V)($a(u)(Z)),ft=rt>0?rt:0,Nt={...F,x:rt>0?d(Z,ft,F.x):F.x,trace:[...F.trace,{...nt,avail:rt,shift:ft}]};return rt>0?Nt:{...Nt,stack:[...Nt.stack,Q]}}return{...F,stack:[...F.stack,Q],trace:[...F.trace,nt],x:F.x}}c()},q=b(M(Rv))({x:Dr(Y(G=>E(G,(()=>{const F=dt(G)(u.root),Q=(()=>{if(F.tag==="Nothing")return G;if(F.tag==="Just")return F._1;c()})(),O=dt(Q)(S.x),z=dt((()=>{const V=dt(Q)(S.sink);if(V.tag==="Nothing")return Q;if(V.tag==="Just")return V._1;c()})())(v),X=(()=>{if(O.tag==="Just")return O._1;if(O.tag==="Nothing")return y;c()})();return(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;c()})()+(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;c()})()})()))(N)),su:S.su,stack:[],trace:[]})(S.queue),$=b(M(Pv))({...q,stack:[]})(re(q.stack));return{x:$.x,queue:S.queue,trace:$.trace}},Iv=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>_=>Av(t)(e)(n)(r)(o)(i)(a)(s)(u)(g)(_).x,zv=t=>e=>n=>r=>o=>i=>{const a=(u,g,_)=>{const f=dt(g)(n),l=(()=>{if(f.tag==="Nothing")return .5;if(f.tag==="Just")return f._1._1/2;c()})(),d=u.from.node===g?u.from.port:u.to.node===g?u.to.port:y;if(d.tag==="Just"){const h=dt(g)(e);if(h.tag==="Just"){const m=te(p=>p.id===d._1)(h._1);if(m.tag==="Just"){const p=ot(m._1.offset)*ot(4);return _==="North"||_==="South"?p:0}if(m.tag==="Nothing"){const p=ga(o)(u.id)(_)(l);return _==="North"||_==="South"?p:0}c()}if(h.tag==="Nothing"){const m=ga(o)(u.id)(_)(l);return _==="North"||_==="South"?m:0}c()}if(d.tag==="Nothing"){const h=ga(o)(u.id)(_)(l);return _==="North"||_==="South"?h:0}c()},s=u=>g=>_=>f=>{let l=u,d=g,h=_,m=f,p=!0,x;for(;p;){const w=l,J=d,N=h,k=It(C=>y,C=>R=>T("Just",{head:C,tail:R}),m);if(k.tag==="Nothing"){p=!1,x=w;continue}if(k.tag==="Just"){const C=k._1.head,R=te(I=>I.from.node===N&&I.to.node===C||I.from.node===C&&I.to.node===N)(r),P=(()=>{if(R.tag==="Nothing")return J+0;if(R.tag==="Just")return J+(a(R._1,N,R._1.from.node===N?ze:Ie)-a(R._1,C,R._1.from.node===C?ze:Ie));c()})();l=it(B)(C)(P)(w),d=P,h=C,m=k._1.tail;continue}c()}return x};return b(u=>g=>{const _=It(d=>y,d=>h=>T("Just",{head:d,tail:h}),$a(t)(g)),f=(()=>{if(_.tag==="Nothing")return it(B)(g)(0)(H);if(_.tag==="Just")return s(it(B)(_._1.head)(0)(H))(0)(_._1.head)(_._1.tail);c()})(),l=b(d=>h=>Fr(d)(-h._2))(0)(C_(f));return b(d=>h=>it(B)(h._1)(h._2+l)(d))(u)(C_(f))})(H)(Ur(B.compare)((()=>{const u=(g,_)=>{if(g.tag==="Leaf")return _;if(g.tag==="Node")return u(g._5,wt("Cons",g._4,u(g._6,_)));c()};return Mt(ce.foldr,u(t.root,A))})()))},Fv=t=>e=>{const n=(o,i,a)=>Ve(3)(i)==="$d:"&&Hg(rh,(()=>{const s=dt(i)(t.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;c()})()),r=o=>i=>a=>s=>u=>g=>_=>{let f=o,l=i,d=s,h=g,m=_,p=!0,x;for(;p;){const w=f,J=l,N=d,k=h,C=m,R=J.length;if(C>=R){p=!1,x=w;continue}const P=C>=0&&C<J.length?T("Just",J[C]):y,I=(()=>{if(P.tag==="Nothing")return"";if(P.tag==="Just")return P._1;c()})(),U=n(t,I);if(C===(R-1|0)||U){const S=(()=>{if(U){const v=dt(I)(t.preds),D=(()=>{if(v.tag==="Nothing")return[];if(v.tag==="Just")return v._1;c()})();if(0<D.length){const W=N-1|0,M=dt(D[0])(t.nodeIndex);if(M.tag==="Nothing")return W;if(M.tag==="Just")return M._1;c()}}return N-1|0})();f=b(v=>D=>{if(D>=0&&D<J.length){const W=J[D];return n(t,W)?v:b(M=>q=>{const $=dt(q)(t.nodeIndex),G=(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;c()})();return G<k||G>S?it(B)(q+"\u2192"+W)()(M):M})(v)((()=>{const M=dt(W)(t.preds);if(M.tag==="Nothing")return[];if(M.tag==="Just")return M._1;c()})())}return n(t,"")?v:b(W=>M=>{const q=dt(M)(t.nodeIndex),$=(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;c()})();return $<k||$>S?it(B)(M+"\u2192")()(W):W})(v)((()=>{const W=dt("")(t.preds);if(W.tag==="Nothing")return[];if(W.tag==="Just")return W._1;c()})())})(w)(Ut(0,C)),l=J,d=N,h=S,m=C+1|0;continue}f=w,l=J,d=N,h=k,m=C+1|0}return x};return e.length<3?H:b(o=>i=>{if(i>=0&&i<e.length){const a=e[i];return r(o)((()=>{const s=i+1|0;return s>=0&&s<e.length?e[s]:[]})())(a)(a.length)(i)(0)(0)}return r(o)((()=>{const a=i+1|0;return a>=0&&a<e.length?e[a]:[]})())([])(0)(i)(0)(0)})(H)(Ut(1,e.length-2|0))},Dv=t=>e=>n=>r=>o=>{const i=kn(e),a=b(s=>u=>{const g=b(_=>f=>{const l=(()=>{if(o==="HRight"){const p=dt(f)(t.preds);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;c()}if(o==="HLeft"){const p=dt(f)(t.succs);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1}c()})(),d=l.length;if(d===0)return _;const h=Lr(d-1|0,2),m=Lr(d,2);return b(p=>x=>{if((()=>{const w=dt(f)(p.align);if(w.tag==="Nothing")return f!==f;if(w.tag==="Just")return w._1!==f;c()})())return p;if(x>=0&&x<l.length){const w=dt(l[x])(t.nodeIndex),J=(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})();if(!(Th(l[x]+"\u2192"+f)(n)||Th(f+"\u2192"+l[x])(n))&&(()=>{if(r==="VDown")return p.r<J;if(r==="VUp")return p.r>J;c()})()){const N=dt(l[x])(p.root),k=(()=>{if(N.tag==="Nothing")return l[x];if(N.tag==="Just")return N._1;c()})();return{root:it(B)(f)(k)(p.root),align:it(B)(l[x])(f)(it(B)(f)(k)(p.align)),r:J}}}return p})(_)((()=>{if(r==="VDown")return Ut(h,m);if(r==="VUp")return re(Ut(h,m));c()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;c()})()})((()=>{if(r==="VDown")return u;if(r==="VUp")return re(u);c()})());return{root:g.root,align:g.align}})({root:Dr(Y(s=>E(s,s))(i)),align:Dr(Y(s=>E(s,s))(i))})((()=>{if(o==="HRight")return e;if(o==="HLeft")return re(e);c()})());return{root:a.root,align:a.align}},Gu=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>{const _=Dv(e)(n)(s)(u)(g),f=zv(_)(o)(r)(i)(a)(g);return $g()(l=>d=>T("Just",(()=>{const h=dt(l)(f);if(h.tag==="Nothing")return d+0;if(h.tag==="Just")return d+h._1;c()})()))(Iv(t)(e)(n)(r)(o)(i)(a)(f)(_)(u)(g))},bh=t=>e=>Dt(n=>r=>b(o=>i=>i>=0&&i<e.length?i>=0&&i<t.length?o+e[i]+t[i]:o+e[i]+0:i>=0&&i<t.length?o+1+t[i]:o+1)(0)((()=>{const o=Ut(0,e.length-1|0);return n<1?[]:Bt(0,n,o)})()))(e),Mv=t=>e=>n=>r=>o=>i=>a=>{const s=Sv(0)(e.length-1|0),u=ot(t.layerGap),g=a(Do(s,u)),_=Tv(fh(o)(g)(r)(i)(H))(g);return Y(f=>{const l=Ev(f)(_);return l.tag==="Just"&&l._1>0?Fr(u)(2+ot(l._1-1|0)*2.5):u})(Ut(0,s-1|0))},vh=t=>e=>n=>r=>Hg(o=>b(i=>a=>{if(!i.ok)return i;const s=dt(a)(r),u=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})(),g=dt(a)(n),_=(()=>{if(g.tag==="Nothing")return u+1;if(g.tag==="Just")return u+g._1._1;c()})();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),Qv=t=>e=>n=>r=>{const o=Rt(i=>a=>at.compare(i.w)(a.w))(Y(i=>({l:i,w:Nh(i)}))(_t(vh()(e)(n),r)));return 0<o.length?T("Just",o[0].l):y},Hv=t=>e=>{const n=Dr(kn(Y(Dt(o=>i=>E(i,o)))(t))),r=o=>Rt(i=>a=>ut.compare((()=>{const s=dt(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})())((()=>{const s=dt(a)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(o);return{preds:(()=>{const o=i=>{if(i.tag==="Leaf")return H;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));c()};return o(b(i=>a=>Ht(B)(we)(a.to.node)([a.from.node])(i))(H)(e))})(),succs:(()=>{const o=i=>{if(i.tag==="Leaf")return H;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));c()};return o(b(i=>a=>Ht(B)(we)(a.from.node)([a.to.node])(i))(H)(e))})(),nodeIndex:n}},Ov=t=>e=>{const n=Rt(f=>l=>at.compare(f.w)(l.w))(Dt(f=>l=>({i:f,l,w:Nh(l)}))(e)),r=0<n.length?T("Just",n[0]):y,o=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;c()})(),i=o>=0&&o<e.length?T("Just",e[o]):y,a=(()=>{if(i.tag==="Just")return(f=>l=>{let d=f,h=l,m=!0,p;for(;m;){const x=d,w=h;if(w.tag==="Nil"){m=!1,p=x;continue}if(w.tag==="Cons"){d=er(x)(w._1),h=w._2;continue}c()}return p})(999999)((()=>{const f=(l,d)=>{if(l.tag==="Leaf")return d;if(l.tag==="Node")return f(l._5,wt("Cons",l._4,f(l._6,d)));c()};return f(i._1,A)})());if(i.tag==="Nothing")return 0;c()})(),s=f=>b(l=>d=>Fr(l)((()=>{const h=dt(d._1)(t);if(h.tag==="Nothing")return d._2+1;if(h.tag==="Just")return d._2+h._1._1;c()})()))(-999999)(C_(f)),u=o>=0&&o<e.length?T("Just",e[o]):y,g=(()=>{if(u.tag==="Just")return s(u._1);if(u.tag==="Nothing")return 0;c()})(),_=He(f=>l=>{const d=h=>{if(h.tag==="Leaf")return H;if(h.tag==="Node")return ee("Node",h._1,h._2,h._3,h._4+l,d(h._5),d(h._6));c()};return d(f)},e,Dt(f=>l=>fo(f)(2)===0?a-(d=>h=>{let m=d,p=h,x=!0,w;for(;x;){const J=m,N=p;if(N.tag==="Nil"){x=!1,w=J;continue}if(N.tag==="Cons"){m=er(J)(N._1),p=N._2;continue}c()}return w})(999999)((()=>{const d=(h,m)=>{if(h.tag==="Leaf")return m;if(h.tag==="Node")return d(h._5,wt("Cons",h._4,d(h._6,m)));c()};return d(l,A)})()):g-s(l))(e));return Bv(b(f=>l=>{const d=Rt(at.compare)(ht(dt(l))(_));return it(B)(l)(d.length===4?1<d.length&&2<d.length?(d[1]+d[2])/2:0:0<d.length?d[0]:0)(f)})(H)(Ur(B.compare)(kn(Y(f=>{const l=d=>{if(d.tag==="Leaf")return H;if(d.tag==="Node")return ee("Node",d._1,d._2,d._3,void 0,l(d._5),l(d._6));c()};return Mt(wn.foldr,l(f))})(_)))))},Wv=t=>e=>n=>r=>o=>i=>{const a=Hv(e)(o),s=Fv(a)(e),u={nodeGap:t.nodeGap*4|0},g=en(B.compare,je,Dr(Y(d=>E(d,E(1,1)))(_t(rh,kn(e)))),(()=>{const d=h=>{if(h.tag==="Leaf")return H;if(h.tag==="Node")return ee("Node",h._1,h._2,h._3,E(h._4._1*ot(4),h._4._2),d(h._5),d(h._6));c()};return d(n)})()),_=[Gu(u)(a)(e)(g)(r)(o)(i)(s)(yh)(wh),Gu(u)(a)(e)(g)(r)(o)(i)(s)(xh)(wh),Gu(u)(a)(e)(g)(r)(o)(i)(s)(yh)(Jh),Gu(u)(a)(e)(g)(r)(o)(i)(s)(xh)(Jh)],f=Ov(g)(_);if(vh()(e)(g)(f))return f;const l=Qv()(e)(g)(_);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return _[0];c()},$v=t=>e=>n=>r=>{const o=j1(y,U1,i=>i.node===e?T("Just",i.position):y,t);if(o.tag==="Nothing")return t;if(o.tag==="Just"){const i=o._1;return Y(a=>a.node===n?{...a,position:E(i._1+r._1,i._2+r._2)}:a)(t)}c()},qv=t=>e=>n=>r=>{const o=_t(a=>yn(kr)(a.node)(e),t),i=(()=>{if(n==="Vertical"){if(r==="Start")return b(a=>s=>er(a)(s.position._1))(99999)(o);if(r==="End")return b(a=>s=>Fr(a)(s.position._1))(0)(o);if(r==="Center"){const a=b(s=>u=>s+u.position._1)(0)(o);return o.length===0?0:a/ot(o.length)}c()}if(n==="Horizontal"){if(r==="Start")return b(a=>s=>er(a)(s.position._2))(99999)(o);if(r==="End")return b(a=>s=>Fr(a)(s.position._2))(0)(o);if(r==="Center"){const a=b(s=>u=>s+u.position._2)(0)(o);return o.length===0?0:a/ot(o.length)}}c()})();return Y(a=>{if(yn(kr)(a.node)(e)){if(n==="Vertical")return{...a,position:E(i,a.position._2)};if(n==="Horizontal")return{...a,position:E(a.position._1,i)};c()}return a})(t)},Vv=t=>e=>b(n=>r=>r.tag==="AlignGroup"?qv(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?$v(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),Uv=t=>e=>n=>r=>o=>i=>a=>s=>{const u=Y(f=>b(l=>d=>Fr(l)((()=>{const h=dt(d)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;c()})()))(1)(f))(n),g=Wv(t)(n)(r)(o)(i)(s),_=bh(Mv(t)(n)(r)(o)(i)(a)(f=>{const l=bh(f)(u);return kn(Dt(d=>h=>Dt(m=>p=>({node:p,position:E((()=>{const x=dt(p)(g);return(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;c()})()/ot(4)})(),d>=0&&d<l.length?l[d]:0),size:(()=>{const x=Ve(3)(p)==="$d:"?E(0,1):E(1,1),w=dt(p)(r);if(w.tag==="Nothing")return x;if(w.tag==="Just")return w._1;c()})(),layer:d,order:m}))(h))(n))}))(u);return Vv(e)(kn(Dt(f=>l=>Dt(d=>h=>({node:h,position:E((()=>{const m=dt(h)(g);return(()=>{if(m.tag==="Nothing")return 0;if(m.tag==="Just")return m._1;c()})()/ot(4)})(),f>=0&&f<_.length?_[f]:0),size:(()=>{const m=Ve(3)(h)==="$d:"?E(0,1):E(1,1),p=dt(h)(r);if(p.tag==="Nothing")return m;if(p.tag==="Just")return p._1;c()})(),layer:f,order:d}))(l))(n)))},L_=gc(Bs)($o(32)),Ch=gc(Bs)($o(31)),qa=(()=>{const t=fx("25214903917");if(t.tag==="Nothing")return Pf;if(t.tag==="Just")return t._1;c()})(),Va=uc(gc(Bs)($o(48)))(Bs),Kv=t=>{const e=lx(t);return Ea(Gf((()=>{if(e.tag==="Nothing")return Pf;if(e.tag==="Just")return e._1;c()})())(qa))(Va)},k_=$o(11),Bu=t=>e=>{const n=Ea(Ps(Gs(e)(qa))(k_))(Va);return E((()=>{const r=nf(ux(cc(n)($o(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;c()})(),n)},Yv=t=>{const e=Bu(26)(t),n=Bu(27)(e._2);return E((ot(e._1)*Wg(2)(27)+ot(n._1))/Wg(2)(53),n._2)},Xv=t=>e=>{const n=b(r=>o=>{const i=Yv(r.finalR);return{rs:[...r.rs,i._1],finalR:i._2}})({rs:[],finalR:t})(e);return E(Y(r=>r.x)(Rt(r=>o=>at.compare(r.k)(o.k))(He(r=>o=>({x:r,k:o}),e,n.rs))),n.finalR)},Zv=t=>{const e=Ea(Ps(Gs(t)(qa))(k_))(Va),n=Ea(Ps(Gs(e)(qa))(k_))(Va);return E(Ps(Gs((()=>{const r=cc(e)($o(16));return Bf.compare(r)(Ch)!=="LT"?uc(r)(L_):r})())(L_))((()=>{const r=cc(n)($o(16));return Bf.compare(r)(Ch)!=="LT"?uc(r)(L_):r})()),n)},Ua=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Au=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=B.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}}c()}return o},S_=fe(B)(Qt),ca=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Iu=fe(B)(Qt),jv=bs(zi),tC=b(ur)(0),eC=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Lh=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=B.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}}c()}return o},nC=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const o=go(Xt,y,t,n[e],n);if(o.tag==="Just")return go(Xt,y,e,r,o._1);if(o.tag==="Nothing")return y;c()}}return y},rC=t=>e=>n=>r=>o=>S_(b(i=>a=>{const s=Rt(u=>g=>ut.compare((()=>{const _=Ua(u.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;c()})())((()=>{const _=Ua(g.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;c()})()))(_t(u=>Au(u.to.node)(n),_t(u=>u.from.node===a,r)));return{ranks:[...i.ranks,...Dt(u=>g=>E(g.id,ot((i.rankSum+u|0)+1|0)))(s)],rankSum:i.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),oC=t=>e=>n=>r=>o=>S_(b(i=>a=>{const s=Rt(g=>_=>{const f=ut.compare((()=>{const l=ca(_.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})())((()=>{const l=ca(g.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})());return f==="EQ"?ut.compare((()=>{const l=Ua(g.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Ua(_.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})()):f})(_t(g=>Au(g.from.node)(n),_t(g=>g.to.node===a,r))),u=s.length;return{ranks:[...i.ranks,...Dt(g=>_=>E(_.id,ot((i.rankSum+u|0)-g|0)))(s)],rankSum:i.rankSum+u|0}})({ranks:[],rankSum:0})(t).ranks),E_=t=>e=>n=>{const r=Iu(Dt(s=>u=>E(u,s))(t)),o=Iu(Dt(s=>u=>E(u,s))(e)),i=ht(s=>{const u=ca(s.from.node)(r),g=ca(s.to.node)(o);if(u.tag==="Just"&&g.tag==="Just")return T("Just",E(u._1,g._1));const _=ca(s.from.node)(o),f=ca(s.to.node)(r);return _.tag==="Just"&&f.tag==="Just"?T("Just",E(f._1,_._1)):y})(n),a=i.length;return b(s=>u=>b(g=>_=>u>=0&&u<i.length&&_>=0&&_<i.length&&((i[u]._1-i[_]._1|0)*(i[u]._2-i[_]._2|0)|0)<0?g+1|0:g)(s)(Ut(u+1|0,a-1|0)))(0)(Ut(0,a-2|0))},iC=t=>e=>n=>r=>{const o=i=>a=>{let s=i,u=a,g=!0,_;for(;g;){const f=s,l=u;if(l>=(f.length-1|0)){g=!1,_=f;continue}if(l>=0&&l<f.length){const d=l+1|0;if(d>=0&&d<f.length){const h=f[l],m=f[d];if(oe(J=>J.before===h&&J.after===m,r)){s=f,u=l+1|0;continue}const p=go(Xt,y,l,m,f),x=(()=>{if(p.tag==="Just")return go(Xt,y,l+1|0,h,p._1);if(p.tag==="Nothing")return y;c()})(),w=(()=>{if(x.tag==="Nothing")return f;if(x.tag==="Just")return x._1;c()})();if(E_(e)(w)(n)<E_(e)(f)(n)){s=w,u=l+1|0;continue}s=f,u=l+1|0;continue}g=!1,_=f;continue}g=!1,_=f}return _};return(i=>{let a=i,s=!0,u;for(;s;){const g=a,_=o(g)(0);if(jv(_)(g)){s=!1,u=g;continue}a=_}return u})(t)},zu=t=>e=>b(n=>r=>{if(r>=0&&r<t.length){const o=t[r],i=r+1|0;if(i>=0&&i<t.length)return n+E_(o)(t[i])(e)|0}return n})(0)(Ut(0,t.length-2|0)),aC=(()=>{const t=e=>{if(e.length<7){const i=a=>s=>{let u=a,g=s,_=!0,f;for(;_;){const l=u,d=g,h=d-1|0;if(h>=0&&h<l.length){if(d>=0&&d<l.length&&d>0&&l[h].key>l[d].key){const m=nC(d-1|0)(d)(l);if(m.tag==="Just"){u=m._1,g=d-1|0;continue}if(m.tag==="Nothing"){_=!1,f=l;continue}c()}_=!1,f=l;continue}_=!1,f=l}return f};return b(a=>s=>i(a)(s))(e)(Ut(1,e.length-1|0))}const n=Lr(e.length,2),r=t(Bt(0,n,e)),o=t(Bt(n,e.length,e));return(i=>a=>s=>{let u=i,g=a,_=s,f=!0,l;for(;f;){const d=u,h=g,m=_;if(h>=0&&h<r.length){if(m>=0&&m<o.length){if(r[h].key>o[m].key){u=Et(d)(o[m]),g=h,_=m+1|0;continue}u=Et(d)(r[h]),g=h+1|0,_=m;continue}f=!1,l=[...d,...h<1?r:Bt(h,r.length,r)];continue}f=!1,l=[...d,...m<1?o:Bt(m,o.length,o)]}return l})([])(0)(0)};return t})(),sC=t=>e=>n=>{const r=ht(g=>g.tag==="OrderConstraint"?T("Just",{before:g._1.before,after:g._1.after}):y)(t.constraints),o=g=>b(_=>f=>{const l=f.after,d=f.before,h=Mo(Xt,y,p=>p===d,_),m=Mo(Xt,y,p=>p===l,_);if(h.tag==="Just"&&m.tag==="Just"&&h._1>m._1){const p=ef(Xt,y,h._1,_),x=(()=>{if(p.tag==="Nothing")return _;if(p.tag==="Just")return p._1;c()})(),w=tf(Xt,y,m._1,d,x);if(w.tag==="Nothing")return x;if(w.tag==="Just")return w._1;c()}return _})(g)(r),i=S_(Dt(g=>_=>E(_.id,g))(n)),a=(g,_,f)=>{const l=g.length;return b(d=>h=>{const m=_?h-1|0:h+1|0,p=m>=0&&m<d._1.length?T("Just",d._1[m]):y;if(p.tag==="Just"){const x=h>=0&&h<d._1.length?T("Just",d._1[h]):y;if(x.tag==="Just"){const w=Iu(Dt(R=>P=>E(P,R))(p._1)),J=Iu(Dt(R=>P=>E(P,R))(x._1)),N=_?rC(p._1)(w)(J)(n)(i):oC(p._1)(w)(J)(n)(i),k=b(R=>P=>{const I=ht(S=>Ua(S.id)(N))(_t(_?S=>S.to.node===P._2&&Au(S.from.node)(w):S=>S.from.node===P._2&&Au(S.to.node)(w),n));if(I.length===0)return{...R,items:[...R.items,{n:P._2,key:y,origIdx:P._1}]};const U=Bu(24)(R.r);return{items:[...R.items,{n:P._2,key:T("Just",(tC(I)+(ot(U._1)*4172325152040912e-24-.03500000014901161))/ot(I.length)),origIdx:P._1}],r:U._2}})({items:[],r:d._2})(Dt(mn)(x._1)),C=go(Xt,y,h,iC(o(Y(R=>R.n)(aC((()=>{const R=k.items,P=I=>U=>{let S=I,v=U,D=!0,W;for(;D;){const M=S,q=v;if(M>=0&&M<R.length){if(R[M].key.tag==="Just"){D=!1,W=R[M].key._1;continue}if(R[M].key.tag==="Nothing"){S=M+1|0,v=q;continue}c()}D=!1,W=q}return W};return(I=>U=>S=>{let v=I,D=U,W=S,M=!0,q;for(;M;){const $=v,G=D,F=W;if($>=0&&$<R.length){if(R[$].key.tag==="Just"){v=$+1|0,D=R[$].key._1,W=[...F,{n:R[$].n,key:R[$].key._1,origIdx:R[$].origIdx}];continue}if(R[$].key.tag==="Nothing"){const Q=(G+P($+1|0)(G+1))/2;v=$+1|0,D=Q,W=[...F,{n:R[$].n,key:Q,origIdx:R[$].origIdx}];continue}c()}M=!1,q=F}return q})(0)(-1)([])})()))))(p._1)(n)(r),d._1);if(C.tag==="Just")return E(C._1,k.r);if(C.tag==="Nothing")return E(d._1,d._2);c()}if(x.tag==="Nothing")return E(d._1,d._2);c()}if(p.tag==="Nothing")return E(d._1,d._2);c()})(E(g,f))(_?Ut(1,l-1|0):re(Ut(0,l-2|0)))},s=b(g=>_=>it(B)(_.from.node)()(it(B)(_.to.node)()(g)))(H)(n),u=b(g=>_=>{if(g.result.crossings===0)return g;const f=w=>J=>N=>k=>{let C=w,R=J,P=N,I=k,U=!0,S;for(;U;){const v=C,D=R,W=P,M=I;if(W===0){U=!1,S={layout:v,crossings:0,random:M};continue}const q=a(v,D,M),$=zu(q._1)(n);if($<W){C=q._1,R=!D,P=$,I=q._2;continue}U=!1,S={layout:v,crossings:W,random:q._2}}return S},l=Bu(1)(g.result.random),d=l._1!==0,h=t.modelOrder.tag==="Leaf",m=(g.firstTry||g.secondTry)&&!h?g.firstTry:d,p=(()=>{if(!h){const k=a(e,m,l._2);return f(k._1)(!m)(zu(k._1)(n))(k._2)}const w=m?0:eC(0)(e.length-1|0),J=w>=0&&w<e.length?T("Just",e[w]):y;if(J.tag==="Just"&&J._1.length>1){const k=_t(C=>Lh(C)(s),J._1);if(k.length>1){const C=Xv(l._2)(k),R=C._1,P=go(Xt,y,w,o(b(I=>U=>Lh(U)(s)?I.idx>=0&&I.idx<R.length?{idx:I.idx+1|0,result:[...I.result,R[I.idx]]}:{idx:I.idx,result:[...I.result,U]}:{idx:I.idx,result:[...I.result,U]})({idx:0,result:[]})(J._1).result),e);if(P.tag==="Just"){const I=a(P._1,m,C._2);return f(I._1)(!m)(zu(I._1)(n))(I._2)}}}const N=a(e,m,l._2);return f(N._1)(!m)(zu(N._1)(n))(N._2)})(),x=g.secondTry?!1:g.secondTry;return g.firstTry?{result:p.crossings<g.result.crossings?{layout:p.layout,crossings:p.crossings,random:p.random}:{...g.result,random:p.random},firstTry:!1,secondTry:!0}:{result:p.crossings<g.result.crossings?{layout:p.layout,crossings:p.crossings,random:p.random}:{...g.result,random:p.random},firstTry:g.firstTry,secondTry:x}})({result:{layout:e,crossings:1e9,random:Ea(Gf(Zv(Kv(1))._1)(qa))(Va)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Ut(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:u.layout},uC=t=>t,kh=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=B.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}}c()}return o},Tn=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},_a=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=B.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}}c()}return o},Ka=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=B.compare(e._1)(n._1);return r==="LT"?Me:r==="GT"?Qe:B.compare(e._2)(n._2)},Eq0:()=>t}})(),gC=fe(B)(Qt),cC=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=Ka.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}}c()}return o},_C=uC("Greedy"),R_=t=>e=>n=>b(r=>o=>{if(o.from.node===o.to.node)return r;if(o.from.node===e&&!kh(o.to.node)(r.marks)){const i=Tn(o.to.node)(r.inDeg),a=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;c()})(),s=it(B)(o.to.node)(a)(r.inDeg);return(()=>{const u=Tn(o.to.node)(r.outDeg);return a<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;c()})()&&!yn(kr)(o.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,o.to.node]}:{...r,inDeg:s}}if(o.to.node===e&&!kh(o.from.node)(r.marks)){const i=Tn(o.from.node)(r.outDeg),a=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;c()})(),s=it(B)(o.from.node)(a)(r.outDeg);return(()=>{const u=Tn(o.from.node)(r.inDeg);return a<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;c()})()&&!yn(kr)(o.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,o.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:_t(r=>r!==e,n.remaining)})(t),fC=b(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return it(B)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return it(B)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return it(B)(e._1.node)(99999)(t)}return t})(H),Sh=t=>e=>n=>{const r=Tn(e)(t),o=Tn(n)(t);return r.tag==="Just"&&o.tag==="Just"&&r._1>o._1},Eh=t=>e=>n=>r=>{if(_a(n)(r.visited)||_a(n)(r.visiting))return r;const o=b(lC(t)(e)(n))({...r,visiting:it(B)(n)()(r.visiting)})((()=>{const i=Tn(n)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;c()})());return{...o,visiting:Mi(B)(n)(o.visiting),visited:it(B)(n)()(o.visited)}},lC=t=>e=>n=>r=>o=>Sh(t)(n)(o)?{...r,backEdges:it(Ka)(E(n,o))()(r.backEdges)}:_a(o)(r.visiting)?{...r,backEdges:it(Ka)(E(n,o))()(r.backEdges)}:_a(o)(r.visited)?r:Eh(t)(e)(o)(r),dC=t=>e=>n=>{const r=l=>{let d=l,h=!0,m;for(;h;){const p=d,x=It(w=>y,w=>J=>T("Just",{head:w,tail:J}),p.sinks);if(x.tag==="Just"){d=R_(n)(x._1.head)({...p,sinks:x._1.tail,marks:it(B)(x._1.head)(p.nextRight)(p.marks),nextRight:p.nextRight-1|0});continue}if(x.tag==="Nothing"){const w=It(J=>y,J=>N=>T("Just",{head:J,tail:N}),p.sources);if(w.tag==="Just"){d=R_(n)(w._1.head)({...p,sources:w._1.tail,marks:it(B)(w._1.head)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}if(w.tag==="Nothing"){const J=k=>{const C=Tn(k)(p.outDeg),R=Tn(k)(p.inDeg);return(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;c()})()-(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;c()})()|0},N=Rt(k=>C=>{const R=ut.compare(J(C))(J(k));return R==="EQ"?ut.compare((()=>{const P=Tn(k)(e);if(P.tag==="Nothing")return 1e6;if(P.tag==="Just")return P._1;c()})())((()=>{const P=Tn(C)(e);if(P.tag==="Nothing")return 1e6;if(P.tag==="Just")return P._1;c()})()):R})(p.remaining);if(0<N.length){const k=N[0];d=R_(n)(k)({...p,remaining:_t(C=>C!==k,p.remaining),marks:it(B)(k)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}h=!1,m=p;continue}}c()}return m},o=Ur(B.compare)([...Y(l=>l.from.node)(n),...Y(l=>l.to.node)(n)]),i=_t(l=>l.from.node!==l.to.node,n),a=b(l=>d=>Ht(B)(ve)(d.to.node)(1)(l))(H)(i),s=b(l=>d=>Ht(B)(ve)(d.from.node)(1)(l))(H)(i),u=_t(l=>{const d=Tn(l)(a);if(d.tag==="Nothing")return!0;if(d.tag==="Just")return d._1===0;c()},o),g=_t(l=>{const d=Tn(l)(s);if(d.tag==="Nothing")return!0;if(d.tag==="Just")return d._1===0;c()},o),_=o.length+1|0,f=b(l=>d=>{const h=Tn(d)(l);return h.tag==="Just"&&h._1<0?it(B)(d)(h._1+_|0)(l):l})(r({remaining:_t(l=>!yn(kr)(l)(u)&&!yn(kr)(l)(g),o),marks:H,inDeg:a,outDeg:s,sources:u,sinks:g,nextLeft:1,nextRight:-1}).marks)(o);return b(l=>d=>{if(d.from.node===d.to.node)return l;if(Sh(t)(d.from.node)(d.to.node))return it(Ka)(E(d.from.node,d.to.node))()(l);const h=Tn(d.from.node)(f),m=Tn(d.to.node)(f);return h.tag==="Just"&&m.tag==="Just"&&h._1>m._1?it(Ka)(E(d.from.node,d.to.node))()(l):l})(H)(n)},hC=b(t=>e=>Ht(B)(we)(e.from.node)([e.to.node])(t))(H),pC=t=>e=>{const n=hC(e),r=Ur(B.compare)([...Y(i=>i.from.node)(e),...Y(i=>i.to.node)(e)]),o=b(i=>a=>it(B)(a.to.node)()(i))(H)(e);return b(i=>a=>Eh(t)(n)(a)(i))({visiting:H,visited:H,backEdges:H})([..._t(i=>!_a(i)(o),r),..._t(i=>_a(i)(o),r)]).backEdges},mC=t=>e=>n=>r=>{const o=gC(Dt(s=>u=>E(u,s))(e)),i=fC(n),a=(()=>{if(t==="DepthFirst")return pC(i)(r);if(t==="Greedy")return dC(i)(o)(r);c()})();return{edges:Y(s=>cC(E(s.from.node,s.to.node))(a)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:a}},Rh=Qt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),Ge=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Be=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ya=t=>e=>n=>r=>Rh(o=>n>=o.x&&n<o.x+o.w&&e>o.y&&t<o.y+o.h)(r),Fu=t=>e=>n=>r=>Ya(Ge(e)(n))(Be(e)(n))(r)(t),Du=ot(4),yC=vs(t=>{if(t.direction==="H"){const e=Ge(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:Be(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=Ge(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:Be(t.start._2)(t.end._2)-e}]}c()}),Xa=Ta(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})())}),xC=t=>e=>n=>{const r=It(o=>y,o=>i=>T("Just",{head:o,tail:i}),e);if(r.tag==="Nothing")return[{start:t.start,end:n.end,direction:t.direction}];if(r.tag==="Just"){const o=(r._1.head.direction==="H"?t.direction==="H":r._1.head.direction==="V"&&t.direction==="V")?[{start:t.start,end:r._1.head.end,direction:t.direction}]:[t,r._1.head],i=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?[]:Bt(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]}c()},Za=t=>{const e=r=>o=>{const i=It(a=>y,a=>s=>T("Just",{head:a,tail:s}),o);if(i.tag==="Nothing")return[r];if(i.tag==="Just")return(r.direction==="H"?i._1.head.direction==="H":r.direction==="V"&&i._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==i._1.head.end._1-i._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==i._1.head.end._2-i._1.head.start._2>=0;c()})()?e({start:r.start,end:i._1.head.end,direction:r.direction})(i._1.tail):[r,...e(i._1.head)(i._1.tail)];c()},n=It(r=>y,r=>o=>T("Just",{head:r,tail:o}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);c()},ja=t=>e=>n=>r=>Rh(o=>n>=o.y&&n<o.y+o.h&&e>o.x&&t<o.x+o.w)(r),ts=t=>e=>n=>r=>ja(Ge(e)(n))(Be(e)(n))(r)(t),wC=t=>e=>n=>r=>{const o=n+2|0,i=o<1?e:Bt(o,e.length,e),a=n<1?[]:Bt(0,n,e),s=(n+1|0)===(r-1|0),u=n===0,g=n>=0&&n<e.length?T("Just",e[n]):y;if(g.tag==="Just"){const _=n+1|0,f=_>=0&&_<e.length?T("Just",e[_]):y;if(f.tag==="Just"){const l=g._1.start._1===f._1.end._1&&(!u||g._1.direction==="V")&&(!s||f._1.direction==="V")&&!Fu(t)(Ge(g._1.start._2)(f._1.end._2))(Be(g._1.start._2)(f._1.end._2))(g._1.start._1)?T("Just",[...a,{start:g._1.start,end:f._1.end,direction:Ne},...i]):y,d=g._1.start._2===f._1.end._2&&(!u||g._1.direction==="H")&&(!s||f._1.direction==="H")&&!ts(t)(Ge(g._1.start._1)(f._1.end._1))(Be(g._1.start._1)(f._1.end._1))(g._1.start._2)?T("Just",[...a,{start:g._1.start,end:f._1.end,direction:Te},...i]):y;return l.tag==="Nothing"?d:l}if(f.tag==="Nothing")return y;c()}if(g.tag==="Nothing")return y;c()},JC=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=wC(t)(e)(s)(n);if(u.tag==="Just"){i=!1,a=u._1;continue}if(u.tag==="Nothing"){o=s+1|0;continue}c()}return a})(0)},TC=t=>e=>n=>r=>{const o=(l,d,h)=>!Fu(t)(Ge(d)(h))(Be(d)(h))(l),i=n+3|0,a=i<1?e:Bt(i,e.length,e),s=n<1?[]:Bt(0,n,e),u=(n+2|0)===(r-1|0),g=n===0,_=(l,d,h)=>!ts(t)(Ge(d)(h))(Be(d)(h))(l),f=n>=0&&n<e.length?T("Just",e[n]):y;if(f.tag==="Just"){const l=n+2|0,d=l>=0&&l<e.length?T("Just",e[l]):y;if(d.tag==="Just"){const h=f._1.start._1===d._1.end._1&&(!g||f._1.direction==="V")&&(!u||d._1.direction==="V")&&o(f._1.start._1,f._1.start._2,d._1.end._2)?T("Just",[...s,{start:f._1.start,end:d._1.end,direction:Ne},...a]):f._1.start._2===d._1.end._2&&(!g||f._1.direction==="H")&&(!u||d._1.direction==="H")&&_(f._1.start._2,f._1.start._1,d._1.end._1)?T("Just",[...s,{start:f._1.start,end:d._1.end,direction:Te},...a]):y,m=(!g||f._1.direction==="V")&&(!u||d._1.direction==="H")&&o(f._1.start._1,f._1.start._2,d._1.end._2)&&_(d._1.end._2,f._1.start._1,d._1.end._1)?T("Just",[...s,{start:f._1.start,end:E(f._1.start._1,d._1.end._2),direction:Ne},{start:E(f._1.start._1,d._1.end._2),end:d._1.end,direction:Te},...a]):y,p=(!g||f._1.direction==="H")&&(!u||d._1.direction==="V")&&_(f._1.start._2,f._1.start._1,d._1.end._1)&&o(d._1.end._1,f._1.start._2,d._1.end._2)?T("Just",[...s,{start:f._1.start,end:E(d._1.end._1,f._1.start._2),direction:Te},{start:E(d._1.end._1,f._1.start._2),end:d._1.end,direction:Ne},...a]):y,x=m.tag==="Nothing"?p:m;return h.tag==="Nothing"?x:h}if(d.tag==="Nothing")return y;c()}if(f.tag==="Nothing")return y;c()},NC=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=TC(t)(e)(s)(n);if(u.tag==="Just"){i=!1,a=u._1;continue}if(u.tag==="Nothing"){o=s+1|0;continue}c()}return a})(0)},bC=t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const a=r,s=Za(Xa(JC(t)(NC(t)(a))));if(s.length<a.length){r=s;continue}o=!1,i=s}return i};return n=>e(Za(Xa(n)))},vC=t=>e=>n=>r=>{const o=Ge(n)(r),i=Be(n)(r),a=_t(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Rt(g=>_=>at.compare(g.x)(_.x))(a);return 0<u.length?u[0].x-1:(n+r)/2}const s=Rt(u=>g=>at.compare(g.x)(u.x))(Y(u=>({...u,x:u.x+u.w}))(a));return 0<s.length?s[0].x+1:(n+r)/2},CC=t=>e=>n=>r=>{const o=Ge(n)(r),i=Be(n)(r),a=_t(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Rt(g=>_=>at.compare(g.y)(_.y))(a);return 0<u.length?u[0].y-1:(n+r)/2}const s=Rt(u=>g=>at.compare(g.y)(u.y))(Y(u=>({...u,y:u.y+u.h}))(a));return 0<s.length?s[0].y+1:(n+r)/2},LC=t=>e=>n=>r=>{const o=Ge(n)(r),i=Be(n)(r),a=_t(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Rt(g=>_=>at.compare(_.x)(g.x))(Y(g=>({...g,x:g.x+g.w}))(a));return 0<u.length?u[0].x:(n+r)/2}const s=Rt(u=>g=>at.compare(u.x)(g.x))(a);return 0<s.length?s[0].x-1:(n+r)/2},kC=t=>e=>n=>r=>{const o=Ge(n)(r),i=Be(n)(r),a=_t(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Rt(g=>_=>at.compare(_.y)(g.y))(Y(g=>({...g,y:g.y+g.h}))(a));return 0<u.length?u[0].y:(n+r)/2}const s=Rt(u=>g=>at.compare(u.y)(g.y))(a);return 0<s.length?s[0].y-1:(n+r)/2},Ph=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,g=o,_=i;if(_>100){a=!1,s=g;continue}if(!u(g+_)){a=!1,s=g+_;continue}if(!u(g-_)){a=!1,s=g-_;continue}r=u,o=g,i=_+1}return s},Gh=t=>e=>n=>r=>o=>{const i=Ge(e)(n),a=Be(e)(n);if(!Ya(i)(a)(r)(t))return r;if(!Ya(i)(a)(o)(t))return o;const s=(r+o)/2;return Ya(i)(a)(s)(t)?Ph(u=>Ya(i)(a)(u)(t))(s)(1):s},SC=t=>e=>n=>r=>o=>{const i=Ge(e)(n),a=Be(e)(n);if(!ja(i)(a)(r)(t))return r;if(!ja(i)(a)(o)(t))return o;const s=(r+o)/2;return ja(i)(a)(s)(t)?Ph(u=>ja(i)(a)(u)(t))(s)(1):s},EC=t=>e=>n=>r=>{const o=Ge(e)(n),i=Be(e)(n),a=_t(g=>r>=g.x&&r<g.x+g.w&&g.y+g.h>o&&g.y<i,t),s=b(g=>_=>Be(g)(_.x+_.w+4))(r+4)(a),u=b(g=>_=>Ge(g)(_.x-4))(r-4)(a);return(()=>{const g=s-r,_=u-r;return(g<0?-g:g)<=(_<0?-_:_)})()?s:u},RC=t=>e=>n=>r=>{const o=Ge(e)(n),i=Be(e)(n),a=_t(g=>r>=g.y&&r<g.y+g.h&&g.x+g.w>o&&g.x<i,t),s=b(g=>_=>Be(g)(_.y+_.h+4))(r+4)(a),u=b(g=>_=>Ge(g)(_.y-4))(r-4)(a);return(()=>{const g=s-r,_=u-r;return(g<0?-g:g)<=(_<0?-_:_)})()?s:u},PC=t=>e=>n=>r=>o=>i=>a=>{const s=(()=>{if(r==="South")return E(o._1,o._2+4);if(r==="North")return E(o._1,o._2-4);if(r==="East")return E(o._1+4,o._2);if(r==="West")return E(o._1-4,o._2);c()})(),u=(()=>{if(i==="South")return E(a._1,a._2+4);if(i==="North")return E(a._1,a._2-4);if(i==="East")return E(a._1+4,a._2);if(i==="West")return E(a._1-4,a._2);c()})(),g=(k,C,R)=>!Fu(e)(Ge(C)(R))(Be(C)(R))(k),_=(k,C,R)=>!Fu(n)(Ge(C)(R))(Be(C)(R))(k),f=(k,C,R,P)=>t.tag==="Just"&&!ts(n)(Ge(k)(C))(Be(k)(C))(t._1)?t._1:SC(e)(k)(C)(R)(P),l=(k,C,R,P)=>{if(k===R){const U=EC(e)(C)(P)(k),S=CC(e)(k)(C)(P),v=kC(e)(k)(C)(P);return[{start:E(k,C),end:E(k,S),direction:Ne},{start:E(k,S),end:E(U,S),direction:Te},{start:E(U,S),end:E(U,v),direction:Ne},{start:E(U,v),end:E(R,v),direction:Te},{start:E(R,v),end:E(R,P),direction:Ne}]}const I=f(k,R,C,P);return[{start:E(k,C),end:E(k,I),direction:Ne},{start:E(k,I),end:E(R,I),direction:Te},{start:E(R,I),end:E(R,P),direction:Ne}]},d=(k,C,R,P)=>{if(C===P){const U=RC(e)(k)(R)(C),S=vC(e)(C)(k)(R),v=LC(e)(C)(k)(R);return[{start:E(k,C),end:E(S,C),direction:Te},{start:E(S,C),end:E(S,U),direction:Ne},{start:E(S,U),end:E(v,U),direction:Te},{start:E(v,U),end:E(v,P),direction:Ne},{start:E(v,P),end:E(R,P),direction:Te}]}const I=Gh(e)(C)(P)(k)(R);return[{start:E(k,C),end:E(I,C),direction:Te},{start:E(I,C),end:E(I,P),direction:Ne},{start:E(I,P),end:E(R,P),direction:Te}]},h=(k,C,R)=>!ts(e)(Ge(C)(R))(Be(C)(R))(k),m=(k,C,R)=>!ts(n)(Ge(C)(R))(Be(C)(R))(k),p=(k,C,R,P)=>{if(m(C,k,R)&&_(R,C,P))return[{start:E(k,C),end:E(R,C),direction:Te},{start:E(R,C),end:E(R,P),direction:Ne}];const I=Gh(e)(C)(P)(k)(R);return[{start:E(k,C),end:E(I,C),direction:Te},{start:E(I,C),end:E(I,P),direction:Ne},{start:E(I,P),end:E(R,P),direction:Te}]},x=(k,C,R,P)=>{if(_(k,C,P)&&m(P,k,R))return[{start:E(k,C),end:E(k,P),direction:Ne},{start:E(k,P),end:E(R,P),direction:Te}];const I=f(k,R,C,P);return[{start:E(k,C),end:E(k,I),direction:Ne},{start:E(k,I),end:E(R,I),direction:Te},{start:E(R,I),end:E(R,P),direction:Ne}]},w=(()=>{if(r==="South")return i==="North"?s._1===u._1&&g(s._1,s._2,u._2)?[{start:E(s._1,s._2),end:E(u._1,u._2),direction:Ne}]:l(s._1,s._2,u._1,u._2):i==="East"||i==="West"?x(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&&g(s._1,s._2,u._2)?[{start:E(s._1,s._2),end:E(u._1,u._2),direction:Ne}]:l(s._1,s._2,u._1,u._2):i==="East"||i==="West"?x(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:E(s._1,s._2),end:E(u._1,u._2),direction:Te}]:d(s._1,s._2,u._1,u._2):i==="North"||i==="South"?p(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:E(s._1,s._2),end:E(u._1,u._2),direction:Te}]:d(s._1,s._2,u._1,u._2);if(i==="North"||i==="South")return p(s._1,s._2,u._1,u._2)}return l(s._1,s._2,u._1,u._2)})(),J=(()=>{if(r==="South"||r==="North")return Ne;if(r==="East"||r==="West")return Te;c()})(),N={start:E(u._1,u._2),end:E(a._1,a._2),direction:(()=>{if(i==="South"||i==="North")return Ne;if(i==="East"||i==="West")return Te;c()})()};return s._1===u._1&&s._2===u._2?[{start:E(o._1,o._2),end:E(a._1,a._2),direction:J}]:xC({start:E(o._1,o._2),end:E(s._1,s._2),direction:J})(w)(N)},GC=Y(t=>({x:t.position._1*Du-2,y:t.position._2*Du-2,w:t.size._1*Du+4,h:t.size._2*Du+4})),Bh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},fa=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},BC=(()=>{const t=un.unfoldr(Yn);return e=>t(gn("IterNode",e,Un))})(),P_=t=>e=>t.gapTop+1*ot(4)+ot(e)*2.5*ot(4),AC=t=>e=>{const n=Bh(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return T("Just",{slot1Y:P_(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:P_(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return y;c()}if(n.tag==="Nothing")return y;c()},IC=t=>e=>{const n=b(r=>o=>it(B)(o.node)(o)(r))(H)(e);return kn(Dt(r=>o=>{const i=fa(o.node)(n);if(i.tag==="Nothing")return[];if(i.tag==="Just"){const a=i._1;return Dt(s=>u=>{const g=o.edges.length,_=ot(4),f=a.position._1*_,l=a.position._2*_,d=a.size._2*_,h=ot((2*g|0)+1|0),m=l+d*ot(g-s|0)/h,p=l+d*ot((g+1|0)+s|0)/h,x=f-_*2.5*ot(s+1|0),w=[{start:E(f,m),end:E(x,m),direction:Te},{start:E(x,m),end:E(x,p),direction:Ne},{start:E(x,p),end:E(f,p),direction:Te}];return{edge:u.id,segments:w,bends:He(J=>N=>J.end,w,Bt(1,3,w)),bendType:[],jumps:[],reversed:!1}})(o.edges)}c()})(Y(r=>({node:r._1,edges:r._2}))(BC(b(r=>o=>Ht(B)(we)(o.from.node)([o])(r))(H)(t)))))},zC=t=>e=>{const n=b(i=>a=>it(B)(a.node)(a)(i))(H)(e),r=i=>{const a=fa(i)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1.position._1;c()},o=i=>{const a=fa(i)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1.layer;c()};return Rt(i=>a=>{const s=ut.compare(o(i.edge.from.node))(o(a.edge.from.node));if(s==="EQ"){const u=at.compare(r(i.edge.from.node))(r(a.edge.from.node));return u==="EQ"?at.compare(r(i.edge.to.node))(r(a.edge.to.node)):u}return s})(t)},Nn=t=>{const e=ot(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}},FC=t=>t.from.node===t.to.node,DC=t=>e=>n=>r=>{const o=bC(n)(PC(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:o,bends:He(i=>a=>i.end,o,Bt(1,o.length,o)),bendType:[],jumps:[],reversed:!1}},MC=t=>e=>n=>r=>{const o=[{start:E(r.fromPos._1,r.fromPos._2),end:E(r.fromPos._1,t.slot1Y),direction:Ne},{start:E(r.fromPos._1,t.slot1Y),end:E(t.splitX,t.slot1Y),direction:Te},{start:E(t.splitX,t.slot1Y),end:E(t.splitX,t.slot2Y),direction:Ne},{start:E(t.splitX,t.slot2Y),end:E(r.toPos._1,t.slot2Y),direction:Te},{start:E(r.toPos._1,t.slot2Y),end:E(r.toPos._1,r.toPos._2),direction:Ne}];return{edge:r.edge.id,segments:o,bends:He(i=>a=>i.end,o,Bt(1,5,o)),bendType:[],jumps:[],reversed:!1}},QC=t=>e=>n=>{const r=fa(t.edge.from.node)(n);if(r.tag==="Just"){const i=fa(t.edge.to.node)(n);return i.tag==="Just"?_t(a=>!(a.h===Nn(r._1).h&&a.w===Nn(r._1).w&&a.x===Nn(r._1).x&&a.y===Nn(r._1).y)&&!(a.h===Nn(i._1).h&&a.w===Nn(i._1).w&&a.x===Nn(i._1).x&&a.y===Nn(i._1).y),e):_t(a=>!(a.h===Nn(r._1).h&&a.w===Nn(r._1).w&&a.x===Nn(r._1).x&&a.y===Nn(r._1).y),e)}const o=fa(t.edge.to.node)(n);return o.tag==="Just"?_t(i=>!(i.h===Nn(o._1).h&&i.w===Nn(o._1).w&&i.x===Nn(o._1).x&&i.y===Nn(o._1).y),e):_t(i=>!0,e)},HC=t=>e=>{const n=Bh(e.edge.id)(t);if(n.tag==="Just")return T("Just",P_(n._1)(n._1.slot));if(n.tag==="Nothing")return y;c()},OC=t=>e=>n=>r=>o=>{const i=b(g=>_=>it(B)(_.node)(_)(g))(H)(e),a=GC(e),s=fh(_t(g=>g.from.node!==g.to.node,t))(e)(n)(r)(o),u=sh(s)(e);return[...IC(_t(FC,t))(e),...b(g=>_=>{const f=QC(_)(a)(i),l=[...f,...g.edgeObstacles],d=AC(u)(_),h=(()=>{if(d.tag==="Just")return MC(d._1)(f)(l)(_);if(d.tag==="Nothing")return DC(HC(u)(_))(f)(l)(_);c()})();return{results:[...g.results,h],edgeObstacles:[...g.edgeObstacles,...yC(h.segments)]}})({results:[],edgeObstacles:[]})(zC(s)(e)).results]},No=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},bo=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},WC=t=>e=>n=>{if(t.start._1!==e.start._1)return y;const r=bo(No(t.start._2)(t.end._2))(No(e.start._2)(e.end._2)),o=No(bo(t.start._2)(t.end._2))(bo(e.start._2)(e.end._2));return r<o?T("Just",{position:E(t.start._1,(r+o)/2),crossingEdge:n}):y},$C=t=>e=>n=>{if(t.start._2!==e.start._2)return y;const r=bo(No(t.start._1)(t.end._1))(No(e.start._1)(e.end._1)),o=No(bo(t.start._1)(t.end._1))(bo(e.start._1)(e.end._1));return r<o?T("Just",{position:E((r+o)/2,t.start._2),crossingEdge:n}):y},qC=t=>e=>n=>{if(t.direction==="H")return $C(t)(e)(n);if(t.direction==="V")return WC(t)(e)(n);c()},VC=t=>e=>n=>{const r=t+1|0,o=r<1?n:Bt(r,n.length,n);return St(e.segments)(i=>St(o)(a=>ht(s=>qC(i)(s)(a.edge))(_t(s=>s.direction==="H"?i.direction==="H":s.direction==="V"&&i.direction==="V",a.segments))))},UC=t=>e=>n=>e.start._1>No(t.start._1)(t.end._1)&&e.start._1<bo(t.start._1)(t.end._1)&&t.start._2>No(e.start._2)(e.end._2)&&t.start._2<bo(e.start._2)(e.end._2)?T("Just",{position:E(e.start._1,t.start._2),crossingEdge:n}):y,KC=t=>e=>St(_t(n=>n.direction==="H",t.segments))(n=>St(e)(r=>ht(o=>UC(n)(o)(r.edge))(_t(o=>o.direction==="V",r.segments)))),YC=t=>e=>n=>[...KC(e)(_t(r=>r.edge!==e.edge,n)),...VC(t)(e)(n)],Ah=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},XC=b(t=>e=>it(B)(e)()(t))(H),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 a=B.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}}c()}return o},ZC=Xd(B),Mr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Ih=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},G_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},jC=fe(ut)(Qt),t3=t=>e=>en(B.compare,je,t,e),zh=Dt(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),e3=t=>b(e=>n=>({base:(()=>{const r=o=>i=>{let a=o,s=i,u=!0,g;for(;u;){const _=a,f=s;if(f.tag==="Nil"){u=!1,g=_;continue}if(f.tag==="Cons"){a=Ah(_)(f._1),s=f._2;continue}c()}return g};return(e.base+r(0)((()=>{const o=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return o(i._5,wt("Cons",i._4,o(i._6,a)));c()};return o(n,A)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=o=>{if(o.tag==="Leaf")return H;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,o._4+e.base|0,r(o._5),r(o._6));c()};return r(n)})()]}))({base:0,result:[]})(t).result,n3=t=>e=>{const n=XC(t);return ZC(t)(zh(_t(r=>Mu(r.src)(n)&&Mu(r.tgt)(n),e)))},r3=t=>e=>{const n=b(o=>i=>Ht(B)(we)(i.tgt)([i.src])(Ht(B)(we)(i.src)([i.tgt])(o)))(H)(e),r=o=>i=>a=>{let s=o,u=i,g=a,_=!0,f;for(;_;){const l=s,d=u,h=g,m=It(p=>y,p=>x=>T("Just",{head:p,tail:x}),l);if(m.tag==="Nothing"){_=!1,f={nodes:h};continue}if(m.tag==="Just"){if(Mu(m._1.head)(d)){s=m._1.tail,u=d,g=h;continue}s=[...m._1.tail,...(()=>{const p=Mr(m._1.head)(n);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;c()})()],u=it(B)(m._1.head)()(d),g=[...h,m._1.head];continue}c()}return f};return b(o=>i=>{if(Mu(i)(o.visited))return o;const a=r([i])(o.visited)([]);return{...o,visited:b(s=>u=>it(B)(u)()(s))(o.visited)(a.nodes),components:[...o.components,a.nodes]}})({visited:H,components:[]})(t).components},o3=t=>e=>n=>{const r=b(i=>a=>Ht(B)(ve)(a.tgt)(1)(i))(H)(e),o=b(i=>a=>Ht(B)(ve)(a.src)(1)(i))(H)(e);return b(i=>a=>{const s=Mr(a)(r),u=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})();if((()=>{const w=Mr(a)(o);return(()=>{if(w.tag==="Nothing")return u!==0;if(w.tag==="Just")return u!==w._1;c()})()||u===0})())return i;const g=Mr(a)(i.layers),_=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;c()})(),f=i.layers,l=b(w=>J=>J.tgt===a?{...w,mIn:Ih(w.mIn)((()=>{const N=Mr(a)(f),k=Mr(J.src)(f);return(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})()-(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;c()})()|0})())}:J.src===a?{...w,mOut:Ih(w.mOut)((()=>{const N=Mr(J.tgt)(f),k=Mr(a)(f);return(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})()-(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;c()})()|0})())}:w)({mIn:1e9,mOut:1e9})(e),d=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(d<0||h<0)return i;const m=(_-d|0)+1|0,p=(_+h|0)-1|0;if(p<m)return i;const x=b(w=>J=>{const N=G_(J)(i.filling),k=(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})();return k<w.bestFill?{best:J,bestFill:k}:w})({best:_,bestFill:(()=>{const w=G_(_)(i.filling);if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})()})(Ut(m,p));return x.best===_?i:{layers:it(B)(a)(x.best)(i.layers),filling:it(ut)(_)((()=>{const w=G_(_)(i.filling);if(w.tag==="Nothing")return-1;if(w.tag==="Just")return w._1-1|0;c()})())(it(ut)(x.best)(x.bestFill+1|0)(i.filling))}})({layers:n,filling:jC(Y(i=>E(i,b(a=>s=>(()=>{const u=Mr(s)(n);return u.tag==="Nothing"?!1:u.tag==="Just"&&u._1===i})()?a+1|0:a)(0)(t)))(Ut(0,b(i=>a=>Ah(i)((()=>{const s=Mr(a)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(0)(t))))})(t).layers},i3=t=>e=>o3(t)(zh(e))(b(t3)(H)(e3(Y(n=>n3(n)(e))(r3(t)(e))))),a3=t=>t,ui=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Qu=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Fh=(()=>{const t=un.unfoldr(Yn);return e=>t(gn("IterNode",e,Un))})(),s3=a3("NetworkSimplex"),u3=t=>e=>b(n=>r=>{const o=b(Qu)(0)(ht(i=>ui(i)(n))(r));return b(i=>a=>it(B)(a)(o)(i))(n)(r)})(e)(t),g3=t=>e=>({layers:Y(n=>_t(r=>{const o=ui(r)(e);return o.tag==="Nothing"?!1:o.tag==="Just"&&o._1===n},t))(Ut(0,(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,g=i;if(g.tag==="Nil"){a=!1,s=u;continue}if(g.tag==="Cons"){o=Qu(u)(g._1),i=g._2;continue}c()}return s})(0)((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,wt("Cons",r._4,n(r._6,o)));c()};return n(e,A)})()))),nodeLayer:e}),c3=t=>e=>n=>{const r=b(o=>i=>it(B)(i)(!0)(o))(H)(e);return b(o=>i=>it(B)(i._1)(i._2)(o))(i3(e)(ht(o=>o.from.node===o.to.node||(()=>{const i=ui(o.from.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;c()})()||(()=>{const i=ui(o.to.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;c()})()?y:T("Just",{src:o.from.node,tgt:o.to.node}))(t)))(Fh(n))},_3=t=>e=>n=>r=>{const o=s=>u=>{const g=ui(u)(s);if(g.tag==="Just")return s;if(g.tag==="Nothing"){const _=_t(l=>l!==u,(()=>{const l=ui(u)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;c()})()),f=b(o)(s)(_);return it(B)(u)(1+b(Qu)(0)(ht(l=>ui(l)(f))(_))|0)(f)}c()},i=b(o)(H)(n),a=(s=>u=>{let g=s,_=u,f=!0,l;for(;f;){const d=g,h=_;if(h.tag==="Nil"){f=!1,l=d;continue}if(h.tag==="Cons"){g=Qu(d)(h._1),_=h._2;continue}c()}return l})(1)((()=>{const s=(u,g)=>{if(u.tag==="Leaf")return g;if(u.tag==="Node")return s(u._5,wt("Cons",u._4,s(u._6,g)));c()};return s(i,A)})());return b(s=>u=>it(B)(u._1)(u._2)(s))((()=>{const s=u=>{if(u.tag==="Leaf")return H;if(u.tag==="Node")return ee("Node",u._1,u._2,u._3,a-u._4|0,s(u._5),s(u._6));c()};return s(i)})())(Fh(r))},f3=b(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return it(B)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return it(B)(e._1.node)(0)(t)}return t})(H),l3=b(t=>e=>Ht(B)(we)(e.to.node)([e.from.node])(t))(H),d3=b(t=>e=>Ht(B)(we)(e.from.node)([e.to.node])(t))(H),h3=t=>e=>n=>r=>{const o=d3(n),i=l3(n),a=f3(e);return g3(r)(u3(ht(s=>s.tag==="SameLayer"?T("Just",s._1.nodes):y)(e))((()=>{if(t==="LongestPath")return _3(o)(i)(r)(a);if(t==="NetworkSimplex")return c3(n)(r)(a);c()})()))},p3=fe(B)(Qt),m3=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Dh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Mh=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},es=fe(B)(Qt),y3=fe(B)(Qt),Qh=(()=>{const t=Y(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>re(t(e))})(),x3=t=>e=>n=>r=>{const o=p3(Y(a=>E(a.edge,a))(r)),i=a=>0<a.nodes.length&&(()=>{const s=m3(a.edgeId)(n);return s.tag==="Just"&&a.nodes[0]!==s._1._1})();return Y(a=>{if(a.nodes.length<=2){const _=Dh(a.edgeId)(o);if(_.tag==="Just"){const f=i(a),l=Za(Xa(f?Qh(_._1.segments):_._1.segments));return{..._._1,edge:a.edgeId,segments:l,bends:He(d=>h=>d.end,l,Bt(1,l.length,l)),reversed:f}}if(_.tag==="Nothing")return{edge:a.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};c()}const s=St(ht(_=>Dh(_)(o))(He(_=>f=>a.edgeId+":"+_+"->"+f,a.nodes,Bt(1,a.nodes.length,a.nodes))))(_=>_.segments),u=i(a),g=Za(Xa(u?Qh(s):s));return{edge:a.edgeId,segments:g,bends:He(_=>f=>_.end,g,Bt(1,g.length,g)),bendType:[],jumps:[],reversed:u}})(t)},w3={layers:[],edges:[],chains:[]},Hh={nodeGap:3,layerGap:2,iterations:8,layerer:s3,cycleBreaker:_C,compactPostRouting:!0,compactionSpacings:lv},J3=t=>({pos:E(0,0),size:E(b(e=>n=>Mh(e)(n.position._1+n.size._1))(0)(t),b(e=>n=>Mh(e)(n.position._2+n.size._2))(0)(t))}),T3=t=>e=>n=>{const r=es(Y(g=>E(g.id,g.ports))(e.nodes)),o=_t(g=>Ve(3)(g.node)!=="$d:",n.placements),i=x3(n.withDummies.chains)(n.acyclic.reversedEdges)(y3(Y(g=>E(g.id,E(g.from.node,g.to.node)))(e.edges)))(OC(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(dh(n.ordered)(_t(g=>g.from.node!==g.to.node,n.withDummies.edges))((()=>{const g=_=>{if(_.tag==="Leaf")return H;if(_.tag==="Node")return ee("Node",_._1,_._2,_._3,E(_._4._1*4,_._4._2),g(_._5),g(_._6));c()};return g(es(Y(_=>E(_.id,_.size))(e.nodes)))})()))),a=t.compactPostRouting?pv()(t.compactionSpacings)({nodes:o,edges:e.edges,paths:i,ports:r}):{nodes:o,edges:i},s=Y(g=>{const _=Za(Xa(g.segments));return{...g,segments:_,bends:He(f=>l=>f.end,_,Bt(1,_.length,_))}})(a.edges),u=Dt(g=>_=>({..._,jumps:YC(g)(_)(s)}))(s);return{nodes:a.nodes,edges:u,boundingBox:J3(a.nodes),metrics:HN(a.nodes)(u)(0)}},Oh=t=>e=>n=>{const r=es(Y(i=>E(i.id,i.size))(e.nodes)),o={...n,placements:Uv({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(es(Y(i=>E(i.id,i.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(dh(n.ordered)(n.withDummies.edges)((()=>{const i=a=>{if(a.tag==="Leaf")return H;if(a.tag==="Node")return ee("Node",a._1,a._2,a._3,E(a._4._1*4,a._4._2),i(a._5),i(a._6));c()};return i(r)})()))};return{pipeline:o,result:T3(t)(e)(o)}},N3=t=>e=>n=>Oh(t)(e)({...n,ordered:sC({iterations:t.iterations,constraints:e.constraints,modelOrder:es(Dt(r=>o=>E(o.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),b3=t=>e=>n=>N3(t)(e)({...n,withDummies:mv(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),Wh=t=>e=>{const n=Y(o=>o.id)(e.nodes),r=mC(t.cycleBreaker)(n)(e.constraints)(e.edges);return b3(t)(e)({acyclic:r,layered:h3(t.layerer)(e.constraints)(r.edges)(n),withDummies:w3,ordered:[],placements:[]})},$h=fe(B)(Qt),la=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Hu=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},vo=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},v3=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},C3=t=>e=>n=>{const r=n.result.nodes,o=$h(Y(a=>E(a.node,a))(r)),i=n.result.boundingBox.size._1;return $h(ht(a=>{const s=vo(a.id)(o);if(s.tag==="Just"){const u=vo(a.id)(n.pipeline.layered.nodeLayer);if(u.tag==="Just"){const g=u._1,_=It(f=>y,f=>l=>T("Just",{head:f,tail:l}),_t(f=>f.length>=2,[ht(f=>{if(f.to.node===a.id){const l=vo(f.from.node)(n.pipeline.layered.nodeLayer);if(l.tag==="Just")return l._1>=g?y:vo(f.from.node)(o);if(l.tag==="Nothing")return y;c()}return y})(e.edges),ht(f=>{if(f.from.node===a.id){const l=vo(f.to.node)(n.pipeline.layered.nodeLayer);if(l.tag==="Just")return l._1<=g?y:vo(f.to.node)(o);if(l.tag==="Nothing")return y;c()}return y})(e.edges)]));if(_.tag==="Just"){const f=Hu(b(la)((()=>{const m=It(p=>y,p=>x=>T("Just",{head:p,tail:x}),Y(p=>p.position._1+p.size._1*.5)(_._1.head));if(m.tag==="Nothing")return a.size._1;if(m.tag==="Just")return la(a.size._1)(b(la)(m._1.head)(m._1.tail)-b(Hu)(m._1.head)(m._1.tail)+2);c()})())(Y(m=>{const p=It(x=>y,x=>w=>T("Just",{head:x,tail:w}),Y(x=>x.position._1+x.size._1*.5)(m));if(p.tag==="Nothing")return a.size._1;if(p.tag==="Just")return la(a.size._1)(b(la)(p._1.head)(p._1.tail)-b(Hu)(p._1.head)(p._1.tail)+2);c()})(_._1.tail)))(a.size._1+ot(b(v3)(_._1.head.length)(Y(ay)(_._1.tail))-1|0)),l=s._1.position._1,d=l+s._1.size._1,h=_t(m=>{const p=vo(m.node)(n.pipeline.layered.nodeLayer);return m.node!==a.id&&(p.tag==="Nothing"?!1:p.tag==="Just"&&p._1===g)},r);return f>a.size._1+.5&&f<=b(m=>p=>p.position._1>=d?Hu(m)(p.position._1-ot(t.nodeGap)):m)(i)(h)-b(m=>p=>p.position._1+p.size._1<=l?la(m)(p.position._1+p.size._1+ot(t.nodeGap)):m)(0)(h)?T("Just",E(a.id,E(f,a.size._2))):y}if(_.tag==="Nothing")return y;c()}if(u.tag==="Nothing")return y;c()}if(s.tag==="Nothing")return y;c()})(e.nodes))},L3=t=>e=>{const n=Wh(t)(e),r=C3(t)(e)(n),o=Oh(t)({...e,nodes:Y(i=>{const a=vo(i.id)(r);if(a.tag==="Just")return{...i,size:a._1};if(a.tag==="Nothing")return i;c()})(e.nodes)})(n.pipeline);return r.tag==="Leaf"?n:o},k3=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},da=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},S3=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},qh=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},E3=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Vh=t=>Bn(re(Er(e=>e===" ")(re(Er(e=>e===" ")(Xn(t)).rest)).rest)),R3=t=>b(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?T("Just",n._1):e)(y)(Dt(mn)(t)),B_=t=>e=>{if(t<=0)return[e];if(In(e)<=t)return[e];const n=Xn(e),r=t<1?[]:Bt(0,t,n),o=R3(r);if(o.tag==="Just"){const i=Vh(Ef(!(o._1>=0&&o._1<r.length)||r[o._1]===" "?o._1:o._1+1|0)(e)),a=Vh(Qi(o._1+1|0)(e));return a===""?[i]:[i,...B_(t)(a)]}if(o.tag==="Nothing"){const i=Ef(t)(e),a=Qi(t)(e);return a===""?[i]:[i,...B_(t)(a)]}c()},P3={cellW:7,cellH:3,maxLineWidth:20},G3=t=>e=>{const n=Y(i=>E((()=>{if(i.label.tag==="Just")return i.label._1;if(i.label.tag==="Nothing")return i.id;c()})(),i))(e.nodes),r=da(1)(Lr((S3(t.maxLineWidth)(b(i=>a=>da(i)(In(a._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),o=(r*t.cellW|0)-1|0;return{...e,nodes:Y(i=>{const a=St($i(`
|
|
7
|
-
`)(i._1))(
|
|
8
|
-
`)(t),n=e.length===0?[""]:e;return n.length*I_(1)(b(r=>o=>I_(r)(In(o)))(0)(n))|0},j3=t=>{const e=It(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return"";if(e.tag==="Just")return b(n=>r=>Zh(r)>Zh(n)?r:n)(e._1.head)(e._1.tail);c()},tL=t=>e=>j3(Yh(t)(e.id)((()=>{if(e.label.tag==="Just")return e.label._1;if(e.label.tag==="Nothing")return e.id;c()})())),jh=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,wt("Cons",n._4,e(n._6,r)));c()};return Mt(ce.foldr,e(t.interiors,A))},eL=t=>ns(ht(e=>T("Just",E(e.edge,{id:e.edge,from:{node:e.from,port:y},to:{node:e.to,port:y},label:y})))(St(t.scenes)(e=>e.tag==="DataFlow"?ht(n=>n.kind.tag==="SendToken"?T("Just",n.kind._1):y)(e._1.events):[]))),tp=t=>{const e=Cx(t),n=Y(o=>({...o,label:T("Just",tL(t)(o))}))(_t(o=>F3(o.id)(e.nodes),t.graph.nodes)),r=_t(o=>D3(o.id)(e.edges),t.graph.edges);return{nodes:[...n,...Y(X3)(Mt(wn.foldr,Kn(B.compare,e.nodes,M3(Y(o=>o.id)(n)))))],edges:[...r,...ht(K3(t)(eL(t)))(Mt(wn.foldr,Kn(B.compare,e.edges,Q3(Y(o=>o.id)(r)))))],constraints:t.graph.constraints}},nL=t=>{const e=rs(n=>{const r=rs(ml(pl))(Yh(t)(n.id)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;c()})()));return()=>{const o=r();return E(n.id,b(oo)(0)(o))}})(tp(t).nodes);return()=>{const n=e();return os(n)}},ep=t=>{const e=nL(t);return()=>{const n=e(),r=rs(ep)(jh(t))();return b(H3)(n)(r)}},rL=t=>e=>n=>{const r=It(o=>y,o=>i=>T("Just",{head:o,tail:i}),n.segments);if(r.tag==="Nothing")return[];if(r.tag==="Just")return U3(e)([{x:r._1.head.start._1*t,y:r._1.head.start._2*t},...Y(o=>({x:o.end._1*t,y:o.end._2*t}))([r._1.head,...r._1.tail])]);c()},oL=t=>e=>{const n=os(Y(r=>E(r.id,r))(t.nodes));return{...e,nodes:Y(r=>{const o=li(r.id)(n);return o.tag==="Just"&&o._1.size._2===1?{...r,size:E(r.size._1,di(r.size._2)(ot(I_(1)(Lr(Jn((()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;c()})()).length+3|0,3))+(r.shape==="Cylinder"||r.shape==="Document"?1:0)|0)))}:r})(e.nodes)}},iL=t=>e=>n=>E(n.edge,rL(t)(e)(n)),aL=t=>e=>n=>r=>{const o=Y(Z3(ot(4)*t)(e)(n))(r.nodes),i=os(o),a=ns(Y(iL(t)(Y(s=>s._2)(o)))(r.edges));return{nodes:i,edges:a,bounds:gl(i)(a),chipExtras:H,edgeLabels:H}},sL=t=>e=>({...V3(ns(Y(n=>E(n.id,E(n.from.node,n.to.node)))(e.edges)))(aL(8)(os(Y(n=>E(n.id,(()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;c()})()))(e.nodes)))(os(Y(n=>E(n.id,n.shape))(e.nodes)))(t.stretchNodes?L3(Hh)(e).result:Wh(Hh)(e).result)),edgeLabels:ns(ht(n=>n.label.tag==="Just"?T("Just",E(n.id,n.label._1)):y)(e.edges))}),uL=t=>b(e=>n=>{if(n.tag==="Structural")return e;if(n.tag==="DataFlow")return b(r=>o=>{if(o.kind.tag==="SendToken")return b(i=>a=>it(B)(a)()(i))(r)(o.kind._1.labels);if(o.kind.tag==="FillNodeWithoutTransition")return b(i=>a=>it(B)(a)()(i))(r)(o.kind._1.labels);c()})(e)(n._1.events);if(n.tag==="Hold"||n.tag==="EnterNode"||n.tag==="ExitNode"||n.tag==="StepScene")return e;c()})(H)(t.scenes),gL=t=>{const e=rs(n=>{const r=ml(pl)(n);return()=>{const o=r();return E(n,{labelW:o,charCount:In(jn(Ki(n))),lineCount:1})}})(Mt(wn.foldr,O3(St(Mt(wn.foldr,uL(t)))(Xh))));return()=>{const n=e();return W3(n)}},np=t=>{const e=gL(t);return()=>{const n=e(),r=rs(np)(jh(t))();return b($3)(n)(r)}},cL=ot(4)*8,_L=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[];c()}),fL=t=>e=>n=>{const r=o=>{const i=ht(a=>{const s=q3(a)(t);return s.tag==="Just"?T("Just",{w:s._1.labelW+28,h:ot(k3(1)(s._1.lineCount))*13.2+12}):y})(St(o)(Xh));return i.length===0?y:T("Just",{w:b(oo)(0)(Y(a=>a.w)(i)),h:b(oo)(0)(Y(a=>a.h)(i))})};return b(o=>i=>{if(i.kind.tag==="SendToken"){const a=A_(i.kind._1.edge)(n.edges),s=r(i.kind._1.labels);if(s.tag==="Just"&&a.tag==="Just"){const u=s._1;return Ht(B)(we)(i.kind._1.edge)(Y(g=>({x:g.x+14+u.w,y:g.y-6-8-u.h}))(a._1))(o)}return o}if(i.kind.tag==="FillNodeWithoutTransition"){const a=li(i.kind._1.node)(n.nodes),s=r(i.kind._1.labels);return s.tag==="Just"&&a.tag==="Just"?Ht(B)(we)("__fill__:"+i.kind._1.node)((()=>{const u=a._1.y-s._1.h-14,g=a._1.x+a._1.w/2,_=g-s._1.w/2,f=g+s._1.w/2,l=a._1.y-14;return[{x:_,y:u},{x:f,y:u},{x:_,y:l},{x:f,y:l}]})())(o):o}c()})(H)(_L(e))},rp=t=>e=>n=>{const r=tp(n);return{layout:(()=>{const o=sL(n)(oL(r)(B3(cL)(t)(G3(P3)(r))));return{...o,chipExtras:fL(e)(n)(o)}})(),interiors:(()=>{const o=rp(t)(e),i=a=>{if(a.tag==="Leaf")return H;if(a.tag==="Node")return ee("Node",a._1,a._2,a._3,o(a._4),i(a._5),i(a._6));c()};return i(n.interiors)})()}},op=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},z_=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=op(s._3)(n),g=(()=>{if(u.tag==="Just")return u._1;if(u.tag==="Nothing")return{x:s._4.x,y:s._4.y,vx:0,vy:0};c()})(),_=g.vx+(180*(s._4.x-g.x)-22*g.vx)*r,f=g.vy+(180*(s._4.y-g.y)-22*g.vy)*r;return it(B)(s._3)({x:g.x+_*r,y:g.y+f*r,vx:_,vy:f})(o(a,s._5))})(),s._6);c()},i=o(H,e);return{springs:i,applied:(()=>{const a=(s,u)=>{if(u.tag==="Leaf")return s;if(u.tag==="Node")return a((()=>{const g=a(s,u._5),_=op(u._3)(i);if(_.tag==="Just")return it(B)(u._3)({...u._4,x:_._1.x,y:_._1.y})(g);if(_.tag==="Nothing")return it(B)(u._3)(u._4)(g);c()})(),u._6);c()};return a(H,e)})()}},lL=t=>()=>t.clip("evenodd"),dL=t=>e=>()=>{t.filter=`blur(${e}px)`},hL=t=>e=>()=>{const n=e>0?t.canvas.width/e:1;t.setTransform(n,0,0,n,0,0)},pL=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)},mL=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()},F_=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},D_=t=>e=>n=>{const r=e.stroke;return()=>{const o=r.value,i=pf(t)(n);if(o!==n)return i(),e.stroke.value=n}},yL=t=>e=>n=>{const r=e.font;return()=>{const o=r.value,i=Jf(t)(n);if(o!==n)return i(),e.font.value=n}},is=t=>e=>n=>{const r=e.fill;return()=>{const o=r.value,i=hf(t)(n);if(o!==n)return i(),e.fill.value=n}},Wu=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=yf(t)((()=>{const g=i+1|0;return g>=0&&g<e.length?e[g]:0})())((()=>{const g=i+2|0;return g>=0&&g<e.length?e[g]:0})()),u=r(i+3|0);return()=>(s(),u())}if(a===2){const s=va(t)((()=>{const g=i+1|0;return g>=0&&g<e.length?e[g]:0})())((()=>{const g=i+2|0;return g>=0&&g<e.length?e[g]:0})()),u=r(i+3|0);return()=>(s(),u())}if(a===3){const s=La(t)({cpx:(()=>{const g=i+1|0;return g>=0&&g<e.length?e[g]:0})(),cpy:(()=>{const g=i+2|0;return g>=0&&g<e.length?e[g]:0})(),x:(()=>{const g=i+3|0;return g>=0&&g<e.length?e[g]:0})(),y:(()=>{const g=i+4|0;return g>=0&&g<e.length?e[g]:0})()}),u=r(i+5|0);return()=>(s(),u())}if(a===4){const s=Dy(t)({cp1x:(()=>{const g=i+1|0;return g>=0&&g<e.length?e[g]:0})(),cp1y:(()=>{const g=i+2|0;return g>=0&&g<e.length?e[g]:0})(),cp2x:(()=>{const g=i+3|0;return g>=0&&g<e.length?e[g]:0})(),cp2y:(()=>{const g=i+4|0;return g>=0&&g<e.length?e[g]:0})(),x:(()=>{const g=i+5|0;return g>=0&&g<e.length?e[g]:0})(),y:(()=>{const g=i+6|0;return g>=0&&g<e.length?e[g]:0})()}),u=r(i+7|0);return()=>(s(),u())}if(a===5){const s=xf(t),u=r(i+1|0);return()=>(s(),u())}return()=>{}},o=mf(t);return()=>(o(),r(0)())},xL=t=>e=>n=>r=>o=>i=>{const a=F_(i)(F_(r/2)(o/2)),s=yf(t)(e+a)(n);return()=>(s(),va(t)(e+r-a)(n)(),La(t)({cpx:e+r,cpy:n,x:e+r,y:n+a})(),va(t)(e+r)(n+o-a)(),La(t)({cpx:e+r,cpy:n+o,x:e+r-a,y:n+o})(),va(t)(e+a)(n+o)(),La(t)({cpx:e,cpy:n+o,x:e,y:n+o-a})(),va(t)(e)(n+a)(),La(t)({cpx:e,cpy:n,x:e+a,y:n})(),xf(t)())},wL=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),ip=t=>e=>{const n=Ay(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=wL();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0},groupAlpha:{value:1},alphaSaves:{value:[]}}}},JL={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},TL=t=>ue(t.weight)+" "+Ln(t.size)+"px "+t.family,Qr=t=>{const e=Ln(ot(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+")"},NL=t=>e=>n=>r=>{const o=gr(t);return()=>(o(),hL(t)(e.width)(),is(t)(n)(Qr(r))(),Gy(t)({x:0,y:0,width:e.width,height:e.height})(),cr(t)(),n.font.value="",n.fill.value="",n.stroke.value="")},bL=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",mL(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:Qr(n.bgColor),dotCss:Qr(n.dotColor),tile:n.tile,dotR:n.dotRadius,ox:n.origin.x,oy:n.origin.y})())},vL=t=>e=>n=>r=>{const o=is(t)(e)(Qr(r));return()=>(o(),Wu(t)(n)(),Yg(t)())},CL=t=>e=>n=>r=>o=>{const i=is(t)(e)(Qr(r));return()=>(i(),D_(t)(e)(Qr(o.color))(),Ss(t)(o.width)(),ac(t)((()=>{if(o.lineJoin==="RoundJoin")return ec;if(o.lineJoin==="BevelJoin")return tc;if(o.lineJoin==="MiterJoin")return nc;c()})())(),sc(t)((()=>{if(o.lineCap==="ButtCap")return ic;if(o.lineCap==="RoundCap")return rc;if(o.lineCap==="SquareCap")return oc;c()})())(),Wu(t)(n)(),Yg(t)(),Kg(t)())},LL=t=>e=>n=>r=>o=>i=>{const a=mf(t);return()=>{if(a(),xL(t)(n.x)(n.y)(n.w)(n.h)(r)(),o.tag==="Just"?(is(t)(e)(Qr(o._1.color))(),Yg(t)()):o.tag==="Nothing"||c(),i.tag==="Just")return D_(t)(e)(Qr(i._1.color))(),Ss(t)(i._1.width)(),ac(t)((()=>{if(i._1.lineJoin==="RoundJoin")return ec;if(i._1.lineJoin==="BevelJoin")return tc;if(i._1.lineJoin==="MiterJoin")return nc;c()})())(),sc(t)((()=>{if(i._1.lineCap==="ButtCap")return ic;if(i._1.lineCap==="RoundCap")return rc;if(i._1.lineCap==="SquareCap")return oc;c()})())(),Kg(t)();i.tag!=="Nothing"&&c()}},kL=t=>e=>n=>r=>{const o=D_(t)(e)(Qr(r.color));return()=>(o(),Ss(t)(r.width)(),ac(t)((()=>{if(r.lineJoin==="RoundJoin")return ec;if(r.lineJoin==="BevelJoin")return tc;if(r.lineJoin==="MiterJoin")return nc;c()})())(),sc(t)((()=>{if(r.lineCap==="ButtCap")return ic;if(r.lineCap==="RoundCap")return rc;if(r.lineCap==="SquareCap")return oc;c()})())(),Wu(t)(n)(),Kg(t)())},ap=t=>e=>n=>{const r=is(t)(e)(Qr(n.color));return()=>(r(),yL(t)(e)(TL(n.font))(),Yy(t)((()=>{if(n.align==="AlignLeft")return Wy;if(n.align==="AlignCenter")return qy;if(n.align==="AlignRight")return $y;c()})())(),Ky(t)((()=>{if(n.baseline==="BaselineTop")return My;if(n.baseline==="BaselineMiddle")return Qy;if(n.baseline==="BaselineAlphabetic")return Hy;if(n.baseline==="BaselineBottom")return Oy;c()})())(),Tf(t)(n.content)(n.x)(n.y)())},sp={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),a=o();return i(a)}},Functor0:()=>JL},SL={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>sp},EL=t=>e=>n=>{const r=F_(e.width/n.vw)(e.height/n.vh);return pL(t)(e.width)(r)((e.width-n.vw*r)/2-n.vx*r)((e.height-n.vh*r)/2-n.vy*r)},RL={pure:t=>e=>()=>t,Apply0:()=>sp},up={Applicative0:()=>RL,Bind1:()=>SL},M_={fillPath:t=>e=>n=>{const r=vL(n.ctx)(n.styleCache)(t)(e.color),o=n.maskDepth;return()=>{if(o.value===0)return r()}},strokePath:t=>e=>n=>{const r=kL(n.ctx)(n.styleCache)(t)(e),o=n.maskDepth;return()=>{if(o.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const o=CL(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=LL(o.ctx)(o.styleCache)(t)(e)(n)(r),a=o.maskDepth;return()=>{if(a.value===0)return i()}},drawText:t=>e=>{const n=ap(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=gr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Iy(n.ctx)(t)(),ap(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=gr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",wf(e.ctx)({translateX:t.tx,translateY:t.ty})(),Ca(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=gr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",wf(e.ctx)({translateX:t.tx,translateY:t.ty})(),Ca(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=gr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Wu(n.ctx)(t)(),e==="NonZero")return Py(n.ctx)();if(e==="EvenOdd")return lL(n.ctx)();c()}}},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=gr(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 bf(e.ctx)(Vy)();if(t==="Difference")return bf(e.ctx)(Uy)();c()}}},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=gr(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,Ry(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;c()}}},pushBlur:t=>e=>{const n=gr(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=dL(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=EL(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=NL(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=bL(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=Ec(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Rc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>zc,Monad0:()=>up},PL=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},as=t=>e=>n=>{const r=PL(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},Q_=t=>{const e=at.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;c()})(),r=at.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;c()},GL=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:Q_(t._2)};if(t._1==="ExtendFromTarget")return{lo:1-t._2,hi:1};c()}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}}c()},hi=t=>{if(t.tag==="Hidden")return{alpha:0,scale:1};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:t._1>0?1:0,scale:Uo(8)(.6)(Q_(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:Uo(8)(.6)(Q_(1-t._1))};c()};function BL(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function AL(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:BL(o,i)}}return n}function IL(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 gp(t,e){if(e.length===0)return[];const n=AL(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]=IL(n,e,i*r/t);return o}function zL(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 FL(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},g=e[(s+i)%n]||{x:0,y:0},_=u.x-g.x,f=u.y-g.y;a+=_*_+f*f}a<o&&(o=a,r=i)}return zL(r,e)}const cp=t=>e=>n=>{const r=gp(t,e),o=gp(t,n),i=FL(r,o);return{from:r,to:i}};function _p(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 DL(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 ML(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 QL(t){return t<0?0:t>1?1:t}const fp=t=>e=>n=>r=>{const o=e.length;if(o===0)return[];const i=_p(e),a=_p(n),s=DL(i,a),u=new Array(o);let g=1/0,_=-1/0;for(let d=0;d<o;d++){const h=e[d],m=(h.x-i.x)*s.x+(h.y-i.y)*s.y;u[d]=m,m<g&&(g=m),m>_&&(_=m)}const f=_-g;let l=new Array(o);for(let d=0;d<o;d++){const h=e[d],m=n[d];if(m===void 0){l[d]=h;continue}const p=f<=1e-4?0:r.maxDelay*(1-(u[d]-g)/f),x=Math.max(1e-4,1-p),w=QL((t-p)/x),J=w*w*(3-2*w);l[d]={x:h.x+(m.x-h.x)*J,y:h.y+(m.y-h.y)*J}}for(let d=0;d<r.smoothPasses;d++)l=ML(.5,l);return l},lp=(t,e)=>({tag:t,_1:e}),dp=(t,e)=>({tag:t,_1:e}),pe=(t,e,n)=>({tag:t,_1:e,_2:n}),hp=t=>t,$u=(t,e)=>({tag:t,_1:e}),qu=(t,e)=>({tag:t,_1:e}),Vu=t=>t,pi=t=>({tag:"FloorOverlay",_1:t}),Ae=(t,e,n)=>({tag:t,_1:e,_2:n}),Co=(t,e)=>({tag:t,_1:e}),ha=(t,e)=>({tag:t,_1:e}),pp=(t,e)=>({tag:t,_1:e}),mp=t=>t,yp=(t,e)=>({tag:t,_1:e}),mi=(t,e,n)=>({tag:t,_1:e,_2:n}),xp=t=>t,HL=t=>t,yi=xp("NormalTransform"),OL=xp("BakedTransform"),wp=mp("TokenOutside"),Jp=mp("TokenInside"),H_=ha("PlainText"),WL=Co("Watermark"),$L=Vu("NodeShadow"),qL=Vu("NodeDoorwayFrame"),Tp=Vu("NodeBody"),VL=Vu("NodeInversion"),O_=hp("LabelsShown"),Uu=hp("LabelsHidden"),mr={map:t=>e=>{if(e.tag==="BeginFrame")return Ae("BeginFrame",e._1,t(e._2));if(e.tag==="EndFrame")return Ae("EndFrame",t(e._1));if(e.tag==="BeginGroup")return Ae("BeginGroup",e._1,t(e._2));if(e.tag==="EndGroup")return Ae("EndGroup",e._1,t(e._2));if(e.tag==="Background")return Ae("Background",e._1,t(e._2));if(e.tag==="Overlay")return Ae("Overlay",e._1,t(e._2));if(e.tag==="Node")return Ae("Node",e._1,t(e._2));if(e.tag==="Edge")return Ae("Edge",e._1,t(e._2));if(e.tag==="Text")return Ae("Text",e._1,t(e._2));if(e.tag==="Token")return Ae("Token",e._1,t(e._2));if(e.tag==="AskInsideTokenStyle")return Ae("AskInsideTokenStyle",e._1,n=>t(e._2(n)));c()}},Np=t=>e=>yo(t)(e),UL=t=>{const e=t.Bind1().Apply0().Functor0(),n=Yw(t);return r=>o=>n(Uw()()()({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));c()},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));c()}}))(o)},KL=t=>j(st("Bind",{type:"scene",value:Ae("AskInsideTokenStyle",t,HL),map:mr.map},e=>j(st("Return",e),gt)),gt),bp=t=>j(st("Bind",{type:"scene",value:Ae("Background",t,void 0),map:mr.map},e=>j(st("Return",e),gt)),gt),vp=t=>j(st("Bind",{type:"scene",value:Ae("Edge",t,void 0),map:mr.map},e=>j(st("Return",e),gt)),gt),Ku=t=>j(st("Bind",{type:"scene",value:Ae("Node",t,void 0),map:mr.map},e=>j(st("Return",e),gt)),gt),xi=t=>j(st("Bind",{type:"scene",value:Ae("Overlay",t,void 0),map:mr.map},e=>j(st("Return",e),gt)),gt),wi=t=>j(st("Bind",{type:"scene",value:Ae("Text",t,void 0),map:mr.map},e=>j(st("Return",e),gt)),gt),Cp=t=>j(st("Bind",{type:"scene",value:Ae("Token",t,void 0),map:mr.map},e=>j(st("Return",e),gt)),gt),YL=t=>e=>j(st("Bind",{type:"scene",value:Ae("BeginFrame",t,void 0),map:mr.map},n=>j(st("Return",n),gt)),et("CatCons",()=>j(e._1,(()=>{if(e._2.tag==="CatNil")return et("CatCons",()=>j(st("Bind",{type:"scene",value:Ae("EndFrame",void 0),map:mr.map},n=>j(st("Return",n),gt)),gt),tt(A,A));if(e._2.tag==="CatCons")return et("CatCons",e._2._1,tt(e._2._2._1,wt("Cons",et("CatCons",()=>j(st("Bind",{type:"scene",value:Ae("EndFrame",void 0),map:mr.map},n=>j(st("Return",n),gt)),gt),tt(A,A)),e._2._2._2)));c()})()),tt(A,A))),Se=t=>e=>j(st("Bind",{type:"scene",value:Ae("BeginGroup",t,void 0),map:mr.map},n=>j(st("Return",n),gt)),et("CatCons",()=>{const n=()=>j(st("Bind",{type:"scene",value:Ae("EndGroup",t,void 0),map:mr.map},r=>j(st("Return",r),gt)),gt);return j(e._1,(()=>{if(e._2.tag==="CatNil")return et("CatCons",n,tt(A,A));if(e._2.tag==="CatCons")return et("CatCons",e._2._1,tt(e._2._2._1,wt("Cons",et("CatCons",n,tt(A,A)),e._2._2._2)));c()})())},tt(A,A))),Lo=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},W_=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},XL=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},ZL=t=>e=>{const n=Lo(0)(t.y+4-e.y)+Lo(0)(e.y+e.h-(t.y+t.h-4)),r=Lo(0)(t.x+4-e.x)+Lo(0)(e.x+e.w-(t.x+t.w-4));return r*e.h+n*e.w+r*n},jL=t=>e=>{const n=t.y+t.h-6,r=t.y+6,o=t.x+14,i=t.x+t.w-14,a=b(Lo)(0)(Y(s=>o-10<s.x+s.w+12&&i+10>s.x-12&&r-10<s.y+s.h+12&&n+10>s.y-12?W_((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}},tk=t=>e=>{const n=W_(t.x+t.w)(e.x+e.w)-Lo(t.x)(e.x),r=W_(t.y+t.h)(e.y+e.h)-Lo(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},Lp=t=>e=>n=>r=>{const o=t+4,i=Lo(0)(e-8),a=o+i-n;return n<=i?XL(o)(a)(r):t+(e-n)/2},$_=t=>e=>({...e,x:Lp(t.x)(t.w)(e.w)(e.x),y:Lp(t.y)(t.h)(e.h)(e.y)}),ek=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}]},nk=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*ZL(t)(o)+1e4*b(g=>_=>g+tk(o)(_))(0)(e)+.05*(u*u+a*a)+.01*(s*s+i*i)})()+(o.y>n.token.y?100:0)},rk=t=>e=>n=>r=>{const o=a=>{const s=$_(t)(a);return{rect:s,score:nk(t)(e)(n)(r)(s)}},i=It(a=>y,a=>s=>T("Just",{head:a,tail:s}),[r,n.rect,...ek(n)]);if(i.tag==="Nothing")return $_(t)(r);if(i.tag==="Just")return b(a=>s=>{const u=o(s);return u.score<a.score?u:a})(o(i._1.head))(i._1.tail).rect;c()},ok=t=>e=>n=>b(r=>o=>{const i=jL(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:rk(t)(r.obstacles)(o)(i);return{acc:it(B)(o.id)(a)(r.acc),obstacles:Et(r.obstacles)(a)}})({acc:H,obstacles:e})(n).acc,q_=t=>t,io=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ji=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},ik=Ii(Fg)(Qt),ak=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},sk=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},kp=q_("SegMove"),uk=q_("SegLine"),gk=q_("SegQuad"),Sp={offset:.4,passes:1,rMax:1.5},Ep=t=>he(sr(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,Yu=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},Xu=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},ao=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},ss=(()=>{const t=b(e=>n=>((e*31|0)+he(sr(n.x*100))|0)+he(sr(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),ck=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const o=n,i=r,a=o>=0&&o<t.length?T("Just",t[o]):y;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:kp,m:i,c:i,p:s,len:0}),r=s,n=o+3|0;continue}if(a._1===2){const s={x:(()=>{const _=o+1|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+2|0;return _>=0&&_<t.length?t[_]:0})()},u=s.x-i.x,g=s.y-i.y;e.push({kind:uk,m:i,c:i,p:s,len:qe(u*u+g*g)}),r=s,n=o+3|0;continue}if(a._1===3){const s={x:(()=>{const _=o+3|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+4|0;return _>=0&&_<t.length?t[_]:0})()},u=s.x-i.x,g=s.y-i.y;e.push({kind:gk,m:i,c:{x:(()=>{const _=o+1|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+2|0;return _>=0&&_<t.length?t[_]:0})()},p:s,len:qe(u*u+g*g)*1.05}),r=s,n=o+5|0;continue}if(a._1===5){e.push({kind:kp,m:i,c:i,p:i,len:0}),n=o+1|0;continue}n=t.length;continue}c()}return e},_k=t=>e=>{const n=e.length-1|0,r=n<1?[]:Bt(0,n,e),o=(()=>{const a=r.length-1|0;return a>=0&&a<r.length?T("Just",r[a]):y})(),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=qe(s*s+a*a);return u<=1e-4?e:Et((()=>{const g=e.length-1|0;return g<1?[]:Bt(0,g,e)})())({x:e[i].x+s/u*t,y:e[i].y+a/u*t})}return e},fk=t=>e=>n=>re(b(r=>o=>{const i=Pe(0)(t)(r.prng),a=Pe(0)(6.283185307179586)(i.prng);return{prng:a.prng,out:[{x:o.x+i.value*xn(a.value),y:o.y+i.value*tn(a.value)},...r.out]}})({prng:e,out:[]})(n).out),lk=t=>e=>n=>{if(e.kind==="SegMove")return Xu(t)(e.p);if(e.kind==="SegLine")return ao(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 ao(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});c()},dk=t=>e=>{if(e.kind==="SegMove")return Xu(t)(e.p);if(e.kind==="SegLine")return ao(t)(e.p);if(e.kind==="SegQuad")return Yu(t)(e.c)(e.p);c()},Rp=t=>e=>{const n=ck(e),r=b(s=>u=>s+u.len)(0)(n)*io(0)(Ji(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 g=n[s];dk(o)(g)(),i=u+g.len,a=s+1|0;continue}if(u>=r){a=n.length;continue}lk(o)(n[s])((r-u)/io(n[s].len)(1e-4))()}a=n.length}return o},Pp={offset:1.5,passes:2,rMax:14,overshoot:2.5},Gp=t=>e=>n=>r=>{const o=r.y-n.y,i=n.y-e.y,a=r.x-n.x,s=qe(a*a+o*o),u=n.x-e.x,g=qe(u*u+i*i),_=Ji(t.rMax*(fy(g>0&&s>0?io(-1)(Ji(1)((u*a+i*o)/(g*s))):1)/3.141592653589793))(.4*Ji(g)(s));return{inP:g>0?{x:n.x-u/g*_,y:n.y-i/g*_}:n,curr:n,outP:s>0?{x:n.x+a/s*_,y:n.y+o/s*_}:n}},Bp=t=>e=>{const n=e.length,r=[],o=0<e.length?T("Just",e[0]):y;if(o.tag==="Just"?Xu(r)(o._1)():o.tag==="Nothing"||c(),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 g=s-1|0;if(g>=0&&g<e.length){const _=Gp(t)(e[g])(e[s])(e[u]);ao(r)(_.inP)(),Yu(r)(_.curr)(_.outP)()}}a=s+1|0;continue}a=s+1|0}}const i=e.length-1|0;return i>=0&&i<e.length&&n>=2&&ao(r)(e[i])(),r},hk=t=>e=>n=>r=>o=>{if(o.length<4)return Bp(t)(o);const i=0<o.length?T("Just",o[0]):y,a=(()=>{if(i.tag==="Nothing")return{x:0,y:0};if(i.tag==="Just")return i._1;c()})(),s=o.length-1|0,u=fo(fo(e)(s)+s|0)(s),g=d=>{const h=fo(d+s|0)(s);return h>=0&&h<o.length?o[h]:a},_=Y(d=>Gp(t)(g((u+d|0)-1|0))(g(u+d|0))(g((u+d|0)+1|0)))(Ut(0,s-1|0)),f=[],l=0<_.length?T("Just",_[0]):y;if(l.tag==="Just")if(Xu(f)(l._1.outP)(),ik((()=>{const d=It(h=>y,h=>m=>T("Just",m),_);if(d.tag==="Nothing")return[];if(d.tag==="Just")return d._1;c()})())(d=>{const h=ao(f)(d.inP);return()=>(h(),Yu(f)(d.curr)(d.outP)())})(),n)ao(f)(l._1.inP)(),Yu(f)(l._1.curr)(l._1.outP)(),f.push(5);else{const d=_.length-1|0;d>=0&&d<_.length?ao(f)((()=>{const h=1-r;return{x:_[d].outP.x+(l._1.inP.x-_[d].outP.x)*h,y:_[d].outP.y+(l._1.inP.y-_[d].outP.y)*h}})())():ao(f)(l._1.inP)()}else l.tag==="Nothing"||c();return f},pa=t=>e=>n=>r=>{const o=ak(1)(r.length-1|0),i=Pe(0)(ot(o))(Ac("shape")(e)),a=sk(o-1|0)(he(sr(i.value))),s=i.prng;return Y(u=>{const g=Pe(0)(1)(Ac(ue(u))(s)),_=Pe(-.18)(.3)(g.prng),f=g.value<.7,l=Pe(.5)(.85)(_.prng),d=fk(t.offset)(l.prng)(r);return{path:n?hk(t)(a)(f)(_.value)(d):Bp(t)(d),alpha:l.value}})(Ut(0,t.passes-1|0))},pk=t=>e=>n=>pa(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}]),mk=t=>e=>n=>{const r=io(0)(Ji(1)(n)),o=e.h/ot(4),i=io(6)(o*1.4);return ht(a=>a)(Y(a=>{if(r<io(0)(ot(a)/ot(4)-.05))return y;const s=Ac(ue(a))(t),u=io(0)(ot(a)/ot(4)-.05),g=fo(a)(2)===0,_=g?e.x-2:e.x+e.w+2,f=g?e.x+e.w+2:e.x-2,l=e.y+(ot(a)+.5)*o;return T("Just",{path:Rp(io(0)(Ji(1)((r-u)/io(1e-4)(Ji(1)(ot(a+1|0)/ot(4)+.05)-u))))((()=>{const d={rMax:2,offset:.6,passes:1},h=re(b(p=>x=>{const w=Pe(-o*.08)(o*.08)(p.prng);return{prng:w.prng,out:[{x:_+(f-_)*(ot(x)/ot(4)),y:l+w.value},...p.out]}})({prng:s,out:[]})(Ut(0,4)).out),m=h.length<2?[]:pa(d)(s)(!1)(h);return 0<m.length?m[0].path:[]})()),width:i,alpha:1})})(Ut(0,3)))},V_=(t,e,n)=>({tag:t,_1:e,_2:n}),us=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Ap=t=>t,Zu=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},dn=(()=>{const t=un.unfoldr(Yn);return e=>t(gn("IterNode",e,Un))})(),yk=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Ti=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},me=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},xk=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},yr=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ni=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Hr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},wk=Qt.foldMap(vy),Ip=fe(B)(Qt),zp=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},gs=Vr.traverse(Zr),bi=b(ur)(0),Jk=sf(B),Tk=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=B.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}}c()}return o},U_=Ap("FullTokenGeometry"),Nk=Ap("ConvexInsideGeometry"),vi=t=>{const e=t.Apply0();return n=>b(r=>o=>e.apply(e.Functor0().map(i=>q1)(r))(n(o)))(t.pure())},nr=vi(Zr),Fp=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=as(o)(i)(r),g=0<t.length?T("Just",t[0]):y,_=(()=>{if(g.tag==="Just")return g._1;if(g.tag==="Nothing")return s;c()})(),f=t.length-1|0,l=f>=0&&f<t.length?T("Just",t[f]):y,d=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return a;c()})(),h=_.x-s.x,m=2*(()=>{const C=_.y-s.y;return(h<0?-h:h)+(C<0?-C:C)})(),p=d.x-a.x,x=2*(()=>{const C=d.y-a.y;return(p<0?-p:p)+(C<0?-C:C)})(),w=m+Ba(t)+x,J=w<=1e-4?1:1-x/w,N=w<=1e-4?0:m/w,k=J-N;return{progress:u,morphOutEnd:N,morphInStart:J,outT:(()=>{if(N<=1e-4)return 1;const C=u/N,R=C<0?0:C>1?1:C;return R*R*(3-2*R)})(),inT:(()=>{if(J>=1)return 0;const C=(u-J)/(1-J),R=C<0?0:C>1?1:C;return R*R*(3-2*R)})(),pathStart:_,pathEnd:d,travelPt:(()=>{const C=Zo(t)(Zu(0)(1)(k<=1e-4?0:(u-N)/k));if(C.tag==="Just")return C._1;if(C.tag==="Nothing")return _;c()})()}},Dp=t=>e=>n=>r=>o=>i=>{const a=Fp(t)(e)(n)(r)(o)(i),s=cp(128)(ei(4)(e))(Wl(a.pathStart)(6)),u=cp(128)(Wl(a.pathEnd)(6))(ei(4)(n)),g={maxDelay:.4,smoothPasses:2};return a.progress<a.morphOutEnd?mi("PolyShape",fp(a.outT)(s.from)(s.to)(g)):a.progress>=a.morphInStart?mi("PolyShape",fp(a.inT)(u.from)(u.to)(g)):mi("CircleShape",a.travelPt,6)},K_=t=>e=>n=>r=>o=>i=>{const a=Dp(t)(e)(n)(r)(o)(i);if(a.tag==="PolyShape")return Mc(a._1);if(a.tag==="CircleShape")return a._1;c()},bk=t=>{const e=n=>{const r=te(o=>n.x>=o._2.x-1&&n.x<=o._2.x+o._2.w+1&&n.y>=o._2.y-1&&n.y<=o._2.y+o._2.h+1)(dn(t.nodes));return r.tag==="Just"?T("Just",r._1._2):y};return n=>{const r=(()=>{if(0<n.length){const i=e(n[0]);if(i.tag==="Just")return re(ql(ei(7)(i._1))(re(n)))}return n})(),o=r.length-1|0;if(o>=0&&o<r.length){const i=e(r[o]);if(i.tag==="Just")return ql(ei(7)(i._1))(r)}return r}},Y_=t=>({nodes:t.nodes,edges:(()=>{const e=bk(t),n=r=>{if(r.tag==="Leaf")return H;if(r.tag==="Node")return ee("Node",r._1,r._2,r._3,e(r._4),n(r._5),n(r._6));c()};return n(t.edges)})()}),vk=t=>e=>{const n=((t.bg.r+t.bg.g|0)+t.bg.b|0)<384,r=n?90:104,o=n?165:122,i=a=>yk(255)(Ti(0)(he(Vn(o+r*tn(e+a)))));return{r:i(0),g:i(-2.0943951023931953),b:i(-4.1887902047863905),a:255}},Mp=t=>e=>{if(t<=0)return[];const n=It(r=>y,r=>o=>T("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return _n(n._1.head.text).length<=t?[n._1.head,...Mp(t-_n(n._1.head.text).length|0)(n._1.tail)]:[{...n._1.head,text:Ve(t)(n._1.head.text)}];c()},X_=(()=>{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:jr,nodeFill:Je,nodeStroke:jr,text:jr,edge:jr,arrowFill:jr,tokenOutsideFill:jr,tokenOutsideStroke:Je,tokenInside:Je,tokenInsideStroke:Je,tokenInsideBlend:au,tokenInsideAlpha:1,chipPillFill:jr,chipPillText:Je,chipHairline:{r:26,g:26,b:26,a:90},trailDot:jr,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:jr,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:Je,tokenOutsideStroke:Je,tokenInside:Je,tokenInsideStroke:Je,tokenInsideBlend:au,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:Je,chip:Je,chipShadow:{r:0,g:0,b:0,a:120},chipText:o,nodeFill:o,nodeStroke:Je,text:Je,edge:Je,arrowFill:Je,tokenOutsideFill:Je,tokenOutsideStroke:Je,tokenInside:Je,tokenInsideStroke:Je,tokenInsideBlend:Ll,tokenInsideAlpha:.35,chipPillFill:Je,chipPillText:o,chipHairline:{r:255,g:255,b:255,a:120},trailDot:Je,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:Ll,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:Je,tokenInside:Je,tokenInsideStroke:Je,tokenInsideBlend:au,tokenInsideAlpha:1,chipPillFill:a,chipPillText:Je,chipHairline:{r:60,g:66,b:78,a:90},trailDot:a,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};c()}})(),Z_=t=>e=>St(dn(t))(n=>{const r=me(n._1)(e.nodes);return r.tag==="Just"&&hi(r._1).alpha>0?wo(n._2):[]}),Ck=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,...Z_(e)(n)],Lk=t=>e=>n=>{const r=(o,i)=>he(Vn(ot(o)+(ot(i)-ot(o))*n));return{r:r(t.r,e.r),g:r(t.g,e.g),b:r(t.b,e.b),a:r(t.a,e.a)}},kk=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=Vr.traverse(r);return i=>a=>{const s=Xn(a),u=.32*i.size;return o(g=>n.bind(g===0?r.pure(0):t.measureText(i)(Ve(g)(a)))(_=>n.bind(t.measureText(i)(Ve(g+1|0)(a)))(f=>n.bind(t.measureInk(i)(g>=0&&g<s.length?An(s[g]):" "))(l=>r.pure({x:_,w:f-_,up:l.ascent-u,down:l.descent+u})))))(Ut(0,s.length-1|0))}},Qp=t=>[...wo({...t,x:t.x-1.25,y:t.y-1.25,w:t.w+2.5,h:t.h+2.5}),...wo({...t,y:t.y-5})],Sk=t=>e=>{const n=o=>(o.x-e.x)*(o.x-e.x)+(o.y-e.y)*(o.y-e.y),r=b(o=>i=>n(i)<n(o)?i:o)({x:t.x,y:t.y})([{x:t.x,y:t.y},{x:t.x+t.w,y:t.y},{x:t.x,y:t.y+t.h},{x:t.x+t.w,y:t.y+t.h}]);return Y(o=>{const i=ot(o)/5;return{x:r.x+(e.x-r.x)*i,y:r.y+(e.y-r.y)*i}})([1,2,3,4])},cs=t=>e=>n=>{const r=xk(ue(e)+":"+ue(n))(t);if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;c()},Ek=t=>e=>{const n=e.length;return b(r=>o=>b(i=>a=>it(B)(ue(o)+":"+ue(a))(a>=0&&a<e.length&&o>=0&&o<t.length?t[o]===e[a]?1+cs(i)(o+1|0)(a+1|0)|0:Ti(cs(i)(o+1|0)(a))(cs(i)(o)(a+1|0)):0)(i))(r)(n<=0?[]:re(Ut(0,n-1|0))))(H)((()=>{const r=t.length;return r<=0?[]:re(Ut(0,r-1|0))})())},j_=t=>Jn(t),Rk=t=>e=>n=>{const r=e*n;return Zu(0)(1)(r/t)},Pk=t=>e=>n=>r=>o=>i=>{const a=Fp(t)(e)(n)(r)(o)(i);return a.progress<a.morphOutEnd?V_("InsideRect",Fc(2)(e)):a.progress>=a.morphInStart?V_("InsideRect",Fc(2)(n)):V_("InsideBall",a.travelPt,6)},t1=t=>e=>n=>r=>o=>i=>a=>s=>{const u=(g,_)=>Cp({id:g,pass:t,geometry:pp("FlatToken",_),position:(()=>{if(_.tag==="CircleShape")return _._1;if(_.tag==="PolyShape")return Mc(_._1);c()})(),plan:yp("FlatTokenPlan",{wobble:n,fill:a,stroke:s})});return nr(g=>{if(g._2.tag==="Travelling"){const _=me(g._2._1.target)(r),f=me(g._2._1.source)(r);if(f.tag==="Just"&&_.tag==="Just"){const l=Hr(g._2._1.edge)(o);if(l.tag==="Just"){const d=(()=>{if(g._2._1.direction==="Forward")return l._1;if(g._2._1.direction==="Backward")return re(l._1);c()})();return u(g._1,(()=>{if(e==="FullTokenGeometry")return Dp(d)(f._1)(_._1)(g._2._1.progress)(g._2._1.holdPre)(g._2._1.holdPost);if(e==="ConvexInsideGeometry"){const h=Pk(d)(f._1)(_._1)(g._2._1.progress)(g._2._1.holdPre)(g._2._1.holdPost);if(h.tag==="InsideRect")return mi("PolyShape",Qc(4)(h._1));if(h.tag==="InsideBall")return mi("CircleShape",h._1,h._2)}c()})())}if(l.tag==="Nothing"){const d=as(g._2._1.holdPre)(g._2._1.holdPost)(g._2._1.progress),h={x:f._1.x+f._1.w/2,y:f._1.y+f._1.h/2},m={x:_._1.x+_._1.w/2,y:_._1.y+_._1.h/2};return Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",(()=>{if(d<.5){const x=d*2;return 1-yr(0)(Ni(1)(x))*yr(0)(Ni(1)(x))*(3-2*yr(0)(Ni(1)(x)))}const p=(d-.5)*2;return yr(0)(Ni(1)(p))*yr(0)(Ni(1)(p))*(3-2*yr(0)(Ni(1)(p)))})())]})(u(g._1,mi("CircleShape",d<.5?h:m,6)))}c()}return j(st("Return",void 0),gt)}if(g._2.tag==="Filling"){if(n)return j(st("Return",void 0),gt);const _=me(g._2._1.node)(r);if(_.tag==="Just")return u(g._1,mi("PolyShape",ei(4)(e==="ConvexInsideGeometry"?Fc(2)(_._1):_._1)));if(_.tag==="Nothing")return j(st("Return",void 0),gt);c()}return j(st("Return",void 0),gt)})(dn(i.tokens))},Gk=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0();return o=>n.bind((()=>{const i=r.pure();if(o.clear.tag==="Nothing")return i;if(o.clear.tag==="Just")return t.clearBackground(o.clear._1);c()})())(()=>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);c()}))},Hp=t=>e=>n=>r=>Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",n.fadeAlpha),pe("GroupTransform",yi,{tx:t.x*(1-n.popScale),ty:(t.y+t.h)*(1-n.popScale),sx:n.popScale,sy:n.popScale}),pe("GroupTransform",yi,{tx:0,ty:e.y*(1-n.flipY),sx:1,sy:n.flipY})]})(wi(r)),Bk=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const g=_=>f=>{const l=It(d=>y,d=>h=>T("Just",{head:d,tail:h}),f);if(l.tag==="Nothing")return j(st("Return",void 0),gt);if(l.tag==="Just"){const d=l._1,h=yo(i)(An(d.head)),m=p=>{const x=wi({owner:Co("NodeText",o),text:An(d.head),spec:{x:_,y:s-n*i.size*.11*tn(e*5-_*.22),content:An(d.head),font:i,color:Lk(r.text)(vk(r)(e*2.2+_*.16))(n),align:Gr,baseline:tr},bounds:y,plan:t});return j(x._1,(()=>{if(x._2.tag==="CatNil")return et("CatCons",()=>g(_+p)(d.tail),tt(A,A));if(x._2.tag==="CatCons")return et("CatCons",x._2._1,tt(x._2._2._1,wt("Cons",et("CatCons",()=>g(_+p)(d.tail),tt(A,A)),x._2._2._2)));c()})())};return j(h._1,(()=>{if(h._2.tag==="CatNil")return et("CatCons",m,tt(A,A));if(h._2.tag==="CatCons")return et("CatCons",h._2._1,tt(h._2._2._1,wt("Cons",et("CatCons",m,tt(A,A)),h._2._2._2)));c()})())}c()};return g(a)(Xn(u))},Op=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>a==="RunHighlight"||a==="RunBoldHighlight"||a==="RunCodeHighlight"||a==="RunCodeBoldHighlight"?Bk(t)(e)(n)(r)(o)(i)(s)(u)(g):wi({owner:Co("NodeText",o),text:g,spec:{x:s,y:u,content:g,font:i,color:r.text,align:Gr,baseline:tr},bounds:y,plan:t}),Ak=t=>e=>n=>r=>o=>i=>a=>{const s=jn(n);return Hp(o)(i)(a)({owner:Co("TokenText",t),text:s,spec:{x:i.x,y:i.y,content:s,font:{family:e.fontFamily,size:11,weight:500},color:e.chipText,align:Aa,baseline:tr},bounds:T("Just",o),plan:ha("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:nn,lineCap:zn},leader:[1,i.x,o.y+o.h,2,r.x+r.w/2,r.y]})})},Ik={offset:.8,passes:2,rMax:5},e1=t=>e=>n=>r=>Se({path:[],role:ln,layer:T("Just",rJ),effects:[pe("GroupClip",Ck(n)(t.nodes)(r),Gc)]})(t1(wp)(U_)(e.wobble)(t.nodes)(t.edges)(r)(e.tokenOutsideFill)(e.tokenOutsideStroke)),Wp=t=>e=>n=>r=>{if(n.tokenInsideBlend==="Difference"){const o=KL(e),i=a=>{const s=Se({path:[],role:ln,layer:T("Just",oJ),effects:[pe("GroupBlend",au),pe("GroupClip",Z_(t.nodes)(r),jo)]})(t1(Jp)(a==="ConvexAbsorb"?Nk:U_)(n.wobble)(t.nodes)(t.edges)(r)(n.tokenInside)(n.tokenInsideStroke)),u=()=>Se({path:[],role:ln,layer:T("Just",iJ),effects:[]})(nr(g=>{const _=me(g._1)(r.nodes);return _.tag==="Just"&&hi(_._1).alpha>0?xi(pi({path:wo(g._2),fill:T("Just",{color:Je,flat:!1}),stroke:y})):j(st("Return",void 0),gt)})(dn(t.nodes)));return j(s._1,(()=>{if(s._2.tag==="CatNil")return et("CatCons",u,tt(A,A));if(s._2.tag==="CatCons")return et("CatCons",s._2._1,tt(s._2._2._1,wt("Cons",et("CatCons",u,tt(A,A)),s._2._2._2)));c()})())};return j(o._1,(()=>{if(o._2.tag==="CatNil")return et("CatCons",i,tt(A,A));if(o._2.tag==="CatCons")return et("CatCons",o._2._1,tt(o._2._2._1,wt("Cons",et("CatCons",i,tt(A,A)),o._2._2._2)));c()})())}if(n.tokenInsideBlend==="Normal")return Se({path:[],role:ln,layer:y,effects:[pe("GroupClip",Z_(t.nodes)(r),jo),pe("GroupAlpha",n.tokenInsideAlpha)]})(t1(Jp)(U_)(n.wobble)(t.nodes)(t.edges)(r)(n.tokenInside)(n.tokenInsideStroke));c()},$p=t=>e=>n=>r=>t.strokePath((()=>{const o=It(i=>y,i=>a=>T("Just",{head:i,tail:a}),Y(i=>i.pt)(sy(i=>a=>{const s=ot(a)/ot(72),u=Pe(-.18)(.18)(i.prng),g=Pe(-.1)(.1)(u.prng),_=Pe(-.07)(.07)(g.prng),f=n*(.05+.55*s)*(1+g.value),l=s*28.274333882308138+u.value;return{prng:_.prng,pt:{x:e.x+xn(l)*f+_.value*n,y:e.y+tn(l)*f+_.value*n}}},{prng:137,pt:{x:e.x,y:e.y}},Ut(0,72))));if(o.tag==="Just")return[1,o._1.head.x,o._1.head.y,...wk(i=>[2,i.x,i.y])(o._1.tail)];if(o.tag==="Nothing")return[];c()})())({color:r,width:5.5,lineJoin:nn,lineCap:Br}),zk=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?$p(t)(n.geometry._1._1)(n.geometry._1._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath($l(n.geometry._1._1)(n.geometry._1._2))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:nn,lineCap:zn});if(n.geometry._1.tag==="PolyShape")return n.plan._1.wobble&&n.geometry._1._1.length>=3?$p(t)(Mc(n.geometry._1._1))(6)({r:200,g:35,b:30,a:220}):n.geometry._1._1.length>=3?t.fillStrokePath(Hl(n.geometry._1._1))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:nn,lineCap:zn}):e.pure();c()}return e.pure()}},Fk=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popClip,i=t.popTransform,a=t.popAlpha;return s=>u=>g=>_=>f=>{const l=hi(f),d=g*l.alpha,h={..._,y:_.y+5},m=_.x+_.w/2,p=_.y+_.h/2,x=Qp(h),w=r.bind(t.pushAlpha(d))(()=>r.bind(t.pushTransform({tx:m*(1-l.scale),ty:p*(1-l.scale),sx:l.scale,sy:l.scale}))(()=>r.bind(t.pushClip(x)(Gc))(()=>r.bind(ti(t)(h.shape)({x:h.x,y:h.y,w:h.w,h:h.h})(7)(T("Just",{color:s.shadowFill,flat:!0}))(y))(()=>r.bind((()=>{const J=r.bind(t.pushClip(wo(h))(jo))(()=>r.bind(t.backgroundDots({viewport:{vx:h.x,vy:h.y,vw:h.w,vh:h.h},bgColor:s.bgTransparent,dotColor:s.shadowDot,tile:1.6,dotRadius:.25,origin:{x:0,y:0}}))(()=>o));return u&&!s.wobble?J:n.pure()})())(()=>r.bind(ti(t)(h.shape)({x:h.x,y:h.y,w:h.w,h:h.h})(7)(y)(T("Just",{color:s.nodeStroke,width:1.25,lineJoin:nn,lineCap:zn})))(()=>r.bind(o)(()=>r.bind(i)(()=>a))))))));return d>0&&!s.wobble?w:n.pure()}},Dk=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=vi(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:nn,lineCap:Br}))(()=>r)))(mk(Ep(a)+7777|0)(a)(s))},Mk=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=e.Applicative0(),i=vi(o),a=t.popClip,s=vi(o),u=Vr.traverse(o),g=kk(t),_=Dk(t),f=t.popTransform;return l=>d=>h=>m=>p=>x=>w=>J=>N=>k=>{const C=F=>n.bind(t.pushAlpha(F.alpha))(()=>n.bind(t.strokePath(F.path)({color:h.nodeStroke,width:2,lineJoin:nn,lineCap:Br}))(()=>r)),R={family:h.fontFamily,size:h.wobble?15:11,weight:h.wobble?800:500},P=Jn(N.label===""?J:N.label),I=R.size*1.2,U=N.shape==="Cylinder"?t.strokePath(mJ({x:N.x,y:N.y,w:N.w,h:N.h}))({color:h.nodeStroke,width:1.25,lineJoin:nn,lineCap:zn}):o.pure(),S=(N.shape==="Cylinder"?(N.y+(N.y+N.h+5-2*Sn(N.h*.075)(N.w*.075)))/2:(N.y+N.y+N.h)/2)-ot(P.length)*I/2+I/2,v=k.tag==="PloppingOut"&&h.wobble?k._1:-1,D=v>=0,W=hi(k),M=D?{alpha:1,scale:1}:W,q=N.x+N.w/2,$=N.y+N.h/2,G=n.bind(t.pushAlpha(M.alpha))(()=>n.bind(t.pushTransform({tx:q*(1-M.scale),ty:$*(1-M.scale),sx:M.scale,sy:M.scale}))(()=>{const F={x:N.x,y:N.y,w:N.w,h:N.h},Q={color:h.nodeStroke,width:h.wobble?2:1.25*d,lineJoin:nn,lineCap:h.wobble?Br:zn},O=(()=>{if(h.wobble){if(N.shape==="Rectangle")return i(C)(pk(Pp)(Ep(F))(F));const z=ei(7)(N);return n.bind(i(C)((()=>{const X=ss(z);return z.length<4?[]:pa(Sp)(X)(!0)(z)})()))(()=>s(X=>i(C)((()=>{const V=ss(X);return X.length<2?[]:pa(Sp)(V)(!1)(X)})()))(N.shape==="Cylinder"?[EJ(N)]:[]))}return n.bind(ti(t)(N.shape)(F)(7)(y)(T("Just",Q)))(()=>U)})();return n.bind((()=>{if(p.tag==="Nothing")return n.bind(t.pushAlpha(m))(()=>n.bind(h.wobble?O:n.bind(ti(t)(N.shape)(F)(7)(T("Just",{color:h.nodeFill,flat:!1}))(T("Just",Q)))(()=>U))(()=>n.bind((()=>{if(w.tag==="Just"&&h.wobble&&!D){const z=w._1;return n.bind(u(g(R))(P))(X=>{const V=Rt(yt=>Ct=>at.compare(yt.x)(Ct.x)),K=he(sr(N.x*7919+N.y*3001))*-1640531535|0,Z=Pe(5)(7.5)(K),nt=Pe(0)(Z.value)(Z.prng),rt=-(1+2*Pe(-1)(1)(nt.prng).value*3.141592653589793/180),ft=(yt,Ct,Ot,Ft,se)=>V(ht(_e=>_e)([rt*Ct+yt>=Ft&&rt*Ct+yt<=se?T("Just",{x:Ct,y:rt*Ct+yt}):y,rt*Ot+yt>=Ft&&rt*Ot+yt<=se?T("Just",{x:Ot,y:rt*Ot+yt}):y,(()=>{const _e=(Ft-yt)/rt;return _e>=Ct&&_e<=Ot?T("Just",{x:_e,y:Ft}):y})(),(()=>{const _e=(se-yt)/rt;return _e>=Ct&&_e<=Ot?T("Just",{x:_e,y:se}):y})()])),Nt=Z.value,lt=fo(z.frameHash)(3),mt=lt===0?{r:200,g:35,b:30,a:220}:lt===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},vt=N.x+N.w/2,Wt=kn(Dt(yt=>Ct=>Dt((()=>{const Ot=S+ot(yt)*I,Ft=vt-b(se=>_e=>se+_e.w)(0)(Ct)/2;return se=>_e=>{const pn=R.size*.1,qt=se-1|0,jt=qt>=0&&qt<Ct.length&&se>0?(Ct[qt].x+Ct[qt].w+_e.x)/2:_e.x-pn;return{x:Ft+jt-1,y:Ot-_e.up-1,w:yr(0)((()=>{const an=se+1|0;return an>=0&&an<Ct.length&&se<(Ct.length-1|0)?(_e.x+_e.w+Ct[an].x)/2-jt:_e.x+_e.w+pn-jt})())+2,h:_e.up+_e.down+2}}})())(Ct))(X)),Tt=N.y+4,Vt=N.x+N.w-4,Gt=N.x+4,bt=Tt-rt*Gt+nt.value,pt=N.y+N.h-4,ct=St(St(Dt(yt=>Ct=>{const Ot=(Ct.from.x+Ct.to.x)/2,Ft=(Ct.from.y+Ct.to.y)/2,se=Pe(-1)(1)(K+(911*(yt+1|0)|0)|0),_e=Pe(-3)(5)(se.prng),pn=se.value*3.141592653589793/180,qt=xn(pn),jt=tn(pn),an=$e=>({x:Ot+($e.x-Ot)*qt-($e.y-Ft)*jt,y:Ft+($e.x-Ot)*jt+($e.y-Ft)*qt});return{from:(()=>{const $e=an(Ct.from),Wn=$e.y-Ft,$n=$e.x-Ot,Ze=qe($n*$n+Wn*Wn),ge=Ze<1e-4?1:(Ze+_e.value)/Ze;return{x:Ot+$n*ge,y:Ft+Wn*ge}})(),to:(()=>{const $e=an(Ct.to),Wn=Pe(-3)(5)(_e.prng).value,$n=$e.y-Ft,Ze=$e.x-Ot,ge=qe(Ze*Ze+$n*$n),be=ge<1e-4?1:(ge+Wn)/ge;return{x:Ot+Ze*be,y:Ft+$n*be}})()}})(ht(yt=>{const Ct=ft(bt+ot(yt)*Nt,Gt,Vt,Tt,pt);return Ct.length===2?T("Just",{from:Ct[0],to:Ct[1]}):y})(Ut(0,Ti(1)(he(sr((pt-rt*Vt-bt)/Nt)))))))(yt=>_t(Ct=>Ct.to.x-Ct.from.x>1,b(Ct=>Ot=>St(Ct)(Ft=>{const se=ft(Ft.from.y-rt*Ft.from.x,Ot.x,Ot.x+Ot.w,Ot.y,Ot.y+Ot.h);return se.length===2?se[0].x>Ft.from.x+.001&&se[1].x<Ft.to.x-.001?[{from:Ft.from,to:se[0]},{from:se[1],to:Ft.to}]:se[0].x<=Ft.from.x+.001&&se[1].x<Ft.to.x-.001?[{from:se[1],to:Ft.to}]:se[0].x>Ft.from.x+.001&&se[1].x>=Ft.to.x-.001?[{from:Ft.from,to:se[0]}]:[]:[Ft]}))([yt])(Wt))))(yt=>(()=>{const Ct=yt.to.x-yt.from.x;return qe(2)*(Ct>=0?Ct:-Ct)<=28})()?[yt]:[{from:yt.from,to:{x:yt.from.x+(yt.to.x-yt.from.x)*.495,y:yt.from.y+(yt.to.y-yt.from.y)*.495}},{from:{x:yt.from.x+(yt.to.x-yt.from.x)*.505,y:yt.from.y+(yt.to.y-yt.from.y)*.505},to:yt.to}]),Jt=ct.length,At=yt=>yr(0)(Ni(1)(z.t*ot(Jt)-ot(yt)));return n.bind(t.pushClip(Hl(ei(7)(N)))(jo))(()=>n.bind(i(yt=>{const Ct=yt._1,Ot=Pe(1.4)(1.9)(K+(1303*(Ct+1|0)|0)|0),Ft=Pe(.35)(.8)(Ot.prng),se=i(_e=>n.bind(t.pushAlpha(_e.alpha*Ft.value))(()=>n.bind(t.strokePath(Rp(At(Ct))(_e.path))({color:mt,width:Ot.value,lineJoin:nn,lineCap:Br}))(()=>r)))(pa({...Pp,rMax:0,offset:.5})(K+(53*(Ct+1|0)|0)|0)(!1)([yt._2.from,yt._2.to]));return At(Ct)>0?se:o.pure()})(Dt(mn)(ct)))(()=>a))})}return o.pure()})())(()=>n.bind((()=>{if(l==="LabelsShown"){const z=n.bind(t.pushAlpha(x))(()=>n.bind(i(X=>t.drawText({x:N.x+N.w/2,y:S+ot(X._1)*I,content:X._2,font:R,color:h.text,align:Aa,baseline:tr}))(Dt(mn)(P)))(()=>r));return x>0?z:o.pure()}if(l==="LabelsHidden")return o.pure();c()})())(()=>n.bind((()=>{const z=_(h)(F)(v);return D?z:o.pure()})())(()=>r)))));if(p.tag==="Just"){const z=p._1;return n.bind((()=>{const X=n.bind(t.pushAlpha(m))(()=>n.bind(ti(t)(N.shape)(F)(7)(T("Just",{color:h.nodeFill,flat:!1}))(y))(()=>r));return m>0&&!h.wobble?X:o.pure()})())(()=>{const X=n.bind(t.pushAlpha(z))(()=>n.bind(O)(()=>r));return z>0?X:o.pure()})}c()})())(()=>n.bind(f)(()=>r))}));return M.alpha*yr(m)((()=>{if(p.tag==="Nothing")return m;if(p.tag==="Just")return p._1;c()})())>0?G:o.pure()}},qp=t=>e=>n=>r=>nr(o=>{const i=Hr(o._1)(r.edges);if(i.tag==="Just"){const a=Hr(o._1)(r.edgeFadeAlpha),s=(()=>{if(a.tag==="Nothing")return 1;if(a.tag==="Just")return a._1;c()})(),u=vp({id:o._1,geometry:lp("FlatRoute",(()=>{const g=Hr(o._1)(t.edges);if(g.tag==="Nothing")return o._2;if(g.tag==="Just")return g._1;c()})()),visible:GL(i._1),arrow:(()=>{const g=xr("conn:")(o._1);if(g.tag==="Just")return!1;if(g.tag==="Nothing")return!0;c()})(),settlingAtTarget:i._1.tag==="Extending"&&i._1._1==="ExtendFromSource",plan:dp("FlatEdgePlan",e)});return s===1?u:Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",s)]})(u)}if(i.tag==="Nothing")return j(st("Return",void 0),gt);c()})(dn(n.edges)),Qk=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popClip,i=t.popTransform,a=t.popAlpha;return s=>u=>g=>_=>f=>{const l=hi(f),d=g*l.alpha,h=_.x+_.w/2,m=_.y-5+_.h/2,p=Qp(_),x=r.bind(t.pushAlpha(d))(()=>r.bind(t.pushTransform({tx:h*(1-l.scale),ty:m*(1-l.scale),sx:l.scale,sy:l.scale}))(()=>r.bind(t.pushClip(p)(Gc))(()=>r.bind(ti(t)(_.shape)({x:_.x,y:_.y,w:_.w,h:_.h})(7)(T("Just",{color:s.shadowFill,flat:!0}))(y))(()=>r.bind((()=>{const w=r.bind(t.pushClip(wo(_))(jo))(()=>r.bind(t.backgroundDots({viewport:{vx:_.x,vy:_.y,vw:_.w,vh:_.h},bgColor:s.bgTransparent,dotColor:s.shadowDot,tile:1.6,dotRadius:.25,origin:{x:0,y:0}}))(()=>o));return u?w:n.pure()})())(()=>r.bind(ti(t)(_.shape)({x:_.x,y:_.y,w:_.w,h:_.h})(7)(y)(T("Just",{color:s.nodeStroke,width:1.25,lineJoin:nn,lineCap:zn})))(()=>r.bind(o)(()=>r.bind(i)(()=>a))))))));return d>0&&!s.wobble?x:n.pure()}},Hk=t=>{const e=Fk(t),n=Qk(t),r=Mk(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(Uu)(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);c()}return t.Monad0().Applicative0().pure()}},Ok=t=>e=>{const n=Xn(t),r=n.length,o=Xn(e),i=o.length,a=Ek(n)(o);return(s=>u=>g=>{let _=s,f=u,l=g,d=!0,h;for(;d;){const m=_,p=f,x=l;if(m>=r&&p>=i){d=!1,h=re(x);continue}if(m>=r){if(p>=0&&p<o.length){_=m,f=p+1|0,l=[us("DiffInsert",p,o[p]),...x];continue}d=!1,h=re(x);continue}if(p>=i){if(m>=0&&m<n.length){_=m+1|0,f=p,l=[us("DiffDelete",m,n[m]),...x];continue}d=!1,h=re(x);continue}if(p>=0&&p<o.length){if(m>=0&&m<n.length){if(n[m]===o[p]){_=m+1|0,f=p+1|0,l=[us("DiffKeep",m,p,n[m]),...x];continue}if(cs(a)(m+1|0)(p)>=cs(a)(m)(p+1|0)){_=m+1|0,f=p,l=[us("DiffDelete",m,n[m]),...x];continue}_=m,f=p+1|0,l=[us("DiffInsert",p,o[p]),...x];continue}d=!1,h=re(x);continue}d=!1,h=re(x)}return h})(0)(0)([])},Vp=t=>e=>n=>r=>o=>nr(i=>{if(t.tag==="Just"&&i._1===t._1)return j(st("Return",void 0),gt);const a=me(i._1)(o.nodes);if(a.tag==="Just"){const s=me(i._1)(o.nodeLabels),u=(()=>{if(s.tag==="Nothing")return i._2;if(s.tag==="Just"){if(s._1.tag==="StaticNodeLabel")return{...i._2,label:s._1._1===""?i._1:s._1._1};if(s._1.tag==="RelabelingNode")return{...i._2,label:(()=>{const g=s._1._1.progress<.5?s._1._1.oldLabel:s._1._1.newLabel;return g===""?i._1:g})()}}c()})();return Ku({id:i._1,role:$L,geometry:$u("FlatNode",{shape:u.shape,bounds:{x:u.x,y:u.y,w:u.w,h:u.h}}),alpha:(()=>{const g=me(i._1)(o.nodeFadeAlpha),_=(()=>{if(g.tag==="Nothing")return 1;if(g.tag==="Just")return g._1;c()})();return _<1?0:_})(),plan:qu("FlatNodePlan",{palette:e,label:(()=>{const g=me(i._1)(o.nodeLabels);if(g.tag==="Just"){if(g._1.tag==="StaticNodeLabel")return g._1._1===""?i._1:g._1._1;if(g._1.tag==="RelabelingNode"){const _=g._1._1.progress<.5?g._1._1.oldLabel:g._1._1.newLabel;return _===""?i._1:_}c()}if(g.tag==="Nothing")return u.label===""?i._1:u.label;c()})(),labelVisibility:Uu,inkBoost:n?1:0,labelAlpha:0,outlineAlpha:y,arrival:y,animState:a._1})})}if(a.tag==="Nothing")return j(st("Return",void 0),gt);c()})(dn(r.nodes)),Up=t=>{const e=n=>{if(n.tag==="Leaf")return H;if(n.tag==="Node")return ee("Node",n._1,n._2,n._3,$_({x:t.vx,y:t.vy,w:t.vw,h:t.vh})(n._4),e(n._5),e(n._6));c()};return e},Wk=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=vi(r);return i=>a=>s=>u=>g=>_=>{const f=_n(_).length,l=ot(f+1|0),d=p=>{const x=(s*l-ot(p))/1.5,w=x<0?0:x>1?1:x;return w*w*(3-2*w)},h=(p=>{let x=p,w=!0,J;for(;w;){const N=x;if(N>=f){w=!1,J=N;continue}if(d(N)>=1){x=N+1|0;continue}w=!1,J=N}return J})(0),m=h>=f?[]:Er(p=>d(p)>0)(Ut(h,f-1|0)).init;return n.bind((()=>{const p=t.drawText({x:u,y:g,content:Ve(h)(_),font:i,color:a,align:Gr,baseline:tr});return h>0?p:r.pure()})())(()=>o(p=>n.bind(t.measureText(i)(Ve(p)(_)))(x=>{const w=d(p);return t.drawText({x:u+x,y:g-(1-w)*10,content:Ve(1)(Qi(In(Ve(p)(_)))(_)),font:i,color:{...a,a:he(sr(w*ot(a.a)))},align:Gr,baseline:tr})}))(m))}},$k=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=vi(r),i=Wk(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);c()})())(()=>t.drawText(a.spec));if(a.plan.tag==="TokenTravelText"){const s=a.plan._1;return n.bind(o(u=>t.fillPath($l(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)(T("Just",s.fill))(y);c()})())(()=>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)(T("Just",s.shadowFill))(y))(()=>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)(T("Just",s.fill))(T("Just",s.stroke));c()})())(()=>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);c()}},qk=t=>e=>n=>r=>o=>i=>a=>{const s=jn(n.line);return Hp(r)(o)(i)({owner:Co("TokenText",t),text:s,spec:{x:o.x,y:o.y,content:s,font:{family:e.fontFamily,size:11,weight:500},color:e.chipPillText,align:Gr,baseline:tr},bounds:T("Just",r),plan:ha("TokenTravelText",{trail:Sk(r)(a),trailFill:{color:e.trailDot,flat:!0},radius:3,fill:{color:e.chipPillFill,flat:!0},textLeft:r.x+14,reveal:(()=>{const u=n.phaseInLabel/.45;return u<0?0:u>1?1:u})()})})},ju=t=>e=>n=>r=>{const o=Y(d=>ot(Ti(1)(_n(d).length)))(r),i=yr(1)(b(ur)(0)(o)),a=as(e)(n)(t),s=a*i,u=Ti(1)(r.length),g=(d=>h=>m=>{let p=d,x=h,w=m,J=!0,N;for(;J;){const k=p,C=x,R=It(P=>y,P=>I=>T("Just",{head:P,tail:I}),w);if(R.tag==="Nothing"){J=!1,N=Ti(0)(u-1|0);continue}if(R.tag==="Just"){if(C+R._1.head>=s){J=!1,N=k;continue}p=k+1|0,x=C+R._1.head,w=R._1.tail;continue}c()}return N})(0)(0)(o),_=b(ur)(0)(g<1?[]:Bt(0,g,o)),f=_/i;if(g>=0&&g<o.length){const d=(_+o[g])/i;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(d<=f)return 1;const h=(a-f)/(d-f);return h<0?0:h>1?1:h})()}}const l=(_+1)/i;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(l<=f)return 1;const d=(a-f)/(l-f);return d<0?0:d>1?1:d})()}},Kp=t=>e=>n=>r=>o=>t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(ju(r)(0)(0)(Y(Ja)(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})}),Vk=t=>{const e=t.Bind1(),n=t.Applicative0(),r=Vr.traverse(n);return o=>i=>a=>e.Apply0().Functor0().map(s=>Ip(ht(u=>u)(s)))(r(s=>{if(s._2.tag==="Filling"&&s._2._1.labels.length!==0){const u=me(s._2._1.node)(i);if(u.tag==="Just")return e.bind(Kp(t)(o)(u._1)(s._2._1.progress)(s._2._1.labels))(g=>n.pure(T("Just",E(s._1,g))));if(u.tag==="Nothing")return n.pure(y);c()}return n.pure(y)})(dn(a.tokens)))},Uk=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const g=K_(n)(r)(o)(i)(a)(s);return t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(ju(i)(a)(s)(St(u)(j_)).line))(_=>t.Applicative0().pure({x:g.x+14+_/2-_/2-14,y:g.y-6-8-6.6-6,w:_+28,h:25.2}))},Kk=t=>{const e=t.Bind1(),n=t.Applicative0(),r=Vr.traverse(n);return o=>i=>a=>s=>e.Apply0().Functor0().map(u=>Ip(ht(g=>g)(u)))(r(u=>{if(u._2.tag==="Travelling"&&u._2._1.labels.length!==0){const g=me(u._2._1.target)(i),_=me(u._2._1.source)(i),f=Hr(u._2._1.edge)(a);if(f.tag==="Just"&&_.tag==="Just"&&g.tag==="Just"){const l=(()=>{if(u._2._1.direction==="Forward")return f._1;if(u._2._1.direction==="Backward")return re(f._1);c()})(),d=K_(l)(_._1)(g._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost);return e.bind(Uk(t)(o)(l)(_._1)(g._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost)(u._2._1.labels))(h=>n.pure(T("Just",E(u._1,{id:u._1,rect:h,token:d}))))}}return n.pure(y)})(dn(s.tokens)))},Yp=t=>{const e=t.Bind1(),n=Kk(t),r=Vk(t);return o=>i=>a=>s=>e.bind(n(o)(a.nodes)(a.edges)(s))(u=>e.bind(r(o)(a.nodes)(s))(g=>t.Applicative0().pure(ok({x:i.vx,y:i.vy,w:i.vw,h:i.vh})([...ht(_=>{const f=me(_._1)(s.nodes);return f.tag==="Just"&&hi(f._1).alpha>0?T("Just",{x:_._2.x,y:_._2.y,w:_._2.w,h:_._2.h}):y})(dn(a.nodes)),...(()=>{const _=(f,l)=>{if(f.tag==="Leaf")return l;if(f.tag==="Node")return _(f._5,wt("Cons",f._4,_(f._6,l)));c()};return Mt(ce.foldr,_(g,A))})()])(ht(_=>zp(_)(u))((()=>{const _=f=>{if(f.tag==="Leaf")return H;if(f.tag==="Node")return ee("Node",f._1,f._2,f._3,void 0,_(f._5),_(f._6));c()};return Rt(B.compare)(Mt(wn.foldr,_(u)))})())))))},Yk=Yp(Lc),Xp=t=>{const e=Yp(t);return n=>r=>o=>e(n)(r)(Y_(o))},n1=t=>e=>n=>{const r=(e*ot(t+1|0)-ot(n))/1.5,o=r<0?0:r>1?1:r;return o*o*(3-2*o)},Zp=t=>e=>n=>{const r=Uo(6)(.55)(Zu(0)(1)((1-t)/.06)),o=t>.94,i=o&&n>1e-4,a=Uo(6)(.55)(Zu(0)(1)(t/.06)),s=t<.06,u=s&&e>1e-4,g=o&&n<=1e-4;return{popScale:u?a:i?r:1,flipY:s&&e<=1e-4?a:g?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})()}},tg=t=>e=>n=>r=>Se({path:[],role:ln,layer:T("Just",aJ),effects:[]})(nr((()=>{const o=t.nodes,i=t.edges;return a=>{if(a._2.tag==="Travelling"){if(a._2._1.labels.length!==0){const s=me(a._2._1.target)(o),u=me(a._2._1.source)(o),g=Hr(a._2._1.edge)(i),_=zp(a._1)(r);if(_.tag==="Just"&&g.tag==="Just"&&u.tag==="Just"&&s.tag==="Just")return qk(a._1)(e)(ju(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(St(a._2._1.labels)(j_)))(_._1)({x:_._1.x+_._1.w/2,y:_._1.y+_._1.h/2})(Zp(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost))(K_((()=>{if(a._2._1.direction==="Forward")return g._1;if(a._2._1.direction==="Backward")return re(g._1);c()})())(u._1)(s._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost))}return j(st("Return",void 0),gt)}if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const s=me(a._2._1.node)(o);if(s.tag==="Just"){const u=s._1,g=Kp(Lc)(Np)(u)(a._2._1.progress)(a._2._1.labels),_=f=>Ak(a._1)(e)(ju(a._2._1.progress)(0)(0)(St(a._2._1.labels)(j_)).line)(u)(f)({x:f.x+f.w/2,y:f.y+f.h/2})(Zp(a._2._1.progress)(0)(0));return j(g._1,(()=>{if(g._2.tag==="CatNil")return et("CatCons",_,tt(A,A));if(g._2.tag==="CatCons")return et("CatCons",g._2._1,tt(g._2._2._1,wt("Cons",et("CatCons",_,tt(A,A)),g._2._2._2)));c()})())}if(s.tag==="Nothing")return j(st("Return",void 0),gt);c()}return j(st("Return",void 0),gt)}})())(dn(n.tokens))),jp=t=>e=>n=>r=>{const o=Yk(Np)(n)(t)(r);return j(o._1,(()=>{if(o._2.tag==="CatNil")return et("CatCons",i=>tg(t)(e)(r)(i),tt(A,A));if(o._2.tag==="CatCons")return et("CatCons",o._2._1,tt(o._2._2._1,wt("Cons",et("CatCons",i=>tg(t)(e)(r)(i),tt(A,A)),o._2._2._2)));c()})())},Xk=t=>e=>n=>{const r={family:t.fontFamily,size:11,weight:500},o=i=>a=>s=>u=>g=>_=>{const f=It(d=>y,d=>h=>T("Just",{head:d,tail:h}),_),l=It(d=>y,d=>h=>T("Just",{head:d,tail:h}),g);if(l.tag==="Just"&&f.tag==="Just"){const d=wi({owner:Co("EdgeText",i),text:l._1.head.text,spec:{x:s,y:a.y+a.h/2,content:l._1.head.text,font:(()=>{const h=l._1.head.style==="RunCode"||l._1.head.style==="RunCodeBold"||l._1.head.style==="RunCodeHighlight"||l._1.head.style==="RunCodeBoldHighlight"?{...r,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:r;return l._1.head.style==="RunBold"||l._1.head.style==="RunCodeBold"||l._1.head.style==="RunBoldHighlight"||l._1.head.style==="RunCodeBoldHighlight"?{...h,weight:700}:h})(),color:t.chipPillText,align:Gr,baseline:tr},bounds:T("Just",a),plan:u?ha("RoundedText",{radius:3,fill:T("Just",{color:t.chipPillFill,flat:!0}),stroke:y}):H_});return j(d._1,(()=>{if(d._2.tag==="CatNil")return et("CatCons",()=>o(i)(a)(s+f._1.head)(!1)(l._1.tail)(f._1.tail),tt(A,A));if(d._2.tag==="CatCons")return et("CatCons",d._2._1,tt(d._2._2._1,wt("Cons",et("CatCons",()=>o(i)(a)(s+f._1.head)(!1)(l._1.tail)(f._1.tail),tt(A,A)),d._2._2._2)));c()})())}return j(st("Return",void 0),gt)};return nr(i=>{if(i._2===""||(()=>{const u=Hr(i._1)(n.edges);return u.tag==="Nothing"||!(u.tag==="Just"&&UT.eq(u._1)(xu))})())return j(st("Return",void 0),gt);const a=Hr(i._1)(e.edges),s=(()=>{if(a.tag==="Just")return Zo(a._1)(.5);if(a.tag==="Nothing")return y;c()})();if(s.tag==="Nothing")return j(st("Return",void 0),gt);if(s.tag==="Just"){const u=s._1,g=Zn(i._2),_=gs(l=>{const d=l.style==="RunCode"||l.style==="RunCodeBold"||l.style==="RunCodeHighlight"||l.style==="RunCodeBoldHighlight"?{...r,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:r;return yo(l.style==="RunBold"||l.style==="RunCodeBold"||l.style==="RunBoldHighlight"||l.style==="RunCodeBoldHighlight"?{...d,weight:700}:d)(l.text)})(g),f=l=>{const d=bi(l),h=d+12;return o(i._1)({x:u.x-h/2,y:u.y-8.5,w:h,h:17})(u.x-d/2)(!0)(g)(l)};return j(_._1,(()=>{if(_._2.tag==="CatNil")return et("CatCons",f,tt(A,A));if(_._2.tag==="CatCons")return et("CatCons",_._2._1,tt(_._2._2._1,wt("Cons",et("CatCons",f,tt(A,A)),_._2._2._2)));c()})())}c()})(dn(e.edgeLabels))},r1=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const g=Zn(u),_=l=>d=>h=>{const m=It(x=>y,x=>w=>T("Just",{head:x,tail:w}),h),p=It(x=>y,x=>w=>T("Just",{head:x,tail:w}),d);if(p.tag==="Just"&&m.tag==="Just"){const x=Op(t)(e)(n)(r)(o)((()=>{const w=p._1.head.style==="RunCode"||p._1.head.style==="RunCodeBold"||p._1.head.style==="RunCodeHighlight"||p._1.head.style==="RunCodeBoldHighlight"?{...i,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:i;return p._1.head.style==="RunBold"||p._1.head.style==="RunCodeBold"||p._1.head.style==="RunBoldHighlight"||p._1.head.style==="RunCodeBoldHighlight"?{...w,weight:700}:w})())(p._1.head.style)(l)(s)(p._1.head.text);return j(x._1,(()=>{if(x._2.tag==="CatNil")return et("CatCons",()=>_(l+m._1.head)(p._1.tail)(m._1.tail),tt(A,A));if(x._2.tag==="CatCons")return et("CatCons",x._2._1,tt(x._2._2._1,wt("Cons",et("CatCons",()=>_(l+m._1.head)(p._1.tail)(m._1.tail),tt(A,A)),x._2._2._2)));c()})())}return j(st("Return",void 0),gt)};if(g.length===1&&g[0].style==="RunText")return wi({owner:Co("NodeText",o),text:g[0].text,spec:{x:a,y:s,content:g[0].text,font:i,color:r.text,align:Aa,baseline:tr},bounds:y,plan:t});const f=gs(l=>{const d=l.style==="RunCode"||l.style==="RunCodeBold"||l.style==="RunCodeHighlight"||l.style==="RunCodeBoldHighlight"?{...i,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:i;return yo(l.style==="RunBold"||l.style==="RunCodeBold"||l.style==="RunBoldHighlight"||l.style==="RunCodeBoldHighlight"?{...d,weight:700}:d)(l.text)})(g);return j(f._1,(()=>{if(f._2.tag==="CatNil")return et("CatCons",l=>_(a-bi(l)/2)(g)(l),tt(A,A));if(f._2.tag==="CatCons")return et("CatCons",f._2._1,tt(f._2._2._1,wt("Cons",et("CatCons",l=>_(a-bi(l)/2)(g)(l),tt(A,A)),f._2._2._2)));c()})())},Zk=t=>e=>{const n=gs(r=>{const o=r.style==="RunCode"||r.style==="RunCodeBold"||r.style==="RunCodeHighlight"||r.style==="RunCodeBoldHighlight"?{...t,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:t;return yo(r.style==="RunBold"||r.style==="RunCodeBold"||r.style==="RunBoldHighlight"||r.style==="RunCodeBoldHighlight"?{...o,weight:700}:o)(r.text)})(Zn(e));return j(n._1,(()=>{if(n._2.tag==="CatNil")return et("CatCons",r=>j(st("Return",bi(r)),gt),tt(A,A));if(n._2.tag==="CatCons")return et("CatCons",n._2._1,tt(n._2._2._1,wt("Cons",et("CatCons",r=>j(st("Return",bi(r)),gt),tt(A,A)),n._2._2._2)));c()})())},t0=t=>e=>n=>r=>{const o=Jn(r===""?t:r),i=n.size*1.2,a=(e.shape==="Cylinder"?(e.y+(e.y+e.h+5-2*Sn(e.h*.075)(e.w*.075)))/2:(e.y+e.y+e.h)/2)-ot(o.length)*i/2+i/2,s=gs(Zk(n))(o),u=g=>j(st("Return",Dt(_=>f=>({line:jn(f),runs:Zn(f),left:_>=0&&_<g.length?e.x+e.w/2-g[_]/2:e.x+e.w/2-0,y:a+ot(_)*i}))(o)),gt);return j(s._1,(()=>{if(s._2.tag==="CatNil")return et("CatCons",u,tt(A,A));if(s._2.tag==="CatCons")return et("CatCons",s._2._1,tt(s._2._2._1,wt("Cons",et("CatCons",u,tt(A,A)),s._2._2._2)));c()})())},jk=t=>e=>n=>{const r=gs(o=>{const i=o.style==="RunCode"||o.style==="RunCodeBold"||o.style==="RunCodeHighlight"||o.style==="RunCodeBoldHighlight"?{...t,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:t;return yo(o.style==="RunBold"||o.style==="RunCodeBold"||o.style==="RunBoldHighlight"||o.style==="RunCodeBoldHighlight"?{...i,weight:700}:i)(o.text)})(Mp(e)(n));return j(r._1,(()=>{if(r._2.tag==="CatNil")return et("CatCons",o=>j(st("Return",bi(o)),gt),tt(A,A));if(r._2.tag==="CatCons")return et("CatCons",r._2._1,tt(r._2._2._1,wt("Cons",et("CatCons",o=>j(st("Return",bi(o)),gt),tt(A,A)),r._2._2._2)));c()})())},ma=t=>e=>n=>{const r=jk(t)(n)(e.runs);return j(r._1,(()=>{if(r._2.tag==="CatNil")return et("CatCons",o=>j(st("Return",e.left+o),gt),tt(A,A));if(r._2.tag==="CatCons")return et("CatCons",r._2._1,tt(r._2._2._1,wt("Cons",et("CatCons",o=>j(st("Return",e.left+o),gt),tt(A,A)),r._2._2._2)));c()})())},t5=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const g=u<0?0:u>1?1:u,_=yr(8)(i.size*.9),f=(m,p,x,w,J)=>{const N=Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",m)]})(Op(t)(e)(1)(n)(r)((()=>{const k=J==="RunCode"||J==="RunCodeBold"||J==="RunCodeHighlight"||J==="RunCodeBoldHighlight"?{...i,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:i;return J==="RunBold"||J==="RunCodeBold"||J==="RunBoldHighlight"||J==="RunCodeBoldHighlight"?{...k,weight:700}:k})())(J)(p)(x)(An(w)));return m>.001?N:j(st("Return",void 0),gt)},l=(m,p)=>{const x=_n(m.line).length;return n1(x)(g)((x-p|0)-1|0)},d=t0(r)(o)(i)(a),h=m=>{const p=t0(r)(o)(i)(s),x=w=>nr(J=>{const N=J>=0&&J<m.length?T("Just",m[J]):y,k=J>=0&&J<w.length?T("Just",w[J]):y;return nr(C=>{if(C.tag==="DiffKeep"){if(N.tag==="Just"){if(k.tag==="Just"){const R=k._1,P=N._1,I=ma(i)(P)(C._1),U=S=>{const v=ma(i)(R)(C._2),D=W=>f(1,S+(W-S)*g,P.y+(R.y-P.y)*g,C._3,(()=>{if(g<.5){const q=St(P.runs)($=>Do(_n($.text).length,$.style));return C._1>=0&&C._1<q.length?q[C._1]:Pr}const M=St(R.runs)(q=>Do(_n(q.text).length,q.style));return C._2>=0&&C._2<M.length?M[C._2]:Pr})());return j(v._1,(()=>{if(v._2.tag==="CatNil")return et("CatCons",D,tt(A,A));if(v._2.tag==="CatCons")return et("CatCons",v._2._1,tt(v._2._2._1,wt("Cons",et("CatCons",D,tt(A,A)),v._2._2._2)));c()})())};return j(I._1,(()=>{if(I._2.tag==="CatNil")return et("CatCons",U,tt(A,A));if(I._2.tag==="CatCons")return et("CatCons",I._2._1,tt(I._2._2._1,wt("Cons",et("CatCons",U,tt(A,A)),I._2._2._2)));c()})())}if(k.tag==="Nothing"){const R=N._1,P=ma(i)(R)(C._1),I=U=>{const S=l(R,C._1);return f(1-S,U,R.y-_*S,C._3,(()=>{const v=St(R.runs)(D=>Do(_n(D.text).length,D.style));return C._1>=0&&C._1<v.length?v[C._1]:Pr})())};return j(P._1,(()=>{if(P._2.tag==="CatNil")return et("CatCons",I,tt(A,A));if(P._2.tag==="CatCons")return et("CatCons",P._2._1,tt(P._2._2._1,wt("Cons",et("CatCons",I,tt(A,A)),P._2._2._2)));c()})())}c()}if(N.tag==="Nothing"){if(k.tag==="Just"){const R=k._1,P=ma(i)(R)(C._2),I=U=>{const S=n1(_n(R.line).length)(g)(C._2);return f(S,U,R.y-_*(1-S),C._3,(()=>{const v=St(R.runs)(D=>Do(_n(D.text).length,D.style));return C._2>=0&&C._2<v.length?v[C._2]:Pr})())};return j(P._1,(()=>{if(P._2.tag==="CatNil")return et("CatCons",I,tt(A,A));if(P._2.tag==="CatCons")return et("CatCons",P._2._1,tt(P._2._2._1,wt("Cons",et("CatCons",I,tt(A,A)),P._2._2._2)));c()})())}if(k.tag==="Nothing")return j(st("Return",void 0),gt)}c()}if(C.tag==="DiffDelete"){if(N.tag==="Just"){const R=N._1,P=ma(i)(R)(C._1),I=U=>{const S=l(R,C._1);return f(1-S,U,R.y-_*S,C._2,(()=>{const v=St(R.runs)(D=>Do(_n(D.text).length,D.style));return C._1>=0&&C._1<v.length?v[C._1]:Pr})())};return j(P._1,(()=>{if(P._2.tag==="CatNil")return et("CatCons",I,tt(A,A));if(P._2.tag==="CatCons")return et("CatCons",P._2._1,tt(P._2._2._1,wt("Cons",et("CatCons",I,tt(A,A)),P._2._2._2)));c()})())}if(N.tag==="Nothing")return j(st("Return",void 0),gt);c()}if(C.tag==="DiffInsert"){if(k.tag==="Just"){const R=k._1,P=ma(i)(R)(C._1),I=U=>{const S=n1(_n(R.line).length)(g)(C._1);return f(S,U,R.y-_*(1-S),C._2,(()=>{const v=St(R.runs)(D=>Do(_n(D.text).length,D.style));return C._1>=0&&C._1<v.length?v[C._1]:Pr})())};return j(P._1,(()=>{if(P._2.tag==="CatNil")return et("CatCons",I,tt(A,A));if(P._2.tag==="CatCons")return et("CatCons",P._2._1,tt(P._2._2._1,wt("Cons",et("CatCons",I,tt(A,A)),P._2._2._2)));c()})())}if(k.tag==="Nothing")return j(st("Return",void 0),gt)}c()})(Ok((()=>{if(N.tag==="Nothing")return"";if(N.tag==="Just")return N._1.line;c()})())((()=>{if(k.tag==="Nothing")return"";if(k.tag==="Just")return k._1.line;c()})()))})(Ut(0,Ti(m.length)(w.length)-1|0));return j(p._1,(()=>{if(p._2.tag==="CatNil")return et("CatCons",x,tt(A,A));if(p._2.tag==="CatCons")return et("CatCons",p._2._1,tt(p._2._2._1,wt("Cons",et("CatCons",x,tt(A,A)),p._2._2._2)));c()})())};return j(d._1,(()=>{if(d._2.tag==="CatNil")return et("CatCons",h,tt(A,A));if(d._2.tag==="CatCons")return et("CatCons",d._2._1,tt(d._2._2._1,wt("Cons",et("CatCons",h,tt(A,A)),d._2._2._2)));c()})())},e0=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const g=hi(s),_=s.tag==="PloppingOut"&&n.wobble?{alpha:1,scale:1}:g,f=Jn((()=>{if(u.tag==="Just"){if(u._1.tag==="StaticNodeLabel")return u._1._1===""?i:u._1._1;if(u._1.tag==="RelabelingNode"){const w=u._1._1.progress<.5?u._1._1.oldLabel:u._1._1.newLabel;return w===""?i:w}c()}if(u.tag==="Nothing")return a.label===""?i:a.label;c()})()),l={family:n.fontFamily,size:n.wobble?15:11,weight:n.wobble?800:500},d=l.size*1.2,h=(a.shape==="Cylinder"?(a.y+(a.y+a.h+5-2*Sn(a.h*.075)(a.w*.075)))/2:(a.y+a.y+a.h)/2)-ot(f.length)*d/2+d/2,m=(w,J)=>{const N=Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",w)]})(nr(k=>r1(t)(e)(1)(n)(i)(l)(a.x+a.w/2)(h+ot(k._1)*d)(k._2))(Dt(mn)(Jn(J))));return w>.001?N:j(st("Return",void 0),gt)},p=(w,J)=>nr(N=>r1(t)(e)(w)(n)(i)(l)(a.x+a.w/2)(h+ot(N._1)*d)(N._2))(Dt(mn)(Jn(J))),x=Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",_.alpha*r),pe("GroupTransform",yi,{tx:(a.x+a.w/2)*(1-_.scale),ty:(a.y+a.h/2)*(1-_.scale),sx:_.scale,sy:_.scale}),pe("GroupAlpha",o)]})((()=>{if(u.tag==="Just"&&u._1.tag==="RelabelingNode"&&jn(u._1._1.oldLabel)===jn(u._1._1.newLabel)&&!oe(w=>oe(J=>J.style==="RunHighlight"||J.style==="RunBoldHighlight"||J.style==="RunCodeHighlight"||J.style==="RunCodeBoldHighlight",Zn(w)),Jn(u._1._1.oldLabel))&&oe(w=>oe(J=>J.style==="RunHighlight"||J.style==="RunBoldHighlight"||J.style==="RunCodeHighlight"||J.style==="RunCodeBoldHighlight",Zn(w)),Jn(u._1._1.newLabel)))return p(u._1._1.progress<0?0:u._1._1.progress>1?1:u._1._1.progress,u._1._1.newLabel);if(u.tag==="Just"&&u._1.tag==="RelabelingNode"&&jn(u._1._1.oldLabel)===jn(u._1._1.newLabel)&&oe(w=>oe(J=>J.style==="RunHighlight"||J.style==="RunBoldHighlight"||J.style==="RunCodeHighlight"||J.style==="RunCodeBoldHighlight",Zn(w)),Jn(u._1._1.oldLabel))&&!oe(w=>oe(J=>J.style==="RunHighlight"||J.style==="RunBoldHighlight"||J.style==="RunCodeHighlight"||J.style==="RunCodeBoldHighlight",Zn(w)),Jn(u._1._1.newLabel)))return p(u._1._1.progress<0?1:u._1._1.progress>1?0:1-u._1._1.progress,u._1._1.oldLabel);if(u.tag==="Just"&&u._1.tag==="RelabelingNode"){if(jn(u._1._1.oldLabel)===jn(u._1._1.newLabel)){const w=u._1._1,J=m(w.progress<0?1:w.progress>1?0:1-w.progress,w.oldLabel),N=()=>m(w.progress<0?0:w.progress>1?1:w.progress,w.newLabel);return j(J._1,(()=>{if(J._2.tag==="CatNil")return et("CatCons",N,tt(A,A));if(J._2.tag==="CatCons")return et("CatCons",J._2._1,tt(J._2._2._1,wt("Cons",et("CatCons",N,tt(A,A)),J._2._2._2)));c()})())}return t5(t)(e)(n)(i)(a)(l)(u._1._1.oldLabel)(u._1._1.newLabel)(u._1._1.progress)}return nr(w=>r1(t)(e)(1)(n)(i)(l)(a.x+a.w/2)(h+ot(w._1)*d)(w._2))(Dt(mn)(f))})());return o>0&&_.alpha*r>0?x:j(st("Return",void 0),gt)},n0=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>_=>f=>l=>{const d=Ku({id:g,role:t,geometry:$u("FlatNode",{shape:_.shape,bounds:{x:_.x,y:_.y,w:_.w,h:_.h}}),alpha:i,plan:qu("FlatNodePlan",{palette:o,label:(()=>{if(l.tag==="Just"){if(l._1.tag==="StaticNodeLabel")return l._1._1===""?g:l._1._1;if(l._1.tag==="RelabelingNode"){const m=l._1._1.progress<.5?l._1._1.oldLabel:l._1._1.newLabel;return m===""?g:m}c()}if(l.tag==="Nothing")return _.label===""?g:_.label;c()})(),labelVisibility:n,inkBoost:r,labelAlpha:s,outlineAlpha:a,arrival:u,animState:f})}),h=()=>{if(n==="LabelsHidden")return j(st("Return",void 0),gt);if(n==="LabelsShown")return e0(H_)(e)(o)(i)(s)(g)(_)(f)(l);c()};return j(d._1,(()=>{if(d._2.tag==="CatNil")return et("CatCons",h,tt(A,A));if(d._2.tag==="CatCons")return et("CatCons",d._2._1,tt(d._2._2._1,wt("Cons",et("CatCons",h,tt(A,A)),d._2._2._2)));c()})())},r0=t=>e=>n=>{const r={...t,nodeFill:t.text,text:t.nodeFill,nodeStroke:t.nodeFill};return nr(o=>{const i=me(o._1)(n.nodes),a=me(o._1)(e.nodes),s=a.tag==="Just"&&i.tag==="Just"?Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",o._2)]})(n0(VL)(n.animationTime)(O_)(1)(r)(1)(y)(1)(y)(o._1)((()=>{const u=me(o._1)(n.nodeLabels);if(u.tag==="Nothing")return a._1;if(u.tag==="Just"){if(u._1.tag==="StaticNodeLabel")return{...a._1,label:u._1._1===""?o._1:u._1._1};if(u._1.tag==="RelabelingNode")return{...a._1,label:(()=>{const g=u._1._1.progress<.5?u._1._1.oldLabel:u._1._1.newLabel;return g===""?o._1:g})()}}c()})())(i._1)(me(o._1)(n.nodeLabels))):j(st("Return",void 0),gt);return o._2>0?s:j(st("Return",void 0),gt)})(dn(n.nodeInvert))},e5=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>o=>{const i=o.length-1|0,a=i<1?[]:Bt(0,i,o),s=a.length-1|0,u=s>=0&&s<a.length?T("Just",a[s]):y,g=o.length-1|0,_=g>=0&&g<o.length?T("Just",o[g]):y;if(_.tag==="Just"&&u.tag==="Just"){const f=Pe(.78)(1.18)(ss(o)+19|0),l=Pe(.4)(.62)(f.prng),d=r.wobble?8.75*l.value:4.375,h=Pe(.4)(.62)(l.prng),m=r.wobble?8.75*h.value:4.375,p=_._1.y-u._1.y,x=_._1.x-u._1.x,w=qe(x*x+p*p),J=p/w,N=-J,k=x/w,C=_._1.x+k*.875,R=_._1.y+J*.875,P=r.wobble?8.75*f.value:8.75,I=C-k*P,U=R-J*P,S=I+N*d,v=U+k*d,D=I-N*m,W=U-k*m,M=[1,C,R,2,S,v,2,D,W,...xo],q={color:r.arrowFill,width:2,lineJoin:nn,lineCap:Br};return w<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,S,v,2,C,R])(q))(()=>t.strokePath([1,D,W,2,C,R])(q)):t.fillPath(M)({color:r.arrowFill,flat:!0})}return n.pure()}},n5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=vi(n),i=t.popAlpha,a=e5(t);return s=>u=>g=>_=>f=>{const l=Ol(8)(_),d=g&&(1-f.hi)*Ba(l)<=8.75?1:f.hi;if(d<=f.lo)return n.pure();const h=PJ(l)(f.lo)(d);if(h.length===0)return n.pure();const m={color:s.edge,width:s.wobble?2:.9375,lineJoin:nn,lineCap:Br},p=s.wobble?Pe(-10)(4)(ss(h)).value:0,x=s.wobble?_k(p)(h):h;return r.bind(s.wobble?o(w=>r.bind(t.pushAlpha(w.alpha))(()=>r.bind(t.strokePath(w.path)(m))(()=>i)))((()=>{const w=ss(h);return x.length<2?[]:pa(Ik)(w)(!1)(x)})()):t.strokePath(TJ(h))(m))(()=>{const w=a(s)(x);return u&&d>=.999?w:n.pure()})}},r5=t=>{const e=n5(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()},o5=t=>e=>{const n=i=>{const a=me(i)(t.nodes);if(a.tag==="Nothing")return!1;if(a.tag==="Just"){const s=a._1;return!oe(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,dn(t.edges))}c()},r=b(i=>a=>(i*31|0)+Xr(a)|0)(5381)(Xn(e.frameTitle)),o=i=>{const a=me(i)(t.nodes);if(a.tag==="Nothing")return!1;if(a.tag==="Just"){const s=a._1;return!oe(u=>{const g=u._2.length-1|0;return g>=0&&g<u._2.length&&u._2[g].x>=s.x&&u._2[g].x<=s.x+s.w&&u._2[g].y>=s.y&&u._2[g].y<=s.y+s.h},dn(t.edges))}c()};return b(i=>a=>{const s=a._2;return Jk(u=>{if(u.tag==="Nothing")return T("Just",s);if(u.tag==="Just")return T("Just",{t:yr(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});c()})(a._1)(i)})(H)(St(dn(e.tokens))(i=>{if(i._2.tag==="Filling"){const a=i._2._1.node;return[E(a,{t:1,angle:(()=>{const s=ht(u=>(()=>{const g=me(a)(t.nodes),_=u._2.length-1|0;return _>=0&&_<u._2.length&&g.tag==="Just"&&u._2[_].x>=g._1.x&&u._2[_].x<=g._1.x+g._1.w&&u._2[_].y>=g._1.y&&u._2[_].y<=g._1.y+g._1.h})()?T("Just",u._2):y)(dn(t.edges));if(0<s.length){const u=s[0].length-1|0,g=u<1?[]:Bt(0,u,s[0]),_=g.length-1|0;if(_>=0&&_<g.length){const f=s[0].length-1|0;return f>=0&&f<s[0].length?Qo(s[0][f].y-g[_].y)(s[0][f].x-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[E(i._2._1.target,{t:(i._2._1.progress-.75)/.25,angle:(()=>{const a=Hr(i._2._1.edge)(t.edges);if(a.tag==="Just"){const s=a._1.length-1|0,u=s<1?[]:Bt(0,s,a._1),g=u.length-1|0;if(g>=0&&g<u.length){const _=a._1.length-1|0;return _>=0&&_<a._1.length?Qo(a._1[_].y-u[g].y)(a._1[_].x-u[g].x):0}return a._1.length-1|0,0}if(a.tag==="Nothing")return 0;c()})(),bigCircle:n(i._2._1.target)||o(i._2._1.target),frameHash:r})];if(i._2._1.progress<.25)return[E(i._2._1.source,{t:i._2._1.progress/.25,angle:(()=>{const a=Hr(i._2._1.edge)(t.edges);if(a.tag==="Just")return 1<a._1.length&&0<a._1.length?Qo(a._1[1].y-a._1[0].y)(a._1[1].x-a._1[0].x):0;if(a.tag==="Nothing")return 0;c()})(),bigCircle:n(i._2._1.source)||o(i._2._1.source),frameHash:r})]}return[]}))},i5=t=>b(e=>n=>(e*31|0)+Xr(n)|0)(5381)(Xn(t.frameTitle)),o0=t=>e=>n=>r=>o=>i=>a=>{const s=i5(a),u=o5(i)(a);return nr(g=>{const _=me(g._1)(a.nodes);if(_.tag==="Just")return n0(Tp)(a.animationTime)(e)(r)(o)((()=>{const f=me(g._1)(a.nodeFadeAlpha);if(f.tag==="Nothing")return 1;if(f.tag==="Just")return f._1;c()})())(t(g._1))((()=>{const f=me(g._1)(a.nodeLabelFadeAlpha);if(f.tag==="Nothing")return n*1;if(f.tag==="Just")return n*f._1;c()})())((()=>{const f=me(g._1)(u);return f.tag==="Just"?T("Just",f._1):f.tag==="Nothing"&&Tk(g._1)(a.visited)?T("Just",{t:1,angle:0,bigCircle:!1,frameHash:s}):y})())(g._1)((()=>{const f=me(g._1)(a.nodeLabels);if(f.tag==="Nothing")return g._2;if(f.tag==="Just"){if(f._1.tag==="StaticNodeLabel")return{...g._2,label:f._1._1===""?g._1:f._1._1};if(f._1.tag==="RelabelingNode")return{...g._2,label:(()=>{const l=f._1._1.progress<.5?f._1._1.oldLabel:f._1._1.newLabel;return l===""?g._1:l})()}}c()})())(_._1)(me(g._1)(a.nodeLabels));if(_.tag==="Nothing")return j(st("Return",void 0),gt);c()})(dn(i.nodes))},a5=t=>e=>n=>{const r=ut.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=ut.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},i0=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},a0=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},o1=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},s5=Vr.traverse(Zr),u5=b(ur)(0),s0=Fo(Zr)(Qt),u0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},g5=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},i1=(()=>{const t=un.unfoldr(Yn);return e=>t(gn("IterNode",e,Un))})(),c5=t=>e=>{const n=tn(t.angle),r=xn(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},_5=t=>[t.box.ground.a,t.box.ground.b,t.box.ground.c,t.box.ground.d,t.box.top.a,t.box.top.b,t.box.top.c,t.box.top.d],a1=t=>e=>{const n=r=>a5(0)(255)(he(Vn(ot(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},on=t=>e=>n=>r=>({x:(e-n)*xn(t.angle),y:(e+n)*tn(t.angle)-r}),s1=t=>{const e=It(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(e._1.tail)(n=>[2,n.x,n.y]),5];c()},f5=t=>e=>n=>r=>o=>{const i=He(mn,o,Bt(1,o.length,o)),a=i.length-1|0;return Dt(s=>u=>({depth:(u._1.x+u._1.y+u._2.x+u._2.y)/2,draw:vp({id:n,geometry:lp("IsoSegments",[[on(t)(u._1.x)(u._1.y)(0),on(t)(u._2.x)(u._2.y)(0)]]),visible:{lo:0,hi:1},arrow:r&&s===a,settlingAtTarget:!1,plan:dp("IsoEdgePlan",{config:t,palette:e})})}))(i)},l5=t=>e=>n=>r=>o=>{const i=(()=>{if(t==="Forward")return o;if(t==="Backward")return re(o);c()})();if(0<i.length){const s=Zo(i)(i0(0)(1)(as(n)(r)(e)));if(s.tag==="Nothing")return i[0];if(s.tag==="Just")return s._1;c()}const a=Zo(i)(i0(0)(1)(as(n)(r)(e)));if(a.tag==="Nothing")return{x:0,y:0};if(a.tag==="Just")return a._1;c()},d5=t=>{const e=It(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(e._1.tail)(n=>[2,n.x,n.y])];c()},h5=t=>{const e=It(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{vx:0,vy:0,vw:0,vh:0};if(e.tag==="Just"){const n=b(r=>o=>({minX:a0(r.minX)(o.x),minY:a0(r.minY)(o.y),maxX:o1(r.maxX)(o.x),maxY:o1(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}}c()},p5=t=>e=>n=>{const r=n.id,o=n.np,i=Jn(o.label),a={family:e.fontFamily,size:11,weight:600},s=ot(i.length)*13.2,u=c5(t)(o.y+o.h),g=l=>d=>h=>m=>{const p=It(w=>y,w=>J=>T("Just",{head:w,tail:J}),m),x=It(w=>y,w=>J=>T("Just",{head:w,tail:J}),h);if(x.tag==="Just"&&p.tag==="Just"){const w=wi({owner:Co("NodeText",r),text:x._1.head.text,spec:{x:l,y:d,content:x._1.head.text,font:(()=>{if(x._1.head.style==="RunText")return a;if(x._1.head.style==="RunBold")return{...a,weight:700};if(x._1.head.style==="RunCode")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:400};if(x._1.head.style==="RunCodeBold")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:700};if(x._1.head.style==="RunHighlight")return a;if(x._1.head.style==="RunBoldHighlight")return{...a,weight:700};if(x._1.head.style==="RunCodeHighlight")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:400};if(x._1.head.style==="RunCodeBoldHighlight")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:700};c()})(),color:e.text,align:Gr,baseline:tr},bounds:y,plan:ha("AffineText",u)});return j(w._1,(()=>{if(w._2.tag==="CatNil")return et("CatCons",()=>g(l+p._1.head)(d)(x._1.tail)(p._1.tail),tt(A,A));if(w._2.tag==="CatCons")return et("CatCons",w._2._1,tt(w._2._2._1,wt("Cons",et("CatCons",()=>g(l+p._1.head)(d)(x._1.tail)(p._1.tail),tt(A,A)),w._2._2._2)));c()})())}return j(st("Return",void 0),gt)},_=Ku({id:r,role:Tp,geometry:$u("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:qu("IsoNodePlan",{config:t,palette:e})}),f=()=>s0(l=>{const d=l._1,h=Zn(l._2),m=s5(x=>yo((()=>{if(x.style==="RunText")return a;if(x.style==="RunBold")return{...a,weight:700};if(x.style==="RunCode")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:400};if(x.style==="RunCodeBold")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:700};if(x.style==="RunHighlight")return a;if(x.style==="RunBoldHighlight")return{...a,weight:700};if(x.style==="RunCodeHighlight")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:400};if(x.style==="RunCodeBoldHighlight")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:700};c()})())(x.text))(h),p=x=>g(o.x+o.w/2-u5(x)/2)(ot(d)*13.2-s/2+6.6)(h)(x);return j(m._1,(()=>{if(m._2.tag==="CatNil")return et("CatCons",p,tt(A,A));if(m._2.tag==="CatCons")return et("CatCons",m._2._1,tt(m._2._2._1,wt("Cons",et("CatCons",p,tt(A,A)),m._2._2._2)));c()})())})(Dt(mn)(i));return j(_._1,(()=>{if(_._2.tag==="CatNil")return et("CatCons",f,tt(A,A));if(_._2.tag==="CatCons")return et("CatCons",_._2._1,tt(_._2._2._1,wt("Cons",et("CatCons",f,tt(A,A)),_._2._2._2)));c()})())},m5=t=>{const e=t.Monad0(),n=e.Bind1();return r=>{if(r.geometry.tag==="IsoSlab"&&r.plan.tag==="IsoNodePlan"){const o=r.geometry._1,i=r.plan._1.palette,a=(s,u)=>t.fillStrokePath(s1(s))({color:u,flat:!0})({color:i.nodeStroke,width:1,lineJoin:nn,lineCap:zn});return n.bind(a(o.south,a1(.66)(i.nodeFill)))(()=>n.bind(a(o.east,a1(.82)(i.nodeFill)))(()=>a(o.top,i.nodeFill)))}return e.Applicative0().pure()}},y5=t=>{const e=t.Monad0(),n=e.Bind1();return r=>{if(r.geometry.tag==="IsoCube"&&r.plan.tag==="IsoTokenPlan"){const o=r.geometry._1,i=r.plan._1.palette,a=(s,u)=>t.fillStrokePath(s1(s))({color:a1(u)(i.tokenOutsideFill),flat:!0})({color:i.tokenOutsideStroke,width:1,lineJoin:nn,lineCap:zn});return n.bind(a(o.south,.66))(()=>n.bind(a(o.east,.82))(()=>a(o.top,1)))}return e.Applicative0().pure()}},x5={angle:.5235987755982988,boxHeight:26,transparentBg:!0},w5=t=>e=>n=>{const r=u0(t)(n.nodeLabels);if(r.tag==="Just"){if(r._1.tag==="StaticNodeLabel")return r._1._1===""?t:r._1._1;if(r._1.tag==="RelabelingNode"){const o=r._1._1.progress<.5?r._1._1.oldLabel:r._1._1.newLabel;return o===""?t:o}c()}if(r.tag==="Nothing")return e.label===""?t:e.label;c()},J5=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=on(t)(o)(i)(s),g=on(t)(o)(a)(s),_=on(t)(r)(a)(s),f=on(t)(o)(a)(e);return{south:[on(t)(r)(a)(e),f,g,_],east:[on(t)(o)(i)(e),f,g,u],top:[on(t)(r)(i)(s),u,g,_]}},T5=t=>e=>n=>r=>{const o=r._1,i=(a,s)=>({depth:s.x+s.y,draw:Cp({id:o,pass:wp,geometry:pp("IsoCube",J5(t)(a)(s)),position:s,plan:yp("IsoTokenPlan",{config:t,palette:e,baseZ:a})})});if(r._2.tag==="Travelling"){const a=g5(r._2._1.edge)(n.edges);return a.tag==="Just"?T("Just",i(0,l5(r._2._1.direction)(r._2._1.progress)(r._2._1.holdPre)(r._2._1.holdPost)(a._1))):y}if(r._2.tag==="Filling"){const a=u0(r._2._1.node)(n.nodes);if(a.tag==="Just")return T("Just",i(t.boxHeight,{x:a._1.x+a._1.w/2,y:a._1.y+a._1.h/2}))}return y},N5=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:on(t)(e.x)(e.y)(0),b:on(t)(r)(e.y)(0),c:on(t)(r)(n)(0),d:on(t)(e.x)(n)(0)},top:{a:on(t)(e.x)(e.y)(t.boxHeight),b:on(t)(r)(e.y)(t.boxHeight),c:on(t)(r)(n)(t.boxHeight),d:on(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},g0=t=>e=>Y(n=>({id:n._1,np:n._2,box:N5(t)(n._2)}))(i1(e.nodes)),b5=t=>e=>[...St(g0(t)(e))(_5),...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,wt("Cons",r._4,n(r._6,o)));c()};return St(Mt(ce.foldr,n(e.edges,A)))(Y(r=>on(t)(r.x)(r.y)(0)))})()],v5=t=>e=>n=>Y(r=>({...r,np:{...r.np,label:w5(r.id)(r.np)(n)}}))(g0(t)(e)),C5=t=>e=>n=>r=>{const o=X_(e),i=[...St(i1(n.edges))(u=>f5(t)(o)(u._1)((()=>{const g=xr("conn:")(u._1);if(g.tag==="Just")return!1;if(g.tag==="Nothing")return!0;c()})())(u._2)),...Y(u=>({depth:u.box.depth,draw:p5(t)(o)(u)}))(v5(t)(n)(r)),...ht(T5(t)(o)(n))(i1(r.tokens))],a=bp({viewport:h5(b5(t)(n)),clear:T("Just",t.transparentBg?o.bgTransparent:o.bg),dots:y}),s=()=>s0(u=>u.draw)(Rt(u=>g=>at.compare(u.depth)(g.depth))(i));return j(a._1,(()=>{if(a._2.tag==="CatNil")return et("CatCons",s,tt(A,A));if(a._2.tag==="CatCons")return et("CatCons",a._2._1,tt(a._2._2._1,wt("Cons",et("CatCons",s,tt(A,A)),a._2._2._2)));c()})())},L5=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=o1(1e-4)(qe(n*n+e*e)),o=e/r,i=n/r,a=t.to.y-o*7,s=t.to.x-i*7;return s1([t.to,{x:s-o*3,y:a+i*3},{x:s+o*3,y:a-i*3}])},k5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Fo(n)(Qt);return o=>{if(o.geometry.tag==="IsoSegments"&&o.plan.tag==="IsoEdgePlan"){const i=o.plan._1.palette,a=o.geometry._1;return e.Bind1().bind(r(s=>t.strokePath(d5(s))({color:i.edge,width:1.5,lineJoin:nn,lineCap:Br}))(a))(()=>{const s=a.length-1|0;if(s>=0&&s<a.length){const g=a[s],_=g.length-1|0,f=_<1?[]:Bt(0,_,g),l=f.length-1|0;if(l>=0&&l<f.length){const h=a.length-1|0,m=(()=>{if(h>=0&&h<a.length){const p=a[h],x=p.length-1|0;if(x>=0&&x<p.length)return t.fillPath(L5({from:f[l],to:p[x]}))({color:i.arrowFill,flat:!0})}return n.pure()})();return o.arrow?m:n.pure()}a.length-1|0;const d=n.pure();return o.arrow?d:n.pure()}a.length-1|0;const u=n.pure();return o.arrow?u:n.pure()})}return n.pure()}},c0=t=>t,Ue=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},ko=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},S5=c0("Split"),E5=c0("Fall"),hn=t=>e=>n=>r=>{const o=n?0:1,i=1-xe(r.x-o)*tn(e)*1.1,a=xe(i)<.06?i<0?-.06:.06:i,s=t.y+t.h/2,u=t.x+t.w/2;return{x:u+(t.x+(o+(r.x-o)*xn(e))*t.w-u)/a,y:s+(t.y+r.y*t.h-s)/a}},R5=t=>e=>n=>{const r=hn(t)(e)(n)({x:.5,y:.5}),o=t.x+.5*t.w,i=hn(t)(e)(n)({x:.5,y:0}),a=n?0:1,s=t.x+a*t.w,u=hn(t)(e)(n)({x:a,y:0}),g=hn(t)(e)(n)({x:a,y:1}),_=(g.y-u.y)/Ue(1e-6)(t.h),f=(g.x-u.x)/Ue(1e-6)(t.h),l=o-s,d=(i.y-u.y)/(xe(l)<1e-6?l<0?-1e-6:1e-6:l),h=t.y+t.h/2,m=t.x+t.w/2,p=o-s,x=(i.x-u.x)/(xe(p)<1e-6?p<0?-1e-6:1e-6:p);return{a:x,b:d,c:f,d:_,e:r.x-x*m-f*h,f:r.y-d*m-_*h}},u1=t=>{const e=Ue(0)(t)*3.05,n=xn(e);return{expansion:1+tn(e)*.16,verticalScale:xe(n)<.06?n<0?-.06:.06:n}},So=t=>e=>n=>{const r=u1(e),o=t.x+t.w/2,i=t.y+t.h;return{x:o+(t.x+n.x*t.w-o)*r.expansion,y:i+(t.y+n.y*t.h-i)*r.verticalScale}},P5=t=>e=>{const n=u1(e),r=So(t)(e)({x:.5,y:.5});return{a:n.expansion,b:0,c:0,d:n.verticalScale,e:r.x-n.expansion*(t.x+t.w/2),f:r.y-n.verticalScale*(t.y+t.h/2)}},G5=t=>Ue(0)(t.w)/Ue(1e-6)(Ue(0)(t.h))>=4?E5:S5,B5=t=>e=>n=>{const r=n/Ue(1e-6)(t.h),o=n/Ue(1e-6)(t.w),i=(s,u,g)=>{const _=So(t)(e)(s),f=So(t)(e)(u),l=So(t)(e)(g);return[4,_.x,_.y,f.x,f.y,l.x,l.y]},a=[...(()=>{const s=So(t)(e)({x:o,y:0});return[1,s.x,s.y]})(),...i({x:o*.44771525016920644,y:0},{x:0,y:r*.44771525016920644},{x:0,y:r}),...(()=>{const s=So(t)(e)({x:0,y:1-r});return[2,s.x,s.y]})(),...i({x:0,y:1-r*.44771525016920644},{x:o*.44771525016920644,y:1},{x:o,y:1}),...(()=>{const s=So(t)(e)({x:1-o,y:1});return[2,s.x,s.y]})(),...i({x:1-o*.44771525016920644,y:1},{x:1,y:1-r*.44771525016920644},{x:1,y:1-r}),...(()=>{const s=So(t)(e)({x:1,y:r});return[2,s.x,s.y]})(),...i({x:1,y:r*.44771525016920644},{x:1-o*.44771525016920644,y:0},{x:1-o,y:0}),...xo];return{face:a,labelAffine:P5(t)(e),labelVisible:u1(e).verticalScale>0,outline:a}},g1=t=>Uo(10.8)(.48)(ko(1)(Ue(0)(t)))/Uo(10.8)(.48)(1),A5=t=>e=>{const n=g1(ko(1)(Ue(0)((1-ko(1)(Ue(0)(t))-.48)/.5))*.48)/g1(.48);if(e<0){const r=ko(1)(Ue(0)((t-.25)/.28));return g1(r*r*r)}return ko(1)(xe(1-n))},I5=t=>A5((()=>{if(t.tag==="Closed")return 0;if(t.tag==="Opening")return t._1;if(t.tag==="Open")return 1;if(t.tag==="Closing")return 1-t._1;c()})())(t.tag==="Opening"?-1:t.tag==="Closing"?1:0),_0=t=>e=>n=>{const r=ko(1)(Ue(0)((n-t)/Ue(1e-6)(e-t)));return r*r*(3-2*r)},f0=t=>e=>n=>r=>{const o=n/Ue(1e-6)(t.h),i=n/Ue(1e-6)(t.w),a=_0(.08)(.2)(e),s=o*a,u=i*a,g=Ue(0)(e)*1.91986,_=(f,l,d)=>{const h=hn(t)(g)(r)(r?f:{...f,x:1-f.x}),m=hn(t)(g)(r)(r?l:{...l,x:1-l.x}),p=hn(t)(g)(r)(r?d:{...d,x:1-d.x});return[4,h.x,h.y,m.x,m.y,p.x,p.y]};return{leaf:{face:[...(()=>{const f={x:i,y:0},l=hn(t)(g)(r)(r?f:{...f,x:1-f.x});return[1,l.x,l.y]})(),..._({x:i*.44771525016920644,y:0},{x:0,y:o*.44771525016920644},{x:0,y:o}),...(()=>{const f={x:0,y:1-o},l=hn(t)(g)(r)(r?f:{...f,x:1});return[2,l.x,l.y]})(),..._({x:0,y:1-o*.44771525016920644},{x:i*.44771525016920644,y:1},{x:i,y:1}),...(()=>{const f={x:.5-u,y:1},l=hn(t)(g)(r)(r?f:{...f,x:1-f.x});return[2,l.x,l.y]})(),..._({x:.5-u*.44771525016920644,y:1},{x:.5,y:1-s*.44771525016920644},{x:.5,y:1-s}),...(()=>{const f={x:.5,y:s},l=hn(t)(g)(r)(r?f:{...f,x:.5});return[2,l.x,l.y]})(),..._({x:.5,y:s*.44771525016920644},{x:.5-u*.44771525016920644,y:0},{x:.5-u,y:0}),...xo],labelAffine:R5(t)(g)(r),labelVisible:xn(g)>0,outline:[...(()=>{const f={x:.5,y:s},l=hn(t)(g)(r)(r?f:{...f,x:.5});return[1,l.x,l.y]})(),..._({x:.5,y:s*.44771525016920644},{x:.5-u*.44771525016920644,y:0},{x:.5-u,y:0}),...(()=>{const f={x:i,y:0},l=hn(t)(g)(r)(r?f:{...f,x:1-f.x});return[2,l.x,l.y]})(),..._({x:i*.44771525016920644,y:0},{x:0,y:o*.44771525016920644},{x:0,y:o}),...(()=>{const f={x:0,y:1-o},l=hn(t)(g)(r)(r?f:{...f,x:1});return[2,l.x,l.y]})(),..._({x:0,y:1-o*.44771525016920644},{x:i*.44771525016920644,y:1},{x:i,y:1}),...(()=>{const f={x:.5-u,y:1},l=hn(t)(g)(r)(r?f:{...f,x:1-f.x});return[2,l.x,l.y]})(),..._({x:.5-u*.44771525016920644,y:1},{x:.5,y:1-s*.44771525016920644},{x:.5,y:1-s})]},seam:[...(()=>{const f={x:.5,y:s},l=hn(t)(g)(r)(r?f:{...f,x:.5});return[1,l.x,l.y]})(),...(()=>{const f={x:.5,y:1-s},l=hn(t)(g)(r)(r?f:{...f,x:.5});return[2,l.x,l.y]})()]}},z5=t=>e=>n=>{const r=_0(.08)(.26)(e),o=f0(t)(e)(n)(!1),i=f0(t)(e)(n)(!0);return{leaves:[i.leaf,o.leaf],seams:[{alpha:r,path:i.seam},{alpha:r,path:o.seam}]}},F5=t=>e=>n=>Ue(0)(ko(t)(ko(Ue(0)(e)/2)(Ue(0)(n)/2))),D5=t=>e=>n=>{const r=F5(n)(e.w)(e.h),o=I5(t),i=G5(e);if(i==="Fall")return{leaves:[B5(e)(o)(r)],seams:[]};if(i==="Split")return z5(e)(o)(r);c()},l0=(t,e)=>({tag:t,_1:e}),c1=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},M5=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},ya=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},_1=Ii(Zr)(Qt),Q5=l0("ResolvedLabels"),_s=t=>e=>{const n=c1(1)(e.rootLayout.bounds.w),r=e.portalState.tag==="Closed"&&e.levels.length===1,o=_r(e.rootLayout)(e.camera),i=r?1:M5(0)(1)(o.w/n),a=t.padding*i*i*(()=>{if(r)return 1;if(e.portalState.tag==="Opening"||e.portalState.tag==="Closing"){if(e.portalState.tag==="Closed")return 1;if(e.portalState.tag==="Opening")return 1-e.portalState._1;if(e.portalState.tag==="Open")return 0;if(e.portalState.tag==="Closing")return 1-(1-e.portalState._1);c()}return 0})();return(()=>{if(t.outputAspect.tag==="Nothing")return Cw;if(t.outputAspect.tag==="Just")return cl(t.outputAspect._1);c()})()({vx:o.x-a,vy:o.y-a,vw:o.w+2*a,vh:o.h+2*a})},H5=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=ya(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]}}c()},f1=t=>e=>{const n=Tw(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}},l1=t=>e=>t===""?j(st("Return",void 0),gt):wi({owner:WL,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:Gr,baseline:eJ},bounds:y,plan:H_}),O5=t=>e=>n=>r=>o=>i=>a=>s=>{const u=Y_(i),g=X_(t.theme),_=(()=>{if(s.tag==="ResolvedLabels")return jp(u)(g)(o)(a);if(s.tag==="SpringLabels")return tg(u)(g)(a)(Up(o)(s._1));c()})(),f=bp({viewport:o,clear:T("Just",t.transparentBg?g.bgTransparent:g.bg),dots:y}),l=()=>{const d=Se({path:[],role:ln,layer:y,effects:n<1?[pe("GroupAlpha",n)]:[]})((()=>{const h=qp(u)(g)(i)(a),m=()=>{const p=Vp(r)(g)(t.halftoneShadows)(i)(a),x=()=>{const w=o0(N=>r.tag!=="Nothing"&&r.tag==="Just"&&r._1===N?T("Just",0):y)(O_)(1)(1)(g)(i)(a),J=()=>{const N=r0(g)(i)(a),k=()=>{const C=e1(u)(g)(o)(a),R=()=>{const P=Wp(u)(cJ)(g)(a),I=()=>{const U=()=>{const S=Xk(g)(i)(a);return a.staticKind!=="Animated"?S:j(st("Return",void 0),gt)};return j(_._1,(()=>{if(_._2.tag==="CatNil")return et("CatCons",U,tt(A,A));if(_._2.tag==="CatCons")return et("CatCons",_._2._1,tt(_._2._2._1,wt("Cons",et("CatCons",U,tt(A,A)),_._2._2._2)));c()})())};return j(P._1,(()=>{if(P._2.tag==="CatNil")return et("CatCons",I,tt(A,A));if(P._2.tag==="CatCons")return et("CatCons",P._2._1,tt(P._2._2._1,wt("Cons",et("CatCons",I,tt(A,A)),P._2._2._2)));c()})())};return j(C._1,(()=>{if(C._2.tag==="CatNil")return et("CatCons",R,tt(A,A));if(C._2.tag==="CatCons")return et("CatCons",C._2._1,tt(C._2._2._1,wt("Cons",et("CatCons",R,tt(A,A)),C._2._2._2)));c()})())};return j(N._1,(()=>{if(N._2.tag==="CatNil")return et("CatCons",k,tt(A,A));if(N._2.tag==="CatCons")return et("CatCons",N._2._1,tt(N._2._2._1,wt("Cons",et("CatCons",k,tt(A,A)),N._2._2._2)));c()})())};return j(w._1,(()=>{if(w._2.tag==="CatNil")return et("CatCons",J,tt(A,A));if(w._2.tag==="CatCons")return et("CatCons",w._2._1,tt(w._2._2._1,wt("Cons",et("CatCons",J,tt(A,A)),w._2._2._2)));c()})())};return j(p._1,(()=>{if(p._2.tag==="CatNil")return et("CatCons",x,tt(A,A));if(p._2.tag==="CatCons")return et("CatCons",p._2._1,tt(p._2._2._1,wt("Cons",et("CatCons",x,tt(A,A)),p._2._2._2)));c()})())};return j(h._1,(()=>{if(h._2.tag==="CatNil")return et("CatCons",m,tt(A,A));if(h._2.tag==="CatCons")return et("CatCons",h._2._1,tt(h._2._2._1,wt("Cons",et("CatCons",m,tt(A,A)),h._2._2._2)));c()})())})());return n>0?j(d._1,(()=>{if(d._2.tag==="CatNil")return et("CatCons",()=>l1(t.watermark)(o),tt(A,A));if(d._2.tag==="CatCons")return et("CatCons",d._2._1,tt(d._2._2._1,wt("Cons",et("CatCons",()=>l1(t.watermark)(o),tt(A,A)),d._2._2._2)));c()})()):j(st("Return",void 0),et("CatCons",()=>l1(t.watermark)(o),tt(A,A)))};return j(f._1,(()=>{if(f._2.tag==="CatNil")return et("CatCons",l,tt(A,A));if(f._2.tag==="CatCons")return et("CatCons",f._2._1,tt(f._2._2._1,wt("Cons",et("CatCons",l,tt(A,A)),f._2._2._2)));c()})())},W5=t=>e=>n=>r=>o=>i=>{const a=i.segment.path.length-1|0,s=a>=0&&a<i.segment.path.length?T("Just",i.segment.path[a]):y;if(s.tag==="Nothing")return j(st("Return",void 0),gt);if(s.tag==="Just"){const u=ya(s._1)(o.segment.layout.nodes);if(u.tag==="Nothing")return j(st("Return",void 0),gt);if(u.tag==="Just"){const g=u._1,_=ya(s._1)(o.state.nodes),f=(()=>{if(_.tag==="Nothing")return e_;if(_.tag==="Just")return _._1;c()})(),l={color:t.nodeStroke,width:t.wobble?2:1.25,lineJoin:nn,lineCap:Br},d={...l,width:1.25},h=D5(r)({x:g.x,y:g.y,w:g.w,h:g.h})(7);return Se({path:o.segment.path,role:o.role,layer:y,effects:[pe("GroupAlpha",o.bgAlpha),pe("GroupTransform",yi,n)]})((()=>{const m=Ku({id:s._1,role:qL,geometry:$u("FlatNode",{shape:g.shape,bounds:{x:g.x,y:g.y+5,w:g.w,h:g.h}}),alpha:1,plan:qu("FlatNodePlan",{palette:t,label:g.label,labelVisibility:Uu,inkBoost:e?1:0,labelAlpha:0,outlineAlpha:T("Just",1),arrival:y,animState:f})}),p=()=>{const x=xi(pi({path:wo(g),fill:y,stroke:T("Just",l)})),w=()=>{const J=_1(h.leaves)(k=>{const C=Se({path:o.segment.path,role:o.role,layer:y,effects:[pe("GroupAlpha",1)]})(xi(pi({path:k.face,fill:T("Just",{color:t.nodeFill,flat:!1}),stroke:y}))),R=()=>{const P=Se({path:o.segment.path,role:o.role,layer:y,effects:[pe("GroupClip",k.face,jo)]})(e0(ha("AffineText",k.labelAffine))(o.state.animationTime)(t)(1)(1)(s._1)(g)(f)(ya(s._1)(o.state.nodeLabels)));return k.labelVisible?P:j(st("Return",void 0),gt)};return j(C._1,(()=>{if((()=>{if(C._2.tag==="CatNil"||C._2.tag==="CatCons")return!1;c()})())return et("CatCons",R,tt(A,A));if((()=>{if(C._2.tag==="CatNil"||C._2.tag==="CatCons")return!0;c()})())return et("CatCons",(()=>{if(C._2.tag==="CatNil")return()=>xi(pi({path:k.outline,fill:y,stroke:T("Just",l)}));if(C._2.tag==="CatCons")return C._2._1;c()})(),tt((()=>{if(C._2.tag==="CatNil")return A;if(C._2.tag==="CatCons")return C._2._2._1;c()})(),wt("Cons",et("CatCons",R,tt(A,A)),(()=>{if(C._2.tag==="CatNil")return A;if(C._2.tag==="CatCons")return wt("Cons",et("CatCons",()=>xi(pi({path:k.outline,fill:y,stroke:T("Just",l)})),tt(A,A)),C._2._2._2);c()})())));c()})())}),N=()=>_1(h.seams)(k=>{const C=Se({path:o.segment.path,role:o.role,layer:y,effects:[pe("GroupAlpha",k.alpha)]})(xi(pi({path:k.path,fill:y,stroke:T("Just",d)})));return k.alpha>0?C:j(st("Return",void 0),gt)});return j(J._1,(()=>{if(J._2.tag==="CatNil")return et("CatCons",N,tt(A,A));if(J._2.tag==="CatCons")return et("CatCons",J._2._1,tt(J._2._2._1,wt("Cons",et("CatCons",N,tt(A,A)),J._2._2._2)));c()})())};return j(x._1,(()=>{if(x._2.tag==="CatNil")return et("CatCons",w,tt(A,A));if(x._2.tag==="CatCons")return et("CatCons",x._2._1,tt(x._2._2._1,wt("Cons",et("CatCons",w,tt(A,A)),x._2._2._2)));c()})())};return j(m._1,(()=>{if(m._2.tag==="CatNil")return et("CatCons",p,tt(A,A));if(m._2.tag==="CatCons")return et("CatCons",m._2._1,tt(m._2._2._1,wt("Cons",et("CatCons",p,tt(A,A)),m._2._2._2)));c()})())})())}}c()},d1=t=>e=>n=>r=>_1(r.minis)(o=>{const i=d0(t)(e)(n)(xd)(H)(y)(r)(o);return(()=>{const a=o.segment.path.length-1|0;return o.bgAlpha>0&&a>=0&&a<o.segment.path.length&&(()=>{const s=ya(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;c()})()})()?i:j(st("Return",void 0),gt)}),d0=t=>e=>n=>r=>o=>i=>a=>s=>{const u=[1,e.viewport.vx,e.viewport.vy,2,e.viewport.vx+e.viewport.vw,e.viewport.vy,2,e.viewport.vx+e.viewport.vw,e.viewport.vy+e.viewport.vh,2,e.viewport.vx,e.viewport.vy+e.viewport.vh,5],g=s.state,_={tx:a.segment.placement.tx,ty:a.segment.placement.ty,sx:a.segment.placement.scale,sy:a.segment.placement.scale},f=X_(t.theme),l=s.segment.layout,d={vx:l.bounds.x-1e3,vy:l.bounds.y-1e3,vw:l.bounds.w+2e3,vh:l.bounds.h+2e3},h=Y_(l),m=s.segment.path.length-1|0,p=m>=0&&m<s.segment.path.length?ya(s.segment.path[m])(a.segment.layout.nodes):y,x=Rk(5)(11)(s.segment.placement.scale*n),w=x>0?O_:Uu,J=f1(e.viewport)(s),N=(()=>{if(w==="LabelsHidden")return j(st("Return",void 0),gt);if(w==="LabelsShown")return Se({path:s.segment.path,role:s.role,layer:y,effects:x<1?[pe("GroupAlpha",x)]:[]})(o.tag==="Leaf"?jp(h)(f)(J)(g):tg(h)(f)(g)(Up(J)(o)));c()})(),k={tx:s.segment.placement.tx,ty:s.segment.placement.ty,sx:s.segment.placement.scale,sy:s.segment.placement.scale},C=Se({path:s.segment.path,role:s.role,layer:y,effects:[pe("GroupAlpha",s.bgAlpha)]})((()=>{const P=Se({path:s.segment.path,role:s.role,layer:y,effects:[pe("GroupClip",(()=>{if(Cd(r)>=.52)return u;const U=H5(a)((()=>{const S=s.segment.path.length-1|0;return S>=0&&S<s.segment.path.length?T("Just",s.segment.path[S]):y})());return U.length===0?u:U})(),jo)]})((()=>{const U=(()=>{if(p.tag==="Just")return Se({path:a.segment.path,role:a.role,layer:y,effects:[pe("GroupTransform",yi,_)]})(xi(pi({path:wo({...p._1,x:p._1.x+1,y:p._1.y+1,w:p._1.w-2,h:p._1.h-2}),fill:T("Just",{color:f.bg,flat:!0}),stroke:y})));if(p.tag==="Nothing")return j(st("Return",void 0),gt);c()})(),S=(a.role==="Active"||a.role==="FlyThrough")&&!t.transparentBg?U:j(st("Return",void 0),gt),v=()=>{const D=Se({path:s.segment.path,role:s.role,layer:y,effects:[pe("GroupTransform",yi,k)]})((()=>{const M=qp(h)(f)(l)(g),q=()=>{const $=Vp(i)(f)(t.halftoneShadows)(l)(g),G=()=>{const F=o0(O=>i.tag!=="Nothing"&&i.tag==="Just"&&i._1===O?T("Just",0):y)(w)(x)(1)(f)(l)(g),Q=()=>{const O=r0(f)(l)(g);return j(O._1,(()=>{if(O._2.tag==="CatNil")return et("CatCons",()=>e1(h)(f)(d)(g),tt(A,A));if(O._2.tag==="CatCons")return et("CatCons",O._2._1,tt(O._2._2._1,wt("Cons",et("CatCons",()=>e1(h)(f)(d)(g),tt(A,A)),O._2._2._2)));c()})())};return j(F._1,(()=>{if(F._2.tag==="CatNil")return et("CatCons",Q,tt(A,A));if(F._2.tag==="CatCons")return et("CatCons",F._2._1,tt(F._2._2._1,wt("Cons",et("CatCons",Q,tt(A,A)),F._2._2._2)));c()})())};return j($._1,(()=>{if($._2.tag==="CatNil")return et("CatCons",G,tt(A,A));if($._2.tag==="CatCons")return et("CatCons",$._2._1,tt($._2._2._1,wt("Cons",et("CatCons",G,tt(A,A)),$._2._2._2)));c()})())};return j(M._1,(()=>{if(M._2.tag==="CatNil")return et("CatCons",q,tt(A,A));if(M._2.tag==="CatCons")return et("CatCons",M._2._1,tt(M._2._2._1,wt("Cons",et("CatCons",q,tt(A,A)),M._2._2._2)));c()})())})()),W=()=>{const M=Se({path:s.segment.path,role:s.role,layer:y,effects:[pe("GroupTransform",OL,k)]})(Wp(h)(_J)(f)(g));return j(M._1,(()=>{if(M._2.tag==="CatNil")return et("CatCons",()=>d1(t)(e)(n)(s),tt(A,A));if(M._2.tag==="CatCons")return et("CatCons",M._2._1,tt(M._2._2._1,wt("Cons",et("CatCons",()=>d1(t)(e)(n)(s),tt(A,A)),M._2._2._2)));c()})())};return j(D._1,(()=>{if(D._2.tag==="CatNil")return et("CatCons",W,tt(A,A));if(D._2.tag==="CatCons")return et("CatCons",D._2._1,tt(D._2._2._1,wt("Cons",et("CatCons",W,tt(A,A)),D._2._2._2)));c()})())};return j(S._1,(()=>{if(S._2.tag==="CatNil")return et("CatCons",v,tt(A,A));if(S._2.tag==="CatCons")return et("CatCons",S._2._1,tt(S._2._2._1,wt("Cons",et("CatCons",v,tt(A,A)),S._2._2._2)));c()})())})()),I=()=>Se({path:s.segment.path,role:s.role,layer:y,effects:[pe("GroupTransform",yi,k)]})(N);return j(P._1,(()=>{if(P._2.tag==="CatNil")return et("CatCons",I,tt(A,A));if(P._2.tag==="CatCons")return et("CatCons",P._2._1,tt(P._2._2._1,wt("Cons",et("CatCons",I,tt(A,A)),P._2._2._2)));c()})())})()),R=()=>{const P=W5(f)(t.halftoneShadows)(_)(r)(a)(s);return a.role==="FlyThrough"&&(r.tag==="Opening"||r.tag==="Closing")?P:j(st("Return",void 0),gt)};return j(C._1,(()=>{if(C._2.tag==="CatNil")return et("CatCons",R,tt(A,A));if(C._2.tag==="CatCons")return et("CatCons",C._2._1,tt(C._2._2._1,wt("Cons",et("CatCons",R,tt(A,A)),C._2._2._2)));c()})())},$5=t=>e=>n=>{if(t.theme==="Isometric")return C5({...x5,transparentBg:t.transparentBg})(t.theme)(bd(n).segment.layout)(bd(n).state);const r=_s(t)(n),o={tileScale:n.hasDives?r.vw/c1(1)(n.rootLayout.bounds.w):1,viewport:r},i=s=>u=>{if(u.length===0)return j(st("Return",void 0),gt);const g=It(_=>y,_=>f=>T("Just",{head:_,tail:f}),u);if(g.tag==="Nothing")return j(st("Return",void 0),gt);if(g.tag==="Just"){const _=d0(t)(o)(n.camera.zoom)(n.portalState)(g._1.head.role==="Active"?e:H)((()=>{if(g._1.head.role==="FlyThrough"&&0<g._1.tail.length){const f=g._1.tail[0].segment.path.length-1|0;if(f>=0&&f<g._1.tail[0].segment.path.length)return T("Just",g._1.tail[0].segment.path[f])}return y})())(s)(g._1.head);return g._1.head.role==="Active"||g._1.head.role==="FlyThrough"?j(_._1,(()=>{if(_._2.tag==="CatNil")return et("CatCons",()=>i(g._1.head)(g._1.tail),tt(A,A));if(_._2.tag==="CatCons")return et("CatCons",_._2._1,tt(_._2._2._1,wt("Cons",et("CatCons",()=>i(g._1.head)(g._1.tail),tt(A,A)),_._2._2._2)));c()})()):j(st("Return",void 0),et("CatCons",()=>i(g._1.head)(g._1.tail),tt(A,A)))}c()},a=It(s=>y,s=>u=>T("Just",{head:s,tail:u}),n.levels);if(a.tag==="Nothing")return j(st("Return",void 0),gt);if(a.tag==="Just"){const s=a._1.tail,u=a._1.head,g=O5(t)(n.hasDives?r.vw/c1(1)(n.rootLayout.bounds.w):1)(u.role==="Active"||u.role==="FlyThrough"?u.bgAlpha:0)((()=>{if(u.role==="FlyThrough"&&0<s.length){const f=s[0].segment.path.length-1|0;if(f>=0&&f<s[0].segment.path.length)return T("Just",s[0].segment.path[f])}return y})())(r)(u.segment.layout)(u.state)(s.length===0&&e.tag!=="Leaf"?l0("SpringLabels",e):Q5),_=()=>{const f=d1(t)(o)(n.camera.zoom)(u);return u.role==="Active"||u.role==="FlyThrough"?j(f._1,(()=>{if(f._2.tag==="CatNil")return et("CatCons",()=>i(u)(s),tt(A,A));if(f._2.tag==="CatCons")return et("CatCons",f._2._1,tt(f._2._2._1,wt("Cons",et("CatCons",()=>i(u)(s),tt(A,A)),f._2._2._2)));c()})()):j(st("Return",void 0),et("CatCons",()=>i(u)(s),tt(A,A)))};return j(g._1,(()=>{if(g._2.tag==="CatNil")return et("CatCons",_,tt(A,A));if(g._2.tag==="CatCons")return et("CatCons",g._2._1,tt(g._2._2._1,wt("Cons",et("CatCons",_,tt(A,A)),g._2._2._2)));c()})())}c()},h1=t=>e=>n=>YL({viewport:_s(t)(n),camera:n.camera})($5(t)(e)(n)),q5=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);c()}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()}c()},V5=t=>e=>q5(t)(e._1),U5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Fo(n)(Qt),o=t.popTransform,i=t.popBakedTransform,a=(()=>{const u=t.popClip,g=t.popAlpha,_=t.popBlend,f=t.popBlur;return l=>{if(l.tag==="GroupTransform"){if(l._1==="NormalTransform")return o;if(l._1==="BakedTransform")return i;c()}if(l.tag==="GroupClip")return u;if(l.tag==="GroupAlpha")return g;if(l.tag==="GroupBlend")return _;if(l.tag==="GroupBlur")return f;c()}})(),s=t.popLayer;return u=>e.Bind1().bind(r(a)(re(u.effects)))(()=>{if(u.layer.tag==="Just")return s;if(u.layer.tag==="Nothing")return n.pure();c()})},K5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Fo(n)(Qt);return o=>e.Bind1().bind((()=>{if(o.layer.tag==="Just")return t.pushLayer(o.layer._1);if(o.layer.tag==="Nothing")return n.pure();c()})())(()=>r(i=>{if(i.tag==="GroupTransform"){if(i._1==="NormalTransform")return t.pushTransform(i._2);if(i._1==="BakedTransform")return t.pushBakedTransform(i._2);c()}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);c()})(o.effects))},h0=t=>{const e=t.Monad0(),n=Hk(t),r=m5(t),o=r5(t),i=k5(t),a=zk(t),s=y5(t);return UL(e)({beginFrame:u=>t.setViewport(u.viewport),endFrame:e.Applicative0().pure(),beginGroup:K5(t),endGroup:U5(t),background:Gk(t),overlay:V5(t),node:u=>{if(u.geometry.tag==="FlatNode")return n(u);if(u.geometry.tag==="IsoSlab")return r(u);c()},edge:u=>{if(u.geometry.tag==="FlatRoute")return o(u);if(u.geometry.tag==="IsoSegments")return i(u);c()},text:$k(t),token:u=>{if(u.geometry.tag==="FlatToken")return a(u);if(u.geometry.tag==="IsoCube")return s(u);c()},insideTokenStyle:t.insideTokenStyle,measureText:t.measureText,measureInk:t.measureInk})},Y5=Xp(up)(M_.measureText),p0=h0(M_),p1=t=>_s({padding:24,outputAspect:t.width<=0||t.height<=0?y:T("Just",t.width/t.height)}),X5=t=>e=>n=>r=>o=>i=>a=>{const s={padding:24,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;c()})(),halftoneShadows:!1,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?y:T("Just",r.width/r.height)},u=ip(n)(r);return()=>{const g=u(),_=o.levels.length-1|0;if(_>=0&&_<o.levels.length){const l=Y5(f1(p1(r)(o))(o.levels[_]))(o.levels[_].segment.layout)(o.levels[_].state)(g)(),d=z_(i)(l)(a);return p0(h1(s)(d.applied)(o))(g)(),d.springs}const f=z_(i)(H)(a);return p0(h1(s)(f.applied)(o))(g)(),f.springs}},fs=t=>"rgb("+ue(t.r)+","+ue(t.g)+","+ue(t.b)+")",Ci=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,le=Wo(Ho("Fixed",Oo(0)(20)(2))),m1=t=>{const e=n=>{const r=n>=0&&n<t.length?T("Just",t[n]):y;if(r.tag==="Just")return r._1===1?["M",le((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===2?["L",le((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===3?["Q",le((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+5|0)]:r._1===4?["C",le((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+5|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{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[];c()};return dr(" ")(e(0))},Z5=t=>le(t.vx)+" "+le(t.vy)+" "+le(t.vw)+" "+le(t.vh),rr=t=>e=>he(sr(e>=0&&e<t.length?t[e]:0)),y1=t=>e=>{const n=rr(t.ops)(e+1|0);return Bt(n,n+rr(t.ops)(e+2|0)|0,t.paths)},m0=(()=>{const t=lr("&")("&"),e=lr("<")("<"),n=(()=>{const r=lr(">")(">"),o=(()=>{const i=lr('"')(""");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),j5={vx:0,vy:0,vw:1,vh:1},tS=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+Ci(t[i])|0;continue}r=!1,o=j5}return o})(0),ls=t=>e=>({r:rr(t)(e),g:rr(t)(e+1|0),b:rr(t)(e+2|0),a:rr(t)(e+3|0)}),y0=t=>e=>({color:ls(t)(e),width:(()=>{const n=e+4|0;return n>=0&&n<t.length?t[n]:0})(),join:rr(t)(e+5|0),cap:rr(t)(e+6|0)}),eS=t=>e=>'<rect x="'+le(t.vx)+'" y="'+le(t.vy)+'" width="'+le(t.vw)+'" height="'+le(t.vh)+'" fill="'+fs(e)+'" opacity="'+le(ot(e.a)/255)+'"/>',nS=t=>e=>'<path d="'+m1(t)+'" fill="'+fs(e)+'" fill-opacity="'+le(ot(e.a)/255)+'"/>',x0=t=>' stroke="'+fs(t.color)+'" stroke-opacity="'+le(ot(t.color.a)/255)+'" stroke-width="'+le(t.width)+'" stroke-linejoin="'+(t.join===0?"round":t.join===1?"bevel":"miter")+'" stroke-linecap="'+(t.cap===0?"butt":t.cap===1?"round":"square")+'"',rS=t=>e=>n=>'<path d="'+m1(t)+'" fill="'+fs(e)+'" fill-opacity="'+le(ot(e.a)/255)+'"'+x0(n)+"/>",oS=t=>e=>'<path d="'+m1(t)+'" fill="none"'+x0(e)+"/>",iS=t=>e=>{const n=ls(t.ops)(e+7|0),r=rr(t.ops)(e+12|0),o=rr(t.ops)(e+11|0);return'<text x="'+le((()=>{const i=e+1|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" y="'+le((()=>{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="'+fs(n)+'" fill-opacity="'+le(ot(n.a)/255)+'" font-size="'+le((()=>{const i=e+5|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" font-family="'+m0((()=>{const i=rr(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(rr(t.ops)(e+6|0))+'" text-anchor="'+(o===0?"start":o===1?"middle":"end")+'">'+m0((()=>{const i=rr(t.ops)(e+3|0);return i>=0&&i<t.strs.length?t.strs[i]:""})())+"</text>"},Li=t=>e=>n=>{const r=n>=0&&n<e.ops.length?T("Just",e.ops[n]):y;if(r.tag==="Just")return r._1===1?nS(y1(e)(n))(ls(e.ops)(n+3|0))+Li(t)(e)(n+Ci(r._1)|0):r._1===2?oS(y1(e)(n))(y0(e.ops)(n+3|0))+Li(t)(e)(n+Ci(r._1)|0):r._1===3?rS(y1(e)(n))(ls(e.ops)(n+3|0))(y0(e.ops)(n+7|0))+Li(t)(e)(n+Ci(r._1)|0):r._1===4?iS(e)(n)+Li(t)(e)(n+Ci(r._1)|0):r._1===16?eS(t)(ls(e.ops)(n+1|0))+Li(t)(e)(n+Ci(r._1)|0):Li(t)(e)(n+Ci(r._1)|0);if(r.tag==="Nothing")return"";c()},aS=t=>{const e=tS(t.ops);return{viewBox:Z5(e),body:Li(e)(t)(0),vx:e.vx,vy:e.vy,vw:e.vw,vh:e.vh}},sS=Rw(qw)(H2),w0=t=>e=>{const n=t.strs;return()=>{const r=Dg(n);return t.strs.push(e),r}},eg=t=>e=>{const n=t.paths;return()=>{const r=Dg(n);return t.paths.push(...e),{offset:r,len:e.length}}},uS=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)}},J0=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)}},so=t=>e=>{const n=ot(e),r=t.ops;return()=>{r.push(n)}},ng=t=>e=>{const n=e.len,r=so(t)(e.offset);return()=>(r(),so(t)(n)())},gS=()=>{const t=[],e=[],n=[],r=[];return r.push(1),{ops:t,paths:e,strs:n,alphaStack:r}},cS=t=>{if(t.tag==="MeasureText"){const e=t._3(Ec(t._1)(t._2));return()=>e}if(t.tag==="MeasureInk"){const e=t._3(Rc(t._1)(t._2));return()=>e}c()},T0=t=>{const e=t.alphaStack;return()=>{const n=Dg(e);if(n===0)return 1;const r=W2(Xt,y,n-1|0,t.alphaStack);if(r.tag==="Nothing")return 1;if(r.tag==="Just")return r._1;c()}},ki=t=>e=>{const n=T0(t);return()=>{const r=n();return so(t)(e.r)(),so(t)(e.g)(),so(t)(e.b)(),so(t)(he(sr(ot(e.a)*r+.5)))()}},N0=t=>e=>{const n=ki(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;c()})()),t.ops.push((()=>{if(e.lineCap==="ButtCap")return 0;if(e.lineCap==="RoundCap")return 1;if(e.lineCap==="SquareCap")return 2;c()})())}},_S=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,g=s._2,_=eg(a)(s._1);o=!1,i=()=>{const f=_();return a.ops.push(1),ng(a)(f)(),ki(a)(g.color)(),u};continue}if(s.tag==="StrokePath"){const u=s._3,g=s._2,_=eg(a)(s._1);o=!1,i=()=>{const f=_();return a.ops.push(2),ng(a)(f)(),N0(a)(g)(),u};continue}if(s.tag==="FillStrokePath"){const u=s._2,g=s._4,_=s._3,f=eg(a)(s._1);o=!1,i=()=>{const l=f();return a.ops.push(3),ng(a)(l)(),ki(a)(u.color)(),N0(a)(_)(),g};continue}if(s.tag==="DrawText"){const u=s._2,g=s._1,_=w0(a)(Ki(g.content));o=!1,i=()=>{const f=_(),l=w0(a)(g.font.family)();return a.ops.push(4),a.ops.push(g.x),a.ops.push(g.y),so(a)(f)(),so(a)(l)(),a.ops.push(g.font.size),so(a)(g.font.weight)(),ki(a)(g.color)(),a.ops.push((()=>{if(g.align==="AlignLeft")return 0;if(g.align==="AlignCenter")return 1;if(g.align==="AlignRight")return 2;c()})()),a.ops.push((()=>{if(g.baseline==="BaselineTop")return 0;if(g.baseline==="BaselineMiddle")return 1;if(g.baseline==="BaselineAlphabetic")return 2;if(g.baseline==="BaselineBottom")return 3;c()})()),u};continue}if(s.tag==="DrawTextAffine"){n=a,r=Yt("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,g=s._1,_=a.ops;o=!1,i=()=>(_.push(5),uS(a)(g)(),u);continue}if(s.tag==="PopTransform"){const u=s._1,g=a.ops;o=!1,i=()=>(g.push(6),u);continue}if(s.tag==="PushClip"){const u=s._3,g=s._2,_=eg(a)(s._1);o=!1,i=()=>{const f=_();return a.ops.push(7),ng(a)(f)(),a.ops.push((()=>{if(g==="NonZero")return 0;if(g==="EvenOdd")return 1;c()})()),u};continue}if(s.tag==="PopClip"){const u=s._1,g=a.ops;o=!1,i=()=>(g.push(8),u);continue}if(s.tag==="PushBlend"){const u=s._1,g=s._2,_=a.ops;o=!1,i=()=>(_.push(9),a.ops.push((()=>{if(u==="Normal")return 0;if(u==="Difference")return 1;c()})()),g);continue}if(s.tag==="PopBlend"){const u=s._1,g=a.ops;o=!1,i=()=>(g.push(10),u);continue}if(s.tag==="PushAlpha"){const u=s._1,g=s._2,_=T0(a);o=!1,i=()=>{const f=_();return a.alphaStack.push(f*u),a.ops.push(11),a.ops.push(u),g};continue}if(s.tag==="PopAlpha"){const u=s._1,g=a.alphaStack;o=!1,i=()=>($2(Xt,y,g),a.ops.push(12),u);continue}if(s.tag==="PushBlur"){const u=s._2,g=s._1,_=a.ops;o=!1,i=()=>(_.push(18),a.ops.push(g),u);continue}if(s.tag==="PopBlur"){const u=s._1,g=a.ops;o=!1,i=()=>(g.push(19),u);continue}if(s.tag==="PushLayer"){const u=s._1,g=s._2,_=a.ops;o=!1,i=()=>(_.push(13),a.ops.push((()=>{if(u==="LayerBase")return 0;if(u==="LayerPolyOut")return 1;if(u==="LayerPolyIn")return 2;if(u==="LayerNodeMask")return 3;if(u==="LayerOverlay")return 4;c()})()),g);continue}if(s.tag==="PopLayer"){const u=s._1,g=a.ops;o=!1,i=()=>(g.push(14),u);continue}if(s.tag==="SetViewport"){const u=s._2,g=s._1,_=a.ops;o=!1,i=()=>(_.push(15),J0(a)(g)(),u);continue}if(s.tag==="ClearBackground"){const u=s._1,g=s._2,_=a.ops;o=!1,i=()=>(_.push(16),ki(a)(u)(),g);continue}if(s.tag==="BackgroundDots"){const u=s._2,g=s._1,_=a.ops;o=!1,i=()=>(_.push(17),J0(a)(g.viewport)(),ki(a)(g.bgColor)(),ki(a)(g.dotColor)(),a.ops.push(g.tile),a.ops.push(g.dotRadius),a.ops.push(g.origin.x),a.ops.push(g.origin.y),u);continue}c()}return i},fS=t=>e=>e.type==="metrics"?cS(e.value):e.type==="render"?_S(t)(e.value):Af("Data.Functor.Variant: pattern match failure ["+e.type+"]"),lS=t=>{const e=gS();return sS(fS(e))(t)(),{ops:e.ops,paths:e.paths,strs:e.strs}},dS=t=>t,ds=t=>t,x1=ds("Light"),hS=ds("Dark"),pS=ds("Blueprint"),mS=ds("Whiteboard"),yS=ds("Isometric"),xS=dS("TransparentBackground"),Eo=t=>"rgb("+ue(t.r)+","+ue(t.g)+","+ue(t.b)+")",rg=Wo(Ho("Fixed",Oo(0)(20)(6))),Or=Wo(Ho("Fixed",Oo(0)(20)(4))),wS=t=>"translate("+Or(t.tx)+","+Or(t.ty)+") scale("+Or(t.sx)+","+Or(t.sy)+")",$t=Wo(Ho("Fixed",Oo(0)(20)(2))),w1=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,o=r>=0&&r<t.length?T("Just",t[r]):y;if(o.tag==="Nothing"){n=t.length;continue}if(o.tag==="Just"){if(o._1===1){e.push("M"),e.push($t((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{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($t((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{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($t((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{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($t((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{const i=r+4|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{const i=r+5|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{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}c()}return dr(" ")(e)},JS={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},b0=(()=>{const t=lr("&")("&"),e=lr("<")("<"),n=(()=>{const r=lr(">")(">"),o=(()=>{const i=lr('"')(""");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),Xe=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},TS=t=>e=>{const n=[];let r=0;const o=i=>{const a=i>=0&&i<e.length?t.sx*e[i]+t.tx:t.sx*0+t.tx;return()=>{n.push(a),n.push((()=>{const s=i+1|0;return s>=0&&s<e.length?t.sy*e[s]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const i=r,a=i>=0&&i<e.length?T("Just",e[i]):y;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}c()}return n},og=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return TS(r._1)(e);c()}},v0={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),a=o();return i(a)}},Functor0:()=>JS},NS={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>v0},bS={pure:t=>e=>()=>t,Apply0:()=>v0},C0={Applicative0:()=>bS,Bind1:()=>NS},vS=t=>e=>'<defs><pattern id="'+t+'" x="'+$t(e.origin.x)+'" y="'+$t(e.origin.y)+'" width="'+$t(e.tile)+'" height="'+$t(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+$t(e.tile)+'" height="'+$t(e.tile)+'" fill="'+Eo(e.bgColor)+'" fill-opacity="'+$t(ot(e.bgColor.a)/255)+'"/>')+'<circle cx="'+$t(e.tile/2)+'" cy="'+$t(e.tile/2)+'" r="'+$t(e.dotRadius)+'" fill="'+Eo(e.dotColor)+'"/></pattern></defs><rect x="'+$t(e.viewport.vx)+'" y="'+$t(e.viewport.vy)+'" width="'+$t(e.viewport.vw)+'" height="'+$t(e.viewport.vh)+'" fill="url(#'+t+')"/>',L0=t=>e=>'<path d="'+w1(t)+'" fill="'+Eo(e)+'" fill-opacity="'+$t(ot(e.a)/255)+'"/>',CS=t=>e=>n=>r=>'<rect x="'+$t(t.x)+'" y="'+$t(t.y)+'" width="'+$t(t.w)+'" height="'+$t(t.h)+'" rx="'+$t(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+Eo(n._1.color)+'" fill-opacity="'+$t(ot(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';c()})()+(()=>{if(r.tag==="Just")return' stroke="'+Eo(r._1.color)+'" stroke-opacity="'+$t(ot(r._1.color.a)/255)+'" stroke-width="'+$t(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";c()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";c()})()+'"';if(r.tag==="Nothing")return"";c()})()+"/>",k0=t=>e=>'<path d="'+w1(t)+'" fill="none" stroke="'+Eo(e.color)+'" stroke-opacity="'+$t(ot(e.color.a)/255)+'" stroke-width="'+$t(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";c()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";c()})()+'"/>',S0=t=>'<text x="'+$t(t.x)+'" y="'+$t(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"";c()})()+' fill="'+Eo(t.color)+'" fill-opacity="'+$t(ot(t.color.a)/255)+'" font-size="'+$t(t.font.size)+'" font-family="'+b0(t.font.family)+'" 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";c()})()+'">'+b0(Ki(t.content))+"</text>",LS=t=>"matrix("+Or(t.a)+" "+Or(t.b)+" "+Or(t.c)+" "+Or(t.d)+" "+Or(t.e)+" "+Or(t.f)+")",E0={fillPath:t=>e=>n=>{const r=og(n)(t);return()=>{const o=r();return Xe(L0(o)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=og(n)(t);return()=>{const o=r(),i=n.bake.value;return Xe(k0(o)((()=>{if(i.tag==="Nothing")return e;if(i.tag==="Just")return{...e,width:i._1.sx*e.width};c()})()))(n)()}},fillStrokePath:t=>e=>n=>r=>{const o=og(r)(t);return()=>{const i=o(),a=r.bake.value;return Xe(L0(i)(e.color)+k0(i)((()=>{if(a.tag==="Nothing")return n;if(a.tag==="Just")return{...n,width:a._1.sx*n.width};c()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>o=>{const i=o.bake;return()=>{const a=i.value;return Xe(CS((()=>{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};c()})())((()=>{if(a.tag==="Nothing")return e;if(a.tag==="Just")return a._1.sx*e;c()})())(n)(r.tag==="Just"?T("Just",(()=>{if(a.tag==="Nothing")return r._1;if(a.tag==="Just")return{...r._1,width:a._1.sx*r._1.width};c()})()):y))(o)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return Xe(S0((()=>{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}};c()})()))(e)()}},drawTextAffine:t=>e=>Xe((()=>{const n='transform="'+LS(t)+'"';return(n===""?"<g>":"<g "+n+">")+S0(e)+"</g>"})()),pushTransform:t=>Xe((()=>{const e='transform="'+wS(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:Xe("</g>"),pushBakedTransform:t=>e=>{const n=e.bake;return()=>{n.value=T("Just",t)}},popBakedTransform:t=>{const e=t.bake;return()=>{e.value=y}},pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const o=r.value;n.clipCounter.value=o+1|0;const i=og(n)(t)(),a="clip"+ue(o);return Xe((()=>{const s='clip-path="url(#'+a+')"';return'<defs><clipPath id="'+a+'"><path d="'+w1(i)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";c()})()+"/></clipPath></defs>"+(s===""?"<g>":"<g "+s+">")})())(n)()}},popClip:Xe("</g>"),pushBlend:t=>Xe((()=>{const e=(()=>{if(t==="Normal")return'style="mix-blend-mode: normal"';if(t==="Difference")return'style="mix-blend-mode: difference"';c()})();return e===""?"<g>":"<g "+e+">"})()),popBlend:Xe("</g>"),pushAlpha:t=>Xe((()=>{const e='opacity="'+$t(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:Xe("</g>"),pushBlur:t=>e=>{if(t<.01)return Xe("<g>")(e);const n=e.patternCounter;return()=>{const r=n.value;e.patternCounter.value=r+1|0;const o="lvl-blur-"+ue(r);return Xe((()=>{const i='filter="url(#'+o+')"';return'<defs><filter id="'+o+'" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="'+$t(t)+'"/></filter></defs>'+(i===""?"<g>":"<g "+i+">")})())(e)()}},popBlur:Xe("</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=>Xe('<rect x="'+$t(e.viewport.vx)+'" y="'+$t(e.viewport.vy)+'" width="'+$t(e.viewport.vw)+'" height="'+$t(e.viewport.vh)+'" fill="'+Eo(t)+'" opacity="'+$t(ot(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,Xe(vS("bg-dots-"+ue(r))(t))(e)()}},measureText:t=>e=>n=>{const r=Ec(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Rc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>zc,Monad0:()=>C0},kS=h0(E0),SS=Xp(C0)(E0.measureText),ES=t=>e=>n=>r=>o=>{const i={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;c()})(),halftoneShadows:!1,watermark:"",theme:n,outputAspect:t},a=_s(i)(o);return{viewBox:rg(a.vx)+" "+rg(a.vy)+" "+rg(a.vw)+" "+rg(a.vh),body:(()=>{const s=[],u={value:0},g={value:0},_={value:0},f={value:y};return kS(h1(i)(e)(o))({out:s,maskDepth:u,clipCounter:g,patternCounter:_,viewport:a,bake:f})(),dr("")(s)})(),vx:a.vx,vy:a.vy,vw:a.vw,vh:a.vh}},RS=t=>e=>n=>r=>o=>i=>{const a={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;c()})(),outputAspect:t},s=z_(o)((()=>{const u=[],g={value:0},_={value:0},f={value:0},l={value:y},d=r.levels.length-1|0;if(d>=0&&d<r.levels.length){const h=f1(_s(a)(r))(r.levels[d]);return SS(h)(r.levels[d].segment.layout)(r.levels[d].state)({out:u,maskDepth:g,clipCounter:_,patternCounter:f,viewport:h,bake:l})()}return H})())(i);return{parts:ES(t)(s.applied)(e)(n)(r),springs:s.springs}},Ro=(t,e)=>({tag:t,_1:e}),ig=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Qn=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},R0=fe(B)(Qt),P0=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=B.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}}c()}return o},G0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},ag=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},sg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Si=(()=>{const t=un.unfoldr(e=>{if(e.tag==="Nil")return y;if(e.tag==="Cons")return T("Just",E(e._1,e._2));c()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,wt("Cons",r._3,n(r._6,o)));c()};return n(e,A)})())})(),PS=b(t=>e=>it(B)(e)()(t))(H),J1=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=B.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}}c()}return o},GS=bs(zi),B0=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},BS=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},ug=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=B.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}}c()}return o},AS=Ro("NoKeyframes"),IS=t=>Ro("DuplicateEventId",t),zS=t=>Ro("UnknownEvent",t),FS=t=>e=>({...e,cameraSpans:ld(e.cameraConfig)(t)(e.timing.edgeEasing)(e.layout)(e.keyframes)({endT:e.totalDuration,spans:e.spans,windows:e.windows,segments:e.segments,dives:e.dives}),cameraViewport:t}),DS=t=>e=>n=>r=>{const o=ig(r.edge)(e.edges),i=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return Ba(o._1);c()})(),a=Qn(t.minTokenDuration)(Qn(ot(b(s=>u=>s+_n(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}},MS=vs(t=>{const e=$i(`
|
|
9
|
-
`)(t);return e.length===0?[""]:e}),QS=t=>e=>R0(ht(n=>{if(n.kind.tag==="SendToken")return T("Just",E(n.id,{post:(()=>{const r=n.id;return(()=>{const o=n.kind._1.to;return oe(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;c()},e)})()?0:t.tokenHold})()}));if(n.kind.tag==="FillNodeWithoutTransition")return y;c()})(e)),HS=t=>{if(t.event.kind.tag==="SendToken")return T("Just",{startT:t.startT,endT:t.endT,target:ni("TokenWindow",t.event.id,t.event.kind._1.edge,t.event.kind._1.direction,t.event.kind._1.from,t.event.kind._1.to,t.event.kind._1.labels,t.holdPre,t.holdPost)});if(t.event.kind.tag==="FillNodeWithoutTransition")return T("Just",{startT:t.startT,endT:t.endT,target:ni("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});c()},OS=t=>ht((()=>{const e=t.path;return n=>n.target.tag==="TokenWindow"?T("Just",{path:e,eventId:n.target._1,window:n,from:n.target._4,to:n.target._5,labels:n.target._6,holdPre:n.target._7,holdPost:n.target._8}):y})())(t.windows),WS=t=>e=>n=>{const r=ig(n)(t);if(r.tag==="Nothing")return pd;if(r.tag==="Just"){const o=P0(r._1.target)(e);return P0(r._1.source)(e)?o?VT:qT:pd}c()},A0=t=>e=>{if(t.tag==="Just"&&t._1>e.endT+1e-4){const n=Qn(0)(e.endT-e.startT),r=Qn(e.startT)(t._1-n);return{...e,startT:r,endT:r+n}}return e},I0=Y(Ja),$S={post:0},qS=t=>e=>n=>r=>o=>{const i=G0(o.event.id)(n),a=(()=>{if(i.tag==="Nothing")return $S;if(i.tag==="Just")return i._1;c()})(),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 g=o.event.when._1,_=te(f=>f.event.id===g)(r);if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1.endT;c()}if(o.event.when.tag==="With"){const g=o.event.when._1,_=te(f=>f.event.id===g)(r);if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1.startT}c()})(),u=(()=>{if(o.event.kind.tag==="SendToken")return DS(t)(e)(a)(o.event.kind._1);if(o.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};c()})();return Et(r)({startT:s,endT:s+u.duration,event:o.event,holdPre:u.holdPre,holdPost:u.holdPost})},z0=t=>e=>n=>b(qS(t)(e)(QS(t)(n)))([])(Dt(r=>o=>({event:o}))(n)),VS=t=>b(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?Et(r._1.init)({...r._1.last,endT:Qn(r._1.last.endT)(n.endT)}):Et(e)(n);c()})([])(Rt(e=>n=>at.compare(e.startT)(n.startT))(t)),US=t=>e=>{const n=ag(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;c()},KS=t=>e=>{const n=Rt(at.compare)(ht(r=>r.target.tag==="RelabelWindow"?r.target._1===e?T("Just",r.startT):y:r.target.tag==="TokenWindow"?r.target._4===e||r.target._5===e?T("Just",r.startT):y:r.target.tag==="FillWindow"&&r.target._2===e?T("Just",r.startT):y)(t));return 0<n.length?T("Just",n[0]):y},YS=t=>e=>{const n=Rt(at.compare)(ht(r=>r.target.tag==="TokenWindow"&&r.target._2===e?T("Just",r.startT):y)(t));return 0<n.length?T("Just",n[0]):y},XS=t=>e=>e.target.tag==="NodeWindow"?e.target._2==="PlopIn"?A0(KS(t.windows)(e.target._1))(e):e:e.target.tag==="EdgeWindow"&&e.target._2.tag==="Extend"?A0(YS(t.windows)(e.target._1))(e):e,ZS=t=>({...t,windows:Rt(e=>n=>at.compare(e.startT)(n.startT))(Y(XS(t))(t.windows))}),jS=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];c()},gg={id:"",nodes:H,edges:H,labels:H,kind:Ra,authored:!1},tE=t=>e=>Lx((()=>{const n=sg(e.from)(t);if(n.tag==="Nothing")return gg;if(n.tag==="Just")return n._1;c()})())((()=>{const n=sg(e.to)(t);if(n.tag==="Nothing")return gg;if(n.tag==="Just")return n._1;c()})()),eE=t=>e=>{const n=ag(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:H};if(n.tag==="Just")return n._1;c()},F0={id:"",index:-1,kind:"",name:"",time:0,endTime:0,path:[],tokenIndex:-1,lineIndex:-1,text:"",from:"",to:""},nE=t=>e=>e.scene.tag==="StepScene"?T("Just",{...F0,id:"step:"+e.scene._1,kind:"step",name:e.scene._1,time:e.startT,endTime:e.startT,path:I0(t)}):y,rE=t=>ht(nE(t.path))(t.spans),T1=t=>e=>n=>r=>{const o=ig(r)(n.edges);if(o.tag==="Just")return t<=0?e:Qn(e)(Ba(o._1)/t);if(o.tag==="Nothing")return e;c()},D0=t=>e=>n=>r=>o=>{const i=sg(o.to)(n),a=(()=>{if(i.tag==="Nothing")return gg;if(i.tag==="Just")return i._1;c()})(),s=t.plop,u=sg(o.from)(n),g=(()=>{if(u.tag==="Nothing")return gg;if(u.tag==="Just")return u._1;c()})(),_=tE(n)(o),f=Y(w=>({startT:0,endT:0+T1(t.edgeSpeed)(t.minEdgeDuration)(e)(w),target:ni("EdgeWindow",w,cu("Extend",n_))}))(Si(_.entering.edges)),l=Y(w=>({startT:0,endT:s,target:ni("NodeWindow",w,Hc)}))(Si(_.entering.nodes)),d=Y(w=>({startT:0,endT:t.plop,target:ni("RelabelWindow",w.node,w.oldLabel,w.newLabel)}))(ht(w=>{const J=ag(w)(g.labels);if(J.tag==="Just"){const N=ag(w)(a.labels);if(N.tag==="Just")return J._1===N._1?y:T("Just",{node:w,oldLabel:J._1,newLabel:N._1});if(N.tag==="Nothing")return y;c()}if(J.tag==="Nothing")return y;c()})(Si(_.surviving.nodes))),h=b(Qn)(0)(Y(w=>T1(t.edgeSpeed)(t.minEdgeDuration)(e)(w))(Si(_.leaving.edges))),m=w=>oe(J=>{const N=ig(J)(r);if(N.tag==="Just")return N._1.source===w||N._1.target===w;if(N.tag==="Nothing")return!1;c()},Si(_.leaving.edges))?h:0,p=Y(w=>({startT:m(w),endT:m(w)+t.plop,target:ni("NodeWindow",w,AJ)}))(Si(_.leaving.nodes)),x=Y(w=>({startT:0,endT:T1(t.edgeSpeed)(t.minEdgeDuration)(e)(w),target:ni("EdgeWindow",w,cu("Retract",WS(r)(_.leaving.nodes)(w)))}))(Si(_.leaving.edges));return{duration:(()=>{const w=Rt(at.compare)([...Y(N=>N.endT)(x),...Y(N=>N.endT)(p),...Y(N=>N.endT)(l),...Y(N=>N.endT)(d),...Y(N=>N.endT)(f)]),J=w.length-1|0;return J>=0&&J<w.length?w[J]+t.gap:t.gap})(),windows:[...x,...p,...l,...d,...f]}},oE=t=>e=>n=>r=>o=>i=>Y((()=>{const a=o.startT;return s=>({...s,startT:s.startT+a,endT:s.endT+a})})())(D0(t)(e)(n)(r)(i).windows),iE=t=>ht(e=>Mt(Ai,e).length>1?T("Just",(()=>{const n=It(r=>y,r=>o=>T("Just",{head:r,tail:o}),Mt(Ai,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";c()})()):y)(_y(zi)(Rt(B.compare)(t))),aE=t=>{const e=Y(r=>r.id)(t),n=PS(e);return[...Y(IS)(iE(e)),...Y(zS)(_t(r=>!J1(r)(n),St(t)(jS)))]},sE=t=>{const e=R0(Y(r=>E(r.id,(()=>{if(r.when.tag==="First")return[];if(r.when.tag==="At")return[];if(r.when.tag==="After")return[r.when._1];if(r.when.tag==="With")return[r.when._1];c()})()))(t)),n=r=>o=>i=>{if(J1(i)(o))return[Ro("ScheduleCycle",[...Mt(wn.foldr,o),i])];if(J1(i)(r))return[];const a=G0(i)(e);if(a.tag==="Nothing")return[];if(a.tag==="Just")return St(a._1)(n(it(B)(i)()(r))(it(B)(i)()(o)));c()};return St(t)(r=>n(H)(H)(r.id))},uE={plop:.5,gap:0,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:0,stillHold:1.8,hatchHold:0,tokenReadSecPerChar:.06,nodeEasing:zx,edgeEasing:fr,tokenEasing:mc,diveDur:2.45,retreatDur:2.45},gE=t=>e=>n=>r=>Y((()=>{const o=n.startT;return i=>({...i,startT:i.startT+o,endT:i.endT+o})})())(ht(HS)(z0(t)(e)(r.events))),cE=t=>e=>n=>r=>o=>{if(o.scene.tag==="Structural")return oE(t)(e)(n)(r)(o)(o.scene._1);if(o.scene.tag==="Hold")return[];if(o.scene.tag==="DataFlow")return gE(t)(e)(o)(o.scene._1);if(o.scene.tag==="EnterNode")return[];if(o.scene.tag==="ExitNode")return[];if(o.scene.tag==="StepScene")return[];c()},_E=t=>e=>n=>{const r=z0(t)(e)(n.events);return r.length===0?t.gap:b(Qn)(0)(Y(o=>o.endT)(r))+t.gap},fE=t=>e=>n=>r=>o=>{if(o.tag==="Structural")return D0(t)(e)(n)(r)(o._1).duration;if(o.tag==="Hold")return t.stillHold;if(o.tag==="DataFlow")return _E(t)(e)(o._1);if(o.tag==="EnterNode"||o.tag==="ExitNode"||o.tag==="StepScene")return 0;c()},M0=t=>e=>n=>r=>o=>i=>{const a=vw(e)(r),s=n.layout,u=Mf(Y(p=>E(p.id,p))(o.keyframes)),g=0<o.keyframes.length?T("Just",o.keyframes[0]):y,_=(()=>{if(g.tag==="Just")return g._1.id;if(g.tag==="Nothing")return"";c()})(),f=Ax(o),l=p=>({startT:p.runStart,endT:p.t,path:r,layout:s,placement:a,windows:p.runWindows,spans:p.runSpans,keyframes:u,initialKeyframe:_,edgeEndpoints:f}),d=p=>({segments:p.runSpans.length===0?p.segments:Et(p.segments)(l(p)),spans:p.spans,windows:p.windows,dives:p.dives}),h=b(p=>x=>{if(x.tag==="EnterNode"){const k=d(p),C=p.runSpans.length===0?{...k,segments:Et(k.segments)(l(p))}:k,R=p.t+t.diveDur,P=Et(r)(x._1),I=M0(t)(e)(eE(n)(x._1))(P)(US(o)(x._1))(R),U=I.endT+t.retreatDur;return{...p,t:U,runStart:U,runSpans:[],runWindows:[],segments:[...C.segments,...I.segments],spans:[...C.spans,...I.spans],windows:[...C.windows,...I.windows],dives:[...C.dives,{startT:p.t,endT:R,node:x._1,parentPath:r,childPath:P,direction:IJ},...I.dives,{startT:I.endT,endT:U,node:x._1,parentPath:r,childPath:P,direction:zJ}]}}if(x.tag==="ExitNode")return p;const w=p.t+fE(t)(s)(u)(f)(x),J={startT:p.t,endT:w,scene:x},N=cE(t)(s)(u)(f)(J);return{...p,t:w,runSpans:Et(p.runSpans)(J),runWindows:[...p.runWindows,...N],spans:Et(p.spans)(J),windows:[...p.windows,...N]}})({t:i,runStart:i,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(o.scenes),m=d(h);return{endT:h.t,spans:m.spans,windows:Rt(p=>x=>at.compare(p.startT)(x.startT))(m.windows),segments:r.length===0||oe(p=>GS(p.path)(r),m.segments)?m.segments:Et(m.segments)(l(h)),dives:m.dives}},lE=t=>e=>{const n=at.compare(t.time)(e.time);return n==="EQ"?B.compare(t.id)(e.id):n},or=t=>e=>e-b(n=>r=>n+Qn(0)(B0(e)(r.endT)-r.startT))(0)(t),dE=t=>e=>{const n=Qn(t.startT)(e.startT),r=B0(t.endT)(e.endT);return r>n+1e-4?T("Just",{startT:n,endT:r}):y},hE=t=>e=>{if(e.scene.tag==="Structural"){const n=b(r=>o=>({cursor:Qn(r.cursor)(o.endT),cuts:o.startT>r.cursor+1e-4?Et(r.cuts)({startT:r.cursor,endT:o.startT}):r.cuts}))({cursor:e.startT,cuts:[]})(Rt(r=>o=>at.compare(r.startT)(o.startT))(ht(dE(e))(t)));return e.endT>n.cursor+1e-4?Et(n.cuts)({startT:n.cursor,endT:e.endT}):n.cuts}return[]},pE=t=>{const e=VS(St(t.spans)(hE(t.windows)));return e.length===0?t:{...t,endT:or(e)(t.endT),spans:Y(n=>({...n,startT:or(e)(n.startT),endT:or(e)(n.endT)}))(t.spans),windows:Rt(n=>r=>at.compare(n.startT)(r.startT))(Y(n=>({...n,startT:or(e)(n.startT),endT:or(e)(n.endT)}))(t.windows)),segments:Y(n=>({...n,startT:or(e)(n.startT),endT:or(e)(n.endT),spans:Y(r=>({...r,startT:or(e)(r.startT),endT:or(e)(r.endT)}))(n.spans),windows:Rt(r=>o=>at.compare(r.startT)(o.startT))(Y(r=>({...r,startT:or(e)(r.startT),endT:or(e)(r.endT)}))(n.windows))}))(t.segments),dives:Y(n=>({...n,startT:or(e)(n.startT),endT:or(e)(n.endT)}))(t.dives)}},mE=t=>{const e=Y(ZS)(t.segments);return pE({...t,segments:e,windows:Rt(n=>r=>at.compare(n.startT)(r.startT))(St(e)(n=>n.windows))})},yE=t=>e=>n=>{const r=Qn(.05)(1-t-e),o=u=>{if(u<=0)return 0;if(u>=1)return 1;const g=t+u*r;return g<0?0:g>1?1:g},i=MS(n),a=Y(u=>ot(BS(1)(_n(u).length)))(i),s=Qn(1)(b(ur)(0)(a));return Dt(u=>g=>({lineIndex:u,text:g,start:o(b(ur)(0)(u<1?[]:Bt(0,u,a))/s),end:o(u>=0&&u<a.length?(b(ur)(0)(u<1?[]:Bt(0,u,a))+a[u])/s:(b(ur)(0)(u<1?[]:Bt(0,u,a))+1)/s)}))(i)},xE=t=>{const e=Qn(0)(t.window.endT-t.window.startT);return Y(n=>({...F0,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:I0(t.path),tokenIndex:t.tokenIndex,lineIndex:n.lineIndex,text:n.text,from:t.from,to:t.to}))(yE(t.holdPre)(t.holdPost)(t.labels))},wE=t=>St(Dt(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)(OS)))(xE),JE=t=>Dt(e=>n=>({...n,index:e}))(Rt(lE)([...St(t.segments)(rE),...wE(t.segments)])),TE=t=>e=>{if(e.tag==="Structural")return ht(n=>n)([ug(e._1.from)(t)?y:T("Just",Ro("UnknownKeyframe",e._1.from)),ug(e._1.to)(t)?y:T("Just",Ro("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return ht(n=>n)([ug(e._1)(t)?y:T("Just",Ro("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...ht(n=>n)([ug(e._1.keyframe)(t)?y:T("Just",Ro("UnknownKeyframe",e._1.keyframe))]),...aE(e._1.events),...sE(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];if(e.tag==="StepScene")return[];c()},NE=t=>e=>{const n=St(e)(TE(t));return n.length===0?zt("Right",void 0):zt("Left",n)},bE=t=>e=>n=>r=>o=>{if(0<r.keyframes.length){const i=r.keyframes[0],a=Mf(Y(u=>E(u.id,u))(r.keyframes)),s=NE(a)(r.scenes);return(()=>{if(s.tag==="Left"){const u=s._1;return g=>zt("Left",u)}if(s.tag==="Right"){const u=s._1;return g=>g(u)}c()})()(()=>{const u=mE(M0(n)(o)(o)([])(r)(0)),g=r.minimumFontSize.tag==="Just"&&r.minimumFontSize._1>0?{...t,minimumReadableLabelPx:r.minimumFontSize._1}:t;return zt("Right",{totalDuration:u.endT,windows:u.windows,spans:u.spans,keyframes:a,initialKeyframe:i.id,timing:n,layout:o.layout,cameraSpans:ld(g)(e)(n.edgeEasing)(o.layout)(a)(u),cameraConfig:g,cameraViewport:e,levelTree:o,segments:u.segments,dives:u.dives,cues:JE(u),seed:r.seed})})}return zt("Left",[AS])},Ei=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(o=>n(o._1)(o._2)),Apply0:()=>Q0(t)}),Q0=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>o=>i=>e.map(a=>E(r(a._1),a._2))(o(i))};return{apply:(()=>{const r=Ei(t);return o=>i=>r.bind(o)(a=>r.bind(i)(s=>Ri(t).pure(a(s))))})(),Functor0:()=>n}},Ri=t=>({pure:e=>n=>t.Applicative0().pure(E(e,n)),Apply0:()=>Q0(t)}),H0=t=>{const e={Applicative0:()=>Ri(t),Bind1:()=>Ei(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},ir=(t,e)=>({tag:"ParseError",_1:t,_2:e}),L=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),cg=(t,e,n)=>({tag:t,_1:e,_2:n}),vE=t=>cg("More",t),CE=t=>cg("Lift",t),LE={defer:t=>{const e=ox(t);return(n,r,o,i,a)=>ix(e)(n,r,o,i,a)}},O0={map:t=>e=>(n,r,o,i,a)=>r(s=>e(n,r,o,i,(u,g)=>r(_=>a(u,t(g)))))},kE={alt:t=>e=>(n,r,o,i,a)=>{const s=n._1,u=n._2;return r(g=>t(L(s,u,!1),r,o,(_,f)=>{const l=_._3;return r(d=>l?i(_,f):e(n,r,o,i,a))},a))},Functor0:()=>O0},SE=t=>{const e=t.Monad0();return n=>r=>{const o=i=>{let a=i,s=!0,u;for(;s;){const g=a();if(g.tag==="More"){a=g._1;continue}if(g.tag==="Lift"){s=!1,u=e.Bind1().Apply0().Functor0().map(zg)(g._1);continue}if(g.tag==="Stop"){s=!1,u=e.Applicative0().pure(Bi("Done",E(g._2,g._1)));continue}c()}return u};return t.tailRecM(o)(i=>r(n,vE,CE,(a,s)=>cg("Stop",a,zt("Left",s)),(a,s)=>cg("Stop",a,zt("Right",s))))}},Hn=(t,e,n,r,o)=>o(t,t._2),EE={index:0,line:1,column:1},W0=(t=>{const e=SE(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(Ns)(e(L(n,EE,!1))(r))})(A2),_g=(t,e,n,r,o)=>o(L(t._1,t._2,!0),void 0),$0={apply:t=>e=>(n,r,o,i,a)=>r(s=>t(n,r,o,i,(u,g)=>r(_=>{const f=n._3&&!u._3?L(u._1,u._2,!0):u;return e(f,r,o,i,(l,d)=>r(h=>a(f._3&&!l._3?L(l._1,l._2,!0):l,g(d))))}))),Functor0:()=>O0},q0={pure:t=>(e,n,r,o,i)=>i(e,t),Apply0:()=>$0},RE={bind:t=>e=>(n,r,o,i,a)=>r(s=>t(n,r,o,i,(u,g)=>r(_=>e(g)(n._3&&!u._3?L(u._1,u._2,!0):u,r,o,i,a)))),Apply0:()=>$0},PE={Applicative0:()=>q0,Bind1:()=>RE},fg=t=>(e,n,r,o,i)=>n(a=>Hn(e,n,r,o,(s,u)=>n(g=>o(e._3&&!s._3?L(s._1,s._2,!0):s,ir(t,u))))),GE={empty:fg("No alternative"),Alt0:()=>kE},BE={Applicative0:()=>q0,Plus1:()=>GE},De=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return o=>t.tailRecM(i=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(zg)(o))(r.pure(Bi("Done",void 0))))(a=>r.pure((()=>{if(a.tag==="Loop")return Bi("Loop",wt("Cons",a._1,i));if(a.tag==="Done")return Bi("Done",(s=>u=>{let g=s,_=u,f=!0,l;for(;f;){const d=g,h=_;if(h.tag==="Nil"){f=!1,l=d;continue}if(h.tag==="Cons"){g=wt("Cons",h._1,d),_=h._2;continue}c()}return l})(A)(i));c()})())))(A)})({tailRecM:t=>e=>(n,r,o,i,a)=>{const s=(u,g,_)=>t(g)(u,r,o,i,(f,l)=>{const d=u._3&&!f._3?L(f._1,f._2,!0):f;if(l.tag==="Loop")return _===0?r(h=>s(d,l._1,30)):s(d,l._1,_-1|0);if(l.tag==="Done")return a(d,l._1);c()});return s(n,e,30)},Monad0:()=>PE})(BE),xt=t=>e=>{const n=fg("Expected "+e);return(r,o,i,a,s)=>{const u=r._1,g=r._2;return o(_=>t(L(u,g,!1),o,i,(f,l)=>{const d=f._3;return o(h=>d?a(f,l):n(r,o,i,a,s))},s))}},Po=t=>(e,n,r,o,i)=>{const a=e._3,s=e._1,u=e._2;return n(g=>{const _=(f,l)=>{const d=f._3;return n(h=>d?o(L(f._1,f._2,a),l):i(e,void 0))};return n(f=>n(l=>t(L(s,u,!1),n,r,(d,h)=>_(L(d._1,d._2,!1),h),(d,h)=>n(m=>n(p=>fg("Negated parser succeeded")(d,n,r,_,(x,w)=>n(J=>i(d._3&&!x._3?L(x._1,x._2,!0):x,w))))))))})},AE=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return T("Just",n);if(r.tag==="Just")return T("Just",(o,i,a,s,u)=>{const g=o._1,_=o._2;return i(f=>n(L(g,_,!1),i,a,(l,d)=>{const h=l._3;return i(m=>h?s(l,d):r._1(o,i,a,s,u))},u))});c()})(y);return n=>{const r=e(n);if(r.tag==="Nothing")return fg("No alternative");if(r.tag==="Just")return r._1;c()}},V0=t=>e=>n=>(r,o,i,a,s)=>o(u=>o(g=>o(_=>o(f=>t(r,o,i,a,(l,d)=>o(h=>o(m=>{const p=r._3&&!l._3?L(l._1,l._2,!0):l;return n(p,o,i,a,(x,w)=>o(J=>{const N=p._3&&!x._3?L(x._1,x._2,!0):x;return o(k=>o(C=>{const R=r._3&&!N._3?L(N._1,N._2,!0):N;return e(R,o,i,a,(P,I)=>o(U=>s(R._3&&!P._3?L(P._1,P._2,!0):P,w)))}))}))}))))))),N1=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=xw()(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)-fo(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},IE=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,g=o,_=i,f=qs(g);if(f.tag==="Nothing"){a=!1,s=u;continue}if(f.tag==="Just"){r=f._1.tail===""?N1(u)(f._1.head)(_):N1(u)(f._1.head)(f._1.tail),o=f._1.tail,i=_;continue}c()}return s},Pt=t=>(e,n,r,o,i)=>{const a=qs(e._1);if(a.tag==="Nothing")return o(e,ir("Unexpected EOF",e._2));if(a.tag==="Just"){if(a._1.head<0||a._1.head>65535)return o(e,ir("Expected Char",e._2));if(a._1.head>=0&&a._1.head<=65535){const s=Uf(a._1.head);return t(s)?i(L(a._1.tail,N1(e._2)(a._1.head)(a._1.tail),!0),s):o(e,ir("Predicate unsatisfied",e._2))}}c()},xa=(t,e,n,r,o)=>t._1===""?o(L(t._1,t._2,!0),void 0):r(t,ir("Expected EOF",t._2)),zE=t=>(e,n,r,o,i)=>{const a=t(e._1);if(a.tag==="Left")return o(e,ir(a._1,e._2));if(a.tag==="Right")return i(L(a._1.remainder,IE(e._2)(a._1.consumed)(a._1.remainder),a._1.consumed!==""),a._1.value);c()},Ee=t=>zE(e=>{const n=xr(t)(e);return n.tag==="Just"?zt("Right",{value:t,consumed:t,remainder:n._1}):zt("Left","Expected "+T2(t))}),b1=Pt(t=>!0),U0=(t,e)=>({tag:t,_1:e}),K0=(t,e,n)=>({tag:t,_1:e,_2:n}),FE=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=B.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}}c()}return o},Y0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},DE=t=>e=>b(n=>r=>(()=>{if(n.tag==="Left"){const o=n._1;return i=>zt("Left",o)}if(n.tag==="Right"){const o=n._1;return i=>i(o)}c()})()(o=>t(o)(r)))(zt("Right",e)),X0=t=>e=>n=>FE(t)(n.values)?zt("Right",{...n,values:it(B)(t)(e)(n.values)}):zt("Left","label has no placeholder `"+t+"`"),Z0=(()=>{const t=Po((e,n,r,o,i)=>{const a=e._3;return Ee("{{")(e,n,r,(s,u)=>o(L(s._1,s._2,a),u),i)});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>b1(e._3&&!s._3?L(s._1,s._2,!0):s,n,r,o,i))))})(),ME=(()=>{const t=Po((e,n,r,o,i)=>{const a=e._3;return Ee("}}")(e,n,r,(s,u)=>o(L(s._1,s._2,a),u),i)});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>b1(e._3&&!s._3?L(s._1,s._2,!0):s,n,r,o,i))))})(),wa=t=>dr("")(Y(e=>{if(e.tag==="LabelText")return e._1;if(e.tag==="LabelSlot"){const n=Y0(e._1)(t.values);if(n.tag==="Just")return n._1;if(n.tag==="Nothing")return""}c()})(t.parts)),QE=(t,e,n,r,o)=>e(i=>Z0(t,e,n,r,(a,s)=>e(u=>{const g=De(Z0),_=t._3&&!a._3?L(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>o(_._3&&!l._3?L(l._1,l._2,!0):l,K0("ParsedText",Bn([s,...Mt(ce.foldr,d)]))))))}))),HE=t=>t===" "||t===" "||t===`
|
|
10
|
-
`||t==="\r",j0=(()=>{const t=
|
|
5
|
+
`)(" "),n=(()=>{const r=lr("\r")(" "),o=(()=>{const i=lr(" ")(" ");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),pl={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"}},ml=t=>e=>{const n=hl(r=>{const o=hl(i=>{const a=(()=>{if(i.style==="RunText")return t.text;if(i.style==="RunBold")return{...t.text,weight:"700"};if(i.style==="RunCode")return t.code;if(i.style==="RunCodeBold")return{...t.code,weight:"700"};if(i.style==="RunHighlight")return t.text;if(i.style==="RunBoldHighlight")return{...t.text,weight:"700"};if(i.style==="RunCodeHighlight")return t.code;if(i.style==="RunCodeBoldHighlight")return{...t.code,weight:"700"};c()})();return WJ(a.family)(a.size)(a.weight)(Xi(i.text))})(Sn(r));return()=>{const i=o();return OJ(i)}})(wn(e));return()=>{const r=n();return b(HJ)(0)(r)}},$J=()=>()=>()=>t=>e=>n=>J2(n.type)(t)?w2(n.type)(t)(n.value):e(n),qJ={map:t=>e=>({type:e.type,value:e.map(t)(e.value),map:e.map})},VJ=t=>Af("Data.Functor.Variant: pattern match failure ["+t.type+"]"),UJ=()=>()=>()=>t=>$J()()()(t)(VJ);(function(){var t={},e="Pure",n="Throw",r="Catch",o="Sync",i="Async",a="Bind",s="Bracket",u="Fork",g="Sequential",_="Map",f="Apply",l="Alt",d="Cons",h="Resume",m="Release",p="Finalizer",x="Finalized",J="Forked";function w(O,z,Y,V){this.tag=O,this._1=z,this._2=Y,this._3=V}function N(O){var z=function(Y,V,X){return new w(O,Y,V,X)};return z.tag=O,z}function L(O){return new w(e,void 0)}function C(O){try{O()}catch(z){setTimeout(function(){throw z},0)}}function R(O,z,Y){try{return z(Y())}catch(V){return O(V)}}function P(O,z,Y){try{return z(Y)()}catch(V){return Y(O(V))(),L}}var I=(function(){var O=1024,z=0,Y=0,V=new Array(O),X=!1;function Z(){var nt;for(X=!0;z!==0;)z--,nt=V[Y],V[Y]=void 0,Y=(Y+1)%O,nt();X=!1}return{isDraining:function(){return X},enqueue:function(nt){var rt;z===O&&(rt=X,Z(),X=rt),V[(Y+z)%O]=nt,z++,X||Z()}}})();function U(O){var z={},Y=0,V=0;return{register:function(X){var Z=Y++;X.onComplete({rethrow:!0,handler:function(nt){return function(){V--,delete z[Z]}}})(),z[Z]=X,V++},isEmpty:function(){return V===0},killAll:function(X,Z){return function(){if(V===0)return Z();var nt=0,rt={};function ft(lt){rt[lt]=z[lt].kill(X,function(mt){return function(){delete rt[lt],nt--,O.isLeft(mt)&&O.fromLeft(mt)&&setTimeout(function(){throw O.fromLeft(mt)},0),nt===0&&Z()}})()}for(var Nt in z)z.hasOwnProperty(Nt)&&(nt++,ft(Nt));return z={},Y=0,V=0,function(lt){return new w(o,function(){for(var mt in rt)rt.hasOwnProperty(mt)&&rt[mt]()})}}}}}var S=0,v=1,F=2,H=3,M=4,q=5,$=6;function B(O,z,Y){var V=0,X=S,Z=Y,nt=null,rt=null,ft=null,Nt=null,lt=null,mt=0,vt=0,Ht=null,Tt=!0;function Vt(ct){for(var wt,It,yt;;)switch(wt=null,It=null,yt=null,X){case F:X=v;try{Z=ft(Z),Nt===null?ft=null:(ft=Nt._1,Nt=Nt._2)}catch(Ot){X=q,nt=O.left(Ot),Z=null}break;case H:O.isLeft(Z)?(X=q,nt=Z,Z=null):ft===null?X=q:(X=F,Z=O.fromRight(Z));break;case v:switch(Z.tag){case a:ft&&(Nt=new w(d,ft,Nt)),ft=Z._2,X=v,Z=Z._1;break;case e:ft===null?(X=q,Z=O.right(Z._1)):(X=F,Z=Z._1);break;case o:X=H,Z=R(O.left,O.right,Z._1);break;case i:X=M,Z=P(O.left,Z._1,function(Ot){return function(){V===ct&&(V++,I.enqueue(function(){V===ct+1&&(X=H,Z=Ot,Vt(V))}))}});return;case n:X=q,nt=O.left(Z._1),Z=null;break;case r:ft===null?lt=new w(d,Z,lt,rt):lt=new w(d,Z,new w(d,new w(h,ft,Nt),lt,rt),rt),ft=null,Nt=null,X=v,Z=Z._1;break;case s:mt++,ft===null?lt=new w(d,Z,lt,rt):lt=new w(d,Z,new w(d,new w(h,ft,Nt),lt,rt),rt),ft=null,Nt=null,X=v,Z=Z._1;break;case u:X=H,wt=B(O,z,Z._2),z&&z.register(wt),Z._1&&wt.run(),Z=O.right(wt);break;case g:X=v,Z=Q(O,z,Z._1);break}break;case q:if(ft=null,Nt=null,lt===null)X=$,Z=rt||nt||Z;else switch(wt=lt._3,yt=lt._1,lt=lt._2,yt.tag){case r:rt&&rt!==wt&&mt===0?X=q:nt&&(X=v,Z=yt._2(O.fromLeft(nt)),nt=null);break;case h:rt&&rt!==wt&&mt===0||nt?X=q:(ft=yt._1,Nt=yt._2,X=F,Z=O.fromRight(Z));break;case s:mt--,nt===null&&(It=O.fromRight(Z),lt=new w(d,new w(m,yt._2,It),lt,wt),(rt===wt||mt>0)&&(X=v,Z=yt._3(It)));break;case m:lt=new w(d,new w(x,Z,nt),lt,rt),X=v,rt&&rt!==wt&&mt===0?Z=yt._1.killed(O.fromLeft(rt))(yt._2):nt?Z=yt._1.failed(O.fromLeft(nt))(yt._2):Z=yt._1.completed(O.fromRight(Z))(yt._2),nt=null,mt++;break;case p:mt++,lt=new w(d,new w(x,Z,nt),lt,rt),X=v,Z=yt._1;break;case x:mt--,X=q,Z=yt._1,nt=yt._2;break}break;case $:for(var Ct in Ht)Ht.hasOwnProperty(Ct)&&(Tt=Tt&&Ht[Ct].rethrow,C(Ht[Ct].handler(Z)));Ht=null,rt&&nt?setTimeout(function(){throw O.fromLeft(nt)},0):O.isLeft(Z)&&Tt&&setTimeout(function(){if(Tt)throw O.fromLeft(Z)},0);return;case S:X=v;break;case M:return}}function Gt(ct){return function(){if(X===$)return Tt=Tt&&ct.rethrow,ct.handler(Z)(),function(){};var wt=vt++;return Ht=Ht||{},Ht[wt]=ct,function(){Ht!==null&&delete Ht[wt]}}}function bt(ct,wt){return function(){if(X===$)return wt(O.right(void 0))(),function(){};var It=Gt({rethrow:!1,handler:function(){return wt(O.right(void 0))}})();switch(X){case S:rt=O.left(ct),X=$,Z=rt,Vt(V);break;case M:rt===null&&(rt=O.left(ct)),mt===0&&(X===M&&(lt=new w(d,new w(p,Z(ct)),lt,rt)),X=q,Z=null,nt=null,Vt(++V));break;default:rt===null&&(rt=O.left(ct)),mt===0&&(X=q,Z=null,nt=null)}return It}}function pt(ct){return function(){var wt=Gt({rethrow:!1,handler:ct})();return X===S&&Vt(V),wt}}return{kill:bt,join:pt,onComplete:Gt,isSuspended:function(){return X===S},run:function(){X===S&&(I.isDraining()?Vt(V):I.enqueue(function(){Vt(V)}))}}}function D(O,z,Y,V){var X=0,Z={},nt=0,rt={},ft=new Error("[ParAff] Early exit"),Nt=null,lt=t;function mt(Gt,bt,pt){var ct=bt,wt=null,It=null,yt=0,Ct={},Ot,Dt;t:for(;;)switch(Ot=null,ct.tag){case J:if(ct._3===t&&(Ot=Z[ct._1],Ct[yt++]=Ot.kill(Gt,function(se){return function(){yt--,yt===0&&pt(se)()}})),wt===null)break t;ct=wt._2,It===null?wt=null:(wt=It._1,It=It._2);break;case _:ct=ct._2;break;case f:case l:wt&&(It=new w(d,wt,It)),wt=ct,ct=ct._1;break}if(yt===0)pt(O.right(void 0))();else for(Dt=0,Ot=yt;Dt<Ot;Dt++)Ct[Dt]=Ct[Dt]();return Ct}function vt(Gt,bt,pt){var ct,wt,It,yt,Ct,Ot;for(O.isLeft(Gt)?(ct=Gt,wt=null):(wt=Gt,ct=null);;){if(It=null,yt=null,Ct=null,Ot=null,Nt!==null)return;if(bt===null){V(ct||wt)();return}if(bt._3!==t)return;switch(bt.tag){case _:ct===null?(bt._3=O.right(bt._1(O.fromRight(wt))),wt=bt._3):bt._3=ct;break;case f:if(It=bt._1._3,yt=bt._2._3,ct){if(bt._3=ct,Ct=!0,Ot=nt++,rt[Ot]=mt(ft,ct===It?bt._2:bt._1,function(){return function(){delete rt[Ot],Ct?Ct=!1:pt===null?vt(ct,null,null):vt(ct,pt._1,pt._2)}}),Ct){Ct=!1;return}}else{if(It===t||yt===t)return;wt=O.right(O.fromRight(It)(O.fromRight(yt))),bt._3=wt}break;case l:if(It=bt._1._3,yt=bt._2._3,It===t&&O.isLeft(yt)||yt===t&&O.isLeft(It))return;if(It!==t&&O.isLeft(It)&&yt!==t&&O.isLeft(yt))ct=wt===It?yt:It,wt=null,bt._3=ct;else if(bt._3=wt,Ct=!0,Ot=nt++,rt[Ot]=mt(ft,wt===It?bt._2:bt._1,function(){return function(){delete rt[Ot],Ct?Ct=!1:pt===null?vt(wt,null,null):vt(wt,pt._1,pt._2)}}),Ct){Ct=!1;return}break}pt===null?bt=null:(bt=pt._1,pt=pt._2)}}function Ht(Gt){return function(bt){return function(){delete Z[Gt._1],Gt._3=bt,vt(bt,Gt._2._1,Gt._2._2)}}}function Tt(){var Gt=v,bt=Y,pt=null,ct=null,wt,It;t:for(;;)switch(wt=null,It=null,Gt){case v:switch(bt.tag){case _:pt&&(ct=new w(d,pt,ct)),pt=new w(_,bt._1,t,t),bt=bt._2;break;case f:pt&&(ct=new w(d,pt,ct)),pt=new w(f,t,bt._2,t),bt=bt._1;break;case l:pt&&(ct=new w(d,pt,ct)),pt=new w(l,t,bt._2,t),bt=bt._1;break;default:It=X++,Gt=q,wt=bt,bt=new w(J,It,new w(d,pt,ct),t),wt=B(O,z,wt),wt.onComplete({rethrow:!1,handler:Ht(bt)})(),Z[It]=wt,z&&z.register(wt)}break;case q:if(pt===null)break t;pt._1===t?(pt._1=bt,Gt=v,bt=pt._2,pt._2=t):(pt._2=bt,bt=pt,ct===null?pt=null:(pt=ct._1,ct=ct._2))}for(lt=bt,It=0;It<X;It++)Z[It].run()}function Vt(Gt,bt){Nt=O.left(Gt);var pt;for(var ct in rt)if(rt.hasOwnProperty(ct)){pt=rt[ct];for(ct in pt)pt.hasOwnProperty(ct)&&pt[ct]()}rt=null;var wt=mt(Gt,lt,bt);return function(It){return new w(i,function(yt){return function(){for(var Ct in wt)wt.hasOwnProperty(Ct)&&wt[Ct]();return L}})}}return Tt(),function(Gt){return new w(i,function(bt){return function(){return Vt(Gt,bt)}})}}function Q(O,z,Y){return new w(i,function(V){return function(){return D(O,z,Y,V)}})}return w.EMPTY=t,w.Pure=N(e),w.Throw=N(n),w.Catch=N(r),w.Sync=N(o),w.Async=N(i),w.Bind=N(a),w.Bracket=N(s),w.Fork=N(u),w.Seq=N(g),w.ParMap=N(_),w.ParApply=N(f),w.ParAlt=N(l),w.Fiber=B,w.Supervisor=U,w.Scheduler=I,w.nonCanceler=L,w})();const XJ=t=>e=>PJ(n=>r=>t({type:n.type,value:n.map(o=>r(o))(n.value),map:n.map}))(e),KJ=t=>{const e=t.Bind1(),n=t.Applicative0().pure;return r=>{const o=y2(()=>XJ(i=>e.bind(r(i))(o()))(n));return o()}};let yl=null;function YJ(){return yl||(typeof document>"u"?null:yl=document.createElement("canvas").getContext("2d"))}const Sc=new Map;function xl(t,e,n,r,o,i){const a=`${n} ${e}px ${t}`,s=a+"|"+r;if(Sc.has(s))return Sc.get(s);const u=YJ();if(!u)return i;u.font=a;const g=o(u.measureText(r)),_=typeof document<"u"?document.fonts:null;if(!_||_.check(a))Sc.set(s,g);else if(_&&_.load)try{_.load(a)}catch{}return g}const ZJ=(t,e,n,r)=>xl(t,e,n,r,o=>o.width,-1),jJ=(t,e,n,r)=>xl(t,e,n,r,o=>({ascent:o.actualBoundingBoxAscent,descent:o.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),ou=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Jl=t=>t,wl={map:t=>e=>{if(e.tag==="MeasureText")return ou("MeasureText",e._1,e._2,n=>t(e._3(n)));if(e.tag==="MeasureInk")return ou("MeasureInk",e._1,e._2,n=>t(e._3(n)));c()}},Ec=t=>e=>{const n=ZJ(t.family,t.size,t.weight,Xi(e));return n<0?ot(Ke(e).length)*t.size*.62:n},Rc=t=>e=>{const n=jJ(t.family,t.size,t.weight,Xi(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},tw=t=>e=>j(st("Bind",{type:"metrics",value:ou("MeasureInk",t,e,Jl),map:wl.map},n=>j(st("Return",n),gt)),gt),xo=t=>e=>j(st("Bind",{type:"metrics",value:ou("MeasureText",t,e,Jl),map:wl.map},n=>j(st("Return",n),gt)),gt),Tl=t=>t,Nl=t=>t,iu=t=>t,bl=t=>t,vl=t=>t,Kt=(t,e,n,r,o)=>({tag:t,_1:e,_2:n,_3:r,_4:o}),Cl=t=>t,Pc=t=>t,ew=Pc("BaselineTop"),Fn=Pc("BaselineMiddle"),nw=Pc("BaselineBottom"),wr=Cl("AlignLeft"),Aa=Cl("AlignCenter"),rn=vl("RoundJoin"),Ia=vl("MiterJoin"),Mn=bl("ButtCap"),Ar=bl("RoundCap"),rw=iu("LayerPolyOut"),ow=iu("LayerPolyIn"),iw=iu("LayerNodeMask"),aw=iu("LayerOverlay"),ei=Nl("NonZero"),Bc=Nl("EvenOdd"),Ll=Tl("Normal"),au=Tl("Difference"),we={r:255,g:255,b:255,a:255},Jo=[5],Ce={map:t=>e=>{if(e.tag==="FillPath")return Kt("FillPath",e._1,e._2,t(e._3));if(e.tag==="StrokePath")return Kt("StrokePath",e._1,e._2,t(e._3));if(e.tag==="FillStrokePath")return Kt("FillStrokePath",e._1,e._2,e._3,t(e._4));if(e.tag==="DrawText")return Kt("DrawText",e._1,t(e._2));if(e.tag==="DrawTextAffine")return Kt("DrawTextAffine",e._1,e._2,t(e._3));if(e.tag==="PushTransform")return Kt("PushTransform",e._1,t(e._2));if(e.tag==="PopTransform")return Kt("PopTransform",t(e._1));if(e.tag==="PushClip")return Kt("PushClip",e._1,e._2,t(e._3));if(e.tag==="PopClip")return Kt("PopClip",t(e._1));if(e.tag==="PushBlend")return Kt("PushBlend",e._1,t(e._2));if(e.tag==="PopBlend")return Kt("PopBlend",t(e._1));if(e.tag==="PushAlpha")return Kt("PushAlpha",e._1,t(e._2));if(e.tag==="PopAlpha")return Kt("PopAlpha",t(e._1));if(e.tag==="PushBlur")return Kt("PushBlur",e._1,t(e._2));if(e.tag==="PopBlur")return Kt("PopBlur",t(e._1));if(e.tag==="PushLayer")return Kt("PushLayer",e._1,t(e._2));if(e.tag==="PopLayer")return Kt("PopLayer",t(e._1));if(e.tag==="SetViewport")return Kt("SetViewport",e._1,t(e._2));if(e.tag==="ClearBackground")return Kt("ClearBackground",e._1,t(e._2));if(e.tag==="BackgroundDots")return Kt("BackgroundDots",e._1,t(e._2));c()}},jr={r:26,g:26,b:26,a:255},Gc=t=>e=>Math.imul(t,e),Ki=t=>{const e=t+1831565813|0,n=Gc(e^e>>>15)(e|1),r=n^(n+Gc(n^n>>>7)(n|61)|0),o=r^r>>>14;return{prng:o,value:o<0?(ot(o)+4294967296)/4294967296:ot(o)/4294967296}},Pe=t=>e=>n=>{const r=Ki(n);return{prng:r.prng,value:t+r.value*(e-t)}},Ac=t=>e=>b(n=>r=>Gc(n^r)(-2048144789))(e)(K(Yr)(tr(t))),sw=t=>t,kl=t=>t,uw=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},En=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Sl=t=>e=>n=>{const r=ut.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=ut.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},Ic=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},gw=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},cw=kl("FlatLevel"),_w=kl("NestedLevel"),zc=sw("GenieSilhouette"),fw=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const o=Ki(t);return{prng:o.prng,yLift:o.value*n.yJitter*r}},lw=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const o=Ki(t);return{prng:o.prng,dx:(o.value*2-1)*n.xJitter*r}},El=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,o=qe(r*r+n*n),i=(t.r*t.r-e.r*e.r+o*o)/(2*o),a=qe(uw(0)(t.r*t.r-i*i)),s=t.cx+i*r/o,u=t.cy+i*n/o,g={x:s-a*n/o,y:u+a*r/o},_={x:s+a*n/o,y:u-a*r/o};return o===0||o>t.r+e.r?{x:(t.cx+e.cx)/2,y:t.cy}:g.y<_.y?g:_},su=t=>e=>{const n=En(e)(En(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]},dw=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=Ki(t);return{prng:a.prng,r:o*(1+a.value*i.rJitter)}},Rl=t=>{const e=En(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]},hw=t=>e=>n=>{const r=Ki(t),o=e.length;return o===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const i=Sl(0)(o-1|0)(he(sr(r.value*ot(n))));return i>=0&&i<e.length?e[i]:-1})()}},pw=t=>e=>{const n=Ki(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const o=Sl(0)(r-1|0)(he(sr(n.value*ot(r))));return o>=0&&o<e.length?e[o]:-1})()}},Pl=t=>{const e=En(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]},Bl=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],Gl={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},mw=t=>{const e=En(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]},Al=t=>{const e=En(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]},Il=t=>e=>{const n=e.y+e.h,r=ly(t.rBase*e.h)(e.w/(2*(1+(ot(t.minN)-1)*t.stepRatio))),o=e.w-2*r,i=2*r*t.stepRatio,a=Ic(t.minN)(o<=0||i<=0?t.minN:he(Kn(o/i))+1|0),s=a>=3?Ut(1,a-2|0):[],u=s.length,g=Sr(u+1|0,2),_=g<1?[]:At(0,g,s),f=pw(t.seed)((()=>{const p=u-g|0;return p<1?s:At(p,s.length,s)})()),l=f.idx,d=hw(f.prng)(_t(p=>p!==l,_))(Ic(1)(_.length-(yn(go)(l)(_)?1:0)|0)),h=d.idx,m=a>=2?o/(ot(a)-1):0;return b(p=>x=>{const J=x===h,w=x===l,N=x===0||x===(a-1|0),L=dw(p.prng)(N)(w)(J)(r)(t),C=fw(L.prng)(N)(t)(e.h),R=lw(C.prng)(N)(t)(m);return{prng:R.prng,circles:Et(p.circles)({cx:e.x+gw(L.r)(e.w-L.r)((a>=2?r+ot(x)/(ot(a)-1)*o+R.dx:r+0*o+R.dx)+(w?t.heroShift*m:J?-1*t.smallShift*m:0)),cy:n-C.yLift,r:L.r})}})({prng:d.prng,circles:[]})(Ut(0,a-1|0)).circles},zl=t=>e=>{const n=t.length;return Ft(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?El(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?El(o)(t[i]):{x:o.cx+o.r,y:e}})()}))(t)},Dl=t=>{const e=En(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]},yw=t=>e=>n=>{const r=Oo(e.y-t.cy)(e.x-t.cx),o=Oo(n.y-t.cy)(n.x-t.cx),i=o>r?o-r:o+6.283185307179586-r,a=Ic(1)(he(Cs(i/1.5707963267948966))),s=i/ot(a),u=1.3333333333333333*dy(s/4);return St(Ut(0,a-1|0))(g=>{const _=r+ot(g+1|0)*s,f=t.cx+t.r*xn(_),l=t.cy+t.r*en(_),d=r+ot(g)*s;return[4,t.cx+t.r*xn(d)-u*t.r*en(d),t.cy+t.r*en(d)+u*t.r*xn(d),f+u*t.r*en(_),l-u*t.r*xn(_),f,l]})},Fl=t=>e=>{const n=t.h*.38,r=zl(Il(Gl)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),o=En(e)(En(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...St(r)(i=>yw(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]:su(t)(e)},ni=t=>e=>n=>r=>o=>i=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(o)(i);if(e==="Cylinder"){const a=Al(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);c()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}c()}if(e==="Parallelogram"){const a=Pl(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);c()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}c()}if(e==="Diamond"){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);c()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}c()}if(e==="Ellipse"){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);c()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}c()}if(e==="Document"){const a=Bl(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);c()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}c()}if(e==="Cloud"){const a=Fl(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);c()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(a)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}c()}return t.drawRoundedRect(n)(r)(o)(i)},xw={fillPath:t=>e=>j(st("Bind",{type:"render",value:Kt("FillPath",t,e,void 0),map:Ce.map},n=>j(st("Return",n),gt)),gt),strokePath:t=>e=>j(st("Bind",{type:"render",value:Kt("StrokePath",t,e,void 0),map:Ce.map},n=>j(st("Return",n),gt)),gt),fillStrokePath:t=>e=>n=>j(st("Bind",{type:"render",value:Kt("FillStrokePath",t,e,n,void 0),map:Ce.map},r=>j(st("Return",r),gt)),gt),drawRoundedRect:t=>e=>n=>r=>{if(n.tag==="Just"){if(r.tag==="Just")return j(st("Bind",{type:"render",value:Kt("FillStrokePath",su(t)(e),n._1,r._1,void 0),map:Ce.map},o=>j(st("Return",o),gt)),gt);if(r.tag==="Nothing")return j(st("Bind",{type:"render",value:Kt("FillPath",su(t)(e),n._1,void 0),map:Ce.map},o=>j(st("Return",o),gt)),gt);c()}if(n.tag==="Nothing"){if(r.tag==="Just")return j(st("Bind",{type:"render",value:Kt("StrokePath",su(t)(e),r._1,void 0),map:Ce.map},o=>j(st("Return",o),gt)),gt);if(r.tag==="Nothing")return j(st("Return",void 0),gt)}c()},drawText:t=>j(st("Bind",{type:"render",value:Kt("DrawText",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),drawTextAffine:t=>e=>j(st("Bind",{type:"render",value:Kt("DrawTextAffine",t,e,void 0),map:Ce.map},n=>j(st("Return",n),gt)),gt),pushTransform:t=>j(st("Bind",{type:"render",value:Kt("PushTransform",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),popTransform:j(st("Bind",{type:"render",value:Kt("PopTransform",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),pushBakedTransform:t=>j(st("Bind",{type:"render",value:Kt("PushTransform",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),popBakedTransform:j(st("Bind",{type:"render",value:Kt("PopTransform",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),pushClip:t=>e=>j(st("Bind",{type:"render",value:Kt("PushClip",t,e,void 0),map:Ce.map},n=>j(st("Return",n),gt)),gt),popClip:j(st("Bind",{type:"render",value:Kt("PopClip",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),pushBlend:t=>j(st("Bind",{type:"render",value:Kt("PushBlend",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),popBlend:j(st("Bind",{type:"render",value:Kt("PopBlend",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),pushAlpha:t=>j(st("Bind",{type:"render",value:Kt("PushAlpha",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),popAlpha:j(st("Bind",{type:"render",value:Kt("PopAlpha",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),pushBlur:t=>j(st("Bind",{type:"render",value:Kt("PushBlur",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),popBlur:j(st("Bind",{type:"render",value:Kt("PopBlur",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),pushLayer:t=>j(st("Bind",{type:"render",value:Kt("PushLayer",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),popLayer:j(st("Bind",{type:"render",value:Kt("PopLayer",void 0),map:Ce.map},t=>j(st("Return",t),gt)),gt),setViewport:t=>j(st("Bind",{type:"render",value:Kt("SetViewport",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),clearBackground:t=>j(st("Bind",{type:"render",value:Kt("ClearBackground",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),backgroundDots:t=>j(st("Bind",{type:"render",value:Kt("BackgroundDots",t,void 0),map:Ce.map},e=>j(st("Return",e),gt)),gt),measureText:t=>e=>xo(t)(e),measureInk:t=>e=>tw(t)(e),insideTokenStyle:t=>j(st("Return",zc),gt),Monad0:()=>Lc},Ir=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Ml=b(ur)(0),Ql=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},Jw=b(t=>e=>t+e.len)(0),Wl=t=>{const e=Bt(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(At(1,t.length,t))(n=>[2,n.x,n.y]),5];c()},ww=t=>e=>{const n=Ir(e)(Ir(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]},Tw=t=>{const e=Bt(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(e._1.tail)(n=>[2,n.x,n.y])];c()},wo=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return Al(e);if(t.shape==="Parallelogram")return Pl(e);if(t.shape==="Diamond")return Dl(e);if(t.shape==="Ellipse")return Rl(e);if(t.shape==="Document")return Bl(e);if(t.shape==="Cloud")return Fl(e)(7);if(t.shape==="Rectangle")return ww(e)(7);c()},De=t=>e=>n=>K(r=>{const o=ot(r)/ot(n);return{x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o}})(Ut(0,n-1|0)),Nw=t=>{const e=En(t.w*.18)(t.h*.6);return[...De({x:t.x+e,y:t.y})({x:t.x+t.w,y:t.y})(16),...De({x:t.x+t.w,y:t.y})({x:t.x+t.w-e,y:t.y+t.h})(16),...De({x:t.x+t.w-e,y:t.y+t.h})({x:t.x,y:t.y+t.h})(16),...De({x:t.x,y:t.y+t.h})({x:t.x+e,y:t.y})(16)]},Dc=t=>e=>{const n=Ir(t)(Ir(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}},Fc=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return qe(r*r+n*n)},bw=t=>We(e=>n=>({a:e,b:n,len:Fc(e)(n)}),t,At(1,t.length,t)),Ol=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?T("Just",e[n]):y,o=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];c()})(),i=0<e.length?T("Just",e[0]):y,a=(()=>{if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return{x:0,y:0};c()})(),s=e.length;return s<3?e:[a,...St(Ut(1,s-2|0))(u=>{const g=u+1|0,_=g>=0&&g<e.length?T("Just",e[g]):y,f=u>=0&&u<e.length?T("Just",e[u]):y,l=u-1|0,d=l>=0&&l<e.length?T("Just",e[l]):y;if(d.tag==="Just"&&f.tag==="Just"&&_.tag==="Just"){const h=f._1,m=Fc(h)(_._1),p=Fc(d._1)(h),x=Ir(t)(m/2),J=Ir(t)(p/2),w=m>0?x/m:0,N=h.x+(_._1.x-h.x)*w,L=h.y+(_._1.y-h.y)*w,C=p>0?J/p:0,R=h.x+(d._1.x-h.x)*C,P=h.y+(d._1.y-h.y)*C;return K(I=>{const U=ot(I)/ot(10),S=1-U;return{x:S*S*R+2*S*U*h.x+U*U*N,y:S*S*P+2*S*U*h.y+U*U*L}})(Ut(0,10))}return[]}),...o]},vw=t=>e=>n=>r=>o=>K(i=>{const a=ot(i)/ot(o),s=1-a,u=a*a*a,g=3*s*a*a,_=3*s*s*a,f=s*s*s;return{x:f*t.x+_*e.x+g*n.x+u*r.x,y:f*t.y+_*e.y+g*n.y+u*r.y}})(Ut(0,o-1|0)),Cw=t=>[...De({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...De({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...vw({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),...De({x:t.x,y:t.y+t.h*.85})({x:t.x,y:t.y})(12)],Hl=t=>e=>K(n=>{const r=6.283185307179586*ot(n)/ot(64);return{x:t.x+e*xn(r),y:t.y+e*en(r)}})(Ut(0,63)),$l=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]},Lw=t=>{const e=t.y+t.h/2,n=En(t.h*.4)(t.w*.2);return[...De({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...De({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...De({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...De({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...De({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...De({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},Mc=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:Ml(K(n=>n.x)(t))/ot(e),y:Ml(K(n=>n.y)(t))/ot(e)}},uu=t=>e=>n=>r=>o=>K(i=>{const a=n+(r-n)*(ot(i)/ot(o));return{x:t.x+e*xn(a),y:t.y+e*en(a)}})(Ut(0,o-1|0)),Qc=t=>e=>{const n=Ir(t)(Ir(e.w/2)(e.h/2));return[...De({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...uu({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...De({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...uu({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...De({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...uu({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...De({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...uu({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},gu=t=>e=>n=>r=>o=>i=>K(a=>{const s=r+(o-r)*(ot(a)/ot(i));return{x:t.x+e*xn(s),y:t.y+n*en(s)}})(Ut(0,i-1|0)),kw=t=>{const e=t.h*.38;return[...St(zl(Il(Gl)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=Oo(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),o=Oo(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return gu({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(o)(r>o?r:r+6.283185307179586)(16)}),...De({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...De({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...De({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},Sw=t=>{const e=Ir(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[...gu({x:i,y:r})(n)(e)(3.141592653589793)(6.283185307179586)(24),...De({x:t.x+t.w,y:r})({x:t.x+t.w,y:o})(12),...gu({x:i,y:o})(n)(e)(0)(3.141592653589793)(24),...De({x:t.x,y:o})({x:t.x,y:r})(12)]},ri=t=>e=>e.shape==="Cylinder"?Sw(e):e.shape==="Parallelogram"?Nw(e):e.shape==="Diamond"?Lw(e):e.shape==="Ellipse"?Qc(En(e.w)(e.h)/2)(e):e.shape==="Document"?Cw(e):e.shape==="Cloud"?kw(e):Qc(t)(e),Ew=t=>{const e=Ir(t.h*.075)(t.w*.075),n=t.w/2;return gu({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},Rw=t=>e=>n=>b(r=>o=>{const i=r.pos+o.len,a=n<i?(n-r.pos)/o.len:1,s={x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a},u=e>r.pos?(e-r.pos)/o.len:0,g={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,f=_>=0&&_<r.points.length?(()=>{const l=r.points[_].x-g.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const d=r.points[_].y-g.y;return d<0?-d<1e-4:d<1e-4})()})()?Et(r.points)(s):[...r.points,g,s]:[g,s];return o.len<=0||i<=e||r.pos>=n?{...r,pos:i}:{pos:i,points:f}})({pos:0,points:[]})(t).points,Pw=t=>e=>n=>{const r=Bt(o=>y,o=>i=>T("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const o=bw(t),i=Jw(o),a=Ql(0)(i)(e*i),s=Ql(0)(i)(n*i);return s<=a?[]:Rw(o)(a)(s)}c()},Bw=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,g=n.y-t.y,_=a*i-s*o,f=(u*i-g*o)/_,l=(u*s-g*a)/_;return(_<0?-_<1e-9:_<1e-9)?y:f>=0&&f<=1&&l>=0&&l<=1?T("Just",f):y},Gw=t=>e=>n=>{const r=Rt(o=>i=>at.compare(o.t)(i.t))(ht(o=>{const i=Bw(e)(n)(o._1)(o._2);return i.tag==="Just"?T("Just",{t:i._1,p:{x:e.x+(n.x-e.x)*i._1,y:e.y+(n.y-e.y)*i._1}}):y})(We(mn,t,[...At(1,t.length,t),...At(0,1,t)])));return 0<r.length?T("Just",r[0].p):y},ql=t=>e=>{const n=Rr(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=Gw(t)(n._1.init[r])(n._1.last);if(o.tag==="Just")return Et(n._1.init)(o._1);if(o.tag==="Nothing")return e;c()}return e}c()},Vl=t=>t,cu=(t,e)=>({tag:t,_1:e}),Yi=(t,e,n)=>({tag:t,_1:e,_2:n}),Ul=t=>t,oi=(t,e,n,r,o,i,a,s,u)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:a,_7:s,_8:u}),Wc=Ul("PlopIn"),Aw=Ul("PlopOut"),Iw=Vl("DiveIn"),zw=Vl("DiveOut"),Xl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Zi=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=G.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}}c()}return o},ji=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=G.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}}c()}return o},Oc=(()=>{const t=gn.unfoldr(jn);return e=>t(cn("IterNode",e,Yn))})(),Dw=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;c()},Hc=t=>e=>{const n=Xl(e)(t.keyframes);if(n.tag==="Nothing")return W;if(n.tag==="Just")return n._1.nodes;c()},Kl=t=>e=>Zi(e)(t.activePlopOuts)?!0:Zi(e)(t.pastPlopOuts)?!1:Zi(e)(t.activeNodes)?!0:Zi(e)(t.futurePlopIns)?!1:Zi(e)(t.currentNodes),Fw=t=>e=>n=>oe(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),Mw=t=>e=>n=>oe(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),Qw=t=>e=>n=>oe(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),Ww=t=>e=>n=>oe(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),_u=t=>e=>n=>oe(r=>n(r)&&e>=r.startT&&e<r.endT,t),Ow=b(Dw),ta=t=>e=>{if(e<t.startT)return Yi("AtKeyframe",t.initialKeyframe);const n=te(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Yi("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Yi("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return Yi("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode"||n._1.scene.tag==="StepScene")return Yi("AtKeyframe",t.initialKeyframe);c()}if(n.tag==="Nothing")return Yi("AtKeyframe",Ow(t.initialKeyframe)(t.spans));c()},$c=t=>e=>{const n=Xl(e)(t.keyframes);if(n.tag==="Nothing")return W;if(n.tag==="Just")return n._1.edges;c()},Hw=t=>e=>ji(e)(t.activeRetracts)?!0:ji(e)(t.pastRetracts)?!1:ji(e)(t.activeEdges)?!0:ji(e)(t.futureExtends)?!1:ji(e)(t.currentEdges),qc=t=>e=>{const n=ta(t)(e);if(n.tag==="AtKeyframe")return Hc(t)(n._1);if(n.tag==="InTransition")return nn(G.compare,tn,Hc(t)(n._1),Hc(t)(n._2));c()},Yl=t=>e=>n=>_u(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n&&r.target._2==="PlopOut")?!0:Mw(t.windows)(e)(n)?!1:_u(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n)?!0:Qw(t.windows)(e)(n)?!1:Zi(n)(qc(t)(e)),Vc=t=>e=>{const n=ta(t)(e);if(n.tag==="AtKeyframe")return $c(t)(n._1);if(n.tag==="InTransition")return nn(G.compare,tn,$c(t)(n._1),$c(t)(n._2));c()},$w=t=>e=>n=>_u(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n)?!0:Fw(t.windows)(e)(n)?!1:_u(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._1===n)?!0:Ww(t.windows)(e)(n)?!1:ji(n)(Vc(t)(e)),Zl=t=>e=>b(n=>r=>{const o=e>=r.startT&&e<r.endT;return r.target.tag==="NodeWindow"?{...n,activeNodes:o?it(G)(r.target._1)()(n.activeNodes):n.activeNodes,activePlopOuts:o&&r.target._2==="PlopOut"?it(G)(r.target._1)()(n.activePlopOuts):n.activePlopOuts,pastPlopOuts:r.endT<=e&&r.target._2==="PlopOut"?it(G)(r.target._1)()(n.pastPlopOuts):n.pastPlopOuts,futurePlopIns:r.startT>e&&r.target._2==="PlopIn"?it(G)(r.target._1)()(n.futurePlopIns):n.futurePlopIns}:r.target.tag==="EdgeWindow"?{...n,activeEdges:o?it(G)(r.target._1)()(n.activeEdges):n.activeEdges,activeRetracts:o&&r.target._2.tag==="Retract"?it(G)(r.target._1)()(n.activeRetracts):n.activeRetracts,pastRetracts:r.endT<=e&&r.target._2.tag==="Retract"?it(G)(r.target._1)()(n.pastRetracts):n.pastRetracts,futureExtends:r.startT>e&&r.target._2.tag==="Extend"?it(G)(r.target._1)()(n.futureExtends):n.futureExtends}:n})({currentNodes:qc(t)(e),currentEdges:Vc(t)(e),activeNodes:W,activePlopOuts:W,pastPlopOuts:W,futurePlopIns:W,activeEdges:W,activeRetracts:W,pastRetracts:W,futureExtends:W})(t.windows),qw=t=>e=>{const n=Zl(t)(e);return ht(r=>Kl(n)(r._1)?T("Just",{x:r._2.x,y:r._2.y,w:r._2.w,h:r._2.h}):y)(Oc(t.layout.nodes))},Vw=t=>e=>{const n=qw(t)(e);return n.length===0?y:T("Just",ae(n))},za=t=>e=>{const n=Zl(t)(e),r=[...ht(o=>Kl(n)(o._1)?T("Just",{x:o._2.x,y:o._2.y,w:o._2.w,h:o._2.h}):y)(Oc(t.layout.nodes)),...ht(o=>Hw(n)(o._1)?T("Just",Pa(o._2)):y)(Oc(t.layout.edges))];return r.length===0?y:T("Just",ae(r))},Uw=t=>e=>e.map(t),ne=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},on=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},Ye=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Xw=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Rn=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},To=bs(zi),ii=t=>t,jl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Tr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Kw=(()=>{const t=gn.unfoldr(jn);return e=>t(cn("IterNode",e,Yn))})(),Yw=t=>e=>on(0)(1)((t-e.pre)/ne(.05)(1-e.pre-e.post)),td=t=>e=>n=>{const r=Ye(n)(t.nodes),o=Ye(e)(t.nodes);if(o.tag==="Just"&&r.tag==="Just"){const i=r._1.x+r._1.w/2-(o._1.x+o._1.w/2),a=r._1.y+r._1.h/2-(o._1.y+o._1.h/2),s=ne(xe(i))(xe(a));return s<=.001?{x:0,y:0}:{x:i/s,y:a/s}}return{x:0,y:0}},Uc=t=>e=>n=>r=>o=>i=>{const a=s=>{if(s)return 0<e.length?e[0]:{x:0,y:0};const u=e.length-1|0;return u>=0&&u<e.length?e[u]:{x:0,y:0}};return NJ(e)((()=>{const s=a(!0),u=Ye(n)(t.nodes);return u.tag==="Just"?{x:u._1.x+u._1.w/2,y:u._1.y+u._1.h/2}:s})())((()=>{const s=a(!1),u=Ye(r)(t.nodes);return u.tag==="Just"?{x:u._1.x+u._1.w/2,y:u._1.y+u._1.h/2}:s})())(o)(i)},Zw=t=>e=>t.labelBasePx*.62*ot(b(Xw)(0)(K(mJ)(St(e)(n=>$i(`
|
|
6
|
+
`)(n))))),fu=t=>e=>n=>on(0)(1)((n-t)/ne(1e-4)(e-t)),jw=t=>e=>ot(zn(Dn(e)))*t*.62,ed=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,g=o<0?-o:o;return e<=t?(t+e)/2:g<=u?n:r+i*(a-s*_o(-(g-u)/s))},Xc=t=>e=>n=>({...n,center:{x:e.w>t.w?n.center.x+(e.x+e.w/2-(t.x+t.w/2)):e.x<t.x?n.center.x+(e.x-t.x):e.x+e.w>t.x+t.w?n.center.x+(e.x+e.w-t.x-t.w):n.center.x+0,y:e.h>t.h?n.center.y+(e.y+e.h/2-(t.y+t.h/2)):e.y<t.y?n.center.y+(e.y-t.y):e.y+e.h>t.y+t.h?n.center.y+(e.y+e.h-t.y-t.h):n.center.y+0}}),Da=t=>e=>n=>r=>{const o=te(i=>To(i.path)(e)&&(xe(i.endT-n)<1e-4||xe(i.startT-r)<1e-4))(t.segments);if(o.tag==="Just")return T("Just",o._1);if(o.tag==="Nothing")return te(i=>To(i.path)(e))(t.segments);c()},tT=t=>ht(e=>{const n=Vw(t)(ne(e.startT)(e.endT-1e-4));if(n.tag==="Nothing")return y;if(n.tag==="Just")return T("Just",{startT:e.startT,endT:e.endT,bbox:n._1,priority:0,continuous:!1,stationary:!1});c()}),eT=t=>e=>{const n=Cc({width:t.widthPx,height:t.heightPx})({vx:e.bounds.x,vy:e.bounds.y,vw:e.bounds.w,vh:e.bounds.h});return{w:n.vw,h:n.vh}},nT=t=>e=>n=>r=>{const o=ne(n.center.x-r.x)(r.x+r.w-n.center.x),i=ne(n.center.y-r.y)(r.y+r.h-n.center.y),a=eT(t)(e);return Rn(o<=0?n.zoom:a.w/(o*2))(i<=0?n.zoom:a.h/(i*2))},nd=t=>e=>n=>r=>o=>{const i=(s,u)=>{const g=wn(u);return kn(Ft(_=>f=>{const l=t*1.2,d=s.y+s.h/2-ot(g.length)*l/2+ot(_)*l;return b(h=>m=>{const p=ot(zn(Dn(m.text)))*t*.62;return{x:h.x+p,boxes:m.style==="RunHighlight"||m.style==="RunBoldHighlight"||m.style==="RunCodeHighlight"||m.style==="RunCodeBoldHighlight"?Et(h.boxes)({x:h.x,y:d,w:p,h:l}):h.boxes}})({x:s.x+s.w/2-ot(zn(Dn(f)))*t*.62/2,boxes:[]})(Sn(f)).boxes})(g))},a=Ye(n)(e.layout.nodes);if(a.tag==="Just"){const s=[...i(a._1,r),...i(a._1,o)];return s.length===0?y:T("Just",ae(s))}if(a.tag==="Nothing")return y;c()},Kc=t=>e=>n=>{const r=wn(n),o=b(ne)(t)(K(jw(t))(r)),i=ne(t)(ot(r.length)*t*1.2);return T("Just",{x:e.x+e.w/2-o/2,y:e.y+e.h/2-i/2,w:o,h:i})},rT=t=>e=>n=>r=>{const o=b(ne)(r.startT-t.maxTransition)(ht(i=>i.startT>r.startT+1e-4?y:i.target.tag==="NodeWindow"&&i.target._2==="PlopIn"&&i.target._1===r.target?T("Just",i.startT):y)(e.windows));return on(0)(1)((n-o)/ne(1e-4)(r.startT-o))},rd=t=>{const e=Bt(n=>y,n=>r=>T("Just",{head:n,tail:r}),ht(ii)(t));if(e.tag==="Nothing")return y;if(e.tag==="Just")return T("Just",b(n=>r=>({whole:ae([n.whole,r.whole]),text:(()=>{if(n.text.tag==="Just"){if(r.text.tag==="Just")return T("Just",ae([n.text._1,r.text._1]));if(r.text.tag==="Nothing")return T("Just",n.text._1);c()}if(n.text.tag==="Nothing"){if(r.text.tag==="Just")return T("Just",r.text._1);if(r.text.tag==="Nothing")return y}c()})(),guide:(()=>{if(n.guide.tag==="Just"){if(r.guide.tag==="Just")return T("Just",ae([n.guide._1,r.guide._1]));if(r.guide.tag==="Nothing")return T("Just",n.guide._1);c()}if(n.guide.tag==="Nothing"){if(r.guide.tag==="Just")return T("Just",r.guide._1);if(r.guide.tag==="Nothing")return y}c()})()}))(e._1.head)(e._1.tail));c()},oT=t=>e=>n=>r=>({...r,fromCam:yc(t)(e)(n)(r.fromCam),toCam:yc(t)(e)(n)(r.toCam)}),iT=t=>e=>n=>r=>o=>i=>a=>{const s=a*a*(3-2*a),u=td(t)(e)(n),g=(()=>{if(r)return 1;const f=on(0)(1)(i/.12);return f*f*(3-2*f)})(),_={x:0+(u.x-0)*g,y:0+(u.y-0)*g};if(o.tag==="Just"){const f=td(t)(o._1.source)(o._1.target);return{x:_.x+(f.x-_.x)*s,y:_.y+(f.y-_.y)*s}}if(o.tag==="Nothing")return _;c()},aT=t=>e=>n=>oe(r=>r.endT<=e&&r.target.tag==="RelabelWindow"&&r.target._1===n,t),sT=t=>e=>n=>{const r=Ye(n)(t.layout.nodes),o=r.tag==="Just"&&r._1.label!==""?r._1.label:n,i=ta(t)(e),a=(()=>{if(i.tag==="AtKeyframe")return jl(i._1)(t.keyframes);if(i.tag==="InTransition")return jl(aT(t.windows)(e)(n)?i._2:i._1)(t.keyframes);c()})(),s=(()=>{if(a.tag==="Just")return Ye(n)(a._1.labels);if(a.tag==="Nothing")return y;c()})();if(s.tag==="Nothing")return o;if(s.tag==="Just")return s._1;c()},lu=t=>e=>n=>r=>{const o=Ye(r)(e.layout.nodes);if(o.tag==="Just")return Kc(t)(o._1)(sT(e)(n)(r));if(o.tag==="Nothing")return y;c()},uT=t=>e=>n=>{if(e.length===0)return n;const r=Rn(160)(Zw(t)(e)+32)/2;return{x:n.x-r,y:n.y-30.6,w:n.w+r+r,h:n.h+40.6}},ai=t=>e=>n=>r=>o=>{const i={width:e.widthPx,height:e.heightPx},a=Cc(i)((()=>{if(r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0){const s=_r(n)(o);return{vx:s.x-t.padding,vy:s.y-t.padding,vw:s.w+t.padding*2,vh:s.h+t.padding*2}}return{vx:_r(n)(o).x,vy:_r(n)(o).y,vw:_r(n)(o).w,vh:_r(n)(o).h}})());return t.labelBasePx*r.placement.scale*(i.width<=0||a.vw<=0?0:i.width/a.vw)},od=t=>e=>n=>r=>(o=>i=>{let a=o,s=i,u=!0,g;for(;u;){const _=a,f=s,l=ai(t)(e)(n)(r)(f);if(e.widthPx<=0||e.heightPx<=0||l<=0||l>=t.minimumReadableLabelPx){u=!1,g=f;continue}if(_<=0){u=!1,g=f;continue}a=_-1|0,s={...f,zoom:f.zoom*t.minimumReadableLabelPx/l}}return g})(8),fn=t=>e=>n=>r=>{const o=Cc({width:t.widthPx,height:t.heightPx})((()=>{const i=_r(n)(r);return{vx:i.x-e,vy:i.y-e,vw:i.w+e*2,vh:i.h+e*2}})());return{x:o.vx,y:o.vy,w:o.vw,h:o.vh}},gT=t=>e=>n=>r=>{const o=Ye(e)(t.nodes);if(o.tag==="Just"){const i=o._1.x+o._1.w/2,a=o._1.y+o._1.h/2,s=Ye(n)(t.nodes);if(s.tag==="Just")return T("Just",{x:i+(s._1.x+s._1.w/2-i)*r-6,y:a+(s._1.y+s._1.h/2-a)*r-6,w:12,h:12})}return y},Yc=t=>e=>n=>r=>o=>i=>{const a=K((()=>{const s=t.padding;return u=>({x:u.x-s,y:u.y-s,w:u.w+s*2,h:u.h+s*2})})())(ht(lu(t.labelBasePx)(e)(n))([r,o]));return a.length===0?i:ae([i,...a])},cT=t=>e=>n=>r=>o=>i=>a=>s=>{const u=Yc(t)(e)(n)(r)(o)(s);if(i.tag==="Nothing")return u;if(i.tag==="Just"){const g=Yc(t)(e)(n)(i._1.source)(i._1.target)(s),_=a*a*(3-2*a);return{x:u.x+(g.x-u.x)*_,y:u.y+(g.y-u.y)*_,w:u.w+(g.w-u.w)*_,h:u.h+(g.h-u.h)*_}}c()},id=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>{const _=i.x-6,f=i.y-6;return T("Just",{visibleBounds:(()=>{const l=za(e)(n);return l.tag==="Just"?T("Just",{x:l._1.x*e.placement.scale+e.placement.tx,y:l._1.y*e.placement.scale+e.placement.ty,w:l._1.w*e.placement.scale,h:l._1.h*e.placement.scale}):y})(),subject:T("Just",{x:_*e.placement.scale+e.placement.tx,y:f*e.placement.scale+e.placement.ty,w:12*e.placement.scale,h:12*e.placement.scale}),guide:(()=>{const l=gT(e.layout)(r)(o)(a);return l.tag==="Just"?T("Just",{x:l._1.x*e.placement.scale+e.placement.tx,y:l._1.y*e.placement.scale+e.placement.ty,w:l._1.w*e.placement.scale,h:l._1.h*e.placement.scale}):y})(),mustSee:T("Just",(()=>{const l=cT(t)(e)(n)(r)(o)(g)(s)({x:_-t.padding,y:f-t.padding,w:12+t.padding*2,h:12+t.padding*2});return{x:l.x*e.placement.scale+e.placement.tx,y:l.y*e.placement.scale+e.placement.ty,w:l.w*e.placement.scale,h:l.h*e.placement.scale}})()),lookAhead:T("Just",iT(e.layout)(r)(o)(u)(g)(a)(s))})},du=t=>e=>n=>r=>o=>i=>{const a=Yc(t)(e)(n)(r)(o)(i);return{x:a.x,y:i.y,w:a.w,h:i.h}},_T=t=>e=>n=>r=>o=>i=>a=>s=>{let u=t,g=e,_=n,f=r,l=o,d=i,h=a,m=s,p=!0,x;for(;p;){const J=u,w=g,N=_,L=f,C=l,R=d,P=h,I=m,U=N.path.length!==0,S=fn(J)(N.path.length===0||N.placement.scale===1&&N.placement.tx===0&&N.placement.ty===0?L.padding:0)(w)(I),v=ne(R)(I.zoom*Rn(S.w/ne(1e-4)(C.w))(S.h/ne(1e-4)(C.h)));if(P<=0){p=!1,x=I;continue}if(U&&xe(v-I.zoom)<1e-6){p=!1,x=I;continue}if(U){u=J,g=w,_=N,f=L,l=C,d=R,h=P-1|0,m={...I,zoom:v};continue}if(C.w<=S.w+.001&&C.h<=S.h+.001){p=!1,x=I;continue}if(v>=I.zoom-1e-6){p=!1,x=I;continue}u=J,g=w,_=N,f=L,l=C,d=R,h=P-1|0,m={...I,zoom:v}}return x},fT=t=>e=>n=>r=>{const o=Tr(r)(e.edgeEndpoints),i=Tr(r)(e.layout.edges);if(i.tag==="Just"&&o.tag==="Just"){const a=Xo(e.layout)(e.edgeEndpoints)(r),s=du(t)(e)(n)(o._1.source)(o._1.target)(Pa(i._1));return{x:s.x,y:a.y,w:s.w,h:a.h}}return Xo(e.layout)(e.edgeEndpoints)(r)},ad=t=>e=>n=>r=>{const o=Ol(8)(t);if(n==="ExtendFromSource")return{path:o,source:e.source,target:e.target,progress:on(0)(1)(r)};if(n==="ExtendFromTarget")return{path:re(o),source:e.target,target:e.source,progress:on(0)(1)(r)};c()},lT=t=>e=>n=>r=>o=>i=>{const a=t.padding*.75,s=ot(48),u=o.layout;return vs(g=>{if(g.target.tag==="NodeWindow")return[];if(g.target.tag==="RelabelWindow")return[(()=>{const _=dc(u)(i)(ee("Node",1,1,g.target._1,void 0,W,W));return{startT:g.startT,endT:g.endT,bbox:(()=>{const f=nd(t.labelBasePx)(o)(g.target._1)(g.target._2)(g.target._3);if(f.tag==="Nothing")return _;if(f.tag==="Just")return f._1;c()})(),priority:1,continuous:!1,stationary:!1}})()];if(g.target.tag==="EdgeWindow"){if(g.target._2.tag==="Extend"){const _=Tr(g.target._1)(i),f=Tr(g.target._1)(u.edges);if(f.tag==="Just"&&_.tag==="Just"){const l=_._1,d=f._1;return St(Ut(0,47))(h=>{const m=g.startT+(g.endT-g.startT)*(ot(h)/s),p=g.startT+(g.endT-g.startT)*(ot(h+1|0)/s),x=ad(d)(l)(g.target._2._1)(Hi(r)(((m+p)/2-g.startT)/ne(1e-4)(g.endT-g.startT))),J=0<x.path.length?x.path[0]:{x:0,y:0},w=ti(x.path)(x.progress),N=(()=>{if(w.tag==="Nothing")return J;if(w.tag==="Just")return w._1;c()})();return[{startT:m,endT:p,bbox:du(t)(o)((m+p)/2)(x.source)(x.target)({x:N.x-6,y:N.y-6,w:12,h:12}),priority:1,continuous:!0,stationary:!1}]})}return[{startT:g.startT,endT:g.endT,bbox:Xo(u)(i)(g.target._1),priority:1,continuous:!1,stationary:!1}]}if(g.target._2.tag==="Retract")return[];c()}if(g.target.tag==="TokenWindow"){if(e.widthPx>=e.heightPx*1.5&&o.path.length===0)return[{startT:g.startT,endT:g.endT,bbox:du(t)(o)((g.startT+g.endT)/2)(g.target._4)(g.target._5)((()=>{const f=ht(l=>{const d=Ye(l)(u.nodes);return d.tag==="Just"?T("Just",{x:d._1.x,y:d._1.y,w:d._1.w,h:d._1.h}):y})([g.target._4,g.target._5]);return f.length===0?Xo(u)(i)(g.target._2):ae(f)})()),priority:1,continuous:!1,stationary:!1}];const _=Tr(g.target._2)(u.edges);if(_.tag==="Just"){const f=(()=>{if(g.target._3==="Forward")return _._1;if(g.target._3==="Backward")return re(_._1);c()})(),l=St(Ut(0,47))(h=>{const m=g.startT+(g.endT-g.startT)*(ot(h)/s),p=g.startT+(g.endT-g.startT)*(ot(h+1|0)/s),x=Uc(u)(f)(g.target._4)(g.target._5)(((m+p)/2-g.startT)/ne(1e-4)(g.endT-g.startT))({pre:g.target._7,post:g.target._8});return[{startT:m,endT:p,bbox:du(t)(o)((m+p)/2)(g.target._4)(g.target._5)({x:x.x-a,y:x.y-a,w:0+a*2,h:0+a*2}),priority:1,continuous:!0,stationary:!1}]}),d=ae(K(h=>h.bbox)(l));return(()=>{const h=yc(n)(u)(o.placement)(Sf(t)(e)(u)(d).camera),m=fn(e)(o.path.length===0||o.placement.scale===1&&o.placement.tx===0&&o.placement.ty===0?t.padding:0)(n)(h);return ai(t)(e)(n)(o)(h)>=t.minimumReadableLabelPx-.001&&(()=>{const p=d.x*o.placement.scale+o.placement.tx,x=d.y*o.placement.scale+o.placement.ty;return p>=m.x-.001&&x>=m.y-.001&&p+d.w*o.placement.scale<=m.x+m.w+.001&&x+d.h*o.placement.scale<=m.y+m.h+.001})()})()?[{startT:g.startT,endT:g.endT,bbox:d,priority:1,continuous:!1,stationary:!0}]:l}if(_.tag==="Nothing")return[{startT:g.startT,endT:g.endT,bbox:Xo(u)(i)(g.target._2),priority:1,continuous:!1,stationary:!1}];c()}if(g.target.tag==="FillWindow")return[{startT:g.startT,endT:g.endT,bbox:uT(t)(g.target._3)(dc(u)(i)(ee("Node",1,1,g.target._2,void 0,W,W))),priority:1,continuous:!1,stationary:!1}];c()})},dT=t=>e=>n=>r=>o=>i=>a=>s=>[...tT(s)(_t(u=>u.startT>=s.startT&&u.endT<=s.endT,a.spans)),...lT(t)(e)(n)(r)(s)(i)(s.windows)],hT=t=>e=>n=>r=>o=>i=>a=>s=>aJ(t)(e)(s.layout)(a.endT)(ht(u=>u.scene.tag==="StepScene"?T("Just",u.startT):y)(s.spans))(dT(t)(e)(n)(r)(o)(i)(a)(s)),sd=t=>e=>(()=>{if(e.subject.tag==="Nothing")return!0;if(e.subject.tag==="Just")return e.subject._1.x>=t.x&&e.subject._1.y>=t.y&&e.subject._1.x+e.subject._1.w<=t.x+t.w&&e.subject._1.y+e.subject._1.h<=t.y+t.h;c()})()&&(()=>{if(e.mustSee.tag==="Nothing")return!0;if(e.mustSee.tag==="Just")return e.mustSee._1.x>=t.x&&e.mustSee._1.y>=t.y&&e.mustSee._1.x+e.mustSee._1.w<=t.x+t.w&&e.mustSee._1.y+e.mustSee._1.h<=t.y+t.h;c()})(),ud=t=>e=>n=>r=>n>=e?on(t+e-n/2)(t+n/2)(r):t+e/2,gd=t=>e=>n=>r=>{if((()=>{const a=_r(e)(n);return r.x>=a.x&&r.y>=a.y&&r.x+r.w<=a.x+a.w&&r.y+r.h<=a.y+a.h})())return n;const o={...n,zoom:Rn(n.zoom)(nT(t)(e)({...n,center:{x:r.x+r.w/2,y:r.y+r.h/2}})(r))},i=_r(e)(o);return{...o,center:{x:ud(r.x)(r.w)(i.w)(n.center.x),y:ud(r.y)(r.h)(i.h)(n.center.y)}}},pT=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=ne(o.lo)(e.x+e.w-n/2),g=Rn(o.hi)(e.x+n/2);return u<=g?{lo:u,hi:g}:o}const i=e.x+e.w/2;if(n>=e.w){const u=ne(o.lo)(i),g=Rn(o.hi)(i);return u<=g?{lo:u,hi:g}:o}const a=ne(o.lo)(e.x+n/2),s=Rn(o.hi)(e.x+e.w-n/2);return a<=s?{lo:a,hi:s}:o},hu=t=>e=>{if(t.tag==="Just"){if(e.tag==="Just")return T("Just",ae([t._1,e._1]));if(e.tag==="Nothing")return T("Just",t._1);c()}if(t.tag==="Nothing"){if(e.tag==="Just")return T("Just",e._1);if(e.tag==="Nothing")return y}c()},mT=t=>e=>n=>n.endT<=t||n.startT>=e?y:T("Just",{...n,startT:ne(t)(n.startT),endT:Rn(e)(n.endT)}),yT=t=>e=>n=>r=>o=>i=>a=>ht(mT(a.startT)(a.endT))(K(oT(r)(a.layout)(a.placement))(hT(t)(e)(r)(n)(o)(a.edgeEndpoints)(i)(a))),xT=t=>e=>n=>r=>{const o=Rn(r.zoom)(t.bounds.w/ne(1e-4)(e.w));return{...r,center:{...r.center,x:(()=>{const i=pT(t.bounds)(e)(t.bounds.w/ne(1e-4)(o));return on(i.lo)(i.hi)(n.center.x)})()},zoom:o}},JT=t=>e=>n=>{const r=t.bounds.h/ne(1e-4)(n.zoom),o=t.bounds.w/ne(1e-4)(n.zoom);return{...n,center:{x:o>=e.w?e.x+e.w/2:ed(e.x+o/2)(e.x+e.w-o/2)(n.center.x),y:r>=e.h?e.y+e.h/2:ed(e.y+r/2)(e.y+e.h-r/2)(n.center.y)}}},ea=t=>e=>n=>JT(t)((()=>{const r=e*n.placement.scale;return{x:n.layout.bounds.x*n.placement.scale+n.placement.tx-r,y:n.layout.bounds.y*n.placement.scale+n.placement.ty-r,w:n.layout.bounds.w*n.placement.scale+r*2,h:n.layout.bounds.h*n.placement.scale+r*2}})()),wT=t=>e=>n=>r=>{const o=_r(t)(r),i=t.bounds,a=s=>{const u=ea(t)(e)(n)(s);return ea(t)(e)(n)({...u,zoom:ne(u.zoom)(ne(i.w/ne(1e-4)(2*Rn(u.center.x-o.x)(o.x+o.w-u.center.x)))(i.h/ne(1e-4)(2*Rn(u.center.y-o.y)(o.y+o.h-u.center.y))))})};return s=>a(a(s))},TT=t=>e=>n=>r=>ea(n)(t.padding)(r)(tx(t)(e)(n)(r.placement)(r.layout.bounds).camera),NT=t=>e=>n=>r=>o=>{const i=TT(t)(e)(n)(o),a=te(s=>s.direction==="DiveIn"&&To(s.childPath)(o.path))(r.dives);if(a.tag==="Just"){const s=Da(r)(a._1.parentPath)(a._1.startT)(a._1.endT);if(s.tag==="Just"){const u=Ye(a._1.node)(s._1.layout.nodes);if(u.tag==="Just"){const g=u._1.w*s._1.placement.scale,_=u._1.h*s._1.placement.scale,f=Rn(g)(_*2),l=ex(e)(n)({h:_,w:f,x:u._1.x*s._1.placement.scale+s._1.placement.tx+(g-f)*.5,y:u._1.y*s._1.placement.scale+s._1.placement.ty});return wT(n)(t.padding)(o)(l)(l.zoom>i.zoom?l:i)}if(u.tag==="Nothing")return i;c()}if(s.tag==="Nothing")return i;c()}if(a.tag==="Nothing")return i;c()},na=t=>e=>n=>r=>o=>i=>{if(r.direction==="DiveIn"){const a=ea(n)(t.padding)(o)(jo(t)(n)(i)(r.startT-1e-4).camera),s=od(t)(e)(n)(o)(a),u=Ye(r.node)(o.layout.nodes);return r.direction==="DiveIn"&&u.tag==="Just"?gd(e)(n)(s)({x:u._1.x*o.placement.scale+o.placement.tx+u._1.w*o.placement.scale/2-.5,y:u._1.y*o.placement.scale+o.placement.ty+u._1.h*o.placement.scale/2-.5,w:1,h:1}):a}if(r.direction==="DiveOut"){const a=ea(n)(t.padding)(o)(jo(t)(n)(i)(r.endT+1e-4).camera),s=od(t)(e)(n)(o)(a),u=Ye(r.node)(o.layout.nodes);return r.direction==="DiveIn"&&u.tag==="Just"?gd(e)(n)(s)({x:u._1.x*o.placement.scale+o.placement.tx+u._1.w*o.placement.scale/2-.5,y:u._1.y*o.placement.scale+o.placement.ty+u._1.h*o.placement.scale/2-.5,w:1,h:1}):a}c()},bT=t=>t.target.tag==="NodeWindow"||t.target.tag==="RelabelWindow"||t.target.tag==="EdgeWindow"||t.target.tag==="TokenWindow"||t.target.tag==="FillWindow",cd=t=>Rt(at.compare)(Ur(at.compare)(St(_t(bT,t.windows))(e=>[e.startT,e.endT]))),_d=t=>e=>n=>r=>o=>i=>{if(o.tag==="Just"){if(i.tag==="Just"){const a=ae([o._1,i._1]);return r<e?T("Just",(()=>{const s=fu(t)(e)(r);return{x:o._1.x+(a.x-o._1.x)*s,y:o._1.y+(a.y-o._1.y)*s,w:o._1.w+(a.w-o._1.w)*s,h:o._1.h+(a.h-o._1.h)*s}})()):T("Just",(()=>{const s=fu(e)(n)(r);return{x:a.x+(i._1.x-a.x)*s,y:a.y+(i._1.y-a.y)*s,w:a.w+(i._1.w-a.w)*s,h:a.h+(i._1.h-a.h)*s}})())}if(i.tag==="Nothing")return T("Just",(()=>{const a=fu(t)(n)(r);return{x:o._1.x+(o._1.x+o._1.w/2-o._1.x)*a,y:o._1.y+(o._1.y+o._1.h/2-o._1.y)*a,w:o._1.w+-o._1.w*a,h:o._1.h+-o._1.h*a}})());c()}if(o.tag==="Nothing"){if(i.tag==="Just")return T("Just",(()=>{const a=i._1.x+i._1.w/2,s=i._1.y+i._1.h/2,u=fu(t)(n)(r);return{x:a+(i._1.x-a)*u,y:s+(i._1.y-s)*u,w:0+(i._1.w-0)*u,h:0+(i._1.h-0)*u}})());if(i.tag==="Nothing")return y}c()},fd=t=>e=>n=>r=>{const o=r.path.length===0?t.minimumReadableLabelPx*1:t.minimumReadableLabelPx*1.8;return(i=>a=>{let s=i,u=a,g=!0,_;for(;g;){const f=s,l=u,d=ai(t)(e)(n)(r)(l);if(f<=0){g=!1,_=l.zoom;continue}if(e.widthPx<=0||e.heightPx<=0){g=!1,_=l.zoom;continue}if(d<=0){g=!1,_=l.zoom;continue}if(xe(d-o)<.001){g=!1,_=l.zoom;continue}s=f-1|0,u={...l,zoom:l.zoom*o/d}}return _})(12)({center:(()=>{const i=t.padding*r.placement.scale;return{x:r.layout.bounds.x*r.placement.scale+r.placement.tx-i+(r.layout.bounds.w*r.placement.scale+i*2)/2,y:r.layout.bounds.y*r.placement.scale+r.placement.ty-i+(r.layout.bounds.h*r.placement.scale+i*2)/2}})(),zoom:1})},Zc=t=>e=>n=>r=>o=>{const i=fn(t)(e)(n)(o);return{...o,center:{x:i.w>r.w+ne(1)(xe(r.w))*1e-9?o.center.x+(r.x+r.w/2-(i.x+i.w/2)):i.x<r.x?o.center.x+(r.x-i.x):i.x+i.w>r.x+r.w?o.center.x+(r.x+r.w-i.x-i.w):o.center.x+0,y:i.h>r.h+ne(1)(xe(r.h))*1e-9?o.center.y+(r.y+r.h/2-(i.y+i.h/2)):i.y<r.y?o.center.y+(r.y-i.y):i.y+i.h>r.y+r.h?o.center.y+(r.y+r.h-i.y-i.h):o.center.y+0}}},vT=t=>e=>n=>r=>Zc(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)((()=>{const o=t.padding*r.placement.scale;return{x:r.layout.bounds.x*r.placement.scale+r.placement.tx-o,y:r.layout.bounds.y*r.placement.scale+r.placement.ty-o,w:r.layout.bounds.w*r.placement.scale+o*2,h:r.layout.bounds.h*r.placement.scale+o*2}})()),No=t=>e=>n=>r=>o=>i=>{const a=fd(t)(e)(n)(r),s=(()=>{if(r.path.length===0)return{x:n.bounds.x-t.padding,y:n.bounds.y-t.padding,w:n.bounds.w+t.padding*2,h:n.bounds.h+t.padding*2};const m=t.padding*r.placement.scale;return{x:r.layout.bounds.x*r.placement.scale+r.placement.tx-m,y:r.layout.bounds.y*r.placement.scale+r.placement.ty-m,w:r.layout.bounds.w*r.placement.scale+m*2,h:r.layout.bounds.h*r.placement.scale+m*2}})(),u=r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0,g=r.path.length!==0,_=r.path.length===0?a:0,f=Zc(e)(u)(n)(s)({...i,zoom:ne(a)(i.zoom)}),l=fn(e)(u)(n)(f),d=(()=>{if(o.tag==="Nothing")return f;if(o.tag==="Just")return _T(e)(n)(r)(t)(o._1)(_)(12)(f);c()})(),h=fn(e)(u)(n)(d);if(o.tag==="Nothing")return f;if(o.tag==="Just")return g?Xc(h)(o._1)(d):o._1.x>=l.x-.001&&o._1.y>=l.y-.001&&o._1.x+o._1.w<=l.x+l.w+.001&&o._1.y+o._1.h<=l.y+l.h+.001?f:o._1.w<=h.w+.001&&o._1.h<=h.h+.001?Xc(h)(o._1)(d):Zc(e)(u)(n)(ae([s,o._1]))(Xc(h)(o._1)(d));c()},CT=t=>e=>n=>r=>o=>i=>a=>{const s=t.padding*r.placement.scale,u={x:r.layout.bounds.x*r.placement.scale+r.placement.tx-s,y:r.layout.bounds.y*r.placement.scale+r.placement.ty-s,w:r.layout.bounds.w*r.placement.scale+s*2,h:r.layout.bounds.h*r.placement.scale+s*2},g=x=>sd(fn(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)(x))(i),_=x=>J=>w=>N=>{let L=x,C=J,R=w,P=N,I=!0,U;for(;I;){const S=L,v=C,F=R,H=P;if(S<=0){I=!1,U=H;continue}const M={...o,zoom:(v+F)/2},q=fn(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)(M),$={...M,center:bc(Nc)(u)({w:q.w,h:q.h})(o.center)(i)};if(g($)){L=S-1|0,C=$.zoom,R=F,P=$;continue}L=S-1|0,C=v,R=$.zoom,P=H}return U},f=fn(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)(a),l=fn(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)(o),d=ai(t)(e)(n)(r)(o)>=t.minimumReadableLabelPx-.001,h={...o,center:bc(Nc)(u)({w:l.w,h:l.h})(o.center)(i)},m=sd(fn(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)(h))(i),p={...a,center:bc(Nc)(u)({w:f.w,h:f.h})(o.center)(i)};return p.zoom>h.zoom&&g(p)?p:d&&m?h:p.zoom>=h.zoom||!g(p)?p:_(12)(p.zoom)(o.zoom)(p)},LT=t=>K(e=>{const n=te(i=>e.startT<i.startT&&e.endT>=i.startT-1e-4)(t),r=(()=>{if(n.tag==="Just")return{...e,endT:n._1.startT,toCam:n._1.fromCam,easing:fr,interp:Yo,intent:$f};if(n.tag==="Nothing")return e;c()})(),o=te(i=>r.startT<=i.endT+1e-4&&r.endT>i.endT)(t);if(o.tag==="Just")return{...r,startT:o._1.endT,fromCam:o._1.toCam,easing:fr,interp:Yo,intent:$f};if(o.tag==="Nothing")return r;c()}),kT=t=>e=>n=>r=>o=>i=>a=>{const s=r.layout.bounds.w*r.placement.scale,u=s/ne(1e-4)(r.layout.bounds.h*r.placement.scale);if(o.tag==="Nothing")return a;if(o.tag==="Just"){const g=xT(n)(o._1)(i)(a);return ai(t)(e)(n)(r)(g)>=t.minimumReadableLabelPx-.001||o._1.w>=s-.001&&u>=.33&&ai(t)(e)(n)(r)(g)>=t.minimumReadableLabelPx*1?g:a}c()},ST=t=>e=>n=>{const r=Rt(o=>i=>at.compare(o.startT)(i.startT))(_t(o=>o.startT>=e.endT-1e-4&&o.startT-e.endT<=1.1001&&o.target.tag==="TokenWindow",t.windows));return 0<r.length&&r[0].target.tag==="TokenWindow"&&r[0].target._4===n?T("Just",{source:r[0].target._4,target:r[0].target._5,startT:r[0].startT}):y},ET=t=>e=>n=>{const r=Rt(i=>a=>at.compare(i.endT)(a.endT))(_t(i=>i.endT<=e.startT+1e-4&&e.startT-i.endT<=1.1001&&i.target.tag==="TokenWindow",t.windows)),o=r.length-1|0;return o>=0&&o<r.length&&r[o].target.tag==="TokenWindow"&&r[o].target._5===n},RT=t=>e=>n=>r=>o=>{if(r.target.tag==="TokenWindow"){const i=Tr(r.target._2)(n.layout.edges);if(i.tag==="Just"){const a=(o-r.startT)/ne(1e-4)(r.endT-r.startT),s=ST(n)(r)(r.target._5);return id(t)(n)(o)(r.target._4)(r.target._5)(Uc(n.layout)((()=>{if(r.target._3==="Forward")return i._1;if(r.target._3==="Backward")return re(i._1);c()})())(r.target._4)(r.target._5)(a)({pre:r.target._7,post:r.target._8}))(Yw(a)({pre:r.target._7,post:r.target._8}))(s.tag==="Just"?rT(t)(n)(o)(s._1):0)(ET(n)(r)(r.target._4))(s)}if(i.tag==="Nothing")return y;c()}if(r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"){const i=Tr(r.target._1)(n.layout.edges);if(i.tag==="Just"){const a=Tr(r.target._1)(n.edgeEndpoints);if(a.tag==="Just"){const s=ad(i._1)(a._1)(r.target._2._1)(Hi(e)((o-r.startT)/ne(1e-4)(r.endT-r.startT)));return id(t)(n)(o)(s.source)(s.target)((()=>{const u=0<s.path.length?s.path[0]:{x:0,y:0},g=ti(s.path)(s.progress);if(g.tag==="Nothing")return u;if(g.tag==="Just")return g._1;c()})())(s.progress)(0)(!1)(y)}if(a.tag==="Nothing")return y;c()}if(i.tag==="Nothing")return y;c()}return y},PT=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=i=>n<i.startT?i.startT-n:n>i.endT?n-i.endT:0,o=Rt(i=>a=>{const s=at.compare(r(i))(r(a));return s==="EQ"?at.compare(a.startT)(i.startT):s})(_t(i=>e.startT<i.endT-1e-4&&e.endT>i.startT+1e-4&&(i.target.tag==="RelabelWindow"?!0:i.target.tag==="EdgeWindow"?i.target._2.tag==="Extend":i.target.tag==="TokenWindow"||i.target.tag==="FillWindow"),t.windows));return 0<o.length?on(o[0].startT+1e-4)(o[0].endT-1e-4)(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):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},BT=t=>e=>n=>{const r=n.fromCam.zoom===n.toCam.zoom&&n.fromCam.center.x===n.toCam.center.x&&n.fromCam.center.y===n.toCam.center.y?(n.startT+n.endT)/2:n.endT+1e-4,o=a=>r<a.startT?a.startT-r:r>a.endT?r-a.endT:0,i=Rt(a=>s=>at.compare(o(a))(o(s)))(_t(a=>n.startT<a.endT-1e-4&&n.endT>a.startT+1e-4&&a.target.tag==="TokenWindow",e.windows));return 0<i.length?RT(t)(mc)(e)(i[0])(on(i[0].startT+1e-4)(i[0].endT-1e-4)(PT(e)(n))):y},zr=t=>e=>n=>{const r=(i,a)=>{const s=ht(lu(t.labelBasePx)(e)(n))([i,a]);return s.length===0?y:T("Just",ae(s))},o=Bt(i=>y,i=>a=>T("Just",{head:i,tail:a}),ht(i=>{if(i.startT<=n&&n<i.endT){if(i.target.tag==="NodeWindow"){const a=Ye(i.target._1)(e.layout.nodes);if(a.tag==="Just")return T("Just",{whole:(()=>{const s=_t(g=>(g._2.source===i.target._1||g._2.target===i.target._1)&&Yl(e)(n)(g._2.source)&&Yl(e)(n)(g._2.target)&&$w(e)(n)(g._1),Kw(e.edgeEndpoints)),u=[...ht(g=>{const _=Ye(g)(e.layout.nodes);return _.tag==="Just"?T("Just",{x:_._1.x,y:_._1.y,w:_._1.w,h:_._1.h}):y})(Ur(G.compare)([...St(s)(g=>[g._2.source,g._2.target]),i.target._1])),...ht(g=>{const _=Tr(g._1)(e.layout.edges);return _.tag==="Just"?T("Just",Pa(_._1)):y})(s)];return u.length===0?{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}:ae(u)})(),text:lu(t.labelBasePx)(e)(n)(i.target._1),guide:y});if(a.tag==="Nothing")return y;c()}if(i.target.tag==="RelabelWindow"){const a=Ye(i.target._1)(e.layout.nodes);if(a.tag==="Just"){const s=ht(ii)([Kc(t.labelBasePx)(a._1)(i.target._2),Kc(t.labelBasePx)(a._1)(i.target._3)]),u=s.length===0?y:T("Just",ae(s)),g={x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h};return T("Just",{whole:(()=>{if(u.tag==="Just")return ae([g,u._1]);if(u.tag==="Nothing")return g;c()})(),text:u,guide:nd(t.labelBasePx)(e)(i.target._1)(i.target._2)(i.target._3)})}if(a.tag==="Nothing")return y;c()}if(i.target.tag==="EdgeWindow")return T("Just",(()=>{const a=fT(t)(e)(n)(i.target._1),s=Tr(i.target._1)(e.edgeEndpoints);if(s.tag==="Just"){const u=r(s._1.source,s._1.target);return{whole:(()=>{if(u.tag==="Nothing")return a;if(u.tag==="Just")return u._1;c()})(),text:u,guide:T("Just",a)}}if(s.tag==="Nothing")return{whole:Xo(e.layout)(e.edgeEndpoints)(i.target._1),text:y,guide:T("Just",a)};c()})());if(i.target.tag==="TokenWindow")return T("Just",(()=>{const a=r(i.target._4,i.target._5),s=Tr(i.target._2)(e.layout.edges),u=(()=>{if(s.tag==="Nothing")return Xo(e.layout)(e.edgeEndpoints)(i.target._2);if(s.tag==="Just"){const g=Uc(e.layout)((()=>{if(i.target._3==="Forward")return s._1;if(i.target._3==="Backward")return re(s._1);c()})())(i.target._4)(i.target._5)((n-i.startT)/ne(1e-4)(i.endT-i.startT))({pre:i.target._7,post:i.target._8});return{x:g.x-6,y:g.y-6,w:12,h:12}}c()})();return{whole:(()=>{const g=ht(ii)([(()=>{const _=ht(f=>{const l=Ye(f)(e.layout.nodes);return l.tag==="Just"?T("Just",{x:l._1.x,y:l._1.y,w:l._1.w,h:l._1.h}):y})([i.target._4,i.target._5]);return _.length===0?y:T("Just",ae(_))})(),a]);return g.length===0?u:ae(g)})(),text:a,guide:T("Just",u)}})());if(i.target.tag==="FillWindow"){const a=Ye(i.target._2)(e.layout.nodes);if(a.tag==="Just")return T("Just",{whole:{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h},text:lu(t.labelBasePx)(e)(n)(i.target._2),guide:y});if(a.tag==="Nothing")return y;c()}}return y})(e.windows));return o.tag==="Just"?T("Just",(()=>{const i=ae(K(g=>g.whole)([o._1.head,...o._1.tail])),a=ht(ii)(K(g=>g.text)([o._1.head,...o._1.tail])),s=a.length===0?y:T("Just",ae(a)),u=ht(ii)(K(g=>g.guide)([o._1.head,...o._1.tail]));return u.length===0?{whole:{x:i.x*e.placement.scale+e.placement.tx,y:i.y*e.placement.scale+e.placement.ty,w:i.w*e.placement.scale,h:i.h*e.placement.scale},text:s.tag==="Just"?T("Just",{x:s._1.x*e.placement.scale+e.placement.tx,y:s._1.y*e.placement.scale+e.placement.ty,w:s._1.w*e.placement.scale,h:s._1.h*e.placement.scale}):y,guide:y}:{whole:{x:i.x*e.placement.scale+e.placement.tx,y:i.y*e.placement.scale+e.placement.ty,w:i.w*e.placement.scale,h:i.h*e.placement.scale},text:s.tag==="Just"?T("Just",{x:s._1.x*e.placement.scale+e.placement.tx,y:s._1.y*e.placement.scale+e.placement.ty,w:s._1.w*e.placement.scale,h:s._1.h*e.placement.scale}):y,guide:T("Just",{x:ae(u).x*e.placement.scale+e.placement.tx,y:ae(u).y*e.placement.scale+e.placement.ty,w:ae(u).w*e.placement.scale,h:ae(u).h*e.placement.scale})}})()):y},Fa=t=>e=>n=>r=>o=>{const i=t.padding*r.placement.scale;return hu((()=>{const a=zr(t)(r)(o);return a.tag==="Just"?T("Just",{x:a._1.whole.x-i,y:a._1.whole.y-i,w:a._1.whole.w+i*2,h:a._1.whole.h+i*2}):y})())(T("Just",(()=>{const a={x:r.layout.bounds.x*r.placement.scale+r.placement.tx-i,y:r.layout.bounds.y*r.placement.scale+r.placement.ty-i,w:r.layout.bounds.w*r.placement.scale+i*2,h:r.layout.bounds.h*r.placement.scale+i*2},s=za(r)(o);return s.tag==="Just"?{x:s._1.x*r.placement.scale+r.placement.tx-i,y:s._1.y*r.placement.scale+r.placement.ty-i,w:s._1.w*r.placement.scale+i*2,h:s._1.h*r.placement.scale+i*2}:a})()))},GT=t=>e=>n=>r=>o=>St(r.dives)(i=>{const a=Da(r)(i.parentPath)(i.startT)(i.endT);if(a.tag==="Just"){const s=i.childPath,u=te(g=>To(g.path)(s))(r.segments);if(u.tag==="Just"){const g=o(u._1),_=No(t)(e)(n)(u._1)(Fa(t)(e)(n)(u._1)(u._1.startT+2e-4))(NT(t)(e)(n)(r)(u._1)),f=g.length===0?_:ea(n)(t.padding)(u._1)(jo(t)(n)(g)(i.startT-1e-4).camera),l=na(t)(e)(n)(i)(a._1)(o(a._1)),d=(()=>{if(i.direction==="DiveIn")return _;if(i.direction==="DiveOut"){const h=te(m=>m.direction==="DiveOut"&&To(m.parentPath)(i.childPath)&&xe(m.endT-i.startT)<1e-4)(r.dives);if(h.tag==="Just"){const m=Da(r)(h._1.parentPath)(h._1.startT)(h._1.endT);if(m.tag==="Just")return na(t)(e)(n)(h._1)(m._1)(o(m._1));if(m.tag==="Nothing")return f;c()}if(h.tag==="Nothing")return f}c()})();if(i.direction==="DiveIn"){const h=te(m=>m.direction==="DiveIn"&&To(m.parentPath)(i.childPath)&&xe(m.startT-i.endT)<1e-4)(r.dives);if(h.tag==="Just"){const m=Da(r)(h._1.parentPath)(h._1.startT)(h._1.endT);if(m.tag==="Just"){if(i.direction==="DiveIn"&&i.endT-i.startT>.12){const p=i.endT-.12,x={easing:fr,endT:p,fromCam:l,intent:mo,interp:po,startT:i.startT,toCam:na(t)(e)(n)(h._1)(m._1)(o(m._1))};return[x,{...x,startT:p,endT:i.endT,fromCam:na(t)(e)(n)(h._1)(m._1)(o(m._1))}]}return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:fr,interp:po,intent:mo}]}if(m.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:fr,interp:po,intent:mo}];c()}if(h.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:fr,interp:po,intent:mo}];c()}if(i.direction==="DiveOut"){const h=te(m=>m.direction==="DiveIn"&&To(m.parentPath)(i.childPath)&&xe(m.startT-i.endT)<1e-4)(r.dives);if(h.tag==="Just"){const m=Da(r)(h._1.parentPath)(h._1.startT)(h._1.endT);if(m.tag==="Just"){if(i.direction==="DiveIn"&&i.endT-i.startT>.12){const p=i.endT-.12,x={easing:fr,endT:p,fromCam:d,intent:mo,interp:po,startT:i.startT,toCam:na(t)(e)(n)(h._1)(m._1)(o(m._1))};return[x,{...x,startT:p,endT:i.endT,fromCam:na(t)(e)(n)(h._1)(m._1)(o(m._1))}]}return[{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:fr,interp:po,intent:mo}]}if(m.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:fr,interp:po,intent:mo}];c()}if(h.tag==="Nothing")return[{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:fr,interp:po,intent:mo}]}c()}if(u.tag==="Nothing")return[];c()}if(a.tag==="Nothing")return[];c()}),Ma=t=>e=>n=>r=>o=>{const i=t.padding*r.placement.scale,a=fn(e)(r.path.length===0||r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?t.padding:0)(n)({center:(()=>{const h=t.padding*r.placement.scale;return{x:r.layout.bounds.x*r.placement.scale+r.placement.tx-h+(r.layout.bounds.w*r.placement.scale+h*2)/2,y:r.layout.bounds.y*r.placement.scale+r.placement.ty-h+(r.layout.bounds.h*r.placement.scale+h*2)/2}})(),zoom:fd(t)(e)(n)(r)}),s=h=>h.w<=a.w+.001&&h.h<=a.h+.001,u=zr(t)(r)(o),g=(()=>{const h=hu(u.tag==="Just"?T("Just",{x:u._1.whole.x-i,y:u._1.whole.y-i,w:u._1.whole.w+i*2,h:u._1.whole.h+i*2}):y)((()=>{const m=za(r)(o);return m.tag==="Just"?T("Just",{x:m._1.x*r.placement.scale+r.placement.tx-i,y:m._1.y*r.placement.scale+r.placement.ty-i,w:m._1.w*r.placement.scale+i*2,h:m._1.h*r.placement.scale+i*2}):y})());if(h.tag==="Nothing")return!1;if(h.tag==="Just")return s(h._1);c()})()?i/2:i,_=u.tag==="Just"?T("Just",{x:u._1.whole.x-g,y:u._1.whole.y-g,w:u._1.whole.w+g*2,h:u._1.whole.h+g*2}):y,f=h=>{if(_.tag==="Nothing")return h;if(_.tag==="Just")return ae([h,{x:_._1.x+_._1.w/2,y:_._1.y+_._1.h/2,w:0,h:0}]);c()},l=(()=>{if(u.tag==="Just")return u._1.guide;if(u.tag==="Nothing")return y;c()})();if(l.tag==="Just"){const h=(()=>{if(u.tag==="Just")return u._1.text;if(u.tag==="Nothing")return y;c()})();return h.tag==="Just"&&s({x:h._1.x-g,y:h._1.y-g,w:h._1.w+g*2,h:h._1.h+g*2})?r.path.length!==0?Fa(t)(e)(n)(r)(o):_.tag==="Just"&&s(_._1)?T("Just",_._1):T("Just",f({x:h._1.x-g,y:h._1.y-g,w:h._1.w+g*2,h:h._1.h+g*2})):r.path.length!==0?Fa(t)(e)(n)(r)(o):_.tag==="Just"&&s(_._1)?T("Just",_._1):T("Just",f({x:l._1.x-g,y:l._1.y-g,w:l._1.w+g*2,h:l._1.h+g*2}))}const d=(()=>{if(u.tag==="Just")return u._1.text;if(u.tag==="Nothing")return y;c()})();return d.tag==="Just"?r.path.length!==0?Fa(t)(e)(n)(r)(o):_.tag==="Just"&&s(_._1)?T("Just",_._1):T("Just",f({x:d._1.x-g,y:d._1.y-g,w:d._1.w+g*2,h:d._1.h+g*2})):r.path.length!==0?Fa(t)(e)(n)(r)(o):_.tag==="Just"&&s(_._1)?T("Just",_._1):_.tag==="Just"?T("Just",f(_._1)):y},AT=t=>e=>n=>r=>o=>i=>{const a=Ma(t)(e)(n)(r)(i),s=u=>Ma(t)(e)(n)(r)(on(r.startT)(r.endT)(u));return hu(a)((()=>{const u=ht(ii)(Ft(g=>_=>{const f=ne(_-t.maxTransition)((()=>{const m=g-1|0;return m>=0&&m<o.length?(o[m]+_)/2:r.startT})()),l=Rn(_+t.maxTransition)((()=>{const m=g+1|0;return m>=0&&m<o.length?(o[m]+_)/2:r.endT})());if(i<f-1e-4||i>l+1e-4)return y;const d=s(_-1e-4),h=s(_+1e-4);return _d(f)(_)(l)(i)(i<_?a:d)(i<_?h:a)})(o));return u.length===0?y:T("Just",ae(u))})())},IT=t=>e=>n=>r=>o=>i=>o<=r.startT+1e-4?vT(t)(e)(n)(r)(i):No(t)(e)(n)(r)(AT(t)(e)(n)(r)(cd(r))(o))(i),zT=t=>e=>n=>r=>o=>i=>{const a=Ma(t)(e)(n)(r)(i);return hu(a)((()=>{const s=ht(u=>i<u.left-1e-4||i>u.right+1e-4?y:_d(u.left)(u.boundary)(u.right)(i)(i<u.boundary?a:u.before)(i<u.boundary?u.after:a))(o);return s.length===0?y:T("Just",ae(s))})())},DT=t=>e=>n=>r=>o=>{const i=a=>Ma(t)(e)(n)(r)(on(r.startT)(r.endT)(a));return Ft(a=>s=>({boundary:s,left:ne(s-t.maxTransition)((()=>{const u=a-1|0;return u>=0&&u<o.length?(o[u]+s)/2:r.startT})()),right:Rn(s+t.maxTransition)((()=>{const u=a+1|0;return u>=0&&u<o.length?(o[u]+s)/2:r.endT})()),before:i(s-1e-4),after:i(s+1e-4)}))(o)},FT=t=>e=>n=>r=>o=>i=>a=>{const s=e.widthPx>=e.heightPx*1.5&&a.path.length===0,u=S=>s&&oe(v=>v.startT<=S&&S<v.endT&&(v.target.tag==="TokenWindow"||v.target.tag==="FillWindow"),a.windows),g=S=>v=>{let F=S,H=v,M=!0,q;for(;M;){const $=F,B=H,D=ai(t)(e)(r)(a)(B);if($<=0){M=!1,q=B.zoom;continue}if(e.widthPx<=0||e.heightPx<=0){M=!1,q=B.zoom;continue}if(D<=0){M=!1,q=B.zoom;continue}if(xe(D-t.minimumReadableLabelPx)<.001){M=!1,q=B.zoom;continue}F=$-1|0,H={...B,zoom:B.zoom*t.minimumReadableLabelPx/D}}return q},_=t.padding*a.placement.scale/2,f=s?.016666666666666666:1e-4,l=t.padding*a.placement.scale,d={x:a.layout.bounds.x*a.placement.scale+a.placement.tx-l,y:a.layout.bounds.y*a.placement.scale+a.placement.ty-l,w:a.layout.bounds.w*a.placement.scale+l*2,h:a.layout.bounds.h*a.placement.scale+l*2},h={center:{x:d.x+d.w/2,y:d.y+d.h/2},zoom:1},m=g(12)(h),p=fn(e)(a.path.length===0||a.placement.scale===1&&a.placement.tx===0&&a.placement.ty===0?t.padding:0)(r)(h),x=fn(e)(a.path.length===0||a.placement.scale===1&&a.placement.tx===0&&a.placement.ty===0?t.padding:0)(r)({...h,zoom:m}),J={w:x.w*m,h:x.h*m},w=(S,v)=>{const F=fn(e)(a.path.length===0||a.placement.scale===1&&a.placement.tx===0&&a.placement.ty===0?t.padding:0)(r)(v);return Wg(H=>{if(H.tag==="Nothing")return!0;if(H.tag==="Just")return H._1.x>=F.x-.001&&H._1.y>=F.y-.001&&H._1.x+H._1.w<=F.x+F.w+.001&&H._1.y+H._1.h<=F.y+F.h+.001;c()},S)},N=ht(S=>{if(S.target.tag==="RelabelWindow"){const v=zr(t)(a)((S.startT+S.endT)/2);if(v.tag==="Just")return T("Just",{window:S,bounds:(()=>{if(v._1.text.tag==="Just")return ae([v._1.whole,v._1.text._1]);if(v._1.text.tag==="Nothing")return v._1.whole;c()})(),preparers:(()=>{const F=S.startT;return _t(H=>F>=H.endT-1e-4&&F<=H.endT+t.maxTransition&&H.target.tag==="TokenWindow"&&H.target._5===S.target._1,a.windows)})()})}return y})(a.windows),L=ht(S=>S.target.tag==="NodeWindow"||S.target.tag==="RelabelWindow"||S.target.tag==="EdgeWindow"||S.target.tag==="TokenWindow"||S.target.tag==="FillWindow"?T("Just",{window:S,afterStart:zr(t)(a)(S.startT+1e-4),beforeEnd:zr(t)(a)(S.endT-1e-4)}):y)(a.windows),C=S=>u(S)?zr(t)(a)(S):rd([(()=>{const v=b(F=>H=>H.window.endT>S+1e-4||H.window.endT<S-t.maxTransition||F.tag==="Just"&&F._1.window.endT>=H.window.endT?F:T("Just",H))(y)(L);if(v.tag==="Just")return v._1.beforeEnd;if(v.tag==="Nothing")return y;c()})(),zr(t)(a)(S),(()=>{const v=b(F=>H=>H.window.startT<S-1e-4||H.window.startT>S+t.maxTransition||F.tag==="Just"&&F._1.window.startT<=H.window.startT?F:T("Just",H))(y)(L);if(v.tag==="Just")return v._1.afterStart;if(v.tag==="Nothing")return y;c()})()]),R=(S,v)=>{const F=za(a)(S),H=F.tag==="Just"?T("Just",{x:F._1.x*a.placement.scale+a.placement.tx,y:F._1.y*a.placement.scale+a.placement.ty,w:F._1.w*a.placement.scale,h:F._1.h*a.placement.scale}):y,M=ht(B=>B.window.endT>=S-1e-4&&B.window.startT<=S+t.maxTransition&&B.window.target.tag==="RelabelWindow"||oe(D=>D.startT<=S+1e-4&&D.endT>=S-1e-4,B.preparers)?T("Just",B.bounds):y)(N),q=M.length===0?y:T("Just",ae(M));if(v.tag==="Just"){if(q.tag==="Just"){const D=(()=>{if(H.tag==="Just")return T("Just",ae([H._1,ae([q._1,v._1.whole])]));if(H.tag==="Nothing")return T("Just",ae([q._1,v._1.whole]));c()})();return a.path.length===0?Ui({worldBounds:d,bounds:D,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,actionTextBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:{w:p.w,h:p.h},padding:_,zoomFloor:m}):Vi({worldBounds:d,visibleBounds:H,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,fallbackActionBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:J,zoomCap:m,padding:_})}if(q.tag==="Nothing"){const D=(()=>{if(H.tag==="Just")return T("Just",ae([H._1,v._1.whole]));if(H.tag==="Nothing")return T("Just",v._1.whole);c()})();return a.path.length===0?Ui({worldBounds:d,bounds:D,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,actionTextBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:{w:p.w,h:p.h},padding:_,zoomFloor:m}):Vi({worldBounds:d,visibleBounds:H,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,fallbackActionBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:J,zoomCap:m,padding:_})}const B=(H.tag==="Just"&&c(),void c());return a.path.length===0?Ui({worldBounds:d,bounds:B,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,actionTextBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:{w:p.w,h:p.h},padding:_,zoomFloor:m}):Vi({worldBounds:d,visibleBounds:H,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,fallbackActionBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:J,zoomCap:m,padding:_})}if(q.tag==="Just"){const B=(()=>{if(H.tag==="Just")return T("Just",ae([H._1,q._1]));if(H.tag==="Nothing")return T("Just",q._1);c()})();return a.path.length===0?Ui({worldBounds:d,bounds:B,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,actionTextBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:{w:p.w,h:p.h},padding:_,zoomFloor:m}):Vi({worldBounds:d,visibleBounds:H,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,fallbackActionBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:J,zoomCap:m,padding:_})}if(q.tag==="Nothing"){const B=(()=>{if(H.tag==="Just")return T("Just",H._1);if(H.tag==="Nothing")return y;c()})();return a.path.length===0?Ui({worldBounds:d,bounds:B,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,actionTextBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:{w:p.w,h:p.h},padding:_,zoomFloor:m}):Vi({worldBounds:d,visibleBounds:H,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,fallbackActionBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:J,zoomCap:m,padding:_})}const $=(H.tag==="Just"&&c(),void c());return a.path.length===0?Ui({worldBounds:d,bounds:$,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,actionTextBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:{w:p.w,h:p.h},padding:_,zoomFloor:m}):Vi({worldBounds:d,visibleBounds:H,actionBounds:v.tag==="Just"?T("Just",v._1.whole):y,fallbackActionBounds:(()=>{if(v.tag==="Just")return v._1.text;if(v.tag==="Nothing")return y;c()})(),actionGuideBounds:(()=>{if(v.tag==="Just")return v._1.guide;if(v.tag==="Nothing")return y;c()})(),frameAtUnitZoom:J,zoomCap:m,padding:_})},P=cd(a),I=DT(t)(e)(r)(a)(P),U=S=>u(S)?Ma(t)(e)(r)(a)(S):zT(t)(e)(r)(a)(I)(S);return b(S=>v=>{const F=on(a.startT)(a.endT)(v.startT+1e-4),H=on(a.startT)(a.endT)(v.endT+1e-4),M=(F+H)/2,q=v.intent==="ActionFocus"&&u(M),$=v.intent==="ActionFocus"?M:H,B=q?[U(M)]:K(mt=>U(mt))((()=>{const mt=v.easing==="Linear"?6:2,vt=v.endT-v.startT;return K(Ht=>on(a.startT)(a.endT)(v.startT+vt*ot(Ht)/ot(mt)+1e-4))(Ut(0,mt))})()),D=ht(ii)(B),Q=D.length===0?y:T("Just",ae(D)),O=B.length-1|0,z=O>=0&&O<B.length?T("Just",B[O]):y,Y=(()=>{if(z.tag==="Just")return z._1;if(z.tag==="Nothing")return U(H);c()})(),V=Hx.eq(v.interp)(Hf)&&w(B,v.toCam),X=V&&!q?v.toCam:R(H,C($)),Z=0<B.length?No(t)(e)(r)(a)(B[0])(R(F,C(F))):No(t)(e)(r)(a)(U(F))(R(F,C(F))),nt=(()=>{if(S.previous.tag==="Nothing")return Z;if(S.previous.tag==="Just")return S.previous._1;c()})(),rt=(()=>{if(s)return X;const mt=BT(t)(a)(v);return mt.tag==="Just"&&v.easing==="Linear"?CT(t)(e)(r)(a)(nt)(mt._1)(X):X})(),ft=No(t)(e)(r)(a)(Y)(nt),Nt=No(t)(e)(r)(a)(Q)(kT(t)(e)(r)(a)(Q)(nt)(q&&X.zoom>nt.zoom+1e-4||!V&&q?No(t)(e)(r)(a)(Y)(rt):w(B,nt)&&(!q||nt.zoom>=X.zoom-1e-4)?nt:(()=>{const mt=fn(e)(a.path.length===0||a.placement.scale===1&&a.placement.tx===0&&a.placement.ty===0?t.padding:0)(r)(nt),vt=(ft.center.y-nt.center.y)*e.heightPx/ne(1e-4)(mt.h),Ht=(ft.center.x-nt.center.x)*e.widthPx/ne(1e-4)(mt.w);return qe(Ht*Ht+vt*vt)<=12})()?ft:No(t)(e)(r)(a)(Y)(rt))),lt=(()=>{if(v.easing==="Linear"){const mt=fn(e)(a.path.length===0||a.placement.scale===1&&a.placement.tx===0&&a.placement.ty===0?t.padding:0)(r)(nt),vt=(Nt.center.y-nt.center.y)*e.heightPx/ne(1e-4)(mt.h),Ht=(Nt.center.x-nt.center.x)*e.widthPx/ne(1e-4)(mt.w),Tt=qe(Ht*Ht+vt*vt),Vt=t.panSpeed*ne(0)(v.endT-v.startT),Gt=Tt<=Vt||Tt<=1e-4?1:Vt/Tt,bt={...Nt,center:{x:nt.center.x+(Nt.center.x-nt.center.x)*Gt,y:nt.center.y+(Nt.center.y-nt.center.y)*Gt}};if((()=>{const pt=U(on(a.startT)(a.endT)(v.endT+1e-4));if(pt.tag==="Nothing")return!0;if(pt.tag==="Just"){const ct=fn(e)(a.path.length===0||a.placement.scale===1&&a.placement.tx===0&&a.placement.ty===0?t.padding:0)(r)(bt);return pt._1.x>=ct.x-.001&&pt._1.y>=ct.y-.001&&pt._1.x+pt._1.w<=ct.x+ct.w+.001&&pt._1.y+pt._1.h<=ct.y+ct.h+.001}c()})())return bt}return Nt})();return{previous:T("Just",lt),spans:Et(S.spans)({startT:v.startT,endT:v.endT,fromCam:nt,toCam:lt,easing:v.easing,interp:Yo,intent:v.intent})}})({previous:y,spans:[]})(_t(S=>S.endT-S.startT>=f,(()=>{const S=Rt(at.compare)(Ur(at.compare)(St(P)(F=>[ne(F-t.maxTransition)((()=>{const H=_t(q=>q<F,P),M=H.length-1|0;return M>=0&&M<H.length?(H[M]+F)/2:a.startT})()),F,Rn(F+t.maxTransition)((()=>{const H=_t(M=>M>F,P);return 0<H.length?(H[0]+F)/2:a.endT})())]))),v=yT(t)(e)(n)(r)(o)(i)(a);return St((()=>{if(v.length===0){const F=R(on(a.startT)(a.endT)(a.startT+1e-4),C(on(a.startT)(a.endT)(a.startT+1e-4)));return[{startT:a.startT,endT:a.endT,fromCam:F,toCam:F,easing:t.easing,interp:Yo,intent:Ws}]}return v})())(F=>{const H=[F.startT,...Et(_t(M=>M>F.startT+1e-4&&M<F.endT-1e-4,S))(F.endT)];return K(M=>({...F,startT:M._1,endT:M._2}))(We(mn,H,At(1,H.length,H)))})})())).spans},MT=t=>e=>n=>r=>o=>i=>Uw(a=>({segment:a,spans:FT(t)(e)(n)(r)(o)(i)(a)}))(i.segments),ld=t=>e=>n=>r=>o=>i=>{const a=MT(t)(e)(n)(r)(o)(i),s=Rt(g=>_=>at.compare(g.startT)(_.startT))(St(a)(g=>g.spans)),u=GT(t)(e)(r)(i)(g=>{const _=te(f=>To(f.segment.path)(g.path)&&f.segment.startT===g.startT&&f.segment.endT===g.endT)(a);return _.tag==="Just"?_._1.spans:[]});return[...u,...u.length===0?s:LT(u)(s)]},QT=t=>e=>n=>{const r=b(o=>i=>!(i.target.tag==="NodeWindow"||i.target.tag==="RelabelWindow"||i.target.tag==="EdgeWindow"||i.target.tag==="TokenWindow"||i.target.tag==="FillWindow")||i.endT>n+1e-4||i.endT<n-t.maxTransition||o.tag==="Just"&&o._1.endT>=i.endT?o:T("Just",i))(y)(e.windows);if(r.tag==="Just")return zr(t)(e)(r._1.endT-1e-4);if(r.tag==="Nothing")return y;c()},WT=t=>e=>n=>{const r=b(o=>i=>!(i.target.tag==="NodeWindow"||i.target.tag==="RelabelWindow"||i.target.tag==="EdgeWindow"||i.target.tag==="TokenWindow"||i.target.tag==="FillWindow")||i.startT<n-1e-4||i.startT>n+t.maxTransition||o.tag==="Just"&&o._1.startT<=i.startT?o:T("Just",i))(y)(e.windows);if(r.tag==="Just")return zr(t)(e)(r._1.startT+1e-4);if(r.tag==="Nothing")return y;c()},OT=t=>e=>n=>rd([QT(t)(e)(n),zr(t)(e)(n),WT(t)(e)(n)]),HT=t=>e=>n=>{const r=OT(t)(e)(n);return{level:(()=>{const o=t.padding*e.placement.scale;return{x:e.layout.bounds.x*e.placement.scale+e.placement.tx-o,y:e.layout.bounds.y*e.placement.scale+e.placement.ty-o,w:e.layout.bounds.w*e.placement.scale+o*2,h:e.layout.bounds.h*e.placement.scale+o*2}})(),visible:(()=>{const o=za(e)(n);return o.tag==="Just"?T("Just",{x:o._1.x*e.placement.scale+e.placement.tx,y:o._1.y*e.placement.scale+e.placement.ty,w:o._1.w*e.placement.scale,h:o._1.h*e.placement.scale}):y})(),action:r.tag==="Just"?T("Just",r._1.whole):y,actionText:(()=>{if(r.tag==="Just")return r._1.text;if(r.tag==="Nothing")return y;c()})(),actionGuide:(()=>{if(r.tag==="Just")return r._1.guide;if(r.tag==="Nothing")return y;c()})()}},ra=(t,e,n)=>({tag:t,_1:e,_2:n}),$T=t=>t,si=(t,e)=>({tag:t,_1:e}),dd=(t,e)=>({tag:t,_1:e}),jc=t=>t,pu=(t,e)=>({tag:t,_1:e}),t_=pu("NotYet"),hd=pu("Consumed"),qT=jc("FromSource"),pd=jc("FromTarget"),VT=jc("FromBoth"),mu=si("Hidden"),e_=si("Visible"),n_=$T("ExtendFromSource"),yu=ra("Retracted"),xu=ra("Extended"),UT={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},r_=t=>t,Ju=(t,e)=>({tag:t,_1:e}),oa={eq:bs(zi)},XT=(()=>{const t=gn.unfoldr(jn);return e=>t(cn("IterNode",e,Yn))})(),o_=fe(G)(Qt),to=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},md=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Qn=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},i_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=G.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}}c()}return o},a_=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=G.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}}c()}return o},yd=Qt.foldMap(nx(G)),ui=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},KT=fe(G)(Qt),YT=fe(G)(Qt),ZT=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},xd=Ju("Closed"),jT=Ju("Open"),Jd=r_("Backdrop"),tN=r_("FlyThrough"),ln=r_("Active"),wu=t=>e=>n=>{const r=te(o=>oa.eq(o.path)(e)&&n>=o.startT&&n<o.endT)(t.segments);if(r.tag==="Just")return T("Just",r._1);if(r.tag==="Nothing")return te(o=>oa.eq(o.path)(e))(t.segments);c()},eN=t=>{const e=te(n=>n.path.length===0)(t.segments);if(e.tag==="Just")return e._1.edgeEndpoints;if(e.tag==="Nothing")return W;c()},nN=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:vc,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:eN(t)}),Tu=t=>e=>n=>({...n,minis:K(r=>{const o=Tu(t)(e)({...r,state:{...r.state,tokens:W,nodeInvert:W,visited:W}});return(()=>{const i=r.segment.path;return oe(a=>a.direction==="DiveOut"&&oa.eq(a.childPath)(i)&&a.endT<=e+1e-4,t.dives)})()?{...o,bgAlpha:1}:o})(n.minis)}),rN=t=>K(e=>e<1?[]:At(0,e,t))(Ut(0,t.length-1|0)),oN=t=>e=>K(n=>oa.eq(n.segment.path)(t)?{...n,bgAlpha:e,state:{...n.state,tokens:W,nodeInvert:W,visited:W}}:n),iN=t=>b(e=>n=>(e*31|0)+Yr(n)|0)(7)(tr(t)),aN=t=>e=>n=>({...n,state:{...n.state,nodes:o_(K(r=>E(r._1,t(r._1)(r._2)))(XT(n.state.nodes))),edges:(()=>{const r=o=>{if(o.tag==="Leaf")return W;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,e(o._4),r(o._5),r(o._6));c()};return r(n.state.edges)})()}}),s_=t=>e=>n=>{const r=to(e)(t.keyframes);if(r.tag==="Just")return md(n)(r._1.labels);if(r.tag==="Nothing")return y;c()},sN=t=>e=>ht(n=>md(e)(n.labels))((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Jt("Cons",r._4,n(r._6,o)));c()};return Mt(ce.foldr,n(t.keyframes,A))})()),uN=b(t=>e=>{const n=Rr(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?Et(n._1.init)({...n._1.last,endT:Qn(n._1.last.endT)(e.endT),windows:Et(n._1.last.windows)(e)}):Et(t)({endT:e.endT,windows:[e]})})([]),gN=t=>b(e=>n=>{if(!e.leading)return e;if(n.scene.tag==="Structural"){if((()=>{const r=to(n.scene._1.to)(t.keyframes),o=to(e.keyframe)(t.keyframes);return!(o.tag==="Just"&&r.tag==="Just"&&Zn(G.compare,o._1.nodes,r._1.nodes).tag==="Leaf"&&Zn(G.compare,o._1.edges,r._1.edges).tag==="Leaf")})())return{...e,leading:!1};if((()=>{const r=to(n.scene._1.to)(t.keyframes);if(r.tag==="Nothing")return!0;if(r.tag==="Just")return!r._1.authored;c()})())return{...e,keyframe:n.scene._1.to};if(!e.namedSceneSeen)return{...e,keyframe:n.scene._1.to,namedSceneSeen:!0}}return{...e,leading:!1}})({keyframe:t.initialKeyframe,leading:!0,namedSceneSeen:(()=>{const e=to(t.initialKeyframe)(t.keyframes);if(e.tag==="Just")return!(e._1.nodes.tag==="Leaf"&&e._1.edges.tag==="Leaf");if(e.tag==="Nothing")return!1;c()})()})(t.spans).keyframe,wd=t=>{const e=to(gN(t))(t.keyframes);if(e.tag==="Just")return{nodes:e._1.nodes,edges:e._1.edges};if(e.tag==="Nothing")return{nodes:W,edges:W};c()},cN=t=>{const e=wd(t);return b(Qn)(t.startT)(ht(n=>n.target.tag==="NodeWindow"?n.target._2==="PlopIn"&&i_(n.target._1)(e.nodes)?T("Just",n.endT):y:n.target.tag==="EdgeWindow"&&n.target._2.tag==="Extend"&&a_(n.target._1)(e.edges)?T("Just",n.endT):y)(t.windows))},Td=t=>e=>{const n=wd(t);return{...e,state:{...e.state,nodes:$g()(r=>o=>T("Just",i_(r)(n.nodes)?e_:o))(e.state.nodes),edges:$g()(r=>o=>T("Just",a_(r)(n.edges)?xu:o))(e.state.edges)}}},_N=t=>e=>n=>e.path.length===0||t>=cN(e)?n:Td(e)(n),fN=t=>e=>n=>yd(r=>yd(o=>o.target.tag==="FillWindow"?o.startT<=n?ee("Node",1,1,o.target._2,void 0,W,W):W:o.target.tag==="TokenWindow"&&o.startT+(o.endT-o.startT)*.25<=n?ee("Node",1,1,o.target._4,void 0,W,W):W)(r.windows))(_t(r=>n<=r.endT+t,uN(Rt(r=>o=>at.compare(r.startT)(o.startT))(_t(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),lN=t=>e=>{const n=Bt(r=>y,r=>o=>T("Just",{head:r,tail:o}),sN(t)(e));if(n.tag==="Nothing")return!1;if(n.tag==="Just"){const r=n._1.head;return oe(o=>o!==r,n._1.tail)}c()},dN=t=>e=>n=>oe(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),hN=t=>e=>n=>oe(r=>r.endT<=e&&r.target.tag==="RelabelWindow"&&r.target._1===n,t),pN=t=>e=>n=>{const r=ta(t)(e);if(r.tag==="AtKeyframe")return s_(t)(r._1)(n);if(r.tag==="InTransition")return hN(t.windows)(e)(n)?s_(t)(r._2)(n):s_(t)(r._1)(n);c()},mN=t=>e=>n=>oe(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),yN=t=>e=>n=>oe(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),xN=t=>e=>n=>oe(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),JN=t=>e=>{const n=ta(t)(e),r=(()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;c()})(),o=to(r)(t.keyframes);return o.tag==="Just"&&o._1.authored?r:""},wN=t=>e=>{const n=ta(t)(e),r=to((()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;c()})())(t.keyframes);if(r.tag==="Just")return r._1.kind;if(r.tag==="Nothing")return Ra;c()},Nd=t=>{const e=j1(y,U1,o=>(()=>{const i=to((()=>{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;c()})())(t.keyframes);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return i._1.nodes.tag==="Leaf";c()})()?y:T("Just",Qn(o.startT)(o.endT-1e-4)),t.spans),n=(()=>{if(e.tag==="Nothing")return t.startT;if(e.tag==="Just")return e._1;c()})(),r=te(o=>o.target.tag==="NodeWindow"&&o.target._2==="PlopIn")(Rt(o=>i=>at.compare(o.startT)(i.startT))(t.windows));if(r.tag==="Nothing")return n;if(r.tag==="Just")return Qn(r._1.startT)(r._1.endT-1e-4);c()},Qa=t=>e=>n=>te(r=>n(r)&&e>=r.startT&&e<r.endT)(t),TN={segment:{startT:0,endT:0,path:[],layout:{nodes:W,edges:W,bounds:{x:0,y:0,w:0,h:0},chipExtras:W,edgeLabels:W},placement:vc,windows:[],spans:[],keyframes:W,initialKeyframe:"",edgeEndpoints:W},state:{animationTime:0,nodes:W,nodeLabels:W,edgeEndpoints:W,edges:W,tokens:W,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:Ra,visited:W,nodeFadeAlpha:W,nodeLabelFadeAlpha:W,edgeFadeAlpha:W,nodeInvert:W},bgAlpha:1,minis:[],role:ln},bd=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:TN},Wa=t=>e=>{const n=t.endT-t.startT;return n<=0?1:Qn(0)(ui(1)((e-t.startT)/n))},NN=t=>e=>n=>xc(jo(t.cameraConfig)(t.layout)(t.cameraSpans)(n.startT).camera)(jo(t.cameraConfig)(t.layout)(t.cameraSpans)(n.endT).camera)(Wa(n)(e)),vd=t=>e=>n=>{const r=Qn(0)(ui(1)((n-t)/Qn(1e-6)(e-t)));return r*r*r*(r*(r*6-15)+10)},Cd=t=>{if(t.tag==="Closed")return 0;if(t.tag==="Opening")return vd(.3)(1)(t._1);if(t.tag==="Open")return 1;if(t.tag==="Closing")return 1-vd(0)(.7)(t._1);c()},bN=t=>{const e=Cd(t);return e<=0||e>=1?0:en(3.141592653589793*e)},vN=t=>e=>n=>Qn(0)(ui(1)((n-Pe(0)(.3)(t+iN(e)|0).value)/.7)),gi=t=>e=>{const n=t.endT-t.startT;return n<=0?1:Qn(0)(ui(1)((e-t.startT)/n))},CN=t=>e=>o_(ht(n=>{const r=Qa(t.windows)(e)(o=>o.target.tag==="RelabelWindow"&&o.target._1===n);if(r.tag==="Just")return r._1.target.tag==="RelabelWindow"?T("Just",E(n,dd("RelabelingNode",{oldLabel:r._1.target._2,newLabel:r._1.target._3,progress:gi(r._1)(e)}))):y;if(r.tag==="Nothing"){if(lN(t)(n)){const o=pN(t)(e)(n);if(o.tag==="Just")return T("Just",E(n,dd("StaticNodeLabel",o._1)));if(o.tag==="Nothing")return y;c()}return y}c()})((()=>{const n=r=>{if(r.tag==="Leaf")return W;if(r.tag==="Node")return ee("Node",r._1,r._2,r._3,void 0,n(r._5),n(r._6));c()};return Mt(Jn.foldr,n(t.layout.nodes))})())),LN=t=>e=>n=>r=>o=>{const i=Qa(e)(n)(a=>a.target.tag==="EdgeWindow"&&a.target._2.tag==="Retract"&&a.target._1===o);if(i.tag==="Just"){const a=Hi(t.timing.edgeEasing)(gi(i._1)(n)),s=i._1.target.tag==="EdgeWindow"?i._1.target._2:cu("Extend",n_);if(s.tag==="Retract")return ra("Retracting",s._1,a);if(s.tag==="Extend")return ra("Extending",s._1,a);c()}if(i.tag==="Nothing"){if(dN(e)(n)(o))return yu;const a=Qa(e)(n)(s=>s.target.tag==="EdgeWindow"&&s.target._1===o);if(a.tag==="Just"){const s=Hi(t.timing.edgeEasing)(gi(a._1)(n)),u=a._1.target.tag==="EdgeWindow"?a._1.target._2:cu("Extend",n_);if(u.tag==="Retract")return ra("Retracting",u._1,s);if(u.tag==="Extend")return ra("Extending",u._1,s);c()}if(a.tag==="Nothing")return xN(e)(n)(o)?yu:a_(o)(r)?xu:yu}c()},kN=t=>e=>n=>{const r=Vc(e)(n);return KT(K(o=>E(o,LN(t)(e.windows)(n)(r)(o)))((()=>{const o=i=>{if(i.tag==="Leaf")return W;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,void 0,o(i._5),o(i._6));c()};return Mt(Jn.foldr,o(e.layout.edges))})()))},SN=t=>e=>n=>r=>{const o=Qa(t)(e)(i=>i.target.tag==="NodeWindow"&&i.target._1===r&&i.target._2==="PlopOut");if(o.tag==="Just"){const i=gi(o._1)(e),a=o._1.target.tag==="NodeWindow"?o._1.target._2:Wc;if(a==="PlopIn")return si("PloppingIn",i);if(a==="PlopOut")return si("PloppingOut",i);c()}if(o.tag==="Nothing"){if(mN(t)(e)(r))return mu;const i=Qa(t)(e)(a=>a.target.tag==="NodeWindow"&&a.target._1===r);if(i.tag==="Just"){const a=gi(i._1)(e),s=i._1.target.tag==="NodeWindow"?i._1.target._2:Wc;if(s==="PlopIn")return si("PloppingIn",a);if(s==="PlopOut")return si("PloppingOut",a);c()}if(i.tag==="Nothing")return yN(t)(e)(r)?mu:i_(r)(n)?e_:mu}c()},EN=t=>e=>{const n=qc(t)(e);return o_(K(r=>E(r,SN(t.windows)(e)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return W;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));c()};return Mt(Jn.foldr,r(t.layout.nodes))})()))},RN=t=>e=>n=>e.target.tag==="TokenWindow"?E(e.target._1,n<e.startT?t_:n>=e.endT?hd:pu("Travelling",{edge:e.target._2,direction:e.target._3,progress:Hi(t.timing.tokenEasing)(gi(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"?E(e.target._1,n<e.startT?t_:n>=e.endT?hd:pu("Filling",{node:e.target._2,progress:gi(e)(n),labels:e.target._3})):E("",t_),PN=t=>e=>n=>YT(K(r=>RN(t)(r)(n))(_t(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),BN=t=>e=>n=>({animationTime:n,nodes:EN(e)(n),nodeLabels:CN(e)(n),edgeEndpoints:e.edgeEndpoints,edges:kN(t)(e)(n),tokens:PN(t)(e.windows)(n),camera:jo(t.cameraConfig)(e.layout)(t.cameraSpans)(n).camera,frameTitle:JN(e)(n),staticKind:wN(e)(n),visited:fN(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:W,nodeLabelFadeAlpha:W,edgeFadeAlpha:W,nodeInvert:W}),ia=t=>e=>n=>r=>({segment:n,state:BN(t)(n)(e),bgAlpha:1,minis:GN(t)(e)(n),role:r}),GN=t=>e=>n=>ht(r=>{const o=wu(t)(Et(n.path)(r))(e);if(o.tag==="Just")return T("Just",{...ia(t)(ZT(o._1.startT)(o._1.endT-1e-4)(e))(o._1)(Jd),bgAlpha:0});if(o.tag==="Nothing")return y;c()})((()=>{const r=o=>{if(o.tag==="Leaf")return W;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));c()};return Mt(Jn.foldr,r(n.layout.nodes))})()),AN=t=>e=>{if(t.direction==="DiveIn")return Nd(e);if(t.direction==="DiveOut")return t.startT-1e-4;c()},IN=t=>e=>n=>e>=1?n:aN(r=>o=>o.tag==="Hidden"?mu:si("PloppingIn",Qn(.4)(vN(t)(r)(e))))(r=>r.tag==="Retracted"?yu:xu)(n),Ld=t=>e=>ht(n=>{const r=te(o=>o.direction==="DiveIn"&&oa.eq(o.childPath)((()=>{const i=n.length+1|0;return i<1?[]:At(0,i,e)})()))(t.dives);if(r.tag==="Just"){const o=wu(t)(n)(r._1.startT-1e-4);if(o.tag==="Just")return T("Just",(()=>{const i=ia(t)(r._1.startT-1e-4)(o._1)(Jd);return{...i,state:{...i.state,nodeFadeAlpha:ee("Node",1,1,r._1.node,0,W,W)}}})());if(o.tag==="Nothing")return y;c()}if(r.tag==="Nothing")return y;c()})(rN(e)),kd=t=>e=>{const n=_t(o=>e>=o.startT&&e<o.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:nN(t)},zN=t=>e=>n=>r=>{const o=g=>{const _=ia(t)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT;c()})())(g)(tN);return{..._,bgAlpha:1,minis:(()=>{if(n.direction==="DiveIn")return _t(f=>!oa.eq(f.segment.path)(n.childPath),_.minis);if(n.direction==="DiveOut")return n.childPath.length>1?oN(n.childPath)(Wa(n)(e))(Tu(t)(n.startT)(_).minis):Tu(t)(n.startT)(_).minis;c()})(),state:{..._.state,edgeFadeAlpha:W,nodeFadeAlpha:ee("Node",1,1,n.node,0,W,W),nodeInvert:W,tokens:W}}},i=wu(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT;c()})()),a=wu(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;c()})()),s=n.direction==="DiveOut"&&n.childPath.length>1?1-Wa(n)(e):1,u=Qn(0)(ui(1)((Wa(n)(e)-.25)/.55));return[...Ld(t)(n.parentPath),...(()=>{if(i.tag==="Just"){if(a.tag==="Just")return[o(i._1),(()=>{const g=Td(a._1)(ia(t)(AN(n)(a._1))(a._1)(ln)),_={...g,bgAlpha:s,state:{...g.state,tokens:W,nodeInvert:W,visited:W}};if(n.direction==="DiveIn")return IN(t.seed)(u)(_);if(n.direction==="DiveOut")return Tu(t)(n.startT)(_);c()})()];if(a.tag==="Nothing")return[o(i._1)];c()}if(i.tag==="Nothing")return[ia(t)(e)(kd(t)(e))(ln)];c()})()]},DN=t=>e=>te(n=>e>=n.startT&&e<n.endT)(t.dives),FN=t=>e=>{const n=kd(t)(e),r=t.dives.length!==0,o=jo(t.cameraConfig)(t.layout)(t.cameraSpans)(e).camera,i=IT(t.cameraConfig)(t.cameraViewport)(t.layout)(n)(e)(o),a=Ld(t)(n.path),s=_N(e)(n)(ia(t)(n.path.length===0?e:Qn(e)(Nd(n)))(n)(ln)),u={...s,state:{...s.state,camera:i}},g=DN(t)(e);if(g.tag==="Just"){const _=Wa(g._1)(e);return{levels:zN(t)(e)(g._1)(NN(t)(e)(g._1)),camera:o,rootLayout:t.layout,hasDives:r,portalState:(()=>{if(g._1.direction==="DiveIn")return Ju("Opening",Qn(0)(ui(1)(_)));if(g._1.direction==="DiveOut")return Ju("Closing",Qn(0)(ui(1)(_)));c()})()}}if(g.tag==="Nothing")return{levels:Et(a)(u),camera:i,rootLayout:t.layout,hasDives:r,portalState:n.path.length===0?xd:jT};c()},MN=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},QN=t=>{const e=t.length;return(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,g=i;if(u>=e){a=!1,s=g;continue}const _=f=>l=>{let d=f,h=l,m=!0,p;for(;m;){const x=d,J=h;if(x>=e){m=!1,p=J;continue}if(u>=0&&u<t.length){if(x>=0&&x<t.length){d=x+1|0,h=(()=>{const w=t[u].position,N=t[u].size,L=t[x].position,C=t[x].size;return w._1<L._1+C._1&&L._1<w._1+N._1&&w._2<L._2+C._2&&L._2<w._2+N._2})()?J+1|0:J;continue}d=x+1|0,h=J;continue}m=!1,p=J}return p};o=u+1|0,i=_(u+1|0)(g)}return s})(0)(0)},Sd=t=>b(e=>n=>e+dx(n.start)(n.end))(0)(t.segments),WN=t=>e=>n=>({crossingCount:b(r=>o=>r+o.jumps.length|0)(0)(e),bendCount:b(r=>o=>r+o.bends.length|0)(0)(e),totalEdgeLength:b(r=>o=>r+Sd(o))(0)(e),maxEdgeLength:b(r=>o=>MN(r)(Sd(o)))(0)(e),nodeOverlapCount:QN(t),constraintViolations:n,jumpCount:b(r=>o=>r+o.jumps.length|0)(0)(e)}),u_=t=>t,de=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},g_=u_("LEFT"),ON=u_("RIGHT"),Ed=u_("UNDEFINED"),HN={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},$N={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?un:Me;if(e==="LEFT")return Qe;if(t==="RIGHT")return e==="RIGHT"?un:Me;if(e==="RIGHT")return Qe;if(t==="UP")return e==="UP"?un:Me;if(e==="UP")return Qe;if(t==="DOWN")return e==="DOWN"?un:Me;if(e==="DOWN")return Qe;if(t==="UNDEFINED"&&e==="UNDEFINED")return un;c()},Eq0:()=>HN},qN=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}}c()}return o},VN={x:0,y:0},Wn=t=>e=>n=>{const r=de(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:it(ut)(t)(e(r._1))(n.cNodes)};c()},Oa=t=>e=>n=>{const r=de(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:it(ut)(t)(e(r._1))(n.cGroups)};c()},UN=t=>b(e=>n=>Wn(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),XN=t=>{const e=b(n=>r=>{const o=de(r)(t.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just")return b(i=>a=>Wt(ut)(Je)(a)([r])(i))(n)(o._1.constraints);c()})(W)(t.cNodeOrder);return b(n=>r=>Wn(r)(o=>({...o,constraints:(()=>{const i=de(r)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;c()})()}))(n))(t)(t.cNodeOrder)},KN=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}})),YN=t=>{const e=b(n=>r=>Oa(r)(o=>({...o,outDegree:o.outDegreeReal}))(n))(t)(t.cGroupOrder);return b(n=>r=>Wn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder)},hr={left:!1,right:!1,up:!1,down:!1},ZN={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},c_=t=>b(e=>n=>{const r=de(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const o=b(a=>s=>{const u=de(s)(e.cNodes);if(u.tag==="Nothing")return a;if(u.tag==="Just"){if(a.tag==="Nothing")return T("Just",s);if(a.tag==="Just"){const g=de(a._1)(e.cNodes);if(g.tag==="Nothing")return T("Just",s);if(g.tag==="Just")return u._1.hitbox.x<g._1.hitbox.x?T("Just",s):T("Just",a._1)}}c()})(y)(r._1.cNodes),i=Oa(n)(a=>({...a,reference:o}))(e);if(o.tag==="Nothing")return i;if(o.tag==="Just"){const a=de(o._1)(i.cNodes);if(a.tag==="Nothing")return i;if(a.tag==="Just"){const s=a._1;return b(u=>g=>Wn(g)(_=>({..._,cGroupOffset:{x:_.hitbox.x-s.hitbox.x,y:_.hitbox.y-s.hitbox.y}}))(u))(i)(r._1.cNodes)}}}c()})(t)(t.cGroupOrder),On=t=>c_({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return W;if(n.tag==="Node")return ee("Node",n._1,n._2,n._3,{...n._4,hitbox:{...n._4.hitbox,x:-n._4.hitbox.x-n._4.hitbox.width}},e(n._5),e(n._6));c()};return e(t.cNodes)})()}),Dr=t=>c_({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return W;if(n.tag==="Node")return ee("Node",n._1,n._2,n._3,{...n._4,hitbox:{x:n._4.hitbox.y,y:n._4.hitbox.x,width:n._4.hitbox.height,height:n._4.hitbox.width},cGroupOffset:{x:n._4.cGroupOffset.y,y:n._4.cGroupOffset.x}},e(n._5),e(n._6));c()};return e(t.cNodes)})()}),Rd=t=>{const e=b(n=>r=>Oa(r)(o=>({...o,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return b(n=>r=>{const o=de(r)(n.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just"){if(o._1.cGroup.tag==="Nothing")return n;if(o._1.cGroup.tag==="Just"){const i=o._1.cGroup._1;return b(a=>s=>{const u=de(s)(a.cNodes);if(u.tag==="Nothing")return a;if(u.tag==="Just")return u._1.cGroup.tag==="Just"&&u._1.cGroup._1!==i?Oa(u._1.cGroup._1)(g=>({...g,outDegree:g.outDegree+1|0,outDegreeReal:g.outDegreeReal+1|0}))(Oa(i)(g=>yn(go)(s)(g.incomingConstraints)?g:{...g,incomingConstraints:[...g.incomingConstraints,s]})(a)):a;c()})(n)(o._1.constraints)}}c()})(e)(e.cNodeOrder)},Nu=t=>{const e=XN(t.cGraph);return{...t,cGraph:Rd(b(n=>r=>Wn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},jN=t=>e=>b(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),pr=t=>{const e={...t,cGraph:jN(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return W;if(r.tag==="Node")return ee("Node",r._1,r._2,r._3,{...r._4,constraints:[]},n(r._5),n(r._6));c()};return n(t.cGraph.cNodes)})()})};return{...e,cGraph:Rd((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);c()})())}},tb=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?pr(r):e==="RIGHT"?pr({...r,cGraph:On(r.cGraph)}):e==="UP"?pr({...r,cGraph:Dr(r.cGraph)}):e==="DOWN"?pr({...r,cGraph:On(Dr(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?Nu({...r,cGraph:On(r.cGraph)}):e==="UP"?pr({...r,cGraph:Dr(r.cGraph)}):e==="DOWN"?pr({...r,cGraph:On(Dr(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?Nu({...r,cGraph:On(r.cGraph)}):e==="UP"?pr({...r,cGraph:Dr(On(r.cGraph))}):e==="DOWN"?pr({...r,cGraph:On(Dr(On(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?pr({...r,cGraph:Dr(r.cGraph)}):e==="RIGHT"?pr({...r,cGraph:On(Dr(r.cGraph))}):e==="DOWN"?Nu({...r,cGraph:On(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?pr({...r,cGraph:Dr(On(r.cGraph))}):e==="RIGHT"?pr({...r,cGraph:On(Dr(On(r.cGraph)))}):e==="UP"?Nu({...r,cGraph:On(r.cGraph)}):r;c()},Pd=t=>e=>e.finished||!qN(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:tb(e.direction)(t)(e),eb=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?Pd(g_)(t):t,n={...e,cGraph:YN(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);c()},Bd=t=>e=>n=>{const r=de(t)(n.cNodes),o=de(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;c()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:it(ut)(t)({...r._1,cGroup:T("Just",e)})(n.cNodes),cGroups:it(ut)(e)({...o._1,cNodes:yn(go)(t)(o._1.cNodes)?o._1.cNodes:[...o._1.cNodes,t],reference:(()=>{if(o._1.reference.tag==="Nothing")return T("Just",t);if(o._1.reference.tag==="Just")return T("Just",o._1.reference._1);c()})()})(n.cGroups)}:n},Gd=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:it(ut)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:y,cGroupOffset:VN,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:hr})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),__=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:b(r=>o=>Bd(o)(n)(r))({...e,cGroups:it(ut)(n)({id:n,master:t.master,cNodes:[],startPos:-1e308,incomingConstraints:[],outDegree:0,outDegreeReal:0,reference:y,delta:0,deltaNormalized:0})(e.cGroups),cGroupOrder:[...e.cGroupOrder,n],nextCGroupId:n+1|0})(t.nodes)}},nb=t=>b(e=>n=>{const r=de(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?__({master:y,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),rb=t=>({cGraph:UN(nb(c_(t))),direction:Ed,compactionAlgorithm:y,constraintAlgorithm:y,spacingsHandler:ZN,lockFun:y,finished:!1}),ob=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},ib=t=>e=>{const n=at.compare(t._1)(e._1);return n==="LT"?Me:n==="GT"?Qe:ut.compare(t._2)(e._2)},ab=(()=>{const t=gn.unfoldr(jn);return e=>t(cn("IterNode",e,Yn))})(),Ad=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Id=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",zd=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),bu=t=>e=>ib(E(t.hitbox.x+t.hitbox.width/2,t.id))(E(e.hitbox.x+e.hitbox.width/2,e.id)),sb=t=>e=>{const n=Wo(Yt,y,r=>bu(t)(r)==="LT",e);if(n.tag==="Just"){const r=tf(Yt,y,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;c()}if(n.tag==="Nothing")return Et(e)(t);c()},Dd=t=>e=>{const n=_t(o=>bu(o)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?T("Just",n[r]):y},ub=t=>e=>{const n=sb(e)(t.intervals),r=te(i=>bu(e)(i)==="LT")(n),o=it(ut)(e.id)((()=>{const i=Dd(e)(n);return i.tag==="Just"?T("Just",i._1.id):y})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return it(ut)(r._1.id)(T("Just",e.id))(o);if(r.tag==="Nothing")return o;c()})()}},gb=t=>e=>{const n=at.compare(t.low?t.node.hitbox.y:t.node.hitbox.y+t.node.hitbox.height)(e.low?e.node.hitbox.y:e.node.hitbox.y+e.node.hitbox.height);return n==="EQ"?t.low?t.low&&!e.low?Qe:un:e.low?Me:un:n},cb=t=>b(e=>n=>Wn(n.id)(r=>({...r,constraints:[]}))(e))(t)(ht(e=>de(e)(t.cNodes))(t.cNodeOrder)),f_=t=>e=>b(n=>r=>{const o=de(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;c()})(e)(ab(t)),Fd=t=>e=>e.kind.tag!=="Nothing"&&e.kind.tag==="Just"&&e.kind._1==="vs"?e.ignoreSpacing.up?e.ignoreSpacing.down?e:{...e,hitbox:{...e.hitbox,height:e.hitbox.height+t+.01}}:{...e,hitbox:{...e.hitbox,y:e.hitbox.y-t-.01,height:e.hitbox.height+t+.01}}:{...e,hitbox:{...e.hitbox,y:e.hitbox.y-t,height:e.hitbox.height+2*t}},Md=t=>e=>n=>b(r=>o=>n(o)?Wn(o.id)(Fd(t))(r):r)(e)(ht(r=>de(r)(e.cNodes))(e.cNodeOrder)),_b=t=>e=>{const n=(r,o,i)=>{const a=Wn(i)(Fd(t))(r);return o.length<=1?a:b(s=>u=>u===i?s:Wn(u)(g=>g.ignoreSpacing.up?{...g,hitbox:{...g.hitbox,y:g.hitbox.y+t+.01,height:g.hitbox.height-t-.01}}:g.ignoreSpacing.down?{...g,hitbox:{...g.hitbox,height:g.hitbox.height-t-.01}}:g)(s))(a)(o)};return b(r=>o=>{if(o.master.tag==="Nothing")return 0<o.cNodes.length?n(r,o.cNodes,o.cNodes[0]):r;if(o.master.tag==="Just")return n(r,o.cNodes,o.master._1);c()})(e)(ht(r=>de(r)(e.cGroups))(e.cGroupOrder))},fb=t=>e=>{const n=Dd(e)(t.intervals),r=te(i=>bu(e)(i)==="LT")(t.intervals),o=n.tag==="Just"&&(()=>{const i=Ad(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})()?Wt(ut)(Je)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const i=Ad(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})()?Wt(ut)(Je)(e.id)([r._1.id])(o):o,intervals:_t(i=>i.id!==e.id,t.intervals)}},lb=t=>e=>e.low?ub(t)(e.node):fb(t)(e.node),l_=t=>e=>b(lb)({intervals:[],cand:W,constraints:W})(Rt(gb)(St(_t(t,ht(n=>de(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,db=t=>e=>{const n=ob(0)(t/2-.5),r=f_(l_(Id)(Md(n)(e)(Id)))(e),o=f_(l_(zd)(Md(n)(r)(zd)))(r);return f_(l_(i=>!0)(_b(n)(o)))(o)},hb=t=>e=>db(t)(cb(e.cGraph)),vu=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Qd=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},d_=t=>e=>n=>r=>o=>({id:t,representedEdges:[o],affectedBends:[e,n],hitbox:{x:vu(e._1)(n._1),y:vu(e._2)(n._2),width:xe(e._1-n._1),height:xe(e._2-n._2)},ignoreSpacing:hr,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];c()})(),aPort:y}),pb=t=>e=>{const n=vu(t.hitbox.x)(e.hitbox.x),r=vu(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:Qd(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Qd(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;c()})()}},mb=t=>e=>xe(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,yb=t=>e=>xe(t.hitbox.x-e.hitbox.x)<=1e-4?at.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?Me:Qe,Wd=(t,e)=>({tag:t,_1:e}),h_=fe(G)(Qt),Cu=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Od=(()=>{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=G.compare(n._1)(r._1);if(o==="LT")return Me;if(o==="GT")return Qe;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?un:Me;if(r._2.tag==="Nothing")return Qe;if(n._2.tag==="Just"&&r._2.tag==="Just")return G.compare(n._2._1)(r._2._1);c()},Eq0:()=>t};return b(n=>r=>it(e)(r)()(n))(W)})(),eo=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},xb=b(t=>e=>it($N)(e)()(t))(W),p_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=If.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Jb=t=>e=>{const n=h_(K(i=>E(i.id,i))(t)),r=ht(i=>Cu(i)(n))(e),o=ut.compare((()=>{const i=Od(K(a=>E(a.from.node,a.from.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;c()})())((()=>{const i=Od(K(a=>E(a.to.node,a.to.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;c()})());if(o==="LT")return{...hr,left:!0,right:!1};if(o==="GT")return{...hr,left:!1,right:!0};if(o==="EQ")return hr;c()},wb=t=>ht(e=>{if(e.direction==="V")return T("Just",{start:e.start,end:e.end});if(e.direction==="H")return y;c()})(t.segments),Lu=t=>e=>n=>r=>{if(r.tag==="Just"){const o=eo(n)(e);if(o.tag==="Just"){const i=te(a=>a.id===r._1)(o._1);if(i.tag==="Just")return i._1.side;if(i.tag==="Nothing")return t;c()}if(o.tag==="Nothing")return t;c()}if(r.tag==="Nothing")return t;c()},Tb=t=>e=>n=>{const r=Gd({origin:T("Just",Wd("SegmentOrigin",n)),kind:T("Just","vs"),hitbox:n.hitbox})(e.cGraph),o=KN(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const i=de(n.potentialGroupParents[0])(o.cNodes);if(i.tag==="Just"){if(i._1.cGroup.tag==="Just")return Bd(r.id)(i._1.cGroup._1)(o);if(i._1.cGroup.tag==="Nothing")return o;c()}if(i.tag==="Nothing")return o;c()}return __({master:T("Just",r.id),nodes:[r.id]})(o).graph})(),edgeToCs:b(i=>a=>Wt(G)(Je)(a)([r.id])(i))(e.edgeToCs)(n.representedEdges),lockMap:it(ut)(r.id)(Jb(t)(n.representedEdges))(e.lockMap)}},Nb=t=>e=>n=>{const r=Bt(o=>y,o=>i=>T("Just",{head:o,tail:i}),Rt(yb)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const o=b(i=>a=>mb(i.survivor)(a)?{...i,survivor:pb(i.survivor)(a)}:{survivor:a,merged:[...i.merged,i.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return b(Tb(t))(n)([...o.merged,o.survivor])}c()},bb=t=>({cGraph:{cNodes:W,cNodeOrder:[],cGroups:W,cGroupOrder:[],supportedDirections:xb([Ed,g_,ON]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:W,edgeToCs:W,lockMap:W}),vb=t=>{const e=ot(4);return{x:t.position._1*e,y:t.position._2*e,width:t.size._1*e,height:t.size._2*e}},Cb=t=>e=>n=>b(r=>o=>{const i=Gd({origin:T("Just",Wd("NodeOrigin",o.node)),kind:y,hitbox:vb(o)})(r.cGraph),a=eo(o.node)(t),s=(()=>{if(a.tag==="Nothing")return E(0,0);if(a.tag==="Just")return a._1;c()})();return{...r,cGraph:__({master:T("Just",i.id),nodes:[i.id]})(i.graph).graph,nodeToC:it(G)(o.node)(i.id)(r.nodeToC),lockMap:it(ut)(i.id)((()=>{const u=s._1-s._2|0;return u<0?{...hr,left:!0}:u>0?{...hr,right:!0}:hr})())(r.lockMap)}})(n)(e),Lb=t=>b(e=>n=>Wt(G)(r=>o=>E(r._1+o._1|0,r._2+o._2|0))(n.to.node)(E(1,0))(Wt(G)(r=>o=>E(r._1+o._1|0,r._2+o._2|0))(n.from.node)(E(0,1))(e)))(W)(t),kb=t=>b(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?it(G)(n.origin._1._1)(n.hitbox.x)(e):e)(W)(ht(e=>de(e)(t.cNodes))(t.cNodeOrder)),Sb=t=>b(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?it(G)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(W)(ht(e=>de(e)(t.cNodes))(t.cNodeOrder)),Eb=t=>b(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return b(o=>i=>it(If)(i)(r)(o))(e)(n.origin._1._1.affectedBends)}return e})(W)(ht(e=>de(e)(t.cNodes))(t.cNodeOrder)),Hd=t=>{const e=h_(K(n=>E(n.id,n))(t.edges));return ht(n=>{const r=Cu(n.edge)(e);if(r.tag==="Just")return n.reversed?T("Just",{edgeId:n.edge,src:r._1.to.node,tgt:r._1.from.node,srcSide:Lu(Xr)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:Lu(Kr)(t.ports)(r._1.from.node)(r._1.from.port),path:n}):T("Just",{edgeId:n.edge,src:r._1.from.node,tgt:r._1.to.node,srcSide:Lu(Xr)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:Lu(Kr)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return y;c()})(t.paths)},Rb=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=eo(r.tgt)(t.nodeToC),i=(()=>{if(o.tag==="Just")return de(o._1)(t.cGraph.cNodes);if(o.tag==="Nothing")return y;c()})(),a=eo(r.src)(t.nodeToC),s=(()=>{if(a.tag==="Just")return de(a._1)(t.cGraph.cNodes);if(a.tag==="Nothing")return y;c()})(),u=(()=>{if(s.tag==="Just"){if(i.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(i._1.cGroup.tag==="Just")return T("Just",{srcGroup:s._1.cGroup._1,tgtGroup:i._1.cGroup._1,delta:0,weight:100});if(i._1.cGroup.tag==="Nothing")return y;c()}if(s._1.cGroup.tag==="Nothing")return y;c()}if(i.tag==="Nothing")return y;c()}if(s.tag==="Nothing")return y;c()})(),g=d=>h=>m=>{if(s.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(m.cGroup.tag==="Just")return d(m.hitbox.x)&&m.cGroup._1!==s._1.cGroup._1?T("Just",h(m.cGroup._1)(s._1.cGroup._1)):y;if(m.cGroup.tag==="Nothing")return y;c()}if(s._1.cGroup.tag==="Nothing")return y;c()}if(s.tag==="Nothing")return y;c()},_=ht(d=>de(d)(t.cGraph.cNodes))((()=>{const d=Cu(r.edgeId)(t.edgeToCs);if(d.tag==="Nothing")return[];if(d.tag==="Just")return d._1;c()})()),f=(()=>{if(s.tag==="Just"&&r.srcSide==="West"){const d=s._1;return ht(g(h=>h<d.hitbox.x)(h=>m=>({srcGroup:h,tgtGroup:m,delta:1,weight:100})))(_)}return[]})(),l=(()=>{if(s.tag==="Just"&&r.tgtSide==="East"){const d=s._1;return ht(g(h=>h>d.hitbox.x)(h=>m=>({srcGroup:m,tgtGroup:h,delta:1,weight:100})))(_)}return[]})();if(u.tag==="Nothing")return[];if(u.tag==="Just")return[u._1,...f,...l];c()});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 oe(a=>yn(Er)(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}},Pb=t=>e=>{const n=ot(4),r=kb(t),o=Sb(t),i=h_(K(s=>E(s.id,E(s.from.node,s.to.node)))(e.edges)),a=Eb(t);return{nodes:K(s=>{const u=eo(s.node)(r);if(u.tag==="Just")return{...s,position:E(u._1/n,s.position._2)};if(u.tag==="Nothing")return s;c()})(e.nodes),edges:K(s=>{const u=Cu(s.edge)(i),g=(()=>{if(u.tag==="Nothing")return s.segments;if(u.tag==="Just"){const _=eo(u._1._1)(o),f=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;c()})(),l=eo(u._1._2)(o),d=(()=>{if(l.tag==="Nothing")return 0;if(l.tag==="Just")return l._1;c()})();return Ft((()=>{const h=s.reversed?d:f,m=s.reversed?f:d,p=s.segments.length;return x=>J=>{if(J.direction==="V"){const w=(()=>{if(x===0)return h;if(x===(p-1|0))return m;const N=p_(J.start)(a);if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})();return{...J,start:E(J.start._1+w,J.start._2),end:E(J.end._1+w,J.end._2)}}if(J.direction==="H")return{...J,start:E((()=>{if(x===0)return J.start._1+h;const w=p_(J.start)(a);if(w.tag==="Nothing")return J.start._1+0;if(w.tag==="Just")return J.start._1+w._1;c()})(),J.start._2),end:E((()=>{if(x===(p-1|0))return J.end._1+m;const w=p_(J.end)(a);if(w.tag==="Nothing")return J.end._1+0;if(w.tag==="Just")return J.end._1+w._1;c()})(),J.end._2)};c()}})())(s.segments)}c()})();return{...s,segments:g,bends:We(_=>f=>_.end,g,At(1,g.length,g))}})(e.paths)}},Bb=t=>e=>n=>r=>o=>i=>{const a=d_(o.nextId)(i._2.start)(i._2.end)(y)(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}};c()}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}};c()}return s})()]}},$d=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...d_(i.nextId)(r.start)(E(r.start._1,o.down?n.y:n.y+n.height))(T("Just",e))(t.edgeId),aPort:T("Just",{node:t.src,side:o.side}),ignoreSpacing:o.down?{...hr,down:!0}:{...hr,up:!0}}]}),ku=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...d_(i.nextId)(r.end)(E(r.end._1,o.down?n.y:n.y+n.height))(T("Just",e))(t.edgeId),aPort:T("Just",{node:t.tgt,side:o.side}),ignoreSpacing:o.down?{...hr,down:!0}:{...hr,up:!0}}]}),Gb=t=>e=>n=>{if(n.src===n.tgt)return e;const r=eo(n.src)(t.nodeToC),o=eo(n.tgt)(t.nodeToC),i=(()=>{if(r.tag==="Just"){const _=de(r._1)(t.cGraph.cNodes);return _.tag==="Just"?T("Just",_._1.hitbox):y}if(r.tag==="Nothing")return y;c()})(),a=(()=>{if(o.tag==="Just"){const _=de(o._1)(t.cGraph.cNodes);return _.tag==="Just"?T("Just",_._1.hitbox):y}if(o.tag==="Nothing")return y;c()})(),s=wb(n.path),u=b(Bb(n)(i)(a)(s.length-1|0))(e)(Ft(_=>f=>E(_,f))(s));if(0<s.length){const _=(()=>{if(r.tag==="Just"&&i.tag==="Just"){if(n.srcSide==="North")return $d(n)(r._1)(i._1)(s[0])({side:Ie,down:!0})(u);if(n.srcSide==="South")return $d(n)(r._1)(i._1)(s[0])({side:ze,down:!1})(u)}return u})(),f=s.length-1|0;if(f>=0&&f<s.length&&o.tag==="Just"&&a.tag==="Just"){if(n.tgtSide==="North")return ku(n)(o._1)(a._1)(s[f])({side:Ie,down:!0})(_);if(n.tgtSide==="South")return ku(n)(o._1)(a._1)(s[f])({side:ze,down:!1})(_)}return _}const g=s.length-1|0;if(g>=0&&g<s.length&&o.tag==="Just"&&a.tag==="Just"){if(n.tgtSide==="North")return ku(n)(o._1)(a._1)(s[g])({side:Ie,down:!0})(u);if(n.tgtSide==="South")return ku(n)(o._1)(a._1)(s[g])({side:ze,down:!1})(u)}return u},Ab=t=>e=>n=>Nb(t)(b(Gb(n))({nextId:0,segments:[]})(e).segments)(n),Ib=t=>Ab(t.edges)(Hd(t))(Cb(Lb(t.edges))(t.nodes)(bb())),no=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}c()}return o},m_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},y_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},zb=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Db=t=>{const e=t.Eq0();return n=>r=>{const o=s=>{let u=s,g=!0,_;for(;g;){const f=u,l=Bt(d=>y,d=>h=>T("Just",{head:d,tail:h}),f.queue);if(l.tag==="Nothing"){g=!1,_=f;continue}if(l.tag==="Just"){const d=l._1.head;if((m=>{let p=m,x=!0,J;for(;x;){const w=p;if(w.tag==="Leaf"){x=!1,J=!1;continue}if(w.tag==="Node"){const N=t.compare(d)(w._3);if(N==="LT"){p=w._5;continue}if(N==="GT"){p=w._6;continue}if(N==="EQ"){x=!1,J=!0;continue}}c()}return J})(f.removedNodes)){u={...f,queue:l._1.tail};continue}const h=te(m=>!no(m.eid)(f.removedEdges)&&(e.eq(m.src)(d)||e.eq(m.tgt)(d)))(r);if(h.tag==="Nothing"){u={...f,queue:l._1.tail};continue}if(h.tag==="Just"){const m=e.eq(h._1.src)(d)?h._1.tgt:h._1.src,p={...f,degree:it(t)(m)((()=>{const x=(J=>{let w=J,N=!0,L;for(;N;){const C=w;if(C.tag==="Leaf"){N=!1,L=y;continue}if(C.tag==="Node"){const R=t.compare(m)(C._3);if(R==="LT"){w=C._5;continue}if(R==="GT"){w=C._6;continue}if(R==="EQ"){N=!1,L=T("Just",C._4);continue}}c()}return L})(f.degree);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;c()})())(f.degree),removedNodes:it(t)(d)()(f.removedNodes),removedEdges:it(ut)(h._1.eid)()(f.removedEdges),record:[...f.record,{node:d,neighbour:m,viaSrc:e.eq(h._1.src)(d)}],queue:l._1.tail};if((()=>{const x=(w=>{let N=w,L=!0,C;for(;L;){const R=N;if(R.tag==="Leaf"){L=!1,C=y;continue}if(R.tag==="Node"){const P=t.compare(m)(R._3);if(P==="LT"){N=R._5;continue}if(P==="GT"){N=R._6;continue}if(P==="EQ"){L=!1,C=T("Just",R._4);continue}}c()}return C})(p.degree),J=w=>{let N=w,L=!0,C;for(;L;){const R=N;if(R.tag==="Leaf"){L=!1,C=!1;continue}if(R.tag==="Node"){const P=t.compare(m)(R._3);if(P==="LT"){N=R._5;continue}if(P==="GT"){N=R._6;continue}if(P==="EQ"){L=!1,C=!0;continue}}c()}return C};return(()=>{if(x.tag==="Nothing")return!1;if(x.tag==="Just")return x._1===1;c()})()&&!J(p.removedNodes)})()){u={...p,queue:[...p.queue,m]};continue}u=p;continue}}c()}return _},i=b(s=>u=>Wt(t)(ve)(u.src)(1)(Wt(t)(ve)(u.tgt)(1)(s)))(W)(r),a=o({degree:i,removedNodes:W,removedEdges:W,record:[],queue:_t(s=>{const u=(g=>{let _=g,f=!0,l;for(;f;){const d=_;if(d.tag==="Leaf"){f=!1,l=y;continue}if(d.tag==="Node"){const h=t.compare(s)(d._3);if(h==="LT"){_=d._5;continue}if(h==="GT"){_=d._6;continue}if(h==="EQ"){f=!1,l=T("Just",d._4);continue}}c()}return l})(i);if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1===1;c()},n)});return{coreNodes:_t(s=>!(u=>{let g=u,_=!0,f;for(;_;){const l=g;if(l.tag==="Leaf"){_=!1,f=!1;continue}if(l.tag==="Node"){const d=t.compare(s)(l._3);if(d==="LT"){g=l._5;continue}if(d==="GT"){g=l._6;continue}if(d==="EQ"){_=!1,f=!0;continue}}c()}return f})(a.removedNodes),n),coreEdges:_t(s=>!no(s.eid)(a.removedEdges),r),removed:a.record}}},Fb=t=>e=>n=>b(r=>o=>{const i=o.neighbour,a=(()=>{const s=(u=>{let g=u,_=!0,f;for(;_;){const l=g;if(l.tag==="Leaf"){_=!1,f=y;continue}if(l.tag==="Node"){const d=t.compare(i)(l._3);if(d==="LT"){g=l._5;continue}if(d==="GT"){g=l._6;continue}if(d==="EQ"){_=!1,f=T("Just",l._4);continue}}c()}return f})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})();return it(t)(o.node)(o.viaSrc?a-1|0:a+1|0)(r)})(n)(re(e)),x_=t=>{const e=t.Eq0();return n=>r=>o=>{const i={...o,treeNode:it(t)(r)()(o.treeNode)};return b(a=>s=>{if(no(s.eid)(a.st.edgeVisited))return a;const u={...a.st,edgeVisited:it(ut)(s.eid)()(a.st.edgeVisited)},g=e.eq(s.src)((()=>{const _=s.src,f=d=>{let h=d,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const J=t.compare(_)(x._3);if(J==="LT"){h=x._5;continue}if(J==="GT"){h=x._6;continue}if(J==="EQ"){m=!1,p=!0;continue}}c()}return p},l=s.tgt;return f(u.treeNode)&&!(d=>{let h=d,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const J=t.compare(l)(x._3);if(J==="LT"){h=x._5;continue}if(J==="GT"){h=x._6;continue}if(J==="EQ"){m=!1,p=!0;continue}}c()}return p})(u.treeNode)})()?s.src:(()=>{const _=s.tgt,f=d=>{let h=d,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const J=t.compare(_)(x._3);if(J==="LT"){h=x._5;continue}if(J==="GT"){h=x._6;continue}if(J==="EQ"){m=!1,p=!0;continue}}c()}return p},l=s.src;return f(u.treeNode)&&!(d=>{let h=d,m=!0,p;for(;m;){const x=h;if(x.tag==="Leaf"){m=!1,p=!1;continue}if(x.tag==="Node"){const J=t.compare(l)(x._3);if(J==="LT"){h=x._5;continue}if(J==="GT"){h=x._6;continue}if(J==="EQ"){m=!1,p=!0;continue}}c()}return p})(u.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(no(s.eid)(u.treeEdge)){if((f=>{let l=f,d=!0,h;for(;d;){const m=l;if(m.tag==="Leaf"){d=!1,h=!1;continue}if(m.tag==="Node"){const p=t.compare(g)(m._3);if(p==="LT"){l=m._5;continue}if(p==="GT"){l=m._6;continue}if(p==="EQ"){d=!1,h=!0;continue}}c()}return h})(u.treeNode))return{...a,st:u};const _=x_(t)(n)(g)(u);return{count:a.count+_.count|0,st:_.st}}if((()=>{const _=l=>{let d=l,h=!0,m;for(;h;){const p=d;if(p.tag==="Leaf"){h=!1,m=!1;continue}if(p.tag==="Node"){const x=t.compare(g)(p._3);if(x==="LT"){d=p._5;continue}if(x==="GT"){d=p._6;continue}if(x==="EQ"){h=!1,m=!0;continue}}c()}return m},f=s.tgt;return!_(u.treeNode)&&(()=>{const l=(m=>{let p=m,x=!0,J;for(;x;){const w=p;if(w.tag==="Leaf"){x=!1,J=y;continue}if(w.tag==="Node"){const N=t.compare(f)(w._3);if(N==="LT"){p=w._5;continue}if(N==="GT"){p=w._6;continue}if(N==="EQ"){x=!1,J=T("Just",w._4);continue}}c()}return J})(u.layer),d=s.src,h=(m=>{let p=m,x=!0,J;for(;x;){const w=p;if(w.tag==="Leaf"){x=!1,J=y;continue}if(w.tag==="Node"){const N=t.compare(d)(w._3);if(N==="LT"){p=w._5;continue}if(N==="GT"){p=w._6;continue}if(N==="EQ"){x=!1,J=T("Just",w._4);continue}}c()}return J})(u.layer);if(l.tag==="Nothing"){if(h.tag==="Nothing")return s.delta===0;if(h.tag==="Just")return s.delta===-h._1;c()}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)}c()})()})()){const _=x_(t)(n)(g)({...u,treeEdge:it(ut)(s.eid)()(u.treeEdge)});return{count:a.count+_.count|0,st:_.st}}return{...a,st:u}})({count:1,st:i})(_t(a=>(e.eq(a.src)(r)||e.eq(a.tgt)(r))&&!no(a.eid)(i.edgeVisited),n))}},Su=t=>e=>n=>r=>{const o=r.src,i=(l=>{let d=l,h=!0,m;for(;h;){const p=d;if(p.tag==="Leaf"){h=!1,m=y;continue}if(p.tag==="Node"){const x=t.compare(o)(p._3);if(x==="LT"){d=p._5;continue}if(x==="GT"){d=p._6;continue}if(x==="EQ"){h=!1,m=T("Just",p._4);continue}}c()}return m})(e.poID),a=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;c()})(),s=r.tgt,u=(l=>{let d=l,h=!0,m;for(;h;){const p=d;if(p.tag==="Leaf"){h=!1,m=y;continue}if(p.tag==="Node"){const x=t.compare(s)(p._3);if(x==="LT"){d=p._5;continue}if(x==="GT"){d=p._6;continue}if(x==="EQ"){h=!1,m=T("Just",p._4);continue}}c()}return m})(e.poID),g=(()=>{if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;c()})(),_=(l=>{let d=l,h=!0,m;for(;h;){const p=d;if(p.tag==="Leaf"){h=!1,m=y;continue}if(p.tag==="Node"){const x=t.compare(n)(p._3);if(x==="LT"){d=p._5;continue}if(x==="GT"){d=p._6;continue}if(x==="EQ"){h=!1,m=T("Just",p._4);continue}}c()}return m})(e.poID),f=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;c()})();return(()=>{const l=r.src,d=(h=>{let m=h,p=!0,x;for(;p;){const J=m;if(J.tag==="Leaf"){p=!1,x=y;continue}if(J.tag==="Node"){const w=t.compare(l)(J._3);if(w==="LT"){m=J._5;continue}if(w==="GT"){m=J._6;continue}if(w==="EQ"){p=!1,x=T("Just",J._4);continue}}c()}return x})(e.lowestPoID);return(()=>{if(d.tag==="Nothing")return 0<=f;if(d.tag==="Just")return d._1<=f;c()})()&&(()=>{const h=r.tgt;return f<=a&&(()=>{const m=(p=>{let x=p,J=!0,w;for(;J;){const N=x;if(N.tag==="Leaf"){J=!1,w=y;continue}if(N.tag==="Node"){const L=t.compare(h)(N._3);if(L==="LT"){x=N._5;continue}if(L==="GT"){x=N._6;continue}if(L==="EQ"){J=!1,w=T("Just",N._4);continue}}c()}return w})(e.lowestPoID);return(()=>{if(m.tag==="Nothing")return 0<=f;if(m.tag==="Just")return m._1<=f;c()})()&&f<=g})()})()})()?a>=g:a<g},Mb=t=>{const e=fe(t)(Qt);return n=>({layer:e(K(r=>E(r,0))(n)),treeNode:W,treeEdge:W,poID:W,lowestPoID:W,cutvalue:W,postOrder:1,edgeVisited:W})},Qb=t=>e=>n=>b(r=>o=>{if((()=>{const _=o.src,f=h=>{let m=h,p=!0,x;for(;p;){const J=m;if(J.tag==="Leaf"){p=!1,x=!1;continue}if(J.tag==="Node"){const w=t.compare(_)(J._3);if(w==="LT"){m=J._5;continue}if(w==="GT"){m=J._6;continue}if(w==="EQ"){p=!1,x=!0;continue}}c()}return x},l=o.tgt,d=h=>{let m=h,p=!0,x;for(;p;){const J=m;if(J.tag==="Leaf"){p=!1,x=!1;continue}if(J.tag==="Node"){const w=t.compare(l)(J._3);if(w==="LT"){m=J._5;continue}if(w==="GT"){m=J._6;continue}if(w==="EQ"){p=!1,x=!0;continue}}c()}return x};return f(n.treeNode)===d(n.treeNode)})())return r;const i=o.tgt,a=(_=>{let f=_,l=!0,d;for(;l;){const h=f;if(h.tag==="Leaf"){l=!1,d=y;continue}if(h.tag==="Node"){const m=t.compare(i)(h._3);if(m==="LT"){f=h._5;continue}if(m==="GT"){f=h._6;continue}if(m==="EQ"){l=!1,d=T("Just",h._4);continue}}c()}return d})(n.layer),s=o.src,u=(_=>{let f=_,l=!0,d;for(;l;){const h=f;if(h.tag==="Leaf"){l=!1,d=y;continue}if(h.tag==="Node"){const m=t.compare(s)(h._3);if(m==="LT"){f=h._5;continue}if(m==="GT"){f=h._6;continue}if(m==="EQ"){l=!1,d=T("Just",h._4);continue}}c()}return d})(n.layer),g=(()=>{if(a.tag==="Nothing"){if(u.tag==="Nothing")return-o.delta;if(u.tag==="Just")return-u._1-o.delta|0;c()}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}c()})();return g<r.slack?{edge:T("Just",o),slack:g}:r})({edge:y,slack:1e9})(e).edge,Wb=t=>{const e=fe(t)(Qt);return n=>r=>{const o=b(i=>a=>m_(i)((()=>{const s=(u=>{let g=u,_=!0,f;for(;_;){const l=g;if(l.tag==="Leaf"){_=!1,f=y;continue}if(l.tag==="Node"){const d=t.compare(a)(l._3);if(d==="LT"){g=l._5;continue}if(d==="GT"){g=l._6;continue}if(d==="EQ"){_=!1,f=T("Just",l._4);continue}}c()}return f})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(1e9)(n);return e(K(i=>E(i,(()=>{const a=(s=>{let u=s,g=!0,_;for(;g;){const f=u;if(f.tag==="Leaf"){g=!1,_=y;continue}if(f.tag==="Node"){const l=t.compare(i)(f._3);if(l==="LT"){u=f._5;continue}if(l==="GT"){u=f._6;continue}if(l==="EQ"){g=!1,_=T("Just",f._4);continue}}c()}return _})(r);if(a.tag==="Nothing")return-o;if(a.tag==="Just")return a._1-o|0;c()})()))(n))}},qd=t=>{const e=t.Eq0();return n=>r=>o=>{const i=b(s=>u=>{const g=qd(t)(n)(e.eq(u.src)(r)?u.tgt:u.src)({...s.st,edgeVisited:it(ut)(u.eid)()(s.st.edgeVisited)});return{lowest:m_(s.lowest)(g.lowest),st:g.st}})({lowest:1e9,st:o})(_t(s=>no(s.eid)(o.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!no(s.eid)(o.edgeVisited),n)),a=m_(i.lowest)(i.st.postOrder);return{lowest:a,st:{...i.st,poID:it(t)(r)(i.st.postOrder)(i.st.poID),lowestPoID:it(t)(r)(a)(i.st.lowestPoID),postOrder:i.st.postOrder+1|0}}}},Vd=t=>{const e=qd(t);return n=>r=>o=>0<n.length?e(r)(n[0])({...o,edgeVisited:W,postOrder:1,poID:W,lowestPoID:W}).st:o},Ob=t=>{const e=t.Eq0();return n=>r=>o=>_t(i=>no(i.eid)(r.treeEdge)&&(e.eq(i.src)(o)||e.eq(i.tgt)(o)),n)},Hb=t=>e=>te(n=>{const r=y_(n.eid)(e.cutvalue);return no(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;c()})()})(t),Ud=t=>{const e=x_(t);return n=>r=>o=>{const i=0<n.length?T("Just",n[0]):y;if(i.tag==="Nothing")return o;if(i.tag==="Just"){const a=e(r)(i._1)({...o,edgeVisited:W,treeNode:W,treeEdge:W});if(a.count>=n.length)return a.st;const s=Qb(t)(r)(a.st);if(s.tag==="Nothing")return a.st;if(s.tag==="Just"){const u=s._1.tgt,g=(h=>{let m=h,p=!0,x;for(;p;){const J=m;if(J.tag==="Leaf"){p=!1,x=y;continue}if(J.tag==="Node"){const w=t.compare(u)(J._3);if(w==="LT"){m=J._5;continue}if(w==="GT"){m=J._6;continue}if(w==="EQ"){p=!1,x=T("Just",J._4);continue}}c()}return x})(a.st.layer),_=s._1.src,f=(h=>{let m=h,p=!0,x;for(;p;){const J=m;if(J.tag==="Leaf"){p=!1,x=y;continue}if(J.tag==="Node"){const w=t.compare(_)(J._3);if(w==="LT"){m=J._5;continue}if(w==="GT"){m=J._6;continue}if(w==="EQ"){p=!1,x=T("Just",J._4);continue}}c()}return x})(a.st.layer),l=(()=>{if(g.tag==="Nothing"){if(f.tag==="Nothing")return-s._1.delta;if(f.tag==="Just")return-f._1-s._1.delta|0;c()}if(g.tag==="Just"){if(f.tag==="Nothing")return(g._1-0|0)-s._1.delta|0;if(f.tag==="Just")return(g._1-f._1|0)-s._1.delta|0}c()})(),d=(()=>{const h=s._1.tgt;return(m=>{let p=m,x=!0,J;for(;x;){const w=p;if(w.tag==="Leaf"){x=!1,J=!1;continue}if(w.tag==="Node"){const N=t.compare(h)(w._3);if(N==="LT"){p=w._5;continue}if(N==="GT"){p=w._6;continue}if(N==="EQ"){x=!1,J=!0;continue}}c()}return J})(a.st.treeNode)})()?-l:l;return Ud(t)(n)(r)({...a.st,layer:b(h=>m=>(p=>{let x=p,J=!0,w;for(;J;){const N=x;if(N.tag==="Leaf"){J=!1,w=!1;continue}if(N.tag==="Node"){const L=t.compare(m)(N._3);if(L==="LT"){x=N._5;continue}if(L==="GT"){x=N._6;continue}if(L==="EQ"){J=!1,w=!0;continue}}c()}return w})(a.st.treeNode)?it(t)(m)((()=>{const p=(x=>{let J=x,w=!0,N;for(;w;){const L=J;if(L.tag==="Leaf"){w=!1,N=y;continue}if(L.tag==="Node"){const C=t.compare(m)(L._3);if(C==="LT"){J=L._5;continue}if(C==="GT"){J=L._6;continue}if(C==="EQ"){w=!1,N=T("Just",L._4);continue}}c()}return N})(a.st.layer);if(p.tag==="Nothing")return 0+d|0;if(p.tag==="Just")return p._1+d|0;c()})())(h):h)(a.st.layer)(n)})}}c()}},$b=t=>e=>n=>r=>b(o=>i=>{if(Su(t)(r)(i.src)(n)&&!Su(t)(r)(i.tgt)(n)){const a=i.tgt,s=(f=>{let l=f,d=!0,h;for(;d;){const m=l;if(m.tag==="Leaf"){d=!1,h=y;continue}if(m.tag==="Node"){const p=t.compare(a)(m._3);if(p==="LT"){l=m._5;continue}if(p==="GT"){l=m._6;continue}if(p==="EQ"){d=!1,h=T("Just",m._4);continue}}c()}return h})(r.layer),u=i.src,g=(f=>{let l=f,d=!0,h;for(;d;){const m=l;if(m.tag==="Leaf"){d=!1,h=y;continue}if(m.tag==="Node"){const p=t.compare(u)(m._3);if(p==="LT"){l=m._5;continue}if(p==="GT"){l=m._6;continue}if(p==="EQ"){d=!1,h=T("Just",m._4);continue}}c()}return h})(r.layer),_=(()=>{if(s.tag==="Nothing"){if(g.tag==="Nothing")return-i.delta;if(g.tag==="Just")return-g._1-i.delta|0;c()}if(s.tag==="Just"){if(g.tag==="Nothing")return(s._1-0|0)-i.delta|0;if(g.tag==="Just")return(s._1-g._1|0)-i.delta|0}c()})();if(_<o.slack)return{edge:T("Just",i),slack:_}}return o})({edge:y,slack:1e9})(e).edge,qb=t=>{const e=t.Eq0();return n=>r=>o=>i=>{const a=i.tgt,s=i.src;return b(u=>g=>{if((()=>{const _=y_(g.eid)(r.cutvalue);if(_.tag==="Just")return!0;if(_.tag==="Nothing")return!1;c()})()){const _=y_(g.eid)(r.cutvalue),f=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;c()})();return e.eq(s)(g.src)||e.eq(a)(g.tgt)?u-(f-g.weight):u+(f-g.weight)}return e.eq(o)(s)?e.eq(g.src)(o)?u+g.weight:u-g.weight:e.eq(g.src)(o)?u-g.weight:u+g.weight})(i.weight)(_t(u=>u.eid!==i.eid&&(e.eq(u.src)(o)||e.eq(u.tgt)(o)),n))}},Vb=t=>{const e=qb(t);return n=>r=>o=>{const i=(a,s,u)=>{const g=(_=>{let f=_,l=!0,d;for(;l;){const h=f;if(h.tag==="Leaf"){l=!1,d=y;continue}if(h.tag==="Node"){const m=t.compare(a)(h._3);if(m==="LT"){f=h._5;continue}if(m==="GT"){f=h._6;continue}if(m==="EQ"){l=!1,d=T("Just",h._4);continue}}c()}return d})(u);if(g.tag==="Just")return it(t)(a)(_t(_=>_.eid!==s.eid,g._1))(u);if(g.tag==="Nothing")return u;c()};return(a=>s=>{let u=a,g=s,_=!0,f;for(;_;){const l=u,d=g,h=(p=>{let x=p,J=!0,w;for(;J;){const N=x;if(N.tag==="Leaf"){J=!1,w=y;continue}if(N.tag==="Node"){const L=t.compare(d)(N._3);if(L==="LT"){x=N._5;continue}if(L==="GT"){x=N._6;continue}if(L==="EQ"){J=!1,w=T("Just",N._4);continue}}c()}return w})(l.unknown),m=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;c()})();if(m.length===1){const p=t.Eq0().eq(m[0].src)(d)?m[0].tgt:m[0].src;u={unknown:i(d,m[0],i(p,m[0],l.unknown)),cutvalue:it(ut)(m[0].eid)(e(n)(l)(d)(m[0]))(l.cutvalue)},g=p;continue}_=!1,f=l}return f})(r)(o)}},Xd=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:g=>_=>g.delta===_.delta&&g.eid===_.eid&&n.eq(g.src)(_.src)&&e.eq(g.tgt)(_.tgt)&&g.weight===_.weight},o={compare:g=>_=>{const f=ut.compare(g.delta)(_.delta);if(f==="LT"||f==="GT"||f!=="EQ")return f;const l=ut.compare(g.eid)(_.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const d=t.compare(g.src)(_.src);if(d==="LT"||d==="GT"||d!=="EQ")return d;const h=t.compare(g.tgt)(_.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const m=at.compare(g.weight)(_.weight);return m==="LT"||m==="GT"||m!=="EQ"?m:un},Eq0:()=>r},i=b(g=>_=>it(o)(_)()(g))(W),a=Ob(t),s=fe(t)(Qt),u=Vb(t);return g=>_=>f=>{const l={unknown:s(K(d=>E(d,Mt(Jn.foldr,i(a(_)(f)(d)))))(g)),cutvalue:W};return{...f,cutvalue:b(u(_))(l)(_t(d=>{const h=(m=>{let p=m,x=!0,J;for(;x;){const w=p;if(w.tag==="Leaf"){x=!1,J=y;continue}if(w.tag==="Node"){const N=t.compare(d)(w._3);if(N==="LT"){p=w._5;continue}if(N==="GT"){p=w._6;continue}if(N==="EQ"){x=!1,J=T("Just",w._4);continue}}c()}return J})(l.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;c()},g)).cutvalue}}},Ub=t=>{const e=Vd(t),n=Xd(t);return r=>o=>i=>a=>s=>{const u={...s,treeEdge:it(ut)(a.eid)()(Mi(ut)(i.eid)(s.treeEdge))},g=a.tgt,_=(m=>{let p=m,x=!0,J;for(;x;){const w=p;if(w.tag==="Leaf"){x=!1,J=y;continue}if(w.tag==="Node"){const N=t.compare(g)(w._3);if(N==="LT"){p=w._5;continue}if(N==="GT"){p=w._6;continue}if(N==="EQ"){x=!1,J=T("Just",w._4);continue}}c()}return J})(u.layer),f=a.src,l=(m=>{let p=m,x=!0,J;for(;x;){const w=p;if(w.tag==="Leaf"){x=!1,J=y;continue}if(w.tag==="Node"){const N=t.compare(f)(w._3);if(N==="LT"){p=w._5;continue}if(N==="GT"){p=w._6;continue}if(N==="EQ"){x=!1,J=T("Just",w._4);continue}}c()}return J})(u.layer),d=(()=>{if(_.tag==="Nothing"){if(l.tag==="Nothing")return-a.delta;if(l.tag==="Just")return-l._1-a.delta|0;c()}if(_.tag==="Just"){if(l.tag==="Nothing")return(_._1-0|0)-a.delta|0;if(l.tag==="Just")return(_._1-l._1|0)-a.delta|0}c()})(),h=Su(t)(u)(a.tgt)(i)?d:-d;return n(r)(o)(e(r)(o)({...u,layer:b(m=>p=>Su(t)(u)(p)(i)?m:it(t)(p)((()=>{const x=(J=>{let w=J,N=!0,L;for(;N;){const C=w;if(C.tag==="Leaf"){N=!1,L=y;continue}if(C.tag==="Node"){const R=t.compare(p)(C._3);if(R==="LT"){w=C._5;continue}if(R==="GT"){w=C._6;continue}if(R==="EQ"){N=!1,L=T("Just",C._4);continue}}c()}return L})(u.layer);if(x.tag==="Nothing")return 0+h|0;if(x.tag==="Just")return x._1+h|0;c()})())(m))(u.layer)(r)}))}},Xb=t=>{const e=Ub(t);return n=>r=>o=>i=>(a=>s=>{let u=a,g=s,_=!0,f;for(;_;){const l=u,d=g;if(l===0){_=!1,f=d;continue}const h=Hb(o)(d);if(h.tag==="Nothing"){_=!1,f=d;continue}if(h.tag==="Just"){const m=$b(t)(o)(h._1)(d);if(m.tag==="Nothing"){_=!1,f=d;continue}if(m.tag==="Just"){u=l-1|0,g=e(r)(o)(h._1)(m._1)(d);continue}}c()}return f})(n)(i)},Kb=t=>{const e=Xd(t),n=Vd(t),r=Ud(t);return o=>i=>a=>e(o)(i)(n(o)(i)(r(o)(i)(a)))},Kd=t=>e=>b(n=>r=>Wt(t)(Je)(e(r))([r])(n))(W),Yb=t=>{const e=fe(t)(Qt);return n=>r=>o=>{const i=u=>g=>_=>f=>{let l=u,d=g,h=_,m=f,p=!0,x;for(;p;){const J=l,w=d,N=h,L=m,C=Bt(R=>y,R=>P=>T("Just",{head:R,tail:P}),N);if(C.tag==="Nothing"){p=!1,x=L;continue}if(C.tag==="Just"){const R=C._1.head,P=(S=>{let v=S,F=!0,H;for(;F;){const M=v;if(M.tag==="Leaf"){F=!1,H=y;continue}if(M.tag==="Node"){const q=t.compare(R)(M._3);if(q==="LT"){v=M._5;continue}if(q==="GT"){v=M._6;continue}if(q==="EQ"){F=!1,H=T("Just",M._4);continue}}c()}return H})(L.layer),I=(()=>{if(P.tag==="Nothing")return 0;if(P.tag==="Just")return P._1;c()})(),U=b(S=>v=>{const F=v.tgt,H=(q=>{let $=q,B=!0,D;for(;B;){const Q=$;if(Q.tag==="Leaf"){B=!1,D=y;continue}if(Q.tag==="Node"){const O=t.compare(F)(Q._3);if(O==="LT"){$=Q._5;continue}if(O==="GT"){$=Q._6;continue}if(O==="EQ"){B=!1,D=T("Just",Q._4);continue}}c()}return D})(S.incident),M=(()=>{if(H.tag==="Nothing")return-1;if(H.tag==="Just")return H._1-1|0;c()})();return{st:{...S.st,layer:it(t)(v.tgt)(zb((()=>{const q=v.tgt,$=(B=>{let D=B,Q=!0,O;for(;Q;){const z=D;if(z.tag==="Leaf"){Q=!1,O=y;continue}if(z.tag==="Node"){const Y=t.compare(q)(z._3);if(Y==="LT"){D=z._5;continue}if(Y==="GT"){D=z._6;continue}if(Y==="EQ"){Q=!1,O=T("Just",z._4);continue}}c()}return O})(S.st.layer);if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;c()})())(I+v.delta|0))(S.st.layer)},incident:it(t)(v.tgt)(M)(S.incident),queue:M===0?[...S.queue,v.tgt]:S.queue}})({st:L,incident:w,queue:C._1.tail})((()=>{const S=(v=>{let F=v,H=!0,M;for(;H;){const q=F;if(q.tag==="Leaf"){H=!1,M=y;continue}if(q.tag==="Node"){const $=t.compare(R)(q._3);if($==="LT"){F=q._5;continue}if($==="GT"){F=q._6;continue}if($==="EQ"){H=!1,M=T("Just",q._4);continue}}c()}return M})(J);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;c()})());l=J,d=U.incident,h=U.queue,m=U.st;continue}c()}return x},a=Kd(t)(u=>u.tgt)(r),s=e(K(u=>E(u,(()=>{const g=(_=>{let f=_,l=!0,d;for(;l;){const h=f;if(h.tag==="Leaf"){l=!1,d=y;continue}if(h.tag==="Node"){const m=t.compare(u)(h._3);if(m==="LT"){f=h._5;continue}if(m==="GT"){f=h._6;continue}if(m==="EQ"){l=!1,d=T("Just",h._4);continue}}c()}return d})(a);if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1.length;c()})()))(n));return i(Kd(t)(u=>u.src)(r))(s)(_t(u=>{const g=(_=>{let f=_,l=!0,d;for(;l;){const h=f;if(h.tag==="Leaf"){l=!1,d=y;continue}if(h.tag==="Node"){const m=t.compare(u)(h._3);if(m==="LT"){f=h._5;continue}if(m==="GT"){f=h._6;continue}if(m==="EQ"){l=!1,d=T("Just",h._4);continue}}c()}return d})(s);if(g.tag==="Nothing")return!0;if(g.tag==="Just")return g._1===0;c()},n))(o)}},Zb=t=>{const e=Mb(t),n=Yb(t),r=Kb(t),o=Xb(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}},Yd=t=>{const e=Wb(t),n=Zb(t),r=Db(t);return o=>i=>{if(o.length===0)return W;if(o.length<40)return e(o)(n(o)(i));const a=r(o)(i);return e(o)(Fb(t)(a.removed)(n(a.coreNodes)(a.coreEdges)))}},Zd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},J_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},jb=Yd(ut),Ha=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}),tv=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=ot((()=>{const o=Zd(n.cGroup._1)(t);if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;c()})());return Wn(n.id)(o=>({...o,hitbox:{...o.hitbox,x:r+o.cGroupOffset.x}}))(e)}c()},ev=t=>e=>({...e,cGraph:b(tv(t))(e.cGraph)((()=>{const n=e.cGraph;return ht(r=>de(r)(n.cNodes))(n.cNodeOrder)})())}),nv=t=>e=>n=>r=>o=>{const i=he(Cs(e.cGroupOffset.x-t.cGroupOffset.x));return Ha({src:o.nextNodeId,tgt:r,delta:J_(0)(-i),weight:1})(Ha({src:o.nextNodeId,tgt:n,delta:J_(0)(i),weight:1})({...o,nodes:[...o.nodes,o.nextNodeId],nextNodeId:o.nextNodeId+1|0}))},rv=t=>e=>n=>r=>o=>i=>a=>{const s=J_(0)(he(Cs(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)?nv(n)(r)(o)(i)(a):Ha({src:o,tgt:i,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(a)},ov=t=>e=>n=>r=>o=>{const i=de(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"?rv(t)(e)(n)(i._1)(n.cGroup._1)(i._1.cGroup._1)(r):r;c()},iv=t=>e=>n=>r=>b(ov(t)(e)(r))(n)(r.constraints),av=t=>e=>Ha({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),sv=t=>{const e=b(o=>i=>Wt(ut)(ve)(i.tgt)(1)(o))(W)(t.edges),n=_t(o=>{const i=Zd(o)(e);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return i._1===0;c()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return b(o=>i=>Ha({src:r,tgt:i,delta:1,weight:0})(o))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},uv=t=>e=>{const n=sv(b(av)(b(iv(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return ht(o=>de(o)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},gv=t=>e=>{const n=uv(t)(e);return ev(jb(n.nodes)(n.edges))(e)},jd=t=>t,Te=jd("H"),Ne=jd("V"),cv=t=>E(t._2,t._1),th=t=>({...t,position:E(t.position._2,t.position._1),size:E(t.size._2,t.size._1)}),_v=t=>({start:E(t.start._2,t.start._1),end:E(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return Ne;if(t.direction==="V")return Te;c()})()}),eh=t=>({...t,segments:K(_v)(t.segments),bends:K(cv)(t.bends)}),fv=t=>({nodes:K(th)(t.nodes),edges:t.edges,paths:K(eh)(t.paths),ports:t.ports}),lv={nodeNode:8,edgeNode:4,edgeEdge:10},dv=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}}),hv=t=>e=>gv(e),pv=t=>e=>n=>{const r=fv(n),o=Ib(r),i=Rb(o)(Hd(r)),a=Pb(Pd(g_)(eb({...rb(o.cGraph),compactionAlgorithm:T("Just",hv()(i)),constraintAlgorithm:T("Just",hb(e.edgeEdge)),spacingsHandler:dv(e)(i)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:K(th)(a.nodes),edges:K(eh)(a.edges)}},nh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},rh=t=>Ve(3)(t)==="$d:",mv=t=>e=>n=>b(r=>o=>{const i=nh(o.from.node)(t),a=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;c()})(),s=nh(o.to.node)(t),u=(()=>{if(s.tag==="Nothing")return-a;if(s.tag==="Just")return s._1-a|0;c()})();if(u<=1)return{...r,edges:[...r.edges,o],chains:[...r.chains,{edgeId:o.id,nodes:[o.from.node,o.to.node]}]};const g=o.id,_=K(l=>"$d:"+g+":"+ue(l))(Ut(1,u-1|0)),f=[o.from.node,..._,o.to.node];return{...r,layers:b(l=>d=>{const h=d._2,m=cy(a+d._1|0)(p=>[...p,h])(l);if(m.tag==="Nothing")return l;if(m.tag==="Just")return m._1;c()})(r.layers)(We(mn,Ut(1,u-1|0),_)),edges:[...r.edges,...We(l=>d=>({id:g+":"+l+"->"+d,from:{node:l,port:o.from.port},to:{node:d,port:o.to.port},label:y}),f,At(1,f.length,f))],chains:[...r.chains,{edgeId:o.id,nodes:f}]}})({layers:n,edges:[],chains:[]})(e),oh=t=>t,aa=fe(ut)(Qt),Zt=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},ih=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Lt=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},kt=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},sa=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},yv=t=>e=>{const n=ut.compare(t._1)(e._1);return n==="LT"?Me:n==="GT"?Qe:ut.compare(t._2)(e._2)},ua=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},xv=(()=>{const t=gn.unfoldr(jn);return e=>t(cn("IterNode",e,Yn))})(),Jv=t=>t,ah=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},wv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Eu=oh("Regular"),Ru=oh("Critical"),sh=t=>e=>{const n=b(a=>s=>it(G)(s.node)(s)(a))(W)(e),r=1.25*ot(4),o=(a,s,u)=>(g=>_=>f=>{let l=g,d=_,h=f,m=!0,p;for(;m;){const x=l,J=d,w=h;if(w.critical){m=!1,p=w;continue}const N=Bt(C=>y,C=>R=>T("Just",{head:C,tail:R}),x),L=Bt(C=>y,C=>R=>T("Just",{head:C,tail:R}),J);if(N.tag==="Just"&&L.tag==="Just"){const C=N._1.head>L._1.head-a&&N._1.head<L._1.head+a?{...w,critical:!0}:N._1.head>L._1.head-r&&N._1.head<L._1.head+r?{...w,conflicts:w.conflicts+1|0}:w;if(C.critical){m=!1,p=C;continue}if(N._1.head<=L._1.head){l=N._1.tail,d=J,h=C;continue}l=x,d=L._1.tail,h=C;continue}m=!1,p=w}return p})(s)(u)({conflicts:0,critical:!1}),i=(a,s,u)=>{if(kt(b(kt)(-1e18)(s.incoming))(b(kt)(-1e18)(s.outgoing))-Lt(b(Lt)(1e18)(s.incoming))(b(Lt)(1e18)(s.outgoing))<.001||kt(b(kt)(-1e18)(u.incoming))(b(kt)(-1e18)(u.outgoing))-Lt(b(Lt)(1e18)(u.incoming))(b(Lt)(1e18)(u.outgoing))<.001)return[];const g=o(a,s.outgoing,u.incoming),_=o(a,u.outgoing,s.incoming);if(g.critical||_.critical)return[...g.critical?[{src:u.id,tgt:s.id,weight:1,kind:Ru}]:[],..._.critical?[{src:s.id,tgt:u.id,weight:1,kind:Ru}]:[]];const f=Lt(b(Lt)(1e18)(s.incoming))(b(Lt)(1e18)(s.outgoing)),l=kt(b(kt)(-1e18)(s.incoming))(b(kt)(-1e18)(s.outgoing)),d=Lt(b(Lt)(1e18)(u.incoming))(b(Lt)(1e18)(u.outgoing)),h=kt(b(kt)(-1e18)(u.incoming))(b(kt)(-1e18)(u.outgoing)),m=(1*g.conflicts|0)+(16*(b(x=>J=>J>h?x:J>=d?x+1|0:x)(0)(s.outgoing)+b(x=>J=>J>l?x:J>=f?x+1|0:x)(0)(u.incoming)|0)|0)|0,p=(1*_.conflicts|0)+(16*(b(x=>J=>J>l?x:J>=f?x+1|0:x)(0)(u.outgoing)+b(x=>J=>J>h?x:J>=d?x+1|0:x)(0)(s.incoming)|0)|0)|0;return m<p?[{src:s.id,tgt:u.id,weight:p-m|0,kind:Eu}]:m>p?[{src:u.id,tgt:s.id,weight:m-p|0,kind:Eu}]:m>0?[{src:s.id,tgt:u.id,weight:0,kind:Eu},{src:u.id,tgt:s.id,weight:0,kind:Eu}]:[]};return b(a=>s=>b(u=>g=>it(G)(g._1)(g._2)(u))(a)((()=>{const u=b(S=>v=>{const F=v.edge.from.node+"|"+(()=>{if(v.edge.from.port.tag==="Just")return v.edge.from.port._1;if(v.edge.from.port.tag==="Nothing")return"_auto_"+v.edge.id;c()})(),H=ah(F)(S.entries);if(H.tag==="Nothing")return{...S,entries:it(G)(F)({id:0,members:[v.edge.id],incoming:[v.fromPos._1],outgoing:[v.toPos._1],slot:0,mark:0,splitBy:y,splitPartner:y})(S.entries),order:[...S.order,F]};if(H.tag==="Just")return{...S,entries:it(G)(F)({...H._1,members:[...H._1.members,v.edge.id],incoming:[...Pr(M=>M<v.fromPos._1)(H._1.incoming).init,v.fromPos._1,...Pr(M=>M<=v.fromPos._1)(H._1.incoming).rest],outgoing:[...Pr(M=>M<v.toPos._1)(H._1.outgoing).init,v.toPos._1,...Pr(M=>M<=v.toPos._1)(H._1.outgoing).rest]})(S.entries)};c()})({entries:W,order:[]})(s._2),g=Ft(S=>v=>({...v,id:S}))(ht(S=>ah(S)(u.entries))(u.order));if(g.length===0)return[];const _=b(S=>v=>S.prev.tag==="Just"&&v-S.prev._1<1e-9?S:{prev:T("Just",v),out:[...S.out,v]})({prev:y,out:[]})(Rt(at.compare)([...St(g)(S=>S.incoming),...St(g)(S=>S.outgoing)])).out,f=_.length<2?.2*r:.2*b(S=>v=>{if(S.prev.tag==="Nothing")return{prev:T("Just",v),mn:S.mn};if(S.prev.tag==="Just")return{prev:T("Just",v),mn:Lt(S.mn)(v-S.prev._1)};c()})({prev:y,mn:1e18})(_).mn,l={segments:g,deps:(()=>{const S=g.length;return St(St(Ut(0,S-2|0))(v=>St(Ut(v+1|0,S-1|0))(F=>[E(v,F)])))(v=>v._1>=0&&v._1<g.length?v._2>=0&&v._2<g.length?i(f,g[v._1],g[v._2]):[]:[])})()},d=_t(S=>{if(S.kind==="Critical")return!0;if(S.kind==="Regular")return!1;c()},l.deps),h=(()=>{if(d.length<2)return l;const S=aa((()=>{const q=l.segments;return K($=>E($.id,$.mark))((()=>{const $=q.length,B=Q=>{let O=Q,z=!0,Y;for(;z;){const V=O,X=te(Z=>{const nt=Zt(Z)(V.inWeight);if(nt.tag==="Nothing")return!0;if(nt.tag==="Just")return nt._1===0;c()})(V.remaining);if(X.tag==="Nothing"){z=!1,Y=V;continue}if(X.tag==="Just"){const Z=X._1;O={...V,inWeight:b(nt=>rt=>Wt(ut)(ve)(rt.tgt)(-rt.weight)(nt))(V.inWeight)((()=>{const nt=Zt(Z)(V.depsBySrc);if(nt.tag==="Nothing")return[];if(nt.tag==="Just")return nt._1;c()})()),marks:it(ut)(Z)(V.nextSource)(V.marks),nextSource:V.nextSource+1|0,outWeight:b(nt=>rt=>Wt(ut)(ve)(rt.src)(-rt.weight)(nt))(V.outWeight)((()=>{const nt=Zt(Z)(V.depsByTgt);if(nt.tag==="Nothing")return[];if(nt.tag==="Just")return nt._1;c()})()),remaining:_t(nt=>nt!==Z,V.remaining)};continue}c()}return Y},D=Q=>{let O=Q,z=!0,Y;for(;z;){const V=O,X=te(Z=>{const nt=Zt(Z)(V.outWeight);if(nt.tag==="Nothing")return!0;if(nt.tag==="Just")return nt._1===0;c()})(V.remaining);if(X.tag==="Nothing"){z=!1,Y=V;continue}if(X.tag==="Just"){const Z=X._1;O={...V,inWeight:b(nt=>rt=>Wt(ut)(ve)(rt.tgt)(-rt.weight)(nt))(V.inWeight)((()=>{const nt=Zt(Z)(V.depsBySrc);if(nt.tag==="Nothing")return[];if(nt.tag==="Just")return nt._1;c()})()),marks:it(ut)(Z)(V.nextSink)(V.marks),nextSink:V.nextSink-1|0,outWeight:b(nt=>rt=>Wt(ut)(ve)(rt.src)(-rt.weight)(nt))(V.outWeight)((()=>{const nt=Zt(Z)(V.depsByTgt);if(nt.tag==="Nothing")return[];if(nt.tag==="Just")return nt._1;c()})()),remaining:_t(nt=>nt!==Z,V.remaining)};continue}c()}return Y};return(Q=>{let O=Q,z=!0,Y;for(;z;){const V=B(D(O));if(V.remaining.length===0){z=!1,Y=K(X=>{const Z=Zt(X.id)(V.marks),nt=(()=>{if(Z.tag==="Nothing")return X.id;if(Z.tag==="Just")return Z._1;c()})();return{...X,mark:nt<$?(nt+$|0)+1|0:nt}})(q);continue}O=(()=>{const X=nt=>{const rt=Zt(nt)(V.outWeight),ft=Zt(nt)(V.inWeight);return(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()-(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;c()})()|0},Z=Rt(nt=>rt=>ut.compare(X(rt))(X(nt)))(V.remaining);if(0<Z.length){const nt=Z[0];return{...V,inWeight:b(rt=>ft=>Wt(ut)(ve)(ft.tgt)(-ft.weight)(rt))(V.inWeight)((()=>{const rt=Zt(nt)(V.depsBySrc);if(rt.tag==="Nothing")return[];if(rt.tag==="Just")return rt._1;c()})()),marks:it(ut)(nt)(V.nextSource)(V.marks),nextSource:V.nextSource+1|0,outWeight:b(rt=>ft=>Wt(ut)(ve)(ft.src)(-ft.weight)(rt))(V.outWeight)((()=>{const rt=Zt(nt)(V.depsByTgt);if(rt.tag==="Nothing")return[];if(rt.tag==="Just")return rt._1;c()})()),remaining:_t(rt=>rt!==nt,V.remaining)}}return V})()}return Y})({remaining:K(Q=>Q.id)(q),marks:W,inWeight:b(Q=>O=>Wt(ut)(ve)(O.tgt)(O.weight)(Q))(W)(d),outWeight:b(Q=>O=>Wt(ut)(ve)(O.src)(O.weight)(Q))(W)(d),depsBySrc:b(Q=>O=>Wt(ut)(Je)(O.src)([O])(Q))(W)(d),depsByTgt:b(Q=>O=>Wt(ut)(Je)(O.tgt)([O])(Q))(W)(d),nextSink:$-1|0,nextSource:$+1|0})})())})()),v=_t(q=>{const $=Zt(q.src)(S),B=Zt(q.tgt)(S);return(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;c()})()>(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;c()})()},d);if(v.length===0)return l;const F=b(q=>$=>{if(yn(go)($.src)(q.decisions)||yn(go)($.tgt)(q.decisions))return q;const B=Zt($.src)(q.segMap),D=Zt($.tgt)(q.segMap);if(B.tag==="Just"&&D.tag==="Just"){const Q=(B._1.incoming.length+B._1.outgoing.length|0)>2&&(D._1.incoming.length+D._1.outgoing.length|0)<=2,O=Q?D._1:B._1;return{decisions:[...q.decisions,O.id],segMap:it(ut)(O.id)({...O,splitBy:T("Just",Q?B._1.id:D._1.id)})(q.segMap)}}return q})({decisions:[],segMap:aa(K(q=>E(q.id,q))(l.segments))})(v),H=F.segMap,M=b(q=>$=>{const B=Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)($.outgoing)),D=kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)($.outgoing)),Q=_t(X=>X.a.startPosition<=D&&X.a.endPosition>=B,Ft(X=>Z=>({i:X,a:Z}))(q.freeAreas));if(Q.length===0){const X={...$,incoming:Rt(at.compare)($.incoming),outgoing:Rt(at.compare)([(B+D)/2]),splitPartner:T("Just",q.nextId)},Z={id:q.nextId,incoming:Rt(at.compare)([(B+D)/2]),mark:0,members:$.members,outgoing:Rt(at.compare)($.outgoing),slot:0,splitBy:y,splitPartner:T("Just",$.id)};return{segMap:it(ut)(Z.id)(Z)(it(ut)(X.id)(X)(q.segMap)),freeAreas:q.freeAreas,nextId:q.nextId+1|0}}const O=0<Q.length?T("Just",Q[0]):y,z=(()=>{if(O.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(O.tag==="Just"){if(Q.length===1)return O._1;const X=K(Z=>({c:Z,rating:(()=>{const nt=(Z.a.startPosition+Z.a.endPosition)/2,rt=[nt],ft=[nt],Nt=b((()=>{const mt=q.segMap;return vt=>Ht=>{const Tt=Zt(Ht.tgt)(mt);if(Tt.tag==="Nothing")return vt;if(Tt.tag==="Just"){const Vt=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),Gt=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),bt=Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)(rt)),pt=(()=>{const qt=kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)(rt)),jt=b(ge=>be=>be>Gt?ge:be>=Vt?ge+1|0:ge)(0)(rt)+b(ge=>be=>be>qt?ge:be>=bt?ge+1|0:ge)(0)(Tt._1.incoming)|0,sn=Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)(rt)),$e=kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)(rt)),Vn=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),Un=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),je=b(ge=>be=>be>$e?ge:be>=sn?ge+1|0:ge)(0)(Tt._1.outgoing)+b(ge=>be=>be>Un?ge:be>=Vn?ge+1|0:ge)(0)($.incoming)|0;return jt===je?jt>0?{...vt,deps:vt.deps+2|0,crossings:vt.crossings+jt|0}:vt:{...vt,deps:vt.deps+1|0,crossings:vt.crossings+ua(jt)(je)|0}})(),ct=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),wt=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),It=Lt(b(Lt)(1e18)(ft))(b(Lt)(1e18)($.outgoing)),yt=kt(b(kt)(-1e18)(ft))(b(kt)(-1e18)($.outgoing)),Ct=b(qt=>jt=>jt>wt?qt:jt>=ct?qt+1|0:qt)(0)($.outgoing)+b(qt=>jt=>jt>yt?qt:jt>=It?qt+1|0:qt)(0)(Tt._1.incoming)|0,Ot=Lt(b(Lt)(1e18)(ft))(b(Lt)(1e18)($.outgoing)),Dt=kt(b(kt)(-1e18)(ft))(b(kt)(-1e18)($.outgoing)),se=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),_e=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),pn=b(qt=>jt=>jt>Dt?qt:jt>=Ot?qt+1|0:qt)(0)(Tt._1.outgoing)+b(qt=>jt=>jt>_e?qt:jt>=se?qt+1|0:qt)(0)(ft)|0;return Ct===pn?Ct>0?{...pt,deps:pt.deps+2|0,crossings:pt.crossings+Ct|0}:pt:{...pt,deps:pt.deps+1|0,crossings:pt.crossings+ua(Ct)(pn)|0}}c()}})())(b((()=>{const mt=q.segMap;return vt=>Ht=>{const Tt=Zt(Ht.src)(mt);if(Tt.tag==="Nothing")return vt;if(Tt.tag==="Just"){const Vt=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),Gt=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),bt=Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)(rt)),pt=(()=>{const qt=kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)(rt)),jt=b(ge=>be=>be>Gt?ge:be>=Vt?ge+1|0:ge)(0)(rt)+b(ge=>be=>be>qt?ge:be>=bt?ge+1|0:ge)(0)(Tt._1.incoming)|0,sn=Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)(rt)),$e=kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)(rt)),Vn=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),Un=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),je=b(ge=>be=>be>$e?ge:be>=sn?ge+1|0:ge)(0)(Tt._1.outgoing)+b(ge=>be=>be>Un?ge:be>=Vn?ge+1|0:ge)(0)($.incoming)|0;return jt===je?jt>0?{...vt,deps:vt.deps+2|0,crossings:vt.crossings+jt|0}:vt:{...vt,deps:vt.deps+1|0,crossings:vt.crossings+ua(jt)(je)|0}})(),ct=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),wt=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),It=Lt(b(Lt)(1e18)(ft))(b(Lt)(1e18)($.outgoing)),yt=kt(b(kt)(-1e18)(ft))(b(kt)(-1e18)($.outgoing)),Ct=b(qt=>jt=>jt>wt?qt:jt>=ct?qt+1|0:qt)(0)($.outgoing)+b(qt=>jt=>jt>yt?qt:jt>=It?qt+1|0:qt)(0)(Tt._1.incoming)|0,Ot=Lt(b(Lt)(1e18)(ft))(b(Lt)(1e18)($.outgoing)),Dt=kt(b(kt)(-1e18)(ft))(b(kt)(-1e18)($.outgoing)),se=Lt(b(Lt)(1e18)(Tt._1.incoming))(b(Lt)(1e18)(Tt._1.outgoing)),_e=kt(b(kt)(-1e18)(Tt._1.incoming))(b(kt)(-1e18)(Tt._1.outgoing)),pn=b(qt=>jt=>jt>Dt?qt:jt>=Ot?qt+1|0:qt)(0)(Tt._1.outgoing)+b(qt=>jt=>jt>_e?qt:jt>=se?qt+1|0:qt)(0)(ft)|0;return Ct===pn?Ct>0?{...pt,deps:pt.deps+2|0,crossings:pt.crossings+Ct|0}:pt:{...pt,deps:pt.deps+1|0,crossings:pt.crossings+ua(Ct)(pn)|0}}c()}})())({crossings:0,deps:0})(_t(mt=>mt.tgt===$.id,l.deps)))(_t(mt=>mt.src===$.id,l.deps)),lt=(()=>{if($.splitBy.tag==="Just")return Zt($.splitBy._1)(q.segMap);if($.splitBy.tag==="Nothing")return y;c()})();if(lt.tag==="Just")return{...Nt,deps:Nt.deps+2|0,crossings:(()=>{const mt=Lt(b(Lt)(1e18)(lt._1.incoming))(b(Lt)(1e18)(lt._1.outgoing)),vt=Lt(b(Lt)(1e18)(ft))(b(Lt)(1e18)($.outgoing)),Ht=kt(b(kt)(-1e18)(lt._1.incoming))(b(kt)(-1e18)(lt._1.outgoing)),Tt=kt(b(kt)(-1e18)(ft))(b(kt)(-1e18)($.outgoing)),Vt=Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)(rt));return Nt.crossings+(()=>{const Gt=Lt(b(Lt)(1e18)(lt._1.incoming))(b(Lt)(1e18)(lt._1.outgoing)),bt=kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)(rt)),pt=kt(b(kt)(-1e18)(lt._1.incoming))(b(kt)(-1e18)(lt._1.outgoing));return((b(ct=>wt=>wt>Ht?ct:wt>=mt?ct+1|0:ct)(0)(rt)+b(ct=>wt=>wt>bt?ct:wt>=Vt?ct+1|0:ct)(0)(lt._1.incoming)|0)+b(ct=>wt=>wt>Tt?ct:wt>=vt?ct+1|0:ct)(0)(lt._1.outgoing)|0)+b(ct=>wt=>wt>pt?ct:wt>=Gt?ct+1|0:ct)(0)(ft)|0})()|0})()};if(lt.tag==="Nothing")return Nt;c()})()}))(Q);return b(Z=>nt=>nt.rating.crossings<Z.rating.crossings||!(nt.rating.crossings>Z.rating.crossings)&&(nt.rating.deps<Z.rating.deps||!(nt.rating.deps>Z.rating.deps)&&nt.c.a.size>Z.c.a.size)?nt:Z)(0<X.length?X[0]:{c:O._1,rating:{crossings:1e6,deps:1e6}})(X).c}c()})(),Y={...$,incoming:Rt(at.compare)($.incoming),outgoing:Rt(at.compare)([(z.a.startPosition+z.a.endPosition)/2]),splitPartner:T("Just",q.nextId)},V={id:q.nextId,incoming:Rt(at.compare)([(z.a.startPosition+z.a.endPosition)/2]),mark:0,members:$.members,outgoing:Rt(at.compare)($.outgoing),slot:0,splitBy:y,splitPartner:T("Just",$.id)};return{segMap:it(ut)(V.id)(V)(it(ut)(Y.id)(Y)(q.segMap)),freeAreas:(()=>{if(z.i>=0&&z.i<q.freeAreas.length){const X=ef(Yt,y,z.i,q.freeAreas),Z=(()=>{if(X.tag==="Nothing")return q.freeAreas;if(X.tag==="Just")return X._1;c()})();if(q.freeAreas[z.i].size/2<f)return Z;const nt=(q.freeAreas[z.i].startPosition+q.freeAreas[z.i].endPosition)/2,rt=nt-f,ft=nt+f;return[...z.i<1?[]:At(0,z.i,Z),...q.freeAreas[z.i].startPosition<=rt?[{startPosition:q.freeAreas[z.i].startPosition,endPosition:rt,size:rt-q.freeAreas[z.i].startPosition}]:[],...ft<=q.freeAreas[z.i].endPosition?[{startPosition:ft,endPosition:q.freeAreas[z.i].endPosition,size:q.freeAreas[z.i].endPosition-ft}]:[],...z.i<1?Z:At(z.i,Z.length,Z)]}return q.freeAreas})(),nextId:q.nextId+1|0}})({segMap:H,freeAreas:(()=>{const q=Rt(at.compare)([...St(l.segments)($=>$.incoming),...St(l.segments)($=>$.outgoing)]);return ht(Jv)(We($=>B=>B-$>=2*f?T("Just",{startPosition:$+f,endPosition:B-f,size:B-$-2*f}):y,q,At(1,q.length,q)))})(),nextId:l.segments.length})(Rt(q=>$=>at.compare(kt(b(kt)(-1e18)(q.incoming))(b(kt)(-1e18)(q.outgoing))-Lt(b(Lt)(1e18)(q.incoming))(b(Lt)(1e18)(q.outgoing)))(kt(b(kt)(-1e18)($.incoming))(b(kt)(-1e18)($.outgoing))-Lt(b(Lt)(1e18)($.incoming))(b(Lt)(1e18)($.outgoing))))(ht(q=>Zt(q)(H))(F.decisions)));return{segments:(()=>{const q=($,B)=>{if($.tag==="Leaf")return B;if($.tag==="Node")return q($._5,Jt("Cons",$._4,q($._6,B)));c()};return Mt(ce.foldr,q(M.segMap,A))})(),deps:(()=>{const q=M.segMap,$=(Q,O)=>{if(Q.tag==="Leaf")return O;if(Q.tag==="Node")return $(Q._5,Jt("Cons",Q._4,$(Q._6,O)));c()},B=Mt(ce.foldr,$(q,A)),D=B.length;return[...St(St(Ut(0,D-2|0))(Q=>St(Ut(Q+1|0,D-1|0))(O=>[E(Q,O)])))(Q=>Q._1>=0&&Q._1<B.length?Q._2>=0&&Q._2<B.length?B[Q._1].splitPartner.tag!=="Nothing"&&B[Q._1].splitPartner.tag==="Just"&&B[Q._1].splitPartner._1===B[Q._2].id||B[Q._2].splitPartner.tag!=="Nothing"&&B[Q._2].splitPartner.tag==="Just"&&B[Q._2].splitPartner._1===B[Q._1].id?[]:i(f,B[Q._1],B[Q._2]):[]:[]),...St(B)(Q=>Q.splitBy.tag==="Just"&&Q.splitPartner.tag==="Just"&&(()=>{const O=Zt(Q.splitPartner._1)(q);if(O.tag==="Nothing")return!1;if(O.tag==="Just")return!0;c()})()&&(()=>{const O=Zt(Q.splitBy._1)(q);if(O.tag==="Nothing")return!1;if(O.tag==="Just")return!0;c()})()?[{src:Q.id,tgt:Q.splitBy._1,weight:1,kind:Ru},{src:Q.splitBy._1,tgt:Q.splitPartner._1,weight:1,kind:Ru}]:[])]})()}})(),m=h.segments,p=m.length,x=S=>{let v=S,F=!0,H;for(;F;){const M=v,q=te($=>{const B=Zt($)(M.inWeight);if(B.tag==="Nothing")return!0;if(B.tag==="Just")return B._1===0;c()})(M.remaining);if(q.tag==="Nothing"){F=!1,H=M;continue}if(q.tag==="Just"){const $=q._1;v={...M,inWeight:b(B=>D=>Wt(ut)(ve)(D.tgt)(-D.weight)(B))(M.inWeight)((()=>{const B=Zt($)(M.depsBySrc);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;c()})()),marks:it(ut)($)(M.nextSource)(M.marks),nextSource:M.nextSource+1|0,outWeight:b(B=>D=>Wt(ut)(ve)(D.src)(-D.weight)(B))(M.outWeight)((()=>{const B=Zt($)(M.depsByTgt);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;c()})()),remaining:_t(B=>B!==$,M.remaining)};continue}c()}return H},J=S=>{let v=S,F=!0,H;for(;F;){const M=v,q=te($=>{const B=Zt($)(M.outWeight);if(B.tag==="Nothing")return!0;if(B.tag==="Just")return B._1===0;c()})(M.remaining);if(q.tag==="Nothing"){F=!1,H=M;continue}if(q.tag==="Just"){const $=q._1;v={...M,inWeight:b(B=>D=>Wt(ut)(ve)(D.tgt)(-D.weight)(B))(M.inWeight)((()=>{const B=Zt($)(M.depsBySrc);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;c()})()),marks:it(ut)($)(M.nextSink)(M.marks),nextSink:M.nextSink-1|0,outWeight:b(B=>D=>Wt(ut)(ve)(D.src)(-D.weight)(B))(M.outWeight)((()=>{const B=Zt($)(M.depsByTgt);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;c()})()),remaining:_t(B=>B!==$,M.remaining)};continue}c()}return H},w=(S=>{let v=S,F=!0,H;for(;F;){const M=x(J(v));if(M.remaining.length===0){F=!1,H=K(q=>{const $=Zt(q.id)(M.marks),B=(()=>{if($.tag==="Nothing")return q.id;if($.tag==="Just")return $._1;c()})();return{...q,mark:B<p?(B+p|0)+1|0:B}})(m);continue}v=(()=>{const q=B=>{const D=Zt(B)(M.outWeight),Q=Zt(B)(M.inWeight);return(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;c()})()-(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;c()})()|0},$=Rt(B=>D=>ut.compare(q(D))(q(B)))(M.remaining);if(0<$.length){const B=$[0];return{...M,inWeight:b(D=>Q=>Wt(ut)(ve)(Q.tgt)(-Q.weight)(D))(M.inWeight)((()=>{const D=Zt(B)(M.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})()),marks:it(ut)(B)(M.nextSource)(M.marks),nextSource:M.nextSource+1|0,outWeight:b(D=>Q=>Wt(ut)(ve)(Q.src)(-Q.weight)(D))(M.outWeight)((()=>{const D=Zt(B)(M.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})()),remaining:_t(D=>D!==B,M.remaining)}}return M})()}return H})({remaining:K(S=>S.id)(m),marks:W,inWeight:b(S=>v=>Wt(ut)(ve)(v.tgt)(v.weight)(S))(W)(h.deps),outWeight:b(S=>v=>Wt(ut)(ve)(v.src)(v.weight)(S))(W)(h.deps),depsBySrc:b(S=>v=>Wt(ut)(Je)(v.src)([v])(S))(W)(h.deps),depsByTgt:b(S=>v=>Wt(ut)(Je)(v.tgt)([v])(S))(W)(h.deps),nextSink:p-1|0,nextSource:p+1|0}),N=(()=>{const S=(()=>{const H=aa(K(M=>E(M.id,M.mark))(w));return{segments:w,deps:ht(M=>(()=>{if(M.kind==="Critical")return!0;if(M.kind==="Regular")return!1;c()})()?T("Just",M):(()=>{const q=Zt(M.src)(H),$=Zt(M.tgt)(H);return(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;c()})()>(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;c()})()})()?M.weight===0?y:T("Just",{src:M.tgt,tgt:M.src,weight:M.weight,kind:M.kind}):T("Just",M))(h.deps)}})(),v=b(H=>M=>Wt(ut)(ve)(M.tgt)(1)(H))(W)(S.deps),F=(H=>{let M=H,q=!0,$;for(;q;){const B=M,D=Bt(Q=>y,Q=>O=>T("Just",{head:Q,tail:O}),B.queue);if(D.tag==="Nothing"){q=!1,$=B;continue}if(D.tag==="Just"){M=b((()=>{const Q=Zt(D._1.head)(B.slots),O=(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;c()})();return z=>Y=>{const V=Zt(Y)(z.inDegree),X=(()=>{if(V.tag==="Nothing")return-1;if(V.tag==="Just")return V._1-1|0;c()})();return{...z,slots:it(ut)(Y)(ih((()=>{const Z=Zt(Y)(z.slots);if(Z.tag==="Nothing")return 0;if(Z.tag==="Just")return Z._1;c()})())(O+1|0))(z.slots),inDegree:it(ut)(Y)(X)(z.inDegree),queue:X===0?[...z.queue,Y]:z.queue}}})())({...B,queue:D._1.tail})((()=>{const Q=Zt(D._1.head)(B.adj);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()})());continue}c()}return $})({slots:aa(K(H=>E(H.id,0))(S.segments)),inDegree:v,adj:b(H=>M=>Wt(ut)(Je)(M.src)([M.tgt])(H))(W)(S.deps),queue:K(H=>H.id)(_t(H=>{const M=Zt(H.id)(v);if(M.tag==="Nothing")return!0;if(M.tag==="Just")return M._1===0;c()},S.segments))});return Rt(H=>M=>ut.compare(H.slot)(M.slot))(K(H=>({...H,slot:(()=>{const M=Zt(H.id)(F.slots);if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;c()})()}))(S.segments))})(),L=1+b(S=>v=>ih(S)(v.slot))(0)(N)|0,C=St(N)(S=>S.members),R=_t(S=>yn(Er)(S.edge.id)(C),t),P=b(kt)(-1e18)(K(S=>S.fromPos._2)(R)),I=b(Lt)(1e18)(K(S=>S.toPos._2)(R));if(P>I){const S=aa(K(v=>E(v.id,v))(N));return kn(K(v=>K(F=>E(F,{slot:v.slot,slotCount:L,gapTop:I,gapBottom:P,partner:(()=>{if(v.splitPartner.tag==="Just"){const H=Zt(v.splitPartner._1)(S);if(H.tag==="Just")return T("Just",{slot:H._1.slot,splitX:0<H._1.incoming.length?H._1.incoming[0]:0});if(H.tag==="Nothing")return y;c()}if(v.splitPartner.tag==="Nothing")return y;c()})()}))(v.members))(_t(v=>{if(v.splitPartner.tag==="Just"){const F=Zt(v.splitPartner._1)(S);return!(F.tag==="Just"&&(()=>{if(F._1.splitBy.tag==="Nothing")return!1;if(F._1.splitBy.tag==="Just")return!0;c()})())}if(v.splitPartner.tag==="Nothing")return!0;c()},N)))}const U=aa(K(S=>E(S.id,S))(N));return kn(K(S=>K(v=>E(v,{slot:S.slot,slotCount:L,gapTop:P,gapBottom:I,partner:(()=>{if(S.splitPartner.tag==="Just"){const F=Zt(S.splitPartner._1)(U);if(F.tag==="Just")return T("Just",{slot:F._1.slot,splitX:0<F._1.incoming.length?F._1.incoming[0]:0});if(F.tag==="Nothing")return y;c()}if(S.splitPartner.tag==="Nothing")return y;c()})()}))(S.members))(_t(S=>{if(S.splitPartner.tag==="Just"){const v=Zt(S.splitPartner._1)(U);return!(v.tag==="Just"&&(()=>{if(v._1.splitBy.tag==="Nothing")return!1;if(v._1.splitBy.tag==="Just")return!0;c()})())}if(S.splitPartner.tag==="Nothing")return!0;c()},N)))})()))(W)(xv(b(a=>s=>{const u=sa(s.edge.from.node)(n);if(u.tag==="Just"){const g=sa(s.edge.to.node)(n);return g.tag==="Just"&&u._1.layer!==g._1.layer?Wt(ut)(Je)(ua(u._1.layer)(g._1.layer))([s])(a):a}return a})(W)((()=>{const a=s=>E((()=>{const u=sa(s.edge.from.node)(n);return u.tag==="Just"?u._1.layer:1e6})(),(()=>{const u=sa(s.edge.from.node)(n);return u.tag==="Just"?u._1.order:1e6})());return Rt(s=>u=>yv(a(s))(a(u)))(t)})())))},Tv=t=>e=>{const n=sh(t)(e),r=b(o=>i=>it(G)(i.node)(i)(o))(W)(e);return b(o=>i=>{const a=sa(i.edge.from.node)(r);if(a.tag==="Just"){const s=sa(i.edge.to.node)(r);if(s.tag==="Just"&&a._1.layer!==s._1.layer){const u=wv(i.edge.id)(n);if(u.tag==="Just")return it(ut)(ua(a._1.layer)(s._1.layer))(u._1.slotCount)(o)}return o}return o})(W)(t)},w_=fe(G)(Qt),ro=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},T_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Nv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t._1)(i._3._1);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(t._2==="North"){if(i._3._2==="North"){r=!1,o=T("Just",i._4);continue}n=i._5;continue}if(i._3._2==="North"){n=i._6;continue}if(t._2==="South"){if(i._3._2==="South"){r=!1,o=T("Just",i._4);continue}n=i._5;continue}if(i._3._2==="South"){n=i._6;continue}if(t._2==="East"){if(i._3._2==="East"){r=!1,o=T("Just",i._4);continue}n=i._5;continue}if(i._3._2==="East"){n=i._6;continue}if(t._2==="West"&&i._3._2==="West"){r=!1,o=T("Just",i._4);continue}}c()}return o},uh=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 E(o,i*2);if(t==="North")return E(o,e.position._2*2);if(t==="East")return E(n*2,r);if(t==="West")return E(e.position._1*2,r);c()},N_=t=>e=>{const n=ot(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};c()},gh=t=>e=>b(n=>r=>Wt(t)(Je)(e(r))([r])(n))(W),ch=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;c()})()&&(()=>{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;c()})(),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;c()})()&&(()=>{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;c()})();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},_h=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,o=e.length;return o===0?W:w_(o===1?K(i=>E(i,r))(e):Ft(i=>a=>E(a,t.lo+ot(i+1|0)*n/ot(o+1|0)))(e))},fh=t=>e=>n=>r=>o=>{const i=gh(G)(d=>d.to.node)(t),a=gh(G)(d=>d.from.node)(t),s=b(d=>h=>it(G)(h.node)(h)(d))(W)(e),u=(d,h,m)=>{const p=ro(d)(s);if(p.tag==="Nothing")return E(0,0);if(p.tag==="Just"){const x=ro(d)(n);if(x.tag==="Nothing"){const J=ot(4);if(m==="South")return E(p._1.position._1*J+p._1.size._1*J/2,(p._1.position._2+p._1.size._2)*J);if(m==="North")return E(p._1.position._1*J+p._1.size._1*J/2,p._1.position._2*J);if(m==="East")return E((p._1.position._1+p._1.size._1)*J,p._1.position._2*J+p._1.size._2*J/2);if(m==="West")return E(p._1.position._1*J,p._1.position._2*J+p._1.size._2*J/2);c()}if(x.tag==="Just"){const J=te(w=>w.id===h)(x._1);if(J.tag==="Nothing"){const w=ot(4);if(m==="South")return E(p._1.position._1*w+p._1.size._1*w/2,(p._1.position._2+p._1.size._2)*w);if(m==="North")return E(p._1.position._1*w+p._1.size._1*w/2,p._1.position._2*w);if(m==="East")return E((p._1.position._1+p._1.size._1)*w,p._1.position._2*w+p._1.size._2*w/2);if(m==="West")return E(p._1.position._1*w,p._1.position._2*w+p._1.size._2*w/2);c()}if(J.tag==="Just"){const w=ot(4);if(J._1.side==="North")return E(p._1.position._1*w+ot(J._1.offset)*w,p._1.position._2*w);if(J._1.side==="South")return E(p._1.position._1*w+ot(J._1.offset)*w,(p._1.position._2+p._1.size._2)*w);if(J._1.side==="East")return E((p._1.position._1+p._1.size._1)*w,p._1.position._2*w+ot(J._1.offset)*w);if(J._1.side==="West")return E(p._1.position._1*w,p._1.position._2*w+ot(J._1.offset)*w)}}}c()},g=w_(St(r)(d=>{if(d.nodes.length<=2)return[];const h=ot(4);if(1<d.nodes.length){const m=ro(d.nodes[1])(s);if(m.tag==="Nothing")return[];if(m.tag==="Just"){const p=m._1.position._1*h+m._1.size._1*h/2;return K(x=>E(x,p))(We(x=>J=>d.edgeId+":"+x+"->"+J,d.nodes,At(1,d.nodes.length,d.nodes)))}c()}return[]})),_=d=>{const h=ro(d.from.node)(s),m=ro(d.to.node)(s);if(h.tag==="Just"&&m.tag==="Just"){const p=h._1,x=m._1,J=Rt(w=>N=>ut.compare(w.score)(N.score))(K(w=>{const N=w._1,L=w._2;return{from:N,to:L,score:(()=>{const C=(U,S,v,F,H)=>{const M=N_(U)(S),q=N_(U)(v);return M.lo<q.hi&&q.lo<M.hi&&(N==="South"?L==="North"&&H._2>F._2:N==="North"?L==="South"&&H._2<F._2:N==="East"?L==="West"&&H._1>F._1:N==="West"&&L==="East"&&H._1<F._1)?0:ch(N)(L)(F)(H)},R=uh(N)(p),P=uh(L)(x),I=ch(N)(L)(R)(P);return(()=>{if(I>0){if(N==="South")return L==="North"?C(ze,p,x,R,P)*10|0:I*10|0;if(N==="North")return L==="South"?C(Ie,p,x,R,P)*10|0:I*10|0;if(N==="East")return L==="West"?C(Xr,p,x,R,P)*10|0:I*10|0;if(N==="West"&&L==="East")return C(Kr,p,x,R,P)*10|0}return I*10|0})()+(N==="South"?L==="North"?x.layer>=p.layer?0:20:15:N==="North"?L==="South"?x.layer<=p.layer?0:20:15:N==="East"?L==="West"?5:15:N==="West"&&L==="East"?5:15)|0})()}})([E(ze,Ie),E(Xr,Ie),E(Kr,Ie),E(ze,Xr),E(ze,Kr),E(Ie,ze),E(Ie,Xr),E(Ie,Kr),E(Xr,ze),E(Kr,ze),E(Xr,Kr),E(Kr,Xr)]));if(0<J.length)return{from:J[0].from,to:J[0].to}}return{from:ze,to:Ie}},f=w_(K(d=>E(d.id,_(d)))(t)),l=(d,h,m,p,x,J)=>{const w=ot(4),N=ro(h)(s);if(N.tag==="Nothing")return E(0,0);if(N.tag==="Just"){const L=Nv(E(m,d))(o);if(L.tag==="Just"){const C=N._1.position._1*w+L._1,R=ot(4);if(d==="South")return E(C,(N._1.position._2+N._1.size._2)*R);if(d==="North")return E(C,N._1.position._2*R);if(d==="East")return E((N._1.position._1+N._1.size._1)*R,C);if(d==="West")return E(N._1.position._1*R,C);c()}if(L.tag==="Nothing"){const C=N_(d)(N._1),R=(C.lo+C.hi)/2,P=T_(m)(_h(C)(K(S=>S.id)(Rt(S=>v=>at.compare(x(d)(S))(x(d)(v)))(_t(S=>{const v=T_(S.id)(f);if(v.tag==="Just"){const F=J(v._1);return F==="North"?d==="North":F==="South"?d==="South":F==="East"?d==="East":F==="West"&&d==="West"}if(v.tag==="Nothing")return!0;c()},(()=>{const S=ro(h)(p);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;c()})()))))),I=(()=>{if(P.tag==="Nothing")return R;if(P.tag==="Just")return P._1;c()})(),U=ot(4);if(d==="South")return E(I,(N._1.position._2+N._1.size._2)*U);if(d==="North")return E(I,N._1.position._2*U);if(d==="East")return E((N._1.position._1+N._1.size._1)*U,I);if(d==="West")return E(N._1.position._1*U,I)}}c()};return K(d=>{const h=T_(d.edge.id)(g);if(h.tag==="Nothing")return d;if(h.tag==="Just")return{...d,fromPos:Ve(3)(d.edge.from.node)==="$d:"?E(h._1,d.fromPos._2):d.fromPos,toPos:Ve(3)(d.edge.to.node)==="$d:"?E(h._1,d.toPos._2):d.toPos};c()})(K(d=>{if(d.from.port.tag==="Just"&&d.to.port.tag==="Just")return{edge:d,fromPos:u(d.from.node,d.from.port._1,ze),toPos:u(d.to.node,d.to.port._1,Ie),fromSide:ze,toSide:Ie};const h=_(d);return{edge:d,fromPos:l(h.from,d.from.node,d.id,a,m=>p=>{const x=ro(p.to.node)(s);if(x.tag==="Nothing")return 0;if(x.tag==="Just"){const J=ot(4);if(m==="South"||m==="North")return x._1.position._1*J+x._1.size._1*J/2;if(m==="East"||m==="West")return x._1.position._2*J+x._1.size._2*J/2}c()},m=>m.from),toPos:l(h.to,d.to.node,d.id,i,m=>p=>{const x=ro(p.from.node)(s);if(x.tag==="Nothing")return 0;if(x.tag==="Just"){const J=ot(4);if(m==="South"||m==="North")return x._1.position._1*J+x._1.size._1*J/2;if(m==="East"||m==="West")return x._1.position._2*J+x._1.size._2*J/2}c()},m=>m.to),fromSide:h.from,toSide:h.to}})(t))},Pu=(()=>{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=G.compare(e._1)(n._1);if(r==="LT")return Me;if(r==="GT")return Qe;if(e._2==="North")return n._2==="North"?un:Me;if(n._2==="North")return Qe;if(e._2==="South")return n._2==="South"?un:Me;if(n._2==="South")return Qe;if(e._2==="East")return n._2==="East"?un:Me;if(n._2==="East")return Qe;if(e._2==="West"&&n._2==="West")return un;c()},Eq0:()=>t}})(),bv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=Pu.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},vv=fe(G)(Qt),b_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Cv=fe(Pu)(Qt),lh=(()=>{const t=gn.unfoldr(jn);return e=>t(cn("IterNode",e,Yn))})(),ga=t=>e=>n=>r=>{const o=bv(E(e,n))(t);if(o.tag==="Nothing")return r;if(o.tag==="Just")return o._1;c()},dh=t=>e=>n=>{const r=vv(kn(K(a=>Ft(s=>u=>E(u,s))(a))(t))),o=(a,s)=>{if(a==="South"){const u=b_(s.to.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;c()}if(a==="North"){const u=b_(s.from.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;c()}return 0},i=a=>b(s=>u=>nn(Pu.compare,tn,Cv(K(g=>E(E(g._1,a),g._2))(lh(_h({lo:0,hi:(()=>{const g=b_(u._1)(n);if(g.tag==="Just")return g._1._1;if(g.tag==="Nothing")return Ve(3)(u._1)==="$d:"?0:1;c()})()})(K(g=>g.id)(Rt(g=>_=>ut.compare(o(a,g))(o(a,_)))(u._2)))))),s))(W)(lh(b(s=>u=>u.from.node===u.to.node?s:a==="South"?Wt(G)(Je)(u.from.node)([u])(s):a==="North"?Wt(G)(Je)(u.to.node)([u])(s):s)(W)(e)));return nn(Pu.compare,tn,i(Ie),i(ze))},hh=t=>t,ph=t=>t,mh=t=>t,Lv=b(t=>e=>it(G)(e)()(t))(W),kv=(()=>{const t=gn.unfoldr(e=>{if(e.tag==="Nil")return y;if(e.tag==="Cons")return T("Just",E(e._1,e._2));c()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Jt("Cons",r._3,n(r._6,o)));c()};return n(e,A)})())})(),dt=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},er=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Fr=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Mr=fe(G)(Qt),v_=sf(G),C_=(()=>{const t=gn.unfoldr(jn);return e=>t(cn("IterNode",e,Yn))})(),Sv=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ev=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},yh=mh("VDown"),xh=mh("VUp"),Rv=ph("ForwardPhase"),Pv=ph("StackPhase"),Jh=hh("HRight"),wh=hh("HLeft"),Th=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=G.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}}c()}return o},Bv=t=>e=>n=>{const r=b(a=>s=>Wt(G)(ve)(s.tgt)(1)(a))(W)(t),o=kv(Lv([...K(a=>a.src)(t),...K(a=>a.tgt)(t),...(()=>{const a=(s,u)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return a(s._5,Jt("Cons",s._4,a(s._6,u)));c()};return Mt(ce.foldr,a(e,A))})()])),i=b(a=>s=>Wt(G)(Je)(s.src)([{target:s.tgt,sep:s.sep}])(a))(W)(t);return(a=>s=>u=>{let g=a,_=s,f=u,l=!0,d;for(;l;){const h=g,m=_,p=f,x=Bt(J=>y,J=>w=>T("Just",{head:J,tail:w}),h);if(x.tag==="Nothing"){l=!1,d=p;continue}if(x.tag==="Just"){const J=dt(x._1.head)(p),w=(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;c()})(),N=b(L=>C=>{const R=dt(C.target)(L.result),P=w+C.sep,I=dt(C.target)(L.indeg),U=(()=>{if(I.tag==="Nothing")return-1;if(I.tag==="Just")return I._1-1|0;c()})();return{newQueue:U===0?[...L.newQueue,C.target]:L.newQueue,result:it(G)(C.target)((()=>{if(R.tag==="Nothing")return P;if(R.tag==="Just"){if(n==="VDown")return er(R._1)(P);if(n==="VUp")return Fr(R._1)(P)}c()})())(L.result),indeg:it(G)(C.target)(U)(L.indeg)}})({newQueue:[],result:p,indeg:m})((()=>{const L=dt(x._1.head)(i);if(L.tag==="Nothing")return[];if(L.tag==="Just")return L._1;c()})());g=[...x._1.tail,...N.newQueue],_=N.indeg,f=N.result;continue}c()}return d})(_t(a=>{const s=dt(a)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;c()},o))(r)(b(a=>s=>it(G)(s)(0)(a))(W)(o))},Gv=t=>{const e=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return e(i._5,Jt("Cons",i._4,e(i._6,a)));c()},n=Mt(ce.foldr,e(t,A)),r=b(er)(999999)(n);if(r===0||n.length===0)return t;const o=i=>{if(i.tag==="Leaf")return W;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,i._4-r,o(i._5),o(i._6));c()};return o(t)},Nh=t=>{const e=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return e(i._5,Jt("Cons",i._4,e(i._6,a)));c()},n=e(t,A),r=i=>a=>{let s=i,u=a,g=!0,_;for(;g;){const f=s,l=u;if(l.tag==="Nil"){g=!1,_=f;continue}if(l.tag==="Cons"){s=Fr(f)(l._1),u=l._2;continue}c()}return _},o=i=>a=>{let s=i,u=a,g=!0,_;for(;g;){const f=s,l=u;if(l.tag==="Nil"){g=!1,_=f;continue}if(l.tag==="Cons"){s=er(f)(l._1),u=l._2;continue}c()}return _};return r(-999999)(n)-o(999999)(n)},$a=t=>e=>(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,g=i;if(u===e){a=!1,s=g;continue}o=(()=>{const _=dt(u)(t.align);if(_.tag==="Nothing")return e;if(_.tag==="Just")return _._1;c()})(),i=[...g,u]}return s})((()=>{const n=dt(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;c()})())([e]),Av=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>_=>{const f=(B,D,Q)=>{const O=B.from.node===D?B.from.port:B.to.node===D?B.to.port:y;if(O.tag==="Just"){const z=dt(D)(o);if(z.tag==="Just"){const Y=te(V=>V.id===O._1)(z._1);if(Y.tag==="Just"){const V=ot(Y._1.offset)*ot(4);return Q==="North"||Q==="South"?V:0}if(Y.tag==="Nothing"){const V=dt(D)(r),X=ga(a)(B.id)(Q)((()=>{if(V.tag==="Nothing")return .5;if(V.tag==="Just")return V._1._1/2;c()})());return Q==="North"||Q==="South"?X:0}c()}if(z.tag==="Nothing"){const Y=dt(D)(r),V=ga(a)(B.id)(Q)((()=>{if(Y.tag==="Nothing")return .5;if(Y.tag==="Just")return Y._1._1/2;c()})());return Q==="North"||Q==="South"?V:0}c()}if(O.tag==="Nothing"){const z=dt(D)(r),Y=ga(a)(B.id)(Q)((()=>{if(z.tag==="Nothing")return .5;if(z.tag==="Just")return z._1._1/2;c()})());return Q==="North"||Q==="South"?Y:0}c()},l=(B,D)=>{if(B.from.node===D){if(_==="HRight")return ze;if(_==="HLeft")return Ie;c()}if(_==="HRight")return Ie;if(_==="HLeft")return ze;c()},d=(B,D,Q)=>b(O=>z=>it(G)(z)((()=>{const Y=dt(z)(O);if(Y.tag==="Nothing")return 0+D;if(Y.tag==="Just")return Y._1+D;c()})())(O))(Q)($a(u)(B)),h=(()=>{if(_==="HRight")return n;if(_==="HLeft")return re(n);c()})(),m=B=>{const D=dt(B)(r);if(D.tag==="Nothing")return 1;if(D.tag==="Just")return D._1._1;c()},p=Mr(kn(Ft(B=>D=>K(Q=>E(Q,B))(D))(n))),x=(B,D)=>Ve(3)(B)==="$d:"&&Ve(3)(D)==="$d:"||Ve(3)(B)==="$d:"||Ve(3)(D)==="$d:"?10:ot(t.nodeGap),J=b(B=>D=>v_(Q=>T("Just",[...(()=>{if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()})(),D]))(D.to.node)(B))(W)(i),w=b(B=>D=>v_(Q=>T("Just",[...(()=>{if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()})(),D]))(D.from.node)(B))(W)(i),N=kn(n),L=b(B=>D=>{const Q=dt(D)(u.root),O=(()=>{if(Q.tag==="Nothing")return D;if(Q.tag==="Just")return Q._1;c()})();return D===O?B:v_(z=>T("Just",(()=>{if(z.tag==="Nothing")return!0;if(z.tag==="Just")return z._1;c()})()&&Ve(3)(D)==="$d:"))(O)(B)})(Mr(K(B=>E(B,!0))(Ur(G.compare)((()=>{const B=(D,Q)=>{if(D.tag==="Leaf")return Q;if(D.tag==="Node")return B(D._5,Jt("Cons",D._4,B(D._6,Q)));c()};return Mt(ce.foldr,B(u.root,A))})()))))(N),C=(B,D)=>{const Q=B.free,O=dt(Q)(u.root),z=(()=>{if(O.tag==="Nothing")return Q;if(O.tag==="Just")return O._1;c()})(),Y=dt(z)(L),V=(()=>{if(Y.tag==="Nothing")return!0;if(Y.tag==="Just")return Y._1;c()})();return b(X=>Z=>{if(X.edge.tag==="Just")return X;if(X.edge.tag==="Nothing"){if((()=>{const lt=dt(z)(D.su);return!V&&(()=>{const mt=dt(Z.from.node)(p);return Z.from.node!==Z.to.node&&(()=>{const vt=dt(Z.to.node)(p);return(()=>{if(mt.tag==="Nothing")return-1;if(mt.tag==="Just")return mt._1;c()})()===(()=>{if(vt.tag==="Nothing")return-1;if(vt.tag==="Just")return vt._1;c()})()})()})()||(()=>{if(lt.tag==="Nothing")return!1;if(lt.tag==="Just")return lt._1;c()})()})())return X;const nt=Z.from.node===Q?Z.to.node:Z.from.node,rt=dt(nt)(u.root),ft=(()=>{if(rt.tag==="Nothing")return nt;if(rt.tag==="Just")return rt._1;c()})(),Nt=ft!==z;return Nt&&(()=>{const lt=dt(ft)(D.blockFinished);if(lt.tag==="Nothing")return!1;if(lt.tag==="Just")return lt._1;c()})()?{...X,edge:T("Just",Z),hasEdges:!0}:{...X,hasEdges:X.hasEdges||Nt}}c()})({edge:y,hasEdges:!1})((()=>{if(B.isRoot){if(_==="HRight"){const X=dt(Q)(J);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;c()}if(_==="HLeft"){const X=dt(Q)(w);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1}c()}if(_==="HRight"){const X=dt(Q)(w);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;c()}if(_==="HLeft"){const X=dt(Q)(J);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1}c()})())},R=(B,D,Q,O)=>{const z=(()=>{if(g==="VDown")return-1e18;if(g==="VUp")return 1e18;c()})(),Y={free:D,isRoot:Q},V=C(Y,O);if(V.edge.tag==="Nothing")return V.hasEdges?{thresh:z,state:{...O,queue:[...O.queue,Y]}}:{thresh:z,state:O};if(V.edge.tag==="Just"){const X=V.edge._1.from.node===D?V.edge._1.to.node:V.edge._1.from.node;return{thresh:(()=>{const Z=dt((()=>{const Nt=dt(X)(u.root);if(Nt.tag==="Nothing")return X;if(Nt.tag==="Just")return Nt._1;c()})())(O.x),nt=dt(X)(s),rt=dt(D)(s),ft=(()=>{if(Z.tag==="Just")return Z._1;if(Z.tag==="Nothing")return y;c()})();return(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;c()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+f(V.edge._1,X,(()=>{if(Q){if(_==="HRight")return ze;if(_==="HLeft")return Ie;c()}if(_==="HRight")return Ie;if(_==="HLeft")return ze;c()})())-(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()-f(V.edge._1,D,(()=>{if(Q){if(_==="HRight")return Ie;if(_==="HLeft")return ze;c()}if(_==="HRight")return ze;if(_==="HLeft")return Ie;c()})())})(),state:{...O,su:it(G)((()=>{const Z=dt(V.edge._1.from.node)(u.root);if(Z.tag==="Nothing")return V.edge._1.from.node;if(Z.tag==="Just")return Z._1;c()})())(!0)(it(G)((()=>{const Z=dt(V.edge._1.to.node)(u.root);if(Z.tag==="Nothing")return V.edge._1.to.node;if(Z.tag==="Just")return Z._1;c()})())(!0)(O.su))}}}c()},P=(B,D,Q,O)=>{const z=D===B,Y=dt(D)(u.align),V=(()=>{if(Y.tag==="Nothing")return D===B;if(Y.tag==="Just")return Y._1===B;c()})();if(!(z||V))return{thresh:Q,state:O};const X=(()=>{if(g==="VDown")return z&&Q<=-1e18;if(g==="VUp")return z&&Q>=1e18;c()})()?R(B,D,!0,O):{thresh:Q,state:O};return(()=>{if(g==="VDown")return X.thresh<=-1e18&&V;if(g==="VUp")return X.thresh>=1e18&&V;c()})()?R(B,D,!1,X.state):X},I=B=>D=>Q=>{const O=dt(Q)(e.nodeIndex),z=(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;c()})(),Y=te(rt=>yn(Er)(Q)(rt))(h),V=(()=>{if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1;c()})(),X=V.length;if((()=>{if(g==="VDown")return z<=0;if(g==="VUp")return z>=(X-1|0);c()})()){const rt=P(B,Q,D.thresh,D.st);return{...D,st:rt.state,thresh:rt.thresh}}const Z=(()=>{if(g==="VDown")return z-1|0;if(g==="VUp")return z+1|0;c()})(),nt=Z>=0&&Z<V.length?T("Just",V[Z]):y;if(nt.tag==="Nothing")return D;if(nt.tag==="Just"){const rt=dt(nt._1)(u.root),ft=(()=>{if(rt.tag==="Nothing")return nt._1;if(rt.tag==="Just")return rt._1;c()})(),Nt=P(B,Q,D.thresh,U(ft)(D.st)),lt=(()=>{const Dt=dt(B)(Nt.state.sink);if(Dt.tag==="Nothing")return B===B;if(Dt.tag==="Just")return Dt._1===B;c()})()?{...Nt.state,sink:it(G)(B)((()=>{const Dt=dt(ft)(Nt.state.sink);if(Dt.tag==="Nothing")return ft;if(Dt.tag==="Just")return Dt._1;c()})())(Nt.state.sink)}:Nt.state,mt=dt(ft)(lt.sink),vt=(()=>{if(mt.tag==="Nothing")return ft;if(mt.tag==="Just")return mt._1;c()})(),Ht=dt(B)(lt.sink),Tt=(()=>{if(Ht.tag==="Nothing")return B;if(Ht.tag==="Just")return Ht._1;c()})();if(Tt===vt){const Dt=dt(ft)(lt.x),se=(()=>{if(Dt.tag==="Just")return Dt._1;if(Dt.tag==="Nothing")return y;c()})(),_e=(()=>{if(se.tag==="Nothing")return 0;if(se.tag==="Just")return se._1;c()})(),pn=dt(B)(lt.x),qt=(()=>{if(pn.tag==="Just")return pn._1;if(pn.tag==="Nothing")return y;c()})(),jt=(()=>{if(qt.tag==="Nothing")return 0;if(qt.tag==="Just")return qt._1;c()})(),sn=x(Q,nt._1),$e=dt(nt._1)(s),Vn=dt(Q)(s),Un=(()=>{if($e.tag==="Nothing")return 0;if($e.tag==="Just")return $e._1;c()})()-(()=>{if(Vn.tag==="Nothing")return 0;if(Vn.tag==="Just")return Vn._1;c()})();if(g==="VDown"){const je=Fr(_e+Un+m(nt._1)+sn)(Nt.thresh);return{st:{...lt,x:it(G)(B)(T("Just",D.initial?je:Fr(jt)(je)))(lt.x)},initial:!1,thresh:Nt.thresh}}if(g==="VUp"){const je=er(_e+Un-sn-m(Q))(Nt.thresh);return{st:{...lt,x:it(G)(B)(T("Just",D.initial?je:er(jt)(je)))(lt.x)},initial:!1,thresh:Nt.thresh}}c()}const Vt=dt(ft)(lt.x),Gt=(()=>{if(Vt.tag==="Just")return Vt._1;if(Vt.tag==="Nothing")return y;c()})(),bt=(()=>{if(Gt.tag==="Nothing")return 0;if(Gt.tag==="Just")return Gt._1;c()})(),pt=dt(B)(lt.x),ct=(()=>{if(pt.tag==="Just")return pt._1;if(pt.tag==="Nothing")return y;c()})(),wt=(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;c()})(),It=ot(t.nodeGap),yt=dt(Q)(s),Ct=dt(nt._1)(s),Ot=(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()-(()=>{if(Ct.tag==="Nothing")return 0;if(Ct.tag==="Just")return Ct._1;c()})();return{st:{...lt,classEdges:[...lt.classEdges,{src:Tt,tgt:vt,sep:(()=>{if(g==="VDown")return wt+Ot-bt-m(nt._1)-It;if(g==="VUp")return wt+Ot+m(Q)+It-bt;c()})()}]},initial:D.initial,thresh:Nt.thresh}}c()},U=B=>D=>{const Q=dt(B)(D.x),O=(()=>{if(Q.tag==="Just")return Q._1;if(Q.tag==="Nothing")return y;c()})();if(O.tag==="Just")return D;if(O.tag==="Nothing"){const z=b(I(B))({st:{...D,x:it(G)(B)(T("Just",0))(D.x)},initial:!0,thresh:(()=>{if(g==="VDown")return-1e18;if(g==="VUp")return 1e18;c()})()})($a(u)(B));return{...z.st,blockFinished:it(G)(B)(!0)(z.st.blockFinished)}}c()},S=b(B=>D=>b(Q=>O=>{const z=dt(O)(u.root),Y=(()=>{if(z.tag==="Nothing")return O;if(z.tag==="Just")return z._1;c()})();return Y===O?U(Y)(Q):Q})(B)((()=>{if(g==="VDown")return D;if(g==="VUp")return re(D);c()})()))({x:Mr(K(B=>E(B,y))(N)),sink:Mr(K(B=>E(B,B))(N)),classEdges:[],su:W,blockFinished:W,queue:[]})(h),v=Bv(S.classEdges)(S.sink)(g),F=(B,D,Q,O)=>{const z=dt(D)(O),Y=dt(D)(s);return(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;c()})()+(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;c()})()+f(B,D,Q)},H=Mr(K(B=>E(B,!0))(Ur(G.compare)((()=>{const B=(D,Q)=>{if(D.tag==="Leaf")return Q;if(D.tag==="Node")return B(D._5,Jt("Cons",D._4,B(D._6,Q)));c()};return Mt(ce.foldr,B(u.root,A))})()))),M=B=>D=>Q=>{const O=C(Q,{su:D.su,blockFinished:H}),z={phase:B,ppFree:Q.free,ppIsRoot:Q.isRoot,edgeId:y,delta:0,avail:0,shift:0,freeSu:(()=>{const Y=dt((()=>{const V=dt(Q.free)(u.root);if(V.tag==="Nothing")return Q.free;if(V.tag==="Just")return V._1;c()})())(D.su);if(Y.tag==="Nothing")return!1;if(Y.tag==="Just")return Y._1;c()})(),hasEdges:O.hasEdges,candCount:(()=>{if(Q.isRoot){if(_==="HRight"){const Y=dt(Q.free)(J);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length;c()}if(_==="HLeft"){const Y=dt(Q.free)(w);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length}c()}if(_==="HRight"){const Y=dt(Q.free)(w);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length;c()}if(_==="HLeft"){const Y=dt(Q.free)(J);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length}c()})()};if(O.edge.tag==="Nothing")return{...D,stack:[...D.stack,Q],trace:[...D.trace,z],x:D.x};if(O.edge.tag==="Just"){const Y=O.edge._1.from.node===Q.free?E(O.edge._1.from.node,O.edge._1.to.node):E(O.edge._1.to.node,O.edge._1.from.node),V=F(O.edge._1,Y._1,l(O.edge._1,Y._1),D.x)-F(O.edge._1,Y._2,l(O.edge._1,Y._2),D.x),X=dt(Y._1)(u.root),Z=(()=>{if(X.tag==="Nothing")return Y._1;if(X.tag==="Just")return X._1;c()})(),nt={...z,edgeId:T("Just",O.edge._1.id),delta:V};if(V>0&&V<1e300){const rt=b(lt=>mt=>{const vt=dt(mt)(p),Ht=(()=>{if(vt.tag==="Nothing")return-1;if(vt.tag==="Just")return vt._1;c()})();if(Ht>=0&&Ht<n.length){const Gt=n[Ht],bt=dt(mt)(e.nodeIndex),pt=(()=>{if(bt.tag==="Nothing")return-2;if(bt.tag==="Just")return bt._1-1|0;c()})();return pt>=0&&pt<Gt.length?er(lt)((()=>{const ct=dt(mt)(D.x),wt=dt(mt)(s),It=dt(Gt[pt])(D.x),yt=dt(Gt[pt])(s);return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;c()})()+(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1;c()})()-((()=>{if(It.tag==="Nothing")return 0;if(It.tag==="Just")return It._1;c()})()+(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+m(Gt[pt])+x(mt,Gt[pt]))})()):lt}const Tt=dt(mt)(e.nodeIndex),Vt=(()=>{if(Tt.tag==="Nothing")return-2;if(Tt.tag==="Just")return Tt._1-1|0;c()})();return Vt>=0&&Vt<0?er(lt)((()=>{const Gt=dt(mt)(D.x),bt=dt(mt)(s),pt=dt([][Vt])(D.x),ct=dt([][Vt])(s);return(()=>{if(Gt.tag==="Nothing")return 0;if(Gt.tag==="Just")return Gt._1;c()})()+(()=>{if(bt.tag==="Nothing")return 0;if(bt.tag==="Just")return bt._1;c()})()-((()=>{if(pt.tag==="Nothing")return 0;if(pt.tag==="Just")return pt._1;c()})()+(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;c()})()+m([][Vt])+x(mt,[][Vt]))})()):lt})(V)($a(u)(Z)),ft=rt>0?-rt:0,Nt={...D,x:rt>0?d(Z,ft,D.x):D.x,trace:[...D.trace,{...nt,avail:rt,shift:ft}]};return rt>0?Nt:{...Nt,stack:[...Nt.stack,Q]}}if(V<0&&-V<1e300){const rt=b(lt=>mt=>{const vt=dt(mt)(p),Ht=(()=>{if(vt.tag==="Nothing")return-1;if(vt.tag==="Just")return vt._1;c()})();if(Ht>=0&&Ht<n.length){const Gt=n[Ht],bt=dt(mt)(e.nodeIndex),pt=(()=>{if(bt.tag==="Nothing")return 0;if(bt.tag==="Just")return bt._1+1|0;c()})();return pt>=0&&pt<Gt.length?er(lt)((()=>{const ct=dt(Gt[pt])(D.x),wt=dt(Gt[pt])(s),It=dt(mt)(D.x),yt=dt(mt)(s);return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;c()})()+(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1;c()})()-((()=>{if(It.tag==="Nothing")return 0;if(It.tag==="Just")return It._1;c()})()+(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+m(mt)+x(mt,Gt[pt]))})()):lt}const Tt=dt(mt)(e.nodeIndex),Vt=(()=>{if(Tt.tag==="Nothing")return 0;if(Tt.tag==="Just")return Tt._1+1|0;c()})();return Vt>=0&&Vt<0?er(lt)((()=>{const Gt=dt([][Vt])(D.x),bt=dt([][Vt])(s),pt=dt(mt)(D.x),ct=dt(mt)(s);return(()=>{if(Gt.tag==="Nothing")return 0;if(Gt.tag==="Just")return Gt._1;c()})()+(()=>{if(bt.tag==="Nothing")return 0;if(bt.tag==="Just")return bt._1;c()})()-((()=>{if(pt.tag==="Nothing")return 0;if(pt.tag==="Just")return pt._1;c()})()+(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;c()})()+m(mt)+x(mt,[][Vt]))})()):lt})(-V)($a(u)(Z)),ft=rt>0?rt:0,Nt={...D,x:rt>0?d(Z,ft,D.x):D.x,trace:[...D.trace,{...nt,avail:rt,shift:ft}]};return rt>0?Nt:{...Nt,stack:[...Nt.stack,Q]}}return{...D,stack:[...D.stack,Q],trace:[...D.trace,nt],x:D.x}}c()},q=b(M(Rv))({x:Mr(K(B=>E(B,(()=>{const D=dt(B)(u.root),Q=(()=>{if(D.tag==="Nothing")return B;if(D.tag==="Just")return D._1;c()})(),O=dt(Q)(S.x),z=dt((()=>{const V=dt(Q)(S.sink);if(V.tag==="Nothing")return Q;if(V.tag==="Just")return V._1;c()})())(v),Y=(()=>{if(O.tag==="Just")return O._1;if(O.tag==="Nothing")return y;c()})();return(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;c()})()+(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;c()})()})()))(N)),su:S.su,stack:[],trace:[]})(S.queue),$=b(M(Pv))({...q,stack:[]})(re(q.stack));return{x:$.x,queue:S.queue,trace:$.trace}},Iv=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>_=>Av(t)(e)(n)(r)(o)(i)(a)(s)(u)(g)(_).x,zv=t=>e=>n=>r=>o=>i=>{const a=(u,g,_)=>{const f=dt(g)(n),l=(()=>{if(f.tag==="Nothing")return .5;if(f.tag==="Just")return f._1._1/2;c()})(),d=u.from.node===g?u.from.port:u.to.node===g?u.to.port:y;if(d.tag==="Just"){const h=dt(g)(e);if(h.tag==="Just"){const m=te(p=>p.id===d._1)(h._1);if(m.tag==="Just"){const p=ot(m._1.offset)*ot(4);return _==="North"||_==="South"?p:0}if(m.tag==="Nothing"){const p=ga(o)(u.id)(_)(l);return _==="North"||_==="South"?p:0}c()}if(h.tag==="Nothing"){const m=ga(o)(u.id)(_)(l);return _==="North"||_==="South"?m:0}c()}if(d.tag==="Nothing"){const h=ga(o)(u.id)(_)(l);return _==="North"||_==="South"?h:0}c()},s=u=>g=>_=>f=>{let l=u,d=g,h=_,m=f,p=!0,x;for(;p;){const J=l,w=d,N=h,L=Bt(C=>y,C=>R=>T("Just",{head:C,tail:R}),m);if(L.tag==="Nothing"){p=!1,x=J;continue}if(L.tag==="Just"){const C=L._1.head,R=te(I=>I.from.node===N&&I.to.node===C||I.from.node===C&&I.to.node===N)(r),P=(()=>{if(R.tag==="Nothing")return w+0;if(R.tag==="Just")return w+(a(R._1,N,R._1.from.node===N?ze:Ie)-a(R._1,C,R._1.from.node===C?ze:Ie));c()})();l=it(G)(C)(P)(J),d=P,h=C,m=L._1.tail;continue}c()}return x};return b(u=>g=>{const _=Bt(d=>y,d=>h=>T("Just",{head:d,tail:h}),$a(t)(g)),f=(()=>{if(_.tag==="Nothing")return it(G)(g)(0)(W);if(_.tag==="Just")return s(it(G)(_._1.head)(0)(W))(0)(_._1.head)(_._1.tail);c()})(),l=b(d=>h=>Fr(d)(-h._2))(0)(C_(f));return b(d=>h=>it(G)(h._1)(h._2+l)(d))(u)(C_(f))})(W)(Ur(G.compare)((()=>{const u=(g,_)=>{if(g.tag==="Leaf")return _;if(g.tag==="Node")return u(g._5,Jt("Cons",g._4,u(g._6,_)));c()};return Mt(ce.foldr,u(t.root,A))})()))},Dv=t=>e=>{const n=(o,i,a)=>Ve(3)(i)==="$d:"&&Wg(rh,(()=>{const s=dt(i)(t.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;c()})()),r=o=>i=>a=>s=>u=>g=>_=>{let f=o,l=i,d=s,h=g,m=_,p=!0,x;for(;p;){const J=f,w=l,N=d,L=h,C=m,R=w.length;if(C>=R){p=!1,x=J;continue}const P=C>=0&&C<w.length?T("Just",w[C]):y,I=(()=>{if(P.tag==="Nothing")return"";if(P.tag==="Just")return P._1;c()})(),U=n(t,I);if(C===(R-1|0)||U){const S=(()=>{if(U){const v=dt(I)(t.preds),F=(()=>{if(v.tag==="Nothing")return[];if(v.tag==="Just")return v._1;c()})();if(0<F.length){const H=N-1|0,M=dt(F[0])(t.nodeIndex);if(M.tag==="Nothing")return H;if(M.tag==="Just")return M._1;c()}}return N-1|0})();f=b(v=>F=>{if(F>=0&&F<w.length){const H=w[F];return n(t,H)?v:b(M=>q=>{const $=dt(q)(t.nodeIndex),B=(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;c()})();return B<L||B>S?it(G)(q+"\u2192"+H)()(M):M})(v)((()=>{const M=dt(H)(t.preds);if(M.tag==="Nothing")return[];if(M.tag==="Just")return M._1;c()})())}return n(t,"")?v:b(H=>M=>{const q=dt(M)(t.nodeIndex),$=(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;c()})();return $<L||$>S?it(G)(M+"\u2192")()(H):H})(v)((()=>{const H=dt("")(t.preds);if(H.tag==="Nothing")return[];if(H.tag==="Just")return H._1;c()})())})(J)(Ut(0,C)),l=w,d=N,h=S,m=C+1|0;continue}f=J,l=w,d=N,h=L,m=C+1|0}return x};return e.length<3?W:b(o=>i=>{if(i>=0&&i<e.length){const a=e[i];return r(o)((()=>{const s=i+1|0;return s>=0&&s<e.length?e[s]:[]})())(a)(a.length)(i)(0)(0)}return r(o)((()=>{const a=i+1|0;return a>=0&&a<e.length?e[a]:[]})())([])(0)(i)(0)(0)})(W)(Ut(1,e.length-2|0))},Fv=t=>e=>n=>r=>o=>{const i=kn(e),a=b(s=>u=>{const g=b(_=>f=>{const l=(()=>{if(o==="HRight"){const p=dt(f)(t.preds);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;c()}if(o==="HLeft"){const p=dt(f)(t.succs);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1}c()})(),d=l.length;if(d===0)return _;const h=Sr(d-1|0,2),m=Sr(d,2);return b(p=>x=>{if((()=>{const J=dt(f)(p.align);if(J.tag==="Nothing")return f!==f;if(J.tag==="Just")return J._1!==f;c()})())return p;if(x>=0&&x<l.length){const J=dt(l[x])(t.nodeIndex),w=(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;c()})();if(!(Th(l[x]+"\u2192"+f)(n)||Th(f+"\u2192"+l[x])(n))&&(()=>{if(r==="VDown")return p.r<w;if(r==="VUp")return p.r>w;c()})()){const N=dt(l[x])(p.root),L=(()=>{if(N.tag==="Nothing")return l[x];if(N.tag==="Just")return N._1;c()})();return{root:it(G)(f)(L)(p.root),align:it(G)(l[x])(f)(it(G)(f)(L)(p.align)),r:w}}}return p})(_)((()=>{if(r==="VDown")return Ut(h,m);if(r==="VUp")return re(Ut(h,m));c()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;c()})()})((()=>{if(r==="VDown")return u;if(r==="VUp")return re(u);c()})());return{root:g.root,align:g.align}})({root:Mr(K(s=>E(s,s))(i)),align:Mr(K(s=>E(s,s))(i))})((()=>{if(o==="HRight")return e;if(o==="HLeft")return re(e);c()})());return{root:a.root,align:a.align}},Bu=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>{const _=Fv(e)(n)(s)(u)(g),f=zv(_)(o)(r)(i)(a)(g);return $g()(l=>d=>T("Just",(()=>{const h=dt(l)(f);if(h.tag==="Nothing")return d+0;if(h.tag==="Just")return d+h._1;c()})()))(Iv(t)(e)(n)(r)(o)(i)(a)(f)(_)(u)(g))},bh=t=>e=>Ft(n=>r=>b(o=>i=>i>=0&&i<e.length?i>=0&&i<t.length?o+e[i]+t[i]:o+e[i]+0:i>=0&&i<t.length?o+1+t[i]:o+1)(0)((()=>{const o=Ut(0,e.length-1|0);return n<1?[]:At(0,n,o)})()))(e),Mv=t=>e=>n=>r=>o=>i=>a=>{const s=Sv(0)(e.length-1|0),u=ot(t.layerGap),g=a(Qo(s,u)),_=Tv(fh(o)(g)(r)(i)(W))(g);return K(f=>{const l=Ev(f)(_);return l.tag==="Just"&&l._1>0?Fr(u)(2+ot(l._1-1|0)*2.5):u})(Ut(0,s-1|0))},vh=t=>e=>n=>r=>Wg(o=>b(i=>a=>{if(!i.ok)return i;const s=dt(a)(r),u=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})(),g=dt(a)(n),_=(()=>{if(g.tag==="Nothing")return u+1;if(g.tag==="Just")return u+g._1._1;c()})();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),Qv=t=>e=>n=>r=>{const o=Rt(i=>a=>at.compare(i.w)(a.w))(K(i=>({l:i,w:Nh(i)}))(_t(vh()(e)(n),r)));return 0<o.length?T("Just",o[0].l):y},Wv=t=>e=>{const n=Mr(kn(K(Ft(o=>i=>E(i,o)))(t))),r=o=>Rt(i=>a=>ut.compare((()=>{const s=dt(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})())((()=>{const s=dt(a)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(o);return{preds:(()=>{const o=i=>{if(i.tag==="Leaf")return W;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));c()};return o(b(i=>a=>Wt(G)(Je)(a.to.node)([a.from.node])(i))(W)(e))})(),succs:(()=>{const o=i=>{if(i.tag==="Leaf")return W;if(i.tag==="Node")return ee("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));c()};return o(b(i=>a=>Wt(G)(Je)(a.from.node)([a.to.node])(i))(W)(e))})(),nodeIndex:n}},Ov=t=>e=>{const n=Rt(f=>l=>at.compare(f.w)(l.w))(Ft(f=>l=>({i:f,l,w:Nh(l)}))(e)),r=0<n.length?T("Just",n[0]):y,o=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;c()})(),i=o>=0&&o<e.length?T("Just",e[o]):y,a=(()=>{if(i.tag==="Just")return(f=>l=>{let d=f,h=l,m=!0,p;for(;m;){const x=d,J=h;if(J.tag==="Nil"){m=!1,p=x;continue}if(J.tag==="Cons"){d=er(x)(J._1),h=J._2;continue}c()}return p})(999999)((()=>{const f=(l,d)=>{if(l.tag==="Leaf")return d;if(l.tag==="Node")return f(l._5,Jt("Cons",l._4,f(l._6,d)));c()};return f(i._1,A)})());if(i.tag==="Nothing")return 0;c()})(),s=f=>b(l=>d=>Fr(l)((()=>{const h=dt(d._1)(t);if(h.tag==="Nothing")return d._2+1;if(h.tag==="Just")return d._2+h._1._1;c()})()))(-999999)(C_(f)),u=o>=0&&o<e.length?T("Just",e[o]):y,g=(()=>{if(u.tag==="Just")return s(u._1);if(u.tag==="Nothing")return 0;c()})(),_=We(f=>l=>{const d=h=>{if(h.tag==="Leaf")return W;if(h.tag==="Node")return ee("Node",h._1,h._2,h._3,h._4+l,d(h._5),d(h._6));c()};return d(f)},e,Ft(f=>l=>lo(f)(2)===0?a-(d=>h=>{let m=d,p=h,x=!0,J;for(;x;){const w=m,N=p;if(N.tag==="Nil"){x=!1,J=w;continue}if(N.tag==="Cons"){m=er(w)(N._1),p=N._2;continue}c()}return J})(999999)((()=>{const d=(h,m)=>{if(h.tag==="Leaf")return m;if(h.tag==="Node")return d(h._5,Jt("Cons",h._4,d(h._6,m)));c()};return d(l,A)})()):g-s(l))(e));return Gv(b(f=>l=>{const d=Rt(at.compare)(ht(dt(l))(_));return it(G)(l)(d.length===4?1<d.length&&2<d.length?(d[1]+d[2])/2:0:0<d.length?d[0]:0)(f)})(W)(Ur(G.compare)(kn(K(f=>{const l=d=>{if(d.tag==="Leaf")return W;if(d.tag==="Node")return ee("Node",d._1,d._2,d._3,void 0,l(d._5),l(d._6));c()};return Mt(Jn.foldr,l(f))})(_)))))},Hv=t=>e=>n=>r=>o=>i=>{const a=Wv(e)(o),s=Dv(a)(e),u={nodeGap:t.nodeGap*4|0},g=nn(G.compare,tn,Mr(K(d=>E(d,E(1,1)))(_t(rh,kn(e)))),(()=>{const d=h=>{if(h.tag==="Leaf")return W;if(h.tag==="Node")return ee("Node",h._1,h._2,h._3,E(h._4._1*ot(4),h._4._2),d(h._5),d(h._6));c()};return d(n)})()),_=[Bu(u)(a)(e)(g)(r)(o)(i)(s)(yh)(Jh),Bu(u)(a)(e)(g)(r)(o)(i)(s)(xh)(Jh),Bu(u)(a)(e)(g)(r)(o)(i)(s)(yh)(wh),Bu(u)(a)(e)(g)(r)(o)(i)(s)(xh)(wh)],f=Ov(g)(_);if(vh()(e)(g)(f))return f;const l=Qv()(e)(g)(_);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return _[0];c()},$v=t=>e=>n=>r=>{const o=j1(y,U1,i=>i.node===e?T("Just",i.position):y,t);if(o.tag==="Nothing")return t;if(o.tag==="Just"){const i=o._1;return K(a=>a.node===n?{...a,position:E(i._1+r._1,i._2+r._2)}:a)(t)}c()},qv=t=>e=>n=>r=>{const o=_t(a=>yn(Er)(a.node)(e),t),i=(()=>{if(n==="Vertical"){if(r==="Start")return b(a=>s=>er(a)(s.position._1))(99999)(o);if(r==="End")return b(a=>s=>Fr(a)(s.position._1))(0)(o);if(r==="Center"){const a=b(s=>u=>s+u.position._1)(0)(o);return o.length===0?0:a/ot(o.length)}c()}if(n==="Horizontal"){if(r==="Start")return b(a=>s=>er(a)(s.position._2))(99999)(o);if(r==="End")return b(a=>s=>Fr(a)(s.position._2))(0)(o);if(r==="Center"){const a=b(s=>u=>s+u.position._2)(0)(o);return o.length===0?0:a/ot(o.length)}}c()})();return K(a=>{if(yn(Er)(a.node)(e)){if(n==="Vertical")return{...a,position:E(i,a.position._2)};if(n==="Horizontal")return{...a,position:E(a.position._1,i)};c()}return a})(t)},Vv=t=>e=>b(n=>r=>r.tag==="AlignGroup"?qv(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?$v(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),Uv=t=>e=>n=>r=>o=>i=>a=>s=>{const u=K(f=>b(l=>d=>Fr(l)((()=>{const h=dt(d)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;c()})()))(1)(f))(n),g=Hv(t)(n)(r)(o)(i)(s),_=bh(Mv(t)(n)(r)(o)(i)(a)(f=>{const l=bh(f)(u);return kn(Ft(d=>h=>Ft(m=>p=>({node:p,position:E((()=>{const x=dt(p)(g);return(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;c()})()/ot(4)})(),d>=0&&d<l.length?l[d]:0),size:(()=>{const x=Ve(3)(p)==="$d:"?E(0,1):E(1,1),J=dt(p)(r);if(J.tag==="Nothing")return x;if(J.tag==="Just")return J._1;c()})(),layer:d,order:m}))(h))(n))}))(u);return Vv(e)(kn(Ft(f=>l=>Ft(d=>h=>({node:h,position:E((()=>{const m=dt(h)(g);return(()=>{if(m.tag==="Nothing")return 0;if(m.tag==="Just")return m._1;c()})()/ot(4)})(),f>=0&&f<_.length?_[f]:0),size:(()=>{const m=Ve(3)(h)==="$d:"?E(0,1):E(1,1),p=dt(h)(r);if(p.tag==="Nothing")return m;if(p.tag==="Just")return p._1;c()})(),layer:f,order:d}))(l))(n)))},L_=gc(Gs)(Vo(32)),Ch=gc(Gs)(Vo(31)),qa=(()=>{const t=fx("25214903917");if(t.tag==="Nothing")return Pf;if(t.tag==="Just")return t._1;c()})(),Va=uc(gc(Gs)(Vo(48)))(Gs),Xv=t=>{const e=lx(t);return Ea(Bf((()=>{if(e.tag==="Nothing")return Pf;if(e.tag==="Just")return e._1;c()})())(qa))(Va)},k_=Vo(11),Gu=t=>e=>{const n=Ea(Ps(Bs(e)(qa))(k_))(Va);return E((()=>{const r=nf(ux(cc(n)(Vo(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;c()})(),n)},Kv=t=>{const e=Gu(26)(t),n=Gu(27)(e._2);return E((ot(e._1)*Hg(2)(27)+ot(n._1))/Hg(2)(53),n._2)},Yv=t=>e=>{const n=b(r=>o=>{const i=Kv(r.finalR);return{rs:[...r.rs,i._1],finalR:i._2}})({rs:[],finalR:t})(e);return E(K(r=>r.x)(Rt(r=>o=>at.compare(r.k)(o.k))(We(r=>o=>({x:r,k:o}),e,n.rs))),n.finalR)},Zv=t=>{const e=Ea(Ps(Bs(t)(qa))(k_))(Va),n=Ea(Ps(Bs(e)(qa))(k_))(Va);return E(Ps(Bs((()=>{const r=cc(e)(Vo(16));return Gf.compare(r)(Ch)!=="LT"?uc(r)(L_):r})())(L_))((()=>{const r=cc(n)(Vo(16));return Gf.compare(r)(Ch)!=="LT"?uc(r)(L_):r})()),n)},Ua=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Au=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=G.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}}c()}return o},S_=fe(G)(Qt),ca=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Iu=fe(G)(Qt),jv=bs(zi),tC=b(ur)(0),eC=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Lh=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=G.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}}c()}return o},nC=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const o=co(Yt,y,t,n[e],n);if(o.tag==="Just")return co(Yt,y,e,r,o._1);if(o.tag==="Nothing")return y;c()}}return y},rC=t=>e=>n=>r=>o=>S_(b(i=>a=>{const s=Rt(u=>g=>ut.compare((()=>{const _=Ua(u.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;c()})())((()=>{const _=Ua(g.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;c()})()))(_t(u=>Au(u.to.node)(n),_t(u=>u.from.node===a,r)));return{ranks:[...i.ranks,...Ft(u=>g=>E(g.id,ot((i.rankSum+u|0)+1|0)))(s)],rankSum:i.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),oC=t=>e=>n=>r=>o=>S_(b(i=>a=>{const s=Rt(g=>_=>{const f=ut.compare((()=>{const l=ca(_.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})())((()=>{const l=ca(g.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})());return f==="EQ"?ut.compare((()=>{const l=Ua(g.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Ua(_.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})()):f})(_t(g=>Au(g.from.node)(n),_t(g=>g.to.node===a,r))),u=s.length;return{ranks:[...i.ranks,...Ft(g=>_=>E(_.id,ot((i.rankSum+u|0)-g|0)))(s)],rankSum:i.rankSum+u|0}})({ranks:[],rankSum:0})(t).ranks),E_=t=>e=>n=>{const r=Iu(Ft(s=>u=>E(u,s))(t)),o=Iu(Ft(s=>u=>E(u,s))(e)),i=ht(s=>{const u=ca(s.from.node)(r),g=ca(s.to.node)(o);if(u.tag==="Just"&&g.tag==="Just")return T("Just",E(u._1,g._1));const _=ca(s.from.node)(o),f=ca(s.to.node)(r);return _.tag==="Just"&&f.tag==="Just"?T("Just",E(f._1,_._1)):y})(n),a=i.length;return b(s=>u=>b(g=>_=>u>=0&&u<i.length&&_>=0&&_<i.length&&((i[u]._1-i[_]._1|0)*(i[u]._2-i[_]._2|0)|0)<0?g+1|0:g)(s)(Ut(u+1|0,a-1|0)))(0)(Ut(0,a-2|0))},iC=t=>e=>n=>r=>{const o=i=>a=>{let s=i,u=a,g=!0,_;for(;g;){const f=s,l=u;if(l>=(f.length-1|0)){g=!1,_=f;continue}if(l>=0&&l<f.length){const d=l+1|0;if(d>=0&&d<f.length){const h=f[l],m=f[d];if(oe(w=>w.before===h&&w.after===m,r)){s=f,u=l+1|0;continue}const p=co(Yt,y,l,m,f),x=(()=>{if(p.tag==="Just")return co(Yt,y,l+1|0,h,p._1);if(p.tag==="Nothing")return y;c()})(),J=(()=>{if(x.tag==="Nothing")return f;if(x.tag==="Just")return x._1;c()})();if(E_(e)(J)(n)<E_(e)(f)(n)){s=J,u=l+1|0;continue}s=f,u=l+1|0;continue}g=!1,_=f;continue}g=!1,_=f}return _};return(i=>{let a=i,s=!0,u;for(;s;){const g=a,_=o(g)(0);if(jv(_)(g)){s=!1,u=g;continue}a=_}return u})(t)},zu=t=>e=>b(n=>r=>{if(r>=0&&r<t.length){const o=t[r],i=r+1|0;if(i>=0&&i<t.length)return n+E_(o)(t[i])(e)|0}return n})(0)(Ut(0,t.length-2|0)),aC=(()=>{const t=e=>{if(e.length<7){const i=a=>s=>{let u=a,g=s,_=!0,f;for(;_;){const l=u,d=g,h=d-1|0;if(h>=0&&h<l.length){if(d>=0&&d<l.length&&d>0&&l[h].key>l[d].key){const m=nC(d-1|0)(d)(l);if(m.tag==="Just"){u=m._1,g=d-1|0;continue}if(m.tag==="Nothing"){_=!1,f=l;continue}c()}_=!1,f=l;continue}_=!1,f=l}return f};return b(a=>s=>i(a)(s))(e)(Ut(1,e.length-1|0))}const n=Sr(e.length,2),r=t(At(0,n,e)),o=t(At(n,e.length,e));return(i=>a=>s=>{let u=i,g=a,_=s,f=!0,l;for(;f;){const d=u,h=g,m=_;if(h>=0&&h<r.length){if(m>=0&&m<o.length){if(r[h].key>o[m].key){u=Et(d)(o[m]),g=h,_=m+1|0;continue}u=Et(d)(r[h]),g=h+1|0,_=m;continue}f=!1,l=[...d,...h<1?r:At(h,r.length,r)];continue}f=!1,l=[...d,...m<1?o:At(m,o.length,o)]}return l})([])(0)(0)};return t})(),sC=t=>e=>n=>{const r=ht(g=>g.tag==="OrderConstraint"?T("Just",{before:g._1.before,after:g._1.after}):y)(t.constraints),o=g=>b(_=>f=>{const l=f.after,d=f.before,h=Wo(Yt,y,p=>p===d,_),m=Wo(Yt,y,p=>p===l,_);if(h.tag==="Just"&&m.tag==="Just"&&h._1>m._1){const p=ef(Yt,y,h._1,_),x=(()=>{if(p.tag==="Nothing")return _;if(p.tag==="Just")return p._1;c()})(),J=tf(Yt,y,m._1,d,x);if(J.tag==="Nothing")return x;if(J.tag==="Just")return J._1;c()}return _})(g)(r),i=S_(Ft(g=>_=>E(_.id,g))(n)),a=(g,_,f)=>{const l=g.length;return b(d=>h=>{const m=_?h-1|0:h+1|0,p=m>=0&&m<d._1.length?T("Just",d._1[m]):y;if(p.tag==="Just"){const x=h>=0&&h<d._1.length?T("Just",d._1[h]):y;if(x.tag==="Just"){const J=Iu(Ft(R=>P=>E(P,R))(p._1)),w=Iu(Ft(R=>P=>E(P,R))(x._1)),N=_?rC(p._1)(J)(w)(n)(i):oC(p._1)(J)(w)(n)(i),L=b(R=>P=>{const I=ht(S=>Ua(S.id)(N))(_t(_?S=>S.to.node===P._2&&Au(S.from.node)(J):S=>S.from.node===P._2&&Au(S.to.node)(J),n));if(I.length===0)return{...R,items:[...R.items,{n:P._2,key:y,origIdx:P._1}]};const U=Gu(24)(R.r);return{items:[...R.items,{n:P._2,key:T("Just",(tC(I)+(ot(U._1)*4172325152040912e-24-.03500000014901161))/ot(I.length)),origIdx:P._1}],r:U._2}})({items:[],r:d._2})(Ft(mn)(x._1)),C=co(Yt,y,h,iC(o(K(R=>R.n)(aC((()=>{const R=L.items,P=I=>U=>{let S=I,v=U,F=!0,H;for(;F;){const M=S,q=v;if(M>=0&&M<R.length){if(R[M].key.tag==="Just"){F=!1,H=R[M].key._1;continue}if(R[M].key.tag==="Nothing"){S=M+1|0,v=q;continue}c()}F=!1,H=q}return H};return(I=>U=>S=>{let v=I,F=U,H=S,M=!0,q;for(;M;){const $=v,B=F,D=H;if($>=0&&$<R.length){if(R[$].key.tag==="Just"){v=$+1|0,F=R[$].key._1,H=[...D,{n:R[$].n,key:R[$].key._1,origIdx:R[$].origIdx}];continue}if(R[$].key.tag==="Nothing"){const Q=(B+P($+1|0)(B+1))/2;v=$+1|0,F=Q,H=[...D,{n:R[$].n,key:Q,origIdx:R[$].origIdx}];continue}c()}M=!1,q=D}return q})(0)(-1)([])})()))))(p._1)(n)(r),d._1);if(C.tag==="Just")return E(C._1,L.r);if(C.tag==="Nothing")return E(d._1,d._2);c()}if(x.tag==="Nothing")return E(d._1,d._2);c()}if(p.tag==="Nothing")return E(d._1,d._2);c()})(E(g,f))(_?Ut(1,l-1|0):re(Ut(0,l-2|0)))},s=b(g=>_=>it(G)(_.from.node)()(it(G)(_.to.node)()(g)))(W)(n),u=b(g=>_=>{if(g.result.crossings===0)return g;const f=J=>w=>N=>L=>{let C=J,R=w,P=N,I=L,U=!0,S;for(;U;){const v=C,F=R,H=P,M=I;if(H===0){U=!1,S={layout:v,crossings:0,random:M};continue}const q=a(v,F,M),$=zu(q._1)(n);if($<H){C=q._1,R=!F,P=$,I=q._2;continue}U=!1,S={layout:v,crossings:H,random:q._2}}return S},l=Gu(1)(g.result.random),d=l._1!==0,h=t.modelOrder.tag==="Leaf",m=(g.firstTry||g.secondTry)&&!h?g.firstTry:d,p=(()=>{if(!h){const L=a(e,m,l._2);return f(L._1)(!m)(zu(L._1)(n))(L._2)}const J=m?0:eC(0)(e.length-1|0),w=J>=0&&J<e.length?T("Just",e[J]):y;if(w.tag==="Just"&&w._1.length>1){const L=_t(C=>Lh(C)(s),w._1);if(L.length>1){const C=Yv(l._2)(L),R=C._1,P=co(Yt,y,J,o(b(I=>U=>Lh(U)(s)?I.idx>=0&&I.idx<R.length?{idx:I.idx+1|0,result:[...I.result,R[I.idx]]}:{idx:I.idx,result:[...I.result,U]}:{idx:I.idx,result:[...I.result,U]})({idx:0,result:[]})(w._1).result),e);if(P.tag==="Just"){const I=a(P._1,m,C._2);return f(I._1)(!m)(zu(I._1)(n))(I._2)}}}const N=a(e,m,l._2);return f(N._1)(!m)(zu(N._1)(n))(N._2)})(),x=g.secondTry?!1:g.secondTry;return g.firstTry?{result:p.crossings<g.result.crossings?{layout:p.layout,crossings:p.crossings,random:p.random}:{...g.result,random:p.random},firstTry:!1,secondTry:!0}:{result:p.crossings<g.result.crossings?{layout:p.layout,crossings:p.crossings,random:p.random}:{...g.result,random:p.random},firstTry:g.firstTry,secondTry:x}})({result:{layout:e,crossings:1e9,random:Ea(Bf(Zv(Xv(1))._1)(qa))(Va)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Ut(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:u.layout},uC=t=>t,kh=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=G.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}}c()}return o},Tn=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},_a=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=G.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}}c()}return o},Xa=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=G.compare(e._1)(n._1);return r==="LT"?Me:r==="GT"?Qe:G.compare(e._2)(n._2)},Eq0:()=>t}})(),gC=fe(G)(Qt),cC=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=Xa.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}}c()}return o},_C=uC("Greedy"),R_=t=>e=>n=>b(r=>o=>{if(o.from.node===o.to.node)return r;if(o.from.node===e&&!kh(o.to.node)(r.marks)){const i=Tn(o.to.node)(r.inDeg),a=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;c()})(),s=it(G)(o.to.node)(a)(r.inDeg);return(()=>{const u=Tn(o.to.node)(r.outDeg);return a<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;c()})()&&!yn(Er)(o.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,o.to.node]}:{...r,inDeg:s}}if(o.to.node===e&&!kh(o.from.node)(r.marks)){const i=Tn(o.from.node)(r.outDeg),a=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;c()})(),s=it(G)(o.from.node)(a)(r.outDeg);return(()=>{const u=Tn(o.from.node)(r.inDeg);return a<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;c()})()&&!yn(Er)(o.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,o.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:_t(r=>r!==e,n.remaining)})(t),fC=b(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return it(G)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return it(G)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return it(G)(e._1.node)(99999)(t)}return t})(W),Sh=t=>e=>n=>{const r=Tn(e)(t),o=Tn(n)(t);return r.tag==="Just"&&o.tag==="Just"&&r._1>o._1},Eh=t=>e=>n=>r=>{if(_a(n)(r.visited)||_a(n)(r.visiting))return r;const o=b(lC(t)(e)(n))({...r,visiting:it(G)(n)()(r.visiting)})((()=>{const i=Tn(n)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;c()})());return{...o,visiting:Mi(G)(n)(o.visiting),visited:it(G)(n)()(o.visited)}},lC=t=>e=>n=>r=>o=>Sh(t)(n)(o)?{...r,backEdges:it(Xa)(E(n,o))()(r.backEdges)}:_a(o)(r.visiting)?{...r,backEdges:it(Xa)(E(n,o))()(r.backEdges)}:_a(o)(r.visited)?r:Eh(t)(e)(o)(r),dC=t=>e=>n=>{const r=l=>{let d=l,h=!0,m;for(;h;){const p=d,x=Bt(J=>y,J=>w=>T("Just",{head:J,tail:w}),p.sinks);if(x.tag==="Just"){d=R_(n)(x._1.head)({...p,sinks:x._1.tail,marks:it(G)(x._1.head)(p.nextRight)(p.marks),nextRight:p.nextRight-1|0});continue}if(x.tag==="Nothing"){const J=Bt(w=>y,w=>N=>T("Just",{head:w,tail:N}),p.sources);if(J.tag==="Just"){d=R_(n)(J._1.head)({...p,sources:J._1.tail,marks:it(G)(J._1.head)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}if(J.tag==="Nothing"){const w=L=>{const C=Tn(L)(p.outDeg),R=Tn(L)(p.inDeg);return(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;c()})()-(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;c()})()|0},N=Rt(L=>C=>{const R=ut.compare(w(C))(w(L));return R==="EQ"?ut.compare((()=>{const P=Tn(L)(e);if(P.tag==="Nothing")return 1e6;if(P.tag==="Just")return P._1;c()})())((()=>{const P=Tn(C)(e);if(P.tag==="Nothing")return 1e6;if(P.tag==="Just")return P._1;c()})()):R})(p.remaining);if(0<N.length){const L=N[0];d=R_(n)(L)({...p,remaining:_t(C=>C!==L,p.remaining),marks:it(G)(L)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}h=!1,m=p;continue}}c()}return m},o=Ur(G.compare)([...K(l=>l.from.node)(n),...K(l=>l.to.node)(n)]),i=_t(l=>l.from.node!==l.to.node,n),a=b(l=>d=>Wt(G)(ve)(d.to.node)(1)(l))(W)(i),s=b(l=>d=>Wt(G)(ve)(d.from.node)(1)(l))(W)(i),u=_t(l=>{const d=Tn(l)(a);if(d.tag==="Nothing")return!0;if(d.tag==="Just")return d._1===0;c()},o),g=_t(l=>{const d=Tn(l)(s);if(d.tag==="Nothing")return!0;if(d.tag==="Just")return d._1===0;c()},o),_=o.length+1|0,f=b(l=>d=>{const h=Tn(d)(l);return h.tag==="Just"&&h._1<0?it(G)(d)(h._1+_|0)(l):l})(r({remaining:_t(l=>!yn(Er)(l)(u)&&!yn(Er)(l)(g),o),marks:W,inDeg:a,outDeg:s,sources:u,sinks:g,nextLeft:1,nextRight:-1}).marks)(o);return b(l=>d=>{if(d.from.node===d.to.node)return l;if(Sh(t)(d.from.node)(d.to.node))return it(Xa)(E(d.from.node,d.to.node))()(l);const h=Tn(d.from.node)(f),m=Tn(d.to.node)(f);return h.tag==="Just"&&m.tag==="Just"&&h._1>m._1?it(Xa)(E(d.from.node,d.to.node))()(l):l})(W)(n)},hC=b(t=>e=>Wt(G)(Je)(e.from.node)([e.to.node])(t))(W),pC=t=>e=>{const n=hC(e),r=Ur(G.compare)([...K(i=>i.from.node)(e),...K(i=>i.to.node)(e)]),o=b(i=>a=>it(G)(a.to.node)()(i))(W)(e);return b(i=>a=>Eh(t)(n)(a)(i))({visiting:W,visited:W,backEdges:W})([..._t(i=>!_a(i)(o),r),..._t(i=>_a(i)(o),r)]).backEdges},mC=t=>e=>n=>r=>{const o=gC(Ft(s=>u=>E(u,s))(e)),i=fC(n),a=(()=>{if(t==="DepthFirst")return pC(i)(r);if(t==="Greedy")return dC(i)(o)(r);c()})();return{edges:K(s=>cC(E(s.from.node,s.to.node))(a)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:a}},Rh=Qt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),Be=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Ge=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ka=t=>e=>n=>r=>Rh(o=>n>=o.x&&n<o.x+o.w&&e>o.y&&t<o.y+o.h)(r),Du=t=>e=>n=>r=>Ka(Be(e)(n))(Ge(e)(n))(r)(t),Fu=ot(4),yC=vs(t=>{if(t.direction==="H"){const e=Be(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:Ge(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=Be(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:Ge(t.start._2)(t.end._2)-e}]}c()}),Ya=Ta(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})())}),xC=t=>e=>n=>{const r=Bt(o=>y,o=>i=>T("Just",{head:o,tail:i}),e);if(r.tag==="Nothing")return[{start:t.start,end:n.end,direction:t.direction}];if(r.tag==="Just"){const o=(r._1.head.direction==="H"?t.direction==="H":r._1.head.direction==="V"&&t.direction==="V")?[{start:t.start,end:r._1.head.end,direction:t.direction}]:[t,r._1.head],i=Rr(r._1.tail);if(i.tag==="Nothing"){const a=o.length-1|0;return a>=0&&a<o.length&&(o[a].direction==="H"?n.direction==="H":o[a].direction==="V"&&n.direction==="V")?[...(()=>{const s=o.length-1|0;return s<1?[]:At(0,s,o)})(),{start:o[a].start,end:n.end,direction:n.direction}]:[...o,n]}if(i.tag==="Just")return(i._1.last.direction==="H"?n.direction==="H":i._1.last.direction==="V"&&n.direction==="V")?[...o,...i._1.init,{start:i._1.last.start,end:n.end,direction:n.direction}]:[...o,...r._1.tail,n]}c()},Za=t=>{const e=r=>o=>{const i=Bt(a=>y,a=>s=>T("Just",{head:a,tail:s}),o);if(i.tag==="Nothing")return[r];if(i.tag==="Just")return(r.direction==="H"?i._1.head.direction==="H":r.direction==="V"&&i._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==i._1.head.end._1-i._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==i._1.head.end._2-i._1.head.start._2>=0;c()})()?e({start:r.start,end:i._1.head.end,direction:r.direction})(i._1.tail):[r,...e(i._1.head)(i._1.tail)];c()},n=Bt(r=>y,r=>o=>T("Just",{head:r,tail:o}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);c()},ja=t=>e=>n=>r=>Rh(o=>n>=o.y&&n<o.y+o.h&&e>o.x&&t<o.x+o.w)(r),ts=t=>e=>n=>r=>ja(Be(e)(n))(Ge(e)(n))(r)(t),JC=t=>e=>n=>r=>{const o=n+2|0,i=o<1?e:At(o,e.length,e),a=n<1?[]:At(0,n,e),s=(n+1|0)===(r-1|0),u=n===0,g=n>=0&&n<e.length?T("Just",e[n]):y;if(g.tag==="Just"){const _=n+1|0,f=_>=0&&_<e.length?T("Just",e[_]):y;if(f.tag==="Just"){const l=g._1.start._1===f._1.end._1&&(!u||g._1.direction==="V")&&(!s||f._1.direction==="V")&&!Du(t)(Be(g._1.start._2)(f._1.end._2))(Ge(g._1.start._2)(f._1.end._2))(g._1.start._1)?T("Just",[...a,{start:g._1.start,end:f._1.end,direction:Ne},...i]):y,d=g._1.start._2===f._1.end._2&&(!u||g._1.direction==="H")&&(!s||f._1.direction==="H")&&!ts(t)(Be(g._1.start._1)(f._1.end._1))(Ge(g._1.start._1)(f._1.end._1))(g._1.start._2)?T("Just",[...a,{start:g._1.start,end:f._1.end,direction:Te},...i]):y;return l.tag==="Nothing"?d:l}if(f.tag==="Nothing")return y;c()}if(g.tag==="Nothing")return y;c()},wC=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=JC(t)(e)(s)(n);if(u.tag==="Just"){i=!1,a=u._1;continue}if(u.tag==="Nothing"){o=s+1|0;continue}c()}return a})(0)},TC=t=>e=>n=>r=>{const o=(l,d,h)=>!Du(t)(Be(d)(h))(Ge(d)(h))(l),i=n+3|0,a=i<1?e:At(i,e.length,e),s=n<1?[]:At(0,n,e),u=(n+2|0)===(r-1|0),g=n===0,_=(l,d,h)=>!ts(t)(Be(d)(h))(Ge(d)(h))(l),f=n>=0&&n<e.length?T("Just",e[n]):y;if(f.tag==="Just"){const l=n+2|0,d=l>=0&&l<e.length?T("Just",e[l]):y;if(d.tag==="Just"){const h=f._1.start._1===d._1.end._1&&(!g||f._1.direction==="V")&&(!u||d._1.direction==="V")&&o(f._1.start._1,f._1.start._2,d._1.end._2)?T("Just",[...s,{start:f._1.start,end:d._1.end,direction:Ne},...a]):f._1.start._2===d._1.end._2&&(!g||f._1.direction==="H")&&(!u||d._1.direction==="H")&&_(f._1.start._2,f._1.start._1,d._1.end._1)?T("Just",[...s,{start:f._1.start,end:d._1.end,direction:Te},...a]):y,m=(!g||f._1.direction==="V")&&(!u||d._1.direction==="H")&&o(f._1.start._1,f._1.start._2,d._1.end._2)&&_(d._1.end._2,f._1.start._1,d._1.end._1)?T("Just",[...s,{start:f._1.start,end:E(f._1.start._1,d._1.end._2),direction:Ne},{start:E(f._1.start._1,d._1.end._2),end:d._1.end,direction:Te},...a]):y,p=(!g||f._1.direction==="H")&&(!u||d._1.direction==="V")&&_(f._1.start._2,f._1.start._1,d._1.end._1)&&o(d._1.end._1,f._1.start._2,d._1.end._2)?T("Just",[...s,{start:f._1.start,end:E(d._1.end._1,f._1.start._2),direction:Te},{start:E(d._1.end._1,f._1.start._2),end:d._1.end,direction:Ne},...a]):y,x=m.tag==="Nothing"?p:m;return h.tag==="Nothing"?x:h}if(d.tag==="Nothing")return y;c()}if(f.tag==="Nothing")return y;c()},NC=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=TC(t)(e)(s)(n);if(u.tag==="Just"){i=!1,a=u._1;continue}if(u.tag==="Nothing"){o=s+1|0;continue}c()}return a})(0)},bC=t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const a=r,s=Za(Ya(wC(t)(NC(t)(a))));if(s.length<a.length){r=s;continue}o=!1,i=s}return i};return n=>e(Za(Ya(n)))},vC=t=>e=>n=>r=>{const o=Be(n)(r),i=Ge(n)(r),a=_t(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Rt(g=>_=>at.compare(g.x)(_.x))(a);return 0<u.length?u[0].x-1:(n+r)/2}const s=Rt(u=>g=>at.compare(g.x)(u.x))(K(u=>({...u,x:u.x+u.w}))(a));return 0<s.length?s[0].x+1:(n+r)/2},CC=t=>e=>n=>r=>{const o=Be(n)(r),i=Ge(n)(r),a=_t(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Rt(g=>_=>at.compare(g.y)(_.y))(a);return 0<u.length?u[0].y-1:(n+r)/2}const s=Rt(u=>g=>at.compare(g.y)(u.y))(K(u=>({...u,y:u.y+u.h}))(a));return 0<s.length?s[0].y+1:(n+r)/2},LC=t=>e=>n=>r=>{const o=Be(n)(r),i=Ge(n)(r),a=_t(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Rt(g=>_=>at.compare(_.x)(g.x))(K(g=>({...g,x:g.x+g.w}))(a));return 0<u.length?u[0].x:(n+r)/2}const s=Rt(u=>g=>at.compare(u.x)(g.x))(a);return 0<s.length?s[0].x-1:(n+r)/2},kC=t=>e=>n=>r=>{const o=Be(n)(r),i=Ge(n)(r),a=_t(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Rt(g=>_=>at.compare(_.y)(g.y))(K(g=>({...g,y:g.y+g.h}))(a));return 0<u.length?u[0].y:(n+r)/2}const s=Rt(u=>g=>at.compare(u.y)(g.y))(a);return 0<s.length?s[0].y-1:(n+r)/2},Ph=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,g=o,_=i;if(_>100){a=!1,s=g;continue}if(!u(g+_)){a=!1,s=g+_;continue}if(!u(g-_)){a=!1,s=g-_;continue}r=u,o=g,i=_+1}return s},Bh=t=>e=>n=>r=>o=>{const i=Be(e)(n),a=Ge(e)(n);if(!Ka(i)(a)(r)(t))return r;if(!Ka(i)(a)(o)(t))return o;const s=(r+o)/2;return Ka(i)(a)(s)(t)?Ph(u=>Ka(i)(a)(u)(t))(s)(1):s},SC=t=>e=>n=>r=>o=>{const i=Be(e)(n),a=Ge(e)(n);if(!ja(i)(a)(r)(t))return r;if(!ja(i)(a)(o)(t))return o;const s=(r+o)/2;return ja(i)(a)(s)(t)?Ph(u=>ja(i)(a)(u)(t))(s)(1):s},EC=t=>e=>n=>r=>{const o=Be(e)(n),i=Ge(e)(n),a=_t(g=>r>=g.x&&r<g.x+g.w&&g.y+g.h>o&&g.y<i,t),s=b(g=>_=>Ge(g)(_.x+_.w+4))(r+4)(a),u=b(g=>_=>Be(g)(_.x-4))(r-4)(a);return(()=>{const g=s-r,_=u-r;return(g<0?-g:g)<=(_<0?-_:_)})()?s:u},RC=t=>e=>n=>r=>{const o=Be(e)(n),i=Ge(e)(n),a=_t(g=>r>=g.y&&r<g.y+g.h&&g.x+g.w>o&&g.x<i,t),s=b(g=>_=>Ge(g)(_.y+_.h+4))(r+4)(a),u=b(g=>_=>Be(g)(_.y-4))(r-4)(a);return(()=>{const g=s-r,_=u-r;return(g<0?-g:g)<=(_<0?-_:_)})()?s:u},PC=t=>e=>n=>r=>o=>i=>a=>{const s=(()=>{if(r==="South")return E(o._1,o._2+4);if(r==="North")return E(o._1,o._2-4);if(r==="East")return E(o._1+4,o._2);if(r==="West")return E(o._1-4,o._2);c()})(),u=(()=>{if(i==="South")return E(a._1,a._2+4);if(i==="North")return E(a._1,a._2-4);if(i==="East")return E(a._1+4,a._2);if(i==="West")return E(a._1-4,a._2);c()})(),g=(L,C,R)=>!Du(e)(Be(C)(R))(Ge(C)(R))(L),_=(L,C,R)=>!Du(n)(Be(C)(R))(Ge(C)(R))(L),f=(L,C,R,P)=>t.tag==="Just"&&!ts(n)(Be(L)(C))(Ge(L)(C))(t._1)?t._1:SC(e)(L)(C)(R)(P),l=(L,C,R,P)=>{if(L===R){const U=EC(e)(C)(P)(L),S=CC(e)(L)(C)(P),v=kC(e)(L)(C)(P);return[{start:E(L,C),end:E(L,S),direction:Ne},{start:E(L,S),end:E(U,S),direction:Te},{start:E(U,S),end:E(U,v),direction:Ne},{start:E(U,v),end:E(R,v),direction:Te},{start:E(R,v),end:E(R,P),direction:Ne}]}const I=f(L,R,C,P);return[{start:E(L,C),end:E(L,I),direction:Ne},{start:E(L,I),end:E(R,I),direction:Te},{start:E(R,I),end:E(R,P),direction:Ne}]},d=(L,C,R,P)=>{if(C===P){const U=RC(e)(L)(R)(C),S=vC(e)(C)(L)(R),v=LC(e)(C)(L)(R);return[{start:E(L,C),end:E(S,C),direction:Te},{start:E(S,C),end:E(S,U),direction:Ne},{start:E(S,U),end:E(v,U),direction:Te},{start:E(v,U),end:E(v,P),direction:Ne},{start:E(v,P),end:E(R,P),direction:Te}]}const I=Bh(e)(C)(P)(L)(R);return[{start:E(L,C),end:E(I,C),direction:Te},{start:E(I,C),end:E(I,P),direction:Ne},{start:E(I,P),end:E(R,P),direction:Te}]},h=(L,C,R)=>!ts(e)(Be(C)(R))(Ge(C)(R))(L),m=(L,C,R)=>!ts(n)(Be(C)(R))(Ge(C)(R))(L),p=(L,C,R,P)=>{if(m(C,L,R)&&_(R,C,P))return[{start:E(L,C),end:E(R,C),direction:Te},{start:E(R,C),end:E(R,P),direction:Ne}];const I=Bh(e)(C)(P)(L)(R);return[{start:E(L,C),end:E(I,C),direction:Te},{start:E(I,C),end:E(I,P),direction:Ne},{start:E(I,P),end:E(R,P),direction:Te}]},x=(L,C,R,P)=>{if(_(L,C,P)&&m(P,L,R))return[{start:E(L,C),end:E(L,P),direction:Ne},{start:E(L,P),end:E(R,P),direction:Te}];const I=f(L,R,C,P);return[{start:E(L,C),end:E(L,I),direction:Ne},{start:E(L,I),end:E(R,I),direction:Te},{start:E(R,I),end:E(R,P),direction:Ne}]},J=(()=>{if(r==="South")return i==="North"?s._1===u._1&&g(s._1,s._2,u._2)?[{start:E(s._1,s._2),end:E(u._1,u._2),direction:Ne}]:l(s._1,s._2,u._1,u._2):i==="East"||i==="West"?x(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&&g(s._1,s._2,u._2)?[{start:E(s._1,s._2),end:E(u._1,u._2),direction:Ne}]:l(s._1,s._2,u._1,u._2):i==="East"||i==="West"?x(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:E(s._1,s._2),end:E(u._1,u._2),direction:Te}]:d(s._1,s._2,u._1,u._2):i==="North"||i==="South"?p(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:E(s._1,s._2),end:E(u._1,u._2),direction:Te}]:d(s._1,s._2,u._1,u._2);if(i==="North"||i==="South")return p(s._1,s._2,u._1,u._2)}return l(s._1,s._2,u._1,u._2)})(),w=(()=>{if(r==="South"||r==="North")return Ne;if(r==="East"||r==="West")return Te;c()})(),N={start:E(u._1,u._2),end:E(a._1,a._2),direction:(()=>{if(i==="South"||i==="North")return Ne;if(i==="East"||i==="West")return Te;c()})()};return s._1===u._1&&s._2===u._2?[{start:E(o._1,o._2),end:E(a._1,a._2),direction:w}]:xC({start:E(o._1,o._2),end:E(s._1,s._2),direction:w})(J)(N)},BC=K(t=>({x:t.position._1*Fu-2,y:t.position._2*Fu-2,w:t.size._1*Fu+4,h:t.size._2*Fu+4})),Gh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},fa=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},GC=(()=>{const t=gn.unfoldr(jn);return e=>t(cn("IterNode",e,Yn))})(),P_=t=>e=>t.gapTop+1*ot(4)+ot(e)*2.5*ot(4),AC=t=>e=>{const n=Gh(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return T("Just",{slot1Y:P_(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:P_(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return y;c()}if(n.tag==="Nothing")return y;c()},IC=t=>e=>{const n=b(r=>o=>it(G)(o.node)(o)(r))(W)(e);return kn(Ft(r=>o=>{const i=fa(o.node)(n);if(i.tag==="Nothing")return[];if(i.tag==="Just"){const a=i._1;return Ft(s=>u=>{const g=o.edges.length,_=ot(4),f=a.position._1*_,l=a.position._2*_,d=a.size._2*_,h=ot((2*g|0)+1|0),m=l+d*ot(g-s|0)/h,p=l+d*ot((g+1|0)+s|0)/h,x=f-_*2.5*ot(s+1|0),J=[{start:E(f,m),end:E(x,m),direction:Te},{start:E(x,m),end:E(x,p),direction:Ne},{start:E(x,p),end:E(f,p),direction:Te}];return{edge:u.id,segments:J,bends:We(w=>N=>w.end,J,At(1,3,J)),bendType:[],jumps:[],reversed:!1}})(o.edges)}c()})(K(r=>({node:r._1,edges:r._2}))(GC(b(r=>o=>Wt(G)(Je)(o.from.node)([o])(r))(W)(t)))))},zC=t=>e=>{const n=b(i=>a=>it(G)(a.node)(a)(i))(W)(e),r=i=>{const a=fa(i)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1.position._1;c()},o=i=>{const a=fa(i)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1.layer;c()};return Rt(i=>a=>{const s=ut.compare(o(i.edge.from.node))(o(a.edge.from.node));if(s==="EQ"){const u=at.compare(r(i.edge.from.node))(r(a.edge.from.node));return u==="EQ"?at.compare(r(i.edge.to.node))(r(a.edge.to.node)):u}return s})(t)},Nn=t=>{const e=ot(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}},DC=t=>t.from.node===t.to.node,FC=t=>e=>n=>r=>{const o=bC(n)(PC(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,At(1,o.length,o)),bendType:[],jumps:[],reversed:!1}},MC=t=>e=>n=>r=>{const o=[{start:E(r.fromPos._1,r.fromPos._2),end:E(r.fromPos._1,t.slot1Y),direction:Ne},{start:E(r.fromPos._1,t.slot1Y),end:E(t.splitX,t.slot1Y),direction:Te},{start:E(t.splitX,t.slot1Y),end:E(t.splitX,t.slot2Y),direction:Ne},{start:E(t.splitX,t.slot2Y),end:E(r.toPos._1,t.slot2Y),direction:Te},{start:E(r.toPos._1,t.slot2Y),end:E(r.toPos._1,r.toPos._2),direction:Ne}];return{edge:r.edge.id,segments:o,bends:We(i=>a=>i.end,o,At(1,5,o)),bendType:[],jumps:[],reversed:!1}},QC=t=>e=>n=>{const r=fa(t.edge.from.node)(n);if(r.tag==="Just"){const i=fa(t.edge.to.node)(n);return i.tag==="Just"?_t(a=>!(a.h===Nn(r._1).h&&a.w===Nn(r._1).w&&a.x===Nn(r._1).x&&a.y===Nn(r._1).y)&&!(a.h===Nn(i._1).h&&a.w===Nn(i._1).w&&a.x===Nn(i._1).x&&a.y===Nn(i._1).y),e):_t(a=>!(a.h===Nn(r._1).h&&a.w===Nn(r._1).w&&a.x===Nn(r._1).x&&a.y===Nn(r._1).y),e)}const o=fa(t.edge.to.node)(n);return o.tag==="Just"?_t(i=>!(i.h===Nn(o._1).h&&i.w===Nn(o._1).w&&i.x===Nn(o._1).x&&i.y===Nn(o._1).y),e):_t(i=>!0,e)},WC=t=>e=>{const n=Gh(e.edge.id)(t);if(n.tag==="Just")return T("Just",P_(n._1)(n._1.slot));if(n.tag==="Nothing")return y;c()},OC=t=>e=>n=>r=>o=>{const i=b(g=>_=>it(G)(_.node)(_)(g))(W)(e),a=BC(e),s=fh(_t(g=>g.from.node!==g.to.node,t))(e)(n)(r)(o),u=sh(s)(e);return[...IC(_t(DC,t))(e),...b(g=>_=>{const f=QC(_)(a)(i),l=[...f,...g.edgeObstacles],d=AC(u)(_),h=(()=>{if(d.tag==="Just")return MC(d._1)(f)(l)(_);if(d.tag==="Nothing")return FC(WC(u)(_))(f)(l)(_);c()})();return{results:[...g.results,h],edgeObstacles:[...g.edgeObstacles,...yC(h.segments)]}})({results:[],edgeObstacles:[]})(zC(s)(e)).results]},bo=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},vo=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},HC=t=>e=>n=>{if(t.start._1!==e.start._1)return y;const r=vo(bo(t.start._2)(t.end._2))(bo(e.start._2)(e.end._2)),o=bo(vo(t.start._2)(t.end._2))(vo(e.start._2)(e.end._2));return r<o?T("Just",{position:E(t.start._1,(r+o)/2),crossingEdge:n}):y},$C=t=>e=>n=>{if(t.start._2!==e.start._2)return y;const r=vo(bo(t.start._1)(t.end._1))(bo(e.start._1)(e.end._1)),o=bo(vo(t.start._1)(t.end._1))(vo(e.start._1)(e.end._1));return r<o?T("Just",{position:E((r+o)/2,t.start._2),crossingEdge:n}):y},qC=t=>e=>n=>{if(t.direction==="H")return $C(t)(e)(n);if(t.direction==="V")return HC(t)(e)(n);c()},VC=t=>e=>n=>{const r=t+1|0,o=r<1?n:At(r,n.length,n);return St(e.segments)(i=>St(o)(a=>ht(s=>qC(i)(s)(a.edge))(_t(s=>s.direction==="H"?i.direction==="H":s.direction==="V"&&i.direction==="V",a.segments))))},UC=t=>e=>n=>e.start._1>bo(t.start._1)(t.end._1)&&e.start._1<vo(t.start._1)(t.end._1)&&t.start._2>bo(e.start._2)(e.end._2)&&t.start._2<vo(e.start._2)(e.end._2)?T("Just",{position:E(e.start._1,t.start._2),crossingEdge:n}):y,XC=t=>e=>St(_t(n=>n.direction==="H",t.segments))(n=>St(e)(r=>ht(o=>UC(n)(o)(r.edge))(_t(o=>o.direction==="V",r.segments)))),KC=t=>e=>n=>[...XC(e)(_t(r=>r.edge!==e.edge,n)),...VC(t)(e)(n)],Ah=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},YC=b(t=>e=>it(G)(e)()(t))(W),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 a=G.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}}c()}return o},ZC=Yd(G),Qr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Ih=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},B_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},jC=fe(ut)(Qt),t3=t=>e=>nn(G.compare,tn,t,e),zh=Ft(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),e3=t=>b(e=>n=>({base:(()=>{const r=o=>i=>{let a=o,s=i,u=!0,g;for(;u;){const _=a,f=s;if(f.tag==="Nil"){u=!1,g=_;continue}if(f.tag==="Cons"){a=Ah(_)(f._1),s=f._2;continue}c()}return g};return(e.base+r(0)((()=>{const o=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return o(i._5,Jt("Cons",i._4,o(i._6,a)));c()};return o(n,A)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=o=>{if(o.tag==="Leaf")return W;if(o.tag==="Node")return ee("Node",o._1,o._2,o._3,o._4+e.base|0,r(o._5),r(o._6));c()};return r(n)})()]}))({base:0,result:[]})(t).result,n3=t=>e=>{const n=YC(t);return ZC(t)(zh(_t(r=>Mu(r.src)(n)&&Mu(r.tgt)(n),e)))},r3=t=>e=>{const n=b(o=>i=>Wt(G)(Je)(i.tgt)([i.src])(Wt(G)(Je)(i.src)([i.tgt])(o)))(W)(e),r=o=>i=>a=>{let s=o,u=i,g=a,_=!0,f;for(;_;){const l=s,d=u,h=g,m=Bt(p=>y,p=>x=>T("Just",{head:p,tail:x}),l);if(m.tag==="Nothing"){_=!1,f={nodes:h};continue}if(m.tag==="Just"){if(Mu(m._1.head)(d)){s=m._1.tail,u=d,g=h;continue}s=[...m._1.tail,...(()=>{const p=Qr(m._1.head)(n);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;c()})()],u=it(G)(m._1.head)()(d),g=[...h,m._1.head];continue}c()}return f};return b(o=>i=>{if(Mu(i)(o.visited))return o;const a=r([i])(o.visited)([]);return{...o,visited:b(s=>u=>it(G)(u)()(s))(o.visited)(a.nodes),components:[...o.components,a.nodes]}})({visited:W,components:[]})(t).components},o3=t=>e=>n=>{const r=b(i=>a=>Wt(G)(ve)(a.tgt)(1)(i))(W)(e),o=b(i=>a=>Wt(G)(ve)(a.src)(1)(i))(W)(e);return b(i=>a=>{const s=Qr(a)(r),u=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})();if((()=>{const J=Qr(a)(o);return(()=>{if(J.tag==="Nothing")return u!==0;if(J.tag==="Just")return u!==J._1;c()})()||u===0})())return i;const g=Qr(a)(i.layers),_=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;c()})(),f=i.layers,l=b(J=>w=>w.tgt===a?{...J,mIn:Ih(J.mIn)((()=>{const N=Qr(a)(f),L=Qr(w.src)(f);return(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})()-(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;c()})()|0})())}:w.src===a?{...J,mOut:Ih(J.mOut)((()=>{const N=Qr(w.tgt)(f),L=Qr(a)(f);return(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})()-(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;c()})()|0})())}:J)({mIn:1e9,mOut:1e9})(e),d=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(d<0||h<0)return i;const m=(_-d|0)+1|0,p=(_+h|0)-1|0;if(p<m)return i;const x=b(J=>w=>{const N=B_(w)(i.filling),L=(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})();return L<J.bestFill?{best:w,bestFill:L}:J})({best:_,bestFill:(()=>{const J=B_(_)(i.filling);if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;c()})()})(Ut(m,p));return x.best===_?i:{layers:it(G)(a)(x.best)(i.layers),filling:it(ut)(_)((()=>{const J=B_(_)(i.filling);if(J.tag==="Nothing")return-1;if(J.tag==="Just")return J._1-1|0;c()})())(it(ut)(x.best)(x.bestFill+1|0)(i.filling))}})({layers:n,filling:jC(K(i=>E(i,b(a=>s=>(()=>{const u=Qr(s)(n);return u.tag==="Nothing"?!1:u.tag==="Just"&&u._1===i})()?a+1|0:a)(0)(t)))(Ut(0,b(i=>a=>Ah(i)((()=>{const s=Qr(a)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(0)(t))))})(t).layers},i3=t=>e=>o3(t)(zh(e))(b(t3)(W)(e3(K(n=>n3(n)(e))(r3(t)(e))))),a3=t=>t,ci=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Qu=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Dh=(()=>{const t=gn.unfoldr(jn);return e=>t(cn("IterNode",e,Yn))})(),s3=a3("NetworkSimplex"),u3=t=>e=>b(n=>r=>{const o=b(Qu)(0)(ht(i=>ci(i)(n))(r));return b(i=>a=>it(G)(a)(o)(i))(n)(r)})(e)(t),g3=t=>e=>({layers:K(n=>_t(r=>{const o=ci(r)(e);return o.tag==="Nothing"?!1:o.tag==="Just"&&o._1===n},t))(Ut(0,(n=>r=>{let o=n,i=r,a=!0,s;for(;a;){const u=o,g=i;if(g.tag==="Nil"){a=!1,s=u;continue}if(g.tag==="Cons"){o=Qu(u)(g._1),i=g._2;continue}c()}return s})(0)((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Jt("Cons",r._4,n(r._6,o)));c()};return n(e,A)})()))),nodeLayer:e}),c3=t=>e=>n=>{const r=b(o=>i=>it(G)(i)(!0)(o))(W)(e);return b(o=>i=>it(G)(i._1)(i._2)(o))(i3(e)(ht(o=>o.from.node===o.to.node||(()=>{const i=ci(o.from.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;c()})()||(()=>{const i=ci(o.to.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;c()})()?y:T("Just",{src:o.from.node,tgt:o.to.node}))(t)))(Dh(n))},_3=t=>e=>n=>r=>{const o=s=>u=>{const g=ci(u)(s);if(g.tag==="Just")return s;if(g.tag==="Nothing"){const _=_t(l=>l!==u,(()=>{const l=ci(u)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;c()})()),f=b(o)(s)(_);return it(G)(u)(1+b(Qu)(0)(ht(l=>ci(l)(f))(_))|0)(f)}c()},i=b(o)(W)(n),a=(s=>u=>{let g=s,_=u,f=!0,l;for(;f;){const d=g,h=_;if(h.tag==="Nil"){f=!1,l=d;continue}if(h.tag==="Cons"){g=Qu(d)(h._1),_=h._2;continue}c()}return l})(1)((()=>{const s=(u,g)=>{if(u.tag==="Leaf")return g;if(u.tag==="Node")return s(u._5,Jt("Cons",u._4,s(u._6,g)));c()};return s(i,A)})());return b(s=>u=>it(G)(u._1)(u._2)(s))((()=>{const s=u=>{if(u.tag==="Leaf")return W;if(u.tag==="Node")return ee("Node",u._1,u._2,u._3,a-u._4|0,s(u._5),s(u._6));c()};return s(i)})())(Dh(r))},f3=b(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return it(G)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return it(G)(e._1.node)(0)(t)}return t})(W),l3=b(t=>e=>Wt(G)(Je)(e.to.node)([e.from.node])(t))(W),d3=b(t=>e=>Wt(G)(Je)(e.from.node)([e.to.node])(t))(W),h3=t=>e=>n=>r=>{const o=d3(n),i=l3(n),a=f3(e);return g3(r)(u3(ht(s=>s.tag==="SameLayer"?T("Just",s._1.nodes):y)(e))((()=>{if(t==="LongestPath")return _3(o)(i)(r)(a);if(t==="NetworkSimplex")return c3(n)(r)(a);c()})()))},p3=fe(G)(Qt),m3=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Fh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Mh=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},es=fe(G)(Qt),y3=fe(G)(Qt),Qh=(()=>{const t=K(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>re(t(e))})(),x3=t=>e=>n=>r=>{const o=p3(K(a=>E(a.edge,a))(r)),i=a=>0<a.nodes.length&&(()=>{const s=m3(a.edgeId)(n);return s.tag==="Just"&&a.nodes[0]!==s._1._1})();return K(a=>{if(a.nodes.length<=2){const _=Fh(a.edgeId)(o);if(_.tag==="Just"){const f=i(a),l=Za(Ya(f?Qh(_._1.segments):_._1.segments));return{..._._1,edge:a.edgeId,segments:l,bends:We(d=>h=>d.end,l,At(1,l.length,l)),reversed:f}}if(_.tag==="Nothing")return{edge:a.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};c()}const s=St(ht(_=>Fh(_)(o))(We(_=>f=>a.edgeId+":"+_+"->"+f,a.nodes,At(1,a.nodes.length,a.nodes))))(_=>_.segments),u=i(a),g=Za(Ya(u?Qh(s):s));return{edge:a.edgeId,segments:g,bends:We(_=>f=>_.end,g,At(1,g.length,g)),bendType:[],jumps:[],reversed:u}})(t)},J3={layers:[],edges:[],chains:[]},Wh={nodeGap:3,layerGap:2,iterations:8,layerer:s3,cycleBreaker:_C,compactPostRouting:!0,compactionSpacings:lv},w3=t=>({pos:E(0,0),size:E(b(e=>n=>Mh(e)(n.position._1+n.size._1))(0)(t),b(e=>n=>Mh(e)(n.position._2+n.size._2))(0)(t))}),T3=t=>e=>n=>{const r=es(K(g=>E(g.id,g.ports))(e.nodes)),o=_t(g=>Ve(3)(g.node)!=="$d:",n.placements),i=x3(n.withDummies.chains)(n.acyclic.reversedEdges)(y3(K(g=>E(g.id,E(g.from.node,g.to.node)))(e.edges)))(OC(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(dh(n.ordered)(_t(g=>g.from.node!==g.to.node,n.withDummies.edges))((()=>{const g=_=>{if(_.tag==="Leaf")return W;if(_.tag==="Node")return ee("Node",_._1,_._2,_._3,E(_._4._1*4,_._4._2),g(_._5),g(_._6));c()};return g(es(K(_=>E(_.id,_.size))(e.nodes)))})()))),a=t.compactPostRouting?pv()(t.compactionSpacings)({nodes:o,edges:e.edges,paths:i,ports:r}):{nodes:o,edges:i},s=K(g=>{const _=Za(Ya(g.segments));return{...g,segments:_,bends:We(f=>l=>f.end,_,At(1,_.length,_))}})(a.edges),u=Ft(g=>_=>({..._,jumps:KC(g)(_)(s)}))(s);return{nodes:a.nodes,edges:u,boundingBox:w3(a.nodes),metrics:WN(a.nodes)(u)(0)}},Oh=t=>e=>n=>{const r=es(K(i=>E(i.id,i.size))(e.nodes)),o={...n,placements:Uv({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(es(K(i=>E(i.id,i.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(dh(n.ordered)(n.withDummies.edges)((()=>{const i=a=>{if(a.tag==="Leaf")return W;if(a.tag==="Node")return ee("Node",a._1,a._2,a._3,E(a._4._1*4,a._4._2),i(a._5),i(a._6));c()};return i(r)})()))};return{pipeline:o,result:T3(t)(e)(o)}},N3=t=>e=>n=>Oh(t)(e)({...n,ordered:sC({iterations:t.iterations,constraints:e.constraints,modelOrder:es(Ft(r=>o=>E(o.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),b3=t=>e=>n=>N3(t)(e)({...n,withDummies:mv(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),Hh=t=>e=>{const n=K(o=>o.id)(e.nodes),r=mC(t.cycleBreaker)(n)(e.constraints)(e.edges);return b3(t)(e)({acyclic:r,layered:h3(t.layerer)(e.constraints)(r.edges)(n),withDummies:J3,ordered:[],placements:[]})},$h=fe(G)(Qt),la=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Wu=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Co=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},v3=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},C3=t=>e=>n=>{const r=n.result.nodes,o=$h(K(a=>E(a.node,a))(r)),i=n.result.boundingBox.size._1;return $h(ht(a=>{const s=Co(a.id)(o);if(s.tag==="Just"){const u=Co(a.id)(n.pipeline.layered.nodeLayer);if(u.tag==="Just"){const g=u._1,_=Bt(f=>y,f=>l=>T("Just",{head:f,tail:l}),_t(f=>f.length>=2,[ht(f=>{if(f.to.node===a.id){const l=Co(f.from.node)(n.pipeline.layered.nodeLayer);if(l.tag==="Just")return l._1>=g?y:Co(f.from.node)(o);if(l.tag==="Nothing")return y;c()}return y})(e.edges),ht(f=>{if(f.from.node===a.id){const l=Co(f.to.node)(n.pipeline.layered.nodeLayer);if(l.tag==="Just")return l._1<=g?y:Co(f.to.node)(o);if(l.tag==="Nothing")return y;c()}return y})(e.edges)]));if(_.tag==="Just"){const f=Wu(b(la)((()=>{const m=Bt(p=>y,p=>x=>T("Just",{head:p,tail:x}),K(p=>p.position._1+p.size._1*.5)(_._1.head));if(m.tag==="Nothing")return a.size._1;if(m.tag==="Just")return la(a.size._1)(b(la)(m._1.head)(m._1.tail)-b(Wu)(m._1.head)(m._1.tail)+2);c()})())(K(m=>{const p=Bt(x=>y,x=>J=>T("Just",{head:x,tail:J}),K(x=>x.position._1+x.size._1*.5)(m));if(p.tag==="Nothing")return a.size._1;if(p.tag==="Just")return la(a.size._1)(b(la)(p._1.head)(p._1.tail)-b(Wu)(p._1.head)(p._1.tail)+2);c()})(_._1.tail)))(a.size._1+ot(b(v3)(_._1.head.length)(K(ay)(_._1.tail))-1|0)),l=s._1.position._1,d=l+s._1.size._1,h=_t(m=>{const p=Co(m.node)(n.pipeline.layered.nodeLayer);return m.node!==a.id&&(p.tag==="Nothing"?!1:p.tag==="Just"&&p._1===g)},r);return f>a.size._1+.5&&f<=b(m=>p=>p.position._1>=d?Wu(m)(p.position._1-ot(t.nodeGap)):m)(i)(h)-b(m=>p=>p.position._1+p.size._1<=l?la(m)(p.position._1+p.size._1+ot(t.nodeGap)):m)(0)(h)?T("Just",E(a.id,E(f,a.size._2))):y}if(_.tag==="Nothing")return y;c()}if(u.tag==="Nothing")return y;c()}if(s.tag==="Nothing")return y;c()})(e.nodes))},L3=t=>e=>{const n=Hh(t)(e),r=C3(t)(e)(n),o=Oh(t)({...e,nodes:K(i=>{const a=Co(i.id)(r);if(a.tag==="Just")return{...i,size:a._1};if(a.tag==="Nothing")return i;c()})(e.nodes)})(n.pipeline);return r.tag==="Leaf"?n:o},k3=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},da=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},S3=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},qh=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},E3=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Vh=t=>An(re(Pr(e=>e===" ")(re(Pr(e=>e===" ")(tr(t)).rest)).rest)),R3=t=>b(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?T("Just",n._1):e)(y)(Ft(mn)(t)),G_=t=>e=>{if(t<=0)return[e];if(zn(e)<=t)return[e];const n=tr(e),r=t<1?[]:At(0,t,n),o=R3(r);if(o.tag==="Just"){const i=Vh(Ef(!(o._1>=0&&o._1<r.length)||r[o._1]===" "?o._1:o._1+1|0)(e)),a=Vh(Qi(o._1+1|0)(e));return a===""?[i]:[i,...G_(t)(a)]}if(o.tag==="Nothing"){const i=Ef(t)(e),a=Qi(t)(e);return a===""?[i]:[i,...G_(t)(a)]}c()},P3={cellW:7,cellH:3,maxLineWidth:20},B3=t=>e=>{const n=K(i=>E((()=>{if(i.label.tag==="Just")return i.label._1;if(i.label.tag==="Nothing")return i.id;c()})(),i))(e.nodes),r=da(1)(Sr((S3(t.maxLineWidth)(b(i=>a=>da(i)(zn(a._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),o=(r*t.cellW|0)-1|0;return{...e,nodes:K(i=>{const a=St($i(`
|
|
7
|
+
`)(i._1))(G_(o)),s=b(f=>l=>da(f)(zn(l)))(0)(a),u=da(1)(Sr(a.length+t.cellH|0,t.cellH))+(i._2.shape==="Cylinder"||i._2.shape==="Document"?1:0)|0,g=i._2.shape==="Cylinder"?da(1)(Sr((s+2|0)+t.cellW|0,t.cellW)):r,_=s>o?Sr((s+2|0)+t.cellW|0,t.cellW):g;return{...i._2,size:E(i._2.size._1!==1?qh(i._2.size._1)(ot(_)):ot(_),i._2.size._2!==1?i._2.size._2:ot(u))}})(n)}},G3=t=>e=>n=>({...n,nodes:K(r=>{const o=E3(r.id)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just")return{...r,size:E(qh(r.size._1)(ot(da(1)(he(Cs(r.shape==="Cylinder"?(o._1+0)/t:(o._1+32)/t))))),r.size._2)};c()})(n.nodes)}),Ou=t=>t,A3=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},_i=Ou("TopSide"),fi=Ou("BottomSide"),li=Ou("LeftSide"),di=Ou("RightSide"),I3=t=>{const e=at.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;c()})(),r=at.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;c()},Uh=t=>e=>n=>{const r=A3(t.h*.12)(t.w*.2),o=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*qe(I3((()=>{const i=(n-(t.x+o))/o;return 1-i*i})()))},bn=t=>e=>n=>r=>{let o=t,i=e,a=n,s=r,u=!0,g;for(;u;){const _=o,f=i,l=a,d=s;if(_==="Rectangle"){if(l==="TopSide"){u=!1,g=f.y;continue}if(l==="BottomSide"){u=!1,g=f.y+f.h;continue}if(l==="LeftSide"){u=!1,g=f.x;continue}if(l==="RightSide"){u=!1,g=f.x+f.w;continue}o=ho,i=f,a=l,s=d;continue}if(_==="Cylinder"){if(l==="TopSide"){u=!1,g=Uh(f)(-1)(d);continue}if(l==="BottomSide"){u=!1,g=Uh(f)(1)(d);continue}if(l==="LeftSide"){u=!1,g=f.x;continue}if(l==="RightSide"){u=!1,g=f.x+f.w;continue}}o=ho,i=f,a=l,s=d}return g},Xh=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),g=u<0?-u:u;return r<=g&&r<=s&&r<=i?_i:g<=s&&g<=i?fi:s<=i?li:di},z3=(()=>{const t=gn.unfoldr(jn);return e=>t(cn("IterNode",e,Yn))})(),A_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},hi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},ns=fe(G)(Qt),oo=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},pi=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},I_=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},D3=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=G.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}}c()}return o},F3=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=G.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}}c()}return o},M3=b(t=>e=>it(G)(e)()(t))(W),Q3=b(t=>e=>it(G)(e)()(t))(W),rs=xr.traverse(Ig),os=fe(G)(Qt),W3=t=>e=>nn(G.compare,tn,t,e),O3=b(t=>e=>it(G)(e)()(t))(W),H3=fe(G)(Qt),$3=t=>e=>nn(G.compare,tn,t,e),q3=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},V3=t=>e=>{const n=ns(K(r=>E(r._1,(()=>{const o=A_(r._1)(t);if(o.tag==="Nothing")return r._2;if(o.tag==="Just"){const i=hi(o._1._2)(e.nodes),a=hi(o._1._1)(e.nodes),s=(()=>{if(a.tag==="Nothing")return r._2;if(a.tag==="Just"){const u=Bt(g=>y,g=>_=>T("Just",{head:g,tail:_}),r._2);if(u.tag==="Nothing")return r._2;if(u.tag==="Just")return[(()=>{const g=Bt(d=>y,d=>h=>T("Just",{head:d,tail:h}),u._1.tail),_=g.tag==="Just"?T("Just",g._1.head):y,f={x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h},l=(()=>{if(_.tag==="Just"){if((_._1.x>u._1.head.x?_._1.x-u._1.head.x<.5:u._1.head.x-_._1.x<.5)&&u._1.head.x>=f.x-.5&&u._1.head.x<=f.x+f.w+.5)return _._1.y>=f.y+f.h?T("Just",fi):_._1.y<=f.y?T("Just",_i):y;if((_._1.y>u._1.head.y?_._1.y-u._1.head.y<.5:u._1.head.y-_._1.y<.5)&&u._1.head.y>=f.y-.5&&u._1.head.y<=f.y+f.h+.5){if(_._1.x>=f.x+f.w)return T("Just",di);if(_._1.x<=f.x)return T("Just",li)}return y}if(_.tag==="Nothing")return y;c()})();if(l.tag==="Just"){if(l._1==="TopSide")return{...u._1.head,y:bn(a._1.shape)(f)(_i)(u._1.head.x)};if(l._1==="BottomSide")return{...u._1.head,y:bn(a._1.shape)(f)(fi)(u._1.head.x)};if(l._1==="LeftSide")return{...u._1.head,x:bn(a._1.shape)(f)(li)(u._1.head.y)};if(l._1==="RightSide")return{...u._1.head,x:bn(a._1.shape)(f)(di)(u._1.head.y)};c()}if(l.tag==="Nothing"){const d={x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h},h=Xh(d)(u._1.head);if(h==="TopSide")return{...u._1.head,y:bn(a._1.shape)(d)(_i)(u._1.head.x)};if(h==="BottomSide")return{...u._1.head,y:bn(a._1.shape)(d)(fi)(u._1.head.x)};if(h==="LeftSide")return{...u._1.head,x:bn(a._1.shape)(d)(li)(u._1.head.y)};if(h==="RightSide")return{...u._1.head,x:bn(a._1.shape)(d)(di)(u._1.head.y)}}c()})(),...u._1.tail]}c()})();if(i.tag==="Nothing")return s;if(i.tag==="Just"){const u=Rr(s);if(u.tag==="Nothing")return s;if(u.tag==="Just")return Et(u._1.init)((()=>{const g=Rr(u._1.init),_=g.tag==="Just"?T("Just",g._1.last):y,f={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},l=(()=>{if(_.tag==="Just"){if((_._1.x>u._1.last.x?_._1.x-u._1.last.x<.5:u._1.last.x-_._1.x<.5)&&u._1.last.x>=f.x-.5&&u._1.last.x<=f.x+f.w+.5)return _._1.y>=f.y+f.h?T("Just",fi):_._1.y<=f.y?T("Just",_i):y;if((_._1.y>u._1.last.y?_._1.y-u._1.last.y<.5:u._1.last.y-_._1.y<.5)&&u._1.last.y>=f.y-.5&&u._1.last.y<=f.y+f.h+.5){if(_._1.x>=f.x+f.w)return T("Just",di);if(_._1.x<=f.x)return T("Just",li)}return y}if(_.tag==="Nothing")return y;c()})();if(l.tag==="Just"){if(l._1==="TopSide")return{...u._1.last,y:bn(i._1.shape)(f)(_i)(u._1.last.x)};if(l._1==="BottomSide")return{...u._1.last,y:bn(i._1.shape)(f)(fi)(u._1.last.x)};if(l._1==="LeftSide")return{...u._1.last,x:bn(i._1.shape)(f)(li)(u._1.last.y)};if(l._1==="RightSide")return{...u._1.last,x:bn(i._1.shape)(f)(di)(u._1.last.y)};c()}if(l.tag==="Nothing"){const d={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},h=Xh(d)(u._1.last);if(h==="TopSide")return{...u._1.last,y:bn(i._1.shape)(d)(_i)(u._1.last.x)};if(h==="BottomSide")return{...u._1.last,y:bn(i._1.shape)(d)(fi)(u._1.last.x)};if(h==="LeftSide")return{...u._1.last,x:bn(i._1.shape)(d)(li)(u._1.last.y)};if(h==="RightSide")return{...u._1.last,x:bn(i._1.shape)(d)(di)(u._1.last.y)}}c()})())}}c()})()))(z3(e.edges)));return{...e,edges:n,bounds:gl(e.nodes)(n)}},U3=t=>{const e=r=>{let o=r,i=!0,a;for(;i;){const s=o,u=b(g=>_=>{if(g.tag==="Just")return g;if(g.tag==="Nothing"){const f=_>=0&&_<s.length?T("Just",s[_]):y;if(f.tag==="Just"){const l=_+1|0,d=l>=0&&l<s.length?T("Just",s[l]):y;if(d.tag==="Just"){const h=_+2|0,m=h>=0&&h<s.length?T("Just",s[h]):y;if(m.tag==="Just"){const p=_+3|0,x=p>=0&&p<s.length?T("Just",s[p]):y;if(x.tag==="Just"){const J=f._1.y===d._1.y&&d._1.x===m._1.x&&m._1.y===x._1.y&&(d._1.x-f._1.x)*(x._1.x-m._1.x)<0&&x._1.x>=pi(f._1.x)(d._1.x)&&x._1.x<=oo(f._1.x)(d._1.x)?T("Just",{x:x._1.x,y:f._1.y}):f._1.x===d._1.x&&d._1.y===m._1.y&&m._1.x===x._1.x&&(d._1.y-f._1.y)*(x._1.y-m._1.y)<0&&x._1.y>=pi(f._1.y)(d._1.y)&&x._1.y<=oo(f._1.y)(d._1.y)?T("Just",{x:f._1.x,y:x._1.y}):y;if(J.tag==="Just"){const w=J._1;return oe(N=>w.x===x._1.x?w.x>N.x&&w.x<N.x+N.w&&oo(pi(w.y)(x._1.y))(N.y)<pi(oo(w.y)(x._1.y))(N.y+N.h):w.y===x._1.y?w.y>N.y&&w.y<N.y+N.h&&oo(pi(w.x)(x._1.x))(N.x)<pi(oo(w.x)(x._1.x))(N.x+N.w):!0,t)?y:T("Just",[...(()=>{const N=_+1|0;return N<1?[]:At(0,N,s)})(),w,x._1,...(()=>{const N=_+4|0;return N<1?s:At(N,s.length,s)})()])}if(J.tag==="Nothing")return y;c()}if(x.tag==="Nothing")return y;c()}if(m.tag==="Nothing")return y;c()}if(d.tag==="Nothing")return y;c()}if(f.tag==="Nothing")return y}c()})(y)(s.length<4?[]:Ut(0,s.length-4|0));if(u.tag==="Nothing"){i=!1,a=s;continue}if(u.tag==="Just"){o=b(g=>_=>{const f=Rr(g);if(f.tag==="Nothing")return[_];if(f.tag==="Just"){if(f._1.last.x===_.x&&f._1.last.y===_.y)return g;const l=f._1.init.length-1|0;return l>=0&&l<f._1.init.length&&(f._1.init[l].x===f._1.last.x&&f._1.last.x===_.x||f._1.init[l].y===f._1.last.y&&f._1.last.y===_.y)?Et(f._1.init)(_):Et(g)(_)}c()})([])(u._1);continue}c()}return a},n=b(r=>o=>{const i=Rr(r);if(i.tag==="Nothing")return[o];if(i.tag==="Just"){if(i._1.last.x===o.x&&i._1.last.y===o.y)return r;const a=i._1.init.length-1|0;return a>=0&&a<i._1.init.length&&(i._1.init[a].x===i._1.last.x&&i._1.last.x===o.x||i._1.init[a].y===i._1.last.y&&i._1.last.y===o.y)?Et(i._1.init)(o):Et(r)(o)}c()})([]);return r=>e(n(r))},X3=t=>e=>n=>{const r=te(o=>o.id===n)(t.graph.edges);if(r.tag==="Just")return T("Just",r._1);if(r.tag==="Nothing")return A_(n)(e);c()},K3=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=hi(r.node)(e);if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return r.node;c()})(),shape:(()=>{const o=hi(r.node)(n);if(o.tag==="Nothing")return ho;if(o.tag==="Just")return o._1;c()})()}),Y3=t=>({id:t,size:E(1,1),ports:[],label:T("Just",t),shape:ho}),Kh=t=>e=>n=>{const r=ht(i=>hi(e)(i.labels))(t.keyframes),o=Bt(i=>y,i=>a=>T("Just",{head:i,tail:a}),r);if(o.tag==="Nothing")return[n];if(o.tag==="Just")return[n,...r];c()},Z3=t=>e=>n=>r=>E(r.node,K3(t)(e)(n)(r)),Yh=t=>wn(t),Zh=t=>{const e=$i(`
|
|
8
|
+
`)(t),n=e.length===0?[""]:e;return n.length*I_(1)(b(r=>o=>I_(r)(zn(o)))(0)(n))|0},j3=t=>{const e=Bt(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return"";if(e.tag==="Just")return b(n=>r=>Zh(r)>Zh(n)?r:n)(e._1.head)(e._1.tail);c()},tL=t=>e=>j3(Kh(t)(e.id)((()=>{if(e.label.tag==="Just")return e.label._1;if(e.label.tag==="Nothing")return e.id;c()})())),jh=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Jt("Cons",n._4,e(n._6,r)));c()};return Mt(ce.foldr,e(t.interiors,A))},eL=t=>ns(ht(e=>T("Just",E(e.edge,{id:e.edge,from:{node:e.from,port:y},to:{node:e.to,port:y},label:y})))(St(t.scenes)(e=>e.tag==="DataFlow"?ht(n=>n.kind.tag==="SendToken"?T("Just",n.kind._1):y)(e._1.events):[]))),tp=t=>{const e=Cx(t),n=K(o=>({...o,label:T("Just",tL(t)(o))}))(_t(o=>D3(o.id)(e.nodes),t.graph.nodes)),r=_t(o=>F3(o.id)(e.edges),t.graph.edges);return{nodes:[...n,...K(Y3)(Mt(Jn.foldr,Zn(G.compare,e.nodes,M3(K(o=>o.id)(n)))))],edges:[...r,...ht(X3(t)(eL(t)))(Mt(Jn.foldr,Zn(G.compare,e.edges,Q3(K(o=>o.id)(r)))))],constraints:t.graph.constraints}},nL=t=>{const e=rs(n=>{const r=rs(ml(pl))(Kh(t)(n.id)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;c()})()));return()=>{const o=r();return E(n.id,b(oo)(0)(o))}})(tp(t).nodes);return()=>{const n=e();return os(n)}},ep=t=>{const e=nL(t);return()=>{const n=e(),r=rs(ep)(jh(t))();return b(W3)(n)(r)}},rL=t=>e=>n=>{const r=Bt(o=>y,o=>i=>T("Just",{head:o,tail:i}),n.segments);if(r.tag==="Nothing")return[];if(r.tag==="Just")return U3(e)([{x:r._1.head.start._1*t,y:r._1.head.start._2*t},...K(o=>({x:o.end._1*t,y:o.end._2*t}))([r._1.head,...r._1.tail])]);c()},oL=t=>e=>{const n=os(K(r=>E(r.id,r))(t.nodes));return{...e,nodes:K(r=>{const o=hi(r.id)(n);return o.tag==="Just"&&o._1.size._2===1?{...r,size:E(r.size._1,pi(r.size._2)(ot(I_(1)(Sr(wn((()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;c()})()).length+3|0,3))+(r.shape==="Cylinder"||r.shape==="Document"?1:0)|0)))}:r})(e.nodes)}},iL=t=>e=>n=>E(n.edge,rL(t)(e)(n)),aL=t=>e=>n=>r=>{const o=K(Z3(ot(4)*t)(e)(n))(r.nodes),i=os(o),a=ns(K(iL(t)(K(s=>s._2)(o)))(r.edges));return{nodes:i,edges:a,bounds:gl(i)(a),chipExtras:W,edgeLabels:W}},sL=t=>e=>({...V3(ns(K(n=>E(n.id,E(n.from.node,n.to.node)))(e.edges)))(aL(8)(os(K(n=>E(n.id,(()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;c()})()))(e.nodes)))(os(K(n=>E(n.id,n.shape))(e.nodes)))(t.stretchNodes?L3(Wh)(e).result:Hh(Wh)(e).result)),edgeLabels:ns(ht(n=>n.label.tag==="Just"?T("Just",E(n.id,n.label._1)):y)(e.edges))}),uL=t=>b(e=>n=>{if(n.tag==="Structural")return e;if(n.tag==="DataFlow")return b(r=>o=>{if(o.kind.tag==="SendToken")return b(i=>a=>it(G)(a)()(i))(r)(o.kind._1.labels);if(o.kind.tag==="FillNodeWithoutTransition")return b(i=>a=>it(G)(a)()(i))(r)(o.kind._1.labels);c()})(e)(n._1.events);if(n.tag==="Hold"||n.tag==="EnterNode"||n.tag==="ExitNode"||n.tag==="StepScene")return e;c()})(W)(t.scenes),gL=t=>{const e=rs(n=>{const r=ml(pl)(n);return()=>{const o=r();return E(n,{labelW:o,charCount:zn(Dn(Xi(n))),lineCount:1})}})(Mt(Jn.foldr,O3(St(Mt(Jn.foldr,uL(t)))(Yh))));return()=>{const n=e();return H3(n)}},np=t=>{const e=gL(t);return()=>{const n=e(),r=rs(np)(jh(t))();return b($3)(n)(r)}},cL=ot(4)*8,_L=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[];c()}),fL=t=>e=>n=>{const r=o=>{const i=ht(a=>{const s=q3(a)(t);return s.tag==="Just"?T("Just",{w:s._1.labelW+28,h:ot(k3(1)(s._1.lineCount))*13.2+12}):y})(St(o)(Yh));return i.length===0?y:T("Just",{w:b(oo)(0)(K(a=>a.w)(i)),h:b(oo)(0)(K(a=>a.h)(i))})};return b(o=>i=>{if(i.kind.tag==="SendToken"){const a=A_(i.kind._1.edge)(n.edges),s=r(i.kind._1.labels);if(s.tag==="Just"&&a.tag==="Just"){const u=s._1;return Wt(G)(Je)(i.kind._1.edge)(K(g=>({x:g.x+14+u.w,y:g.y-6-8-u.h}))(a._1))(o)}return o}if(i.kind.tag==="FillNodeWithoutTransition"){const a=hi(i.kind._1.node)(n.nodes),s=r(i.kind._1.labels);return s.tag==="Just"&&a.tag==="Just"?Wt(G)(Je)("__fill__:"+i.kind._1.node)((()=>{const u=a._1.y-s._1.h-14,g=a._1.x+a._1.w/2,_=g-s._1.w/2,f=g+s._1.w/2,l=a._1.y-14;return[{x:_,y:u},{x:f,y:u},{x:_,y:l},{x:f,y:l}]})())(o):o}c()})(W)(_L(e))},rp=t=>e=>n=>{const r=tp(n);return{layout:(()=>{const o=sL(n)(oL(r)(G3(cL)(t)(B3(P3)(r))));return{...o,chipExtras:fL(e)(n)(o)}})(),interiors:(()=>{const o=rp(t)(e),i=a=>{if(a.tag==="Leaf")return W;if(a.tag==="Node")return ee("Node",a._1,a._2,a._3,o(a._4),i(a._5),i(a._6));c()};return i(n.interiors)})()}},op=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},z_=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=op(s._3)(n),g=(()=>{if(u.tag==="Just")return u._1;if(u.tag==="Nothing")return{x:s._4.x,y:s._4.y,vx:0,vy:0};c()})(),_=g.vx+(180*(s._4.x-g.x)-22*g.vx)*r,f=g.vy+(180*(s._4.y-g.y)-22*g.vy)*r;return it(G)(s._3)({x:g.x+_*r,y:g.y+f*r,vx:_,vy:f})(o(a,s._5))})(),s._6);c()},i=o(W,e);return{springs:i,applied:(()=>{const a=(s,u)=>{if(u.tag==="Leaf")return s;if(u.tag==="Node")return a((()=>{const g=a(s,u._5),_=op(u._3)(i);if(_.tag==="Just")return it(G)(u._3)({...u._4,x:_._1.x,y:_._1.y})(g);if(_.tag==="Nothing")return it(G)(u._3)(u._4)(g);c()})(),u._6);c()};return a(W,e)})()}},lL=t=>()=>t.clip("evenodd"),dL=t=>e=>()=>{t.filter=`blur(${e}px)`},hL=t=>e=>()=>{const n=e>0?t.canvas.width/e:1;t.setTransform(n,0,0,n,0,0)},pL=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)},mL=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()},D_=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},F_=t=>e=>n=>{const r=e.stroke;return()=>{const o=r.value,i=pf(t)(n);if(o!==n)return i(),e.stroke.value=n}},yL=t=>e=>n=>{const r=e.font;return()=>{const o=r.value,i=wf(t)(n);if(o!==n)return i(),e.font.value=n}},is=t=>e=>n=>{const r=e.fill;return()=>{const o=r.value,i=hf(t)(n);if(o!==n)return i(),e.fill.value=n}},Hu=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=yf(t)((()=>{const g=i+1|0;return g>=0&&g<e.length?e[g]:0})())((()=>{const g=i+2|0;return g>=0&&g<e.length?e[g]:0})()),u=r(i+3|0);return()=>(s(),u())}if(a===2){const s=va(t)((()=>{const g=i+1|0;return g>=0&&g<e.length?e[g]:0})())((()=>{const g=i+2|0;return g>=0&&g<e.length?e[g]:0})()),u=r(i+3|0);return()=>(s(),u())}if(a===3){const s=La(t)({cpx:(()=>{const g=i+1|0;return g>=0&&g<e.length?e[g]:0})(),cpy:(()=>{const g=i+2|0;return g>=0&&g<e.length?e[g]:0})(),x:(()=>{const g=i+3|0;return g>=0&&g<e.length?e[g]:0})(),y:(()=>{const g=i+4|0;return g>=0&&g<e.length?e[g]:0})()}),u=r(i+5|0);return()=>(s(),u())}if(a===4){const s=Fy(t)({cp1x:(()=>{const g=i+1|0;return g>=0&&g<e.length?e[g]:0})(),cp1y:(()=>{const g=i+2|0;return g>=0&&g<e.length?e[g]:0})(),cp2x:(()=>{const g=i+3|0;return g>=0&&g<e.length?e[g]:0})(),cp2y:(()=>{const g=i+4|0;return g>=0&&g<e.length?e[g]:0})(),x:(()=>{const g=i+5|0;return g>=0&&g<e.length?e[g]:0})(),y:(()=>{const g=i+6|0;return g>=0&&g<e.length?e[g]:0})()}),u=r(i+7|0);return()=>(s(),u())}if(a===5){const s=xf(t),u=r(i+1|0);return()=>(s(),u())}return()=>{}},o=mf(t);return()=>(o(),r(0)())},xL=t=>e=>n=>r=>o=>i=>{const a=D_(i)(D_(r/2)(o/2)),s=yf(t)(e+a)(n);return()=>(s(),va(t)(e+r-a)(n)(),La(t)({cpx:e+r,cpy:n,x:e+r,y:n+a})(),va(t)(e+r)(n+o-a)(),La(t)({cpx:e+r,cpy:n+o,x:e+r-a,y:n+o})(),va(t)(e+a)(n+o)(),La(t)({cpx:e,cpy:n+o,x:e,y:n+o-a})(),va(t)(e)(n+a)(),La(t)({cpx:e,cpy:n,x:e+a,y:n})(),xf(t)())},JL=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),ip=t=>e=>{const n=Ay(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=JL();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0},groupAlpha:{value:1},alphaSaves:{value:[]}}}},wL={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},TL=t=>ue(t.weight)+" "+Ln(t.size)+"px "+t.family,Wr=t=>{const e=Ln(ot(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+")"},NL=t=>e=>n=>r=>{const o=gr(t);return()=>(o(),hL(t)(e.width)(),is(t)(n)(Wr(r))(),By(t)({x:0,y:0,width:e.width,height:e.height})(),cr(t)(),n.font.value="",n.fill.value="",n.stroke.value="")},bL=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",mL(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:Wr(n.bgColor),dotCss:Wr(n.dotColor),tile:n.tile,dotR:n.dotRadius,ox:n.origin.x,oy:n.origin.y})())},vL=t=>e=>n=>r=>{const o=is(t)(e)(Wr(r));return()=>(o(),Hu(t)(n)(),Kg(t)())},CL=t=>e=>n=>r=>o=>{const i=is(t)(e)(Wr(r));return()=>(i(),F_(t)(e)(Wr(o.color))(),Ss(t)(o.width)(),ac(t)((()=>{if(o.lineJoin==="RoundJoin")return ec;if(o.lineJoin==="BevelJoin")return tc;if(o.lineJoin==="MiterJoin")return nc;c()})())(),sc(t)((()=>{if(o.lineCap==="ButtCap")return ic;if(o.lineCap==="RoundCap")return rc;if(o.lineCap==="SquareCap")return oc;c()})())(),Hu(t)(n)(),Kg(t)(),Xg(t)())},LL=t=>e=>n=>r=>o=>i=>{const a=mf(t);return()=>{if(a(),xL(t)(n.x)(n.y)(n.w)(n.h)(r)(),o.tag==="Just"?(is(t)(e)(Wr(o._1.color))(),Kg(t)()):o.tag==="Nothing"||c(),i.tag==="Just")return F_(t)(e)(Wr(i._1.color))(),Ss(t)(i._1.width)(),ac(t)((()=>{if(i._1.lineJoin==="RoundJoin")return ec;if(i._1.lineJoin==="BevelJoin")return tc;if(i._1.lineJoin==="MiterJoin")return nc;c()})())(),sc(t)((()=>{if(i._1.lineCap==="ButtCap")return ic;if(i._1.lineCap==="RoundCap")return rc;if(i._1.lineCap==="SquareCap")return oc;c()})())(),Xg(t)();i.tag!=="Nothing"&&c()}},kL=t=>e=>n=>r=>{const o=F_(t)(e)(Wr(r.color));return()=>(o(),Ss(t)(r.width)(),ac(t)((()=>{if(r.lineJoin==="RoundJoin")return ec;if(r.lineJoin==="BevelJoin")return tc;if(r.lineJoin==="MiterJoin")return nc;c()})())(),sc(t)((()=>{if(r.lineCap==="ButtCap")return ic;if(r.lineCap==="RoundCap")return rc;if(r.lineCap==="SquareCap")return oc;c()})())(),Hu(t)(n)(),Xg(t)())},ap=t=>e=>n=>{const r=is(t)(e)(Wr(n.color));return()=>(r(),yL(t)(e)(TL(n.font))(),Ky(t)((()=>{if(n.align==="AlignLeft")return Hy;if(n.align==="AlignCenter")return qy;if(n.align==="AlignRight")return $y;c()})())(),Xy(t)((()=>{if(n.baseline==="BaselineTop")return My;if(n.baseline==="BaselineMiddle")return Qy;if(n.baseline==="BaselineAlphabetic")return Wy;if(n.baseline==="BaselineBottom")return Oy;c()})())(),Tf(t)(n.content)(n.x)(n.y)())},sp={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),a=o();return i(a)}},Functor0:()=>wL},SL={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>sp},EL=t=>e=>n=>{const r=D_(e.width/n.vw)(e.height/n.vh);return pL(t)(e.width)(r)((e.width-n.vw*r)/2-n.vx*r)((e.height-n.vh*r)/2-n.vy*r)},RL={pure:t=>e=>()=>t,Apply0:()=>sp},up={Applicative0:()=>RL,Bind1:()=>SL},M_={fillPath:t=>e=>n=>{const r=vL(n.ctx)(n.styleCache)(t)(e.color),o=n.maskDepth;return()=>{if(o.value===0)return r()}},strokePath:t=>e=>n=>{const r=kL(n.ctx)(n.styleCache)(t)(e),o=n.maskDepth;return()=>{if(o.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const o=CL(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=LL(o.ctx)(o.styleCache)(t)(e)(n)(r),a=o.maskDepth;return()=>{if(a.value===0)return i()}},drawText:t=>e=>{const n=ap(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=gr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Iy(n.ctx)(t)(),ap(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=gr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Jf(e.ctx)({translateX:t.tx,translateY:t.ty})(),Ca(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=gr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Jf(e.ctx)({translateX:t.tx,translateY:t.ty})(),Ca(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=gr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Hu(n.ctx)(t)(),e==="NonZero")return Py(n.ctx)();if(e==="EvenOdd")return lL(n.ctx)();c()}}},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=gr(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 bf(e.ctx)(Vy)();if(t==="Difference")return bf(e.ctx)(Uy)();c()}}},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=gr(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,Ry(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=Rr(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;c()}}},pushBlur:t=>e=>{const n=gr(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=dL(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=EL(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=NL(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=bL(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=Ec(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Rc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>zc,Monad0:()=>up},PL=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},as=t=>e=>n=>{const r=PL(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},Q_=t=>{const e=at.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;c()})(),r=at.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;c()},BL=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:Q_(t._2)};if(t._1==="ExtendFromTarget")return{lo:1-t._2,hi:1};c()}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}}c()},mi=t=>{if(t.tag==="Hidden")return{alpha:0,scale:1};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:t._1>0?1:0,scale:Ko(8)(.6)(Q_(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:Ko(8)(.6)(Q_(1-t._1))};c()};function GL(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function AL(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:GL(o,i)}}return n}function IL(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 gp(t,e){if(e.length===0)return[];const n=AL(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]=IL(n,e,i*r/t);return o}function zL(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 DL(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},g=e[(s+i)%n]||{x:0,y:0},_=u.x-g.x,f=u.y-g.y;a+=_*_+f*f}a<o&&(o=a,r=i)}return zL(r,e)}const cp=t=>e=>n=>{const r=gp(t,e),o=gp(t,n),i=DL(r,o);return{from:r,to:i}};function _p(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 FL(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 ML(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 QL(t){return t<0?0:t>1?1:t}const fp=t=>e=>n=>r=>{const o=e.length;if(o===0)return[];const i=_p(e),a=_p(n),s=FL(i,a),u=new Array(o);let g=1/0,_=-1/0;for(let d=0;d<o;d++){const h=e[d],m=(h.x-i.x)*s.x+(h.y-i.y)*s.y;u[d]=m,m<g&&(g=m),m>_&&(_=m)}const f=_-g;let l=new Array(o);for(let d=0;d<o;d++){const h=e[d],m=n[d];if(m===void 0){l[d]=h;continue}const p=f<=1e-4?0:r.maxDelay*(1-(u[d]-g)/f),x=Math.max(1e-4,1-p),J=QL((t-p)/x),w=J*J*(3-2*J);l[d]={x:h.x+(m.x-h.x)*w,y:h.y+(m.y-h.y)*w}}for(let d=0;d<r.smoothPasses;d++)l=ML(.5,l);return l},lp=(t,e)=>({tag:t,_1:e}),dp=(t,e)=>({tag:t,_1:e}),pe=(t,e,n)=>({tag:t,_1:e,_2:n}),hp=t=>t,$u=(t,e)=>({tag:t,_1:e}),qu=(t,e)=>({tag:t,_1:e}),Vu=t=>t,yi=t=>({tag:"FloorOverlay",_1:t}),Ae=(t,e,n)=>({tag:t,_1:e,_2:n}),Lo=(t,e)=>({tag:t,_1:e}),ha=(t,e)=>({tag:t,_1:e}),pp=(t,e)=>({tag:t,_1:e}),mp=t=>t,yp=(t,e)=>({tag:t,_1:e}),xi=(t,e,n)=>({tag:t,_1:e,_2:n}),xp=t=>t,WL=t=>t,Ji=xp("NormalTransform"),OL=xp("BakedTransform"),Jp=mp("TokenOutside"),wp=mp("TokenInside"),W_=ha("PlainText"),HL=Lo("Watermark"),$L=Vu("NodeShadow"),qL=Vu("NodeDoorwayFrame"),Tp=Vu("NodeBody"),VL=Vu("NodeInversion"),O_=hp("LabelsShown"),Uu=hp("LabelsHidden"),mr={map:t=>e=>{if(e.tag==="BeginFrame")return Ae("BeginFrame",e._1,t(e._2));if(e.tag==="EndFrame")return Ae("EndFrame",t(e._1));if(e.tag==="BeginGroup")return Ae("BeginGroup",e._1,t(e._2));if(e.tag==="EndGroup")return Ae("EndGroup",e._1,t(e._2));if(e.tag==="Background")return Ae("Background",e._1,t(e._2));if(e.tag==="Overlay")return Ae("Overlay",e._1,t(e._2));if(e.tag==="Node")return Ae("Node",e._1,t(e._2));if(e.tag==="Edge")return Ae("Edge",e._1,t(e._2));if(e.tag==="Text")return Ae("Text",e._1,t(e._2));if(e.tag==="Token")return Ae("Token",e._1,t(e._2));if(e.tag==="AskInsideTokenStyle")return Ae("AskInsideTokenStyle",e._1,n=>t(e._2(n)));c()}},Np=t=>e=>xo(t)(e),UL=t=>{const e=t.Bind1().Apply0().Functor0(),n=KJ(t);return r=>o=>n(UJ()()()({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));c()},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));c()}}))(o)},XL=t=>j(st("Bind",{type:"scene",value:Ae("AskInsideTokenStyle",t,WL),map:mr.map},e=>j(st("Return",e),gt)),gt),bp=t=>j(st("Bind",{type:"scene",value:Ae("Background",t,void 0),map:mr.map},e=>j(st("Return",e),gt)),gt),vp=t=>j(st("Bind",{type:"scene",value:Ae("Edge",t,void 0),map:mr.map},e=>j(st("Return",e),gt)),gt),Xu=t=>j(st("Bind",{type:"scene",value:Ae("Node",t,void 0),map:mr.map},e=>j(st("Return",e),gt)),gt),wi=t=>j(st("Bind",{type:"scene",value:Ae("Overlay",t,void 0),map:mr.map},e=>j(st("Return",e),gt)),gt),Ti=t=>j(st("Bind",{type:"scene",value:Ae("Text",t,void 0),map:mr.map},e=>j(st("Return",e),gt)),gt),Cp=t=>j(st("Bind",{type:"scene",value:Ae("Token",t,void 0),map:mr.map},e=>j(st("Return",e),gt)),gt),KL=t=>e=>j(st("Bind",{type:"scene",value:Ae("BeginFrame",t,void 0),map:mr.map},n=>j(st("Return",n),gt)),et("CatCons",()=>j(e._1,(()=>{if(e._2.tag==="CatNil")return et("CatCons",()=>j(st("Bind",{type:"scene",value:Ae("EndFrame",void 0),map:mr.map},n=>j(st("Return",n),gt)),gt),tt(A,A));if(e._2.tag==="CatCons")return et("CatCons",e._2._1,tt(e._2._2._1,Jt("Cons",et("CatCons",()=>j(st("Bind",{type:"scene",value:Ae("EndFrame",void 0),map:mr.map},n=>j(st("Return",n),gt)),gt),tt(A,A)),e._2._2._2)));c()})()),tt(A,A))),Se=t=>e=>j(st("Bind",{type:"scene",value:Ae("BeginGroup",t,void 0),map:mr.map},n=>j(st("Return",n),gt)),et("CatCons",()=>{const n=()=>j(st("Bind",{type:"scene",value:Ae("EndGroup",t,void 0),map:mr.map},r=>j(st("Return",r),gt)),gt);return j(e._1,(()=>{if(e._2.tag==="CatNil")return et("CatCons",n,tt(A,A));if(e._2.tag==="CatCons")return et("CatCons",e._2._1,tt(e._2._2._1,Jt("Cons",et("CatCons",n,tt(A,A)),e._2._2._2)));c()})())},tt(A,A))),ko=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},H_=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},YL=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},ZL=t=>e=>{const n=ko(0)(t.y+4-e.y)+ko(0)(e.y+e.h-(t.y+t.h-4)),r=ko(0)(t.x+4-e.x)+ko(0)(e.x+e.w-(t.x+t.w-4));return r*e.h+n*e.w+r*n},jL=t=>e=>{const n=t.y+t.h-6,r=t.y+6,o=t.x+14,i=t.x+t.w-14,a=b(ko)(0)(K(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?H_((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}},tk=t=>e=>{const n=H_(t.x+t.w)(e.x+e.w)-ko(t.x)(e.x),r=H_(t.y+t.h)(e.y+e.h)-ko(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},Lp=t=>e=>n=>r=>{const o=t+4,i=ko(0)(e-8),a=o+i-n;return n<=i?YL(o)(a)(r):t+(e-n)/2},$_=t=>e=>({...e,x:Lp(t.x)(t.w)(e.w)(e.x),y:Lp(t.y)(t.h)(e.h)(e.y)}),ek=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}]},nk=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*ZL(t)(o)+1e4*b(g=>_=>g+tk(o)(_))(0)(e)+.05*(u*u+a*a)+.01*(s*s+i*i)})()+(o.y>n.token.y?100:0)},rk=t=>e=>n=>r=>{const o=a=>{const s=$_(t)(a);return{rect:s,score:nk(t)(e)(n)(r)(s)}},i=Bt(a=>y,a=>s=>T("Just",{head:a,tail:s}),[r,n.rect,...ek(n)]);if(i.tag==="Nothing")return $_(t)(r);if(i.tag==="Just")return b(a=>s=>{const u=o(s);return u.score<a.score?u:a})(o(i._1.head))(i._1.tail).rect;c()},ok=t=>e=>n=>b(r=>o=>{const i=jL(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:rk(t)(r.obstacles)(o)(i);return{acc:it(G)(o.id)(a)(r.acc),obstacles:Et(r.obstacles)(a)}})({acc:W,obstacles:e})(n).acc,q_=t=>t,io=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ni=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},ik=Ii(Dg)(Qt),ak=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},sk=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},kp=q_("SegMove"),uk=q_("SegLine"),gk=q_("SegQuad"),Sp={offset:.4,passes:1,rMax:1.5},Ep=t=>he(sr(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,Ku=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},Yu=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},ao=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},ss=(()=>{const t=b(e=>n=>((e*31|0)+he(sr(n.x*100))|0)+he(sr(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),ck=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const o=n,i=r,a=o>=0&&o<t.length?T("Just",t[o]):y;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:kp,m:i,c:i,p:s,len:0}),r=s,n=o+3|0;continue}if(a._1===2){const s={x:(()=>{const _=o+1|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+2|0;return _>=0&&_<t.length?t[_]:0})()},u=s.x-i.x,g=s.y-i.y;e.push({kind:uk,m:i,c:i,p:s,len:qe(u*u+g*g)}),r=s,n=o+3|0;continue}if(a._1===3){const s={x:(()=>{const _=o+3|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+4|0;return _>=0&&_<t.length?t[_]:0})()},u=s.x-i.x,g=s.y-i.y;e.push({kind:gk,m:i,c:{x:(()=>{const _=o+1|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+2|0;return _>=0&&_<t.length?t[_]:0})()},p:s,len:qe(u*u+g*g)*1.05}),r=s,n=o+5|0;continue}if(a._1===5){e.push({kind:kp,m:i,c:i,p:i,len:0}),n=o+1|0;continue}n=t.length;continue}c()}return e},_k=t=>e=>{const n=e.length-1|0,r=n<1?[]:At(0,n,e),o=(()=>{const a=r.length-1|0;return a>=0&&a<r.length?T("Just",r[a]):y})(),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=qe(s*s+a*a);return u<=1e-4?e:Et((()=>{const g=e.length-1|0;return g<1?[]:At(0,g,e)})())({x:e[i].x+s/u*t,y:e[i].y+a/u*t})}return e},fk=t=>e=>n=>re(b(r=>o=>{const i=Pe(0)(t)(r.prng),a=Pe(0)(6.283185307179586)(i.prng);return{prng:a.prng,out:[{x:o.x+i.value*xn(a.value),y:o.y+i.value*en(a.value)},...r.out]}})({prng:e,out:[]})(n).out),lk=t=>e=>n=>{if(e.kind==="SegMove")return Yu(t)(e.p);if(e.kind==="SegLine")return ao(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 ao(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});c()},dk=t=>e=>{if(e.kind==="SegMove")return Yu(t)(e.p);if(e.kind==="SegLine")return ao(t)(e.p);if(e.kind==="SegQuad")return Ku(t)(e.c)(e.p);c()},Rp=t=>e=>{const n=ck(e),r=b(s=>u=>s+u.len)(0)(n)*io(0)(Ni(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 g=n[s];dk(o)(g)(),i=u+g.len,a=s+1|0;continue}if(u>=r){a=n.length;continue}lk(o)(n[s])((r-u)/io(n[s].len)(1e-4))()}a=n.length}return o},Pp={offset:1.5,passes:2,rMax:14,overshoot:2.5},Bp=t=>e=>n=>r=>{const o=r.y-n.y,i=n.y-e.y,a=r.x-n.x,s=qe(a*a+o*o),u=n.x-e.x,g=qe(u*u+i*i),_=Ni(t.rMax*(fy(g>0&&s>0?io(-1)(Ni(1)((u*a+i*o)/(g*s))):1)/3.141592653589793))(.4*Ni(g)(s));return{inP:g>0?{x:n.x-u/g*_,y:n.y-i/g*_}:n,curr:n,outP:s>0?{x:n.x+a/s*_,y:n.y+o/s*_}:n}},Gp=t=>e=>{const n=e.length,r=[],o=0<e.length?T("Just",e[0]):y;if(o.tag==="Just"?Yu(r)(o._1)():o.tag==="Nothing"||c(),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 g=s-1|0;if(g>=0&&g<e.length){const _=Bp(t)(e[g])(e[s])(e[u]);ao(r)(_.inP)(),Ku(r)(_.curr)(_.outP)()}}a=s+1|0;continue}a=s+1|0}}const i=e.length-1|0;return i>=0&&i<e.length&&n>=2&&ao(r)(e[i])(),r},hk=t=>e=>n=>r=>o=>{if(o.length<4)return Gp(t)(o);const i=0<o.length?T("Just",o[0]):y,a=(()=>{if(i.tag==="Nothing")return{x:0,y:0};if(i.tag==="Just")return i._1;c()})(),s=o.length-1|0,u=lo(lo(e)(s)+s|0)(s),g=d=>{const h=lo(d+s|0)(s);return h>=0&&h<o.length?o[h]:a},_=K(d=>Bp(t)(g((u+d|0)-1|0))(g(u+d|0))(g((u+d|0)+1|0)))(Ut(0,s-1|0)),f=[],l=0<_.length?T("Just",_[0]):y;if(l.tag==="Just")if(Yu(f)(l._1.outP)(),ik((()=>{const d=Bt(h=>y,h=>m=>T("Just",m),_);if(d.tag==="Nothing")return[];if(d.tag==="Just")return d._1;c()})())(d=>{const h=ao(f)(d.inP);return()=>(h(),Ku(f)(d.curr)(d.outP)())})(),n)ao(f)(l._1.inP)(),Ku(f)(l._1.curr)(l._1.outP)(),f.push(5);else{const d=_.length-1|0;d>=0&&d<_.length?ao(f)((()=>{const h=1-r;return{x:_[d].outP.x+(l._1.inP.x-_[d].outP.x)*h,y:_[d].outP.y+(l._1.inP.y-_[d].outP.y)*h}})())():ao(f)(l._1.inP)()}else l.tag==="Nothing"||c();return f},pa=t=>e=>n=>r=>{const o=ak(1)(r.length-1|0),i=Pe(0)(ot(o))(Ac("shape")(e)),a=sk(o-1|0)(he(sr(i.value))),s=i.prng;return K(u=>{const g=Pe(0)(1)(Ac(ue(u))(s)),_=Pe(-.18)(.3)(g.prng),f=g.value<.7,l=Pe(.5)(.85)(_.prng),d=fk(t.offset)(l.prng)(r);return{path:n?hk(t)(a)(f)(_.value)(d):Gp(t)(d),alpha:l.value}})(Ut(0,t.passes-1|0))},pk=t=>e=>n=>pa(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}]),mk=t=>e=>n=>{const r=io(0)(Ni(1)(n)),o=e.h/ot(4),i=io(6)(o*1.4);return ht(a=>a)(K(a=>{if(r<io(0)(ot(a)/ot(4)-.05))return y;const s=Ac(ue(a))(t),u=io(0)(ot(a)/ot(4)-.05),g=lo(a)(2)===0,_=g?e.x-2:e.x+e.w+2,f=g?e.x+e.w+2:e.x-2,l=e.y+(ot(a)+.5)*o;return T("Just",{path:Rp(io(0)(Ni(1)((r-u)/io(1e-4)(Ni(1)(ot(a+1|0)/ot(4)+.05)-u))))((()=>{const d={rMax:2,offset:.6,passes:1},h=re(b(p=>x=>{const J=Pe(-o*.08)(o*.08)(p.prng);return{prng:J.prng,out:[{x:_+(f-_)*(ot(x)/ot(4)),y:l+J.value},...p.out]}})({prng:s,out:[]})(Ut(0,4)).out),m=h.length<2?[]:pa(d)(s)(!1)(h);return 0<m.length?m[0].path:[]})()),width:i,alpha:1})})(Ut(0,3)))},V_=(t,e,n)=>({tag:t,_1:e,_2:n}),us=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Ap=t=>t,Zu=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},dn=(()=>{const t=gn.unfoldr(jn);return e=>t(cn("IterNode",e,Yn))})(),yk=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},so=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},me=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},xk=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},yr=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},bi=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Or=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Jk=Qt.foldMap(vy),Ip=fe(G)(Qt),zp=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},gs=xr.traverse(Zr),So=b(ur)(0),wk=sf(G),Tk=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=G.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}}c()}return o},U_=Ap("FullTokenGeometry"),Nk=Ap("ConvexInsideGeometry"),vi=t=>{const e=t.Apply0();return n=>b(r=>o=>e.apply(e.Functor0().map(i=>q1)(r))(n(o)))(t.pure())},nr=vi(Zr),Dp=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=as(o)(i)(r),g=0<t.length?T("Just",t[0]):y,_=(()=>{if(g.tag==="Just")return g._1;if(g.tag==="Nothing")return s;c()})(),f=t.length-1|0,l=f>=0&&f<t.length?T("Just",t[f]):y,d=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return a;c()})(),h=_.x-s.x,m=2*(()=>{const C=_.y-s.y;return(h<0?-h:h)+(C<0?-C:C)})(),p=d.x-a.x,x=2*(()=>{const C=d.y-a.y;return(p<0?-p:p)+(C<0?-C:C)})(),J=m+Ga(t)+x,w=J<=1e-4?1:1-x/J,N=J<=1e-4?0:m/J,L=w-N;return{progress:u,morphOutEnd:N,morphInStart:w,outT:(()=>{if(N<=1e-4)return 1;const C=u/N,R=C<0?0:C>1?1:C;return R*R*(3-2*R)})(),inT:(()=>{if(w>=1)return 0;const C=(u-w)/(1-w),R=C<0?0:C>1?1:C;return R*R*(3-2*R)})(),pathStart:_,pathEnd:d,travelPt:(()=>{const C=ti(t)(Zu(0)(1)(L<=1e-4?0:(u-N)/L));if(C.tag==="Just")return C._1;if(C.tag==="Nothing")return _;c()})()}},Fp=t=>e=>n=>r=>o=>i=>{const a=Dp(t)(e)(n)(r)(o)(i),s=cp(128)(ri(4)(e))(Hl(a.pathStart)(6)),u=cp(128)(Hl(a.pathEnd)(6))(ri(4)(n)),g={maxDelay:.4,smoothPasses:2};return a.progress<a.morphOutEnd?xi("PolyShape",fp(a.outT)(s.from)(s.to)(g)):a.progress>=a.morphInStart?xi("PolyShape",fp(a.inT)(u.from)(u.to)(g)):xi("CircleShape",a.travelPt,6)},X_=t=>e=>n=>r=>o=>i=>{const a=Fp(t)(e)(n)(r)(o)(i);if(a.tag==="PolyShape")return Mc(a._1);if(a.tag==="CircleShape")return a._1;c()},bk=t=>{const e=n=>{const r=te(o=>n.x>=o._2.x-1&&n.x<=o._2.x+o._2.w+1&&n.y>=o._2.y-1&&n.y<=o._2.y+o._2.h+1)(dn(t.nodes));return r.tag==="Just"?T("Just",r._1._2):y};return n=>{const r=(()=>{if(0<n.length){const i=e(n[0]);if(i.tag==="Just")return re(ql(ri(7)(i._1))(re(n)))}return n})(),o=r.length-1|0;if(o>=0&&o<r.length){const i=e(r[o]);if(i.tag==="Just")return ql(ri(7)(i._1))(r)}return r}},K_=t=>({nodes:t.nodes,edges:(()=>{const e=bk(t),n=r=>{if(r.tag==="Leaf")return W;if(r.tag==="Node")return ee("Node",r._1,r._2,r._3,e(r._4),n(r._5),n(r._6));c()};return n(t.edges)})()}),vk=t=>e=>{const n=((t.bg.r+t.bg.g|0)+t.bg.b|0)<384,r=n?90:104,o=n?165:122,i=a=>yk(255)(so(0)(he(Kn(o+r*en(e+a)))));return{r:i(0),g:i(-2.0943951023931953),b:i(-4.1887902047863905),a:255}},Mp=t=>e=>{if(t<=0)return[];const n=Bt(r=>y,r=>o=>T("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return Ke(n._1.head.text).length<=t?[n._1.head,...Mp(t-Ke(n._1.head.text).length|0)(n._1.tail)]:[{...n._1.head,text:Ve(t)(n._1.head.text)}];c()},Y_=(()=>{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:jr,nodeFill:we,nodeStroke:jr,text:jr,edge:jr,arrowFill:jr,tokenOutsideFill:jr,tokenOutsideStroke:we,tokenInside:we,tokenInsideStroke:we,tokenInsideBlend:au,tokenInsideAlpha:1,chipPillFill:jr,chipPillText:we,chipHairline:{r:26,g:26,b:26,a:90},trailDot:jr,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:jr,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:we,tokenOutsideStroke:we,tokenInside:we,tokenInsideStroke:we,tokenInsideBlend:au,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:we,chip:we,chipShadow:{r:0,g:0,b:0,a:120},chipText:o,nodeFill:o,nodeStroke:we,text:we,edge:we,arrowFill:we,tokenOutsideFill:we,tokenOutsideStroke:we,tokenInside:we,tokenInsideStroke:we,tokenInsideBlend:Ll,tokenInsideAlpha:.35,chipPillFill:we,chipPillText:o,chipHairline:{r:255,g:255,b:255,a:120},trailDot:we,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:Ll,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:we,tokenInside:we,tokenInsideStroke:we,tokenInsideBlend:au,tokenInsideAlpha:1,chipPillFill:a,chipPillText:we,chipHairline:{r:60,g:66,b:78,a:90},trailDot:a,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};c()}})(),Z_=t=>e=>St(dn(t))(n=>{const r=me(n._1)(e.nodes);return r.tag==="Just"&&mi(r._1).alpha>0?wo(n._2):[]}),Ck=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,...Z_(e)(n)],Lk=t=>e=>n=>{const r=(o,i)=>he(Kn(ot(o)+(ot(i)-ot(o))*n));return{r:r(t.r,e.r),g:r(t.g,e.g),b:r(t.b,e.b),a:r(t.a,e.a)}},kk=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=xr.traverse(r);return i=>a=>{const s=tr(a),u=.32*i.size;return o(g=>n.bind(g===0?r.pure(0):t.measureText(i)(Ve(g)(a)))(_=>n.bind(t.measureText(i)(Ve(g+1|0)(a)))(f=>n.bind(t.measureInk(i)(g>=0&&g<s.length?In(s[g]):" "))(l=>r.pure({x:_,w:f-_,up:l.ascent-u,down:l.descent+u})))))(Ut(0,s.length-1|0))}},Qp=t=>[...wo({...t,x:t.x-1.25,y:t.y-1.25,w:t.w+2.5,h:t.h+2.5}),...wo({...t,y:t.y-5})],Sk=t=>e=>{const n=o=>(o.x-e.x)*(o.x-e.x)+(o.y-e.y)*(o.y-e.y),r=b(o=>i=>n(i)<n(o)?i:o)({x:t.x,y:t.y})([{x:t.x,y:t.y},{x:t.x+t.w,y:t.y},{x:t.x,y:t.y+t.h},{x:t.x+t.w,y:t.y+t.h}]);return K(o=>{const i=ot(o)/5;return{x:r.x+(e.x-r.x)*i,y:r.y+(e.y-r.y)*i}})([1,2,3,4])},cs=t=>e=>n=>{const r=xk(ue(e)+":"+ue(n))(t);if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;c()},Ek=t=>e=>{const n=e.length;return b(r=>o=>b(i=>a=>it(G)(ue(o)+":"+ue(a))(a>=0&&a<e.length&&o>=0&&o<t.length?t[o]===e[a]?1+cs(i)(o+1|0)(a+1|0)|0:so(cs(i)(o+1|0)(a))(cs(i)(o)(a+1|0)):0)(i))(r)(n<=0?[]:re(Ut(0,n-1|0))))(W)((()=>{const r=t.length;return r<=0?[]:re(Ut(0,r-1|0))})())},j_=t=>wn(t),Rk=t=>e=>n=>{const r=e*n;return Zu(0)(1)(r/t)},Pk=t=>e=>n=>r=>o=>i=>{const a=Dp(t)(e)(n)(r)(o)(i);return a.progress<a.morphOutEnd?V_("InsideRect",Dc(2)(e)):a.progress>=a.morphInStart?V_("InsideRect",Dc(2)(n)):V_("InsideBall",a.travelPt,6)},t1=t=>e=>n=>r=>o=>i=>a=>s=>{const u=(g,_)=>Cp({id:g,pass:t,geometry:pp("FlatToken",_),position:(()=>{if(_.tag==="CircleShape")return _._1;if(_.tag==="PolyShape")return Mc(_._1);c()})(),plan:yp("FlatTokenPlan",{wobble:n,fill:a,stroke:s})});return nr(g=>{if(g._2.tag==="Travelling"){const _=me(g._2._1.target)(r),f=me(g._2._1.source)(r);if(f.tag==="Just"&&_.tag==="Just"){const l=Or(g._2._1.edge)(o);if(l.tag==="Just"){const d=(()=>{if(g._2._1.direction==="Forward")return l._1;if(g._2._1.direction==="Backward")return re(l._1);c()})();return u(g._1,(()=>{if(e==="FullTokenGeometry")return Fp(d)(f._1)(_._1)(g._2._1.progress)(g._2._1.holdPre)(g._2._1.holdPost);if(e==="ConvexInsideGeometry"){const h=Pk(d)(f._1)(_._1)(g._2._1.progress)(g._2._1.holdPre)(g._2._1.holdPost);if(h.tag==="InsideRect")return xi("PolyShape",Qc(4)(h._1));if(h.tag==="InsideBall")return xi("CircleShape",h._1,h._2)}c()})())}if(l.tag==="Nothing"){const d=as(g._2._1.holdPre)(g._2._1.holdPost)(g._2._1.progress),h={x:f._1.x+f._1.w/2,y:f._1.y+f._1.h/2},m={x:_._1.x+_._1.w/2,y:_._1.y+_._1.h/2};return Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",(()=>{if(d<.5){const x=d*2;return 1-yr(0)(bi(1)(x))*yr(0)(bi(1)(x))*(3-2*yr(0)(bi(1)(x)))}const p=(d-.5)*2;return yr(0)(bi(1)(p))*yr(0)(bi(1)(p))*(3-2*yr(0)(bi(1)(p)))})())]})(u(g._1,xi("CircleShape",d<.5?h:m,6)))}c()}return j(st("Return",void 0),gt)}if(g._2.tag==="Filling"){if(n)return j(st("Return",void 0),gt);const _=me(g._2._1.node)(r);if(_.tag==="Just")return u(g._1,xi("PolyShape",ri(4)(e==="ConvexInsideGeometry"?Dc(2)(_._1):_._1)));if(_.tag==="Nothing")return j(st("Return",void 0),gt);c()}return j(st("Return",void 0),gt)})(dn(i.tokens))},Bk=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);c()})())(()=>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);c()}))},Wp=t=>e=>n=>r=>Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",n.fadeAlpha),pe("GroupTransform",Ji,{tx:t.x*(1-n.popScale),ty:(t.y+t.h)*(1-n.popScale),sx:n.popScale,sy:n.popScale}),pe("GroupTransform",Ji,{tx:0,ty:e.y*(1-n.flipY),sx:1,sy:n.flipY})]})(Ti(r)),Gk=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const g=_=>f=>{const l=Bt(d=>y,d=>h=>T("Just",{head:d,tail:h}),f);if(l.tag==="Nothing")return j(st("Return",void 0),gt);if(l.tag==="Just"){const d=l._1,h=xo(i)(In(d.head)),m=p=>{const x=Ti({owner:Lo("NodeText",o),text:In(d.head),spec:{x:_,y:s-n*i.size*.11*en(e*5-_*.22),content:In(d.head),font:i,color:Lk(r.text)(vk(r)(e*2.2+_*.16))(n),align:wr,baseline:Fn},bounds:y,plan:t});return j(x._1,(()=>{if(x._2.tag==="CatNil")return et("CatCons",()=>g(_+p)(d.tail),tt(A,A));if(x._2.tag==="CatCons")return et("CatCons",x._2._1,tt(x._2._2._1,Jt("Cons",et("CatCons",()=>g(_+p)(d.tail),tt(A,A)),x._2._2._2)));c()})())};return j(h._1,(()=>{if(h._2.tag==="CatNil")return et("CatCons",m,tt(A,A));if(h._2.tag==="CatCons")return et("CatCons",h._2._1,tt(h._2._2._1,Jt("Cons",et("CatCons",m,tt(A,A)),h._2._2._2)));c()})())}c()};return g(a)(tr(u))},Op=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>a==="RunHighlight"||a==="RunBoldHighlight"||a==="RunCodeHighlight"||a==="RunCodeBoldHighlight"?Gk(t)(e)(n)(r)(o)(i)(s)(u)(g):Ti({owner:Lo("NodeText",o),text:g,spec:{x:s,y:u,content:g,font:i,color:r.text,align:wr,baseline:Fn},bounds:y,plan:t}),Ak=t=>e=>n=>r=>o=>i=>a=>Wp(o)(i)(a)({owner:Lo("TokenText",t),text:n,spec:{x:i.x,y:i.y,content:Dn(n),font:{family:e.fontFamily,size:11,weight:500},color:e.chipText,align:Aa,baseline:Fn},bounds:T("Just",o),plan:ha("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:rn,lineCap:Mn},leader:[1,i.x,o.y+o.h,2,r.x+r.w/2,r.y]})}),Ik={offset:.8,passes:2,rMax:5},e1=t=>e=>n=>r=>Se({path:[],role:ln,layer:T("Just",rw),effects:[pe("GroupClip",Ck(n)(t.nodes)(r),Bc)]})(t1(Jp)(U_)(e.wobble)(t.nodes)(t.edges)(r)(e.tokenOutsideFill)(e.tokenOutsideStroke)),Hp=t=>e=>n=>r=>{if(n.tokenInsideBlend==="Difference"){const o=XL(e),i=a=>{const s=Se({path:[],role:ln,layer:T("Just",ow),effects:[pe("GroupBlend",au),pe("GroupClip",Z_(t.nodes)(r),ei)]})(t1(wp)(a==="ConvexAbsorb"?Nk:U_)(n.wobble)(t.nodes)(t.edges)(r)(n.tokenInside)(n.tokenInsideStroke)),u=()=>Se({path:[],role:ln,layer:T("Just",iw),effects:[]})(nr(g=>{const _=me(g._1)(r.nodes);return _.tag==="Just"&&mi(_._1).alpha>0?wi(yi({path:wo(g._2),fill:T("Just",{color:we,flat:!1}),stroke:y})):j(st("Return",void 0),gt)})(dn(t.nodes)));return j(s._1,(()=>{if(s._2.tag==="CatNil")return et("CatCons",u,tt(A,A));if(s._2.tag==="CatCons")return et("CatCons",s._2._1,tt(s._2._2._1,Jt("Cons",et("CatCons",u,tt(A,A)),s._2._2._2)));c()})())};return j(o._1,(()=>{if(o._2.tag==="CatNil")return et("CatCons",i,tt(A,A));if(o._2.tag==="CatCons")return et("CatCons",o._2._1,tt(o._2._2._1,Jt("Cons",et("CatCons",i,tt(A,A)),o._2._2._2)));c()})())}if(n.tokenInsideBlend==="Normal")return Se({path:[],role:ln,layer:y,effects:[pe("GroupClip",Z_(t.nodes)(r),ei),pe("GroupAlpha",n.tokenInsideAlpha)]})(t1(wp)(U_)(n.wobble)(t.nodes)(t.edges)(r)(n.tokenInside)(n.tokenInsideStroke));c()},$p=t=>e=>n=>r=>t.strokePath((()=>{const o=Bt(i=>y,i=>a=>T("Just",{head:i,tail:a}),K(i=>i.pt)(sy(i=>a=>{const s=ot(a)/ot(72),u=Pe(-.18)(.18)(i.prng),g=Pe(-.1)(.1)(u.prng),_=Pe(-.07)(.07)(g.prng),f=n*(.05+.55*s)*(1+g.value),l=s*28.274333882308138+u.value;return{prng:_.prng,pt:{x:e.x+xn(l)*f+_.value*n,y:e.y+en(l)*f+_.value*n}}},{prng:137,pt:{x:e.x,y:e.y}},Ut(0,72))));if(o.tag==="Just")return[1,o._1.head.x,o._1.head.y,...Jk(i=>[2,i.x,i.y])(o._1.tail)];if(o.tag==="Nothing")return[];c()})())({color:r,width:5.5,lineJoin:rn,lineCap:Ar}),zk=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?$p(t)(n.geometry._1._1)(n.geometry._1._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath($l(n.geometry._1._1)(n.geometry._1._2))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:rn,lineCap:Mn});if(n.geometry._1.tag==="PolyShape")return n.plan._1.wobble&&n.geometry._1._1.length>=3?$p(t)(Mc(n.geometry._1._1))(6)({r:200,g:35,b:30,a:220}):n.geometry._1._1.length>=3?t.fillStrokePath(Wl(n.geometry._1._1))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:rn,lineCap:Mn}):e.pure();c()}return e.pure()}},Dk=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popClip,i=t.popTransform,a=t.popAlpha;return s=>u=>g=>_=>f=>{const l=mi(f),d=g*l.alpha,h={..._,y:_.y+5},m=_.x+_.w/2,p=_.y+_.h/2,x=Qp(h),J=r.bind(t.pushAlpha(d))(()=>r.bind(t.pushTransform({tx:m*(1-l.scale),ty:p*(1-l.scale),sx:l.scale,sy:l.scale}))(()=>r.bind(t.pushClip(x)(Bc))(()=>r.bind(ni(t)(h.shape)({x:h.x,y:h.y,w:h.w,h:h.h})(7)(T("Just",{color:s.shadowFill,flat:!0}))(y))(()=>r.bind((()=>{const w=r.bind(t.pushClip(wo(h))(ei))(()=>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?w:n.pure()})())(()=>r.bind(ni(t)(h.shape)({x:h.x,y:h.y,w:h.w,h:h.h})(7)(y)(T("Just",{color:s.nodeStroke,width:1.25,lineJoin:rn,lineCap:Mn})))(()=>r.bind(o)(()=>r.bind(i)(()=>a))))))));return d>0&&!s.wobble?J:n.pure()}},Fk=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=vi(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:rn,lineCap:Ar}))(()=>r)))(mk(Ep(a)+7777|0)(a)(s))},Mk=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=e.Applicative0(),i=vi(o),a=t.popClip,s=vi(o),u=xr.traverse(o),g=kk(t),_=Fk(t),f=t.popTransform;return l=>d=>h=>m=>p=>x=>J=>w=>N=>L=>{const C=D=>n.bind(t.pushAlpha(D.alpha))(()=>n.bind(t.strokePath(D.path)({color:h.nodeStroke,width:2,lineJoin:rn,lineCap:Ar}))(()=>r)),R={family:h.fontFamily,size:h.wobble?15:11,weight:h.wobble?800:500},P=wn(N.label===""?w:N.label),I=R.size*1.2,U=N.shape==="Cylinder"?t.strokePath(mw({x:N.x,y:N.y,w:N.w,h:N.h}))({color:h.nodeStroke,width:1.25,lineJoin:rn,lineCap:Mn}):o.pure(),S=(N.shape==="Cylinder"?(N.y+(N.y+N.h+5-2*En(N.h*.075)(N.w*.075)))/2:(N.y+N.y+N.h)/2)-ot(P.length)*I/2+I/2,v=L.tag==="PloppingOut"&&h.wobble?L._1:-1,F=v>=0,H=mi(L),M=F?{alpha:1,scale:1}:H,q=N.x+N.w/2,$=N.y+N.h/2,B=n.bind(t.pushAlpha(M.alpha))(()=>n.bind(t.pushTransform({tx:q*(1-M.scale),ty:$*(1-M.scale),sx:M.scale,sy:M.scale}))(()=>{const D={x:N.x,y:N.y,w:N.w,h:N.h},Q={color:h.nodeStroke,width:h.wobble?2:1.25*d,lineJoin:rn,lineCap:h.wobble?Ar:Mn},O=(()=>{if(h.wobble){if(N.shape==="Rectangle")return i(C)(pk(Pp)(Ep(D))(D));const z=ri(7)(N);return n.bind(i(C)((()=>{const Y=ss(z);return z.length<4?[]:pa(Sp)(Y)(!0)(z)})()))(()=>s(Y=>i(C)((()=>{const V=ss(Y);return Y.length<2?[]:pa(Sp)(V)(!1)(Y)})()))(N.shape==="Cylinder"?[Ew(N)]:[]))}return n.bind(ni(t)(N.shape)(D)(7)(y)(T("Just",Q)))(()=>U)})();return n.bind((()=>{if(p.tag==="Nothing")return n.bind(t.pushAlpha(m))(()=>n.bind(h.wobble?O:n.bind(ni(t)(N.shape)(D)(7)(T("Just",{color:h.nodeFill,flat:!1}))(T("Just",Q)))(()=>U))(()=>n.bind((()=>{if(J.tag==="Just"&&h.wobble&&!F){const z=J._1;return n.bind(u(g(R))(P))(Y=>{const V=Rt(yt=>Ct=>at.compare(yt.x)(Ct.x)),X=he(sr(N.x*7919+N.y*3001))*-1640531535|0,Z=Pe(5)(7.5)(X),nt=Pe(0)(Z.value)(Z.prng),rt=-(1+2*Pe(-1)(1)(nt.prng).value*3.141592653589793/180),ft=(yt,Ct,Ot,Dt,se)=>V(ht(_e=>_e)([rt*Ct+yt>=Dt&&rt*Ct+yt<=se?T("Just",{x:Ct,y:rt*Ct+yt}):y,rt*Ot+yt>=Dt&&rt*Ot+yt<=se?T("Just",{x:Ot,y:rt*Ot+yt}):y,(()=>{const _e=(Dt-yt)/rt;return _e>=Ct&&_e<=Ot?T("Just",{x:_e,y:Dt}):y})(),(()=>{const _e=(se-yt)/rt;return _e>=Ct&&_e<=Ot?T("Just",{x:_e,y:se}):y})()])),Nt=Z.value,lt=lo(z.frameHash)(3),mt=lt===0?{r:200,g:35,b:30,a:220}:lt===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},vt=N.x+N.w/2,Ht=kn(Ft(yt=>Ct=>Ft((()=>{const Ot=S+ot(yt)*I,Dt=vt-b(se=>_e=>se+_e.w)(0)(Ct)/2;return se=>_e=>{const pn=R.size*.1,qt=se-1|0,jt=qt>=0&&qt<Ct.length&&se>0?(Ct[qt].x+Ct[qt].w+_e.x)/2:_e.x-pn;return{x:Dt+jt-1,y:Ot-_e.up-1,w:yr(0)((()=>{const sn=se+1|0;return sn>=0&&sn<Ct.length&&se<(Ct.length-1|0)?(_e.x+_e.w+Ct[sn].x)/2-jt:_e.x+_e.w+pn-jt})())+2,h:_e.up+_e.down+2}}})())(Ct))(Y)),Tt=N.y+4,Vt=N.x+N.w-4,Gt=N.x+4,bt=Tt-rt*Gt+nt.value,pt=N.y+N.h-4,ct=St(St(Ft(yt=>Ct=>{const Ot=(Ct.from.x+Ct.to.x)/2,Dt=(Ct.from.y+Ct.to.y)/2,se=Pe(-1)(1)(X+(911*(yt+1|0)|0)|0),_e=Pe(-3)(5)(se.prng),pn=se.value*3.141592653589793/180,qt=xn(pn),jt=en(pn),sn=$e=>({x:Ot+($e.x-Ot)*qt-($e.y-Dt)*jt,y:Dt+($e.x-Ot)*jt+($e.y-Dt)*qt});return{from:(()=>{const $e=sn(Ct.from),Vn=$e.y-Dt,Un=$e.x-Ot,je=qe(Un*Un+Vn*Vn),ge=je<1e-4?1:(je+_e.value)/je;return{x:Ot+Un*ge,y:Dt+Vn*ge}})(),to:(()=>{const $e=sn(Ct.to),Vn=Pe(-3)(5)(_e.prng).value,Un=$e.y-Dt,je=$e.x-Ot,ge=qe(je*je+Un*Un),be=ge<1e-4?1:(ge+Vn)/ge;return{x:Ot+je*be,y:Dt+Un*be}})()}})(ht(yt=>{const Ct=ft(bt+ot(yt)*Nt,Gt,Vt,Tt,pt);return Ct.length===2?T("Just",{from:Ct[0],to:Ct[1]}):y})(Ut(0,so(1)(he(sr((pt-rt*Vt-bt)/Nt)))))))(yt=>_t(Ct=>Ct.to.x-Ct.from.x>1,b(Ct=>Ot=>St(Ct)(Dt=>{const se=ft(Dt.from.y-rt*Dt.from.x,Ot.x,Ot.x+Ot.w,Ot.y,Ot.y+Ot.h);return se.length===2?se[0].x>Dt.from.x+.001&&se[1].x<Dt.to.x-.001?[{from:Dt.from,to:se[0]},{from:se[1],to:Dt.to}]:se[0].x<=Dt.from.x+.001&&se[1].x<Dt.to.x-.001?[{from:se[1],to:Dt.to}]:se[0].x>Dt.from.x+.001&&se[1].x>=Dt.to.x-.001?[{from:Dt.from,to:se[0]}]:[]:[Dt]}))([yt])(Ht))))(yt=>(()=>{const Ct=yt.to.x-yt.from.x;return qe(2)*(Ct>=0?Ct:-Ct)<=28})()?[yt]:[{from:yt.from,to:{x:yt.from.x+(yt.to.x-yt.from.x)*.495,y:yt.from.y+(yt.to.y-yt.from.y)*.495}},{from:{x:yt.from.x+(yt.to.x-yt.from.x)*.505,y:yt.from.y+(yt.to.y-yt.from.y)*.505},to:yt.to}]),wt=ct.length,It=yt=>yr(0)(bi(1)(z.t*ot(wt)-ot(yt)));return n.bind(t.pushClip(Wl(ri(7)(N)))(ei))(()=>n.bind(i(yt=>{const Ct=yt._1,Ot=Pe(1.4)(1.9)(X+(1303*(Ct+1|0)|0)|0),Dt=Pe(.35)(.8)(Ot.prng),se=i(_e=>n.bind(t.pushAlpha(_e.alpha*Dt.value))(()=>n.bind(t.strokePath(Rp(It(Ct))(_e.path))({color:mt,width:Ot.value,lineJoin:rn,lineCap:Ar}))(()=>r)))(pa({...Pp,rMax:0,offset:.5})(X+(53*(Ct+1|0)|0)|0)(!1)([yt._2.from,yt._2.to]));return It(Ct)>0?se:o.pure()})(Ft(mn)(ct)))(()=>a))})}return o.pure()})())(()=>n.bind((()=>{if(l==="LabelsShown"){const z=n.bind(t.pushAlpha(x))(()=>n.bind(i(Y=>t.drawText({x:N.x+N.w/2,y:S+ot(Y._1)*I,content:Y._2,font:R,color:h.text,align:Aa,baseline:Fn}))(Ft(mn)(P)))(()=>r));return x>0?z:o.pure()}if(l==="LabelsHidden")return o.pure();c()})())(()=>n.bind((()=>{const z=_(h)(D)(v);return F?z:o.pure()})())(()=>r)))));if(p.tag==="Just"){const z=p._1;return n.bind((()=>{const Y=n.bind(t.pushAlpha(m))(()=>n.bind(ni(t)(N.shape)(D)(7)(T("Just",{color:h.nodeFill,flat:!1}))(y))(()=>r));return m>0&&!h.wobble?Y:o.pure()})())(()=>{const Y=n.bind(t.pushAlpha(z))(()=>n.bind(O)(()=>r));return z>0?Y:o.pure()})}c()})())(()=>n.bind(f)(()=>r))}));return M.alpha*yr(m)((()=>{if(p.tag==="Nothing")return m;if(p.tag==="Just")return p._1;c()})())>0?B:o.pure()}},qp=t=>e=>n=>r=>nr(o=>{const i=Or(o._1)(r.edges);if(i.tag==="Just"){const a=Or(o._1)(r.edgeFadeAlpha),s=(()=>{if(a.tag==="Nothing")return 1;if(a.tag==="Just")return a._1;c()})(),u=vp({id:o._1,geometry:lp("FlatRoute",(()=>{const g=Or(o._1)(t.edges);if(g.tag==="Nothing")return o._2;if(g.tag==="Just")return g._1;c()})()),visible:BL(i._1),arrow:(()=>{const g=Jr("conn:")(o._1);if(g.tag==="Just")return!1;if(g.tag==="Nothing")return!0;c()})(),settlingAtTarget:i._1.tag==="Extending"&&i._1._1==="ExtendFromSource",plan:dp("FlatEdgePlan",e)});return s===1?u:Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",s)]})(u)}if(i.tag==="Nothing")return j(st("Return",void 0),gt);c()})(dn(n.edges)),Qk=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popClip,i=t.popTransform,a=t.popAlpha;return s=>u=>g=>_=>f=>{const l=mi(f),d=g*l.alpha,h=_.x+_.w/2,m=_.y-5+_.h/2,p=Qp(_),x=r.bind(t.pushAlpha(d))(()=>r.bind(t.pushTransform({tx:h*(1-l.scale),ty:m*(1-l.scale),sx:l.scale,sy:l.scale}))(()=>r.bind(t.pushClip(p)(Bc))(()=>r.bind(ni(t)(_.shape)({x:_.x,y:_.y,w:_.w,h:_.h})(7)(T("Just",{color:s.shadowFill,flat:!0}))(y))(()=>r.bind((()=>{const J=r.bind(t.pushClip(wo(_))(ei))(()=>r.bind(t.backgroundDots({viewport:{vx:_.x,vy:_.y,vw:_.w,vh:_.h},bgColor:s.bgTransparent,dotColor:s.shadowDot,tile:1.6,dotRadius:.25,origin:{x:0,y:0}}))(()=>o));return u?J:n.pure()})())(()=>r.bind(ni(t)(_.shape)({x:_.x,y:_.y,w:_.w,h:_.h})(7)(y)(T("Just",{color:s.nodeStroke,width:1.25,lineJoin:rn,lineCap:Mn})))(()=>r.bind(o)(()=>r.bind(i)(()=>a))))))));return d>0&&!s.wobble?x:n.pure()}},Wk=t=>{const e=Dk(t),n=Qk(t),r=Mk(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(Uu)(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);c()}return t.Monad0().Applicative0().pure()}},Ok=t=>e=>{const n=tr(t),r=n.length,o=tr(e),i=o.length,a=Ek(n)(o);return(s=>u=>g=>{let _=s,f=u,l=g,d=!0,h;for(;d;){const m=_,p=f,x=l;if(m>=r&&p>=i){d=!1,h=re(x);continue}if(m>=r){if(p>=0&&p<o.length){_=m,f=p+1|0,l=[us("DiffInsert",p,o[p]),...x];continue}d=!1,h=re(x);continue}if(p>=i){if(m>=0&&m<n.length){_=m+1|0,f=p,l=[us("DiffDelete",m,n[m]),...x];continue}d=!1,h=re(x);continue}if(p>=0&&p<o.length){if(m>=0&&m<n.length){if(n[m]===o[p]){_=m+1|0,f=p+1|0,l=[us("DiffKeep",m,p,n[m]),...x];continue}if(cs(a)(m+1|0)(p)>=cs(a)(m)(p+1|0)){_=m+1|0,f=p,l=[us("DiffDelete",m,n[m]),...x];continue}_=m,f=p+1|0,l=[us("DiffInsert",p,o[p]),...x];continue}d=!1,h=re(x);continue}d=!1,h=re(x)}return h})(0)(0)([])},Vp=t=>e=>n=>r=>o=>nr(i=>{if(t.tag==="Just"&&i._1===t._1)return j(st("Return",void 0),gt);const a=me(i._1)(o.nodes);if(a.tag==="Just"){const s=me(i._1)(o.nodeLabels),u=(()=>{if(s.tag==="Nothing")return i._2;if(s.tag==="Just"){if(s._1.tag==="StaticNodeLabel")return{...i._2,label:s._1._1===""?i._1:s._1._1};if(s._1.tag==="RelabelingNode")return{...i._2,label:(()=>{const g=s._1._1.progress<.5?s._1._1.oldLabel:s._1._1.newLabel;return g===""?i._1:g})()}}c()})();return Xu({id:i._1,role:$L,geometry:$u("FlatNode",{shape:u.shape,bounds:{x:u.x,y:u.y,w:u.w,h:u.h}}),alpha:(()=>{const g=me(i._1)(o.nodeFadeAlpha),_=(()=>{if(g.tag==="Nothing")return 1;if(g.tag==="Just")return g._1;c()})();return _<1?0:_})(),plan:qu("FlatNodePlan",{palette:e,label:(()=>{const g=me(i._1)(o.nodeLabels);if(g.tag==="Just"){if(g._1.tag==="StaticNodeLabel")return g._1._1===""?i._1:g._1._1;if(g._1.tag==="RelabelingNode"){const _=g._1._1.progress<.5?g._1._1.oldLabel:g._1._1.newLabel;return _===""?i._1:_}c()}if(g.tag==="Nothing")return u.label===""?i._1:u.label;c()})(),labelVisibility:Uu,inkBoost:n?1:0,labelAlpha:0,outlineAlpha:y,arrival:y,animState:a._1})})}if(a.tag==="Nothing")return j(st("Return",void 0),gt);c()})(dn(r.nodes)),Up=t=>{const e=n=>{if(n.tag==="Leaf")return W;if(n.tag==="Node")return ee("Node",n._1,n._2,n._3,$_({x:t.vx,y:t.vy,w:t.vw,h:t.vh})(n._4),e(n._5),e(n._6));c()};return e},Hk=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=vi(r);return i=>a=>s=>u=>g=>_=>{const f=Ke(_).length,l=ot(f+1|0),d=p=>{const x=(s*l-ot(p))/1.5,J=x<0?0:x>1?1:x;return J*J*(3-2*J)},h=(p=>{let x=p,J=!0,w;for(;J;){const N=x;if(N>=f){J=!1,w=N;continue}if(d(N)>=1){x=N+1|0;continue}J=!1,w=N}return w})(0),m=h>=f?[]:Pr(p=>d(p)>0)(Ut(h,f-1|0)).init;return n.bind((()=>{const p=t.drawText({x:u,y:g,content:Ve(h)(_),font:i,color:a,align:wr,baseline:Fn});return h>0?p:r.pure()})())(()=>o(p=>n.bind(t.measureText(i)(Ve(p)(_)))(x=>{const J=d(p);return t.drawText({x:u+x,y:g-(1-J)*10,content:Ve(1)(Qi(zn(Ve(p)(_)))(_)),font:i,color:{...a,a:he(sr(J*ot(a.a)))},align:wr,baseline:Fn})}))(m))}},$k=t=>e=>n=>r=>o=>i=>a=>Wp(r)(o)(i)({owner:Lo("TokenText",t),text:n.line,spec:{x:o.x,y:o.y,content:Dn(n.line),font:{family:e.fontFamily,size:11,weight:500},color:e.chipPillText,align:wr,baseline:Fn},bounds:T("Just",r),plan:ha("TokenTravelText",{trail:Sk(r)(a),trailFill:{color:e.trailDot,flat:!0},radius:3,fill:{color:e.chipPillFill,flat:!0},textLeft:r.x+14,reveal:(()=>{const s=n.phaseInLabel/.45;return s<0?0:s>1?1:s})()})}),ju=t=>e=>n=>r=>{const o=K(d=>ot(so(1)(Ke(d).length)))(r),i=yr(1)(b(ur)(0)(o)),a=as(e)(n)(t),s=a*i,u=so(1)(r.length),g=(d=>h=>m=>{let p=d,x=h,J=m,w=!0,N;for(;w;){const L=p,C=x,R=Bt(P=>y,P=>I=>T("Just",{head:P,tail:I}),J);if(R.tag==="Nothing"){w=!1,N=so(0)(u-1|0);continue}if(R.tag==="Just"){if(C+R._1.head>=s){w=!1,N=L;continue}p=L+1|0,x=C+R._1.head,J=R._1.tail;continue}c()}return N})(0)(0)(o),_=b(ur)(0)(g<1?[]:At(0,g,o)),f=_/i;if(g>=0&&g<o.length){const d=(_+o[g])/i;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(d<=f)return 1;const h=(a-f)/(d-f);return h<0?0:h>1?1:h})()}}const l=(_+1)/i;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(l<=f)return 1;const d=(a-f)/(l-f);return d<0?0:d>1?1:d})()}},Xp=t=>e=>n=>r=>o=>t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(ju(r)(0)(0)(K(wa)(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})}),qk=t=>{const e=t.Bind1(),n=t.Applicative0(),r=xr.traverse(n);return o=>i=>a=>e.Apply0().Functor0().map(s=>Ip(ht(u=>u)(s)))(r(s=>{if(s._2.tag==="Filling"&&s._2._1.labels.length!==0){const u=me(s._2._1.node)(i);if(u.tag==="Just")return e.bind(Xp(t)(o)(u._1)(s._2._1.progress)(s._2._1.labels))(g=>n.pure(T("Just",E(s._1,g))));if(u.tag==="Nothing")return n.pure(y);c()}return n.pure(y)})(dn(a.tokens)))},Vk=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const g=X_(n)(r)(o)(i)(a)(s);return t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(ju(i)(a)(s)(St(u)(j_)).line))(_=>t.Applicative0().pure({x:g.x+14+_/2-_/2-14,y:g.y-6-8-6.6-6,w:_+28,h:25.2}))},Uk=t=>{const e=t.Bind1(),n=t.Applicative0(),r=xr.traverse(n);return o=>i=>a=>s=>e.Apply0().Functor0().map(u=>Ip(ht(g=>g)(u)))(r(u=>{if(u._2.tag==="Travelling"&&u._2._1.labels.length!==0){const g=me(u._2._1.target)(i),_=me(u._2._1.source)(i),f=Or(u._2._1.edge)(a);if(f.tag==="Just"&&_.tag==="Just"&&g.tag==="Just"){const l=(()=>{if(u._2._1.direction==="Forward")return f._1;if(u._2._1.direction==="Backward")return re(f._1);c()})(),d=X_(l)(_._1)(g._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost);return e.bind(Vk(t)(o)(l)(_._1)(g._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost)(u._2._1.labels))(h=>n.pure(T("Just",E(u._1,{id:u._1,rect:h,token:d}))))}}return n.pure(y)})(dn(s.tokens)))},Kp=t=>{const e=t.Bind1(),n=Uk(t),r=qk(t);return o=>i=>a=>s=>e.bind(n(o)(a.nodes)(a.edges)(s))(u=>e.bind(r(o)(a.nodes)(s))(g=>t.Applicative0().pure(ok({x:i.vx,y:i.vy,w:i.vw,h:i.vh})([...ht(_=>{const f=me(_._1)(s.nodes);return f.tag==="Just"&&mi(f._1).alpha>0?T("Just",{x:_._2.x,y:_._2.y,w:_._2.w,h:_._2.h}):y})(dn(a.nodes)),...(()=>{const _=(f,l)=>{if(f.tag==="Leaf")return l;if(f.tag==="Node")return _(f._5,Jt("Cons",f._4,_(f._6,l)));c()};return Mt(ce.foldr,_(g,A))})()])(ht(_=>zp(_)(u))((()=>{const _=f=>{if(f.tag==="Leaf")return W;if(f.tag==="Node")return ee("Node",f._1,f._2,f._3,void 0,_(f._5),_(f._6));c()};return Rt(G.compare)(Mt(Jn.foldr,_(u)))})())))))},Xk=Kp(Lc),Yp=t=>{const e=Kp(t);return n=>r=>o=>e(n)(r)(K_(o))},n1=t=>e=>n=>{const r=(e*ot(t+1|0)-ot(n))/1.5,o=r<0?0:r>1?1:r;return o*o*(3-2*o)},Zp=t=>e=>n=>{const r=Ko(6)(.55)(Zu(0)(1)((1-t)/.06)),o=t>.94,i=o&&n>1e-4,a=Ko(6)(.55)(Zu(0)(1)(t/.06)),s=t<.06,u=s&&e>1e-4,g=o&&n<=1e-4;return{popScale:u?a:i?r:1,flipY:s&&e<=1e-4?a:g?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})()}},tg=t=>e=>n=>r=>Se({path:[],role:ln,layer:T("Just",aw),effects:[]})(nr((()=>{const o=t.nodes,i=t.edges;return a=>{if(a._2.tag==="Travelling"){if(a._2._1.labels.length!==0){const s=me(a._2._1.target)(o),u=me(a._2._1.source)(o),g=Or(a._2._1.edge)(i),_=zp(a._1)(r);if(_.tag==="Just"&&g.tag==="Just"&&u.tag==="Just"&&s.tag==="Just")return $k(a._1)(e)(ju(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(St(a._2._1.labels)(j_)))(_._1)({x:_._1.x+_._1.w/2,y:_._1.y+_._1.h/2})(Zp(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost))(X_((()=>{if(a._2._1.direction==="Forward")return g._1;if(a._2._1.direction==="Backward")return re(g._1);c()})())(u._1)(s._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost))}return j(st("Return",void 0),gt)}if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const s=me(a._2._1.node)(o);if(s.tag==="Just"){const u=s._1,g=Xp(Lc)(Np)(u)(a._2._1.progress)(a._2._1.labels),_=f=>Ak(a._1)(e)(ju(a._2._1.progress)(0)(0)(St(a._2._1.labels)(j_)).line)(u)(f)({x:f.x+f.w/2,y:f.y+f.h/2})(Zp(a._2._1.progress)(0)(0));return j(g._1,(()=>{if(g._2.tag==="CatNil")return et("CatCons",_,tt(A,A));if(g._2.tag==="CatCons")return et("CatCons",g._2._1,tt(g._2._2._1,Jt("Cons",et("CatCons",_,tt(A,A)),g._2._2._2)));c()})())}if(s.tag==="Nothing")return j(st("Return",void 0),gt);c()}return j(st("Return",void 0),gt)}})())(dn(n.tokens))),jp=t=>e=>n=>r=>{const o=Xk(Np)(n)(t)(r);return j(o._1,(()=>{if(o._2.tag==="CatNil")return et("CatCons",i=>tg(t)(e)(r)(i),tt(A,A));if(o._2.tag==="CatCons")return et("CatCons",o._2._1,tt(o._2._2._1,Jt("Cons",et("CatCons",i=>tg(t)(e)(r)(i),tt(A,A)),o._2._2._2)));c()})())},Kk=t=>e=>n=>{const r={family:t.fontFamily,size:11,weight:500},o=i=>a=>s=>u=>g=>_=>{const f=Bt(d=>y,d=>h=>T("Just",{head:d,tail:h}),_),l=Bt(d=>y,d=>h=>T("Just",{head:d,tail:h}),g);if(l.tag==="Just"&&f.tag==="Just"){const d=Ti({owner:Lo("EdgeText",i),text:l._1.head.text,spec:{x:s,y:a.y+a.h/2,content:l._1.head.text,font:(()=>{const h=l._1.head.style==="RunCode"||l._1.head.style==="RunCodeBold"||l._1.head.style==="RunCodeHighlight"||l._1.head.style==="RunCodeBoldHighlight"?{...r,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:r;return l._1.head.style==="RunBold"||l._1.head.style==="RunCodeBold"||l._1.head.style==="RunBoldHighlight"||l._1.head.style==="RunCodeBoldHighlight"?{...h,weight:700}:h})(),color:t.chipPillText,align:wr,baseline:Fn},bounds:T("Just",a),plan:u?ha("RoundedText",{radius:3,fill:T("Just",{color:t.chipPillFill,flat:!0}),stroke:y}):W_});return j(d._1,(()=>{if(d._2.tag==="CatNil")return et("CatCons",()=>o(i)(a)(s+f._1.head)(!1)(l._1.tail)(f._1.tail),tt(A,A));if(d._2.tag==="CatCons")return et("CatCons",d._2._1,tt(d._2._2._1,Jt("Cons",et("CatCons",()=>o(i)(a)(s+f._1.head)(!1)(l._1.tail)(f._1.tail),tt(A,A)),d._2._2._2)));c()})())}return j(st("Return",void 0),gt)};return nr(i=>{if(i._2===""||(()=>{const u=Or(i._1)(n.edges);return u.tag==="Nothing"||!(u.tag==="Just"&&UT.eq(u._1)(xu))})())return j(st("Return",void 0),gt);const a=Or(i._1)(e.edges),s=(()=>{if(a.tag==="Just")return ti(a._1)(.5);if(a.tag==="Nothing")return y;c()})();if(s.tag==="Nothing")return j(st("Return",void 0),gt);if(s.tag==="Just"){const u=s._1,g=Sn(i._2),_=gs(l=>{const d=l.style==="RunCode"||l.style==="RunCodeBold"||l.style==="RunCodeHighlight"||l.style==="RunCodeBoldHighlight"?{...r,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:r;return xo(l.style==="RunBold"||l.style==="RunCodeBold"||l.style==="RunBoldHighlight"||l.style==="RunCodeBoldHighlight"?{...d,weight:700}:d)(l.text)})(g),f=l=>{const d=So(l),h=d+12;return o(i._1)({x:u.x-h/2,y:u.y-8.5,w:h,h:17})(u.x-d/2)(!0)(g)(l)};return j(_._1,(()=>{if(_._2.tag==="CatNil")return et("CatCons",f,tt(A,A));if(_._2.tag==="CatCons")return et("CatCons",_._2._1,tt(_._2._2._1,Jt("Cons",et("CatCons",f,tt(A,A)),_._2._2._2)));c()})())}c()})(dn(e.edgeLabels))},Yk=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=xr.traverse(r);return i=>a=>s=>u=>g=>{const _=l=>d=>h=>{const m=Bt(x=>y,x=>J=>T("Just",{head:x,tail:J}),h),p=Bt(x=>y,x=>J=>T("Just",{head:x,tail:J}),d);if(p.tag==="Just"&&m.tag==="Just"){const x=p._1,J=m._1;return n.bind(t.drawText({x:l,y:u,content:x.head.text,font:(()=>{const w=x.head.style==="RunCode"||x.head.style==="RunCodeBold"||x.head.style==="RunCodeHighlight"||x.head.style==="RunCodeBoldHighlight"?{...i,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:i;return x.head.style==="RunBold"||x.head.style==="RunCodeBold"||x.head.style==="RunBoldHighlight"||x.head.style==="RunCodeBoldHighlight"?{...w,weight:700}:w})(),color:a,align:wr,baseline:Fn}))(()=>_(l+J.head)(x.tail)(J.tail))}return r.pure()},f=Sn(g);return n.bind(o(l=>t.measureText((()=>{const d=l.style==="RunCode"||l.style==="RunCodeBold"||l.style==="RunCodeHighlight"||l.style==="RunCodeBoldHighlight"?{...i,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:i;return l.style==="RunBold"||l.style==="RunCodeBold"||l.style==="RunBoldHighlight"||l.style==="RunCodeBoldHighlight"?{...d,weight:700}:d})())(l.text))(f))(l=>_(s-So(l)/2)(f)(l))}},Zk=t=>{const e=t.Monad0(),n=e.Bind1(),r=Hk(t),o=e.Applicative0(),i=xr.traverse(o);return a=>s=>u=>g=>_=>f=>{const l=so(1)(Ke(Dn(f)).length),d=m=>p=>x=>J=>{const w=Bt(L=>y,L=>C=>T("Just",{head:L,tail:C}),J),N=Bt(L=>y,L=>C=>T("Just",{head:L,tail:C}),x);if(N.tag==="Just"&&w.tag==="Just"){const L=N._1,C=w._1,R=so(1)(Ke(L.head.text).length);return n.bind(r((()=>{const P=L.head.style==="RunCode"||L.head.style==="RunCodeBold"||L.head.style==="RunCodeHighlight"||L.head.style==="RunCodeBoldHighlight"?{...a,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:a;return L.head.style==="RunBold"||L.head.style==="RunCodeBold"||L.head.style==="RunBoldHighlight"||L.head.style==="RunCodeBoldHighlight"?{...P,weight:700}:P})())(s)((()=>{const P=(u*ot(l)-ot(p))/ot(R);return P<0?0:P>1?1:P})())(m)(_)(L.head.text))(()=>d(m+C.head)(p+R|0)(L.tail)(C.tail))}return o.pure()},h=Sn(f);return n.bind(i(m=>t.measureText((()=>{const p=m.style==="RunCode"||m.style==="RunCodeBold"||m.style==="RunCodeHighlight"||m.style==="RunCodeBoldHighlight"?{...a,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:a;return m.style==="RunBold"||m.style==="RunCodeBold"||m.style==="RunBoldHighlight"||m.style==="RunCodeBoldHighlight"?{...p,weight:700}:p})())(m.text))(h))(m=>d(g)(0)(h)(m))}},jk=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=vi(r),i=Zk(t),a=Yk(t);return s=>{if(s.plan.tag==="PlainText")return t.drawText(s.spec);if(s.plan.tag==="RoundedText")return n.bind((()=>{const u=r.pure();if(s.bounds.tag==="Nothing")return u;if(s.bounds.tag==="Just")return t.drawRoundedRect(s.bounds._1)(s.plan._1.radius)(s.plan._1.fill)(s.plan._1.stroke);c()})())(()=>t.drawText(s.spec));if(s.plan.tag==="TokenTravelText"){const u=s.plan._1;return n.bind(o(g=>t.fillPath($l(g)(1.5))(u.trailFill))(u.trail))(()=>n.bind((()=>{const g=r.pure();if(s.bounds.tag==="Nothing")return g;if(s.bounds.tag==="Just")return t.drawRoundedRect(s.bounds._1)(u.radius)(T("Just",u.fill))(y);c()})())(()=>i(s.spec.font)(s.spec.color)(u.reveal)(u.textLeft)(s.spec.y)(s.text)))}if(s.plan.tag==="TokenFillingText"){const u=s.plan._1;return n.bind(t.drawRoundedRect(u.shadow)(u.radius)(T("Just",u.shadowFill))(y))(()=>n.bind((()=>{const g=r.pure();if(s.bounds.tag==="Nothing")return g;if(s.bounds.tag==="Just")return t.drawRoundedRect(s.bounds._1)(u.radius)(T("Just",u.fill))(T("Just",u.stroke));c()})())(()=>n.bind(t.strokePath(u.leader)(u.stroke))(()=>a(s.spec.font)(s.spec.color)(s.spec.x)(s.spec.y)(s.text))))}if(s.plan.tag==="AffineText")return t.drawTextAffine(s.plan._1)(s.spec);c()}},r1=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const g=Sn(u),_=l=>d=>h=>{const m=Bt(x=>y,x=>J=>T("Just",{head:x,tail:J}),h),p=Bt(x=>y,x=>J=>T("Just",{head:x,tail:J}),d);if(p.tag==="Just"&&m.tag==="Just"){const x=Op(t)(e)(n)(r)(o)((()=>{const J=p._1.head.style==="RunCode"||p._1.head.style==="RunCodeBold"||p._1.head.style==="RunCodeHighlight"||p._1.head.style==="RunCodeBoldHighlight"?{...i,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:i;return p._1.head.style==="RunBold"||p._1.head.style==="RunCodeBold"||p._1.head.style==="RunBoldHighlight"||p._1.head.style==="RunCodeBoldHighlight"?{...J,weight:700}:J})())(p._1.head.style)(l)(s)(p._1.head.text);return j(x._1,(()=>{if(x._2.tag==="CatNil")return et("CatCons",()=>_(l+m._1.head)(p._1.tail)(m._1.tail),tt(A,A));if(x._2.tag==="CatCons")return et("CatCons",x._2._1,tt(x._2._2._1,Jt("Cons",et("CatCons",()=>_(l+m._1.head)(p._1.tail)(m._1.tail),tt(A,A)),x._2._2._2)));c()})())}return j(st("Return",void 0),gt)};if(g.length===1&&g[0].style==="RunText")return Ti({owner:Lo("NodeText",o),text:g[0].text,spec:{x:a,y:s,content:g[0].text,font:i,color:r.text,align:Aa,baseline:Fn},bounds:y,plan:t});const f=gs(l=>{const d=l.style==="RunCode"||l.style==="RunCodeBold"||l.style==="RunCodeHighlight"||l.style==="RunCodeBoldHighlight"?{...i,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:i;return xo(l.style==="RunBold"||l.style==="RunCodeBold"||l.style==="RunBoldHighlight"||l.style==="RunCodeBoldHighlight"?{...d,weight:700}:d)(l.text)})(g);return j(f._1,(()=>{if(f._2.tag==="CatNil")return et("CatCons",l=>_(a-So(l)/2)(g)(l),tt(A,A));if(f._2.tag==="CatCons")return et("CatCons",f._2._1,tt(f._2._2._1,Jt("Cons",et("CatCons",l=>_(a-So(l)/2)(g)(l),tt(A,A)),f._2._2._2)));c()})())},t5=t=>e=>{const n=gs(r=>{const o=r.style==="RunCode"||r.style==="RunCodeBold"||r.style==="RunCodeHighlight"||r.style==="RunCodeBoldHighlight"?{...t,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:t;return xo(r.style==="RunBold"||r.style==="RunCodeBold"||r.style==="RunBoldHighlight"||r.style==="RunCodeBoldHighlight"?{...o,weight:700}:o)(r.text)})(Sn(e));return j(n._1,(()=>{if(n._2.tag==="CatNil")return et("CatCons",r=>j(st("Return",So(r)),gt),tt(A,A));if(n._2.tag==="CatCons")return et("CatCons",n._2._1,tt(n._2._2._1,Jt("Cons",et("CatCons",r=>j(st("Return",So(r)),gt),tt(A,A)),n._2._2._2)));c()})())},t0=t=>e=>n=>r=>{const o=wn(r===""?t:r),i=n.size*1.2,a=(e.shape==="Cylinder"?(e.y+(e.y+e.h+5-2*En(e.h*.075)(e.w*.075)))/2:(e.y+e.y+e.h)/2)-ot(o.length)*i/2+i/2,s=gs(t5(n))(o),u=g=>j(st("Return",Ft(_=>f=>({line:Dn(f),runs:Sn(f),left:_>=0&&_<g.length?e.x+e.w/2-g[_]/2:e.x+e.w/2-0,y:a+ot(_)*i}))(o)),gt);return j(s._1,(()=>{if(s._2.tag==="CatNil")return et("CatCons",u,tt(A,A));if(s._2.tag==="CatCons")return et("CatCons",s._2._1,tt(s._2._2._1,Jt("Cons",et("CatCons",u,tt(A,A)),s._2._2._2)));c()})())},e5=t=>e=>n=>{const r=gs(o=>{const i=o.style==="RunCode"||o.style==="RunCodeBold"||o.style==="RunCodeHighlight"||o.style==="RunCodeBoldHighlight"?{...t,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:t;return xo(o.style==="RunBold"||o.style==="RunCodeBold"||o.style==="RunBoldHighlight"||o.style==="RunCodeBoldHighlight"?{...i,weight:700}:i)(o.text)})(Mp(e)(n));return j(r._1,(()=>{if(r._2.tag==="CatNil")return et("CatCons",o=>j(st("Return",So(o)),gt),tt(A,A));if(r._2.tag==="CatCons")return et("CatCons",r._2._1,tt(r._2._2._1,Jt("Cons",et("CatCons",o=>j(st("Return",So(o)),gt),tt(A,A)),r._2._2._2)));c()})())},ma=t=>e=>n=>{const r=e5(t)(n)(e.runs);return j(r._1,(()=>{if(r._2.tag==="CatNil")return et("CatCons",o=>j(st("Return",e.left+o),gt),tt(A,A));if(r._2.tag==="CatCons")return et("CatCons",r._2._1,tt(r._2._2._1,Jt("Cons",et("CatCons",o=>j(st("Return",e.left+o),gt),tt(A,A)),r._2._2._2)));c()})())},n5=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const g=u<0?0:u>1?1:u,_=yr(8)(i.size*.9),f=(m,p,x,J,w)=>{const N=Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",m)]})(Op(t)(e)(1)(n)(r)((()=>{const L=w==="RunCode"||w==="RunCodeBold"||w==="RunCodeHighlight"||w==="RunCodeBoldHighlight"?{...i,family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",weight:400}:i;return w==="RunBold"||w==="RunCodeBold"||w==="RunBoldHighlight"||w==="RunCodeBoldHighlight"?{...L,weight:700}:L})())(w)(p)(x)(In(J)));return m>.001?N:j(st("Return",void 0),gt)},l=(m,p)=>{const x=Ke(m.line).length;return n1(x)(g)((x-p|0)-1|0)},d=t0(r)(o)(i)(a),h=m=>{const p=t0(r)(o)(i)(s),x=J=>nr(w=>{const N=w>=0&&w<m.length?T("Just",m[w]):y,L=w>=0&&w<J.length?T("Just",J[w]):y;return nr(C=>{if(C.tag==="DiffKeep"){if(N.tag==="Just"){if(L.tag==="Just"){const R=L._1,P=N._1,I=ma(i)(P)(C._1),U=S=>{const v=ma(i)(R)(C._2),F=H=>f(1,S+(H-S)*g,P.y+(R.y-P.y)*g,C._3,(()=>{if(g<.5){const q=St(P.runs)($=>Qo(Ke($.text).length,$.style));return C._1>=0&&C._1<q.length?q[C._1]:Gr}const M=St(R.runs)(q=>Qo(Ke(q.text).length,q.style));return C._2>=0&&C._2<M.length?M[C._2]:Gr})());return j(v._1,(()=>{if(v._2.tag==="CatNil")return et("CatCons",F,tt(A,A));if(v._2.tag==="CatCons")return et("CatCons",v._2._1,tt(v._2._2._1,Jt("Cons",et("CatCons",F,tt(A,A)),v._2._2._2)));c()})())};return j(I._1,(()=>{if(I._2.tag==="CatNil")return et("CatCons",U,tt(A,A));if(I._2.tag==="CatCons")return et("CatCons",I._2._1,tt(I._2._2._1,Jt("Cons",et("CatCons",U,tt(A,A)),I._2._2._2)));c()})())}if(L.tag==="Nothing"){const R=N._1,P=ma(i)(R)(C._1),I=U=>{const S=l(R,C._1);return f(1-S,U,R.y-_*S,C._3,(()=>{const v=St(R.runs)(F=>Qo(Ke(F.text).length,F.style));return C._1>=0&&C._1<v.length?v[C._1]:Gr})())};return j(P._1,(()=>{if(P._2.tag==="CatNil")return et("CatCons",I,tt(A,A));if(P._2.tag==="CatCons")return et("CatCons",P._2._1,tt(P._2._2._1,Jt("Cons",et("CatCons",I,tt(A,A)),P._2._2._2)));c()})())}c()}if(N.tag==="Nothing"){if(L.tag==="Just"){const R=L._1,P=ma(i)(R)(C._2),I=U=>{const S=n1(Ke(R.line).length)(g)(C._2);return f(S,U,R.y-_*(1-S),C._3,(()=>{const v=St(R.runs)(F=>Qo(Ke(F.text).length,F.style));return C._2>=0&&C._2<v.length?v[C._2]:Gr})())};return j(P._1,(()=>{if(P._2.tag==="CatNil")return et("CatCons",I,tt(A,A));if(P._2.tag==="CatCons")return et("CatCons",P._2._1,tt(P._2._2._1,Jt("Cons",et("CatCons",I,tt(A,A)),P._2._2._2)));c()})())}if(L.tag==="Nothing")return j(st("Return",void 0),gt)}c()}if(C.tag==="DiffDelete"){if(N.tag==="Just"){const R=N._1,P=ma(i)(R)(C._1),I=U=>{const S=l(R,C._1);return f(1-S,U,R.y-_*S,C._2,(()=>{const v=St(R.runs)(F=>Qo(Ke(F.text).length,F.style));return C._1>=0&&C._1<v.length?v[C._1]:Gr})())};return j(P._1,(()=>{if(P._2.tag==="CatNil")return et("CatCons",I,tt(A,A));if(P._2.tag==="CatCons")return et("CatCons",P._2._1,tt(P._2._2._1,Jt("Cons",et("CatCons",I,tt(A,A)),P._2._2._2)));c()})())}if(N.tag==="Nothing")return j(st("Return",void 0),gt);c()}if(C.tag==="DiffInsert"){if(L.tag==="Just"){const R=L._1,P=ma(i)(R)(C._1),I=U=>{const S=n1(Ke(R.line).length)(g)(C._1);return f(S,U,R.y-_*(1-S),C._2,(()=>{const v=St(R.runs)(F=>Qo(Ke(F.text).length,F.style));return C._1>=0&&C._1<v.length?v[C._1]:Gr})())};return j(P._1,(()=>{if(P._2.tag==="CatNil")return et("CatCons",I,tt(A,A));if(P._2.tag==="CatCons")return et("CatCons",P._2._1,tt(P._2._2._1,Jt("Cons",et("CatCons",I,tt(A,A)),P._2._2._2)));c()})())}if(L.tag==="Nothing")return j(st("Return",void 0),gt)}c()})(Ok((()=>{if(N.tag==="Nothing")return"";if(N.tag==="Just")return N._1.line;c()})())((()=>{if(L.tag==="Nothing")return"";if(L.tag==="Just")return L._1.line;c()})()))})(Ut(0,so(m.length)(J.length)-1|0));return j(p._1,(()=>{if(p._2.tag==="CatNil")return et("CatCons",x,tt(A,A));if(p._2.tag==="CatCons")return et("CatCons",p._2._1,tt(p._2._2._1,Jt("Cons",et("CatCons",x,tt(A,A)),p._2._2._2)));c()})())};return j(d._1,(()=>{if(d._2.tag==="CatNil")return et("CatCons",h,tt(A,A));if(d._2.tag==="CatCons")return et("CatCons",d._2._1,tt(d._2._2._1,Jt("Cons",et("CatCons",h,tt(A,A)),d._2._2._2)));c()})())},e0=t=>e=>n=>r=>o=>i=>a=>s=>u=>{const g=mi(s),_=s.tag==="PloppingOut"&&n.wobble?{alpha:1,scale:1}:g,f=wn((()=>{if(u.tag==="Just"){if(u._1.tag==="StaticNodeLabel")return u._1._1===""?i:u._1._1;if(u._1.tag==="RelabelingNode"){const J=u._1._1.progress<.5?u._1._1.oldLabel:u._1._1.newLabel;return J===""?i:J}c()}if(u.tag==="Nothing")return a.label===""?i:a.label;c()})()),l={family:n.fontFamily,size:n.wobble?15:11,weight:n.wobble?800:500},d=l.size*1.2,h=(a.shape==="Cylinder"?(a.y+(a.y+a.h+5-2*En(a.h*.075)(a.w*.075)))/2:(a.y+a.y+a.h)/2)-ot(f.length)*d/2+d/2,m=(J,w)=>{const N=Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",J)]})(nr(L=>r1(t)(e)(1)(n)(i)(l)(a.x+a.w/2)(h+ot(L._1)*d)(L._2))(Ft(mn)(wn(w))));return J>.001?N:j(st("Return",void 0),gt)},p=(J,w)=>nr(N=>r1(t)(e)(J)(n)(i)(l)(a.x+a.w/2)(h+ot(N._1)*d)(N._2))(Ft(mn)(wn(w))),x=Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",_.alpha*r),pe("GroupTransform",Ji,{tx:(a.x+a.w/2)*(1-_.scale),ty:(a.y+a.h/2)*(1-_.scale),sx:_.scale,sy:_.scale}),pe("GroupAlpha",o)]})((()=>{if(u.tag==="Just"&&u._1.tag==="RelabelingNode"&&Dn(u._1._1.oldLabel)===Dn(u._1._1.newLabel)&&!oe(J=>oe(w=>w.style==="RunHighlight"||w.style==="RunBoldHighlight"||w.style==="RunCodeHighlight"||w.style==="RunCodeBoldHighlight",Sn(J)),wn(u._1._1.oldLabel))&&oe(J=>oe(w=>w.style==="RunHighlight"||w.style==="RunBoldHighlight"||w.style==="RunCodeHighlight"||w.style==="RunCodeBoldHighlight",Sn(J)),wn(u._1._1.newLabel)))return p(u._1._1.progress<0?0:u._1._1.progress>1?1:u._1._1.progress,u._1._1.newLabel);if(u.tag==="Just"&&u._1.tag==="RelabelingNode"&&Dn(u._1._1.oldLabel)===Dn(u._1._1.newLabel)&&oe(J=>oe(w=>w.style==="RunHighlight"||w.style==="RunBoldHighlight"||w.style==="RunCodeHighlight"||w.style==="RunCodeBoldHighlight",Sn(J)),wn(u._1._1.oldLabel))&&!oe(J=>oe(w=>w.style==="RunHighlight"||w.style==="RunBoldHighlight"||w.style==="RunCodeHighlight"||w.style==="RunCodeBoldHighlight",Sn(J)),wn(u._1._1.newLabel)))return p(u._1._1.progress<0?1:u._1._1.progress>1?0:1-u._1._1.progress,u._1._1.oldLabel);if(u.tag==="Just"&&u._1.tag==="RelabelingNode"){if(Dn(u._1._1.oldLabel)===Dn(u._1._1.newLabel)){const J=u._1._1,w=m(J.progress<0?1:J.progress>1?0:1-J.progress,J.oldLabel),N=()=>m(J.progress<0?0:J.progress>1?1:J.progress,J.newLabel);return j(w._1,(()=>{if(w._2.tag==="CatNil")return et("CatCons",N,tt(A,A));if(w._2.tag==="CatCons")return et("CatCons",w._2._1,tt(w._2._2._1,Jt("Cons",et("CatCons",N,tt(A,A)),w._2._2._2)));c()})())}return n5(t)(e)(n)(i)(a)(l)(u._1._1.oldLabel)(u._1._1.newLabel)(u._1._1.progress)}return nr(J=>r1(t)(e)(1)(n)(i)(l)(a.x+a.w/2)(h+ot(J._1)*d)(J._2))(Ft(mn)(f))})());return o>0&&_.alpha*r>0?x:j(st("Return",void 0),gt)},n0=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>_=>f=>l=>{const d=Xu({id:g,role:t,geometry:$u("FlatNode",{shape:_.shape,bounds:{x:_.x,y:_.y,w:_.w,h:_.h}}),alpha:i,plan:qu("FlatNodePlan",{palette:o,label:(()=>{if(l.tag==="Just"){if(l._1.tag==="StaticNodeLabel")return l._1._1===""?g:l._1._1;if(l._1.tag==="RelabelingNode"){const m=l._1._1.progress<.5?l._1._1.oldLabel:l._1._1.newLabel;return m===""?g:m}c()}if(l.tag==="Nothing")return _.label===""?g:_.label;c()})(),labelVisibility:n,inkBoost:r,labelAlpha:s,outlineAlpha:a,arrival:u,animState:f})}),h=()=>{if(n==="LabelsHidden")return j(st("Return",void 0),gt);if(n==="LabelsShown")return e0(W_)(e)(o)(i)(s)(g)(_)(f)(l);c()};return j(d._1,(()=>{if(d._2.tag==="CatNil")return et("CatCons",h,tt(A,A));if(d._2.tag==="CatCons")return et("CatCons",d._2._1,tt(d._2._2._1,Jt("Cons",et("CatCons",h,tt(A,A)),d._2._2._2)));c()})())},r0=t=>e=>n=>{const r={...t,nodeFill:t.text,text:t.nodeFill,nodeStroke:t.nodeFill};return nr(o=>{const i=me(o._1)(n.nodes),a=me(o._1)(e.nodes),s=a.tag==="Just"&&i.tag==="Just"?Se({path:[],role:ln,layer:y,effects:[pe("GroupAlpha",o._2)]})(n0(VL)(n.animationTime)(O_)(1)(r)(1)(y)(1)(y)(o._1)((()=>{const u=me(o._1)(n.nodeLabels);if(u.tag==="Nothing")return a._1;if(u.tag==="Just"){if(u._1.tag==="StaticNodeLabel")return{...a._1,label:u._1._1===""?o._1:u._1._1};if(u._1.tag==="RelabelingNode")return{...a._1,label:(()=>{const g=u._1._1.progress<.5?u._1._1.oldLabel:u._1._1.newLabel;return g===""?o._1:g})()}}c()})())(i._1)(me(o._1)(n.nodeLabels))):j(st("Return",void 0),gt);return o._2>0?s:j(st("Return",void 0),gt)})(dn(n.nodeInvert))},r5=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>o=>{const i=o.length-1|0,a=i<1?[]:At(0,i,o),s=a.length-1|0,u=s>=0&&s<a.length?T("Just",a[s]):y,g=o.length-1|0,_=g>=0&&g<o.length?T("Just",o[g]):y;if(_.tag==="Just"&&u.tag==="Just"){const f=Pe(.78)(1.18)(ss(o)+19|0),l=Pe(.4)(.62)(f.prng),d=r.wobble?8.75*l.value:4.375,h=Pe(.4)(.62)(l.prng),m=r.wobble?8.75*h.value:4.375,p=_._1.y-u._1.y,x=_._1.x-u._1.x,J=qe(x*x+p*p),w=p/J,N=-w,L=x/J,C=_._1.x+L*.875,R=_._1.y+w*.875,P=r.wobble?8.75*f.value:8.75,I=C-L*P,U=R-w*P,S=I+N*d,v=U+L*d,F=I-N*m,H=U-L*m,M=[1,C,R,2,S,v,2,F,H,...Jo],q={color:r.arrowFill,width:2,lineJoin:rn,lineCap:Ar};return J<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,S,v,2,C,R])(q))(()=>t.strokePath([1,F,H,2,C,R])(q)):t.fillPath(M)({color:r.arrowFill,flat:!0})}return n.pure()}},o5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=vi(n),i=t.popAlpha,a=r5(t);return s=>u=>g=>_=>f=>{const l=Ol(8)(_),d=g&&(1-f.hi)*Ga(l)<=8.75?1:f.hi;if(d<=f.lo)return n.pure();const h=Pw(l)(f.lo)(d);if(h.length===0)return n.pure();const m={color:s.edge,width:s.wobble?2:.9375,lineJoin:rn,lineCap:Ar},p=s.wobble?Pe(-10)(4)(ss(h)).value:0,x=s.wobble?_k(p)(h):h;return r.bind(s.wobble?o(J=>r.bind(t.pushAlpha(J.alpha))(()=>r.bind(t.strokePath(J.path)(m))(()=>i)))((()=>{const J=ss(h);return x.length<2?[]:pa(Ik)(J)(!1)(x)})()):t.strokePath(Tw(h))(m))(()=>{const J=a(s)(x);return u&&d>=.999?J:n.pure()})}},i5=t=>{const e=o5(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()},a5=t=>e=>{const n=i=>{const a=me(i)(t.nodes);if(a.tag==="Nothing")return!1;if(a.tag==="Just"){const s=a._1;return!oe(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,dn(t.edges))}c()},r=b(i=>a=>(i*31|0)+Yr(a)|0)(5381)(tr(e.frameTitle)),o=i=>{const a=me(i)(t.nodes);if(a.tag==="Nothing")return!1;if(a.tag==="Just"){const s=a._1;return!oe(u=>{const g=u._2.length-1|0;return g>=0&&g<u._2.length&&u._2[g].x>=s.x&&u._2[g].x<=s.x+s.w&&u._2[g].y>=s.y&&u._2[g].y<=s.y+s.h},dn(t.edges))}c()};return b(i=>a=>{const s=a._2;return wk(u=>{if(u.tag==="Nothing")return T("Just",s);if(u.tag==="Just")return T("Just",{t:yr(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});c()})(a._1)(i)})(W)(St(dn(e.tokens))(i=>{if(i._2.tag==="Filling"){const a=i._2._1.node;return[E(a,{t:1,angle:(()=>{const s=ht(u=>(()=>{const g=me(a)(t.nodes),_=u._2.length-1|0;return _>=0&&_<u._2.length&&g.tag==="Just"&&u._2[_].x>=g._1.x&&u._2[_].x<=g._1.x+g._1.w&&u._2[_].y>=g._1.y&&u._2[_].y<=g._1.y+g._1.h})()?T("Just",u._2):y)(dn(t.edges));if(0<s.length){const u=s[0].length-1|0,g=u<1?[]:At(0,u,s[0]),_=g.length-1|0;if(_>=0&&_<g.length){const f=s[0].length-1|0;return f>=0&&f<s[0].length?Oo(s[0][f].y-g[_].y)(s[0][f].x-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[E(i._2._1.target,{t:(i._2._1.progress-.75)/.25,angle:(()=>{const a=Or(i._2._1.edge)(t.edges);if(a.tag==="Just"){const s=a._1.length-1|0,u=s<1?[]:At(0,s,a._1),g=u.length-1|0;if(g>=0&&g<u.length){const _=a._1.length-1|0;return _>=0&&_<a._1.length?Oo(a._1[_].y-u[g].y)(a._1[_].x-u[g].x):0}return a._1.length-1|0,0}if(a.tag==="Nothing")return 0;c()})(),bigCircle:n(i._2._1.target)||o(i._2._1.target),frameHash:r})];if(i._2._1.progress<.25)return[E(i._2._1.source,{t:i._2._1.progress/.25,angle:(()=>{const a=Or(i._2._1.edge)(t.edges);if(a.tag==="Just")return 1<a._1.length&&0<a._1.length?Oo(a._1[1].y-a._1[0].y)(a._1[1].x-a._1[0].x):0;if(a.tag==="Nothing")return 0;c()})(),bigCircle:n(i._2._1.source)||o(i._2._1.source),frameHash:r})]}return[]}))},s5=t=>b(e=>n=>(e*31|0)+Yr(n)|0)(5381)(tr(t.frameTitle)),o0=t=>e=>n=>r=>o=>i=>a=>{const s=s5(a),u=a5(i)(a);return nr(g=>{const _=me(g._1)(a.nodes);if(_.tag==="Just")return n0(Tp)(a.animationTime)(e)(r)(o)((()=>{const f=me(g._1)(a.nodeFadeAlpha);if(f.tag==="Nothing")return 1;if(f.tag==="Just")return f._1;c()})())(t(g._1))((()=>{const f=me(g._1)(a.nodeLabelFadeAlpha);if(f.tag==="Nothing")return n*1;if(f.tag==="Just")return n*f._1;c()})())((()=>{const f=me(g._1)(u);return f.tag==="Just"?T("Just",f._1):f.tag==="Nothing"&&Tk(g._1)(a.visited)?T("Just",{t:1,angle:0,bigCircle:!1,frameHash:s}):y})())(g._1)((()=>{const f=me(g._1)(a.nodeLabels);if(f.tag==="Nothing")return g._2;if(f.tag==="Just"){if(f._1.tag==="StaticNodeLabel")return{...g._2,label:f._1._1===""?g._1:f._1._1};if(f._1.tag==="RelabelingNode")return{...g._2,label:(()=>{const l=f._1._1.progress<.5?f._1._1.oldLabel:f._1._1.newLabel;return l===""?g._1:l})()}}c()})())(_._1)(me(g._1)(a.nodeLabels));if(_.tag==="Nothing")return j(st("Return",void 0),gt);c()})(dn(i.nodes))},u5=t=>e=>n=>{const r=ut.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=ut.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},i0=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},a0=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},o1=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},g5=xr.traverse(Zr),c5=b(ur)(0),s0=Mo(Zr)(Qt),u0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},_5=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},i1=(()=>{const t=gn.unfoldr(jn);return e=>t(cn("IterNode",e,Yn))})(),f5=t=>e=>{const n=en(t.angle),r=xn(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},l5=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],a1=t=>e=>{const n=r=>u5(0)(255)(he(Kn(ot(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},an=t=>e=>n=>r=>({x:(e-n)*xn(t.angle),y:(e+n)*en(t.angle)-r}),s1=t=>{const e=Bt(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(e._1.tail)(n=>[2,n.x,n.y]),5];c()},d5=t=>e=>n=>r=>o=>{const i=We(mn,o,At(1,o.length,o)),a=i.length-1|0;return Ft(s=>u=>({depth:(u._1.x+u._1.y+u._2.x+u._2.y)/2,draw:vp({id:n,geometry:lp("IsoSegments",[[an(t)(u._1.x)(u._1.y)(0),an(t)(u._2.x)(u._2.y)(0)]]),visible:{lo:0,hi:1},arrow:r&&s===a,settlingAtTarget:!1,plan:dp("IsoEdgePlan",{config:t,palette:e})})}))(i)},h5=t=>e=>n=>r=>o=>{const i=(()=>{if(t==="Forward")return o;if(t==="Backward")return re(o);c()})();if(0<i.length){const s=ti(i)(i0(0)(1)(as(n)(r)(e)));if(s.tag==="Nothing")return i[0];if(s.tag==="Just")return s._1;c()}const a=ti(i)(i0(0)(1)(as(n)(r)(e)));if(a.tag==="Nothing")return{x:0,y:0};if(a.tag==="Just")return a._1;c()},p5=t=>{const e=Bt(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(e._1.tail)(n=>[2,n.x,n.y])];c()},m5=t=>{const e=Bt(n=>y,n=>r=>T("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{vx:0,vy:0,vw:0,vh:0};if(e.tag==="Just"){const n=b(r=>o=>({minX:a0(r.minX)(o.x),minY:a0(r.minY)(o.y),maxX:o1(r.maxX)(o.x),maxY:o1(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}}c()},y5=t=>e=>n=>{const r=n.id,o=n.np,i=wn(o.label),a={family:e.fontFamily,size:11,weight:600},s=ot(i.length)*13.2,u=f5(t)(o.y+o.h),g=l=>d=>h=>m=>{const p=Bt(J=>y,J=>w=>T("Just",{head:J,tail:w}),m),x=Bt(J=>y,J=>w=>T("Just",{head:J,tail:w}),h);if(x.tag==="Just"&&p.tag==="Just"){const J=Ti({owner:Lo("NodeText",r),text:x._1.head.text,spec:{x:l,y:d,content:x._1.head.text,font:(()=>{if(x._1.head.style==="RunText")return a;if(x._1.head.style==="RunBold")return{...a,weight:700};if(x._1.head.style==="RunCode")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:400};if(x._1.head.style==="RunCodeBold")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:700};if(x._1.head.style==="RunHighlight")return a;if(x._1.head.style==="RunBoldHighlight")return{...a,weight:700};if(x._1.head.style==="RunCodeHighlight")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:400};if(x._1.head.style==="RunCodeBoldHighlight")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:700};c()})(),color:e.text,align:wr,baseline:Fn},bounds:y,plan:ha("AffineText",u)});return j(J._1,(()=>{if(J._2.tag==="CatNil")return et("CatCons",()=>g(l+p._1.head)(d)(x._1.tail)(p._1.tail),tt(A,A));if(J._2.tag==="CatCons")return et("CatCons",J._2._1,tt(J._2._2._1,Jt("Cons",et("CatCons",()=>g(l+p._1.head)(d)(x._1.tail)(p._1.tail),tt(A,A)),J._2._2._2)));c()})())}return j(st("Return",void 0),gt)},_=Xu({id:r,role:Tp,geometry:$u("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:qu("IsoNodePlan",{config:t,palette:e})}),f=()=>s0(l=>{const d=l._1,h=Sn(l._2),m=g5(x=>xo((()=>{if(x.style==="RunText")return a;if(x.style==="RunBold")return{...a,weight:700};if(x.style==="RunCode")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:400};if(x.style==="RunCodeBold")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:700};if(x.style==="RunHighlight")return a;if(x.style==="RunBoldHighlight")return{...a,weight:700};if(x.style==="RunCodeHighlight")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:400};if(x.style==="RunCodeBoldHighlight")return{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:700};c()})())(x.text))(h),p=x=>g(o.x+o.w/2-c5(x)/2)(ot(d)*13.2-s/2+6.6)(h)(x);return j(m._1,(()=>{if(m._2.tag==="CatNil")return et("CatCons",p,tt(A,A));if(m._2.tag==="CatCons")return et("CatCons",m._2._1,tt(m._2._2._1,Jt("Cons",et("CatCons",p,tt(A,A)),m._2._2._2)));c()})())})(Ft(mn)(i));return j(_._1,(()=>{if(_._2.tag==="CatNil")return et("CatCons",f,tt(A,A));if(_._2.tag==="CatCons")return et("CatCons",_._2._1,tt(_._2._2._1,Jt("Cons",et("CatCons",f,tt(A,A)),_._2._2._2)));c()})())},x5=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(s1(s))({color:u,flat:!0})({color:i.nodeStroke,width:1,lineJoin:rn,lineCap:Mn});return n.bind(a(o.south,a1(.66)(i.nodeFill)))(()=>n.bind(a(o.east,a1(.82)(i.nodeFill)))(()=>a(o.top,i.nodeFill)))}return e.Applicative0().pure()}},J5=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(s1(s))({color:a1(u)(i.tokenOutsideFill),flat:!0})({color:i.tokenOutsideStroke,width:1,lineJoin:rn,lineCap:Mn});return n.bind(a(o.south,.66))(()=>n.bind(a(o.east,.82))(()=>a(o.top,1)))}return e.Applicative0().pure()}},w5={angle:.5235987755982988,boxHeight:26,transparentBg:!0},T5=t=>e=>n=>{const r=u0(t)(n.nodeLabels);if(r.tag==="Just"){if(r._1.tag==="StaticNodeLabel")return r._1._1===""?t:r._1._1;if(r._1.tag==="RelabelingNode"){const o=r._1._1.progress<.5?r._1._1.oldLabel:r._1._1.newLabel;return o===""?t:o}c()}if(r.tag==="Nothing")return e.label===""?t:e.label;c()},N5=t=>e=>n=>{const r=n.x-5.5,o=n.x+5.5,i=n.y-5.5,a=n.y+5.5,s=e+11,u=an(t)(o)(i)(s),g=an(t)(o)(a)(s),_=an(t)(r)(a)(s),f=an(t)(o)(a)(e);return{south:[an(t)(r)(a)(e),f,g,_],east:[an(t)(o)(i)(e),f,g,u],top:[an(t)(r)(i)(s),u,g,_]}},b5=t=>e=>n=>r=>{const o=r._1,i=(a,s)=>({depth:s.x+s.y,draw:Cp({id:o,pass:Jp,geometry:pp("IsoCube",N5(t)(a)(s)),position:s,plan:yp("IsoTokenPlan",{config:t,palette:e,baseZ:a})})});if(r._2.tag==="Travelling"){const a=_5(r._2._1.edge)(n.edges);return a.tag==="Just"?T("Just",i(0,h5(r._2._1.direction)(r._2._1.progress)(r._2._1.holdPre)(r._2._1.holdPost)(a._1))):y}if(r._2.tag==="Filling"){const a=u0(r._2._1.node)(n.nodes);if(a.tag==="Just")return T("Just",i(t.boxHeight,{x:a._1.x+a._1.w/2,y:a._1.y+a._1.h/2}))}return y},v5=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:an(t)(e.x)(e.y)(0),b:an(t)(r)(e.y)(0),c:an(t)(r)(n)(0),d:an(t)(e.x)(n)(0)},top:{a:an(t)(e.x)(e.y)(t.boxHeight),b:an(t)(r)(e.y)(t.boxHeight),c:an(t)(r)(n)(t.boxHeight),d:an(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},g0=t=>e=>K(n=>({id:n._1,np:n._2,box:v5(t)(n._2)}))(i1(e.nodes)),C5=t=>e=>[...St(g0(t)(e))(l5),...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Jt("Cons",r._4,n(r._6,o)));c()};return St(Mt(ce.foldr,n(e.edges,A)))(K(r=>an(t)(r.x)(r.y)(0)))})()],L5=t=>e=>n=>K(r=>({...r,np:{...r.np,label:T5(r.id)(r.np)(n)}}))(g0(t)(e)),k5=t=>e=>n=>r=>{const o=Y_(e),i=[...St(i1(n.edges))(u=>d5(t)(o)(u._1)((()=>{const g=Jr("conn:")(u._1);if(g.tag==="Just")return!1;if(g.tag==="Nothing")return!0;c()})())(u._2)),...K(u=>({depth:u.box.depth,draw:y5(t)(o)(u)}))(L5(t)(n)(r)),...ht(b5(t)(o)(n))(i1(r.tokens))],a=bp({viewport:m5(C5(t)(n)),clear:T("Just",t.transparentBg?o.bgTransparent:o.bg),dots:y}),s=()=>s0(u=>u.draw)(Rt(u=>g=>at.compare(u.depth)(g.depth))(i));return j(a._1,(()=>{if(a._2.tag==="CatNil")return et("CatCons",s,tt(A,A));if(a._2.tag==="CatCons")return et("CatCons",a._2._1,tt(a._2._2._1,Jt("Cons",et("CatCons",s,tt(A,A)),a._2._2._2)));c()})())},S5=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=o1(1e-4)(qe(n*n+e*e)),o=e/r,i=n/r,a=t.to.y-o*7,s=t.to.x-i*7;return s1([t.to,{x:s-o*3,y:a+i*3},{x:s+o*3,y:a-i*3}])},E5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Mo(n)(Qt);return o=>{if(o.geometry.tag==="IsoSegments"&&o.plan.tag==="IsoEdgePlan"){const i=o.plan._1.palette,a=o.geometry._1;return e.Bind1().bind(r(s=>t.strokePath(p5(s))({color:i.edge,width:1.5,lineJoin:rn,lineCap:Ar}))(a))(()=>{const s=a.length-1|0;if(s>=0&&s<a.length){const g=a[s],_=g.length-1|0,f=_<1?[]:At(0,_,g),l=f.length-1|0;if(l>=0&&l<f.length){const h=a.length-1|0,m=(()=>{if(h>=0&&h<a.length){const p=a[h],x=p.length-1|0;if(x>=0&&x<p.length)return t.fillPath(S5({from:f[l],to:p[x]}))({color:i.arrowFill,flat:!0})}return n.pure()})();return o.arrow?m:n.pure()}a.length-1|0;const d=n.pure();return o.arrow?d:n.pure()}a.length-1|0;const u=n.pure();return o.arrow?u:n.pure()})}return n.pure()}},c0=t=>t,Ue=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Eo=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},R5=c0("Split"),P5=c0("Fall"),hn=t=>e=>n=>r=>{const o=n?0:1,i=1-xe(r.x-o)*en(e)*1.1,a=xe(i)<.06?i<0?-.06:.06:i,s=t.y+t.h/2,u=t.x+t.w/2;return{x:u+(t.x+(o+(r.x-o)*xn(e))*t.w-u)/a,y:s+(t.y+r.y*t.h-s)/a}},B5=t=>e=>n=>{const r=hn(t)(e)(n)({x:.5,y:.5}),o=t.x+.5*t.w,i=hn(t)(e)(n)({x:.5,y:0}),a=n?0:1,s=t.x+a*t.w,u=hn(t)(e)(n)({x:a,y:0}),g=hn(t)(e)(n)({x:a,y:1}),_=(g.y-u.y)/Ue(1e-6)(t.h),f=(g.x-u.x)/Ue(1e-6)(t.h),l=o-s,d=(i.y-u.y)/(xe(l)<1e-6?l<0?-1e-6:1e-6:l),h=t.y+t.h/2,m=t.x+t.w/2,p=o-s,x=(i.x-u.x)/(xe(p)<1e-6?p<0?-1e-6:1e-6:p);return{a:x,b:d,c:f,d:_,e:r.x-x*m-f*h,f:r.y-d*m-_*h}},u1=t=>{const e=Ue(0)(t)*3.05,n=xn(e);return{expansion:1+en(e)*.16,verticalScale:xe(n)<.06?n<0?-.06:.06:n}},Ro=t=>e=>n=>{const r=u1(e),o=t.x+t.w/2,i=t.y+t.h;return{x:o+(t.x+n.x*t.w-o)*r.expansion,y:i+(t.y+n.y*t.h-i)*r.verticalScale}},G5=t=>e=>{const n=u1(e),r=Ro(t)(e)({x:.5,y:.5});return{a:n.expansion,b:0,c:0,d:n.verticalScale,e:r.x-n.expansion*(t.x+t.w/2),f:r.y-n.verticalScale*(t.y+t.h/2)}},A5=t=>Ue(0)(t.w)/Ue(1e-6)(Ue(0)(t.h))>=4?P5:R5,I5=t=>e=>n=>{const r=n/Ue(1e-6)(t.h),o=n/Ue(1e-6)(t.w),i=(s,u,g)=>{const _=Ro(t)(e)(s),f=Ro(t)(e)(u),l=Ro(t)(e)(g);return[4,_.x,_.y,f.x,f.y,l.x,l.y]},a=[...(()=>{const s=Ro(t)(e)({x:o,y:0});return[1,s.x,s.y]})(),...i({x:o*.44771525016920644,y:0},{x:0,y:r*.44771525016920644},{x:0,y:r}),...(()=>{const s=Ro(t)(e)({x:0,y:1-r});return[2,s.x,s.y]})(),...i({x:0,y:1-r*.44771525016920644},{x:o*.44771525016920644,y:1},{x:o,y:1}),...(()=>{const s=Ro(t)(e)({x:1-o,y:1});return[2,s.x,s.y]})(),...i({x:1-o*.44771525016920644,y:1},{x:1,y:1-r*.44771525016920644},{x:1,y:1-r}),...(()=>{const s=Ro(t)(e)({x:1,y:r});return[2,s.x,s.y]})(),...i({x:1,y:r*.44771525016920644},{x:1-o*.44771525016920644,y:0},{x:1-o,y:0}),...Jo];return{face:a,labelAffine:G5(t)(e),labelVisible:u1(e).verticalScale>0,outline:a}},g1=t=>Ko(10.8)(.48)(Eo(1)(Ue(0)(t)))/Ko(10.8)(.48)(1),z5=t=>e=>{const n=g1(Eo(1)(Ue(0)((1-Eo(1)(Ue(0)(t))-.48)/.5))*.48)/g1(.48);if(e<0){const r=Eo(1)(Ue(0)((t-.25)/.28));return g1(r*r*r)}return Eo(1)(xe(1-n))},D5=t=>z5((()=>{if(t.tag==="Closed")return 0;if(t.tag==="Opening")return t._1;if(t.tag==="Open")return 1;if(t.tag==="Closing")return 1-t._1;c()})())(t.tag==="Opening"?-1:t.tag==="Closing"?1:0),_0=t=>e=>n=>{const r=Eo(1)(Ue(0)((n-t)/Ue(1e-6)(e-t)));return r*r*(3-2*r)},f0=t=>e=>n=>r=>{const o=n/Ue(1e-6)(t.h),i=n/Ue(1e-6)(t.w),a=_0(.08)(.2)(e),s=o*a,u=i*a,g=Ue(0)(e)*1.91986,_=(f,l,d)=>{const h=hn(t)(g)(r)(r?f:{...f,x:1-f.x}),m=hn(t)(g)(r)(r?l:{...l,x:1-l.x}),p=hn(t)(g)(r)(r?d:{...d,x:1-d.x});return[4,h.x,h.y,m.x,m.y,p.x,p.y]};return{leaf:{face:[...(()=>{const f={x:i,y:0},l=hn(t)(g)(r)(r?f:{...f,x:1-f.x});return[1,l.x,l.y]})(),..._({x:i*.44771525016920644,y:0},{x:0,y:o*.44771525016920644},{x:0,y:o}),...(()=>{const f={x:0,y:1-o},l=hn(t)(g)(r)(r?f:{...f,x:1});return[2,l.x,l.y]})(),..._({x:0,y:1-o*.44771525016920644},{x:i*.44771525016920644,y:1},{x:i,y:1}),...(()=>{const f={x:.5-u,y:1},l=hn(t)(g)(r)(r?f:{...f,x:1-f.x});return[2,l.x,l.y]})(),..._({x:.5-u*.44771525016920644,y:1},{x:.5,y:1-s*.44771525016920644},{x:.5,y:1-s}),...(()=>{const f={x:.5,y:s},l=hn(t)(g)(r)(r?f:{...f,x:.5});return[2,l.x,l.y]})(),..._({x:.5,y:s*.44771525016920644},{x:.5-u*.44771525016920644,y:0},{x:.5-u,y:0}),...Jo],labelAffine:B5(t)(g)(r),labelVisible:xn(g)>0,outline:[...(()=>{const f={x:.5,y:s},l=hn(t)(g)(r)(r?f:{...f,x:.5});return[1,l.x,l.y]})(),..._({x:.5,y:s*.44771525016920644},{x:.5-u*.44771525016920644,y:0},{x:.5-u,y:0}),...(()=>{const f={x:i,y:0},l=hn(t)(g)(r)(r?f:{...f,x:1-f.x});return[2,l.x,l.y]})(),..._({x:i*.44771525016920644,y:0},{x:0,y:o*.44771525016920644},{x:0,y:o}),...(()=>{const f={x:0,y:1-o},l=hn(t)(g)(r)(r?f:{...f,x:1});return[2,l.x,l.y]})(),..._({x:0,y:1-o*.44771525016920644},{x:i*.44771525016920644,y:1},{x:i,y:1}),...(()=>{const f={x:.5-u,y:1},l=hn(t)(g)(r)(r?f:{...f,x:1-f.x});return[2,l.x,l.y]})(),..._({x:.5-u*.44771525016920644,y:1},{x:.5,y:1-s*.44771525016920644},{x:.5,y:1-s})]},seam:[...(()=>{const f={x:.5,y:s},l=hn(t)(g)(r)(r?f:{...f,x:.5});return[1,l.x,l.y]})(),...(()=>{const f={x:.5,y:1-s},l=hn(t)(g)(r)(r?f:{...f,x:.5});return[2,l.x,l.y]})()]}},F5=t=>e=>n=>{const r=_0(.08)(.26)(e),o=f0(t)(e)(n)(!1),i=f0(t)(e)(n)(!0);return{leaves:[i.leaf,o.leaf],seams:[{alpha:r,path:i.seam},{alpha:r,path:o.seam}]}},M5=t=>e=>n=>Ue(0)(Eo(t)(Eo(Ue(0)(e)/2)(Ue(0)(n)/2))),Q5=t=>e=>n=>{const r=M5(n)(e.w)(e.h),o=D5(t),i=A5(e);if(i==="Fall")return{leaves:[I5(e)(o)(r)],seams:[]};if(i==="Split")return F5(e)(o)(r);c()},l0=(t,e)=>({tag:t,_1:e}),c1=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},W5=t=>e=>n=>{const r=at.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),i=at.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;c()},ya=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},_1=Ii(Zr)(Qt),O5=l0("ResolvedLabels"),_s=t=>e=>{const n=c1(1)(e.rootLayout.bounds.w),r=e.portalState.tag==="Closed"&&e.levels.length===1,o=_r(e.rootLayout)(e.camera),i=r?1:W5(0)(1)(o.w/n),a=t.padding*i*i*(()=>{if(r)return 1;if(e.portalState.tag==="Opening"||e.portalState.tag==="Closing"){if(e.portalState.tag==="Closed")return 1;if(e.portalState.tag==="Opening")return 1-e.portalState._1;if(e.portalState.tag==="Open")return 0;if(e.portalState.tag==="Closing")return 1-(1-e.portalState._1);c()}return 0})();return(()=>{if(t.outputAspect.tag==="Nothing")return CJ;if(t.outputAspect.tag==="Just")return cl(t.outputAspect._1);c()})()({vx:o.x-a,vy:o.y-a,vw:o.w+2*a,vh:o.h+2*a})},H5=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=ya(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]}}c()},f1=t=>e=>{const n=TJ(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}},l1=t=>e=>t===""?j(st("Return",void 0),gt):Ti({owner:HL,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:wr,baseline:ew},bounds:y,plan:W_}),$5=t=>e=>n=>r=>o=>i=>a=>s=>{const u=K_(i),g=Y_(t.theme),_=(()=>{if(s.tag==="ResolvedLabels")return jp(u)(g)(o)(a);if(s.tag==="SpringLabels")return tg(u)(g)(a)(Up(o)(s._1));c()})(),f=bp({viewport:o,clear:T("Just",t.transparentBg?g.bgTransparent:g.bg),dots:y}),l=()=>{const d=Se({path:[],role:ln,layer:y,effects:n<1?[pe("GroupAlpha",n)]:[]})((()=>{const h=qp(u)(g)(i)(a),m=()=>{const p=Vp(r)(g)(t.halftoneShadows)(i)(a),x=()=>{const J=o0(N=>r.tag!=="Nothing"&&r.tag==="Just"&&r._1===N?T("Just",0):y)(O_)(1)(1)(g)(i)(a),w=()=>{const N=r0(g)(i)(a),L=()=>{const C=e1(u)(g)(o)(a),R=()=>{const P=Hp(u)(cw)(g)(a),I=()=>{const U=()=>{const S=Kk(g)(i)(a);return a.staticKind!=="Animated"?S:j(st("Return",void 0),gt)};return j(_._1,(()=>{if(_._2.tag==="CatNil")return et("CatCons",U,tt(A,A));if(_._2.tag==="CatCons")return et("CatCons",_._2._1,tt(_._2._2._1,Jt("Cons",et("CatCons",U,tt(A,A)),_._2._2._2)));c()})())};return j(P._1,(()=>{if(P._2.tag==="CatNil")return et("CatCons",I,tt(A,A));if(P._2.tag==="CatCons")return et("CatCons",P._2._1,tt(P._2._2._1,Jt("Cons",et("CatCons",I,tt(A,A)),P._2._2._2)));c()})())};return j(C._1,(()=>{if(C._2.tag==="CatNil")return et("CatCons",R,tt(A,A));if(C._2.tag==="CatCons")return et("CatCons",C._2._1,tt(C._2._2._1,Jt("Cons",et("CatCons",R,tt(A,A)),C._2._2._2)));c()})())};return j(N._1,(()=>{if(N._2.tag==="CatNil")return et("CatCons",L,tt(A,A));if(N._2.tag==="CatCons")return et("CatCons",N._2._1,tt(N._2._2._1,Jt("Cons",et("CatCons",L,tt(A,A)),N._2._2._2)));c()})())};return j(J._1,(()=>{if(J._2.tag==="CatNil")return et("CatCons",w,tt(A,A));if(J._2.tag==="CatCons")return et("CatCons",J._2._1,tt(J._2._2._1,Jt("Cons",et("CatCons",w,tt(A,A)),J._2._2._2)));c()})())};return j(p._1,(()=>{if(p._2.tag==="CatNil")return et("CatCons",x,tt(A,A));if(p._2.tag==="CatCons")return et("CatCons",p._2._1,tt(p._2._2._1,Jt("Cons",et("CatCons",x,tt(A,A)),p._2._2._2)));c()})())};return j(h._1,(()=>{if(h._2.tag==="CatNil")return et("CatCons",m,tt(A,A));if(h._2.tag==="CatCons")return et("CatCons",h._2._1,tt(h._2._2._1,Jt("Cons",et("CatCons",m,tt(A,A)),h._2._2._2)));c()})())})());return n>0?j(d._1,(()=>{if(d._2.tag==="CatNil")return et("CatCons",()=>l1(t.watermark)(o),tt(A,A));if(d._2.tag==="CatCons")return et("CatCons",d._2._1,tt(d._2._2._1,Jt("Cons",et("CatCons",()=>l1(t.watermark)(o),tt(A,A)),d._2._2._2)));c()})()):j(st("Return",void 0),et("CatCons",()=>l1(t.watermark)(o),tt(A,A)))};return j(f._1,(()=>{if(f._2.tag==="CatNil")return et("CatCons",l,tt(A,A));if(f._2.tag==="CatCons")return et("CatCons",f._2._1,tt(f._2._2._1,Jt("Cons",et("CatCons",l,tt(A,A)),f._2._2._2)));c()})())},q5=t=>e=>n=>r=>o=>i=>{const a=i.segment.path.length-1|0,s=a>=0&&a<i.segment.path.length?T("Just",i.segment.path[a]):y;if(s.tag==="Nothing")return j(st("Return",void 0),gt);if(s.tag==="Just"){const u=ya(s._1)(o.segment.layout.nodes);if(u.tag==="Nothing")return j(st("Return",void 0),gt);if(u.tag==="Just"){const g=u._1,_=ya(s._1)(o.state.nodes),f=(()=>{if(_.tag==="Nothing")return e_;if(_.tag==="Just")return _._1;c()})(),l={color:t.nodeStroke,width:t.wobble?2:1.25,lineJoin:rn,lineCap:Ar},d={...l,width:1.25},h=Q5(r)({x:g.x,y:g.y,w:g.w,h:g.h})(7);return Se({path:o.segment.path,role:o.role,layer:y,effects:[pe("GroupAlpha",o.bgAlpha),pe("GroupTransform",Ji,n)]})((()=>{const m=Xu({id:s._1,role:qL,geometry:$u("FlatNode",{shape:g.shape,bounds:{x:g.x,y:g.y+5,w:g.w,h:g.h}}),alpha:1,plan:qu("FlatNodePlan",{palette:t,label:g.label,labelVisibility:Uu,inkBoost:e?1:0,labelAlpha:0,outlineAlpha:T("Just",1),arrival:y,animState:f})}),p=()=>{const x=wi(yi({path:wo(g),fill:y,stroke:T("Just",l)})),J=()=>{const w=_1(h.leaves)(L=>{const C=Se({path:o.segment.path,role:o.role,layer:y,effects:[pe("GroupAlpha",1)]})(wi(yi({path:L.face,fill:T("Just",{color:t.nodeFill,flat:!1}),stroke:y}))),R=()=>{const P=Se({path:o.segment.path,role:o.role,layer:y,effects:[pe("GroupClip",L.face,ei)]})(e0(ha("AffineText",L.labelAffine))(o.state.animationTime)(t)(1)(1)(s._1)(g)(f)(ya(s._1)(o.state.nodeLabels)));return L.labelVisible?P:j(st("Return",void 0),gt)};return j(C._1,(()=>{if((()=>{if(C._2.tag==="CatNil"||C._2.tag==="CatCons")return!1;c()})())return et("CatCons",R,tt(A,A));if((()=>{if(C._2.tag==="CatNil"||C._2.tag==="CatCons")return!0;c()})())return et("CatCons",(()=>{if(C._2.tag==="CatNil")return()=>wi(yi({path:L.outline,fill:y,stroke:T("Just",l)}));if(C._2.tag==="CatCons")return C._2._1;c()})(),tt((()=>{if(C._2.tag==="CatNil")return A;if(C._2.tag==="CatCons")return C._2._2._1;c()})(),Jt("Cons",et("CatCons",R,tt(A,A)),(()=>{if(C._2.tag==="CatNil")return A;if(C._2.tag==="CatCons")return Jt("Cons",et("CatCons",()=>wi(yi({path:L.outline,fill:y,stroke:T("Just",l)})),tt(A,A)),C._2._2._2);c()})())));c()})())}),N=()=>_1(h.seams)(L=>{const C=Se({path:o.segment.path,role:o.role,layer:y,effects:[pe("GroupAlpha",L.alpha)]})(wi(yi({path:L.path,fill:y,stroke:T("Just",d)})));return L.alpha>0?C:j(st("Return",void 0),gt)});return j(w._1,(()=>{if(w._2.tag==="CatNil")return et("CatCons",N,tt(A,A));if(w._2.tag==="CatCons")return et("CatCons",w._2._1,tt(w._2._2._1,Jt("Cons",et("CatCons",N,tt(A,A)),w._2._2._2)));c()})())};return j(x._1,(()=>{if(x._2.tag==="CatNil")return et("CatCons",J,tt(A,A));if(x._2.tag==="CatCons")return et("CatCons",x._2._1,tt(x._2._2._1,Jt("Cons",et("CatCons",J,tt(A,A)),x._2._2._2)));c()})())};return j(m._1,(()=>{if(m._2.tag==="CatNil")return et("CatCons",p,tt(A,A));if(m._2.tag==="CatCons")return et("CatCons",m._2._1,tt(m._2._2._1,Jt("Cons",et("CatCons",p,tt(A,A)),m._2._2._2)));c()})())})())}}c()},d1=t=>e=>n=>r=>_1(r.minis)(o=>{const i=d0(t)(e)(n)(xd)(W)(y)(r)(o);return(()=>{const a=o.segment.path.length-1|0;return o.bgAlpha>0&&a>=0&&a<o.segment.path.length&&(()=>{const s=ya(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;c()})()})()?i:j(st("Return",void 0),gt)}),d0=t=>e=>n=>r=>o=>i=>a=>s=>{const u=[1,e.viewport.vx,e.viewport.vy,2,e.viewport.vx+e.viewport.vw,e.viewport.vy,2,e.viewport.vx+e.viewport.vw,e.viewport.vy+e.viewport.vh,2,e.viewport.vx,e.viewport.vy+e.viewport.vh,5],g=s.state,_={tx:a.segment.placement.tx,ty:a.segment.placement.ty,sx:a.segment.placement.scale,sy:a.segment.placement.scale},f=Y_(t.theme),l=s.segment.layout,d={vx:l.bounds.x-1e3,vy:l.bounds.y-1e3,vw:l.bounds.w+2e3,vh:l.bounds.h+2e3},h=K_(l),m=s.segment.path.length-1|0,p=m>=0&&m<s.segment.path.length?ya(s.segment.path[m])(a.segment.layout.nodes):y,x=Rk(5)(11)(s.segment.placement.scale*n),J=x>0?O_:Uu,w=f1(e.viewport)(s),N=(()=>{if(J==="LabelsHidden")return j(st("Return",void 0),gt);if(J==="LabelsShown")return Se({path:s.segment.path,role:s.role,layer:y,effects:x<1?[pe("GroupAlpha",x)]:[]})(o.tag==="Leaf"?jp(h)(f)(w)(g):tg(h)(f)(g)(Up(w)(o)));c()})(),L={tx:s.segment.placement.tx,ty:s.segment.placement.ty,sx:s.segment.placement.scale,sy:s.segment.placement.scale},C=Se({path:s.segment.path,role:s.role,layer:y,effects:[pe("GroupAlpha",s.bgAlpha)]})((()=>{const P=Se({path:s.segment.path,role:s.role,layer:y,effects:[pe("GroupClip",(()=>{if(Cd(r)>=.52)return u;const U=H5(a)((()=>{const S=s.segment.path.length-1|0;return S>=0&&S<s.segment.path.length?T("Just",s.segment.path[S]):y})());return U.length===0?u:U})(),ei)]})((()=>{const U=(()=>{if(p.tag==="Just")return Se({path:a.segment.path,role:a.role,layer:y,effects:[pe("GroupTransform",Ji,_)]})(wi(yi({path:wo({...p._1,x:p._1.x+1,y:p._1.y+1,w:p._1.w-2,h:p._1.h-2}),fill:T("Just",{color:f.bg,flat:!0}),stroke:y})));if(p.tag==="Nothing")return j(st("Return",void 0),gt);c()})(),S=(a.role==="Active"||a.role==="FlyThrough")&&!t.transparentBg?U:j(st("Return",void 0),gt),v=()=>{const F=Se({path:s.segment.path,role:s.role,layer:y,effects:[pe("GroupTransform",Ji,L)]})((()=>{const M=qp(h)(f)(l)(g),q=()=>{const $=Vp(i)(f)(t.halftoneShadows)(l)(g),B=()=>{const D=o0(O=>i.tag!=="Nothing"&&i.tag==="Just"&&i._1===O?T("Just",0):y)(J)(x)(1)(f)(l)(g),Q=()=>{const O=r0(f)(l)(g);return j(O._1,(()=>{if(O._2.tag==="CatNil")return et("CatCons",()=>e1(h)(f)(d)(g),tt(A,A));if(O._2.tag==="CatCons")return et("CatCons",O._2._1,tt(O._2._2._1,Jt("Cons",et("CatCons",()=>e1(h)(f)(d)(g),tt(A,A)),O._2._2._2)));c()})())};return j(D._1,(()=>{if(D._2.tag==="CatNil")return et("CatCons",Q,tt(A,A));if(D._2.tag==="CatCons")return et("CatCons",D._2._1,tt(D._2._2._1,Jt("Cons",et("CatCons",Q,tt(A,A)),D._2._2._2)));c()})())};return j($._1,(()=>{if($._2.tag==="CatNil")return et("CatCons",B,tt(A,A));if($._2.tag==="CatCons")return et("CatCons",$._2._1,tt($._2._2._1,Jt("Cons",et("CatCons",B,tt(A,A)),$._2._2._2)));c()})())};return j(M._1,(()=>{if(M._2.tag==="CatNil")return et("CatCons",q,tt(A,A));if(M._2.tag==="CatCons")return et("CatCons",M._2._1,tt(M._2._2._1,Jt("Cons",et("CatCons",q,tt(A,A)),M._2._2._2)));c()})())})()),H=()=>{const M=Se({path:s.segment.path,role:s.role,layer:y,effects:[pe("GroupTransform",OL,L)]})(Hp(h)(_w)(f)(g));return j(M._1,(()=>{if(M._2.tag==="CatNil")return et("CatCons",()=>d1(t)(e)(n)(s),tt(A,A));if(M._2.tag==="CatCons")return et("CatCons",M._2._1,tt(M._2._2._1,Jt("Cons",et("CatCons",()=>d1(t)(e)(n)(s),tt(A,A)),M._2._2._2)));c()})())};return j(F._1,(()=>{if(F._2.tag==="CatNil")return et("CatCons",H,tt(A,A));if(F._2.tag==="CatCons")return et("CatCons",F._2._1,tt(F._2._2._1,Jt("Cons",et("CatCons",H,tt(A,A)),F._2._2._2)));c()})())};return j(S._1,(()=>{if(S._2.tag==="CatNil")return et("CatCons",v,tt(A,A));if(S._2.tag==="CatCons")return et("CatCons",S._2._1,tt(S._2._2._1,Jt("Cons",et("CatCons",v,tt(A,A)),S._2._2._2)));c()})())})()),I=()=>Se({path:s.segment.path,role:s.role,layer:y,effects:[pe("GroupTransform",Ji,L)]})(N);return j(P._1,(()=>{if(P._2.tag==="CatNil")return et("CatCons",I,tt(A,A));if(P._2.tag==="CatCons")return et("CatCons",P._2._1,tt(P._2._2._1,Jt("Cons",et("CatCons",I,tt(A,A)),P._2._2._2)));c()})())})()),R=()=>{const P=q5(f)(t.halftoneShadows)(_)(r)(a)(s);return a.role==="FlyThrough"&&(r.tag==="Opening"||r.tag==="Closing")?P:j(st("Return",void 0),gt)};return j(C._1,(()=>{if(C._2.tag==="CatNil")return et("CatCons",R,tt(A,A));if(C._2.tag==="CatCons")return et("CatCons",C._2._1,tt(C._2._2._1,Jt("Cons",et("CatCons",R,tt(A,A)),C._2._2._2)));c()})())},V5=t=>e=>n=>{if(t.theme==="Isometric")return k5({...w5,transparentBg:t.transparentBg})(t.theme)(bd(n).segment.layout)(bd(n).state);const r=_s(t)(n),o={tileScale:n.hasDives?r.vw/c1(1)(n.rootLayout.bounds.w):1,viewport:r},i=s=>u=>{if(u.length===0)return j(st("Return",void 0),gt);const g=Bt(_=>y,_=>f=>T("Just",{head:_,tail:f}),u);if(g.tag==="Nothing")return j(st("Return",void 0),gt);if(g.tag==="Just"){const _=d0(t)(o)(n.camera.zoom)(n.portalState)(g._1.head.role==="Active"?e:W)((()=>{if(g._1.head.role==="FlyThrough"&&0<g._1.tail.length){const f=g._1.tail[0].segment.path.length-1|0;if(f>=0&&f<g._1.tail[0].segment.path.length)return T("Just",g._1.tail[0].segment.path[f])}return y})())(s)(g._1.head);return g._1.head.role==="Active"||g._1.head.role==="FlyThrough"?j(_._1,(()=>{if(_._2.tag==="CatNil")return et("CatCons",()=>i(g._1.head)(g._1.tail),tt(A,A));if(_._2.tag==="CatCons")return et("CatCons",_._2._1,tt(_._2._2._1,Jt("Cons",et("CatCons",()=>i(g._1.head)(g._1.tail),tt(A,A)),_._2._2._2)));c()})()):j(st("Return",void 0),et("CatCons",()=>i(g._1.head)(g._1.tail),tt(A,A)))}c()},a=Bt(s=>y,s=>u=>T("Just",{head:s,tail:u}),n.levels);if(a.tag==="Nothing")return j(st("Return",void 0),gt);if(a.tag==="Just"){const s=a._1.tail,u=a._1.head,g=$5(t)(n.hasDives?r.vw/c1(1)(n.rootLayout.bounds.w):1)(u.role==="Active"||u.role==="FlyThrough"?u.bgAlpha:0)((()=>{if(u.role==="FlyThrough"&&0<s.length){const f=s[0].segment.path.length-1|0;if(f>=0&&f<s[0].segment.path.length)return T("Just",s[0].segment.path[f])}return y})())(r)(u.segment.layout)(u.state)(s.length===0&&e.tag!=="Leaf"?l0("SpringLabels",e):O5),_=()=>{const f=d1(t)(o)(n.camera.zoom)(u);return u.role==="Active"||u.role==="FlyThrough"?j(f._1,(()=>{if(f._2.tag==="CatNil")return et("CatCons",()=>i(u)(s),tt(A,A));if(f._2.tag==="CatCons")return et("CatCons",f._2._1,tt(f._2._2._1,Jt("Cons",et("CatCons",()=>i(u)(s),tt(A,A)),f._2._2._2)));c()})()):j(st("Return",void 0),et("CatCons",()=>i(u)(s),tt(A,A)))};return j(g._1,(()=>{if(g._2.tag==="CatNil")return et("CatCons",_,tt(A,A));if(g._2.tag==="CatCons")return et("CatCons",g._2._1,tt(g._2._2._1,Jt("Cons",et("CatCons",_,tt(A,A)),g._2._2._2)));c()})())}c()},h1=t=>e=>n=>KL({viewport:_s(t)(n),camera:n.camera})(V5(t)(e)(n)),U5=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);c()}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()}c()},X5=t=>e=>U5(t)(e._1),K5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Mo(n)(Qt),o=t.popTransform,i=t.popBakedTransform,a=(()=>{const u=t.popClip,g=t.popAlpha,_=t.popBlend,f=t.popBlur;return l=>{if(l.tag==="GroupTransform"){if(l._1==="NormalTransform")return o;if(l._1==="BakedTransform")return i;c()}if(l.tag==="GroupClip")return u;if(l.tag==="GroupAlpha")return g;if(l.tag==="GroupBlend")return _;if(l.tag==="GroupBlur")return f;c()}})(),s=t.popLayer;return u=>e.Bind1().bind(r(a)(re(u.effects)))(()=>{if(u.layer.tag==="Just")return s;if(u.layer.tag==="Nothing")return n.pure();c()})},Y5=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Mo(n)(Qt);return o=>e.Bind1().bind((()=>{if(o.layer.tag==="Just")return t.pushLayer(o.layer._1);if(o.layer.tag==="Nothing")return n.pure();c()})())(()=>r(i=>{if(i.tag==="GroupTransform"){if(i._1==="NormalTransform")return t.pushTransform(i._2);if(i._1==="BakedTransform")return t.pushBakedTransform(i._2);c()}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);c()})(o.effects))},h0=t=>{const e=t.Monad0(),n=Wk(t),r=x5(t),o=i5(t),i=E5(t),a=zk(t),s=J5(t);return UL(e)({beginFrame:u=>t.setViewport(u.viewport),endFrame:e.Applicative0().pure(),beginGroup:Y5(t),endGroup:K5(t),background:Bk(t),overlay:X5(t),node:u=>{if(u.geometry.tag==="FlatNode")return n(u);if(u.geometry.tag==="IsoSlab")return r(u);c()},edge:u=>{if(u.geometry.tag==="FlatRoute")return o(u);if(u.geometry.tag==="IsoSegments")return i(u);c()},text:jk(t),token:u=>{if(u.geometry.tag==="FlatToken")return a(u);if(u.geometry.tag==="IsoCube")return s(u);c()},insideTokenStyle:t.insideTokenStyle,measureText:t.measureText,measureInk:t.measureInk})},Z5=Yp(up)(M_.measureText),p0=h0(M_),p1=t=>_s({padding:24,outputAspect:t.width<=0||t.height<=0?y:T("Just",t.width/t.height)}),j5=t=>e=>n=>r=>o=>i=>a=>{const s={padding:24,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;c()})(),halftoneShadows:!1,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?y:T("Just",r.width/r.height)},u=ip(n)(r);return()=>{const g=u(),_=o.levels.length-1|0;if(_>=0&&_<o.levels.length){const l=Z5(f1(p1(r)(o))(o.levels[_]))(o.levels[_].segment.layout)(o.levels[_].state)(g)(),d=z_(i)(l)(a);return p0(h1(s)(d.applied)(o))(g)(),d.springs}const f=z_(i)(W)(a);return p0(h1(s)(f.applied)(o))(g)(),f.springs}},fs=t=>"rgb("+ue(t.r)+","+ue(t.g)+","+ue(t.b)+")",Ci=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,le=qo(Ho("Fixed",$o(0)(20)(2))),m1=t=>{const e=n=>{const r=n>=0&&n<t.length?T("Just",t[n]):y;if(r.tag==="Just")return r._1===1?["M",le((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===2?["L",le((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===3?["Q",le((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+5|0)]:r._1===4?["C",le((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{const o=n+5|0;return o>=0&&o<t.length?t[o]:0})()),le((()=>{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[];c()};return dr(" ")(e(0))},tS=t=>le(t.vx)+" "+le(t.vy)+" "+le(t.vw)+" "+le(t.vh),rr=t=>e=>he(sr(e>=0&&e<t.length?t[e]:0)),y1=t=>e=>{const n=rr(t.ops)(e+1|0);return At(n,n+rr(t.ops)(e+2|0)|0,t.paths)},m0=(()=>{const t=lr("&")("&"),e=lr("<")("<"),n=(()=>{const r=lr(">")(">"),o=(()=>{const i=lr('"')(""");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),eS={vx:0,vy:0,vw:1,vh:1},nS=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+Ci(t[i])|0;continue}r=!1,o=eS}return o})(0),ls=t=>e=>({r:rr(t)(e),g:rr(t)(e+1|0),b:rr(t)(e+2|0),a:rr(t)(e+3|0)}),y0=t=>e=>({color:ls(t)(e),width:(()=>{const n=e+4|0;return n>=0&&n<t.length?t[n]:0})(),join:rr(t)(e+5|0),cap:rr(t)(e+6|0)}),rS=t=>e=>'<rect x="'+le(t.vx)+'" y="'+le(t.vy)+'" width="'+le(t.vw)+'" height="'+le(t.vh)+'" fill="'+fs(e)+'" opacity="'+le(ot(e.a)/255)+'"/>',oS=t=>e=>'<path d="'+m1(t)+'" fill="'+fs(e)+'" fill-opacity="'+le(ot(e.a)/255)+'"/>',x0=t=>' stroke="'+fs(t.color)+'" stroke-opacity="'+le(ot(t.color.a)/255)+'" stroke-width="'+le(t.width)+'" stroke-linejoin="'+(t.join===0?"round":t.join===1?"bevel":"miter")+'" stroke-linecap="'+(t.cap===0?"butt":t.cap===1?"round":"square")+'"',iS=t=>e=>n=>'<path d="'+m1(t)+'" fill="'+fs(e)+'" fill-opacity="'+le(ot(e.a)/255)+'"'+x0(n)+"/>",aS=t=>e=>'<path d="'+m1(t)+'" fill="none"'+x0(e)+"/>",sS=t=>e=>{const n=ls(t.ops)(e+7|0),r=rr(t.ops)(e+12|0),o=rr(t.ops)(e+11|0);return'<text x="'+le((()=>{const i=e+1|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" y="'+le((()=>{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="'+fs(n)+'" fill-opacity="'+le(ot(n.a)/255)+'" font-size="'+le((()=>{const i=e+5|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" font-family="'+m0((()=>{const i=rr(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(rr(t.ops)(e+6|0))+'" text-anchor="'+(o===0?"start":o===1?"middle":"end")+'">'+m0((()=>{const i=rr(t.ops)(e+3|0);return i>=0&&i<t.strs.length?t.strs[i]:""})())+"</text>"},Li=t=>e=>n=>{const r=n>=0&&n<e.ops.length?T("Just",e.ops[n]):y;if(r.tag==="Just")return r._1===1?oS(y1(e)(n))(ls(e.ops)(n+3|0))+Li(t)(e)(n+Ci(r._1)|0):r._1===2?aS(y1(e)(n))(y0(e.ops)(n+3|0))+Li(t)(e)(n+Ci(r._1)|0):r._1===3?iS(y1(e)(n))(ls(e.ops)(n+3|0))(y0(e.ops)(n+7|0))+Li(t)(e)(n+Ci(r._1)|0):r._1===4?sS(e)(n)+Li(t)(e)(n+Ci(r._1)|0):r._1===16?rS(t)(ls(e.ops)(n+1|0))+Li(t)(e)(n+Ci(r._1)|0):Li(t)(e)(n+Ci(r._1)|0);if(r.tag==="Nothing")return"";c()},uS=t=>{const e=nS(t.ops);return{viewBox:tS(e),body:Li(e)(t)(0),vx:e.vx,vy:e.vy,vw:e.vw,vh:e.vh}},gS=RJ(qJ)(W2),J0=t=>e=>{const n=t.strs;return()=>{const r=Fg(n);return t.strs.push(e),r}},eg=t=>e=>{const n=t.paths;return()=>{const r=Fg(n);return t.paths.push(...e),{offset:r,len:e.length}}},cS=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)}},w0=t=>e=>{const n=e.vx,r=t.ops;return()=>{r.push(n),t.ops.push(e.vy),t.ops.push(e.vw),t.ops.push(e.vh)}},uo=t=>e=>{const n=ot(e),r=t.ops;return()=>{r.push(n)}},ng=t=>e=>{const n=e.len,r=uo(t)(e.offset);return()=>(r(),uo(t)(n)())},_S=()=>{const t=[],e=[],n=[],r=[];return r.push(1),{ops:t,paths:e,strs:n,alphaStack:r}},fS=t=>{if(t.tag==="MeasureText"){const e=t._3(Ec(t._1)(t._2));return()=>e}if(t.tag==="MeasureInk"){const e=t._3(Rc(t._1)(t._2));return()=>e}c()},T0=t=>{const e=t.alphaStack;return()=>{const n=Fg(e);if(n===0)return 1;const r=H2(Yt,y,n-1|0,t.alphaStack);if(r.tag==="Nothing")return 1;if(r.tag==="Just")return r._1;c()}},ki=t=>e=>{const n=T0(t);return()=>{const r=n();return uo(t)(e.r)(),uo(t)(e.g)(),uo(t)(e.b)(),uo(t)(he(sr(ot(e.a)*r+.5)))()}},N0=t=>e=>{const n=ki(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;c()})()),t.ops.push((()=>{if(e.lineCap==="ButtCap")return 0;if(e.lineCap==="RoundCap")return 1;if(e.lineCap==="SquareCap")return 2;c()})())}},lS=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,g=s._2,_=eg(a)(s._1);o=!1,i=()=>{const f=_();return a.ops.push(1),ng(a)(f)(),ki(a)(g.color)(),u};continue}if(s.tag==="StrokePath"){const u=s._3,g=s._2,_=eg(a)(s._1);o=!1,i=()=>{const f=_();return a.ops.push(2),ng(a)(f)(),N0(a)(g)(),u};continue}if(s.tag==="FillStrokePath"){const u=s._2,g=s._4,_=s._3,f=eg(a)(s._1);o=!1,i=()=>{const l=f();return a.ops.push(3),ng(a)(l)(),ki(a)(u.color)(),N0(a)(_)(),g};continue}if(s.tag==="DrawText"){const u=s._2,g=s._1,_=J0(a)(Xi(g.content));o=!1,i=()=>{const f=_(),l=J0(a)(g.font.family)();return a.ops.push(4),a.ops.push(g.x),a.ops.push(g.y),uo(a)(f)(),uo(a)(l)(),a.ops.push(g.font.size),uo(a)(g.font.weight)(),ki(a)(g.color)(),a.ops.push((()=>{if(g.align==="AlignLeft")return 0;if(g.align==="AlignCenter")return 1;if(g.align==="AlignRight")return 2;c()})()),a.ops.push((()=>{if(g.baseline==="BaselineTop")return 0;if(g.baseline==="BaselineMiddle")return 1;if(g.baseline==="BaselineAlphabetic")return 2;if(g.baseline==="BaselineBottom")return 3;c()})()),u};continue}if(s.tag==="DrawTextAffine"){n=a,r=Kt("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,g=s._1,_=a.ops;o=!1,i=()=>(_.push(5),cS(a)(g)(),u);continue}if(s.tag==="PopTransform"){const u=s._1,g=a.ops;o=!1,i=()=>(g.push(6),u);continue}if(s.tag==="PushClip"){const u=s._3,g=s._2,_=eg(a)(s._1);o=!1,i=()=>{const f=_();return a.ops.push(7),ng(a)(f)(),a.ops.push((()=>{if(g==="NonZero")return 0;if(g==="EvenOdd")return 1;c()})()),u};continue}if(s.tag==="PopClip"){const u=s._1,g=a.ops;o=!1,i=()=>(g.push(8),u);continue}if(s.tag==="PushBlend"){const u=s._1,g=s._2,_=a.ops;o=!1,i=()=>(_.push(9),a.ops.push((()=>{if(u==="Normal")return 0;if(u==="Difference")return 1;c()})()),g);continue}if(s.tag==="PopBlend"){const u=s._1,g=a.ops;o=!1,i=()=>(g.push(10),u);continue}if(s.tag==="PushAlpha"){const u=s._1,g=s._2,_=T0(a);o=!1,i=()=>{const f=_();return a.alphaStack.push(f*u),a.ops.push(11),a.ops.push(u),g};continue}if(s.tag==="PopAlpha"){const u=s._1,g=a.alphaStack;o=!1,i=()=>($2(Yt,y,g),a.ops.push(12),u);continue}if(s.tag==="PushBlur"){const u=s._2,g=s._1,_=a.ops;o=!1,i=()=>(_.push(18),a.ops.push(g),u);continue}if(s.tag==="PopBlur"){const u=s._1,g=a.ops;o=!1,i=()=>(g.push(19),u);continue}if(s.tag==="PushLayer"){const u=s._1,g=s._2,_=a.ops;o=!1,i=()=>(_.push(13),a.ops.push((()=>{if(u==="LayerBase")return 0;if(u==="LayerPolyOut")return 1;if(u==="LayerPolyIn")return 2;if(u==="LayerNodeMask")return 3;if(u==="LayerOverlay")return 4;c()})()),g);continue}if(s.tag==="PopLayer"){const u=s._1,g=a.ops;o=!1,i=()=>(g.push(14),u);continue}if(s.tag==="SetViewport"){const u=s._2,g=s._1,_=a.ops;o=!1,i=()=>(_.push(15),w0(a)(g)(),u);continue}if(s.tag==="ClearBackground"){const u=s._1,g=s._2,_=a.ops;o=!1,i=()=>(_.push(16),ki(a)(u)(),g);continue}if(s.tag==="BackgroundDots"){const u=s._2,g=s._1,_=a.ops;o=!1,i=()=>(_.push(17),w0(a)(g.viewport)(),ki(a)(g.bgColor)(),ki(a)(g.dotColor)(),a.ops.push(g.tile),a.ops.push(g.dotRadius),a.ops.push(g.origin.x),a.ops.push(g.origin.y),u);continue}c()}return i},dS=t=>e=>e.type==="metrics"?fS(e.value):e.type==="render"?lS(t)(e.value):Af("Data.Functor.Variant: pattern match failure ["+e.type+"]"),hS=t=>{const e=_S();return gS(dS(e))(t)(),{ops:e.ops,paths:e.paths,strs:e.strs}},pS=t=>t,ds=t=>t,x1=ds("Light"),mS=ds("Dark"),yS=ds("Blueprint"),xS=ds("Whiteboard"),JS=ds("Isometric"),wS=pS("TransparentBackground"),Po=t=>"rgb("+ue(t.r)+","+ue(t.g)+","+ue(t.b)+")",rg=qo(Ho("Fixed",$o(0)(20)(6))),Hr=qo(Ho("Fixed",$o(0)(20)(4))),TS=t=>"translate("+Hr(t.tx)+","+Hr(t.ty)+") scale("+Hr(t.sx)+","+Hr(t.sy)+")",$t=qo(Ho("Fixed",$o(0)(20)(2))),J1=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,o=r>=0&&r<t.length?T("Just",t[r]):y;if(o.tag==="Nothing"){n=t.length;continue}if(o.tag==="Just"){if(o._1===1){e.push("M"),e.push($t((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{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($t((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{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($t((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{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($t((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{const i=r+4|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{const i=r+5|0;return i>=0&&i<t.length?t[i]:0})())),e.push($t((()=>{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}c()}return dr(" ")(e)},NS={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},b0=(()=>{const t=lr("&")("&"),e=lr("<")("<"),n=(()=>{const r=lr(">")(">"),o=(()=>{const i=lr('"')(""");return a=>i(r(a))})();return i=>o(e(i))})();return r=>n(t(r))})(),Ze=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},bS=t=>e=>{const n=[];let r=0;const o=i=>{const a=i>=0&&i<e.length?t.sx*e[i]+t.tx:t.sx*0+t.tx;return()=>{n.push(a),n.push((()=>{const s=i+1|0;return s>=0&&s<e.length?t.sy*e[s]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const i=r,a=i>=0&&i<e.length?T("Just",e[i]):y;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}c()}return n},og=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return bS(r._1)(e);c()}},v0={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),a=o();return i(a)}},Functor0:()=>NS},vS={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>v0},CS={pure:t=>e=>()=>t,Apply0:()=>v0},C0={Applicative0:()=>CS,Bind1:()=>vS},LS=t=>e=>'<defs><pattern id="'+t+'" x="'+$t(e.origin.x)+'" y="'+$t(e.origin.y)+'" width="'+$t(e.tile)+'" height="'+$t(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+$t(e.tile)+'" height="'+$t(e.tile)+'" fill="'+Po(e.bgColor)+'" fill-opacity="'+$t(ot(e.bgColor.a)/255)+'"/>')+'<circle cx="'+$t(e.tile/2)+'" cy="'+$t(e.tile/2)+'" r="'+$t(e.dotRadius)+'" fill="'+Po(e.dotColor)+'"/></pattern></defs><rect x="'+$t(e.viewport.vx)+'" y="'+$t(e.viewport.vy)+'" width="'+$t(e.viewport.vw)+'" height="'+$t(e.viewport.vh)+'" fill="url(#'+t+')"/>',L0=t=>e=>'<path d="'+J1(t)+'" fill="'+Po(e)+'" fill-opacity="'+$t(ot(e.a)/255)+'"/>',kS=t=>e=>n=>r=>'<rect x="'+$t(t.x)+'" y="'+$t(t.y)+'" width="'+$t(t.w)+'" height="'+$t(t.h)+'" rx="'+$t(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+Po(n._1.color)+'" fill-opacity="'+$t(ot(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';c()})()+(()=>{if(r.tag==="Just")return' stroke="'+Po(r._1.color)+'" stroke-opacity="'+$t(ot(r._1.color.a)/255)+'" stroke-width="'+$t(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";c()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";c()})()+'"';if(r.tag==="Nothing")return"";c()})()+"/>",k0=t=>e=>'<path d="'+J1(t)+'" fill="none" stroke="'+Po(e.color)+'" stroke-opacity="'+$t(ot(e.color.a)/255)+'" stroke-width="'+$t(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";c()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";c()})()+'"/>',S0=t=>'<text x="'+$t(t.x)+'" y="'+$t(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"";c()})()+' fill="'+Po(t.color)+'" fill-opacity="'+$t(ot(t.color.a)/255)+'" font-size="'+$t(t.font.size)+'" font-family="'+b0(t.font.family)+'" 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";c()})()+'">'+b0(Xi(t.content))+"</text>",SS=t=>"matrix("+Hr(t.a)+" "+Hr(t.b)+" "+Hr(t.c)+" "+Hr(t.d)+" "+Hr(t.e)+" "+Hr(t.f)+")",E0={fillPath:t=>e=>n=>{const r=og(n)(t);return()=>{const o=r();return Ze(L0(o)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=og(n)(t);return()=>{const o=r(),i=n.bake.value;return Ze(k0(o)((()=>{if(i.tag==="Nothing")return e;if(i.tag==="Just")return{...e,width:i._1.sx*e.width};c()})()))(n)()}},fillStrokePath:t=>e=>n=>r=>{const o=og(r)(t);return()=>{const i=o(),a=r.bake.value;return Ze(L0(i)(e.color)+k0(i)((()=>{if(a.tag==="Nothing")return n;if(a.tag==="Just")return{...n,width:a._1.sx*n.width};c()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>o=>{const i=o.bake;return()=>{const a=i.value;return Ze(kS((()=>{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};c()})())((()=>{if(a.tag==="Nothing")return e;if(a.tag==="Just")return a._1.sx*e;c()})())(n)(r.tag==="Just"?T("Just",(()=>{if(a.tag==="Nothing")return r._1;if(a.tag==="Just")return{...r._1,width:a._1.sx*r._1.width};c()})()):y))(o)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return Ze(S0((()=>{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}};c()})()))(e)()}},drawTextAffine:t=>e=>Ze((()=>{const n='transform="'+SS(t)+'"';return(n===""?"<g>":"<g "+n+">")+S0(e)+"</g>"})()),pushTransform:t=>Ze((()=>{const e='transform="'+TS(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:Ze("</g>"),pushBakedTransform:t=>e=>{const n=e.bake;return()=>{n.value=T("Just",t)}},popBakedTransform:t=>{const e=t.bake;return()=>{e.value=y}},pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const o=r.value;n.clipCounter.value=o+1|0;const i=og(n)(t)(),a="clip"+ue(o);return Ze((()=>{const s='clip-path="url(#'+a+')"';return'<defs><clipPath id="'+a+'"><path d="'+J1(i)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";c()})()+"/></clipPath></defs>"+(s===""?"<g>":"<g "+s+">")})())(n)()}},popClip:Ze("</g>"),pushBlend:t=>Ze((()=>{const e=(()=>{if(t==="Normal")return'style="mix-blend-mode: normal"';if(t==="Difference")return'style="mix-blend-mode: difference"';c()})();return e===""?"<g>":"<g "+e+">"})()),popBlend:Ze("</g>"),pushAlpha:t=>Ze((()=>{const e='opacity="'+$t(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:Ze("</g>"),pushBlur:t=>e=>{if(t<.01)return Ze("<g>")(e);const n=e.patternCounter;return()=>{const r=n.value;e.patternCounter.value=r+1|0;const o="lvl-blur-"+ue(r);return Ze((()=>{const i='filter="url(#'+o+')"';return'<defs><filter id="'+o+'" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="'+$t(t)+'"/></filter></defs>'+(i===""?"<g>":"<g "+i+">")})())(e)()}},popBlur:Ze("</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=>Ze('<rect x="'+$t(e.viewport.vx)+'" y="'+$t(e.viewport.vy)+'" width="'+$t(e.viewport.vw)+'" height="'+$t(e.viewport.vh)+'" fill="'+Po(t)+'" opacity="'+$t(ot(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,Ze(LS("bg-dots-"+ue(r))(t))(e)()}},measureText:t=>e=>n=>{const r=Ec(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Rc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>zc,Monad0:()=>C0},ES=h0(E0),RS=Yp(C0)(E0.measureText),PS=t=>e=>n=>r=>o=>{const i={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;c()})(),halftoneShadows:!1,watermark:"",theme:n,outputAspect:t},a=_s(i)(o);return{viewBox:rg(a.vx)+" "+rg(a.vy)+" "+rg(a.vw)+" "+rg(a.vh),body:(()=>{const s=[],u={value:0},g={value:0},_={value:0},f={value:y};return ES(h1(i)(e)(o))({out:s,maskDepth:u,clipCounter:g,patternCounter:_,viewport:a,bake:f})(),dr("")(s)})(),vx:a.vx,vy:a.vy,vw:a.vw,vh:a.vh}},BS=t=>e=>n=>r=>o=>i=>{const a={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;c()})(),outputAspect:t},s=z_(o)((()=>{const u=[],g={value:0},_={value:0},f={value:0},l={value:y},d=r.levels.length-1|0;if(d>=0&&d<r.levels.length){const h=f1(_s(a)(r))(r.levels[d]);return RS(h)(r.levels[d].segment.layout)(r.levels[d].state)({out:u,maskDepth:g,clipCounter:_,patternCounter:f,viewport:h,bake:l})()}return W})())(i);return{parts:PS(t)(s.applied)(e)(n)(r),springs:s.springs}},Bo=(t,e)=>({tag:t,_1:e}),ig=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Hn=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},R0=fe(G)(Qt),P0=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=G.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}}c()}return o},B0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},ag=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},sg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Si=(()=>{const t=gn.unfoldr(e=>{if(e.tag==="Nil")return y;if(e.tag==="Cons")return T("Just",E(e._1,e._2));c()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Jt("Cons",r._3,n(r._6,o)));c()};return n(e,A)})())})(),GS=b(t=>e=>it(G)(e)()(t))(W),w1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=G.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}}c()}return o},AS=bs(zi),G0=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},IS=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},ug=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=G.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}}c()}return o},zS=Bo("NoKeyframes"),DS=t=>Bo("DuplicateEventId",t),FS=t=>Bo("UnknownEvent",t),MS=t=>e=>({...e,cameraSpans:ld(e.cameraConfig)(t)(e.timing.edgeEasing)(e.layout)(e.keyframes)({endT:e.totalDuration,spans:e.spans,windows:e.windows,segments:e.segments,dives:e.dives}),cameraViewport:t}),QS=t=>e=>n=>r=>{const o=ig(r.edge)(e.edges),i=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return Ga(o._1);c()})(),a=Hn(t.minTokenDuration)(Hn(ot(b(s=>u=>s+Ke(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}},WS=vs(t=>{const e=$i(`
|
|
9
|
+
`)(t);return e.length===0?[""]:e}),OS=t=>e=>R0(ht(n=>{if(n.kind.tag==="SendToken")return T("Just",E(n.id,{post:(()=>{const r=n.id;return(()=>{const o=n.kind._1.to;return oe(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;c()},e)})()?0:t.tokenHold})()}));if(n.kind.tag==="FillNodeWithoutTransition")return y;c()})(e)),HS=t=>{if(t.event.kind.tag==="SendToken")return T("Just",{startT:t.startT,endT:t.endT,target:oi("TokenWindow",t.event.id,t.event.kind._1.edge,t.event.kind._1.direction,t.event.kind._1.from,t.event.kind._1.to,t.event.kind._1.labels,t.holdPre,t.holdPost)});if(t.event.kind.tag==="FillNodeWithoutTransition")return T("Just",{startT:t.startT,endT:t.endT,target:oi("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});c()},$S=t=>ht((()=>{const e=t.path;return n=>n.target.tag==="TokenWindow"?T("Just",{path:e,eventId:n.target._1,window:n,from:n.target._4,to:n.target._5,labels:n.target._6,holdPre:n.target._7,holdPost:n.target._8}):y})())(t.windows),qS=t=>e=>n=>{const r=ig(n)(t);if(r.tag==="Nothing")return pd;if(r.tag==="Just"){const o=P0(r._1.target)(e);return P0(r._1.source)(e)?o?VT:qT:pd}c()},A0=t=>e=>{if(t.tag==="Just"&&t._1>e.endT+1e-4){const n=Hn(0)(e.endT-e.startT),r=Hn(e.startT)(t._1-n);return{...e,startT:r,endT:r+n}}return e},I0=K(wa),VS={post:0},US=t=>e=>n=>r=>o=>{const i=B0(o.event.id)(n),a=(()=>{if(i.tag==="Nothing")return VS;if(i.tag==="Just")return i._1;c()})(),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 g=o.event.when._1,_=te(f=>f.event.id===g)(r);if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1.endT;c()}if(o.event.when.tag==="With"){const g=o.event.when._1,_=te(f=>f.event.id===g)(r);if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1.startT}c()})(),u=(()=>{if(o.event.kind.tag==="SendToken")return QS(t)(e)(a)(o.event.kind._1);if(o.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};c()})();return Et(r)({startT:s,endT:s+u.duration,event:o.event,holdPre:u.holdPre,holdPost:u.holdPost})},z0=t=>e=>n=>b(US(t)(e)(OS(t)(n)))([])(Ft(r=>o=>({event:o}))(n)),XS=t=>b(e=>n=>{const r=Rr(e);if(r.tag==="Nothing")return[n];if(r.tag==="Just")return n.startT<=r._1.last.endT+1e-4?Et(r._1.init)({...r._1.last,endT:Hn(r._1.last.endT)(n.endT)}):Et(e)(n);c()})([])(Rt(e=>n=>at.compare(e.startT)(n.startT))(t)),KS=t=>e=>{const n=ag(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;c()},YS=t=>e=>{const n=Rt(at.compare)(ht(r=>r.target.tag==="RelabelWindow"?r.target._1===e?T("Just",r.startT):y:r.target.tag==="TokenWindow"?r.target._4===e||r.target._5===e?T("Just",r.startT):y:r.target.tag==="FillWindow"&&r.target._2===e?T("Just",r.startT):y)(t));return 0<n.length?T("Just",n[0]):y},ZS=t=>e=>{const n=Rt(at.compare)(ht(r=>r.target.tag==="TokenWindow"&&r.target._2===e?T("Just",r.startT):y)(t));return 0<n.length?T("Just",n[0]):y},jS=t=>e=>e.target.tag==="NodeWindow"?e.target._2==="PlopIn"?A0(YS(t.windows)(e.target._1))(e):e:e.target.tag==="EdgeWindow"&&e.target._2.tag==="Extend"?A0(ZS(t.windows)(e.target._1))(e):e,tE=t=>({...t,windows:Rt(e=>n=>at.compare(e.startT)(n.startT))(K(jS(t))(t.windows))}),eE=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];c()},gg={id:"",nodes:W,edges:W,labels:W,kind:Ra,authored:!1},nE=t=>e=>Lx((()=>{const n=sg(e.from)(t);if(n.tag==="Nothing")return gg;if(n.tag==="Just")return n._1;c()})())((()=>{const n=sg(e.to)(t);if(n.tag==="Nothing")return gg;if(n.tag==="Just")return n._1;c()})()),rE=t=>e=>{const n=ag(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:W};if(n.tag==="Just")return n._1;c()},D0={id:"",index:-1,kind:"",name:"",time:0,endTime:0,path:[],tokenIndex:-1,lineIndex:-1,text:"",from:"",to:""},oE=t=>e=>e.scene.tag==="StepScene"?T("Just",{...D0,id:"step:"+e.scene._1,kind:"step",name:e.scene._1,time:e.startT,endTime:e.startT,path:I0(t)}):y,iE=t=>ht(oE(t.path))(t.spans),T1=t=>e=>n=>r=>{const o=ig(r)(n.edges);if(o.tag==="Just")return t<=0?e:Hn(e)(Ga(o._1)/t);if(o.tag==="Nothing")return e;c()},F0=t=>e=>n=>r=>o=>{const i=sg(o.to)(n),a=(()=>{if(i.tag==="Nothing")return gg;if(i.tag==="Just")return i._1;c()})(),s=t.plop,u=sg(o.from)(n),g=(()=>{if(u.tag==="Nothing")return gg;if(u.tag==="Just")return u._1;c()})(),_=nE(n)(o),f=K(J=>({startT:0,endT:0+T1(t.edgeSpeed)(t.minEdgeDuration)(e)(J),target:oi("EdgeWindow",J,cu("Extend",n_))}))(Si(_.entering.edges)),l=K(J=>({startT:0,endT:s,target:oi("NodeWindow",J,Wc)}))(Si(_.entering.nodes)),d=K(J=>({startT:0,endT:t.plop,target:oi("RelabelWindow",J.node,J.oldLabel,J.newLabel)}))(ht(J=>{const w=ag(J)(g.labels);if(w.tag==="Just"){const N=ag(J)(a.labels);if(N.tag==="Just")return w._1===N._1?y:T("Just",{node:J,oldLabel:w._1,newLabel:N._1});if(N.tag==="Nothing")return y;c()}if(w.tag==="Nothing")return y;c()})(Si(_.surviving.nodes))),h=b(Hn)(0)(K(J=>T1(t.edgeSpeed)(t.minEdgeDuration)(e)(J))(Si(_.leaving.edges))),m=J=>oe(w=>{const N=ig(w)(r);if(N.tag==="Just")return N._1.source===J||N._1.target===J;if(N.tag==="Nothing")return!1;c()},Si(_.leaving.edges))?h:0,p=K(J=>({startT:m(J),endT:m(J)+t.plop,target:oi("NodeWindow",J,Aw)}))(Si(_.leaving.nodes)),x=K(J=>({startT:0,endT:T1(t.edgeSpeed)(t.minEdgeDuration)(e)(J),target:oi("EdgeWindow",J,cu("Retract",qS(r)(_.leaving.nodes)(J)))}))(Si(_.leaving.edges));return{duration:(()=>{const J=Rt(at.compare)([...K(N=>N.endT)(x),...K(N=>N.endT)(p),...K(N=>N.endT)(l),...K(N=>N.endT)(d),...K(N=>N.endT)(f)]),w=J.length-1|0;return w>=0&&w<J.length?J[w]+t.gap:t.gap})(),windows:[...x,...p,...l,...d,...f]}},aE=t=>e=>n=>r=>o=>i=>K((()=>{const a=o.startT;return s=>({...s,startT:s.startT+a,endT:s.endT+a})})())(F0(t)(e)(n)(r)(i).windows),sE=t=>ht(e=>Mt(Ai,e).length>1?T("Just",(()=>{const n=Bt(r=>y,r=>o=>T("Just",{head:r,tail:o}),Mt(Ai,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";c()})()):y)(_y(zi)(Rt(G.compare)(t))),uE=t=>{const e=K(r=>r.id)(t),n=GS(e);return[...K(DS)(sE(e)),...K(FS)(_t(r=>!w1(r)(n),St(t)(eE)))]},gE=t=>{const e=R0(K(r=>E(r.id,(()=>{if(r.when.tag==="First")return[];if(r.when.tag==="At")return[];if(r.when.tag==="After")return[r.when._1];if(r.when.tag==="With")return[r.when._1];c()})()))(t)),n=r=>o=>i=>{if(w1(i)(o))return[Bo("ScheduleCycle",[...Mt(Jn.foldr,o),i])];if(w1(i)(r))return[];const a=B0(i)(e);if(a.tag==="Nothing")return[];if(a.tag==="Just")return St(a._1)(n(it(G)(i)()(r))(it(G)(i)()(o)));c()};return St(t)(r=>n(W)(W)(r.id))},cE={plop:.5,gap:0,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:0,stillHold:1.8,hatchHold:0,tokenReadSecPerChar:.06,nodeEasing:zx,edgeEasing:fr,tokenEasing:mc,diveDur:2.45,retreatDur:2.45},_E=t=>e=>n=>r=>K((()=>{const o=n.startT;return i=>({...i,startT:i.startT+o,endT:i.endT+o})})())(ht(HS)(z0(t)(e)(r.events))),fE=t=>e=>n=>r=>o=>{if(o.scene.tag==="Structural")return aE(t)(e)(n)(r)(o)(o.scene._1);if(o.scene.tag==="Hold")return[];if(o.scene.tag==="DataFlow")return _E(t)(e)(o)(o.scene._1);if(o.scene.tag==="EnterNode")return[];if(o.scene.tag==="ExitNode")return[];if(o.scene.tag==="StepScene")return[];c()},lE=t=>e=>n=>{const r=z0(t)(e)(n.events);return r.length===0?t.gap:b(Hn)(0)(K(o=>o.endT)(r))+t.gap},dE=t=>e=>n=>r=>o=>{if(o.tag==="Structural")return F0(t)(e)(n)(r)(o._1).duration;if(o.tag==="Hold")return t.stillHold;if(o.tag==="DataFlow")return lE(t)(e)(o._1);if(o.tag==="EnterNode"||o.tag==="ExitNode"||o.tag==="StepScene")return 0;c()},M0=t=>e=>n=>r=>o=>i=>{const a=vJ(e)(r),s=n.layout,u=Mf(K(p=>E(p.id,p))(o.keyframes)),g=0<o.keyframes.length?T("Just",o.keyframes[0]):y,_=(()=>{if(g.tag==="Just")return g._1.id;if(g.tag==="Nothing")return"";c()})(),f=Ax(o),l=p=>({startT:p.runStart,endT:p.t,path:r,layout:s,placement:a,windows:p.runWindows,spans:p.runSpans,keyframes:u,initialKeyframe:_,edgeEndpoints:f}),d=p=>({segments:p.runSpans.length===0?p.segments:Et(p.segments)(l(p)),spans:p.spans,windows:p.windows,dives:p.dives}),h=b(p=>x=>{if(x.tag==="EnterNode"){const L=d(p),C=p.runSpans.length===0?{...L,segments:Et(L.segments)(l(p))}:L,R=p.t+t.diveDur,P=Et(r)(x._1),I=M0(t)(e)(rE(n)(x._1))(P)(KS(o)(x._1))(R),U=I.endT+t.retreatDur;return{...p,t:U,runStart:U,runSpans:[],runWindows:[],segments:[...C.segments,...I.segments],spans:[...C.spans,...I.spans],windows:[...C.windows,...I.windows],dives:[...C.dives,{startT:p.t,endT:R,node:x._1,parentPath:r,childPath:P,direction:Iw},...I.dives,{startT:I.endT,endT:U,node:x._1,parentPath:r,childPath:P,direction:zw}]}}if(x.tag==="ExitNode")return p;const J=p.t+dE(t)(s)(u)(f)(x),w={startT:p.t,endT:J,scene:x},N=fE(t)(s)(u)(f)(w);return{...p,t:J,runSpans:Et(p.runSpans)(w),runWindows:[...p.runWindows,...N],spans:Et(p.spans)(w),windows:[...p.windows,...N]}})({t:i,runStart:i,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(o.scenes),m=d(h);return{endT:h.t,spans:m.spans,windows:Rt(p=>x=>at.compare(p.startT)(x.startT))(m.windows),segments:r.length===0||oe(p=>AS(p.path)(r),m.segments)?m.segments:Et(m.segments)(l(h)),dives:m.dives}},hE=t=>e=>{const n=at.compare(t.time)(e.time);return n==="EQ"?G.compare(t.id)(e.id):n},or=t=>e=>e-b(n=>r=>n+Hn(0)(G0(e)(r.endT)-r.startT))(0)(t),pE=t=>e=>{const n=Hn(t.startT)(e.startT),r=G0(t.endT)(e.endT);return r>n+1e-4?T("Just",{startT:n,endT:r}):y},mE=t=>e=>{if(e.scene.tag==="Structural"){const n=b(r=>o=>({cursor:Hn(r.cursor)(o.endT),cuts:o.startT>r.cursor+1e-4?Et(r.cuts)({startT:r.cursor,endT:o.startT}):r.cuts}))({cursor:e.startT,cuts:[]})(Rt(r=>o=>at.compare(r.startT)(o.startT))(ht(pE(e))(t)));return e.endT>n.cursor+1e-4?Et(n.cuts)({startT:n.cursor,endT:e.endT}):n.cuts}return[]},yE=t=>{const e=XS(St(t.spans)(mE(t.windows)));return e.length===0?t:{...t,endT:or(e)(t.endT),spans:K(n=>({...n,startT:or(e)(n.startT),endT:or(e)(n.endT)}))(t.spans),windows:Rt(n=>r=>at.compare(n.startT)(r.startT))(K(n=>({...n,startT:or(e)(n.startT),endT:or(e)(n.endT)}))(t.windows)),segments:K(n=>({...n,startT:or(e)(n.startT),endT:or(e)(n.endT),spans:K(r=>({...r,startT:or(e)(r.startT),endT:or(e)(r.endT)}))(n.spans),windows:Rt(r=>o=>at.compare(r.startT)(o.startT))(K(r=>({...r,startT:or(e)(r.startT),endT:or(e)(r.endT)}))(n.windows))}))(t.segments),dives:K(n=>({...n,startT:or(e)(n.startT),endT:or(e)(n.endT)}))(t.dives)}},xE=t=>{const e=K(tE)(t.segments);return yE({...t,segments:e,windows:Rt(n=>r=>at.compare(n.startT)(r.startT))(St(e)(n=>n.windows))})},JE=t=>e=>n=>{const r=Hn(.05)(1-t-e),o=u=>{if(u<=0)return 0;if(u>=1)return 1;const g=t+u*r;return g<0?0:g>1?1:g},i=WS(n),a=K(u=>ot(IS(1)(Ke(u).length)))(i),s=Hn(1)(b(ur)(0)(a));return Ft(u=>g=>({lineIndex:u,text:g,start:o(b(ur)(0)(u<1?[]:At(0,u,a))/s),end:o(u>=0&&u<a.length?(b(ur)(0)(u<1?[]:At(0,u,a))+a[u])/s:(b(ur)(0)(u<1?[]:At(0,u,a))+1)/s)}))(i)},wE=t=>{const e=Hn(0)(t.window.endT-t.window.startT);return K(n=>({...D0,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:I0(t.path),tokenIndex:t.tokenIndex,lineIndex:n.lineIndex,text:n.text,from:t.from,to:t.to}))(JE(t.holdPre)(t.holdPost)(t.labels))},TE=t=>St(Ft(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)($S)))(wE),NE=t=>Ft(e=>n=>({...n,index:e}))(Rt(hE)([...St(t.segments)(iE),...TE(t.segments)])),bE=t=>e=>{if(e.tag==="Structural")return ht(n=>n)([ug(e._1.from)(t)?y:T("Just",Bo("UnknownKeyframe",e._1.from)),ug(e._1.to)(t)?y:T("Just",Bo("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return ht(n=>n)([ug(e._1)(t)?y:T("Just",Bo("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...ht(n=>n)([ug(e._1.keyframe)(t)?y:T("Just",Bo("UnknownKeyframe",e._1.keyframe))]),...uE(e._1.events),...gE(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];if(e.tag==="StepScene")return[];c()},vE=t=>e=>{const n=St(e)(bE(t));return n.length===0?zt("Right",void 0):zt("Left",n)},CE=t=>e=>n=>r=>o=>{if(0<r.keyframes.length){const i=r.keyframes[0],a=Mf(K(u=>E(u.id,u))(r.keyframes)),s=vE(a)(r.scenes);return(()=>{if(s.tag==="Left"){const u=s._1;return g=>zt("Left",u)}if(s.tag==="Right"){const u=s._1;return g=>g(u)}c()})()(()=>{const u=xE(M0(n)(o)(o)([])(r)(0)),g=r.minimumFontSize.tag==="Just"&&r.minimumFontSize._1>0?{...t,minimumReadableLabelPx:r.minimumFontSize._1}:t;return zt("Right",{totalDuration:u.endT,windows:u.windows,spans:u.spans,keyframes:a,initialKeyframe:i.id,timing:n,layout:o.layout,cameraSpans:ld(g)(e)(n.edgeEasing)(o.layout)(a)(u),cameraConfig:g,cameraViewport:e,levelTree:o,segments:u.segments,dives:u.dives,cues:NE(u),seed:r.seed})})}return zt("Left",[zS])},Ei=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(o=>n(o._1)(o._2)),Apply0:()=>Q0(t)}),Q0=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>o=>i=>e.map(a=>E(r(a._1),a._2))(o(i))};return{apply:(()=>{const r=Ei(t);return o=>i=>r.bind(o)(a=>r.bind(i)(s=>Ri(t).pure(a(s))))})(),Functor0:()=>n}},Ri=t=>({pure:e=>n=>t.Applicative0().pure(E(e,n)),Apply0:()=>Q0(t)}),W0=t=>{const e={Applicative0:()=>Ri(t),Bind1:()=>Ei(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},ir=(t,e)=>({tag:"ParseError",_1:t,_2:e}),k=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),cg=(t,e,n)=>({tag:t,_1:e,_2:n}),LE=t=>cg("More",t),kE=t=>cg("Lift",t),SE={defer:t=>{const e=ox(t);return(n,r,o,i,a)=>ix(e)(n,r,o,i,a)}},O0={map:t=>e=>(n,r,o,i,a)=>r(s=>e(n,r,o,i,(u,g)=>r(_=>a(u,t(g)))))},EE={alt:t=>e=>(n,r,o,i,a)=>{const s=n._1,u=n._2;return r(g=>t(k(s,u,!1),r,o,(_,f)=>{const l=_._3;return r(d=>l?i(_,f):e(n,r,o,i,a))},a))},Functor0:()=>O0},RE=t=>{const e=t.Monad0();return n=>r=>{const o=i=>{let a=i,s=!0,u;for(;s;){const g=a();if(g.tag==="More"){a=g._1;continue}if(g.tag==="Lift"){s=!1,u=e.Bind1().Apply0().Functor0().map(zg)(g._1);continue}if(g.tag==="Stop"){s=!1,u=e.Applicative0().pure(Gi("Done",E(g._2,g._1)));continue}c()}return u};return t.tailRecM(o)(i=>r(n,LE,kE,(a,s)=>cg("Stop",a,zt("Left",s)),(a,s)=>cg("Stop",a,zt("Right",s))))}},$n=(t,e,n,r,o)=>o(t,t._2),PE={index:0,line:1,column:1},H0=(t=>{const e=RE(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(Ns)(e(k(n,PE,!1))(r))})(A2),_g=(t,e,n,r,o)=>o(k(t._1,t._2,!0),void 0),$0={apply:t=>e=>(n,r,o,i,a)=>r(s=>t(n,r,o,i,(u,g)=>r(_=>{const f=n._3&&!u._3?k(u._1,u._2,!0):u;return e(f,r,o,i,(l,d)=>r(h=>a(f._3&&!l._3?k(l._1,l._2,!0):l,g(d))))}))),Functor0:()=>O0},q0={pure:t=>(e,n,r,o,i)=>i(e,t),Apply0:()=>$0},BE={bind:t=>e=>(n,r,o,i,a)=>r(s=>t(n,r,o,i,(u,g)=>r(_=>e(g)(n._3&&!u._3?k(u._1,u._2,!0):u,r,o,i,a)))),Apply0:()=>$0},GE={Applicative0:()=>q0,Bind1:()=>BE},fg=t=>(e,n,r,o,i)=>n(a=>$n(e,n,r,o,(s,u)=>n(g=>o(e._3&&!s._3?k(s._1,s._2,!0):s,ir(t,u))))),AE={empty:fg("No alternative"),Alt0:()=>EE},IE={Applicative0:()=>q0,Plus1:()=>AE},Fe=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return o=>t.tailRecM(i=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(zg)(o))(r.pure(Gi("Done",void 0))))(a=>r.pure((()=>{if(a.tag==="Loop")return Gi("Loop",Jt("Cons",a._1,i));if(a.tag==="Done")return Gi("Done",(s=>u=>{let g=s,_=u,f=!0,l;for(;f;){const d=g,h=_;if(h.tag==="Nil"){f=!1,l=d;continue}if(h.tag==="Cons"){g=Jt("Cons",h._1,d),_=h._2;continue}c()}return l})(A)(i));c()})())))(A)})({tailRecM:t=>e=>(n,r,o,i,a)=>{const s=(u,g,_)=>t(g)(u,r,o,i,(f,l)=>{const d=u._3&&!f._3?k(f._1,f._2,!0):f;if(l.tag==="Loop")return _===0?r(h=>s(d,l._1,30)):s(d,l._1,_-1|0);if(l.tag==="Done")return a(d,l._1);c()});return s(n,e,30)},Monad0:()=>GE})(IE),xt=t=>e=>{const n=fg("Expected "+e);return(r,o,i,a,s)=>{const u=r._1,g=r._2;return o(_=>t(k(u,g,!1),o,i,(f,l)=>{const d=f._3;return o(h=>d?a(f,l):n(r,o,i,a,s))},s))}},Go=t=>(e,n,r,o,i)=>{const a=e._3,s=e._1,u=e._2;return n(g=>{const _=(f,l)=>{const d=f._3;return n(h=>d?o(k(f._1,f._2,a),l):i(e,void 0))};return n(f=>n(l=>t(k(s,u,!1),n,r,(d,h)=>_(k(d._1,d._2,!1),h),(d,h)=>n(m=>n(p=>fg("Negated parser succeeded")(d,n,r,_,(x,J)=>n(w=>i(d._3&&!x._3?k(x._1,x._2,!0):x,J))))))))})},zE=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return T("Just",n);if(r.tag==="Just")return T("Just",(o,i,a,s,u)=>{const g=o._1,_=o._2;return i(f=>n(k(g,_,!1),i,a,(l,d)=>{const h=l._3;return i(m=>h?s(l,d):r._1(o,i,a,s,u))},u))});c()})(y);return n=>{const r=e(n);if(r.tag==="Nothing")return fg("No alternative");if(r.tag==="Just")return r._1;c()}},V0=t=>e=>n=>(r,o,i,a,s)=>o(u=>o(g=>o(_=>o(f=>t(r,o,i,a,(l,d)=>o(h=>o(m=>{const p=r._3&&!l._3?k(l._1,l._2,!0):l;return n(p,o,i,a,(x,J)=>o(w=>{const N=p._3&&!x._3?k(x._1,x._2,!0):x;return o(L=>o(C=>{const R=r._3&&!N._3?k(N._1,N._2,!0):N;return e(R,o,i,a,(P,I)=>o(U=>s(R._3&&!P._3?k(P._1,P._2,!0):P,J)))}))}))}))))))),N1=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=xJ()(n);return r.tag==="Just"&&r._1===10?{index:t.index+1|0,line:t.line,column:t.column}:{index:t.index+1|0,line:t.line+1|0,column:1}}return e===9?{index:t.index+1|0,line:t.line,column:(t.column+8|0)-lo(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},DE=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,g=o,_=i,f=qs(g);if(f.tag==="Nothing"){a=!1,s=u;continue}if(f.tag==="Just"){r=f._1.tail===""?N1(u)(f._1.head)(_):N1(u)(f._1.head)(f._1.tail),o=f._1.tail,i=_;continue}c()}return s},Pt=t=>(e,n,r,o,i)=>{const a=qs(e._1);if(a.tag==="Nothing")return o(e,ir("Unexpected EOF",e._2));if(a.tag==="Just"){if(a._1.head<0||a._1.head>65535)return o(e,ir("Expected Char",e._2));if(a._1.head>=0&&a._1.head<=65535){const s=Uf(a._1.head);return t(s)?i(k(a._1.tail,N1(e._2)(a._1.head)(a._1.tail),!0),s):o(e,ir("Predicate unsatisfied",e._2))}}c()},xa=(t,e,n,r,o)=>t._1===""?o(k(t._1,t._2,!0),void 0):r(t,ir("Expected EOF",t._2)),FE=t=>(e,n,r,o,i)=>{const a=t(e._1);if(a.tag==="Left")return o(e,ir(a._1,e._2));if(a.tag==="Right")return i(k(a._1.remainder,DE(e._2)(a._1.consumed)(a._1.remainder),a._1.consumed!==""),a._1.value);c()},Ee=t=>FE(e=>{const n=Jr(t)(e);return n.tag==="Just"?zt("Right",{value:t,consumed:t,remainder:n._1}):zt("Left","Expected "+T2(t))}),b1=Pt(t=>!0),U0=(t,e)=>({tag:t,_1:e}),X0=(t,e,n)=>({tag:t,_1:e,_2:n}),ME=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=G.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}}c()}return o},K0=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},QE=t=>e=>b(n=>r=>(()=>{if(n.tag==="Left"){const o=n._1;return i=>zt("Left",o)}if(n.tag==="Right"){const o=n._1;return i=>i(o)}c()})()(o=>t(o)(r)))(zt("Right",e)),Y0=t=>e=>n=>ME(t)(n.values)?zt("Right",{...n,values:it(G)(t)(e)(n.values)}):zt("Left","label has no placeholder `"+t+"`"),Z0=(()=>{const t=Go((e,n,r,o,i)=>{const a=e._3;return Ee("{{")(e,n,r,(s,u)=>o(k(s._1,s._2,a),u),i)});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>b1(e._3&&!s._3?k(s._1,s._2,!0):s,n,r,o,i))))})(),WE=(()=>{const t=Go((e,n,r,o,i)=>{const a=e._3;return Ee("}}")(e,n,r,(s,u)=>o(k(s._1,s._2,a),u),i)});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>b1(e._3&&!s._3?k(s._1,s._2,!0):s,n,r,o,i))))})(),Ja=t=>dr("")(K(e=>{if(e.tag==="LabelText")return e._1;if(e.tag==="LabelSlot"){const n=K0(e._1)(t.values);if(n.tag==="Just")return n._1;if(n.tag==="Nothing")return""}c()})(t.parts)),OE=(t,e,n,r,o)=>e(i=>Z0(t,e,n,r,(a,s)=>e(u=>{const g=Fe(Z0),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>o(_._3&&!l._3?k(l._1,l._2,!0):l,X0("ParsedText",An([s,...Mt(ce.foldr,d)]))))))}))),HE=t=>t===" "||t===" "||t===`
|
|
10
|
+
`||t==="\r",j0=(()=>{const t=Fe(Pt(HE));return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>i(s,void 0))))})(),$E=t=>t>="a"&&t<="z"||t>="A"&&t<="Z"||t==="_",qE=t=>t>="a"&&t<="z"||t>="A"&&t<="Z"||t==="_"||t>="0"&&t<="9"||t==="-",VE=(t,e,n,r,o)=>e(i=>Pt($E)(t,e,n,r,(a,s)=>e(u=>{const g=Fe(Pt(qE)),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>o(_._3&&!l._3?k(l._1,l._2,!0):l,In(s)+An(Mt(ce.foldr,d))))))}))),UE=(t,e,n,r,o)=>e(i=>Ee("{{")(t,e,n,r,(a,s)=>e(u=>{const g=t._3&&!a._3?k(a._1,a._2,!0):a;return e(_=>j0(g,e,n,r,(f,l)=>e(d=>{const h=g._3&&!f._3?k(f._1,f._2,!0):f;return e(m=>VE(h,e,n,r,(p,x)=>e(J=>{const w=h._3&&!p._3?k(p._1,p._2,!0):p;return e(N=>j0(w,e,n,r,(L,C)=>e(R=>{const P=xt(Pt(U=>U===":"))("':'"),I=w._3&&!L._3?k(L._1,L._2,!0):L;return e(U=>P(I,e,n,r,(S,v)=>e(F=>{const H=Fe(WE),M=I._3&&!S._3?k(S._1,S._2,!0):S;return e(q=>e($=>H(M,e,n,r,(B,D)=>e(Q=>{const O=An(Mt(ce.foldr,D));return e(z=>{const Y=M._3&&!B._3?k(B._1,B._2,!0):B;return e(V=>Ee("}}")(Y,e,n,r,(X,Z)=>e(nt=>o(Y._3&&!X._3?k(X._1,X._2,!0):X,X0("ParsedSlot",x,Ba(O))))))})}))))})))})))})))})))}))),XE=(()=>{const t=Fe((e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>UE(k(a,s,!1),n,r,(g,_)=>{const f=g._3;return n(l=>f?o(g,_):OE(e,n,r,o,i))},i))});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>i(s,Mt(ce.foldr,u)))))})(),KE=t=>{const e=QE(n=>r=>{if(r.tag==="ParsedText")return zt("Right",{...n,parts:Et(n.parts)(U0("LabelText",r._1))});if(r.tag==="ParsedSlot"){const o=K0(r._1)(n.values);return o.tag==="Just"&&o._1!==r._2?zt("Left","placeholder `"+r._1+"` has conflicting initial values"):zt("Right",{parts:Et(n.parts)(U0("LabelSlot",r._1)),values:it(G)(r._1)(r._2)(n.values)})}c()})({parts:[],values:W})(t);if(e.tag==="Left")return zt("Left",e._1);if(e.tag==="Right")return zt("Right",e._1);c()},lg=t=>{const e=H0(t)((n,r,o,i,a)=>r(s=>r(u=>XE(n,r,o,i,(g,_)=>r(f=>r(l=>{const d=n._3&&!g._3?k(g._1,g._2,!0):g;return xa(d,r,o,i,(h,m)=>r(p=>a(d._3&&!h._3?k(h._1,h._2,!0):h,_)))}))))));if(e.tag==="Left")return zt("Left",e._1._1);if(e.tag==="Right")return KE(e._1);c()},Pi=(t,e)=>({tag:t,_1:e}),$r=(t,e)=>({tag:t,_1:e}),dg=t=>t,ar=(t,e)=>({tag:t,_1:e}),v1=t=>t,tm=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},YE=fe(G)(Qt),em=(()=>{const t=gn.unfoldr(e=>{if(e.tag==="Nil")return y;if(e.tag==="Cons")return T("Just",E(e._1,e._2));c()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Jt("Cons",r._3,n(r._6,o)));c()};return n(e,A)})())})(),Le=W0(Xn),ZE=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},jE=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=G.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}}c()}return o},t4=fe(G)(Qt),C1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},e4=b(t=>e=>it(G)(e)()(t))(W),Xt=Ei(Xn),Xe=Le.state(t=>E(t,t)),ye=Ri(Xn),nm=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=G.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}}c()}return o},rm=Mo(ye),L1=rm(Qt),n4=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=G.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}}c()}return o},Nr=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=G.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}}c()}return o},br=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=G.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}}c()}return o},r4=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=G.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}}c()}return o},hg=t=>e=>n=>b(r=>o=>t.Bind1().bind(r)(i=>e(i)(o)))(t.Applicative0().pure(n)),o4=b(t=>e=>it(G)(e)()(t))(W),i4=(()=>{const t=(e=>n=>{let r=e,o=n,i=!0,a;for(;i;){const s=r,u=o;if(u.tag==="Nil"){i=!1,a=s;continue}if(u.tag==="Cons"){r=it(G)(u._1)()(s),o=u._2;continue}c()}return a})(W);return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Jt("Cons",r._3,n(r._6,o)));c()};return n(e,A)})())})(),a4=b(t=>e=>it(G)(e)()(t))(W),s4=rm(K2),u4=v1("AnimatedSurface"),g4=v1("StillSurface"),c4=v1("SequenceSurface"),_4=ar("Exit"),pg=dg("AnimatedKeyframe"),k1=dg("Still"),f4=dg("Title"),om=dg("StepMarker"),l4=t=>$r("Par",t),d4=t=>$r("Seq",t),h4=t=>$r("GroupSeq",t),im=t=>Pi("StepDive",t),p4={line:0,column:0,endLine:0,endColumn:0},m4=t=>e=>n=>{const r=Wo(Yt,y,o=>o._1===t,n);if(r.tag==="Just"){const o=co(Yt,y,r._1,E(t,e),n);if(o.tag==="Nothing")return n;if(o.tag==="Just")return o._1;c()}if(r.tag==="Nothing")return Et(n)(E(t,e));c()},y4=t=>e=>K(n=>n._1===t?E(n._1,{...n._2,label:T("Just",e)}):E(n._1,n._2)),am=t=>YE(ht(e=>{const n=tm(e)(t.currLabels);return n.tag==="Just"?T("Just",E(e,n._1)):y})(em(t.currNodes))),sm=t=>{const e=t.compare;return n=>b(r=>o=>nn(e,tn,r,n(o)))(W)},S1=sm(G),E1=sm(G),um=t=>e=>Le.state(n=>E(void 0,{...n,graphNodes:y4(t)(Ja(e))(n.graphNodes),currLabels:it(G)(t)(Ja(e))(n.currLabels),currLabelTemplates:it(G)(t)(e)(n.currLabelTemplates)})),x4=t=>{const e=t.span;return Le.state(n=>E(void 0,{...n,currentSpan:e}))},J4=ot(4)*8,w4=t=>t.tag==="Just"&&Na(t._1)&&t._1>0?E(ZE(1)(t._1/J4),1):E(1,1),T4=t=>e=>({structural:[...t.structural,...e.structural],flow:t.flow||e.flow,dives:[...t.dives,...e.dives]}),N4=t=>e=>e.kind==="Animated"||jE(e.id)(t),gm={graphNodes:[],graphEdges:W,currNodes:W,currEdges:W,currLabels:W,currLabelTemplates:W,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:y,currentSpan:p4,error:y,enterStack:[],interiorOf:W,stepNames:W},cm=t=>e=>n=>{const r=Mt(Jn.foldr,n);return dr(", ")(K(e)(At(0,6,r)))+(r.length>6?", \u2026":"")},b4=t=>e=>{const n=C1(e)(t4(K(r=>E(r.id,r))(t.graph.edges)));if(n.tag==="Just")return(()=>{const r=Jr("conn:")(n._1.id);if(r.tag==="Just")return!1;if(r.tag==="Nothing")return!0;c()})()?n._1.from.node+" -> "+n._1.to.node:n._1.from.node+" -- "+n._1.to.node;if(n.tag==="Nothing")return e;c()},v4=t=>e=>n=>{const r=cm()(wa)(e),o=cm()(b4(t))(n);return(r===""?"animated flow contains unused topology: every animated node or edge must be visited by a token or fill.":"animated flow contains unused topology: every animated node or edge must be visited by a token or fill. Unused nodes: "+r+".")+(o===""?"":" Unused edges: "+o+".")+" Move context-only topology into a `still`/`title`, remove it, or add token/fill events."},C4=t=>{if(t.kind.tag==="SendToken")return e4([t.kind._1.from,t.kind._1.to]);if(t.kind.tag==="FillNodeWithoutTransition")return ee("Node",1,1,t.kind._1.node,void 0,W,W);c()},L4=t=>S1(C4)(t.events),k4=t=>{if(t.kind.tag==="SendToken")return ee("Node",1,1,t.kind._1.edge,void 0,W,W);if(t.kind.tag==="FillNodeWithoutTransition")return W;c()},S4=t=>E1(k4)(t.events),vr=t=>Le.state(e=>E(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:T("Just",{msg:t,line:e.currentSpan.line,column:e.currentSpan.column,endLine:e.currentSpan.endLine,endColumn:e.currentSpan.endColumn})};c()})())),E4=L1(t=>Xt.bind(Xe)(e=>{if(e.error.tag==="Just")return ye.pure();if(e.error.tag==="Nothing")return nm(t.node)(e.interiorOf)?vr("node "+t.node+" has more than one `inside` block"):Le.state(n=>E(void 0,{...n,interiorOf:it(G)(t.node)(t.doc)(n.interiorOf)}));c()})),R4=t=>Xt.bind(Xe)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ue(e.kfCounter);if(oe(o=>o.id===n,e.keyframes))return vr("duplicate frame name "+n);const r={...e,keyframes:Et(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges,labels:am(e),kind:Ra,authored:(()=>{if(t.tag==="Just")return t._1!=="";if(t.tag==="Nothing")return!1;c()})()}),kfCounter:e.kfCounter+1|0,currentKf:T("Just",n)};return Le.state(o=>E(void 0,r))}),Oe=t=>e=>Xt.bind(Le.state(n=>E(void 0,{...n,currentSpan:t})))(()=>vr(e)),_m=t=>e=>Xt.bind(Xe)(n=>n4(e)(n.stepNames)?Oe(t)("duplicate step name "+e):Le.state(r=>E(void 0,{...r,scenes:Et(r.scenes)(Wi("StepScene",e)),stepNames:it(G)(e)()(r.stepNames)}))),P4=t=>{if(t.ops.tag==="Leaf"){const e=t.ops._1;return Xt.bind((()=>{const n=e.span;return Le.state(r=>E(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?_m(e.span)(e.op._1.name):vr("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 Xt.bind((()=>{const n=e.span;return Le.state(r=>E(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?_m(e.span)(e.op._1.name):vr("step marker frame did not contain a step"))}return vr("step marker frame did not contain a step")},B4=t=>Xt.bind((()=>{const e=t.span;return Le.state(n=>E(void 0,{...n,currentSpan:e}))})())(()=>Xt.bind(Xe)(e=>{if(e.error.tag==="Just")return ye.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!Nr(t.op._1.id)(e.currNodes))return Oe(0<t.operands.length?t.operands[0]:t.span)("cannot dive into node "+t.op._1.id+": does not exist");if(!nm(t.op._1.id)(e.interiorOf))return Oe(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+` {
|
|
11
11
|
+ detail: Detail
|
|
12
|
-
}`);const n=t.op._1;return Le.state(r=>E(void 0,{...r,enterStack:Et(r.enterStack)(n.id),scenes:Et(r.scenes)(Hi("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=Sr(e.enterStack);if(n.tag==="Nothing")return Nr("`out` without a matching `into`");if(n.tag==="Just"){const r=n._1.init;return Le.state(o=>E(void 0,{...o,enterStack:r,scenes:Et(o.scenes)(vx)}))}c()}return ye.pure()}c()})),mg={structural:[],flow:!1,dives:[]},P4=Kt.bind(Ke)(t=>{if(t.error.tag==="Just")return ye.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return Le.state(n=>E(void 0,{...n,scenes:Et(n.scenes)(Hi("Hold",e))}))}if(t.currentKf.tag==="Nothing")return ye.pure()}c()}),G4=t=>e=>Kt.bind(Ke)(n=>{const r="ev-"+ue(n.eventCounter);return Kt.bind((()=>{const o={...n,eventCounter:n.eventCounter+1|0};return Le.state(i=>E(void 0,o))})())(()=>ye.pure({events:[{id:r,kind:e,when:t}],firstId:T("Just",r),lastId:T("Just",r)}))}),B4=t=>t.tag==="DataFlow"?T("Just",t._1):y,A4=t=>ht(e=>C1(e)(t.graphEdges))(Mt(Ai,em(t.currEdges))),I4=t=>e=>{const n=_t(o=>o.from.node===e.id||o.to.node===e.id,A4(t)),r=hg(Y1)(o=>i=>{const a=i.from+"->"+e.id,s=e.id+"->"+i.to,u=i.from+"->"+i.to,g="via "+i.from+" "+i.to+": no edge "+i.from+"\u2192"+e.id;if(!Tr(a)(t.currEdges))return zt("Left",g);const _="via "+i.from+" "+i.to+": no edge "+e.id+"\u2192"+i.to;if(!Tr(s)(t.currEdges))return zt("Left",_);const f="via "+i.from+" "+i.to+": would create "+i.from+"\u2192"+i.to+" but it already exists";return Tr(u)(t.currEdges)||e4(u)(o.synthesized)?zt("Left",f):zt("Right",{consumed:it(B)(a)()(it(B)(s)()(o.consumed)),synthesized:it(B)(u)({id:u,from:{node:i.from,port:y},to:{node:i.to,port:y},label:y})(o.synthesized)})})({consumed:H,synthesized:H})(e.via);return(()=>{if(r.tag==="Left"){const o=r._1;return i=>zt("Left",o)}if(r.tag==="Right"){const o=r._1;return i=>i(o)}c()})()(o=>{const i=o.consumed,a=_t(s=>!Tr(s.id)(i),n);return a.length===0?zt("Right",{nextCurrEdges:en(B.compare,je,Kn(B.compare,t.currEdges,n4(Y(s=>s.id)(n))),r4((()=>{const s=u=>{if(u.tag==="Leaf")return H;if(u.tag==="Node")return ee("Node",u._1,u._2,u._3,void 0,s(u._5),s(u._6));c()};return s(o.synthesized)})())),synthesized:o.synthesized}):zt("Left","cannot delete node "+e.id+": still connected ("+dr(", ")(Y(s=>(()=>{const u=xr("conn:")(s.id);if(u.tag==="Just")return!1;if(u.tag==="Nothing")return!0;c()})()?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.")})},fm=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}},lm=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq"||t.tag==="GroupSeq")return St(t._1)(lm);c()},z4=t=>({nodes:Y(Ts)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,wt("Cons",n._4,e(n._6,r)));c()};return Mt(ce.foldr,e(t.graphEdges,A))})(),constraints:[]}),R1=t=>{if(t.tag==="Leaf")return t._1.op.tag==="AddNode"||t._1.op.tag==="DelNode"||t._1.op.tag==="ModNode"||t._1.op.tag==="ModNodeSlot"||t._1.op.tag==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?{...mg,structural:[t._1]}:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?{...mg,dives:[t._1]}:{...mg,flow:!0};if(t.tag==="Seq"||t.tag==="GroupSeq"||t.tag==="Par")return b(w4)(mg)(Y(R1)(t._1));c()},yg=t=>{if(t.tag==="Leaf")return t._1.op.tag==="AddNode"||t._1.op.tag==="DelNode"||t._1.op.tag==="ModNode"||t._1.op.tag==="ModNodeSlot"||t._1.op.tag==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?[Pi("StepStructural",[t._1])]:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?[Pi("StepDive",t._1)]:[Pi("StepFlow",t)];if(t.tag==="Seq")return St(t._1)(yg);if(t.tag==="GroupSeq")return D4(t)(t._1);if(t.tag==="Par")return F4(t)(t._1);c()},F4=t=>e=>{const n=R1(t);return n.structural.length!==0&&!n.flow&&n.dives.length===0?[Pi("StepStructural",n.structural)]:n.structural.length===0&&n.flow&&n.dives.length===0?[Pi("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?Y(im)(n.dives):St(e)(yg)},D4=t=>e=>{const n=R1(t);return n.structural.length===0&&n.flow&&n.dives.length===0?[Pi("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?Y(im)(n.dives):St(e)(yg)},M4=t=>e=>Kt.bind(Ke)(n=>{const r=e.from+"->"+e.to,o=e.newFrom+"->"+e.newTo;return Tr(r)(n.currEdges)?Jr(e.newFrom)(n.currNodes)?Jr(e.newTo)(n.currNodes)?r!==o&&Tr(o)(n.currEdges)?Oe((()=>{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"):Le.state(i=>E(void 0,{...i,currEdges:it(B)(o)()(Mi(B)(r)(i.currEdges)),graphEdges:it(B)(o)({id:o,from:{node:e.newFrom,port:y},to:{node:e.newTo,port:y},label:y})(i.graphEdges)})):Oe(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):Oe(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):Oe((()=>{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")}),Q4=t=>e=>{const n=ht(B4)(e.scenes),r=_t(J4(o4(Y(a=>a.keyframe)(n))),e.keyframes),o=Kn(B.compare,S1(a=>a.nodes)(r),S1(v4)(n)),i=Kn(B.compare,E1(a=>a.edges)(r),E1(L4)(n));return t!=="AnimatedSurface"||n.length===0||o.tag==="Leaf"&&i.tag==="Leaf"?y:T("Just",N4(e)(o)(i))},H4=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 T("Just",{id:r,direction:Ff});if(Tr(n)(t.currEdges))return T("Just",{id:n,direction:Df});const i=C1(o)(t.graphEdges);if(i.tag==="Just")return Tr(o)(t.currEdges)?T("Just",{id:o,direction:i._1.from.node===e.from&&i._1.to.node===e.to?Ff:Df}):y;if(i.tag==="Nothing")return y;c()},O4=t=>e=>{if(e.op.tag==="Token"){const n=e.op._1;return Kt.bind(Ke)(r=>{const o=!Jr(n.from)(r.currNodes),i=!Jr(n.to)(r.currNodes);if(o||i)return Kt.bind(Oe(fm(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: "))(()=>ye.pure({events:[],firstId:y,lastId:y}));const a=H4(r)(n);if(a.tag==="Just")return G4(t)(Jx("SendToken",{from:n.from,to:n.to,edge:a._1.id,direction:a._1.direction,labels:n.labels}));if(a.tag==="Nothing")return Kt.bind(Oe((()=>{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))(()=>ye.pure({events:[],firstId:y,lastId:y}));c()})}return ye.pure({events:[],firstId:y,lastId:y})},W4=t=>e=>{const n=It(r=>y,r=>o=>T("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return ye.pure({events:[],firstId:y,lastId:y});if(n.tag==="Just"){const r=n._1.tail;return Kt.bind(hs(t)(n._1.head))(o=>Kt.bind(hg({Applicative0:()=>Ri(qn),Bind1:()=>Ei(qn)})(i=>a=>Kt.bind(hs((()=>{if(i.lastId.tag==="Just")return fc("After",i.lastId._1);if(i.lastId.tag==="Nothing")return t;c()})())(a))(s=>ye.pure({events:[...i.events,...s.events],firstId:(()=>{if(i.firstId.tag==="Just")return T("Just",i.firstId._1);if(i.firstId.tag==="Nothing")return s.firstId;c()})(),lastId:(()=>{if(s.lastId.tag==="Just")return T("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return i.lastId;c()})()})))(o)(r))(i=>ye.pure(i)))}c()},$4=t=>e=>{const n=It(r=>y,r=>o=>T("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return ye.pure({events:[],firstId:y,lastId:y});if(n.tag==="Just"){const r=n._1.tail;return Kt.bind(hs(t)(n._1.head))(o=>Kt.bind(q4((()=>{if(o.firstId.tag==="Just")return fc("With",o.firstId._1);if(o.firstId.tag==="Nothing")return t;c()})())(r))(i=>ye.pure({events:[...o.events,...i.events],firstId:o.firstId,lastId:(()=>{if(o.lastId.tag==="Just")return T("Just",o.lastId._1);if(o.lastId.tag==="Nothing")return i.lastId;c()})()})))}c()},hs=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return Kt.bind((()=>{const r=n.span;return Le.state(o=>E(void 0,{...o,currentSpan:r}))})())(()=>O4(t)(n))}if(e.tag==="Seq"||e.tag==="GroupSeq")return W4(t)(e._1);if(e.tag==="Par")return $4(t)(e._1);c()},q4=t=>hg({Applicative0:()=>Ri(qn),Bind1:()=>Ei(qn)})(e=>n=>Kt.bind(hs(t)(n))(r=>ye.pure({events:[...e.events,...r.events],firstId:(()=>{if(e.firstId.tag==="Just")return T("Just",e.firstId._1);if(e.firstId.tag==="Nothing")return r.firstId;c()})(),lastId:(()=>{if(r.lastId.tag==="Just")return T("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;c()})()})))({events:[],firstId:y,lastId:y}),V4=t=>Kt.bind(Ke)(e=>{if(e.currentKf.tag==="Nothing")return Nr("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return Kt.bind(hs(bx)(t))(r=>Kt.bind(Ke)(o=>{const i={...o,scenes:Et(o.scenes)(Hi("DataFlow",{keyframe:n,events:r.events,focus:y}))};return Le.state(a=>E(void 0,i))}))}c()}),U4=t=>e=>Le.state(n=>E(void 0,{...n,graphNodes:h4(t.id)({id:t.id,size:x4(t.width),ports:[],label:T("Just",wa(e)),shape:t.shape})(n.graphNodes),currNodes:it(B)(t.id)()(n.currNodes),currLabels:it(B)(t.id)(wa(e))(n.currLabels),currLabelTemplates:it(B)(t.id)(e)(n.currLabelTemplates)})),K4=t=>{if(t.op.tag==="AddNode"){const e=t.op._1;return Kt.bind(Ke)(n=>{if(Jr(e.id)(n.currNodes))return Oe(0<t.operands.length?t.operands[0]:t.span)("cannot add node "+e.id+": already exists");const r=lg(e.label);if(r.tag==="Left")return Oe(0<t.operands.length?t.operands[0]:t.span)("invalid label for node "+e.id+": "+r._1);if(r.tag==="Right")return U4(e)(r._1);c()})}if(t.op.tag==="DelNode"){const e=t.op._1;return Kt.bind(Ke)(n=>{if(!Jr(e.id)(n.currNodes))return Oe(0<t.operands.length?t.operands[0]:t.span)("cannot delete node "+e.id+": does not exist");const r=I4(n)(e);if(r.tag==="Left")return Oe(0<t.operands.length?t.operands[0]:t.span)(r._1);if(r.tag==="Right"){const o=r._1;return Le.state(i=>E(void 0,{...i,currNodes:Mi(B)(e.id)(i.currNodes),currEdges:o.nextCurrEdges,graphEdges:en(B.compare,je,o.synthesized,i.graphEdges)}))}c()})}if(t.op.tag==="ModNode"){const e=t.op._1;return Kt.bind(Ke)(n=>{if(!Jr(e.id)(n.currNodes))return Oe(0<t.operands.length?t.operands[0]:t.span)("cannot relabel node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=lg(e.label._1);if(r.tag==="Left")return Oe(0<t.operands.length?t.operands[0]:t.span)("invalid label for node "+e.id+": "+r._1);if(r.tag==="Right")return um(e.id)(r._1);c()}if(e.label.tag==="Nothing")return ye.pure();c()})}if(t.op.tag==="ModNodeSlot"){const e=t.op._1;return Kt.bind(Ke)(n=>{if(!Jr(e.id)(n.currNodes))return Oe(0<t.operands.length?t.operands[0]:t.span)("cannot update placeholder on node "+e.id+": does not exist");const r=tm(e.id)(n.currLabelTemplates);if(r.tag==="Nothing")return Oe(1<t.operands.length?t.operands[1]:t.span)("node "+e.id+" label has no placeholder `"+e.slot+"`");if(r.tag==="Just"){const o=X0(e.slot)(e.value)(r._1);if(o.tag==="Left")return Oe(1<t.operands.length?t.operands[1]:t.span)("node "+e.id+" "+o._1);if(o.tag==="Right")return um(e.id)(o._1)}c()})}if(t.op.tag==="AddEdge"){const e=t.op._1;return Kt.bind(Ke)(n=>{const r=!Jr(e.from)(n.currNodes),o=!Jr(e.to)(n.currNodes);if(r||o)return Oe(fm(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)?Oe((()=>{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"):Le.state(a=>E(void 0,{...a,graphEdges:it(B)(i)({id:i,from:{node:e.from,port:y},to:{node:e.to,port:y},label:e.label})(a.graphEdges),currEdges:it(B)(i)()(a.currEdges)}))})}if(t.op.tag==="DelEdge"){const e=t.op._1;return Kt.bind(Ke)(n=>{const r=e.directed?e.from+"->"+e.to:e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;return Tr(r)(n.currEdges)?Le.state(o=>E(void 0,{...o,currEdges:Mi(B)(r)(o.currEdges)})):Oe((()=>{const o=0<t.operands.length?t.operands[0]:t.span,i=1<t.operands.length?t.operands[1]:t.span;return{line:o.line,column:o.column,endLine:i.endLine,endColumn:i.endColumn}})())((e.directed?"cannot delete edge ":"cannot delete connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": does not exist")})}return t.op.tag==="RepointEdge"?M4(t)(t.op._1):ye.pure()},Y4=t=>Kt.bind((()=>{const e=t.span;return Le.state(n=>E(void 0,{...n,currentSpan:e}))})())(()=>K4(t)),dm=t=>e=>n=>Kt.bind(L1(Y4)(n))(()=>Kt.bind(Ke)(r=>{const o=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ue(r.kfCounter);if(oe(a=>a.id===o,r.keyframes))return Kt.bind(i4(m4)(0<n.length?T("Just",n[0]):y))(()=>Nr("duplicate frame name "+o));const i={...r,keyframes:Et(r.keyframes)({id:o,nodes:r.currNodes,edges:r.currEdges,labels:am(r),kind:t,authored:(()=>{if(e.tag==="Just")return e._1!=="";if(e.tag==="Nothing")return!1;c()})()}),kfCounter:r.kfCounter+1|0,currentKf:T("Just",o),scenes:(()=>{if(r.currentKf.tag==="Nothing")return r.scenes;if(r.currentKf.tag==="Just")return Et(r.scenes)(Hi("Structural",{from:r.currentKf._1,to:o,focus:y}));c()})()};return Le.state(a=>E(void 0,i))})),X4=t=>e=>n=>{if(n.tag==="StepStructural")return Kt.bind((()=>{const r=dm(Ra)(e?y:t)(n._1);return n._1.length!==0?r:ye.pure()})())(()=>ye.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;c()})();return Kt.bind((()=>{const i=S4(t);return o?i:ye.pure()})())(()=>Kt.bind(V4(r))(()=>ye.pure(e||o)))}if(n.tag==="StepDive")return Kt.bind(R4(n._1))(()=>ye.pure(e));c()},hm=t=>e=>n=>{const r=It(o=>y,o=>i=>T("Just",{head:o,tail:i}),n);if(r.tag==="Nothing")return ye.pure();if(r.tag==="Just"){const o=r._1.head,i=r._1.tail;return Kt.bind(Ke)(a=>{if(a.error.tag==="Just")return ye.pure();if(a.error.tag==="Nothing")return Kt.bind(X4(t)(e)(o))(s=>hm(t)(s)(i));c()})}c()},pm=t=>e=>{const n=lm(e.ops),r=_t(i=>i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="ModNodeSlot"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge",n),o=_t(i=>!(i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="ModNodeSlot"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge"),n);return 0<o.length?Kt.bind((()=>{const i=o[0].span;return Le.state(a=>E(void 0,{...a,currentSpan:i}))})())(()=>Nr("still/title blocks hold a still snapshot; they cannot contain movement tokens (`api ~> db`) or dive commands (`into`/`out`)")):t==="TitleCard"&&r.length===0?Nr(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"):Kt.bind(dm(t)(e.name)(r))(()=>P4)},Z4=t=>Kt.bind(Ke)(e=>{if(e.error.tag==="Just")return ye.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return hm(t.name)(!1)(yg(t.ops));if(t.kind==="Still")return pm(Tx)(t);if(t.kind==="Title")return pm(Nx)(t);if(t.kind==="StepMarker")return E4(t)}c()}),mm=t=>Kt.bind(k4(t.interiors))(()=>Kt.bind(L1(Z4)(t.frames))(()=>Kt.bind(Ke)(e=>{if(e.error.tag==="Just")return ye.pure(zt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=j4(t.interiors);if(n.tag==="Left")return ye.pure(zt("Left",n._1));if(n.tag==="Right"){const r={seed:t.seed,minimumFontSize:t.minimumFontSize,stretchNodes:t.stretchNodes,graph:z4(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1};return ye.pure((()=>{const o=Q4(t.mode)(r);if(o.tag==="Just")return zt("Left",{msg:o._1,line:0,column:0,endLine:0,endColumn:0});if(o.tag==="Nothing")return zt("Right",r);c()})())}}c()}))),j4=t=>{const e=hg(Y1)(n=>r=>{const o=mm(r.doc)(gm)._1;return(()=>{if(o.tag==="Left"){const i=o._1;return a=>zt("Left",i)}if(o.tag==="Right"){const i=o._1;return a=>a(i)}c()})()(i=>zt("Right",it(B)(r.node)(i)(n)))})(H)(t);if(e.tag==="Left")return zt("Left",e._1);if(e.tag==="Right")return zt("Right",e._1);c()},xg=(t,e)=>({tag:t,_1:e}),P1=AE(Qt),tR=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},eR=fe(B)(Qt),ym=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},ps=(()=>{const t=xt(Pt(r=>r==="}"))("'}'"),e=xt(Pt(r=>r==="#"))("'#'"),n=Pt(r=>r===`
|
|
13
|
-
`||r==="\r");return(r,o,i,a,s)=>{const u=r._1,g=r._2;return o(_=>o(f=>t(
|
|
14
|
-
`||e==="\r");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>i(e._3&&!s._3?
|
|
15
|
-
`)),_=t._3&&!a._3?
|
|
16
|
-
`||n==="\r");return(n,r,o,i,a)=>{const s=n._1,u=n._2;return r(g=>r(_=>t(
|
|
17
|
-
`&&t!=="\r"&&t!=="#"&&t!=="}"&&t!=="{",
|
|
18
|
-
`||t==="\r"||t==="#"||t==="}",
|
|
19
|
-
`||t==="\r"||t==="#"||t==="}"||t==="{",
|
|
20
|
-
`&&t!=="\r",Tm=t=>
|
|
21
|
-
`:d==="t"?" ":d==="r"?"\r":d))))})))})(),
|
|
22
|
-
`);return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>
|
|
12
|
+
}`);const n=t.op._1;return Le.state(r=>E(void 0,{...r,enterStack:Et(r.enterStack)(n.id),scenes:Et(r.scenes)(Wi("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=Rr(e.enterStack);if(n.tag==="Nothing")return vr("`out` without a matching `into`");if(n.tag==="Just"){const r=n._1.init;return Le.state(o=>E(void 0,{...o,enterStack:r,scenes:Et(o.scenes)(vx)}))}c()}return ye.pure()}c()})),mg={structural:[],flow:!1,dives:[]},G4=Xt.bind(Xe)(t=>{if(t.error.tag==="Just")return ye.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return Le.state(n=>E(void 0,{...n,scenes:Et(n.scenes)(Wi("Hold",e))}))}if(t.currentKf.tag==="Nothing")return ye.pure()}c()}),A4=t=>e=>Xt.bind(Xe)(n=>{const r="ev-"+ue(n.eventCounter);return Xt.bind((()=>{const o={...n,eventCounter:n.eventCounter+1|0};return Le.state(i=>E(void 0,o))})())(()=>ye.pure({events:[{id:r,kind:e,when:t}],firstId:T("Just",r),lastId:T("Just",r)}))}),I4=t=>t.tag==="DataFlow"?T("Just",t._1):y,z4=t=>ht(e=>C1(e)(t.graphEdges))(Mt(Ai,em(t.currEdges))),D4=t=>e=>{const n=_t(o=>o.from.node===e.id||o.to.node===e.id,z4(t)),r=hg(K1)(o=>i=>{const a=i.from+"->"+e.id,s=e.id+"->"+i.to,u=i.from+"->"+i.to,g="via "+i.from+" "+i.to+": no edge "+i.from+"\u2192"+e.id;if(!br(a)(t.currEdges))return zt("Left",g);const _="via "+i.from+" "+i.to+": no edge "+e.id+"\u2192"+i.to;if(!br(s)(t.currEdges))return zt("Left",_);const f="via "+i.from+" "+i.to+": would create "+i.from+"\u2192"+i.to+" but it already exists";return br(u)(t.currEdges)||r4(u)(o.synthesized)?zt("Left",f):zt("Right",{consumed:it(G)(a)()(it(G)(s)()(o.consumed)),synthesized:it(G)(u)({id:u,from:{node:i.from,port:y},to:{node:i.to,port:y},label:y})(o.synthesized)})})({consumed:W,synthesized:W})(e.via);return(()=>{if(r.tag==="Left"){const o=r._1;return i=>zt("Left",o)}if(r.tag==="Right"){const o=r._1;return i=>i(o)}c()})()(o=>{const i=o.consumed,a=_t(s=>!br(s.id)(i),n);return a.length===0?zt("Right",{nextCurrEdges:nn(G.compare,tn,Zn(G.compare,t.currEdges,o4(K(s=>s.id)(n))),i4((()=>{const s=u=>{if(u.tag==="Leaf")return W;if(u.tag==="Node")return ee("Node",u._1,u._2,u._3,void 0,s(u._5),s(u._6));c()};return s(o.synthesized)})())),synthesized:o.synthesized}):zt("Left","cannot delete node "+e.id+": still connected ("+dr(", ")(K(s=>(()=>{const u=Jr("conn:")(s.id);if(u.tag==="Just")return!1;if(u.tag==="Nothing")return!0;c()})()?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.")})},fm=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}},lm=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq"||t.tag==="GroupSeq")return St(t._1)(lm);c()},F4=t=>({nodes:K(Ts)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Jt("Cons",n._4,e(n._6,r)));c()};return Mt(ce.foldr,e(t.graphEdges,A))})(),constraints:[]}),R1=t=>{if(t.tag==="Leaf")return t._1.op.tag==="AddNode"||t._1.op.tag==="DelNode"||t._1.op.tag==="ModNode"||t._1.op.tag==="ModNodeSlot"||t._1.op.tag==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?{...mg,structural:[t._1]}:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?{...mg,dives:[t._1]}:{...mg,flow:!0};if(t.tag==="Seq"||t.tag==="GroupSeq"||t.tag==="Par")return b(T4)(mg)(K(R1)(t._1));c()},yg=t=>{if(t.tag==="Leaf")return t._1.op.tag==="AddNode"||t._1.op.tag==="DelNode"||t._1.op.tag==="ModNode"||t._1.op.tag==="ModNodeSlot"||t._1.op.tag==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?[Pi("StepStructural",[t._1])]:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?[Pi("StepDive",t._1)]:[Pi("StepFlow",t)];if(t.tag==="Seq")return St(t._1)(yg);if(t.tag==="GroupSeq")return Q4(t)(t._1);if(t.tag==="Par")return M4(t)(t._1);c()},M4=t=>e=>{const n=R1(t);return n.structural.length!==0&&!n.flow&&n.dives.length===0?[Pi("StepStructural",n.structural)]:n.structural.length===0&&n.flow&&n.dives.length===0?[Pi("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?K(im)(n.dives):St(e)(yg)},Q4=t=>e=>{const n=R1(t);return n.structural.length===0&&n.flow&&n.dives.length===0?[Pi("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?K(im)(n.dives):St(e)(yg)},W4=t=>e=>Xt.bind(Xe)(n=>{const r=e.from+"->"+e.to,o=e.newFrom+"->"+e.newTo;return br(r)(n.currEdges)?Nr(e.newFrom)(n.currNodes)?Nr(e.newTo)(n.currNodes)?r!==o&&br(o)(n.currEdges)?Oe((()=>{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"):Le.state(i=>E(void 0,{...i,currEdges:it(G)(o)()(Mi(G)(r)(i.currEdges)),graphEdges:it(G)(o)({id:o,from:{node:e.newFrom,port:y},to:{node:e.newTo,port:y},label:y})(i.graphEdges)})):Oe(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):Oe(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):Oe((()=>{const i=0<t.operands.length?t.operands[0]:t.span,a=1<t.operands.length?t.operands[1]:t.span;return{line:i.line,column:i.column,endLine:a.endLine,endColumn:a.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist")}),O4=t=>e=>{const n=ht(I4)(e.scenes),r=_t(N4(a4(K(a=>a.keyframe)(n))),e.keyframes),o=Zn(G.compare,S1(a=>a.nodes)(r),S1(L4)(n)),i=Zn(G.compare,E1(a=>a.edges)(r),E1(S4)(n));return t!=="AnimatedSurface"||n.length===0||o.tag==="Leaf"&&i.tag==="Leaf"?y:T("Just",v4(e)(o)(i))},H4=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(br(r)(t.currEdges))return T("Just",{id:r,direction:Df});if(br(n)(t.currEdges))return T("Just",{id:n,direction:Ff});const i=C1(o)(t.graphEdges);if(i.tag==="Just")return br(o)(t.currEdges)?T("Just",{id:o,direction:i._1.from.node===e.from&&i._1.to.node===e.to?Df:Ff}):y;if(i.tag==="Nothing")return y;c()},$4=t=>e=>{if(e.op.tag==="Token"){const n=e.op._1;return Xt.bind(Xe)(r=>{const o=!Nr(n.from)(r.currNodes),i=!Nr(n.to)(r.currNodes);if(o||i)return Xt.bind(Oe(fm(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: "))(()=>ye.pure({events:[],firstId:y,lastId:y}));const a=H4(r)(n);if(a.tag==="Just")return A4(t)(wx("SendToken",{from:n.from,to:n.to,edge:a._1.id,direction:a._1.direction,labels:n.labels}));if(a.tag==="Nothing")return Xt.bind(Oe((()=>{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))(()=>ye.pure({events:[],firstId:y,lastId:y}));c()})}return ye.pure({events:[],firstId:y,lastId:y})},q4=t=>e=>{const n=Bt(r=>y,r=>o=>T("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return ye.pure({events:[],firstId:y,lastId:y});if(n.tag==="Just"){const r=n._1.tail;return Xt.bind(hs(t)(n._1.head))(o=>Xt.bind(hg({Applicative0:()=>Ri(Xn),Bind1:()=>Ei(Xn)})(i=>a=>Xt.bind(hs((()=>{if(i.lastId.tag==="Just")return fc("After",i.lastId._1);if(i.lastId.tag==="Nothing")return t;c()})())(a))(s=>ye.pure({events:[...i.events,...s.events],firstId:(()=>{if(i.firstId.tag==="Just")return T("Just",i.firstId._1);if(i.firstId.tag==="Nothing")return s.firstId;c()})(),lastId:(()=>{if(s.lastId.tag==="Just")return T("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return i.lastId;c()})()})))(o)(r))(i=>ye.pure(i)))}c()},V4=t=>e=>{const n=Bt(r=>y,r=>o=>T("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return ye.pure({events:[],firstId:y,lastId:y});if(n.tag==="Just"){const r=n._1.tail;return Xt.bind(hs(t)(n._1.head))(o=>Xt.bind(U4((()=>{if(o.firstId.tag==="Just")return fc("With",o.firstId._1);if(o.firstId.tag==="Nothing")return t;c()})())(r))(i=>ye.pure({events:[...o.events,...i.events],firstId:o.firstId,lastId:(()=>{if(o.lastId.tag==="Just")return T("Just",o.lastId._1);if(o.lastId.tag==="Nothing")return i.lastId;c()})()})))}c()},hs=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return Xt.bind((()=>{const r=n.span;return Le.state(o=>E(void 0,{...o,currentSpan:r}))})())(()=>$4(t)(n))}if(e.tag==="Seq"||e.tag==="GroupSeq")return q4(t)(e._1);if(e.tag==="Par")return V4(t)(e._1);c()},U4=t=>hg({Applicative0:()=>Ri(Xn),Bind1:()=>Ei(Xn)})(e=>n=>Xt.bind(hs(t)(n))(r=>ye.pure({events:[...e.events,...r.events],firstId:(()=>{if(e.firstId.tag==="Just")return T("Just",e.firstId._1);if(e.firstId.tag==="Nothing")return r.firstId;c()})(),lastId:(()=>{if(r.lastId.tag==="Just")return T("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;c()})()})))({events:[],firstId:y,lastId:y}),X4=t=>Xt.bind(Xe)(e=>{if(e.currentKf.tag==="Nothing")return vr("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return Xt.bind(hs(bx)(t))(r=>Xt.bind(Xe)(o=>{const i={...o,scenes:Et(o.scenes)(Wi("DataFlow",{keyframe:n,events:r.events,focus:y}))};return Le.state(a=>E(void 0,i))}))}c()}),K4=t=>e=>Le.state(n=>E(void 0,{...n,graphNodes:m4(t.id)({id:t.id,size:w4(t.width),ports:[],label:T("Just",Ja(e)),shape:t.shape})(n.graphNodes),currNodes:it(G)(t.id)()(n.currNodes),currLabels:it(G)(t.id)(Ja(e))(n.currLabels),currLabelTemplates:it(G)(t.id)(e)(n.currLabelTemplates)})),Y4=t=>{if(t.op.tag==="AddNode"){const e=t.op._1;return Xt.bind(Xe)(n=>{if(Nr(e.id)(n.currNodes))return Oe(0<t.operands.length?t.operands[0]:t.span)("cannot add node "+e.id+": already exists");const r=lg(e.label);if(r.tag==="Left")return Oe(0<t.operands.length?t.operands[0]:t.span)("invalid label for node "+e.id+": "+r._1);if(r.tag==="Right")return K4(e)(r._1);c()})}if(t.op.tag==="DelNode"){const e=t.op._1;return Xt.bind(Xe)(n=>{if(!Nr(e.id)(n.currNodes))return Oe(0<t.operands.length?t.operands[0]:t.span)("cannot delete node "+e.id+": does not exist");const r=D4(n)(e);if(r.tag==="Left")return Oe(0<t.operands.length?t.operands[0]:t.span)(r._1);if(r.tag==="Right"){const o=r._1;return Le.state(i=>E(void 0,{...i,currNodes:Mi(G)(e.id)(i.currNodes),currEdges:o.nextCurrEdges,graphEdges:nn(G.compare,tn,o.synthesized,i.graphEdges)}))}c()})}if(t.op.tag==="ModNode"){const e=t.op._1;return Xt.bind(Xe)(n=>{if(!Nr(e.id)(n.currNodes))return Oe(0<t.operands.length?t.operands[0]:t.span)("cannot relabel node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=lg(e.label._1);if(r.tag==="Left")return Oe(0<t.operands.length?t.operands[0]:t.span)("invalid label for node "+e.id+": "+r._1);if(r.tag==="Right")return um(e.id)(r._1);c()}if(e.label.tag==="Nothing")return ye.pure();c()})}if(t.op.tag==="ModNodeSlot"){const e=t.op._1;return Xt.bind(Xe)(n=>{if(!Nr(e.id)(n.currNodes))return Oe(0<t.operands.length?t.operands[0]:t.span)("cannot update placeholder on node "+e.id+": does not exist");const r=tm(e.id)(n.currLabelTemplates);if(r.tag==="Nothing")return Oe(1<t.operands.length?t.operands[1]:t.span)("node "+e.id+" label has no placeholder `"+e.slot+"`");if(r.tag==="Just"){const o=Y0(e.slot)(e.value)(r._1);if(o.tag==="Left")return Oe(1<t.operands.length?t.operands[1]:t.span)("node "+e.id+" "+o._1);if(o.tag==="Right")return um(e.id)(o._1)}c()})}if(t.op.tag==="AddEdge"){const e=t.op._1;return Xt.bind(Xe)(n=>{const r=!Nr(e.from)(n.currNodes),o=!Nr(e.to)(n.currNodes);if(r||o)return Oe(fm(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 br(i)(n.currEdges)?Oe((()=>{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"):Le.state(a=>E(void 0,{...a,graphEdges:it(G)(i)({id:i,from:{node:e.from,port:y},to:{node:e.to,port:y},label:e.label})(a.graphEdges),currEdges:it(G)(i)()(a.currEdges)}))})}if(t.op.tag==="DelEdge"){const e=t.op._1;return Xt.bind(Xe)(n=>{const r=e.directed?e.from+"->"+e.to:e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;return br(r)(n.currEdges)?Le.state(o=>E(void 0,{...o,currEdges:Mi(G)(r)(o.currEdges)})):Oe((()=>{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"?W4(t)(t.op._1):ye.pure()},Z4=t=>Xt.bind((()=>{const e=t.span;return Le.state(n=>E(void 0,{...n,currentSpan:e}))})())(()=>Y4(t)),dm=t=>e=>n=>Xt.bind(L1(Z4)(n))(()=>Xt.bind(Xe)(r=>{const o=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ue(r.kfCounter);if(oe(a=>a.id===o,r.keyframes))return Xt.bind(s4(x4)(0<n.length?T("Just",n[0]):y))(()=>vr("duplicate frame name "+o));const i={...r,keyframes:Et(r.keyframes)({id:o,nodes:r.currNodes,edges:r.currEdges,labels:am(r),kind:t,authored:(()=>{if(e.tag==="Just")return e._1!=="";if(e.tag==="Nothing")return!1;c()})()}),kfCounter:r.kfCounter+1|0,currentKf:T("Just",o),scenes:(()=>{if(r.currentKf.tag==="Nothing")return r.scenes;if(r.currentKf.tag==="Just")return Et(r.scenes)(Wi("Structural",{from:r.currentKf._1,to:o,focus:y}));c()})()};return Le.state(a=>E(void 0,i))})),j4=t=>e=>n=>{if(n.tag==="StepStructural")return Xt.bind((()=>{const r=dm(Ra)(e?y:t)(n._1);return n._1.length!==0?r:ye.pure()})())(()=>ye.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;c()})();return Xt.bind((()=>{const i=R4(t);return o?i:ye.pure()})())(()=>Xt.bind(X4(r))(()=>ye.pure(e||o)))}if(n.tag==="StepDive")return Xt.bind(B4(n._1))(()=>ye.pure(e));c()},hm=t=>e=>n=>{const r=Bt(o=>y,o=>i=>T("Just",{head:o,tail:i}),n);if(r.tag==="Nothing")return ye.pure();if(r.tag==="Just"){const o=r._1.head,i=r._1.tail;return Xt.bind(Xe)(a=>{if(a.error.tag==="Just")return ye.pure();if(a.error.tag==="Nothing")return Xt.bind(j4(t)(e)(o))(s=>hm(t)(s)(i));c()})}c()},pm=t=>e=>{const n=lm(e.ops),r=_t(i=>i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="ModNodeSlot"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge",n),o=_t(i=>!(i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="ModNodeSlot"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge"),n);return 0<o.length?Xt.bind((()=>{const i=o[0].span;return Le.state(a=>E(void 0,{...a,currentSpan:i}))})())(()=>vr("still/title blocks hold a still snapshot; they cannot contain movement tokens (`api ~> db`) or dive commands (`into`/`out`)")):t==="TitleCard"&&r.length===0?vr(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"):Xt.bind(dm(t)(e.name)(r))(()=>G4)},tR=t=>Xt.bind(Xe)(e=>{if(e.error.tag==="Just")return ye.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return hm(t.name)(!1)(yg(t.ops));if(t.kind==="Still")return pm(Tx)(t);if(t.kind==="Title")return pm(Nx)(t);if(t.kind==="StepMarker")return P4(t)}c()}),mm=t=>Xt.bind(E4(t.interiors))(()=>Xt.bind(L1(tR)(t.frames))(()=>Xt.bind(Xe)(e=>{if(e.error.tag==="Just")return ye.pure(zt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=eR(t.interiors);if(n.tag==="Left")return ye.pure(zt("Left",n._1));if(n.tag==="Right"){const r={seed:t.seed,minimumFontSize:t.minimumFontSize,stretchNodes:t.stretchNodes,graph:F4(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1};return ye.pure((()=>{const o=O4(t.mode)(r);if(o.tag==="Just")return zt("Left",{msg:o._1,line:0,column:0,endLine:0,endColumn:0});if(o.tag==="Nothing")return zt("Right",r);c()})())}}c()}))),eR=t=>{const e=hg(K1)(n=>r=>{const o=mm(r.doc)(gm)._1;return(()=>{if(o.tag==="Left"){const i=o._1;return a=>zt("Left",i)}if(o.tag==="Right"){const i=o._1;return a=>a(i)}c()})()(i=>zt("Right",it(G)(r.node)(i)(n)))})(W)(t);if(e.tag==="Left")return zt("Left",e._1);if(e.tag==="Right")return zt("Right",e._1);c()},xg=(t,e)=>({tag:t,_1:e}),P1=zE(Qt),nR=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},rR=fe(G)(Qt),ym=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},ps=(()=>{const t=xt(Pt(r=>r==="}"))("'}'"),e=xt(Pt(r=>r==="#"))("'#'"),n=Pt(r=>r===`
|
|
13
|
+
`||r==="\r");return(r,o,i,a,s)=>{const u=r._1,g=r._2;return o(_=>o(f=>t(k(u,g,!1),o,i,(l,d)=>o(h=>{const m=r._1,p=r._2;return o(x=>o(J=>e(k(m,p,!1),o,i,(w,N)=>o(L=>{const C=r._1,R=r._2;return o(P=>o(I=>n(k(C,R,!1),o,i,(U,S)=>o(v=>xa(r,o,i,a,s)),(U,S)=>o(v=>s(k(C,R,!1),void 0)))))}),(w,N)=>o(L=>s(k(m,p,!1),void 0)))))}),(l,d)=>o(h=>s(k(u,g,!1),void 0)))))}})(),Pn=t=>(e,n,r,o,i)=>n(a=>$n(e,n,r,o,(s,u)=>n(g=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(f=>t(_,n,r,o,(l,d)=>n(h=>{const m=_._3&&!l._3?k(l._1,l._2,!0):l;return n(p=>$n(m,n,r,o,(x,J)=>n(w=>i(m._3&&!x._3?k(x._1,x._2,!0):x,E(d,{line:u.line,column:u.column,endLine:J.line,endColumn:J.column})))))})))}))),oR=(()=>{const t=Pt(e=>e===" "||e===" "||e===`
|
|
14
|
+
`||e==="\r");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>i(e._3&&!s._3?k(s._1,s._2,!0):s,void 0))))})(),xm=(t,e,n,r,o)=>e(i=>Ee("#")(t,e,n,r,(a,s)=>e(u=>{const g=Fe(Pt(f=>f!==`
|
|
15
|
+
`)),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>o(_._3&&!l._3?k(l._1,l._2,!0):l,void 0))))}))),Jm=xt((()=>{const t=xt(Pt(n=>n==="}"))("'}'"),e=Pt(n=>n===`
|
|
16
|
+
`||n==="\r");return(n,r,o,i,a)=>{const s=n._1,u=n._2;return r(g=>r(_=>t(k(s,u,!1),r,o,(f,l)=>r(d=>{const h=n._1,m=n._2;return r(p=>r(x=>xm(k(h,m,!1),r,o,(J,w)=>{const N=J._3;return r(L=>{if(N)return i(J,w);const C=n._1,R=n._2;return r(P=>r(I=>e(k(C,R,!1),r,o,(U,S)=>{const v=U._3;return r(F=>v?i(U,S):xa(n,r,o,i,a))},(U,S)=>r(v=>a(U,void 0)))))})},(J,w)=>r(N=>a(J,void 0)))))}),(f,l)=>r(d=>a(k(s,u,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),vn=(()=>{const t=Fe((e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>oR(k(a,s,!1),n,r,(g,_)=>{const f=g._3;return n(l=>f?o(g,_):xm(e,n,r,o,i))},i))});return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>i(e._3&&!s._3?k(s._1,s._2,!0):s,void 0))))})(),wm=(()=>{const t=Pt(e=>e!=="|");return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>n(g=>Ee("\\|")(k(a,s,!1),n,r,(_,f)=>n(l=>n(d=>t(e,n,r,o,(h,m)=>n(p=>i(h,In(m)))))),(_,f)=>n(l=>i(_,"|")))))}})(),iR=xt(P1([(t,e,n,r,o)=>e(i=>{const a=t._3;return Ee("->")(t,e,n,(s,u)=>r(k(s._1,s._2,a),u),(s,u)=>e(g=>o(s,!0)))}),(t,e,n,r,o)=>e(i=>{const a=t._3;return Ee("--")(t,e,n,(s,u)=>r(k(s._1,s._2,a),u),(s,u)=>e(g=>o(s,!1)))})]))("edge arrow '->' or '--'"),aR=t=>t!==`
|
|
17
|
+
`&&t!=="\r"&&t!=="#"&&t!=="}"&&t!=="{",Jg=Pt(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),sR=t=>t===" "||t===" "||t==="\r",uR=t=>An(re(Pr(sR)(re(tr(t))).rest)),B1=t=>t===`
|
|
18
|
+
`||t==="\r"||t==="#"||t==="}",gR=t=>t===`
|
|
19
|
+
`||t==="\r"||t==="#"||t==="}"||t==="{",cR=t=>t!=="{"&&t!==`
|
|
20
|
+
`&&t!=="\r",Tm=t=>Ba(t)==="",_R=t=>re(Pr(Tm)(re(Pr(Tm)(t).rest)).rest),fR=t=>(e=>n=>{let r=e,o=n,i=!0,a;for(;i;){const s=r,u=Bt(g=>y,g=>_=>T("Just",{head:g,tail:_}),o);if(u.tag==="Just"&&(u._1.head===" "||u._1.head===" ")){r=s+1|0,o=u._1.tail;continue}i=!1,a=s}return a})(0)(tr(t)),lR=t=>{const e=Bt(n=>y,n=>r=>T("Just",{head:n,tail:r}),K(fR)(_t(n=>Ba(n)!=="",t)));if(e.tag==="Nothing")return 0;if(e.tag==="Just")return b(nR)(e._1.head)(e._1.tail);c()},dR=(()=>{const t=xt(Pt(e=>e==="-"))("'-'");return(e,n,r,o,i)=>{const a=e._3;return n(s=>t(e,n,r,(u,g)=>o(k(u._1,u._2,a),g),(u,g)=>n(_=>{const f=Go((()=>{const d=xt(Pt(m=>m===">"))("'>'"),h=xt(Pt(m=>m==="-"))("'-'");return(m,p,x,J,w)=>{const N=m._1,L=m._2;return p(C=>d(k(N,L,!1),p,x,(R,P)=>{const I=R._3;return p(U=>I?J(R,P):h(m,p,x,J,w))},w))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(d=>f(l,n,r,(h,m)=>o(k(h._1,h._2,a),m),(h,m)=>n(p=>i(l._3&&!h._3?k(h._1,h._2,!0):h,"-"))))})))}})(),ie=(()=>{const t=Fe(Pt(e=>e===" "||e===" "));return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>i(e._3&&!s._3?k(s._1,s._2,!0):s,void 0))))})(),Ao=(()=>{const t=Pt(e=>e===" "||e===" ");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>ie(e._3&&!s._3?k(s._1,s._2,!0):s,n,r,o,i))))})(),Nm=(t,e,n,r,o)=>e(i=>e(a=>ie(t,e,n,r,(s,u)=>e(g=>e(_=>{const f=t._3&&!s._3?k(s._1,s._2,!0):s;return ps(f,e,n,r,(l,d)=>e(h=>o(f._3&&!l._3?k(l._1,l._2,!0):l,d)))}))))),bm=(t,e,n,r,o)=>e(i=>ie(t,e,n,r,(a,s)=>e(u=>{const g=xt(Pt(f=>f==="-"))("'-'"),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(f=>{const l=(m,p)=>e(x=>(()=>{if(p.tag==="Just")return(J,w,N,L,C)=>w(R=>iR(J,w,N,L,(P,I)=>w(U=>C(P,T("Just",I)))));if(p.tag==="Nothing")return(J,w,N,L,C)=>C(J,y);c()})()(_._3&&!m._3?k(m._1,m._2,!0):m,e,n,r,o)),d=_._1,h=_._2;return e(m=>e(p=>g(k(d,h,!1),e,n,(x,J)=>e(w=>l(_,y)),(x,J)=>e(w=>l(k(d,h,!1),T("Just",J))))))})}))),hR=t=>{const e=Jr("Expected ")(t),n=(()=>{if(e.tag==="Nothing")return t;if(e.tag==="Just")return e._1;c()})();return n==="'{'"?"Open the block with `{`.":n==="integer (seed value)"?"Put an integer after `seed`.":n==="number (min-font-size value)"?"Put a positive number after `min-font-size`.":n==="positive min-font-size value"?"`min-font-size` must be greater than zero.":n==="closing '}'"?"Close this block with `}`.":n===`closing '"' (unterminated string)`?'This string is unterminated; close it with `"`.':n==="closing '|'"?"Close this pipe label with `|`.":n==="space after '+'"?"Put a space after `+`: `+ api: API`.":n==="node identifier after '+'"?"Put a node id after `+`: `+ api: API`.":n==="space after '-'"?"Put a space after `-`: `- api`.":n==="node identifier after '-'"?"Put a node id after `-`: `- api`.":n==="space after '~'"?"Put a space after `~`: `~ api: API` or `~ api -> db => api -> cache`.":n==="node relabel label"?"Give the replacement label after `~ api`: `~ api: API`.":n==="node placeholder value"?"Give the replacement value after the placeholder name: `~ total.count: 3`.":n==="node identifier"?"Put a node identifier here.":n==="space after 'inside'"?"Put a space after `inside`: `inside api { ... }`.":n==="node identifier after 'inside'"?"Tell `inside` which node owns this interior: `inside api { ... }`.":n==="source node identifier after 'via'"?"Put the source node after `via`: `via a b`.":n==="target node identifier after 'via'"?"Put the second endpoint after `via`: `via a b`.":n==="source node identifier"?"Put a source node identifier here.":n==="new source node identifier"?"Put the new source node identifier after `=>`.":n==="new target node identifier"?"Put the new target node identifier after the replacement arrow.":n==="edge arrow '->' or '--'"?"Use `->` for a directed edge or `--` for an undirected edge.":n==="source edge arrow '->'"?"Use `->` in the edge you are changing: `~ api -> db => api -> cache`.":n==="replacement edge arrow '->'"?"Use `->` in the replacement edge: `~ api -> db => api -> cache`.":n==="repoint separator '=>'"?"Use `=>` before the replacement edge: `~ api -> db => api -> cache`.":n==="target node identifier"?"Put a target node after the arrow.":n==="'~>'"?"Use `~>` for movement from left to right.":n==="'<~'"?"Use `<~` for movement from right to left.":n==="'->' or '<-'"?"Use `~>` / `<~` for movement tokens.":n==='label ("\u2026", : rest-of-line, or |\u2026|)'?'label must use `: text`, `"text"`, or `|multi-line|`.':n==="attribute key"?"Start each attribute with a name, like `shape`.":n==="':'"?"Put `:` between the attribute name and value: `{shape: cylinder}`.":n==="attribute value"?"Put an attribute value after `:`.":n==="closing '}' for attributes"?"Close the attribute block with `}`.":n==="space after 'into'"?"Put a space after `into`: `into api`.":n==="node identifier after 'into'"?"Tell `into` which node to dive into.":n==="space after 'step'"?"Put a space after `step`: `step request`.":n==="step name"?"Name the step: `step request`.":n==="newline or '}' (statements end at the end of the line)"?"This statement has extra text. Put the next statement on a new line or close the block with `}`.":n==="statement (+ node, - node, + edge, - edge, ~ node, into, out, or 'a ~> b'/'a <~ b')"?"I don't recognize this statement. Start with `+`, `-`, `~`, `into`, `out`, `par`, `seq`, or movement like `api ~> db`.":n==="'scene', 'still', 'title', 'step', 'inside', a statement, or end of input"?"Start with a statement like `+ api: API`, a marker like `step request`, or a block with `scene`, `still`, `title`, or `inside`.":n},pR=t=>{const e=Ba(t),n=Jr('"')(e),r=(()=>{if(n.tag==="Just")return rx('"')(n._1);if(n.tag==="Nothing")return y;c()})(),o=(()=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;c()})();return o===""?y:T("Just",o)},vm=t=>e=>t!=="AnimatedSurface"&&e.statements.length!==0?{...e,frames:Et(e.frames)((()=>{if(t==="StillSurface")return{name:y,ops:$r("Seq",e.statements),kind:k1};if(t==="SequenceSurface")return{name:y,ops:$r("Seq",e.statements),kind:pg};if(t==="AnimatedSurface")return{name:y,ops:$r("Seq",e.statements),kind:pg};c()})()),statements:[]}:e,mR=(()=>{const t=xt(Pt(e=>e==="\\"))("'\\\\'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(f=>b1(_,n,r,o,(l,d)=>n(h=>i(_._3&&!l._3?k(l._1,l._2,!0):l,d==="n"?`
|
|
21
|
+
`:d==="t"?" ":d==="r"?"\r":d))))})))})(),yR=(()=>{const t=Pt(e=>e!=='"'&&e!=="\\"&&e!==`
|
|
22
|
+
`);return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>mR(k(a,s,!1),n,r,(g,_)=>n(f=>t(e,n,r,o,i)),i))}})(),Cm=(()=>{const t=xt(Pt(e=>e==='"'))(`'"'`);return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>{const _=Fe(yR),f=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>_(f,n,r,o,(d,h)=>n(m=>{const p=xt(xt(Pt(J=>J==='"'))(`'"'`))(`closing '"' (unterminated string)`),x=f._3&&!d._3?k(d._1,d._2,!0):d;return n(J=>p(x,n,r,o,(w,N)=>n(L=>i(x._3&&!w._3?k(w._1,w._2,!0):w,An(Mt(ce.foldr,h))))))})))})))})(),xR={frames:[],statements:[]},Lm=t=>{const e=_R($i(`
|
|
23
23
|
`)(t));return dr(`
|
|
24
|
-
`)(
|
|
25
|
-
`)(
|
|
26
|
-
`)(L(P,I,!1),d,h,(S,v)=>{const D=S._3;return d(W=>D?m(S,v):Ee("\r")(l,d,h,m,p))},p))})},p))})("newline after '|md'"),f=t._3&&!s._3?L(s._1,s._2,!0):s;return e(l=>_(f,e,n,(d,h)=>r(L(d._1,d._2,i),h),(d,h)=>e(m=>{const p=De(Jm),x=f._3&&!d._3?L(d._1,d._2,!0):d;return e(w=>p(x,e,n,(J,N)=>r(L(J._1,J._2,i),N),(J,N)=>e(k=>{const C=xt(xt(Pt(P=>P==="|"))("'|'"))("closing '|'"),R=x._3&&!J._3?L(J._1,J._2,!0):J;return e(P=>C(R,e,n,(I,U)=>r(L(I._1,I._2,i),U),(I,U)=>e(S=>o(R._3&&!I._3?L(I._1,I._2,!0):I,"md:"+Lm(dr("")(Mt(ce.foldr,N)))))))})))})))})))},xR=(()=>{const t=xt(Pt(e=>e==="|"))("'|'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>{const _=De(Jm),f=e._3&&!s._3?L(s._1,s._2,!0):s;return n(l=>_(f,n,r,o,(d,h)=>n(m=>{const p=xt(xt(Pt(w=>w==="|"))("'|'"))("closing '|'"),x=f._3&&!d._3?L(d._1,d._2,!0):d;return n(w=>p(x,n,r,o,(J,N)=>n(k=>i(x._3&&!J._3?L(J._1,J._2,!0):J,Lm(dr("")(Mt(ce.foldr,h)))))))})))})))})(),br=Pt(t=>t>="0"&&t<="9"),wR=(()=>{const t=xt(Pt(e=>e==="_"))("'_'");return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>wg(L(a,s,!1),n,r,(g,_)=>{const f=g._3;return n(l=>{if(f)return o(g,_);const d=e._1,h=e._2;return n(m=>br(L(d,h,!1),n,r,(p,x)=>{const w=p._3;return n(J=>{if(w)return o(p,x);const N=e._1,k=e._2;return n(C=>t(L(N,k,!1),n,r,(R,P)=>{const I=R._3;return n(U=>I?o(R,P):fR(e,n,r,o,i))},i))})},i))})},i))}})(),We=(()=>{const t=xt(Pt(e=>e==="_"))("'_'");return(e,n,r,o,i)=>n(a=>{const s=(_,f)=>n(l=>{const d=De(wR),h=e._3&&!_._3?L(_._1,_._2,!0):_;return n(m=>d(h,n,r,o,(p,x)=>n(w=>i(h._3&&!p._3?L(p._1,p._2,!0):p,An(f)+Bn(Mt(ce.foldr,x))))))}),u=e._1,g=e._2;return n(_=>wg(L(u,g,!1),n,r,(f,l)=>{const d=f._3;return n(h=>d?o(f,l):t(e,n,r,o,s))},s))})})(),JR=t=>e=>n=>(r,o,i,a,s)=>o(u=>ie(r,o,i,a,(g,_)=>o(f=>{const l=Rn(xt(We)("target node identifier")),d=r._3&&!g._3?L(g._1,g._2,!0):g;return o(h=>l(d,o,i,a,(m,p)=>o(x=>s(d._3&&!m._3?L(m._1,m._2,!0):m,{op:ar("DelEdge",{from:t,to:p._1,directed:n}),operands:[e,p._2]}))))}))),TR=(t,e,n,r,o)=>e(i=>Hn(t,e,n,r,(a,s)=>e(u=>{const g=t._3&&!a._3?L(a._1,a._2,!0):a;return e(_=>{const f=g._3;return e(l=>We(g,e,n,(d,h)=>r(L(d._1,d._2,f),h),(d,h)=>e(m=>{const p=g._3&&!d._3?L(d._1,d._2,!0):d;return e(x=>ie(p,e,n,(w,J)=>r(L(w._1,w._2,f),J),(w,J)=>e(N=>{const k=p._3&&!w._3?L(w._1,w._2,!0):w;return e(C=>{const R=(U,S)=>e(v=>{const D=k._3&&!U._3?L(U._1,U._2,!0):U;return e(W=>r(g._3&&!D._3?L(D._1,D._2,!0):D,ir("Use `~>` / `<~` for movement tokens.",s)))}),P=k._1,I=k._2;return e(U=>Ee("->")(L(P,I,!1),e,n,(S,v)=>{const D=S._3;return e(W=>D?r(L(S._1,S._2,f),v):Ee("<-")(k,e,n,(M,q)=>r(L(M._1,M._2,f),q),R))},R))})})))})))})}))),NR=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>Rn(We)(t,e,n,(u,g)=>r(L(u._1,u._2,a),g),(u,g)=>e(_=>{const f=t._3&&!u._3?L(u._1,u._2,!0):u;return e(l=>ie(f,e,n,(d,h)=>r(L(d._1,d._2,a),h),(d,h)=>e(m=>{const p=xt(Pt(w=>w==="~"))("'~'"),x=f._3&&!d._3?L(d._1,d._2,!0):d;return e(w=>{const J=(C,R)=>e(P=>{const I=x._3&&!C._3?L(C._1,C._2,!0):C;return e(U=>{const S=g._1,v=g._2,D=t._3&&!I._3?L(I._1,I._2,!0):I;return e(W=>ie(D,e,n,r,(M,q)=>e($=>{const G=xt(Pt(O=>O==="~"))("'~'"),F=xt(Pt(O=>O==="<"))("'<'"),Q=D._3&&!M._3?L(M._1,M._2,!0):M;return e(O=>{const z=(K,Z)=>e(nt=>{const rt=Z==="~"?xt(Ee("~>"))("'~>'"):xt(Ee("<~"))("'<~'"),ft=Q._3&&!K._3?L(K._1,K._2,!0):K;return e(Nt=>rt(ft,e,n,r,(lt,mt)=>e(vt=>o(ft._3&&!lt._3?L(lt._1,lt._2,!0):lt,E(S,E(v,mt))))))}),X=Q._1,V=Q._2;return e(K=>G(L(X,V,!1),e,n,(Z,nt)=>{const rt=Z._3;return e(ft=>rt?r(Q,nt):F(Q,e,n,(Nt,lt)=>r(Q,lt),(Nt,lt)=>z(Q,lt)))},(Z,nt)=>z(Q,nt)))})})))})}),N=x._1,k=x._2;return e(C=>p(L(N,k,!1),e,n,(R,P)=>{const I=R._3;return e(U=>I?r(L(x._1,x._2,a),P):e(S=>Ee("<~")(x,e,n,(v,D)=>r(L(x._1,x._2,a),D),(v,D)=>e(W=>J(x)))))},(R,P)=>J(x)))})})))})))}),bR=t=>e=>{const n=xt(Ee("->"))("source edge arrow '->'");return(r,o,i,a,s)=>o(u=>n(r,o,i,a,(g,_)=>o(f=>{const l=r._3&&!g._3?L(g._1,g._2,!0):g;return o(d=>ie(l,o,i,a,(h,m)=>o(p=>{const x=Rn(xt(We)("target node identifier")),w=l._3&&!h._3?L(h._1,h._2,!0):h;return o(J=>x(w,o,i,a,(N,k)=>o(C=>{const R=k._1,P=k._2,I=w._3&&!N._3?L(N._1,N._2,!0):N;return o(U=>ie(I,o,i,a,(S,v)=>o(D=>{const W=xt(Ee("=>"))("repoint separator '=>'"),M=I._3&&!S._3?L(S._1,S._2,!0):S;return o(q=>W(M,o,i,a,($,G)=>o(F=>{const Q=M._3&&!$._3?L($._1,$._2,!0):$;return o(O=>ie(Q,o,i,a,(z,X)=>o(V=>{const K=Rn(xt(We)("new source node identifier")),Z=Q._3&&!z._3?L(z._1,z._2,!0):z;return o(nt=>K(Z,o,i,a,(rt,ft)=>o(Nt=>{const lt=ft._1,mt=ft._2,vt=Z._3&&!rt._3?L(rt._1,rt._2,!0):rt;return o(Wt=>ie(vt,o,i,a,(Tt,Vt)=>o(Gt=>{const bt=xt(Ee("->"))("replacement edge arrow '->'"),pt=vt._3&&!Tt._3?L(Tt._1,Tt._2,!0):Tt;return o(ct=>bt(pt,o,i,a,(Jt,At)=>o(yt=>{const Ct=pt._3&&!Jt._3?L(Jt._1,Jt._2,!0):Jt;return o(Ot=>ie(Ct,o,i,a,(Ft,se)=>o(_e=>{const pn=Rn(xt(We)("new target node identifier")),qt=Ct._3&&!Ft._3?L(Ft._1,Ft._2,!0):Ft;return o(jt=>pn(qt,o,i,a,(an,$e)=>o(Wn=>s(qt._3&&!an._3?L(an._1,an._2,!0):an,{op:ar("RepointEdge",{from:t,to:R,newFrom:lt,newTo:$e._1}),operands:[e,P,mt,$e._2]}))))})))})))})))})))})))})))})))})))})))})))},vR=(t,e,n,r,o)=>e(i=>br(t,e,n,r,(a,s)=>e(u=>{const g=De(br),_=t._3&&!a._3?L(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>{const m=py(An(s)+Bn(Mt(ce.foldr,d)));return(()=>{if(m.tag==="Just"){const p=m._1;return(x,w,J,N,k)=>k(x,p)}if(m.tag==="Nothing")return(p,x,w,J,N)=>N(p,0);c()})()(_._3&&!l._3?L(l._1,l._2,!0):l,e,n,r,o)})))}))),km=t=>(e,n,r,o,i)=>{const a=e._3;return n(s=>Ee(t)(e,n,r,(u,g)=>o(L(u._1,u._2,a),g),(u,g)=>n(_=>{const f=Po((()=>{const d=xt(Pt(m=>m==="_"))("'_'"),h=xt(Pt(m=>m==="-"))("'-'");return(m,p,x,w,J)=>{const N=m._1,k=m._2;return p(C=>wg(L(N,k,!1),p,x,(R,P)=>{const I=R._3;return p(U=>{if(I)return w(R,P);const S=m._1,v=m._2;return p(D=>br(L(S,v,!1),p,x,(W,M)=>{const q=W._3;return p($=>{if(q)return w(W,M);const G=m._1,F=m._2;return p(Q=>d(L(G,F,!1),p,x,(O,z)=>{const X=O._3;return p(V=>X?w(O,z):h(m,p,x,w,J))},J))})},J))})},J))}})()),l=e._3&&!u._3?L(u._1,u._2,!0):u;return n(d=>f(l,n,r,(h,m)=>o(L(h._1,h._2,a),m),(h,m)=>n(p=>{const x=l._3&&!h._3?L(h._1,h._2,!0):h;return n(w=>vn(x,n,r,(J,N)=>o(L(J._1,J._2,a),N),(J,N)=>n(k=>i(x._3&&!J._3?L(J._1,J._2,!0):J,t))))})))})))},CR=(t,e,n,r,o)=>e(i=>km("stretch-nodes")(t,e,n,r,(a,s)=>e(u=>o(a,void 0)))),LR=(t,e,n,r,o)=>e(i=>e(a=>br(t,e,n,r,(s,u)=>e(g=>{const _=De(br),f=t._3&&!s._3?L(s._1,s._2,!0):s;return e(l=>_(f,e,n,r,(d,h)=>e(m=>{const p=f._3&&!d._3?L(d._1,d._2,!0):d,x=An(u)+Bn(Mt(ce.foldr,h));return e(w=>{const J=xt(Pt(k=>k==="."))("'.'"),N=t._3&&!p._3?L(p._1,p._2,!0):p;return e(k=>{const C=(I,U)=>e(S=>{const v=Og((()=>{if(U.tag==="Nothing")return x+"";if(U.tag==="Just")return x+U._1;c()})(),Na,Xt,y);return(()=>{if(v.tag==="Just"){const D=v._1;return(W,M,q,$,G)=>G(W,D)}if(v.tag==="Nothing")return(D,W,M,q,$)=>$(D,0);c()})()(N._3&&!I._3?L(I._1,I._2,!0):I,e,n,r,o)}),R=N._1,P=N._2;return e(I=>e(U=>{const S=(v,D)=>{const W=v._3;return e(M=>W?r(v,D):C(N,y))};return e(v=>J(L(R,P,!1),e,n,S,(D,W)=>e(M=>e(q=>e($=>br(D,e,n,S,(G,F)=>e(Q=>{const O=De(br),z=D._3&&!G._3?L(G._1,G._2,!0):G;return e(X=>O(z,e,n,S,(V,K)=>e(Z=>{const nt=z._3&&!V._3?L(V._1,V._2,!0):V,rt=An(F)+Bn(Mt(ce.foldr,K));return e(ft=>{const Nt=D._3&&!nt._3?L(nt._1,nt._2,!0):nt,lt=An(W)+rt;return e(mt=>C(Nt,T("Just",lt)))})})))})))))))}))})})})))})))),kR=(t,e,n,r,o)=>e(i=>br(t,e,n,r,(a,s)=>e(u=>{const g=De((()=>{const f=xt(Pt(l=>l==="."))("'.'");return(l,d,h,m,p)=>{const x=l._1,w=l._2;return d(J=>br(L(x,w,!1),d,h,(N,k)=>{const C=N._3;return d(R=>C?m(N,k):f(l,d,h,m,p))},p))}})()),_=t._3&&!a._3?L(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>o(_._3&&!l._3?L(l._1,l._2,!0):l,An(s)+Bn(Mt(ce.foldr,d))))))}))),Pn=t=>(e,n,r,o,i)=>{const a=e._3;return n(s=>Ee(t)(e,n,r,(u,g)=>o(L(u._1,u._2,a),g),(u,g)=>n(_=>{const f=Po((()=>{const d=xt(Pt(m=>m==="_"))("'_'"),h=xt(Pt(m=>m==="-"))("'-'");return(m,p,x,w,J)=>{const N=m._1,k=m._2;return p(C=>wg(L(N,k,!1),p,x,(R,P)=>{const I=R._3;return p(U=>{if(I)return w(R,P);const S=m._1,v=m._2;return p(D=>br(L(S,v,!1),p,x,(W,M)=>{const q=W._3;return p($=>{if(q)return w(W,M);const G=m._1,F=m._2;return p(Q=>d(L(G,F,!1),p,x,(O,z)=>{const X=O._3;return p(V=>X?w(O,z):h(m,p,x,w,J))},J))})},J))})},J))}})()),l=e._3&&!u._3?L(u._1,u._2,!0):u;return n(d=>f(l,n,r,(h,m)=>o(L(h._1,h._2,a),m),(h,m)=>n(p=>i(l._3&&!h._3?L(h._1,h._2,!0):h,void 0))))})))},SR=(t,e,n,r,o)=>e(i=>Pn("into")(t,e,n,r,(a,s)=>e(u=>{const g=xt(Go)("space after 'into'"),_=t._3&&!a._3?L(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>{const m=Rn(xt(We)("node identifier after 'into'")),p=_._3&&!l._3?L(l._1,l._2,!0):l;return e(x=>m(p,e,n,r,(w,J)=>e(N=>o(p._3&&!w._3?L(w._1,w._2,!0):w,{op:ar("Enter",{id:J._1}),operands:[J._2]}))))})))}))),ER=(t,e,n,r,o)=>e(i=>Hn(t,e,n,r,(a,s)=>e(u=>{const g=t._3&&!a._3?L(a._1,a._2,!0):a;return e(_=>Pn("min-font-size")(g,e,n,r,(f,l)=>e(d=>{const h=g._3&&!f._3?L(f._1,f._2,!0):f;return e(m=>ie(h,e,n,r,(p,x)=>e(w=>{const J=xt(LR)("number (min-font-size value)"),N=h._3&&!p._3?L(p._1,p._2,!0):p;return e(k=>J(N,e,n,r,(C,R)=>e(P=>(R>0?((I,U,S,v,D)=>U(W=>vn(I,U,S,v,(M,q)=>U($=>D(M,R))))):(I,U,S,v,D)=>v(I,ir("positive min-font-size value",s)))(N._3&&!C._3?L(C._1,C._2,!0):C,e,n,r,o))))})))})))}))),RR=(t,e,n,r,o)=>e(i=>Pn("out")(t,e,n,r,(a,s)=>e(u=>o(t._3&&!a._3?L(a._1,a._2,!0):a,{op:g4,operands:[]})))),PR=(t,e,n,r,o)=>e(i=>Pn("seed")(t,e,n,r,(a,s)=>e(u=>{const g=t._3&&!a._3?L(a._1,a._2,!0):a;return e(_=>ie(g,e,n,r,(f,l)=>e(d=>{const h=xt(vR)("integer (seed value)"),m=g._3&&!f._3?L(f._1,f._2,!0):f;return e(p=>h(m,e,n,r,(x,w)=>e(J=>{const N=m._3&&!x._3?L(x._1,x._2,!0):x;return e(k=>vn(N,e,n,r,(C,R)=>e(P=>o(N._3&&!C._3?L(C._1,C._2,!0):C,w))))})))})))}))),Sm=(t,e,n,r,o)=>{const i=t._3;return e(a=>Pn("diagram")(t,e,n,(s,u)=>r(L(s._1,s._2,i),u),(s,u)=>e(g=>{const _=xt(Go)("space after 'diagram'"),f=t._3&&!s._3?L(s._1,s._2,!0):s;return e(l=>_(f,e,n,(d,h)=>r(L(d._1,d._2,i),h),(d,h)=>e(m=>{const p=xt(Pn("sequence"))("diagram mode"),x=f._3&&!d._3?L(d._1,d._2,!0):d;return e(w=>p(x,e,n,(J,N)=>r(L(J._1,J._2,i),N),(J,N)=>e(k=>{const C=x._3&&!J._3?L(J._1,J._2,!0):J;return e(R=>Nm(C,e,n,(P,I)=>r(L(P._1,P._2,i),I),(P,I)=>e(U=>o(C._3&&!P._3?L(P._1,P._2,!0):P,u4))))})))})))})))},Em=(t,e,n,r,o)=>{const i=t._3;return e(a=>Pn("still")(t,e,n,(s,u)=>r(L(s._1,s._2,i),u),(s,u)=>e(g=>{const _=t._3&&!s._3?L(s._1,s._2,!0):s;return e(f=>Nm(_,e,n,(l,d)=>r(L(l._1,l._2,i),d),(l,d)=>e(h=>o(_._3&&!l._3?L(l._1,l._2,!0):l,s4))))})))},Rm=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>Em(L(i,a,!1),e,n,(u,g)=>{const _=u._3;return e(f=>_?r(u,g):Sm(t,e,n,r,o))},o))},GR=t=>(e,n,r,o,i)=>n(a=>Hn(e,n,r,o,(s,u)=>n(g=>{const _=e._3&&!s._3?L(s._1,s._2,!0):s;return n(f=>{const l=_._3;return Rm(_,n,r,(d,h)=>o(L(d._1,d._2,l),h),(d,h)=>n(m=>o(_._3&&!d._3?L(d._1,d._2,!0):d,ir((()=>{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.";c()})(),u))))})}))),BR=t=>(e,n,r,o,i)=>n(a=>Hn(e,n,r,o,(s,u)=>n(g=>{const _=e._3&&!s._3?L(s._1,s._2,!0):s;return n(f=>{const l=(m,p)=>n(x=>(()=>{if(p.tag==="Just"){const w=(()=>{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.";c()})();return(J,N,k,C,R)=>C(J,ir(w,u))}if(p.tag==="Nothing")return(w,J,N,k,C)=>C(w,void 0);c()})()(_._3&&!m._3?L(m._1,m._2,!0):m,n,r,o,i)),d=_._1,h=_._2;return n(m=>n(p=>Rm(L(d,h,!1),n,r,(x,w)=>{const J=x._3;return n(N=>J?o(x,w):l(_,y))},(x,w)=>n(J=>l(x,T("Just",w))))))})}))),AR=(t,e,n,r,o)=>e(i=>{const a=(g,_)=>e(f=>{const l=t._3&&!g._3?L(g._1,g._2,!0):g;return e(d=>vn(l,e,n,r,(h,m)=>e(p=>{const x=l._3&&!h._3?L(h._1,h._2,!0):h;return e(w=>BR(_)(x,e,n,r,(J,N)=>e(k=>o(x._3&&!J._3?L(J._1,J._2,!0):J,_))))})))}),s=t._1,u=t._2;return e(g=>Em(L(s,u,!1),e,n,(_,f)=>{const l=_._3;return e(d=>l?r(_,f):Sm(t,e,n,r,a))},a))}),IR=(t,e,n,r,o)=>e(i=>{const a=(g,_)=>e(f=>o(g,(()=>{if(_.tag==="Nothing")return a4;if(_.tag==="Just")return _._1;c()})())),s=t._1,u=t._2;return e(g=>e(_=>AR(L(s,u,!1),e,n,(f,l)=>{const d=f._3;return e(h=>d?r(f,l):a(t,y))},(f,l)=>e(d=>a(f,T("Just",l))))))}),zR=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>ie(t,e,n,(u,g)=>r(L(u._1,u._2,a),g),(u,g)=>e(_=>Pn("via")(t._3&&!u._3?L(u._1,u._2,!0):u,e,n,(f,l)=>r(L(f._1,f._2,a),l),(f,l)=>e(d=>{const h=t._3&&!f._3?L(f._1,f._2,!0):f;return e(m=>_g(h,e,n,r,(p,x)=>e(w=>{const J=h._3&&!p._3?L(p._1,p._2,!0):p;return e(N=>Go(J,e,n,r,(k,C)=>e(R=>{const P=xt(We)("source node identifier after 'via'"),I=J._3&&!k._3?L(k._1,k._2,!0):k;return e(U=>P(I,e,n,r,(S,v)=>e(D=>{const W=I._3&&!S._3?L(S._1,S._2,!0):S;return e(M=>ie(W,e,n,r,(q,$)=>e(G=>{const F=xt(We)("target node identifier after 'via'"),Q=W._3&&!q._3?L(q._1,q._2,!0):q;return e(O=>F(Q,e,n,r,(z,X)=>e(V=>o(Q._3&&!z._3?L(z._1,z._2,!0):z,{from:v,to:X}))))})))})))})))})))})))))}),FR=t=>e=>{const n=De(zR);return(r,o,i,a,s)=>o(u=>n(r,o,i,a,(g,_)=>o(f=>s(r._3&&!g._3?L(g._1,g._2,!0):g,{op:ar("DelNode",{id:t,via:Mt(ce.foldr,_)}),operands:[e]}))))},DR=(()=>{const t=xt(Pt(e=>e==="-"))("'-'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>{const _=xt(Go)("space after '-'"),f=e._3&&!s._3?L(s._1,s._2,!0):s;return n(l=>_(f,n,r,o,(d,h)=>n(m=>{const p=Rn(xt(We)("node identifier after '-'")),x=f._3&&!d._3?L(d._1,d._2,!0):d;return n(w=>p(x,n,r,o,(J,N)=>n(k=>{const C=N._1,R=N._2,P=x._3&&!J._3?L(J._1,J._2,!0):J;return n(I=>bm(P,n,r,o,(U,S)=>n(v=>(()=>{if(S.tag==="Just")return JR(C)(R)(S._1);if(S.tag==="Nothing")return FR(C)(R);c()})()(P._3&&!U._3?L(U._1,U._2,!0):U,n,r,o,i))))})))})))})))})(),vr=t=>e=>(n,r,o,i,a)=>r(s=>Hn(n,r,o,i,(u,g)=>r(_=>{const f=n._3&&!u._3?L(u._1,u._2,!0):u;return r(l=>Pn(t)(f,r,o,i,(d,h)=>r(m=>i(f._3&&!d._3?L(d._1,d._2,!0):d,ir(e,g)))))}))),MR=t=>t==="AnimatedSurface"?(e,n,r,o,i)=>n(a=>Hn(e,n,r,o,(s,u)=>n(g=>{const _=e._3&&!s._3?L(s._1,s._2,!0):s;return n(f=>Pn("step")(_,n,r,o,(l,d)=>n(h=>{const m=xt(Go)("space after 'step'"),p=_._3&&!l._3?L(l._1,l._2,!0):l;return n(x=>m(p,n,r,o,(w,J)=>n(N=>{const k=Rn(xt(We)("step name")),C=p._3&&!w._3?L(w._1,w._2,!0):w;return n(R=>k(C,n,r,o,(P,I)=>n(U=>{const S=I._1,v=I._2,D=C._3&&!P._3?L(P._1,P._2,!0):P;return n(W=>Hn(D,n,r,o,(M,q)=>n($=>{const G=D._3&&!M._3?L(M._1,M._2,!0):M;return n(F=>ie(G,n,r,o,(Q,O)=>n(z=>{const X=G._3&&!Q._3?L(Q._1,Q._2,!0):Q;return n(V=>wm(X,n,r,o,(K,Z)=>n(nt=>{const rt=X._3&&!K._3?L(K._1,K._2,!0):K;return n(ft=>vn(rt,n,r,o,(Nt,lt)=>n(mt=>{const vt={line:u.line,column:u.column,endLine:q.line,endColumn:q.column};return i(rt._3&&!Nt._3?L(Nt._1,Nt._2,!0):Nt,{name:T("Just",S),ops:Wr("Leaf",{op:ar("Step",{name:S}),line:vt.line,column:vt.column,endLine:vt.endLine,endColumn:vt.endColumn,span:vt,operands:[v]}),kind:om})})))})))})))})))})))})))})))}))):vr("step")("`step` markers are only supported in animated diagrams."),QR=(()=>{const t=xt(Pt(e=>e===":"))("':'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>{const _=e._3&&!s._3?L(s._1,s._2,!0):s;return n(f=>ie(_,n,r,o,(l,d)=>n(h=>{const m=De(Pt(oR)),p=_._3&&!l._3?L(l._1,l._2,!0):l;return n(x=>m(p,n,r,o,(w,J)=>n(N=>i(p._3&&!w._3?L(w._1,w._2,!0):w,Ga(Bn(Mt(ce.foldr,J)))))))})))})))})(),Pm=xt((t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>QR(L(i,a,!1),e,n,(u,g)=>{const _=u._3;return e(f=>{if(_)return r(u,g);const l=t._1,d=t._2;return e(h=>yR(L(l,d,!1),e,n,(m,p)=>{const x=m._3;return e(w=>{if(x)return r(m,p);const J=t._1,N=t._2;return e(k=>xR(L(J,N,!1),e,n,(C,R)=>{const P=C._3;return e(I=>P?r(C,R):Cm(t,e,n,r,o))},o))})},o))})},o))})('label ("\u2026", : rest-of-line, or |\u2026|)'),Gm=(t,e,n,r,o)=>e(i=>ie(t,e,n,r,(a,s)=>e(u=>Pm(t._3&&!a._3?L(a._1,a._2,!0):a,e,n,r,o)))),Jg=t=>(e,n,r,o,i)=>n(a=>ie(e,n,r,o,(s,u)=>n(g=>{const _=e._3&&!s._3?L(s._1,s._2,!0):s;return n(f=>{const l=(m,p)=>n(x=>(p?((w,J,N,k,C)=>C(w,y)):(w,J,N,k,C)=>J(R=>Gm(w,J,N,k,(P,I)=>J(U=>C(P,T("Just",I))))))(_._3&&!m._3?L(m._1,m._2,!0):m,n,r,o,i)),d=_._1,h=_._2;return n(m=>{const p=(x,w)=>{const J=x._3;return n(N=>J?o(x,w):l(_,!1))};return n(x=>n(w=>n(J=>xa(L(d,h,!1),n,r,(N,k)=>{const C=N._3;return n(R=>C?p(L(d,h,!1),k):n(P=>Pt(t)(L(d,h,!1),n,r,(I,U)=>p(L(d,h,!1),U),(I,U)=>n(S=>n(v=>l(L(d,h,!1),!0))))))},(N,k)=>n(C=>n(R=>l(L(d,h,!1),!0)))))))})})}))),HR=t=>e=>n=>(r,o,i,a,s)=>o(u=>ie(r,o,i,a,(g,_)=>o(f=>{const l=Rn(xt(We)("target node identifier")),d=r._3&&!g._3?L(g._1,g._2,!0):g;return o(h=>l(d,o,i,a,(m,p)=>o(x=>{const w=p._1,J=p._2,N=d._3&&!m._3?L(m._1,m._2,!0):m;return o(k=>Jg(G1)(N,o,i,a,(C,R)=>o(P=>s(N._3&&!C._3?L(C._1,C._2,!0):C,{op:ar("AddEdge",{from:t,to:w,label:R.tag==="Just"?T("Just",R._1):y,directed:n}),operands:[e,J]}))))})))}))),OR=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>Rn(We)(t,e,n,(u,g)=>r(L(u._1,u._2,a),g),(u,g)=>e(_=>{const f=t._3&&!u._3?L(u._1,u._2,!0):u;return e(l=>ie(f,e,n,(d,h)=>r(L(d._1,d._2,a),h),(d,h)=>e(m=>{const p=xt(Pt(w=>w==="<"))("'<'"),x=f._3&&!d._3?L(d._1,d._2,!0):d;return e(w=>p(x,e,n,(J,N)=>r(L(x._1,x._2,a),N),(J,N)=>e(k=>{const C=Po((P,I,U,S,v)=>{const D=P._3;return Ee("<-")(P,I,U,(W,M)=>S(L(W._1,W._2,D),M),v)}),R=x._3&&!x._3?L(x._1,x._2,!0):x;return e(P=>C(R,e,n,(I,U)=>r(L(I._1,I._2,a),U),(I,U)=>e(S=>{const v=R._3&&!I._3?L(I._1,I._2,!0):I;return e(D=>{const W=g._1,M=g._2,q=t._3&&!v._3?L(v._1,v._2,!0):v;return e($=>ie(q,e,n,r,(G,F)=>e(Q=>{const O=xt(Ee("<~"))("'<~'"),z=q._3&&!G._3?L(G._1,G._2,!0):G;return e(X=>O(z,e,n,r,(V,K)=>e(Z=>{const nt=z._3&&!V._3?L(V._1,V._2,!0):V;return e(rt=>ie(nt,e,n,r,(ft,Nt)=>e(lt=>{const mt=Rn(xt(We)("target node identifier")),vt=nt._3&&!ft._3?L(ft._1,ft._2,!0):ft;return e(Wt=>mt(vt,e,n,r,(Tt,Vt)=>e(Gt=>{const bt=Vt._1,pt=Vt._2,ct=vt._3&&!Tt._3?L(Tt._1,Tt._2,!0):Tt;return e(Jt=>Jg(G1)(ct,e,n,r,(At,yt)=>e(Ct=>o(ct._3&&!At._3?L(At._1,At._2,!0):At,{op:ar("Token",{from:bt,to:W,labels:(()=>{if(yt.tag==="Nothing")return[];if(yt.tag==="Just")return[yt._1];c()})()}),operands:[pt,M]}))))})))})))})))})))})})))})))})))})))}),WR=(t,e,n,r,o)=>e(i=>NR(t,e,n,r,(a,s)=>e(u=>{const g=s._2._2,_=s._1,f=s._2._1,l=t._3&&!a._3?L(a._1,a._2,!0):a;return e(d=>ie(l,e,n,r,(h,m)=>e(p=>{const x=Rn(xt(We)("target node identifier")),w=l._3&&!h._3?L(h._1,h._2,!0):h;return e(J=>x(w,e,n,r,(N,k)=>e(C=>{const R=k._1,P=k._2,I=w._3&&!N._3?L(N._1,N._2,!0):N;return e(U=>Jg(G1)(I,e,n,r,(S,v)=>e(D=>(g==="<~"?((W,M,q,$,G)=>G(W,{op:ar("Token",{from:R,to:_,labels:(()=>{if(v.tag==="Nothing")return[];if(v.tag==="Just")return[v._1];c()})()}),operands:g==="<~"?[P,f]:[f,P]})):(W,M,q,$,G)=>G(W,{op:ar("Token",{from:_,to:R,labels:(()=>{if(v.tag==="Nothing")return[];if(v.tag==="Just")return[v._1];c()})()}),operands:g==="<~"?[P,f]:[f,P]}))(I._3&&!S._3?L(S._1,S._2,!0):S,e,n,r,o))))})))})))}))),$R=(t,e,n,r,o)=>e(i=>Jg(sR)(t,e,n,r,(a,s)=>e(u=>o(a,(()=>{if(s.tag==="Nothing")return"";if(s.tag==="Just")return s._1;c()})())))),qR=t=>e=>n=>r=>(o,i,a,s,u)=>i(g=>Hn(o,i,a,s,(_,f)=>i(l=>{const d=o._3&&!_._3?L(_._1,_._2,!0):_;return i(h=>{const m=(w,J)=>i(N=>(()=>{if(J.tag==="Just")return(k,C,R,P,I)=>P(k,ir("node placeholder value",f));if(J.tag==="Nothing")return(k,C,R,P,I)=>C(U=>Gm(k,C,R,P,(S,v)=>C(D=>I(k._3&&!S._3?L(S._1,S._2,!0):S,{op:ar("ModNodeSlot",{id:t,slot:n,value:v}),operands:[e,r]}))));c()})()(d._3&&!w._3?L(w._1,w._2,!0):w,i,a,s,u)),p=d._1,x=d._2;return i(w=>i(J=>ps(L(p,x,!1),i,a,(N,k)=>i(C=>m(d,y)),(N,k)=>i(C=>m(L(p,x,!1),T("Just",k))))))})}))),VR=t=>e=>(n,r,o,i,a)=>r(s=>Hn(n,r,o,i,(u,g)=>r(_=>{const f=n._3&&!u._3?L(u._1,u._2,!0):u;return r(l=>{const d=(p,x)=>r(w=>(()=>{if(x.tag==="Just")return(J,N,k,C,R)=>C(J,ir("node relabel label",g));if(x.tag==="Nothing")return(J,N,k,C,R)=>N(P=>Pm(J,N,k,C,(I,U)=>N(S=>R(J._3&&!I._3?L(I._1,I._2,!0):I,{op:ar("ModNode",{id:t,label:T("Just",U)}),operands:[e]}))));c()})()(f._3&&!p._3?L(p._1,p._2,!0):p,r,o,i,a)),h=f._1,m=f._2;return r(p=>r(x=>ps(L(h,m,!1),r,o,(w,J)=>r(N=>d(f,y)),(w,J)=>r(N=>d(L(h,m,!1),T("Just",J))))))})}))),UR=(()=>{const t=xt(Pt(e=>e==="~"))("'~'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>{const _=xt(Go)("space after '~'"),f=e._3&&!s._3?L(s._1,s._2,!0):s;return n(l=>_(f,n,r,o,(d,h)=>n(m=>{const p=Rn(xt(We)("source node identifier")),x=f._3&&!d._3?L(d._1,d._2,!0):d;return n(w=>p(x,n,r,o,(J,N)=>n(k=>{const C=N._1,R=N._2,P=xt(Pt(S=>S==="."))("'.'"),I=Rn(xt(We)("placeholder name")),U=x._3&&!J._3?L(J._1,J._2,!0):J;return n(S=>{const v=(M,q)=>n($=>(()=>{if(q.tag==="Just")return qR(C)(R)(q._1._1)(q._1._2);if(q.tag==="Nothing")return(G,F,Q,O,z)=>F(X=>ie(G,F,Q,O,(V,K)=>F(Z=>{const nt=xt(Pt(ft=>ft==="-"))("'-'"),rt=G._3&&!V._3?L(V._1,V._2,!0):V;return F(ft=>{const Nt=(vt,Wt)=>F(Tt=>(()=>{if(Wt.tag==="Just")return bR(C)(R);if(Wt.tag==="Nothing")return VR(C)(R);c()})()(rt._3&&!vt._3?L(vt._1,vt._2,!0):vt,F,Q,O,z)),lt=rt._1,mt=rt._2;return F(vt=>F(Wt=>nt(L(lt,mt,!1),F,Q,(Tt,Vt)=>F(Gt=>Nt(rt,y)),(Tt,Vt)=>F(Gt=>Nt(L(lt,mt,!1),T("Just",Vt))))))})})));c()})()(U._3&&!M._3?L(M._1,M._2,!0):M,n,r,o,i)),D=U._1,W=U._2;return n(M=>n(q=>{const $=(G,F)=>{const Q=G._3;return n(O=>Q?o(G,F):v(U,y))};return n(G=>n(F=>P(L(D,W,!1),n,r,(Q,O)=>$(L(Q._1,Q._2,!1),O),(Q,O)=>n(z=>n(X=>I(Q,n,r,(V,K)=>$(L(V._1,V._2,!1),K),(V,K)=>n(Z=>{const nt=Q._3&&!V._3?L(V._1,V._2,!0):V;return n(rt=>v(nt,T("Just",K)))})))))))}))})})))})))})))})(),B1=V0((()=>{const t=xt(Pt(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(a=>n(s=>t(e,n,r,o,(u,g)=>n(_=>n(f=>{const l=e._3&&!u._3?L(u._1,u._2,!0):u;return vn(l,n,r,o,(d,h)=>n(m=>i(l._3&&!d._3?L(d._1,d._2,!0):d,h)))})))))})())(xt((()=>{const t=xt(Pt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>n(s=>vn(e,n,r,o,(u,g)=>n(_=>n(f=>{const l=e._3&&!u._3?L(u._1,u._2,!0):u;return t(l,n,r,o,(d,h)=>n(m=>i(l._3&&!d._3?L(d._1,d._2,!0):d,h)))})))))})())("closing '}'")),KR=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>Cm(L(i,a,!1),e,n,(u,g)=>{const _=u._3;return e(f=>{if(_)return r(u,g);const l=t._1,d=t._2;return e(h=>kR(L(l,d,!1),e,n,(m,p)=>{const x=m._3;return e(w=>x?r(m,p):We(t,e,n,r,o))},o))})},o))},Bm=(t,e,n,r,o)=>e(i=>ie(t,e,n,r,(a,s)=>e(u=>{const g=xt(We)("attribute key"),_=t._3&&!a._3?L(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>{const m=_._3&&!l._3?L(l._1,l._2,!0):l;return e(p=>ie(m,e,n,r,(x,w)=>e(J=>{const N=xt(xt(Pt(C=>C===":"))("':'"))("':'"),k=m._3&&!x._3?L(x._1,x._2,!0):x;return e(C=>N(k,e,n,r,(R,P)=>e(I=>{const U=k._3&&!R._3?L(R._1,R._2,!0):R;return e(S=>ie(U,e,n,r,(v,D)=>e(W=>{const M=xt(KR)("attribute value"),q=U._3&&!v._3?L(v._1,v._2,!0):v;return e($=>M(q,e,n,r,(G,F)=>e(Q=>{const O=q._3&&!G._3?L(G._1,G._2,!0):G;return e(z=>ie(O,e,n,r,(X,V)=>e(K=>o(O._3&&!X._3?L(X._1,X._2,!0):X,E(d,F)))))})))})))})))})))})))}))),YR=V0((()=>{const t=xt(Pt(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(a=>n(s=>t(e,n,r,o,(u,g)=>n(_=>n(f=>{const l=e._3&&!u._3?L(u._1,u._2,!0):u;return ie(l,n,r,o,(d,h)=>n(m=>i(l._3&&!d._3?L(d._1,d._2,!0):d,h)))})))))})())(xt((()=>{const t=xt(Pt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>n(s=>ie(e,n,r,o,(u,g)=>n(_=>n(f=>{const l=e._3&&!u._3?L(u._1,u._2,!0):u;return t(l,n,r,o,(d,h)=>n(m=>i(l._3&&!d._3?L(d._1,d._2,!0):d,h)))})))))})())("closing '}' for attributes"))((()=>{const t=xt(Pt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>{const s=(_,f)=>n(l=>(()=>{if(f.tag==="Just")return(d,h,m,p,x)=>x(d,H);if(f.tag==="Nothing")return(d,h,m,p,x)=>h(w=>Bm(d,h,m,p,(J,N)=>h(k=>{const C=De((()=>{const P=xt(Pt(I=>I===","))("','");return(I,U,S,v,D)=>{const W=I._3;return U(M=>U(q=>U($=>U(G=>U(F=>U(Q=>ie(I,U,S,(O,z)=>v(L(O._1,O._2,W),z),(O,z)=>U(X=>U(V=>{const K=I._3&&!O._3?L(O._1,O._2,!0):O;return P(K,U,S,(Z,nt)=>v(L(Z._1,Z._2,W),nt),(Z,nt)=>U(rt=>{const ft=K._3&&!Z._3?L(Z._1,Z._2,!0):Z;return U(Nt=>U(lt=>{const mt=I._3&&!ft._3?L(ft._1,ft._2,!0):ft;return ie(mt,U,S,(vt,Wt)=>v(L(vt._1,vt._2,W),Wt),(vt,Wt)=>U(Tt=>{const Vt=mt._3&&!vt._3?L(vt._1,vt._2,!0):vt;return U(Gt=>U(bt=>{const pt=I._3&&!Vt._3?L(Vt._1,Vt._2,!0):Vt;return Bm(pt,U,S,(ct,Jt)=>v(L(ct._1,ct._2,W),Jt),(ct,Jt)=>U(At=>D(pt._3&&!ct._3?L(ct._1,ct._2,!0):ct,Jt)))}))}))}))}))})))))))))}})()),R=d._3&&!J._3?L(J._1,J._2,!0):J;return h(P=>C(R,h,m,p,(I,U)=>h(S=>x(R._3&&!I._3?L(I._1,I._2,!0):I,eR([N,...Mt(ce.foldr,U)])))))})));c()})()(e._3&&!_._3?L(_._1,_._2,!0):_,n,r,o,i)),u=e._1,g=e._2;return n(_=>n(f=>t(L(u,g,!1),n,r,(l,d)=>n(h=>s(e,y)),(l,d)=>n(h=>s(L(u,g,!1),T("Just",d))))))})})()),XR=(t,e,n,r,o)=>e(i=>ie(t,e,n,r,(a,s)=>e(u=>{const g=xt(Pt(f=>f==="{"))("'{'"),_=t._3&&!a._3?L(a._1,a._2,!0):a;return e(f=>{const l=(m,p)=>e(x=>(()=>{if(p.tag==="Just")return YR;if(p.tag==="Nothing")return(w,J,N,k,C)=>C(w,H);c()})()(_._3&&!m._3?L(m._1,m._2,!0):m,e,n,r,o)),d=_._1,h=_._2;return e(m=>e(p=>g(L(d,h,!1),e,n,(x,w)=>e(J=>l(_,y)),(x,w)=>e(J=>l(L(d,h,!1),T("Just",w))))))})}))),ZR=t=>e=>(n,r,o,i,a)=>r(s=>$R(n,r,o,i,(u,g)=>r(_=>{const f=n._3&&!u._3?L(u._1,u._2,!0):u;return r(l=>XR(f,r,o,i,(d,h)=>r(m=>a(f._3&&!d._3?L(d._1,d._2,!0):d,{op:ar("AddNode",{id:t,label:g,shape:(()=>{const p=ym("shape")(h);if(p.tag==="Just")return p._1==="rectangle"||p._1==="rect"?lo:p._1==="cylinder"||p._1==="cyl"?hx:p._1==="parallelogram"?px:p._1==="diamond"?mx:p._1==="ellipse"?yx:p._1==="document"||p._1==="doc"?xx:p._1==="cloud"?wx:lo;if(p.tag==="Nothing")return lo;c()})(),width:(()=>{const p=ym("width")(h);if(p.tag==="Just")return Og(p._1,Na,Xt,y);if(p.tag==="Nothing")return y;c()})()}),operands:[e]}))))}))),jR=(()=>{const t=xt(Pt(e=>e==="+"))("'+'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>{const _=xt(Go)("space after '+'"),f=e._3&&!s._3?L(s._1,s._2,!0):s;return n(l=>_(f,n,r,o,(d,h)=>n(m=>{const p=Rn(xt(We)("node identifier after '+'")),x=f._3&&!d._3?L(d._1,d._2,!0):d;return n(w=>p(x,n,r,o,(J,N)=>n(k=>{const C=N._1,R=N._2,P=x._3&&!J._3?L(J._1,J._2,!0):J;return n(I=>bm(P,n,r,o,(U,S)=>n(v=>(()=>{if(S.tag==="Just")return HR(C)(R)(S._1);if(S.tag==="Nothing")return ZR(C)(R);c()})()(P._3&&!U._3?L(U._1,U._2,!0):U,n,r,o,i))))})))})))})))})(),t6=(t,e,n,r,o)=>e(i=>Hn(t,e,n,r,(a,s)=>e(u=>{const g=xt(P1([vr("+node")("Node additions use `+ api: API`."),vr("+edge")("Graph edges use `+ api -> db`."),vr("+conn")("Undirected graph edges use `+ api -- db`."),vr("-node")("Node removals use `- api`."),vr("-edge")("Graph edge removals use `- api -> db`."),vr("-conn")("Undirected graph edge removals use `- api -- db`."),vr("~edge")("Graph edge repoints use `~ api -> db => api -> cache`."),vr("enter")("Dive commands use `into api`."),vr("exit")("Return from a dive with `out`."),TR,jR,DR,UR,WR,OR,SR,RR]))("statement (+ node, - node, + edge, - edge, ~ node, into, out, or 'a ~> b'/'a <~ b')"),_=t._3&&!a._3?L(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>{const m=_._3&&!l._3?L(l._1,l._2,!0):l;return e(p=>Hn(m,e,n,r,(x,w)=>e(J=>{const N={line:s.line,column:s.column,endLine:w.line,endColumn:w.column};return o(m._3&&!x._3?L(x._1,x._2,!0):x,Wr("Leaf",{op:d.op,line:N.line,column:N.column,endLine:N.endLine,endColumn:N.endColumn,span:N,operands:d.operands}))})))})))}))),Am=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>vn(t,e,n,(u,g)=>r(L(u._1,u._2,a),g),(u,g)=>e(_=>{const f=Po(xt(Pt(d=>d==="}"))("'}'")),l=t._3&&!u._3?L(u._1,u._2,!0):u;return e(d=>f(l,e,n,(h,m)=>r(L(h._1,h._2,a),m),(h,m)=>e(p=>Po(xa)(l._3&&!h._3?L(h._1,h._2,!0):h,e,n,(x,w)=>r(L(x._1,x._2,a),w),(x,w)=>e(J=>{const N=t._3&&!x._3?L(x._1,x._2,!0):x;return e(k=>_g(N,e,n,r,(C,R)=>e(P=>{const I=P1([n6,e6,t6]),U=N._3&&!C._3?L(C._1,C._2,!0):C;return e(S=>I(U,e,n,r,(v,D)=>e(W=>{const M=U._3&&!v._3?L(v._1,v._2,!0):v;return e(q=>ie(M,e,n,r,($,G)=>e(F=>{const Q=M._3&&!$._3?L($._1,$._2,!0):$;return e(O=>wm(Q,e,n,r,(z,X)=>e(V=>{const K=Q._3&&!z._3?L(z._1,z._2,!0):z;return e(Z=>vn(K,e,n,r,(nt,rt)=>e(ft=>o(K._3&&!nt._3?L(nt._1,nt._2,!0):nt,D))))})))})))})))})))})))))})))}),e6=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>{const u=(g,_)=>{const f=g._3;return e(l=>f?r(g,_):e(d=>{const h=t._3;return e(m=>Pn("seq")(t,e,n,(p,x)=>r(L(p._1,p._2,h),x),(p,x)=>e(w=>{const J=t._3&&!p._3?L(p._1,p._2,!0):p;return e(N=>ie(J,e,n,(k,C)=>r(L(k._1,k._2,h),C),(k,C)=>e(R=>ps(J._3&&!k._3?L(k._1,k._2,!0):k,e,n,(P,I)=>r(L(P._1,P._2,h),I),(P,I)=>e(U=>{const S=t._3&&!P._3?L(P._1,P._2,!0):P;return e(v=>_g(S,e,n,r,(D,W)=>e(M=>{const q=xt(xt(Pt(G=>G==="{"))("'{'"))("'{'"),$=S._3&&!D._3?L(D._1,D._2,!0):D;return e(G=>q($,e,n,r,(F,Q)=>e(O=>o($._3&&!F._3?L(F._1,F._2,!0):F,Wr("GroupSeq",[])))))})))})))))})))}))};return e(g=>e(_=>Pn("seq")(L(i,a,!1),e,n,(f,l)=>u(L(f._1,f._2,!1),l),(f,l)=>e(d=>e(h=>ie(f,e,n,(m,p)=>u(L(m._1,m._2,!1),p),(m,p)=>e(x=>{const w=f._3&&!m._3?L(m._1,m._2,!0):m;return xt(Pt(J=>J==="{"))("'{'")(w,e,n,(J,N)=>u(L(w._1,w._2,!1),N),(J,N)=>e(k=>B1(A1(l4))(w,e,n,u,o)))})))))))})},n6=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>{const u=(g,_)=>{const f=g._3;return e(l=>f?r(g,_):e(d=>{const h=t._3;return e(m=>Pn("par")(t,e,n,(p,x)=>r(L(p._1,p._2,h),x),(p,x)=>e(w=>{const J=t._3&&!p._3?L(p._1,p._2,!0):p;return e(N=>ie(J,e,n,(k,C)=>r(L(k._1,k._2,h),C),(k,C)=>e(R=>ps(J._3&&!k._3?L(k._1,k._2,!0):k,e,n,(P,I)=>r(L(P._1,P._2,h),I),(P,I)=>e(U=>{const S=t._3&&!P._3?L(P._1,P._2,!0):P;return e(v=>_g(S,e,n,r,(D,W)=>e(M=>{const q=xt(xt(Pt(G=>G==="{"))("'{'"))("'{'"),$=S._3&&!D._3?L(D._1,D._2,!0):D;return e(G=>q($,e,n,r,(F,Q)=>e(O=>o($._3&&!F._3?L(F._1,F._2,!0):F,Wr("Par",[])))))})))})))))})))}))};return e(g=>e(_=>Pn("par")(L(i,a,!1),e,n,(f,l)=>u(L(f._1,f._2,!1),l),(f,l)=>e(d=>e(h=>ie(f,e,n,(m,p)=>u(L(m._1,m._2,!1),p),(m,p)=>e(x=>{const w=f._3&&!m._3?L(m._1,m._2,!0):m;return xt(Pt(J=>J==="{"))("'{'")(w,e,n,(J,N)=>u(L(w._1,w._2,!1),N),(J,N)=>e(k=>B1(A1(_4))(w,e,n,u,o)))})))))))})},A1=t=>{const e=De(Am);return(n,r,o,i,a)=>r(s=>e(n,r,o,i,(u,g)=>r(_=>a(n._3&&!u._3?L(u._1,u._2,!0):u,t(Mt(ce.foldr,g))))))},I1=t=>e=>(n,r,o,i,a)=>r(s=>km(t)(n,r,o,i,(u,g)=>r(_=>{const f=De(Pt(uR)),l=n._3&&!u._3?L(u._1,u._2,!0):u;return r(d=>f(l,r,o,i,(h,m)=>r(p=>{const x=xt(xt(Pt(J=>J==="{"))("'{'"))("'{'"),w=l._3&&!h._3?L(h._1,h._2,!0):h;return r(J=>x(w,r,o,i,(N,k)=>r(C=>{const R=w._3&&!N._3?L(N._1,N._2,!0):N;return r(P=>vn(R,r,o,i,(I,U)=>r(S=>{const v=A1(f4),D=R._3&&!I._3?L(I._1,I._2,!0):I;return r(W=>v(D,r,o,i,(M,q)=>r($=>{const G=D._3&&!M._3?L(M._1,M._2,!0):M;return r(F=>vn(G,r,o,i,(Q,O)=>r(z=>{const X=xt(xt(Pt(K=>K==="}"))("'}'"))("closing '}'"),V=G._3&&!Q._3?L(Q._1,Q._2,!0):Q;return r(K=>X(V,r,o,i,(Z,nt)=>r(rt=>{const ft=V._3&&!Z._3?L(Z._1,Z._2,!0):Z;return r(Nt=>vn(ft,r,o,i,(lt,mt)=>r(vt=>a(ft._3&&!lt._3?L(lt._1,lt._2,!0):lt,{name:dR(Bn(Mt(ce.foldr,m))),ops:q,kind:e}))))})))})))})))})))})))})))}))),r6=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>vr("keyframe")("Drop the `keyframe` wrapper; Markgraf animates statements in order.")(L(i,a,!1),e,n,(u,g)=>{const _=u._3;return e(f=>{if(_)return r(u,g);const l=t._1,d=t._2;return e(h=>I1("scene")(pg)(L(l,d,!1),e,n,(m,p)=>{const x=m._3;return e(w=>{if(x)return r(m,p);const J=t._1,N=t._2;return e(k=>I1("still")(k1)(L(J,N,!1),e,n,(C,R)=>{const P=C._3;return e(I=>P?r(C,R):I1("title")(c4)(t,e,n,r,o))},o))})},o))})},o))},o6=t=>e=>n=>{if(t==="AnimatedSurface")return{...e,frames:Et(e.frames)({name:y,ops:n,kind:pg})};if(t==="StillSurface")return{...e,statements:Et(e.statements)(n)};if(t==="SequenceSurface")return{...e,statements:Et(e.statements)(n)};c()},i6=t=>e=>n=>{if(n.tag==="TopFrame"){const r=vm(t)(e);return{...r,frames:Et(r.frames)((()=>{if(t==="AnimatedSurface")return n._1;if(t==="StillSurface")return{...n._1,kind:n._1.kind==="AnimatedKeyframe"?k1:n._1.kind==="StepMarker"?om:n._1.kind};if(t==="SequenceSurface")return n._1;c()})())}}if(n.tag==="TopStatement")return o6(t)(e)(n._1);if(n.tag==="TopInside")return e;c()},a6=t=>{const e=b(i6(t))(mR);return n=>vm(t)(e(n)).frames},s6=t=>LE.defer(e=>{const n=MR(t);return(r,o,i,a,s)=>{const u=r._1,g=r._2;return o(_=>GR(t)(L(u,g,!1),o,i,(f,l)=>{const d=f._3;return o(h=>{if(d)return a(f,l);const m=r._1,p=r._2;return o(x=>o(w=>u6(L(m,p,!1),o,i,(J,N)=>{const k=J._3;return o(C=>{if(k)return a(J,N);const R=r._1,P=r._2;return o(I=>o(U=>n(L(R,P,!1),o,i,(S,v)=>{const D=S._3;return o(W=>{if(D)return a(S,v);const M=r._1,q=r._2;return o($=>o(G=>r6(L(M,q,!1),o,i,(F,Q)=>{const O=F._3;return o(z=>O?a(F,Q):o(X=>Am(r,o,i,a,(V,K)=>o(Z=>s(V,xg("TopStatement",K))))))},(F,Q)=>o(O=>s(F,xg("TopFrame",Q))))))})},(S,v)=>o(D=>s(S,xg("TopFrame",v))))))})},(J,N)=>o(k=>s(J,xg("TopInside",N))))))})},s))}}),u6=(t,e,n,r,o)=>e(i=>Pn("inside")(t,e,n,r,(a,s)=>e(u=>{const g=xt(Go)("space after 'inside'"),_=t._3&&!a._3?L(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>{const m=xt(We)("node identifier after 'inside'"),p=_._3&&!l._3?L(l._1,l._2,!0):l;return e(x=>m(p,e,n,r,(w,J)=>e(N=>{const k=p._3&&!w._3?L(w._1,w._2,!0):w;return e(C=>vn(k,e,n,r,(R,P)=>e(I=>{const U=k._3&&!R._3?L(R._1,R._2,!0):R;return e(S=>B1(Im)(U,e,n,r,(v,D)=>e(W=>{const M=U._3&&!v._3?L(v._1,v._2,!0):v;return e(q=>vn(M,e,n,r,($,G)=>e(F=>o(M._3&&!$._3?L($._1,$._2,!0):$,{node:J,doc:D}))))})))})))})))})))}))),Im=(t,e,n,r,o)=>e(i=>IR(t,e,n,r,(a,s)=>e(u=>{const g=t._3&&!a._3?L(a._1,a._2,!0):a;return e(_=>{const f=(h,m)=>e(p=>{const x=g._3&&!h._3?L(h._1,h._2,!0):h;return e(w=>{const J=(C,R)=>e(P=>{const I=x._3&&!C._3?L(C._1,C._2,!0):C;return e(U=>{const S=(v,D)=>e(W=>{const M=De(s6(s)),q=I._3&&!v._3?L(v._1,v._2,!0):v;return e($=>M(q,e,n,r,(G,F)=>e(Q=>{const O=Mt(ce.foldr,F);return o(q._3&&!G._3?L(G._1,G._2,!0):G,{seed:(()=>{if(m.tag==="Nothing")return 0;if(m.tag==="Just")return m._1;c()})(),minimumFontSize:R,stretchNodes:D,mode:s,frames:a6(s)(O),interiors:ht(z=>{if(z.tag==="TopInside")return T("Just",z._1);if(z.tag==="TopFrame"||z.tag==="TopStatement")return y;c()})(O)})})))});return e(v=>{const D=I._1,W=I._2;return e(M=>e(q=>CR(L(D,W,!1),e,n,($,G)=>{const F=$._3;return e(Q=>F?r($,G):e(O=>S(I,!1)))},($,G)=>e(F=>e(Q=>S($,!0))))))})})}),N=x._1,k=x._2;return e(C=>e(R=>ER(L(N,k,!1),e,n,(P,I)=>{const U=P._3;return e(S=>U?r(P,I):J(x,y))},(P,I)=>e(U=>J(P,T("Just",I))))))})}),l=g._1,d=g._2;return e(h=>e(m=>PR(L(l,d,!1),e,n,(p,x)=>{const w=p._3;return e(J=>w?r(p,x):f(g,y))},(p,x)=>e(w=>f(p,T("Just",x))))))})}))),g6=(()=>{const t=xt((e,n,r,o,i)=>n(a=>n(s=>vn(e,n,r,o,(u,g)=>n(_=>n(f=>{const l=e._3&&!u._3?L(u._1,u._2,!0):u;return xa(l,n,r,o,(d,h)=>n(m=>i(l._3&&!d._3?L(d._1,d._2,!0):d,h)))}))))))("'scene', 'still', 'title', 'step', 'inside', a statement, or end of input");return(e,n,r,o,i)=>n(a=>n(s=>n(u=>n(g=>vn(e,n,r,o,(_,f)=>n(l=>n(d=>{const h=e._3&&!_._3?L(_._1,_._2,!0):_;return Im(h,n,r,o,(m,p)=>n(x=>{const w=h._3&&!m._3?L(m._1,m._2,!0):m;return n(J=>n(N=>{const k=e._3&&!w._3?L(w._1,w._2,!0):w;return t(k,n,r,o,(C,R)=>n(P=>i(k._3&&!C._3?L(C._1,C._2,!0):C,p)))}))}))})))))))})(),c6=t=>{const e=W0(t)(g6);if(e.tag==="Left")return zt("Left",{msg:lR(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 zt("Right",e._1);c()},_6=t=>{const e=c6(t);if(e.tag==="Left")return zt("Left",e._1.msg);if(e.tag==="Right")return zt("Right",e._1);c()},f6=()=>({tag:"ParFrag"}),zm=t=>t,l6=zm("Sync"),d6=zm("SelfMsg"),h6=f6(),Bo=H0(qn),On=Ei(qn),Cr=Bo.state(t=>E(t,t)),Ao=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=B.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Fm=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Tg=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Io=Ri(qn),p6=t=>e=>b(n=>r=>Ei(qn).bind(n)(o=>t(o)(r)))(Ri(qn).pure(e)),Dm=Fo(Io)(Qt),Mm=t=>e=>Bo.state(n=>E(void 0,{...n,lifelines:af(B)(r=>T("Just",{...r,label:wa(e)}))(t)(n.lifelines),labelTemplates:it(B)(t)(e)(n.labelTemplates)})),ms=t=>Bo.state(e=>E(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:T("Just",t)};c()})())),m6=t=>e=>n=>On.bind(Cr)(r=>{const o=Ao(t)(r.labelTemplates);if(o.tag==="Nothing")return ms("node "+t+" label has no placeholder `"+e+"`");if(o.tag==="Just"){const i=X0(e)(n)(o._1);if(i.tag==="Left")return ms("node "+t+" "+i._1);if(i.tag==="Right")return Mm(t)(i._1)}c()}),y6=t=>e=>{const n=lg(e);if(n.tag==="Left")return ms("invalid label for node "+t+": "+n._1);if(n.tag==="Right")return Mm(t)(n._1);c()},x6=t=>e=>n=>{const r=Ao(n)(t.lifelines);return Ao(e)(t.lifelines).tag==="Nothing"?r.tag==="Nothing"?e+", "+n:e:r.tag==="Nothing"?n:""},w6={lifelines:H,labelTemplates:H,lifelineOrder:[],messages:[],fragments:[],frameEndRows:[],row:0,error:y},J6=t=>e=>n=>On.bind(Cr)(r=>{const o=Ao(t)(r.lifelines),i=Ao(e)(r.lifelines);if(o.tag==="Just"&&i.tag==="Just"){const a={...r,messages:[{fromCol:o._1.column,toCol:i._1.column,labels:n,row:r.row,kind:t===e?d6:l6},...r.messages],row:r.row+1|0};return Bo.state(s=>E(void 0,a))}return ms("token references unknown node: "+x6(r)(t)(e))}),T6=t=>Bo.state(e=>E(void 0,{...e,lifelines:af(B)(n=>T("Just",{...n,destroyedAt:T("Just",e.row)}))(t)(e.lifelines)})),N6=t=>e=>{const n=e.lifelineOrder.length,r=It(o=>y,o=>i=>T("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return{fromCol:0,toCol:Tg(0)(e.lifelineOrder.length-1|0)};if(r.tag==="Just")return b(o=>i=>({fromCol:Fm(o.fromCol)(Fm(i.fromCol)(i.toCol)),toCol:Tg(o.toCol)(Tg(i.fromCol)(i.toCol))}))({fromCol:n,toCol:0})(t);c()},b6=t=>({lifelines:ht(e=>Ao(e)(t.lifelines))(t.lifelineOrder),messages:re(t.messages),fragments:re(t.fragments),frameEndRows:t.frameEndRows,totalRows:t.row}),v6=t=>e=>On.bind(Cr)(n=>{const r=Ao(t)(n.lifelines);if(r.tag==="Just")return Io.pure();if(r.tag==="Nothing"){const o={...n,lifelines:it(B)(t)({id:t,label:wa(e),column:n.lifelineOrder.length,createdAt:n.row,destroyedAt:y})(n.lifelines),labelTemplates:it(B)(t)(e)(n.labelTemplates),lifelineOrder:Et(n.lifelineOrder)(t),row:n.row>0||n.messages.length!==0?n.row+1|0:n.row};return Bo.state(i=>E(void 0,o))}c()}),C6=t=>e=>On.bind(Cr)(n=>{const r=Ao(t)(n.lifelines);if(r.tag==="Just")return Io.pure();if(r.tag==="Nothing"){const o=lg(e);if(o.tag==="Left")return ms("invalid label for node "+t+": "+o._1);if(o.tag==="Right")return v6(t)(o._1)}c()}),L6=t=>{if(t.tag==="AddNode")return C6(t._1.id)(t._1.label);if(t.tag==="DelNode")return T6(t._1.id);if(t.tag==="ModNode"){if(t._1.label.tag==="Just")return y6(t._1.id)(t._1.label._1);if(t._1.label.tag==="Nothing")return Io.pure();c()}return t.tag==="ModNodeSlot"?m6(t._1.id)(t._1.slot)(t._1.value):t.tag==="Token"?J6(t._1.from)(t._1.to)(t._1.labels):Io.pure()},k6=t=>On.bind(Cr)(e=>{const n=e.row;return On.bind(p6(r=>o=>On.bind(Cr)(i=>{const a=r.childMessages.length===0?r.dividers:[i.row,...r.dividers],s=i.messages;return On.bind(z1(o))(()=>On.bind(Cr)(u=>Io.pure({dividers:a,childMessages:[...r.childMessages,...(()=>{const g=u.messages.length-s.length|0;return g<1?[]:Bt(0,g,u.messages)})()]})))}))({dividers:[],childMessages:[]})(t))(r=>On.bind(Cr)(o=>{const i=N6(r.childMessages)(o),a={kind:h6,label:"par",fromRow:n,toRow:Tg(o.row)(n+1|0),fromCol:i.fromCol,toCol:i.toCol,regionDividers:re(r.dividers)},s=Bo.state(u=>E(void 0,{...u,fragments:[a,...u.fragments]}));return r.childMessages.length>=2?s:Io.pure()}))}),z1=t=>{if(t.tag==="Leaf")return L6(t._1.op);if(t.tag==="Seq"||t.tag==="GroupSeq")return Dm(z1)(t._1);if(t.tag==="Par")return k6(t._1);c()},S6=t=>{const e=On.bind(Dm(n=>On.bind(Cr)(r=>On.bind(z1(n.ops))(()=>On.bind(Cr)(o=>{const i=Bo.state(a=>E(void 0,{...a,frameEndRows:Et(a.frameEndRows)(a.row-1|0)}));return(o.messages.length-r.messages.length|0)>0?i:Io.pure()}))))(t.frames))(()=>Cr)(w6)._1;if(e.error.tag==="Just")return zt("Left",e.error._1);if(e.error.tag==="Nothing")return zt("Right",b6(e));c()},E6=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},R6={padding:24,headerHeight:36,headerWidth:120,columnSpacing:160,rowHeight:36,topGap:24,bottomGap:24},P6=t=>{const e=84+ot(E6(1)(t.totalRows))*36,n=Dt(r=>o=>({lifeline:o,x:84+ot(r)*160}))(t.lifelines);return{metrics:R6,columns:n,width:(()=>{const r=n.length-1|0;return r>=0&&r<n.length?n[r].x+84:48})(),height:e+48,headerTop:24,headerBottom:60,bodyTop:84,bodyBottom:e,diagram:t}},G6=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Qm=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Hm=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}c()}return o},Om=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},B6=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},A6=b(t=>e=>it(ut)(e)()(t))(H),I6={r:255,g:255,b:255,a:255},Ng={r:26,g:26,b:26,a:255},z6={color:{r:232,g:232,b:232,a:255},flat:!0},F6={r:232,g:232,b:232,a:255},bg=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,...xo],Wm=t=>e=>n=>({...n,stack:Et(n.stack)(t),openedAt:it(ut)(t)(e)(n.openedAt)}),vg=t=>e=>{const n=e.stack.length-1|0;if(n>=0&&n<e.stack.length){const r=G6(e.stack[n])(e.openedAt),o=(()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return r._1;c()})();return{...e,stack:e.stack.length===0?[]:Bt(0,e.stack.length-1|0,e.stack),openedAt:Mi(ut)(e.stack[n])(e.openedAt),spans:Et(e.spans)({col:e.stack[n],fromRow:o,toRow:Qm(o)(t)})}}return e},$m=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,g=o,_=i,f=_.stack.length-1|0;if(f>=0&&f<_.stack.length){if(u(_.stack[f])){a=!1,s=_;continue}r=u,o=g,i=vg(g)(_);continue}a=!1,s=_}return s},qm=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=vg(a)(s);continue}o=!1,i=s}return i},D6=t=>e=>{const n=yn(uo)(e.fromCol)(t.stack)?$m((()=>{const r=e.fromCol;return o=>r===o})())(e.row-1|0)(t):Wm(e.fromCol)(e.row)(qm(e.row-1|0)(t));if(yn(uo)(e.toCol)(n.stack)){const r=$m((()=>{const o=e.toCol;return i=>o===i})())(e.row-1|0)(vg(e.row)(n));return{...r,returnRows:it(ut)(e.row)()(r.returnRows)}}return Wm(e.toCol)(e.row)(n)},M6=t=>e=>n=>{const r=D6(e)(n);return Hm(n.row)(t)?qm(n.row)(r):r},Cg={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:Ia,lineCap:Br},Vm={r:26,g:26,b:26,a:255},Q6={color:{r:130,g:130,b:130,a:255},width:1,lineJoin:Ia,lineCap:zn},Um={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:Ia,lineCap:zn},H6={color:{r:244,g:244,b:244,a:255},flat:!0},Km=t=>e=>n=>oe(r=>r.col===e&&r.fromRow<=n&&n<=r.toRow,t),Ym={color:{r:90,g:90,b:90,a:255},width:1,lineJoin:Ia,lineCap:zn},O6={stack:[],openedAt:H,spans:[],returnRows:H},W6={color:{r:150,g:150,b:150,a:255},width:1,lineJoin:Ia,lineCap:zn},$6=t=>e=>n=>r=>o=>{const i=e.bodyTop+(ot(o)+.5)*e.metrics.rowHeight-e.metrics.rowHeight/2;return t.strokePath([1,n,i,2,r,i])(W6)},q6=t=>{const e=t.Monad0(),n=e.Bind1(),r=Ii(e.Applicative0())(Qt);return o=>i=>{const a=o.bodyTop+(ot(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,...xo],g=i.toCol>=0&&i.toCol<o.columns.length?o.columns[i.toCol].x+16:o.metrics.padding+16,_=o.bodyTop+(ot(Qm(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,g,a,2,g,_,2,s,_,...xo])(Ym))(()=>n.bind(t.fillStrokePath(u)(z6)(Ym))(()=>n.bind(t.drawText({x:s+6,y:a+7,content:"par",font:{family:"Inter",size:11,weight:700},color:Ng,align:Gr,baseline:tr}))(()=>r(i.regionDividers)($6(t)(o)(s)(g)))))}},Xm=t=>e=>t>=e?[]:[E(t,Om(e)(t+6)),...Xm(t+10)(e)],V6=t=>e=>{if(e<=t)return[];const n=r=>r>=e?[]:[E(r,Om(e)(r+6)),...n(r+10)];return n(t)},U6=t=>{const e=Ii(t.Monad0().Applicative0())(Qt);return n=>r=>e(V6(n.headerTop+n.metrics.headerHeight+ot(r.lifeline.createdAt)*n.metrics.rowHeight+4)((()=>{if(r.lifeline.destroyedAt.tag==="Just")return n.bodyTop+(ot(r.lifeline.destroyedAt._1)+.5)*n.metrics.rowHeight;if(r.lifeline.destroyedAt.tag==="Nothing")return n.bodyBottom;c()})()))(o=>t.strokePath([1,r.x,o._1,2,r.x,o._2])(Q6))},Zm=t=>e=>t<=e?[]:[E(t,B6(e)(t-6)),...Zm(t-6-4)(e)],K6=t=>e=>t===e?[]:t<e?Xm(t)(e):Zm(t)(e),Y6=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.headerTop+ot(r.lifeline.createdAt)*n.metrics.rowHeight,i=n.metrics.headerWidth/2,a=o+n.metrics.headerHeight,s=bg(r.x-i)(o)(r.x+i)(a)(6);return e.bind(t.fillStrokePath(bg(r.x-i)(o+5)(r.x+i)(a+5)(6))({color:F6,flat:!0})(Um))(()=>e.bind(t.fillStrokePath(s)(H6)(Um))(()=>t.drawText({x:r.x,y:o+n.metrics.headerHeight/2,content:r.lifeline.label,font:{family:"Inter",size:14,weight:600},color:Ng,align:Aa,baseline:tr})))}},X6=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=vg(a)(s);continue}o=!1,i=s}return i},Z6=t=>X6((()=>{const e=t.diagram.messages.length-1|0;return e>=0&&e<t.diagram.messages.length?t.diagram.messages[e].row:0})())(b(M6(A6(t.diagram.frameEndRows)))(O6)(_t(e=>e.kind==="Sync"||e.kind!=="SelfMsg",t.diagram.messages))),j6=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.bodyTop+(ot(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,g=i+10,_=[1,i,u,2,g,u-5,2,g,u+5,...xo];return e.bind(t.strokePath([1,i,a,2,s,a,2,s,u,2,i,u])(Cg))(()=>e.bind(t.fillPath(_)({color:Vm,flat:!0}))(()=>t.drawText({x:i+42,y:o,content:dr(" ")(Y(Ja)(r.labels)),font:{family:"Inter",size:12,weight:400},color:Ng,align:Gr,baseline:tr})))}},tP=t=>{const e=t.Monad0(),n=e.Bind1(),r=Ii(e.Applicative0())(Qt);return o=>i=>a=>s=>{const u=a?o.bodyTop+(ot(s.row)+.5)*o.metrics.rowHeight+o.metrics.rowHeight*.5:o.bodyTop+(ot(s.row)+.5)*o.metrics.rowHeight,g=s.toCol>=s.fromCol?1:-1,_=(s.fromCol>=0&&s.fromCol<o.columns.length?o.columns[s.fromCol].x:o.metrics.padding)+(Km(i)(s.fromCol)(s.row)?g*6:g*0),f=(s.toCol>=0&&s.toCol<o.columns.length?o.columns[s.toCol].x:o.metrics.padding)-(Km(i)(s.toCol)(s.row)?g*6:g*0),l=f-g*10,d=a?t.strokePath([1,l,u-5,2,f,u,2,l,u+5])(Cg):t.fillPath([1,f,u,2,l,u-5,2,l,u+5,...xo])({color:Vm,flat:!0});return n.bind(a?r(K6(_)(f))(h=>t.strokePath([1,h._1,u,2,h._2,u])(Cg)):t.strokePath([1,_,u,2,f,u])(Cg))(()=>n.bind(d)(()=>t.drawText({x:(_+f)/2,y:u-6,content:dr(" ")(Y(Ja)(s.labels)),font:{family:"Inter",size:12,weight:400},color:Ng,align:Aa,baseline:nJ})))}},eP=t=>{const e=j6(t),n=tP(t);return r=>o=>i=>a=>{if(a.kind==="SelfMsg")return e(r)(a);if(a.kind==="Sync")return n(r)(o)(Hm(a.row)(i))(a);c()}},jm={color:{r:26,g:26,b:26,a:255},width:1.25,lineJoin:nn,lineCap:zn},nP={color:{r:232,g:232,b:232,a:255},flat:!0},rP={color:{r:252,g:252,b:252,a:255},flat:!0},oP=t=>e=>n=>{const r=n.col>=0&&n.col<e.columns.length?e.columns[n.col].x:e.metrics.padding,o=e.bodyTop+(ot(n.fromRow)+.5)*e.metrics.rowHeight,i=e.bodyTop+(ot(n.toRow)+.5)*e.metrics.rowHeight+e.metrics.rowHeight*.5,a=bg(r-6)(o)(r+6)(i)(3);return t.Monad0().Bind1().bind(t.fillStrokePath(bg(r-6)(o+5)(r+6)(i+5)(3))(nP)(jm))(()=>t.fillStrokePath(a)(rP)(jm))},t2=t=>{const e=t.Monad0(),n=e.Bind1(),r=Ii(e.Applicative0())(Qt),o=Y6(t),i=U6(t),a=q6(t),s=eP(t);return u=>{const g=Z6(u);return n.bind(t.setViewport({vx:0,vy:0,vw:u.width,vh:u.height}))(()=>n.bind(t.clearBackground(I6))(()=>n.bind(r(u.columns)(o(u)))(()=>n.bind(r(u.columns)(i(u)))(()=>n.bind(r(g.spans)(oP(t)(u)))(()=>n.bind(r(u.diagram.fragments)(a(u)))(()=>r(u.diagram.messages)(s(u)(g.spans)(g.returnRows))))))))}},iP=t2(xJ);function e2(t){return function(e){return function(){return t.add(e)}}}function F1(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 n2(t){return function(){return t.classList}}function Cn(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function aP(t){return function(e){return function(){return e.getAttribute(t)}}}const r2=t=>{const e=aP(t);return n=>{const r=e(n);return()=>{const o=r();return Gn(o,y,Xt)}}};function sP(t){return function(e){return function(){e.textContent=t}}}function uP(t){return function(){return function(e){return t(e)()}}}function gP(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const D1=function(){return window};function cP(t){return function(e){return function(){e.value=t}}}function _P(t){return function(){return t.valueAsNumber}}function fP(t){return function(){return t.value}}function M1(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const ys=t=>t,xs=t=>()=>{const e=t.getBoundingClientRect?.(),n=e?.width||t.clientWidth||0,r=e?.height||t.clientHeight||0;return{width:n,height:r}},o2=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)}},i2=()=>window.devicePixelRatio||1,a2=()=>performance.now()/1e3,lP=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=`
|
|
24
|
+
`)(K(uR)(K(Qi(lR(e)))(e)))},JR=(t,e,n,r,o)=>{const i=t._3;return e(a=>Ee("|md")(t,e,n,(s,u)=>r(k(s._1,s._2,i),u),(s,u)=>e(g=>{const _=xt((l,d,h,m,p)=>{const x=l._1,J=l._2;return d(w=>Ee(`\r
|
|
25
|
+
`)(k(x,J,!1),d,h,(N,L)=>{const C=N._3;return d(R=>{if(C)return m(N,L);const P=l._1,I=l._2;return d(U=>Ee(`
|
|
26
|
+
`)(k(P,I,!1),d,h,(S,v)=>{const F=S._3;return d(H=>F?m(S,v):Ee("\r")(l,d,h,m,p))},p))})},p))})("newline after '|md'"),f=t._3&&!s._3?k(s._1,s._2,!0):s;return e(l=>_(f,e,n,(d,h)=>r(k(d._1,d._2,i),h),(d,h)=>e(m=>{const p=Fe(wm),x=f._3&&!d._3?k(d._1,d._2,!0):d;return e(J=>p(x,e,n,(w,N)=>r(k(w._1,w._2,i),N),(w,N)=>e(L=>{const C=xt(xt(Pt(P=>P==="|"))("'|'"))("closing '|'"),R=x._3&&!w._3?k(w._1,w._2,!0):w;return e(P=>C(R,e,n,(I,U)=>r(k(I._1,I._2,i),U),(I,U)=>e(S=>o(R._3&&!I._3?k(I._1,I._2,!0):I,"md:"+Lm(dr("")(Mt(ce.foldr,N)))))))})))})))})))},wR=(()=>{const t=xt(Pt(e=>e==="|"))("'|'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>{const _=Fe(wm),f=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>_(f,n,r,o,(d,h)=>n(m=>{const p=xt(xt(Pt(J=>J==="|"))("'|'"))("closing '|'"),x=f._3&&!d._3?k(d._1,d._2,!0):d;return n(J=>p(x,n,r,o,(w,N)=>n(L=>i(x._3&&!w._3?k(w._1,w._2,!0):w,Lm(dr("")(Mt(ce.foldr,h)))))))})))})))})(),Cr=Pt(t=>t>="0"&&t<="9"),TR=(()=>{const t=xt(Pt(e=>e==="_"))("'_'");return(e,n,r,o,i)=>{const a=e._1,s=e._2;return n(u=>Jg(k(a,s,!1),n,r,(g,_)=>{const f=g._3;return n(l=>{if(f)return o(g,_);const d=e._1,h=e._2;return n(m=>Cr(k(d,h,!1),n,r,(p,x)=>{const J=p._3;return n(w=>{if(J)return o(p,x);const N=e._1,L=e._2;return n(C=>t(k(N,L,!1),n,r,(R,P)=>{const I=R._3;return n(U=>I?o(R,P):dR(e,n,r,o,i))},i))})},i))})},i))}})(),He=(()=>{const t=xt(Pt(e=>e==="_"))("'_'");return(e,n,r,o,i)=>n(a=>{const s=(_,f)=>n(l=>{const d=Fe(TR),h=e._3&&!_._3?k(_._1,_._2,!0):_;return n(m=>d(h,n,r,o,(p,x)=>n(J=>i(h._3&&!p._3?k(p._1,p._2,!0):p,In(f)+An(Mt(ce.foldr,x))))))}),u=e._1,g=e._2;return n(_=>Jg(k(u,g,!1),n,r,(f,l)=>{const d=f._3;return n(h=>d?o(f,l):t(e,n,r,o,s))},s))})})(),NR=t=>e=>n=>(r,o,i,a,s)=>o(u=>ie(r,o,i,a,(g,_)=>o(f=>{const l=Pn(xt(He)("target node identifier")),d=r._3&&!g._3?k(g._1,g._2,!0):g;return o(h=>l(d,o,i,a,(m,p)=>o(x=>s(d._3&&!m._3?k(m._1,m._2,!0):m,{op:ar("DelEdge",{from:t,to:p._1,directed:n}),operands:[e,p._2]}))))}))),bR=(t,e,n,r,o)=>e(i=>$n(t,e,n,r,(a,s)=>e(u=>{const g=t._3&&!a._3?k(a._1,a._2,!0):a;return e(_=>{const f=g._3;return e(l=>He(g,e,n,(d,h)=>r(k(d._1,d._2,f),h),(d,h)=>e(m=>{const p=g._3&&!d._3?k(d._1,d._2,!0):d;return e(x=>ie(p,e,n,(J,w)=>r(k(J._1,J._2,f),w),(J,w)=>e(N=>{const L=p._3&&!J._3?k(J._1,J._2,!0):J;return e(C=>{const R=(U,S)=>e(v=>{const F=L._3&&!U._3?k(U._1,U._2,!0):U;return e(H=>r(g._3&&!F._3?k(F._1,F._2,!0):F,ir("Use `~>` / `<~` for movement tokens.",s)))}),P=L._1,I=L._2;return e(U=>Ee("->")(k(P,I,!1),e,n,(S,v)=>{const F=S._3;return e(H=>F?r(k(S._1,S._2,f),v):Ee("<-")(L,e,n,(M,q)=>r(k(M._1,M._2,f),q),R))},R))})})))})))})}))),vR=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>Pn(He)(t,e,n,(u,g)=>r(k(u._1,u._2,a),g),(u,g)=>e(_=>{const f=t._3&&!u._3?k(u._1,u._2,!0):u;return e(l=>ie(f,e,n,(d,h)=>r(k(d._1,d._2,a),h),(d,h)=>e(m=>{const p=xt(Pt(J=>J==="~"))("'~'"),x=f._3&&!d._3?k(d._1,d._2,!0):d;return e(J=>{const w=(C,R)=>e(P=>{const I=x._3&&!C._3?k(C._1,C._2,!0):C;return e(U=>{const S=g._1,v=g._2,F=t._3&&!I._3?k(I._1,I._2,!0):I;return e(H=>ie(F,e,n,r,(M,q)=>e($=>{const B=xt(Pt(O=>O==="~"))("'~'"),D=xt(Pt(O=>O==="<"))("'<'"),Q=F._3&&!M._3?k(M._1,M._2,!0):M;return e(O=>{const z=(X,Z)=>e(nt=>{const rt=Z==="~"?xt(Ee("~>"))("'~>'"):xt(Ee("<~"))("'<~'"),ft=Q._3&&!X._3?k(X._1,X._2,!0):X;return e(Nt=>rt(ft,e,n,r,(lt,mt)=>e(vt=>o(ft._3&&!lt._3?k(lt._1,lt._2,!0):lt,E(S,E(v,mt))))))}),Y=Q._1,V=Q._2;return e(X=>B(k(Y,V,!1),e,n,(Z,nt)=>{const rt=Z._3;return e(ft=>rt?r(Q,nt):D(Q,e,n,(Nt,lt)=>r(Q,lt),(Nt,lt)=>z(Q,lt)))},(Z,nt)=>z(Q,nt)))})})))})}),N=x._1,L=x._2;return e(C=>p(k(N,L,!1),e,n,(R,P)=>{const I=R._3;return e(U=>I?r(k(x._1,x._2,a),P):e(S=>Ee("<~")(x,e,n,(v,F)=>r(k(x._1,x._2,a),F),(v,F)=>e(H=>w(x)))))},(R,P)=>w(x)))})})))})))}),CR=t=>e=>{const n=xt(Ee("->"))("source edge arrow '->'");return(r,o,i,a,s)=>o(u=>n(r,o,i,a,(g,_)=>o(f=>{const l=r._3&&!g._3?k(g._1,g._2,!0):g;return o(d=>ie(l,o,i,a,(h,m)=>o(p=>{const x=Pn(xt(He)("target node identifier")),J=l._3&&!h._3?k(h._1,h._2,!0):h;return o(w=>x(J,o,i,a,(N,L)=>o(C=>{const R=L._1,P=L._2,I=J._3&&!N._3?k(N._1,N._2,!0):N;return o(U=>ie(I,o,i,a,(S,v)=>o(F=>{const H=xt(Ee("=>"))("repoint separator '=>'"),M=I._3&&!S._3?k(S._1,S._2,!0):S;return o(q=>H(M,o,i,a,($,B)=>o(D=>{const Q=M._3&&!$._3?k($._1,$._2,!0):$;return o(O=>ie(Q,o,i,a,(z,Y)=>o(V=>{const X=Pn(xt(He)("new source node identifier")),Z=Q._3&&!z._3?k(z._1,z._2,!0):z;return o(nt=>X(Z,o,i,a,(rt,ft)=>o(Nt=>{const lt=ft._1,mt=ft._2,vt=Z._3&&!rt._3?k(rt._1,rt._2,!0):rt;return o(Ht=>ie(vt,o,i,a,(Tt,Vt)=>o(Gt=>{const bt=xt(Ee("->"))("replacement edge arrow '->'"),pt=vt._3&&!Tt._3?k(Tt._1,Tt._2,!0):Tt;return o(ct=>bt(pt,o,i,a,(wt,It)=>o(yt=>{const Ct=pt._3&&!wt._3?k(wt._1,wt._2,!0):wt;return o(Ot=>ie(Ct,o,i,a,(Dt,se)=>o(_e=>{const pn=Pn(xt(He)("new target node identifier")),qt=Ct._3&&!Dt._3?k(Dt._1,Dt._2,!0):Dt;return o(jt=>pn(qt,o,i,a,(sn,$e)=>o(Vn=>s(qt._3&&!sn._3?k(sn._1,sn._2,!0):sn,{op:ar("RepointEdge",{from:t,to:R,newFrom:lt,newTo:$e._1}),operands:[e,P,mt,$e._2]}))))})))})))})))})))})))})))})))})))})))})))},LR=(t,e,n,r,o)=>e(i=>Cr(t,e,n,r,(a,s)=>e(u=>{const g=Fe(Cr),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>{const m=py(In(s)+An(Mt(ce.foldr,d)));return(()=>{if(m.tag==="Just"){const p=m._1;return(x,J,w,N,L)=>L(x,p)}if(m.tag==="Nothing")return(p,x,J,w,N)=>N(p,0);c()})()(_._3&&!l._3?k(l._1,l._2,!0):l,e,n,r,o)})))}))),km=t=>(e,n,r,o,i)=>{const a=e._3;return n(s=>Ee(t)(e,n,r,(u,g)=>o(k(u._1,u._2,a),g),(u,g)=>n(_=>{const f=Go((()=>{const d=xt(Pt(m=>m==="_"))("'_'"),h=xt(Pt(m=>m==="-"))("'-'");return(m,p,x,J,w)=>{const N=m._1,L=m._2;return p(C=>Jg(k(N,L,!1),p,x,(R,P)=>{const I=R._3;return p(U=>{if(I)return J(R,P);const S=m._1,v=m._2;return p(F=>Cr(k(S,v,!1),p,x,(H,M)=>{const q=H._3;return p($=>{if(q)return J(H,M);const B=m._1,D=m._2;return p(Q=>d(k(B,D,!1),p,x,(O,z)=>{const Y=O._3;return p(V=>Y?J(O,z):h(m,p,x,J,w))},w))})},w))})},w))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(d=>f(l,n,r,(h,m)=>o(k(h._1,h._2,a),m),(h,m)=>n(p=>{const x=l._3&&!h._3?k(h._1,h._2,!0):h;return n(J=>vn(x,n,r,(w,N)=>o(k(w._1,w._2,a),N),(w,N)=>n(L=>i(x._3&&!w._3?k(w._1,w._2,!0):w,t))))})))})))},kR=(t,e,n,r,o)=>e(i=>km("stretch-nodes")(t,e,n,r,(a,s)=>e(u=>o(a,void 0)))),SR=(t,e,n,r,o)=>e(i=>e(a=>Cr(t,e,n,r,(s,u)=>e(g=>{const _=Fe(Cr),f=t._3&&!s._3?k(s._1,s._2,!0):s;return e(l=>_(f,e,n,r,(d,h)=>e(m=>{const p=f._3&&!d._3?k(d._1,d._2,!0):d,x=In(u)+An(Mt(ce.foldr,h));return e(J=>{const w=xt(Pt(L=>L==="."))("'.'"),N=t._3&&!p._3?k(p._1,p._2,!0):p;return e(L=>{const C=(I,U)=>e(S=>{const v=Og((()=>{if(U.tag==="Nothing")return x+"";if(U.tag==="Just")return x+U._1;c()})(),Na,Yt,y);return(()=>{if(v.tag==="Just"){const F=v._1;return(H,M,q,$,B)=>B(H,F)}if(v.tag==="Nothing")return(F,H,M,q,$)=>$(F,0);c()})()(N._3&&!I._3?k(I._1,I._2,!0):I,e,n,r,o)}),R=N._1,P=N._2;return e(I=>e(U=>{const S=(v,F)=>{const H=v._3;return e(M=>H?r(v,F):C(N,y))};return e(v=>w(k(R,P,!1),e,n,S,(F,H)=>e(M=>e(q=>e($=>Cr(F,e,n,S,(B,D)=>e(Q=>{const O=Fe(Cr),z=F._3&&!B._3?k(B._1,B._2,!0):B;return e(Y=>O(z,e,n,S,(V,X)=>e(Z=>{const nt=z._3&&!V._3?k(V._1,V._2,!0):V,rt=In(D)+An(Mt(ce.foldr,X));return e(ft=>{const Nt=F._3&&!nt._3?k(nt._1,nt._2,!0):nt,lt=In(H)+rt;return e(mt=>C(Nt,T("Just",lt)))})})))})))))))}))})})})))})))),ER=(t,e,n,r,o)=>e(i=>Cr(t,e,n,r,(a,s)=>e(u=>{const g=Fe((()=>{const f=xt(Pt(l=>l==="."))("'.'");return(l,d,h,m,p)=>{const x=l._1,J=l._2;return d(w=>Cr(k(x,J,!1),d,h,(N,L)=>{const C=N._3;return d(R=>C?m(N,L):f(l,d,h,m,p))},p))}})()),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>o(_._3&&!l._3?k(l._1,l._2,!0):l,In(s)+An(Mt(ce.foldr,d))))))}))),Bn=t=>(e,n,r,o,i)=>{const a=e._3;return n(s=>Ee(t)(e,n,r,(u,g)=>o(k(u._1,u._2,a),g),(u,g)=>n(_=>{const f=Go((()=>{const d=xt(Pt(m=>m==="_"))("'_'"),h=xt(Pt(m=>m==="-"))("'-'");return(m,p,x,J,w)=>{const N=m._1,L=m._2;return p(C=>Jg(k(N,L,!1),p,x,(R,P)=>{const I=R._3;return p(U=>{if(I)return J(R,P);const S=m._1,v=m._2;return p(F=>Cr(k(S,v,!1),p,x,(H,M)=>{const q=H._3;return p($=>{if(q)return J(H,M);const B=m._1,D=m._2;return p(Q=>d(k(B,D,!1),p,x,(O,z)=>{const Y=O._3;return p(V=>Y?J(O,z):h(m,p,x,J,w))},w))})},w))})},w))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(d=>f(l,n,r,(h,m)=>o(k(h._1,h._2,a),m),(h,m)=>n(p=>i(l._3&&!h._3?k(h._1,h._2,!0):h,void 0))))})))},RR=(t,e,n,r,o)=>e(i=>Bn("into")(t,e,n,r,(a,s)=>e(u=>{const g=xt(Ao)("space after 'into'"),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>{const m=Pn(xt(He)("node identifier after 'into'")),p=_._3&&!l._3?k(l._1,l._2,!0):l;return e(x=>m(p,e,n,r,(J,w)=>e(N=>o(p._3&&!J._3?k(J._1,J._2,!0):J,{op:ar("Enter",{id:w._1}),operands:[w._2]}))))})))}))),PR=(t,e,n,r,o)=>e(i=>$n(t,e,n,r,(a,s)=>e(u=>{const g=t._3&&!a._3?k(a._1,a._2,!0):a;return e(_=>Bn("min-font-size")(g,e,n,r,(f,l)=>e(d=>{const h=g._3&&!f._3?k(f._1,f._2,!0):f;return e(m=>ie(h,e,n,r,(p,x)=>e(J=>{const w=xt(SR)("number (min-font-size value)"),N=h._3&&!p._3?k(p._1,p._2,!0):p;return e(L=>w(N,e,n,r,(C,R)=>e(P=>(R>0?((I,U,S,v,F)=>U(H=>vn(I,U,S,v,(M,q)=>U($=>F(M,R))))):(I,U,S,v,F)=>v(I,ir("positive min-font-size value",s)))(N._3&&!C._3?k(C._1,C._2,!0):C,e,n,r,o))))})))})))}))),BR=(t,e,n,r,o)=>e(i=>Bn("out")(t,e,n,r,(a,s)=>e(u=>o(t._3&&!a._3?k(a._1,a._2,!0):a,{op:_4,operands:[]})))),GR=(t,e,n,r,o)=>e(i=>Bn("seed")(t,e,n,r,(a,s)=>e(u=>{const g=t._3&&!a._3?k(a._1,a._2,!0):a;return e(_=>ie(g,e,n,r,(f,l)=>e(d=>{const h=xt(LR)("integer (seed value)"),m=g._3&&!f._3?k(f._1,f._2,!0):f;return e(p=>h(m,e,n,r,(x,J)=>e(w=>{const N=m._3&&!x._3?k(x._1,x._2,!0):x;return e(L=>vn(N,e,n,r,(C,R)=>e(P=>o(N._3&&!C._3?k(C._1,C._2,!0):C,J))))})))})))}))),Sm=(t,e,n,r,o)=>{const i=t._3;return e(a=>Bn("diagram")(t,e,n,(s,u)=>r(k(s._1,s._2,i),u),(s,u)=>e(g=>{const _=xt(Ao)("space after 'diagram'"),f=t._3&&!s._3?k(s._1,s._2,!0):s;return e(l=>_(f,e,n,(d,h)=>r(k(d._1,d._2,i),h),(d,h)=>e(m=>{const p=xt(Bn("sequence"))("diagram mode"),x=f._3&&!d._3?k(d._1,d._2,!0):d;return e(J=>p(x,e,n,(w,N)=>r(k(w._1,w._2,i),N),(w,N)=>e(L=>{const C=x._3&&!w._3?k(w._1,w._2,!0):w;return e(R=>Nm(C,e,n,(P,I)=>r(k(P._1,P._2,i),I),(P,I)=>e(U=>o(C._3&&!P._3?k(P._1,P._2,!0):P,c4))))})))})))})))},Em=(t,e,n,r,o)=>{const i=t._3;return e(a=>Bn("still")(t,e,n,(s,u)=>r(k(s._1,s._2,i),u),(s,u)=>e(g=>{const _=t._3&&!s._3?k(s._1,s._2,!0):s;return e(f=>Nm(_,e,n,(l,d)=>r(k(l._1,l._2,i),d),(l,d)=>e(h=>o(_._3&&!l._3?k(l._1,l._2,!0):l,g4))))})))},Rm=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>Em(k(i,a,!1),e,n,(u,g)=>{const _=u._3;return e(f=>_?r(u,g):Sm(t,e,n,r,o))},o))},AR=t=>(e,n,r,o,i)=>n(a=>$n(e,n,r,o,(s,u)=>n(g=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(f=>{const l=_._3;return Rm(_,n,r,(d,h)=>o(k(d._1,d._2,l),h),(d,h)=>n(m=>o(_._3&&!d._3?k(d._1,d._2,!0):d,ir((()=>{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.";c()})(),u))))})}))),IR=t=>(e,n,r,o,i)=>n(a=>$n(e,n,r,o,(s,u)=>n(g=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(f=>{const l=(m,p)=>n(x=>(()=>{if(p.tag==="Just"){const J=(()=>{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.";c()})();return(w,N,L,C,R)=>C(w,ir(J,u))}if(p.tag==="Nothing")return(J,w,N,L,C)=>C(J,void 0);c()})()(_._3&&!m._3?k(m._1,m._2,!0):m,n,r,o,i)),d=_._1,h=_._2;return n(m=>n(p=>Rm(k(d,h,!1),n,r,(x,J)=>{const w=x._3;return n(N=>w?o(x,J):l(_,y))},(x,J)=>n(w=>l(x,T("Just",J))))))})}))),zR=(t,e,n,r,o)=>e(i=>{const a=(g,_)=>e(f=>{const l=t._3&&!g._3?k(g._1,g._2,!0):g;return e(d=>vn(l,e,n,r,(h,m)=>e(p=>{const x=l._3&&!h._3?k(h._1,h._2,!0):h;return e(J=>IR(_)(x,e,n,r,(w,N)=>e(L=>o(x._3&&!w._3?k(w._1,w._2,!0):w,_))))})))}),s=t._1,u=t._2;return e(g=>Em(k(s,u,!1),e,n,(_,f)=>{const l=_._3;return e(d=>l?r(_,f):Sm(t,e,n,r,a))},a))}),DR=(t,e,n,r,o)=>e(i=>{const a=(g,_)=>e(f=>o(g,(()=>{if(_.tag==="Nothing")return u4;if(_.tag==="Just")return _._1;c()})())),s=t._1,u=t._2;return e(g=>e(_=>zR(k(s,u,!1),e,n,(f,l)=>{const d=f._3;return e(h=>d?r(f,l):a(t,y))},(f,l)=>e(d=>a(f,T("Just",l))))))}),FR=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>ie(t,e,n,(u,g)=>r(k(u._1,u._2,a),g),(u,g)=>e(_=>Bn("via")(t._3&&!u._3?k(u._1,u._2,!0):u,e,n,(f,l)=>r(k(f._1,f._2,a),l),(f,l)=>e(d=>{const h=t._3&&!f._3?k(f._1,f._2,!0):f;return e(m=>_g(h,e,n,r,(p,x)=>e(J=>{const w=h._3&&!p._3?k(p._1,p._2,!0):p;return e(N=>Ao(w,e,n,r,(L,C)=>e(R=>{const P=xt(He)("source node identifier after 'via'"),I=w._3&&!L._3?k(L._1,L._2,!0):L;return e(U=>P(I,e,n,r,(S,v)=>e(F=>{const H=I._3&&!S._3?k(S._1,S._2,!0):S;return e(M=>ie(H,e,n,r,(q,$)=>e(B=>{const D=xt(He)("target node identifier after 'via'"),Q=H._3&&!q._3?k(q._1,q._2,!0):q;return e(O=>D(Q,e,n,r,(z,Y)=>e(V=>o(Q._3&&!z._3?k(z._1,z._2,!0):z,{from:v,to:Y}))))})))})))})))})))})))))}),MR=t=>e=>{const n=Fe(FR);return(r,o,i,a,s)=>o(u=>n(r,o,i,a,(g,_)=>o(f=>s(r._3&&!g._3?k(g._1,g._2,!0):g,{op:ar("DelNode",{id:t,via:Mt(ce.foldr,_)}),operands:[e]}))))},QR=(()=>{const t=xt(Pt(e=>e==="-"))("'-'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>{const _=xt(Ao)("space after '-'"),f=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>_(f,n,r,o,(d,h)=>n(m=>{const p=Pn(xt(He)("node identifier after '-'")),x=f._3&&!d._3?k(d._1,d._2,!0):d;return n(J=>p(x,n,r,o,(w,N)=>n(L=>{const C=N._1,R=N._2,P=x._3&&!w._3?k(w._1,w._2,!0):w;return n(I=>bm(P,n,r,o,(U,S)=>n(v=>(()=>{if(S.tag==="Just")return NR(C)(R)(S._1);if(S.tag==="Nothing")return MR(C)(R);c()})()(P._3&&!U._3?k(U._1,U._2,!0):U,n,r,o,i))))})))})))})))})(),Lr=t=>e=>(n,r,o,i,a)=>r(s=>$n(n,r,o,i,(u,g)=>r(_=>{const f=n._3&&!u._3?k(u._1,u._2,!0):u;return r(l=>Bn(t)(f,r,o,i,(d,h)=>r(m=>i(f._3&&!d._3?k(d._1,d._2,!0):d,ir(e,g)))))}))),WR=t=>t==="AnimatedSurface"?(e,n,r,o,i)=>n(a=>$n(e,n,r,o,(s,u)=>n(g=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(f=>Bn("step")(_,n,r,o,(l,d)=>n(h=>{const m=xt(Ao)("space after 'step'"),p=_._3&&!l._3?k(l._1,l._2,!0):l;return n(x=>m(p,n,r,o,(J,w)=>n(N=>{const L=Pn(xt(He)("step name")),C=p._3&&!J._3?k(J._1,J._2,!0):J;return n(R=>L(C,n,r,o,(P,I)=>n(U=>{const S=I._1,v=I._2,F=C._3&&!P._3?k(P._1,P._2,!0):P;return n(H=>$n(F,n,r,o,(M,q)=>n($=>{const B=F._3&&!M._3?k(M._1,M._2,!0):M;return n(D=>ie(B,n,r,o,(Q,O)=>n(z=>{const Y=B._3&&!Q._3?k(Q._1,Q._2,!0):Q;return n(V=>Jm(Y,n,r,o,(X,Z)=>n(nt=>{const rt=Y._3&&!X._3?k(X._1,X._2,!0):X;return n(ft=>vn(rt,n,r,o,(Nt,lt)=>n(mt=>{const vt={line:u.line,column:u.column,endLine:q.line,endColumn:q.column};return i(rt._3&&!Nt._3?k(Nt._1,Nt._2,!0):Nt,{name:T("Just",S),ops:$r("Leaf",{op:ar("Step",{name:S}),line:vt.line,column:vt.column,endLine:vt.endLine,endColumn:vt.endColumn,span:vt,operands:[v]}),kind:om})})))})))})))})))})))})))})))}))):Lr("step")("`step` markers are only supported in animated diagrams."),OR=(()=>{const t=xt(Pt(e=>e===":"))("':'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(f=>ie(_,n,r,o,(l,d)=>n(h=>{const m=Fe(Pt(aR)),p=_._3&&!l._3?k(l._1,l._2,!0):l;return n(x=>m(p,n,r,o,(J,w)=>n(N=>i(p._3&&!J._3?k(J._1,J._2,!0):J,Ba(An(Mt(ce.foldr,w)))))))})))})))})(),Pm=xt((t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>OR(k(i,a,!1),e,n,(u,g)=>{const _=u._3;return e(f=>{if(_)return r(u,g);const l=t._1,d=t._2;return e(h=>JR(k(l,d,!1),e,n,(m,p)=>{const x=m._3;return e(J=>{if(x)return r(m,p);const w=t._1,N=t._2;return e(L=>wR(k(w,N,!1),e,n,(C,R)=>{const P=C._3;return e(I=>P?r(C,R):Cm(t,e,n,r,o))},o))})},o))})},o))})('label ("\u2026", : rest-of-line, or |\u2026|)'),Bm=(t,e,n,r,o)=>e(i=>ie(t,e,n,r,(a,s)=>e(u=>Pm(t._3&&!a._3?k(a._1,a._2,!0):a,e,n,r,o)))),wg=t=>(e,n,r,o,i)=>n(a=>ie(e,n,r,o,(s,u)=>n(g=>{const _=e._3&&!s._3?k(s._1,s._2,!0):s;return n(f=>{const l=(m,p)=>n(x=>(p?((J,w,N,L,C)=>C(J,y)):(J,w,N,L,C)=>w(R=>Bm(J,w,N,L,(P,I)=>w(U=>C(P,T("Just",I))))))(_._3&&!m._3?k(m._1,m._2,!0):m,n,r,o,i)),d=_._1,h=_._2;return n(m=>{const p=(x,J)=>{const w=x._3;return n(N=>w?o(x,J):l(_,!1))};return n(x=>n(J=>n(w=>xa(k(d,h,!1),n,r,(N,L)=>{const C=N._3;return n(R=>C?p(k(d,h,!1),L):n(P=>Pt(t)(k(d,h,!1),n,r,(I,U)=>p(k(d,h,!1),U),(I,U)=>n(S=>n(v=>l(k(d,h,!1),!0))))))},(N,L)=>n(C=>n(R=>l(k(d,h,!1),!0)))))))})})}))),HR=t=>e=>n=>(r,o,i,a,s)=>o(u=>ie(r,o,i,a,(g,_)=>o(f=>{const l=Pn(xt(He)("target node identifier")),d=r._3&&!g._3?k(g._1,g._2,!0):g;return o(h=>l(d,o,i,a,(m,p)=>o(x=>{const J=p._1,w=p._2,N=d._3&&!m._3?k(m._1,m._2,!0):m;return o(L=>wg(B1)(N,o,i,a,(C,R)=>o(P=>s(N._3&&!C._3?k(C._1,C._2,!0):C,{op:ar("AddEdge",{from:t,to:J,label:R.tag==="Just"?T("Just",R._1):y,directed:n}),operands:[e,w]}))))})))}))),$R=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>Pn(He)(t,e,n,(u,g)=>r(k(u._1,u._2,a),g),(u,g)=>e(_=>{const f=t._3&&!u._3?k(u._1,u._2,!0):u;return e(l=>ie(f,e,n,(d,h)=>r(k(d._1,d._2,a),h),(d,h)=>e(m=>{const p=xt(Pt(J=>J==="<"))("'<'"),x=f._3&&!d._3?k(d._1,d._2,!0):d;return e(J=>p(x,e,n,(w,N)=>r(k(x._1,x._2,a),N),(w,N)=>e(L=>{const C=Go((P,I,U,S,v)=>{const F=P._3;return Ee("<-")(P,I,U,(H,M)=>S(k(H._1,H._2,F),M),v)}),R=x._3&&!x._3?k(x._1,x._2,!0):x;return e(P=>C(R,e,n,(I,U)=>r(k(I._1,I._2,a),U),(I,U)=>e(S=>{const v=R._3&&!I._3?k(I._1,I._2,!0):I;return e(F=>{const H=g._1,M=g._2,q=t._3&&!v._3?k(v._1,v._2,!0):v;return e($=>ie(q,e,n,r,(B,D)=>e(Q=>{const O=xt(Ee("<~"))("'<~'"),z=q._3&&!B._3?k(B._1,B._2,!0):B;return e(Y=>O(z,e,n,r,(V,X)=>e(Z=>{const nt=z._3&&!V._3?k(V._1,V._2,!0):V;return e(rt=>ie(nt,e,n,r,(ft,Nt)=>e(lt=>{const mt=Pn(xt(He)("target node identifier")),vt=nt._3&&!ft._3?k(ft._1,ft._2,!0):ft;return e(Ht=>mt(vt,e,n,r,(Tt,Vt)=>e(Gt=>{const bt=Vt._1,pt=Vt._2,ct=vt._3&&!Tt._3?k(Tt._1,Tt._2,!0):Tt;return e(wt=>wg(B1)(ct,e,n,r,(It,yt)=>e(Ct=>o(ct._3&&!It._3?k(It._1,It._2,!0):It,{op:ar("Token",{from:bt,to:H,labels:(()=>{if(yt.tag==="Nothing")return[];if(yt.tag==="Just")return[yt._1];c()})()}),operands:[pt,M]}))))})))})))})))})))})})))})))})))})))}),qR=(t,e,n,r,o)=>e(i=>vR(t,e,n,r,(a,s)=>e(u=>{const g=s._2._2,_=s._1,f=s._2._1,l=t._3&&!a._3?k(a._1,a._2,!0):a;return e(d=>ie(l,e,n,r,(h,m)=>e(p=>{const x=Pn(xt(He)("target node identifier")),J=l._3&&!h._3?k(h._1,h._2,!0):h;return e(w=>x(J,e,n,r,(N,L)=>e(C=>{const R=L._1,P=L._2,I=J._3&&!N._3?k(N._1,N._2,!0):N;return e(U=>wg(B1)(I,e,n,r,(S,v)=>e(F=>(g==="<~"?((H,M,q,$,B)=>B(H,{op:ar("Token",{from:R,to:_,labels:(()=>{if(v.tag==="Nothing")return[];if(v.tag==="Just")return[v._1];c()})()}),operands:g==="<~"?[P,f]:[f,P]})):(H,M,q,$,B)=>B(H,{op:ar("Token",{from:_,to:R,labels:(()=>{if(v.tag==="Nothing")return[];if(v.tag==="Just")return[v._1];c()})()}),operands:g==="<~"?[P,f]:[f,P]}))(I._3&&!S._3?k(S._1,S._2,!0):S,e,n,r,o))))})))})))}))),VR=(t,e,n,r,o)=>e(i=>wg(gR)(t,e,n,r,(a,s)=>e(u=>o(a,(()=>{if(s.tag==="Nothing")return"";if(s.tag==="Just")return s._1;c()})())))),UR=t=>e=>n=>r=>(o,i,a,s,u)=>i(g=>$n(o,i,a,s,(_,f)=>i(l=>{const d=o._3&&!_._3?k(_._1,_._2,!0):_;return i(h=>{const m=(J,w)=>i(N=>(()=>{if(w.tag==="Just")return(L,C,R,P,I)=>P(L,ir("node placeholder value",f));if(w.tag==="Nothing")return(L,C,R,P,I)=>C(U=>Bm(L,C,R,P,(S,v)=>C(F=>I(L._3&&!S._3?k(S._1,S._2,!0):S,{op:ar("ModNodeSlot",{id:t,slot:n,value:v}),operands:[e,r]}))));c()})()(d._3&&!J._3?k(J._1,J._2,!0):J,i,a,s,u)),p=d._1,x=d._2;return i(J=>i(w=>ps(k(p,x,!1),i,a,(N,L)=>i(C=>m(d,y)),(N,L)=>i(C=>m(k(p,x,!1),T("Just",L))))))})}))),XR=t=>e=>(n,r,o,i,a)=>r(s=>$n(n,r,o,i,(u,g)=>r(_=>{const f=n._3&&!u._3?k(u._1,u._2,!0):u;return r(l=>{const d=(p,x)=>r(J=>(()=>{if(x.tag==="Just")return(w,N,L,C,R)=>C(w,ir("node relabel label",g));if(x.tag==="Nothing")return(w,N,L,C,R)=>N(P=>Pm(w,N,L,C,(I,U)=>N(S=>R(w._3&&!I._3?k(I._1,I._2,!0):I,{op:ar("ModNode",{id:t,label:T("Just",U)}),operands:[e]}))));c()})()(f._3&&!p._3?k(p._1,p._2,!0):p,r,o,i,a)),h=f._1,m=f._2;return r(p=>r(x=>ps(k(h,m,!1),r,o,(J,w)=>r(N=>d(f,y)),(J,w)=>r(N=>d(k(h,m,!1),T("Just",w))))))})}))),KR=(()=>{const t=xt(Pt(e=>e==="~"))("'~'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>{const _=xt(Ao)("space after '~'"),f=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>_(f,n,r,o,(d,h)=>n(m=>{const p=Pn(xt(He)("source node identifier")),x=f._3&&!d._3?k(d._1,d._2,!0):d;return n(J=>p(x,n,r,o,(w,N)=>n(L=>{const C=N._1,R=N._2,P=xt(Pt(S=>S==="."))("'.'"),I=Pn(xt(He)("placeholder name")),U=x._3&&!w._3?k(w._1,w._2,!0):w;return n(S=>{const v=(M,q)=>n($=>(()=>{if(q.tag==="Just")return UR(C)(R)(q._1._1)(q._1._2);if(q.tag==="Nothing")return(B,D,Q,O,z)=>D(Y=>ie(B,D,Q,O,(V,X)=>D(Z=>{const nt=xt(Pt(ft=>ft==="-"))("'-'"),rt=B._3&&!V._3?k(V._1,V._2,!0):V;return D(ft=>{const Nt=(vt,Ht)=>D(Tt=>(()=>{if(Ht.tag==="Just")return CR(C)(R);if(Ht.tag==="Nothing")return XR(C)(R);c()})()(rt._3&&!vt._3?k(vt._1,vt._2,!0):vt,D,Q,O,z)),lt=rt._1,mt=rt._2;return D(vt=>D(Ht=>nt(k(lt,mt,!1),D,Q,(Tt,Vt)=>D(Gt=>Nt(rt,y)),(Tt,Vt)=>D(Gt=>Nt(k(lt,mt,!1),T("Just",Vt))))))})})));c()})()(U._3&&!M._3?k(M._1,M._2,!0):M,n,r,o,i)),F=U._1,H=U._2;return n(M=>n(q=>{const $=(B,D)=>{const Q=B._3;return n(O=>Q?o(B,D):v(U,y))};return n(B=>n(D=>P(k(F,H,!1),n,r,(Q,O)=>$(k(Q._1,Q._2,!1),O),(Q,O)=>n(z=>n(Y=>I(Q,n,r,(V,X)=>$(k(V._1,V._2,!1),X),(V,X)=>n(Z=>{const nt=Q._3&&!V._3?k(V._1,V._2,!0):V;return n(rt=>v(nt,T("Just",X)))})))))))}))})})))})))})))})(),G1=V0((()=>{const t=xt(Pt(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(a=>n(s=>t(e,n,r,o,(u,g)=>n(_=>n(f=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return vn(l,n,r,o,(d,h)=>n(m=>i(l._3&&!d._3?k(d._1,d._2,!0):d,h)))})))))})())(xt((()=>{const t=xt(Pt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>n(s=>vn(e,n,r,o,(u,g)=>n(_=>n(f=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return t(l,n,r,o,(d,h)=>n(m=>i(l._3&&!d._3?k(d._1,d._2,!0):d,h)))})))))})())("closing '}'")),YR=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>Cm(k(i,a,!1),e,n,(u,g)=>{const _=u._3;return e(f=>{if(_)return r(u,g);const l=t._1,d=t._2;return e(h=>ER(k(l,d,!1),e,n,(m,p)=>{const x=m._3;return e(J=>x?r(m,p):He(t,e,n,r,o))},o))})},o))},Gm=(t,e,n,r,o)=>e(i=>ie(t,e,n,r,(a,s)=>e(u=>{const g=xt(He)("attribute key"),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>{const m=_._3&&!l._3?k(l._1,l._2,!0):l;return e(p=>ie(m,e,n,r,(x,J)=>e(w=>{const N=xt(xt(Pt(C=>C===":"))("':'"))("':'"),L=m._3&&!x._3?k(x._1,x._2,!0):x;return e(C=>N(L,e,n,r,(R,P)=>e(I=>{const U=L._3&&!R._3?k(R._1,R._2,!0):R;return e(S=>ie(U,e,n,r,(v,F)=>e(H=>{const M=xt(YR)("attribute value"),q=U._3&&!v._3?k(v._1,v._2,!0):v;return e($=>M(q,e,n,r,(B,D)=>e(Q=>{const O=q._3&&!B._3?k(B._1,B._2,!0):B;return e(z=>ie(O,e,n,r,(Y,V)=>e(X=>o(O._3&&!Y._3?k(Y._1,Y._2,!0):Y,E(d,D)))))})))})))})))})))})))}))),ZR=V0((()=>{const t=xt(Pt(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(a=>n(s=>t(e,n,r,o,(u,g)=>n(_=>n(f=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return ie(l,n,r,o,(d,h)=>n(m=>i(l._3&&!d._3?k(d._1,d._2,!0):d,h)))})))))})())(xt((()=>{const t=xt(Pt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>n(s=>ie(e,n,r,o,(u,g)=>n(_=>n(f=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return t(l,n,r,o,(d,h)=>n(m=>i(l._3&&!d._3?k(d._1,d._2,!0):d,h)))})))))})())("closing '}' for attributes"))((()=>{const t=xt(Pt(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(a=>{const s=(_,f)=>n(l=>(()=>{if(f.tag==="Just")return(d,h,m,p,x)=>x(d,W);if(f.tag==="Nothing")return(d,h,m,p,x)=>h(J=>Gm(d,h,m,p,(w,N)=>h(L=>{const C=Fe((()=>{const P=xt(Pt(I=>I===","))("','");return(I,U,S,v,F)=>{const H=I._3;return U(M=>U(q=>U($=>U(B=>U(D=>U(Q=>ie(I,U,S,(O,z)=>v(k(O._1,O._2,H),z),(O,z)=>U(Y=>U(V=>{const X=I._3&&!O._3?k(O._1,O._2,!0):O;return P(X,U,S,(Z,nt)=>v(k(Z._1,Z._2,H),nt),(Z,nt)=>U(rt=>{const ft=X._3&&!Z._3?k(Z._1,Z._2,!0):Z;return U(Nt=>U(lt=>{const mt=I._3&&!ft._3?k(ft._1,ft._2,!0):ft;return ie(mt,U,S,(vt,Ht)=>v(k(vt._1,vt._2,H),Ht),(vt,Ht)=>U(Tt=>{const Vt=mt._3&&!vt._3?k(vt._1,vt._2,!0):vt;return U(Gt=>U(bt=>{const pt=I._3&&!Vt._3?k(Vt._1,Vt._2,!0):Vt;return Gm(pt,U,S,(ct,wt)=>v(k(ct._1,ct._2,H),wt),(ct,wt)=>U(It=>F(pt._3&&!ct._3?k(ct._1,ct._2,!0):ct,wt)))}))}))}))}))})))))))))}})()),R=d._3&&!w._3?k(w._1,w._2,!0):w;return h(P=>C(R,h,m,p,(I,U)=>h(S=>x(R._3&&!I._3?k(I._1,I._2,!0):I,rR([N,...Mt(ce.foldr,U)])))))})));c()})()(e._3&&!_._3?k(_._1,_._2,!0):_,n,r,o,i)),u=e._1,g=e._2;return n(_=>n(f=>t(k(u,g,!1),n,r,(l,d)=>n(h=>s(e,y)),(l,d)=>n(h=>s(k(u,g,!1),T("Just",d))))))})})()),jR=(t,e,n,r,o)=>e(i=>ie(t,e,n,r,(a,s)=>e(u=>{const g=xt(Pt(f=>f==="{"))("'{'"),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(f=>{const l=(m,p)=>e(x=>(()=>{if(p.tag==="Just")return ZR;if(p.tag==="Nothing")return(J,w,N,L,C)=>C(J,W);c()})()(_._3&&!m._3?k(m._1,m._2,!0):m,e,n,r,o)),d=_._1,h=_._2;return e(m=>e(p=>g(k(d,h,!1),e,n,(x,J)=>e(w=>l(_,y)),(x,J)=>e(w=>l(k(d,h,!1),T("Just",J))))))})}))),t6=t=>e=>(n,r,o,i,a)=>r(s=>VR(n,r,o,i,(u,g)=>r(_=>{const f=n._3&&!u._3?k(u._1,u._2,!0):u;return r(l=>jR(f,r,o,i,(d,h)=>r(m=>a(f._3&&!d._3?k(d._1,d._2,!0):d,{op:ar("AddNode",{id:t,label:g,shape:(()=>{const p=ym("shape")(h);if(p.tag==="Just")return p._1==="rectangle"||p._1==="rect"?ho:p._1==="cylinder"||p._1==="cyl"?hx:p._1==="parallelogram"?px:p._1==="diamond"?mx:p._1==="ellipse"?yx:p._1==="document"||p._1==="doc"?xx:p._1==="cloud"?Jx:ho;if(p.tag==="Nothing")return ho;c()})(),width:(()=>{const p=ym("width")(h);if(p.tag==="Just")return Og(p._1,Na,Yt,y);if(p.tag==="Nothing")return y;c()})()}),operands:[e]}))))}))),e6=(()=>{const t=xt(Pt(e=>e==="+"))("'+'");return(e,n,r,o,i)=>n(a=>t(e,n,r,o,(s,u)=>n(g=>{const _=xt(Ao)("space after '+'"),f=e._3&&!s._3?k(s._1,s._2,!0):s;return n(l=>_(f,n,r,o,(d,h)=>n(m=>{const p=Pn(xt(He)("node identifier after '+'")),x=f._3&&!d._3?k(d._1,d._2,!0):d;return n(J=>p(x,n,r,o,(w,N)=>n(L=>{const C=N._1,R=N._2,P=x._3&&!w._3?k(w._1,w._2,!0):w;return n(I=>bm(P,n,r,o,(U,S)=>n(v=>(()=>{if(S.tag==="Just")return HR(C)(R)(S._1);if(S.tag==="Nothing")return t6(C)(R);c()})()(P._3&&!U._3?k(U._1,U._2,!0):U,n,r,o,i))))})))})))})))})(),n6=(t,e,n,r,o)=>e(i=>$n(t,e,n,r,(a,s)=>e(u=>{const g=xt(P1([Lr("+node")("Node additions use `+ api: API`."),Lr("+edge")("Graph edges use `+ api -> db`."),Lr("+conn")("Undirected graph edges use `+ api -- db`."),Lr("-node")("Node removals use `- api`."),Lr("-edge")("Graph edge removals use `- api -> db`."),Lr("-conn")("Undirected graph edge removals use `- api -- db`."),Lr("~edge")("Graph edge repoints use `~ api -> db => api -> cache`."),Lr("enter")("Dive commands use `into api`."),Lr("exit")("Return from a dive with `out`."),bR,e6,QR,KR,qR,$R,RR,BR]))("statement (+ node, - node, + edge, - edge, ~ node, into, out, or 'a ~> b'/'a <~ b')"),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>{const m=_._3&&!l._3?k(l._1,l._2,!0):l;return e(p=>$n(m,e,n,r,(x,J)=>e(w=>{const N={line:s.line,column:s.column,endLine:J.line,endColumn:J.column};return o(m._3&&!x._3?k(x._1,x._2,!0):x,$r("Leaf",{op:d.op,line:N.line,column:N.column,endLine:N.endLine,endColumn:N.endColumn,span:N,operands:d.operands}))})))})))}))),Am=(t,e,n,r,o)=>e(i=>{const a=t._3;return e(s=>vn(t,e,n,(u,g)=>r(k(u._1,u._2,a),g),(u,g)=>e(_=>{const f=Go(xt(Pt(d=>d==="}"))("'}'")),l=t._3&&!u._3?k(u._1,u._2,!0):u;return e(d=>f(l,e,n,(h,m)=>r(k(h._1,h._2,a),m),(h,m)=>e(p=>Go(xa)(l._3&&!h._3?k(h._1,h._2,!0):h,e,n,(x,J)=>r(k(x._1,x._2,a),J),(x,J)=>e(w=>{const N=t._3&&!x._3?k(x._1,x._2,!0):x;return e(L=>_g(N,e,n,r,(C,R)=>e(P=>{const I=P1([o6,r6,n6]),U=N._3&&!C._3?k(C._1,C._2,!0):C;return e(S=>I(U,e,n,r,(v,F)=>e(H=>{const M=U._3&&!v._3?k(v._1,v._2,!0):v;return e(q=>ie(M,e,n,r,($,B)=>e(D=>{const Q=M._3&&!$._3?k($._1,$._2,!0):$;return e(O=>Jm(Q,e,n,r,(z,Y)=>e(V=>{const X=Q._3&&!z._3?k(z._1,z._2,!0):z;return e(Z=>vn(X,e,n,r,(nt,rt)=>e(ft=>o(X._3&&!nt._3?k(nt._1,nt._2,!0):nt,F))))})))})))})))})))})))))})))}),r6=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>{const u=(g,_)=>{const f=g._3;return e(l=>f?r(g,_):e(d=>{const h=t._3;return e(m=>Bn("seq")(t,e,n,(p,x)=>r(k(p._1,p._2,h),x),(p,x)=>e(J=>{const w=t._3&&!p._3?k(p._1,p._2,!0):p;return e(N=>ie(w,e,n,(L,C)=>r(k(L._1,L._2,h),C),(L,C)=>e(R=>ps(w._3&&!L._3?k(L._1,L._2,!0):L,e,n,(P,I)=>r(k(P._1,P._2,h),I),(P,I)=>e(U=>{const S=t._3&&!P._3?k(P._1,P._2,!0):P;return e(v=>_g(S,e,n,r,(F,H)=>e(M=>{const q=xt(xt(Pt(B=>B==="{"))("'{'"))("'{'"),$=S._3&&!F._3?k(F._1,F._2,!0):F;return e(B=>q($,e,n,r,(D,Q)=>e(O=>o($._3&&!D._3?k(D._1,D._2,!0):D,$r("GroupSeq",[])))))})))})))))})))}))};return e(g=>e(_=>Bn("seq")(k(i,a,!1),e,n,(f,l)=>u(k(f._1,f._2,!1),l),(f,l)=>e(d=>e(h=>ie(f,e,n,(m,p)=>u(k(m._1,m._2,!1),p),(m,p)=>e(x=>{const J=f._3&&!m._3?k(m._1,m._2,!0):m;return xt(Pt(w=>w==="{"))("'{'")(J,e,n,(w,N)=>u(k(J._1,J._2,!1),N),(w,N)=>e(L=>G1(A1(h4))(J,e,n,u,o)))})))))))})},o6=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>{const u=(g,_)=>{const f=g._3;return e(l=>f?r(g,_):e(d=>{const h=t._3;return e(m=>Bn("par")(t,e,n,(p,x)=>r(k(p._1,p._2,h),x),(p,x)=>e(J=>{const w=t._3&&!p._3?k(p._1,p._2,!0):p;return e(N=>ie(w,e,n,(L,C)=>r(k(L._1,L._2,h),C),(L,C)=>e(R=>ps(w._3&&!L._3?k(L._1,L._2,!0):L,e,n,(P,I)=>r(k(P._1,P._2,h),I),(P,I)=>e(U=>{const S=t._3&&!P._3?k(P._1,P._2,!0):P;return e(v=>_g(S,e,n,r,(F,H)=>e(M=>{const q=xt(xt(Pt(B=>B==="{"))("'{'"))("'{'"),$=S._3&&!F._3?k(F._1,F._2,!0):F;return e(B=>q($,e,n,r,(D,Q)=>e(O=>o($._3&&!D._3?k(D._1,D._2,!0):D,$r("Par",[])))))})))})))))})))}))};return e(g=>e(_=>Bn("par")(k(i,a,!1),e,n,(f,l)=>u(k(f._1,f._2,!1),l),(f,l)=>e(d=>e(h=>ie(f,e,n,(m,p)=>u(k(m._1,m._2,!1),p),(m,p)=>e(x=>{const J=f._3&&!m._3?k(m._1,m._2,!0):m;return xt(Pt(w=>w==="{"))("'{'")(J,e,n,(w,N)=>u(k(J._1,J._2,!1),N),(w,N)=>e(L=>G1(A1(l4))(J,e,n,u,o)))})))))))})},A1=t=>{const e=Fe(Am);return(n,r,o,i,a)=>r(s=>e(n,r,o,i,(u,g)=>r(_=>a(n._3&&!u._3?k(u._1,u._2,!0):u,t(Mt(ce.foldr,g))))))},I1=t=>e=>(n,r,o,i,a)=>r(s=>km(t)(n,r,o,i,(u,g)=>r(_=>{const f=Fe(Pt(cR)),l=n._3&&!u._3?k(u._1,u._2,!0):u;return r(d=>f(l,r,o,i,(h,m)=>r(p=>{const x=xt(xt(Pt(w=>w==="{"))("'{'"))("'{'"),J=l._3&&!h._3?k(h._1,h._2,!0):h;return r(w=>x(J,r,o,i,(N,L)=>r(C=>{const R=J._3&&!N._3?k(N._1,N._2,!0):N;return r(P=>vn(R,r,o,i,(I,U)=>r(S=>{const v=A1(d4),F=R._3&&!I._3?k(I._1,I._2,!0):I;return r(H=>v(F,r,o,i,(M,q)=>r($=>{const B=F._3&&!M._3?k(M._1,M._2,!0):M;return r(D=>vn(B,r,o,i,(Q,O)=>r(z=>{const Y=xt(xt(Pt(X=>X==="}"))("'}'"))("closing '}'"),V=B._3&&!Q._3?k(Q._1,Q._2,!0):Q;return r(X=>Y(V,r,o,i,(Z,nt)=>r(rt=>{const ft=V._3&&!Z._3?k(Z._1,Z._2,!0):Z;return r(Nt=>vn(ft,r,o,i,(lt,mt)=>r(vt=>a(ft._3&&!lt._3?k(lt._1,lt._2,!0):lt,{name:pR(An(Mt(ce.foldr,m))),ops:q,kind:e}))))})))})))})))})))})))})))}))),i6=(t,e,n,r,o)=>{const i=t._1,a=t._2;return e(s=>Lr("keyframe")("Drop the `keyframe` wrapper; Markgraf animates statements in order.")(k(i,a,!1),e,n,(u,g)=>{const _=u._3;return e(f=>{if(_)return r(u,g);const l=t._1,d=t._2;return e(h=>I1("scene")(pg)(k(l,d,!1),e,n,(m,p)=>{const x=m._3;return e(J=>{if(x)return r(m,p);const w=t._1,N=t._2;return e(L=>I1("still")(k1)(k(w,N,!1),e,n,(C,R)=>{const P=C._3;return e(I=>P?r(C,R):I1("title")(f4)(t,e,n,r,o))},o))})},o))})},o))},a6=t=>e=>n=>{if(t==="AnimatedSurface")return{...e,frames:Et(e.frames)({name:y,ops:n,kind:pg})};if(t==="StillSurface")return{...e,statements:Et(e.statements)(n)};if(t==="SequenceSurface")return{...e,statements:Et(e.statements)(n)};c()},s6=t=>e=>n=>{if(n.tag==="TopFrame"){const r=vm(t)(e);return{...r,frames:Et(r.frames)((()=>{if(t==="AnimatedSurface")return n._1;if(t==="StillSurface")return{...n._1,kind:n._1.kind==="AnimatedKeyframe"?k1:n._1.kind==="StepMarker"?om:n._1.kind};if(t==="SequenceSurface")return n._1;c()})())}}if(n.tag==="TopStatement")return a6(t)(e)(n._1);if(n.tag==="TopInside")return e;c()},u6=t=>{const e=b(s6(t))(xR);return n=>vm(t)(e(n)).frames},g6=t=>SE.defer(e=>{const n=WR(t);return(r,o,i,a,s)=>{const u=r._1,g=r._2;return o(_=>AR(t)(k(u,g,!1),o,i,(f,l)=>{const d=f._3;return o(h=>{if(d)return a(f,l);const m=r._1,p=r._2;return o(x=>o(J=>c6(k(m,p,!1),o,i,(w,N)=>{const L=w._3;return o(C=>{if(L)return a(w,N);const R=r._1,P=r._2;return o(I=>o(U=>n(k(R,P,!1),o,i,(S,v)=>{const F=S._3;return o(H=>{if(F)return a(S,v);const M=r._1,q=r._2;return o($=>o(B=>i6(k(M,q,!1),o,i,(D,Q)=>{const O=D._3;return o(z=>O?a(D,Q):o(Y=>Am(r,o,i,a,(V,X)=>o(Z=>s(V,xg("TopStatement",X))))))},(D,Q)=>o(O=>s(D,xg("TopFrame",Q))))))})},(S,v)=>o(F=>s(S,xg("TopFrame",v))))))})},(w,N)=>o(L=>s(w,xg("TopInside",N))))))})},s))}}),c6=(t,e,n,r,o)=>e(i=>Bn("inside")(t,e,n,r,(a,s)=>e(u=>{const g=xt(Ao)("space after 'inside'"),_=t._3&&!a._3?k(a._1,a._2,!0):a;return e(f=>g(_,e,n,r,(l,d)=>e(h=>{const m=xt(He)("node identifier after 'inside'"),p=_._3&&!l._3?k(l._1,l._2,!0):l;return e(x=>m(p,e,n,r,(J,w)=>e(N=>{const L=p._3&&!J._3?k(J._1,J._2,!0):J;return e(C=>vn(L,e,n,r,(R,P)=>e(I=>{const U=L._3&&!R._3?k(R._1,R._2,!0):R;return e(S=>G1(Im)(U,e,n,r,(v,F)=>e(H=>{const M=U._3&&!v._3?k(v._1,v._2,!0):v;return e(q=>vn(M,e,n,r,($,B)=>e(D=>o(M._3&&!$._3?k($._1,$._2,!0):$,{node:w,doc:F}))))})))})))})))})))}))),Im=(t,e,n,r,o)=>e(i=>DR(t,e,n,r,(a,s)=>e(u=>{const g=t._3&&!a._3?k(a._1,a._2,!0):a;return e(_=>{const f=(h,m)=>e(p=>{const x=g._3&&!h._3?k(h._1,h._2,!0):h;return e(J=>{const w=(C,R)=>e(P=>{const I=x._3&&!C._3?k(C._1,C._2,!0):C;return e(U=>{const S=(v,F)=>e(H=>{const M=Fe(g6(s)),q=I._3&&!v._3?k(v._1,v._2,!0):v;return e($=>M(q,e,n,r,(B,D)=>e(Q=>{const O=Mt(ce.foldr,D);return o(q._3&&!B._3?k(B._1,B._2,!0):B,{seed:(()=>{if(m.tag==="Nothing")return 0;if(m.tag==="Just")return m._1;c()})(),minimumFontSize:R,stretchNodes:F,mode:s,frames:u6(s)(O),interiors:ht(z=>{if(z.tag==="TopInside")return T("Just",z._1);if(z.tag==="TopFrame"||z.tag==="TopStatement")return y;c()})(O)})})))});return e(v=>{const F=I._1,H=I._2;return e(M=>e(q=>kR(k(F,H,!1),e,n,($,B)=>{const D=$._3;return e(Q=>D?r($,B):e(O=>S(I,!1)))},($,B)=>e(D=>e(Q=>S($,!0))))))})})}),N=x._1,L=x._2;return e(C=>e(R=>PR(k(N,L,!1),e,n,(P,I)=>{const U=P._3;return e(S=>U?r(P,I):w(x,y))},(P,I)=>e(U=>w(P,T("Just",I))))))})}),l=g._1,d=g._2;return e(h=>e(m=>GR(k(l,d,!1),e,n,(p,x)=>{const J=p._3;return e(w=>J?r(p,x):f(g,y))},(p,x)=>e(J=>f(p,T("Just",x))))))})}))),_6=(()=>{const t=xt((e,n,r,o,i)=>n(a=>n(s=>vn(e,n,r,o,(u,g)=>n(_=>n(f=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return xa(l,n,r,o,(d,h)=>n(m=>i(l._3&&!d._3?k(d._1,d._2,!0):d,h)))}))))))("'scene', 'still', 'title', 'step', 'inside', a statement, or end of input");return(e,n,r,o,i)=>n(a=>n(s=>n(u=>n(g=>vn(e,n,r,o,(_,f)=>n(l=>n(d=>{const h=e._3&&!_._3?k(_._1,_._2,!0):_;return Im(h,n,r,o,(m,p)=>n(x=>{const J=h._3&&!m._3?k(m._1,m._2,!0):m;return n(w=>n(N=>{const L=e._3&&!J._3?k(J._1,J._2,!0):J;return t(L,n,r,o,(C,R)=>n(P=>i(L._3&&!C._3?k(C._1,C._2,!0):C,p)))}))}))})))))))})(),f6=t=>{const e=H0(t)(_6);if(e.tag==="Left")return zt("Left",{msg:hR(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 zt("Right",e._1);c()},l6=t=>{const e=f6(t);if(e.tag==="Left")return zt("Left",e._1.msg);if(e.tag==="Right")return zt("Right",e._1);c()},d6=()=>({tag:"ParFrag"}),zm=t=>t,h6=zm("Sync"),p6=zm("SelfMsg"),m6=d6(),Io=W0(Xn),qn=Ei(Xn),kr=Io.state(t=>E(t,t)),zo=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=G.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Dm=t=>e=>{const n=ut.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Tg=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Do=Ri(Xn),y6=t=>e=>b(n=>r=>Ei(Xn).bind(n)(o=>t(o)(r)))(Ri(Xn).pure(e)),Fm=Mo(Do)(Qt),Mm=t=>e=>Io.state(n=>E(void 0,{...n,lifelines:af(G)(r=>T("Just",{...r,label:Ja(e)}))(t)(n.lifelines),labelTemplates:it(G)(t)(e)(n.labelTemplates)})),ms=t=>Io.state(e=>E(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:T("Just",t)};c()})())),x6=t=>e=>n=>qn.bind(kr)(r=>{const o=zo(t)(r.labelTemplates);if(o.tag==="Nothing")return ms("node "+t+" label has no placeholder `"+e+"`");if(o.tag==="Just"){const i=Y0(e)(n)(o._1);if(i.tag==="Left")return ms("node "+t+" "+i._1);if(i.tag==="Right")return Mm(t)(i._1)}c()}),J6=t=>e=>{const n=lg(e);if(n.tag==="Left")return ms("invalid label for node "+t+": "+n._1);if(n.tag==="Right")return Mm(t)(n._1);c()},w6=t=>e=>n=>{const r=zo(n)(t.lifelines);return zo(e)(t.lifelines).tag==="Nothing"?r.tag==="Nothing"?e+", "+n:e:r.tag==="Nothing"?n:""},T6={lifelines:W,labelTemplates:W,lifelineOrder:[],messages:[],fragments:[],frameEndRows:[],row:0,error:y},N6=t=>e=>n=>qn.bind(kr)(r=>{const o=zo(t)(r.lifelines),i=zo(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?p6:h6},...r.messages],row:r.row+1|0};return Io.state(s=>E(void 0,a))}return ms("token references unknown node: "+w6(r)(t)(e))}),b6=t=>Io.state(e=>E(void 0,{...e,lifelines:af(G)(n=>T("Just",{...n,destroyedAt:T("Just",e.row)}))(t)(e.lifelines)})),v6=t=>e=>{const n=e.lifelineOrder.length,r=Bt(o=>y,o=>i=>T("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return{fromCol:0,toCol:Tg(0)(e.lifelineOrder.length-1|0)};if(r.tag==="Just")return b(o=>i=>({fromCol:Dm(o.fromCol)(Dm(i.fromCol)(i.toCol)),toCol:Tg(o.toCol)(Tg(i.fromCol)(i.toCol))}))({fromCol:n,toCol:0})(t);c()},C6=t=>({lifelines:ht(e=>zo(e)(t.lifelines))(t.lifelineOrder),messages:re(t.messages),fragments:re(t.fragments),frameEndRows:t.frameEndRows,totalRows:t.row}),L6=t=>e=>qn.bind(kr)(n=>{const r=zo(t)(n.lifelines);if(r.tag==="Just")return Do.pure();if(r.tag==="Nothing"){const o={...n,lifelines:it(G)(t)({id:t,label:Ja(e),column:n.lifelineOrder.length,createdAt:n.row,destroyedAt:y})(n.lifelines),labelTemplates:it(G)(t)(e)(n.labelTemplates),lifelineOrder:Et(n.lifelineOrder)(t),row:n.row>0||n.messages.length!==0?n.row+1|0:n.row};return Io.state(i=>E(void 0,o))}c()}),k6=t=>e=>qn.bind(kr)(n=>{const r=zo(t)(n.lifelines);if(r.tag==="Just")return Do.pure();if(r.tag==="Nothing"){const o=lg(e);if(o.tag==="Left")return ms("invalid label for node "+t+": "+o._1);if(o.tag==="Right")return L6(t)(o._1)}c()}),S6=t=>{if(t.tag==="AddNode")return k6(t._1.id)(t._1.label);if(t.tag==="DelNode")return b6(t._1.id);if(t.tag==="ModNode"){if(t._1.label.tag==="Just")return J6(t._1.id)(t._1.label._1);if(t._1.label.tag==="Nothing")return Do.pure();c()}return t.tag==="ModNodeSlot"?x6(t._1.id)(t._1.slot)(t._1.value):t.tag==="Token"?N6(t._1.from)(t._1.to)(t._1.labels):Do.pure()},E6=t=>qn.bind(kr)(e=>{const n=e.row;return qn.bind(y6(r=>o=>qn.bind(kr)(i=>{const a=r.childMessages.length===0?r.dividers:[i.row,...r.dividers],s=i.messages;return qn.bind(z1(o))(()=>qn.bind(kr)(u=>Do.pure({dividers:a,childMessages:[...r.childMessages,...(()=>{const g=u.messages.length-s.length|0;return g<1?[]:At(0,g,u.messages)})()]})))}))({dividers:[],childMessages:[]})(t))(r=>qn.bind(kr)(o=>{const i=v6(r.childMessages)(o),a={kind:m6,label:"par",fromRow:n,toRow:Tg(o.row)(n+1|0),fromCol:i.fromCol,toCol:i.toCol,regionDividers:re(r.dividers)},s=Io.state(u=>E(void 0,{...u,fragments:[a,...u.fragments]}));return r.childMessages.length>=2?s:Do.pure()}))}),z1=t=>{if(t.tag==="Leaf")return S6(t._1.op);if(t.tag==="Seq"||t.tag==="GroupSeq")return Fm(z1)(t._1);if(t.tag==="Par")return E6(t._1);c()},R6=t=>{const e=qn.bind(Fm(n=>qn.bind(kr)(r=>qn.bind(z1(n.ops))(()=>qn.bind(kr)(o=>{const i=Io.state(a=>E(void 0,{...a,frameEndRows:Et(a.frameEndRows)(a.row-1|0)}));return(o.messages.length-r.messages.length|0)>0?i:Do.pure()}))))(t.frames))(()=>kr)(T6)._1;if(e.error.tag==="Just")return zt("Left",e.error._1);if(e.error.tag==="Nothing")return zt("Right",C6(e));c()},P6=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},B6={padding:24,headerHeight:36,headerWidth:120,columnSpacing:160,rowHeight:36,topGap:24,bottomGap:24},G6=t=>{const e=84+ot(P6(1)(t.totalRows))*36,n=Ft(r=>o=>({lifeline:o,x:84+ot(r)*160}))(t.lifelines);return{metrics:B6,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}},A6=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=y;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=T("Just",i._4);continue}}c()}return o},Qm=t=>e=>{const n=ut.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Wm=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const a=ut.compare(t)(i._3);if(a==="LT"){n=i._5;continue}if(a==="GT"){n=i._6;continue}if(a==="EQ"){r=!1,o=!0;continue}}c()}return o},Om=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},I6=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},z6=b(t=>e=>it(ut)(e)()(t))(W),D6={r:255,g:255,b:255,a:255},Ng={r:26,g:26,b:26,a:255},F6={color:{r:232,g:232,b:232,a:255},flat:!0},M6={r:232,g:232,b:232,a:255},bg=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,...Jo],Hm=t=>e=>n=>({...n,stack:Et(n.stack)(t),openedAt:it(ut)(t)(e)(n.openedAt)}),vg=t=>e=>{const n=e.stack.length-1|0;if(n>=0&&n<e.stack.length){const r=A6(e.stack[n])(e.openedAt),o=(()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return r._1;c()})();return{...e,stack:e.stack.length===0?[]:At(0,e.stack.length-1|0,e.stack),openedAt:Mi(ut)(e.stack[n])(e.openedAt),spans:Et(e.spans)({col:e.stack[n],fromRow:o,toRow:Qm(o)(t)})}}return e},$m=t=>e=>n=>{let r=t,o=e,i=n,a=!0,s;for(;a;){const u=r,g=o,_=i,f=_.stack.length-1|0;if(f>=0&&f<_.stack.length){if(u(_.stack[f])){a=!1,s=_;continue}r=u,o=g,i=vg(g)(_);continue}a=!1,s=_}return s},qm=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=vg(a)(s);continue}o=!1,i=s}return i},Q6=t=>e=>{const n=yn(go)(e.fromCol)(t.stack)?$m((()=>{const r=e.fromCol;return o=>r===o})())(e.row-1|0)(t):Hm(e.fromCol)(e.row)(qm(e.row-1|0)(t));if(yn(go)(e.toCol)(n.stack)){const r=$m((()=>{const o=e.toCol;return i=>o===i})())(e.row-1|0)(vg(e.row)(n));return{...r,returnRows:it(ut)(e.row)()(r.returnRows)}}return Hm(e.toCol)(e.row)(n)},W6=t=>e=>n=>{const r=Q6(e)(n);return Wm(n.row)(t)?qm(n.row)(r):r},Cg={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:Ia,lineCap:Ar},Vm={r:26,g:26,b:26,a:255},O6={color:{r:130,g:130,b:130,a:255},width:1,lineJoin:Ia,lineCap:Mn},Um={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:Ia,lineCap:Mn},H6={color:{r:244,g:244,b:244,a:255},flat:!0},Xm=t=>e=>n=>oe(r=>r.col===e&&r.fromRow<=n&&n<=r.toRow,t),Km={color:{r:90,g:90,b:90,a:255},width:1,lineJoin:Ia,lineCap:Mn},$6={stack:[],openedAt:W,spans:[],returnRows:W},q6={color:{r:150,g:150,b:150,a:255},width:1,lineJoin:Ia,lineCap:Mn},V6=t=>e=>n=>r=>o=>{const i=e.bodyTop+(ot(o)+.5)*e.metrics.rowHeight-e.metrics.rowHeight/2;return t.strokePath([1,n,i,2,r,i])(q6)},U6=t=>{const e=t.Monad0(),n=e.Bind1(),r=Ii(e.Applicative0())(Qt);return o=>i=>{const a=o.bodyTop+(ot(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,...Jo],g=i.toCol>=0&&i.toCol<o.columns.length?o.columns[i.toCol].x+16:o.metrics.padding+16,_=o.bodyTop+(ot(Qm(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,g,a,2,g,_,2,s,_,...Jo])(Km))(()=>n.bind(t.fillStrokePath(u)(F6)(Km))(()=>n.bind(t.drawText({x:s+6,y:a+7,content:"par",font:{family:"Inter",size:11,weight:700},color:Ng,align:wr,baseline:Fn}))(()=>r(i.regionDividers)(V6(t)(o)(s)(g)))))}},Ym=t=>e=>t>=e?[]:[E(t,Om(e)(t+6)),...Ym(t+10)(e)],X6=t=>e=>{if(e<=t)return[];const n=r=>r>=e?[]:[E(r,Om(e)(r+6)),...n(r+10)];return n(t)},K6=t=>{const e=Ii(t.Monad0().Applicative0())(Qt);return n=>r=>e(X6(n.headerTop+n.metrics.headerHeight+ot(r.lifeline.createdAt)*n.metrics.rowHeight+4)((()=>{if(r.lifeline.destroyedAt.tag==="Just")return n.bodyTop+(ot(r.lifeline.destroyedAt._1)+.5)*n.metrics.rowHeight;if(r.lifeline.destroyedAt.tag==="Nothing")return n.bodyBottom;c()})()))(o=>t.strokePath([1,r.x,o._1,2,r.x,o._2])(O6))},Zm=t=>e=>t<=e?[]:[E(t,I6(e)(t-6)),...Zm(t-6-4)(e)],Y6=t=>e=>t===e?[]:t<e?Ym(t)(e):Zm(t)(e),Z6=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.headerTop+ot(r.lifeline.createdAt)*n.metrics.rowHeight,i=n.metrics.headerWidth/2,a=o+n.metrics.headerHeight,s=bg(r.x-i)(o)(r.x+i)(a)(6);return e.bind(t.fillStrokePath(bg(r.x-i)(o+5)(r.x+i)(a+5)(6))({color:M6,flat:!0})(Um))(()=>e.bind(t.fillStrokePath(s)(H6)(Um))(()=>t.drawText({x:r.x,y:o+n.metrics.headerHeight/2,content:r.lifeline.label,font:{family:"Inter",size:14,weight:600},color:Ng,align:Aa,baseline:Fn})))}},j6=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=vg(a)(s);continue}o=!1,i=s}return i},tP=t=>j6((()=>{const e=t.diagram.messages.length-1|0;return e>=0&&e<t.diagram.messages.length?t.diagram.messages[e].row:0})())(b(W6(z6(t.diagram.frameEndRows)))($6)(_t(e=>e.kind==="Sync"||e.kind!=="SelfMsg",t.diagram.messages))),eP=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.bodyTop+(ot(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,g=i+10,_=[1,i,u,2,g,u-5,2,g,u+5,...Jo];return e.bind(t.strokePath([1,i,a,2,s,a,2,s,u,2,i,u])(Cg))(()=>e.bind(t.fillPath(_)({color:Vm,flat:!0}))(()=>t.drawText({x:i+42,y:o,content:dr(" ")(K(wa)(r.labels)),font:{family:"Inter",size:12,weight:400},color:Ng,align:wr,baseline:Fn})))}},nP=t=>{const e=t.Monad0(),n=e.Bind1(),r=Ii(e.Applicative0())(Qt);return o=>i=>a=>s=>{const u=a?o.bodyTop+(ot(s.row)+.5)*o.metrics.rowHeight+o.metrics.rowHeight*.5:o.bodyTop+(ot(s.row)+.5)*o.metrics.rowHeight,g=s.toCol>=s.fromCol?1:-1,_=(s.fromCol>=0&&s.fromCol<o.columns.length?o.columns[s.fromCol].x:o.metrics.padding)+(Xm(i)(s.fromCol)(s.row)?g*6:g*0),f=(s.toCol>=0&&s.toCol<o.columns.length?o.columns[s.toCol].x:o.metrics.padding)-(Xm(i)(s.toCol)(s.row)?g*6:g*0),l=f-g*10,d=a?t.strokePath([1,l,u-5,2,f,u,2,l,u+5])(Cg):t.fillPath([1,f,u,2,l,u-5,2,l,u+5,...Jo])({color:Vm,flat:!0});return n.bind(a?r(Y6(_)(f))(h=>t.strokePath([1,h._1,u,2,h._2,u])(Cg)):t.strokePath([1,_,u,2,f,u])(Cg))(()=>n.bind(d)(()=>t.drawText({x:(_+f)/2,y:u-6,content:dr(" ")(K(wa)(s.labels)),font:{family:"Inter",size:12,weight:400},color:Ng,align:Aa,baseline:nw})))}},rP=t=>{const e=eP(t),n=nP(t);return r=>o=>i=>a=>{if(a.kind==="SelfMsg")return e(r)(a);if(a.kind==="Sync")return n(r)(o)(Wm(a.row)(i))(a);c()}},jm={color:{r:26,g:26,b:26,a:255},width:1.25,lineJoin:rn,lineCap:Mn},oP={color:{r:232,g:232,b:232,a:255},flat:!0},iP={color:{r:252,g:252,b:252,a:255},flat:!0},aP=t=>e=>n=>{const r=n.col>=0&&n.col<e.columns.length?e.columns[n.col].x:e.metrics.padding,o=e.bodyTop+(ot(n.fromRow)+.5)*e.metrics.rowHeight,i=e.bodyTop+(ot(n.toRow)+.5)*e.metrics.rowHeight+e.metrics.rowHeight*.5,a=bg(r-6)(o)(r+6)(i)(3);return t.Monad0().Bind1().bind(t.fillStrokePath(bg(r-6)(o+5)(r+6)(i+5)(3))(oP)(jm))(()=>t.fillStrokePath(a)(iP)(jm))},t2=t=>{const e=t.Monad0(),n=e.Bind1(),r=Ii(e.Applicative0())(Qt),o=Z6(t),i=K6(t),a=U6(t),s=rP(t);return u=>{const g=tP(u);return n.bind(t.setViewport({vx:0,vy:0,vw:u.width,vh:u.height}))(()=>n.bind(t.clearBackground(D6))(()=>n.bind(r(u.columns)(o(u)))(()=>n.bind(r(u.columns)(i(u)))(()=>n.bind(r(g.spans)(aP(t)(u)))(()=>n.bind(r(u.diagram.fragments)(a(u)))(()=>r(u.diagram.messages)(s(u)(g.spans)(g.returnRows))))))))}},sP=t2(xw);function e2(t){return function(e){return function(){return t.add(e)}}}function D1(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 n2(t){return function(){return t.classList}}function Cn(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function uP(t){return function(e){return function(){return e.getAttribute(t)}}}const r2=t=>{const e=uP(t);return n=>{const r=e(n);return()=>{const o=r();return Gn(o,y,Yt)}}};function gP(t){return function(e){return function(){e.textContent=t}}}function cP(t){return function(){return function(e){return t(e)()}}}function _P(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const F1=function(){return window};function fP(t){return function(e){return function(){e.value=t}}}function lP(t){return function(){return t.valueAsNumber}}function dP(t){return function(){return t.value}}function M1(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const ys=t=>t,xs=t=>()=>{const e=t.getBoundingClientRect?.(),n=e?.width||t.clientWidth||0,r=e?.height||t.clientHeight||0;return{width:n,height:r}},o2=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)}},i2=()=>window.devicePixelRatio||1,a2=()=>performance.now()/1e3,hP=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
27
|
<rect x="0" y="0" width="${i}" height="${a}" rx="16" fill="#111827"/>
|
|
28
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
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 g=window.devicePixelRatio||1;t.width=Math.max(1,Math.round(i*g)),t.height=Math.max(1,Math.round(a*g));const _=t.getContext("2d");if(!_)return;_.save(),_.scale(g,g),_.clearRect(0,0,i,a),_.fillStyle="#111827",_.fillRect(0,0,i,a),_.textAlign="center",_.textBaseline="middle",_.fillStyle="#f9fafb",_.font="700 18px system-ui, sans-serif",_.fillText(s,i/2,a/2-10),_.fillStyle="#cbd5e1",_.font="13px system-ui, sans-serif",_.fillText(u,i/2,a/2+18),_.restore();return}t.textContent=`${s}. ${u}.`},
|
|
30
|
+
`;return}if(t instanceof HTMLCanvasElement){const g=window.devicePixelRatio||1;t.width=Math.max(1,Math.round(i*g)),t.height=Math.max(1,Math.round(a*g));const _=t.getContext("2d");if(!_)return;_.save(),_.scale(g,g),_.clearRect(0,0,i,a),_.fillStyle="#111827",_.fillRect(0,0,i,a),_.textAlign="center",_.textBaseline="middle",_.fillStyle="#f9fafb",_.font="700 18px system-ui, sans-serif",_.fillText(s,i/2,a/2-10),_.fillStyle="#cbd5e1",_.font="13px system-ui, sans-serif",_.fillText(u,i/2,a/2+18),_.restore();return}t.textContent=`${s}. ${u}.`},Js=(t,e)=>{e.innerHTML=t},Lg=(t,e,n)=>{t.style.setProperty(e,n)},pP=(t,e)=>t.querySelector(`[data-mg="${e}"]`),kg=t=>e=>t===e,Sg=new WeakMap,Q1=new WeakSet,mP=`#version 300 es
|
|
31
31
|
precision highp float;
|
|
32
32
|
out vec2 vUv;
|
|
33
33
|
void main() {
|
|
34
34
|
vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
|
|
35
35
|
vUv = p;
|
|
36
36
|
gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
|
37
|
-
}`,
|
|
37
|
+
}`,yP=`#version 300 es
|
|
38
38
|
precision highp float;
|
|
39
39
|
uniform sampler2D uScene;
|
|
40
40
|
uniform float uStrength;
|
|
@@ -58,7 +58,7 @@ void main() {
|
|
|
58
58
|
float flicker = sin(uTime * 21.7) * 0.004 + sin(uTime * 7.1) * 0.003;
|
|
59
59
|
color.rgb *= 1.0 + flicker * film;
|
|
60
60
|
fragColor = color;
|
|
61
|
-
}`,s2=(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},
|
|
61
|
+
}`,s2=(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},xP=(t,e,n)=>{const r=s2(t,t.VERTEX_SHADER,e),o=s2(t,t.FRAGMENT_SHADER,n),i=t.createProgram();if(!i)throw new Error("Unable to allocate zoom program");if(t.attachShader(i,r),t.attachShader(i,o),t.linkProgram(i),t.deleteShader(r),t.deleteShader(o),!t.getProgramParameter(i,t.LINK_STATUS)){const a=t.getProgramInfoLog(i)||"Zoom shader link failed";throw t.deleteProgram(i),new Error(a)}return i},JP=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=xP(n,mP,yP),s=n.createTexture();if(!s)throw new Error("Unable to allocate zoom texture");return n.bindTexture(n.TEXTURE_2D,s),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!0),n.useProgram(a),n.uniform1i(n.getUniformLocation(a,"uScene"),0),{changedPosition:i,gl:n,overlay:e,overlayHeight:-1,overlayLeft:-1,overlayTop:-1,overlayWidth:-1,parent:r,program:a,restorePosition:o,restoreVisibility:t.style.visibility,sceneTextureHeight:0,sceneTextureWidth:0,source:t,texture:s,zoomFilmAmountLocation:n.getUniformLocation(a,"uFilmAmount"),zoomStrengthLocation:n.getUniformLocation(a,"uStrength"),zoomTimeLocation:n.getUniformLocation(a,"uTime")}}catch{return e.remove(),i&&r.style.position==="relative"&&(r.style.position=o),null}},wP=(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")},Eg=(t,e)=>{let n=Sg.get(t);if(Number(e)<.008){wP(t,n);return}if(Q1.has(t)){t.setAttribute("data-mg-gpu-pass","unavailable");return}if(!n){try{n=JP(t)}catch{n=null}if(!n){Q1.add(t),t.setAttribute("data-mg-gpu-pass","unavailable");return}Sg.set(t,n)}const{gl:r,overlay:o,program:i,texture:a}=n,s=Math.max(1,t.width),u=Math.max(1,t.height);o.width!==s&&(o.width=s),o.height!==u&&(o.height=u);const g=t.offsetLeft,_=t.offsetTop,f=t.clientWidth,l=t.clientHeight;n.overlayLeft!==g&&(o.style.left=`${g}px`,n.overlayLeft=g),n.overlayTop!==_&&(o.style.top=`${_}px`,n.overlayTop=_),n.overlayWidth!==f&&(o.style.width=`${f}px`,n.overlayWidth=f),n.overlayHeight!==l&&(o.style.height=`${l}px`,n.overlayHeight=l),o.style.display!=="block"&&(o.style.display="block"),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,a),n.sceneTextureWidth!==s||n.sceneTextureHeight!==u?(r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t),n.sceneTextureWidth=s,n.sceneTextureHeight=u):r.texSubImage2D(r.TEXTURE_2D,0,0,0,r.RGBA,r.UNSIGNED_BYTE,t),r.bindFramebuffer(r.FRAMEBUFFER,null),r.viewport(0,0,s,u),r.useProgram(i);const d=Math.max(0,Math.min(1,Number(e)||0));r.uniform1f(n.zoomFilmAmountLocation,Math.sqrt(d)),r.uniform1f(n.zoomTimeLocation,performance.now()/1e3),r.uniform1f(n.zoomStrengthLocation,d),r.drawArrays(r.TRIANGLES,0,3),t.getAttribute("data-mg-gpu-pass")!=="active"&&t.setAttribute("data-mg-gpu-pass","active"),t.style.visibility!=="hidden"&&(t.style.visibility="hidden")},TP=t=>{const e=Sg.get(t);e&&(e.gl.deleteTexture(e.texture),e.gl.deleteProgram(e.program),e.overlay.remove(),t.style.visibility=e.restoreVisibility,e.changedPosition&&e.parent.style.position==="relative"&&(e.parent.style.position=e.restorePosition)),Sg.delete(t),Q1.delete(t),t.removeAttribute("data-mg-gpu-pass")},u2=(t,e)=>({tag:t,_1:e}),g2=t=>t,NP=(t,e,n)=>({tag:t,_1:e,_2:n}),Fo=t=>e=>{const n=at.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},bP=t2(M_),vP=Qt.foldMap(uf),Rg=t=>e=>{const n=at.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},CP=Qt.foldMap(uf),W1=NP("AutoSize"),LP=g2("CanvasRenderer"),kP=g2("SvgRenderer"),SP=t=>e=>{const n=t-e*ot(he(sr(t/e)));return e<=0?0:n<0?n+e:n},Bi=t=>b(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),EP=t=>{const e=r2("data-markgraf-theme")(t);return()=>{const n=e();if(n.tag==="Just")return n._1==="light"?x1:n._1==="dark"?mS:n._1==="blueprint"?yS:n._1==="whiteboard"?xS:n._1==="isometric"?JS:x1;if(n.tag==="Nothing")return x1;c()}},RP=`
|
|
62
62
|
<canvas data-mg="stage" tabindex="0"></canvas>
|
|
63
63
|
<div data-mg="play-overlay" aria-hidden="true"></div>
|
|
64
64
|
<div data-mg="bar">
|
|
@@ -75,6 +75,6 @@ void main() {
|
|
|
75
75
|
<option value="2">2\xD7</option>
|
|
76
76
|
</select>
|
|
77
77
|
</div>
|
|
78
|
-
`,c2=t=>e=>{const n=Gn(t,y,
|
|
78
|
+
`,c2=t=>e=>{const n=Gn(t,y,Yt);if(n.tag==="Just"){const r=Gn(n._1.stopAt,y,Yt);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;c()}if(n.tag==="Nothing")return e;c()},PP=t=>e=>{const n=o=>r(o),r=o=>({...o,state:{...o.state,animationTime:t},minis:K(n)(o.minis)});return{...e,levels:K(r)(e.levels)}},_2=t=>e=>({...e,state:{...e.state,camera:t},minis:K(n=>_2(t)(n))(e.minis)}),BP=t=>e=>n=>{const r=_r(n.rootLayout)(n.camera),o=Cn("data-mg-too-small")("0")(t);return()=>(o(),Cn("data-mg-camera-vw")(Ln(r.w))(t)(),Cn("data-mg-camera-vh")(Ln(r.h))(t)(),Cn("data-mg-camera-zoom")(Ln(n.camera.zoom))(t)(),Cn("data-mg-viewport-css-width")(Ln(e.w))(t)(),Cn("data-mg-viewport-css-height")(Ln(e.h))(t)())},GP=t=>{const e=R6(t);if(e.tag==="Left")return zt("Left",e._1);if(e.tag==="Right")return zt("Right",G6(e._1));c()},AP=t=>e=>n=>{if(e.tag==="FixedSize")return()=>({w:e._1,h:e._2});if(e.tag==="AutoSize"){const r=xs(t);return()=>{const o=r(),i=o.width<=0?n.width:o.width;return{w:i,h:o.height<=0?i*n.height/Fo(1)(n.width):o.height}}}c()},IP=t=>oe(e=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Jt("Cons",r._4,n(r._6,o)));c()};return oe(r=>{const o=(i,a)=>{if(i.tag==="Leaf")return a;if(i.tag==="Node")return o(i._5,Jt("Cons",i._4,o(i._6,a)));c()};return oe(i=>oe(a=>a.style==="RunHighlight"||a.style==="RunBoldHighlight"||a.style==="RunCodeHighlight"||a.style==="RunCodeBoldHighlight",Sn(i)),Mt(ce.foldr,o(r.labels,A)))},Mt(ce.foldr,n(e.keyframes,A)))},t.segments),zP=t=>e=>n=>{const r=uS(hS(sP(n))),o=Cn("viewBox")(r.viewBox)(t);return()=>(o(),Cn("preserveAspectRatio")("xMidYMid meet")(t)(),e.tag==="FixedSize"?(Cn("width")(ue(he(Kn(e._1))))(t)(),Cn("height")(ue(he(Kn(e._2))))(t)()):e.tag==="AutoSize"||c(),Js(r.body,t))},DP=t=>e=>n=>{const r=ys(t),o=AP(t)(e)(n);return()=>{const i=o(),a=i2(),s=i.w*a,u=i.h*a,g=_f(r)(),_=ff(r)(),f=lf(r)(s);g!==s&&f();const l=df(r)(u);_!==u&&l(),e.tag==="FixedSize"?(Lg(t,"width",ue(he(Kn(i.w)))+"px"),Lg(t,"height",ue(he(Kn(i.h)))+"px")):e.tag==="AutoSize"||c();const d=cf(r)();gr(d)(),Ca(d)({scaleX:a,scaleY:a})();const h=ip(d)({width:i.w,height:i.h})();return bP(n)(h)(),cr(d)()}},FP=t=>e=>n=>r=>{if(e==="CanvasRenderer")return DP(t)(n)(r);if(e==="SvgRenderer")return zP(t)(n)(r);c()},MP=t=>e=>n=>r=>()=>{let o=!1,i=()=>{},a=[];const s=()=>{const g=o,_=FP(t)(e)(n)(r);if(!g)return _()},u={time:0,keyframe:"sequence",playing:!1};return s(),i=o2(t)(()=>{s();const g=a;return Bi(_=>_(u))(g)()})(),{play:()=>{},playWith:g=>()=>{},pause:()=>{},toggle:()=>{},seek:g=>()=>{},seekCue:g=>()=>{},seekStep:g=>()=>{},playToCue:g=>_=>()=>{},playToStep:g=>_=>()=>{},playNext:g=>()=>{},playPrevious:g=>()=>{},setSpeed:g=>()=>{},currentTime:(()=>{const g=u.time;return()=>g})(),currentKeyframe:(()=>{const g=u.keyframe;return()=>g})(),isPlaying:()=>!1,duration:0,cues:[],steps:[],subscribe:g=>()=>{a=Et(a)(g),g(u)();const _=Ta(f=>!kg(f)(g));return()=>{a=_(a)}},subscribeCue:g=>()=>()=>{},subscribeComplete:g=>()=>()=>{},destroy:()=>(o=!0,i())}},qr=t=>e=>n=>()=>{const r=pP(t,e),o=Gn(r,y,Yt);if(o.tag==="Just")return n(o._1)();o.tag!=="Nothing"&&c()},QP=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=vP(o=>'<span class="mg-tick" style="left:'+qo(Ho("Fixed",$o(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;c()})()+'"></span>')(e.spans);return qr(t)("ticks")(o=>()=>Js(r,o))},WP=t=>e=>n=>qr(t)("scrub")(r=>{const o=D1(y,Yt,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return n<=0?()=>{}:fP(ue(he(Kn(e/n*1e3))))(o._1);c()}),O1=t=>e=>n=>{const r=cP(o=>n);return()=>{const o=r();return _P(t)(o)(!1)(e)()}},OP=t=>e=>{const n=n2(t);return()=>{const r=n();return e2(r)("markgraf-embed")(),Js(`
|
|
79
79
|
<svg data-mg="stage" tabindex="0" role="img" aria-label="Markgraf sequence diagram"></svg>
|
|
80
|
-
`,t),$r(t)("stage")(o=>{const i=FP(o)(CP)(H1)(e);return()=>{const a=D1();M1(()=>{i()})(a)()}})()}},HP=t=>e=>{const n=Gn(t,y,Xt);if(n.tag==="Just"){const r=Gn(n._1.loop,y,Xt);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;c()}if(n.tag==="Nothing")return e;c()},W1=t=>e=>{const n=te(r=>r.startT<=e&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return n._1.scene._1.to;if(n._1.scene.tag==="DataFlow")return n._1.scene._1.keyframe;if(n._1.scene.tag==="Hold")return n._1.scene._1;if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return"";if(n._1.scene.tag==="StepScene")return n._1.scene._1;c()}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;c()}return""}c()},OP=t=>e=>$r(t)("speed")(n=>{const r=F1(y,Xt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return O1("change")(n)((()=>{const o=fP(r._1);return()=>{const i=o(),a=Og(i,Na,Xt,y);if(a.tag==="Just")return e(a._1)();a.tag!=="Nothing"&&c()}})());c()}),WP=t=>e=>n=>$r(t)("scrub")(r=>{const o=F1(y,Xt,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return O1("input")(r)((()=>{const i=_P(o._1);return()=>{const a=i();return n.pause(),n.seek(a/1e3*e.totalDuration)()}})());c()}),$P=t=>e=>n=>{const r=DP(t)(e);return()=>{r(),$r(t)("play")(o=>Cn("data-mg-playing")("1")(o))(),OP(t)(n.setSpeed)(),$r(t)("play")(o=>O1("click")(o)(n.toggle))(),WP(t)(e)(n)(),n.subscribe(o=>{const i=MP(t)(o.time)(e.totalDuration);return()=>(i(),$r(t)("time")(a=>sP(Wo(Ho("Fixed",Oo(0)(20)(2)))(o.time)+" / "+Wo(Ho("Fixed",Oo(0)(20)(2)))(e.totalDuration))(a))(),$r(t)("play")(a=>Cn("data-mg-playing")(o.playing?"1":"0")(a))())})()}},qP=t=>e=>{if(e.tag==="FixedSize")return()=>({widthPx:e._1,heightPx:e._2});if(e.tag==="AutoSize"){const n=xs(t);return()=>{const r=n();return{widthPx:r.width<=0?200:r.width,heightPx:r.height<=0?180:r.height}}}c()},VP=t=>e=>n=>{const r=qP(t)(e);return()=>{const o=r(),i=ep(n)(),a=np(n)(),s=bE(Xx)(o)(uE)(n)(rp(i)(a)(n));if(s.tag==="Left")return zt("Left","precompute failed");if(s.tag==="Right")return zt("Right",{schedule:s._1});c()}},UP=t=>e=>(()=>{const n=Gn(t,y,Xt);if(n.tag==="Just")return{...n._1,direction:e<0?"backward":"forward"};if(n.tag==="Nothing")return{direction:e<0?"backward":"forward",speed:ba,duration:ba,loop:ba,stopAt:ba};c()})(),f2=t=>e=>{const n=Gn(t,y,Xt);if(n.tag==="Just"){const r=Gn(n._1.direction,y,Xt);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;c()},KP=t=>e=>{const n=_t(o=>o.time<=e+1e-4,t),r=n.length-1|0;return r>=0&&r<n.length?n[r].index:-1},l2=t=>e=>[{label:"PAN BOUNDS",color:"#22c55e",box:e.level},...(()=>{if(e.visible.tag==="Nothing")return[];if(e.visible.tag==="Just")return[{label:"VISIBLE CONTENT",color:"#f59e0b",box:e.visible._1}];c()})(),...(()=>{if(e.action.tag==="Nothing")return[];if(e.action.tag==="Just")return[{label:"ACTION BOXES",color:"#f43f5e",box:e.action._1}];c()})(),...(()=>{if(e.actionText.tag==="Nothing")return[];if(e.actionText.tag==="Just")return[{label:"ACTION TEXT",color:"#a855f7",box:e.actionText._1}];c()})(),...(()=>{if(e.actionGuide.tag==="Nothing")return[];if(e.actionGuide.tag==="Just")return[{label:"ACTION DETAIL",color:"#a3a3a3",box:e.actionGuide._1}];c()})(),{label:"OUTPUT",color:"#38bdf8",box:{x:t.vx,y:t.vy,w:t.vw,h:t.vh}},{label:"RAW CAMERA FRAME",color:"#2563eb",box:e.camera}],YP=t=>e=>n=>r=>o=>{const i=gr(t);return()=>(i(),Ss(t)(1.5)(),Sy(t)([6,4])(),Jf(t)("bold 10px monospace")(),Gi(a=>{const s={x:(a.box.x-r.vx)*e/r.vw,y:(a.box.y-r.vy)*n/r.vh,width:a.box.w*e/r.vw,height:a.box.h*n/r.vh},u=pf(t)(a.color);return()=>(u(),hf(t)(a.color)(),By(t)(s)(),Tf(t)(a.label)(s.x+4)(s.y+12)())})(l2(r)(o))(),cr(t)())},XP=t=>e=>n=>'<g data-mg-camera-bounds="1" pointer-events="none">'+bP(r=>'<rect x="'+Ln(r.box.x)+'" y="'+Ln(r.box.y)+'" width="'+Ln(r.box.w)+'" height="'+Ln(r.box.h)+'" fill="none" stroke="'+r.color+'" stroke-width="1.5" stroke-dasharray="6 4" vector-effect="non-scaling-stroke"/><text x="'+Ln(r.box.x+4*t)+'" y="'+Ln(r.box.y+12*t)+'" fill="'+r.color+'" stroke="#09090b" stroke-width="'+Ln(3*t)+'" paint-order="stroke" font-family="monospace" font-size="'+Ln(10*t)+'">'+r.label+"</text>")(l2(e)(n))+"</g>",ZP=t=>e=>n=>{const r=n.levels.length-1|0;if(r>=0&&r<n.levels.length){const o=WT(t.cameraConfig)(n.levels[r].segment)(e);return T("Just",{action:o.action,actionText:o.actionText,actionGuide:o.actionGuide,camera:_r(n.rootLayout)(n.camera),level:o.level,visible:o.visible})}return y},jP=t=>e=>{if(e.tag==="FixedSize"){const n=e._1<=0||e._2<=0?y:T("Just",e._1/e._2);return()=>n}if(e.tag==="AutoSize"){const n=xs(t);return()=>{const r=n();return r.width<=0||r.height<=0?y:T("Just",r.width/r.height)}}c()},Js=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>_=>f=>()=>{const l=a2(),d=_.value,h=g.value,m=d===0?0:l-d,p=h+m;_.value=l,g.value=p;const x=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const S=xs(t)();return{w:S.width<=0?200:S.width,h:S.height<=0?180:S.height}}c()})();if(x.w<200||x.h<180){if(lP(t)(x.w)(x.h)(200)(180)(),e==="CanvasRenderer")return Eg(ys(t),0);if(e==="SvgRenderer")return;c()}const w=a.value,J=(()=>{if(w.tag==="Just"&&w._1.w===x.w&&w._1.h===x.h)return w._1.schedule;const S={widthPx:x.w,heightPx:x.h},v=S.heightPx===i.cameraViewport.heightPx&&S.widthPx===i.cameraViewport.widthPx?i:FS(S)(i);return a.value=T("Just",{w:x.w,h:x.h,schedule:v}),v})(),N=Rg(f)(J.totalDuration),k=EP(p)(DN(J)(N)),C=u.value,R=(()=>{if(C.tag==="Nothing")return k.camera;if(C.tag==="Just")return Yx(i.cameraConfig.cameraDecay)(m)(C._1)(k.camera);c()})();u.value=T("Just",R);const P={...k,camera:R,levels:Y(_2(R))(k.levels)};RP(t)(x)(P)();const I=r2("data-mg-debug-camera")(t)(),U=(()=>{if(I.tag==="Nothing")return!1;if(I.tag==="Just")return!0;c()})()?ZP(J)(N)(P):y;if(e==="CanvasRenderer"){const S=ys(t),v=p1({width:0,height:0})(P),D=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const V=xs(t)();return{w:V.width,h:V.height<=0?v.vw<=0?V.width:V.width*v.vh/v.vw:V.height}}c()})(),W=i2(),M=D.w*W,q=D.h*W,$=_f(S)(),G=ff(S)(),F=lf(S)(M);$!==M&&F();const Q=df(S)(q);G!==q&&Q(),n.tag==="FixedSize"?(Lg(t,"width",ue(he(Vn(D.w)))+"px"),Lg(t,"height",ue(he(Vn(D.h)))+"px")):n.tag==="AutoSize"||c();const O=cf(S)();gr(O)(),Ca(O)({scaleX:W,scaleY:W})();const z=s.value,X=X5(r)(o)(O)({width:D.w,height:D.h})(P)(m)(z)();return s.value=X,cr(O)(),U.tag==="Just"?(gr(O)(),Ca(O)({scaleX:W,scaleY:W})(),YP(O)(D.w)(D.h)(p1({width:D.w,height:D.h})(P))(U._1)(),cr(O)()):U.tag==="Nothing"||c(),Eg(S,bN(P.portalState))}if(e==="SvgRenderer"){const S=s.value,v=jP(t)(n)(),D=RS(v)(r)(o)(P)(m)(S);s.value=D.springs,Cn("viewBox")(D.parts.viewBox)(t)(),Cn("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(Cn("width")(ue(he(Vn(n._1))))(t)(),Cn("height")(ue(he(Vn(n._2))))(t)()):n.tag==="AutoSize"||c();const W=XP(D.parts.vw/zo(1)(x.w))({vx:D.parts.vx,vy:D.parts.vy,vw:D.parts.vw,vh:D.parts.vh});return ws((()=>{if(U.tag==="Nothing")return D.parts.body+"";if(U.tag==="Just")return D.parts.body+W(U._1);c()})(),t)}c()},tG=t=>{const e=mm(t)(gm)._1;if(e.tag==="Left")return zt("Left",e._1.msg);if(e.tag==="Right")return zt("Right",e._1);c()},d2=t=>{const e=_6(t);if(e.tag==="Left")return zt("Left",e._1);if(e.tag==="Right"){if(e._1.mode==="SequenceSurface"){const r=PP(e._1);if(r.tag==="Left")return zt("Left",r._1);if(r.tag==="Right")return zt("Right",u2("LoadedSequence",r._1));c()}const n=tG(e._1);if(n.tag==="Left")return zt("Left",n._1);if(n.tag==="Right")return zt("Right",u2("LoadedAnimation",n._1))}c()},eG=t=>{const e=d2(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return ba;c()},h2=t=>e=>n=>r=>{const o=n+1e-4>=e?_t(a=>a.time>e+1e-4&&a.time<=n+1e-4,t):[..._t(a=>a.time>e+1e-4,t),..._t(a=>a.time<=n+1e-4,t)],i=n<=e+1e-4?re(_t(a=>a.time<e-1e-4&&a.time>=n-1e-4,t)):[...re(_t(a=>a.time<e-1e-4,t)),...re(_t(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},nG=t=>e=>n=>r=>te(o=>oe(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),rG=t=>e=>n=>r=>{const o=_t(a=>oe(s=>s===a.kind,e)&&(a.time<n-1e-4||(()=>{const s=a.time-n;return(s<0?-s<=1e-4:s<=1e-4)&&a.index<r})()),t),i=o.length-1|0;return i>=0&&i<o.length?T("Just",o[i]):y},$1=t=>e=>n=>{const r=Gn(e,y,Xt);if(r.tag==="Just"){const o=Gn(r._1.speed,y,Xt);if(o.tag==="Just"){const i=zo(1e-4)(o._1<0?-o._1:o._1);return()=>t.value=i}if(o.tag==="Nothing"){const i=Gn(r._1.duration,y,Xt);if(i.tag==="Just"&&n.tag==="Just"){const a=n._1/i._1,s=zo(1e-4)(a<0?-a:a);if(i._1>0)return()=>t.value=s}return()=>{}}c()}if(r.tag==="Nothing")return()=>{};c()},oG=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,g=Gn(t,y,Xt);if(g.tag==="Just"){const _=Gn(g._1.direction,y,Xt);if(_.tag==="Just"){if(_._1==="forward")return i||u?T("Just",1):y;if(_._1==="backward"||_._1==="reverse")return i||a?T("Just",-1):y}return T("Just",s)}if(g.tag==="Nothing")return T("Just",s);c()},iG=t=>e=>n=>r=>o=>i=>()=>{const a={value:1};let s=1,u=!0,g=y,_=-1,f=!0,l=!1,d=0,h=0;const m={value:H},p={value:y},x={value:0},w={value:0},J={value:y};let N=!1,k=()=>{},C=[],R=[],P=[];if(Js(t)(n)(r)(o)(i)(e)(J)(m)(p)(x)(w)(0)(),n==="CanvasRenderer"&&e.dives.length!==0){const z=ys(t);Eg(z,.01),Eg(z,0)}const I=z=>{const X=z.index;return()=>{_=X;const V=R;return Gi(K=>K(z))(V)()}},U=z=>()=>{const X=C,V=f,K={time:z,keyframe:W1(e)(z),playing:V};return Gi(Z=>Z(K))(X)()},S=()=>(f=!1,g=y,U(d)()),v=z=>()=>(d=z,Js(t)(n)(r)(o)(i)(e)(J)(m)(p)(x)(w)(z)(),U(z)()),D=z=>{const X=zo(0)(Rg(e.totalDuration)(z));return()=>(d=X,_=KP(e.cues)(X),h=0,g=y,p.value=y,Js(t)(n)(r)(o)(i)(e)(J)(m)(p)(x)(w)(X)(),U(X)())},W=(z,X,V,K,Z)=>()=>{f=!1,g=y;const nt=d;U(nt)();const rt={reason:z,direction:X<0?"backward":"forward",targetId:V,targetStep:K,reached:Z,time:nt},ft=P;return Gi(Nt=>Nt(rt))(ft)()},M=BP(e),q=()=>{if(!N){if(l=!1,f){const z=a2(),X=h;h=z;const V=a.value,K=s,Z=u,nt=g,rt=d,ft=X===0?rt+0*V*K:rt+(z-X)*V*K;if(nt.tag==="Just"){const Nt=K>=0?nt._1.cue.time>=rt-1e-4&&nt._1.cue.time<=ft+1e-4:nt._1.cue.time<=rt+1e-4&&nt._1.cue.time>=ft-1e-4,lt=Nt?nt._1.cue.time:zo(0)(Rg(e.totalDuration)(ft));(K>=0?lt+1e-4<rt:lt>rt+1e-4)&&(p.value=y),v(lt)(),Gi(vt=>I(vt))(h2(e.cues)(rt)(lt)(K))();const mt=W("target",K,nt._1.targetId,nt._1.targetStep,!0);Nt&&mt(),Nt||$()}else if(nt.tag==="Nothing"){const Nt=K>=0?e.totalDuration:0,lt=!Z&&(K>=0?Nt>=rt-1e-4&&Nt<=ft+1e-4:Nt<=rt+1e-4&&Nt>=ft-1e-4),mt=Z?LP(ft)(e.totalDuration+.8):zo(0)(Rg(e.totalDuration)(ft));(K>=0?mt+1e-4<rt:mt>rt+1e-4)&&(p.value=y),v(mt)(),Gi(Wt=>I(Wt))(h2(e.cues)(rt)(mt)(K))();const vt=W("boundary",K,"","",!0);lt&&vt(),lt||$()}else c()}if(M&&!f){const z=d;return Js(t)(n)(r)(o)(i)(e)(J)(m)(p)(x)(w)(z)(),$()}}},$=()=>{if(!N&&!l){l=!0;const z=D1();M1(q)(z)()}},G=()=>(h=0,f=!0,$()),F=()=>(s=1,u=!0,g=y,G(),U(d)()),Q=(z,X)=>()=>{const V=d;return s=z,u=!1,g=y,$1(a)(X)(T("Just",z>=0?e.totalDuration-V:V))(),G()},O=(z,X)=>()=>{const V=d,K=_,Z=oG(X)(V)(K)(z);if(Z.tag==="Nothing")return Q(f2(X)(1),X)();if(Z.tag==="Just"){const nt=z.time-V,rt=nt<0?-nt:nt;return s=Z._1,u=!1,g=T("Just",{cue:z,direction:Z._1,targetId:z.id,targetStep:z.name}),$1(a)(X)(T("Just",rt))(),rt<=1e-4?(D(z.time)(),I(z)(),W("target",Z._1,z.id,z.name,!0)()):G()}c()};return k=o2(t)(()=>{if(!N){const z=d;return Js(t)(n)(r)(o)(i)(e)(J)(m)(p)(x)(w)(z)(),U(z)()}})(),G(),{play:F,playWith:z=>{const X=f2(z)(1);return()=>(s=X,u=HP(z)(!1),g=y,$1(a)(z)(y)(),G(),U(d)())},pause:S,toggle:()=>f?S():F(),seek:z=>D(z),seekCue:z=>{const X=te(V=>V.id===z)(e.cues);if(X.tag==="Nothing")return()=>{};if(X.tag==="Just"){const V=X._1,K=D(V.time);return()=>(K(),I(V)())}c()},seekStep:z=>{const X=te(V=>V.kind==="step"&&V.name===z)(e.cues);if(X.tag==="Nothing")return()=>{};if(X.tag==="Just"){const V=X._1,K=D(V.time);return()=>(K(),I(V)())}c()},playToCue:z=>X=>{const V=te(K=>K.id===z)(e.cues);if(V.tag==="Nothing")return()=>{};if(V.tag==="Just")return O(V._1,X);c()},playToStep:z=>X=>{const V=te(K=>K.kind==="step"&&K.name===z)(e.cues);if(V.tag==="Nothing")return()=>{};if(V.tag==="Just")return O(V._1,X);c()},playNext:z=>()=>{const X=d,V=_,K=nG(e.cues)(c2(z)(["step"]))(X)(V);if(K.tag==="Nothing")return Q(1,z)();if(K.tag==="Just")return O(K._1,z)();c()},playPrevious:z=>()=>{const X=d,V=_,K=rG(e.cues)(c2(z)(["step"]))(X)(V);if(K.tag==="Nothing")return Q(-1,z)();if(K.tag==="Just")return O(K._1,UP(z)(-1))();c()},setSpeed:z=>{const X=zo(1e-4)(z<0?-z:z);return()=>a.value=X},currentTime:()=>d,currentKeyframe:()=>{const z=d;return W1(e)(z)},isPlaying:()=>f,duration:e.totalDuration,cues:e.cues,steps:_t(z=>z.kind==="step",e.cues),subscribe:z=>()=>{C=Et(C)(z);const X=d,V=f;z({time:X,keyframe:W1(e)(X),playing:V})();const K=Ta(Z=>!kg(Z)(z));return()=>{C=K(C)}},subscribeCue:z=>()=>{R=Et(R)(z);const X=Ta(V=>!kg(V)(z));return()=>{R=X(R)}},subscribeComplete:z=>()=>{P=Et(P)(z);const X=Ta(V=>!kg(V)(z));return()=>{P=X(P)}},destroy:()=>{if(N=!0,k(),n==="CanvasRenderer")return wP(ys(t));n!=="SvgRenderer"&&c()}}},aG=t=>e=>{const n=n2(t);return()=>{const r=n();e2(r)("markgraf-embed")();const o=kP(t)();return ws(SP,t),$r(t)("stage")(i=>{const a=VP(i)(H1)(e);return()=>{const s=D1();M1(()=>{const u=a();if(u.tag==="Left")return gf("[markgraf] precompute failed")();if(u.tag==="Right"){const g=iG(i)(u._1.schedule)(vP)(H1)(o)(xS)();return $P(t)(u._1.schedule)(g)()}c()})(s)()}})()}},p2=t=>e=>{const n=d2(e);if(n.tag==="Left")return gf("[markgraf] parse failed: "+n._1);if(n.tag==="Right"){if(n._1.tag==="LoadedAnimation")return aG(t)(n._1._1);if(n._1.tag==="LoadedSequence")return QP(t)(n._1._1)}c()},sG=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 qr=null;const Pg=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",uG=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{Pg(t)?(qr&&qr!==t&&Pg(qr)&&qr.querySelector('[data-mg="play"]').click(),qr=t):qr===t&&(qr=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},gG=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=sG(t),n=t.dataset.markgrafPaused==="true";t.textContent="",p2(t)(e)(),t.querySelector('[data-mg="play"]')&&(n?Pg(t)&&t.querySelector('[data-mg="play"]').click():qr===null?qr=t:Pg(t)&&t.querySelector('[data-mg="play"]').click(),uG(t))},Gg=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(gG)},m2=()=>{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||qr||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=eG(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>p2(e)(n)(),mountAll:Gg,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{Gg(),m2()}):(Gg(),m2())}return Bg.mountAll=Gg,Object.defineProperty(Bg,Symbol.toStringTag,{value:"Module"}),Bg})({});
|
|
80
|
+
`,t),qr(t)("stage")(o=>{const i=MP(o)(kP)(W1)(e);return()=>{const a=F1();M1(()=>{i()})(a)()}})()}},HP=t=>e=>{const n=Gn(t,y,Yt);if(n.tag==="Just"){const r=Gn(n._1.loop,y,Yt);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;c()}if(n.tag==="Nothing")return e;c()},H1=t=>e=>{const n=te(r=>r.startT<=e&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return n._1.scene._1.to;if(n._1.scene.tag==="DataFlow")return n._1.scene._1.keyframe;if(n._1.scene.tag==="Hold")return n._1.scene._1;if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return"";if(n._1.scene.tag==="StepScene")return n._1.scene._1;c()}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;c()}return""}c()},$P=t=>e=>qr(t)("speed")(n=>{const r=D1(y,Yt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return O1("change")(n)((()=>{const o=dP(r._1);return()=>{const i=o(),a=Og(i,Na,Yt,y);if(a.tag==="Just")return e(a._1)();a.tag!=="Nothing"&&c()}})());c()}),qP=t=>e=>n=>qr(t)("scrub")(r=>{const o=D1(y,Yt,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return O1("input")(r)((()=>{const i=lP(o._1);return()=>{const a=i();return n.pause(),n.seek(a/1e3*e.totalDuration)()}})());c()}),VP=t=>e=>n=>{const r=QP(t)(e);return()=>{r(),qr(t)("play")(o=>Cn("data-mg-playing")("1")(o))(),$P(t)(n.setSpeed)(),qr(t)("play")(o=>O1("click")(o)(n.toggle))(),qP(t)(e)(n)(),n.subscribe(o=>{const i=WP(t)(o.time)(e.totalDuration);return()=>(i(),qr(t)("time")(a=>gP(qo(Ho("Fixed",$o(0)(20)(2)))(o.time)+" / "+qo(Ho("Fixed",$o(0)(20)(2)))(e.totalDuration))(a))(),qr(t)("play")(a=>Cn("data-mg-playing")(o.playing?"1":"0")(a))())})()}},UP=t=>e=>{if(e.tag==="FixedSize")return()=>({widthPx:e._1,heightPx:e._2});if(e.tag==="AutoSize"){const n=xs(t);return()=>{const r=n();return{widthPx:r.width<=0?200:r.width,heightPx:r.height<=0?180:r.height}}}c()},XP=t=>e=>n=>{const r=UP(t)(e);return()=>{const o=r(),i=ep(n)(),a=np(n)(),s=CE(Yx)(o)(cE)(n)(rp(i)(a)(n));if(s.tag==="Left")return zt("Left","precompute failed");if(s.tag==="Right")return zt("Right",{schedule:s._1});c()}},KP=t=>e=>(()=>{const n=Gn(t,y,Yt);if(n.tag==="Just")return{...n._1,direction:e<0?"backward":"forward"};if(n.tag==="Nothing")return{direction:e<0?"backward":"forward",speed:ba,duration:ba,loop:ba,stopAt:ba};c()})(),f2=t=>e=>{const n=Gn(t,y,Yt);if(n.tag==="Just"){const r=Gn(n._1.direction,y,Yt);if(r.tag==="Just"){if(r._1==="backward"||r._1==="reverse")return-1;if(r._1==="forward")return 1}return e}if(n.tag==="Nothing")return e;c()},YP=t=>e=>{const n=_t(o=>o.time<=e+1e-4,t),r=n.length-1|0;return r>=0&&r<n.length?n[r].index:-1},l2=t=>e=>[{label:"PAN BOUNDS",color:"#22c55e",box:e.level},...(()=>{if(e.visible.tag==="Nothing")return[];if(e.visible.tag==="Just")return[{label:"VISIBLE CONTENT",color:"#f59e0b",box:e.visible._1}];c()})(),...(()=>{if(e.action.tag==="Nothing")return[];if(e.action.tag==="Just")return[{label:"ACTION BOXES",color:"#f43f5e",box:e.action._1}];c()})(),...(()=>{if(e.actionText.tag==="Nothing")return[];if(e.actionText.tag==="Just")return[{label:"ACTION TEXT",color:"#a855f7",box:e.actionText._1}];c()})(),...(()=>{if(e.actionGuide.tag==="Nothing")return[];if(e.actionGuide.tag==="Just")return[{label:"ACTION DETAIL",color:"#a3a3a3",box:e.actionGuide._1}];c()})(),{label:"OUTPUT",color:"#38bdf8",box:{x:t.vx,y:t.vy,w:t.vw,h:t.vh}},{label:"RAW CAMERA FRAME",color:"#2563eb",box:e.camera}],ZP=t=>e=>n=>r=>o=>{const i=gr(t);return()=>(i(),Ss(t)(1.5)(),Sy(t)([6,4])(),wf(t)("bold 10px monospace")(),Bi(a=>{const s={x:(a.box.x-r.vx)*e/r.vw,y:(a.box.y-r.vy)*n/r.vh,width:a.box.w*e/r.vw,height:a.box.h*n/r.vh},u=pf(t)(a.color);return()=>(u(),hf(t)(a.color)(),Gy(t)(s)(),Tf(t)(a.label)(s.x+4)(s.y+12)())})(l2(r)(o))(),cr(t)())},jP=t=>e=>n=>'<g data-mg-camera-bounds="1" pointer-events="none">'+CP(r=>'<rect x="'+Ln(r.box.x)+'" y="'+Ln(r.box.y)+'" width="'+Ln(r.box.w)+'" height="'+Ln(r.box.h)+'" fill="none" stroke="'+r.color+'" stroke-width="1.5" stroke-dasharray="6 4" vector-effect="non-scaling-stroke"/><text x="'+Ln(r.box.x+4*t)+'" y="'+Ln(r.box.y+12*t)+'" fill="'+r.color+'" stroke="#09090b" stroke-width="'+Ln(3*t)+'" paint-order="stroke" font-family="monospace" font-size="'+Ln(10*t)+'">'+r.label+"</text>")(l2(e)(n))+"</g>",tB=t=>e=>n=>{const r=n.levels.length-1|0;if(r>=0&&r<n.levels.length){const o=HT(t.cameraConfig)(n.levels[r].segment)(e);return T("Just",{action:o.action,actionText:o.actionText,actionGuide:o.actionGuide,camera:_r(n.rootLayout)(n.camera),level:o.level,visible:o.visible})}return y},eB=t=>e=>{if(e.tag==="FixedSize"){const n=e._1<=0||e._2<=0?y:T("Just",e._1/e._2);return()=>n}if(e.tag==="AutoSize"){const n=xs(t);return()=>{const r=n();return r.width<=0||r.height<=0?y:T("Just",r.width/r.height)}}c()},ws=t=>e=>n=>r=>o=>i=>a=>s=>u=>g=>_=>f=>()=>{const l=a2(),d=_.value,h=g.value,m=d===0?0:l-d,p=h+m;_.value=l,g.value=p;const x=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const S=xs(t)();return{w:S.width<=0?200:S.width,h:S.height<=0?180:S.height}}c()})();if(x.w<200||x.h<180){if(hP(t)(x.w)(x.h)(200)(180)(),e==="CanvasRenderer")return Eg(ys(t),0);if(e==="SvgRenderer")return;c()}const J=a.value,w=(()=>{if(J.tag==="Just"&&J._1.w===x.w&&J._1.h===x.h)return J._1.schedule;const S={widthPx:x.w,heightPx:x.h},v=S.heightPx===i.cameraViewport.heightPx&&S.widthPx===i.cameraViewport.widthPx?i:MS(S)(i);return a.value=T("Just",{w:x.w,h:x.h,schedule:v}),v})(),N=Rg(f)(w.totalDuration),L=PP(p)(FN(w)(N)),C=u.value,R=(()=>{if(C.tag==="Nothing")return L.camera;if(C.tag==="Just")return Kx(i.cameraConfig.cameraDecay)(m)(C._1)(L.camera);c()})();u.value=T("Just",R);const P={...L,camera:R,levels:K(_2(R))(L.levels)};BP(t)(x)(P)();const I=r2("data-mg-debug-camera")(t)(),U=(()=>{if(I.tag==="Nothing")return!1;if(I.tag==="Just")return!0;c()})()?tB(w)(N)(P):y;if(e==="CanvasRenderer"){const S=ys(t),v=p1({width:0,height:0})(P),F=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const V=xs(t)();return{w:V.width,h:V.height<=0?v.vw<=0?V.width:V.width*v.vh/v.vw:V.height}}c()})(),H=i2(),M=F.w*H,q=F.h*H,$=_f(S)(),B=ff(S)(),D=lf(S)(M);$!==M&&D();const Q=df(S)(q);B!==q&&Q(),n.tag==="FixedSize"?(Lg(t,"width",ue(he(Kn(F.w)))+"px"),Lg(t,"height",ue(he(Kn(F.h)))+"px")):n.tag==="AutoSize"||c();const O=cf(S)();gr(O)(),Ca(O)({scaleX:H,scaleY:H})();const z=s.value,Y=j5(r)(o)(O)({width:F.w,height:F.h})(P)(m)(z)();return s.value=Y,cr(O)(),U.tag==="Just"?(gr(O)(),Ca(O)({scaleX:H,scaleY:H})(),ZP(O)(F.w)(F.h)(p1({width:F.w,height:F.h})(P))(U._1)(),cr(O)()):U.tag==="Nothing"||c(),Eg(S,bN(P.portalState))}if(e==="SvgRenderer"){const S=s.value,v=eB(t)(n)(),F=BS(v)(r)(o)(P)(m)(S);s.value=F.springs,Cn("viewBox")(F.parts.viewBox)(t)(),Cn("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(Cn("width")(ue(he(Kn(n._1))))(t)(),Cn("height")(ue(he(Kn(n._2))))(t)()):n.tag==="AutoSize"||c();const H=jP(F.parts.vw/Fo(1)(x.w))({vx:F.parts.vx,vy:F.parts.vy,vw:F.parts.vw,vh:F.parts.vh});return Js((()=>{if(U.tag==="Nothing")return F.parts.body+"";if(U.tag==="Just")return F.parts.body+H(U._1);c()})(),t)}c()},nB=t=>{const e=mm(t)(gm)._1;if(e.tag==="Left")return zt("Left",e._1.msg);if(e.tag==="Right")return zt("Right",e._1);c()},d2=t=>{const e=l6(t);if(e.tag==="Left")return zt("Left",e._1);if(e.tag==="Right"){if(e._1.mode==="SequenceSurface"){const r=GP(e._1);if(r.tag==="Left")return zt("Left",r._1);if(r.tag==="Right")return zt("Right",u2("LoadedSequence",r._1));c()}const n=nB(e._1);if(n.tag==="Left")return zt("Left",n._1);if(n.tag==="Right")return zt("Right",u2("LoadedAnimation",n._1))}c()},rB=t=>{const e=d2(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return ba;c()},h2=t=>e=>n=>r=>{const o=n+1e-4>=e?_t(a=>a.time>e+1e-4&&a.time<=n+1e-4,t):[..._t(a=>a.time>e+1e-4,t),..._t(a=>a.time<=n+1e-4,t)],i=n<=e+1e-4?re(_t(a=>a.time<e-1e-4&&a.time>=n-1e-4,t)):[...re(_t(a=>a.time<e-1e-4,t)),...re(_t(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},oB=t=>e=>n=>r=>te(o=>oe(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),iB=t=>e=>n=>r=>{const o=_t(a=>oe(s=>s===a.kind,e)&&(a.time<n-1e-4||(()=>{const s=a.time-n;return(s<0?-s<=1e-4:s<=1e-4)&&a.index<r})()),t),i=o.length-1|0;return i>=0&&i<o.length?T("Just",o[i]):y},$1=t=>e=>n=>{const r=Gn(e,y,Yt);if(r.tag==="Just"){const o=Gn(r._1.speed,y,Yt);if(o.tag==="Just"){const i=Fo(1e-4)(o._1<0?-o._1:o._1);return()=>t.value=i}if(o.tag==="Nothing"){const i=Gn(r._1.duration,y,Yt);if(i.tag==="Just"&&n.tag==="Just"){const a=n._1/i._1,s=Fo(1e-4)(a<0?-a:a);if(i._1>0)return()=>t.value=s}return()=>{}}c()}if(r.tag==="Nothing")return()=>{};c()},aB=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,g=Gn(t,y,Yt);if(g.tag==="Just"){const _=Gn(g._1.direction,y,Yt);if(_.tag==="Just"){if(_._1==="forward")return i||u?T("Just",1):y;if(_._1==="backward"||_._1==="reverse")return i||a?T("Just",-1):y}return T("Just",s)}if(g.tag==="Nothing")return T("Just",s);c()},sB=t=>e=>n=>r=>o=>i=>()=>{const a={value:1};let s=1,u=!0,g=y,_=-1,f=!0,l=!1,d=0,h=0;const m={value:W},p={value:y},x={value:0},J={value:0},w={value:y};let N=!1,L=()=>{},C=[],R=[],P=[];if(ws(t)(n)(r)(o)(i)(e)(w)(m)(p)(x)(J)(0)(),n==="CanvasRenderer"&&e.dives.length!==0){const z=ys(t);Eg(z,.01),Eg(z,0)}const I=z=>{const Y=z.index;return()=>{_=Y;const V=R;return Bi(X=>X(z))(V)()}},U=z=>()=>{const Y=C,V=f,X={time:z,keyframe:H1(e)(z),playing:V};return Bi(Z=>Z(X))(Y)()},S=()=>(f=!1,g=y,U(d)()),v=z=>()=>(d=z,ws(t)(n)(r)(o)(i)(e)(w)(m)(p)(x)(J)(z)(),U(z)()),F=z=>{const Y=Fo(0)(Rg(e.totalDuration)(z));return()=>(d=Y,_=YP(e.cues)(Y),h=0,g=y,p.value=y,ws(t)(n)(r)(o)(i)(e)(w)(m)(p)(x)(J)(Y)(),U(Y)())},H=(z,Y,V,X,Z)=>()=>{f=!1,g=y;const nt=d;U(nt)();const rt={reason:z,direction:Y<0?"backward":"forward",targetId:V,targetStep:X,reached:Z,time:nt},ft=P;return Bi(Nt=>Nt(rt))(ft)()},M=IP(e),q=()=>{if(!N){if(l=!1,f){const z=a2(),Y=h;h=z;const V=a.value,X=s,Z=u,nt=g,rt=d,ft=Y===0?rt+0*V*X:rt+(z-Y)*V*X;if(nt.tag==="Just"){const Nt=X>=0?nt._1.cue.time>=rt-1e-4&&nt._1.cue.time<=ft+1e-4:nt._1.cue.time<=rt+1e-4&&nt._1.cue.time>=ft-1e-4,lt=Nt?nt._1.cue.time:Fo(0)(Rg(e.totalDuration)(ft));(X>=0?lt+1e-4<rt:lt>rt+1e-4)&&(p.value=y),v(lt)(),Bi(vt=>I(vt))(h2(e.cues)(rt)(lt)(X))();const mt=H("target",X,nt._1.targetId,nt._1.targetStep,!0);Nt&&mt(),Nt||$()}else if(nt.tag==="Nothing"){const Nt=X>=0?e.totalDuration:0,lt=!Z&&(X>=0?Nt>=rt-1e-4&&Nt<=ft+1e-4:Nt<=rt+1e-4&&Nt>=ft-1e-4),mt=Z?SP(ft)(e.totalDuration+.8):Fo(0)(Rg(e.totalDuration)(ft));(X>=0?mt+1e-4<rt:mt>rt+1e-4)&&(p.value=y),v(mt)(),Bi(Ht=>I(Ht))(h2(e.cues)(rt)(mt)(X))();const vt=H("boundary",X,"","",!0);lt&&vt(),lt||$()}else c()}if(M&&!f){const z=d;return ws(t)(n)(r)(o)(i)(e)(w)(m)(p)(x)(J)(z)(),$()}}},$=()=>{if(!N&&!l){l=!0;const z=F1();M1(q)(z)()}},B=()=>(h=0,f=!0,$()),D=()=>(s=1,u=!0,g=y,B(),U(d)()),Q=(z,Y)=>()=>{const V=d;return s=z,u=!1,g=y,$1(a)(Y)(T("Just",z>=0?e.totalDuration-V:V))(),B()},O=(z,Y)=>()=>{const V=d,X=_,Z=aB(Y)(V)(X)(z);if(Z.tag==="Nothing")return Q(f2(Y)(1),Y)();if(Z.tag==="Just"){const nt=z.time-V,rt=nt<0?-nt:nt;return s=Z._1,u=!1,g=T("Just",{cue:z,direction:Z._1,targetId:z.id,targetStep:z.name}),$1(a)(Y)(T("Just",rt))(),rt<=1e-4?(F(z.time)(),I(z)(),H("target",Z._1,z.id,z.name,!0)()):B()}c()};return L=o2(t)(()=>{if(!N){const z=d;return ws(t)(n)(r)(o)(i)(e)(w)(m)(p)(x)(J)(z)(),U(z)()}})(),B(),{play:D,playWith:z=>{const Y=f2(z)(1);return()=>(s=Y,u=HP(z)(!1),g=y,$1(a)(z)(y)(),B(),U(d)())},pause:S,toggle:()=>f?S():D(),seek:z=>F(z),seekCue:z=>{const Y=te(V=>V.id===z)(e.cues);if(Y.tag==="Nothing")return()=>{};if(Y.tag==="Just"){const V=Y._1,X=F(V.time);return()=>(X(),I(V)())}c()},seekStep:z=>{const Y=te(V=>V.kind==="step"&&V.name===z)(e.cues);if(Y.tag==="Nothing")return()=>{};if(Y.tag==="Just"){const V=Y._1,X=F(V.time);return()=>(X(),I(V)())}c()},playToCue:z=>Y=>{const V=te(X=>X.id===z)(e.cues);if(V.tag==="Nothing")return()=>{};if(V.tag==="Just")return O(V._1,Y);c()},playToStep:z=>Y=>{const V=te(X=>X.kind==="step"&&X.name===z)(e.cues);if(V.tag==="Nothing")return()=>{};if(V.tag==="Just")return O(V._1,Y);c()},playNext:z=>()=>{const Y=d,V=_,X=oB(e.cues)(c2(z)(["step"]))(Y)(V);if(X.tag==="Nothing")return Q(1,z)();if(X.tag==="Just")return O(X._1,z)();c()},playPrevious:z=>()=>{const Y=d,V=_,X=iB(e.cues)(c2(z)(["step"]))(Y)(V);if(X.tag==="Nothing")return Q(-1,z)();if(X.tag==="Just")return O(X._1,KP(z)(-1))();c()},setSpeed:z=>{const Y=Fo(1e-4)(z<0?-z:z);return()=>a.value=Y},currentTime:()=>d,currentKeyframe:()=>{const z=d;return H1(e)(z)},isPlaying:()=>f,duration:e.totalDuration,cues:e.cues,steps:_t(z=>z.kind==="step",e.cues),subscribe:z=>()=>{C=Et(C)(z);const Y=d,V=f;z({time:Y,keyframe:H1(e)(Y),playing:V})();const X=Ta(Z=>!kg(Z)(z));return()=>{C=X(C)}},subscribeCue:z=>()=>{R=Et(R)(z);const Y=Ta(V=>!kg(V)(z));return()=>{R=Y(R)}},subscribeComplete:z=>()=>{P=Et(P)(z);const Y=Ta(V=>!kg(V)(z));return()=>{P=Y(P)}},destroy:()=>{if(N=!0,L(),n==="CanvasRenderer")return TP(ys(t));n!=="SvgRenderer"&&c()}}},uB=t=>e=>{const n=n2(t);return()=>{const r=n();e2(r)("markgraf-embed")();const o=EP(t)();return Js(RP,t),qr(t)("stage")(i=>{const a=XP(i)(W1)(e);return()=>{const s=F1();M1(()=>{const u=a();if(u.tag==="Left")return gf("[markgraf] precompute failed")();if(u.tag==="Right"){const g=sB(i)(u._1.schedule)(LP)(W1)(o)(wS)();return VP(t)(u._1.schedule)(g)()}c()})(s)()}})()}},p2=t=>e=>{const n=d2(e);if(n.tag==="Left")return gf("[markgraf] parse failed: "+n._1);if(n.tag==="Right"){if(n._1.tag==="LoadedAnimation")return uB(t)(n._1._1);if(n._1.tag==="LoadedSequence")return OP(t)(n._1._1)}c()},gB=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 Vr=null;const Pg=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",cB=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{Pg(t)?(Vr&&Vr!==t&&Pg(Vr)&&Vr.querySelector('[data-mg="play"]').click(),Vr=t):Vr===t&&(Vr=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},_B=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=gB(t),n=t.dataset.markgrafPaused==="true";t.textContent="",p2(t)(e)(),t.querySelector('[data-mg="play"]')&&(n?Pg(t)&&t.querySelector('[data-mg="play"]').click():Vr===null?Vr=t:Pg(t)&&t.querySelector('[data-mg="play"]').click(),cB(t))},Bg=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(_B)},m2=()=>{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||Vr||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=rB(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>p2(e)(n)(),mountAll:Bg,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{Bg(),m2()}):(Bg(),m2())}return Gg.mountAll=Bg,Object.defineProperty(Gg,Symbol.toStringTag,{value:"Module"}),Gg})({});
|