@markgrafhq/markgraf-embed 0.1.18 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

@@ -1,22 +1,32 @@
1
- var jb=(function(Iu){"use strict";function Ua(t){let e=0,n;return()=>{if(e===2)return n;if(e===1)throw new Error("Binding demanded before initialized");return e=1,n=t(),e=2,n}}function g(){throw new Error("Failed pattern match")}function An(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const Se=t=>e=>t,H=function(t){return function(e){for(var n=e.length,r=new Array(n),i=0;i<n;i++)r[i]=t(e[i]);return r}},id={map:H},Ka=t=>t,Tt=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,i=0;i<r;i++)for(var o=e(t[i]),u=o.length,s=0;s<u;s++)n.push(o[s]);return n}},ue=function(t){return t.toString()},dr=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},od=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 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=or(`
4
- `)(" "),n=(()=>{const r=or("\r")(" "),i=(()=>{const o=or(" ")(" ");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),Dg=t=>e=>{const n=lm(r=>{const i=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;g()})();return dm(i.family)(i.size)(i.weight)(Yr(r.text))})(Ig(Yr(e)));return()=>{const r=n();return hm(r)}},Fg={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"}},pm=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Vr=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},mm=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ym=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},xm=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=t=>Nr(ve(mr(e=>e===" ")(ve(mr(e=>e===" ")(Jr(t)).rest)).rest)),Nm=t=>w(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?T("Just",n._1):e)(J)(Ft(ln)(t)),Ps=t=>e=>{if(t<=0)return[e];if(tr(e)<=t)return[e];const n=Jr(e),r=t<1?[]:kt(0,t,n),i=Nm(r);if(i.tag==="Just"){const o=zg(bc(!(i._1>=0&&i._1<r.length)||r[i._1]===" "?i._1:i._1+1|0)(e)),u=zg(Ni(i._1+1|0)(e));return u===""?[o]:[o,...Ps(t)(u)]}if(i.tag==="Nothing"){const o=bc(t)(e),u=Ni(t)(e);return u===""?[o]:[o,...Ps(t)(u)]}g()},Jm={cellW:7,cellH:3,maxLineWidth:20},wm=t=>e=>{const n=H(o=>L((()=>{if(o.label.tag==="Just")return o.label._1;if(o.label.tag==="Nothing")return o.id;g()})(),o))(e.nodes),r=Vr(1)(An((mm(t.maxLineWidth)(w(o=>u=>Vr(o)(tr(u._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),i=(r*t.cellW|0)-1|0;return{...e,nodes:H(o=>{if(!(o._2.size._1===1&&o._2.size._2===1))return o._2;const u=Tt(Lo(`
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},Sw=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.x-s.x,p=2*(()=>{const A=f.y-s.y;return(h<0?-h:h)+(A<0?-A:A)})(),m=_.x-u.x,y=2*(()=>{const A=_.y-u.y;return(m<0?-m:m)+(A<0?-A:A)})(),x=p+mo(t)+y,N=x<=1e-4?1:1-y/x,v=x<=1e-4?0:p/x,b=N-v,k=wi(t)(yu(0)(1)(b<=1e-4?0:(a-v)/b)),E=(()=>{if(k.tag==="Just")return k._1;if(k.tag==="Nothing")return f;g()})();return a<v?xa("InsideRect",ui(2)(e)):a>=N?xa("InsideRect",ui(2)(n)):xa("InsideBall",E,6)},Cw={offset:.8,passes:2,rMax:5},Gw=t=>{const e=t.Monad0().Applicative0(),n=tn(e);return r=>i=>o=>u=>{const s={color:u,width:1,lineJoin:Le,lineCap:mn},a={color:o,flat:!0},c=f=>t.drawRoundedRect({x:f.x,y:f.y,w:f.w,h:f.h})(4)(T("Just",a))(T("Just",s));return n(f=>{if(f._2.tag==="Travelling"){const d=Cn(f._2._1.edge)(r.edges),l=ae(f._2._1.target)(r.nodes),_=ae(f._2._1.source)(r.nodes);if(_.tag==="Just"&&l.tag==="Just"&&d.tag==="Just"){const h=Sw((()=>{if(f._2._1.direction==="Forward")return d._1;if(f._2._1.direction==="Backward")return ve(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(du(h._1)(h._2))(a)(s);g()}return e.pure()}if(f._2.tag==="Filling"){const d=ae(f._2._1.node)(r.nodes);if(d.tag==="Just")return c(ui(2)(d._1));if(d.tag==="Nothing")return e.pure();g()}return e.pure()})(Qe(i.tokens))}},u1=t=>e=>n=>r=>t.strokePath((()=>{const i=Mt(o=>J,o=>u=>T("Just",{head:o,tail:u}),H(o=>o.pt)(Fd(o=>u=>{const s=et(u)/et(72),a=he(-.18)(.18)(o.prng),c=he(-.1)(.1)(a.prng),f=he(-.07)(.07)(c.prng),d=n*(.05+.55*s)*(1+c.value),l=s*28.274333882308138+a.value;return{prng:f.prng,pt:{x:e.x+rn(l)*d+f.value*n,y:e.y+Ve(l)*d+f.value*n}}},{prng:137,pt:{x:e.x,y:e.y}},zt(0,72))));if(i.tag==="Just")return[1,i._1.head.x,i._1.head.y,...Jw(o=>[2,o.x,o.y])(i._1.tail)];if(i.tag==="Nothing")return[];g()})())({color:r,width:5.5,lineJoin:Le,lineCap:kn}),Pw=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=tn(e.Applicative0());return o=>u=>s=>i(a=>n.bind(t.pushAlpha(a.alpha))(()=>n.bind(t.strokePath(a.path)({color:o.nodeFill,width:a.width,lineJoin:Le,lineCap:kn}))(()=>r)))(Nw(U_(u)+7777|0)(u)(s))},s1=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,i=e.Applicative0(),o=tn(i),u=t.popClip,s=tn(i),a=lr.traverse(i),c=kw(t),f=Pw(t),d=t.popTransform;return l=>_=>h=>p=>m=>y=>x=>N=>v=>{const b=I=>n.bind(t.pushAlpha(I.alpha))(()=>n.bind(t.strokePath(I.path)({color:h.nodeStroke,width:2,lineJoin:Le,lineCap:kn}))(()=>r)),k={family:h.fontFamily,size:h.wobble?15:11,weight:h.wobble?800:500},E=Lo(`
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("&")("&amp;"),e=or("<")("&lt;"),n=(()=>{const r=or(">")("&gt;"),i=(()=>{const o=or('"')("&quot;");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
- `||e==="\r");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?z(s._1,s._2,!0):s,void 0))))})(),Wa=(t,e,n,r,i)=>e(o=>Ir("#")(t,e,n,r,(u,s)=>e(a=>{const c=sn(Yt(d=>d!==`
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
- `||n==="\r");return(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(c=>r(f=>t(z(s,a,!1),r,i,(d,l)=>r(_=>{const h=n._1,p=n._2;return r(m=>r(y=>Wa(z(h,p,!1),r,i,(x,N)=>{const v=x._3;return r(b=>{if(v)return o(x,N);const k=n._1,E=n._2;return r(A=>r($=>e(z(k,E,!1),r,i,(tt,S)=>{const C=tt._3;return r(V=>C?o(tt,S):Ba(n,r,i,o,u))},(tt,S)=>r(C=>u(tt,void 0)))))})},(x,N)=>r(v=>u(x,void 0)))))}),(d,l)=>r(_=>u(z(s,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),en=(()=>{const t=sn((e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>R1(z(u,s,!1),n,r,(c,f)=>{const d=c._3;return n(l=>d?i(c,f):Wa(e,n,r,i,o))},o))});return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?z(s._1,s._2,!0):s,void 0))))})(),fn=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>en(t._3&&!c._3?z(c._1,c._2,!0):c,e,n,r,i)),s=t._1,a=t._2;return e(c=>R1(z(s,a,!1),e,n,(f,d)=>{const l=f._3;return e(_=>l?r(f,d):Wa(t,e,n,r,u))},u))}),q1=(()=>{const t=St(Yt(e=>e==="|"))("'|'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=sn(Yt(l=>l!=="|")),d=e._3&&!s._3?z(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(p=>{const m=St(St(Yt(x=>x==="|"))("'|'"))("closing '|'"),y=d._3&&!_._3?z(_._1,_._2,!0):_;return n(x=>m(y,n,r,i,(N,v)=>n(b=>o(y._3&&!N._3?z(N._1,N._2,!0):N,Nr(At(Kt.foldr,h))))))})))})))})(),Rv=St(Ma([(t,e,n,r,i)=>e(o=>{const u=t._3;return Ir("->")(t,e,n,(s,a)=>r(z(s._1,s._2,u),a),(s,a)=>e(c=>i(s,XT)))}),(t,e,n,r,i)=>e(o=>{const u=t._3;return Ir("<-")(t,e,n,(s,a)=>r(z(s._1,s._2,u),a),(s,a)=>e(c=>i(s,YT)))}),(()=>{const t=Su(St(Yt(e=>e===">"))("'>'"));return(e,n,r,i,o)=>n(u=>{const s=e._3;return n(a=>n(c=>Ir("--")(e,n,r,(f,d)=>i(z(f._1,f._2,s),d),(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?z(f._1,f._2,!0):f;return t(h,n,r,(p,m)=>i(z(p._1,p._2,s),m),(p,m)=>n(y=>{const x=h._3&&!p._3?z(p._1,p._2,!0):p;return n(N=>o(x,VT))}))})))))})})()]))("'->', '<-', or '--'"),Cu=Yt(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),Re=(()=>{const t=sn(Yt(e=>e===" "||e===" "));return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>o(e._3&&!s._3?z(s._1,s._2,!0):s,void 0))))})(),qv=(()=>{const t=St(Yt(e=>e==="\\"))("'\\\\'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=e._3&&!s._3?z(s._1,s._2,!0):s;return n(d=>zv(f,n,r,i,(l,_)=>n(h=>o(f._3&&!l._3?z(l._1,l._2,!0):l,_==="n"?`
12
- `:_==="t"?" ":_==="r"?"\r":_))))})))})(),Hv=(()=>{const t=Yt(e=>e!=='"'&&e!=="\\"&&e!==`
13
- `);return(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>qv(z(u,s,!1),n,r,(c,f)=>n(d=>t(e,n,r,i,o)),o))}})(),Ra=(()=>{const t=St(Yt(e=>e==='"'))(`'"'`);return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(c=>{const f=sn(Hv),d=e._3&&!s._3?z(s._1,s._2,!0):s;return n(l=>f(d,n,r,i,(_,h)=>n(p=>{const m=St(St(Yt(x=>x==='"'))(`'"'`))(`closing '"' (unterminated string)`),y=d._3&&!_._3?z(_._1,_._2,!0):_;return n(x=>m(y,n,r,i,(N,v)=>n(b=>o(y._3&&!N._3?z(N._1,N._2,!0):N,Nr(At(Kt.foldr,h))))))})))})))})(),Ov=(()=>{const t=St(Yt(e=>e===":"))("':'");return(e,n,r,i,o)=>n(u=>Re(e,n,r,i,(s,a)=>n(c=>St((f,d,l,_,h)=>{const p=f._1,m=f._2;return d(y=>{const x=(N,v)=>{const b=N._3;return d(k=>{if(b)return _(N,v);const E=f._1,A=f._2;return d($=>q1(z(E,A,!1),d,l,(tt,S)=>{const C=tt._3;return d(V=>C?_(tt,S):Ra(f,d,l,_,h))},h))})};return d(N=>t(z(p,m,!1),d,l,x,(v,b)=>d(k=>d(E=>Re(v,d,l,x,(A,$)=>d(tt=>{const S=sn(Yt(V=>V!==`
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
- `||C==="\r"||C==="#"||C==="}"||C==="{"),S=v._3&&!E._3?z(E._1,E._2,!0):E;return e(C=>{const V=(W,B)=>e(P=>(B?((I,F,Q,R,Y)=>Y(I,"")):Ov)(S._3&&!W._3?z(W._1,W._2,!0):W,e,n,r,(I,F)=>e(Q=>{const R=v._3&&!I._3?z(I._1,I._2,!0):I;return e(Y=>{const O=(K,j)=>e(ot=>i(R._3&&!K._3?z(K._1,K._2,!0):K,On("AddNode",{id:x,label:F,shape:(()=>{const _t=Mv("shape")(j);if(_t.tag==="Just")return _t._1==="rectangle"||_t._1==="rect"?er:_t._1==="cylinder"||_t._1==="cyl"?Zl:_t._1==="parallelogram"?th:_t._1==="diamond"?eh:_t._1==="ellipse"?nh:_t._1==="document"||_t._1==="doc"?rh:_t._1==="cloud"?ih:er;if(_t.tag==="Nothing")return er;g()})()}))),X=R._1,q=R._2;return e(K=>{const j=(ot,_t)=>{const gt=ot._3;return e(yt=>gt?r(ot,_t):O(R,D))};return e(ot=>e(_t=>Re(z(X,q,!1),e,n,(gt,yt)=>j(z(gt._1,gt._2,!1),yt),(gt,yt)=>e(Ct=>e(Rt=>rb(gt,e,n,(pt,qt)=>j(z(pt._1,pt._2,!1),qt),(pt,qt)=>e(wt=>O(gt._3&&!pt._3?z(pt._1,pt._2,!0):pt,qt))))))))})})}))),U=S._1,M=S._2;return e(W=>{const B=(P,I)=>{const F=P._3;return e(Q=>F?r(P,I):V(S,!1))};return e(P=>e(I=>e(F=>Ba(z(U,M,!1),e,n,(Q,R)=>{const Y=Q._3;return e(O=>Y?B(z(U,M,!1),R):e(X=>tt(z(U,M,!1),e,n,(q,K)=>B(z(U,M,!1),K),(q,K)=>e(j=>e(ot=>V(z(U,M,!1),!0))))))},(Q,R)=>e(Y=>e(O=>V(z(U,M,!1),!0)))))))})})}))))})))})))}))),ob=(t,e,n,r,i)=>e(o=>z1(t,e,n,r,(u,s)=>e(a=>{const c=St(Ma([ib,jv,eb,Uv,Kv,Zv,tb,Xv]))("statement (+node, -node, +edge, -edge, ~edge, enter, exit, or 'a -> b'/'a <- b'/'a -- b')"),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,Ia("Leaf",{op:_,line:s.line,column:s.column})))))}))),ub=(t,e,n,r,i)=>e(o=>ji("seq")(t,e,n,r,(u,s)=>e(a=>Zi(qa(G1))(t._3&&!u._3?z(u._1,u._2,!0):u,e,n,r,i)))),sb=(t,e,n,r,i)=>e(o=>ji("par")(t,e,n,r,(u,s)=>e(a=>Zi(qa(tv))(t._3&&!u._3?z(u._1,u._2,!0):u,e,n,r,i)))),qa=t=>{const e=sn(ab());return(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,c)=>r(f=>u(n._3&&!a._3?z(a._1,a._2,!0):a,t(At(Kt.foldr,c))))))},ab=Ua(()=>{const t=Su(St(Yt(e=>e==="}"))("'}'"));return(e,n,r,i,o)=>n(u=>{const s=e._3;return n(a=>n(c=>en(e,n,r,(f,d)=>i(z(f._1,f._2,s),d),(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?z(f._1,f._2,!0):f;return t(h,n,r,(p,m)=>i(z(p._1,p._2,s),m),(p,m)=>n(y=>{const x=h._3&&!p._3?z(p._1,p._2,!0):p;return n(N=>{const v=Ma([(k,E,A,$,tt)=>{const S=k._3;return sb(k,E,A,(C,V)=>$(z(C._1,C._2,S),V),tt)},(k,E,A,$,tt)=>{const S=k._3;return ub(k,E,A,(C,V)=>$(z(C._1,C._2,S),V),tt)},ob]),b=e._3&&!x._3?z(x._1,x._2,!0):x;return n(k=>v(b,n,r,i,(E,A)=>n($=>{const tt=b._3&&!E._3?z(E._1,E._2,!0):E;return n(S=>Re(tt,n,r,i,(C,V)=>n(U=>{const M=tt._3&&!C._3?z(C._1,C._2,!0):C;return n(W=>Wv(M,n,r,i,(B,P)=>n(I=>o(M._3&&!B._3?z(B._1,B._2,!0):B,A))))})))})))})}))})))))})}),Ha=t=>e=>(n,r,i,o,u)=>r(s=>ji(t)(n,r,i,o,(a,c)=>r(f=>{const d=n._3&&!a._3?z(a._1,a._2,!0):a;return r(l=>$v(d,r,i,o,(_,h)=>r(p=>{const m=d._3&&!_._3?z(_._1,_._2,!0):_;return r(y=>en(m,r,i,o,(x,N)=>r(v=>{const b=Zi(qa(G1)),k=m._3&&!x._3?z(x._1,x._2,!0):x;return r(E=>b(k,r,i,o,(A,$)=>r(tt=>{const S=k._3&&!A._3?z(A._1,A._2,!0):A;return r(C=>en(S,r,i,o,(V,U)=>r(M=>u(S._3&&!V._3?z(V._1,V._2,!0):V,{name:T("Just",h),ops:$,kind:e}))))})))})))})))}))),cb=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>Ha("keyframe")(KT)(z(o,u,!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=>Ha("still")(jT)(z(l,_,!1),e,n,(p,m)=>{const y=p._3;return e(x=>y?r(p,m):Ha("title")(ZT)(t,e,n,r,i))},i))})},i))},gb=(t,e,n,r,i)=>e(o=>ji("inside")(t,e,n,r,(u,s)=>e(a=>{const c=St(Ee)("node identifier"),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=>en(p,e,n,r,(y,x)=>e(N=>{const v=p._3&&!y._3?z(y._1,y._2,!0):y;return e(b=>Zi($1)(v,e,n,r,(k,E)=>e(A=>{const $=v._3&&!k._3?z(k._1,k._2,!0):k;return e(tt=>en($,e,n,r,(S,C)=>e(V=>i($._3&&!S._3?z(S._1,S._2,!0):S,{node:_,doc:E}))))})))})))})))}))),$1=(t,e,n,r,i)=>e(o=>{const u=(c,f)=>e(d=>{const l=sn(fb()),_=t._3&&!c._3?z(c._1,c._2,!0):c;return e(h=>l(_,e,n,r,(p,m)=>e(y=>{const x=At(Kt.foldr,m);return i(_._3&&!p._3?z(p._1,p._2,!0):p,{seed:(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;g()})(),frames:xt(N=>{if(N.tag==="TopFrame")return T("Just",N._1);if(N.tag==="TopInside")return J;g()})(x),interiors:xt(N=>{if(N.tag==="TopInside")return T("Just",N._1);if(N.tag==="TopFrame")return J;g()})(x)})})))}),s=t._1,a=t._2;return e(c=>e(f=>nb(z(s,a,!1),e,n,(d,l)=>{const _=d._3;return e(h=>_?r(d,l):u(t,J))},(d,l)=>e(_=>u(d,T("Just",l))))))}),fb=Ua(()=>bv.defer(t=>(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>n(c=>gb(z(u,s,!1),n,r,(f,d)=>n(l=>n(_=>cb(e,n,r,i,(h,p)=>n(m=>o(h,W1("TopFrame",p)))))),(f,d)=>n(l=>o(f,W1("TopInside",d))))))})),_b=(()=>{const t=St((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 Ba(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?z(_._1,_._2,!0):_,h)))}))))))("'keyframe', 'still', 'title', 'inside', or end of input");return(e,n,r,i,o)=>n(u=>n(s=>n(a=>n(c=>en(e,n,r,i,(f,d)=>n(l=>n(_=>{const h=e._3&&!f._3?z(f._1,f._2,!0):f;return $1(h,n,r,i,(p,m)=>n(y=>{const x=h._3&&!p._3?z(p._1,p._2,!0):p;return n(N=>n(v=>{const b=e._3&&!x._3?z(x._1,x._2,!0):x;return t(b,n,r,i,(k,E)=>n(A=>o(b._3&&!k._3?z(k._1,k._2,!0):k,m)))}))}))})))))))})(),db=t=>{const e=Sv(t)(_b);if(e.tag==="Left")return Gt("Left",{msg:e._1._1,line:e._1._2.line,column:e._1._2.column});if(e.tag==="Right")return Gt("Right",e._1);g()},lb=t=>{const e=db(t);if(e.tag==="Left")return Gt("Left",e._1.msg);if(e.tag==="Right")return Gt("Right",e._1);g()};function Oa(t,e,n,r){if(typeof window<"u"){var i=window[n];if(i!=null&&r instanceof i)return e(r)}for(var o=r;o!=null;){var u=Object.getPrototypeOf(o),s=u.constructor.name;if(s===n)return e(r);if(s==="Object")return t;o=u}return t}function _n(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function hb(t){return function(e){return function(){return e.getAttribute(t)}}}const X1=t=>{const e=hb(t);return n=>{const r=e(n);return()=>{const i=r();return mc(i,J,Zt)}}};function pb(t){return function(e){return function(){e.textContent=t}}}function mb(t){return function(){return function(e){return t(e)()}}}function yb(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const Y1=function(){return window};function xb(t){return function(e){return function(){e.value=t}}}function Nb(t){return function(){return t.valueAsNumber}}function Jb(t){return function(){return t.value}}function V1(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const wb=t=>t,$a=t=>()=>{const e=t.getBoundingClientRect?.(),n=e?.width||t.clientWidth||0,r=e?.height||t.clientHeight||0;return{width:n,height:r}},Tb=t=>e=>()=>{let n=0;const r=()=>{n||(n=requestAnimationFrame(()=>{n=0,e()}))},i=typeof ResizeObserver>"u"?null:new ResizeObserver(r);return i?.observe(t),window.addEventListener("resize",r),()=>{n&&cancelAnimationFrame(n),i?.disconnect(),window.removeEventListener("resize",r)}},vb=()=>window.devicePixelRatio||1,bb=t=>e=>n=>r=>i=>()=>{const o=Math.max(1,e||t.clientWidth||r),u=Math.max(1,n||t.clientHeight||i),s="Markgraf needs more room",a=`Resize to at least ${Math.round(r)} \xD7 ${Math.round(i)} 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 ${o} ${u}`),t.setAttribute("preserveAspectRatio","xMidYMid meet"),t.innerHTML=`
16
- <rect x="0" y="0" width="${o}" height="${u}" rx="16" fill="#111827"/>
17
- <text x="${o/2}" y="${u/2-10}" text-anchor="middle" dominant-baseline="middle" fill="#f9fafb" font-family="system-ui, sans-serif" font-size="18" font-weight="700">${s}</text>
18
- <text x="${o/2}" y="${u/2+18}" text-anchor="middle" dominant-baseline="middle" fill="#cbd5e1" font-family="system-ui, sans-serif" font-size="13">${a}</text>
19
- `;return}if(t instanceof HTMLCanvasElement){const c=window.devicePixelRatio||1;t.width=Math.max(1,Math.round(o*c)),t.height=Math.max(1,Math.round(u*c));const f=t.getContext("2d");if(!f)return;f.save(),f.scale(c,c),f.clearRect(0,0,o,u),f.fillStyle="#111827",f.fillRect(0,0,o,u),f.textAlign="center",f.textBaseline="middle",f.fillStyle="#f9fafb",f.font="700 18px system-ui, sans-serif",f.fillText(s,o/2,u/2-10),f.fillStyle="#cbd5e1",f.font="13px system-ui, sans-serif",f.fillText(a,o/2,u/2+18),f.restore();return}t.textContent=`${s}. ${a}.`},Xa=(t,e)=>{e.innerHTML=t},U1=(t,e,n)=>{t.style.setProperty(e,n)},Lb=(t,e)=>t.querySelector(`[data-mg="${e}"]`),kb=t=>e=>t===e,Eb=t=>t,Sb=(t,e,n)=>({tag:t,_1:e,_2:n}),Cb=Bt.foldMap(rl),Gb=t=>e=>{const n=rt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},K1=t=>e=>{const n=rt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},j1=Sb("AutoSize"),Pb=Eb("CanvasRenderer"),Ab=t=>e=>{const n=t-e*et(xe(xn(t/e)));return e<=0?0:n<0?n+e:n},Ib=t=>w(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),Qb=t=>{const e=X1("data-markgraf-titles")(t);return()=>{const n=e();return n.tag==="Nothing"||!(n.tag==="Just"&&n._1==="false")}},Db=t=>{const e=X1("data-markgraf-theme")(t);return()=>{const n=e();if(n.tag==="Just")return n._1==="light"?Ga:n._1==="dark"?wT:n._1==="blueprint"?TT:n._1==="whiteboard"?vT:n._1==="isometric"?bT:Ga;if(n.tag==="Nothing")return Ga;g()}},Fb=`
1
+ var B4=(function(uu){"use strict";function Hp(t){let e=0,n;return()=>{if(e===2)return n;if(e===1)throw new Error("Binding demanded before initialized");return e=1,n=t(),e=2,n}}function g(){throw new Error("Failed pattern match")}function Jr(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const Ie=t=>e=>t,q=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}},$p={map:q},i_=t=>t,Et=typeof Array.prototype.flatMap=="function"?function(t){return function(e){return t.flatMap(e)}}:function(t){return function(e){for(var n=[],r=t.length,o=0;o<r;o++)for(var i=e(t[o]),s=i.length,a=0;a<s;a++)n.push(i[a]);return n}},Vp=function(t){return function(e){return{}.hasOwnProperty.call(e,t)}},Up=function(t){return function(e){return e[t]}},ie=function(t){return t.toString()},ro=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},Kp=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})+'"'},cu=t=>t,Be=cu("LT"),De=cu("GT"),Ye=cu("EQ"),N=(t,e)=>({tag:t,_1:e}),J=N("Nothing"),Kt=t=>N("Just",t),s_=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;g()},a_=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;g()},Wt=(t,e)=>({tag:t,_1:e}),Yp=t=>Wt("Right",t),Xp={map:t=>e=>{if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right")return Wt("Right",t(e._1));g()}},u_={apply:t=>e=>{if(t.tag==="Left")return Wt("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right")return Wt("Right",t._1(e._1))}g()},Functor0:()=>Xp},jp={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Wt("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}g()},Apply0:()=>u_},Zp={pure:Yp,Apply0:()=>u_},c_={Applicative0:()=>Zp,Bind1:()=>jp},t0=t=>t,e0={map:t=>e=>t(e)},g_={apply:t=>e=>t(e),Functor0:()=>e0},n0={bind:t=>e=>e(t),Apply0:()=>g_},r0={pure:t0,Apply0:()=>g_},kn={Applicative0:()=>r0,Bind1:()=>n0},o0=function(t){return function(){return t}},i0={apply:t=>e=>()=>{const n=t(),r=e();return gu.pure(n(r))()},Functor0:()=>s0},gu={pure:o0,Apply0:()=>i0},s0={map:t=>e=>()=>{const n=e();return t(n)}},Ro=(t,e)=>({tag:t,_1:e}),_u=t=>Ro("Loop",t),a0=t=>Ro("Done",t),u0={tailRecM:t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const s=r;if(s.tag==="Loop"){r=t(s._1);continue}if(s.tag==="Done"){o=!1,i=s._1;continue}g()}return i};return n=>e(t(n))},Monad0:()=>kn},c0=function(t){return function(e){return function(){return t(e())}}},g0=function(t){return function(){return t}},_0=function(t){return function(e){return function(){return e(t())()}}},f0={map:c0},d0={Applicative0:()=>fu,Bind1:()=>l0},l0={bind:_0,Apply0:()=>__},__={apply:t=>e=>()=>{const n=t(),r=e();return fu.pure(n(r))()},Functor0:()=>f0},fu={pure:g0,Apply0:()=>__},h0={tailRecM:t=>e=>{const n=t(e);return()=>{let r=n();for(;r.tag==="Loop";){const i=r;if(i.tag==="Loop"){r=t(i._1)();continue}i.tag!=="Done"&&g()}const o=r;if(o.tag==="Done")return o._1;g()}},Monad0:()=>d0},p0=function(t){return function(e){return function(n){return function(){return t(e,n)}}}},m0=function(t,e,n,r){return n>=0&&n<r.length?t(r[n]):e},du=function(t){return t.length},y0=function(t,e,n){return n.length>0?t(n.pop()):e},x0=p0(function(t,e){return e.push(t)}),w0=(t,e)=>({tag:"Iterator",_1:t,_2:e}),J0=t=>e=>n=>()=>{let r=!1;const o=e._2;for(;!r;){const i=o.value,s=e._1(i);if(s.tag==="Just"&&t(s._1)){n.push(s._1),e._2.value;const a=e._2.value;e._2.value=a+1|0;continue}r=!0}},N0=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const o=r.value,i=r.value;r.value=i+1|0;const s=t._1(o);if(s.tag==="Just"){e(s._1)();continue}if(s.tag==="Nothing"){n=!0;continue}g()}},Ao=function(t){return function(e){return function(n){for(var r=e,o=n.length,i=o-1;i>=0;i--)r=t(n[i])(r);return r}}},v=function(t){return function(e){return function(n){for(var r=e,o=n.length,i=0;i<o;i++)r=t(r)(n[i]);return r}}},Qr=t=>{const e=t.Apply0();return n=>r=>n.foldr(o=>{const i=r(o);return s=>e.apply(e.Functor0().map(a=>i_)(i))(s)})(t.pure())},Io=t=>{const e=Qr(t);return n=>{const r=e(n);return o=>i=>r(i)(o)}},f_={foldr:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(n._1)(e);g()},foldl:t=>e=>n=>{if(n.tag==="Nothing")return e;if(n.tag==="Just")return t(e)(n._1);g()},foldMap:t=>{const e=t.mempty;return n=>r=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return n(r._1);g()}}},Mt={foldr:Ao,foldl:v,foldMap:t=>{const e=t.mempty;return n=>Mt.foldr(r=>o=>t.Semigroup0().append(n(r))(o))(e)}},b=(t,e)=>({tag:"Tuple",_1:t,_2:e}),Rn=t=>e=>b(t,e),ps=t=>t._2,ms=t=>t._1,Ht=function(t){return function(e){for(var n=e.length,r=Array(n),o=0;o<n;o++)r[o]=t(o)(e[o]);return r}};var lu=function(t){return function(e){return t===e}};const v0=lu,T0=lu,Ti=lu,hu=function(t){return function(e){return function(n){if(e.length!==n.length)return!1;for(var r=0;r<e.length;r++)if(!t(e[r])(n[r]))return!1;return!0}}},Zn={eq:Ti},C0={eq:T0},zr={eq:v0};var pu=function(t){return function(e){return function(n){return function(r){return function(o){return r<o?t:r===o?e:n}}}}};const b0=pu,k0=pu,P={compare:pu(Be)(Ye)(De),Eq0:()=>Zn},ot={compare:k0(Be)(Ye)(De),Eq0:()=>C0},it={compare:b0(Be)(Ye)(De),Eq0:()=>zr},Ci=function(t){return t},S0=(function(){function t(o){return[o]}function e(o){return function(i){return[o,i]}}function n(o){return function(i){return function(s){return[o,i,s]}}}function r(o){return function(i){return o.concat(i)}}return function(o){return function(i){return function(s){return function(a){return function(u){function c(_,d){switch(d-_){case 0:return s([]);case 1:return i(t)(a(u[_]));case 2:return o(i(e)(a(u[_])))(a(u[_+1]));case 3:return o(o(i(n)(a(u[_])))(a(u[_+1])))(a(u[_+2]));default:var l=_+Math.floor((d-_)/4)*2;return o(i(r)(c(_,l)))(c(l,d))}}return c(0,u.length)}}}}}})(),L0=t=>t,oo={traverse:t=>{const e=t.Apply0();return S0(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>oo.traverse(t)(L0),Functor0:()=>$p,Foldable1:()=>Mt},Xt=function(t,e){for(var n=t>e?-1:1,r=new Array(n*(e-t)+1),o=t,i=0;o!==e;)r[i++]=o,o+=n;return r[i]=o,r};var E0=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},G0=function(t,e){for(var n=[],r=0,o=0;o<t;o++)n[r++]=e;return n};const P0=typeof Array.prototype.fill=="function"?E0:G0,Zt=(function(){function t(o,i){this.head=o,this.tail=i}var e={};function n(o){return function(i){return new t(o,i)}}function r(o){for(var i=[],s=0,a=o;a!==e;)i[s++]=a.head,a=a.tail;return i}return function(o,i){return r(o(n)(e)(i))}})(),Ft=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},d_=function(t,e,n,r){for(var o=0;o<r.length;o++){var i=n(r[o]);if(e(i))return i}return t},io=function(t,e,n,r){for(var o=0,i=r.length;o<i;o++)if(n(r[o]))return t(o);return e},l_=function(t,e,n,r,o){if(n<0||n>o.length)return e;var i=o.slice();return i.splice(n,0,r),t(i)},h_=function(t,e,n,r){if(n<0||n>=r.length)return e;var o=r.slice();return o.splice(n,1),t(o)},Mr=function(t,e,n,r,o){if(n<0||n>=o.length)return e;var i=o.slice();return i[n]=r,t(i)},se=function(t){return t.slice().reverse()},hn=function(t){if(t.length<=1e4)return Array.prototype.concat.apply([],t);for(var e=[],n=0,r=t.length;n<r;n++)for(var o=t[n],i=0,s=o.length;i<s;i++)e.push(o[i]);return e},ft=function(t,e){return e.filter(t)},B0=function(t,e,n){for(var r=n.length,o=e,i=new Array(r),s=0;s<r;s++)o=t(o)(n[s]),i[s]=o;return i},D0=(function(){function t(e,n,r,o,i,s){var a,u,c,_,d,l,f;for(a=i+(s-i>>1),a-i>1&&t(e,n,o,r,i,a),s-a>1&&t(e,n,o,r,a,s),u=i,c=a,_=i;u<a&&c<s;)d=o[u],l=o[c],f=n(e(d)(l)),f>0?(r[_++]=l,++c):(r[_++]=d,++u);for(;u<a;)r[_++]=o[u++];for(;c<s;)r[_++]=o[c++]}return function(e,n,r){var o;return r.length<2?r:(o=r.slice(0),t(e,n,o,r.slice(0),0,r.length),o)}})(),Rt=function(t,e,n){return n.slice(t,e)},Fe=function(t,e,n){for(var r=e.length<n.length?e.length:n.length,o=new Array(r),i=0;i<r;i++)o[i]=t(e[i])(n[i]);return o},Ne=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},p_=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},Pt=t=>e=>D0(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;g()},e),R0=t=>e=>Pt(n=>r=>t.compare(e(n))(e(r))),St=t=>e=>(()=>{const n=x0(e);return()=>{const r=[...t];return n(r)(),r}})()(),Nr=t=>{if(t.length===0)return t.length-1|0,J;const e=t.length-1|0;return e>=0&&e<t.length?N("Just",{init:Rt(0,t.length-1|0,t),last:t[e]}):J},A0=t=>e=>n=>t>=0&&t<n.length?Mr(Kt,J,t,e(n[t]),n):J,tr=t=>e=>{const n=(r=>{let o=r,i=!0,s;for(;i;){const a=o;if(a>=0&&a<e.length){if(t(e[a])){o=a+1|0;continue}i=!1,s=N("Just",a);continue}i=!1,s=J}return s})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:Rt(0,n._1,e),rest:Rt(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};g()},Fo=t=>e=>{const n=Pt(r=>o=>t(r._2)(o._2))(Ht(Rn)(e));return 0<n.length?q(ps)(R0(it)(ms)((()=>{const r=[n[0]];for(const o of n){const i=t((()=>{const s=r.length-1|0;if(s>=0&&s<r.length)return r[s]._2;g()})())(o._2);(i==="LT"||i==="GT"||i!=="EQ")&&r.push(o)}return r})())):[]},I0=t=>e=>{const n=[],r=w0(o=>o>=0&&o<e.length?N("Just",e[o]):J,{value:0});return N0(r)(o=>()=>{const i=[];i.push(o),J0(t(o))(r)(i)(),n.push(i)})(),n},re=t=>e=>{const n=io(Kt,J,t,e);return n.tag==="Just"?N("Just",e[n._1]):J},bi=t=>e=>ft(t,e),en=t=>e=>n=>{const r=io(Kt,J,o=>t.eq(o)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;g()},ys=t=>e=>Et(e)(t),vt=t=>ys(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];g()}),m_=isFinite;function F0(t,e,n,r){var o=parseFloat(t);return e(o)?n(o):r}const Oe=Math.abs,Q0=Math.acos,so=function(t){return function(e){return Math.atan2(t,e)}},xs=Math.ceil,Sn=Math.cos,Qo=Math.exp,An=Math.floor,ws=Math.log,z0=function(t){return function(e){return Math.min(t,e)}},mu=function(t){return function(e){return Math.pow(t,e)}},Hn=Math.round,pn=Math.sin,$e=Math.sqrt,M0=Math.tan,W0=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},nt=function(t){return t},O0=(function(t){return function(e){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var o=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(i){if(o.test(i)){var s=parseInt(i,n);return(s|0)===s?t(s):e}else return e}}}})(Kt)(J)(10),y_=W0(Kt)(J),fe=t=>{if(!m_(t))return 0;if(t>=nt(2147483647))return 2147483647;if(t<=nt(-2147483648))return-2147483648;const e=y_(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;g()},kt=(t,e,n)=>({tag:t,_1:e,_2:n}),$=kt("Nil"),de={foldr:t=>e=>{const n=de.foldl(o=>i=>t(i)(o))(e),r=(o=>i=>{let s=o,a=i,u=!0,c;for(;u;){const _=s,d=a;if(d.tag==="Nil"){u=!1,c=_;continue}if(d.tag==="Cons"){s=kt("Cons",d._1,_),a=d._2;continue}g()}return c})($);return o=>n(r(o))},foldl:t=>e=>n=>{let r=e,o=n,i=!0,s;for(;i;){const a=r,u=o;if(u.tag==="Nil"){i=!1,s=a;continue}if(u.tag==="Cons"){r=t(a)(u._1),o=u._2;continue}g()}return s},foldMap:t=>{const e=t.mempty;return n=>de.foldl(r=>{const o=t.Semigroup0().append(r);return i=>o(n(i))})(e)}},q0=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var s=[],a=i;;){var u=o(a);s.push(n(u));var c=r(u);if(t(c))return s;a=e(c)}}}}}}},H0=t=>{if(t.tag==="Just")return t._1;g()},$0={unfoldr1:q0(s_)(H0)(ms)(ps)},V0=function(t){return function(e){return function(n){return function(r){return function(o){return function(i){for(var s=[],a=i;;){var u=o(a);if(t(u))return s;var c=e(u);s.push(n(c)),a=r(c)}}}}}}},U0=t=>{if(t.tag==="Just")return t._1;g()},nn={unfoldr:V0(s_)(U0)(ms)(ps),Unfoldable10:()=>$0},te=(t,e,n,r,o,i,s)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:s}),rn=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Js=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),x_=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),I=te("Leaf"),In=rn("IterLeaf"),ve=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return te("Node",1,1,t,e,n,r);if(r.tag==="Node")return te("Node",1+r._1|0,1+r._2|0,t,e,n,r);g()}if(n.tag==="Node"){if(r.tag==="Leaf")return te("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return te("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,t,e,n,r)}g()},Xe=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?te("Node",1,1,t,e,I,I):r.tag==="Node"&&r._1>1?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;g()})()?ve(r._5._3,r._5._4,ve(t,e,n,r._5._5),ve(r._3,r._4,r._5._6,r._6)):ve(r._3,r._4,ve(t,e,n,r._5),r._6):ve(t,e,n,r);if(n.tag==="Node")return r.tag==="Node"?r._1>(n._1+1|0)?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;g()})()?ve(r._5._3,r._5._4,ve(t,e,n,r._5._5),ve(r._3,r._4,r._5._6,r._6)):ve(r._3,r._4,ve(t,e,n,r._5),r._6):n._1>(r._1+1|0)?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?ve(n._6._3,n._6._4,ve(n._3,n._4,n._5,n._6._5),ve(t,e,n._6._6,r)):ve(n._3,n._4,n._5,ve(t,e,n._6,r)):ve(t,e,n,r):r.tag==="Leaf"&&n._1>1?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;g()})()?ve(n._6._3,n._6._4,ve(n._3,n._4,n._5,n._6._5),ve(t,e,n._6._6,r)):ve(n._3,n._4,n._5,ve(t,e,n._6,r)):ve(t,e,n,r);g()},zo=(t,e,n)=>{if(n.tag==="Leaf")return Js(J,I,I);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const o=zo(t,e,n._5);return Js(o._1,o._2,Xe(n._3,n._4,o._3,n._6))}if(r==="GT"){const o=zo(t,e,n._6);return Js(o._1,Xe(n._3,n._4,n._5,o._2),o._3)}if(r==="EQ")return Js(N("Just",n._4),n._5,n._6)}g()},w_=(t,e,n,r)=>{if(r.tag==="Leaf")return x_(t,e,n);if(r.tag==="Node"){const o=w_(r._3,r._4,r._5,r._6);return x_(o._1,o._2,Xe(t,e,n,o._3))}g()},Mo=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=w_(t._3,t._4,t._5,t._6);return Xe(n._1,n._2,n._3,e)}g()},$n=(t,e,n)=>{if(e.tag==="Leaf")return I;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=zo(t,n._3,e);return Mo($n(t,r._2,n._5),$n(t,r._3,n._6))}g()},Ns=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return I;if(r.tag==="Node"){const o=zo(t,r._3,n),i=Ns(t,e,o._2,r._5),s=Ns(t,e,o._3,r._6);if(o._1.tag==="Just")return Xe(r._3,e(o._1._1)(r._4),i,s);if(o._1.tag==="Nothing")return Mo(i,s)}g()},Qe=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const o=zo(t,r._3,n),i=Qe(t,e,o._2,r._5),s=Qe(t,e,o._3,r._6);if(o._1.tag==="Just")return Xe(r._3,e(o._1._1)(r._4),i,s);if(o._1.tag==="Nothing")return Xe(r._3,r._4,i,s)}g()},J_=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return I;if(o.tag==="Node"){const i=t.compare(n)(o._3);if(i==="LT")return Xe(o._3,o._4,r(o._5),o._6);if(i==="GT")return Xe(o._3,o._4,o._5,r(o._6));if(i==="EQ"){const s=e(o._4);if(s.tag==="Nothing")return Mo(o._5,o._6);if(s.tag==="Just")return te("Node",o._1,o._2,o._3,s._1,o._5,o._6)}}g()};return r},K0=t=>e=>{const n=r=>{if(r.tag==="Leaf")return I;if(r.tag==="Node"){const o=e(r._3)(r._4);if(o.tag==="Just")return Xe(r._3,o._1,n(r._5),n(r._6));if(o.tag==="Nothing")return Mo(n(r._5),n(r._6))}g()};return n},Fn=(t=>e=>n=>{let r=n,o=!0,i;for(;o;){const s=r;if(s.tag==="IterLeaf"){o=!1,i=e();continue}if(s.tag==="IterEmit"){o=!1,i=t(s._1,s._2,s._3);continue}if(s.tag==="IterNode"){r=(a=>u=>{let c=a,_=u,d=!0,l;for(;d;){const f=c,h=_;if(h.tag==="Leaf"){d=!1,l=f;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){c=rn("IterEmit",h._3,h._4,f),_=h._5;continue}c=rn("IterEmit",h._3,h._4,rn("IterNode",h._6,f)),_=h._5;continue}g()}return l})(s._2)(s._1);continue}g()}return i})((t,e,n)=>N("Just",b(b(t,e),n)))(t=>J),Qt=t=>e=>n=>r=>{const o=i=>{if(i.tag==="Leaf")return te("Node",1,1,n,r,I,I);if(i.tag==="Node"){const s=t.compare(n)(i._3);if(s==="LT")return Xe(i._3,i._4,o(i._5),i._6);if(s==="GT")return Xe(i._3,i._4,i._5,o(i._6));if(s==="EQ")return te("Node",i._1,i._2,n,e(i._4)(r),i._5,i._6)}g()};return o},rt=t=>e=>n=>{const r=o=>{if(o.tag==="Leaf")return te("Node",1,1,e,n,I,I);if(o.tag==="Node"){const i=t.compare(e)(o._3);if(i==="LT")return Xe(o._3,o._4,r(o._5),o._6);if(i==="GT")return Xe(o._3,o._4,o._5,r(o._6));if(i==="EQ")return te("Node",o._1,o._2,e,n,o._5,o._6)}g()};return r},ce=t=>e=>e.foldl(n=>r=>rt(t)(r._1)(r._2)(n))(I),Wo=t=>e=>{const n=r=>{if(r.tag==="Leaf")return I;if(r.tag==="Node"){const o=t.compare(e)(r._3);if(o==="LT")return Xe(r._3,r._4,n(r._5),r._6);if(o==="GT")return Xe(r._3,r._4,r._5,n(r._6));if(o==="EQ")return Mo(r._5,r._6)}g()};return n},N_=t=>{const e=t.compare;return n=>r=>o=>{const i=zo(e,r,o),s=n(i._1);if(s.tag==="Nothing")return Mo(i._2,i._3);if(s.tag==="Just")return Xe(r,s._1,i._2,i._3);g()}},xe=function(t){return function(e){return t+e|0}},er=function(t){return function(e){return t+e}},Wr=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},Y0=function(t){return function(e){return t+e}},le=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},X0={append:Y0},j0={append:le},Z0={mempty:"",Semigroup0:()=>X0},tm={mempty:[],Semigroup0:()=>j0},ki=null;function mn(t,e,n){return t==null?e:n(t)}function N4(t){return t}function yu(t){return function(e){return function(n){return t.apply(n,[e])}}}const em=yu(Number.prototype.toPrecision),nm=yu(Number.prototype.toFixed),rm=yu(Number.prototype.toExponential),Oo=(t,e)=>({tag:t,_1:e}),qo=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Ho=t=>{if(t.tag==="Precision")return em(t._1);if(t.tag==="Fixed")return nm(t._1);if(t.tag==="Exponential")return rm(t._1);g()},v_=function(t){return function(){console.log(t)}};function om(){return Date.now()}function T_(t){return function(){return t.getContext("2d")}}function C_(t){return function(){return t.width}}function b_(t){return function(){return t.height}}function k_(t){return function(e){return function(){t.width=e}}}function S_(t){return function(e){return function(){t.height=e}}}function xu(t){return function(e){return function(){t.lineWidth=e}}}function im(t){return function(e){return function(){t.fillStyle=e}}}function sm(t){return function(e){return function(){t.strokeStyle=e}}}function wu(t){return function(e){return function(){t.lineCap=e}}}function Ju(t){return function(e){return function(){t.lineJoin=e}}}function am(t){return function(e){return function(){t.globalCompositeOperation=e}}}function um(t){return function(e){return function(){t.globalAlpha=e}}}function L_(t){return function(){t.beginPath()}}function Nu(t){return function(){t.stroke()}}function vu(t){return function(){t.fill()}}function cm(t){return function(){t.clip()}}function Si(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function E_(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function G_(t){return function(){t.closePath()}}function gm(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function _m(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function vs(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function P_(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function fm(t){return function(e){return function(){t.transform(e.a,e.b,e.c,e.d,e.e,e.f)}}}function dm(t){return function(e){return function(){t.textAlign=e}}}function lm(t){return function(e){return function(){t.textBaseline=e}}}function hm(t){return function(e){return function(){t.font=e}}}function pm(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function nr(t){return function(){t.save()}}function rr(t){return function(){t.restore()}}function Li(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function mm(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const B_=t=>t,Tu=t=>t,Cu=t=>t,bu=t=>t,Ts=t=>t,ym=Ts("BaselineTop"),xm=Ts("BaselineMiddle"),wm=Ts("BaselineAlphabetic"),Jm=Ts("BaselineBottom"),Nm=bu("AlignLeft"),vm=bu("AlignRight"),Tm=bu("AlignCenter"),ku=Cu("BevelJoin"),Su=Cu("RoundJoin"),Lu=Cu("MiterJoin"),Eu=Tu("Round"),Gu=Tu("Square"),Pu=Tu("Butt"),Cm=B_("SourceOver"),bm=B_("Difference"),km=t=>e=>lm(t)((()=>{if(e==="BaselineTop")return"top";if(e==="BaselineHanging")return"hanging";if(e==="BaselineMiddle")return"middle";if(e==="BaselineAlphabetic")return"alphabetic";if(e==="BaselineIdeographic")return"ideographic";if(e==="BaselineBottom")return"bottom";g()})()),Sm=t=>e=>dm(t)((()=>{if(e==="AlignLeft")return"left";if(e==="AlignRight")return"right";if(e==="AlignCenter")return"center";if(e==="AlignStart")return"start";if(e==="AlignEnd")return"end";g()})()),Bu=t=>e=>{if(e==="BevelJoin")return Ju(t)("bevel");if(e==="RoundJoin")return Ju(t)("round");if(e==="MiterJoin")return Ju(t)("miter");g()},Du=t=>e=>{if(e==="Round")return wu(t)("round");if(e==="Square")return wu(t)("square");if(e==="Butt")return wu(t)("butt");g()},D_=t=>e=>am(t)((()=>{if(e==="SourceOver")return"source-over";if(e==="SourceIn")return"source-in";if(e==="SourceOut")return"source-out";if(e==="SourceAtop")return"source-atop";if(e==="DestinationOver")return"destination-over";if(e==="DestinationIn")return"destination-in";if(e==="DestinationOut")return"destination-out";if(e==="DestinationAtop")return"destination-atop";if(e==="Lighter")return"lighter";if(e==="Copy")return"copy";if(e==="Xor")return"xor";if(e==="Multiply")return"multiply";if(e==="Screen")return"screen";if(e==="Overlay")return"overlay";if(e==="Darken")return"darken";if(e==="Lighten")return"lighten";if(e==="ColorDodge")return"color-dodge";if(e==="ColorBurn")return"color-burn";if(e==="HardLight")return"hard-light";if(e==="SoftLight")return"soft-light";if(e==="Difference")return"difference";if(e==="Exclusion")return"exclusion";if(e==="Hue")return"hue";if(e==="Saturation")return"saturation";if(e==="Color")return"color";if(e==="Luminosity")return"luminosity";g()})()),R_={foldrWithIndex:t=>e=>{const n=Ao(o=>{const i=o._1,s=o._2;return a=>t(i)(s)(a)})(e),r=Ht(Rn);return o=>n(r(o))},foldlWithIndex:t=>e=>{const n=v(o=>i=>t(i._1)(o)(i._2))(e),r=Ht(Rn);return o=>n(r(o))},foldMapWithIndex:t=>{const e=t.mempty;return n=>R_.foldrWithIndex(r=>o=>i=>t.Semigroup0().append(n(r)(o))(i))(e)},Foldable0:()=>Mt},fn={foldr:t=>e=>{const n=de.foldr(t)(e);return r=>n((()=>{const o=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return o(i._5,kt("Cons",i._3,o(i._6,s)));g()};return o(r,$)})())}},Lm=t=>{const e={append:(()=>{const n=t.compare;return r=>o=>Qe(n,Ie,r,o)})()};return{mempty:I,Semigroup0:()=>e}},Ei=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},Or=function(t){return t.join("")},vr=function(t){return t.split("")},Gi=function(t){return t},or=function(t){return t.length},A_=function(t){return function(e){return e.substr(0,t)}},$o=function(t){return function(e){return e.substring(t)}},I_=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},Em=t=>e=>{const n=I_(or(e)-or(t)|0)(e);return n.after===t?N("Just",n.before):J},ao=t=>e=>{const n=I_(or(t))(e);return n.before===t?N("Just",n.after):J},Gm=function(t){var e=null;return function(){return t===void 0||(e=t(),t=void 0),e}},Pm=function(t){return t()},Bm=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},Dm=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},uo=t=>BigInt(t),Rm=t=>Number(t),Cs=t=>e=>t+e,bs=t=>e=>t*e,Ru=t=>e=>t-e,F_=0n,ks=1n,Q_=t=>e=>t^e,Pi=t=>e=>t&e,Au=t=>e=>t<<e,Iu=t=>e=>t>>e,Am=t=>e=>t==e,Im=t=>e=>t===e?0:t>e?1:-1,Fm={eq:Am},z_={compare:t=>e=>{const n=Im(t)(e);return n===1?De:n===0?Ye:Be},Eq0:()=>Fm},Qm=Bm(Kt)(J),zm=Dm(Kt)(J),M_=function(t){throw new Error(t)},W_=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=ot.compare(e._1)(n._1);return r==="LT"?Be:r==="GT"?De:ot.compare(e._2)(n._2)},Eq0:()=>t}})(),Mm=t=>e=>Oe(t._1-e._1)+Oe(t._2-e._2),co=t=>t,Ss=t=>t,Se=Ss("North"),Le=Ss("South"),Tr=Ss("East"),Cr=Ss("West"),qr=co("Rectangle"),Wm=co("Cylinder"),Om=co("Parallelogram"),qm=co("Diamond"),Hm=co("Ellipse"),$m=co("Document"),Vm=co("Cloud"),O_=v(er)(0),Um=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Hr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ls=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},q_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Km=t=>{const e={top:0,bottom:0,left:0,right:0},n=t.shape==="Cloud"?{...e,top:t.h*.38}:t.shape==="Cylinder"?{...e,bottom:5}:t.shape==="Document"?{...e,bottom:t.h*.05}:e;return[{x:t.x-n.left,y:t.y-n.top},{x:t.x+t.w+n.right,y:t.y+t.h+n.bottom}]},go=t=>e=>{const n=Fe(s=>a=>({a:s,b:a,len:(()=>{const u=a.y-s.y,c=a.x-s.x;return $e(c*c+u*u)})()}),t,Rt(1,t.length,t)),r=O_(q(s=>s.len)(n)),o=Um(0)(r)(e*r),i=s=>a=>u=>{let c=s,_=a,d=u,l=!0,f;for(;l;){const h=c,p=_,m=d,w=Ft(x=>J,x=>y=>N("Just",{head:x,tail:y}),h);if(w.tag==="Nothing"){const x=t.length-1|0;if(x>=0&&x<t.length){l=!1,f=t[x];continue}l=!1,f=m;continue}if(w.tag==="Just"){if(p<=w._1.head.len){const x=w._1.head.len<=0?0:p/w._1.head.len;l=!1,f={x:w._1.head.a.x+(w._1.head.b.x-w._1.head.a.x)*x,y:w._1.head.a.y+(w._1.head.b.y-w._1.head.a.y)*x};continue}c=w._1.tail,_=p-w._1.head.len,d=m;continue}g()}return f};return 0<t.length?N("Just",i(n)(o)(t[0])):J},Ym=t=>e=>{const n=Hr(1e-6)(t.scale);return{x:(e.x-t.tx)/n,y:(e.y-t.ty)/n,w:e.w/n,h:e.h/n}},Bi=t=>O_(Fe(e=>n=>{const r=n.y-e.y,o=n.x-e.x;return $e(o*o+r*r)},t,Rt(1,t.length,t))),Xm=t=>e=>{const n=Hr(4)(.15*Ls(e.w)(e.h)),r=Hr(1)(t.w),o=Hr(1)(t.h),i=Hr(1)(e.w-2*n),s=Hr(1)(e.h-2*n),a=Ls(i/r)(s/o);return{scale:a,tx:e.x+n+(i-r*a)/2-t.x*a,ty:e.y+n+(s-o*a)/2-t.y*a}},Fu={scale:1,tx:0,ty:0},he=t=>{const e=Ft(n=>J,n=>r=>N("Just",{head:n,tail:r}),[...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,kt("Cons",r._4,n(r._6,o)));g()};return Et(Zt(de.foldr,n(t.nodes,$)))(Km)})(),...hn((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,kt("Cons",r._4,n(r._6,o)));g()};return Zt(de.foldr,n(t.edges,$))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=v(r=>o=>({minX:Ls(r.minX)(o.x),minY:Ls(r.minY)(o.y),maxX:Hr(r.maxX)(o.x),maxY:Hr(r.maxY)(o.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},jm=t=>e=>(n=>r=>o=>{let i=n,s=r,a=o,u=!0,c;for(;u;){const _=i,d=s,l=a,f=Ft(h=>J,h=>p=>N("Just",{head:h,tail:p}),d);if(f.tag==="Nothing"){u=!1,c=l;continue}if(f.tag==="Just"){const h=q_(f._1.head)(_.interiors);if(h.tag==="Nothing"){u=!1,c=l;continue}if(h.tag==="Just"){i=h._1,s=f._1.tail,a=(()=>{const p=Xm(he(h._1.layout))((()=>{const m=q_(f._1.head)(_.layout.nodes);if(m.tag==="Nothing")return{x:0,y:0,w:1,h:1,label:"",shape:qr};if(m.tag==="Just")return m._1;g()})());return{scale:l.scale*p.scale,tx:l.scale*p.tx+l.tx,ty:l.scale*p.ty+l.ty}})();continue}}g()}return c})(t)(e)(Fu),Zm=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},t2=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Es=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},e2=t=>e=>n=>r=>{const o=he(e);return n<=0||r<=0||o.w<=0||o.h<=0?1:t?Zm(o.w/n)(o.h/r):t2(o.w/n)(o.h/r)},H_=t=>e=>n=>{const r=t.widthPx/t.heightPx,o=n.w/n.h;if(t.widthPx<=0||t.heightPx<=0){const s=1/Es(.05)(1)(e);return{w:n.w*s,h:n.h*s}}if(r>o){const s=1/Es(.05)(1)(e);return{w:n.h*r*s,h:n.h*s}}const i=1/Es(.05)(1)(e);return{w:n.w*i,h:n.w/r*i}},$_=t=>e=>n=>r=>o=>{const i=t+o/2,s=t+e-o/2,a=t+e/2,u=n+r/2;return o>=e?a:Es(i)(s)(u)},V_=t=>e=>n=>r=>{const o=he(t);return{x:$_(o.x)(o.w)(e.x)(e.w)(n),y:$_(o.y)(o.h)(e.y)(e.h)(r)}},U_=t=>e=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:e2(t)(e)(n.w)(n.h)}),n2=t=>e=>n=>r=>{const o={x:r.x-t.padding,y:r.y-t.padding,w:r.w+t.padding*2,h:r.h+t.padding*2},i=H_(e)(.65)(o),s=V_(n)(o)(i.w)(i.h),a={x:s.x-i.w/2,y:s.y-i.h/2,w:i.w,h:i.h};return{focus:r,paddedFocus:o,viewport:a,camera:U_(e.widthPx>0&&e.heightPx>0)(n)(a)}},r2=t=>e=>n=>r=>o=>i=>{const s=he(r),a={x:s.x*o.scale+o.tx,y:s.y*o.scale+o.ty,w:s.w*o.scale,h:s.h*o.scale},u=t.padding*o.scale,c={x:a.x-u,y:a.y-u,w:a.w+u*2,h:a.h+u*2},_=H_(e)(.7)(c),d=V_(n)(c)(_.w)(_.h),l={x:d.x-_.w/2,y:d.y-_.h/2,w:_.w,h:_.h};return{footprint:a,viewport:l,camera:U_(e.widthPx>0&&e.heightPx>0)(n)(l)}},K_=t=>t,o2=(t,e)=>({tag:t,_1:e}),Qu=t=>t,Vo=(t,e)=>({tag:t,_1:e}),zu=(t,e)=>({tag:t,_1:e}),Di=Qu("Animated"),i2=Qu("StaticStill"),s2=Qu("TitleCard"),a2=zu("First"),Y_=K_("Forward"),X_=K_("Backward"),u2=Vo("ExitNode"),j_=ce(P)(Mt),c2=t=>Ao(e=>n=>({nodes:Qe(P.compare,Ie,e.nodes,n.nodes),edges:Qe(P.compare,Ie,e.edges,n.edges)}))({nodes:I,edges:I})(t.keyframes),g2=t=>e=>({entering:{nodes:$n(P.compare,e.nodes,t.nodes),edges:$n(P.compare,e.edges,t.edges)},leaving:{nodes:$n(P.compare,t.nodes,e.nodes),edges:$n(P.compare,t.edges,e.edges)},surviving:{nodes:Ns(P.compare,Ie,t.nodes,e.nodes),edges:Ns(P.compare,Ie,t.edges,e.edges)}}),Gs=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Uo=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ps=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Mu=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},_2=v(t=>e=>rt(P)(e)()(t))(I),f2=v(t=>e=>rt(P)(e)()(t))(I),d2=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),Z_=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},tf=ce(P)(Mt),Wu=t=>{const e=Ft(n=>J,n=>r=>N("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=v(r=>o=>({minX:Gs(r.minX)(o.x),minY:Gs(r.minY)(o.y),maxX:Uo(r.maxX)(o.x),maxY:Uo(r.maxY)(o.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},l2=t=>e=>n=>_2(Et(Zt(fn.foldr,n))(r=>{const o=Ps(r)(t);if(o.tag==="Just")return ft(i=>!Mu(i)(e),[o._1.source,o._1.target]);if(o.tag==="Nothing")return[];g()})),h2=t=>t.kind.tag==="SendToken"?N("Just",b(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):J,p2=t=>t.tag==="DataFlow"?vt(h2)(t._1.events):[],m2=t=>e=>f2(vt(n=>Mu(n._2.source)(e)||Mu(n._2.target)(e)?N("Just",n._1):J)(d2(t))),ir=t=>{const e=Ft(n=>J,n=>r=>N("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=v(r=>o=>({minX:Gs(r.minX)(o.x),minY:Gs(r.minY)(o.y),maxX:Uo(r.maxX)(o.x+o.w),maxY:Uo(r.maxY)(o.y+o.h)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x+e._1.head.w,maxY:e._1.head.y+e._1.head.h})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}g()},Ou=t=>e=>n=>{if(n.tag==="Leaf")return he(t);const r=m2(e)(n),o=[...vt(i=>{const s=Z_(i)(t.nodes);return s.tag==="Just"?N("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):J})(Zt(fn.foldr,Qe(P.compare,Ie,n,l2(e)(n)(r)))),...vt(i=>{const s=Ps(i)(t.edges);return s.tag==="Just"?N("Just",Wu(s._1)):J})(Zt(fn.foldr,r))];return o.length===0?he(t):ir(o)},Bs=t=>e=>n=>{const r=[...vt(o=>o)([(()=>{const o=Ps(n)(t.edges);return o.tag==="Just"?N("Just",Wu(o._1)):J})()]),...(()=>{const o=Ps(n)(e);if(o.tag==="Just")return vt(i=>{const s=Z_(i)(t.nodes);return s.tag==="Just"?N("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):J})([o._1.source,o._1.target]);if(o.tag==="Nothing")return[];g()})()];return r.length===0?Ou(t)(e)(I):ir(r)},_o=t=>e=>{const n=he(t),r=n.w/Uo(1e-4)(e.zoom),o=n.h/Uo(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-o/2,w:r,h:o}},y2=t=>Qe(P.compare,Ie,tf(q(e=>b(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),tf(Et(t.scenes)(p2))),qu=t=>t,x2=t=>t,ef=qu("Linear"),$r=qu("EaseInOutQuad"),w2=qu("SpringBouncy"),Ri=t=>e=>n=>{const r=$e(1-e*e),o=t*r;return 1-Qo(-e*t*n)*(Sn(o*n)+e/r*pn(o*n))},J2=t=>{const e=ot.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ot.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},Vr=t=>e=>(()=>{if(t==="Linear")return x2;if(t==="EaseInQuad")return n=>n*n;if(t==="EaseOutQuad")return n=>1-(1-n)*(1-n);if(t==="EaseInOutQuad")return n=>n<.5?2*n*n:1-2*(1-n)*(1-n);if(t==="EaseInCubic")return n=>n*n*n;if(t==="EaseOutCubic")return n=>1-(1-n)*(1-n)*(1-n);if(t==="EaseInOutCubic")return n=>n<.5?4*n*n*n:1-(-2*n+2)*(-2*n+2)*(-2*n+2)/2;if(t==="EaseOutExpo")return n=>n>=1?1:1-mu(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*Qo(-6*n);if(t==="SpringBouncy")return Ri(6)(.7);g()})()(J2(e)),Ds=t=>t,nf=t=>t,rf=t=>t,yn=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ai=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Hu=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},N2=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?Be:n==="GT"?De:ot.compare(t._2)(e._2)},v2=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},T2=rf("Hold"),C2=rf("Gap"),br=nf("LinearLerp"),of=nf("StagedLogLerp"),$u=Ds("Overview"),sf=Ds("DiveHome"),af=Ds("DiveTransition"),Rs=Ds("ActionFocus"),b2=t=>e=>n=>{const r=t.widthPx>0&&t.heightPx>0,o=t.widthPx/yn(1e-6)(t.heightPx),i=he(e),s=i.w/yn(1e-6)(n.zoom),a=i.h/yn(1e-6)(n.zoom),u=s/yn(1e-6)(a),c=r&&o<u?s/o:a,_=r&&o>u?a*o:s;return{x:n.center.x-_/2,y:n.center.y-c/2,w:_,h:c}},k2=t=>e=>n=>{const r=n.center.y-e.center.y,o=n.center.x-e.center.x,i=$e(o*o+r*r),s=n.zoom-e.zoom,a=s<0?-s:s;return Ai(t.minTransition)(t.maxTransition)(yn(t.panSpeed<=0?t.minTransition:i/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:a/t.zoomSpeed))},S2=t=>({startT:t.startT,endT:t.endT,fromCam:t.fromCam,toCam:t.toCam,easing:t.easing,interp:t.interp,intent:t.intent}),uf=t=>e=>Vr($r)(Ai(0)(1)((e-t)/yn(1e-4)(1-t))),cf=t=>e=>Vr($r)(Ai(0)(1)(e/yn(1e-4)(t))),L2=v(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:St(t)(e)})([]),E2=t=>e=>{const n=t.x-e.x;return(n<0?-n<.001:n<.001)&&(()=>{const r=t.y-e.y;return(r<0?-r<.001:r<.001)&&(()=>{const o=t.w-e.w;return(o<0?-o<.001:o<.001)&&(()=>{const i=t.h-e.h;return i<0?-i<.001:i<.001})()})()})()},G2=t=>e=>t.tag==="Just"?e.tag==="Just"&&E2(t._1)(e._1):t.tag==="Nothing"&&e.tag==="Nothing",gf=t=>e=>n=>r=>({center:{x:r.center.x*n.scale+n.tx,y:r.center.y*n.scale+n.ty},zoom:r.zoom*he(t).w/yn(1e-6)(n.scale*he(e).w)}),_f=t=>e=>n=>r=>({center:{x:t.center.x+(e.center.x-t.center.x)*n,y:t.center.y+(e.center.y-t.center.y)*n},zoom:Qo((()=>{const o=ws(yn(1e-6)(t.zoom));return o+(ws(yn(1e-6)(e.zoom))-o)*r})())}),P2=v(t=>e=>{if(t.tag==="Nothing")return N("Just",e);if(t.tag==="Just")return e.endT>t._1.endT?N("Just",e):N("Just",t._1);g()})(J),B2=t=>e=>n=>r=>{if(t<=0)return r;const o=Qo(-t*e);return{center:{x:r.center.x+(n.center.x-r.center.x)*o,y:r.center.y+(n.center.y-r.center.y)*o},zoom:Qo((()=>{const i=ws(yn(1e-6)(r.zoom));return i+(ws(yn(1e-6)(n.zoom))-i)*o})())}},D2=t=>e=>n=>e.zoom>=t.zoom?uf(.18000000000000005)(n):cf(.82)(n),R2=t=>e=>n=>e.zoom>=t.zoom?cf(.28)(n):uf(.72)(n),A2=t=>e=>n=>_f(t)(e)(R2(t)(e)(n))(D2(t)(e)(n)),I2=t=>e=>n=>{const r=n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT),o=Vr(n.easing)(Ai(0)(1)(r));if(n.interp==="LinearLerp")return{center:{x:n.fromCam.center.x+(n.toCam.center.x-n.fromCam.center.x)*o,y:n.fromCam.center.y+(n.toCam.center.y-n.fromCam.center.y)*o},zoom:n.fromCam.zoom+(n.toCam.zoom-n.fromCam.zoom)*o};if(n.interp==="LogLerp")return _f(n.fromCam)(n.toCam)(o)(o);if(n.interp==="StagedLogLerp")return A2(n.fromCam)(n.toCam)(r);g()},F2={widthPx:0,heightPx:0},Q2={padding:24,easing:$r,minimumReadableLabelPx:11,minimumVisibleLabelPx:5,labelBasePx:11,panSpeed:1500,zoomSpeed:4,minTransition:.15,maxTransition:.6,cameraDecay:0},Ko=t=>e=>n=>r=>o=>{const i=b2(e)(n)(r),s=o.x-t.padding,a=o.y-t.padding;return s>=i.x&&a>=i.y&&s+o.w+t.padding*2<=i.x+i.w&&a+o.h+t.padding*2<=i.y+i.h},z2=t=>e=>n=>r=>o=>R_.foldlWithIndex(i=>s=>a=>{const u=(()=>{if(a.kind==="Hold"){const c=(()=>{if(i===0)return a.toCam;if(a.focus.tag==="Just"){if(a.intent==="ActionFocus")return Ko(t)(e)(n)(s.prev)(a.focus._1)?s.prev:Ko(t)(e)(n)({center:s.prev.center,zoom:a.toCam.zoom})(a.focus._1)?{...a.toCam,center:s.prev.center}:{...a.toCam,center:{...a.toCam.center,x:(()=>{const _=he(n).w/yn(1e-6)(a.toCam.zoom);if(_<=0)return a.toCam.center.x;const d=a.focus._1.x+a.focus._1.w/2,l=e.widthPx<=0?0:Hu(_/4)(6*_/e.widthPx),f=s.prev.center.x+_/2-l,h=d<s.prev.center.x-_/2+l?d-l+_/2:d>f?d+l-_/2:s.prev.center.x,p=he(n);return _>=p.w?p.x+p.w/2:Ai(p.x+_/2)(p.x+p.w-_/2)(h)})()}};if(Ko(t)(e)(n)(s.prev)(a.focus._1))return s.prev;if(Ko(t)(e)(n)({center:s.prev.center,zoom:a.toCam.zoom})(a.focus._1))return{...a.toCam,center:s.prev.center}}return a.toCam})();return{startT:a.startT,endT:a.endT,fromCam:c,toCam:c,easing:a.easing,interp:br,focus:a.focus,intent:a.intent}}if(a.kind==="Gap")return{startT:a.startT,endT:a.endT,fromCam:s.prev,toCam:(()=>{const c=i+1|0,_=io(Kt,J,d=>d.kind==="Hold",c<1?o:Rt(c,o.length,o));if(_.tag==="Just"){const d=(i+1|0)+_._1|0;return d>=0&&d<o.length?(()=>{if(o[d].focus.tag==="Just")return Ko(t)(e)(n)(s.prev)(o[d].focus._1);if(o[d].focus.tag==="Nothing")return!1;g()})()?s.prev:o[d].fromCam:s.prev}if(_.tag==="Nothing")return s.prev;g()})(),easing:a.easing,interp:br,focus:J,intent:a.intent};g()})();return{acc:St(s.acc)(u),prev:u.toCam}})({acc:[],prev:r})(o).acc,M2=t=>e=>n=>r=>o=>{const i=(a,u)=>Hu(k2(t)(a.toCam)(u.toCam))(a.endT-a.startT),s=v(a=>u=>{if(a.pending.tag==="Nothing")return{acc:a.acc,pending:N("Just",u)};if(a.pending.tag==="Just")return!(u.fromCam.zoom===u.toCam.zoom&&u.fromCam.center.x===u.toCam.center.x&&u.fromCam.center.y===u.toCam.center.y)||(()=>{if(u.focus.tag==="Just")return Ko(t)(e)(n)(a.pending._1.toCam)(u.focus._1);if(u.focus.tag==="Nothing")return!1;g()})()||(()=>{const c=a.pending._1.toCam.center.x-u.toCam.center.x;return(c<0?-c<8:c<8)&&(()=>{const _=a.pending._1.toCam.center.y-u.toCam.center.y;return(_<0?-_<8:_<8)&&(()=>{const d=a.pending._1.toCam.zoom-u.toCam.zoom;return d<0?-d<.08:d<.08})()})()})()||i(a.pending._1,u)<=0?{acc:St(a.acc)(a.pending._1),pending:N("Just",u)}:{acc:St(St(a.acc)({...a.pending._1,endT:u.startT-i(a.pending._1,u)}))({startT:u.startT-i(a.pending._1,u),endT:u.startT,fromCam:a.pending._1.toCam,toCam:u.toCam,easing:u.easing,interp:br,focus:u.focus,intent:u.intent}),pending:N("Just",u)};g()})({acc:[],pending:J})(o);if(s.pending.tag==="Nothing")return s.acc;if(s.pending.tag==="Just")return St(s.acc)(s.pending._1);g()},W2=t=>e=>n=>{const r=e.w+n*2,o=e.h+n*2,i=he(t);return r<=0||o<=0||i.w<=0||i.h<=0?1:Hu(i.w/r)(i.h/o)},O2=t=>e=>{if(t.tag==="Just"){if(e.tag==="Just")return N("Just",ir([t._1,e._1]));if(e.tag==="Nothing")return N("Just",t._1);g()}if(t.tag==="Nothing"){if(e.tag==="Just")return N("Just",e._1);if(e.tag==="Nothing")return J}g()},q2=v(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?N("Just",t[n]):J;return r.tag==="Just"&&r._1.fromCam.zoom===r._1.toCam.zoom&&r._1.fromCam.center.x===r._1.toCam.center.x&&r._1.fromCam.center.y===r._1.toCam.center.y&&e.fromCam.zoom===e.toCam.zoom&&e.fromCam.center.x===e.toCam.center.x&&e.fromCam.center.y===e.toCam.center.y&&(!(r._1.intent==="ActionFocus"||e.intent==="ActionFocus")||(r._1.intent==="Overview"?e.intent==="Overview":r._1.intent==="DiveHome"?e.intent==="DiveHome":r._1.intent==="DiveTransition"?e.intent==="DiveTransition":r._1.intent==="ActionFocus"&&e.intent==="ActionFocus")&&G2(r._1.focus)(e.focus))&&(()=>{const o=r._1.toCam.center.x-e.toCam.center.x;return(o<0?-o<8:o<8)&&(()=>{const i=r._1.toCam.center.y-e.toCam.center.y;return(i<0?-i<8:i<8)&&(()=>{const s=r._1.toCam.zoom-e.toCam.zoom;return s<0?-s<.08:s<.08})()})()})()?St((()=>{const o=t.length-1|0;return o<1?[]:Rt(0,o,t)})())({...r._1,endT:e.endT,focus:O2(r._1.focus)(e.focus)}):St(t)(e)})([]),H2=t=>{const e=Pt(n=>r=>N2(b((()=>{if(r.intent==="DiveTransition")return 3;if(r.intent==="ActionFocus")return 2;if(r.intent==="DiveHome")return 1;if(r.intent==="Overview")return 0;g()})(),r.startT))(b((()=>{if(n.intent==="DiveTransition")return 3;if(n.intent==="ActionFocus")return 2;if(n.intent==="DiveHome")return 1;if(n.intent==="Overview")return 0;g()})(),n.startT)))(t);return 0<e.length?N("Just",e[0]):J},Vu=t=>e=>n=>r=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:yn(r)(W2(e)(n)(t.padding))}),$2=t=>e=>n=>r=>o=>{const i=Vu(t)(n)(he(n))(0),s=ft(u=>u>=0&&u<=r,L2(Pt(ot.compare)([0,r,...Et(o)(u=>[u.startT,u.endT])]))),a=(u,c)=>Ne(_=>_.priority>=1,ft(_=>_.startT<=c&&c<_.endT,o))?n2(t)(e)(n)(ir(u)).camera:Vu(t)(n)(ir(u))(0);return q(S2)(M2(t)(e)(n)(i)(q2(z2(t)(e)(n)(i)(vt(u=>{const c=(u._1+u._2)/2;if(u._2<=u._1)return J;const _=q(d=>d.bbox)(ft(d=>d.priority===v(v2)(0)(q(l=>l.priority)(ft(l=>l.startT<=c&&c<l.endT,o))),ft(d=>d.startT<=c&&c<d.endT,o)));return _.length===0?N("Just",{kind:C2,startT:u._1,endT:u._2,fromCam:i,toCam:i,easing:t.easing,focus:J,intent:$u}):N("Just",{kind:T2,startT:u._1,endT:u._2,fromCam:a(_,c),toCam:a(_,c),easing:t.easing,focus:N("Just",ir(_)),intent:Ne(d=>d.priority>=1,ft(d=>d.startT<=c&&c<d.endT,o))?Rs:$u})})(Fe(Rn,s,Rt(1,s.length,s)))))))},Ii=t=>e=>n=>r=>{const o=H2(ft(i=>r>=i.startT&&r<i.endT,n));if(o.tag==="Just")return{camera:I2()(r)(o._1),intent:o._1.intent};if(o.tag==="Nothing"){const i=P2(n);return i.tag==="Just"&&r>=i._1.endT?{camera:i._1.toCam,intent:i._1.intent}:{camera:(()=>{const s=Vu(t)(e)(he(e))(0);return 0<n.length?n[0].fromCam:s})(),intent:0<n.length?n[0].intent:$u}}g()};function Ur(t){return t.charCodeAt(0)}function ff(t){return String.fromCharCode(t)}const Qn=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},Kr=function(t){return function(e){return e.split(t)}},As=function(t){return t.trim()},sr=function(t){return function(e){return e.join(t)}};var V2=typeof Array.from=="function",U2=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",K2=typeof String.prototype.fromCodePoint=="function",Y2=typeof String.prototype.codePointAt=="function";const X2=function(t){return Y2?function(e){return e.codePointAt(0)}:t},j2=function(t){return K2?String.fromCodePoint:t},Z2=function(t){return function(e){return U2?function(n){for(var r="",o=n[Symbol.iterator](),i=0;i<e;++i){var s=o.next();if(s.done)return r;r+=s.value}return r}:t(e)}},ty=function(t){return function(e){return V2?function(n){return Array.from(n,e)}:t}},Is=t=>{const e=or(t);if(e===0)return J;if(e===1)return N("Just",{head:Ur(Ei(0)(t)),tail:""});const n=Ur(Ei(1)(t)),r=Ur(Ei(0)(t));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?N("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:$o(2)(t)}):N("Just",{head:r,tail:$o(1)(t)})},ey=t=>{const e=Is(t);return e.tag==="Just"?N("Just",b(e._1.head,e._1.tail)):J},ny=t=>nn.unfoldr(ey)(t),df=X2(t=>{const e=Ur(Ei(0)(t));if(55296<=e&&e<=56319&&or(t)>1){const n=Ur(Ei(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),Yo=ty(ny)(df),ry=t=>Yo(t).length,Uu=t=>Gi(t>=0&&t<=65535?ff(t):t<0?"\0":"\uFFFF"),oy=j2(t=>t<=65535?Uu(t):Uu(Jr(t-65536|0,1024)+55296|0)+Uu(Wr(t-65536|0)(1024)+56320|0)),lf=t=>e=>{if(t<1)return"";const n=Is(e);return n.tag==="Just"?oy(n._1.head)+lf(t-1|0)(n._1.tail):e},Re=Z2(lf),iy=t=>e=>e===""?J:N("Just",df(e)),hf=t=>t,Fs=(t,e)=>({tag:t,_1:e}),zn=(t,e,n)=>({tag:t,_1:e,_2:n}),pf=t=>t,Xo=(t,e,n,r,o,i,s,a,u)=>({tag:t,_1:e,_2:n,_3:r,_4:o,_5:i,_6:s,_7:a,_8:u}),Ku=pf("PlopIn"),sy=pf("PlopOut"),ay=hf("DiveIn"),uy=hf("DiveOut"),jo=(t,e,n)=>({tag:t,_1:e,_2:n}),cy=t=>t,Zo=(t,e)=>({tag:t,_1:e}),Yu=t=>t,Qs=(t,e)=>({tag:t,_1:e}),Xu=Qs("NotYet"),mf=Qs("Consumed"),gy=Yu("FromSource"),yf=Yu("FromTarget"),_y=Yu("FromBoth"),ju=Zo("Hidden"),fy=Zo("Visible"),Zu=cy("ExtendFromSource"),tc=jo("Retracted"),xf=jo("Extended"),dy={eq:t=>e=>t.tag==="Retracted"?e.tag==="Retracted":t.tag==="Extending"?e.tag==="Extending"&&(t._1==="ExtendFromSource"?e._1==="ExtendFromSource":t._1==="ExtendFromTarget"&&e._1==="ExtendFromTarget")&&t._2===e._2:t.tag==="Extended"?e.tag==="Extended":t.tag==="Retracting"&&e.tag==="Retracting"&&(t._1==="FromSource"?e._1==="FromSource":t._1==="FromTarget"?e._1==="FromTarget":t._1==="FromBoth"&&e._1==="FromBoth")&&t._2===e._2},ec=t=>t,wf=ce(P)(Mt),Fi={eq:hu(Ti)},nc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},kr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jf=Mt.foldMap(Lm(P)),ly=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},hy=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),ti=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},py=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},my=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},yy=ce(P)(Mt),xy=ce(P)(Mt),wy=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Nf=ec("Backdrop"),Jy=ec("FlyThrough"),dn=ec("Active"),Ny=t=>e=>n=>({...n,state:{...n.state,edgeFadeAlpha:wf(q(r=>b(r,e))(t))}}),vf=t=>e=>n=>{const r=(t+e)/2,o=n-r,i=o<0?-1:1,s=(e-t)/2,a=s*.15,u=s-a,c=o<0?-o:o;return e<=t?(t+e)/2:c<=u?n:r+i*(s-a*Qo(-(c-u)/a))},zs=t=>e=>n=>{const r=re(o=>Fi.eq(o.path)(e)&&n>=o.startT&&n<o.endT)(t.segments);if(r.tag==="Just")return N("Just",r._1);if(r.tag==="Nothing")return re(o=>Fi.eq(o.path)(e))(t.segments);g()},vy=t=>e=>{if(e.scene.tag==="Structural")return e.scene._1.to;if(e.scene.tag==="DataFlow")return e.scene._1.keyframe;if(e.scene.tag==="Hold")return e.scene._1;if(e.scene.tag==="EnterNode"||e.scene.tag==="ExitNode"||e.scene.tag==="StepScene")return t;g()},Ty=t=>({startT:0,endT:t.totalDuration,path:[],layout:t.layout,placement:Fu,windows:t.windows,spans:t.spans,keyframes:t.keyframes,initialKeyframe:t.initialKeyframe,edgeEndpoints:I}),Cy=t=>q(e=>e<1?[]:Rt(0,e,t))(Xt(0,t.length-1|0)),rc=t=>e=>{const n=nc(e)(t.keyframes);if(n.tag==="Nothing")return I;if(n.tag==="Just")return n._1.nodes;g()},oc=t=>e=>{const n=nc(e)(t.keyframes);if(n.tag==="Nothing")return I;if(n.tag==="Just")return n._1.edges;g()},by=v(t=>e=>{const n=Nr(t);return n.tag==="Just"&&e.startT<=n._1.last.endT+1e-6?St(n._1.init)({...n._1.last,endT:kr(n._1.last.endT)(e.endT),windows:St(n._1.last.windows)(e)}):St(t)({endT:e.endT,windows:[e]})})([]),ky=t=>e=>n=>Jf(r=>Jf(o=>o.target.tag==="FillWindow"?o.startT<=n?te("Node",1,1,o.target._2,void 0,I,I):I:o.target.tag==="TokenWindow"&&o.startT+(o.endT-o.startT)*.25<=n?te("Node",1,1,o.target._4,void 0,I,I):I)(r.windows))(ft(r=>n<=r.endT+t,by(Pt(r=>o=>ot.compare(r.startT)(o.startT))(ft(r=>r.target.tag==="FillWindow"||r.target.tag==="TokenWindow",e))))),Sy=t=>e=>n=>Ne(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),Ly=t=>e=>n=>Ne(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),Ey=t=>e=>n=>Ne(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),Gy=t=>e=>n=>Ne(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),Ms=t=>e=>n=>re(r=>n(r)&&e>=r.startT&&e<r.endT)(t),Ws=t=>e=>{if(e<t.startT)return zn("AtKeyframe",t.initialKeyframe);const n=re(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return zn("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return zn("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return zn("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode"||n._1.scene.tag==="StepScene")return zn("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing")return zn("AtKeyframe",v(vy)(t.initialKeyframe)(t.spans));g()},Py=t=>e=>{const n=Ws(t)(e),r=nc((()=>{if(n.tag==="AtKeyframe")return n._1;if(n.tag==="InTransition")return n._2;g()})())(t.keyframes);if(r.tag==="Just")return r._1.kind;if(r.tag==="Nothing")return Di;g()},By=t=>e=>{const n=Ws(t)(e);if(n.tag==="AtKeyframe")return Re(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return Re(3)(n._2)==="kf-"?"":n._2;g()},Dy={segment:{startT:0,endT:0,path:[],layout:{nodes:I,edges:I,chipExtras:I,edgeLabels:I},placement:Fu,windows:[],spans:[],keyframes:I,initialKeyframe:"",edgeEndpoints:I},state:{nodes:I,edges:I,tokens:I,camera:{center:{x:0,y:0},zoom:1},frameTitle:"",staticKind:Di,visited:I,nodeFadeAlpha:I,nodeLabelFadeAlpha:I,edgeFadeAlpha:I,nodeInvert:I},bgAlpha:1,blur:0,minis:[],role:dn},Os=t=>{const e=t.levels.length-1|0;return e>=0&&e<t.levels.length?t.levels[e]:Dy},Ry=t=>e=>{const n=ly(e)(t.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1,o=i=>i.x>=r.x-1&&i.x<=r.x+r.w+1&&i.y>=r.y-1&&i.y<=r.y+r.h+1;return vt(i=>(()=>{if(0<i._2.length){const a=i._2.length-1|0;return o(i._2[0])||a>=0&&a<i._2.length&&o(i._2[a])}const s=i._2.length-1|0;return s>=0&&s<i._2.length&&o(i._2[s])})()?N("Just",i._1):J)(hy(t.edges))}g()},Ay=t=>e=>{const n=Ws(t)(e);if(n.tag==="AtKeyframe")return rc(t)(n._1);if(n.tag==="InTransition")return Qe(P.compare,Ie,rc(t)(n._1),rc(t)(n._2));g()},Iy=t=>e=>{const n=Ws(t)(e);if(n.tag==="AtKeyframe")return oc(t)(n._1);if(n.tag==="InTransition")return Qe(P.compare,Ie,oc(t)(n._1),oc(t)(n._2));g()},Fy=t=>e=>n=>{const r=he(t),o=r.h/kr(1e-4)(n.zoom),i=r.w/kr(1e-4)(n.zoom);return{...n,center:{x:i>=e.w?e.x+e.w/2:vf(e.x+i/2)(e.x+e.w-i/2)(n.center.x),y:o>=e.h?e.y+e.h/2:vf(e.y+o/2)(e.y+e.h-o/2)(n.center.y)}}},Qy=t=>e=>n=>Fy(t)((()=>{const r=e*n.placement.scale,o=he(n.layout),i=(()=>{const s=o.x*n.placement.scale+n.placement.tx,a=o.y*n.placement.scale+n.placement.ty;return{x:s,y:a,w:(o.x+o.w)*n.placement.scale+n.placement.tx-s,h:(o.y+o.h)*n.placement.scale+n.placement.ty-a}})();return{x:i.x-r,y:i.y-r,w:i.w+r*2,h:i.h+r*2}})()),zy=t=>e=>{const n=t.endT-t.startT;return n<=0?1:kr(0)(ti(1)((e-t.startT)/n))},ei=t=>e=>{const n=t.endT-t.startT;return n<=0?1:kr(0)(ti(1)((e-t.startT)/n))},My=t=>e=>n=>r=>o=>{const i=Ms(e)(n)(s=>s.target.tag==="EdgeWindow"&&s.target._2.tag==="Retract"&&s.target._1===o);if(i.tag==="Just"){const s=Vr(t.timing.edgeEasing)(ei(i._1)(n)),a=i._1.target.tag==="EdgeWindow"?i._1.target._2:Fs("Extend",Zu);if(a.tag==="Retract")return jo("Retracting",a._1,s);if(a.tag==="Extend")return jo("Extending",a._1,s);g()}if(i.tag==="Nothing"){if(Sy(e)(n)(o))return tc;const s=Ms(e)(n)(a=>a.target.tag==="EdgeWindow"&&a.target._1===o);if(s.tag==="Just"){const a=Vr(t.timing.edgeEasing)(ei(s._1)(n)),u=s._1.target.tag==="EdgeWindow"?s._1.target._2:Fs("Extend",Zu);if(u.tag==="Retract")return jo("Retracting",u._1,a);if(u.tag==="Extend")return jo("Extending",u._1,a);g()}if(s.tag==="Nothing")return Gy(e)(n)(o)?tc:py(o)(r)?xf:tc}g()},Wy=t=>e=>n=>{const r=Iy(e)(n);return wf(q(o=>b(o,My(t)(e.windows)(n)(r)(o)))((()=>{const o=i=>{if(i.tag==="Leaf")return I;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,void 0,o(i._5),o(i._6));g()};return Zt(fn.foldr,o(e.layout.edges))})()))},Oy=t=>e=>n=>r=>{const o=Ms(t)(e)(i=>i.target.tag==="NodeWindow"&&i.target._1===r&&i.target._2==="PlopOut");if(o.tag==="Just"){const i=ei(o._1)(e),s=o._1.target.tag==="NodeWindow"?o._1.target._2:Ku;if(s==="PlopIn")return Zo("PloppingIn",i);if(s==="PlopOut")return Zo("PloppingOut",i);g()}if(o.tag==="Nothing"){if(Ly(t)(e)(r))return ju;const i=Ms(t)(e)(s=>s.target.tag==="NodeWindow"&&s.target._1===r);if(i.tag==="Just"){const s=ei(i._1)(e),a=i._1.target.tag==="NodeWindow"?i._1.target._2:Ku;if(a==="PlopIn")return Zo("PloppingIn",s);if(a==="PlopOut")return Zo("PloppingOut",s);g()}if(i.tag==="Nothing")return Ey(t)(e)(r)?ju:my(r)(n)?fy:ju}g()},qy=t=>e=>{const n=Ay(t)(e);return yy(q(r=>b(r,Oy(t.windows)(e)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return I;if(o.tag==="Node")return te("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));g()};return Zt(fn.foldr,r(t.layout.nodes))})()))},Hy=t=>e=>n=>e.target.tag==="TokenWindow"?b(e.target._1,n<e.startT?Xu:n>=e.endT?mf:Qs("Travelling",{edge:e.target._2,direction:e.target._3,progress:Vr(t.timing.tokenEasing)(ei(e)(n)),labels:e.target._6,source:e.target._4,target:e.target._5,holdPre:e.target._7,holdPost:e.target._8})):e.target.tag==="FillWindow"?b(e.target._1,n<e.startT?Xu:n>=e.endT?mf:Qs("Filling",{node:e.target._2,progress:ei(e)(n),labels:e.target._3})):b("",Xu),$y=t=>e=>n=>xy(q(r=>Hy(t)(r)(n))(ft(r=>r.target.tag==="TokenWindow"||r.target.tag==="FillWindow",e))),Vy=t=>e=>n=>({nodes:qy(e)(n),edges:Wy(t)(e)(n),tokens:$y(t)(e.windows)(n),camera:Ii(t.cameraConfig)(e.layout)(t.cameraSpans)(n).camera,frameTitle:By(e)(n),staticKind:Py(e)(n),visited:ky(t.timing.hatchHold)(e.windows)(n),nodeFadeAlpha:I,nodeLabelFadeAlpha:I,edgeFadeAlpha:I,nodeInvert:I}),ni=t=>e=>n=>r=>({segment:n,state:Vy(t)(n)(e),bgAlpha:1,blur:0,minis:Uy(t)(e)(n),role:r}),Uy=t=>e=>n=>vt(r=>{const o=zs(t)(St(n.path)(r))(e);if(o.tag==="Just")return N("Just",{...ni(t)(wy(o._1.startT)(o._1.endT-1e-4)(e))(o._1)(Nf),bgAlpha:0});if(o.tag==="Nothing")return J;g()})((()=>{const r=o=>{if(o.tag==="Leaf")return I;if(o.tag==="Node")return te("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));g()};return Zt(fn.foldr,r(n.layout.nodes))})()),Ky=t=>e=>n=>d_(J,a_,r=>r.direction==="DiveIn"&&Fi.eq(r.parentPath)(e.path)&&n>=r.startT-.7&&n<r.startT?N("Just",{node:r.node,phase:(n-(r.startT-.7))/.7}):J,t.dives),Yy=t=>e=>n=>r=>{const o=Ky(t)(e)(n);if(o.tag==="Just"){const i=pn(3.141592653589793*o._1.phase*3);return{...r,state:{...r.state,nodeInvert:te("Node",1,1,o._1.node,1*i*i,I,I)}}}if(o.tag==="Nothing")return r;g()},Tf=t=>e=>vt(n=>{const r=re(o=>o.direction==="DiveIn"&&Fi.eq(o.childPath)((()=>{const i=n.length+1|0;return i<1?[]:Rt(0,i,e)})()))(t.dives);if(r.tag==="Just"){const o=zs(t)(n)(r._1.startT-1e-4);if(o.tag==="Just")return N("Just",(()=>{const i=ni(t)(r._1.startT-1e-4)(o._1)(Nf);return{...i,state:{...i.state,nodeFadeAlpha:te("Node",1,1,r._1.node,0,I,I)}}})());if(o.tag==="Nothing")return J;g()}if(r.tag==="Nothing")return J;g()})(Cy(e)),Cf=t=>e=>{const n=ft(o=>e>=o.startT&&e<o.endT,t.segments),r=n.length-1|0;return r>=0&&r<n.length?n[r]:Ty(t)},Xy=t=>e=>n=>{const r=zy(n)(e),o=zs(t)(n.parentPath)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})()),i=zs(t)(n.childPath)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})()),s=(()=>{if(n.direction==="DiveIn")return Vr($r)(r);if(n.direction==="DiveOut")return 1-Vr($r)(r);g()})(),a=1-kr(0)(ti(1)((s-.1)/.25)),u=1-kr(0)(ti(1)((s-.1)/.25)),c=1-kr(0)(ti(1)((s-.8)/.2)),_=l=>{const f=ni(t)((()=>{if(n.direction==="DiveIn")return n.startT-1e-4;if(n.direction==="DiveOut")return n.endT-1e-4;g()})())(l)(Jy);return{...Ny(Ry(l.layout)(n.node))(u)({...f,state:{...f.state,nodeFadeAlpha:te("Node",1,1,n.node,a,I,I),nodeLabelFadeAlpha:te("Node",1,1,n.node,u,I,I)}}),minis:ft(h=>!Fi.eq(h.segment.path)(n.childPath),f.minis),bgAlpha:c}},d=0+1*kr(0)(ti(1)((s-.1)/.5));return[...Tf(t)(n.parentPath),...(()=>{if(o.tag==="Just"){if(i.tag==="Just")return[_(o._1),{...ni(t)((()=>{if(n.direction==="DiveIn")return n.endT;if(n.direction==="DiveOut")return n.startT-1e-4;g()})())(i._1)(dn),bgAlpha:d}];if(i.tag==="Nothing")return[_(o._1)];g()}if(o.tag==="Nothing")return[ni(t)(e)(Cf(t)(e))(dn)];g()})()]},jy=t=>e=>re(n=>e>=n.startT&&e<n.endT)(t.dives),Zy=t=>e=>{const n=Cf(t)(e),r=ni(t)(e)(n)(dn),o=t.dives.length!==0,i=Ii(t.cameraConfig)(t.layout)(t.cameraSpans)(e).camera,s=Qy(t.layout)(t.cameraConfig.padding)(n)(i),a=Yy(t)(n)(e)({...r,state:{...r.state,camera:s}}),u=Tf(t)(n.path),c=jy(t)(e);if(c.tag==="Just")return{levels:Xy(t)(e)(c._1),camera:i,rootLayout:t.layout,hasDives:o,diving:!0};if(c.tag==="Nothing")return{levels:St(u)(a),camera:s,rootLayout:t.layout,hasDives:o,diving:!1};g()},tx=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ex=t=>{const e=t.length;return(n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=i;if(u>=e){s=!1,a=c;continue}const _=d=>l=>{let f=d,h=l,p=!0,m;for(;p;){const w=f,x=h;if(w>=e){p=!1,m=x;continue}if(u>=0&&u<t.length){if(w>=0&&w<t.length){f=w+1|0,h=(()=>{const y=t[u].position,T=t[u].size,C=t[w].position,S=t[w].size;return y._1<C._1+S._1&&C._1<y._1+T._1&&y._2<C._2+S._2&&C._2<y._2+T._2})()?x+1|0:x;continue}f=w+1|0,h=x;continue}p=!1,m=x}return m};o=u+1|0,i=_(u+1|0)(c)}return a})(0)(0)},bf=t=>v(e=>n=>e+Mm(n.start)(n.end))(0)(t.segments),nx=t=>e=>n=>({crossingCount:v(r=>o=>r+o.jumps.length|0)(0)(e),bendCount:v(r=>o=>r+o.bends.length|0)(0)(e),totalEdgeLength:v(r=>o=>r+bf(o))(0)(e),maxEdgeLength:v(r=>o=>tx(r)(bf(o)))(0)(e),nodeOverlapCount:ex(t),constraintViolations:n,jumpCount:v(r=>o=>r+o.jumps.length|0)(0)(e)}),ic=t=>t,ue=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},sc=ic("LEFT"),rx=ic("RIGHT"),kf=ic("UNDEFINED"),ox={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},ix={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?Ye:Be;if(e==="LEFT")return De;if(t==="RIGHT")return e==="RIGHT"?Ye:Be;if(e==="RIGHT")return De;if(t==="UP")return e==="UP"?Ye:Be;if(e==="UP")return De;if(t==="DOWN")return e==="DOWN"?Ye:Be;if(e==="DOWN")return De;if(t==="UNDEFINED"&&e==="UNDEFINED")return Ye;g()},Eq0:()=>ox},sx=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){if(t==="LEFT"){if(i._3==="LEFT"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="LEFT"){n=i._6;continue}if(t==="RIGHT"){if(i._3==="RIGHT"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="RIGHT"){n=i._6;continue}if(t==="UP"){if(i._3==="UP"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="UP"){n=i._6;continue}if(t==="DOWN"){if(i._3==="DOWN"){r=!1,o=!0;continue}n=i._5;continue}if(i._3==="DOWN"){n=i._6;continue}if(t==="UNDEFINED"&&i._3==="UNDEFINED"){r=!1,o=!0;continue}}g()}return o},ax={x:0,y:0},xn=t=>e=>n=>{const r=ue(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:rt(it)(t)(e(r._1))(n.cNodes)};g()},Qi=t=>e=>n=>{const r=ue(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:rt(it)(t)(e(r._1))(n.cGroups)};g()},ux=t=>v(e=>n=>xn(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),cx=t=>{const e=v(n=>r=>{const o=ue(r)(t.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just")return v(i=>s=>Qt(it)(le)(s)([r])(i))(n)(o._1.constraints);g()})(I)(t.cNodeOrder);return v(n=>r=>xn(r)(o=>({...o,constraints:(()=>{const i=ue(r)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;g()})()}))(n))(t)(t.cNodeOrder)},gx=t=>e=>xn(t)(n=>({...n,ignoreSpacing:{left:n.ignoreSpacing.left||e.left,right:n.ignoreSpacing.right||e.right,up:n.ignoreSpacing.up||e.up,down:n.ignoreSpacing.down||e.down}})),_x=t=>{const e=v(n=>r=>Qi(r)(o=>({...o,outDegree:o.outDegreeReal}))(n))(t)(t.cGroupOrder);return v(n=>r=>xn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder)},Mn={left:!1,right:!1,up:!1,down:!1},fx={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},ac=t=>v(e=>n=>{const r=ue(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const o=v(s=>a=>{const u=ue(a)(e.cNodes);if(u.tag==="Nothing")return s;if(u.tag==="Just"){if(s.tag==="Nothing")return N("Just",a);if(s.tag==="Just"){const c=ue(s._1)(e.cNodes);if(c.tag==="Nothing")return N("Just",a);if(c.tag==="Just")return u._1.hitbox.x<c._1.hitbox.x?N("Just",a):N("Just",s._1)}}g()})(J)(r._1.cNodes),i=Qi(n)(s=>({...s,reference:o}))(e);if(o.tag==="Nothing")return i;if(o.tag==="Just"){const s=ue(o._1)(i.cNodes);if(s.tag==="Nothing")return i;if(s.tag==="Just"){const a=s._1;return v(u=>c=>xn(c)(_=>({..._,cGroupOffset:{x:_.hitbox.x-a.hitbox.x,y:_.hitbox.y-a.hitbox.y}}))(u))(i)(r._1.cNodes)}}}g()})(t)(t.cGroupOrder),wn=t=>ac({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return I;if(n.tag==="Node")return te("Node",n._1,n._2,n._3,{...n._4,hitbox:{...n._4.hitbox,x:-n._4.hitbox.x-n._4.hitbox.width}},e(n._5),e(n._6));g()};return e(t.cNodes)})()}),ar=t=>ac({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return I;if(n.tag==="Node")return te("Node",n._1,n._2,n._3,{...n._4,hitbox:{x:n._4.hitbox.y,y:n._4.hitbox.x,width:n._4.hitbox.height,height:n._4.hitbox.width},cGroupOffset:{x:n._4.cGroupOffset.y,y:n._4.cGroupOffset.x}},e(n._5),e(n._6));g()};return e(t.cNodes)})()}),Sf=t=>{const e=v(n=>r=>Qi(r)(o=>({...o,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return v(n=>r=>{const o=ue(r)(n.cNodes);if(o.tag==="Nothing")return n;if(o.tag==="Just"){if(o._1.cGroup.tag==="Nothing")return n;if(o._1.cGroup.tag==="Just"){const i=o._1.cGroup._1;return v(s=>a=>{const u=ue(a)(s.cNodes);if(u.tag==="Nothing")return s;if(u.tag==="Just")return u._1.cGroup.tag==="Just"&&u._1.cGroup._1!==i?Qi(u._1.cGroup._1)(c=>({...c,outDegree:c.outDegree+1|0,outDegreeReal:c.outDegreeReal+1|0}))(Qi(i)(c=>en(zr)(a)(c.incomingConstraints)?c:{...c,incomingConstraints:[...c.incomingConstraints,a]})(s)):s;g()})(n)(o._1.constraints)}}g()})(e)(e.cNodeOrder)},qs=t=>{const e=cx(t.cGraph);return{...t,cGraph:Sf(v(n=>r=>xn(r)(o=>({...o,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},dx=t=>e=>v(n=>r=>{if(t==="LEFT"||t==="UP"){const i=r._2;return xn(r._1)(s=>({...s,constraints:[...s.constraints,i]}))(n)}const o=r._1;return xn(r._2)(i=>({...i,constraints:[...i.constraints,o]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),Wn=t=>{const e={...t,cGraph:dx(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return I;if(r.tag==="Node")return te("Node",r._1,r._2,r._3,{...r._4,constraints:[]},n(r._5),n(r._6));g()};return n(t.cGraph.cNodes)})()})};return{...e,cGraph:Sf((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);g()})())}},lx=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?Wn(r):e==="RIGHT"?Wn({...r,cGraph:wn(r.cGraph)}):e==="UP"?Wn({...r,cGraph:ar(r.cGraph)}):e==="DOWN"?Wn({...r,cGraph:wn(ar(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?qs({...r,cGraph:wn(r.cGraph)}):e==="UP"?Wn({...r,cGraph:ar(r.cGraph)}):e==="DOWN"?Wn({...r,cGraph:wn(ar(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?qs({...r,cGraph:wn(r.cGraph)}):e==="UP"?Wn({...r,cGraph:ar(wn(r.cGraph))}):e==="DOWN"?Wn({...r,cGraph:wn(ar(wn(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?Wn({...r,cGraph:ar(r.cGraph)}):e==="RIGHT"?Wn({...r,cGraph:wn(ar(r.cGraph))}):e==="DOWN"?qs({...r,cGraph:wn(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?Wn({...r,cGraph:ar(wn(r.cGraph))}):e==="RIGHT"?Wn({...r,cGraph:wn(ar(wn(r.cGraph)))}):e==="UP"?qs({...r,cGraph:wn(r.cGraph)}):r;g()},Lf=t=>e=>e.finished||!sx(t)(e.cGraph.supportedDirections)||(t==="LEFT"?e.direction==="LEFT":t==="RIGHT"?e.direction==="RIGHT":t==="UP"?e.direction==="UP":t==="DOWN"?e.direction==="DOWN":t==="UNDEFINED"&&e.direction==="UNDEFINED")?e:lx(e.direction)(t)(e),hx=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?Lf(sc)(t):t,n={...e,cGraph:_x(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);g()},Ef=t=>e=>n=>{const r=ue(t)(n.cNodes),o=ue(e)(n.cGroups);return r.tag==="Just"&&o.tag==="Just"?(()=>{if(r._1.cGroup.tag==="Nothing")return!1;if(r._1.cGroup.tag==="Just")return!0;g()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:rt(it)(t)({...r._1,cGroup:N("Just",e)})(n.cNodes),cGroups:rt(it)(e)({...o._1,cNodes:en(zr)(t)(o._1.cNodes)?o._1.cNodes:[...o._1.cNodes,t],reference:(()=>{if(o._1.reference.tag==="Nothing")return N("Just",t);if(o._1.reference.tag==="Just")return N("Just",o._1.reference._1);g()})()})(n.cGroups)}:n},Gf=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:rt(it)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:J,cGroupOffset:ax,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308,ignoreSpacing:Mn})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),uc=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:v(r=>o=>Ef(o)(n)(r))({...e,cGroups:rt(it)(n)({id:n,master:t.master,cNodes:[],startPos:-1e308,incomingConstraints:[],outDegree:0,outDegreeReal:0,reference:J,delta:0,deltaNormalized:0})(e.cGroups),cGroupOrder:[...e.cGroupOrder,n],nextCGroupId:n+1|0})(t.nodes)}},px=t=>v(e=>n=>{const r=ue(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?uc({master:J,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),mx=t=>({cGraph:ux(px(ac(t))),direction:kf,compactionAlgorithm:J,constraintAlgorithm:J,spacingsHandler:fx,lockFun:J,finished:!1}),yx=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},xx=t=>e=>{const n=ot.compare(t._1)(e._1);return n==="LT"?Be:n==="GT"?De:it.compare(t._2)(e._2)},wx=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),Pf=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Bf=t=>t.kind.tag==="Nothing"?!1:t.kind.tag==="Just"&&t.kind._1==="vs",Df=t=>t.kind.tag==="Nothing"||!(t.kind.tag==="Just"&&t.kind._1==="vs"),Hs=t=>e=>xx(b(t.hitbox.x+t.hitbox.width/2,t.id))(b(e.hitbox.x+e.hitbox.width/2,e.id)),Jx=t=>e=>{const n=io(Kt,J,r=>Hs(t)(r)==="LT",e);if(n.tag==="Just"){const r=l_(Kt,J,n._1,t,e);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return St(e)(t);g()},Rf=t=>e=>{const n=ft(o=>Hs(o)(t)==="LT",e),r=n.length-1|0;return r>=0&&r<n.length?N("Just",n[r]):J},Nx=t=>e=>{const n=Jx(e)(t.intervals),r=re(i=>Hs(e)(i)==="LT")(n),o=rt(it)(e.id)((()=>{const i=Rf(e)(n);return i.tag==="Just"?N("Just",i._1.id):J})())(t.cand);return{...t,intervals:n,cand:(()=>{if(r.tag==="Just")return rt(it)(r._1.id)(N("Just",e.id))(o);if(r.tag==="Nothing")return o;g()})()}},vx=t=>e=>{const n=ot.compare(t.low?t.node.hitbox.y:t.node.hitbox.y+t.node.hitbox.height)(e.low?e.node.hitbox.y:e.node.hitbox.y+e.node.hitbox.height);return n==="EQ"?t.low?t.low&&!e.low?De:Ye:e.low?Be:Ye:n},Tx=t=>v(e=>n=>xn(n.id)(r=>({...r,constraints:[]}))(e))(t)(vt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),cc=t=>e=>v(n=>r=>{const o=ue(r._1)(n.cNodes);if(o.tag==="Just")return xn(r._1)(i=>({...i,constraints:[...i.constraints,...r._2]}))(n);if(o.tag==="Nothing")return n;g()})(e)(wx(t)),Af=t=>e=>e.kind.tag!=="Nothing"&&e.kind.tag==="Just"&&e.kind._1==="vs"?e.ignoreSpacing.up?e.ignoreSpacing.down?e:{...e,hitbox:{...e.hitbox,height:e.hitbox.height+t+.01}}:{...e,hitbox:{...e.hitbox,y:e.hitbox.y-t-.01,height:e.hitbox.height+t+.01}}:{...e,hitbox:{...e.hitbox,y:e.hitbox.y-t,height:e.hitbox.height+2*t}},If=t=>e=>n=>v(r=>o=>n(o)?xn(o.id)(Af(t))(r):r)(e)(vt(r=>ue(r)(e.cNodes))(e.cNodeOrder)),Cx=t=>e=>{const n=(r,o,i)=>{const s=xn(i)(Af(t))(r);return o.length<=1?s:v(a=>u=>u===i?a:xn(u)(c=>c.ignoreSpacing.up?{...c,hitbox:{...c.hitbox,y:c.hitbox.y+t+.01,height:c.hitbox.height-t-.01}}:c.ignoreSpacing.down?{...c,hitbox:{...c.hitbox,height:c.hitbox.height-t-.01}}:c)(a))(s)(o)};return v(r=>o=>{if(o.master.tag==="Nothing")return 0<o.cNodes.length?n(r,o.cNodes,o.cNodes[0]):r;if(o.master.tag==="Just")return n(r,o.cNodes,o.master._1);g()})(e)(vt(r=>ue(r)(e.cGroups))(e.cGroupOrder))},bx=t=>e=>{const n=Rf(e)(t.intervals),r=re(i=>Hs(e)(i)==="LT")(t.intervals),o=n.tag==="Just"&&(()=>{const i=Pf(e.id)(t.cand);return(i.tag==="Nothing"?!1:i.tag==="Just"&&(i._1.tag==="Nothing"?!1:i._1.tag==="Just"&&i._1._1===n._1.id))&&n._1.cGroup.tag==="Just"&&e.cGroup.tag==="Just"&&n._1.cGroup._1!==e.cGroup._1})()?Qt(it)(le)(n._1.id)([e.id])(t.constraints):t.constraints;return{...t,constraints:r.tag==="Just"&&(()=>{const i=Pf(r._1.id)(t.cand);return(i.tag==="Nothing"?!1:i.tag==="Just"&&(i._1.tag==="Nothing"?!1:i._1.tag==="Just"&&i._1._1===e.id))&&e.cGroup.tag==="Just"&&r._1.cGroup.tag==="Just"&&e.cGroup._1!==r._1.cGroup._1})()?Qt(it)(le)(e.id)([r._1.id])(o):o,intervals:ft(i=>i.id!==e.id,t.intervals)}},kx=t=>e=>e.low?Nx(t)(e.node):bx(t)(e.node),gc=t=>e=>v(kx)({intervals:[],cand:I,constraints:I})(Pt(vx)(Et(ft(t,vt(n=>ue(n)(e.cNodes))(e.cNodeOrder)))(n=>[{node:n,low:!0},{node:n,low:!1}]))).constraints,Sx=t=>e=>{const n=yx(0)(t/2-.5),r=cc(gc(Bf)(If(n)(e)(Bf)))(e),o=cc(gc(Df)(If(n)(r)(Df)))(r);return cc(gc(i=>!0)(Cx(n)(o)))(o)},Lx=t=>e=>Sx(t)(Tx(e.cGraph)),$s=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ff=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},_c=t=>e=>n=>r=>o=>({id:t,representedEdges:[o],affectedBends:[e,n],hitbox:{x:$s(e._1)(n._1),y:$s(e._2)(n._2),width:Oe(e._1-n._1),height:Oe(e._2-n._2)},ignoreSpacing:Mn,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];g()})(),aPort:J}),Ex=t=>e=>{const n=$s(t.hitbox.x)(e.hitbox.x),r=$s(t.hitbox.y)(e.hitbox.y);return{...t,representedEdges:[...t.representedEdges,...e.representedEdges],affectedBends:[...t.affectedBends,...e.affectedBends],potentialGroupParents:[...t.potentialGroupParents,...e.potentialGroupParents],hitbox:{x:n,y:r,width:Ff(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:Ff(t.hitbox.y+t.hitbox.height)(e.hitbox.y+e.hitbox.height)-r},ignoreSpacing:{left:t.ignoreSpacing.left||e.ignoreSpacing.left,right:t.ignoreSpacing.right||e.ignoreSpacing.right,up:t.ignoreSpacing.up||e.ignoreSpacing.up,down:t.ignoreSpacing.down||e.ignoreSpacing.down},aPort:(()=>{if(t.aPort.tag==="Just")return t.aPort;if(t.aPort.tag==="Nothing")return e.aPort;g()})()}},Gx=t=>e=>Oe(t.hitbox.x-e.hitbox.x)<=1e-4&&e.hitbox.y-(t.hitbox.y+t.hitbox.height)<=1e-4&&t.hitbox.y-(e.hitbox.y+e.hitbox.height)<=1e-4,Px=t=>e=>Oe(t.hitbox.x-e.hitbox.x)<=1e-4?ot.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?Be:De,Qf=(t,e)=>({tag:t,_1:e}),fc=ce(P)(Mt),Vs=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},zf=(()=>{const t={eq:n=>r=>n._1===r._1&&(n._2.tag==="Nothing"?r._2.tag==="Nothing":n._2.tag==="Just"&&r._2.tag==="Just"&&n._2._1===r._2._1)},e={compare:n=>r=>{const o=P.compare(n._1)(r._1);if(o==="LT")return Be;if(o==="GT")return De;if(n._2.tag==="Nothing")return r._2.tag==="Nothing"?Ye:Be;if(r._2.tag==="Nothing")return De;if(n._2.tag==="Just"&&r._2.tag==="Just")return P.compare(n._2._1)(r._2._1);g()},Eq0:()=>t};return v(n=>r=>rt(e)(r)()(n))(I)})(),Sr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Bx=v(t=>e=>rt(ix)(e)()(t))(I),dc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=W_.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Dx=t=>e=>{const n=fc(q(i=>b(i.id,i))(t)),r=vt(i=>Vs(i)(n))(e),o=it.compare((()=>{const i=zf(q(s=>b(s.from.node,s.from.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;g()})())((()=>{const i=zf(q(s=>b(s.to.node,s.to.port))(r));if(i.tag==="Leaf")return 0;if(i.tag==="Node")return i._2;g()})());if(o==="LT")return{...Mn,left:!0,right:!1};if(o==="GT")return{...Mn,left:!1,right:!0};if(o==="EQ")return Mn;g()},Rx=t=>vt(e=>{if(e.direction==="V")return N("Just",{start:e.start,end:e.end});if(e.direction==="H")return J;g()})(t.segments),Us=t=>e=>n=>r=>{if(r.tag==="Just"){const o=Sr(n)(e);if(o.tag==="Just"){const i=re(s=>s.id===r._1)(o._1);if(i.tag==="Just")return i._1.side;if(i.tag==="Nothing")return t;g()}if(o.tag==="Nothing")return t;g()}if(r.tag==="Nothing")return t;g()},Ax=t=>e=>n=>{const r=Gf({origin:N("Just",Qf("SegmentOrigin",n)),kind:N("Just","vs"),hitbox:n.hitbox})(e.cGraph),o=gx(r.id)(n.ignoreSpacing)(r.graph);return{...e,cGraph:(()=>{if(0<n.potentialGroupParents.length){const i=ue(n.potentialGroupParents[0])(o.cNodes);if(i.tag==="Just"){if(i._1.cGroup.tag==="Just")return Ef(r.id)(i._1.cGroup._1)(o);if(i._1.cGroup.tag==="Nothing")return o;g()}if(i.tag==="Nothing")return o;g()}return uc({master:N("Just",r.id),nodes:[r.id]})(o).graph})(),edgeToCs:v(i=>s=>Qt(P)(le)(s)([r.id])(i))(e.edgeToCs)(n.representedEdges),lockMap:rt(it)(r.id)(Dx(t)(n.representedEdges))(e.lockMap)}},Ix=t=>e=>n=>{const r=Ft(o=>J,o=>i=>N("Just",{head:o,tail:i}),Pt(Px)(e));if(r.tag==="Nothing")return n;if(r.tag==="Just"){const o=v(i=>s=>Gx(i.survivor)(s)?{...i,survivor:Ex(i.survivor)(s)}:{survivor:s,merged:[...i.merged,i.survivor]})({survivor:r._1.head,merged:[]})(r._1.tail);return v(Ax(t))(n)([...o.merged,o.survivor])}g()},Fx=t=>({cGraph:{cNodes:I,cNodeOrder:[],cGroups:I,cGroupOrder:[],supportedDirections:Bx([kf,sc,rx]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:I,edgeToCs:I,lockMap:I}),Qx=t=>{const e=nt(4);return{x:t.position._1*e,y:t.position._2*e,width:t.size._1*e,height:t.size._2*e}},zx=t=>e=>n=>v(r=>o=>{const i=Gf({origin:N("Just",Qf("NodeOrigin",o.node)),kind:J,hitbox:Qx(o)})(r.cGraph),s=Sr(o.node)(t),a=(()=>{if(s.tag==="Nothing")return b(0,0);if(s.tag==="Just")return s._1;g()})();return{...r,cGraph:uc({master:N("Just",i.id),nodes:[i.id]})(i.graph).graph,nodeToC:rt(P)(o.node)(i.id)(r.nodeToC),lockMap:rt(it)(i.id)((()=>{const u=a._1-a._2|0;return u<0?{...Mn,left:!0}:u>0?{...Mn,right:!0}:Mn})())(r.lockMap)}})(n)(e),Mx=t=>v(e=>n=>Qt(P)(r=>o=>b(r._1+o._1|0,r._2+o._2|0))(n.to.node)(b(1,0))(Qt(P)(r=>o=>b(r._1+o._1|0,r._2+o._2|0))(n.from.node)(b(0,1))(e)))(I)(t),Wx=t=>v(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?rt(P)(n.origin._1._1)(n.hitbox.x)(e):e)(I)(vt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),Ox=t=>v(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?rt(P)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(I)(vt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),qx=t=>v(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return v(o=>i=>rt(W_)(i)(r)(o))(e)(n.origin._1._1.affectedBends)}return e})(I)(vt(e=>ue(e)(t.cNodes))(t.cNodeOrder)),Mf=t=>{const e=fc(q(n=>b(n.id,n))(t.edges));return vt(n=>{const r=Vs(n.edge)(e);if(r.tag==="Just")return n.reversed?N("Just",{edgeId:n.edge,src:r._1.to.node,tgt:r._1.from.node,srcSide:Us(Tr)(t.ports)(r._1.to.node)(r._1.to.port),tgtSide:Us(Cr)(t.ports)(r._1.from.node)(r._1.from.port),path:n}):N("Just",{edgeId:n.edge,src:r._1.from.node,tgt:r._1.to.node,srcSide:Us(Tr)(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:Us(Cr)(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return J;g()})(t.paths)},Hx=t=>e=>{const n=Et(e)(r=>{if(r.src===r.tgt)return[];if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return[];const o=Sr(r.tgt)(t.nodeToC),i=(()=>{if(o.tag==="Just")return ue(o._1)(t.cGraph.cNodes);if(o.tag==="Nothing")return J;g()})(),s=Sr(r.src)(t.nodeToC),a=(()=>{if(s.tag==="Just")return ue(s._1)(t.cGraph.cNodes);if(s.tag==="Nothing")return J;g()})(),u=(()=>{if(a.tag==="Just"){if(i.tag==="Just"){if(a._1.cGroup.tag==="Just"){if(i._1.cGroup.tag==="Just")return N("Just",{srcGroup:a._1.cGroup._1,tgtGroup:i._1.cGroup._1,delta:0,weight:100});if(i._1.cGroup.tag==="Nothing")return J;g()}if(a._1.cGroup.tag==="Nothing")return J;g()}if(i.tag==="Nothing")return J;g()}if(a.tag==="Nothing")return J;g()})(),c=f=>h=>p=>{if(a.tag==="Just"){if(a._1.cGroup.tag==="Just"){if(p.cGroup.tag==="Just")return f(p.hitbox.x)&&p.cGroup._1!==a._1.cGroup._1?N("Just",h(p.cGroup._1)(a._1.cGroup._1)):J;if(p.cGroup.tag==="Nothing")return J;g()}if(a._1.cGroup.tag==="Nothing")return J;g()}if(a.tag==="Nothing")return J;g()},_=vt(f=>ue(f)(t.cGraph.cNodes))((()=>{const f=Vs(r.edgeId)(t.edgeToCs);if(f.tag==="Nothing")return[];if(f.tag==="Just")return f._1;g()})()),d=(()=>{if(a.tag==="Just"&&r.srcSide==="West"){const f=a._1;return vt(c(h=>h<f.hitbox.x)(h=>p=>({srcGroup:h,tgtGroup:p,delta:1,weight:100})))(_)}return[]})(),l=(()=>{if(a.tag==="Just"&&r.tgtSide==="East"){const f=a._1;return vt(c(h=>h>f.hitbox.x)(h=>p=>({srcGroup:p,tgtGroup:h,delta:1,weight:100})))(_)}return[]})();if(u.tag==="Nothing")return[];if(u.tag==="Just")return[u._1,...d,...l];g()});return{sameEdgeVerticalSegments:r=>o=>r.origin.tag==="Just"&&r.origin._1.tag==="SegmentOrigin"&&o.origin.tag==="Just"&&o.origin._1.tag==="SegmentOrigin"&&(()=>{const i=o.origin._1._1;return Ne(s=>en(Zn)(s)(i.representedEdges),r.origin._1._1.representedEdges)})(),vsLNodePair:r=>o=>r.origin.tag==="Just"&&o.origin.tag==="Just"&&(r.origin._1.tag==="SegmentOrigin"?o.origin._1.tag==="NodeOrigin":r.origin._1.tag==="NodeOrigin"&&o.origin._1.tag==="SegmentOrigin"),edgeLengthEdges:r=>n}},$x=t=>e=>{const n=nt(4),r=Wx(t),o=Ox(t),i=fc(q(a=>b(a.id,b(a.from.node,a.to.node)))(e.edges)),s=qx(t);return{nodes:q(a=>{const u=Sr(a.node)(r);if(u.tag==="Just")return{...a,position:b(u._1/n,a.position._2)};if(u.tag==="Nothing")return a;g()})(e.nodes),edges:q(a=>{const u=Vs(a.edge)(i),c=(()=>{if(u.tag==="Nothing")return a.segments;if(u.tag==="Just"){const _=Sr(u._1._1)(o),d=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;g()})(),l=Sr(u._1._2)(o),f=(()=>{if(l.tag==="Nothing")return 0;if(l.tag==="Just")return l._1;g()})();return Ht((()=>{const h=a.reversed?f:d,p=a.reversed?d:f,m=a.segments.length;return w=>x=>{if(x.direction==="V"){const y=(()=>{if(w===0)return h;if(w===(m-1|0))return p;const T=dc(x.start)(s);if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})();return{...x,start:b(x.start._1+y,x.start._2),end:b(x.end._1+y,x.end._2)}}if(x.direction==="H")return{...x,start:b((()=>{if(w===0)return x.start._1+h;const y=dc(x.start)(s);if(y.tag==="Nothing")return x.start._1+0;if(y.tag==="Just")return x.start._1+y._1;g()})(),x.start._2),end:b((()=>{if(w===(m-1|0))return x.end._1+p;const y=dc(x.end)(s);if(y.tag==="Nothing")return x.end._1+0;if(y.tag==="Just")return x.end._1+y._1;g()})(),x.end._2)};g()}})())(a.segments)}g()})();return{...a,segments:c,bends:Fe(_=>d=>_.end,c,Rt(1,c.length,c))}})(e.paths)}},Vx=t=>e=>n=>r=>o=>i=>{const s=_c(o.nextId)(i._2.start)(i._2.end)(J)(t.edgeId),a=(()=>{if(i._1===0){if(e.tag==="Nothing")return s;if(e.tag==="Just")return{...s,ignoreSpacing:i._2.end._2<e._1.y?{...s.ignoreSpacing,down:!0}:i._2.end._2>e._1.y+e._1.height?{...s.ignoreSpacing,up:!0}:{...s.ignoreSpacing,up:!0,down:!0}};g()}return s})();return{nextId:o.nextId+1|0,segments:[...o.segments,(()=>{if(i._1===r){if(n.tag==="Nothing")return a;if(n.tag==="Just")return{...a,ignoreSpacing:i._2.start._2<n._1.y?{...a.ignoreSpacing,down:!0}:i._2.start._2>n._1.y+n._1.height?{...a.ignoreSpacing,up:!0}:{...a.ignoreSpacing,up:!0,down:!0}};g()}return a})()]}},Wf=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{..._c(i.nextId)(r.start)(b(r.start._1,o.down?n.y:n.y+n.height))(N("Just",e))(t.edgeId),aPort:N("Just",{node:t.src,side:o.side}),ignoreSpacing:o.down?{...Mn,down:!0}:{...Mn,up:!0}}]}),Ks=t=>e=>n=>r=>o=>i=>({nextId:i.nextId+1|0,segments:[...i.segments,{..._c(i.nextId)(r.end)(b(r.end._1,o.down?n.y:n.y+n.height))(N("Just",e))(t.edgeId),aPort:N("Just",{node:t.tgt,side:o.side}),ignoreSpacing:o.down?{...Mn,down:!0}:{...Mn,up:!0}}]}),Ux=t=>e=>n=>{if(n.src===n.tgt)return e;const r=Sr(n.src)(t.nodeToC),o=Sr(n.tgt)(t.nodeToC),i=(()=>{if(r.tag==="Just"){const _=ue(r._1)(t.cGraph.cNodes);return _.tag==="Just"?N("Just",_._1.hitbox):J}if(r.tag==="Nothing")return J;g()})(),s=(()=>{if(o.tag==="Just"){const _=ue(o._1)(t.cGraph.cNodes);return _.tag==="Just"?N("Just",_._1.hitbox):J}if(o.tag==="Nothing")return J;g()})(),a=Rx(n.path),u=v(Vx(n)(i)(s)(a.length-1|0))(e)(Ht(_=>d=>b(_,d))(a));if(0<a.length){const _=(()=>{if(r.tag==="Just"&&i.tag==="Just"){if(n.srcSide==="North")return Wf(n)(r._1)(i._1)(a[0])({side:Se,down:!0})(u);if(n.srcSide==="South")return Wf(n)(r._1)(i._1)(a[0])({side:Le,down:!1})(u)}return u})(),d=a.length-1|0;if(d>=0&&d<a.length&&o.tag==="Just"&&s.tag==="Just"){if(n.tgtSide==="North")return Ks(n)(o._1)(s._1)(a[d])({side:Se,down:!0})(_);if(n.tgtSide==="South")return Ks(n)(o._1)(s._1)(a[d])({side:Le,down:!1})(_)}return _}const c=a.length-1|0;if(c>=0&&c<a.length&&o.tag==="Just"&&s.tag==="Just"){if(n.tgtSide==="North")return Ks(n)(o._1)(s._1)(a[c])({side:Se,down:!0})(u);if(n.tgtSide==="South")return Ks(n)(o._1)(s._1)(a[c])({side:Le,down:!1})(u)}return u},Kx=t=>e=>n=>Ix(t)(v(Ux(n))({nextId:0,segments:[]})(e).segments)(n),Yx=t=>Kx(t.edges)(Mf(t))(zx(Mx(t.edges))(t.nodes)(Fx())),Lr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},lc=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},hc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Xx=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},jx=t=>{const e=t.Eq0();return n=>r=>{const o=a=>{let u=a,c=!0,_;for(;c;){const d=u,l=Ft(f=>J,f=>h=>N("Just",{head:f,tail:h}),d.queue);if(l.tag==="Nothing"){c=!1,_=d;continue}if(l.tag==="Just"){const f=l._1.head;if((p=>{let m=p,w=!0,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!1,x=!1;continue}if(y.tag==="Node"){const T=t.compare(f)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){w=!1,x=!0;continue}}g()}return x})(d.removedNodes)){u={...d,queue:l._1.tail};continue}const h=re(p=>!Lr(p.eid)(d.removedEdges)&&(e.eq(p.src)(f)||e.eq(p.tgt)(f)))(r);if(h.tag==="Nothing"){u={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const p=e.eq(h._1.src)(f)?h._1.tgt:h._1.src,m={...d,degree:rt(t)(p)((()=>{const w=(x=>{let y=x,T=!0,C;for(;T;){const S=y;if(S.tag==="Leaf"){T=!1,C=J;continue}if(S.tag==="Node"){const E=t.compare(p)(S._3);if(E==="LT"){y=S._5;continue}if(E==="GT"){y=S._6;continue}if(E==="EQ"){T=!1,C=N("Just",S._4);continue}}g()}return C})(d.degree);if(w.tag==="Nothing")return-1;if(w.tag==="Just")return w._1-1|0;g()})())(d.degree),removedNodes:rt(t)(f)()(d.removedNodes),removedEdges:rt(it)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:f,neighbour:p,viaSrc:e.eq(h._1.src)(f)}],queue:l._1.tail};if((()=>{const w=(y=>{let T=y,C=!0,S;for(;C;){const E=T;if(E.tag==="Leaf"){C=!1,S=J;continue}if(E.tag==="Node"){const B=t.compare(p)(E._3);if(B==="LT"){T=E._5;continue}if(B==="GT"){T=E._6;continue}if(B==="EQ"){C=!1,S=N("Just",E._4);continue}}g()}return S})(m.degree),x=y=>{let T=y,C=!0,S;for(;C;){const E=T;if(E.tag==="Leaf"){C=!1,S=!1;continue}if(E.tag==="Node"){const B=t.compare(p)(E._3);if(B==="LT"){T=E._5;continue}if(B==="GT"){T=E._6;continue}if(B==="EQ"){C=!1,S=!0;continue}}g()}return S};return(()=>{if(w.tag==="Nothing")return!1;if(w.tag==="Just")return w._1===1;g()})()&&!x(m.removedNodes)})()){u={...m,queue:[...m.queue,p]};continue}u=m;continue}}g()}return _},i=v(a=>u=>Qt(t)(xe)(u.src)(1)(Qt(t)(xe)(u.tgt)(1)(a)))(I)(r),s=o({degree:i,removedNodes:I,removedEdges:I,record:[],queue:ft(a=>{const u=(c=>{let _=c,d=!0,l;for(;d;){const f=_;if(f.tag==="Leaf"){d=!1,l=J;continue}if(f.tag==="Node"){const h=t.compare(a)(f._3);if(h==="LT"){_=f._5;continue}if(h==="GT"){_=f._6;continue}if(h==="EQ"){d=!1,l=N("Just",f._4);continue}}g()}return l})(i);if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1===1;g()},n)});return{coreNodes:ft(a=>!(u=>{let c=u,_=!0,d;for(;_;){const l=c;if(l.tag==="Leaf"){_=!1,d=!1;continue}if(l.tag==="Node"){const f=t.compare(a)(l._3);if(f==="LT"){c=l._5;continue}if(f==="GT"){c=l._6;continue}if(f==="EQ"){_=!1,d=!0;continue}}g()}return d})(s.removedNodes),n),coreEdges:ft(a=>!Lr(a.eid)(s.removedEdges),r),removed:s.record}}},Zx=t=>e=>n=>v(r=>o=>{const i=o.neighbour,s=(()=>{const a=(u=>{let c=u,_=!0,d;for(;_;){const l=c;if(l.tag==="Leaf"){_=!1,d=J;continue}if(l.tag==="Node"){const f=t.compare(i)(l._3);if(f==="LT"){c=l._5;continue}if(f==="GT"){c=l._6;continue}if(f==="EQ"){_=!1,d=N("Just",l._4);continue}}g()}return d})(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})();return rt(t)(o.node)(o.viaSrc?s-1|0:s+1|0)(r)})(n)(se(e)),pc=t=>{const e=t.Eq0();return n=>r=>o=>{const i={...o,treeNode:rt(t)(r)()(o.treeNode)};return v(s=>a=>{if(Lr(a.eid)(s.st.edgeVisited))return s;const u={...s.st,edgeVisited:rt(it)(a.eid)()(s.st.edgeVisited)},c=e.eq(a.src)((()=>{const _=a.src,d=f=>{let h=f,p=!0,m;for(;p;){const w=h;if(w.tag==="Leaf"){p=!1,m=!1;continue}if(w.tag==="Node"){const x=t.compare(_)(w._3);if(x==="LT"){h=w._5;continue}if(x==="GT"){h=w._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=a.tgt;return d(u.treeNode)&&!(f=>{let h=f,p=!0,m;for(;p;){const w=h;if(w.tag==="Leaf"){p=!1,m=!1;continue}if(w.tag==="Node"){const x=t.compare(l)(w._3);if(x==="LT"){h=w._5;continue}if(x==="GT"){h=w._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(u.treeNode)})()?a.src:(()=>{const _=a.tgt,d=f=>{let h=f,p=!0,m;for(;p;){const w=h;if(w.tag==="Leaf"){p=!1,m=!1;continue}if(w.tag==="Node"){const x=t.compare(_)(w._3);if(x==="LT"){h=w._5;continue}if(x==="GT"){h=w._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m},l=a.src;return d(u.treeNode)&&!(f=>{let h=f,p=!0,m;for(;p;){const w=h;if(w.tag==="Leaf"){p=!1,m=!1;continue}if(w.tag==="Node"){const x=t.compare(l)(w._3);if(x==="LT"){h=w._5;continue}if(x==="GT"){h=w._6;continue}if(x==="EQ"){p=!1,m=!0;continue}}g()}return m})(u.treeNode)})()?a.tgt:a.src)?a.tgt:a.src;if(Lr(a.eid)(u.treeEdge)){if((d=>{let l=d,f=!0,h;for(;f;){const p=l;if(p.tag==="Leaf"){f=!1,h=!1;continue}if(p.tag==="Node"){const m=t.compare(c)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){f=!1,h=!0;continue}}g()}return h})(u.treeNode))return{...s,st:u};const _=pc(t)(n)(c)(u);return{count:s.count+_.count|0,st:_.st}}if((()=>{const _=l=>{let f=l,h=!0,p;for(;h;){const m=f;if(m.tag==="Leaf"){h=!1,p=!1;continue}if(m.tag==="Node"){const w=t.compare(c)(m._3);if(w==="LT"){f=m._5;continue}if(w==="GT"){f=m._6;continue}if(w==="EQ"){h=!1,p=!0;continue}}g()}return p},d=a.tgt;return!_(u.treeNode)&&(()=>{const l=(p=>{let m=p,w=!0,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!1,x=J;continue}if(y.tag==="Node"){const T=t.compare(d)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){w=!1,x=N("Just",y._4);continue}}g()}return x})(u.layer),f=a.src,h=(p=>{let m=p,w=!0,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!1,x=J;continue}if(y.tag==="Node"){const T=t.compare(f)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){w=!1,x=N("Just",y._4);continue}}g()}return x})(u.layer);if(l.tag==="Nothing"){if(h.tag==="Nothing")return a.delta===0;if(h.tag==="Just")return a.delta===-h._1;g()}if(l.tag==="Just"){if(h.tag==="Nothing")return a.delta===(l._1-0|0);if(h.tag==="Just")return a.delta===(l._1-h._1|0)}g()})()})()){const _=pc(t)(n)(c)({...u,treeEdge:rt(it)(a.eid)()(u.treeEdge)});return{count:s.count+_.count|0,st:_.st}}return{...s,st:u}})({count:1,st:i})(ft(s=>(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!Lr(s.eid)(i.edgeVisited),n))}},Ys=t=>e=>n=>r=>{const o=r.src,i=(l=>{let f=l,h=!0,p;for(;h;){const m=f;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const w=t.compare(o)(m._3);if(w==="LT"){f=m._5;continue}if(w==="GT"){f=m._6;continue}if(w==="EQ"){h=!1,p=N("Just",m._4);continue}}g()}return p})(e.poID),s=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})(),a=r.tgt,u=(l=>{let f=l,h=!0,p;for(;h;){const m=f;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const w=t.compare(a)(m._3);if(w==="LT"){f=m._5;continue}if(w==="GT"){f=m._6;continue}if(w==="EQ"){h=!1,p=N("Just",m._4);continue}}g()}return p})(e.poID),c=(()=>{if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()})(),_=(l=>{let f=l,h=!0,p;for(;h;){const m=f;if(m.tag==="Leaf"){h=!1,p=J;continue}if(m.tag==="Node"){const w=t.compare(n)(m._3);if(w==="LT"){f=m._5;continue}if(w==="GT"){f=m._6;continue}if(w==="EQ"){h=!1,p=N("Just",m._4);continue}}g()}return p})(e.poID),d=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;g()})();return(()=>{const l=r.src,f=(h=>{let p=h,m=!0,w;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,w=J;continue}if(x.tag==="Node"){const y=t.compare(l)(x._3);if(y==="LT"){p=x._5;continue}if(y==="GT"){p=x._6;continue}if(y==="EQ"){m=!1,w=N("Just",x._4);continue}}g()}return w})(e.lowestPoID);return(()=>{if(f.tag==="Nothing")return 0<=d;if(f.tag==="Just")return f._1<=d;g()})()&&(()=>{const h=r.tgt;return d<=s&&(()=>{const p=(m=>{let w=m,x=!0,y;for(;x;){const T=w;if(T.tag==="Leaf"){x=!1,y=J;continue}if(T.tag==="Node"){const C=t.compare(h)(T._3);if(C==="LT"){w=T._5;continue}if(C==="GT"){w=T._6;continue}if(C==="EQ"){x=!1,y=N("Just",T._4);continue}}g()}return y})(e.lowestPoID);return(()=>{if(p.tag==="Nothing")return 0<=d;if(p.tag==="Just")return p._1<=d;g()})()&&d<=c})()})()})()?s>=c:s<c},tw=t=>{const e=ce(t)(Mt);return n=>({layer:e(q(r=>b(r,0))(n)),treeNode:I,treeEdge:I,poID:I,lowestPoID:I,cutvalue:I,postOrder:1,edgeVisited:I})},ew=t=>e=>n=>v(r=>o=>{if((()=>{const _=o.src,d=h=>{let p=h,m=!0,w;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,w=!1;continue}if(x.tag==="Node"){const y=t.compare(_)(x._3);if(y==="LT"){p=x._5;continue}if(y==="GT"){p=x._6;continue}if(y==="EQ"){m=!1,w=!0;continue}}g()}return w},l=o.tgt,f=h=>{let p=h,m=!0,w;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,w=!1;continue}if(x.tag==="Node"){const y=t.compare(l)(x._3);if(y==="LT"){p=x._5;continue}if(y==="GT"){p=x._6;continue}if(y==="EQ"){m=!1,w=!0;continue}}g()}return w};return d(n.treeNode)===f(n.treeNode)})())return r;const i=o.tgt,s=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=J;continue}if(h.tag==="Node"){const p=t.compare(i)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(n.layer),a=o.src,u=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=J;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(n.layer),c=(()=>{if(s.tag==="Nothing"){if(u.tag==="Nothing")return-o.delta;if(u.tag==="Just")return-u._1-o.delta|0;g()}if(s.tag==="Just"){if(u.tag==="Nothing")return(s._1-0|0)-o.delta|0;if(u.tag==="Just")return(s._1-u._1|0)-o.delta|0}g()})();return c<r.slack?{edge:N("Just",o),slack:c}:r})({edge:J,slack:1e9})(e).edge,nw=t=>{const e=ce(t)(Mt);return n=>r=>{const o=v(i=>s=>lc(i)((()=>{const a=(u=>{let c=u,_=!0,d;for(;_;){const l=c;if(l.tag==="Leaf"){_=!1,d=J;continue}if(l.tag==="Node"){const f=t.compare(s)(l._3);if(f==="LT"){c=l._5;continue}if(f==="GT"){c=l._6;continue}if(f==="EQ"){_=!1,d=N("Just",l._4);continue}}g()}return d})(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})()))(1e9)(n);return e(q(i=>b(i,(()=>{const s=(a=>{let u=a,c=!0,_;for(;c;){const d=u;if(d.tag==="Leaf"){c=!1,_=J;continue}if(d.tag==="Node"){const l=t.compare(i)(d._3);if(l==="LT"){u=d._5;continue}if(l==="GT"){u=d._6;continue}if(l==="EQ"){c=!1,_=N("Just",d._4);continue}}g()}return _})(r);if(s.tag==="Nothing")return-o;if(s.tag==="Just")return s._1-o|0;g()})()))(n))}},Of=t=>{const e=t.Eq0();return n=>r=>o=>{const i=v(a=>u=>{const c=Of(t)(n)(e.eq(u.src)(r)?u.tgt:u.src)({...a.st,edgeVisited:rt(it)(u.eid)()(a.st.edgeVisited)});return{lowest:lc(a.lowest)(c.lowest),st:c.st}})({lowest:1e9,st:o})(ft(a=>Lr(a.eid)(o.treeEdge)&&(e.eq(a.src)(r)||e.eq(a.tgt)(r))&&!Lr(a.eid)(o.edgeVisited),n)),s=lc(i.lowest)(i.st.postOrder);return{lowest:s,st:{...i.st,poID:rt(t)(r)(i.st.postOrder)(i.st.poID),lowestPoID:rt(t)(r)(s)(i.st.lowestPoID),postOrder:i.st.postOrder+1|0}}}},qf=t=>{const e=Of(t);return n=>r=>o=>0<n.length?e(r)(n[0])({...o,edgeVisited:I,postOrder:1,poID:I,lowestPoID:I}).st:o},rw=t=>{const e=t.Eq0();return n=>r=>o=>ft(i=>Lr(i.eid)(r.treeEdge)&&(e.eq(i.src)(o)||e.eq(i.tgt)(o)),n)},ow=t=>e=>re(n=>{const r=hc(n.eid)(e.cutvalue);return Lr(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;g()})()})(t),Hf=t=>{const e=pc(t);return n=>r=>o=>{const i=0<n.length?N("Just",n[0]):J;if(i.tag==="Nothing")return o;if(i.tag==="Just"){const s=e(r)(i._1)({...o,edgeVisited:I,treeNode:I,treeEdge:I});if(s.count>=n.length)return s.st;const a=ew(t)(r)(s.st);if(a.tag==="Nothing")return s.st;if(a.tag==="Just"){const u=a._1.tgt,c=(h=>{let p=h,m=!0,w;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,w=J;continue}if(x.tag==="Node"){const y=t.compare(u)(x._3);if(y==="LT"){p=x._5;continue}if(y==="GT"){p=x._6;continue}if(y==="EQ"){m=!1,w=N("Just",x._4);continue}}g()}return w})(s.st.layer),_=a._1.src,d=(h=>{let p=h,m=!0,w;for(;m;){const x=p;if(x.tag==="Leaf"){m=!1,w=J;continue}if(x.tag==="Node"){const y=t.compare(_)(x._3);if(y==="LT"){p=x._5;continue}if(y==="GT"){p=x._6;continue}if(y==="EQ"){m=!1,w=N("Just",x._4);continue}}g()}return w})(s.st.layer),l=(()=>{if(c.tag==="Nothing"){if(d.tag==="Nothing")return-a._1.delta;if(d.tag==="Just")return-d._1-a._1.delta|0;g()}if(c.tag==="Just"){if(d.tag==="Nothing")return(c._1-0|0)-a._1.delta|0;if(d.tag==="Just")return(c._1-d._1|0)-a._1.delta|0}g()})(),f=(()=>{const h=a._1.tgt;return(p=>{let m=p,w=!0,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!1,x=!1;continue}if(y.tag==="Node"){const T=t.compare(h)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){w=!1,x=!0;continue}}g()}return x})(s.st.treeNode)})()?-l:l;return Hf(t)(n)(r)({...s.st,layer:v(h=>p=>(m=>{let w=m,x=!0,y;for(;x;){const T=w;if(T.tag==="Leaf"){x=!1,y=!1;continue}if(T.tag==="Node"){const C=t.compare(p)(T._3);if(C==="LT"){w=T._5;continue}if(C==="GT"){w=T._6;continue}if(C==="EQ"){x=!1,y=!0;continue}}g()}return y})(s.st.treeNode)?rt(t)(p)((()=>{const m=(w=>{let x=w,y=!0,T;for(;y;){const C=x;if(C.tag==="Leaf"){y=!1,T=J;continue}if(C.tag==="Node"){const S=t.compare(p)(C._3);if(S==="LT"){x=C._5;continue}if(S==="GT"){x=C._6;continue}if(S==="EQ"){y=!1,T=N("Just",C._4);continue}}g()}return T})(s.st.layer);if(m.tag==="Nothing")return 0+f|0;if(m.tag==="Just")return m._1+f|0;g()})())(h):h)(s.st.layer)(n)})}}g()}},iw=t=>e=>n=>r=>v(o=>i=>{if(Ys(t)(r)(i.src)(n)&&!Ys(t)(r)(i.tgt)(n)){const s=i.tgt,a=(d=>{let l=d,f=!0,h;for(;f;){const p=l;if(p.tag==="Leaf"){f=!1,h=J;continue}if(p.tag==="Node"){const m=t.compare(s)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){f=!1,h=N("Just",p._4);continue}}g()}return h})(r.layer),u=i.src,c=(d=>{let l=d,f=!0,h;for(;f;){const p=l;if(p.tag==="Leaf"){f=!1,h=J;continue}if(p.tag==="Node"){const m=t.compare(u)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){f=!1,h=N("Just",p._4);continue}}g()}return h})(r.layer),_=(()=>{if(a.tag==="Nothing"){if(c.tag==="Nothing")return-i.delta;if(c.tag==="Just")return-c._1-i.delta|0;g()}if(a.tag==="Just"){if(c.tag==="Nothing")return(a._1-0|0)-i.delta|0;if(c.tag==="Just")return(a._1-c._1|0)-i.delta|0}g()})();if(_<o.slack)return{edge:N("Just",i),slack:_}}return o})({edge:J,slack:1e9})(e).edge,sw=t=>{const e=t.Eq0();return n=>r=>o=>i=>{const s=i.tgt,a=i.src;return v(u=>c=>{if((()=>{const _=hc(c.eid)(r.cutvalue);if(_.tag==="Just")return!0;if(_.tag==="Nothing")return!1;g()})()){const _=hc(c.eid)(r.cutvalue),d=(()=>{if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1;g()})();return e.eq(a)(c.src)||e.eq(s)(c.tgt)?u-(d-c.weight):u+(d-c.weight)}return e.eq(o)(a)?e.eq(c.src)(o)?u+c.weight:u-c.weight:e.eq(c.src)(o)?u-c.weight:u+c.weight})(i.weight)(ft(u=>u.eid!==i.eid&&(e.eq(u.src)(o)||e.eq(u.tgt)(o)),n))}},aw=t=>{const e=sw(t);return n=>r=>o=>{const i=(s,a,u)=>{const c=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=J;continue}if(h.tag==="Node"){const p=t.compare(s)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(u);if(c.tag==="Just")return rt(t)(s)(ft(_=>_.eid!==a.eid,c._1))(u);if(c.tag==="Nothing")return u;g()};return(s=>a=>{let u=s,c=a,_=!0,d;for(;_;){const l=u,f=c,h=(m=>{let w=m,x=!0,y;for(;x;){const T=w;if(T.tag==="Leaf"){x=!1,y=J;continue}if(T.tag==="Node"){const C=t.compare(f)(T._3);if(C==="LT"){w=T._5;continue}if(C==="GT"){w=T._6;continue}if(C==="EQ"){x=!1,y=N("Just",T._4);continue}}g()}return y})(l.unknown),p=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;g()})();if(p.length===1){const m=t.Eq0().eq(p[0].src)(f)?p[0].tgt:p[0].src;u={unknown:i(f,p[0],i(m,p[0],l.unknown)),cutvalue:rt(it)(p[0].eid)(e(n)(l)(f)(p[0]))(l.cutvalue)},c=m;continue}_=!1,d=l}return d})(r)(o)}},$f=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:c=>_=>c.delta===_.delta&&c.eid===_.eid&&n.eq(c.src)(_.src)&&e.eq(c.tgt)(_.tgt)&&c.weight===_.weight},o={compare:c=>_=>{const d=it.compare(c.delta)(_.delta);if(d==="LT"||d==="GT"||d!=="EQ")return d;const l=it.compare(c.eid)(_.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const f=t.compare(c.src)(_.src);if(f==="LT"||f==="GT"||f!=="EQ")return f;const h=t.compare(c.tgt)(_.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const p=ot.compare(c.weight)(_.weight);return p==="LT"||p==="GT"||p!=="EQ"?p:Ye},Eq0:()=>r},i=v(c=>_=>rt(o)(_)()(c))(I),s=rw(t),a=ce(t)(Mt),u=aw(t);return c=>_=>d=>{const l={unknown:a(q(f=>b(f,Zt(fn.foldr,i(s(_)(d)(f)))))(c)),cutvalue:I};return{...d,cutvalue:v(u(_))(l)(ft(f=>{const h=(p=>{let m=p,w=!0,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!1,x=J;continue}if(y.tag==="Node"){const T=t.compare(f)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){w=!1,x=N("Just",y._4);continue}}g()}return x})(l.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;g()},c)).cutvalue}}},uw=t=>{const e=qf(t),n=$f(t);return r=>o=>i=>s=>a=>{const u={...a,treeEdge:rt(it)(s.eid)()(Wo(it)(i.eid)(a.treeEdge))},c=s.tgt,_=(p=>{let m=p,w=!0,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!1,x=J;continue}if(y.tag==="Node"){const T=t.compare(c)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){w=!1,x=N("Just",y._4);continue}}g()}return x})(u.layer),d=s.src,l=(p=>{let m=p,w=!0,x;for(;w;){const y=m;if(y.tag==="Leaf"){w=!1,x=J;continue}if(y.tag==="Node"){const T=t.compare(d)(y._3);if(T==="LT"){m=y._5;continue}if(T==="GT"){m=y._6;continue}if(T==="EQ"){w=!1,x=N("Just",y._4);continue}}g()}return x})(u.layer),f=(()=>{if(_.tag==="Nothing"){if(l.tag==="Nothing")return-s.delta;if(l.tag==="Just")return-l._1-s.delta|0;g()}if(_.tag==="Just"){if(l.tag==="Nothing")return(_._1-0|0)-s.delta|0;if(l.tag==="Just")return(_._1-l._1|0)-s.delta|0}g()})(),h=Ys(t)(u)(s.tgt)(i)?f:-f;return n(r)(o)(e(r)(o)({...u,layer:v(p=>m=>Ys(t)(u)(m)(i)?p:rt(t)(m)((()=>{const w=(x=>{let y=x,T=!0,C;for(;T;){const S=y;if(S.tag==="Leaf"){T=!1,C=J;continue}if(S.tag==="Node"){const E=t.compare(m)(S._3);if(E==="LT"){y=S._5;continue}if(E==="GT"){y=S._6;continue}if(E==="EQ"){T=!1,C=N("Just",S._4);continue}}g()}return C})(u.layer);if(w.tag==="Nothing")return 0+h|0;if(w.tag==="Just")return w._1+h|0;g()})())(p))(u.layer)(r)}))}},cw=t=>{const e=uw(t);return n=>r=>o=>i=>(s=>a=>{let u=s,c=a,_=!0,d;for(;_;){const l=u,f=c;if(l===0){_=!1,d=f;continue}const h=ow(o)(f);if(h.tag==="Nothing"){_=!1,d=f;continue}if(h.tag==="Just"){const p=iw(t)(o)(h._1)(f);if(p.tag==="Nothing"){_=!1,d=f;continue}if(p.tag==="Just"){u=l-1|0,c=e(r)(o)(h._1)(p._1)(f);continue}}g()}return d})(n)(i)},gw=t=>{const e=$f(t),n=qf(t),r=Hf(t);return o=>i=>s=>e(o)(i)(n(o)(i)(r(o)(i)(s)))},Vf=t=>e=>v(n=>r=>Qt(t)(le)(e(r))([r])(n))(I),_w=t=>{const e=ce(t)(Mt);return n=>r=>o=>{const i=u=>c=>_=>d=>{let l=u,f=c,h=_,p=d,m=!0,w;for(;m;){const x=l,y=f,T=h,C=p,S=Ft(E=>J,E=>B=>N("Just",{head:E,tail:B}),T);if(S.tag==="Nothing"){m=!1,w=C;continue}if(S.tag==="Just"){const E=S._1.head,B=(R=>{let A=R,j=!0,Z;for(;j;){const z=A;if(z.tag==="Leaf"){j=!1,Z=J;continue}if(z.tag==="Node"){const W=t.compare(E)(z._3);if(W==="LT"){A=z._5;continue}if(W==="GT"){A=z._6;continue}if(W==="EQ"){j=!1,Z=N("Just",z._4);continue}}g()}return Z})(C.layer),M=(()=>{if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;g()})(),Y=v(R=>A=>{const j=A.tgt,Z=(W=>{let H=W,D=!0,F;for(;D;){const L=H;if(L.tag==="Leaf"){D=!1,F=J;continue}if(L.tag==="Node"){const G=t.compare(j)(L._3);if(G==="LT"){H=L._5;continue}if(G==="GT"){H=L._6;continue}if(G==="EQ"){D=!1,F=N("Just",L._4);continue}}g()}return F})(R.incident),z=(()=>{if(Z.tag==="Nothing")return-1;if(Z.tag==="Just")return Z._1-1|0;g()})();return{st:{...R.st,layer:rt(t)(A.tgt)(Xx((()=>{const W=A.tgt,H=(D=>{let F=D,L=!0,G;for(;L;){const Q=F;if(Q.tag==="Leaf"){L=!1,G=J;continue}if(Q.tag==="Node"){const V=t.compare(W)(Q._3);if(V==="LT"){F=Q._5;continue}if(V==="GT"){F=Q._6;continue}if(V==="EQ"){L=!1,G=N("Just",Q._4);continue}}g()}return G})(R.st.layer);if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})())(M+A.delta|0))(R.st.layer)},incident:rt(t)(A.tgt)(z)(R.incident),queue:z===0?[...R.queue,A.tgt]:R.queue}})({st:C,incident:y,queue:S._1.tail})((()=>{const R=(A=>{let j=A,Z=!0,z;for(;Z;){const W=j;if(W.tag==="Leaf"){Z=!1,z=J;continue}if(W.tag==="Node"){const H=t.compare(E)(W._3);if(H==="LT"){j=W._5;continue}if(H==="GT"){j=W._6;continue}if(H==="EQ"){Z=!1,z=N("Just",W._4);continue}}g()}return z})(x);if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;g()})());l=x,f=Y.incident,h=Y.queue,p=Y.st;continue}g()}return w},s=Vf(t)(u=>u.tgt)(r),a=e(q(u=>b(u,(()=>{const c=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=J;continue}if(h.tag==="Node"){const p=t.compare(u)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(s);if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1.length;g()})()))(n));return i(Vf(t)(u=>u.src)(r))(a)(ft(u=>{const c=(_=>{let d=_,l=!0,f;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,f=J;continue}if(h.tag==="Node"){const p=t.compare(u)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,f=N("Just",h._4);continue}}g()}return f})(a);if(c.tag==="Nothing")return!0;if(c.tag==="Just")return c._1===0;g()},n))(o)}},fw=t=>{const e=tw(t),n=_w(t),r=gw(t),o=cw(t);return i=>s=>{const a=n(i)(s)(e(i));return s.length===0?a.layer:o(4*i.length|0)(i)(s)(r(i)(s)(a)).layer}},Uf=t=>{const e=nw(t),n=fw(t),r=jx(t);return o=>i=>{if(o.length===0)return I;if(o.length<40)return e(o)(n(o)(i));const s=r(o)(i);return e(o)(Zx(t)(s.removed)(n(s.coreNodes)(s.coreEdges)))}},Kf=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},mc=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},dw=Uf(it),zi=t=>e=>({...e,edges:[...e.edges,{src:t.src,tgt:t.tgt,delta:t.delta,weight:t.weight,eid:e.nextEid}],nextEid:e.nextEid+1|0}),lw=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=nt((()=>{const o=Kf(n.cGroup._1)(t);if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;g()})());return xn(n.id)(o=>({...o,hitbox:{...o.hitbox,x:r+o.cGroupOffset.x}}))(e)}g()},hw=t=>e=>({...e,cGraph:v(lw(t))(e.cGraph)((()=>{const n=e.cGraph;return vt(r=>ue(r)(n.cNodes))(n.cNodeOrder)})())}),pw=t=>e=>n=>r=>o=>{const i=fe(xs(e.cGroupOffset.x-t.cGroupOffset.x));return zi({src:o.nextNodeId,tgt:r,delta:mc(0)(-i),weight:1})(zi({src:o.nextNodeId,tgt:n,delta:mc(0)(i),weight:1})({...o,nodes:[...o.nodes,o.nextNodeId],nextNodeId:o.nextNodeId+1|0}))},mw=t=>e=>n=>r=>o=>i=>s=>{const a=mc(0)(fe(xs(n.cGroupOffset.x+n.hitbox.width+(e.direction==="LEFT"||e.direction==="RIGHT"?e.spacingsHandler.horizontalSpacing(n)(r):e.spacingsHandler.verticalSpacing(n)(r))-r.cGroupOffset.x)));return t.sameEdgeVerticalSegments(n)(r)?pw(n)(r)(o)(i)(s):zi({src:o,tgt:i,delta:a,weight:t.vsLNodePair(n)(r)?2:1})(s)},yw=t=>e=>n=>r=>o=>{const i=ue(o)(e.cGraph.cNodes);if(i.tag==="Nothing")return r;if(i.tag==="Just")return(n.cGroup.tag==="Nothing"?i._1.cGroup.tag==="Nothing":n.cGroup.tag==="Just"&&i._1.cGroup.tag==="Just"&&n.cGroup._1===i._1.cGroup._1)?r:n.cGroup.tag==="Just"&&i._1.cGroup.tag==="Just"?mw(t)(e)(n)(i._1)(n.cGroup._1)(i._1.cGroup._1)(r):r;g()},xw=t=>e=>n=>r=>v(yw(t)(e)(r))(n)(r.constraints),ww=t=>e=>zi({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),Jw=t=>{const e=v(o=>i=>Qt(it)(xe)(i.tgt)(1)(o))(I)(t.edges),n=ft(o=>{const i=Kf(o)(e);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return i._1===0;g()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return v(o=>i=>zi({src:r,tgt:i,delta:1,weight:0})(o))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},Nw=t=>e=>{const n=Jw(v(ww)(v(xw(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return vt(o=>ue(o)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},vw=t=>e=>{const n=Nw(t)(e);return hw(dw(n.nodes)(n.edges))(e)},Yf=t=>t,pe=Yf("H"),me=Yf("V"),Tw=t=>b(t._2,t._1),Xf=t=>({...t,position:b(t.position._2,t.position._1),size:b(t.size._2,t.size._1)}),Cw=t=>({start:b(t.start._2,t.start._1),end:b(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return me;if(t.direction==="V")return pe;g()})()}),jf=t=>({...t,segments:q(Cw)(t.segments),bends:q(Tw)(t.bends)}),bw=t=>({nodes:q(Xf)(t.nodes),edges:t.edges,paths:q(jf)(t.paths),ports:t.ports}),kw={nodeNode:8,edgeNode:4,edgeEdge:10},Sw=t=>e=>({horizontalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r)||n.ignoreSpacing.right||r.ignoreSpacing.left)return 0;const o=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?o?t.edgeEdge:t.edgeNode:o?t.edgeNode:t.nodeNode},verticalSpacing:n=>r=>{if(e.sameEdgeVerticalSegments(n)(r))return 1;if(n.hitbox.y<=r.hitbox.y?n.ignoreSpacing.down||r.ignoreSpacing.up:n.ignoreSpacing.up||r.ignoreSpacing.down)return 0;const o=r.kind.tag==="Nothing"?!1:r.kind.tag==="Just"&&r.kind._1==="vs";return n.kind.tag!=="Nothing"&&n.kind.tag==="Just"&&n.kind._1==="vs"?o?t.edgeEdge:t.edgeNode:o?t.edgeNode:t.nodeNode}}),Lw=t=>e=>vw(e),Ew=t=>e=>n=>{const r=bw(n),o=Yx(r),i=Hx(o)(Mf(r)),s=$x(Lf(sc)(hx({...mx(o.cGraph),compactionAlgorithm:N("Just",Lw()(i)),constraintAlgorithm:N("Just",Lx(e.edgeEdge)),spacingsHandler:Sw(e)(i)})).cGraph)({nodes:r.nodes,edges:r.edges,paths:r.paths});return{nodes:q(Xf)(s.nodes),edges:q(jf)(s.edges)}},Zf=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},t1=t=>Re(3)(t)==="$d:",Gw=t=>e=>n=>v(r=>o=>{const i=Zf(o.from.node)(t),s=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;g()})(),a=Zf(o.to.node)(t),u=(()=>{if(a.tag==="Nothing")return-s;if(a.tag==="Just")return a._1-s|0;g()})();if(u<=1)return{...r,edges:[...r.edges,o],chains:[...r.chains,{edgeId:o.id,nodes:[o.from.node,o.to.node]}]};const c=o.id,_=q(l=>"$d:"+c+":"+ie(l))(Xt(1,u-1|0)),d=[o.from.node,..._,o.to.node];return{...r,layers:v(l=>f=>{const h=f._2,p=A0(s+f._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;g()})(r.layers)(Fe(Rn,Xt(1,u-1|0),_)),edges:[...r.edges,...Fe(l=>f=>({id:c+":"+l+"->"+f,from:{node:l,port:o.from.port},to:{node:f,port:o.to.port},label:J}),d,Rt(1,d.length,d))],chains:[...r.chains,{edgeId:o.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),e1=t=>t,ri=ce(it)(Mt),Ut=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},n1=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jt=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Nt=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},oi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Pw=t=>e=>{const n=it.compare(t._1)(e._1);return n==="LT"?Be:n==="GT"?De:it.compare(t._2)(e._2)},ii=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Bw=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),Dw=t=>t,r1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Rw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Xs=e1("Regular"),js=e1("Critical"),o1=t=>e=>{const n=v(s=>a=>rt(P)(a.node)(a)(s))(I)(e),r=1.25*nt(4),o=(s,a,u)=>(c=>_=>d=>{let l=c,f=_,h=d,p=!0,m;for(;p;){const w=l,x=f,y=h;if(y.critical){p=!1,m=y;continue}const T=Ft(S=>J,S=>E=>N("Just",{head:S,tail:E}),w),C=Ft(S=>J,S=>E=>N("Just",{head:S,tail:E}),x);if(T.tag==="Just"&&C.tag==="Just"){const S=T._1.head>C._1.head-s&&T._1.head<C._1.head+s?{...y,critical:!0}:T._1.head>C._1.head-r&&T._1.head<C._1.head+r?{...y,conflicts:y.conflicts+1|0}:y;if(S.critical){p=!1,m=S;continue}if(T._1.head<=C._1.head){l=T._1.tail,f=x,h=S;continue}l=w,f=C._1.tail,h=S;continue}p=!1,m=y}return m})(a)(u)({conflicts:0,critical:!1}),i=(s,a,u)=>{if(Nt(v(Nt)(-1e18)(a.incoming))(v(Nt)(-1e18)(a.outgoing))-Jt(v(Jt)(1e18)(a.incoming))(v(Jt)(1e18)(a.outgoing))<.001||Nt(v(Nt)(-1e18)(u.incoming))(v(Nt)(-1e18)(u.outgoing))-Jt(v(Jt)(1e18)(u.incoming))(v(Jt)(1e18)(u.outgoing))<.001)return[];const c=o(s,a.outgoing,u.incoming),_=o(s,u.outgoing,a.incoming);if(c.critical||_.critical)return[...c.critical?[{src:u.id,tgt:a.id,weight:1,kind:js}]:[],..._.critical?[{src:a.id,tgt:u.id,weight:1,kind:js}]:[]];const d=Jt(v(Jt)(1e18)(a.incoming))(v(Jt)(1e18)(a.outgoing)),l=Nt(v(Nt)(-1e18)(a.incoming))(v(Nt)(-1e18)(a.outgoing)),f=Jt(v(Jt)(1e18)(u.incoming))(v(Jt)(1e18)(u.outgoing)),h=Nt(v(Nt)(-1e18)(u.incoming))(v(Nt)(-1e18)(u.outgoing)),p=(1*c.conflicts|0)+(16*(v(w=>x=>x>h?w:x>=f?w+1|0:w)(0)(a.outgoing)+v(w=>x=>x>l?w:x>=d?w+1|0:w)(0)(u.incoming)|0)|0)|0,m=(1*_.conflicts|0)+(16*(v(w=>x=>x>l?w:x>=d?w+1|0:w)(0)(u.outgoing)+v(w=>x=>x>h?w:x>=f?w+1|0:w)(0)(a.incoming)|0)|0)|0;return p<m?[{src:a.id,tgt:u.id,weight:m-p|0,kind:Xs}]:p>m?[{src:u.id,tgt:a.id,weight:p-m|0,kind:Xs}]:p>0?[{src:a.id,tgt:u.id,weight:0,kind:Xs},{src:u.id,tgt:a.id,weight:0,kind:Xs}]:[]};return v(s=>a=>v(u=>c=>rt(P)(c._1)(c._2)(u))(s)((()=>{const u=v(R=>A=>{const j=A.edge.from.node+"|"+(()=>{if(A.edge.from.port.tag==="Just")return A.edge.from.port._1;if(A.edge.from.port.tag==="Nothing")return"_auto_"+A.edge.id;g()})(),Z=r1(j)(R.entries);if(Z.tag==="Nothing")return{...R,entries:rt(P)(j)({id:0,members:[A.edge.id],incoming:[A.fromPos._1],outgoing:[A.toPos._1],slot:0,mark:0,splitBy:J,splitPartner:J})(R.entries),order:[...R.order,j]};if(Z.tag==="Just")return{...R,entries:rt(P)(j)({...Z._1,members:[...Z._1.members,A.edge.id],incoming:[...tr(z=>z<A.fromPos._1)(Z._1.incoming).init,A.fromPos._1,...tr(z=>z<=A.fromPos._1)(Z._1.incoming).rest],outgoing:[...tr(z=>z<A.toPos._1)(Z._1.outgoing).init,A.toPos._1,...tr(z=>z<=A.toPos._1)(Z._1.outgoing).rest]})(R.entries)};g()})({entries:I,order:[]})(a._2),c=Ht(R=>A=>({...A,id:R}))(vt(R=>r1(R)(u.entries))(u.order));if(c.length===0)return[];const _=v(R=>A=>R.prev.tag==="Just"&&A-R.prev._1<1e-9?R:{prev:N("Just",A),out:[...R.out,A]})({prev:J,out:[]})(Pt(ot.compare)([...Et(c)(R=>R.incoming),...Et(c)(R=>R.outgoing)])).out,d=_.length<2?.2*r:.2*v(R=>A=>{if(R.prev.tag==="Nothing")return{prev:N("Just",A),mn:R.mn};if(R.prev.tag==="Just")return{prev:N("Just",A),mn:Jt(R.mn)(A-R.prev._1)};g()})({prev:J,mn:1e18})(_).mn,l={segments:c,deps:(()=>{const R=c.length;return Et(Et(Xt(0,R-2|0))(A=>Et(Xt(A+1|0,R-1|0))(j=>[b(A,j)])))(A=>A._1>=0&&A._1<c.length?A._2>=0&&A._2<c.length?i(d,c[A._1],c[A._2]):[]:[])})()},f=ft(R=>{if(R.kind==="Critical")return!0;if(R.kind==="Regular")return!1;g()},l.deps),h=(()=>{if(f.length<2)return l;const R=ri((()=>{const W=l.segments;return q(H=>b(H.id,H.mark))((()=>{const H=W.length,D=L=>{let G=L,Q=!0,V;for(;Q;){const K=G,U=re(O=>{const X=Ut(O)(K.inWeight);if(X.tag==="Nothing")return!0;if(X.tag==="Just")return X._1===0;g()})(K.remaining);if(U.tag==="Nothing"){Q=!1,V=K;continue}if(U.tag==="Just"){const O=U._1;G={...K,inWeight:v(X=>et=>Qt(it)(xe)(et.tgt)(-et.weight)(X))(K.inWeight)((()=>{const X=Ut(O)(K.depsBySrc);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()})()),marks:rt(it)(O)(K.nextSource)(K.marks),nextSource:K.nextSource+1|0,outWeight:v(X=>et=>Qt(it)(xe)(et.src)(-et.weight)(X))(K.outWeight)((()=>{const X=Ut(O)(K.depsByTgt);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()})()),remaining:ft(X=>X!==O,K.remaining)};continue}g()}return V},F=L=>{let G=L,Q=!0,V;for(;Q;){const K=G,U=re(O=>{const X=Ut(O)(K.outWeight);if(X.tag==="Nothing")return!0;if(X.tag==="Just")return X._1===0;g()})(K.remaining);if(U.tag==="Nothing"){Q=!1,V=K;continue}if(U.tag==="Just"){const O=U._1;G={...K,inWeight:v(X=>et=>Qt(it)(xe)(et.tgt)(-et.weight)(X))(K.inWeight)((()=>{const X=Ut(O)(K.depsBySrc);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()})()),marks:rt(it)(O)(K.nextSink)(K.marks),nextSink:K.nextSink-1|0,outWeight:v(X=>et=>Qt(it)(xe)(et.src)(-et.weight)(X))(K.outWeight)((()=>{const X=Ut(O)(K.depsByTgt);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;g()})()),remaining:ft(X=>X!==O,K.remaining)};continue}g()}return V};return(L=>{let G=L,Q=!0,V;for(;Q;){const K=D(F(G));if(K.remaining.length===0){Q=!1,V=q(U=>{const O=Ut(U.id)(K.marks),X=(()=>{if(O.tag==="Nothing")return U.id;if(O.tag==="Just")return O._1;g()})();return{...U,mark:X<H?(X+H|0)+1|0:X}})(W);continue}G=(()=>{const U=X=>{const et=Ut(X)(K.outWeight),lt=Ut(X)(K.inWeight);return(()=>{if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1;g()})()-(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()|0},O=Pt(X=>et=>it.compare(U(et))(U(X)))(K.remaining);if(0<O.length){const X=O[0];return{...K,inWeight:v(et=>lt=>Qt(it)(xe)(lt.tgt)(-lt.weight)(et))(K.inWeight)((()=>{const et=Ut(X)(K.depsBySrc);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;g()})()),marks:rt(it)(X)(K.nextSource)(K.marks),nextSource:K.nextSource+1|0,outWeight:v(et=>lt=>Qt(it)(xe)(lt.src)(-lt.weight)(et))(K.outWeight)((()=>{const et=Ut(X)(K.depsByTgt);if(et.tag==="Nothing")return[];if(et.tag==="Just")return et._1;g()})()),remaining:ft(et=>et!==X,K.remaining)}}return K})()}return V})({remaining:q(L=>L.id)(W),marks:I,inWeight:v(L=>G=>Qt(it)(xe)(G.tgt)(G.weight)(L))(I)(f),outWeight:v(L=>G=>Qt(it)(xe)(G.src)(G.weight)(L))(I)(f),depsBySrc:v(L=>G=>Qt(it)(le)(G.src)([G])(L))(I)(f),depsByTgt:v(L=>G=>Qt(it)(le)(G.tgt)([G])(L))(I)(f),nextSink:H-1|0,nextSource:H+1|0})})())})()),A=ft(W=>{const H=Ut(W.src)(R),D=Ut(W.tgt)(R);return(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})()>(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;g()})()},f);if(A.length===0)return l;const j=v(W=>H=>{if(en(zr)(H.src)(W.decisions)||en(zr)(H.tgt)(W.decisions))return W;const D=Ut(H.src)(W.segMap),F=Ut(H.tgt)(W.segMap);if(D.tag==="Just"&&F.tag==="Just"){const L=(D._1.incoming.length+D._1.outgoing.length|0)>2&&(F._1.incoming.length+F._1.outgoing.length|0)<=2,G=L?F._1:D._1;return{decisions:[...W.decisions,G.id],segMap:rt(it)(G.id)({...G,splitBy:N("Just",L?D._1.id:F._1.id)})(W.segMap)}}return W})({decisions:[],segMap:ri(q(W=>b(W.id,W))(l.segments))})(A),Z=j.segMap,z=v(W=>H=>{const D=Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(H.outgoing)),F=Nt(v(Nt)(-1e18)(H.incoming))(v(Nt)(-1e18)(H.outgoing)),L=ft(U=>U.a.startPosition<=F&&U.a.endPosition>=D,Ht(U=>O=>({i:U,a:O}))(W.freeAreas));if(L.length===0){const U={...H,incoming:Pt(ot.compare)(H.incoming),outgoing:Pt(ot.compare)([(D+F)/2]),splitPartner:N("Just",W.nextId)},O={id:W.nextId,incoming:Pt(ot.compare)([(D+F)/2]),mark:0,members:H.members,outgoing:Pt(ot.compare)(H.outgoing),slot:0,splitBy:J,splitPartner:N("Just",H.id)};return{segMap:rt(it)(O.id)(O)(rt(it)(U.id)(U)(W.segMap)),freeAreas:W.freeAreas,nextId:W.nextId+1|0}}const G=0<L.length?N("Just",L[0]):J,Q=(()=>{if(G.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(G.tag==="Just"){if(L.length===1)return G._1;const U=q(O=>({c:O,rating:(()=>{const X=(O.a.startPosition+O.a.endPosition)/2,et=[X],lt=[X],bt=v((()=>{const Tt=W.segMap;return Gt=>jt=>{const Ct=Ut(jt.tgt)(Tt);if(Ct.tag==="Nothing")return Gt;if(Ct.tag==="Just"){const Yt=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),Dt=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),wt=Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(et)),mt=(()=>{const qt=Nt(v(Nt)(-1e18)(H.incoming))(v(Nt)(-1e18)(et)),Ot=v(oe=>_e=>_e>Dt?oe:_e>=Yt?oe+1|0:oe)(0)(et)+v(oe=>_e=>_e>qt?oe:_e>=wt?oe+1|0:oe)(0)(Ct._1.incoming)|0,We=Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(et)),bn=Nt(v(Nt)(-1e18)(H.incoming))(v(Nt)(-1e18)(et)),tn=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),_n=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),Ae=v(oe=>_e=>_e>bn?oe:_e>=We?oe+1|0:oe)(0)(Ct._1.outgoing)+v(oe=>_e=>_e>_n?oe:_e>=tn?oe+1|0:oe)(0)(H.incoming)|0;return Ot===Ae?Ot>0?{...Gt,deps:Gt.deps+2|0,crossings:Gt.crossings+Ot|0}:Gt:{...Gt,deps:Gt.deps+1|0,crossings:Gt.crossings+ii(Ot)(Ae)|0}})(),ct=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),yt=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),dt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(H.outgoing)),ht=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(H.outgoing)),Lt=v(qt=>Ot=>Ot>yt?qt:Ot>=ct?qt+1|0:qt)(0)(H.outgoing)+v(qt=>Ot=>Ot>ht?qt:Ot>=dt?qt+1|0:qt)(0)(Ct._1.incoming)|0,Bt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(H.outgoing)),zt=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(H.outgoing)),ne=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),Cn=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),Me=v(qt=>Ot=>Ot>zt?qt:Ot>=Bt?qt+1|0:qt)(0)(Ct._1.outgoing)+v(qt=>Ot=>Ot>Cn?qt:Ot>=ne?qt+1|0:qt)(0)(lt)|0;return Lt===Me?Lt>0?{...mt,deps:mt.deps+2|0,crossings:mt.crossings+Lt|0}:mt:{...mt,deps:mt.deps+1|0,crossings:mt.crossings+ii(Lt)(Me)|0}}g()}})())(v((()=>{const Tt=W.segMap;return Gt=>jt=>{const Ct=Ut(jt.src)(Tt);if(Ct.tag==="Nothing")return Gt;if(Ct.tag==="Just"){const Yt=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),Dt=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),wt=Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(et)),mt=(()=>{const qt=Nt(v(Nt)(-1e18)(H.incoming))(v(Nt)(-1e18)(et)),Ot=v(oe=>_e=>_e>Dt?oe:_e>=Yt?oe+1|0:oe)(0)(et)+v(oe=>_e=>_e>qt?oe:_e>=wt?oe+1|0:oe)(0)(Ct._1.incoming)|0,We=Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(et)),bn=Nt(v(Nt)(-1e18)(H.incoming))(v(Nt)(-1e18)(et)),tn=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),_n=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),Ae=v(oe=>_e=>_e>bn?oe:_e>=We?oe+1|0:oe)(0)(Ct._1.outgoing)+v(oe=>_e=>_e>_n?oe:_e>=tn?oe+1|0:oe)(0)(H.incoming)|0;return Ot===Ae?Ot>0?{...Gt,deps:Gt.deps+2|0,crossings:Gt.crossings+Ot|0}:Gt:{...Gt,deps:Gt.deps+1|0,crossings:Gt.crossings+ii(Ot)(Ae)|0}})(),ct=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),yt=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),dt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(H.outgoing)),ht=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(H.outgoing)),Lt=v(qt=>Ot=>Ot>yt?qt:Ot>=ct?qt+1|0:qt)(0)(H.outgoing)+v(qt=>Ot=>Ot>ht?qt:Ot>=dt?qt+1|0:qt)(0)(Ct._1.incoming)|0,Bt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(H.outgoing)),zt=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(H.outgoing)),ne=Jt(v(Jt)(1e18)(Ct._1.incoming))(v(Jt)(1e18)(Ct._1.outgoing)),Cn=Nt(v(Nt)(-1e18)(Ct._1.incoming))(v(Nt)(-1e18)(Ct._1.outgoing)),Me=v(qt=>Ot=>Ot>zt?qt:Ot>=Bt?qt+1|0:qt)(0)(Ct._1.outgoing)+v(qt=>Ot=>Ot>Cn?qt:Ot>=ne?qt+1|0:qt)(0)(lt)|0;return Lt===Me?Lt>0?{...mt,deps:mt.deps+2|0,crossings:mt.crossings+Lt|0}:mt:{...mt,deps:mt.deps+1|0,crossings:mt.crossings+ii(Lt)(Me)|0}}g()}})())({crossings:0,deps:0})(ft(Tt=>Tt.tgt===H.id,l.deps)))(ft(Tt=>Tt.src===H.id,l.deps)),pt=(()=>{if(H.splitBy.tag==="Just")return Ut(H.splitBy._1)(W.segMap);if(H.splitBy.tag==="Nothing")return J;g()})();if(pt.tag==="Just")return{...bt,deps:bt.deps+2|0,crossings:(()=>{const Tt=Jt(v(Jt)(1e18)(pt._1.incoming))(v(Jt)(1e18)(pt._1.outgoing)),Gt=Jt(v(Jt)(1e18)(lt))(v(Jt)(1e18)(H.outgoing)),jt=Nt(v(Nt)(-1e18)(pt._1.incoming))(v(Nt)(-1e18)(pt._1.outgoing)),Ct=Nt(v(Nt)(-1e18)(lt))(v(Nt)(-1e18)(H.outgoing)),Yt=Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(et));return bt.crossings+(()=>{const Dt=Jt(v(Jt)(1e18)(pt._1.incoming))(v(Jt)(1e18)(pt._1.outgoing)),wt=Nt(v(Nt)(-1e18)(H.incoming))(v(Nt)(-1e18)(et)),mt=Nt(v(Nt)(-1e18)(pt._1.incoming))(v(Nt)(-1e18)(pt._1.outgoing));return((v(ct=>yt=>yt>jt?ct:yt>=Tt?ct+1|0:ct)(0)(et)+v(ct=>yt=>yt>wt?ct:yt>=Yt?ct+1|0:ct)(0)(pt._1.incoming)|0)+v(ct=>yt=>yt>Ct?ct:yt>=Gt?ct+1|0:ct)(0)(pt._1.outgoing)|0)+v(ct=>yt=>yt>mt?ct:yt>=Dt?ct+1|0:ct)(0)(lt)|0})()|0})()};if(pt.tag==="Nothing")return bt;g()})()}))(L);return v(O=>X=>X.rating.crossings<O.rating.crossings||!(X.rating.crossings>O.rating.crossings)&&(X.rating.deps<O.rating.deps||!(X.rating.deps>O.rating.deps)&&X.c.a.size>O.c.a.size)?X:O)(0<U.length?U[0]:{c:G._1,rating:{crossings:1e6,deps:1e6}})(U).c}g()})(),V={...H,incoming:Pt(ot.compare)(H.incoming),outgoing:Pt(ot.compare)([(Q.a.startPosition+Q.a.endPosition)/2]),splitPartner:N("Just",W.nextId)},K={id:W.nextId,incoming:Pt(ot.compare)([(Q.a.startPosition+Q.a.endPosition)/2]),mark:0,members:H.members,outgoing:Pt(ot.compare)(H.outgoing),slot:0,splitBy:J,splitPartner:N("Just",H.id)};return{segMap:rt(it)(K.id)(K)(rt(it)(V.id)(V)(W.segMap)),freeAreas:(()=>{if(Q.i>=0&&Q.i<W.freeAreas.length){const U=h_(Kt,J,Q.i,W.freeAreas),O=(()=>{if(U.tag==="Nothing")return W.freeAreas;if(U.tag==="Just")return U._1;g()})();if(W.freeAreas[Q.i].size/2<d)return O;const X=(W.freeAreas[Q.i].startPosition+W.freeAreas[Q.i].endPosition)/2,et=X-d,lt=X+d;return[...Q.i<1?[]:Rt(0,Q.i,O),...W.freeAreas[Q.i].startPosition<=et?[{startPosition:W.freeAreas[Q.i].startPosition,endPosition:et,size:et-W.freeAreas[Q.i].startPosition}]:[],...lt<=W.freeAreas[Q.i].endPosition?[{startPosition:lt,endPosition:W.freeAreas[Q.i].endPosition,size:W.freeAreas[Q.i].endPosition-lt}]:[],...Q.i<1?O:Rt(Q.i,O.length,O)]}return W.freeAreas})(),nextId:W.nextId+1|0}})({segMap:Z,freeAreas:(()=>{const W=Pt(ot.compare)([...Et(l.segments)(H=>H.incoming),...Et(l.segments)(H=>H.outgoing)]);return vt(Dw)(Fe(H=>D=>D-H>=2*d?N("Just",{startPosition:H+d,endPosition:D-d,size:D-H-2*d}):J,W,Rt(1,W.length,W)))})(),nextId:l.segments.length})(Pt(W=>H=>ot.compare(Nt(v(Nt)(-1e18)(W.incoming))(v(Nt)(-1e18)(W.outgoing))-Jt(v(Jt)(1e18)(W.incoming))(v(Jt)(1e18)(W.outgoing)))(Nt(v(Nt)(-1e18)(H.incoming))(v(Nt)(-1e18)(H.outgoing))-Jt(v(Jt)(1e18)(H.incoming))(v(Jt)(1e18)(H.outgoing))))(vt(W=>Ut(W)(Z))(j.decisions)));return{segments:(()=>{const W=(H,D)=>{if(H.tag==="Leaf")return D;if(H.tag==="Node")return W(H._5,kt("Cons",H._4,W(H._6,D)));g()};return Zt(de.foldr,W(z.segMap,$))})(),deps:(()=>{const W=z.segMap,H=(L,G)=>{if(L.tag==="Leaf")return G;if(L.tag==="Node")return H(L._5,kt("Cons",L._4,H(L._6,G)));g()},D=Zt(de.foldr,H(W,$)),F=D.length;return[...Et(Et(Xt(0,F-2|0))(L=>Et(Xt(L+1|0,F-1|0))(G=>[b(L,G)])))(L=>L._1>=0&&L._1<D.length?L._2>=0&&L._2<D.length?D[L._1].splitPartner.tag!=="Nothing"&&D[L._1].splitPartner.tag==="Just"&&D[L._1].splitPartner._1===D[L._2].id||D[L._2].splitPartner.tag!=="Nothing"&&D[L._2].splitPartner.tag==="Just"&&D[L._2].splitPartner._1===D[L._1].id?[]:i(d,D[L._1],D[L._2]):[]:[]),...Et(D)(L=>L.splitBy.tag==="Just"&&L.splitPartner.tag==="Just"&&(()=>{const G=Ut(L.splitPartner._1)(W);if(G.tag==="Nothing")return!1;if(G.tag==="Just")return!0;g()})()&&(()=>{const G=Ut(L.splitBy._1)(W);if(G.tag==="Nothing")return!1;if(G.tag==="Just")return!0;g()})()?[{src:L.id,tgt:L.splitBy._1,weight:1,kind:js},{src:L.splitBy._1,tgt:L.splitPartner._1,weight:1,kind:js}]:[])]})()}})(),p=h.segments,m=p.length,w=R=>{let A=R,j=!0,Z;for(;j;){const z=A,W=re(H=>{const D=Ut(H)(z.inWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;g()})(z.remaining);if(W.tag==="Nothing"){j=!1,Z=z;continue}if(W.tag==="Just"){const H=W._1;A={...z,inWeight:v(D=>F=>Qt(it)(xe)(F.tgt)(-F.weight)(D))(z.inWeight)((()=>{const D=Ut(H)(z.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),marks:rt(it)(H)(z.nextSource)(z.marks),nextSource:z.nextSource+1|0,outWeight:v(D=>F=>Qt(it)(xe)(F.src)(-F.weight)(D))(z.outWeight)((()=>{const D=Ut(H)(z.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),remaining:ft(D=>D!==H,z.remaining)};continue}g()}return Z},x=R=>{let A=R,j=!0,Z;for(;j;){const z=A,W=re(H=>{const D=Ut(H)(z.outWeight);if(D.tag==="Nothing")return!0;if(D.tag==="Just")return D._1===0;g()})(z.remaining);if(W.tag==="Nothing"){j=!1,Z=z;continue}if(W.tag==="Just"){const H=W._1;A={...z,inWeight:v(D=>F=>Qt(it)(xe)(F.tgt)(-F.weight)(D))(z.inWeight)((()=>{const D=Ut(H)(z.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),marks:rt(it)(H)(z.nextSink)(z.marks),nextSink:z.nextSink-1|0,outWeight:v(D=>F=>Qt(it)(xe)(F.src)(-F.weight)(D))(z.outWeight)((()=>{const D=Ut(H)(z.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;g()})()),remaining:ft(D=>D!==H,z.remaining)};continue}g()}return Z},y=(R=>{let A=R,j=!0,Z;for(;j;){const z=w(x(A));if(z.remaining.length===0){j=!1,Z=q(W=>{const H=Ut(W.id)(z.marks),D=(()=>{if(H.tag==="Nothing")return W.id;if(H.tag==="Just")return H._1;g()})();return{...W,mark:D<m?(D+m|0)+1|0:D}})(p);continue}A=(()=>{const W=D=>{const F=Ut(D)(z.outWeight),L=Ut(D)(z.inWeight);return(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;g()})()-(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;g()})()|0},H=Pt(D=>F=>it.compare(W(F))(W(D)))(z.remaining);if(0<H.length){const D=H[0];return{...z,inWeight:v(F=>L=>Qt(it)(xe)(L.tgt)(-L.weight)(F))(z.inWeight)((()=>{const F=Ut(D)(z.depsBySrc);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})()),marks:rt(it)(D)(z.nextSource)(z.marks),nextSource:z.nextSource+1|0,outWeight:v(F=>L=>Qt(it)(xe)(L.src)(-L.weight)(F))(z.outWeight)((()=>{const F=Ut(D)(z.depsByTgt);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;g()})()),remaining:ft(F=>F!==D,z.remaining)}}return z})()}return Z})({remaining:q(R=>R.id)(p),marks:I,inWeight:v(R=>A=>Qt(it)(xe)(A.tgt)(A.weight)(R))(I)(h.deps),outWeight:v(R=>A=>Qt(it)(xe)(A.src)(A.weight)(R))(I)(h.deps),depsBySrc:v(R=>A=>Qt(it)(le)(A.src)([A])(R))(I)(h.deps),depsByTgt:v(R=>A=>Qt(it)(le)(A.tgt)([A])(R))(I)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),T=(()=>{const R=(()=>{const Z=ri(q(z=>b(z.id,z.mark))(y));return{segments:y,deps:vt(z=>(()=>{if(z.kind==="Critical")return!0;if(z.kind==="Regular")return!1;g()})()?N("Just",z):(()=>{const W=Ut(z.src)(Z),H=Ut(z.tgt)(Z);return(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})()>(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})()})()?z.weight===0?J:N("Just",{src:z.tgt,tgt:z.src,weight:z.weight,kind:z.kind}):N("Just",z))(h.deps)}})(),A=v(Z=>z=>Qt(it)(xe)(z.tgt)(1)(Z))(I)(R.deps),j=(Z=>{let z=Z,W=!0,H;for(;W;){const D=z,F=Ft(L=>J,L=>G=>N("Just",{head:L,tail:G}),D.queue);if(F.tag==="Nothing"){W=!1,H=D;continue}if(F.tag==="Just"){z=v((()=>{const L=Ut(F._1.head)(D.slots),G=(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;g()})();return Q=>V=>{const K=Ut(V)(Q.inDegree),U=(()=>{if(K.tag==="Nothing")return-1;if(K.tag==="Just")return K._1-1|0;g()})();return{...Q,slots:rt(it)(V)(n1((()=>{const O=Ut(V)(Q.slots);if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;g()})())(G+1|0))(Q.slots),inDegree:rt(it)(V)(U)(Q.inDegree),queue:U===0?[...Q.queue,V]:Q.queue}}})())({...D,queue:F._1.tail})((()=>{const L=Ut(F._1.head)(D.adj);if(L.tag==="Nothing")return[];if(L.tag==="Just")return L._1;g()})());continue}g()}return H})({slots:ri(q(Z=>b(Z.id,0))(R.segments)),inDegree:A,adj:v(Z=>z=>Qt(it)(le)(z.src)([z.tgt])(Z))(I)(R.deps),queue:q(Z=>Z.id)(ft(Z=>{const z=Ut(Z.id)(A);if(z.tag==="Nothing")return!0;if(z.tag==="Just")return z._1===0;g()},R.segments))});return Pt(Z=>z=>it.compare(Z.slot)(z.slot))(q(Z=>({...Z,slot:(()=>{const z=Ut(Z.id)(j.slots);if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;g()})()}))(R.segments))})(),C=1+v(R=>A=>n1(R)(A.slot))(0)(T)|0,S=Et(T)(R=>R.members),E=ft(R=>en(Zn)(R.edge.id)(S),t),B=v(Nt)(-1e18)(q(R=>R.fromPos._2)(E)),M=v(Jt)(1e18)(q(R=>R.toPos._2)(E));if(B>M){const R=ri(q(A=>b(A.id,A))(T));return hn(q(A=>q(j=>b(j,{slot:A.slot,slotCount:C,gapTop:M,gapBottom:B,partner:(()=>{if(A.splitPartner.tag==="Just"){const Z=Ut(A.splitPartner._1)(R);if(Z.tag==="Just")return N("Just",{slot:Z._1.slot,splitX:0<Z._1.incoming.length?Z._1.incoming[0]:0});if(Z.tag==="Nothing")return J;g()}if(A.splitPartner.tag==="Nothing")return J;g()})()}))(A.members))(ft(A=>{if(A.splitPartner.tag==="Just"){const j=Ut(A.splitPartner._1)(R);return!(j.tag==="Just"&&(()=>{if(j._1.splitBy.tag==="Nothing")return!1;if(j._1.splitBy.tag==="Just")return!0;g()})())}if(A.splitPartner.tag==="Nothing")return!0;g()},T)))}const Y=ri(q(R=>b(R.id,R))(T));return hn(q(R=>q(A=>b(A,{slot:R.slot,slotCount:C,gapTop:B,gapBottom:M,partner:(()=>{if(R.splitPartner.tag==="Just"){const j=Ut(R.splitPartner._1)(Y);if(j.tag==="Just")return N("Just",{slot:j._1.slot,splitX:0<j._1.incoming.length?j._1.incoming[0]:0});if(j.tag==="Nothing")return J;g()}if(R.splitPartner.tag==="Nothing")return J;g()})()}))(R.members))(ft(R=>{if(R.splitPartner.tag==="Just"){const A=Ut(R.splitPartner._1)(Y);return!(A.tag==="Just"&&(()=>{if(A._1.splitBy.tag==="Nothing")return!1;if(A._1.splitBy.tag==="Just")return!0;g()})())}if(R.splitPartner.tag==="Nothing")return!0;g()},T)))})()))(I)(Bw(v(s=>a=>{const u=oi(a.edge.from.node)(n);if(u.tag==="Just"){const c=oi(a.edge.to.node)(n);return c.tag==="Just"&&u._1.layer!==c._1.layer?Qt(it)(le)(ii(u._1.layer)(c._1.layer))([a])(s):s}return s})(I)((()=>{const s=a=>b((()=>{const u=oi(a.edge.from.node)(n);return u.tag==="Just"?u._1.layer:1e6})(),(()=>{const u=oi(a.edge.from.node)(n);return u.tag==="Just"?u._1.order:1e6})());return Pt(a=>u=>Pw(s(a))(s(u)))(t)})())))},Aw=t=>e=>{const n=o1(t)(e),r=v(o=>i=>rt(P)(i.node)(i)(o))(I)(e);return v(o=>i=>{const s=oi(i.edge.from.node)(r);if(s.tag==="Just"){const a=oi(i.edge.to.node)(r);if(a.tag==="Just"&&s._1.layer!==a._1.layer){const u=Rw(i.edge.id)(n);if(u.tag==="Just")return rt(it)(ii(s._1.layer)(a._1.layer))(u._1.slotCount)(o)}return o}return o})(I)(t)},yc=ce(P)(Mt),Er=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},xc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Iw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t._1)(i._3._1);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(t._2==="North"){if(i._3._2==="North"){r=!1,o=N("Just",i._4);continue}n=i._5;continue}if(i._3._2==="North"){n=i._6;continue}if(t._2==="South"){if(i._3._2==="South"){r=!1,o=N("Just",i._4);continue}n=i._5;continue}if(i._3._2==="South"){n=i._6;continue}if(t._2==="East"){if(i._3._2==="East"){r=!1,o=N("Just",i._4);continue}n=i._5;continue}if(i._3._2==="East"){n=i._6;continue}if(t._2==="West"&&i._3._2==="West"){r=!1,o=N("Just",i._4);continue}}g()}return o},i1=t=>e=>{const n=e.position._1+e.size._1,r=e.position._2*2+e.size._2,o=e.position._1*2+e.size._1,i=e.position._2+e.size._2;if(t==="South")return b(o,i*2);if(t==="North")return b(o,e.position._2*2);if(t==="East")return b(n*2,r);if(t==="West")return b(e.position._1*2,r);g()},wc=t=>e=>{const n=nt(4);if(t==="South")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="North")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="East")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};if(t==="West")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};g()},s1=t=>e=>v(n=>r=>Qt(t)(le)(e(r))([r])(n))(I),a1=t=>e=>n=>r=>{const o=(t==="South"||t==="North")&&(e==="East"||e==="West")&&(()=>{if(t==="South")return r._2>n._2;if(t==="North")return r._2<n._2;if(t==="East")return r._2>n._2;if(t==="West")return r._2<n._2;g()})()&&(()=>{if(e==="East")return n._1>r._1;if(e==="West"||e==="North")return n._1<r._1;if(e==="South")return n._1>r._1;g()})(),i=(t==="East"||t==="West")&&(e==="North"||e==="South")&&(()=>{if(t==="South")return r._1>n._1;if(t==="North")return r._1<n._1;if(t==="East")return r._1>n._1;if(t==="West")return r._1<n._1;g()})()&&(()=>{if(e==="East")return n._2>r._2;if(e==="West"||e==="North")return n._2<r._2;if(e==="South")return n._2>r._2;g()})();return(t==="South"?e==="North"&&n._1===r._1&&r._2>n._2:t==="North"?e==="South"&&n._1===r._1&&r._2<n._2:t==="East"?e==="West"&&n._2===r._2&&r._1>n._1:t==="West"&&e==="East"&&n._2===r._2&&r._1<n._1)?0:o||i?1:2},u1=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,o=e.length;return o===0?I:yc(o===1?q(i=>b(i,r))(e):Ht(i=>s=>b(s,t.lo+nt(i+1|0)*n/nt(o+1|0)))(e))},c1=t=>e=>n=>r=>o=>{const i=s1(P)(f=>f.to.node)(t),s=s1(P)(f=>f.from.node)(t),a=v(f=>h=>rt(P)(h.node)(h)(f))(I)(e),u=(f,h,p)=>{const m=Er(f)(a);if(m.tag==="Nothing")return b(0,0);if(m.tag==="Just"){const w=Er(f)(n);if(w.tag==="Nothing"){const x=nt(4);if(p==="South")return b(m._1.position._1*x+m._1.size._1*x/2,(m._1.position._2+m._1.size._2)*x);if(p==="North")return b(m._1.position._1*x+m._1.size._1*x/2,m._1.position._2*x);if(p==="East")return b((m._1.position._1+m._1.size._1)*x,m._1.position._2*x+m._1.size._2*x/2);if(p==="West")return b(m._1.position._1*x,m._1.position._2*x+m._1.size._2*x/2);g()}if(w.tag==="Just"){const x=re(y=>y.id===h)(w._1);if(x.tag==="Nothing"){const y=nt(4);if(p==="South")return b(m._1.position._1*y+m._1.size._1*y/2,(m._1.position._2+m._1.size._2)*y);if(p==="North")return b(m._1.position._1*y+m._1.size._1*y/2,m._1.position._2*y);if(p==="East")return b((m._1.position._1+m._1.size._1)*y,m._1.position._2*y+m._1.size._2*y/2);if(p==="West")return b(m._1.position._1*y,m._1.position._2*y+m._1.size._2*y/2);g()}if(x.tag==="Just"){const y=nt(4);if(x._1.side==="North")return b(m._1.position._1*y+nt(x._1.offset)*y,m._1.position._2*y);if(x._1.side==="South")return b(m._1.position._1*y+nt(x._1.offset)*y,(m._1.position._2+m._1.size._2)*y);if(x._1.side==="East")return b((m._1.position._1+m._1.size._1)*y,m._1.position._2*y+nt(x._1.offset)*y);if(x._1.side==="West")return b(m._1.position._1*y,m._1.position._2*y+nt(x._1.offset)*y)}}}g()},c=yc(Et(r)(f=>{if(f.nodes.length<=2)return[];const h=nt(4);if(1<f.nodes.length){const p=Er(f.nodes[1])(a);if(p.tag==="Nothing")return[];if(p.tag==="Just"){const m=p._1.position._1*h+p._1.size._1*h/2;return q(w=>b(w,m))(Fe(w=>x=>f.edgeId+":"+w+"->"+x,f.nodes,Rt(1,f.nodes.length,f.nodes)))}g()}return[]})),_=f=>{const h=Er(f.from.node)(a),p=Er(f.to.node)(a);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,w=p._1,x=Pt(y=>T=>it.compare(y.score)(T.score))(q(y=>{const T=y._1,C=y._2;return{from:T,to:C,score:(()=>{const S=(Y,R,A,j,Z)=>{const z=wc(Y)(R),W=wc(Y)(A);return z.lo<W.hi&&W.lo<z.hi&&(T==="South"?C==="North"&&Z._2>j._2:T==="North"?C==="South"&&Z._2<j._2:T==="East"?C==="West"&&Z._1>j._1:T==="West"&&C==="East"&&Z._1<j._1)?0:a1(T)(C)(j)(Z)},E=i1(T)(m),B=i1(C)(w),M=a1(T)(C)(E)(B);return(()=>{if(M>0){if(T==="South")return C==="North"?S(Le,m,w,E,B)*10|0:M*10|0;if(T==="North")return C==="South"?S(Se,m,w,E,B)*10|0:M*10|0;if(T==="East")return C==="West"?S(Tr,m,w,E,B)*10|0:M*10|0;if(T==="West"&&C==="East")return S(Cr,m,w,E,B)*10|0}return M*10|0})()+(T==="South"?C==="North"?w.layer>=m.layer?0:20:15:T==="North"?C==="South"?w.layer<=m.layer?0:20:15:T==="East"?C==="West"?5:15:T==="West"&&C==="East"?5:15)|0})()}})([b(Le,Se),b(Tr,Se),b(Cr,Se),b(Le,Tr),b(Le,Cr),b(Se,Le),b(Se,Tr),b(Se,Cr),b(Tr,Le),b(Cr,Le),b(Tr,Cr),b(Cr,Tr)]));if(0<x.length)return{from:x[0].from,to:x[0].to}}return{from:Le,to:Se}},d=yc(q(f=>b(f.id,_(f)))(t)),l=(f,h,p,m,w,x)=>{const y=nt(4),T=Er(h)(a);if(T.tag==="Nothing")return b(0,0);if(T.tag==="Just"){const C=Iw(b(p,f))(o);if(C.tag==="Just"){const S=T._1.position._1*y+C._1,E=nt(4);if(f==="South")return b(S,(T._1.position._2+T._1.size._2)*E);if(f==="North")return b(S,T._1.position._2*E);if(f==="East")return b((T._1.position._1+T._1.size._1)*E,S);if(f==="West")return b(T._1.position._1*E,S);g()}if(C.tag==="Nothing"){const S=wc(f)(T._1),E=(S.lo+S.hi)/2,B=xc(p)(u1(S)(q(R=>R.id)(Pt(R=>A=>ot.compare(w(f)(R))(w(f)(A)))(ft(R=>{const A=xc(R.id)(d);if(A.tag==="Just"){const j=x(A._1);return j==="North"?f==="North":j==="South"?f==="South":j==="East"?f==="East":j==="West"&&f==="West"}if(A.tag==="Nothing")return!0;g()},(()=>{const R=Er(h)(m);if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;g()})()))))),M=(()=>{if(B.tag==="Nothing")return E;if(B.tag==="Just")return B._1;g()})(),Y=nt(4);if(f==="South")return b(M,(T._1.position._2+T._1.size._2)*Y);if(f==="North")return b(M,T._1.position._2*Y);if(f==="East")return b((T._1.position._1+T._1.size._1)*Y,M);if(f==="West")return b(T._1.position._1*Y,M)}}g()};return q(f=>{const h=xc(f.edge.id)(c);if(h.tag==="Nothing")return f;if(h.tag==="Just")return{...f,fromPos:Re(3)(f.edge.from.node)==="$d:"?b(h._1,f.fromPos._2):f.fromPos,toPos:Re(3)(f.edge.to.node)==="$d:"?b(h._1,f.toPos._2):f.toPos};g()})(q(f=>{if(f.from.port.tag==="Just"&&f.to.port.tag==="Just")return{edge:f,fromPos:u(f.from.node,f.from.port._1,Le),toPos:u(f.to.node,f.to.port._1,Se),fromSide:Le,toSide:Se};const h=_(f);return{edge:f,fromPos:l(h.from,f.from.node,f.id,s,p=>m=>{const w=Er(m.to.node)(a);if(w.tag==="Nothing")return 0;if(w.tag==="Just"){const x=nt(4);if(p==="South"||p==="North")return w._1.position._1*x+w._1.size._1*x/2;if(p==="East"||p==="West")return w._1.position._2*x+w._1.size._2*x/2}g()},p=>p.from),toPos:l(h.to,f.to.node,f.id,i,p=>m=>{const w=Er(m.from.node)(a);if(w.tag==="Nothing")return 0;if(w.tag==="Just"){const x=nt(4);if(p==="South"||p==="North")return w._1.position._1*x+w._1.size._1*x/2;if(p==="East"||p==="West")return w._1.position._2*x+w._1.size._2*x/2}g()},p=>p.to),fromSide:h.from,toSide:h.to}})(t))},Zs=(()=>{const t={eq:e=>n=>e._1===n._1&&(e._2==="North"?n._2==="North":e._2==="South"?n._2==="South":e._2==="East"?n._2==="East":e._2==="West"&&n._2==="West")};return{compare:e=>n=>{const r=P.compare(e._1)(n._1);if(r==="LT")return Be;if(r==="GT")return De;if(e._2==="North")return n._2==="North"?Ye:Be;if(n._2==="North")return De;if(e._2==="South")return n._2==="South"?Ye:Be;if(n._2==="South")return De;if(e._2==="East")return n._2==="East"?Ye:Be;if(n._2==="East")return De;if(e._2==="West"&&n._2==="West")return Ye;g()},Eq0:()=>t}})(),Fw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=Zs.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Qw=ce(P)(Mt),Jc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},zw=ce(Zs)(Mt),g1=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),si=t=>e=>n=>r=>{const o=Fw(b(e,n))(t);if(o.tag==="Nothing")return r;if(o.tag==="Just")return o._1;g()},_1=t=>e=>n=>{const r=Qw(hn(q(s=>Ht(a=>u=>b(u,a))(s))(t))),o=(s,a)=>{if(s==="South"){const u=Jc(a.to.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()}if(s==="North"){const u=Jc(a.from.node)(r);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1;g()}return 0},i=s=>v(a=>u=>Qe(Zs.compare,Ie,zw(q(c=>b(b(c._1,s),c._2))(g1(u1({lo:0,hi:(()=>{const c=Jc(u._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return Re(3)(u._1)==="$d:"?0:1;g()})()})(q(c=>c.id)(Pt(c=>_=>it.compare(o(s,c))(o(s,_)))(u._2)))))),a))(I)(g1(v(a=>u=>u.from.node===u.to.node?a:s==="South"?Qt(P)(le)(u.from.node)([u])(a):s==="North"?Qt(P)(le)(u.to.node)([u])(a):a)(I)(e)));return Qe(Zs.compare,Ie,i(Se),i(Le))},f1=t=>t,d1=t=>t,l1=t=>t,Mw=v(t=>e=>rt(P)(e)()(t))(I),Ww=(()=>{const t=nn.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return N("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,kt("Cons",r._3,n(r._6,o)));g()};return n(e,$)})())})(),gt=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Ln=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ur=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},cr=ce(P)(Mt),Nc=N_(P),vc=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),Ow=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},qw=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},h1=l1("VDown"),p1=l1("VUp"),Hw=d1("ForwardPhase"),$w=d1("StackPhase"),m1=f1("HRight"),y1=f1("HLeft"),x1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Vw=t=>e=>n=>{const r=v(s=>a=>Qt(P)(xe)(a.tgt)(1)(s))(I)(t),o=Ww(Mw([...q(s=>s.src)(t),...q(s=>s.tgt)(t),...(()=>{const s=(a,u)=>{if(a.tag==="Leaf")return u;if(a.tag==="Node")return s(a._5,kt("Cons",a._4,s(a._6,u)));g()};return Zt(de.foldr,s(e,$))})()])),i=v(s=>a=>Qt(P)(le)(a.src)([{target:a.tgt,sep:a.sep}])(s))(I)(t);return(s=>a=>u=>{let c=s,_=a,d=u,l=!0,f;for(;l;){const h=c,p=_,m=d,w=Ft(x=>J,x=>y=>N("Just",{head:x,tail:y}),h);if(w.tag==="Nothing"){l=!1,f=m;continue}if(w.tag==="Just"){const x=gt(w._1.head)(m),y=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})(),T=v(C=>S=>{const E=gt(S.target)(C.result),B=y+S.sep,M=gt(S.target)(C.indeg),Y=(()=>{if(M.tag==="Nothing")return-1;if(M.tag==="Just")return M._1-1|0;g()})();return{newQueue:Y===0?[...C.newQueue,S.target]:C.newQueue,result:rt(P)(S.target)((()=>{if(E.tag==="Nothing")return B;if(E.tag==="Just"){if(n==="VDown")return Ln(E._1)(B);if(n==="VUp")return ur(E._1)(B)}g()})())(C.result),indeg:rt(P)(S.target)(Y)(C.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const C=gt(w._1.head)(i);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;g()})());c=[...w._1.tail,...T.newQueue],_=T.indeg,d=T.result;continue}g()}return f})(ft(s=>{const a=gt(s)(r);if(a.tag==="Nothing")return!0;if(a.tag==="Just")return a._1===0;g()},o))(r)(v(s=>a=>rt(P)(a)(0)(s))(I)(o))},Uw=t=>{const e=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return e(i._5,kt("Cons",i._4,e(i._6,s)));g()},n=Zt(de.foldr,e(t,$)),r=v(Ln)(999999)(n);if(r===0||n.length===0)return t;const o=i=>{if(i.tag==="Leaf")return I;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,i._4-r,o(i._5),o(i._6));g()};return o(t)},w1=t=>{const e=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return e(i._5,kt("Cons",i._4,e(i._6,s)));g()},n=e(t,$),r=i=>s=>{let a=i,u=s,c=!0,_;for(;c;){const d=a,l=u;if(l.tag==="Nil"){c=!1,_=d;continue}if(l.tag==="Cons"){a=ur(d)(l._1),u=l._2;continue}g()}return _},o=i=>s=>{let a=i,u=s,c=!0,_;for(;c;){const d=a,l=u;if(l.tag==="Nil"){c=!1,_=d;continue}if(l.tag==="Cons"){a=Ln(d)(l._1),u=l._2;continue}g()}return _};return r(-999999)(n)-o(999999)(n)},Mi=t=>e=>(n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=i;if(u===e){s=!1,a=c;continue}o=(()=>{const _=gt(u)(t.align);if(_.tag==="Nothing")return e;if(_.tag==="Just")return _._1;g()})(),i=[...c,u]}return a})((()=>{const n=gt(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;g()})())([e]),Kw=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>_=>{const d=(D,F,L)=>{const G=D.from.node===F?D.from.port:D.to.node===F?D.to.port:J;if(G.tag==="Just"){const Q=gt(F)(o);if(Q.tag==="Just"){const V=re(K=>K.id===G._1)(Q._1);if(V.tag==="Just"){const K=nt(V._1.offset)*nt(4);return L==="North"||L==="South"?K:0}if(V.tag==="Nothing"){const K=gt(F)(r),U=si(s)(D.id)(L)((()=>{if(K.tag==="Nothing")return .5;if(K.tag==="Just")return K._1._1/2;g()})());return L==="North"||L==="South"?U:0}g()}if(Q.tag==="Nothing"){const V=gt(F)(r),K=si(s)(D.id)(L)((()=>{if(V.tag==="Nothing")return .5;if(V.tag==="Just")return V._1._1/2;g()})());return L==="North"||L==="South"?K:0}g()}if(G.tag==="Nothing"){const Q=gt(F)(r),V=si(s)(D.id)(L)((()=>{if(Q.tag==="Nothing")return .5;if(Q.tag==="Just")return Q._1._1/2;g()})());return L==="North"||L==="South"?V:0}g()},l=(D,F)=>{if(D.from.node===F){if(_==="HRight")return Le;if(_==="HLeft")return Se;g()}if(_==="HRight")return Se;if(_==="HLeft")return Le;g()},f=(D,F,L)=>v(G=>Q=>rt(P)(Q)((()=>{const V=gt(Q)(G);if(V.tag==="Nothing")return 0+F;if(V.tag==="Just")return V._1+F;g()})())(G))(L)(Mi(u)(D)),h=(()=>{if(_==="HRight")return n;if(_==="HLeft")return se(n);g()})(),p=D=>{const F=gt(D)(r);if(F.tag==="Nothing")return 1;if(F.tag==="Just")return F._1._1;g()},m=cr(hn(Ht(D=>F=>q(L=>b(L,D))(F))(n))),w=(D,F)=>Re(3)(D)==="$d:"&&Re(3)(F)==="$d:"||Re(3)(D)==="$d:"||Re(3)(F)==="$d:"?10:nt(t.nodeGap),x=v(D=>F=>Nc(L=>N("Just",[...(()=>{if(L.tag==="Nothing")return[];if(L.tag==="Just")return L._1;g()})(),F]))(F.to.node)(D))(I)(i),y=v(D=>F=>Nc(L=>N("Just",[...(()=>{if(L.tag==="Nothing")return[];if(L.tag==="Just")return L._1;g()})(),F]))(F.from.node)(D))(I)(i),T=hn(n),C=v(D=>F=>{const L=gt(F)(u.root),G=(()=>{if(L.tag==="Nothing")return F;if(L.tag==="Just")return L._1;g()})();return F===G?D:Nc(Q=>N("Just",(()=>{if(Q.tag==="Nothing")return!0;if(Q.tag==="Just")return Q._1;g()})()&&Re(3)(F)==="$d:"))(G)(D)})(cr(q(D=>b(D,!0))(Fo(P.compare)((()=>{const D=(F,L)=>{if(F.tag==="Leaf")return L;if(F.tag==="Node")return D(F._5,kt("Cons",F._4,D(F._6,L)));g()};return Zt(de.foldr,D(u.root,$))})()))))(T),S=(D,F)=>{const L=D.free,G=gt(L)(u.root),Q=(()=>{if(G.tag==="Nothing")return L;if(G.tag==="Just")return G._1;g()})(),V=gt(Q)(C),K=(()=>{if(V.tag==="Nothing")return!0;if(V.tag==="Just")return V._1;g()})();return v(U=>O=>{if(U.edge.tag==="Just")return U;if(U.edge.tag==="Nothing"){if((()=>{const pt=gt(Q)(F.su);return!K&&(()=>{const Tt=gt(O.from.node)(m);return O.from.node!==O.to.node&&(()=>{const Gt=gt(O.to.node)(m);return(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._1;g()})()===(()=>{if(Gt.tag==="Nothing")return-1;if(Gt.tag==="Just")return Gt._1;g()})()})()})()||(()=>{if(pt.tag==="Nothing")return!1;if(pt.tag==="Just")return pt._1;g()})()})())return U;const X=O.from.node===L?O.to.node:O.from.node,et=gt(X)(u.root),lt=(()=>{if(et.tag==="Nothing")return X;if(et.tag==="Just")return et._1;g()})(),bt=lt!==Q;return bt&&(()=>{const pt=gt(lt)(F.blockFinished);if(pt.tag==="Nothing")return!1;if(pt.tag==="Just")return pt._1;g()})()?{...U,edge:N("Just",O),hasEdges:!0}:{...U,hasEdges:U.hasEdges||bt}}g()})({edge:J,hasEdges:!1})((()=>{if(D.isRoot){if(_==="HRight"){const U=gt(L)(x);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;g()}if(_==="HLeft"){const U=gt(L)(y);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1}g()}if(_==="HRight"){const U=gt(L)(y);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;g()}if(_==="HLeft"){const U=gt(L)(x);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1}g()})())},E=(D,F,L,G)=>{const Q=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})(),V={free:F,isRoot:L},K=S(V,G);if(K.edge.tag==="Nothing")return K.hasEdges?{thresh:Q,state:{...G,queue:[...G.queue,V]}}:{thresh:Q,state:G};if(K.edge.tag==="Just"){const U=K.edge._1.from.node===F?K.edge._1.to.node:K.edge._1.from.node;return{thresh:(()=>{const O=gt((()=>{const bt=gt(U)(u.root);if(bt.tag==="Nothing")return U;if(bt.tag==="Just")return bt._1;g()})())(G.x),X=gt(U)(a),et=gt(F)(a),lt=(()=>{if(O.tag==="Just")return O._1;if(O.tag==="Nothing")return J;g()})();return(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1;g()})()+(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;g()})()+d(K.edge._1,U,(()=>{if(L){if(_==="HRight")return Le;if(_==="HLeft")return Se;g()}if(_==="HRight")return Se;if(_==="HLeft")return Le;g()})())-(()=>{if(et.tag==="Nothing")return 0;if(et.tag==="Just")return et._1;g()})()-d(K.edge._1,F,(()=>{if(L){if(_==="HRight")return Se;if(_==="HLeft")return Le;g()}if(_==="HRight")return Le;if(_==="HLeft")return Se;g()})())})(),state:{...G,su:rt(P)((()=>{const O=gt(K.edge._1.from.node)(u.root);if(O.tag==="Nothing")return K.edge._1.from.node;if(O.tag==="Just")return O._1;g()})())(!0)(rt(P)((()=>{const O=gt(K.edge._1.to.node)(u.root);if(O.tag==="Nothing")return K.edge._1.to.node;if(O.tag==="Just")return O._1;g()})())(!0)(G.su))}}}g()},B=(D,F,L,G)=>{const Q=F===D,V=gt(F)(u.align),K=(()=>{if(V.tag==="Nothing")return F===D;if(V.tag==="Just")return V._1===D;g()})();if(!(Q||K))return{thresh:L,state:G};const U=(()=>{if(c==="VDown")return Q&&L<=-1e18;if(c==="VUp")return Q&&L>=1e18;g()})()?E(D,F,!0,G):{thresh:L,state:G};return(()=>{if(c==="VDown")return U.thresh<=-1e18&&K;if(c==="VUp")return U.thresh>=1e18&&K;g()})()?E(D,F,!1,U.state):U},M=D=>F=>L=>{const G=gt(L)(e.nodeIndex),Q=(()=>{if(G.tag==="Nothing")return 0;if(G.tag==="Just")return G._1;g()})(),V=re(et=>en(Zn)(L)(et))(h),K=(()=>{if(V.tag==="Nothing")return[];if(V.tag==="Just")return V._1;g()})(),U=K.length;if((()=>{if(c==="VDown")return Q<=0;if(c==="VUp")return Q>=(U-1|0);g()})()){const et=B(D,L,F.thresh,F.st);return{...F,st:et.state,thresh:et.thresh}}const O=(()=>{if(c==="VDown")return Q-1|0;if(c==="VUp")return Q+1|0;g()})(),X=O>=0&&O<K.length?N("Just",K[O]):J;if(X.tag==="Nothing")return F;if(X.tag==="Just"){const et=gt(X._1)(u.root),lt=(()=>{if(et.tag==="Nothing")return X._1;if(et.tag==="Just")return et._1;g()})(),bt=B(D,L,F.thresh,Y(lt)(F.st)),pt=(()=>{const zt=gt(D)(bt.state.sink);if(zt.tag==="Nothing")return D===D;if(zt.tag==="Just")return zt._1===D;g()})()?{...bt.state,sink:rt(P)(D)((()=>{const zt=gt(lt)(bt.state.sink);if(zt.tag==="Nothing")return lt;if(zt.tag==="Just")return zt._1;g()})())(bt.state.sink)}:bt.state,Tt=gt(lt)(pt.sink),Gt=(()=>{if(Tt.tag==="Nothing")return lt;if(Tt.tag==="Just")return Tt._1;g()})(),jt=gt(D)(pt.sink),Ct=(()=>{if(jt.tag==="Nothing")return D;if(jt.tag==="Just")return jt._1;g()})();if(Ct===Gt){const zt=gt(lt)(pt.x),ne=(()=>{if(zt.tag==="Just")return zt._1;if(zt.tag==="Nothing")return J;g()})(),Cn=(()=>{if(ne.tag==="Nothing")return 0;if(ne.tag==="Just")return ne._1;g()})(),Me=gt(D)(pt.x),qt=(()=>{if(Me.tag==="Just")return Me._1;if(Me.tag==="Nothing")return J;g()})(),Ot=(()=>{if(qt.tag==="Nothing")return 0;if(qt.tag==="Just")return qt._1;g()})(),We=w(L,X._1),bn=gt(X._1)(a),tn=gt(L)(a),_n=(()=>{if(bn.tag==="Nothing")return 0;if(bn.tag==="Just")return bn._1;g()})()-(()=>{if(tn.tag==="Nothing")return 0;if(tn.tag==="Just")return tn._1;g()})();if(c==="VDown"){const Ae=ur(Cn+_n+p(X._1)+We)(bt.thresh);return{st:{...pt,x:rt(P)(D)(N("Just",F.initial?Ae:ur(Ot)(Ae)))(pt.x)},initial:!1,thresh:bt.thresh}}if(c==="VUp"){const Ae=Ln(Cn+_n-We-p(L))(bt.thresh);return{st:{...pt,x:rt(P)(D)(N("Just",F.initial?Ae:Ln(Ot)(Ae)))(pt.x)},initial:!1,thresh:bt.thresh}}g()}const Yt=gt(lt)(pt.x),Dt=(()=>{if(Yt.tag==="Just")return Yt._1;if(Yt.tag==="Nothing")return J;g()})(),wt=(()=>{if(Dt.tag==="Nothing")return 0;if(Dt.tag==="Just")return Dt._1;g()})(),mt=gt(D)(pt.x),ct=(()=>{if(mt.tag==="Just")return mt._1;if(mt.tag==="Nothing")return J;g()})(),yt=(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})(),dt=nt(t.nodeGap),ht=gt(L)(a),Lt=gt(X._1)(a),Bt=(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()-(()=>{if(Lt.tag==="Nothing")return 0;if(Lt.tag==="Just")return Lt._1;g()})();return{st:{...pt,classEdges:[...pt.classEdges,{src:Ct,tgt:Gt,sep:(()=>{if(c==="VDown")return yt+Bt-wt-p(X._1)-dt;if(c==="VUp")return yt+Bt+p(L)+dt-wt;g()})()}]},initial:F.initial,thresh:bt.thresh}}g()},Y=D=>F=>{const L=gt(D)(F.x),G=(()=>{if(L.tag==="Just")return L._1;if(L.tag==="Nothing")return J;g()})();if(G.tag==="Just")return F;if(G.tag==="Nothing"){const Q=v(M(D))({st:{...F,x:rt(P)(D)(N("Just",0))(F.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;g()})()})(Mi(u)(D));return{...Q.st,blockFinished:rt(P)(D)(!0)(Q.st.blockFinished)}}g()},R=v(D=>F=>v(L=>G=>{const Q=gt(G)(u.root),V=(()=>{if(Q.tag==="Nothing")return G;if(Q.tag==="Just")return Q._1;g()})();return V===G?Y(V)(L):L})(D)((()=>{if(c==="VDown")return F;if(c==="VUp")return se(F);g()})()))({x:cr(q(D=>b(D,J))(T)),sink:cr(q(D=>b(D,D))(T)),classEdges:[],su:I,blockFinished:I,queue:[]})(h),A=Vw(R.classEdges)(R.sink)(c),j=(D,F,L,G)=>{const Q=gt(F)(G),V=gt(F)(a);return(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;g()})()+(()=>{if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1;g()})()+d(D,F,L)},Z=cr(q(D=>b(D,!0))(Fo(P.compare)((()=>{const D=(F,L)=>{if(F.tag==="Leaf")return L;if(F.tag==="Node")return D(F._5,kt("Cons",F._4,D(F._6,L)));g()};return Zt(de.foldr,D(u.root,$))})()))),z=D=>F=>L=>{const G=S(L,{su:F.su,blockFinished:Z}),Q={phase:D,ppFree:L.free,ppIsRoot:L.isRoot,edgeId:J,delta:0,avail:0,shift:0,freeSu:(()=>{const V=gt((()=>{const K=gt(L.free)(u.root);if(K.tag==="Nothing")return L.free;if(K.tag==="Just")return K._1;g()})())(F.su);if(V.tag==="Nothing")return!1;if(V.tag==="Just")return V._1;g()})(),hasEdges:G.hasEdges,candCount:(()=>{if(L.isRoot){if(_==="HRight"){const V=gt(L.free)(x);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length;g()}if(_==="HLeft"){const V=gt(L.free)(y);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length}g()}if(_==="HRight"){const V=gt(L.free)(y);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length;g()}if(_==="HLeft"){const V=gt(L.free)(x);if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1.length}g()})()};if(G.edge.tag==="Nothing")return{...F,stack:[...F.stack,L],trace:[...F.trace,Q],x:F.x};if(G.edge.tag==="Just"){const V=G.edge._1.from.node===L.free?b(G.edge._1.from.node,G.edge._1.to.node):b(G.edge._1.to.node,G.edge._1.from.node),K=j(G.edge._1,V._1,l(G.edge._1,V._1),F.x)-j(G.edge._1,V._2,l(G.edge._1,V._2),F.x),U=gt(V._1)(u.root),O=(()=>{if(U.tag==="Nothing")return V._1;if(U.tag==="Just")return U._1;g()})(),X={...Q,edgeId:N("Just",G.edge._1.id),delta:K};if(K>0&&K<1e300){const et=v(pt=>Tt=>{const Gt=gt(Tt)(m),jt=(()=>{if(Gt.tag==="Nothing")return-1;if(Gt.tag==="Just")return Gt._1;g()})();if(jt>=0&&jt<n.length){const Dt=n[jt],wt=gt(Tt)(e.nodeIndex),mt=(()=>{if(wt.tag==="Nothing")return-2;if(wt.tag==="Just")return wt._1-1|0;g()})();return mt>=0&&mt<Dt.length?Ln(pt)((()=>{const ct=gt(Tt)(F.x),yt=gt(Tt)(a),dt=gt(Dt[mt])(F.x),ht=gt(Dt[mt])(a);return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;g()})()-((()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1;g()})()+(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+p(Dt[mt])+w(Tt,Dt[mt]))})()):pt}const Ct=gt(Tt)(e.nodeIndex),Yt=(()=>{if(Ct.tag==="Nothing")return-2;if(Ct.tag==="Just")return Ct._1-1|0;g()})();return Yt>=0&&Yt<0?Ln(pt)((()=>{const Dt=gt(Tt)(F.x),wt=gt(Tt)(a),mt=gt([][Yt])(F.x),ct=gt([][Yt])(a);return(()=>{if(Dt.tag==="Nothing")return 0;if(Dt.tag==="Just")return Dt._1;g()})()+(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1;g()})()-((()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()+(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+p([][Yt])+w(Tt,[][Yt]))})()):pt})(K)(Mi(u)(O)),lt=et>0?-et:0,bt={...F,x:et>0?f(O,lt,F.x):F.x,trace:[...F.trace,{...X,avail:et,shift:lt}]};return et>0?bt:{...bt,stack:[...bt.stack,L]}}if(K<0&&-K<1e300){const et=v(pt=>Tt=>{const Gt=gt(Tt)(m),jt=(()=>{if(Gt.tag==="Nothing")return-1;if(Gt.tag==="Just")return Gt._1;g()})();if(jt>=0&&jt<n.length){const Dt=n[jt],wt=gt(Tt)(e.nodeIndex),mt=(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1+1|0;g()})();return mt>=0&&mt<Dt.length?Ln(pt)((()=>{const ct=gt(Dt[mt])(F.x),yt=gt(Dt[mt])(a),dt=gt(Tt)(F.x),ht=gt(Tt)(a);return(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;g()})()-((()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1;g()})()+(()=>{if(ht.tag==="Nothing")return 0;if(ht.tag==="Just")return ht._1;g()})()+p(Tt)+w(Tt,Dt[mt]))})()):pt}const Ct=gt(Tt)(e.nodeIndex),Yt=(()=>{if(Ct.tag==="Nothing")return 0;if(Ct.tag==="Just")return Ct._1+1|0;g()})();return Yt>=0&&Yt<0?Ln(pt)((()=>{const Dt=gt([][Yt])(F.x),wt=gt([][Yt])(a),mt=gt(Tt)(F.x),ct=gt(Tt)(a);return(()=>{if(Dt.tag==="Nothing")return 0;if(Dt.tag==="Just")return Dt._1;g()})()+(()=>{if(wt.tag==="Nothing")return 0;if(wt.tag==="Just")return wt._1;g()})()-((()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;g()})()+(()=>{if(ct.tag==="Nothing")return 0;if(ct.tag==="Just")return ct._1;g()})()+p(Tt)+w(Tt,[][Yt]))})()):pt})(-K)(Mi(u)(O)),lt=et>0?et:0,bt={...F,x:et>0?f(O,lt,F.x):F.x,trace:[...F.trace,{...X,avail:et,shift:lt}]};return et>0?bt:{...bt,stack:[...bt.stack,L]}}return{...F,stack:[...F.stack,L],trace:[...F.trace,X],x:F.x}}g()},W=v(z(Hw))({x:cr(q(D=>b(D,(()=>{const F=gt(D)(u.root),L=(()=>{if(F.tag==="Nothing")return D;if(F.tag==="Just")return F._1;g()})(),G=gt(L)(R.x),Q=gt((()=>{const K=gt(L)(R.sink);if(K.tag==="Nothing")return L;if(K.tag==="Just")return K._1;g()})())(A),V=(()=>{if(G.tag==="Just")return G._1;if(G.tag==="Nothing")return J;g()})();return(()=>{if(V.tag==="Nothing")return 0;if(V.tag==="Just")return V._1;g()})()+(()=>{if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;g()})()})()))(T)),su:R.su,stack:[],trace:[]})(R.queue),H=v(z($w))({...W,stack:[]})(se(W.stack));return{x:H.x,queue:R.queue,trace:H.trace}},Yw=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>_=>Kw(t)(e)(n)(r)(o)(i)(s)(a)(u)(c)(_).x,Xw=t=>e=>n=>r=>o=>i=>{const s=(u,c,_)=>{const d=gt(c)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;g()})(),f=u.from.node===c?u.from.port:u.to.node===c?u.to.port:J;if(f.tag==="Just"){const h=gt(c)(e);if(h.tag==="Just"){const p=re(m=>m.id===f._1)(h._1);if(p.tag==="Just"){const m=nt(p._1.offset)*nt(4);return _==="North"||_==="South"?m:0}if(p.tag==="Nothing"){const m=si(o)(u.id)(_)(l);return _==="North"||_==="South"?m:0}g()}if(h.tag==="Nothing"){const p=si(o)(u.id)(_)(l);return _==="North"||_==="South"?p:0}g()}if(f.tag==="Nothing"){const h=si(o)(u.id)(_)(l);return _==="North"||_==="South"?h:0}g()},a=u=>c=>_=>d=>{let l=u,f=c,h=_,p=d,m=!0,w;for(;m;){const x=l,y=f,T=h,C=Ft(S=>J,S=>E=>N("Just",{head:S,tail:E}),p);if(C.tag==="Nothing"){m=!1,w=x;continue}if(C.tag==="Just"){const S=C._1.head,E=re(M=>M.from.node===T&&M.to.node===S||M.from.node===S&&M.to.node===T)(r),B=(()=>{if(E.tag==="Nothing")return y+0;if(E.tag==="Just")return y+(s(E._1,T,E._1.from.node===T?Le:Se)-s(E._1,S,E._1.from.node===S?Le:Se));g()})();l=rt(P)(S)(B)(x),f=B,h=S,p=C._1.tail;continue}g()}return w};return v(u=>c=>{const _=Ft(f=>J,f=>h=>N("Just",{head:f,tail:h}),Mi(t)(c)),d=(()=>{if(_.tag==="Nothing")return rt(P)(c)(0)(I);if(_.tag==="Just")return a(rt(P)(_._1.head)(0)(I))(0)(_._1.head)(_._1.tail);g()})(),l=v(f=>h=>ur(f)(-h._2))(0)(vc(d));return v(f=>h=>rt(P)(h._1)(h._2+l)(f))(u)(vc(d))})(I)(Fo(P.compare)((()=>{const u=(c,_)=>{if(c.tag==="Leaf")return _;if(c.tag==="Node")return u(c._5,kt("Cons",c._4,u(c._6,_)));g()};return Zt(de.foldr,u(t.root,$))})()))},jw=t=>e=>{const n=(o,i,s)=>Re(3)(i)==="$d:"&&p_(t1,(()=>{const a=gt(i)(t.preds);if(a.tag==="Nothing")return[];if(a.tag==="Just")return a._1;g()})()),r=o=>i=>s=>a=>u=>c=>_=>{let d=o,l=i,f=a,h=c,p=_,m=!0,w;for(;m;){const x=d,y=l,T=f,C=h,S=p,E=y.length;if(S>=E){m=!1,w=x;continue}const B=S>=0&&S<y.length?N("Just",y[S]):J,M=(()=>{if(B.tag==="Nothing")return"";if(B.tag==="Just")return B._1;g()})(),Y=n(t,M);if(S===(E-1|0)||Y){const R=(()=>{if(Y){const A=gt(M)(t.preds),j=(()=>{if(A.tag==="Nothing")return[];if(A.tag==="Just")return A._1;g()})();if(0<j.length){const Z=T-1|0,z=gt(j[0])(t.nodeIndex);if(z.tag==="Nothing")return Z;if(z.tag==="Just")return z._1;g()}}return T-1|0})();d=v(A=>j=>{if(j>=0&&j<y.length){const Z=y[j];return n(t,Z)?A:v(z=>W=>{const H=gt(W)(t.nodeIndex),D=(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;g()})();return D<C||D>R?rt(P)(W+"\u2192"+Z)()(z):z})(A)((()=>{const z=gt(Z)(t.preds);if(z.tag==="Nothing")return[];if(z.tag==="Just")return z._1;g()})())}return n(t,"")?A:v(Z=>z=>{const W=gt(z)(t.nodeIndex),H=(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;g()})();return H<C||H>R?rt(P)(z+"\u2192")()(Z):Z})(A)((()=>{const Z=gt("")(t.preds);if(Z.tag==="Nothing")return[];if(Z.tag==="Just")return Z._1;g()})())})(x)(Xt(0,S)),l=y,f=T,h=R,p=S+1|0;continue}d=x,l=y,f=T,h=C,p=S+1|0}return w};return e.length<3?I:v(o=>i=>{if(i>=0&&i<e.length){const s=e[i];return r(o)((()=>{const a=i+1|0;return a>=0&&a<e.length?e[a]:[]})())(s)(s.length)(i)(0)(0)}return r(o)((()=>{const s=i+1|0;return s>=0&&s<e.length?e[s]:[]})())([])(0)(i)(0)(0)})(I)(Xt(1,e.length-2|0))},Zw=t=>e=>n=>r=>o=>{const i=hn(e),s=v(a=>u=>{const c=v(_=>d=>{const l=(()=>{if(o==="HRight"){const m=gt(d)(t.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()}if(o==="HLeft"){const m=gt(d)(t.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}g()})(),f=l.length;if(f===0)return _;const h=Jr(f-1|0,2),p=Jr(f,2);return v(m=>w=>{if((()=>{const x=gt(d)(m.align);if(x.tag==="Nothing")return d!==d;if(x.tag==="Just")return x._1!==d;g()})())return m;if(w>=0&&w<l.length){const x=gt(l[w])(t.nodeIndex),y=(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})();if(!(x1(l[w]+"\u2192"+d)(n)||x1(d+"\u2192"+l[w])(n))&&(()=>{if(r==="VDown")return m.r<y;if(r==="VUp")return m.r>y;g()})()){const T=gt(l[w])(m.root),C=(()=>{if(T.tag==="Nothing")return l[w];if(T.tag==="Just")return T._1;g()})();return{root:rt(P)(d)(C)(m.root),align:rt(P)(l[w])(d)(rt(P)(d)(C)(m.align)),r:y}}}return m})(_)((()=>{if(r==="VDown")return Xt(h,p);if(r==="VUp")return se(Xt(h,p));g()})())})({root:a.root,align:a.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;g()})()})((()=>{if(r==="VDown")return u;if(r==="VUp")return se(u);g()})());return{root:c.root,align:c.align}})({root:cr(q(a=>b(a,a))(i)),align:cr(q(a=>b(a,a))(i))})((()=>{if(o==="HRight")return e;if(o==="HLeft")return se(e);g()})());return{root:s.root,align:s.align}},ta=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>{const _=Zw(e)(n)(a)(u)(c),d=Xw(_)(o)(r)(i)(s)(c);return K0()(l=>f=>N("Just",(()=>{const h=gt(l)(d);if(h.tag==="Nothing")return f+0;if(h.tag==="Just")return f+h._1;g()})()))(Yw(t)(e)(n)(r)(o)(i)(s)(d)(_)(u)(c))},J1=t=>e=>Ht(n=>r=>v(o=>i=>i>=0&&i<e.length?i>=0&&i<t.length?o+e[i]+t[i]:o+e[i]+0:i>=0&&i<t.length?o+1+t[i]:o+1)(0)((()=>{const o=Xt(0,e.length-1|0);return n<1?[]:Rt(0,n,o)})()))(e),tJ=t=>e=>n=>r=>o=>i=>s=>{const a=Ow(0)(e.length-1|0),u=nt(t.layerGap),c=s(P0(a,u)),_=Aw(c1(o)(c)(r)(i)(I))(c);return q(d=>{const l=qw(d)(_);return l.tag==="Just"&&l._1>0?ur(u)(2+nt(l._1-1|0)*2.5):u})(Xt(0,a-1|0))},N1=t=>e=>n=>r=>p_(o=>v(i=>s=>{if(!i.ok)return i;const a=gt(s)(r),u=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})(),c=gt(s)(n),_=(()=>{if(c.tag==="Nothing")return u+1;if(c.tag==="Just")return u+c._1._1;g()})();return u+1e-4>i.pos&&_+1e-4>i.pos?{ok:!0,pos:_}:{ok:!1,pos:i.pos}})({ok:!0,pos:-1e18})(o).ok,e),eJ=t=>e=>n=>r=>{const o=Pt(i=>s=>ot.compare(i.w)(s.w))(q(i=>({l:i,w:w1(i)}))(ft(N1()(e)(n),r)));return 0<o.length?N("Just",o[0].l):J},nJ=t=>e=>{const n=cr(hn(q(Ht(o=>i=>b(i,o)))(t))),r=o=>Pt(i=>s=>it.compare((()=>{const a=gt(i)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})())((()=>{const a=gt(s)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})()))(o);return{preds:(()=>{const o=i=>{if(i.tag==="Leaf")return I;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(v(i=>s=>Qt(P)(le)(s.to.node)([s.from.node])(i))(I)(e))})(),succs:(()=>{const o=i=>{if(i.tag==="Leaf")return I;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(v(i=>s=>Qt(P)(le)(s.from.node)([s.to.node])(i))(I)(e))})(),nodeIndex:n}},rJ=t=>e=>{const n=Pt(d=>l=>ot.compare(d.w)(l.w))(Ht(d=>l=>({i:d,l,w:w1(l)}))(e)),r=0<n.length?N("Just",n[0]):J,o=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;g()})(),i=o>=0&&o<e.length?N("Just",e[o]):J,s=(()=>{if(i.tag==="Just")return(d=>l=>{let f=d,h=l,p=!0,m;for(;p;){const w=f,x=h;if(x.tag==="Nil"){p=!1,m=w;continue}if(x.tag==="Cons"){f=Ln(w)(x._1),h=x._2;continue}g()}return m})(999999)((()=>{const d=(l,f)=>{if(l.tag==="Leaf")return f;if(l.tag==="Node")return d(l._5,kt("Cons",l._4,d(l._6,f)));g()};return d(i._1,$)})());if(i.tag==="Nothing")return 0;g()})(),a=d=>v(l=>f=>ur(l)((()=>{const h=gt(f._1)(t);if(h.tag==="Nothing")return f._2+1;if(h.tag==="Just")return f._2+h._1._1;g()})()))(-999999)(vc(d)),u=o>=0&&o<e.length?N("Just",e[o]):J,c=(()=>{if(u.tag==="Just")return a(u._1);if(u.tag==="Nothing")return 0;g()})(),_=Fe(d=>l=>{const f=h=>{if(h.tag==="Leaf")return I;if(h.tag==="Node")return te("Node",h._1,h._2,h._3,h._4+l,f(h._5),f(h._6));g()};return f(d)},e,Ht(d=>l=>Wr(d)(2)===0?s-(f=>h=>{let p=f,m=h,w=!0,x;for(;w;){const y=p,T=m;if(T.tag==="Nil"){w=!1,x=y;continue}if(T.tag==="Cons"){p=Ln(y)(T._1),m=T._2;continue}g()}return x})(999999)((()=>{const f=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return f(h._5,kt("Cons",h._4,f(h._6,p)));g()};return f(l,$)})()):c-a(l))(e));return Uw(v(d=>l=>{const f=Pt(ot.compare)(vt(gt(l))(_));return rt(P)(l)(f.length===4?1<f.length&&2<f.length?(f[1]+f[2])/2:0:0<f.length?f[0]:0)(d)})(I)(Fo(P.compare)(hn(q(d=>{const l=f=>{if(f.tag==="Leaf")return I;if(f.tag==="Node")return te("Node",f._1,f._2,f._3,void 0,l(f._5),l(f._6));g()};return Zt(fn.foldr,l(d))})(_)))))},oJ=t=>e=>n=>r=>o=>i=>{const s=nJ(e)(o),a=jw(s)(e),u={nodeGap:t.nodeGap*4|0},c=Qe(P.compare,Ie,cr(q(f=>b(f,b(1,1)))(ft(t1,hn(e)))),(()=>{const f=h=>{if(h.tag==="Leaf")return I;if(h.tag==="Node")return te("Node",h._1,h._2,h._3,b(h._4._1*nt(4),h._4._2),f(h._5),f(h._6));g()};return f(n)})()),_=[ta(u)(s)(e)(c)(r)(o)(i)(a)(h1)(m1),ta(u)(s)(e)(c)(r)(o)(i)(a)(p1)(m1),ta(u)(s)(e)(c)(r)(o)(i)(a)(h1)(y1),ta(u)(s)(e)(c)(r)(o)(i)(a)(p1)(y1)],d=rJ(c)(_);if(N1()(e)(c)(d))return d;const l=eJ()(e)(c)(_);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return _[0];g()},iJ=t=>e=>n=>r=>{const o=d_(J,a_,i=>i.node===e?N("Just",i.position):J,t);if(o.tag==="Nothing")return t;if(o.tag==="Just"){const i=o._1;return q(s=>s.node===n?{...s,position:b(i._1+r._1,i._2+r._2)}:s)(t)}g()},sJ=t=>e=>n=>r=>{const o=ft(s=>en(Zn)(s.node)(e),t),i=(()=>{if(n==="Vertical"){if(r==="Start")return v(s=>a=>Ln(s)(a.position._1))(99999)(o);if(r==="End")return v(s=>a=>ur(s)(a.position._1))(0)(o);if(r==="Center"){const s=v(a=>u=>a+u.position._1)(0)(o);return o.length===0?0:s/nt(o.length)}g()}if(n==="Horizontal"){if(r==="Start")return v(s=>a=>Ln(s)(a.position._2))(99999)(o);if(r==="End")return v(s=>a=>ur(s)(a.position._2))(0)(o);if(r==="Center"){const s=v(a=>u=>a+u.position._2)(0)(o);return o.length===0?0:s/nt(o.length)}}g()})();return q(s=>{if(en(Zn)(s.node)(e)){if(n==="Vertical")return{...s,position:b(i,s.position._2)};if(n==="Horizontal")return{...s,position:b(s.position._1,i)};g()}return s})(t)},aJ=t=>e=>v(n=>r=>r.tag==="AlignGroup"?sJ(n)(r._1.nodes)(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?iJ(n)(r._1.anchor)(r._1.target)(r._1.offset):n)(e)(t),uJ=t=>e=>n=>r=>o=>i=>s=>a=>{const u=q(d=>v(l=>f=>ur(l)((()=>{const h=gt(f)(r);if(h.tag==="Nothing")return 1;if(h.tag==="Just")return h._1._2;g()})()))(1)(d))(n),c=oJ(t)(n)(r)(o)(i)(a),_=J1(tJ(t)(n)(r)(o)(i)(s)(d=>{const l=J1(d)(u);return hn(Ht(f=>h=>Ht(p=>m=>({node:m,position:b((()=>{const w=gt(m)(c);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;g()})()/nt(4)})(),f>=0&&f<l.length?l[f]:0),size:(()=>{const w=Re(3)(m)==="$d:"?b(0,1):b(1,1),x=gt(m)(r);if(x.tag==="Nothing")return w;if(x.tag==="Just")return x._1;g()})(),layer:f,order:p}))(h))(n))}))(u);return aJ(e)(hn(Ht(d=>l=>Ht(f=>h=>({node:h,position:b((()=>{const p=gt(h)(c);return(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})()/nt(4)})(),d>=0&&d<_.length?_[d]:0),size:(()=>{const p=Re(3)(h)==="$d:"?b(0,1):b(1,1),m=gt(h)(r);if(m.tag==="Nothing")return p;if(m.tag==="Just")return m._1;g()})(),layer:d,order:f}))(l))(n)))},Tc=Au(ks)(uo(32)),v1=Au(ks)(uo(31)),Wi=(()=>{const t=Qm("25214903917");if(t.tag==="Nothing")return F_;if(t.tag==="Just")return t._1;g()})(),Oi=Ru(Au(ks)(uo(48)))(ks),cJ=t=>{const e=zm(t);return Pi(Q_((()=>{if(e.tag==="Nothing")return F_;if(e.tag==="Just")return e._1;g()})())(Wi))(Oi)},Cc=uo(11),ea=t=>e=>{const n=Pi(Cs(bs(e)(Wi))(Cc))(Oi);return b((()=>{const r=y_(Rm(Iu(n)(uo(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;g()})(),n)},gJ=t=>{const e=ea(26)(t),n=ea(27)(e._2);return b((nt(e._1)*mu(2)(27)+nt(n._1))/mu(2)(53),n._2)},_J=t=>e=>{const n=v(r=>o=>{const i=gJ(r.finalR);return{rs:[...r.rs,i._1],finalR:i._2}})({rs:[],finalR:t})(e);return b(q(r=>r.x)(Pt(r=>o=>ot.compare(r.k)(o.k))(Fe(r=>o=>({x:r,k:o}),e,n.rs))),n.finalR)},fJ=t=>{const e=Pi(Cs(bs(t)(Wi))(Cc))(Oi),n=Pi(Cs(bs(e)(Wi))(Cc))(Oi);return b(Cs(bs((()=>{const r=Iu(e)(uo(16));return z_.compare(r)(v1)!=="LT"?Ru(r)(Tc):r})())(Tc))((()=>{const r=Iu(n)(uo(16));return z_.compare(r)(v1)!=="LT"?Ru(r)(Tc):r})()),n)},qi=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},na=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},bc=ce(P)(Mt),ai=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ra=ce(P)(Mt),dJ=hu(Ti),lJ=v(er)(0),hJ=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},T1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},pJ=t=>e=>n=>{if(t>=0&&t<n.length){const r=n[t];if(e>=0&&e<n.length){const o=Mr(Kt,J,t,n[e],n);if(o.tag==="Just")return Mr(Kt,J,e,r,o._1);if(o.tag==="Nothing")return J;g()}}return J},mJ=t=>e=>n=>r=>o=>bc(v(i=>s=>{const a=Pt(u=>c=>it.compare((()=>{const _=qi(u.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;g()})())((()=>{const _=qi(c.id)(o);if(_.tag==="Nothing")return 1e6;if(_.tag==="Just")return _._1;g()})()))(ft(u=>na(u.to.node)(n),ft(u=>u.from.node===s,r)));return{ranks:[...i.ranks,...Ht(u=>c=>b(c.id,nt((i.rankSum+u|0)+1|0)))(a)],rankSum:i.rankSum+a.length|0}})({ranks:[],rankSum:0})(t).ranks),yJ=t=>e=>n=>r=>o=>bc(v(i=>s=>{const a=Pt(c=>_=>{const d=it.compare((()=>{const l=ai(_.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})())((()=>{const l=ai(c.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;g()})());return d==="EQ"?it.compare((()=>{const l=qi(c.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})())((()=>{const l=qi(_.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;g()})()):d})(ft(c=>na(c.from.node)(n),ft(c=>c.to.node===s,r))),u=a.length;return{ranks:[...i.ranks,...Ht(c=>_=>b(_.id,nt((i.rankSum+u|0)-c|0)))(a)],rankSum:i.rankSum+u|0}})({ranks:[],rankSum:0})(t).ranks),kc=t=>e=>n=>{const r=ra(Ht(a=>u=>b(u,a))(t)),o=ra(Ht(a=>u=>b(u,a))(e)),i=vt(a=>{const u=ai(a.from.node)(r),c=ai(a.to.node)(o);if(u.tag==="Just"&&c.tag==="Just")return N("Just",b(u._1,c._1));const _=ai(a.from.node)(o),d=ai(a.to.node)(r);return _.tag==="Just"&&d.tag==="Just"?N("Just",b(d._1,_._1)):J})(n),s=i.length;return v(a=>u=>v(c=>_=>u>=0&&u<i.length&&_>=0&&_<i.length&&((i[u]._1-i[_]._1|0)*(i[u]._2-i[_]._2|0)|0)<0?c+1|0:c)(a)(Xt(u+1|0,s-1|0)))(0)(Xt(0,s-2|0))},xJ=t=>e=>n=>r=>{const o=i=>s=>{let a=i,u=s,c=!0,_;for(;c;){const d=a,l=u;if(l>=(d.length-1|0)){c=!1,_=d;continue}if(l>=0&&l<d.length){const f=l+1|0;if(f>=0&&f<d.length){const h=d[l],p=d[f];if(Ne(y=>y.before===h&&y.after===p,r)){a=d,u=l+1|0;continue}const m=Mr(Kt,J,l,p,d),w=(()=>{if(m.tag==="Just")return Mr(Kt,J,l+1|0,h,m._1);if(m.tag==="Nothing")return J;g()})(),x=(()=>{if(w.tag==="Nothing")return d;if(w.tag==="Just")return w._1;g()})();if(kc(e)(x)(n)<kc(e)(d)(n)){a=x,u=l+1|0;continue}a=d,u=l+1|0;continue}c=!1,_=d;continue}c=!1,_=d}return _};return(i=>{let s=i,a=!0,u;for(;a;){const c=s,_=o(c)(0);if(dJ(_)(c)){a=!1,u=c;continue}s=_}return u})(t)},oa=t=>e=>v(n=>r=>{if(r>=0&&r<t.length){const o=t[r],i=r+1|0;if(i>=0&&i<t.length)return n+kc(o)(t[i])(e)|0}return n})(0)(Xt(0,t.length-2|0)),wJ=(()=>{const t=e=>{if(e.length<7){const i=s=>a=>{let u=s,c=a,_=!0,d;for(;_;){const l=u,f=c,h=f-1|0;if(h>=0&&h<l.length){if(f>=0&&f<l.length&&f>0&&l[h].key>l[f].key){const p=pJ(f-1|0)(f)(l);if(p.tag==="Just"){u=p._1,c=f-1|0;continue}if(p.tag==="Nothing"){_=!1,d=l;continue}g()}_=!1,d=l;continue}_=!1,d=l}return d};return v(s=>a=>i(s)(a))(e)(Xt(1,e.length-1|0))}const n=Jr(e.length,2),r=t(Rt(0,n,e)),o=t(Rt(n,e.length,e));return(i=>s=>a=>{let u=i,c=s,_=a,d=!0,l;for(;d;){const f=u,h=c,p=_;if(h>=0&&h<r.length){if(p>=0&&p<o.length){if(r[h].key>o[p].key){u=St(f)(o[p]),c=h,_=p+1|0;continue}u=St(f)(r[h]),c=h+1|0,_=p;continue}d=!1,l=[...f,...h<1?r:Rt(h,r.length,r)];continue}d=!1,l=[...f,...p<1?o:Rt(p,o.length,o)]}return l})([])(0)(0)};return t})(),JJ=t=>e=>n=>{const r=vt(c=>c.tag==="OrderConstraint"?N("Just",{before:c._1.before,after:c._1.after}):J)(t.constraints),o=c=>v(_=>d=>{const l=d.after,f=d.before,h=io(Kt,J,m=>m===f,_),p=io(Kt,J,m=>m===l,_);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=h_(Kt,J,h._1,_),w=(()=>{if(m.tag==="Nothing")return _;if(m.tag==="Just")return m._1;g()})(),x=l_(Kt,J,p._1,f,w);if(x.tag==="Nothing")return w;if(x.tag==="Just")return x._1;g()}return _})(c)(r),i=bc(Ht(c=>_=>b(_.id,c))(n)),s=(c,_,d)=>{const l=c.length;return v(f=>h=>{const p=_?h-1|0:h+1|0,m=p>=0&&p<f._1.length?N("Just",f._1[p]):J;if(m.tag==="Just"){const w=h>=0&&h<f._1.length?N("Just",f._1[h]):J;if(w.tag==="Just"){const x=ra(Ht(E=>B=>b(B,E))(m._1)),y=ra(Ht(E=>B=>b(B,E))(w._1)),T=_?mJ(m._1)(x)(y)(n)(i):yJ(m._1)(x)(y)(n)(i),C=v(E=>B=>{const M=vt(R=>qi(R.id)(T))(ft(_?R=>R.to.node===B._2&&na(R.from.node)(x):R=>R.from.node===B._2&&na(R.to.node)(x),n));if(M.length===0)return{...E,items:[...E.items,{n:B._2,key:J,origIdx:B._1}]};const Y=ea(24)(E.r);return{items:[...E.items,{n:B._2,key:N("Just",(lJ(M)+(nt(Y._1)*4172325152040912e-24-.03500000014901161))/nt(M.length)),origIdx:B._1}],r:Y._2}})({items:[],r:f._2})(Ht(Rn)(w._1)),S=Mr(Kt,J,h,xJ(o(q(E=>E.n)(wJ((()=>{const E=C.items,B=M=>Y=>{let R=M,A=Y,j=!0,Z;for(;j;){const z=R,W=A;if(z>=0&&z<E.length){if(E[z].key.tag==="Just"){j=!1,Z=E[z].key._1;continue}if(E[z].key.tag==="Nothing"){R=z+1|0,A=W;continue}g()}j=!1,Z=W}return Z};return(M=>Y=>R=>{let A=M,j=Y,Z=R,z=!0,W;for(;z;){const H=A,D=j,F=Z;if(H>=0&&H<E.length){if(E[H].key.tag==="Just"){A=H+1|0,j=E[H].key._1,Z=[...F,{n:E[H].n,key:E[H].key._1,origIdx:E[H].origIdx}];continue}if(E[H].key.tag==="Nothing"){const L=(D+B(H+1|0)(D+1))/2;A=H+1|0,j=L,Z=[...F,{n:E[H].n,key:L,origIdx:E[H].origIdx}];continue}g()}z=!1,W=F}return W})(0)(-1)([])})()))))(m._1)(n)(r),f._1);if(S.tag==="Just")return b(S._1,C.r);if(S.tag==="Nothing")return b(f._1,f._2);g()}if(w.tag==="Nothing")return b(f._1,f._2);g()}if(m.tag==="Nothing")return b(f._1,f._2);g()})(b(c,d))(_?Xt(1,l-1|0):se(Xt(0,l-2|0)))},a=v(c=>_=>rt(P)(_.from.node)()(rt(P)(_.to.node)()(c)))(I)(n),u=v(c=>_=>{if(c.result.crossings===0)return c;const d=x=>y=>T=>C=>{let S=x,E=y,B=T,M=C,Y=!0,R;for(;Y;){const A=S,j=E,Z=B,z=M;if(Z===0){Y=!1,R={layout:A,crossings:0,random:z};continue}const W=s(A,j,z),H=oa(W._1)(n);if(H<Z){S=W._1,E=!j,B=H,M=W._2;continue}Y=!1,R={layout:A,crossings:Z,random:W._2}}return R},l=ea(1)(c.result.random),f=l._1!==0,h=t.modelOrder.tag==="Leaf",p=(c.firstTry||c.secondTry)&&!h?c.firstTry:f,m=(()=>{if(!h){const C=s(e,p,l._2);return d(C._1)(!p)(oa(C._1)(n))(C._2)}const x=p?0:hJ(0)(e.length-1|0),y=x>=0&&x<e.length?N("Just",e[x]):J;if(y.tag==="Just"&&y._1.length>1){const C=ft(S=>T1(S)(a),y._1);if(C.length>1){const S=_J(l._2)(C),E=S._1,B=Mr(Kt,J,x,o(v(M=>Y=>T1(Y)(a)?M.idx>=0&&M.idx<E.length?{idx:M.idx+1|0,result:[...M.result,E[M.idx]]}:{idx:M.idx,result:[...M.result,Y]}:{idx:M.idx,result:[...M.result,Y]})({idx:0,result:[]})(y._1).result),e);if(B.tag==="Just"){const M=s(B._1,p,S._2);return d(M._1)(!p)(oa(M._1)(n))(M._2)}}}const T=s(e,p,l._2);return d(T._1)(!p)(oa(T._1)(n))(T._2)})(),w=c.secondTry?!1:c.secondTry;return c.firstTry?{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<c.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...c.result,random:m.random},firstTry:c.firstTry,secondTry:w}})({result:{layout:e,crossings:1e9,random:Pi(Q_(fJ(cJ(1))._1)(Wi))(Oi)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Xt(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:u.layout},NJ=t=>t,C1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},on=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ui=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Hi=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=P.compare(e._1)(n._1);return r==="LT"?Be:r==="GT"?De:P.compare(e._2)(n._2)},Eq0:()=>t}})(),vJ=ce(P)(Mt),TJ=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=Hi.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},CJ=NJ("Greedy"),Sc=t=>e=>n=>v(r=>o=>{if(o.from.node===o.to.node)return r;if(o.from.node===e&&!C1(o.to.node)(r.marks)){const i=on(o.to.node)(r.inDeg),s=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;g()})(),a=rt(P)(o.to.node)(s)(r.inDeg);return(()=>{const u=on(o.to.node)(r.outDeg);return s<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;g()})()&&!en(Zn)(o.to.node)(r.sources)})()?{...r,inDeg:a,sources:[...r.sources,o.to.node]}:{...r,inDeg:a}}if(o.to.node===e&&!C1(o.from.node)(r.marks)){const i=on(o.from.node)(r.outDeg),s=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;g()})(),a=rt(P)(o.from.node)(s)(r.outDeg);return(()=>{const u=on(o.from.node)(r.inDeg);return s<=0&&(()=>{if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1>0;g()})()&&!en(Zn)(o.from.node)(r.sinks)})()?{...r,outDeg:a,sinks:[...r.sinks,o.from.node]}:{...r,outDeg:a}}return r})({...n,remaining:ft(r=>r!==e,n.remaining)})(t),bJ=v(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return rt(P)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return rt(P)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return rt(P)(e._1.node)(99999)(t)}return t})(I),b1=t=>e=>n=>{const r=on(e)(t),o=on(n)(t);return r.tag==="Just"&&o.tag==="Just"&&r._1>o._1},k1=t=>e=>n=>r=>{if(ui(n)(r.visited)||ui(n)(r.visiting))return r;const o=v(kJ(t)(e)(n))({...r,visiting:rt(P)(n)()(r.visiting)})((()=>{const i=on(n)(e);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;g()})());return{...o,visiting:Wo(P)(n)(o.visiting),visited:rt(P)(n)()(o.visited)}},kJ=t=>e=>n=>r=>o=>b1(t)(n)(o)?{...r,backEdges:rt(Hi)(b(n,o))()(r.backEdges)}:ui(o)(r.visiting)?{...r,backEdges:rt(Hi)(b(n,o))()(r.backEdges)}:ui(o)(r.visited)?r:k1(t)(e)(o)(r),SJ=t=>e=>n=>{const r=l=>{let f=l,h=!0,p;for(;h;){const m=f,w=Ft(x=>J,x=>y=>N("Just",{head:x,tail:y}),m.sinks);if(w.tag==="Just"){f=Sc(n)(w._1.head)({...m,sinks:w._1.tail,marks:rt(P)(w._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(w.tag==="Nothing"){const x=Ft(y=>J,y=>T=>N("Just",{head:y,tail:T}),m.sources);if(x.tag==="Just"){f=Sc(n)(x._1.head)({...m,sources:x._1.tail,marks:rt(P)(x._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(x.tag==="Nothing"){const y=C=>{const S=on(C)(m.outDeg),E=on(C)(m.inDeg);return(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;g()})()-(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;g()})()|0},T=Pt(C=>S=>{const E=it.compare(y(S))(y(C));return E==="EQ"?it.compare((()=>{const B=on(C)(e);if(B.tag==="Nothing")return 1e6;if(B.tag==="Just")return B._1;g()})())((()=>{const B=on(S)(e);if(B.tag==="Nothing")return 1e6;if(B.tag==="Just")return B._1;g()})()):E})(m.remaining);if(0<T.length){const C=T[0];f=Sc(n)(C)({...m,remaining:ft(S=>S!==C,m.remaining),marks:rt(P)(C)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}g()}return p},o=Fo(P.compare)([...q(l=>l.from.node)(n),...q(l=>l.to.node)(n)]),i=ft(l=>l.from.node!==l.to.node,n),s=v(l=>f=>Qt(P)(xe)(f.to.node)(1)(l))(I)(i),a=v(l=>f=>Qt(P)(xe)(f.from.node)(1)(l))(I)(i),u=ft(l=>{const f=on(l)(s);if(f.tag==="Nothing")return!0;if(f.tag==="Just")return f._1===0;g()},o),c=ft(l=>{const f=on(l)(a);if(f.tag==="Nothing")return!0;if(f.tag==="Just")return f._1===0;g()},o),_=o.length+1|0,d=v(l=>f=>{const h=on(f)(l);return h.tag==="Just"&&h._1<0?rt(P)(f)(h._1+_|0)(l):l})(r({remaining:ft(l=>!en(Zn)(l)(u)&&!en(Zn)(l)(c),o),marks:I,inDeg:s,outDeg:a,sources:u,sinks:c,nextLeft:1,nextRight:-1}).marks)(o);return v(l=>f=>{if(f.from.node===f.to.node)return l;if(b1(t)(f.from.node)(f.to.node))return rt(Hi)(b(f.from.node,f.to.node))()(l);const h=on(f.from.node)(d),p=on(f.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?rt(Hi)(b(f.from.node,f.to.node))()(l):l})(I)(n)},LJ=v(t=>e=>Qt(P)(le)(e.from.node)([e.to.node])(t))(I),EJ=t=>e=>{const n=LJ(e),r=Fo(P.compare)([...q(i=>i.from.node)(e),...q(i=>i.to.node)(e)]),o=v(i=>s=>rt(P)(s.to.node)()(i))(I)(e);return v(i=>s=>k1(t)(n)(s)(i))({visiting:I,visited:I,backEdges:I})([...ft(i=>!ui(i)(o),r),...ft(i=>ui(i)(o),r)]).backEdges},GJ=t=>e=>n=>r=>{const o=vJ(Ht(a=>u=>b(u,a))(e)),i=bJ(n),s=(()=>{if(t==="DepthFirst")return EJ(i)(r);if(t==="Greedy")return SJ(i)(o)(r);g()})();return{edges:q(a=>TJ(b(a.from.node,a.to.node))(s)?{...a,from:a.to,to:a.from}:a)(r),reversedEdges:s}},S1=Mt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),Te=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ce=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},$i=t=>e=>n=>r=>S1(o=>n>=o.x&&n<o.x+o.w&&e>o.y&&t<o.y+o.h)(r),ia=t=>e=>n=>r=>$i(Te(e)(n))(Ce(e)(n))(r)(t),sa=nt(4),PJ=ys(t=>{if(t.direction==="H"){const e=Te(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:Ce(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=Te(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:Ce(t.start._2)(t.end._2)-e}]}g()}),Vi=bi(t=>{const e=t.start._1-t.end._1;return!((e<0?-e<1e-6:e<1e-6)&&(()=>{const n=t.start._2-t.end._2;return n<0?-n<1e-6:n<1e-6})())}),BJ=t=>e=>n=>{const r=Ft(o=>J,o=>i=>N("Just",{head:o,tail:i}),e);if(r.tag==="Nothing")return[{start:t.start,end:n.end,direction:t.direction}];if(r.tag==="Just"){const o=(r._1.head.direction==="H"?t.direction==="H":r._1.head.direction==="V"&&t.direction==="V")?[{start:t.start,end:r._1.head.end,direction:t.direction}]:[t,r._1.head],i=Nr(r._1.tail);if(i.tag==="Nothing"){const s=o.length-1|0;return s>=0&&s<o.length&&(o[s].direction==="H"?n.direction==="H":o[s].direction==="V"&&n.direction==="V")?[...(()=>{const a=o.length-1|0;return a<1?[]:Rt(0,a,o)})(),{start:o[s].start,end:n.end,direction:n.direction}]:[...o,n]}if(i.tag==="Just")return(i._1.last.direction==="H"?n.direction==="H":i._1.last.direction==="V"&&n.direction==="V")?[...o,...i._1.init,{start:i._1.last.start,end:n.end,direction:n.direction}]:[...o,...r._1.tail,n]}g()},Ui=t=>{const e=r=>o=>{const i=Ft(s=>J,s=>a=>N("Just",{head:s,tail:a}),o);if(i.tag==="Nothing")return[r];if(i.tag==="Just")return(r.direction==="H"?i._1.head.direction==="H":r.direction==="V"&&i._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==i._1.head.end._1-i._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==i._1.head.end._2-i._1.head.start._2>=0;g()})()?e({start:r.start,end:i._1.head.end,direction:r.direction})(i._1.tail):[r,...e(i._1.head)(i._1.tail)];g()},n=Ft(r=>J,r=>o=>N("Just",{head:r,tail:o}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);g()},Ki=t=>e=>n=>r=>S1(o=>n>=o.y&&n<o.y+o.h&&e>o.x&&t<o.x+o.w)(r),Yi=t=>e=>n=>r=>Ki(Te(e)(n))(Ce(e)(n))(r)(t),DJ=t=>e=>n=>r=>{const o=n+2|0,i=o<1?e:Rt(o,e.length,e),s=n<1?[]:Rt(0,n,e),a=(n+1|0)===(r-1|0),u=n===0,c=n>=0&&n<e.length?N("Just",e[n]):J;if(c.tag==="Just"){const _=n+1|0,d=_>=0&&_<e.length?N("Just",e[_]):J;if(d.tag==="Just"){const l=c._1.start._1===d._1.end._1&&(!u||c._1.direction==="V")&&(!a||d._1.direction==="V")&&!ia(t)(Te(c._1.start._2)(d._1.end._2))(Ce(c._1.start._2)(d._1.end._2))(c._1.start._1)?N("Just",[...s,{start:c._1.start,end:d._1.end,direction:me},...i]):J,f=c._1.start._2===d._1.end._2&&(!u||c._1.direction==="H")&&(!a||d._1.direction==="H")&&!Yi(t)(Te(c._1.start._1)(d._1.end._1))(Ce(c._1.start._1)(d._1.end._1))(c._1.start._2)?N("Just",[...s,{start:c._1.start,end:d._1.end,direction:pe},...i]):J;return l.tag==="Nothing"?f:l}if(d.tag==="Nothing")return J;g()}if(c.tag==="Nothing")return J;g()},RJ=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,s;for(;i;){const a=o;if((a+1|0)>=n){i=!1,s=e;continue}const u=DJ(t)(e)(a)(n);if(u.tag==="Just"){i=!1,s=u._1;continue}if(u.tag==="Nothing"){o=a+1|0;continue}g()}return s})(0)},AJ=t=>e=>n=>r=>{const o=(l,f,h)=>!ia(t)(Te(f)(h))(Ce(f)(h))(l),i=n+3|0,s=i<1?e:Rt(i,e.length,e),a=n<1?[]:Rt(0,n,e),u=(n+2|0)===(r-1|0),c=n===0,_=(l,f,h)=>!Yi(t)(Te(f)(h))(Ce(f)(h))(l),d=n>=0&&n<e.length?N("Just",e[n]):J;if(d.tag==="Just"){const l=n+2|0,f=l>=0&&l<e.length?N("Just",e[l]):J;if(f.tag==="Just"){const h=d._1.start._1===f._1.end._1&&(!c||d._1.direction==="V")&&(!u||f._1.direction==="V")&&o(d._1.start._1,d._1.start._2,f._1.end._2)?N("Just",[...a,{start:d._1.start,end:f._1.end,direction:me},...s]):d._1.start._2===f._1.end._2&&(!c||d._1.direction==="H")&&(!u||f._1.direction==="H")&&_(d._1.start._2,d._1.start._1,f._1.end._1)?N("Just",[...a,{start:d._1.start,end:f._1.end,direction:pe},...s]):J,p=(!c||d._1.direction==="V")&&(!u||f._1.direction==="H")&&o(d._1.start._1,d._1.start._2,f._1.end._2)&&_(f._1.end._2,d._1.start._1,f._1.end._1)?N("Just",[...a,{start:d._1.start,end:b(d._1.start._1,f._1.end._2),direction:me},{start:b(d._1.start._1,f._1.end._2),end:f._1.end,direction:pe},...s]):J,m=(!c||d._1.direction==="H")&&(!u||f._1.direction==="V")&&_(d._1.start._2,d._1.start._1,f._1.end._1)&&o(f._1.end._1,d._1.start._2,f._1.end._2)?N("Just",[...a,{start:d._1.start,end:b(f._1.end._1,d._1.start._2),direction:pe},{start:b(f._1.end._1,d._1.start._2),end:f._1.end,direction:me},...s]):J,w=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?w:h}if(f.tag==="Nothing")return J;g()}if(d.tag==="Nothing")return J;g()},IJ=t=>e=>{const n=e.length;return(r=>{let o=r,i=!0,s;for(;i;){const a=o;if((a+2|0)>=n){i=!1,s=e;continue}const u=AJ(t)(e)(a)(n);if(u.tag==="Just"){i=!1,s=u._1;continue}if(u.tag==="Nothing"){o=a+1|0;continue}g()}return s})(0)},FJ=t=>{const e=n=>{let r=n,o=!0,i;for(;o;){const s=r,a=Ui(Vi(RJ(t)(IJ(t)(s))));if(a.length<s.length){r=a;continue}o=!1,i=a}return i};return n=>e(Ui(Vi(n)))},QJ=t=>e=>n=>r=>{const o=Te(n)(r),i=Ce(n)(r),s=ft(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Pt(c=>_=>ot.compare(c.x)(_.x))(s);return 0<u.length?u[0].x-1:(n+r)/2}const a=Pt(u=>c=>ot.compare(c.x)(u.x))(q(u=>({...u,x:u.x+u.w}))(s));return 0<a.length?a[0].x+1:(n+r)/2},zJ=t=>e=>n=>r=>{const o=Te(n)(r),i=Ce(n)(r),s=ft(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Pt(c=>_=>ot.compare(c.y)(_.y))(s);return 0<u.length?u[0].y-1:(n+r)/2}const a=Pt(u=>c=>ot.compare(c.y)(u.y))(q(u=>({...u,y:u.y+u.h}))(s));return 0<a.length?a[0].y+1:(n+r)/2},MJ=t=>e=>n=>r=>{const o=Te(n)(r),i=Ce(n)(r),s=ft(u=>e>=u.y&&e<u.y+u.h&&u.x+u.w>o&&u.x<i,t);if(r>n){const u=Pt(c=>_=>ot.compare(_.x)(c.x))(q(c=>({...c,x:c.x+c.w}))(s));return 0<u.length?u[0].x:(n+r)/2}const a=Pt(u=>c=>ot.compare(u.x)(c.x))(s);return 0<a.length?a[0].x-1:(n+r)/2},WJ=t=>e=>n=>r=>{const o=Te(n)(r),i=Ce(n)(r),s=ft(u=>e>=u.x&&e<u.x+u.w&&u.y+u.h>o&&u.y<i,t);if(r>n){const u=Pt(c=>_=>ot.compare(_.y)(c.y))(q(c=>({...c,y:c.y+c.h}))(s));return 0<u.length?u[0].y:(n+r)/2}const a=Pt(u=>c=>ot.compare(u.y)(c.y))(s);return 0<a.length?a[0].y-1:(n+r)/2},L1=t=>e=>n=>{let r=t,o=e,i=n,s=!0,a;for(;s;){const u=r,c=o,_=i;if(_>100){s=!1,a=c;continue}if(!u(c+_)){s=!1,a=c+_;continue}if(!u(c-_)){s=!1,a=c-_;continue}r=u,o=c,i=_+1}return a},E1=t=>e=>n=>r=>o=>{const i=Te(e)(n),s=Ce(e)(n);if(!$i(i)(s)(r)(t))return r;if(!$i(i)(s)(o)(t))return o;const a=(r+o)/2;return $i(i)(s)(a)(t)?L1(u=>$i(i)(s)(u)(t))(a)(1):a},OJ=t=>e=>n=>r=>o=>{const i=Te(e)(n),s=Ce(e)(n);if(!Ki(i)(s)(r)(t))return r;if(!Ki(i)(s)(o)(t))return o;const a=(r+o)/2;return Ki(i)(s)(a)(t)?L1(u=>Ki(i)(s)(u)(t))(a)(1):a},qJ=t=>e=>n=>r=>{const o=Te(e)(n),i=Ce(e)(n),s=ft(c=>r>=c.x&&r<c.x+c.w&&c.y+c.h>o&&c.y<i,t),a=v(c=>_=>Ce(c)(_.x+_.w+4))(r+4)(s),u=v(c=>_=>Te(c)(_.x-4))(r-4)(s);return(()=>{const c=a-r,_=u-r;return(c<0?-c:c)<=(_<0?-_:_)})()?a:u},HJ=t=>e=>n=>r=>{const o=Te(e)(n),i=Ce(e)(n),s=ft(c=>r>=c.y&&r<c.y+c.h&&c.x+c.w>o&&c.x<i,t),a=v(c=>_=>Ce(c)(_.y+_.h+4))(r+4)(s),u=v(c=>_=>Te(c)(_.y-4))(r-4)(s);return(()=>{const c=a-r,_=u-r;return(c<0?-c:c)<=(_<0?-_:_)})()?a:u},$J=t=>e=>n=>r=>o=>i=>s=>{const a=(()=>{if(r==="South")return b(o._1,o._2+4);if(r==="North")return b(o._1,o._2-4);if(r==="East")return b(o._1+4,o._2);if(r==="West")return b(o._1-4,o._2);g()})(),u=(()=>{if(i==="South")return b(s._1,s._2+4);if(i==="North")return b(s._1,s._2-4);if(i==="East")return b(s._1+4,s._2);if(i==="West")return b(s._1-4,s._2);g()})(),c=(C,S,E)=>!ia(e)(Te(S)(E))(Ce(S)(E))(C),_=(C,S,E)=>!ia(n)(Te(S)(E))(Ce(S)(E))(C),d=(C,S,E,B)=>t.tag==="Just"&&!Yi(n)(Te(C)(S))(Ce(C)(S))(t._1)?t._1:OJ(e)(C)(S)(E)(B),l=(C,S,E,B)=>{if(C===E){const Y=qJ(e)(S)(B)(C),R=zJ(e)(C)(S)(B),A=WJ(e)(C)(S)(B);return[{start:b(C,S),end:b(C,R),direction:me},{start:b(C,R),end:b(Y,R),direction:pe},{start:b(Y,R),end:b(Y,A),direction:me},{start:b(Y,A),end:b(E,A),direction:pe},{start:b(E,A),end:b(E,B),direction:me}]}const M=d(C,E,S,B);return[{start:b(C,S),end:b(C,M),direction:me},{start:b(C,M),end:b(E,M),direction:pe},{start:b(E,M),end:b(E,B),direction:me}]},f=(C,S,E,B)=>{if(S===B){const Y=HJ(e)(C)(E)(S),R=QJ(e)(S)(C)(E),A=MJ(e)(S)(C)(E);return[{start:b(C,S),end:b(R,S),direction:pe},{start:b(R,S),end:b(R,Y),direction:me},{start:b(R,Y),end:b(A,Y),direction:pe},{start:b(A,Y),end:b(A,B),direction:me},{start:b(A,B),end:b(E,B),direction:pe}]}const M=E1(e)(S)(B)(C)(E);return[{start:b(C,S),end:b(M,S),direction:pe},{start:b(M,S),end:b(M,B),direction:me},{start:b(M,B),end:b(E,B),direction:pe}]},h=(C,S,E)=>!Yi(e)(Te(S)(E))(Ce(S)(E))(C),p=(C,S,E)=>!Yi(n)(Te(S)(E))(Ce(S)(E))(C),m=(C,S,E,B)=>{if(p(S,C,E)&&_(E,S,B))return[{start:b(C,S),end:b(E,S),direction:pe},{start:b(E,S),end:b(E,B),direction:me}];const M=E1(e)(S)(B)(C)(E);return[{start:b(C,S),end:b(M,S),direction:pe},{start:b(M,S),end:b(M,B),direction:me},{start:b(M,B),end:b(E,B),direction:pe}]},w=(C,S,E,B)=>{if(_(C,S,B)&&p(B,C,E))return[{start:b(C,S),end:b(C,B),direction:me},{start:b(C,B),end:b(E,B),direction:pe}];const M=d(C,E,S,B);return[{start:b(C,S),end:b(C,M),direction:me},{start:b(C,M),end:b(E,M),direction:pe},{start:b(E,M),end:b(E,B),direction:me}]},x=(()=>{if(r==="South")return i==="North"?a._1===u._1&&c(a._1,a._2,u._2)?[{start:b(a._1,a._2),end:b(u._1,u._2),direction:me}]:l(a._1,a._2,u._1,u._2):i==="East"||i==="West"?w(a._1,a._2,u._1,u._2):l(a._1,a._2,u._1,u._2);if(r==="North")return i==="South"?a._1===u._1&&c(a._1,a._2,u._2)?[{start:b(a._1,a._2),end:b(u._1,u._2),direction:me}]:l(a._1,a._2,u._1,u._2):i==="East"||i==="West"?w(a._1,a._2,u._1,u._2):l(a._1,a._2,u._1,u._2);if(r==="East")return i==="West"?a._2===u._2&&h(a._2,a._1,u._1)?[{start:b(a._1,a._2),end:b(u._1,u._2),direction:pe}]:f(a._1,a._2,u._1,u._2):i==="North"||i==="South"?m(a._1,a._2,u._1,u._2):l(a._1,a._2,u._1,u._2);if(r==="West"){if(i==="East")return a._2===u._2&&h(a._2,a._1,u._1)?[{start:b(a._1,a._2),end:b(u._1,u._2),direction:pe}]:f(a._1,a._2,u._1,u._2);if(i==="North"||i==="South")return m(a._1,a._2,u._1,u._2)}return l(a._1,a._2,u._1,u._2)})(),y=(()=>{if(r==="South"||r==="North")return me;if(r==="East"||r==="West")return pe;g()})(),T={start:b(u._1,u._2),end:b(s._1,s._2),direction:(()=>{if(i==="South"||i==="North")return me;if(i==="East"||i==="West")return pe;g()})()};return a._1===u._1&&a._2===u._2?[{start:b(o._1,o._2),end:b(s._1,s._2),direction:y}]:BJ({start:b(o._1,o._2),end:b(a._1,a._2),direction:y})(x)(T)},VJ=q(t=>({x:t.position._1*sa-2,y:t.position._2*sa-2,w:t.size._1*sa+4,h:t.size._2*sa+4})),G1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ci=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},UJ=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),Lc=t=>e=>t.gapTop+1*nt(4)+nt(e)*2.5*nt(4),KJ=t=>e=>{const n=G1(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return N("Just",{slot1Y:Lc(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Lc(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return J;g()}if(n.tag==="Nothing")return J;g()},YJ=t=>e=>{const n=v(r=>o=>rt(P)(o.node)(o)(r))(I)(e);return hn(Ht(r=>o=>{const i=ci(o.node)(n);if(i.tag==="Nothing")return[];if(i.tag==="Just"){const s=i._1;return Ht(a=>u=>{const c=o.edges.length,_=nt(4),d=s.position._1*_,l=s.position._2*_,f=s.size._2*_,h=nt((2*c|0)+1|0),p=l+f*nt(c-a|0)/h,m=l+f*nt((c+1|0)+a|0)/h,w=d-_*2.5*nt(a+1|0),x=[{start:b(d,p),end:b(w,p),direction:pe},{start:b(w,p),end:b(w,m),direction:me},{start:b(w,m),end:b(d,m),direction:pe}];return{edge:u.id,segments:x,bends:Fe(y=>T=>y.end,x,Rt(1,3,x)),bendType:[],jumps:[],reversed:!1}})(o.edges)}g()})(q(r=>({node:r._1,edges:r._2}))(UJ(v(r=>o=>Qt(P)(le)(o.from.node)([o])(r))(I)(t)))))},XJ=t=>e=>{const n=v(i=>s=>rt(P)(s.node)(s)(i))(I)(e),r=i=>{const s=ci(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.position._1;g()},o=i=>{const s=ci(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.layer;g()};return Pt(i=>s=>{const a=it.compare(o(i.edge.from.node))(o(s.edge.from.node));if(a==="EQ"){const u=ot.compare(r(i.edge.from.node))(r(s.edge.from.node));return u==="EQ"?ot.compare(r(i.edge.to.node))(r(s.edge.to.node)):u}return a})(t)},sn=t=>{const e=nt(4);return{x:t.position._1*e-2,y:t.position._2*e-2,w:t.size._1*e+4,h:t.size._2*e+4}},jJ=t=>t.from.node===t.to.node,ZJ=t=>e=>n=>r=>{const o=FJ(n)($J(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:o,bends:Fe(i=>s=>i.end,o,Rt(1,o.length,o)),bendType:[],jumps:[],reversed:!1}},tN=t=>e=>n=>r=>{const o=[{start:b(r.fromPos._1,r.fromPos._2),end:b(r.fromPos._1,t.slot1Y),direction:me},{start:b(r.fromPos._1,t.slot1Y),end:b(t.splitX,t.slot1Y),direction:pe},{start:b(t.splitX,t.slot1Y),end:b(t.splitX,t.slot2Y),direction:me},{start:b(t.splitX,t.slot2Y),end:b(r.toPos._1,t.slot2Y),direction:pe},{start:b(r.toPos._1,t.slot2Y),end:b(r.toPos._1,r.toPos._2),direction:me}];return{edge:r.edge.id,segments:o,bends:Fe(i=>s=>i.end,o,Rt(1,5,o)),bendType:[],jumps:[],reversed:!1}},eN=t=>e=>n=>{const r=ci(t.edge.from.node)(n);if(r.tag==="Just"){const i=ci(t.edge.to.node)(n);return i.tag==="Just"?ft(s=>!(s.h===sn(r._1).h&&s.w===sn(r._1).w&&s.x===sn(r._1).x&&s.y===sn(r._1).y)&&!(s.h===sn(i._1).h&&s.w===sn(i._1).w&&s.x===sn(i._1).x&&s.y===sn(i._1).y),e):ft(s=>!(s.h===sn(r._1).h&&s.w===sn(r._1).w&&s.x===sn(r._1).x&&s.y===sn(r._1).y),e)}const o=ci(t.edge.to.node)(n);return o.tag==="Just"?ft(i=>!(i.h===sn(o._1).h&&i.w===sn(o._1).w&&i.x===sn(o._1).x&&i.y===sn(o._1).y),e):ft(i=>!0,e)},nN=t=>e=>{const n=G1(e.edge.id)(t);if(n.tag==="Just")return N("Just",Lc(n._1)(n._1.slot));if(n.tag==="Nothing")return J;g()},rN=t=>e=>n=>r=>o=>{const i=v(c=>_=>rt(P)(_.node)(_)(c))(I)(e),s=VJ(e),a=c1(ft(c=>c.from.node!==c.to.node,t))(e)(n)(r)(o),u=o1(a)(e);return[...YJ(ft(jJ,t))(e),...v(c=>_=>{const d=eN(_)(s)(i),l=[...d,...c.edgeObstacles],f=KJ(u)(_),h=(()=>{if(f.tag==="Just")return tN(f._1)(d)(l)(_);if(f.tag==="Nothing")return ZJ(nN(u)(_))(d)(l)(_);g()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...PJ(h.segments)]}})({results:[],edgeObstacles:[]})(XJ(a)(e)).results]},Yr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Xr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},oN=t=>e=>n=>{if(t.start._1!==e.start._1)return J;const r=Xr(Yr(t.start._2)(t.end._2))(Yr(e.start._2)(e.end._2)),o=Yr(Xr(t.start._2)(t.end._2))(Xr(e.start._2)(e.end._2));return r<o?N("Just",{position:b(t.start._1,(r+o)/2),crossingEdge:n}):J},iN=t=>e=>n=>{if(t.start._2!==e.start._2)return J;const r=Xr(Yr(t.start._1)(t.end._1))(Yr(e.start._1)(e.end._1)),o=Yr(Xr(t.start._1)(t.end._1))(Xr(e.start._1)(e.end._1));return r<o?N("Just",{position:b((r+o)/2,t.start._2),crossingEdge:n}):J},sN=t=>e=>n=>{if(t.direction==="H")return iN(t)(e)(n);if(t.direction==="V")return oN(t)(e)(n);g()},aN=t=>e=>n=>{const r=t+1|0,o=r<1?n:Rt(r,n.length,n);return Et(e.segments)(i=>Et(o)(s=>vt(a=>sN(i)(a)(s.edge))(ft(a=>a.direction==="H"?i.direction==="H":a.direction==="V"&&i.direction==="V",s.segments))))},uN=t=>e=>n=>e.start._1>Yr(t.start._1)(t.end._1)&&e.start._1<Xr(t.start._1)(t.end._1)&&t.start._2>Yr(e.start._2)(e.end._2)&&t.start._2<Xr(e.start._2)(e.end._2)?N("Just",{position:b(e.start._1,t.start._2),crossingEdge:n}):J,cN=t=>e=>Et(ft(n=>n.direction==="H",t.segments))(n=>Et(e)(r=>vt(o=>uN(n)(o)(r.edge))(ft(o=>o.direction==="V",r.segments)))),gN=t=>e=>n=>[...cN(e)(ft(r=>r.edge!==e.edge,n)),...aN(t)(e)(n)],P1=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},_N=v(t=>e=>rt(P)(e)()(t))(I),aa=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},fN=Uf(P),gr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},B1=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Ec=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},dN=ce(it)(Mt),lN=t=>e=>Qe(P.compare,Ie,t,e),D1=Ht(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),hN=t=>v(e=>n=>({base:(()=>{const r=o=>i=>{let s=o,a=i,u=!0,c;for(;u;){const _=s,d=a;if(d.tag==="Nil"){u=!1,c=_;continue}if(d.tag==="Cons"){s=P1(_)(d._1),a=d._2;continue}g()}return c};return(e.base+r(0)((()=>{const o=(i,s)=>{if(i.tag==="Leaf")return s;if(i.tag==="Node")return o(i._5,kt("Cons",i._4,o(i._6,s)));g()};return o(n,$)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=o=>{if(o.tag==="Leaf")return I;if(o.tag==="Node")return te("Node",o._1,o._2,o._3,o._4+e.base|0,r(o._5),r(o._6));g()};return r(n)})()]}))({base:0,result:[]})(t).result,pN=t=>e=>{const n=_N(t);return fN(t)(D1(ft(r=>aa(r.src)(n)&&aa(r.tgt)(n),e)))},mN=t=>e=>{const n=v(o=>i=>Qt(P)(le)(i.tgt)([i.src])(Qt(P)(le)(i.src)([i.tgt])(o)))(I)(e),r=o=>i=>s=>{let a=o,u=i,c=s,_=!0,d;for(;_;){const l=a,f=u,h=c,p=Ft(m=>J,m=>w=>N("Just",{head:m,tail:w}),l);if(p.tag==="Nothing"){_=!1,d={nodes:h};continue}if(p.tag==="Just"){if(aa(p._1.head)(f)){a=p._1.tail,u=f,c=h;continue}a=[...p._1.tail,...(()=>{const m=gr(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;g()})()],u=rt(P)(p._1.head)()(f),c=[...h,p._1.head];continue}g()}return d};return v(o=>i=>{if(aa(i)(o.visited))return o;const s=r([i])(o.visited)([]);return{...o,visited:v(a=>u=>rt(P)(u)()(a))(o.visited)(s.nodes),components:[...o.components,s.nodes]}})({visited:I,components:[]})(t).components},yN=t=>e=>n=>{const r=v(i=>s=>Qt(P)(xe)(s.tgt)(1)(i))(I)(e),o=v(i=>s=>Qt(P)(xe)(s.src)(1)(i))(I)(e);return v(i=>s=>{const a=gr(s)(r),u=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})();if((()=>{const x=gr(s)(o);return(()=>{if(x.tag==="Nothing")return u!==0;if(x.tag==="Just")return u!==x._1;g()})()||u===0})())return i;const c=gr(s)(i.layers),_=(()=>{if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1;g()})(),d=i.layers,l=v(x=>y=>y.tgt===s?{...x,mIn:B1(x.mIn)((()=>{const T=gr(s)(d),C=gr(y.src)(d);return(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})()-(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;g()})()|0})())}:y.src===s?{...x,mOut:B1(x.mOut)((()=>{const T=gr(y.tgt)(d),C=gr(s)(d);return(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})()-(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;g()})()|0})())}:x)({mIn:1e9,mOut:1e9})(e),f=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(f<0||h<0)return i;const p=(_-f|0)+1|0,m=(_+h|0)-1|0;if(m<p)return i;const w=v(x=>y=>{const T=Ec(y)(i.filling),C=(()=>{if(T.tag==="Nothing")return 0;if(T.tag==="Just")return T._1;g()})();return C<x.bestFill?{best:y,bestFill:C}:x})({best:_,bestFill:(()=>{const x=Ec(_)(i.filling);if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;g()})()})(Xt(p,m));return w.best===_?i:{layers:rt(P)(s)(w.best)(i.layers),filling:rt(it)(_)((()=>{const x=Ec(_)(i.filling);if(x.tag==="Nothing")return-1;if(x.tag==="Just")return x._1-1|0;g()})())(rt(it)(w.best)(w.bestFill+1|0)(i.filling))}})({layers:n,filling:dN(q(i=>b(i,v(s=>a=>(()=>{const u=gr(a)(n);return u.tag==="Nothing"?!1:u.tag==="Just"&&u._1===i})()?s+1|0:s)(0)(t)))(Xt(0,v(i=>s=>P1(i)((()=>{const a=gr(s)(n);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;g()})()))(0)(t))))})(t).layers},xN=t=>e=>yN(t)(D1(e))(v(lN)(I)(hN(q(n=>pN(n)(e))(mN(t)(e))))),wN=t=>t,fo=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ua=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},R1=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),JN=wN("NetworkSimplex"),NN=t=>e=>v(n=>r=>{const o=v(ua)(0)(vt(i=>fo(i)(n))(r));return v(i=>s=>rt(P)(s)(o)(i))(n)(r)})(e)(t),vN=t=>e=>({layers:q(n=>ft(r=>{const o=fo(r)(e);return o.tag==="Nothing"?!1:o.tag==="Just"&&o._1===n},t))(Xt(0,(n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=i;if(c.tag==="Nil"){s=!1,a=u;continue}if(c.tag==="Cons"){o=ua(u)(c._1),i=c._2;continue}g()}return a})(0)((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,kt("Cons",r._4,n(r._6,o)));g()};return n(e,$)})()))),nodeLayer:e}),TN=t=>e=>n=>{const r=v(o=>i=>rt(P)(i)(!0)(o))(I)(e);return v(o=>i=>rt(P)(i._1)(i._2)(o))(xN(e)(vt(o=>o.from.node===o.to.node||(()=>{const i=fo(o.from.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;g()})()||(()=>{const i=fo(o.to.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;g()})()?J:N("Just",{src:o.from.node,tgt:o.to.node}))(t)))(R1(n))},CN=t=>e=>n=>r=>{const o=a=>u=>{const c=fo(u)(a);if(c.tag==="Just")return a;if(c.tag==="Nothing"){const _=ft(l=>l!==u,(()=>{const l=fo(u)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;g()})()),d=v(o)(a)(_);return rt(P)(u)(1+v(ua)(0)(vt(l=>fo(l)(d))(_))|0)(d)}g()},i=v(o)(I)(n),s=(a=>u=>{let c=a,_=u,d=!0,l;for(;d;){const f=c,h=_;if(h.tag==="Nil"){d=!1,l=f;continue}if(h.tag==="Cons"){c=ua(f)(h._1),_=h._2;continue}g()}return l})(1)((()=>{const a=(u,c)=>{if(u.tag==="Leaf")return c;if(u.tag==="Node")return a(u._5,kt("Cons",u._4,a(u._6,c)));g()};return a(i,$)})());return v(a=>u=>rt(P)(u._1)(u._2)(a))((()=>{const a=u=>{if(u.tag==="Leaf")return I;if(u.tag==="Node")return te("Node",u._1,u._2,u._3,s-u._4|0,a(u._5),a(u._6));g()};return a(i)})())(R1(r))},bN=v(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return rt(P)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return rt(P)(e._1.node)(0)(t)}return t})(I),kN=v(t=>e=>Qt(P)(le)(e.to.node)([e.from.node])(t))(I),SN=v(t=>e=>Qt(P)(le)(e.from.node)([e.to.node])(t))(I),LN=t=>e=>n=>r=>{const o=SN(n),i=kN(n),s=bN(e);return vN(r)(NN(vt(a=>a.tag==="SameLayer"?N("Just",a._1.nodes):J)(e))((()=>{if(t==="LongestPath")return CN(o)(i)(r)(s);if(t==="NetworkSimplex")return TN(n)(r)(s);g()})()))},EN=ce(P)(Mt),GN=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},A1=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},I1=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Xi=ce(P)(Mt),PN=ce(P)(Mt),F1=(()=>{const t=q(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>se(t(e))})(),BN=t=>e=>n=>r=>{const o=EN(q(s=>b(s.edge,s))(r)),i=s=>0<s.nodes.length&&(()=>{const a=GN(s.edgeId)(n);return a.tag==="Just"&&s.nodes[0]!==a._1._1})();return q(s=>{if(s.nodes.length<=2){const _=A1(s.edgeId)(o);if(_.tag==="Just"){const d=i(s),l=Ui(Vi(d?F1(_._1.segments):_._1.segments));return{..._._1,edge:s.edgeId,segments:l,bends:Fe(f=>h=>f.end,l,Rt(1,l.length,l)),reversed:d}}if(_.tag==="Nothing")return{edge:s.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};g()}const a=Et(vt(_=>A1(_)(o))(Fe(_=>d=>s.edgeId+":"+_+"->"+d,s.nodes,Rt(1,s.nodes.length,s.nodes))))(_=>_.segments),u=i(s),c=Ui(Vi(u?F1(a):a));return{edge:s.edgeId,segments:c,bends:Fe(_=>d=>_.end,c,Rt(1,c.length,c)),bendType:[],jumps:[],reversed:u}})(t)},DN={layers:[],edges:[],chains:[]},RN={nodeGap:3,layerGap:2,iterations:8,layerer:JN,cycleBreaker:CJ,compactPostRouting:!0,compactionSpacings:kw},AN=t=>({pos:b(0,0),size:b(v(e=>n=>I1(e)(n.position._1+n.size._1))(0)(t),v(e=>n=>I1(e)(n.position._2+n.size._2))(0)(t))}),IN=t=>e=>n=>{const r=Xi(q(c=>b(c.id,c.ports))(e.nodes)),o=ft(c=>Re(3)(c.node)!=="$d:",n.placements),i=BN(n.withDummies.chains)(n.acyclic.reversedEdges)(PN(q(c=>b(c.id,b(c.from.node,c.to.node)))(e.edges)))(rN(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(_1(n.ordered)(ft(c=>c.from.node!==c.to.node,n.withDummies.edges))((()=>{const c=_=>{if(_.tag==="Leaf")return I;if(_.tag==="Node")return te("Node",_._1,_._2,_._3,b(_._4._1*4,_._4._2),c(_._5),c(_._6));g()};return c(Xi(q(_=>b(_.id,_.size))(e.nodes)))})()))),s=t.compactPostRouting?Ew()(t.compactionSpacings)({nodes:o,edges:e.edges,paths:i,ports:r}):{nodes:o,edges:i},a=q(c=>{const _=Ui(Vi(c.segments));return{...c,segments:_,bends:Fe(d=>l=>d.end,_,Rt(1,_.length,_))}})(s.edges),u=Ht(c=>_=>({..._,jumps:gN(c)(_)(a)}))(a);return{nodes:s.nodes,edges:u,boundingBox:AN(s.nodes),metrics:nx(s.nodes)(u)(0)}},FN=t=>e=>n=>{const r=Xi(q(i=>b(i.id,i.size))(e.nodes)),o={...n,placements:uJ({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)(Xi(q(i=>b(i.id,i.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(_1(n.ordered)(n.withDummies.edges)((()=>{const i=s=>{if(s.tag==="Leaf")return I;if(s.tag==="Node")return te("Node",s._1,s._2,s._3,b(s._4._1*4,s._4._2),i(s._5),i(s._6));g()};return i(r)})()))};return{pipeline:o,result:IN(t)(e)(o)}},QN=t=>e=>n=>FN(t)(e)({...n,ordered:JJ({iterations:t.iterations,constraints:e.constraints,modelOrder:Xi(Ht(r=>o=>b(o.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),zN=t=>e=>n=>QN(t)(e)({...n,withDummies:Gw(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),MN=t=>e=>{const n=q(o=>o.id)(e.nodes),r=GJ(t.cycleBreaker)(n)(e.constraints)(e.edges);return zN(t)(e)({acyclic:r,layered:LN(t.layerer)(e.constraints)(r.edges)(n),withDummies:DN,ordered:[],placements:[]})},Q1=t=>t,z1=Q1("RunText"),WN=Q1("RunCode"),M1=t=>e=>n=>e.length===0?n:St(n)({style:t,text:Or(e)}),ON=t=>({style:(()=>{if(t.style==="RunText")return WN;if(t.style==="RunCode")return z1;g()})(),buf:[],runs:M1(t.style)(t.buf)(t.runs)}),qN=t=>e=>0<e.length?{...t,buf:St(t.buf)(e[0])}:{...t,buf:St(t.buf)("\\")},HN=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=Ft(u=>J,u=>c=>N("Just",{head:u,tail:c}),r);if(a.tag==="Nothing"){o=!1,i=s;continue}if(a.tag==="Just"){if(a._1.head==="\\"){n=qN(s)(a._1.tail),r=Rt(1,a._1.tail.length,a._1.tail);continue}if(a._1.head==="`"){n=ON(s),r=a._1.tail;continue}n={...s,buf:St(s.buf)(a._1.head)},r=a._1.tail;continue}g()}return i},W1=t=>{const e=HN({style:z1,buf:[],runs:[]})(vr(t));return M1(e.style)(e.buf)(e.runs)};let Gc=null;function $N(){return Gc||(typeof document>"u"?null:(Gc=document.createElement("canvas").getContext("2d"),Gc))}const O1=new Map,VN=t=>e=>n=>r=>()=>{const o=`${n} ${e}px ${t}|${r}`,i=O1.get(o);if(i!==void 0)return i;const s=$N();if(!s)return r.length*e*.62;s.font=`${n} ${e}px ${t}`;const a=s.measureText(r).width;return O1.set(o,a),a},UN=oo.traverse(gu),KN=v(er)(0),lo=(()=>{const t=Qn(`\r
3
+ `)(" "),e=Qn(`
4
+ `)(" "),n=(()=>{const r=Qn("\r")(" "),o=(()=>{const i=Qn(" ")(" ");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),q1=t=>e=>{const n=UN(r=>{const o=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;g()})();return VN(o.family)(o.size)(o.weight)(lo(r.text))})(W1(lo(e)));return()=>{const r=n();return KN(r)}},H1={text:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:"500"},code:{family:"'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:"400"}},YN=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},gi=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},XN=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},jN=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ZN=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},$1=t=>Or(se(tr(e=>e===" ")(se(tr(e=>e===" ")(vr(t)).rest)).rest)),tv=t=>v(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?N("Just",n._1):e)(J)(Ht(Rn)(t)),Pc=t=>e=>{if(t<=0)return[e];if(or(e)<=t)return[e];const n=vr(e),r=t<1?[]:Rt(0,t,n),o=tv(r);if(o.tag==="Just"){const i=$1(A_(!(o._1>=0&&o._1<r.length)||r[o._1]===" "?o._1:o._1+1|0)(e)),s=$1($o(o._1+1|0)(e));return s===""?[i]:[i,...Pc(t)(s)]}if(o.tag==="Nothing"){const i=A_(t)(e),s=$o(t)(e);return s===""?[i]:[i,...Pc(t)(s)]}g()},ev={cellW:7,cellH:3,maxLineWidth:20},nv=t=>e=>{const n=q(i=>b((()=>{if(i.label.tag==="Just")return i.label._1;if(i.label.tag==="Nothing")return i.id;g()})(),i))(e.nodes),r=gi(1)(Jr((XN(t.maxLineWidth)(v(i=>s=>gi(i)(or(s._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),o=(r*t.cellW|0)-1|0;return{...e,nodes:q(i=>{if(!(i._2.size._1===1&&i._2.size._2===1))return i._2;const s=Et(Kr(`
5
+ `)(i._1))(Pc(o)),a=v(c=>_=>gi(c)(or(_)))(0)(s),u=i._2.shape==="Cylinder"?gi(1)(Jr((a+2|0)+t.cellW|0,t.cellW)):r;return{...i._2,size:b(nt(a>o?Jr((a+2|0)+t.cellW|0,t.cellW):u),nt(gi(1)(Jr(s.length+t.cellH|0,t.cellH))+(i._2.shape==="Cylinder"||i._2.shape==="Document"?1:0)|0))}})(n)}},rv=t=>e=>n=>({...n,nodes:q(r=>{const o=ZN(r.id)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just")return{...r,size:b(jN(r.size._1)(nt(gi(1)(fe(xs(r.shape==="Cylinder"?(o._1+0)/t:(o._1+32)/t))))),r.size._2)};g()})(n.nodes)}),ca=t=>t,ov=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},ho=ca("TopSide"),po=ca("BottomSide"),mo=ca("LeftSide"),yo=ca("RightSide"),iv=t=>{const e=ot.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ot.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},V1=t=>e=>n=>{const r=ov(t.h*.12)(t.w*.2),o=t.w/2;return(e<0?t.y+r:t.y+t.h-r)+e*r*$e(iv((()=>{const i=(n-(t.x+o))/o;return 1-i*i})()))},an=t=>e=>n=>r=>{let o=t,i=e,s=n,a=r,u=!0,c;for(;u;){const _=o,d=i,l=s,f=a;if(_==="Rectangle"){if(l==="TopSide"){u=!1,c=d.y;continue}if(l==="BottomSide"){u=!1,c=d.y+d.h;continue}if(l==="LeftSide"){u=!1,c=d.x;continue}if(l==="RightSide"){u=!1,c=d.x+d.w;continue}o=qr,i=d,s=l,a=f;continue}if(_==="Cylinder"){if(l==="TopSide"){u=!1,c=V1(d)(-1)(f);continue}if(l==="BottomSide"){u=!1,c=V1(d)(1)(f);continue}if(l==="LeftSide"){u=!1,c=d.x;continue}if(l==="RightSide"){u=!1,c=d.x+d.w;continue}}o=qr,i=d,s=l,a=f}return c},U1=t=>e=>{const n=e.y-t.y,r=n<0?-n:n,o=e.x-(t.x+t.w),i=o<0?-o:o,s=e.x-t.x,a=s<0?-s:s,u=e.y-(t.y+t.h),c=u<0?-u:u;return r<=c&&r<=a&&r<=i?ho:c<=a&&c<=i?po:a<=i?mo:yo},sv=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),Bc=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},ji=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Zi=ce(P)(Mt),av=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},uv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},cv=v(t=>e=>rt(P)(e)()(t))(I),gv=v(t=>e=>rt(P)(e)()(t))(I),ga=oo.traverse(gu),_a=ce(P)(Mt),_v=t=>e=>Qe(P.compare,Ie,t,e),fv=v(t=>e=>rt(P)(e)()(t))(I),dv=ce(P)(Mt),lv=t=>e=>Qe(P.compare,Ie,t,e),hv=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},K1=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},pv=t=>e=>({...e,edges:Zi(q(n=>b(n._1,(()=>{const r=Bc(n._1)(t);if(r.tag==="Nothing")return n._2;if(r.tag==="Just"){const o=ji(r._1._2)(e.nodes),i=ji(r._1._1)(e.nodes),s=(()=>{if(i.tag==="Nothing")return n._2;if(i.tag==="Just"){const a=Ft(u=>J,u=>c=>N("Just",{head:u,tail:c}),n._2);if(a.tag==="Nothing")return n._2;if(a.tag==="Just")return[(()=>{const u=Ft(l=>J,l=>f=>N("Just",{head:l,tail:f}),a._1.tail),c=u.tag==="Just"?N("Just",u._1.head):J,_={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},d=(()=>{if(c.tag==="Just"){if((c._1.x>a._1.head.x?c._1.x-a._1.head.x<.5:a._1.head.x-c._1.x<.5)&&a._1.head.x>=_.x-.5&&a._1.head.x<=_.x+_.w+.5)return c._1.y>=_.y+_.h?N("Just",po):c._1.y<=_.y?N("Just",ho):J;if((c._1.y>a._1.head.y?c._1.y-a._1.head.y<.5:a._1.head.y-c._1.y<.5)&&a._1.head.y>=_.y-.5&&a._1.head.y<=_.y+_.h+.5){if(c._1.x>=_.x+_.w)return N("Just",yo);if(c._1.x<=_.x)return N("Just",mo)}return J}if(c.tag==="Nothing")return J;g()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...a._1.head,y:an(i._1.shape)(_)(ho)(a._1.head.x)};if(d._1==="BottomSide")return{...a._1.head,y:an(i._1.shape)(_)(po)(a._1.head.x)};if(d._1==="LeftSide")return{...a._1.head,x:an(i._1.shape)(_)(mo)(a._1.head.y)};if(d._1==="RightSide")return{...a._1.head,x:an(i._1.shape)(_)(yo)(a._1.head.y)};g()}if(d.tag==="Nothing"){const l={x:i._1.x,y:i._1.y,w:i._1.w,h:i._1.h},f=U1(l)(a._1.head);if(f==="TopSide")return{...a._1.head,y:an(i._1.shape)(l)(ho)(a._1.head.x)};if(f==="BottomSide")return{...a._1.head,y:an(i._1.shape)(l)(po)(a._1.head.x)};if(f==="LeftSide")return{...a._1.head,x:an(i._1.shape)(l)(mo)(a._1.head.y)};if(f==="RightSide")return{...a._1.head,x:an(i._1.shape)(l)(yo)(a._1.head.y)}}g()})(),...a._1.tail]}g()})();if(o.tag==="Nothing")return s;if(o.tag==="Just"){const a=Nr(s);if(a.tag==="Nothing")return s;if(a.tag==="Just")return St(a._1.init)((()=>{const u=Nr(a._1.init),c=u.tag==="Just"?N("Just",u._1.last):J,_={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},d=(()=>{if(c.tag==="Just"){if((c._1.x>a._1.last.x?c._1.x-a._1.last.x<.5:a._1.last.x-c._1.x<.5)&&a._1.last.x>=_.x-.5&&a._1.last.x<=_.x+_.w+.5)return c._1.y>=_.y+_.h?N("Just",po):c._1.y<=_.y?N("Just",ho):J;if((c._1.y>a._1.last.y?c._1.y-a._1.last.y<.5:a._1.last.y-c._1.y<.5)&&a._1.last.y>=_.y-.5&&a._1.last.y<=_.y+_.h+.5){if(c._1.x>=_.x+_.w)return N("Just",yo);if(c._1.x<=_.x)return N("Just",mo)}return J}if(c.tag==="Nothing")return J;g()})();if(d.tag==="Just"){if(d._1==="TopSide")return{...a._1.last,y:an(o._1.shape)(_)(ho)(a._1.last.x)};if(d._1==="BottomSide")return{...a._1.last,y:an(o._1.shape)(_)(po)(a._1.last.x)};if(d._1==="LeftSide")return{...a._1.last,x:an(o._1.shape)(_)(mo)(a._1.last.y)};if(d._1==="RightSide")return{...a._1.last,x:an(o._1.shape)(_)(yo)(a._1.last.y)};g()}if(d.tag==="Nothing"){const l={x:o._1.x,y:o._1.y,w:o._1.w,h:o._1.h},f=U1(l)(a._1.last);if(f==="TopSide")return{...a._1.last,y:an(o._1.shape)(l)(ho)(a._1.last.x)};if(f==="BottomSide")return{...a._1.last,y:an(o._1.shape)(l)(po)(a._1.last.x)};if(f==="LeftSide")return{...a._1.last,x:an(o._1.shape)(l)(mo)(a._1.last.y)};if(f==="RightSide")return{...a._1.last,x:an(o._1.shape)(l)(yo)(a._1.last.y)}}g()})())}}g()})()))(sv(e.edges)))}),mv=t=>e=>n=>{const r=re(o=>o.id===n)(t.graph.edges);if(r.tag==="Just")return N("Just",r._1);if(r.tag==="Nothing")return Bc(n)(e);g()},yv=t=>e=>n=>r=>({x:r.position._1*t,y:r.position._2*t,w:r.size._1*t,h:r.size._2*t,label:(()=>{const o=ji(r.node)(e);if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return r.node;g()})(),shape:(()=>{const o=ji(r.node)(n);if(o.tag==="Nothing")return qr;if(o.tag==="Just")return o._1;g()})()}),xv=t=>({id:t,size:b(1,1),ports:[],label:N("Just",t),shape:qr}),wv=t=>e=>n=>r=>b(r.node,yv(t)(e)(n)(r)),Y1=t=>{const e=Kr(`
6
+ `)(t);return e.length===0?[""]:e},X1=t=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,kt("Cons",n._4,e(n._6,r)));g()};return Zt(de.foldr,e(t.interiors,$))},Jv=t=>Zi(vt(e=>N("Just",b(e.edge,{id:e.edge,from:{node:e.from,port:J},to:{node:e.to,port:J},label:J})))(Et(t.scenes)(e=>e.tag==="DataFlow"?vt(n=>n.kind.tag==="SendToken"?N("Just",n.kind._1):J)(e._1.events):[]))),j1=t=>{const e=c2(t),n=ft(o=>av(o.id)(e.nodes),t.graph.nodes),r=ft(o=>uv(o.id)(e.edges),t.graph.edges);return{nodes:[...n,...q(xv)(Zt(fn.foldr,$n(P.compare,e.nodes,cv(q(o=>o.id)(n)))))],edges:[...r,...vt(mv(t)(Jv(t)))(Zt(fn.foldr,$n(P.compare,e.edges,gv(q(o=>o.id)(r)))))],constraints:t.graph.constraints}},Nv=t=>{const e=ga(n=>{const r=q1(H1)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})());return()=>{const o=r();return b(n.id,o)}})(j1(t).nodes);return()=>{const n=e();return _a(n)}},Z1=t=>{const e=Nv(t);return()=>{const n=e(),r=ga(Z1)(X1(t))();return v(_v)(n)(r)}},vv=t=>e=>{const n=Ft(r=>J,r=>o=>N("Just",{head:r,tail:o}),e.segments);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{x:n._1.head.start._1*t,y:n._1.head.start._2*t},...q(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];g()},Tv=t=>e=>b(e.edge,vv(t)(e)),Cv=t=>e=>n=>r=>({nodes:_a(q(wv(nt(4)*t)(e)(n))(r.nodes)),edges:Zi(q(Tv(t))(r.edges)),chipExtras:I,edgeLabels:I}),bv=t=>e=>({...pv(Zi(q(n=>b(n.id,b(n.from.node,n.to.node)))(e.edges)))(Cv(8)(_a(q(n=>b(n.id,(()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;g()})()))(e.nodes)))(_a(q(n=>b(n.id,n.shape))(e.nodes)))(MN(RN)(e).result)),edgeLabels:Zi(vt(n=>n.label.tag==="Just"?N("Just",b(n.id,n.label._1)):J)(e.edges))}),kv=t=>v(e=>n=>{if(n.tag==="Structural")return e;if(n.tag==="DataFlow")return v(r=>o=>{if(o.kind.tag==="SendToken")return v(i=>s=>rt(P)(s)()(i))(r)(o.kind._1.labels);if(o.kind.tag==="FillNodeWithoutTransition")return v(i=>s=>rt(P)(s)()(i))(r)(o.kind._1.labels);g()})(e)(n._1.events);if(n.tag==="Hold"||n.tag==="EnterNode"||n.tag==="ExitNode"||n.tag==="StepScene")return e;g()})(I)(t.scenes),Sv=t=>{const e=ga(n=>{const r=q1(H1)(n);return()=>{const o=r();return b(n,{labelW:o,charCount:or(lo(n)),lineCount:1})}})(Zt(fn.foldr,fv(Et(Zt(fn.foldr,kv(t)))(Y1))));return()=>{const n=e();return dv(n)}},td=t=>{const e=Sv(t);return()=>{const n=e(),r=ga(td)(X1(t))();return v(lv)(n)(r)}},Lv=nt(4)*8,Ev=t=>Et(t.scenes)(e=>{if(e.tag==="Structural")return[];if(e.tag==="DataFlow")return e._1.events;if(e.tag==="Hold")return[];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];if(e.tag==="StepScene")return[];g()}),Gv=t=>e=>n=>{const r=o=>{const i=vt(s=>{const a=hv(s)(t);return a.tag==="Just"?N("Just",{w:a._1.labelW+28,h:nt(YN(1)(a._1.lineCount))*13.2+12}):J})(Et(o)(Y1));return i.length===0?J:N("Just",{w:v(K1)(0)(q(s=>s.w)(i)),h:v(K1)(0)(q(s=>s.h)(i))})};return v(o=>i=>{if(i.kind.tag==="SendToken"){const s=Bc(i.kind._1.edge)(n.edges),a=r(i.kind._1.labels);if(a.tag==="Just"&&s.tag==="Just"){const u=a._1;return Qt(P)(le)(i.kind._1.edge)(q(c=>({x:c.x+14+u.w,y:c.y-6-8-u.h}))(s._1))(o)}return o}if(i.kind.tag==="FillNodeWithoutTransition"){const s=ji(i.kind._1.node)(n.nodes),a=r(i.kind._1.labels);return a.tag==="Just"&&s.tag==="Just"?Qt(P)(le)("__fill__:"+i.kind._1.node)((()=>{const u=s._1.y-a._1.h-14,c=s._1.x+s._1.w/2,_=c-a._1.w/2,d=c+a._1.w/2,l=s._1.y-14;return[{x:_,y:u},{x:d,y:u},{x:_,y:l},{x:d,y:l}]})())(o):o}g()})(I)(Ev(e))},ed=t=>e=>n=>({layout:(()=>{const r=bv()(rv(Lv)(t)(nv(ev)(j1(n))));return{...r,chipExtras:Gv(e)(n)(r)}})(),interiors:(()=>{const r=ed(t)(e),o=i=>{if(i.tag==="Leaf")return I;if(i.tag==="Node")return te("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));g()};return o(n.interiors)})()}),nd=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Dc=t=>e=>n=>{const r=t<.05?t:.05,o=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return o((()=>{const u=nd(a._3)(n),c=(()=>{if(u.tag==="Just")return u._1;if(u.tag==="Nothing")return{x:a._4.x,y:a._4.y,vx:0,vy:0};g()})(),_=c.vx+(180*(a._4.x-c.x)-22*c.vx)*r,d=c.vy+(180*(a._4.y-c.y)-22*c.vy)*r;return rt(P)(a._3)({x:c.x+_*r,y:c.y+d*r,vx:_,vy:d})(o(s,a._5))})(),a._6);g()},i=o(I,e);return{springs:i,applied:(()=>{const s=(a,u)=>{if(u.tag==="Leaf")return a;if(u.tag==="Node")return s((()=>{const c=s(a,u._5),_=nd(u._3)(i);if(_.tag==="Just")return rt(P)(u._3)({...u._4,x:_._1.x,y:_._1.y})(c);if(_.tag==="Nothing")return rt(P)(u._3)(u._4)(c);g()})(),u._6);g()};return s(I,e)})()}},st=(t,e)=>({tag:"CatQueue",_1:t,_2:e}),Pv=t=>{let e=t,n=!0,r;for(;n;){const o=e;if(o._1.tag==="Nil"){if(o._2.tag==="Nil"){n=!1,r=J;continue}e=st((i=>s=>{let a=i,u=s,c=!0,_;for(;c;){const d=a,l=u;if(l.tag==="Nil"){c=!1,_=d;continue}if(l.tag==="Cons"){a=kt("Cons",l._1,d),u=l._2;continue}g()}return _})($)(o._2),$);continue}if(o._1.tag==="Cons"){n=!1,r=N("Just",b(o._1._1,st(o._1._2,o._2)));continue}g()}return r},at=(t,e,n)=>({tag:t,_1:e,_2:n}),_t=at("CatNil"),Bv=t=>e=>{if(t.tag==="CatNil")return e;if(e.tag==="CatNil")return t;if(t.tag==="CatCons")return at("CatCons",t._1,st(t._2._1,kt("Cons",e,t._2._2)));g()},Dv=t=>e=>n=>{const r=o=>i=>s=>{let a=o,u=i,c=s,_=!0,d;for(;_;){const l=a,f=u,h=c;if(h.tag==="Nil"){_=!1,d=f;continue}if(h.tag==="Cons"){a=l,u=l(f)(h._1),c=h._2;continue}g()}return d};return(o=>i=>{let s=o,a=i,u=!0,c;for(;u;){const _=s,d=a,l=Pv(_);if(l.tag==="Nothing"){u=!1,c=r(f=>h=>h(f))(e)(d);continue}if(l.tag==="Just"){s=l._1._2,a=kt("Cons",t(l._1._1),d);continue}g()}return c})(n)($)},Rv=t=>{if(t.tag==="CatNil")return J;if(t.tag==="CatCons")return N("Just",b(t._1,t._2._1.tag==="Nil"&&t._2._2.tag==="Nil"?_t:Dv(Bv)(_t)(t._2)));g()},tt=(t,e)=>({tag:"Free",_1:t,_2:e}),ut=(t,e,n)=>({tag:t,_1:e,_2:n}),rd=t=>{let e=t,n=!0,r;for(;n;){const o=e;if(o._1.tag==="Return"){const i=Rv(o._2);if(i.tag==="Nothing"){n=!1,r=ut("Return",o._1._1);continue}if(i.tag==="Just"){e=(()=>{const s=i._1._1(o._1._1);return tt(s._1,(()=>{if(s._2.tag==="CatNil")return i._1._2;if(i._1._2.tag==="CatNil")return s._2;if(s._2.tag==="CatCons")return at("CatCons",s._2._1,st(s._2._2._1,kt("Cons",i._1._2,s._2._2._2)));g()})())})();continue}g()}if(o._1.tag==="Bind"){n=!1,r=ut("Bind",o._1._1,i=>{const s=o._1._2(i);return tt(s._1,(()=>{if(s._2.tag==="CatNil")return o._2;if(o._2.tag==="CatNil")return s._2;if(s._2.tag==="CatCons")return at("CatCons",s._2._1,st(s._2._2._1,kt("Cons",o._2,s._2._2._2)));g()})())});continue}g()}return r},Av=t=>e=>{const n=e.Monad0(),r=n.Bind1().Apply0().Functor0();return o=>e.tailRecM(i=>{const s=rd(i);if(s.tag==="Return")return r.map(a0)(n.Applicative0().pure(s._1));if(s.tag==="Bind")return r.map(_u)(o(t.map(s._2)(s._1)));g()})},Iv=t=>e=>n=>{const r=rd(n);if(r.tag==="Return")return e(r._1);if(r.tag==="Bind")return t(r._1)(r._2);g()},Rc={Applicative0:()=>xo,Bind1:()=>od},Fv={map:t=>e=>od.bind(e)(n=>xo.pure(t(n)))},od={bind:t=>e=>tt(t._1,(()=>{if(t._2.tag==="CatNil")return at("CatCons",e,st($,$));if(t._2.tag==="CatCons")return at("CatCons",t._2._1,st(t._2._2._1,kt("Cons",at("CatCons",e,st($,$)),t._2._2._2)));g()})()),Apply0:()=>id},id={apply:t=>e=>{const n=r=>tt(e._1,(()=>{if(e._2.tag==="CatNil")return at("CatCons",o=>xo.pure(r(o)),st($,$));if(e._2.tag==="CatCons")return at("CatCons",e._2._1,st(e._2._2._1,kt("Cons",at("CatCons",o=>xo.pure(r(o)),st($,$)),e._2._2._2)));g()})());return tt(t._1,(()=>{if(t._2.tag==="CatNil")return at("CatCons",n,st($,$));if(t._2.tag==="CatCons")return at("CatCons",t._2._1,st(t._2._2._1,kt("Cons",at("CatCons",n,st($,$)),t._2._2._2)));g()})())},Functor0:()=>Fv},xo={pure:t=>tt(ut("Return",t),_t),Apply0:()=>id},Qv=()=>()=>()=>t=>e=>n=>Vp(n.type)(t)?Up(n.type)(t)(n.value):e(n),zv={map:t=>e=>({type:e.type,value:e.map(t)(e.value),map:e.map})},Mv=t=>M_("Data.Functor.Variant: pattern match failure ["+t.type+"]"),Wv=()=>()=>()=>t=>Qv()()()(t)(Mv);(function(){var t={},e="Pure",n="Throw",r="Catch",o="Sync",i="Async",s="Bind",a="Bracket",u="Fork",c="Sequential",_="Map",d="Apply",l="Alt",f="Cons",h="Resume",p="Release",m="Finalizer",w="Finalized",x="Forked";function y(G,Q,V,K){this.tag=G,this._1=Q,this._2=V,this._3=K}function T(G){var Q=function(V,K,U){return new y(G,V,K,U)};return Q.tag=G,Q}function C(G){return new y(e,void 0)}function S(G){try{G()}catch(Q){setTimeout(function(){throw Q},0)}}function E(G,Q,V){try{return Q(V())}catch(K){return G(K)}}function B(G,Q,V){try{return Q(V)()}catch(K){return V(G(K))(),C}}var M=(function(){var G=1024,Q=0,V=0,K=new Array(G),U=!1;function O(){var X;for(U=!0;Q!==0;)Q--,X=K[V],K[V]=void 0,V=(V+1)%G,X();U=!1}return{isDraining:function(){return U},enqueue:function(X){var et;Q===G&&(et=U,O(),U=et),K[(V+Q)%G]=X,Q++,U||O()}}})();function Y(G){var Q={},V=0,K=0;return{register:function(U){var O=V++;U.onComplete({rethrow:!0,handler:function(X){return function(){K--,delete Q[O]}}})(),Q[O]=U,K++},isEmpty:function(){return K===0},killAll:function(U,O){return function(){if(K===0)return O();var X=0,et={};function lt(pt){et[pt]=Q[pt].kill(U,function(Tt){return function(){delete et[pt],X--,G.isLeft(Tt)&&G.fromLeft(Tt)&&setTimeout(function(){throw G.fromLeft(Tt)},0),X===0&&O()}})()}for(var bt in Q)Q.hasOwnProperty(bt)&&(X++,lt(bt));return Q={},V=0,K=0,function(pt){return new y(o,function(){for(var Tt in et)et.hasOwnProperty(Tt)&&et[Tt]()})}}}}}var R=0,A=1,j=2,Z=3,z=4,W=5,H=6;function D(G,Q,V){var K=0,U=R,O=V,X=null,et=null,lt=null,bt=null,pt=null,Tt=0,Gt=0,jt=null,Ct=!0;function Yt(ct){for(var yt,dt,ht;;)switch(yt=null,dt=null,ht=null,U){case j:U=A;try{O=lt(O),bt===null?lt=null:(lt=bt._1,bt=bt._2)}catch(Bt){U=W,X=G.left(Bt),O=null}break;case Z:G.isLeft(O)?(U=W,X=O,O=null):lt===null?U=W:(U=j,O=G.fromRight(O));break;case A:switch(O.tag){case s:lt&&(bt=new y(f,lt,bt)),lt=O._2,U=A,O=O._1;break;case e:lt===null?(U=W,O=G.right(O._1)):(U=j,O=O._1);break;case o:U=Z,O=E(G.left,G.right,O._1);break;case i:U=z,O=B(G.left,O._1,function(Bt){return function(){K===ct&&(K++,M.enqueue(function(){K===ct+1&&(U=Z,O=Bt,Yt(K))}))}});return;case n:U=W,X=G.left(O._1),O=null;break;case r:lt===null?pt=new y(f,O,pt,et):pt=new y(f,O,new y(f,new y(h,lt,bt),pt,et),et),lt=null,bt=null,U=A,O=O._1;break;case a:Tt++,lt===null?pt=new y(f,O,pt,et):pt=new y(f,O,new y(f,new y(h,lt,bt),pt,et),et),lt=null,bt=null,U=A,O=O._1;break;case u:U=Z,yt=D(G,Q,O._2),Q&&Q.register(yt),O._1&&yt.run(),O=G.right(yt);break;case c:U=A,O=L(G,Q,O._1);break}break;case W:if(lt=null,bt=null,pt===null)U=H,O=et||X||O;else switch(yt=pt._3,ht=pt._1,pt=pt._2,ht.tag){case r:et&&et!==yt&&Tt===0?U=W:X&&(U=A,O=ht._2(G.fromLeft(X)),X=null);break;case h:et&&et!==yt&&Tt===0||X?U=W:(lt=ht._1,bt=ht._2,U=j,O=G.fromRight(O));break;case a:Tt--,X===null&&(dt=G.fromRight(O),pt=new y(f,new y(p,ht._2,dt),pt,yt),(et===yt||Tt>0)&&(U=A,O=ht._3(dt)));break;case p:pt=new y(f,new y(w,O,X),pt,et),U=A,et&&et!==yt&&Tt===0?O=ht._1.killed(G.fromLeft(et))(ht._2):X?O=ht._1.failed(G.fromLeft(X))(ht._2):O=ht._1.completed(G.fromRight(O))(ht._2),X=null,Tt++;break;case m:Tt++,pt=new y(f,new y(w,O,X),pt,et),U=A,O=ht._1;break;case w:Tt--,U=W,O=ht._1,X=ht._2;break}break;case H:for(var Lt in jt)jt.hasOwnProperty(Lt)&&(Ct=Ct&&jt[Lt].rethrow,S(jt[Lt].handler(O)));jt=null,et&&X?setTimeout(function(){throw G.fromLeft(X)},0):G.isLeft(O)&&Ct&&setTimeout(function(){if(Ct)throw G.fromLeft(O)},0);return;case R:U=A;break;case z:return}}function Dt(ct){return function(){if(U===H)return Ct=Ct&&ct.rethrow,ct.handler(O)(),function(){};var yt=Gt++;return jt=jt||{},jt[yt]=ct,function(){jt!==null&&delete jt[yt]}}}function wt(ct,yt){return function(){if(U===H)return yt(G.right(void 0))(),function(){};var dt=Dt({rethrow:!1,handler:function(){return yt(G.right(void 0))}})();switch(U){case R:et=G.left(ct),U=H,O=et,Yt(K);break;case z:et===null&&(et=G.left(ct)),Tt===0&&(U===z&&(pt=new y(f,new y(m,O(ct)),pt,et)),U=W,O=null,X=null,Yt(++K));break;default:et===null&&(et=G.left(ct)),Tt===0&&(U=W,O=null,X=null)}return dt}}function mt(ct){return function(){var yt=Dt({rethrow:!1,handler:ct})();return U===R&&Yt(K),yt}}return{kill:wt,join:mt,onComplete:Dt,isSuspended:function(){return U===R},run:function(){U===R&&(M.isDraining()?Yt(K):M.enqueue(function(){Yt(K)}))}}}function F(G,Q,V,K){var U=0,O={},X=0,et={},lt=new Error("[ParAff] Early exit"),bt=null,pt=t;function Tt(Dt,wt,mt){var ct=wt,yt=null,dt=null,ht=0,Lt={},Bt,zt;t:for(;;)switch(Bt=null,ct.tag){case x:if(ct._3===t&&(Bt=O[ct._1],Lt[ht++]=Bt.kill(Dt,function(ne){return function(){ht--,ht===0&&mt(ne)()}})),yt===null)break t;ct=yt._2,dt===null?yt=null:(yt=dt._1,dt=dt._2);break;case _:ct=ct._2;break;case d:case l:yt&&(dt=new y(f,yt,dt)),yt=ct,ct=ct._1;break}if(ht===0)mt(G.right(void 0))();else for(zt=0,Bt=ht;zt<Bt;zt++)Lt[zt]=Lt[zt]();return Lt}function Gt(Dt,wt,mt){var ct,yt,dt,ht,Lt,Bt;for(G.isLeft(Dt)?(ct=Dt,yt=null):(yt=Dt,ct=null);;){if(dt=null,ht=null,Lt=null,Bt=null,bt!==null)return;if(wt===null){K(ct||yt)();return}if(wt._3!==t)return;switch(wt.tag){case _:ct===null?(wt._3=G.right(wt._1(G.fromRight(yt))),yt=wt._3):wt._3=ct;break;case d:if(dt=wt._1._3,ht=wt._2._3,ct){if(wt._3=ct,Lt=!0,Bt=X++,et[Bt]=Tt(lt,ct===dt?wt._2:wt._1,function(){return function(){delete et[Bt],Lt?Lt=!1:mt===null?Gt(ct,null,null):Gt(ct,mt._1,mt._2)}}),Lt){Lt=!1;return}}else{if(dt===t||ht===t)return;yt=G.right(G.fromRight(dt)(G.fromRight(ht))),wt._3=yt}break;case l:if(dt=wt._1._3,ht=wt._2._3,dt===t&&G.isLeft(ht)||ht===t&&G.isLeft(dt))return;if(dt!==t&&G.isLeft(dt)&&ht!==t&&G.isLeft(ht))ct=yt===dt?ht:dt,yt=null,wt._3=ct;else if(wt._3=yt,Lt=!0,Bt=X++,et[Bt]=Tt(lt,yt===dt?wt._2:wt._1,function(){return function(){delete et[Bt],Lt?Lt=!1:mt===null?Gt(yt,null,null):Gt(yt,mt._1,mt._2)}}),Lt){Lt=!1;return}break}mt===null?wt=null:(wt=mt._1,mt=mt._2)}}function jt(Dt){return function(wt){return function(){delete O[Dt._1],Dt._3=wt,Gt(wt,Dt._2._1,Dt._2._2)}}}function Ct(){var Dt=A,wt=V,mt=null,ct=null,yt,dt;t:for(;;)switch(yt=null,dt=null,Dt){case A:switch(wt.tag){case _:mt&&(ct=new y(f,mt,ct)),mt=new y(_,wt._1,t,t),wt=wt._2;break;case d:mt&&(ct=new y(f,mt,ct)),mt=new y(d,t,wt._2,t),wt=wt._1;break;case l:mt&&(ct=new y(f,mt,ct)),mt=new y(l,t,wt._2,t),wt=wt._1;break;default:dt=U++,Dt=W,yt=wt,wt=new y(x,dt,new y(f,mt,ct),t),yt=D(G,Q,yt),yt.onComplete({rethrow:!1,handler:jt(wt)})(),O[dt]=yt,Q&&Q.register(yt)}break;case W:if(mt===null)break t;mt._1===t?(mt._1=wt,Dt=A,wt=mt._2,mt._2=t):(mt._2=wt,wt=mt,ct===null?mt=null:(mt=ct._1,ct=ct._2))}for(pt=wt,dt=0;dt<U;dt++)O[dt].run()}function Yt(Dt,wt){bt=G.left(Dt);var mt;for(var ct in et)if(et.hasOwnProperty(ct)){mt=et[ct];for(ct in mt)mt.hasOwnProperty(ct)&&mt[ct]()}et=null;var yt=Tt(Dt,pt,wt);return function(dt){return new y(i,function(ht){return function(){for(var Lt in yt)yt.hasOwnProperty(Lt)&&yt[Lt]();return C}})}}return Ct(),function(Dt){return new y(i,function(wt){return function(){return Yt(Dt,wt)}})}}function L(G,Q,V){return new y(i,function(K){return function(){return F(G,Q,V,K)}})}return y.EMPTY=t,y.Pure=T(e),y.Throw=T(n),y.Catch=T(r),y.Sync=T(o),y.Async=T(i),y.Bind=T(s),y.Bracket=T(a),y.Fork=T(u),y.Seq=T(c),y.ParMap=T(_),y.ParApply=T(d),y.ParAlt=T(l),y.Fiber=D,y.Supervisor=Y,y.Scheduler=M,y.nonCanceler=C,y})();const Ov=t=>e=>Iv(n=>r=>t({type:n.type,value:n.map(o=>r(o))(n.value),map:n.map}))(e),qv=t=>{const e=t.Bind1(),n=t.Applicative0().pure;return r=>{const o=Hp(()=>Ov(i=>e.bind(r(i))(o()))(n));return o()}};let sd=null;function Hv(){return sd||(typeof document>"u"?null:sd=document.createElement("canvas").getContext("2d"))}const Ac=new Map;function ad(t,e,n,r,o,i){const s=`${n} ${e}px ${t}`,a=s+"|"+r;if(Ac.has(a))return Ac.get(a);const u=Hv();if(!u)return i;u.font=s;const c=o(u.measureText(r)),_=typeof document<"u"?document.fonts:null;if(!_||_.check(s))Ac.set(a,c);else if(_&&_.load)try{_.load(s)}catch{}return c}const $v=(t,e,n,r)=>ad(t,e,n,r,o=>o.width,-1),Vv=(t,e,n,r)=>ad(t,e,n,r,o=>({ascent:o.actualBoundingBoxAscent,descent:o.actualBoundingBoxDescent}),{ascent:-1,descent:-1}),fa=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),ud=t=>t,cd={map:t=>e=>{if(e.tag==="MeasureText")return fa("MeasureText",e._1,e._2,n=>t(e._3(n)));if(e.tag==="MeasureInk")return fa("MeasureInk",e._1,e._2,n=>t(e._3(n)));g()}},Ic=t=>e=>{const n=$v(t.family,t.size,t.weight,lo(e));return n<0?nt(Yo(e).length)*t.size*.62:n},Fc=t=>e=>{const n=Vv(t.family,t.size,t.weight,lo(e));return n.ascent<0?{ascent:t.size*.72,descent:t.size*.2}:n},Uv=t=>e=>tt(ut("Bind",{type:"metrics",value:fa("MeasureInk",t,e,ud),map:cd.map},n=>tt(ut("Return",n),_t)),_t),ts=t=>e=>tt(ut("Bind",{type:"metrics",value:fa("MeasureText",t,e,ud),map:cd.map},n=>tt(ut("Return",n),_t)),_t),gd=t=>t,_d=t=>t,da=t=>t,fd=t=>t,dd=t=>t,$t=(t,e,n,r,o)=>({tag:t,_1:e,_2:n,_3:r,_4:o}),ld=t=>t,Qc=t=>t,Kv=Qc("BaselineTop"),En=Qc("BaselineMiddle"),Yv=Qc("BaselineBottom"),_i=ld("AlignLeft"),Gr=ld("AlignCenter"),Ve=dd("RoundJoin"),es=dd("MiterJoin"),Gn=fd("ButtCap"),Vn=fd("RoundCap"),Xv=da("LayerPolyOut"),jv=da("LayerPolyIn"),Zv=da("LayerNodeMask"),tT=da("LayerOverlay"),ns=_d("NonZero"),eT=_d("EvenOdd"),hd=gd("Normal"),la=gd("Difference"),ye={r:255,g:255,b:255,a:255},rs=[5],we={map:t=>e=>{if(e.tag==="FillPath")return $t("FillPath",e._1,e._2,t(e._3));if(e.tag==="StrokePath")return $t("StrokePath",e._1,e._2,t(e._3));if(e.tag==="FillStrokePath")return $t("FillStrokePath",e._1,e._2,e._3,t(e._4));if(e.tag==="DrawText")return $t("DrawText",e._1,t(e._2));if(e.tag==="DrawTextAffine")return $t("DrawTextAffine",e._1,e._2,t(e._3));if(e.tag==="PushTransform")return $t("PushTransform",e._1,t(e._2));if(e.tag==="PopTransform")return $t("PopTransform",t(e._1));if(e.tag==="PushClip")return $t("PushClip",e._1,e._2,t(e._3));if(e.tag==="PopClip")return $t("PopClip",t(e._1));if(e.tag==="PushBlend")return $t("PushBlend",e._1,t(e._2));if(e.tag==="PopBlend")return $t("PopBlend",t(e._1));if(e.tag==="PushAlpha")return $t("PushAlpha",e._1,t(e._2));if(e.tag==="PopAlpha")return $t("PopAlpha",t(e._1));if(e.tag==="PushBlur")return $t("PushBlur",e._1,t(e._2));if(e.tag==="PopBlur")return $t("PopBlur",t(e._1));if(e.tag==="PushLayer")return $t("PushLayer",e._1,t(e._2));if(e.tag==="PopLayer")return $t("PopLayer",t(e._1));if(e.tag==="SetViewport")return $t("SetViewport",e._1,t(e._2));if(e.tag==="ClearBackground")return $t("ClearBackground",e._1,t(e._2));if(e.tag==="BackgroundDots")return $t("BackgroundDots",e._1,t(e._2));g()}},Pr={r:26,g:26,b:26,a:255},zc=t=>e=>Math.imul(t,e),fi=t=>{const e=t+1831565813|0,n=zc(e^e>>>15)(e|1),r=n^(n+zc(n^n>>>7)(n|61)|0),o=r^r>>>14;return{prng:o,value:o<0?(nt(o)+4294967296)/4294967296:nt(o)/4294967296}},Ee=t=>e=>n=>{const r=fi(n);return{prng:r.prng,value:t+r.value*(e-t)}},Mc=t=>e=>v(n=>r=>zc(n^r)(-2048144789))(e)(q(Ur)(vr(t))),nT=t=>t,pd=t=>t,rT=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Jn=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},md=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Wc=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},oT=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},iT=pd("FlatLevel"),sT=pd("NestedLevel"),Oc=nT("GenieSilhouette"),aT=t=>e=>n=>r=>{if(e)return{prng:t,yLift:0};const o=fi(t);return{prng:o.prng,yLift:o.value*n.yJitter*r}},uT=t=>e=>n=>r=>{if(e)return{prng:t,dx:0};const o=fi(t);return{prng:o.prng,dx:(o.value*2-1)*n.xJitter*r}},yd=t=>e=>{const n=e.cy-t.cy,r=e.cx-t.cx,o=$e(r*r+n*n),i=(t.r*t.r-e.r*e.r+o*o)/(2*o),s=$e(rT(0)(t.r*t.r-i*i)),a=t.cx+i*r/o,u=t.cy+i*n/o,c={x:a-s*n/o,y:u+s*r/o},_={x:a+s*n/o,y:u-s*r/o};return o===0||o>t.r+e.r?{x:(t.cx+e.cx)/2,y:t.cy}:c.y<_.y?c:_},di=t=>e=>{const n=Jn(e)(Jn(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},cT=t=>e=>n=>r=>o=>i=>{if(e)return{prng:t,r:o};if(n)return{prng:t,r:o*(1+i.rJitter)};if(r)return{prng:t,r:o*i.smallScale};const s=fi(t);return{prng:s.prng,r:o*(1+s.value*i.rJitter)}},xd=t=>{const e=Jn(t.w)(t.h)/2;return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,4,t.x+t.w-e+.5522847498307936*e,t.y,t.x+t.w,t.y+e-.5522847498307936*e,t.x+t.w,t.y+e,4,t.x+t.w,t.y+e+.5522847498307936*e,t.x+t.w-e+.5522847498307936*e,t.y+t.h,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,4,t.x+e-.5522847498307936*e,t.y+t.h,t.x,t.y+e+.5522847498307936*e,t.x,t.y+e,4,t.x,t.y+e-.5522847498307936*e,t.x+e-.5522847498307936*e,t.y,t.x+e,t.y,5]},gT=t=>e=>n=>{const r=fi(t),o=e.length;return o===0?{prng:t,idx:-1}:{prng:r.prng,idx:(()=>{const i=md(0)(o-1|0)(fe(An(r.value*nt(n))));return i>=0&&i<e.length?e[i]:-1})()}},_T=t=>e=>{const n=fi(t),r=e.length;return r===0?{prng:t,idx:-1}:{prng:n.prng,idx:(()=>{const o=md(0)(r-1|0)(fe(An(n.value*nt(r))));return o>=0&&o<e.length?e[o]:-1})()}},wd=t=>{const e=Jn(t.w*.18)(t.h*.6);return[1,t.x+e,t.y,2,t.x+t.w,t.y,2,t.x+t.w-e,t.y+t.h,2,t.x,t.y+t.h,5]},Jd=t=>[1,t.x,t.y,2,t.x+t.w,t.y,2,t.x+t.w,t.y+t.h*.85,4,t.x+t.w*.66,t.y+t.h*1.05,t.x+t.w*.34,t.y+t.h*.65,t.x,t.y+t.h*.85,5],Nd={rBase:1.2,stepRatio:.7,rJitter:.35,yJitter:.2,xJitter:.2,heroShift:.2,smallScale:.85,smallShift:.15,seed:7,minN:3},fT=t=>{const e=Jn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,o=t.x+n;return[1,t.x,r,4,t.x,r+.5522847498*e,o-.5522847498*n,r+e,o,r+e,4,o+.5522847498*n,r+e,t.x+t.w,r+.5522847498*e,t.x+t.w,r]},vd=t=>{const e=Jn(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+t.h+5,o=t.y+e,i=r-e,s=t.x+n;return[1,t.x,o,4,t.x,o-.5522847498*e,s-.5522847498*n,t.y,s,t.y,4,s+.5522847498*n,t.y,t.x+t.w,o-.5522847498*e,t.x+t.w,o,2,t.x+t.w,i,4,t.x+t.w,i+.5522847498*e,s+.5522847498*n,r,s,r,4,s-.5522847498*n,r,t.x,i+.5522847498*e,t.x,i,5]},Td=t=>e=>{const n=e.y+e.h,r=z0(t.rBase*e.h)(e.w/(2*(1+(nt(t.minN)-1)*t.stepRatio))),o=e.w-2*r,i=2*r*t.stepRatio,s=Wc(t.minN)(o<=0||i<=0?t.minN:fe(Hn(o/i))+1|0),a=s>=3?Xt(1,s-2|0):[],u=a.length,c=Jr(u+1|0,2),_=c<1?[]:Rt(0,c,a),d=_T(t.seed)((()=>{const m=u-c|0;return m<1?a:Rt(m,a.length,a)})()),l=d.idx,f=gT(d.prng)(ft(m=>m!==l,_))(Wc(1)(_.length-(en(zr)(l)(_)?1:0)|0)),h=f.idx,p=s>=2?o/(nt(s)-1):0;return v(m=>w=>{const x=w===h,y=w===l,T=w===0||w===(s-1|0),C=cT(m.prng)(T)(y)(x)(r)(t),S=aT(C.prng)(T)(t)(e.h),E=uT(S.prng)(T)(t)(p);return{prng:E.prng,circles:St(m.circles)({cx:e.x+oT(C.r)(e.w-C.r)((s>=2?r+nt(w)/(nt(s)-1)*o+E.dx:r+0*o+E.dx)+(y?t.heroShift*p:x?-1*t.smallShift*p:0)),cy:n-S.yLift,r:C.r})}})({prng:f.prng,circles:[]})(Xt(0,s-1|0)).circles},Cd=t=>e=>{const n=t.length;return Ht(r=>o=>({c:o,p1:(()=>{if(r===0)return{x:o.cx-o.r,y:e};const i=r-1|0;return i>=0&&i<t.length?yd(t[i])(o):{x:o.cx-o.r,y:e}})(),p2:(()=>{if(r===(n-1|0))return{x:o.cx+o.r,y:e};const i=r+1|0;return i>=0&&i<t.length?yd(o)(t[i]):{x:o.cx+o.r,y:e}})()}))(t)},bd=t=>{const e=Jn(t.h*.4)(t.w*.2);return[1,t.x+e,t.y,2,t.x+t.w-e,t.y,2,t.x+t.w,t.y+t.h/2,2,t.x+t.w-e,t.y+t.h,2,t.x+e,t.y+t.h,2,t.x,t.y+t.h/2,5]},dT=t=>e=>n=>{const r=so(e.y-t.cy)(e.x-t.cx),o=so(n.y-t.cy)(n.x-t.cx),i=o>r?o-r:o+6.283185307179586-r,s=Wc(1)(fe(xs(i/1.5707963267948966))),a=i/nt(s),u=1.3333333333333333*M0(a/4);return Et(Xt(0,s-1|0))(c=>{const _=r+nt(c+1|0)*a,d=t.cx+t.r*Sn(_),l=t.cy+t.r*pn(_),f=r+nt(c)*a;return[4,t.cx+t.r*Sn(f)-u*t.r*pn(f),t.cy+t.r*pn(f)+u*t.r*Sn(f),d+u*t.r*pn(_),l-u*t.r*Sn(_),d,l]})},kd=t=>e=>{const n=t.h*.38,r=Cd(Td(Nd)({x:t.x,y:t.y-n,w:t.w,h:n}))(t.y),o=Jn(e)(Jn(t.w/2)(t.h/2));return 0<r.length?[1,r[0].p1.x,r[0].p1.y,...Et(r)(i=>dT(i.c)(i.p1)(i.p2)),2,t.x+t.w,t.y+t.h-o,3,t.x+t.w,t.y+t.h,t.x+t.w-o,t.y+t.h,2,t.x+o,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-o,2,r[0].p1.x,r[0].p1.y,5]:di(t)(e)},lT=t=>e=>n=>r=>o=>i=>{if(e==="Rectangle")return t.drawRoundedRect(n)(r)(o)(i);if(e==="Cylinder"){const s=vd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Parallelogram"){const s=wd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Diamond"){const s=bd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Ellipse"){const s=xd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Document"){const s=Jd(n);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}if(e==="Cloud"){const s=kd(n)(r);if(o.tag==="Just"){if(i.tag==="Just")return t.fillStrokePath(s)(o._1)(i._1);if(i.tag==="Nothing")return t.fillPath(s)(o._1);g()}if(o.tag==="Nothing"){if(i.tag==="Just")return t.strokePath(s)(i._1);if(i.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()}return t.drawRoundedRect(n)(r)(o)(i)},hT={fillPath:t=>e=>tt(ut("Bind",{type:"render",value:$t("FillPath",t,e,void 0),map:we.map},n=>tt(ut("Return",n),_t)),_t),strokePath:t=>e=>tt(ut("Bind",{type:"render",value:$t("StrokePath",t,e,void 0),map:we.map},n=>tt(ut("Return",n),_t)),_t),fillStrokePath:t=>e=>n=>tt(ut("Bind",{type:"render",value:$t("FillStrokePath",t,e,n,void 0),map:we.map},r=>tt(ut("Return",r),_t)),_t),drawRoundedRect:t=>e=>n=>r=>{if(n.tag==="Just"){if(r.tag==="Just")return tt(ut("Bind",{type:"render",value:$t("FillStrokePath",di(t)(e),n._1,r._1,void 0),map:we.map},o=>tt(ut("Return",o),_t)),_t);if(r.tag==="Nothing")return tt(ut("Bind",{type:"render",value:$t("FillPath",di(t)(e),n._1,void 0),map:we.map},o=>tt(ut("Return",o),_t)),_t);g()}if(n.tag==="Nothing"){if(r.tag==="Just")return tt(ut("Bind",{type:"render",value:$t("StrokePath",di(t)(e),r._1,void 0),map:we.map},o=>tt(ut("Return",o),_t)),_t);if(r.tag==="Nothing")return tt(ut("Return",void 0),_t)}g()},drawText:t=>tt(ut("Bind",{type:"render",value:$t("DrawText",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),drawTextAffine:t=>e=>tt(ut("Bind",{type:"render",value:$t("DrawTextAffine",t,e,void 0),map:we.map},n=>tt(ut("Return",n),_t)),_t),pushTransform:t=>tt(ut("Bind",{type:"render",value:$t("PushTransform",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),popTransform:tt(ut("Bind",{type:"render",value:$t("PopTransform",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),pushBakedTransform:t=>tt(ut("Bind",{type:"render",value:$t("PushTransform",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),popBakedTransform:tt(ut("Bind",{type:"render",value:$t("PopTransform",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),pushClip:t=>e=>tt(ut("Bind",{type:"render",value:$t("PushClip",t,e,void 0),map:we.map},n=>tt(ut("Return",n),_t)),_t),popClip:tt(ut("Bind",{type:"render",value:$t("PopClip",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),pushBlend:t=>tt(ut("Bind",{type:"render",value:$t("PushBlend",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),popBlend:tt(ut("Bind",{type:"render",value:$t("PopBlend",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),pushAlpha:t=>tt(ut("Bind",{type:"render",value:$t("PushAlpha",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),popAlpha:tt(ut("Bind",{type:"render",value:$t("PopAlpha",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),pushBlur:t=>tt(ut("Bind",{type:"render",value:$t("PushBlur",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),popBlur:tt(ut("Bind",{type:"render",value:$t("PopBlur",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),pushLayer:t=>tt(ut("Bind",{type:"render",value:$t("PushLayer",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),popLayer:tt(ut("Bind",{type:"render",value:$t("PopLayer",void 0),map:we.map},t=>tt(ut("Return",t),_t)),_t),setViewport:t=>tt(ut("Bind",{type:"render",value:$t("SetViewport",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),clearBackground:t=>tt(ut("Bind",{type:"render",value:$t("ClearBackground",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),backgroundDots:t=>tt(ut("Bind",{type:"render",value:$t("BackgroundDots",t,void 0),map:we.map},e=>tt(ut("Return",e),_t)),_t),measureText:t=>e=>ts(t)(e),measureInk:t=>e=>Uv(t)(e),insideTokenStyle:t=>tt(ut("Return",Oc),_t),Monad0:()=>Rc},pT=t=>()=>t.clip("evenodd"),mT=t=>e=>()=>{t.filter=`blur(${e}px)`},yT=t=>e=>()=>{const n=e>0?t.canvas.width/e:1;t.setTransform(n,0,0,n,0,0)},xT=t=>e=>n=>r=>o=>()=>{const i=e>0?t.canvas.width/e:1;t.setTransform(i*n,0,0,i*n,i*r,i*o)},wT=t=>e=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(e.tile,.001))),r=Math.max(2,Math.round(e.tile*n)),o=document.createElement("canvas");o.width=r,o.height=r;const i=o.getContext("2d");i.scale(n,n),i.fillStyle=e.bgCss,i.fillRect(0,0,e.tile,e.tile),i.fillStyle=e.dotCss,i.beginPath(),i.arc(e.tile/2,e.tile/2,e.dotR,0,2*Math.PI),i.fill();const s=t.createPattern(o,"repeat");s&&typeof s.setTransform=="function"&&s.setTransform(new DOMMatrix().translateSelf(e.ox,e.oy).scaleSelf(1/n,1/n)),t.save(),t.fillStyle=s,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},qc=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Hc=t=>e=>n=>{const r=e.stroke;return()=>{const o=r.value,i=sm(t)(n);if(o!==n)return i(),e.stroke.value=n}},JT=t=>e=>n=>{const r=e.font;return()=>{const o=r.value,i=hm(t)(n);if(o!==n)return i(),e.font.value=n}},os=t=>e=>n=>{const r=e.fill;return()=>{const o=r.value,i=im(t)(n);if(o!==n)return i(),e.fill.value=n}},ha=t=>e=>{const n=e.length,r=i=>{if(i>=n)return()=>{};const s=i>=0&&i<e.length?e[i]:0;if(s===1){const a=E_(t)((()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})()),u=r(i+3|0);return()=>(a(),u())}if(s===2){const a=Si(t)((()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})())((()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})()),u=r(i+3|0);return()=>(a(),u())}if(s===3){const a=Li(t)({cpx:(()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})(),cpy:(()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=i+3|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=i+4|0;return c>=0&&c<e.length?e[c]:0})()}),u=r(i+5|0);return()=>(a(),u())}if(s===4){const a=mm(t)({cp1x:(()=>{const c=i+1|0;return c>=0&&c<e.length?e[c]:0})(),cp1y:(()=>{const c=i+2|0;return c>=0&&c<e.length?e[c]:0})(),cp2x:(()=>{const c=i+3|0;return c>=0&&c<e.length?e[c]:0})(),cp2y:(()=>{const c=i+4|0;return c>=0&&c<e.length?e[c]:0})(),x:(()=>{const c=i+5|0;return c>=0&&c<e.length?e[c]:0})(),y:(()=>{const c=i+6|0;return c>=0&&c<e.length?e[c]:0})()}),u=r(i+7|0);return()=>(a(),u())}if(s===5){const a=G_(t),u=r(i+1|0);return()=>(a(),u())}return()=>{}},o=L_(t);return()=>(o(),r(0)())},NT=t=>e=>n=>r=>o=>i=>{const s=qc(i)(qc(r/2)(o/2)),a=E_(t)(e+s)(n);return()=>(a(),Si(t)(e+r-s)(n)(),Li(t)({cpx:e+r,cpy:n,x:e+r,y:n+s})(),Si(t)(e+r)(n+o-s)(),Li(t)({cpx:e+r,cpy:n+o,x:e+r-s,y:n+o})(),Si(t)(e+s)(n+o)(),Li(t)({cpx:e,cpy:n+o,x:e,y:n+o-s})(),Si(t)(e)(n+s)(),Li(t)({cpx:e,cpy:n,x:e+s,y:n})(),G_(t)())},vT=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),Sd=t=>e=>{const n=_m(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=vT();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0},groupAlpha:{value:1},alphaSaves:{value:[]}}}},TT={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},CT=t=>ie(t.weight)+" "+ro(t.size)+"px "+t.family,_r=t=>{const e=ro(nt(t.a)/255);return t.a>=255?"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")":"rgba("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+","+e+")"},bT=t=>e=>n=>r=>{const o=nr(t);return()=>(o(),yT(t)(e.width)(),os(t)(n)(_r(r))(),gm(t)({x:0,y:0,width:e.width,height:e.height})(),rr(t)(),n.font.value="",n.fill.value="",n.stroke.value="")},kT=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",wT(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:_r(n.bgColor),dotCss:_r(n.dotColor),tile:n.tile,dotR:n.dotRadius,ox:n.origin.x,oy:n.origin.y})())},ST=t=>e=>n=>r=>{const o=os(t)(e)(_r(r));return()=>(o(),ha(t)(n)(),vu(t)())},LT=t=>e=>n=>r=>o=>{const i=os(t)(e)(_r(r));return()=>(i(),Hc(t)(e)(_r(o.color))(),xu(t)(o.width)(),Bu(t)((()=>{if(o.lineJoin==="RoundJoin")return Su;if(o.lineJoin==="BevelJoin")return ku;if(o.lineJoin==="MiterJoin")return Lu;g()})())(),Du(t)((()=>{if(o.lineCap==="ButtCap")return Pu;if(o.lineCap==="RoundCap")return Eu;if(o.lineCap==="SquareCap")return Gu;g()})())(),ha(t)(n)(),vu(t)(),Nu(t)())},ET=t=>e=>n=>r=>o=>i=>{const s=L_(t);return()=>{if(s(),NT(t)(n.x)(n.y)(n.w)(n.h)(r)(),o.tag==="Just"?(os(t)(e)(_r(o._1.color))(),vu(t)()):o.tag==="Nothing"||g(),i.tag==="Just")return Hc(t)(e)(_r(i._1.color))(),xu(t)(i._1.width)(),Bu(t)((()=>{if(i._1.lineJoin==="RoundJoin")return Su;if(i._1.lineJoin==="BevelJoin")return ku;if(i._1.lineJoin==="MiterJoin")return Lu;g()})())(),Du(t)((()=>{if(i._1.lineCap==="ButtCap")return Pu;if(i._1.lineCap==="RoundCap")return Eu;if(i._1.lineCap==="SquareCap")return Gu;g()})())(),Nu(t)();i.tag!=="Nothing"&&g()}},GT=t=>e=>n=>r=>{const o=Hc(t)(e)(_r(r.color));return()=>(o(),xu(t)(r.width)(),Bu(t)((()=>{if(r.lineJoin==="RoundJoin")return Su;if(r.lineJoin==="BevelJoin")return ku;if(r.lineJoin==="MiterJoin")return Lu;g()})())(),Du(t)((()=>{if(r.lineCap==="ButtCap")return Pu;if(r.lineCap==="RoundCap")return Eu;if(r.lineCap==="SquareCap")return Gu;g()})())(),ha(t)(n)(),Nu(t)())},Ld=t=>e=>n=>{const r=os(t)(e)(_r(n.color));return()=>(r(),JT(t)(e)(CT(n.font))(),Sm(t)((()=>{if(n.align==="AlignLeft")return Nm;if(n.align==="AlignCenter")return Tm;if(n.align==="AlignRight")return vm;g()})())(),km(t)((()=>{if(n.baseline==="BaselineTop")return ym;if(n.baseline==="BaselineMiddle")return xm;if(n.baseline==="BaselineAlphabetic")return wm;if(n.baseline==="BaselineBottom")return Jm;g()})())(),pm(t)(n.content)(n.x)(n.y)())},Ed={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),s=o();return i(s)}},Functor0:()=>TT},PT={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>Ed},BT=t=>e=>n=>{const r=qc(e.width/n.vw)(e.height/n.vh);return xT(t)(e.width)(r)((e.width-n.vw*r)/2-n.vx*r)((e.height-n.vh*r)/2-n.vy*r)},DT={pure:t=>e=>()=>t,Apply0:()=>Ed},Gd={Applicative0:()=>DT,Bind1:()=>PT},$c={fillPath:t=>e=>n=>{const r=ST(n.ctx)(n.styleCache)(t)(e.color),o=n.maskDepth;return()=>{if(o.value===0)return r()}},strokePath:t=>e=>n=>{const r=GT(n.ctx)(n.styleCache)(t)(e),o=n.maskDepth;return()=>{if(o.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const o=LT(r.ctx)(r.styleCache)(t)(e.color)(n),i=r.maskDepth;return()=>{if(i.value===0)return o()}},drawRoundedRect:t=>e=>n=>r=>o=>{const i=ET(o.ctx)(o.styleCache)(t)(e)(n)(r),s=o.maskDepth;return()=>{if(s.value===0)return i()}},drawText:t=>e=>{const n=Ld(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},drawTextAffine:t=>e=>n=>{const r=nr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0)return r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",fm(n.ctx)(t)(),Ld(n.ctx)(n.styleCache)(e)(),rr(n.ctx)(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value=""}},pushTransform:t=>e=>{const n=nr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",P_(e.ctx)({translateX:t.tx,translateY:t.ty})(),vs(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=rr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBakedTransform:t=>e=>{const n=nr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",P_(e.ctx)({translateX:t.tx,translateY:t.ty})(),vs(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popBakedTransform:t=>{const e=rr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushClip:t=>e=>n=>{const r=nr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",ha(n.ctx)(t)(),e==="NonZero")return cm(n.ctx)();if(e==="EvenOdd")return pT(n.ctx)();g()}}},popClip:t=>{const e=rr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBlend:t=>e=>{const n=nr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){if(n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",t==="Normal")return D_(e.ctx)(Cm)();if(t==="Difference")return D_(e.ctx)(bm)();g()}}},popBlend:t=>{const e=rr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushAlpha:t=>e=>{const n=nr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="";const o=e.groupAlpha.value,i=e.alphaSaves.value;e.alphaSaves.value=[...i,o];const s=o*t;return e.groupAlpha.value=s,um(e.ctx)(s)()}}},popAlpha:t=>{const e=rr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0){e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="";const r=t.alphaSaves.value,o=Nr(r);if(o.tag==="Just")return t.alphaSaves.value=o._1.init,t.groupAlpha.value=o._1.last;if(o.tag==="Nothing")return t.groupAlpha.value=1;g()}}},pushBlur:t=>e=>{const n=nr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="";const o=mT(e.ctx)(t);if(t>=.01)return o()}}},popBlur:t=>{const e=rr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushLayer:t=>e=>{if(t==="LayerNodeMask"){const n=e.maskDepth;return()=>{const r=n.value;n.value=r+1|0}}return()=>{}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;if(n>0)return t.maskDepth.value=r}},setViewport:t=>e=>{const n=BT(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=bT(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=kT(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=Ic(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Fc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Oc,Monad0:()=>Gd},RT=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},li=t=>e=>n=>{const r=RT(.05)(1-t-e);return n<t?0:n>1-e?1:(n-t)/r},Vc=t=>{const e=ot.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;g()})(),r=ot.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;g()},AT=t=>{if(t.tag==="Retracted")return{lo:0,hi:0};if(t.tag==="Extended")return{lo:0,hi:1};if(t.tag==="Extending"){if(t._1==="ExtendFromSource")return{lo:0,hi:Vc(t._2)};if(t._1==="ExtendFromTarget")return{lo:1-t._2,hi:1};g()}if(t.tag==="Retracting"){if(t._1==="FromSource")return{lo:t._2,hi:1};if(t._1==="FromTarget")return{lo:0,hi:1-t._2};if(t._1==="FromBoth")return{lo:t._2/2,hi:1-t._2/2}}g()},hi=t=>{if(t.tag==="Hidden")return{alpha:0,scale:0};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:t._1>0?1:0,scale:Ri(8)(.6)(Vc(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:Ri(8)(.6)(Vc(1-t._1))};g()};function IT(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function FT(t){const e=t.length,n=new Array(e);for(let r=0;r<e;r++){const o=t[r],i=t[(r+1)%e];n[r]={a:o,b:i,len:IT(o,i)}}return n}function QT(t,e,n){let r=0;for(let o=0;o<t.length;o++){const i=t[o],s=r,a=s+i.len;if(n<=a){const u=i.len>1e-6?(n-s)/i.len:0;return{x:i.a.x+(i.b.x-i.a.x)*u,y:i.a.y+(i.b.y-i.a.y)*u}}r=a}return e.length>0?e[e.length-1]:{x:0,y:0}}function Pd(t,e){if(e.length===0)return[];const n=FT(e);let r=0;for(let i=0;i<n.length;i++)r+=n[i].len;const o=new Array(t);for(let i=0;i<t;i++)o[i]=QT(n,e,i*r/t);return o}function zT(t,e){const n=e.length;if(n===0)return e;const r=(t%n+n)%n|0,o=new Array(n);for(let i=0;i<n;i++)o[i]=e[(i+r)%n];return o}function MT(t,e){const n=e.length;if(n===0)return e;let r=0,o=1/0;for(let i=0;i<n;i++){let s=0;for(let a=0;a<n;a++){const u=t[a]||{x:0,y:0},c=e[(a+i)%n]||{x:0,y:0},_=u.x-c.x,d=u.y-c.y;s+=_*_+d*d}s<o&&(o=s,r=i)}return zT(r,e)}const Bd=t=>e=>n=>{const r=Pd(t,e),o=Pd(t,n),i=MT(r,o);return{from:r,to:i}};function Dd(t){const e=t.length;if(e===0)return{x:0,y:0};let n=0,r=0;for(let o=0;o<e;o++)n+=t[o].x,r+=t[o].y;return{x:n/e,y:r/e}}function WT(t,e){const n=e.x-t.x,r=e.y-t.y,o=Math.sqrt(n*n+r*r);return o<=1e-4?{x:1,y:0}:{x:n/o,y:r/o}}function OT(t,e){const n=e.length;if(n===0)return e;const r=new Array(n);for(let o=0;o<n;o++){const i=e[((o-1)%n+n)%n],s=e[((o+1)%n+n)%n],a=e[o];r[o]={x:a.x+((i.x+s.x)/2-a.x)*t,y:a.y+((i.y+s.y)/2-a.y)*t}}return r}function qT(t){return t<0?0:t>1?1:t}const Rd=t=>e=>n=>r=>{const o=e.length;if(o===0)return[];const i=Dd(e),s=Dd(n),a=WT(i,s),u=new Array(o);let c=1/0,_=-1/0;for(let f=0;f<o;f++){const h=e[f],p=(h.x-i.x)*a.x+(h.y-i.y)*a.y;u[f]=p,p<c&&(c=p),p>_&&(_=p)}const d=_-c;let l=new Array(o);for(let f=0;f<o;f++){const h=e[f],p=n[f];if(p===void 0){l[f]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(u[f]-c)/d),w=Math.max(1e-4,1-m),x=qT((t-m)/w),y=x*x*(3-2*x);l[f]={x:h.x+(p.x-h.x)*y,y:h.y+(p.y-h.y)*y}}for(let f=0;f<r.smoothPasses;f++)l=OT(.5,l);return l},Ad=(t,e)=>({tag:t,_1:e}),Id=(t,e)=>({tag:t,_1:e}),be=(t,e,n)=>({tag:t,_1:e,_2:n}),Fd=t=>t,Uc=(t,e)=>({tag:t,_1:e}),Kc=(t,e)=>({tag:t,_1:e}),Yc=t=>t,pa=(t,e)=>({tag:t,_1:e}),ke=(t,e,n)=>({tag:t,_1:e,_2:n}),wo=(t,e)=>({tag:t,_1:e}),is=(t,e)=>({tag:t,_1:e}),Qd=(t,e)=>({tag:t,_1:e}),zd=t=>t,Md=(t,e)=>({tag:t,_1:e}),Jo=(t,e,n)=>({tag:t,_1:e,_2:n}),Wd=t=>t,HT=t=>t,pi=Wd("NormalTransform"),$T=Wd("BakedTransform"),Od=zd("TokenOutside"),qd=zd("TokenInside"),ma=is("PlainText"),Hd=wo("FrameTitle"),VT=wo("Watermark"),UT=Yc("NodeShadow"),$d=Yc("NodeBody"),KT=Yc("NodeInversion"),Xc=Fd("LabelsShown"),jc=Fd("LabelsHidden"),On={map:t=>e=>{if(e.tag==="BeginFrame")return ke("BeginFrame",e._1,t(e._2));if(e.tag==="EndFrame")return ke("EndFrame",t(e._1));if(e.tag==="BeginGroup")return ke("BeginGroup",e._1,t(e._2));if(e.tag==="EndGroup")return ke("EndGroup",e._1,t(e._2));if(e.tag==="Background")return ke("Background",e._1,t(e._2));if(e.tag==="Overlay")return ke("Overlay",e._1,t(e._2));if(e.tag==="Node")return ke("Node",e._1,t(e._2));if(e.tag==="Edge")return ke("Edge",e._1,t(e._2));if(e.tag==="Text")return ke("Text",e._1,t(e._2));if(e.tag==="Token")return ke("Token",e._1,t(e._2));if(e.tag==="AskInsideTokenStyle")return ke("AskInsideTokenStyle",e._1,n=>t(e._2(n)));g()}},Vd=t=>e=>ts(t)(e),YT=t=>{const e=t.Bind1().Apply0().Functor0(),n=qv(t);return r=>o=>n(Wv()()()({scene:i=>{if(i.tag==="BeginFrame"){const s=i._2;return e.map(a=>s)(r.beginFrame(i._1))}if(i.tag==="EndFrame"){const s=i._1;return e.map(a=>s)(r.endFrame)}if(i.tag==="BeginGroup"){const s=i._2;return e.map(a=>s)(r.beginGroup(i._1))}if(i.tag==="EndGroup"){const s=i._2;return e.map(a=>s)(r.endGroup(i._1))}if(i.tag==="Background"){const s=i._2;return e.map(a=>s)(r.background(i._1))}if(i.tag==="Overlay"){const s=i._2;return e.map(a=>s)(r.overlay(i._1))}if(i.tag==="Node"){const s=i._2;return e.map(a=>s)(r.node(i._1))}if(i.tag==="Edge"){const s=i._2;return e.map(a=>s)(r.edge(i._1))}if(i.tag==="Text"){const s=i._2;return e.map(a=>s)(r.text(i._1))}if(i.tag==="Token"){const s=i._2;return e.map(a=>s)(r.token(i._1))}if(i.tag==="AskInsideTokenStyle")return e.map(i._2)(r.insideTokenStyle(i._1));g()},metrics:i=>{if(i.tag==="MeasureText")return e.map(i._3)(r.measureText(i._1)(i._2));if(i.tag==="MeasureInk")return e.map(i._3)(r.measureInk(i._1)(i._2));g()}}))(o)},XT=t=>tt(ut("Bind",{type:"scene",value:ke("AskInsideTokenStyle",t,HT),map:On.map},e=>tt(ut("Return",e),_t)),_t),Ud=t=>tt(ut("Bind",{type:"scene",value:ke("Background",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),Kd=t=>tt(ut("Bind",{type:"scene",value:ke("Edge",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),Zc=t=>tt(ut("Bind",{type:"scene",value:ke("Node",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),ya=t=>tt(ut("Bind",{type:"scene",value:ke("Overlay",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),ss=t=>tt(ut("Bind",{type:"scene",value:ke("Text",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),Yd=t=>tt(ut("Bind",{type:"scene",value:ke("Token",t,void 0),map:On.map},e=>tt(ut("Return",e),_t)),_t),jT=t=>e=>tt(ut("Bind",{type:"scene",value:ke("BeginFrame",t,void 0),map:On.map},n=>tt(ut("Return",n),_t)),at("CatCons",()=>tt(e._1,(()=>{if(e._2.tag==="CatNil")return at("CatCons",()=>tt(ut("Bind",{type:"scene",value:ke("EndFrame",void 0),map:On.map},n=>tt(ut("Return",n),_t)),_t),st($,$));if(e._2.tag==="CatCons")return at("CatCons",e._2._1,st(e._2._2._1,kt("Cons",at("CatCons",()=>tt(ut("Bind",{type:"scene",value:ke("EndFrame",void 0),map:On.map},n=>tt(ut("Return",n),_t)),_t),st($,$)),e._2._2._2)));g()})()),st($,$))),je=t=>e=>tt(ut("Bind",{type:"scene",value:ke("BeginGroup",t,void 0),map:On.map},n=>tt(ut("Return",n),_t)),at("CatCons",()=>{const n=()=>tt(ut("Bind",{type:"scene",value:ke("EndGroup",t,void 0),map:On.map},r=>tt(ut("Return",r),_t)),_t);return tt(e._1,(()=>{if(e._2.tag==="CatNil")return at("CatCons",n,st($,$));if(e._2.tag==="CatCons")return at("CatCons",e._2._1,st(e._2._2._1,kt("Cons",at("CatCons",n,st($,$)),e._2._2._2)));g()})())},st($,$))),fr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Xd=v(er)(0),jd=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},ZT=v(t=>e=>t+e.len)(0),Zd=t=>{const e=Ft(n=>J,n=>r=>N("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Et(Rt(1,t.length,t))(n=>[2,n.x,n.y]),5];g()},tl=t=>e=>{const n=fr(e)(fr(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},t3=t=>{const e=Ft(n=>J,n=>r=>N("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Et(e._1.tail)(n=>[2,n.x,n.y])];g()},tg=t=>{const e={x:t.x,y:t.y,w:t.w,h:t.h};if(t.shape==="Cylinder")return vd(e);if(t.shape==="Parallelogram")return wd(e);if(t.shape==="Diamond")return bd(e);if(t.shape==="Ellipse")return xd(e);if(t.shape==="Document")return Jd(e);if(t.shape==="Cloud")return kd(e)(7);if(t.shape==="Rectangle")return tl(e)(7);g()},Ge=t=>e=>n=>q(r=>{const o=nt(r)/nt(n);return{x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o}})(Xt(0,n-1|0)),e3=t=>{const e=Jn(t.w*.18)(t.h*.6);return[...Ge({x:t.x+e,y:t.y})({x:t.x+t.w,y:t.y})(16),...Ge({x:t.x+t.w,y:t.y})({x:t.x+t.w-e,y:t.y+t.h})(16),...Ge({x:t.x+t.w-e,y:t.y+t.h})({x:t.x,y:t.y+t.h})(16),...Ge({x:t.x,y:t.y+t.h})({x:t.x+e,y:t.y})(16)]},as=t=>e=>{const n=fr(t)(fr(e.w/2)(e.h/2));return{...e,x:e.x+n,y:e.y+n,w:e.w-2*n,h:e.h-2*n}},eg=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return $e(r*r+n*n)},n3=t=>Fe(e=>n=>({a:e,b:n,len:eg(e)(n)}),t,Rt(1,t.length,t)),r3=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?N("Just",e[n]):J,o=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];g()})(),i=0<e.length?N("Just",e[0]):J,s=(()=>{if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return{x:0,y:0};g()})(),a=e.length;return a<3?e:[s,...Et(Xt(1,a-2|0))(u=>{const c=u+1|0,_=c>=0&&c<e.length?N("Just",e[c]):J,d=u>=0&&u<e.length?N("Just",e[u]):J,l=u-1|0,f=l>=0&&l<e.length?N("Just",e[l]):J;if(f.tag==="Just"&&d.tag==="Just"&&_.tag==="Just"){const h=d._1,p=eg(h)(_._1),m=eg(f._1)(h),w=fr(t)(p/2),x=fr(t)(m/2),y=p>0?w/p:0,T=h.x+(_._1.x-h.x)*y,C=h.y+(_._1.y-h.y)*y,S=m>0?x/m:0,E=h.x+(f._1.x-h.x)*S,B=h.y+(f._1.y-h.y)*S;return q(M=>{const Y=nt(M)/nt(10),R=1-Y;return{x:R*R*E+2*R*Y*h.x+Y*Y*T,y:R*R*B+2*R*Y*h.y+Y*Y*C}})(Xt(0,10))}return[]}),...o]},o3=t=>e=>n=>r=>o=>q(i=>{const s=nt(i)/nt(o),a=1-s,u=s*s*s,c=3*a*s*s,_=3*a*a*s,d=a*a*a;return{x:d*t.x+_*e.x+c*n.x+u*r.x,y:d*t.y+_*e.y+c*n.y+u*r.y}})(Xt(0,o-1|0)),i3=t=>[...Ge({x:t.x,y:t.y})({x:t.x+t.w,y:t.y})(12),...Ge({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h*.85})(12),...o3({x:t.x+t.w,y:t.y+t.h*.85})({x:t.x+t.w*.66,y:t.y+t.h*1.05})({x:t.x+t.w*.34,y:t.y+t.h*.65})({x:t.x,y:t.y+t.h*.85})(32),...Ge({x:t.x,y:t.y+t.h*.85})({x:t.x,y:t.y})(12)],el=t=>e=>q(n=>{const r=6.283185307179586*nt(n)/nt(64);return{x:t.x+e*Sn(r),y:t.y+e*pn(r)}})(Xt(0,63)),nl=t=>e=>{const n=.5522847498*e;return[1,t.x+e,t.y,4,t.x+e,t.y+n,t.x+n,t.y+e,t.x,t.y+e,4,t.x-n,t.y+e,t.x-e,t.y+n,t.x-e,t.y,4,t.x-e,t.y-n,t.x-n,t.y-e,t.x,t.y-e,4,t.x+n,t.y-e,t.x+e,t.y-n,t.x+e,t.y,5]},s3=t=>{const e=t.y+t.h/2,n=Jn(t.h*.4)(t.w*.2);return[...Ge({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(10),...Ge({x:t.x+t.w-n,y:t.y})({x:t.x+t.w,y:e})(8),...Ge({x:t.x+t.w,y:e})({x:t.x+t.w-n,y:t.y+t.h})(8),...Ge({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(10),...Ge({x:t.x+n,y:t.y+t.h})({x:t.x,y:e})(8),...Ge({x:t.x,y:e})({x:t.x+n,y:t.y})(8)]},ng=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:Xd(q(n=>n.x)(t))/nt(e),y:Xd(q(n=>n.y)(t))/nt(e)}},xa=t=>e=>n=>r=>o=>q(i=>{const s=n+(r-n)*(nt(i)/nt(o));return{x:t.x+e*Sn(s),y:t.y+e*pn(s)}})(Xt(0,o-1|0)),rg=t=>e=>{const n=fr(t)(fr(e.w/2)(e.h/2));return[...Ge({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...xa({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...Ge({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...xa({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...Ge({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...xa({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...Ge({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...xa({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},wa=t=>e=>n=>r=>o=>i=>q(s=>{const a=r+(o-r)*(nt(s)/nt(i));return{x:t.x+e*Sn(a),y:t.y+n*pn(a)}})(Xt(0,i-1|0)),a3=t=>{const e=t.h*.38;return[...Et(Cd(Td(Nd)({x:t.x,y:t.y-e,w:t.w,h:e}))(t.y))(n=>{const r=so(n.p2.y-n.c.cy)(n.p2.x-n.c.cx),o=so(n.p1.y-n.c.cy)(n.p1.x-n.c.cx);return wa({x:n.c.cx,y:n.c.cy})(n.c.r)(n.c.r)(o)(r>o?r:r+6.283185307179586)(16)}),...Ge({x:t.x+t.w,y:t.y})({x:t.x+t.w,y:t.y+t.h})(8),...Ge({x:t.x+t.w,y:t.y+t.h})({x:t.x,y:t.y+t.h})(12),...Ge({x:t.x,y:t.y+t.h})({x:t.x,y:t.y})(8)]},u3=t=>{const e=fr(t.h*.075)(t.w*.075),n=t.w/2,r=t.y+e,o=t.y+t.h+5-e-2,i=t.x+n;return[...wa({x:i,y:r})(n)(e)(3.141592653589793)(6.283185307179586)(24),...Ge({x:t.x+t.w,y:r})({x:t.x+t.w,y:o})(12),...wa({x:i,y:o})(n)(e)(0)(3.141592653589793)(24),...Ge({x:t.x,y:o})({x:t.x,y:r})(12)]},No=t=>e=>e.shape==="Cylinder"?u3(e):e.shape==="Parallelogram"?e3(e):e.shape==="Diamond"?s3(e):e.shape==="Ellipse"?rg(Jn(e.w)(e.h)/2)(e):e.shape==="Document"?i3(e):e.shape==="Cloud"?a3(e):rg(t)(e),c3=t=>{const e=fr(t.h*.075)(t.w*.075),n=t.w/2;return wa({x:t.x+n,y:t.y+e})(n)(e)(0)(3.141592653589793)(24)},g3=t=>e=>n=>v(r=>o=>{const i=r.pos+o.len,s=n<i?(n-r.pos)/o.len:1,a={x:o.a.x+(o.b.x-o.a.x)*s,y:o.a.y+(o.b.y-o.a.y)*s},u=e>r.pos?(e-r.pos)/o.len:0,c={x:o.a.x+(o.b.x-o.a.x)*u,y:o.a.y+(o.b.y-o.a.y)*u},_=r.points.length-1|0,d=_>=0&&_<r.points.length?(()=>{const l=r.points[_].x-c.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const f=r.points[_].y-c.y;return f<0?-f<1e-4:f<1e-4})()})()?St(r.points)(a):[...r.points,c,a]:[c,a];return o.len<=0||i<=e||r.pos>=n?{...r,pos:i}:{pos:i,points:d}})({pos:0,points:[]})(t).points,_3=t=>e=>n=>{const r=Ft(o=>J,o=>i=>N("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const o=n3(t),i=ZT(o),s=jd(0)(i)(e*i),a=jd(0)(i)(n*i);return a<=s?[]:g3(o)(s)(a)}g()},f3=t=>e=>n=>r=>{const o=r.x-n.x,i=r.y-n.y,s=e.x-t.x,a=e.y-t.y,u=n.x-t.x,c=n.y-t.y,_=s*i-a*o,d=(u*i-c*o)/_,l=(u*a-c*s)/_;return(_<0?-_<1e-9:_<1e-9)?J:d>=0&&d<=1&&l>=0&&l<=1?N("Just",d):J},d3=t=>e=>n=>{const r=Pt(o=>i=>ot.compare(o.t)(i.t))(vt(o=>{const i=f3(e)(n)(o._1)(o._2);return i.tag==="Just"?N("Just",{t:i._1,p:{x:e.x+(n.x-e.x)*i._1,y:e.y+(n.y-e.y)*i._1}}):J})(Fe(Rn,t,[...Rt(1,t.length,t),...Rt(0,1,t)])));return 0<r.length?N("Just",r[0].p):J},rl=t=>e=>{const n=Nr(e);if(n.tag==="Nothing")return e;if(n.tag==="Just"){const r=n._1.init.length-1|0;if(r>=0&&r<n._1.init.length){const o=d3(t)(n._1.init[r])(n._1.last);if(o.tag==="Just")return St(n._1.init)(o._1);if(o.tag==="Nothing")return e;g()}return e}g()},jr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},og=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},l3=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},h3=t=>e=>{const n=jr(0)(t.y+4-e.y)+jr(0)(e.y+e.h-(t.y+t.h-4)),r=jr(0)(t.x+4-e.x)+jr(0)(e.x+e.w-(t.x+t.w-4));return r*e.h+n*e.w+r*n},p3=t=>e=>{const n=t.y+t.h-6,r=t.y+6,o=t.x+14,i=t.x+t.w-14,s=v(jr)(0)(q(a=>o-10<a.x+a.w+12&&i+10>a.x-12&&r-10<a.y+a.h+12&&n+10>a.y-12?og((a.x+a.w+12-(o-10))/.7071067811865476)((n+10-(a.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+s*.7071067811865476,y:t.y-s*.7071067811865476}},m3=t=>e=>{const n=og(t.x+t.w)(e.x+e.w)-jr(t.x)(e.x),r=og(t.y+t.h)(e.y+e.h)-jr(t.y)(e.y);return t.x<e.x+e.w&&t.x+t.w>e.x&&t.y<e.y+e.h&&t.y+t.h>e.y?n*r:0},ol=t=>e=>n=>r=>{const o=t+4,i=jr(0)(e-8),s=o+i-n;return n<=i?l3(o)(s)(r):t+(e-n)/2},ig=t=>e=>({...e,x:ol(t.x)(t.w)(e.w)(e.x),y:ol(t.y)(t.h)(e.h)(e.y)}),y3=t=>{const e=2*t.token.x-t.rect.x-t.rect.w,n=t.token.y-t.rect.h/2,r=t.token.x-t.rect.w/2,o=2*t.token.y-t.rect.y-t.rect.h;return[{...t.rect,x:t.rect.x,y:t.rect.y},{...t.rect,x:e,y:t.rect.y},{...t.rect,x:t.rect.x,y:o},{...t.rect,x:e,y:o},{...t.rect,x:t.rect.x,y:n},{...t.rect,x:e,y:n},{...t.rect,x:r,y:t.rect.y},{...t.rect,x:r,y:o}]},x3=t=>e=>n=>r=>o=>{const i=o.y+o.h/2-n.token.y,s=o.y-r.y;return(()=>{const a=o.x+o.w/2-n.token.x,u=o.x-r.x;return 1e6*h3(t)(o)+1e4*v(c=>_=>c+m3(o)(_))(0)(e)+.05*(u*u+s*s)+.01*(a*a+i*i)})()+(o.y>n.token.y?100:0)},w3=t=>e=>n=>r=>{const o=s=>{const a=ig(t)(s);return{rect:a,score:x3(t)(e)(n)(r)(a)}},i=Ft(s=>J,s=>a=>N("Just",{head:s,tail:a}),[r,n.rect,...y3(n)]);if(i.tag==="Nothing")return ig(t)(r);if(i.tag==="Just")return v(s=>a=>{const u=o(a);return u.score<s.score?u:s})(o(i._1.head))(i._1.tail).rect;g()},J3=t=>e=>n=>v(r=>o=>{const i=p3(o.rect)(r.obstacles),s=i.x>=t.x+4&&i.y>=t.y+4&&i.x+i.w<=t.x+t.w-4&&i.y+i.h<=t.y+t.h-4?i:w3(t)(r.obstacles)(o)(i);return{acc:rt(P)(o.id)(s)(r.acc),obstacles:St(r.obstacles)(s)}})({acc:I,obstacles:e})(n).acc,sg=t=>t,Br=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},vo=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},N3=Io(fu)(Mt),v3=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},T3=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},il=sg("SegMove"),C3=sg("SegLine"),b3=sg("SegQuad"),sl={offset:.4,passes:1,rMax:1.5},al=t=>fe(An(t.x*7919+t.y*3001+t.w*113+t.h*17+1))*-1640531535|0,Ja=t=>e=>n=>()=>{t.push(3),t.push(e.x),t.push(e.y),t.push(n.x),t.push(n.y)},Na=t=>e=>()=>{t.push(1),t.push(e.x),t.push(e.y)},Dr=t=>e=>()=>{t.push(2),t.push(e.x),t.push(e.y)},us=(()=>{const t=v(e=>n=>((e*31|0)+fe(An(n.x*100))|0)+fe(An(n.y*100))|0)(1);return e=>t(e)*-1640531535|0})(),k3=t=>{const e=[];let n=0,r={x:0,y:0};for(;n<t.length;){const o=n,i=r,s=o>=0&&o<t.length?N("Just",t[o]):J;if(s.tag==="Nothing"){n=t.length;continue}if(s.tag==="Just"){if(s._1===1){const a={x:(()=>{const u=o+1|0;return u>=0&&u<t.length?t[u]:0})(),y:(()=>{const u=o+2|0;return u>=0&&u<t.length?t[u]:0})()};e.push({kind:il,m:i,c:i,p:a,len:0}),r=a,n=o+3|0;continue}if(s._1===2){const a={x:(()=>{const _=o+1|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+2|0;return _>=0&&_<t.length?t[_]:0})()},u=a.x-i.x,c=a.y-i.y;e.push({kind:C3,m:i,c:i,p:a,len:$e(u*u+c*c)}),r=a,n=o+3|0;continue}if(s._1===3){const a={x:(()=>{const _=o+3|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+4|0;return _>=0&&_<t.length?t[_]:0})()},u=a.x-i.x,c=a.y-i.y;e.push({kind:b3,m:i,c:{x:(()=>{const _=o+1|0;return _>=0&&_<t.length?t[_]:0})(),y:(()=>{const _=o+2|0;return _>=0&&_<t.length?t[_]:0})()},p:a,len:$e(u*u+c*c)*1.05}),r=a,n=o+5|0;continue}if(s._1===5){e.push({kind:il,m:i,c:i,p:i,len:0}),n=o+1|0;continue}n=t.length;continue}g()}return e},S3=t=>e=>{const n=e.length-1|0,r=n<1?[]:Rt(0,n,e),o=(()=>{const s=r.length-1|0;return s>=0&&s<r.length?N("Just",r[s]):J})(),i=e.length-1|0;if(i>=0&&i<e.length&&o.tag==="Just"){const s=e[i].y-o._1.y,a=e[i].x-o._1.x,u=$e(a*a+s*s);return u<=1e-4?e:St((()=>{const c=e.length-1|0;return c<1?[]:Rt(0,c,e)})())({x:e[i].x+a/u*t,y:e[i].y+s/u*t})}return e},L3=t=>e=>n=>se(v(r=>o=>{const i=Ee(0)(t)(r.prng),s=Ee(0)(6.283185307179586)(i.prng);return{prng:s.prng,out:[{x:o.x+i.value*Sn(s.value),y:o.y+i.value*pn(s.value)},...r.out]}})({prng:e,out:[]})(n).out),E3=t=>e=>n=>{if(e.kind==="SegMove")return Na(t)(e.p);if(e.kind==="SegLine")return Dr(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});if(e.kind==="SegQuad")return Dr(t)({x:e.m.x+(e.p.x-e.m.x)*n,y:e.m.y+(e.p.y-e.m.y)*n});g()},G3=t=>e=>{if(e.kind==="SegMove")return Na(t)(e.p);if(e.kind==="SegLine")return Dr(t)(e.p);if(e.kind==="SegQuad")return Ja(t)(e.c)(e.p);g()},ul=t=>e=>{const n=k3(e),r=v(a=>u=>a+u.len)(0)(n)*Br(0)(vo(1)(t)),o=[];let i=0,s=0;for(;s<n.length;){const a=s,u=i;if(a>=0&&a<n.length){if(u+n[a].len<=r){const c=n[a];G3(o)(c)(),i=u+c.len,s=a+1|0;continue}if(u>=r){s=n.length;continue}E3(o)(n[a])((r-u)/Br(n[a].len)(1e-4))()}s=n.length}return o},cl={offset:1.5,passes:2,rMax:14,overshoot:2.5},gl=t=>e=>n=>r=>{const o=r.y-n.y,i=n.y-e.y,s=r.x-n.x,a=$e(s*s+o*o),u=n.x-e.x,c=$e(u*u+i*i),_=vo(t.rMax*(Q0(c>0&&a>0?Br(-1)(vo(1)((u*s+i*o)/(c*a))):1)/3.141592653589793))(.4*vo(c)(a));return{inP:c>0?{x:n.x-u/c*_,y:n.y-i/c*_}:n,curr:n,outP:a>0?{x:n.x+s/a*_,y:n.y+o/a*_}:n}},_l=t=>e=>{const n=e.length,r=[],o=0<e.length?N("Just",e[0]):J;if(o.tag==="Just"?Na(r)(o._1)():o.tag==="Nothing"||g(),n>=3){let s=1;for(;s<=(n-2|0);){const a=s,u=a+1|0;if(u>=0&&u<e.length){if(a>=0&&a<e.length){const c=a-1|0;if(c>=0&&c<e.length){const _=gl(t)(e[c])(e[a])(e[u]);Dr(r)(_.inP)(),Ja(r)(_.curr)(_.outP)()}}s=a+1|0;continue}s=a+1|0}}const i=e.length-1|0;return i>=0&&i<e.length&&n>=2&&Dr(r)(e[i])(),r},P3=t=>e=>n=>r=>o=>{if(o.length<4)return _l(t)(o);const i=0<o.length?N("Just",o[0]):J,s=(()=>{if(i.tag==="Nothing")return{x:0,y:0};if(i.tag==="Just")return i._1;g()})(),a=o.length-1|0,u=Wr(Wr(e)(a)+a|0)(a),c=f=>{const h=Wr(f+a|0)(a);return h>=0&&h<o.length?o[h]:s},_=q(f=>gl(t)(c((u+f|0)-1|0))(c(u+f|0))(c((u+f|0)+1|0)))(Xt(0,a-1|0)),d=[],l=0<_.length?N("Just",_[0]):J;if(l.tag==="Just")if(Na(d)(l._1.outP)(),N3((()=>{const f=Ft(h=>J,h=>p=>N("Just",p),_);if(f.tag==="Nothing")return[];if(f.tag==="Just")return f._1;g()})())(f=>{const h=Dr(d)(f.inP);return()=>(h(),Ja(d)(f.curr)(f.outP)())})(),n)Dr(d)(l._1.inP)(),Ja(d)(l._1.curr)(l._1.outP)(),d.push(5);else{const f=_.length-1|0;f>=0&&f<_.length?Dr(d)((()=>{const h=1-r;return{x:_[f].outP.x+(l._1.inP.x-_[f].outP.x)*h,y:_[f].outP.y+(l._1.inP.y-_[f].outP.y)*h}})())():Dr(d)(l._1.inP)()}else l.tag==="Nothing"||g();return d},mi=t=>e=>n=>r=>{const o=v3(1)(r.length-1|0),i=Ee(0)(nt(o))(Mc("shape")(e)),s=T3(o-1|0)(fe(An(i.value))),a=i.prng;return q(u=>{const c=Ee(0)(1)(Mc(ie(u))(a)),_=Ee(-.18)(.3)(c.prng),d=c.value<.7,l=Ee(.5)(.85)(_.prng),f=L3(t.offset)(l.prng)(r);return{path:n?P3(t)(s)(d)(_.value)(f):_l(t)(f),alpha:l.value}})(Xt(0,t.passes-1|0))},B3=t=>e=>n=>mi(t)(e)(!0)([{x:n.x,y:n.y},{x:n.x+n.w,y:n.y},{x:n.x+n.w,y:n.y+n.h},{x:n.x,y:n.y+n.h},{x:n.x,y:n.y}]),D3=t=>e=>n=>{const r=Br(0)(vo(1)(n)),o=e.h/nt(4),i=Br(6)(o*1.4);return vt(s=>s)(q(s=>{if(r<Br(0)(nt(s)/nt(4)-.05))return J;const a=Mc(ie(s))(t),u=Br(0)(nt(s)/nt(4)-.05),c=Wr(s)(2)===0,_=c?e.x-2:e.x+e.w+2,d=c?e.x+e.w+2:e.x-2,l=e.y+(nt(s)+.5)*o;return N("Just",{path:ul(Br(0)(vo(1)((r-u)/Br(1e-4)(vo(1)(nt(s+1|0)/nt(4)+.05)-u))))((()=>{const f={rMax:2,offset:.6,passes:1},h=se(v(m=>w=>{const x=Ee(-o*.08)(o*.08)(m.prng);return{prng:x.prng,out:[{x:_+(d-_)*(nt(w)/nt(4)),y:l+x.value},...m.out]}})({prng:a,out:[]})(Xt(0,4)).out),p=h.length<2?[]:mi(f)(a)(!1)(h);return 0<p.length?p[0].path:[]})()),width:i,alpha:1})})(Xt(0,3)))},ag=(t,e,n)=>({tag:t,_1:e,_2:n}),va=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Pe=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Ze=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),dr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},To=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Rr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},R3=Mt.foldMap(tm),Ta=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},fl=ce(P)(Mt),dl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},A3=N_(P),I3=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Co=t=>{const e=t.Apply0();return n=>v(r=>o=>e.apply(e.Functor0().map(i=>i_)(r))(n(o)))(t.pure())},Ar=Co(xo),ll=t=>e=>n=>r=>o=>i=>{const s={x:n.x+n.w/2,y:n.y+n.h/2},a={x:e.x+e.w/2,y:e.y+e.h/2},u=li(o)(i)(r),c=0<t.length?N("Just",t[0]):J,_=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return a;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?N("Just",t[d]):J,f=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return s;g()})(),h=Bd(128)(No(4)(as(2)(e)))(el(_)(6)),p=_.x-a.x,m=2*(()=>{const j=_.y-a.y;return(p<0?-p:p)+(j<0?-j:j)})(),w=f.x-s.x,x=2*(()=>{const j=f.y-s.y;return(w<0?-w:w)+(j<0?-j:j)})(),y=m+Bi(t)+x,T=y<=1e-4?1:1-x/y,C=y<=1e-4?0:m/y,S=T-C,E=Bd(128)(el(f)(6))(No(4)(as(2)(n))),B={maxDelay:.4,smoothPasses:2},M=go(t)(va(0)(1)(S<=1e-4?0:(u-C)/S)),Y=(()=>{if(M.tag==="Just")return M._1;if(M.tag==="Nothing")return _;g()})(),R=(()=>{if(T>=1)return 0;const j=(u-T)/(1-T),Z=j<0?0:j>1?1:j;return Z*Z*(3-2*Z)})(),A=(()=>{if(C<=1e-4)return 1;const j=u/C,Z=j<0?0:j>1?1:j;return Z*Z*(3-2*Z)})();return u<C?Jo("PolyShape",Rd(A)(h.from)(h.to)(B)):u>=T?Jo("PolyShape",Rd(R)(E.from)(E.to)(B)):Jo("CircleShape",Y,6)},ug=t=>e=>n=>r=>o=>i=>{const s=ll(t)(e)(n)(r)(o)(i);if(s.tag==="PolyShape")return ng(s._1);if(s.tag==="CircleShape")return s._1;g()},cg=(()=>{const t={r:24,g:24,b:27,a:255},e={r:244,g:244,b:245,a:255},n={r:248,g:249,b:246,a:255},r={r:26,g:26,b:26,a:255},o={r:28,g:101,b:192,a:255},i={r:247,g:248,b:250,a:255},s={r:42,g:48,b:60,a:255},a={r:120,g:130,b:146,a:255};return u=>{if(u==="Light")return{bg:{r:255,g:255,b:255,a:255},bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:211,b:209,a:255},shadowFill:{r:255,g:255,b:255,a:255},shadowDot:{r:26,g:26,b:26,a:255},chip:{r:255,g:235,b:130,a:255},chipShadow:{r:214,g:211,b:209,a:255},chipText:Pr,nodeFill:ye,nodeStroke:Pr,text:Pr,edge:Pr,arrowFill:Pr,tokenOutsideFill:Pr,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:la,tokenInsideAlpha:1,chipPillFill:Pr,chipPillText:ye,chipHairline:{r:26,g:26,b:26,a:90},trailDot:Pr,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(u==="Dark")return{bg:t,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:63,g:63,b:70,a:255},shadowFill:t,shadowDot:e,chip:{r:234,g:179,b:8,a:255},chipShadow:{r:0,g:0,b:0,a:120},chipText:t,nodeFill:Pr,nodeStroke:e,text:e,edge:e,arrowFill:e,tokenOutsideFill:ye,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:la,tokenInsideAlpha:1,chipPillFill:e,chipPillText:t,chipHairline:{r:244,g:244,b:245,a:120},trailDot:e,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(u==="Blueprint")return{bg:o,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:90,g:160,b:230,a:255},shadowFill:o,shadowDot:ye,chip:ye,chipShadow:{r:0,g:0,b:0,a:120},chipText:o,nodeFill:o,nodeStroke:ye,text:ye,edge:ye,arrowFill:ye,tokenOutsideFill:ye,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:hd,tokenInsideAlpha:.35,chipPillFill:ye,chipPillText:o,chipHairline:{r:255,g:255,b:255,a:120},trailDot:ye,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(u==="Whiteboard")return{bg:n,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:0,g:0,b:0,a:0},shadowFill:n,shadowDot:r,chip:{r:217,g:74,b:56,a:255},chipShadow:{r:26,g:26,b:26,a:60},chipText:n,nodeFill:n,nodeStroke:r,text:r,edge:r,arrowFill:r,tokenOutsideFill:r,tokenOutsideStroke:n,tokenInside:n,tokenInsideStroke:n,tokenInsideBlend:hd,tokenInsideAlpha:1,chipPillFill:r,chipPillText:n,chipHairline:{r:26,g:26,b:26,a:90},trailDot:r,wobble:!0,fontFamily:"Supermarker, Ilisarniq, ui-sans-serif, system-ui, sans-serif"};if(u==="Isometric")return{bg:i,bgTransparent:{r:0,g:0,b:0,a:0},bgDot:{r:214,g:218,b:224,a:255},shadowFill:i,shadowDot:s,chip:{r:255,g:235,b:130,a:255},chipShadow:{r:100,g:110,b:125,a:90},chipText:s,nodeFill:{r:236,g:239,b:244,a:255},nodeStroke:s,text:s,edge:a,arrowFill:a,tokenOutsideFill:s,tokenOutsideStroke:ye,tokenInside:ye,tokenInsideStroke:ye,tokenInsideBlend:la,tokenInsideAlpha:1,chipPillFill:s,chipPillText:ye,chipHairline:{r:60,g:66,b:78,a:90},trailDot:s,wobble:!1,fontFamily:"Ilisarniq, ui-sans-serif, system-ui, sans-serif"};g()}})(),gg=t=>e=>Et(Ze(t.nodes))(n=>{const r=Pe(n._1)(e.nodes);return r.tag==="Just"&&hi(r._1).alpha>0?tg(n._2):[]}),F3=t=>e=>n=>[1,t.vx,t.vy,2,t.vx+t.vw,t.vy,2,t.vx+t.vw,t.vy+t.vh,2,t.vx,t.vy+t.vh,5,...gg(e)(n)],Q3=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=oo.traverse(r);return i=>s=>{const a=vr(s),u=.32*i.size;return o(c=>n.bind(c===0?r.pure(0):t.measureText(i)(Re(c)(s)))(_=>n.bind(t.measureText(i)(Re(c+1|0)(s)))(d=>n.bind(t.measureInk(i)(c>=0&&c<a.length?Gi(a[c]):" "))(l=>r.pure({x:_,w:d-_,up:l.ascent-u,down:l.descent+u})))))(Xt(0,a.length-1|0))}},z3=t=>e=>{const n=o=>(o.x-e.x)*(o.x-e.x)+(o.y-e.y)*(o.y-e.y),r=v(o=>i=>n(i)<n(o)?i:o)({x:t.x,y:t.y})([{x:t.x,y:t.y},{x:t.x+t.w,y:t.y},{x:t.x,y:t.y+t.h},{x:t.x+t.w,y:t.y+t.h}]);return q(o=>{const i=nt(o)/5;return{x:r.x+(e.x-r.x)*i,y:r.y+(e.y-r.y)*i}})([1,2,3,4])},_g=t=>{const e=Kr(`
7
+ `)(t);return e.length===0?[""]:e},M3=t=>e=>n=>r=>o=>i=>{const s={x:n.x+n.w/2,y:n.y+n.h/2},a={x:e.x+e.w/2,y:e.y+e.h/2},u=li(o)(i)(r),c=0<t.length?N("Just",t[0]):J,_=(()=>{if(c.tag==="Just")return c._1;if(c.tag==="Nothing")return a;g()})(),d=t.length-1|0,l=d>=0&&d<t.length?N("Just",t[d]):J,f=(()=>{if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return s;g()})(),h=_.x-a.x,p=2*(()=>{const B=_.y-a.y;return(h<0?-h:h)+(B<0?-B:B)})(),m=f.x-s.x,w=2*(()=>{const B=f.y-s.y;return(m<0?-m:m)+(B<0?-B:B)})(),x=p+Bi(t)+w,y=x<=1e-4?1:1-w/x,T=x<=1e-4?0:p/x,C=y-T,S=go(t)(va(0)(1)(C<=1e-4?0:(u-T)/C)),E=(()=>{if(S.tag==="Just")return S._1;if(S.tag==="Nothing")return _;g()})();return u<T?ag("InsideRect",as(2)(e)):u>=y?ag("InsideRect",as(2)(n)):ag("InsideBall",E,6)},fg=t=>e=>n=>r=>o=>i=>s=>{const a=(u,c)=>Yd({id:u,pass:t,geometry:Qd("FlatToken",c),position:(()=>{if(c.tag==="CircleShape")return c._1;if(c.tag==="PolyShape")return ng(c._1);g()})(),plan:Md("FlatTokenPlan",{wobble:n,fill:i,stroke:s})});return Ar(u=>{if(u._2.tag==="Travelling"){const c=Pe(u._2._1.target)(r.nodes),_=Pe(u._2._1.source)(r.nodes);if(_.tag==="Just"&&c.tag==="Just"){const d=Rr(u._2._1.edge)(r.edges);if(d.tag==="Just"){const l=(()=>{if(u._2._1.direction==="Forward")return d._1;if(u._2._1.direction==="Backward")return se(d._1);g()})();return a(u._1,(()=>{if(e){const f=M3(l)(_._1)(c._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost);if(f.tag==="InsideRect")return Jo("PolyShape",rg(4)(f._1));if(f.tag==="InsideBall")return Jo("CircleShape",f._1,f._2);g()}return ll(l)(_._1)(c._1)(u._2._1.progress)(u._2._1.holdPre)(u._2._1.holdPost)})())}if(d.tag==="Nothing"){const l=li(u._2._1.holdPre)(u._2._1.holdPost)(u._2._1.progress),f={x:_._1.x+_._1.w/2,y:_._1.y+_._1.h/2},h={x:c._1.x+c._1.w/2,y:c._1.y+c._1.h/2};return je({path:[],role:dn,layer:J,effects:[be("GroupAlpha",(()=>{if(l<.5){const m=l*2;return 1-dr(0)(To(1)(m))*dr(0)(To(1)(m))*(3-2*dr(0)(To(1)(m)))}const p=(l-.5)*2;return dr(0)(To(1)(p))*dr(0)(To(1)(p))*(3-2*dr(0)(To(1)(p)))})())]})(a(u._1,Jo("CircleShape",l<.5?f:h,6)))}g()}return tt(ut("Return",void 0),_t)}if(u._2.tag==="Filling"){if(n)return tt(ut("Return",void 0),_t);const c=Pe(u._2._1.node)(r.nodes);if(c.tag==="Just")return a(u._1,Jo("PolyShape",No(4)(as(2)(c._1))));if(c.tag==="Nothing")return tt(ut("Return",void 0),_t);g()}return tt(ut("Return",void 0),_t)})(Ze(o.tokens))},W3=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0();return o=>n.bind((()=>{const i=r.pure();if(o.clear.tag==="Nothing")return i;if(o.clear.tag==="Just")return t.clearBackground(o.clear._1);g()})())(()=>n.bind(t.setViewport(o.viewport))(()=>{const i=r.pure();if(o.dots.tag==="Nothing")return i;if(o.dots.tag==="Just")return t.backgroundDots(o.dots._1);g()}))},hl=t=>e=>n=>r=>je({path:[],role:dn,layer:J,effects:[be("GroupAlpha",n.fadeAlpha),be("GroupTransform",pi,{tx:t.x*(1-n.popScale),ty:(t.y+t.h)*(1-n.popScale),sx:n.popScale,sy:n.popScale}),be("GroupTransform",pi,{tx:0,ty:e.y*(1-n.flipY),sx:1,sy:n.flipY})]})(ss(r)),pl=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>{const _=hi(c),d=c.tag==="PloppingOut"&&r.wobble?{alpha:1,scale:1}:_,l=Kr(`
8
+ `)(u.label===""?a:u.label),f=l.length===0?[""]:l,h={family:r.fontFamily,size:r.wobble?15:11,weight:r.wobble?800:500},p=h.size*1.2,m={tx:(u.x+u.w/2)*(1-d.scale),ty:(u.y+u.h/2)*(1-d.scale),sx:d.scale,sy:d.scale},w=(u.shape==="Cylinder"?(u.y+(u.y+u.h+5-2*Jn(u.h*.075)(u.w*.075)))/2:(u.y+u.y+u.h)/2)-nt(f.length)*p/2+p/2,x=Zc({id:a,role:t,geometry:Uc("FlatNode",{shape:u.shape,bounds:{x:u.x,y:u.y,w:u.w,h:u.h}}),alpha:o,plan:Kc("FlatNodePlan",{palette:r,label:u.label,labelVisibility:e,inkBoost:n,labelAlpha:i,arrival:s,animState:c})}),y=()=>{if(e==="LabelsHidden")return tt(ut("Return",void 0),_t);if(e==="LabelsShown"){const T=je({path:[],role:dn,layer:J,effects:[be("GroupAlpha",d.alpha*o),be("GroupTransform",pi,m),be("GroupAlpha",i)]})(Ar(C=>ss({owner:wo("NodeText",a),text:C._2,spec:{x:u.x+u.w/2,y:w+nt(C._1)*p,content:C._2,font:h,color:r.text,align:Gr,baseline:En},bounds:J,plan:ma}))(Ht(Rn)(f)));return i>0&&d.alpha*o>0?T:tt(ut("Return",void 0),_t)}g()};return tt(x._1,(()=>{if(x._2.tag==="CatNil")return at("CatCons",y,st($,$));if(x._2.tag==="CatCons")return at("CatCons",x._2._1,st(x._2._2._1,kt("Cons",at("CatCons",y,st($,$)),x._2._2._2)));g()})())},O3=t=>e=>n=>r=>o=>i=>s=>hl(o)(i)(s)({owner:wo("TokenText",t),text:n,spec:{x:i.x,y:i.y,content:n,font:{family:e.fontFamily,size:11,weight:500},color:e.chipText,align:Gr,baseline:En},bounds:N("Just",o),plan:is("TokenFillingText",{shadow:{...o,y:o.y+1.5},shadowFill:{color:e.chipShadow,flat:!0},radius:6,fill:{color:e.chip,flat:!0},stroke:{color:e.chipHairline,width:1,lineJoin:Ve,lineCap:Gn},leader:[1,i.x,o.y+o.h,2,r.x+r.w/2,r.y]})}),q3={offset:.8,passes:2,rMax:5},dg=t=>e=>n=>r=>je({path:[],role:dn,layer:N("Just",Xv),effects:[be("GroupClip",F3(e)(n)(r),eT)]})(fg(Od)(!1)(t.wobble)(n)(r)(t.tokenOutsideFill)(t.tokenOutsideStroke)),ml=t=>e=>n=>r=>{if(e.tokenInsideBlend==="Difference"){const o=XT(t),i=s=>{const a=je({path:[],role:dn,layer:N("Just",jv),effects:[be("GroupBlend",la),be("GroupClip",gg(n)(r),ns)]})(fg(qd)(s==="ConvexAbsorb")(e.wobble)(n)(r)(e.tokenInside)(e.tokenInsideStroke)),u=()=>je({path:[],role:dn,layer:N("Just",Zv),effects:[]})(Ar(c=>{const _=Pe(c._1)(r.nodes);return _.tag==="Just"&&hi(_._1).alpha>0?ya(pa("FloorOverlay",{path:tg(c._2),fill:N("Just",{color:ye,flat:!1}),stroke:J})):tt(ut("Return",void 0),_t)})(Ze(n.nodes)));return tt(a._1,(()=>{if(a._2.tag==="CatNil")return at("CatCons",u,st($,$));if(a._2.tag==="CatCons")return at("CatCons",a._2._1,st(a._2._2._1,kt("Cons",at("CatCons",u,st($,$)),a._2._2._2)));g()})())};return tt(o._1,(()=>{if(o._2.tag==="CatNil")return at("CatCons",i,st($,$));if(o._2.tag==="CatCons")return at("CatCons",o._2._1,st(o._2._2._1,kt("Cons",at("CatCons",i,st($,$)),o._2._2._2)));g()})())}if(e.tokenInsideBlend==="Normal")return je({path:[],role:dn,layer:J,effects:[be("GroupClip",gg(n)(r),ns),be("GroupAlpha",e.tokenInsideAlpha)]})(fg(qd)(!1)(e.wobble)(n)(r)(e.tokenInside)(e.tokenInsideStroke));g()},yl=t=>e=>n=>r=>t.strokePath((()=>{const o=Ft(i=>J,i=>s=>N("Just",{head:i,tail:s}),q(i=>i.pt)(B0(i=>s=>{const a=nt(s)/nt(72),u=Ee(-.18)(.18)(i.prng),c=Ee(-.1)(.1)(u.prng),_=Ee(-.07)(.07)(c.prng),d=n*(.05+.55*a)*(1+c.value),l=a*28.274333882308138+u.value;return{prng:_.prng,pt:{x:e.x+Sn(l)*d+_.value*n,y:e.y+pn(l)*d+_.value*n}}},{prng:137,pt:{x:e.x,y:e.y}},Xt(0,72))));if(o.tag==="Just")return[1,o._1.head.x,o._1.head.y,...R3(i=>[2,i.x,i.y])(o._1.tail)];if(o.tag==="Nothing")return[];g()})())({color:r,width:5.5,lineJoin:Ve,lineCap:Vn}),H3=t=>{const e=t.Monad0().Applicative0();return n=>{if(n.geometry.tag==="FlatToken"&&n.plan.tag==="FlatTokenPlan"){if(n.geometry._1.tag==="CircleShape")return n.plan._1.wobble?yl(t)(n.geometry._1._1)(n.geometry._1._2)({r:200,g:35,b:30,a:220}):t.fillStrokePath(nl(n.geometry._1._1)(n.geometry._1._2))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:Ve,lineCap:Gn});if(n.geometry._1.tag==="PolyShape")return n.plan._1.wobble&&n.geometry._1._1.length>=3?yl(t)(ng(n.geometry._1._1))(6)({r:200,g:35,b:30,a:220}):n.geometry._1._1.length>=3?t.fillStrokePath(Zd(n.geometry._1._1))({color:n.plan._1.fill,flat:!0})({color:n.plan._1.stroke,width:1,lineJoin:Ve,lineCap:Gn}):e.pure();g()}return e.pure()}},$3=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=t.popClip,i=t.popTransform,s=t.popAlpha;return a=>u=>c=>_=>{const d=hi(_),l={...c,y:c.y+5},f=l.x+l.w/2,h=l.y+l.h/2,p=r.bind(t.pushAlpha(d.alpha))(()=>r.bind(t.pushTransform({tx:f*(1-d.scale),ty:h*(1-d.scale),sx:d.scale,sy:d.scale}))(()=>r.bind(t.drawRoundedRect({x:l.x,y:l.y,w:l.w,h:l.h})(7)(N("Just",{color:a.shadowFill,flat:!0}))(J))(()=>r.bind((()=>{const m=r.bind(t.pushClip(tl(l)(7))(ns))(()=>r.bind(t.backgroundDots({viewport:{vx:l.x,vy:l.y,vw:l.w,vh:l.h},bgColor:a.bgTransparent,dotColor:a.shadowDot,tile:1.6,dotRadius:.25,origin:{x:0,y:0}}))(()=>o));return u&&!a.wobble?m:n.pure()})())(()=>r.bind(t.drawRoundedRect({x:l.x,y:l.y,w:l.w,h:l.h})(7)(J)(N("Just",{color:a.nodeStroke,width:1.25,lineJoin:Ve,lineCap:Gn})))(()=>r.bind(i)(()=>s))))));return d.alpha>0&&!a.wobble?p:n.pure()}},xl=t=>e=>n=>r=>Ar(o=>{const i=Pe(o._1)(r.nodes);if(i.tag==="Just")return Zc({id:o._1,role:UT,geometry:Uc("FlatNode",{shape:o._2.shape,bounds:{x:o._2.x,y:o._2.y,w:o._2.w,h:o._2.h}}),alpha:1,plan:Kc("FlatNodePlan",{palette:t,label:o._2.label,labelVisibility:jc,inkBoost:e?1:0,labelAlpha:0,arrival:J,animState:i._1})});if(i.tag==="Nothing")return tt(ut("Return",void 0),_t);g()})(Ze(n.nodes)),wl=t=>e=>n=>{const r={...t,nodeFill:t.text,text:t.nodeFill,nodeStroke:t.nodeFill};return Ar(o=>{const i=Pe(o._1)(n.nodes),s=Pe(o._1)(e.nodes),a=s.tag==="Just"&&i.tag==="Just"?je({path:[],role:dn,layer:J,effects:[be("GroupAlpha",o._2)]})(pl(KT)(Xc)(1)(r)(1)(1)(J)(o._1)(s._1)(i._1)):tt(ut("Return",void 0),_t);return o._2>0?a:tt(ut("Return",void 0),_t)})(Ze(n.nodeInvert))},V3=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=Co(e.Applicative0());return i=>s=>a=>o(u=>n.bind(t.pushAlpha(u.alpha))(()=>n.bind(t.strokePath(u.path)({color:i.nodeFill,width:u.width,lineJoin:Ve,lineCap:Vn}))(()=>r)))(D3(al(s)+7777|0)(s)(a))},U3=t=>{const e=t.Monad0(),n=e.Bind1(),r=t.popAlpha,o=e.Applicative0(),i=Co(o),s=t.popClip,a=Co(o),u=oo.traverse(o),c=Q3(t),_=V3(t),d=t.popTransform;return l=>f=>h=>p=>m=>w=>x=>y=>T=>{const C=F=>n.bind(t.pushAlpha(F.alpha))(()=>n.bind(t.strokePath(F.path)({color:h.nodeStroke,width:2,lineJoin:Ve,lineCap:Vn}))(()=>r)),S={family:h.fontFamily,size:h.wobble?15:11,weight:h.wobble?800:500},E=Kr(`
9
+ `)(y.label===""?x:y.label),B=E.length===0?[""]:E,M=S.size*1.2,Y=y.shape==="Cylinder"?t.strokePath(fT({x:y.x,y:y.y,w:y.w,h:y.h}))({color:h.nodeStroke,width:1.25,lineJoin:Ve,lineCap:Gn}):o.pure(),R=(y.shape==="Cylinder"?(y.y+(y.y+y.h+5-2*Jn(y.h*.075)(y.w*.075)))/2:(y.y+y.y+y.h)/2)-nt(B.length)*M/2+M/2,A=T.tag==="PloppingOut"&&h.wobble?T._1:-1,j=A>=0,Z=hi(T),z=j?{alpha:1,scale:1}:Z,W=y.x+y.w/2,H=y.y+y.h/2,D=n.bind(t.pushAlpha(z.alpha*p))(()=>n.bind(t.pushTransform({tx:W*(1-z.scale),ty:H*(1-z.scale),sx:z.scale,sy:z.scale}))(()=>{const F={x:y.x,y:y.y,w:y.w,h:y.h},L={color:h.nodeStroke,width:h.wobble?2:1.25*f,lineJoin:Ve,lineCap:h.wobble?Vn:Gn};return n.bind((()=>{if(h.wobble){if(y.shape==="Rectangle")return i(C)(B3(cl)(al(F))(F));const G=No(7)(y);return n.bind(i(C)((()=>{const Q=us(G);return G.length<4?[]:mi(sl)(Q)(!0)(G)})()))(()=>a(Q=>i(C)((()=>{const V=us(Q);return Q.length<2?[]:mi(sl)(V)(!1)(Q)})()))(y.shape==="Cylinder"?[c3(y)]:[]))}return n.bind(lT(t)(y.shape)(F)(7)(N("Just",{color:h.nodeFill,flat:!1}))(N("Just",L)))(()=>Y)})())(()=>n.bind((()=>{if(w.tag==="Just"&&h.wobble&&!j){const G=w._1;return n.bind(u(c(S))(B))(Q=>{const V=Pt(dt=>ht=>ot.compare(dt.x)(ht.x)),K=fe(An(y.x*7919+y.y*3001))*-1640531535|0,U=Ee(5)(7.5)(K),O=Ee(0)(U.value)(U.prng),X=-(1+2*Ee(-1)(1)(O.prng).value*3.141592653589793/180),et=(dt,ht,Lt,Bt,zt)=>V(vt(ne=>ne)([X*ht+dt>=Bt&&X*ht+dt<=zt?N("Just",{x:ht,y:X*ht+dt}):J,X*Lt+dt>=Bt&&X*Lt+dt<=zt?N("Just",{x:Lt,y:X*Lt+dt}):J,(()=>{const ne=(Bt-dt)/X;return ne>=ht&&ne<=Lt?N("Just",{x:ne,y:Bt}):J})(),(()=>{const ne=(zt-dt)/X;return ne>=ht&&ne<=Lt?N("Just",{x:ne,y:zt}):J})()])),lt=U.value,bt=Wr(G.frameHash)(3),pt=bt===0?{r:200,g:35,b:30,a:220}:bt===1?{r:35,g:150,b:80,a:220}:{r:30,g:80,b:200,a:220},Tt=y.x+y.w/2,Gt=hn(Ht(dt=>ht=>Ht((()=>{const Lt=R+nt(dt)*M,Bt=Tt-v(zt=>ne=>zt+ne.w)(0)(ht)/2;return zt=>ne=>{const Cn=S.size*.1,Me=zt-1|0,qt=Me>=0&&Me<ht.length&&zt>0?(ht[Me].x+ht[Me].w+ne.x)/2:ne.x-Cn;return{x:Bt+qt-1,y:Lt-ne.up-1,w:dr(0)((()=>{const Ot=zt+1|0;return Ot>=0&&Ot<ht.length&&zt<(ht.length-1|0)?(ne.x+ne.w+ht[Ot].x)/2-qt:ne.x+ne.w+Cn-qt})())+2,h:ne.up+ne.down+2}}})())(ht))(Q)),jt=y.y+4,Ct=y.x+y.w-4,Yt=y.x+4,Dt=jt-X*Yt+O.value,wt=y.y+y.h-4,mt=Et(Et(Ht(dt=>ht=>{const Lt=(ht.from.x+ht.to.x)/2,Bt=(ht.from.y+ht.to.y)/2,zt=Ee(-1)(1)(K+(911*(dt+1|0)|0)|0),ne=Ee(-3)(5)(zt.prng),Cn=zt.value*3.141592653589793/180,Me=Sn(Cn),qt=pn(Cn),Ot=We=>({x:Lt+(We.x-Lt)*Me-(We.y-Bt)*qt,y:Bt+(We.x-Lt)*qt+(We.y-Bt)*Me});return{from:(()=>{const We=Ot(ht.from),bn=We.y-Bt,tn=We.x-Lt,_n=$e(tn*tn+bn*bn),Ae=_n<1e-4?1:(_n+ne.value)/_n;return{x:Lt+tn*Ae,y:Bt+bn*Ae}})(),to:(()=>{const We=Ot(ht.to),bn=Ee(-3)(5)(ne.prng).value,tn=We.y-Bt,_n=We.x-Lt,Ae=$e(_n*_n+tn*tn),oe=Ae<1e-4?1:(Ae+bn)/Ae;return{x:Lt+_n*oe,y:Bt+tn*oe}})()}})(vt(dt=>{const ht=et(Dt+nt(dt)*lt,Yt,Ct,jt,wt);return ht.length===2?N("Just",{from:ht[0],to:ht[1]}):J})(Xt(0,Ta(1)(fe(An((wt-X*Ct-Dt)/lt)))))))(dt=>ft(ht=>ht.to.x-ht.from.x>1,v(ht=>Lt=>Et(ht)(Bt=>{const zt=et(Bt.from.y-X*Bt.from.x,Lt.x,Lt.x+Lt.w,Lt.y,Lt.y+Lt.h);return zt.length===2?zt[0].x>Bt.from.x+.001&&zt[1].x<Bt.to.x-.001?[{from:Bt.from,to:zt[0]},{from:zt[1],to:Bt.to}]:zt[0].x<=Bt.from.x+.001&&zt[1].x<Bt.to.x-.001?[{from:zt[1],to:Bt.to}]:zt[0].x>Bt.from.x+.001&&zt[1].x>=Bt.to.x-.001?[{from:Bt.from,to:zt[0]}]:[]:[Bt]}))([dt])(Gt))))(dt=>(()=>{const ht=dt.to.x-dt.from.x;return $e(2)*(ht>=0?ht:-ht)<=28})()?[dt]:[{from:dt.from,to:{x:dt.from.x+(dt.to.x-dt.from.x)*.495,y:dt.from.y+(dt.to.y-dt.from.y)*.495}},{from:{x:dt.from.x+(dt.to.x-dt.from.x)*.505,y:dt.from.y+(dt.to.y-dt.from.y)*.505},to:dt.to}]),ct=mt.length,yt=dt=>dr(0)(To(1)(G.t*nt(ct)-nt(dt)));return n.bind(t.pushClip(Zd(No(7)(y)))(ns))(()=>n.bind(i(dt=>{const ht=dt._1,Lt=Ee(1.4)(1.9)(K+(1303*(ht+1|0)|0)|0),Bt=Ee(.35)(.8)(Lt.prng),zt=i(ne=>n.bind(t.pushAlpha(ne.alpha*Bt.value))(()=>n.bind(t.strokePath(ul(yt(ht))(ne.path))({color:pt,width:Lt.value,lineJoin:Ve,lineCap:Vn}))(()=>r)))(mi({...cl,rMax:0,offset:.5})(K+(53*(ht+1|0)|0)|0)(!1)([dt._2.from,dt._2.to]));return yt(ht)>0?zt:o.pure()})(Ht(Rn)(mt)))(()=>s))})}return o.pure()})())(()=>n.bind((()=>{if(l==="LabelsShown"){const G=n.bind(t.pushAlpha(m))(()=>n.bind(i(Q=>t.drawText({x:y.x+y.w/2,y:R+nt(Q._1)*M,content:Q._2,font:S,color:h.text,align:Gr,baseline:En}))(Ht(Rn)(B)))(()=>r));return m>0?G:o.pure()}if(l==="LabelsHidden")return o.pure();g()})())(()=>n.bind((()=>{const G=_(h)(F)(A);return j?G:o.pure()})())(()=>n.bind(d)(()=>r)))))}));return z.alpha*p>0?D:o.pure()}},K3=t=>{const e=$3(t),n=U3(t);return r=>{if(r.geometry.tag==="FlatNode"&&r.plan.tag==="FlatNodePlan"){const o={x:r.geometry._1.bounds.x,y:r.geometry._1.bounds.y,w:r.geometry._1.bounds.w,h:r.geometry._1.bounds.h,label:r.plan._1.label,shape:r.geometry._1.shape};if(r.role==="NodeShadow")return e(r.plan._1.palette)(r.plan._1.inkBoost>0)(o)(r.plan._1.animState);if(r.role==="NodeBody"||r.role==="NodeInversion")return n(jc)(r.plan._1.inkBoost)(r.plan._1.palette)(r.alpha)(0)(r.plan._1.arrival)(r.id)(o)(r.plan._1.animState);g()}return t.Monad0().Applicative0().pure()}},Jl=t=>e=>n=>{const r=o=>{const i=re(s=>o.x>=s._2.x-1&&o.x<=s._2.x+s._2.w+1&&o.y>=s._2.y-1&&o.y<=s._2.y+s._2.h+1)(Ze(e.nodes));return i.tag==="Just"?N("Just",i._1._2):J};return Ar(o=>{const i=Rr(o._1)(n.edges);if(i.tag==="Just"){const s=Rr(o._1)(n.edgeFadeAlpha),a=(()=>{if(s.tag==="Nothing")return 1;if(s.tag==="Just")return s._1;g()})(),u=Kd({id:o._1,geometry:Ad("FlatRoute",(()=>{const c=(()=>{if(0<o._2.length){const d=r(o._2[0]);if(d.tag==="Just")return se(rl(No(7)(d._1))(se(o._2)))}return o._2})(),_=c.length-1|0;if(_>=0&&_<c.length){const d=r(c[_]);if(d.tag==="Just")return rl(No(7)(d._1))(c)}return c})()),visible:AT(i._1),arrow:(()=>{const c=ao("conn:")(o._1);if(c.tag==="Just")return!1;if(c.tag==="Nothing")return!0;g()})(),settlingAtTarget:i._1.tag==="Extending"&&i._1._1==="ExtendFromSource",plan:Id("FlatEdgePlan",t)});return a===1?u:je({path:[],role:dn,layer:J,effects:[be("GroupAlpha",a)]})(u)}if(i.tag==="Nothing")return tt(ut("Return",void 0),_t);g()})(Ze(e.edges))},Y3=t=>e=>n=>{const r={family:t.fontFamily,size:11,weight:500};return Ar(o=>{if(o._2===""||(()=>{const a=Rr(o._1)(n.edges);return a.tag==="Nothing"||!(a.tag==="Just"&&dy.eq(a._1)(xf))})())return tt(ut("Return",void 0),_t);const i=Rr(o._1)(e.edges),s=(()=>{if(i.tag==="Just")return go(i._1)(.5);if(i.tag==="Nothing")return J;g()})();if(s.tag==="Nothing")return tt(ut("Return",void 0),_t);if(s.tag==="Just"){const a=s._1,u=ts(r)(o._2),c=_=>{const d=_+12;return ss({owner:wo("EdgeText",o._1),text:o._2,spec:{x:a.x,y:a.y,content:o._2,font:r,color:t.chipPillText,align:Gr,baseline:En},bounds:N("Just",{x:a.x-d/2,y:a.y-8.5,w:d,h:17}),plan:is("RoundedText",{radius:3,fill:N("Just",{color:t.chipPillFill,flat:!0}),stroke:J})})};return tt(u._1,(()=>{if(u._2.tag==="CatNil")return at("CatCons",c,st($,$));if(u._2.tag==="CatCons")return at("CatCons",u._2._1,st(u._2._2._1,kt("Cons",at("CatCons",c,st($,$)),u._2._2._2)));g()})())}g()})(Ze(e.edgeLabels))},Nl=t=>{const e=n=>{if(n.tag==="Leaf")return I;if(n.tag==="Node")return te("Node",n._1,n._2,n._3,ig({x:t.vx,y:t.vy,w:t.vw,h:t.vh})(n._4),e(n._5),e(n._6));g()};return e},X3=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=Co(r);return i=>s=>a=>u=>c=>_=>{const d=Yo(_).length,l=nt(d+1|0),f=m=>{const w=(a*l-nt(m))/1.5,x=w<0?0:w>1?1:w;return x*x*(3-2*x)},h=(m=>{let w=m,x=!0,y;for(;x;){const T=w;if(T>=d){x=!1,y=T;continue}if(f(T)>=1){w=T+1|0;continue}x=!1,y=T}return y})(0),p=h>=d?[]:tr(m=>f(m)>0)(Xt(h,d-1|0)).init;return n.bind((()=>{const m=t.drawText({x:u,y:c,content:Re(h)(_),font:i,color:s,align:_i,baseline:En});return h>0?m:r.pure()})())(()=>o(m=>n.bind(t.measureText(i)(Re(m)(_)))(w=>{const x=f(m);return t.drawText({x:u+w,y:c-(1-x)*10,content:Re(1)($o(or(Re(m)(_)))(_)),font:i,color:{...s,a:fe(An(x*nt(s.a)))},align:_i,baseline:En})}))(p))}},vl=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),o=Co(r),i=X3(t);return s=>{if(s.plan.tag==="PlainText")return t.drawText(s.spec);if(s.plan.tag==="RoundedText")return n.bind((()=>{const a=r.pure();if(s.bounds.tag==="Nothing")return a;if(s.bounds.tag==="Just")return t.drawRoundedRect(s.bounds._1)(s.plan._1.radius)(s.plan._1.fill)(s.plan._1.stroke);g()})())(()=>t.drawText(s.spec));if(s.plan.tag==="TokenTravelText"){const a=s.plan._1;return n.bind(o(u=>t.fillPath(nl(u)(1.5))(a.trailFill))(a.trail))(()=>n.bind((()=>{const u=r.pure();if(s.bounds.tag==="Nothing")return u;if(s.bounds.tag==="Just")return t.drawRoundedRect(s.bounds._1)(a.radius)(N("Just",a.fill))(J);g()})())(()=>i(s.spec.font)(s.spec.color)(a.reveal)(a.textLeft)(s.spec.y)(s.text)))}if(s.plan.tag==="TokenFillingText"){const a=s.plan._1;return n.bind(t.drawRoundedRect(a.shadow)(a.radius)(N("Just",a.shadowFill))(J))(()=>n.bind((()=>{const u=r.pure();if(s.bounds.tag==="Nothing")return u;if(s.bounds.tag==="Just")return t.drawRoundedRect(s.bounds._1)(a.radius)(N("Just",a.fill))(N("Just",a.stroke));g()})())(()=>n.bind(t.strokePath(a.leader)(a.stroke))(()=>t.drawText(s.spec))))}if(s.plan.tag==="AffineText")return t.drawTextAffine(s.plan._1)(s.spec);g()}},j3=t=>e=>n=>r=>o=>i=>s=>hl(r)(o)(i)({owner:wo("TokenText",t),text:n.line,spec:{x:o.x,y:o.y,content:n.line,font:{family:e.fontFamily,size:11,weight:500},color:e.chipPillText,align:_i,baseline:En},bounds:N("Just",r),plan:is("TokenTravelText",{trail:z3(r)(s),trailFill:{color:e.trailDot,flat:!0},radius:3,fill:{color:e.chipPillFill,flat:!0},textLeft:r.x+14,reveal:(()=>{const a=n.phaseInLabel/.45;return a<0?0:a>1?1:a})()})}),Ca=t=>e=>n=>r=>{const o=q(f=>nt(Ta(1)(Yo(f).length)))(r),i=dr(1)(v(er)(0)(o)),s=li(e)(n)(t),a=s*i,u=Ta(1)(r.length),c=(f=>h=>p=>{let m=f,w=h,x=p,y=!0,T;for(;y;){const C=m,S=w,E=Ft(B=>J,B=>M=>N("Just",{head:B,tail:M}),x);if(E.tag==="Nothing"){y=!1,T=Ta(0)(u-1|0);continue}if(E.tag==="Just"){if(S+E._1.head>=a){y=!1,T=C;continue}m=C+1|0,w=S+E._1.head,x=E._1.tail;continue}g()}return T})(0)(0)(o),_=v(er)(0)(c<1?[]:Rt(0,c,o)),d=_/i;if(c>=0&&c<o.length){const f=(_+o[c])/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(f<=d)return 1;const h=(s-d)/(f-d);return h<0?0:h>1?1:h})()}}const l=(_+1)/i;return{line:c>=0&&c<r.length?r[c]:"",phaseInLabel:(()=>{if(l<=d)return 1;const f=(s-d)/(l-d);return f<0?0:f>1?1:f})()}},Tl=t=>e=>n=>r=>o=>t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Ca(r)(0)(0)(q(Ci)(o)).line))(i=>{const s=i+28;return t.Applicative0().pure({x:n.x+n.w/2-s/2,y:n.y-25.2-14,w:s,h:25.2})}),Z3=t=>{const e=t.Bind1(),n=t.Applicative0(),r=oo.traverse(n);return o=>i=>s=>e.Apply0().Functor0().map(a=>fl(vt(u=>u)(a)))(r(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const u=Pe(a._2._1.node)(i.nodes);if(u.tag==="Just")return e.bind(Tl(t)(o)(u._1)(a._2._1.progress)(a._2._1.labels))(c=>n.pure(N("Just",b(a._1,c))));if(u.tag==="Nothing")return n.pure(J);g()}return n.pure(J)})(Ze(s.tokens)))},tC=t=>e=>n=>r=>o=>i=>s=>a=>u=>{const c=ug(n)(r)(o)(i)(s)(a);return t.Bind1().bind(e({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Ca(i)(s)(a)(Et(u)(_g)).line))(_=>t.Applicative0().pure({x:c.x+14+_/2-_/2-14,y:c.y-6-8-6.6-6,w:_+28,h:25.2}))},eC=t=>{const e=t.Bind1(),n=t.Applicative0(),r=oo.traverse(n);return o=>i=>s=>e.Apply0().Functor0().map(a=>fl(vt(u=>u)(a)))(r(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const u=Pe(a._2._1.target)(i.nodes),c=Pe(a._2._1.source)(i.nodes),_=Rr(a._2._1.edge)(i.edges);if(_.tag==="Just"&&c.tag==="Just"&&u.tag==="Just"){const d=(()=>{if(a._2._1.direction==="Forward")return _._1;if(a._2._1.direction==="Backward")return se(_._1);g()})(),l=ug(d)(c._1)(u._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);return e.bind(tC(t)(o)(d)(c._1)(u._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(f=>n.pure(N("Just",b(a._1,{id:a._1,rect:f,token:l}))))}}return n.pure(J)})(Ze(s.tokens)))},lg=t=>{const e=t.Bind1(),n=eC(t),r=Z3(t);return o=>i=>s=>a=>e.bind(n(o)(s)(a))(u=>e.bind(r(o)(s)(a))(c=>t.Applicative0().pure(J3({x:i.vx,y:i.vy,w:i.vw,h:i.vh})([...vt(_=>{const d=Pe(_._1)(a.nodes);return d.tag==="Just"&&hi(d._1).alpha>0?N("Just",{x:_._2.x,y:_._2.y,w:_._2.w,h:_._2.h}):J})(Ze(s.nodes)),...(()=>{const _=(d,l)=>{if(d.tag==="Leaf")return l;if(d.tag==="Node")return _(d._5,kt("Cons",d._4,_(d._6,l)));g()};return Zt(de.foldr,_(c,$))})()])(vt(_=>dl(_)(u))((()=>{const _=d=>{if(d.tag==="Leaf")return I;if(d.tag==="Node")return te("Node",d._1,d._2,d._3,void 0,_(d._5),_(d._6));g()};return Pt(P.compare)(Zt(fn.foldr,_(u)))})())))))},nC=lg(Rc),Cl=t=>e=>n=>{const r=Ri(6)(.55)(va(0)(1)((1-t)/.06)),o=t>.94,i=o&&n>1e-4,s=Ri(6)(.55)(va(0)(1)(t/.06)),a=t<.06,u=a&&e>1e-4,c=o&&n<=1e-4;return{popScale:u?s:i?r:1,flipY:a&&e<=1e-4?s:c?r:1,fadeAlpha:(()=>{if(u){const _=t/.06;return _<0?.55:_>1?1:.55+.44999999999999996*_}if(i){const _=(1-t)/.06;return _<0?.55:_>1?1:.55+.44999999999999996*_}return 1})()}},ba=t=>e=>n=>r=>je({path:[],role:dn,layer:N("Just",tT),effects:[]})(Ar(o=>{if(o._2.tag==="Travelling"){if(o._2._1.labels.length!==0){const i=Pe(o._2._1.target)(e.nodes),s=Pe(o._2._1.source)(e.nodes),a=Rr(o._2._1.edge)(e.edges),u=dl(o._1)(r);if(u.tag==="Just"&&a.tag==="Just"&&s.tag==="Just"&&i.tag==="Just")return j3(o._1)(t)(Ca(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost)(Et(o._2._1.labels)(_g)))(u._1)({x:u._1.x+u._1.w/2,y:u._1.y+u._1.h/2})(Cl(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost))(ug((()=>{if(o._2._1.direction==="Forward")return a._1;if(o._2._1.direction==="Backward")return se(a._1);g()})())(s._1)(i._1)(o._2._1.progress)(o._2._1.holdPre)(o._2._1.holdPost))}return tt(ut("Return",void 0),_t)}if(o._2.tag==="Filling"&&o._2._1.labels.length!==0){const i=Pe(o._2._1.node)(e.nodes);if(i.tag==="Just"){const s=i._1,a=Tl(Rc)(Vd)(s)(o._2._1.progress)(o._2._1.labels),u=c=>O3(o._1)(t)(Ca(o._2._1.progress)(0)(0)(Et(o._2._1.labels)(_g)).line)(s)(c)({x:c.x+c.w/2,y:c.y+c.h/2})(Cl(o._2._1.progress)(0)(0));return tt(a._1,(()=>{if(a._2.tag==="CatNil")return at("CatCons",u,st($,$));if(a._2.tag==="CatCons")return at("CatCons",a._2._1,st(a._2._2._1,kt("Cons",at("CatCons",u,st($,$)),a._2._2._2)));g()})())}if(i.tag==="Nothing")return tt(ut("Return",void 0),_t);g()}return tt(ut("Return",void 0),_t)})(Ze(n.tokens))),bl=t=>e=>n=>r=>{const o=nC(Vd)(e)(n)(r);return tt(o._1,(()=>{if(o._2.tag==="CatNil")return at("CatCons",i=>ba(t)(n)(r)(i),st($,$));if(o._2.tag==="CatCons")return at("CatCons",o._2._1,st(o._2._2._1,kt("Cons",at("CatCons",i=>ba(t)(n)(r)(i),st($,$)),o._2._2._2)));g()})())},rC=t=>{const e=t.Monad0(),n=e.Applicative0();return r=>o=>{const i=o.length-1|0,s=i<1?[]:Rt(0,i,o),a=s.length-1|0,u=a>=0&&a<s.length?N("Just",s[a]):J,c=o.length-1|0,_=c>=0&&c<o.length?N("Just",o[c]):J;if(_.tag==="Just"&&u.tag==="Just"){const d=Ee(.78)(1.18)(us(o)+19|0),l=Ee(.4)(.62)(d.prng),f=r.wobble?8.75*l.value:4.375,h=Ee(.4)(.62)(l.prng),p=r.wobble?8.75*h.value:4.375,m=_._1.y-u._1.y,w=_._1.x-u._1.x,x=$e(w*w+m*m),y=m/x,T=-y,C=w/x,S=_._1.x+C*.875,E=_._1.y+y*.875,B=r.wobble?8.75*d.value:8.75,M=S-C*B,Y=E-y*B,R=M+T*f,A=Y+C*f,j=[1,S,E,2,M+T*4.375,Y+C*4.375,2,M-T*4.375,Y-C*4.375,5],Z=M-T*p,z=Y-C*p,W={color:r.arrowFill,width:2,lineJoin:Ve,lineCap:Vn};return x<=1e-4?n.pure():r.wobble?e.Bind1().bind(t.strokePath([1,R,A,2,S,E])(W))(()=>t.strokePath([1,Z,z,2,S,E])(W)):t.fillPath(j)({color:r.arrowFill,flat:!0})}return n.pure()}},oC=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),o=Co(n),i=t.popAlpha,s=rC(t);return a=>u=>c=>_=>d=>{const l=r3(8)(_),f=c&&d.hi>=.9&&(1-d.hi)*Bi(l)<=8.75?1:d.hi;if(f<=d.lo)return n.pure();const h=_3(l)(d.lo)(f);if(h.length===0)return n.pure();const p={color:a.edge,width:a.wobble?2:.9375,lineJoin:Ve,lineCap:Vn},m=a.wobble?Ee(-10)(4)(us(h)).value:0,w=a.wobble?S3(m)(h):h;return r.bind(a.wobble?o(x=>r.bind(t.pushAlpha(x.alpha))(()=>r.bind(t.strokePath(x.path)(p))(()=>i)))((()=>{const x=us(h);return w.length<2?[]:mi(q3)(x)(!1)(w)})()):t.strokePath(t3(h))(p))(()=>{const x=s(a)(w);return u&&f>=.999?x:n.pure()})}},iC=t=>{const e=oC(t);return n=>n.geometry.tag==="FlatRoute"&&n.plan.tag==="FlatEdgePlan"?e(n.plan._1)(n.arrow)(n.settlingAtTarget)(n.geometry._1)(n.visible):t.Monad0().Applicative0().pure()},sC=t=>e=>{const n=i=>{const s=Pe(i)(t.nodes);if(s.tag==="Nothing")return!1;if(s.tag==="Just"){const a=s._1;return!Ne(u=>0<u._2.length&&u._2[0].x>=a.x&&u._2[0].x<=a.x+a.w&&u._2[0].y>=a.y&&u._2[0].y<=a.y+a.h,Ze(t.edges))}g()},r=v(i=>s=>(i*31|0)+Ur(s)|0)(5381)(vr(e.frameTitle)),o=i=>{const s=Pe(i)(t.nodes);if(s.tag==="Nothing")return!1;if(s.tag==="Just"){const a=s._1;return!Ne(u=>{const c=u._2.length-1|0;return c>=0&&c<u._2.length&&u._2[c].x>=a.x&&u._2[c].x<=a.x+a.w&&u._2[c].y>=a.y&&u._2[c].y<=a.y+a.h},Ze(t.edges))}g()};return v(i=>s=>{const a=s._2;return A3(u=>{if(u.tag==="Nothing")return N("Just",a);if(u.tag==="Just")return N("Just",{t:dr(u._1.t)(a.t),angle:a.t>=u._1.t?a.angle:u._1.angle,bigCircle:u._1.bigCircle||a.bigCircle,frameHash:u._1.frameHash});g()})(s._1)(i)})(I)(Et(Ze(e.tokens))(i=>{if(i._2.tag==="Filling"){const s=i._2._1.node;return[b(s,{t:1,angle:(()=>{const a=vt(u=>(()=>{const c=Pe(s)(t.nodes),_=u._2.length-1|0;return _>=0&&_<u._2.length&&c.tag==="Just"&&u._2[_].x>=c._1.x&&u._2[_].x<=c._1.x+c._1.w&&u._2[_].y>=c._1.y&&u._2[_].y<=c._1.y+c._1.h})()?N("Just",u._2):J)(Ze(t.edges));if(0<a.length){const u=a[0].length-1|0,c=u<1?[]:Rt(0,u,a[0]),_=c.length-1|0;if(_>=0&&_<c.length){const d=a[0].length-1|0;return d>=0&&d<a[0].length?so(a[0][d].y-c[_].y)(a[0][d].x-c[_].x):0}a[0].length-1|0}return 0})(),bigCircle:n(s)||o(s),frameHash:r})]}if(i._2.tag==="Travelling"){if(i._2._1.progress>=.75)return[b(i._2._1.target,{t:(i._2._1.progress-.75)/.25,angle:(()=>{const s=Rr(i._2._1.edge)(t.edges);if(s.tag==="Just"){const a=s._1.length-1|0,u=a<1?[]:Rt(0,a,s._1),c=u.length-1|0;if(c>=0&&c<u.length){const _=s._1.length-1|0;return _>=0&&_<s._1.length?so(s._1[_].y-u[c].y)(s._1[_].x-u[c].x):0}return s._1.length-1|0,0}if(s.tag==="Nothing")return 0;g()})(),bigCircle:n(i._2._1.target)||o(i._2._1.target),frameHash:r})];if(i._2._1.progress<.25)return[b(i._2._1.source,{t:i._2._1.progress/.25,angle:(()=>{const s=Rr(i._2._1.edge)(t.edges);if(s.tag==="Just")return 1<s._1.length&&0<s._1.length?so(s._1[1].y-s._1[0].y)(s._1[1].x-s._1[0].x):0;if(s.tag==="Nothing")return 0;g()})(),bigCircle:n(i._2._1.source)||o(i._2._1.source),frameHash:r})]}return[]}))},aC=t=>v(e=>n=>(e*31|0)+Ur(n)|0)(5381)(vr(t.frameTitle)),kl=t=>e=>n=>r=>o=>{const i=aC(o),s=sC(r)(o);return Ar(a=>{const u=Pe(a._1)(o.nodes);if(u.tag==="Just")return pl($d)(t)(e)(n)((()=>{const c=Pe(a._1)(o.nodeFadeAlpha);if(c.tag==="Nothing")return 1;if(c.tag==="Just")return c._1;g()})())((()=>{const c=Pe(a._1)(o.nodeLabelFadeAlpha);if(c.tag==="Nothing")return 1;if(c.tag==="Just")return c._1;g()})())((()=>{const c=Pe(a._1)(s);return c.tag==="Just"?N("Just",c._1):c.tag==="Nothing"&&I3(a._1)(o.visited)?N("Just",{t:1,angle:0,bigCircle:!1,frameHash:i}):J})())(a._1)(a._2)(u._1);if(u.tag==="Nothing")return tt(ut("Return",void 0),_t);g()})(Ze(r.nodes))},uC=t=>t,Sl=t=>e=>{const n=e.vw/e.vh,r=e.vh*t,o={...e,vx:e.vx-(r-e.vw)/2,vw:r},i=e.vw/t,s={...e,vy:e.vy-(i-e.vh)/2,vh:i};return t<=0||e.vw<=0||e.vh<=0?e:t>n?o:t<n?s:e},Ll=t=>e=>t.width<=0||t.height<=0?e:Sl(t.width/t.height)(e),cC=t=>e=>n=>{const r=it.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=it.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},El=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Gl=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},hg=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},gC=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},_C=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},pg=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),fC=Qr(xo)(Mt),dC=t=>e=>{const n=pn(t.angle),r=Sn(t.angle);return{a:r,b:n,c:0,d:1,e:-e*r,f:e*n-t.boxHeight/2}},lC=t=>[t.box.ground.a,t.box.ground.b,t.box.ground.c,t.box.ground.d,t.box.top.a,t.box.top.b,t.box.top.c,t.box.top.d],mg=t=>e=>{const n=r=>cC(0)(255)(fe(Hn(nt(r)*t)));return{r:n(e.r),g:n(e.g),b:n(e.b),a:e.a}},Ue=t=>e=>n=>r=>({x:(e-n)*Sn(t.angle),y:(e+n)*pn(t.angle)-r}),yg=t=>{const e=Ft(n=>J,n=>r=>N("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Et(e._1.tail)(n=>[2,n.x,n.y]),5];g()},hC=t=>e=>n=>{const r=n.id,o=n.np,i=Zc({id:r,role:$d,geometry:Uc("IsoSlab",{south:[n.box.ground.d,n.box.ground.c,n.box.top.c,n.box.top.d],east:[n.box.ground.b,n.box.ground.c,n.box.top.c,n.box.top.b],top:[n.box.top.a,n.box.top.b,n.box.top.c,n.box.top.d]}),alpha:1,plan:Kc("IsoNodePlan",{config:t,palette:e})}),s=()=>ss({owner:wo("NodeText",r),text:o.label,spec:{x:o.x+o.w/2,y:0,content:o.label,font:{family:e.fontFamily,size:11,weight:600},color:e.text,align:Gr,baseline:En},bounds:J,plan:is("AffineText",dC(t)(o.y+o.h))});return tt(i._1,(()=>{if(i._2.tag==="CatNil")return at("CatCons",s,st($,$));if(i._2.tag==="CatCons")return at("CatCons",i._2._1,st(i._2._2._1,kt("Cons",at("CatCons",s,st($,$)),i._2._2._2)));g()})())},pC=t=>e=>n=>r=>o=>{const i=Fe(Rn,o,Rt(1,o.length,o)),s=i.length-1|0;return Ht(a=>u=>({depth:(u._1.x+u._1.y+u._2.x+u._2.y)/2,draw:Kd({id:n,geometry:Ad("IsoSegments",[[Ue(t)(u._1.x)(u._1.y)(0),Ue(t)(u._2.x)(u._2.y)(0)]]),visible:{lo:0,hi:1},arrow:r&&a===s,settlingAtTarget:!1,plan:Id("IsoEdgePlan",{config:t,palette:e})})}))(i)},mC=t=>e=>n=>r=>o=>{const i=(()=>{if(t==="Forward")return o;if(t==="Backward")return se(o);g()})();if(0<i.length){const a=go(i)(El(0)(1)(li(n)(r)(e)));if(a.tag==="Nothing")return i[0];if(a.tag==="Just")return a._1;g()}const s=go(i)(El(0)(1)(li(n)(r)(e)));if(s.tag==="Nothing")return{x:0,y:0};if(s.tag==="Just")return s._1;g()},yC=t=>{const e=Ft(n=>J,n=>r=>N("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...Et(e._1.tail)(n=>[2,n.x,n.y])];g()},xC=t=>{const e=Ft(n=>J,n=>r=>N("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{vx:0,vy:0,vw:0,vh:0};if(e.tag==="Just"){const n=v(r=>o=>({minX:Gl(r.minX)(o.x),minY:Gl(r.minY)(o.y),maxX:hg(r.maxX)(o.x),maxY:hg(r.maxY)(o.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{vx:n.minX-40,vy:n.minY-40,vw:n.maxX-n.minX+80,vh:n.maxY-n.minY+80}}g()},wC=t=>{const e=t.Monad0(),n=e.Bind1();return r=>{if(r.geometry.tag==="IsoSlab"&&r.plan.tag==="IsoNodePlan"){const o=r.geometry._1,i=r.plan._1.palette,s=(a,u)=>t.fillStrokePath(yg(a))({color:u,flat:!0})({color:i.nodeStroke,width:1,lineJoin:Ve,lineCap:Gn});return n.bind(s(o.south,mg(.66)(i.nodeFill)))(()=>n.bind(s(o.east,mg(.82)(i.nodeFill)))(()=>s(o.top,i.nodeFill)))}return e.Applicative0().pure()}},JC=t=>{const e=t.Monad0(),n=e.Bind1();return r=>{if(r.geometry.tag==="IsoCube"&&r.plan.tag==="IsoTokenPlan"){const o=r.geometry._1,i=r.plan._1.palette,s=(a,u)=>t.fillStrokePath(yg(a))({color:mg(u)(i.tokenOutsideFill),flat:!0})({color:i.tokenOutsideStroke,width:1,lineJoin:Ve,lineCap:Gn});return n.bind(s(o.south,.66))(()=>n.bind(s(o.east,.82))(()=>s(o.top,1)))}return e.Applicative0().pure()}},NC={angle:.5235987755982988,boxHeight:26,transparentBg:!0},vC=t=>e=>n=>{const r=n.x-5.5,o=n.x+5.5,i=n.y-5.5,s=n.y+5.5,a=e+11,u=Ue(t)(o)(i)(a),c=Ue(t)(o)(s)(a),_=Ue(t)(r)(s)(a),d=Ue(t)(o)(s)(e);return{south:[Ue(t)(r)(s)(e),d,c,_],east:[Ue(t)(o)(i)(e),d,c,u],top:[Ue(t)(r)(i)(a),u,c,_]}},TC=t=>e=>n=>r=>{const o=r._1,i=(s,a)=>({depth:a.x+a.y,draw:Yd({id:o,pass:Od,geometry:Qd("IsoCube",vC(t)(s)(a)),position:a,plan:Md("IsoTokenPlan",{config:t,palette:e,baseZ:s})})});if(r._2.tag==="Travelling"){const s=gC(r._2._1.edge)(n.edges);return s.tag==="Just"?N("Just",i(0,mC(r._2._1.direction)(r._2._1.progress)(r._2._1.holdPre)(r._2._1.holdPost)(s._1))):J}if(r._2.tag==="Filling"){const s=_C(r._2._1.node)(n.nodes);if(s.tag==="Just")return N("Just",i(t.boxHeight,{x:s._1.x+s._1.w/2,y:s._1.y+s._1.h/2}))}return J},CC=t=>e=>{const n=e.y+e.h,r=e.x+e.w;return{ground:{a:Ue(t)(e.x)(e.y)(0),b:Ue(t)(r)(e.y)(0),c:Ue(t)(r)(n)(0),d:Ue(t)(e.x)(n)(0)},top:{a:Ue(t)(e.x)(e.y)(t.boxHeight),b:Ue(t)(r)(e.y)(t.boxHeight),c:Ue(t)(r)(n)(t.boxHeight),d:Ue(t)(e.x)(n)(t.boxHeight)},depth:(e.x+r)/2+(e.y+n)/2}},Pl=t=>e=>q(n=>({id:n._1,np:n._2,box:CC(t)(n._2)}))(pg(e.nodes)),bC=t=>e=>[...Et(Pl(t)(e))(lC),...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,kt("Cons",r._4,n(r._6,o)));g()};return Et(Zt(de.foldr,n(e.edges,$)))(q(r=>Ue(t)(r.x)(r.y)(0)))})()],kC=t=>e=>n=>r=>{const o=cg(e),i=[...Et(pg(n.edges))(u=>pC(t)(o)(u._1)((()=>{const c=ao("conn:")(u._1);if(c.tag==="Just")return!1;if(c.tag==="Nothing")return!0;g()})())(u._2)),...q(u=>({depth:u.box.depth,draw:hC(t)(o)(u)}))(Pl(t)(n)),...vt(TC(t)(o)(n))(pg(r.tokens))],s=Ud({viewport:xC(bC(t)(n)),clear:N("Just",t.transparentBg?o.bgTransparent:o.bg),dots:J}),a=()=>fC(u=>u.draw)(Pt(u=>c=>ot.compare(u.depth)(c.depth))(i));return tt(s._1,(()=>{if(s._2.tag==="CatNil")return at("CatCons",a,st($,$));if(s._2.tag==="CatCons")return at("CatCons",s._2._1,st(s._2._2._1,kt("Cons",at("CatCons",a,st($,$)),s._2._2._2)));g()})())},SC=t=>{const e=t.to.y-t.from.y,n=t.to.x-t.from.x,r=hg(1e-4)($e(n*n+e*e)),o=e/r,i=n/r,s=t.to.y-o*7,a=t.to.x-i*7;return yg([t.to,{x:a-o*3,y:s+i*3},{x:a+o*3,y:s-i*3}])},LC=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Qr(n)(Mt);return o=>{if(o.geometry.tag==="IsoSegments"&&o.plan.tag==="IsoEdgePlan"){const i=o.plan._1.palette,s=o.geometry._1;return e.Bind1().bind(r(a=>t.strokePath(yC(a))({color:i.edge,width:1.5,lineJoin:Ve,lineCap:Vn}))(s))(()=>{const a=s.length-1|0;if(a>=0&&a<s.length){const c=s[a],_=c.length-1|0,d=_<1?[]:Rt(0,_,c),l=d.length-1|0;if(l>=0&&l<d.length){const h=s.length-1|0,p=(()=>{if(h>=0&&h<s.length){const m=s[h],w=m.length-1|0;if(w>=0&&w<m.length)return t.fillPath(SC({from:d[l],to:m[w]}))({color:i.arrowFill,flat:!0})}return n.pure()})();return o.arrow?p:n.pure()}s.length-1|0;const f=n.pure();return o.arrow?f:n.pure()}s.length-1|0;const u=n.pure();return o.arrow?u:n.pure()})}return n.pure()}},Bl=(t,e)=>({tag:t,_1:e}),ka=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},EC=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},xg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},GC=Io(xo)(Mt),PC=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},BC=Bl("ResolvedLabels"),DC=t=>{const e=re(n=>n.role==="FlyThrough")(t.levels);if(e.tag==="Just")return e._1;if(e.tag==="Nothing")return Os(t);g()},yi=t=>e=>{const n=ka(1)(he(e.rootLayout).w),r=_o(e.rootLayout)(e.camera),o=!e.diving&&e.levels.length===1?1:EC(0)(1)(r.w/n),i=Os(e).state.frameTitle===""?0*o:40*o,s=t.padding*o*o;return(()=>{if(t.outputAspect.tag==="Nothing")return uC;if(t.outputAspect.tag==="Just")return Sl(t.outputAspect._1);g()})()({vx:r.x-s,vy:r.y-s-i,vw:r.w+2*s,vh:r.h+2*s+i})},RC=t=>e=>{if(e.tag==="Nothing")return[];if(e.tag==="Just"){const n=xg(e._1)(t.segment.layout.nodes);if(n.tag==="Nothing")return[];if(n.tag==="Just"){const r=n._1.x*t.segment.placement.scale+t.segment.placement.tx,o=n._1.y*t.segment.placement.scale+t.segment.placement.ty,i=n._1.w*t.segment.placement.scale,s=n._1.h*t.segment.placement.scale;return[1,r,o,2,r+i,o,2,r+i,o+s,2,r,o+s,5]}}g()},wg=t=>e=>{const n=Ym(e.segment.placement)({x:t.vx,y:t.vy,w:t.vw,h:t.vh});return{vx:n.x,vy:n.y,vw:n.w,vh:n.h}},Dl=t=>e=>t===""?tt(ut("Return",void 0),_t):ss({owner:VT,text:t,spec:{x:e.vx+6,y:e.vy+6,content:t,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:_i,baseline:Kv},bounds:J,plan:ma}),Rl=t=>e=>{if(t==="")return tt(ut("Return",void 0),_t);const n=e.vh/720,r=56*n,o=ts({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:56,weight:700})(t),i=s=>{const a=r+16*n*2,u=s*n+28*n*2,c=e.vy+e.vh/2,_=e.vx+e.vw/2,d={x:_-u/2,y:c-a/2,w:u,h:a};return ya(pa("TitleCardOverlay",{backing:{path:di(d)(16*n),fill:N("Just",{color:{r:255,g:255,b:255,a:235},flat:!0}),stroke:N("Just",{color:{r:0,g:0,b:0,a:255},width:1.5*n,lineJoin:Ve,lineCap:Vn})},text:{owner:Hd,text:t,spec:{x:_,y:c,content:t,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:r,weight:700},color:{r:28,g:30,b:36,a:255},align:Gr,baseline:En},bounds:N("Just",d),plan:ma}}))};return tt(o._1,(()=>{if(o._2.tag==="CatNil")return at("CatCons",i,st($,$));if(o._2.tag==="CatCons")return at("CatCons",o._2._1,st(o._2._2._1,kt("Cons",at("CatCons",i,st($,$)),o._2._2._2)));g()})())},Al=t=>e=>{if(t==="")return tt(ut("Return",void 0),_t);const n=e.vh/720,r=15*n,o=ts({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:15,weight:600})(t),i=s=>{const a=e.vy+12*n,u=r+6*n*2,c=s*n+11*n*2,_=e.vx+e.vw/2,d={x:_-c/2,y:a,w:c,h:u};return ya(pa("FrameTitleOverlay",{backing:N("Just",{path:di(d)(u/2),fill:N("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}),stroke:N("Just",{color:{r:0,g:0,b:0,a:255},width:1*n,lineJoin:Ve,lineCap:Vn})}),text:{owner:Hd,text:t,spec:{x:_,y:a+u/2,content:t,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:r,weight:600},color:{r:28,g:30,b:36,a:255},align:Gr,baseline:En},bounds:N("Just",d),plan:ma}}))};return tt(o._1,(()=>{if(o._2.tag==="CatNil")return at("CatCons",i,st($,$));if(o._2.tag==="CatCons")return at("CatCons",o._2._1,st(o._2._2._1,kt("Cons",at("CatCons",i,st($,$)),o._2._2._2)));g()})())},AC=t=>e=>n=>r=>o=>i=>s=>a=>{const u=cg(t.theme),c=(()=>{if(a.tag==="ResolvedLabels")return bl(u)(o)(i)(s);if(a.tag==="SpringLabels")return ba(u)(i)(s)(Nl(o)(a._1));g()})(),_=Ud({viewport:o,clear:N("Just",t.transparentBg?u.bgTransparent:u.bg),dots:J}),d=()=>{const l=je({path:[],role:dn,layer:J,effects:[...n<1?[be("GroupAlpha",n)]:[],...r>0?[be("GroupBlur",r)]:[]]})((()=>{const f=Jl(u)(i)(s),h=()=>{const p=xl(u)(t.halftoneShadows)(i)(s),m=()=>{const w=kl(Xc)(1)(u)(i)(s),x=()=>{const y=wl(u)(i)(s),T=()=>{const C=dg(u)(o)(i)(s),S=()=>{const E=ml(iT)(u)(i)(s),B=()=>{const M=()=>{const Y=Y3(u)(i)(s);return s.staticKind!=="Animated"?Y:tt(ut("Return",void 0),_t)};return tt(c._1,(()=>{if(c._2.tag==="CatNil")return at("CatCons",M,st($,$));if(c._2.tag==="CatCons")return at("CatCons",c._2._1,st(c._2._2._1,kt("Cons",at("CatCons",M,st($,$)),c._2._2._2)));g()})())};return tt(E._1,(()=>{if(E._2.tag==="CatNil")return at("CatCons",B,st($,$));if(E._2.tag==="CatCons")return at("CatCons",E._2._1,st(E._2._2._1,kt("Cons",at("CatCons",B,st($,$)),E._2._2._2)));g()})())};return tt(C._1,(()=>{if(C._2.tag==="CatNil")return at("CatCons",S,st($,$));if(C._2.tag==="CatCons")return at("CatCons",C._2._1,st(C._2._2._1,kt("Cons",at("CatCons",S,st($,$)),C._2._2._2)));g()})())};return tt(y._1,(()=>{if(y._2.tag==="CatNil")return at("CatCons",T,st($,$));if(y._2.tag==="CatCons")return at("CatCons",y._2._1,st(y._2._2._1,kt("Cons",at("CatCons",T,st($,$)),y._2._2._2)));g()})())};return tt(w._1,(()=>{if(w._2.tag==="CatNil")return at("CatCons",x,st($,$));if(w._2.tag==="CatCons")return at("CatCons",w._2._1,st(w._2._2._1,kt("Cons",at("CatCons",x,st($,$)),w._2._2._2)));g()})())};return tt(p._1,(()=>{if(p._2.tag==="CatNil")return at("CatCons",m,st($,$));if(p._2.tag==="CatCons")return at("CatCons",p._2._1,st(p._2._2._1,kt("Cons",at("CatCons",m,st($,$)),p._2._2._2)));g()})())};return tt(f._1,(()=>{if(f._2.tag==="CatNil")return at("CatCons",h,st($,$));if(f._2.tag==="CatCons")return at("CatCons",f._2._1,st(f._2._2._1,kt("Cons",at("CatCons",h,st($,$)),f._2._2._2)));g()})())})());if(n>0){const f=()=>{const h=Dl(t.watermark)(o),p=()=>s.staticKind==="TitleCard"?Rl(s.frameTitle)(o):Al(s.frameTitle)(o);return tt(h._1,(()=>{if(h._2.tag==="CatNil")return at("CatCons",p,st($,$));if(h._2.tag==="CatCons")return at("CatCons",h._2._1,st(h._2._2._1,kt("Cons",at("CatCons",p,st($,$)),h._2._2._2)));g()})())};return tt(l._1,(()=>{if(l._2.tag==="CatNil")return at("CatCons",f,st($,$));if(l._2.tag==="CatCons")return at("CatCons",l._2._1,st(l._2._2._1,kt("Cons",at("CatCons",f,st($,$)),l._2._2._2)));g()})())}return tt(ut("Return",void 0),at("CatCons",()=>{const f=Dl(t.watermark)(o),h=()=>s.staticKind==="TitleCard"?Rl(s.frameTitle)(o):Al(s.frameTitle)(o);return tt(f._1,(()=>{if(f._2.tag==="CatNil")return at("CatCons",h,st($,$));if(f._2.tag==="CatCons")return at("CatCons",f._2._1,st(f._2._2._1,kt("Cons",at("CatCons",h,st($,$)),f._2._2._2)));g()})())},st($,$)))};return tt(_._1,(()=>{if(_._2.tag==="CatNil")return at("CatCons",d,st($,$));if(_._2.tag==="CatCons")return at("CatCons",_._2._1,st(_._2._2._1,kt("Cons",at("CatCons",d,st($,$)),_._2._2._2)));g()})())},Jg=t=>e=>n=>r=>GC(r.minis)(o=>{const i=Il(t)(e)(n)(I)(r)(o);return(()=>{const s=o.segment.path.length-1|0;return o.bgAlpha>0&&s>=0&&s<o.segment.path.length&&(()=>{const a=xg(o.segment.path[s])(r.state.nodes);if(a.tag==="Just")return a._1.tag==="Hidden"?!1:a._1.tag!=="PloppingOut";if(a.tag==="Nothing")return!1;g()})()})()?i:tt(ut("Return",void 0),_t)}),Il=t=>e=>n=>r=>o=>i=>{const s=i.state,a={tx:i.segment.placement.tx,ty:i.segment.placement.ty,sx:i.segment.placement.scale,sy:i.segment.placement.scale},u=cg(t.theme),c=i.segment.layout,_=he(c),d={vx:_.x-1e3,vy:_.y-1e3,vw:_.w+2e3,vh:_.h+2e3},l=i.segment.path.length-1|0,f=l>=0&&l<i.segment.path.length?xg(i.segment.path[l])(o.segment.layout.nodes):J,h=i.segment.placement.scale*n,p=PC(8)(ka(1)(1/(1.25*ka(1e-6)(h)))),m=11*h>=5?Xc:jc,w=wg(e.viewport)(i),x=(()=>{if(m==="LabelsHidden")return tt(ut("Return",void 0),_t);if(m==="LabelsShown")return r.tag==="Leaf"?bl(u)(w)(c)(s):ba(u)(c)(s)(Nl(w)(r));g()})();return je({path:i.segment.path,role:i.role,layer:J,effects:[be("GroupAlpha",i.bgAlpha),...i.blur>0?[be("GroupBlur",i.blur*i.segment.placement.scale)]:[]]})((()=>{const y=je({path:i.segment.path,role:i.role,layer:J,effects:[be("GroupClip",RC(o)((()=>{const C=i.segment.path.length-1|0;return C>=0&&C<i.segment.path.length?N("Just",i.segment.path[C]):J})()),ns)]})((()=>{const C=(()=>{if(f.tag==="Just")return je({path:o.segment.path,role:o.role,layer:J,effects:[be("GroupTransform",pi,{tx:o.segment.placement.tx,ty:o.segment.placement.ty,sx:o.segment.placement.scale,sy:o.segment.placement.scale})]})(ya(pa("FloorOverlay",{path:tg({...f._1,x:f._1.x+1,y:f._1.y+1,w:f._1.w-2,h:f._1.h-2}),fill:N("Just",{color:u.bg,flat:!0}),stroke:J})));if(f.tag==="Nothing")return tt(ut("Return",void 0),_t);g()})(),S=o.role==="Active"||o.role==="FlyThrough"?C:tt(ut("Return",void 0),_t),E=()=>{const B=je({path:i.segment.path,role:i.role,layer:J,effects:[be("GroupTransform",pi,a)]})((()=>{const Y=Jl(u)(c)(s),R=()=>{const A=xl(u)(t.halftoneShadows)(c)(s),j=()=>{const Z=kl(m)(p)(u)(c)(s),z=()=>{const W=wl(u)(c)(s);return tt(W._1,(()=>{if(W._2.tag==="CatNil")return at("CatCons",()=>dg(u)(d)(c)(s),st($,$));if(W._2.tag==="CatCons")return at("CatCons",W._2._1,st(W._2._2._1,kt("Cons",at("CatCons",()=>dg(u)(d)(c)(s),st($,$)),W._2._2._2)));g()})())};return tt(Z._1,(()=>{if(Z._2.tag==="CatNil")return at("CatCons",z,st($,$));if(Z._2.tag==="CatCons")return at("CatCons",Z._2._1,st(Z._2._2._1,kt("Cons",at("CatCons",z,st($,$)),Z._2._2._2)));g()})())};return tt(A._1,(()=>{if(A._2.tag==="CatNil")return at("CatCons",j,st($,$));if(A._2.tag==="CatCons")return at("CatCons",A._2._1,st(A._2._2._1,kt("Cons",at("CatCons",j,st($,$)),A._2._2._2)));g()})())};return tt(Y._1,(()=>{if(Y._2.tag==="CatNil")return at("CatCons",R,st($,$));if(Y._2.tag==="CatCons")return at("CatCons",Y._2._1,st(Y._2._2._1,kt("Cons",at("CatCons",R,st($,$)),Y._2._2._2)));g()})())})()),M=()=>je({path:i.segment.path,role:i.role,layer:J,effects:[be("GroupTransform",$T,a)]})(ml(sT)(u)(c)(s));return tt(B._1,(()=>{if(B._2.tag==="CatNil")return at("CatCons",M,st($,$));if(B._2.tag==="CatCons")return at("CatCons",B._2._1,st(B._2._2._1,kt("Cons",at("CatCons",M,st($,$)),B._2._2._2)));g()})())};return tt(S._1,(()=>{if(S._2.tag==="CatNil")return at("CatCons",E,st($,$));if(S._2.tag==="CatCons")return at("CatCons",S._2._1,st(S._2._2._1,kt("Cons",at("CatCons",E,st($,$)),S._2._2._2)));g()})())})()),T=()=>{const C=je({path:i.segment.path,role:i.role,layer:J,effects:[be("GroupTransform",pi,a)]})(x);return tt(C._1,(()=>{if(C._2.tag==="CatNil")return at("CatCons",()=>Jg(t)(e)(n)(i),st($,$));if(C._2.tag==="CatCons")return at("CatCons",C._2._1,st(C._2._2._1,kt("Cons",at("CatCons",()=>Jg(t)(e)(n)(i),st($,$)),C._2._2._2)));g()})())};return tt(y._1,(()=>{if(y._2.tag==="CatNil")return at("CatCons",T,st($,$));if(y._2.tag==="CatCons")return at("CatCons",y._2._1,st(y._2._2._1,kt("Cons",at("CatCons",T,st($,$)),y._2._2._2)));g()})())})())},IC=t=>e=>n=>{if(t.theme==="Isometric")return kC({...NC,transparentBg:t.transparentBg})(t.theme)(Os(n).segment.layout)(Os(n).state);const r=yi(t)(n),o=u=>n.hasDives?r.vw/ka(1)(he(n.rootLayout).w):1,i={tileScale:o(),viewport:r},s=u=>c=>{if(c.length===0)return tt(ut("Return",void 0),_t);const _=Ft(d=>J,d=>l=>N("Just",{head:d,tail:l}),c);if(_.tag==="Nothing")return tt(ut("Return",void 0),_t);if(_.tag==="Just"){const d=Il(t)(i)(n.camera.zoom)(_._1.head.role==="Active"?e:I)(u)(_._1.head);return n.diving||_._1.head.role==="Active"?tt(d._1,(()=>{if(d._2.tag==="CatNil")return at("CatCons",()=>s(_._1.head)(_._1.tail),st($,$));if(d._2.tag==="CatCons")return at("CatCons",d._2._1,st(d._2._2._1,kt("Cons",at("CatCons",()=>s(_._1.head)(_._1.tail),st($,$)),d._2._2._2)));g()})()):tt(ut("Return",void 0),at("CatCons",()=>s(_._1.head)(_._1.tail),st($,$)))}g()},a=Ft(u=>J,u=>c=>N("Just",{head:u,tail:c}),n.levels);if(a.tag==="Nothing")return tt(ut("Return",void 0),_t);if(a.tag==="Just"){const u=a._1.tail,c=a._1.head,_=u.length===0,d=AC(t)(o())(c.role==="Active"||c.role==="FlyThrough"?c.bgAlpha:0)(c.blur)(r)(c.segment.layout)(DC(n).state)(_&&e.tag!=="Leaf"?Bl("SpringLabels",e):BC),l=()=>{const f=Jg(t)(i)(n.camera.zoom)(c);return c.role==="Active"||c.role==="FlyThrough"?tt(f._1,(()=>{if(f._2.tag==="CatNil")return at("CatCons",()=>s(c)(u),st($,$));if(f._2.tag==="CatCons")return at("CatCons",f._2._1,st(f._2._2._1,kt("Cons",at("CatCons",()=>s(c)(u),st($,$)),f._2._2._2)));g()})()):tt(ut("Return",void 0),at("CatCons",()=>s(c)(u),st($,$)))};return tt(d._1,(()=>{if(d._2.tag==="CatNil")return at("CatCons",l,st($,$));if(d._2.tag==="CatCons")return at("CatCons",d._2._1,st(d._2._2._1,kt("Cons",at("CatCons",l,st($,$)),d._2._2._2)));g()})())}g()},Ng=t=>e=>n=>jT({viewport:yi(t)(n),camera:n.camera})(IC(t)(e)(n)),vg=t=>e=>{if(e.fill.tag==="Just"){if(e.stroke.tag==="Just")return t.fillStrokePath(e.path)(e.fill._1)(e.stroke._1);if(e.stroke.tag==="Nothing")return t.fillPath(e.path)(e.fill._1);g()}if(e.fill.tag==="Nothing"){if(e.stroke.tag==="Just")return t.strokePath(e.path)(e.stroke._1);if(e.stroke.tag==="Nothing")return t.Monad0().Applicative0().pure()}g()},FC=t=>{const e=t.Monad0(),n=e.Bind1(),r=Qr(e.Applicative0())(f_),o=vl(t);return i=>{if(i.tag==="FrameTitleOverlay"){const s=i._1;return n.bind(r(vg(t))(s.backing))(()=>o(s.text))}if(i.tag==="TitleCardOverlay"){const s=i._1;return n.bind(vg(t)(s.backing))(()=>o(s.text))}if(i.tag==="FloorOverlay")return vg(t)(i._1);g()}},QC=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Qr(n)(Mt),o=t.popTransform,i=t.popBakedTransform,s=(()=>{const u=t.popClip,c=t.popAlpha,_=t.popBlend,d=t.popBlur;return l=>{if(l.tag==="GroupTransform"){if(l._1==="NormalTransform")return o;if(l._1==="BakedTransform")return i;g()}if(l.tag==="GroupClip")return u;if(l.tag==="GroupAlpha")return c;if(l.tag==="GroupBlend")return _;if(l.tag==="GroupBlur")return d;g()}})(),a=t.popLayer;return u=>e.Bind1().bind(r(s)(se(u.effects)))(()=>{if(u.layer.tag==="Just")return a;if(u.layer.tag==="Nothing")return n.pure();g()})},zC=t=>{const e=t.Monad0(),n=e.Applicative0(),r=Qr(n)(Mt);return o=>e.Bind1().bind((()=>{if(o.layer.tag==="Just")return t.pushLayer(o.layer._1);if(o.layer.tag==="Nothing")return n.pure();g()})())(()=>r(i=>{if(i.tag==="GroupTransform"){if(i._1==="NormalTransform")return t.pushTransform(i._2);if(i._1==="BakedTransform")return t.pushBakedTransform(i._2);g()}if(i.tag==="GroupClip")return t.pushClip(i._1)(i._2);if(i.tag==="GroupAlpha")return t.pushAlpha(i._1);if(i.tag==="GroupBlend")return t.pushBlend(i._1);if(i.tag==="GroupBlur")return t.pushBlur(i._1);g()})(o.effects))},Fl=t=>{const e=t.Monad0(),n=K3(t),r=wC(t),o=iC(t),i=LC(t),s=H3(t),a=JC(t);return YT(e)({beginFrame:u=>t.setViewport(u.viewport),endFrame:e.Applicative0().pure(),beginGroup:zC(t),endGroup:QC(t),background:W3(t),overlay:FC(t),node:u=>{if(u.geometry.tag==="FlatNode")return n(u);if(u.geometry.tag==="IsoSlab")return r(u);g()},edge:u=>{if(u.geometry.tag==="FlatRoute")return o(u);if(u.geometry.tag==="IsoSegments")return i(u);g()},text:vl(t),token:u=>{if(u.geometry.tag==="FlatToken")return s(u);if(u.geometry.tag==="IsoCube")return a(u);g()},insideTokenStyle:t.insideTokenStyle,measureText:t.measureText,measureInk:t.measureInk})},MC=lg(Gd)($c.measureText),Ql=Fl($c),WC=t=>e=>n=>r=>o=>i=>s=>{const a={padding:24,transparentBg:(()=>{if(e==="TransparentBackground")return!0;if(e==="PaintBackground")return!1;g()})(),halftoneShadows:!1,watermark:"",theme:t,outputAspect:r.width<=0||r.height<=0?J:N("Just",r.width/r.height)},u=Sd(n)(r);return()=>{const c=u(),_=o.levels.length-1|0;if(_>=0&&_<o.levels.length){const l=MC(wg(yi(a)(o))(o.levels[_]))(o.levels[_].segment.layout)(o.levels[_].state)(c)(),f=Dc(i)(l)(s);return Ql(Ng(a)(f.applied)(o))(c)(),f.springs}const d=Dc(i)(I)(s);return Ql(Ng(a)(d.applied)(o))(c)(),d.springs}},cs=t=>"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")",bo=t=>t===1?7:t===2?10:t===3?14:t===4?13:t===5?5:t===6?1:t===7?4:t===8?1:t===9?2:t===10?1:t===11?2:t===12?1:t===18?2:t===19?1:t===13?2:t===14?1:t===15||t===16?5:1,ae=Ho(Oo("Fixed",qo(0)(20)(2))),Tg=t=>{const e=n=>{const r=n>=0&&n<t.length?N("Just",t[n]):J;if(r.tag==="Just")return r._1===1?["M",ae((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===2?["L",ae((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+3|0)]:r._1===3?["Q",ae((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+5|0)]:r._1===4?["C",ae((()=>{const o=n+1|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+2|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+3|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+4|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+5|0;return o>=0&&o<t.length?t[o]:0})()),ae((()=>{const o=n+6|0;return o>=0&&o<t.length?t[o]:0})()),...e(n+7|0)]:r._1===5?["Z",...e(n+1|0)]:[];if(r.tag==="Nothing")return[];g()};return sr(" ")(e(0))},OC=t=>ae(t.vx)+" "+ae(t.vy)+" "+ae(t.vw)+" "+ae(t.vh),Pn=t=>e=>fe(An(e>=0&&e<t.length?t[e]:0)),Cg=t=>e=>{const n=Pn(t.ops)(e+1|0);return Rt(n,n+Pn(t.ops)(e+2|0)|0,t.paths)},zl=(()=>{const t=Qn("&")("&amp;"),e=Qn("<")("&lt;"),n=(()=>{const r=Qn(">")("&gt;"),o=(()=>{const i=Qn('"')("&quot;");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),qC={vx:0,vy:0,vw:1,vh:1},HC=t=>(e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i>=0&&i<t.length){if(t[i]===15){const s=i+1|0;r=!1,o={vx:s>=0&&s<t.length?t[s]:0,vy:(()=>{const a=s+1|0;return a>=0&&a<t.length?t[a]:0})(),vw:(()=>{const a=s+2|0;return a>=0&&a<t.length?t[a]:0})(),vh:(()=>{const a=s+3|0;return a>=0&&a<t.length?t[a]:0})()};continue}n=i+bo(t[i])|0;continue}r=!1,o=qC}return o})(0),gs=t=>e=>({r:Pn(t)(e),g:Pn(t)(e+1|0),b:Pn(t)(e+2|0),a:Pn(t)(e+3|0)}),Ml=t=>e=>({color:gs(t)(e),width:(()=>{const n=e+4|0;return n>=0&&n<t.length?t[n]:0})(),join:Pn(t)(e+5|0),cap:Pn(t)(e+6|0)}),$C=t=>e=>'<rect x="'+ae(t.vx)+'" y="'+ae(t.vy)+'" width="'+ae(t.vw)+'" height="'+ae(t.vh)+'" fill="'+cs(e)+'" opacity="'+ae(nt(e.a)/255)+'"/>',VC=t=>e=>'<path d="'+Tg(t)+'" fill="'+cs(e)+'" fill-opacity="'+ae(nt(e.a)/255)+'"/>',Wl=t=>' stroke="'+cs(t.color)+'" stroke-opacity="'+ae(nt(t.color.a)/255)+'" stroke-width="'+ae(t.width)+'" stroke-linejoin="'+(t.join===0?"round":t.join===1?"bevel":"miter")+'" stroke-linecap="'+(t.cap===0?"butt":t.cap===1?"round":"square")+'"',UC=t=>e=>n=>'<path d="'+Tg(t)+'" fill="'+cs(e)+'" fill-opacity="'+ae(nt(e.a)/255)+'"'+Wl(n)+"/>",KC=t=>e=>'<path d="'+Tg(t)+'" fill="none"'+Wl(e)+"/>",YC=t=>e=>{const n=gs(t.ops)(e+7|0),r=Pn(t.ops)(e+12|0),o=Pn(t.ops)(e+11|0);return'<text x="'+ae((()=>{const i=e+1|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" y="'+ae((()=>{const i=e+2|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'"'+(r===0?' dy="0.8em"':r===1?' dy="0.32em"':"")+' fill="'+cs(n)+'" fill-opacity="'+ae(nt(n.a)/255)+'" font-size="'+ae((()=>{const i=e+5|0;return i>=0&&i<t.ops.length?t.ops[i]:0})())+'" font-family="'+zl((()=>{const i=Pn(t.ops)(e+4|0);return i>=0&&i<t.strs.length?t.strs[i]+", ui-sans-serif, system-ui, sans-serif":", ui-sans-serif, system-ui, sans-serif"})())+'" font-weight="'+ie(Pn(t.ops)(e+6|0))+'" text-anchor="'+(o===0?"start":o===1?"middle":"end")+'">'+zl((()=>{const i=Pn(t.ops)(e+3|0);return i>=0&&i<t.strs.length?t.strs[i]:""})())+"</text>"},ko=t=>e=>n=>{const r=n>=0&&n<e.ops.length?N("Just",e.ops[n]):J;if(r.tag==="Just")return r._1===1?VC(Cg(e)(n))(gs(e.ops)(n+3|0))+ko(t)(e)(n+bo(r._1)|0):r._1===2?KC(Cg(e)(n))(Ml(e.ops)(n+3|0))+ko(t)(e)(n+bo(r._1)|0):r._1===3?UC(Cg(e)(n))(gs(e.ops)(n+3|0))(Ml(e.ops)(n+7|0))+ko(t)(e)(n+bo(r._1)|0):r._1===4?YC(e)(n)+ko(t)(e)(n+bo(r._1)|0):r._1===16?$C(t)(gs(e.ops)(n+1|0))+ko(t)(e)(n+bo(r._1)|0):ko(t)(e)(n+bo(r._1)|0);if(r.tag==="Nothing")return"";g()},XC=t=>{const e=HC(t.ops);return{viewBox:OC(e),body:ko(e)(t)(0),vx:e.vx,vy:e.vy,vw:e.vw,vh:e.vh}},jC=Av(zv)(h0),Ol=t=>e=>{const n=t.strs;return()=>{const r=du(n);return t.strs.push(e),r}},Sa=t=>e=>{const n=t.paths;return()=>{const r=du(n);return t.paths.push(...e),{offset:r,len:e.length}}},ZC=t=>e=>{const n=e.tx,r=t.ops;return()=>{r.push(n),t.ops.push(e.ty),t.ops.push(e.sx),t.ops.push(e.sy)}},ql=t=>e=>{const n=e.vx,r=t.ops;return()=>{r.push(n),t.ops.push(e.vy),t.ops.push(e.vw),t.ops.push(e.vh)}},Ir=t=>e=>{const n=nt(e),r=t.ops;return()=>{r.push(n)}},La=t=>e=>{const n=e.len,r=Ir(t)(e.offset);return()=>(r(),Ir(t)(n)())},tb=()=>{const t=[],e=[],n=[],r=[];return r.push(1),{ops:t,paths:e,strs:n,alphaStack:r}},eb=t=>{if(t.tag==="MeasureText"){const e=t._3(Ic(t._1)(t._2));return()=>e}if(t.tag==="MeasureInk"){const e=t._3(Fc(t._1)(t._2));return()=>e}g()},Hl=t=>{const e=t.alphaStack;return()=>{const n=du(e);if(n===0)return 1;const r=m0(Kt,J,n-1|0,t.alphaStack);if(r.tag==="Nothing")return 1;if(r.tag==="Just")return r._1;g()}},So=t=>e=>{const n=Hl(t);return()=>{const r=n();return Ir(t)(e.r)(),Ir(t)(e.g)(),Ir(t)(e.b)(),Ir(t)(fe(An(nt(e.a)*r+.5)))()}},$l=t=>e=>{const n=So(t)(e.color);return()=>{n(),t.ops.push(e.width),t.ops.push((()=>{if(e.lineJoin==="RoundJoin")return 0;if(e.lineJoin==="BevelJoin")return 1;if(e.lineJoin==="MiterJoin")return 2;g()})()),t.ops.push((()=>{if(e.lineCap==="ButtCap")return 0;if(e.lineCap==="RoundCap")return 1;if(e.lineCap==="SquareCap")return 2;g()})())}},nb=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r;if(a.tag==="FillPath"){const u=a._3,c=a._2,_=Sa(s)(a._1);o=!1,i=()=>{const d=_();return s.ops.push(1),La(s)(d)(),So(s)(c.color)(),u};continue}if(a.tag==="StrokePath"){const u=a._3,c=a._2,_=Sa(s)(a._1);o=!1,i=()=>{const d=_();return s.ops.push(2),La(s)(d)(),$l(s)(c)(),u};continue}if(a.tag==="FillStrokePath"){const u=a._2,c=a._4,_=a._3,d=Sa(s)(a._1);o=!1,i=()=>{const l=d();return s.ops.push(3),La(s)(l)(),So(s)(u.color)(),$l(s)(_)(),c};continue}if(a.tag==="DrawText"){const u=a._2,c=a._1,_=Ol(s)(lo(c.content));o=!1,i=()=>{const d=_(),l=Ol(s)(c.font.family)();return s.ops.push(4),s.ops.push(c.x),s.ops.push(c.y),Ir(s)(d)(),Ir(s)(l)(),s.ops.push(c.font.size),Ir(s)(c.font.weight)(),So(s)(c.color)(),s.ops.push((()=>{if(c.align==="AlignLeft")return 0;if(c.align==="AlignCenter")return 1;if(c.align==="AlignRight")return 2;g()})()),s.ops.push((()=>{if(c.baseline==="BaselineTop")return 0;if(c.baseline==="BaselineMiddle")return 1;if(c.baseline==="BaselineAlphabetic")return 2;if(c.baseline==="BaselineBottom")return 3;g()})()),u};continue}if(a.tag==="DrawTextAffine"){n=s,r=$t("DrawText",{...a._2,x:a._1.a*a._2.x+a._1.c*a._2.y+a._1.e,y:a._1.b*a._2.x+a._1.d*a._2.y+a._1.f},a._3);continue}if(a.tag==="PushTransform"){const u=a._2,c=a._1,_=s.ops;o=!1,i=()=>(_.push(5),ZC(s)(c)(),u);continue}if(a.tag==="PopTransform"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(6),u);continue}if(a.tag==="PushClip"){const u=a._3,c=a._2,_=Sa(s)(a._1);o=!1,i=()=>{const d=_();return s.ops.push(7),La(s)(d)(),s.ops.push((()=>{if(c==="NonZero")return 0;if(c==="EvenOdd")return 1;g()})()),u};continue}if(a.tag==="PopClip"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(8),u);continue}if(a.tag==="PushBlend"){const u=a._1,c=a._2,_=s.ops;o=!1,i=()=>(_.push(9),s.ops.push((()=>{if(u==="Normal")return 0;if(u==="Difference")return 1;g()})()),c);continue}if(a.tag==="PopBlend"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(10),u);continue}if(a.tag==="PushAlpha"){const u=a._1,c=a._2,_=Hl(s);o=!1,i=()=>{const d=_();return s.alphaStack.push(d*u),s.ops.push(11),s.ops.push(u),c};continue}if(a.tag==="PopAlpha"){const u=a._1,c=s.alphaStack;o=!1,i=()=>(y0(Kt,J,c),s.ops.push(12),u);continue}if(a.tag==="PushBlur"){const u=a._2,c=a._1,_=s.ops;o=!1,i=()=>(_.push(18),s.ops.push(c),u);continue}if(a.tag==="PopBlur"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(19),u);continue}if(a.tag==="PushLayer"){const u=a._1,c=a._2,_=s.ops;o=!1,i=()=>(_.push(13),s.ops.push((()=>{if(u==="LayerBase")return 0;if(u==="LayerPolyOut")return 1;if(u==="LayerPolyIn")return 2;if(u==="LayerNodeMask")return 3;if(u==="LayerOverlay")return 4;g()})()),c);continue}if(a.tag==="PopLayer"){const u=a._1,c=s.ops;o=!1,i=()=>(c.push(14),u);continue}if(a.tag==="SetViewport"){const u=a._2,c=a._1,_=s.ops;o=!1,i=()=>(_.push(15),ql(s)(c)(),u);continue}if(a.tag==="ClearBackground"){const u=a._1,c=a._2,_=s.ops;o=!1,i=()=>(_.push(16),So(s)(u)(),c);continue}if(a.tag==="BackgroundDots"){const u=a._2,c=a._1,_=s.ops;o=!1,i=()=>(_.push(17),ql(s)(c.viewport)(),So(s)(c.bgColor)(),So(s)(c.dotColor)(),s.ops.push(c.tile),s.ops.push(c.dotRadius),s.ops.push(c.origin.x),s.ops.push(c.origin.y),u);continue}g()}return i},rb=t=>e=>e.type==="metrics"?eb(e.value):e.type==="render"?nb(t)(e.value):M_("Data.Functor.Variant: pattern match failure ["+e.type+"]"),ob=t=>{const e=tb();return jC(rb(e))(t)(),{ops:e.ops,paths:e.paths,strs:e.strs}},ib=t=>t,_s=t=>t,bg=_s("Light"),sb=_s("Dark"),ab=_s("Blueprint"),ub=_s("Whiteboard"),cb=_s("Isometric"),gb=ib("TransparentBackground"),Zr=t=>"rgb("+ie(t.r)+","+ie(t.g)+","+ie(t.b)+")",lr=Ho(Oo("Fixed",qo(0)(20)(4))),_b=t=>"translate("+lr(t.tx)+","+lr(t.ty)+") scale("+lr(t.sx)+","+lr(t.sy)+")",It=Ho(Oo("Fixed",qo(0)(20)(2))),kg=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,o=r>=0&&r<t.length?N("Just",t[r]):J;if(o.tag==="Nothing"){n=t.length;continue}if(o.tag==="Just"){if(o._1===1){e.push("M"),e.push(It((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),n=r+3|0;continue}if(o._1===2){e.push("L"),e.push(It((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),n=r+3|0;continue}if(o._1===3){e.push("Q"),e.push(It((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+4|0;return i>=0&&i<t.length?t[i]:0})())),n=r+5|0;continue}if(o._1===4){e.push("C"),e.push(It((()=>{const i=r+1|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+2|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+3|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+4|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+5|0;return i>=0&&i<t.length?t[i]:0})())),e.push(It((()=>{const i=r+6|0;return i>=0&&i<t.length?t[i]:0})())),n=r+7|0;continue}if(o._1===5){e.push("Z"),n=r+1|0;continue}n=t.length;continue}g()}return sr(" ")(e)},fb={map:t=>e=>n=>{const r=e(n);return()=>{const o=r();return t(o)}}},Sg=(()=>{const t=Qn("&")("&amp;"),e=Qn("<")("&lt;"),n=(()=>{const r=Qn(">")("&gt;"),o=(()=>{const i=Qn('"')("&quot;");return s=>i(r(s))})();return i=>o(e(i))})();return r=>n(t(r))})(),db=t=>{if(t.style==="RunText")return"<tspan>"+Sg(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'CommitMono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+Sg(t.text)+"</tspan>";g()},qe=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},lb=t=>e=>{const n=[];let r=0;const o=i=>{const s=i>=0&&i<e.length?t.sx*e[i]+t.tx:t.sx*0+t.tx;return()=>{n.push(s),n.push((()=>{const a=i+1|0;return a>=0&&a<e.length?t.sy*e[a]+t.ty:t.sy*0+t.ty})())}};for(;r<e.length;){const i=r,s=i>=0&&i<e.length?N("Just",e[i]):J;if(s.tag==="Nothing"){r=e.length;continue}if(s.tag==="Just"){if(s._1===1){n.push(s._1),o(i+1|0)(),r=i+3|0;continue}if(s._1===2){n.push(s._1),o(i+1|0)(),r=i+3|0;continue}if(s._1===3){n.push(s._1),o(i+1|0)(),o(i+3|0)(),r=i+5|0;continue}if(s._1===4){n.push(s._1),o(i+1|0)(),o(i+3|0)(),o(i+5|0)(),r=i+7|0;continue}if(s._1===5){n.push(s._1),r=i+1|0;continue}r=e.length;continue}g()}return n},Ea=t=>e=>{const n=t.bake;return()=>{const r=n.value;if(r.tag==="Nothing")return e;if(r.tag==="Just")return lb(r._1)(e);g()}},Vl={apply:t=>e=>n=>{const r=t(n),o=e(n);return()=>{const i=r(),s=o();return i(s)}},Functor0:()=>fb},hb={bind:t=>e=>n=>{const r=t(n);return()=>{const o=r();return e(o)(n)()}},Apply0:()=>Vl},pb={pure:t=>e=>()=>t,Apply0:()=>Vl},Ul={Applicative0:()=>pb,Bind1:()=>hb},mb=t=>e=>'<defs><pattern id="'+t+'" x="'+It(e.origin.x)+'" y="'+It(e.origin.y)+'" width="'+It(e.tile)+'" height="'+It(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+It(e.tile)+'" height="'+It(e.tile)+'" fill="'+Zr(e.bgColor)+'" fill-opacity="'+It(nt(e.bgColor.a)/255)+'"/>')+'<circle cx="'+It(e.tile/2)+'" cy="'+It(e.tile/2)+'" r="'+It(e.dotRadius)+'" fill="'+Zr(e.dotColor)+'"/></pattern></defs><rect x="'+It(e.viewport.vx)+'" y="'+It(e.viewport.vy)+'" width="'+It(e.viewport.vw)+'" height="'+It(e.viewport.vh)+'" fill="url(#'+t+')"/>',Kl=t=>e=>'<path d="'+kg(t)+'" fill="'+Zr(e)+'" fill-opacity="'+It(nt(e.a)/255)+'"/>',yb=t=>e=>n=>r=>'<rect x="'+It(t.x)+'" y="'+It(t.y)+'" width="'+It(t.w)+'" height="'+It(t.h)+'" rx="'+It(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+Zr(n._1.color)+'" fill-opacity="'+It(nt(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';g()})()+(()=>{if(r.tag==="Just")return' stroke="'+Zr(r._1.color)+'" stroke-opacity="'+It(nt(r._1.color.a)/255)+'" stroke-width="'+It(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";g()})()+'"';if(r.tag==="Nothing")return"";g()})()+"/>",Yl=t=>e=>'<path d="'+kg(t)+'" fill="none" stroke="'+Zr(e.color)+'" stroke-opacity="'+It(nt(e.color.a)/255)+'" stroke-width="'+It(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";g()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";g()})()+'"/>',Xl=t=>{const e=W1(lo(t.content));return'<text x="'+It(t.x)+'" y="'+It(t.y)+'"'+(()=>{if(t.baseline==="BaselineTop")return' dy="0.8em"';if(t.baseline==="BaselineMiddle")return' dy="0.32em"';if(t.baseline==="BaselineAlphabetic"||t.baseline==="BaselineBottom")return"";g()})()+' fill="'+Zr(t.color)+'" fill-opacity="'+It(nt(t.color.a)/255)+'" font-size="'+It(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+ie(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";g()})()+'">'+(e.length===1&&e[0].style==="RunText"?Sg(e[0].text):sr("")(q(db)(e)))+"</text>"},xb=t=>"matrix("+lr(t.a)+" "+lr(t.b)+" "+lr(t.c)+" "+lr(t.d)+" "+lr(t.e)+" "+lr(t.f)+")",jl={fillPath:t=>e=>n=>{const r=Ea(n)(t);return()=>{const o=r();return qe(Kl(o)(e.color))(n)()}},strokePath:t=>e=>n=>{const r=Ea(n)(t);return()=>{const o=r(),i=n.bake.value;return qe(Yl(o)((()=>{if(i.tag==="Nothing")return e;if(i.tag==="Just")return{...e,width:i._1.sx*e.width};g()})()))(n)()}},fillStrokePath:t=>e=>n=>r=>{const o=Ea(r)(t);return()=>{const i=o(),s=r.bake.value;return qe(Kl(i)(e.color)+Yl(i)((()=>{if(s.tag==="Nothing")return n;if(s.tag==="Just")return{...n,width:s._1.sx*n.width};g()})()))(r)()}},drawRoundedRect:t=>e=>n=>r=>o=>{const i=o.bake;return()=>{const s=i.value;return qe(yb((()=>{if(s.tag==="Nothing")return t;if(s.tag==="Just")return{x:s._1.sx*t.x+s._1.tx,y:s._1.sy*t.y+s._1.ty,w:s._1.sx*t.w,h:s._1.sy*t.h};g()})())((()=>{if(s.tag==="Nothing")return e;if(s.tag==="Just")return s._1.sx*e;g()})())(n)(r.tag==="Just"?N("Just",(()=>{if(s.tag==="Nothing")return r._1;if(s.tag==="Just")return{...r._1,width:s._1.sx*r._1.width};g()})()):J))(o)()}},drawText:t=>e=>{const n=e.bake;return()=>{const r=n.value;return qe(Xl((()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return{...t,x:r._1.sx*t.x+r._1.tx,y:r._1.sy*t.y+r._1.ty,font:{...t.font,size:r._1.sx*t.font.size}};g()})()))(e)()}},drawTextAffine:t=>e=>qe((()=>{const n='transform="'+xb(t)+'"';return(n===""?"<g>":"<g "+n+">")+Xl(e)+"</g>"})()),pushTransform:t=>qe((()=>{const e='transform="'+_b(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:qe("</g>"),pushBakedTransform:t=>e=>{const n=e.bake;return()=>{n.value=N("Just",t)}},popBakedTransform:t=>{const e=t.bake;return()=>{e.value=J}},pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const o=r.value;n.clipCounter.value=o+1|0;const i=Ea(n)(t)(),s="clip"+ie(o);return qe((()=>{const a='clip-path="url(#'+s+')"';return'<defs><clipPath id="'+s+'"><path d="'+kg(i)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";g()})()+"/></clipPath></defs>"+(a===""?"<g>":"<g "+a+">")})())(n)()}},popClip:qe("</g>"),pushBlend:t=>qe((()=>{const e=(()=>{if(t==="Normal")return'style="mix-blend-mode: normal"';if(t==="Difference")return'style="mix-blend-mode: difference"';g()})();return e===""?"<g>":"<g "+e+">"})()),popBlend:qe("</g>"),pushAlpha:t=>qe((()=>{const e='opacity="'+It(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:qe("</g>"),pushBlur:t=>e=>{if(t<.01)return qe("<g>")(e);const n=e.patternCounter;return()=>{const r=n.value;e.patternCounter.value=r+1|0;const o="lvl-blur-"+ie(r);return qe((()=>{const i='filter="url(#'+o+')"';return'<defs><filter id="'+o+'" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="'+It(t)+'"/></filter></defs>'+(i===""?"<g>":"<g "+i+">")})())(e)()}},popBlur:qe("</g>"),pushLayer:t=>e=>{const n=(()=>{if(t==="LayerNodeMask"){const r=e.maskDepth;return()=>{const o=r.value;e.maskDepth.value=o+1|0}}return()=>{}})();return()=>{n(),e.out.push("<g>")}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;n>0&&(t.maskDepth.value=r),t.out.push("</g>")}},setViewport:t=>e=>()=>{},clearBackground:t=>e=>qe('<rect x="'+It(e.viewport.vx)+'" y="'+It(e.viewport.vy)+'" width="'+It(e.viewport.vw)+'" height="'+It(e.viewport.vh)+'" fill="'+Zr(t)+'" opacity="'+It(nt(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,qe(mb("bg-dots-"+ie(r))(t))(e)()}},measureText:t=>e=>n=>{const r=Ic(t)(e);return()=>r},measureInk:t=>e=>n=>{const r=Fc(t)(e);return()=>r},insideTokenStyle:t=>e=>()=>Oc,Monad0:()=>Ul},wb=Fl(jl),Jb=lg(Ul)(jl.measureText),Nb=t=>e=>n=>r=>o=>{const i={padding:24,transparentBg:(()=>{if(r==="TransparentBackground")return!0;if(r==="PaintBackground")return!1;g()})(),halftoneShadows:!1,watermark:"",theme:n,outputAspect:t},s=yi(i)(o);return{viewBox:It(s.vx)+" "+It(s.vy)+" "+It(s.vw)+" "+It(s.vh),body:(()=>{const a=[],u={value:0},c={value:0},_={value:0},d={value:J};return wb(Ng(i)(e)(o))({out:a,maskDepth:u,clipCounter:c,patternCounter:_,viewport:s,bake:d})(),sr("")(a)})(),vx:s.vx,vy:s.vy,vw:s.vw,vh:s.vh}},vb=t=>e=>n=>r=>o=>i=>{const s={padding:24,transparentBg:(()=>{if(n==="TransparentBackground")return!0;if(n==="PaintBackground")return!1;g()})(),outputAspect:t},a=Dc(o)((()=>{const u=[],c={value:0},_={value:0},d={value:0},l={value:J},f=r.levels.length-1|0;if(f>=0&&f<r.levels.length){const h=wg(yi(s)(r))(r.levels[f]);return Jb(h)(r.levels[f].segment.layout)(r.levels[f].state)({out:u,maskDepth:c,clipCounter:_,patternCounter:d,viewport:h,bake:l})()}return I})())(i);return{parts:Nb(t)(a.applied)(e)(n)(r),springs:a.springs}},Tb=t=>e=>{if(e.scene.tag==="Structural")return e.scene._1.to;if(e.scene.tag==="DataFlow")return e.scene._1.keyframe;if(e.scene.tag==="Hold")return e.scene._1;if(e.scene.tag==="EnterNode"||e.scene.tag==="ExitNode"||e.scene.tag==="StepScene")return t;g()},Ke=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},hr=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Cb=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Zl=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Ga=hu(Ti),th=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},bb=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},eh=(()=>{const t=nn.unfoldr(Fn);return e=>t(rn("IterNode",e,In))})(),kb=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},xi=t=>e=>n=>{const r=ot.compare(t)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;g()})(),i=ot.compare(e)(o);if(i==="LT"||i==="EQ")return e;if(i==="GT")return o;g()},Sb=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Lb=t=>t,nh=t=>e=>n=>n<t?0:n>1-e?1:(n-t)/Ke(.05)(1-t-e),Eb=t=>e=>t.labelBasePx*.62*nt(v(Cb)(0)(q(ry)(Et(e)(n=>Kr(`
10
+ `)(n))))),Lg=(()=>{const t=v(e=>n=>{const r=e.previous.tag==="Just"&&Oe(e.previous._1.endT-n.startT)<1e-4?{...n,fromCam:e.previous._1.toCam}:n;return{previous:N("Just",r),spans:St(e.spans)(r)}})({previous:J,spans:[]});return e=>t(e).spans})(),Eg=t=>e=>{const n=Zl(e)(t.keyframes);if(n.tag==="Nothing")return I;if(n.tag==="Just")return n._1.nodes;g()},rh=t=>e=>{if(e<t.startT)return zn("AtKeyframe",t.initialKeyframe);const n=re(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return zn("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return zn("AtKeyframe",n._1.scene._1.keyframe);if(n._1.scene.tag==="Hold")return zn("AtKeyframe",n._1.scene._1);if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode"||n._1.scene.tag==="StepScene")return zn("AtKeyframe",t.initialKeyframe);g()}if(n.tag==="Nothing")return zn("AtKeyframe",v(Tb)(t.initialKeyframe)(t.spans));g()},Gb=t=>e=>n=>r=>{const o=re(i=>Ga(i.path)(e)&&(Oe(i.endT-n)<1e-4||Oe(i.startT-r)<1e-4))(t.segments);if(o.tag==="Just")return N("Just",o._1);if(o.tag==="Nothing")return re(i=>Ga(i.path)(e))(t.segments);g()},Gg=t=>e=>{const n=Zl(e)(t.keyframes);if(n.tag==="Nothing")return I;if(n.tag==="Just")return n._1.edges;g()},oh=(()=>{const t=(n,r,o,i,s)=>{let a=n,u=r,c=o,_=i,d=s,l=!0,f;for(;l;){if(a===0){const h=Ft(p=>J,p=>m=>N("Just",{head:p,tail:m}),u);if(h.tag==="Nothing"){l=!1,f=[];continue}if(h.tag==="Just"){a=1,u=h._1.head,c=h._1.head,_=!1,d=h._1.tail;continue}g()}if(a===1){const h=u,p=c,m=_,w=d,x=Ft(y=>J,y=>T=>N("Just",{head:y,tail:T}),w);if(x.tag==="Just"&&p.intent==="Overview"&&x._1.head.intent==="Overview"&&!(p.fromCam.zoom===p.toCam.zoom&&p.fromCam.center.x===p.toCam.center.x&&p.fromCam.center.y===p.toCam.center.y)&&!(x._1.head.fromCam.zoom===x._1.head.toCam.zoom&&x._1.head.fromCam.center.x===x._1.head.toCam.center.x&&x._1.head.fromCam.center.y===x._1.head.toCam.center.y)&&Oe(p.toCam.center.x-x._1.head.fromCam.center.x)<1e-4&&Oe(p.toCam.center.y-x._1.head.fromCam.center.y)<1e-4&&Oe(p.toCam.zoom-x._1.head.fromCam.zoom)<1e-4&&Oe(p.endT-x._1.head.startT)<1e-4){a=1,u=h,c=x._1.head,_=!0,d=x._1.tail;continue}l=!1,f=[m?{...h,endT:p.endT,toCam:p.toCam,easing:p.easing,interp:br}:h,...e(w)]}}return f},e=n=>t(0,n);return e})(),Pb=t=>e=>{const n=he(e),r=Ll({width:t.widthPx,height:t.heightPx})({vx:n.x,vy:n.y,vw:n.w,vh:n.h});return{w:r.vw,h:r.vh}},Bb=t=>e=>n=>r=>{const o=Ke(n.center.x-r.x)(r.x+r.w-n.center.x),i=Ke(n.center.y-r.y)(r.y+r.h-n.center.y),s=Pb(t)(e);return hr(o<=0?n.zoom:s.w/(o*2))(i<=0?n.zoom:s.h/(i*2))},ih=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r,u=Nr(a);if(u.tag==="Just"&&u._1.last.intent==="Overview"){n=[u._1.last,...s],r=u._1.init;continue}o=!1,i={prefix:a,overview:s}}return i},Db=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r,u=Ft(c=>J,c=>_=>N("Just",{head:c,tail:_}),a);if(u.tag==="Just"&&u._1.head.intent==="Overview"){n=St(s)(u._1.head),r=u._1.tail;continue}o=!1,i={overview:s,rest:a}}return i},Lo=t=>e=>n=>r=>o=>{const i={width:e.widthPx,height:e.heightPx},s=Ll(i)((()=>{const a=_o(n)(o);return{vx:a.x,vy:a.y,vw:a.w,vh:a.h}})());return t.labelBasePx*r.placement.scale*(i.width<=0||s.vw<=0?0:i.width/s.vw)},Rb=t=>e=>n=>r=>o=>{const i=Lo(t)(e)(n)(r)(o);return i<=t.minimumReadableLabelPx?o:{...o,zoom:o.zoom*t.minimumReadableLabelPx/i}},Ab=t=>e=>n=>r=>({...r,fromCam:gf(t)(e)(n)(r.fromCam),toCam:gf(t)(e)(n)(r.toCam)}),sh=t=>e=>t.widthPx<=0?0:hr(e/4)(32*e/t.widthPx),Ib=t=>e=>n=>r=>o=>{const i=sh(e)(n),s=r+n/2-i;return o.x<r-n/2+i?o.x-i+n/2:o.x+o.w>s?o.x+o.w+i-n/2:r},Fb=t=>e=>n=>Ne(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),Qb=t=>e=>n=>Ne(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),zb=t=>e=>n=>Ne(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),Mb=t=>e=>n=>Ne(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),Pa=t=>e=>n=>Ne(r=>n(r)&&e>=r.startT&&e<r.endT,t),Pg=t=>e=>n=>{if(e.length===0)return n;const r=hr(160)(Eb(t)(e)+31),o=hr(40)(t.labelBasePx*1.2+23);return{x:n.x-r,y:n.y-o,w:n.w+r*2,h:n.h+o*2}},Wb=t=>e=>n=>{const r=t.padding*.75,o=nt(8);return ys(i=>{if(i.target.tag==="NodeWindow")return[];if(i.target.tag==="EdgeWindow"){if(i.target._2.tag==="Extend")return[{startT:i.startT,endT:i.endT,bbox:Bs(e)(n)(i.target._1),priority:1}];if(i.target._2.tag==="Retract")return[];g()}if(i.target.tag==="TokenWindow"){const s=th(i.target._2)(e.edges);if(s.tag==="Just"){const a=(()=>{if(i.target._3==="Forward")return s._1;if(i.target._3==="Backward")return se(s._1);g()})();return Et(Xt(0,7))(u=>{const c=i.startT+(i.endT-i.startT)*(nt(u)/o),_=(()=>{const d=i.startT+(i.endT-i.startT)*(nt(u+1|0)/o);return{startT:c,endT:d,box:(()=>{const l=go(a)(nh(i.target._7)(i.target._8)(((c+d)/2-i.startT)/Ke(1e-4)(i.endT-i.startT)));if(l.tag==="Just")return{x:l._1.x-r,y:l._1.y-r,w:0+r*2,h:0+r*2};if(l.tag==="Nothing")return{x:0,y:0,w:0,h:0};g()})()}})();return[{startT:_.startT,endT:_.endT,bbox:Pg(t)(i.target._6)(_.box),priority:1}]})}if(s.tag==="Nothing")return[{startT:i.startT,endT:i.endT,bbox:Pg(t)(i.target._6)(Bs(e)(n)(i.target._2)),priority:1}];g()}if(i.target.tag==="FillWindow")return[{startT:i.startT,endT:i.endT,bbox:Pg(t)(i.target._3)(Ou(e)(n)(te("Node",1,1,i.target._2,void 0,I,I))),priority:1}];g()})},Ob=t=>e=>n=>r=>o=>i=>{if(o.tag==="Nothing")return i.zoom;if(o.tag==="Just")return Ke(0)(Bb(e)(n)(i)((()=>{const s=t.padding*r.placement.scale;return{x:o._1.x-s,y:o._1.y-s,w:o._1.w+s*2,h:o._1.h+s*2}})()));g()},qb=t=>e=>n=>r=>o=>{const i=s=>{const a=Lo(t)(e)(n)(r)(s);return a<=0||a>=t.minimumReadableLabelPx?s:{...s,zoom:s.zoom*t.minimumReadableLabelPx/a}};return{...o,fromCam:i(o.fromCam),toCam:i(o.toCam)}},Hb=t=>e=>{const n=rh(t)(e);if(n.tag==="AtKeyframe")return Eg(t)(n._1);if(n.tag==="InTransition")return Qe(P.compare,Ie,Eg(t)(n._1),Eg(t)(n._2));g()},$b=t=>e=>n=>Pa(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n&&r.target._2==="PlopOut")?!0:Qb(t.windows)(e)(n)?!1:Pa(t.windows)(e)(r=>r.target.tag==="NodeWindow"&&r.target._1===n)?!0:zb(t.windows)(e)(n)?!1:bb(n)(Hb(t)(e)),ah=t=>e=>vt(n=>$b(t)(e)(n._1)?N("Just",{x:n._2.x,y:n._2.y,w:n._2.w,h:n._2.h}):J)(eh(t.layout.nodes)),Vb=t=>e=>{const n=ah(t)(e);return n.length===0?J:N("Just",ir(n))},Ub=t=>vt(e=>{const n=Vb(t)(Ke(e.startT)(e.endT-1e-4));if(n.tag==="Nothing")return J;if(n.tag==="Just")return N("Just",{startT:e.startT,endT:e.endT,bbox:n._1,priority:0});g()}),Kb=t=>e=>n=>r=>o=>[...Ub(o)(ft(i=>i.startT>=o.startT&&i.endT<=o.endT,r.spans)),...Wb(t)(o.layout)(n)(o.windows)],Yb=t=>e=>n=>r=>o=>i=>$2(t)(e)(i.layout)(o.endT)(Kb(t)(n)(r)(o)(i)),Xb=t=>e=>{const n=rh(t)(e);if(n.tag==="AtKeyframe")return Gg(t)(n._1);if(n.tag==="InTransition")return Qe(P.compare,Ie,Gg(t)(n._1),Gg(t)(n._2));g()},jb=t=>e=>n=>Pa(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n)?!0:Fb(t.windows)(e)(n)?!1:Pa(t.windows)(e)(r=>r.target.tag==="EdgeWindow"&&r.target._1===n)?!0:Mb(t.windows)(e)(n)?!1:kb(n)(Xb(t)(e)),Zb=t=>e=>{const n=[...ah(t)(e),...vt(r=>jb(t)(e)(r._1)?N("Just",Wu(r._2)):J)(eh(t.layout.edges))];return n.length===0?J:N("Just",ir(n))},tk=t=>e=>n=>{const r=_o(t)(n);return e.x>=r.x&&e.x+e.w<=r.x+r.w},uh=t=>e=>n=>{const r=t.x+t.w/2,o=n>=t.w?{lo:r,hi:r}:{lo:t.x+n/2,hi:t.x+t.w-n/2};if(n>=e.w){const u=Ke(o.lo)(e.x+e.w-n/2),c=hr(o.hi)(e.x+n/2);return u<=c?{lo:u,hi:c}:o}const i=e.x+e.w/2;if(n>=e.w){const u=Ke(o.lo)(i),c=hr(o.hi)(i);return u<=c?{lo:u,hi:c}:o}const s=Ke(o.lo)(e.x+n/2),a=hr(o.hi)(e.x+e.w-n/2);return s<=a?{lo:s,hi:a}:o},ek=t=>e=>n=>n.endT<=t||n.startT>=e?J:N("Just",{...n,startT:Ke(t)(n.startT),endT:hr(e)(n.endT)}),ch=t=>e=>n=>r=>o=>i=>vt(ek(i.startT)(i.endT))(q(Ab(n)(i.layout)(i.placement))(Yb(t)(e)(r)(i.edgeEndpoints)(o)(i))),gh=t=>e=>n=>r=>{const o=he(t),i=hr(r.zoom)(o.w/Ke(1e-4)(e.w));return{...r,center:{...r.center,x:(()=>{const s=uh(o)(e)(o.w/Ke(1e-4)(i));return xi(s.lo)(s.hi)(n.center.x)})()},zoom:i}},nk=t=>e=>n=>r=>o=>i=>s=>a=>{const u=sh(e)(a),c=he(n),_={x:c.x-u,y:c.y-u,w:c.w+u*2,h:c.h+u*2},d=(()=>{if(o.tag==="Nothing")return s.center.x;if(o.tag==="Just")return Ib()(e)(a)(i.center.x)(o._1);g()})();if(r.tag==="Nothing"){const l=_.x+_.w/2;return a>=_.w?xi(l)(l)(d):xi(_.x+a/2)(_.x+_.w-a/2)(d)}if(r.tag==="Just"){const l={x:r._1.x-u,y:r._1.y-u,w:r._1.w+u*2,h:r._1.h+u*2};if(a<l.w){const h=_.x+_.w/2;return a>=_.w?xi(h)(h)(d):xi(_.x+a/2)(_.x+_.w-a/2)(d)}const f=uh(_)(l)(a);return xi(f.lo)(f.hi)(d)}g()},rk=t=>e=>n=>r=>o=>i=>s=>{const a=_o(n)(s);return a.w<=0?s:{...s,center:{...s.center,x:nk()(e)(n)(r)(o)(i)(s)(a.w)}}},_h=t=>e=>n=>r=>r2(t)(e)(n)(r.layout)(r.placement)((()=>{if(r.layout.nodes.tag==="Leaf")return 0;if(r.layout.nodes.tag==="Node")return r.layout.nodes._2;g()})()).camera,fh=t=>e=>n=>r=>o=>{const i=_o(n)(o);return(()=>{const s=he(r.layout),a=s.x*r.placement.scale+r.placement.tx,u=s.y*r.placement.scale+r.placement.ty;return a>=i.x&&u>=i.y&&a+s.w*r.placement.scale<=i.x+i.w&&u+s.h*r.placement.scale<=i.y+i.h})()&&Lo(t)(e)(n)(r)(o)>=t.minimumReadableLabelPx},Bg=t=>e=>n=>r=>o=>i=>fh(t)(e)(n)(r)(o)?o:Rb(t)(e)(n)(r)(i),ok=t=>e=>n=>{const r=Db([])(n),o=Ft(s=>J,s=>a=>N("Just",{head:s,tail:a}),r.rest),i=r.overview.length-1|0;return i>=0&&i<r.overview.length&&0<r.overview.length&&o.tag==="Just"&&Oe(r.overview[0].startT-e.startT)<1e-4&&o._1.head.intent==="ActionFocus"?[{startT:r.overview[0].startT,endT:r.overview[i].endT,fromCam:t,toCam:t,easing:r.overview[0].easing,interp:br,intent:sf},{...o._1.head,fromCam:t},...o._1.tail]:n},ik=t=>e=>{const n=Ft(r=>J,r=>o=>N("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{...n._1.head,fromCam:t},...n._1.tail];g()},sk=t=>e=>{const n=o=>i=>s=>{let a=o,u=i,c=s,_=!0,d;for(;_;){const l=a,f=u,h=Ft(p=>J,p=>m=>N("Just",{head:p,tail:m}),c);if(h.tag==="Nothing"){_=!1,d=St(l)(f);continue}if(h.tag==="Just"){if(f.intent==="Overview"&&h._1.head.intent==="ActionFocus"&&Oe(f.endT-h._1.head.startT)<1e-4&&f.fromCam.zoom===f.toCam.zoom&&f.fromCam.center.x===f.toCam.center.x&&f.fromCam.center.y===f.toCam.center.y&&(()=>{const p=h._1.head.startT;return!(h._1.head.fromCam.zoom===h._1.head.toCam.zoom&&h._1.head.fromCam.center.x===h._1.head.toCam.center.x&&h._1.head.fromCam.center.y===h._1.head.toCam.center.y)&&Ne(m=>Oe(m.startT-p)<1e-4&&(m.target.tag==="EdgeWindow"?m.target._2.tag==="Extend":m.target.tag==="TokenWindow"||m.target.tag==="FillWindow"),t.windows)})()){const p=h._1.head.startT,m=Pt(ot.compare)(vt(T=>T.target.tag==="EdgeWindow"&&T.target._2.tag==="Extend"&&Oe(T.endT-p)<1e-4?N("Just",T.startT):J)(t.windows)),w=0<m.length?m[0]:p,x=Ke(f.startT)(w-(h._1.head.endT-h._1.head.startT)),y={...f,endT:x};a=St(y.endT>y.startT?St(l)(y):l)({...h._1.head,startT:x,endT:w}),u={...h._1.head,startT:w,fromCam:h._1.head.toCam},c=h._1.tail;continue}a=St(l)(f),u=h._1.head,c=h._1.tail;continue}g()}return d},r=Ft(o=>J,o=>i=>N("Just",{head:o,tail:i}),e);if(r.tag==="Nothing")return[];if(r.tag==="Just")return n([])(r._1.head)(r._1.tail);g()},ak=t=>e=>n=>r=>o=>i=>{const s=he(r.layout),a={x:s.x*r.placement.scale+r.placement.tx,y:s.y*r.placement.scale+r.placement.ty,w:s.w*r.placement.scale,h:s.h*r.placement.scale},u=gh(n)(a)(o)(i);return a.w/Ke(1e-4)(a.h)>=.33&&i.zoom/Ke(1e-4)(u.zoom)<=1.25&&_o(n)(u).w>=a.w-.001&&Lo(t)(e)(n)(r)(u)>=t.minimumReadableLabelPx*.85?u:i},uk=t=>e=>n=>r=>o=>i=>s=>{const a=he(r.layout),u=a.w*r.placement.scale,c=u/Ke(1e-4)(a.h*r.placement.scale);if(o.tag==="Nothing")return s;if(o.tag==="Just"){if(tk(n)(o._1)(s))return s;const _=gh(n)(o._1)(i)(s);return s.zoom/Ke(1e-4)(_.zoom)<=1.25&&(Lo(t)(e)(n)(r)(_)>=t.minimumReadableLabelPx-.001||o._1.w>=u-.001&&c>=.33&&Lo(t)(e)(n)(r)(_)>=t.minimumReadableLabelPx*.85)?_:s}g()},ck=t=>e=>n=>r=>o=>i=>s=>{const a={...s,center:(()=>{if(i.tag==="Nothing")return s.center;if(i.tag==="Just")return{x:i._1.x+i._1.w/2,y:i._1.y+i._1.h/2};g()})()},u=Lo(t)(e)(n)(r)(a);return rk()(e)(n)(o)(i)(s)(uk(t)(e)(n)(r)(o)(s)(ak(t)(e)(n)(r)(s)(u<=0?a:{...a,zoom:hr(a.zoom*t.minimumReadableLabelPx/u)(Ob(t)(e)(n)(r)(i)(a))})))},Dg=t=>e=>n=>r=>o=>i=>s=>fh(t)(e)(n)(r)(s)?s:ck(t)(e)(n)(r)(o)(i)(s),dh=t=>{const e=n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=i,_=Ft(d=>J,d=>l=>N("Just",{head:d,tail:l}),c);if(_.tag==="Just"&&_._1.head.intent==="Overview"){o=St(u)(_._1.head),i=_._1.tail;continue}s=!1,a={overview:u,rest:c}}return a};return(n=>r=>{let o=n,i=r,s=!0,a;for(;s;){const u=o,c=Ft(_=>J,_=>d=>N("Just",{head:_,tail:d}),i);if(c.tag==="Nothing"){s=!1,a=u;continue}if(c.tag==="Just"){if(c._1.head.intent==="Overview"){const _=e([c._1.head])(c._1.tail),d=Ft(h=>J,h=>p=>N("Just",{head:h,tail:p}),_.rest),l=u.length-1|0,f=l>=0&&l<u.length?N("Just",u[l]):J;if(f.tag==="Just"&&d.tag==="Just"&&f._1.intent==="ActionFocus"&&(()=>{const h=_.overview.length-1|0;return d._1.head.intent==="ActionFocus"&&(h>=0&&h<_.overview.length&&0<_.overview.length?_.overview[h].endT-_.overview[0].startT<=1.0001:!0)})()&&0<_.overview.length){const h=_.overview.length-1|0;if(h>=0&&h<_.overview.length){o=St(u)({startT:_.overview[0].startT,endT:_.overview[h].endT,fromCam:f._1.toCam,toCam:f._1.toCam,easing:_.overview[0].easing,interp:br,intent:Rs}),i=[{...d._1.head,fromCam:f._1.toCam},...d._1.tail];continue}}o=[...u,..._.overview],i=_.rest;continue}o=St(u)(c._1.head),i=c._1.tail;continue}g()}return a})([])(t)},gk=t=>e=>n=>{const r=ih([])(n),o=r.overview.length-1|0;if(o>=0&&o<r.overview.length){if(0<r.overview.length){const i=r.prefix.length-1|0;if(i>=0&&i<r.prefix.length&&r.prefix[i].intent==="ActionFocus"&&Oe(r.overview[o].endT-e.endT)<1e-4)return[...r.prefix,{startT:r.overview[0].startT,endT:r.overview[o].endT,fromCam:r.prefix[i].toCam,toCam:r.prefix[i].toCam,easing:r.overview[0].easing,interp:br,intent:Rs}]}return n}return 0<r.overview.length&&r.prefix.length-1|0,n},lh=t=>e=>n=>{const r=ih([])(n),o=r.overview.length-1|0;if(o>=0&&o<r.overview.length){if(0<r.overview.length){const i=r.prefix.length-1|0;if(i>=0&&i<r.prefix.length&&(()=>{const s=r.overview[o].endT;return r.prefix[i].intent==="ActionFocus"&&(()=>{const a=r.overview.length-1|0;return Ne(u=>u.direction==="DiveIn"&&Ga(u.parentPath)(t.path)&&Oe(u.startT-s)<1e-4,e)&&(a>=0&&a<r.overview.length&&0<r.overview.length?r.overview[a].endT-r.overview[0].startT<=1.0001:!0)})()})())return[...r.prefix,{startT:r.overview[0].startT,endT:r.overview[o].endT,fromCam:r.prefix[i].toCam,toCam:r.prefix[i].toCam,easing:r.overview[0].easing,interp:br,intent:Rs}]}return n}return n},_k=t=>e=>{const n=e.fromCam.zoom===e.toCam.zoom&&e.fromCam.center.x===e.toCam.center.x&&e.fromCam.center.y===e.toCam.center.y?(e.startT+e.endT)/2:e.endT+1e-4,r=vt(o=>o.target.tag==="EdgeWindow"?o.target._2.tag==="Extend"?N("Just",Bs(t.layout)(t.edgeEndpoints)(o.target._1)):J:o.target.tag==="TokenWindow"?N("Just",(()=>{const i=[...vt(s=>{const a=Sb(s)(t.layout.nodes);return a.tag==="Just"?N("Just",{x:a._1.x,y:a._1.y,w:a._1.w,h:a._1.h}):J})([o.target._4,o.target._5]),...(()=>{const s=th(o.target._2)(t.layout.edges),a=nh(o.target._7)(o.target._8)((n-o.startT)/Ke(1e-4)(o.endT-o.startT)),u=(()=>{if(s.tag==="Just")return go((()=>{if(o.target._3==="Forward")return s._1;if(o.target._3==="Backward")return se(s._1);g()})())(a);if(s.tag==="Nothing")return J;g()})();return u.tag==="Just"?[{x:u._1.x,y:u._1.y,w:0,h:0}]:[]})()];return i.length===0?Bs(t.layout)(t.edgeEndpoints)(o.target._2):ir(i)})()):o.target.tag==="FillWindow"?N("Just",Ou(t.layout)(t.edgeEndpoints)(te("Node",1,1,o.target._2,void 0,I,I))):J)(ft(o=>o.startT<=n&&n<o.endT,t.windows));return r.length===0?J:N("Just",(()=>{const o=ir(r);return{x:o.x*t.placement.scale+t.placement.tx,y:o.y*t.placement.scale+t.placement.ty,w:o.w*t.placement.scale,h:o.h*t.placement.scale}})())},fk=t=>e=>{const n=Zb(t)(e.endT+1e-4);return n.tag==="Just"?N("Just",{x:n._1.x*t.placement.scale+t.placement.tx,y:n._1.y*t.placement.scale+t.placement.ty,w:n._1.w*t.placement.scale,h:n._1.h*t.placement.scale}):J},hh=t=>e=>n=>r=>o=>i=>{const s=o(i.fromCam),a=o(i.toCam),u=_k(r)(i),c=fk(r)(i);return s.zoom===a.zoom&&s.center.x===a.center.x&&s.center.y===a.center.y?{...i,fromCam:Dg(t)(e)(n)(r)(c)(u)(s),toCam:Dg(t)(e)(n)(r)(c)(u)(a)}:{...i,fromCam:s,toCam:Dg(t)(e)(n)(r)(c)(u)(a)}},ph=t=>e=>n=>r=>o=>i=>i.intent==="ActionFocus"?hh(t)(e)(n)(r)(Bg(t)(e)(n)(r)(o))(i):{...i,fromCam:Bg(t)(e)(n)(r)(o)(i.fromCam),toCam:Bg(t)(e)(n)(r)(o)(i.toCam)},mh=t=>e=>n=>r=>o=>i=>{const s=re(a=>a.intent==="ActionFocus"&&a.startT>=r.startT-1e-4)(i);if(s.tag==="Just"){const a=ph(t)(e)(n)(r)(o)(s._1).toCam;return{...o,center:a.center,zoom:a.zoom<o.zoom?a.zoom:o.zoom}}if(s.tag==="Nothing")return o;g()},dk=t=>e=>n=>r=>o=>mh(t)(e)(n)(r)(_h(t)(e)(n)(r))(o),lk=t=>e=>n=>r=>o=>o.intent==="ActionFocus"?hh(t)(e)(n)(r)(Lb)(o):o,Ba=t=>e=>n=>r=>o=>i=>Lg(q(qb(t)(e)(n)(i))(sk(i)((()=>{const s=ch(t)(e)(n)(r)(o)(i);if(i.placement.scale===1&&i.placement.tx===0&&i.placement.ty===0)return lh(i)(o.dives)(dh(oh(Lg(q(lk(t)(e)(n)(i))(s)))));const a=_h(t)(e)(n)(i),u=mh(t)(e)(n)(i)(a)(s);return s.length===0?[{startT:i.startT,endT:i.endT,fromCam:u,toCam:u,easing:ef,interp:br,intent:sf}]:gk()(i)(ok(u)(i)(lh(i)(o.dives)(dh(oh(Lg(ik(u)(q(ph(t)(e)(n)(i)(a))(s))))))))})()))),hk=t=>e=>n=>r=>o=>Pt(i=>s=>ot.compare(i.startT)(s.startT))(Et(o.segments)(Ba(t)(e)(n)(r)(o))),pk=t=>e=>n=>r=>o=>i=>s=>{if(i.direction==="DiveIn")return Ii(t)(n)(Ba(t)(e)(n)(r)(o)(s))(i.startT-1e-4).camera;if(i.direction==="DiveOut")return Ii(t)(n)(Ba(t)(e)(n)(r)(o)(s))(i.endT+1e-4).camera;g()},mk=t=>e=>n=>r=>o=>vt(i=>{const s=Gb(o)(i.parentPath)(i.startT)(i.endT);if(s.tag==="Just"){const a=i.childPath,u=re(c=>Ga(c.path)(a))(o.segments);if(u.tag==="Just"){const c=Ba(t)(e)(n)(r)(o)(u._1),_=dk(t)(e)(n)(u._1)(ch(t)(e)(n)(r)(o)(u._1)),d=pk(t)(e)(n)(r)(o)(i)(s._1),l=(()=>{if(i.direction==="DiveIn")return _;if(i.direction==="DiveOut")return Ii(t)(n)(c)(i.startT-1e-4).camera;g()})();if(i.direction==="DiveIn")return N("Just",{startT:i.startT,endT:i.endT,fromCam:d,toCam:l,easing:$r,interp:of,intent:af});if(i.direction==="DiveOut")return N("Just",{startT:i.startT,endT:i.endT,fromCam:l,toCam:d,easing:$r,interp:of,intent:af});g()}if(u.tag==="Nothing")return J;g()}if(s.tag==="Nothing")return J;g()})(o.dives),yh=t=>e=>n=>r=>o=>[...mk(t)(e)(n)(r)(o),...hk(t)(e)(n)(r)(o)],to=(t,e)=>({tag:t,_1:e}),Da=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Nn=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},xh=ce(P)(Mt),wh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Jh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},Nh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},vh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},wi=(()=>{const t=nn.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return N("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,kt("Cons",r._3,n(r._6,o)));g()};return n(e,$)})())})(),yk=v(t=>e=>rt(P)(e)()(t))(I),Rg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Th=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},xk=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Ra=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},wk=to("NoKeyframes"),Jk=t=>to("DuplicateEventId",t),Nk=t=>to("UnknownEvent",t),vk=t=>e=>({...e,cameraSpans:yh(e.cameraConfig)(t)(e.layout)(e.keyframes)({endT:e.totalDuration,spans:e.spans,windows:e.windows,segments:e.segments,dives:e.dives})}),Tk=t=>e=>n=>r=>{const o=Da(r.edge)(e.edges),i=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return Bi(o._1);g()})(),s=Nn(t.minTokenDuration)(Nn(nt(v(a=>u=>a+Yo(u).length|0)(0)(r.labels))*t.tokenReadSecPerChar)(t.tokenSpeed<=0?0:i/t.tokenSpeed))+n.post;return{duration:s,holdPre:0,holdPost:s<=0?0:n.post/s}},Ck=ys(t=>{const e=Kr(`
11
+ `)(t);return e.length===0?[""]:e}),bk=t=>e=>xh(vt(n=>{if(n.kind.tag==="SendToken")return N("Just",b(n.id,{post:(()=>{const r=n.id;return(()=>{const o=n.kind._1.to;return Ne(i=>{if(i.kind.tag==="SendToken")return(i.when.tag==="First"?!1:i.when.tag==="After"&&i.when._1===r)&&i.kind._1.from===o;if(i.kind.tag==="FillNodeWithoutTransition")return!1;g()},e)})()?0:t.tokenHold})()}));if(n.kind.tag==="FillNodeWithoutTransition")return J;g()})(e)),kk=t=>{if(t.event.kind.tag==="SendToken")return N("Just",{startT:t.startT,endT:t.endT,target:Xo("TokenWindow",t.event.id,t.event.kind._1.edge,t.event.kind._1.direction,t.event.kind._1.from,t.event.kind._1.to,t.event.kind._1.labels,t.holdPre,t.holdPost)});if(t.event.kind.tag==="FillNodeWithoutTransition")return N("Just",{startT:t.startT,endT:t.endT,target:Xo("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});g()},Sk=t=>vt((()=>{const e=t.path;return n=>n.target.tag==="TokenWindow"?N("Just",{path:e,eventId:n.target._1,window:n,from:n.target._4,to:n.target._5,labels:n.target._6,holdPre:n.target._7,holdPost:n.target._8}):J})())(t.windows),Lk=t=>e=>n=>{const r=Da(n)(t);if(r.tag==="Nothing")return yf;if(r.tag==="Just"){const o=wh(r._1.target)(e);return wh(r._1.source)(e)?o?_y:gy:yf}g()},Ch=t=>e=>{if(t.tag==="Just"&&t._1>e.endT+1e-4){const n=Nn(0)(e.endT-e.startT),r=Nn(e.startT)(t._1-n);return{...e,startT:r,endT:r+n}}return e},bh=q(Ci),Ek={post:0},Gk=t=>e=>n=>r=>o=>{const i=Jh(o.event.id)(n),s=(()=>{if(i.tag==="Nothing")return Ek;if(i.tag==="Just")return i._1;g()})(),a=(()=>{if(o.event.when.tag==="First")return 0;if(o.event.when.tag==="At")return o.event.when._1;if(o.event.when.tag==="After"){const c=o.event.when._1,_=re(d=>d.event.id===c)(r);if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1.endT;g()}if(o.event.when.tag==="With"){const c=o.event.when._1,_=re(d=>d.event.id===c)(r);if(_.tag==="Nothing")return 0;if(_.tag==="Just")return _._1.startT}g()})(),u=(()=>{if(o.event.kind.tag==="SendToken")return Tk(t)(e)(s)(o.event.kind._1);if(o.event.kind.tag==="FillNodeWithoutTransition")return{duration:t.plop,holdPre:0,holdPost:0};g()})();return St(r)({startT:a,endT:a+u.duration,event:o.event,holdPre:u.holdPre,holdPost:u.holdPost})},kh=t=>e=>n=>v(Gk(t)(e)(bk(t)(n)))([])(Ht(r=>o=>({event:o}))(n)),Pk=t=>v(e=>n=>{const r=Nr(e);if(r.tag==="Nothing")return[n];if(r.tag==="Just")return n.startT<=r._1.last.endT+1e-4?St(r._1.init)({...r._1.last,endT:Nn(r._1.last.endT)(n.endT)}):St(e)(n);g()})([])(Pt(e=>n=>ot.compare(e.startT)(n.startT))(t)),Bk=t=>e=>{const n=Nh(e)(t.interiors);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;g()},Dk=t=>e=>{const n=Pt(ot.compare)(vt(r=>r.target.tag==="TokenWindow"?r.target._4===e||r.target._5===e?N("Just",r.startT):J:r.target.tag==="FillWindow"&&r.target._2===e?N("Just",r.startT):J)(t));return 0<n.length?N("Just",n[0]):J},Rk=t=>e=>{const n=Pt(ot.compare)(vt(r=>r.target.tag==="TokenWindow"&&r.target._2===e?N("Just",r.startT):J)(t));return 0<n.length?N("Just",n[0]):J},Ak=t=>e=>e.target.tag==="NodeWindow"?e.target._2==="PlopIn"?Ch(Dk(t.windows)(e.target._1))(e):e:e.target.tag==="EdgeWindow"&&e.target._2.tag==="Extend"?Ch(Rk(t.windows)(e.target._1))(e):e,Ik=t=>({...t,windows:Pt(e=>n=>ot.compare(e.startT)(n.startT))(q(Ak(t))(t.windows))}),Fk=t=>{if(t.when.tag==="First")return[];if(t.when.tag==="At")return[];if(t.when.tag==="After")return[t.when._1];if(t.when.tag==="With")return[t.when._1];g()},Sh={id:"",nodes:I,edges:I,kind:Di},Qk=t=>e=>g2((()=>{const n=vh(e.from)(t);if(n.tag==="Nothing")return Sh;if(n.tag==="Just")return n._1;g()})())((()=>{const n=vh(e.to)(t);if(n.tag==="Nothing")return Sh;if(n.tag==="Just")return n._1;g()})()),zk=t=>e=>{const n=Nh(e)(t.interiors);if(n.tag==="Nothing")return{layout:t.layout,interiors:I};if(n.tag==="Just")return n._1;g()},Lh={id:"",index:-1,kind:"",name:"",time:0,endTime:0,path:[],tokenIndex:-1,lineIndex:-1,text:"",from:"",to:""},Mk=t=>e=>e.scene.tag==="StepScene"?N("Just",{...Lh,id:"step:"+e.scene._1,kind:"step",name:e.scene._1,time:e.startT,endTime:e.startT,path:bh(t)}):J,Wk=t=>vt(Mk(t.path))(t.spans),Ag=t=>e=>n=>r=>{const o=Da(r)(n.edges);if(o.tag==="Just")return t<=0?e:Nn(e)(Bi(o._1)/t);if(o.tag==="Nothing")return e;g()},Eh=t=>e=>n=>r=>o=>{const i=t.plop,s=Qk(n)(o),a=q(f=>({startT:0,endT:0+Ag(t.edgeSpeed)(t.minEdgeDuration)(e)(f),target:Xo("EdgeWindow",f,Fs("Extend",Zu))}))(wi(s.entering.edges)),u=q(f=>({startT:0,endT:i,target:Xo("NodeWindow",f,Ku)}))(wi(s.entering.nodes)),c=v(Nn)(0)(q(f=>Ag(t.edgeSpeed)(t.minEdgeDuration)(e)(f))(wi(s.leaving.edges))),_=f=>Ne(h=>{const p=Da(h)(r);if(p.tag==="Just")return p._1.source===f||p._1.target===f;if(p.tag==="Nothing")return!1;g()},wi(s.leaving.edges))?c:0,d=q(f=>({startT:_(f),endT:_(f)+t.plop,target:Xo("NodeWindow",f,sy)}))(wi(s.leaving.nodes)),l=q(f=>({startT:0,endT:Ag(t.edgeSpeed)(t.minEdgeDuration)(e)(f),target:Xo("EdgeWindow",f,Fs("Retract",Lk(r)(s.leaving.nodes)(f)))}))(wi(s.leaving.edges));return{duration:(()=>{const f=Pt(ot.compare)([...q(p=>p.endT)(l),...q(p=>p.endT)(d),...q(p=>p.endT)(u),...q(p=>p.endT)(a)]),h=f.length-1|0;return h>=0&&h<f.length?f[h]+t.gap:t.gap})(),windows:[...l,...d,...u,...a]}},Ok=t=>e=>n=>r=>o=>i=>q((()=>{const s=o.startT;return a=>({...a,startT:a.startT+s,endT:a.endT+s})})())(Eh(t)(e)(n)(r)(i).windows),qk=t=>vt(e=>Zt(Ao,e).length>1?N("Just",(()=>{const n=Ft(r=>J,r=>o=>N("Just",{head:r,tail:o}),Zt(Ao,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";g()})()):J)(I0(Ti)(Pt(P.compare)(t))),Hk=t=>{const e=q(r=>r.id)(t),n=yk(e);return[...q(Jk)(qk(e)),...q(Nk)(ft(r=>!Rg(r)(n),Et(t)(Fk)))]},$k=t=>{const e=xh(q(r=>b(r.id,(()=>{if(r.when.tag==="First")return[];if(r.when.tag==="At")return[];if(r.when.tag==="After")return[r.when._1];if(r.when.tag==="With")return[r.when._1];g()})()))(t)),n=r=>o=>i=>{if(Rg(i)(o))return[to("ScheduleCycle",[...Zt(fn.foldr,o),i])];if(Rg(i)(r))return[];const s=Jh(i)(e);if(s.tag==="Nothing")return[];if(s.tag==="Just")return Et(s._1)(n(rt(P)(i)()(r))(rt(P)(i)()(o)));g()};return Et(t)(r=>n(I)(I)(r.id))},Vk={plop:.5,gap:0,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:250,minTokenDuration:1.8,tokenHold:0,stillHold:1.8,hatchHold:0,tokenReadSecPerChar:.06,nodeEasing:w2,edgeEasing:$r,tokenEasing:ef,diveDur:1.2,retreatDur:1.2},Uk=t=>e=>n=>r=>q((()=>{const o=n.startT;return i=>({...i,startT:i.startT+o,endT:i.endT+o})})())(vt(kk)(kh(t)(e)(r.events))),Kk=t=>e=>n=>r=>o=>{if(o.scene.tag==="Structural")return Ok(t)(e)(n)(r)(o)(o.scene._1);if(o.scene.tag==="Hold")return[];if(o.scene.tag==="DataFlow")return Uk(t)(e)(o)(o.scene._1);if(o.scene.tag==="EnterNode")return[];if(o.scene.tag==="ExitNode")return[];if(o.scene.tag==="StepScene")return[];g()},Yk=t=>e=>n=>{const r=kh(t)(e)(n.events);return r.length===0?t.gap:v(Nn)(0)(q(o=>o.endT)(r))+t.gap},Xk=t=>e=>n=>r=>o=>{if(o.tag==="Structural")return Eh(t)(e)(n)(r)(o._1).duration;if(o.tag==="Hold")return t.stillHold;if(o.tag==="DataFlow")return Yk(t)(e)(o._1);if(o.tag==="EnterNode"||o.tag==="ExitNode"||o.tag==="StepScene")return 0;g()},Gh=t=>e=>n=>r=>o=>i=>{const s=jm(e)(r),a=n.layout,u=j_(q(p=>b(p.id,p))(o.keyframes)),c=0<o.keyframes.length?N("Just",o.keyframes[0]):J,_=(()=>{if(c.tag==="Just")return c._1.id;if(c.tag==="Nothing")return"";g()})(),d=y2(o),l=p=>({segments:p.runSpans.length===0?p.segments:St(p.segments)({startT:p.runStart,endT:p.t,path:r,layout:a,placement:s,windows:p.runWindows,spans:p.runSpans,keyframes:u,initialKeyframe:_,edgeEndpoints:d}),spans:p.spans,windows:p.windows,dives:p.dives}),f=v(p=>m=>{if(m.tag==="EnterNode"){const T=l(p),C=p.t+t.diveDur,S=St(r)(m._1),E=Gh(t)(e)(zk(n)(m._1))(S)(Bk(o)(m._1))(C),B=E.endT+t.retreatDur;return{...p,t:B,runStart:B,runSpans:[],runWindows:[],segments:[...T.segments,...E.segments],spans:[...T.spans,...E.spans],windows:[...T.windows,...E.windows],dives:[...T.dives,{startT:p.t,endT:C,node:m._1,parentPath:r,childPath:S,direction:ay},...E.dives,{startT:E.endT,endT:B,node:m._1,parentPath:r,childPath:S,direction:uy}]}}if(m.tag==="ExitNode")return p;const w=p.t+Xk(t)(a)(u)(d)(m),x={startT:p.t,endT:w,scene:m},y=Kk(t)(a)(u)(d)(x);return{...p,t:w,runSpans:St(p.runSpans)(x),runWindows:[...p.runWindows,...y],spans:St(p.spans)(x),windows:[...p.windows,...y]}})({t:i,runStart:i,runSpans:[],runWindows:[],segments:[],spans:[],windows:[],dives:[]})(o.scenes),h=l(f);return{endT:f.t,spans:h.spans,windows:Pt(p=>m=>ot.compare(p.startT)(m.startT))(h.windows),segments:h.segments,dives:h.dives}},jk=t=>e=>{const n=ot.compare(t.time)(e.time);return n==="EQ"?P.compare(t.id)(e.id):n},Bn=t=>e=>e-v(n=>r=>n+Nn(0)(Th(e)(r.endT)-r.startT))(0)(t),Zk=t=>e=>{const n=Nn(t.startT)(e.startT),r=Th(t.endT)(e.endT);return r>n+1e-4?N("Just",{startT:n,endT:r}):J},t5=t=>e=>{if(e.scene.tag==="Structural"){const n=v(r=>o=>({cursor:Nn(r.cursor)(o.endT),cuts:o.startT>r.cursor+1e-4?St(r.cuts)({startT:r.cursor,endT:o.startT}):r.cuts}))({cursor:e.startT,cuts:[]})(Pt(r=>o=>ot.compare(r.startT)(o.startT))(vt(Zk(e))(t)));return e.endT>n.cursor+1e-4?St(n.cuts)({startT:n.cursor,endT:e.endT}):n.cuts}return[]},e5=t=>{const e=Pk(Et(t.spans)(t5(t.windows)));return e.length===0?t:{...t,endT:Bn(e)(t.endT),spans:q(n=>({...n,startT:Bn(e)(n.startT),endT:Bn(e)(n.endT)}))(t.spans),windows:Pt(n=>r=>ot.compare(n.startT)(r.startT))(q(n=>({...n,startT:Bn(e)(n.startT),endT:Bn(e)(n.endT)}))(t.windows)),segments:q(n=>({...n,startT:Bn(e)(n.startT),endT:Bn(e)(n.endT),spans:q(r=>({...r,startT:Bn(e)(r.startT),endT:Bn(e)(r.endT)}))(n.spans),windows:Pt(r=>o=>ot.compare(r.startT)(o.startT))(q(r=>({...r,startT:Bn(e)(r.startT),endT:Bn(e)(r.endT)}))(n.windows))}))(t.segments),dives:q(n=>({...n,startT:Bn(e)(n.startT),endT:Bn(e)(n.endT)}))(t.dives)}},n5=t=>{const e=q(Ik)(t.segments);return e5({...t,segments:e,windows:Pt(n=>r=>ot.compare(n.startT)(r.startT))(Et(e)(n=>n.windows))})},r5=t=>e=>n=>{const r=Nn(.05)(1-t-e),o=u=>{if(u<=0)return 0;if(u>=1)return 1;const c=t+u*r;return c<0?0:c>1?1:c},i=Ck(n),s=q(u=>nt(xk(1)(Yo(u).length)))(i),a=Nn(1)(v(er)(0)(s));return Ht(u=>c=>({lineIndex:u,text:c,start:o(v(er)(0)(u<1?[]:Rt(0,u,s))/a),end:o(u>=0&&u<s.length?(v(er)(0)(u<1?[]:Rt(0,u,s))+s[u])/a:(v(er)(0)(u<1?[]:Rt(0,u,s))+1)/a)}))(i)},o5=t=>{const e=Nn(0)(t.window.endT-t.window.startT);return q(n=>({...Lh,id:"token:"+t.eventId+":line:"+ie(n.lineIndex),kind:"tokenLine",time:t.window.startT+n.start*e,endTime:t.window.startT+n.end*e,path:bh(t.path),tokenIndex:t.tokenIndex,lineIndex:n.lineIndex,text:n.text,from:t.from,to:t.to}))(r5(t.holdPre)(t.holdPost)(t.labels))},i5=t=>Et(Ht(e=>n=>({path:n.path,eventId:n.eventId,window:n.window,from:n.from,to:n.to,labels:n.labels,holdPre:n.holdPre,holdPost:n.holdPost,tokenIndex:e}))(Et(t)(Sk)))(o5),s5=t=>Ht(e=>n=>({...n,index:e}))(Pt(jk)([...Et(t.segments)(Wk),...i5(t.segments)])),a5=t=>e=>{if(e.tag==="Structural")return vt(n=>n)([Ra(e._1.from)(t)?J:N("Just",to("UnknownKeyframe",e._1.from)),Ra(e._1.to)(t)?J:N("Just",to("UnknownKeyframe",e._1.to))]);if(e.tag==="Hold")return vt(n=>n)([Ra(e._1)(t)?J:N("Just",to("UnknownKeyframe",e._1))]);if(e.tag==="DataFlow")return[...vt(n=>n)([Ra(e._1.keyframe)(t)?J:N("Just",to("UnknownKeyframe",e._1.keyframe))]),...Hk(e._1.events),...$k(e._1.events)];if(e.tag==="EnterNode")return[];if(e.tag==="ExitNode")return[];if(e.tag==="StepScene")return[];g()},u5=t=>e=>{const n=Et(e)(a5(t));return n.length===0?Wt("Right",void 0):Wt("Left",n)},c5=t=>e=>n=>r=>{if(0<n.keyframes.length){const o=n.keyframes[0],i=j_(q(a=>b(a.id,a))(n.keyframes)),s=u5(i)(n.scenes);return(()=>{if(s.tag==="Left"){const a=s._1;return u=>Wt("Left",a)}if(s.tag==="Right"){const a=s._1;return u=>u(a)}g()})()(()=>{const a=n5(Gh(e)(r)(r)([])(n)(0));return Wt("Right",{totalDuration:a.endT,windows:a.windows,spans:a.spans,keyframes:i,initialKeyframe:o.id,timing:e,layout:r.layout,cameraSpans:yh(t)(F2)(r.layout)(i)(a),cameraConfig:t,levelTree:r,segments:a.segments,dives:a.dives,cues:s5(a),seed:n.seed})})}return Wt("Left",[wk])},Eo=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(o=>n(o._1)(o._2)),Apply0:()=>Ph(t)}),Ph=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>o=>i=>e.map(s=>b(r(s._1),s._2))(o(i))};return{apply:(()=>{const r=Eo(t);return o=>i=>r.bind(o)(s=>r.bind(i)(a=>Go(t).pure(s(a))))})(),Functor0:()=>n}},Go=t=>({pure:e=>n=>t.Applicative0().pure(b(e,n)),Apply0:()=>Ph(t)}),Bh=t=>{const e={Applicative0:()=>Go(t),Bind1:()=>Eo(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},Po=(t,e)=>({tag:t,_1:e}),pr=(t,e)=>({tag:t,_1:e}),Aa=t=>t,Un=(t,e)=>({tag:t,_1:e}),Ig=t=>t,Je=Bh(kn),g5=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},_5=ce(P)(Mt),Fg=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},f5=v(t=>e=>rt(P)(e)()(t))(I),Vt=Eo(kn),He=Je.state(t=>b(t,t)),ge=Go(kn),Dh=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Rh=Qr(ge),Qg=Rh(Mt),d5=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},mr=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},l5=(()=>{const t=nn.unfoldr(e=>{if(e.tag==="Nil")return J;if(e.tag==="Cons")return N("Just",b(e._1,e._2));g()});return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,kt("Cons",r._3,n(r._6,o)));g()};return n(e,$)})())})(),Kn=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},h5=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},Ia=t=>e=>n=>v(r=>o=>t.Bind1().bind(r)(i=>e(i)(o)))(t.Applicative0().pure(n)),p5=v(t=>e=>rt(P)(e)()(t))(I),m5=(()=>{const t=(e=>n=>{let r=e,o=n,i=!0,s;for(;i;){const a=r,u=o;if(u.tag==="Nil"){i=!1,s=a;continue}if(u.tag==="Cons"){r=rt(P)(u._1)()(a),o=u._2;continue}g()}return s})(I);return e=>t((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,kt("Cons",r._3,n(r._6,o)));g()};return n(e,$)})())})(),y5=Rh(f_),x5=v(t=>e=>rt(P)(e)()(t))(I),w5=Ig("AnimatedSurface"),J5=Ig("StillSurface"),N5=Ig("SequenceSurface"),v5=Un("Exit"),Fa=Aa("AnimatedKeyframe"),zg=Aa("Still"),T5=Aa("Title"),Ah=Aa("StepMarker"),C5=t=>pr("Par",t),b5=t=>pr("Seq",t),k5=t=>pr("GroupSeq",t),Ih=t=>Po("StepDive",t),S5={line:0,column:0,endLine:0,endColumn:0},L5=t=>e=>n=>{const r=io(Kt,J,o=>o._1===t,n);if(r.tag==="Just"){const o=Mr(Kt,J,r._1,b(t,e),n);if(o.tag==="Nothing")return n;if(o.tag==="Just")return o._1;g()}if(r.tag==="Nothing")return St(n)(b(t,e));g()},E5=t=>e=>q(n=>n._1===t?b(n._1,{...n._2,label:N("Just",e)}):b(n._1,n._2)),Fh=t=>{const e=t.compare;return n=>v(r=>o=>Qe(e,Ie,r,n(o)))(I)},Mg=Fh(P),Wg=Fh(P),G5=t=>{const e=t.span;return Je.state(n=>b(void 0,{...n,currentSpan:e}))},P5=t=>e=>({structural:[...t.structural,...e.structural],flow:t.flow||e.flow,dives:[...t.dives,...e.dives]}),B5=t=>e=>e.kind==="Animated"||g5(e.id)(t),Qh={graphNodes:[],graphEdges:I,currNodes:I,currEdges:I,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:J,currentSpan:S5,error:J,enterStack:[],interiorOf:I,stepNames:I},zh=t=>e=>n=>{const r=Zt(fn.foldr,n);return sr(", ")(q(e)(Rt(0,6,r)))+(r.length>6?", \u2026":"")},D5=t=>e=>{const n=Fg(e)(_5(q(r=>b(r.id,r))(t.graph.edges)));if(n.tag==="Just")return(()=>{const r=ao("conn:")(n._1.id);if(r.tag==="Just")return!1;if(r.tag==="Nothing")return!0;g()})()?n._1.from.node+" -> "+n._1.to.node:n._1.from.node+" -- "+n._1.to.node;if(n.tag==="Nothing")return e;g()},R5=t=>e=>n=>{const r=zh()(Ci)(e),o=zh()(D5(t))(n);return(r===""?"animated flow contains unused topology: every animated node or edge must be visited by a token or fill.":"animated flow contains unused topology: every animated node or edge must be visited by a token or fill. Unused nodes: "+r+".")+(o===""?"":" Unused edges: "+o+".")+" Move context-only topology into a `still`/`title`, remove it, or add token/fill events."},A5=t=>{if(t.kind.tag==="SendToken")return f5([t.kind._1.from,t.kind._1.to]);if(t.kind.tag==="FillNodeWithoutTransition")return te("Node",1,1,t.kind._1.node,void 0,I,I);g()},I5=t=>Mg(A5)(t.events),F5=t=>{if(t.kind.tag==="SendToken")return te("Node",1,1,t.kind._1.edge,void 0,I,I);if(t.kind.tag==="FillNodeWithoutTransition")return I;g()},Q5=t=>Wg(F5)(t.events),Yn=t=>Je.state(e=>b(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:N("Just",{msg:t,line:e.currentSpan.line,column:e.currentSpan.column,endLine:e.currentSpan.endLine,endColumn:e.currentSpan.endColumn})};g()})())),z5=Qg(t=>Vt.bind(He)(e=>{if(e.error.tag==="Just")return ge.pure();if(e.error.tag==="Nothing")return Dh(t.node)(e.interiorOf)?Yn("node "+t.node+" has more than one `inside` block"):Je.state(n=>b(void 0,{...n,interiorOf:rt(P)(t.node)(t.doc)(n.interiorOf)}));g()})),M5=t=>Vt.bind(He)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+ie(e.kfCounter);if(Ne(o=>o.id===n,e.keyframes))return Yn("duplicate frame name "+n);const r={...e,keyframes:St(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges,kind:Di}),kfCounter:e.kfCounter+1|0,currentKf:N("Just",n)};return Je.state(o=>b(void 0,r))}),un=t=>e=>Vt.bind(Je.state(n=>b(void 0,{...n,currentSpan:t})))(()=>Yn(e)),Mh=t=>e=>Vt.bind(He)(n=>d5(e)(n.stepNames)?un(t)("duplicate step name "+e):Je.state(r=>b(void 0,{...r,scenes:St(r.scenes)(Vo("StepScene",e)),stepNames:rt(P)(e)()(r.stepNames)}))),W5=t=>{if(t.ops.tag==="Leaf"){const e=t.ops._1;return Vt.bind((()=>{const n=e.span;return Je.state(r=>b(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?Mh(e.span)(e.op._1.name):Yn("step marker frame did not contain a step"))}if(t.ops.tag==="Seq"&&t.ops._1.length===1&&t.ops._1[0].tag==="Leaf"){const e=t.ops._1[0]._1;return Vt.bind((()=>{const n=e.span;return Je.state(r=>b(void 0,{...r,currentSpan:n}))})())(()=>e.op.tag==="Step"?Mh(e.span)(e.op._1.name):Yn("step marker frame did not contain a step"))}return Yn("step marker frame did not contain a step")},O5=t=>Vt.bind((()=>{const e=t.span;return Je.state(n=>b(void 0,{...n,currentSpan:e}))})())(()=>Vt.bind(He)(e=>{if(e.error.tag==="Just")return ge.pure();if(e.error.tag==="Nothing"){if(t.op.tag==="Enter"){if(!mr(t.op._1.id)(e.currNodes))return un(0<t.operands.length?t.operands[0]:t.span)("cannot dive into node "+t.op._1.id+": does not exist");if(!Dh(t.op._1.id)(e.interiorOf))return un(0<t.operands.length?t.operands[0]:t.span)("cannot enter node "+t.op._1.id+": it has no `inside` block. Add the block at the document level, alongside the animated statements:\n\ninside "+t.op._1.id+` {
12
+ + detail: Detail
13
+ }`);const n=t.op._1;return Je.state(r=>b(void 0,{...r,enterStack:St(r.enterStack)(n.id),scenes:St(r.scenes)(Vo("EnterNode",n.id))}))}if(t.op.tag==="Exit"){const n=Nr(e.enterStack);if(n.tag==="Nothing")return Yn("`out` without a matching `into`");if(n.tag==="Just"){const r=n._1.init;return Je.state(o=>b(void 0,{...o,enterStack:r,scenes:St(o.scenes)(u2)}))}g()}return ge.pure()}g()})),Qa={structural:[],flow:!1,dives:[]},q5=Vt.bind(He)(t=>{if(t.error.tag==="Just")return ge.pure();if(t.error.tag==="Nothing"){if(t.currentKf.tag==="Just"){const e=t.currentKf._1;return Je.state(n=>b(void 0,{...n,scenes:St(n.scenes)(Vo("Hold",e))}))}if(t.currentKf.tag==="Nothing")return ge.pure()}g()}),H5=t=>e=>Vt.bind(He)(n=>{const r="ev-"+ie(n.eventCounter);return Vt.bind((()=>{const o={...n,eventCounter:n.eventCounter+1|0};return Je.state(i=>b(void 0,o))})())(()=>ge.pure({events:[{id:r,kind:e,when:t}],firstId:N("Just",r),lastId:N("Just",r)}))}),$5=t=>t.tag==="DataFlow"?N("Just",t._1):J,V5=t=>vt(e=>Fg(e)(t.graphEdges))(Zt(Ao,l5(t.currEdges))),U5=t=>e=>{const n=ft(o=>o.from.node===e.id||o.to.node===e.id,V5(t)),r=Ia(c_)(o=>i=>{const s=i.from+"->"+e.id,a=e.id+"->"+i.to,u=i.from+"->"+i.to,c="via "+i.from+" "+i.to+": no edge "+i.from+"\u2192"+e.id;if(!Kn(s)(t.currEdges))return Wt("Left",c);const _="via "+i.from+" "+i.to+": no edge "+e.id+"\u2192"+i.to;if(!Kn(a)(t.currEdges))return Wt("Left",_);const d="via "+i.from+" "+i.to+": would create "+i.from+"\u2192"+i.to+" but it already exists";return Kn(u)(t.currEdges)||h5(u)(o.synthesized)?Wt("Left",d):Wt("Right",{consumed:rt(P)(s)()(rt(P)(a)()(o.consumed)),synthesized:rt(P)(u)({id:u,from:{node:i.from,port:J},to:{node:i.to,port:J},label:J})(o.synthesized)})})({consumed:I,synthesized:I})(e.via);return(()=>{if(r.tag==="Left"){const o=r._1;return i=>Wt("Left",o)}if(r.tag==="Right"){const o=r._1;return i=>i(o)}g()})()(o=>{const i=o.consumed,s=ft(a=>!Kn(a.id)(i),n);return s.length===0?Wt("Right",{nextCurrEdges:Qe(P.compare,Ie,$n(P.compare,t.currEdges,p5(q(a=>a.id)(n))),m5((()=>{const a=u=>{if(u.tag==="Leaf")return I;if(u.tag==="Node")return te("Node",u._1,u._2,u._3,void 0,a(u._5),a(u._6));g()};return a(o.synthesized)})())),synthesized:o.synthesized}):Wt("Left","cannot delete node "+e.id+": still connected ("+sr(", ")(q(a=>(()=>{const u=ao("conn:")(a.id);if(u.tag==="Just")return!1;if(u.tag==="Nothing")return!0;g()})()?a.from.node+"\u2192"+a.to.node:a.from.node+"--"+a.to.node)(s))+"). Use `- a -> b` or `- a -- b` to drop them, or `via a b` to merge "+e.id+"'s endpoints.")})},Wh=t=>e=>n=>{if(t){if(e){const i=0<n.operands.length?n.operands[0]:n.span,s=1<n.operands.length?n.operands[1]:n.span;return{line:i.line,column:i.column,endLine:s.endLine,endColumn:s.endColumn}}return 0<n.operands.length?n.operands[0]:n.span}if(e)return 1<n.operands.length?n.operands[1]:n.span;const r=0<n.operands.length?n.operands[0]:n.span,o=1<n.operands.length?n.operands[1]:n.span;return{line:r.line,column:r.column,endLine:o.endLine,endColumn:o.endColumn}},Oh=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq"||t.tag==="GroupSeq")return Et(t._1)(Oh);g()},K5=t=>({nodes:q(ps)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,kt("Cons",n._4,e(n._6,r)));g()};return Zt(de.foldr,e(t.graphEdges,$))})(),constraints:[]}),Og=t=>{if(t.tag==="Leaf")return t._1.op.tag==="AddNode"||t._1.op.tag==="DelNode"||t._1.op.tag==="ModNode"||t._1.op.tag==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?{...Qa,structural:[t._1]}:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?{...Qa,dives:[t._1]}:{...Qa,flow:!0};if(t.tag==="Seq"||t.tag==="GroupSeq"||t.tag==="Par")return v(P5)(Qa)(q(Og)(t._1));g()},za=t=>{if(t.tag==="Leaf")return t._1.op.tag==="AddNode"||t._1.op.tag==="DelNode"||t._1.op.tag==="ModNode"||t._1.op.tag==="AddEdge"||t._1.op.tag==="DelEdge"||t._1.op.tag==="RepointEdge"?[Po("StepStructural",[t._1])]:t._1.op.tag==="Enter"||t._1.op.tag==="Exit"?[Po("StepDive",t._1)]:[Po("StepFlow",t)];if(t.tag==="Seq")return Et(t._1)(za);if(t.tag==="GroupSeq")return X5(t)(t._1);if(t.tag==="Par")return Y5(t)(t._1);g()},Y5=t=>e=>{const n=Og(t);return n.structural.length!==0&&!n.flow&&n.dives.length===0?[Po("StepStructural",n.structural)]:n.structural.length===0&&n.flow&&n.dives.length===0?[Po("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?q(Ih)(n.dives):Et(e)(za)},X5=t=>e=>{const n=Og(t);return n.structural.length===0&&n.flow&&n.dives.length===0?[Po("StepFlow",t)]:n.structural.length===0&&!n.flow&&n.dives.length!==0?q(Ih)(n.dives):Et(e)(za)},j5=t=>e=>Vt.bind(He)(n=>{const r=e.from+"->"+e.to,o=e.newFrom+"->"+e.newTo;return Kn(r)(n.currEdges)?mr(e.newFrom)(n.currNodes)?mr(e.newTo)(n.currNodes)?r!==o&&Kn(o)(n.currEdges)?un((()=>{const i=2<t.operands.length?t.operands[2]:t.span,s=3<t.operands.length?t.operands[3]:t.span;return{line:i.line,column:i.column,endLine:s.endLine,endColumn:s.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists"):Je.state(i=>b(void 0,{...i,currEdges:rt(P)(o)()(Wo(P)(r)(i.currEdges)),graphEdges:rt(P)(o)({id:o,from:{node:e.newFrom,port:J},to:{node:e.newTo,port:J},label:J})(i.graphEdges)})):un(3<t.operands.length?t.operands[3]:t.span)("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo):un(2<t.operands.length?t.operands[2]:t.span)("cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newFrom):un((()=>{const i=0<t.operands.length?t.operands[0]:t.span,s=1<t.operands.length?t.operands[1]:t.span;return{line:i.line,column:i.column,endLine:s.endLine,endColumn:s.endColumn}})())("cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist")}),Z5=t=>{if(t.op.tag==="AddNode"){const e=t.op._1;return Vt.bind(He)(n=>mr(e.id)(n.currNodes)?un(0<t.operands.length?t.operands[0]:t.span)("cannot add node "+e.id+": already exists"):Je.state(r=>b(void 0,{...r,graphNodes:L5(e.id)({id:e.id,size:b(1,1),ports:[],label:N("Just",e.label),shape:e.shape})(r.graphNodes),currNodes:rt(P)(e.id)()(r.currNodes)})))}if(t.op.tag==="DelNode"){const e=t.op._1;return Vt.bind(He)(n=>{if(!mr(e.id)(n.currNodes))return un(0<t.operands.length?t.operands[0]:t.span)("cannot delete node "+e.id+": does not exist");const r=U5(n)(e);if(r.tag==="Left")return un(0<t.operands.length?t.operands[0]:t.span)(r._1);if(r.tag==="Right"){const o=r._1;return Je.state(i=>b(void 0,{...i,currNodes:Wo(P)(e.id)(i.currNodes),currEdges:o.nextCurrEdges,graphEdges:Qe(P.compare,Ie,o.synthesized,i.graphEdges)}))}g()})}if(t.op.tag==="ModNode"){const e=t.op._1;return Vt.bind(He)(n=>{if(!mr(e.id)(n.currNodes))return un(0<t.operands.length?t.operands[0]:t.span)("cannot modify node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=e.label._1;return Je.state(o=>b(void 0,{...o,graphNodes:E5(e.id)(r)(o.graphNodes)}))}if(e.label.tag==="Nothing")return ge.pure();g()})}if(t.op.tag==="AddEdge"){const e=t.op._1;return Vt.bind(He)(n=>{const r=!mr(e.from)(n.currNodes),o=!mr(e.to)(n.currNodes);if(r||o)return un(Wh(r)(o)(t))((e.directed?"cannot add edge ":"cannot add connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": unknown node "+(r?o?e.from+", "+e.to:e.from:o?e.to:""));const i=e.directed?e.from+"->"+e.to:e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;return Kn(i)(n.currEdges)?un((()=>{const s=0<t.operands.length?t.operands[0]:t.span,a=1<t.operands.length?t.operands[1]:t.span;return{line:s.line,column:s.column,endLine:a.endLine,endColumn:a.endColumn}})())((e.directed?"cannot add edge ":"cannot add connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": already exists"):Je.state(s=>b(void 0,{...s,graphEdges:rt(P)(i)({id:i,from:{node:e.from,port:J},to:{node:e.to,port:J},label:e.label})(s.graphEdges),currEdges:rt(P)(i)()(s.currEdges)}))})}if(t.op.tag==="DelEdge"){const e=t.op._1;return Vt.bind(He)(n=>{const r=e.directed?e.from+"->"+e.to:e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;return Kn(r)(n.currEdges)?Je.state(o=>b(void 0,{...o,currEdges:Wo(P)(r)(o.currEdges)})):un((()=>{const o=0<t.operands.length?t.operands[0]:t.span,i=1<t.operands.length?t.operands[1]:t.span;return{line:o.line,column:o.column,endLine:i.endLine,endColumn:i.endColumn}})())((e.directed?"cannot delete edge ":"cannot delete connection ")+(e.directed?e.from+"\u2192"+e.to:e.from+"--"+e.to)+": does not exist")})}return t.op.tag==="RepointEdge"?j5(t)(t.op._1):ge.pure()},tS=t=>Vt.bind((()=>{const e=t.span;return Je.state(n=>b(void 0,{...n,currentSpan:e}))})())(()=>Z5(t)),qh=t=>e=>n=>Vt.bind(Qg(tS)(n))(()=>Vt.bind(He)(r=>{const o=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ie(r.kfCounter);if(Ne(s=>s.id===o,r.keyframes))return Vt.bind(y5(G5)(0<n.length?N("Just",n[0]):J))(()=>Yn("duplicate frame name "+o));const i={...r,keyframes:St(r.keyframes)({id:o,nodes:r.currNodes,edges:r.currEdges,kind:t}),kfCounter:r.kfCounter+1|0,currentKf:N("Just",o),scenes:(()=>{if(r.currentKf.tag==="Nothing")return r.scenes;if(r.currentKf.tag==="Just")return St(r.scenes)(Vo("Structural",{from:r.currentKf._1,to:o,focus:J}));g()})()};return Je.state(s=>b(void 0,i))})),Hh=t=>e=>{const n=Oh(e.ops),r=ft(i=>i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge",n),o=ft(i=>!(i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge"),n);return 0<o.length?Vt.bind((()=>{const i=o[0].span;return Je.state(s=>b(void 0,{...s,currentSpan:i}))})())(()=>Yn("still/title blocks hold a still snapshot; they cannot contain movement tokens (`api ~> db`) or dive commands (`into`/`out`)")):t==="TitleCard"&&r.length===0?Yn(e.name.tag==="Just"&&e.name._1!==""?'title "'+e.name._1+'" has an empty body; give it nodes/edges to title, or use a still':"title has an empty body; give it nodes/edges to title, or use a still"):Vt.bind(qh(t)(e.name)(r))(()=>q5)},eS=t=>e=>{const n=vt($5)(e.scenes),r=ft(B5(x5(q(s=>s.keyframe)(n))),e.keyframes),o=$n(P.compare,Mg(s=>s.nodes)(r),Mg(I5)(n)),i=$n(P.compare,Wg(s=>s.edges)(r),Wg(Q5)(n));return t!=="AnimatedSurface"||n.length===0||o.tag==="Leaf"&&i.tag==="Leaf"?J:N("Just",R5(e)(o)(i))},nS=t=>e=>{const n=e.to+"->"+e.from,r=e.from+"->"+e.to,o=e.from<=e.to?"conn:"+e.from+"--"+e.to:"conn:"+e.to+"--"+e.from;if(Kn(r)(t.currEdges))return N("Just",{id:r,direction:Y_});if(Kn(n)(t.currEdges))return N("Just",{id:n,direction:X_});const i=Fg(o)(t.graphEdges);if(i.tag==="Just")return Kn(o)(t.currEdges)?N("Just",{id:o,direction:i._1.from.node===e.from&&i._1.to.node===e.to?Y_:X_}):J;if(i.tag==="Nothing")return J;g()},rS=t=>e=>{if(e.op.tag==="Token"){const n=e.op._1;return Vt.bind(He)(r=>{const o=!mr(n.from)(r.currNodes),i=!mr(n.to)(r.currNodes);if(o||i)return Vt.bind(un(Wh(o)(i)(e))(o?i?"token references unknown node: "+n.from+", "+n.to:"token references unknown node: "+n.from:i?"token references unknown node: "+n.to:"token references unknown node: "))(()=>ge.pure({events:[],firstId:J,lastId:J}));const s=nS(r)(n);if(s.tag==="Just")return H5(t)(o2("SendToken",{from:n.from,to:n.to,edge:s._1.id,direction:s._1.direction,labels:n.labels}));if(s.tag==="Nothing")return Vt.bind(un((()=>{const a=0<e.operands.length?e.operands[0]:e.span,u=1<e.operands.length?e.operands[1]:e.span;return{line:a.line,column:a.column,endLine:u.endLine,endColumn:u.endColumn}})())("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>ge.pure({events:[],firstId:J,lastId:J}));g()})}return ge.pure({events:[],firstId:J,lastId:J})},oS=t=>e=>{const n=Ft(r=>J,r=>o=>N("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return ge.pure({events:[],firstId:J,lastId:J});if(n.tag==="Just"){const r=n._1.tail;return Vt.bind(fs(t)(n._1.head))(o=>Vt.bind(Ia({Applicative0:()=>Go(kn),Bind1:()=>Eo(kn)})(i=>s=>Vt.bind(fs((()=>{if(i.lastId.tag==="Just")return zu("After",i.lastId._1);if(i.lastId.tag==="Nothing")return t;g()})())(s))(a=>ge.pure({events:[...i.events,...a.events],firstId:(()=>{if(i.firstId.tag==="Just")return N("Just",i.firstId._1);if(i.firstId.tag==="Nothing")return a.firstId;g()})(),lastId:(()=>{if(a.lastId.tag==="Just")return N("Just",a.lastId._1);if(a.lastId.tag==="Nothing")return i.lastId;g()})()})))(o)(r))(i=>ge.pure(i)))}g()},iS=t=>e=>{const n=Ft(r=>J,r=>o=>N("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return ge.pure({events:[],firstId:J,lastId:J});if(n.tag==="Just"){const r=n._1.tail;return Vt.bind(fs(t)(n._1.head))(o=>Vt.bind(sS((()=>{if(o.firstId.tag==="Just")return zu("With",o.firstId._1);if(o.firstId.tag==="Nothing")return t;g()})())(r))(i=>ge.pure({events:[...o.events,...i.events],firstId:o.firstId,lastId:(()=>{if(o.lastId.tag==="Just")return N("Just",o.lastId._1);if(o.lastId.tag==="Nothing")return i.lastId;g()})()})))}g()},fs=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return Vt.bind((()=>{const r=n.span;return Je.state(o=>b(void 0,{...o,currentSpan:r}))})())(()=>rS(t)(n))}if(e.tag==="Seq"||e.tag==="GroupSeq")return oS(t)(e._1);if(e.tag==="Par")return iS(t)(e._1);g()},sS=t=>Ia({Applicative0:()=>Go(kn),Bind1:()=>Eo(kn)})(e=>n=>Vt.bind(fs(t)(n))(r=>ge.pure({events:[...e.events,...r.events],firstId:(()=>{if(e.firstId.tag==="Just")return N("Just",e.firstId._1);if(e.firstId.tag==="Nothing")return r.firstId;g()})(),lastId:(()=>{if(r.lastId.tag==="Just")return N("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;g()})()})))({events:[],firstId:J,lastId:J}),aS=t=>Vt.bind(He)(e=>{if(e.currentKf.tag==="Nothing")return Yn("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return Vt.bind(fs(a2)(t))(r=>Vt.bind(He)(o=>{const i={...o,scenes:St(o.scenes)(Vo("DataFlow",{keyframe:n,events:r.events,focus:J}))};return Je.state(s=>b(void 0,i))}))}g()}),uS=t=>e=>n=>{if(n.tag==="StepStructural")return Vt.bind((()=>{const r=qh(Di)(e?J:t)(n._1);return n._1.length!==0?r:ge.pure()})())(()=>ge.pure(!0));if(n.tag==="StepFlow"){const r=n._1,o=!e&&(()=>{if(t.tag==="Just")return t._1!=="";if(t.tag==="Nothing")return!1;g()})();return Vt.bind((()=>{const i=M5(t);return o?i:ge.pure()})())(()=>Vt.bind(aS(r))(()=>ge.pure(e||o)))}if(n.tag==="StepDive")return Vt.bind(O5(n._1))(()=>ge.pure(e));g()},$h=t=>e=>n=>{const r=Ft(o=>J,o=>i=>N("Just",{head:o,tail:i}),n);if(r.tag==="Nothing")return ge.pure();if(r.tag==="Just"){const o=r._1.head,i=r._1.tail;return Vt.bind(He)(s=>{if(s.error.tag==="Just")return ge.pure();if(s.error.tag==="Nothing")return Vt.bind(uS(t)(e)(o))(a=>$h(t)(a)(i));g()})}g()},cS=t=>Vt.bind(He)(e=>{if(e.error.tag==="Just")return ge.pure();if(e.error.tag==="Nothing"){if(t.kind==="AnimatedKeyframe")return $h(t.name)(!1)(za(t.ops));if(t.kind==="Still")return Hh(i2)(t);if(t.kind==="Title")return Hh(s2)(t);if(t.kind==="StepMarker")return W5(t)}g()}),Vh=t=>Vt.bind(z5(t.interiors))(()=>Vt.bind(Qg(cS)(t.frames))(()=>Vt.bind(He)(e=>{if(e.error.tag==="Just")return ge.pure(Wt("Left",e.error._1));if(e.error.tag==="Nothing"){const n=gS(t.interiors);if(n.tag==="Left")return ge.pure(Wt("Left",n._1));if(n.tag==="Right"){const r={seed:t.seed,graph:K5(e),keyframes:e.keyframes,scenes:e.scenes,interiors:n._1};return ge.pure((()=>{const o=eS(t.mode)(r);if(o.tag==="Just")return Wt("Left",{msg:o._1,line:0,column:0,endLine:0,endColumn:0});if(o.tag==="Nothing")return Wt("Right",r);g()})())}}g()}))),gS=t=>{const e=Ia(c_)(n=>r=>{const o=Vh(r.doc)(Qh)._1;return(()=>{if(o.tag==="Left"){const i=o._1;return s=>Wt("Left",i)}if(o.tag==="Right"){const i=o._1;return s=>s(i)}g()})()(i=>Wt("Right",rt(P)(r.node)(i)(n)))})(I)(t);if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right")return Wt("Right",e._1);g()},yr=(t,e)=>({tag:"ParseError",_1:t,_2:e}),k=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),Ma=(t,e,n)=>({tag:t,_1:e,_2:n}),_S=t=>Ma("More",t),fS=t=>Ma("Lift",t),dS={defer:t=>{const e=Gm(t);return(n,r,o,i,s)=>Pm(e)(n,r,o,i,s)}},Uh={map:t=>e=>(n,r,o,i,s)=>r(a=>e(n,r,o,i,(u,c)=>r(_=>s(u,t(c)))))},lS={alt:t=>e=>(n,r,o,i,s)=>{const a=n._1,u=n._2;return r(c=>t(k(a,u,!1),r,o,(_,d)=>{const l=_._3;return r(f=>l?i(_,d):e(n,r,o,i,s))},s))},Functor0:()=>Uh},hS=t=>{const e=t.Monad0();return n=>r=>{const o=i=>{let s=i,a=!0,u;for(;a;){const c=s();if(c.tag==="More"){s=c._1;continue}if(c.tag==="Lift"){a=!1,u=e.Bind1().Apply0().Functor0().map(_u)(c._1);continue}if(c.tag==="Stop"){a=!1,u=e.Applicative0().pure(Ro("Done",b(c._2,c._1)));continue}g()}return u};return t.tailRecM(o)(i=>r(n,_S,fS,(s,a)=>Ma("Stop",s,Wt("Left",a)),(s,a)=>Ma("Stop",s,Wt("Right",a))))}},Xn=(t,e,n,r,o)=>o(t,t._2),pS={index:0,line:1,column:1},mS=(t=>{const e=hS(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(ms)(e(k(n,pS,!1))(r))})(u0),Wa=(t,e,n,r,o)=>o(k(t._1,t._2,!0),void 0),Kh={apply:t=>e=>(n,r,o,i,s)=>r(a=>t(n,r,o,i,(u,c)=>r(_=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return e(d,r,o,i,(l,f)=>r(h=>s(d._3&&!l._3?k(l._1,l._2,!0):l,c(f))))}))),Functor0:()=>Uh},Yh={pure:t=>(e,n,r,o,i)=>i(e,t),Apply0:()=>Kh},yS={bind:t=>e=>(n,r,o,i,s)=>r(a=>t(n,r,o,i,(u,c)=>r(_=>e(c)(n._3&&!u._3?k(u._1,u._2,!0):u,r,o,i,s)))),Apply0:()=>Kh},xS={Applicative0:()=>Yh,Bind1:()=>yS},Oa=t=>(e,n,r,o,i)=>n(s=>Xn(e,n,r,o,(a,u)=>n(c=>o(e._3&&!a._3?k(a._1,a._2,!0):a,yr(t,u))))),wS={empty:Oa("No alternative"),Alt0:()=>lS},JS={Applicative0:()=>Yh,Plus1:()=>wS},Dn=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return o=>t.tailRecM(i=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(_u)(o))(r.pure(Ro("Done",void 0))))(s=>r.pure((()=>{if(s.tag==="Loop")return Ro("Loop",kt("Cons",s._1,i));if(s.tag==="Done")return Ro("Done",(a=>u=>{let c=a,_=u,d=!0,l;for(;d;){const f=c,h=_;if(h.tag==="Nil"){d=!1,l=f;continue}if(h.tag==="Cons"){c=kt("Cons",h._1,f),_=h._2;continue}g()}return l})($)(i));g()})())))($)})({tailRecM:t=>e=>(n,r,o,i,s)=>{const a=(u,c,_)=>t(c)(u,r,o,i,(d,l)=>{const f=u._3&&!d._3?k(d._1,d._2,!0):d;if(l.tag==="Loop")return _===0?r(h=>a(f,l._1,30)):a(f,l._1,_-1|0);if(l.tag==="Done")return s(f,l._1);g()});return a(n,e,30)},Monad0:()=>xS})(JS),xt=t=>e=>{const n=Oa("Expected "+e);return(r,o,i,s,a)=>{const u=r._1,c=r._2;return o(_=>t(k(u,c,!1),o,i,(d,l)=>{const f=d._3;return o(h=>f?s(d,l):n(r,o,i,s,a))},a))}},Ji=t=>(e,n,r,o,i)=>{const s=e._3,a=e._1,u=e._2;return n(c=>{const _=(d,l)=>{const f=d._3;return n(h=>f?o(k(d._1,d._2,s),l):i(e,void 0))};return n(d=>n(l=>t(k(a,u,!1),n,r,(f,h)=>_(k(f._1,f._2,!1),h),(f,h)=>n(p=>n(m=>Oa("Negated parser succeeded")(f,n,r,_,(w,x)=>n(y=>i(f._3&&!w._3?k(w._1,w._2,!0):w,x))))))))})},NS=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return N("Just",n);if(r.tag==="Just")return N("Just",(o,i,s,a,u)=>{const c=o._1,_=o._2;return i(d=>n(k(c,_,!1),i,s,(l,f)=>{const h=l._3;return i(p=>h?a(l,f):r._1(o,i,s,a,u))},u))});g()})(J);return n=>{const r=e(n);if(r.tag==="Nothing")return Oa("No alternative");if(r.tag==="Just")return r._1;g()}},Xh=t=>e=>n=>(r,o,i,s,a)=>o(u=>o(c=>o(_=>o(d=>t(r,o,i,s,(l,f)=>o(h=>o(p=>{const m=r._3&&!l._3?k(l._1,l._2,!0):l;return n(m,o,i,s,(w,x)=>o(y=>{const T=m._3&&!w._3?k(w._1,w._2,!0):w;return o(C=>o(S=>{const E=r._3&&!T._3?k(T._1,T._2,!0):T;return e(E,o,i,s,(B,M)=>o(Y=>a(E._3&&!B._3?k(B._1,B._2,!0):B,x)))}))}))}))))))),qg=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=iy()(n);return r.tag==="Just"&&r._1===10?{index:t.index+1|0,line:t.line,column:t.column}:{index:t.index+1|0,line:t.line+1|0,column:1}}return e===9?{index:t.index+1|0,line:t.line,column:(t.column+8|0)-Wr(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},vS=t=>e=>n=>{let r=t,o=e,i=n,s=!0,a;for(;s;){const u=r,c=o,_=i,d=Is(c);if(d.tag==="Nothing"){s=!1,a=u;continue}if(d.tag==="Just"){r=d._1.tail===""?qg(u)(d._1.head)(_):qg(u)(d._1.head)(d._1.tail),o=d._1.tail,i=_;continue}g()}return a},At=t=>(e,n,r,o,i)=>{const s=Is(e._1);if(s.tag==="Nothing")return o(e,yr("Unexpected EOF",e._2));if(s.tag==="Just"){if(s._1.head<0||s._1.head>65535)return o(e,yr("Expected Char",e._2));if(s._1.head>=0&&s._1.head<=65535){const a=ff(s._1.head);return t(a)?i(k(s._1.tail,qg(e._2)(s._1.head)(s._1.tail),!0),a):o(e,yr("Predicate unsatisfied",e._2))}}g()},ds=(t,e,n,r,o)=>t._1===""?o(k(t._1,t._2,!0),void 0):r(t,yr("Expected EOF",t._2)),TS=t=>(e,n,r,o,i)=>{const s=t(e._1);if(s.tag==="Left")return o(e,yr(s._1,e._2));if(s.tag==="Right")return i(k(s._1.remainder,vS(e._2)(s._1.consumed)(s._1.remainder),s._1.consumed!==""),s._1.value);g()},cn=t=>TS(e=>{const n=ao(t)(e);return n.tag==="Just"?Wt("Right",{value:t,consumed:t,remainder:n._1}):Wt("Left","Expected "+Kp(t))}),CS=At(t=>!0),qa=(t,e)=>({tag:t,_1:e}),Hg=NS(Mt),bS=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},kS=ce(P)(Mt),SS=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},$g=(()=>{const t=xt(At(r=>r==="}"))("'}'"),e=xt(At(r=>r==="#"))("'#'"),n=At(r=>r===`
14
+ `||r==="\r");return(r,o,i,s,a)=>{const u=r._1,c=r._2;return o(_=>o(d=>t(k(u,c,!1),o,i,(l,f)=>o(h=>{const p=r._1,m=r._2;return o(w=>o(x=>e(k(p,m,!1),o,i,(y,T)=>o(C=>{const S=r._1,E=r._2;return o(B=>o(M=>n(k(S,E,!1),o,i,(Y,R)=>o(A=>ds(r,o,i,s,a)),(Y,R)=>o(A=>a(k(S,E,!1),void 0)))))}),(y,T)=>o(C=>a(k(p,m,!1),void 0)))))}),(l,f)=>o(h=>a(k(u,c,!1),void 0)))))}})(),vn=t=>(e,n,r,o,i)=>n(s=>Xn(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>t(_,n,r,o,(l,f)=>n(h=>{const p=_._3&&!l._3?k(l._1,l._2,!0):l;return n(m=>Xn(p,n,r,o,(w,x)=>n(y=>i(p._3&&!w._3?k(w._1,w._2,!0):w,b(f,{line:u.line,column:u.column,endLine:x.line,endColumn:x.column})))))})))}))),LS=(()=>{const t=At(e=>e===" "||e===" "||e===`
15
+ `||e==="\r");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>i(e._3&&!a._3?k(a._1,a._2,!0):a,void 0))))})(),jh=(t,e,n,r,o)=>e(i=>cn("#")(t,e,n,r,(s,a)=>e(u=>{const c=Dn(At(d=>d!==`
16
+ `)),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>o(_._3&&!l._3?k(l._1,l._2,!0):l,void 0))))}))),Zh=xt((()=>{const t=xt(At(n=>n==="}"))("'}'"),e=At(n=>n===`
17
+ `||n==="\r");return(n,r,o,i,s)=>{const a=n._1,u=n._2;return r(c=>r(_=>t(k(a,u,!1),r,o,(d,l)=>r(f=>{const h=n._1,p=n._2;return r(m=>r(w=>jh(k(h,p,!1),r,o,(x,y)=>{const T=x._3;return r(C=>{if(T)return i(x,y);const S=n._1,E=n._2;return r(B=>r(M=>e(k(S,E,!1),r,o,(Y,R)=>{const A=Y._3;return r(j=>A?i(Y,R):ds(n,r,o,i,s))},(Y,R)=>r(A=>s(Y,void 0)))))})},(x,y)=>r(T=>s(x,void 0)))))}),(d,l)=>r(f=>s(k(a,u,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),ln=(()=>{const t=Dn((e,n,r,o,i)=>{const s=e._1,a=e._2;return n(u=>LS(k(s,a,!1),n,r,(c,_)=>{const d=c._3;return n(l=>d?o(c,_):jh(e,n,r,o,i))},i))});return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>i(e._3&&!a._3?k(a._1,a._2,!0):a,void 0))))})(),ES=(()=>{const t=At(e=>e!=="|");return(e,n,r,o,i)=>{const s=e._1,a=e._2;return n(u=>n(c=>cn("\\|")(k(s,a,!1),n,r,(_,d)=>n(l=>n(f=>t(e,n,r,o,(h,p)=>n(m=>i(h,Gi(p)))))),(_,d)=>n(l=>i(_,"|")))))}})(),GS=xt(Hg([(t,e,n,r,o)=>e(i=>{const s=t._3;return cn("->")(t,e,n,(a,u)=>r(k(a._1,a._2,s),u),(a,u)=>e(c=>o(a,!0)))}),(t,e,n,r,o)=>e(i=>{const s=t._3;return cn("--")(t,e,n,(a,u)=>r(k(a._1,a._2,s),u),(a,u)=>e(c=>o(a,!1)))})]))("edge arrow '->' or '--'"),PS=t=>t!==`
18
+ `&&t!=="\r"&&t!=="#"&&t!=="}"&&t!=="{",Ha=At(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),BS=t=>t===" "||t===" "||t==="\r",DS=t=>Or(se(tr(BS)(se(vr(t))).rest)),Vg=t=>t===`
19
+ `||t==="\r"||t==="#"||t==="}",RS=t=>t===`
20
+ `||t==="\r"||t==="#"||t==="}"||t==="{",AS=t=>t!=="{"&&t!==`
21
+ `&&t!=="\r",tp=t=>As(t)==="",IS=t=>se(tr(tp)(se(tr(tp)(t).rest)).rest),FS=t=>(e=>n=>{let r=e,o=n,i=!0,s;for(;i;){const a=r,u=Ft(c=>J,c=>_=>N("Just",{head:c,tail:_}),o);if(u.tag==="Just"&&(u._1.head===" "||u._1.head===" ")){r=a+1|0,o=u._1.tail;continue}i=!1,s=a}return s})(0)(vr(t)),QS=t=>{const e=Ft(n=>J,n=>r=>N("Just",{head:n,tail:r}),q(FS)(ft(n=>As(n)!=="",t)));if(e.tag==="Nothing")return 0;if(e.tag==="Just")return v(bS)(e._1.head)(e._1.tail);g()},zS=(()=>{const t=xt(At(e=>e==="-"))("'-'");return(e,n,r,o,i)=>{const s=e._3;return n(a=>t(e,n,r,(u,c)=>o(k(u._1,u._2,s),c),(u,c)=>n(_=>{const d=Ji((()=>{const f=xt(At(p=>p===">"))("'>'"),h=xt(At(p=>p==="-"))("'-'");return(p,m,w,x,y)=>{const T=p._1,C=p._2;return m(S=>f(k(T,C,!1),m,w,(E,B)=>{const M=E._3;return m(Y=>M?x(E,B):h(p,m,w,x,y))},y))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(f=>d(l,n,r,(h,p)=>o(k(h._1,h._2,s),p),(h,p)=>n(m=>i(l._3&&!h._3?k(h._1,h._2,!0):h,"-"))))})))}})(),ee=(()=>{const t=Dn(At(e=>e===" "||e===" "));return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>i(e._3&&!a._3?k(a._1,a._2,!0):a,void 0))))})(),eo=(()=>{const t=At(e=>e===" "||e===" ");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>ee(e._3&&!a._3?k(a._1,a._2,!0):a,n,r,o,i))))})(),ep=(t,e,n,r,o)=>e(i=>e(s=>ee(t,e,n,r,(a,u)=>e(c=>e(_=>{const d=t._3&&!a._3?k(a._1,a._2,!0):a;return $g(d,e,n,r,(l,f)=>e(h=>o(d._3&&!l._3?k(l._1,l._2,!0):l,f)))}))))),np=(t,e,n,r,o)=>e(i=>ee(t,e,n,r,(s,a)=>e(u=>{const c=xt(At(d=>d==="-"))("'-'"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>{const l=(p,m)=>e(w=>(()=>{if(m.tag==="Just")return(x,y,T,C,S)=>y(E=>GS(x,y,T,C,(B,M)=>y(Y=>S(B,N("Just",M)))));if(m.tag==="Nothing")return(x,y,T,C,S)=>S(x,J);g()})()(_._3&&!p._3?k(p._1,p._2,!0):p,e,n,r,o)),f=_._1,h=_._2;return e(p=>e(m=>c(k(f,h,!1),e,n,(w,x)=>e(y=>l(_,J)),(w,x)=>e(y=>l(k(f,h,!1),N("Just",x))))))})}))),MS=t=>{const e=ao("Expected ")(t),n=(()=>{if(e.tag==="Nothing")return t;if(e.tag==="Just")return e._1;g()})();return n==="'{'"?"Open the block with `{`.":n==="integer (seed value)"?"Put an integer after `seed`.":n==="closing '}'"?"Close this block with `}`.":n===`closing '"' (unterminated string)`?'This string is unterminated; close it with `"`.':n==="closing '|'"?"Close this pipe label with `|`.":n==="space after '+'"?"Put a space after `+`: `+ api: API`.":n==="node identifier after '+'"?"Put a node id after `+`: `+ api: API`.":n==="space after '-'"?"Put a space after `-`: `- api`.":n==="node identifier after '-'"?"Put a node id after `-`: `- api`.":n==="space after '~'"?"Put a space after `~`: `~ api -> db => api -> cache`.":n==="node identifier"?"Put a node identifier here.":n==="space after 'inside'"?"Put a space after `inside`: `inside api { ... }`.":n==="node identifier after 'inside'"?"Tell `inside` which node owns this interior: `inside api { ... }`.":n==="source node identifier after 'via'"?"Put the source node after `via`: `via a b`.":n==="target node identifier after 'via'"?"Put the second endpoint after `via`: `via a b`.":n==="source node identifier"?"Put a source node identifier here.":n==="new source node identifier"?"Put the new source node identifier after `=>`.":n==="new target node identifier"?"Put the new target node identifier after the replacement arrow.":n==="edge arrow '->' or '--'"?"Use `->` for a directed edge or `--` for an undirected edge.":n==="source edge arrow '->'"?"Use `->` in the edge you are changing: `~ api -> db => api -> cache`.":n==="replacement edge arrow '->'"?"Use `->` in the replacement edge: `~ api -> db => api -> cache`.":n==="repoint separator '=>'"?"Use `=>` before the replacement edge: `~ api -> db => api -> cache`.":n==="target node identifier"?"Put a target node after the arrow.":n==="'~>'"?"Use `~>` for movement from left to right.":n==="'<~'"?"Use `<~` for movement from right to left.":n==="'->' or '<-'"?"Use `~>` / `<~` for movement tokens.":n==='label ("\u2026", : rest-of-line, or |\u2026|)'?'label must use `: text`, `"text"`, or `|multi-line|`.':n==="attribute key"?"Start each attribute with a name, like `shape`.":n==="':'"?"Put `:` between the attribute name and value: `{shape: cylinder}`.":n==="attribute value"?"Put an attribute value after `:`.":n==="closing '}' for attributes"?"Close the attribute block with `}`.":n==="space after 'into'"?"Put a space after `into`: `into api`.":n==="node identifier after 'into'"?"Tell `into` which node to dive into.":n==="space after 'step'"?"Put a space after `step`: `step request`.":n==="step name"?"Name the step: `step request`.":n==="newline or '}' (statements end at the end of the line)"?"This statement has extra text. Put the next statement on a new line or close the block with `}`.":n==="statement (+ node, - node, + edge, - edge, into, out, or 'a ~> b'/'a <~ b')"?"I don't recognize this statement. Start with `+`, `-`, `~`, `into`, `out`, `par`, `seq`, or movement like `api ~> db`.":n==="'scene', 'still', 'title', 'step', 'inside', a statement, or end of input"?"Start with a statement like `+ api: API`, a marker like `step request`, or a block with `scene`, `still`, `title`, or `inside`.":n},WS=t=>{const e=As(t),n=ao('"')(e),r=(()=>{if(n.tag==="Just")return Em('"')(n._1);if(n.tag==="Nothing")return J;g()})(),o=(()=>{if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()})();return o===""?J:N("Just",o)},rp=t=>e=>t!=="AnimatedSurface"&&e.statements.length!==0?{...e,frames:St(e.frames)((()=>{if(t==="StillSurface")return{name:J,ops:pr("Seq",e.statements),kind:zg};if(t==="SequenceSurface")return{name:J,ops:pr("Seq",e.statements),kind:Fa};if(t==="AnimatedSurface")return{name:J,ops:pr("Seq",e.statements),kind:Fa};g()})()),statements:[]}:e,OS=(()=>{const t=xt(At(e=>e==="\\"))("'\\\\'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>CS(_,n,r,o,(l,f)=>n(h=>i(_._3&&!l._3?k(l._1,l._2,!0):l,f==="n"?`
22
+ `:f==="t"?" ":f==="r"?"\r":f))))})))})(),qS=(()=>{const t=At(e=>e!=='"'&&e!=="\\"&&e!==`
23
+ `);return(e,n,r,o,i)=>{const s=e._1,a=e._2;return n(u=>OS(k(s,a,!1),n,r,(c,_)=>n(d=>t(e,n,r,o,i)),i))}})(),HS=(()=>{const t=xt(At(e=>e==='"'))(`'"'`);return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=Dn(qS),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=xt(xt(At(x=>x==='"'))(`'"'`))(`closing '"' (unterminated string)`),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(w,n,r,o,(y,T)=>n(C=>i(w._3&&!y._3?k(y._1,y._2,!0):y,Or(Zt(de.foldr,h))))))})))})))})(),$S={frames:[],statements:[]},VS=t=>{const e=IS(Kr(`
24
+ `)(t));return sr(`
25
+ `)(q(DS)(q($o(QS(e)))(e)))},US=(()=>{const t=xt(At(e=>e==="|"))("'|'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=Dn(ES),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=xt(xt(At(x=>x==="|"))("'|'"))("closing '|'"),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(w,n,r,o,(y,T)=>n(C=>i(w._3&&!y._3?k(y._1,y._2,!0):y,VS(sr("")(Zt(de.foldr,h)))))))})))})))})(),ls=At(t=>t>="0"&&t<="9"),KS=(()=>{const t=xt(At(e=>e==="_"))("'_'");return(e,n,r,o,i)=>{const s=e._1,a=e._2;return n(u=>Ha(k(s,a,!1),n,r,(c,_)=>{const d=c._3;return n(l=>{if(d)return o(c,_);const f=e._1,h=e._2;return n(p=>ls(k(f,h,!1),n,r,(m,w)=>{const x=m._3;return n(y=>{if(x)return o(m,w);const T=e._1,C=e._2;return n(S=>t(k(T,C,!1),n,r,(E,B)=>{const M=E._3;return n(Y=>M?o(E,B):zS(e,n,r,o,i))},i))})},i))})},i))}})(),ze=(()=>{const t=xt(At(e=>e==="_"))("'_'");return(e,n,r,o,i)=>n(s=>{const a=(_,d)=>n(l=>{const f=Dn(KS),h=e._3&&!_._3?k(_._1,_._2,!0):_;return n(p=>f(h,n,r,o,(m,w)=>n(x=>i(h._3&&!m._3?k(m._1,m._2,!0):m,Gi(d)+Or(Zt(de.foldr,w))))))}),u=e._1,c=e._2;return n(_=>Ha(k(u,c,!1),n,r,(d,l)=>{const f=d._3;return n(h=>f?o(d,l):t(e,n,r,o,a))},a))})})(),op=(t,e,n,r,o)=>e(i=>ee(t,e,n,r,(s,a)=>e(u=>{const c=xt(ze)("attribute key"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=_._3&&!l._3?k(l._1,l._2,!0):l;return e(m=>ee(p,e,n,r,(w,x)=>e(y=>{const T=xt(xt(At(S=>S===":"))("':'"))("':'"),C=p._3&&!w._3?k(w._1,w._2,!0):w;return e(S=>T(C,e,n,r,(E,B)=>e(M=>{const Y=C._3&&!E._3?k(E._1,E._2,!0):E;return e(R=>ee(Y,e,n,r,(A,j)=>e(Z=>{const z=xt(ze)("attribute value"),W=Y._3&&!A._3?k(A._1,A._2,!0):A;return e(H=>z(W,e,n,r,(D,F)=>e(L=>{const G=W._3&&!D._3?k(D._1,D._2,!0):D;return e(Q=>ee(G,e,n,r,(V,K)=>e(U=>o(G._3&&!V._3?k(V._1,V._2,!0):V,b(f,F)))))})))})))})))})))})))}))),YS=Xh((()=>{const t=xt(At(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(s=>n(a=>t(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return ee(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(f._1,f._2,!0):f,h)))})))))})())(xt((()=>{const t=xt(At(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(s=>n(a=>ee(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return t(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(f._1,f._2,!0):f,h)))})))))})())("closing '}' for attributes"))((()=>{const t=xt(At(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(s=>{const a=(_,d)=>n(l=>(()=>{if(d.tag==="Just")return(f,h,p,m,w)=>w(f,I);if(d.tag==="Nothing")return(f,h,p,m,w)=>h(x=>op(f,h,p,m,(y,T)=>h(C=>{const S=Dn((()=>{const B=xt(At(M=>M===","))("','");return(M,Y,R,A,j)=>{const Z=M._3;return Y(z=>Y(W=>Y(H=>Y(D=>Y(F=>Y(L=>ee(M,Y,R,(G,Q)=>A(k(G._1,G._2,Z),Q),(G,Q)=>Y(V=>Y(K=>{const U=M._3&&!G._3?k(G._1,G._2,!0):G;return B(U,Y,R,(O,X)=>A(k(O._1,O._2,Z),X),(O,X)=>Y(et=>{const lt=U._3&&!O._3?k(O._1,O._2,!0):O;return Y(bt=>Y(pt=>{const Tt=M._3&&!lt._3?k(lt._1,lt._2,!0):lt;return ee(Tt,Y,R,(Gt,jt)=>A(k(Gt._1,Gt._2,Z),jt),(Gt,jt)=>Y(Ct=>{const Yt=Tt._3&&!Gt._3?k(Gt._1,Gt._2,!0):Gt;return Y(Dt=>Y(wt=>{const mt=M._3&&!Yt._3?k(Yt._1,Yt._2,!0):Yt;return op(mt,Y,R,(ct,yt)=>A(k(ct._1,ct._2,Z),yt),(ct,yt)=>Y(dt=>j(mt._3&&!ct._3?k(ct._1,ct._2,!0):ct,yt)))}))}))}))}))})))))))))}})()),E=f._3&&!y._3?k(y._1,y._2,!0):y;return h(B=>S(E,h,p,m,(M,Y)=>h(R=>w(E._3&&!M._3?k(M._1,M._2,!0):M,kS([T,...Zt(de.foldr,Y)])))))})));g()})()(e._3&&!_._3?k(_._1,_._2,!0):_,n,r,o,i)),u=e._1,c=e._2;return n(_=>n(d=>t(k(u,c,!1),n,r,(l,f)=>n(h=>a(e,J)),(l,f)=>n(h=>a(k(u,c,!1),N("Just",f))))))})})()),XS=(t,e,n,r,o)=>e(i=>ee(t,e,n,r,(s,a)=>e(u=>{const c=xt(At(d=>d==="{"))("'{'"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>{const l=(p,m)=>e(w=>(()=>{if(m.tag==="Just")return YS;if(m.tag==="Nothing")return(x,y,T,C,S)=>S(x,I);g()})()(_._3&&!p._3?k(p._1,p._2,!0):p,e,n,r,o)),f=_._1,h=_._2;return e(p=>e(m=>c(k(f,h,!1),e,n,(w,x)=>e(y=>l(_,J)),(w,x)=>e(y=>l(k(f,h,!1),N("Just",x))))))})}))),jS=t=>e=>n=>(r,o,i,s,a)=>o(u=>ee(r,o,i,s,(c,_)=>o(d=>{const l=vn(xt(ze)("target node identifier")),f=r._3&&!c._3?k(c._1,c._2,!0):c;return o(h=>l(f,o,i,s,(p,m)=>o(w=>a(f._3&&!p._3?k(p._1,p._2,!0):p,{op:Un("DelEdge",{from:t,to:m._1,directed:n}),operands:[e,m._2]}))))}))),ZS=(t,e,n,r,o)=>e(i=>Xn(t,e,n,r,(s,a)=>e(u=>{const c=t._3&&!s._3?k(s._1,s._2,!0):s;return e(_=>{const d=c._3;return e(l=>ze(c,e,n,(f,h)=>r(k(f._1,f._2,d),h),(f,h)=>e(p=>{const m=c._3&&!f._3?k(f._1,f._2,!0):f;return e(w=>ee(m,e,n,(x,y)=>r(k(x._1,x._2,d),y),(x,y)=>e(T=>{const C=m._3&&!x._3?k(x._1,x._2,!0):x;return e(S=>{const E=(Y,R)=>e(A=>{const j=C._3&&!Y._3?k(Y._1,Y._2,!0):Y;return e(Z=>r(c._3&&!j._3?k(j._1,j._2,!0):j,yr("Use `~>` / `<~` for movement tokens.",a)))}),B=C._1,M=C._2;return e(Y=>cn("->")(k(B,M,!1),e,n,(R,A)=>{const j=R._3;return e(Z=>j?r(k(R._1,R._2,d),A):cn("<-")(C,e,n,(z,W)=>r(k(z._1,z._2,d),W),E))},E))})})))})))})}))),tL=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>vn(ze)(t,e,n,(u,c)=>r(k(u._1,u._2,s),c),(u,c)=>e(_=>{const d=t._3&&!u._3?k(u._1,u._2,!0):u;return e(l=>ee(d,e,n,(f,h)=>r(k(f._1,f._2,s),h),(f,h)=>e(p=>{const m=xt(At(x=>x==="~"))("'~'"),w=d._3&&!f._3?k(f._1,f._2,!0):f;return e(x=>{const y=(S,E)=>e(B=>{const M=w._3&&!S._3?k(S._1,S._2,!0):S;return e(Y=>{const R=c._1,A=c._2,j=t._3&&!M._3?k(M._1,M._2,!0):M;return e(Z=>ee(j,e,n,r,(z,W)=>e(H=>{const D=xt(At(G=>G==="~"))("'~'"),F=xt(At(G=>G==="<"))("'<'"),L=j._3&&!z._3?k(z._1,z._2,!0):z;return e(G=>{const Q=(U,O)=>e(X=>{const et=O==="~"?xt(cn("~>"))("'~>'"):xt(cn("<~"))("'<~'"),lt=L._3&&!U._3?k(U._1,U._2,!0):U;return e(bt=>et(lt,e,n,r,(pt,Tt)=>e(Gt=>o(lt._3&&!pt._3?k(pt._1,pt._2,!0):pt,b(R,b(A,Tt))))))}),V=L._1,K=L._2;return e(U=>D(k(V,K,!1),e,n,(O,X)=>{const et=O._3;return e(lt=>et?r(L,X):F(L,e,n,(bt,pt)=>r(L,pt),(bt,pt)=>Q(L,pt)))},(O,X)=>Q(L,X)))})})))})}),T=w._1,C=w._2;return e(S=>m(k(T,C,!1),e,n,(E,B)=>{const M=E._3;return e(Y=>M?r(k(w._1,w._2,s),B):e(R=>cn("<~")(w,e,n,(A,j)=>r(k(w._1,w._2,s),j),(A,j)=>e(Z=>y(w)))))},(E,B)=>y(w)))})})))})))}),eL=(()=>{const t=xt(At(e=>e==="~"))("'~'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=xt(eo)("space after '~'"),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=vn(xt(ze)("source node identifier")),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(w,n,r,o,(y,T)=>n(C=>{const S=T._1,E=T._2,B=w._3&&!y._3?k(y._1,y._2,!0):y;return n(M=>ee(B,n,r,o,(Y,R)=>n(A=>{const j=xt(cn("->"))("source edge arrow '->'"),Z=B._3&&!Y._3?k(Y._1,Y._2,!0):Y;return n(z=>j(Z,n,r,o,(W,H)=>n(D=>{const F=Z._3&&!W._3?k(W._1,W._2,!0):W;return n(L=>ee(F,n,r,o,(G,Q)=>n(V=>{const K=vn(xt(ze)("target node identifier")),U=F._3&&!G._3?k(G._1,G._2,!0):G;return n(O=>K(U,n,r,o,(X,et)=>n(lt=>{const bt=et._1,pt=et._2,Tt=U._3&&!X._3?k(X._1,X._2,!0):X;return n(Gt=>ee(Tt,n,r,o,(jt,Ct)=>n(Yt=>{const Dt=xt(cn("=>"))("repoint separator '=>'"),wt=Tt._3&&!jt._3?k(jt._1,jt._2,!0):jt;return n(mt=>Dt(wt,n,r,o,(ct,yt)=>n(dt=>{const ht=wt._3&&!ct._3?k(ct._1,ct._2,!0):ct;return n(Lt=>ee(ht,n,r,o,(Bt,zt)=>n(ne=>{const Cn=vn(xt(ze)("new source node identifier")),Me=ht._3&&!Bt._3?k(Bt._1,Bt._2,!0):Bt;return n(qt=>Cn(Me,n,r,o,(Ot,We)=>n(bn=>{const tn=We._1,_n=We._2,Ae=Me._3&&!Ot._3?k(Ot._1,Ot._2,!0):Ot;return n(oe=>ee(Ae,n,r,o,(_e,v4)=>n(T4=>{const w4=xt(cn("->"))("replacement edge arrow '->'"),Mp=Ae._3&&!_e._3?k(_e._1,_e._2,!0):_e;return n(C4=>w4(Mp,n,r,o,(iu,b4)=>n(k4=>{const Wp=Mp._3&&!iu._3?k(iu._1,iu._2,!0):iu;return n(S4=>ee(Wp,n,r,o,(su,L4)=>n(E4=>{const J4=vn(xt(ze)("new target node identifier")),Op=Wp._3&&!su._3?k(su._1,su._2,!0):su;return n(G4=>J4(Op,n,r,o,(au,qp)=>n(P4=>i(Op._3&&!au._3?k(au._1,au._2,!0):au,{op:Un("RepointEdge",{from:S,to:bt,newFrom:tn,newTo:qp._1}),operands:[E,pt,_n,qp._2]}))))})))})))})))})))})))})))})))})))})))})))})))})))})))})))})(),nL=(t,e,n,r,o)=>e(i=>ls(t,e,n,r,(s,a)=>e(u=>{const c=Dn(ls),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=O0(Gi(a)+Or(Zt(de.foldr,f)));return(()=>{if(p.tag==="Just"){const m=p._1;return(w,x,y,T,C)=>C(w,m)}if(p.tag==="Nothing")return(m,w,x,y,T)=>T(m,0);g()})()(_._3&&!l._3?k(l._1,l._2,!0):l,e,n,r,o)})))}))),rL=t=>(e,n,r,o,i)=>{const s=e._3;return n(a=>cn(t)(e,n,r,(u,c)=>o(k(u._1,u._2,s),c),(u,c)=>n(_=>{const d=Ji((()=>{const f=xt(At(p=>p==="_"))("'_'"),h=xt(At(p=>p==="-"))("'-'");return(p,m,w,x,y)=>{const T=p._1,C=p._2;return m(S=>Ha(k(T,C,!1),m,w,(E,B)=>{const M=E._3;return m(Y=>{if(M)return x(E,B);const R=p._1,A=p._2;return m(j=>ls(k(R,A,!1),m,w,(Z,z)=>{const W=Z._3;return m(H=>{if(W)return x(Z,z);const D=p._1,F=p._2;return m(L=>f(k(D,F,!1),m,w,(G,Q)=>{const V=G._3;return m(K=>V?x(G,Q):h(p,m,w,x,y))},y))})},y))})},y))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(f=>d(l,n,r,(h,p)=>o(k(h._1,h._2,s),p),(h,p)=>n(m=>{const w=l._3&&!h._3?k(h._1,h._2,!0):h;return n(x=>ln(w,n,r,(y,T)=>o(k(y._1,y._2,s),T),(y,T)=>n(C=>i(w._3&&!y._3?k(y._1,y._2,!0):y,t))))})))})))},Tn=t=>(e,n,r,o,i)=>{const s=e._3;return n(a=>cn(t)(e,n,r,(u,c)=>o(k(u._1,u._2,s),c),(u,c)=>n(_=>{const d=Ji((()=>{const f=xt(At(p=>p==="_"))("'_'"),h=xt(At(p=>p==="-"))("'-'");return(p,m,w,x,y)=>{const T=p._1,C=p._2;return m(S=>Ha(k(T,C,!1),m,w,(E,B)=>{const M=E._3;return m(Y=>{if(M)return x(E,B);const R=p._1,A=p._2;return m(j=>ls(k(R,A,!1),m,w,(Z,z)=>{const W=Z._3;return m(H=>{if(W)return x(Z,z);const D=p._1,F=p._2;return m(L=>f(k(D,F,!1),m,w,(G,Q)=>{const V=G._3;return m(K=>V?x(G,Q):h(p,m,w,x,y))},y))})},y))})},y))}})()),l=e._3&&!u._3?k(u._1,u._2,!0):u;return n(f=>d(l,n,r,(h,p)=>o(k(h._1,h._2,s),p),(h,p)=>n(m=>i(l._3&&!h._3?k(h._1,h._2,!0):h,void 0))))})))},oL=(t,e,n,r,o)=>e(i=>Tn("into")(t,e,n,r,(s,a)=>e(u=>{const c=xt(eo)("space after 'into'"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=vn(xt(ze)("node identifier after 'into'")),m=_._3&&!l._3?k(l._1,l._2,!0):l;return e(w=>p(m,e,n,r,(x,y)=>e(T=>o(m._3&&!x._3?k(x._1,x._2,!0):x,{op:Un("Enter",{id:y._1}),operands:[y._2]}))))})))}))),iL=(t,e,n,r,o)=>e(i=>Tn("out")(t,e,n,r,(s,a)=>e(u=>o(t._3&&!s._3?k(s._1,s._2,!0):s,{op:v5,operands:[]})))),sL=(t,e,n,r,o)=>e(i=>Tn("seed")(t,e,n,r,(s,a)=>e(u=>{const c=t._3&&!s._3?k(s._1,s._2,!0):s;return e(_=>ee(c,e,n,r,(d,l)=>e(f=>{const h=xt(nL)("integer (seed value)"),p=c._3&&!d._3?k(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(w,x)=>e(y=>{const T=p._3&&!w._3?k(w._1,w._2,!0):w;return e(C=>ln(T,e,n,r,(S,E)=>e(B=>o(T._3&&!S._3?k(S._1,S._2,!0):S,x))))})))})))}))),ip=(t,e,n,r,o)=>{const i=t._3;return e(s=>Tn("diagram")(t,e,n,(a,u)=>r(k(a._1,a._2,i),u),(a,u)=>e(c=>{const _=xt(eo)("space after 'diagram'"),d=t._3&&!a._3?k(a._1,a._2,!0):a;return e(l=>_(d,e,n,(f,h)=>r(k(f._1,f._2,i),h),(f,h)=>e(p=>{const m=xt(Tn("sequence"))("diagram mode"),w=d._3&&!f._3?k(f._1,f._2,!0):f;return e(x=>m(w,e,n,(y,T)=>r(k(y._1,y._2,i),T),(y,T)=>e(C=>{const S=w._3&&!y._3?k(y._1,y._2,!0):y;return e(E=>ep(S,e,n,(B,M)=>r(k(B._1,B._2,i),M),(B,M)=>e(Y=>o(S._3&&!B._3?k(B._1,B._2,!0):B,N5))))})))})))})))},sp=(t,e,n,r,o)=>{const i=t._3;return e(s=>Tn("still")(t,e,n,(a,u)=>r(k(a._1,a._2,i),u),(a,u)=>e(c=>{const _=t._3&&!a._3?k(a._1,a._2,!0):a;return e(d=>ep(_,e,n,(l,f)=>r(k(l._1,l._2,i),f),(l,f)=>e(h=>o(_._3&&!l._3?k(l._1,l._2,!0):l,J5))))})))},ap=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(a=>sp(k(i,s,!1),e,n,(u,c)=>{const _=u._3;return e(d=>_?r(u,c):ip(t,e,n,r,o))},o))},aL=t=>(e,n,r,o,i)=>n(s=>Xn(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>{const l=_._3;return ap(_,n,r,(f,h)=>o(k(f._1,f._2,l),h),(f,h)=>n(p=>o(_._3&&!f._3?k(f._1,f._2,!0):f,yr((()=>{if(t==="AnimatedSurface")return"Put diagram mode headers at the top of the document.";if(t==="AnimatedSurface")return"This document already declares `animation`; choose one diagram mode.";if(t==="StillSurface")return"This document already declares `still`; choose one diagram mode.";if(t==="SequenceSurface")return"This document already declares `diagram sequence`; choose one diagram mode.";g()})(),u))))})}))),uL=t=>(e,n,r,o,i)=>n(s=>Xn(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>{const l=(p,m)=>n(w=>(()=>{if(m.tag==="Just"){const x=(()=>{if(t==="AnimatedSurface")return"This document already declares `animation`; choose one diagram mode.";if(t==="StillSurface")return"This document already declares `still`; choose one diagram mode.";if(t==="SequenceSurface")return"This document already declares `diagram sequence`; choose one diagram mode.";g()})();return(y,T,C,S,E)=>S(y,yr(x,u))}if(m.tag==="Nothing")return(x,y,T,C,S)=>S(x,void 0);g()})()(_._3&&!p._3?k(p._1,p._2,!0):p,n,r,o,i)),f=_._1,h=_._2;return n(p=>n(m=>ap(k(f,h,!1),n,r,(w,x)=>{const y=w._3;return n(T=>y?o(w,x):l(_,J))},(w,x)=>n(y=>l(w,N("Just",x))))))})}))),cL=(t,e,n,r,o)=>e(i=>{const s=(c,_)=>e(d=>{const l=t._3&&!c._3?k(c._1,c._2,!0):c;return e(f=>ln(l,e,n,r,(h,p)=>e(m=>{const w=l._3&&!h._3?k(h._1,h._2,!0):h;return e(x=>uL(_)(w,e,n,r,(y,T)=>e(C=>o(w._3&&!y._3?k(y._1,y._2,!0):y,_))))})))}),a=t._1,u=t._2;return e(c=>sp(k(a,u,!1),e,n,(_,d)=>{const l=_._3;return e(f=>l?r(_,d):ip(t,e,n,r,s))},s))}),gL=(t,e,n,r,o)=>e(i=>{const s=(c,_)=>e(d=>o(c,(()=>{if(_.tag==="Nothing")return w5;if(_.tag==="Just")return _._1;g()})())),a=t._1,u=t._2;return e(c=>e(_=>cL(k(a,u,!1),e,n,(d,l)=>{const f=d._3;return e(h=>f?r(d,l):s(t,J))},(d,l)=>e(f=>s(d,N("Just",l))))))}),_L=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>ee(t,e,n,(u,c)=>r(k(u._1,u._2,s),c),(u,c)=>e(_=>Tn("via")(t._3&&!u._3?k(u._1,u._2,!0):u,e,n,(d,l)=>r(k(d._1,d._2,s),l),(d,l)=>e(f=>{const h=t._3&&!d._3?k(d._1,d._2,!0):d;return e(p=>Wa(h,e,n,r,(m,w)=>e(x=>{const y=h._3&&!m._3?k(m._1,m._2,!0):m;return e(T=>eo(y,e,n,r,(C,S)=>e(E=>{const B=xt(ze)("source node identifier after 'via'"),M=y._3&&!C._3?k(C._1,C._2,!0):C;return e(Y=>B(M,e,n,r,(R,A)=>e(j=>{const Z=M._3&&!R._3?k(R._1,R._2,!0):R;return e(z=>ee(Z,e,n,r,(W,H)=>e(D=>{const F=xt(ze)("target node identifier after 'via'"),L=Z._3&&!W._3?k(W._1,W._2,!0):W;return e(G=>F(L,e,n,r,(Q,V)=>e(K=>o(L._3&&!Q._3?k(Q._1,Q._2,!0):Q,{from:A,to:V}))))})))})))})))})))})))))}),fL=t=>e=>{const n=Dn(_L);return(r,o,i,s,a)=>o(u=>n(r,o,i,s,(c,_)=>o(d=>a(r._3&&!c._3?k(c._1,c._2,!0):c,{op:Un("DelNode",{id:t,via:Zt(de.foldr,_)}),operands:[e]}))))},dL=(()=>{const t=xt(At(e=>e==="-"))("'-'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=xt(eo)("space after '-'"),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=vn(xt(ze)("node identifier after '-'")),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(w,n,r,o,(y,T)=>n(C=>{const S=T._1,E=T._2,B=w._3&&!y._3?k(y._1,y._2,!0):y;return n(M=>np(B,n,r,o,(Y,R)=>n(A=>(()=>{if(R.tag==="Just")return jS(S)(E)(R._1);if(R.tag==="Nothing")return fL(S)(E);g()})()(B._3&&!Y._3?k(Y._1,Y._2,!0):Y,n,r,o,i))))})))})))})))})(),jn=t=>e=>(n,r,o,i,s)=>r(a=>Xn(n,r,o,i,(u,c)=>r(_=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return r(l=>Tn(t)(d,r,o,i,(f,h)=>r(p=>i(d._3&&!f._3?k(f._1,f._2,!0):f,yr(e,c)))))}))),lL=t=>t==="AnimatedSurface"?(e,n,r,o,i)=>n(s=>Xn(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>Tn("step")(_,n,r,o,(l,f)=>n(h=>{const p=xt(eo)("space after 'step'"),m=_._3&&!l._3?k(l._1,l._2,!0):l;return n(w=>p(m,n,r,o,(x,y)=>n(T=>{const C=vn(xt(ze)("step name")),S=m._3&&!x._3?k(x._1,x._2,!0):x;return n(E=>C(S,n,r,o,(B,M)=>n(Y=>{const R=M._1,A=M._2,j=S._3&&!B._3?k(B._1,B._2,!0):B;return n(Z=>Xn(j,n,r,o,(z,W)=>n(H=>{const D=j._3&&!z._3?k(z._1,z._2,!0):z;return n(F=>ee(D,n,r,o,(L,G)=>n(Q=>{const V=D._3&&!L._3?k(L._1,L._2,!0):L;return n(K=>Zh(V,n,r,o,(U,O)=>n(X=>{const et=V._3&&!U._3?k(U._1,U._2,!0):U;return n(lt=>ln(et,n,r,o,(bt,pt)=>n(Tt=>{const Gt={line:u.line,column:u.column,endLine:W.line,endColumn:W.column};return i(et._3&&!bt._3?k(bt._1,bt._2,!0):bt,{name:N("Just",R),ops:pr("Leaf",{op:Un("Step",{name:R}),line:Gt.line,column:Gt.column,endLine:Gt.endLine,endColumn:Gt.endColumn,span:Gt,operands:[A]}),kind:Ah})})))})))})))})))})))})))})))}))):jn("step")("`step` markers are only supported in animated diagrams."),hL=(()=>{const t=xt(At(e=>e===":"))("':'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>ee(_,n,r,o,(l,f)=>n(h=>{const p=Dn(At(PS)),m=_._3&&!l._3?k(l._1,l._2,!0):l;return n(w=>p(m,n,r,o,(x,y)=>n(T=>i(m._3&&!x._3?k(x._1,x._2,!0):x,As(Or(Zt(de.foldr,y)))))))})))})))})(),pL=(t,e,n,r,o)=>e(i=>ee(t,e,n,r,(s,a)=>e(u=>xt((c,_,d,l,f)=>{const h=c._1,p=c._2;return _(m=>hL(k(h,p,!1),_,d,(w,x)=>{const y=w._3;return _(T=>{if(y)return l(w,x);const C=c._1,S=c._2;return _(E=>US(k(C,S,!1),_,d,(B,M)=>{const Y=B._3;return _(R=>Y?l(B,M):HS(c,_,d,l,f))},f))})},f))})('label ("\u2026", : rest-of-line, or |\u2026|)')(t._3&&!s._3?k(s._1,s._2,!0):s,e,n,r,o)))),$a=t=>(e,n,r,o,i)=>n(s=>ee(e,n,r,o,(a,u)=>n(c=>{const _=e._3&&!a._3?k(a._1,a._2,!0):a;return n(d=>{const l=(p,m)=>n(w=>(m?((x,y,T,C,S)=>S(x,J)):(x,y,T,C,S)=>y(E=>pL(x,y,T,C,(B,M)=>y(Y=>S(B,N("Just",M))))))(_._3&&!p._3?k(p._1,p._2,!0):p,n,r,o,i)),f=_._1,h=_._2;return n(p=>{const m=(w,x)=>{const y=w._3;return n(T=>y?o(w,x):l(_,!1))};return n(w=>n(x=>n(y=>ds(k(f,h,!1),n,r,(T,C)=>{const S=T._3;return n(E=>S?m(k(f,h,!1),C):n(B=>At(t)(k(f,h,!1),n,r,(M,Y)=>m(k(f,h,!1),Y),(M,Y)=>n(R=>n(A=>l(k(f,h,!1),!0))))))},(T,C)=>n(S=>n(E=>l(k(f,h,!1),!0)))))))})})}))),mL=t=>e=>n=>(r,o,i,s,a)=>o(u=>ee(r,o,i,s,(c,_)=>o(d=>{const l=vn(xt(ze)("target node identifier")),f=r._3&&!c._3?k(c._1,c._2,!0):c;return o(h=>l(f,o,i,s,(p,m)=>o(w=>{const x=m._1,y=m._2,T=f._3&&!p._3?k(p._1,p._2,!0):p;return o(C=>$a(Vg)(T,o,i,s,(S,E)=>o(B=>a(T._3&&!S._3?k(S._1,S._2,!0):S,{op:Un("AddEdge",{from:t,to:x,label:E.tag==="Just"?N("Just",E._1):J,directed:n}),operands:[e,y]}))))})))}))),yL=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>vn(ze)(t,e,n,(u,c)=>r(k(u._1,u._2,s),c),(u,c)=>e(_=>{const d=t._3&&!u._3?k(u._1,u._2,!0):u;return e(l=>ee(d,e,n,(f,h)=>r(k(f._1,f._2,s),h),(f,h)=>e(p=>{const m=xt(At(x=>x==="<"))("'<'"),w=d._3&&!f._3?k(f._1,f._2,!0):f;return e(x=>m(w,e,n,(y,T)=>r(k(w._1,w._2,s),T),(y,T)=>e(C=>{const S=Ji((B,M,Y,R,A)=>{const j=B._3;return cn("<-")(B,M,Y,(Z,z)=>R(k(Z._1,Z._2,j),z),A)}),E=w._3&&!w._3?k(w._1,w._2,!0):w;return e(B=>S(E,e,n,(M,Y)=>r(k(M._1,M._2,s),Y),(M,Y)=>e(R=>{const A=E._3&&!M._3?k(M._1,M._2,!0):M;return e(j=>{const Z=c._1,z=c._2,W=t._3&&!A._3?k(A._1,A._2,!0):A;return e(H=>ee(W,e,n,r,(D,F)=>e(L=>{const G=xt(cn("<~"))("'<~'"),Q=W._3&&!D._3?k(D._1,D._2,!0):D;return e(V=>G(Q,e,n,r,(K,U)=>e(O=>{const X=Q._3&&!K._3?k(K._1,K._2,!0):K;return e(et=>ee(X,e,n,r,(lt,bt)=>e(pt=>{const Tt=vn(xt(ze)("target node identifier")),Gt=X._3&&!lt._3?k(lt._1,lt._2,!0):lt;return e(jt=>Tt(Gt,e,n,r,(Ct,Yt)=>e(Dt=>{const wt=Yt._1,mt=Yt._2,ct=Gt._3&&!Ct._3?k(Ct._1,Ct._2,!0):Ct;return e(yt=>$a(Vg)(ct,e,n,r,(dt,ht)=>e(Lt=>o(ct._3&&!dt._3?k(dt._1,dt._2,!0):dt,{op:Un("Token",{from:wt,to:Z,labels:(()=>{if(ht.tag==="Nothing")return[];if(ht.tag==="Just")return[ht._1];g()})()}),operands:[mt,z]}))))})))})))})))})))})})))})))})))})))}),xL=(t,e,n,r,o)=>e(i=>tL(t,e,n,r,(s,a)=>e(u=>{const c=a._2._2,_=a._1,d=a._2._1,l=t._3&&!s._3?k(s._1,s._2,!0):s;return e(f=>ee(l,e,n,r,(h,p)=>e(m=>{const w=vn(xt(ze)("target node identifier")),x=l._3&&!h._3?k(h._1,h._2,!0):h;return e(y=>w(x,e,n,r,(T,C)=>e(S=>{const E=C._1,B=C._2,M=x._3&&!T._3?k(T._1,T._2,!0):T;return e(Y=>$a(Vg)(M,e,n,r,(R,A)=>e(j=>(c==="<~"?((Z,z,W,H,D)=>D(Z,{op:Un("Token",{from:E,to:_,labels:(()=>{if(A.tag==="Nothing")return[];if(A.tag==="Just")return[A._1];g()})()}),operands:c==="<~"?[B,d]:[d,B]})):(Z,z,W,H,D)=>D(Z,{op:Un("Token",{from:_,to:E,labels:(()=>{if(A.tag==="Nothing")return[];if(A.tag==="Just")return[A._1];g()})()}),operands:c==="<~"?[B,d]:[d,B]}))(M._3&&!R._3?k(R._1,R._2,!0):R,e,n,r,o))))})))})))}))),wL=(t,e,n,r,o)=>e(i=>$a(RS)(t,e,n,r,(s,a)=>e(u=>o(s,(()=>{if(a.tag==="Nothing")return"";if(a.tag==="Just")return a._1;g()})())))),JL=t=>e=>(n,r,o,i,s)=>r(a=>wL(n,r,o,i,(u,c)=>r(_=>{const d=n._3&&!u._3?k(u._1,u._2,!0):u;return r(l=>XS(d,r,o,i,(f,h)=>r(p=>s(d._3&&!f._3?k(f._1,f._2,!0):f,{op:Un("AddNode",{id:t,label:c,shape:(()=>{const m=SS("shape")(h);if(m.tag==="Just")return m._1==="rectangle"||m._1==="rect"?qr:m._1==="cylinder"||m._1==="cyl"?Wm:m._1==="parallelogram"?Om:m._1==="diamond"?qm:m._1==="ellipse"?Hm:m._1==="document"||m._1==="doc"?$m:m._1==="cloud"?Vm:qr;if(m.tag==="Nothing")return qr;g()})()}),operands:[e]}))))}))),NL=(()=>{const t=xt(At(e=>e==="+"))("'+'");return(e,n,r,o,i)=>n(s=>t(e,n,r,o,(a,u)=>n(c=>{const _=xt(eo)("space after '+'"),d=e._3&&!a._3?k(a._1,a._2,!0):a;return n(l=>_(d,n,r,o,(f,h)=>n(p=>{const m=vn(xt(ze)("node identifier after '+'")),w=d._3&&!f._3?k(f._1,f._2,!0):f;return n(x=>m(w,n,r,o,(y,T)=>n(C=>{const S=T._1,E=T._2,B=w._3&&!y._3?k(y._1,y._2,!0):y;return n(M=>np(B,n,r,o,(Y,R)=>n(A=>(()=>{if(R.tag==="Just")return mL(S)(E)(R._1);if(R.tag==="Nothing")return JL(S)(E);g()})()(B._3&&!Y._3?k(Y._1,Y._2,!0):Y,n,r,o,i))))})))})))})))})(),vL=(t,e,n,r,o)=>e(i=>Xn(t,e,n,r,(s,a)=>e(u=>{const c=xt(Hg([jn("+node")("Node additions use `+ api: API`."),jn("+edge")("Graph edges use `+ api -> db`."),jn("+conn")("Undirected graph edges use `+ api -- db`."),jn("-node")("Node removals use `- api`."),jn("-edge")("Graph edge removals use `- api -> db`."),jn("-conn")("Undirected graph edge removals use `- api -- db`."),jn("~edge")("Graph edge repoints use `~ api -> db => api -> cache`."),jn("enter")("Dive commands use `into api`."),jn("exit")("Return from a dive with `out`."),ZS,NL,dL,eL,xL,yL,oL,iL]))("statement (+ node, - node, + edge, - edge, into, out, or 'a ~> b'/'a <~ b')"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=_._3&&!l._3?k(l._1,l._2,!0):l;return e(m=>Xn(p,e,n,r,(w,x)=>e(y=>{const T={line:a.line,column:a.column,endLine:x.line,endColumn:x.column};return o(p._3&&!w._3?k(w._1,w._2,!0):w,pr("Leaf",{op:f.op,line:T.line,column:T.column,endLine:T.endLine,endColumn:T.endColumn,span:T,operands:f.operands}))})))})))}))),Ug=Xh((()=>{const t=xt(At(e=>e==="{"))("'{'");return(e,n,r,o,i)=>n(s=>n(a=>t(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return ln(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(f._1,f._2,!0):f,h)))})))))})())(xt((()=>{const t=xt(At(e=>e==="}"))("'}'");return(e,n,r,o,i)=>n(s=>n(a=>ln(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return t(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(f._1,f._2,!0):f,h)))})))))})())("closing '}'")),up=(t,e,n,r,o)=>e(i=>{const s=t._3;return e(a=>ln(t,e,n,(u,c)=>r(k(u._1,u._2,s),c),(u,c)=>e(_=>{const d=Ji(xt(At(f=>f==="}"))("'}'")),l=t._3&&!u._3?k(u._1,u._2,!0):u;return e(f=>d(l,e,n,(h,p)=>r(k(h._1,h._2,s),p),(h,p)=>e(m=>Ji(ds)(l._3&&!h._3?k(h._1,h._2,!0):h,e,n,(w,x)=>r(k(w._1,w._2,s),x),(w,x)=>e(y=>{const T=t._3&&!w._3?k(w._1,w._2,!0):w;return e(C=>Wa(T,e,n,r,(S,E)=>e(B=>{const M=Hg([CL,TL,vL]),Y=T._3&&!S._3?k(S._1,S._2,!0):S;return e(R=>M(Y,e,n,r,(A,j)=>e(Z=>{const z=Y._3&&!A._3?k(A._1,A._2,!0):A;return e(W=>ee(z,e,n,r,(H,D)=>e(F=>{const L=z._3&&!H._3?k(H._1,H._2,!0):H;return e(G=>Zh(L,e,n,r,(Q,V)=>e(K=>{const U=L._3&&!Q._3?k(Q._1,Q._2,!0):Q;return e(O=>ln(U,e,n,r,(X,et)=>e(lt=>o(U._3&&!X._3?k(X._1,X._2,!0):X,j))))})))})))})))})))})))))})))}),TL=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(a=>{const u=(c,_)=>{const d=c._3;return e(l=>d?r(c,_):e(f=>{const h=t._3;return e(p=>Tn("seq")(t,e,n,(m,w)=>r(k(m._1,m._2,h),w),(m,w)=>e(x=>{const y=t._3&&!m._3?k(m._1,m._2,!0):m;return e(T=>ee(y,e,n,(C,S)=>r(k(C._1,C._2,h),S),(C,S)=>e(E=>$g(y._3&&!C._3?k(C._1,C._2,!0):C,e,n,(B,M)=>r(k(B._1,B._2,h),M),(B,M)=>e(Y=>{const R=t._3&&!B._3?k(B._1,B._2,!0):B;return e(A=>Wa(R,e,n,r,(j,Z)=>e(z=>{const W=xt(xt(At(D=>D==="{"))("'{'"))("'{'"),H=R._3&&!j._3?k(j._1,j._2,!0):j;return e(D=>W(H,e,n,r,(F,L)=>e(G=>o(H._3&&!F._3?k(F._1,F._2,!0):F,pr("GroupSeq",[])))))})))})))))})))}))};return e(c=>e(_=>Tn("seq")(k(i,s,!1),e,n,(d,l)=>u(k(d._1,d._2,!1),l),(d,l)=>e(f=>e(h=>ee(d,e,n,(p,m)=>u(k(p._1,p._2,!1),m),(p,m)=>e(w=>{const x=d._3&&!p._3?k(p._1,p._2,!0):p;return xt(At(y=>y==="{"))("'{'")(x,e,n,(y,T)=>u(k(x._1,x._2,!1),T),(y,T)=>e(C=>Ug(Kg(k5))(x,e,n,u,o)))})))))))})},CL=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(a=>{const u=(c,_)=>{const d=c._3;return e(l=>d?r(c,_):e(f=>{const h=t._3;return e(p=>Tn("par")(t,e,n,(m,w)=>r(k(m._1,m._2,h),w),(m,w)=>e(x=>{const y=t._3&&!m._3?k(m._1,m._2,!0):m;return e(T=>ee(y,e,n,(C,S)=>r(k(C._1,C._2,h),S),(C,S)=>e(E=>$g(y._3&&!C._3?k(C._1,C._2,!0):C,e,n,(B,M)=>r(k(B._1,B._2,h),M),(B,M)=>e(Y=>{const R=t._3&&!B._3?k(B._1,B._2,!0):B;return e(A=>Wa(R,e,n,r,(j,Z)=>e(z=>{const W=xt(xt(At(D=>D==="{"))("'{'"))("'{'"),H=R._3&&!j._3?k(j._1,j._2,!0):j;return e(D=>W(H,e,n,r,(F,L)=>e(G=>o(H._3&&!F._3?k(F._1,F._2,!0):F,pr("Par",[])))))})))})))))})))}))};return e(c=>e(_=>Tn("par")(k(i,s,!1),e,n,(d,l)=>u(k(d._1,d._2,!1),l),(d,l)=>e(f=>e(h=>ee(d,e,n,(p,m)=>u(k(p._1,p._2,!1),m),(p,m)=>e(w=>{const x=d._3&&!p._3?k(p._1,p._2,!0):p;return xt(At(y=>y==="{"))("'{'")(x,e,n,(y,T)=>u(k(x._1,x._2,!1),T),(y,T)=>e(C=>Ug(Kg(C5))(x,e,n,u,o)))})))))))})},Kg=t=>{const e=Dn(up);return(n,r,o,i,s)=>r(a=>e(n,r,o,i,(u,c)=>r(_=>s(n._3&&!u._3?k(u._1,u._2,!0):u,t(Zt(de.foldr,c))))))},Yg=t=>e=>(n,r,o,i,s)=>r(a=>rL(t)(n,r,o,i,(u,c)=>r(_=>{const d=Dn(At(AS)),l=n._3&&!u._3?k(u._1,u._2,!0):u;return r(f=>d(l,r,o,i,(h,p)=>r(m=>{const w=xt(xt(At(y=>y==="{"))("'{'"))("'{'"),x=l._3&&!h._3?k(h._1,h._2,!0):h;return r(y=>w(x,r,o,i,(T,C)=>r(S=>{const E=x._3&&!T._3?k(T._1,T._2,!0):T;return r(B=>ln(E,r,o,i,(M,Y)=>r(R=>{const A=Kg(b5),j=E._3&&!M._3?k(M._1,M._2,!0):M;return r(Z=>A(j,r,o,i,(z,W)=>r(H=>{const D=j._3&&!z._3?k(z._1,z._2,!0):z;return r(F=>ln(D,r,o,i,(L,G)=>r(Q=>{const V=xt(xt(At(U=>U==="}"))("'}'"))("closing '}'"),K=D._3&&!L._3?k(L._1,L._2,!0):L;return r(U=>V(K,r,o,i,(O,X)=>r(et=>{const lt=K._3&&!O._3?k(O._1,O._2,!0):O;return r(bt=>ln(lt,r,o,i,(pt,Tt)=>r(Gt=>s(lt._3&&!pt._3?k(pt._1,pt._2,!0):pt,{name:WS(Or(Zt(de.foldr,p))),ops:W,kind:e}))))})))})))})))})))})))})))}))),bL=(t,e,n,r,o)=>{const i=t._1,s=t._2;return e(a=>jn("keyframe")("Drop the `keyframe` wrapper; Markgraf animates statements in order.")(k(i,s,!1),e,n,(u,c)=>{const _=u._3;return e(d=>{if(_)return r(u,c);const l=t._1,f=t._2;return e(h=>Yg("scene")(Fa)(k(l,f,!1),e,n,(p,m)=>{const w=p._3;return e(x=>{if(w)return r(p,m);const y=t._1,T=t._2;return e(C=>Yg("still")(zg)(k(y,T,!1),e,n,(S,E)=>{const B=S._3;return e(M=>B?r(S,E):Yg("title")(T5)(t,e,n,r,o))},o))})},o))})},o))},kL=t=>e=>n=>{if(t==="AnimatedSurface")return{...e,frames:St(e.frames)({name:J,ops:n,kind:Fa})};if(t==="StillSurface")return{...e,statements:St(e.statements)(n)};if(t==="SequenceSurface")return{...e,statements:St(e.statements)(n)};g()},SL=t=>e=>n=>{if(n.tag==="TopFrame"){const r=rp(t)(e);return{...r,frames:St(r.frames)((()=>{if(t==="AnimatedSurface")return n._1;if(t==="StillSurface")return{...n._1,kind:n._1.kind==="AnimatedKeyframe"?zg:n._1.kind==="StepMarker"?Ah:n._1.kind};if(t==="SequenceSurface")return n._1;g()})())}}if(n.tag==="TopStatement")return kL(t)(e)(n._1);if(n.tag==="TopInside")return e;g()},LL=t=>{const e=v(SL(t))($S);return n=>rp(t)(e(n)).frames},EL=t=>dS.defer(e=>{const n=lL(t);return(r,o,i,s,a)=>{const u=r._1,c=r._2;return o(_=>aL(t)(k(u,c,!1),o,i,(d,l)=>{const f=d._3;return o(h=>{if(f)return s(d,l);const p=r._1,m=r._2;return o(w=>o(x=>GL(k(p,m,!1),o,i,(y,T)=>{const C=y._3;return o(S=>{if(C)return s(y,T);const E=r._1,B=r._2;return o(M=>o(Y=>n(k(E,B,!1),o,i,(R,A)=>{const j=R._3;return o(Z=>{if(j)return s(R,A);const z=r._1,W=r._2;return o(H=>o(D=>bL(k(z,W,!1),o,i,(F,L)=>{const G=F._3;return o(Q=>G?s(F,L):o(V=>up(r,o,i,s,(K,U)=>o(O=>a(K,qa("TopStatement",U))))))},(F,L)=>o(G=>a(F,qa("TopFrame",L))))))})},(R,A)=>o(j=>a(R,qa("TopFrame",A))))))})},(y,T)=>o(C=>a(y,qa("TopInside",T))))))})},a))}}),GL=(t,e,n,r,o)=>e(i=>Tn("inside")(t,e,n,r,(s,a)=>e(u=>{const c=xt(eo)("space after 'inside'"),_=t._3&&!s._3?k(s._1,s._2,!0):s;return e(d=>c(_,e,n,r,(l,f)=>e(h=>{const p=xt(ze)("node identifier after 'inside'"),m=_._3&&!l._3?k(l._1,l._2,!0):l;return e(w=>p(m,e,n,r,(x,y)=>e(T=>{const C=m._3&&!x._3?k(x._1,x._2,!0):x;return e(S=>ln(C,e,n,r,(E,B)=>e(M=>{const Y=C._3&&!E._3?k(E._1,E._2,!0):E;return e(R=>Ug(cp)(Y,e,n,r,(A,j)=>e(Z=>{const z=Y._3&&!A._3?k(A._1,A._2,!0):A;return e(W=>ln(z,e,n,r,(H,D)=>e(F=>o(z._3&&!H._3?k(H._1,H._2,!0):H,{node:y,doc:j}))))})))})))})))})))}))),cp=(t,e,n,r,o)=>e(i=>gL(t,e,n,r,(s,a)=>e(u=>{const c=t._3&&!s._3?k(s._1,s._2,!0):s;return e(_=>{const d=(h,p)=>e(m=>{const w=Dn(EL(a)),x=c._3&&!h._3?k(h._1,h._2,!0):h;return e(y=>w(x,e,n,r,(T,C)=>e(S=>{const E=Zt(de.foldr,C);return o(x._3&&!T._3?k(T._1,T._2,!0):T,{seed:(()=>{if(p.tag==="Nothing")return 0;if(p.tag==="Just")return p._1;g()})(),mode:a,frames:LL(a)(E),interiors:vt(B=>{if(B.tag==="TopInside")return N("Just",B._1);if(B.tag==="TopFrame"||B.tag==="TopStatement")return J;g()})(E)})})))}),l=c._1,f=c._2;return e(h=>e(p=>sL(k(l,f,!1),e,n,(m,w)=>{const x=m._3;return e(y=>x?r(m,w):d(c,J))},(m,w)=>e(x=>d(m,N("Just",w))))))})}))),PL=(()=>{const t=xt((e,n,r,o,i)=>n(s=>n(a=>ln(e,n,r,o,(u,c)=>n(_=>n(d=>{const l=e._3&&!u._3?k(u._1,u._2,!0):u;return ds(l,n,r,o,(f,h)=>n(p=>i(l._3&&!f._3?k(f._1,f._2,!0):f,h)))}))))))("'scene', 'still', 'title', 'step', 'inside', a statement, or end of input");return(e,n,r,o,i)=>n(s=>n(a=>n(u=>n(c=>ln(e,n,r,o,(_,d)=>n(l=>n(f=>{const h=e._3&&!_._3?k(_._1,_._2,!0):_;return cp(h,n,r,o,(p,m)=>n(w=>{const x=h._3&&!p._3?k(p._1,p._2,!0):p;return n(y=>n(T=>{const C=e._3&&!x._3?k(x._1,x._2,!0):x;return t(C,n,r,o,(S,E)=>n(B=>i(C._3&&!S._3?k(S._1,S._2,!0):S,m)))}))}))})))))))})(),BL=t=>{const e=mS(t)(PL);if(e.tag==="Left")return Wt("Left",{msg:MS(e._1._1),line:e._1._2.line,column:e._1._2.column,endLine:e._1._2.line,endColumn:e._1._2.column+1|0});if(e.tag==="Right")return Wt("Right",e._1);g()},DL=t=>{const e=BL(t);if(e.tag==="Left")return Wt("Left",e._1.msg);if(e.tag==="Right")return Wt("Right",e._1);g()},RL=()=>({tag:"ParFrag"}),gp=t=>t,AL=gp("Sync"),IL=gp("SelfMsg"),FL=RL(),no=Bh(kn),Ni=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=P.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},qn=Eo(kn),Fr=no.state(t=>b(t,t)),_p=t=>e=>{const n=it.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},Va=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},Bo=Go(kn),QL=t=>e=>v(n=>r=>Eo(kn).bind(n)(o=>t(o)(r)))(Go(kn).pure(e)),fp=Qr(Bo)(Mt),zL=t=>no.state(e=>b(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:N("Just",t)};g()})())),ML=t=>e=>no.state(n=>b(void 0,{...n,lifelines:J_(P)(r=>N("Just",{...r,label:e}))(t)(n.lifelines)})),WL=t=>e=>n=>{const r=Ni(n)(t.lifelines);return Ni(e)(t.lifelines).tag==="Nothing"?r.tag==="Nothing"?e+", "+n:e:r.tag==="Nothing"?n:""},OL={lifelines:I,lifelineOrder:[],messages:[],fragments:[],frameEndRows:[],row:0,error:J},qL=t=>e=>n=>qn.bind(Fr)(r=>{const o=Ni(t)(r.lifelines),i=Ni(e)(r.lifelines);if(o.tag==="Just"&&i.tag==="Just"){const s={...r,messages:[{fromCol:o._1.column,toCol:i._1.column,labels:n,row:r.row,kind:t===e?IL:AL},...r.messages],row:r.row+1|0};return no.state(a=>b(void 0,s))}return zL("token references unknown node: "+WL(r)(t)(e))}),HL=t=>no.state(e=>b(void 0,{...e,lifelines:J_(P)(n=>N("Just",{...n,destroyedAt:N("Just",e.row)}))(t)(e.lifelines)})),$L=t=>e=>{const n=e.lifelineOrder.length,r=Ft(o=>J,o=>i=>N("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return{fromCol:0,toCol:Va(0)(e.lifelineOrder.length-1|0)};if(r.tag==="Just")return v(o=>i=>({fromCol:_p(o.fromCol)(_p(i.fromCol)(i.toCol)),toCol:Va(o.toCol)(Va(i.fromCol)(i.toCol))}))({fromCol:n,toCol:0})(t);g()},VL=t=>({lifelines:vt(e=>Ni(e)(t.lifelines))(t.lifelineOrder),messages:se(t.messages),fragments:se(t.fragments),frameEndRows:t.frameEndRows,totalRows:t.row}),UL=t=>e=>qn.bind(Fr)(n=>{const r=Ni(t)(n.lifelines);if(r.tag==="Just")return Bo.pure();if(r.tag==="Nothing"){const o={...n,lifelines:rt(P)(t)({id:t,label:e,column:n.lifelineOrder.length,createdAt:n.row,destroyedAt:J})(n.lifelines),lifelineOrder:St(n.lifelineOrder)(t),row:n.row>0||n.messages.length!==0?n.row+1|0:n.row};return no.state(i=>b(void 0,o))}g()}),KL=t=>{if(t.tag==="AddNode")return UL(t._1.id)(t._1.label);if(t.tag==="DelNode")return HL(t._1.id);if(t.tag==="ModNode"){if(t._1.label.tag==="Just")return ML(t._1.id)(t._1.label._1);if(t._1.label.tag==="Nothing")return Bo.pure();g()}return t.tag==="Token"?qL(t._1.from)(t._1.to)(t._1.labels):Bo.pure()},YL=t=>qn.bind(Fr)(e=>{const n=e.row;return qn.bind(QL(r=>o=>qn.bind(Fr)(i=>{const s=r.childMessages.length===0?r.dividers:[i.row,...r.dividers],a=i.messages;return qn.bind(Xg(o))(()=>qn.bind(Fr)(u=>Bo.pure({dividers:s,childMessages:[...r.childMessages,...(()=>{const c=u.messages.length-a.length|0;return c<1?[]:Rt(0,c,u.messages)})()]})))}))({dividers:[],childMessages:[]})(t))(r=>qn.bind(Fr)(o=>{const i=$L(r.childMessages)(o),s={kind:FL,label:"par",fromRow:n,toRow:Va(o.row)(n+1|0),fromCol:i.fromCol,toCol:i.toCol,regionDividers:se(r.dividers)},a=no.state(u=>b(void 0,{...u,fragments:[s,...u.fragments]}));return r.childMessages.length>=2?a:Bo.pure()}))}),Xg=t=>{if(t.tag==="Leaf")return KL(t._1.op);if(t.tag==="Seq"||t.tag==="GroupSeq")return fp(Xg)(t._1);if(t.tag==="Par")return YL(t._1);g()},XL=t=>{const e=qn.bind(fp(n=>qn.bind(Fr)(r=>qn.bind(Xg(n.ops))(()=>qn.bind(Fr)(o=>{const i=no.state(s=>b(void 0,{...s,frameEndRows:St(s.frameEndRows)(s.row-1|0)}));return(o.messages.length-r.messages.length|0)>0?i:Bo.pure()}))))(t.frames))(()=>Fr)(OL)._1;if(e.error.tag==="Just")return Wt("Left",e.error._1);if(e.error.tag==="Nothing")return Wt("Right",VL(e));g()},jL=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},ZL={padding:24,headerHeight:36,headerWidth:120,columnSpacing:160,rowHeight:36,topGap:24,bottomGap:24},tE=t=>{const e=84+nt(jL(1)(t.totalRows))*36,n=Ht(r=>o=>({lifeline:o,x:84+nt(r)*160}))(t.lifelines);return{metrics:ZL,columns:n,width:(()=>{const r=n.length-1|0;return r>=0&&r<n.length?n[r].x+84:48})(),height:e+48,headerTop:24,headerBottom:60,bodyTop:84,bodyBottom:e,diagram:t}},eE=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=J;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=N("Just",i._4);continue}}g()}return o},dp=t=>e=>{const n=it.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},lp=t=>e=>{let n=e,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const s=it.compare(t)(i._3);if(s==="LT"){n=i._5;continue}if(s==="GT"){n=i._6;continue}if(s==="EQ"){r=!1,o=!0;continue}}g()}return o},hp=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},nE=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},rE=v(t=>e=>rt(it)(e)()(t))(I),oE={r:255,g:255,b:255,a:255},Ua={r:26,g:26,b:26,a:255},iE={color:{r:232,g:232,b:232,a:255},flat:!0},sE={r:232,g:232,b:232,a:255},Ka=t=>e=>n=>r=>o=>[1,t+o,e,2,n-o,e,3,n,e,n,e+o,2,n,r-o,3,n,r,n-o,r,2,t+o,r,3,t,r,t,r-o,2,t,e+o,3,t,e,t+o,e,...rs],pp=t=>e=>n=>({...n,stack:St(n.stack)(t),openedAt:rt(it)(t)(e)(n.openedAt)}),Ya=t=>e=>{const n=e.stack.length-1|0;if(n>=0&&n<e.stack.length){const r=eE(e.stack[n])(e.openedAt),o=(()=>{if(r.tag==="Nothing")return t;if(r.tag==="Just")return r._1;g()})();return{...e,stack:e.stack.length===0?[]:Rt(0,e.stack.length-1|0,e.stack),openedAt:Wo(it)(e.stack[n])(e.openedAt),spans:St(e.spans)({col:e.stack[n],fromRow:o,toRow:dp(o)(t)})}}return e},mp=t=>e=>n=>{let r=t,o=e,i=n,s=!0,a;for(;s;){const u=r,c=o,_=i,d=_.stack.length-1|0;if(d>=0&&d<_.stack.length){if(u(_.stack[d])){s=!1,a=_;continue}r=u,o=c,i=Ya(c)(_);continue}s=!1,a=_}return a},yp=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r,u=a.stack.length-1|0;if(u>=0&&u<a.stack.length){n=s,r=Ya(s)(a);continue}o=!1,i=a}return i},aE=t=>e=>{const n=en(zr)(e.fromCol)(t.stack)?mp((()=>{const r=e.fromCol;return o=>r===o})())(e.row-1|0)(t):pp(e.fromCol)(e.row)(yp(e.row-1|0)(t));if(en(zr)(e.toCol)(n.stack)){const r=mp((()=>{const o=e.toCol;return i=>o===i})())(e.row-1|0)(Ya(e.row)(n));return{...r,returnRows:rt(it)(e.row)()(r.returnRows)}}return pp(e.toCol)(e.row)(n)},uE=t=>e=>n=>{const r=aE(e)(n);return lp(n.row)(t)?yp(n.row)(r):r},Xa={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:es,lineCap:Vn},xp={r:26,g:26,b:26,a:255},cE={color:{r:130,g:130,b:130,a:255},width:1,lineJoin:es,lineCap:Gn},wp={color:{r:26,g:26,b:26,a:255},width:1.5,lineJoin:es,lineCap:Gn},gE={color:{r:244,g:244,b:244,a:255},flat:!0},Jp=t=>e=>n=>Ne(r=>r.col===e&&r.fromRow<=n&&n<=r.toRow,t),Np={color:{r:90,g:90,b:90,a:255},width:1,lineJoin:es,lineCap:Gn},_E={stack:[],openedAt:I,spans:[],returnRows:I},fE={color:{r:150,g:150,b:150,a:255},width:1,lineJoin:es,lineCap:Gn},dE=t=>e=>n=>r=>o=>{const i=e.bodyTop+(nt(o)+.5)*e.metrics.rowHeight-e.metrics.rowHeight/2;return t.strokePath([1,n,i,2,r,i])(fE)},lE=t=>{const e=t.Monad0(),n=e.Bind1(),r=Io(e.Applicative0())(Mt);return o=>i=>{const s=o.bodyTop+(nt(i.fromRow)+.5)*o.metrics.rowHeight-o.metrics.rowHeight/2-6,a=i.fromCol>=0&&i.fromCol<o.columns.length?o.columns[i.fromCol].x-16:o.metrics.padding-16,u=[1,a,s,2,a+38,s,2,a+32,s+14,2,a,s+14,...rs],c=i.toCol>=0&&i.toCol<o.columns.length?o.columns[i.toCol].x+16:o.metrics.padding+16,_=o.bodyTop+(nt(dp(i.toRow)(i.fromRow+1|0)-1|0)+.5)*o.metrics.rowHeight+o.metrics.rowHeight/2+6;return n.bind(t.strokePath([1,a,s,2,c,s,2,c,_,2,a,_,...rs])(Np))(()=>n.bind(t.fillStrokePath(u)(iE)(Np))(()=>n.bind(t.drawText({x:a+6,y:s+7,content:"par",font:{family:"Inter",size:11,weight:700},color:Ua,align:_i,baseline:En}))(()=>r(i.regionDividers)(dE(t)(o)(a)(c)))))}},vp=t=>e=>t>=e?[]:[b(t,hp(e)(t+6)),...vp(t+10)(e)],hE=t=>e=>{if(e<=t)return[];const n=r=>r>=e?[]:[b(r,hp(e)(r+6)),...n(r+10)];return n(t)},pE=t=>{const e=Io(t.Monad0().Applicative0())(Mt);return n=>r=>e(hE(n.headerTop+n.metrics.headerHeight+nt(r.lifeline.createdAt)*n.metrics.rowHeight+4)((()=>{if(r.lifeline.destroyedAt.tag==="Just")return n.bodyTop+(nt(r.lifeline.destroyedAt._1)+.5)*n.metrics.rowHeight;if(r.lifeline.destroyedAt.tag==="Nothing")return n.bodyBottom;g()})()))(o=>t.strokePath([1,r.x,o._1,2,r.x,o._2])(cE))},Tp=t=>e=>t<=e?[]:[b(t,nE(e)(t-6)),...Tp(t-6-4)(e)],mE=t=>e=>t===e?[]:t<e?vp(t)(e):Tp(t)(e),yE=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.headerTop+nt(r.lifeline.createdAt)*n.metrics.rowHeight,i=n.metrics.headerWidth/2,s=o+n.metrics.headerHeight,a=Ka(r.x-i)(o)(r.x+i)(s)(6);return e.bind(t.fillStrokePath(Ka(r.x-i)(o+5)(r.x+i)(s+5)(6))({color:sE,flat:!0})(wp))(()=>e.bind(t.fillStrokePath(a)(gE)(wp))(()=>t.drawText({x:r.x,y:o+n.metrics.headerHeight/2,content:r.lifeline.label,font:{family:"Inter",size:14,weight:600},color:Ua,align:Gr,baseline:En})))}},xE=t=>e=>{let n=t,r=e,o=!0,i;for(;o;){const s=n,a=r,u=a.stack.length-1|0;if(u>=0&&u<a.stack.length){n=s,r=Ya(s)(a);continue}o=!1,i=a}return i},wE=t=>xE((()=>{const e=t.diagram.messages.length-1|0;return e>=0&&e<t.diagram.messages.length?t.diagram.messages[e].row:0})())(v(uE(rE(t.diagram.frameEndRows)))(_E)(ft(e=>e.kind==="Sync"||e.kind!=="SelfMsg",t.diagram.messages))),JE=t=>{const e=t.Monad0().Bind1();return n=>r=>{const o=n.bodyTop+(nt(r.row)+.5)*n.metrics.rowHeight,i=r.fromCol>=0&&r.fromCol<n.columns.length?n.columns[r.fromCol].x:n.metrics.padding,s=o-n.metrics.rowHeight*.3,a=i+36,u=o+n.metrics.rowHeight*.3,c=i+10,_=[1,i,u,2,c,u-5,2,c,u+5,...rs];return e.bind(t.strokePath([1,i,s,2,a,s,2,a,u,2,i,u])(Xa))(()=>e.bind(t.fillPath(_)({color:xp,flat:!0}))(()=>t.drawText({x:i+42,y:o,content:sr(" ")(q(Ci)(r.labels)),font:{family:"Inter",size:12,weight:400},color:Ua,align:_i,baseline:En})))}},NE=t=>{const e=t.Monad0(),n=e.Bind1(),r=Io(e.Applicative0())(Mt);return o=>i=>s=>a=>{const u=s?o.bodyTop+(nt(a.row)+.5)*o.metrics.rowHeight+o.metrics.rowHeight*.5:o.bodyTop+(nt(a.row)+.5)*o.metrics.rowHeight,c=a.toCol>=a.fromCol?1:-1,_=(a.fromCol>=0&&a.fromCol<o.columns.length?o.columns[a.fromCol].x:o.metrics.padding)+(Jp(i)(a.fromCol)(a.row)?c*6:c*0),d=(a.toCol>=0&&a.toCol<o.columns.length?o.columns[a.toCol].x:o.metrics.padding)-(Jp(i)(a.toCol)(a.row)?c*6:c*0),l=d-c*10,f=s?t.strokePath([1,l,u-5,2,d,u,2,l,u+5])(Xa):t.fillPath([1,d,u,2,l,u-5,2,l,u+5,...rs])({color:xp,flat:!0});return n.bind(s?r(mE(_)(d))(h=>t.strokePath([1,h._1,u,2,h._2,u])(Xa)):t.strokePath([1,_,u,2,d,u])(Xa))(()=>n.bind(f)(()=>t.drawText({x:(_+d)/2,y:u-6,content:sr(" ")(q(Ci)(a.labels)),font:{family:"Inter",size:12,weight:400},color:Ua,align:Gr,baseline:Yv})))}},vE=t=>{const e=JE(t),n=NE(t);return r=>o=>i=>s=>{if(s.kind==="SelfMsg")return e(r)(s);if(s.kind==="Sync")return n(r)(o)(lp(s.row)(i))(s);g()}},Cp={color:{r:26,g:26,b:26,a:255},width:1.25,lineJoin:Ve,lineCap:Gn},TE={color:{r:232,g:232,b:232,a:255},flat:!0},CE={color:{r:252,g:252,b:252,a:255},flat:!0},bE=t=>e=>n=>{const r=n.col>=0&&n.col<e.columns.length?e.columns[n.col].x:e.metrics.padding,o=e.bodyTop+(nt(n.fromRow)+.5)*e.metrics.rowHeight,i=e.bodyTop+(nt(n.toRow)+.5)*e.metrics.rowHeight+e.metrics.rowHeight*.5,s=Ka(r-6)(o)(r+6)(i)(3);return t.Monad0().Bind1().bind(t.fillStrokePath(Ka(r-6)(o+5)(r+6)(i+5)(3))(TE)(Cp))(()=>t.fillStrokePath(s)(CE)(Cp))},bp=t=>{const e=t.Monad0(),n=e.Bind1(),r=Io(e.Applicative0())(Mt),o=yE(t),i=pE(t),s=lE(t),a=vE(t);return u=>{const c=wE(u);return n.bind(t.setViewport({vx:0,vy:0,vw:u.width,vh:u.height}))(()=>n.bind(t.clearBackground(oE))(()=>n.bind(r(u.columns)(o(u)))(()=>n.bind(r(u.columns)(i(u)))(()=>n.bind(r(c.spans)(bE(t)(u)))(()=>n.bind(r(u.diagram.fragments)(s(u)))(()=>r(u.diagram.messages)(a(u)(c.spans)(c.returnRows))))))))}},kE=bp(hT);function jg(t,e,n,r){if(typeof window<"u"){var o=window[n];if(o!=null&&r instanceof o)return e(r)}for(var i=r;i!=null;){var s=Object.getPrototypeOf(i),a=s.constructor.name;if(a===n)return e(r);if(a==="Object")return t;i=s}return t}function gn(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function SE(t){return function(e){return function(){return e.getAttribute(t)}}}const kp=t=>{const e=SE(t);return n=>{const r=e(n);return()=>{const o=r();return mn(o,J,Kt)}}};function LE(t){return function(e){return function(){e.textContent=t}}}function EE(t){return function(){return function(e){return t(e)()}}}function GE(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const Zg=function(){return window};function PE(t){return function(e){return function(){e.value=t}}}function BE(t){return function(){return t.valueAsNumber}}function DE(t){return function(){return t.value}}function t_(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const Sp=t=>t,ja=t=>()=>{const e=t.getBoundingClientRect?.(),n=e?.width||t.clientWidth||0,r=e?.height||t.clientHeight||0;return{width:n,height:r}},Lp=t=>e=>()=>{let n=0;const r=()=>{n||(n=requestAnimationFrame(()=>{n=0,e()}))},o=typeof ResizeObserver>"u"?null:new ResizeObserver(r);return o?.observe(t),window.addEventListener("resize",r),()=>{n&&cancelAnimationFrame(n),o?.disconnect(),window.removeEventListener("resize",r)}},Ep=()=>window.devicePixelRatio||1,RE=t=>e=>n=>r=>o=>()=>{const i=Math.max(1,e||t.clientWidth||r),s=Math.max(1,n||t.clientHeight||o),a="Markgraf needs more room",u=`Resize to at least ${Math.round(r)} \xD7 ${Math.round(o)} px`;if(t.setAttribute("data-mg-too-small","1"),t.setAttribute("data-mg-viewport-css-width",String(e||0)),t.setAttribute("data-mg-viewport-css-height",String(n||0)),t.setAttribute("data-mg-camera-vw","0"),t.setAttribute("data-mg-camera-vh","0"),t.setAttribute("data-mg-camera-zoom","0"),t instanceof SVGElement){t.setAttribute("viewBox",`0 0 ${i} ${s}`),t.setAttribute("preserveAspectRatio","xMidYMid meet"),t.innerHTML=`
26
+ <rect x="0" y="0" width="${i}" height="${s}" rx="16" fill="#111827"/>
27
+ <text x="${i/2}" y="${s/2-10}" text-anchor="middle" dominant-baseline="middle" fill="#f9fafb" font-family="system-ui, sans-serif" font-size="18" font-weight="700">${a}</text>
28
+ <text x="${i/2}" y="${s/2+18}" text-anchor="middle" dominant-baseline="middle" fill="#cbd5e1" font-family="system-ui, sans-serif" font-size="13">${u}</text>
29
+ `;return}if(t instanceof HTMLCanvasElement){const c=window.devicePixelRatio||1;t.width=Math.max(1,Math.round(i*c)),t.height=Math.max(1,Math.round(s*c));const _=t.getContext("2d");if(!_)return;_.save(),_.scale(c,c),_.clearRect(0,0,i,s),_.fillStyle="#111827",_.fillRect(0,0,i,s),_.textAlign="center",_.textBaseline="middle",_.fillStyle="#f9fafb",_.font="700 18px system-ui, sans-serif",_.fillText(a,i/2,s/2-10),_.fillStyle="#cbd5e1",_.font="13px system-ui, sans-serif",_.fillText(u,i/2,s/2+18),_.restore();return}t.textContent=`${a}. ${u}.`},hs=(t,e)=>{e.innerHTML=t},Za=(t,e,n)=>{t.style.setProperty(e,n)},AE=(t,e)=>t.querySelector(`[data-mg="${e}"]`),tu=t=>e=>t===e,Gp=(t,e)=>({tag:t,_1:e}),Pp=t=>t,IE=(t,e,n)=>({tag:t,_1:e,_2:n}),Do=t=>e=>{const n=ot.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;g()},FE=bp($c),QE=Mt.foldMap(Z0),eu=t=>e=>{const n=ot.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;g()},e_=IE("AutoSize"),zE=Pp("CanvasRenderer"),ME=Pp("SvgRenderer"),WE=t=>e=>{const n=t-e*nt(fe(An(t/e)));return e<=0?0:n<0?n+e:n},vi=t=>v(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),OE=t=>{const e=kp("data-markgraf-titles")(t);return()=>{const n=e();return n.tag==="Nothing"||!(n.tag==="Just"&&n._1==="false")}},qE=t=>{const e=kp("data-markgraf-theme")(t);return()=>{const n=e();if(n.tag==="Just")return n._1==="light"?bg:n._1==="dark"?sb:n._1==="blueprint"?ab:n._1==="whiteboard"?ub:n._1==="isometric"?cb:bg;if(n.tag==="Nothing")return bg;g()}},HE=`
20
30
  <canvas data-mg="stage" tabindex="0"></canvas>
21
31
  <div data-mg="play-overlay" aria-hidden="true"></div>
22
32
  <div data-mg="bar">
@@ -33,4 +43,6 @@ var jb=(function(Iu){"use strict";function Ua(t){let e=0,n;return()=>{if(e===2)r
33
43
  <option value="2">2\xD7</option>
34
44
  </select>
35
45
  </div>
36
- `,Z1=t=>e=>({...e,state:{...e.state,camera:t},minis:H(n=>Z1(t)(n))(e.minis)}),zb=t=>e=>n=>{const r=Jo(n.rootLayout)(n.camera),i=_n("data-mg-too-small")("0")(t);return()=>(i(),_n("data-mg-camera-vw")(dr(r.w))(t)(),_n("data-mg-camera-vh")(dr(r.h))(t)(),_n("data-mg-camera-zoom")(dr(n.camera.zoom))(t)(),_n("data-mg-viewport-css-width")(dr(e.w))(t)(),_n("data-mg-viewport-css-height")(dr(e.h))(t)())},Yn=t=>e=>n=>()=>{const r=Lb(t,e),i=mc(r,J,Zt);if(i.tag==="Just")return n(i._1)();i.tag!=="Nothing"&&g()},Bb=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=Cb(i=>'<span class="mg-tick" style="left:'+pi(li("Fixed",hi(0)(20)(2)))(100*i.startT/n)+'%" data-label="'+(()=>{if(i.scene.tag==="Structural")return i.scene._1.to;if(i.scene.tag==="DataFlow")return i.scene._1.keyframe;if(i.scene.tag==="Hold")return i.scene._1;if(i.scene.tag==="EnterNode"||i.scene.tag==="ExitNode")return"";g()})()+'"></span>')(e.spans);return Yn(t)("ticks")(i=>()=>Xa(r,i))},Mb=t=>e=>n=>Yn(t)("scrub")(r=>{const i=Oa(J,Zt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return n<=0?()=>{}:xb(ue(xe(xr(e/n*1e3))))(i._1);g()}),Ya=t=>e=>n=>{const r=mb(i=>n);return()=>{const i=r();return yb(t)(i)(!1)(e)()}},td=()=>cl()/1e3,ed=t=>{const e=lb(t);if(e.tag==="Left")return Gt("Left",e._1);if(e.tag==="Right"){const n=D1(e._1)(P1)._1;if(n.tag==="Left")return Gt("Left",n._1.msg);if(n.tag==="Right")return Gt("Right",n._1)}g()},Wb=t=>{const e=ed(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return ol;g()},Va=t=>e=>{const n=Vt(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()},Rb=t=>e=>Yn(t)("speed")(n=>{const r=Oa(J,Zt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return Ya("change")(n)((()=>{const i=Jb(r._1);return()=>{const o=i(),u=Rd(o,_c,Zt,J);if(u.tag==="Just")return e(u._1)();u.tag!=="Nothing"&&g()}})());g()}),qb=t=>e=>n=>Yn(t)("scrub")(r=>{const i=Oa(J,Zt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return Ya("input")(r)((()=>{const o=Nb(i._1);return()=>{const u=o();return n.pause(),n.seek(u/1e3*e.totalDuration)()}})());g()}),Hb=t=>e=>n=>{const r=Bb(t)(e);return()=>{r(),Yn(t)("play")(i=>_n("data-mg-playing")("1")(i))(),Rb(t)(n.setSpeed)(),Yn(t)("play")(i=>Ya("click")(i)(n.toggle))(),qb(t)(e)(n)(),n.subscribe(i=>{const o=Mb(t)(i.time)(e.totalDuration);return()=>(o(),Yn(t)("time")(u=>pb(pi(li("Fixed",hi(0)(20)(2)))(i.time)+" / "+pi(li("Fixed",hi(0)(20)(2)))(e.totalDuration))(u))(),Yn(t)("play")(u=>_n("data-mg-playing")(i.playing?"1":"0")(u))())})()}},Ob=t=>e=>n=>{const r=o_(n);return()=>{const i=r(),o=u_(n)(),u=Jp(t0)(up)(n)(s_(i)(o)(n));if(u.tag==="Left")return Gt("Left","precompute failed");if(u.tag==="Right")return Gt("Right",{schedule:u._1});g()}},$b=t=>e=>{if(e.tag==="FixedSize"){const n=e._1<=0||e._2<=0?J:T("Just",e._1/e._2);return()=>n}if(e.tag==="AutoSize"){const n=$a(t);return()=>{const r=n();return r.width<=0||r.height<=0?J:T("Just",r.width/r.height)}}g()},Gu=t=>e=>n=>r=>i=>o=>u=>s=>a=>c=>f=>()=>{const d=td(),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=$a(t)();return{w:b.width<=0?480:b.width,h:b.height<=0?320:b.height}}g()})();if(h.w<480||h.h<320)return bb(t)(h.w)(h.h)(480)(320)();const p=wp({widthPx:h.w,heightPx:h.h})(u),m=sm(p)(K1(f)(p.totalDuration)),y=o?m:{...m,levels:H(b=>({...b,state:{...b.state,frameTitle:""}}))(m.levels)},x=a.value,N=(()=>{if(x.tag==="Nothing")return y.camera;if(x.tag==="Just")return Yh(u.cameraConfig.cameraDecay)(_)(x._1)(y.camera);g()})();a.value=T("Just",N);const v={...y,camera:N,levels:H(Z1(N))(y.levels)};if(zb(t)(h)(v)(),e==="CanvasRenderer"){const b=wb(t),k=$i({padding:8,outputAspect:J})(v),E=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const P=$a(t)();return{w:P.width,h:P.height<=0?k.vw<=0?P.width:P.width*k.vh/k.vw:P.height}}g()})(),A=vb(),$=E.w*A,tt=E.h*A,S=fl(b)(),C=_l(b)(),V=dl(b)($);S!==$&&V();const U=ll(b)(tt);C!==tt&&U(),n.tag==="FixedSize"?(U1(t,"width",ue(xe(xr(E.w)))+"px"),U1(t,"height",ue(xe(xr(E.h)))+"px")):n.tag==="AutoSize"||g();const M=gl(b)();jn(M)(),uo(M)({scaleX:A,scaleY:A})();const W=s.value,B=NT(r)(i)(M)({width:E.w,height:E.h})(v)(_)(W)();return s.value=B,Zn(M)()}if(e==="SvgRenderer"){const b=s.value,k=$b(t)(n)(),E=MT(k)(r)(i)(v)(_)(b);return s.value=E.springs,_n("viewBox")(E.parts.viewBox)(t)(),_n("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(_n("width")(ue(xe(xr(n._1))))(t)(),_n("height")(ue(xe(xr(n._2))))(t)()):n.tag==="AutoSize"||g(),Xa(E.parts.body,t)}g()},Xb=t=>e=>n=>r=>i=>o=>u=>()=>{let s=1,a=!0,c=!1,f=0,d=0;const l={value:D},_={value:J},h={value:0};let p=!1,m=()=>{},y=[];Gu(t)(n)(r)(i)(o)(u)(e)(l)(_)(h)(0)();const x=A=>()=>{const $=y,tt=a,S={time:A,keyframe:Va(e)(A),playing:tt};return Ib(C=>C(S))($)()},N=()=>(a=!1,x(f)()),v=()=>{if(!p&&(c=!1,a)){const A=td(),$=d;d=A;const tt=s,S=f,C=Ab($===0?S+0*tt:S+(A-$)*tt)(e.totalDuration+.8);return C<S&&(_.value=J),f=C,Gu(t)(n)(r)(i)(o)(u)(e)(l)(_)(h)(C)(),x(C)(),b()}},b=()=>{if(!p&&!c){c=!0;const A=Y1();V1(v)(A)()}},k=()=>(d=0,a=!0,b()),E=()=>(a||k(),x(f)());return m=Tb(t)(()=>{if(!p){const A=f;return Gu(t)(n)(r)(i)(o)(u)(e)(l)(_)(h)(A)(),x(A)()}})(),k(),{play:E,pause:N,toggle:()=>a?N():E(),seek:A=>{const $=Gb(0)(K1(e.totalDuration)(A));return()=>(f=$,d=0,_.value=J,Gu(t)(n)(r)(i)(o)(u)(e)(l)(_)(h)($)(),x($)())},setSpeed:A=>()=>s=A,currentTime:()=>f,currentKeyframe:()=>{const A=f;return Va(e)(A)},isPlaying:()=>a,duration:e.totalDuration,subscribe:A=>()=>{y=Dt(y)(A);const $=f,tt=a;A({time:$,keyframe:Va(e)($),playing:tt})();const S=gc(C=>!kb(C)(A));return()=>{y=S(y)}},destroy:()=>(p=!0,m())}},nd=t=>e=>{const n=ed(e);if(n.tag==="Left")return yc("[markgraf] parse failed: "+n._1);if(n.tag==="Right"){const r=n._1,i=Qb(t);return()=>{const o=i(),u=Db(t)();return Xa(Fb,t),Yn(t)("stage")(s=>{const a=Ob()(j1)(r);return()=>{const c=Y1();V1(()=>{const f=a();if(f.tag==="Left")return yc("[markgraf] precompute failed")();if(f.tag==="Right"){const d=Xb(s)(f._1.schedule)(Pb)(j1)(u)(LT)(o)();return Hb(t)(f._1.schedule)(d)()}g()})(c)()}})()}}g()},Yb=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 Pn=null;const Pu=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",Vb=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{Pu(t)?(Pn&&Pn!==t&&Pu(Pn)&&Pn.querySelector('[data-mg="play"]').click(),Pn=t):Pn===t&&(Pn=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},Ub=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=Yb(t),n=t.dataset.markgrafPaused==="true";t.textContent="",nd(t)(e)(),n?Pu(t)&&t.querySelector('[data-mg="play"]').click():Pn===null?Pn=t:Pu(t)&&t.querySelector('[data-mg="play"]').click(),Vb(t)},Au=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(Ub)},rd=()=>{document.addEventListener("keydown",t=>{if(t.code!=="Space"&&t.key!==" ")return;const e=t.target,n=e&&e.closest?.("[data-markgraf]");if(!n){const i=e?.tagName,o=(e?.type||"").toLowerCase();if(e?.isContentEditable||i==="TEXTAREA"||i==="SELECT"||i==="INPUT"&&!["range","checkbox","radio","button","submit","reset"].includes(o))return}const r=n||Pn||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=Wb(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>nd(e)(n)(),mountAll:Au,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{Au(),rd()}):(Au(),rd())}return Iu.mountAll=Au,Object.defineProperty(Iu,Symbol.toStringTag,{value:"Module"}),Iu})({});
46
+ `,Bp=t=>e=>{const n=mn(t,J,Kt);if(n.tag==="Just"){const r=mn(n._1.stopAt,J,Kt);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return e;g()},Dp=t=>e=>({...e,state:{...e.state,camera:t},minis:q(n=>Dp(t)(n))(e.minis)}),$E=t=>e=>n=>{const r=_o(n.rootLayout)(n.camera),o=gn("data-mg-too-small")("0")(t);return()=>(o(),gn("data-mg-camera-vw")(ro(r.w))(t)(),gn("data-mg-camera-vh")(ro(r.h))(t)(),gn("data-mg-camera-zoom")(ro(n.camera.zoom))(t)(),gn("data-mg-viewport-css-width")(ro(e.w))(t)(),gn("data-mg-viewport-css-height")(ro(e.h))(t)())},VE=t=>{const e=XL(t);if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right")return Wt("Right",tE(e._1));g()},UE=t=>e=>n=>{if(e.tag==="FixedSize")return()=>({w:e._1,h:e._2});if(e.tag==="AutoSize"){const r=ja(t);return()=>{const o=r(),i=o.width<=0?n.width:o.width;return{w:i,h:o.height<=0?i*n.height/Do(1)(n.width):o.height}}}g()},KE=t=>e=>n=>{const r=XC(ob(kE(n))),o=gn("viewBox")(r.viewBox)(t);return()=>(o(),gn("preserveAspectRatio")("xMidYMid meet")(t)(),e.tag==="FixedSize"?(gn("width")(ie(fe(Hn(e._1))))(t)(),gn("height")(ie(fe(Hn(e._2))))(t)()):e.tag==="AutoSize"||g(),hs(r.body,t))},YE=t=>e=>n=>{const r=Sp(t),o=UE(t)(e)(n);return()=>{const i=o(),s=Ep(),a=i.w*s,u=i.h*s,c=C_(r)(),_=b_(r)(),d=k_(r)(a);c!==a&&d();const l=S_(r)(u);_!==u&&l(),e.tag==="FixedSize"?(Za(t,"width",ie(fe(Hn(i.w)))+"px"),Za(t,"height",ie(fe(Hn(i.h)))+"px")):e.tag==="AutoSize"||g();const f=T_(r)();nr(f)(),vs(f)({scaleX:s,scaleY:s})();const h=Sd(f)({width:i.w,height:i.h})();return FE(n)(h)(),rr(f)()}},XE=t=>e=>n=>r=>{if(e==="CanvasRenderer")return YE(t)(n)(r);if(e==="SvgRenderer")return KE(t)(n)(r);g()},jE=t=>e=>n=>r=>()=>{let o=!1,i=()=>{},s=[];const a=()=>{const c=o,_=XE(t)(e)(n)(r);if(!c)return _()},u={time:0,keyframe:"sequence",playing:!1};return a(),i=Lp(t)(()=>{a();const c=s;return vi(_=>_(u))(c)()})(),{play:()=>{},playWith:c=>()=>{},pause:()=>{},toggle:()=>{},seek:c=>()=>{},seekCue:c=>()=>{},seekStep:c=>()=>{},playToCue:c=>_=>()=>{},playToStep:c=>_=>()=>{},playNext:c=>()=>{},playPrevious:c=>()=>{},setSpeed:c=>()=>{},currentTime:(()=>{const c=u.time;return()=>c})(),currentKeyframe:(()=>{const c=u.keyframe;return()=>c})(),isPlaying:()=>!1,duration:0,cues:[],steps:[],subscribe:c=>()=>{s=St(s)(c),c(u)();const _=bi(d=>!tu(d)(c));return()=>{s=_(s)}},subscribeCue:c=>()=>()=>{},subscribeComplete:c=>()=>()=>{},destroy:()=>(o=!0,i())}},xr=t=>e=>n=>()=>{const r=AE(t,e),o=mn(r,J,Kt);if(o.tag==="Just")return n(o._1)();o.tag!=="Nothing"&&g()},ZE=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=QE(o=>'<span class="mg-tick" style="left:'+Ho(Oo("Fixed",qo(0)(20)(2)))(100*o.startT/n)+'%" data-label="'+(()=>{if(o.scene.tag==="Structural")return o.scene._1.to;if(o.scene.tag==="DataFlow")return o.scene._1.keyframe;if(o.scene.tag==="Hold")return o.scene._1;if(o.scene.tag==="EnterNode"||o.scene.tag==="ExitNode")return"";if(o.scene.tag==="StepScene")return o.scene._1;g()})()+'"></span>')(e.spans);return xr(t)("ticks")(o=>()=>hs(r,o))},t4=t=>e=>n=>xr(t)("scrub")(r=>{const o=jg(J,Kt,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return n<=0?()=>{}:PE(ie(fe(Hn(e/n*1e3))))(o._1);g()}),n_=t=>e=>n=>{const r=EE(o=>n);return()=>{const o=r();return GE(t)(o)(!1)(e)()}},Rp=()=>om()/1e3,e4=t=>e=>()=>(hs(`
47
+ <svg data-mg="stage" tabindex="0" role="img" aria-label="Markgraf sequence diagram"></svg>
48
+ `,t),xr(t)("stage")(n=>{const r=jE(n)(ME)(e_)(e);return()=>{const o=Zg();t_(()=>{r()})(o)()}})()),n4=t=>e=>{const n=mn(t,J,Kt);if(n.tag==="Just"){const r=mn(n._1.loop,J,Kt);if(r.tag==="Nothing")return e;if(r.tag==="Just")return r._1;g()}if(n.tag==="Nothing")return e;g()},r_=t=>e=>{const n=re(r=>r.startT<=e&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return n._1.scene._1.to;if(n._1.scene.tag==="DataFlow")return n._1.scene._1.keyframe;if(n._1.scene.tag==="Hold")return n._1.scene._1;if(n._1.scene.tag==="EnterNode"||n._1.scene.tag==="ExitNode")return"";if(n._1.scene.tag==="StepScene")return n._1.scene._1;g()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;if(r>=0&&r<t.spans.length){if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;if(t.spans[r].scene.tag==="Hold")return t.spans[r].scene._1;if(t.spans[r].scene.tag==="EnterNode"||t.spans[r].scene.tag==="ExitNode")return"";if(t.spans[r].scene.tag==="StepScene")return t.spans[r].scene._1;g()}return""}g()},r4=t=>e=>xr(t)("speed")(n=>{const r=jg(J,Kt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return n_("change")(n)((()=>{const o=DE(r._1);return()=>{const i=o(),s=F0(i,m_,Kt,J);if(s.tag==="Just")return e(s._1)();s.tag!=="Nothing"&&g()}})());g()}),o4=t=>e=>n=>xr(t)("scrub")(r=>{const o=jg(J,Kt,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return n_("input")(r)((()=>{const i=BE(o._1);return()=>{const s=i();return n.pause(),n.seek(s/1e3*e.totalDuration)()}})());g()}),i4=t=>e=>n=>{const r=ZE(t)(e);return()=>{r(),xr(t)("play")(o=>gn("data-mg-playing")("1")(o))(),r4(t)(n.setSpeed)(),xr(t)("play")(o=>n_("click")(o)(n.toggle))(),o4(t)(e)(n)(),n.subscribe(o=>{const i=t4(t)(o.time)(e.totalDuration);return()=>(i(),xr(t)("time")(s=>LE(Ho(Oo("Fixed",qo(0)(20)(2)))(o.time)+" / "+Ho(Oo("Fixed",qo(0)(20)(2)))(e.totalDuration))(s))(),xr(t)("play")(s=>gn("data-mg-playing")(o.playing?"1":"0")(s))())})()}},s4=t=>e=>n=>{const r=Z1(n);return()=>{const o=r(),i=td(n)(),s=c5(Q2)(Vk)(n)(ed(o)(i)(n));if(s.tag==="Left")return Wt("Left","precompute failed");if(s.tag==="Right")return Wt("Right",{schedule:s._1});g()}},a4=t=>e=>(()=>{const n=mn(t,J,Kt);if(n.tag==="Just")return{...n._1,direction:e<0?"backward":"forward"};if(n.tag==="Nothing")return{direction:e<0?"backward":"forward",speed:ki,duration:ki,loop:ki,stopAt:ki};g()})(),Ap=t=>e=>{const n=mn(t,J,Kt);if(n.tag==="Just"){const r=mn(n._1.direction,J,Kt);if(r.tag==="Just"){if(r._1==="backward"||r._1==="reverse")return-1;if(r._1==="forward")return 1}return e}if(n.tag==="Nothing")return e;g()},u4=t=>e=>{const n=ft(o=>o.time<=e+1e-4,t),r=n.length-1|0;return r>=0&&r<n.length?n[r].index:-1},c4=t=>e=>{if(e.tag==="FixedSize"){const n=e._1<=0||e._2<=0?J:N("Just",e._1/e._2);return()=>n}if(e.tag==="AutoSize"){const n=ja(t);return()=>{const r=n();return r.width<=0||r.height<=0?J:N("Just",r.width/r.height)}}g()},nu=t=>e=>n=>r=>o=>i=>s=>a=>u=>c=>_=>()=>{const d=Rp(),l=c.value;c.value=d;const f=l===0?0:d-l,h=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const C=ja(t)();return{w:C.width<=0?200:C.width,h:C.height<=0?180:C.height}}g()})();if(h.w<200||h.h<180)return RE(t)(h.w)(h.h)(200)(180)();const p=vk({widthPx:h.w,heightPx:h.h})(s),m=Zy(p)(eu(_)(p.totalDuration)),w=i?m:{...m,levels:q(C=>({...C,state:{...C.state,frameTitle:""}}))(m.levels)},x=u.value,y=(()=>{if(x.tag==="Nothing")return w.camera;if(x.tag==="Just")return B2(s.cameraConfig.cameraDecay)(f)(x._1)(w.camera);g()})();u.value=N("Just",y);const T={...w,camera:y,levels:q(Dp(y))(w.levels)};if($E(t)(h)(T)(),e==="CanvasRenderer"){const C=Sp(t),S=yi({padding:8,outputAspect:J})(T),E=(()=>{if(n.tag==="FixedSize")return{w:n._1,h:n._2};if(n.tag==="AutoSize"){const D=ja(t)();return{w:D.width,h:D.height<=0?S.vw<=0?D.width:D.width*S.vh/S.vw:D.height}}g()})(),B=Ep(),M=E.w*B,Y=E.h*B,R=C_(C)(),A=b_(C)(),j=k_(C)(M);R!==M&&j();const Z=S_(C)(Y);A!==Y&&Z(),n.tag==="FixedSize"?(Za(t,"width",ie(fe(Hn(E.w)))+"px"),Za(t,"height",ie(fe(Hn(E.h)))+"px")):n.tag==="AutoSize"||g();const z=T_(C)();nr(z)(),vs(z)({scaleX:B,scaleY:B})();const W=a.value,H=WC(r)(o)(z)({width:E.w,height:E.h})(T)(f)(W)();return a.value=H,rr(z)()}if(e==="SvgRenderer"){const C=a.value,S=c4(t)(n)(),E=vb(S)(r)(o)(T)(f)(C);return a.value=E.springs,gn("viewBox")(E.parts.viewBox)(t)(),gn("preserveAspectRatio")("xMidYMid meet")(t)(),n.tag==="FixedSize"?(gn("width")(ie(fe(Hn(n._1))))(t)(),gn("height")(ie(fe(Hn(n._2))))(t)()):n.tag==="AutoSize"||g(),hs(E.parts.body,t)}g()},g4=t=>{const e=Vh(t)(Qh)._1;if(e.tag==="Left")return Wt("Left",e._1.msg);if(e.tag==="Right")return Wt("Right",e._1);g()},Ip=t=>{const e=DL(t);if(e.tag==="Left")return Wt("Left",e._1);if(e.tag==="Right"){if(e._1.mode==="SequenceSurface"){const r=VE(e._1);if(r.tag==="Left")return Wt("Left",r._1);if(r.tag==="Right")return Wt("Right",Gp("LoadedSequence",r._1));g()}const n=g4(e._1);if(n.tag==="Left")return Wt("Left",n._1);if(n.tag==="Right")return Wt("Right",Gp("LoadedAnimation",n._1))}g()},_4=t=>{const e=Ip(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return ki;g()},Fp=t=>e=>n=>r=>{const o=n+1e-4>=e?ft(s=>s.time>e+1e-4&&s.time<=n+1e-4,t):[...ft(s=>s.time>e+1e-4,t),...ft(s=>s.time<=n+1e-4,t)],i=n<=e+1e-4?se(ft(s=>s.time<e-1e-4&&s.time>=n-1e-4,t)):[...se(ft(s=>s.time<e-1e-4,t)),...se(ft(s=>s.time>=n-1e-4,t))];return(()=>{const s=n-e;return s<0?-s<=1e-4:s<=1e-4})()?[]:r>=0?o:i},f4=t=>e=>n=>r=>re(o=>Ne(i=>i===o.kind,e)&&(o.time>n+1e-4||(()=>{const i=o.time-n;return(i<0?-i<=1e-4:i<=1e-4)&&o.index>r})()))(t),d4=t=>e=>n=>r=>{const o=ft(s=>Ne(a=>a===s.kind,e)&&(s.time<n-1e-4||(()=>{const a=s.time-n;return(a<0?-a<=1e-4:a<=1e-4)&&s.index<r})()),t),i=o.length-1|0;return i>=0&&i<o.length?N("Just",o[i]):J},o_=t=>e=>n=>{const r=mn(e,J,Kt);if(r.tag==="Just"){const o=mn(r._1.speed,J,Kt);if(o.tag==="Just"){const i=Do(1e-4)(o._1<0?-o._1:o._1);return()=>t.value=i}if(o.tag==="Nothing"){const i=mn(r._1.duration,J,Kt);if(i.tag==="Just"&&n.tag==="Just"){const s=n._1/i._1,a=Do(1e-4)(s<0?-s:s);if(i._1>0)return()=>t.value=a}return()=>{}}g()}if(r.tag==="Nothing")return()=>{};g()},l4=t=>e=>n=>r=>{const o=r.time-e,i=o<0?-o<=1e-4:o<=1e-4,s=r.time<e-1e-4||i&&r.index<n,a=s?-1:1,u=r.time>e+1e-4||i&&r.index>n,c=mn(t,J,Kt);if(c.tag==="Just"){const _=mn(c._1.direction,J,Kt);if(_.tag==="Just"){if(_._1==="forward")return i||u?N("Just",1):J;if(_._1==="backward"||_._1==="reverse")return i||s?N("Just",-1):J}return N("Just",a)}if(c.tag==="Nothing")return N("Just",a);g()},h4=t=>e=>n=>r=>o=>i=>s=>()=>{const a={value:1};let u=1,c=!0,_=J,d=-1,l=!0,f=!1,h=0,p=0;const m={value:I},w={value:J},x={value:0};let y=!1,T=()=>{},C=[],S=[],E=[];nu(t)(n)(r)(o)(i)(s)(e)(m)(w)(x)(0)();const B=L=>{const G=L.index;return()=>{d=G;const Q=S;return vi(V=>V(L))(Q)()}},M=L=>()=>{const G=C,Q=l,V={time:L,keyframe:r_(e)(L),playing:Q};return vi(K=>K(V))(G)()},Y=()=>(l=!1,_=J,M(h)()),R=L=>()=>(h=L,nu(t)(n)(r)(o)(i)(s)(e)(m)(w)(x)(L)(),M(L)()),A=L=>{const G=Do(0)(eu(e.totalDuration)(L));return()=>(h=G,d=u4(e.cues)(G),p=0,_=J,w.value=J,nu(t)(n)(r)(o)(i)(s)(e)(m)(w)(x)(G)(),M(G)())},j=(L,G,Q,V,K)=>()=>{l=!1,_=J;const U=h;M(U)();const O={reason:L,direction:G<0?"backward":"forward",targetId:Q,targetStep:V,reached:K,time:U},X=E;return vi(et=>et(O))(X)()},Z=()=>{if(!y&&(f=!1,l)){const L=Rp(),G=p;p=L;const Q=a.value,V=u,K=c,U=_,O=h,X=G===0?O+0*Q*V:O+(L-G)*Q*V;if(U.tag==="Just"){const et=V>=0?U._1.cue.time>=O-1e-4&&U._1.cue.time<=X+1e-4:U._1.cue.time<=O+1e-4&&U._1.cue.time>=X-1e-4,lt=et?U._1.cue.time:Do(0)(eu(e.totalDuration)(X));(V>=0?lt+1e-4<O:lt>O+1e-4)&&(w.value=J),R(lt)(),vi(pt=>B(pt))(Fp(e.cues)(O)(lt)(V))();const bt=j("target",V,U._1.targetId,U._1.targetStep,!0);return et&&bt(),et?void 0:z()}if(U.tag==="Nothing"){const et=V>=0?e.totalDuration:0,lt=!K&&(V>=0?et>=O-1e-4&&et<=X+1e-4:et<=O+1e-4&&et>=X-1e-4),bt=K?WE(X)(e.totalDuration+.8):Do(0)(eu(e.totalDuration)(X));(V>=0?bt+1e-4<O:bt>O+1e-4)&&(w.value=J),R(bt)(),vi(Tt=>B(Tt))(Fp(e.cues)(O)(bt)(V))();const pt=j("boundary",V,"","",!0);return lt&&pt(),lt?void 0:z()}g()}},z=()=>{if(!y&&!f){f=!0;const L=Zg();t_(Z)(L)()}},W=()=>(p=0,l=!0,z()),H=()=>(u=1,c=!0,_=J,W(),M(h)()),D=(L,G)=>()=>{const Q=h;return u=L,c=!1,_=J,o_(a)(G)(N("Just",L>=0?e.totalDuration-Q:Q))(),W()},F=(L,G)=>()=>{const Q=h,V=d,K=l4(G)(Q)(V)(L);if(K.tag==="Nothing")return D(Ap(G)(1),G)();if(K.tag==="Just"){const U=L.time-Q,O=U<0?-U:U;return u=K._1,c=!1,_=N("Just",{cue:L,direction:K._1,targetId:L.id,targetStep:L.name}),o_(a)(G)(N("Just",O))(),O<=1e-4?(A(L.time)(),B(L)(),j("target",K._1,L.id,L.name,!0)()):W()}g()};return T=Lp(t)(()=>{if(!y){const L=h;return nu(t)(n)(r)(o)(i)(s)(e)(m)(w)(x)(L)(),M(L)()}})(),W(),{play:H,playWith:L=>{const G=Ap(L)(1);return()=>(u=G,c=n4(L)(!1),_=J,o_(a)(L)(J)(),W(),M(h)())},pause:Y,toggle:()=>l?Y():H(),seek:L=>A(L),seekCue:L=>{const G=re(Q=>Q.id===L)(e.cues);if(G.tag==="Nothing")return()=>{};if(G.tag==="Just"){const Q=G._1,V=A(Q.time);return()=>(V(),B(Q)())}g()},seekStep:L=>{const G=re(Q=>Q.kind==="step"&&Q.name===L)(e.cues);if(G.tag==="Nothing")return()=>{};if(G.tag==="Just"){const Q=G._1,V=A(Q.time);return()=>(V(),B(Q)())}g()},playToCue:L=>G=>{const Q=re(V=>V.id===L)(e.cues);if(Q.tag==="Nothing")return()=>{};if(Q.tag==="Just")return F(Q._1,G);g()},playToStep:L=>G=>{const Q=re(V=>V.kind==="step"&&V.name===L)(e.cues);if(Q.tag==="Nothing")return()=>{};if(Q.tag==="Just")return F(Q._1,G);g()},playNext:L=>()=>{const G=h,Q=d,V=f4(e.cues)(Bp(L)(["step"]))(G)(Q);if(V.tag==="Nothing")return D(1,L)();if(V.tag==="Just")return F(V._1,L)();g()},playPrevious:L=>()=>{const G=h,Q=d,V=d4(e.cues)(Bp(L)(["step"]))(G)(Q);if(V.tag==="Nothing")return D(-1,L)();if(V.tag==="Just")return F(V._1,a4(L)(-1))();g()},setSpeed:L=>{const G=Do(1e-4)(L<0?-L:L);return()=>a.value=G},currentTime:()=>h,currentKeyframe:()=>{const L=h;return r_(e)(L)},isPlaying:()=>l,duration:e.totalDuration,cues:e.cues,steps:ft(L=>L.kind==="step",e.cues),subscribe:L=>()=>{C=St(C)(L);const G=h,Q=l;L({time:G,keyframe:r_(e)(G),playing:Q})();const V=bi(K=>!tu(K)(L));return()=>{C=V(C)}},subscribeCue:L=>()=>{S=St(S)(L);const G=bi(Q=>!tu(Q)(L));return()=>{S=G(S)}},subscribeComplete:L=>()=>{E=St(E)(L);const G=bi(Q=>!tu(Q)(L));return()=>{E=G(E)}},destroy:()=>(y=!0,T())}},p4=t=>e=>{const n=OE(t);return()=>{const r=n(),o=qE(t)();return hs(HE,t),xr(t)("stage")(i=>{const s=s4()(e_)(e);return()=>{const a=Zg();t_(()=>{const u=s();if(u.tag==="Left")return v_("[markgraf] precompute failed")();if(u.tag==="Right"){const c=h4(i)(u._1.schedule)(zE)(e_)(o)(gb)(r)();return i4(t)(u._1.schedule)(c)()}g()})(a)()}})()}},Qp=t=>e=>{const n=Ip(e);if(n.tag==="Left")return v_("[markgraf] parse failed: "+n._1);if(n.tag==="Right"){if(n._1.tag==="LoadedAnimation")return p4(t)(n._1._1);if(n._1.tag==="LoadedSequence")return e4(t)(n._1._1)}g()},m4=t=>{const e=t.getAttribute("data-markgraf-src-b64");if(e)try{return decodeURIComponent(escape(atob(e)))}catch{return atob(e)}return t.getAttribute("data-markgraf-src")||t.textContent||""};let wr=null;const ru=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",y4=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{ru(t)?(wr&&wr!==t&&ru(wr)&&wr.querySelector('[data-mg="play"]').click(),wr=t):wr===t&&(wr=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},x4=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=m4(t),n=t.dataset.markgrafPaused==="true";t.textContent="",Qp(t)(e)(),t.querySelector('[data-mg="play"]')&&(n?ru(t)&&t.querySelector('[data-mg="play"]').click():wr===null?wr=t:ru(t)&&t.querySelector('[data-mg="play"]').click(),y4(t))},ou=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(x4)},zp=()=>{document.addEventListener("keydown",t=>{if(t.code!=="Space"&&t.key!==" ")return;const e=t.target,n=e&&e.closest?.("[data-markgraf]");if(!n){const o=e?.tagName,i=(e?.type||"").toLowerCase();if(e?.isContentEditable||o==="TEXTAREA"||o==="SELECT"||o==="INPUT"&&!["range","checkbox","radio","button","submit","reset"].includes(i))return}const r=n||wr||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=_4(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>Qp(e)(n)(),mountAll:ou,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{ou(),zp()}):(ou(),zp())}return uu.mountAll=ou,Object.defineProperty(uu,Symbol.toStringTag,{value:"Module"}),uu})({});