@markgrafhq/markgraf-embed 0.0.25 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/markgraf-embed.css +3 -1
- package/dist/markgraf-embed.js +29 -20
- package/package.json +1 -1
package/dist/markgraf-embed.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
var
|
|
2
|
-
`:return"\\n";case"\r":return"\\r";case" ":return"\\t";case"\v":return"\\v"}var i=r+1,o=i<e&&t[i]>="0"&&t[i]<="9"?"\\&":"";return"\\"+n.charCodeAt(0).toString(10)+o})+'"'},Qu=t=>t,me=Qu("LT"),ye=Qu("GT"),Ie=Qu("EQ"),T=(t,e)=>({tag:t,_1:e}),J=T("Nothing"),Zt=t=>T("Just",t),ja=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;g()},Za=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;g()},Gt=(t,e)=>({tag:t,_1:e}),ud=t=>Gt("Right",t),sd={map:t=>e=>{if(e.tag==="Left")return Gt("Left",e._1);if(e.tag==="Right")return Gt("Right",t(e._1));g()}},tc={apply:t=>e=>{if(t.tag==="Left")return Gt("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Gt("Left",e._1);if(e.tag==="Right")return Gt("Right",t._1(e._1))}g()},Functor0:()=>sd},ad={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Gt("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}g()},Apply0:()=>tc},cd={pure:ud,Apply0:()=>tc},ec={Applicative0:()=>cd,Bind1:()=>ad},gd=t=>t,fd={map:t=>e=>t(e)},nc={apply:t=>e=>t(e),Functor0:()=>fd},_d={bind:t=>e=>e(t),Apply0:()=>nc},dd={pure:gd,Apply0:()=>nc},Vn={Applicative0:()=>dd,Bind1:()=>_d},ld=function(t){return function(){return t}},hd={apply:t=>e=>()=>{const n=t(),r=e();return Du.pure(n(r))()},Functor0:()=>pd},Du={pure:ld,Apply0:()=>hd},pd={map:t=>e=>()=>{const n=e();return t(n)}},gi=(t,e)=>({tag:t,_1:e}),rc=t=>gi("Loop",t),md={tailRecM:t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="Loop"){r=t(u._1);continue}if(u.tag==="Done"){i=!1,o=u._1;continue}g()}return o};return n=>e(t(n))},Monad0:()=>Vn},yd=function(t){return function(e){return function(){return t(e())}}},xd=function(t){return function(){return t}},Nd={map:yd},Jd={apply:t=>e=>()=>{const n=t(),r=e();return ic.pure(n(r))()},Functor0:()=>Nd},ic={pure:xd,Apply0:()=>Jd},wd=(function(t){return function(e){return function(n){return function(){return t(e,n)}}}})(function(t,e){return e.push(t)}),Td=(t,e)=>({tag:"Iterator",_1:t,_2:e}),vd=t=>e=>n=>()=>{let r=!1;const i=e._2;for(;!r;){const o=i.value,u=e._1(o);if(u.tag==="Just"&&t(u._1)){n.push(u._1),e._2.value;const s=e._2.value;e._2.value=s+1|0;continue}r=!0}},bd=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const i=r.value,o=r.value;r.value=o+1|0;const u=t._1(i);if(u.tag==="Just"){e(u._1)();continue}if(u.tag==="Nothing"){n=!0;continue}g()}},Qr=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=i-1;o>=0;o--)r=t(n[o])(r);return r}}},w=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=0;o<i;o++)r=t(r)(n[o]);return r}}},Fu=t=>{const e=t.Apply0();return n=>r=>n.foldr(i=>{const o=r(i);return u=>e.apply(e.Functor0().map(s=>Ka)(o))(u)})(t.pure())},oc=t=>{const e=Fu(t);return n=>{const r=e(n);return i=>o=>r(o)(i)}},Bt={foldr:Qr,foldl:w,foldMap:t=>{const e=t.mempty;return n=>Bt.foldr(r=>i=>t.Semigroup0().append(n(r))(i))(e)}},L=(t,e)=>({tag:"Tuple",_1:t,_2:e}),ln=t=>e=>L(t,e),to=t=>t._2,eo=t=>t._1,Ft=function(t){return function(e){for(var n=e.length,r=Array(n),i=0;i<n;i++)r[i]=t(i)(e[i]);return r}};var zu=function(t){return function(e){return t===e}};const Ld=zu,kd=zu,fi=zu,Bu=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}}},hn={eq:fi},Ed={eq:kd},Dr={eq:Ld};var Mu=function(t){return function(e){return function(n){return function(r){return function(i){return r<i?t:r===i?e:n}}}}};const Sd=Mu,Cd=Mu,G={compare:Mu(me)(Ie)(ye),Eq0:()=>hn},rt={compare:Cd(me)(Ie)(ye),Eq0:()=>Ed},nt={compare:Sd(me)(Ie)(ye),Eq0:()=>Dr},Gd=function(t){return t},Pd=(function(){function t(i){return[i]}function e(i){return function(o){return[i,o]}}function n(i){return function(o){return function(u){return[i,o,u]}}}function r(i){return function(o){return i.concat(o)}}return function(i){return function(o){return function(u){return function(s){return function(a){function c(f,d){switch(d-f){case 0:return u([]);case 1:return o(t)(s(a[f]));case 2:return i(o(e)(s(a[f])))(s(a[f+1]));case 3:return i(i(o(n)(s(a[f])))(s(a[f+1])))(s(a[f+2]));default:var l=f+Math.floor((d-f)/4)*2;return i(o(r)(c(f,l)))(c(l,d))}}return c(0,a.length)}}}}}})(),Ad=t=>t,lr={traverse:t=>{const e=t.Apply0();return Pd(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>lr.traverse(t)(Ad),Functor0:()=>id,Foldable1:()=>Bt},zt=function(t,e){for(var n=t>e?-1:1,r=new Array(n*(e-t)+1),i=t,o=0;i!==e;)r[o++]=i,i+=n;return r[o]=i,r};var Id=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},Qd=function(t,e){for(var n=[],r=0,i=0;i<t;i++)n[r++]=e;return n};const Dd=typeof Array.prototype.fill=="function"?Id:Qd,At=(function(){function t(i,o){this.head=i,this.tail=o}var e={};function n(i){return function(o){return new t(i,o)}}function r(i){for(var o=[],u=0,s=i;s!==e;)o[u++]=s.head,s=s.tail;return o}return function(i,o){return r(i(n)(e)(o))}})(),Mt=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},uc=function(t,e,n,r){for(var i=0;i<r.length;i++){var o=n(r[i]);if(e(o))return o}return t},hr=function(t,e,n,r){for(var i=0,o=r.length;i<o;i++)if(n(r[i]))return t(i);return e},sc=function(t,e,n,r,i){if(n<0||n>i.length)return e;var o=i.slice();return o.splice(n,0,r),t(o)},ac=function(t,e,n,r){if(n<0||n>=r.length)return e;var i=r.slice();return i.splice(n,1),t(i)},Un=function(t,e,n,r,i){if(n<0||n>=i.length)return e;var o=i.slice();return o[n]=r,t(o)},ve=function(t){return t.slice().reverse()},Ye=function(t){if(t.length<=1e4)return Array.prototype.concat.apply([],t);for(var e=[],n=0,r=t.length;n<r;n++)for(var i=t[n],o=0,u=i.length;o<u;o++)e.push(i[o]);return e},ut=function(t,e){return e.filter(t)},Fd=function(t,e,n){for(var r=n.length,i=e,o=new Array(r),u=0;u<r;u++)i=t(i)(n[u]),o[u]=i;return o},zd=(function(){function t(e,n,r,i,o,u){var s,a,c,f,d,l,_;for(s=o+(u-o>>1),s-o>1&&t(e,n,i,r,o,s),u-s>1&&t(e,n,i,r,s,u),a=o,c=s,f=o;a<s&&c<u;)d=i[a],l=i[c],_=n(e(d)(l)),_>0?(r[f++]=l,++c):(r[f++]=d,++a);for(;a<s;)r[f++]=i[a++];for(;c<u;)r[f++]=i[c++]}return function(e,n,r){var i;return r.length<2?r:(i=r.slice(0),t(e,n,i,r.slice(0),0,r.length),i)}})(),kt=function(t,e,n){return n.slice(t,e)},be=function(t,e,n){for(var r=e.length<n.length?e.length:n.length,i=new Array(r),o=0;o<r;o++)i[o]=t(e[o])(n[o]);return i},qe=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},cc=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Et=t=>e=>zd(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),Bd=t=>e=>Et(n=>r=>t.compare(e(n))(e(r))),Dt=t=>e=>(()=>{const n=wd(e);return()=>{const r=[...t];return n(r)(),r}})()(),pr=t=>{if(t.length===0)return t.length-1|0,J;const e=t.length-1|0;return e>=0&&e<t.length?T("Just",{init:kt(0,t.length-1|0,t),last:t[e]}):J},Md=t=>e=>n=>t>=0&&t<n.length?Un(Zt,J,t,e(n[t]),n):J,mr=t=>e=>{const n=(r=>{let i=r,o=!0,u;for(;o;){const s=i;if(s>=0&&s<e.length){if(t(e[s])){i=s+1|0;continue}o=!1,u=T("Just",s);continue}o=!1,u=J}return u})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:kt(0,n._1,e),rest:kt(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};g()},Fr=t=>e=>{const n=Et(r=>i=>t(r._2)(i._2))(Ft(ln)(e));return 0<n.length?H(to)(Bd(nt)(eo)((()=>{const r=[n[0]];for(const i of n){const o=t((()=>{const u=r.length-1|0;if(u>=0&&u<r.length)return r[u]._2;g()})())(i._2);(o==="LT"||o==="GT"||o!=="EQ")&&r.push(i)}return r})())):[]},Wd=t=>e=>{const n=[],r=Td(i=>i>=0&&i<e.length?T("Just",e[i]):J,{value:0});return bd(r)(i=>()=>{const o=[];o.push(i),vd(t(i))(r)(o)(),n.push(o)})(),n},Vt=t=>e=>{const n=hr(Zt,J,t,e);return n.tag==="Just"?T("Just",e[n._1]):J},gc=t=>e=>ut(t,e),He=t=>e=>n=>{const r=hr(Zt,J,i=>t.eq(i)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},fc=t=>e=>Tt(e)(t),xt=t=>fc(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];g()}),_c=isFinite;function Rd(t,e,n,r){var i=parseFloat(t);return e(i)?n(i):r}const yn=Math.abs,qd=Math.acos,yr=function(t){return function(e){return Math.atan2(t,e)}},no=Math.ceil,rn=Math.cos,zr=Math.exp,xn=Math.floor,ro=Math.log,Hd=function(t){return function(e){return Math.min(t,e)}},Wu=function(t){return function(e){return Math.pow(t,e)}},xr=Math.round,Ve=Math.sin,Ce=Math.sqrt,Od=Math.tan,$d=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},et=function(t){return t},Xd=(function(t){return function(e){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var i=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(o){if(i.test(o)){var u=parseInt(o,n);return(u|0)===u?t(u):e}else return e}}}})(Zt)(J)(10),dc=$d(Zt)(J),xe=t=>{if(!_c(t))return 0;if(t>=et(2147483647))return 2147483647;if(t<=et(-2147483648))return-2147483648;const e=dc(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;g()},Xt=(t,e,n)=>({tag:t,_1:e,_2:n}),Ut=Xt("Nil"),Kt={foldr:t=>e=>{const n=Kt.foldl(i=>o=>t(o)(i))(e),r=(i=>o=>{let u=i,s=o,a=!0,c;for(;a;){const f=u,d=s;if(d.tag==="Nil"){a=!1,c=f;continue}if(d.tag==="Cons"){u=Xt("Cons",d._1,f),s=d._2;continue}g()}return c})(Ut);return i=>n(r(i))},foldl:t=>e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=t(s)(a._1),i=a._2;continue}g()}return u},foldMap:t=>{const e=t.mempty;return n=>Kt.foldl(r=>{const i=t.Semigroup0().append(r);return o=>i(n(o))})(e)}},Yd=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);u.push(n(a));var c=r(a);if(t(c))return u;s=e(c)}}}}}}},Vd=t=>{if(t.tag==="Just")return t._1;g()},Ud={unfoldr1:Yd(ja)(Vd)(eo)(to)},Kd=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);if(t(a))return u;var c=e(a);u.push(n(c)),s=r(c)}}}}}}},jd=t=>{if(t.tag==="Just")return t._1;g()},Ue={unfoldr:Kd(ja)(jd)(eo)(to),Unfoldable10:()=>Ud},Ot=(t,e,n,r,i,o,u)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u}),Ke=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),io=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),lc=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),D=Ot("Leaf"),Nn=Ke("IterLeaf"),ce=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return Ot("Node",1,1,t,e,n,r);if(r.tag==="Node")return Ot("Node",1+r._1|0,1+r._2|0,t,e,n,r);g()}if(n.tag==="Node"){if(r.tag==="Leaf")return Ot("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return Ot("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,t,e,n,r)}g()},Oe=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?Ot("Node",1,1,t,e,D,D):r.tag==="Node"&&r._1>1?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;g()})()?ce(r._5._3,r._5._4,ce(t,e,n,r._5._5),ce(r._3,r._4,r._5._6,r._6)):ce(r._3,r._4,ce(t,e,n,r._5),r._6):ce(t,e,n,r);if(n.tag==="Node")return r.tag==="Node"?r._1>(n._1+1|0)?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;g()})()?ce(r._5._3,r._5._4,ce(t,e,n,r._5._5),ce(r._3,r._4,r._5._6,r._6)):ce(r._3,r._4,ce(t,e,n,r._5),r._6):n._1>(r._1+1|0)?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?ce(n._6._3,n._6._4,ce(n._3,n._4,n._5,n._6._5),ce(t,e,n._6._6,r)):ce(n._3,n._4,n._5,ce(t,e,n._6,r)):ce(t,e,n,r):r.tag==="Leaf"&&n._1>1?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?ce(n._6._3,n._6._4,ce(n._3,n._4,n._5,n._6._5),ce(t,e,n._6._6,r)):ce(n._3,n._4,n._5,ce(t,e,n._6,r)):ce(t,e,n,r);g()},Br=(t,e,n)=>{if(n.tag==="Leaf")return io(J,D,D);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const i=Br(t,e,n._5);return io(i._1,i._2,Oe(n._3,n._4,i._3,n._6))}if(r==="GT"){const i=Br(t,e,n._6);return io(i._1,Oe(n._3,n._4,n._5,i._2),i._3)}if(r==="EQ")return io(T("Just",n._4),n._5,n._6)}g()},hc=(t,e,n,r)=>{if(r.tag==="Leaf")return lc(t,e,n);if(r.tag==="Node"){const i=hc(r._3,r._4,r._5,r._6);return lc(i._1,i._2,Oe(t,e,n,i._3))}g()},_i=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=hc(t._3,t._4,t._5,t._6);return Oe(n._1,n._2,n._3,e)}g()},In=(t,e,n)=>{if(e.tag==="Leaf")return D;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=Br(t,n._3,e);return _i(In(t,r._2,n._5),In(t,r._3,n._6))}g()},oo=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return D;if(r.tag==="Node"){const i=Br(t,r._3,n),o=oo(t,e,i._2,r._5),u=oo(t,e,i._3,r._6);if(i._1.tag==="Just")return Oe(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return _i(o,u)}g()},Ge=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const i=Br(t,r._3,n),o=Ge(t,e,i._2,r._5),u=Ge(t,e,i._3,r._6);if(i._1.tag==="Just")return Oe(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return Oe(r._3,r._4,o,u)}g()},Zd=t=>e=>{const n=r=>{if(r.tag==="Leaf")return D;if(r.tag==="Node"){const i=e(r._3)(r._4);if(i.tag==="Just")return Oe(r._3,i._1,n(r._5),n(r._6));if(i.tag==="Nothing")return _i(n(r._5),n(r._6))}g()};return n},Jn=(t=>e=>n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="IterLeaf"){i=!1,o=e();continue}if(u.tag==="IterEmit"){i=!1,o=t(u._1,u._2,u._3);continue}if(u.tag==="IterNode"){r=(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Leaf"){d=!1,l=_;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){c=Ke("IterEmit",h._3,h._4,_),f=h._5;continue}c=Ke("IterEmit",h._3,h._4,Ke("IterNode",h._6,_)),f=h._5;continue}g()}return l})(u._2)(u._1);continue}g()}return o})((t,e,n)=>T("Just",L(L(t,e),n)))(t=>J),bt=t=>e=>n=>r=>{const i=o=>{if(o.tag==="Leaf")return Ot("Node",1,1,n,r,D,D);if(o.tag==="Node"){const u=t.compare(n)(o._3);if(u==="LT")return Oe(o._3,o._4,i(o._5),o._6);if(u==="GT")return Oe(o._3,o._4,o._5,i(o._6));if(u==="EQ")return Ot("Node",o._1,o._2,n,e(o._4)(r),o._5,o._6)}g()};return i},Z=t=>e=>n=>{const r=i=>{if(i.tag==="Leaf")return Ot("Node",1,1,e,n,D,D);if(i.tag==="Node"){const o=t.compare(e)(i._3);if(o==="LT")return Oe(i._3,i._4,r(i._5),i._6);if(o==="GT")return Oe(i._3,i._4,i._5,r(i._6));if(o==="EQ")return Ot("Node",i._1,i._2,e,n,i._5,i._6)}g()};return r},te=t=>e=>e.foldl(n=>r=>Z(t)(r._1)(r._2)(n))(D),di=t=>e=>{const n=r=>{if(r.tag==="Leaf")return D;if(r.tag==="Node"){const i=t.compare(e)(r._3);if(i==="LT")return Oe(r._3,r._4,n(r._5),r._6);if(i==="GT")return Oe(r._3,r._4,r._5,n(r._6));if(i==="EQ")return _i(r._5,r._6)}g()};return n},pc=t=>{const e=t.compare;return n=>r=>i=>{const o=Br(e,r,i),u=n(o._1);if(u.tag==="Nothing")return _i(o._2,o._3);if(u.tag==="Just")return Oe(r,u._1,o._2,o._3);g()}},se=function(t){return function(e){return t+e|0}},Mr=function(t){return function(e){return t+e}},Kn=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},tl=function(t){return function(e){return t+e}},ne=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},el={append:tl},nl={append:ne},rl={mempty:"",Semigroup0:()=>el},il={mempty:[],Semigroup0:()=>nl},ol=null;function mc(t,e,n){return t==null?e:n(t)}function Kb(t){return t}function Ru(t){return function(e){return function(n){return t.apply(n,[e])}}}const ul=Ru(Number.prototype.toPrecision),sl=Ru(Number.prototype.toFixed),al=Ru(Number.prototype.toExponential),li=(t,e)=>({tag:t,_1:e}),hi=t=>e=>n=>{const r=nt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=nt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},pi=t=>{if(t.tag==="Precision")return ul(t._1);if(t.tag==="Fixed")return sl(t._1);if(t.tag==="Exponential")return al(t._1);g()},yc=function(t){return function(){console.log(t)}};function cl(){return Date.now()}function gl(t){return function(){return t.getContext("2d")}}function fl(t){return function(){return t.width}}function _l(t){return function(){return t.height}}function dl(t){return function(e){return function(){t.width=e}}}function ll(t){return function(e){return function(){t.height=e}}}function qu(t){return function(e){return function(){t.lineWidth=e}}}function hl(t){return function(e){return function(){t.fillStyle=e}}}function pl(t){return function(e){return function(){t.strokeStyle=e}}}function Hu(t){return function(e){return function(){t.lineCap=e}}}function Ou(t){return function(e){return function(){t.lineJoin=e}}}function ml(t){return function(e){return function(){t.globalCompositeOperation=e}}}function yl(t){return function(e){return function(){t.globalAlpha=e}}}function xc(t){return function(){t.beginPath()}}function $u(t){return function(){t.stroke()}}function Xu(t){return function(){t.fill()}}function xl(t){return function(){t.clip()}}function mi(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function Nc(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function Jc(t){return function(){t.closePath()}}function Nl(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function Jl(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function uo(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function Yu(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function wl(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function Tl(t){return function(e){return function(){t.textAlign=e}}}function vl(t){return function(e){return function(){t.textBaseline=e}}}function bl(t){return function(e){return function(){t.font=e}}}function Ll(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function jn(t){return function(){t.save()}}function Zn(t){return function(){t.restore()}}function yi(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function kl(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const wc=t=>t,Vu=t=>t,Uu=t=>t,Ku=t=>t,so=t=>t,El=so("BaselineTop"),Sl=so("BaselineMiddle"),Cl=so("BaselineAlphabetic"),Gl=so("BaselineBottom"),Pl=Ku("AlignLeft"),Al=Ku("AlignRight"),Il=Ku("AlignCenter"),ju=Uu("BevelJoin"),ao=Uu("RoundJoin"),Zu=Uu("MiterJoin"),ts=Vu("Round"),es=Vu("Square"),ns=Vu("Butt"),Ql=wc("SourceOver"),Dl=wc("Difference"),Fl=t=>e=>vl(t)((()=>{if(e==="BaselineTop")return"top";if(e==="BaselineHanging")return"hanging";if(e==="BaselineMiddle")return"middle";if(e==="BaselineAlphabetic")return"alphabetic";if(e==="BaselineIdeographic")return"ideographic";if(e==="BaselineBottom")return"bottom";g()})()),zl=t=>e=>Tl(t)((()=>{if(e==="AlignLeft")return"left";if(e==="AlignRight")return"right";if(e==="AlignCenter")return"center";if(e==="AlignStart")return"start";if(e==="AlignEnd")return"end";g()})()),co=t=>e=>{if(e==="BevelJoin")return Ou(t)("bevel");if(e==="RoundJoin")return Ou(t)("round");if(e==="MiterJoin")return Ou(t)("miter");g()},rs=t=>e=>{if(e==="Round")return Hu(t)("round");if(e==="Square")return Hu(t)("square");if(e==="Butt")return Hu(t)("butt");g()},Tc=t=>e=>ml(t)((()=>{if(e==="SourceOver")return"source-over";if(e==="SourceIn")return"source-in";if(e==="SourceOut")return"source-out";if(e==="SourceAtop")return"source-atop";if(e==="DestinationOver")return"destination-over";if(e==="DestinationIn")return"destination-in";if(e==="DestinationOut")return"destination-out";if(e==="DestinationAtop")return"destination-atop";if(e==="Lighter")return"lighter";if(e==="Copy")return"copy";if(e==="Xor")return"xor";if(e==="Multiply")return"multiply";if(e==="Screen")return"screen";if(e==="Overlay")return"overlay";if(e==="Darken")return"darken";if(e==="Lighten")return"lighten";if(e==="ColorDodge")return"color-dodge";if(e==="ColorBurn")return"color-burn";if(e==="HardLight")return"hard-light";if(e==="SoftLight")return"soft-light";if(e==="Difference")return"difference";if(e==="Exclusion")return"exclusion";if(e==="Hue")return"hue";if(e==="Saturation")return"saturation";if(e==="Color")return"color";if(e==="Luminosity")return"luminosity";g()})()),vc={foldrWithIndex:t=>e=>{const n=Qr(i=>{const o=i._1,u=i._2;return s=>t(o)(u)(s)})(e),r=Ft(ln);return i=>n(r(i))},foldlWithIndex:t=>e=>{const n=w(i=>o=>t(o._1)(i)(o._2))(e),r=Ft(ln);return i=>n(r(i))},foldMapWithIndex:t=>{const e=t.mempty;return n=>vc.foldrWithIndex(r=>i=>o=>t.Semigroup0().append(n(r)(i))(o))(e)},Foldable0:()=>Bt},$e={foldr:t=>e=>{const n=Kt.foldr(t)(e);return r=>n((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,Xt("Cons",o._3,i(o._6,u)));g()};return i(r,Ut)})())}},Bl=t=>{const e={append:(()=>{const n=t.compare;return r=>i=>Ge(n,Se,r,i)})()};return{mempty:D,Semigroup0:()=>e}},xi=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},Nr=function(t){return t.join("")},Jr=function(t){return t.split("")},go=function(t){return t},tr=function(t){return t.length},bc=function(t){return function(e){return e.substr(0,t)}},Ni=function(t){return function(e){return e.substring(t)}},Ml=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},Wl=t=>e=>{const n=Ml(tr(t))(e);return n.before===t?T("Just",n.after):J},Rl=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},ql=function(t){return t()},Hl=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},Ol=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},wr=t=>BigInt(t),$l=t=>Number(t),fo=t=>e=>t+e,_o=t=>e=>t*e,is=t=>e=>t-e,Lc=0n,lo=1n,kc=t=>e=>t^e,Ji=t=>e=>t&e,os=t=>e=>t<<e,us=t=>e=>t>>e,Xl=t=>e=>t==e,Yl=t=>e=>t===e?0:t>e?1:-1,Vl={eq:Xl},Ec={compare:t=>e=>{const n=Yl(t)(e);return n===1?ye:n===0?Ie:me},Eq0:()=>Vl},Ul=Hl(Zt)(J),Kl=Ol(Zt)(J),Sc=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=rt.compare(e._1)(n._1);return r==="LT"?me:r==="GT"?ye:rt.compare(e._2)(n._2)},Eq0:()=>t}})(),jl=t=>e=>yn(t._1-e._1)+yn(t._2-e._2),Tr=t=>t,ho=t=>t,de=ho("North"),le=ho("South"),Qn=ho("East"),Dn=ho("West"),er=Tr("Rectangle"),Zl=Tr("Cylinder"),th=Tr("Parallelogram"),eh=Tr("Diamond"),nh=Tr("Ellipse"),rh=Tr("Document"),ih=Tr("Cloud"),Cc=t=>t,Gc=w(Mr)(0),oh=t=>e=>n=>{const r=rt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=rt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},nr=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},po=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Pc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},uh=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}]},wi=t=>e=>{const n=be(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,c=s.x-u.x;return Ce(c*c+a*a)})()}),t,kt(1,t.length,t)),r=Gc(H(u=>u.len)(n)),i=oh(0)(r)(e*r),o=u=>s=>a=>{let c=u,f=s,d=a,l=!0,_;for(;l;){const h=c,p=f,m=d,y=Mt(x=>J,x=>N=>T("Just",{head:x,tail:N}),h);if(y.tag==="Nothing"){const x=t.length-1|0;if(x>=0&&x<t.length){l=!1,_=t[x];continue}l=!1,_=m;continue}if(y.tag==="Just"){if(p<=y._1.head.len){const x=y._1.head.len<=0?0:p/y._1.head.len;l=!1,_={x:y._1.head.a.x+(y._1.head.b.x-y._1.head.a.x)*x,y:y._1.head.a.y+(y._1.head.b.y-y._1.head.a.y)*x};continue}c=y._1.tail,f=p-y._1.head.len,d=m;continue}g()}return _};return 0<t.length?T("Just",o(n)(i)(t[0])):J},sh=t=>e=>{const n=nr(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}},mo=t=>Gc(be(e=>n=>{const r=n.y-e.y,i=n.x-e.x;return Ce(i*i+r*r)},t,kt(1,t.length,t))),ah=t=>e=>{const n=nr(4)(.15*po(e.w)(e.h)),r=nr(1)(t.w),i=nr(1)(t.h),o=nr(1)(e.w-2*n),u=nr(1)(e.h-2*n),s=po(o/r)(u/i);return{scale:s,tx:e.x+n+(o-r*s)/2-t.x*s,ty:e.y+n+(u-i*s)/2-t.y*s}},ss={scale:1,tx:0,ty:0},Ne=t=>{const e=Mt(n=>J,n=>r=>T("Just",{head:n,tail:r}),[...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Xt("Cons",r._4,n(r._6,i)));g()};return Tt(At(Kt.foldr,n(t.nodes,Ut)))(uh)})(),...Ye((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Xt("Cons",r._4,n(r._6,i)));g()};return At(Kt.foldr,n(t.edges,Ut))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=w(r=>i=>({minX:po(r.minX)(i.x),minY:po(r.minY)(i.y),maxX:nr(r.maxX)(i.x),maxY:nr(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},ch=t=>e=>(n=>r=>i=>{let o=n,u=r,s=i,a=!0,c;for(;a;){const f=o,d=u,l=s,_=Mt(h=>J,h=>p=>T("Just",{head:h,tail:p}),d);if(_.tag==="Nothing"){a=!1,c=l;continue}if(_.tag==="Just"){const h=Pc(_._1.head)(f.interiors);if(h.tag==="Nothing"){a=!1,c=l;continue}if(h.tag==="Just"){o=h._1,u=_._1.tail,s=(()=>{const p=ah(Ne(h._1.layout))((()=>{const m=Pc(_._1.head)(f.layout.nodes);if(m.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:er};if(m.tag==="Just")return m._1;g()})());return{scale:l.scale*p.scale,tx:l.scale*p.tx+l.tx,ty:l.scale*p.ty+l.ty}})();continue}}g()}return c})(t)(e)(ss),gh=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fh=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},yo=t=>e=>n=>{const r=rt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=rt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},_h=t=>e=>n=>r=>{const i=Ne(e);return n<=0||r<=0||i.w<=0||i.h<=0?1:t?gh(i.w/n)(i.h/r):fh(i.w/n)(i.h/r)},Ac=t=>e=>n=>{const r=t.widthPx/t.heightPx,i=n.w/n.h;if(t.widthPx<=0||t.heightPx<=0){const u=1/yo(.05)(1)(e);return{w:n.w*u,h:n.h*u}}if(r>i){const u=1/yo(.05)(1)(e);return{w:n.h*r*u,h:n.h*u}}const o=1/yo(.05)(1)(e);return{w:n.w*o,h:n.w/r*o}},Ic=t=>e=>n=>r=>i=>{const o=t+i/2,u=t+e-i/2,s=t+e/2,a=n+r/2;return i>=e?s:yo(o)(u)(a)},Qc=t=>e=>n=>r=>{const i=Ne(t);return{x:Ic(i.x)(i.w)(e.x)(e.w)(n),y:Ic(i.y)(i.h)(e.y)(e.h)(r)}},Dc=t=>e=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:_h(t)(e)(n.w)(n.h)}),dh=t=>e=>n=>r=>{const i={x:r.x-t.padding,y:r.y-t.padding,w:r.w+t.padding*2,h:r.h+t.padding*2},o=Ac(e)(.65)(i),u=Qc(n)(i)(o.w)(o.h),s={x:u.x-o.w/2,y:u.y-o.h/2,w:o.w,h:o.h};return{focus:r,paddedFocus:i,viewport:s,camera:Dc(e.widthPx>0&&e.heightPx>0)(n)(s)}},lh=t=>e=>n=>r=>i=>o=>{const u=Ne(r),s={x:u.x*i.scale+i.tx,y:u.y*i.scale+i.ty,w:u.w*i.scale,h:u.h*i.scale},a=t.padding*i.scale,c={x:s.x-a,y:s.y-a,w:s.w+a*2,h:s.h+a*2},f=Ac(e)(.7)(c),d=Qc(n)(c)(f.w)(f.h),l={x:d.x-f.w/2,y:d.y-f.h/2,w:f.w,h:f.h};return{footprint:s,viewport:l,camera:Dc(e.widthPx>0&&e.heightPx>0)(n)(l)}},Fc=t=>t,zc=(t,e)=>({tag:t,_1:e}),as=t=>t,Ti=(t,e)=>({tag:t,_1:e}),cs=(t,e)=>({tag:t,_1:e}),vi=as("Animated"),hh=as("StaticStill"),ph=as("TitleCard"),mh=cs("First"),yh=Fc("Forward"),xh=Fc("Backward"),Nh=Ti("ExitNode"),Bc=te(G)(Bt),Jh=t=>Qr(e=>n=>({nodes:Ge(G.compare,Se,e.nodes,n.nodes),edges:Ge(G.compare,Se,e.edges,n.edges)}))({nodes:D,edges:D})(t.keyframes),wh=t=>e=>({entering:{nodes:In(G.compare,e.nodes,t.nodes),edges:In(G.compare,e.edges,t.edges)},leaving:{nodes:In(G.compare,t.nodes,e.nodes),edges:In(G.compare,t.edges,e.edges)},surviving:{nodes:oo(G.compare,Se,t.nodes,e.nodes),edges:oo(G.compare,Se,t.edges,e.edges)}}),xo=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Wr=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},No=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},gs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Th=w(t=>e=>Z(G)(e)()(t))(D),vh=w(t=>e=>Z(G)(e)()(t))(D),bh=(()=>{const t=Ue.unfoldr(Jn);return e=>t(Ke("IterNode",e,Nn))})(),Mc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Wc=te(G)(Bt),Rc=t=>{const e=Mt(n=>J,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=w(r=>i=>({minX:xo(r.minX)(i.x),minY:xo(r.minY)(i.y),maxX:Wr(r.maxX)(i.x),maxY:Wr(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},Lh=t=>e=>n=>Th(Tt(At($e.foldr,n))(r=>{const i=No(r)(t);if(i.tag==="Just")return ut(o=>!gs(o)(e),[i._1.source,i._1.target]);if(i.tag==="Nothing")return[];g()})),kh=t=>t.kind.tag==="SendToken"?T("Just",L(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):J,Eh=t=>t.tag==="DataFlow"?xt(kh)(t._1.events):[],Sh=t=>e=>vh(xt(n=>gs(n._2.source)(e)||gs(n._2.target)(e)?T("Just",n._1):J)(bh(t))),vr=t=>{const e=Mt(n=>J,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=w(r=>i=>({minX:xo(r.minX)(i.x),minY:xo(r.minY)(i.y),maxX:Wr(r.maxX)(i.x+i.w),maxY:Wr(r.maxY)(i.y+i.h)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x+e._1.head.w,maxY:e._1.head.y+e._1.head.h})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},fs=t=>e=>n=>{if(n.tag==="Leaf")return Ne(t);const r=Sh(e)(n),i=[...xt(o=>{const u=Mc(o)(t.nodes);return u.tag==="Just"?T("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):J})(At($e.foldr,Ge(G.compare,Se,n,Lh(e)(n)(r)))),...xt(o=>{const u=No(o)(t.edges);return u.tag==="Just"?T("Just",Rc(u._1)):J})(At($e.foldr,r))];return i.length===0?Ne(t):vr(i)},qc=t=>e=>n=>{const r=[...xt(i=>i)([(()=>{const i=No(n)(t.edges);return i.tag==="Just"?T("Just",Rc(i._1)):J})()]),...(()=>{const i=No(n)(e);if(i.tag==="Just")return xt(o=>{const u=Mc(o)(t.nodes);return u.tag==="Just"?T("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):J})([i._1.source,i._1.target]);if(i.tag==="Nothing")return[];g()})()];return r.length===0?fs(t)(e)(D):vr(r)},Jo=t=>e=>{const n=Ne(t),r=n.w/Wr(1e-4)(e.zoom),i=n.h/Wr(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-i/2,w:r,h:i}},Ch=t=>Ge(G.compare,Se,Wc(H(e=>L(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),Wc(Tt(t.scenes)(Eh))),wo=t=>t,Gh=t=>t,_s=wo("Linear"),Ph=wo("EaseInOutQuad"),rr=wo("EaseInOutCubic"),Ah=wo("SpringBouncy"),bi=t=>e=>n=>{const r=Ce(1-e*e),i=t*r;return 1-zr(-e*t*n)*(rn(i*n)+e/r*Ve(i*n))},Ih=t=>{const e=rt.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=rt.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Fn=t=>e=>(()=>{if(t==="Linear")return Gh;if(t==="EaseInQuad")return n=>n*n;if(t==="EaseOutQuad")return n=>1-(1-n)*(1-n);if(t==="EaseInOutQuad")return n=>n<.5?2*n*n:1-2*(1-n)*(1-n);if(t==="EaseInCubic")return n=>n*n*n;if(t==="EaseOutCubic")return n=>1-(1-n)*(1-n)*(1-n);if(t==="EaseInOutCubic")return n=>n<.5?4*n*n*n:1-(-2*n+2)*(-2*n+2)*(-2*n+2)/2;if(t==="EaseOutExpo")return n=>n>=1?1:1-Wu(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*zr(-6*n);if(t==="SpringBouncy")return bi(6)(.7);g()})()(Ih(e)),To=t=>t,Hc=t=>t,Oc=t=>t,wn=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Rr=t=>e=>n=>{const r=rt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=rt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},$c=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Qh=t=>e=>{const n=nt.compare(t._1)(e._1);return n==="LT"?me:n==="GT"?ye:rt.compare(t._2)(e._2)},Dh=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Fh=Oc("Hold"),zh=Oc("Gap"),vo=Hc("LinearLerp"),Xc=Hc("StagedLogLerp"),ds=To("Overview"),Bh=To("DiveHome"),Yc=To("DiveTransition"),Mh=To("ActionFocus"),Wh=t=>e=>{const n=Ne(t),r=n.h/wn(1e-6)(e.zoom),i=n.w/wn(1e-6)(e.zoom);return{x:e.center.x-i/2,y:e.center.y-r/2,w:i,h:r}},Rh=t=>e=>n=>{const r=n.center.y-e.center.y,i=n.center.x-e.center.x,o=Ce(i*i+r*r),u=n.zoom-e.zoom,s=u<0?-u:u;return Rr(t.minTransition)(t.maxTransition)(wn(t.panSpeed<=0?t.minTransition:o/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:s/t.zoomSpeed))},qh=t=>({startT:t.startT,endT:t.endT,fromCam:t.fromCam,toCam:t.toCam,easing:t.easing,interp:t.interp,intent:t.intent}),Hh=w(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:Dt(t)(e)})([]),Oh=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 i=t.w-e.w;return(i<0?-i<.001:i<.001)&&(()=>{const o=t.h-e.h;return o<0?-o<.001:o<.001})()})()})()},$h=t=>e=>t.tag==="Just"?e.tag==="Just"&&Oh(t._1)(e._1):t.tag==="Nothing"&&e.tag==="Nothing",Vc=t=>e=>n=>r=>({center:{x:r.center.x*n.scale+n.tx,y:r.center.y*n.scale+n.ty},zoom:r.zoom*Ne(t).w/wn(1e-6)(n.scale*Ne(e).w)}),Xh=t=>e=>({center:{x:e.center.x*t.scale+t.tx,y:e.center.y*t.scale+t.ty},zoom:e.zoom/wn(1e-6)(t.scale)}),Uc=t=>e=>n=>r=>({center:{x:t.center.x+(e.center.x-t.center.x)*n,y:t.center.y+(e.center.y-t.center.y)*n},zoom:zr((()=>{const i=ro(wn(1e-6)(t.zoom));return i+(ro(wn(1e-6)(e.zoom))-i)*r})())}),Yh=t=>e=>n=>r=>{const i=zr(-t*e);return{center:{x:r.center.x+(n.center.x-r.center.x)*i,y:r.center.y+(n.center.y-r.center.y)*i},zoom:zr((()=>{const o=ro(wn(1e-6)(r.zoom));return o+(ro(wn(1e-6)(n.zoom))-o)*i})())}},Vh=t=>e=>n=>e.zoom>=t.zoom?Fn(rr)(Rr(0)(1)((n-.28)/.72)):Fn(rr)(Rr(0)(1)(n/.28)),Uh=t=>e=>n=>e.zoom>=t.zoom?Fn(rr)(Rr(0)(1)(n/.28)):Fn(rr)(Rr(0)(1)((n-.28)/.72)),Kh=t=>e=>n=>Uc(t)(e)(Uh(t)(e)(n))(Vh(t)(e)(n)),jh=t=>e=>n=>{const r=n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT),i=Fn(n.easing)(Rr(0)(1)(r));if(n.interp==="LinearLerp")return{center:{x:n.fromCam.center.x+(n.toCam.center.x-n.fromCam.center.x)*i,y:n.fromCam.center.y+(n.toCam.center.y-n.fromCam.center.y)*i},zoom:n.fromCam.zoom+(n.toCam.zoom-n.fromCam.zoom)*i};if(n.interp==="LogLerp")return Uc(n.fromCam)(n.toCam)(i)(i);if(n.interp==="StagedLogLerp")return Kh(n.fromCam)(n.toCam)(r);g()},Zh={widthPx:0,heightPx:0},t0={padding:24,easing:_s,minimumReadableLabelPx:24,minimumVisibleLabelPx:5,labelBasePx:11,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:6},Li=t=>e=>n=>r=>i=>{const o=Wh(n)(r),u=i.x-t.padding,s=i.y-t.padding;return u>=o.x&&s>=o.y&&u+i.w+t.padding*2<=o.x+o.w&&s+i.h+t.padding*2<=o.y+o.h},e0=t=>e=>n=>r=>i=>vc.foldlWithIndex(o=>u=>s=>{const a=(()=>{if(s.kind==="Hold"){const c=(()=>{if(s.focus.tag==="Just"){if(s.intent==="ActionFocus"&&Li(t)(e)(n)({center:u.prev.center,zoom:s.toCam.zoom})(s.focus._1))return{...s.toCam,center:u.prev.center};if(s.intent==="ActionFocus")return s.toCam;if(Li(t)(e)(n)(u.prev)(s.focus._1))return u.prev;if(Li(t)(e)(n)({center:u.prev.center,zoom:s.toCam.zoom})(s.focus._1))return{...s.toCam,center:u.prev.center}}return s.toCam})();return{startT:s.startT,endT:s.endT,fromCam:c,toCam:c,easing:s.easing,interp:vo,focus:s.focus,intent:s.intent}}if(s.kind==="Gap")return{startT:s.startT,endT:s.endT,fromCam:u.prev,toCam:(()=>{const c=o+1|0,f=hr(Zt,J,d=>d.kind==="Hold",c<1?i:kt(c,i.length,i));if(f.tag==="Just"){const d=(o+1|0)+f._1|0;return d>=0&&d<i.length?(()=>{if(i[d].focus.tag==="Just")return Li(t)(e)(n)(u.prev)(i[d].focus._1);if(i[d].focus.tag==="Nothing")return!1;g()})()?u.prev:i[d].fromCam:u.prev}if(f.tag==="Nothing")return u.prev;g()})(),easing:s.easing,interp:vo,focus:J,intent:s.intent};g()})();return{acc:Dt(u.acc)(a),prev:a.toCam}})({acc:[],prev:r})(i).acc,n0=t=>e=>n=>r=>i=>{const o=(s,a)=>$c(Rh(t)(s.toCam)(a.toCam))(s.endT-s.startT),u=w(s=>a=>{if(s.pending.tag==="Nothing")return{acc:s.acc,pending:T("Just",a)};if(s.pending.tag==="Just")return!(a.fromCam.zoom===a.toCam.zoom&&a.fromCam.center.x===a.toCam.center.x&&a.fromCam.center.y===a.toCam.center.y)||(()=>{if(a.focus.tag==="Just")return Li(t)(e)(n)(s.pending._1.toCam)(a.focus._1);if(a.focus.tag==="Nothing")return!1;g()})()||(()=>{const c=s.pending._1.toCam.center.x-a.toCam.center.x;return(c<0?-c<8:c<8)&&(()=>{const f=s.pending._1.toCam.center.y-a.toCam.center.y;return(f<0?-f<8:f<8)&&(()=>{const d=s.pending._1.toCam.zoom-a.toCam.zoom;return d<0?-d<.08:d<.08})()})()})()||o(s.pending._1,a)<=0?{acc:Dt(s.acc)(s.pending._1),pending:T("Just",a)}:{acc:Dt(Dt(s.acc)({...s.pending._1,endT:a.startT-o(s.pending._1,a)}))({startT:a.startT-o(s.pending._1,a),endT:a.startT,fromCam:s.pending._1.toCam,toCam:a.toCam,easing:a.easing,interp:vo,focus:a.focus,intent:a.intent}),pending:T("Just",a)};g()})({acc:[],pending:J})(i);if(u.pending.tag==="Nothing")return u.acc;if(u.pending.tag==="Just")return Dt(u.acc)(u.pending._1);g()},r0=t=>e=>n=>{const r=e.w+n*2,i=e.h+n*2,o=Ne(t);return r<=0||i<=0||o.w<=0||o.h<=0?1:$c(o.w/r)(o.h/i)},i0=t=>e=>{if(t.tag==="Just"){if(e.tag==="Just")return T("Just",vr([t._1,e._1]));if(e.tag==="Nothing")return T("Just",t._1);g()}if(t.tag==="Nothing"){if(e.tag==="Just")return T("Just",e._1);if(e.tag==="Nothing")return J}g()},o0=w(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?T("Just",t[n]):J;return r.tag==="Just"&&r._1.fromCam.zoom===r._1.toCam.zoom&&r._1.fromCam.center.x===r._1.toCam.center.x&&r._1.fromCam.center.y===r._1.toCam.center.y&&e.fromCam.zoom===e.toCam.zoom&&e.fromCam.center.x===e.toCam.center.x&&e.fromCam.center.y===e.toCam.center.y&&(!(r._1.intent==="ActionFocus"||e.intent==="ActionFocus")||(r._1.intent==="Overview"?e.intent==="Overview":r._1.intent==="DiveHome"?e.intent==="DiveHome":r._1.intent==="DiveTransition"?e.intent==="DiveTransition":r._1.intent==="ActionFocus"&&e.intent==="ActionFocus")&&$h(r._1.focus)(e.focus))&&(()=>{const i=r._1.toCam.center.x-e.toCam.center.x;return(i<0?-i<8:i<8)&&(()=>{const o=r._1.toCam.center.y-e.toCam.center.y;return(o<0?-o<8:o<8)&&(()=>{const u=r._1.toCam.zoom-e.toCam.zoom;return u<0?-u<.08:u<.08})()})()})()?Dt((()=>{const i=t.length-1|0;return i<1?[]:kt(0,i,t)})())({...r._1,endT:e.endT,focus:i0(r._1.focus)(e.focus)}):Dt(t)(e)})([]),u0=t=>{const e=Et(n=>r=>Qh(L((()=>{if(r.intent==="DiveTransition")return 3;if(r.intent==="ActionFocus")return 2;if(r.intent==="DiveHome")return 1;if(r.intent==="Overview")return 0;g()})(),r.startT))(L((()=>{if(n.intent==="DiveTransition")return 3;if(n.intent==="ActionFocus")return 2;if(n.intent==="DiveHome")return 1;if(n.intent==="Overview")return 0;g()})(),n.startT)))(t);return 0<e.length?T("Just",e[0]):J},bo=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:wn(r)(r0(e)(n)(t.padding))}),s0=t=>e=>n=>r=>i=>{const o=bo(t)(n)(Ne(n))(0),u=ut(a=>a>=0&&a<=r,Hh(Et(rt.compare)([0,r,...Tt(i)(a=>[a.startT,a.endT])]))),s=(a,c)=>qe(f=>f.priority>=1,ut(f=>f.startT<=c&&c<f.endT,i))?dh(t)(e)(n)(vr(a)).camera:bo(t)(n)(vr(a))(0);return H(qh)(n0(t)(e)(n)(o)(o0(e0(t)(e)(n)(o)(xt(a=>{const c=(a._1+a._2)/2;if(a._2<=a._1)return J;const f=H(d=>d.bbox)(ut(d=>d.priority===w(Dh)(0)(H(l=>l.priority)(ut(l=>l.startT<=c&&c<l.endT,i))),ut(d=>d.startT<=c&&c<d.endT,i)));return f.length===0?T("Just",{kind:zh,startT:a._1,endT:a._2,fromCam:o,toCam:o,easing:t.easing,focus:J,intent:ds}):T("Just",{kind:Fh,startT:a._1,endT:a._2,fromCam:s(f,c),toCam:s(f,c),easing:t.easing,focus:T("Just",vr(f)),intent:qe(d=>d.priority>=1,ut(d=>d.startT<=c&&c<d.endT,i))?Mh:ds})})(be(ln,u,kt(1,u.length,u)))))))},Kc=t=>e=>n=>r=>{const i=u0(ut(o=>r>=o.startT&&r<o.endT,n));if(i.tag==="Just")return{camera:jh()(r)(i._1),intent:i._1.intent};if(i.tag==="Nothing"){const o=n.length-1|0;return o>=0&&o<n.length&&r>=n[o].endT?{camera:n[o].toCam,intent:n[o].intent}:{camera:(()=>{const u=bo(t)(e)(Ne(e))(0);return 0<n.length?n[0].fromCam:u})(),intent:0<n.length?n[0].intent:ds}}g()};function ir(t){return t.charCodeAt(0)}function jc(t){return String.fromCharCode(t)}const or=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},Lo=function(t){return function(e){return e.split(t)}},a0=function(t){return t.trim()},ko=function(t){return function(e){return e.join(t)}};var c0=typeof Array.from=="function",g0=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",f0=typeof String.prototype.fromCodePoint=="function",_0=typeof String.prototype.codePointAt=="function";const d0=function(t){return _0?function(e){return e.codePointAt(0)}:t},l0=function(t){return f0?String.fromCodePoint:t},h0=function(t){return function(e){return g0?function(n){for(var r="",i=n[Symbol.iterator](),o=0;o<e;++o){var u=i.next();if(u.done)return r;r+=u.value}return r}:t(e)}},p0=function(t){return function(e){return c0?function(n){return Array.from(n,e)}:t}},Eo=t=>{const e=tr(t);if(e===0)return J;if(e===1)return T("Just",{head:ir(xi(0)(t)),tail:""});const n=ir(xi(1)(t)),r=ir(xi(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:Ni(2)(t)}):T("Just",{head:r,tail:Ni(1)(t)})},m0=t=>{const e=Eo(t);return e.tag==="Just"?T("Just",L(e._1.head,e._1.tail)):J},y0=t=>Ue.unfoldr(m0)(t),Zc=d0(t=>{const e=ir(xi(0)(t));if(55296<=e&&e<=56319&&tr(t)>1){const n=ir(xi(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),So=p0(y0)(Zc),ls=t=>go(t>=0&&t<=65535?jc(t):t<0?"\0":"\uFFFF"),x0=l0(t=>t<=65535?ls(t):ls(An(t-65536|0,1024)+55296|0)+ls(Kn(t-65536|0)(1024)+56320|0)),tg=t=>e=>{if(t<1)return"";const n=Eo(e);return n.tag==="Just"?x0(n._1.head)+tg(t-1|0)(n._1.tail):e},Je=h0(tg),N0=t=>e=>e===""?J:T("Just",Zc(e)),J0=t=>t,eg=t=>e=>{const n=e.vw/e.vh,r=e.vh*t,i={...e,vx:e.vx-(r-e.vw)/2,vw:r},o=e.vw/t,u={...e,vy:e.vy-(o-e.vh)/2,vh:o};return t<=0||e.vw<=0||e.vh<=0?e:t>n?i:t<n?u:e},ng=t=>e=>t.width<=0||t.height<=0?e:eg(t.width/t.height)(e),Co=(t,e,n)=>({tag:t,_1:e,_2:n}),w0=()=>({tag:"ExtendFromSource"}),Go=(t,e)=>({tag:t,_1:e}),hs=t=>t,Po=(t,e)=>({tag:t,_1:e}),ps=Po("NotYet"),rg=Po("Consumed"),T0=hs("FromSource"),ig=hs("FromTarget"),v0=hs("FromBoth"),og=Go("Hidden"),b0=Go("Visible"),ug=w0(),sg=Co("Retracted"),L0=Co("Extended"),ag=t=>t,ms=(t,e)=>({tag:t,_1:e}),br=(t,e,n)=>({tag:t,_1:e,_2:n}),cg=t=>t,ur=(t,e)=>({tag:t,_1:e}),qr=(t,e,n,r,i,o,u,s,a)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u,_7:s,_8:a}),Ao=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},pn=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},gg=te(G)(Bt),ys=Bu(fi),Hr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},ki=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},xs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},fg=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},_g=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Or=(()=>{const t=Ue.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return T("Just",L(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Xt("Cons",r._3,n(r._6,i)));g()};return n(e,Ut)})())})(),k0=w(t=>e=>Z(G)(e)()(t))(D),Ns=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Io=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},E0=t=>t,S0=ur("NoKeyframes"),C0=t=>ur("DuplicateEventId",t),G0=t=>ur("UnknownEvent",t),dg=cg("PlopIn"),P0=cg("PlopOut"),A0=ag("DiveIn"),I0=ag("DiveOut"),Q0=t=>e=>n=>xt(r=>{if(r.target.tag==="NodeWindow"||r.target.tag==="EdgeWindow")return J;if(r.target.tag==="TokenWindow")return T("Just",{startT:r.startT,endT:r.endT,bbox:qc(e)(n)(r.target._2),priority:1});if(r.target.tag==="FillWindow")return T("Just",{startT:r.startT,endT:r.endT,bbox:fs(e)(n)(Ot("Node",1,1,r.target._2,void 0,D,D)),priority:1});g()}),D0=t=>e=>n=>r=>{const i=Ao(r.edge)(e.edges),o=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return mo(i._1);g()})(),u=pn(t.minTokenDuration)(pn(et(w(s=>a=>s+So(a).length|0)(0)(r.labels))*t.tokenReadSecPerChar)(t.tokenSpeed<=0?0:o/t.tokenSpeed))+n.pre+n.post;return{duration:u,holdPre:u<=0?0:n.pre/u,holdPost:u<=0?0:n.post/u}},F0=t=>e=>gg(xt(n=>{if(n.kind.tag==="SendToken")return T("Just",L(n.id,{pre:(()=>{const r=n.when;return(()=>{const i=n.kind._1.from;return qe(o=>{if(o.kind.tag==="SendToken")return(r.tag==="First"?!1:r.tag==="After"&&r._1===o.id)&&o.kind._1.to===i;if(o.kind.tag==="FillNodeWithoutTransition")return!1;g()},e)})()?0:t.tokenHold})(),post:(()=>{const r=n.id;return(()=>{const i=n.kind._1.to;return qe(o=>{if(o.kind.tag==="SendToken")return(o.when.tag==="First"?!1:o.when.tag==="After"&&o.when._1===r)&&o.kind._1.from===i;if(o.kind.tag==="FillNodeWithoutTransition")return!1;g()},e)})()?0:t.tokenHold})()}));if(n.kind.tag==="FillNodeWithoutTransition")return J;g()})(e)),z0=t=>{if(t.event.kind.tag==="SendToken")return T("Just",{startT:t.startT,endT:t.endT,target:qr("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:qr("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},B0=t=>e=>n=>r=>{const i=Vt(o=>ys(o.path)(e)&&(yn(o.endT-n)<1e-4||yn(o.startT-r)<1e-4))(t.segments);if(i.tag==="Just")return T("Just",i._1);if(i.tag==="Nothing")return Vt(o=>ys(o.path)(e))(t.segments);g()},M0=t=>e=>n=>xt(r=>{const i=xt(o=>xs(o)(t.nodes))(At($e.foldr,(()=>{if(r.scene.tag==="Structural")return Ge(G.compare,Se,(()=>{const o=Hr(r.scene._1.from)(n);if(o.tag==="Nothing")return D;if(o.tag==="Just")return o._1.nodes;g()})(),(()=>{const o=Hr(r.scene._1.to)(n);if(o.tag==="Nothing")return D;if(o.tag==="Just")return o._1.nodes;g()})());if(r.scene.tag==="DataFlow"){const o=Hr(r.scene._1.keyframe)(n);if(o.tag==="Nothing")return D;if(o.tag==="Just")return o._1.nodes;g()}if(r.scene.tag==="Hold"){const o=Hr(r.scene._1)(n);if(o.tag==="Nothing")return D;if(o.tag==="Just")return o._1.nodes;g()}if(r.scene.tag==="EnterNode"||r.scene.tag==="ExitNode")return D;g()})()));return i.length===0?J:T("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const o=w(u=>s=>({minX:ki(u.minX)(s.x),minY:ki(u.minY)(s.y),maxX:pn(u.maxX)(s.x+s.w),maxY:pn(u.maxY)(s.y+s.h)}))(0<i.length?{minX:i[0].x,minY:i[0].y,maxX:i[0].x+i[0].w,maxY:i[0].y+i[0].h}:{minX:0,minY:0,maxX:0,maxY:0})(kt(1,i.length,i));return{x:o.minX,y:o.minY,w:o.maxX-o.minX,h:o.maxY-o.minY}})(),priority:0})}),W0=t=>e=>n=>r=>i=>[...M0(i.layout)(n)(e)(ut(o=>o.startT>=i.startT&&o.endT<=i.endT,r.spans)),...Q0()(i.layout)(n)(i.windows)],R0=t=>e=>n=>r=>i=>o=>s0(t)(e)(o.layout)(i.endT)(W0()(n)(r)(i)(o)),lg=(()=>{const t=w(e=>n=>{const r=e.previous.tag==="Just"&&yn(e.previous._1.endT-n.startT)<1e-4&&!(n.fromCam.zoom===n.toCam.zoom&&n.fromCam.center.x===n.toCam.center.x&&n.fromCam.center.y===n.toCam.center.y)?{...n,fromCam:e.previous._1.toCam}:n;return{previous:T("Just",r),spans:Dt(e.spans)(r)}})({previous:J,spans:[]});return e=>t(e).spans})(),q0=t=>e=>n=>{const r=Ao(n)(t);if(r.tag==="Nothing")return ig;if(r.tag==="Just"){const i=fg(r._1.target)(e);return fg(r._1.source)(e)?i?v0:T0:ig}g()},H0=t=>e=>{const n=Ne(e),r=ng({width:t.widthPx,height:t.heightPx})({vx:n.x,vy:n.y,vw:n.w,vh:n.h});return{w:r.vw,h:r.vh}},O0=t=>e=>n=>r=>{const i=pn(n.center.x-r.x)(r.x+r.w-n.center.x),o=pn(n.center.y-r.y)(r.y+r.h-n.center.y),u=H0(t)(e);return ki(i<=0?n.zoom:u.w/(i*2))(o<=0?n.zoom:u.h/(o*2))},$0={pre:0,post:0},X0=t=>e=>n=>r=>i=>{const o=_g(i.event.id)(n),u=(()=>{if(o.tag==="Nothing")return $0;if(o.tag==="Just")return o._1;g()})(),s=(()=>{if(i.event.when.tag==="First")return 0;if(i.event.when.tag==="At")return i.event.when._1;if(i.event.when.tag==="After"){const c=i.event.when._1,f=Vt(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.endT;g()}if(i.event.when.tag==="With"){const c=i.event.when._1,f=Vt(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.startT}g()})(),a=(()=>{if(i.event.kind.tag==="SendToken")return D0(t)(e)(u)(i.event.kind._1);if(i.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return Dt(r)({startT:s,endT:s+a.duration,event:i.event,holdPre:a.holdPre,holdPost:a.holdPost})},hg=t=>e=>n=>w(X0(t)(e)(F0(t)(n)))([])(Ft(r=>i=>({event:i}))(n)),Js=t=>e=>n=>r=>i=>{const o={width:e.widthPx,height:e.heightPx},u=ng(o)((()=>{const s=Jo(n)(i);return{vx:s.x,vy:s.y,vw:s.w,vh:s.h}})());return t.labelBasePx*r.placement.scale*(o.width<=0||u.vw<=0?0:o.width/u.vw)},Y0=t=>e=>n=>r=>i=>{const o=Js(t)(e)(n)(r)(i);return o<=t.minimumReadableLabelPx?i:{...i,zoom:i.zoom*t.minimumReadableLabelPx/o}},V0=t=>e=>{const n=xs(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},U0=t=>e=>n=>r=>({...r,fromCam:Vc(t)(e)(n)(r.fromCam),toCam:Vc(t)(e)(n)(r.toCam)}),K0=t=>e=>n=>r=>i=>o=>{if(i.tag==="Nothing")return o.zoom;if(i.tag==="Just")return pn(0)(O0(e)(n)(o)((()=>{const u=t.padding*r.placement.scale;return{x:i._1.x-u,y:i._1.y-u,w:i._1.w+u*2,h:i._1.h+u*2}})()));g()},j0=t=>e=>n=>r=>i=>o=>{const u=Js(t)(e)(n)(r)(o);return u<=0?o:{...o,zoom:ki(o.zoom*t.minimumReadableLabelPx/u)(K0(t)(e)(n)(r)(i)(o))}},Z0=t=>{if(t.when.tag==="First")return[];if(t.when.tag==="At")return[];if(t.when.tag==="After")return[t.when._1];if(t.when.tag==="With")return[t.when._1];g()},pg={id:"",nodes:D,edges:D,kind:vi},tp=t=>e=>wh((()=>{const n=Hr(e.from)(t);if(n.tag==="Nothing")return pg;if(n.tag==="Just")return n._1;g()})())((()=>{const n=Hr(e.to)(t);if(n.tag==="Nothing")return pg;if(n.tag==="Just")return n._1;g()})()),ep=t=>e=>{const n=xs(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:D};if(n.tag==="Just")return n._1;g()},ws=t=>e=>n=>r=>{const i=Ao(r)(n.edges);if(i.tag==="Just")return t<=0?e:pn(e)(mo(i._1)/t);if(i.tag==="Nothing")return e;g()},mg=t=>e=>n=>r=>i=>{const o=t.plop,u=tp(n)(i),s=H(_=>({startT:0,endT:0+ws(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:qr("EdgeWindow",_,ms("Extend",ug))}))(Or(u.entering.edges)),a=H(_=>({startT:0,endT:o,target:qr("NodeWindow",_,dg)}))(Or(u.entering.nodes)),c=w(pn)(0)(H(_=>ws(t.edgeSpeed)(t.minEdgeDuration)(e)(_))(Or(u.leaving.edges))),f=_=>qe(h=>{const p=Ao(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;g()},Or(u.leaving.edges))?c:0,d=H(_=>({startT:f(_),endT:f(_)+t.plop,target:qr("NodeWindow",_,P0)}))(Or(u.leaving.nodes)),l=H(_=>({startT:0,endT:ws(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:qr("EdgeWindow",_,ms("Retract",q0(r)(u.leaving.nodes)(_)))}))(Or(u.leaving.edges));return{duration:(()=>{const _=Et(rt.compare)([...H(p=>p.endT)(l),...H(p=>p.endT)(d),...H(p=>p.endT)(a),...H(p=>p.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+t.gap:t.gap})(),windows:[...l,...d,...a,...s]}},np=t=>e=>n=>r=>i=>o=>H((()=>{const u=i.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())(mg(t)(e)(n)(r)(o).windows),rp=t=>xt(e=>At(Qr,e).length>1?T("Just",(()=>{const n=Mt(r=>J,r=>i=>T("Just",{head:r,tail:i}),At(Qr,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):J)(Wd(fi)(Et(G.compare)(t))),ip=t=>{const e=H(r=>r.id)(t),n=k0(e);return[...H(C0)(rp(e)),...H(G0)(ut(r=>!Ns(r)(n),Tt(t)(Z0)))]},op=t=>{const e=gg(H(r=>L(r.id,(()=>{if(r.when.tag==="First")return[];if(r.when.tag==="At")return[];if(r.when.tag==="After")return[r.when._1];if(r.when.tag==="With")return[r.when._1];g()})()))(t)),n=r=>i=>o=>{if(Ns(o)(i))return[ur("ScheduleCycle",[...At($e.foldr,i),o])];if(Ns(o)(r))return[];const u=_g(o)(e);if(u.tag==="Nothing")return[];if(u.tag==="Just")return Tt(u._1)(n(Z(G)(o)()(r))(Z(G)(o)()(i)));g()};return Tt(t)(r=>n(D)(D)(r.id))},up={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:.5,stillHold:1.8,hatchHold:.4,tokenReadSecPerChar:.06,nodeEasing:Ah,edgeEasing:Ph,tokenEasing:_s,diveDur:1.2,retreatDur:1.2},sp=t=>e=>n=>r=>H((()=>{const i=n.startT;return o=>({...o,startT:o.startT+i,endT:o.endT+i})})())(xt(z0)(hg(t)(e)(r.events))),ap=t=>e=>n=>r=>i=>{if(i.scene.tag==="Structural")return np(t)(e)(n)(r)(i)(i.scene._1);if(i.scene.tag==="Hold")return[];if(i.scene.tag==="DataFlow")return sp(t)(e)(i)(i.scene._1);if(i.scene.tag==="EnterNode")return[];if(i.scene.tag==="ExitNode")return[];g()},cp=t=>e=>n=>{const r=hg(t)(e)(n.events);return r.length===0?t.gap:w(pn)(0)(H(i=>i.endT)(r))+t.gap},gp=t=>e=>n=>r=>i=>{if(i.tag==="Structural")return mg(t)(e)(n)(r)(i._1).duration;if(i.tag==="Hold")return t.stillHold;if(i.tag==="DataFlow")return cp(t)(e)(i._1);if(i.tag==="EnterNode"||i.tag==="ExitNode")return 0;g()},yg=t=>e=>n=>r=>i=>o=>{const u=ch(e)(r),s=n.layout,a=Bc(H(p=>L(p.id,p))(i.keyframes)),c=0<i.keyframes.length?T("Just",i.keyframes[0]):J,f=(()=>{if(c.tag==="Just")return c._1.id;if(c.tag==="Nothing")return"";g()})(),d=Ch(i),l=p=>({segments:p.runSpans.length===0?p.segments:Dt(p.segments)({startT:p.runStart,endT:p.t,path:r,layout:s,placement:u,windows:p.runWindows,spans:p.runSpans,keyframes:a,initialKeyframe:f,edgeEndpoints:d}),spans:p.spans,windows:p.windows,dives:p.dives}),_=w(p=>m=>{if(m.tag==="EnterNode"){const v=l(p),b=p.t+t.diveDur,k=Dt(r)(m._1),E=yg(t)(e)(ep(n)(m._1))(k)(V0(i)(m._1))(b),A=E.endT+t.retreatDur;return{...p,t:A,runStart:A,runSpans:[],runWindows:[],segments:[...v.segments,...E.segments],spans:[...v.spans,...E.spans],windows:[...v.windows,...E.windows],dives:[...v.dives,{startT:p.t,endT:b,node:m._1,parentPath:r,childPath:k,direction:A0},...E.dives,{startT:E.endT,endT:A,node:m._1,parentPath:r,childPath:k,direction:I0}]}}if(m.tag==="ExitNode")return p;const y=p.t+gp(t)(s)(a)(d)(m),x={startT:p.t,endT:y,scene:m},N=ap(t)(s)(a)(d)(x);return{...p,t:y,runSpans:Dt(p.runSpans)(x),runWindows:[...p.runWindows,...N],spans:Dt(p.spans)(x),windows:[...p.windows,...N]}})({t:o,runStart:o,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(i.scenes),h=l(_);return{endT:_.t,spans:h.spans,windows:Et(p=>m=>rt.compare(p.startT)(m.startT))(h.windows),segments:h.segments,dives:h.dives}},fp=t=>e=>n=>n.endT<=t||n.startT>=e?J:T("Just",{...n,startT:pn(t)(n.startT),endT:ki(e)(n.endT)}),Ts=t=>e=>n=>r=>i=>o=>xt(fp(o.startT)(o.endT))(H(U0(n)(o.layout)(o.placement))(R0(t)(e)(r)(o.edgeEndpoints)(i)(o))),vs=t=>e=>n=>r=>lh(t)(e)(n)(r.layout)(r.placement)((()=>{if(r.layout.nodes.tag==="Leaf")return 0;if(r.layout.nodes.tag==="Node")return r.layout.nodes._2;g()})()).camera,_p=t=>e=>n=>r=>r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?Xh(r.placement)(bo(t)(r.layout)(Ne(r.layout))(0)):vs(t)(e)(n)(r),xg=t=>e=>n=>r=>i=>{const o=Jo(n)(i);return(()=>{const u=Ne(r.layout),s=u.x*r.placement.scale+r.placement.tx,a=u.y*r.placement.scale+r.placement.ty;return s>=o.x&&a>=o.y&&s+u.w*r.placement.scale<=o.x+o.w&&a+u.h*r.placement.scale<=o.y+o.h})()&&Js(t)(e)(n)(r)(i)>=t.minimumReadableLabelPx},bs=t=>e=>n=>r=>i=>o=>xg(t)(e)(n)(r)(o)?o:j0(t)(e)(n)(r)(i)(o),dp=t=>e=>{if(e.tag==="Structural")return xt(n=>n)([Io(e._1.from)(t)?J:T("Just",ur("UnknownKeyframe",e._1.from)),Io(e._1.to)(t)?J:T("Just",ur("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return xt(n=>n)([Io(e._1)(t)?J:T("Just",ur("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...xt(n=>n)([Io(e._1.keyframe)(t)?J:T("Just",ur("UnknownKeyframe",e._1.keyframe))]),...ip(e._1.events),...op(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()},lp=t=>e=>{const n=Tt(e)(dp(t));return n.length===0?Gt("Right",void 0):Gt("Left",n)},Ls=t=>e=>n=>r=>i=>o=>xg(t)(e)(n)(r)(i)?i:Y0(t)(e)(n)(r)(o),hp=t=>e=>{const n=Mt(r=>J,r=>i=>T("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{...n._1.head,fromCam:t},...n._1.tail];g()},pp=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=xt(i=>i.target.tag==="TokenWindow"?T("Just",qc(t.layout)(t.edgeEndpoints)(i.target._2)):i.target.tag==="FillWindow"?T("Just",fs(t.layout)(t.edgeEndpoints)(Ot("Node",1,1,i.target._2,void 0,D,D))):J)(ut(i=>i.startT<=n&&n<i.endT,t.windows));return r.length===0?J:T("Just",(()=>{const i=vr(r);return{x:i.x*t.placement.scale+t.placement.tx,y:i.y*t.placement.scale+t.placement.ty,w:i.w*t.placement.scale,h:i.h*t.placement.scale}})())},Ng=t=>e=>n=>r=>i=>o=>{const u=i(o.fromCam),s=i(o.toCam),a=pp(r)(o);return u.zoom===s.zoom&&u.center.x===s.center.x&&u.center.y===s.center.y?{...o,fromCam:bs(t)(e)(n)(r)(a)(u),toCam:bs(t)(e)(n)(r)(a)(s)}:{...o,fromCam:u,toCam:bs(t)(e)(n)(r)(a)(s)}},Jg=t=>e=>n=>r=>i=>o=>o.intent==="ActionFocus"?Ng(t)(e)(n)(r)(Ls(t)(e)(n)(r)(i))(o):{...o,fromCam:Ls(t)(e)(n)(r)(i)(o.fromCam),toCam:Ls(t)(e)(n)(r)(i)(o.toCam)},wg=t=>e=>n=>r=>i=>o=>{const u=Vt(s=>s.intent==="ActionFocus"&&yn(s.startT-r.startT)<1e-4)(o);if(u.tag==="Just"){const s=Jg(t)(e)(n)(r)(i)(u._1).toCam;return s.zoom<i.zoom?{...i,zoom:s.zoom}:i}if(u.tag==="Nothing")return i;g()},mp=t=>e=>n=>r=>i=>wg(t)(e)(n)(r)(vs(t)(e)(n)(r))(i),yp=t=>e=>n=>r=>i=>xt(o=>{const u=B0(i)(o.parentPath)(o.startT)(o.endT);if(u.tag==="Just"){const s=o.childPath,a=Vt(c=>ys(c.path)(s))(i.segments);if(a.tag==="Just"){const c=_p(t)(e)(n)(u._1),f=mp(t)(e)(n)(a._1)(Ts(t)(e)(n)(r)(i)(a._1));if(o.direction==="DiveIn")return T("Just",{startT:o.startT,endT:o.endT,fromCam:c,toCam:f,easing:rr,interp:Xc,intent:Yc});if(o.direction==="DiveOut")return T("Just",{startT:o.startT,endT:o.endT,fromCam:f,toCam:c,easing:rr,interp:Xc,intent:Yc});g()}if(a.tag==="Nothing")return J;g()}if(u.tag==="Nothing")return J;g()})(i.dives),xp=t=>e=>n=>r=>i=>i.intent==="ActionFocus"?Ng(t)(e)(n)(r)(E0)(i):i,Np=t=>e=>n=>r=>i=>Et(o=>u=>rt.compare(o.startT)(u.startT))(Tt(i.segments)(o=>{if(o.placement.scale===1&&o.placement.tx===0&&o.placement.ty===0)return lg(H(xp(t)(e)(n)(o))(Ts(t)(e)(n)(r)(i)(o)));const u=Ts(t)(e)(n)(r)(i)(o),s=vs(t)(e)(n)(o),a=wg(t)(e)(n)(o)(s)(u);return u.length===0?[{startT:o.startT,endT:o.endT,fromCam:a,toCam:a,easing:_s,interp:vo,intent:Bh}]:lg(hp(a)(H(Jg(t)(e)(n)(o)(s))(u)))})),Tg=t=>e=>n=>r=>i=>[...yp(t)(e)(n)(r)(i),...Np(t)(e)(n)(r)(i)],Jp=t=>e=>n=>r=>{if(0<n.keyframes.length){const i=n.keyframes[0],o=Bc(H(s=>L(s.id,s))(n.keyframes)),u=lp(o)(n.scenes);return(()=>{if(u.tag==="Left"){const s=u._1;return a=>Gt("Left",s)}if(u.tag==="Right"){const s=u._1;return a=>a(s)}g()})()(()=>{const s=yg(e)(r)(r)([])(n)(0);return Gt("Right",{totalDuration:s.endT,windows:s.windows,spans:s.spans,keyframes:o,initialKeyframe:i.id,timing:e,layout:r.layout,cameraSpans:Tg(t)(Zh)(r.layout)(o)(s),cameraConfig:t,levelTree:r,segments:s.segments,dives:s.dives,seed:n.seed})})}return Gt("Left",[S0])},wp=t=>e=>({...e,cameraSpans:Tg(e.cameraConfig)(t)(e.layout)(e.keyframes)({endT:e.totalDuration,spans:e.spans,windows:e.windows,segments:e.segments,dives:e.dives})}),ks=t=>t,vg=te(G)(Bt),Ei={eq:Bu(fi)},Es=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},zn=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bg=Bt.foldMap(Bl(G)),Tp=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},vp=(()=>{const t=Ue.unfoldr(Jn);return e=>t(Ke("IterNode",e,Nn))})(),$r=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},bp=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Lp=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},kp=te(G)(Bt),Ep=te(G)(Bt),Sp=t=>e=>n=>{const r=rt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=rt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},Lg=ks("Backdrop"),Cp=ks("FlyThrough"),Qo=ks("Active"),Gp=t=>e=>n=>({...n,state:{...n.state,edgeFadeAlpha:vg(H(r=>L(r,e))(t))}}),kg=t=>e=>n=>{const r=(t+e)/2,i=n-r,o=i<0?-1:1,u=(e-t)/2,s=u*.15,a=u-s,c=i<0?-i:i;return e<=t?(t+e)/2:c<=a?n:r+o*(u-s*zr(-(c-a)/s))},Do=t=>e=>n=>{const r=Vt(i=>Ei.eq(i.path)(e)&&n>=i.startT&&n<i.endT)(t.segments);if(r.tag==="Just")return T("Just",r._1);if(r.tag==="Nothing")return Vt(i=>Ei.eq(i.path)(e))(t.segments);g()},Pp=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:ss,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:D}),Ap=t=>H(e=>e<1?[]:kt(0,e,t))(zt(0,t.length-1|0)),Ss=t=>e=>{const n=Es(e)(t.keyframes);if(n.tag==="Nothing")return D;if(n.tag==="Just")return n._1.nodes;g()},Cs=t=>e=>{const n=Es(e)(t.keyframes);if(n.tag==="Nothing")return D;if(n.tag==="Just")return n._1.edges;g()},Fo=t=>e=>{if(e<t.startT)return br("AtKeyframe",t.initialKeyframe);const n=Vt(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return br("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return br("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return br("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return br("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;return r>=0&&r<t.spans.length?br("AtKeyframe",(()=>{if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="Hold")return t.spans[r].scene._1;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return t.initialKeyframe;g()})()):br("AtKeyframe",t.initialKeyframe)}g()},Ip=w(t=>e=>{const n=pr(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?Dt(n._1.init)({...n._1.last,endT:zn(n._1.last.endT)(e.endT),windows:Dt(n._1.last.windows)(e)}):Dt(t)({endT:e.endT,windows:[e]})})([]),Qp=t=>e=>n=>bg(r=>bg(i=>i.target.tag==="FillWindow"?i.startT<=n?Ot("Node",1,1,i.target._2,void 0,D,D):D:i.target.tag==="TokenWindow"&&i.startT+(i.endT-i.startT)*.25<=n?Ot("Node",1,1,i.target._4,void 0,D,D):D)(r.windows))(ut(r=>n<=r.endT+t,Ip(Et(r=>i=>rt.compare(r.startT)(i.startT))(ut(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),Dp=t=>e=>n=>qe(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),Fp=t=>e=>n=>qe(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),zp=t=>e=>n=>qe(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),Bp=t=>e=>n=>qe(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),Mp=t=>e=>{const n=Fo(t)(e);if(n.tag==="AtKeyframe")return Je(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return Je(3)(n._2)==="kf-"?"":n._2;g()},Wp=t=>e=>{const n=Fo(t)(e),r=Es((()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;g()})())(t.keyframes);if(r.tag==="Just")return r._1.kind;if(r.tag==="Nothing")return vi;g()},Eg=t=>e=>n=>Vt(r=>n(r)&&e>=r.startT&&e<r.endT)(t),Rp={segment:{startT:0,endT:0,path:[],layout:{nodes:D,edges:D,chipExtras:D,edgeLabels:D},placement:ss,windows:[],spans:[],keyframes:D,initialKeyframe:"",edgeEndpoints:D},state:{nodes:D,edges:D,tokens:D,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:vi,visited:D,nodeFadeAlpha:D,nodeLabelFadeAlpha:D,edgeFadeAlpha:D,nodeInvert:D},bgAlpha:1,blur:0,minis:[],role:Qo},zo=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:Rp},qp=t=>e=>{const n=Tp(e)(t.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1,i=o=>o.x>=r.x-1&&o.x<=r.x+r.w+1&&o.y>=r.y-1&&o.y<=r.y+r.h+1;return xt(o=>(()=>{if(0<o._2.length){const s=o._2.length-1|0;return i(o._2[0])||s>=0&&s<o._2.length&&i(o._2[s])}const u=o._2.length-1|0;return u>=0&&u<o._2.length&&i(o._2[u])})()?T("Just",o._1):J)(vp(t.edges))}g()},Hp=t=>e=>{const n=Fo(t)(e);if(n.tag==="AtKeyframe")return Ss(t)(n._1);if(n.tag==="InTransition")return Ge(G.compare,Se,Ss(t)(n._1),Ss(t)(n._2));g()},Op=t=>e=>{const n=Fo(t)(e);if(n.tag==="AtKeyframe")return Cs(t)(n._1);if(n.tag==="InTransition")return Ge(G.compare,Se,Cs(t)(n._1),Cs(t)(n._2));g()},$p=t=>e=>n=>{const r=Ne(t),i=r.h/zn(1e-4)(n.zoom),o=r.w/zn(1e-4)(n.zoom);return{...n,center:{x:o>=e.w?e.x+e.w/2:kg(e.x+o/2)(e.x+e.w-o/2)(n.center.x),y:i>=e.h?e.y+e.h/2:kg(e.y+i/2)(e.y+e.h-i/2)(n.center.y)}}},Xp=t=>e=>n=>$p(t)((()=>{const r=e*n.placement.scale,i=Ne(n.layout),o=(()=>{const u=i.x*n.placement.scale+n.placement.tx,s=i.y*n.placement.scale+n.placement.ty;return{x:u,y:s,w:(i.x+i.w)*n.placement.scale+n.placement.tx-u,h:(i.y+i.h)*n.placement.scale+n.placement.ty-s}})();return{x:o.x-r,y:o.y-r,w:o.w+r*2,h:o.h+r*2}})()),Yp=t=>e=>{const n=t.endT-t.startT;return n<=0?1:zn(0)($r(1)((e-t.startT)/n))},Bo=t=>e=>{const n=t.endT-t.startT;return n<=0?1:zn(0)($r(1)((e-t.startT)/n))},Vp=t=>e=>n=>r=>i=>{const o=Eg(e)(n)(u=>u.target.tag==="EdgeWindow"&&u.target._1===i);if(o.tag==="Just"){const u=Fn(t.timing.edgeEasing)(Bo(o._1)(n)),s=o._1.target.tag==="EdgeWindow"?o._1.target._2:ms("Extend",ug);if(s.tag==="Retract")return Co("Retracting",s._1,u);if(s.tag==="Extend")return Co("Extending",s._1,u);g()}if(o.tag==="Nothing")return Bp(e)(n)(i)||Dp(e)(n)(i)?sg:bp(i)(r)?L0:sg;g()},Up=t=>e=>n=>{const r=Op(e)(n);return vg(H(i=>L(i,Vp(t)(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return D;if(o.tag==="Node")return Ot("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return At($e.foldr,i(e.layout.edges))})()))},Kp=t=>e=>n=>r=>{const i=Eg(t)(e)(o=>o.target.tag==="NodeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=Bo(i._1)(e),u=i._1.target.tag==="NodeWindow"?i._1.target._2:dg;if(u==="PlopIn")return Go("PloppingIn",o);if(u==="PlopOut")return Go("PloppingOut",o);g()}if(i.tag==="Nothing")return zp(t)(e)(r)||Fp(t)(e)(r)?og:Lp(r)(n)?b0:og;g()},jp=t=>e=>n=>{const r=Hp(e)(n);return kp(H(i=>L(i,Kp(e.windows)(n)(r)(i)))((()=>{const i=o=>{if(o.tag==="Leaf")return D;if(o.tag==="Node")return Ot("Node",o._1,o._2,o._3,void 0,i(o._5),i(o._6));g()};return At($e.foldr,i(e.layout.nodes))})()))},Zp=t=>e=>n=>e.target.tag==="TokenWindow"?L(e.target._1,n<e.startT?ps:n>=e.endT?rg:Po("Travelling",{edge:e.target._2,direction:e.target._3,progress:Fn(t.timing.tokenEasing)(Bo(e)(n)),labels:e.target._6,source:e.target._4,target:e.target._5,holdPre:e.target._7,holdPost:e.target._8})):e.target.tag==="FillWindow"?L(e.target._1,n<e.startT?ps:n>=e.endT?rg:Po("Filling",{node:e.target._2,progress:Bo(e)(n),labels:e.target._3})):L("",ps),tm=t=>e=>n=>Ep(H(r=>Zp(t)(r)(n))(ut(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),em=t=>e=>n=>({nodes:jp()(e)(n),edges:Up(t)(e)(n),tokens:tm(t)(e.windows)(n),camera:Kc(t.cameraConfig)(e.layout)(t.cameraSpans)(n).camera,frameTitle:Mp(e)(n),staticKind:Wp(e)(n),visited:Qp(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:D,nodeLabelFadeAlpha:D,edgeFadeAlpha:D,nodeInvert:D}),Xr=t=>e=>n=>r=>({segment:n,state:em(t)(n)(e),bgAlpha:1,blur:0,minis:nm(t)(e)(n),role:r}),nm=t=>e=>n=>xt(r=>{const i=Do(t)(Dt(n.path)(r))(e);if(i.tag==="Just")return T("Just",{...Xr(t)(Sp(i._1.startT)(i._1.endT-1e-4)(e))(i._1)(Lg),bgAlpha:0});if(i.tag==="Nothing")return J;g()})((()=>{const r=i=>{if(i.tag==="Leaf")return D;if(i.tag==="Node")return Ot("Node",i._1,i._2,i._3,void 0,r(i._5),r(i._6));g()};return At($e.foldr,r(n.layout.nodes))})()),rm=t=>e=>n=>uc(J,Za,r=>r.direction==="DiveIn"&&Ei.eq(r.parentPath)(e.path)&&n>=r.startT-.7&&n<r.startT?T("Just",{node:r.node,phase:(n-(r.startT-.7))/.7}):J,t.dives),im=t=>e=>n=>r=>{const i=rm(t)(e)(n);if(i.tag==="Just"){const o=Ve(3.141592653589793*i._1.phase*3);return{...r,state:{...r.state,nodeInvert:Ot("Node",1,1,i._1.node,1*o*o,D,D)}}}if(i.tag==="Nothing")return r;g()},Sg=t=>e=>xt(n=>{const r=Vt(i=>i.direction==="DiveIn"&&Ei.eq(i.childPath)((()=>{const o=n.length+1|0;return o<1?[]:kt(0,o,e)})()))(t.dives);if(r.tag==="Just"){const i=Do(t)(n)(r._1.startT-1e-4);if(i.tag==="Just")return T("Just",(()=>{const o=Xr(t)(r._1.startT-1e-4)(i._1)(Lg);return{...o,state:{...o.state,nodeFadeAlpha:Ot("Node",1,1,r._1.node,0,D,D)}}})());if(i.tag==="Nothing")return J;g()}if(r.tag==="Nothing")return J;g()})(Ap(e)),Cg=t=>e=>{const n=ut(i=>e>=i.startT&&e<i.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:Pp(t)},om=t=>e=>n=>{const r=Yp(n)(e),i=Do(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),o=Do(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),u=(()=>{if(n.direction==="DiveIn")return Fn(rr)(r);if(n.direction==="DiveOut")return 1-Fn(rr)(r);g()})(),s=1-zn(0)($r(1)((u-.1)/.25)),a=1-zn(0)($r(1)((u-.1)/.25)),c=1-zn(0)($r(1)((u-.8)/.2)),f=l=>{const _=Xr(t)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})())(l)(Cp);return{...Gp(qp(l.layout)(n.node))(a)({..._,state:{..._.state,nodeFadeAlpha:Ot("Node",1,1,n.node,s,D,D),nodeLabelFadeAlpha:Ot("Node",1,1,n.node,a,D,D)}}),minis:ut(h=>!Ei.eq(h.segment.path)(n.childPath),_.minis),bgAlpha:c}},d=0+1*zn(0)($r(1)((u-.1)/.5));return[...Sg(t)(n.parentPath),...(()=>{if(i.tag==="Just"){if(o.tag==="Just")return[f(i._1),{...Xr(t)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})())(o._1)(Qo),bgAlpha:d}];if(o.tag==="Nothing")return[f(i._1)];g()}if(i.tag==="Nothing")return[Xr(t)(e)(Cg(t)(e))(Qo)];g()})()]},um=t=>e=>Vt(n=>e>=n.startT&&e<n.endT)(t.dives),sm=t=>e=>{const n=Cg(t)(e),r=Xr(t)(e)(n)(Qo),i=t.dives.length!==0,o=Kc(t.cameraConfig)(t.layout)(t.cameraSpans)(e).camera,u=Xp(t.layout)(t.cameraConfig.padding)(n)(o),s=im(t)(n)(e)({...r,state:{...r.state,camera:u}}),a=Sg(t)(n.path),c=um(t)(e);if(c.tag==="Just")return{levels:om(t)(e)(c._1),camera:o,rootLayout:t.layout,hasDives:i,diving:!0};if(c.tag==="Nothing")return{levels:Dt(a)(s),camera:u,rootLayout:t.layout,hasDives:i,diving:!1};g()},Gg=t=>t,Pg=Gg("RunText"),am=Gg("RunCode"),Ag=t=>e=>n=>e.length===0?n:Dt(n)({style:t,text:Nr(e)}),cm=t=>({style:(()=>{if(t.style==="RunText")return am;if(t.style==="RunCode")return Pg;g()})(),buf:[],runs:Ag(t.style)(t.buf)(t.runs)}),gm=t=>e=>0<e.length?{...t,buf:Dt(t.buf)(e[0])}:{...t,buf:Dt(t.buf)("\\")},fm=t=>e=>{let n=t,r=e,i=!0,o;for(;i;){const u=n,s=Mt(a=>J,a=>c=>T("Just",{head:a,tail:c}),r);if(s.tag==="Nothing"){i=!1,o=u;continue}if(s.tag==="Just"){if(s._1.head==="\\"){n=gm(u)(s._1.tail),r=kt(1,s._1.tail.length,s._1.tail);continue}if(s._1.head==="`"){n=cm(u),r=s._1.tail;continue}n={...u,buf:Dt(u.buf)(s._1.head)},r=s._1.tail;continue}g()}return o},Ig=t=>{const e=fm({style:Pg,buf:[],runs:[]})(Jr(t));return Ag(e.style)(e.buf)(e.runs)};let Gs=null;function _m(){return Gs||(typeof document>"u"?null:(Gs=document.createElement("canvas").getContext("2d"),Gs))}const Qg=new Map,dm=t=>e=>n=>r=>()=>{const i=`${n} ${e}px ${t}|${r}`,o=Qg.get(i);if(o!==void 0)return o;const u=_m();if(!u)return r.length*e*.62;u.font=`${n} ${e}px ${t}`;const s=u.measureText(r).width;return Qg.set(i,s),s},lm=lr.traverse(Du),hm=w(Mr)(0),Yr=(()=>{const t=or(`\r
|
|
3
|
-
`)(" "),e=
|
|
4
|
-
`)(" "),n=(()=>{const r=
|
|
5
|
-
`)(o._1))(Ps(i)),s=w(c=>f=>Vr(c)(tr(f)))(0)(u),a=o._2.shape==="Cylinder"?Vr(1)(An((s+2|0)+t.cellW|0,t.cellW)):r;return{...o._2,size:L(et(s>i?An((s+2|0)+t.cellW|0,t.cellW):a),et(Vr(1)(An(u.length+t.cellH|0,t.cellH))+(o._2.shape==="Cylinder"||o._2.shape==="Document"?1:0)|0))}})(n)}},Tm=t=>e=>n=>({...n,nodes:H(r=>{const i=xm(r.id)(e);if(i.tag==="Nothing")return r;if(i.tag==="Just")return{...r,size:L(ym(r.size._1)(et(Vr(1)(xe(no(r.shape==="Cylinder"?(i._1+0)/t:(i._1+32)/t))))),r.size._2)};g()})(n.nodes)}),vm=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bm=t=>{const e=t.length;return(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(a>=e){u=!1,s=c;continue}const f=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const y=_,x=h;if(y>=e){p=!1,m=x;continue}if(a>=0&&a<t.length){if(y>=0&&y<t.length){_=y+1|0,h=(()=>{const N=t[a].position,v=t[a].size,b=t[y].position,k=t[y].size;return N._1<b._1+k._1&&b._1<N._1+v._1&&N._2<b._2+k._2&&b._2<N._2+v._2})()?x+1|0:x;continue}_=y+1|0,h=x;continue}p=!1,m=x}return m};i=a+1|0,o=f(a+1|0)(c)}return s})(0)(0)},Bg=t=>w(e=>n=>e+jl(n.start)(n.end))(0)(t.segments),Lm=t=>e=>n=>({crossingCount:w(r=>i=>r+i.jumps.length|0)(0)(e),bendCount:w(r=>i=>r+i.bends.length|0)(0)(e),totalEdgeLength:w(r=>i=>r+Bg(i))(0)(e),maxEdgeLength:w(r=>i=>vm(r)(Bg(i)))(0)(e),nodeOverlapCount:bm(t),constraintViolations:n,jumpCount:w(r=>i=>r+i.jumps.length|0)(0)(e)}),As=t=>t,jt=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Is=As("LEFT"),km=As("RIGHT"),Mg=As("UNDEFINED"),Em={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},Sm={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?Ie:me;if(e==="LEFT")return ye;if(t==="RIGHT")return e==="RIGHT"?Ie:me;if(e==="RIGHT")return ye;if(t==="UP")return e==="UP"?Ie:me;if(e==="UP")return ye;if(t==="DOWN")return e==="DOWN"?Ie:me;if(e==="DOWN")return ye;if(t==="UNDEFINED"&&e==="UNDEFINED")return Ie;g()},Eq0:()=>Em},Cm=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){if(t==="LEFT"){if(o._3==="LEFT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="LEFT"){n=o._6;continue}if(t==="RIGHT"){if(o._3==="RIGHT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="RIGHT"){n=o._6;continue}if(t==="UP"){if(o._3==="UP"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="UP"){n=o._6;continue}if(t==="DOWN"){if(o._3==="DOWN"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="DOWN"){n=o._6;continue}if(t==="UNDEFINED"&&o._3==="UNDEFINED"){r=!1,i=!0;continue}}g()}return i},Gm={x:0,y:0},je=t=>e=>n=>{const r=jt(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:Z(nt)(t)(e(r._1))(n.cNodes)};g()},Si=t=>e=>n=>{const r=jt(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:Z(nt)(t)(e(r._1))(n.cGroups)};g()},Pm=t=>w(e=>n=>je(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),Am=t=>{const e=w(n=>r=>{const i=jt(r)(t.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just")return w(o=>u=>bt(nt)(ne)(u)([r])(o))(n)(i._1.constraints);g()})(D)(t.cNodeOrder);return w(n=>r=>je(r)(i=>({...i,constraints:(()=>{const o=jt(r)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})()}))(n))(t)(t.cNodeOrder)},Im=t=>e=>je(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}})),Qm=t=>{const e=w(n=>r=>Si(r)(i=>({...i,outDegree:i.outDegreeReal}))(n))(t)(t.cGroupOrder);return w(n=>r=>je(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder)},cn={left:!1,right:!1,up:!1,down:!1},Dm={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},Qs=t=>w(e=>n=>{const r=jt(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const i=w(u=>s=>{const a=jt(s)(e.cNodes);if(a.tag==="Nothing")return u;if(a.tag==="Just"){if(u.tag==="Nothing")return T("Just",s);if(u.tag==="Just"){const c=jt(u._1)(e.cNodes);if(c.tag==="Nothing")return T("Just",s);if(c.tag==="Just")return a._1.hitbox.x<c._1.hitbox.x?T("Just",s):T("Just",u._1)}}g()})(J)(r._1.cNodes),o=Si(n)(u=>({...u,reference:i}))(e);if(i.tag==="Nothing")return o;if(i.tag==="Just"){const u=jt(i._1)(o.cNodes);if(u.tag==="Nothing")return o;if(u.tag==="Just"){const s=u._1;return w(a=>c=>je(c)(f=>({...f,cGroupOffset:{x:f.hitbox.x-s.hitbox.x,y:f.hitbox.y-s.hitbox.y}}))(a))(o)(r._1.cNodes)}}}g()})(t)(t.cGroupOrder),Ze=t=>Qs({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return D;if(n.tag==="Node")return Ot("Node",n._1,n._2,n._3,{...n._4,hitbox:{...n._4.hitbox,x:-n._4.hitbox.x-n._4.hitbox.width}},e(n._5),e(n._6));g()};return e(t.cNodes)})()}),Tn=t=>Qs({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return D;if(n.tag==="Node")return Ot("Node",n._1,n._2,n._3,{...n._4,hitbox:{x:n._4.hitbox.y,y:n._4.hitbox.x,width:n._4.hitbox.height,height:n._4.hitbox.width},cGroupOffset:{x:n._4.cGroupOffset.y,y:n._4.cGroupOffset.x}},e(n._5),e(n._6));g()};return e(t.cNodes)})()}),Wg=t=>{const e=w(n=>r=>Si(r)(i=>({...i,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return w(n=>r=>{const i=jt(r)(n.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just"){if(i._1.cGroup.tag==="Nothing")return n;if(i._1.cGroup.tag==="Just"){const o=i._1.cGroup._1;return w(u=>s=>{const a=jt(s)(u.cNodes);if(a.tag==="Nothing")return u;if(a.tag==="Just")return a._1.cGroup.tag==="Just"&&a._1.cGroup._1!==o?Si(a._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(Si(o)(c=>He(Dr)(s)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,s]})(u)):u;g()})(n)(i._1.constraints)}}g()})(e)(e.cNodeOrder)},Mo=t=>{const e=Am(t.cGraph);return{...t,cGraph:Wg(w(n=>r=>je(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},Fm=t=>e=>w(n=>r=>{if(t==="LEFT"||t==="UP"){const o=r._2;return je(r._1)(u=>({...u,constraints:[...u.constraints,o]}))(n)}const i=r._1;return je(r._2)(o=>({...o,constraints:[...o.constraints,i]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),gn=t=>{const e={...t,cGraph:Fm(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return D;if(r.tag==="Node")return Ot("Node",r._1,r._2,r._3,{...r._4,constraints:[]},n(r._5),n(r._6));g()};return n(t.cGraph.cNodes)})()})};return{...e,cGraph:Wg((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);g()})())}},zm=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?gn(r):e==="RIGHT"?gn({...r,cGraph:Ze(r.cGraph)}):e==="UP"?gn({...r,cGraph:Tn(r.cGraph)}):e==="DOWN"?gn({...r,cGraph:Ze(Tn(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?Mo({...r,cGraph:Ze(r.cGraph)}):e==="UP"?gn({...r,cGraph:Tn(r.cGraph)}):e==="DOWN"?gn({...r,cGraph:Ze(Tn(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?Mo({...r,cGraph:Ze(r.cGraph)}):e==="UP"?gn({...r,cGraph:Tn(Ze(r.cGraph))}):e==="DOWN"?gn({...r,cGraph:Ze(Tn(Ze(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?gn({...r,cGraph:Tn(r.cGraph)}):e==="RIGHT"?gn({...r,cGraph:Ze(Tn(r.cGraph))}):e==="DOWN"?Mo({...r,cGraph:Ze(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?gn({...r,cGraph:Tn(Ze(r.cGraph))}):e==="RIGHT"?gn({...r,cGraph:Ze(Tn(Ze(r.cGraph)))}):e==="UP"?Mo({...r,cGraph:Ze(r.cGraph)}):r;g()},Rg=t=>e=>e.finished||!Cm(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:zm(e.direction)(t)(e),Bm=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?Rg(Is)(t):t,n={...e,cGraph:Qm(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},qg=t=>e=>n=>{const r=jt(t)(n.cNodes),i=jt(e)(n.cGroups);return r.tag==="Just"&&i.tag==="Just"?(()=>{if(r._1.cGroup.tag==="Nothing")return!1;if(r._1.cGroup.tag==="Just")return!0;g()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:Z(nt)(t)({...r._1,cGroup:T("Just",e)})(n.cNodes),cGroups:Z(nt)(e)({...i._1,cNodes:He(Dr)(t)(i._1.cNodes)?i._1.cNodes:[...i._1.cNodes,t],reference:(()=>{if(i._1.reference.tag==="Nothing")return T("Just",t);if(i._1.reference.tag==="Just")return T("Just",i._1.reference._1);g()})()})(n.cGroups)}:n},Hg=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:Z(nt)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:J,cGroupOffset:Gm,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:cn})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),Ds=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:w(r=>i=>qg(i)(n)(r))({...e,cGroups:Z(nt)(n)({id:n,master:t.master,cNodes:[],startPos:-1e308,incomingConstraints:[],outDegree:0,outDegreeReal:0,reference:J,delta:0,deltaNormalized:0})(e.cGroups),cGroupOrder:[...e.cGroupOrder,n],nextCGroupId:n+1|0})(t.nodes)}},Mm=t=>w(e=>n=>{const r=jt(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?Ds({master:J,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),Wm=t=>({cGraph:Pm(Mm(Qs(t))),direction:Mg,compactionAlgorithm:J,constraintAlgorithm:J,spacingsHandler:Dm,lockFun:J,finished:!1}),Rm=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},qm=t=>e=>{const n=rt.compare(t._1)(e._1);return n==="LT"?me:n==="GT"?ye:nt.compare(t._2)(e._2)},Hm=(()=>{const t=Ue.unfoldr(Jn);return e=>t(Ke("IterNode",e,Nn))})(),Og=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},$g=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",Xg=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),Wo=t=>e=>qm(L(t.hitbox.x+t.hitbox.width/2,t.id))(L(e.hitbox.x+e.hitbox.width/2,e.id)),Om=t=>e=>{const n=hr(Zt,J,r=>Wo(t)(r)==="LT",e);if(n.tag==="Just"){const r=sc(Zt,J,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return Dt(e)(t);g()},Yg=t=>e=>{const n=ut(i=>Wo(i)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?T("Just",n[r]):J},$m=t=>e=>{const n=Om(e)(t.intervals),r=Vt(o=>Wo(e)(o)==="LT")(n),i=Z(nt)(e.id)((()=>{const o=Yg(e)(n);return o.tag==="Just"?T("Just",o._1.id):J})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return Z(nt)(r._1.id)(T("Just",e.id))(i);if(r.tag==="Nothing")return i;g()})()}},Xm=t=>e=>{const n=rt.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?ye:Ie:e.low?me:Ie:n},Ym=t=>w(e=>n=>je(n.id)(r=>({...r,constraints:[]}))(e))(t)(xt(e=>jt(e)(t.cNodes))(t.cNodeOrder)),Fs=t=>e=>w(n=>r=>{const i=jt(r._1)(n.cNodes);if(i.tag==="Just")return je(r._1)(o=>({...o,constraints:[...o.constraints,...r._2]}))(n);if(i.tag==="Nothing")return n;g()})(e)(Hm(t)),Vg=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}},Ug=t=>e=>n=>w(r=>i=>n(i)?je(i.id)(Vg(t))(r):r)(e)(xt(r=>jt(r)(e.cNodes))(e.cNodeOrder)),Vm=t=>e=>{const n=(r,i,o)=>{const u=je(o)(Vg(t))(r);return i.length<=1?u:w(s=>a=>a===o?s:je(a)(c=>c.ignoreSpacing.up?{...c,hitbox:{...c.hitbox,y:c.hitbox.y+t+.01,height:c.hitbox.height-t-.01}}:c.ignoreSpacing.down?{...c,hitbox:{...c.hitbox,height:c.hitbox.height-t-.01}}:c)(s))(u)(i)};return w(r=>i=>{if(i.master.tag==="Nothing")return 0<i.cNodes.length?n(r,i.cNodes,i.cNodes[0]):r;if(i.master.tag==="Just")return n(r,i.cNodes,i.master._1);g()})(e)(xt(r=>jt(r)(e.cGroups))(e.cGroupOrder))},Um=t=>e=>{const n=Yg(e)(t.intervals),r=Vt(o=>Wo(e)(o)==="LT")(t.intervals),i=n.tag==="Just"&&(()=>{const o=Og(e.id)(t.cand);return(o.tag==="Nothing"?!1:o.tag==="Just"&&(o._1.tag==="Nothing"?!1:o._1.tag==="Just"&&o._1._1===n._1.id))&&n._1.cGroup.tag==="Just"&&e.cGroup.tag==="Just"&&n._1.cGroup._1!==e.cGroup._1})()?bt(nt)(ne)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const o=Og(r._1.id)(t.cand);return(o.tag==="Nothing"?!1:o.tag==="Just"&&(o._1.tag==="Nothing"?!1:o._1.tag==="Just"&&o._1._1===e.id))&&e.cGroup.tag==="Just"&&r._1.cGroup.tag==="Just"&&e.cGroup._1!==r._1.cGroup._1})()?bt(nt)(ne)(e.id)([r._1.id])(i):i,intervals:ut(o=>o.id!==e.id,t.intervals)}},Km=t=>e=>e.low?$m(t)(e.node):Um(t)(e.node),zs=t=>e=>w(Km)({intervals:[],cand:D,constraints:D})(Et(Xm)(Tt(ut(t,xt(n=>jt(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,jm=t=>e=>{const n=Rm(0)(t/2-.5),r=Fs(zs($g)(Ug(n)(e)($g)))(e),i=Fs(zs(Xg)(Ug(n)(r)(Xg)))(r);return Fs(zs(o=>!0)(Vm(n)(i)))(i)},Zm=t=>e=>jm(t)(Ym(e.cGraph)),Ro=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Kg=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Bs=t=>e=>n=>r=>i=>({id:t,representedEdges:[i],affectedBends:[e,n],hitbox:{x:Ro(e._1)(n._1),y:Ro(e._2)(n._2),width:yn(e._1-n._1),height:yn(e._2-n._2)},ignoreSpacing:cn,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:J}),ty=t=>e=>{const n=Ro(t.hitbox.x)(e.hitbox.x),r=Ro(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:Kg(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Kg(t.hitbox.y+t.hitbox.height)(e.hitbox.y+e.hitbox.height)-r},ignoreSpacing:{left:t.ignoreSpacing.left||e.ignoreSpacing.left,right:t.ignoreSpacing.right||e.ignoreSpacing.right,up:t.ignoreSpacing.up||e.ignoreSpacing.up,down:t.ignoreSpacing.down||e.ignoreSpacing.down},aPort:(()=>{if(t.aPort.tag==="Just")return t.aPort;if(t.aPort.tag==="Nothing")return e.aPort;g()})()}},ey=t=>e=>yn(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,ny=t=>e=>yn(t.hitbox.x-e.hitbox.x)<=1e-4?rt.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?me:ye,jg=(t,e)=>({tag:t,_1:e}),Ms=te(G)(Bt),qo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Zg=(()=>{const t={eq:n=>r=>n._1===r._1&&(n._2.tag==="Nothing"?r._2.tag==="Nothing":n._2.tag==="Just"&&r._2.tag==="Just"&&n._2._1===r._2._1)},e={compare:n=>r=>{const i=G.compare(n._1)(r._1);if(i==="LT")return me;if(i==="GT")return ye;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?Ie:me;if(r._2.tag==="Nothing")return ye;if(n._2.tag==="Just"&&r._2.tag==="Just")return G.compare(n._2._1)(r._2._1);g()},Eq0:()=>t};return w(n=>r=>Z(e)(r)()(n))(D)})(),Bn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},ry=w(t=>e=>Z(Sm)(e)()(t))(D),Ws=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=Sc.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},iy=t=>e=>{const n=Ms(H(o=>L(o.id,o))(t)),r=xt(o=>qo(o)(n))(e),i=nt.compare((()=>{const o=Zg(H(u=>L(u.from.node,u.from.port))(r));if(o.tag==="Leaf")return 0;if(o.tag==="Node")return o._2;g()})())((()=>{const o=Zg(H(u=>L(u.to.node,u.to.port))(r));if(o.tag==="Leaf")return 0;if(o.tag==="Node")return o._2;g()})());if(i==="LT")return{...cn,left:!0,right:!1};if(i==="GT")return{...cn,left:!1,right:!0};if(i==="EQ")return cn;g()},oy=t=>xt(e=>{if(e.direction==="V")return T("Just",{start:e.start,end:e.end});if(e.direction==="H")return J;g()})(t.segments),Ho=t=>e=>n=>r=>{if(r.tag==="Just"){const i=Bn(n)(e);if(i.tag==="Just"){const o=Vt(u=>u.id===r._1)(i._1);if(o.tag==="Just")return o._1.side;if(o.tag==="Nothing")return t;g()}if(i.tag==="Nothing")return t;g()}if(r.tag==="Nothing")return t;g()},uy=t=>e=>n=>{const r=Hg({origin:T("Just",jg("SegmentOrigin",n)),kind:T("Just","vs"),hitbox:n.hitbox})(e.cGraph),i=Im(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const o=jt(n.potentialGroupParents[0])(i.cNodes);if(o.tag==="Just"){if(o._1.cGroup.tag==="Just")return qg(r.id)(o._1.cGroup._1)(i);if(o._1.cGroup.tag==="Nothing")return i;g()}if(o.tag==="Nothing")return i;g()}return Ds({master:T("Just",r.id),nodes:[r.id]})(i).graph})(),edgeToCs:w(o=>u=>bt(G)(ne)(u)([r.id])(o))(e.edgeToCs)(n.representedEdges),lockMap:Z(nt)(r.id)(iy(t)(n.representedEdges))(e.lockMap)}},sy=t=>e=>n=>{const r=Mt(i=>J,i=>o=>T("Just",{head:i,tail:o}),Et(ny)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const i=w(o=>u=>ey(o.survivor)(u)?{...o,survivor:ty(o.survivor)(u)}:{survivor:u,merged:[...o.merged,o.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return w(uy(t))(n)([...i.merged,i.survivor])}g()},ay=t=>({cGraph:{cNodes:D,cNodeOrder:[],cGroups:D,cGroupOrder:[],supportedDirections:ry([Mg,Is,km]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:D,edgeToCs:D,lockMap:D}),cy=t=>{const e=et(4);return{x:t.position._1*e,y:t.position._2*e,width:t.size._1*e,height:t.size._2*e}},gy=t=>e=>n=>w(r=>i=>{const o=Hg({origin:T("Just",jg("NodeOrigin",i.node)),kind:J,hitbox:cy(i)})(r.cGraph),u=Bn(i.node)(t),s=(()=>{if(u.tag==="Nothing")return L(0,0);if(u.tag==="Just")return u._1;g()})();return{...r,cGraph:Ds({master:T("Just",o.id),nodes:[o.id]})(o.graph).graph,nodeToC:Z(G)(i.node)(o.id)(r.nodeToC),lockMap:Z(nt)(o.id)((()=>{const a=s._1-s._2|0;return a<0?{...cn,left:!0}:a>0?{...cn,right:!0}:cn})())(r.lockMap)}})(n)(e),fy=t=>w(e=>n=>bt(G)(r=>i=>L(r._1+i._1|0,r._2+i._2|0))(n.to.node)(L(1,0))(bt(G)(r=>i=>L(r._1+i._1|0,r._2+i._2|0))(n.from.node)(L(0,1))(e)))(D)(t),_y=t=>w(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?Z(G)(n.origin._1._1)(n.hitbox.x)(e):e)(D)(xt(e=>jt(e)(t.cNodes))(t.cNodeOrder)),dy=t=>w(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?Z(G)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(D)(xt(e=>jt(e)(t.cNodes))(t.cNodeOrder)),ly=t=>w(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return w(i=>o=>Z(Sc)(o)(r)(i))(e)(n.origin._1._1.affectedBends)}return e})(D)(xt(e=>jt(e)(t.cNodes))(t.cNodeOrder)),tf=t=>{const e=Ms(H(n=>L(n.id,n))(t.edges));return xt(n=>{const r=qo(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:Ho(Qn)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:Ho(Dn)(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:Ho(Qn)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:Ho(Dn)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return J;g()})(t.paths)},hy=t=>e=>{const n=Tt(e)(r=>{if(r.src===r.tgt)return[];if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return[];const i=Bn(r.tgt)(t.nodeToC),o=(()=>{if(i.tag==="Just")return jt(i._1)(t.cGraph.cNodes);if(i.tag==="Nothing")return J;g()})(),u=Bn(r.src)(t.nodeToC),s=(()=>{if(u.tag==="Just")return jt(u._1)(t.cGraph.cNodes);if(u.tag==="Nothing")return J;g()})(),a=(()=>{if(s.tag==="Just"){if(o.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(o._1.cGroup.tag==="Just")return T("Just",{srcGroup:s._1.cGroup._1,tgtGroup:o._1.cGroup._1,delta:0,weight:100});if(o._1.cGroup.tag==="Nothing")return J;g()}if(s._1.cGroup.tag==="Nothing")return J;g()}if(o.tag==="Nothing")return J;g()}if(s.tag==="Nothing")return J;g()})(),c=_=>h=>p=>{if(s.tag==="Just"){if(s._1.cGroup.tag==="Just"){if(p.cGroup.tag==="Just")return _(p.hitbox.x)&&p.cGroup._1!==s._1.cGroup._1?T("Just",h(p.cGroup._1)(s._1.cGroup._1)):J;if(p.cGroup.tag==="Nothing")return J;g()}if(s._1.cGroup.tag==="Nothing")return J;g()}if(s.tag==="Nothing")return J;g()},f=xt(_=>jt(_)(t.cGraph.cNodes))((()=>{const _=qo(r.edgeId)(t.edgeToCs);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})()),d=(()=>{if(s.tag==="Just"&&r.srcSide==="West"){const _=s._1;return xt(c(h=>h<_.hitbox.x)(h=>p=>({srcGroup:h,tgtGroup:p,delta:1,weight:100})))(f)}return[]})(),l=(()=>{if(s.tag==="Just"&&r.tgtSide==="East"){const _=s._1;return xt(c(h=>h>_.hitbox.x)(h=>p=>({srcGroup:p,tgtGroup:h,delta:1,weight:100})))(f)}return[]})();if(a.tag==="Nothing")return[];if(a.tag==="Just")return[a._1,...d,...l];g()});return{sameEdgeVerticalSegments:r=>i=>r.origin.tag==="Just"&&r.origin._1.tag==="SegmentOrigin"&&i.origin.tag==="Just"&&i.origin._1.tag==="SegmentOrigin"&&(()=>{const o=i.origin._1._1;return qe(u=>He(hn)(u)(o.representedEdges),r.origin._1._1.representedEdges)})(),vsLNodePair:r=>i=>r.origin.tag==="Just"&&i.origin.tag==="Just"&&(r.origin._1.tag==="SegmentOrigin"?i.origin._1.tag==="NodeOrigin":r.origin._1.tag==="NodeOrigin"&&i.origin._1.tag==="SegmentOrigin"),edgeLengthEdges:r=>n}},py=t=>e=>{const n=et(4),r=_y(t),i=dy(t),o=Ms(H(s=>L(s.id,L(s.from.node,s.to.node)))(e.edges)),u=ly(t);return{nodes:H(s=>{const a=Bn(s.node)(r);if(a.tag==="Just")return{...s,position:L(a._1/n,s.position._2)};if(a.tag==="Nothing")return s;g()})(e.nodes),edges:H(s=>{const a=qo(s.edge)(o),c=(()=>{if(a.tag==="Nothing")return s.segments;if(a.tag==="Just"){const f=Bn(a._1._1)(i),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})(),l=Bn(a._1._2)(i),_=(()=>{if(l.tag==="Nothing")return 0;if(l.tag==="Just")return l._1;g()})();return Ft((()=>{const h=s.reversed?_:d,p=s.reversed?d:_,m=s.segments.length;return y=>x=>{if(x.direction==="V"){const N=(()=>{if(y===0)return h;if(y===(m-1|0))return p;const v=Ws(x.start)(u);if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})();return{...x,start:L(x.start._1+N,x.start._2),end:L(x.end._1+N,x.end._2)}}if(x.direction==="H")return{...x,start:L((()=>{if(y===0)return x.start._1+h;const N=Ws(x.start)(u);if(N.tag==="Nothing")return x.start._1+0;if(N.tag==="Just")return x.start._1+N._1;g()})(),x.start._2),end:L((()=>{if(y===(m-1|0))return x.end._1+p;const N=Ws(x.end)(u);if(N.tag==="Nothing")return x.end._1+0;if(N.tag==="Just")return x.end._1+N._1;g()})(),x.end._2)};g()}})())(s.segments)}g()})();return{...s,segments:c,bends:be(f=>d=>f.end,c,kt(1,c.length,c))}})(e.paths)}},my=t=>e=>n=>r=>i=>o=>{const u=Bs(i.nextId)(o._2.start)(o._2.end)(J)(t.edgeId),s=(()=>{if(o._1===0){if(e.tag==="Nothing")return u;if(e.tag==="Just")return{...u,ignoreSpacing:o._2.end._2<e._1.y?{...u.ignoreSpacing,down:!0}:o._2.end._2>e._1.y+e._1.height?{...u.ignoreSpacing,up:!0}:{...u.ignoreSpacing,up:!0,down:!0}};g()}return u})();return{nextId:i.nextId+1|0,segments:[...i.segments,(()=>{if(o._1===r){if(n.tag==="Nothing")return s;if(n.tag==="Just")return{...s,ignoreSpacing:o._2.start._2<n._1.y?{...s.ignoreSpacing,down:!0}:o._2.start._2>n._1.y+n._1.height?{...s.ignoreSpacing,up:!0}:{...s.ignoreSpacing,up:!0,down:!0}};g()}return s})()]}},ef=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...Bs(o.nextId)(r.start)(L(r.start._1,i.down?n.y:n.y+n.height))(T("Just",e))(t.edgeId),aPort:T("Just",{node:t.src,side:i.side}),ignoreSpacing:i.down?{...cn,down:!0}:{...cn,up:!0}}]}),Oo=t=>e=>n=>r=>i=>o=>({nextId:o.nextId+1|0,segments:[...o.segments,{...Bs(o.nextId)(r.end)(L(r.end._1,i.down?n.y:n.y+n.height))(T("Just",e))(t.edgeId),aPort:T("Just",{node:t.tgt,side:i.side}),ignoreSpacing:i.down?{...cn,down:!0}:{...cn,up:!0}}]}),yy=t=>e=>n=>{if(n.src===n.tgt)return e;const r=Bn(n.src)(t.nodeToC),i=Bn(n.tgt)(t.nodeToC),o=(()=>{if(r.tag==="Just"){const f=jt(r._1)(t.cGraph.cNodes);return f.tag==="Just"?T("Just",f._1.hitbox):J}if(r.tag==="Nothing")return J;g()})(),u=(()=>{if(i.tag==="Just"){const f=jt(i._1)(t.cGraph.cNodes);return f.tag==="Just"?T("Just",f._1.hitbox):J}if(i.tag==="Nothing")return J;g()})(),s=oy(n.path),a=w(my(n)(o)(u)(s.length-1|0))(e)(Ft(f=>d=>L(f,d))(s));if(0<s.length){const f=(()=>{if(r.tag==="Just"&&o.tag==="Just"){if(n.srcSide==="North")return ef(n)(r._1)(o._1)(s[0])({side:de,down:!0})(a);if(n.srcSide==="South")return ef(n)(r._1)(o._1)(s[0])({side:le,down:!1})(a)}return a})(),d=s.length-1|0;if(d>=0&&d<s.length&&i.tag==="Just"&&u.tag==="Just"){if(n.tgtSide==="North")return Oo(n)(i._1)(u._1)(s[d])({side:de,down:!0})(f);if(n.tgtSide==="South")return Oo(n)(i._1)(u._1)(s[d])({side:le,down:!1})(f)}return f}const c=s.length-1|0;if(c>=0&&c<s.length&&i.tag==="Just"&&u.tag==="Just"){if(n.tgtSide==="North")return Oo(n)(i._1)(u._1)(s[c])({side:de,down:!0})(a);if(n.tgtSide==="South")return Oo(n)(i._1)(u._1)(s[c])({side:le,down:!1})(a)}return a},xy=t=>e=>n=>sy(t)(w(yy(n))({nextId:0,segments:[]})(e).segments)(n),Ny=t=>xy(t.edges)(tf(t))(gy(fy(t.edges))(t.nodes)(ay())),Mn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Rs=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},qs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Jy=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},wy=t=>{const e=t.Eq0();return n=>r=>{const i=s=>{let a=s,c=!0,f;for(;c;){const d=a,l=Mt(_=>J,_=>h=>T("Just",{head:_,tail:h}),d.queue);if(l.tag==="Nothing"){c=!1,f=d;continue}if(l.tag==="Just"){const _=l._1.head;if((p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=!1;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=!0;continue}}g()}return x})(d.removedNodes)){a={...d,queue:l._1.tail};continue}const h=Vt(p=>!Mn(p.eid)(d.removedEdges)&&(e.eq(p.src)(_)||e.eq(p.tgt)(_)))(r);if(h.tag==="Nothing"){a={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const p=e.eq(h._1.src)(_)?h._1.tgt:h._1.src,m={...d,degree:Z(t)(p)((()=>{const y=(x=>{let N=x,v=!0,b;for(;v;){const k=N;if(k.tag==="Leaf"){v=!1,b=J;continue}if(k.tag==="Node"){const E=t.compare(p)(k._3);if(E==="LT"){N=k._5;continue}if(E==="GT"){N=k._6;continue}if(E==="EQ"){v=!1,b=T("Just",k._4);continue}}g()}return b})(d.degree);if(y.tag==="Nothing")return-1;if(y.tag==="Just")return y._1-1|0;g()})())(d.degree),removedNodes:Z(t)(_)()(d.removedNodes),removedEdges:Z(nt)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:_,neighbour:p,viaSrc:e.eq(h._1.src)(_)}],queue:l._1.tail};if((()=>{const y=(N=>{let v=N,b=!0,k;for(;b;){const E=v;if(E.tag==="Leaf"){b=!1,k=J;continue}if(E.tag==="Node"){const A=t.compare(p)(E._3);if(A==="LT"){v=E._5;continue}if(A==="GT"){v=E._6;continue}if(A==="EQ"){b=!1,k=T("Just",E._4);continue}}g()}return k})(m.degree),x=N=>{let v=N,b=!0,k;for(;b;){const E=v;if(E.tag==="Leaf"){b=!1,k=!1;continue}if(E.tag==="Node"){const A=t.compare(p)(E._3);if(A==="LT"){v=E._5;continue}if(A==="GT"){v=E._6;continue}if(A==="EQ"){b=!1,k=!0;continue}}g()}return k};return(()=>{if(y.tag==="Nothing")return!1;if(y.tag==="Just")return y._1===1;g()})()&&!x(m.removedNodes)})()){a={...m,queue:[...m.queue,p]};continue}a=m;continue}}g()}return f},o=w(s=>a=>bt(t)(se)(a.src)(1)(bt(t)(se)(a.tgt)(1)(s)))(D)(r),u=i({degree:o,removedNodes:D,removedEdges:D,record:[],queue:ut(s=>{const a=(c=>{let f=c,d=!0,l;for(;d;){const _=f;if(_.tag==="Leaf"){d=!1,l=J;continue}if(_.tag==="Node"){const h=t.compare(s)(_._3);if(h==="LT"){f=_._5;continue}if(h==="GT"){f=_._6;continue}if(h==="EQ"){d=!1,l=T("Just",_._4);continue}}g()}return l})(o);if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1===1;g()},n)});return{coreNodes:ut(s=>!(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=!1;continue}if(l.tag==="Node"){const _=t.compare(s)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=!0;continue}}g()}return d})(u.removedNodes),n),coreEdges:ut(s=>!Mn(s.eid)(u.removedEdges),r),removed:u.record}}},Ty=t=>e=>n=>w(r=>i=>{const o=i.neighbour,u=(()=>{const s=(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=J;continue}if(l.tag==="Node"){const _=t.compare(o)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=T("Just",l._4);continue}}g()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})();return Z(t)(i.node)(i.viaSrc?u-1|0:u+1|0)(r)})(n)(ve(e)),Hs=t=>{const e=t.Eq0();return n=>r=>i=>{const o={...i,treeNode:Z(t)(r)()(i.treeNode)};return w(u=>s=>{if(Mn(s.eid)(u.st.edgeVisited))return u;const a={...u.st,edgeVisited:Z(nt)(s.eid)()(u.st.edgeVisited)},c=e.eq(s.src)((()=>{const f=s.src,d=_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(f)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=s.tgt;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?s.src:(()=>{const f=s.tgt,d=_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(f)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=s.src;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const y=h;if(y.tag==="Leaf"){p=!1,m=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){h=y._5;continue}if(x==="GT"){h=y._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(Mn(s.eid)(a.treeEdge)){if((d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=!1;continue}if(p.tag==="Node"){const m=t.compare(c)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=!0;continue}}g()}return h})(a.treeNode))return{...u,st:a};const f=Hs(t)(n)(c)(a);return{count:u.count+f.count|0,st:f.st}}if((()=>{const f=l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=!1;continue}if(m.tag==="Node"){const y=t.compare(c)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=!0;continue}}g()}return p},d=s.tgt;return!f(a.treeNode)&&(()=>{const l=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=J;continue}if(N.tag==="Node"){const v=t.compare(d)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=T("Just",N._4);continue}}g()}return x})(a.layer),_=s.src,h=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=J;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=T("Just",N._4);continue}}g()}return x})(a.layer);if(l.tag==="Nothing"){if(h.tag==="Nothing")return s.delta===0;if(h.tag==="Just")return s.delta===-h._1;g()}if(l.tag==="Just"){if(h.tag==="Nothing")return s.delta===(l._1-0|0);if(h.tag==="Just")return s.delta===(l._1-h._1|0)}g()})()})()){const f=Hs(t)(n)(c)({...a,treeEdge:Z(nt)(s.eid)()(a.treeEdge)});return{count:u.count+f.count|0,st:f.st}}return{...u,st:a}})({count:1,st:o})(ut(u=>(e.eq(u.src)(r)||e.eq(u.tgt)(r))&&!Mn(u.eid)(o.edgeVisited),n))}},$o=t=>e=>n=>r=>{const i=r.src,o=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const y=t.compare(i)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=T("Just",m._4);continue}}g()}return p})(e.poID),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})(),s=r.tgt,a=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const y=t.compare(s)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=T("Just",m._4);continue}}g()}return p})(e.poID),c=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})(),f=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const y=t.compare(n)(m._3);if(y==="LT"){_=m._5;continue}if(y==="GT"){_=m._6;continue}if(y==="EQ"){h=!1,p=T("Just",m._4);continue}}g()}return p})(e.poID),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return(()=>{const l=r.src,_=(h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=J;continue}if(x.tag==="Node"){const N=t.compare(l)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=T("Just",x._4);continue}}g()}return y})(e.lowestPoID);return(()=>{if(_.tag==="Nothing")return 0<=d;if(_.tag==="Just")return _._1<=d;g()})()&&(()=>{const h=r.tgt;return d<=u&&(()=>{const p=(m=>{let y=m,x=!0,N;for(;x;){const v=y;if(v.tag==="Leaf"){x=!1,N=J;continue}if(v.tag==="Node"){const b=t.compare(h)(v._3);if(b==="LT"){y=v._5;continue}if(b==="GT"){y=v._6;continue}if(b==="EQ"){x=!1,N=T("Just",v._4);continue}}g()}return N})(e.lowestPoID);return(()=>{if(p.tag==="Nothing")return 0<=d;if(p.tag==="Just")return p._1<=d;g()})()&&d<=c})()})()})()?u>=c:u<c},vy=t=>{const e=te(t)(Bt);return n=>({layer:e(H(r=>L(r,0))(n)),treeNode:D,treeEdge:D,poID:D,lowestPoID:D,cutvalue:D,postOrder:1,edgeVisited:D})},by=t=>e=>n=>w(r=>i=>{if((()=>{const f=i.src,d=h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=!1;continue}if(x.tag==="Node"){const N=t.compare(f)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=!0;continue}}g()}return y},l=i.tgt,_=h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=!1;continue}if(x.tag==="Node"){const N=t.compare(l)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=!0;continue}}g()}return y};return d(n.treeNode)===_(n.treeNode)})())return r;const o=i.tgt,u=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(o)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=T("Just",h._4);continue}}g()}return _})(n.layer),s=i.src,a=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(s)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=T("Just",h._4);continue}}g()}return _})(n.layer),c=(()=>{if(u.tag==="Nothing"){if(a.tag==="Nothing")return-i.delta;if(a.tag==="Just")return-a._1-i.delta|0;g()}if(u.tag==="Just"){if(a.tag==="Nothing")return(u._1-0|0)-i.delta|0;if(a.tag==="Just")return(u._1-a._1|0)-i.delta|0}g()})();return c<r.slack?{edge:T("Just",i),slack:c}:r})({edge:J,slack:1e9})(e).edge,Ly=t=>{const e=te(t)(Bt);return n=>r=>{const i=w(o=>u=>Rs(o)((()=>{const s=(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=J;continue}if(l.tag==="Node"){const _=t.compare(u)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=T("Just",l._4);continue}}g()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(1e9)(n);return e(H(o=>L(o,(()=>{const u=(s=>{let a=s,c=!0,f;for(;c;){const d=a;if(d.tag==="Leaf"){c=!1,f=J;continue}if(d.tag==="Node"){const l=t.compare(o)(d._3);if(l==="LT"){a=d._5;continue}if(l==="GT"){a=d._6;continue}if(l==="EQ"){c=!1,f=T("Just",d._4);continue}}g()}return f})(r);if(u.tag==="Nothing")return-i;if(u.tag==="Just")return u._1-i|0;g()})()))(n))}},nf=t=>{const e=t.Eq0();return n=>r=>i=>{const o=w(s=>a=>{const c=nf(t)(n)(e.eq(a.src)(r)?a.tgt:a.src)({...s.st,edgeVisited:Z(nt)(a.eid)()(s.st.edgeVisited)});return{lowest:Rs(s.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:i})(ut(s=>Mn(s.eid)(i.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!Mn(s.eid)(i.edgeVisited),n)),u=Rs(o.lowest)(o.st.postOrder);return{lowest:u,st:{...o.st,poID:Z(t)(r)(o.st.postOrder)(o.st.poID),lowestPoID:Z(t)(r)(u)(o.st.lowestPoID),postOrder:o.st.postOrder+1|0}}}},rf=t=>{const e=nf(t);return n=>r=>i=>0<n.length?e(r)(n[0])({...i,edgeVisited:D,postOrder:1,poID:D,lowestPoID:D}).st:i},ky=t=>{const e=t.Eq0();return n=>r=>i=>ut(o=>Mn(o.eid)(r.treeEdge)&&(e.eq(o.src)(i)||e.eq(o.tgt)(i)),n)},Ey=t=>e=>Vt(n=>{const r=qs(n.eid)(e.cutvalue);return Mn(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),of=t=>{const e=Hs(t);return n=>r=>i=>{const o=0<n.length?T("Just",n[0]):J;if(o.tag==="Nothing")return i;if(o.tag==="Just"){const u=e(r)(o._1)({...i,edgeVisited:D,treeNode:D,treeEdge:D});if(u.count>=n.length)return u.st;const s=by(t)(r)(u.st);if(s.tag==="Nothing")return u.st;if(s.tag==="Just"){const a=s._1.tgt,c=(h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=J;continue}if(x.tag==="Node"){const N=t.compare(a)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=T("Just",x._4);continue}}g()}return y})(u.st.layer),f=s._1.src,d=(h=>{let p=h,m=!0,y;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,y=J;continue}if(x.tag==="Node"){const N=t.compare(f)(x._3);if(N==="LT"){p=x._5;continue}if(N==="GT"){p=x._6;continue}if(N==="EQ"){m=!1,y=T("Just",x._4);continue}}g()}return y})(u.st.layer),l=(()=>{if(c.tag==="Nothing"){if(d.tag==="Nothing")return-s._1.delta;if(d.tag==="Just")return-d._1-s._1.delta|0;g()}if(c.tag==="Just"){if(d.tag==="Nothing")return(c._1-0|0)-s._1.delta|0;if(d.tag==="Just")return(c._1-d._1|0)-s._1.delta|0}g()})(),_=(()=>{const h=s._1.tgt;return(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=!1;continue}if(N.tag==="Node"){const v=t.compare(h)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=!0;continue}}g()}return x})(u.st.treeNode)})()?-l:l;return of(t)(n)(r)({...u.st,layer:w(h=>p=>(m=>{let y=m,x=!0,N;for(;x;){const v=y;if(v.tag==="Leaf"){x=!1,N=!1;continue}if(v.tag==="Node"){const b=t.compare(p)(v._3);if(b==="LT"){y=v._5;continue}if(b==="GT"){y=v._6;continue}if(b==="EQ"){x=!1,N=!0;continue}}g()}return N})(u.st.treeNode)?Z(t)(p)((()=>{const m=(y=>{let x=y,N=!0,v;for(;N;){const b=x;if(b.tag==="Leaf"){N=!1,v=J;continue}if(b.tag==="Node"){const k=t.compare(p)(b._3);if(k==="LT"){x=b._5;continue}if(k==="GT"){x=b._6;continue}if(k==="EQ"){N=!1,v=T("Just",b._4);continue}}g()}return v})(u.st.layer);if(m.tag==="Nothing")return 0+_|0;if(m.tag==="Just")return m._1+_|0;g()})())(h):h)(u.st.layer)(n)})}}g()}},Sy=t=>e=>n=>r=>w(i=>o=>{if($o(t)(r)(o.src)(n)&&!$o(t)(r)(o.tgt)(n)){const u=o.tgt,s=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=J;continue}if(p.tag==="Node"){const m=t.compare(u)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=T("Just",p._4);continue}}g()}return h})(r.layer),a=o.src,c=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=J;continue}if(p.tag==="Node"){const m=t.compare(a)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=T("Just",p._4);continue}}g()}return h})(r.layer),f=(()=>{if(s.tag==="Nothing"){if(c.tag==="Nothing")return-o.delta;if(c.tag==="Just")return-c._1-o.delta|0;g()}if(s.tag==="Just"){if(c.tag==="Nothing")return(s._1-0|0)-o.delta|0;if(c.tag==="Just")return(s._1-c._1|0)-o.delta|0}g()})();if(f<i.slack)return{edge:T("Just",o),slack:f}}return i})({edge:J,slack:1e9})(e).edge,Cy=t=>{const e=t.Eq0();return n=>r=>i=>o=>{const u=o.tgt,s=o.src;return w(a=>c=>{if((()=>{const f=qs(c.eid)(r.cutvalue);if(f.tag==="Just")return!0;if(f.tag==="Nothing")return!1;g()})()){const f=qs(c.eid)(r.cutvalue),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return e.eq(s)(c.src)||e.eq(u)(c.tgt)?a-(d-c.weight):a+(d-c.weight)}return e.eq(i)(s)?e.eq(c.src)(i)?a+c.weight:a-c.weight:e.eq(c.src)(i)?a-c.weight:a+c.weight})(o.weight)(ut(a=>a.eid!==o.eid&&(e.eq(a.src)(i)||e.eq(a.tgt)(i)),n))}},Gy=t=>{const e=Cy(t);return n=>r=>i=>{const o=(u,s,a)=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(u)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=T("Just",h._4);continue}}g()}return _})(a);if(c.tag==="Just")return Z(t)(u)(ut(f=>f.eid!==s.eid,c._1))(a);if(c.tag==="Nothing")return a;g()};return(u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=(m=>{let y=m,x=!0,N;for(;x;){const v=y;if(v.tag==="Leaf"){x=!1,N=J;continue}if(v.tag==="Node"){const b=t.compare(_)(v._3);if(b==="LT"){y=v._5;continue}if(b==="GT"){y=v._6;continue}if(b==="EQ"){x=!1,N=T("Just",v._4);continue}}g()}return N})(l.unknown),p=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;g()})();if(p.length===1){const m=t.Eq0().eq(p[0].src)(_)?p[0].tgt:p[0].src;a={unknown:o(_,p[0],o(m,p[0],l.unknown)),cutvalue:Z(nt)(p[0].eid)(e(n)(l)(_)(p[0]))(l.cutvalue)},c=m;continue}f=!1,d=l}return d})(r)(i)}},uf=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:c=>f=>c.delta===f.delta&&c.eid===f.eid&&n.eq(c.src)(f.src)&&e.eq(c.tgt)(f.tgt)&&c.weight===f.weight},i={compare:c=>f=>{const d=nt.compare(c.delta)(f.delta);if(d==="LT"||d==="GT"||d!=="EQ")return d;const l=nt.compare(c.eid)(f.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const _=t.compare(c.src)(f.src);if(_==="LT"||_==="GT"||_!=="EQ")return _;const h=t.compare(c.tgt)(f.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const p=rt.compare(c.weight)(f.weight);return p==="LT"||p==="GT"||p!=="EQ"?p:Ie},Eq0:()=>r},o=w(c=>f=>Z(i)(f)()(c))(D),u=ky(t),s=te(t)(Bt),a=Gy(t);return c=>f=>d=>{const l={unknown:s(H(_=>L(_,At($e.foldr,o(u(f)(d)(_)))))(c)),cutvalue:D};return{...d,cutvalue:w(a(f))(l)(ut(_=>{const h=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=J;continue}if(N.tag==="Node"){const v=t.compare(_)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=T("Just",N._4);continue}}g()}return x})(l.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;g()},c)).cutvalue}}},Py=t=>{const e=rf(t),n=uf(t);return r=>i=>o=>u=>s=>{const a={...s,treeEdge:Z(nt)(u.eid)()(di(nt)(o.eid)(s.treeEdge))},c=u.tgt,f=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=J;continue}if(N.tag==="Node"){const v=t.compare(c)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=T("Just",N._4);continue}}g()}return x})(a.layer),d=u.src,l=(p=>{let m=p,y=!0,x;for(;y;){const N=m;if(N.tag==="Leaf"){y=!1,x=J;continue}if(N.tag==="Node"){const v=t.compare(d)(N._3);if(v==="LT"){m=N._5;continue}if(v==="GT"){m=N._6;continue}if(v==="EQ"){y=!1,x=T("Just",N._4);continue}}g()}return x})(a.layer),_=(()=>{if(f.tag==="Nothing"){if(l.tag==="Nothing")return-u.delta;if(l.tag==="Just")return-l._1-u.delta|0;g()}if(f.tag==="Just"){if(l.tag==="Nothing")return(f._1-0|0)-u.delta|0;if(l.tag==="Just")return(f._1-l._1|0)-u.delta|0}g()})(),h=$o(t)(a)(u.tgt)(o)?_:-_;return n(r)(i)(e(r)(i)({...a,layer:w(p=>m=>$o(t)(a)(m)(o)?p:Z(t)(m)((()=>{const y=(x=>{let N=x,v=!0,b;for(;v;){const k=N;if(k.tag==="Leaf"){v=!1,b=J;continue}if(k.tag==="Node"){const E=t.compare(m)(k._3);if(E==="LT"){N=k._5;continue}if(E==="GT"){N=k._6;continue}if(E==="EQ"){v=!1,b=T("Just",k._4);continue}}g()}return b})(a.layer);if(y.tag==="Nothing")return 0+h|0;if(y.tag==="Just")return y._1+h|0;g()})())(p))(a.layer)(r)}))}},Ay=t=>{const e=Py(t);return n=>r=>i=>o=>(u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c;if(l===0){f=!1,d=_;continue}const h=Ey(i)(_);if(h.tag==="Nothing"){f=!1,d=_;continue}if(h.tag==="Just"){const p=Sy(t)(i)(h._1)(_);if(p.tag==="Nothing"){f=!1,d=_;continue}if(p.tag==="Just"){a=l-1|0,c=e(r)(i)(h._1)(p._1)(_);continue}}g()}return d})(n)(o)},Iy=t=>{const e=uf(t),n=rf(t),r=of(t);return i=>o=>u=>e(i)(o)(n(i)(o)(r(i)(o)(u)))},sf=t=>e=>w(n=>r=>bt(t)(ne)(e(r))([r])(n))(D),Qy=t=>{const e=te(t)(Bt);return n=>r=>i=>{const o=a=>c=>f=>d=>{let l=a,_=c,h=f,p=d,m=!0,y;for(;m;){const x=l,N=_,v=h,b=p,k=Mt(E=>J,E=>A=>T("Just",{head:E,tail:A}),v);if(k.tag==="Nothing"){m=!1,y=b;continue}if(k.tag==="Just"){const E=k._1.head,A=(S=>{let C=S,V=!0,U;for(;V;){const M=C;if(M.tag==="Leaf"){V=!1,U=J;continue}if(M.tag==="Node"){const W=t.compare(E)(M._3);if(W==="LT"){C=M._5;continue}if(W==="GT"){C=M._6;continue}if(W==="EQ"){V=!1,U=T("Just",M._4);continue}}g()}return U})(b.layer),$=(()=>{if(A.tag==="Nothing")return 0;if(A.tag==="Just")return A._1;g()})(),tt=w(S=>C=>{const V=C.tgt,U=(W=>{let B=W,P=!0,I;for(;P;){const F=B;if(F.tag==="Leaf"){P=!1,I=J;continue}if(F.tag==="Node"){const Q=t.compare(V)(F._3);if(Q==="LT"){B=F._5;continue}if(Q==="GT"){B=F._6;continue}if(Q==="EQ"){P=!1,I=T("Just",F._4);continue}}g()}return I})(S.incident),M=(()=>{if(U.tag==="Nothing")return-1;if(U.tag==="Just")return U._1-1|0;g()})();return{st:{...S.st,layer:Z(t)(C.tgt)(Jy((()=>{const W=C.tgt,B=(P=>{let I=P,F=!0,Q;for(;F;){const R=I;if(R.tag==="Leaf"){F=!1,Q=J;continue}if(R.tag==="Node"){const Y=t.compare(W)(R._3);if(Y==="LT"){I=R._5;continue}if(Y==="GT"){I=R._6;continue}if(Y==="EQ"){F=!1,Q=T("Just",R._4);continue}}g()}return Q})(S.st.layer);if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})())($+C.delta|0))(S.st.layer)},incident:Z(t)(C.tgt)(M)(S.incident),queue:M===0?[...S.queue,C.tgt]:S.queue}})({st:b,incident:N,queue:k._1.tail})((()=>{const S=(C=>{let V=C,U=!0,M;for(;U;){const W=V;if(W.tag==="Leaf"){U=!1,M=J;continue}if(W.tag==="Node"){const B=t.compare(E)(W._3);if(B==="LT"){V=W._5;continue}if(B==="GT"){V=W._6;continue}if(B==="EQ"){U=!1,M=T("Just",W._4);continue}}g()}return M})(x);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})());l=x,_=tt.incident,h=tt.queue,p=tt.st;continue}g()}return y},u=sf(t)(a=>a.tgt)(r),s=e(H(a=>L(a,(()=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=T("Just",h._4);continue}}g()}return _})(u);if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1.length;g()})()))(n));return o(sf(t)(a=>a.src)(r))(s)(ut(a=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=J;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=T("Just",h._4);continue}}g()}return _})(s);if(c.tag==="Nothing")return!0;if(c.tag==="Just")return c._1===0;g()},n))(i)}},Dy=t=>{const e=vy(t),n=Qy(t),r=Iy(t),i=Ay(t);return o=>u=>{const s=n(o)(u)(e(o));return u.length===0?s.layer:i(4*o.length|0)(o)(u)(r(o)(u)(s)).layer}},af=t=>{const e=Ly(t),n=Dy(t),r=wy(t);return i=>o=>{if(i.length===0)return D;if(i.length<40)return e(i)(n(i)(o));const u=r(i)(o);return e(i)(Ty(t)(u.removed)(n(u.coreNodes)(u.coreEdges)))}},cf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Os=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Fy=af(nt),Ci=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}),zy=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=et((()=>{const i=cf(n.cGroup._1)(t);if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})());return je(n.id)(i=>({...i,hitbox:{...i.hitbox,x:r+i.cGroupOffset.x}}))(e)}g()},By=t=>e=>({...e,cGraph:w(zy(t))(e.cGraph)((()=>{const n=e.cGraph;return xt(r=>jt(r)(n.cNodes))(n.cNodeOrder)})())}),My=t=>e=>n=>r=>i=>{const o=xe(no(e.cGroupOffset.x-t.cGroupOffset.x));return Ci({src:i.nextNodeId,tgt:r,delta:Os(0)(-o),weight:1})(Ci({src:i.nextNodeId,tgt:n,delta:Os(0)(o),weight:1})({...i,nodes:[...i.nodes,i.nextNodeId],nextNodeId:i.nextNodeId+1|0}))},Wy=t=>e=>n=>r=>i=>o=>u=>{const s=Os(0)(xe(no(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)?My(n)(r)(i)(o)(u):Ci({src:i,tgt:o,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(u)},Ry=t=>e=>n=>r=>i=>{const o=jt(i)(e.cGraph.cNodes);if(o.tag==="Nothing")return r;if(o.tag==="Just")return(n.cGroup.tag==="Nothing"?o._1.cGroup.tag==="Nothing":n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"&&n.cGroup._1===o._1.cGroup._1)?r:n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"?Wy(t)(e)(n)(o._1)(n.cGroup._1)(o._1.cGroup._1)(r):r;g()},qy=t=>e=>n=>r=>w(Ry(t)(e)(r))(n)(r.constraints),Hy=t=>e=>Ci({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),Oy=t=>{const e=w(i=>o=>bt(nt)(se)(o.tgt)(1)(i))(D)(t.edges),n=ut(i=>{const o=cf(i)(e);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return o._1===0;g()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return w(i=>o=>Ci({src:r,tgt:o,delta:1,weight:0})(i))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},$y=t=>e=>{const n=Oy(w(Hy)(w(qy(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return xt(i=>jt(i)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},Xy=t=>e=>{const n=$y(t)(e);return By(Fy(n.nodes)(n.edges))(e)},gf=t=>t,re=gf("H"),ie=gf("V"),Yy=t=>L(t._2,t._1),ff=t=>({...t,position:L(t.position._2,t.position._1),size:L(t.size._2,t.size._1)}),Vy=t=>({start:L(t.start._2,t.start._1),end:L(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return ie;if(t.direction==="V")return re;g()})()}),_f=t=>({...t,segments:H(Vy)(t.segments),bends:H(Yy)(t.bends)}),Uy=t=>({nodes:H(ff)(t.nodes),edges:t.edges,paths:H(_f)(t.paths),ports:t.ports}),Ky={nodeNode:8,edgeNode:4,edgeEdge:10},jy=t=>e=>({horizontalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r)||n.ignoreSpacing.right||r.ignoreSpacing.left)return 0;const i=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"?i?t.edgeEdge:t.edgeNode:i?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 i=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"?i?t.edgeEdge:t.edgeNode:i?t.edgeNode:t.nodeNode}}),Zy=t=>e=>Xy(e),tx=t=>e=>n=>{const r=Uy(n),i=Ny(r),o=hy(i)(tf(r)),u=py(Rg(Is)(Bm({...Wm(i.cGraph),compactionAlgorithm:T("Just",Zy()(o)),constraintAlgorithm:T("Just",Zm(e.edgeEdge)),spacingsHandler:jy(e)(o)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:H(ff)(u.nodes),edges:H(_f)(u.edges)}},df=t=>t,Ur=te(nt)(Bt),It=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},lf=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},lt=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ht=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Kr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},ex=t=>e=>{const n=nt.compare(t._1)(e._1);return n==="LT"?me:n==="GT"?ye:nt.compare(t._2)(e._2)},jr=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},nx=(()=>{const t=Ue.unfoldr(Jn);return e=>t(Ke("IterNode",e,Nn))})(),rx=t=>t,hf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},ix=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Xo=df("Regular"),Yo=df("Critical"),pf=t=>e=>{const n=w(u=>s=>Z(G)(s.node)(s)(u))(D)(e),r=1.25*et(4),i=(u,s,a)=>(c=>f=>d=>{let l=c,_=f,h=d,p=!0,m;for(;p;){const y=l,x=_,N=h;if(N.critical){p=!1,m=N;continue}const v=Mt(k=>J,k=>E=>T("Just",{head:k,tail:E}),y),b=Mt(k=>J,k=>E=>T("Just",{head:k,tail:E}),x);if(v.tag==="Just"&&b.tag==="Just"){const k=v._1.head>b._1.head-u&&v._1.head<b._1.head+u?{...N,critical:!0}:v._1.head>b._1.head-r&&v._1.head<b._1.head+r?{...N,conflicts:N.conflicts+1|0}:N;if(k.critical){p=!1,m=k;continue}if(v._1.head<=b._1.head){l=v._1.tail,_=x,h=k;continue}l=y,_=b._1.tail,h=k;continue}p=!1,m=N}return m})(s)(a)({conflicts:0,critical:!1}),o=(u,s,a)=>{if(ht(w(ht)(-1e18)(s.incoming))(w(ht)(-1e18)(s.outgoing))-lt(w(lt)(1e18)(s.incoming))(w(lt)(1e18)(s.outgoing))<.001||ht(w(ht)(-1e18)(a.incoming))(w(ht)(-1e18)(a.outgoing))-lt(w(lt)(1e18)(a.incoming))(w(lt)(1e18)(a.outgoing))<.001)return[];const c=i(u,s.outgoing,a.incoming),f=i(u,a.outgoing,s.incoming);if(c.critical||f.critical)return[...c.critical?[{src:a.id,tgt:s.id,weight:1,kind:Yo}]:[],...f.critical?[{src:s.id,tgt:a.id,weight:1,kind:Yo}]:[]];const d=lt(w(lt)(1e18)(s.incoming))(w(lt)(1e18)(s.outgoing)),l=ht(w(ht)(-1e18)(s.incoming))(w(ht)(-1e18)(s.outgoing)),_=lt(w(lt)(1e18)(a.incoming))(w(lt)(1e18)(a.outgoing)),h=ht(w(ht)(-1e18)(a.incoming))(w(ht)(-1e18)(a.outgoing)),p=(1*c.conflicts|0)+(16*(w(y=>x=>x>h?y:x>=_?y+1|0:y)(0)(s.outgoing)+w(y=>x=>x>l?y:x>=d?y+1|0:y)(0)(a.incoming)|0)|0)|0,m=(1*f.conflicts|0)+(16*(w(y=>x=>x>l?y:x>=d?y+1|0:y)(0)(a.outgoing)+w(y=>x=>x>h?y:x>=_?y+1|0:y)(0)(s.incoming)|0)|0)|0;return p<m?[{src:s.id,tgt:a.id,weight:m-p|0,kind:Xo}]:p>m?[{src:a.id,tgt:s.id,weight:p-m|0,kind:Xo}]:p>0?[{src:s.id,tgt:a.id,weight:0,kind:Xo},{src:a.id,tgt:s.id,weight:0,kind:Xo}]:[]};return w(u=>s=>w(a=>c=>Z(G)(c._1)(c._2)(a))(u)((()=>{const a=w(S=>C=>{const V=C.edge.from.node+"|"+(()=>{if(C.edge.from.port.tag==="Just")return C.edge.from.port._1;if(C.edge.from.port.tag==="Nothing")return"_auto_"+C.edge.id;g()})(),U=hf(V)(S.entries);if(U.tag==="Nothing")return{...S,entries:Z(G)(V)({id:0,members:[C.edge.id],incoming:[C.fromPos._1],outgoing:[C.toPos._1],slot:0,mark:0,splitBy:J,splitPartner:J})(S.entries),order:[...S.order,V]};if(U.tag==="Just")return{...S,entries:Z(G)(V)({...U._1,members:[...U._1.members,C.edge.id],incoming:[...mr(M=>M<C.fromPos._1)(U._1.incoming).init,C.fromPos._1,...mr(M=>M<=C.fromPos._1)(U._1.incoming).rest],outgoing:[...mr(M=>M<C.toPos._1)(U._1.outgoing).init,C.toPos._1,...mr(M=>M<=C.toPos._1)(U._1.outgoing).rest]})(S.entries)};g()})({entries:D,order:[]})(s._2),c=Ft(S=>C=>({...C,id:S}))(xt(S=>hf(S)(a.entries))(a.order));if(c.length===0)return[];const f=w(S=>C=>S.prev.tag==="Just"&&C-S.prev._1<1e-9?S:{prev:T("Just",C),out:[...S.out,C]})({prev:J,out:[]})(Et(rt.compare)([...Tt(c)(S=>S.incoming),...Tt(c)(S=>S.outgoing)])).out,d=f.length<2?.2*r:.2*w(S=>C=>{if(S.prev.tag==="Nothing")return{prev:T("Just",C),mn:S.mn};if(S.prev.tag==="Just")return{prev:T("Just",C),mn:lt(S.mn)(C-S.prev._1)};g()})({prev:J,mn:1e18})(f).mn,l={segments:c,deps:(()=>{const S=c.length;return Tt(Tt(zt(0,S-2|0))(C=>Tt(zt(C+1|0,S-1|0))(V=>[L(C,V)])))(C=>C._1>=0&&C._1<c.length?C._2>=0&&C._2<c.length?o(d,c[C._1],c[C._2]):[]:[])})()},_=ut(S=>{if(S.kind==="Critical")return!0;if(S.kind==="Regular")return!1;g()},l.deps),h=(()=>{if(_.length<2)return l;const S=Ur((()=>{const W=l.segments;return H(B=>L(B.id,B.mark))((()=>{const B=W.length,P=F=>{let Q=F,R=!0,Y;for(;R;){const O=Q,X=Vt(q=>{const K=It(q)(O.inWeight);if(K.tag==="Nothing")return!0;if(K.tag==="Just")return K._1===0;g()})(O.remaining);if(X.tag==="Nothing"){R=!1,Y=O;continue}if(X.tag==="Just"){const q=X._1;Q={...O,inWeight:w(K=>j=>bt(nt)(se)(j.tgt)(-j.weight)(K))(O.inWeight)((()=>{const K=It(q)(O.depsBySrc);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),marks:Z(nt)(q)(O.nextSource)(O.marks),nextSource:O.nextSource+1|0,outWeight:w(K=>j=>bt(nt)(se)(j.src)(-j.weight)(K))(O.outWeight)((()=>{const K=It(q)(O.depsByTgt);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),remaining:ut(K=>K!==q,O.remaining)};continue}g()}return Y},I=F=>{let Q=F,R=!0,Y;for(;R;){const O=Q,X=Vt(q=>{const K=It(q)(O.outWeight);if(K.tag==="Nothing")return!0;if(K.tag==="Just")return K._1===0;g()})(O.remaining);if(X.tag==="Nothing"){R=!1,Y=O;continue}if(X.tag==="Just"){const q=X._1;Q={...O,inWeight:w(K=>j=>bt(nt)(se)(j.tgt)(-j.weight)(K))(O.inWeight)((()=>{const K=It(q)(O.depsBySrc);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),marks:Z(nt)(q)(O.nextSink)(O.marks),nextSink:O.nextSink-1|0,outWeight:w(K=>j=>bt(nt)(se)(j.src)(-j.weight)(K))(O.outWeight)((()=>{const K=It(q)(O.depsByTgt);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;g()})()),remaining:ut(K=>K!==q,O.remaining)};continue}g()}return Y};return(F=>{let Q=F,R=!0,Y;for(;R;){const O=P(I(Q));if(O.remaining.length===0){R=!1,Y=H(X=>{const q=It(X.id)(O.marks),K=(()=>{if(q.tag==="Nothing")return X.id;if(q.tag==="Just")return q._1;g()})();return{...X,mark:K<B?(K+B|0)+1|0:K}})(W);continue}Q=(()=>{const X=K=>{const j=It(K)(O.outWeight),ot=It(K)(O.inWeight);return(()=>{if(j.tag==="Nothing")return 0;if(j.tag==="Just")return j._1;g()})()-(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;g()})()|0},q=Et(K=>j=>nt.compare(X(j))(X(K)))(O.remaining);if(0<q.length){const K=q[0];return{...O,inWeight:w(j=>ot=>bt(nt)(se)(ot.tgt)(-ot.weight)(j))(O.inWeight)((()=>{const j=It(K)(O.depsBySrc);if(j.tag==="Nothing")return[];if(j.tag==="Just")return j._1;g()})()),marks:Z(nt)(K)(O.nextSource)(O.marks),nextSource:O.nextSource+1|0,outWeight:w(j=>ot=>bt(nt)(se)(ot.src)(-ot.weight)(j))(O.outWeight)((()=>{const j=It(K)(O.depsByTgt);if(j.tag==="Nothing")return[];if(j.tag==="Just")return j._1;g()})()),remaining:ut(j=>j!==K,O.remaining)}}return O})()}return Y})({remaining:H(F=>F.id)(W),marks:D,inWeight:w(F=>Q=>bt(nt)(se)(Q.tgt)(Q.weight)(F))(D)(_),outWeight:w(F=>Q=>bt(nt)(se)(Q.src)(Q.weight)(F))(D)(_),depsBySrc:w(F=>Q=>bt(nt)(ne)(Q.src)([Q])(F))(D)(_),depsByTgt:w(F=>Q=>bt(nt)(ne)(Q.tgt)([Q])(F))(D)(_),nextSink:B-1|0,nextSource:B+1|0})})())})()),C=ut(W=>{const B=It(W.src)(S),P=It(W.tgt)(S);return(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})()>(()=>{if(P.tag==="Nothing")return 0;if(P.tag==="Just")return P._1;g()})()},_);if(C.length===0)return l;const V=w(W=>B=>{if(He(Dr)(B.src)(W.decisions)||He(Dr)(B.tgt)(W.decisions))return W;const P=It(B.src)(W.segMap),I=It(B.tgt)(W.segMap);if(P.tag==="Just"&&I.tag==="Just"){const F=(P._1.incoming.length+P._1.outgoing.length|0)>2&&(I._1.incoming.length+I._1.outgoing.length|0)<=2,Q=F?I._1:P._1;return{decisions:[...W.decisions,Q.id],segMap:Z(nt)(Q.id)({...Q,splitBy:T("Just",F?P._1.id:I._1.id)})(W.segMap)}}return W})({decisions:[],segMap:Ur(H(W=>L(W.id,W))(l.segments))})(C),U=V.segMap,M=w(W=>B=>{const P=lt(w(lt)(1e18)(B.incoming))(w(lt)(1e18)(B.outgoing)),I=ht(w(ht)(-1e18)(B.incoming))(w(ht)(-1e18)(B.outgoing)),F=ut(X=>X.a.startPosition<=I&&X.a.endPosition>=P,Ft(X=>q=>({i:X,a:q}))(W.freeAreas));if(F.length===0){const X={...B,incoming:Et(rt.compare)(B.incoming),outgoing:Et(rt.compare)([(P+I)/2]),splitPartner:T("Just",W.nextId)},q={id:W.nextId,incoming:Et(rt.compare)([(P+I)/2]),mark:0,members:B.members,outgoing:Et(rt.compare)(B.outgoing),slot:0,splitBy:J,splitPartner:T("Just",B.id)};return{segMap:Z(nt)(q.id)(q)(Z(nt)(X.id)(X)(W.segMap)),freeAreas:W.freeAreas,nextId:W.nextId+1|0}}const Q=0<F.length?T("Just",F[0]):J,R=(()=>{if(Q.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(Q.tag==="Just"){if(F.length===1)return Q._1;const X=H(q=>({c:q,rating:(()=>{const K=(q.a.startPosition+q.a.endPosition)/2,j=[K],ot=[K],_t=w((()=>{const yt=W.segMap;return Ct=>Rt=>{const pt=It(Rt.tgt)(yt);if(pt.tag==="Nothing")return Ct;if(pt.tag==="Just"){const qt=lt(w(lt)(1e18)(pt._1.incoming))(w(lt)(1e18)(pt._1.outgoing)),wt=ht(w(ht)(-1e18)(pt._1.incoming))(w(ht)(-1e18)(pt._1.outgoing)),mt=lt(w(lt)(1e18)(B.incoming))(w(lt)(1e18)(j)),ft=(()=>{const Pt=ht(w(ht)(-1e18)(B.incoming))(w(ht)(-1e18)(j)),Qt=w($t=>_e=>_e>wt?$t:_e>=qt?$t+1|0:$t)(0)(j)+w($t=>_e=>_e>Pt?$t:_e>=mt?$t+1|0:$t)(0)(pt._1.incoming)|0,ze=lt(w(lt)(1e18)(B.incoming))(w(lt)(1e18)(j)),an=ht(w(ht)(-1e18)(B.incoming))(w(ht)(-1e18)(j)),Xe=lt(w(lt)(1e18)(pt._1.incoming))(w(lt)(1e18)(pt._1.outgoing)),nn=ht(w(ht)(-1e18)(pt._1.incoming))(w(ht)(-1e18)(pt._1.outgoing)),Ae=w($t=>_e=>_e>an?$t:_e>=ze?$t+1|0:$t)(0)(pt._1.outgoing)+w($t=>_e=>_e>nn?$t:_e>=Xe?$t+1|0:$t)(0)(B.incoming)|0;return Qt===Ae?Qt>0?{...Ct,deps:Ct.deps+2|0,crossings:Ct.crossings+Qt|0}:Ct:{...Ct,deps:Ct.deps+1|0,crossings:Ct.crossings+jr(Qt)(Ae)|0}})(),st=lt(w(lt)(1e18)(pt._1.incoming))(w(lt)(1e18)(pt._1.outgoing)),dt=ht(w(ht)(-1e18)(pt._1.incoming))(w(ht)(-1e18)(pt._1.outgoing)),at=lt(w(lt)(1e18)(ot))(w(lt)(1e18)(B.outgoing)),ct=ht(w(ht)(-1e18)(ot))(w(ht)(-1e18)(B.outgoing)),Nt=w(Pt=>Qt=>Qt>dt?Pt:Qt>=st?Pt+1|0:Pt)(0)(B.outgoing)+w(Pt=>Qt=>Qt>ct?Pt:Qt>=at?Pt+1|0:Pt)(0)(pt._1.incoming)|0,Jt=lt(w(lt)(1e18)(ot))(w(lt)(1e18)(B.outgoing)),Lt=ht(w(ht)(-1e18)(ot))(w(ht)(-1e18)(B.outgoing)),Ht=lt(w(lt)(1e18)(pt._1.incoming))(w(lt)(1e18)(pt._1.outgoing)),dn=ht(w(ht)(-1e18)(pt._1.incoming))(w(ht)(-1e18)(pt._1.outgoing)),Fe=w(Pt=>Qt=>Qt>Lt?Pt:Qt>=Jt?Pt+1|0:Pt)(0)(pt._1.outgoing)+w(Pt=>Qt=>Qt>dn?Pt:Qt>=Ht?Pt+1|0:Pt)(0)(ot)|0;return Nt===Fe?Nt>0?{...ft,deps:ft.deps+2|0,crossings:ft.crossings+Nt|0}:ft:{...ft,deps:ft.deps+1|0,crossings:ft.crossings+jr(Nt)(Fe)|0}}g()}})())(w((()=>{const yt=W.segMap;return Ct=>Rt=>{const pt=It(Rt.src)(yt);if(pt.tag==="Nothing")return Ct;if(pt.tag==="Just"){const qt=lt(w(lt)(1e18)(pt._1.incoming))(w(lt)(1e18)(pt._1.outgoing)),wt=ht(w(ht)(-1e18)(pt._1.incoming))(w(ht)(-1e18)(pt._1.outgoing)),mt=lt(w(lt)(1e18)(B.incoming))(w(lt)(1e18)(j)),ft=(()=>{const Pt=ht(w(ht)(-1e18)(B.incoming))(w(ht)(-1e18)(j)),Qt=w($t=>_e=>_e>wt?$t:_e>=qt?$t+1|0:$t)(0)(j)+w($t=>_e=>_e>Pt?$t:_e>=mt?$t+1|0:$t)(0)(pt._1.incoming)|0,ze=lt(w(lt)(1e18)(B.incoming))(w(lt)(1e18)(j)),an=ht(w(ht)(-1e18)(B.incoming))(w(ht)(-1e18)(j)),Xe=lt(w(lt)(1e18)(pt._1.incoming))(w(lt)(1e18)(pt._1.outgoing)),nn=ht(w(ht)(-1e18)(pt._1.incoming))(w(ht)(-1e18)(pt._1.outgoing)),Ae=w($t=>_e=>_e>an?$t:_e>=ze?$t+1|0:$t)(0)(pt._1.outgoing)+w($t=>_e=>_e>nn?$t:_e>=Xe?$t+1|0:$t)(0)(B.incoming)|0;return Qt===Ae?Qt>0?{...Ct,deps:Ct.deps+2|0,crossings:Ct.crossings+Qt|0}:Ct:{...Ct,deps:Ct.deps+1|0,crossings:Ct.crossings+jr(Qt)(Ae)|0}})(),st=lt(w(lt)(1e18)(pt._1.incoming))(w(lt)(1e18)(pt._1.outgoing)),dt=ht(w(ht)(-1e18)(pt._1.incoming))(w(ht)(-1e18)(pt._1.outgoing)),at=lt(w(lt)(1e18)(ot))(w(lt)(1e18)(B.outgoing)),ct=ht(w(ht)(-1e18)(ot))(w(ht)(-1e18)(B.outgoing)),Nt=w(Pt=>Qt=>Qt>dt?Pt:Qt>=st?Pt+1|0:Pt)(0)(B.outgoing)+w(Pt=>Qt=>Qt>ct?Pt:Qt>=at?Pt+1|0:Pt)(0)(pt._1.incoming)|0,Jt=lt(w(lt)(1e18)(ot))(w(lt)(1e18)(B.outgoing)),Lt=ht(w(ht)(-1e18)(ot))(w(ht)(-1e18)(B.outgoing)),Ht=lt(w(lt)(1e18)(pt._1.incoming))(w(lt)(1e18)(pt._1.outgoing)),dn=ht(w(ht)(-1e18)(pt._1.incoming))(w(ht)(-1e18)(pt._1.outgoing)),Fe=w(Pt=>Qt=>Qt>Lt?Pt:Qt>=Jt?Pt+1|0:Pt)(0)(pt._1.outgoing)+w(Pt=>Qt=>Qt>dn?Pt:Qt>=Ht?Pt+1|0:Pt)(0)(ot)|0;return Nt===Fe?Nt>0?{...ft,deps:ft.deps+2|0,crossings:ft.crossings+Nt|0}:ft:{...ft,deps:ft.deps+1|0,crossings:ft.crossings+jr(Nt)(Fe)|0}}g()}})())({crossings:0,deps:0})(ut(yt=>yt.tgt===B.id,l.deps)))(ut(yt=>yt.src===B.id,l.deps)),gt=(()=>{if(B.splitBy.tag==="Just")return It(B.splitBy._1)(W.segMap);if(B.splitBy.tag==="Nothing")return J;g()})();if(gt.tag==="Just")return{..._t,deps:_t.deps+2|0,crossings:(()=>{const yt=lt(w(lt)(1e18)(gt._1.incoming))(w(lt)(1e18)(gt._1.outgoing)),Ct=lt(w(lt)(1e18)(ot))(w(lt)(1e18)(B.outgoing)),Rt=ht(w(ht)(-1e18)(gt._1.incoming))(w(ht)(-1e18)(gt._1.outgoing)),pt=ht(w(ht)(-1e18)(ot))(w(ht)(-1e18)(B.outgoing)),qt=lt(w(lt)(1e18)(B.incoming))(w(lt)(1e18)(j));return _t.crossings+(()=>{const wt=lt(w(lt)(1e18)(gt._1.incoming))(w(lt)(1e18)(gt._1.outgoing)),mt=ht(w(ht)(-1e18)(B.incoming))(w(ht)(-1e18)(j)),ft=ht(w(ht)(-1e18)(gt._1.incoming))(w(ht)(-1e18)(gt._1.outgoing));return((w(st=>dt=>dt>Rt?st:dt>=yt?st+1|0:st)(0)(j)+w(st=>dt=>dt>mt?st:dt>=qt?st+1|0:st)(0)(gt._1.incoming)|0)+w(st=>dt=>dt>pt?st:dt>=Ct?st+1|0:st)(0)(gt._1.outgoing)|0)+w(st=>dt=>dt>ft?st:dt>=wt?st+1|0:st)(0)(ot)|0})()|0})()};if(gt.tag==="Nothing")return _t;g()})()}))(F);return w(q=>K=>K.rating.crossings<q.rating.crossings||!(K.rating.crossings>q.rating.crossings)&&(K.rating.deps<q.rating.deps||!(K.rating.deps>q.rating.deps)&&K.c.a.size>q.c.a.size)?K:q)(0<X.length?X[0]:{c:Q._1,rating:{crossings:1e6,deps:1e6}})(X).c}g()})(),Y={...B,incoming:Et(rt.compare)(B.incoming),outgoing:Et(rt.compare)([(R.a.startPosition+R.a.endPosition)/2]),splitPartner:T("Just",W.nextId)},O={id:W.nextId,incoming:Et(rt.compare)([(R.a.startPosition+R.a.endPosition)/2]),mark:0,members:B.members,outgoing:Et(rt.compare)(B.outgoing),slot:0,splitBy:J,splitPartner:T("Just",B.id)};return{segMap:Z(nt)(O.id)(O)(Z(nt)(Y.id)(Y)(W.segMap)),freeAreas:(()=>{if(R.i>=0&&R.i<W.freeAreas.length){const X=ac(Zt,J,R.i,W.freeAreas),q=(()=>{if(X.tag==="Nothing")return W.freeAreas;if(X.tag==="Just")return X._1;g()})();if(W.freeAreas[R.i].size/2<d)return q;const K=(W.freeAreas[R.i].startPosition+W.freeAreas[R.i].endPosition)/2,j=K-d,ot=K+d;return[...R.i<1?[]:kt(0,R.i,q),...W.freeAreas[R.i].startPosition<=j?[{startPosition:W.freeAreas[R.i].startPosition,endPosition:j,size:j-W.freeAreas[R.i].startPosition}]:[],...ot<=W.freeAreas[R.i].endPosition?[{startPosition:ot,endPosition:W.freeAreas[R.i].endPosition,size:W.freeAreas[R.i].endPosition-ot}]:[],...R.i<1?q:kt(R.i,q.length,q)]}return W.freeAreas})(),nextId:W.nextId+1|0}})({segMap:U,freeAreas:(()=>{const W=Et(rt.compare)([...Tt(l.segments)(B=>B.incoming),...Tt(l.segments)(B=>B.outgoing)]);return xt(rx)(be(B=>P=>P-B>=2*d?T("Just",{startPosition:B+d,endPosition:P-d,size:P-B-2*d}):J,W,kt(1,W.length,W)))})(),nextId:l.segments.length})(Et(W=>B=>rt.compare(ht(w(ht)(-1e18)(W.incoming))(w(ht)(-1e18)(W.outgoing))-lt(w(lt)(1e18)(W.incoming))(w(lt)(1e18)(W.outgoing)))(ht(w(ht)(-1e18)(B.incoming))(w(ht)(-1e18)(B.outgoing))-lt(w(lt)(1e18)(B.incoming))(w(lt)(1e18)(B.outgoing))))(xt(W=>It(W)(U))(V.decisions)));return{segments:(()=>{const W=(B,P)=>{if(B.tag==="Leaf")return P;if(B.tag==="Node")return W(B._5,Xt("Cons",B._4,W(B._6,P)));g()};return At(Kt.foldr,W(M.segMap,Ut))})(),deps:(()=>{const W=M.segMap,B=(F,Q)=>{if(F.tag==="Leaf")return Q;if(F.tag==="Node")return B(F._5,Xt("Cons",F._4,B(F._6,Q)));g()},P=At(Kt.foldr,B(W,Ut)),I=P.length;return[...Tt(Tt(zt(0,I-2|0))(F=>Tt(zt(F+1|0,I-1|0))(Q=>[L(F,Q)])))(F=>F._1>=0&&F._1<P.length?F._2>=0&&F._2<P.length?P[F._1].splitPartner.tag!=="Nothing"&&P[F._1].splitPartner.tag==="Just"&&P[F._1].splitPartner._1===P[F._2].id||P[F._2].splitPartner.tag!=="Nothing"&&P[F._2].splitPartner.tag==="Just"&&P[F._2].splitPartner._1===P[F._1].id?[]:o(d,P[F._1],P[F._2]):[]:[]),...Tt(P)(F=>F.splitBy.tag==="Just"&&F.splitPartner.tag==="Just"&&(()=>{const Q=It(F.splitPartner._1)(W);if(Q.tag==="Nothing")return!1;if(Q.tag==="Just")return!0;g()})()&&(()=>{const Q=It(F.splitBy._1)(W);if(Q.tag==="Nothing")return!1;if(Q.tag==="Just")return!0;g()})()?[{src:F.id,tgt:F.splitBy._1,weight:1,kind:Yo},{src:F.splitBy._1,tgt:F.splitPartner._1,weight:1,kind:Yo}]:[])]})()}})(),p=h.segments,m=p.length,y=S=>{let C=S,V=!0,U;for(;V;){const M=C,W=Vt(B=>{const P=It(B)(M.inWeight);if(P.tag==="Nothing")return!0;if(P.tag==="Just")return P._1===0;g()})(M.remaining);if(W.tag==="Nothing"){V=!1,U=M;continue}if(W.tag==="Just"){const B=W._1;C={...M,inWeight:w(P=>I=>bt(nt)(se)(I.tgt)(-I.weight)(P))(M.inWeight)((()=>{const P=It(B)(M.depsBySrc);if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})()),marks:Z(nt)(B)(M.nextSource)(M.marks),nextSource:M.nextSource+1|0,outWeight:w(P=>I=>bt(nt)(se)(I.src)(-I.weight)(P))(M.outWeight)((()=>{const P=It(B)(M.depsByTgt);if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})()),remaining:ut(P=>P!==B,M.remaining)};continue}g()}return U},x=S=>{let C=S,V=!0,U;for(;V;){const M=C,W=Vt(B=>{const P=It(B)(M.outWeight);if(P.tag==="Nothing")return!0;if(P.tag==="Just")return P._1===0;g()})(M.remaining);if(W.tag==="Nothing"){V=!1,U=M;continue}if(W.tag==="Just"){const B=W._1;C={...M,inWeight:w(P=>I=>bt(nt)(se)(I.tgt)(-I.weight)(P))(M.inWeight)((()=>{const P=It(B)(M.depsBySrc);if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})()),marks:Z(nt)(B)(M.nextSink)(M.marks),nextSink:M.nextSink-1|0,outWeight:w(P=>I=>bt(nt)(se)(I.src)(-I.weight)(P))(M.outWeight)((()=>{const P=It(B)(M.depsByTgt);if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})()),remaining:ut(P=>P!==B,M.remaining)};continue}g()}return U},N=(S=>{let C=S,V=!0,U;for(;V;){const M=y(x(C));if(M.remaining.length===0){V=!1,U=H(W=>{const B=It(W.id)(M.marks),P=(()=>{if(B.tag==="Nothing")return W.id;if(B.tag==="Just")return B._1;g()})();return{...W,mark:P<m?(P+m|0)+1|0:P}})(p);continue}C=(()=>{const W=P=>{const I=It(P)(M.outWeight),F=It(P)(M.inWeight);return(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;g()})()-(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;g()})()|0},B=Et(P=>I=>nt.compare(W(I))(W(P)))(M.remaining);if(0<B.length){const P=B[0];return{...M,inWeight:w(I=>F=>bt(nt)(se)(F.tgt)(-F.weight)(I))(M.inWeight)((()=>{const I=It(P)(M.depsBySrc);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})()),marks:Z(nt)(P)(M.nextSource)(M.marks),nextSource:M.nextSource+1|0,outWeight:w(I=>F=>bt(nt)(se)(F.src)(-F.weight)(I))(M.outWeight)((()=>{const I=It(P)(M.depsByTgt);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;g()})()),remaining:ut(I=>I!==P,M.remaining)}}return M})()}return U})({remaining:H(S=>S.id)(p),marks:D,inWeight:w(S=>C=>bt(nt)(se)(C.tgt)(C.weight)(S))(D)(h.deps),outWeight:w(S=>C=>bt(nt)(se)(C.src)(C.weight)(S))(D)(h.deps),depsBySrc:w(S=>C=>bt(nt)(ne)(C.src)([C])(S))(D)(h.deps),depsByTgt:w(S=>C=>bt(nt)(ne)(C.tgt)([C])(S))(D)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),v=(()=>{const S=(()=>{const U=Ur(H(M=>L(M.id,M.mark))(N));return{segments:N,deps:xt(M=>(()=>{if(M.kind==="Critical")return!0;if(M.kind==="Regular")return!1;g()})()?T("Just",M):(()=>{const W=It(M.src)(U),B=It(M.tgt)(U);return(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})()>(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})()})()?M.weight===0?J:T("Just",{src:M.tgt,tgt:M.src,weight:M.weight,kind:M.kind}):T("Just",M))(h.deps)}})(),C=w(U=>M=>bt(nt)(se)(M.tgt)(1)(U))(D)(S.deps),V=(U=>{let M=U,W=!0,B;for(;W;){const P=M,I=Mt(F=>J,F=>Q=>T("Just",{head:F,tail:Q}),P.queue);if(I.tag==="Nothing"){W=!1,B=P;continue}if(I.tag==="Just"){M=w((()=>{const F=It(I._1.head)(P.slots),Q=(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;g()})();return R=>Y=>{const O=It(Y)(R.inDegree),X=(()=>{if(O.tag==="Nothing")return-1;if(O.tag==="Just")return O._1-1|0;g()})();return{...R,slots:Z(nt)(Y)(lf((()=>{const q=It(Y)(R.slots);if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;g()})())(Q+1|0))(R.slots),inDegree:Z(nt)(Y)(X)(R.inDegree),queue:X===0?[...R.queue,Y]:R.queue}}})())({...P,queue:I._1.tail})((()=>{const F=It(I._1.head)(P.adj);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})());continue}g()}return B})({slots:Ur(H(U=>L(U.id,0))(S.segments)),inDegree:C,adj:w(U=>M=>bt(nt)(ne)(M.src)([M.tgt])(U))(D)(S.deps),queue:H(U=>U.id)(ut(U=>{const M=It(U.id)(C);if(M.tag==="Nothing")return!0;if(M.tag==="Just")return M._1===0;g()},S.segments))});return Et(U=>M=>nt.compare(U.slot)(M.slot))(H(U=>({...U,slot:(()=>{const M=It(U.id)(V.slots);if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()}))(S.segments))})(),b=1+w(S=>C=>lf(S)(C.slot))(0)(v)|0,k=Tt(v)(S=>S.members),E=ut(S=>He(hn)(S.edge.id)(k),t),A=w(ht)(-1e18)(H(S=>S.fromPos._2)(E)),$=w(lt)(1e18)(H(S=>S.toPos._2)(E));if(A>$){const S=Ur(H(C=>L(C.id,C))(v));return Ye(H(C=>H(V=>L(V,{slot:C.slot,slotCount:b,gapTop:$,gapBottom:A,partner:(()=>{if(C.splitPartner.tag==="Just"){const U=It(C.splitPartner._1)(S);if(U.tag==="Just")return T("Just",{slot:U._1.slot,splitX:0<U._1.incoming.length?U._1.incoming[0]:0});if(U.tag==="Nothing")return J;g()}if(C.splitPartner.tag==="Nothing")return J;g()})()}))(C.members))(ut(C=>{if(C.splitPartner.tag==="Just"){const V=It(C.splitPartner._1)(S);return!(V.tag==="Just"&&(()=>{if(V._1.splitBy.tag==="Nothing")return!1;if(V._1.splitBy.tag==="Just")return!0;g()})())}if(C.splitPartner.tag==="Nothing")return!0;g()},v)))}const tt=Ur(H(S=>L(S.id,S))(v));return Ye(H(S=>H(C=>L(C,{slot:S.slot,slotCount:b,gapTop:A,gapBottom:$,partner:(()=>{if(S.splitPartner.tag==="Just"){const V=It(S.splitPartner._1)(tt);if(V.tag==="Just")return T("Just",{slot:V._1.slot,splitX:0<V._1.incoming.length?V._1.incoming[0]:0});if(V.tag==="Nothing")return J;g()}if(S.splitPartner.tag==="Nothing")return J;g()})()}))(S.members))(ut(S=>{if(S.splitPartner.tag==="Just"){const C=It(S.splitPartner._1)(tt);return!(C.tag==="Just"&&(()=>{if(C._1.splitBy.tag==="Nothing")return!1;if(C._1.splitBy.tag==="Just")return!0;g()})())}if(S.splitPartner.tag==="Nothing")return!0;g()},v)))})()))(D)(nx(w(u=>s=>{const a=Kr(s.edge.from.node)(n);if(a.tag==="Just"){const c=Kr(s.edge.to.node)(n);return c.tag==="Just"&&a._1.layer!==c._1.layer?bt(nt)(ne)(jr(a._1.layer)(c._1.layer))([s])(u):u}return u})(D)((()=>{const u=s=>L((()=>{const a=Kr(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=Kr(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return Et(s=>a=>ex(u(s))(u(a)))(t)})())))},ox=t=>e=>{const n=pf(t)(e),r=w(i=>o=>Z(G)(o.node)(o)(i))(D)(e);return w(i=>o=>{const u=Kr(o.edge.from.node)(r);if(u.tag==="Just"){const s=Kr(o.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=ix(o.edge.id)(n);if(a.tag==="Just")return Z(nt)(jr(u._1.layer)(s._1.layer))(a._1.slotCount)(i)}return i}return i})(D)(t)},mf=Bt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),ge=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},fe=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Gi=t=>e=>n=>r=>mf(i=>n>=i.x&&n<i.x+i.w&&e>i.y&&t<i.y+i.h)(r),Vo=t=>e=>n=>r=>Gi(ge(e)(n))(fe(e)(n))(r)(t),Uo=et(4),ux=fc(t=>{if(t.direction==="H"){const e=ge(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:fe(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:fe(t.start._2)(t.end._2)-e}]}g()}),Pi=gc(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})())}),sx=t=>e=>n=>{const r=Mt(i=>J,i=>o=>T("Just",{head:i,tail:o}),e);if(r.tag==="Nothing")return[{start:t.start,end:n.end,direction:t.direction}];if(r.tag==="Just"){const i=(r._1.head.direction==="H"?t.direction==="H":r._1.head.direction==="V"&&t.direction==="V")?[{start:t.start,end:r._1.head.end,direction:t.direction}]:[t,r._1.head],o=pr(r._1.tail);if(o.tag==="Nothing"){const u=i.length-1|0;return u>=0&&u<i.length&&(i[u].direction==="H"?n.direction==="H":i[u].direction==="V"&&n.direction==="V")?[...(()=>{const s=i.length-1|0;return s<1?[]:kt(0,s,i)})(),{start:i[u].start,end:n.end,direction:n.direction}]:[...i,n]}if(o.tag==="Just")return(o._1.last.direction==="H"?n.direction==="H":o._1.last.direction==="V"&&n.direction==="V")?[...i,...o._1.init,{start:o._1.last.start,end:n.end,direction:n.direction}]:[...i,...r._1.tail,n]}g()},Ai=t=>{const e=r=>i=>{const o=Mt(u=>J,u=>s=>T("Just",{head:u,tail:s}),i);if(o.tag==="Nothing")return[r];if(o.tag==="Just")return(r.direction==="H"?o._1.head.direction==="H":r.direction==="V"&&o._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==o._1.head.end._1-o._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==o._1.head.end._2-o._1.head.start._2>=0;g()})()?e({start:r.start,end:o._1.head.end,direction:r.direction})(o._1.tail):[r,...e(o._1.head)(o._1.tail)];g()},n=Mt(r=>J,r=>i=>T("Just",{head:r,tail:i}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);g()},Ii=t=>e=>n=>r=>mf(i=>n>=i.y&&n<i.y+i.h&&e>i.x&&t<i.x+i.w)(r),Qi=t=>e=>n=>r=>Ii(ge(e)(n))(fe(e)(n))(r)(t),ax=t=>e=>n=>r=>{const i=n+2|0,o=i<1?e:kt(i,e.length,e),u=n<1?[]:kt(0,n,e),s=(n+1|0)===(r-1|0),a=n===0,c=n>=0&&n<e.length?T("Just",e[n]):J;if(c.tag==="Just"){const f=n+1|0,d=f>=0&&f<e.length?T("Just",e[f]):J;if(d.tag==="Just"){const l=c._1.start._1===d._1.end._1&&(!a||c._1.direction==="V")&&(!s||d._1.direction==="V")&&!Vo(t)(ge(c._1.start._2)(d._1.end._2))(fe(c._1.start._2)(d._1.end._2))(c._1.start._1)?T("Just",[...u,{start:c._1.start,end:d._1.end,direction:ie},...o]):J,_=c._1.start._2===d._1.end._2&&(!a||c._1.direction==="H")&&(!s||d._1.direction==="H")&&!Qi(t)(ge(c._1.start._1)(d._1.end._1))(fe(c._1.start._1)(d._1.end._1))(c._1.start._2)?T("Just",[...u,{start:c._1.start,end:d._1.end,direction:re},...o]):J;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return J;g()}if(c.tag==="Nothing")return J;g()},cx=t=>e=>{const n=e.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+1|0)>=n){o=!1,u=e;continue}const a=ax(t)(e)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}g()}return u})(0)},gx=t=>e=>n=>r=>{const i=(l,_,h)=>!Vo(t)(ge(_)(h))(fe(_)(h))(l),o=n+3|0,u=o<1?e:kt(o,e.length,e),s=n<1?[]:kt(0,n,e),a=(n+2|0)===(r-1|0),c=n===0,f=(l,_,h)=>!Qi(t)(ge(_)(h))(fe(_)(h))(l),d=n>=0&&n<e.length?T("Just",e[n]):J;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<e.length?T("Just",e[l]):J;if(_.tag==="Just"){const h=d._1.start._1===_._1.end._1&&(!c||d._1.direction==="V")&&(!a||_._1.direction==="V")&&i(d._1.start._1,d._1.start._2,_._1.end._2)?T("Just",[...s,{start:d._1.start,end:_._1.end,direction:ie},...u]):d._1.start._2===_._1.end._2&&(!c||d._1.direction==="H")&&(!a||_._1.direction==="H")&&f(d._1.start._2,d._1.start._1,_._1.end._1)?T("Just",[...s,{start:d._1.start,end:_._1.end,direction:re},...u]):J,p=(!c||d._1.direction==="V")&&(!a||_._1.direction==="H")&&i(d._1.start._1,d._1.start._2,_._1.end._2)&&f(_._1.end._2,d._1.start._1,_._1.end._1)?T("Just",[...s,{start:d._1.start,end:L(d._1.start._1,_._1.end._2),direction:ie},{start:L(d._1.start._1,_._1.end._2),end:_._1.end,direction:re},...u]):J,m=(!c||d._1.direction==="H")&&(!a||_._1.direction==="V")&&f(d._1.start._2,d._1.start._1,_._1.end._1)&&i(_._1.end._1,d._1.start._2,_._1.end._2)?T("Just",[...s,{start:d._1.start,end:L(_._1.end._1,d._1.start._2),direction:re},{start:L(_._1.end._1,d._1.start._2),end:_._1.end,direction:ie},...u]):J,y=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?y:h}if(_.tag==="Nothing")return J;g()}if(d.tag==="Nothing")return J;g()},fx=t=>e=>{const n=e.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+2|0)>=n){o=!1,u=e;continue}const a=gx(t)(e)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}g()}return u})(0)},_x=t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r,s=Ai(Pi(cx(t)(fx(t)(u))));if(s.length<u.length){r=s;continue}i=!1,o=s}return o};return n=>e(Ai(Pi(n)))},dx=t=>e=>n=>r=>{const i=ge(n)(r),o=fe(n)(r),u=ut(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=Et(c=>f=>rt.compare(c.x)(f.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=Et(a=>c=>rt.compare(c.x)(a.x))(H(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},lx=t=>e=>n=>r=>{const i=ge(n)(r),o=fe(n)(r),u=ut(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=Et(c=>f=>rt.compare(c.y)(f.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=Et(a=>c=>rt.compare(c.y)(a.y))(H(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},hx=t=>e=>n=>r=>{const i=ge(n)(r),o=fe(n)(r),u=ut(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=Et(c=>f=>rt.compare(f.x)(c.x))(H(c=>({...c,x:c.x+c.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=Et(a=>c=>rt.compare(a.x)(c.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},px=t=>e=>n=>r=>{const i=ge(n)(r),o=fe(n)(r),u=ut(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=Et(c=>f=>rt.compare(f.y)(c.y))(H(c=>({...c,y:c.y+c.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=Et(a=>c=>rt.compare(a.y)(c.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},yf=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,c=i,f=o;if(f>100){u=!1,s=c;continue}if(!a(c+f)){u=!1,s=c+f;continue}if(!a(c-f)){u=!1,s=c-f;continue}r=a,i=c,o=f+1}return s},xf=t=>e=>n=>r=>i=>{const o=ge(e)(n),u=fe(e)(n);if(!Gi(o)(u)(r)(t))return r;if(!Gi(o)(u)(i)(t))return i;const s=(r+i)/2;return Gi(o)(u)(s)(t)?yf(a=>Gi(o)(u)(a)(t))(s)(1):s},mx=t=>e=>n=>r=>i=>{const o=ge(e)(n),u=fe(e)(n);if(!Ii(o)(u)(r)(t))return r;if(!Ii(o)(u)(i)(t))return i;const s=(r+i)/2;return Ii(o)(u)(s)(t)?yf(a=>Ii(o)(u)(a)(t))(s)(1):s},yx=t=>e=>n=>r=>{const i=ge(e)(n),o=fe(e)(n),u=ut(c=>r>=c.x&&r<c.x+c.w&&c.y+c.h>i&&c.y<o,t),s=w(c=>f=>fe(c)(f.x+f.w+4))(r+4)(u),a=w(c=>f=>ge(c)(f.x-4))(r-4)(u);return(()=>{const c=s-r,f=a-r;return(c<0?-c:c)<=(f<0?-f:f)})()?s:a},xx=t=>e=>n=>r=>{const i=ge(e)(n),o=fe(e)(n),u=ut(c=>r>=c.y&&r<c.y+c.h&&c.x+c.w>i&&c.x<o,t),s=w(c=>f=>fe(c)(f.y+f.h+4))(r+4)(u),a=w(c=>f=>ge(c)(f.y-4))(r-4)(u);return(()=>{const c=s-r,f=a-r;return(c<0?-c:c)<=(f<0?-f:f)})()?s:a},Nx=t=>e=>n=>r=>i=>o=>u=>{const s=(()=>{if(r==="South")return L(i._1,i._2+4);if(r==="North")return L(i._1,i._2-4);if(r==="East")return L(i._1+4,i._2);if(r==="West")return L(i._1-4,i._2);g()})(),a=(()=>{if(o==="South")return L(u._1,u._2+4);if(o==="North")return L(u._1,u._2-4);if(o==="East")return L(u._1+4,u._2);if(o==="West")return L(u._1-4,u._2);g()})(),c=(b,k,E)=>!Vo(e)(ge(k)(E))(fe(k)(E))(b),f=(b,k,E)=>!Vo(n)(ge(k)(E))(fe(k)(E))(b),d=(b,k,E,A)=>t.tag==="Just"&&!Qi(n)(ge(b)(k))(fe(b)(k))(t._1)?t._1:mx(e)(b)(k)(E)(A),l=(b,k,E,A)=>{if(b===E){const tt=yx(e)(k)(A)(b),S=lx(e)(b)(k)(A),C=px(e)(b)(k)(A);return[{start:L(b,k),end:L(b,S),direction:ie},{start:L(b,S),end:L(tt,S),direction:re},{start:L(tt,S),end:L(tt,C),direction:ie},{start:L(tt,C),end:L(E,C),direction:re},{start:L(E,C),end:L(E,A),direction:ie}]}const $=d(b,E,k,A);return[{start:L(b,k),end:L(b,$),direction:ie},{start:L(b,$),end:L(E,$),direction:re},{start:L(E,$),end:L(E,A),direction:ie}]},_=(b,k,E,A)=>{if(k===A){const tt=xx(e)(b)(E)(k),S=dx(e)(k)(b)(E),C=hx(e)(k)(b)(E);return[{start:L(b,k),end:L(S,k),direction:re},{start:L(S,k),end:L(S,tt),direction:ie},{start:L(S,tt),end:L(C,tt),direction:re},{start:L(C,tt),end:L(C,A),direction:ie},{start:L(C,A),end:L(E,A),direction:re}]}const $=xf(e)(k)(A)(b)(E);return[{start:L(b,k),end:L($,k),direction:re},{start:L($,k),end:L($,A),direction:ie},{start:L($,A),end:L(E,A),direction:re}]},h=(b,k,E)=>!Qi(e)(ge(k)(E))(fe(k)(E))(b),p=(b,k,E)=>!Qi(n)(ge(k)(E))(fe(k)(E))(b),m=(b,k,E,A)=>{if(p(k,b,E)&&f(E,k,A))return[{start:L(b,k),end:L(E,k),direction:re},{start:L(E,k),end:L(E,A),direction:ie}];const $=xf(e)(k)(A)(b)(E);return[{start:L(b,k),end:L($,k),direction:re},{start:L($,k),end:L($,A),direction:ie},{start:L($,A),end:L(E,A),direction:re}]},y=(b,k,E,A)=>{if(f(b,k,A)&&p(A,b,E))return[{start:L(b,k),end:L(b,A),direction:ie},{start:L(b,A),end:L(E,A),direction:re}];const $=d(b,E,k,A);return[{start:L(b,k),end:L(b,$),direction:ie},{start:L(b,$),end:L(E,$),direction:re},{start:L(E,$),end:L(E,A),direction:ie}]},x=(()=>{if(r==="South")return o==="North"?s._1===a._1&&c(s._1,s._2,a._2)?[{start:L(s._1,s._2),end:L(a._1,a._2),direction:ie}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?y(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="North")return o==="South"?s._1===a._1&&c(s._1,s._2,a._2)?[{start:L(s._1,s._2),end:L(a._1,a._2),direction:ie}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?y(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="East")return o==="West"?s._2===a._2&&h(s._2,s._1,a._1)?[{start:L(s._1,s._2),end:L(a._1,a._2),direction:re}]:_(s._1,s._2,a._1,a._2):o==="North"||o==="South"?m(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="West"){if(o==="East")return s._2===a._2&&h(s._2,s._1,a._1)?[{start:L(s._1,s._2),end:L(a._1,a._2),direction:re}]:_(s._1,s._2,a._1,a._2);if(o==="North"||o==="South")return m(s._1,s._2,a._1,a._2)}return l(s._1,s._2,a._1,a._2)})(),N=(()=>{if(r==="South"||r==="North")return ie;if(r==="East"||r==="West")return re;g()})(),v={start:L(a._1,a._2),end:L(u._1,u._2),direction:(()=>{if(o==="South"||o==="North")return ie;if(o==="East"||o==="West")return re;g()})()};return s._1===a._1&&s._2===a._2?[{start:L(i._1,i._2),end:L(u._1,u._2),direction:N}]:sx({start:L(i._1,i._2),end:L(s._1,s._2),direction:N})(x)(v)},Jx=H(t=>({x:t.position._1*Uo-2,y:t.position._2*Uo-2,w:t.size._1*Uo+4,h:t.size._2*Uo+4})),$s=te(G)(Bt),Wn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Xs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},wx=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t._1)(o._3._1);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(t._2==="North"){if(o._3._2==="North"){r=!1,i=T("Just",o._4);continue}n=o._5;continue}if(o._3._2==="North"){n=o._6;continue}if(t._2==="South"){if(o._3._2==="South"){r=!1,i=T("Just",o._4);continue}n=o._5;continue}if(o._3._2==="South"){n=o._6;continue}if(t._2==="East"){if(o._3._2==="East"){r=!1,i=T("Just",o._4);continue}n=o._5;continue}if(o._3._2==="East"){n=o._6;continue}if(t._2==="West"&&o._3._2==="West"){r=!1,i=T("Just",o._4);continue}}g()}return i},Nf=t=>e=>{const n=e.position._1+e.size._1,r=e.position._2*2+e.size._2,i=e.position._1*2+e.size._1,o=e.position._2+e.size._2;if(t==="South")return L(i,o*2);if(t==="North")return L(i,e.position._2*2);if(t==="East")return L(n*2,r);if(t==="West")return L(e.position._1*2,r);g()},Ys=t=>e=>{const n=et(4);if(t==="South")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="North")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="East")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};if(t==="West")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};g()},Jf=t=>e=>w(n=>r=>bt(t)(ne)(e(r))([r])(n))(D),wf=t=>e=>n=>r=>{const i=(t==="South"||t==="North")&&(e==="East"||e==="West")&&(()=>{if(t==="South")return r._2>n._2;if(t==="North")return r._2<n._2;if(t==="East")return r._2>n._2;if(t==="West")return r._2<n._2;g()})()&&(()=>{if(e==="East")return n._1>r._1;if(e==="West"||e==="North")return n._1<r._1;if(e==="South")return n._1>r._1;g()})(),o=(t==="East"||t==="West")&&(e==="North"||e==="South")&&(()=>{if(t==="South")return r._1>n._1;if(t==="North")return r._1<n._1;if(t==="East")return r._1>n._1;if(t==="West")return r._1<n._1;g()})()&&(()=>{if(e==="East")return n._2>r._2;if(e==="West"||e==="North")return n._2<r._2;if(e==="South")return n._2>r._2;g()})();return(t==="South"?e==="North"&&n._1===r._1&&r._2>n._2:t==="North"?e==="South"&&n._1===r._1&&r._2<n._2:t==="East"?e==="West"&&n._2===r._2&&r._1>n._1:t==="West"&&e==="East"&&n._2===r._2&&r._1<n._1)?0:i||o?1:2},Tf=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,i=e.length;return i===0?D:$s(i===1?H(o=>L(o,r))(e):Ft(o=>u=>L(u,t.lo+et(o+1|0)*n/et(i+1|0)))(e))},vf=t=>e=>n=>r=>i=>{const o=Jf(G)(_=>_.to.node)(t),u=Jf(G)(_=>_.from.node)(t),s=w(_=>h=>Z(G)(h.node)(h)(_))(D)(e),a=(_,h,p)=>{const m=Wn(_)(s);if(m.tag==="Nothing")return L(0,0);if(m.tag==="Just"){const y=Wn(_)(n);if(y.tag==="Nothing"){const x=et(4);if(p==="South")return L(m._1.position._1*x+m._1.size._1*x/2,(m._1.position._2+m._1.size._2)*x);if(p==="North")return L(m._1.position._1*x+m._1.size._1*x/2,m._1.position._2*x);if(p==="East")return L((m._1.position._1+m._1.size._1)*x,m._1.position._2*x+m._1.size._2*x/2);if(p==="West")return L(m._1.position._1*x,m._1.position._2*x+m._1.size._2*x/2);g()}if(y.tag==="Just"){const x=Vt(N=>N.id===h)(y._1);if(x.tag==="Nothing"){const N=et(4);if(p==="South")return L(m._1.position._1*N+m._1.size._1*N/2,(m._1.position._2+m._1.size._2)*N);if(p==="North")return L(m._1.position._1*N+m._1.size._1*N/2,m._1.position._2*N);if(p==="East")return L((m._1.position._1+m._1.size._1)*N,m._1.position._2*N+m._1.size._2*N/2);if(p==="West")return L(m._1.position._1*N,m._1.position._2*N+m._1.size._2*N/2);g()}if(x.tag==="Just"){const N=et(4);if(x._1.side==="North")return L(m._1.position._1*N+et(x._1.offset)*N,m._1.position._2*N);if(x._1.side==="South")return L(m._1.position._1*N+et(x._1.offset)*N,(m._1.position._2+m._1.size._2)*N);if(x._1.side==="East")return L((m._1.position._1+m._1.size._1)*N,m._1.position._2*N+et(x._1.offset)*N);if(x._1.side==="West")return L(m._1.position._1*N,m._1.position._2*N+et(x._1.offset)*N)}}}g()},c=$s(Tt(r)(_=>{if(_.nodes.length<=2)return[];const h=et(4);if(1<_.nodes.length){const p=Wn(_.nodes[1])(s);if(p.tag==="Nothing")return[];if(p.tag==="Just"){const m=p._1.position._1*h+p._1.size._1*h/2;return H(y=>L(y,m))(be(y=>x=>_.edgeId+":"+y+"->"+x,_.nodes,kt(1,_.nodes.length,_.nodes)))}g()}return[]})),f=_=>{const h=Wn(_.from.node)(s),p=Wn(_.to.node)(s);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,y=p._1,x=Et(N=>v=>nt.compare(N.score)(v.score))(H(N=>{const v=N._1,b=N._2;return{from:v,to:b,score:(()=>{const k=(tt,S,C,V,U)=>{const M=Ys(tt)(S),W=Ys(tt)(C);return M.lo<W.hi&&W.lo<M.hi&&(v==="South"?b==="North"&&U._2>V._2:v==="North"?b==="South"&&U._2<V._2:v==="East"?b==="West"&&U._1>V._1:v==="West"&&b==="East"&&U._1<V._1)?0:wf(v)(b)(V)(U)},E=Nf(v)(m),A=Nf(b)(y),$=wf(v)(b)(E)(A);return(()=>{if($>0){if(v==="South")return b==="North"?k(le,m,y,E,A)*10|0:$*10|0;if(v==="North")return b==="South"?k(de,m,y,E,A)*10|0:$*10|0;if(v==="East")return b==="West"?k(Qn,m,y,E,A)*10|0:$*10|0;if(v==="West"&&b==="East")return k(Dn,m,y,E,A)*10|0}return $*10|0})()+(v==="South"?b==="North"?0:15:v==="North"?b==="South"?0:15:v==="East"?b==="West"?5:15:v==="West"&&b==="East"?5:15)|0})()}})([L(le,de),L(Qn,de),L(Dn,de),L(le,Qn),L(le,Dn),L(de,le),L(de,Qn),L(de,Dn),L(Qn,le),L(Dn,le),L(Qn,Dn),L(Dn,Qn)]));if(0<x.length)return{from:x[0].from,to:x[0].to}}return{from:le,to:de}},d=$s(H(_=>L(_.id,f(_)))(t)),l=(_,h,p,m,y,x)=>{const N=et(4),v=Wn(h)(s);if(v.tag==="Nothing")return L(0,0);if(v.tag==="Just"){const b=wx(L(p,_))(i);if(b.tag==="Just"){const k=v._1.position._1*N+b._1,E=et(4);if(_==="South")return L(k,(v._1.position._2+v._1.size._2)*E);if(_==="North")return L(k,v._1.position._2*E);if(_==="East")return L((v._1.position._1+v._1.size._1)*E,k);if(_==="West")return L(v._1.position._1*E,k);g()}if(b.tag==="Nothing"){const k=Ys(_)(v._1),E=(k.lo+k.hi)/2,A=Xs(p)(Tf(k)(H(S=>S.id)(Et(S=>C=>rt.compare(y(_)(S))(y(_)(C)))(ut(S=>{const C=Xs(S.id)(d);if(C.tag==="Just"){const V=x(C._1);return V==="North"?_==="North":V==="South"?_==="South":V==="East"?_==="East":V==="West"&&_==="West"}if(C.tag==="Nothing")return!0;g()},(()=>{const S=Wn(h)(m);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;g()})()))))),$=(()=>{if(A.tag==="Nothing")return E;if(A.tag==="Just")return A._1;g()})(),tt=et(4);if(_==="South")return L($,(v._1.position._2+v._1.size._2)*tt);if(_==="North")return L($,v._1.position._2*tt);if(_==="East")return L((v._1.position._1+v._1.size._1)*tt,$);if(_==="West")return L(v._1.position._1*tt,$)}}g()};return H(_=>{const h=Xs(_.edge.id)(c);if(h.tag==="Nothing")return _;if(h.tag==="Just")return{..._,fromPos:Je(3)(_.edge.from.node)==="$d:"?L(h._1,_.fromPos._2):_.fromPos,toPos:Je(3)(_.edge.to.node)==="$d:"?L(h._1,_.toPos._2):_.toPos};g()})(H(_=>{if(_.from.port.tag==="Just"&&_.to.port.tag==="Just")return{edge:_,fromPos:a(_.from.node,_.from.port._1,le),toPos:a(_.to.node,_.to.port._1,de),fromSide:le,toSide:de};const h=f(_);return{edge:_,fromPos:l(h.from,_.from.node,_.id,u,p=>m=>{const y=Wn(m.to.node)(s);if(y.tag==="Nothing")return 0;if(y.tag==="Just"){const x=et(4);if(p==="South"||p==="North")return y._1.position._1*x+y._1.size._1*x/2;if(p==="East"||p==="West")return y._1.position._2*x+y._1.size._2*x/2}g()},p=>p.from),toPos:l(h.to,_.to.node,_.id,o,p=>m=>{const y=Wn(m.from.node)(s);if(y.tag==="Nothing")return 0;if(y.tag==="Just"){const x=et(4);if(p==="South"||p==="North")return y._1.position._1*x+y._1.size._1*x/2;if(p==="East"||p==="West")return y._1.position._2*x+y._1.size._2*x/2}g()},p=>p.to),fromSide:h.from,toSide:h.to}})(t))},bf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Zr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Tx=(()=>{const t=Ue.unfoldr(Jn);return e=>t(Ke("IterNode",e,Nn))})(),Vs=t=>e=>t.gapTop+1*et(4)+et(e)*2.5*et(4),vx=t=>e=>{const n=bf(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return T("Just",{slot1Y:Vs(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Vs(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return J;g()}if(n.tag==="Nothing")return J;g()},bx=t=>e=>{const n=w(r=>i=>Z(G)(i.node)(i)(r))(D)(e);return Ye(Ft(r=>i=>{const o=Zr(i.node)(n);if(o.tag==="Nothing")return[];if(o.tag==="Just"){const u=o._1;return Ft(s=>a=>{const c=i.edges.length,f=et(4),d=u.position._1*f,l=u.position._2*f,_=u.size._2*f,h=et((2*c|0)+1|0),p=l+_*et(c-s|0)/h,m=l+_*et((c+1|0)+s|0)/h,y=d-f*2.5*et(s+1|0),x=[{start:L(d,p),end:L(y,p),direction:re},{start:L(y,p),end:L(y,m),direction:ie},{start:L(y,m),end:L(d,m),direction:re}];return{edge:a.id,segments:x,bends:be(N=>v=>N.end,x,kt(1,3,x)),bendType:[],jumps:[],reversed:!1}})(i.edges)}g()})(H(r=>({node:r._1,edges:r._2}))(Tx(w(r=>i=>bt(G)(ne)(i.from.node)([i])(r))(D)(t)))))},Lx=t=>e=>{const n=w(o=>u=>Z(G)(u.node)(u)(o))(D)(e),r=o=>{const u=Zr(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.position._1;g()},i=o=>{const u=Zr(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.layer;g()};return Et(o=>u=>{const s=nt.compare(i(o.edge.from.node))(i(u.edge.from.node));if(s==="EQ"){const a=rt.compare(r(o.edge.from.node))(r(u.edge.from.node));return a==="EQ"?rt.compare(r(o.edge.to.node))(r(u.edge.to.node)):a}return s})(t)},Be=t=>{const e=et(4);return{x:t.position._1*e-2,y:t.position._2*e-2,w:t.size._1*e+4,h:t.size._2*e+4}},kx=t=>t.from.node===t.to.node,Ex=t=>e=>n=>r=>{const i=_x(n)(Nx(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:i,bends:be(o=>u=>o.end,i,kt(1,i.length,i)),bendType:[],jumps:[],reversed:!1}},Sx=t=>e=>n=>r=>{const i=[{start:L(r.fromPos._1,r.fromPos._2),end:L(r.fromPos._1,t.slot1Y),direction:ie},{start:L(r.fromPos._1,t.slot1Y),end:L(t.splitX,t.slot1Y),direction:re},{start:L(t.splitX,t.slot1Y),end:L(t.splitX,t.slot2Y),direction:ie},{start:L(t.splitX,t.slot2Y),end:L(r.toPos._1,t.slot2Y),direction:re},{start:L(r.toPos._1,t.slot2Y),end:L(r.toPos._1,r.toPos._2),direction:ie}];return{edge:r.edge.id,segments:i,bends:be(o=>u=>o.end,i,kt(1,5,i)),bendType:[],jumps:[],reversed:!1}},Cx=t=>e=>n=>{const r=Zr(t.edge.from.node)(n);if(r.tag==="Just"){const o=Zr(t.edge.to.node)(n);return o.tag==="Just"?ut(u=>!(u.h===Be(r._1).h&&u.w===Be(r._1).w&&u.x===Be(r._1).x&&u.y===Be(r._1).y)&&!(u.h===Be(o._1).h&&u.w===Be(o._1).w&&u.x===Be(o._1).x&&u.y===Be(o._1).y),e):ut(u=>!(u.h===Be(r._1).h&&u.w===Be(r._1).w&&u.x===Be(r._1).x&&u.y===Be(r._1).y),e)}const i=Zr(t.edge.to.node)(n);return i.tag==="Just"?ut(o=>!(o.h===Be(i._1).h&&o.w===Be(i._1).w&&o.x===Be(i._1).x&&o.y===Be(i._1).y),e):ut(o=>!0,e)},Gx=t=>e=>{const n=bf(e.edge.id)(t);if(n.tag==="Just")return T("Just",Vs(n._1)(n._1.slot));if(n.tag==="Nothing")return J;g()},Px=t=>e=>n=>r=>i=>{const o=w(c=>f=>Z(G)(f.node)(f)(c))(D)(e),u=Jx(e),s=vf(ut(c=>c.from.node!==c.to.node,t))(e)(n)(r)(i),a=pf(s)(e);return[...bx(ut(kx,t))(e),...w(c=>f=>{const d=Cx(f)(u)(o),l=[...d,...c.edgeObstacles],_=vx(a)(f),h=(()=>{if(_.tag==="Just")return Sx(_._1)(d)(l)(f);if(_.tag==="Nothing")return Ex(Gx(a)(f))(d)(l)(f);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...ux(h.segments)]}})({results:[],edgeObstacles:[]})(Lx(s)(e)).results]},sr=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ar=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ax=t=>e=>n=>{if(t.start._1!==e.start._1)return J;const r=ar(sr(t.start._2)(t.end._2))(sr(e.start._2)(e.end._2)),i=sr(ar(t.start._2)(t.end._2))(ar(e.start._2)(e.end._2));return r<i?T("Just",{position:L(t.start._1,(r+i)/2),crossingEdge:n}):J},Ix=t=>e=>n=>{if(t.start._2!==e.start._2)return J;const r=ar(sr(t.start._1)(t.end._1))(sr(e.start._1)(e.end._1)),i=sr(ar(t.start._1)(t.end._1))(ar(e.start._1)(e.end._1));return r<i?T("Just",{position:L((r+i)/2,t.start._2),crossingEdge:n}):J},Qx=t=>e=>n=>{if(t.direction==="H")return Ix(t)(e)(n);if(t.direction==="V")return Ax(t)(e)(n);g()},Dx=t=>e=>n=>{const r=t+1|0,i=r<1?n:kt(r,n.length,n);return Tt(e.segments)(o=>Tt(i)(u=>xt(s=>Qx(o)(s)(u.edge))(ut(s=>s.direction==="H"?o.direction==="H":s.direction==="V"&&o.direction==="V",u.segments))))},Fx=t=>e=>n=>e.start._1>sr(t.start._1)(t.end._1)&&e.start._1<ar(t.start._1)(t.end._1)&&t.start._2>sr(e.start._2)(e.end._2)&&t.start._2<ar(e.start._2)(e.end._2)?T("Just",{position:L(e.start._1,t.start._2),crossingEdge:n}):J,zx=t=>e=>Tt(ut(n=>n.direction==="H",t.segments))(n=>Tt(e)(r=>xt(i=>Fx(n)(i)(r.edge))(ut(i=>i.direction==="V",r.segments)))),Bx=t=>e=>n=>[...zx(e)(ut(r=>r.edge!==e.edge,n)),...Dx(t)(e)(n)],Lf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},kf=t=>Je(3)(t)==="$d:",Mx=t=>e=>n=>w(r=>i=>{const o=Lf(i.from.node)(t),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})(),s=Lf(i.to.node)(t),a=(()=>{if(s.tag==="Nothing")return-u;if(s.tag==="Just")return s._1-u|0;g()})();if(a<=1)return{...r,edges:[...r.edges,i],chains:[...r.chains,{edgeId:i.id,nodes:[i.from.node,i.to.node]}]};const c=i.id,f=H(l=>"$d:"+c+":"+ue(l))(zt(1,a-1|0)),d=[i.from.node,...f,i.to.node];return{...r,layers:w(l=>_=>{const h=_._2,p=Md(u+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;g()})(r.layers)(be(ln,zt(1,a-1|0),f)),edges:[...r.edges,...be(l=>_=>({id:c+":"+l+"->"+_,from:{node:l,port:i.from.port},to:{node:_,port:i.to.port},label:J}),d,kt(1,d.length,d))],chains:[...r.chains,{edgeId:i.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),Ko=(()=>{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 ye;if(e._2==="North")return n._2==="North"?Ie:me;if(n._2==="North")return ye;if(e._2==="South")return n._2==="South"?Ie:me;if(n._2==="South")return ye;if(e._2==="East")return n._2==="East"?Ie:me;if(n._2==="East")return ye;if(e._2==="West"&&n._2==="West")return Ie;g()},Eq0:()=>t}})(),Wx=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=Ko.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Rx=te(G)(Bt),Us=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},qx=te(Ko)(Bt),Ef=(()=>{const t=Ue.unfoldr(Jn);return e=>t(Ke("IterNode",e,Nn))})(),ti=t=>e=>n=>r=>{const i=Wx(L(e,n))(t);if(i.tag==="Nothing")return r;if(i.tag==="Just")return i._1;g()},Sf=t=>e=>n=>{const r=Rx(Ye(H(u=>Ft(s=>a=>L(a,s))(u))(t))),i=(u,s)=>{if(u==="South"){const a=Us(s.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()}if(u==="North"){const a=Us(s.from.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()}return 0},o=u=>w(s=>a=>Ge(Ko.compare,Se,qx(H(c=>L(L(c._1,u),c._2))(Ef(Tf({lo:0,hi:(()=>{const c=Us(a._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return Je(3)(a._1)==="$d:"?0:1;g()})()})(H(c=>c.id)(Et(c=>f=>nt.compare(i(u,c))(i(u,f)))(a._2)))))),s))(D)(Ef(w(s=>a=>a.from.node===a.to.node?s:u==="South"?bt(G)(ne)(a.from.node)([a])(s):u==="North"?bt(G)(ne)(a.to.node)([a])(s):s)(D)(e)));return Ge(Ko.compare,Se,o(de),o(le))},Cf=t=>t,Gf=t=>t,Pf=t=>t,Hx=w(t=>e=>Z(G)(e)()(t))(D),Ox=(()=>{const t=Ue.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return T("Just",L(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Xt("Cons",r._3,n(r._6,i)));g()};return n(e,Ut)})())})(),it=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},on=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},vn=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},bn=te(G)(Bt),Ks=pc(G),js=(()=>{const t=Ue.unfoldr(Jn);return e=>t(Ke("IterNode",e,Nn))})(),$x=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Xx=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Af=Pf("VDown"),If=Pf("VUp"),Yx=Gf("ForwardPhase"),Vx=Gf("StackPhase"),Qf=Cf("HRight"),Df=Cf("HLeft"),Ff=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Ux=t=>e=>n=>{const r=w(u=>s=>bt(G)(se)(s.tgt)(1)(u))(D)(t),i=Ox(Hx([...H(u=>u.src)(t),...H(u=>u.tgt)(t),...(()=>{const u=(s,a)=>{if(s.tag==="Leaf")return a;if(s.tag==="Node")return u(s._5,Xt("Cons",s._4,u(s._6,a)));g()};return At(Kt.foldr,u(e,Ut))})()])),o=w(u=>s=>bt(G)(ne)(s.src)([{target:s.tgt,sep:s.sep}])(u))(D)(t);return(u=>s=>a=>{let c=u,f=s,d=a,l=!0,_;for(;l;){const h=c,p=f,m=d,y=Mt(x=>J,x=>N=>T("Just",{head:x,tail:N}),h);if(y.tag==="Nothing"){l=!1,_=m;continue}if(y.tag==="Just"){const x=it(y._1.head)(m),N=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})(),v=w(b=>k=>{const E=it(k.target)(b.result),A=N+k.sep,$=it(k.target)(b.indeg),tt=(()=>{if($.tag==="Nothing")return-1;if($.tag==="Just")return $._1-1|0;g()})();return{newQueue:tt===0?[...b.newQueue,k.target]:b.newQueue,result:Z(G)(k.target)((()=>{if(E.tag==="Nothing")return A;if(E.tag==="Just"){if(n==="VDown")return on(E._1)(A);if(n==="VUp")return vn(E._1)(A)}g()})())(b.result),indeg:Z(G)(k.target)(tt)(b.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const b=it(y._1.head)(o);if(b.tag==="Nothing")return[];if(b.tag==="Just")return b._1;g()})());c=[...y._1.tail,...v.newQueue],f=v.indeg,d=v.result;continue}g()}return _})(ut(u=>{const s=it(u)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;g()},i))(r)(w(u=>s=>Z(G)(s)(0)(u))(D)(i))},Kx=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,Xt("Cons",o._4,e(o._6,u)));g()},n=At(Kt.foldr,e(t,Ut)),r=w(on)(999999)(n);if(r===0||n.length===0)return t;const i=o=>{if(o.tag==="Leaf")return D;if(o.tag==="Node")return Ot("Node",o._1,o._2,o._3,o._4-r,i(o._5),i(o._6));g()};return i(t)},zf=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,Xt("Cons",o._4,e(o._6,u)));g()},n=e(t,Ut),r=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l.tag==="Nil"){c=!1,f=d;continue}if(l.tag==="Cons"){s=vn(d)(l._1),a=l._2;continue}g()}return f},i=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l.tag==="Nil"){c=!1,f=d;continue}if(l.tag==="Cons"){s=on(d)(l._1),a=l._2;continue}g()}return f};return r(-999999)(n)-i(999999)(n)},Di=t=>e=>(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(a===e){u=!1,s=c;continue}i=(()=>{const f=it(a)(t.align);if(f.tag==="Nothing")return e;if(f.tag==="Just")return f._1;g()})(),o=[...c,a]}return s})((()=>{const n=it(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;g()})())([e]),jx=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>{const d=(P,I,F)=>{const Q=P.from.node===I?P.from.port:P.to.node===I?P.to.port:J;if(Q.tag==="Just"){const R=it(I)(i);if(R.tag==="Just"){const Y=Vt(O=>O.id===Q._1)(R._1);if(Y.tag==="Just"){const O=et(Y._1.offset)*et(4);return F==="North"||F==="South"?O:0}if(Y.tag==="Nothing"){const O=it(I)(r),X=ti(u)(P.id)(F)((()=>{if(O.tag==="Nothing")return .5;if(O.tag==="Just")return O._1._1/2;g()})());return F==="North"||F==="South"?X:0}g()}if(R.tag==="Nothing"){const Y=it(I)(r),O=ti(u)(P.id)(F)((()=>{if(Y.tag==="Nothing")return .5;if(Y.tag==="Just")return Y._1._1/2;g()})());return F==="North"||F==="South"?O:0}g()}if(Q.tag==="Nothing"){const R=it(I)(r),Y=ti(u)(P.id)(F)((()=>{if(R.tag==="Nothing")return .5;if(R.tag==="Just")return R._1._1/2;g()})());return F==="North"||F==="South"?Y:0}g()},l=(P,I)=>{if(P.from.node===I){if(f==="HRight")return le;if(f==="HLeft")return de;g()}if(f==="HRight")return de;if(f==="HLeft")return le;g()},_=(P,I,F)=>w(Q=>R=>Z(G)(R)((()=>{const Y=it(R)(Q);if(Y.tag==="Nothing")return 0+I;if(Y.tag==="Just")return Y._1+I;g()})())(Q))(F)(Di(a)(P)),h=(()=>{if(f==="HRight")return n;if(f==="HLeft")return ve(n);g()})(),p=P=>{const I=it(P)(r);if(I.tag==="Nothing")return 1;if(I.tag==="Just")return I._1._1;g()},m=bn(Ye(Ft(P=>I=>H(F=>L(F,P))(I))(n))),y=(P,I)=>Je(3)(P)==="$d:"&&Je(3)(I)==="$d:"||Je(3)(P)==="$d:"||Je(3)(I)==="$d:"?10:et(t.nodeGap),x=w(P=>I=>Ks(F=>T("Just",[...(()=>{if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})(),I]))(I.to.node)(P))(D)(o),N=w(P=>I=>Ks(F=>T("Just",[...(()=>{if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})(),I]))(I.from.node)(P))(D)(o),v=Ye(n),b=w(P=>I=>{const F=it(I)(a.root),Q=(()=>{if(F.tag==="Nothing")return I;if(F.tag==="Just")return F._1;g()})();return I===Q?P:Ks(R=>T("Just",(()=>{if(R.tag==="Nothing")return!0;if(R.tag==="Just")return R._1;g()})()&&Je(3)(I)==="$d:"))(Q)(P)})(bn(H(P=>L(P,!0))(Fr(G.compare)((()=>{const P=(I,F)=>{if(I.tag==="Leaf")return F;if(I.tag==="Node")return P(I._5,Xt("Cons",I._4,P(I._6,F)));g()};return At(Kt.foldr,P(a.root,Ut))})()))))(v),k=(P,I)=>{const F=P.free,Q=it(F)(a.root),R=(()=>{if(Q.tag==="Nothing")return F;if(Q.tag==="Just")return Q._1;g()})(),Y=it(R)(b),O=(()=>{if(Y.tag==="Nothing")return!0;if(Y.tag==="Just")return Y._1;g()})();return w(X=>q=>{if(X.edge.tag==="Just")return X;if(X.edge.tag==="Nothing"){if((()=>{const gt=it(R)(I.su);return!O&&(()=>{const yt=it(q.from.node)(m);return q.from.node!==q.to.node&&(()=>{const Ct=it(q.to.node)(m);return(()=>{if(yt.tag==="Nothing")return-1;if(yt.tag==="Just")return yt._1;g()})()===(()=>{if(Ct.tag==="Nothing")return-1;if(Ct.tag==="Just")return Ct._1;g()})()})()})()||(()=>{if(gt.tag==="Nothing")return!1;if(gt.tag==="Just")return gt._1;g()})()})())return X;const K=q.from.node===F?q.to.node:q.from.node,j=it(K)(a.root),ot=(()=>{if(j.tag==="Nothing")return K;if(j.tag==="Just")return j._1;g()})(),_t=ot!==R;return _t&&(()=>{const gt=it(ot)(I.blockFinished);if(gt.tag==="Nothing")return!1;if(gt.tag==="Just")return gt._1;g()})()?{...X,edge:T("Just",q),hasEdges:!0}:{...X,hasEdges:X.hasEdges||_t}}g()})({edge:J,hasEdges:!1})((()=>{if(P.isRoot){if(f==="HRight"){const X=it(F)(x);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()}if(f==="HLeft"){const X=it(F)(N);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1}g()}if(f==="HRight"){const X=it(F)(N);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()}if(f==="HLeft"){const X=it(F)(x);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1}g()})())},E=(P,I,F,Q)=>{const R=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),Y={free:I,isRoot:F},O=k(Y,Q);if(O.edge.tag==="Nothing")return O.hasEdges?{thresh:R,state:{...Q,queue:[...Q.queue,Y]}}:{thresh:R,state:Q};if(O.edge.tag==="Just"){const X=O.edge._1.from.node===I?O.edge._1.to.node:O.edge._1.from.node;return{thresh:(()=>{const q=it((()=>{const _t=it(X)(a.root);if(_t.tag==="Nothing")return X;if(_t.tag==="Just")return _t._1;g()})())(Q.x),K=it(X)(s),j=it(I)(s),ot=(()=>{if(q.tag==="Just")return q._1;if(q.tag==="Nothing")return J;g()})();return(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;g()})()+(()=>{if(K.tag==="Nothing")return 0;if(K.tag==="Just")return K._1;g()})()+d(O.edge._1,X,(()=>{if(F){if(f==="HRight")return le;if(f==="HLeft")return de;g()}if(f==="HRight")return de;if(f==="HLeft")return le;g()})())-(()=>{if(j.tag==="Nothing")return 0;if(j.tag==="Just")return j._1;g()})()-d(O.edge._1,I,(()=>{if(F){if(f==="HRight")return de;if(f==="HLeft")return le;g()}if(f==="HRight")return le;if(f==="HLeft")return de;g()})())})(),state:{...Q,su:Z(G)((()=>{const q=it(O.edge._1.from.node)(a.root);if(q.tag==="Nothing")return O.edge._1.from.node;if(q.tag==="Just")return q._1;g()})())(!0)(Z(G)((()=>{const q=it(O.edge._1.to.node)(a.root);if(q.tag==="Nothing")return O.edge._1.to.node;if(q.tag==="Just")return q._1;g()})())(!0)(Q.su))}}}g()},A=(P,I,F,Q)=>{const R=I===P,Y=it(I)(a.align),O=(()=>{if(Y.tag==="Nothing")return I===P;if(Y.tag==="Just")return Y._1===P;g()})();if(!(R||O))return{thresh:F,state:Q};const X=(()=>{if(c==="VDown")return R&&F<=-1e18;if(c==="VUp")return R&&F>=1e18;g()})()?E(P,I,!0,Q):{thresh:F,state:Q};return(()=>{if(c==="VDown")return X.thresh<=-1e18&&O;if(c==="VUp")return X.thresh>=1e18&&O;g()})()?E(P,I,!1,X.state):X},$=P=>I=>F=>{const Q=it(F)(e.nodeIndex),R=(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;g()})(),Y=Vt(j=>He(hn)(F)(j))(h),O=(()=>{if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1;g()})(),X=O.length;if((()=>{if(c==="VDown")return R<=0;if(c==="VUp")return R>=(X-1|0);g()})()){const j=A(P,F,I.thresh,I.st);return{...I,st:j.state,thresh:j.thresh}}const q=(()=>{if(c==="VDown")return R-1|0;if(c==="VUp")return R+1|0;g()})(),K=q>=0&&q<O.length?T("Just",O[q]):J;if(K.tag==="Nothing")return I;if(K.tag==="Just"){const j=it(K._1)(a.root),ot=(()=>{if(j.tag==="Nothing")return K._1;if(j.tag==="Just")return j._1;g()})(),_t=A(P,F,I.thresh,tt(ot)(I.st)),gt=(()=>{const Lt=it(P)(_t.state.sink);if(Lt.tag==="Nothing")return P===P;if(Lt.tag==="Just")return Lt._1===P;g()})()?{..._t.state,sink:Z(G)(P)((()=>{const Lt=it(ot)(_t.state.sink);if(Lt.tag==="Nothing")return ot;if(Lt.tag==="Just")return Lt._1;g()})())(_t.state.sink)}:_t.state,yt=it(ot)(gt.sink),Ct=(()=>{if(yt.tag==="Nothing")return ot;if(yt.tag==="Just")return yt._1;g()})(),Rt=it(P)(gt.sink),pt=(()=>{if(Rt.tag==="Nothing")return P;if(Rt.tag==="Just")return Rt._1;g()})();if(pt===Ct){const Lt=it(ot)(gt.x),Ht=(()=>{if(Lt.tag==="Just")return Lt._1;if(Lt.tag==="Nothing")return J;g()})(),dn=(()=>{if(Ht.tag==="Nothing")return 0;if(Ht.tag==="Just")return Ht._1;g()})(),Fe=it(P)(gt.x),Pt=(()=>{if(Fe.tag==="Just")return Fe._1;if(Fe.tag==="Nothing")return J;g()})(),Qt=(()=>{if(Pt.tag==="Nothing")return 0;if(Pt.tag==="Just")return Pt._1;g()})(),ze=y(F,K._1),an=it(K._1)(s),Xe=it(F)(s),nn=(()=>{if(an.tag==="Nothing")return 0;if(an.tag==="Just")return an._1;g()})()-(()=>{if(Xe.tag==="Nothing")return 0;if(Xe.tag==="Just")return Xe._1;g()})();if(c==="VDown"){const Ae=vn(dn+nn+p(K._1)+ze)(_t.thresh);return{st:{...gt,x:Z(G)(P)(T("Just",I.initial?Ae:vn(Qt)(Ae)))(gt.x)},initial:!1,thresh:_t.thresh}}if(c==="VUp"){const Ae=on(dn+nn-ze-p(F))(_t.thresh);return{st:{...gt,x:Z(G)(P)(T("Just",I.initial?Ae:on(Qt)(Ae)))(gt.x)},initial:!1,thresh:_t.thresh}}g()}const qt=it(ot)(gt.x),wt=(()=>{if(qt.tag==="Just")return qt._1;if(qt.tag==="Nothing")return J;g()})(),mt=(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1;g()})(),ft=it(P)(gt.x),st=(()=>{if(ft.tag==="Just")return ft._1;if(ft.tag==="Nothing")return J;g()})(),dt=(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;g()})(),at=et(t.nodeGap),ct=it(F)(s),Nt=it(K._1)(s),Jt=(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()-(()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1;g()})();return{st:{...gt,classEdges:[...gt.classEdges,{src:pt,tgt:Ct,sep:(()=>{if(c==="VDown")return dt+Jt-mt-p(K._1)-at;if(c==="VUp")return dt+Jt+p(F)+at-mt;g()})()}]},initial:I.initial,thresh:_t.thresh}}g()},tt=P=>I=>{const F=it(P)(I.x),Q=(()=>{if(F.tag==="Just")return F._1;if(F.tag==="Nothing")return J;g()})();if(Q.tag==="Just")return I;if(Q.tag==="Nothing"){const R=w($(P))({st:{...I,x:Z(G)(P)(T("Just",0))(I.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})()})(Di(a)(P));return{...R.st,blockFinished:Z(G)(P)(!0)(R.st.blockFinished)}}g()},S=w(P=>I=>w(F=>Q=>{const R=it(Q)(a.root),Y=(()=>{if(R.tag==="Nothing")return Q;if(R.tag==="Just")return R._1;g()})();return Y===Q?tt(Y)(F):F})(P)((()=>{if(c==="VDown")return I;if(c==="VUp")return ve(I);g()})()))({x:bn(H(P=>L(P,J))(v)),sink:bn(H(P=>L(P,P))(v)),classEdges:[],su:D,blockFinished:D,queue:[]})(h),C=Ux(S.classEdges)(S.sink)(c),V=(P,I,F,Q)=>{const R=it(I)(Q),Y=it(I)(s);return(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})()+(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;g()})()+d(P,I,F)},U=bn(H(P=>L(P,!0))(Fr(G.compare)((()=>{const P=(I,F)=>{if(I.tag==="Leaf")return F;if(I.tag==="Node")return P(I._5,Xt("Cons",I._4,P(I._6,F)));g()};return At(Kt.foldr,P(a.root,Ut))})()))),M=P=>I=>F=>{const Q=k(F,{su:I.su,blockFinished:U}),R={phase:P,ppFree:F.free,ppIsRoot:F.isRoot,edgeId:J,delta:0,avail:0,shift:0,freeSu:(()=>{const Y=it((()=>{const O=it(F.free)(a.root);if(O.tag==="Nothing")return F.free;if(O.tag==="Just")return O._1;g()})())(I.su);if(Y.tag==="Nothing")return!1;if(Y.tag==="Just")return Y._1;g()})(),hasEdges:Q.hasEdges,candCount:(()=>{if(F.isRoot){if(f==="HRight"){const Y=it(F.free)(x);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length;g()}if(f==="HLeft"){const Y=it(F.free)(N);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length}g()}if(f==="HRight"){const Y=it(F.free)(N);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length;g()}if(f==="HLeft"){const Y=it(F.free)(x);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length}g()})()};if(Q.edge.tag==="Nothing")return{...I,stack:[...I.stack,F],trace:[...I.trace,R],x:I.x};if(Q.edge.tag==="Just"){const Y=Q.edge._1.from.node===F.free?L(Q.edge._1.from.node,Q.edge._1.to.node):L(Q.edge._1.to.node,Q.edge._1.from.node),O=V(Q.edge._1,Y._1,l(Q.edge._1,Y._1),I.x)-V(Q.edge._1,Y._2,l(Q.edge._1,Y._2),I.x),X=it(Y._1)(a.root),q=(()=>{if(X.tag==="Nothing")return Y._1;if(X.tag==="Just")return X._1;g()})(),K={...R,edgeId:T("Just",Q.edge._1.id),delta:O};if(O>0&&O<1e300){const j=w(gt=>yt=>{const Ct=it(yt)(m),Rt=(()=>{if(Ct.tag==="Nothing")return-1;if(Ct.tag==="Just")return Ct._1;g()})();if(Rt>=0&&Rt<n.length){const wt=n[Rt],mt=it(yt)(e.nodeIndex),ft=(()=>{if(mt.tag==="Nothing")return-2;if(mt.tag==="Just")return mt._1-1|0;g()})();return ft>=0&&ft<wt.length?on(gt)((()=>{const st=it(yt)(I.x),dt=it(yt)(s),at=it(wt[ft])(I.x),ct=it(wt[ft])(s);return(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;g()})()+(()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1;g()})()-((()=>{if(at.tag==="Nothing")return 0;if(at.tag==="Just")return at._1;g()})()+(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+p(wt[ft])+y(yt,wt[ft]))})()):gt}const pt=it(yt)(e.nodeIndex),qt=(()=>{if(pt.tag==="Nothing")return-2;if(pt.tag==="Just")return pt._1-1|0;g()})();return qt>=0&&qt<0?on(gt)((()=>{const wt=it(yt)(I.x),mt=it(yt)(s),ft=it([][qt])(I.x),st=it([][qt])(s);return(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1;g()})()+(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()-((()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;g()})()+(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;g()})()+p([][qt])+y(yt,[][qt]))})()):gt})(O)(Di(a)(q)),ot=j>0?-j:0,_t={...I,x:j>0?_(q,ot,I.x):I.x,trace:[...I.trace,{...K,avail:j,shift:ot}]};return j>0?_t:{..._t,stack:[..._t.stack,F]}}if(O<0&&-O<1e300){const j=w(gt=>yt=>{const Ct=it(yt)(m),Rt=(()=>{if(Ct.tag==="Nothing")return-1;if(Ct.tag==="Just")return Ct._1;g()})();if(Rt>=0&&Rt<n.length){const wt=n[Rt],mt=it(yt)(e.nodeIndex),ft=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1+1|0;g()})();return ft>=0&&ft<wt.length?on(gt)((()=>{const st=it(wt[ft])(I.x),dt=it(wt[ft])(s),at=it(yt)(I.x),ct=it(yt)(s);return(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;g()})()+(()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1;g()})()-((()=>{if(at.tag==="Nothing")return 0;if(at.tag==="Just")return at._1;g()})()+(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+p(yt)+y(yt,wt[ft]))})()):gt}const pt=it(yt)(e.nodeIndex),qt=(()=>{if(pt.tag==="Nothing")return 0;if(pt.tag==="Just")return pt._1+1|0;g()})();return qt>=0&&qt<0?on(gt)((()=>{const wt=it([][qt])(I.x),mt=it([][qt])(s),ft=it(yt)(I.x),st=it(yt)(s);return(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1;g()})()+(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()-((()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;g()})()+(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;g()})()+p(yt)+y(yt,[][qt]))})()):gt})(-O)(Di(a)(q)),ot=j>0?j:0,_t={...I,x:j>0?_(q,ot,I.x):I.x,trace:[...I.trace,{...K,avail:j,shift:ot}]};return j>0?_t:{..._t,stack:[..._t.stack,F]}}return{...I,stack:[...I.stack,F],trace:[...I.trace,K],x:I.x}}g()},W=w(M(Yx))({x:bn(H(P=>L(P,(()=>{const I=it(P)(a.root),F=(()=>{if(I.tag==="Nothing")return P;if(I.tag==="Just")return I._1;g()})(),Q=it(F)(S.x),R=it((()=>{const O=it(F)(S.sink);if(O.tag==="Nothing")return F;if(O.tag==="Just")return O._1;g()})())(C),Y=(()=>{if(Q.tag==="Just")return Q._1;if(Q.tag==="Nothing")return J;g()})();return(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;g()})()+(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})()})()))(v)),su:S.su,stack:[],trace:[]})(S.queue),B=w(M(Vx))({...W,stack:[]})(ve(W.stack));return{x:B.x,queue:S.queue,trace:B.trace}},Zx=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>jx(t)(e)(n)(r)(i)(o)(u)(s)(a)(c)(f).x,t2=t=>e=>n=>r=>i=>o=>{const u=(a,c,f)=>{const d=it(c)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;g()})(),_=a.from.node===c?a.from.port:a.to.node===c?a.to.port:J;if(_.tag==="Just"){const h=it(c)(e);if(h.tag==="Just"){const p=Vt(m=>m.id===_._1)(h._1);if(p.tag==="Just"){const m=et(p._1.offset)*et(4);return f==="North"||f==="South"?m:0}if(p.tag==="Nothing"){const m=ti(i)(a.id)(f)(l);return f==="North"||f==="South"?m:0}g()}if(h.tag==="Nothing"){const p=ti(i)(a.id)(f)(l);return f==="North"||f==="South"?p:0}g()}if(_.tag==="Nothing"){const h=ti(i)(a.id)(f)(l);return f==="North"||f==="South"?h:0}g()},s=a=>c=>f=>d=>{let l=a,_=c,h=f,p=d,m=!0,y;for(;m;){const x=l,N=_,v=h,b=Mt(k=>J,k=>E=>T("Just",{head:k,tail:E}),p);if(b.tag==="Nothing"){m=!1,y=x;continue}if(b.tag==="Just"){const k=b._1.head,E=Vt($=>$.from.node===v&&$.to.node===k||$.from.node===k&&$.to.node===v)(r),A=(()=>{if(E.tag==="Nothing")return N+0;if(E.tag==="Just")return N+(u(E._1,v,E._1.from.node===v?le:de)-u(E._1,k,E._1.from.node===k?le:de));g()})();l=Z(G)(k)(A)(x),_=A,h=k,p=b._1.tail;continue}g()}return y};return w(a=>c=>{const f=Mt(_=>J,_=>h=>T("Just",{head:_,tail:h}),Di(t)(c)),d=(()=>{if(f.tag==="Nothing")return Z(G)(c)(0)(D);if(f.tag==="Just")return s(Z(G)(f._1.head)(0)(D))(0)(f._1.head)(f._1.tail);g()})(),l=w(_=>h=>vn(_)(-h._2))(0)(js(d));return w(_=>h=>Z(G)(h._1)(h._2+l)(_))(a)(js(d))})(D)(Fr(G.compare)((()=>{const a=(c,f)=>{if(c.tag==="Leaf")return f;if(c.tag==="Node")return a(c._5,Xt("Cons",c._4,a(c._6,f)));g()};return At(Kt.foldr,a(t.root,Ut))})()))},e2=t=>e=>{const n=(i,o,u)=>Je(3)(o)==="$d:"&&cc(kf,(()=>{const s=it(o)(t.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;g()})()),r=i=>o=>u=>s=>a=>c=>f=>{let d=i,l=o,_=s,h=c,p=f,m=!0,y;for(;m;){const x=d,N=l,v=_,b=h,k=p,E=N.length;if(k>=E){m=!1,y=x;continue}const A=k>=0&&k<N.length?T("Just",N[k]):J,$=(()=>{if(A.tag==="Nothing")return"";if(A.tag==="Just")return A._1;g()})(),tt=n(t,$);if(k===(E-1|0)||tt){const S=(()=>{if(tt){const C=it($)(t.preds),V=(()=>{if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;g()})();if(0<V.length){const U=v-1|0,M=it(V[0])(t.nodeIndex);if(M.tag==="Nothing")return U;if(M.tag==="Just")return M._1;g()}}return v-1|0})();d=w(C=>V=>{if(V>=0&&V<N.length){const U=N[V];return n(t,U)?C:w(M=>W=>{const B=it(W)(t.nodeIndex),P=(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})();return P<b||P>S?Z(G)(W+"\u2192"+U)()(M):M})(C)((()=>{const M=it(U)(t.preds);if(M.tag==="Nothing")return[];if(M.tag==="Just")return M._1;g()})())}return n(t,"")?C:w(U=>M=>{const W=it(M)(t.nodeIndex),B=(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})();return B<b||B>S?Z(G)(M+"\u2192")()(U):U})(C)((()=>{const U=it("")(t.preds);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;g()})())})(x)(zt(0,k)),l=N,_=v,h=S,p=k+1|0;continue}d=x,l=N,_=v,h=b,p=k+1|0}return y};return e.length<3?D:w(i=>o=>{if(o>=0&&o<e.length){const u=e[o];return r(i)((()=>{const s=o+1|0;return s>=0&&s<e.length?e[s]:[]})())(u)(u.length)(o)(0)(0)}return r(i)((()=>{const u=o+1|0;return u>=0&&u<e.length?e[u]:[]})())([])(0)(o)(0)(0)})(D)(zt(1,e.length-2|0))},n2=t=>e=>n=>r=>i=>{const o=Ye(e),u=w(s=>a=>{const c=w(f=>d=>{const l=(()=>{if(i==="HRight"){const m=it(d)(t.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()}if(i==="HLeft"){const m=it(d)(t.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}g()})(),_=l.length;if(_===0)return f;const h=An(_-1|0,2),p=An(_,2);return w(m=>y=>{if((()=>{const x=it(d)(m.align);if(x.tag==="Nothing")return d!==d;if(x.tag==="Just")return x._1!==d;g()})())return m;if(y>=0&&y<l.length){const x=it(l[y])(t.nodeIndex),N=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})();if(!(Ff(l[y]+"\u2192"+d)(n)||Ff(d+"\u2192"+l[y])(n))&&(()=>{if(r==="VDown")return m.r<N;if(r==="VUp")return m.r>N;g()})()){const v=it(l[y])(m.root),b=(()=>{if(v.tag==="Nothing")return l[y];if(v.tag==="Just")return v._1;g()})();return{root:Z(G)(d)(b)(m.root),align:Z(G)(l[y])(d)(Z(G)(d)(b)(m.align)),r:N}}}return m})(f)((()=>{if(r==="VDown")return zt(h,p);if(r==="VUp")return ve(zt(h,p));g()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;g()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return ve(a);g()})());return{root:c.root,align:c.align}})({root:bn(H(s=>L(s,s))(o)),align:bn(H(s=>L(s,s))(o))})((()=>{if(i==="HRight")return e;if(i==="HLeft")return ve(e);g()})());return{root:u.root,align:u.align}},jo=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>{const f=n2(e)(n)(s)(a)(c),d=t2(f)(i)(r)(o)(u)(c);return Zd()(l=>_=>T("Just",(()=>{const h=it(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;g()})()))(Zx(t)(e)(n)(r)(i)(o)(u)(d)(f)(a)(c))},Bf=t=>e=>Ft(n=>r=>w(i=>o=>o>=0&&o<e.length?o>=0&&o<t.length?i+e[o]+t[o]:i+e[o]+0:o>=0&&o<t.length?i+1+t[o]:i+1)(0)((()=>{const i=zt(0,e.length-1|0);return n<1?[]:kt(0,n,i)})()))(e),r2=t=>e=>n=>r=>i=>o=>u=>{const s=$x(0)(e.length-1|0),a=et(t.layerGap),c=u(Dd(s,a)),f=ox(vf(i)(c)(r)(o)(D))(c);return H(d=>{const l=Xx(d)(f);return l.tag==="Just"&&l._1>0?vn(a)(2+et(l._1-1|0)*2.5):a})(zt(0,s-1|0))},Mf=t=>e=>n=>r=>cc(i=>w(o=>u=>{if(!o.ok)return o;const s=it(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})(),c=it(u)(n),f=(()=>{if(c.tag==="Nothing")return a+1;if(c.tag==="Just")return a+c._1._1;g()})();return a+1e-4>o.pos&&f+1e-4>o.pos?{ok:!0,pos:f}:{ok:!1,pos:o.pos}})({ok:!0,pos:-1e18})(i).ok,e),i2=t=>e=>n=>r=>{const i=Et(o=>u=>rt.compare(o.w)(u.w))(H(o=>({l:o,w:zf(o)}))(ut(Mf()(e)(n),r)));return 0<i.length?T("Just",i[0].l):J},o2=t=>e=>{const n=bn(Ye(H(Ft(i=>o=>L(o,i)))(t))),r=i=>Et(o=>u=>nt.compare((()=>{const s=it(o)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})())((()=>{const s=it(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(i);return{preds:(()=>{const i=o=>{if(o.tag==="Leaf")return D;if(o.tag==="Node")return Ot("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(w(o=>u=>bt(G)(ne)(u.to.node)([u.from.node])(o))(D)(e))})(),succs:(()=>{const i=o=>{if(o.tag==="Leaf")return D;if(o.tag==="Node")return Ot("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(w(o=>u=>bt(G)(ne)(u.from.node)([u.to.node])(o))(D)(e))})(),nodeIndex:n}},u2=t=>e=>{const n=Et(d=>l=>rt.compare(d.w)(l.w))(Ft(d=>l=>({i:d,l,w:zf(l)}))(e)),r=0<n.length?T("Just",n[0]):J,i=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;g()})(),o=i>=0&&i<e.length?T("Just",e[i]):J,u=(()=>{if(o.tag==="Just")return(d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const y=_,x=h;if(x.tag==="Nil"){p=!1,m=y;continue}if(x.tag==="Cons"){_=on(y)(x._1),h=x._2;continue}g()}return m})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,Xt("Cons",l._4,d(l._6,_)));g()};return d(o._1,Ut)})());if(o.tag==="Nothing")return 0;g()})(),s=d=>w(l=>_=>vn(l)((()=>{const h=it(_._1)(t);if(h.tag==="Nothing")return _._2+1;if(h.tag==="Just")return _._2+h._1._1;g()})()))(-999999)(js(d)),a=i>=0&&i<e.length?T("Just",e[i]):J,c=(()=>{if(a.tag==="Just")return s(a._1);if(a.tag==="Nothing")return 0;g()})(),f=be(d=>l=>{const _=h=>{if(h.tag==="Leaf")return D;if(h.tag==="Node")return Ot("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));g()};return _(d)},e,Ft(d=>l=>Kn(d)(2)===0?u-(_=>h=>{let p=_,m=h,y=!0,x;for(;y;){const N=p,v=m;if(v.tag==="Nil"){y=!1,x=N;continue}if(v.tag==="Cons"){p=on(N)(v._1),m=v._2;continue}g()}return x})(999999)((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,Xt("Cons",h._4,_(h._6,p)));g()};return _(l,Ut)})()):c-s(l))(e));return Kx(w(d=>l=>{const _=Et(rt.compare)(xt(it(l))(f));return Z(G)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(D)(Fr(G.compare)(Ye(H(d=>{const l=_=>{if(_.tag==="Leaf")return D;if(_.tag==="Node")return Ot("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));g()};return At($e.foldr,l(d))})(f)))))},s2=t=>e=>n=>r=>i=>o=>{const u=o2(e)(i),s=e2(u)(e),a={nodeGap:t.nodeGap*4|0},c=Ge(G.compare,Se,bn(H(_=>L(_,L(1,1)))(ut(kf,Ye(e)))),(()=>{const _=h=>{if(h.tag==="Leaf")return D;if(h.tag==="Node")return Ot("Node",h._1,h._2,h._3,L(h._4._1*et(4),h._4._2),_(h._5),_(h._6));g()};return _(n)})()),f=[jo(a)(u)(e)(c)(r)(i)(o)(s)(Af)(Qf),jo(a)(u)(e)(c)(r)(i)(o)(s)(If)(Qf),jo(a)(u)(e)(c)(r)(i)(o)(s)(Af)(Df),jo(a)(u)(e)(c)(r)(i)(o)(s)(If)(Df)],d=u2(c)(f);if(Mf()(e)(c)(d))return d;const l=i2()(e)(c)(f);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return f[0];g()},a2=t=>e=>n=>r=>{const i=uc(J,Za,o=>o.node===e?T("Just",o.position):J,t);if(i.tag==="Nothing")return t;if(i.tag==="Just"){const o=i._1;return H(u=>u.node===n?{...u,position:L(o._1+r._1,o._2+r._2)}:u)(t)}g()},c2=t=>e=>n=>r=>{const i=ut(u=>He(hn)(u.node)(e),t),o=(()=>{if(n==="Vertical"){if(r==="Start")return w(u=>s=>on(u)(s.position._1))(99999)(i);if(r==="End")return w(u=>s=>vn(u)(s.position._1))(0)(i);if(r==="Center"){const u=w(s=>a=>s+a.position._1)(0)(i);return i.length===0?0:u/et(i.length)}g()}if(n==="Horizontal"){if(r==="Start")return w(u=>s=>on(u)(s.position._2))(99999)(i);if(r==="End")return w(u=>s=>vn(u)(s.position._2))(0)(i);if(r==="Center"){const u=w(s=>a=>s+a.position._2)(0)(i);return i.length===0?0:u/et(i.length)}}g()})();return H(u=>{if(He(hn)(u.node)(e)){if(n==="Vertical")return{...u,position:L(o,u.position._2)};if(n==="Horizontal")return{...u,position:L(u.position._1,o)};g()}return u})(t)},g2=t=>e=>w(n=>r=>r.tag==="AlignGroup"?c2(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?a2(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),f2=t=>e=>n=>r=>i=>o=>u=>s=>{const a=H(d=>w(l=>_=>vn(l)((()=>{const h=it(_)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;g()})()))(1)(d))(n),c=s2(t)(n)(r)(i)(o)(s),f=Bf(r2(t)(n)(r)(i)(o)(u)(d=>{const l=Bf(d)(a);return Ye(Ft(_=>h=>Ft(p=>m=>({node:m,position:L((()=>{const y=it(m)(c);return(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;g()})()/et(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const y=Je(3)(m)==="$d:"?L(0,1):L(1,1),x=it(m)(r);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;g()})(),layer:_,order:p}))(h))(n))}))(a);return g2(e)(Ye(Ft(d=>l=>Ft(_=>h=>({node:h,position:L((()=>{const p=it(h)(c);return(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})()/et(4)})(),d>=0&&d<f.length?f[d]:0),size:(()=>{const p=Je(3)(h)==="$d:"?L(0,1):L(1,1),m=it(h)(r);if(m.tag==="Nothing")return p;if(m.tag==="Just")return m._1;g()})(),layer:d,order:_}))(l))(n)))},Zs=os(lo)(wr(32)),Wf=os(lo)(wr(31)),Fi=(()=>{const t=Ul("25214903917");if(t.tag==="Nothing")return Lc;if(t.tag==="Just")return t._1;g()})(),zi=is(os(lo)(wr(48)))(lo),_2=t=>{const e=Kl(t);return Ji(kc((()=>{if(e.tag==="Nothing")return Lc;if(e.tag==="Just")return e._1;g()})())(Fi))(zi)},ta=wr(11),Zo=t=>e=>{const n=Ji(fo(_o(e)(Fi))(ta))(zi);return L((()=>{const r=dc($l(us(n)(wr(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},d2=t=>{const e=Zo(26)(t),n=Zo(27)(e._2);return L((et(e._1)*Wu(2)(27)+et(n._1))/Wu(2)(53),n._2)},l2=t=>e=>{const n=w(r=>i=>{const o=d2(r.finalR);return{rs:[...r.rs,o._1],finalR:o._2}})({rs:[],finalR:t})(e);return L(H(r=>r.x)(Et(r=>i=>rt.compare(r.k)(i.k))(be(r=>i=>({x:r,k:i}),e,n.rs))),n.finalR)},h2=t=>{const e=Ji(fo(_o(t)(Fi))(ta))(zi),n=Ji(fo(_o(e)(Fi))(ta))(zi);return L(fo(_o((()=>{const r=us(e)(wr(16));return Ec.compare(r)(Wf)!=="LT"?is(r)(Zs):r})())(Zs))((()=>{const r=us(n)(wr(16));return Ec.compare(r)(Wf)!=="LT"?is(r)(Zs):r})()),n)},Bi=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},tu=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},ea=te(G)(Bt),ei=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},eu=te(G)(Bt),p2=Bu(fi),m2=w(Mr)(0),y2=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Rf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},x2=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const i=Un(Zt,J,t,n[e],n);if(i.tag==="Just")return Un(Zt,J,e,r,i._1);if(i.tag==="Nothing")return J;g()}}return J},N2=t=>e=>n=>r=>i=>ea(w(o=>u=>{const s=Et(a=>c=>nt.compare((()=>{const f=Bi(a.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})())((()=>{const f=Bi(c.id)(i);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})()))(ut(a=>tu(a.to.node)(n),ut(a=>a.from.node===u,r)));return{ranks:[...o.ranks,...Ft(a=>c=>L(c.id,et((o.rankSum+a|0)+1|0)))(s)],rankSum:o.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),J2=t=>e=>n=>r=>i=>ea(w(o=>u=>{const s=Et(c=>f=>{const d=nt.compare((()=>{const l=ei(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=ei(c.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})());return d==="EQ"?nt.compare((()=>{const l=Bi(c.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})())((()=>{const l=Bi(f.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})()):d})(ut(c=>tu(c.from.node)(n),ut(c=>c.to.node===u,r))),a=s.length;return{ranks:[...o.ranks,...Ft(c=>f=>L(f.id,et((o.rankSum+a|0)-c|0)))(s)],rankSum:o.rankSum+a|0}})({ranks:[],rankSum:0})(t).ranks),na=t=>e=>n=>{const r=eu(Ft(s=>a=>L(a,s))(t)),i=eu(Ft(s=>a=>L(a,s))(e)),o=xt(s=>{const a=ei(s.from.node)(r),c=ei(s.to.node)(i);if(a.tag==="Just"&&c.tag==="Just")return T("Just",L(a._1,c._1));const f=ei(s.from.node)(i),d=ei(s.to.node)(r);return f.tag==="Just"&&d.tag==="Just"?T("Just",L(d._1,f._1)):J})(n),u=o.length;return w(s=>a=>w(c=>f=>a>=0&&a<o.length&&f>=0&&f<o.length&&((o[a]._1-o[f]._1|0)*(o[a]._2-o[f]._2|0)|0)<0?c+1|0:c)(s)(zt(a+1|0,u-1|0)))(0)(zt(0,u-2|0))},w2=t=>e=>n=>r=>{const i=o=>u=>{let s=o,a=u,c=!0,f;for(;c;){const d=s,l=a;if(l>=(d.length-1|0)){c=!1,f=d;continue}if(l>=0&&l<d.length){const _=l+1|0;if(_>=0&&_<d.length){const h=d[l],p=d[_];if(qe(N=>N.before===h&&N.after===p,r)){s=d,a=l+1|0;continue}const m=Un(Zt,J,l,p,d),y=(()=>{if(m.tag==="Just")return Un(Zt,J,l+1|0,h,m._1);if(m.tag==="Nothing")return J;g()})(),x=(()=>{if(y.tag==="Nothing")return d;if(y.tag==="Just")return y._1;g()})();if(na(e)(x)(n)<na(e)(d)(n)){s=x,a=l+1|0;continue}s=d,a=l+1|0;continue}c=!1,f=d;continue}c=!1,f=d}return f};return(o=>{let u=o,s=!0,a;for(;s;){const c=u,f=i(c)(0);if(p2(f)(c)){s=!1,a=c;continue}u=f}return a})(t)},nu=t=>e=>w(n=>r=>{if(r>=0&&r<t.length){const i=t[r],o=r+1|0;if(o>=0&&o<t.length)return n+na(i)(t[o])(e)|0}return n})(0)(zt(0,t.length-2|0)),T2=(()=>{const t=e=>{if(e.length<7){const o=u=>s=>{let a=u,c=s,f=!0,d;for(;f;){const l=a,_=c,h=_-1|0;if(h>=0&&h<l.length){if(_>=0&&_<l.length&&_>0&&l[h].key>l[_].key){const p=x2(_-1|0)(_)(l);if(p.tag==="Just"){a=p._1,c=_-1|0;continue}if(p.tag==="Nothing"){f=!1,d=l;continue}g()}f=!1,d=l;continue}f=!1,d=l}return d};return w(u=>s=>o(u)(s))(e)(zt(1,e.length-1|0))}const n=An(e.length,2),r=t(kt(0,n,e)),i=t(kt(n,e.length,e));return(o=>u=>s=>{let a=o,c=u,f=s,d=!0,l;for(;d;){const _=a,h=c,p=f;if(h>=0&&h<r.length){if(p>=0&&p<i.length){if(r[h].key>i[p].key){a=Dt(_)(i[p]),c=h,f=p+1|0;continue}a=Dt(_)(r[h]),c=h+1|0,f=p;continue}d=!1,l=[..._,...h<1?r:kt(h,r.length,r)];continue}d=!1,l=[..._,...p<1?i:kt(p,i.length,i)]}return l})([])(0)(0)};return t})(),v2=t=>e=>n=>{const r=xt(c=>c.tag==="OrderConstraint"?T("Just",{before:c._1.before,after:c._1.after}):J)(t.constraints),i=c=>w(f=>d=>{const l=d.after,_=d.before,h=hr(Zt,J,m=>m===_,f),p=hr(Zt,J,m=>m===l,f);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=ac(Zt,J,h._1,f),y=(()=>{if(m.tag==="Nothing")return f;if(m.tag==="Just")return m._1;g()})(),x=sc(Zt,J,p._1,_,y);if(x.tag==="Nothing")return y;if(x.tag==="Just")return x._1;g()}return f})(c)(r),o=ea(Ft(c=>f=>L(f.id,c))(n)),u=(c,f,d)=>{const l=c.length;return w(_=>h=>{const p=f?h-1|0:h+1|0,m=p>=0&&p<_._1.length?T("Just",_._1[p]):J;if(m.tag==="Just"){const y=h>=0&&h<_._1.length?T("Just",_._1[h]):J;if(y.tag==="Just"){const x=eu(Ft(E=>A=>L(A,E))(m._1)),N=eu(Ft(E=>A=>L(A,E))(y._1)),v=f?N2(m._1)(x)(N)(n)(o):J2(m._1)(x)(N)(n)(o),b=w(E=>A=>{const $=xt(S=>Bi(S.id)(v))(ut(f?S=>S.to.node===A._2&&tu(S.from.node)(x):S=>S.from.node===A._2&&tu(S.to.node)(x),n));if($.length===0)return{...E,items:[...E.items,{n:A._2,key:J,origIdx:A._1}]};const tt=Zo(24)(E.r);return{items:[...E.items,{n:A._2,key:T("Just",(m2($)+(et(tt._1)*4172325152040912e-24-.03500000014901161))/et($.length)),origIdx:A._1}],r:tt._2}})({items:[],r:_._2})(Ft(ln)(y._1)),k=Un(Zt,J,h,w2(i(H(E=>E.n)(T2((()=>{const E=b.items,A=$=>tt=>{let S=$,C=tt,V=!0,U;for(;V;){const M=S,W=C;if(M>=0&&M<E.length){if(E[M].key.tag==="Just"){V=!1,U=E[M].key._1;continue}if(E[M].key.tag==="Nothing"){S=M+1|0,C=W;continue}g()}V=!1,U=W}return U};return($=>tt=>S=>{let C=$,V=tt,U=S,M=!0,W;for(;M;){const B=C,P=V,I=U;if(B>=0&&B<E.length){if(E[B].key.tag==="Just"){C=B+1|0,V=E[B].key._1,U=[...I,{n:E[B].n,key:E[B].key._1,origIdx:E[B].origIdx}];continue}if(E[B].key.tag==="Nothing"){const F=(P+A(B+1|0)(P+1))/2;C=B+1|0,V=F,U=[...I,{n:E[B].n,key:F,origIdx:E[B].origIdx}];continue}g()}M=!1,W=I}return W})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(k.tag==="Just")return L(k._1,b.r);if(k.tag==="Nothing")return L(_._1,_._2);g()}if(y.tag==="Nothing")return L(_._1,_._2);g()}if(m.tag==="Nothing")return L(_._1,_._2);g()})(L(c,d))(f?zt(1,l-1|0):ve(zt(0,l-2|0)))},s=w(c=>f=>Z(G)(f.from.node)()(Z(G)(f.to.node)()(c)))(D)(n),a=w(c=>f=>{if(c.result.crossings===0)return c;const d=x=>N=>v=>b=>{let k=x,E=N,A=v,$=b,tt=!0,S;for(;tt;){const C=k,V=E,U=A,M=$;if(U===0){tt=!1,S={layout:C,crossings:0,random:M};continue}const W=u(C,V,M),B=nu(W._1)(n);if(B<U){k=W._1,E=!V,A=B,$=W._2;continue}tt=!1,S={layout:C,crossings:U,random:W._2}}return S},l=Zo(1)(c.result.random),_=l._1!==0,h=t.modelOrder.tag==="Leaf",p=(c.firstTry||c.secondTry)&&!h?c.firstTry:_,m=(()=>{if(!h){const b=u(e,p,l._2);return d(b._1)(!p)(nu(b._1)(n))(b._2)}const x=p?0:y2(0)(e.length-1|0),N=x>=0&&x<e.length?T("Just",e[x]):J;if(N.tag==="Just"&&N._1.length>1){const b=ut(k=>Rf(k)(s),N._1);if(b.length>1){const k=l2(l._2)(b),E=k._1,A=Un(Zt,J,x,i(w($=>tt=>Rf(tt)(s)?$.idx>=0&&$.idx<E.length?{idx:$.idx+1|0,result:[...$.result,E[$.idx]]}:{idx:$.idx,result:[...$.result,tt]}:{idx:$.idx,result:[...$.result,tt]})({idx:0,result:[]})(N._1).result),e);if(A.tag==="Just"){const $=u(A._1,p,k._2);return d($._1)(!p)(nu($._1)(n))($._2)}}}const v=u(e,p,l._2);return d(v._1)(!p)(nu(v._1)(n))(v._2)})(),y=c.secondTry?!1:c.secondTry;return c.firstTry?{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:c.firstTry,secondTry:y}})({result:{layout:e,crossings:1e9,random:Ji(kc(h2(_2(1))._1)(Fi))(zi)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(zt(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:a.layout},b2=t=>t,qf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Me=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},ni=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Mi=(()=>{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"?ye:G.compare(e._2)(n._2)},Eq0:()=>t}})(),L2=te(G)(Bt),k2=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=Mi.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},E2=b2("Greedy"),ra=t=>e=>n=>w(r=>i=>{if(i.from.node===i.to.node)return r;if(i.from.node===e&&!qf(i.to.node)(r.marks)){const o=Me(i.to.node)(r.inDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;g()})(),s=Z(G)(i.to.node)(u)(r.inDeg);return(()=>{const a=Me(i.to.node)(r.outDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!He(hn)(i.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,i.to.node]}:{...r,inDeg:s}}if(i.to.node===e&&!qf(i.from.node)(r.marks)){const o=Me(i.from.node)(r.outDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;g()})(),s=Z(G)(i.from.node)(u)(r.outDeg);return(()=>{const a=Me(i.from.node)(r.inDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!He(hn)(i.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,i.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:ut(r=>r!==e,n.remaining)})(t),S2=w(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return Z(G)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return Z(G)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return Z(G)(e._1.node)(99999)(t)}return t})(D),Hf=t=>e=>n=>{const r=Me(e)(t),i=Me(n)(t);return r.tag==="Just"&&i.tag==="Just"&&r._1>i._1},Of=t=>e=>n=>r=>{if(ni(n)(r.visited)||ni(n)(r.visiting))return r;const i=w(C2(t)(e)(n))({...r,visiting:Z(G)(n)()(r.visiting)})((()=>{const o=Me(n)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;g()})());return{...i,visiting:di(G)(n)(i.visiting),visited:Z(G)(n)()(i.visited)}},C2=t=>e=>n=>r=>i=>Hf(t)(n)(i)?{...r,backEdges:Z(Mi)(L(n,i))()(r.backEdges)}:ni(i)(r.visiting)?{...r,backEdges:Z(Mi)(L(n,i))()(r.backEdges)}:ni(i)(r.visited)?r:Of(t)(e)(i)(r),G2=t=>e=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,y=Mt(x=>J,x=>N=>T("Just",{head:x,tail:N}),m.sinks);if(y.tag==="Just"){_=ra(n)(y._1.head)({...m,sinks:y._1.tail,marks:Z(G)(y._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(y.tag==="Nothing"){const x=Mt(N=>J,N=>v=>T("Just",{head:N,tail:v}),m.sources);if(x.tag==="Just"){_=ra(n)(x._1.head)({...m,sources:x._1.tail,marks:Z(G)(x._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(x.tag==="Nothing"){const N=b=>{const k=Me(b)(m.outDeg),E=Me(b)(m.inDeg);return(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;g()})()-(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;g()})()|0},v=Et(b=>k=>{const E=nt.compare(N(k))(N(b));return E==="EQ"?nt.compare((()=>{const A=Me(b)(e);if(A.tag==="Nothing")return 1e6;if(A.tag==="Just")return A._1;g()})())((()=>{const A=Me(k)(e);if(A.tag==="Nothing")return 1e6;if(A.tag==="Just")return A._1;g()})()):E})(m.remaining);if(0<v.length){const b=v[0];_=ra(n)(b)({...m,remaining:ut(k=>k!==b,m.remaining),marks:Z(G)(b)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}g()}return p},i=Fr(G.compare)([...H(l=>l.from.node)(n),...H(l=>l.to.node)(n)]),o=ut(l=>l.from.node!==l.to.node,n),u=w(l=>_=>bt(G)(se)(_.to.node)(1)(l))(D)(o),s=w(l=>_=>bt(G)(se)(_.from.node)(1)(l))(D)(o),a=ut(l=>{const _=Me(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),c=ut(l=>{const _=Me(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},i),f=i.length+1|0,d=w(l=>_=>{const h=Me(_)(l);return h.tag==="Just"&&h._1<0?Z(G)(_)(h._1+f|0)(l):l})(r({remaining:ut(l=>!He(hn)(l)(a)&&!He(hn)(l)(c),i),marks:D,inDeg:u,outDeg:s,sources:a,sinks:c,nextLeft:1,nextRight:-1}).marks)(i);return w(l=>_=>{if(_.from.node===_.to.node)return l;if(Hf(t)(_.from.node)(_.to.node))return Z(Mi)(L(_.from.node,_.to.node))()(l);const h=Me(_.from.node)(d),p=Me(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?Z(Mi)(L(_.from.node,_.to.node))()(l):l})(D)(n)},P2=w(t=>e=>bt(G)(ne)(e.from.node)([e.to.node])(t))(D),A2=t=>e=>{const n=P2(e),r=Fr(G.compare)([...H(o=>o.from.node)(e),...H(o=>o.to.node)(e)]),i=w(o=>u=>Z(G)(u.to.node)()(o))(D)(e);return w(o=>u=>Of(t)(n)(u)(o))({visiting:D,visited:D,backEdges:D})([...ut(o=>!ni(o)(i),r),...ut(o=>ni(o)(i),r)]).backEdges},I2=t=>e=>n=>r=>{const i=L2(Ft(s=>a=>L(a,s))(e)),o=S2(n),u=(()=>{if(t==="DepthFirst")return A2(o)(r);if(t==="Greedy")return G2(o)(i)(r);g()})();return{edges:H(s=>k2(L(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},$f=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Q2=w(t=>e=>Z(G)(e)()(t))(D),ru=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},D2=af(G),Ln=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Xf=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ia=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},F2=te(nt)(Bt),z2=t=>e=>Ge(G.compare,Se,t,e),Yf=Ft(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),B2=t=>w(e=>n=>({base:(()=>{const r=i=>o=>{let u=i,s=o,a=!0,c;for(;a;){const f=u,d=s;if(d.tag==="Nil"){a=!1,c=f;continue}if(d.tag==="Cons"){u=$f(f)(d._1),s=d._2;continue}g()}return c};return(e.base+r(0)((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,Xt("Cons",o._4,i(o._6,u)));g()};return i(n,Ut)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=i=>{if(i.tag==="Leaf")return D;if(i.tag==="Node")return Ot("Node",i._1,i._2,i._3,i._4+e.base|0,r(i._5),r(i._6));g()};return r(n)})()]}))({base:0,result:[]})(t).result,M2=t=>e=>{const n=Q2(t);return D2(t)(Yf(ut(r=>ru(r.src)(n)&&ru(r.tgt)(n),e)))},W2=t=>e=>{const n=w(i=>o=>bt(G)(ne)(o.tgt)([o.src])(bt(G)(ne)(o.src)([o.tgt])(i)))(D)(e),r=i=>o=>u=>{let s=i,a=o,c=u,f=!0,d;for(;f;){const l=s,_=a,h=c,p=Mt(m=>J,m=>y=>T("Just",{head:m,tail:y}),l);if(p.tag==="Nothing"){f=!1,d={nodes:h};continue}if(p.tag==="Just"){if(ru(p._1.head)(_)){s=p._1.tail,a=_,c=h;continue}s=[...p._1.tail,...(()=>{const m=Ln(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()})()],a=Z(G)(p._1.head)()(_),c=[...h,p._1.head];continue}g()}return d};return w(i=>o=>{if(ru(o)(i.visited))return i;const u=r([o])(i.visited)([]);return{...i,visited:w(s=>a=>Z(G)(a)()(s))(i.visited)(u.nodes),components:[...i.components,u.nodes]}})({visited:D,components:[]})(t).components},R2=t=>e=>n=>{const r=w(o=>u=>bt(G)(se)(u.tgt)(1)(o))(D)(e),i=w(o=>u=>bt(G)(se)(u.src)(1)(o))(D)(e);return w(o=>u=>{const s=Ln(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})();if((()=>{const x=Ln(u)(i);return(()=>{if(x.tag==="Nothing")return a!==0;if(x.tag==="Just")return a!==x._1;g()})()||a===0})())return o;const c=Ln(u)(o.layers),f=(()=>{if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1;g()})(),d=o.layers,l=w(x=>N=>N.tgt===u?{...x,mIn:Xf(x.mIn)((()=>{const v=Ln(u)(d),b=Ln(N.src)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;g()})()|0})())}:N.src===u?{...x,mOut:Xf(x.mOut)((()=>{const v=Ln(N.tgt)(d),b=Ln(u)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;g()})()|0})())}:x)({mIn:1e9,mOut:1e9})(e),_=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(_<0||h<0)return o;const p=(f-_|0)+1|0,m=(f+h|0)-1|0;if(m<p)return o;const y=w(x=>N=>{const v=ia(N)(o.filling),b=(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;g()})();return b<x.bestFill?{best:N,bestFill:b}:x})({best:f,bestFill:(()=>{const x=ia(f)(o.filling);if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})()})(zt(p,m));return y.best===f?o:{layers:Z(G)(u)(y.best)(o.layers),filling:Z(nt)(f)((()=>{const x=ia(f)(o.filling);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;g()})())(Z(nt)(y.best)(y.bestFill+1|0)(o.filling))}})({layers:n,filling:F2(H(o=>L(o,w(u=>s=>(()=>{const a=Ln(s)(n);return a.tag==="Nothing"?!1:a.tag==="Just"&&a._1===o})()?u+1|0:u)(0)(t)))(zt(0,w(o=>u=>$f(o)((()=>{const s=Ln(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;g()})()))(0)(t))))})(t).layers},q2=t=>e=>R2(t)(Yf(e))(w(z2)(D)(B2(H(n=>M2(n)(e))(W2(t)(e))))),H2=t=>t,Lr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},iu=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Vf=(()=>{const t=Ue.unfoldr(Jn);return e=>t(Ke("IterNode",e,Nn))})(),O2=H2("NetworkSimplex"),$2=t=>e=>w(n=>r=>{const i=w(iu)(0)(xt(o=>Lr(o)(n))(r));return w(o=>u=>Z(G)(u)(i)(o))(n)(r)})(e)(t),X2=t=>e=>({layers:H(n=>ut(r=>{const i=Lr(r)(e);return i.tag==="Nothing"?!1:i.tag==="Just"&&i._1===n},t))(zt(0,(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,c=o;if(c.tag==="Nil"){u=!1,s=a;continue}if(c.tag==="Cons"){i=iu(a)(c._1),o=c._2;continue}g()}return s})(0)((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Xt("Cons",r._4,n(r._6,i)));g()};return n(e,Ut)})()))),nodeLayer:e}),Y2=t=>e=>n=>{const r=w(i=>o=>Z(G)(o)(!0)(i))(D)(e);return w(i=>o=>Z(G)(o._1)(o._2)(i))(q2(e)(xt(i=>i.from.node===i.to.node||(()=>{const o=Lr(i.from.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()||(()=>{const o=Lr(i.to.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;g()})()?J:T("Just",{src:i.from.node,tgt:i.to.node}))(t)))(Vf(n))},V2=t=>e=>n=>r=>{const i=s=>a=>{const c=Lr(a)(s);if(c.tag==="Just")return s;if(c.tag==="Nothing"){const f=ut(l=>l!==a,(()=>{const l=Lr(a)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;g()})()),d=w(i)(s)(f);return Z(G)(a)(1+w(iu)(0)(xt(l=>Lr(l)(d))(f))|0)(d)}g()},o=w(i)(D)(n),u=(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=iu(_)(h._1),f=h._2;continue}g()}return l})(1)((()=>{const s=(a,c)=>{if(a.tag==="Leaf")return c;if(a.tag==="Node")return s(a._5,Xt("Cons",a._4,s(a._6,c)));g()};return s(o,Ut)})());return w(s=>a=>Z(G)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return D;if(a.tag==="Node")return Ot("Node",a._1,a._2,a._3,u-a._4|0,s(a._5),s(a._6));g()};return s(o)})())(Vf(r))},U2=w(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return Z(G)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return Z(G)(e._1.node)(0)(t)}return t})(D),K2=w(t=>e=>bt(G)(ne)(e.to.node)([e.from.node])(t))(D),j2=w(t=>e=>bt(G)(ne)(e.from.node)([e.to.node])(t))(D),Z2=t=>e=>n=>r=>{const i=j2(n),o=K2(n),u=U2(e);return X2(r)($2(xt(s=>s.tag==="SameLayer"?T("Just",s._1.nodes):J)(e))((()=>{if(t==="LongestPath")return V2(i)(o)(r)(u);if(t==="NetworkSimplex")return Y2(n)(r)(u);g()})()))},tN=te(G)(Bt),eN=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Uf=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Kf=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Wi=te(G)(Bt),nN=te(G)(Bt),jf=(()=>{const t=H(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>ve(t(e))})(),rN=t=>e=>n=>r=>{const i=tN(H(u=>L(u.edge,u))(r)),o=u=>0<u.nodes.length&&(()=>{const s=eN(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return H(u=>{if(u.nodes.length<=2){const f=Uf(u.edgeId)(i);if(f.tag==="Just"){const d=o(u),l=Ai(Pi(d?jf(f._1.segments):f._1.segments));return{...f._1,edge:u.edgeId,segments:l,bends:be(_=>h=>_.end,l,kt(1,l.length,l)),reversed:d}}if(f.tag==="Nothing")return{edge:u.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};g()}const s=Tt(xt(f=>Uf(f)(i))(be(f=>d=>u.edgeId+":"+f+"->"+d,u.nodes,kt(1,u.nodes.length,u.nodes))))(f=>f.segments),a=o(u),c=Ai(Pi(a?jf(s):s));return{edge:u.edgeId,segments:c,bends:be(f=>d=>f.end,c,kt(1,c.length,c)),bendType:[],jumps:[],reversed:a}})(t)},iN={layers:[],edges:[],chains:[]},oN={nodeGap:3,layerGap:2,iterations:8,layerer:O2,cycleBreaker:E2,compactPostRouting:!0,compactionSpacings:Ky},uN=t=>({pos:L(0,0),size:L(w(e=>n=>Kf(e)(n.position._1+n.size._1))(0)(t),w(e=>n=>Kf(e)(n.position._2+n.size._2))(0)(t))}),sN=t=>e=>n=>{const r=Wi(H(c=>L(c.id,c.ports))(e.nodes)),i=ut(c=>Je(3)(c.node)!=="$d:",n.placements),o=rN(n.withDummies.chains)(n.acyclic.reversedEdges)(nN(H(c=>L(c.id,L(c.from.node,c.to.node)))(e.edges)))(Px(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(Sf(n.ordered)(ut(c=>c.from.node!==c.to.node,n.withDummies.edges))((()=>{const c=f=>{if(f.tag==="Leaf")return D;if(f.tag==="Node")return Ot("Node",f._1,f._2,f._3,L(f._4._1*4,f._4._2),c(f._5),c(f._6));g()};return c(Wi(H(f=>L(f.id,f.size))(e.nodes)))})()))),u=t.compactPostRouting?tx()(t.compactionSpacings)({nodes:i,edges:e.edges,paths:o,ports:r}):{nodes:i,edges:o},s=H(c=>{const f=Ai(Pi(c.segments));return{...c,segments:f,bends:be(d=>l=>d.end,f,kt(1,f.length,f))}})(u.edges),a=Ft(c=>f=>({...f,jumps:Bx(c)(f)(s)}))(s);return{nodes:u.nodes,edges:a,boundingBox:uN(u.nodes),metrics:Lm(u.nodes)(a)(0)}},aN=t=>e=>n=>{const r=Wi(H(o=>L(o.id,o.size))(e.nodes)),i={...n,placements:f2({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(Wi(H(o=>L(o.id,o.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(Sf(n.ordered)(n.withDummies.edges)((()=>{const o=u=>{if(u.tag==="Leaf")return D;if(u.tag==="Node")return Ot("Node",u._1,u._2,u._3,L(u._4._1*4,u._4._2),o(u._5),o(u._6));g()};return o(r)})()))};return{pipeline:i,result:sN(t)(e)(i)}},cN=t=>e=>n=>aN(t)(e)({...n,ordered:v2({iterations:t.iterations,constraints:e.constraints,modelOrder:Wi(Ft(r=>i=>L(i.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),gN=t=>e=>n=>cN(t)(e)({...n,withDummies:Mx(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),fN=t=>e=>{const n=H(i=>i.id)(e.nodes),r=I2(t.cycleBreaker)(n)(e.constraints)(e.edges);return gN(t)(e)({acyclic:r,layered:Z2(t.layerer)(e.constraints)(r.edges)(n),withDummies:iN,ordered:[],placements:[]})},ou=t=>t,_N=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},kr=ou("TopSide"),Er=ou("BottomSide"),Sr=ou("LeftSide"),Cr=ou("RightSide"),dN=t=>{const e=rt.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=rt.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Zf=t=>e=>n=>{const r=_N(t.h*.12)(t.w*.2),i=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*Ce(dN((()=>{const o=(n-(t.x+i))/i;return 1-o*o})()))},We=t=>e=>n=>r=>{let i=t,o=e,u=n,s=r,a=!0,c;for(;a;){const f=i,d=o,l=u,_=s;if(f==="Rectangle"){if(l==="TopSide"){a=!1,c=d.y;continue}if(l==="BottomSide"){a=!1,c=d.y+d.h;continue}if(l==="LeftSide"){a=!1,c=d.x;continue}if(l==="RightSide"){a=!1,c=d.x+d.w;continue}i=er,o=d,u=l,s=_;continue}if(f==="Cylinder"){if(l==="TopSide"){a=!1,c=Zf(d)(-1)(_);continue}if(l==="BottomSide"){a=!1,c=Zf(d)(1)(_);continue}if(l==="LeftSide"){a=!1,c=d.x;continue}if(l==="RightSide"){a=!1,c=d.x+d.w;continue}}i=er,o=d,u=l,s=_}return c},t_=t=>e=>{const n=e.y-t.y,r=n<0?-n:n,i=e.x-(t.x+t.w),o=i<0?-i:i,u=e.x-t.x,s=u<0?-u:u,a=e.y-(t.y+t.h),c=a<0?-a:a;return r<=c&&r<=s&&r<=o?kr:c<=s&&c<=o?Er:s<=o?Sr:Cr},lN=(()=>{const t=Ue.unfoldr(Jn);return e=>t(Ke("IterNode",e,Nn))})(),oa=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Ri=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},qi=te(G)(Bt),hN=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},pN=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},mN=w(t=>e=>Z(G)(e)()(t))(D),yN=w(t=>e=>Z(G)(e)()(t))(D),uu=lr.traverse(Du),su=te(G)(Bt),xN=t=>e=>Ge(G.compare,Se,t,e),NN=w(t=>e=>Z(G)(e)()(t))(D),JN=te(G)(Bt),wN=t=>e=>Ge(G.compare,Se,t,e),TN=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},e_=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},vN=t=>e=>({...e,edges:qi(H(n=>L(n._1,(()=>{const r=oa(n._1)(t);if(r.tag==="Nothing")return n._2;if(r.tag==="Just"){const i=Ri(r._1._2)(e.nodes),o=Ri(r._1._1)(e.nodes),u=(()=>{if(o.tag==="Nothing")return n._2;if(o.tag==="Just"){const s=Mt(a=>J,a=>c=>T("Just",{head:a,tail:c}),n._2);if(s.tag==="Nothing")return n._2;if(s.tag==="Just")return[(()=>{const a=Mt(l=>J,l=>_=>T("Just",{head:l,tail:_}),s._1.tail),c=a.tag==="Just"?T("Just",a._1.head):J,f={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},d=(()=>{if(c.tag==="Just"){if((c._1.x>s._1.head.x?c._1.x-s._1.head.x<.5:s._1.head.x-c._1.x<.5)&&s._1.head.x>=f.x-.5&&s._1.head.x<=f.x+f.w+.5)return c._1.y>=f.y+f.h?T("Just",Er):c._1.y<=f.y?T("Just",kr):J;if((c._1.y>s._1.head.y?c._1.y-s._1.head.y<.5:s._1.head.y-c._1.y<.5)&&s._1.head.y>=f.y-.5&&s._1.head.y<=f.y+f.h+.5){if(c._1.x>=f.x+f.w)return T("Just",Cr);if(c._1.x<=f.x)return T("Just",Sr)}return J}if(c.tag==="Nothing")return J;g()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...s._1.head,y:We(o._1.shape)(f)(kr)(s._1.head.x)};if(d._1==="BottomSide")return{...s._1.head,y:We(o._1.shape)(f)(Er)(s._1.head.x)};if(d._1==="LeftSide")return{...s._1.head,x:We(o._1.shape)(f)(Sr)(s._1.head.y)};if(d._1==="RightSide")return{...s._1.head,x:We(o._1.shape)(f)(Cr)(s._1.head.y)};g()}if(d.tag==="Nothing"){const l={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},_=t_(l)(s._1.head);if(_==="TopSide")return{...s._1.head,y:We(o._1.shape)(l)(kr)(s._1.head.x)};if(_==="BottomSide")return{...s._1.head,y:We(o._1.shape)(l)(Er)(s._1.head.x)};if(_==="LeftSide")return{...s._1.head,x:We(o._1.shape)(l)(Sr)(s._1.head.y)};if(_==="RightSide")return{...s._1.head,x:We(o._1.shape)(l)(Cr)(s._1.head.y)}}g()})(),...s._1.tail]}g()})();if(i.tag==="Nothing")return u;if(i.tag==="Just"){const s=pr(u);if(s.tag==="Nothing")return u;if(s.tag==="Just")return Dt(s._1.init)((()=>{const a=pr(s._1.init),c=a.tag==="Just"?T("Just",a._1.last):J,f={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},d=(()=>{if(c.tag==="Just"){if((c._1.x>s._1.last.x?c._1.x-s._1.last.x<.5:s._1.last.x-c._1.x<.5)&&s._1.last.x>=f.x-.5&&s._1.last.x<=f.x+f.w+.5)return c._1.y>=f.y+f.h?T("Just",Er):c._1.y<=f.y?T("Just",kr):J;if((c._1.y>s._1.last.y?c._1.y-s._1.last.y<.5:s._1.last.y-c._1.y<.5)&&s._1.last.y>=f.y-.5&&s._1.last.y<=f.y+f.h+.5){if(c._1.x>=f.x+f.w)return T("Just",Cr);if(c._1.x<=f.x)return T("Just",Sr)}return J}if(c.tag==="Nothing")return J;g()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...s._1.last,y:We(i._1.shape)(f)(kr)(s._1.last.x)};if(d._1==="BottomSide")return{...s._1.last,y:We(i._1.shape)(f)(Er)(s._1.last.x)};if(d._1==="LeftSide")return{...s._1.last,x:We(i._1.shape)(f)(Sr)(s._1.last.y)};if(d._1==="RightSide")return{...s._1.last,x:We(i._1.shape)(f)(Cr)(s._1.last.y)};g()}if(d.tag==="Nothing"){const l={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},_=t_(l)(s._1.last);if(_==="TopSide")return{...s._1.last,y:We(i._1.shape)(l)(kr)(s._1.last.x)};if(_==="BottomSide")return{...s._1.last,y:We(i._1.shape)(l)(Er)(s._1.last.x)};if(_==="LeftSide")return{...s._1.last,x:We(i._1.shape)(l)(Sr)(s._1.last.y)};if(_==="RightSide")return{...s._1.last,x:We(i._1.shape)(l)(Cr)(s._1.last.y)}}g()})())}}g()})()))(lN(e.edges)))}),bN=t=>e=>n=>{const r=Vt(i=>i.id===n)(t.graph.edges);if(r.tag==="Just")return T("Just",r._1);if(r.tag==="Nothing")return oa(n)(e);g()},LN=t=>e=>n=>r=>({x:r.position._1*t,y:r.position._2*t,w:r.size._1*t,h:r.size._2*t,label:(()=>{const i=Ri(r.node)(e);if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return r.node;g()})(),shape:(()=>{const i=Ri(r.node)(n);if(i.tag==="Nothing")return er;if(i.tag==="Just")return i._1;g()})()}),kN=t=>({id:t,size:L(1,1),ports:[],label:T("Just",t),shape:er}),EN=t=>e=>n=>r=>L(r.node,LN(t)(e)(n)(r)),n_=t=>{const e=Lo(`
|
|
6
|
-
`)(t);return e.length===0?[""]:e},r_=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Xt("Cons",n._4,e(n._6,r)));g()};return At(Kt.foldr,e(t.interiors,Ut))},SN=t=>qi(xt(e=>T("Just",L(e.edge,{id:e.edge,from:{node:e.from,port:J},to:{node:e.to,port:J},label:J})))(Tt(t.scenes)(e=>e.tag==="DataFlow"?xt(n=>n.kind.tag==="SendToken"?T("Just",n.kind._1):J)(e._1.events):[]))),i_=t=>{const e=Jh(t),n=ut(i=>hN(i.id)(e.nodes),t.graph.nodes),r=ut(i=>pN(i.id)(e.edges),t.graph.edges);return{nodes:[...n,...H(kN)(At($e.foldr,In(G.compare,e.nodes,mN(H(i=>i.id)(n)))))],edges:[...r,...xt(bN(t)(SN(t)))(At($e.foldr,In(G.compare,e.edges,yN(H(i=>i.id)(r)))))],constraints:t.graph.constraints}},CN=t=>{const e=uu(n=>{const r=Dg(Fg)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})());return()=>{const i=r();return L(n.id,i)}})(i_(t).nodes);return()=>{const n=e();return su(n)}},o_=t=>{const e=CN(t);return()=>{const n=e(),r=uu(o_)(r_(t))();return w(xN)(n)(r)}},GN=t=>e=>{const n=Mt(r=>J,r=>i=>T("Just",{head:r,tail:i}),e.segments);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{x:n._1.head.start._1*t,y:n._1.head.start._2*t},...H(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];g()},PN=t=>e=>L(e.edge,GN(t)(e)),AN=t=>e=>n=>r=>({nodes:su(H(EN(et(4)*t)(e)(n))(r.nodes)),edges:qi(H(PN(t))(r.edges)),chipExtras:D,edgeLabels:D}),IN=t=>e=>({...vN(qi(H(n=>L(n.id,L(n.from.node,n.to.node)))(e.edges)))(AN(8)(su(H(n=>L(n.id,(()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})()))(e.nodes)))(su(H(n=>L(n.id,n.shape))(e.nodes)))(fN(oN)(e).result)),edgeLabels:qi(xt(n=>n.label.tag==="Just"?T("Just",L(n.id,n.label._1)):J)(e.edges))}),QN=t=>w(e=>n=>{if(n.tag==="Structural")return e;if(n.tag==="DataFlow")return w(r=>i=>{if(i.kind.tag==="SendToken")return w(o=>u=>Z(G)(u)()(o))(r)(i.kind._1.labels);if(i.kind.tag==="FillNodeWithoutTransition")return w(o=>u=>Z(G)(u)()(o))(r)(i.kind._1.labels);g()})(e)(n._1.events);if(n.tag==="Hold"||n.tag==="EnterNode"||n.tag==="ExitNode")return e;g()})(D)(t.scenes),DN=t=>{const e=uu(n=>{const r=Dg(Fg)(n);return()=>{const i=r();return L(n,{labelW:i,charCount:tr(Yr(n)),lineCount:1})}})(At($e.foldr,NN(Tt(At($e.foldr,QN(t)))(n_))));return()=>{const n=e();return JN(n)}},u_=t=>{const e=DN(t);return()=>{const n=e(),r=uu(u_)(r_(t))();return w(wN)(n)(r)}},FN=et(4)*8,zN=t=>Tt(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[];g()}),BN=t=>e=>n=>{const r=i=>{const o=xt(u=>{const s=TN(u)(t);return s.tag==="Just"?T("Just",{w:s._1.labelW+28,h:et(pm(1)(s._1.lineCount))*13.2+12}):J})(Tt(i)(n_));return o.length===0?J:T("Just",{w:w(e_)(0)(H(u=>u.w)(o)),h:w(e_)(0)(H(u=>u.h)(o))})};return w(i=>o=>{if(o.kind.tag==="SendToken"){const u=oa(o.kind._1.edge)(n.edges),s=r(o.kind._1.labels);if(s.tag==="Just"&&u.tag==="Just"){const a=s._1;return bt(G)(ne)(o.kind._1.edge)(H(c=>({x:c.x+14+a.w,y:c.y-6-8-a.h}))(u._1))(i)}return i}if(o.kind.tag==="FillNodeWithoutTransition"){const u=Ri(o.kind._1.node)(n.nodes),s=r(o.kind._1.labels);return s.tag==="Just"&&u.tag==="Just"?bt(G)(ne)("__fill__:"+o.kind._1.node)((()=>{const a=u._1.y-s._1.h-14,c=u._1.x+u._1.w/2,f=c-s._1.w/2,d=c+s._1.w/2,l=u._1.y-14;return[{x:f,y:a},{x:d,y:a},{x:f,y:l},{x:d,y:l}]})())(i):i}g()})(D)(zN(e))},s_=t=>e=>n=>({layout:(()=>{const r=IN()(Tm(FN)(t)(wm(Jm)(i_(n))));return{...r,chipExtras:BN(e)(n)(r)}})(),interiors:(()=>{const r=s_(t)(e),i=o=>{if(o.tag==="Leaf")return D;if(o.tag==="Node")return Ot("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));g()};return i(n.interiors)})()}),a_=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},ua=t=>e=>n=>{const r=t<.05?t:.05,i=(u,s)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return i((()=>{const a=a_(s._3)(n),c=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return{x:s._4.x,y:s._4.y,vx:0,vy:0};g()})(),f=c.vx+(180*(s._4.x-c.x)-22*c.vx)*r,d=c.vy+(180*(s._4.y-c.y)-22*c.vy)*r;return Z(G)(s._3)({x:c.x+f*r,y:c.y+d*r,vx:f,vy:d})(i(u,s._5))})(),s._6);g()},o=i(D,e);return{springs:o,applied:(()=>{const u=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return u((()=>{const c=u(s,a._5),f=a_(a._3)(o);if(f.tag==="Just")return Z(G)(a._3)({...a._4,x:f._1.x,y:f._1.y})(c);if(f.tag==="Nothing")return Z(G)(a._3)(a._4)(c);g()})(),a._6);g()};return u(D,e)})()}};(function(){var t={},e="Pure",n="Throw",r="Catch",i="Sync",o="Async",u="Bind",s="Bracket",a="Fork",c="Sequential",f="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",y="Finalized",x="Forked";function N(Q,R,Y,O){this.tag=Q,this._1=R,this._2=Y,this._3=O}function v(Q){var R=function(Y,O,X){return new N(Q,Y,O,X)};return R.tag=Q,R}function b(Q){return new N(e,void 0)}function k(Q){try{Q()}catch(R){setTimeout(function(){throw R},0)}}function E(Q,R,Y){try{return R(Y())}catch(O){return Q(O)}}function A(Q,R,Y){try{return R(Y)()}catch(O){return Y(Q(O))(),b}}var $=(function(){var Q=1024,R=0,Y=0,O=new Array(Q),X=!1;function q(){var K;for(X=!0;R!==0;)R--,K=O[Y],O[Y]=void 0,Y=(Y+1)%Q,K();X=!1}return{isDraining:function(){return X},enqueue:function(K){var j;R===Q&&(j=X,q(),X=j),O[(Y+R)%Q]=K,R++,X||q()}}})();function tt(Q){var R={},Y=0,O=0;return{register:function(X){var q=Y++;X.onComplete({rethrow:!0,handler:function(K){return function(){O--,delete R[q]}}})(),R[q]=X,O++},isEmpty:function(){return O===0},killAll:function(X,q){return function(){if(O===0)return q();var K=0,j={};function ot(gt){j[gt]=R[gt].kill(X,function(yt){return function(){delete j[gt],K--,Q.isLeft(yt)&&Q.fromLeft(yt)&&setTimeout(function(){throw Q.fromLeft(yt)},0),K===0&&q()}})()}for(var _t in R)R.hasOwnProperty(_t)&&(K++,ot(_t));return R={},Y=0,O=0,function(gt){return new N(i,function(){for(var yt in j)j.hasOwnProperty(yt)&&j[yt]()})}}}}}var S=0,C=1,V=2,U=3,M=4,W=5,B=6;function P(Q,R,Y){var O=0,X=S,q=Y,K=null,j=null,ot=null,_t=null,gt=null,yt=0,Ct=0,Rt=null,pt=!0;function qt(st){for(var dt,at,ct;;)switch(dt=null,at=null,ct=null,X){case V:X=C;try{q=ot(q),_t===null?ot=null:(ot=_t._1,_t=_t._2)}catch(Jt){X=W,K=Q.left(Jt),q=null}break;case U:Q.isLeft(q)?(X=W,K=q,q=null):ot===null?X=W:(X=V,q=Q.fromRight(q));break;case C:switch(q.tag){case u:ot&&(_t=new N(_,ot,_t)),ot=q._2,X=C,q=q._1;break;case e:ot===null?(X=W,q=Q.right(q._1)):(X=V,q=q._1);break;case i:X=U,q=E(Q.left,Q.right,q._1);break;case o:X=M,q=A(Q.left,q._1,function(Jt){return function(){O===st&&(O++,$.enqueue(function(){O===st+1&&(X=U,q=Jt,qt(O))}))}});return;case n:X=W,K=Q.left(q._1),q=null;break;case r:ot===null?gt=new N(_,q,gt,j):gt=new N(_,q,new N(_,new N(h,ot,_t),gt,j),j),ot=null,_t=null,X=C,q=q._1;break;case s:yt++,ot===null?gt=new N(_,q,gt,j):gt=new N(_,q,new N(_,new N(h,ot,_t),gt,j),j),ot=null,_t=null,X=C,q=q._1;break;case a:X=U,dt=P(Q,R,q._2),R&&R.register(dt),q._1&&dt.run(),q=Q.right(dt);break;case c:X=C,q=F(Q,R,q._1);break}break;case W:if(ot=null,_t=null,gt===null)X=B,q=j||K||q;else switch(dt=gt._3,ct=gt._1,gt=gt._2,ct.tag){case r:j&&j!==dt&&yt===0?X=W:K&&(X=C,q=ct._2(Q.fromLeft(K)),K=null);break;case h:j&&j!==dt&&yt===0||K?X=W:(ot=ct._1,_t=ct._2,X=V,q=Q.fromRight(q));break;case s:yt--,K===null&&(at=Q.fromRight(q),gt=new N(_,new N(p,ct._2,at),gt,dt),(j===dt||yt>0)&&(X=C,q=ct._3(at)));break;case p:gt=new N(_,new N(y,q,K),gt,j),X=C,j&&j!==dt&&yt===0?q=ct._1.killed(Q.fromLeft(j))(ct._2):K?q=ct._1.failed(Q.fromLeft(K))(ct._2):q=ct._1.completed(Q.fromRight(q))(ct._2),K=null,yt++;break;case m:yt++,gt=new N(_,new N(y,q,K),gt,j),X=C,q=ct._1;break;case y:yt--,X=W,q=ct._1,K=ct._2;break}break;case B:for(var Nt in Rt)Rt.hasOwnProperty(Nt)&&(pt=pt&&Rt[Nt].rethrow,k(Rt[Nt].handler(q)));Rt=null,j&&K?setTimeout(function(){throw Q.fromLeft(K)},0):Q.isLeft(q)&&pt&&setTimeout(function(){if(pt)throw Q.fromLeft(q)},0);return;case S:X=C;break;case M:return}}function wt(st){return function(){if(X===B)return pt=pt&&st.rethrow,st.handler(q)(),function(){};var dt=Ct++;return Rt=Rt||{},Rt[dt]=st,function(){Rt!==null&&delete Rt[dt]}}}function mt(st,dt){return function(){if(X===B)return dt(Q.right(void 0))(),function(){};var at=wt({rethrow:!1,handler:function(){return dt(Q.right(void 0))}})();switch(X){case S:j=Q.left(st),X=B,q=j,qt(O);break;case M:j===null&&(j=Q.left(st)),yt===0&&(X===M&&(gt=new N(_,new N(m,q(st)),gt,j)),X=W,q=null,K=null,qt(++O));break;default:j===null&&(j=Q.left(st)),yt===0&&(X=W,q=null,K=null)}return at}}function ft(st){return function(){var dt=wt({rethrow:!1,handler:st})();return X===S&&qt(O),dt}}return{kill:mt,join:ft,onComplete:wt,isSuspended:function(){return X===S},run:function(){X===S&&($.isDraining()?qt(O):$.enqueue(function(){qt(O)}))}}}function I(Q,R,Y,O){var X=0,q={},K=0,j={},ot=new Error("[ParAff] Early exit"),_t=null,gt=t;function yt(wt,mt,ft){var st=mt,dt=null,at=null,ct=0,Nt={},Jt,Lt;t:for(;;)switch(Jt=null,st.tag){case x:if(st._3===t&&(Jt=q[st._1],Nt[ct++]=Jt.kill(wt,function(Ht){return function(){ct--,ct===0&&ft(Ht)()}})),dt===null)break t;st=dt._2,at===null?dt=null:(dt=at._1,at=at._2);break;case f:st=st._2;break;case d:case l:dt&&(at=new N(_,dt,at)),dt=st,st=st._1;break}if(ct===0)ft(Q.right(void 0))();else for(Lt=0,Jt=ct;Lt<Jt;Lt++)Nt[Lt]=Nt[Lt]();return Nt}function Ct(wt,mt,ft){var st,dt,at,ct,Nt,Jt;for(Q.isLeft(wt)?(st=wt,dt=null):(dt=wt,st=null);;){if(at=null,ct=null,Nt=null,Jt=null,_t!==null)return;if(mt===null){O(st||dt)();return}if(mt._3!==t)return;switch(mt.tag){case f:st===null?(mt._3=Q.right(mt._1(Q.fromRight(dt))),dt=mt._3):mt._3=st;break;case d:if(at=mt._1._3,ct=mt._2._3,st){if(mt._3=st,Nt=!0,Jt=K++,j[Jt]=yt(ot,st===at?mt._2:mt._1,function(){return function(){delete j[Jt],Nt?Nt=!1:ft===null?Ct(st,null,null):Ct(st,ft._1,ft._2)}}),Nt){Nt=!1;return}}else{if(at===t||ct===t)return;dt=Q.right(Q.fromRight(at)(Q.fromRight(ct))),mt._3=dt}break;case l:if(at=mt._1._3,ct=mt._2._3,at===t&&Q.isLeft(ct)||ct===t&&Q.isLeft(at))return;if(at!==t&&Q.isLeft(at)&&ct!==t&&Q.isLeft(ct))st=dt===at?ct:at,dt=null,mt._3=st;else if(mt._3=dt,Nt=!0,Jt=K++,j[Jt]=yt(ot,dt===at?mt._2:mt._1,function(){return function(){delete j[Jt],Nt?Nt=!1:ft===null?Ct(dt,null,null):Ct(dt,ft._1,ft._2)}}),Nt){Nt=!1;return}break}ft===null?mt=null:(mt=ft._1,ft=ft._2)}}function Rt(wt){return function(mt){return function(){delete q[wt._1],wt._3=mt,Ct(mt,wt._2._1,wt._2._2)}}}function pt(){var wt=C,mt=Y,ft=null,st=null,dt,at;t:for(;;)switch(dt=null,at=null,wt){case C:switch(mt.tag){case f:ft&&(st=new N(_,ft,st)),ft=new N(f,mt._1,t,t),mt=mt._2;break;case d:ft&&(st=new N(_,ft,st)),ft=new N(d,t,mt._2,t),mt=mt._1;break;case l:ft&&(st=new N(_,ft,st)),ft=new N(l,t,mt._2,t),mt=mt._1;break;default:at=X++,wt=W,dt=mt,mt=new N(x,at,new N(_,ft,st),t),dt=P(Q,R,dt),dt.onComplete({rethrow:!1,handler:Rt(mt)})(),q[at]=dt,R&&R.register(dt)}break;case W:if(ft===null)break t;ft._1===t?(ft._1=mt,wt=C,mt=ft._2,ft._2=t):(ft._2=mt,mt=ft,st===null?ft=null:(ft=st._1,st=st._2))}for(gt=mt,at=0;at<X;at++)q[at].run()}function qt(wt,mt){_t=Q.left(wt);var ft;for(var st in j)if(j.hasOwnProperty(st)){ft=j[st];for(st in ft)ft.hasOwnProperty(st)&&ft[st]()}j=null;var dt=yt(wt,gt,mt);return function(at){return new N(o,function(ct){return function(){for(var Nt in dt)dt.hasOwnProperty(Nt)&&dt[Nt]();return b}})}}return pt(),function(wt){return new N(o,function(mt){return function(){return qt(wt,mt)}})}}function F(Q,R,Y){return new N(o,function(O){return function(){return I(Q,R,Y,O)}})}return N.EMPTY=t,N.Pure=v(e),N.Throw=v(n),N.Catch=v(r),N.Sync=v(i),N.Async=v(o),N.Bind=v(u),N.Bracket=v(s),N.Fork=v(a),N.Seq=v(c),N.ParMap=v(f),N.ParApply=v(d),N.ParAlt=v(l),N.Fiber=P,N.Supervisor=tt,N.Scheduler=$,N.nonCanceler=b,N})();let c_=null;function MN(){return c_||(typeof document>"u"?null:c_=document.createElement("canvas").getContext("2d"))}const sa=new Map;function g_(t,e,n,r,i,o){const u=`${n} ${e}px ${t}`,s=u+"|"+r;if(sa.has(s))return sa.get(s);const a=MN();if(!a)return o;a.font=u;const c=i(a.measureText(r)),f=typeof document<"u"?document.fonts:null;if(!f||f.check(u))sa.set(s,c);else if(f&&f.load)try{f.load(u)}catch{}return c}const WN=(t,e,n,r)=>g_(t,e,n,r,i=>i.width,-1),RN=(t,e,n,r)=>g_(t,e,n,r,i=>({ascent:i.actualBoundingBoxAscent,descent:i.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),f_=t=>e=>{const n=WN(t.family,t.size,t.weight,Yr(e));return n<0?et(So(e).length)*t.size*.62:n},__=t=>e=>{const n=RN(t.family,t.size,t.weight,Yr(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},d_=t=>t,l_=t=>t,au=t=>t,h_=t=>t,qN=t=>t,p_=t=>t,m_=t=>t,HN=m_("BaselineTop"),cr=m_("BaselineMiddle"),aa=p_("AlignLeft"),ri=p_("AlignCenter"),Le=qN("RoundJoin"),mn=h_("ButtCap"),kn=h_("RoundCap"),ON=au("LayerPolyOut"),$N=au("LayerPolyIn"),XN=au("LayerNodeMask"),YN=au("LayerOverlay"),cu=l_("NonZero"),VN=l_("EvenOdd"),y_=d_("Normal"),gu=d_("Difference"),oe={r:255,g:255,b:255,a:255},Rn={r:26,g:26,b:26,a:255},ca=t=>e=>Math.imul(t,e),ii=t=>{const e=t+1831565813|0,n=ca(e^e>>>15)(e|1),r=n^(n+ca(n^n>>>7)(n|61)|0),i=r^r>>>14;return{prng:i,value:i<0?(et(i)+4294967296)/4294967296:et(i)/4294967296}},he=t=>e=>n=>{const r=ii(n);return{prng:r.prng,value:t+r.value*(e-t)}},ga=t=>e=>w(n=>r=>ca(n^r)(-2048144789))(e)(H(ir)(Jr(t))),UN=t=>t,x_=t=>t,KN=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},un=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},N_=t=>e=>n=>{const r=nt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=nt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},fa=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},jN=t=>e=>n=>{const r=rt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=rt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},ZN=x_("FlatLevel"),tJ=x_("NestedLevel"),J_=UN("GenieSilhouette"),eJ=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const i=ii(t);return{prng:i.prng,yLift:i.value*n.yJitter*r}},nJ=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const i=ii(t);return{prng:i.prng,dx:(i.value*2-1)*n.xJitter*r}},w_=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,i=Ce(r*r+n*n),o=(t.r*t.r-e.r*e.r+i*i)/(2*i),u=Ce(KN(0)(t.r*t.r-o*o)),s=t.cx+o*r/i,a=t.cy+o*n/i,c={x:s-u*n/i,y:a+u*r/i},f={x:s+u*n/i,y:a-u*r/i};return i===0||i>t.r+e.r?{x:(t.cx+e.cx)/2,y:t.cy}:c.y<f.y?c:f},rJ=t=>e=>{const n=un(e)(un(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]},iJ=t=>e=>n=>r=>i=>o=>{if(e)return{prng:t,r:i};if(n)return{prng:t,r:i*(1+o.rJitter)};if(r)return{prng:t,r:i*o.smallScale};const u=ii(t);return{prng:u.prng,r:i*(1+u.value*o.rJitter)}},T_=t=>{const e=un(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]},oJ=t=>e=>n=>{const r=ii(t),i=e.length;return i===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const o=N_(0)(i-1|0)(xe(xn(r.value*et(n))));return o>=0&&o<e.length?e[o]:-1})()}},uJ=t=>e=>{const n=ii(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const i=N_(0)(r-1|0)(xe(xn(n.value*et(r))));return i>=0&&i<e.length?e[i]:-1})()}},v_=t=>{const e=un(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]},b_=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],L_={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},sJ=t=>{const e=un(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,i=t.x+n;return[1,t.x,r,4,t.x,r+.5522847498*e,i-.5522847498*n,r+e,i,r+e,4,i+.5522847498*n,r+e,t.x+t.w,r+.5522847498*e,t.x+t.w,r]},k_=t=>{const e=un(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+t.h+5,i=t.y+e,o=r-e,u=t.x+n;return[1,t.x,i,4,t.x,i-.5522847498*e,u-.5522847498*n,t.y,u,t.y,4,u+.5522847498*n,t.y,t.x+t.w,i-.5522847498*e,t.x+t.w,i,2,t.x+t.w,o,4,t.x+t.w,o+.5522847498*e,u+.5522847498*n,r,u,r,4,u-.5522847498*n,r,t.x,o+.5522847498*e,t.x,o,5]},E_=t=>e=>{const n=e.y+e.h,r=Hd(t.rBase*e.h)(e.w/(2*(1+(et(t.minN)-1)*t.stepRatio))),i=e.w-2*r,o=2*r*t.stepRatio,u=fa(t.minN)(i<=0||o<=0?t.minN:xe(xr(i/o))+1|0),s=u>=3?zt(1,u-2|0):[],a=s.length,c=An(a+1|0,2),f=c<1?[]:kt(0,c,s),d=uJ(t.seed)((()=>{const m=a-c|0;return m<1?s:kt(m,s.length,s)})()),l=d.idx,_=oJ(d.prng)(ut(m=>m!==l,f))(fa(1)(f.length-(He(Dr)(l)(f)?1:0)|0)),h=_.idx,p=u>=2?i/(et(u)-1):0;return w(m=>y=>{const x=y===h,N=y===l,v=y===0||y===(u-1|0),b=iJ(m.prng)(v)(N)(x)(r)(t),k=eJ(b.prng)(v)(t)(e.h),E=nJ(k.prng)(v)(t)(p);return{prng:E.prng,circles:Dt(m.circles)({cx:e.x+jN(b.r)(e.w-b.r)((u>=2?r+et(y)/(et(u)-1)*i+E.dx:r+0*i+E.dx)+(N?t.heroShift*p:x?-1*t.smallShift*p:0)),cy:n-k.yLift,r:b.r})}})({prng:_.prng,circles:[]})(zt(0,u-1|0)).circles},S_=t=>e=>{const n=t.length;return Ft(r=>i=>({c:i,p1:(()=>{if(r===0)return{x:i.cx-i.r,y:e};const o=r-1|0;return o>=0&&o<t.length?w_(t[o])(i):{x:i.cx-i.r,y:e}})(),p2:(()=>{if(r===(n-1|0))return{x:i.cx+i.r,y:e};const o=r+1|0;return o>=0&&o<t.length?w_(i)(t[o]):{x:i.cx+i.r,y:e}})()}))(t)},C_=t=>{const e=un(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]},aJ=t=>e=>n=>{const r=yr(e.y-t.cy)(e.x-t.cx),i=yr(n.y-t.cy)(n.x-t.cx),o=i>r?i-r:i+6.283185307179586-r,u=fa(1)(xe(no(o/1.5707963267948966))),s=o/et(u),a=1.3333333333333333*Od(s/4);return Tt(zt(0,u-1|0))(c=>{const f=r+et(c+1|0)*s,d=t.cx+t.r*rn(f),l=t.cy+t.r*Ve(f),_=r+et(c)*s;return[4,t.cx+t.r*rn(_)-a*t.r*Ve(_),t.cy+t.r*Ve(_)+a*t.r*rn(_),d+a*t.r*Ve(f),l-a*t.r*rn(f),d,l]})},G_=t=>e=>{const n=t.h*.38,r=S_(E_(L_)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),i=un(e)(un(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...Tt(r)(o=>aJ(o.c)(o.p1)(o.p2)),2,t.x+t.w,t.y+t.h-i,3,t.x+t.w,t.y+t.h,t.x+t.w-i,t.y+t.h,2,t.x+i,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-i,2,r[0].p1.x,r[0].p1.y,5]:rJ(t)(e)},_a=t=>e=>n=>r=>i=>o=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(i)(o);if(e==="Cylinder"){const u=k_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Parallelogram"){const u=v_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Diamond"){const u=C_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Ellipse"){const u=T_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Document"){const u=b_(n);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Cloud"){const u=G_(n)(r);if(i.tag==="Just"){if(o.tag==="Just")return t.fillStrokePath(u)(i._1)(o._1);if(o.tag==="Nothing")return t.fillPath(u)(i._1);g()}if(i.tag==="Nothing"){if(o.tag==="Just")return t.strokePath(u)(o._1);if(o.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}return t.drawRoundedRect(n)(r)(i)(o)},cJ=t=>()=>t.clip("evenodd"),gJ=t=>e=>()=>{t.filter=`blur(${e}px)`},fJ=t=>e=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(e.tile,.001))),r=Math.max(2,Math.round(e.tile*n)),i=document.createElement("canvas");i.width=r,i.height=r;const o=i.getContext("2d");o.scale(n,n),o.fillStyle=e.bgCss,o.fillRect(0,0,e.tile,e.tile),o.fillStyle=e.dotCss,o.beginPath(),o.arc(e.tile/2,e.tile/2,e.dotR,0,2*Math.PI),o.fill();const u=t.createPattern(i,"repeat");u&&typeof u.setTransform=="function"&&u.setTransform(new DOMMatrix().translateSelf(e.ox,e.oy).scaleSelf(1/n,1/n)),t.save(),t.fillStyle=u,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},da=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},la=t=>e=>n=>{const r=e.stroke;return()=>{const i=r.value,o=pl(t)(n);if(i!==n)return o(),e.stroke.value=n}},_J=t=>e=>n=>{const r=e.font;return()=>{const i=r.value,o=bl(t)(n);if(i!==n)return o(),e.font.value=n}},Hi=t=>e=>n=>{const r=e.fill;return()=>{const i=r.value,o=hl(t)(n);if(i!==n)return o(),e.fill.value=n}},fu=t=>e=>{const n=e.length,r=o=>{if(o>=n)return()=>{};const u=o>=0&&o<e.length?e[o]:0;if(u===1){const s=Nc(t)((()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===2){const s=mi(t)((()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===3){const s=yi(t)({cpx:(()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})(),cpy:(()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=o+3|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=o+4|0;return c>=0&&c<e.length?e[c]:0})()}),a=r(o+5|0);return()=>(s(),a())}if(u===4){const s=kl(t)({cp1x:(()=>{const c=o+1|0;return c>=0&&c<e.length?e[c]:0})(),cp1y:(()=>{const c=o+2|0;return c>=0&&c<e.length?e[c]:0})(),cp2x:(()=>{const c=o+3|0;return c>=0&&c<e.length?e[c]:0})(),cp2y:(()=>{const c=o+4|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=o+5|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=o+6|0;return c>=0&&c<e.length?e[c]:0})()}),a=r(o+7|0);return()=>(s(),a())}if(u===5){const s=Jc(t),a=r(o+1|0);return()=>(s(),a())}return()=>{}},i=xc(t);return()=>(i(),r(0)())},dJ=t=>e=>n=>r=>i=>o=>{const u=da(o)(da(r/2)(i/2)),s=Nc(t)(e+u)(n);return()=>(s(),mi(t)(e+r-u)(n)(),yi(t)({cpx:e+r,cpy:n,x:e+r,y:n+u})(),mi(t)(e+r)(n+i-u)(),yi(t)({cpx:e+r,cpy:n+i,x:e+r-u,y:n+i})(),mi(t)(e+u)(n+i)(),yi(t)({cpx:e,cpy:n+i,x:e,y:n+i-u})(),mi(t)(e)(n+u)(),yi(t)({cpx:e,cpy:n,x:e+u,y:n})(),Jc(t)())},lJ=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),hJ=t=>e=>{const n=Jl(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=lJ();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0},groupAlpha:{value:1},alphaSaves:{value:[]}}}},pJ={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},mJ=t=>ue(t.weight)+" "+dr(t.size)+"px "+t.family,En=t=>{const e=dr(et(t.a)/255);return t.a>=255?"rgb("+ue(t.r)+","+ue(t.g)+","+ue(t.b)+")":"rgba("+ue(t.r)+","+ue(t.g)+","+ue(t.b)+","+e+")"},yJ=t=>e=>n=>r=>{const i=Hi(t)(n)(En(r));return()=>(i(),Nl(t)({x:0,y:0,width:e.width,height:e.height})())},xJ=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",fJ(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:En(n.bgColor),dotCss:En(n.dotColor),tile:n.tile,dotR:n.dotRadius,ox:n.origin.x,oy:n.origin.y})())},NJ=t=>e=>n=>r=>{const i=Hi(t)(e)(En(r));return()=>(i(),fu(t)(n)(),Xu(t)())},JJ=t=>e=>n=>r=>i=>{const o=Hi(t)(e)(En(r));return()=>(o(),la(t)(e)(En(i.color))(),qu(t)(i.width)(),co(t)((()=>{if(i.lineJoin==="RoundJoin")return ao;if(i.lineJoin==="BevelJoin")return ju;if(i.lineJoin==="MiterJoin")return Zu;g()})())(),rs(t)((()=>{if(i.lineCap==="ButtCap")return ns;if(i.lineCap==="RoundCap")return ts;if(i.lineCap==="SquareCap")return es;g()})())(),fu(t)(n)(),Xu(t)(),$u(t)())},wJ=t=>e=>n=>r=>i=>o=>{const u=xc(t);return()=>{if(u(),dJ(t)(n.x)(n.y)(n.w)(n.h)(r)(),i.tag==="Just"?(Hi(t)(e)(En(i._1.color))(),Xu(t)()):i.tag==="Nothing"||g(),o.tag==="Just")return la(t)(e)(En(o._1.color))(),qu(t)(o._1.width)(),co(t)((()=>{if(o._1.lineJoin==="RoundJoin")return ao;if(o._1.lineJoin==="BevelJoin")return ju;if(o._1.lineJoin==="MiterJoin")return Zu;g()})())(),rs(t)((()=>{if(o._1.lineCap==="ButtCap")return ns;if(o._1.lineCap==="RoundCap")return ts;if(o._1.lineCap==="SquareCap")return es;g()})())(),$u(t)();o.tag!=="Nothing"&&g()}},TJ=t=>e=>n=>r=>{const i=la(t)(e)(En(r.color));return()=>(i(),qu(t)(r.width)(),co(t)((()=>{if(r.lineJoin==="RoundJoin")return ao;if(r.lineJoin==="BevelJoin")return ju;if(r.lineJoin==="MiterJoin")return Zu;g()})())(),rs(t)((()=>{if(r.lineCap==="ButtCap")return ns;if(r.lineCap==="RoundCap")return ts;if(r.lineCap==="SquareCap")return es;g()})())(),fu(t)(n)(),$u(t)())},P_=t=>e=>n=>{const r=Hi(t)(e)(En(n.color));return()=>(r(),_J(t)(e)(mJ(n.font))(),zl(t)((()=>{if(n.align==="AlignLeft")return Pl;if(n.align==="AlignCenter")return Il;if(n.align==="AlignRight")return Al;g()})())(),Fl(t)((()=>{if(n.baseline==="BaselineTop")return El;if(n.baseline==="BaselineMiddle")return Sl;if(n.baseline==="BaselineAlphabetic")return Cl;if(n.baseline==="BaselineBottom")return Gl;g()})())(),Ll(t)(n.content)(n.x)(n.y)())},A_={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>pJ},vJ={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>A_},bJ=t=>e=>n=>{const r=da(e.width/n.vw)(e.height/n.vh),i=Yu(t)({translateX:(e.width-n.vw*r)/2-n.vx*r,translateY:(e.height-n.vh*r)/2-n.vy*r});return()=>(i(),uo(t)({scaleX:r,scaleY:r})(),co(t)(ao)())},LJ={pure:t=>e=>()=>t,Apply0:()=>A_},kJ={Applicative0:()=>LJ,Bind1:()=>vJ},I_={fillPath:t=>e=>n=>{const r=NJ(n.ctx)(n.styleCache)(t)(e.color),i=n.maskDepth;return()=>{if(i.value===0)return r()}},strokePath:t=>e=>n=>{const r=TJ(n.ctx)(n.styleCache)(t)(e),i=n.maskDepth;return()=>{if(i.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const i=JJ(r.ctx)(r.styleCache)(t)(e.color)(n),o=r.maskDepth;return()=>{if(o.value===0)return i()}},drawRoundedRect:t=>e=>n=>r=>i=>{const o=wJ(i.ctx)(i.styleCache)(t)(e)(n)(r),u=i.maskDepth;return()=>{if(u.value===0)return o()}},drawText:t=>e=>{const n=P_(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=jn(n.ctx),i=n.maskDepth;return()=>{if(i.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",wl(n.ctx)(t)(),P_(n.ctx)(n.styleCache)(e)(),Zn(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=jn(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Yu(e.ctx)({translateX:t.tx,translateY:t.ty})(),uo(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=Zn(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=jn(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Yu(e.ctx)({translateX:t.tx,translateY:t.ty})(),uo(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=Zn(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=jn(n.ctx),i=n.maskDepth;return()=>{if(i.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",fu(n.ctx)(t)(),e==="NonZero")return xl(n.ctx)();if(e==="EvenOdd")return cJ(n.ctx)();g()}}},popClip:t=>{const e=Zn(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=jn(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 Tc(e.ctx)(Ql)();if(t==="Difference")return Tc(e.ctx)(Dl)();g()}}},popBlend:t=>{const e=Zn(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=jn(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="";const i=e.groupAlpha.value,o=e.alphaSaves.value;e.alphaSaves.value=[...o,i];const u=i*t;return e.groupAlpha.value=u,yl(e.ctx)(u)()}}},popAlpha:t=>{const e=Zn(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,i=pr(r);if(i.tag==="Just")return t.alphaSaves.value=i._1.init,t.groupAlpha.value=i._1.last;if(i.tag==="Nothing")return t.groupAlpha.value=1;g()}}},pushBlur:t=>e=>{const n=jn(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="";const i=gJ(e.ctx)(t);if(t>=.01)return i()}}},popBlur:t=>{const e=Zn(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=bJ(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=yJ(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=xJ(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=f_(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=__(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>J_,Monad0:()=>kJ},EJ=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},oi=t=>e=>n=>{const r=EJ(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},Q_=t=>{const e=rt.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=rt.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},_u=t=>{if(t.tag==="Hidden")return{alpha:0,scale:0};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:t._1>0?1:0,scale:bi(8)(.6)(Q_(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:bi(8)(.6)(Q_(1-t._1))};g()};function SJ(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function CJ(t){const e=t.length,n=new Array(e);for(let r=0;r<e;r++){const i=t[r],o=t[(r+1)%e];n[r]={a:i,b:o,len:SJ(i,o)}}return n}function GJ(t,e,n){let r=0;for(let i=0;i<t.length;i++){const o=t[i],u=r,s=u+o.len;if(n<=s){const a=o.len>1e-6?(n-u)/o.len:0;return{x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a}}r=s}return e.length>0?e[e.length-1]:{x:0,y:0}}function D_(t,e){if(e.length===0)return[];const n=CJ(e);let r=0;for(let o=0;o<n.length;o++)r+=n[o].len;const i=new Array(t);for(let o=0;o<t;o++)i[o]=GJ(n,e,o*r/t);return i}function PJ(t,e){const n=e.length;if(n===0)return e;const r=(t%n+n)%n|0,i=new Array(n);for(let o=0;o<n;o++)i[o]=e[(o+r)%n];return i}function AJ(t,e){const n=e.length;if(n===0)return e;let r=0,i=1/0;for(let o=0;o<n;o++){let u=0;for(let s=0;s<n;s++){const a=t[s]||{x:0,y:0},c=e[(s+o)%n]||{x:0,y:0},f=a.x-c.x,d=a.y-c.y;u+=f*f+d*d}u<i&&(i=u,r=o)}return PJ(r,e)}const F_=t=>e=>n=>{const r=D_(t,e),i=D_(t,n),o=AJ(r,i);return{from:r,to:o}};function z_(t){const e=t.length;if(e===0)return{x:0,y:0};let n=0,r=0;for(let i=0;i<e;i++)n+=t[i].x,r+=t[i].y;return{x:n/e,y:r/e}}function IJ(t,e){const n=e.x-t.x,r=e.y-t.y,i=Math.sqrt(n*n+r*r);return i<=1e-4?{x:1,y:0}:{x:n/i,y:r/i}}function QJ(t,e){const n=e.length;if(n===0)return e;const r=new Array(n);for(let i=0;i<n;i++){const o=e[((i-1)%n+n)%n],u=e[((i+1)%n+n)%n],s=e[i];r[i]={x:s.x+((o.x+u.x)/2-s.x)*t,y:s.y+((o.y+u.y)/2-s.y)*t}}return r}function DJ(t){return t<0?0:t>1?1:t}const B_=t=>e=>n=>r=>{const i=e.length;if(i===0)return[];const o=z_(e),u=z_(n),s=IJ(o,u),a=new Array(i);let c=1/0,f=-1/0;for(let _=0;_<i;_++){const h=e[_],p=(h.x-o.x)*s.x+(h.y-o.y)*s.y;a[_]=p,p<c&&(c=p),p>f&&(f=p)}const d=f-c;let l=new Array(i);for(let _=0;_<i;_++){const h=e[_],p=n[_];if(p===void 0){l[_]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(a[_]-c)/d),y=Math.max(1e-4,1-m),x=DJ((t-m)/y),N=x*x*(3-2*x);l[_]={x:h.x+(p.x-h.x)*N,y:h.y+(p.y-h.y)*N}}for(let _=0;_<r.smoothPasses;_++)l=QJ(.5,l);return l},Sn=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},M_=w(Mr)(0),W_=t=>e=>n=>{const r=rt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=rt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},FJ=w(t=>e=>t+e.len)(0),ha=t=>{const e=Mt(n=>J,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,...Tt(kt(1,t.length,t))(n=>[2,n.x,n.y]),5];g()},zJ=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]},BJ=t=>{const e=Mt(n=>J,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,...Tt(e._1.tail)(n=>[2,n.x,n.y])];g()},MJ=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return k_(e);if(t.shape==="Parallelogram")return v_(e);if(t.shape==="Diamond")return C_(e);if(t.shape==="Ellipse")return T_(e);if(t.shape==="Document")return b_(e);if(t.shape==="Cloud")return G_(e)(7);if(t.shape==="Rectangle")return zJ(e)(7);g()},pe=t=>e=>n=>H(r=>{const i=et(r)/et(n);return{x:t.x+(e.x-t.x)*i,y:t.y+(e.y-t.y)*i}})(zt(0,n-1|0)),WJ=t=>{const e=un(t.w*.18)(t.h*.6);return[...pe({x:t.x+e,y:t.y})({x:t.x+t.w,y:t.y})(16),...pe({x:t.x+t.w,y:t.y})({x:t.x+t.w-e,y:t.y+t.h})(16),...pe({x:t.x+t.w-e,y:t.y+t.h})({x:t.x,y:t.y+t.h})(16),...pe({x:t.x,y:t.y+t.h})({x:t.x+e,y:t.y})(16)]},ui=t=>e=>{const n=Sn(t)(Sn(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}},pa=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return Ce(r*r+n*n)},RJ=t=>be(e=>n=>({a:e,b:n,len:pa(e)(n)}),t,kt(1,t.length,t)),qJ=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?T("Just",e[n]):J,i=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];g()})(),o=0<e.length?T("Just",e[0]):J,u=(()=>{if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return{x:0,y:0};g()})(),s=e.length;return s<3?e:[u,...Tt(zt(1,s-2|0))(a=>{const c=a+1|0,f=c>=0&&c<e.length?T("Just",e[c]):J,d=a>=0&&a<e.length?T("Just",e[a]):J,l=a-1|0,_=l>=0&&l<e.length?T("Just",e[l]):J;if(_.tag==="Just"&&d.tag==="Just"&&f.tag==="Just"){const h=d._1,p=pa(h)(f._1),m=pa(_._1)(h),y=Sn(t)(p/2),x=Sn(t)(m/2),N=p>0?y/p:0,v=h.x+(f._1.x-h.x)*N,b=h.y+(f._1.y-h.y)*N,k=m>0?x/m:0,E=h.x+(_._1.x-h.x)*k,A=h.y+(_._1.y-h.y)*k;return H($=>{const tt=et($)/et(10),S=1-tt;return{x:S*S*E+2*S*tt*h.x+tt*tt*v,y:S*S*A+2*S*tt*h.y+tt*tt*b}})(zt(0,10))}return[]}),...i]},HJ=t=>e=>n=>r=>i=>H(o=>{const u=et(o)/et(i),s=1-u,a=u*u*u,c=3*s*u*u,f=3*s*s*u,d=s*s*s;return{x:d*t.x+f*e.x+c*n.x+a*r.x,y:d*t.y+f*e.y+c*n.y+a*r.y}})(zt(0,i-1|0)),OJ=t=>[...pe({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...pe({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...HJ({x:t.x+t.w,y:t.y+t.h*.85})({x:t.x+t.w*.66,y:t.y+t.h*1.05})({x:t.x+t.w*.34,y:t.y+t.h*.65})({x:t.x,y:t.y+t.h*.85})(32),...pe({x:t.x,y:t.y+t.h*.85})({x:t.x,y:t.y})(12)],R_=t=>e=>H(n=>{const r=6.283185307179586*et(n)/et(64);return{x:t.x+e*rn(r),y:t.y+e*Ve(r)}})(zt(0,63)),du=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]},$J=t=>{const e=t.y+t.h/2,n=un(t.h*.4)(t.w*.2);return[...pe({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...pe({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...pe({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...pe({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...pe({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...pe({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},q_=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:M_(H(n=>n.x)(t))/et(e),y:M_(H(n=>n.y)(t))/et(e)}},lu=t=>e=>n=>r=>i=>H(o=>{const u=n+(r-n)*(et(o)/et(i));return{x:t.x+e*rn(u),y:t.y+e*Ve(u)}})(zt(0,i-1|0)),H_=t=>e=>{const n=Sn(t)(Sn(e.w/2)(e.h/2));return[...pe({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...lu({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...pe({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...lu({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...pe({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...lu({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...pe({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...lu({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},hu=t=>e=>n=>r=>i=>o=>H(u=>{const s=r+(i-r)*(et(u)/et(o));return{x:t.x+e*rn(s),y:t.y+n*Ve(s)}})(zt(0,o-1|0)),XJ=t=>{const e=t.h*.38;return[...Tt(S_(E_(L_)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=yr(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),i=yr(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return hu({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(i)(r>i?r:r+6.283185307179586)(16)}),...pe({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...pe({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...pe({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},YJ=t=>{const e=Sn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,i=t.y+t.h+5-e-2,o=t.x+n;return[...hu({x:o,y:r})(n)(e)(3.141592653589793)(6.283185307179586)(24),...pe({x:t.x+t.w,y:r})({x:t.x+t.w,y:i})(12),...hu({x:o,y:i})(n)(e)(0)(3.141592653589793)(24),...pe({x:t.x,y:i})({x:t.x,y:r})(12)]},Gr=t=>e=>e.shape==="Cylinder"?YJ(e):e.shape==="Parallelogram"?WJ(e):e.shape==="Diamond"?$J(e):e.shape==="Ellipse"?H_(un(e.w)(e.h)/2)(e):e.shape==="Document"?OJ(e):e.shape==="Cloud"?XJ(e):H_(t)(e),VJ=t=>{const e=Sn(t.h*.075)(t.w*.075),n=t.w/2;return hu({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},UJ=t=>e=>n=>w(r=>i=>{const o=r.pos+i.len,u=n<o?(n-r.pos)/i.len:1,s={x:i.a.x+(i.b.x-i.a.x)*u,y:i.a.y+(i.b.y-i.a.y)*u},a=e>r.pos?(e-r.pos)/i.len:0,c={x:i.a.x+(i.b.x-i.a.x)*a,y:i.a.y+(i.b.y-i.a.y)*a},f=r.points.length-1|0,d=f>=0&&f<r.points.length?(()=>{const l=r.points[f].x-c.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const _=r.points[f].y-c.y;return _<0?-_<1e-4:_<1e-4})()})()?Dt(r.points)(s):[...r.points,c,s]:[c,s];return i.len<=0||o<=e||r.pos>=n?{...r,pos:o}:{pos:o,points:d}})({pos:0,points:[]})(t).points,KJ=t=>e=>n=>{const r=Mt(i=>J,i=>o=>T("Just",{head:i,tail:o}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const i=RJ(t),o=FJ(i),u=W_(0)(o)(e*o),s=W_(0)(o)(n*o);return s<=u?[]:UJ(i)(u)(s)}g()},jJ=t=>e=>n=>r=>{const i=r.x-n.x,o=r.y-n.y,u=e.x-t.x,s=e.y-t.y,a=n.x-t.x,c=n.y-t.y,f=u*o-s*i,d=(a*o-c*i)/f,l=(a*s-c*u)/f;return(f<0?-f<1e-9:f<1e-9)?J:d>=0&&d<=1&&l>=0&&l<=1?T("Just",d):J},ZJ=t=>e=>n=>{const r=Et(i=>o=>rt.compare(i.t)(o.t))(xt(i=>{const o=jJ(e)(n)(i._1)(i._2);return o.tag==="Just"?T("Just",{t:o._1,p:{x:e.x+(n.x-e.x)*o._1,y:e.y+(n.y-e.y)*o._1}}):J})(be(ln,t,[...kt(1,t.length,t),...kt(0,1,t)])));return 0<r.length?T("Just",r[0].p):J},O_=t=>e=>{const n=pr(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 i=ZJ(t)(n._1.init[r])(n._1.last);if(i.tag==="Just")return Dt(n._1.init)(i._1);if(i.tag==="Nothing")return e;g()}return e}g()},gr=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ma=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},tw=t=>e=>n=>{const r=rt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=rt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},ew=t=>e=>{const n=gr(0)(t.y+4-e.y)+gr(0)(e.y+e.h-(t.y+t.h-4)),r=gr(0)(t.x+4-e.x)+gr(0)(e.x+e.w-(t.x+t.w-4));return r*e.h+n*e.w+r*n},nw=t=>e=>{const n=t.y+t.h-6,r=t.y+6,i=t.x+14,o=t.x+t.w-14,u=w(gr)(0)(H(s=>i-10<s.x+s.w+12&&o+10>s.x-12&&r-10<s.y+s.h+12&&n+10>s.y-12?ma((s.x+s.w+12-(i-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+u*.7071067811865476,y:t.y-u*.7071067811865476}},rw=t=>e=>{const n=ma(t.x+t.w)(e.x+e.w)-gr(t.x)(e.x),r=ma(t.y+t.h)(e.y+e.h)-gr(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},$_=t=>e=>n=>r=>{const i=t+4,o=gr(0)(e-8),u=i+o-n;return n<=o?tw(i)(u)(r):t+(e-n)/2},X_=t=>e=>({...e,x:$_(t.x)(t.w)(e.w)(e.x),y:$_(t.y)(t.h)(e.h)(e.y)}),iw=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,i=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:i},{...t.rect,x:e,y:i},{...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:i}]},ow=t=>e=>n=>r=>i=>{const o=i.y+i.h/2-n.token.y,u=i.y-r.y;return(()=>{const s=i.x+i.w/2-n.token.x,a=i.x-r.x;return 1e6*ew(t)(i)+1e4*w(c=>f=>c+rw(i)(f))(0)(e)+.05*(a*a+u*u)+.01*(s*s+o*o)})()+(i.y>n.token.y?100:0)},uw=t=>e=>n=>r=>{const i=u=>{const s=X_(t)(u);return{rect:s,score:ow(t)(e)(n)(r)(s)}},o=Mt(u=>J,u=>s=>T("Just",{head:u,tail:s}),[r,n.rect,...iw(n)]);if(o.tag==="Nothing")return X_(t)(r);if(o.tag==="Just")return w(u=>s=>{const a=i(s);return a.score<u.score?a:u})(i(o._1.head))(o._1.tail).rect;g()},sw=t=>e=>n=>w(r=>i=>{const o=nw(i.rect)(r.obstacles),u=o.x>=t.x+4&&o.y>=t.y+4&&o.x+o.w<=t.x+t.w-4&&o.y+o.h<=t.y+t.h-4?o:uw(t)(r.obstacles)(i)(o);return{acc:Z(G)(i.id)(u)(r.acc),obstacles:Dt(r.obstacles)(u)}})({acc:D,obstacles:e})(n).acc,ya=t=>t,qn=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Pr=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},aw=oc(ic)(Bt),cw=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},gw=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Y_=ya("SegMove"),fw=ya("SegLine"),_w=ya("SegQuad"),V_={offset:.4,passes:1,rMax:1.5},U_=t=>xe(xn(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,pu=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},mu=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},Hn=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},Oi=(()=>{const t=w(e=>n=>((e*31|0)+xe(xn(n.x*100))|0)+xe(xn(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),dw=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const i=n,o=r,u=i>=0&&i<t.length?T("Just",t[i]):J;if(u.tag==="Nothing"){n=t.length;continue}if(u.tag==="Just"){if(u._1===1){const s={x:(()=>{const a=i+1|0;return a>=0&&a<t.length?t[a]:0})(),y:(()=>{const a=i+2|0;return a>=0&&a<t.length?t[a]:0})()};e.push({kind:Y_,m:o,c:o,p:s,len:0}),r=s,n=i+3|0;continue}if(u._1===2){const s={x:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()},a=s.x-o.x,c=s.y-o.y;e.push({kind:fw,m:o,c:o,p:s,len:Ce(a*a+c*c)}),r=s,n=i+3|0;continue}if(u._1===3){const s={x:(()=>{const f=i+3|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+4|0;return f>=0&&f<t.length?t[f]:0})()},a=s.x-o.x,c=s.y-o.y;e.push({kind:_w,m:o,c:{x:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()},p:s,len:Ce(a*a+c*c)*1.05}),r=s,n=i+5|0;continue}if(u._1===5){e.push({kind:Y_,m:o,c:o,p:o,len:0}),n=i+1|0;continue}n=t.length;continue}g()}return e},lw=t=>e=>{const n=e.length-1|0,r=n<1?[]:kt(0,n,e),i=(()=>{const u=r.length-1|0;return u>=0&&u<r.length?T("Just",r[u]):J})(),o=e.length-1|0;if(o>=0&&o<e.length&&i.tag==="Just"){const u=e[o].y-i._1.y,s=e[o].x-i._1.x,a=Ce(s*s+u*u);return a<=1e-4?e:Dt((()=>{const c=e.length-1|0;return c<1?[]:kt(0,c,e)})())({x:e[o].x+s/a*t,y:e[o].y+u/a*t})}return e},hw=t=>e=>n=>ve(w(r=>i=>{const o=he(0)(t)(r.prng),u=he(0)(6.283185307179586)(o.prng);return{prng:u.prng,out:[{x:i.x+o.value*rn(u.value),y:i.y+o.value*Ve(u.value)},...r.out]}})({prng:e,out:[]})(n).out),pw=t=>e=>n=>{if(e.kind==="SegMove")return mu(t)(e.p);if(e.kind==="SegLine")return Hn(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 Hn(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});g()},mw=t=>e=>{if(e.kind==="SegMove")return mu(t)(e.p);if(e.kind==="SegLine")return Hn(t)(e.p);if(e.kind==="SegQuad")return pu(t)(e.c)(e.p);g()},K_=t=>e=>{const n=dw(e),r=w(s=>a=>s+a.len)(0)(n)*qn(0)(Pr(1)(t)),i=[];let o=0,u=0;for(;u<n.length;){const s=u,a=o;if(s>=0&&s<n.length){if(a+n[s].len<=r){const c=n[s];mw(i)(c)(),o=a+c.len,u=s+1|0;continue}if(a>=r){u=n.length;continue}pw(i)(n[s])((r-a)/qn(n[s].len)(1e-4))()}u=n.length}return i},j_={offset:1.5,passes:2,rMax:14,overshoot:2.5},Z_=t=>e=>n=>r=>{const i=r.y-n.y,o=n.y-e.y,u=r.x-n.x,s=Ce(u*u+i*i),a=n.x-e.x,c=Ce(a*a+o*o),f=Pr(t.rMax*(qd(c>0&&s>0?qn(-1)(Pr(1)((a*u+o*i)/(c*s))):1)/3.141592653589793))(.4*Pr(c)(s));return{inP:c>0?{x:n.x-a/c*f,y:n.y-o/c*f}:n,curr:n,outP:s>0?{x:n.x+u/s*f,y:n.y+i/s*f}:n}},t1=t=>e=>{const n=e.length,r=[],i=0<e.length?T("Just",e[0]):J;if(i.tag==="Just"?mu(r)(i._1)():i.tag==="Nothing"||g(),n>=3){let u=1;for(;u<=(n-2|0);){const s=u,a=s+1|0;if(a>=0&&a<e.length){if(s>=0&&s<e.length){const c=s-1|0;if(c>=0&&c<e.length){const f=Z_(t)(e[c])(e[s])(e[a]);Hn(r)(f.inP)(),pu(r)(f.curr)(f.outP)()}}u=s+1|0;continue}u=s+1|0}}const o=e.length-1|0;return o>=0&&o<e.length&&n>=2&&Hn(r)(e[o])(),r},yw=t=>e=>n=>r=>i=>{if(i.length<4)return t1(t)(i);const o=0<i.length?T("Just",i[0]):J,u=(()=>{if(o.tag==="Nothing")return{x:0,y:0};if(o.tag==="Just")return o._1;g()})(),s=i.length-1|0,a=Kn(Kn(e)(s)+s|0)(s),c=_=>{const h=Kn(_+s|0)(s);return h>=0&&h<i.length?i[h]:u},f=H(_=>Z_(t)(c((a+_|0)-1|0))(c(a+_|0))(c((a+_|0)+1|0)))(zt(0,s-1|0)),d=[],l=0<f.length?T("Just",f[0]):J;if(l.tag==="Just")if(mu(d)(l._1.outP)(),aw((()=>{const _=Mt(h=>J,h=>p=>T("Just",p),f);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})())(_=>{const h=Hn(d)(_.inP);return()=>(h(),pu(d)(_.curr)(_.outP)())})(),n)Hn(d)(l._1.inP)(),pu(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const _=f.length-1|0;_>=0&&_<f.length?Hn(d)((()=>{const h=1-r;return{x:f[_].outP.x+(l._1.inP.x-f[_].outP.x)*h,y:f[_].outP.y+(l._1.inP.y-f[_].outP.y)*h}})())():Hn(d)(l._1.inP)()}else l.tag==="Nothing"||g();return d},si=t=>e=>n=>r=>{const i=cw(1)(r.length-1|0),o=he(0)(et(i))(ga("shape")(e)),u=gw(i-1|0)(xe(xn(o.value))),s=o.prng;return H(a=>{const c=he(0)(1)(ga(ue(a))(s)),f=he(-.18)(.3)(c.prng),d=c.value<.7,l=he(.5)(.85)(f.prng),_=hw(t.offset)(l.prng)(r);return{path:n?yw(t)(u)(d)(f.value)(_):t1(t)(_),alpha:l.value}})(zt(0,t.passes-1|0))},xw=t=>e=>n=>si(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}]),Nw=t=>e=>n=>{const r=qn(0)(Pr(1)(n)),i=e.h/et(4),o=qn(6)(i*1.4);return xt(u=>u)(H(u=>{if(r<qn(0)(et(u)/et(4)-.05))return J;const s=ga(ue(u))(t),a=qn(0)(et(u)/et(4)-.05),c=Kn(u)(2)===0,f=c?e.x-2:e.x+e.w+2,d=c?e.x+e.w+2:e.x-2,l=e.y+(et(u)+.5)*i;return T("Just",{path:K_(qn(0)(Pr(1)((r-a)/qn(1e-4)(Pr(1)(et(u+1|0)/et(4)+.05)-a))))((()=>{const _={rMax:2,offset:.6,passes:1},h=ve(w(m=>y=>{const x=he(-i*.08)(i*.08)(m.prng);return{prng:x.prng,out:[{x:f+(d-f)*(et(y)/et(4)),y:l+x.value},...m.out]}})({prng:s,out:[]})(zt(0,4)).out),p=h.length<2?[]:si(_)(s)(!1)(h);return 0<p.length?p[0].path:[]})()),width:o,alpha:1})})(zt(0,3)))},xa=(t,e,n)=>({tag:t,_1:e,_2:n}),e1=t=>t,Na=(t,e,n)=>({tag:t,_1:e,_2:n}),yu=t=>e=>n=>{const r=rt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=rt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},ae=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Qe=(()=>{const t=Ue.unfoldr(Jn);return e=>t(Ke("IterNode",e,Nn))})(),Cn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Jw=Bt.foldMap(il),xu=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ww=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Nu=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},n1=te(G)(Bt),r1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Tw=pc(G),vw=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Ja=e1("LabelsShown"),bw=e1("LabelsHidden"),i1=t=>{const e=t.Monad0().Bind1(),n=t.popTransform,r=t.popAlpha;return i=>o=>u=>s=>a=>e.bind(t.pushAlpha(i.fadeAlpha))(()=>e.bind(t.pushTransform({tx:o*(1-i.popScale),ty:u*(1-i.popScale),sx:i.popScale,sy:i.popScale}))(()=>e.bind(t.pushTransform({tx:0,ty:s.y*(1-i.flipY),sx:1,sy:i.flipY}))(()=>e.bind(a)(()=>e.bind(n)(()=>e.bind(n)(()=>r))))))},tn=t=>{const e=t.Apply0();return n=>w(r=>i=>e.apply(e.Functor0().map(o=>Ka)(r))(n(i)))(t.pure())},o1=t=>e=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},a=oi(i)(o)(r),c=0<t.length?T("Just",t[0]):J,f=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return s;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?T("Just",t[d]):J,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return u;g()})(),h=F_(128)(Gr(4)(ui(2)(e)))(R_(f)(6)),p=f.x-s.x,m=2*(()=>{const V=f.y-s.y;return(p<0?-p:p)+(V<0?-V:V)})(),y=_.x-u.x,x=2*(()=>{const V=_.y-u.y;return(y<0?-y:y)+(V<0?-V:V)})(),N=m+mo(t)+x,v=N<=1e-4?1:1-x/N,b=N<=1e-4?0:m/N,k=v-b,E=F_(128)(R_(_)(6))(Gr(4)(ui(2)(n))),A={maxDelay:.4,smoothPasses:2},$=wi(t)(yu(0)(1)(k<=1e-4?0:(a-b)/k)),tt=(()=>{if($.tag==="Just")return $._1;if($.tag==="Nothing")return f;g()})(),S=(()=>{if(v>=1)return 0;const V=(a-v)/(1-v),U=V<0?0:V>1?1:V;return U*U*(3-2*U)})(),C=(()=>{if(b<=1e-4)return 1;const V=a/b,U=V<0?0:V>1?1:V;return U*U*(3-2*U)})();return a<b?Na("PolyShape",B_(C)(h.from)(h.to)(A)):a>=v?Na("PolyShape",B_(S)(E.from)(E.to)(A)):Na("CircleShape",tt,6)},wa=t=>e=>n=>r=>i=>o=>{const u=o1(t)(e)(n)(r)(i)(o);if(u.tag==="PolyShape")return q_(u._1);if(u.tag==="CircleShape")return u._1;g()},Ta=(()=>{const t={r:24,g:24,b:27,a:255},e={r:244,g:244,b:245,a:255},n={r:248,g:249,b:246,a:255},r={r:26,g:26,b:26,a:255},i={r:28,g:101,b:192,a:255},o={r:247,g:248,b:250,a:255},u={r:42,g:48,b:60,a:255},s={r:120,g:130,b:146,a:255};return a=>{if(a==="Light")return{bg:{r:255,g:255,b:255,a:255},bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:211,b:209,a:255},shadowFill:{r:255,g:255,b:255,a:255},shadowDot:{r:26,g:26,b:26,a:255},chip:{r:255,g:235,b:130,a:255},chipShadow:{r:214,g:211,b:209,a:255},chipText:Rn,nodeFill:oe,nodeStroke:Rn,text:Rn,edge:Rn,arrowFill:Rn,tokenOutsideFill:Rn,tokenOutsideStroke:oe,tokenInside:oe,tokenInsideStroke:oe,tokenInsideBlend:gu,tokenInsideAlpha:1,chipPillFill:Rn,chipPillText:oe,chipHairline:{r:26,g:26,b:26,a:90},trailDot:Rn,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Dark")return{bg:t,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:63,g:63,b:70,a:255},shadowFill:t,shadowDot:e,chip:{r:234,g:179,b:8,a:255},chipShadow:{r:0,g:0,b:0,a:120},chipText:t,nodeFill:Rn,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:oe,tokenOutsideStroke:oe,tokenInside:oe,tokenInsideStroke:oe,tokenInsideBlend:gu,tokenInsideAlpha:1,chipPillFill:e,chipPillText:t,chipHairline:{r:244,g:244,b:245,a:120},trailDot:e,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Blueprint")return{bg:i,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:90,g:160,b:230,a:255},shadowFill:i,shadowDot:oe,chip:oe,chipShadow:{r:0,g:0,b:0,a:120},chipText:i,nodeFill:i,nodeStroke:oe,text:oe,edge:oe,arrowFill:oe,tokenOutsideFill:oe,tokenOutsideStroke:oe,tokenInside:oe,tokenInsideStroke:oe,tokenInsideBlend:y_,tokenInsideAlpha:.35,chipPillFill:oe,chipPillText:i,chipHairline:{r:255,g:255,b:255,a:120},trailDot:oe,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Whiteboard")return{bg:n,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:0,g:0,b:0,a:0},shadowFill:n,shadowDot:r,chip:{r:217,g:74,b:56,a:255},chipShadow:{r:26,g:26,b:26,a:60},chipText:n,nodeFill:n,nodeStroke:r,text:r,edge:r,arrowFill:r,tokenOutsideFill:r,tokenOutsideStroke:n,tokenInside:n,tokenInsideStroke:n,tokenInsideBlend:y_,tokenInsideAlpha:1,chipPillFill:r,chipPillText:n,chipHairline:{r:26,g:26,b:26,a:90},trailDot:r,wobble:!0,fontFamily:"Supermarker, Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Isometric")return{bg:o,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:218,b:224,a:255},shadowFill:o,shadowDot:u,chip:{r:255,g:235,b:130,a:255},chipShadow:{r:100,g:110,b:125,a:90},chipText:u,nodeFill:{r:236,g:239,b:244,a:255},nodeStroke:u,text:u,edge:s,arrowFill:s,tokenOutsideFill:u,tokenOutsideStroke:oe,tokenInside:oe,tokenInsideStroke:oe,tokenInsideBlend:gu,tokenInsideAlpha:1,chipPillFill:u,chipPillText:oe,chipHairline:{r:60,g:66,b:78,a:90},trailDot:u,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};g()}})(),va=t=>e=>Tt(Qe(t.nodes))(n=>{const r=ae(n._1)(e.nodes);return r.tag==="Just"&&_u(r._1).alpha>0?MJ(n._2):[]}),Lw=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,...va(e)(n)],kw=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=lr.traverse(r);return o=>u=>{const s=Jr(u),a=.32*o.size;return i(c=>n.bind(c===0?r.pure(0):t.measureText(o)(Je(c)(u)))(f=>n.bind(t.measureText(o)(Je(c+1|0)(u)))(d=>n.bind(t.measureInk(o)(c>=0&&c<s.length?go(s[c]):" "))(l=>r.pure({x:f,w:d-f,up:l.ascent-a,down:l.descent+a})))))(zt(0,s.length-1|0))}},Ew=t=>e=>{const n=i=>(i.x-e.x)*(i.x-e.x)+(i.y-e.y)*(i.y-e.y),r=w(i=>o=>n(o)<n(i)?o:i)({x:t.x,y:t.y})([{x:t.x,y:t.y},{x:t.x+t.w,y:t.y},{x:t.x,y:t.y+t.h},{x:t.x+t.w,y:t.y+t.h}]);return H(i=>{const o=et(i)/5;return{x:r.x+(e.x-r.x)*o,y:r.y+(e.y-r.y)*o}})([1,2,3,4])},ba=t=>{const e=Lo(`
|
|
7
|
-
`)(t);return e.length===0?[""]:e},
|
|
8
|
-
`)(N.label===""?x:N.label),A=E.length===0?[""]:E,$=k.size*1.2,tt=N.shape==="Cylinder"?t.strokePath(sJ({x:N.x,y:N.y,w:N.w,h:N.h}))({color:h.nodeStroke,width:1.25,lineJoin:Le,lineCap:mn}):i.pure(),S=(N.shape==="Cylinder"?(N.y+(N.y+N.h+5-2*un(N.h*.075)(N.w*.075)))/2:(N.y+N.y+N.h)/2)-et(A.length)*$/2+$/2,C=v.tag==="PloppingOut"&&h.wobble?v._1:-1,V=C>=0,U=_u(v),M=V?{alpha:1,scale:1}:U,W=N.x+N.w/2,B=N.y+N.h/2,P=n.bind(t.pushAlpha(M.alpha*p))(()=>n.bind(t.pushTransform({tx:W*(1-M.scale),ty:B*(1-M.scale),sx:M.scale,sy:M.scale}))(()=>{const I={x:N.x,y:N.y,w:N.w,h:N.h},F={color:h.nodeStroke,width:h.wobble?2:1.25*_,lineJoin:Le,lineCap:h.wobble?kn:mn};return n.bind((()=>{if(h.wobble){if(N.shape==="Rectangle")return o(b)(xw(j_)(U_(I))(I));const Q=Gr(7)(N);return n.bind(o(b)((()=>{const R=Oi(Q);return Q.length<4?[]:si(V_)(R)(!0)(Q)})()))(()=>s(R=>o(b)((()=>{const Y=Oi(R);return R.length<2?[]:si(V_)(Y)(!1)(R)})()))(N.shape==="Cylinder"?[VJ(N)]:[]))}return n.bind(_a(t)(N.shape)(I)(7)(T("Just",{color:h.nodeFill,flat:!1}))(T("Just",F)))(()=>tt)})())(()=>n.bind((()=>{if(y.tag==="Just"&&h.wobble&&!V){const Q=y._1;return n.bind(a(c(k))(A))(R=>{const Y=Et(at=>ct=>rt.compare(at.x)(ct.x)),O=xe(xn(N.x*7919+N.y*3001))*-1640531535|0,X=he(5)(7.5)(O),q=he(0)(X.value)(X.prng),K=-(1+2*he(-1)(1)(q.prng).value*3.141592653589793/180),j=(at,ct,Nt,Jt,Lt)=>Y(xt(Ht=>Ht)([K*ct+at>=Jt&&K*ct+at<=Lt?T("Just",{x:ct,y:K*ct+at}):J,K*Nt+at>=Jt&&K*Nt+at<=Lt?T("Just",{x:Nt,y:K*Nt+at}):J,(()=>{const Ht=(Jt-at)/K;return Ht>=ct&&Ht<=Nt?T("Just",{x:Ht,y:Jt}):J})(),(()=>{const Ht=(Lt-at)/K;return Ht>=ct&&Ht<=Nt?T("Just",{x:Ht,y:Lt}):J})()])),ot=X.value,_t=Kn(Q.frameHash)(3),gt=_t===0?{r:200,g:35,b:30,a:220}:_t===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},yt=N.x+N.w/2,Ct=Ye(Ft(at=>ct=>Ft((()=>{const Nt=S+et(at)*$,Jt=yt-w(Lt=>Ht=>Lt+Ht.w)(0)(ct)/2;return Lt=>Ht=>{const dn=k.size*.1,Fe=Lt-1|0,Pt=Fe>=0&&Fe<ct.length&&Lt>0?(ct[Fe].x+ct[Fe].w+Ht.x)/2:Ht.x-dn;return{x:Jt+Pt-1,y:Nt-Ht.up-1,w:xu(0)((()=>{const Qt=Lt+1|0;return Qt>=0&&Qt<ct.length&&Lt<(ct.length-1|0)?(Ht.x+Ht.w+ct[Qt].x)/2-Pt:Ht.x+Ht.w+dn-Pt})())+2,h:Ht.up+Ht.down+2}}})())(ct))(R)),Rt=N.y+4,pt=N.x+N.w-4,qt=N.x+4,wt=Rt-K*qt+q.value,mt=N.y+N.h-4,ft=Tt(Tt(Ft(at=>ct=>{const Nt=(ct.from.x+ct.to.x)/2,Jt=(ct.from.y+ct.to.y)/2,Lt=he(-1)(1)(O+(911*(at+1|0)|0)|0),Ht=he(-3)(5)(Lt.prng),dn=Lt.value*3.141592653589793/180,Fe=rn(dn),Pt=Ve(dn),Qt=ze=>({x:Nt+(ze.x-Nt)*Fe-(ze.y-Jt)*Pt,y:Jt+(ze.x-Nt)*Pt+(ze.y-Jt)*Fe});return{from:(()=>{const ze=Qt(ct.from),an=ze.y-Jt,Xe=ze.x-Nt,nn=Ce(Xe*Xe+an*an),Ae=nn<1e-4?1:(nn+Ht.value)/nn;return{x:Nt+Xe*Ae,y:Jt+an*Ae}})(),to:(()=>{const ze=Qt(ct.to),an=he(-3)(5)(Ht.prng).value,Xe=ze.y-Jt,nn=ze.x-Nt,Ae=Ce(nn*nn+Xe*Xe),$t=Ae<1e-4?1:(Ae+an)/Ae;return{x:Nt+nn*$t,y:Jt+Xe*$t}})()}})(xt(at=>{const ct=j(wt+et(at)*ot,qt,pt,Rt,mt);return ct.length===2?T("Just",{from:ct[0],to:ct[1]}):J})(zt(0,Nu(1)(xe(xn((mt-K*pt-wt)/ot)))))))(at=>ut(ct=>ct.to.x-ct.from.x>1,w(ct=>Nt=>Tt(ct)(Jt=>{const Lt=j(Jt.from.y-K*Jt.from.x,Nt.x,Nt.x+Nt.w,Nt.y,Nt.y+Nt.h);return Lt.length===2?Lt[0].x>Jt.from.x+.001&&Lt[1].x<Jt.to.x-.001?[{from:Jt.from,to:Lt[0]},{from:Lt[1],to:Jt.to}]:Lt[0].x<=Jt.from.x+.001&&Lt[1].x<Jt.to.x-.001?[{from:Lt[1],to:Jt.to}]:Lt[0].x>Jt.from.x+.001&&Lt[1].x>=Jt.to.x-.001?[{from:Jt.from,to:Lt[0]}]:[]:[Jt]}))([at])(Ct))))(at=>(()=>{const ct=at.to.x-at.from.x;return Ce(2)*(ct>=0?ct:-ct)<=28})()?[at]:[{from:at.from,to:{x:at.from.x+(at.to.x-at.from.x)*.495,y:at.from.y+(at.to.y-at.from.y)*.495}},{from:{x:at.from.x+(at.to.x-at.from.x)*.505,y:at.from.y+(at.to.y-at.from.y)*.505},to:at.to}]),st=ft.length,dt=at=>xu(0)(ww(1)(Q.t*et(st)-et(at)));return n.bind(t.pushClip(ha(Gr(7)(N)))(cu))(()=>n.bind(o(at=>{const ct=at._1,Nt=he(1.4)(1.9)(O+(1303*(ct+1|0)|0)|0),Jt=he(.35)(.8)(Nt.prng),Lt=o(Ht=>n.bind(t.pushAlpha(Ht.alpha*Jt.value))(()=>n.bind(t.strokePath(K_(dt(ct))(Ht.path))({color:gt,width:Nt.value,lineJoin:Le,lineCap:kn}))(()=>r)))(si({...j_,rMax:0,offset:.5})(O+(53*(ct+1|0)|0)|0)(!1)([at._2.from,at._2.to]));return dt(ct)>0?Lt:i.pure()})(Ft(ln)(ft)))(()=>u))})}return i.pure()})())(()=>n.bind((()=>{if(l==="LabelsShown"){const Q=n.bind(t.pushAlpha(m))(()=>n.bind(o(R=>t.drawText({x:N.x+N.w/2,y:S+et(R._1)*$,content:R._2,font:k,color:h.text,align:ri,baseline:cr}))(Ft(ln)(A)))(()=>r));return m>0?Q:i.pure()}if(l==="LabelsHidden")return i.pure();g()})())(()=>n.bind((()=>{const Q=f(h)(I)(C);return V?Q:i.pure()})())(()=>n.bind(d)(()=>r)))))}));return M.alpha*p>0?P:i.pure()}},a1=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=s1(t),o=t.popAlpha,u=tn(n);return s=>a=>c=>{const f={...s,nodeFill:s.text,text:s.nodeFill,nodeStroke:s.nodeFill};return u(d=>{const l=ae(d._1)(c.nodes),_=ae(d._1)(a.nodes),h=(()=>{if(_.tag==="Just"&&l.tag==="Just"){const p=l._1,m=_._1;return r.bind(t.pushAlpha(d._2))(()=>r.bind(i(Ja)(1)(f)(1)(1)(J)(d._1)(m)(p))(()=>o))}return n.pure()})();return d._2>0?h:n.pure()})(Qe(c.nodeInvert))}},Aw=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=tn(n);return o=>u=>s=>{const a={family:o.fontFamily,size:11,weight:500};return i(c=>{if(c._2===""||(()=>{const l=Cn(c._1)(s.edges);return l.tag==="Nothing"||!(l.tag==="Just"&&l._1.tag==="Extended")})())return n.pure();const f=Cn(c._1)(u.edges),d=(()=>{if(f.tag==="Just")return wi(f._1)(.5);if(f.tag==="Nothing")return J;g()})();if(d.tag==="Nothing")return n.pure();if(d.tag==="Just"){const l=d._1;return r.bind(t.measureText(a)(c._2))(_=>{const h=_+12;return r.bind(t.drawRoundedRect({x:l.x-h/2,y:l.y-8.5,w:h,h:17})(3)(T("Just",{color:o.chipPillFill,flat:!0}))(J))(()=>t.drawText({x:l.x,y:l.y,content:c._2,font:a,color:o.chipPillText,align:ri,baseline:cr}))})}g()})(Qe(u.edgeLabels))}},Iw=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=t.popAlpha;return o=>u=>s=>a=>c=>f=>d=>l=>_=>{const h=(()=>{if(_>1e-4&&d>1-_){const m=(1-d)/_;return m<0?0:m>1?1:m}if(l>1e-4&&d<l){const m=d/l;return m<0?0:m>1?1:m}return 1})(),p=o1(a)(c)(f)(d)(l)(_);if(p.tag==="CircleShape")return o?u1(t)(p._1)(p._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(du(p._1)(p._2))({color:u,flat:!0})({color:s,width:1,lineJoin:Le,lineCap:mn});if(p.tag==="PolyShape"&&o&&p._1.length>=3)return r.bind(t.pushAlpha(h))(()=>r.bind(u1(t)(q_(p._1))(6)({r:200,g:35,b:30,a:220}))(()=>i));if(p.tag==="PolyShape")return o?n.pure():p._1.length>=3?t.fillStrokePath(ha(p._1))({color:u,flat:!0})({color:s,width:1,lineJoin:Le,lineCap:mn}):n.pure();g()}},Qw=t=>{const e=t.Monad0().Bind1(),n=t.popAlpha;return r=>i=>o=>u=>s=>a=>c=>{const f=oi(a)(c)(s),d={x:o.x+o.w/2,y:o.y+o.h/2},l={x:u.x+u.w/2,y:u.y+u.h/2},_=(h,p)=>e.bind(t.pushAlpha(p))(()=>e.bind(t.fillStrokePath(du(h)(6))({color:r,flat:!0})({color:i,width:1,lineJoin:Le,lineCap:mn}))(()=>n));return f<.5?_(d,(()=>{const h=f*2;return 1-(h<0?0:h>1?1:h)*(h<0?0:h>1?1:h)*(h<0?3:h>1?1:3-2*h)})()):_(l,(()=>{const h=(f-.5)*2;return(h<0?0:h>1?1:h)*(h<0?0:h>1?1:h)*(h<0?3:h>1?1:3-2*h)})())}},Ju=t=>{const e=Iw(t),n=Qw(t),r=t.Monad0().Applicative0(),i=tn(r);return o=>u=>s=>a=>c=>i(f=>{if(f._2.tag==="Travelling"){const d=ae(f._2._1.target)(u.nodes),l=ae(f._2._1.source)(u.nodes);if(l.tag==="Just"&&d.tag==="Just"){const _=Cn(f._2._1.edge)(u.edges);if(_.tag==="Just")return e(o)(a)(c)((()=>{if(f._2._1.direction==="Forward")return _._1;if(f._2._1.direction==="Backward")return ve(_._1);g()})())(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);if(_.tag==="Nothing")return n(a)(c)(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);g()}return r.pure()}if(f._2.tag==="Filling"){if(o)return r.pure();const d=ae(f._2._1.node)(u.nodes);if(d.tag==="Just")return t.fillStrokePath(ha(Gr(4)(ui(2)(d._1))))({color:a,flat:!0})({color:c,width:1,lineJoin:Le,lineCap:mn});if(d.tag==="Nothing")return r.pure();g()}return r.pure()})(Qe(s.tokens))},c1=t=>{const e=Ju(t),n=t.Monad0(),r=n.Bind1(),i=Ju(t),o=Gw(t),u=t.popClip,s=t.popBlend,a=t.popLayer,c=n.Applicative0(),f=tn(c),d=t.popAlpha;return l=>_=>h=>p=>{const m=_.wobble?e(!0)(h)(p)(_.tokenInside)(_.tokenInsideStroke):r.bind(t.insideTokenStyle(l))(y=>{if(y==="GenieSilhouette")return i(!1)(h)(p)(_.tokenInside)(_.tokenInsideStroke);if(y==="ConvexAbsorb")return o(h)(p)(_.tokenInside)(_.tokenInsideStroke);g()});if(_.tokenInsideBlend==="Difference")return r.bind(t.pushLayer($N))(()=>r.bind(t.pushBlend(gu))(()=>r.bind(t.pushClip(va(h)(p))(cu))(()=>r.bind(m)(()=>r.bind(u)(()=>r.bind(s)(()=>r.bind(a)(()=>r.bind(t.pushLayer(XN))(()=>r.bind(f(y=>{const x=ae(y._1)(p.nodes);return x.tag==="Just"&&_u(x._1).alpha>0?_a(t)(y._2.shape)({x:y._2.x,y:y._2.y,w:y._2.w,h:y._2.h})(7)(T("Just",{color:oe,flat:!1}))(J):c.pure()})(Qe(h.nodes)))(()=>a)))))))));if(_.tokenInsideBlend==="Normal")return r.bind(t.pushClip(va(h)(p))(cu))(()=>r.bind(t.pushAlpha(_.tokenInsideAlpha))(()=>r.bind(m)(()=>r.bind(d)(()=>u))));g()}},g1=t=>{const e=t.Monad0().Bind1(),n=Ju(t),r=Ju(t),i=t.popClip,o=t.popLayer;return u=>s=>a=>c=>e.bind(t.pushLayer(ON))(()=>e.bind(t.pushClip(Lw(s)(a)(c))(VN))(()=>e.bind(u.wobble?n(!0)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke):r(!1)(a)(c)(u.tokenOutsideFill)(u.tokenOutsideStroke))(()=>e.bind(i)(()=>o))))},Dw=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=tn(r);return o=>u=>s=>a=>c=>f=>{const d=So(f).length,l=et(d+1|0),_=m=>{const y=(s*l-et(m))/1.5,x=y<0?0:y>1?1:y;return x*x*(3-2*x)},h=(m=>{let y=m,x=!0,N;for(;x;){const v=y;if(v>=d){x=!1,N=v;continue}if(_(v)>=1){y=v+1|0;continue}x=!1,N=v}return N})(0),p=h>=d?[]:mr(m=>_(m)>0)(zt(h,d-1|0)).init;return n.bind((()=>{const m=t.drawText({x:a,y:c,content:Je(h)(f),font:o,color:u,align:aa,baseline:cr});return h>0?m:r.pure()})())(()=>i(m=>n.bind(t.measureText(o)(Je(m)(f)))(y=>{const x=_(m);return t.drawText({x:a+y,y:c-(1-x)*10,content:Je(1)(Ni(tr(Je(m)(f)))(f)),font:o,color:{...u,a:xe(xn(x*et(u.a)))},align:aa,baseline:cr})}))(p))}},wu=t=>e=>n=>r=>{const i=H(_=>et(Nu(1)(So(_).length)))(r),o=xu(1)(w(Mr)(0)(i)),u=oi(e)(n)(t),s=u*o,a=Nu(1)(r.length),c=(_=>h=>p=>{let m=_,y=h,x=p,N=!0,v;for(;N;){const b=m,k=y,E=Mt(A=>J,A=>$=>T("Just",{head:A,tail:$}),x);if(E.tag==="Nothing"){N=!1,v=Nu(0)(a-1|0);continue}if(E.tag==="Just"){if(k+E._1.head>=s){N=!1,v=b;continue}m=b+1|0,y=k+E._1.head,x=E._1.tail;continue}g()}return v})(0)(0)(i),f=w(Mr)(0)(c<1?[]:kt(0,c,i)),d=f/o;if(c>=0&&c<i.length){const _=(f+i[c])/o;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(_<=d)return 1;const h=(u-d)/(_-d);return h<0?0:h>1?1:h})()}}const l=(f+1)/o;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(l<=d)return 1;const _=(u-d)/(l-d);return _<0?0:_>1?1:_})()}},f1=t=>{const e=t.Monad0();return n=>r=>i=>e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(wu(r)(0)(0)(H(Gd)(i)).line))(o=>{const u=o+28;return e.Applicative0().pure({x:n.x+n.w/2-u/2,y:n.y-25.2-14,w:u,h:25.2})})},Fw=t=>{const e=t.Monad0(),n=e.Bind1(),r=f1(t),i=e.Applicative0(),o=lr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>n1(xt(c=>c)(a)))(o(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const c=ae(a._2._1.node)(u.nodes);if(c.tag==="Just")return n.bind(r(c._1)(a._2._1.progress)(a._2._1.labels))(f=>i.pure(T("Just",L(a._1,f))));if(c.tag==="Nothing")return i.pure(J);g()}return i.pure(J)})(Qe(s.tokens)))},zw=t=>{const e=t.Monad0();return n=>r=>i=>o=>u=>s=>a=>{const c=wa(n)(r)(i)(o)(u)(s);return e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(wu(o)(u)(s)(Tt(a)(ba)).line))(f=>e.Applicative0().pure({x:c.x+14+f/2-f/2-14,y:c.y-6-8-6.6-6,w:f+28,h:25.2}))}},Bw=t=>{const e=t.Monad0(),n=e.Bind1(),r=zw(t),i=e.Applicative0(),o=lr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>n1(xt(c=>c)(a)))(o(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const c=ae(a._2._1.target)(u.nodes),f=ae(a._2._1.source)(u.nodes),d=Cn(a._2._1.edge)(u.edges);if(d.tag==="Just"&&f.tag==="Just"&&c.tag==="Just"){const l=(()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return ve(d._1);g()})(),_=wa(l)(f._1)(c._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);return n.bind(r(l)(f._1)(c._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(h=>i.pure(T("Just",L(a._1,{id:a._1,rect:h,token:_}))))}}return i.pure(J)})(Qe(s.tokens)))},La=t=>{const e=t.Monad0(),n=e.Bind1(),r=Bw(t),i=Fw(t);return o=>u=>s=>n.bind(r(u)(s))(a=>n.bind(i(u)(s))(c=>e.Applicative0().pure(sw({x:o.vx,y:o.vy,w:o.vw,h:o.vh})([...xt(f=>{const d=ae(f._1)(s.nodes);return d.tag==="Just"&&_u(d._1).alpha>0?T("Just",{x:f._2.x,y:f._2.y,w:f._2.w,h:f._2.h}):J})(Qe(u.nodes)),...(()=>{const f=(d,l)=>{if(d.tag==="Leaf")return l;if(d.tag==="Node")return f(d._5,Xt("Cons",d._4,f(d._6,l)));g()};return At(Kt.foldr,f(c,Ut))})()])(xt(f=>r1(f)(a))((()=>{const f=d=>{if(d.tag==="Leaf")return D;if(d.tag==="Node")return Ot("Node",d._1,d._2,d._3,void 0,f(d._5),f(d._6));g()};return Et(G.compare)(At($e.foldr,f(a)))})())))))},_1=t=>e=>n=>{const r=bi(6)(.55)(yu(0)(1)((1-t)/.06)),i=t>.94,o=i&&n>1e-4,u=bi(6)(.55)(yu(0)(1)(t/.06)),s=t<.06,a=s&&e>1e-4,c=i&&n<=1e-4;return{popScale:a?u:o?r:1,flipY:s&&e<=1e-4?u:c?r:1,fadeAlpha:(()=>{if(a){const f=t/.06;return f<0?.55:f>1?1:.55+.44999999999999996*f}if(o){const f=(1-t)/.06;return f<0?.55:f>1?1:.55+.44999999999999996*f}return 1})()}},Mw=t=>{const e=i1(t),n=t.Monad0().Bind1();return r=>i=>o=>u=>s=>{const a=wu(o)(0)(0)(Tt(u)(ba)),c={x:s.x+s.w/2,y:s.y+s.h/2},f=[1,c.x,s.y+s.h,2,i.x+i.w/2,i.y];return e(_1(o)(0)(0))(s.x)(s.y+s.h)(c)(n.bind(t.drawRoundedRect({x:s.x,y:s.y+1.5,w:s.w,h:s.h})(6)(T("Just",{color:r.chipShadow,flat:!0}))(J))(()=>n.bind(t.drawRoundedRect({x:s.x,y:s.y,w:s.w,h:s.h})(6)(T("Just",{color:r.chip,flat:!0}))(T("Just",{color:r.chipHairline,width:1,lineJoin:Le,lineCap:mn})))(()=>n.bind(t.strokePath(f)({color:r.chipHairline,width:1,lineJoin:Le,lineCap:mn}))(()=>t.drawText({x:c.x,y:c.y,content:a.line,font:{family:r.fontFamily,size:11,weight:500},color:r.chipText,align:ri,baseline:cr})))))}},Ww=t=>{const e=f1(t),n=Mw(t);return r=>i=>o=>u=>s=>t.Monad0().Bind1().bind(e(o)(u)(s))(a=>n(r)(o)(u)(s)(a))},Rw=t=>{const e=i1(t),n=t.Monad0(),r=n.Bind1(),i=tn(n.Applicative0()),o=Dw(t);return u=>s=>a=>c=>f=>d=>l=>_=>h=>{const p=wu(f)(d)(l)(Tt(_)(ba)),m=p.line,y=p.phaseInLabel/.45,x=y<0?0:y>1?1:y,N=h.w,v=h.y,b=h.x,k=b+14,E=h.h,A=v+E/2;return e(_1(f)(d)(l))(b)(v+E)({x:b+N/2,y:A})(r.bind(i($=>t.fillPath(du($)(1.5))({color:u.trailDot,flat:!0}))(Ew(h)(wa(s)(a)(c)(f)(d)(l))))(()=>r.bind(t.drawRoundedRect({x:b,y:v,w:N,h:E})(3)(T("Just",{color:u.chipPillFill,flat:!0}))(J))(()=>o({family:u.fontFamily,size:11,weight:500})(u.chipPillText)(x)(k)(A)(m))))}},ka=t=>{const e=Rw(t),n=t.Monad0(),r=n.Applicative0(),i=Ww(t),o=n.Bind1(),u=tn(r),s=t.popLayer;return a=>c=>f=>d=>o.bind(t.pushLayer(YN))(()=>o.bind(u(l=>{if(l._2.tag==="Travelling"){if(l._2._1.labels.length!==0){const _=ae(l._2._1.target)(c.nodes),h=ae(l._2._1.source)(c.nodes),p=Cn(l._2._1.edge)(c.edges),m=r1(l._1)(d);if(m.tag==="Just"&&p.tag==="Just"&&h.tag==="Just"&&_.tag==="Just")return e(a)((()=>{if(l._2._1.direction==="Forward")return p._1;if(l._2._1.direction==="Backward")return ve(p._1);g()})())(h._1)(_._1)(l._2._1.progress)(l._2._1.holdPre)(l._2._1.holdPost)(l._2._1.labels)(m._1)}return r.pure()}if(l._2.tag==="Filling"&&l._2._1.labels.length!==0){const _=ae(l._2._1.node)(c.nodes);if(_.tag==="Just")return i(a)(c)(_._1)(l._2._1.progress)(l._2._1.labels);if(_.tag==="Nothing")return r.pure();g()}return r.pure()})(Qe(f.tokens)))(()=>s))},d1=t=>{const e=La(t),n=ka(t);return r=>i=>o=>u=>t.Monad0().Bind1().bind(e(i)(o)(u))(s=>n(r)(o)(u)(s))},qw=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>i=>{const o=i.length-1|0,u=o<1?[]:kt(0,o,i),s=u.length-1|0,a=s>=0&&s<u.length?T("Just",u[s]):J,c=i.length-1|0,f=c>=0&&c<i.length?T("Just",i[c]):J;if(f.tag==="Just"&&a.tag==="Just"){const d=he(.78)(1.18)(Oi(i)+19|0),l=he(.4)(.62)(d.prng),_=r.wobble?8.75*l.value:4.375,h=he(.4)(.62)(l.prng),p=r.wobble?8.75*h.value:4.375,m=f._1.y-a._1.y,y=f._1.x-a._1.x,x=Ce(y*y+m*m),N=m/x,v=-N,b=y/x,k=f._1.x+b*.875,E=f._1.y+N*.875,A=r.wobble?8.75*d.value:8.75,$=k-b*A,tt=E-N*A,S=$+v*_,C=tt+b*_,V=[1,k,E,2,$+v*4.375,tt+b*4.375,2,$-v*4.375,tt-b*4.375,5],U=$-v*p,M=tt-b*p,W={color:r.arrowFill,width:2,lineJoin:Le,lineCap:kn};return x<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,S,C,2,k,E])(W))(()=>t.strokePath([1,U,M,2,k,E])(W)):t.fillPath(V)({color:r.arrowFill,flat:!0})}return n.pure()}},Hw=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=tn(n),o=t.popAlpha,u=qw(t);return s=>a=>c=>f=>{const d=qJ(8)(c);if(f.hi<=f.lo)return n.pure();const l=KJ(d)(f.lo)(f.hi);if(l.length===0)return n.pure();const _={color:s.edge,width:s.wobble?2:.9375,lineJoin:Le,lineCap:kn},h=s.wobble?he(-10)(4)(Oi(l)).value:0,p=s.wobble?lw(h)(l):l;return r.bind(s.wobble?i(m=>r.bind(t.pushAlpha(m.alpha))(()=>r.bind(t.strokePath(m.path)(_))(()=>o)))((()=>{const m=Oi(l);return p.length<2?[]:si(Cw)(m)(!1)(p)})()):t.strokePath(BJ(l))(_))(()=>{const m=u(s)(p);return f.hi>=.999?m:n.pure()})}},l1=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=Hw(t),o=t.popAlpha,u=tn(n);return s=>a=>c=>{const f=d=>{const l=Vt(_=>d.x>=_._2.x-1&&d.x<=_._2.x+_._2.w+1&&d.y>=_._2.y-1&&d.y<=_._2.y+_._2.h+1)(Qe(a.nodes));return l.tag==="Just"?T("Just",l._1._2):J};return u(d=>{const l=Cn(d._1)(c.edges);if(l.tag==="Just"){const _=l._1,h=Cn(d._1)(c.edgeFadeAlpha),p=(()=>{if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1;g()})(),m=r.bind(t.pushAlpha(p))(()=>r.bind(i(s)(d._1)((()=>{const y=(()=>{if(0<d._2.length){const N=f(d._2[0]);if(N.tag==="Just")return ve(O_(Gr(7)(N._1))(ve(d._2)))}return d._2})(),x=y.length-1|0;if(x>=0&&x<y.length){const N=f(y[x]);if(N.tag==="Just")return O_(Gr(7)(N._1))(y)}return y})())((()=>{if(_.tag==="Retracted")return{lo:0,hi:0};if(_.tag==="Extended")return{lo:0,hi:1};if(_.tag==="Extending")return{lo:0,hi:_._2};if(_.tag==="Retracting"){if(_._1==="FromSource")return{lo:_._2,hi:1};if(_._1==="FromTarget")return{lo:0,hi:1-_._2};if(_._1==="FromBoth")return{lo:_._2/2,hi:1-_._2/2}}g()})()))(()=>o));return p>0?m:n.pure()}if(l.tag==="Nothing")return n.pure();g()})(Qe(a.edges))}},Ow=t=>e=>{const n=o=>{const u=ae(o)(t.nodes);if(u.tag==="Nothing")return!1;if(u.tag==="Just"){const s=u._1;return!qe(a=>0<a._2.length&&a._2[0].x>=s.x&&a._2[0].x<=s.x+s.w&&a._2[0].y>=s.y&&a._2[0].y<=s.y+s.h,Qe(t.edges))}g()},r=w(o=>u=>(o*31|0)+ir(u)|0)(5381)(Jr(e.frameTitle)),i=o=>{const u=ae(o)(t.nodes);if(u.tag==="Nothing")return!1;if(u.tag==="Just"){const s=u._1;return!qe(a=>{const c=a._2.length-1|0;return c>=0&&c<a._2.length&&a._2[c].x>=s.x&&a._2[c].x<=s.x+s.w&&a._2[c].y>=s.y&&a._2[c].y<=s.y+s.h},Qe(t.edges))}g()};return w(o=>u=>{const s=u._2;return Tw(a=>{if(a.tag==="Nothing")return T("Just",s);if(a.tag==="Just")return T("Just",{t:xu(a._1.t)(s.t),angle:s.t>=a._1.t?s.angle:a._1.angle,bigCircle:a._1.bigCircle||s.bigCircle,frameHash:a._1.frameHash});g()})(u._1)(o)})(D)(Tt(Qe(e.tokens))(o=>{if(o._2.tag==="Filling"){const u=o._2._1.node;return[L(u,{t:1,angle:(()=>{const s=xt(a=>(()=>{const c=ae(u)(t.nodes),f=a._2.length-1|0;return f>=0&&f<a._2.length&&c.tag==="Just"&&a._2[f].x>=c._1.x&&a._2[f].x<=c._1.x+c._1.w&&a._2[f].y>=c._1.y&&a._2[f].y<=c._1.y+c._1.h})()?T("Just",a._2):J)(Qe(t.edges));if(0<s.length){const a=s[0].length-1|0,c=a<1?[]:kt(0,a,s[0]),f=c.length-1|0;if(f>=0&&f<c.length){const d=s[0].length-1|0;return d>=0&&d<s[0].length?yr(s[0][d].y-c[f].y)(s[0][d].x-c[f].x):0}s[0].length-1|0}return 0})(),bigCircle:n(u)||i(u),frameHash:r})]}if(o._2.tag==="Travelling"){if(o._2._1.progress>=.75)return[L(o._2._1.target,{t:(o._2._1.progress-.75)/.25,angle:(()=>{const u=Cn(o._2._1.edge)(t.edges);if(u.tag==="Just"){const s=u._1.length-1|0,a=s<1?[]:kt(0,s,u._1),c=a.length-1|0;if(c>=0&&c<a.length){const f=u._1.length-1|0;return f>=0&&f<u._1.length?yr(u._1[f].y-a[c].y)(u._1[f].x-a[c].x):0}return u._1.length-1|0,0}if(u.tag==="Nothing")return 0;g()})(),bigCircle:n(o._2._1.target)||i(o._2._1.target),frameHash:r})];if(o._2._1.progress<.25)return[L(o._2._1.source,{t:o._2._1.progress/.25,angle:(()=>{const u=Cn(o._2._1.edge)(t.edges);if(u.tag==="Just")return 1<u._1.length&&0<u._1.length?yr(u._1[1].y-u._1[0].y)(u._1[1].x-u._1[0].x):0;if(u.tag==="Nothing")return 0;g()})(),bigCircle:n(o._2._1.source)||i(o._2._1.source),frameHash:r})]}return[]}))},$w=t=>w(e=>n=>(e*31|0)+ir(n)|0)(5381)(Jr(t.frameTitle)),h1=t=>{const e=s1(t),n=t.Monad0().Applicative0(),r=tn(n);return i=>o=>u=>s=>a=>{const c=$w(a),f=Ow(s)(a);return r(d=>{const l=ae(d._1)(a.nodes);if(l.tag==="Just")return e(i)(o)(u)((()=>{const _=ae(d._1)(a.nodeFadeAlpha);if(_.tag==="Nothing")return 1;if(_.tag==="Just")return _._1;g()})())((()=>{const _=ae(d._1)(a.nodeLabelFadeAlpha);if(_.tag==="Nothing")return 1;if(_.tag==="Just")return _._1;g()})())((()=>{const _=ae(d._1)(f);return _.tag==="Just"?T("Just",_._1):_.tag==="Nothing"&&vw(d._1)(a.visited)?T("Just",{t:1,angle:0,bigCircle:!1,frameHash:c}):J})())(d._1)(d._2)(l._1);if(l.tag==="Nothing")return n.pure();g()})(Qe(s.nodes))}},Xw=t=>e=>n=>{const r=nt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=nt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},p1=t=>e=>n=>{const r=rt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=rt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},m1=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ea=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Yw=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Vw=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},Uw=t=>e=>{const n=Ve(t.angle),r=rn(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},Kw=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],ai=t=>e=>{const n=r=>Xw(0)(255)(xe(xr(et(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},Pe=t=>e=>n=>r=>({x:(e-n)*rn(t.angle),y:(e+n)*Ve(t.angle)-r}),Ar=t=>{const e=Mt(n=>J,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,...Tt(e._1.tail)(n=>[2,n.x,n.y]),5];g()},jw=t=>e=>n=>r=>i=>{const o=(()=>{if(t==="Forward")return i;if(t==="Backward")return ve(i);g()})();if(0<o.length){const s=wi(o)(p1(0)(1)(oi(n)(r)(e)));if(s.tag==="Nothing")return o[0];if(s.tag==="Just")return s._1;g()}const u=wi(o)(p1(0)(1)(oi(n)(r)(e)));if(u.tag==="Nothing")return{x:0,y:0};if(u.tag==="Just")return u._1;g()},Zw=t=>{const e=Mt(n=>J,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,...Tt(e._1.tail)(n=>[2,n.x,n.y])];g()},tT=t=>{const e=Mt(n=>J,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=w(r=>i=>({minX:m1(r.minX)(i.x),minY:m1(r.minY)(i.y),maxX:Ea(r.maxX)(i.x),maxY:Ea(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{vx:n.minX-40,vy:n.minY-40,vw:n.maxX-n.minX+80,vh:n.maxY-n.minY+80}}g()},eT=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>{const o=i.box,u=i.np,s={color:r.nodeStroke,width:1,lineJoin:Le,lineCap:mn};return e.bind(t.fillStrokePath(Ar([o.ground.d,o.ground.c,o.top.c,o.top.d]))({color:ai(.66)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(Ar([o.ground.b,o.ground.c,o.top.c,o.top.b]))({color:ai(.82)(r.nodeFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(Ar([o.top.a,o.top.b,o.top.c,o.top.d]))({color:ai(1)(r.nodeFill),flat:!0})(s))(()=>t.drawTextAffine(Uw(n)(u.y+u.h))({x:u.x+u.w/2,y:0,content:u.label,font:{family:r.fontFamily,size:11,weight:600},color:r.text,align:ri,baseline:cr}))))}},nT=t=>{const e=t.Monad0().Bind1();return n=>r=>i=>o=>{const u={color:r.tokenOutsideStroke,width:1,lineJoin:Le,lineCap:mn},s=o.x-5.5,a=o.x+5.5,c=o.y-5.5,f=o.y+5.5,d=i+11,l=Pe(n)(s)(c)(d),_=Pe(n)(a)(c)(d),h=Pe(n)(a)(f)(d),p=Pe(n)(s)(f)(d),m=Pe(n)(a)(f)(i),y=Pe(n)(a)(c)(i);return e.bind(t.fillStrokePath(Ar([Pe(n)(s)(f)(i),m,h,p]))({color:ai(.66)(r.tokenOutsideFill),flat:!0})(u))(()=>e.bind(t.fillStrokePath(Ar([y,m,h,_]))({color:ai(.82)(r.tokenOutsideFill),flat:!0})(u))(()=>t.fillStrokePath(Ar([l,_,h,p]))({color:ai(1)(r.tokenOutsideFill),flat:!0})(u)))}},rT=t=>{const e=nT(t);return n=>r=>i=>o=>{if(o.tag==="Travelling"){const u=Yw(o._1.edge)(i.edges);return u.tag==="Just"?T("Just",(()=>{const s=jw(o._1.direction)(o._1.progress)(o._1.holdPre)(o._1.holdPost)(u._1);return{depth:s.x+s.y,draw:e(n)(r)(0)(s)}})()):J}if(o.tag==="Filling"){const u=Vw(o._1.node)(i.nodes);if(u.tag==="Just")return T("Just",(()=>{const s={x:u._1.x+u._1.w/2,y:u._1.y+u._1.h/2};return{depth:s.x+s.y,draw:e(n)(r)(n.boxHeight)(s)}})())}return J}},iT={angle:.5235987755982988,boxHeight:26,transparentBg:!0},oT=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:Pe(t)(e.x)(e.y)(0),b:Pe(t)(r)(e.y)(0),c:Pe(t)(r)(n)(0),d:Pe(t)(e.x)(n)(0)},top:{a:Pe(t)(e.x)(e.y)(t.boxHeight),b:Pe(t)(r)(e.y)(t.boxHeight),c:Pe(t)(r)(n)(t.boxHeight),d:Pe(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},y1=t=>e=>H(n=>({np:n,box:oT(t)(n)}))((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Xt("Cons",r._4,n(r._6,i)));g()};return At(Kt.foldr,n(e.nodes,Ut))})()),uT=t=>e=>[...Tt(y1(t)(e))(Kw),...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Xt("Cons",r._4,n(r._6,i)));g()};return Tt(At(Kt.foldr,n(e.edges,Ut)))(H(r=>Pe(t)(r.x)(r.y)(0)))})()],sT=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=Ea(1e-4)(Ce(n*n+e*e)),i=e/r,o=n/r,u=t.to.y-i*7,s=t.to.x-o*7;return Ar([t.to,{x:s-i*3,y:u+o*3},{x:s+i*3,y:u-o*3}])},aT=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>i=>o=>u=>s=>{const a=Pe(r)(s.x)(s.y)(0),c=Pe(r)(u.x)(u.y)(0);return e.Bind1().bind(t.strokePath(Zw([c,a]))({color:i.edge,width:1.5,lineJoin:Le,lineCap:kn}))(()=>{const f=t.fillPath(sT({from:c,to:a}))({color:i.arrowFill,flat:!0});return o?f:n.pure()})}},cT=t=>{const e=aT(t);return n=>r=>i=>{const o=be(ln,i,kt(1,i.length,i)),u=o.length-1|0;return Ft(s=>a=>({depth:(a._1.x+a._1.y+a._2.x+a._2.y)/2,draw:e(n)(r)(s===u)(a._1)(a._2)}))(o)}},gT=t=>{const e=eT(t),n=rT(t),r=cT(t),i=t.Monad0(),o=Fu(i.Applicative0())(Bt);return u=>s=>a=>c=>{const f=Ta(s),d=[...(()=>{const l=(_,h)=>{if(_.tag==="Leaf")return h;if(_.tag==="Node")return l(_._5,Xt("Cons",_._4,l(_._6,h)));g()};return Tt(At(Kt.foldr,l(a.edges,Ut)))(r(u)(f))})(),...H(l=>({depth:l.box.depth,draw:e(u)(f)(l)}))(y1(u)(a)),...xt(n(u)(f)(a))((()=>{const l=(_,h)=>{if(_.tag==="Leaf")return h;if(_.tag==="Node")return l(_._5,Xt("Cons",_._4,l(_._6,h)));g()};return At(Kt.foldr,l(c.tokens,Ut))})())];return i.Bind1().bind((()=>{const l=tT(uT(u)(a));return t.Monad0().Bind1().bind(t.clearBackground(u.transparentBg?f.bgTransparent:f.bg))(()=>t.setViewport(l))})())(()=>o(l=>l.draw)(Et(l=>_=>rt.compare(l.depth)(_.depth))(d)))}},x1=(t,e)=>({tag:t,_1:e}),Tu=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fT=t=>e=>n=>{const r=rt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),o=rt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;g()},Sa=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},_T=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},dT=x1("ResolvedLabels"),lT=t=>{const e=Vt(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return zo(t);g()},$i=t=>e=>{const n=Tu(1)(Ne(e.rootLayout).w),r=Jo(e.rootLayout)(e.camera),i=!e.diving&&e.levels.length===1?1:fT(0)(1)(r.w/n),o=zo(e).state.frameTitle===""?0*i:40*i,u=t.padding*i*i;return(()=>{if(t.outputAspect.tag==="Nothing")return J0;if(t.outputAspect.tag==="Just")return eg(t.outputAspect._1);g()})()({vx:r.x-u,vy:r.y-u-o,vw:r.w+2*u,vh:r.h+2*u+o})},hT=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=Sa(e._1)(t.segment.layout.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1.x*t.segment.placement.scale+t.segment.placement.tx,i=n._1.y*t.segment.placement.scale+t.segment.placement.ty,o=n._1.w*t.segment.placement.scale,u=n._1.h*t.segment.placement.scale;return[1,r,i,2,r+o,i,2,r+o,i+u,2,r,i+u,5]}}g()},Ca=t=>e=>{const n=sh(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}},pT=t=>{const e=t.Monad0(),n=e.Bind1();return r=>i=>{if(r==="")return e.Applicative0().pure();const o=i.vh/720,u=56*o;return n.bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:56,weight:700})(r))(s=>{const a=u+16*o*2,c=s*o+28*o*2,f=i.vy+i.vh/2,d=i.vx+i.vw/2;return n.bind(t.drawRoundedRect({x:d-c/2,y:f-a/2,w:c,h:a})(16*o)(T("Just",{color:{r:255,g:255,b:255,a:235},flat:!0}))(T("Just",{color:{r:0,g:0,b:0,a:255},width:1.5*o,lineJoin:Le,lineCap:kn})))(()=>t.drawText({x:d,y:f,content:r,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:700},color:{r:28,g:30,b:36,a:255},align:ri,baseline:cr}))})}},mT=t=>{const e=t.Monad0(),n=e.Bind1();return r=>i=>{if(r==="")return e.Applicative0().pure();const o=i.vh/720,u=15*o;return n.bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:15,weight:600})(r))(s=>{const a=i.vy+12*o,c=u+6*o*2,f=s*o+11*o*2,d=i.vx+i.vw/2;return n.bind(t.drawRoundedRect({x:d-f/2,y:a,w:f,h:c})(c/2)(T("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}))(T("Just",{color:{r:0,g:0,b:0,a:255},width:1*o,lineJoin:Le,lineCap:kn})))(()=>t.drawText({x:d,y:a+c/2,content:r,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:600},color:{r:28,g:30,b:36,a:255},align:ri,baseline:cr}))})}},yT=t=>{const e=d1(t),n=ka(t),r=t.Monad0(),i=r.Bind1(),o=r.Applicative0(),u=l1(t),s=h1(t)(Ja)(1),a=a1(t),c=g1(t),f=c1(t),d=Aw(t),l=t.popBlur,_=t.popAlpha,h=pT(t),p=mT(t);return m=>y=>x=>N=>v=>b=>k=>E=>{const A=Ta(m.theme),$=(()=>{if(E.tag==="ResolvedLabels")return e(A)(v)(b)(k);if(E.tag==="SpringLabels")return n(A)(b)(k)(E._1);g()})();return i.bind(t.Monad0().Bind1().bind(t.clearBackground(m.transparentBg?A.bgTransparent:A.bg))(()=>t.setViewport(v)))(()=>i.bind((()=>{const tt=i.bind((()=>{const S=t.pushAlpha(x);return x<1?S:o.pure()})())(()=>i.bind((()=>{const S=t.pushBlur(N);return N>0?S:o.pure()})())(()=>i.bind(u(A)(b)(k))(()=>i.bind(s(A)(b)(k))(()=>i.bind(a(A)(b)(k))(()=>i.bind(c(A)(v)(b)(k))(()=>i.bind(f(ZN)(A)(b)(k))(()=>i.bind($)(()=>i.bind((()=>{const S=d(A)(b)(k);return k.staticKind!=="Animated"?S:o.pure()})())(()=>i.bind(N>0?l:o.pure())(()=>x<1?_:o.pure()))))))))));return x>0?tt:o.pure()})())(()=>i.bind(m.watermark===""?t.Monad0().Applicative0().pure():t.drawText({x:v.vx+6,y:v.vy+6,content:m.watermark,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:aa,baseline:HN}))(()=>k.staticKind==="TitleCard"?h(k.frameTitle)(v):p(k.frameTitle)(v))))}},N1=t=>{const e=t.Monad0().Applicative0(),n=oc(e)(Bt);return r=>i=>o=>u=>n(u.minis)(s=>{const a=J1(t)(r)(i)(o)(D)(u)(s);return(()=>{const c=s.segment.path.length-1|0;return s.bgAlpha>0&&c>=0&&c<s.segment.path.length&&(()=>{const f=Sa(s.segment.path[c])(u.state.nodes);if(f.tag==="Just")return f._1.tag==="Hidden"?!1:f._1.tag!=="PloppingOut";if(f.tag==="Nothing")return!1;g()})()})()?a:e.pure()})},J1=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=t.popTransform,o=d1(t),u=ka(t),s=l1(t),a=h1(t),c=a1(t),f=g1(t),d=c1(t),l=t.popBakedTransform,_=t.popClip,h=t.popBlur,p=t.popAlpha;return m=>y=>x=>N=>v=>b=>{const k=b.blur>0,E=b.segment.placement,A=b.state,$={tx:E.tx,ty:E.ty,sx:E.scale,sy:E.scale},tt=Ta(m.theme),S=b.segment.layout,C=Ne(S),V={vx:C.x-1e3,vy:C.y-1e3,vw:C.w+2e3,vh:C.h+2e3},U=b.segment.path.length-1|0,M=U>=0&&U<b.segment.path.length?Sa(b.segment.path[U])(v.segment.layout.nodes):J,W=b.segment.placement.scale*x,B=_T(8)(Tu(1)(1/(1.25*Tu(1e-6)(W)))),P=11*W>=5?Ja:bw,I=(()=>{if(M.tag==="Nothing")return n.pure();if(M.tag==="Just"){const R=M._1;return r.bind(t.pushTransform({tx:v.segment.placement.tx,ty:v.segment.placement.ty,sx:v.segment.placement.scale,sy:v.segment.placement.scale}))(()=>r.bind(_a(t)(R.shape)({x:R.x+1,y:R.y+1,w:R.w-2,h:R.h-2})(7)(T("Just",{color:tt.bg,flat:!0}))(J))(()=>i))}g()})(),F=(()=>{if(P==="LabelsHidden")return n.pure();if(P==="LabelsShown")return N.tag==="Leaf"?o(tt)(Ca(y.viewport)(b))(S)(A):u(tt)(S)(A)(N);g()})(),Q=hT(v)((()=>{const R=b.segment.path.length-1|0;return R>=0&&R<b.segment.path.length?T("Just",b.segment.path[R]):J})());return r.bind(t.pushAlpha(b.bgAlpha))(()=>r.bind((()=>{const R=t.pushBlur(b.blur*E.scale);return k?R:n.pure()})())(()=>r.bind(t.pushClip(Q)(cu))(()=>r.bind(v.role==="Active"||v.role==="FlyThrough"?I:n.pure())(()=>r.bind(t.pushTransform($))(()=>r.bind(s(tt)(S)(A))(()=>r.bind(a(P)(B)(tt)(S)(A))(()=>r.bind(c(tt)(S)(A))(()=>r.bind(f(tt)(V)(S)(A))(()=>r.bind(i)(()=>r.bind(t.pushBakedTransform($))(()=>r.bind(d(tJ)(tt)(S)(A))(()=>r.bind(l)(()=>r.bind(_)(()=>r.bind(t.pushTransform($))(()=>r.bind(F)(()=>r.bind(i)(()=>r.bind(N1(t)(m)(y)(x)(b))(()=>r.bind(k?h:n.pure())(()=>p)))))))))))))))))))}},w1=t=>{const e=gT(t),n=t.Monad0(),r=n.Applicative0(),i=n.Bind1(),o=J1(t),u=yT(t),s=N1(t);return a=>c=>f=>{if(a.theme==="Isometric")return e({...iT,transparentBg:a.transparentBg})(a.theme)(zo(f).segment.layout)(zo(f).state);const d=$i(a)(f),l=m=>f.hasDives?d.vw/Tu(1)(Ne(f.rootLayout).w):1,_={tileScale:l(),viewport:d},h=m=>y=>{if(y.length===0)return r.pure();const x=Mt(N=>J,N=>v=>T("Just",{head:N,tail:v}),y);if(x.tag==="Nothing")return r.pure();if(x.tag==="Just"){const N=x._1.head,v=x._1.tail;return i.bind((()=>{const b=o(a)(_)(f.camera.zoom)(N.role==="Active"?c:D)(m)(N);return f.diving||N.role==="Active"?b:r.pure()})())(()=>h(N)(v))}g()},p=Mt(m=>J,m=>y=>T("Just",{head:m,tail:y}),f.levels);if(p.tag==="Nothing")return r.pure();if(p.tag==="Just"){const m=p._1.tail,y=p._1.head;return i.bind((()=>{const x=m.length===0;return u(a)(l())(y.role==="Active"||y.role==="FlyThrough"?y.bgAlpha:0)(y.blur)(d)(y.segment.layout)(lT(f).state)(x&&c.tag!=="Leaf"?x1("SpringLabels",c):dT)})())(()=>i.bind((()=>{const x=s(a)(_)(f.camera.zoom)(y);return y.role==="Active"||y.role==="FlyThrough"?x:r.pure()})())(()=>h(y)(m)))}g()}},xT=La(I_),T1=w1(I_),NT=t=>e=>n=>r=>i=>o=>u=>{const s={padding:24,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?J:T("Just",r.width/r.height)},a=hJ(n)(r);return()=>{const c=a(),f=i.levels.length-1|0;if(f>=0&&f<i.levels.length){const l=xT(Ca($i(s)(i))(i.levels[f]))(i.levels[f].segment.layout)(i.levels[f].state)(c)(),_=ua(o)(l)(u);return T1(s)(_.applied)(i)(c)(),_.springs}const d=ua(o)(D)(u);return T1(s)(d.applied)(i)(c)(),d.springs}},JT=t=>t,Xi=t=>t,Ga=Xi("Light"),wT=Xi("Dark"),TT=Xi("Blueprint"),vT=Xi("Whiteboard"),bT=Xi("Isometric"),LT=JT("TransparentBackground"),fr=t=>"rgb("+ue(t.r)+","+ue(t.g)+","+ue(t.b)+")",Gn=pi(li("Fixed",hi(0)(20)(4))),kT=t=>"translate("+Gn(t.tx)+","+Gn(t.ty)+") scale("+Gn(t.sx)+","+Gn(t.sy)+")",vt=pi(li("Fixed",hi(0)(20)(2))),Pa=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,i=r>=0&&r<t.length?T("Just",t[r]):J;if(i.tag==="Nothing"){n=t.length;continue}if(i.tag==="Just"){if(i._1===1){e.push("M"),e.push(vt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===2){e.push("L"),e.push(vt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===3){e.push("Q"),e.push(vt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),n=r+5|0;continue}if(i._1===4){e.push("C"),e.push(vt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+5|0;return o>=0&&o<t.length?t[o]:0})())),e.push(vt((()=>{const o=r+6|0;return o>=0&&o<t.length?t[o]:0})())),n=r+7|0;continue}if(i._1===5){e.push("Z"),n=r+1|0;continue}n=t.length;continue}g()}return ko(" ")(e)},ET={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},Aa=(()=>{const t=or("&")("&"),e=or("<")("<"),n=(()=>{const r=or(">")(">"),i=(()=>{const o=or('"')(""");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),ST=t=>{if(t.style==="RunText")return"<tspan>"+Aa(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+Aa(t.text)+"</tspan>";g()},ke=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},CT=t=>e=>{const n=[];let r=0;const i=o=>{const u=o>=0&&o<e.length?t.sx*e[o]+t.tx:t.sx*0+t.tx;return()=>{n.push(u),n.push((()=>{const s=o+1|0;return s>=0&&s<e.length?t.sy*e[s]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const o=r,u=o>=0&&o<e.length?T("Just",e[o]):J;if(u.tag==="Nothing"){r=e.length;continue}if(u.tag==="Just"){if(u._1===1){n.push(u._1),i(o+1|0)(),r=o+3|0;continue}if(u._1===2){n.push(u._1),i(o+1|0)(),r=o+3|0;continue}if(u._1===3){n.push(u._1),i(o+1|0)(),i(o+3|0)(),r=o+5|0;continue}if(u._1===4){n.push(u._1),i(o+1|0)(),i(o+3|0)(),i(o+5|0)(),r=o+7|0;continue}if(u._1===5){n.push(u._1),r=o+1|0;continue}r=e.length;continue}g()}return n},vu=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return CT(r._1)(e);g()}},v1={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>ET},GT={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>v1},PT={pure:t=>e=>()=>t,Apply0:()=>v1},AT={Applicative0:()=>PT,Bind1:()=>GT},IT=t=>e=>'<defs><pattern id="'+t+'" x="'+vt(e.origin.x)+'" y="'+vt(e.origin.y)+'" width="'+vt(e.tile)+'" height="'+vt(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+vt(e.tile)+'" height="'+vt(e.tile)+'" fill="'+fr(e.bgColor)+'" fill-opacity="'+vt(et(e.bgColor.a)/255)+'"/>')+'<circle cx="'+vt(e.tile/2)+'" cy="'+vt(e.tile/2)+'" r="'+vt(e.dotRadius)+'" fill="'+fr(e.dotColor)+'"/></pattern></defs><rect x="'+vt(e.viewport.vx)+'" y="'+vt(e.viewport.vy)+'" width="'+vt(e.viewport.vw)+'" height="'+vt(e.viewport.vh)+'" fill="url(#'+t+')"/>',b1=t=>e=>'<path d="'+Pa(t)+'" fill="'+fr(e)+'" fill-opacity="'+vt(et(e.a)/255)+'"/>',QT=t=>e=>n=>r=>'<rect x="'+vt(t.x)+'" y="'+vt(t.y)+'" width="'+vt(t.w)+'" height="'+vt(t.h)+'" rx="'+vt(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+fr(n._1.color)+'" fill-opacity="'+vt(et(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';g()})()+(()=>{if(r.tag==="Just")return' stroke="'+fr(r._1.color)+'" stroke-opacity="'+vt(et(r._1.color.a)/255)+'" stroke-width="'+vt(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";g()})()+'"';if(r.tag==="Nothing")return"";g()})()+"/>",L1=t=>e=>'<path d="'+Pa(t)+'" fill="none" stroke="'+fr(e.color)+'" stroke-opacity="'+vt(et(e.color.a)/255)+'" stroke-width="'+vt(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";g()})()+'"/>',k1=t=>{const e=Ig(Yr(t.content));return'<text x="'+vt(t.x)+'" y="'+vt(t.y)+'"'+(()=>{if(t.baseline==="BaselineTop")return' dy="0.8em"';if(t.baseline==="BaselineMiddle")return' dy="0.32em"';if(t.baseline==="BaselineAlphabetic"||t.baseline==="BaselineBottom")return"";g()})()+' fill="'+fr(t.color)+'" fill-opacity="'+vt(et(t.color.a)/255)+'" font-size="'+vt(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+ue(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";g()})()+'">'+(e.length===1&&e[0].style==="RunText"?Aa(e[0].text):ko("")(H(ST)(e)))+"</text>"},DT=t=>"matrix("+Gn(t.a)+" "+Gn(t.b)+" "+Gn(t.c)+" "+Gn(t.d)+" "+Gn(t.e)+" "+Gn(t.f)+")",E1={fillPath:t=>e=>n=>{const r=vu(n)(t);return()=>{const i=r();return ke(b1(i)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=vu(n)(t);return()=>{const i=r(),o=n.bake.value;return ke(L1(i)((()=>{if(o.tag==="Nothing")return e;if(o.tag==="Just")return{...e,width:o._1.sx*e.width};g()})()))(n)()}},fillStrokePath:t=>e=>n=>r=>{const i=vu(r)(t);return()=>{const o=i(),u=r.bake.value;return ke(b1(o)(e.color)+L1(o)((()=>{if(u.tag==="Nothing")return n;if(u.tag==="Just")return{...n,width:u._1.sx*n.width};g()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>i=>{const o=i.bake;return()=>{const u=o.value;return ke(QT((()=>{if(u.tag==="Nothing")return t;if(u.tag==="Just")return{x:u._1.sx*t.x+u._1.tx,y:u._1.sy*t.y+u._1.ty,w:u._1.sx*t.w,h:u._1.sy*t.h};g()})())((()=>{if(u.tag==="Nothing")return e;if(u.tag==="Just")return u._1.sx*e;g()})())(n)(r.tag==="Just"?T("Just",(()=>{if(u.tag==="Nothing")return r._1;if(u.tag==="Just")return{...r._1,width:u._1.sx*r._1.width};g()})()):J))(i)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return ke(k1((()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return{...t,x:r._1.sx*t.x+r._1.tx,y:r._1.sy*t.y+r._1.ty,font:{...t.font,size:r._1.sx*t.font.size}};g()})()))(e)()}},drawTextAffine:t=>e=>ke((()=>{const n='transform="'+DT(t)+'"';return(n===""?"<g>":"<g "+n+">")+k1(e)+"</g>"})()),pushTransform:t=>ke((()=>{const e='transform="'+kT(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:ke("</g>"),pushBakedTransform:t=>e=>{const n=e.bake;return()=>{n.value=T("Just",t)}},popBakedTransform:t=>{const e=t.bake;return()=>{e.value=J}},pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const i=r.value;n.clipCounter.value=i+1|0;const o=vu(n)(t)(),u="clip"+ue(i);return ke((()=>{const s='clip-path="url(#'+u+')"';return'<defs><clipPath id="'+u+'"><path d="'+Pa(o)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";g()})()+"/></clipPath></defs>"+(s===""?"<g>":"<g "+s+">")})())(n)()}},popClip:ke("</g>"),pushBlend:t=>ke((()=>{const e=(()=>{if(t==="Normal")return'style="mix-blend-mode: normal"';if(t==="Difference")return'style="mix-blend-mode: difference"';g()})();return e===""?"<g>":"<g "+e+">"})()),popBlend:ke("</g>"),pushAlpha:t=>ke((()=>{const e='opacity="'+vt(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:ke("</g>"),pushBlur:t=>e=>{if(t<.01)return ke("<g>")(e);const n=e.patternCounter;return()=>{const r=n.value;e.patternCounter.value=r+1|0;const i="lvl-blur-"+ue(r);return ke((()=>{const o='filter="url(#'+i+')"';return'<defs><filter id="'+i+'" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="'+vt(t)+'"/></filter></defs>'+(o===""?"<g>":"<g "+o+">")})())(e)()}},popBlur:ke("</g>"),pushLayer:t=>e=>{const n=(()=>{if(t==="LayerNodeMask"){const r=e.maskDepth;return()=>{const i=r.value;e.maskDepth.value=i+1|0}}return()=>{}})();return()=>{n(),e.out.push("<g>")}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;n>0&&(t.maskDepth.value=r),t.out.push("</g>")}},setViewport:t=>e=>()=>{},clearBackground:t=>e=>ke('<rect x="'+vt(e.viewport.vx)+'" y="'+vt(e.viewport.vy)+'" width="'+vt(e.viewport.vw)+'" height="'+vt(e.viewport.vh)+'" fill="'+fr(t)+'" opacity="'+vt(et(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,ke(IT("bg-dots-"+ue(r))(t))(e)()}},measureText:t=>e=>n=>{const r=f_(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=__(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>J_,Monad0:()=>AT},FT=w1(E1),zT=La(E1),BT=t=>e=>n=>r=>i=>{const o={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:n,outputAspect:t},u=$i(o)(i);return{viewBox:vt(u.vx)+" "+vt(u.vy)+" "+vt(u.vw)+" "+vt(u.vh),body:(()=>{const s=[],a={value:0},c={value:0},f={value:0},d={value:J};return FT(o)(e)(i)({out:s,maskDepth:a,clipCounter:c,patternCounter:f,viewport:u,bake:d})(),ko("")(s)})(),vx:u.vx,vy:u.vy,vw:u.vw,vh:u.vh}},MT=t=>e=>n=>r=>i=>o=>{const u={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;g()})(),outputAspect:t},s=ua(i)((()=>{const a=[],c={value:0},f={value:0},d={value:0},l={value:J},_=r.levels.length-1|0;if(_>=0&&_<r.levels.length){const h=Ca($i(u)(r))(r.levels[_]);return zT(h)(r.levels[_].segment.layout)(r.levels[_].state)({out:a,maskDepth:c,clipCounter:f,patternCounter:d,viewport:h,bake:l})()}return D})())(o);return{parts:BT(t)(s.applied)(e)(n)(r),springs:s.springs}},Yi=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(i=>n(i._1)(i._2)),Apply0:()=>S1(t)}),S1=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>i=>o=>e.map(u=>L(r(u._1),u._2))(i(o))};return{apply:(()=>{const r=Yi(t);return i=>o=>r.bind(i)(u=>r.bind(o)(s=>Vi(t).pure(u(s))))})(),Functor0:()=>n}},Vi=t=>({pure:e=>n=>t.Applicative0().pure(L(e,n)),Apply0:()=>S1(t)}),WT=t=>{const e={Applicative0:()=>Vi(t),Bind1:()=>Yi(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},Ia=(t,e)=>({tag:t,_1:e}),Qa=t=>t,On=(t,e)=>({tag:t,_1:e}),Da=t=>t,we=WT(Vn),Wt=Yi(Vn),De=we.state(t=>L(t,t)),ee=Vi(Vn),$n=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},C1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},bu=Fu(ee)(Bt),Xn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},RT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},qT=(()=>{const t=Ue.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return T("Just",L(e._1,e._2));g()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Xt("Cons",r._3,n(r._6,i)));g()};return n(e,Ut)})())})(),HT=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}g()}return i},Lu=t=>e=>n=>w(r=>i=>t.Bind1().bind(r)(o=>e(o)(i)))(t.Applicative0().pure(n)),OT=w(t=>e=>Z(G)(e)()(t))(D),$T=(()=>{const t=(e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=Z(G)(a._1)()(s),i=a._2;continue}g()}return u})(D);return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Xt("Cons",r._3,n(r._6,i)));g()};return n(e,Ut)})())})(),XT=Da("RightArrow"),YT=Da("LeftArrow"),VT=Da("UndirectedArrow"),UT=On("Exit"),KT=Qa("AnimatedKeyframe"),jT=Qa("Still"),ZT=Qa("Title"),tv=t=>Ia("Par",t),G1=t=>Ia("Seq",t),ev=t=>e=>n=>{const r=hr(Zt,J,i=>i._1===t,n);if(r.tag==="Just"){const i=Un(Zt,J,r._1,L(t,e),n);if(i.tag==="Nothing")return n;if(i.tag==="Just")return i._1;g()}if(r.tag==="Nothing")return Dt(n)(L(t,e));g()},nv=t=>e=>H(n=>n._1===t?L(n._1,{...n._2,label:T("Just",e)}):L(n._1,n._2)),Te=t=>we.state(e=>L(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:T("Just",{msg:t,line:e.currentLine,column:e.currentColumn})};g()})())),rv=t=>Wt.bind(we.state(e=>L(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>Wt.bind(De)(e=>{if(e.error.tag==="Just")return ee.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!$n(t.op._1.id)(e.currNodes))return Te("cannot enter node "+t.op._1.id+": does not exist");if(!C1(t.op._1.id)(e.interiorOf))return Te("cannot enter node "+t.op._1.id+": it has no `inside` block");if(He(hn)(t.op._1.id)(e.enterStack))return Te("cannot enter node "+t.op._1.id+": already entered");const n=t.op._1;return we.state(r=>L(void 0,{...r,enterStack:Dt(r.enterStack)(n.id),scenes:Dt(r.scenes)(Ti("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=pr(e.enterStack);if(n.tag==="Nothing")return Te("`exit` without a matching `enter`");if(n.tag==="Just"){const r=n._1.init;return we.state(i=>L(void 0,{...i,enterStack:r,scenes:Dt(i.scenes)(Nh)}))}g()}return ee.pure()}g()})),iv=t=>Wt.bind(De)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ue(e.kfCounter);if(qe(i=>i.id===n,e.keyframes))return Te("duplicate frame name "+n);const r={...e,keyframes:Dt(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges,kind:vi}),kfCounter:e.kfCounter+1|0,currentKf:T("Just",n)};return we.state(i=>L(void 0,r))}),ov=bu(t=>Wt.bind(De)(e=>{if(e.error.tag==="Just")return ee.pure();if(e.error.tag==="Nothing")return C1(t.node)(e.interiorOf)?Te("node "+t.node+" has more than one `inside` block"):we.state(n=>L(void 0,{...n,interiorOf:Z(G)(t.node)(t.doc)(n.interiorOf)}));g()})),uv=t=>e=>{const n=e.from+"->"+e.to,r=e.newFrom+"->"+e.newTo,i=Gt("Left","cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist"),o=Xn(n)(t.currEdges)?Gt("Right",void 0):i;return(()=>{if(o.tag==="Left"){const u=o._1;return s=>Gt("Left",u)}if(o.tag==="Right"){const u=o._1;return s=>s(u)}g()})()(()=>{const u="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newFrom;if(!$n(e.newFrom)(t.currNodes))return Gt("Left",u);const s="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo;if(!$n(e.newTo)(t.currNodes))return Gt("Left",s);const a="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists";return n!==r&&Xn(r)(t.currEdges)?Gt("Left",a):Gt("Right",{nextCurrEdges:Z(G)(r)()(di(G)(n)(t.currEdges)),newId:r,newEdge:{id:r,from:{node:e.newFrom,port:J},to:{node:e.newTo,port:J},label:J}})})},P1={graphNodes:[],graphEdges:D,currNodes:D,currEdges:D,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:J,currentLine:0,currentColumn:0,error:J,enterStack:[],interiorOf:D},sv=Wt.bind(De)(t=>{if(t.error.tag==="Just")return ee.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return we.state(n=>L(void 0,{...n,scenes:Dt(n.scenes)(Ti("Hold",e))}))}if(t.currentKf.tag==="Nothing")return ee.pure()}g()}),A1=t=>e=>Wt.bind(De)(n=>{const r="ev-"+ue(n.eventCounter);return Wt.bind((()=>{const i={...n,eventCounter:n.eventCounter+1|0};return we.state(o=>L(void 0,i))})())(()=>ee.pure({events:[{id:r,kind:e,when:t}],firstId:T("Just",r),lastId:T("Just",r)}))}),av=t=>e=>{if(e.tag==="Token"){const n=e._1;return Wt.bind(De)(r=>{const i=!$n(n.from)(r.currNodes),o=!$n(n.to)(r.currNodes);if(i||o)return Wt.bind(Te(i?o?"token references unknown node: "+n.from+", "+n.to:"token references unknown node: "+n.from:o?"token references unknown node: "+n.to:"token references unknown node: "))(()=>ee.pure({events:[],firstId:J,lastId:J}));const u=n.to+"->"+n.from,s=n.from+"->"+n.to;return Xn(s)(r.currEdges)?A1(t)(zc("SendToken",{from:n.from,to:n.to,edge:s,direction:yh,labels:n.labels})):Xn(u)(r.currEdges)?A1(t)(zc("SendToken",{from:n.from,to:n.to,edge:u,direction:xh,labels:n.labels})):Wt.bind(Te("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>ee.pure({events:[],firstId:J,lastId:J}))})}return ee.pure({events:[],firstId:J,lastId:J})},cv=t=>e=>{if(0<t.length){const n=t[0];return Wt.bind(we.state(r=>L(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>Te(e))}return Te(e)},gv=t=>xt(e=>RT(e)(t.graphEdges))(At(Qr,qT(t.currEdges))),fv=t=>e=>{const n=ut(i=>i.from.node===e.id||i.to.node===e.id,gv(t)),r=Lu(ec)(i=>o=>{const u=o.from+"->"+e.id,s=e.id+"->"+o.to,a=o.from+"->"+o.to,c="via "+o.from+" "+o.to+": no edge "+o.from+"\u2192"+e.id;if(!Xn(u)(t.currEdges))return Gt("Left",c);const f="via "+o.from+" "+o.to+": no edge "+e.id+"\u2192"+o.to;if(!Xn(s)(t.currEdges))return Gt("Left",f);const d="via "+o.from+" "+o.to+": would create "+o.from+"\u2192"+o.to+" but it already exists";return Xn(a)(t.currEdges)||HT(a)(i.synthesized)?Gt("Left",d):Gt("Right",{consumed:Z(G)(u)()(Z(G)(s)()(i.consumed)),synthesized:Z(G)(a)({id:a,from:{node:o.from,port:J},to:{node:o.to,port:J},label:J})(i.synthesized)})})({consumed:D,synthesized:D})(e.via);return(()=>{if(r.tag==="Left"){const i=r._1;return o=>Gt("Left",i)}if(r.tag==="Right"){const i=r._1;return o=>o(i)}g()})()(i=>{const o=i.consumed,u=ut(s=>!Xn(s.id)(o),n);return u.length===0?Gt("Right",{nextCurrEdges:Ge(G.compare,Se,In(G.compare,t.currEdges,OT(H(s=>s.id)(n))),$T((()=>{const s=a=>{if(a.tag==="Leaf")return D;if(a.tag==="Node")return Ot("Node",a._1,a._2,a._3,void 0,s(a._5),s(a._6));g()};return s(i.synthesized)})())),synthesized:i.synthesized}):Gt("Left","cannot delete node "+e.id+": still connected ("+ko(", ")(H(s=>s.from.node+"\u2192"+s.to.node)(u))+"). Use -edge to drop them or `via a b` to merge "+e.id+"'s endpoints.")})},Fa=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq")return Tt(t._1)(Fa);g()},_v=Wt.bind(De)(t=>{if(t.error.tag==="Just")return ee.pure();if(t.error.tag==="Nothing"){const e=t.enterStack.length-1|0;return e>=0&&e<t.enterStack.length?Te("entered node "+t.enterStack[e]+" was never exited"):ee.pure()}g()}),dv=t=>({nodes:H(to)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Xt("Cons",n._4,e(n._6,r)));g()};return At(Kt.foldr,e(t.graphEdges,Ut))})(),constraints:[]}),lv=t=>{if(t.tag==="AddNode"){const e=t._1;return we.state(n=>L(void 0,{...n,graphNodes:ev(e.id)({id:e.id,size:L(1,1),ports:[],label:T("Just",e.label),shape:e.shape})(n.graphNodes),currNodes:Z(G)(e.id)()(n.currNodes)}))}if(t.tag==="DelNode"){const e=t._1;return Wt.bind(De)(n=>{if(!$n(e.id)(n.currNodes))return Te("cannot delete node "+e.id+": does not exist");const r=fv(n)(e);if(r.tag==="Left")return Te(r._1);if(r.tag==="Right"){const i=r._1;return we.state(o=>L(void 0,{...o,currNodes:di(G)(e.id)(o.currNodes),currEdges:i.nextCurrEdges,graphEdges:Ge(G.compare,Se,i.synthesized,o.graphEdges)}))}g()})}if(t.tag==="ModNode"){const e=t._1;return Wt.bind(De)(n=>{if(!$n(e.id)(n.currNodes))return Te("cannot modify node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=e.label._1;return we.state(i=>L(void 0,{...i,graphNodes:nv(e.id)(r)(i.graphNodes)}))}if(e.label.tag==="Nothing")return ee.pure();g()})}if(t.tag==="AddEdge"){const e=t._1;return Wt.bind(De)(n=>{const r=!$n(e.from)(n.currNodes),i=!$n(e.to)(n.currNodes);if(r||i)return Te("cannot add edge "+e.from+"\u2192"+e.to+": unknown node "+(r?i?e.from+", "+e.to:e.from:i?e.to:""));const o=e.from+"->"+e.to;return we.state(u=>L(void 0,{...u,graphEdges:Z(G)(o)({id:o,from:{node:e.from,port:J},to:{node:e.to,port:J},label:e.label})(u.graphEdges),currEdges:Z(G)(o)()(u.currEdges)}))})}if(t.tag==="DelEdge"){const e=t._1;return Wt.bind(De)(n=>{const r=e.from+"->"+e.to;return Xn(r)(n.currEdges)?we.state(i=>L(void 0,{...i,currEdges:di(G)(r)(i.currEdges)})):Te("cannot delete edge "+e.from+"\u2192"+e.to+": does not exist")})}if(t.tag==="RepointEdge"){const e=t._1;return Wt.bind(De)(n=>{const r=uv(n)(e);if(r.tag==="Left")return Te(r._1);if(r.tag==="Right"){const i=r._1;return we.state(o=>L(void 0,{...o,currEdges:i.nextCurrEdges,graphEdges:Z(G)(i.newId)(i.newEdge)(o.graphEdges)}))}g()})}return ee.pure()},hv=t=>Wt.bind(we.state(e=>L(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>lv(t.op)),I1=t=>e=>n=>Wt.bind(bu(hv)(n))(()=>Wt.bind(De)(r=>{const i=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ue(r.kfCounter);if(qe(u=>u.id===i,r.keyframes))return Te("duplicate frame name "+i);const o={...r,keyframes:Dt(r.keyframes)({id:i,nodes:r.currNodes,edges:r.currEdges,kind:t}),kfCounter:r.kfCounter+1|0,currentKf:T("Just",i),scenes:(()=>{if(r.currentKf.tag==="Nothing")return r.scenes;if(r.currentKf.tag==="Just")return Dt(r.scenes)(Ti("Structural",{from:r.currentKf._1,to:i,focus:J}));g()})()};return we.state(u=>L(void 0,o))})),Q1=t=>e=>{const n=Fa(e.ops),r=ut(o=>o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge",n),i=ut(o=>!(o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge"),n);if(0<i.length){const o=i[0];return Wt.bind(we.state(u=>L(void 0,{...u,currentLine:o.line,currentColumn:o.column})))(()=>Te("still/title blocks hold a static snapshot; they cannot contain tokens (a -> b, a <- b, or a -- b) or enter/exit"))}return t==="TitleCard"&&r.length===0?Te(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"):Wt.bind(I1(t)(e.name)(r))(()=>sv)},pv=t=>e=>{const n=Mt(r=>J,r=>i=>T("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return ee.pure({events:[],firstId:J,lastId:J});if(n.tag==="Just"){const r=n._1.tail;return Wt.bind(Ui(t)(n._1.head))(i=>Wt.bind(Lu({Applicative0:()=>Vi(Vn),Bind1:()=>Yi(Vn)})(o=>u=>Wt.bind(Ui((()=>{if(o.lastId.tag==="Just")return cs("After",o.lastId._1);if(o.lastId.tag==="Nothing")return t;g()})())(u))(s=>ee.pure({events:[...o.events,...s.events],firstId:(()=>{if(o.firstId.tag==="Just")return T("Just",o.firstId._1);if(o.firstId.tag==="Nothing")return s.firstId;g()})(),lastId:(()=>{if(s.lastId.tag==="Just")return T("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return o.lastId;g()})()})))(i)(r))(o=>ee.pure(o)))}g()},mv=t=>e=>{const n=Mt(r=>J,r=>i=>T("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return ee.pure({events:[],firstId:J,lastId:J});if(n.tag==="Just"){const r=n._1.tail;return Wt.bind(Ui(t)(n._1.head))(i=>Wt.bind(yv((()=>{if(i.firstId.tag==="Just")return cs("With",i.firstId._1);if(i.firstId.tag==="Nothing")return t;g()})())(r))(o=>ee.pure({events:[...i.events,...o.events],firstId:i.firstId,lastId:(()=>{if(i.lastId.tag==="Just")return T("Just",i.lastId._1);if(i.lastId.tag==="Nothing")return o.lastId;g()})()})))}g()},Ui=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return Wt.bind(we.state(r=>L(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>av(t)(n.op))}if(e.tag==="Seq")return pv(t)(e._1);if(e.tag==="Par")return mv(t)(e._1);g()},yv=t=>Lu({Applicative0:()=>Vi(Vn),Bind1:()=>Yi(Vn)})(e=>n=>Wt.bind(Ui(t)(n))(r=>ee.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;g()})(),lastId:(()=>{if(r.lastId.tag==="Just")return T("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;g()})()})))({events:[],firstId:J,lastId:J}),xv=t=>Wt.bind(De)(e=>{if(e.currentKf.tag==="Nothing")return Te("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return Wt.bind(Ui(mh)(t))(r=>Wt.bind(De)(i=>{const o={...i,scenes:Dt(i.scenes)(Ti("DataFlow",{keyframe:n,events:r.events,focus:J}))};return we.state(u=>L(void 0,o))}))}g()}),Nv=t=>{const e=Fa(t.ops),n=ut(o=>o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge",e),r=ut(o=>o.op.tag==="Enter"||o.op.tag==="Exit",e),i=ut(o=>!(o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge")&&!(o.op.tag==="Enter"||o.op.tag==="Exit"),e);return r.length!==0&&i.length!==0?cv(r)("`enter`/`exit` cannot be mixed with flow tokens in the same frame"):Wt.bind((()=>{const o=I1(vi)(t.name)(n);return n.length!==0?o:ee.pure()})())(()=>Wt.bind((()=>{const o=iv(t.name);return n.length===0&&i.length!==0?o:ee.pure()})())(()=>Wt.bind((()=>{const o=xv(t.ops);return i.length!==0?o:ee.pure()})())(()=>bu(rv)(r))))},Jv=t=>Wt.bind(De)(e=>{if(e.error.tag==="Just")return ee.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return Nv(t);if(t.kind==="Still")return Q1(hh)(t);if(t.kind==="Title")return Q1(ph)(t)}g()}),D1=t=>Wt.bind(ov(t.interiors))(()=>Wt.bind(bu(Jv)(t.frames))(()=>Wt.bind(_v)(()=>Wt.bind(De)(e=>{if(e.error.tag==="Just")return ee.pure(Gt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=wv(t.interiors);if(n.tag==="Left")return ee.pure(Gt("Left",n._1));if(n.tag==="Right")return ee.pure(Gt("Right",{seed:t.seed,graph:dv(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1}))}g()})))),wv=t=>{const e=Lu(ec)(n=>r=>{const i=D1(r.doc)(P1)._1;return(()=>{if(i.tag==="Left"){const o=i._1;return u=>Gt("Left",o)}if(i.tag==="Right"){const o=i._1;return u=>u(o)}g()})()(o=>Gt("Right",Z(G)(r.node)(o)(n)))})(D)(t);if(e.tag==="Left")return Gt("Left",e._1);if(e.tag==="Right")return Gt("Right",e._1);g()},ci=(t,e)=>({tag:"ParseError",_1:t,_2:e}),z=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),ku=(t,e,n)=>({tag:t,_1:e,_2:n}),Tv=t=>ku("More",t),vv=t=>ku("Lift",t),bv={defer:t=>{const e=Rl(t);return(n,r,i,o,u)=>ql(e)(n,r,i,o,u)}},F1={map:t=>e=>(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,c)=>r(f=>u(a,t(c)))))},Lv={alt:t=>e=>(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>t(z(s,a,!1),r,i,(f,d)=>{const l=f._3;return r(_=>l?o(f,d):e(n,r,i,o,u))},u))},Functor0:()=>F1},kv=t=>{const e=t.Monad0();return n=>r=>{const i=o=>{let u=o,s=!0,a;for(;s;){const c=u();if(c.tag==="More"){u=c._1;continue}if(c.tag==="Lift"){s=!1,a=e.Bind1().Apply0().Functor0().map(rc)(c._1);continue}if(c.tag==="Stop"){s=!1,a=e.Applicative0().pure(gi("Done",L(c._2,c._1)));continue}g()}return a};return t.tailRecM(i)(o=>r(n,Tv,vv,(u,s)=>ku("Stop",u,Gt("Left",s)),(u,s)=>ku("Stop",u,Gt("Right",s))))}},z1=(t,e,n,r,i)=>i(t,t._2),Ev={index:0,line:1,column:1},Sv=(t=>{const e=kv(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(eo)(e(z(n,Ev,!1))(r))})(md),B1={apply:t=>e=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,c)=>r(f=>{const d=n._3&&!a._3?z(a._1,a._2,!0):a;return e(d,r,i,o,(l,_)=>r(h=>u(d._3&&!l._3?z(l._1,l._2,!0):l,c(_))))}))),Functor0:()=>F1},M1={pure:t=>(e,n,r,i,o)=>o(e,t),Apply0:()=>B1},Cv={bind:t=>e=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,c)=>r(f=>e(c)(n._3&&!a._3?z(a._1,a._2,!0):a,r,i,o,u)))),Apply0:()=>B1},Gv={Applicative0:()=>M1,Bind1:()=>Cv},Eu=t=>(e,n,r,i,o)=>n(u=>z1(e,n,r,i,(s,a)=>n(c=>i(e._3&&!s._3?z(s._1,s._2,!0):s,ci(t,a))))),Pv={empty:Eu("No alternative"),Alt0:()=>Lv},Av={Applicative0:()=>M1,Plus1:()=>Pv},sn=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return i=>t.tailRecM(o=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(rc)(i))(r.pure(gi("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return gi("Loop",Xt("Cons",u._1,o));if(u.tag==="Done")return gi("Done",(s=>a=>{let c=s,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=Xt("Cons",h._1,_),f=h._2;continue}g()}return l})(Ut)(o));g()})())))(Ut)})({tailRecM:t=>e=>(n,r,i,o,u)=>{const s=(a,c,f)=>t(c)(a,r,i,o,(d,l)=>{const _=a._3&&!d._3?z(d._1,d._2,!0):d;if(l.tag==="Loop")return f===0?r(h=>s(_,l._1,30)):s(_,l._1,f-1|0);if(l.tag==="Done")return u(_,l._1);g()});return s(n,e,30)},Monad0:()=>Gv})(Av),St=t=>e=>{const n=Eu("Expected "+e);return(r,i,o,u,s)=>{const a=r._1,c=r._2;return i(f=>t(z(a,c,!1),i,o,(d,l)=>{const _=d._3;return i(h=>_?u(d,l):n(r,i,o,u,s))},s))}},Su=t=>(e,n,r,i,o)=>{const u=e._3,s=e._1,a=e._2;return n(c=>{const f=(d,l)=>{const _=d._3;return n(h=>_?i(z(d._1,d._2,u),l):o(e,void 0))};return n(d=>n(l=>t(z(s,a,!1),n,r,(_,h)=>f(z(_._1,_._2,!1),h),(_,h)=>n(p=>n(m=>Eu("Negated parser succeeded")(_,n,r,f,(y,x)=>n(N=>o(_._3&&!y._3?z(y._1,y._2,!0):y,x))))))))})},Iv=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return T("Just",n);if(r.tag==="Just")return T("Just",(i,o,u,s,a)=>{const c=i._1,f=i._2;return o(d=>n(z(c,f,!1),o,u,(l,_)=>{const h=l._3;return o(p=>h?s(l,_):r._1(i,o,u,s,a))},a))});g()})(J);return n=>{const r=e(n);if(r.tag==="Nothing")return Eu("No alternative");if(r.tag==="Just")return r._1;g()}},Qv=t=>e=>n=>(r,i,o,u,s)=>i(a=>i(c=>i(f=>i(d=>t(r,i,o,u,(l,_)=>i(h=>i(p=>{const m=r._3&&!l._3?z(l._1,l._2,!0):l;return n(m,i,o,u,(y,x)=>i(N=>{const v=m._3&&!y._3?z(y._1,y._2,!0):y;return i(b=>i(k=>{const E=r._3&&!v._3?z(v._1,v._2,!0):v;return e(E,i,o,u,(A,$)=>i(tt=>s(E._3&&!A._3?z(A._1,A._2,!0):A,x)))}))}))}))))))),za=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=N0()(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)-Kn(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},Dv=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,c=i,f=o,d=Eo(c);if(d.tag==="Nothing"){u=!1,s=a;continue}if(d.tag==="Just"){r=d._1.tail===""?za(a)(d._1.head)(f):za(a)(d._1.head)(d._1.tail),i=d._1.tail,o=f;continue}g()}return s},Yt=t=>(e,n,r,i,o)=>{const u=Eo(e._1);if(u.tag==="Nothing")return i(e,ci("Unexpected EOF",e._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return i(e,ci("Expected Char",e._2));if(u._1.head>=0&&u._1.head<=65535){const s=jc(u._1.head);return t(s)?o(z(u._1.tail,za(e._2)(u._1.head)(u._1.tail),!0),s):i(e,ci("Predicate unsatisfied",e._2))}}g()},Ba=(t,e,n,r,i)=>t._1===""?i(z(t._1,t._2,!0),void 0):r(t,ci("Expected EOF",t._2)),Fv=t=>(e,n,r,i,o)=>{const u=t(e._1);if(u.tag==="Left")return i(e,ci(u._1,e._2));if(u.tag==="Right")return o(z(u._1.remainder,Dv(e._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);g()},Ir=t=>Fv(e=>{const n=Wl(t)(e);return n.tag==="Just"?Gt("Right",{value:t,consumed:t,remainder:n._1}):Gt("Left","Expected "+od(t))}),zv=Yt(t=>!0),W1=(t,e)=>({tag:t,_1:e}),Ma=Iv(Bt),Bv=te(G)(Bt),Mv=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=J;continue}if(o.tag==="Node"){const u=G.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=T("Just",o._4);continue}}g()}return i},R1=(()=>{const t=Yt(e=>e===" "||e===" "||e===`
|
|
9
|
-
|
|
10
|
-
`)),f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>i(f._3&&!l._3?z(l._1,l._2,!0):l,void 0))))}))),Wv=St((()=>{const t=St(Yt(n=>n==="}"))("'}'"),e=Yt(n=>n===`
|
|
11
|
-
`||
|
|
12
|
-
|
|
13
|
-
`)
|
|
14
|
-
`&&V!=="\r"&&V!=="#"&&V!=="}")),C=v._3&&!A._3?z(A._1,A._2,!0):A;return d(V=>S(C,d,l,x,(U,M)=>d(W=>h(C._3&&!U._3?z(U._1,U._2,!0):U,a0(Nr(At(Kt.foldr,M)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(e._3&&!s._3?z(s._1,s._2,!0):s,n,r,i,o))))})(),H1=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>q1(z(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):Ra(t,e,n,r,i))},i))},Ki=Yt(t=>t>="0"&&t<="9"),Ee=(()=>{const t=St(Yt(e=>e==="_"))("'_'");return(e,n,r,i,o)=>n(u=>{const s=(f,d)=>n(l=>{const _=sn((()=>{const p=St(Yt(y=>y==="_"))("'_'"),m=St(Yt(y=>y==="-"))("'-'");return(y,x,N,v,b)=>{const k=y._1,E=y._2;return x(A=>Cu(z(k,E,!1),x,N,($,tt)=>{const S=$._3;return x(C=>{if(S)return v($,tt);const V=y._1,U=y._2;return x(M=>Ki(z(V,U,!1),x,N,(W,B)=>{const P=W._3;return x(I=>{if(P)return v(W,B);const F=y._1,Q=y._2;return x(R=>p(z(F,Q,!1),x,N,(Y,O)=>{const X=Y._3;return x(q=>X?v(Y,O):m(y,x,N,v,b))},b))})},b))})},b))}})()),h=e._3&&!f._3?z(f._1,f._2,!0):f;return n(p=>_(h,n,r,i,(m,y)=>n(x=>o(h._3&&!m._3?z(m._1,m._2,!0):m,go(d)+Nr(At(Kt.foldr,y))))))}),a=e._1,c=e._2;return n(f=>Cu(z(a,c,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?i(d,l):t(e,n,r,i,s))},s))})})(),$v=St((t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>Ra(z(o,u,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):Ee(t,e,n,r,i))},i))})("frame name (identifier or quoted string)"),O1=(t,e,n,r,i)=>e(o=>Re(t,e,n,r,(u,s)=>e(a=>{const c=St(Ee)("attribute key"),f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=f._3&&!l._3?z(l._1,l._2,!0):l;return e(m=>Re(p,e,n,r,(y,x)=>e(N=>{const v=St(St(Yt(k=>k===":"))("':'"))("':'"),b=p._3&&!y._3?z(y._1,y._2,!0):y;return e(k=>v(b,e,n,r,(E,A)=>e($=>{const tt=b._3&&!E._3?z(E._1,E._2,!0):E;return e(S=>Re(tt,e,n,r,(C,V)=>e(U=>{const M=St(Ee)("attribute value"),W=tt._3&&!C._3?z(C._1,C._2,!0):C;return e(B=>M(W,e,n,r,(P,I)=>e(F=>{const Q=W._3&&!P._3?z(P._1,P._2,!0):P;return e(R=>Re(Q,e,n,r,(Y,O)=>e(X=>i(Q._3&&!Y._3?z(Y._1,Y._2,!0):Y,L(_,I)))))})))})))})))})))})))}))),Xv=(t,e,n,r,i)=>e(o=>Ee(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?z(u._1,u._2,!0):u;return e(f=>Re(c,e,n,r,(d,l)=>e(_=>{const h=c._3&&!d._3?z(d._1,d._2,!0):d;return e(p=>Rv(h,e,n,r,(m,y)=>e(x=>{const N=h._3&&!m._3?z(m._1,m._2,!0):m;return e(v=>Re(N,e,n,r,(b,k)=>e(E=>{const A=St(Ee)("target node identifier"),$=N._3&&!b._3?z(b._1,b._2,!0):b;return e(tt=>A($,e,n,r,(S,C)=>e(V=>{const U=sn((W,B,P,I,F)=>{const Q=W._3;return B(R=>B(Y=>Re(W,B,P,(O,X)=>I(z(O._1,O._2,Q),X),(O,X)=>B(q=>B(K=>{const j=W._3&&!O._3?z(O._1,O._2,!0):O;return H1(j,B,P,(ot,_t)=>I(z(ot._1,ot._2,Q),_t),(ot,_t)=>B(gt=>F(j._3&&!ot._3?z(ot._1,ot._2,!0):ot,_t)))})))))}),M=$._3&&!S._3?z(S._1,S._2,!0):S;return e(W=>U(M,e,n,r,(B,P)=>e(I=>(()=>{if(y==="LeftArrow"){const Q=On("Token",{from:C,to:s,labels:H(Cc)(At(Kt.foldr,P)),arrow:y});return(R,Y,O,X,q)=>q(R,Q)}const F=On("Token",{from:s,to:C,labels:H(Cc)(At(Kt.foldr,P)),arrow:y});return(Q,R,Y,O,X)=>X(Q,F)})()(M._3&&!B._3?z(B._1,B._2,!0):B,e,n,r,i))))})))})))})))})))}))),Yv=(t,e,n,r,i)=>e(o=>Ki(t,e,n,r,(u,s)=>e(a=>{const c=sn(Ki),f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=Xd(go(s)+Nr(At(Kt.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(y,x,N,v,b)=>b(y,m)}if(p.tag==="Nothing")return(m,y,x,N,v)=>v(m,0);g()})()(f._3&&!l._3?z(l._1,l._2,!0):l,e,n,r,i)})))}))),ji=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>Ir(t)(e,n,r,(a,c)=>i(z(a._1,a._2,u),c),(a,c)=>n(f=>{const d=Su((()=>{const _=St(Yt(p=>p==="_"))("'_'"),h=St(Yt(p=>p==="-"))("'-'");return(p,m,y,x,N)=>{const v=p._1,b=p._2;return m(k=>Cu(z(v,b,!1),m,y,(E,A)=>{const $=E._3;return m(tt=>{if($)return x(E,A);const S=p._1,C=p._2;return m(V=>Ki(z(S,C,!1),m,y,(U,M)=>{const W=U._3;return m(B=>{if(W)return x(U,M);const P=p._1,I=p._2;return m(F=>_(z(P,I,!1),m,y,(Q,R)=>{const Y=Q._3;return m(O=>Y?x(Q,R):h(p,m,y,x,N))},N))})},N))})},N))}})()),l=e._3&&!a._3?z(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(z(h._1,h._2,u),p),(h,p)=>n(m=>{const y=l._3&&!h._3?z(h._1,h._2,!0):h;return n(x=>en(y,n,r,(N,v)=>i(z(N._1,N._2,u),v),(N,v)=>n(b=>o(y._3&&!N._3?z(N._1,N._2,!0):N,t))))})))})))},Vv=(t,e,n,r,i)=>e(o=>fn(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?z(u._1,u._2,!0):u;return e(f=>ji("via")(c,e,n,r,(d,l)=>e(_=>{const h=c._3&&!d._3?z(d._1,d._2,!0):d;return e(p=>Ee(h,e,n,r,(m,y)=>e(x=>{const N=h._3&&!m._3?z(m._1,m._2,!0):m;return e(v=>fn(N,e,n,r,(b,k)=>e(E=>{const A=N._3&&!b._3?z(b._1,b._2,!0):b;return e($=>Ee(A,e,n,r,(tt,S)=>e(C=>i(A._3&&!tt._3?z(tt._1,tt._2,!0):tt,{from:y,to:S}))))})))})))})))}))),_r=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>Ir(t)(e,n,r,(a,c)=>i(z(a._1,a._2,u),c),(a,c)=>n(f=>{const d=Su((()=>{const _=St(Yt(p=>p==="_"))("'_'"),h=St(Yt(p=>p==="-"))("'-'");return(p,m,y,x,N)=>{const v=p._1,b=p._2;return m(k=>Cu(z(v,b,!1),m,y,(E,A)=>{const $=E._3;return m(tt=>{if($)return x(E,A);const S=p._1,C=p._2;return m(V=>Ki(z(S,C,!1),m,y,(U,M)=>{const W=U._3;return m(B=>{if(W)return x(U,M);const P=p._1,I=p._2;return m(F=>_(z(P,I,!1),m,y,(Q,R)=>{const Y=Q._3;return m(O=>Y?x(Q,R):h(p,m,y,x,N))},N))})},N))})},N))}})()),l=e._3&&!a._3?z(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(z(h._1,h._2,u),p),(h,p)=>n(m=>o(l._3&&!h._3?z(h._1,h._2,!0):h,void 0))))})))},Uv=(t,e,n,r,i)=>e(o=>_r("+edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?z(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=St(Ee)("source node identifier"),p=c._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const v=p._3&&!y._3?z(y._1,y._2,!0):y;return e(b=>fn(v,e,n,r,(k,E)=>e(A=>{const $=St(Ee)("target node identifier"),tt=v._3&&!k._3?z(k._1,k._2,!0):k;return e(S=>$(tt,e,n,r,(C,V)=>e(U=>{const M=tt._3&&!C._3?z(C._1,C._2,!0):C;return e(W=>{const B=(F,Q)=>e(R=>i(M._3&&!F._3?z(F._1,F._2,!0):F,On("AddEdge",{from:x,to:V,label:Q.tag==="Just"?T("Just",Q._1):J}))),P=M._1,I=M._2;return e(F=>e(Q=>{const R=(Y,O)=>{const X=Y._3;return e(q=>X?r(Y,O):B(M,J))};return e(Y=>e(O=>Re(z(P,I,!1),e,n,(X,q)=>R(z(X._1,X._2,!1),q),(X,q)=>e(K=>e(j=>H1(X,e,n,(ot,_t)=>R(z(ot._1,ot._2,!1),_t),(ot,_t)=>e(gt=>{const yt=X._3&&!ot._3?z(ot._1,ot._2,!0):ot;return e(Ct=>B(yt,T("Just",_t)))})))))))}))})})))})))})))})))}))),Kv=(t,e,n,r,i)=>e(o=>_r("-edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?z(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=St(Ee)("source node identifier"),p=c._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const v=p._3&&!y._3?z(y._1,y._2,!0):y;return e(b=>fn(v,e,n,r,(k,E)=>e(A=>{const $=St(Ee)("target node identifier"),tt=v._3&&!k._3?z(k._1,k._2,!0):k;return e(S=>$(tt,e,n,r,(C,V)=>e(U=>i(tt._3&&!C._3?z(C._1,C._2,!0):C,On("DelEdge",{from:x,to:V})))))})))})))})))}))),jv=(t,e,n,r,i)=>e(o=>_r("-node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?z(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=St(Ee)("node identifier"),p=c._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const v=sn((k,E,A,$,tt)=>{const S=k._3;return Vv(k,E,A,(C,V)=>$(z(C._1,C._2,S),V),tt)}),b=p._3&&!y._3?z(y._1,y._2,!0):y;return e(k=>v(b,e,n,r,(E,A)=>e($=>i(b._3&&!E._3?z(E._1,E._2,!0):E,On("DelNode",{id:x,via:At(Kt.foldr,A)})))))})))})))}))),Zv=(t,e,n,r,i)=>e(o=>_r("enter")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?z(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=St(Ee)("node identifier"),p=c._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>i(p._3&&!y._3?z(y._1,y._2,!0):y,On("Enter",{id:x})))))})))}))),tb=(t,e,n,r,i)=>e(o=>_r("exit")(t,e,n,r,(u,s)=>e(a=>i(t._3&&!u._3?z(u._1,u._2,!0):u,UT)))),eb=(t,e,n,r,i)=>e(o=>_r("~edge")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?z(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=St(Ee)("source node identifier"),p=c._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const v=p._3&&!y._3?z(y._1,y._2,!0):y;return e(b=>fn(v,e,n,r,(k,E)=>e(A=>{const $=St(Ee)("target node identifier"),tt=v._3&&!k._3?z(k._1,k._2,!0):k;return e(S=>$(tt,e,n,r,(C,V)=>e(U=>{const M=tt._3&&!C._3?z(C._1,C._2,!0):C;return e(W=>en(M,e,n,r,(B,P)=>e(I=>{const F=St(Ir("->"))("'->'"),Q=M._3&&!B._3?z(B._1,B._2,!0):B;return e(R=>F(Q,e,n,r,(Y,O)=>e(X=>{const q=Q._3&&!Y._3?z(Y._1,Y._2,!0):Y;return e(K=>en(q,e,n,r,(j,ot)=>e(_t=>{const gt=St(Ee)("new source node identifier"),yt=q._3&&!j._3?z(j._1,j._2,!0):j;return e(Ct=>gt(yt,e,n,r,(Rt,pt)=>e(qt=>{const wt=yt._3&&!Rt._3?z(Rt._1,Rt._2,!0):Rt;return e(mt=>fn(wt,e,n,r,(ft,st)=>e(dt=>{const at=St(Ee)("new target node identifier"),ct=wt._3&&!ft._3?z(ft._1,ft._2,!0):ft;return e(Nt=>at(ct,e,n,r,(Jt,Lt)=>e(Ht=>i(ct._3&&!Jt._3?z(Jt._1,Jt._2,!0):Jt,On("RepointEdge",{from:x,to:V,newFrom:pt,newTo:Lt})))))})))})))})))})))})))})))})))})))})))}))),nb=(t,e,n,r,i)=>e(o=>_r("seed")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?z(u._1,u._2,!0):u;return e(f=>Re(c,e,n,r,(d,l)=>e(_=>{const h=St(Yv)("integer (seed value)"),p=c._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const v=p._3&&!y._3?z(y._1,y._2,!0):y;return e(b=>en(v,e,n,r,(k,E)=>e(A=>i(v._3&&!k._3?z(k._1,k._2,!0):k,x))))})))})))}))),Zi=Qv((()=>{const t=St(Yt(e=>e==="{"))("'{'");return(e,n,r,i,o)=>n(u=>n(s=>t(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?z(a._1,a._2,!0):a;return en(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?z(_._1,_._2,!0):_,h)))})))))})())(St((()=>{const t=St(Yt(e=>e==="}"))("'}'");return(e,n,r,i,o)=>n(u=>n(s=>en(e,n,r,i,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?z(a._1,a._2,!0):a;return t(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?z(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),rb=Zi((t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>(()=>{if(f.tag==="Nothing")return(l,_,h,p,m)=>m(l,D);if(f.tag==="Just"){const l=f._1,_=sn((()=>{const h=St(Yt(p=>p===","))("','");return(p,m,y,x,N)=>{const v=p._3;return m(b=>m(k=>m(E=>m(A=>m($=>m(tt=>Re(p,m,y,(S,C)=>x(z(S._1,S._2,v),C),(S,C)=>m(V=>m(U=>{const M=p._3&&!S._3?z(S._1,S._2,!0):S;return h(M,m,y,(W,B)=>x(z(W._1,W._2,v),B),(W,B)=>m(P=>{const I=M._3&&!W._3?z(W._1,W._2,!0):W;return m(F=>m(Q=>{const R=p._3&&!I._3?z(I._1,I._2,!0):I;return Re(R,m,y,(Y,O)=>x(z(Y._1,Y._2,v),O),(Y,O)=>m(X=>{const q=R._3&&!Y._3?z(Y._1,Y._2,!0):Y;return m(K=>m(j=>{const ot=p._3&&!q._3?z(q._1,q._2,!0):q;return O1(ot,m,y,(_t,gt)=>x(z(_t._1,_t._2,v),gt),(_t,gt)=>m(yt=>N(ot._3&&!_t._3?z(_t._1,_t._2,!0):_t,gt)))}))}))}))}))})))))))))}})());return(h,p,m,y,x)=>p(N=>_(h,p,m,y,(v,b)=>p(k=>x(h._3&&!v._3?z(v._1,v._2,!0):v,Bv([l,...At(Kt.foldr,b)])))))}g()})()(t._3&&!c._3?z(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>e(f=>O1(z(s,a,!1),e,n,(d,l)=>e(_=>u(t,J)),(d,l)=>e(_=>u(d,T("Just",l))))))})),ib=(t,e,n,r,i)=>e(o=>_r("+node")(t,e,n,r,(u,s)=>e(a=>{const c=t._3&&!u._3?z(u._1,u._2,!0):u;return e(f=>fn(c,e,n,r,(d,l)=>e(_=>{const h=St(Ee)("node identifier"),p=c._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(y,x)=>e(N=>{const v=p._3&&!y._3?z(y._1,y._2,!0):y;return e(b=>e(k=>Re(v,e,n,r,(E,A)=>e($=>{const tt=Yt(C=>C===`
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
var JC=(function(Pu){"use strict";function g(){throw new Error("Failed pattern match")}function rr(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const Qe=t=>e=>t,$=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}},ah={map:$},ag=t=>t,Lt=typeof Array.prototype.flatMap=="function"?function(t){return function(e){return t.flatMap(e)}}:function(t){return function(e){for(var n=[],r=t.length,o=0;o<r;o++)for(var i=e(t[o]),s=i.length,u=0;u<s;u++)n.push(i[u]);return n}},ee=function(t){return t.toString()},Fr=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},ch=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})+'"'},Iu=t=>t,Le=Iu("LT"),Ce=Iu("GT"),Oe=Iu("EQ"),v=(t,e)=>({tag:t,_1:e}),N=v("Nothing"),ne=t=>v("Just",t),cg=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;g()},gg=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;g()},Rt=(t,e)=>({tag:t,_1:e}),gh=t=>Rt("Right",t),fh={map:t=>e=>{if(e.tag==="Left")return Rt("Left",e._1);if(e.tag==="Right")return Rt("Right",t(e._1));g()}},fg={apply:t=>e=>{if(t.tag==="Left")return Rt("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Rt("Left",e._1);if(e.tag==="Right")return Rt("Right",t._1(e._1))}g()},Functor0:()=>fh},_h={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Rt("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}g()},Apply0:()=>fg},dh={pure:gh,Apply0:()=>fg},_g={Applicative0:()=>dh,Bind1:()=>_h},lh=t=>t,hh={map:t=>e=>t(e)},dg={apply:t=>e=>t(e),Functor0:()=>hh},ph={bind:t=>e=>e(t),Apply0:()=>dg},mh={pure:lh,Apply0:()=>dg},pn={Applicative0:()=>mh,Bind1:()=>ph},yh=function(t){return function(){return t}},xh={apply:t=>e=>()=>{const n=t(),r=e();return Au.pure(n(r))()},Functor0:()=>Jh},Au={pure:yh,Apply0:()=>xh},Jh={map:t=>e=>()=>{const n=e();return t(n)}},fo=(t,e)=>({tag:t,_1:e}),Du=t=>fo("Loop",t),Nh=t=>fo("Done",t),wh={tailRecM:t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const s=r;if(s.tag==="Loop"){r=t(s._1);continue}if(s.tag==="Done"){o=!1,i=s._1;continue}g()}return i};return n=>e(t(n))},Monad0:()=>pn},vh=function(t){return function(e){return function(){return t(e())}}},Th=function(t){return function(){return t}},bh=function(t){return function(e){return function(){return e(t())()}}},kh={map:vh},Lh={Applicative0:()=>Bu,Bind1:()=>Ch},Ch={bind:bh,Apply0:()=>lg},lg={apply:t=>e=>()=>{const n=t(),r=e();return Bu.pure(n(r))()},Functor0:()=>kh},Bu={pure:Th,Apply0:()=>lg},Sh={tailRecM:t=>e=>{const n=t(e);return()=>{let r=n();for(;r.tag==="Loop";){const i=r;if(i.tag==="Loop"){r=t(i._1)();continue}i.tag!=="Done"&&g()}const o=r;if(o.tag==="Done")return o._1;g()}},Monad0:()=>Lh},Eh=function(t){return function(e){return function(n){return function(){return t(e,n)}}}},Gh=function(t,e,n,r){return n>=0&&n<r.length?t(r[n]):e},Ru=function(t){return t.length},Ph=function(t,e,n){return n.length>0?t(n.pop()):e},Ih=Eh(function(t,e){return e.push(t)}),Ah=(t,e)=>({tag:"Iterator",_1:t,_2:e}),Dh=t=>e=>n=>()=>{let r=!1;const o=e._2;for(;!r;){const i=o.value,s=e._1(i);if(s.tag==="Just"&&t(s._1)){n.push(s._1),e._2.value;const u=e._2.value;e._2.value=u+1|0;continue}r=!0}},Bh=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const o=r.value,i=r.value;r.value=i+1|0;const s=t._1(o);if(s.tag==="Just"){e(s._1)();continue}if(s.tag==="Nothing"){n=!0;continue}g()}},_o=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}}},w=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}}},Ri=t=>{const e=t.Apply0();return n=>r=>n.foldr(o=>{const i=r(o);return s=>e.apply(e.Functor0().map(u=>ag)(i))(s)})(t.pure())},lo=t=>{const e=Ri(t);return n=>{const r=e(n);return o=>i=>r(i)(o)}},Rh={foldr:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(n._1)(e);g()},foldl:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(e)(n._1);g()},foldMap:t=>{const e=t.mempty;return n=>r=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return n(r._1);g()}}},zt={foldr:_o,foldl:w,foldMap:t=>{const e=t.mempty;return n=>zt.foldr(r=>o=>t.Semigroup0().append(n(r))(o))(e)}},k=(t,e)=>({tag:"Tuple",_1:t,_2:e}),En=t=>e=>k(t,e),Qi=t=>t._2,Fi=t=>t._1,Yt=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 Qu=function(t){return function(e){return t===e}};const Qh=Qu,Fh=Qu,Vo=Qu,Fu=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}}},Qn={eq:Vo},zh={eq:Fh},vr={eq:Qh};var zu=function(t){return function(e){return function(n){return function(r){return function(o){return r<o?t:r===o?e:n}}}}};const Mh=zu,Hh=zu,I={compare:zu(Le)(Oe)(Ce),Eq0:()=>Qn},rt={compare:Hh(Le)(Oe)(Ce),Eq0:()=>zh},nt={compare:Mh(Le)(Oe)(Ce),Eq0:()=>vr},Mu=function(t){return t},Oh=(function(){function t(o){return[o]}function e(o){return function(i){return[o,i]}}function n(o){return function(i){return function(s){return[o,i,s]}}}function r(o){return function(i){return o.concat(i)}}return function(o){return function(i){return function(s){return function(u){return function(a){function c(f,d){switch(d-f){case 0:return s([]);case 1:return i(t)(u(a[f]));case 2:return o(i(e)(u(a[f])))(u(a[f+1]));case 3:return o(o(i(n)(u(a[f])))(u(a[f+1])))(u(a[f+2]));default:var l=f+Math.floor((d-f)/4)*2;return o(i(r)(c(f,l)))(c(l,d))}}return c(0,a.length)}}}}}})(),qh=t=>t,zr={traverse:t=>{const e=t.Apply0();return Oh(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>zr.traverse(t)(qh),Functor0:()=>ah,Foldable1:()=>zt},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 $h=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},Wh=function(t,e){for(var n=[],r=0,o=0;o<t;o++)n[r++]=e;return n};const Yh=typeof Array.prototype.fill=="function"?$h:Wh,qt=(function(){function t(o,i){this.head=o,this.tail=i}var e={};function n(o){return function(i){return new t(o,i)}}function r(o){for(var i=[],s=0,u=o;u!==e;)i[s++]=u.head,u=u.tail;return i}return function(o,i){return r(o(n)(e)(i))}})(),Mt=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},hg=function(t,e,n,r){for(var o=0;o<r.length;o++){var i=n(r[o]);if(e(i))return i}return t},Mr=function(t,e,n,r){for(var o=0,i=r.length;o<i;o++)if(n(r[o]))return t(o);return e},pg=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)},mg=function(t,e,n,r){if(n<0||n>=r.length)return e;var o=r.slice();return o.splice(n,1),t(o)},Tr=function(t,e,n,r,o){if(n<0||n>=o.length)return e;var i=o.slice();return i[n]=r,t(i)},ge=function(t){return t.slice().reverse()},un=function(t){if(t.length<=1e4)return Array.prototype.concat.apply([],t);for(var e=[],n=0,r=t.length;n<r;n++)for(var o=t[n],i=0,s=o.length;i<s;i++)e.push(o[i]);return e},at=function(t,e){return e.filter(t)},Vh=function(t,e,n){for(var r=n.length,o=e,i=new Array(r),s=0;s<r;s++)o=t(o)(n[s]),i[s]=o;return i},Uh=(function(){function t(e,n,r,o,i,s){var u,a,c,f,d,l,_;for(u=i+(s-i>>1),u-i>1&&t(e,n,o,r,i,u),s-u>1&&t(e,n,o,r,u,s),a=i,c=u,f=i;a<u&&c<s;)d=o[a],l=o[c],_=n(e(d)(l)),_>0?(r[f++]=l,++c):(r[f++]=d,++a);for(;a<u;)r[f++]=o[a++];for(;c<s;)r[f++]=o[c++]}return function(e,n,r){var o;return r.length<2?r:(o=r.slice(0),t(e,n,o,r.slice(0),0,r.length),o)}})(),Gt=function(t,e,n){return n.slice(t,e)},Ie=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},Ye=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},yg=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Dt=t=>e=>Uh(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),Xh=t=>e=>Dt(n=>r=>t.compare(e(n))(e(r))),Pt=t=>e=>(()=>{const n=Ih(e);return()=>{const r=[...t];return n(r)(),r}})()(),Hr=t=>{if(t.length===0)return t.length-1|0,N;const e=t.length-1|0;return e>=0&&e<t.length?v("Just",{init:Gt(0,t.length-1|0,t),last:t[e]}):N},Kh=t=>e=>n=>t>=0&&t<n.length?Tr(ne,N,t,e(n[t]),n):N,Fn=t=>e=>{const n=(r=>{let o=r,i=!0,s;for(;i;){const u=o;if(u>=0&&u<e.length){if(t(e[u])){o=u+1|0;continue}i=!1,s=v("Just",u);continue}i=!1,s=N}return s})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:Gt(0,n._1,e),rest:Gt(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};g()},ho=t=>e=>{const n=Dt(r=>o=>t(r._2)(o._2))(Yt(En)(e));return 0<n.length?$(Qi)(Xh(nt)(Fi)((()=>{const r=[n[0]];for(const o of n){const i=t((()=>{const s=r.length-1|0;if(s>=0&&s<r.length)return r[s]._2;g()})())(o._2);(i==="LT"||i==="GT"||i!=="EQ")&&r.push(o)}return r})())):[]},jh=t=>e=>{const n=[],r=Ah(o=>o>=0&&o<e.length?v("Just",e[o]):N,{value:0});return Bh(r)(o=>()=>{const i=[];i.push(o),Dh(t(o))(r)(i)(),n.push(i)})(),n},oe=t=>e=>{const n=Mr(ne,N,t,e);return n.tag==="Just"?v("Just",e[n._1]):N},Hu=t=>e=>at(t,e),Ve=t=>e=>n=>{const r=Mr(ne,N,o=>t.eq(o)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},xg=t=>e=>Lt(e)(t),xt=t=>xg(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];g()}),Jg=isFinite;function Zh(t,e,n,r){var o=parseFloat(t);return e(o)?n(o):r}const zn=Math.abs,tp=Math.acos,Or=function(t){return function(e){return Math.atan2(t,e)}},zi=Math.ceil,mn=Math.cos,po=Math.exp,bn=Math.floor,Mi=Math.log,ep=function(t){return function(e){return Math.min(t,e)}},Ou=function(t){return function(e){return Math.pow(t,e)}},Gn=Math.round,an=Math.sin,Fe=Math.sqrt,np=Math.tan,rp=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},Z=function(t){return t},op=(function(t){return function(e){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var o=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(i){if(o.test(i)){var s=parseInt(i,n);return(s|0)===s?t(s):e}else return e}}}})(ne)(N)(10),Ng=rp(ne)(N),fe=t=>{if(!Jg(t))return 0;if(t>=Z(2147483647))return 2147483647;if(t<=Z(-2147483648))return-2147483648;const e=Ng(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;g()},Xt=(t,e,n)=>({tag:t,_1:e,_2:n}),Ht=Xt("Nil"),ue={foldr:t=>e=>{const n=ue.foldl(o=>i=>t(i)(o))(e),r=(o=>i=>{let s=o,u=i,a=!0,c;for(;a;){const f=s,d=u;if(d.tag==="Nil"){a=!1,c=f;continue}if(d.tag==="Cons"){s=Xt("Cons",d._1,f),u=d._2;continue}g()}return c})(Ht);return o=>n(r(o))},foldl:t=>e=>n=>{let r=e,o=n,i=!0,s;for(;i;){const u=r,a=o;if(a.tag==="Nil"){i=!1,s=u;continue}if(a.tag==="Cons"){r=t(u)(a._1),o=a._2;continue}g()}return s},foldMap:t=>{const e=t.mempty;return n=>ue.foldl(r=>{const o=t.Semigroup0().append(r);return i=>o(n(i))})(e)}},ip=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var s=[],u=i;;){var a=o(u);s.push(n(a));var c=r(a);if(t(c))return s;u=e(c)}}}}}}},sp=t=>{if(t.tag==="Just")return t._1;g()},up={unfoldr1:ip(cg)(sp)(Fi)(Qi)},ap=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var s=[],u=i;;){var a=o(u);if(t(a))return s;var c=e(a);s.push(n(c)),u=r(c)}}}}}}},cp=t=>{if(t.tag==="Just")return t._1;g()},nn={unfoldr:ap(cg)(cp)(Fi)(Qi),Unfoldable10:()=>up},Kt=(t,e,n,r,o,i,s)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:s}),rn=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Hi=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),wg=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),D=Kt("Leaf"),Pn=rn("IterLeaf"),xe=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return Kt("Node",1,1,t,e,n,r);if(r.tag==="Node")return Kt("Node",1+r._1|0,1+r._2|0,t,e,n,r);g()}if(n.tag==="Node"){if(r.tag==="Leaf")return Kt("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return Kt("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,t,e,n,r)}g()},qe=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?Kt("Node",1,1,t,e,D,D):r.tag==="Node"&&r._1>1?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;g()})()?xe(r._5._3,r._5._4,xe(t,e,n,r._5._5),xe(r._3,r._4,r._5._6,r._6)):xe(r._3,r._4,xe(t,e,n,r._5),r._6):xe(t,e,n,r);if(n.tag==="Node")return r.tag==="Node"?r._1>(n._1+1|0)?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;g()})()?xe(r._5._3,r._5._4,xe(t,e,n,r._5._5),xe(r._3,r._4,r._5._6,r._6)):xe(r._3,r._4,xe(t,e,n,r._5),r._6):n._1>(r._1+1|0)?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?xe(n._6._3,n._6._4,xe(n._3,n._4,n._5,n._6._5),xe(t,e,n._6._6,r)):xe(n._3,n._4,n._5,xe(t,e,n._6,r)):xe(t,e,n,r):r.tag==="Leaf"&&n._1>1?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?xe(n._6._3,n._6._4,xe(n._3,n._4,n._5,n._6._5),xe(t,e,n._6._6,r)):xe(n._3,n._4,n._5,xe(t,e,n._6,r)):xe(t,e,n,r);g()},mo=(t,e,n)=>{if(n.tag==="Leaf")return Hi(N,D,D);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const o=mo(t,e,n._5);return Hi(o._1,o._2,qe(n._3,n._4,o._3,n._6))}if(r==="GT"){const o=mo(t,e,n._6);return Hi(o._1,qe(n._3,n._4,n._5,o._2),o._3)}if(r==="EQ")return Hi(v("Just",n._4),n._5,n._6)}g()},vg=(t,e,n,r)=>{if(r.tag==="Leaf")return wg(t,e,n);if(r.tag==="Node"){const o=vg(r._3,r._4,r._5,r._6);return wg(o._1,o._2,qe(t,e,n,o._3))}g()},yo=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=vg(t._3,t._4,t._5,t._6);return qe(n._1,n._2,n._3,e)}g()},or=(t,e,n)=>{if(e.tag==="Leaf")return D;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=mo(t,n._3,e);return yo(or(t,r._2,n._5),or(t,r._3,n._6))}g()},Oi=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return D;if(r.tag==="Node"){const o=mo(t,r._3,n),i=Oi(t,e,o._2,r._5),s=Oi(t,e,o._3,r._6);if(o._1.tag==="Just")return qe(r._3,e(o._1._1)(r._4),i,s);if(o._1.tag==="Nothing")return yo(i,s)}g()},ze=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const o=mo(t,r._3,n),i=ze(t,e,o._2,r._5),s=ze(t,e,o._3,r._6);if(o._1.tag==="Just")return qe(r._3,e(o._1._1)(r._4),i,s);if(o._1.tag==="Nothing")return qe(r._3,r._4,i,s)}g()},Tg=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return D;if(o.tag==="Node"){const i=t.compare(n)(o._3);if(i==="LT")return qe(o._3,o._4,r(o._5),o._6);if(i==="GT")return qe(o._3,o._4,o._5,r(o._6));if(i==="EQ"){const s=e(o._4);if(s.tag==="Nothing")return yo(o._5,o._6);if(s.tag==="Just")return Kt("Node",o._1,o._2,o._3,s._1,o._5,o._6)}}g()};return r},gp=t=>e=>{const n=r=>{if(r.tag==="Leaf")return D;if(r.tag==="Node"){const o=e(r._3)(r._4);if(o.tag==="Just")return qe(r._3,o._1,n(r._5),n(r._6));if(o.tag==="Nothing")return yo(n(r._5),n(r._6))}g()};return n},In=(t=>e=>n=>{let r=n,o=!0,i;for(;o;){const s=r;if(s.tag==="IterLeaf"){o=!1,i=e();continue}if(s.tag==="IterEmit"){o=!1,i=t(s._1,s._2,s._3);continue}if(s.tag==="IterNode"){r=(u=>a=>{let c=u,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Leaf"){d=!1,l=_;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){c=rn("IterEmit",h._3,h._4,_),f=h._5;continue}c=rn("IterEmit",h._3,h._4,rn("IterNode",h._6,_)),f=h._5;continue}g()}return l})(s._2)(s._1);continue}g()}return i})((t,e,n)=>v("Just",k(k(t,e),n)))(t=>N),It=t=>e=>n=>r=>{const o=i=>{if(i.tag==="Leaf")return Kt("Node",1,1,n,r,D,D);if(i.tag==="Node"){const s=t.compare(n)(i._3);if(s==="LT")return qe(i._3,i._4,o(i._5),i._6);if(s==="GT")return qe(i._3,i._4,i._5,o(i._6));if(s==="EQ")return Kt("Node",i._1,i._2,n,e(i._4)(r),i._5,i._6)}g()};return o},j=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return Kt("Node",1,1,e,n,D,D);if(o.tag==="Node"){const i=t.compare(e)(o._3);if(i==="LT")return qe(o._3,o._4,r(o._5),o._6);if(i==="GT")return qe(o._3,o._4,o._5,r(o._6));if(i==="EQ")return Kt("Node",o._1,o._2,e,n,o._5,o._6)}g()};return r},ae=t=>e=>e.foldl(n=>r=>j(t)(r._1)(r._2)(n))(D),xo=t=>e=>{const n=r=>{if(r.tag==="Leaf")return D;if(r.tag==="Node"){const o=t.compare(e)(r._3);if(o==="LT")return qe(r._3,r._4,n(r._5),r._6);if(o==="GT")return qe(r._3,r._4,r._5,n(r._6));if(o==="EQ")return yo(r._5,r._6)}g()};return n},bg=t=>{const e=t.compare;return n=>r=>o=>{const i=mo(e,r,o),s=n(i._1);if(s.tag==="Nothing")return yo(i._2,i._3);if(s.tag==="Just")return qe(r,s._1,i._2,i._3);g()}},pe=function(t){return function(e){return t+e|0}},Jo=function(t){return function(e){return t+e}},br=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},fp=function(t){return function(e){return t+e}},_e=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},_p={append:fp},dp={append:_e},lp={mempty:"",Semigroup0:()=>_p},hp={mempty:[],Semigroup0:()=>dp},pp=null;function kg(t,e,n){return t==null?e:n(t)}function cC(t){return t}function qu(t){return function(e){return function(n){return t.apply(n,[e])}}}const mp=qu(Number.prototype.toPrecision),yp=qu(Number.prototype.toFixed),xp=qu(Number.prototype.toExponential),No=(t,e)=>({tag:t,_1:e}),wo=t=>e=>n=>{const r=nt.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=nt.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},vo=t=>{if(t.tag==="Precision")return mp(t._1);if(t.tag==="Fixed")return yp(t._1);if(t.tag==="Exponential")return xp(t._1);g()},Lg=function(t){return function(){console.log(t)}};function Jp(){return Date.now()}function Cg(t){return function(){return t.getContext("2d")}}function Sg(t){return function(){return t.width}}function Eg(t){return function(){return t.height}}function Gg(t){return function(e){return function(){t.width=e}}}function Pg(t){return function(e){return function(){t.height=e}}}function $u(t){return function(e){return function(){t.lineWidth=e}}}function Np(t){return function(e){return function(){t.fillStyle=e}}}function wp(t){return function(e){return function(){t.strokeStyle=e}}}function Wu(t){return function(e){return function(){t.lineCap=e}}}function Yu(t){return function(e){return function(){t.lineJoin=e}}}function vp(t){return function(e){return function(){t.globalCompositeOperation=e}}}function Tp(t){return function(e){return function(){t.globalAlpha=e}}}function Ig(t){return function(){t.beginPath()}}function Vu(t){return function(){t.stroke()}}function Uu(t){return function(){t.fill()}}function bp(t){return function(){t.clip()}}function Uo(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function Ag(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function Dg(t){return function(){t.closePath()}}function kp(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function Lp(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function Xo(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function Xu(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function Cp(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function Sp(t){return function(e){return function(){t.textAlign=e}}}function Ep(t){return function(e){return function(){t.textBaseline=e}}}function Gp(t){return function(e){return function(){t.font=e}}}function Pp(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function ir(t){return function(){t.save()}}function sr(t){return function(){t.restore()}}function Ko(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function Ip(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const Bg=t=>t,Ku=t=>t,ju=t=>t,Zu=t=>t,qi=t=>t,Ap=qi("BaselineTop"),Dp=qi("BaselineMiddle"),Bp=qi("BaselineAlphabetic"),Rp=qi("BaselineBottom"),Qp=Zu("AlignLeft"),Fp=Zu("AlignRight"),zp=Zu("AlignCenter"),ta=ju("BevelJoin"),$i=ju("RoundJoin"),ea=ju("MiterJoin"),na=Ku("Round"),ra=Ku("Square"),oa=Ku("Butt"),Mp=Bg("SourceOver"),Hp=Bg("Difference"),Op=t=>e=>Ep(t)((()=>{if(e==="BaselineTop")return"top";if(e==="BaselineHanging")return"hanging";if(e==="BaselineMiddle")return"middle";if(e==="BaselineAlphabetic")return"alphabetic";if(e==="BaselineIdeographic")return"ideographic";if(e==="BaselineBottom")return"bottom";g()})()),qp=t=>e=>Sp(t)((()=>{if(e==="AlignLeft")return"left";if(e==="AlignRight")return"right";if(e==="AlignCenter")return"center";if(e==="AlignStart")return"start";if(e==="AlignEnd")return"end";g()})()),Wi=t=>e=>{if(e==="BevelJoin")return Yu(t)("bevel");if(e==="RoundJoin")return Yu(t)("round");if(e==="MiterJoin")return Yu(t)("miter");g()},ia=t=>e=>{if(e==="Round")return Wu(t)("round");if(e==="Square")return Wu(t)("square");if(e==="Butt")return Wu(t)("butt");g()},Rg=t=>e=>vp(t)((()=>{if(e==="SourceOver")return"source-over";if(e==="SourceIn")return"source-in";if(e==="SourceOut")return"source-out";if(e==="SourceAtop")return"source-atop";if(e==="DestinationOver")return"destination-over";if(e==="DestinationIn")return"destination-in";if(e==="DestinationOut")return"destination-out";if(e==="DestinationAtop")return"destination-atop";if(e==="Lighter")return"lighter";if(e==="Copy")return"copy";if(e==="Xor")return"xor";if(e==="Multiply")return"multiply";if(e==="Screen")return"screen";if(e==="Overlay")return"overlay";if(e==="Darken")return"darken";if(e==="Lighten")return"lighten";if(e==="ColorDodge")return"color-dodge";if(e==="ColorBurn")return"color-burn";if(e==="HardLight")return"hard-light";if(e==="SoftLight")return"soft-light";if(e==="Difference")return"difference";if(e==="Exclusion")return"exclusion";if(e==="Hue")return"hue";if(e==="Saturation")return"saturation";if(e==="Color")return"color";if(e==="Luminosity")return"luminosity";g()})()),Qg={foldrWithIndex:t=>e=>{const n=_o(o=>{const i=o._1,s=o._2;return u=>t(i)(s)(u)})(e),r=Yt(En);return o=>n(r(o))},foldlWithIndex:t=>e=>{const n=w(o=>i=>t(i._1)(o)(i._2))(e),r=Yt(En);return o=>n(r(o))},foldMapWithIndex:t=>{const e=t.mempty;return n=>Qg.foldrWithIndex(r=>o=>i=>t.Semigroup0().append(n(r)(o))(i))(e)},Foldable0:()=>zt},on={foldr:t=>e=>{const n=ue.foldr(t)(e);return r=>n((()=>{const o=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return o(i._5,Xt("Cons",i._3,o(i._6,s)));g()};return o(r,Ht)})())}},$p=t=>{const e={append:(()=>{const n=t.compare;return r=>o=>ze(n,Qe,r,o)})()};return{mempty:D,Semigroup0:()=>e}},jo=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},kr=function(t){return t.join("")},ur=function(t){return t.split("")},Zo=function(t){return t},Mn=function(t){return t.length},Fg=function(t){return function(e){return e.substr(0,t)}},To=function(t){return function(e){return e.substring(t)}},zg=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},Wp=t=>e=>{const n=zg(Mn(e)-Mn(t)|0)(e);return n.after===t?v("Just",n.before):N},bo=t=>e=>{const n=zg(Mn(t))(e);return n.before===t?v("Just",n.after):N},Yp=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},Vp=function(t){return t()},Up=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},Xp=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},qr=t=>BigInt(t),Kp=t=>Number(t),Yi=t=>e=>t+e,Vi=t=>e=>t*e,sa=t=>e=>t-e,Mg=0n,Ui=1n,Hg=t=>e=>t^e,ti=t=>e=>t&e,ua=t=>e=>t<<e,aa=t=>e=>t>>e,jp=t=>e=>t==e,Zp=t=>e=>t===e?0:t>e?1:-1,t0={eq:jp},Og={compare:t=>e=>{const n=Zp(t)(e);return n===1?Ce:n===0?Oe:Le},Eq0:()=>t0},e0=Up(ne)(N),n0=Xp(ne)(N),r0=function(t){throw new Error(t)},qg=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=rt.compare(e._1)(n._1);return r==="LT"?Le:r==="GT"?Ce:rt.compare(e._2)(n._2)},Eq0:()=>t}})(),o0=t=>e=>zn(t._1-e._1)+zn(t._2-e._2),$r=t=>t,Xi=t=>t,we=Xi("North"),ve=Xi("South"),ar=Xi("East"),cr=Xi("West"),Lr=$r("Rectangle"),i0=$r("Cylinder"),s0=$r("Parallelogram"),u0=$r("Diamond"),a0=$r("Ellipse"),c0=$r("Document"),g0=$r("Cloud"),$g=w(Jo)(0),f0=t=>e=>n=>{const r=rt.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=rt.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Cr=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ki=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Wg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},_0=t=>{const e={top:0,bottom:0,left:0,right:0},n=t.shape==="Cloud"?{...e,top:t.h*.38}:t.shape==="Cylinder"?{...e,bottom:5}:t.shape==="Document"?{...e,bottom:t.h*.05}:e;return[{x:t.x-n.left,y:t.y-n.top},{x:t.x+t.w+n.right,y:t.y+t.h+n.bottom}]},ei=t=>e=>{const n=Ie(s=>u=>({a:s,b:u,len:(()=>{const a=u.y-s.y,c=u.x-s.x;return Fe(c*c+a*a)})()}),t,Gt(1,t.length,t)),r=$g($(s=>s.len)(n)),o=f0(0)(r)(e*r),i=s=>u=>a=>{let c=s,f=u,d=a,l=!0,_;for(;l;){const h=c,p=f,m=d,x=Mt(J=>N,J=>y=>v("Just",{head:J,tail:y}),h);if(x.tag==="Nothing"){const J=t.length-1|0;if(J>=0&&J<t.length){l=!1,_=t[J];continue}l=!1,_=m;continue}if(x.tag==="Just"){if(p<=x._1.head.len){const J=x._1.head.len<=0?0:p/x._1.head.len;l=!1,_={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}c=x._1.tail,f=p-x._1.head.len,d=m;continue}g()}return _};return 0<t.length?v("Just",i(n)(o)(t[0])):N},d0=t=>e=>{const n=Cr(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}},ji=t=>$g(Ie(e=>n=>{const r=n.y-e.y,o=n.x-e.x;return Fe(o*o+r*r)},t,Gt(1,t.length,t))),l0=t=>e=>{const n=Cr(4)(.15*Ki(e.w)(e.h)),r=Cr(1)(t.w),o=Cr(1)(t.h),i=Cr(1)(e.w-2*n),s=Cr(1)(e.h-2*n),u=Ki(i/r)(s/o);return{scale:u,tx:e.x+n+(i-r*u)/2-t.x*u,ty:e.y+n+(s-o*u)/2-t.y*u}},ca={scale:1,tx:0,ty:0},Se=t=>{const e=Mt(n=>N,n=>r=>v("Just",{head:n,tail:r}),[...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Xt("Cons",r._4,n(r._6,o)));g()};return Lt(qt(ue.foldr,n(t.nodes,Ht)))(_0)})(),...un((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Xt("Cons",r._4,n(r._6,o)));g()};return qt(ue.foldr,n(t.edges,Ht))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=w(r=>o=>({minX:Ki(r.minX)(o.x),minY:Ki(r.minY)(o.y),maxX:Cr(r.maxX)(o.x),maxY:Cr(r.maxY)(o.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},h0=t=>e=>(n=>r=>o=>{let i=n,s=r,u=o,a=!0,c;for(;a;){const f=i,d=s,l=u,_=Mt(h=>N,h=>p=>v("Just",{head:h,tail:p}),d);if(_.tag==="Nothing"){a=!1,c=l;continue}if(_.tag==="Just"){const h=Wg(_._1.head)(f.interiors);if(h.tag==="Nothing"){a=!1,c=l;continue}if(h.tag==="Just"){i=h._1,s=_._1.tail,u=(()=>{const p=l0(Se(h._1.layout))((()=>{const m=Wg(_._1.head)(f.layout.nodes);if(m.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:Lr};if(m.tag==="Just")return m._1;g()})());return{scale:l.scale*p.scale,tx:l.scale*p.tx+l.tx,ty:l.scale*p.ty+l.ty}})();continue}}g()}return c})(t)(e)(ca),p0=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},m0=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Zi=t=>e=>n=>{const r=rt.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=rt.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},y0=t=>e=>n=>r=>{const o=Se(e);return n<=0||r<=0||o.w<=0||o.h<=0?1:t?p0(o.w/n)(o.h/r):m0(o.w/n)(o.h/r)},Yg=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;if(t.widthPx<=0||t.heightPx<=0){const s=1/Zi(.05)(1)(e);return{w:n.w*s,h:n.h*s}}if(r>o){const s=1/Zi(.05)(1)(e);return{w:n.h*r*s,h:n.h*s}}const i=1/Zi(.05)(1)(e);return{w:n.w*i,h:n.w/r*i}},Vg=t=>e=>n=>r=>o=>{const i=t+o/2,s=t+e-o/2,u=t+e/2,a=n+r/2;return o>=e?u:Zi(i)(s)(a)},Ug=t=>e=>n=>r=>{const o=Se(t);return{x:Vg(o.x)(o.w)(e.x)(e.w)(n),y:Vg(o.y)(o.h)(e.y)(e.h)(r)}},Xg=t=>e=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:y0(t)(e)(n.w)(n.h)}),x0=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=Yg(e)(.65)(o),s=Ug(n)(o)(i.w)(i.h),u={x:s.x-i.w/2,y:s.y-i.h/2,w:i.w,h:i.h};return{focus:r,paddedFocus:o,viewport:u,camera:Xg(e.widthPx>0&&e.heightPx>0)(n)(u)}},J0=t=>e=>n=>r=>o=>i=>{const s=Se(r),u={x:s.x*o.scale+o.tx,y:s.y*o.scale+o.ty,w:s.w*o.scale,h:s.h*o.scale},a=t.padding*o.scale,c={x:u.x-a,y:u.y-a,w:u.w+a*2,h:u.h+a*2},f=Yg(e)(.7)(c),d=Ug(n)(c)(f.w)(f.h),l={x:d.x-f.w/2,y:d.y-f.h/2,w:f.w,h:f.h};return{footprint:u,viewport:l,camera:Xg(e.widthPx>0&&e.heightPx>0)(n)(l)}},Kg=t=>t,N0=(t,e)=>({tag:t,_1:e}),ga=t=>t,ni=(t,e)=>({tag:t,_1:e}),fa=(t,e)=>({tag:t,_1:e}),ri=ga("Animated"),w0=ga("StaticStill"),v0=ga("TitleCard"),T0=fa("First"),jg=Kg("Forward"),Zg=Kg("Backward"),b0=ni("ExitNode"),tf=ae(I)(zt),k0=t=>_o(e=>n=>({nodes:ze(I.compare,Qe,e.nodes,n.nodes),edges:ze(I.compare,Qe,e.edges,n.edges)}))({nodes:D,edges:D})(t.keyframes),L0=t=>e=>({entering:{nodes:or(I.compare,e.nodes,t.nodes),edges:or(I.compare,e.edges,t.edges)},leaving:{nodes:or(I.compare,t.nodes,e.nodes),edges:or(I.compare,t.edges,e.edges)},surviving:{nodes:Oi(I.compare,Qe,t.nodes,e.nodes),edges:Oi(I.compare,Qe,t.edges,e.edges)}}),ts=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ko=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},es=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}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 s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},C0=w(t=>e=>j(I)(e)()(t))(D),S0=w(t=>e=>j(I)(e)()(t))(D),E0=(()=>{const t=nn.unfoldr(In);return e=>t(rn("IterNode",e,Pn))})(),ef=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},nf=ae(I)(zt),rf=t=>{const e=Mt(n=>N,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=w(r=>o=>({minX:ts(r.minX)(o.x),minY:ts(r.minY)(o.y),maxX:ko(r.maxX)(o.x),maxY:ko(r.maxY)(o.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},G0=t=>e=>n=>C0(Lt(qt(on.foldr,n))(r=>{const o=es(r)(t);if(o.tag==="Just")return at(i=>!_a(i)(e),[o._1.source,o._1.target]);if(o.tag==="Nothing")return[];g()})),P0=t=>t.kind.tag==="SendToken"?v("Just",k(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):N,I0=t=>t.tag==="DataFlow"?xt(P0)(t._1.events):[],A0=t=>e=>S0(xt(n=>_a(n._2.source)(e)||_a(n._2.target)(e)?v("Just",n._1):N)(E0(t))),Wr=t=>{const e=Mt(n=>N,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=w(r=>o=>({minX:ts(r.minX)(o.x),minY:ts(r.minY)(o.y),maxX:ko(r.maxX)(o.x+o.w),maxY:ko(r.maxY)(o.y+o.h)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x+e._1.head.w,maxY:e._1.head.y+e._1.head.h})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},da=t=>e=>n=>{if(n.tag==="Leaf")return Se(t);const r=A0(e)(n),o=[...xt(i=>{const s=ef(i)(t.nodes);return s.tag==="Just"?v("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):N})(qt(on.foldr,ze(I.compare,Qe,n,G0(e)(n)(r)))),...xt(i=>{const s=es(i)(t.edges);return s.tag==="Just"?v("Just",rf(s._1)):N})(qt(on.foldr,r))];return o.length===0?Se(t):Wr(o)},of=t=>e=>n=>{const r=[...xt(o=>o)([(()=>{const o=es(n)(t.edges);return o.tag==="Just"?v("Just",rf(o._1)):N})()]),...(()=>{const o=es(n)(e);if(o.tag==="Just")return xt(i=>{const s=ef(i)(t.nodes);return s.tag==="Just"?v("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):N})([o._1.source,o._1.target]);if(o.tag==="Nothing")return[];g()})()];return r.length===0?da(t)(e)(D):Wr(r)},ns=t=>e=>{const n=Se(t),r=n.w/ko(1e-4)(e.zoom),o=n.h/ko(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-o/2,w:r,h:o}},D0=t=>ze(I.compare,Qe,nf($(e=>k(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),nf(Lt(t.scenes)(I0))),rs=t=>t,B0=t=>t,la=rs("Linear"),R0=rs("EaseInOutQuad"),Sr=rs("EaseInOutCubic"),Q0=rs("SpringBouncy"),oi=t=>e=>n=>{const r=Fe(1-e*e),o=t*r;return 1-po(-e*t*n)*(mn(o*n)+e/r*an(o*n))},F0=t=>{const e=rt.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=rt.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},gr=t=>e=>(()=>{if(t==="Linear")return B0;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-Ou(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*po(-6*n);if(t==="SpringBouncy")return oi(6)(.7);g()})()(F0(e)),os=t=>t,sf=t=>t,uf=t=>t,Hn=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Lo=t=>e=>n=>{const r=rt.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=rt.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},af=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},z0=t=>e=>{const n=nt.compare(t._1)(e._1);return n==="LT"?Le:n==="GT"?Ce:rt.compare(t._2)(e._2)},M0=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},H0=uf("Hold"),O0=uf("Gap"),is=sf("LinearLerp"),cf=sf("StagedLogLerp"),ha=os("Overview"),q0=os("DiveHome"),gf=os("DiveTransition"),$0=os("ActionFocus"),W0=t=>e=>{const n=Se(t),r=n.h/Hn(1e-6)(e.zoom),o=n.w/Hn(1e-6)(e.zoom);return{x:e.center.x-o/2,y:e.center.y-r/2,w:o,h:r}},Y0=t=>e=>n=>{const r=n.center.y-e.center.y,o=n.center.x-e.center.x,i=Fe(o*o+r*r),s=n.zoom-e.zoom,u=s<0?-s:s;return Lo(t.minTransition)(t.maxTransition)(Hn(t.panSpeed<=0?t.minTransition:i/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:u/t.zoomSpeed))},V0=t=>({startT:t.startT,endT:t.endT,fromCam:t.fromCam,toCam:t.toCam,easing:t.easing,interp:t.interp,intent:t.intent}),U0=w(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:Pt(t)(e)})([]),X0=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})()})()})()},K0=t=>e=>t.tag==="Just"?e.tag==="Just"&&X0(t._1)(e._1):t.tag==="Nothing"&&e.tag==="Nothing",ff=t=>e=>n=>r=>({center:{x:r.center.x*n.scale+n.tx,y:r.center.y*n.scale+n.ty},zoom:r.zoom*Se(t).w/Hn(1e-6)(n.scale*Se(e).w)}),j0=t=>e=>({center:{x:e.center.x*t.scale+t.tx,y:e.center.y*t.scale+t.ty},zoom:e.zoom/Hn(1e-6)(t.scale)}),_f=t=>e=>n=>r=>({center:{x:t.center.x+(e.center.x-t.center.x)*n,y:t.center.y+(e.center.y-t.center.y)*n},zoom:po((()=>{const o=Mi(Hn(1e-6)(t.zoom));return o+(Mi(Hn(1e-6)(e.zoom))-o)*r})())}),Z0=t=>e=>n=>r=>{const o=po(-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:po((()=>{const i=Mi(Hn(1e-6)(r.zoom));return i+(Mi(Hn(1e-6)(n.zoom))-i)*o})())}},tm=t=>e=>n=>e.zoom>=t.zoom?gr(Sr)(Lo(0)(1)((n-.28)/.72)):gr(Sr)(Lo(0)(1)(n/.28)),em=t=>e=>n=>e.zoom>=t.zoom?gr(Sr)(Lo(0)(1)(n/.28)):gr(Sr)(Lo(0)(1)((n-.28)/.72)),nm=t=>e=>n=>_f(t)(e)(em(t)(e)(n))(tm(t)(e)(n)),rm=t=>e=>n=>{const r=n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT),o=gr(n.easing)(Lo(0)(1)(r));if(n.interp==="LinearLerp")return{center:{x:n.fromCam.center.x+(n.toCam.center.x-n.fromCam.center.x)*o,y:n.fromCam.center.y+(n.toCam.center.y-n.fromCam.center.y)*o},zoom:n.fromCam.zoom+(n.toCam.zoom-n.fromCam.zoom)*o};if(n.interp==="LogLerp")return _f(n.fromCam)(n.toCam)(o)(o);if(n.interp==="StagedLogLerp")return nm(n.fromCam)(n.toCam)(r);g()},om={widthPx:0,heightPx:0},im={padding:24,easing:la,minimumReadableLabelPx:24,minimumVisibleLabelPx:5,labelBasePx:11,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:6},ii=t=>e=>n=>r=>o=>{const i=W0(n)(r),s=o.x-t.padding,u=o.y-t.padding;return s>=i.x&&u>=i.y&&s+o.w+t.padding*2<=i.x+i.w&&u+o.h+t.padding*2<=i.y+i.h},sm=t=>e=>n=>r=>o=>Qg.foldlWithIndex(i=>s=>u=>{const a=(()=>{if(u.kind==="Hold"){const c=(()=>{if(u.focus.tag==="Just"){if(u.intent==="ActionFocus"&&ii(t)(e)(n)({center:s.prev.center,zoom:u.toCam.zoom})(u.focus._1))return{...u.toCam,center:s.prev.center};if(u.intent==="ActionFocus")return u.toCam;if(ii(t)(e)(n)(s.prev)(u.focus._1))return s.prev;if(ii(t)(e)(n)({center:s.prev.center,zoom:u.toCam.zoom})(u.focus._1))return{...u.toCam,center:s.prev.center}}return u.toCam})();return{startT:u.startT,endT:u.endT,fromCam:c,toCam:c,easing:u.easing,interp:is,focus:u.focus,intent:u.intent}}if(u.kind==="Gap")return{startT:u.startT,endT:u.endT,fromCam:s.prev,toCam:(()=>{const c=i+1|0,f=Mr(ne,N,d=>d.kind==="Hold",c<1?o:Gt(c,o.length,o));if(f.tag==="Just"){const d=(i+1|0)+f._1|0;return d>=0&&d<o.length?(()=>{if(o[d].focus.tag==="Just")return ii(t)(e)(n)(s.prev)(o[d].focus._1);if(o[d].focus.tag==="Nothing")return!1;g()})()?s.prev:o[d].fromCam:s.prev}if(f.tag==="Nothing")return s.prev;g()})(),easing:u.easing,interp:is,focus:N,intent:u.intent};g()})();return{acc:Pt(s.acc)(a),prev:a.toCam}})({acc:[],prev:r})(o).acc,um=t=>e=>n=>r=>o=>{const i=(u,a)=>af(Y0(t)(u.toCam)(a.toCam))(u.endT-u.startT),s=w(u=>a=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:v("Just",a)};if(u.pending.tag==="Just")return!(a.fromCam.zoom===a.toCam.zoom&&a.fromCam.center.x===a.toCam.center.x&&a.fromCam.center.y===a.toCam.center.y)||(()=>{if(a.focus.tag==="Just")return ii(t)(e)(n)(u.pending._1.toCam)(a.focus._1);if(a.focus.tag==="Nothing")return!1;g()})()||(()=>{const c=u.pending._1.toCam.center.x-a.toCam.center.x;return(c<0?-c<8:c<8)&&(()=>{const f=u.pending._1.toCam.center.y-a.toCam.center.y;return(f<0?-f<8:f<8)&&(()=>{const d=u.pending._1.toCam.zoom-a.toCam.zoom;return d<0?-d<.08:d<.08})()})()})()||i(u.pending._1,a)<=0?{acc:Pt(u.acc)(u.pending._1),pending:v("Just",a)}:{acc:Pt(Pt(u.acc)({...u.pending._1,endT:a.startT-i(u.pending._1,a)}))({startT:a.startT-i(u.pending._1,a),endT:a.startT,fromCam:u.pending._1.toCam,toCam:a.toCam,easing:a.easing,interp:is,focus:a.focus,intent:a.intent}),pending:v("Just",a)};g()})({acc:[],pending:N})(o);if(s.pending.tag==="Nothing")return s.acc;if(s.pending.tag==="Just")return Pt(s.acc)(s.pending._1);g()},am=t=>e=>n=>{const r=e.w+n*2,o=e.h+n*2,i=Se(t);return r<=0||o<=0||i.w<=0||i.h<=0?1:af(i.w/r)(i.h/o)},cm=t=>e=>{if(t.tag==="Just"){if(e.tag==="Just")return v("Just",Wr([t._1,e._1]));if(e.tag==="Nothing")return v("Just",t._1);g()}if(t.tag==="Nothing"){if(e.tag==="Just")return v("Just",e._1);if(e.tag==="Nothing")return N}g()},gm=w(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?v("Just",t[n]):N;return r.tag==="Just"&&r._1.fromCam.zoom===r._1.toCam.zoom&&r._1.fromCam.center.x===r._1.toCam.center.x&&r._1.fromCam.center.y===r._1.toCam.center.y&&e.fromCam.zoom===e.toCam.zoom&&e.fromCam.center.x===e.toCam.center.x&&e.fromCam.center.y===e.toCam.center.y&&(!(r._1.intent==="ActionFocus"||e.intent==="ActionFocus")||(r._1.intent==="Overview"?e.intent==="Overview":r._1.intent==="DiveHome"?e.intent==="DiveHome":r._1.intent==="DiveTransition"?e.intent==="DiveTransition":r._1.intent==="ActionFocus"&&e.intent==="ActionFocus")&&K0(r._1.focus)(e.focus))&&(()=>{const o=r._1.toCam.center.x-e.toCam.center.x;return(o<0?-o<8:o<8)&&(()=>{const i=r._1.toCam.center.y-e.toCam.center.y;return(i<0?-i<8:i<8)&&(()=>{const s=r._1.toCam.zoom-e.toCam.zoom;return s<0?-s<.08:s<.08})()})()})()?Pt((()=>{const o=t.length-1|0;return o<1?[]:Gt(0,o,t)})())({...r._1,endT:e.endT,focus:cm(r._1.focus)(e.focus)}):Pt(t)(e)})([]),fm=t=>{const e=Dt(n=>r=>z0(k((()=>{if(r.intent==="DiveTransition")return 3;if(r.intent==="ActionFocus")return 2;if(r.intent==="DiveHome")return 1;if(r.intent==="Overview")return 0;g()})(),r.startT))(k((()=>{if(n.intent==="DiveTransition")return 3;if(n.intent==="ActionFocus")return 2;if(n.intent==="DiveHome")return 1;if(n.intent==="Overview")return 0;g()})(),n.startT)))(t);return 0<e.length?v("Just",e[0]):N},ss=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:Hn(r)(am(e)(n)(t.padding))}),_m=t=>e=>n=>r=>o=>{const i=ss(t)(n)(Se(n))(0),s=at(a=>a>=0&&a<=r,U0(Dt(rt.compare)([0,r,...Lt(o)(a=>[a.startT,a.endT])]))),u=(a,c)=>Ye(f=>f.priority>=1,at(f=>f.startT<=c&&c<f.endT,o))?x0(t)(e)(n)(Wr(a)).camera:ss(t)(n)(Wr(a))(0);return $(V0)(um(t)(e)(n)(i)(gm(sm(t)(e)(n)(i)(xt(a=>{const c=(a._1+a._2)/2;if(a._2<=a._1)return N;const f=$(d=>d.bbox)(at(d=>d.priority===w(M0)(0)($(l=>l.priority)(at(l=>l.startT<=c&&c<l.endT,o))),at(d=>d.startT<=c&&c<d.endT,o)));return f.length===0?v("Just",{kind:O0,startT:a._1,endT:a._2,fromCam:i,toCam:i,easing:t.easing,focus:N,intent:ha}):v("Just",{kind:H0,startT:a._1,endT:a._2,fromCam:u(f,c),toCam:u(f,c),easing:t.easing,focus:v("Just",Wr(f)),intent:Ye(d=>d.priority>=1,at(d=>d.startT<=c&&c<d.endT,o))?$0:ha})})(Ie(En,s,Gt(1,s.length,s)))))))},df=t=>e=>n=>r=>{const o=fm(at(i=>r>=i.startT&&r<i.endT,n));if(o.tag==="Just")return{camera:rm()(r)(o._1),intent:o._1.intent};if(o.tag==="Nothing"){const i=n.length-1|0;return i>=0&&i<n.length&&r>=n[i].endT?{camera:n[i].toCam,intent:n[i].intent}:{camera:(()=>{const s=ss(t)(e)(Se(e))(0);return 0<n.length?n[0].fromCam:s})(),intent:0<n.length?n[0].intent:ha}}g()};function Er(t){return t.charCodeAt(0)}function lf(t){return String.fromCharCode(t)}const kn=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},si=function(t){return function(e){return e.split(t)}},us=function(t){return t.trim()},fr=function(t){return function(e){return e.join(t)}};var dm=typeof Array.from=="function",lm=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",hm=typeof String.prototype.fromCodePoint=="function",pm=typeof String.prototype.codePointAt=="function";const mm=function(t){return pm?function(e){return e.codePointAt(0)}:t},ym=function(t){return hm?String.fromCodePoint:t},xm=function(t){return function(e){return lm?function(n){for(var r="",o=n[Symbol.iterator](),i=0;i<e;++i){var s=o.next();if(s.done)return r;r+=s.value}return r}:t(e)}},Jm=function(t){return function(e){return dm?function(n){return Array.from(n,e)}:t}},as=t=>{const e=Mn(t);if(e===0)return N;if(e===1)return v("Just",{head:Er(jo(0)(t)),tail:""});const n=Er(jo(1)(t)),r=Er(jo(0)(t));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?v("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:To(2)(t)}):v("Just",{head:r,tail:To(1)(t)})},Nm=t=>{const e=as(t);return e.tag==="Just"?v("Just",k(e._1.head,e._1.tail)):N},wm=t=>nn.unfoldr(Nm)(t),hf=mm(t=>{const e=Er(jo(0)(t));if(55296<=e&&e<=56319&&Mn(t)>1){const n=Er(jo(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),cs=Jm(wm)(hf),pa=t=>Zo(t>=0&&t<=65535?lf(t):t<0?"\0":"\uFFFF"),vm=ym(t=>t<=65535?pa(t):pa(rr(t-65536|0,1024)+55296|0)+pa(br(t-65536|0)(1024)+56320|0)),pf=t=>e=>{if(t<1)return"";const n=as(e);return n.tag==="Just"?vm(n._1.head)+pf(t-1|0)(n._1.tail):e},Ee=xm(pf),Tm=t=>e=>e===""?N:v("Just",hf(e)),bm=t=>t,mf=t=>e=>{const n=e.vw/e.vh,r=e.vh*t,o={...e,vx:e.vx-(r-e.vw)/2,vw:r},i=e.vw/t,s={...e,vy:e.vy-(i-e.vh)/2,vh:i};return t<=0||e.vw<=0||e.vh<=0?e:t>n?o:t<n?s:e},yf=t=>e=>t.width<=0||t.height<=0?e:mf(t.width/t.height)(e),gs=(t,e,n)=>({tag:t,_1:e,_2:n}),km=()=>({tag:"ExtendFromSource"}),fs=(t,e)=>({tag:t,_1:e}),ma=t=>t,_s=(t,e)=>({tag:t,_1:e}),ya=_s("NotYet"),xf=_s("Consumed"),Lm=ma("FromSource"),Jf=ma("FromTarget"),Cm=ma("FromBoth"),Nf=fs("Hidden"),Sm=fs("Visible"),wf=km(),vf=gs("Retracted"),Em=gs("Extended"),Tf=t=>t,xa=(t,e)=>({tag:t,_1:e}),Yr=(t,e,n)=>({tag:t,_1:e,_2:n}),bf=t=>t,Gr=(t,e)=>({tag:t,_1:e}),Co=(t,e,n,r,o,i,s,u,a)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:s,_7:u,_8:a}),ds=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},An=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},kf=ae(I)(zt),Ja=Fu(Vo),So=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},ui=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Na=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},Lf=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Cf=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},Eo=(()=>{const t=nn.unfoldr(e=>{if(e.tag==="Nil")return N;if(e.tag==="Cons")return v("Just",k(e._1,e._2));g()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Xt("Cons",r._3,n(r._6,o)));g()};return n(e,Ht)})())})(),Gm=w(t=>e=>j(I)(e)()(t))(D),wa=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},ls=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Pm=t=>t,Im=Gr("NoKeyframes"),Am=t=>Gr("DuplicateEventId",t),Dm=t=>Gr("UnknownEvent",t),Sf=bf("PlopIn"),Bm=bf("PlopOut"),Rm=Tf("DiveIn"),Qm=Tf("DiveOut"),Fm=t=>e=>n=>xt(r=>{if(r.target.tag==="NodeWindow"||r.target.tag==="EdgeWindow")return N;if(r.target.tag==="TokenWindow")return v("Just",{startT:r.startT,endT:r.endT,bbox:of(e)(n)(r.target._2),priority:1});if(r.target.tag==="FillWindow")return v("Just",{startT:r.startT,endT:r.endT,bbox:da(e)(n)(Kt("Node",1,1,r.target._2,void 0,D,D)),priority:1});g()}),zm=t=>e=>n=>r=>{const o=ds(r.edge)(e.edges),i=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return ji(o._1);g()})(),s=An(t.minTokenDuration)(An(Z(w(u=>a=>u+cs(a).length|0)(0)(r.labels))*t.tokenReadSecPerChar)(t.tokenSpeed<=0?0:i/t.tokenSpeed))+n.pre+n.post;return{duration:s,holdPre:s<=0?0:n.pre/s,holdPost:s<=0?0:n.post/s}},Mm=t=>e=>kf(xt(n=>{if(n.kind.tag==="SendToken")return v("Just",k(n.id,{pre:(()=>{const r=n.when;return(()=>{const o=n.kind._1.from;return Ye(i=>{if(i.kind.tag==="SendToken")return(r.tag==="First"?!1:r.tag==="After"&&r._1===i.id)&&i.kind._1.to===o;if(i.kind.tag==="FillNodeWithoutTransition")return!1;g()},e)})()?0:t.tokenHold})(),post:(()=>{const r=n.id;return(()=>{const o=n.kind._1.to;return Ye(i=>{if(i.kind.tag==="SendToken")return(i.when.tag==="First"?!1:i.when.tag==="After"&&i.when._1===r)&&i.kind._1.from===o;if(i.kind.tag==="FillNodeWithoutTransition")return!1;g()},e)})()?0:t.tokenHold})()}));if(n.kind.tag==="FillNodeWithoutTransition")return N;g()})(e)),Hm=t=>{if(t.event.kind.tag==="SendToken")return v("Just",{startT:t.startT,endT:t.endT,target:Co("TokenWindow",t.event.id,t.event.kind._1.edge,t.event.kind._1.direction,t.event.kind._1.from,t.event.kind._1.to,t.event.kind._1.labels,t.holdPre,t.holdPost)});if(t.event.kind.tag==="FillNodeWithoutTransition")return v("Just",{startT:t.startT,endT:t.endT,target:Co("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},Om=t=>e=>n=>r=>{const o=oe(i=>Ja(i.path)(e)&&(zn(i.endT-n)<1e-4||zn(i.startT-r)<1e-4))(t.segments);if(o.tag==="Just")return v("Just",o._1);if(o.tag==="Nothing")return oe(i=>Ja(i.path)(e))(t.segments);g()},qm=t=>e=>n=>xt(r=>{const o=xt(i=>Na(i)(t.nodes))(qt(on.foldr,(()=>{if(r.scene.tag==="Structural")return ze(I.compare,Qe,(()=>{const i=So(r.scene._1.from)(n);if(i.tag==="Nothing")return D;if(i.tag==="Just")return i._1.nodes;g()})(),(()=>{const i=So(r.scene._1.to)(n);if(i.tag==="Nothing")return D;if(i.tag==="Just")return i._1.nodes;g()})());if(r.scene.tag==="DataFlow"){const i=So(r.scene._1.keyframe)(n);if(i.tag==="Nothing")return D;if(i.tag==="Just")return i._1.nodes;g()}if(r.scene.tag==="Hold"){const i=So(r.scene._1)(n);if(i.tag==="Nothing")return D;if(i.tag==="Just")return i._1.nodes;g()}if(r.scene.tag==="EnterNode"||r.scene.tag==="ExitNode")return D;g()})()));return o.length===0?N:v("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const i=w(s=>u=>({minX:ui(s.minX)(u.x),minY:ui(s.minY)(u.y),maxX:An(s.maxX)(u.x+u.w),maxY:An(s.maxY)(u.y+u.h)}))(0<o.length?{minX:o[0].x,minY:o[0].y,maxX:o[0].x+o[0].w,maxY:o[0].y+o[0].h}:{minX:0,minY:0,maxX:0,maxY:0})(Gt(1,o.length,o));return{x:i.minX,y:i.minY,w:i.maxX-i.minX,h:i.maxY-i.minY}})(),priority:0})}),$m=t=>e=>n=>r=>o=>[...qm(o.layout)(n)(e)(at(i=>i.startT>=o.startT&&i.endT<=o.endT,r.spans)),...Fm()(o.layout)(n)(o.windows)],Wm=t=>e=>n=>r=>o=>i=>_m(t)(e)(i.layout)(o.endT)($m()(n)(r)(o)(i)),Ef=(()=>{const t=w(e=>n=>{const r=e.previous.tag==="Just"&&zn(e.previous._1.endT-n.startT)<1e-4&&!(n.fromCam.zoom===n.toCam.zoom&&n.fromCam.center.x===n.toCam.center.x&&n.fromCam.center.y===n.toCam.center.y)?{...n,fromCam:e.previous._1.toCam}:n;return{previous:v("Just",r),spans:Pt(e.spans)(r)}})({previous:N,spans:[]});return e=>t(e).spans})(),Ym=t=>e=>n=>{const r=ds(n)(t);if(r.tag==="Nothing")return Jf;if(r.tag==="Just"){const o=Lf(r._1.target)(e);return Lf(r._1.source)(e)?o?Cm:Lm:Jf}g()},Vm=t=>e=>{const n=Se(e),r=yf({width:t.widthPx,height:t.heightPx})({vx:n.x,vy:n.y,vw:n.w,vh:n.h});return{w:r.vw,h:r.vh}},Um=t=>e=>n=>r=>{const o=An(n.center.x-r.x)(r.x+r.w-n.center.x),i=An(n.center.y-r.y)(r.y+r.h-n.center.y),s=Vm(t)(e);return ui(o<=0?n.zoom:s.w/(o*2))(i<=0?n.zoom:s.h/(i*2))},Xm={pre:0,post:0},Km=t=>e=>n=>r=>o=>{const i=Cf(o.event.id)(n),s=(()=>{if(i.tag==="Nothing")return Xm;if(i.tag==="Just")return i._1;g()})(),u=(()=>{if(o.event.when.tag==="First")return 0;if(o.event.when.tag==="At")return o.event.when._1;if(o.event.when.tag==="After"){const c=o.event.when._1,f=oe(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.endT;g()}if(o.event.when.tag==="With"){const c=o.event.when._1,f=oe(d=>d.event.id===c)(r);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.startT}g()})(),a=(()=>{if(o.event.kind.tag==="SendToken")return zm(t)(e)(s)(o.event.kind._1);if(o.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return Pt(r)({startT:u,endT:u+a.duration,event:o.event,holdPre:a.holdPre,holdPost:a.holdPost})},Gf=t=>e=>n=>w(Km(t)(e)(Mm(t)(n)))([])(Yt(r=>o=>({event:o}))(n)),va=t=>e=>n=>r=>o=>{const i={width:e.widthPx,height:e.heightPx},s=yf(i)((()=>{const u=ns(n)(o);return{vx:u.x,vy:u.y,vw:u.w,vh:u.h}})());return t.labelBasePx*r.placement.scale*(i.width<=0||s.vw<=0?0:i.width/s.vw)},jm=t=>e=>n=>r=>o=>{const i=va(t)(e)(n)(r)(o);return i<=t.minimumReadableLabelPx?o:{...o,zoom:o.zoom*t.minimumReadableLabelPx/i}},Zm=t=>e=>{const n=Na(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},t2=t=>e=>n=>r=>({...r,fromCam:ff(t)(e)(n)(r.fromCam),toCam:ff(t)(e)(n)(r.toCam)}),e2=t=>e=>n=>r=>o=>i=>{if(o.tag==="Nothing")return i.zoom;if(o.tag==="Just")return An(0)(Um(e)(n)(i)((()=>{const s=t.padding*r.placement.scale;return{x:o._1.x-s,y:o._1.y-s,w:o._1.w+s*2,h:o._1.h+s*2}})()));g()},n2=t=>e=>n=>r=>o=>i=>{const s=va(t)(e)(n)(r)(i);return s<=0?i:{...i,zoom:ui(i.zoom*t.minimumReadableLabelPx/s)(e2(t)(e)(n)(r)(o)(i))}},r2=t=>{if(t.when.tag==="First")return[];if(t.when.tag==="At")return[];if(t.when.tag==="After")return[t.when._1];if(t.when.tag==="With")return[t.when._1];g()},Pf={id:"",nodes:D,edges:D,kind:ri},o2=t=>e=>L0((()=>{const n=So(e.from)(t);if(n.tag==="Nothing")return Pf;if(n.tag==="Just")return n._1;g()})())((()=>{const n=So(e.to)(t);if(n.tag==="Nothing")return Pf;if(n.tag==="Just")return n._1;g()})()),i2=t=>e=>{const n=Na(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:D};if(n.tag==="Just")return n._1;g()},Ta=t=>e=>n=>r=>{const o=ds(r)(n.edges);if(o.tag==="Just")return t<=0?e:An(e)(ji(o._1)/t);if(o.tag==="Nothing")return e;g()},If=t=>e=>n=>r=>o=>{const i=t.plop,s=o2(n)(o),u=$(_=>({startT:0,endT:0+Ta(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Co("EdgeWindow",_,xa("Extend",wf))}))(Eo(s.entering.edges)),a=$(_=>({startT:0,endT:i,target:Co("NodeWindow",_,Sf)}))(Eo(s.entering.nodes)),c=w(An)(0)($(_=>Ta(t.edgeSpeed)(t.minEdgeDuration)(e)(_))(Eo(s.leaving.edges))),f=_=>Ye(h=>{const p=ds(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;g()},Eo(s.leaving.edges))?c:0,d=$(_=>({startT:f(_),endT:f(_)+t.plop,target:Co("NodeWindow",_,Bm)}))(Eo(s.leaving.nodes)),l=$(_=>({startT:0,endT:Ta(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Co("EdgeWindow",_,xa("Retract",Ym(r)(s.leaving.nodes)(_)))}))(Eo(s.leaving.edges));return{duration:(()=>{const _=Dt(rt.compare)([...$(p=>p.endT)(l),...$(p=>p.endT)(d),...$(p=>p.endT)(a),...$(p=>p.endT)(u)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+t.gap:t.gap})(),windows:[...l,...d,...a,...u]}},s2=t=>e=>n=>r=>o=>i=>$((()=>{const s=o.startT;return u=>({...u,startT:u.startT+s,endT:u.endT+s})})())(If(t)(e)(n)(r)(i).windows),u2=t=>xt(e=>qt(_o,e).length>1?v("Just",(()=>{const n=Mt(r=>N,r=>o=>v("Just",{head:r,tail:o}),qt(_o,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):N)(jh(Vo)(Dt(I.compare)(t))),a2=t=>{const e=$(r=>r.id)(t),n=Gm(e);return[...$(Am)(u2(e)),...$(Dm)(at(r=>!wa(r)(n),Lt(t)(r2)))]},c2=t=>{const e=kf($(r=>k(r.id,(()=>{if(r.when.tag==="First")return[];if(r.when.tag==="At")return[];if(r.when.tag==="After")return[r.when._1];if(r.when.tag==="With")return[r.when._1];g()})()))(t)),n=r=>o=>i=>{if(wa(i)(o))return[Gr("ScheduleCycle",[...qt(on.foldr,o),i])];if(wa(i)(r))return[];const s=Cf(i)(e);if(s.tag==="Nothing")return[];if(s.tag==="Just")return Lt(s._1)(n(j(I)(i)()(r))(j(I)(i)()(o)));g()};return Lt(t)(r=>n(D)(D)(r.id))},g2={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:.5,stillHold:1.8,hatchHold:.4,tokenReadSecPerChar:.06,nodeEasing:Q0,edgeEasing:R0,tokenEasing:la,diveDur:1.2,retreatDur:1.2},f2=t=>e=>n=>r=>$((()=>{const o=n.startT;return i=>({...i,startT:i.startT+o,endT:i.endT+o})})())(xt(Hm)(Gf(t)(e)(r.events))),_2=t=>e=>n=>r=>o=>{if(o.scene.tag==="Structural")return s2(t)(e)(n)(r)(o)(o.scene._1);if(o.scene.tag==="Hold")return[];if(o.scene.tag==="DataFlow")return f2(t)(e)(o)(o.scene._1);if(o.scene.tag==="EnterNode")return[];if(o.scene.tag==="ExitNode")return[];g()},d2=t=>e=>n=>{const r=Gf(t)(e)(n.events);return r.length===0?t.gap:w(An)(0)($(o=>o.endT)(r))+t.gap},l2=t=>e=>n=>r=>o=>{if(o.tag==="Structural")return If(t)(e)(n)(r)(o._1).duration;if(o.tag==="Hold")return t.stillHold;if(o.tag==="DataFlow")return d2(t)(e)(o._1);if(o.tag==="EnterNode"||o.tag==="ExitNode")return 0;g()},Af=t=>e=>n=>r=>o=>i=>{const s=h0(e)(r),u=n.layout,a=tf($(p=>k(p.id,p))(o.keyframes)),c=0<o.keyframes.length?v("Just",o.keyframes[0]):N,f=(()=>{if(c.tag==="Just")return c._1.id;if(c.tag==="Nothing")return"";g()})(),d=D0(o),l=p=>({segments:p.runSpans.length===0?p.segments:Pt(p.segments)({startT:p.runStart,endT:p.t,path:r,layout:u,placement:s,windows:p.runWindows,spans:p.runSpans,keyframes:a,initialKeyframe:f,edgeEndpoints:d}),spans:p.spans,windows:p.windows,dives:p.dives}),_=w(p=>m=>{if(m.tag==="EnterNode"){const T=l(p),b=p.t+t.diveDur,C=Pt(r)(m._1),S=Af(t)(e)(i2(n)(m._1))(C)(Zm(o)(m._1))(b),E=S.endT+t.retreatDur;return{...p,t:E,runStart:E,runSpans:[],runWindows:[],segments:[...T.segments,...S.segments],spans:[...T.spans,...S.spans],windows:[...T.windows,...S.windows],dives:[...T.dives,{startT:p.t,endT:b,node:m._1,parentPath:r,childPath:C,direction:Rm},...S.dives,{startT:S.endT,endT:E,node:m._1,parentPath:r,childPath:C,direction:Qm}]}}if(m.tag==="ExitNode")return p;const x=p.t+l2(t)(u)(a)(d)(m),J={startT:p.t,endT:x,scene:m},y=_2(t)(u)(a)(d)(J);return{...p,t:x,runSpans:Pt(p.runSpans)(J),runWindows:[...p.runWindows,...y],spans:Pt(p.spans)(J),windows:[...p.windows,...y]}})({t:i,runStart:i,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(o.scenes),h=l(_);return{endT:_.t,spans:h.spans,windows:Dt(p=>m=>rt.compare(p.startT)(m.startT))(h.windows),segments:h.segments,dives:h.dives}},h2=t=>e=>n=>n.endT<=t||n.startT>=e?N:v("Just",{...n,startT:An(t)(n.startT),endT:ui(e)(n.endT)}),ba=t=>e=>n=>r=>o=>i=>xt(h2(i.startT)(i.endT))($(t2(n)(i.layout)(i.placement))(Wm(t)(e)(r)(i.edgeEndpoints)(o)(i))),ka=t=>e=>n=>r=>J0(t)(e)(n)(r.layout)(r.placement)((()=>{if(r.layout.nodes.tag==="Leaf")return 0;if(r.layout.nodes.tag==="Node")return r.layout.nodes._2;g()})()).camera,p2=t=>e=>n=>r=>r.placement.scale===1&&r.placement.tx===0&&r.placement.ty===0?j0(r.placement)(ss(t)(r.layout)(Se(r.layout))(0)):ka(t)(e)(n)(r),Df=t=>e=>n=>r=>o=>{const i=ns(n)(o);return(()=>{const s=Se(r.layout),u=s.x*r.placement.scale+r.placement.tx,a=s.y*r.placement.scale+r.placement.ty;return u>=i.x&&a>=i.y&&u+s.w*r.placement.scale<=i.x+i.w&&a+s.h*r.placement.scale<=i.y+i.h})()&&va(t)(e)(n)(r)(o)>=t.minimumReadableLabelPx},La=t=>e=>n=>r=>o=>i=>Df(t)(e)(n)(r)(i)?i:n2(t)(e)(n)(r)(o)(i),m2=t=>e=>{if(e.tag==="Structural")return xt(n=>n)([ls(e._1.from)(t)?N:v("Just",Gr("UnknownKeyframe",e._1.from)),ls(e._1.to)(t)?N:v("Just",Gr("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return xt(n=>n)([ls(e._1)(t)?N:v("Just",Gr("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...xt(n=>n)([ls(e._1.keyframe)(t)?N:v("Just",Gr("UnknownKeyframe",e._1.keyframe))]),...a2(e._1.events),...c2(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];g()},y2=t=>e=>{const n=Lt(e)(m2(t));return n.length===0?Rt("Right",void 0):Rt("Left",n)},Ca=t=>e=>n=>r=>o=>i=>Df(t)(e)(n)(r)(o)?o:jm(t)(e)(n)(r)(i),x2=t=>e=>{const n=Mt(r=>N,r=>o=>v("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{...n._1.head,fromCam:t},...n._1.tail];g()},J2=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=xt(o=>o.target.tag==="TokenWindow"?v("Just",of(t.layout)(t.edgeEndpoints)(o.target._2)):o.target.tag==="FillWindow"?v("Just",da(t.layout)(t.edgeEndpoints)(Kt("Node",1,1,o.target._2,void 0,D,D))):N)(at(o=>o.startT<=n&&n<o.endT,t.windows));return r.length===0?N:v("Just",(()=>{const o=Wr(r);return{x:o.x*t.placement.scale+t.placement.tx,y:o.y*t.placement.scale+t.placement.ty,w:o.w*t.placement.scale,h:o.h*t.placement.scale}})())},Bf=t=>e=>n=>r=>o=>i=>{const s=o(i.fromCam),u=o(i.toCam),a=J2(r)(i);return s.zoom===u.zoom&&s.center.x===u.center.x&&s.center.y===u.center.y?{...i,fromCam:La(t)(e)(n)(r)(a)(s),toCam:La(t)(e)(n)(r)(a)(u)}:{...i,fromCam:s,toCam:La(t)(e)(n)(r)(a)(u)}},Rf=t=>e=>n=>r=>o=>i=>i.intent==="ActionFocus"?Bf(t)(e)(n)(r)(Ca(t)(e)(n)(r)(o))(i):{...i,fromCam:Ca(t)(e)(n)(r)(o)(i.fromCam),toCam:Ca(t)(e)(n)(r)(o)(i.toCam)},Qf=t=>e=>n=>r=>o=>i=>{const s=oe(u=>u.intent==="ActionFocus"&&zn(u.startT-r.startT)<1e-4)(i);if(s.tag==="Just"){const u=Rf(t)(e)(n)(r)(o)(s._1).toCam;return u.zoom<o.zoom?{...o,zoom:u.zoom}:o}if(s.tag==="Nothing")return o;g()},N2=t=>e=>n=>r=>o=>Qf(t)(e)(n)(r)(ka(t)(e)(n)(r))(o),w2=t=>e=>n=>r=>o=>xt(i=>{const s=Om(o)(i.parentPath)(i.startT)(i.endT);if(s.tag==="Just"){const u=i.childPath,a=oe(c=>Ja(c.path)(u))(o.segments);if(a.tag==="Just"){const c=p2(t)(e)(n)(s._1),f=N2(t)(e)(n)(a._1)(ba(t)(e)(n)(r)(o)(a._1));if(i.direction==="DiveIn")return v("Just",{startT:i.startT,endT:i.endT,fromCam:c,toCam:f,easing:Sr,interp:cf,intent:gf});if(i.direction==="DiveOut")return v("Just",{startT:i.startT,endT:i.endT,fromCam:f,toCam:c,easing:Sr,interp:cf,intent:gf});g()}if(a.tag==="Nothing")return N;g()}if(s.tag==="Nothing")return N;g()})(o.dives),v2=t=>e=>n=>r=>o=>o.intent==="ActionFocus"?Bf(t)(e)(n)(r)(Pm)(o):o,T2=t=>e=>n=>r=>o=>Dt(i=>s=>rt.compare(i.startT)(s.startT))(Lt(o.segments)(i=>{if(i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0)return Ef($(v2(t)(e)(n)(i))(ba(t)(e)(n)(r)(o)(i)));const s=ba(t)(e)(n)(r)(o)(i),u=ka(t)(e)(n)(i),a=Qf(t)(e)(n)(i)(u)(s);return s.length===0?[{startT:i.startT,endT:i.endT,fromCam:a,toCam:a,easing:la,interp:is,intent:q0}]:Ef(x2(a)($(Rf(t)(e)(n)(i)(u))(s)))})),Ff=t=>e=>n=>r=>o=>[...w2(t)(e)(n)(r)(o),...T2(t)(e)(n)(r)(o)],b2=t=>e=>n=>r=>{if(0<n.keyframes.length){const o=n.keyframes[0],i=tf($(u=>k(u.id,u))(n.keyframes)),s=y2(i)(n.scenes);return(()=>{if(s.tag==="Left"){const u=s._1;return a=>Rt("Left",u)}if(s.tag==="Right"){const u=s._1;return a=>a(u)}g()})()(()=>{const u=Af(e)(r)(r)([])(n)(0);return Rt("Right",{totalDuration:u.endT,windows:u.windows,spans:u.spans,keyframes:i,initialKeyframe:o.id,timing:e,layout:r.layout,cameraSpans:Ff(t)(om)(r.layout)(i)(u),cameraConfig:t,levelTree:r,segments:u.segments,dives:u.dives,seed:n.seed})})}return Rt("Left",[Im])},k2=t=>e=>({...e,cameraSpans:Ff(e.cameraConfig)(t)(e.layout)(e.keyframes)({endT:e.totalDuration,spans:e.spans,windows:e.windows,segments:e.segments,dives:e.dives})}),Sa=t=>t,zf=ae(I)(zt),ai={eq:Fu(Vo)},Ea=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},_r=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Mf=zt.foldMap($p(I)),L2=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},C2=(()=>{const t=nn.unfoldr(In);return e=>t(rn("IterNode",e,Pn))})(),Go=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},S2=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},E2=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},G2=ae(I)(zt),P2=ae(I)(zt),I2=t=>e=>n=>{const r=rt.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=rt.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Hf=Sa("Backdrop"),A2=Sa("FlyThrough"),hs=Sa("Active"),D2=t=>e=>n=>({...n,state:{...n.state,edgeFadeAlpha:zf($(r=>k(r,e))(t))}}),Of=t=>e=>n=>{const r=(t+e)/2,o=n-r,i=o<0?-1:1,s=(e-t)/2,u=s*.15,a=s-u,c=o<0?-o:o;return e<=t?(t+e)/2:c<=a?n:r+i*(s-u*po(-(c-a)/u))},ps=t=>e=>n=>{const r=oe(o=>ai.eq(o.path)(e)&&n>=o.startT&&n<o.endT)(t.segments);if(r.tag==="Just")return v("Just",r._1);if(r.tag==="Nothing")return oe(o=>ai.eq(o.path)(e))(t.segments);g()},B2=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:ca,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:D}),R2=t=>$(e=>e<1?[]:Gt(0,e,t))(Ut(0,t.length-1|0)),Ga=t=>e=>{const n=Ea(e)(t.keyframes);if(n.tag==="Nothing")return D;if(n.tag==="Just")return n._1.nodes;g()},Pa=t=>e=>{const n=Ea(e)(t.keyframes);if(n.tag==="Nothing")return D;if(n.tag==="Just")return n._1.edges;g()},ms=t=>e=>{if(e<t.startT)return Yr("AtKeyframe",t.initialKeyframe);const n=oe(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Yr("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Yr("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return Yr("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return Yr("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;return r>=0&&r<t.spans.length?Yr("AtKeyframe",(()=>{if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="Hold")return t.spans[r].scene._1;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return t.initialKeyframe;g()})()):Yr("AtKeyframe",t.initialKeyframe)}g()},Q2=w(t=>e=>{const n=Hr(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?Pt(n._1.init)({...n._1.last,endT:_r(n._1.last.endT)(e.endT),windows:Pt(n._1.last.windows)(e)}):Pt(t)({endT:e.endT,windows:[e]})})([]),F2=t=>e=>n=>Mf(r=>Mf(o=>o.target.tag==="FillWindow"?o.startT<=n?Kt("Node",1,1,o.target._2,void 0,D,D):D:o.target.tag==="TokenWindow"&&o.startT+(o.endT-o.startT)*.25<=n?Kt("Node",1,1,o.target._4,void 0,D,D):D)(r.windows))(at(r=>n<=r.endT+t,Q2(Dt(r=>o=>rt.compare(r.startT)(o.startT))(at(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),z2=t=>e=>n=>Ye(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),M2=t=>e=>n=>Ye(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),H2=t=>e=>n=>Ye(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),O2=t=>e=>n=>Ye(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),q2=t=>e=>{const n=ms(t)(e);if(n.tag==="AtKeyframe")return Ee(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return Ee(3)(n._2)==="kf-"?"":n._2;g()},$2=t=>e=>{const n=ms(t)(e),r=Ea((()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;g()})())(t.keyframes);if(r.tag==="Just")return r._1.kind;if(r.tag==="Nothing")return ri;g()},qf=t=>e=>n=>oe(r=>n(r)&&e>=r.startT&&e<r.endT)(t),W2={segment:{startT:0,endT:0,path:[],layout:{nodes:D,edges:D,chipExtras:D,edgeLabels:D},placement:ca,windows:[],spans:[],keyframes:D,initialKeyframe:"",edgeEndpoints:D},state:{nodes:D,edges:D,tokens:D,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:ri,visited:D,nodeFadeAlpha:D,nodeLabelFadeAlpha:D,edgeFadeAlpha:D,nodeInvert:D},bgAlpha:1,blur:0,minis:[],role:hs},ys=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:W2},Y2=t=>e=>{const n=L2(e)(t.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1,o=i=>i.x>=r.x-1&&i.x<=r.x+r.w+1&&i.y>=r.y-1&&i.y<=r.y+r.h+1;return xt(i=>(()=>{if(0<i._2.length){const u=i._2.length-1|0;return o(i._2[0])||u>=0&&u<i._2.length&&o(i._2[u])}const s=i._2.length-1|0;return s>=0&&s<i._2.length&&o(i._2[s])})()?v("Just",i._1):N)(C2(t.edges))}g()},V2=t=>e=>{const n=ms(t)(e);if(n.tag==="AtKeyframe")return Ga(t)(n._1);if(n.tag==="InTransition")return ze(I.compare,Qe,Ga(t)(n._1),Ga(t)(n._2));g()},U2=t=>e=>{const n=ms(t)(e);if(n.tag==="AtKeyframe")return Pa(t)(n._1);if(n.tag==="InTransition")return ze(I.compare,Qe,Pa(t)(n._1),Pa(t)(n._2));g()},X2=t=>e=>n=>{const r=Se(t),o=r.h/_r(1e-4)(n.zoom),i=r.w/_r(1e-4)(n.zoom);return{...n,center:{x:i>=e.w?e.x+e.w/2:Of(e.x+i/2)(e.x+e.w-i/2)(n.center.x),y:o>=e.h?e.y+e.h/2:Of(e.y+o/2)(e.y+e.h-o/2)(n.center.y)}}},K2=t=>e=>n=>X2(t)((()=>{const r=e*n.placement.scale,o=Se(n.layout),i=(()=>{const s=o.x*n.placement.scale+n.placement.tx,u=o.y*n.placement.scale+n.placement.ty;return{x:s,y:u,w:(o.x+o.w)*n.placement.scale+n.placement.tx-s,h:(o.y+o.h)*n.placement.scale+n.placement.ty-u}})();return{x:i.x-r,y:i.y-r,w:i.w+r*2,h:i.h+r*2}})()),j2=t=>e=>{const n=t.endT-t.startT;return n<=0?1:_r(0)(Go(1)((e-t.startT)/n))},xs=t=>e=>{const n=t.endT-t.startT;return n<=0?1:_r(0)(Go(1)((e-t.startT)/n))},Z2=t=>e=>n=>r=>o=>{const i=qf(e)(n)(s=>s.target.tag==="EdgeWindow"&&s.target._1===o);if(i.tag==="Just"){const s=gr(t.timing.edgeEasing)(xs(i._1)(n)),u=i._1.target.tag==="EdgeWindow"?i._1.target._2:xa("Extend",wf);if(u.tag==="Retract")return gs("Retracting",u._1,s);if(u.tag==="Extend")return gs("Extending",u._1,s);g()}if(i.tag==="Nothing")return O2(e)(n)(o)||z2(e)(n)(o)?vf:S2(o)(r)?Em:vf;g()},ty=t=>e=>n=>{const r=U2(e)(n);return zf($(o=>k(o,Z2(t)(e.windows)(n)(r)(o)))((()=>{const o=i=>{if(i.tag==="Leaf")return D;if(i.tag==="Node")return Kt("Node",i._1,i._2,i._3,void 0,o(i._5),o(i._6));g()};return qt(on.foldr,o(e.layout.edges))})()))},ey=t=>e=>n=>r=>{const o=qf(t)(e)(i=>i.target.tag==="NodeWindow"&&i.target._1===r);if(o.tag==="Just"){const i=xs(o._1)(e),s=o._1.target.tag==="NodeWindow"?o._1.target._2:Sf;if(s==="PlopIn")return fs("PloppingIn",i);if(s==="PlopOut")return fs("PloppingOut",i);g()}if(o.tag==="Nothing")return H2(t)(e)(r)||M2(t)(e)(r)?Nf:E2(r)(n)?Sm:Nf;g()},ny=t=>e=>n=>{const r=V2(e)(n);return G2($(o=>k(o,ey(e.windows)(n)(r)(o)))((()=>{const o=i=>{if(i.tag==="Leaf")return D;if(i.tag==="Node")return Kt("Node",i._1,i._2,i._3,void 0,o(i._5),o(i._6));g()};return qt(on.foldr,o(e.layout.nodes))})()))},ry=t=>e=>n=>e.target.tag==="TokenWindow"?k(e.target._1,n<e.startT?ya:n>=e.endT?xf:_s("Travelling",{edge:e.target._2,direction:e.target._3,progress:gr(t.timing.tokenEasing)(xs(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"?k(e.target._1,n<e.startT?ya:n>=e.endT?xf:_s("Filling",{node:e.target._2,progress:xs(e)(n),labels:e.target._3})):k("",ya),oy=t=>e=>n=>P2($(r=>ry(t)(r)(n))(at(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),iy=t=>e=>n=>({nodes:ny()(e)(n),edges:ty(t)(e)(n),tokens:oy(t)(e.windows)(n),camera:df(t.cameraConfig)(e.layout)(t.cameraSpans)(n).camera,frameTitle:q2(e)(n),staticKind:$2(e)(n),visited:F2(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:D,nodeLabelFadeAlpha:D,edgeFadeAlpha:D,nodeInvert:D}),Po=t=>e=>n=>r=>({segment:n,state:iy(t)(n)(e),bgAlpha:1,blur:0,minis:sy(t)(e)(n),role:r}),sy=t=>e=>n=>xt(r=>{const o=ps(t)(Pt(n.path)(r))(e);if(o.tag==="Just")return v("Just",{...Po(t)(I2(o._1.startT)(o._1.endT-1e-4)(e))(o._1)(Hf),bgAlpha:0});if(o.tag==="Nothing")return N;g()})((()=>{const r=o=>{if(o.tag==="Leaf")return D;if(o.tag==="Node")return Kt("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));g()};return qt(on.foldr,r(n.layout.nodes))})()),uy=t=>e=>n=>hg(N,gg,r=>r.direction==="DiveIn"&&ai.eq(r.parentPath)(e.path)&&n>=r.startT-.7&&n<r.startT?v("Just",{node:r.node,phase:(n-(r.startT-.7))/.7}):N,t.dives),ay=t=>e=>n=>r=>{const o=uy(t)(e)(n);if(o.tag==="Just"){const i=an(3.141592653589793*o._1.phase*3);return{...r,state:{...r.state,nodeInvert:Kt("Node",1,1,o._1.node,1*i*i,D,D)}}}if(o.tag==="Nothing")return r;g()},$f=t=>e=>xt(n=>{const r=oe(o=>o.direction==="DiveIn"&&ai.eq(o.childPath)((()=>{const i=n.length+1|0;return i<1?[]:Gt(0,i,e)})()))(t.dives);if(r.tag==="Just"){const o=ps(t)(n)(r._1.startT-1e-4);if(o.tag==="Just")return v("Just",(()=>{const i=Po(t)(r._1.startT-1e-4)(o._1)(Hf);return{...i,state:{...i.state,nodeFadeAlpha:Kt("Node",1,1,r._1.node,0,D,D)}}})());if(o.tag==="Nothing")return N;g()}if(r.tag==="Nothing")return N;g()})(R2(e)),Wf=t=>e=>{const n=at(o=>e>=o.startT&&e<o.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:B2(t)},cy=t=>e=>n=>{const r=j2(n)(e),o=ps(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),i=ps(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),s=(()=>{if(n.direction==="DiveIn")return gr(Sr)(r);if(n.direction==="DiveOut")return 1-gr(Sr)(r);g()})(),u=1-_r(0)(Go(1)((s-.1)/.25)),a=1-_r(0)(Go(1)((s-.1)/.25)),c=1-_r(0)(Go(1)((s-.8)/.2)),f=l=>{const _=Po(t)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})())(l)(A2);return{...D2(Y2(l.layout)(n.node))(a)({..._,state:{..._.state,nodeFadeAlpha:Kt("Node",1,1,n.node,u,D,D),nodeLabelFadeAlpha:Kt("Node",1,1,n.node,a,D,D)}}),minis:at(h=>!ai.eq(h.segment.path)(n.childPath),_.minis),bgAlpha:c}},d=0+1*_r(0)(Go(1)((s-.1)/.5));return[...$f(t)(n.parentPath),...(()=>{if(o.tag==="Just"){if(i.tag==="Just")return[f(o._1),{...Po(t)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})())(i._1)(hs),bgAlpha:d}];if(i.tag==="Nothing")return[f(o._1)];g()}if(o.tag==="Nothing")return[Po(t)(e)(Wf(t)(e))(hs)];g()})()]},gy=t=>e=>oe(n=>e>=n.startT&&e<n.endT)(t.dives),fy=t=>e=>{const n=Wf(t)(e),r=Po(t)(e)(n)(hs),o=t.dives.length!==0,i=df(t.cameraConfig)(t.layout)(t.cameraSpans)(e).camera,s=K2(t.layout)(t.cameraConfig.padding)(n)(i),u=ay(t)(n)(e)({...r,state:{...r.state,camera:s}}),a=$f(t)(n.path),c=gy(t)(e);if(c.tag==="Just")return{levels:cy(t)(e)(c._1),camera:i,rootLayout:t.layout,hasDives:o,diving:!0};if(c.tag==="Nothing")return{levels:Pt(a)(u),camera:s,rootLayout:t.layout,hasDives:o,diving:!1};g()},Yf=t=>t,Vf=Yf("RunText"),_y=Yf("RunCode"),Uf=t=>e=>n=>e.length===0?n:Pt(n)({style:t,text:kr(e)}),dy=t=>({style:(()=>{if(t.style==="RunText")return _y;if(t.style==="RunCode")return Vf;g()})(),buf:[],runs:Uf(t.style)(t.buf)(t.runs)}),ly=t=>e=>0<e.length?{...t,buf:Pt(t.buf)(e[0])}:{...t,buf:Pt(t.buf)("\\")},hy=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,u=Mt(a=>N,a=>c=>v("Just",{head:a,tail:c}),r);if(u.tag==="Nothing"){o=!1,i=s;continue}if(u.tag==="Just"){if(u._1.head==="\\"){n=ly(s)(u._1.tail),r=Gt(1,u._1.tail.length,u._1.tail);continue}if(u._1.head==="`"){n=dy(s),r=u._1.tail;continue}n={...s,buf:Pt(s.buf)(u._1.head)},r=u._1.tail;continue}g()}return i},Xf=t=>{const e=hy({style:Vf,buf:[],runs:[]})(ur(t));return Uf(e.style)(e.buf)(e.runs)};let Ia=null;function py(){return Ia||(typeof document>"u"?null:(Ia=document.createElement("canvas").getContext("2d"),Ia))}const Kf=new Map,my=t=>e=>n=>r=>()=>{const o=`${n} ${e}px ${t}|${r}`,i=Kf.get(o);if(i!==void 0)return i;const s=py();if(!s)return r.length*e*.62;s.font=`${n} ${e}px ${t}`;const u=s.measureText(r).width;return Kf.set(o,u),u},yy=zr.traverse(Au),xy=w(Jo)(0),Vr=(()=>{const t=kn(`\r
|
|
3
|
+
`)(" "),e=kn(`
|
|
4
|
+
`)(" "),n=(()=>{const r=kn("\r")(" "),o=(()=>{const i=kn(" ")(" ");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),jf=t=>e=>{const n=yy(r=>{const o=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;g()})();return my(o.family)(o.size)(o.weight)(Vr(r.text))})(Xf(Vr(e)));return()=>{const r=n();return xy(r)}},Zf={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"}},Jy=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Io=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ny=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},wy=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},vy=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},t_=t=>kr(ge(Fn(e=>e===" ")(ge(Fn(e=>e===" ")(ur(t)).rest)).rest)),Ty=t=>w(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?v("Just",n._1):e)(N)(Yt(En)(t)),Aa=t=>e=>{if(t<=0)return[e];if(Mn(e)<=t)return[e];const n=ur(e),r=t<1?[]:Gt(0,t,n),o=Ty(r);if(o.tag==="Just"){const i=t_(Fg(!(o._1>=0&&o._1<r.length)||r[o._1]===" "?o._1:o._1+1|0)(e)),s=t_(To(o._1+1|0)(e));return s===""?[i]:[i,...Aa(t)(s)]}if(o.tag==="Nothing"){const i=Fg(t)(e),s=To(t)(e);return s===""?[i]:[i,...Aa(t)(s)]}g()},by={cellW:7,cellH:3,maxLineWidth:20},ky=t=>e=>{const n=$(i=>k((()=>{if(i.label.tag==="Just")return i.label._1;if(i.label.tag==="Nothing")return i.id;g()})(),i))(e.nodes),r=Io(1)(rr((Ny(t.maxLineWidth)(w(i=>s=>Io(i)(Mn(s._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),o=(r*t.cellW|0)-1|0;return{...e,nodes:$(i=>{if(!(i._2.size._1===1&&i._2.size._2===1))return i._2;const s=Lt(si(`
|
|
5
|
+
`)(i._1))(Aa(o)),u=w(c=>f=>Io(c)(Mn(f)))(0)(s),a=i._2.shape==="Cylinder"?Io(1)(rr((u+2|0)+t.cellW|0,t.cellW)):r;return{...i._2,size:k(Z(u>o?rr((u+2|0)+t.cellW|0,t.cellW):a),Z(Io(1)(rr(s.length+t.cellH|0,t.cellH))+(i._2.shape==="Cylinder"||i._2.shape==="Document"?1:0)|0))}})(n)}},Ly=t=>e=>n=>({...n,nodes:$(r=>{const o=vy(r.id)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just")return{...r,size:k(wy(r.size._1)(Z(Io(1)(fe(zi(r.shape==="Cylinder"?(o._1+0)/t:(o._1+32)/t))))),r.size._2)};g()})(n.nodes)}),Cy=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Sy=t=>{const e=t.length;return(n=>r=>{let o=n,i=r,s=!0,u;for(;s;){const a=o,c=i;if(a>=e){s=!1,u=c;continue}const f=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const x=_,J=h;if(x>=e){p=!1,m=J;continue}if(a>=0&&a<t.length){if(x>=0&&x<t.length){_=x+1|0,h=(()=>{const y=t[a].position,T=t[a].size,b=t[x].position,C=t[x].size;return y._1<b._1+C._1&&b._1<y._1+T._1&&y._2<b._2+C._2&&b._2<y._2+T._2})()?J+1|0:J;continue}_=x+1|0,h=J;continue}p=!1,m=J}return m};o=a+1|0,i=f(a+1|0)(c)}return u})(0)(0)},e_=t=>w(e=>n=>e+o0(n.start)(n.end))(0)(t.segments),Ey=t=>e=>n=>({crossingCount:w(r=>o=>r+o.jumps.length|0)(0)(e),bendCount:w(r=>o=>r+o.bends.length|0)(0)(e),totalEdgeLength:w(r=>o=>r+e_(o))(0)(e),maxEdgeLength:w(r=>o=>Cy(r)(e_(o)))(0)(e),nodeOverlapCount:Sy(t),constraintViolations:n,jumpCount:w(r=>o=>r+o.jumps.length|0)(0)(e)}),Da=t=>t,ie=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=nt.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},Ba=Da("LEFT"),Gy=Da("RIGHT"),n_=Da("UNDEFINED"),Py={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},Iy={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?Oe:Le;if(e==="LEFT")return Ce;if(t==="RIGHT")return e==="RIGHT"?Oe:Le;if(e==="RIGHT")return Ce;if(t==="UP")return e==="UP"?Oe:Le;if(e==="UP")return Ce;if(t==="DOWN")return e==="DOWN"?Oe:Le;if(e==="DOWN")return Ce;if(t==="UNDEFINED"&&e==="UNDEFINED")return Oe;g()},Eq0:()=>Py},Ay=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){if(t==="LEFT"){if(i._3==="LEFT"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="LEFT"){n=i._6;continue}if(t==="RIGHT"){if(i._3==="RIGHT"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="RIGHT"){n=i._6;continue}if(t==="UP"){if(i._3==="UP"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="UP"){n=i._6;continue}if(t==="DOWN"){if(i._3==="DOWN"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="DOWN"){n=i._6;continue}if(t==="UNDEFINED"&&i._3==="UNDEFINED"){r=!1,o=!0;continue}}g()}return o},Dy={x:0,y:0},cn=t=>e=>n=>{const r=ie(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:j(nt)(t)(e(r._1))(n.cNodes)};g()},ci=t=>e=>n=>{const r=ie(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:j(nt)(t)(e(r._1))(n.cGroups)};g()},By=t=>w(e=>n=>cn(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),Ry=t=>{const e=w(n=>r=>{const o=ie(r)(t.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just")return w(i=>s=>It(nt)(_e)(s)([r])(i))(n)(o._1.constraints);g()})(D)(t.cNodeOrder);return w(n=>r=>cn(r)(o=>({...o,constraints:(()=>{const i=ie(r)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;g()})()}))(n))(t)(t.cNodeOrder)},Qy=t=>e=>cn(t)(n=>({...n,ignoreSpacing:{left:n.ignoreSpacing.left||e.left,right:n.ignoreSpacing.right||e.right,up:n.ignoreSpacing.up||e.up,down:n.ignoreSpacing.down||e.down}})),Fy=t=>{const e=w(n=>r=>ci(r)(o=>({...o,outDegree:o.outDegreeReal}))(n))(t)(t.cGroupOrder);return w(n=>r=>cn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder)},Ln={left:!1,right:!1,up:!1,down:!1},zy={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},Ra=t=>w(e=>n=>{const r=ie(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const o=w(s=>u=>{const a=ie(u)(e.cNodes);if(a.tag==="Nothing")return s;if(a.tag==="Just"){if(s.tag==="Nothing")return v("Just",u);if(s.tag==="Just"){const c=ie(s._1)(e.cNodes);if(c.tag==="Nothing")return v("Just",u);if(c.tag==="Just")return a._1.hitbox.x<c._1.hitbox.x?v("Just",u):v("Just",s._1)}}g()})(N)(r._1.cNodes),i=ci(n)(s=>({...s,reference:o}))(e);if(o.tag==="Nothing")return i;if(o.tag==="Just"){const s=ie(o._1)(i.cNodes);if(s.tag==="Nothing")return i;if(s.tag==="Just"){const u=s._1;return w(a=>c=>cn(c)(f=>({...f,cGroupOffset:{x:f.hitbox.x-u.hitbox.x,y:f.hitbox.y-u.hitbox.y}}))(a))(i)(r._1.cNodes)}}}g()})(t)(t.cGroupOrder),gn=t=>Ra({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return D;if(n.tag==="Node")return Kt("Node",n._1,n._2,n._3,{...n._4,hitbox:{...n._4.hitbox,x:-n._4.hitbox.x-n._4.hitbox.width}},e(n._5),e(n._6));g()};return e(t.cNodes)})()}),On=t=>Ra({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return D;if(n.tag==="Node")return Kt("Node",n._1,n._2,n._3,{...n._4,hitbox:{x:n._4.hitbox.y,y:n._4.hitbox.x,width:n._4.hitbox.height,height:n._4.hitbox.width},cGroupOffset:{x:n._4.cGroupOffset.y,y:n._4.cGroupOffset.x}},e(n._5),e(n._6));g()};return e(t.cNodes)})()}),r_=t=>{const e=w(n=>r=>ci(r)(o=>({...o,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return w(n=>r=>{const o=ie(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 w(s=>u=>{const a=ie(u)(s.cNodes);if(a.tag==="Nothing")return s;if(a.tag==="Just")return a._1.cGroup.tag==="Just"&&a._1.cGroup._1!==i?ci(a._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(ci(i)(c=>Ve(vr)(u)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,u]})(s)):s;g()})(n)(o._1.constraints)}}g()})(e)(e.cNodeOrder)},Js=t=>{const e=Ry(t.cGraph);return{...t,cGraph:r_(w(n=>r=>cn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},My=t=>e=>w(n=>r=>{if(t==="LEFT"||t==="UP"){const i=r._2;return cn(r._1)(s=>({...s,constraints:[...s.constraints,i]}))(n)}const o=r._1;return cn(r._2)(i=>({...i,constraints:[...i.constraints,o]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),Cn=t=>{const e={...t,cGraph:My(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return D;if(r.tag==="Node")return Kt("Node",r._1,r._2,r._3,{...r._4,constraints:[]},n(r._5),n(r._6));g()};return n(t.cGraph.cNodes)})()})};return{...e,cGraph:r_((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);g()})())}},Hy=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?Cn(r):e==="RIGHT"?Cn({...r,cGraph:gn(r.cGraph)}):e==="UP"?Cn({...r,cGraph:On(r.cGraph)}):e==="DOWN"?Cn({...r,cGraph:gn(On(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?Js({...r,cGraph:gn(r.cGraph)}):e==="UP"?Cn({...r,cGraph:On(r.cGraph)}):e==="DOWN"?Cn({...r,cGraph:gn(On(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?Js({...r,cGraph:gn(r.cGraph)}):e==="UP"?Cn({...r,cGraph:On(gn(r.cGraph))}):e==="DOWN"?Cn({...r,cGraph:gn(On(gn(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?Cn({...r,cGraph:On(r.cGraph)}):e==="RIGHT"?Cn({...r,cGraph:gn(On(r.cGraph))}):e==="DOWN"?Js({...r,cGraph:gn(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?Cn({...r,cGraph:On(gn(r.cGraph))}):e==="RIGHT"?Cn({...r,cGraph:gn(On(gn(r.cGraph)))}):e==="UP"?Js({...r,cGraph:gn(r.cGraph)}):r;g()},o_=t=>e=>e.finished||!Ay(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:Hy(e.direction)(t)(e),Oy=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?o_(Ba)(t):t,n={...e,cGraph:Fy(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},i_=t=>e=>n=>{const r=ie(t)(n.cNodes),o=ie(e)(n.cGroups);return r.tag==="Just"&&o.tag==="Just"?(()=>{if(r._1.cGroup.tag==="Nothing")return!1;if(r._1.cGroup.tag==="Just")return!0;g()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:j(nt)(t)({...r._1,cGroup:v("Just",e)})(n.cNodes),cGroups:j(nt)(e)({...o._1,cNodes:Ve(vr)(t)(o._1.cNodes)?o._1.cNodes:[...o._1.cNodes,t],reference:(()=>{if(o._1.reference.tag==="Nothing")return v("Just",t);if(o._1.reference.tag==="Just")return v("Just",o._1.reference._1);g()})()})(n.cGroups)}:n},s_=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:j(nt)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:N,cGroupOffset:Dy,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:Ln})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),Qa=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:w(r=>o=>i_(o)(n)(r))({...e,cGroups:j(nt)(n)({id:n,master:t.master,cNodes:[],startPos:-1e308,incomingConstraints:[],outDegree:0,outDegreeReal:0,reference:N,delta:0,deltaNormalized:0})(e.cGroups),cGroupOrder:[...e.cGroupOrder,n],nextCGroupId:n+1|0})(t.nodes)}},qy=t=>w(e=>n=>{const r=ie(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?Qa({master:N,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),$y=t=>({cGraph:By(qy(Ra(t))),direction:n_,compactionAlgorithm:N,constraintAlgorithm:N,spacingsHandler:zy,lockFun:N,finished:!1}),Wy=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Yy=t=>e=>{const n=rt.compare(t._1)(e._1);return n==="LT"?Le:n==="GT"?Ce:nt.compare(t._2)(e._2)},Vy=(()=>{const t=nn.unfoldr(In);return e=>t(rn("IterNode",e,Pn))})(),u_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=nt.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},a_=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",c_=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),Ns=t=>e=>Yy(k(t.hitbox.x+t.hitbox.width/2,t.id))(k(e.hitbox.x+e.hitbox.width/2,e.id)),Uy=t=>e=>{const n=Mr(ne,N,r=>Ns(t)(r)==="LT",e);if(n.tag==="Just"){const r=pg(ne,N,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return Pt(e)(t);g()},g_=t=>e=>{const n=at(o=>Ns(o)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?v("Just",n[r]):N},Xy=t=>e=>{const n=Uy(e)(t.intervals),r=oe(i=>Ns(e)(i)==="LT")(n),o=j(nt)(e.id)((()=>{const i=g_(e)(n);return i.tag==="Just"?v("Just",i._1.id):N})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return j(nt)(r._1.id)(v("Just",e.id))(o);if(r.tag==="Nothing")return o;g()})()}},Ky=t=>e=>{const n=rt.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?Ce:Oe:e.low?Le:Oe:n},jy=t=>w(e=>n=>cn(n.id)(r=>({...r,constraints:[]}))(e))(t)(xt(e=>ie(e)(t.cNodes))(t.cNodeOrder)),Fa=t=>e=>w(n=>r=>{const o=ie(r._1)(n.cNodes);if(o.tag==="Just")return cn(r._1)(i=>({...i,constraints:[...i.constraints,...r._2]}))(n);if(o.tag==="Nothing")return n;g()})(e)(Vy(t)),f_=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}},__=t=>e=>n=>w(r=>o=>n(o)?cn(o.id)(f_(t))(r):r)(e)(xt(r=>ie(r)(e.cNodes))(e.cNodeOrder)),Zy=t=>e=>{const n=(r,o,i)=>{const s=cn(i)(f_(t))(r);return o.length<=1?s:w(u=>a=>a===i?u:cn(a)(c=>c.ignoreSpacing.up?{...c,hitbox:{...c.hitbox,y:c.hitbox.y+t+.01,height:c.hitbox.height-t-.01}}:c.ignoreSpacing.down?{...c,hitbox:{...c.hitbox,height:c.hitbox.height-t-.01}}:c)(u))(s)(o)};return w(r=>o=>{if(o.master.tag==="Nothing")return 0<o.cNodes.length?n(r,o.cNodes,o.cNodes[0]):r;if(o.master.tag==="Just")return n(r,o.cNodes,o.master._1);g()})(e)(xt(r=>ie(r)(e.cGroups))(e.cGroupOrder))},tx=t=>e=>{const n=g_(e)(t.intervals),r=oe(i=>Ns(e)(i)==="LT")(t.intervals),o=n.tag==="Just"&&(()=>{const i=u_(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})()?It(nt)(_e)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const i=u_(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})()?It(nt)(_e)(e.id)([r._1.id])(o):o,intervals:at(i=>i.id!==e.id,t.intervals)}},ex=t=>e=>e.low?Xy(t)(e.node):tx(t)(e.node),za=t=>e=>w(ex)({intervals:[],cand:D,constraints:D})(Dt(Ky)(Lt(at(t,xt(n=>ie(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,nx=t=>e=>{const n=Wy(0)(t/2-.5),r=Fa(za(a_)(__(n)(e)(a_)))(e),o=Fa(za(c_)(__(n)(r)(c_)))(r);return Fa(za(i=>!0)(Zy(n)(o)))(o)},rx=t=>e=>nx(t)(jy(e.cGraph)),ws=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},d_=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ma=t=>e=>n=>r=>o=>({id:t,representedEdges:[o],affectedBends:[e,n],hitbox:{x:ws(e._1)(n._1),y:ws(e._2)(n._2),width:zn(e._1-n._1),height:zn(e._2-n._2)},ignoreSpacing:Ln,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:N}),ox=t=>e=>{const n=ws(t.hitbox.x)(e.hitbox.x),r=ws(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:d_(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:d_(t.hitbox.y+t.hitbox.height)(e.hitbox.y+e.hitbox.height)-r},ignoreSpacing:{left:t.ignoreSpacing.left||e.ignoreSpacing.left,right:t.ignoreSpacing.right||e.ignoreSpacing.right,up:t.ignoreSpacing.up||e.ignoreSpacing.up,down:t.ignoreSpacing.down||e.ignoreSpacing.down},aPort:(()=>{if(t.aPort.tag==="Just")return t.aPort;if(t.aPort.tag==="Nothing")return e.aPort;g()})()}},ix=t=>e=>zn(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,sx=t=>e=>zn(t.hitbox.x-e.hitbox.x)<=1e-4?rt.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?Le:Ce,l_=(t,e)=>({tag:t,_1:e}),Ha=ae(I)(zt),vs=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},h_=(()=>{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=I.compare(n._1)(r._1);if(o==="LT")return Le;if(o==="GT")return Ce;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?Oe:Le;if(r._2.tag==="Nothing")return Ce;if(n._2.tag==="Just"&&r._2.tag==="Just")return I.compare(n._2._1)(r._2._1);g()},Eq0:()=>t};return w(n=>r=>j(e)(r)()(n))(D)})(),dr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},ux=w(t=>e=>j(Iy)(e)()(t))(D),Oa=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=qg.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},ax=t=>e=>{const n=Ha($(i=>k(i.id,i))(t)),r=xt(i=>vs(i)(n))(e),o=nt.compare((()=>{const i=h_($(s=>k(s.from.node,s.from.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;g()})())((()=>{const i=h_($(s=>k(s.to.node,s.to.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;g()})());if(o==="LT")return{...Ln,left:!0,right:!1};if(o==="GT")return{...Ln,left:!1,right:!0};if(o==="EQ")return Ln;g()},cx=t=>xt(e=>{if(e.direction==="V")return v("Just",{start:e.start,end:e.end});if(e.direction==="H")return N;g()})(t.segments),Ts=t=>e=>n=>r=>{if(r.tag==="Just"){const o=dr(n)(e);if(o.tag==="Just"){const i=oe(s=>s.id===r._1)(o._1);if(i.tag==="Just")return i._1.side;if(i.tag==="Nothing")return t;g()}if(o.tag==="Nothing")return t;g()}if(r.tag==="Nothing")return t;g()},gx=t=>e=>n=>{const r=s_({origin:v("Just",l_("SegmentOrigin",n)),kind:v("Just","vs"),hitbox:n.hitbox})(e.cGraph),o=Qy(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const i=ie(n.potentialGroupParents[0])(o.cNodes);if(i.tag==="Just"){if(i._1.cGroup.tag==="Just")return i_(r.id)(i._1.cGroup._1)(o);if(i._1.cGroup.tag==="Nothing")return o;g()}if(i.tag==="Nothing")return o;g()}return Qa({master:v("Just",r.id),nodes:[r.id]})(o).graph})(),edgeToCs:w(i=>s=>It(I)(_e)(s)([r.id])(i))(e.edgeToCs)(n.representedEdges),lockMap:j(nt)(r.id)(ax(t)(n.representedEdges))(e.lockMap)}},fx=t=>e=>n=>{const r=Mt(o=>N,o=>i=>v("Just",{head:o,tail:i}),Dt(sx)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const o=w(i=>s=>ix(i.survivor)(s)?{...i,survivor:ox(i.survivor)(s)}:{survivor:s,merged:[...i.merged,i.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return w(gx(t))(n)([...o.merged,o.survivor])}g()},_x=t=>({cGraph:{cNodes:D,cNodeOrder:[],cGroups:D,cGroupOrder:[],supportedDirections:ux([n_,Ba,Gy]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:D,edgeToCs:D,lockMap:D}),dx=t=>{const e=Z(4);return{x:t.position._1*e,y:t.position._2*e,width:t.size._1*e,height:t.size._2*e}},lx=t=>e=>n=>w(r=>o=>{const i=s_({origin:v("Just",l_("NodeOrigin",o.node)),kind:N,hitbox:dx(o)})(r.cGraph),s=dr(o.node)(t),u=(()=>{if(s.tag==="Nothing")return k(0,0);if(s.tag==="Just")return s._1;g()})();return{...r,cGraph:Qa({master:v("Just",i.id),nodes:[i.id]})(i.graph).graph,nodeToC:j(I)(o.node)(i.id)(r.nodeToC),lockMap:j(nt)(i.id)((()=>{const a=u._1-u._2|0;return a<0?{...Ln,left:!0}:a>0?{...Ln,right:!0}:Ln})())(r.lockMap)}})(n)(e),hx=t=>w(e=>n=>It(I)(r=>o=>k(r._1+o._1|0,r._2+o._2|0))(n.to.node)(k(1,0))(It(I)(r=>o=>k(r._1+o._1|0,r._2+o._2|0))(n.from.node)(k(0,1))(e)))(D)(t),px=t=>w(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?j(I)(n.origin._1._1)(n.hitbox.x)(e):e)(D)(xt(e=>ie(e)(t.cNodes))(t.cNodeOrder)),mx=t=>w(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?j(I)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(D)(xt(e=>ie(e)(t.cNodes))(t.cNodeOrder)),yx=t=>w(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return w(o=>i=>j(qg)(i)(r)(o))(e)(n.origin._1._1.affectedBends)}return e})(D)(xt(e=>ie(e)(t.cNodes))(t.cNodeOrder)),p_=t=>{const e=Ha($(n=>k(n.id,n))(t.edges));return xt(n=>{const r=vs(n.edge)(e);if(r.tag==="Just")return n.reversed?v("Just",{edgeId:n.edge,src:r._1.to.node,tgt:r._1.from.node,srcSide:Ts(ar)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:Ts(cr)(t.ports)(r._1.from.node)(r._1.from.port),path:n}):v("Just",{edgeId:n.edge,src:r._1.from.node,tgt:r._1.to.node,srcSide:Ts(ar)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:Ts(cr)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return N;g()})(t.paths)},xx=t=>e=>{const n=Lt(e)(r=>{if(r.src===r.tgt)return[];if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return[];const o=dr(r.tgt)(t.nodeToC),i=(()=>{if(o.tag==="Just")return ie(o._1)(t.cGraph.cNodes);if(o.tag==="Nothing")return N;g()})(),s=dr(r.src)(t.nodeToC),u=(()=>{if(s.tag==="Just")return ie(s._1)(t.cGraph.cNodes);if(s.tag==="Nothing")return N;g()})(),a=(()=>{if(u.tag==="Just"){if(i.tag==="Just"){if(u._1.cGroup.tag==="Just"){if(i._1.cGroup.tag==="Just")return v("Just",{srcGroup:u._1.cGroup._1,tgtGroup:i._1.cGroup._1,delta:0,weight:100});if(i._1.cGroup.tag==="Nothing")return N;g()}if(u._1.cGroup.tag==="Nothing")return N;g()}if(i.tag==="Nothing")return N;g()}if(u.tag==="Nothing")return N;g()})(),c=_=>h=>p=>{if(u.tag==="Just"){if(u._1.cGroup.tag==="Just"){if(p.cGroup.tag==="Just")return _(p.hitbox.x)&&p.cGroup._1!==u._1.cGroup._1?v("Just",h(p.cGroup._1)(u._1.cGroup._1)):N;if(p.cGroup.tag==="Nothing")return N;g()}if(u._1.cGroup.tag==="Nothing")return N;g()}if(u.tag==="Nothing")return N;g()},f=xt(_=>ie(_)(t.cGraph.cNodes))((()=>{const _=vs(r.edgeId)(t.edgeToCs);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})()),d=(()=>{if(u.tag==="Just"&&r.srcSide==="West"){const _=u._1;return xt(c(h=>h<_.hitbox.x)(h=>p=>({srcGroup:h,tgtGroup:p,delta:1,weight:100})))(f)}return[]})(),l=(()=>{if(u.tag==="Just"&&r.tgtSide==="East"){const _=u._1;return xt(c(h=>h>_.hitbox.x)(h=>p=>({srcGroup:p,tgtGroup:h,delta:1,weight:100})))(f)}return[]})();if(a.tag==="Nothing")return[];if(a.tag==="Just")return[a._1,...d,...l];g()});return{sameEdgeVerticalSegments:r=>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 Ye(s=>Ve(Qn)(s)(i.representedEdges),r.origin._1._1.representedEdges)})(),vsLNodePair:r=>o=>r.origin.tag==="Just"&&o.origin.tag==="Just"&&(r.origin._1.tag==="SegmentOrigin"?o.origin._1.tag==="NodeOrigin":r.origin._1.tag==="NodeOrigin"&&o.origin._1.tag==="SegmentOrigin"),edgeLengthEdges:r=>n}},Jx=t=>e=>{const n=Z(4),r=px(t),o=mx(t),i=Ha($(u=>k(u.id,k(u.from.node,u.to.node)))(e.edges)),s=yx(t);return{nodes:$(u=>{const a=dr(u.node)(r);if(a.tag==="Just")return{...u,position:k(a._1/n,u.position._2)};if(a.tag==="Nothing")return u;g()})(e.nodes),edges:$(u=>{const a=vs(u.edge)(i),c=(()=>{if(a.tag==="Nothing")return u.segments;if(a.tag==="Just"){const f=dr(a._1._1)(o),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})(),l=dr(a._1._2)(o),_=(()=>{if(l.tag==="Nothing")return 0;if(l.tag==="Just")return l._1;g()})();return Yt((()=>{const h=u.reversed?_:d,p=u.reversed?d:_,m=u.segments.length;return x=>J=>{if(J.direction==="V"){const y=(()=>{if(x===0)return h;if(x===(m-1|0))return p;const T=Oa(J.start)(s);if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})();return{...J,start:k(J.start._1+y,J.start._2),end:k(J.end._1+y,J.end._2)}}if(J.direction==="H")return{...J,start:k((()=>{if(x===0)return J.start._1+h;const y=Oa(J.start)(s);if(y.tag==="Nothing")return J.start._1+0;if(y.tag==="Just")return J.start._1+y._1;g()})(),J.start._2),end:k((()=>{if(x===(m-1|0))return J.end._1+p;const y=Oa(J.end)(s);if(y.tag==="Nothing")return J.end._1+0;if(y.tag==="Just")return J.end._1+y._1;g()})(),J.end._2)};g()}})())(u.segments)}g()})();return{...u,segments:c,bends:Ie(f=>d=>f.end,c,Gt(1,c.length,c))}})(e.paths)}},Nx=t=>e=>n=>r=>o=>i=>{const s=Ma(o.nextId)(i._2.start)(i._2.end)(N)(t.edgeId),u=(()=>{if(i._1===0){if(e.tag==="Nothing")return s;if(e.tag==="Just")return{...s,ignoreSpacing:i._2.end._2<e._1.y?{...s.ignoreSpacing,down:!0}:i._2.end._2>e._1.y+e._1.height?{...s.ignoreSpacing,up:!0}:{...s.ignoreSpacing,up:!0,down:!0}};g()}return s})();return{nextId:o.nextId+1|0,segments:[...o.segments,(()=>{if(i._1===r){if(n.tag==="Nothing")return u;if(n.tag==="Just")return{...u,ignoreSpacing:i._2.start._2<n._1.y?{...u.ignoreSpacing,down:!0}:i._2.start._2>n._1.y+n._1.height?{...u.ignoreSpacing,up:!0}:{...u.ignoreSpacing,up:!0,down:!0}};g()}return u})()]}},m_=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...Ma(i.nextId)(r.start)(k(r.start._1,o.down?n.y:n.y+n.height))(v("Just",e))(t.edgeId),aPort:v("Just",{node:t.src,side:o.side}),ignoreSpacing:o.down?{...Ln,down:!0}:{...Ln,up:!0}}]}),bs=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{...Ma(i.nextId)(r.end)(k(r.end._1,o.down?n.y:n.y+n.height))(v("Just",e))(t.edgeId),aPort:v("Just",{node:t.tgt,side:o.side}),ignoreSpacing:o.down?{...Ln,down:!0}:{...Ln,up:!0}}]}),wx=t=>e=>n=>{if(n.src===n.tgt)return e;const r=dr(n.src)(t.nodeToC),o=dr(n.tgt)(t.nodeToC),i=(()=>{if(r.tag==="Just"){const f=ie(r._1)(t.cGraph.cNodes);return f.tag==="Just"?v("Just",f._1.hitbox):N}if(r.tag==="Nothing")return N;g()})(),s=(()=>{if(o.tag==="Just"){const f=ie(o._1)(t.cGraph.cNodes);return f.tag==="Just"?v("Just",f._1.hitbox):N}if(o.tag==="Nothing")return N;g()})(),u=cx(n.path),a=w(Nx(n)(i)(s)(u.length-1|0))(e)(Yt(f=>d=>k(f,d))(u));if(0<u.length){const f=(()=>{if(r.tag==="Just"&&i.tag==="Just"){if(n.srcSide==="North")return m_(n)(r._1)(i._1)(u[0])({side:we,down:!0})(a);if(n.srcSide==="South")return m_(n)(r._1)(i._1)(u[0])({side:ve,down:!1})(a)}return a})(),d=u.length-1|0;if(d>=0&&d<u.length&&o.tag==="Just"&&s.tag==="Just"){if(n.tgtSide==="North")return bs(n)(o._1)(s._1)(u[d])({side:we,down:!0})(f);if(n.tgtSide==="South")return bs(n)(o._1)(s._1)(u[d])({side:ve,down:!1})(f)}return f}const c=u.length-1|0;if(c>=0&&c<u.length&&o.tag==="Just"&&s.tag==="Just"){if(n.tgtSide==="North")return bs(n)(o._1)(s._1)(u[c])({side:we,down:!0})(a);if(n.tgtSide==="South")return bs(n)(o._1)(s._1)(u[c])({side:ve,down:!1})(a)}return a},vx=t=>e=>n=>fx(t)(w(wx(n))({nextId:0,segments:[]})(e).segments)(n),Tx=t=>vx(t.edges)(p_(t))(lx(hx(t.edges))(t.nodes)(_x())),lr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=nt.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},qa=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},$a=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=nt.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},bx=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},kx=t=>{const e=t.Eq0();return n=>r=>{const o=u=>{let a=u,c=!0,f;for(;c;){const d=a,l=Mt(_=>N,_=>h=>v("Just",{head:_,tail:h}),d.queue);if(l.tag==="Nothing"){c=!1,f=d;continue}if(l.tag==="Just"){const _=l._1.head;if((p=>{let m=p,x=!0,J;for(;x;){const y=m;if(y.tag==="Leaf"){x=!1,J=!1;continue}if(y.tag==="Node"){const T=t.compare(_)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){x=!1,J=!0;continue}}g()}return J})(d.removedNodes)){a={...d,queue:l._1.tail};continue}const h=oe(p=>!lr(p.eid)(d.removedEdges)&&(e.eq(p.src)(_)||e.eq(p.tgt)(_)))(r);if(h.tag==="Nothing"){a={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const p=e.eq(h._1.src)(_)?h._1.tgt:h._1.src,m={...d,degree:j(t)(p)((()=>{const x=(J=>{let y=J,T=!0,b;for(;T;){const C=y;if(C.tag==="Leaf"){T=!1,b=N;continue}if(C.tag==="Node"){const S=t.compare(p)(C._3);if(S==="LT"){y=C._5;continue}if(S==="GT"){y=C._6;continue}if(S==="EQ"){T=!1,b=v("Just",C._4);continue}}g()}return b})(d.degree);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;g()})())(d.degree),removedNodes:j(t)(_)()(d.removedNodes),removedEdges:j(nt)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:_,neighbour:p,viaSrc:e.eq(h._1.src)(_)}],queue:l._1.tail};if((()=>{const x=(y=>{let T=y,b=!0,C;for(;b;){const S=T;if(S.tag==="Leaf"){b=!1,C=N;continue}if(S.tag==="Node"){const E=t.compare(p)(S._3);if(E==="LT"){T=S._5;continue}if(E==="GT"){T=S._6;continue}if(E==="EQ"){b=!1,C=v("Just",S._4);continue}}g()}return C})(m.degree),J=y=>{let T=y,b=!0,C;for(;b;){const S=T;if(S.tag==="Leaf"){b=!1,C=!1;continue}if(S.tag==="Node"){const E=t.compare(p)(S._3);if(E==="LT"){T=S._5;continue}if(E==="GT"){T=S._6;continue}if(E==="EQ"){b=!1,C=!0;continue}}g()}return C};return(()=>{if(x.tag==="Nothing")return!1;if(x.tag==="Just")return x._1===1;g()})()&&!J(m.removedNodes)})()){a={...m,queue:[...m.queue,p]};continue}a=m;continue}}g()}return f},i=w(u=>a=>It(t)(pe)(a.src)(1)(It(t)(pe)(a.tgt)(1)(u)))(D)(r),s=o({degree:i,removedNodes:D,removedEdges:D,record:[],queue:at(u=>{const a=(c=>{let f=c,d=!0,l;for(;d;){const _=f;if(_.tag==="Leaf"){d=!1,l=N;continue}if(_.tag==="Node"){const h=t.compare(u)(_._3);if(h==="LT"){f=_._5;continue}if(h==="GT"){f=_._6;continue}if(h==="EQ"){d=!1,l=v("Just",_._4);continue}}g()}return l})(i);if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1===1;g()},n)});return{coreNodes:at(u=>!(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=!1;continue}if(l.tag==="Node"){const _=t.compare(u)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=!0;continue}}g()}return d})(s.removedNodes),n),coreEdges:at(u=>!lr(u.eid)(s.removedEdges),r),removed:s.record}}},Lx=t=>e=>n=>w(r=>o=>{const i=o.neighbour,s=(()=>{const u=(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=N;continue}if(l.tag==="Node"){const _=t.compare(i)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=v("Just",l._4);continue}}g()}return d})(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()})();return j(t)(o.node)(o.viaSrc?s-1|0:s+1|0)(r)})(n)(ge(e)),Wa=t=>{const e=t.Eq0();return n=>r=>o=>{const i={...o,treeNode:j(t)(r)()(o.treeNode)};return w(s=>u=>{if(lr(u.eid)(s.st.edgeVisited))return s;const a={...s.st,edgeVisited:j(nt)(u.eid)()(s.st.edgeVisited)},c=e.eq(u.src)((()=>{const f=u.src,d=_=>{let h=_,p=!0,m;for(;p;){const x=h;if(x.tag==="Leaf"){p=!1,m=!1;continue}if(x.tag==="Node"){const J=t.compare(f)(x._3);if(J==="LT"){h=x._5;continue}if(J==="GT"){h=x._6;continue}if(J==="EQ"){p=!1,m=!0;continue}}g()}return m},l=u.tgt;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const x=h;if(x.tag==="Leaf"){p=!1,m=!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"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?u.src:(()=>{const f=u.tgt,d=_=>{let h=_,p=!0,m;for(;p;){const x=h;if(x.tag==="Leaf"){p=!1,m=!1;continue}if(x.tag==="Node"){const J=t.compare(f)(x._3);if(J==="LT"){h=x._5;continue}if(J==="GT"){h=x._6;continue}if(J==="EQ"){p=!1,m=!0;continue}}g()}return m},l=u.src;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const x=h;if(x.tag==="Leaf"){p=!1,m=!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"){p=!1,m=!0;continue}}g()}return m})(a.treeNode)})()?u.tgt:u.src)?u.tgt:u.src;if(lr(u.eid)(a.treeEdge)){if((d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=!1;continue}if(p.tag==="Node"){const m=t.compare(c)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=!0;continue}}g()}return h})(a.treeNode))return{...s,st:a};const f=Wa(t)(n)(c)(a);return{count:s.count+f.count|0,st:f.st}}if((()=>{const f=l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=!1;continue}if(m.tag==="Node"){const x=t.compare(c)(m._3);if(x==="LT"){_=m._5;continue}if(x==="GT"){_=m._6;continue}if(x==="EQ"){h=!1,p=!0;continue}}g()}return p},d=u.tgt;return!f(a.treeNode)&&(()=>{const l=(p=>{let m=p,x=!0,J;for(;x;){const y=m;if(y.tag==="Leaf"){x=!1,J=N;continue}if(y.tag==="Node"){const T=t.compare(d)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){x=!1,J=v("Just",y._4);continue}}g()}return J})(a.layer),_=u.src,h=(p=>{let m=p,x=!0,J;for(;x;){const y=m;if(y.tag==="Leaf"){x=!1,J=N;continue}if(y.tag==="Node"){const T=t.compare(_)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){x=!1,J=v("Just",y._4);continue}}g()}return J})(a.layer);if(l.tag==="Nothing"){if(h.tag==="Nothing")return u.delta===0;if(h.tag==="Just")return u.delta===-h._1;g()}if(l.tag==="Just"){if(h.tag==="Nothing")return u.delta===(l._1-0|0);if(h.tag==="Just")return u.delta===(l._1-h._1|0)}g()})()})()){const f=Wa(t)(n)(c)({...a,treeEdge:j(nt)(u.eid)()(a.treeEdge)});return{count:s.count+f.count|0,st:f.st}}return{...s,st:a}})({count:1,st:i})(at(s=>(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!lr(s.eid)(i.edgeVisited),n))}},ks=t=>e=>n=>r=>{const o=r.src,i=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=N;continue}if(m.tag==="Node"){const x=t.compare(o)(m._3);if(x==="LT"){_=m._5;continue}if(x==="GT"){_=m._6;continue}if(x==="EQ"){h=!1,p=v("Just",m._4);continue}}g()}return p})(e.poID),s=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})(),u=r.tgt,a=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=N;continue}if(m.tag==="Node"){const x=t.compare(u)(m._3);if(x==="LT"){_=m._5;continue}if(x==="GT"){_=m._6;continue}if(x==="EQ"){h=!1,p=v("Just",m._4);continue}}g()}return p})(e.poID),c=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})(),f=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=N;continue}if(m.tag==="Node"){const x=t.compare(n)(m._3);if(x==="LT"){_=m._5;continue}if(x==="GT"){_=m._6;continue}if(x==="EQ"){h=!1,p=v("Just",m._4);continue}}g()}return p})(e.poID),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return(()=>{const l=r.src,_=(h=>{let p=h,m=!0,x;for(;m;){const J=p;if(J.tag==="Leaf"){m=!1,x=N;continue}if(J.tag==="Node"){const y=t.compare(l)(J._3);if(y==="LT"){p=J._5;continue}if(y==="GT"){p=J._6;continue}if(y==="EQ"){m=!1,x=v("Just",J._4);continue}}g()}return x})(e.lowestPoID);return(()=>{if(_.tag==="Nothing")return 0<=d;if(_.tag==="Just")return _._1<=d;g()})()&&(()=>{const h=r.tgt;return d<=s&&(()=>{const p=(m=>{let x=m,J=!0,y;for(;J;){const T=x;if(T.tag==="Leaf"){J=!1,y=N;continue}if(T.tag==="Node"){const b=t.compare(h)(T._3);if(b==="LT"){x=T._5;continue}if(b==="GT"){x=T._6;continue}if(b==="EQ"){J=!1,y=v("Just",T._4);continue}}g()}return y})(e.lowestPoID);return(()=>{if(p.tag==="Nothing")return 0<=d;if(p.tag==="Just")return p._1<=d;g()})()&&d<=c})()})()})()?s>=c:s<c},Cx=t=>{const e=ae(t)(zt);return n=>({layer:e($(r=>k(r,0))(n)),treeNode:D,treeEdge:D,poID:D,lowestPoID:D,cutvalue:D,postOrder:1,edgeVisited:D})},Sx=t=>e=>n=>w(r=>o=>{if((()=>{const f=o.src,d=h=>{let p=h,m=!0,x;for(;m;){const J=p;if(J.tag==="Leaf"){m=!1,x=!1;continue}if(J.tag==="Node"){const y=t.compare(f)(J._3);if(y==="LT"){p=J._5;continue}if(y==="GT"){p=J._6;continue}if(y==="EQ"){m=!1,x=!0;continue}}g()}return x},l=o.tgt,_=h=>{let p=h,m=!0,x;for(;m;){const J=p;if(J.tag==="Leaf"){m=!1,x=!1;continue}if(J.tag==="Node"){const y=t.compare(l)(J._3);if(y==="LT"){p=J._5;continue}if(y==="GT"){p=J._6;continue}if(y==="EQ"){m=!1,x=!0;continue}}g()}return x};return d(n.treeNode)===_(n.treeNode)})())return r;const i=o.tgt,s=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=N;continue}if(h.tag==="Node"){const p=t.compare(i)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=v("Just",h._4);continue}}g()}return _})(n.layer),u=o.src,a=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=N;continue}if(h.tag==="Node"){const p=t.compare(u)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=v("Just",h._4);continue}}g()}return _})(n.layer),c=(()=>{if(s.tag==="Nothing"){if(a.tag==="Nothing")return-o.delta;if(a.tag==="Just")return-a._1-o.delta|0;g()}if(s.tag==="Just"){if(a.tag==="Nothing")return(s._1-0|0)-o.delta|0;if(a.tag==="Just")return(s._1-a._1|0)-o.delta|0}g()})();return c<r.slack?{edge:v("Just",o),slack:c}:r})({edge:N,slack:1e9})(e).edge,Ex=t=>{const e=ae(t)(zt);return n=>r=>{const o=w(i=>s=>qa(i)((()=>{const u=(a=>{let c=a,f=!0,d;for(;f;){const l=c;if(l.tag==="Leaf"){f=!1,d=N;continue}if(l.tag==="Node"){const _=t.compare(s)(l._3);if(_==="LT"){c=l._5;continue}if(_==="GT"){c=l._6;continue}if(_==="EQ"){f=!1,d=v("Just",l._4);continue}}g()}return d})(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()})()))(1e9)(n);return e($(i=>k(i,(()=>{const s=(u=>{let a=u,c=!0,f;for(;c;){const d=a;if(d.tag==="Leaf"){c=!1,f=N;continue}if(d.tag==="Node"){const l=t.compare(i)(d._3);if(l==="LT"){a=d._5;continue}if(l==="GT"){a=d._6;continue}if(l==="EQ"){c=!1,f=v("Just",d._4);continue}}g()}return f})(r);if(s.tag==="Nothing")return-o;if(s.tag==="Just")return s._1-o|0;g()})()))(n))}},y_=t=>{const e=t.Eq0();return n=>r=>o=>{const i=w(u=>a=>{const c=y_(t)(n)(e.eq(a.src)(r)?a.tgt:a.src)({...u.st,edgeVisited:j(nt)(a.eid)()(u.st.edgeVisited)});return{lowest:qa(u.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:o})(at(u=>lr(u.eid)(o.treeEdge)&&(e.eq(u.src)(r)||e.eq(u.tgt)(r))&&!lr(u.eid)(o.edgeVisited),n)),s=qa(i.lowest)(i.st.postOrder);return{lowest:s,st:{...i.st,poID:j(t)(r)(i.st.postOrder)(i.st.poID),lowestPoID:j(t)(r)(s)(i.st.lowestPoID),postOrder:i.st.postOrder+1|0}}}},x_=t=>{const e=y_(t);return n=>r=>o=>0<n.length?e(r)(n[0])({...o,edgeVisited:D,postOrder:1,poID:D,lowestPoID:D}).st:o},Gx=t=>{const e=t.Eq0();return n=>r=>o=>at(i=>lr(i.eid)(r.treeEdge)&&(e.eq(i.src)(o)||e.eq(i.tgt)(o)),n)},Px=t=>e=>oe(n=>{const r=$a(n.eid)(e.cutvalue);return lr(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),J_=t=>{const e=Wa(t);return n=>r=>o=>{const i=0<n.length?v("Just",n[0]):N;if(i.tag==="Nothing")return o;if(i.tag==="Just"){const s=e(r)(i._1)({...o,edgeVisited:D,treeNode:D,treeEdge:D});if(s.count>=n.length)return s.st;const u=Sx(t)(r)(s.st);if(u.tag==="Nothing")return s.st;if(u.tag==="Just"){const a=u._1.tgt,c=(h=>{let p=h,m=!0,x;for(;m;){const J=p;if(J.tag==="Leaf"){m=!1,x=N;continue}if(J.tag==="Node"){const y=t.compare(a)(J._3);if(y==="LT"){p=J._5;continue}if(y==="GT"){p=J._6;continue}if(y==="EQ"){m=!1,x=v("Just",J._4);continue}}g()}return x})(s.st.layer),f=u._1.src,d=(h=>{let p=h,m=!0,x;for(;m;){const J=p;if(J.tag==="Leaf"){m=!1,x=N;continue}if(J.tag==="Node"){const y=t.compare(f)(J._3);if(y==="LT"){p=J._5;continue}if(y==="GT"){p=J._6;continue}if(y==="EQ"){m=!1,x=v("Just",J._4);continue}}g()}return x})(s.st.layer),l=(()=>{if(c.tag==="Nothing"){if(d.tag==="Nothing")return-u._1.delta;if(d.tag==="Just")return-d._1-u._1.delta|0;g()}if(c.tag==="Just"){if(d.tag==="Nothing")return(c._1-0|0)-u._1.delta|0;if(d.tag==="Just")return(c._1-d._1|0)-u._1.delta|0}g()})(),_=(()=>{const h=u._1.tgt;return(p=>{let m=p,x=!0,J;for(;x;){const y=m;if(y.tag==="Leaf"){x=!1,J=!1;continue}if(y.tag==="Node"){const T=t.compare(h)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){x=!1,J=!0;continue}}g()}return J})(s.st.treeNode)})()?-l:l;return J_(t)(n)(r)({...s.st,layer:w(h=>p=>(m=>{let x=m,J=!0,y;for(;J;){const T=x;if(T.tag==="Leaf"){J=!1,y=!1;continue}if(T.tag==="Node"){const b=t.compare(p)(T._3);if(b==="LT"){x=T._5;continue}if(b==="GT"){x=T._6;continue}if(b==="EQ"){J=!1,y=!0;continue}}g()}return y})(s.st.treeNode)?j(t)(p)((()=>{const m=(x=>{let J=x,y=!0,T;for(;y;){const b=J;if(b.tag==="Leaf"){y=!1,T=N;continue}if(b.tag==="Node"){const C=t.compare(p)(b._3);if(C==="LT"){J=b._5;continue}if(C==="GT"){J=b._6;continue}if(C==="EQ"){y=!1,T=v("Just",b._4);continue}}g()}return T})(s.st.layer);if(m.tag==="Nothing")return 0+_|0;if(m.tag==="Just")return m._1+_|0;g()})())(h):h)(s.st.layer)(n)})}}g()}},Ix=t=>e=>n=>r=>w(o=>i=>{if(ks(t)(r)(i.src)(n)&&!ks(t)(r)(i.tgt)(n)){const s=i.tgt,u=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=N;continue}if(p.tag==="Node"){const m=t.compare(s)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=v("Just",p._4);continue}}g()}return h})(r.layer),a=i.src,c=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=N;continue}if(p.tag==="Node"){const m=t.compare(a)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=v("Just",p._4);continue}}g()}return h})(r.layer),f=(()=>{if(u.tag==="Nothing"){if(c.tag==="Nothing")return-i.delta;if(c.tag==="Just")return-c._1-i.delta|0;g()}if(u.tag==="Just"){if(c.tag==="Nothing")return(u._1-0|0)-i.delta|0;if(c.tag==="Just")return(u._1-c._1|0)-i.delta|0}g()})();if(f<o.slack)return{edge:v("Just",i),slack:f}}return o})({edge:N,slack:1e9})(e).edge,Ax=t=>{const e=t.Eq0();return n=>r=>o=>i=>{const s=i.tgt,u=i.src;return w(a=>c=>{if((()=>{const f=$a(c.eid)(r.cutvalue);if(f.tag==="Just")return!0;if(f.tag==="Nothing")return!1;g()})()){const f=$a(c.eid)(r.cutvalue),d=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})();return e.eq(u)(c.src)||e.eq(s)(c.tgt)?a-(d-c.weight):a+(d-c.weight)}return e.eq(o)(u)?e.eq(c.src)(o)?a+c.weight:a-c.weight:e.eq(c.src)(o)?a-c.weight:a+c.weight})(i.weight)(at(a=>a.eid!==i.eid&&(e.eq(a.src)(o)||e.eq(a.tgt)(o)),n))}},Dx=t=>{const e=Ax(t);return n=>r=>o=>{const i=(s,u,a)=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=N;continue}if(h.tag==="Node"){const p=t.compare(s)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=v("Just",h._4);continue}}g()}return _})(a);if(c.tag==="Just")return j(t)(s)(at(f=>f.eid!==u.eid,c._1))(a);if(c.tag==="Nothing")return a;g()};return(s=>u=>{let a=s,c=u,f=!0,d;for(;f;){const l=a,_=c,h=(m=>{let x=m,J=!0,y;for(;J;){const T=x;if(T.tag==="Leaf"){J=!1,y=N;continue}if(T.tag==="Node"){const b=t.compare(_)(T._3);if(b==="LT"){x=T._5;continue}if(b==="GT"){x=T._6;continue}if(b==="EQ"){J=!1,y=v("Just",T._4);continue}}g()}return y})(l.unknown),p=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;g()})();if(p.length===1){const m=t.Eq0().eq(p[0].src)(_)?p[0].tgt:p[0].src;a={unknown:i(_,p[0],i(m,p[0],l.unknown)),cutvalue:j(nt)(p[0].eid)(e(n)(l)(_)(p[0]))(l.cutvalue)},c=m;continue}f=!1,d=l}return d})(r)(o)}},N_=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:c=>f=>c.delta===f.delta&&c.eid===f.eid&&n.eq(c.src)(f.src)&&e.eq(c.tgt)(f.tgt)&&c.weight===f.weight},o={compare:c=>f=>{const d=nt.compare(c.delta)(f.delta);if(d==="LT"||d==="GT"||d!=="EQ")return d;const l=nt.compare(c.eid)(f.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const _=t.compare(c.src)(f.src);if(_==="LT"||_==="GT"||_!=="EQ")return _;const h=t.compare(c.tgt)(f.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const p=rt.compare(c.weight)(f.weight);return p==="LT"||p==="GT"||p!=="EQ"?p:Oe},Eq0:()=>r},i=w(c=>f=>j(o)(f)()(c))(D),s=Gx(t),u=ae(t)(zt),a=Dx(t);return c=>f=>d=>{const l={unknown:u($(_=>k(_,qt(on.foldr,i(s(f)(d)(_)))))(c)),cutvalue:D};return{...d,cutvalue:w(a(f))(l)(at(_=>{const h=(p=>{let m=p,x=!0,J;for(;x;){const y=m;if(y.tag==="Leaf"){x=!1,J=N;continue}if(y.tag==="Node"){const T=t.compare(_)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){x=!1,J=v("Just",y._4);continue}}g()}return J})(l.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;g()},c)).cutvalue}}},Bx=t=>{const e=x_(t),n=N_(t);return r=>o=>i=>s=>u=>{const a={...u,treeEdge:j(nt)(s.eid)()(xo(nt)(i.eid)(u.treeEdge))},c=s.tgt,f=(p=>{let m=p,x=!0,J;for(;x;){const y=m;if(y.tag==="Leaf"){x=!1,J=N;continue}if(y.tag==="Node"){const T=t.compare(c)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){x=!1,J=v("Just",y._4);continue}}g()}return J})(a.layer),d=s.src,l=(p=>{let m=p,x=!0,J;for(;x;){const y=m;if(y.tag==="Leaf"){x=!1,J=N;continue}if(y.tag==="Node"){const T=t.compare(d)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){x=!1,J=v("Just",y._4);continue}}g()}return J})(a.layer),_=(()=>{if(f.tag==="Nothing"){if(l.tag==="Nothing")return-s.delta;if(l.tag==="Just")return-l._1-s.delta|0;g()}if(f.tag==="Just"){if(l.tag==="Nothing")return(f._1-0|0)-s.delta|0;if(l.tag==="Just")return(f._1-l._1|0)-s.delta|0}g()})(),h=ks(t)(a)(s.tgt)(i)?_:-_;return n(r)(o)(e(r)(o)({...a,layer:w(p=>m=>ks(t)(a)(m)(i)?p:j(t)(m)((()=>{const x=(J=>{let y=J,T=!0,b;for(;T;){const C=y;if(C.tag==="Leaf"){T=!1,b=N;continue}if(C.tag==="Node"){const S=t.compare(m)(C._3);if(S==="LT"){y=C._5;continue}if(S==="GT"){y=C._6;continue}if(S==="EQ"){T=!1,b=v("Just",C._4);continue}}g()}return b})(a.layer);if(x.tag==="Nothing")return 0+h|0;if(x.tag==="Just")return x._1+h|0;g()})())(p))(a.layer)(r)}))}},Rx=t=>{const e=Bx(t);return n=>r=>o=>i=>(s=>u=>{let a=s,c=u,f=!0,d;for(;f;){const l=a,_=c;if(l===0){f=!1,d=_;continue}const h=Px(o)(_);if(h.tag==="Nothing"){f=!1,d=_;continue}if(h.tag==="Just"){const p=Ix(t)(o)(h._1)(_);if(p.tag==="Nothing"){f=!1,d=_;continue}if(p.tag==="Just"){a=l-1|0,c=e(r)(o)(h._1)(p._1)(_);continue}}g()}return d})(n)(i)},Qx=t=>{const e=N_(t),n=x_(t),r=J_(t);return o=>i=>s=>e(o)(i)(n(o)(i)(r(o)(i)(s)))},w_=t=>e=>w(n=>r=>It(t)(_e)(e(r))([r])(n))(D),Fx=t=>{const e=ae(t)(zt);return n=>r=>o=>{const i=a=>c=>f=>d=>{let l=a,_=c,h=f,p=d,m=!0,x;for(;m;){const J=l,y=_,T=h,b=p,C=Mt(S=>N,S=>E=>v("Just",{head:S,tail:E}),T);if(C.tag==="Nothing"){m=!1,x=b;continue}if(C.tag==="Just"){const S=C._1.head,E=(G=>{let A=G,K=!0,U;for(;K;){const z=A;if(z.tag==="Leaf"){K=!1,U=N;continue}if(z.tag==="Node"){const H=t.compare(S)(z._3);if(H==="LT"){A=z._5;continue}if(H==="GT"){A=z._6;continue}if(H==="EQ"){K=!1,U=v("Just",z._4);continue}}g()}return U})(b.layer),F=(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;g()})(),O=w(G=>A=>{const K=A.tgt,U=(H=>{let M=H,P=!0,R;for(;P;){const Q=M;if(Q.tag==="Leaf"){P=!1,R=N;continue}if(Q.tag==="Node"){const B=t.compare(K)(Q._3);if(B==="LT"){M=Q._5;continue}if(B==="GT"){M=Q._6;continue}if(B==="EQ"){P=!1,R=v("Just",Q._4);continue}}g()}return R})(G.incident),z=(()=>{if(U.tag==="Nothing")return-1;if(U.tag==="Just")return U._1-1|0;g()})();return{st:{...G.st,layer:j(t)(A.tgt)(bx((()=>{const H=A.tgt,M=(P=>{let R=P,Q=!0,B;for(;Q;){const q=R;if(q.tag==="Leaf"){Q=!1,B=N;continue}if(q.tag==="Node"){const et=t.compare(H)(q._3);if(et==="LT"){R=q._5;continue}if(et==="GT"){R=q._6;continue}if(et==="EQ"){Q=!1,B=v("Just",q._4);continue}}g()}return B})(G.st.layer);if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})())(F+A.delta|0))(G.st.layer)},incident:j(t)(A.tgt)(z)(G.incident),queue:z===0?[...G.queue,A.tgt]:G.queue}})({st:b,incident:y,queue:C._1.tail})((()=>{const G=(A=>{let K=A,U=!0,z;for(;U;){const H=K;if(H.tag==="Leaf"){U=!1,z=N;continue}if(H.tag==="Node"){const M=t.compare(S)(H._3);if(M==="LT"){K=H._5;continue}if(M==="GT"){K=H._6;continue}if(M==="EQ"){U=!1,z=v("Just",H._4);continue}}g()}return z})(J);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})());l=J,_=O.incident,h=O.queue,p=O.st;continue}g()}return x},s=w_(t)(a=>a.tgt)(r),u=e($(a=>k(a,(()=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=N;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=v("Just",h._4);continue}}g()}return _})(s);if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1.length;g()})()))(n));return i(w_(t)(a=>a.src)(r))(u)(at(a=>{const c=(f=>{let d=f,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=N;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=v("Just",h._4);continue}}g()}return _})(u);if(c.tag==="Nothing")return!0;if(c.tag==="Just")return c._1===0;g()},n))(o)}},zx=t=>{const e=Cx(t),n=Fx(t),r=Qx(t),o=Rx(t);return i=>s=>{const u=n(i)(s)(e(i));return s.length===0?u.layer:o(4*i.length|0)(i)(s)(r(i)(s)(u)).layer}},v_=t=>{const e=Ex(t),n=zx(t),r=kx(t);return o=>i=>{if(o.length===0)return D;if(o.length<40)return e(o)(n(o)(i));const s=r(o)(i);return e(o)(Lx(t)(s.removed)(n(s.coreNodes)(s.coreEdges)))}},T_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=nt.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},Ya=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Mx=v_(nt),gi=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}),Hx=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=Z((()=>{const o=T_(n.cGroup._1)(t);if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})());return cn(n.id)(o=>({...o,hitbox:{...o.hitbox,x:r+o.cGroupOffset.x}}))(e)}g()},Ox=t=>e=>({...e,cGraph:w(Hx(t))(e.cGraph)((()=>{const n=e.cGraph;return xt(r=>ie(r)(n.cNodes))(n.cNodeOrder)})())}),qx=t=>e=>n=>r=>o=>{const i=fe(zi(e.cGroupOffset.x-t.cGroupOffset.x));return gi({src:o.nextNodeId,tgt:r,delta:Ya(0)(-i),weight:1})(gi({src:o.nextNodeId,tgt:n,delta:Ya(0)(i),weight:1})({...o,nodes:[...o.nodes,o.nextNodeId],nextNodeId:o.nextNodeId+1|0}))},$x=t=>e=>n=>r=>o=>i=>s=>{const u=Ya(0)(fe(zi(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)?qx(n)(r)(o)(i)(s):gi({src:o,tgt:i,delta:u,weight:t.vsLNodePair(n)(r)?2:1})(s)},Wx=t=>e=>n=>r=>o=>{const i=ie(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"?$x(t)(e)(n)(i._1)(n.cGroup._1)(i._1.cGroup._1)(r):r;g()},Yx=t=>e=>n=>r=>w(Wx(t)(e)(r))(n)(r.constraints),Vx=t=>e=>gi({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),Ux=t=>{const e=w(o=>i=>It(nt)(pe)(i.tgt)(1)(o))(D)(t.edges),n=at(o=>{const i=T_(o)(e);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return i._1===0;g()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return w(o=>i=>gi({src:r,tgt:i,delta:1,weight:0})(o))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},Xx=t=>e=>{const n=Ux(w(Vx)(w(Yx(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return xt(o=>ie(o)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},Kx=t=>e=>{const n=Xx(t)(e);return Ox(Mx(n.nodes)(n.edges))(e)},b_=t=>t,de=b_("H"),le=b_("V"),jx=t=>k(t._2,t._1),k_=t=>({...t,position:k(t.position._2,t.position._1),size:k(t.size._2,t.size._1)}),Zx=t=>({start:k(t.start._2,t.start._1),end:k(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return le;if(t.direction==="V")return de;g()})()}),L_=t=>({...t,segments:$(Zx)(t.segments),bends:$(jx)(t.bends)}),tJ=t=>({nodes:$(k_)(t.nodes),edges:t.edges,paths:$(L_)(t.paths),ports:t.ports}),eJ={nodeNode:8,edgeNode:4,edgeEdge:10},nJ=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}}),rJ=t=>e=>Kx(e),oJ=t=>e=>n=>{const r=tJ(n),o=Tx(r),i=xx(o)(p_(r)),s=Jx(o_(Ba)(Oy({...$y(o.cGraph),compactionAlgorithm:v("Just",rJ()(i)),constraintAlgorithm:v("Just",rx(e.edgeEdge)),spacingsHandler:nJ(e)(i)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:$(k_)(s.nodes),edges:$(L_)(s.edges)}},C_=t=>t,Ao=ae(nt)(zt),Ot=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=nt.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},S_=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ht=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},pt=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Do=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},iJ=t=>e=>{const n=nt.compare(t._1)(e._1);return n==="LT"?Le:n==="GT"?Ce:nt.compare(t._2)(e._2)},Bo=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},sJ=(()=>{const t=nn.unfoldr(In);return e=>t(rn("IterNode",e,Pn))})(),uJ=t=>t,E_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},aJ=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},Ls=C_("Regular"),Cs=C_("Critical"),G_=t=>e=>{const n=w(s=>u=>j(I)(u.node)(u)(s))(D)(e),r=1.25*Z(4),o=(s,u,a)=>(c=>f=>d=>{let l=c,_=f,h=d,p=!0,m;for(;p;){const x=l,J=_,y=h;if(y.critical){p=!1,m=y;continue}const T=Mt(C=>N,C=>S=>v("Just",{head:C,tail:S}),x),b=Mt(C=>N,C=>S=>v("Just",{head:C,tail:S}),J);if(T.tag==="Just"&&b.tag==="Just"){const C=T._1.head>b._1.head-s&&T._1.head<b._1.head+s?{...y,critical:!0}:T._1.head>b._1.head-r&&T._1.head<b._1.head+r?{...y,conflicts:y.conflicts+1|0}:y;if(C.critical){p=!1,m=C;continue}if(T._1.head<=b._1.head){l=T._1.tail,_=J,h=C;continue}l=x,_=b._1.tail,h=C;continue}p=!1,m=y}return m})(u)(a)({conflicts:0,critical:!1}),i=(s,u,a)=>{if(pt(w(pt)(-1e18)(u.incoming))(w(pt)(-1e18)(u.outgoing))-ht(w(ht)(1e18)(u.incoming))(w(ht)(1e18)(u.outgoing))<.001||pt(w(pt)(-1e18)(a.incoming))(w(pt)(-1e18)(a.outgoing))-ht(w(ht)(1e18)(a.incoming))(w(ht)(1e18)(a.outgoing))<.001)return[];const c=o(s,u.outgoing,a.incoming),f=o(s,a.outgoing,u.incoming);if(c.critical||f.critical)return[...c.critical?[{src:a.id,tgt:u.id,weight:1,kind:Cs}]:[],...f.critical?[{src:u.id,tgt:a.id,weight:1,kind:Cs}]:[]];const d=ht(w(ht)(1e18)(u.incoming))(w(ht)(1e18)(u.outgoing)),l=pt(w(pt)(-1e18)(u.incoming))(w(pt)(-1e18)(u.outgoing)),_=ht(w(ht)(1e18)(a.incoming))(w(ht)(1e18)(a.outgoing)),h=pt(w(pt)(-1e18)(a.incoming))(w(pt)(-1e18)(a.outgoing)),p=(1*c.conflicts|0)+(16*(w(x=>J=>J>h?x:J>=_?x+1|0:x)(0)(u.outgoing)+w(x=>J=>J>l?x:J>=d?x+1|0:x)(0)(a.incoming)|0)|0)|0,m=(1*f.conflicts|0)+(16*(w(x=>J=>J>l?x:J>=d?x+1|0:x)(0)(a.outgoing)+w(x=>J=>J>h?x:J>=_?x+1|0:x)(0)(u.incoming)|0)|0)|0;return p<m?[{src:u.id,tgt:a.id,weight:m-p|0,kind:Ls}]:p>m?[{src:a.id,tgt:u.id,weight:p-m|0,kind:Ls}]:p>0?[{src:u.id,tgt:a.id,weight:0,kind:Ls},{src:a.id,tgt:u.id,weight:0,kind:Ls}]:[]};return w(s=>u=>w(a=>c=>j(I)(c._1)(c._2)(a))(s)((()=>{const a=w(G=>A=>{const K=A.edge.from.node+"|"+(()=>{if(A.edge.from.port.tag==="Just")return A.edge.from.port._1;if(A.edge.from.port.tag==="Nothing")return"_auto_"+A.edge.id;g()})(),U=E_(K)(G.entries);if(U.tag==="Nothing")return{...G,entries:j(I)(K)({id:0,members:[A.edge.id],incoming:[A.fromPos._1],outgoing:[A.toPos._1],slot:0,mark:0,splitBy:N,splitPartner:N})(G.entries),order:[...G.order,K]};if(U.tag==="Just")return{...G,entries:j(I)(K)({...U._1,members:[...U._1.members,A.edge.id],incoming:[...Fn(z=>z<A.fromPos._1)(U._1.incoming).init,A.fromPos._1,...Fn(z=>z<=A.fromPos._1)(U._1.incoming).rest],outgoing:[...Fn(z=>z<A.toPos._1)(U._1.outgoing).init,A.toPos._1,...Fn(z=>z<=A.toPos._1)(U._1.outgoing).rest]})(G.entries)};g()})({entries:D,order:[]})(u._2),c=Yt(G=>A=>({...A,id:G}))(xt(G=>E_(G)(a.entries))(a.order));if(c.length===0)return[];const f=w(G=>A=>G.prev.tag==="Just"&&A-G.prev._1<1e-9?G:{prev:v("Just",A),out:[...G.out,A]})({prev:N,out:[]})(Dt(rt.compare)([...Lt(c)(G=>G.incoming),...Lt(c)(G=>G.outgoing)])).out,d=f.length<2?.2*r:.2*w(G=>A=>{if(G.prev.tag==="Nothing")return{prev:v("Just",A),mn:G.mn};if(G.prev.tag==="Just")return{prev:v("Just",A),mn:ht(G.mn)(A-G.prev._1)};g()})({prev:N,mn:1e18})(f).mn,l={segments:c,deps:(()=>{const G=c.length;return Lt(Lt(Ut(0,G-2|0))(A=>Lt(Ut(A+1|0,G-1|0))(K=>[k(A,K)])))(A=>A._1>=0&&A._1<c.length?A._2>=0&&A._2<c.length?i(d,c[A._1],c[A._2]):[]:[])})()},_=at(G=>{if(G.kind==="Critical")return!0;if(G.kind==="Regular")return!1;g()},l.deps),h=(()=>{if(_.length<2)return l;const G=Ao((()=>{const H=l.segments;return $(M=>k(M.id,M.mark))((()=>{const M=H.length,P=Q=>{let B=Q,q=!0,et;for(;q;){const V=B,Y=oe(W=>{const X=Ot(W)(V.inWeight);if(X.tag==="Nothing")return!0;if(X.tag==="Just")return X._1===0;g()})(V.remaining);if(Y.tag==="Nothing"){q=!1,et=V;continue}if(Y.tag==="Just"){const W=Y._1;B={...V,inWeight:w(X=>tt=>It(nt)(pe)(tt.tgt)(-tt.weight)(X))(V.inWeight)((()=>{const X=Ot(W)(V.depsBySrc);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()})()),marks:j(nt)(W)(V.nextSource)(V.marks),nextSource:V.nextSource+1|0,outWeight:w(X=>tt=>It(nt)(pe)(tt.src)(-tt.weight)(X))(V.outWeight)((()=>{const X=Ot(W)(V.depsByTgt);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()})()),remaining:at(X=>X!==W,V.remaining)};continue}g()}return et},R=Q=>{let B=Q,q=!0,et;for(;q;){const V=B,Y=oe(W=>{const X=Ot(W)(V.outWeight);if(X.tag==="Nothing")return!0;if(X.tag==="Just")return X._1===0;g()})(V.remaining);if(Y.tag==="Nothing"){q=!1,et=V;continue}if(Y.tag==="Just"){const W=Y._1;B={...V,inWeight:w(X=>tt=>It(nt)(pe)(tt.tgt)(-tt.weight)(X))(V.inWeight)((()=>{const X=Ot(W)(V.depsBySrc);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()})()),marks:j(nt)(W)(V.nextSink)(V.marks),nextSink:V.nextSink-1|0,outWeight:w(X=>tt=>It(nt)(pe)(tt.src)(-tt.weight)(X))(V.outWeight)((()=>{const X=Ot(W)(V.depsByTgt);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()})()),remaining:at(X=>X!==W,V.remaining)};continue}g()}return et};return(Q=>{let B=Q,q=!0,et;for(;q;){const V=P(R(B));if(V.remaining.length===0){q=!1,et=$(Y=>{const W=Ot(Y.id)(V.marks),X=(()=>{if(W.tag==="Nothing")return Y.id;if(W.tag==="Just")return W._1;g()})();return{...Y,mark:X<M?(X+M|0)+1|0:X}})(H);continue}B=(()=>{const Y=X=>{const tt=Ot(X)(V.outWeight),gt=Ot(X)(V.inWeight);return(()=>{if(tt.tag==="Nothing")return 0;if(tt.tag==="Just")return tt._1;g()})()-(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()|0},W=Dt(X=>tt=>nt.compare(Y(tt))(Y(X)))(V.remaining);if(0<W.length){const X=W[0];return{...V,inWeight:w(tt=>gt=>It(nt)(pe)(gt.tgt)(-gt.weight)(tt))(V.inWeight)((()=>{const tt=Ot(X)(V.depsBySrc);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),marks:j(nt)(X)(V.nextSource)(V.marks),nextSource:V.nextSource+1|0,outWeight:w(tt=>gt=>It(nt)(pe)(gt.src)(-gt.weight)(tt))(V.outWeight)((()=>{const tt=Ot(X)(V.depsByTgt);if(tt.tag==="Nothing")return[];if(tt.tag==="Just")return tt._1;g()})()),remaining:at(tt=>tt!==X,V.remaining)}}return V})()}return et})({remaining:$(Q=>Q.id)(H),marks:D,inWeight:w(Q=>B=>It(nt)(pe)(B.tgt)(B.weight)(Q))(D)(_),outWeight:w(Q=>B=>It(nt)(pe)(B.src)(B.weight)(Q))(D)(_),depsBySrc:w(Q=>B=>It(nt)(_e)(B.src)([B])(Q))(D)(_),depsByTgt:w(Q=>B=>It(nt)(_e)(B.tgt)([B])(Q))(D)(_),nextSink:M-1|0,nextSource:M+1|0})})())})()),A=at(H=>{const M=Ot(H.src)(G),P=Ot(H.tgt)(G);return(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()>(()=>{if(P.tag==="Nothing")return 0;if(P.tag==="Just")return P._1;g()})()},_);if(A.length===0)return l;const K=w(H=>M=>{if(Ve(vr)(M.src)(H.decisions)||Ve(vr)(M.tgt)(H.decisions))return H;const P=Ot(M.src)(H.segMap),R=Ot(M.tgt)(H.segMap);if(P.tag==="Just"&&R.tag==="Just"){const Q=(P._1.incoming.length+P._1.outgoing.length|0)>2&&(R._1.incoming.length+R._1.outgoing.length|0)<=2,B=Q?R._1:P._1;return{decisions:[...H.decisions,B.id],segMap:j(nt)(B.id)({...B,splitBy:v("Just",Q?P._1.id:R._1.id)})(H.segMap)}}return H})({decisions:[],segMap:Ao($(H=>k(H.id,H))(l.segments))})(A),U=K.segMap,z=w(H=>M=>{const P=ht(w(ht)(1e18)(M.incoming))(w(ht)(1e18)(M.outgoing)),R=pt(w(pt)(-1e18)(M.incoming))(w(pt)(-1e18)(M.outgoing)),Q=at(Y=>Y.a.startPosition<=R&&Y.a.endPosition>=P,Yt(Y=>W=>({i:Y,a:W}))(H.freeAreas));if(Q.length===0){const Y={...M,incoming:Dt(rt.compare)(M.incoming),outgoing:Dt(rt.compare)([(P+R)/2]),splitPartner:v("Just",H.nextId)},W={id:H.nextId,incoming:Dt(rt.compare)([(P+R)/2]),mark:0,members:M.members,outgoing:Dt(rt.compare)(M.outgoing),slot:0,splitBy:N,splitPartner:v("Just",M.id)};return{segMap:j(nt)(W.id)(W)(j(nt)(Y.id)(Y)(H.segMap)),freeAreas:H.freeAreas,nextId:H.nextId+1|0}}const B=0<Q.length?v("Just",Q[0]):N,q=(()=>{if(B.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(B.tag==="Just"){if(Q.length===1)return B._1;const Y=$(W=>({c:W,rating:(()=>{const X=(W.a.startPosition+W.a.endPosition)/2,tt=[X],gt=[X],wt=w((()=>{const yt=H.segMap;return Ct=>Vt=>{const mt=Ot(Vt.tgt)(yt);if(mt.tag==="Nothing")return Ct;if(mt.tag==="Just"){const Wt=ht(w(ht)(1e18)(mt._1.incoming))(w(ht)(1e18)(mt._1.outgoing)),kt=pt(w(pt)(-1e18)(mt._1.incoming))(w(pt)(-1e18)(mt._1.outgoing)),lt=ht(w(ht)(1e18)(M.incoming))(w(ht)(1e18)(tt)),ft=(()=>{const Qt=pt(w(pt)(-1e18)(M.incoming))(w(pt)(-1e18)(tt)),Bt=w(te=>ce=>ce>kt?te:ce>=Wt?te+1|0:te)(0)(tt)+w(te=>ce=>ce>Qt?te:ce>=lt?te+1|0:te)(0)(mt._1.incoming)|0,De=ht(w(ht)(1e18)(M.incoming))(w(ht)(1e18)(tt)),hn=pt(w(pt)(-1e18)(M.incoming))(w(pt)(-1e18)(tt)),We=ht(w(ht)(1e18)(mt._1.incoming))(w(ht)(1e18)(mt._1.outgoing)),en=pt(w(pt)(-1e18)(mt._1.incoming))(w(pt)(-1e18)(mt._1.outgoing)),Pe=w(te=>ce=>ce>hn?te:ce>=De?te+1|0:te)(0)(mt._1.outgoing)+w(te=>ce=>ce>en?te:ce>=We?te+1|0:te)(0)(M.incoming)|0;return Bt===Pe?Bt>0?{...Ct,deps:Ct.deps+2|0,crossings:Ct.crossings+Bt|0}:Ct:{...Ct,deps:Ct.deps+1|0,crossings:Ct.crossings+Bo(Bt)(Pe)|0}})(),ot=ht(w(ht)(1e18)(mt._1.incoming))(w(ht)(1e18)(mt._1.outgoing)),_t=pt(w(pt)(-1e18)(mt._1.incoming))(w(pt)(-1e18)(mt._1.outgoing)),st=ht(w(ht)(1e18)(gt))(w(ht)(1e18)(M.outgoing)),ut=pt(w(pt)(-1e18)(gt))(w(pt)(-1e18)(M.outgoing)),Jt=w(Qt=>Bt=>Bt>_t?Qt:Bt>=ot?Qt+1|0:Qt)(0)(M.outgoing)+w(Qt=>Bt=>Bt>ut?Qt:Bt>=st?Qt+1|0:Qt)(0)(mt._1.incoming)|0,vt=ht(w(ht)(1e18)(gt))(w(ht)(1e18)(M.outgoing)),At=pt(w(pt)(-1e18)(gt))(w(pt)(-1e18)(M.outgoing)),Zt=ht(w(ht)(1e18)(mt._1.incoming))(w(ht)(1e18)(mt._1.outgoing)),ln=pt(w(pt)(-1e18)(mt._1.incoming))(w(pt)(-1e18)(mt._1.outgoing)),Ae=w(Qt=>Bt=>Bt>At?Qt:Bt>=vt?Qt+1|0:Qt)(0)(mt._1.outgoing)+w(Qt=>Bt=>Bt>ln?Qt:Bt>=Zt?Qt+1|0:Qt)(0)(gt)|0;return Jt===Ae?Jt>0?{...ft,deps:ft.deps+2|0,crossings:ft.crossings+Jt|0}:ft:{...ft,deps:ft.deps+1|0,crossings:ft.crossings+Bo(Jt)(Ae)|0}}g()}})())(w((()=>{const yt=H.segMap;return Ct=>Vt=>{const mt=Ot(Vt.src)(yt);if(mt.tag==="Nothing")return Ct;if(mt.tag==="Just"){const Wt=ht(w(ht)(1e18)(mt._1.incoming))(w(ht)(1e18)(mt._1.outgoing)),kt=pt(w(pt)(-1e18)(mt._1.incoming))(w(pt)(-1e18)(mt._1.outgoing)),lt=ht(w(ht)(1e18)(M.incoming))(w(ht)(1e18)(tt)),ft=(()=>{const Qt=pt(w(pt)(-1e18)(M.incoming))(w(pt)(-1e18)(tt)),Bt=w(te=>ce=>ce>kt?te:ce>=Wt?te+1|0:te)(0)(tt)+w(te=>ce=>ce>Qt?te:ce>=lt?te+1|0:te)(0)(mt._1.incoming)|0,De=ht(w(ht)(1e18)(M.incoming))(w(ht)(1e18)(tt)),hn=pt(w(pt)(-1e18)(M.incoming))(w(pt)(-1e18)(tt)),We=ht(w(ht)(1e18)(mt._1.incoming))(w(ht)(1e18)(mt._1.outgoing)),en=pt(w(pt)(-1e18)(mt._1.incoming))(w(pt)(-1e18)(mt._1.outgoing)),Pe=w(te=>ce=>ce>hn?te:ce>=De?te+1|0:te)(0)(mt._1.outgoing)+w(te=>ce=>ce>en?te:ce>=We?te+1|0:te)(0)(M.incoming)|0;return Bt===Pe?Bt>0?{...Ct,deps:Ct.deps+2|0,crossings:Ct.crossings+Bt|0}:Ct:{...Ct,deps:Ct.deps+1|0,crossings:Ct.crossings+Bo(Bt)(Pe)|0}})(),ot=ht(w(ht)(1e18)(mt._1.incoming))(w(ht)(1e18)(mt._1.outgoing)),_t=pt(w(pt)(-1e18)(mt._1.incoming))(w(pt)(-1e18)(mt._1.outgoing)),st=ht(w(ht)(1e18)(gt))(w(ht)(1e18)(M.outgoing)),ut=pt(w(pt)(-1e18)(gt))(w(pt)(-1e18)(M.outgoing)),Jt=w(Qt=>Bt=>Bt>_t?Qt:Bt>=ot?Qt+1|0:Qt)(0)(M.outgoing)+w(Qt=>Bt=>Bt>ut?Qt:Bt>=st?Qt+1|0:Qt)(0)(mt._1.incoming)|0,vt=ht(w(ht)(1e18)(gt))(w(ht)(1e18)(M.outgoing)),At=pt(w(pt)(-1e18)(gt))(w(pt)(-1e18)(M.outgoing)),Zt=ht(w(ht)(1e18)(mt._1.incoming))(w(ht)(1e18)(mt._1.outgoing)),ln=pt(w(pt)(-1e18)(mt._1.incoming))(w(pt)(-1e18)(mt._1.outgoing)),Ae=w(Qt=>Bt=>Bt>At?Qt:Bt>=vt?Qt+1|0:Qt)(0)(mt._1.outgoing)+w(Qt=>Bt=>Bt>ln?Qt:Bt>=Zt?Qt+1|0:Qt)(0)(gt)|0;return Jt===Ae?Jt>0?{...ft,deps:ft.deps+2|0,crossings:ft.crossings+Jt|0}:ft:{...ft,deps:ft.deps+1|0,crossings:ft.crossings+Bo(Jt)(Ae)|0}}g()}})())({crossings:0,deps:0})(at(yt=>yt.tgt===M.id,l.deps)))(at(yt=>yt.src===M.id,l.deps)),ct=(()=>{if(M.splitBy.tag==="Just")return Ot(M.splitBy._1)(H.segMap);if(M.splitBy.tag==="Nothing")return N;g()})();if(ct.tag==="Just")return{...wt,deps:wt.deps+2|0,crossings:(()=>{const yt=ht(w(ht)(1e18)(ct._1.incoming))(w(ht)(1e18)(ct._1.outgoing)),Ct=ht(w(ht)(1e18)(gt))(w(ht)(1e18)(M.outgoing)),Vt=pt(w(pt)(-1e18)(ct._1.incoming))(w(pt)(-1e18)(ct._1.outgoing)),mt=pt(w(pt)(-1e18)(gt))(w(pt)(-1e18)(M.outgoing)),Wt=ht(w(ht)(1e18)(M.incoming))(w(ht)(1e18)(tt));return wt.crossings+(()=>{const kt=ht(w(ht)(1e18)(ct._1.incoming))(w(ht)(1e18)(ct._1.outgoing)),lt=pt(w(pt)(-1e18)(M.incoming))(w(pt)(-1e18)(tt)),ft=pt(w(pt)(-1e18)(ct._1.incoming))(w(pt)(-1e18)(ct._1.outgoing));return((w(ot=>_t=>_t>Vt?ot:_t>=yt?ot+1|0:ot)(0)(tt)+w(ot=>_t=>_t>lt?ot:_t>=Wt?ot+1|0:ot)(0)(ct._1.incoming)|0)+w(ot=>_t=>_t>mt?ot:_t>=Ct?ot+1|0:ot)(0)(ct._1.outgoing)|0)+w(ot=>_t=>_t>ft?ot:_t>=kt?ot+1|0:ot)(0)(gt)|0})()|0})()};if(ct.tag==="Nothing")return wt;g()})()}))(Q);return w(W=>X=>X.rating.crossings<W.rating.crossings||!(X.rating.crossings>W.rating.crossings)&&(X.rating.deps<W.rating.deps||!(X.rating.deps>W.rating.deps)&&X.c.a.size>W.c.a.size)?X:W)(0<Y.length?Y[0]:{c:B._1,rating:{crossings:1e6,deps:1e6}})(Y).c}g()})(),et={...M,incoming:Dt(rt.compare)(M.incoming),outgoing:Dt(rt.compare)([(q.a.startPosition+q.a.endPosition)/2]),splitPartner:v("Just",H.nextId)},V={id:H.nextId,incoming:Dt(rt.compare)([(q.a.startPosition+q.a.endPosition)/2]),mark:0,members:M.members,outgoing:Dt(rt.compare)(M.outgoing),slot:0,splitBy:N,splitPartner:v("Just",M.id)};return{segMap:j(nt)(V.id)(V)(j(nt)(et.id)(et)(H.segMap)),freeAreas:(()=>{if(q.i>=0&&q.i<H.freeAreas.length){const Y=mg(ne,N,q.i,H.freeAreas),W=(()=>{if(Y.tag==="Nothing")return H.freeAreas;if(Y.tag==="Just")return Y._1;g()})();if(H.freeAreas[q.i].size/2<d)return W;const X=(H.freeAreas[q.i].startPosition+H.freeAreas[q.i].endPosition)/2,tt=X-d,gt=X+d;return[...q.i<1?[]:Gt(0,q.i,W),...H.freeAreas[q.i].startPosition<=tt?[{startPosition:H.freeAreas[q.i].startPosition,endPosition:tt,size:tt-H.freeAreas[q.i].startPosition}]:[],...gt<=H.freeAreas[q.i].endPosition?[{startPosition:gt,endPosition:H.freeAreas[q.i].endPosition,size:H.freeAreas[q.i].endPosition-gt}]:[],...q.i<1?W:Gt(q.i,W.length,W)]}return H.freeAreas})(),nextId:H.nextId+1|0}})({segMap:U,freeAreas:(()=>{const H=Dt(rt.compare)([...Lt(l.segments)(M=>M.incoming),...Lt(l.segments)(M=>M.outgoing)]);return xt(uJ)(Ie(M=>P=>P-M>=2*d?v("Just",{startPosition:M+d,endPosition:P-d,size:P-M-2*d}):N,H,Gt(1,H.length,H)))})(),nextId:l.segments.length})(Dt(H=>M=>rt.compare(pt(w(pt)(-1e18)(H.incoming))(w(pt)(-1e18)(H.outgoing))-ht(w(ht)(1e18)(H.incoming))(w(ht)(1e18)(H.outgoing)))(pt(w(pt)(-1e18)(M.incoming))(w(pt)(-1e18)(M.outgoing))-ht(w(ht)(1e18)(M.incoming))(w(ht)(1e18)(M.outgoing))))(xt(H=>Ot(H)(U))(K.decisions)));return{segments:(()=>{const H=(M,P)=>{if(M.tag==="Leaf")return P;if(M.tag==="Node")return H(M._5,Xt("Cons",M._4,H(M._6,P)));g()};return qt(ue.foldr,H(z.segMap,Ht))})(),deps:(()=>{const H=z.segMap,M=(Q,B)=>{if(Q.tag==="Leaf")return B;if(Q.tag==="Node")return M(Q._5,Xt("Cons",Q._4,M(Q._6,B)));g()},P=qt(ue.foldr,M(H,Ht)),R=P.length;return[...Lt(Lt(Ut(0,R-2|0))(Q=>Lt(Ut(Q+1|0,R-1|0))(B=>[k(Q,B)])))(Q=>Q._1>=0&&Q._1<P.length?Q._2>=0&&Q._2<P.length?P[Q._1].splitPartner.tag!=="Nothing"&&P[Q._1].splitPartner.tag==="Just"&&P[Q._1].splitPartner._1===P[Q._2].id||P[Q._2].splitPartner.tag!=="Nothing"&&P[Q._2].splitPartner.tag==="Just"&&P[Q._2].splitPartner._1===P[Q._1].id?[]:i(d,P[Q._1],P[Q._2]):[]:[]),...Lt(P)(Q=>Q.splitBy.tag==="Just"&&Q.splitPartner.tag==="Just"&&(()=>{const B=Ot(Q.splitPartner._1)(H);if(B.tag==="Nothing")return!1;if(B.tag==="Just")return!0;g()})()&&(()=>{const B=Ot(Q.splitBy._1)(H);if(B.tag==="Nothing")return!1;if(B.tag==="Just")return!0;g()})()?[{src:Q.id,tgt:Q.splitBy._1,weight:1,kind:Cs},{src:Q.splitBy._1,tgt:Q.splitPartner._1,weight:1,kind:Cs}]:[])]})()}})(),p=h.segments,m=p.length,x=G=>{let A=G,K=!0,U;for(;K;){const z=A,H=oe(M=>{const P=Ot(M)(z.inWeight);if(P.tag==="Nothing")return!0;if(P.tag==="Just")return P._1===0;g()})(z.remaining);if(H.tag==="Nothing"){K=!1,U=z;continue}if(H.tag==="Just"){const M=H._1;A={...z,inWeight:w(P=>R=>It(nt)(pe)(R.tgt)(-R.weight)(P))(z.inWeight)((()=>{const P=Ot(M)(z.depsBySrc);if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})()),marks:j(nt)(M)(z.nextSource)(z.marks),nextSource:z.nextSource+1|0,outWeight:w(P=>R=>It(nt)(pe)(R.src)(-R.weight)(P))(z.outWeight)((()=>{const P=Ot(M)(z.depsByTgt);if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})()),remaining:at(P=>P!==M,z.remaining)};continue}g()}return U},J=G=>{let A=G,K=!0,U;for(;K;){const z=A,H=oe(M=>{const P=Ot(M)(z.outWeight);if(P.tag==="Nothing")return!0;if(P.tag==="Just")return P._1===0;g()})(z.remaining);if(H.tag==="Nothing"){K=!1,U=z;continue}if(H.tag==="Just"){const M=H._1;A={...z,inWeight:w(P=>R=>It(nt)(pe)(R.tgt)(-R.weight)(P))(z.inWeight)((()=>{const P=Ot(M)(z.depsBySrc);if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})()),marks:j(nt)(M)(z.nextSink)(z.marks),nextSink:z.nextSink-1|0,outWeight:w(P=>R=>It(nt)(pe)(R.src)(-R.weight)(P))(z.outWeight)((()=>{const P=Ot(M)(z.depsByTgt);if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;g()})()),remaining:at(P=>P!==M,z.remaining)};continue}g()}return U},y=(G=>{let A=G,K=!0,U;for(;K;){const z=x(J(A));if(z.remaining.length===0){K=!1,U=$(H=>{const M=Ot(H.id)(z.marks),P=(()=>{if(M.tag==="Nothing")return H.id;if(M.tag==="Just")return M._1;g()})();return{...H,mark:P<m?(P+m|0)+1|0:P}})(p);continue}A=(()=>{const H=P=>{const R=Ot(P)(z.outWeight),Q=Ot(P)(z.inWeight);return(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;g()})()-(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;g()})()|0},M=Dt(P=>R=>nt.compare(H(R))(H(P)))(z.remaining);if(0<M.length){const P=M[0];return{...z,inWeight:w(R=>Q=>It(nt)(pe)(Q.tgt)(-Q.weight)(R))(z.inWeight)((()=>{const R=Ot(P)(z.depsBySrc);if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;g()})()),marks:j(nt)(P)(z.nextSource)(z.marks),nextSource:z.nextSource+1|0,outWeight:w(R=>Q=>It(nt)(pe)(Q.src)(-Q.weight)(R))(z.outWeight)((()=>{const R=Ot(P)(z.depsByTgt);if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;g()})()),remaining:at(R=>R!==P,z.remaining)}}return z})()}return U})({remaining:$(G=>G.id)(p),marks:D,inWeight:w(G=>A=>It(nt)(pe)(A.tgt)(A.weight)(G))(D)(h.deps),outWeight:w(G=>A=>It(nt)(pe)(A.src)(A.weight)(G))(D)(h.deps),depsBySrc:w(G=>A=>It(nt)(_e)(A.src)([A])(G))(D)(h.deps),depsByTgt:w(G=>A=>It(nt)(_e)(A.tgt)([A])(G))(D)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),T=(()=>{const G=(()=>{const U=Ao($(z=>k(z.id,z.mark))(y));return{segments:y,deps:xt(z=>(()=>{if(z.kind==="Critical")return!0;if(z.kind==="Regular")return!1;g()})()?v("Just",z):(()=>{const H=Ot(z.src)(U),M=Ot(z.tgt)(U);return(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})()>(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})()})()?z.weight===0?N:v("Just",{src:z.tgt,tgt:z.src,weight:z.weight,kind:z.kind}):v("Just",z))(h.deps)}})(),A=w(U=>z=>It(nt)(pe)(z.tgt)(1)(U))(D)(G.deps),K=(U=>{let z=U,H=!0,M;for(;H;){const P=z,R=Mt(Q=>N,Q=>B=>v("Just",{head:Q,tail:B}),P.queue);if(R.tag==="Nothing"){H=!1,M=P;continue}if(R.tag==="Just"){z=w((()=>{const Q=Ot(R._1.head)(P.slots),B=(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;g()})();return q=>et=>{const V=Ot(et)(q.inDegree),Y=(()=>{if(V.tag==="Nothing")return-1;if(V.tag==="Just")return V._1-1|0;g()})();return{...q,slots:j(nt)(et)(S_((()=>{const W=Ot(et)(q.slots);if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})())(B+1|0))(q.slots),inDegree:j(nt)(et)(Y)(q.inDegree),queue:Y===0?[...q.queue,et]:q.queue}}})())({...P,queue:R._1.tail})((()=>{const Q=Ot(R._1.head)(P.adj);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;g()})());continue}g()}return M})({slots:Ao($(U=>k(U.id,0))(G.segments)),inDegree:A,adj:w(U=>z=>It(nt)(_e)(z.src)([z.tgt])(U))(D)(G.deps),queue:$(U=>U.id)(at(U=>{const z=Ot(U.id)(A);if(z.tag==="Nothing")return!0;if(z.tag==="Just")return z._1===0;g()},G.segments))});return Dt(U=>z=>nt.compare(U.slot)(z.slot))($(U=>({...U,slot:(()=>{const z=Ot(U.id)(K.slots);if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})()}))(G.segments))})(),b=1+w(G=>A=>S_(G)(A.slot))(0)(T)|0,C=Lt(T)(G=>G.members),S=at(G=>Ve(Qn)(G.edge.id)(C),t),E=w(pt)(-1e18)($(G=>G.fromPos._2)(S)),F=w(ht)(1e18)($(G=>G.toPos._2)(S));if(E>F){const G=Ao($(A=>k(A.id,A))(T));return un($(A=>$(K=>k(K,{slot:A.slot,slotCount:b,gapTop:F,gapBottom:E,partner:(()=>{if(A.splitPartner.tag==="Just"){const U=Ot(A.splitPartner._1)(G);if(U.tag==="Just")return v("Just",{slot:U._1.slot,splitX:0<U._1.incoming.length?U._1.incoming[0]:0});if(U.tag==="Nothing")return N;g()}if(A.splitPartner.tag==="Nothing")return N;g()})()}))(A.members))(at(A=>{if(A.splitPartner.tag==="Just"){const K=Ot(A.splitPartner._1)(G);return!(K.tag==="Just"&&(()=>{if(K._1.splitBy.tag==="Nothing")return!1;if(K._1.splitBy.tag==="Just")return!0;g()})())}if(A.splitPartner.tag==="Nothing")return!0;g()},T)))}const O=Ao($(G=>k(G.id,G))(T));return un($(G=>$(A=>k(A,{slot:G.slot,slotCount:b,gapTop:E,gapBottom:F,partner:(()=>{if(G.splitPartner.tag==="Just"){const K=Ot(G.splitPartner._1)(O);if(K.tag==="Just")return v("Just",{slot:K._1.slot,splitX:0<K._1.incoming.length?K._1.incoming[0]:0});if(K.tag==="Nothing")return N;g()}if(G.splitPartner.tag==="Nothing")return N;g()})()}))(G.members))(at(G=>{if(G.splitPartner.tag==="Just"){const A=Ot(G.splitPartner._1)(O);return!(A.tag==="Just"&&(()=>{if(A._1.splitBy.tag==="Nothing")return!1;if(A._1.splitBy.tag==="Just")return!0;g()})())}if(G.splitPartner.tag==="Nothing")return!0;g()},T)))})()))(D)(sJ(w(s=>u=>{const a=Do(u.edge.from.node)(n);if(a.tag==="Just"){const c=Do(u.edge.to.node)(n);return c.tag==="Just"&&a._1.layer!==c._1.layer?It(nt)(_e)(Bo(a._1.layer)(c._1.layer))([u])(s):s}return s})(D)((()=>{const s=u=>k((()=>{const a=Do(u.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=Do(u.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return Dt(u=>a=>iJ(s(u))(s(a)))(t)})())))},cJ=t=>e=>{const n=G_(t)(e),r=w(o=>i=>j(I)(i.node)(i)(o))(D)(e);return w(o=>i=>{const s=Do(i.edge.from.node)(r);if(s.tag==="Just"){const u=Do(i.edge.to.node)(r);if(u.tag==="Just"&&s._1.layer!==u._1.layer){const a=aJ(i.edge.id)(n);if(a.tag==="Just")return j(nt)(Bo(s._1.layer)(u._1.layer))(a._1.slotCount)(o)}return o}return o})(D)(t)},P_=zt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),Je=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ne=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fi=t=>e=>n=>r=>P_(o=>n>=o.x&&n<o.x+o.w&&e>o.y&&t<o.y+o.h)(r),Ss=t=>e=>n=>r=>fi(Je(e)(n))(Ne(e)(n))(r)(t),Es=Z(4),gJ=xg(t=>{if(t.direction==="H"){const e=Je(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:Ne(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=Je(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:Ne(t.start._2)(t.end._2)-e}]}g()}),_i=Hu(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})())}),fJ=t=>e=>n=>{const r=Mt(o=>N,o=>i=>v("Just",{head:o,tail:i}),e);if(r.tag==="Nothing")return[{start:t.start,end:n.end,direction:t.direction}];if(r.tag==="Just"){const o=(r._1.head.direction==="H"?t.direction==="H":r._1.head.direction==="V"&&t.direction==="V")?[{start:t.start,end:r._1.head.end,direction:t.direction}]:[t,r._1.head],i=Hr(r._1.tail);if(i.tag==="Nothing"){const s=o.length-1|0;return s>=0&&s<o.length&&(o[s].direction==="H"?n.direction==="H":o[s].direction==="V"&&n.direction==="V")?[...(()=>{const u=o.length-1|0;return u<1?[]:Gt(0,u,o)})(),{start:o[s].start,end:n.end,direction:n.direction}]:[...o,n]}if(i.tag==="Just")return(i._1.last.direction==="H"?n.direction==="H":i._1.last.direction==="V"&&n.direction==="V")?[...o,...i._1.init,{start:i._1.last.start,end:n.end,direction:n.direction}]:[...o,...r._1.tail,n]}g()},di=t=>{const e=r=>o=>{const i=Mt(s=>N,s=>u=>v("Just",{head:s,tail:u}),o);if(i.tag==="Nothing")return[r];if(i.tag==="Just")return(r.direction==="H"?i._1.head.direction==="H":r.direction==="V"&&i._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==i._1.head.end._1-i._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==i._1.head.end._2-i._1.head.start._2>=0;g()})()?e({start:r.start,end:i._1.head.end,direction:r.direction})(i._1.tail):[r,...e(i._1.head)(i._1.tail)];g()},n=Mt(r=>N,r=>o=>v("Just",{head:r,tail:o}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);g()},li=t=>e=>n=>r=>P_(o=>n>=o.y&&n<o.y+o.h&&e>o.x&&t<o.x+o.w)(r),hi=t=>e=>n=>r=>li(Je(e)(n))(Ne(e)(n))(r)(t),_J=t=>e=>n=>r=>{const o=n+2|0,i=o<1?e:Gt(o,e.length,e),s=n<1?[]:Gt(0,n,e),u=(n+1|0)===(r-1|0),a=n===0,c=n>=0&&n<e.length?v("Just",e[n]):N;if(c.tag==="Just"){const f=n+1|0,d=f>=0&&f<e.length?v("Just",e[f]):N;if(d.tag==="Just"){const l=c._1.start._1===d._1.end._1&&(!a||c._1.direction==="V")&&(!u||d._1.direction==="V")&&!Ss(t)(Je(c._1.start._2)(d._1.end._2))(Ne(c._1.start._2)(d._1.end._2))(c._1.start._1)?v("Just",[...s,{start:c._1.start,end:d._1.end,direction:le},...i]):N,_=c._1.start._2===d._1.end._2&&(!a||c._1.direction==="H")&&(!u||d._1.direction==="H")&&!hi(t)(Je(c._1.start._1)(d._1.end._1))(Ne(c._1.start._1)(d._1.end._1))(c._1.start._2)?v("Just",[...s,{start:c._1.start,end:d._1.end,direction:de},...i]):N;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return N;g()}if(c.tag==="Nothing")return N;g()},dJ=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,s;for(;i;){const u=o;if((u+1|0)>=n){i=!1,s=e;continue}const a=_J(t)(e)(u)(n);if(a.tag==="Just"){i=!1,s=a._1;continue}if(a.tag==="Nothing"){o=u+1|0;continue}g()}return s})(0)},lJ=t=>e=>n=>r=>{const o=(l,_,h)=>!Ss(t)(Je(_)(h))(Ne(_)(h))(l),i=n+3|0,s=i<1?e:Gt(i,e.length,e),u=n<1?[]:Gt(0,n,e),a=(n+2|0)===(r-1|0),c=n===0,f=(l,_,h)=>!hi(t)(Je(_)(h))(Ne(_)(h))(l),d=n>=0&&n<e.length?v("Just",e[n]):N;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<e.length?v("Just",e[l]):N;if(_.tag==="Just"){const h=d._1.start._1===_._1.end._1&&(!c||d._1.direction==="V")&&(!a||_._1.direction==="V")&&o(d._1.start._1,d._1.start._2,_._1.end._2)?v("Just",[...u,{start:d._1.start,end:_._1.end,direction:le},...s]):d._1.start._2===_._1.end._2&&(!c||d._1.direction==="H")&&(!a||_._1.direction==="H")&&f(d._1.start._2,d._1.start._1,_._1.end._1)?v("Just",[...u,{start:d._1.start,end:_._1.end,direction:de},...s]):N,p=(!c||d._1.direction==="V")&&(!a||_._1.direction==="H")&&o(d._1.start._1,d._1.start._2,_._1.end._2)&&f(_._1.end._2,d._1.start._1,_._1.end._1)?v("Just",[...u,{start:d._1.start,end:k(d._1.start._1,_._1.end._2),direction:le},{start:k(d._1.start._1,_._1.end._2),end:_._1.end,direction:de},...s]):N,m=(!c||d._1.direction==="H")&&(!a||_._1.direction==="V")&&f(d._1.start._2,d._1.start._1,_._1.end._1)&&o(_._1.end._1,d._1.start._2,_._1.end._2)?v("Just",[...u,{start:d._1.start,end:k(_._1.end._1,d._1.start._2),direction:de},{start:k(_._1.end._1,d._1.start._2),end:_._1.end,direction:le},...s]):N,x=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?x:h}if(_.tag==="Nothing")return N;g()}if(d.tag==="Nothing")return N;g()},hJ=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,s;for(;i;){const u=o;if((u+2|0)>=n){i=!1,s=e;continue}const a=lJ(t)(e)(u)(n);if(a.tag==="Just"){i=!1,s=a._1;continue}if(a.tag==="Nothing"){o=u+1|0;continue}g()}return s})(0)},pJ=t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const s=r,u=di(_i(dJ(t)(hJ(t)(s))));if(u.length<s.length){r=u;continue}o=!1,i=u}return i};return n=>e(di(_i(n)))},mJ=t=>e=>n=>r=>{const o=Je(n)(r),i=Ne(n)(r),s=at(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>o&&a.x<i,t);if(r>n){const a=Dt(c=>f=>rt.compare(c.x)(f.x))(s);return 0<a.length?a[0].x-1:(n+r)/2}const u=Dt(a=>c=>rt.compare(c.x)(a.x))($(a=>({...a,x:a.x+a.w}))(s));return 0<u.length?u[0].x+1:(n+r)/2},yJ=t=>e=>n=>r=>{const o=Je(n)(r),i=Ne(n)(r),s=at(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>o&&a.y<i,t);if(r>n){const a=Dt(c=>f=>rt.compare(c.y)(f.y))(s);return 0<a.length?a[0].y-1:(n+r)/2}const u=Dt(a=>c=>rt.compare(c.y)(a.y))($(a=>({...a,y:a.y+a.h}))(s));return 0<u.length?u[0].y+1:(n+r)/2},xJ=t=>e=>n=>r=>{const o=Je(n)(r),i=Ne(n)(r),s=at(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>o&&a.x<i,t);if(r>n){const a=Dt(c=>f=>rt.compare(f.x)(c.x))($(c=>({...c,x:c.x+c.w}))(s));return 0<a.length?a[0].x:(n+r)/2}const u=Dt(a=>c=>rt.compare(a.x)(c.x))(s);return 0<u.length?u[0].x-1:(n+r)/2},JJ=t=>e=>n=>r=>{const o=Je(n)(r),i=Ne(n)(r),s=at(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>o&&a.y<i,t);if(r>n){const a=Dt(c=>f=>rt.compare(f.y)(c.y))($(c=>({...c,y:c.y+c.h}))(s));return 0<a.length?a[0].y:(n+r)/2}const u=Dt(a=>c=>rt.compare(a.y)(c.y))(s);return 0<u.length?u[0].y-1:(n+r)/2},I_=t=>e=>n=>{let r=t,o=e,i=n,s=!0,u;for(;s;){const a=r,c=o,f=i;if(f>100){s=!1,u=c;continue}if(!a(c+f)){s=!1,u=c+f;continue}if(!a(c-f)){s=!1,u=c-f;continue}r=a,o=c,i=f+1}return u},A_=t=>e=>n=>r=>o=>{const i=Je(e)(n),s=Ne(e)(n);if(!fi(i)(s)(r)(t))return r;if(!fi(i)(s)(o)(t))return o;const u=(r+o)/2;return fi(i)(s)(u)(t)?I_(a=>fi(i)(s)(a)(t))(u)(1):u},NJ=t=>e=>n=>r=>o=>{const i=Je(e)(n),s=Ne(e)(n);if(!li(i)(s)(r)(t))return r;if(!li(i)(s)(o)(t))return o;const u=(r+o)/2;return li(i)(s)(u)(t)?I_(a=>li(i)(s)(a)(t))(u)(1):u},wJ=t=>e=>n=>r=>{const o=Je(e)(n),i=Ne(e)(n),s=at(c=>r>=c.x&&r<c.x+c.w&&c.y+c.h>o&&c.y<i,t),u=w(c=>f=>Ne(c)(f.x+f.w+4))(r+4)(s),a=w(c=>f=>Je(c)(f.x-4))(r-4)(s);return(()=>{const c=u-r,f=a-r;return(c<0?-c:c)<=(f<0?-f:f)})()?u:a},vJ=t=>e=>n=>r=>{const o=Je(e)(n),i=Ne(e)(n),s=at(c=>r>=c.y&&r<c.y+c.h&&c.x+c.w>o&&c.x<i,t),u=w(c=>f=>Ne(c)(f.y+f.h+4))(r+4)(s),a=w(c=>f=>Je(c)(f.y-4))(r-4)(s);return(()=>{const c=u-r,f=a-r;return(c<0?-c:c)<=(f<0?-f:f)})()?u:a},TJ=t=>e=>n=>r=>o=>i=>s=>{const u=(()=>{if(r==="South")return k(o._1,o._2+4);if(r==="North")return k(o._1,o._2-4);if(r==="East")return k(o._1+4,o._2);if(r==="West")return k(o._1-4,o._2);g()})(),a=(()=>{if(i==="South")return k(s._1,s._2+4);if(i==="North")return k(s._1,s._2-4);if(i==="East")return k(s._1+4,s._2);if(i==="West")return k(s._1-4,s._2);g()})(),c=(b,C,S)=>!Ss(e)(Je(C)(S))(Ne(C)(S))(b),f=(b,C,S)=>!Ss(n)(Je(C)(S))(Ne(C)(S))(b),d=(b,C,S,E)=>t.tag==="Just"&&!hi(n)(Je(b)(C))(Ne(b)(C))(t._1)?t._1:NJ(e)(b)(C)(S)(E),l=(b,C,S,E)=>{if(b===S){const O=wJ(e)(C)(E)(b),G=yJ(e)(b)(C)(E),A=JJ(e)(b)(C)(E);return[{start:k(b,C),end:k(b,G),direction:le},{start:k(b,G),end:k(O,G),direction:de},{start:k(O,G),end:k(O,A),direction:le},{start:k(O,A),end:k(S,A),direction:de},{start:k(S,A),end:k(S,E),direction:le}]}const F=d(b,S,C,E);return[{start:k(b,C),end:k(b,F),direction:le},{start:k(b,F),end:k(S,F),direction:de},{start:k(S,F),end:k(S,E),direction:le}]},_=(b,C,S,E)=>{if(C===E){const O=vJ(e)(b)(S)(C),G=mJ(e)(C)(b)(S),A=xJ(e)(C)(b)(S);return[{start:k(b,C),end:k(G,C),direction:de},{start:k(G,C),end:k(G,O),direction:le},{start:k(G,O),end:k(A,O),direction:de},{start:k(A,O),end:k(A,E),direction:le},{start:k(A,E),end:k(S,E),direction:de}]}const F=A_(e)(C)(E)(b)(S);return[{start:k(b,C),end:k(F,C),direction:de},{start:k(F,C),end:k(F,E),direction:le},{start:k(F,E),end:k(S,E),direction:de}]},h=(b,C,S)=>!hi(e)(Je(C)(S))(Ne(C)(S))(b),p=(b,C,S)=>!hi(n)(Je(C)(S))(Ne(C)(S))(b),m=(b,C,S,E)=>{if(p(C,b,S)&&f(S,C,E))return[{start:k(b,C),end:k(S,C),direction:de},{start:k(S,C),end:k(S,E),direction:le}];const F=A_(e)(C)(E)(b)(S);return[{start:k(b,C),end:k(F,C),direction:de},{start:k(F,C),end:k(F,E),direction:le},{start:k(F,E),end:k(S,E),direction:de}]},x=(b,C,S,E)=>{if(f(b,C,E)&&p(E,b,S))return[{start:k(b,C),end:k(b,E),direction:le},{start:k(b,E),end:k(S,E),direction:de}];const F=d(b,S,C,E);return[{start:k(b,C),end:k(b,F),direction:le},{start:k(b,F),end:k(S,F),direction:de},{start:k(S,F),end:k(S,E),direction:le}]},J=(()=>{if(r==="South")return i==="North"?u._1===a._1&&c(u._1,u._2,a._2)?[{start:k(u._1,u._2),end:k(a._1,a._2),direction:le}]:l(u._1,u._2,a._1,a._2):i==="East"||i==="West"?x(u._1,u._2,a._1,a._2):l(u._1,u._2,a._1,a._2);if(r==="North")return i==="South"?u._1===a._1&&c(u._1,u._2,a._2)?[{start:k(u._1,u._2),end:k(a._1,a._2),direction:le}]:l(u._1,u._2,a._1,a._2):i==="East"||i==="West"?x(u._1,u._2,a._1,a._2):l(u._1,u._2,a._1,a._2);if(r==="East")return i==="West"?u._2===a._2&&h(u._2,u._1,a._1)?[{start:k(u._1,u._2),end:k(a._1,a._2),direction:de}]:_(u._1,u._2,a._1,a._2):i==="North"||i==="South"?m(u._1,u._2,a._1,a._2):l(u._1,u._2,a._1,a._2);if(r==="West"){if(i==="East")return u._2===a._2&&h(u._2,u._1,a._1)?[{start:k(u._1,u._2),end:k(a._1,a._2),direction:de}]:_(u._1,u._2,a._1,a._2);if(i==="North"||i==="South")return m(u._1,u._2,a._1,a._2)}return l(u._1,u._2,a._1,a._2)})(),y=(()=>{if(r==="South"||r==="North")return le;if(r==="East"||r==="West")return de;g()})(),T={start:k(a._1,a._2),end:k(s._1,s._2),direction:(()=>{if(i==="South"||i==="North")return le;if(i==="East"||i==="West")return de;g()})()};return u._1===a._1&&u._2===a._2?[{start:k(o._1,o._2),end:k(s._1,s._2),direction:y}]:fJ({start:k(o._1,o._2),end:k(u._1,u._2),direction:y})(J)(T)},bJ=$(t=>({x:t.position._1*Es-2,y:t.position._2*Es-2,w:t.size._1*Es+4,h:t.size._2*Es+4})),Va=ae(I)(zt),hr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},Ua=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},kJ=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t._1)(i._3._1);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(t._2==="North"){if(i._3._2==="North"){r=!1,o=v("Just",i._4);continue}n=i._5;continue}if(i._3._2==="North"){n=i._6;continue}if(t._2==="South"){if(i._3._2==="South"){r=!1,o=v("Just",i._4);continue}n=i._5;continue}if(i._3._2==="South"){n=i._6;continue}if(t._2==="East"){if(i._3._2==="East"){r=!1,o=v("Just",i._4);continue}n=i._5;continue}if(i._3._2==="East"){n=i._6;continue}if(t._2==="West"&&i._3._2==="West"){r=!1,o=v("Just",i._4);continue}}g()}return o},D_=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 k(o,i*2);if(t==="North")return k(o,e.position._2*2);if(t==="East")return k(n*2,r);if(t==="West")return k(e.position._1*2,r);g()},Xa=t=>e=>{const n=Z(4);if(t==="South")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="North")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="East")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};if(t==="West")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};g()},B_=t=>e=>w(n=>r=>It(t)(_e)(e(r))([r])(n))(D),R_=t=>e=>n=>r=>{const o=(t==="South"||t==="North")&&(e==="East"||e==="West")&&(()=>{if(t==="South")return r._2>n._2;if(t==="North")return r._2<n._2;if(t==="East")return r._2>n._2;if(t==="West")return r._2<n._2;g()})()&&(()=>{if(e==="East")return n._1>r._1;if(e==="West"||e==="North")return n._1<r._1;if(e==="South")return n._1>r._1;g()})(),i=(t==="East"||t==="West")&&(e==="North"||e==="South")&&(()=>{if(t==="South")return r._1>n._1;if(t==="North")return r._1<n._1;if(t==="East")return r._1>n._1;if(t==="West")return r._1<n._1;g()})()&&(()=>{if(e==="East")return n._2>r._2;if(e==="West"||e==="North")return n._2<r._2;if(e==="South")return n._2>r._2;g()})();return(t==="South"?e==="North"&&n._1===r._1&&r._2>n._2:t==="North"?e==="South"&&n._1===r._1&&r._2<n._2:t==="East"?e==="West"&&n._2===r._2&&r._1>n._1:t==="West"&&e==="East"&&n._2===r._2&&r._1<n._1)?0:o||i?1:2},Q_=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,o=e.length;return o===0?D:Va(o===1?$(i=>k(i,r))(e):Yt(i=>s=>k(s,t.lo+Z(i+1|0)*n/Z(o+1|0)))(e))},F_=t=>e=>n=>r=>o=>{const i=B_(I)(_=>_.to.node)(t),s=B_(I)(_=>_.from.node)(t),u=w(_=>h=>j(I)(h.node)(h)(_))(D)(e),a=(_,h,p)=>{const m=hr(_)(u);if(m.tag==="Nothing")return k(0,0);if(m.tag==="Just"){const x=hr(_)(n);if(x.tag==="Nothing"){const J=Z(4);if(p==="South")return k(m._1.position._1*J+m._1.size._1*J/2,(m._1.position._2+m._1.size._2)*J);if(p==="North")return k(m._1.position._1*J+m._1.size._1*J/2,m._1.position._2*J);if(p==="East")return k((m._1.position._1+m._1.size._1)*J,m._1.position._2*J+m._1.size._2*J/2);if(p==="West")return k(m._1.position._1*J,m._1.position._2*J+m._1.size._2*J/2);g()}if(x.tag==="Just"){const J=oe(y=>y.id===h)(x._1);if(J.tag==="Nothing"){const y=Z(4);if(p==="South")return k(m._1.position._1*y+m._1.size._1*y/2,(m._1.position._2+m._1.size._2)*y);if(p==="North")return k(m._1.position._1*y+m._1.size._1*y/2,m._1.position._2*y);if(p==="East")return k((m._1.position._1+m._1.size._1)*y,m._1.position._2*y+m._1.size._2*y/2);if(p==="West")return k(m._1.position._1*y,m._1.position._2*y+m._1.size._2*y/2);g()}if(J.tag==="Just"){const y=Z(4);if(J._1.side==="North")return k(m._1.position._1*y+Z(J._1.offset)*y,m._1.position._2*y);if(J._1.side==="South")return k(m._1.position._1*y+Z(J._1.offset)*y,(m._1.position._2+m._1.size._2)*y);if(J._1.side==="East")return k((m._1.position._1+m._1.size._1)*y,m._1.position._2*y+Z(J._1.offset)*y);if(J._1.side==="West")return k(m._1.position._1*y,m._1.position._2*y+Z(J._1.offset)*y)}}}g()},c=Va(Lt(r)(_=>{if(_.nodes.length<=2)return[];const h=Z(4);if(1<_.nodes.length){const p=hr(_.nodes[1])(u);if(p.tag==="Nothing")return[];if(p.tag==="Just"){const m=p._1.position._1*h+p._1.size._1*h/2;return $(x=>k(x,m))(Ie(x=>J=>_.edgeId+":"+x+"->"+J,_.nodes,Gt(1,_.nodes.length,_.nodes)))}g()}return[]})),f=_=>{const h=hr(_.from.node)(u),p=hr(_.to.node)(u);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,x=p._1,J=Dt(y=>T=>nt.compare(y.score)(T.score))($(y=>{const T=y._1,b=y._2;return{from:T,to:b,score:(()=>{const C=(O,G,A,K,U)=>{const z=Xa(O)(G),H=Xa(O)(A);return z.lo<H.hi&&H.lo<z.hi&&(T==="South"?b==="North"&&U._2>K._2:T==="North"?b==="South"&&U._2<K._2:T==="East"?b==="West"&&U._1>K._1:T==="West"&&b==="East"&&U._1<K._1)?0:R_(T)(b)(K)(U)},S=D_(T)(m),E=D_(b)(x),F=R_(T)(b)(S)(E);return(()=>{if(F>0){if(T==="South")return b==="North"?C(ve,m,x,S,E)*10|0:F*10|0;if(T==="North")return b==="South"?C(we,m,x,S,E)*10|0:F*10|0;if(T==="East")return b==="West"?C(ar,m,x,S,E)*10|0:F*10|0;if(T==="West"&&b==="East")return C(cr,m,x,S,E)*10|0}return F*10|0})()+(T==="South"?b==="North"?0:15:T==="North"?b==="South"?0:15:T==="East"?b==="West"?5:15:T==="West"&&b==="East"?5:15)|0})()}})([k(ve,we),k(ar,we),k(cr,we),k(ve,ar),k(ve,cr),k(we,ve),k(we,ar),k(we,cr),k(ar,ve),k(cr,ve),k(ar,cr),k(cr,ar)]));if(0<J.length)return{from:J[0].from,to:J[0].to}}return{from:ve,to:we}},d=Va($(_=>k(_.id,f(_)))(t)),l=(_,h,p,m,x,J)=>{const y=Z(4),T=hr(h)(u);if(T.tag==="Nothing")return k(0,0);if(T.tag==="Just"){const b=kJ(k(p,_))(o);if(b.tag==="Just"){const C=T._1.position._1*y+b._1,S=Z(4);if(_==="South")return k(C,(T._1.position._2+T._1.size._2)*S);if(_==="North")return k(C,T._1.position._2*S);if(_==="East")return k((T._1.position._1+T._1.size._1)*S,C);if(_==="West")return k(T._1.position._1*S,C);g()}if(b.tag==="Nothing"){const C=Xa(_)(T._1),S=(C.lo+C.hi)/2,E=Ua(p)(Q_(C)($(G=>G.id)(Dt(G=>A=>rt.compare(x(_)(G))(x(_)(A)))(at(G=>{const A=Ua(G.id)(d);if(A.tag==="Just"){const K=J(A._1);return K==="North"?_==="North":K==="South"?_==="South":K==="East"?_==="East":K==="West"&&_==="West"}if(A.tag==="Nothing")return!0;g()},(()=>{const G=hr(h)(m);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;g()})()))))),F=(()=>{if(E.tag==="Nothing")return S;if(E.tag==="Just")return E._1;g()})(),O=Z(4);if(_==="South")return k(F,(T._1.position._2+T._1.size._2)*O);if(_==="North")return k(F,T._1.position._2*O);if(_==="East")return k((T._1.position._1+T._1.size._1)*O,F);if(_==="West")return k(T._1.position._1*O,F)}}g()};return $(_=>{const h=Ua(_.edge.id)(c);if(h.tag==="Nothing")return _;if(h.tag==="Just")return{..._,fromPos:Ee(3)(_.edge.from.node)==="$d:"?k(h._1,_.fromPos._2):_.fromPos,toPos:Ee(3)(_.edge.to.node)==="$d:"?k(h._1,_.toPos._2):_.toPos};g()})($(_=>{if(_.from.port.tag==="Just"&&_.to.port.tag==="Just")return{edge:_,fromPos:a(_.from.node,_.from.port._1,ve),toPos:a(_.to.node,_.to.port._1,we),fromSide:ve,toSide:we};const h=f(_);return{edge:_,fromPos:l(h.from,_.from.node,_.id,s,p=>m=>{const x=hr(m.to.node)(u);if(x.tag==="Nothing")return 0;if(x.tag==="Just"){const J=Z(4);if(p==="South"||p==="North")return x._1.position._1*J+x._1.size._1*J/2;if(p==="East"||p==="West")return x._1.position._2*J+x._1.size._2*J/2}g()},p=>p.from),toPos:l(h.to,_.to.node,_.id,i,p=>m=>{const x=hr(m.from.node)(u);if(x.tag==="Nothing")return 0;if(x.tag==="Just"){const J=Z(4);if(p==="South"||p==="North")return x._1.position._1*J+x._1.size._1*J/2;if(p==="East"||p==="West")return x._1.position._2*J+x._1.size._2*J/2}g()},p=>p.to),fromSide:h.from,toSide:h.to}})(t))},z_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},Ro=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},LJ=(()=>{const t=nn.unfoldr(In);return e=>t(rn("IterNode",e,Pn))})(),Ka=t=>e=>t.gapTop+1*Z(4)+Z(e)*2.5*Z(4),CJ=t=>e=>{const n=z_(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return v("Just",{slot1Y:Ka(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Ka(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return N;g()}if(n.tag==="Nothing")return N;g()},SJ=t=>e=>{const n=w(r=>o=>j(I)(o.node)(o)(r))(D)(e);return un(Yt(r=>o=>{const i=Ro(o.node)(n);if(i.tag==="Nothing")return[];if(i.tag==="Just"){const s=i._1;return Yt(u=>a=>{const c=o.edges.length,f=Z(4),d=s.position._1*f,l=s.position._2*f,_=s.size._2*f,h=Z((2*c|0)+1|0),p=l+_*Z(c-u|0)/h,m=l+_*Z((c+1|0)+u|0)/h,x=d-f*2.5*Z(u+1|0),J=[{start:k(d,p),end:k(x,p),direction:de},{start:k(x,p),end:k(x,m),direction:le},{start:k(x,m),end:k(d,m),direction:de}];return{edge:a.id,segments:J,bends:Ie(y=>T=>y.end,J,Gt(1,3,J)),bendType:[],jumps:[],reversed:!1}})(o.edges)}g()})($(r=>({node:r._1,edges:r._2}))(LJ(w(r=>o=>It(I)(_e)(o.from.node)([o])(r))(D)(t)))))},EJ=t=>e=>{const n=w(i=>s=>j(I)(s.node)(s)(i))(D)(e),r=i=>{const s=Ro(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.position._1;g()},o=i=>{const s=Ro(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.layer;g()};return Dt(i=>s=>{const u=nt.compare(o(i.edge.from.node))(o(s.edge.from.node));if(u==="EQ"){const a=rt.compare(r(i.edge.from.node))(r(s.edge.from.node));return a==="EQ"?rt.compare(r(i.edge.to.node))(r(s.edge.to.node)):a}return u})(t)},Ue=t=>{const e=Z(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}},GJ=t=>t.from.node===t.to.node,PJ=t=>e=>n=>r=>{const o=pJ(n)(TJ(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:o,bends:Ie(i=>s=>i.end,o,Gt(1,o.length,o)),bendType:[],jumps:[],reversed:!1}},IJ=t=>e=>n=>r=>{const o=[{start:k(r.fromPos._1,r.fromPos._2),end:k(r.fromPos._1,t.slot1Y),direction:le},{start:k(r.fromPos._1,t.slot1Y),end:k(t.splitX,t.slot1Y),direction:de},{start:k(t.splitX,t.slot1Y),end:k(t.splitX,t.slot2Y),direction:le},{start:k(t.splitX,t.slot2Y),end:k(r.toPos._1,t.slot2Y),direction:de},{start:k(r.toPos._1,t.slot2Y),end:k(r.toPos._1,r.toPos._2),direction:le}];return{edge:r.edge.id,segments:o,bends:Ie(i=>s=>i.end,o,Gt(1,5,o)),bendType:[],jumps:[],reversed:!1}},AJ=t=>e=>n=>{const r=Ro(t.edge.from.node)(n);if(r.tag==="Just"){const i=Ro(t.edge.to.node)(n);return i.tag==="Just"?at(s=>!(s.h===Ue(r._1).h&&s.w===Ue(r._1).w&&s.x===Ue(r._1).x&&s.y===Ue(r._1).y)&&!(s.h===Ue(i._1).h&&s.w===Ue(i._1).w&&s.x===Ue(i._1).x&&s.y===Ue(i._1).y),e):at(s=>!(s.h===Ue(r._1).h&&s.w===Ue(r._1).w&&s.x===Ue(r._1).x&&s.y===Ue(r._1).y),e)}const o=Ro(t.edge.to.node)(n);return o.tag==="Just"?at(i=>!(i.h===Ue(o._1).h&&i.w===Ue(o._1).w&&i.x===Ue(o._1).x&&i.y===Ue(o._1).y),e):at(i=>!0,e)},DJ=t=>e=>{const n=z_(e.edge.id)(t);if(n.tag==="Just")return v("Just",Ka(n._1)(n._1.slot));if(n.tag==="Nothing")return N;g()},BJ=t=>e=>n=>r=>o=>{const i=w(c=>f=>j(I)(f.node)(f)(c))(D)(e),s=bJ(e),u=F_(at(c=>c.from.node!==c.to.node,t))(e)(n)(r)(o),a=G_(u)(e);return[...SJ(at(GJ,t))(e),...w(c=>f=>{const d=AJ(f)(s)(i),l=[...d,...c.edgeObstacles],_=CJ(a)(f),h=(()=>{if(_.tag==="Just")return IJ(_._1)(d)(l)(f);if(_.tag==="Nothing")return PJ(DJ(a)(f))(d)(l)(f);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...gJ(h.segments)]}})({results:[],edgeObstacles:[]})(EJ(u)(e)).results]},Pr=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ir=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},RJ=t=>e=>n=>{if(t.start._1!==e.start._1)return N;const r=Ir(Pr(t.start._2)(t.end._2))(Pr(e.start._2)(e.end._2)),o=Pr(Ir(t.start._2)(t.end._2))(Ir(e.start._2)(e.end._2));return r<o?v("Just",{position:k(t.start._1,(r+o)/2),crossingEdge:n}):N},QJ=t=>e=>n=>{if(t.start._2!==e.start._2)return N;const r=Ir(Pr(t.start._1)(t.end._1))(Pr(e.start._1)(e.end._1)),o=Pr(Ir(t.start._1)(t.end._1))(Ir(e.start._1)(e.end._1));return r<o?v("Just",{position:k((r+o)/2,t.start._2),crossingEdge:n}):N},FJ=t=>e=>n=>{if(t.direction==="H")return QJ(t)(e)(n);if(t.direction==="V")return RJ(t)(e)(n);g()},zJ=t=>e=>n=>{const r=t+1|0,o=r<1?n:Gt(r,n.length,n);return Lt(e.segments)(i=>Lt(o)(s=>xt(u=>FJ(i)(u)(s.edge))(at(u=>u.direction==="H"?i.direction==="H":u.direction==="V"&&i.direction==="V",s.segments))))},MJ=t=>e=>n=>e.start._1>Pr(t.start._1)(t.end._1)&&e.start._1<Ir(t.start._1)(t.end._1)&&t.start._2>Pr(e.start._2)(e.end._2)&&t.start._2<Ir(e.start._2)(e.end._2)?v("Just",{position:k(e.start._1,t.start._2),crossingEdge:n}):N,HJ=t=>e=>Lt(at(n=>n.direction==="H",t.segments))(n=>Lt(e)(r=>xt(o=>MJ(n)(o)(r.edge))(at(o=>o.direction==="V",r.segments)))),OJ=t=>e=>n=>[...HJ(e)(at(r=>r.edge!==e.edge,n)),...zJ(t)(e)(n)],M_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},H_=t=>Ee(3)(t)==="$d:",qJ=t=>e=>n=>w(r=>o=>{const i=M_(o.from.node)(t),s=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})(),u=M_(o.to.node)(t),a=(()=>{if(u.tag==="Nothing")return-s;if(u.tag==="Just")return u._1-s|0;g()})();if(a<=1)return{...r,edges:[...r.edges,o],chains:[...r.chains,{edgeId:o.id,nodes:[o.from.node,o.to.node]}]};const c=o.id,f=$(l=>"$d:"+c+":"+ee(l))(Ut(1,a-1|0)),d=[o.from.node,...f,o.to.node];return{...r,layers:w(l=>_=>{const h=_._2,p=Kh(s+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;g()})(r.layers)(Ie(En,Ut(1,a-1|0),f)),edges:[...r.edges,...Ie(l=>_=>({id:c+":"+l+"->"+_,from:{node:l,port:o.from.port},to:{node:_,port:o.to.port},label:N}),d,Gt(1,d.length,d))],chains:[...r.chains,{edgeId:o.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),Gs=(()=>{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=I.compare(e._1)(n._1);if(r==="LT")return Le;if(r==="GT")return Ce;if(e._2==="North")return n._2==="North"?Oe:Le;if(n._2==="North")return Ce;if(e._2==="South")return n._2==="South"?Oe:Le;if(n._2==="South")return Ce;if(e._2==="East")return n._2==="East"?Oe:Le;if(n._2==="East")return Ce;if(e._2==="West"&&n._2==="West")return Oe;g()},Eq0:()=>t}})(),$J=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=Gs.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},WJ=ae(I)(zt),ja=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},YJ=ae(Gs)(zt),O_=(()=>{const t=nn.unfoldr(In);return e=>t(rn("IterNode",e,Pn))})(),Qo=t=>e=>n=>r=>{const o=$J(k(e,n))(t);if(o.tag==="Nothing")return r;if(o.tag==="Just")return o._1;g()},q_=t=>e=>n=>{const r=WJ(un($(s=>Yt(u=>a=>k(a,u))(s))(t))),o=(s,u)=>{if(s==="South"){const a=ja(u.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()}if(s==="North"){const a=ja(u.from.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()}return 0},i=s=>w(u=>a=>ze(Gs.compare,Qe,YJ($(c=>k(k(c._1,s),c._2))(O_(Q_({lo:0,hi:(()=>{const c=ja(a._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return Ee(3)(a._1)==="$d:"?0:1;g()})()})($(c=>c.id)(Dt(c=>f=>nt.compare(o(s,c))(o(s,f)))(a._2)))))),u))(D)(O_(w(u=>a=>a.from.node===a.to.node?u:s==="South"?It(I)(_e)(a.from.node)([a])(u):s==="North"?It(I)(_e)(a.to.node)([a])(u):u)(D)(e)));return ze(Gs.compare,Qe,i(we),i(ve))},$_=t=>t,W_=t=>t,Y_=t=>t,VJ=w(t=>e=>j(I)(e)()(t))(D),UJ=(()=>{const t=nn.unfoldr(e=>{if(e.tag==="Nil")return N;if(e.tag==="Cons")return v("Just",k(e._1,e._2));g()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Xt("Cons",r._3,n(r._6,o)));g()};return n(e,Ht)})())})(),it=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},yn=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},qn=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},$n=ae(I)(zt),Za=bg(I),tc=(()=>{const t=nn.unfoldr(In);return e=>t(rn("IterNode",e,Pn))})(),XJ=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},KJ=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=nt.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},V_=Y_("VDown"),U_=Y_("VUp"),jJ=W_("ForwardPhase"),ZJ=W_("StackPhase"),X_=$_("HRight"),K_=$_("HLeft"),j_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},tN=t=>e=>n=>{const r=w(s=>u=>It(I)(pe)(u.tgt)(1)(s))(D)(t),o=UJ(VJ([...$(s=>s.src)(t),...$(s=>s.tgt)(t),...(()=>{const s=(u,a)=>{if(u.tag==="Leaf")return a;if(u.tag==="Node")return s(u._5,Xt("Cons",u._4,s(u._6,a)));g()};return qt(ue.foldr,s(e,Ht))})()])),i=w(s=>u=>It(I)(_e)(u.src)([{target:u.tgt,sep:u.sep}])(s))(D)(t);return(s=>u=>a=>{let c=s,f=u,d=a,l=!0,_;for(;l;){const h=c,p=f,m=d,x=Mt(J=>N,J=>y=>v("Just",{head:J,tail:y}),h);if(x.tag==="Nothing"){l=!1,_=m;continue}if(x.tag==="Just"){const J=it(x._1.head)(m),y=(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;g()})(),T=w(b=>C=>{const S=it(C.target)(b.result),E=y+C.sep,F=it(C.target)(b.indeg),O=(()=>{if(F.tag==="Nothing")return-1;if(F.tag==="Just")return F._1-1|0;g()})();return{newQueue:O===0?[...b.newQueue,C.target]:b.newQueue,result:j(I)(C.target)((()=>{if(S.tag==="Nothing")return E;if(S.tag==="Just"){if(n==="VDown")return yn(S._1)(E);if(n==="VUp")return qn(S._1)(E)}g()})())(b.result),indeg:j(I)(C.target)(O)(b.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const b=it(x._1.head)(i);if(b.tag==="Nothing")return[];if(b.tag==="Just")return b._1;g()})());c=[...x._1.tail,...T.newQueue],f=T.indeg,d=T.result;continue}g()}return _})(at(s=>{const u=it(s)(r);if(u.tag==="Nothing")return!0;if(u.tag==="Just")return u._1===0;g()},o))(r)(w(s=>u=>j(I)(u)(0)(s))(D)(o))},eN=t=>{const e=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return e(i._5,Xt("Cons",i._4,e(i._6,s)));g()},n=qt(ue.foldr,e(t,Ht)),r=w(yn)(999999)(n);if(r===0||n.length===0)return t;const o=i=>{if(i.tag==="Leaf")return D;if(i.tag==="Node")return Kt("Node",i._1,i._2,i._3,i._4-r,o(i._5),o(i._6));g()};return o(t)},Z_=t=>{const e=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return e(i._5,Xt("Cons",i._4,e(i._6,s)));g()},n=e(t,Ht),r=i=>s=>{let u=i,a=s,c=!0,f;for(;c;){const d=u,l=a;if(l.tag==="Nil"){c=!1,f=d;continue}if(l.tag==="Cons"){u=qn(d)(l._1),a=l._2;continue}g()}return f},o=i=>s=>{let u=i,a=s,c=!0,f;for(;c;){const d=u,l=a;if(l.tag==="Nil"){c=!1,f=d;continue}if(l.tag==="Cons"){u=yn(d)(l._1),a=l._2;continue}g()}return f};return r(-999999)(n)-o(999999)(n)},pi=t=>e=>(n=>r=>{let o=n,i=r,s=!0,u;for(;s;){const a=o,c=i;if(a===e){s=!1,u=c;continue}o=(()=>{const f=it(a)(t.align);if(f.tag==="Nothing")return e;if(f.tag==="Just")return f._1;g()})(),i=[...c,a]}return u})((()=>{const n=it(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;g()})())([e]),nN=t=>e=>n=>r=>o=>i=>s=>u=>a=>c=>f=>{const d=(P,R,Q)=>{const B=P.from.node===R?P.from.port:P.to.node===R?P.to.port:N;if(B.tag==="Just"){const q=it(R)(o);if(q.tag==="Just"){const et=oe(V=>V.id===B._1)(q._1);if(et.tag==="Just"){const V=Z(et._1.offset)*Z(4);return Q==="North"||Q==="South"?V:0}if(et.tag==="Nothing"){const V=it(R)(r),Y=Qo(s)(P.id)(Q)((()=>{if(V.tag==="Nothing")return .5;if(V.tag==="Just")return V._1._1/2;g()})());return Q==="North"||Q==="South"?Y:0}g()}if(q.tag==="Nothing"){const et=it(R)(r),V=Qo(s)(P.id)(Q)((()=>{if(et.tag==="Nothing")return .5;if(et.tag==="Just")return et._1._1/2;g()})());return Q==="North"||Q==="South"?V:0}g()}if(B.tag==="Nothing"){const q=it(R)(r),et=Qo(s)(P.id)(Q)((()=>{if(q.tag==="Nothing")return .5;if(q.tag==="Just")return q._1._1/2;g()})());return Q==="North"||Q==="South"?et:0}g()},l=(P,R)=>{if(P.from.node===R){if(f==="HRight")return ve;if(f==="HLeft")return we;g()}if(f==="HRight")return we;if(f==="HLeft")return ve;g()},_=(P,R,Q)=>w(B=>q=>j(I)(q)((()=>{const et=it(q)(B);if(et.tag==="Nothing")return 0+R;if(et.tag==="Just")return et._1+R;g()})())(B))(Q)(pi(a)(P)),h=(()=>{if(f==="HRight")return n;if(f==="HLeft")return ge(n);g()})(),p=P=>{const R=it(P)(r);if(R.tag==="Nothing")return 1;if(R.tag==="Just")return R._1._1;g()},m=$n(un(Yt(P=>R=>$(Q=>k(Q,P))(R))(n))),x=(P,R)=>Ee(3)(P)==="$d:"&&Ee(3)(R)==="$d:"||Ee(3)(P)==="$d:"||Ee(3)(R)==="$d:"?10:Z(t.nodeGap),J=w(P=>R=>Za(Q=>v("Just",[...(()=>{if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;g()})(),R]))(R.to.node)(P))(D)(i),y=w(P=>R=>Za(Q=>v("Just",[...(()=>{if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;g()})(),R]))(R.from.node)(P))(D)(i),T=un(n),b=w(P=>R=>{const Q=it(R)(a.root),B=(()=>{if(Q.tag==="Nothing")return R;if(Q.tag==="Just")return Q._1;g()})();return R===B?P:Za(q=>v("Just",(()=>{if(q.tag==="Nothing")return!0;if(q.tag==="Just")return q._1;g()})()&&Ee(3)(R)==="$d:"))(B)(P)})($n($(P=>k(P,!0))(ho(I.compare)((()=>{const P=(R,Q)=>{if(R.tag==="Leaf")return Q;if(R.tag==="Node")return P(R._5,Xt("Cons",R._4,P(R._6,Q)));g()};return qt(ue.foldr,P(a.root,Ht))})()))))(T),C=(P,R)=>{const Q=P.free,B=it(Q)(a.root),q=(()=>{if(B.tag==="Nothing")return Q;if(B.tag==="Just")return B._1;g()})(),et=it(q)(b),V=(()=>{if(et.tag==="Nothing")return!0;if(et.tag==="Just")return et._1;g()})();return w(Y=>W=>{if(Y.edge.tag==="Just")return Y;if(Y.edge.tag==="Nothing"){if((()=>{const ct=it(q)(R.su);return!V&&(()=>{const yt=it(W.from.node)(m);return W.from.node!==W.to.node&&(()=>{const Ct=it(W.to.node)(m);return(()=>{if(yt.tag==="Nothing")return-1;if(yt.tag==="Just")return yt._1;g()})()===(()=>{if(Ct.tag==="Nothing")return-1;if(Ct.tag==="Just")return Ct._1;g()})()})()})()||(()=>{if(ct.tag==="Nothing")return!1;if(ct.tag==="Just")return ct._1;g()})()})())return Y;const X=W.from.node===Q?W.to.node:W.from.node,tt=it(X)(a.root),gt=(()=>{if(tt.tag==="Nothing")return X;if(tt.tag==="Just")return tt._1;g()})(),wt=gt!==q;return wt&&(()=>{const ct=it(gt)(R.blockFinished);if(ct.tag==="Nothing")return!1;if(ct.tag==="Just")return ct._1;g()})()?{...Y,edge:v("Just",W),hasEdges:!0}:{...Y,hasEdges:Y.hasEdges||wt}}g()})({edge:N,hasEdges:!1})((()=>{if(P.isRoot){if(f==="HRight"){const Y=it(Q)(J);if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1;g()}if(f==="HLeft"){const Y=it(Q)(y);if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1}g()}if(f==="HRight"){const Y=it(Q)(y);if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1;g()}if(f==="HLeft"){const Y=it(Q)(J);if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1}g()})())},S=(P,R,Q,B)=>{const q=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),et={free:R,isRoot:Q},V=C(et,B);if(V.edge.tag==="Nothing")return V.hasEdges?{thresh:q,state:{...B,queue:[...B.queue,et]}}:{thresh:q,state:B};if(V.edge.tag==="Just"){const Y=V.edge._1.from.node===R?V.edge._1.to.node:V.edge._1.from.node;return{thresh:(()=>{const W=it((()=>{const wt=it(Y)(a.root);if(wt.tag==="Nothing")return Y;if(wt.tag==="Just")return wt._1;g()})())(B.x),X=it(Y)(u),tt=it(R)(u),gt=(()=>{if(W.tag==="Just")return W._1;if(W.tag==="Nothing")return N;g()})();return(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;g()})()+(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;g()})()+d(V.edge._1,Y,(()=>{if(Q){if(f==="HRight")return ve;if(f==="HLeft")return we;g()}if(f==="HRight")return we;if(f==="HLeft")return ve;g()})())-(()=>{if(tt.tag==="Nothing")return 0;if(tt.tag==="Just")return tt._1;g()})()-d(V.edge._1,R,(()=>{if(Q){if(f==="HRight")return we;if(f==="HLeft")return ve;g()}if(f==="HRight")return ve;if(f==="HLeft")return we;g()})())})(),state:{...B,su:j(I)((()=>{const W=it(V.edge._1.from.node)(a.root);if(W.tag==="Nothing")return V.edge._1.from.node;if(W.tag==="Just")return W._1;g()})())(!0)(j(I)((()=>{const W=it(V.edge._1.to.node)(a.root);if(W.tag==="Nothing")return V.edge._1.to.node;if(W.tag==="Just")return W._1;g()})())(!0)(B.su))}}}g()},E=(P,R,Q,B)=>{const q=R===P,et=it(R)(a.align),V=(()=>{if(et.tag==="Nothing")return R===P;if(et.tag==="Just")return et._1===P;g()})();if(!(q||V))return{thresh:Q,state:B};const Y=(()=>{if(c==="VDown")return q&&Q<=-1e18;if(c==="VUp")return q&&Q>=1e18;g()})()?S(P,R,!0,B):{thresh:Q,state:B};return(()=>{if(c==="VDown")return Y.thresh<=-1e18&&V;if(c==="VUp")return Y.thresh>=1e18&&V;g()})()?S(P,R,!1,Y.state):Y},F=P=>R=>Q=>{const B=it(Q)(e.nodeIndex),q=(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})(),et=oe(tt=>Ve(Qn)(Q)(tt))(h),V=(()=>{if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;g()})(),Y=V.length;if((()=>{if(c==="VDown")return q<=0;if(c==="VUp")return q>=(Y-1|0);g()})()){const tt=E(P,Q,R.thresh,R.st);return{...R,st:tt.state,thresh:tt.thresh}}const W=(()=>{if(c==="VDown")return q-1|0;if(c==="VUp")return q+1|0;g()})(),X=W>=0&&W<V.length?v("Just",V[W]):N;if(X.tag==="Nothing")return R;if(X.tag==="Just"){const tt=it(X._1)(a.root),gt=(()=>{if(tt.tag==="Nothing")return X._1;if(tt.tag==="Just")return tt._1;g()})(),wt=E(P,Q,R.thresh,O(gt)(R.st)),ct=(()=>{const At=it(P)(wt.state.sink);if(At.tag==="Nothing")return P===P;if(At.tag==="Just")return At._1===P;g()})()?{...wt.state,sink:j(I)(P)((()=>{const At=it(gt)(wt.state.sink);if(At.tag==="Nothing")return gt;if(At.tag==="Just")return At._1;g()})())(wt.state.sink)}:wt.state,yt=it(gt)(ct.sink),Ct=(()=>{if(yt.tag==="Nothing")return gt;if(yt.tag==="Just")return yt._1;g()})(),Vt=it(P)(ct.sink),mt=(()=>{if(Vt.tag==="Nothing")return P;if(Vt.tag==="Just")return Vt._1;g()})();if(mt===Ct){const At=it(gt)(ct.x),Zt=(()=>{if(At.tag==="Just")return At._1;if(At.tag==="Nothing")return N;g()})(),ln=(()=>{if(Zt.tag==="Nothing")return 0;if(Zt.tag==="Just")return Zt._1;g()})(),Ae=it(P)(ct.x),Qt=(()=>{if(Ae.tag==="Just")return Ae._1;if(Ae.tag==="Nothing")return N;g()})(),Bt=(()=>{if(Qt.tag==="Nothing")return 0;if(Qt.tag==="Just")return Qt._1;g()})(),De=x(Q,X._1),hn=it(X._1)(u),We=it(Q)(u),en=(()=>{if(hn.tag==="Nothing")return 0;if(hn.tag==="Just")return hn._1;g()})()-(()=>{if(We.tag==="Nothing")return 0;if(We.tag==="Just")return We._1;g()})();if(c==="VDown"){const Pe=qn(ln+en+p(X._1)+De)(wt.thresh);return{st:{...ct,x:j(I)(P)(v("Just",R.initial?Pe:qn(Bt)(Pe)))(ct.x)},initial:!1,thresh:wt.thresh}}if(c==="VUp"){const Pe=yn(ln+en-De-p(Q))(wt.thresh);return{st:{...ct,x:j(I)(P)(v("Just",R.initial?Pe:yn(Bt)(Pe)))(ct.x)},initial:!1,thresh:wt.thresh}}g()}const Wt=it(gt)(ct.x),kt=(()=>{if(Wt.tag==="Just")return Wt._1;if(Wt.tag==="Nothing")return N;g()})(),lt=(()=>{if(kt.tag==="Nothing")return 0;if(kt.tag==="Just")return kt._1;g()})(),ft=it(P)(ct.x),ot=(()=>{if(ft.tag==="Just")return ft._1;if(ft.tag==="Nothing")return N;g()})(),_t=(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;g()})(),st=Z(t.nodeGap),ut=it(Q)(u),Jt=it(X._1)(u),vt=(()=>{if(ut.tag==="Nothing")return 0;if(ut.tag==="Just")return ut._1;g()})()-(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;g()})();return{st:{...ct,classEdges:[...ct.classEdges,{src:mt,tgt:Ct,sep:(()=>{if(c==="VDown")return _t+vt-lt-p(X._1)-st;if(c==="VUp")return _t+vt+p(Q)+st-lt;g()})()}]},initial:R.initial,thresh:wt.thresh}}g()},O=P=>R=>{const Q=it(P)(R.x),B=(()=>{if(Q.tag==="Just")return Q._1;if(Q.tag==="Nothing")return N;g()})();if(B.tag==="Just")return R;if(B.tag==="Nothing"){const q=w(F(P))({st:{...R,x:j(I)(P)(v("Just",0))(R.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})()})(pi(a)(P));return{...q.st,blockFinished:j(I)(P)(!0)(q.st.blockFinished)}}g()},G=w(P=>R=>w(Q=>B=>{const q=it(B)(a.root),et=(()=>{if(q.tag==="Nothing")return B;if(q.tag==="Just")return q._1;g()})();return et===B?O(et)(Q):Q})(P)((()=>{if(c==="VDown")return R;if(c==="VUp")return ge(R);g()})()))({x:$n($(P=>k(P,N))(T)),sink:$n($(P=>k(P,P))(T)),classEdges:[],su:D,blockFinished:D,queue:[]})(h),A=tN(G.classEdges)(G.sink)(c),K=(P,R,Q,B)=>{const q=it(R)(B),et=it(R)(u);return(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;g()})()+(()=>{if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1;g()})()+d(P,R,Q)},U=$n($(P=>k(P,!0))(ho(I.compare)((()=>{const P=(R,Q)=>{if(R.tag==="Leaf")return Q;if(R.tag==="Node")return P(R._5,Xt("Cons",R._4,P(R._6,Q)));g()};return qt(ue.foldr,P(a.root,Ht))})()))),z=P=>R=>Q=>{const B=C(Q,{su:R.su,blockFinished:U}),q={phase:P,ppFree:Q.free,ppIsRoot:Q.isRoot,edgeId:N,delta:0,avail:0,shift:0,freeSu:(()=>{const et=it((()=>{const V=it(Q.free)(a.root);if(V.tag==="Nothing")return Q.free;if(V.tag==="Just")return V._1;g()})())(R.su);if(et.tag==="Nothing")return!1;if(et.tag==="Just")return et._1;g()})(),hasEdges:B.hasEdges,candCount:(()=>{if(Q.isRoot){if(f==="HRight"){const et=it(Q.free)(J);if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1.length;g()}if(f==="HLeft"){const et=it(Q.free)(y);if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1.length}g()}if(f==="HRight"){const et=it(Q.free)(y);if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1.length;g()}if(f==="HLeft"){const et=it(Q.free)(J);if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1.length}g()})()};if(B.edge.tag==="Nothing")return{...R,stack:[...R.stack,Q],trace:[...R.trace,q],x:R.x};if(B.edge.tag==="Just"){const et=B.edge._1.from.node===Q.free?k(B.edge._1.from.node,B.edge._1.to.node):k(B.edge._1.to.node,B.edge._1.from.node),V=K(B.edge._1,et._1,l(B.edge._1,et._1),R.x)-K(B.edge._1,et._2,l(B.edge._1,et._2),R.x),Y=it(et._1)(a.root),W=(()=>{if(Y.tag==="Nothing")return et._1;if(Y.tag==="Just")return Y._1;g()})(),X={...q,edgeId:v("Just",B.edge._1.id),delta:V};if(V>0&&V<1e300){const tt=w(ct=>yt=>{const Ct=it(yt)(m),Vt=(()=>{if(Ct.tag==="Nothing")return-1;if(Ct.tag==="Just")return Ct._1;g()})();if(Vt>=0&&Vt<n.length){const kt=n[Vt],lt=it(yt)(e.nodeIndex),ft=(()=>{if(lt.tag==="Nothing")return-2;if(lt.tag==="Just")return lt._1-1|0;g()})();return ft>=0&&ft<kt.length?yn(ct)((()=>{const ot=it(yt)(R.x),_t=it(yt)(u),st=it(kt[ft])(R.x),ut=it(kt[ft])(u);return(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;g()})()+(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;g()})()-((()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;g()})()+(()=>{if(ut.tag==="Nothing")return 0;if(ut.tag==="Just")return ut._1;g()})()+p(kt[ft])+x(yt,kt[ft]))})()):ct}const mt=it(yt)(e.nodeIndex),Wt=(()=>{if(mt.tag==="Nothing")return-2;if(mt.tag==="Just")return mt._1-1|0;g()})();return Wt>=0&&Wt<0?yn(ct)((()=>{const kt=it(yt)(R.x),lt=it(yt)(u),ft=it([][Wt])(R.x),ot=it([][Wt])(u);return(()=>{if(kt.tag==="Nothing")return 0;if(kt.tag==="Just")return kt._1;g()})()+(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()-((()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;g()})()+(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;g()})()+p([][Wt])+x(yt,[][Wt]))})()):ct})(V)(pi(a)(W)),gt=tt>0?-tt:0,wt={...R,x:tt>0?_(W,gt,R.x):R.x,trace:[...R.trace,{...X,avail:tt,shift:gt}]};return tt>0?wt:{...wt,stack:[...wt.stack,Q]}}if(V<0&&-V<1e300){const tt=w(ct=>yt=>{const Ct=it(yt)(m),Vt=(()=>{if(Ct.tag==="Nothing")return-1;if(Ct.tag==="Just")return Ct._1;g()})();if(Vt>=0&&Vt<n.length){const kt=n[Vt],lt=it(yt)(e.nodeIndex),ft=(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1+1|0;g()})();return ft>=0&&ft<kt.length?yn(ct)((()=>{const ot=it(kt[ft])(R.x),_t=it(kt[ft])(u),st=it(yt)(R.x),ut=it(yt)(u);return(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;g()})()+(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;g()})()-((()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;g()})()+(()=>{if(ut.tag==="Nothing")return 0;if(ut.tag==="Just")return ut._1;g()})()+p(yt)+x(yt,kt[ft]))})()):ct}const mt=it(yt)(e.nodeIndex),Wt=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1+1|0;g()})();return Wt>=0&&Wt<0?yn(ct)((()=>{const kt=it([][Wt])(R.x),lt=it([][Wt])(u),ft=it(yt)(R.x),ot=it(yt)(u);return(()=>{if(kt.tag==="Nothing")return 0;if(kt.tag==="Just")return kt._1;g()})()+(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()-((()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;g()})()+(()=>{if(ot.tag==="Nothing")return 0;if(ot.tag==="Just")return ot._1;g()})()+p(yt)+x(yt,[][Wt]))})()):ct})(-V)(pi(a)(W)),gt=tt>0?tt:0,wt={...R,x:tt>0?_(W,gt,R.x):R.x,trace:[...R.trace,{...X,avail:tt,shift:gt}]};return tt>0?wt:{...wt,stack:[...wt.stack,Q]}}return{...R,stack:[...R.stack,Q],trace:[...R.trace,X],x:R.x}}g()},H=w(z(jJ))({x:$n($(P=>k(P,(()=>{const R=it(P)(a.root),Q=(()=>{if(R.tag==="Nothing")return P;if(R.tag==="Just")return R._1;g()})(),B=it(Q)(G.x),q=it((()=>{const V=it(Q)(G.sink);if(V.tag==="Nothing")return Q;if(V.tag==="Just")return V._1;g()})())(A),et=(()=>{if(B.tag==="Just")return B._1;if(B.tag==="Nothing")return N;g()})();return(()=>{if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1;g()})()+(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;g()})()})()))(T)),su:G.su,stack:[],trace:[]})(G.queue),M=w(z(ZJ))({...H,stack:[]})(ge(H.stack));return{x:M.x,queue:G.queue,trace:M.trace}},rN=t=>e=>n=>r=>o=>i=>s=>u=>a=>c=>f=>nN(t)(e)(n)(r)(o)(i)(s)(u)(a)(c)(f).x,oN=t=>e=>n=>r=>o=>i=>{const s=(a,c,f)=>{const d=it(c)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;g()})(),_=a.from.node===c?a.from.port:a.to.node===c?a.to.port:N;if(_.tag==="Just"){const h=it(c)(e);if(h.tag==="Just"){const p=oe(m=>m.id===_._1)(h._1);if(p.tag==="Just"){const m=Z(p._1.offset)*Z(4);return f==="North"||f==="South"?m:0}if(p.tag==="Nothing"){const m=Qo(o)(a.id)(f)(l);return f==="North"||f==="South"?m:0}g()}if(h.tag==="Nothing"){const p=Qo(o)(a.id)(f)(l);return f==="North"||f==="South"?p:0}g()}if(_.tag==="Nothing"){const h=Qo(o)(a.id)(f)(l);return f==="North"||f==="South"?h:0}g()},u=a=>c=>f=>d=>{let l=a,_=c,h=f,p=d,m=!0,x;for(;m;){const J=l,y=_,T=h,b=Mt(C=>N,C=>S=>v("Just",{head:C,tail:S}),p);if(b.tag==="Nothing"){m=!1,x=J;continue}if(b.tag==="Just"){const C=b._1.head,S=oe(F=>F.from.node===T&&F.to.node===C||F.from.node===C&&F.to.node===T)(r),E=(()=>{if(S.tag==="Nothing")return y+0;if(S.tag==="Just")return y+(s(S._1,T,S._1.from.node===T?ve:we)-s(S._1,C,S._1.from.node===C?ve:we));g()})();l=j(I)(C)(E)(J),_=E,h=C,p=b._1.tail;continue}g()}return x};return w(a=>c=>{const f=Mt(_=>N,_=>h=>v("Just",{head:_,tail:h}),pi(t)(c)),d=(()=>{if(f.tag==="Nothing")return j(I)(c)(0)(D);if(f.tag==="Just")return u(j(I)(f._1.head)(0)(D))(0)(f._1.head)(f._1.tail);g()})(),l=w(_=>h=>qn(_)(-h._2))(0)(tc(d));return w(_=>h=>j(I)(h._1)(h._2+l)(_))(a)(tc(d))})(D)(ho(I.compare)((()=>{const a=(c,f)=>{if(c.tag==="Leaf")return f;if(c.tag==="Node")return a(c._5,Xt("Cons",c._4,a(c._6,f)));g()};return qt(ue.foldr,a(t.root,Ht))})()))},iN=t=>e=>{const n=(o,i,s)=>Ee(3)(i)==="$d:"&&yg(H_,(()=>{const u=it(i)(t.preds);if(u.tag==="Nothing")return[];if(u.tag==="Just")return u._1;g()})()),r=o=>i=>s=>u=>a=>c=>f=>{let d=o,l=i,_=u,h=c,p=f,m=!0,x;for(;m;){const J=d,y=l,T=_,b=h,C=p,S=y.length;if(C>=S){m=!1,x=J;continue}const E=C>=0&&C<y.length?v("Just",y[C]):N,F=(()=>{if(E.tag==="Nothing")return"";if(E.tag==="Just")return E._1;g()})(),O=n(t,F);if(C===(S-1|0)||O){const G=(()=>{if(O){const A=it(F)(t.preds),K=(()=>{if(A.tag==="Nothing")return[];if(A.tag==="Just")return A._1;g()})();if(0<K.length){const U=T-1|0,z=it(K[0])(t.nodeIndex);if(z.tag==="Nothing")return U;if(z.tag==="Just")return z._1;g()}}return T-1|0})();d=w(A=>K=>{if(K>=0&&K<y.length){const U=y[K];return n(t,U)?A:w(z=>H=>{const M=it(H)(t.nodeIndex),P=(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;g()})();return P<b||P>G?j(I)(H+"\u2192"+U)()(z):z})(A)((()=>{const z=it(U)(t.preds);if(z.tag==="Nothing")return[];if(z.tag==="Just")return z._1;g()})())}return n(t,"")?A:w(U=>z=>{const H=it(z)(t.nodeIndex),M=(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})();return M<b||M>G?j(I)(z+"\u2192")()(U):U})(A)((()=>{const U=it("")(t.preds);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;g()})())})(J)(Ut(0,C)),l=y,_=T,h=G,p=C+1|0;continue}d=J,l=y,_=T,h=b,p=C+1|0}return x};return e.length<3?D:w(o=>i=>{if(i>=0&&i<e.length){const s=e[i];return r(o)((()=>{const u=i+1|0;return u>=0&&u<e.length?e[u]:[]})())(s)(s.length)(i)(0)(0)}return r(o)((()=>{const s=i+1|0;return s>=0&&s<e.length?e[s]:[]})())([])(0)(i)(0)(0)})(D)(Ut(1,e.length-2|0))},sN=t=>e=>n=>r=>o=>{const i=un(e),s=w(u=>a=>{const c=w(f=>d=>{const l=(()=>{if(o==="HRight"){const m=it(d)(t.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()}if(o==="HLeft"){const m=it(d)(t.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}g()})(),_=l.length;if(_===0)return f;const h=rr(_-1|0,2),p=rr(_,2);return w(m=>x=>{if((()=>{const J=it(d)(m.align);if(J.tag==="Nothing")return d!==d;if(J.tag==="Just")return J._1!==d;g()})())return m;if(x>=0&&x<l.length){const J=it(l[x])(t.nodeIndex),y=(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;g()})();if(!(j_(l[x]+"\u2192"+d)(n)||j_(d+"\u2192"+l[x])(n))&&(()=>{if(r==="VDown")return m.r<y;if(r==="VUp")return m.r>y;g()})()){const T=it(l[x])(m.root),b=(()=>{if(T.tag==="Nothing")return l[x];if(T.tag==="Just")return T._1;g()})();return{root:j(I)(d)(b)(m.root),align:j(I)(l[x])(d)(j(I)(d)(b)(m.align)),r:y}}}return m})(f)((()=>{if(r==="VDown")return Ut(h,p);if(r==="VUp")return ge(Ut(h,p));g()})())})({root:u.root,align:u.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;g()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return ge(a);g()})());return{root:c.root,align:c.align}})({root:$n($(u=>k(u,u))(i)),align:$n($(u=>k(u,u))(i))})((()=>{if(o==="HRight")return e;if(o==="HLeft")return ge(e);g()})());return{root:s.root,align:s.align}},Ps=t=>e=>n=>r=>o=>i=>s=>u=>a=>c=>{const f=sN(e)(n)(u)(a)(c),d=oN(f)(o)(r)(i)(s)(c);return gp()(l=>_=>v("Just",(()=>{const h=it(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;g()})()))(rN(t)(e)(n)(r)(o)(i)(s)(d)(f)(a)(c))},t1=t=>e=>Yt(n=>r=>w(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?[]:Gt(0,n,o)})()))(e),uN=t=>e=>n=>r=>o=>i=>s=>{const u=XJ(0)(e.length-1|0),a=Z(t.layerGap),c=s(Yh(u,a)),f=cJ(F_(o)(c)(r)(i)(D))(c);return $(d=>{const l=KJ(d)(f);return l.tag==="Just"&&l._1>0?qn(a)(2+Z(l._1-1|0)*2.5):a})(Ut(0,u-1|0))},e1=t=>e=>n=>r=>yg(o=>w(i=>s=>{if(!i.ok)return i;const u=it(s)(r),a=(()=>{if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()})(),c=it(s)(n),f=(()=>{if(c.tag==="Nothing")return a+1;if(c.tag==="Just")return a+c._1._1;g()})();return a+1e-4>i.pos&&f+1e-4>i.pos?{ok:!0,pos:f}:{ok:!1,pos:i.pos}})({ok:!0,pos:-1e18})(o).ok,e),aN=t=>e=>n=>r=>{const o=Dt(i=>s=>rt.compare(i.w)(s.w))($(i=>({l:i,w:Z_(i)}))(at(e1()(e)(n),r)));return 0<o.length?v("Just",o[0].l):N},cN=t=>e=>{const n=$n(un($(Yt(o=>i=>k(i,o)))(t))),r=o=>Dt(i=>s=>nt.compare((()=>{const u=it(i)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()})())((()=>{const u=it(s)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()})()))(o);return{preds:(()=>{const o=i=>{if(i.tag==="Leaf")return D;if(i.tag==="Node")return Kt("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(w(i=>s=>It(I)(_e)(s.to.node)([s.from.node])(i))(D)(e))})(),succs:(()=>{const o=i=>{if(i.tag==="Leaf")return D;if(i.tag==="Node")return Kt("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(w(i=>s=>It(I)(_e)(s.from.node)([s.to.node])(i))(D)(e))})(),nodeIndex:n}},gN=t=>e=>{const n=Dt(d=>l=>rt.compare(d.w)(l.w))(Yt(d=>l=>({i:d,l,w:Z_(l)}))(e)),r=0<n.length?v("Just",n[0]):N,o=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;g()})(),i=o>=0&&o<e.length?v("Just",e[o]):N,s=(()=>{if(i.tag==="Just")return(d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const x=_,J=h;if(J.tag==="Nil"){p=!1,m=x;continue}if(J.tag==="Cons"){_=yn(x)(J._1),h=J._2;continue}g()}return m})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,Xt("Cons",l._4,d(l._6,_)));g()};return d(i._1,Ht)})());if(i.tag==="Nothing")return 0;g()})(),u=d=>w(l=>_=>qn(l)((()=>{const h=it(_._1)(t);if(h.tag==="Nothing")return _._2+1;if(h.tag==="Just")return _._2+h._1._1;g()})()))(-999999)(tc(d)),a=o>=0&&o<e.length?v("Just",e[o]):N,c=(()=>{if(a.tag==="Just")return u(a._1);if(a.tag==="Nothing")return 0;g()})(),f=Ie(d=>l=>{const _=h=>{if(h.tag==="Leaf")return D;if(h.tag==="Node")return Kt("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));g()};return _(d)},e,Yt(d=>l=>br(d)(2)===0?s-(_=>h=>{let p=_,m=h,x=!0,J;for(;x;){const y=p,T=m;if(T.tag==="Nil"){x=!1,J=y;continue}if(T.tag==="Cons"){p=yn(y)(T._1),m=T._2;continue}g()}return J})(999999)((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,Xt("Cons",h._4,_(h._6,p)));g()};return _(l,Ht)})()):c-u(l))(e));return eN(w(d=>l=>{const _=Dt(rt.compare)(xt(it(l))(f));return j(I)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(D)(ho(I.compare)(un($(d=>{const l=_=>{if(_.tag==="Leaf")return D;if(_.tag==="Node")return Kt("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));g()};return qt(on.foldr,l(d))})(f)))))},fN=t=>e=>n=>r=>o=>i=>{const s=cN(e)(o),u=iN(s)(e),a={nodeGap:t.nodeGap*4|0},c=ze(I.compare,Qe,$n($(_=>k(_,k(1,1)))(at(H_,un(e)))),(()=>{const _=h=>{if(h.tag==="Leaf")return D;if(h.tag==="Node")return Kt("Node",h._1,h._2,h._3,k(h._4._1*Z(4),h._4._2),_(h._5),_(h._6));g()};return _(n)})()),f=[Ps(a)(s)(e)(c)(r)(o)(i)(u)(V_)(X_),Ps(a)(s)(e)(c)(r)(o)(i)(u)(U_)(X_),Ps(a)(s)(e)(c)(r)(o)(i)(u)(V_)(K_),Ps(a)(s)(e)(c)(r)(o)(i)(u)(U_)(K_)],d=gN(c)(f);if(e1()(e)(c)(d))return d;const l=aN()(e)(c)(f);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return f[0];g()},_N=t=>e=>n=>r=>{const o=hg(N,gg,i=>i.node===e?v("Just",i.position):N,t);if(o.tag==="Nothing")return t;if(o.tag==="Just"){const i=o._1;return $(s=>s.node===n?{...s,position:k(i._1+r._1,i._2+r._2)}:s)(t)}g()},dN=t=>e=>n=>r=>{const o=at(s=>Ve(Qn)(s.node)(e),t),i=(()=>{if(n==="Vertical"){if(r==="Start")return w(s=>u=>yn(s)(u.position._1))(99999)(o);if(r==="End")return w(s=>u=>qn(s)(u.position._1))(0)(o);if(r==="Center"){const s=w(u=>a=>u+a.position._1)(0)(o);return o.length===0?0:s/Z(o.length)}g()}if(n==="Horizontal"){if(r==="Start")return w(s=>u=>yn(s)(u.position._2))(99999)(o);if(r==="End")return w(s=>u=>qn(s)(u.position._2))(0)(o);if(r==="Center"){const s=w(u=>a=>u+a.position._2)(0)(o);return o.length===0?0:s/Z(o.length)}}g()})();return $(s=>{if(Ve(Qn)(s.node)(e)){if(n==="Vertical")return{...s,position:k(i,s.position._2)};if(n==="Horizontal")return{...s,position:k(s.position._1,i)};g()}return s})(t)},lN=t=>e=>w(n=>r=>r.tag==="AlignGroup"?dN(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?_N(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),hN=t=>e=>n=>r=>o=>i=>s=>u=>{const a=$(d=>w(l=>_=>qn(l)((()=>{const h=it(_)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;g()})()))(1)(d))(n),c=fN(t)(n)(r)(o)(i)(u),f=t1(uN(t)(n)(r)(o)(i)(s)(d=>{const l=t1(d)(a);return un(Yt(_=>h=>Yt(p=>m=>({node:m,position:k((()=>{const x=it(m)(c);return(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})()/Z(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const x=Ee(3)(m)==="$d:"?k(0,1):k(1,1),J=it(m)(r);if(J.tag==="Nothing")return x;if(J.tag==="Just")return J._1;g()})(),layer:_,order:p}))(h))(n))}))(a);return lN(e)(un(Yt(d=>l=>Yt(_=>h=>({node:h,position:k((()=>{const p=it(h)(c);return(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})()/Z(4)})(),d>=0&&d<f.length?f[d]:0),size:(()=>{const p=Ee(3)(h)==="$d:"?k(0,1):k(1,1),m=it(h)(r);if(m.tag==="Nothing")return p;if(m.tag==="Just")return m._1;g()})(),layer:d,order:_}))(l))(n)))},ec=ua(Ui)(qr(32)),n1=ua(Ui)(qr(31)),mi=(()=>{const t=e0("25214903917");if(t.tag==="Nothing")return Mg;if(t.tag==="Just")return t._1;g()})(),yi=sa(ua(Ui)(qr(48)))(Ui),pN=t=>{const e=n0(t);return ti(Hg((()=>{if(e.tag==="Nothing")return Mg;if(e.tag==="Just")return e._1;g()})())(mi))(yi)},nc=qr(11),Is=t=>e=>{const n=ti(Yi(Vi(e)(mi))(nc))(yi);return k((()=>{const r=Ng(Kp(aa(n)(qr(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},mN=t=>{const e=Is(26)(t),n=Is(27)(e._2);return k((Z(e._1)*Ou(2)(27)+Z(n._1))/Ou(2)(53),n._2)},yN=t=>e=>{const n=w(r=>o=>{const i=mN(r.finalR);return{rs:[...r.rs,i._1],finalR:i._2}})({rs:[],finalR:t})(e);return k($(r=>r.x)(Dt(r=>o=>rt.compare(r.k)(o.k))(Ie(r=>o=>({x:r,k:o}),e,n.rs))),n.finalR)},xN=t=>{const e=ti(Yi(Vi(t)(mi))(nc))(yi),n=ti(Yi(Vi(e)(mi))(nc))(yi);return k(Yi(Vi((()=>{const r=aa(e)(qr(16));return Og.compare(r)(n1)!=="LT"?sa(r)(ec):r})())(ec))((()=>{const r=aa(n)(qr(16));return Og.compare(r)(n1)!=="LT"?sa(r)(ec):r})()),n)},xi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},As=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},rc=ae(I)(zt),Fo=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},Ds=ae(I)(zt),JN=Fu(Vo),NN=w(Jo)(0),wN=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},r1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},vN=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const o=Tr(ne,N,t,n[e],n);if(o.tag==="Just")return Tr(ne,N,e,r,o._1);if(o.tag==="Nothing")return N;g()}}return N},TN=t=>e=>n=>r=>o=>rc(w(i=>s=>{const u=Dt(a=>c=>nt.compare((()=>{const f=xi(a.id)(o);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})())((()=>{const f=xi(c.id)(o);if(f.tag==="Nothing")return 1e6;if(f.tag==="Just")return f._1;g()})()))(at(a=>As(a.to.node)(n),at(a=>a.from.node===s,r)));return{ranks:[...i.ranks,...Yt(a=>c=>k(c.id,Z((i.rankSum+a|0)+1|0)))(u)],rankSum:i.rankSum+u.length|0}})({ranks:[],rankSum:0})(t).ranks),bN=t=>e=>n=>r=>o=>rc(w(i=>s=>{const u=Dt(c=>f=>{const d=nt.compare((()=>{const l=Fo(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=Fo(c.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})());return d==="EQ"?nt.compare((()=>{const l=xi(c.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})())((()=>{const l=xi(f.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})()):d})(at(c=>As(c.from.node)(n),at(c=>c.to.node===s,r))),a=u.length;return{ranks:[...i.ranks,...Yt(c=>f=>k(f.id,Z((i.rankSum+a|0)-c|0)))(u)],rankSum:i.rankSum+a|0}})({ranks:[],rankSum:0})(t).ranks),oc=t=>e=>n=>{const r=Ds(Yt(u=>a=>k(a,u))(t)),o=Ds(Yt(u=>a=>k(a,u))(e)),i=xt(u=>{const a=Fo(u.from.node)(r),c=Fo(u.to.node)(o);if(a.tag==="Just"&&c.tag==="Just")return v("Just",k(a._1,c._1));const f=Fo(u.from.node)(o),d=Fo(u.to.node)(r);return f.tag==="Just"&&d.tag==="Just"?v("Just",k(d._1,f._1)):N})(n),s=i.length;return w(u=>a=>w(c=>f=>a>=0&&a<i.length&&f>=0&&f<i.length&&((i[a]._1-i[f]._1|0)*(i[a]._2-i[f]._2|0)|0)<0?c+1|0:c)(u)(Ut(a+1|0,s-1|0)))(0)(Ut(0,s-2|0))},kN=t=>e=>n=>r=>{const o=i=>s=>{let u=i,a=s,c=!0,f;for(;c;){const d=u,l=a;if(l>=(d.length-1|0)){c=!1,f=d;continue}if(l>=0&&l<d.length){const _=l+1|0;if(_>=0&&_<d.length){const h=d[l],p=d[_];if(Ye(y=>y.before===h&&y.after===p,r)){u=d,a=l+1|0;continue}const m=Tr(ne,N,l,p,d),x=(()=>{if(m.tag==="Just")return Tr(ne,N,l+1|0,h,m._1);if(m.tag==="Nothing")return N;g()})(),J=(()=>{if(x.tag==="Nothing")return d;if(x.tag==="Just")return x._1;g()})();if(oc(e)(J)(n)<oc(e)(d)(n)){u=J,a=l+1|0;continue}u=d,a=l+1|0;continue}c=!1,f=d;continue}c=!1,f=d}return f};return(i=>{let s=i,u=!0,a;for(;u;){const c=s,f=o(c)(0);if(JN(f)(c)){u=!1,a=c;continue}s=f}return a})(t)},Bs=t=>e=>w(n=>r=>{if(r>=0&&r<t.length){const o=t[r],i=r+1|0;if(i>=0&&i<t.length)return n+oc(o)(t[i])(e)|0}return n})(0)(Ut(0,t.length-2|0)),LN=(()=>{const t=e=>{if(e.length<7){const i=s=>u=>{let a=s,c=u,f=!0,d;for(;f;){const l=a,_=c,h=_-1|0;if(h>=0&&h<l.length){if(_>=0&&_<l.length&&_>0&&l[h].key>l[_].key){const p=vN(_-1|0)(_)(l);if(p.tag==="Just"){a=p._1,c=_-1|0;continue}if(p.tag==="Nothing"){f=!1,d=l;continue}g()}f=!1,d=l;continue}f=!1,d=l}return d};return w(s=>u=>i(s)(u))(e)(Ut(1,e.length-1|0))}const n=rr(e.length,2),r=t(Gt(0,n,e)),o=t(Gt(n,e.length,e));return(i=>s=>u=>{let a=i,c=s,f=u,d=!0,l;for(;d;){const _=a,h=c,p=f;if(h>=0&&h<r.length){if(p>=0&&p<o.length){if(r[h].key>o[p].key){a=Pt(_)(o[p]),c=h,f=p+1|0;continue}a=Pt(_)(r[h]),c=h+1|0,f=p;continue}d=!1,l=[..._,...h<1?r:Gt(h,r.length,r)];continue}d=!1,l=[..._,...p<1?o:Gt(p,o.length,o)]}return l})([])(0)(0)};return t})(),CN=t=>e=>n=>{const r=xt(c=>c.tag==="OrderConstraint"?v("Just",{before:c._1.before,after:c._1.after}):N)(t.constraints),o=c=>w(f=>d=>{const l=d.after,_=d.before,h=Mr(ne,N,m=>m===_,f),p=Mr(ne,N,m=>m===l,f);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=mg(ne,N,h._1,f),x=(()=>{if(m.tag==="Nothing")return f;if(m.tag==="Just")return m._1;g()})(),J=pg(ne,N,p._1,_,x);if(J.tag==="Nothing")return x;if(J.tag==="Just")return J._1;g()}return f})(c)(r),i=rc(Yt(c=>f=>k(f.id,c))(n)),s=(c,f,d)=>{const l=c.length;return w(_=>h=>{const p=f?h-1|0:h+1|0,m=p>=0&&p<_._1.length?v("Just",_._1[p]):N;if(m.tag==="Just"){const x=h>=0&&h<_._1.length?v("Just",_._1[h]):N;if(x.tag==="Just"){const J=Ds(Yt(S=>E=>k(E,S))(m._1)),y=Ds(Yt(S=>E=>k(E,S))(x._1)),T=f?TN(m._1)(J)(y)(n)(i):bN(m._1)(J)(y)(n)(i),b=w(S=>E=>{const F=xt(G=>xi(G.id)(T))(at(f?G=>G.to.node===E._2&&As(G.from.node)(J):G=>G.from.node===E._2&&As(G.to.node)(J),n));if(F.length===0)return{...S,items:[...S.items,{n:E._2,key:N,origIdx:E._1}]};const O=Is(24)(S.r);return{items:[...S.items,{n:E._2,key:v("Just",(NN(F)+(Z(O._1)*4172325152040912e-24-.03500000014901161))/Z(F.length)),origIdx:E._1}],r:O._2}})({items:[],r:_._2})(Yt(En)(x._1)),C=Tr(ne,N,h,kN(o($(S=>S.n)(LN((()=>{const S=b.items,E=F=>O=>{let G=F,A=O,K=!0,U;for(;K;){const z=G,H=A;if(z>=0&&z<S.length){if(S[z].key.tag==="Just"){K=!1,U=S[z].key._1;continue}if(S[z].key.tag==="Nothing"){G=z+1|0,A=H;continue}g()}K=!1,U=H}return U};return(F=>O=>G=>{let A=F,K=O,U=G,z=!0,H;for(;z;){const M=A,P=K,R=U;if(M>=0&&M<S.length){if(S[M].key.tag==="Just"){A=M+1|0,K=S[M].key._1,U=[...R,{n:S[M].n,key:S[M].key._1,origIdx:S[M].origIdx}];continue}if(S[M].key.tag==="Nothing"){const Q=(P+E(M+1|0)(P+1))/2;A=M+1|0,K=Q,U=[...R,{n:S[M].n,key:Q,origIdx:S[M].origIdx}];continue}g()}z=!1,H=R}return H})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(C.tag==="Just")return k(C._1,b.r);if(C.tag==="Nothing")return k(_._1,_._2);g()}if(x.tag==="Nothing")return k(_._1,_._2);g()}if(m.tag==="Nothing")return k(_._1,_._2);g()})(k(c,d))(f?Ut(1,l-1|0):ge(Ut(0,l-2|0)))},u=w(c=>f=>j(I)(f.from.node)()(j(I)(f.to.node)()(c)))(D)(n),a=w(c=>f=>{if(c.result.crossings===0)return c;const d=J=>y=>T=>b=>{let C=J,S=y,E=T,F=b,O=!0,G;for(;O;){const A=C,K=S,U=E,z=F;if(U===0){O=!1,G={layout:A,crossings:0,random:z};continue}const H=s(A,K,z),M=Bs(H._1)(n);if(M<U){C=H._1,S=!K,E=M,F=H._2;continue}O=!1,G={layout:A,crossings:U,random:H._2}}return G},l=Is(1)(c.result.random),_=l._1!==0,h=t.modelOrder.tag==="Leaf",p=(c.firstTry||c.secondTry)&&!h?c.firstTry:_,m=(()=>{if(!h){const b=s(e,p,l._2);return d(b._1)(!p)(Bs(b._1)(n))(b._2)}const J=p?0:wN(0)(e.length-1|0),y=J>=0&&J<e.length?v("Just",e[J]):N;if(y.tag==="Just"&&y._1.length>1){const b=at(C=>r1(C)(u),y._1);if(b.length>1){const C=yN(l._2)(b),S=C._1,E=Tr(ne,N,J,o(w(F=>O=>r1(O)(u)?F.idx>=0&&F.idx<S.length?{idx:F.idx+1|0,result:[...F.result,S[F.idx]]}:{idx:F.idx,result:[...F.result,O]}:{idx:F.idx,result:[...F.result,O]})({idx:0,result:[]})(y._1).result),e);if(E.tag==="Just"){const F=s(E._1,p,C._2);return d(F._1)(!p)(Bs(F._1)(n))(F._2)}}}const T=s(e,p,l._2);return d(T._1)(!p)(Bs(T._1)(n))(T._2)})(),x=c.secondTry?!1:c.secondTry;return c.firstTry?{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:c.firstTry,secondTry:x}})({result:{layout:e,crossings:1e9,random:ti(Hg(xN(pN(1))._1)(mi))(yi)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Ut(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:a.layout},SN=t=>t,o1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Xe=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},zo=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Ji=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=I.compare(e._1)(n._1);return r==="LT"?Le:r==="GT"?Ce:I.compare(e._2)(n._2)},Eq0:()=>t}})(),EN=ae(I)(zt),GN=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=Ji.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},PN=SN("Greedy"),ic=t=>e=>n=>w(r=>o=>{if(o.from.node===o.to.node)return r;if(o.from.node===e&&!o1(o.to.node)(r.marks)){const i=Xe(o.to.node)(r.inDeg),s=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;g()})(),u=j(I)(o.to.node)(s)(r.inDeg);return(()=>{const a=Xe(o.to.node)(r.outDeg);return s<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!Ve(Qn)(o.to.node)(r.sources)})()?{...r,inDeg:u,sources:[...r.sources,o.to.node]}:{...r,inDeg:u}}if(o.to.node===e&&!o1(o.from.node)(r.marks)){const i=Xe(o.from.node)(r.outDeg),s=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;g()})(),u=j(I)(o.from.node)(s)(r.outDeg);return(()=>{const a=Xe(o.from.node)(r.inDeg);return s<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;g()})()&&!Ve(Qn)(o.from.node)(r.sinks)})()?{...r,outDeg:u,sinks:[...r.sinks,o.from.node]}:{...r,outDeg:u}}return r})({...n,remaining:at(r=>r!==e,n.remaining)})(t),IN=w(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return j(I)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return j(I)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return j(I)(e._1.node)(99999)(t)}return t})(D),i1=t=>e=>n=>{const r=Xe(e)(t),o=Xe(n)(t);return r.tag==="Just"&&o.tag==="Just"&&r._1>o._1},s1=t=>e=>n=>r=>{if(zo(n)(r.visited)||zo(n)(r.visiting))return r;const o=w(AN(t)(e)(n))({...r,visiting:j(I)(n)()(r.visiting)})((()=>{const i=Xe(n)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;g()})());return{...o,visiting:xo(I)(n)(o.visiting),visited:j(I)(n)()(o.visited)}},AN=t=>e=>n=>r=>o=>i1(t)(n)(o)?{...r,backEdges:j(Ji)(k(n,o))()(r.backEdges)}:zo(o)(r.visiting)?{...r,backEdges:j(Ji)(k(n,o))()(r.backEdges)}:zo(o)(r.visited)?r:s1(t)(e)(o)(r),DN=t=>e=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,x=Mt(J=>N,J=>y=>v("Just",{head:J,tail:y}),m.sinks);if(x.tag==="Just"){_=ic(n)(x._1.head)({...m,sinks:x._1.tail,marks:j(I)(x._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(x.tag==="Nothing"){const J=Mt(y=>N,y=>T=>v("Just",{head:y,tail:T}),m.sources);if(J.tag==="Just"){_=ic(n)(J._1.head)({...m,sources:J._1.tail,marks:j(I)(J._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(J.tag==="Nothing"){const y=b=>{const C=Xe(b)(m.outDeg),S=Xe(b)(m.inDeg);return(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;g()})()-(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;g()})()|0},T=Dt(b=>C=>{const S=nt.compare(y(C))(y(b));return S==="EQ"?nt.compare((()=>{const E=Xe(b)(e);if(E.tag==="Nothing")return 1e6;if(E.tag==="Just")return E._1;g()})())((()=>{const E=Xe(C)(e);if(E.tag==="Nothing")return 1e6;if(E.tag==="Just")return E._1;g()})()):S})(m.remaining);if(0<T.length){const b=T[0];_=ic(n)(b)({...m,remaining:at(C=>C!==b,m.remaining),marks:j(I)(b)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}g()}return p},o=ho(I.compare)([...$(l=>l.from.node)(n),...$(l=>l.to.node)(n)]),i=at(l=>l.from.node!==l.to.node,n),s=w(l=>_=>It(I)(pe)(_.to.node)(1)(l))(D)(i),u=w(l=>_=>It(I)(pe)(_.from.node)(1)(l))(D)(i),a=at(l=>{const _=Xe(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},o),c=at(l=>{const _=Xe(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;g()},o),f=o.length+1|0,d=w(l=>_=>{const h=Xe(_)(l);return h.tag==="Just"&&h._1<0?j(I)(_)(h._1+f|0)(l):l})(r({remaining:at(l=>!Ve(Qn)(l)(a)&&!Ve(Qn)(l)(c),o),marks:D,inDeg:s,outDeg:u,sources:a,sinks:c,nextLeft:1,nextRight:-1}).marks)(o);return w(l=>_=>{if(_.from.node===_.to.node)return l;if(i1(t)(_.from.node)(_.to.node))return j(Ji)(k(_.from.node,_.to.node))()(l);const h=Xe(_.from.node)(d),p=Xe(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?j(Ji)(k(_.from.node,_.to.node))()(l):l})(D)(n)},BN=w(t=>e=>It(I)(_e)(e.from.node)([e.to.node])(t))(D),RN=t=>e=>{const n=BN(e),r=ho(I.compare)([...$(i=>i.from.node)(e),...$(i=>i.to.node)(e)]),o=w(i=>s=>j(I)(s.to.node)()(i))(D)(e);return w(i=>s=>s1(t)(n)(s)(i))({visiting:D,visited:D,backEdges:D})([...at(i=>!zo(i)(o),r),...at(i=>zo(i)(o),r)]).backEdges},QN=t=>e=>n=>r=>{const o=EN(Yt(u=>a=>k(a,u))(e)),i=IN(n),s=(()=>{if(t==="DepthFirst")return RN(i)(r);if(t==="Greedy")return DN(i)(o)(r);g()})();return{edges:$(u=>GN(k(u.from.node,u.to.node))(s)?{...u,from:u.to,to:u.from}:u)(r),reversedEdges:s}},u1=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},FN=w(t=>e=>j(I)(e)()(t))(D),Rs=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},zN=v_(I),Wn=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},a1=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},sc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=nt.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},MN=ae(nt)(zt),HN=t=>e=>ze(I.compare,Qe,t,e),c1=Yt(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),ON=t=>w(e=>n=>({base:(()=>{const r=o=>i=>{let s=o,u=i,a=!0,c;for(;a;){const f=s,d=u;if(d.tag==="Nil"){a=!1,c=f;continue}if(d.tag==="Cons"){s=u1(f)(d._1),u=d._2;continue}g()}return c};return(e.base+r(0)((()=>{const o=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return o(i._5,Xt("Cons",i._4,o(i._6,s)));g()};return o(n,Ht)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=o=>{if(o.tag==="Leaf")return D;if(o.tag==="Node")return Kt("Node",o._1,o._2,o._3,o._4+e.base|0,r(o._5),r(o._6));g()};return r(n)})()]}))({base:0,result:[]})(t).result,qN=t=>e=>{const n=FN(t);return zN(t)(c1(at(r=>Rs(r.src)(n)&&Rs(r.tgt)(n),e)))},$N=t=>e=>{const n=w(o=>i=>It(I)(_e)(i.tgt)([i.src])(It(I)(_e)(i.src)([i.tgt])(o)))(D)(e),r=o=>i=>s=>{let u=o,a=i,c=s,f=!0,d;for(;f;){const l=u,_=a,h=c,p=Mt(m=>N,m=>x=>v("Just",{head:m,tail:x}),l);if(p.tag==="Nothing"){f=!1,d={nodes:h};continue}if(p.tag==="Just"){if(Rs(p._1.head)(_)){u=p._1.tail,a=_,c=h;continue}u=[...p._1.tail,...(()=>{const m=Wn(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()})()],a=j(I)(p._1.head)()(_),c=[...h,p._1.head];continue}g()}return d};return w(o=>i=>{if(Rs(i)(o.visited))return o;const s=r([i])(o.visited)([]);return{...o,visited:w(u=>a=>j(I)(a)()(u))(o.visited)(s.nodes),components:[...o.components,s.nodes]}})({visited:D,components:[]})(t).components},WN=t=>e=>n=>{const r=w(i=>s=>It(I)(pe)(s.tgt)(1)(i))(D)(e),o=w(i=>s=>It(I)(pe)(s.src)(1)(i))(D)(e);return w(i=>s=>{const u=Wn(s)(r),a=(()=>{if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()})();if((()=>{const J=Wn(s)(o);return(()=>{if(J.tag==="Nothing")return a!==0;if(J.tag==="Just")return a!==J._1;g()})()||a===0})())return i;const c=Wn(s)(i.layers),f=(()=>{if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1;g()})(),d=i.layers,l=w(J=>y=>y.tgt===s?{...J,mIn:a1(J.mIn)((()=>{const T=Wn(s)(d),b=Wn(y.src)(d);return(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;g()})()|0})())}:y.src===s?{...J,mOut:a1(J.mOut)((()=>{const T=Wn(y.tgt)(d),b=Wn(s)(d);return(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;g()})()|0})())}:J)({mIn:1e9,mOut:1e9})(e),_=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(_<0||h<0)return i;const p=(f-_|0)+1|0,m=(f+h|0)-1|0;if(m<p)return i;const x=w(J=>y=>{const T=sc(y)(i.filling),b=(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})();return b<J.bestFill?{best:y,bestFill:b}:J})({best:f,bestFill:(()=>{const J=sc(f)(i.filling);if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;g()})()})(Ut(p,m));return x.best===f?i:{layers:j(I)(s)(x.best)(i.layers),filling:j(nt)(f)((()=>{const J=sc(f)(i.filling);if(J.tag==="Nothing")return-1;if(J.tag==="Just")return J._1-1|0;g()})())(j(nt)(x.best)(x.bestFill+1|0)(i.filling))}})({layers:n,filling:MN($(i=>k(i,w(s=>u=>(()=>{const a=Wn(u)(n);return a.tag==="Nothing"?!1:a.tag==="Just"&&a._1===i})()?s+1|0:s)(0)(t)))(Ut(0,w(i=>s=>u1(i)((()=>{const u=Wn(s)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()})()))(0)(t))))})(t).layers},YN=t=>e=>WN(t)(c1(e))(w(HN)(D)(ON($(n=>qN(n)(e))($N(t)(e))))),VN=t=>t,Ur=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},Qs=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},g1=(()=>{const t=nn.unfoldr(In);return e=>t(rn("IterNode",e,Pn))})(),UN=VN("NetworkSimplex"),XN=t=>e=>w(n=>r=>{const o=w(Qs)(0)(xt(i=>Ur(i)(n))(r));return w(i=>s=>j(I)(s)(o)(i))(n)(r)})(e)(t),KN=t=>e=>({layers:$(n=>at(r=>{const o=Ur(r)(e);return o.tag==="Nothing"?!1:o.tag==="Just"&&o._1===n},t))(Ut(0,(n=>r=>{let o=n,i=r,s=!0,u;for(;s;){const a=o,c=i;if(c.tag==="Nil"){s=!1,u=a;continue}if(c.tag==="Cons"){o=Qs(a)(c._1),i=c._2;continue}g()}return u})(0)((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Xt("Cons",r._4,n(r._6,o)));g()};return n(e,Ht)})()))),nodeLayer:e}),jN=t=>e=>n=>{const r=w(o=>i=>j(I)(i)(!0)(o))(D)(e);return w(o=>i=>j(I)(i._1)(i._2)(o))(YN(e)(xt(o=>o.from.node===o.to.node||(()=>{const i=Ur(o.from.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;g()})()||(()=>{const i=Ur(o.to.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;g()})()?N:v("Just",{src:o.from.node,tgt:o.to.node}))(t)))(g1(n))},ZN=t=>e=>n=>r=>{const o=u=>a=>{const c=Ur(a)(u);if(c.tag==="Just")return u;if(c.tag==="Nothing"){const f=at(l=>l!==a,(()=>{const l=Ur(a)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;g()})()),d=w(o)(u)(f);return j(I)(a)(1+w(Qs)(0)(xt(l=>Ur(l)(d))(f))|0)(d)}g()},i=w(o)(D)(n),s=(u=>a=>{let c=u,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=Qs(_)(h._1),f=h._2;continue}g()}return l})(1)((()=>{const u=(a,c)=>{if(a.tag==="Leaf")return c;if(a.tag==="Node")return u(a._5,Xt("Cons",a._4,u(a._6,c)));g()};return u(i,Ht)})());return w(u=>a=>j(I)(a._1)(a._2)(u))((()=>{const u=a=>{if(a.tag==="Leaf")return D;if(a.tag==="Node")return Kt("Node",a._1,a._2,a._3,s-a._4|0,u(a._5),u(a._6));g()};return u(i)})())(g1(r))},tw=w(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return j(I)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return j(I)(e._1.node)(0)(t)}return t})(D),ew=w(t=>e=>It(I)(_e)(e.to.node)([e.from.node])(t))(D),nw=w(t=>e=>It(I)(_e)(e.from.node)([e.to.node])(t))(D),rw=t=>e=>n=>r=>{const o=nw(n),i=ew(n),s=tw(e);return KN(r)(XN(xt(u=>u.tag==="SameLayer"?v("Just",u._1.nodes):N)(e))((()=>{if(t==="LongestPath")return ZN(o)(i)(r)(s);if(t==="NetworkSimplex")return jN(n)(r)(s);g()})()))},ow=ae(I)(zt),iw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},f1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},_1=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ni=ae(I)(zt),sw=ae(I)(zt),d1=(()=>{const t=$(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>ge(t(e))})(),uw=t=>e=>n=>r=>{const o=ow($(s=>k(s.edge,s))(r)),i=s=>0<s.nodes.length&&(()=>{const u=iw(s.edgeId)(n);return u.tag==="Just"&&s.nodes[0]!==u._1._1})();return $(s=>{if(s.nodes.length<=2){const f=f1(s.edgeId)(o);if(f.tag==="Just"){const d=i(s),l=di(_i(d?d1(f._1.segments):f._1.segments));return{...f._1,edge:s.edgeId,segments:l,bends:Ie(_=>h=>_.end,l,Gt(1,l.length,l)),reversed:d}}if(f.tag==="Nothing")return{edge:s.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};g()}const u=Lt(xt(f=>f1(f)(o))(Ie(f=>d=>s.edgeId+":"+f+"->"+d,s.nodes,Gt(1,s.nodes.length,s.nodes))))(f=>f.segments),a=i(s),c=di(_i(a?d1(u):u));return{edge:s.edgeId,segments:c,bends:Ie(f=>d=>f.end,c,Gt(1,c.length,c)),bendType:[],jumps:[],reversed:a}})(t)},aw={layers:[],edges:[],chains:[]},cw={nodeGap:3,layerGap:2,iterations:8,layerer:UN,cycleBreaker:PN,compactPostRouting:!0,compactionSpacings:eJ},gw=t=>({pos:k(0,0),size:k(w(e=>n=>_1(e)(n.position._1+n.size._1))(0)(t),w(e=>n=>_1(e)(n.position._2+n.size._2))(0)(t))}),fw=t=>e=>n=>{const r=Ni($(c=>k(c.id,c.ports))(e.nodes)),o=at(c=>Ee(3)(c.node)!=="$d:",n.placements),i=uw(n.withDummies.chains)(n.acyclic.reversedEdges)(sw($(c=>k(c.id,k(c.from.node,c.to.node)))(e.edges)))(BJ(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(q_(n.ordered)(at(c=>c.from.node!==c.to.node,n.withDummies.edges))((()=>{const c=f=>{if(f.tag==="Leaf")return D;if(f.tag==="Node")return Kt("Node",f._1,f._2,f._3,k(f._4._1*4,f._4._2),c(f._5),c(f._6));g()};return c(Ni($(f=>k(f.id,f.size))(e.nodes)))})()))),s=t.compactPostRouting?oJ()(t.compactionSpacings)({nodes:o,edges:e.edges,paths:i,ports:r}):{nodes:o,edges:i},u=$(c=>{const f=di(_i(c.segments));return{...c,segments:f,bends:Ie(d=>l=>d.end,f,Gt(1,f.length,f))}})(s.edges),a=Yt(c=>f=>({...f,jumps:OJ(c)(f)(u)}))(u);return{nodes:s.nodes,edges:a,boundingBox:gw(s.nodes),metrics:Ey(s.nodes)(a)(0)}},_w=t=>e=>n=>{const r=Ni($(i=>k(i.id,i.size))(e.nodes)),o={...n,placements:hN({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(Ni($(i=>k(i.id,i.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(q_(n.ordered)(n.withDummies.edges)((()=>{const i=s=>{if(s.tag==="Leaf")return D;if(s.tag==="Node")return Kt("Node",s._1,s._2,s._3,k(s._4._1*4,s._4._2),i(s._5),i(s._6));g()};return i(r)})()))};return{pipeline:o,result:fw(t)(e)(o)}},dw=t=>e=>n=>_w(t)(e)({...n,ordered:CN({iterations:t.iterations,constraints:e.constraints,modelOrder:Ni(Yt(r=>o=>k(o.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),lw=t=>e=>n=>dw(t)(e)({...n,withDummies:qJ(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),hw=t=>e=>{const n=$(o=>o.id)(e.nodes),r=QN(t.cycleBreaker)(n)(e.constraints)(e.edges);return lw(t)(e)({acyclic:r,layered:rw(t.layerer)(e.constraints)(r.edges)(n),withDummies:aw,ordered:[],placements:[]})},Fs=t=>t,pw=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Xr=Fs("TopSide"),Kr=Fs("BottomSide"),jr=Fs("LeftSide"),Zr=Fs("RightSide"),mw=t=>{const e=rt.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=rt.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},l1=t=>e=>n=>{const r=pw(t.h*.12)(t.w*.2),o=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*Fe(mw((()=>{const i=(n-(t.x+o))/o;return 1-i*i})()))},Ke=t=>e=>n=>r=>{let o=t,i=e,s=n,u=r,a=!0,c;for(;a;){const f=o,d=i,l=s,_=u;if(f==="Rectangle"){if(l==="TopSide"){a=!1,c=d.y;continue}if(l==="BottomSide"){a=!1,c=d.y+d.h;continue}if(l==="LeftSide"){a=!1,c=d.x;continue}if(l==="RightSide"){a=!1,c=d.x+d.w;continue}o=Lr,i=d,s=l,u=_;continue}if(f==="Cylinder"){if(l==="TopSide"){a=!1,c=l1(d)(-1)(_);continue}if(l==="BottomSide"){a=!1,c=l1(d)(1)(_);continue}if(l==="LeftSide"){a=!1,c=d.x;continue}if(l==="RightSide"){a=!1,c=d.x+d.w;continue}}o=Lr,i=d,s=l,u=_}return c},h1=t=>e=>{const n=e.y-t.y,r=n<0?-n:n,o=e.x-(t.x+t.w),i=o<0?-o:o,s=e.x-t.x,u=s<0?-s:s,a=e.y-(t.y+t.h),c=a<0?-a:a;return r<=c&&r<=u&&r<=i?Xr:c<=u&&c<=i?Kr:u<=i?jr:Zr},yw=(()=>{const t=nn.unfoldr(In);return e=>t(rn("IterNode",e,Pn))})(),uc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},wi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},vi=ae(I)(zt),xw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Jw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Nw=w(t=>e=>j(I)(e)()(t))(D),ww=w(t=>e=>j(I)(e)()(t))(D),zs=zr.traverse(Au),Ms=ae(I)(zt),vw=t=>e=>ze(I.compare,Qe,t,e),Tw=w(t=>e=>j(I)(e)()(t))(D),bw=ae(I)(zt),kw=t=>e=>ze(I.compare,Qe,t,e),Lw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},p1=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Cw=t=>e=>({...e,edges:vi($(n=>k(n._1,(()=>{const r=uc(n._1)(t);if(r.tag==="Nothing")return n._2;if(r.tag==="Just"){const o=wi(r._1._2)(e.nodes),i=wi(r._1._1)(e.nodes),s=(()=>{if(i.tag==="Nothing")return n._2;if(i.tag==="Just"){const u=Mt(a=>N,a=>c=>v("Just",{head:a,tail:c}),n._2);if(u.tag==="Nothing")return n._2;if(u.tag==="Just")return[(()=>{const a=Mt(l=>N,l=>_=>v("Just",{head:l,tail:_}),u._1.tail),c=a.tag==="Just"?v("Just",a._1.head):N,f={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},d=(()=>{if(c.tag==="Just"){if((c._1.x>u._1.head.x?c._1.x-u._1.head.x<.5:u._1.head.x-c._1.x<.5)&&u._1.head.x>=f.x-.5&&u._1.head.x<=f.x+f.w+.5)return c._1.y>=f.y+f.h?v("Just",Kr):c._1.y<=f.y?v("Just",Xr):N;if((c._1.y>u._1.head.y?c._1.y-u._1.head.y<.5:u._1.head.y-c._1.y<.5)&&u._1.head.y>=f.y-.5&&u._1.head.y<=f.y+f.h+.5){if(c._1.x>=f.x+f.w)return v("Just",Zr);if(c._1.x<=f.x)return v("Just",jr)}return N}if(c.tag==="Nothing")return N;g()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...u._1.head,y:Ke(i._1.shape)(f)(Xr)(u._1.head.x)};if(d._1==="BottomSide")return{...u._1.head,y:Ke(i._1.shape)(f)(Kr)(u._1.head.x)};if(d._1==="LeftSide")return{...u._1.head,x:Ke(i._1.shape)(f)(jr)(u._1.head.y)};if(d._1==="RightSide")return{...u._1.head,x:Ke(i._1.shape)(f)(Zr)(u._1.head.y)};g()}if(d.tag==="Nothing"){const l={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},_=h1(l)(u._1.head);if(_==="TopSide")return{...u._1.head,y:Ke(i._1.shape)(l)(Xr)(u._1.head.x)};if(_==="BottomSide")return{...u._1.head,y:Ke(i._1.shape)(l)(Kr)(u._1.head.x)};if(_==="LeftSide")return{...u._1.head,x:Ke(i._1.shape)(l)(jr)(u._1.head.y)};if(_==="RightSide")return{...u._1.head,x:Ke(i._1.shape)(l)(Zr)(u._1.head.y)}}g()})(),...u._1.tail]}g()})();if(o.tag==="Nothing")return s;if(o.tag==="Just"){const u=Hr(s);if(u.tag==="Nothing")return s;if(u.tag==="Just")return Pt(u._1.init)((()=>{const a=Hr(u._1.init),c=a.tag==="Just"?v("Just",a._1.last):N,f={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},d=(()=>{if(c.tag==="Just"){if((c._1.x>u._1.last.x?c._1.x-u._1.last.x<.5:u._1.last.x-c._1.x<.5)&&u._1.last.x>=f.x-.5&&u._1.last.x<=f.x+f.w+.5)return c._1.y>=f.y+f.h?v("Just",Kr):c._1.y<=f.y?v("Just",Xr):N;if((c._1.y>u._1.last.y?c._1.y-u._1.last.y<.5:u._1.last.y-c._1.y<.5)&&u._1.last.y>=f.y-.5&&u._1.last.y<=f.y+f.h+.5){if(c._1.x>=f.x+f.w)return v("Just",Zr);if(c._1.x<=f.x)return v("Just",jr)}return N}if(c.tag==="Nothing")return N;g()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...u._1.last,y:Ke(o._1.shape)(f)(Xr)(u._1.last.x)};if(d._1==="BottomSide")return{...u._1.last,y:Ke(o._1.shape)(f)(Kr)(u._1.last.x)};if(d._1==="LeftSide")return{...u._1.last,x:Ke(o._1.shape)(f)(jr)(u._1.last.y)};if(d._1==="RightSide")return{...u._1.last,x:Ke(o._1.shape)(f)(Zr)(u._1.last.y)};g()}if(d.tag==="Nothing"){const l={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},_=h1(l)(u._1.last);if(_==="TopSide")return{...u._1.last,y:Ke(o._1.shape)(l)(Xr)(u._1.last.x)};if(_==="BottomSide")return{...u._1.last,y:Ke(o._1.shape)(l)(Kr)(u._1.last.x)};if(_==="LeftSide")return{...u._1.last,x:Ke(o._1.shape)(l)(jr)(u._1.last.y)};if(_==="RightSide")return{...u._1.last,x:Ke(o._1.shape)(l)(Zr)(u._1.last.y)}}g()})())}}g()})()))(yw(e.edges)))}),Sw=t=>e=>n=>{const r=oe(o=>o.id===n)(t.graph.edges);if(r.tag==="Just")return v("Just",r._1);if(r.tag==="Nothing")return uc(n)(e);g()},Ew=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=wi(r.node)(e);if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return r.node;g()})(),shape:(()=>{const o=wi(r.node)(n);if(o.tag==="Nothing")return Lr;if(o.tag==="Just")return o._1;g()})()}),Gw=t=>({id:t,size:k(1,1),ports:[],label:v("Just",t),shape:Lr}),Pw=t=>e=>n=>r=>k(r.node,Ew(t)(e)(n)(r)),m1=t=>{const e=si(`
|
|
6
|
+
`)(t);return e.length===0?[""]:e},y1=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Xt("Cons",n._4,e(n._6,r)));g()};return qt(ue.foldr,e(t.interiors,Ht))},Iw=t=>vi(xt(e=>v("Just",k(e.edge,{id:e.edge,from:{node:e.from,port:N},to:{node:e.to,port:N},label:N})))(Lt(t.scenes)(e=>e.tag==="DataFlow"?xt(n=>n.kind.tag==="SendToken"?v("Just",n.kind._1):N)(e._1.events):[]))),x1=t=>{const e=k0(t),n=at(o=>xw(o.id)(e.nodes),t.graph.nodes),r=at(o=>Jw(o.id)(e.edges),t.graph.edges);return{nodes:[...n,...$(Gw)(qt(on.foldr,or(I.compare,e.nodes,Nw($(o=>o.id)(n)))))],edges:[...r,...xt(Sw(t)(Iw(t)))(qt(on.foldr,or(I.compare,e.edges,ww($(o=>o.id)(r)))))],constraints:t.graph.constraints}},Aw=t=>{const e=zs(n=>{const r=jf(Zf)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})());return()=>{const o=r();return k(n.id,o)}})(x1(t).nodes);return()=>{const n=e();return Ms(n)}},J1=t=>{const e=Aw(t);return()=>{const n=e(),r=zs(J1)(y1(t))();return w(vw)(n)(r)}},Dw=t=>e=>{const n=Mt(r=>N,r=>o=>v("Just",{head:r,tail:o}),e.segments);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{x:n._1.head.start._1*t,y:n._1.head.start._2*t},...$(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];g()},Bw=t=>e=>k(e.edge,Dw(t)(e)),Rw=t=>e=>n=>r=>({nodes:Ms($(Pw(Z(4)*t)(e)(n))(r.nodes)),edges:vi($(Bw(t))(r.edges)),chipExtras:D,edgeLabels:D}),Qw=t=>e=>({...Cw(vi($(n=>k(n.id,k(n.from.node,n.to.node)))(e.edges)))(Rw(8)(Ms($(n=>k(n.id,(()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})()))(e.nodes)))(Ms($(n=>k(n.id,n.shape))(e.nodes)))(hw(cw)(e).result)),edgeLabels:vi(xt(n=>n.label.tag==="Just"?v("Just",k(n.id,n.label._1)):N)(e.edges))}),Fw=t=>w(e=>n=>{if(n.tag==="Structural")return e;if(n.tag==="DataFlow")return w(r=>o=>{if(o.kind.tag==="SendToken")return w(i=>s=>j(I)(s)()(i))(r)(o.kind._1.labels);if(o.kind.tag==="FillNodeWithoutTransition")return w(i=>s=>j(I)(s)()(i))(r)(o.kind._1.labels);g()})(e)(n._1.events);if(n.tag==="Hold"||n.tag==="EnterNode"||n.tag==="ExitNode")return e;g()})(D)(t.scenes),zw=t=>{const e=zs(n=>{const r=jf(Zf)(n);return()=>{const o=r();return k(n,{labelW:o,charCount:Mn(Vr(n)),lineCount:1})}})(qt(on.foldr,Tw(Lt(qt(on.foldr,Fw(t)))(m1))));return()=>{const n=e();return bw(n)}},N1=t=>{const e=zw(t);return()=>{const n=e(),r=zs(N1)(y1(t))();return w(kw)(n)(r)}},Mw=Z(4)*8,Hw=t=>Lt(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[];g()}),Ow=t=>e=>n=>{const r=o=>{const i=xt(s=>{const u=Lw(s)(t);return u.tag==="Just"?v("Just",{w:u._1.labelW+28,h:Z(Jy(1)(u._1.lineCount))*13.2+12}):N})(Lt(o)(m1));return i.length===0?N:v("Just",{w:w(p1)(0)($(s=>s.w)(i)),h:w(p1)(0)($(s=>s.h)(i))})};return w(o=>i=>{if(i.kind.tag==="SendToken"){const s=uc(i.kind._1.edge)(n.edges),u=r(i.kind._1.labels);if(u.tag==="Just"&&s.tag==="Just"){const a=u._1;return It(I)(_e)(i.kind._1.edge)($(c=>({x:c.x+14+a.w,y:c.y-6-8-a.h}))(s._1))(o)}return o}if(i.kind.tag==="FillNodeWithoutTransition"){const s=wi(i.kind._1.node)(n.nodes),u=r(i.kind._1.labels);return u.tag==="Just"&&s.tag==="Just"?It(I)(_e)("__fill__:"+i.kind._1.node)((()=>{const a=s._1.y-u._1.h-14,c=s._1.x+s._1.w/2,f=c-u._1.w/2,d=c+u._1.w/2,l=s._1.y-14;return[{x:f,y:a},{x:d,y:a},{x:f,y:l},{x:d,y:l}]})())(o):o}g()})(D)(Hw(e))},w1=t=>e=>n=>({layout:(()=>{const r=Qw()(Ly(Mw)(t)(ky(by)(x1(n))));return{...r,chipExtras:Ow(e)(n)(r)}})(),interiors:(()=>{const r=w1(t)(e),o=i=>{if(i.tag==="Leaf")return D;if(i.tag==="Node")return Kt("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(n.interiors)})()}),v1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},ac=t=>e=>n=>{const r=t<.05?t:.05,o=(s,u)=>{if(u.tag==="Leaf")return s;if(u.tag==="Node")return o((()=>{const a=v1(u._3)(n),c=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return{x:u._4.x,y:u._4.y,vx:0,vy:0};g()})(),f=c.vx+(180*(u._4.x-c.x)-22*c.vx)*r,d=c.vy+(180*(u._4.y-c.y)-22*c.vy)*r;return j(I)(u._3)({x:c.x+f*r,y:c.y+d*r,vx:f,vy:d})(o(s,u._5))})(),u._6);g()},i=o(D,e);return{springs:i,applied:(()=>{const s=(u,a)=>{if(a.tag==="Leaf")return u;if(a.tag==="Node")return s((()=>{const c=s(u,a._5),f=v1(a._3)(i);if(f.tag==="Just")return j(I)(a._3)({...a._4,x:f._1.x,y:f._1.y})(c);if(f.tag==="Nothing")return j(I)(a._3)(a._4)(c);g()})(),a._6);g()};return s(D,e)})()}},fn=(t,e)=>({tag:"CatQueue",_1:t,_2:e}),qw=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=N;continue}e=fn((i=>s=>{let u=i,a=s,c=!0,f;for(;c;){const d=u,l=a;if(l.tag==="Nil"){c=!1,f=d;continue}if(l.tag==="Cons"){u=Xt("Cons",l._1,d),a=l._2;continue}g()}return f})(Ht)(o._2),Ht);continue}if(o._1.tag==="Cons"){n=!1,r=v("Just",k(o._1._1,fn(o._1._2,o._2)));continue}g()}return r},xn=(t,e,n)=>({tag:t,_1:e,_2:n}),Tt=xn("CatNil"),$w=t=>e=>{if(t.tag==="CatNil")return e;if(e.tag==="CatNil")return t;if(t.tag==="CatCons")return xn("CatCons",t._1,fn(t._2._1,Xt("Cons",e,t._2._2)));g()},Ww=t=>e=>n=>{const r=o=>i=>s=>{let u=o,a=i,c=s,f=!0,d;for(;f;){const l=u,_=a,h=c;if(h.tag==="Nil"){f=!1,d=_;continue}if(h.tag==="Cons"){u=l,a=l(_)(h._1),c=h._2;continue}g()}return d};return(o=>i=>{let s=o,u=i,a=!0,c;for(;a;){const f=s,d=u,l=qw(f);if(l.tag==="Nothing"){a=!1,c=r(_=>h=>h(_))(e)(d);continue}if(l.tag==="Just"){s=l._1._2,u=Xt("Cons",t(l._1._1),d);continue}g()}return c})(n)(Ht)},Yw=t=>{if(t.tag==="CatNil")return N;if(t.tag==="CatCons")return v("Just",k(t._1,t._2._1.tag==="Nil"&&t._2._2.tag==="Nil"?Tt:Ww($w)(Tt)(t._2)));g()},Nt=(t,e)=>({tag:"Free",_1:t,_2:e}),bt=(t,e,n)=>({tag:t,_1:e,_2:n}),Vw=t=>{let e=t,n=!0,r;for(;n;){const o=e;if(o._1.tag==="Return"){const i=Yw(o._2);if(i.tag==="Nothing"){n=!1,r=bt("Return",o._1._1);continue}if(i.tag==="Just"){e=(()=>{const s=i._1._1(o._1._1);return Nt(s._1,(()=>{if(s._2.tag==="CatNil")return i._1._2;if(i._1._2.tag==="CatNil")return s._2;if(s._2.tag==="CatCons")return xn("CatCons",s._2._1,fn(s._2._2._1,Xt("Cons",i._1._2,s._2._2._2)));g()})())})();continue}g()}if(o._1.tag==="Bind"){n=!1,r=bt("Bind",o._1._1,i=>{const s=o._1._2(i);return Nt(s._1,(()=>{if(s._2.tag==="CatNil")return o._2;if(o._2.tag==="CatNil")return s._2;if(s._2.tag==="CatCons")return xn("CatCons",s._2._1,fn(s._2._2._1,Xt("Cons",o._2,s._2._2._2)));g()})())});continue}g()}return r},Uw=t=>e=>{const n=e.Monad0(),r=n.Bind1().Apply0().Functor0();return o=>e.tailRecM(i=>{const s=Vw(i);if(s.tag==="Return")return r.map(Nh)(n.Applicative0().pure(s._1));if(s.tag==="Bind")return r.map(Du)(o(t.map(s._2)(s._1)));g()})},Xw={Applicative0:()=>Hs,Bind1:()=>T1},Kw={map:t=>e=>T1.bind(e)(n=>Hs.pure(t(n)))},T1={bind:t=>e=>Nt(t._1,(()=>{if(t._2.tag==="CatNil")return xn("CatCons",e,fn(Ht,Ht));if(t._2.tag==="CatCons")return xn("CatCons",t._2._1,fn(t._2._2._1,Xt("Cons",xn("CatCons",e,fn(Ht,Ht)),t._2._2._2)));g()})()),Apply0:()=>b1},b1={apply:t=>e=>{const n=r=>Nt(e._1,(()=>{if(e._2.tag==="CatNil")return xn("CatCons",o=>Hs.pure(r(o)),fn(Ht,Ht));if(e._2.tag==="CatCons")return xn("CatCons",e._2._1,fn(e._2._2._1,Xt("Cons",xn("CatCons",o=>Hs.pure(r(o)),fn(Ht,Ht)),e._2._2._2)));g()})());return Nt(t._1,(()=>{if(t._2.tag==="CatNil")return xn("CatCons",n,fn(Ht,Ht));if(t._2.tag==="CatCons")return xn("CatCons",t._2._1,fn(t._2._2._1,Xt("Cons",xn("CatCons",n,fn(Ht,Ht)),t._2._2._2)));g()})())},Functor0:()=>Kw},Hs={pure:t=>Nt(bt("Return",t),Tt),Apply0:()=>b1},jw={map:t=>e=>({type:e.type,value:e.map(t)(e.value),map:e.map})};(function(){var t={},e="Pure",n="Throw",r="Catch",o="Sync",i="Async",s="Bind",u="Bracket",a="Fork",c="Sequential",f="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",x="Finalized",J="Forked";function y(B,q,et,V){this.tag=B,this._1=q,this._2=et,this._3=V}function T(B){var q=function(et,V,Y){return new y(B,et,V,Y)};return q.tag=B,q}function b(B){return new y(e,void 0)}function C(B){try{B()}catch(q){setTimeout(function(){throw q},0)}}function S(B,q,et){try{return q(et())}catch(V){return B(V)}}function E(B,q,et){try{return q(et)()}catch(V){return et(B(V))(),b}}var F=(function(){var B=1024,q=0,et=0,V=new Array(B),Y=!1;function W(){var X;for(Y=!0;q!==0;)q--,X=V[et],V[et]=void 0,et=(et+1)%B,X();Y=!1}return{isDraining:function(){return Y},enqueue:function(X){var tt;q===B&&(tt=Y,W(),Y=tt),V[(et+q)%B]=X,q++,Y||W()}}})();function O(B){var q={},et=0,V=0;return{register:function(Y){var W=et++;Y.onComplete({rethrow:!0,handler:function(X){return function(){V--,delete q[W]}}})(),q[W]=Y,V++},isEmpty:function(){return V===0},killAll:function(Y,W){return function(){if(V===0)return W();var X=0,tt={};function gt(ct){tt[ct]=q[ct].kill(Y,function(yt){return function(){delete tt[ct],X--,B.isLeft(yt)&&B.fromLeft(yt)&&setTimeout(function(){throw B.fromLeft(yt)},0),X===0&&W()}})()}for(var wt in q)q.hasOwnProperty(wt)&&(X++,gt(wt));return q={},et=0,V=0,function(ct){return new y(o,function(){for(var yt in tt)tt.hasOwnProperty(yt)&&tt[yt]()})}}}}}var G=0,A=1,K=2,U=3,z=4,H=5,M=6;function P(B,q,et){var V=0,Y=G,W=et,X=null,tt=null,gt=null,wt=null,ct=null,yt=0,Ct=0,Vt=null,mt=!0;function Wt(ot){for(var _t,st,ut;;)switch(_t=null,st=null,ut=null,Y){case K:Y=A;try{W=gt(W),wt===null?gt=null:(gt=wt._1,wt=wt._2)}catch(vt){Y=H,X=B.left(vt),W=null}break;case U:B.isLeft(W)?(Y=H,X=W,W=null):gt===null?Y=H:(Y=K,W=B.fromRight(W));break;case A:switch(W.tag){case s:gt&&(wt=new y(_,gt,wt)),gt=W._2,Y=A,W=W._1;break;case e:gt===null?(Y=H,W=B.right(W._1)):(Y=K,W=W._1);break;case o:Y=U,W=S(B.left,B.right,W._1);break;case i:Y=z,W=E(B.left,W._1,function(vt){return function(){V===ot&&(V++,F.enqueue(function(){V===ot+1&&(Y=U,W=vt,Wt(V))}))}});return;case n:Y=H,X=B.left(W._1),W=null;break;case r:gt===null?ct=new y(_,W,ct,tt):ct=new y(_,W,new y(_,new y(h,gt,wt),ct,tt),tt),gt=null,wt=null,Y=A,W=W._1;break;case u:yt++,gt===null?ct=new y(_,W,ct,tt):ct=new y(_,W,new y(_,new y(h,gt,wt),ct,tt),tt),gt=null,wt=null,Y=A,W=W._1;break;case a:Y=U,_t=P(B,q,W._2),q&&q.register(_t),W._1&&_t.run(),W=B.right(_t);break;case c:Y=A,W=Q(B,q,W._1);break}break;case H:if(gt=null,wt=null,ct===null)Y=M,W=tt||X||W;else switch(_t=ct._3,ut=ct._1,ct=ct._2,ut.tag){case r:tt&&tt!==_t&&yt===0?Y=H:X&&(Y=A,W=ut._2(B.fromLeft(X)),X=null);break;case h:tt&&tt!==_t&&yt===0||X?Y=H:(gt=ut._1,wt=ut._2,Y=K,W=B.fromRight(W));break;case u:yt--,X===null&&(st=B.fromRight(W),ct=new y(_,new y(p,ut._2,st),ct,_t),(tt===_t||yt>0)&&(Y=A,W=ut._3(st)));break;case p:ct=new y(_,new y(x,W,X),ct,tt),Y=A,tt&&tt!==_t&&yt===0?W=ut._1.killed(B.fromLeft(tt))(ut._2):X?W=ut._1.failed(B.fromLeft(X))(ut._2):W=ut._1.completed(B.fromRight(W))(ut._2),X=null,yt++;break;case m:yt++,ct=new y(_,new y(x,W,X),ct,tt),Y=A,W=ut._1;break;case x:yt--,Y=H,W=ut._1,X=ut._2;break}break;case M:for(var Jt in Vt)Vt.hasOwnProperty(Jt)&&(mt=mt&&Vt[Jt].rethrow,C(Vt[Jt].handler(W)));Vt=null,tt&&X?setTimeout(function(){throw B.fromLeft(X)},0):B.isLeft(W)&&mt&&setTimeout(function(){if(mt)throw B.fromLeft(W)},0);return;case G:Y=A;break;case z:return}}function kt(ot){return function(){if(Y===M)return mt=mt&&ot.rethrow,ot.handler(W)(),function(){};var _t=Ct++;return Vt=Vt||{},Vt[_t]=ot,function(){Vt!==null&&delete Vt[_t]}}}function lt(ot,_t){return function(){if(Y===M)return _t(B.right(void 0))(),function(){};var st=kt({rethrow:!1,handler:function(){return _t(B.right(void 0))}})();switch(Y){case G:tt=B.left(ot),Y=M,W=tt,Wt(V);break;case z:tt===null&&(tt=B.left(ot)),yt===0&&(Y===z&&(ct=new y(_,new y(m,W(ot)),ct,tt)),Y=H,W=null,X=null,Wt(++V));break;default:tt===null&&(tt=B.left(ot)),yt===0&&(Y=H,W=null,X=null)}return st}}function ft(ot){return function(){var _t=kt({rethrow:!1,handler:ot})();return Y===G&&Wt(V),_t}}return{kill:lt,join:ft,onComplete:kt,isSuspended:function(){return Y===G},run:function(){Y===G&&(F.isDraining()?Wt(V):F.enqueue(function(){Wt(V)}))}}}function R(B,q,et,V){var Y=0,W={},X=0,tt={},gt=new Error("[ParAff] Early exit"),wt=null,ct=t;function yt(kt,lt,ft){var ot=lt,_t=null,st=null,ut=0,Jt={},vt,At;t:for(;;)switch(vt=null,ot.tag){case J:if(ot._3===t&&(vt=W[ot._1],Jt[ut++]=vt.kill(kt,function(Zt){return function(){ut--,ut===0&&ft(Zt)()}})),_t===null)break t;ot=_t._2,st===null?_t=null:(_t=st._1,st=st._2);break;case f:ot=ot._2;break;case d:case l:_t&&(st=new y(_,_t,st)),_t=ot,ot=ot._1;break}if(ut===0)ft(B.right(void 0))();else for(At=0,vt=ut;At<vt;At++)Jt[At]=Jt[At]();return Jt}function Ct(kt,lt,ft){var ot,_t,st,ut,Jt,vt;for(B.isLeft(kt)?(ot=kt,_t=null):(_t=kt,ot=null);;){if(st=null,ut=null,Jt=null,vt=null,wt!==null)return;if(lt===null){V(ot||_t)();return}if(lt._3!==t)return;switch(lt.tag){case f:ot===null?(lt._3=B.right(lt._1(B.fromRight(_t))),_t=lt._3):lt._3=ot;break;case d:if(st=lt._1._3,ut=lt._2._3,ot){if(lt._3=ot,Jt=!0,vt=X++,tt[vt]=yt(gt,ot===st?lt._2:lt._1,function(){return function(){delete tt[vt],Jt?Jt=!1:ft===null?Ct(ot,null,null):Ct(ot,ft._1,ft._2)}}),Jt){Jt=!1;return}}else{if(st===t||ut===t)return;_t=B.right(B.fromRight(st)(B.fromRight(ut))),lt._3=_t}break;case l:if(st=lt._1._3,ut=lt._2._3,st===t&&B.isLeft(ut)||ut===t&&B.isLeft(st))return;if(st!==t&&B.isLeft(st)&&ut!==t&&B.isLeft(ut))ot=_t===st?ut:st,_t=null,lt._3=ot;else if(lt._3=_t,Jt=!0,vt=X++,tt[vt]=yt(gt,_t===st?lt._2:lt._1,function(){return function(){delete tt[vt],Jt?Jt=!1:ft===null?Ct(_t,null,null):Ct(_t,ft._1,ft._2)}}),Jt){Jt=!1;return}break}ft===null?lt=null:(lt=ft._1,ft=ft._2)}}function Vt(kt){return function(lt){return function(){delete W[kt._1],kt._3=lt,Ct(lt,kt._2._1,kt._2._2)}}}function mt(){var kt=A,lt=et,ft=null,ot=null,_t,st;t:for(;;)switch(_t=null,st=null,kt){case A:switch(lt.tag){case f:ft&&(ot=new y(_,ft,ot)),ft=new y(f,lt._1,t,t),lt=lt._2;break;case d:ft&&(ot=new y(_,ft,ot)),ft=new y(d,t,lt._2,t),lt=lt._1;break;case l:ft&&(ot=new y(_,ft,ot)),ft=new y(l,t,lt._2,t),lt=lt._1;break;default:st=Y++,kt=H,_t=lt,lt=new y(J,st,new y(_,ft,ot),t),_t=P(B,q,_t),_t.onComplete({rethrow:!1,handler:Vt(lt)})(),W[st]=_t,q&&q.register(_t)}break;case H:if(ft===null)break t;ft._1===t?(ft._1=lt,kt=A,lt=ft._2,ft._2=t):(ft._2=lt,lt=ft,ot===null?ft=null:(ft=ot._1,ot=ot._2))}for(ct=lt,st=0;st<Y;st++)W[st].run()}function Wt(kt,lt){wt=B.left(kt);var ft;for(var ot in tt)if(tt.hasOwnProperty(ot)){ft=tt[ot];for(ot in ft)ft.hasOwnProperty(ot)&&ft[ot]()}tt=null;var _t=yt(kt,ct,lt);return function(st){return new y(i,function(ut){return function(){for(var Jt in _t)_t.hasOwnProperty(Jt)&&_t[Jt]();return b}})}}return mt(),function(kt){return new y(i,function(lt){return function(){return Wt(kt,lt)}})}}function Q(B,q,et){return new y(i,function(V){return function(){return R(B,q,et,V)}})}return y.EMPTY=t,y.Pure=T(e),y.Throw=T(n),y.Catch=T(r),y.Sync=T(o),y.Async=T(i),y.Bind=T(s),y.Bracket=T(u),y.Fork=T(a),y.Seq=T(c),y.ParMap=T(f),y.ParApply=T(d),y.ParAlt=T(l),y.Fiber=P,y.Supervisor=O,y.Scheduler=F,y.nonCanceler=b,y})();let k1=null;function Zw(){return k1||(typeof document>"u"?null:k1=document.createElement("canvas").getContext("2d"))}const cc=new Map;function L1(t,e,n,r,o,i){const s=`${n} ${e}px ${t}`,u=s+"|"+r;if(cc.has(u))return cc.get(u);const a=Zw();if(!a)return i;a.font=s;const c=o(a.measureText(r)),f=typeof document<"u"?document.fonts:null;if(!f||f.check(s))cc.set(u,c);else if(f&&f.load)try{f.load(s)}catch{}return c}const tv=(t,e,n,r)=>L1(t,e,n,r,o=>o.width,-1),ev=(t,e,n,r)=>L1(t,e,n,r,o=>({ascent:o.actualBoundingBoxAscent,descent:o.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),Os=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),C1=t=>t,S1={map:t=>e=>{if(e.tag==="MeasureText")return Os("MeasureText",e._1,e._2,n=>t(e._3(n)));if(e.tag==="MeasureInk")return Os("MeasureInk",e._1,e._2,n=>t(e._3(n)));g()}},gc=t=>e=>{const n=tv(t.family,t.size,t.weight,Vr(e));return n<0?Z(cs(e).length)*t.size*.62:n},fc=t=>e=>{const n=ev(t.family,t.size,t.weight,Vr(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},nv=t=>e=>Nt(bt("Bind",{type:"metrics",value:Os("MeasureInk",t,e,C1),map:S1.map},n=>Nt(bt("Return",n),Tt)),Tt),rv=t=>e=>Nt(bt("Bind",{type:"metrics",value:Os("MeasureText",t,e,C1),map:S1.map},n=>Nt(bt("Return",n),Tt)),Tt),E1=t=>t,G1=t=>t,qs=t=>t,P1=t=>t,I1=t=>t,Ft=(t,e,n,r,o)=>({tag:t,_1:e,_2:n,_3:r,_4:o}),A1=t=>t,_c=t=>t,ov=_c("BaselineTop"),Dn=_c("BaselineMiddle"),iv=_c("BaselineBottom"),Ti=A1("AlignLeft"),Ar=A1("AlignCenter"),Ge=I1("RoundJoin"),bi=I1("MiterJoin"),je=P1("ButtCap"),Bn=P1("RoundCap"),sv=qs("LayerPolyOut"),uv=qs("LayerPolyIn"),av=qs("LayerNodeMask"),cv=qs("LayerOverlay"),$s=G1("NonZero"),gv=G1("EvenOdd"),D1=E1("Normal"),Ws=E1("Difference"),he={r:255,g:255,b:255,a:255},ki=[5],me={map:t=>e=>{if(e.tag==="FillPath")return Ft("FillPath",e._1,e._2,t(e._3));if(e.tag==="StrokePath")return Ft("StrokePath",e._1,e._2,t(e._3));if(e.tag==="FillStrokePath")return Ft("FillStrokePath",e._1,e._2,e._3,t(e._4));if(e.tag==="DrawText")return Ft("DrawText",e._1,t(e._2));if(e.tag==="DrawTextAffine")return Ft("DrawTextAffine",e._1,e._2,t(e._3));if(e.tag==="PushTransform")return Ft("PushTransform",e._1,t(e._2));if(e.tag==="PopTransform")return Ft("PopTransform",t(e._1));if(e.tag==="PushClip")return Ft("PushClip",e._1,e._2,t(e._3));if(e.tag==="PopClip")return Ft("PopClip",t(e._1));if(e.tag==="PushBlend")return Ft("PushBlend",e._1,t(e._2));if(e.tag==="PopBlend")return Ft("PopBlend",t(e._1));if(e.tag==="PushAlpha")return Ft("PushAlpha",e._1,t(e._2));if(e.tag==="PopAlpha")return Ft("PopAlpha",t(e._1));if(e.tag==="PushBlur")return Ft("PushBlur",e._1,t(e._2));if(e.tag==="PopBlur")return Ft("PopBlur",t(e._1));if(e.tag==="PushLayer")return Ft("PushLayer",e._1,t(e._2));if(e.tag==="PopLayer")return Ft("PopLayer",t(e._1));if(e.tag==="SetViewport")return Ft("SetViewport",e._1,t(e._2));if(e.tag==="ClearBackground")return Ft("ClearBackground",e._1,t(e._2));if(e.tag==="BackgroundDots")return Ft("BackgroundDots",e._1,t(e._2));g()}},pr={r:26,g:26,b:26,a:255},dc=t=>e=>Math.imul(t,e),Mo=t=>{const e=t+1831565813|0,n=dc(e^e>>>15)(e|1),r=n^(n+dc(n^n>>>7)(n|61)|0),o=r^r>>>14;return{prng:o,value:o<0?(Z(o)+4294967296)/4294967296:Z(o)/4294967296}},Te=t=>e=>n=>{const r=Mo(n);return{prng:r.prng,value:t+r.value*(e-t)}},lc=t=>e=>w(n=>r=>dc(n^r)(-2048144789))(e)($(Er)(ur(t))),fv=t=>t,B1=t=>t,_v=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jn=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},R1=t=>e=>n=>{const r=nt.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=nt.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},hc=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},dv=t=>e=>n=>{const r=rt.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=rt.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},lv=B1("FlatLevel"),hv=B1("NestedLevel"),pc=fv("GenieSilhouette"),pv=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const o=Mo(t);return{prng:o.prng,yLift:o.value*n.yJitter*r}},mv=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const o=Mo(t);return{prng:o.prng,dx:(o.value*2-1)*n.xJitter*r}},Q1=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,o=Fe(r*r+n*n),i=(t.r*t.r-e.r*e.r+o*o)/(2*o),s=Fe(_v(0)(t.r*t.r-i*i)),u=t.cx+i*r/o,a=t.cy+i*n/o,c={x:u-s*n/o,y:a+s*r/o},f={x:u+s*n/o,y:a-s*r/o};return o===0||o>t.r+e.r?{x:(t.cx+e.cx)/2,y:t.cy}:c.y<f.y?c:f},Ys=t=>e=>{const n=Jn(e)(Jn(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},yv=t=>e=>n=>r=>o=>i=>{if(e)return{prng:t,r:o};if(n)return{prng:t,r:o*(1+i.rJitter)};if(r)return{prng:t,r:o*i.smallScale};const s=Mo(t);return{prng:s.prng,r:o*(1+s.value*i.rJitter)}},F1=t=>{const e=Jn(t.w)(t.h)/2;return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,4,t.x+t.w-e+.5522847498307936*e,t.y,t.x+t.w,t.y+e-.5522847498307936*e,t.x+t.w,t.y+e,4,t.x+t.w,t.y+e+.5522847498307936*e,t.x+t.w-e+.5522847498307936*e,t.y+t.h,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,4,t.x+e-.5522847498307936*e,t.y+t.h,t.x,t.y+e+.5522847498307936*e,t.x,t.y+e,4,t.x,t.y+e-.5522847498307936*e,t.x+e-.5522847498307936*e,t.y,t.x+e,t.y,5]},xv=t=>e=>n=>{const r=Mo(t),o=e.length;return o===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const i=R1(0)(o-1|0)(fe(bn(r.value*Z(n))));return i>=0&&i<e.length?e[i]:-1})()}},Jv=t=>e=>{const n=Mo(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const o=R1(0)(r-1|0)(fe(bn(n.value*Z(r))));return o>=0&&o<e.length?e[o]:-1})()}},z1=t=>{const e=Jn(t.w*.18)(t.h*.6);return[1,t.x+e,t.y,2,t.x+t.w,t.y,2,t.x+t.w-e,t.y+t.h,2,t.x,t.y+t.h,5]},M1=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],H1={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},Nv=t=>{const e=Jn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,o=t.x+n;return[1,t.x,r,4,t.x,r+.5522847498*e,o-.5522847498*n,r+e,o,r+e,4,o+.5522847498*n,r+e,t.x+t.w,r+.5522847498*e,t.x+t.w,r]},O1=t=>{const e=Jn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+t.h+5,o=t.y+e,i=r-e,s=t.x+n;return[1,t.x,o,4,t.x,o-.5522847498*e,s-.5522847498*n,t.y,s,t.y,4,s+.5522847498*n,t.y,t.x+t.w,o-.5522847498*e,t.x+t.w,o,2,t.x+t.w,i,4,t.x+t.w,i+.5522847498*e,s+.5522847498*n,r,s,r,4,s-.5522847498*n,r,t.x,i+.5522847498*e,t.x,i,5]},q1=t=>e=>{const n=e.y+e.h,r=ep(t.rBase*e.h)(e.w/(2*(1+(Z(t.minN)-1)*t.stepRatio))),o=e.w-2*r,i=2*r*t.stepRatio,s=hc(t.minN)(o<=0||i<=0?t.minN:fe(Gn(o/i))+1|0),u=s>=3?Ut(1,s-2|0):[],a=u.length,c=rr(a+1|0,2),f=c<1?[]:Gt(0,c,u),d=Jv(t.seed)((()=>{const m=a-c|0;return m<1?u:Gt(m,u.length,u)})()),l=d.idx,_=xv(d.prng)(at(m=>m!==l,f))(hc(1)(f.length-(Ve(vr)(l)(f)?1:0)|0)),h=_.idx,p=s>=2?o/(Z(s)-1):0;return w(m=>x=>{const J=x===h,y=x===l,T=x===0||x===(s-1|0),b=yv(m.prng)(T)(y)(J)(r)(t),C=pv(b.prng)(T)(t)(e.h),S=mv(C.prng)(T)(t)(p);return{prng:S.prng,circles:Pt(m.circles)({cx:e.x+dv(b.r)(e.w-b.r)((s>=2?r+Z(x)/(Z(s)-1)*o+S.dx:r+0*o+S.dx)+(y?t.heroShift*p:J?-1*t.smallShift*p:0)),cy:n-C.yLift,r:b.r})}})({prng:_.prng,circles:[]})(Ut(0,s-1|0)).circles},$1=t=>e=>{const n=t.length;return Yt(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?Q1(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?Q1(o)(t[i]):{x:o.cx+o.r,y:e}})()}))(t)},W1=t=>{const e=Jn(t.h*.4)(t.w*.2);return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,2,t.x+t.w,t.y+t.h/2,2,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,2,t.x,t.y+t.h/2,5]},wv=t=>e=>n=>{const r=Or(e.y-t.cy)(e.x-t.cx),o=Or(n.y-t.cy)(n.x-t.cx),i=o>r?o-r:o+6.283185307179586-r,s=hc(1)(fe(zi(i/1.5707963267948966))),u=i/Z(s),a=1.3333333333333333*np(u/4);return Lt(Ut(0,s-1|0))(c=>{const f=r+Z(c+1|0)*u,d=t.cx+t.r*mn(f),l=t.cy+t.r*an(f),_=r+Z(c)*u;return[4,t.cx+t.r*mn(_)-a*t.r*an(_),t.cy+t.r*an(_)+a*t.r*mn(_),d+a*t.r*an(f),l-a*t.r*mn(f),d,l]})},Y1=t=>e=>{const n=t.h*.38,r=$1(q1(H1)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),o=Jn(e)(Jn(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...Lt(r)(i=>wv(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]:Ys(t)(e)},mc=t=>e=>n=>r=>o=>i=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(o)(i);if(e==="Cylinder"){const s=O1(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Parallelogram"){const s=z1(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Diamond"){const s=W1(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Ellipse"){const s=F1(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Document"){const s=M1(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Cloud"){const s=Y1(n)(r);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}return t.drawRoundedRect(n)(r)(o)(i)},vv={fillPath:t=>e=>Nt(bt("Bind",{type:"render",value:Ft("FillPath",t,e,void 0),map:me.map},n=>Nt(bt("Return",n),Tt)),Tt),strokePath:t=>e=>Nt(bt("Bind",{type:"render",value:Ft("StrokePath",t,e,void 0),map:me.map},n=>Nt(bt("Return",n),Tt)),Tt),fillStrokePath:t=>e=>n=>Nt(bt("Bind",{type:"render",value:Ft("FillStrokePath",t,e,n,void 0),map:me.map},r=>Nt(bt("Return",r),Tt)),Tt),drawRoundedRect:t=>e=>n=>r=>{if(n.tag==="Just"){if(r.tag==="Just")return Nt(bt("Bind",{type:"render",value:Ft("FillStrokePath",Ys(t)(e),n._1,r._1,void 0),map:me.map},o=>Nt(bt("Return",o),Tt)),Tt);if(r.tag==="Nothing")return Nt(bt("Bind",{type:"render",value:Ft("FillPath",Ys(t)(e),n._1,void 0),map:me.map},o=>Nt(bt("Return",o),Tt)),Tt);g()}if(n.tag==="Nothing"){if(r.tag==="Just")return Nt(bt("Bind",{type:"render",value:Ft("StrokePath",Ys(t)(e),r._1,void 0),map:me.map},o=>Nt(bt("Return",o),Tt)),Tt);if(r.tag==="Nothing")return Nt(bt("Return",void 0),Tt)}g()},drawText:t=>Nt(bt("Bind",{type:"render",value:Ft("DrawText",t,void 0),map:me.map},e=>Nt(bt("Return",e),Tt)),Tt),drawTextAffine:t=>e=>Nt(bt("Bind",{type:"render",value:Ft("DrawTextAffine",t,e,void 0),map:me.map},n=>Nt(bt("Return",n),Tt)),Tt),pushTransform:t=>Nt(bt("Bind",{type:"render",value:Ft("PushTransform",t,void 0),map:me.map},e=>Nt(bt("Return",e),Tt)),Tt),popTransform:Nt(bt("Bind",{type:"render",value:Ft("PopTransform",void 0),map:me.map},t=>Nt(bt("Return",t),Tt)),Tt),pushBakedTransform:t=>Nt(bt("Bind",{type:"render",value:Ft("PushTransform",t,void 0),map:me.map},e=>Nt(bt("Return",e),Tt)),Tt),popBakedTransform:Nt(bt("Bind",{type:"render",value:Ft("PopTransform",void 0),map:me.map},t=>Nt(bt("Return",t),Tt)),Tt),pushClip:t=>e=>Nt(bt("Bind",{type:"render",value:Ft("PushClip",t,e,void 0),map:me.map},n=>Nt(bt("Return",n),Tt)),Tt),popClip:Nt(bt("Bind",{type:"render",value:Ft("PopClip",void 0),map:me.map},t=>Nt(bt("Return",t),Tt)),Tt),pushBlend:t=>Nt(bt("Bind",{type:"render",value:Ft("PushBlend",t,void 0),map:me.map},e=>Nt(bt("Return",e),Tt)),Tt),popBlend:Nt(bt("Bind",{type:"render",value:Ft("PopBlend",void 0),map:me.map},t=>Nt(bt("Return",t),Tt)),Tt),pushAlpha:t=>Nt(bt("Bind",{type:"render",value:Ft("PushAlpha",t,void 0),map:me.map},e=>Nt(bt("Return",e),Tt)),Tt),popAlpha:Nt(bt("Bind",{type:"render",value:Ft("PopAlpha",void 0),map:me.map},t=>Nt(bt("Return",t),Tt)),Tt),pushBlur:t=>Nt(bt("Bind",{type:"render",value:Ft("PushBlur",t,void 0),map:me.map},e=>Nt(bt("Return",e),Tt)),Tt),popBlur:Nt(bt("Bind",{type:"render",value:Ft("PopBlur",void 0),map:me.map},t=>Nt(bt("Return",t),Tt)),Tt),pushLayer:t=>Nt(bt("Bind",{type:"render",value:Ft("PushLayer",t,void 0),map:me.map},e=>Nt(bt("Return",e),Tt)),Tt),popLayer:Nt(bt("Bind",{type:"render",value:Ft("PopLayer",void 0),map:me.map},t=>Nt(bt("Return",t),Tt)),Tt),setViewport:t=>Nt(bt("Bind",{type:"render",value:Ft("SetViewport",t,void 0),map:me.map},e=>Nt(bt("Return",e),Tt)),Tt),clearBackground:t=>Nt(bt("Bind",{type:"render",value:Ft("ClearBackground",t,void 0),map:me.map},e=>Nt(bt("Return",e),Tt)),Tt),backgroundDots:t=>Nt(bt("Bind",{type:"render",value:Ft("BackgroundDots",t,void 0),map:me.map},e=>Nt(bt("Return",e),Tt)),Tt),measureText:t=>e=>rv(t)(e),measureInk:t=>e=>nv(t)(e),insideTokenStyle:t=>Nt(bt("Return",pc),Tt),Monad0:()=>Xw},Tv=t=>()=>t.clip("evenodd"),bv=t=>e=>()=>{t.filter=`blur(${e}px)`},kv=t=>e=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(e.tile,.001))),r=Math.max(2,Math.round(e.tile*n)),o=document.createElement("canvas");o.width=r,o.height=r;const i=o.getContext("2d");i.scale(n,n),i.fillStyle=e.bgCss,i.fillRect(0,0,e.tile,e.tile),i.fillStyle=e.dotCss,i.beginPath(),i.arc(e.tile/2,e.tile/2,e.dotR,0,2*Math.PI),i.fill();const s=t.createPattern(o,"repeat");s&&typeof s.setTransform=="function"&&s.setTransform(new DOMMatrix().translateSelf(e.ox,e.oy).scaleSelf(1/n,1/n)),t.save(),t.fillStyle=s,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},yc=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},xc=t=>e=>n=>{const r=e.stroke;return()=>{const o=r.value,i=wp(t)(n);if(o!==n)return i(),e.stroke.value=n}},Lv=t=>e=>n=>{const r=e.font;return()=>{const o=r.value,i=Gp(t)(n);if(o!==n)return i(),e.font.value=n}},Li=t=>e=>n=>{const r=e.fill;return()=>{const o=r.value,i=Np(t)(n);if(o!==n)return i(),e.fill.value=n}},Vs=t=>e=>{const n=e.length,r=i=>{if(i>=n)return()=>{};const s=i>=0&&i<e.length?e[i]:0;if(s===1){const u=Ag(t)((()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})()),a=r(i+3|0);return()=>(u(),a())}if(s===2){const u=Uo(t)((()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})()),a=r(i+3|0);return()=>(u(),a())}if(s===3){const u=Ko(t)({cpx:(()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})(),cpy:(()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=i+3|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=i+4|0;return c>=0&&c<e.length?e[c]:0})()}),a=r(i+5|0);return()=>(u(),a())}if(s===4){const u=Ip(t)({cp1x:(()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})(),cp1y:(()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})(),cp2x:(()=>{const c=i+3|0;return c>=0&&c<e.length?e[c]:0})(),cp2y:(()=>{const c=i+4|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=i+5|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=i+6|0;return c>=0&&c<e.length?e[c]:0})()}),a=r(i+7|0);return()=>(u(),a())}if(s===5){const u=Dg(t),a=r(i+1|0);return()=>(u(),a())}return()=>{}},o=Ig(t);return()=>(o(),r(0)())},Cv=t=>e=>n=>r=>o=>i=>{const s=yc(i)(yc(r/2)(o/2)),u=Ag(t)(e+s)(n);return()=>(u(),Uo(t)(e+r-s)(n)(),Ko(t)({cpx:e+r,cpy:n,x:e+r,y:n+s})(),Uo(t)(e+r)(n+o-s)(),Ko(t)({cpx:e+r,cpy:n+o,x:e+r-s,y:n+o})(),Uo(t)(e+s)(n+o)(),Ko(t)({cpx:e,cpy:n+o,x:e,y:n+o-s})(),Uo(t)(e)(n+s)(),Ko(t)({cpx:e,cpy:n,x:e+s,y:n})(),Dg(t)())},Sv=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),V1=t=>e=>{const n=Lp(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=Sv();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0},groupAlpha:{value:1},alphaSaves:{value:[]}}}},Ev={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},Gv=t=>ee(t.weight)+" "+Fr(t.size)+"px "+t.family,Yn=t=>{const e=Fr(Z(t.a)/255);return t.a>=255?"rgb("+ee(t.r)+","+ee(t.g)+","+ee(t.b)+")":"rgba("+ee(t.r)+","+ee(t.g)+","+ee(t.b)+","+e+")"},Pv=t=>e=>n=>r=>{const o=Li(t)(n)(Yn(r));return()=>(o(),kp(t)({x:0,y:0,width:e.width,height:e.height})())},Iv=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",kv(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:Yn(n.bgColor),dotCss:Yn(n.dotColor),tile:n.tile,dotR:n.dotRadius,ox:n.origin.x,oy:n.origin.y})())},Av=t=>e=>n=>r=>{const o=Li(t)(e)(Yn(r));return()=>(o(),Vs(t)(n)(),Uu(t)())},Dv=t=>e=>n=>r=>o=>{const i=Li(t)(e)(Yn(r));return()=>(i(),xc(t)(e)(Yn(o.color))(),$u(t)(o.width)(),Wi(t)((()=>{if(o.lineJoin==="RoundJoin")return $i;if(o.lineJoin==="BevelJoin")return ta;if(o.lineJoin==="MiterJoin")return ea;g()})())(),ia(t)((()=>{if(o.lineCap==="ButtCap")return oa;if(o.lineCap==="RoundCap")return na;if(o.lineCap==="SquareCap")return ra;g()})())(),Vs(t)(n)(),Uu(t)(),Vu(t)())},Bv=t=>e=>n=>r=>o=>i=>{const s=Ig(t);return()=>{if(s(),Cv(t)(n.x)(n.y)(n.w)(n.h)(r)(),o.tag==="Just"?(Li(t)(e)(Yn(o._1.color))(),Uu(t)()):o.tag==="Nothing"||g(),i.tag==="Just")return xc(t)(e)(Yn(i._1.color))(),$u(t)(i._1.width)(),Wi(t)((()=>{if(i._1.lineJoin==="RoundJoin")return $i;if(i._1.lineJoin==="BevelJoin")return ta;if(i._1.lineJoin==="MiterJoin")return ea;g()})())(),ia(t)((()=>{if(i._1.lineCap==="ButtCap")return oa;if(i._1.lineCap==="RoundCap")return na;if(i._1.lineCap==="SquareCap")return ra;g()})())(),Vu(t)();i.tag!=="Nothing"&&g()}},Rv=t=>e=>n=>r=>{const o=xc(t)(e)(Yn(r.color));return()=>(o(),$u(t)(r.width)(),Wi(t)((()=>{if(r.lineJoin==="RoundJoin")return $i;if(r.lineJoin==="BevelJoin")return ta;if(r.lineJoin==="MiterJoin")return ea;g()})())(),ia(t)((()=>{if(r.lineCap==="ButtCap")return oa;if(r.lineCap==="RoundCap")return na;if(r.lineCap==="SquareCap")return ra;g()})())(),Vs(t)(n)(),Vu(t)())},U1=t=>e=>n=>{const r=Li(t)(e)(Yn(n.color));return()=>(r(),Lv(t)(e)(Gv(n.font))(),qp(t)((()=>{if(n.align==="AlignLeft")return Qp;if(n.align==="AlignCenter")return zp;if(n.align==="AlignRight")return Fp;g()})())(),Op(t)((()=>{if(n.baseline==="BaselineTop")return Ap;if(n.baseline==="BaselineMiddle")return Dp;if(n.baseline==="BaselineAlphabetic")return Bp;if(n.baseline==="BaselineBottom")return Rp;g()})())(),Pp(t)(n.content)(n.x)(n.y)())},X1={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),s=o();return i(s)}},Functor0:()=>Ev},Qv={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>X1},Fv=t=>e=>n=>{const r=yc(e.width/n.vw)(e.height/n.vh),o=Xu(t)({translateX:(e.width-n.vw*r)/2-n.vx*r,translateY:(e.height-n.vh*r)/2-n.vy*r});return()=>(o(),Xo(t)({scaleX:r,scaleY:r})(),Wi(t)($i)())},zv={pure:t=>e=>()=>t,Apply0:()=>X1},Mv={Applicative0:()=>zv,Bind1:()=>Qv},Jc={fillPath:t=>e=>n=>{const r=Av(n.ctx)(n.styleCache)(t)(e.color),o=n.maskDepth;return()=>{if(o.value===0)return r()}},strokePath:t=>e=>n=>{const r=Rv(n.ctx)(n.styleCache)(t)(e),o=n.maskDepth;return()=>{if(o.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const o=Dv(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=Bv(o.ctx)(o.styleCache)(t)(e)(n)(r),s=o.maskDepth;return()=>{if(s.value===0)return i()}},drawText:t=>e=>{const n=U1(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=ir(n.ctx),o=n.maskDepth;return()=>{if(o.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Cp(n.ctx)(t)(),U1(n.ctx)(n.styleCache)(e)(),sr(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=ir(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Xu(e.ctx)({translateX:t.tx,translateY:t.ty})(),Xo(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=sr(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=ir(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Xu(e.ctx)({translateX:t.tx,translateY:t.ty})(),Xo(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=sr(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=ir(n.ctx),o=n.maskDepth;return()=>{if(o.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Vs(n.ctx)(t)(),e==="NonZero")return bp(n.ctx)();if(e==="EvenOdd")return Tv(n.ctx)();g()}}},popClip:t=>{const e=sr(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=ir(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 Rg(e.ctx)(Mp)();if(t==="Difference")return Rg(e.ctx)(Hp)();g()}}},popBlend:t=>{const e=sr(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=ir(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="";const o=e.groupAlpha.value,i=e.alphaSaves.value;e.alphaSaves.value=[...i,o];const s=o*t;return e.groupAlpha.value=s,Tp(e.ctx)(s)()}}},popAlpha:t=>{const e=sr(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=Hr(r);if(o.tag==="Just")return t.alphaSaves.value=o._1.init,t.groupAlpha.value=o._1.last;if(o.tag==="Nothing")return t.groupAlpha.value=1;g()}}},pushBlur:t=>e=>{const n=ir(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=bv(e.ctx)(t);if(t>=.01)return o()}}},popBlur:t=>{const e=sr(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=Fv(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=Pv(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=Iv(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=gc(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=fc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>pc,Monad0:()=>Mv},Hv=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ho=t=>e=>n=>{const r=Hv(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},K1=t=>{const e=rt.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=rt.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Us=t=>{if(t.tag==="Hidden")return{alpha:0,scale:0};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:t._1>0?1:0,scale:oi(8)(.6)(K1(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:oi(8)(.6)(K1(1-t._1))};g()};function Ov(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function qv(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:Ov(o,i)}}return n}function $v(t,e,n){let r=0;for(let o=0;o<t.length;o++){const i=t[o],s=r,u=s+i.len;if(n<=u){const a=i.len>1e-6?(n-s)/i.len:0;return{x:i.a.x+(i.b.x-i.a.x)*a,y:i.a.y+(i.b.y-i.a.y)*a}}r=u}return e.length>0?e[e.length-1]:{x:0,y:0}}function j1(t,e){if(e.length===0)return[];const n=qv(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]=$v(n,e,i*r/t);return o}function Wv(t,e){const n=e.length;if(n===0)return e;const r=(t%n+n)%n|0,o=new Array(n);for(let i=0;i<n;i++)o[i]=e[(i+r)%n];return o}function Yv(t,e){const n=e.length;if(n===0)return e;let r=0,o=1/0;for(let i=0;i<n;i++){let s=0;for(let u=0;u<n;u++){const a=t[u]||{x:0,y:0},c=e[(u+i)%n]||{x:0,y:0},f=a.x-c.x,d=a.y-c.y;s+=f*f+d*d}s<o&&(o=s,r=i)}return Wv(r,e)}const Z1=t=>e=>n=>{const r=j1(t,e),o=j1(t,n),i=Yv(r,o);return{from:r,to:i}};function td(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 Vv(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 Uv(t,e){const n=e.length;if(n===0)return e;const r=new Array(n);for(let o=0;o<n;o++){const i=e[((o-1)%n+n)%n],s=e[((o+1)%n+n)%n],u=e[o];r[o]={x:u.x+((i.x+s.x)/2-u.x)*t,y:u.y+((i.y+s.y)/2-u.y)*t}}return r}function Xv(t){return t<0?0:t>1?1:t}const ed=t=>e=>n=>r=>{const o=e.length;if(o===0)return[];const i=td(e),s=td(n),u=Vv(i,s),a=new Array(o);let c=1/0,f=-1/0;for(let _=0;_<o;_++){const h=e[_],p=(h.x-i.x)*u.x+(h.y-i.y)*u.y;a[_]=p,p<c&&(c=p),p>f&&(f=p)}const d=f-c;let l=new Array(o);for(let _=0;_<o;_++){const h=e[_],p=n[_];if(p===void 0){l[_]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(a[_]-c)/d),x=Math.max(1e-4,1-m),J=Xv((t-m)/x),y=J*J*(3-2*J);l[_]={x:h.x+(p.x-h.x)*y,y:h.y+(p.y-h.y)*y}}for(let _=0;_<r.smoothPasses;_++)l=Uv(.5,l);return l},Vn=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},nd=w(Jo)(0),rd=t=>e=>n=>{const r=rt.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=rt.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Kv=w(t=>e=>t+e.len)(0),Nc=t=>{const e=Mt(n=>N,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Lt(Gt(1,t.length,t))(n=>[2,n.x,n.y]),5];g()},jv=t=>e=>{const n=Vn(e)(Vn(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},Zv=t=>{const e=Mt(n=>N,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Lt(e._1.tail)(n=>[2,n.x,n.y])];g()},tT=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return O1(e);if(t.shape==="Parallelogram")return z1(e);if(t.shape==="Diamond")return W1(e);if(t.shape==="Ellipse")return F1(e);if(t.shape==="Document")return M1(e);if(t.shape==="Cloud")return Y1(e)(7);if(t.shape==="Rectangle")return jv(e)(7);g()},be=t=>e=>n=>$(r=>{const o=Z(r)/Z(n);return{x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o}})(Ut(0,n-1|0)),eT=t=>{const e=Jn(t.w*.18)(t.h*.6);return[...be({x:t.x+e,y:t.y})({x:t.x+t.w,y:t.y})(16),...be({x:t.x+t.w,y:t.y})({x:t.x+t.w-e,y:t.y+t.h})(16),...be({x:t.x+t.w-e,y:t.y+t.h})({x:t.x,y:t.y+t.h})(16),...be({x:t.x,y:t.y+t.h})({x:t.x+e,y:t.y})(16)]},Oo=t=>e=>{const n=Vn(t)(Vn(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}},wc=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return Fe(r*r+n*n)},nT=t=>Ie(e=>n=>({a:e,b:n,len:wc(e)(n)}),t,Gt(1,t.length,t)),rT=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?v("Just",e[n]):N,o=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];g()})(),i=0<e.length?v("Just",e[0]):N,s=(()=>{if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return{x:0,y:0};g()})(),u=e.length;return u<3?e:[s,...Lt(Ut(1,u-2|0))(a=>{const c=a+1|0,f=c>=0&&c<e.length?v("Just",e[c]):N,d=a>=0&&a<e.length?v("Just",e[a]):N,l=a-1|0,_=l>=0&&l<e.length?v("Just",e[l]):N;if(_.tag==="Just"&&d.tag==="Just"&&f.tag==="Just"){const h=d._1,p=wc(h)(f._1),m=wc(_._1)(h),x=Vn(t)(p/2),J=Vn(t)(m/2),y=p>0?x/p:0,T=h.x+(f._1.x-h.x)*y,b=h.y+(f._1.y-h.y)*y,C=m>0?J/m:0,S=h.x+(_._1.x-h.x)*C,E=h.y+(_._1.y-h.y)*C;return $(F=>{const O=Z(F)/Z(10),G=1-O;return{x:G*G*S+2*G*O*h.x+O*O*T,y:G*G*E+2*G*O*h.y+O*O*b}})(Ut(0,10))}return[]}),...o]},oT=t=>e=>n=>r=>o=>$(i=>{const s=Z(i)/Z(o),u=1-s,a=s*s*s,c=3*u*s*s,f=3*u*u*s,d=u*u*u;return{x:d*t.x+f*e.x+c*n.x+a*r.x,y:d*t.y+f*e.y+c*n.y+a*r.y}})(Ut(0,o-1|0)),iT=t=>[...be({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...be({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...oT({x:t.x+t.w,y:t.y+t.h*.85})({x:t.x+t.w*.66,y:t.y+t.h*1.05})({x:t.x+t.w*.34,y:t.y+t.h*.65})({x:t.x,y:t.y+t.h*.85})(32),...be({x:t.x,y:t.y+t.h*.85})({x:t.x,y:t.y})(12)],od=t=>e=>$(n=>{const r=6.283185307179586*Z(n)/Z(64);return{x:t.x+e*mn(r),y:t.y+e*an(r)}})(Ut(0,63)),Xs=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]},sT=t=>{const e=t.y+t.h/2,n=Jn(t.h*.4)(t.w*.2);return[...be({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...be({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...be({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...be({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...be({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...be({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},id=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:nd($(n=>n.x)(t))/Z(e),y:nd($(n=>n.y)(t))/Z(e)}},Ks=t=>e=>n=>r=>o=>$(i=>{const s=n+(r-n)*(Z(i)/Z(o));return{x:t.x+e*mn(s),y:t.y+e*an(s)}})(Ut(0,o-1|0)),sd=t=>e=>{const n=Vn(t)(Vn(e.w/2)(e.h/2));return[...be({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...Ks({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...be({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...Ks({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...be({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...Ks({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...be({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...Ks({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},js=t=>e=>n=>r=>o=>i=>$(s=>{const u=r+(o-r)*(Z(s)/Z(i));return{x:t.x+e*mn(u),y:t.y+n*an(u)}})(Ut(0,i-1|0)),uT=t=>{const e=t.h*.38;return[...Lt($1(q1(H1)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=Or(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),o=Or(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return js({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(o)(r>o?r:r+6.283185307179586)(16)}),...be({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...be({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...be({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},aT=t=>{const e=Vn(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[...js({x:i,y:r})(n)(e)(3.141592653589793)(6.283185307179586)(24),...be({x:t.x+t.w,y:r})({x:t.x+t.w,y:o})(12),...js({x:i,y:o})(n)(e)(0)(3.141592653589793)(24),...be({x:t.x,y:o})({x:t.x,y:r})(12)]},to=t=>e=>e.shape==="Cylinder"?aT(e):e.shape==="Parallelogram"?eT(e):e.shape==="Diamond"?sT(e):e.shape==="Ellipse"?sd(Jn(e.w)(e.h)/2)(e):e.shape==="Document"?iT(e):e.shape==="Cloud"?uT(e):sd(t)(e),cT=t=>{const e=Vn(t.h*.075)(t.w*.075),n=t.w/2;return js({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},gT=t=>e=>n=>w(r=>o=>{const i=r.pos+o.len,s=n<i?(n-r.pos)/o.len:1,u={x:o.a.x+(o.b.x-o.a.x)*s,y:o.a.y+(o.b.y-o.a.y)*s},a=e>r.pos?(e-r.pos)/o.len:0,c={x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a},f=r.points.length-1|0,d=f>=0&&f<r.points.length?(()=>{const l=r.points[f].x-c.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const _=r.points[f].y-c.y;return _<0?-_<1e-4:_<1e-4})()})()?Pt(r.points)(u):[...r.points,c,u]:[c,u];return o.len<=0||i<=e||r.pos>=n?{...r,pos:i}:{pos:i,points:d}})({pos:0,points:[]})(t).points,fT=t=>e=>n=>{const r=Mt(o=>N,o=>i=>v("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const o=nT(t),i=Kv(o),s=rd(0)(i)(e*i),u=rd(0)(i)(n*i);return u<=s?[]:gT(o)(s)(u)}g()},_T=t=>e=>n=>r=>{const o=r.x-n.x,i=r.y-n.y,s=e.x-t.x,u=e.y-t.y,a=n.x-t.x,c=n.y-t.y,f=s*i-u*o,d=(a*i-c*o)/f,l=(a*u-c*s)/f;return(f<0?-f<1e-9:f<1e-9)?N:d>=0&&d<=1&&l>=0&&l<=1?v("Just",d):N},dT=t=>e=>n=>{const r=Dt(o=>i=>rt.compare(o.t)(i.t))(xt(o=>{const i=_T(e)(n)(o._1)(o._2);return i.tag==="Just"?v("Just",{t:i._1,p:{x:e.x+(n.x-e.x)*i._1,y:e.y+(n.y-e.y)*i._1}}):N})(Ie(En,t,[...Gt(1,t.length,t),...Gt(0,1,t)])));return 0<r.length?v("Just",r[0].p):N},ud=t=>e=>{const n=Hr(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=dT(t)(n._1.init[r])(n._1.last);if(o.tag==="Just")return Pt(n._1.init)(o._1);if(o.tag==="Nothing")return e;g()}return e}g()},Dr=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},vc=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},lT=t=>e=>n=>{const r=rt.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=rt.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},hT=t=>e=>{const n=Dr(0)(t.y+4-e.y)+Dr(0)(e.y+e.h-(t.y+t.h-4)),r=Dr(0)(t.x+4-e.x)+Dr(0)(e.x+e.w-(t.x+t.w-4));return r*e.h+n*e.w+r*n},pT=t=>e=>{const n=t.y+t.h-6,r=t.y+6,o=t.x+14,i=t.x+t.w-14,s=w(Dr)(0)($(u=>o-10<u.x+u.w+12&&i+10>u.x-12&&r-10<u.y+u.h+12&&n+10>u.y-12?vc((u.x+u.w+12-(o-10))/.7071067811865476)((n+10-(u.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+s*.7071067811865476,y:t.y-s*.7071067811865476}},mT=t=>e=>{const n=vc(t.x+t.w)(e.x+e.w)-Dr(t.x)(e.x),r=vc(t.y+t.h)(e.y+e.h)-Dr(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},ad=t=>e=>n=>r=>{const o=t+4,i=Dr(0)(e-8),s=o+i-n;return n<=i?lT(o)(s)(r):t+(e-n)/2},cd=t=>e=>({...e,x:ad(t.x)(t.w)(e.w)(e.x),y:ad(t.y)(t.h)(e.h)(e.y)}),yT=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}]},xT=t=>e=>n=>r=>o=>{const i=o.y+o.h/2-n.token.y,s=o.y-r.y;return(()=>{const u=o.x+o.w/2-n.token.x,a=o.x-r.x;return 1e6*hT(t)(o)+1e4*w(c=>f=>c+mT(o)(f))(0)(e)+.05*(a*a+s*s)+.01*(u*u+i*i)})()+(o.y>n.token.y?100:0)},JT=t=>e=>n=>r=>{const o=s=>{const u=cd(t)(s);return{rect:u,score:xT(t)(e)(n)(r)(u)}},i=Mt(s=>N,s=>u=>v("Just",{head:s,tail:u}),[r,n.rect,...yT(n)]);if(i.tag==="Nothing")return cd(t)(r);if(i.tag==="Just")return w(s=>u=>{const a=o(u);return a.score<s.score?a:s})(o(i._1.head))(i._1.tail).rect;g()},NT=t=>e=>n=>w(r=>o=>{const i=pT(o.rect)(r.obstacles),s=i.x>=t.x+4&&i.y>=t.y+4&&i.x+i.w<=t.x+t.w-4&&i.y+i.h<=t.y+t.h-4?i:JT(t)(r.obstacles)(o)(i);return{acc:j(I)(o.id)(s)(r.acc),obstacles:Pt(r.obstacles)(s)}})({acc:D,obstacles:e})(n).acc,Tc=t=>t,mr=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},eo=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},wT=lo(Bu)(zt),vT=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},TT=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},gd=Tc("SegMove"),bT=Tc("SegLine"),kT=Tc("SegQuad"),fd={offset:.4,passes:1,rMax:1.5},_d=t=>fe(bn(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,Zs=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},tu=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},yr=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},Ci=(()=>{const t=w(e=>n=>((e*31|0)+fe(bn(n.x*100))|0)+fe(bn(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),LT=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const o=n,i=r,s=o>=0&&o<t.length?v("Just",t[o]):N;if(s.tag==="Nothing"){n=t.length;continue}if(s.tag==="Just"){if(s._1===1){const u={x:(()=>{const a=o+1|0;return a>=0&&a<t.length?t[a]:0})(),y:(()=>{const a=o+2|0;return a>=0&&a<t.length?t[a]:0})()};e.push({kind:gd,m:i,c:i,p:u,len:0}),r=u,n=o+3|0;continue}if(s._1===2){const u={x:(()=>{const f=o+1|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=o+2|0;return f>=0&&f<t.length?t[f]:0})()},a=u.x-i.x,c=u.y-i.y;e.push({kind:bT,m:i,c:i,p:u,len:Fe(a*a+c*c)}),r=u,n=o+3|0;continue}if(s._1===3){const u={x:(()=>{const f=o+3|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=o+4|0;return f>=0&&f<t.length?t[f]:0})()},a=u.x-i.x,c=u.y-i.y;e.push({kind:kT,m:i,c:{x:(()=>{const f=o+1|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=o+2|0;return f>=0&&f<t.length?t[f]:0})()},p:u,len:Fe(a*a+c*c)*1.05}),r=u,n=o+5|0;continue}if(s._1===5){e.push({kind:gd,m:i,c:i,p:i,len:0}),n=o+1|0;continue}n=t.length;continue}g()}return e},CT=t=>e=>{const n=e.length-1|0,r=n<1?[]:Gt(0,n,e),o=(()=>{const s=r.length-1|0;return s>=0&&s<r.length?v("Just",r[s]):N})(),i=e.length-1|0;if(i>=0&&i<e.length&&o.tag==="Just"){const s=e[i].y-o._1.y,u=e[i].x-o._1.x,a=Fe(u*u+s*s);return a<=1e-4?e:Pt((()=>{const c=e.length-1|0;return c<1?[]:Gt(0,c,e)})())({x:e[i].x+u/a*t,y:e[i].y+s/a*t})}return e},ST=t=>e=>n=>ge(w(r=>o=>{const i=Te(0)(t)(r.prng),s=Te(0)(6.283185307179586)(i.prng);return{prng:s.prng,out:[{x:o.x+i.value*mn(s.value),y:o.y+i.value*an(s.value)},...r.out]}})({prng:e,out:[]})(n).out),ET=t=>e=>n=>{if(e.kind==="SegMove")return tu(t)(e.p);if(e.kind==="SegLine")return yr(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 yr(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});g()},GT=t=>e=>{if(e.kind==="SegMove")return tu(t)(e.p);if(e.kind==="SegLine")return yr(t)(e.p);if(e.kind==="SegQuad")return Zs(t)(e.c)(e.p);g()},dd=t=>e=>{const n=LT(e),r=w(u=>a=>u+a.len)(0)(n)*mr(0)(eo(1)(t)),o=[];let i=0,s=0;for(;s<n.length;){const u=s,a=i;if(u>=0&&u<n.length){if(a+n[u].len<=r){const c=n[u];GT(o)(c)(),i=a+c.len,s=u+1|0;continue}if(a>=r){s=n.length;continue}ET(o)(n[u])((r-a)/mr(n[u].len)(1e-4))()}s=n.length}return o},ld={offset:1.5,passes:2,rMax:14,overshoot:2.5},hd=t=>e=>n=>r=>{const o=r.y-n.y,i=n.y-e.y,s=r.x-n.x,u=Fe(s*s+o*o),a=n.x-e.x,c=Fe(a*a+i*i),f=eo(t.rMax*(tp(c>0&&u>0?mr(-1)(eo(1)((a*s+i*o)/(c*u))):1)/3.141592653589793))(.4*eo(c)(u));return{inP:c>0?{x:n.x-a/c*f,y:n.y-i/c*f}:n,curr:n,outP:u>0?{x:n.x+s/u*f,y:n.y+o/u*f}:n}},pd=t=>e=>{const n=e.length,r=[],o=0<e.length?v("Just",e[0]):N;if(o.tag==="Just"?tu(r)(o._1)():o.tag==="Nothing"||g(),n>=3){let s=1;for(;s<=(n-2|0);){const u=s,a=u+1|0;if(a>=0&&a<e.length){if(u>=0&&u<e.length){const c=u-1|0;if(c>=0&&c<e.length){const f=hd(t)(e[c])(e[u])(e[a]);yr(r)(f.inP)(),Zs(r)(f.curr)(f.outP)()}}s=u+1|0;continue}s=u+1|0}}const i=e.length-1|0;return i>=0&&i<e.length&&n>=2&&yr(r)(e[i])(),r},PT=t=>e=>n=>r=>o=>{if(o.length<4)return pd(t)(o);const i=0<o.length?v("Just",o[0]):N,s=(()=>{if(i.tag==="Nothing")return{x:0,y:0};if(i.tag==="Just")return i._1;g()})(),u=o.length-1|0,a=br(br(e)(u)+u|0)(u),c=_=>{const h=br(_+u|0)(u);return h>=0&&h<o.length?o[h]:s},f=$(_=>hd(t)(c((a+_|0)-1|0))(c(a+_|0))(c((a+_|0)+1|0)))(Ut(0,u-1|0)),d=[],l=0<f.length?v("Just",f[0]):N;if(l.tag==="Just")if(tu(d)(l._1.outP)(),wT((()=>{const _=Mt(h=>N,h=>p=>v("Just",p),f);if(_.tag==="Nothing")return[];if(_.tag==="Just")return _._1;g()})())(_=>{const h=yr(d)(_.inP);return()=>(h(),Zs(d)(_.curr)(_.outP)())})(),n)yr(d)(l._1.inP)(),Zs(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const _=f.length-1|0;_>=0&&_<f.length?yr(d)((()=>{const h=1-r;return{x:f[_].outP.x+(l._1.inP.x-f[_].outP.x)*h,y:f[_].outP.y+(l._1.inP.y-f[_].outP.y)*h}})())():yr(d)(l._1.inP)()}else l.tag==="Nothing"||g();return d},qo=t=>e=>n=>r=>{const o=vT(1)(r.length-1|0),i=Te(0)(Z(o))(lc("shape")(e)),s=TT(o-1|0)(fe(bn(i.value))),u=i.prng;return $(a=>{const c=Te(0)(1)(lc(ee(a))(u)),f=Te(-.18)(.3)(c.prng),d=c.value<.7,l=Te(.5)(.85)(f.prng),_=ST(t.offset)(l.prng)(r);return{path:n?PT(t)(s)(d)(f.value)(_):pd(t)(_),alpha:l.value}})(Ut(0,t.passes-1|0))},IT=t=>e=>n=>qo(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}]),AT=t=>e=>n=>{const r=mr(0)(eo(1)(n)),o=e.h/Z(4),i=mr(6)(o*1.4);return xt(s=>s)($(s=>{if(r<mr(0)(Z(s)/Z(4)-.05))return N;const u=lc(ee(s))(t),a=mr(0)(Z(s)/Z(4)-.05),c=br(s)(2)===0,f=c?e.x-2:e.x+e.w+2,d=c?e.x+e.w+2:e.x-2,l=e.y+(Z(s)+.5)*o;return v("Just",{path:dd(mr(0)(eo(1)((r-a)/mr(1e-4)(eo(1)(Z(s+1|0)/Z(4)+.05)-a))))((()=>{const _={rMax:2,offset:.6,passes:1},h=ge(w(m=>x=>{const J=Te(-o*.08)(o*.08)(m.prng);return{prng:J.prng,out:[{x:f+(d-f)*(Z(x)/Z(4)),y:l+J.value},...m.out]}})({prng:u,out:[]})(Ut(0,4)).out),p=h.length<2?[]:qo(_)(u)(!1)(h);return 0<p.length?p[0].path:[]})()),width:i,alpha:1})})(Ut(0,3)))},bc=(t,e,n)=>({tag:t,_1:e,_2:n}),md=t=>t,kc=(t,e,n)=>({tag:t,_1:e,_2:n}),eu=t=>e=>n=>{const r=rt.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=rt.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},ye=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},$e=(()=>{const t=nn.unfoldr(In);return e=>t(rn("IterNode",e,Pn))})(),Un=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},DT=zt.foldMap(hp),nu=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},BT=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ru=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},yd=ae(I)(zt),xd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},RT=bg(I),QT=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Lc=md("LabelsShown"),FT=md("LabelsHidden"),Jd=t=>{const e=t.Monad0().Bind1(),n=t.popTransform,r=t.popAlpha;return o=>i=>s=>u=>a=>e.bind(t.pushAlpha(o.fadeAlpha))(()=>e.bind(t.pushTransform({tx:i*(1-o.popScale),ty:s*(1-o.popScale),sx:o.popScale,sy:o.popScale}))(()=>e.bind(t.pushTransform({tx:0,ty:u.y*(1-o.flipY),sx:1,sy:o.flipY}))(()=>e.bind(a)(()=>e.bind(n)(()=>e.bind(n)(()=>r))))))},_n=t=>{const e=t.Apply0();return n=>w(r=>o=>e.apply(e.Functor0().map(i=>ag)(r))(n(o)))(t.pure())},Nd=t=>e=>n=>r=>o=>i=>{const s={x:n.x+n.w/2,y:n.y+n.h/2},u={x:e.x+e.w/2,y:e.y+e.h/2},a=Ho(o)(i)(r),c=0<t.length?v("Just",t[0]):N,f=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return u;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?v("Just",t[d]):N,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return s;g()})(),h=Z1(128)(to(4)(Oo(2)(e)))(od(f)(6)),p=f.x-u.x,m=2*(()=>{const K=f.y-u.y;return(p<0?-p:p)+(K<0?-K:K)})(),x=_.x-s.x,J=2*(()=>{const K=_.y-s.y;return(x<0?-x:x)+(K<0?-K:K)})(),y=m+ji(t)+J,T=y<=1e-4?1:1-J/y,b=y<=1e-4?0:m/y,C=T-b,S=Z1(128)(od(_)(6))(to(4)(Oo(2)(n))),E={maxDelay:.4,smoothPasses:2},F=ei(t)(eu(0)(1)(C<=1e-4?0:(a-b)/C)),O=(()=>{if(F.tag==="Just")return F._1;if(F.tag==="Nothing")return f;g()})(),G=(()=>{if(T>=1)return 0;const K=(a-T)/(1-T),U=K<0?0:K>1?1:K;return U*U*(3-2*U)})(),A=(()=>{if(b<=1e-4)return 1;const K=a/b,U=K<0?0:K>1?1:K;return U*U*(3-2*U)})();return a<b?kc("PolyShape",ed(A)(h.from)(h.to)(E)):a>=T?kc("PolyShape",ed(G)(S.from)(S.to)(E)):kc("CircleShape",O,6)},Cc=t=>e=>n=>r=>o=>i=>{const s=Nd(t)(e)(n)(r)(o)(i);if(s.tag==="PolyShape")return id(s._1);if(s.tag==="CircleShape")return s._1;g()},Sc=(()=>{const t={r:24,g:24,b:27,a:255},e={r:244,g:244,b:245,a:255},n={r:248,g:249,b:246,a:255},r={r:26,g:26,b:26,a:255},o={r:28,g:101,b:192,a:255},i={r:247,g:248,b:250,a:255},s={r:42,g:48,b:60,a:255},u={r:120,g:130,b:146,a:255};return a=>{if(a==="Light")return{bg:{r:255,g:255,b:255,a:255},bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:211,b:209,a:255},shadowFill:{r:255,g:255,b:255,a:255},shadowDot:{r:26,g:26,b:26,a:255},chip:{r:255,g:235,b:130,a:255},chipShadow:{r:214,g:211,b:209,a:255},chipText:pr,nodeFill:he,nodeStroke:pr,text:pr,edge:pr,arrowFill:pr,tokenOutsideFill:pr,tokenOutsideStroke:he,tokenInside:he,tokenInsideStroke:he,tokenInsideBlend:Ws,tokenInsideAlpha:1,chipPillFill:pr,chipPillText:he,chipHairline:{r:26,g:26,b:26,a:90},trailDot:pr,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Dark")return{bg:t,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:63,g:63,b:70,a:255},shadowFill:t,shadowDot:e,chip:{r:234,g:179,b:8,a:255},chipShadow:{r:0,g:0,b:0,a:120},chipText:t,nodeFill:pr,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:he,tokenOutsideStroke:he,tokenInside:he,tokenInsideStroke:he,tokenInsideBlend:Ws,tokenInsideAlpha:1,chipPillFill:e,chipPillText:t,chipHairline:{r:244,g:244,b:245,a:120},trailDot:e,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Blueprint")return{bg:o,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:90,g:160,b:230,a:255},shadowFill:o,shadowDot:he,chip:he,chipShadow:{r:0,g:0,b:0,a:120},chipText:o,nodeFill:o,nodeStroke:he,text:he,edge:he,arrowFill:he,tokenOutsideFill:he,tokenOutsideStroke:he,tokenInside:he,tokenInsideStroke:he,tokenInsideBlend:D1,tokenInsideAlpha:.35,chipPillFill:he,chipPillText:o,chipHairline:{r:255,g:255,b:255,a:120},trailDot:he,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Whiteboard")return{bg:n,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:0,g:0,b:0,a:0},shadowFill:n,shadowDot:r,chip:{r:217,g:74,b:56,a:255},chipShadow:{r:26,g:26,b:26,a:60},chipText:n,nodeFill:n,nodeStroke:r,text:r,edge:r,arrowFill:r,tokenOutsideFill:r,tokenOutsideStroke:n,tokenInside:n,tokenInsideStroke:n,tokenInsideBlend:D1,tokenInsideAlpha:1,chipPillFill:r,chipPillText:n,chipHairline:{r:26,g:26,b:26,a:90},trailDot:r,wobble:!0,fontFamily:"Supermarker, Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(a==="Isometric")return{bg:i,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:218,b:224,a:255},shadowFill:i,shadowDot:s,chip:{r:255,g:235,b:130,a:255},chipShadow:{r:100,g:110,b:125,a:90},chipText:s,nodeFill:{r:236,g:239,b:244,a:255},nodeStroke:s,text:s,edge:u,arrowFill:u,tokenOutsideFill:s,tokenOutsideStroke:he,tokenInside:he,tokenInsideStroke:he,tokenInsideBlend:Ws,tokenInsideAlpha:1,chipPillFill:s,chipPillText:he,chipHairline:{r:60,g:66,b:78,a:90},trailDot:s,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};g()}})(),Ec=t=>e=>Lt($e(t.nodes))(n=>{const r=ye(n._1)(e.nodes);return r.tag==="Just"&&Us(r._1).alpha>0?tT(n._2):[]}),zT=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,...Ec(e)(n)],MT=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=zr.traverse(r);return i=>s=>{const u=ur(s),a=.32*i.size;return o(c=>n.bind(c===0?r.pure(0):t.measureText(i)(Ee(c)(s)))(f=>n.bind(t.measureText(i)(Ee(c+1|0)(s)))(d=>n.bind(t.measureInk(i)(c>=0&&c<u.length?Zo(u[c]):" "))(l=>r.pure({x:f,w:d-f,up:l.ascent-a,down:l.descent+a})))))(Ut(0,u.length-1|0))}},HT=t=>e=>{const n=o=>(o.x-e.x)*(o.x-e.x)+(o.y-e.y)*(o.y-e.y),r=w(o=>i=>n(i)<n(o)?i:o)({x:t.x,y:t.y})([{x:t.x,y:t.y},{x:t.x+t.w,y:t.y},{x:t.x,y:t.y+t.h},{x:t.x+t.w,y:t.y+t.h}]);return $(o=>{const i=Z(o)/5;return{x:r.x+(e.x-r.x)*i,y:r.y+(e.y-r.y)*i}})([1,2,3,4])},Gc=t=>{const e=si(`
|
|
7
|
+
`)(t);return e.length===0?[""]:e},OT=t=>e=>n=>r=>o=>i=>{const s={x:n.x+n.w/2,y:n.y+n.h/2},u={x:e.x+e.w/2,y:e.y+e.h/2},a=Ho(o)(i)(r),c=0<t.length?v("Just",t[0]):N,f=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return u;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?v("Just",t[d]):N,_=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return s;g()})(),h=f.x-u.x,p=2*(()=>{const E=f.y-u.y;return(h<0?-h:h)+(E<0?-E:E)})(),m=_.x-s.x,x=2*(()=>{const E=_.y-s.y;return(m<0?-m:m)+(E<0?-E:E)})(),J=p+ji(t)+x,y=J<=1e-4?1:1-x/J,T=J<=1e-4?0:p/J,b=y-T,C=ei(t)(eu(0)(1)(b<=1e-4?0:(a-T)/b)),S=(()=>{if(C.tag==="Just")return C._1;if(C.tag==="Nothing")return f;g()})();return a<T?bc("InsideRect",Oo(2)(e)):a>=y?bc("InsideRect",Oo(2)(n)):bc("InsideBall",S,6)},qT={offset:.8,passes:2,rMax:5},$T=t=>{const e=t.Monad0().Applicative0(),n=_n(e);return r=>o=>i=>s=>{const u={color:s,width:1,lineJoin:Ge,lineCap:je},a={color:i,flat:!0},c=f=>t.drawRoundedRect({x:f.x,y:f.y,w:f.w,h:f.h})(4)(v("Just",a))(v("Just",u));return n(f=>{if(f._2.tag==="Travelling"){const d=Un(f._2._1.edge)(r.edges),l=ye(f._2._1.target)(r.nodes),_=ye(f._2._1.source)(r.nodes);if(_.tag==="Just"&&l.tag==="Just"&&d.tag==="Just"){const h=OT((()=>{if(f._2._1.direction==="Forward")return d._1;if(f._2._1.direction==="Backward")return ge(d._1);g()})())(_._1)(l._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);if(h.tag==="InsideRect")return c(h._1);if(h.tag==="InsideBall")return t.fillStrokePath(Xs(h._1)(h._2))(a)(u);g()}return e.pure()}if(f._2.tag==="Filling"){const d=ye(f._2._1.node)(r.nodes);if(d.tag==="Just")return c(Oo(2)(d._1));if(d.tag==="Nothing")return e.pure();g()}return e.pure()})($e(o.tokens))}},wd=t=>e=>n=>r=>t.strokePath((()=>{const o=Mt(i=>N,i=>s=>v("Just",{head:i,tail:s}),$(i=>i.pt)(Vh(i=>s=>{const u=Z(s)/Z(72),a=Te(-.18)(.18)(i.prng),c=Te(-.1)(.1)(a.prng),f=Te(-.07)(.07)(c.prng),d=n*(.05+.55*u)*(1+c.value),l=u*28.274333882308138+a.value;return{prng:f.prng,pt:{x:e.x+mn(l)*d+f.value*n,y:e.y+an(l)*d+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,...DT(i=>[2,i.x,i.y])(o._1.tail)];if(o.tag==="Nothing")return[];g()})())({color:r,width:5.5,lineJoin:Ge,lineCap:Bn}),WT=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=_n(e.Applicative0());return i=>s=>u=>o(a=>n.bind(t.pushAlpha(a.alpha))(()=>n.bind(t.strokePath(a.path)({color:i.nodeFill,width:a.width,lineJoin:Ge,lineCap:Bn}))(()=>r)))(AT(_d(s)+7777|0)(s)(u))},vd=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=e.Applicative0(),i=_n(o),s=t.popClip,u=_n(o),a=zr.traverse(o),c=MT(t),f=WT(t),d=t.popTransform;return l=>_=>h=>p=>m=>x=>J=>y=>T=>{const b=R=>n.bind(t.pushAlpha(R.alpha))(()=>n.bind(t.strokePath(R.path)({color:h.nodeStroke,width:2,lineJoin:Ge,lineCap:Bn}))(()=>r)),C={family:h.fontFamily,size:h.wobble?15:11,weight:h.wobble?800:500},S=si(`
|
|
8
|
+
`)(y.label===""?J:y.label),E=S.length===0?[""]:S,F=C.size*1.2,O=y.shape==="Cylinder"?t.strokePath(Nv({x:y.x,y:y.y,w:y.w,h:y.h}))({color:h.nodeStroke,width:1.25,lineJoin:Ge,lineCap:je}):o.pure(),G=(y.shape==="Cylinder"?(y.y+(y.y+y.h+5-2*Jn(y.h*.075)(y.w*.075)))/2:(y.y+y.y+y.h)/2)-Z(E.length)*F/2+F/2,A=T.tag==="PloppingOut"&&h.wobble?T._1:-1,K=A>=0,U=Us(T),z=K?{alpha:1,scale:1}:U,H=y.x+y.w/2,M=y.y+y.h/2,P=n.bind(t.pushAlpha(z.alpha*p))(()=>n.bind(t.pushTransform({tx:H*(1-z.scale),ty:M*(1-z.scale),sx:z.scale,sy:z.scale}))(()=>{const R={x:y.x,y:y.y,w:y.w,h:y.h},Q={color:h.nodeStroke,width:h.wobble?2:1.25*_,lineJoin:Ge,lineCap:h.wobble?Bn:je};return n.bind((()=>{if(h.wobble){if(y.shape==="Rectangle")return i(b)(IT(ld)(_d(R))(R));const B=to(7)(y);return n.bind(i(b)((()=>{const q=Ci(B);return B.length<4?[]:qo(fd)(q)(!0)(B)})()))(()=>u(q=>i(b)((()=>{const et=Ci(q);return q.length<2?[]:qo(fd)(et)(!1)(q)})()))(y.shape==="Cylinder"?[cT(y)]:[]))}return n.bind(mc(t)(y.shape)(R)(7)(v("Just",{color:h.nodeFill,flat:!1}))(v("Just",Q)))(()=>O)})())(()=>n.bind((()=>{if(x.tag==="Just"&&h.wobble&&!K){const B=x._1;return n.bind(a(c(C))(E))(q=>{const et=Dt(st=>ut=>rt.compare(st.x)(ut.x)),V=fe(bn(y.x*7919+y.y*3001))*-1640531535|0,Y=Te(5)(7.5)(V),W=Te(0)(Y.value)(Y.prng),X=-(1+2*Te(-1)(1)(W.prng).value*3.141592653589793/180),tt=(st,ut,Jt,vt,At)=>et(xt(Zt=>Zt)([X*ut+st>=vt&&X*ut+st<=At?v("Just",{x:ut,y:X*ut+st}):N,X*Jt+st>=vt&&X*Jt+st<=At?v("Just",{x:Jt,y:X*Jt+st}):N,(()=>{const Zt=(vt-st)/X;return Zt>=ut&&Zt<=Jt?v("Just",{x:Zt,y:vt}):N})(),(()=>{const Zt=(At-st)/X;return Zt>=ut&&Zt<=Jt?v("Just",{x:Zt,y:At}):N})()])),gt=Y.value,wt=br(B.frameHash)(3),ct=wt===0?{r:200,g:35,b:30,a:220}:wt===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},yt=y.x+y.w/2,Ct=un(Yt(st=>ut=>Yt((()=>{const Jt=G+Z(st)*F,vt=yt-w(At=>Zt=>At+Zt.w)(0)(ut)/2;return At=>Zt=>{const ln=C.size*.1,Ae=At-1|0,Qt=Ae>=0&&Ae<ut.length&&At>0?(ut[Ae].x+ut[Ae].w+Zt.x)/2:Zt.x-ln;return{x:vt+Qt-1,y:Jt-Zt.up-1,w:nu(0)((()=>{const Bt=At+1|0;return Bt>=0&&Bt<ut.length&&At<(ut.length-1|0)?(Zt.x+Zt.w+ut[Bt].x)/2-Qt:Zt.x+Zt.w+ln-Qt})())+2,h:Zt.up+Zt.down+2}}})())(ut))(q)),Vt=y.y+4,mt=y.x+y.w-4,Wt=y.x+4,kt=Vt-X*Wt+W.value,lt=y.y+y.h-4,ft=Lt(Lt(Yt(st=>ut=>{const Jt=(ut.from.x+ut.to.x)/2,vt=(ut.from.y+ut.to.y)/2,At=Te(-1)(1)(V+(911*(st+1|0)|0)|0),Zt=Te(-3)(5)(At.prng),ln=At.value*3.141592653589793/180,Ae=mn(ln),Qt=an(ln),Bt=De=>({x:Jt+(De.x-Jt)*Ae-(De.y-vt)*Qt,y:vt+(De.x-Jt)*Qt+(De.y-vt)*Ae});return{from:(()=>{const De=Bt(ut.from),hn=De.y-vt,We=De.x-Jt,en=Fe(We*We+hn*hn),Pe=en<1e-4?1:(en+Zt.value)/en;return{x:Jt+We*Pe,y:vt+hn*Pe}})(),to:(()=>{const De=Bt(ut.to),hn=Te(-3)(5)(Zt.prng).value,We=De.y-vt,en=De.x-Jt,Pe=Fe(en*en+We*We),te=Pe<1e-4?1:(Pe+hn)/Pe;return{x:Jt+en*te,y:vt+We*te}})()}})(xt(st=>{const ut=tt(kt+Z(st)*gt,Wt,mt,Vt,lt);return ut.length===2?v("Just",{from:ut[0],to:ut[1]}):N})(Ut(0,ru(1)(fe(bn((lt-X*mt-kt)/gt)))))))(st=>at(ut=>ut.to.x-ut.from.x>1,w(ut=>Jt=>Lt(ut)(vt=>{const At=tt(vt.from.y-X*vt.from.x,Jt.x,Jt.x+Jt.w,Jt.y,Jt.y+Jt.h);return At.length===2?At[0].x>vt.from.x+.001&&At[1].x<vt.to.x-.001?[{from:vt.from,to:At[0]},{from:At[1],to:vt.to}]:At[0].x<=vt.from.x+.001&&At[1].x<vt.to.x-.001?[{from:At[1],to:vt.to}]:At[0].x>vt.from.x+.001&&At[1].x>=vt.to.x-.001?[{from:vt.from,to:At[0]}]:[]:[vt]}))([st])(Ct))))(st=>(()=>{const ut=st.to.x-st.from.x;return Fe(2)*(ut>=0?ut:-ut)<=28})()?[st]:[{from:st.from,to:{x:st.from.x+(st.to.x-st.from.x)*.495,y:st.from.y+(st.to.y-st.from.y)*.495}},{from:{x:st.from.x+(st.to.x-st.from.x)*.505,y:st.from.y+(st.to.y-st.from.y)*.505},to:st.to}]),ot=ft.length,_t=st=>nu(0)(BT(1)(B.t*Z(ot)-Z(st)));return n.bind(t.pushClip(Nc(to(7)(y)))($s))(()=>n.bind(i(st=>{const ut=st._1,Jt=Te(1.4)(1.9)(V+(1303*(ut+1|0)|0)|0),vt=Te(.35)(.8)(Jt.prng),At=i(Zt=>n.bind(t.pushAlpha(Zt.alpha*vt.value))(()=>n.bind(t.strokePath(dd(_t(ut))(Zt.path))({color:ct,width:Jt.value,lineJoin:Ge,lineCap:Bn}))(()=>r)))(qo({...ld,rMax:0,offset:.5})(V+(53*(ut+1|0)|0)|0)(!1)([st._2.from,st._2.to]));return _t(ut)>0?At:o.pure()})(Yt(En)(ft)))(()=>s))})}return o.pure()})())(()=>n.bind((()=>{if(l==="LabelsShown"){const B=n.bind(t.pushAlpha(m))(()=>n.bind(i(q=>t.drawText({x:y.x+y.w/2,y:G+Z(q._1)*F,content:q._2,font:C,color:h.text,align:Ar,baseline:Dn}))(Yt(En)(E)))(()=>r));return m>0?B:o.pure()}if(l==="LabelsHidden")return o.pure();g()})())(()=>n.bind((()=>{const B=f(h)(R)(A);return K?B:o.pure()})())(()=>n.bind(d)(()=>r)))))}));return z.alpha*p>0?P:o.pure()}},Td=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=vd(t),i=t.popAlpha,s=_n(n);return u=>a=>c=>{const f={...u,nodeFill:u.text,text:u.nodeFill,nodeStroke:u.nodeFill};return s(d=>{const l=ye(d._1)(c.nodes),_=ye(d._1)(a.nodes),h=(()=>{if(_.tag==="Just"&&l.tag==="Just"){const p=l._1,m=_._1;return r.bind(t.pushAlpha(d._2))(()=>r.bind(o(Lc)(1)(f)(1)(1)(N)(d._1)(m)(p))(()=>i))}return n.pure()})();return d._2>0?h:n.pure()})($e(c.nodeInvert))}},YT=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=_n(n);return i=>s=>u=>{const a={family:i.fontFamily,size:11,weight:500};return o(c=>{if(c._2===""||(()=>{const l=Un(c._1)(u.edges);return l.tag==="Nothing"||!(l.tag==="Just"&&l._1.tag==="Extended")})())return n.pure();const f=Un(c._1)(s.edges),d=(()=>{if(f.tag==="Just")return ei(f._1)(.5);if(f.tag==="Nothing")return N;g()})();if(d.tag==="Nothing")return n.pure();if(d.tag==="Just"){const l=d._1;return r.bind(t.measureText(a)(c._2))(_=>{const h=_+12;return r.bind(t.drawRoundedRect({x:l.x-h/2,y:l.y-8.5,w:h,h:17})(3)(v("Just",{color:i.chipPillFill,flat:!0}))(N))(()=>t.drawText({x:l.x,y:l.y,content:c._2,font:a,color:i.chipPillText,align:Ar,baseline:Dn}))})}g()})($e(s.edgeLabels))}},VT=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popAlpha;return i=>s=>u=>a=>c=>f=>d=>l=>_=>{const h=(()=>{if(_>1e-4&&d>1-_){const m=(1-d)/_;return m<0?0:m>1?1:m}if(l>1e-4&&d<l){const m=d/l;return m<0?0:m>1?1:m}return 1})(),p=Nd(a)(c)(f)(d)(l)(_);if(p.tag==="CircleShape")return i?wd(t)(p._1)(p._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(Xs(p._1)(p._2))({color:s,flat:!0})({color:u,width:1,lineJoin:Ge,lineCap:je});if(p.tag==="PolyShape"&&i&&p._1.length>=3)return r.bind(t.pushAlpha(h))(()=>r.bind(wd(t)(id(p._1))(6)({r:200,g:35,b:30,a:220}))(()=>o));if(p.tag==="PolyShape")return i?n.pure():p._1.length>=3?t.fillStrokePath(Nc(p._1))({color:s,flat:!0})({color:u,width:1,lineJoin:Ge,lineCap:je}):n.pure();g()}},UT=t=>{const e=t.Monad0().Bind1(),n=t.popAlpha;return r=>o=>i=>s=>u=>a=>c=>{const f=Ho(a)(c)(u),d={x:i.x+i.w/2,y:i.y+i.h/2},l={x:s.x+s.w/2,y:s.y+s.h/2},_=(h,p)=>e.bind(t.pushAlpha(p))(()=>e.bind(t.fillStrokePath(Xs(h)(6))({color:r,flat:!0})({color:o,width:1,lineJoin:Ge,lineCap:je}))(()=>n));return f<.5?_(d,(()=>{const h=f*2;return 1-(h<0?0:h>1?1:h)*(h<0?0:h>1?1:h)*(h<0?3:h>1?1:3-2*h)})()):_(l,(()=>{const h=(f-.5)*2;return(h<0?0:h>1?1:h)*(h<0?0:h>1?1:h)*(h<0?3:h>1?1:3-2*h)})())}},ou=t=>{const e=VT(t),n=UT(t),r=t.Monad0().Applicative0(),o=_n(r);return i=>s=>u=>a=>c=>o(f=>{if(f._2.tag==="Travelling"){const d=ye(f._2._1.target)(s.nodes),l=ye(f._2._1.source)(s.nodes);if(l.tag==="Just"&&d.tag==="Just"){const _=Un(f._2._1.edge)(s.edges);if(_.tag==="Just")return e(i)(a)(c)((()=>{if(f._2._1.direction==="Forward")return _._1;if(f._2._1.direction==="Backward")return ge(_._1);g()})())(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);if(_.tag==="Nothing")return n(a)(c)(l._1)(d._1)(f._2._1.progress)(f._2._1.holdPre)(f._2._1.holdPost);g()}return r.pure()}if(f._2.tag==="Filling"){if(i)return r.pure();const d=ye(f._2._1.node)(s.nodes);if(d.tag==="Just")return t.fillStrokePath(Nc(to(4)(Oo(2)(d._1))))({color:a,flat:!0})({color:c,width:1,lineJoin:Ge,lineCap:je});if(d.tag==="Nothing")return r.pure();g()}return r.pure()})($e(u.tokens))},bd=t=>{const e=ou(t),n=t.Monad0(),r=n.Bind1(),o=ou(t),i=$T(t),s=t.popClip,u=t.popBlend,a=t.popLayer,c=n.Applicative0(),f=_n(c),d=t.popAlpha;return l=>_=>h=>p=>{const m=_.wobble?e(!0)(h)(p)(_.tokenInside)(_.tokenInsideStroke):r.bind(t.insideTokenStyle(l))(x=>{if(x==="GenieSilhouette")return o(!1)(h)(p)(_.tokenInside)(_.tokenInsideStroke);if(x==="ConvexAbsorb")return i(h)(p)(_.tokenInside)(_.tokenInsideStroke);g()});if(_.tokenInsideBlend==="Difference")return r.bind(t.pushLayer(uv))(()=>r.bind(t.pushBlend(Ws))(()=>r.bind(t.pushClip(Ec(h)(p))($s))(()=>r.bind(m)(()=>r.bind(s)(()=>r.bind(u)(()=>r.bind(a)(()=>r.bind(t.pushLayer(av))(()=>r.bind(f(x=>{const J=ye(x._1)(p.nodes);return J.tag==="Just"&&Us(J._1).alpha>0?mc(t)(x._2.shape)({x:x._2.x,y:x._2.y,w:x._2.w,h:x._2.h})(7)(v("Just",{color:he,flat:!1}))(N):c.pure()})($e(h.nodes)))(()=>a)))))))));if(_.tokenInsideBlend==="Normal")return r.bind(t.pushClip(Ec(h)(p))($s))(()=>r.bind(t.pushAlpha(_.tokenInsideAlpha))(()=>r.bind(m)(()=>r.bind(d)(()=>s))));g()}},kd=t=>{const e=t.Monad0().Bind1(),n=ou(t),r=ou(t),o=t.popClip,i=t.popLayer;return s=>u=>a=>c=>e.bind(t.pushLayer(sv))(()=>e.bind(t.pushClip(zT(u)(a)(c))(gv))(()=>e.bind(s.wobble?n(!0)(a)(c)(s.tokenOutsideFill)(s.tokenOutsideStroke):r(!1)(a)(c)(s.tokenOutsideFill)(s.tokenOutsideStroke))(()=>e.bind(o)(()=>i))))},XT=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=_n(r);return i=>s=>u=>a=>c=>f=>{const d=cs(f).length,l=Z(d+1|0),_=m=>{const x=(u*l-Z(m))/1.5,J=x<0?0:x>1?1:x;return J*J*(3-2*J)},h=(m=>{let x=m,J=!0,y;for(;J;){const T=x;if(T>=d){J=!1,y=T;continue}if(_(T)>=1){x=T+1|0;continue}J=!1,y=T}return y})(0),p=h>=d?[]:Fn(m=>_(m)>0)(Ut(h,d-1|0)).init;return n.bind((()=>{const m=t.drawText({x:a,y:c,content:Ee(h)(f),font:i,color:s,align:Ti,baseline:Dn});return h>0?m:r.pure()})())(()=>o(m=>n.bind(t.measureText(i)(Ee(m)(f)))(x=>{const J=_(m);return t.drawText({x:a+x,y:c-(1-J)*10,content:Ee(1)(To(Mn(Ee(m)(f)))(f)),font:i,color:{...s,a:fe(bn(J*Z(s.a)))},align:Ti,baseline:Dn})}))(p))}},iu=t=>e=>n=>r=>{const o=$(_=>Z(ru(1)(cs(_).length)))(r),i=nu(1)(w(Jo)(0)(o)),s=Ho(e)(n)(t),u=s*i,a=ru(1)(r.length),c=(_=>h=>p=>{let m=_,x=h,J=p,y=!0,T;for(;y;){const b=m,C=x,S=Mt(E=>N,E=>F=>v("Just",{head:E,tail:F}),J);if(S.tag==="Nothing"){y=!1,T=ru(0)(a-1|0);continue}if(S.tag==="Just"){if(C+S._1.head>=u){y=!1,T=b;continue}m=b+1|0,x=C+S._1.head,J=S._1.tail;continue}g()}return T})(0)(0)(o),f=w(Jo)(0)(c<1?[]:Gt(0,c,o)),d=f/i;if(c>=0&&c<o.length){const _=(f+o[c])/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(_<=d)return 1;const h=(s-d)/(_-d);return h<0?0:h>1?1:h})()}}const l=(f+1)/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(l<=d)return 1;const _=(s-d)/(l-d);return _<0?0:_>1?1:_})()}},Ld=t=>{const e=t.Monad0();return n=>r=>o=>e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(iu(r)(0)(0)($(Mu)(o)).line))(i=>{const s=i+28;return e.Applicative0().pure({x:n.x+n.w/2-s/2,y:n.y-25.2-14,w:s,h:25.2})})},KT=t=>{const e=t.Monad0(),n=e.Bind1(),r=Ld(t),o=e.Applicative0(),i=zr.traverse(o);return s=>u=>n.Apply0().Functor0().map(a=>yd(xt(c=>c)(a)))(i(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const c=ye(a._2._1.node)(s.nodes);if(c.tag==="Just")return n.bind(r(c._1)(a._2._1.progress)(a._2._1.labels))(f=>o.pure(v("Just",k(a._1,f))));if(c.tag==="Nothing")return o.pure(N);g()}return o.pure(N)})($e(u.tokens)))},jT=t=>{const e=t.Monad0();return n=>r=>o=>i=>s=>u=>a=>{const c=Cc(n)(r)(o)(i)(s)(u);return e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(iu(i)(s)(u)(Lt(a)(Gc)).line))(f=>e.Applicative0().pure({x:c.x+14+f/2-f/2-14,y:c.y-6-8-6.6-6,w:f+28,h:25.2}))}},ZT=t=>{const e=t.Monad0(),n=e.Bind1(),r=jT(t),o=e.Applicative0(),i=zr.traverse(o);return s=>u=>n.Apply0().Functor0().map(a=>yd(xt(c=>c)(a)))(i(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const c=ye(a._2._1.target)(s.nodes),f=ye(a._2._1.source)(s.nodes),d=Un(a._2._1.edge)(s.edges);if(d.tag==="Just"&&f.tag==="Just"&&c.tag==="Just"){const l=(()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return ge(d._1);g()})(),_=Cc(l)(f._1)(c._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);return n.bind(r(l)(f._1)(c._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(h=>o.pure(v("Just",k(a._1,{id:a._1,rect:h,token:_}))))}}return o.pure(N)})($e(u.tokens)))},Pc=t=>{const e=t.Monad0(),n=e.Bind1(),r=ZT(t),o=KT(t);return i=>s=>u=>n.bind(r(s)(u))(a=>n.bind(o(s)(u))(c=>e.Applicative0().pure(NT({x:i.vx,y:i.vy,w:i.vw,h:i.vh})([...xt(f=>{const d=ye(f._1)(u.nodes);return d.tag==="Just"&&Us(d._1).alpha>0?v("Just",{x:f._2.x,y:f._2.y,w:f._2.w,h:f._2.h}):N})($e(s.nodes)),...(()=>{const f=(d,l)=>{if(d.tag==="Leaf")return l;if(d.tag==="Node")return f(d._5,Xt("Cons",d._4,f(d._6,l)));g()};return qt(ue.foldr,f(c,Ht))})()])(xt(f=>xd(f)(a))((()=>{const f=d=>{if(d.tag==="Leaf")return D;if(d.tag==="Node")return Kt("Node",d._1,d._2,d._3,void 0,f(d._5),f(d._6));g()};return Dt(I.compare)(qt(on.foldr,f(a)))})())))))},Cd=t=>e=>n=>{const r=oi(6)(.55)(eu(0)(1)((1-t)/.06)),o=t>.94,i=o&&n>1e-4,s=oi(6)(.55)(eu(0)(1)(t/.06)),u=t<.06,a=u&&e>1e-4,c=o&&n<=1e-4;return{popScale:a?s:i?r:1,flipY:u&&e<=1e-4?s:c?r:1,fadeAlpha:(()=>{if(a){const f=t/.06;return f<0?.55:f>1?1:.55+.44999999999999996*f}if(i){const f=(1-t)/.06;return f<0?.55:f>1?1:.55+.44999999999999996*f}return 1})()}},t3=t=>{const e=Jd(t),n=t.Monad0().Bind1();return r=>o=>i=>s=>u=>{const a=iu(i)(0)(0)(Lt(s)(Gc)),c={x:u.x+u.w/2,y:u.y+u.h/2},f=[1,c.x,u.y+u.h,2,o.x+o.w/2,o.y];return e(Cd(i)(0)(0))(u.x)(u.y+u.h)(c)(n.bind(t.drawRoundedRect({x:u.x,y:u.y+1.5,w:u.w,h:u.h})(6)(v("Just",{color:r.chipShadow,flat:!0}))(N))(()=>n.bind(t.drawRoundedRect({x:u.x,y:u.y,w:u.w,h:u.h})(6)(v("Just",{color:r.chip,flat:!0}))(v("Just",{color:r.chipHairline,width:1,lineJoin:Ge,lineCap:je})))(()=>n.bind(t.strokePath(f)({color:r.chipHairline,width:1,lineJoin:Ge,lineCap:je}))(()=>t.drawText({x:c.x,y:c.y,content:a.line,font:{family:r.fontFamily,size:11,weight:500},color:r.chipText,align:Ar,baseline:Dn})))))}},e3=t=>{const e=Ld(t),n=t3(t);return r=>o=>i=>s=>u=>t.Monad0().Bind1().bind(e(i)(s)(u))(a=>n(r)(i)(s)(u)(a))},n3=t=>{const e=Jd(t),n=t.Monad0(),r=n.Bind1(),o=_n(n.Applicative0()),i=XT(t);return s=>u=>a=>c=>f=>d=>l=>_=>h=>{const p=iu(f)(d)(l)(Lt(_)(Gc)),m=p.line,x=p.phaseInLabel/.45,J=x<0?0:x>1?1:x,y=h.w,T=h.y,b=h.x,C=b+14,S=h.h,E=T+S/2;return e(Cd(f)(d)(l))(b)(T+S)({x:b+y/2,y:E})(r.bind(o(F=>t.fillPath(Xs(F)(1.5))({color:s.trailDot,flat:!0}))(HT(h)(Cc(u)(a)(c)(f)(d)(l))))(()=>r.bind(t.drawRoundedRect({x:b,y:T,w:y,h:S})(3)(v("Just",{color:s.chipPillFill,flat:!0}))(N))(()=>i({family:s.fontFamily,size:11,weight:500})(s.chipPillText)(J)(C)(E)(m))))}},Ic=t=>{const e=n3(t),n=t.Monad0(),r=n.Applicative0(),o=e3(t),i=n.Bind1(),s=_n(r),u=t.popLayer;return a=>c=>f=>d=>i.bind(t.pushLayer(cv))(()=>i.bind(s(l=>{if(l._2.tag==="Travelling"){if(l._2._1.labels.length!==0){const _=ye(l._2._1.target)(c.nodes),h=ye(l._2._1.source)(c.nodes),p=Un(l._2._1.edge)(c.edges),m=xd(l._1)(d);if(m.tag==="Just"&&p.tag==="Just"&&h.tag==="Just"&&_.tag==="Just")return e(a)((()=>{if(l._2._1.direction==="Forward")return p._1;if(l._2._1.direction==="Backward")return ge(p._1);g()})())(h._1)(_._1)(l._2._1.progress)(l._2._1.holdPre)(l._2._1.holdPost)(l._2._1.labels)(m._1)}return r.pure()}if(l._2.tag==="Filling"&&l._2._1.labels.length!==0){const _=ye(l._2._1.node)(c.nodes);if(_.tag==="Just")return o(a)(c)(_._1)(l._2._1.progress)(l._2._1.labels);if(_.tag==="Nothing")return r.pure();g()}return r.pure()})($e(f.tokens)))(()=>u))},Sd=t=>{const e=Pc(t),n=Ic(t);return r=>o=>i=>s=>t.Monad0().Bind1().bind(e(o)(i)(s))(u=>n(r)(i)(s)(u))},r3=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>o=>{const i=o.length-1|0,s=i<1?[]:Gt(0,i,o),u=s.length-1|0,a=u>=0&&u<s.length?v("Just",s[u]):N,c=o.length-1|0,f=c>=0&&c<o.length?v("Just",o[c]):N;if(f.tag==="Just"&&a.tag==="Just"){const d=Te(.78)(1.18)(Ci(o)+19|0),l=Te(.4)(.62)(d.prng),_=r.wobble?8.75*l.value:4.375,h=Te(.4)(.62)(l.prng),p=r.wobble?8.75*h.value:4.375,m=f._1.y-a._1.y,x=f._1.x-a._1.x,J=Fe(x*x+m*m),y=m/J,T=-y,b=x/J,C=f._1.x+b*.875,S=f._1.y+y*.875,E=r.wobble?8.75*d.value:8.75,F=C-b*E,O=S-y*E,G=F+T*_,A=O+b*_,K=[1,C,S,2,F+T*4.375,O+b*4.375,2,F-T*4.375,O-b*4.375,5],U=F-T*p,z=O-b*p,H={color:r.arrowFill,width:2,lineJoin:Ge,lineCap:Bn};return J<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,G,A,2,C,S])(H))(()=>t.strokePath([1,U,z,2,C,S])(H)):t.fillPath(K)({color:r.arrowFill,flat:!0})}return n.pure()}},o3=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=_n(n),i=t.popAlpha,s=r3(t);return u=>a=>c=>f=>{const d=rT(8)(c);if(f.hi<=f.lo)return n.pure();const l=fT(d)(f.lo)(f.hi);if(l.length===0)return n.pure();const _={color:u.edge,width:u.wobble?2:.9375,lineJoin:Ge,lineCap:Bn},h=u.wobble?Te(-10)(4)(Ci(l)).value:0,p=u.wobble?CT(h)(l):l;return r.bind(u.wobble?o(m=>r.bind(t.pushAlpha(m.alpha))(()=>r.bind(t.strokePath(m.path)(_))(()=>i)))((()=>{const m=Ci(l);return p.length<2?[]:qo(qT)(m)(!1)(p)})()):t.strokePath(Zv(l))(_))(()=>{const m=s(u)(p);return a&&f.hi>=.999?m:n.pure()})}},Ed=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=o3(t),i=t.popAlpha,s=_n(n);return u=>a=>c=>{const f=d=>{const l=oe(_=>d.x>=_._2.x-1&&d.x<=_._2.x+_._2.w+1&&d.y>=_._2.y-1&&d.y<=_._2.y+_._2.h+1)($e(a.nodes));return l.tag==="Just"?v("Just",l._1._2):N};return s(d=>{const l=Un(d._1)(c.edges);if(l.tag==="Just"){const _=l._1,h=Un(d._1)(c.edgeFadeAlpha),p=(()=>{if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1;g()})(),m=r.bind(t.pushAlpha(p))(()=>r.bind(o(u)((()=>{const x=bo("conn:")(d._1);if(x.tag==="Just")return!1;if(x.tag==="Nothing")return!0;g()})())((()=>{const x=(()=>{if(0<d._2.length){const y=f(d._2[0]);if(y.tag==="Just")return ge(ud(to(7)(y._1))(ge(d._2)))}return d._2})(),J=x.length-1|0;if(J>=0&&J<x.length){const y=f(x[J]);if(y.tag==="Just")return ud(to(7)(y._1))(x)}return x})())((()=>{if(_.tag==="Retracted")return{lo:0,hi:0};if(_.tag==="Extended")return{lo:0,hi:1};if(_.tag==="Extending")return{lo:0,hi:_._2};if(_.tag==="Retracting"){if(_._1==="FromSource")return{lo:_._2,hi:1};if(_._1==="FromTarget")return{lo:0,hi:1-_._2};if(_._1==="FromBoth")return{lo:_._2/2,hi:1-_._2/2}}g()})()))(()=>i));return p>0?m:n.pure()}if(l.tag==="Nothing")return n.pure();g()})($e(a.edges))}},i3=t=>e=>{const n=i=>{const s=ye(i)(t.nodes);if(s.tag==="Nothing")return!1;if(s.tag==="Just"){const u=s._1;return!Ye(a=>0<a._2.length&&a._2[0].x>=u.x&&a._2[0].x<=u.x+u.w&&a._2[0].y>=u.y&&a._2[0].y<=u.y+u.h,$e(t.edges))}g()},r=w(i=>s=>(i*31|0)+Er(s)|0)(5381)(ur(e.frameTitle)),o=i=>{const s=ye(i)(t.nodes);if(s.tag==="Nothing")return!1;if(s.tag==="Just"){const u=s._1;return!Ye(a=>{const c=a._2.length-1|0;return c>=0&&c<a._2.length&&a._2[c].x>=u.x&&a._2[c].x<=u.x+u.w&&a._2[c].y>=u.y&&a._2[c].y<=u.y+u.h},$e(t.edges))}g()};return w(i=>s=>{const u=s._2;return RT(a=>{if(a.tag==="Nothing")return v("Just",u);if(a.tag==="Just")return v("Just",{t:nu(a._1.t)(u.t),angle:u.t>=a._1.t?u.angle:a._1.angle,bigCircle:a._1.bigCircle||u.bigCircle,frameHash:a._1.frameHash});g()})(s._1)(i)})(D)(Lt($e(e.tokens))(i=>{if(i._2.tag==="Filling"){const s=i._2._1.node;return[k(s,{t:1,angle:(()=>{const u=xt(a=>(()=>{const c=ye(s)(t.nodes),f=a._2.length-1|0;return f>=0&&f<a._2.length&&c.tag==="Just"&&a._2[f].x>=c._1.x&&a._2[f].x<=c._1.x+c._1.w&&a._2[f].y>=c._1.y&&a._2[f].y<=c._1.y+c._1.h})()?v("Just",a._2):N)($e(t.edges));if(0<u.length){const a=u[0].length-1|0,c=a<1?[]:Gt(0,a,u[0]),f=c.length-1|0;if(f>=0&&f<c.length){const d=u[0].length-1|0;return d>=0&&d<u[0].length?Or(u[0][d].y-c[f].y)(u[0][d].x-c[f].x):0}u[0].length-1|0}return 0})(),bigCircle:n(s)||o(s),frameHash:r})]}if(i._2.tag==="Travelling"){if(i._2._1.progress>=.75)return[k(i._2._1.target,{t:(i._2._1.progress-.75)/.25,angle:(()=>{const s=Un(i._2._1.edge)(t.edges);if(s.tag==="Just"){const u=s._1.length-1|0,a=u<1?[]:Gt(0,u,s._1),c=a.length-1|0;if(c>=0&&c<a.length){const f=s._1.length-1|0;return f>=0&&f<s._1.length?Or(s._1[f].y-a[c].y)(s._1[f].x-a[c].x):0}return s._1.length-1|0,0}if(s.tag==="Nothing")return 0;g()})(),bigCircle:n(i._2._1.target)||o(i._2._1.target),frameHash:r})];if(i._2._1.progress<.25)return[k(i._2._1.source,{t:i._2._1.progress/.25,angle:(()=>{const s=Un(i._2._1.edge)(t.edges);if(s.tag==="Just")return 1<s._1.length&&0<s._1.length?Or(s._1[1].y-s._1[0].y)(s._1[1].x-s._1[0].x):0;if(s.tag==="Nothing")return 0;g()})(),bigCircle:n(i._2._1.source)||o(i._2._1.source),frameHash:r})]}return[]}))},s3=t=>w(e=>n=>(e*31|0)+Er(n)|0)(5381)(ur(t.frameTitle)),Gd=t=>{const e=vd(t),n=t.Monad0().Applicative0(),r=_n(n);return o=>i=>s=>u=>a=>{const c=s3(a),f=i3(u)(a);return r(d=>{const l=ye(d._1)(a.nodes);if(l.tag==="Just")return e(o)(i)(s)((()=>{const _=ye(d._1)(a.nodeFadeAlpha);if(_.tag==="Nothing")return 1;if(_.tag==="Just")return _._1;g()})())((()=>{const _=ye(d._1)(a.nodeLabelFadeAlpha);if(_.tag==="Nothing")return 1;if(_.tag==="Just")return _._1;g()})())((()=>{const _=ye(d._1)(f);return _.tag==="Just"?v("Just",_._1):_.tag==="Nothing"&&QT(d._1)(a.visited)?v("Just",{t:1,angle:0,bigCircle:!1,frameHash:c}):N})())(d._1)(d._2)(l._1);if(l.tag==="Nothing")return n.pure();g()})($e(u.nodes))}},u3=t=>e=>n=>{const r=nt.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=nt.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Pd=t=>e=>n=>{const r=rt.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=rt.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Id=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ac=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},a3=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},c3=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},g3=(()=>{const t=nn.unfoldr(In);return e=>t(rn("IterNode",e,Pn))})(),f3=t=>e=>{const n=an(t.angle),r=mn(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},_3=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],$o=t=>e=>{const n=r=>u3(0)(255)(fe(Gn(Z(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},Me=t=>e=>n=>r=>({x:(e-n)*mn(t.angle),y:(e+n)*an(t.angle)-r}),no=t=>{const e=Mt(n=>N,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Lt(e._1.tail)(n=>[2,n.x,n.y]),5];g()},d3=t=>e=>n=>r=>o=>{const i=(()=>{if(t==="Forward")return o;if(t==="Backward")return ge(o);g()})();if(0<i.length){const u=ei(i)(Pd(0)(1)(Ho(n)(r)(e)));if(u.tag==="Nothing")return i[0];if(u.tag==="Just")return u._1;g()}const s=ei(i)(Pd(0)(1)(Ho(n)(r)(e)));if(s.tag==="Nothing")return{x:0,y:0};if(s.tag==="Just")return s._1;g()},l3=t=>{const e=Mt(n=>N,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Lt(e._1.tail)(n=>[2,n.x,n.y])];g()},h3=t=>{const e=Mt(n=>N,n=>r=>v("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{vx:0,vy:0,vw:0,vh:0};if(e.tag==="Just"){const n=w(r=>o=>({minX:Id(r.minX)(o.x),minY:Id(r.minY)(o.y),maxX:Ac(r.maxX)(o.x),maxY:Ac(r.maxY)(o.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{vx:n.minX-40,vy:n.minY-40,vw:n.maxX-n.minX+80,vh:n.maxY-n.minY+80}}g()},p3=t=>{const e=t.Monad0().Bind1();return n=>r=>o=>{const i=o.box,s=o.np,u={color:r.nodeStroke,width:1,lineJoin:Ge,lineCap:je};return e.bind(t.fillStrokePath(no([i.ground.d,i.ground.c,i.top.c,i.top.d]))({color:$o(.66)(r.nodeFill),flat:!0})(u))(()=>e.bind(t.fillStrokePath(no([i.ground.b,i.ground.c,i.top.c,i.top.b]))({color:$o(.82)(r.nodeFill),flat:!0})(u))(()=>e.bind(t.fillStrokePath(no([i.top.a,i.top.b,i.top.c,i.top.d]))({color:$o(1)(r.nodeFill),flat:!0})(u))(()=>t.drawTextAffine(f3(n)(s.y+s.h))({x:s.x+s.w/2,y:0,content:s.label,font:{family:r.fontFamily,size:11,weight:600},color:r.text,align:Ar,baseline:Dn}))))}},m3=t=>{const e=t.Monad0().Bind1();return n=>r=>o=>i=>{const s={color:r.tokenOutsideStroke,width:1,lineJoin:Ge,lineCap:je},u=i.x-5.5,a=i.x+5.5,c=i.y-5.5,f=i.y+5.5,d=o+11,l=Me(n)(u)(c)(d),_=Me(n)(a)(c)(d),h=Me(n)(a)(f)(d),p=Me(n)(u)(f)(d),m=Me(n)(a)(f)(o),x=Me(n)(a)(c)(o);return e.bind(t.fillStrokePath(no([Me(n)(u)(f)(o),m,h,p]))({color:$o(.66)(r.tokenOutsideFill),flat:!0})(s))(()=>e.bind(t.fillStrokePath(no([x,m,h,_]))({color:$o(.82)(r.tokenOutsideFill),flat:!0})(s))(()=>t.fillStrokePath(no([l,_,h,p]))({color:$o(1)(r.tokenOutsideFill),flat:!0})(s)))}},y3=t=>{const e=m3(t);return n=>r=>o=>i=>{if(i.tag==="Travelling"){const s=a3(i._1.edge)(o.edges);return s.tag==="Just"?v("Just",(()=>{const u=d3(i._1.direction)(i._1.progress)(i._1.holdPre)(i._1.holdPost)(s._1);return{depth:u.x+u.y,draw:e(n)(r)(0)(u)}})()):N}if(i.tag==="Filling"){const s=c3(i._1.node)(o.nodes);if(s.tag==="Just")return v("Just",(()=>{const u={x:s._1.x+s._1.w/2,y:s._1.y+s._1.h/2};return{depth:u.x+u.y,draw:e(n)(r)(n.boxHeight)(u)}})())}return N}},x3={angle:.5235987755982988,boxHeight:26,transparentBg:!0},J3=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:Me(t)(e.x)(e.y)(0),b:Me(t)(r)(e.y)(0),c:Me(t)(r)(n)(0),d:Me(t)(e.x)(n)(0)},top:{a:Me(t)(e.x)(e.y)(t.boxHeight),b:Me(t)(r)(e.y)(t.boxHeight),c:Me(t)(r)(n)(t.boxHeight),d:Me(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},Ad=t=>e=>$(n=>({np:n,box:J3(t)(n)}))((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Xt("Cons",r._4,n(r._6,o)));g()};return qt(ue.foldr,n(e.nodes,Ht))})()),N3=t=>e=>[...Lt(Ad(t)(e))(_3),...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Xt("Cons",r._4,n(r._6,o)));g()};return Lt(qt(ue.foldr,n(e.edges,Ht)))($(r=>Me(t)(r.x)(r.y)(0)))})()],w3=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=Ac(1e-4)(Fe(n*n+e*e)),o=e/r,i=n/r,s=t.to.y-o*7,u=t.to.x-i*7;return no([t.to,{x:u-o*3,y:s+i*3},{x:u+o*3,y:s-i*3}])},v3=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>o=>i=>s=>u=>{const a=Me(r)(u.x)(u.y)(0),c=Me(r)(s.x)(s.y)(0);return e.Bind1().bind(t.strokePath(l3([c,a]))({color:o.edge,width:1.5,lineJoin:Ge,lineCap:Bn}))(()=>{const f=t.fillPath(w3({from:c,to:a}))({color:o.arrowFill,flat:!0});return i?f:n.pure()})}},T3=t=>{const e=v3(t);return n=>r=>o=>i=>{const s=Ie(En,i,Gt(1,i.length,i)),u=s.length-1|0;return Yt(a=>c=>({depth:(c._1.x+c._1.y+c._2.x+c._2.y)/2,draw:e(n)(r)(o&&a===u)(c._1)(c._2)}))(s)}},b3=t=>{const e=p3(t),n=y3(t),r=T3(t),o=t.Monad0(),i=Ri(o.Applicative0())(zt);return s=>u=>a=>c=>{const f=Sc(u),d=[...Lt(g3(a.edges))(l=>r(s)(f)((()=>{const _=bo("conn:")(l._1);if(_.tag==="Just")return!1;if(_.tag==="Nothing")return!0;g()})())(l._2)),...$(l=>({depth:l.box.depth,draw:e(s)(f)(l)}))(Ad(s)(a)),...xt(n(s)(f)(a))((()=>{const l=(_,h)=>{if(_.tag==="Leaf")return h;if(_.tag==="Node")return l(_._5,Xt("Cons",_._4,l(_._6,h)));g()};return qt(ue.foldr,l(c.tokens,Ht))})())];return o.Bind1().bind((()=>{const l=h3(N3(s)(a));return t.Monad0().Bind1().bind(t.clearBackground(s.transparentBg?f.bgTransparent:f.bg))(()=>t.setViewport(l))})())(()=>i(l=>l.draw)(Dt(l=>_=>rt.compare(l.depth)(_.depth))(d)))}},Dd=(t,e)=>({tag:t,_1:e}),su=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},k3=t=>e=>n=>{const r=rt.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=rt.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Dc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},L3=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},C3=Dd("ResolvedLabels"),S3=t=>{const e=oe(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return ys(t);g()},Si=t=>e=>{const n=su(1)(Se(e.rootLayout).w),r=ns(e.rootLayout)(e.camera),o=!e.diving&&e.levels.length===1?1:k3(0)(1)(r.w/n),i=ys(e).state.frameTitle===""?0*o:40*o,s=t.padding*o*o;return(()=>{if(t.outputAspect.tag==="Nothing")return bm;if(t.outputAspect.tag==="Just")return mf(t.outputAspect._1);g()})()({vx:r.x-s,vy:r.y-s-i,vw:r.w+2*s,vh:r.h+2*s+i})},E3=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=Dc(e._1)(t.segment.layout.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1.x*t.segment.placement.scale+t.segment.placement.tx,o=n._1.y*t.segment.placement.scale+t.segment.placement.ty,i=n._1.w*t.segment.placement.scale,s=n._1.h*t.segment.placement.scale;return[1,r,o,2,r+i,o,2,r+i,o+s,2,r,o+s,5]}}g()},Bc=t=>e=>{const n=d0(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}},G3=t=>{const e=t.Monad0(),n=e.Bind1();return r=>o=>{if(r==="")return e.Applicative0().pure();const i=o.vh/720,s=56*i;return n.bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:56,weight:700})(r))(u=>{const a=s+16*i*2,c=u*i+28*i*2,f=o.vy+o.vh/2,d=o.vx+o.vw/2;return n.bind(t.drawRoundedRect({x:d-c/2,y:f-a/2,w:c,h:a})(16*i)(v("Just",{color:{r:255,g:255,b:255,a:235},flat:!0}))(v("Just",{color:{r:0,g:0,b:0,a:255},width:1.5*i,lineJoin:Ge,lineCap:Bn})))(()=>t.drawText({x:d,y:f,content:r,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:s,weight:700},color:{r:28,g:30,b:36,a:255},align:Ar,baseline:Dn}))})}},P3=t=>{const e=t.Monad0(),n=e.Bind1();return r=>o=>{if(r==="")return e.Applicative0().pure();const i=o.vh/720,s=15*i;return n.bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:15,weight:600})(r))(u=>{const a=o.vy+12*i,c=s+6*i*2,f=u*i+11*i*2,d=o.vx+o.vw/2;return n.bind(t.drawRoundedRect({x:d-f/2,y:a,w:f,h:c})(c/2)(v("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}))(v("Just",{color:{r:0,g:0,b:0,a:255},width:1*i,lineJoin:Ge,lineCap:Bn})))(()=>t.drawText({x:d,y:a+c/2,content:r,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:s,weight:600},color:{r:28,g:30,b:36,a:255},align:Ar,baseline:Dn}))})}},I3=t=>{const e=Sd(t),n=Ic(t),r=t.Monad0(),o=r.Bind1(),i=r.Applicative0(),s=Ed(t),u=Gd(t)(Lc)(1),a=Td(t),c=kd(t),f=bd(t),d=YT(t),l=t.popBlur,_=t.popAlpha,h=G3(t),p=P3(t);return m=>x=>J=>y=>T=>b=>C=>S=>{const E=Sc(m.theme),F=(()=>{if(S.tag==="ResolvedLabels")return e(E)(T)(b)(C);if(S.tag==="SpringLabels")return n(E)(b)(C)(S._1);g()})();return o.bind(t.Monad0().Bind1().bind(t.clearBackground(m.transparentBg?E.bgTransparent:E.bg))(()=>t.setViewport(T)))(()=>o.bind((()=>{const O=o.bind((()=>{const G=t.pushAlpha(J);return J<1?G:i.pure()})())(()=>o.bind((()=>{const G=t.pushBlur(y);return y>0?G:i.pure()})())(()=>o.bind(s(E)(b)(C))(()=>o.bind(u(E)(b)(C))(()=>o.bind(a(E)(b)(C))(()=>o.bind(c(E)(T)(b)(C))(()=>o.bind(f(lv)(E)(b)(C))(()=>o.bind(F)(()=>o.bind((()=>{const G=d(E)(b)(C);return C.staticKind!=="Animated"?G:i.pure()})())(()=>o.bind(y>0?l:i.pure())(()=>J<1?_:i.pure()))))))))));return J>0?O:i.pure()})())(()=>o.bind(m.watermark===""?t.Monad0().Applicative0().pure():t.drawText({x:T.vx+6,y:T.vy+6,content:m.watermark,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:Ti,baseline:ov}))(()=>C.staticKind==="TitleCard"?h(C.frameTitle)(T):p(C.frameTitle)(T))))}},Bd=t=>{const e=t.Monad0().Applicative0(),n=lo(e)(zt);return r=>o=>i=>s=>n(s.minis)(u=>{const a=Rd(t)(r)(o)(i)(D)(s)(u);return(()=>{const c=u.segment.path.length-1|0;return u.bgAlpha>0&&c>=0&&c<u.segment.path.length&&(()=>{const f=Dc(u.segment.path[c])(s.state.nodes);if(f.tag==="Just")return f._1.tag==="Hidden"?!1:f._1.tag!=="PloppingOut";if(f.tag==="Nothing")return!1;g()})()})()?a:e.pure()})},Rd=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popTransform,i=Sd(t),s=Ic(t),u=Ed(t),a=Gd(t),c=Td(t),f=kd(t),d=bd(t),l=t.popBakedTransform,_=t.popClip,h=t.popBlur,p=t.popAlpha;return m=>x=>J=>y=>T=>b=>{const C=b.blur>0,S=b.segment.placement,E=b.state,F={tx:S.tx,ty:S.ty,sx:S.scale,sy:S.scale},O=Sc(m.theme),G=b.segment.layout,A=Se(G),K={vx:A.x-1e3,vy:A.y-1e3,vw:A.w+2e3,vh:A.h+2e3},U=b.segment.path.length-1|0,z=U>=0&&U<b.segment.path.length?Dc(b.segment.path[U])(T.segment.layout.nodes):N,H=b.segment.placement.scale*J,M=L3(8)(su(1)(1/(1.25*su(1e-6)(H)))),P=11*H>=5?Lc:FT,R=(()=>{if(z.tag==="Nothing")return n.pure();if(z.tag==="Just"){const q=z._1;return r.bind(t.pushTransform({tx:T.segment.placement.tx,ty:T.segment.placement.ty,sx:T.segment.placement.scale,sy:T.segment.placement.scale}))(()=>r.bind(mc(t)(q.shape)({x:q.x+1,y:q.y+1,w:q.w-2,h:q.h-2})(7)(v("Just",{color:O.bg,flat:!0}))(N))(()=>o))}g()})(),Q=(()=>{if(P==="LabelsHidden")return n.pure();if(P==="LabelsShown")return y.tag==="Leaf"?i(O)(Bc(x.viewport)(b))(G)(E):s(O)(G)(E)(y);g()})(),B=E3(T)((()=>{const q=b.segment.path.length-1|0;return q>=0&&q<b.segment.path.length?v("Just",b.segment.path[q]):N})());return r.bind(t.pushAlpha(b.bgAlpha))(()=>r.bind((()=>{const q=t.pushBlur(b.blur*S.scale);return C?q:n.pure()})())(()=>r.bind(t.pushClip(B)($s))(()=>r.bind(T.role==="Active"||T.role==="FlyThrough"?R:n.pure())(()=>r.bind(t.pushTransform(F))(()=>r.bind(u(O)(G)(E))(()=>r.bind(a(P)(M)(O)(G)(E))(()=>r.bind(c(O)(G)(E))(()=>r.bind(f(O)(K)(G)(E))(()=>r.bind(o)(()=>r.bind(t.pushBakedTransform(F))(()=>r.bind(d(hv)(O)(G)(E))(()=>r.bind(l)(()=>r.bind(_)(()=>r.bind(t.pushTransform(F))(()=>r.bind(Q)(()=>r.bind(o)(()=>r.bind(Bd(t)(m)(x)(J)(b))(()=>r.bind(C?h:n.pure())(()=>p)))))))))))))))))))}},Qd=t=>{const e=b3(t),n=t.Monad0(),r=n.Applicative0(),o=n.Bind1(),i=Rd(t),s=I3(t),u=Bd(t);return a=>c=>f=>{if(a.theme==="Isometric")return e({...x3,transparentBg:a.transparentBg})(a.theme)(ys(f).segment.layout)(ys(f).state);const d=Si(a)(f),l=m=>f.hasDives?d.vw/su(1)(Se(f.rootLayout).w):1,_={tileScale:l(),viewport:d},h=m=>x=>{if(x.length===0)return r.pure();const J=Mt(y=>N,y=>T=>v("Just",{head:y,tail:T}),x);if(J.tag==="Nothing")return r.pure();if(J.tag==="Just"){const y=J._1.head,T=J._1.tail;return o.bind((()=>{const b=i(a)(_)(f.camera.zoom)(y.role==="Active"?c:D)(m)(y);return f.diving||y.role==="Active"?b:r.pure()})())(()=>h(y)(T))}g()},p=Mt(m=>N,m=>x=>v("Just",{head:m,tail:x}),f.levels);if(p.tag==="Nothing")return r.pure();if(p.tag==="Just"){const m=p._1.tail,x=p._1.head;return o.bind((()=>{const J=m.length===0;return s(a)(l())(x.role==="Active"||x.role==="FlyThrough"?x.bgAlpha:0)(x.blur)(d)(x.segment.layout)(S3(f).state)(J&&c.tag!=="Leaf"?Dd("SpringLabels",c):C3)})())(()=>o.bind((()=>{const J=u(a)(_)(f.camera.zoom)(x);return x.role==="Active"||x.role==="FlyThrough"?J:r.pure()})())(()=>h(x)(m)))}g()}},A3=Pc(Jc),Fd=Qd(Jc),D3=t=>e=>n=>r=>o=>i=>s=>{const u={padding:24,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?N:v("Just",r.width/r.height)},a=V1(n)(r);return()=>{const c=a(),f=o.levels.length-1|0;if(f>=0&&f<o.levels.length){const l=A3(Bc(Si(u)(o))(o.levels[f]))(o.levels[f].segment.layout)(o.levels[f].state)(c)(),_=ac(i)(l)(s);return Fd(u)(_.applied)(o)(c)(),_.springs}const d=ac(i)(D)(s);return Fd(u)(d.applied)(o)(c)(),d.springs}},Ei=t=>"rgb("+ee(t.r)+","+ee(t.g)+","+ee(t.b)+")",ro=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,re=vo(No("Fixed",wo(0)(20)(2))),Rc=t=>{const e=n=>{const r=n>=0&&n<t.length?v("Just",t[n]):N;if(r.tag==="Just")return r._1===1?["M",re((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),re((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===2?["L",re((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),re((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===3?["Q",re((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),re((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),re((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),re((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+5|0)]:r._1===4?["C",re((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),re((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),re((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),re((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),re((()=>{const o=n+5|0;return o>=0&&o<t.length?t[o]:0})()),re((()=>{const o=n+6|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+7|0)]:r._1===5?["Z",...e(n+1|0)]:[];if(r.tag==="Nothing")return[];g()};return fr(" ")(e(0))},B3=t=>re(t.vx)+" "+re(t.vy)+" "+re(t.vw)+" "+re(t.vh),Nn=t=>e=>fe(bn(e>=0&&e<t.length?t[e]:0)),Qc=t=>e=>{const n=Nn(t.ops)(e+1|0);return Gt(n,n+Nn(t.ops)(e+2|0)|0,t.paths)},zd=(()=>{const t=kn("&")("&"),e=kn("<")("<"),n=(()=>{const r=kn(">")(">"),o=(()=>{const i=kn('"')(""");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),R3={vx:0,vy:0,vw:1,vh:1},Q3=t=>(e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i>=0&&i<t.length){if(t[i]===15){const s=i+1|0;r=!1,o={vx:s>=0&&s<t.length?t[s]:0,vy:(()=>{const u=s+1|0;return u>=0&&u<t.length?t[u]:0})(),vw:(()=>{const u=s+2|0;return u>=0&&u<t.length?t[u]:0})(),vh:(()=>{const u=s+3|0;return u>=0&&u<t.length?t[u]:0})()};continue}n=i+ro(t[i])|0;continue}r=!1,o=R3}return o})(0),Gi=t=>e=>({r:Nn(t)(e),g:Nn(t)(e+1|0),b:Nn(t)(e+2|0),a:Nn(t)(e+3|0)}),Md=t=>e=>({color:Gi(t)(e),width:(()=>{const n=e+4|0;return n>=0&&n<t.length?t[n]:0})(),join:Nn(t)(e+5|0),cap:Nn(t)(e+6|0)}),F3=t=>e=>'<rect x="'+re(t.vx)+'" y="'+re(t.vy)+'" width="'+re(t.vw)+'" height="'+re(t.vh)+'" fill="'+Ei(e)+'" opacity="'+re(Z(e.a)/255)+'"/>',z3=t=>e=>'<path d="'+Rc(t)+'" fill="'+Ei(e)+'" fill-opacity="'+re(Z(e.a)/255)+'"/>',Hd=t=>' stroke="'+Ei(t.color)+'" stroke-opacity="'+re(Z(t.color.a)/255)+'" stroke-width="'+re(t.width)+'" stroke-linejoin="'+(t.join===0?"round":t.join===1?"bevel":"miter")+'" stroke-linecap="'+(t.cap===0?"butt":t.cap===1?"round":"square")+'"',M3=t=>e=>n=>'<path d="'+Rc(t)+'" fill="'+Ei(e)+'" fill-opacity="'+re(Z(e.a)/255)+'"'+Hd(n)+"/>",H3=t=>e=>'<path d="'+Rc(t)+'" fill="none"'+Hd(e)+"/>",O3=t=>e=>{const n=Gi(t.ops)(e+7|0),r=Nn(t.ops)(e+12|0),o=Nn(t.ops)(e+11|0);return'<text x="'+re((()=>{const i=e+1|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" y="'+re((()=>{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="'+Ei(n)+'" fill-opacity="'+re(Z(n.a)/255)+'" font-size="'+re((()=>{const i=e+5|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" font-family="'+zd((()=>{const i=Nn(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="'+ee(Nn(t.ops)(e+6|0))+'" text-anchor="'+(o===0?"start":o===1?"middle":"end")+'">'+zd((()=>{const i=Nn(t.ops)(e+3|0);return i>=0&&i<t.strs.length?t.strs[i]:""})())+"</text>"},oo=t=>e=>n=>{const r=n>=0&&n<e.ops.length?v("Just",e.ops[n]):N;if(r.tag==="Just")return r._1===1?z3(Qc(e)(n))(Gi(e.ops)(n+3|0))+oo(t)(e)(n+ro(r._1)|0):r._1===2?H3(Qc(e)(n))(Md(e.ops)(n+3|0))+oo(t)(e)(n+ro(r._1)|0):r._1===3?M3(Qc(e)(n))(Gi(e.ops)(n+3|0))(Md(e.ops)(n+7|0))+oo(t)(e)(n+ro(r._1)|0):r._1===4?O3(e)(n)+oo(t)(e)(n+ro(r._1)|0):r._1===16?F3(t)(Gi(e.ops)(n+1|0))+oo(t)(e)(n+ro(r._1)|0):oo(t)(e)(n+ro(r._1)|0);if(r.tag==="Nothing")return"";g()},q3=t=>{const e=Q3(t.ops);return{viewBox:B3(e),body:oo(e)(t)(0),vx:e.vx,vy:e.vy,vw:e.vw,vh:e.vh}},$3=Uw(jw)(Sh),Od=t=>e=>{const n=t.strs;return()=>{const r=Ru(n);return t.strs.push(e),r}},uu=t=>e=>{const n=t.paths;return()=>{const r=Ru(n);return t.paths.push(...e),{offset:r,len:e.length}}},W3=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)}},qd=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)}},xr=t=>e=>{const n=Z(e),r=t.ops;return()=>{r.push(n)}},au=t=>e=>{const n=e.len,r=xr(t)(e.offset);return()=>(r(),xr(t)(n)())},Y3=()=>{const t=[],e=[],n=[],r=[];return r.push(1),{ops:t,paths:e,strs:n,alphaStack:r}},V3=t=>{if(t.tag==="MeasureText"){const e=t._3(gc(t._1)(t._2));return()=>e}if(t.tag==="MeasureInk"){const e=t._3(fc(t._1)(t._2));return()=>e}g()},$d=t=>{const e=t.alphaStack;return()=>{const n=Ru(e);if(n===0)return 1;const r=Gh(ne,N,n-1|0,t.alphaStack);if(r.tag==="Nothing")return 1;if(r.tag==="Just")return r._1;g()}},io=t=>e=>{const n=$d(t);return()=>{const r=n();return xr(t)(e.r)(),xr(t)(e.g)(),xr(t)(e.b)(),xr(t)(fe(bn(Z(e.a)*r+.5)))()}},Wd=t=>e=>{const n=io(t)(e.color);return()=>{n(),t.ops.push(e.width),t.ops.push((()=>{if(e.lineJoin==="RoundJoin")return 0;if(e.lineJoin==="BevelJoin")return 1;if(e.lineJoin==="MiterJoin")return 2;g()})()),t.ops.push((()=>{if(e.lineCap==="ButtCap")return 0;if(e.lineCap==="RoundCap")return 1;if(e.lineCap==="SquareCap")return 2;g()})())}},U3=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,u=r;if(u.tag==="FillPath"){const a=u._3,c=u._2,f=uu(s)(u._1);o=!1,i=()=>{const d=f();return s.ops.push(1),au(s)(d)(),io(s)(c.color)(),a};continue}if(u.tag==="StrokePath"){const a=u._3,c=u._2,f=uu(s)(u._1);o=!1,i=()=>{const d=f();return s.ops.push(2),au(s)(d)(),Wd(s)(c)(),a};continue}if(u.tag==="FillStrokePath"){const a=u._2,c=u._4,f=u._3,d=uu(s)(u._1);o=!1,i=()=>{const l=d();return s.ops.push(3),au(s)(l)(),io(s)(a.color)(),Wd(s)(f)(),c};continue}if(u.tag==="DrawText"){const a=u._2,c=u._1,f=Od(s)(Vr(c.content));o=!1,i=()=>{const d=f(),l=Od(s)(c.font.family)();return s.ops.push(4),s.ops.push(c.x),s.ops.push(c.y),xr(s)(d)(),xr(s)(l)(),s.ops.push(c.font.size),xr(s)(c.font.weight)(),io(s)(c.color)(),s.ops.push((()=>{if(c.align==="AlignLeft")return 0;if(c.align==="AlignCenter")return 1;if(c.align==="AlignRight")return 2;g()})()),s.ops.push((()=>{if(c.baseline==="BaselineTop")return 0;if(c.baseline==="BaselineMiddle")return 1;if(c.baseline==="BaselineAlphabetic")return 2;if(c.baseline==="BaselineBottom")return 3;g()})()),a};continue}if(u.tag==="DrawTextAffine"){n=s,r=Ft("DrawText",{...u._2,x:u._1.a*u._2.x+u._1.c*u._2.y+u._1.e,y:u._1.b*u._2.x+u._1.d*u._2.y+u._1.f},u._3);continue}if(u.tag==="PushTransform"){const a=u._2,c=u._1,f=s.ops;o=!1,i=()=>(f.push(5),W3(s)(c)(),a);continue}if(u.tag==="PopTransform"){const a=u._1,c=s.ops;o=!1,i=()=>(c.push(6),a);continue}if(u.tag==="PushClip"){const a=u._3,c=u._2,f=uu(s)(u._1);o=!1,i=()=>{const d=f();return s.ops.push(7),au(s)(d)(),s.ops.push((()=>{if(c==="NonZero")return 0;if(c==="EvenOdd")return 1;g()})()),a};continue}if(u.tag==="PopClip"){const a=u._1,c=s.ops;o=!1,i=()=>(c.push(8),a);continue}if(u.tag==="PushBlend"){const a=u._1,c=u._2,f=s.ops;o=!1,i=()=>(f.push(9),s.ops.push((()=>{if(a==="Normal")return 0;if(a==="Difference")return 1;g()})()),c);continue}if(u.tag==="PopBlend"){const a=u._1,c=s.ops;o=!1,i=()=>(c.push(10),a);continue}if(u.tag==="PushAlpha"){const a=u._1,c=u._2,f=$d(s);o=!1,i=()=>{const d=f();return s.alphaStack.push(d*a),s.ops.push(11),s.ops.push(a),c};continue}if(u.tag==="PopAlpha"){const a=u._1,c=s.alphaStack;o=!1,i=()=>(Ph(ne,N,c),s.ops.push(12),a);continue}if(u.tag==="PushBlur"){const a=u._2,c=u._1,f=s.ops;o=!1,i=()=>(f.push(18),s.ops.push(c),a);continue}if(u.tag==="PopBlur"){const a=u._1,c=s.ops;o=!1,i=()=>(c.push(19),a);continue}if(u.tag==="PushLayer"){const a=u._1,c=u._2,f=s.ops;o=!1,i=()=>(f.push(13),s.ops.push((()=>{if(a==="LayerBase")return 0;if(a==="LayerPolyOut")return 1;if(a==="LayerPolyIn")return 2;if(a==="LayerNodeMask")return 3;if(a==="LayerOverlay")return 4;g()})()),c);continue}if(u.tag==="PopLayer"){const a=u._1,c=s.ops;o=!1,i=()=>(c.push(14),a);continue}if(u.tag==="SetViewport"){const a=u._2,c=u._1,f=s.ops;o=!1,i=()=>(f.push(15),qd(s)(c)(),a);continue}if(u.tag==="ClearBackground"){const a=u._1,c=u._2,f=s.ops;o=!1,i=()=>(f.push(16),io(s)(a)(),c);continue}if(u.tag==="BackgroundDots"){const a=u._2,c=u._1,f=s.ops;o=!1,i=()=>(f.push(17),qd(s)(c.viewport)(),io(s)(c.bgColor)(),io(s)(c.dotColor)(),s.ops.push(c.tile),s.ops.push(c.dotRadius),s.ops.push(c.origin.x),s.ops.push(c.origin.y),a);continue}g()}return i},X3=t=>e=>e.type==="metrics"?V3(e.value):e.type==="render"?U3(t)(e.value):r0("Data.Functor.Variant: pattern match failure ["+e.type+"]"),K3=t=>{const e=Y3();return $3(X3(e))(t)(),{ops:e.ops,paths:e.paths,strs:e.strs}},j3=t=>t,Pi=t=>t,Fc=Pi("Light"),Z3=Pi("Dark"),tb=Pi("Blueprint"),eb=Pi("Whiteboard"),nb=Pi("Isometric"),rb=j3("TransparentBackground"),Br=t=>"rgb("+ee(t.r)+","+ee(t.g)+","+ee(t.b)+")",Xn=vo(No("Fixed",wo(0)(20)(4))),ob=t=>"translate("+Xn(t.tx)+","+Xn(t.ty)+") scale("+Xn(t.sx)+","+Xn(t.sy)+")",Et=vo(No("Fixed",wo(0)(20)(2))),zc=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,o=r>=0&&r<t.length?v("Just",t[r]):N;if(o.tag==="Nothing"){n=t.length;continue}if(o.tag==="Just"){if(o._1===1){e.push("M"),e.push(Et((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Et((()=>{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(Et((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Et((()=>{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(Et((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Et((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Et((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Et((()=>{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(Et((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Et((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Et((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Et((()=>{const i=r+4|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Et((()=>{const i=r+5|0;return i>=0&&i<t.length?t[i]:0})())),e.push(Et((()=>{const i=r+6|0;return i>=0&&i<t.length?t[i]:0})())),n=r+7|0;continue}if(o._1===5){e.push("Z"),n=r+1|0;continue}n=t.length;continue}g()}return fr(" ")(e)},ib={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},Mc=(()=>{const t=kn("&")("&"),e=kn("<")("<"),n=(()=>{const r=kn(">")(">"),o=(()=>{const i=kn('"')(""");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),sb=t=>{if(t.style==="RunText")return"<tspan>"+Mc(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+Mc(t.text)+"</tspan>";g()},Be=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},ub=t=>e=>{const n=[];let r=0;const o=i=>{const s=i>=0&&i<e.length?t.sx*e[i]+t.tx:t.sx*0+t.tx;return()=>{n.push(s),n.push((()=>{const u=i+1|0;return u>=0&&u<e.length?t.sy*e[u]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const i=r,s=i>=0&&i<e.length?v("Just",e[i]):N;if(s.tag==="Nothing"){r=e.length;continue}if(s.tag==="Just"){if(s._1===1){n.push(s._1),o(i+1|0)(),r=i+3|0;continue}if(s._1===2){n.push(s._1),o(i+1|0)(),r=i+3|0;continue}if(s._1===3){n.push(s._1),o(i+1|0)(),o(i+3|0)(),r=i+5|0;continue}if(s._1===4){n.push(s._1),o(i+1|0)(),o(i+3|0)(),o(i+5|0)(),r=i+7|0;continue}if(s._1===5){n.push(s._1),r=i+1|0;continue}r=e.length;continue}g()}return n},cu=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return ub(r._1)(e);g()}},Yd={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),s=o();return i(s)}},Functor0:()=>ib},ab={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>Yd},cb={pure:t=>e=>()=>t,Apply0:()=>Yd},gb={Applicative0:()=>cb,Bind1:()=>ab},fb=t=>e=>'<defs><pattern id="'+t+'" x="'+Et(e.origin.x)+'" y="'+Et(e.origin.y)+'" width="'+Et(e.tile)+'" height="'+Et(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+Et(e.tile)+'" height="'+Et(e.tile)+'" fill="'+Br(e.bgColor)+'" fill-opacity="'+Et(Z(e.bgColor.a)/255)+'"/>')+'<circle cx="'+Et(e.tile/2)+'" cy="'+Et(e.tile/2)+'" r="'+Et(e.dotRadius)+'" fill="'+Br(e.dotColor)+'"/></pattern></defs><rect x="'+Et(e.viewport.vx)+'" y="'+Et(e.viewport.vy)+'" width="'+Et(e.viewport.vw)+'" height="'+Et(e.viewport.vh)+'" fill="url(#'+t+')"/>',Vd=t=>e=>'<path d="'+zc(t)+'" fill="'+Br(e)+'" fill-opacity="'+Et(Z(e.a)/255)+'"/>',_b=t=>e=>n=>r=>'<rect x="'+Et(t.x)+'" y="'+Et(t.y)+'" width="'+Et(t.w)+'" height="'+Et(t.h)+'" rx="'+Et(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+Br(n._1.color)+'" fill-opacity="'+Et(Z(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';g()})()+(()=>{if(r.tag==="Just")return' stroke="'+Br(r._1.color)+'" stroke-opacity="'+Et(Z(r._1.color.a)/255)+'" stroke-width="'+Et(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";g()})()+'"';if(r.tag==="Nothing")return"";g()})()+"/>",Ud=t=>e=>'<path d="'+zc(t)+'" fill="none" stroke="'+Br(e.color)+'" stroke-opacity="'+Et(Z(e.color.a)/255)+'" stroke-width="'+Et(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";g()})()+'"/>',Xd=t=>{const e=Xf(Vr(t.content));return'<text x="'+Et(t.x)+'" y="'+Et(t.y)+'"'+(()=>{if(t.baseline==="BaselineTop")return' dy="0.8em"';if(t.baseline==="BaselineMiddle")return' dy="0.32em"';if(t.baseline==="BaselineAlphabetic"||t.baseline==="BaselineBottom")return"";g()})()+' fill="'+Br(t.color)+'" fill-opacity="'+Et(Z(t.color.a)/255)+'" font-size="'+Et(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+ee(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";g()})()+'">'+(e.length===1&&e[0].style==="RunText"?Mc(e[0].text):fr("")($(sb)(e)))+"</text>"},db=t=>"matrix("+Xn(t.a)+" "+Xn(t.b)+" "+Xn(t.c)+" "+Xn(t.d)+" "+Xn(t.e)+" "+Xn(t.f)+")",Kd={fillPath:t=>e=>n=>{const r=cu(n)(t);return()=>{const o=r();return Be(Vd(o)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=cu(n)(t);return()=>{const o=r(),i=n.bake.value;return Be(Ud(o)((()=>{if(i.tag==="Nothing")return e;if(i.tag==="Just")return{...e,width:i._1.sx*e.width};g()})()))(n)()}},fillStrokePath:t=>e=>n=>r=>{const o=cu(r)(t);return()=>{const i=o(),s=r.bake.value;return Be(Vd(i)(e.color)+Ud(i)((()=>{if(s.tag==="Nothing")return n;if(s.tag==="Just")return{...n,width:s._1.sx*n.width};g()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>o=>{const i=o.bake;return()=>{const s=i.value;return Be(_b((()=>{if(s.tag==="Nothing")return t;if(s.tag==="Just")return{x:s._1.sx*t.x+s._1.tx,y:s._1.sy*t.y+s._1.ty,w:s._1.sx*t.w,h:s._1.sy*t.h};g()})())((()=>{if(s.tag==="Nothing")return e;if(s.tag==="Just")return s._1.sx*e;g()})())(n)(r.tag==="Just"?v("Just",(()=>{if(s.tag==="Nothing")return r._1;if(s.tag==="Just")return{...r._1,width:s._1.sx*r._1.width};g()})()):N))(o)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return Be(Xd((()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return{...t,x:r._1.sx*t.x+r._1.tx,y:r._1.sy*t.y+r._1.ty,font:{...t.font,size:r._1.sx*t.font.size}};g()})()))(e)()}},drawTextAffine:t=>e=>Be((()=>{const n='transform="'+db(t)+'"';return(n===""?"<g>":"<g "+n+">")+Xd(e)+"</g>"})()),pushTransform:t=>Be((()=>{const e='transform="'+ob(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:Be("</g>"),pushBakedTransform:t=>e=>{const n=e.bake;return()=>{n.value=v("Just",t)}},popBakedTransform:t=>{const e=t.bake;return()=>{e.value=N}},pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const o=r.value;n.clipCounter.value=o+1|0;const i=cu(n)(t)(),s="clip"+ee(o);return Be((()=>{const u='clip-path="url(#'+s+')"';return'<defs><clipPath id="'+s+'"><path d="'+zc(i)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";g()})()+"/></clipPath></defs>"+(u===""?"<g>":"<g "+u+">")})())(n)()}},popClip:Be("</g>"),pushBlend:t=>Be((()=>{const e=(()=>{if(t==="Normal")return'style="mix-blend-mode: normal"';if(t==="Difference")return'style="mix-blend-mode: difference"';g()})();return e===""?"<g>":"<g "+e+">"})()),popBlend:Be("</g>"),pushAlpha:t=>Be((()=>{const e='opacity="'+Et(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:Be("</g>"),pushBlur:t=>e=>{if(t<.01)return Be("<g>")(e);const n=e.patternCounter;return()=>{const r=n.value;e.patternCounter.value=r+1|0;const o="lvl-blur-"+ee(r);return Be((()=>{const i='filter="url(#'+o+')"';return'<defs><filter id="'+o+'" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="'+Et(t)+'"/></filter></defs>'+(i===""?"<g>":"<g "+i+">")})())(e)()}},popBlur:Be("</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=>Be('<rect x="'+Et(e.viewport.vx)+'" y="'+Et(e.viewport.vy)+'" width="'+Et(e.viewport.vw)+'" height="'+Et(e.viewport.vh)+'" fill="'+Br(t)+'" opacity="'+Et(Z(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,Be(fb("bg-dots-"+ee(r))(t))(e)()}},measureText:t=>e=>n=>{const r=gc(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=fc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>pc,Monad0:()=>gb},lb=Qd(Kd),hb=Pc(Kd),pb=t=>e=>n=>r=>o=>{const i={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;g()})(),halftoneShadows:!0,watermark:"",theme:n,outputAspect:t},s=Si(i)(o);return{viewBox:Et(s.vx)+" "+Et(s.vy)+" "+Et(s.vw)+" "+Et(s.vh),body:(()=>{const u=[],a={value:0},c={value:0},f={value:0},d={value:N};return lb(i)(e)(o)({out:u,maskDepth:a,clipCounter:c,patternCounter:f,viewport:s,bake:d})(),fr("")(u)})(),vx:s.vx,vy:s.vy,vw:s.vw,vh:s.vh}},mb=t=>e=>n=>r=>o=>i=>{const s={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;g()})(),outputAspect:t},u=ac(o)((()=>{const a=[],c={value:0},f={value:0},d={value:0},l={value:N},_=r.levels.length-1|0;if(_>=0&&_<r.levels.length){const h=Bc(Si(s)(r))(r.levels[_]);return hb(h)(r.levels[_].segment.layout)(r.levels[_].state)({out:a,maskDepth:c,clipCounter:f,patternCounter:d,viewport:h,bake:l})()}return D})())(i);return{parts:pb(t)(u.applied)(e)(n)(r),springs:u.springs}},so=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(o=>n(o._1)(o._2)),Apply0:()=>jd(t)}),jd=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>o=>i=>e.map(s=>k(r(s._1),s._2))(o(i))};return{apply:(()=>{const r=so(t);return o=>i=>r.bind(o)(s=>r.bind(i)(u=>uo(t).pure(s(u))))})(),Functor0:()=>n}},uo=t=>({pure:e=>n=>t.Applicative0().pure(k(e,n)),Apply0:()=>jd(t)}),Zd=t=>{const e={Applicative0:()=>uo(t),Bind1:()=>so(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},ao=(t,e)=>({tag:t,_1:e}),Jr=(t,e)=>({tag:t,_1:e}),Hc=t=>t,Kn=(t,e)=>({tag:t,_1:e}),Oc=t=>t,ke=Zd(pn),$t=so(pn),He=ke.state(t=>k(t,t)),se=uo(pn),tl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},el=Ri(se),qc=el(zt),jn=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},nl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},yb=(()=>{const t=nn.unfoldr(e=>{if(e.tag==="Nil")return N;if(e.tag==="Cons")return v("Just",k(e._1,e._2));g()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Xt("Cons",r._3,n(r._6,o)));g()};return n(e,Ht)})())})(),Rn=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},xb=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},gu=t=>e=>n=>w(r=>o=>t.Bind1().bind(r)(i=>e(i)(o)))(t.Applicative0().pure(n)),Jb=w(t=>e=>j(I)(e)()(t))(D),Nb=(()=>{const t=(e=>n=>{let r=e,o=n,i=!0,s;for(;i;){const u=r,a=o;if(a.tag==="Nil"){i=!1,s=u;continue}if(a.tag==="Cons"){r=j(I)(a._1)()(u),o=a._2;continue}g()}return s})(D);return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Xt("Cons",r._3,n(r._6,o)));g()};return n(e,Ht)})())})(),wb=el(Rh),vb=Oc("AnimatedSurface"),Tb=Oc("StillSurface"),bb=Oc("SequenceSurface"),kb=Kn("Exit"),fu=Hc("AnimatedKeyframe"),$c=Hc("Still"),Lb=Hc("Title"),Cb=t=>Jr("Par",t),Sb=t=>Jr("Seq",t),Eb=t=>Jr("GroupSeq",t),rl=t=>ao("StepDive",t),Gb={line:0,column:0,endLine:0,endColumn:0},Pb=t=>e=>n=>{const r=Mr(ne,N,o=>o._1===t,n);if(r.tag==="Just"){const o=Tr(ne,N,r._1,k(t,e),n);if(o.tag==="Nothing")return n;if(o.tag==="Just")return o._1;g()}if(r.tag==="Nothing")return Pt(n)(k(t,e));g()},Ib=t=>e=>$(n=>n._1===t?k(n._1,{...n._2,label:v("Just",e)}):k(n._1,n._2)),Ab=t=>{const e=t.span;return ke.state(n=>k(void 0,{...n,currentSpan:e}))},Db=t=>e=>({structural:[...t.structural,...e.structural],flow:t.flow||e.flow,dives:[...t.dives,...e.dives]}),ol={graphNodes:[],graphEdges:D,currNodes:D,currEdges:D,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:N,currentSpan:Gb,error:N,enterStack:[],interiorOf:D},Rr=t=>ke.state(e=>k(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:v("Just",{msg:t,line:e.currentSpan.line,column:e.currentSpan.column,endLine:e.currentSpan.endLine,endColumn:e.currentSpan.endColumn})};g()})())),Bb=qc(t=>$t.bind(He)(e=>{if(e.error.tag==="Just")return se.pure();if(e.error.tag==="Nothing")return tl(t.node)(e.interiorOf)?Rr("node "+t.node+" has more than one `inside` block"):ke.state(n=>k(void 0,{...n,interiorOf:j(I)(t.node)(t.doc)(n.interiorOf)}));g()})),Rb=t=>$t.bind(He)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ee(e.kfCounter);if(Ye(o=>o.id===n,e.keyframes))return Rr("duplicate frame name "+n);const r={...e,keyframes:Pt(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges,kind:ri}),kfCounter:e.kfCounter+1|0,currentKf:v("Just",n)};return ke.state(o=>k(void 0,r))}),sn=t=>e=>$t.bind(ke.state(n=>k(void 0,{...n,currentSpan:t})))(()=>Rr(e)),Qb=t=>$t.bind((()=>{const e=t.span;return ke.state(n=>k(void 0,{...n,currentSpan:e}))})())(()=>$t.bind(He)(e=>{if(e.error.tag==="Just")return se.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!jn(t.op._1.id)(e.currNodes))return sn(0<t.operands.length?t.operands[0]:t.span)("cannot dive into node "+t.op._1.id+": does not exist");if(!tl(t.op._1.id)(e.interiorOf))return sn(0<t.operands.length?t.operands[0]:t.span)("cannot enter node "+t.op._1.id+": it has no `inside` block. Add the block at the document level, alongside the animated statements:\n\ninside "+t.op._1.id+` {
|
|
9
|
+
+ detail: Detail
|
|
10
|
+
}`);const n=t.op._1;return ke.state(r=>k(void 0,{...r,enterStack:Pt(r.enterStack)(n.id),scenes:Pt(r.scenes)(ni("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=Hr(e.enterStack);if(n.tag==="Nothing")return Rr("`out` without a matching `into`");if(n.tag==="Just"){const r=n._1.init;return ke.state(o=>k(void 0,{...o,enterStack:r,scenes:Pt(o.scenes)(b0)}))}g()}return se.pure()}g()})),_u={structural:[],flow:!1,dives:[]},Fb=$t.bind(He)(t=>{if(t.error.tag==="Just")return se.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return ke.state(n=>k(void 0,{...n,scenes:Pt(n.scenes)(ni("Hold",e))}))}if(t.currentKf.tag==="Nothing")return se.pure()}g()}),zb=t=>e=>$t.bind(He)(n=>{const r="ev-"+ee(n.eventCounter);return $t.bind((()=>{const o={...n,eventCounter:n.eventCounter+1|0};return ke.state(i=>k(void 0,o))})())(()=>se.pure({events:[{id:r,kind:e,when:t}],firstId:v("Just",r),lastId:v("Just",r)}))}),Mb=t=>xt(e=>nl(e)(t.graphEdges))(qt(_o,yb(t.currEdges))),Hb=t=>e=>{const n=at(o=>o.from.node===e.id||o.to.node===e.id,Mb(t)),r=gu(_g)(o=>i=>{const s=i.from+"->"+e.id,u=e.id+"->"+i.to,a=i.from+"->"+i.to,c="via "+i.from+" "+i.to+": no edge "+i.from+"\u2192"+e.id;if(!Rn(s)(t.currEdges))return Rt("Left",c);const f="via "+i.from+" "+i.to+": no edge "+e.id+"\u2192"+i.to;if(!Rn(u)(t.currEdges))return Rt("Left",f);const d="via "+i.from+" "+i.to+": would create "+i.from+"\u2192"+i.to+" but it already exists";return Rn(a)(t.currEdges)||xb(a)(o.synthesized)?Rt("Left",d):Rt("Right",{consumed:j(I)(s)()(j(I)(u)()(o.consumed)),synthesized:j(I)(a)({id:a,from:{node:i.from,port:N},to:{node:i.to,port:N},label:N})(o.synthesized)})})({consumed:D,synthesized:D})(e.via);return(()=>{if(r.tag==="Left"){const o=r._1;return i=>Rt("Left",o)}if(r.tag==="Right"){const o=r._1;return i=>i(o)}g()})()(o=>{const i=o.consumed,s=at(u=>!Rn(u.id)(i),n);return s.length===0?Rt("Right",{nextCurrEdges:ze(I.compare,Qe,or(I.compare,t.currEdges,Jb($(u=>u.id)(n))),Nb((()=>{const u=a=>{if(a.tag==="Leaf")return D;if(a.tag==="Node")return Kt("Node",a._1,a._2,a._3,void 0,u(a._5),u(a._6));g()};return u(o.synthesized)})())),synthesized:o.synthesized}):Rt("Left","cannot delete node "+e.id+": still connected ("+fr(", ")($(u=>(()=>{const a=bo("conn:")(u.id);if(a.tag==="Just")return!1;if(a.tag==="Nothing")return!0;g()})()?u.from.node+"\u2192"+u.to.node:u.from.node+"--"+u.to.node)(s))+"). Use `- a -> b` or `- a -- b` to drop them, or `via a b` to merge "+e.id+"'s endpoints.")})},il=t=>e=>n=>{if(t){if(e){const i=0<n.operands.length?n.operands[0]:n.span,s=1<n.operands.length?n.operands[1]:n.span;return{line:i.line,column:i.column,endLine:s.endLine,endColumn:s.endColumn}}return 0<n.operands.length?n.operands[0]:n.span}if(e)return 1<n.operands.length?n.operands[1]:n.span;const r=0<n.operands.length?n.operands[0]:n.span,o=1<n.operands.length?n.operands[1]:n.span;return{line:r.line,column:r.column,endLine:o.endLine,endColumn:o.endColumn}},sl=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq"||t.tag==="GroupSeq")return Lt(t._1)(sl);g()},Ob=t=>({nodes:$(Qi)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Xt("Cons",n._4,e(n._6,r)));g()};return qt(ue.foldr,e(t.graphEdges,Ht))})(),constraints:[]}),Wc=t=>{if(t.tag==="Leaf")return t._1.op.tag==="AddNode"||t._1.op.tag==="DelNode"||t._1.op.tag==="ModNode"||t._1.op.tag==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?{..._u,structural:[t._1]}:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?{..._u,dives:[t._1]}:{..._u,flow:!0};if(t.tag==="Seq"||t.tag==="GroupSeq"||t.tag==="Par")return w(Db)(_u)($(Wc)(t._1));g()},du=t=>{if(t.tag==="Leaf")return t._1.op.tag==="AddNode"||t._1.op.tag==="DelNode"||t._1.op.tag==="ModNode"||t._1.op.tag==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?[ao("StepStructural",[t._1])]:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?[ao("StepDive",t._1)]:[ao("StepFlow",t)];if(t.tag==="Seq")return Lt(t._1)(du);if(t.tag==="GroupSeq")return $b(t)(t._1);if(t.tag==="Par")return qb(t)(t._1);g()},qb=t=>e=>{const n=Wc(t);return n.structural.length!==0&&!n.flow&&n.dives.length===0?[ao("StepStructural",n.structural)]:n.structural.length===0&&n.flow&&n.dives.length===0?[ao("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?$(rl)(n.dives):Lt(e)(du)},$b=t=>e=>{const n=Wc(t);return n.structural.length===0&&n.flow&&n.dives.length===0?[ao("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?$(rl)(n.dives):Lt(e)(du)},Wb=t=>e=>$t.bind(He)(n=>{const r=e.from+"->"+e.to,o=e.newFrom+"->"+e.newTo;return Rn(r)(n.currEdges)?jn(e.newFrom)(n.currNodes)?jn(e.newTo)(n.currNodes)?r!==o&&Rn(o)(n.currEdges)?sn((()=>{const i=2<t.operands.length?t.operands[2]:t.span,s=3<t.operands.length?t.operands[3]:t.span;return{line:i.line,column:i.column,endLine:s.endLine,endColumn:s.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists"):ke.state(i=>k(void 0,{...i,currEdges:j(I)(o)()(xo(I)(r)(i.currEdges)),graphEdges:j(I)(o)({id:o,from:{node:e.newFrom,port:N},to:{node:e.newTo,port:N},label:N})(i.graphEdges)})):sn(3<t.operands.length?t.operands[3]:t.span)("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo):sn(2<t.operands.length?t.operands[2]:t.span)("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newFrom):sn((()=>{const i=0<t.operands.length?t.operands[0]:t.span,s=1<t.operands.length?t.operands[1]:t.span;return{line:i.line,column:i.column,endLine:s.endLine,endColumn:s.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist")}),Yb=t=>{if(t.op.tag==="AddNode"){const e=t.op._1;return $t.bind(He)(n=>jn(e.id)(n.currNodes)?sn(0<t.operands.length?t.operands[0]:t.span)("cannot add node "+e.id+": already exists"):ke.state(r=>k(void 0,{...r,graphNodes:Pb(e.id)({id:e.id,size:k(1,1),ports:[],label:v("Just",e.label),shape:e.shape})(r.graphNodes),currNodes:j(I)(e.id)()(r.currNodes)})))}if(t.op.tag==="DelNode"){const e=t.op._1;return $t.bind(He)(n=>{if(!jn(e.id)(n.currNodes))return sn(0<t.operands.length?t.operands[0]:t.span)("cannot delete node "+e.id+": does not exist");const r=Hb(n)(e);if(r.tag==="Left")return sn(0<t.operands.length?t.operands[0]:t.span)(r._1);if(r.tag==="Right"){const o=r._1;return ke.state(i=>k(void 0,{...i,currNodes:xo(I)(e.id)(i.currNodes),currEdges:o.nextCurrEdges,graphEdges:ze(I.compare,Qe,o.synthesized,i.graphEdges)}))}g()})}if(t.op.tag==="ModNode"){const e=t.op._1;return $t.bind(He)(n=>{if(!jn(e.id)(n.currNodes))return sn(0<t.operands.length?t.operands[0]:t.span)("cannot modify node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=e.label._1;return ke.state(o=>k(void 0,{...o,graphNodes:Ib(e.id)(r)(o.graphNodes)}))}if(e.label.tag==="Nothing")return se.pure();g()})}if(t.op.tag==="AddEdge"){const e=t.op._1;return $t.bind(He)(n=>{const r=!jn(e.from)(n.currNodes),o=!jn(e.to)(n.currNodes);if(r||o)return sn(il(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 Rn(i)(n.currEdges)?sn((()=>{const s=0<t.operands.length?t.operands[0]:t.span,u=1<t.operands.length?t.operands[1]:t.span;return{line:s.line,column:s.column,endLine:u.endLine,endColumn:u.endColumn}})())((e.directed?"cannot add edge ":"cannot add connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": already exists"):ke.state(s=>k(void 0,{...s,graphEdges:j(I)(i)({id:i,from:{node:e.from,port:N},to:{node:e.to,port:N},label:e.label})(s.graphEdges),currEdges:j(I)(i)()(s.currEdges)}))})}if(t.op.tag==="DelEdge"){const e=t.op._1;return $t.bind(He)(n=>{const r=e.directed?e.from+"->"+e.to:e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;return Rn(r)(n.currEdges)?ke.state(o=>k(void 0,{...o,currEdges:xo(I)(r)(o.currEdges)})):sn((()=>{const o=0<t.operands.length?t.operands[0]:t.span,i=1<t.operands.length?t.operands[1]:t.span;return{line:o.line,column:o.column,endLine:i.endLine,endColumn:i.endColumn}})())((e.directed?"cannot delete edge ":"cannot delete connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": does not exist")})}return t.op.tag==="RepointEdge"?Wb(t)(t.op._1):se.pure()},Vb=t=>$t.bind((()=>{const e=t.span;return ke.state(n=>k(void 0,{...n,currentSpan:e}))})())(()=>Yb(t)),ul=t=>e=>n=>$t.bind(qc(Vb)(n))(()=>$t.bind(He)(r=>{const o=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ee(r.kfCounter);if(Ye(s=>s.id===o,r.keyframes))return $t.bind(wb(Ab)(0<n.length?v("Just",n[0]):N))(()=>Rr("duplicate frame name "+o));const i={...r,keyframes:Pt(r.keyframes)({id:o,nodes:r.currNodes,edges:r.currEdges,kind:t}),kfCounter:r.kfCounter+1|0,currentKf:v("Just",o),scenes:(()=>{if(r.currentKf.tag==="Nothing")return r.scenes;if(r.currentKf.tag==="Just")return Pt(r.scenes)(ni("Structural",{from:r.currentKf._1,to:o,focus:N}));g()})()};return ke.state(s=>k(void 0,i))})),al=t=>e=>{const n=sl(e.ops),r=at(i=>i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge",n),o=at(i=>!(i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge"),n);return 0<o.length?$t.bind((()=>{const i=o[0].span;return ke.state(s=>k(void 0,{...s,currentSpan:i}))})())(()=>Rr("still/title blocks hold a still snapshot; they cannot contain movement tokens (`api ~> db`) or dive commands (`into`/`out`)")):t==="TitleCard"&&r.length===0?Rr(e.name.tag==="Just"&&e.name._1!==""?'title "'+e.name._1+'" has an empty body; give it nodes/edges to title, or use a still':"title has an empty body; give it nodes/edges to title, or use a still"):$t.bind(ul(t)(e.name)(r))(()=>Fb)},Ub=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(Rn(r)(t.currEdges))return v("Just",{id:r,direction:jg});if(Rn(n)(t.currEdges))return v("Just",{id:n,direction:Zg});const i=nl(o)(t.graphEdges);if(i.tag==="Just")return Rn(o)(t.currEdges)?v("Just",{id:o,direction:i._1.from.node===e.from&&i._1.to.node===e.to?jg:Zg}):N;if(i.tag==="Nothing")return N;g()},Xb=t=>e=>{if(e.op.tag==="Token"){const n=e.op._1;return $t.bind(He)(r=>{const o=!jn(n.from)(r.currNodes),i=!jn(n.to)(r.currNodes);if(o||i)return $t.bind(sn(il(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: "))(()=>se.pure({events:[],firstId:N,lastId:N}));const s=Ub(r)(n);if(s.tag==="Just")return zb(t)(N0("SendToken",{from:n.from,to:n.to,edge:s._1.id,direction:s._1.direction,labels:n.labels}));if(s.tag==="Nothing")return $t.bind(sn((()=>{const u=0<e.operands.length?e.operands[0]:e.span,a=1<e.operands.length?e.operands[1]:e.span;return{line:u.line,column:u.column,endLine:a.endLine,endColumn:a.endColumn}})())("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>se.pure({events:[],firstId:N,lastId:N}));g()})}return se.pure({events:[],firstId:N,lastId:N})},Kb=t=>e=>{const n=Mt(r=>N,r=>o=>v("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return se.pure({events:[],firstId:N,lastId:N});if(n.tag==="Just"){const r=n._1.tail;return $t.bind(Ii(t)(n._1.head))(o=>$t.bind(gu({Applicative0:()=>uo(pn),Bind1:()=>so(pn)})(i=>s=>$t.bind(Ii((()=>{if(i.lastId.tag==="Just")return fa("After",i.lastId._1);if(i.lastId.tag==="Nothing")return t;g()})())(s))(u=>se.pure({events:[...i.events,...u.events],firstId:(()=>{if(i.firstId.tag==="Just")return v("Just",i.firstId._1);if(i.firstId.tag==="Nothing")return u.firstId;g()})(),lastId:(()=>{if(u.lastId.tag==="Just")return v("Just",u.lastId._1);if(u.lastId.tag==="Nothing")return i.lastId;g()})()})))(o)(r))(i=>se.pure(i)))}g()},jb=t=>e=>{const n=Mt(r=>N,r=>o=>v("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return se.pure({events:[],firstId:N,lastId:N});if(n.tag==="Just"){const r=n._1.tail;return $t.bind(Ii(t)(n._1.head))(o=>$t.bind(Zb((()=>{if(o.firstId.tag==="Just")return fa("With",o.firstId._1);if(o.firstId.tag==="Nothing")return t;g()})())(r))(i=>se.pure({events:[...o.events,...i.events],firstId:o.firstId,lastId:(()=>{if(o.lastId.tag==="Just")return v("Just",o.lastId._1);if(o.lastId.tag==="Nothing")return i.lastId;g()})()})))}g()},Ii=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return $t.bind((()=>{const r=n.span;return ke.state(o=>k(void 0,{...o,currentSpan:r}))})())(()=>Xb(t)(n))}if(e.tag==="Seq"||e.tag==="GroupSeq")return Kb(t)(e._1);if(e.tag==="Par")return jb(t)(e._1);g()},Zb=t=>gu({Applicative0:()=>uo(pn),Bind1:()=>so(pn)})(e=>n=>$t.bind(Ii(t)(n))(r=>se.pure({events:[...e.events,...r.events],firstId:(()=>{if(e.firstId.tag==="Just")return v("Just",e.firstId._1);if(e.firstId.tag==="Nothing")return r.firstId;g()})(),lastId:(()=>{if(r.lastId.tag==="Just")return v("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;g()})()})))({events:[],firstId:N,lastId:N}),tk=t=>$t.bind(He)(e=>{if(e.currentKf.tag==="Nothing")return Rr("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return $t.bind(Ii(T0)(t))(r=>$t.bind(He)(o=>{const i={...o,scenes:Pt(o.scenes)(ni("DataFlow",{keyframe:n,events:r.events,focus:N}))};return ke.state(s=>k(void 0,i))}))}g()}),ek=t=>e=>n=>{if(n.tag==="StepStructural")return $t.bind((()=>{const r=ul(ri)(e?N:t)(n._1);return n._1.length!==0?r:se.pure()})())(()=>se.pure(!0));if(n.tag==="StepFlow"){const r=n._1,o=!e&&(()=>{if(t.tag==="Just")return t._1!=="";if(t.tag==="Nothing")return!1;g()})();return $t.bind((()=>{const i=Rb(t);return o?i:se.pure()})())(()=>$t.bind(tk(r))(()=>se.pure(e||o)))}if(n.tag==="StepDive")return $t.bind(Qb(n._1))(()=>se.pure(e));g()},cl=t=>e=>n=>{const r=Mt(o=>N,o=>i=>v("Just",{head:o,tail:i}),n);if(r.tag==="Nothing")return se.pure();if(r.tag==="Just"){const o=r._1.head,i=r._1.tail;return $t.bind(He)(s=>{if(s.error.tag==="Just")return se.pure();if(s.error.tag==="Nothing")return $t.bind(ek(t)(e)(o))(u=>cl(t)(u)(i));g()})}g()},nk=t=>$t.bind(He)(e=>{if(e.error.tag==="Just")return se.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return cl(t.name)(!1)(du(t.ops));if(t.kind==="Still")return al(w0)(t);if(t.kind==="Title")return al(v0)(t)}g()}),gl=t=>$t.bind(Bb(t.interiors))(()=>$t.bind(qc(nk)(t.frames))(()=>$t.bind(He)(e=>{if(e.error.tag==="Just")return se.pure(Rt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=rk(t.interiors);if(n.tag==="Left")return se.pure(Rt("Left",n._1));if(n.tag==="Right")return se.pure(Rt("Right",{seed:t.seed,graph:Ob(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1}))}g()}))),rk=t=>{const e=gu(_g)(n=>r=>{const o=gl(r.doc)(ol)._1;return(()=>{if(o.tag==="Left"){const i=o._1;return s=>Rt("Left",i)}if(o.tag==="Right"){const i=o._1;return s=>s(i)}g()})()(i=>Rt("Right",j(I)(r.node)(i)(n)))})(D)(t);if(e.tag==="Left")return Rt("Left",e._1);if(e.tag==="Right")return Rt("Right",e._1);g()},Zn=(t,e)=>({tag:"ParseError",_1:t,_2:e}),L=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),lu=(t,e,n)=>({tag:t,_1:e,_2:n}),ok=t=>lu("More",t),ik=t=>lu("Lift",t),sk={defer:t=>{const e=Yp(t);return(n,r,o,i,s)=>Vp(e)(n,r,o,i,s)}},fl={map:t=>e=>(n,r,o,i,s)=>r(u=>e(n,r,o,i,(a,c)=>r(f=>s(a,t(c)))))},uk={alt:t=>e=>(n,r,o,i,s)=>{const u=n._1,a=n._2;return r(c=>t(L(u,a,!1),r,o,(f,d)=>{const l=f._3;return r(_=>l?i(f,d):e(n,r,o,i,s))},s))},Functor0:()=>fl},ak=t=>{const e=t.Monad0();return n=>r=>{const o=i=>{let s=i,u=!0,a;for(;u;){const c=s();if(c.tag==="More"){s=c._1;continue}if(c.tag==="Lift"){u=!1,a=e.Bind1().Apply0().Functor0().map(Du)(c._1);continue}if(c.tag==="Stop"){u=!1,a=e.Applicative0().pure(fo("Done",k(c._2,c._1)));continue}g()}return a};return t.tailRecM(o)(i=>r(n,ok,ik,(s,u)=>lu("Stop",s,Rt("Left",u)),(s,u)=>lu("Stop",s,Rt("Right",u))))}},Nr=(t,e,n,r,o)=>o(t,t._2),ck={index:0,line:1,column:1},gk=(t=>{const e=ak(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(Fi)(e(L(n,ck,!1))(r))})(wh),hu=(t,e,n,r,o)=>o(L(t._1,t._2,!0),void 0),_l={apply:t=>e=>(n,r,o,i,s)=>r(u=>t(n,r,o,i,(a,c)=>r(f=>{const d=n._3&&!a._3?L(a._1,a._2,!0):a;return e(d,r,o,i,(l,_)=>r(h=>s(d._3&&!l._3?L(l._1,l._2,!0):l,c(_))))}))),Functor0:()=>fl},dl={pure:t=>(e,n,r,o,i)=>i(e,t),Apply0:()=>_l},fk={bind:t=>e=>(n,r,o,i,s)=>r(u=>t(n,r,o,i,(a,c)=>r(f=>e(c)(n._3&&!a._3?L(a._1,a._2,!0):a,r,o,i,s)))),Apply0:()=>_l},_k={Applicative0:()=>dl,Bind1:()=>fk},pu=t=>(e,n,r,o,i)=>n(s=>Nr(e,n,r,o,(u,a)=>n(c=>o(e._3&&!u._3?L(u._1,u._2,!0):u,Zn(t,a))))),dk={empty:pu("No alternative"),Alt0:()=>uk},lk={Applicative0:()=>dl,Plus1:()=>dk},wn=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return o=>t.tailRecM(i=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(Du)(o))(r.pure(fo("Done",void 0))))(s=>r.pure((()=>{if(s.tag==="Loop")return fo("Loop",Xt("Cons",s._1,i));if(s.tag==="Done")return fo("Done",(u=>a=>{let c=u,f=a,d=!0,l;for(;d;){const _=c,h=f;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=Xt("Cons",h._1,_),f=h._2;continue}g()}return l})(Ht)(i));g()})())))(Ht)})({tailRecM:t=>e=>(n,r,o,i,s)=>{const u=(a,c,f)=>t(c)(a,r,o,i,(d,l)=>{const _=a._3&&!d._3?L(d._1,d._2,!0):d;if(l.tag==="Loop")return f===0?r(h=>u(_,l._1,30)):u(_,l._1,f-1|0);if(l.tag==="Done")return s(_,l._1);g()});return u(n,e,30)},Monad0:()=>_k})(lk),dt=t=>e=>{const n=pu("Expected "+e);return(r,o,i,s,u)=>{const a=r._1,c=r._2;return o(f=>t(L(a,c,!1),o,i,(d,l)=>{const _=d._3;return o(h=>_?s(d,l):n(r,o,i,s,u))},u))}},Wo=t=>(e,n,r,o,i)=>{const s=e._3,u=e._1,a=e._2;return n(c=>{const f=(d,l)=>{const _=d._3;return n(h=>_?o(L(d._1,d._2,s),l):i(e,void 0))};return n(d=>n(l=>t(L(u,a,!1),n,r,(_,h)=>f(L(_._1,_._2,!1),h),(_,h)=>n(p=>n(m=>pu("Negated parser succeeded")(_,n,r,f,(x,J)=>n(y=>i(_._3&&!x._3?L(x._1,x._2,!0):x,J))))))))})},hk=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return v("Just",n);if(r.tag==="Just")return v("Just",(o,i,s,u,a)=>{const c=o._1,f=o._2;return i(d=>n(L(c,f,!1),i,s,(l,_)=>{const h=l._3;return i(p=>h?u(l,_):r._1(o,i,s,u,a))},a))});g()})(N);return n=>{const r=e(n);if(r.tag==="Nothing")return pu("No alternative");if(r.tag==="Just")return r._1;g()}},ll=t=>e=>n=>(r,o,i,s,u)=>o(a=>o(c=>o(f=>o(d=>t(r,o,i,s,(l,_)=>o(h=>o(p=>{const m=r._3&&!l._3?L(l._1,l._2,!0):l;return n(m,o,i,s,(x,J)=>o(y=>{const T=m._3&&!x._3?L(x._1,x._2,!0):x;return o(b=>o(C=>{const S=r._3&&!T._3?L(T._1,T._2,!0):T;return e(S,o,i,s,(E,F)=>o(O=>u(S._3&&!E._3?L(E._1,E._2,!0):E,J)))}))}))}))))))),Yc=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=Tm()(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)-br(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},pk=t=>e=>n=>{let r=t,o=e,i=n,s=!0,u;for(;s;){const a=r,c=o,f=i,d=as(c);if(d.tag==="Nothing"){s=!1,u=a;continue}if(d.tag==="Just"){r=d._1.tail===""?Yc(a)(d._1.head)(f):Yc(a)(d._1.head)(d._1.tail),o=d._1.tail,i=f;continue}g()}return u},St=t=>(e,n,r,o,i)=>{const s=as(e._1);if(s.tag==="Nothing")return o(e,Zn("Unexpected EOF",e._2));if(s.tag==="Just"){if(s._1.head<0||s._1.head>65535)return o(e,Zn("Expected Char",e._2));if(s._1.head>=0&&s._1.head<=65535){const u=lf(s._1.head);return t(u)?i(L(s._1.tail,Yc(e._2)(s._1.head)(s._1.tail),!0),u):o(e,Zn("Predicate unsatisfied",e._2))}}g()},Ai=(t,e,n,r,o)=>t._1===""?o(L(t._1,t._2,!0),void 0):r(t,Zn("Expected EOF",t._2)),mk=t=>(e,n,r,o,i)=>{const s=t(e._1);if(s.tag==="Left")return o(e,Zn(s._1,e._2));if(s.tag==="Right")return i(L(s._1.remainder,pk(e._2)(s._1.consumed)(s._1.remainder),s._1.consumed!==""),s._1.value);g()},Ze=t=>mk(e=>{const n=bo(t)(e);return n.tag==="Just"?Rt("Right",{value:t,consumed:t,remainder:n._1}):Rt("Left","Expected "+ch(t))}),yk=St(t=>!0),Vc=(t,e)=>({tag:t,_1:e}),Uc=hk(zt),xk=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Jk=ae(I)(zt),Nk=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},Xc=(()=>{const t=dt(St(r=>r==="}"))("'}'"),e=dt(St(r=>r==="#"))("'#'"),n=St(r=>r===`
|
|
11
|
+
`||r==="\r");return(r,o,i,s,u)=>{const a=r._1,c=r._2;return o(f=>o(d=>t(L(a,c,!1),o,i,(l,_)=>o(h=>{const p=r._1,m=r._2;return o(x=>o(J=>e(L(p,m,!1),o,i,(y,T)=>o(b=>{const C=r._1,S=r._2;return o(E=>o(F=>n(L(C,S,!1),o,i,(O,G)=>o(A=>Ai(r,o,i,s,u)),(O,G)=>o(A=>u(L(C,S,!1),void 0)))))}),(y,T)=>o(b=>u(L(p,m,!1),void 0)))))}),(l,_)=>o(h=>u(L(a,c,!1),void 0)))))}})(),vn=t=>(e,n,r,o,i)=>n(s=>Nr(e,n,r,o,(u,a)=>n(c=>{const f=e._3&&!u._3?L(u._1,u._2,!0):u;return n(d=>t(f,n,r,o,(l,_)=>n(h=>{const p=f._3&&!l._3?L(l._1,l._2,!0):l;return n(m=>Nr(p,n,r,o,(x,J)=>n(y=>i(p._3&&!x._3?L(x._1,x._2,!0):x,k(_,{line:a.line,column:a.column,endLine:J.line,endColumn:J.column})))))})))}))),wk=(()=>{const t=St(e=>e===" "||e===" "||e===`
|
|
12
|
+
`||e==="\r");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(u,a)=>n(c=>i(e._3&&!u._3?L(u._1,u._2,!0):u,void 0))))})(),hl=(t,e,n,r,o)=>e(i=>Ze("#")(t,e,n,r,(s,u)=>e(a=>{const c=wn(St(d=>d!==`
|
|
13
|
+
`)),f=t._3&&!s._3?L(s._1,s._2,!0):s;return e(d=>c(f,e,n,r,(l,_)=>e(h=>o(f._3&&!l._3?L(l._1,l._2,!0):l,void 0))))}))),vk=dt((()=>{const t=dt(St(n=>n==="}"))("'}'"),e=St(n=>n===`
|
|
14
|
+
`||n==="\r");return(n,r,o,i,s)=>{const u=n._1,a=n._2;return r(c=>r(f=>t(L(u,a,!1),r,o,(d,l)=>r(_=>{const h=n._1,p=n._2;return r(m=>r(x=>hl(L(h,p,!1),r,o,(J,y)=>{const T=J._3;return r(b=>{if(T)return i(J,y);const C=n._1,S=n._2;return r(E=>r(F=>e(L(C,S,!1),r,o,(O,G)=>{const A=O._3;return r(K=>A?i(O,G):Ai(n,r,o,i,s))},(O,G)=>r(A=>s(O,void 0)))))})},(J,y)=>r(T=>s(J,void 0)))))}),(d,l)=>r(_=>s(L(u,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),dn=(()=>{const t=wn((e,n,r,o,i)=>{const s=e._1,u=e._2;return n(a=>wk(L(s,u,!1),n,r,(c,f)=>{const d=c._3;return n(l=>d?o(c,f):hl(e,n,r,o,i))},i))});return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(u,a)=>n(c=>i(e._3&&!u._3?L(u._1,u._2,!0):u,void 0))))})(),Tk=(()=>{const t=St(e=>e!=="|");return(e,n,r,o,i)=>{const s=e._1,u=e._2;return n(a=>n(c=>Ze("\\|")(L(s,u,!1),n,r,(f,d)=>n(l=>n(_=>t(e,n,r,o,(h,p)=>n(m=>i(h,Zo(p)))))),(f,d)=>n(l=>i(f,"|")))))}})(),bk=dt(Uc([(t,e,n,r,o)=>e(i=>{const s=t._3;return Ze("->")(t,e,n,(u,a)=>r(L(u._1,u._2,s),a),(u,a)=>e(c=>o(u,!0)))}),(t,e,n,r,o)=>e(i=>{const s=t._3;return Ze("--")(t,e,n,(u,a)=>r(L(u._1,u._2,s),a),(u,a)=>e(c=>o(u,!1)))})]))("edge arrow '->' or '--'"),kk=t=>t!==`
|
|
15
|
+
`&&t!=="\r"&&t!=="#"&&t!=="}"&&t!=="{",mu=St(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),Lk=t=>t===" "||t===" "||t==="\r",Ck=t=>kr(ge(Fn(Lk)(ge(ur(t))).rest)),Kc=t=>t===`
|
|
16
|
+
`||t==="\r"||t==="#"||t==="}",Sk=t=>t===`
|
|
17
|
+
`||t==="\r"||t==="#"||t==="}"||t==="{",Ek=t=>t!=="{"&&t!==`
|
|
18
|
+
`&&t!=="\r",pl=t=>us(t)==="",Gk=t=>ge(Fn(pl)(ge(Fn(pl)(t).rest)).rest),Pk=t=>(e=>n=>{let r=e,o=n,i=!0,s;for(;i;){const u=r,a=Mt(c=>N,c=>f=>v("Just",{head:c,tail:f}),o);if(a.tag==="Just"&&(a._1.head===" "||a._1.head===" ")){r=u+1|0,o=a._1.tail;continue}i=!1,s=u}return s})(0)(ur(t)),Ik=t=>{const e=Mt(n=>N,n=>r=>v("Just",{head:n,tail:r}),$(Pk)(at(n=>us(n)!=="",t)));if(e.tag==="Nothing")return 0;if(e.tag==="Just")return w(xk)(e._1.head)(e._1.tail);g()},Ak=(()=>{const t=dt(St(e=>e==="-"))("'-'");return(e,n,r,o,i)=>{const s=e._3;return n(u=>t(e,n,r,(a,c)=>o(L(a._1,a._2,s),c),(a,c)=>n(f=>{const d=Wo((()=>{const _=dt(St(p=>p===">"))("'>'"),h=dt(St(p=>p==="-"))("'-'");return(p,m,x,J,y)=>{const T=p._1,b=p._2;return m(C=>_(L(T,b,!1),m,x,(S,E)=>{const F=S._3;return m(O=>F?J(S,E):h(p,m,x,J,y))},y))}})()),l=e._3&&!a._3?L(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>o(L(h._1,h._2,s),p),(h,p)=>n(m=>i(l._3&&!h._3?L(h._1,h._2,!0):h,"-"))))})))}})(),jt=(()=>{const t=wn(St(e=>e===" "||e===" "));return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(u,a)=>n(c=>i(e._3&&!u._3?L(u._1,u._2,!0):u,void 0))))})(),co=(()=>{const t=St(e=>e===" "||e===" ");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(u,a)=>n(c=>jt(e._3&&!u._3?L(u._1,u._2,!0):u,n,r,o,i))))})(),ml=(t,e,n,r,o)=>e(i=>e(s=>jt(t,e,n,r,(u,a)=>e(c=>e(f=>{const d=t._3&&!u._3?L(u._1,u._2,!0):u;return Xc(d,e,n,r,(l,_)=>e(h=>o(d._3&&!l._3?L(l._1,l._2,!0):l,_)))}))))),yl=(t,e,n,r,o)=>e(i=>jt(t,e,n,r,(s,u)=>e(a=>{const c=dt(St(d=>d==="-"))("'-'"),f=t._3&&!s._3?L(s._1,s._2,!0):s;return e(d=>{const l=(p,m)=>e(x=>(()=>{if(m.tag==="Just")return(J,y,T,b,C)=>y(S=>bk(J,y,T,b,(E,F)=>y(O=>C(E,v("Just",F)))));if(m.tag==="Nothing")return(J,y,T,b,C)=>C(J,N);g()})()(f._3&&!p._3?L(p._1,p._2,!0):p,e,n,r,o)),_=f._1,h=f._2;return e(p=>e(m=>c(L(_,h,!1),e,n,(x,J)=>e(y=>l(f,N)),(x,J)=>e(y=>l(L(_,h,!1),v("Just",J))))))})}))),Dk=t=>{const e=bo("Expected ")(t),n=(()=>{if(e.tag==="Nothing")return t;if(e.tag==="Just")return e._1;g()})();return n==="'{'"?"Open the block with `{`.":n==="integer (seed value)"?"Put an integer after `seed`.":n==="closing '}'"?"Close this block with `}`.":n===`closing '"' (unterminated string)`?'This string is unterminated; close it with `"`.':n==="closing '|'"?"Close this pipe label with `|`.":n==="space after '+'"?"Put a space after `+`: `+ api: API`.":n==="node identifier after '+'"?"Put a node id after `+`: `+ api: API`.":n==="space after '-'"?"Put a space after `-`: `- api`.":n==="node identifier after '-'"?"Put a node id after `-`: `- api`.":n==="space after '~'"?"Put a space after `~`: `~ api -> db => api -> cache`.":n==="node identifier"?"Put a node identifier here.":n==="space after 'inside'"?"Put a space after `inside`: `inside api { ... }`.":n==="node identifier after 'inside'"?"Tell `inside` which node owns this interior: `inside api { ... }`.":n==="source node identifier after 'via'"?"Put the source node after `via`: `via a b`.":n==="target node identifier after 'via'"?"Put the second endpoint after `via`: `via a b`.":n==="source node identifier"?"Put a source node identifier here.":n==="new source node identifier"?"Put the new source node identifier after `=>`.":n==="new target node identifier"?"Put the new target node identifier after the replacement arrow.":n==="edge arrow '->' or '--'"?"Use `->` for a directed edge or `--` for an undirected edge.":n==="source edge arrow '->'"?"Use `->` in the edge you are changing: `~ api -> db => api -> cache`.":n==="replacement edge arrow '->'"?"Use `->` in the replacement edge: `~ api -> db => api -> cache`.":n==="repoint separator '=>'"?"Use `=>` before the replacement edge: `~ api -> db => api -> cache`.":n==="target node identifier"?"Put a target node after the arrow.":n==="'~>'"?"Use `~>` for movement from left to right.":n==="'<~'"?"Use `<~` for movement from right to left.":n==="'->' or '<-'"?"Use `~>` / `<~` for movement tokens.":n==='label ("\u2026", : rest-of-line, or |\u2026|)'?'label must use `: text`, `"text"`, or `|multi-line|`.':n==="attribute key"?"Start each attribute with a name, like `shape`.":n==="':'"?"Put `:` between the attribute name and value: `{shape: cylinder}`.":n==="attribute value"?"Put an attribute value after `:`.":n==="closing '}' for attributes"?"Close the attribute block with `}`.":n==="space after 'into'"?"Put a space after `into`: `into api`.":n==="node identifier after 'into'"?"Tell `into` which node to dive into.":n==="newline or '}' (statements end at the end of the line)"?"This statement has extra text. Put the next statement on a new line or close the block with `}`.":n==="statement (+ node, - node, + edge, - edge, into, out, or 'a ~> b'/'a <~ b')"?"I don't recognize this statement. Start with `+`, `-`, `~`, `into`, `out`, `par`, `seq`, or movement like `api ~> db`.":n==="'scene', 'still', 'title', 'inside', a statement, or end of input"?"Start with a statement like `+ api: API`, or a block with `scene`, `still`, `title`, or `inside`.":n},Bk=t=>{const e=us(t),n=bo('"')(e),r=(()=>{if(n.tag==="Just")return Wp('"')(n._1);if(n.tag==="Nothing")return N;g()})(),o=(()=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()})();return o===""?N:v("Just",o)},xl=t=>e=>t!=="AnimatedSurface"&&e.statements.length!==0?{...e,frames:Pt(e.frames)((()=>{if(t==="StillSurface")return{name:N,ops:Jr("Seq",e.statements),kind:$c};if(t==="SequenceSurface")return{name:N,ops:Jr("Seq",e.statements),kind:fu};if(t==="AnimatedSurface")return{name:N,ops:Jr("Seq",e.statements),kind:fu};g()})()),statements:[]}:e,Rk=(()=>{const t=dt(St(e=>e==="\\"))("'\\\\'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(u,a)=>n(c=>{const f=e._3&&!u._3?L(u._1,u._2,!0):u;return n(d=>yk(f,n,r,o,(l,_)=>n(h=>i(f._3&&!l._3?L(l._1,l._2,!0):l,_==="n"?`
|
|
19
|
+
`:_==="t"?" ":_==="r"?"\r":_))))})))})(),Qk=(()=>{const t=St(e=>e!=='"'&&e!=="\\"&&e!==`
|
|
20
|
+
`);return(e,n,r,o,i)=>{const s=e._1,u=e._2;return n(a=>Rk(L(s,u,!1),n,r,(c,f)=>n(d=>t(e,n,r,o,i)),i))}})(),Fk=(()=>{const t=dt(St(e=>e==='"'))(`'"'`);return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(u,a)=>n(c=>{const f=wn(Qk),d=e._3&&!u._3?L(u._1,u._2,!0):u;return n(l=>f(d,n,r,o,(_,h)=>n(p=>{const m=dt(dt(St(J=>J==='"'))(`'"'`))(`closing '"' (unterminated string)`),x=d._3&&!_._3?L(_._1,_._2,!0):_;return n(J=>m(x,n,r,o,(y,T)=>n(b=>i(x._3&&!y._3?L(y._1,y._2,!0):y,kr(qt(ue.foldr,h))))))})))})))})(),zk={frames:[],statements:[]},Mk=t=>{const e=Gk(si(`
|
|
21
|
+
`)(t));return fr(`
|
|
22
|
+
`)($(Ck)($(To(Ik(e)))(e)))},Hk=(()=>{const t=dt(St(e=>e==="|"))("'|'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(u,a)=>n(c=>{const f=wn(Tk),d=e._3&&!u._3?L(u._1,u._2,!0):u;return n(l=>f(d,n,r,o,(_,h)=>n(p=>{const m=dt(dt(St(J=>J==="|"))("'|'"))("closing '|'"),x=d._3&&!_._3?L(_._1,_._2,!0):_;return n(J=>m(x,n,r,o,(y,T)=>n(b=>i(x._3&&!y._3?L(y._1,y._2,!0):y,Mk(fr("")(qt(ue.foldr,h)))))))})))})))})(),Di=St(t=>t>="0"&&t<="9"),Ok=(()=>{const t=dt(St(e=>e==="_"))("'_'");return(e,n,r,o,i)=>{const s=e._1,u=e._2;return n(a=>mu(L(s,u,!1),n,r,(c,f)=>{const d=c._3;return n(l=>{if(d)return o(c,f);const _=e._1,h=e._2;return n(p=>Di(L(_,h,!1),n,r,(m,x)=>{const J=m._3;return n(y=>{if(J)return o(m,x);const T=e._1,b=e._2;return n(C=>t(L(T,b,!1),n,r,(S,E)=>{const F=S._3;return n(O=>F?o(S,E):Ak(e,n,r,o,i))},i))})},i))})},i))}})(),Re=(()=>{const t=dt(St(e=>e==="_"))("'_'");return(e,n,r,o,i)=>n(s=>{const u=(f,d)=>n(l=>{const _=wn(Ok),h=e._3&&!f._3?L(f._1,f._2,!0):f;return n(p=>_(h,n,r,o,(m,x)=>n(J=>i(h._3&&!m._3?L(m._1,m._2,!0):m,Zo(d)+kr(qt(ue.foldr,x))))))}),a=e._1,c=e._2;return n(f=>mu(L(a,c,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?o(d,l):t(e,n,r,o,u))},u))})})(),Jl=(t,e,n,r,o)=>e(i=>jt(t,e,n,r,(s,u)=>e(a=>{const c=dt(Re)("attribute key"),f=t._3&&!s._3?L(s._1,s._2,!0):s;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=f._3&&!l._3?L(l._1,l._2,!0):l;return e(m=>jt(p,e,n,r,(x,J)=>e(y=>{const T=dt(dt(St(C=>C===":"))("':'"))("':'"),b=p._3&&!x._3?L(x._1,x._2,!0):x;return e(C=>T(b,e,n,r,(S,E)=>e(F=>{const O=b._3&&!S._3?L(S._1,S._2,!0):S;return e(G=>jt(O,e,n,r,(A,K)=>e(U=>{const z=dt(Re)("attribute value"),H=O._3&&!A._3?L(A._1,A._2,!0):A;return e(M=>z(H,e,n,r,(P,R)=>e(Q=>{const B=H._3&&!P._3?L(P._1,P._2,!0):P;return e(q=>jt(B,e,n,r,(et,V)=>e(Y=>o(B._3&&!et._3?L(et._1,et._2,!0):et,k(_,R)))))})))})))})))})))})))}))),qk=ll((()=>{const t=dt(St(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(s=>n(u=>t(e,n,r,o,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?L(a._1,a._2,!0):a;return jt(l,n,r,o,(_,h)=>n(p=>i(l._3&&!_._3?L(_._1,_._2,!0):_,h)))})))))})())(dt((()=>{const t=dt(St(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(s=>n(u=>jt(e,n,r,o,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?L(a._1,a._2,!0):a;return t(l,n,r,o,(_,h)=>n(p=>i(l._3&&!_._3?L(_._1,_._2,!0):_,h)))})))))})())("closing '}' for attributes"))((()=>{const t=dt(St(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(s=>{const u=(f,d)=>n(l=>(()=>{if(d.tag==="Just")return(_,h,p,m,x)=>x(_,D);if(d.tag==="Nothing")return(_,h,p,m,x)=>h(J=>Jl(_,h,p,m,(y,T)=>h(b=>{const C=wn((()=>{const E=dt(St(F=>F===","))("','");return(F,O,G,A,K)=>{const U=F._3;return O(z=>O(H=>O(M=>O(P=>O(R=>O(Q=>jt(F,O,G,(B,q)=>A(L(B._1,B._2,U),q),(B,q)=>O(et=>O(V=>{const Y=F._3&&!B._3?L(B._1,B._2,!0):B;return E(Y,O,G,(W,X)=>A(L(W._1,W._2,U),X),(W,X)=>O(tt=>{const gt=Y._3&&!W._3?L(W._1,W._2,!0):W;return O(wt=>O(ct=>{const yt=F._3&&!gt._3?L(gt._1,gt._2,!0):gt;return jt(yt,O,G,(Ct,Vt)=>A(L(Ct._1,Ct._2,U),Vt),(Ct,Vt)=>O(mt=>{const Wt=yt._3&&!Ct._3?L(Ct._1,Ct._2,!0):Ct;return O(kt=>O(lt=>{const ft=F._3&&!Wt._3?L(Wt._1,Wt._2,!0):Wt;return Jl(ft,O,G,(ot,_t)=>A(L(ot._1,ot._2,U),_t),(ot,_t)=>O(st=>K(ft._3&&!ot._3?L(ot._1,ot._2,!0):ot,_t)))}))}))}))}))})))))))))}})()),S=_._3&&!y._3?L(y._1,y._2,!0):y;return h(E=>C(S,h,p,m,(F,O)=>h(G=>x(S._3&&!F._3?L(F._1,F._2,!0):F,Jk([T,...qt(ue.foldr,O)])))))})));g()})()(e._3&&!f._3?L(f._1,f._2,!0):f,n,r,o,i)),a=e._1,c=e._2;return n(f=>n(d=>t(L(a,c,!1),n,r,(l,_)=>n(h=>u(e,N)),(l,_)=>n(h=>u(L(a,c,!1),v("Just",_))))))})})()),$k=(t,e,n,r,o)=>e(i=>jt(t,e,n,r,(s,u)=>e(a=>{const c=dt(St(d=>d==="{"))("'{'"),f=t._3&&!s._3?L(s._1,s._2,!0):s;return e(d=>{const l=(p,m)=>e(x=>(()=>{if(m.tag==="Just")return qk;if(m.tag==="Nothing")return(J,y,T,b,C)=>C(J,D);g()})()(f._3&&!p._3?L(p._1,p._2,!0):p,e,n,r,o)),_=f._1,h=f._2;return e(p=>e(m=>c(L(_,h,!1),e,n,(x,J)=>e(y=>l(f,N)),(x,J)=>e(y=>l(L(_,h,!1),v("Just",J))))))})}))),Wk=t=>e=>n=>(r,o,i,s,u)=>o(a=>jt(r,o,i,s,(c,f)=>o(d=>{const l=vn(dt(Re)("target node identifier")),_=r._3&&!c._3?L(c._1,c._2,!0):c;return o(h=>l(_,o,i,s,(p,m)=>o(x=>u(_._3&&!p._3?L(p._1,p._2,!0):p,{op:Kn("DelEdge",{from:t,to:m._1,directed:n}),operands:[e,m._2]}))))}))),Yk=(t,e,n,r,o)=>e(i=>Nr(t,e,n,r,(s,u)=>e(a=>{const c=t._3&&!s._3?L(s._1,s._2,!0):s;return e(f=>{const d=c._3;return e(l=>Re(c,e,n,(_,h)=>r(L(_._1,_._2,d),h),(_,h)=>e(p=>{const m=c._3&&!_._3?L(_._1,_._2,!0):_;return e(x=>jt(m,e,n,(J,y)=>r(L(J._1,J._2,d),y),(J,y)=>e(T=>{const b=m._3&&!J._3?L(J._1,J._2,!0):J;return e(C=>{const S=(O,G)=>e(A=>{const K=b._3&&!O._3?L(O._1,O._2,!0):O;return e(U=>r(c._3&&!K._3?L(K._1,K._2,!0):K,Zn("Use `~>` / `<~` for movement tokens.",u)))}),E=b._1,F=b._2;return e(O=>Ze("->")(L(E,F,!1),e,n,(G,A)=>{const K=G._3;return e(U=>K?r(L(G._1,G._2,d),A):Ze("<-")(b,e,n,(z,H)=>r(L(z._1,z._2,d),H),S))},S))})})))})))})}))),Vk=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(u=>vn(Re)(t,e,n,(a,c)=>r(L(a._1,a._2,s),c),(a,c)=>e(f=>{const d=t._3&&!a._3?L(a._1,a._2,!0):a;return e(l=>jt(d,e,n,(_,h)=>r(L(_._1,_._2,s),h),(_,h)=>e(p=>{const m=dt(St(J=>J==="~"))("'~'"),x=d._3&&!_._3?L(_._1,_._2,!0):_;return e(J=>{const y=(C,S)=>e(E=>{const F=x._3&&!C._3?L(C._1,C._2,!0):C;return e(O=>{const G=c._1,A=c._2,K=t._3&&!F._3?L(F._1,F._2,!0):F;return e(U=>jt(K,e,n,r,(z,H)=>e(M=>{const P=dt(St(B=>B==="~"))("'~'"),R=dt(St(B=>B==="<"))("'<'"),Q=K._3&&!z._3?L(z._1,z._2,!0):z;return e(B=>{const q=(Y,W)=>e(X=>{const tt=W==="~"?dt(Ze("~>"))("'~>'"):dt(Ze("<~"))("'<~'"),gt=Q._3&&!Y._3?L(Y._1,Y._2,!0):Y;return e(wt=>tt(gt,e,n,r,(ct,yt)=>e(Ct=>o(gt._3&&!ct._3?L(ct._1,ct._2,!0):ct,k(G,k(A,yt))))))}),et=Q._1,V=Q._2;return e(Y=>P(L(et,V,!1),e,n,(W,X)=>{const tt=W._3;return e(gt=>tt?r(Q,X):R(Q,e,n,(wt,ct)=>r(Q,ct),(wt,ct)=>q(Q,ct)))},(W,X)=>q(Q,X)))})})))})}),T=x._1,b=x._2;return e(C=>m(L(T,b,!1),e,n,(S,E)=>{const F=S._3;return e(O=>F?r(L(x._1,x._2,s),E):e(G=>Ze("<~")(x,e,n,(A,K)=>r(L(x._1,x._2,s),K),(A,K)=>e(U=>y(x)))))},(S,E)=>y(x)))})})))})))}),Uk=(()=>{const t=dt(St(e=>e==="~"))("'~'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(u,a)=>n(c=>{const f=dt(co)("space after '~'"),d=e._3&&!u._3?L(u._1,u._2,!0):u;return n(l=>f(d,n,r,o,(_,h)=>n(p=>{const m=vn(dt(Re)("source node identifier")),x=d._3&&!_._3?L(_._1,_._2,!0):_;return n(J=>m(x,n,r,o,(y,T)=>n(b=>{const C=T._1,S=T._2,E=x._3&&!y._3?L(y._1,y._2,!0):y;return n(F=>jt(E,n,r,o,(O,G)=>n(A=>{const K=dt(Ze("->"))("source edge arrow '->'"),U=E._3&&!O._3?L(O._1,O._2,!0):O;return n(z=>K(U,n,r,o,(H,M)=>n(P=>{const R=U._3&&!H._3?L(H._1,H._2,!0):H;return n(Q=>jt(R,n,r,o,(B,q)=>n(et=>{const V=vn(dt(Re)("target node identifier")),Y=R._3&&!B._3?L(B._1,B._2,!0):B;return n(W=>V(Y,n,r,o,(X,tt)=>n(gt=>{const wt=tt._1,ct=tt._2,yt=Y._3&&!X._3?L(X._1,X._2,!0):X;return n(Ct=>jt(yt,n,r,o,(Vt,mt)=>n(Wt=>{const kt=dt(Ze("=>"))("repoint separator '=>'"),lt=yt._3&&!Vt._3?L(Vt._1,Vt._2,!0):Vt;return n(ft=>kt(lt,n,r,o,(ot,_t)=>n(st=>{const ut=lt._3&&!ot._3?L(ot._1,ot._2,!0):ot;return n(Jt=>jt(ut,n,r,o,(vt,At)=>n(Zt=>{const ln=vn(dt(Re)("new source node identifier")),Ae=ut._3&&!vt._3?L(vt._1,vt._2,!0):vt;return n(Qt=>ln(Ae,n,r,o,(Bt,De)=>n(hn=>{const We=De._1,en=De._2,Pe=Ae._3&&!Bt._3?L(Bt._1,Bt._2,!0):Bt;return n(te=>jt(Pe,n,r,o,(ce,gC)=>n(fC=>{const uC=dt(Ze("->"))("replacement edge arrow '->'"),oh=Pe._3&&!ce._3?L(ce._1,ce._2,!0):ce;return n(_C=>uC(oh,n,r,o,(Su,dC)=>n(lC=>{const ih=oh._3&&!Su._3?L(Su._1,Su._2,!0):Su;return n(hC=>jt(ih,n,r,o,(Eu,pC)=>n(mC=>{const aC=vn(dt(Re)("new target node identifier")),sh=ih._3&&!Eu._3?L(Eu._1,Eu._2,!0):Eu;return n(yC=>aC(sh,n,r,o,(Gu,uh)=>n(xC=>i(sh._3&&!Gu._3?L(Gu._1,Gu._2,!0):Gu,{op:Kn("RepointEdge",{from:C,to:wt,newFrom:We,newTo:uh._1}),operands:[S,ct,en,uh._2]}))))})))})))})))})))})))})))})))})))})))})))})))})))})))})))})(),Xk=(t,e,n,r,o)=>e(i=>Di(t,e,n,r,(s,u)=>e(a=>{const c=wn(Di),f=t._3&&!s._3?L(s._1,s._2,!0):s;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=op(Zo(u)+kr(qt(ue.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(x,J,y,T,b)=>b(x,m)}if(p.tag==="Nothing")return(m,x,J,y,T)=>T(m,0);g()})()(f._3&&!l._3?L(l._1,l._2,!0):l,e,n,r,o)})))}))),Kk=t=>(e,n,r,o,i)=>{const s=e._3;return n(u=>Ze(t)(e,n,r,(a,c)=>o(L(a._1,a._2,s),c),(a,c)=>n(f=>{const d=Wo((()=>{const _=dt(St(p=>p==="_"))("'_'"),h=dt(St(p=>p==="-"))("'-'");return(p,m,x,J,y)=>{const T=p._1,b=p._2;return m(C=>mu(L(T,b,!1),m,x,(S,E)=>{const F=S._3;return m(O=>{if(F)return J(S,E);const G=p._1,A=p._2;return m(K=>Di(L(G,A,!1),m,x,(U,z)=>{const H=U._3;return m(M=>{if(H)return J(U,z);const P=p._1,R=p._2;return m(Q=>_(L(P,R,!1),m,x,(B,q)=>{const et=B._3;return m(V=>et?J(B,q):h(p,m,x,J,y))},y))})},y))})},y))}})()),l=e._3&&!a._3?L(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>o(L(h._1,h._2,s),p),(h,p)=>n(m=>{const x=l._3&&!h._3?L(h._1,h._2,!0):h;return n(J=>dn(x,n,r,(y,T)=>o(L(y._1,y._2,s),T),(y,T)=>n(b=>i(x._3&&!y._3?L(y._1,y._2,!0):y,t))))})))})))},Tn=t=>(e,n,r,o,i)=>{const s=e._3;return n(u=>Ze(t)(e,n,r,(a,c)=>o(L(a._1,a._2,s),c),(a,c)=>n(f=>{const d=Wo((()=>{const _=dt(St(p=>p==="_"))("'_'"),h=dt(St(p=>p==="-"))("'-'");return(p,m,x,J,y)=>{const T=p._1,b=p._2;return m(C=>mu(L(T,b,!1),m,x,(S,E)=>{const F=S._3;return m(O=>{if(F)return J(S,E);const G=p._1,A=p._2;return m(K=>Di(L(G,A,!1),m,x,(U,z)=>{const H=U._3;return m(M=>{if(H)return J(U,z);const P=p._1,R=p._2;return m(Q=>_(L(P,R,!1),m,x,(B,q)=>{const et=B._3;return m(V=>et?J(B,q):h(p,m,x,J,y))},y))})},y))})},y))}})()),l=e._3&&!a._3?L(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>o(L(h._1,h._2,s),p),(h,p)=>n(m=>i(l._3&&!h._3?L(h._1,h._2,!0):h,void 0))))})))},jk=(t,e,n,r,o)=>e(i=>Tn("into")(t,e,n,r,(s,u)=>e(a=>{const c=dt(co)("space after 'into'"),f=t._3&&!s._3?L(s._1,s._2,!0):s;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=vn(dt(Re)("node identifier after 'into'")),m=f._3&&!l._3?L(l._1,l._2,!0):l;return e(x=>p(m,e,n,r,(J,y)=>e(T=>o(m._3&&!J._3?L(J._1,J._2,!0):J,{op:Kn("Enter",{id:y._1}),operands:[y._2]}))))})))}))),Zk=(t,e,n,r,o)=>e(i=>Tn("out")(t,e,n,r,(s,u)=>e(a=>o(t._3&&!s._3?L(s._1,s._2,!0):s,{op:kb,operands:[]})))),t5=(t,e,n,r,o)=>e(i=>Tn("seed")(t,e,n,r,(s,u)=>e(a=>{const c=t._3&&!s._3?L(s._1,s._2,!0):s;return e(f=>jt(c,e,n,r,(d,l)=>e(_=>{const h=dt(Xk)("integer (seed value)"),p=c._3&&!d._3?L(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(x,J)=>e(y=>{const T=p._3&&!x._3?L(x._1,x._2,!0):x;return e(b=>dn(T,e,n,r,(C,S)=>e(E=>o(T._3&&!C._3?L(C._1,C._2,!0):C,J))))})))})))}))),Nl=(t,e,n,r,o)=>{const i=t._3;return e(s=>Tn("diagram")(t,e,n,(u,a)=>r(L(u._1,u._2,i),a),(u,a)=>e(c=>{const f=dt(co)("space after 'diagram'"),d=t._3&&!u._3?L(u._1,u._2,!0):u;return e(l=>f(d,e,n,(_,h)=>r(L(_._1,_._2,i),h),(_,h)=>e(p=>{const m=dt(Tn("sequence"))("diagram mode"),x=d._3&&!_._3?L(_._1,_._2,!0):_;return e(J=>m(x,e,n,(y,T)=>r(L(y._1,y._2,i),T),(y,T)=>e(b=>{const C=x._3&&!y._3?L(y._1,y._2,!0):y;return e(S=>ml(C,e,n,(E,F)=>r(L(E._1,E._2,i),F),(E,F)=>e(O=>o(C._3&&!E._3?L(E._1,E._2,!0):E,bb))))})))})))})))},wl=(t,e,n,r,o)=>{const i=t._3;return e(s=>Tn("still")(t,e,n,(u,a)=>r(L(u._1,u._2,i),a),(u,a)=>e(c=>{const f=t._3&&!u._3?L(u._1,u._2,!0):u;return e(d=>ml(f,e,n,(l,_)=>r(L(l._1,l._2,i),_),(l,_)=>e(h=>o(f._3&&!l._3?L(l._1,l._2,!0):l,Tb))))})))},vl=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(u=>wl(L(i,s,!1),e,n,(a,c)=>{const f=a._3;return e(d=>f?r(a,c):Nl(t,e,n,r,o))},o))},e5=t=>(e,n,r,o,i)=>n(s=>Nr(e,n,r,o,(u,a)=>n(c=>{const f=e._3&&!u._3?L(u._1,u._2,!0):u;return n(d=>{const l=f._3;return vl(f,n,r,(_,h)=>o(L(_._1,_._2,l),h),(_,h)=>n(p=>o(f._3&&!_._3?L(_._1,_._2,!0):_,Zn((()=>{if(t==="AnimatedSurface")return"Put diagram mode headers at the top of the document.";if(t==="AnimatedSurface")return"This document already declares `animation`; choose one diagram mode.";if(t==="StillSurface")return"This document already declares `still`; choose one diagram mode.";if(t==="SequenceSurface")return"This document already declares `diagram sequence`; choose one diagram mode.";g()})(),a))))})}))),n5=t=>(e,n,r,o,i)=>n(s=>Nr(e,n,r,o,(u,a)=>n(c=>{const f=e._3&&!u._3?L(u._1,u._2,!0):u;return n(d=>{const l=(p,m)=>n(x=>(()=>{if(m.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.";g()})();return(y,T,b,C,S)=>C(y,Zn(J,a))}if(m.tag==="Nothing")return(J,y,T,b,C)=>C(J,void 0);g()})()(f._3&&!p._3?L(p._1,p._2,!0):p,n,r,o,i)),_=f._1,h=f._2;return n(p=>n(m=>vl(L(_,h,!1),n,r,(x,J)=>{const y=x._3;return n(T=>y?o(x,J):l(f,N))},(x,J)=>n(y=>l(x,v("Just",J))))))})}))),r5=(t,e,n,r,o)=>e(i=>{const s=(c,f)=>e(d=>{const l=t._3&&!c._3?L(c._1,c._2,!0):c;return e(_=>dn(l,e,n,r,(h,p)=>e(m=>{const x=l._3&&!h._3?L(h._1,h._2,!0):h;return e(J=>n5(f)(x,e,n,r,(y,T)=>e(b=>o(x._3&&!y._3?L(y._1,y._2,!0):y,f))))})))}),u=t._1,a=t._2;return e(c=>wl(L(u,a,!1),e,n,(f,d)=>{const l=f._3;return e(_=>l?r(f,d):Nl(t,e,n,r,s))},s))}),o5=(t,e,n,r,o)=>e(i=>{const s=(c,f)=>e(d=>o(c,(()=>{if(f.tag==="Nothing")return vb;if(f.tag==="Just")return f._1;g()})())),u=t._1,a=t._2;return e(c=>e(f=>r5(L(u,a,!1),e,n,(d,l)=>{const _=d._3;return e(h=>_?r(d,l):s(t,N))},(d,l)=>e(_=>s(d,v("Just",l))))))}),i5=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(u=>jt(t,e,n,(a,c)=>r(L(a._1,a._2,s),c),(a,c)=>e(f=>Tn("via")(t._3&&!a._3?L(a._1,a._2,!0):a,e,n,(d,l)=>r(L(d._1,d._2,s),l),(d,l)=>e(_=>{const h=t._3&&!d._3?L(d._1,d._2,!0):d;return e(p=>hu(h,e,n,r,(m,x)=>e(J=>{const y=h._3&&!m._3?L(m._1,m._2,!0):m;return e(T=>co(y,e,n,r,(b,C)=>e(S=>{const E=dt(Re)("source node identifier after 'via'"),F=y._3&&!b._3?L(b._1,b._2,!0):b;return e(O=>E(F,e,n,r,(G,A)=>e(K=>{const U=F._3&&!G._3?L(G._1,G._2,!0):G;return e(z=>jt(U,e,n,r,(H,M)=>e(P=>{const R=dt(Re)("target node identifier after 'via'"),Q=U._3&&!H._3?L(H._1,H._2,!0):H;return e(B=>R(Q,e,n,r,(q,et)=>e(V=>o(Q._3&&!q._3?L(q._1,q._2,!0):q,{from:A,to:et}))))})))})))})))})))})))))}),s5=t=>e=>{const n=wn(i5);return(r,o,i,s,u)=>o(a=>n(r,o,i,s,(c,f)=>o(d=>u(r._3&&!c._3?L(c._1,c._2,!0):c,{op:Kn("DelNode",{id:t,via:qt(ue.foldr,f)}),operands:[e]}))))},u5=(()=>{const t=dt(St(e=>e==="-"))("'-'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(u,a)=>n(c=>{const f=dt(co)("space after '-'"),d=e._3&&!u._3?L(u._1,u._2,!0):u;return n(l=>f(d,n,r,o,(_,h)=>n(p=>{const m=vn(dt(Re)("node identifier after '-'")),x=d._3&&!_._3?L(_._1,_._2,!0):_;return n(J=>m(x,n,r,o,(y,T)=>n(b=>{const C=T._1,S=T._2,E=x._3&&!y._3?L(y._1,y._2,!0):y;return n(F=>yl(E,n,r,o,(O,G)=>n(A=>(()=>{if(G.tag==="Just")return Wk(C)(S)(G._1);if(G.tag==="Nothing")return s5(C)(S);g()})()(E._3&&!O._3?L(O._1,O._2,!0):O,n,r,o,i))))})))})))})))})(),tr=t=>e=>(n,r,o,i,s)=>r(u=>Nr(n,r,o,i,(a,c)=>r(f=>{const d=n._3&&!a._3?L(a._1,a._2,!0):a;return r(l=>Tn(t)(d,r,o,i,(_,h)=>r(p=>i(d._3&&!_._3?L(_._1,_._2,!0):_,Zn(e,c)))))}))),a5=(()=>{const t=dt(St(e=>e===":"))("':'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(u,a)=>n(c=>{const f=e._3&&!u._3?L(u._1,u._2,!0):u;return n(d=>jt(f,n,r,o,(l,_)=>n(h=>{const p=wn(St(kk)),m=f._3&&!l._3?L(l._1,l._2,!0):l;return n(x=>p(m,n,r,o,(J,y)=>n(T=>i(m._3&&!J._3?L(J._1,J._2,!0):J,us(kr(qt(ue.foldr,y)))))))})))})))})(),c5=(t,e,n,r,o)=>e(i=>jt(t,e,n,r,(s,u)=>e(a=>dt((c,f,d,l,_)=>{const h=c._1,p=c._2;return f(m=>a5(L(h,p,!1),f,d,(x,J)=>{const y=x._3;return f(T=>{if(y)return l(x,J);const b=c._1,C=c._2;return f(S=>Hk(L(b,C,!1),f,d,(E,F)=>{const O=E._3;return f(G=>O?l(E,F):Fk(c,f,d,l,_))},_))})},_))})('label ("\u2026", : rest-of-line, or |\u2026|)')(t._3&&!s._3?L(s._1,s._2,!0):s,e,n,r,o)))),yu=t=>(e,n,r,o,i)=>n(s=>jt(e,n,r,o,(u,a)=>n(c=>{const f=e._3&&!u._3?L(u._1,u._2,!0):u;return n(d=>{const l=(p,m)=>n(x=>(m?((J,y,T,b,C)=>C(J,N)):(J,y,T,b,C)=>y(S=>c5(J,y,T,b,(E,F)=>y(O=>C(E,v("Just",F))))))(f._3&&!p._3?L(p._1,p._2,!0):p,n,r,o,i)),_=f._1,h=f._2;return n(p=>{const m=(x,J)=>{const y=x._3;return n(T=>y?o(x,J):l(f,!1))};return n(x=>n(J=>n(y=>Ai(L(_,h,!1),n,r,(T,b)=>{const C=T._3;return n(S=>C?m(L(_,h,!1),b):n(E=>St(t)(L(_,h,!1),n,r,(F,O)=>m(L(_,h,!1),O),(F,O)=>n(G=>n(A=>l(L(_,h,!1),!0))))))},(T,b)=>n(C=>n(S=>l(L(_,h,!1),!0)))))))})})}))),g5=t=>e=>n=>(r,o,i,s,u)=>o(a=>jt(r,o,i,s,(c,f)=>o(d=>{const l=vn(dt(Re)("target node identifier")),_=r._3&&!c._3?L(c._1,c._2,!0):c;return o(h=>l(_,o,i,s,(p,m)=>o(x=>{const J=m._1,y=m._2,T=_._3&&!p._3?L(p._1,p._2,!0):p;return o(b=>yu(Kc)(T,o,i,s,(C,S)=>o(E=>u(T._3&&!C._3?L(C._1,C._2,!0):C,{op:Kn("AddEdge",{from:t,to:J,label:S.tag==="Just"?v("Just",S._1):N,directed:n}),operands:[e,y]}))))})))}))),f5=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(u=>vn(Re)(t,e,n,(a,c)=>r(L(a._1,a._2,s),c),(a,c)=>e(f=>{const d=t._3&&!a._3?L(a._1,a._2,!0):a;return e(l=>jt(d,e,n,(_,h)=>r(L(_._1,_._2,s),h),(_,h)=>e(p=>{const m=dt(St(J=>J==="<"))("'<'"),x=d._3&&!_._3?L(_._1,_._2,!0):_;return e(J=>m(x,e,n,(y,T)=>r(L(x._1,x._2,s),T),(y,T)=>e(b=>{const C=Wo((E,F,O,G,A)=>{const K=E._3;return Ze("<-")(E,F,O,(U,z)=>G(L(U._1,U._2,K),z),A)}),S=x._3&&!x._3?L(x._1,x._2,!0):x;return e(E=>C(S,e,n,(F,O)=>r(L(F._1,F._2,s),O),(F,O)=>e(G=>{const A=S._3&&!F._3?L(F._1,F._2,!0):F;return e(K=>{const U=c._1,z=c._2,H=t._3&&!A._3?L(A._1,A._2,!0):A;return e(M=>jt(H,e,n,r,(P,R)=>e(Q=>{const B=dt(Ze("<~"))("'<~'"),q=H._3&&!P._3?L(P._1,P._2,!0):P;return e(et=>B(q,e,n,r,(V,Y)=>e(W=>{const X=q._3&&!V._3?L(V._1,V._2,!0):V;return e(tt=>jt(X,e,n,r,(gt,wt)=>e(ct=>{const yt=vn(dt(Re)("target node identifier")),Ct=X._3&&!gt._3?L(gt._1,gt._2,!0):gt;return e(Vt=>yt(Ct,e,n,r,(mt,Wt)=>e(kt=>{const lt=Wt._1,ft=Wt._2,ot=Ct._3&&!mt._3?L(mt._1,mt._2,!0):mt;return e(_t=>yu(Kc)(ot,e,n,r,(st,ut)=>e(Jt=>o(ot._3&&!st._3?L(st._1,st._2,!0):st,{op:Kn("Token",{from:lt,to:U,labels:(()=>{if(ut.tag==="Nothing")return[];if(ut.tag==="Just")return[ut._1];g()})()}),operands:[ft,z]}))))})))})))})))})))})})))})))})))})))}),_5=(t,e,n,r,o)=>e(i=>Vk(t,e,n,r,(s,u)=>e(a=>{const c=u._2._2,f=u._1,d=u._2._1,l=t._3&&!s._3?L(s._1,s._2,!0):s;return e(_=>jt(l,e,n,r,(h,p)=>e(m=>{const x=vn(dt(Re)("target node identifier")),J=l._3&&!h._3?L(h._1,h._2,!0):h;return e(y=>x(J,e,n,r,(T,b)=>e(C=>{const S=b._1,E=b._2,F=J._3&&!T._3?L(T._1,T._2,!0):T;return e(O=>yu(Kc)(F,e,n,r,(G,A)=>e(K=>(c==="<~"?((U,z,H,M,P)=>P(U,{op:Kn("Token",{from:S,to:f,labels:(()=>{if(A.tag==="Nothing")return[];if(A.tag==="Just")return[A._1];g()})()}),operands:c==="<~"?[E,d]:[d,E]})):(U,z,H,M,P)=>P(U,{op:Kn("Token",{from:f,to:S,labels:(()=>{if(A.tag==="Nothing")return[];if(A.tag==="Just")return[A._1];g()})()}),operands:c==="<~"?[E,d]:[d,E]}))(F._3&&!G._3?L(G._1,G._2,!0):G,e,n,r,o))))})))})))}))),d5=(t,e,n,r,o)=>e(i=>yu(Sk)(t,e,n,r,(s,u)=>e(a=>o(s,(()=>{if(u.tag==="Nothing")return"";if(u.tag==="Just")return u._1;g()})())))),l5=t=>e=>(n,r,o,i,s)=>r(u=>d5(n,r,o,i,(a,c)=>r(f=>{const d=n._3&&!a._3?L(a._1,a._2,!0):a;return r(l=>$k(d,r,o,i,(_,h)=>r(p=>s(d._3&&!_._3?L(_._1,_._2,!0):_,{op:Kn("AddNode",{id:t,label:c,shape:(()=>{const m=Nk("shape")(h);if(m.tag==="Just")return m._1==="rectangle"||m._1==="rect"?Lr:m._1==="cylinder"||m._1==="cyl"?i0:m._1==="parallelogram"?s0:m._1==="diamond"?u0:m._1==="ellipse"?a0:m._1==="document"||m._1==="doc"?c0:m._1==="cloud"?g0:Lr;if(m.tag==="Nothing")return Lr;g()})()}),operands:[e]}))))}))),h5=(()=>{const t=dt(St(e=>e==="+"))("'+'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(u,a)=>n(c=>{const f=dt(co)("space after '+'"),d=e._3&&!u._3?L(u._1,u._2,!0):u;return n(l=>f(d,n,r,o,(_,h)=>n(p=>{const m=vn(dt(Re)("node identifier after '+'")),x=d._3&&!_._3?L(_._1,_._2,!0):_;return n(J=>m(x,n,r,o,(y,T)=>n(b=>{const C=T._1,S=T._2,E=x._3&&!y._3?L(y._1,y._2,!0):y;return n(F=>yl(E,n,r,o,(O,G)=>n(A=>(()=>{if(G.tag==="Just")return g5(C)(S)(G._1);if(G.tag==="Nothing")return l5(C)(S);g()})()(E._3&&!O._3?L(O._1,O._2,!0):O,n,r,o,i))))})))})))})))})(),p5=(t,e,n,r,o)=>e(i=>Nr(t,e,n,r,(s,u)=>e(a=>{const c=dt(Uc([tr("+node")("Node additions use `+ api: API`."),tr("+edge")("Graph edges use `+ api -> db`."),tr("+conn")("Undirected graph edges use `+ api -- db`."),tr("-node")("Node removals use `- api`."),tr("-edge")("Graph edge removals use `- api -> db`."),tr("-conn")("Undirected graph edge removals use `- api -- db`."),tr("~edge")("Graph edge repoints use `~ api -> db => api -> cache`."),tr("enter")("Dive commands use `into api`."),tr("exit")("Return from a dive with `out`."),Yk,h5,u5,Uk,_5,f5,jk,Zk]))("statement (+ node, - node, + edge, - edge, into, out, or 'a ~> b'/'a <~ b')"),f=t._3&&!s._3?L(s._1,s._2,!0):s;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=f._3&&!l._3?L(l._1,l._2,!0):l;return e(m=>Nr(p,e,n,r,(x,J)=>e(y=>{const T={line:u.line,column:u.column,endLine:J.line,endColumn:J.column};return o(p._3&&!x._3?L(x._1,x._2,!0):x,Jr("Leaf",{op:_.op,line:T.line,column:T.column,endLine:T.endLine,endColumn:T.endColumn,span:T,operands:_.operands}))})))})))}))),jc=ll((()=>{const t=dt(St(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(s=>n(u=>t(e,n,r,o,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?L(a._1,a._2,!0):a;return dn(l,n,r,o,(_,h)=>n(p=>i(l._3&&!_._3?L(_._1,_._2,!0):_,h)))})))))})())(dt((()=>{const t=dt(St(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(s=>n(u=>dn(e,n,r,o,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?L(a._1,a._2,!0):a;return t(l,n,r,o,(_,h)=>n(p=>i(l._3&&!_._3?L(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),Tl=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(u=>dn(t,e,n,(a,c)=>r(L(a._1,a._2,s),c),(a,c)=>e(f=>{const d=Wo(dt(St(_=>_==="}"))("'}'")),l=t._3&&!a._3?L(a._1,a._2,!0):a;return e(_=>d(l,e,n,(h,p)=>r(L(h._1,h._2,s),p),(h,p)=>e(m=>Wo(Ai)(l._3&&!h._3?L(h._1,h._2,!0):h,e,n,(x,J)=>r(L(x._1,x._2,s),J),(x,J)=>e(y=>{const T=t._3&&!x._3?L(x._1,x._2,!0):x;return e(b=>hu(T,e,n,r,(C,S)=>e(E=>{const F=Uc([y5,m5,p5]),O=T._3&&!C._3?L(C._1,C._2,!0):C;return e(G=>F(O,e,n,r,(A,K)=>e(U=>{const z=O._3&&!A._3?L(A._1,A._2,!0):A;return e(H=>jt(z,e,n,r,(M,P)=>e(R=>{const Q=z._3&&!M._3?L(M._1,M._2,!0):M;return e(B=>vk(Q,e,n,r,(q,et)=>e(V=>{const Y=Q._3&&!q._3?L(q._1,q._2,!0):q;return e(W=>dn(Y,e,n,r,(X,tt)=>e(gt=>o(Y._3&&!X._3?L(X._1,X._2,!0):X,K))))})))})))})))})))})))))})))}),m5=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(u=>{const a=(c,f)=>{const d=c._3;return e(l=>d?r(c,f):e(_=>{const h=t._3;return e(p=>Tn("seq")(t,e,n,(m,x)=>r(L(m._1,m._2,h),x),(m,x)=>e(J=>{const y=t._3&&!m._3?L(m._1,m._2,!0):m;return e(T=>jt(y,e,n,(b,C)=>r(L(b._1,b._2,h),C),(b,C)=>e(S=>Xc(y._3&&!b._3?L(b._1,b._2,!0):b,e,n,(E,F)=>r(L(E._1,E._2,h),F),(E,F)=>e(O=>{const G=t._3&&!E._3?L(E._1,E._2,!0):E;return e(A=>hu(G,e,n,r,(K,U)=>e(z=>{const H=dt(dt(St(P=>P==="{"))("'{'"))("'{'"),M=G._3&&!K._3?L(K._1,K._2,!0):K;return e(P=>H(M,e,n,r,(R,Q)=>e(B=>o(M._3&&!R._3?L(R._1,R._2,!0):R,Jr("GroupSeq",[])))))})))})))))})))}))};return e(c=>e(f=>Tn("seq")(L(i,s,!1),e,n,(d,l)=>a(L(d._1,d._2,!1),l),(d,l)=>e(_=>e(h=>jt(d,e,n,(p,m)=>a(L(p._1,p._2,!1),m),(p,m)=>e(x=>{const J=d._3&&!p._3?L(p._1,p._2,!0):p;return dt(St(y=>y==="{"))("'{'")(J,e,n,(y,T)=>a(L(J._1,J._2,!1),T),(y,T)=>e(b=>jc(Zc(Eb))(J,e,n,a,o)))})))))))})},y5=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(u=>{const a=(c,f)=>{const d=c._3;return e(l=>d?r(c,f):e(_=>{const h=t._3;return e(p=>Tn("par")(t,e,n,(m,x)=>r(L(m._1,m._2,h),x),(m,x)=>e(J=>{const y=t._3&&!m._3?L(m._1,m._2,!0):m;return e(T=>jt(y,e,n,(b,C)=>r(L(b._1,b._2,h),C),(b,C)=>e(S=>Xc(y._3&&!b._3?L(b._1,b._2,!0):b,e,n,(E,F)=>r(L(E._1,E._2,h),F),(E,F)=>e(O=>{const G=t._3&&!E._3?L(E._1,E._2,!0):E;return e(A=>hu(G,e,n,r,(K,U)=>e(z=>{const H=dt(dt(St(P=>P==="{"))("'{'"))("'{'"),M=G._3&&!K._3?L(K._1,K._2,!0):K;return e(P=>H(M,e,n,r,(R,Q)=>e(B=>o(M._3&&!R._3?L(R._1,R._2,!0):R,Jr("Par",[])))))})))})))))})))}))};return e(c=>e(f=>Tn("par")(L(i,s,!1),e,n,(d,l)=>a(L(d._1,d._2,!1),l),(d,l)=>e(_=>e(h=>jt(d,e,n,(p,m)=>a(L(p._1,p._2,!1),m),(p,m)=>e(x=>{const J=d._3&&!p._3?L(p._1,p._2,!0):p;return dt(St(y=>y==="{"))("'{'")(J,e,n,(y,T)=>a(L(J._1,J._2,!1),T),(y,T)=>e(b=>jc(Zc(Cb))(J,e,n,a,o)))})))))))})},Zc=t=>{const e=wn(Tl);return(n,r,o,i,s)=>r(u=>e(n,r,o,i,(a,c)=>r(f=>s(n._3&&!a._3?L(a._1,a._2,!0):a,t(qt(ue.foldr,c))))))},tg=t=>e=>(n,r,o,i,s)=>r(u=>Kk(t)(n,r,o,i,(a,c)=>r(f=>{const d=wn(St(Ek)),l=n._3&&!a._3?L(a._1,a._2,!0):a;return r(_=>d(l,r,o,i,(h,p)=>r(m=>{const x=dt(dt(St(y=>y==="{"))("'{'"))("'{'"),J=l._3&&!h._3?L(h._1,h._2,!0):h;return r(y=>x(J,r,o,i,(T,b)=>r(C=>{const S=J._3&&!T._3?L(T._1,T._2,!0):T;return r(E=>dn(S,r,o,i,(F,O)=>r(G=>{const A=Zc(Sb),K=S._3&&!F._3?L(F._1,F._2,!0):F;return r(U=>A(K,r,o,i,(z,H)=>r(M=>{const P=K._3&&!z._3?L(z._1,z._2,!0):z;return r(R=>dn(P,r,o,i,(Q,B)=>r(q=>{const et=dt(dt(St(Y=>Y==="}"))("'}'"))("closing '}'"),V=P._3&&!Q._3?L(Q._1,Q._2,!0):Q;return r(Y=>et(V,r,o,i,(W,X)=>r(tt=>{const gt=V._3&&!W._3?L(W._1,W._2,!0):W;return r(wt=>dn(gt,r,o,i,(ct,yt)=>r(Ct=>s(gt._3&&!ct._3?L(ct._1,ct._2,!0):ct,{name:Bk(kr(qt(ue.foldr,p))),ops:H,kind:e}))))})))})))})))})))})))})))}))),x5=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(u=>tr("keyframe")("Drop the `keyframe` wrapper; Markgraf animates statements in order.")(L(i,s,!1),e,n,(a,c)=>{const f=a._3;return e(d=>{if(f)return r(a,c);const l=t._1,_=t._2;return e(h=>tg("scene")(fu)(L(l,_,!1),e,n,(p,m)=>{const x=p._3;return e(J=>{if(x)return r(p,m);const y=t._1,T=t._2;return e(b=>tg("still")($c)(L(y,T,!1),e,n,(C,S)=>{const E=C._3;return e(F=>E?r(C,S):tg("title")(Lb)(t,e,n,r,o))},o))})},o))})},o))},J5=t=>e=>n=>{if(t==="AnimatedSurface")return{...e,frames:Pt(e.frames)({name:N,ops:n,kind:fu})};if(t==="StillSurface")return{...e,statements:Pt(e.statements)(n)};if(t==="SequenceSurface")return{...e,statements:Pt(e.statements)(n)};g()},N5=t=>e=>n=>{if(n.tag==="TopFrame"){const r=xl(t)(e);return{...r,frames:Pt(r.frames)((()=>{if(t==="AnimatedSurface")return n._1;if(t==="StillSurface")return{...n._1,kind:n._1.kind==="AnimatedKeyframe"?$c:n._1.kind};if(t==="SequenceSurface")return n._1;g()})())}}if(n.tag==="TopStatement")return J5(t)(e)(n._1);if(n.tag==="TopInside")return e;g()},w5=t=>{const e=w(N5(t))(zk);return n=>xl(t)(e(n)).frames},v5=t=>sk.defer(e=>(n,r,o,i,s)=>{const u=n._1,a=n._2;return r(c=>e5(t)(L(u,a,!1),r,o,(f,d)=>{const l=f._3;return r(_=>{if(l)return i(f,d);const h=n._1,p=n._2;return r(m=>r(x=>T5(L(h,p,!1),r,o,(J,y)=>{const T=J._3;return r(b=>{if(T)return i(J,y);const C=n._1,S=n._2;return r(E=>r(F=>x5(L(C,S,!1),r,o,(O,G)=>{const A=O._3;return r(K=>A?i(O,G):r(U=>Tl(n,r,o,i,(z,H)=>r(M=>s(z,Vc("TopStatement",H))))))},(O,G)=>r(A=>s(O,Vc("TopFrame",G))))))})},(J,y)=>r(T=>s(J,Vc("TopInside",y))))))})},s))}),T5=(t,e,n,r,o)=>e(i=>Tn("inside")(t,e,n,r,(s,u)=>e(a=>{const c=dt(co)("space after 'inside'"),f=t._3&&!s._3?L(s._1,s._2,!0):s;return e(d=>c(f,e,n,r,(l,_)=>e(h=>{const p=dt(Re)("node identifier after 'inside'"),m=f._3&&!l._3?L(l._1,l._2,!0):l;return e(x=>p(m,e,n,r,(J,y)=>e(T=>{const b=m._3&&!J._3?L(J._1,J._2,!0):J;return e(C=>dn(b,e,n,r,(S,E)=>e(F=>{const O=b._3&&!S._3?L(S._1,S._2,!0):S;return e(G=>jc(bl)(O,e,n,r,(A,K)=>e(U=>{const z=O._3&&!A._3?L(A._1,A._2,!0):A;return e(H=>dn(z,e,n,r,(M,P)=>e(R=>o(z._3&&!M._3?L(M._1,M._2,!0):M,{node:y,doc:K}))))})))})))})))})))}))),bl=(t,e,n,r,o)=>e(i=>o5(t,e,n,r,(s,u)=>e(a=>{const c=t._3&&!s._3?L(s._1,s._2,!0):s;return e(f=>{const d=(h,p)=>e(m=>{const x=wn(v5(u)),J=c._3&&!h._3?L(h._1,h._2,!0):h;return e(y=>x(J,e,n,r,(T,b)=>e(C=>{const S=qt(ue.foldr,b);return o(J._3&&!T._3?L(T._1,T._2,!0):T,{seed:(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})(),mode:u,frames:w5(u)(S),interiors:xt(E=>{if(E.tag==="TopInside")return v("Just",E._1);if(E.tag==="TopFrame"||E.tag==="TopStatement")return N;g()})(S)})})))}),l=c._1,_=c._2;return e(h=>e(p=>t5(L(l,_,!1),e,n,(m,x)=>{const J=m._3;return e(y=>J?r(m,x):d(c,N))},(m,x)=>e(J=>d(m,v("Just",x))))))})}))),b5=(()=>{const t=dt((e,n,r,o,i)=>n(s=>n(u=>dn(e,n,r,o,(a,c)=>n(f=>n(d=>{const l=e._3&&!a._3?L(a._1,a._2,!0):a;return Ai(l,n,r,o,(_,h)=>n(p=>i(l._3&&!_._3?L(_._1,_._2,!0):_,h)))}))))))("'scene', 'still', 'title', 'inside', a statement, or end of input");return(e,n,r,o,i)=>n(s=>n(u=>n(a=>n(c=>dn(e,n,r,o,(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?L(f._1,f._2,!0):f;return bl(h,n,r,o,(p,m)=>n(x=>{const J=h._3&&!p._3?L(p._1,p._2,!0):p;return n(y=>n(T=>{const b=e._3&&!J._3?L(J._1,J._2,!0):J;return t(b,n,r,o,(C,S)=>n(E=>i(b._3&&!C._3?L(C._1,C._2,!0):C,m)))}))}))})))))))})(),k5=t=>{const e=gk(t)(b5);if(e.tag==="Left")return Rt("Left",{msg:Dk(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 Rt("Right",e._1);g()},L5=t=>{const e=k5(t);if(e.tag==="Left")return Rt("Left",e._1.msg);if(e.tag==="Right")return Rt("Right",e._1);g()},C5=()=>({tag:"ParFrag"}),kl=t=>t,S5=kl("Sync"),E5=kl("SelfMsg"),G5=C5(),Qr=Zd(pn),Yo=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=I.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},Sn=so(pn),wr=Qr.state(t=>k(t,t)),Ll=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},xu=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},go=uo(pn),P5=t=>e=>w(n=>r=>so(pn).bind(n)(o=>t(o)(r)))(uo(pn).pure(e)),Cl=Ri(go)(zt),I5=t=>Qr.state(e=>k(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:v("Just",t)};g()})())),A5=t=>e=>Qr.state(n=>k(void 0,{...n,lifelines:Tg(I)(r=>v("Just",{...r,label:e}))(t)(n.lifelines)})),D5=t=>e=>n=>{const r=Yo(n)(t.lifelines);return Yo(e)(t.lifelines).tag==="Nothing"?r.tag==="Nothing"?e+", "+n:e:r.tag==="Nothing"?n:""},B5={lifelines:D,lifelineOrder:[],messages:[],fragments:[],frameEndRows:[],row:0,error:N},R5=t=>e=>n=>Sn.bind(wr)(r=>{const o=Yo(t)(r.lifelines),i=Yo(e)(r.lifelines);if(o.tag==="Just"&&i.tag==="Just"){const s={...r,messages:[{fromCol:o._1.column,toCol:i._1.column,labels:n,row:r.row,kind:t===e?E5:S5},...r.messages],row:r.row+1|0};return Qr.state(u=>k(void 0,s))}return I5("token references unknown node: "+D5(r)(t)(e))}),Q5=t=>Qr.state(e=>k(void 0,{...e,lifelines:Tg(I)(n=>v("Just",{...n,destroyedAt:v("Just",e.row)}))(t)(e.lifelines)})),F5=t=>e=>{const n=e.lifelineOrder.length,r=Mt(o=>N,o=>i=>v("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return{fromCol:0,toCol:xu(0)(e.lifelineOrder.length-1|0)};if(r.tag==="Just")return w(o=>i=>({fromCol:Ll(o.fromCol)(Ll(i.fromCol)(i.toCol)),toCol:xu(o.toCol)(xu(i.fromCol)(i.toCol))}))({fromCol:n,toCol:0})(t);g()},z5=t=>({lifelines:xt(e=>Yo(e)(t.lifelines))(t.lifelineOrder),messages:ge(t.messages),fragments:ge(t.fragments),frameEndRows:t.frameEndRows,totalRows:t.row}),M5=t=>e=>Sn.bind(wr)(n=>{const r=Yo(t)(n.lifelines);if(r.tag==="Just")return go.pure();if(r.tag==="Nothing"){const o={...n,lifelines:j(I)(t)({id:t,label:e,column:n.lifelineOrder.length,createdAt:n.row,destroyedAt:N})(n.lifelines),lifelineOrder:Pt(n.lifelineOrder)(t),row:n.row>0||n.messages.length!==0?n.row+1|0:n.row};return Qr.state(i=>k(void 0,o))}g()}),H5=t=>{if(t.tag==="AddNode")return M5(t._1.id)(t._1.label);if(t.tag==="DelNode")return Q5(t._1.id);if(t.tag==="ModNode"){if(t._1.label.tag==="Just")return A5(t._1.id)(t._1.label._1);if(t._1.label.tag==="Nothing")return go.pure();g()}return t.tag==="Token"?R5(t._1.from)(t._1.to)(t._1.labels):go.pure()},O5=t=>Sn.bind(wr)(e=>{const n=e.row;return Sn.bind(P5(r=>o=>Sn.bind(wr)(i=>{const s=r.childMessages.length===0?r.dividers:[i.row,...r.dividers],u=i.messages;return Sn.bind(eg(o))(()=>Sn.bind(wr)(a=>go.pure({dividers:s,childMessages:[...r.childMessages,...(()=>{const c=a.messages.length-u.length|0;return c<1?[]:Gt(0,c,a.messages)})()]})))}))({dividers:[],childMessages:[]})(t))(r=>Sn.bind(wr)(o=>{const i=F5(r.childMessages)(o),s={kind:G5,label:"par",fromRow:n,toRow:xu(o.row)(n+1|0),fromCol:i.fromCol,toCol:i.toCol,regionDividers:ge(r.dividers)},u=Qr.state(a=>k(void 0,{...a,fragments:[s,...a.fragments]}));return r.childMessages.length>=2?u:go.pure()}))}),eg=t=>{if(t.tag==="Leaf")return H5(t._1.op);if(t.tag==="Seq"||t.tag==="GroupSeq")return Cl(eg)(t._1);if(t.tag==="Par")return O5(t._1);g()},q5=t=>{const e=Sn.bind(Cl(n=>Sn.bind(wr)(r=>Sn.bind(eg(n.ops))(()=>Sn.bind(wr)(o=>{const i=Qr.state(s=>k(void 0,{...s,frameEndRows:Pt(s.frameEndRows)(s.row-1|0)}));return(o.messages.length-r.messages.length|0)>0?i:go.pure()}))))(t.frames))(()=>wr)(B5)._1;if(e.error.tag==="Just")return Rt("Left",e.error._1);if(e.error.tag==="Nothing")return Rt("Right",z5(e));g()},$5=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},W5={padding:24,headerHeight:36,headerWidth:120,columnSpacing:160,rowHeight:36,topGap:24,bottomGap:24},Y5=t=>{const e=84+Z($5(1)(t.totalRows))*36,n=Yt(r=>o=>({lifeline:o,x:84+Z(r)*160}))(t.lifelines);return{metrics:W5,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}},V5=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=N;continue}if(i.tag==="Node"){const s=nt.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=v("Just",i._4);continue}}g()}return o},Sl=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},El=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=nt.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Gl=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},U5=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},X5=w(t=>e=>j(nt)(e)()(t))(D),K5={r:255,g:255,b:255,a:255},Ju={r:26,g:26,b:26,a:255},j5={color:{r:232,g:232,b:232,a:255},flat:!0},Z5={r:232,g:232,b:232,a:255},Nu=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,...ki],Pl=t=>e=>n=>({...n,stack:Pt(n.stack)(t),openedAt:j(nt)(t)(e)(n.openedAt)}),wu=t=>e=>{const n=e.stack.length-1|0;if(n>=0&&n<e.stack.length){const r=V5(e.stack[n])(e.openedAt),o=(()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return r._1;g()})();return{...e,stack:e.stack.length===0?[]:Gt(0,e.stack.length-1|0,e.stack),openedAt:xo(nt)(e.stack[n])(e.openedAt),spans:Pt(e.spans)({col:e.stack[n],fromRow:o,toRow:Sl(o)(t)})}}return e},Il=t=>e=>n=>{let r=t,o=e,i=n,s=!0,u;for(;s;){const a=r,c=o,f=i,d=f.stack.length-1|0;if(d>=0&&d<f.stack.length){if(a(f.stack[d])){s=!1,u=f;continue}r=a,o=c,i=wu(c)(f);continue}s=!1,u=f}return u},Al=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,u=r,a=u.stack.length-1|0;if(a>=0&&a<u.stack.length){n=s,r=wu(s)(u);continue}o=!1,i=u}return i},tL=t=>e=>{const n=Ve(vr)(e.fromCol)(t.stack)?Il((()=>{const r=e.fromCol;return o=>r===o})())(e.row-1|0)(t):Pl(e.fromCol)(e.row)(Al(e.row-1|0)(t));if(Ve(vr)(e.toCol)(n.stack)){const r=Il((()=>{const o=e.toCol;return i=>o===i})())(e.row-1|0)(wu(e.row)(n));return{...r,returnRows:j(nt)(e.row)()(r.returnRows)}}return Pl(e.toCol)(e.row)(n)},eL=t=>e=>n=>{const r=tL(e)(n);return El(n.row)(t)?Al(n.row)(r):r},vu={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:bi,lineCap:Bn},Dl={r:26,g:26,b:26,a:255},nL={color:{r:130,g:130,b:130,a:255},width:1,lineJoin:bi,lineCap:je},Bl={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:bi,lineCap:je},rL={color:{r:244,g:244,b:244,a:255},flat:!0},Rl=t=>e=>n=>Ye(r=>r.col===e&&r.fromRow<=n&&n<=r.toRow,t),Ql={color:{r:90,g:90,b:90,a:255},width:1,lineJoin:bi,lineCap:je},oL={stack:[],openedAt:D,spans:[],returnRows:D},iL={color:{r:150,g:150,b:150,a:255},width:1,lineJoin:bi,lineCap:je},sL=t=>e=>n=>r=>o=>{const i=e.bodyTop+(Z(o)+.5)*e.metrics.rowHeight-e.metrics.rowHeight/2;return t.strokePath([1,n,i,2,r,i])(iL)},uL=t=>{const e=t.Monad0(),n=e.Bind1(),r=lo(e.Applicative0())(zt);return o=>i=>{const s=o.bodyTop+(Z(i.fromRow)+.5)*o.metrics.rowHeight-o.metrics.rowHeight/2-6,u=i.fromCol>=0&&i.fromCol<o.columns.length?o.columns[i.fromCol].x-16:o.metrics.padding-16,a=[1,u,s,2,u+38,s,2,u+32,s+14,2,u,s+14,...ki],c=i.toCol>=0&&i.toCol<o.columns.length?o.columns[i.toCol].x+16:o.metrics.padding+16,f=o.bodyTop+(Z(Sl(i.toRow)(i.fromRow+1|0)-1|0)+.5)*o.metrics.rowHeight+o.metrics.rowHeight/2+6;return n.bind(t.strokePath([1,u,s,2,c,s,2,c,f,2,u,f,...ki])(Ql))(()=>n.bind(t.fillStrokePath(a)(j5)(Ql))(()=>n.bind(t.drawText({x:u+6,y:s+7,content:"par",font:{family:"Inter",size:11,weight:700},color:Ju,align:Ti,baseline:Dn}))(()=>r(i.regionDividers)(sL(t)(o)(u)(c)))))}},Fl=t=>e=>t>=e?[]:[k(t,Gl(e)(t+6)),...Fl(t+10)(e)],aL=t=>e=>{if(e<=t)return[];const n=r=>r>=e?[]:[k(r,Gl(e)(r+6)),...n(r+10)];return n(t)},cL=t=>{const e=lo(t.Monad0().Applicative0())(zt);return n=>r=>e(aL(n.headerTop+n.metrics.headerHeight+Z(r.lifeline.createdAt)*n.metrics.rowHeight+4)((()=>{if(r.lifeline.destroyedAt.tag==="Just")return n.bodyTop+(Z(r.lifeline.destroyedAt._1)+.5)*n.metrics.rowHeight;if(r.lifeline.destroyedAt.tag==="Nothing")return n.bodyBottom;g()})()))(o=>t.strokePath([1,r.x,o._1,2,r.x,o._2])(nL))},zl=t=>e=>t<=e?[]:[k(t,U5(e)(t-6)),...zl(t-6-4)(e)],gL=t=>e=>t===e?[]:t<e?Fl(t)(e):zl(t)(e),fL=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.headerTop+Z(r.lifeline.createdAt)*n.metrics.rowHeight,i=n.metrics.headerWidth/2,s=o+n.metrics.headerHeight,u=Nu(r.x-i)(o)(r.x+i)(s)(6);return e.bind(t.fillStrokePath(Nu(r.x-i)(o+5)(r.x+i)(s+5)(6))({color:Z5,flat:!0})(Bl))(()=>e.bind(t.fillStrokePath(u)(rL)(Bl))(()=>t.drawText({x:r.x,y:o+n.metrics.headerHeight/2,content:r.lifeline.label,font:{family:"Inter",size:14,weight:600},color:Ju,align:Ar,baseline:Dn})))}},_L=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,u=r,a=u.stack.length-1|0;if(a>=0&&a<u.stack.length){n=s,r=wu(s)(u);continue}o=!1,i=u}return i},dL=t=>_L((()=>{const e=t.diagram.messages.length-1|0;return e>=0&&e<t.diagram.messages.length?t.diagram.messages[e].row:0})())(w(eL(X5(t.diagram.frameEndRows)))(oL)(at(e=>e.kind==="Sync"||e.kind!=="SelfMsg",t.diagram.messages))),lL=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.bodyTop+(Z(r.row)+.5)*n.metrics.rowHeight,i=r.fromCol>=0&&r.fromCol<n.columns.length?n.columns[r.fromCol].x:n.metrics.padding,s=o-n.metrics.rowHeight*.3,u=i+36,a=o+n.metrics.rowHeight*.3,c=i+10,f=[1,i,a,2,c,a-5,2,c,a+5,...ki];return e.bind(t.strokePath([1,i,s,2,u,s,2,u,a,2,i,a])(vu))(()=>e.bind(t.fillPath(f)({color:Dl,flat:!0}))(()=>t.drawText({x:i+42,y:o,content:fr(" ")($(Mu)(r.labels)),font:{family:"Inter",size:12,weight:400},color:Ju,align:Ti,baseline:Dn})))}},hL=t=>{const e=t.Monad0(),n=e.Bind1(),r=lo(e.Applicative0())(zt);return o=>i=>s=>u=>{const a=s?o.bodyTop+(Z(u.row)+.5)*o.metrics.rowHeight+o.metrics.rowHeight*.5:o.bodyTop+(Z(u.row)+.5)*o.metrics.rowHeight,c=u.toCol>=u.fromCol?1:-1,f=(u.fromCol>=0&&u.fromCol<o.columns.length?o.columns[u.fromCol].x:o.metrics.padding)+(Rl(i)(u.fromCol)(u.row)?c*6:c*0),d=(u.toCol>=0&&u.toCol<o.columns.length?o.columns[u.toCol].x:o.metrics.padding)-(Rl(i)(u.toCol)(u.row)?c*6:c*0),l=d-c*10,_=s?t.strokePath([1,l,a-5,2,d,a,2,l,a+5])(vu):t.fillPath([1,d,a,2,l,a-5,2,l,a+5,...ki])({color:Dl,flat:!0});return n.bind(s?r(gL(f)(d))(h=>t.strokePath([1,h._1,a,2,h._2,a])(vu)):t.strokePath([1,f,a,2,d,a])(vu))(()=>n.bind(_)(()=>t.drawText({x:(f+d)/2,y:a-6,content:fr(" ")($(Mu)(u.labels)),font:{family:"Inter",size:12,weight:400},color:Ju,align:Ar,baseline:iv})))}},pL=t=>{const e=lL(t),n=hL(t);return r=>o=>i=>s=>{if(s.kind==="SelfMsg")return e(r)(s);if(s.kind==="Sync")return n(r)(o)(El(s.row)(i))(s);g()}},Ml={color:{r:26,g:26,b:26,a:255},width:1.25,lineJoin:Ge,lineCap:je},mL={color:{r:232,g:232,b:232,a:255},flat:!0},yL={color:{r:252,g:252,b:252,a:255},flat:!0},xL=t=>e=>n=>{const r=n.col>=0&&n.col<e.columns.length?e.columns[n.col].x:e.metrics.padding,o=e.bodyTop+(Z(n.fromRow)+.5)*e.metrics.rowHeight,i=e.bodyTop+(Z(n.toRow)+.5)*e.metrics.rowHeight+e.metrics.rowHeight*.5,s=Nu(r-6)(o)(r+6)(i)(3);return t.Monad0().Bind1().bind(t.fillStrokePath(Nu(r-6)(o+5)(r+6)(i+5)(3))(mL)(Ml))(()=>t.fillStrokePath(s)(yL)(Ml))},Hl=t=>{const e=t.Monad0(),n=e.Bind1(),r=lo(e.Applicative0())(zt),o=fL(t),i=cL(t),s=uL(t),u=pL(t);return a=>{const c=dL(a);return n.bind(t.setViewport({vx:0,vy:0,vw:a.width,vh:a.height}))(()=>n.bind(t.clearBackground(K5))(()=>n.bind(r(a.columns)(o(a)))(()=>n.bind(r(a.columns)(i(a)))(()=>n.bind(r(c.spans)(xL(t)(a)))(()=>n.bind(r(a.diagram.fragments)(s(a)))(()=>r(a.diagram.messages)(u(a)(c.spans)(c.returnRows))))))))}},JL=Hl(vv);function ng(t,e,n,r){if(typeof window<"u"){var o=window[n];if(o!=null&&r instanceof o)return e(r)}for(var i=r;i!=null;){var s=Object.getPrototypeOf(i),u=s.constructor.name;if(u===n)return e(r);if(u==="Object")return t;i=s}return t}function tn(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function NL(t){return function(e){return function(){return e.getAttribute(t)}}}const Ol=t=>{const e=NL(t);return n=>{const r=e(n);return()=>{const o=r();return kg(o,N,ne)}}};function wL(t){return function(e){return function(){e.textContent=t}}}function vL(t){return function(){return function(e){return t(e)()}}}function TL(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const rg=function(){return window};function bL(t){return function(e){return function(){e.value=t}}}function kL(t){return function(){return t.valueAsNumber}}function LL(t){return function(){return t.value}}function og(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const ql=t=>t,Tu=t=>()=>{const e=t.getBoundingClientRect?.(),n=e?.width||t.clientWidth||0,r=e?.height||t.clientHeight||0;return{width:n,height:r}},$l=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)}},Wl=()=>window.devicePixelRatio||1,CL=t=>e=>n=>r=>o=>()=>{const i=Math.max(1,e||t.clientWidth||r),s=Math.max(1,n||t.clientHeight||o),u="Markgraf needs more room",a=`Resize to at least ${Math.round(r)} \xD7 ${Math.round(o)} px`;if(t.setAttribute("data-mg-too-small","1"),t.setAttribute("data-mg-viewport-css-width",String(e||0)),t.setAttribute("data-mg-viewport-css-height",String(n||0)),t.setAttribute("data-mg-camera-vw","0"),t.setAttribute("data-mg-camera-vh","0"),t.setAttribute("data-mg-camera-zoom","0"),t instanceof SVGElement){t.setAttribute("viewBox",`0 0 ${i} ${s}`),t.setAttribute("preserveAspectRatio","xMidYMid meet"),t.innerHTML=`
|
|
23
|
+
<rect x="0" y="0" width="${i}" height="${s}" rx="16" fill="#111827"/>
|
|
24
|
+
<text x="${i/2}" y="${s/2-10}" text-anchor="middle" dominant-baseline="middle" fill="#f9fafb" font-family="system-ui, sans-serif" font-size="18" font-weight="700">${u}</text>
|
|
25
|
+
<text x="${i/2}" y="${s/2+18}" text-anchor="middle" dominant-baseline="middle" fill="#cbd5e1" font-family="system-ui, sans-serif" font-size="13">${a}</text>
|
|
26
|
+
`;return}if(t instanceof HTMLCanvasElement){const c=window.devicePixelRatio||1;t.width=Math.max(1,Math.round(i*c)),t.height=Math.max(1,Math.round(s*c));const f=t.getContext("2d");if(!f)return;f.save(),f.scale(c,c),f.clearRect(0,0,i,s),f.fillStyle="#111827",f.fillRect(0,0,i,s),f.textAlign="center",f.textBaseline="middle",f.fillStyle="#f9fafb",f.font="700 18px system-ui, sans-serif",f.fillText(u,i/2,s/2-10),f.fillStyle="#cbd5e1",f.font="13px system-ui, sans-serif",f.fillText(a,i/2,s/2+18),f.restore();return}t.textContent=`${u}. ${a}.`},Bi=(t,e)=>{e.innerHTML=t},bu=(t,e,n)=>{t.style.setProperty(e,n)},SL=(t,e)=>t.querySelector(`[data-mg="${e}"]`),Yl=t=>e=>t===e,Vl=(t,e)=>({tag:t,_1:e}),Ul=t=>t,EL=(t,e,n)=>({tag:t,_1:e,_2:n}),Xl=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},GL=Hl(Jc),PL=zt.foldMap(lp),Kl=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ig=EL("AutoSize"),IL=Ul("CanvasRenderer"),AL=Ul("SvgRenderer"),DL=t=>e=>{const n=t-e*Z(fe(bn(t/e)));return e<=0?0:n<0?n+e:n},jl=t=>w(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),BL=t=>{const e=Ol("data-markgraf-titles")(t);return()=>{const n=e();return n.tag==="Nothing"||!(n.tag==="Just"&&n._1==="false")}},RL=t=>{const e=Ol("data-markgraf-theme")(t);return()=>{const n=e();if(n.tag==="Just")return n._1==="light"?Fc:n._1==="dark"?Z3:n._1==="blueprint"?tb:n._1==="whiteboard"?eb:n._1==="isometric"?nb:Fc;if(n.tag==="Nothing")return Fc;g()}},QL=`
|
|
20
27
|
<canvas data-mg="stage" tabindex="0"></canvas>
|
|
21
28
|
<div data-mg="play-overlay" aria-hidden="true"></div>
|
|
22
29
|
<div data-mg="bar">
|
|
@@ -33,4 +40,6 @@ var jb=(function(Iu){"use strict";function Ua(t){let e=0,n;return()=>{if(e===2)r
|
|
|
33
40
|
<option value="2">2\xD7</option>
|
|
34
41
|
</select>
|
|
35
42
|
</div>
|
|
36
|
-
`,
|
|
43
|
+
`,Zl=t=>e=>({...e,state:{...e.state,camera:t},minis:$(n=>Zl(t)(n))(e.minis)}),FL=t=>e=>n=>{const r=ns(n.rootLayout)(n.camera),o=tn("data-mg-too-small")("0")(t);return()=>(o(),tn("data-mg-camera-vw")(Fr(r.w))(t)(),tn("data-mg-camera-vh")(Fr(r.h))(t)(),tn("data-mg-camera-zoom")(Fr(n.camera.zoom))(t)(),tn("data-mg-viewport-css-width")(Fr(e.w))(t)(),tn("data-mg-viewport-css-height")(Fr(e.h))(t)())},zL=t=>{const e=q5(t);if(e.tag==="Left")return Rt("Left",e._1);if(e.tag==="Right")return Rt("Right",Y5(e._1));g()},ML=t=>e=>n=>{if(e.tag==="FixedSize")return()=>({w:e._1,h:e._2});if(e.tag==="AutoSize"){const r=Tu(t);return()=>{const o=r(),i=o.width<=0?n.width:o.width;return{w:i,h:o.height<=0?i*n.height/Xl(1)(n.width):o.height}}}g()},HL=t=>e=>n=>{const r=q3(K3(JL(n))),o=tn("viewBox")(r.viewBox)(t);return()=>(o(),tn("preserveAspectRatio")("xMidYMid meet")(t)(),e.tag==="FixedSize"?(tn("width")(ee(fe(Gn(e._1))))(t)(),tn("height")(ee(fe(Gn(e._2))))(t)()):e.tag==="AutoSize"||g(),Bi(r.body,t))},OL=t=>e=>n=>{const r=ql(t),o=ML(t)(e)(n);return()=>{const i=o(),s=Wl(),u=i.w*s,a=i.h*s,c=Sg(r)(),f=Eg(r)(),d=Gg(r)(u);c!==u&&d();const l=Pg(r)(a);f!==a&&l(),e.tag==="FixedSize"?(bu(t,"width",ee(fe(Gn(i.w)))+"px"),bu(t,"height",ee(fe(Gn(i.h)))+"px")):e.tag==="AutoSize"||g();const _=Cg(r)();ir(_)(),Xo(_)({scaleX:s,scaleY:s})();const h=V1(_)({width:i.w,height:i.h})();return GL(n)(h)(),sr(_)()}},qL=t=>e=>n=>r=>{if(e==="CanvasRenderer")return OL(t)(n)(r);if(e==="SvgRenderer")return HL(t)(n)(r);g()},$L=t=>e=>n=>r=>()=>{let o=!1,i=()=>{},s=[];const u=()=>{const c=o,f=qL(t)(e)(n)(r);if(!c)return f()},a={time:0,keyframe:"sequence",playing:!1};return u(),i=$l(t)(()=>{u();const c=s;return jl(f=>f(a))(c)()})(),{play:()=>{},pause:()=>{},toggle:()=>{},seek:c=>()=>{},setSpeed:c=>()=>{},currentTime:(()=>{const c=a.time;return()=>c})(),currentKeyframe:(()=>{const c=a.keyframe;return()=>c})(),isPlaying:()=>!1,duration:0,subscribe:c=>()=>{s=Pt(s)(c),c(a)();const f=Hu(d=>!Yl(d)(c));return()=>{s=f(s)}},destroy:()=>(o=!0,i())}},er=t=>e=>n=>()=>{const r=SL(t,e),o=kg(r,N,ne);if(o.tag==="Just")return n(o._1)();o.tag!=="Nothing"&&g()},WL=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=PL(o=>'<span class="mg-tick" style="left:'+vo(No("Fixed",wo(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"";g()})()+'"></span>')(e.spans);return er(t)("ticks")(o=>()=>Bi(r,o))},YL=t=>e=>n=>er(t)("scrub")(r=>{const o=ng(N,ne,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return n<=0?()=>{}:bL(ee(fe(Gn(e/n*1e3))))(o._1);g()}),sg=t=>e=>n=>{const r=vL(o=>n);return()=>{const o=r();return TL(t)(o)(!1)(e)()}},th=()=>Jp()/1e3,VL=t=>e=>()=>(Bi(`
|
|
44
|
+
<svg data-mg="stage" tabindex="0" role="img" aria-label="Markgraf sequence diagram"></svg>
|
|
45
|
+
`,t),er(t)("stage")(n=>{const r=$L(n)(AL)(ig)(e);return()=>{const o=rg();og(()=>{r()})(o)()}})()),ug=t=>e=>{const n=oe(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"";g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;if(r>=0&&r<t.spans.length){if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="Hold")return t.spans[r].scene._1;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return"";g()}return""}g()},UL=t=>e=>er(t)("speed")(n=>{const r=ng(N,ne,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return sg("change")(n)((()=>{const o=LL(r._1);return()=>{const i=o(),s=Zh(i,Jg,ne,N);if(s.tag==="Just")return e(s._1)();s.tag!=="Nothing"&&g()}})());g()}),XL=t=>e=>n=>er(t)("scrub")(r=>{const o=ng(N,ne,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return sg("input")(r)((()=>{const i=kL(o._1);return()=>{const s=i();return n.pause(),n.seek(s/1e3*e.totalDuration)()}})());g()}),KL=t=>e=>n=>{const r=WL(t)(e);return()=>{r(),er(t)("play")(o=>tn("data-mg-playing")("1")(o))(),UL(t)(n.setSpeed)(),er(t)("play")(o=>sg("click")(o)(n.toggle))(),XL(t)(e)(n)(),n.subscribe(o=>{const i=YL(t)(o.time)(e.totalDuration);return()=>(i(),er(t)("time")(s=>wL(vo(No("Fixed",wo(0)(20)(2)))(o.time)+" / "+vo(No("Fixed",wo(0)(20)(2)))(e.totalDuration))(s))(),er(t)("play")(s=>tn("data-mg-playing")(o.playing?"1":"0")(s))())})()}},jL=t=>e=>n=>{const r=J1(n);return()=>{const o=r(),i=N1(n)(),s=b2(im)(g2)(n)(w1(o)(i)(n));if(s.tag==="Left")return Rt("Left","precompute failed");if(s.tag==="Right")return Rt("Right",{schedule:s._1});g()}},ZL=t=>e=>{if(e.tag==="FixedSize"){const n=e._1<=0||e._2<=0?N:v("Just",e._1/e._2);return()=>n}if(e.tag==="AutoSize"){const n=Tu(t);return()=>{const r=n();return r.width<=0||r.height<=0?N:v("Just",r.width/r.height)}}g()},ku=t=>e=>n=>r=>o=>i=>s=>u=>a=>c=>f=>()=>{const d=th(),l=c.value;c.value=d;const _=l===0?0:d-l,h=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const b=Tu(t)();return{w:b.width<=0?200:b.width,h:b.height<=0?180:b.height}}g()})();if(h.w<200||h.h<180)return CL(t)(h.w)(h.h)(200)(180)();const p=k2({widthPx:h.w,heightPx:h.h})(s),m=fy(p)(Kl(f)(p.totalDuration)),x=i?m:{...m,levels:$(b=>({...b,state:{...b.state,frameTitle:""}}))(m.levels)},J=a.value,y=(()=>{if(J.tag==="Nothing")return x.camera;if(J.tag==="Just")return Z0(s.cameraConfig.cameraDecay)(_)(J._1)(x.camera);g()})();a.value=v("Just",y);const T={...x,camera:y,levels:$(Zl(y))(x.levels)};if(FL(t)(h)(T)(),e==="CanvasRenderer"){const b=ql(t),C=Si({padding:8,outputAspect:N})(T),S=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const P=Tu(t)();return{w:P.width,h:P.height<=0?C.vw<=0?P.width:P.width*C.vh/C.vw:P.height}}g()})(),E=Wl(),F=S.w*E,O=S.h*E,G=Sg(b)(),A=Eg(b)(),K=Gg(b)(F);G!==F&&K();const U=Pg(b)(O);A!==O&&U(),n.tag==="FixedSize"?(bu(t,"width",ee(fe(Gn(S.w)))+"px"),bu(t,"height",ee(fe(Gn(S.h)))+"px")):n.tag==="AutoSize"||g();const z=Cg(b)();ir(z)(),Xo(z)({scaleX:E,scaleY:E})();const H=u.value,M=D3(r)(o)(z)({width:S.w,height:S.h})(T)(_)(H)();return u.value=M,sr(z)()}if(e==="SvgRenderer"){const b=u.value,C=ZL(t)(n)(),S=mb(C)(r)(o)(T)(_)(b);return u.value=S.springs,tn("viewBox")(S.parts.viewBox)(t)(),tn("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(tn("width")(ee(fe(Gn(n._1))))(t)(),tn("height")(ee(fe(Gn(n._2))))(t)()):n.tag==="AutoSize"||g(),Bi(S.parts.body,t)}g()},tC=t=>e=>n=>r=>o=>i=>s=>()=>{let u=1,a=!0,c=!1,f=0,d=0;const l={value:D},_={value:N},h={value:0};let p=!1,m=()=>{},x=[];ku(t)(n)(r)(o)(i)(s)(e)(l)(_)(h)(0)();const J=E=>()=>{const F=x,O=a,G={time:E,keyframe:ug(e)(E),playing:O};return jl(A=>A(G))(F)()},y=()=>(a=!1,J(f)()),T=()=>{if(!p&&(c=!1,a)){const E=th(),F=d;d=E;const O=u,G=f,A=DL(F===0?G+0*O:G+(E-F)*O)(e.totalDuration+.8);return A<G&&(_.value=N),f=A,ku(t)(n)(r)(o)(i)(s)(e)(l)(_)(h)(A)(),J(A)(),b()}},b=()=>{if(!p&&!c){c=!0;const E=rg();og(T)(E)()}},C=()=>(d=0,a=!0,b()),S=()=>(a||C(),J(f)());return m=$l(t)(()=>{if(!p){const E=f;return ku(t)(n)(r)(o)(i)(s)(e)(l)(_)(h)(E)(),J(E)()}})(),C(),{play:S,pause:y,toggle:()=>a?y():S(),seek:E=>{const F=Xl(0)(Kl(e.totalDuration)(E));return()=>(f=F,d=0,_.value=N,ku(t)(n)(r)(o)(i)(s)(e)(l)(_)(h)(F)(),J(F)())},setSpeed:E=>()=>u=E,currentTime:()=>f,currentKeyframe:()=>{const E=f;return ug(e)(E)},isPlaying:()=>a,duration:e.totalDuration,subscribe:E=>()=>{x=Pt(x)(E);const F=f,O=a;E({time:F,keyframe:ug(e)(F),playing:O})();const G=Hu(A=>!Yl(A)(E));return()=>{x=G(x)}},destroy:()=>(p=!0,m())}},eC=t=>e=>{const n=BL(t);return()=>{const r=n(),o=RL(t)();return Bi(QL,t),er(t)("stage")(i=>{const s=jL()(ig)(e);return()=>{const u=rg();og(()=>{const a=s();if(a.tag==="Left")return Lg("[markgraf] precompute failed")();if(a.tag==="Right"){const c=tC(i)(a._1.schedule)(IL)(ig)(o)(rb)(r)();return KL(t)(a._1.schedule)(c)()}g()})(u)()}})()}},nC=t=>{const e=gl(t)(ol)._1;if(e.tag==="Left")return Rt("Left",e._1.msg);if(e.tag==="Right")return Rt("Right",e._1);g()},eh=t=>{const e=L5(t);if(e.tag==="Left")return Rt("Left",e._1);if(e.tag==="Right"){if(e._1.mode==="SequenceSurface"){const r=zL(e._1);if(r.tag==="Left")return Rt("Left",r._1);if(r.tag==="Right")return Rt("Right",Vl("LoadedSequence",r._1));g()}const n=nC(e._1);if(n.tag==="Left")return Rt("Left",n._1);if(n.tag==="Right")return Rt("Right",Vl("LoadedAnimation",n._1))}g()},nh=t=>e=>{const n=eh(e);if(n.tag==="Left")return Lg("[markgraf] parse failed: "+n._1);if(n.tag==="Right"){if(n._1.tag==="LoadedAnimation")return eC(t)(n._1._1);if(n._1.tag==="LoadedSequence")return VL(t)(n._1._1)}g()},rC=t=>{const e=eh(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return pp;g()},oC=t=>{const e=t.getAttribute("data-markgraf-src-b64");if(e)try{return decodeURIComponent(escape(atob(e)))}catch{return atob(e)}return t.getAttribute("data-markgraf-src")||t.textContent||""};let nr=null;const Lu=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",iC=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{Lu(t)?(nr&&nr!==t&&Lu(nr)&&nr.querySelector('[data-mg="play"]').click(),nr=t):nr===t&&(nr=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},sC=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=oC(t),n=t.dataset.markgrafPaused==="true";t.textContent="",nh(t)(e)(),t.querySelector('[data-mg="play"]')&&(n?Lu(t)&&t.querySelector('[data-mg="play"]').click():nr===null?nr=t:Lu(t)&&t.querySelector('[data-mg="play"]').click(),iC(t))},Cu=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(sC)},rh=()=>{document.addEventListener("keydown",t=>{if(t.code!=="Space"&&t.key!==" ")return;const e=t.target,n=e&&e.closest?.("[data-markgraf]");if(!n){const o=e?.tagName,i=(e?.type||"").toLowerCase();if(e?.isContentEditable||o==="TEXTAREA"||o==="SELECT"||o==="INPUT"&&!["range","checkbox","radio","button","submit","reset"].includes(i))return}const r=n||nr||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=rC(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>nh(e)(n)(),mountAll:Cu,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{Cu(),rh()}):(Cu(),rh())}return Pu.mountAll=Cu,Object.defineProperty(Pu,Symbol.toStringTag,{value:"Module"}),Pu})({});
|