@markgrafhq/markgraf-embed 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mark Eibes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @markgrafhq/markgraf-embed
2
+
3
+ Drop-in Canvas2D player for [markgraf](https://github.com/i-am-the-slime/markgraf) animations.
4
+
5
+ Decorate any element with `data-markgraf` containing markgraf source text and
6
+ the script replaces it with an interactive player — scrub bar, keyframe ticks,
7
+ play/pause, speed control, single-active-player coordination across multiple
8
+ embeds on the same page, and Space toggles whichever player is currently
9
+ active.
10
+
11
+ ## From a CDN (no build step)
12
+
13
+ ```html
14
+ <link rel="stylesheet" href="https://unpkg.com/@markgrafhq/markgraf-embed/dist/markgraf-embed.css">
15
+ <script src="https://unpkg.com/@markgrafhq/markgraf-embed/dist/markgraf-embed.js"></script>
16
+
17
+ <div data-markgraf>
18
+ seed 1
19
+ frame v1 {
20
+ +node client "Client"
21
+ +node api "API"
22
+ +edge client api
23
+ client -> api "GET /user/42"
24
+ }
25
+ </div>
26
+ ```
27
+
28
+ ## From a bundler
29
+
30
+ ```js
31
+ import "@markgrafhq/markgraf-embed/dist/markgraf-embed.css";
32
+ import "@markgrafhq/markgraf-embed"; // side-effect: registers window.markgraf, auto-mounts
33
+ ```
34
+
35
+ ## Sizing
36
+
37
+ Set inline CSS on the embed element:
38
+
39
+ ```html
40
+ <!-- Cap canvas height at 320px -->
41
+ <div data-markgraf style="--mg-max-height: 320px">…</div>
42
+
43
+ <!-- Cap the embed width -->
44
+ <div data-markgraf style="max-width: 420px">…</div>
45
+
46
+ <!-- Use most of the viewport for a deep diagram -->
47
+ <div data-markgraf style="--mg-max-height: 80svh">…</div>
48
+ ```
49
+
50
+ ## Programmatic mount
51
+
52
+ The script also exposes `window.markgraf`:
53
+
54
+ ```js
55
+ markgraf.mount(element, "seed 1\nframe v1 { +node a \"A\" }");
56
+ markgraf.mountAll(); // scan the whole document
57
+ markgraf.mountAll(myContainer); // scan a subtree
58
+ ```
59
+
60
+ ## Auto-mount details
61
+
62
+ - Runs on `DOMContentLoaded`, or immediately if the script is loaded after.
63
+ - Each `[data-markgraf]` is mounted exactly once; subsequent calls to
64
+ `mountAll` are idempotent.
65
+ - Source text can come from (in order of preference):
66
+ 1. `data-markgraf-src-b64` attribute (base64-encoded UTF-8)
67
+ 2. `data-markgraf-src` attribute
68
+ 3. the element's `textContent`
69
+
70
+ ## License
71
+
72
+ MIT.
@@ -0,0 +1,281 @@
1
+ .markgraf-embed {
2
+ --mg-bg: #ffffff;
3
+ --mg-fg: #111111;
4
+ --mg-bar-bg: #111111;
5
+ --mg-bar-fg: #ffffff;
6
+ --mg-muted: #9a9a9a;
7
+ --mg-accent: #ffffff;
8
+ --mg-track: #111111;
9
+ --mg-track-hover: #111111;
10
+ position: relative;
11
+ border-radius: 10px;
12
+ background: transparent;
13
+ color: var(--mg-fg);
14
+ font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
15
+ overflow: hidden;
16
+ }
17
+
18
+ .markgraf-embed canvas[data-mg="stage"] {
19
+ width: 100%;
20
+ display: block;
21
+ max-height: var(--mg-max-height, 90svh);
22
+ object-fit: contain;
23
+ }
24
+
25
+ .markgraf-embed :focus,
26
+ .markgraf-embed :focus-visible {
27
+ outline: none;
28
+ }
29
+
30
+ /* Big centered play hint shown while paused. Hidden as soon as a play
31
+ button anywhere in the embed flips to data-mg-playing="1". */
32
+ .markgraf-embed [data-mg="play-overlay"] {
33
+ position: absolute;
34
+ inset: 0;
35
+ margin: auto;
36
+ width: 72px;
37
+ height: 72px;
38
+ border-radius: 50%;
39
+ background: rgba(0, 0, 0, 0.55);
40
+ pointer-events: none;
41
+ opacity: 0;
42
+ transform: scale(0.85);
43
+ transition: opacity 0.12s ease, transform 0.12s ease;
44
+ }
45
+
46
+ .markgraf-embed [data-mg="play-overlay"]::before {
47
+ content: "";
48
+ position: absolute;
49
+ inset: 0;
50
+ margin: auto;
51
+ width: 32px;
52
+ height: 32px;
53
+ background: #fff;
54
+ -webkit-mask: var(--mg-icon-play) center / contain no-repeat;
55
+ mask: var(--mg-icon-play) center / contain no-repeat;
56
+ }
57
+
58
+ .markgraf-embed:has([data-mg="play"][data-mg-playing="0"]) [data-mg="play-overlay"] {
59
+ opacity: 1;
60
+ transform: scale(1);
61
+ }
62
+
63
+ .markgraf-embed [data-mg="bar"] {
64
+ position: absolute;
65
+ left: 0;
66
+ right: 0;
67
+ bottom: 0;
68
+ display: flex;
69
+ align-items: center;
70
+ gap: 8px;
71
+ padding: 6px 8px;
72
+ background: rgba(255, 255, 255, 0.92);
73
+ color: var(--mg-fg);
74
+ opacity: 0;
75
+ transform: translateY(2px);
76
+ transition: opacity 0.08s ease, transform 0.08s ease;
77
+ pointer-events: none;
78
+ }
79
+
80
+ .markgraf-embed:hover [data-mg="bar"],
81
+ .markgraf-embed:focus-within [data-mg="bar"] {
82
+ opacity: 1;
83
+ transform: translateY(0);
84
+ pointer-events: auto;
85
+ transition: opacity 0.16s ease, transform 0.16s ease;
86
+ }
87
+
88
+ .markgraf-embed [data-mg="play"] {
89
+ background: transparent;
90
+ color: var(--mg-fg);
91
+ border: 0;
92
+ border-radius: 999px;
93
+ width: 22px;
94
+ height: 22px;
95
+ padding: 0;
96
+ cursor: pointer;
97
+ display: inline-flex;
98
+ align-items: center;
99
+ justify-content: center;
100
+ transition: background 0.1s ease;
101
+ }
102
+
103
+ .markgraf-embed [data-mg="play"]:hover {
104
+ background: rgba(0, 0, 0, 0.08);
105
+ }
106
+
107
+ /* Heroicons v2 solid play / pause, rendered as a mask so the icon picks up
108
+ currentColor (light-mode black, dark-mode white via the bar override). */
109
+ .markgraf-embed [data-mg="play"]::before {
110
+ content: "";
111
+ display: block;
112
+ width: 14px;
113
+ height: 14px;
114
+ background: currentColor;
115
+ -webkit-mask: var(--mg-icon-play) center / contain no-repeat;
116
+ mask: var(--mg-icon-play) center / contain no-repeat;
117
+ }
118
+
119
+ .markgraf-embed [data-mg="play"][data-mg-playing="1"]::before {
120
+ -webkit-mask: var(--mg-icon-pause) center / contain no-repeat;
121
+ mask: var(--mg-icon-pause) center / contain no-repeat;
122
+ }
123
+
124
+ .markgraf-embed {
125
+ --mg-icon-play: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'><path d='M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653Z'/></svg>");
126
+ --mg-icon-pause: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'><path d='M6.75 5.25a.75.75 0 0 1 .75-.75H9a.75.75 0 0 1 .75.75v13.5a.75.75 0 0 1-.75.75H7.5a.75.75 0 0 1-.75-.75V5.25Zm7.5 0A.75.75 0 0 1 15 4.5h1.5a.75.75 0 0 1 .75.75v13.5a.75.75 0 0 1-.75.75H15a.75.75 0 0 1-.75-.75V5.25Z'/></svg>");
127
+ }
128
+
129
+ .markgraf-embed [data-mg="time"] {
130
+ font-variant-numeric: tabular-nums;
131
+ font-size: 11px;
132
+ color: var(--mg-fg);
133
+ white-space: nowrap;
134
+ }
135
+
136
+ .markgraf-embed [data-mg="speed"] {
137
+ background: transparent;
138
+ border: 1px solid currentColor;
139
+ border-radius: 4px;
140
+ padding: 1px 4px;
141
+ color: var(--mg-fg);
142
+ font: 11px/1 inherit;
143
+ cursor: pointer;
144
+ }
145
+
146
+ .markgraf-embed [data-mg="speed"] option {
147
+ color: var(--mg-fg);
148
+ background: var(--mg-bg);
149
+ }
150
+
151
+ .markgraf-embed [data-mg="scrub-wrap"] {
152
+ position: relative;
153
+ flex: 1;
154
+ display: flex;
155
+ align-items: center;
156
+ }
157
+
158
+ .markgraf-embed [data-mg="ticks"] {
159
+ position: absolute;
160
+ left: 7px;
161
+ right: 7px;
162
+ top: 50%;
163
+ transform: translateY(-50%);
164
+ height: 18px;
165
+ pointer-events: none;
166
+ }
167
+
168
+ .markgraf-embed .mg-tick {
169
+ position: absolute;
170
+ top: 50%;
171
+ width: 4px;
172
+ height: 4px;
173
+ margin-left: -2px;
174
+ margin-top: -2px;
175
+ border-radius: 50%;
176
+ background: #fff;
177
+ opacity: 0.7;
178
+ pointer-events: auto;
179
+ cursor: pointer;
180
+ transition: transform 0.1s ease, opacity 0.1s ease;
181
+ }
182
+
183
+ .markgraf-embed .mg-tick:hover {
184
+ opacity: 1;
185
+ transform: scale(1.6);
186
+ }
187
+
188
+ .markgraf-embed .mg-tick::after {
189
+ content: attr(data-label);
190
+ position: absolute;
191
+ bottom: 100%;
192
+ left: 50%;
193
+ transform: translate(-50%, -4px);
194
+ background: rgba(15, 23, 42, 0.95);
195
+ color: #fff;
196
+ font-size: 11px;
197
+ padding: 2px 6px;
198
+ border-radius: 4px;
199
+ white-space: nowrap;
200
+ opacity: 0;
201
+ pointer-events: none;
202
+ transition: opacity 0.1s ease;
203
+ }
204
+
205
+ .markgraf-embed .mg-tick:hover::after {
206
+ opacity: 1;
207
+ }
208
+
209
+ /* Custom-styled scrubber. Cross-browser range inputs are notoriously ugly,
210
+ so we strip the native chrome and rebuild from CSS primitives. */
211
+ .markgraf-embed [data-mg="scrub"] {
212
+ -webkit-appearance: none;
213
+ appearance: none;
214
+ width: 100%;
215
+ height: 18px;
216
+ background: transparent;
217
+ cursor: pointer;
218
+ margin: 0;
219
+ position: relative;
220
+ z-index: 1;
221
+ }
222
+
223
+ .markgraf-embed [data-mg="scrub"]::-webkit-slider-runnable-track {
224
+ height: 4px;
225
+ background: var(--mg-track);
226
+ border-radius: 999px;
227
+ transition: background 0.15s ease;
228
+ }
229
+
230
+ .markgraf-embed [data-mg="scrub"]:hover::-webkit-slider-runnable-track {
231
+ background: var(--mg-track-hover);
232
+ }
233
+
234
+ .markgraf-embed [data-mg="scrub"]::-moz-range-track {
235
+ height: 4px;
236
+ background: var(--mg-track);
237
+ border-radius: 999px;
238
+ }
239
+
240
+ .markgraf-embed [data-mg="scrub"]::-webkit-slider-thumb {
241
+ -webkit-appearance: none;
242
+ appearance: none;
243
+ width: 14px;
244
+ height: 14px;
245
+ border-radius: 50%;
246
+ background: #111;
247
+ border: 2px solid #fff;
248
+ margin-top: -5px;
249
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
250
+ transition: transform 0.08s ease;
251
+ }
252
+
253
+ .markgraf-embed [data-mg="scrub"]:hover::-webkit-slider-thumb {
254
+ transform: scale(1.15);
255
+ }
256
+
257
+ .markgraf-embed [data-mg="scrub"]::-moz-range-thumb {
258
+ width: 14px;
259
+ height: 14px;
260
+ border-radius: 50%;
261
+ background: #111;
262
+ border: 2px solid #fff;
263
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
264
+ }
265
+
266
+ @media (prefers-color-scheme: dark) {
267
+ .markgraf-embed {
268
+ --mg-bg: #111111;
269
+ --mg-fg: #ffffff;
270
+ --mg-track: #ffffff;
271
+ --mg-track-hover: #ffffff;
272
+ }
273
+ .markgraf-embed [data-mg="bar"] {
274
+ background: rgba(17, 17, 17, 0.92);
275
+ }
276
+ .markgraf-embed [data-mg="scrub"]::-webkit-slider-thumb,
277
+ .markgraf-embed [data-mg="scrub"]::-moz-range-thumb {
278
+ background: #fff;
279
+ border-color: #111;
280
+ }
281
+ }
@@ -0,0 +1,30 @@
1
+ var fm=(function(Eo){"use strict";function oc(e){let t=0,n;return()=>{if(t===2)return n;if(t===1)throw new Error("Binding demanded before initialized");return t=1,n=e(),t=2,n}}function c(){throw new Error("Failed pattern match")}function bn(e,t){return t>0?Math.floor(e/t):t<0?-Math.floor(e/-t):0}const Te=function(e){return e.toString()},fu=function(e){var t=e.toString();return isNaN(t+".0")?t:t+".0"},ic=function(e){var t=e.length;return'"'+e.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<t&&e[o]>="0"&&e[o]<="9"?"\\&":"";return"\\"+n.charCodeAt(0).toString(10)+i})+'"'},ko=e=>e,Re=ko("LT"),Ie=ko("GT"),Ve=ko("EQ"),k=(e,t)=>({tag:e,_1:t}),T=k("Nothing"),Kt=e=>k("Just",e),gu=e=>{if(e.tag==="Nothing")return!0;if(e.tag==="Just")return!1;c()},uc=e=>{if(e.tag==="Nothing")return!1;if(e.tag==="Just")return!0;c()},Lt=(e,t)=>({tag:e,_1:t}),sc=e=>Lt("Right",e),ac={map:e=>t=>{if(t.tag==="Left")return Lt("Left",t._1);if(t.tag==="Right")return Lt("Right",e(t._1));c()}},_u={apply:e=>t=>{if(e.tag==="Left")return Lt("Left",e._1);if(e.tag==="Right"){if(t.tag==="Left")return Lt("Left",t._1);if(t.tag==="Right")return Lt("Right",e._1(t._1))}c()},Functor0:()=>ac},cc={bind:e=>{if(e.tag==="Left"){const t=e._1;return n=>Lt("Left",t)}if(e.tag==="Right"){const t=e._1;return n=>n(t)}c()},Apply0:()=>_u},fc={pure:sc,Apply0:()=>_u},gc={Applicative0:()=>fc,Bind1:()=>cc},he=e=>t=>e,$=function(e){return function(t){for(var n=t.length,r=new Array(n),o=0;o<n;o++)r[o]=e(t[o]);return r}},_c={map:$},du=e=>e,jn=function(e){return function(t){return function(n){for(var r=t,o=n.length,i=o-1;i>=0;i--)r=e(n[i])(r);return r}}},y=function(e){return function(t){return function(n){for(var r=t,o=n.length,i=0;i<o;i++)r=e(r)(n[i]);return r}}},dc=e=>{const t=e.Apply0();return n=>r=>n.foldr(o=>{const i=r(o);return u=>t.apply(t.Functor0().map(s=>du)(i))(u)})(e.pure())},zt={foldr:jn,foldl:y,foldMap:e=>{const t=e.mempty;return n=>zt.foldr(r=>o=>e.Semigroup0().append(n(r))(o))(t)}},lu=isFinite;function lc(e,t,n,r){var o=parseFloat(e);return t(o)?n(o):r}const hu=Math.abs,hc=Math.ceil,bo=Math.cos,pu=Math.exp,mu=Math.floor,Co=function(e){return function(t){return Math.pow(e,t)}},yu=Math.round,So=Math.sin,Cn=Math.sqrt,pc=function(e){return function(t){return function(n){return(n|0)===n?e(n):t}}},_t=function(e){return e},mc=(function(e){return function(t){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 u=parseInt(i,n);return(u|0)===u?e(u):t}else return t}}}})(Kt)(T)(10),Ju=pc(Kt)(T),tr=e=>{if(!lu(e))return 0;if(e>=_t(2147483647))return 2147483647;if(e<=_t(-2147483648))return-2147483648;const t=Ju(e);if(t.tag==="Nothing")return 0;if(t.tag==="Just")return t._1;c()},Ut=function(e){return function(t){return e+t|0}},er=function(e){return function(t){return e+t}},Po=function(e){return function(t){if(t===0)return 0;var n=Math.abs(t);return(e%n+n)%n}},yc=function(e){return function(t){return e+t}},ie=function(e){return function(t){return e.length===0?t:t.length===0?e:e.concat(t)}},Jc={append:yc},Nc={mempty:"",Semigroup0:()=>Jc};function xc(e,t,n){return e==null?t:n(e)}var Go=function(e){return function(t){return e===t}};const vc=Go,Tc=Go,Do=Go,wc=function(e){return function(t){return function(n){if(t.length!==n.length)return!1;for(var r=0;r<t.length;r++)if(!e(t[r])(n[r]))return!1;return!0}}},Ye={eq:Do},Lc={eq:Tc},Wo={eq:vc};var Mo=function(e){return function(t){return function(n){return function(r){return function(o){return r<o?e:r===o?t:n}}}}};const Ec=Mo,kc=Mo,E={compare:Mo(Re)(Ve)(Ie),Eq0:()=>Ye},ht={compare:kc(Re)(Ve)(Ie),Eq0:()=>Lc},it={compare:Ec(Re)(Ve)(Ie),Eq0:()=>Wo};function Ro(e){return function(t){return function(n){return e.apply(n,[t])}}}const bc=Ro(Number.prototype.toPrecision),Cc=Ro(Number.prototype.toFixed),Sc=Ro(Number.prototype.toExponential),Io=(e,t)=>({tag:e,_1:t}),zo=e=>t=>n=>{const r=it.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),i=it.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;c()},Bo=e=>{if(e.tag==="Precision")return bc(e._1);if(e.tag==="Fixed")return Cc(e._1);if(e.tag==="Exponential")return Sc(e._1);c()},Nu=function(e){return function(){console.log(e)}},x=(e,t)=>({tag:"Tuple",_1:e,_2:t}),Sn=e=>t=>x(e,t),Ao=e=>e._2,Dr=e=>e._1;function Pc(){return Date.now()}function Gc(e){return function(){return e.getContext("2d")}}function Dc(e){return function(){return e.width}}function Wc(e){return function(){return e.height}}function Mc(e){return function(t){return function(){e.width=t}}}function Rc(e){return function(t){return function(){e.height=t}}}function Qo(e){return function(t){return function(){e.lineWidth=t}}}function Ic(e){return function(t){return function(){e.fillStyle=t}}}function zc(e){return function(t){return function(){e.strokeStyle=t}}}function qo(e){return function(t){return function(){e.lineCap=t}}}function Ho(e){return function(t){return function(){e.lineJoin=t}}}function Bc(e){return function(t){return function(){e.globalCompositeOperation=t}}}function Ac(e){return function(t){return function(){e.globalAlpha=t}}}function xu(e){return function(){e.beginPath()}}function Vo(e){return function(){e.stroke()}}function Yo(e){return function(){e.fill()}}function Qc(e){return function(){e.clip()}}function qc(e){return function(t){return function(n){return function(){e.lineTo(t,n)}}}}function Hc(e){return function(t){return function(n){return function(){e.moveTo(t,n)}}}}function Vc(e){return function(){e.closePath()}}function Yc(e){return function(t){return function(){e.fillRect(t.x,t.y,t.width,t.height)}}}function Fc(e){return function(t){return function(){e.clearRect(t.x,t.y,t.width,t.height)}}}function Fo(e){return function(t){return function(){e.scale(t.scaleX,t.scaleY)}}}function vu(e){return function(t){return function(){e.translate(t.translateX,t.translateY)}}}function $c(e){return function(t){return function(){e.textAlign=t}}}function Oc(e){return function(t){return function(){e.textBaseline=t}}}function Xc(e){return function(t){return function(){e.font=t}}}function Uc(e){return function(t){return function(n){return function(r){return function(){e.fillText(t,n,r)}}}}}function nr(e){return function(){e.save()}}function rr(e){return function(){e.restore()}}function Kc(e){return function(t){return function(){e.quadraticCurveTo(t.cpx,t.cpy,t.x,t.y)}}}function Zc(e){return function(t){return function(){e.bezierCurveTo(t.cp1x,t.cp1y,t.cp2x,t.cp2y,t.x,t.y)}}}const Tu=e=>e,$o=e=>e,Oo=e=>e,Xo=e=>e,Wr=e=>e,jc=Wr("BaselineTop"),tf=Wr("BaselineMiddle"),ef=Wr("BaselineAlphabetic"),nf=Wr("BaselineBottom"),rf=Xo("AlignLeft"),of=Xo("AlignRight"),uf=Xo("AlignCenter"),Uo=Oo("BevelJoin"),Mr=Oo("RoundJoin"),Ko=Oo("MiterJoin"),Zo=$o("Round"),jo=$o("Square"),ti=$o("Butt"),sf=Tu("SourceOver"),af=Tu("Difference"),cf=e=>t=>Oc(e)((()=>{if(t==="BaselineTop")return"top";if(t==="BaselineHanging")return"hanging";if(t==="BaselineMiddle")return"middle";if(t==="BaselineAlphabetic")return"alphabetic";if(t==="BaselineIdeographic")return"ideographic";if(t==="BaselineBottom")return"bottom";c()})()),ff=e=>t=>$c(e)((()=>{if(t==="AlignLeft")return"left";if(t==="AlignRight")return"right";if(t==="AlignCenter")return"center";if(t==="AlignStart")return"start";if(t==="AlignEnd")return"end";c()})()),Rr=e=>t=>{if(t==="BevelJoin")return Ho(e)("bevel");if(t==="RoundJoin")return Ho(e)("round");if(t==="MiterJoin")return Ho(e)("miter");c()},ei=e=>t=>{if(t==="Round")return qo(e)("round");if(t==="Square")return qo(e)("square");if(t==="Butt")return qo(e)("butt");c()},wu=e=>t=>Bc(e)((()=>{if(t==="SourceOver")return"source-over";if(t==="SourceIn")return"source-in";if(t==="SourceOut")return"source-out";if(t==="SourceAtop")return"source-atop";if(t==="DestinationOver")return"destination-over";if(t==="DestinationIn")return"destination-in";if(t==="DestinationOut")return"destination-out";if(t==="DestinationAtop")return"destination-atop";if(t==="Lighter")return"lighter";if(t==="Copy")return"copy";if(t==="Xor")return"xor";if(t==="Multiply")return"multiply";if(t==="Screen")return"screen";if(t==="Overlay")return"overlay";if(t==="Darken")return"darken";if(t==="Lighten")return"lighten";if(t==="ColorDodge")return"color-dodge";if(t==="ColorBurn")return"color-burn";if(t==="HardLight")return"hard-light";if(t==="SoftLight")return"soft-light";if(t==="Difference")return"difference";if(t==="Exclusion")return"exclusion";if(t==="Hue")return"hue";if(t==="Saturation")return"saturation";if(t==="Color")return"color";if(t==="Luminosity")return"luminosity";c()})()),St=typeof Array.prototype.flatMap=="function"?function(e){return function(t){return e.flatMap(t)}}:function(e){return function(t){for(var n=[],r=e.length,o=0;o<r;o++)for(var i=t(e[o]),u=i.length,s=0;s<u;s++)n.push(i[s]);return n}},gf=e=>e,_f={map:e=>t=>e(t)},Lu={apply:e=>t=>e(t),Functor0:()=>_f},df={bind:e=>t=>t(e),Apply0:()=>Lu},lf={pure:gf,Apply0:()=>Lu},rn={Applicative0:()=>lf,Bind1:()=>df},hf=function(e){return function(){return e}},pf={apply:e=>t=>()=>{const n=e(),r=t();return Eu.pure(n(r))()},Functor0:()=>mf},Eu={pure:hf,Apply0:()=>pf},mf={map:e=>t=>()=>{const n=t();return e(n)}},or=(e,t)=>({tag:e,_1:t}),ku=e=>or("Loop",e),yf={tailRecM:e=>{const t=n=>{let r=n,o=!0,i;for(;o;){const u=r;if(u.tag==="Loop"){r=e(u._1);continue}if(u.tag==="Done"){o=!1,i=u._1;continue}c()}return i};return n=>t(e(n))},Monad0:()=>rn},Jf=(function(e){return function(t){return function(n){return function(){return e(t,n)}}}})(function(e,t){return t.push(e)}),Nf=(e,t)=>({tag:"Iterator",_1:e,_2:t}),xf=e=>t=>n=>()=>{let r=!1;const o=t._2;for(;!r;){const i=o.value,u=t._1(i);if(u.tag==="Just"&&e(u._1)){n.push(u._1),t._2.value;const s=t._2.value;t._2.value=s+1|0;continue}r=!0}},vf=e=>t=>()=>{let n=!1;const r=e._2;for(;!n;){const o=r.value,i=r.value;r.value=i+1|0;const u=e._1(o);if(u.tag==="Just"){t(u._1)();continue}if(u.tag==="Nothing"){n=!0;continue}c()}},Dt=function(e){return function(t){for(var n=t.length,r=Array(n),o=0;o<n;o++)r[o]=e(o)(t[o]);return r}},bu=function(e){return e},Tf=(function(){function e(o){return[o]}function t(o){return function(i){return[o,i]}}function n(o){return function(i){return function(u){return[o,i,u]}}}function r(o){return function(i){return o.concat(i)}}return function(o){return function(i){return function(u){return function(s){return function(a){function f(g,d){switch(d-g){case 0:return u([]);case 1:return i(e)(s(a[g]));case 2:return o(i(t)(s(a[g])))(s(a[g+1]));case 3:return o(o(i(n)(s(a[g])))(s(a[g+1])))(s(a[g+2]));default:var l=g+Math.floor((d-g)/4)*2;return o(i(r)(f(g,l)))(f(l,d))}}return f(0,a.length)}}}}}})(),wf=e=>e,Ir={traverse:e=>{const t=e.Apply0();return Tf(t.apply)(t.Functor0().map)(e.pure)},sequence:e=>Ir.traverse(e)(wf),Functor0:()=>_c,Foldable1:()=>zt},Ht=function(e,t){for(var n=e>t?-1:1,r=new Array(n*(t-e)+1),o=e,i=0;o!==t;)r[i++]=o,o+=n;return r[i]=o,r};var Lf=function(e,t){if(e<1)return[];var n=new Array(e);return n.fill(t)},Ef=function(e,t){for(var n=[],r=0,o=0;o<e;o++)n[r++]=t;return n};const kf=typeof Array.prototype.fill=="function"?Lf:Ef,wt=(function(){function e(o,i){this.head=o,this.tail=i}var t={};function n(o){return function(i){return new e(o,i)}}function r(o){for(var i=[],u=0,s=o;s!==t;)i[u++]=s.head,s=s.tail;return i}return function(o,i){return r(o(n)(t)(i))}})(),Vt=function(e,t,n){return n.length===0?e({}):t(n[0])(n.slice(1))},bf=function(e,t,n,r){for(var o=0;o<r.length;o++){var i=n(r[o]);if(t(i))return i}return e},ir=function(e,t,n,r){for(var o=0,i=r.length;o<i;o++)if(n(r[o]))return e(o);return t},Cf=function(e,t,n,r){for(var o=r.length-1;o>=0;o--)if(n(r[o]))return e(o);return t},Sf=function(e,t,n,r,o){if(n<0||n>o.length)return t;var i=o.slice();return i.splice(n,0,r),e(i)},Cu=function(e,t,n,r){if(n<0||n>=r.length)return t;var o=r.slice();return o.splice(n,1),e(o)},ur=function(e,t,n,r,o){if(n<0||n>=o.length)return t;var i=o.slice();return i[n]=r,e(i)},_e=function(e){return e.slice().reverse()},Ne=function(e){if(e.length<=1e4)return Array.prototype.concat.apply([],e);for(var t=[],n=0,r=e.length;n<r;n++)for(var o=e[n],i=0,u=o.length;i<u;i++)t.push(o[i]);return t},ct=function(e,t){return t.filter(e)},Pf=(function(){function e(t,n,r,o,i,u){var s,a,f,g,d,l,_;for(s=i+(u-i>>1),s-i>1&&e(t,n,o,r,i,s),u-s>1&&e(t,n,o,r,s,u),a=i,f=s,g=i;a<s&&f<u;)d=o[a],l=o[f],_=n(t(d)(l)),_>0?(r[g++]=l,++f):(r[g++]=d,++a);for(;a<s;)r[g++]=o[a++];for(;f<u;)r[g++]=o[f++]}return function(t,n,r){var o;return r.length<2?r:(o=r.slice(0),e(t,n,o,r.slice(0),0,r.length),o)}})(),Wt=function(e,t,n){return n.slice(e,t)},pe=function(e,t,n){for(var r=t.length<n.length?t.length:n.length,o=new Array(r),i=0;i<r;i++)o[i]=e(t[i])(n[i]);return o},on=function(e,t){for(var n=t.length,r=0;r<n;r++)if(e(t[r]))return!0;return!1},Su=function(e,t){for(var n=t.length,r=0;r<n;r++)if(!e(t[r]))return!1;return!0},xt=e=>t=>Pf(e,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;c()},t),Gf=e=>t=>xt(n=>r=>e.compare(t(n))(t(r))),me=e=>t=>(()=>{const n=Jf(t);return()=>{const r=[...e];return n(r)(),r}})()(),Df=e=>{if(e.length===0)return e.length-1|0,T;const t=e.length-1|0;return t>=0&&t<e.length?k("Just",{init:Wt(0,e.length-1|0,e),last:e[t]}):T},Wf=e=>t=>n=>e>=0&&e<n.length?ur(Kt,T,e,t(n[e]),n):T,_n=e=>t=>{const n=(r=>{let o=r,i=!0,u;for(;i;){const s=o;if(s>=0&&s<t.length){if(e(t[s])){o=s+1|0;continue}i=!1,u=k("Just",s);continue}i=!1,u=T}return u})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:t}:{init:Wt(0,n._1,t),rest:Wt(n._1,t.length,t)};if(n.tag==="Nothing")return{init:t,rest:[]};c()},Pn=e=>t=>{const n=xt(r=>o=>e(r._2)(o._2))(Dt(Sn)(t));return 0<n.length?$(Ao)(Gf(it)(Dr)((()=>{const r=[n[0]];for(const o of n){const i=e((()=>{const u=r.length-1|0;if(u>=0&&u<r.length)return r[u]._2;c()})())(o._2);(i==="LT"||i==="GT"||i!=="EQ")&&r.push(o)}return r})())):[]},Mf=e=>t=>{const n=[],r=Nf(o=>o>=0&&o<t.length?k("Just",t[o]):T,{value:0});return vf(r)(o=>()=>{const i=[];i.push(o),xf(e(o))(r)(i)(),n.push(i)})(),n},fe=e=>t=>{const n=ir(Kt,T,e,t);return n.tag==="Just"?k("Just",t[n._1]):T},Rf=e=>t=>ct(e,t),ze=e=>t=>n=>{const r=ir(Kt,T,o=>e.eq(o)(t),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;c()},Pu=e=>t=>St(t)(e),bt=e=>Pu(t=>{const n=e(t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];c()}),It=(e,t,n)=>({tag:e,_1:t,_2:n}),Bt=It("Nil"),qt={foldr:e=>t=>{const n=qt.foldl(o=>i=>e(i)(o))(t),r=(o=>i=>{let u=o,s=i,a=!0,f;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,f=g;continue}if(d.tag==="Cons"){u=It("Cons",d._1,g),s=d._2;continue}c()}return f})(Bt);return o=>n(r(o))},foldl:e=>t=>n=>{let r=t,o=n,i=!0,u;for(;i;){const s=r,a=o;if(a.tag==="Nil"){i=!1,u=s;continue}if(a.tag==="Cons"){r=e(s)(a._1),o=a._2;continue}c()}return u},foldMap:e=>{const t=e.mempty;return n=>qt.foldl(r=>{const o=e.Semigroup0().append(r);return i=>o(n(i))})(t)}},If=function(e){return function(t){return function(n){return function(r){return function(o){return function(i){for(var u=[],s=i;;){var a=o(s);u.push(n(a));var f=r(a);if(e(f))return u;s=t(f)}}}}}}},zf=e=>{if(e.tag==="Just")return e._1;c()},Bf={unfoldr1:If(gu)(zf)(Dr)(Ao)},Af=function(e){return function(t){return function(n){return function(r){return function(o){return function(i){for(var u=[],s=i;;){var a=o(s);if(e(a))return u;var f=t(a);u.push(n(f)),s=r(f)}}}}}}},Qf=e=>{if(e.tag==="Just")return e._1;c()},Pe={unfoldr:Af(gu)(Qf)(Dr)(Ao),Unfoldable10:()=>Bf},$t=(e,t,n,r,o,i,u)=>({tag:e,_1:t,_2:n,_3:r,_4:o,_5:i,_6:u}),Ge=(e,t,n,r)=>({tag:e,_1:t,_2:n,_3:r}),zr=(e,t,n)=>({tag:"Split",_1:e,_2:t,_3:n}),Gu=(e,t,n)=>({tag:"SplitLast",_1:e,_2:t,_3:n}),q=$t("Leaf"),dn=Ge("IterLeaf"),Zt=(e,t,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return $t("Node",1,1,e,t,n,r);if(r.tag==="Node")return $t("Node",1+r._1|0,1+r._2|0,e,t,n,r);c()}if(n.tag==="Node"){if(r.tag==="Leaf")return $t("Node",1+n._1|0,1+n._2|0,e,t,n,r);if(r.tag==="Node")return $t("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,e,t,n,r)}c()},ge=(e,t,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?$t("Node",1,1,e,t,q,q):r.tag==="Node"&&r._1>1?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;c()})()?Zt(r._5._3,r._5._4,Zt(e,t,n,r._5._5),Zt(r._3,r._4,r._5._6,r._6)):Zt(r._3,r._4,Zt(e,t,n,r._5),r._6):Zt(e,t,n,r);if(n.tag==="Node")return r.tag==="Node"?r._1>(n._1+1|0)?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;c()})()?Zt(r._5._3,r._5._4,Zt(e,t,n,r._5._5),Zt(r._3,r._4,r._5._6,r._6)):Zt(r._3,r._4,Zt(e,t,n,r._5),r._6):n._1>(r._1+1|0)?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;c()})()?Zt(n._6._3,n._6._4,Zt(n._3,n._4,n._5,n._6._5),Zt(e,t,n._6._6,r)):Zt(n._3,n._4,n._5,Zt(e,t,n._6,r)):Zt(e,t,n,r):r.tag==="Leaf"&&n._1>1?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;c()})()?Zt(n._6._3,n._6._4,Zt(n._3,n._4,n._5,n._6._5),Zt(e,t,n._6._6,r)):Zt(n._3,n._4,n._5,Zt(e,t,n._6,r)):Zt(e,t,n,r);c()},Gn=(e,t,n)=>{if(n.tag==="Leaf")return zr(T,q,q);if(n.tag==="Node"){const r=e(t)(n._3);if(r==="LT"){const o=Gn(e,t,n._5);return zr(o._1,o._2,ge(n._3,n._4,o._3,n._6))}if(r==="GT"){const o=Gn(e,t,n._6);return zr(o._1,ge(n._3,n._4,n._5,o._2),o._3)}if(r==="EQ")return zr(k("Just",n._4),n._5,n._6)}c()},Du=(e,t,n,r)=>{if(r.tag==="Leaf")return Gu(e,t,n);if(r.tag==="Node"){const o=Du(r._3,r._4,r._5,r._6);return Gu(o._1,o._2,ge(e,t,n,o._3))}c()},Dn=(e,t)=>{if(e.tag==="Leaf")return t;if(e.tag==="Node"){const n=Du(e._3,e._4,e._5,e._6);return ge(n._1,n._2,n._3,t)}c()},Fe=(e,t,n)=>{if(t.tag==="Leaf")return q;if(n.tag==="Leaf")return t;if(n.tag==="Node"){const r=Gn(e,n._3,t);return Dn(Fe(e,r._2,n._5),Fe(e,r._3,n._6))}c()},Br=(e,t,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return q;if(r.tag==="Node"){const o=Gn(e,r._3,n),i=Br(e,t,o._2,r._5),u=Br(e,t,o._3,r._6);if(o._1.tag==="Just")return ge(r._3,t(o._1._1)(r._4),i,u);if(o._1.tag==="Nothing")return Dn(i,u)}c()},ye=(e,t,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const o=Gn(e,r._3,n),i=ye(e,t,o._2,r._5),u=ye(e,t,o._3,r._6);if(o._1.tag==="Just")return ge(r._3,t(o._1._1)(r._4),i,u);if(o._1.tag==="Nothing")return ge(r._3,r._4,i,u)}c()},qf=e=>t=>n=>{const r=o=>{if(o.tag==="Leaf")return q;if(o.tag==="Node"){const i=e.compare(n)(o._3);if(i==="LT")return ge(o._3,o._4,r(o._5),o._6);if(i==="GT")return ge(o._3,o._4,o._5,r(o._6));if(i==="EQ"){const u=t(o._4);if(u.tag==="Nothing")return Dn(o._5,o._6);if(u.tag==="Just")return $t("Node",o._1,o._2,o._3,u._1,o._5,o._6)}}c()};return r},Hf=e=>t=>{const n=r=>{if(r.tag==="Leaf")return q;if(r.tag==="Node"){const o=t(r._3)(r._4);if(o.tag==="Just")return ge(r._3,o._1,n(r._5),n(r._6));if(o.tag==="Nothing")return Dn(n(r._5),n(r._6))}c()};return n},ln=(e=>t=>n=>{let r=n,o=!0,i;for(;o;){const u=r;if(u.tag==="IterLeaf"){o=!1,i=t();continue}if(u.tag==="IterEmit"){o=!1,i=e(u._1,u._2,u._3);continue}if(u.tag==="IterNode"){r=(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Leaf"){d=!1,l=_;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){f=Ge("IterEmit",h._3,h._4,_),g=h._5;continue}f=Ge("IterEmit",h._3,h._4,Ge("IterNode",h._6,_)),g=h._5;continue}c()}return l})(u._2)(u._1);continue}c()}return i})((e,t,n)=>k("Just",x(x(e,t),n)))(e=>T),vt=e=>t=>n=>r=>{const o=i=>{if(i.tag==="Leaf")return $t("Node",1,1,n,r,q,q);if(i.tag==="Node"){const u=e.compare(n)(i._3);if(u==="LT")return ge(i._3,i._4,o(i._5),i._6);if(u==="GT")return ge(i._3,i._4,i._5,o(i._6));if(u==="EQ")return $t("Node",i._1,i._2,n,t(i._4)(r),i._5,i._6)}c()};return o},Z=e=>t=>n=>{const r=o=>{if(o.tag==="Leaf")return $t("Node",1,1,t,n,q,q);if(o.tag==="Node"){const i=e.compare(t)(o._3);if(i==="LT")return ge(o._3,o._4,r(o._5),o._6);if(i==="GT")return ge(o._3,o._4,o._5,r(o._6));if(i==="EQ")return $t("Node",o._1,o._2,t,n,o._5,o._6)}c()};return r},jt=e=>t=>t.foldl(n=>r=>Z(e)(r._1)(r._2)(n))(q),sr=e=>t=>{const n=r=>{if(r.tag==="Leaf")return q;if(r.tag==="Node"){const o=e.compare(t)(r._3);if(o==="LT")return ge(r._3,r._4,n(r._5),r._6);if(o==="GT")return ge(r._3,r._4,r._5,n(r._6));if(o==="EQ")return Dn(r._5,r._6)}c()};return n},Vf=e=>{const t=e.compare;return n=>r=>o=>{const i=Gn(t,r,o),u=n(i._1);if(u.tag==="Nothing")return Dn(i._2,i._3);if(u.tag==="Just")return ge(r,u._1,i._2,i._3);c()}},we={foldr:e=>t=>{const n=qt.foldr(e)(t);return r=>n((()=>{const o=(i,u)=>{if(i.tag==="Leaf")return u;if(i.tag==="Node")return o(i._5,It("Cons",i._3,o(i._6,u)));c()};return o(r,Bt)})())}},Ar=e=>e,Yf=e=>e,Ff=Ar("Linear"),$f=Ar("EaseInOutQuad"),Of=Ar("EaseOutExpo"),Xf=Ar("SpringBouncy"),ar=e=>t=>n=>{const r=Cn(1-t*t),o=e*r;return 1-pu(-t*e*n)*(bo(o*n)+t/r*So(o*n))},Uf=e=>{const t=ht.compare(0)(e),n=(()=>{if(t==="LT")return e;if(t==="EQ"||t==="GT")return 0;c()})(),r=ht.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;c()},ni=e=>t=>(()=>{if(e==="Linear")return Yf;if(e==="EaseInQuad")return n=>n*n;if(e==="EaseOutQuad")return n=>1-(1-n)*(1-n);if(e==="EaseInOutQuad")return n=>n<.5?2*n*n:1-2*(1-n)*(1-n);if(e==="EaseInCubic")return n=>n*n*n;if(e==="EaseOutCubic")return n=>1-(1-n)*(1-n)*(1-n);if(e==="EaseInOutCubic")return n=>n<.5?4*n*n*n:1-(-2*n+2)*(-2*n+2)*(-2*n+2)/2;if(e==="EaseOutExpo")return n=>n>=1?1:1-Co(2)(-10*n);if(e==="Spring")return n=>1-(1+6*n)*pu(-6*n);if(e==="SpringBouncy")return ar(6)(.7);c()})()(Uf(t)),Wu=y(er)(0),Kf=e=>t=>n=>{const r=ht.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),i=ht.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;c()},Mu=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Ru=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Iu=e=>t=>{const n=pe(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,f=s.x-u.x;return Cn(f*f+a*a)})()}),e,Wt(1,e.length,e)),r=Wu($(u=>u.len)(n)),o=Kf(0)(r)(t*r),i=u=>s=>a=>{let f=u,g=s,d=a,l=!0,_;for(;l;){const h=f,p=g,m=d,J=Vt(N=>T,N=>v=>k("Just",{head:N,tail:v}),h);if(J.tag==="Nothing"){const N=e.length-1|0;if(N>=0&&N<e.length){l=!1,_=e[N];continue}l=!1,_=m;continue}if(J.tag==="Just"){if(p<=J._1.head.len){const N=J._1.head.len<=0?0:p/J._1.head.len;l=!1,_={x:J._1.head.a.x+(J._1.head.b.x-J._1.head.a.x)*N,y:J._1.head.a.y+(J._1.head.b.y-J._1.head.a.y)*N};continue}f=J._1.tail,g=p-J._1.head.len,d=m;continue}c()}return _};return 0<e.length?k("Just",i(n)(o)(e[0])):T},ri=e=>Wu(pe(t=>n=>{const r=n.y-t.y,o=n.x-t.x;return Cn(o*o+r*r)},e,Wt(1,e.length,e))),un=e=>{const t=Vt(n=>T,n=>r=>k("Just",{head:n,tail:r}),[...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._4,n(r._6,o)));c()};return St(wt(qt.foldr,n(e.nodes,Bt)))(r=>[{x:r.x,y:r.y},{x:r.x+r.w,y:r.y+r.h}])})(),...Ne((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._4,n(r._6,o)));c()};return wt(qt.foldr,n(e.edges,Bt))})()),...Ne((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._4,n(r._6,o)));c()};return wt(qt.foldr,n(e.chipExtras,Bt))})())]);if(t.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(t.tag==="Just"){const n=y(r=>o=>({minX:Mu(r.minX)(o.x),minY:Mu(r.minY)(o.y),maxX:Ru(r.maxX)(o.x),maxY:Ru(r.maxY)(o.y)}))({minX:t._1.head.x,minY:t._1.head.y,maxX:t._1.head.x,maxY:t._1.head.y})(t._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},cr=function(e){return function(t){if(e>=0&&e<t.length)return t.charAt(e);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},Wn=function(e){return e.join("")},zu=function(e){return e.split("")},oi=function(e){return e},hn=function(e){return e.length},Bu=function(e){return function(t){return t.substr(0,e)}},fr=function(e){return function(t){return t.substring(e)}},Zf=function(e){return function(t){return{before:t.substring(0,e),after:t.substring(e)}}},jf=e=>t=>{const n=Zf(hn(e))(t);return n.before===e?k("Just",n.after):T},tg=e=>t=>n=>{try{var r=BigInt(n);return e(r)}catch{return t}},eg=e=>t=>n=>{try{var r=BigInt(n);return e(r)}catch{return t}},pn=e=>BigInt(e),ng=e=>Number(e),Qr=e=>t=>e+t,qr=e=>t=>e*t,ii=e=>t=>e-t,Au=0n,Hr=1n,Qu=e=>t=>e^t,gr=e=>t=>e&t,ui=e=>t=>e<<t,si=e=>t=>e>>t,rg=e=>t=>e==t,og=e=>t=>e===t?0:e>t?1:-1,ig={eq:rg},qu={compare:e=>t=>{const n=og(e)(t);return n===1?Ie:n===0?Ve:Re},Eq0:()=>ig},ug=tg(Kt)(T),sg=eg(Kt)(T),ag=e=>t=>hu(e._1-t._1)+hu(e._2-t._2),Vr=e=>e,ue=Vr("North"),se=Vr("South"),mn=Vr("East"),yn=Vr("West"),Hu=e=>e,Vu=(e,t)=>({tag:e,_1:t}),Yu=(e,t)=>({tag:e,_1:t}),ai=(e,t)=>({tag:e,_1:t}),cg=ai("First"),fg=Hu("Forward"),gg=Hu("Backward"),_g=jt(E)(zt),dg=e=>jn(t=>n=>({nodes:ye(E.compare,he,t.nodes,n.nodes),edges:ye(E.compare,he,t.edges,n.edges)}))({nodes:q,edges:q})(e.keyframes),lg=e=>t=>({entering:{nodes:Fe(E.compare,t.nodes,e.nodes),edges:Fe(E.compare,t.edges,e.edges)},leaving:{nodes:Fe(E.compare,e.nodes,t.nodes),edges:Fe(E.compare,e.edges,t.edges)},surviving:{nodes:Br(E.compare,he,e.nodes,t.nodes),edges:Br(E.compare,he,e.edges,t.edges)}}),Fu=e=>e,ci=e=>t=>n=>{const r=ht.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),i=ht.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;c()},Jn=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Mn=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Rn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},fi=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},hg=y(e=>t=>Z(E)(t)()(e))(q),pg=y(e=>t=>Z(E)(t)()(e))(q),mg=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),$u=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Ou=jt(E)(zt),yg=Fu("Hold"),Jg=Fu("Gap"),Ng=e=>t=>n=>{const r=n.center.y-t.center.y,o=n.center.x-t.center.x,i=Cn(o*o+r*r),u=n.zoom-t.zoom,s=u<0?-u:u;return ci(e.minTransition)(e.maxTransition)(Jn(e.panSpeed<=0?e.minTransition:i/e.panSpeed)(e.zoomSpeed<=0?e.minTransition:s/e.zoomSpeed))},xg=y(e=>t=>{const n=e.length-1|0;return n>=0&&n<e.length&&e[n]===t?e:me(e)(t)})([]),gi=e=>{const t=Vt(n=>T,n=>r=>k("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(t.tag==="Just"){const n=y(r=>o=>({minX:Mn(r.minX)(o.x),minY:Mn(r.minY)(o.y),maxX:Jn(r.maxX)(o.x),maxY:Jn(r.maxY)(o.y)}))({minX:t._1.head.x,minY:t._1.head.y,maxX:t._1.head.x,maxY:t._1.head.y})(t._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},Xu=e=>{const t=Vt(n=>T,n=>r=>k("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return T;if(t.tag==="Just")return k("Just",gi(e));c()},vg=e=>t=>n=>hg(St(wt(we.foldr,n))(r=>{const o=Rn(r)(e);if(o.tag==="Just")return ct(i=>!fi(i)(t),[o._1.source,o._1.target]);if(o.tag==="Nothing")return[];c()})),Tg=e=>t=>n=>{const r=ni(e.easing)(ci(0)(1)(n.endT<=n.startT?1:(t-n.startT)/(n.endT-n.startT)));return{center:{x:n.fromCam.center.x+(n.toCam.center.x-n.fromCam.center.x)*r,y:n.fromCam.center.y+(n.toCam.center.y-n.fromCam.center.y)*r},zoom:n.fromCam.zoom+(n.toCam.zoom-n.fromCam.zoom)*r}},wg=e=>t=>n=>r=>{const o=(u,s)=>Mn(Ng(e)(u.toCam)(s.toCam))(u.endT-u.startT),i=y(u=>s=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:k("Just",s)};if(u.pending.tag==="Just")return!(s.fromCam.zoom===s.toCam.zoom&&s.fromCam.center.x===s.toCam.center.x&&s.fromCam.center.y===s.toCam.center.y)||(()=>{const a=u.pending._1.toCam.center.x-s.toCam.center.x;return(a<0?-a<8:a<8)&&(()=>{const f=u.pending._1.toCam.center.y-s.toCam.center.y;return(f<0?-f<8:f<8)&&(()=>{const g=u.pending._1.toCam.zoom-s.toCam.zoom;return g<0?-g<.08:g<.08})()})()})()||o(u.pending._1,s)<=0?{acc:me(u.acc)(u.pending._1),pending:k("Just",s)}:{acc:me(me(u.acc)({...u.pending._1,endT:s.startT-o(u.pending._1,s)}))({startT:s.startT-o(u.pending._1,s),endT:s.startT,fromCam:u.pending._1.toCam,toCam:s.toCam}),pending:k("Just",s)};c()})({acc:[],pending:T})(r);if(i.pending.tag==="Nothing")return i.acc;if(i.pending.tag==="Just")return me(i.acc)(i.pending._1);c()},Lg=e=>e.kind.tag==="SendToken"?k("Just",x(e.kind._1.edge,{source:e.kind._1.from,target:e.kind._1.to})):T,Eg=e=>e.tag==="DataFlow"?bt(Lg)(e._1.events):[],kg=e=>t=>pg(bt(n=>fi(n._2.source)(t)||fi(n._2.target)(t)?k("Just",n._1):T)(mg(e))),bg=e=>t=>{const n=r=>{const o=Cf(Kt,T,i=>i.kind==="Hold",r<1?[]:Wt(0,r,t));if(o.tag==="Just")return o._1>=0&&o._1<t.length?k("Just",t[o._1].cam):T;if(o.tag==="Nothing")return T;c()};return Dt(r=>o=>{if(o.kind==="Hold")return{startT:o.startT,endT:o.endT,fromCam:o.cam,toCam:o.cam};if(o.kind==="Gap")return{startT:o.startT,endT:o.endT,fromCam:(()=>{const i=n(r);if(i.tag==="Nothing")return e;if(i.tag==="Just")return i._1;c()})(),toCam:(()=>{const i=n(r),u=(()=>{if(i.tag==="Nothing")return e;if(i.tag==="Just")return i._1;c()})(),s=r+1|0,a=ir(Kt,T,f=>f.kind==="Hold",s<1?t:Wt(s,t.length,t));if(a.tag==="Just"){const f=(r+1|0)+a._1|0;return f>=0&&f<t.length?t[f].cam:u}if(a.tag==="Nothing")return u;c()})()};c()})(t)},Uu={padding:24,easing:Of,minZoom:.5,maxZoom:2.5,panSpeed:700,zoomSpeed:1.5,minTransition:.3,maxTransition:1.4},Cg=e=>t=>n=>{const r=t.w+n*2,o=t.h+n*2,i=un(e);return r<=0||o<=0||i.w<=0||i.h<=0?1:Mn(i.w/r)(i.h/o)},_i=e=>{const t=Vt(n=>T,n=>r=>k("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(t.tag==="Just"){const n=y(r=>o=>({minX:Mn(r.minX)(o.x),minY:Mn(r.minY)(o.y),maxX:Jn(r.maxX)(o.x+o.w),maxY:Jn(r.maxY)(o.y+o.h)}))({minX:t._1.head.x,minY:t._1.head.y,maxX:t._1.head.x+t._1.head.w,maxY:t._1.head.y+t._1.head.h})(t._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},Ku=e=>t=>n=>{if(n.tag==="Leaf")return un(e);const r=kg(t)(n),o=[...bt(i=>{const u=$u(i)(e.nodes);return u.tag==="Just"?k("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):T})(wt(we.foldr,ye(E.compare,he,n,vg(t)(n)(r)))),...bt(i=>{const u=Rn(i)(e.edges);return u.tag==="Just"?k("Just",gi(u._1)):T})(wt(we.foldr,r)),...bt(i=>{const u=Rn(i)(e.chipExtras);if(u.tag==="Just")return Xu(u._1);if(u.tag==="Nothing")return T;c()})(wt(we.foldr,r))];return o.length===0?un(e):_i(o)},Sg=e=>t=>n=>r=>{const o=[...bt(i=>i)([(()=>{const i=Rn(n)(e.edges);return i.tag==="Just"?k("Just",gi(i._1)):T})(),(()=>{const i=Rn(n)(e.chipExtras);if(i.tag==="Just")return Xu(i._1);if(i.tag==="Nothing")return T;c()})()]),...(()=>{const i=Rn(n)(t);if(i.tag==="Just")return bt(u=>{const s=$u(u)(e.nodes);return s.tag==="Just"?k("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):T})([i._1.source,i._1.target]);if(i.tag==="Nothing")return[];c()})()];return o.length===0?Ku(e)(t)(r):_i(o)},Pg=y(e=>t=>{const n=e.length-1|0,r=n>=0&&n<e.length?k("Just",e[n]):T;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&&t.fromCam.zoom===t.toCam.zoom&&t.fromCam.center.x===t.toCam.center.x&&t.fromCam.center.y===t.toCam.center.y&&(()=>{const o=r._1.toCam.center.x-t.toCam.center.x;return(o<0?-o<8:o<8)&&(()=>{const i=r._1.toCam.center.y-t.toCam.center.y;return(i<0?-i<8:i<8)&&(()=>{const u=r._1.toCam.zoom-t.toCam.zoom;return u<0?-u<.08:u<.08})()})()})()?me((()=>{const o=e.length-1|0;return o<1?[]:Wt(0,o,e)})())({...r._1,endT:t.endT}):me(e)(t)})([]),Zu=e=>t=>{const n=un(e),r=n.w/Jn(1e-4)(t.zoom),o=n.h/Jn(1e-4)(t.zoom);return{x:t.center.x-r/2,y:t.center.y-o/2,w:r,h:o}},Gg=e=>ye(E.compare,he,Ou($(t=>x(t.id,{source:t.from.node,target:t.to.node}))(e.graph.edges)),Ou(St(e.scenes)(Eg))),di=e=>t=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:ci(e.minZoom)(e.maxZoom)(Cg(t)(n)(e.padding))}),Dg=e=>t=>n=>r=>{const o=di(e)(t)(un(t)),i=ct(u=>u>=0&&u<=n,xg(xt(ht.compare)([0,n,...St(r)(u=>[u.startT,u.endT])])));return wg(e)(t)(o)(Pg(bg(o)(bt(u=>{const s=(u._1+u._2)/2;if(u._2<=u._1)return T;const a=bt(f=>f.startT<=s&&s<f.endT?k("Just",f.bbox):T)(r);return a.length===0?k("Just",{kind:Jg,startT:u._1,endT:u._2,cam:o}):k("Just",{kind:yg,startT:u._1,endT:u._2,cam:di(e)(t)(_i(a))})})(pe(Sn,i,Wt(1,i.length,i))))))},Wg=e=>t=>n=>r=>{const o=fe(i=>r>=i.startT&&r<i.endT)(n);if(o.tag==="Just")return Tg(e)(r)(o._1);if(o.tag==="Nothing"){const i=n.length-1|0;if(i>=0&&i<n.length&&r>=n[i].endT)return n[i].toCam;const u=di(e)(t)(un(t));return 0<n.length?n[0].fromCam:u}c()};function _r(e){return e.charCodeAt(0)}function ju(e){return String.fromCharCode(e)}const Yr=function(e){return function(t){return function(n){return n.replace(new RegExp(e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),t)}}},li=function(e){return function(t){return t.split(e)}},Mg=function(e){return e.trim()},Rg=function(e){return function(t){return t.join(e)}};var Ig=typeof Array.from=="function",zg=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",Bg=typeof String.prototype.fromCodePoint=="function",Ag=typeof String.prototype.codePointAt=="function";const Qg=function(e){return Ag?function(t){return t.codePointAt(0)}:e},qg=function(e){return Bg?String.fromCodePoint:e},Hg=function(e){return function(t){return zg?function(n){for(var r="",o=n[Symbol.iterator](),i=0;i<t;++i){var u=o.next();if(u.done)return r;r+=u.value}return r}:e(t)}},Vg=function(e){return function(t){return Ig?function(n){return Array.from(n,t)}:e}},Fr=e=>{const t=hn(e);if(t===0)return T;if(t===1)return k("Just",{head:_r(cr(0)(e)),tail:""});const n=_r(cr(1)(e)),r=_r(cr(0)(e));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?k("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:fr(2)(e)}):k("Just",{head:r,tail:fr(1)(e)})},Yg=e=>{const t=Fr(e);return t.tag==="Just"?k("Just",x(t._1.head,t._1.tail)):T},Fg=e=>Pe.unfoldr(Yg)(e),ts=Qg(e=>{const t=_r(cr(0)(e));if(55296<=t&&t<=56319&&hn(e)>1){const n=_r(cr(1)(e));if(56320<=n&&n<=57343)return(((t-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return t}),hi=Vg(Fg)(ts),pi=e=>oi(e>=0&&e<=65535?ju(e):e<0?"\0":"\uFFFF"),$g=qg(e=>e<=65535?pi(e):pi(bn(e-65536|0,1024)+55296|0)+pi(Po(e-65536|0)(1024)+56320|0)),es=e=>t=>{if(e<1)return"";const n=Fr(t);return n.tag==="Just"?$g(n._1.head)+es(e-1|0)(n._1.tail):t},oe=Hg(es),Og=e=>t=>t===""?T:k("Just",ts(t)),$r=(e,t,n)=>({tag:e,_1:t,_2:n}),Xg=()=>({tag:"ExtendFromSource"}),Or=(e,t)=>({tag:e,_1:t}),mi=e=>e,Xr=(e,t)=>({tag:e,_1:t}),yi=Xr("NotYet"),ns=Xr("Consumed"),Ug=mi("FromSource"),rs=mi("FromTarget"),Kg=mi("FromBoth"),os=Or("Hidden"),Zg=Or("Visible"),is=Xg(),us=$r("Retracted"),jg=$r("Extended"),Ji=(e,t)=>({tag:e,_1:t}),In=(e,t,n)=>({tag:e,_1:t,_2:n}),ss=e=>e,Nn=(e,t)=>({tag:e,_1:t}),zn=(e,t,n,r,o,i,u,s,a)=>({tag:e,_1:t,_2:n,_3:r,_4:o,_5:i,_6:u,_7:s,_8:a}),as=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Ur=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},sn=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},dr=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},cs=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},fs=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},Bn=(()=>{const e=Pe.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return k("Just",x(t._1,t._2));c()});return t=>e((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._3,n(r._6,o)));c()};return n(t,Bt)})())})(),t_=y(e=>t=>Z(E)(t)()(e))(q),Ni=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},e_=jt(E)(zt),n_=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},xi=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},r_=Nn("NoKeyframes"),o_=e=>Nn("DuplicateEventId",e),i_=e=>Nn("UnknownEvent",e),gs=ss("PlopIn"),u_=ss("PlopOut"),s_=e=>t=>bt(n=>{if(n.target.tag==="NodeWindow"||n.target.tag==="EdgeWindow")return T;if(n.target.tag==="TokenWindow")return k("Just",{startT:n.startT,endT:n.endT,bbox:Sg(e)(t)(n.target._2)(q)});if(n.target.tag==="FillWindow")return k("Just",{startT:n.startT,endT:n.endT,bbox:Ku(e)(t)($t("Node",1,1,n.target._2,void 0,q,q))});c()}),a_=e=>t=>n=>r=>o=>{const i=_t(y(f=>g=>f+hi(g).length|0)(0)(n.labels))*e.tokenReadSecPerChar,u=f=>{const g=as(f)(t.nodes);if(g.tag==="Just")return{x:g._1.x+g._1.w/2,y:g._1.y+g._1.h/2};if(g.tag==="Nothing")return{x:0,y:0};c()},s=Ur(n.edge)(t.edges),a=(()=>{if(s.tag==="Just"){const f=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return _e(s._1);c()})(),g=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return _e(s._1);c()})(),d=u(n.from),l=g.length-1|0;return(2*(()=>{const _=0<f.length?f[0]:u(n.from),h=_.x-d.x,p=_.y-d.y;return(h<0?-h:h)+(p<0?-p:p)})()+ri(s._1)+2*(()=>{const _=l>=0&&l<g.length?g[l]:u(n.to),h=u(n.to),p=h.x-_.x,m=h.y-_.y;return(p<0?-p:p)+(m<0?-m:m)})())/e.tokenSpeed}if(s.tag==="Nothing")return 0/e.tokenSpeed;c()})();return e.tokenSpeed<=0?e.minTokenDuration:sn(e.minTokenDuration)(sn(a)(i)/sn(.05)(1-r-o))},c_=e=>{if(e.event.kind.tag==="SendToken")return k("Just",{startT:e.startT,endT:e.endT,target:zn("TokenWindow",e.event.id,e.event.kind._1.edge,e.event.kind._1.direction,e.event.kind._1.from,e.event.kind._1.to,e.event.kind._1.labels,e.holdPre,e.holdPost)});if(e.event.kind.tag==="FillNodeWithoutTransition")return k("Just",{startT:e.startT,endT:e.endT,target:zn("FillWindow",e.event.id,e.event.kind._1.node,e.event.kind._1.labels)});c()},f_=e=>t=>n=>bt(r=>{const o=bt(i=>as(i)(e.nodes))(wt(we.foldr,(()=>{if(r.scene.tag==="Structural")return ye(E.compare,he,(()=>{const i=dr(r.scene._1.from)(n);if(i.tag==="Nothing")return q;if(i.tag==="Just")return i._1.nodes;c()})(),(()=>{const i=dr(r.scene._1.to)(n);if(i.tag==="Nothing")return q;if(i.tag==="Just")return i._1.nodes;c()})());if(r.scene.tag==="DataFlow"){const i=dr(r.scene._1.keyframe)(n);if(i.tag==="Nothing")return q;if(i.tag==="Just")return i._1.nodes}c()})()));return o.length===0?T:k("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const i=y(u=>s=>({minX:cs(u.minX)(s.x),minY:cs(u.minY)(s.y),maxX:sn(u.maxX)(s.x+s.w),maxY:sn(u.maxY)(s.y+s.h)}))(0<o.length?{minX:o[0].x,minY:o[0].y,maxX:o[0].x+o[0].w,maxY:o[0].y+o[0].h}:{minX:0,minY:0,maxX:0,maxY:0})(Wt(1,o.length,o));return{x:i.minX,y:i.minY,w:i.maxX-i.minX,h:i.maxY-i.minY}})()})}),g_=e=>t=>n=>{const r=Ur(n)(e);if(r.tag==="Nothing")return rs;if(r.tag==="Just"){const o=fs(r._1.target)(t);return fs(r._1.source)(t)?o?Kg:Ug:rs}c()},__=e=>t=>n=>r=>{const o=(()=>{if(r.event.when.tag==="First")return 0;if(r.event.when.tag==="At")return r.event.when._1;if(r.event.when.tag==="After"){const i=r.event.when._1,u=fe(s=>s.event.id===i)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.endT;c()}if(r.event.when.tag==="With"){const i=r.event.when._1,u=fe(s=>s.event.id===i)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.startT}c()})();return me(n)({startT:o,endT:(()=>{if(r.event.kind.tag==="SendToken")return o+a_(e)(t)(r.event.kind._1)(r.holdPre)(r.holdPost);if(r.event.kind.tag==="FillNodeWithoutTransition")return o+e.plop;c()})(),event:r.event,holdPre:r.holdPre,holdPost:r.holdPost})},vi=e=>t=>{if(t<0)return In("AtKeyframe",e.initialKeyframe);if(t>=e.totalDuration){const r=e.spans.length-1|0;return r>=0&&r<e.spans.length?In("AtKeyframe",(()=>{if(e.spans[r].scene.tag==="Structural")return e.spans[r].scene._1.to;if(e.spans[r].scene.tag==="DataFlow")return e.spans[r].scene._1.keyframe;c()})()):In("AtKeyframe",e.initialKeyframe)}const n=fe(r=>t>=r.startT&&t<r.endT)(e.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return In("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return In("AtKeyframe",n._1.scene._1.keyframe);c()}if(n.tag==="Nothing")return In("AtKeyframe",e.initialKeyframe);c()},d_=e=>{if(e.when.tag==="First")return[];if(e.when.tag==="At")return[];if(e.when.tag==="After")return[e.when._1];if(e.when.tag==="With")return[e.when._1];c()},_s={id:"",nodes:q,edges:q},l_=e=>t=>lg((()=>{const n=dr(t.from)(e);if(n.tag==="Nothing")return _s;if(n.tag==="Just")return n._1;c()})())((()=>{const n=dr(t.to)(e);if(n.tag==="Nothing")return _s;if(n.tag==="Just")return n._1;c()})()),Ti=e=>t=>n=>r=>{const o=Ur(r)(n.edges);if(o.tag==="Just")return e<=0?t:sn(t)(ri(o._1)/e);if(o.tag==="Nothing")return t;c()},ds=e=>t=>n=>r=>o=>{const i=e.plop,u=l_(n)(o),s=$(_=>({startT:0,endT:0+Ti(e.edgeSpeed)(e.minEdgeDuration)(t)(_),target:zn("EdgeWindow",_,Ji("Extend",is))}))(Bn(u.entering.edges)),a=$(_=>({startT:0,endT:i,target:zn("NodeWindow",_,gs)}))(Bn(u.entering.nodes)),f=y(sn)(0)($(_=>Ti(e.edgeSpeed)(e.minEdgeDuration)(t)(_))(Bn(u.leaving.edges))),g=_=>on(h=>{const p=Ur(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;c()},Bn(u.leaving.edges))?f:0,d=$(_=>({startT:g(_),endT:g(_)+e.plop,target:zn("NodeWindow",_,u_)}))(Bn(u.leaving.nodes)),l=$(_=>({startT:0,endT:Ti(e.edgeSpeed)(e.minEdgeDuration)(t)(_),target:zn("EdgeWindow",_,Ji("Retract",g_(r)(u.leaving.nodes)(_)))}))(Bn(u.leaving.edges));return{duration:(()=>{const _=xt(ht.compare)([...$(p=>p.endT)(l),...$(p=>p.endT)(d),...$(p=>p.endT)(a),...$(p=>p.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+e.gap:e.gap})(),windows:[...l,...d,...a,...s]}},h_=e=>t=>n=>r=>o=>i=>$((()=>{const u=o.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())(ds(e)(t)(n)(r)(i).windows),p_=e=>bt(t=>wt(jn,t).length>1?k("Just",(()=>{const n=Vt(r=>T,r=>o=>k("Just",{head:r,tail:o}),wt(jn,t));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";c()})()):T)(Mf(Do)(xt(E.compare)(e))),m_=e=>{const t=$(r=>r.id)(e),n=t_(t);return[...$(o_)(p_(t)),...$(i_)(ct(r=>!Ni(r)(n),St(e)(d_)))]},y_=e=>{const t=e_($(r=>x(r.id,(()=>{if(r.when.tag==="First")return[];if(r.when.tag==="At")return[];if(r.when.tag==="After")return[r.when._1];if(r.when.tag==="With")return[r.when._1];c()})()))(e)),n=r=>o=>i=>{if(Ni(i)(o))return[Nn("ScheduleCycle",[...wt(we.foldr,o),i])];if(Ni(i)(r))return[];const u=n_(i)(t);if(u.tag==="Nothing")return[];if(u.tag==="Just")return St(u._1)(n(Z(E)(i)()(r))(Z(E)(i)()(o)));c()};return St(e)(r=>n(q)(q)(r.id))},J_={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:100,minTokenDuration:1.4,tokenReadSecPerChar:.06,nodeEasing:Xf,edgeEasing:$f,tokenEasing:Ff},N_=e=>t=>{if(t.tag==="Structural")return bt(n=>n)([xi(t._1.from)(e)?T:k("Just",Nn("UnknownKeyframe",t._1.from)),xi(t._1.to)(e)?T:k("Just",Nn("UnknownKeyframe",t._1.to))]);if(t.tag==="DataFlow")return[...bt(n=>n)([xi(t._1.keyframe)(e)?T:k("Just",Nn("UnknownKeyframe",t._1.keyframe))]),...m_(t._1.events),...y_(t._1.events)];c()},x_=e=>t=>{const n=St(t)(N_(e));return n.length===0?Lt("Right",void 0):Lt("Left",n)},ls=e=>t=>n=>y(__(e)(t))([])(Dt(r=>o=>({event:o,holdPre:o.kind.tag==="SendToken"?(()=>{const i=r-1|0;return i>=0&&i<n.length&&n[i].kind.tag==="SendToken"&&n[i].kind._1.to===o.kind._1.from})()?0:.18:0,holdPost:o.kind.tag==="SendToken"?(()=>{const i=r+1|0;return i>=0&&i<n.length&&n[i].kind.tag==="SendToken"&&n[i].kind._1.from===o.kind._1.to})()?0:.18:0}))(n)),v_=e=>t=>n=>{const r=ls(e)(t)(n.events);return r.length===0?e.gap:y(sn)(0)($(o=>o.endT)(r))+e.gap},T_=e=>t=>n=>r=>o=>{if(o.tag==="Structural")return ds(e)(t)(n)(r)(o._1).duration;if(o.tag==="DataFlow")return v_(e)(t)(o._1);c()},w_=e=>t=>n=>r=>o=>y(i=>u=>{const s=T_(e)(t)(n)(r)(u);return{acc:me(i.acc)({startT:i.t,endT:i.t+s,scene:u}),t:i.t+s}})({acc:[],t:0})(o).acc,L_=e=>t=>n=>r=>$((()=>{const o=n.startT;return i=>({...i,startT:i.startT+o,endT:i.endT+o})})())(bt(c_)(ls(e)(t)(r.events))),E_=e=>t=>n=>r=>o=>{if(o.scene.tag==="Structural")return h_(e)(t)(n)(r)(o)(o.scene._1);if(o.scene.tag==="DataFlow")return L_(e)(t)(o)(o.scene._1);c()},k_=e=>t=>n=>{const r=0<t.keyframes.length?k("Just",t.keyframes[0]):T;if(r.tag==="Nothing")return Lt("Left",[r_]);if(r.tag==="Just"){const o=r._1,i=_g($(a=>x(a.id,a))(t.keyframes)),u=Gg(t),s=x_(i)(t.scenes);return(()=>{if(s.tag==="Left"){const a=s._1;return f=>Lt("Left",a)}if(s.tag==="Right"){const a=s._1;return f=>f(a)}c()})()(()=>{const a=w_(e)(n)(i)(u)(t.scenes),f=a.length-1|0,g=f>=0&&f<a.length?a[f].endT:0,d=xt(l=>_=>ht.compare(l.startT)(_.startT))(St(a)(E_(e)(n)(i)(u)));return Lt("Right",{totalDuration:g,windows:d,spans:a,keyframes:i,initialKeyframe:o.id,timing:e,layout:n,cameraSpans:Dg(Uu)(n)(g)([...f_(n)(u)(i)(a),...s_(n)(u)(d)]),cameraConfig:Uu})})}c()},lr=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},hs=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Kr=e=>t=>n=>{const r=ht.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),i=ht.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;c()},b_=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},C_=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},S_=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},P_=jt(E)(zt),G_=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},D_=jt(E)(zt),W_=jt(E)(zt),M_=e=>t=>n=>r=>{const o=un(e),i=o.w/lr(1e-4)(t.zoom)/2,u=o.h/lr(1e-4)(t.zoom)/2,s=n.y-t.center.y,a=n.x-t.center.x;return{...t,center:{x:i<=1e-4?t.center.x+0*r*.35:a<0?t.center.x+a/(1+-a/i)*r*.35:t.center.x+a/(1+a/i)*r*.35,y:u<=1e-4?t.center.y+0*r*.35:s<0?t.center.y+s/(1+-s/u)*r*.35:t.center.y+s/(1+s/u)*r*.35}}},wi=e=>t=>{const n=hs(t)(e.keyframes);if(n.tag==="Nothing")return q;if(n.tag==="Just")return n._1.nodes;c()},Li=e=>t=>{const n=hs(t)(e.keyframes);if(n.tag==="Nothing")return q;if(n.tag==="Just")return n._1.edges;c()},R_=e=>t=>n=>on(r=>r.endT<=t&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,e),I_=e=>t=>n=>on(r=>r.endT<=t&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,e),z_=e=>t=>n=>on(r=>r.startT>t&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,e),B_=e=>t=>n=>on(r=>r.startT>t&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,e),A_=e=>t=>{const n=vi(e)(t);if(n.tag==="AtKeyframe")return oe(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return oe(3)(n._2)==="kf-"?"":n._2;c()},ps=e=>t=>n=>fe(r=>n(r)&&t>=r.startT&&t<r.endT)(e),Q_=e=>{const t=Kr(0)(1)(e/.2),n=Kr(0)(1)((1-e)/.2);return t*t*(3-2*t)*n*n*(3-2*n)},q_=e=>t=>{if(t.tag==="Travelling"){const n=b_(t._1.edge)(e.edges);if(n.tag==="Just"){const r=Iu(n._1)(t._1.progress);return r.tag==="Just"?k("Just",{dot:r._1,weight:Q_(t._1.progress)}):T}if(n.tag==="Nothing")return T;c()}return T},H_=e=>t=>{const n=vi(e)(t);if(n.tag==="AtKeyframe")return wi(e)(n._1);if(n.tag==="InTransition")return ye(E.compare,he,wi(e)(n._1),wi(e)(n._2));c()},V_=e=>t=>{const n=vi(e)(t);if(n.tag==="AtKeyframe")return Li(e)(n._1);if(n.tag==="InTransition")return ye(E.compare,he,Li(e)(n._1),Li(e)(n._2));c()},Y_=e=>t=>{const n=un(e),r=n.h/lr(1e-4)(t.zoom),o=n.w/lr(1e-4)(t.zoom);return{...t,center:{x:o>=n.w?n.x+n.w/2:Kr(n.x+o/2)(n.x+n.w-o/2)(t.center.x),y:r>=n.h?n.y+n.h/2:Kr(n.y+r/2)(n.y+n.h-r/2)(t.center.y)}}},Zr=e=>t=>{const n=e.endT-e.startT;return n<=0?1:lr(0)(C_(1)((t-e.startT)/n))},F_=e=>t=>n=>r=>{const o=ps(e.windows)(t)(i=>i.target.tag==="EdgeWindow"&&i.target._1===r);if(o.tag==="Just"){const i=ni(e.timing.edgeEasing)(Zr(o._1)(t)),u=o._1.target.tag==="EdgeWindow"?o._1.target._2:Ji("Extend",is);if(u.tag==="Retract")return $r("Retracting",u._1,i);if(u.tag==="Extend")return $r("Extending",u._1,i);c()}if(o.tag==="Nothing")return B_(e.windows)(t)(r)||R_(e.windows)(t)(r)?us:S_(r)(n)?jg:us;c()},$_=e=>t=>{const n=V_(e)(t);return P_($(r=>x(r,F_(e)(t)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return q;if(o.tag==="Node")return $t("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));c()};return wt(we.foldr,r(e.layout.edges))})()))},O_=e=>t=>n=>r=>{const o=ps(e.windows)(t)(i=>i.target.tag==="NodeWindow"&&i.target._1===r);if(o.tag==="Just"){const i=Zr(o._1)(t),u=o._1.target.tag==="NodeWindow"?o._1.target._2:gs;if(u==="PlopIn")return Or("PloppingIn",i);if(u==="PlopOut")return Or("PloppingOut",i);c()}if(o.tag==="Nothing")return z_(e.windows)(t)(r)||I_(e.windows)(t)(r)?os:G_(r)(n)?Zg:os;c()},X_=e=>t=>{const n=H_(e)(t);return D_($(r=>x(r,O_(e)(t)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return q;if(o.tag==="Node")return $t("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));c()};return wt(we.foldr,r(e.layout.nodes))})()))},U_=e=>t=>n=>t.target.tag==="TokenWindow"?x(t.target._1,n<t.startT?yi:n>=t.endT?ns:Xr("Travelling",{edge:t.target._2,direction:t.target._3,progress:ni(e.timing.tokenEasing)(Zr(t)(n)),labels:t.target._6,source:t.target._4,target:t.target._5,holdPre:t.target._7,holdPost:t.target._8})):t.target.tag==="FillWindow"?x(t.target._1,n<t.startT?yi:n>=t.endT?ns:Xr("Filling",{node:t.target._2,progress:Zr(t)(n),labels:t.target._3})):x("",yi),K_=e=>t=>W_($(n=>U_(e)(n)(t))(ct(n=>n.target.tag==="TokenWindow"||n.target.tag==="FillWindow",e.windows))),Z_=e=>t=>{const n=bt(q_(e))((()=>{const r=(o,i)=>{if(o.tag==="Leaf")return i;if(o.tag==="Node")return r(o._5,It("Cons",o._4,r(o._6,i)));c()};return wt(qt.foldr,r(t.tokens,Bt))})());return 0<n.length?k("Just",n[0]):T},j_=e=>t=>{const n=Z_(e)(t);if(n.tag==="Nothing")return t.camera;if(n.tag==="Just")return M_(e)(t.camera)(n._1.dot)(n._1.weight);c()},t1=e=>t=>{const n={nodes:X_(e)(t),edges:$_(e)(t),tokens:K_(e)(t),camera:Wg(e.cameraConfig)(e.layout)(e.cameraSpans)(t),frameTitle:A_(e)(t)};return{...n,camera:Y_(e.layout)(j_(e.layout)(n))}};let Ei=null;function e1(){return Ei||(typeof document>"u"?null:(Ei=document.createElement("canvas").getContext("2d"),Ei))}const ms=new Map,n1=e=>t=>n=>r=>()=>{const o=`${n} ${t}px ${e}|${r}`,i=ms.get(o);if(i!==void 0)return i;const u=e1();if(!u)return r.length*t*.62;u.font=`${n} ${t}px ${e}`;const s=u.measureText(r).width;return ms.set(o,s),s},ys=(()=>{const e=Yr(`\r
3
+ `)(" "),t=Yr(`
4
+ `)(" "),n=(()=>{const r=Yr("\r")(" "),o=(()=>{const i=Yr(" ")(" ");return u=>i(r(u))})();return i=>o(t(i))})();return r=>n(e(r))})(),hr=e=>t=>{const n=it.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},r1=e=>t=>{const n=it.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},o1=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},i1=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Js=e=>Wn(_e(_n(t=>t===" ")(_e(_n(t=>t===" ")(zu(e)).rest)).rest)),u1=e=>y(t=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?k("Just",n._1):t)(T)(Dt(Sn)(e)),ki=e=>t=>{if(e<=0)return[t];if(hn(t)<=e)return[t];const n=zu(t),r=e<1?[]:Wt(0,e,n),o=u1(r);if(o.tag==="Just"){const i=Js(Bu(!(o._1>=0&&o._1<r.length)||r[o._1]===" "?o._1:o._1+1|0)(t)),u=Js(fr(o._1+1|0)(t));return u===""?[i]:[i,...ki(e)(u)]}if(o.tag==="Nothing"){const i=Bu(e)(t),u=fr(e)(t);return u===""?[i]:[i,...ki(e)(u)]}c()},s1={cellW:7,cellH:3,maxLineWidth:20},a1=e=>t=>{const n=$(i=>x((()=>{if(i.label.tag==="Just")return i.label._1;if(i.label.tag==="Nothing")return i.id;c()})(),i))(t.nodes),r=hr(1)(bn((r1(e.maxLineWidth)(y(i=>u=>hr(i)(hn(u._1)))(0)(n))+2|0)+e.cellW|0,e.cellW)),o=(r*e.cellW|0)-1|0;return{...t,nodes:$(i=>{if(!(i._2.size._1===1&&i._2.size._2===1))return i._2;const u=St(li(`
5
+ `)(i._1))(ki(o)),s=y(a=>f=>hr(a)(hn(f)))(0)(u);return{...i._2,size:x(_t(s>o?bn((s+2|0)+e.cellW|0,e.cellW):r),_t(hr(1)(bn(u.length+e.cellH|0,e.cellH))))}})(n)}},c1=e=>t=>n=>({...n,nodes:$(r=>{const o=i1(r.id)(t);if(o.tag==="Nothing")return r;if(o.tag==="Just")return{...r,size:x(o1(r.size._1)(_t(hr(1)(tr(hc((o._1+32)/e))))),r.size._2)};c()})(n.nodes)}),f1=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},g1=e=>{const t=e.length;return(n=>r=>{let o=n,i=r,u=!0,s;for(;u;){const a=o,f=i;if(a>=t){u=!1,s=f;continue}const g=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const J=_,N=h;if(J>=t){p=!1,m=N;continue}if(a>=0&&a<e.length){if(J>=0&&J<e.length){_=J+1|0,h=(()=>{const v=e[a].position,w=e[a].size,b=e[J].position,L=e[J].size;return v._1<b._1+L._1&&b._1<v._1+w._1&&v._2<b._2+L._2&&b._2<v._2+w._2})()?N+1|0:N;continue}_=J+1|0,h=N;continue}p=!1,m=N}return m};o=a+1|0,i=g(a+1|0)(f)}return s})(0)(0)},Ns=e=>y(t=>n=>t+ag(n.start)(n.end))(0)(e.segments),_1=e=>t=>n=>({crossingCount:y(r=>o=>r+o.jumps.length|0)(0)(t),bendCount:y(r=>o=>r+o.bends.length|0)(0)(t),totalEdgeLength:y(r=>o=>r+Ns(o))(0)(t),maxEdgeLength:y(r=>o=>f1(r)(Ns(o)))(0)(t),nodeOverlapCount:g1(e),constraintViolations:n,jumpCount:y(r=>o=>r+o.jumps.length|0)(0)(t)}),xs=e=>e,An=jt(it)(zt),Nt=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=it.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},vs=e=>t=>{const n=it.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},ot=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},ut=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},$e=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},d1=e=>t=>{const n=it.compare(e._1)(t._1);return n==="LT"?Re:n==="GT"?Ie:it.compare(e._2)(t._2)},Qn=e=>t=>{const n=it.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},l1=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),h1=e=>e,jr=xs("Regular"),to=xs("Critical"),Ts=e=>t=>{const n=y(u=>s=>Z(E)(s.node)(s)(u))(q)(t),r=1.25*_t(4),o=(u,s,a)=>(f=>g=>d=>{let l=f,_=g,h=d,p=!0,m;for(;p;){const J=l,N=_,v=h;if(v.critical){p=!1,m=v;continue}const w=Vt(L=>T,L=>S=>k("Just",{head:L,tail:S}),J),b=Vt(L=>T,L=>S=>k("Just",{head:L,tail:S}),N);if(w.tag==="Just"&&b.tag==="Just"){const L=w._1.head>b._1.head-u&&w._1.head<b._1.head+u?{...v,critical:!0}:w._1.head>b._1.head-r&&w._1.head<b._1.head+r?{...v,conflicts:v.conflicts+1|0}:v;if(L.critical){p=!1,m=L;continue}if(w._1.head<=b._1.head){l=w._1.tail,_=N,h=L;continue}l=J,_=b._1.tail,h=L;continue}p=!1,m=v}return m})(s)(a)({conflicts:0,critical:!1}),i=(u,s,a)=>{if(ut(y(ut)(-1e18)(s.incoming))(y(ut)(-1e18)(s.outgoing))-ot(y(ot)(1e18)(s.incoming))(y(ot)(1e18)(s.outgoing))<.001||ut(y(ut)(-1e18)(a.incoming))(y(ut)(-1e18)(a.outgoing))-ot(y(ot)(1e18)(a.incoming))(y(ot)(1e18)(a.outgoing))<.001)return[];const f=o(u,s.outgoing,a.incoming),g=o(u,a.outgoing,s.incoming);if(f.critical||g.critical)return[...f.critical?[{src:a.id,tgt:s.id,weight:1,kind:to}]:[],...g.critical?[{src:s.id,tgt:a.id,weight:1,kind:to}]:[]];const d=ot(y(ot)(1e18)(s.incoming))(y(ot)(1e18)(s.outgoing)),l=ut(y(ut)(-1e18)(s.incoming))(y(ut)(-1e18)(s.outgoing)),_=ot(y(ot)(1e18)(a.incoming))(y(ot)(1e18)(a.outgoing)),h=ut(y(ut)(-1e18)(a.incoming))(y(ut)(-1e18)(a.outgoing)),p=(1*f.conflicts|0)+(16*(y(J=>N=>N>h?J:N>=_?J+1|0:J)(0)(s.outgoing)+y(J=>N=>N>l?J:N>=d?J+1|0:J)(0)(a.incoming)|0)|0)|0,m=(1*g.conflicts|0)+(16*(y(J=>N=>N>l?J:N>=d?J+1|0:J)(0)(a.outgoing)+y(J=>N=>N>h?J:N>=_?J+1|0:J)(0)(s.incoming)|0)|0)|0;return p<m?[{src:s.id,tgt:a.id,weight:m-p|0,kind:jr}]:p>m?[{src:a.id,tgt:s.id,weight:p-m|0,kind:jr}]:p>0?[{src:s.id,tgt:a.id,weight:0,kind:jr},{src:a.id,tgt:s.id,weight:0,kind:jr}]:[]};return y(u=>s=>y(a=>f=>Z(E)(f._1)(f._2)(a))(u)((()=>{const a=y(G=>P=>{const et=P.edge.from.node+"|"+(()=>{if(P.edge.from.port.tag==="Just")return P.edge.from.port._1;if(P.edge.from.port.tag==="Nothing")return"_auto_"+P.edge.id;c()})(),K=$e(et)(G.entries);if(K.tag==="Nothing")return{...G,entries:Z(E)(et)({id:0,members:[P.edge.id],incoming:[P.fromPos._1],outgoing:[P.toPos._1],slot:0,mark:0,splitBy:T,splitPartner:T})(G.entries),order:[...G.order,et]};if(K.tag==="Just")return{...G,entries:Z(E)(et)({...K._1,members:[...K._1.members,P.edge.id],incoming:[..._n(A=>A<P.fromPos._1)(K._1.incoming).init,P.fromPos._1,..._n(A=>A<=P.fromPos._1)(K._1.incoming).rest],outgoing:[..._n(A=>A<P.toPos._1)(K._1.outgoing).init,P.toPos._1,..._n(A=>A<=P.toPos._1)(K._1.outgoing).rest]})(G.entries)};c()})({entries:q,order:[]})(s._2),f=Dt(G=>P=>({...P,id:G}))(bt(G=>$e(G)(a.entries))(a.order));if(f.length===0)return[];const g=y(G=>P=>G.prev.tag==="Just"&&P-G.prev._1<1e-9?G:{prev:k("Just",P),out:[...G.out,P]})({prev:T,out:[]})(xt(ht.compare)([...St(f)(G=>G.incoming),...St(f)(G=>G.outgoing)])).out,d=g.length<2?.2*r:.2*y(G=>P=>{if(G.prev.tag==="Nothing")return{prev:k("Just",P),mn:G.mn};if(G.prev.tag==="Just")return{prev:k("Just",P),mn:ot(G.mn)(P-G.prev._1)};c()})({prev:T,mn:1e18})(g).mn,l={segments:f,deps:(()=>{const G=f.length;return St(St(Ht(0,G-2|0))(P=>St(Ht(P+1|0,G-1|0))(et=>[x(P,et)])))(P=>P._1>=0&&P._1<f.length?P._2>=0&&P._2<f.length?i(d,f[P._1],f[P._2]):[]:[])})()},_=ct(G=>{if(G.kind==="Critical")return!0;if(G.kind==="Regular")return!1;c()},l.deps),h=(()=>{if(_.length<2)return l;const G=An((()=>{const H=l.segments;return $(R=>x(R.id,R.mark))((()=>{const R=H.length,C=W=>{let M=W,Y=!0,X;for(;Y;){const V=M,Q=fe(I=>{const U=Nt(I)(V.inWeight);if(U.tag==="Nothing")return!0;if(U.tag==="Just")return U._1===0;c()})(V.remaining);if(Q.tag==="Nothing"){Y=!1,X=V;continue}if(Q.tag==="Just"){const I=Q._1;M={...V,inWeight:y(U=>O=>vt(it)(Ut)(O.tgt)(-O.weight)(U))(V.inWeight)((()=>{const U=Nt(I)(V.depsBySrc);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),marks:Z(it)(I)(V.nextSource)(V.marks),nextSource:V.nextSource+1|0,outWeight:y(U=>O=>vt(it)(Ut)(O.src)(-O.weight)(U))(V.outWeight)((()=>{const U=Nt(I)(V.depsByTgt);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),remaining:ct(U=>U!==I,V.remaining)};continue}c()}return X},D=W=>{let M=W,Y=!0,X;for(;Y;){const V=M,Q=fe(I=>{const U=Nt(I)(V.outWeight);if(U.tag==="Nothing")return!0;if(U.tag==="Just")return U._1===0;c()})(V.remaining);if(Q.tag==="Nothing"){Y=!1,X=V;continue}if(Q.tag==="Just"){const I=Q._1;M={...V,inWeight:y(U=>O=>vt(it)(Ut)(O.tgt)(-O.weight)(U))(V.inWeight)((()=>{const U=Nt(I)(V.depsBySrc);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),marks:Z(it)(I)(V.nextSink)(V.marks),nextSink:V.nextSink-1|0,outWeight:y(U=>O=>vt(it)(Ut)(O.src)(-O.weight)(U))(V.outWeight)((()=>{const U=Nt(I)(V.depsByTgt);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),remaining:ct(U=>U!==I,V.remaining)};continue}c()}return X};return(W=>{let M=W,Y=!0,X;for(;Y;){const V=C(D(M));if(V.remaining.length===0){Y=!1,X=$(Q=>{const I=Nt(Q.id)(V.marks),U=(()=>{if(I.tag==="Nothing")return Q.id;if(I.tag==="Just")return I._1;c()})();return{...Q,mark:U<R?(U+R|0)+1|0:U}})(H);continue}M=(()=>{const Q=U=>{const O=Nt(U)(V.outWeight),gt=Nt(U)(V.inWeight);return(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;c()})()-(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;c()})()|0},I=xt(U=>O=>it.compare(Q(O))(Q(U)))(V.remaining);if(0<I.length){const U=I[0];return{...V,inWeight:y(O=>gt=>vt(it)(Ut)(gt.tgt)(-gt.weight)(O))(V.inWeight)((()=>{const O=Nt(U)(V.depsBySrc);if(O.tag==="Nothing")return[];if(O.tag==="Just")return O._1;c()})()),marks:Z(it)(U)(V.nextSource)(V.marks),nextSource:V.nextSource+1|0,outWeight:y(O=>gt=>vt(it)(Ut)(gt.src)(-gt.weight)(O))(V.outWeight)((()=>{const O=Nt(U)(V.depsByTgt);if(O.tag==="Nothing")return[];if(O.tag==="Just")return O._1;c()})()),remaining:ct(O=>O!==U,V.remaining)}}return V})()}return X})({remaining:$(W=>W.id)(H),marks:q,inWeight:y(W=>M=>vt(it)(Ut)(M.tgt)(M.weight)(W))(q)(_),outWeight:y(W=>M=>vt(it)(Ut)(M.src)(M.weight)(W))(q)(_),depsBySrc:y(W=>M=>vt(it)(ie)(M.src)([M])(W))(q)(_),depsByTgt:y(W=>M=>vt(it)(ie)(M.tgt)([M])(W))(q)(_),nextSink:R-1|0,nextSource:R+1|0})})())})()),P=ct(H=>{const R=Nt(H.src)(G),C=Nt(H.tgt)(G);return(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;c()})()>(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;c()})()},_);if(P.length===0)return l;const et=y(H=>R=>{if(ze(Wo)(R.src)(H.decisions)||ze(Wo)(R.tgt)(H.decisions))return H;const C=Nt(R.src)(H.segMap),D=Nt(R.tgt)(H.segMap);if(C.tag==="Just"&&D.tag==="Just"){const W=(C._1.incoming.length+C._1.outgoing.length|0)>2&&(D._1.incoming.length+D._1.outgoing.length|0)<=2,M=W?D._1:C._1;return{decisions:[...H.decisions,M.id],segMap:Z(it)(M.id)({...M,splitBy:k("Just",W?C._1.id:D._1.id)})(H.segMap)}}return H})({decisions:[],segMap:An($(H=>x(H.id,H))(l.segments))})(P),K=et.segMap,A=y(H=>R=>{const C=ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(R.outgoing)),D=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(R.outgoing)),W=ct(Q=>Q.a.startPosition<=D&&Q.a.endPosition>=C,Dt(Q=>I=>({i:Q,a:I}))(H.freeAreas));if(W.length===0){const Q={...R,incoming:xt(ht.compare)(R.incoming),outgoing:xt(ht.compare)([(C+D)/2]),splitPartner:k("Just",H.nextId)},I={id:H.nextId,incoming:xt(ht.compare)([(C+D)/2]),mark:0,members:R.members,outgoing:xt(ht.compare)(R.outgoing),slot:0,splitBy:T,splitPartner:k("Just",R.id)};return{segMap:Z(it)(I.id)(I)(Z(it)(Q.id)(Q)(H.segMap)),freeAreas:H.freeAreas,nextId:H.nextId+1|0}}const M=0<W.length?k("Just",W[0]):T,Y=(()=>{if(M.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(M.tag==="Just"){if(W.length===1)return M._1;const Q=$(I=>({c:I,rating:(()=>{const U=(I.a.startPosition+I.a.endPosition)/2,O=[U],gt=[U],pt=y((()=>{const lt=H.segMap;return Tt=>Gt=>{const dt=Nt(Gt.tgt)(lt);if(dt.tag==="Nothing")return Tt;if(dt.tag==="Just"){const Mt=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),mt=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),ft=ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(O)),rt=(()=>{const kt=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(O)),Pt=y(Rt=>re=>re>mt?Rt:re>=Mt?Rt+1|0:Rt)(0)(O)+y(Rt=>re=>re>kt?Rt:re>=ft?Rt+1|0:Rt)(0)(dt._1.incoming)|0,Kn=ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(O)),En=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(O)),kn=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),Zn=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),Me=y(Rt=>re=>re>En?Rt:re>=Kn?Rt+1|0:Rt)(0)(dt._1.outgoing)+y(Rt=>re=>re>Zn?Rt:re>=kn?Rt+1|0:Rt)(0)(R.incoming)|0;return Pt===Me?Pt>0?{...Tt,deps:Tt.deps+2|0,crossings:Tt.crossings+Pt|0}:Tt:{...Tt,deps:Tt.deps+1|0,crossings:Tt.crossings+Qn(Pt)(Me)|0}})(),nt=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),st=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),yt=ot(y(ot)(1e18)(gt))(y(ot)(1e18)(R.outgoing)),Jt=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),Ct=y(kt=>Pt=>Pt>st?kt:Pt>=nt?kt+1|0:kt)(0)(R.outgoing)+y(kt=>Pt=>Pt>Jt?kt:Pt>=yt?kt+1|0:kt)(0)(dt._1.incoming)|0,Qt=ot(y(ot)(1e18)(gt))(y(ot)(1e18)(R.outgoing)),ne=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),He=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),Un=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),nn=y(kt=>Pt=>Pt>ne?kt:Pt>=Qt?kt+1|0:kt)(0)(dt._1.outgoing)+y(kt=>Pt=>Pt>Un?kt:Pt>=He?kt+1|0:kt)(0)(gt)|0;return Ct===nn?Ct>0?{...rt,deps:rt.deps+2|0,crossings:rt.crossings+Ct|0}:rt:{...rt,deps:rt.deps+1|0,crossings:rt.crossings+Qn(Ct)(nn)|0}}c()}})())(y((()=>{const lt=H.segMap;return Tt=>Gt=>{const dt=Nt(Gt.src)(lt);if(dt.tag==="Nothing")return Tt;if(dt.tag==="Just"){const Mt=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),mt=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),ft=ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(O)),rt=(()=>{const kt=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(O)),Pt=y(Rt=>re=>re>mt?Rt:re>=Mt?Rt+1|0:Rt)(0)(O)+y(Rt=>re=>re>kt?Rt:re>=ft?Rt+1|0:Rt)(0)(dt._1.incoming)|0,Kn=ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(O)),En=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(O)),kn=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),Zn=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),Me=y(Rt=>re=>re>En?Rt:re>=Kn?Rt+1|0:Rt)(0)(dt._1.outgoing)+y(Rt=>re=>re>Zn?Rt:re>=kn?Rt+1|0:Rt)(0)(R.incoming)|0;return Pt===Me?Pt>0?{...Tt,deps:Tt.deps+2|0,crossings:Tt.crossings+Pt|0}:Tt:{...Tt,deps:Tt.deps+1|0,crossings:Tt.crossings+Qn(Pt)(Me)|0}})(),nt=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),st=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),yt=ot(y(ot)(1e18)(gt))(y(ot)(1e18)(R.outgoing)),Jt=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),Ct=y(kt=>Pt=>Pt>st?kt:Pt>=nt?kt+1|0:kt)(0)(R.outgoing)+y(kt=>Pt=>Pt>Jt?kt:Pt>=yt?kt+1|0:kt)(0)(dt._1.incoming)|0,Qt=ot(y(ot)(1e18)(gt))(y(ot)(1e18)(R.outgoing)),ne=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),He=ot(y(ot)(1e18)(dt._1.incoming))(y(ot)(1e18)(dt._1.outgoing)),Un=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),nn=y(kt=>Pt=>Pt>ne?kt:Pt>=Qt?kt+1|0:kt)(0)(dt._1.outgoing)+y(kt=>Pt=>Pt>Un?kt:Pt>=He?kt+1|0:kt)(0)(gt)|0;return Ct===nn?Ct>0?{...rt,deps:rt.deps+2|0,crossings:rt.crossings+Ct|0}:rt:{...rt,deps:rt.deps+1|0,crossings:rt.crossings+Qn(Ct)(nn)|0}}c()}})())({crossings:0,deps:0})(ct(lt=>lt.tgt===R.id,l.deps)))(ct(lt=>lt.src===R.id,l.deps)),at=(()=>{if(R.splitBy.tag==="Just")return Nt(R.splitBy._1)(H.segMap);if(R.splitBy.tag==="Nothing")return T;c()})();if(at.tag==="Just")return{...pt,deps:pt.deps+2|0,crossings:(()=>{const lt=ot(y(ot)(1e18)(at._1.incoming))(y(ot)(1e18)(at._1.outgoing)),Tt=ot(y(ot)(1e18)(gt))(y(ot)(1e18)(R.outgoing)),Gt=ut(y(ut)(-1e18)(at._1.incoming))(y(ut)(-1e18)(at._1.outgoing)),dt=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),Mt=ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(O));return pt.crossings+(()=>{const mt=ot(y(ot)(1e18)(at._1.incoming))(y(ot)(1e18)(at._1.outgoing)),ft=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(O)),rt=ut(y(ut)(-1e18)(at._1.incoming))(y(ut)(-1e18)(at._1.outgoing));return((y(nt=>st=>st>Gt?nt:st>=lt?nt+1|0:nt)(0)(O)+y(nt=>st=>st>ft?nt:st>=Mt?nt+1|0:nt)(0)(at._1.incoming)|0)+y(nt=>st=>st>dt?nt:st>=Tt?nt+1|0:nt)(0)(at._1.outgoing)|0)+y(nt=>st=>st>rt?nt:st>=mt?nt+1|0:nt)(0)(gt)|0})()|0})()};if(at.tag==="Nothing")return pt;c()})()}))(W);return y(I=>U=>U.rating.crossings<I.rating.crossings||!(U.rating.crossings>I.rating.crossings)&&(U.rating.deps<I.rating.deps||!(U.rating.deps>I.rating.deps)&&U.c.a.size>I.c.a.size)?U:I)(0<Q.length?Q[0]:{c:M._1,rating:{crossings:1e6,deps:1e6}})(Q).c}c()})(),X={...R,incoming:xt(ht.compare)(R.incoming),outgoing:xt(ht.compare)([(Y.a.startPosition+Y.a.endPosition)/2]),splitPartner:k("Just",H.nextId)},V={id:H.nextId,incoming:xt(ht.compare)([(Y.a.startPosition+Y.a.endPosition)/2]),mark:0,members:R.members,outgoing:xt(ht.compare)(R.outgoing),slot:0,splitBy:T,splitPartner:k("Just",R.id)};return{segMap:Z(it)(V.id)(V)(Z(it)(X.id)(X)(H.segMap)),freeAreas:(()=>{if(Y.i>=0&&Y.i<H.freeAreas.length){const Q=Cu(Kt,T,Y.i,H.freeAreas),I=(()=>{if(Q.tag==="Nothing")return H.freeAreas;if(Q.tag==="Just")return Q._1;c()})();if(H.freeAreas[Y.i].size/2<d)return I;const U=(H.freeAreas[Y.i].startPosition+H.freeAreas[Y.i].endPosition)/2,O=U-d,gt=U+d;return[...Y.i<1?[]:Wt(0,Y.i,I),...H.freeAreas[Y.i].startPosition<=O?[{startPosition:H.freeAreas[Y.i].startPosition,endPosition:O,size:O-H.freeAreas[Y.i].startPosition}]:[],...gt<=H.freeAreas[Y.i].endPosition?[{startPosition:gt,endPosition:H.freeAreas[Y.i].endPosition,size:H.freeAreas[Y.i].endPosition-gt}]:[],...Y.i<1?I:Wt(Y.i,I.length,I)]}return H.freeAreas})(),nextId:H.nextId+1|0}})({segMap:K,freeAreas:(()=>{const H=xt(ht.compare)([...St(l.segments)(R=>R.incoming),...St(l.segments)(R=>R.outgoing)]);return bt(h1)(pe(R=>C=>C-R>=2*d?k("Just",{startPosition:R+d,endPosition:C-d,size:C-R-2*d}):T,H,Wt(1,H.length,H)))})(),nextId:l.segments.length})(xt(H=>R=>ht.compare(ut(y(ut)(-1e18)(H.incoming))(y(ut)(-1e18)(H.outgoing))-ot(y(ot)(1e18)(H.incoming))(y(ot)(1e18)(H.outgoing)))(ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(R.outgoing))-ot(y(ot)(1e18)(R.incoming))(y(ot)(1e18)(R.outgoing))))(bt(H=>Nt(H)(K))(et.decisions)));return{segments:(()=>{const H=(R,C)=>{if(R.tag==="Leaf")return C;if(R.tag==="Node")return H(R._5,It("Cons",R._4,H(R._6,C)));c()};return wt(qt.foldr,H(A.segMap,Bt))})(),deps:(()=>{const H=A.segMap,R=(W,M)=>{if(W.tag==="Leaf")return M;if(W.tag==="Node")return R(W._5,It("Cons",W._4,R(W._6,M)));c()},C=wt(qt.foldr,R(H,Bt)),D=C.length;return[...St(St(Ht(0,D-2|0))(W=>St(Ht(W+1|0,D-1|0))(M=>[x(W,M)])))(W=>W._1>=0&&W._1<C.length?W._2>=0&&W._2<C.length?C[W._1].splitPartner.tag!=="Nothing"&&C[W._1].splitPartner.tag==="Just"&&C[W._1].splitPartner._1===C[W._2].id||C[W._2].splitPartner.tag!=="Nothing"&&C[W._2].splitPartner.tag==="Just"&&C[W._2].splitPartner._1===C[W._1].id?[]:i(d,C[W._1],C[W._2]):[]:[]),...St(C)(W=>W.splitBy.tag==="Just"&&W.splitPartner.tag==="Just"&&(()=>{const M=Nt(W.splitPartner._1)(H);if(M.tag==="Nothing")return!1;if(M.tag==="Just")return!0;c()})()&&(()=>{const M=Nt(W.splitBy._1)(H);if(M.tag==="Nothing")return!1;if(M.tag==="Just")return!0;c()})()?[{src:W.id,tgt:W.splitBy._1,weight:1,kind:to},{src:W.splitBy._1,tgt:W.splitPartner._1,weight:1,kind:to}]:[])]})()}})(),p=h.segments,m=p.length,J=G=>{let P=G,et=!0,K;for(;et;){const A=P,H=fe(R=>{const C=Nt(R)(A.inWeight);if(C.tag==="Nothing")return!0;if(C.tag==="Just")return C._1===0;c()})(A.remaining);if(H.tag==="Nothing"){et=!1,K=A;continue}if(H.tag==="Just"){const R=H._1;P={...A,inWeight:y(C=>D=>vt(it)(Ut)(D.tgt)(-D.weight)(C))(A.inWeight)((()=>{const C=Nt(R)(A.depsBySrc);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),marks:Z(it)(R)(A.nextSource)(A.marks),nextSource:A.nextSource+1|0,outWeight:y(C=>D=>vt(it)(Ut)(D.src)(-D.weight)(C))(A.outWeight)((()=>{const C=Nt(R)(A.depsByTgt);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),remaining:ct(C=>C!==R,A.remaining)};continue}c()}return K},N=G=>{let P=G,et=!0,K;for(;et;){const A=P,H=fe(R=>{const C=Nt(R)(A.outWeight);if(C.tag==="Nothing")return!0;if(C.tag==="Just")return C._1===0;c()})(A.remaining);if(H.tag==="Nothing"){et=!1,K=A;continue}if(H.tag==="Just"){const R=H._1;P={...A,inWeight:y(C=>D=>vt(it)(Ut)(D.tgt)(-D.weight)(C))(A.inWeight)((()=>{const C=Nt(R)(A.depsBySrc);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),marks:Z(it)(R)(A.nextSink)(A.marks),nextSink:A.nextSink-1|0,outWeight:y(C=>D=>vt(it)(Ut)(D.src)(-D.weight)(C))(A.outWeight)((()=>{const C=Nt(R)(A.depsByTgt);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),remaining:ct(C=>C!==R,A.remaining)};continue}c()}return K},v=(G=>{let P=G,et=!0,K;for(;et;){const A=J(N(P));if(A.remaining.length===0){et=!1,K=$(H=>{const R=Nt(H.id)(A.marks),C=(()=>{if(R.tag==="Nothing")return H.id;if(R.tag==="Just")return R._1;c()})();return{...H,mark:C<m?(C+m|0)+1|0:C}})(p);continue}P=(()=>{const H=C=>{const D=Nt(C)(A.outWeight),W=Nt(C)(A.inWeight);return(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;c()})()-(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;c()})()|0},R=xt(C=>D=>it.compare(H(D))(H(C)))(A.remaining);if(0<R.length){const C=R[0];return{...A,inWeight:y(D=>W=>vt(it)(Ut)(W.tgt)(-W.weight)(D))(A.inWeight)((()=>{const D=Nt(C)(A.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})()),marks:Z(it)(C)(A.nextSource)(A.marks),nextSource:A.nextSource+1|0,outWeight:y(D=>W=>vt(it)(Ut)(W.src)(-W.weight)(D))(A.outWeight)((()=>{const D=Nt(C)(A.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})()),remaining:ct(D=>D!==C,A.remaining)}}return A})()}return K})({remaining:$(G=>G.id)(p),marks:q,inWeight:y(G=>P=>vt(it)(Ut)(P.tgt)(P.weight)(G))(q)(h.deps),outWeight:y(G=>P=>vt(it)(Ut)(P.src)(P.weight)(G))(q)(h.deps),depsBySrc:y(G=>P=>vt(it)(ie)(P.src)([P])(G))(q)(h.deps),depsByTgt:y(G=>P=>vt(it)(ie)(P.tgt)([P])(G))(q)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),w=(()=>{const G=(()=>{const K=An($(A=>x(A.id,A.mark))(v));return{segments:v,deps:bt(A=>(()=>{if(A.kind==="Critical")return!0;if(A.kind==="Regular")return!1;c()})()?k("Just",A):(()=>{const H=Nt(A.src)(K),R=Nt(A.tgt)(K);return(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;c()})()>(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;c()})()})()?A.weight===0?T:k("Just",{src:A.tgt,tgt:A.src,weight:A.weight,kind:A.kind}):k("Just",A))(h.deps)}})(),P=y(K=>A=>vt(it)(Ut)(A.tgt)(1)(K))(q)(G.deps),et=(K=>{let A=K,H=!0,R;for(;H;){const C=A,D=Vt(W=>T,W=>M=>k("Just",{head:W,tail:M}),C.queue);if(D.tag==="Nothing"){H=!1,R=C;continue}if(D.tag==="Just"){A=y((()=>{const W=Nt(D._1.head)(C.slots),M=(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;c()})();return Y=>X=>{const V=Nt(X)(Y.inDegree),Q=(()=>{if(V.tag==="Nothing")return-1;if(V.tag==="Just")return V._1-1|0;c()})();return{...Y,slots:Z(it)(X)(vs((()=>{const I=Nt(X)(Y.slots);if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;c()})())(M+1|0))(Y.slots),inDegree:Z(it)(X)(Q)(Y.inDegree),queue:Q===0?[...Y.queue,X]:Y.queue}}})())({...C,queue:D._1.tail})((()=>{const W=Nt(D._1.head)(C.adj);if(W.tag==="Nothing")return[];if(W.tag==="Just")return W._1;c()})());continue}c()}return R})({slots:An($(K=>x(K.id,0))(G.segments)),inDegree:P,adj:y(K=>A=>vt(it)(ie)(A.src)([A.tgt])(K))(q)(G.deps),queue:$(K=>K.id)(ct(K=>{const A=Nt(K.id)(P);if(A.tag==="Nothing")return!0;if(A.tag==="Just")return A._1===0;c()},G.segments))});return xt(K=>A=>it.compare(K.slot)(A.slot))($(K=>({...K,slot:(()=>{const A=Nt(K.id)(et.slots);if(A.tag==="Nothing")return 0;if(A.tag==="Just")return A._1;c()})()}))(G.segments))})(),b=1+y(G=>P=>vs(G)(P.slot))(0)(w)|0,L=St(w)(G=>G.members),S=ct(G=>ze(Ye)(G.edge.id)(L),e),z=y(ut)(-1e18)($(G=>G.fromPos._2)(S)),F=y(ot)(1e18)($(G=>G.toPos._2)(S));if(z>F){const G=An($(P=>x(P.id,P))(w));return Ne($(P=>$(et=>x(et,{slot:P.slot,slotCount:b,gapTop:F,gapBottom:z,partner:(()=>{if(P.splitPartner.tag==="Just"){const K=Nt(P.splitPartner._1)(G);if(K.tag==="Just")return k("Just",{slot:K._1.slot,splitX:0<K._1.incoming.length?K._1.incoming[0]:0});if(K.tag==="Nothing")return T;c()}if(P.splitPartner.tag==="Nothing")return T;c()})()}))(P.members))(ct(P=>{if(P.splitPartner.tag==="Just"){const et=Nt(P.splitPartner._1)(G);return!(et.tag==="Just"&&(()=>{if(et._1.splitBy.tag==="Nothing")return!1;if(et._1.splitBy.tag==="Just")return!0;c()})())}if(P.splitPartner.tag==="Nothing")return!0;c()},w)))}const j=An($(G=>x(G.id,G))(w));return Ne($(G=>$(P=>x(P,{slot:G.slot,slotCount:b,gapTop:z,gapBottom:F,partner:(()=>{if(G.splitPartner.tag==="Just"){const et=Nt(G.splitPartner._1)(j);if(et.tag==="Just")return k("Just",{slot:et._1.slot,splitX:0<et._1.incoming.length?et._1.incoming[0]:0});if(et.tag==="Nothing")return T;c()}if(G.splitPartner.tag==="Nothing")return T;c()})()}))(G.members))(ct(G=>{if(G.splitPartner.tag==="Just"){const P=Nt(G.splitPartner._1)(j);return!(P.tag==="Just"&&(()=>{if(P._1.splitBy.tag==="Nothing")return!1;if(P._1.splitBy.tag==="Just")return!0;c()})())}if(G.splitPartner.tag==="Nothing")return!0;c()},w)))})()))(q)(l1(y(u=>s=>{const a=$e(s.edge.from.node)(n);if(a.tag==="Just"){const f=$e(s.edge.to.node)(n);return f.tag==="Just"&&a._1.layer!==f._1.layer?vt(it)(ie)(Qn(a._1.layer)(f._1.layer))([s])(u):u}return u})(q)((()=>{const u=s=>x((()=>{const a=$e(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=$e(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return xt(s=>a=>d1(u(s))(u(a)))(e)})())))},p1=e=>t=>{const n=Ts(e)(t),r=y(o=>i=>Z(E)(i.node)(i)(o))(q)(t);return y(o=>i=>{const u=$e(i.edge.from.node)(r);if(u.tag==="Just"){const s=$e(i.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=$e(i.edge.id)(n);if(a.tag==="Just")return Z(it)(Qn(u._1.layer)(s._1.layer))(a._1.slotCount)(o)}return o}return o})(q)(e)},ws=e=>e,Ot=ws("H"),Xt=ws("V"),Ls=zt.foldMap((()=>{const e={append:t=>n=>t||n};return{mempty:!1,Semigroup0:()=>e}})()),te=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},ee=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},pr=e=>t=>n=>r=>Ls(o=>n>=o.x&&n<o.x+o.w&&t>o.y&&e<o.y+o.h)(r),eo=e=>t=>n=>r=>pr(te(t)(n))(ee(t)(n))(r)(e),no=_t(4),m1=Pu(e=>{if(e.direction==="H"){const t=te(e.start._1)(e.end._1);return[{x:t,y:e.start._2-1,w:ee(e.start._1)(e.end._1)-t,h:2}]}if(e.direction==="V"){const t=te(e.start._2)(e.end._2);return[{x:e.start._1-1,y:t,w:2,h:ee(e.start._2)(e.end._2)-t}]}c()}),Es=Rf(e=>!(e.start._1===e.end._1&&e.start._2===e.end._2)),y1=e=>t=>n=>{const r=Vt(o=>T,o=>i=>k("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return[{start:e.start,end:n.end,direction:e.direction}];if(r.tag==="Just"){const o=(r._1.head.direction==="H"?e.direction==="H":r._1.head.direction==="V"&&e.direction==="V")?[{start:e.start,end:r._1.head.end,direction:e.direction}]:[e,r._1.head],i=Df(r._1.tail);if(i.tag==="Nothing"){const u=o.length-1|0;return u>=0&&u<o.length&&(o[u].direction==="H"?n.direction==="H":o[u].direction==="V"&&n.direction==="V")?[...(()=>{const s=o.length-1|0;return s<1?[]:Wt(0,s,o)})(),{start:o[u].start,end:n.end,direction:n.direction}]:[...o,n]}if(i.tag==="Just")return(i._1.last.direction==="H"?n.direction==="H":i._1.last.direction==="V"&&n.direction==="V")?[...o,...i._1.init,{start:i._1.last.start,end:n.end,direction:n.direction}]:[...o,...r._1.tail,n]}c()},bi=e=>{const t=r=>o=>{const i=Vt(u=>T,u=>s=>k("Just",{head:u,tail:s}),o);if(i.tag==="Nothing")return[r];if(i.tag==="Just")return(r.direction==="H"?i._1.head.direction==="H":r.direction==="V"&&i._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==i._1.head.end._1-i._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==i._1.head.end._2-i._1.head.start._2>=0;c()})()?t({start:r.start,end:i._1.head.end,direction:r.direction})(i._1.tail):[r,...t(i._1.head)(i._1.tail)];c()},n=Vt(r=>T,r=>o=>k("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return t(n._1.head)(n._1.tail);c()},mr=e=>t=>n=>r=>Ls(o=>n>=o.y&&n<o.y+o.h&&t>o.x&&e<o.x+o.w)(r),yr=e=>t=>n=>r=>mr(te(t)(n))(ee(t)(n))(r)(e),J1=e=>t=>n=>r=>{const o=n+2|0,i=o<1?t:Wt(o,t.length,t),u=n<1?[]:Wt(0,n,t),s=(n+1|0)===(r-1|0),a=n===0,f=n>=0&&n<t.length?k("Just",t[n]):T;if(f.tag==="Just"){const g=n+1|0,d=g>=0&&g<t.length?k("Just",t[g]):T;if(d.tag==="Just"){const l=f._1.start._1===d._1.end._1&&(!a||f._1.direction==="V")&&(!s||d._1.direction==="V")&&!eo(e)(te(f._1.start._2)(d._1.end._2))(ee(f._1.start._2)(d._1.end._2))(f._1.start._1)?k("Just",[...u,{start:f._1.start,end:d._1.end,direction:Xt},...i]):T,_=f._1.start._2===d._1.end._2&&(!a||f._1.direction==="H")&&(!s||d._1.direction==="H")&&!yr(e)(te(f._1.start._1)(d._1.end._1))(ee(f._1.start._1)(d._1.end._1))(f._1.start._2)?k("Just",[...u,{start:f._1.start,end:d._1.end,direction:Ot},...i]):T;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return T;c()}if(f.tag==="Nothing")return T;c()},N1=e=>t=>{const n=t.length;return(r=>{let o=r,i=!0,u;for(;i;){const s=o;if((s+1|0)>=n){i=!1,u=t;continue}const a=J1(e)(t)(s)(n);if(a.tag==="Just"){i=!1,u=a._1;continue}if(a.tag==="Nothing"){o=s+1|0;continue}c()}return u})(0)},x1=e=>t=>n=>r=>{const o=(l,_,h)=>!eo(e)(te(_)(h))(ee(_)(h))(l),i=n+3|0,u=i<1?t:Wt(i,t.length,t),s=n<1?[]:Wt(0,n,t),a=(n+2|0)===(r-1|0),f=n===0,g=(l,_,h)=>!yr(e)(te(_)(h))(ee(_)(h))(l),d=n>=0&&n<t.length?k("Just",t[n]):T;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<t.length?k("Just",t[l]):T;if(_.tag==="Just"){const h=d._1.start._1===_._1.end._1&&(!f||d._1.direction==="V")&&(!a||_._1.direction==="V")&&o(d._1.start._1,d._1.start._2,_._1.end._2)?k("Just",[...s,{start:d._1.start,end:_._1.end,direction:Xt},...u]):d._1.start._2===_._1.end._2&&(!f||d._1.direction==="H")&&(!a||_._1.direction==="H")&&g(d._1.start._2,d._1.start._1,_._1.end._1)?k("Just",[...s,{start:d._1.start,end:_._1.end,direction:Ot},...u]):T,p=(!f||d._1.direction==="V")&&(!a||_._1.direction==="H")&&o(d._1.start._1,d._1.start._2,_._1.end._2)&&g(_._1.end._2,d._1.start._1,_._1.end._1)?k("Just",[...s,{start:d._1.start,end:x(d._1.start._1,_._1.end._2),direction:Xt},{start:x(d._1.start._1,_._1.end._2),end:_._1.end,direction:Ot},...u]):T,m=(!f||d._1.direction==="H")&&(!a||_._1.direction==="V")&&g(d._1.start._2,d._1.start._1,_._1.end._1)&&o(_._1.end._1,d._1.start._2,_._1.end._2)?k("Just",[...s,{start:d._1.start,end:x(_._1.end._1,d._1.start._2),direction:Ot},{start:x(_._1.end._1,d._1.start._2),end:_._1.end,direction:Xt},...u]):T,J=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?J:h}if(_.tag==="Nothing")return T;c()}if(d.tag==="Nothing")return T;c()},v1=e=>t=>{const n=t.length;return(r=>{let o=r,i=!0,u;for(;i;){const s=o;if((s+2|0)>=n){i=!1,u=t;continue}const a=x1(e)(t)(s)(n);if(a.tag==="Just"){i=!1,u=a._1;continue}if(a.tag==="Nothing"){o=s+1|0;continue}c()}return u})(0)},T1=e=>{const t=n=>{let r=n,o=!0,i;for(;o;){const u=r,s=bi(Es(N1(e)(v1(e)(u))));if(s.length<u.length){r=s;continue}o=!1,i=s}return i};return n=>t(bi(Es(n)))},w1=e=>t=>n=>r=>{const o=te(n)(r),i=ee(n)(r),u=ct(a=>t>=a.y&&t<a.y+a.h&&a.x+a.w>o&&a.x<i,e);if(r>n){const a=xt(f=>g=>ht.compare(f.x)(g.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=xt(a=>f=>ht.compare(f.x)(a.x))($(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},L1=e=>t=>n=>r=>{const o=te(n)(r),i=ee(n)(r),u=ct(a=>t>=a.x&&t<a.x+a.w&&a.y+a.h>o&&a.y<i,e);if(r>n){const a=xt(f=>g=>ht.compare(f.y)(g.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=xt(a=>f=>ht.compare(f.y)(a.y))($(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},E1=e=>t=>n=>r=>{const o=te(n)(r),i=ee(n)(r),u=ct(a=>t>=a.y&&t<a.y+a.h&&a.x+a.w>o&&a.x<i,e);if(r>n){const a=xt(f=>g=>ht.compare(g.x)(f.x))($(f=>({...f,x:f.x+f.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=xt(a=>f=>ht.compare(a.x)(f.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},k1=e=>t=>n=>r=>{const o=te(n)(r),i=ee(n)(r),u=ct(a=>t>=a.x&&t<a.x+a.w&&a.y+a.h>o&&a.y<i,e);if(r>n){const a=xt(f=>g=>ht.compare(g.y)(f.y))($(f=>({...f,y:f.y+f.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=xt(a=>f=>ht.compare(a.y)(f.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},ks=e=>t=>n=>{let r=e,o=t,i=n,u=!0,s;for(;u;){const a=r,f=o,g=i;if(g>100){u=!1,s=f;continue}if(!a(f+g)){u=!1,s=f+g;continue}if(!a(f-g)){u=!1,s=f-g;continue}r=a,o=f,i=g+1}return s},bs=e=>t=>n=>r=>o=>{const i=te(t)(n),u=ee(t)(n);if(!pr(i)(u)(r)(e))return r;if(!pr(i)(u)(o)(e))return o;const s=(r+o)/2;return pr(i)(u)(s)(e)?ks(a=>pr(i)(u)(a)(e))(s)(1):s},b1=e=>t=>n=>r=>o=>{const i=te(t)(n),u=ee(t)(n);if(!mr(i)(u)(r)(e))return r;if(!mr(i)(u)(o)(e))return o;const s=(r+o)/2;return mr(i)(u)(s)(e)?ks(a=>mr(i)(u)(a)(e))(s)(1):s},C1=e=>t=>n=>r=>{const o=te(t)(n),i=ee(t)(n),u=ct(f=>r>=f.x&&r<f.x+f.w&&f.y+f.h>o&&f.y<i,e),s=y(f=>g=>ee(f)(g.x+g.w+4))(r+4)(u),a=y(f=>g=>te(f)(g.x-4))(r-4)(u);return(()=>{const f=s-r,g=a-r;return(f<0?-f:f)<=(g<0?-g:g)})()?s:a},S1=e=>t=>n=>r=>{const o=te(t)(n),i=ee(t)(n),u=ct(f=>r>=f.y&&r<f.y+f.h&&f.x+f.w>o&&f.x<i,e),s=y(f=>g=>ee(f)(g.y+g.h+4))(r+4)(u),a=y(f=>g=>te(f)(g.y-4))(r-4)(u);return(()=>{const f=s-r,g=a-r;return(f<0?-f:f)<=(g<0?-g:g)})()?s:a},P1=e=>t=>n=>r=>o=>i=>u=>{const s=(()=>{if(r==="South")return x(o._1,o._2+4);if(r==="North")return x(o._1,o._2-4);if(r==="East")return x(o._1+4,o._2);if(r==="West")return x(o._1-4,o._2);c()})(),a=(()=>{if(i==="South")return x(u._1,u._2+4);if(i==="North")return x(u._1,u._2-4);if(i==="East")return x(u._1+4,u._2);if(i==="West")return x(u._1-4,u._2);c()})(),f=(b,L,S)=>!eo(t)(te(L)(S))(ee(L)(S))(b),g=(b,L,S)=>!eo(n)(te(L)(S))(ee(L)(S))(b),d=(b,L,S,z)=>e.tag==="Just"&&!yr(n)(te(b)(L))(ee(b)(L))(e._1)?e._1:b1(t)(b)(L)(S)(z),l=(b,L,S,z)=>{if(b===S){const j=C1(t)(L)(z)(b),G=L1(t)(b)(L)(z),P=k1(t)(b)(L)(z);return[{start:x(b,L),end:x(b,G),direction:Xt},{start:x(b,G),end:x(j,G),direction:Ot},{start:x(j,G),end:x(j,P),direction:Xt},{start:x(j,P),end:x(S,P),direction:Ot},{start:x(S,P),end:x(S,z),direction:Xt}]}const F=d(b,S,L,z);return[{start:x(b,L),end:x(b,F),direction:Xt},{start:x(b,F),end:x(S,F),direction:Ot},{start:x(S,F),end:x(S,z),direction:Xt}]},_=(b,L,S,z)=>{if(L===z){const j=S1(t)(b)(S)(L),G=w1(t)(L)(b)(S),P=E1(t)(L)(b)(S);return[{start:x(b,L),end:x(G,L),direction:Ot},{start:x(G,L),end:x(G,j),direction:Xt},{start:x(G,j),end:x(P,j),direction:Ot},{start:x(P,j),end:x(P,z),direction:Xt},{start:x(P,z),end:x(S,z),direction:Ot}]}const F=bs(t)(L)(z)(b)(S);return[{start:x(b,L),end:x(F,L),direction:Ot},{start:x(F,L),end:x(F,z),direction:Xt},{start:x(F,z),end:x(S,z),direction:Ot}]},h=(b,L,S)=>!yr(t)(te(L)(S))(ee(L)(S))(b),p=(b,L,S)=>!yr(n)(te(L)(S))(ee(L)(S))(b),m=(b,L,S,z)=>{if(p(L,b,S)&&g(S,L,z))return[{start:x(b,L),end:x(S,L),direction:Ot},{start:x(S,L),end:x(S,z),direction:Xt}];const F=bs(t)(L)(z)(b)(S);return[{start:x(b,L),end:x(F,L),direction:Ot},{start:x(F,L),end:x(F,z),direction:Xt},{start:x(F,z),end:x(S,z),direction:Ot}]},J=(b,L,S,z)=>{if(g(b,L,z)&&p(z,b,S))return[{start:x(b,L),end:x(b,z),direction:Xt},{start:x(b,z),end:x(S,z),direction:Ot}];const F=d(b,S,L,z);return[{start:x(b,L),end:x(b,F),direction:Xt},{start:x(b,F),end:x(S,F),direction:Ot},{start:x(S,F),end:x(S,z),direction:Xt}]},N=(()=>{if(r==="South")return i==="North"?s._1===a._1&&f(s._1,s._2,a._2)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Xt}]:l(s._1,s._2,a._1,a._2):i==="East"||i==="West"?J(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="North")return i==="South"?s._1===a._1&&f(s._1,s._2,a._2)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Xt}]:l(s._1,s._2,a._1,a._2):i==="East"||i==="West"?J(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="East")return i==="West"?s._2===a._2&&h(s._2,s._1,a._1)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Ot}]:_(s._1,s._2,a._1,a._2):i==="North"||i==="South"?m(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="West"){if(i==="East")return s._2===a._2&&h(s._2,s._1,a._1)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Ot}]:_(s._1,s._2,a._1,a._2);if(i==="North"||i==="South")return m(s._1,s._2,a._1,a._2)}return l(s._1,s._2,a._1,a._2)})(),v=(()=>{if(r==="South"||r==="North")return Xt;if(r==="East"||r==="West")return Ot;c()})(),w={start:x(a._1,a._2),end:x(u._1,u._2),direction:(()=>{if(i==="South"||i==="North")return Xt;if(i==="East"||i==="West")return Ot;c()})()};return s._1===a._1&&s._2===a._2?[{start:x(o._1,o._2),end:x(u._1,u._2),direction:v}]:y1({start:x(o._1,o._2),end:x(s._1,s._2),direction:v})(N)(w)},G1=$(e=>({x:e.position._1*no-2,y:e.position._2*no-2,w:e.size._1*no+4,h:e.size._2*no+4})),Cs=jt(E)(zt),Oe=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},D1=jt(E)(zt),Ss=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},W1=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e._1)(i._3._1);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(e._2==="North"){if(i._3._2==="North"){r=!1,o=k("Just",i._4);continue}n=i._5;continue}if(i._3._2==="North"){n=i._6;continue}if(e._2==="South"){if(i._3._2==="South"){r=!1,o=k("Just",i._4);continue}n=i._5;continue}if(i._3._2==="South"){n=i._6;continue}if(e._2==="East"){if(i._3._2==="East"){r=!1,o=k("Just",i._4);continue}n=i._5;continue}if(i._3._2==="East"){n=i._6;continue}if(e._2==="West"&&i._3._2==="West"){r=!1,o=k("Just",i._4);continue}}c()}return o},M1=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Ps=e=>t=>{const n=t.position._1+t.size._1,r=t.position._2*2+t.size._2,o=t.position._1*2+t.size._1,i=t.position._2+t.size._2;if(e==="South")return x(o,i*2);if(e==="North")return x(o,t.position._2*2);if(e==="East")return x(n*2,r);if(e==="West")return x(t.position._1*2,r);c()},Ci=e=>t=>{const n=_t(4);if(e==="South")return{lo:t.position._1*n,hi:(t.position._1+t.size._1)*n};if(e==="North")return{lo:t.position._1*n,hi:(t.position._1+t.size._1)*n};if(e==="East")return{lo:t.position._2*n,hi:(t.position._2+t.size._2)*n};if(e==="West")return{lo:t.position._2*n,hi:(t.position._2+t.size._2)*n};c()},Gs=e=>t=>y(n=>r=>vt(e)(ie)(t(r))([r])(n))(q),Ds=e=>t=>n=>r=>{const o=(e==="South"||e==="North")&&(t==="East"||t==="West")&&(()=>{if(e==="South")return r._2>n._2;if(e==="North")return r._2<n._2;if(e==="East")return r._2>n._2;if(e==="West")return r._2<n._2;c()})()&&(()=>{if(t==="East")return n._1>r._1;if(t==="West"||t==="North")return n._1<r._1;if(t==="South")return n._1>r._1;c()})(),i=(e==="East"||e==="West")&&(t==="North"||t==="South")&&(()=>{if(e==="South")return r._1>n._1;if(e==="North")return r._1<n._1;if(e==="East")return r._1>n._1;if(e==="West")return r._1<n._1;c()})()&&(()=>{if(t==="East")return n._2>r._2;if(t==="West"||t==="North")return n._2<r._2;if(t==="South")return n._2>r._2;c()})();return(e==="South"?t==="North"&&n._1===r._1&&r._2>n._2:e==="North"?t==="South"&&n._1===r._1&&r._2<n._2:e==="East"?t==="West"&&n._2===r._2&&r._1>n._1:e==="West"&&t==="East"&&n._2===r._2&&r._1<n._1)?0:o||i?1:2},Ws=e=>t=>{const n=e.hi-e.lo,r=(e.lo+e.hi)/2,o=t.length;return o===0?q:Cs(o===1?$(i=>x(i,r))(t):Dt(i=>u=>x(u,e.lo+_t(i+1|0)*n/_t(o+1|0)))(t))},Ms=e=>t=>n=>r=>o=>{const i=Gs(E)(_=>_.to.node)(e),u=Gs(E)(_=>_.from.node)(e),s=y(_=>h=>Z(E)(h.node)(h)(_))(q)(t),a=(_,h,p)=>{const m=Oe(_)(s);if(m.tag==="Nothing")return x(0,0);if(m.tag==="Just"){const J=Oe(_)(n);if(J.tag==="Nothing"){const N=_t(4);if(p==="South")return x(m._1.position._1*N+m._1.size._1*N/2,(m._1.position._2+m._1.size._2)*N);if(p==="North")return x(m._1.position._1*N+m._1.size._1*N/2,m._1.position._2*N);if(p==="East")return x((m._1.position._1+m._1.size._1)*N,m._1.position._2*N+m._1.size._2*N/2);if(p==="West")return x(m._1.position._1*N,m._1.position._2*N+m._1.size._2*N/2);c()}if(J.tag==="Just"){const N=fe(v=>v.id===h)(J._1);if(N.tag==="Nothing"){const v=_t(4);if(p==="South")return x(m._1.position._1*v+m._1.size._1*v/2,(m._1.position._2+m._1.size._2)*v);if(p==="North")return x(m._1.position._1*v+m._1.size._1*v/2,m._1.position._2*v);if(p==="East")return x((m._1.position._1+m._1.size._1)*v,m._1.position._2*v+m._1.size._2*v/2);if(p==="West")return x(m._1.position._1*v,m._1.position._2*v+m._1.size._2*v/2);c()}if(N.tag==="Just"){const v=_t(4);if(N._1.side==="North")return x(m._1.position._1*v+_t(N._1.offset)*v,m._1.position._2*v);if(N._1.side==="South")return x(m._1.position._1*v+_t(N._1.offset)*v,(m._1.position._2+m._1.size._2)*v);if(N._1.side==="East")return x((m._1.position._1+m._1.size._1)*v,m._1.position._2*v+_t(N._1.offset)*v);if(N._1.side==="West")return x(m._1.position._1*v,m._1.position._2*v+_t(N._1.offset)*v)}}}c()},f=D1(St(r)(_=>{if(_.nodes.length<=2)return[];const h=_t(4);if(1<_.nodes.length){const p=Oe(_.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 $(J=>x(J,m))(pe(J=>N=>_.edgeId+":"+J+"->"+N,_.nodes,Wt(1,_.nodes.length,_.nodes)))}c()}return[]})),g=_=>{const h=Oe(_.from.node)(s),p=Oe(_.to.node)(s);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,J=p._1,N=xt(v=>w=>it.compare(v.score)(w.score))($(v=>{const w=v._1,b=v._2;return{from:w,to:b,score:(()=>{const L=(j,G,P,et,K)=>{const A=Ci(j)(G),H=Ci(j)(P);return A.lo<H.hi&&H.lo<A.hi&&(w==="South"?b==="North"&&K._2>et._2:w==="North"?b==="South"&&K._2<et._2:w==="East"?b==="West"&&K._1>et._1:w==="West"&&b==="East"&&K._1<et._1)?0:Ds(w)(b)(et)(K)},S=Ps(w)(m),z=Ps(b)(J),F=Ds(w)(b)(S)(z);return(()=>{if(F>0){if(w==="South")return b==="North"?L(se,m,J,S,z)*10|0:F*10|0;if(w==="North")return b==="South"?L(ue,m,J,S,z)*10|0:F*10|0;if(w==="East")return b==="West"?L(mn,m,J,S,z)*10|0:F*10|0;if(w==="West"&&b==="East")return L(yn,m,J,S,z)*10|0}return F*10|0})()+(w==="South"?b==="North"?0:15:w==="North"?b==="South"?0:15:w==="East"?b==="West"?5:15:w==="West"&&b==="East"?5:15)|0})()}})([x(se,ue),x(mn,ue),x(yn,ue),x(se,mn),x(se,yn),x(ue,se),x(ue,mn),x(ue,yn),x(mn,se),x(yn,se),x(mn,yn),x(yn,mn)]));if(0<N.length)return{from:N[0].from,to:N[0].to}}return{from:se,to:ue}},d=Cs($(_=>x(_.id,g(_)))(e)),l=(_,h,p,m,J,N)=>{const v=_t(4),w=Oe(h)(s);if(w.tag==="Nothing")return x(0,0);if(w.tag==="Just"){const b=W1(x(p,_))(o);if(b.tag==="Just"){const L=w._1.position._1*v+b._1,S=_t(4);if(_==="South")return x(L,(w._1.position._2+w._1.size._2)*S);if(_==="North")return x(L,w._1.position._2*S);if(_==="East")return x((w._1.position._1+w._1.size._1)*S,L);if(_==="West")return x(w._1.position._1*S,L);c()}if(b.tag==="Nothing"){const L=Ci(_)(w._1),S=(L.lo+L.hi)/2,z=Ss(p)(Ws(L)($(G=>G.id)(xt(G=>P=>ht.compare(J(_)(G))(J(_)(P)))(ct(G=>{const P=Ss(G.id)(d);if(P.tag==="Just"){const et=N(P._1);return et==="North"?_==="North":et==="South"?_==="South":et==="East"?_==="East":et==="West"&&_==="West"}if(P.tag==="Nothing")return!0;c()},(()=>{const G=Oe(h)(m);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()))))),F=(()=>{if(z.tag==="Nothing")return S;if(z.tag==="Just")return z._1;c()})(),j=_t(4);if(_==="South")return x(F,(w._1.position._2+w._1.size._2)*j);if(_==="North")return x(F,w._1.position._2*j);if(_==="East")return x((w._1.position._1+w._1.size._1)*j,F);if(_==="West")return x(w._1.position._1*j,F)}}c()};return $(_=>{const h=M1(_.edge.id)(f);if(h.tag==="Nothing")return _;if(h.tag==="Just")return{..._,fromPos:oe(3)(_.edge.from.node)==="$d:"?x(h._1,_.fromPos._2):_.fromPos,toPos:oe(3)(_.edge.to.node)==="$d:"?x(h._1,_.toPos._2):_.toPos};c()})($(_=>{if(_.from.port.tag==="Just"&&_.to.port.tag==="Just")return{edge:_,fromPos:a(_.from.node,_.from.port._1,se),toPos:a(_.to.node,_.to.port._1,ue),fromSide:se,toSide:ue};const h=g(_);return{edge:_,fromPos:l(h.from,_.from.node,_.id,u,p=>m=>{const J=Oe(m.to.node)(s);if(J.tag==="Nothing")return 0;if(J.tag==="Just"){const N=_t(4);if(p==="South"||p==="North")return J._1.position._1*N+J._1.size._1*N/2;if(p==="East"||p==="West")return J._1.position._2*N+J._1.size._2*N/2}c()},p=>p.from),toPos:l(h.to,_.to.node,_.id,i,p=>m=>{const J=Oe(m.from.node)(s);if(J.tag==="Nothing")return 0;if(J.tag==="Just"){const N=_t(4);if(p==="South"||p==="North")return J._1.position._1*N+J._1.size._1*N/2;if(p==="East"||p==="West")return J._1.position._2*N+J._1.size._2*N/2}c()},p=>p.to),fromSide:h.from,toSide:h.to}})(e))},Rs=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},qn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},R1=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),Si=e=>t=>e.gapTop+1*_t(4)+_t(t)*2.5*_t(4),I1=e=>t=>{const n=Rs(t.edge.id)(e);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return k("Just",{slot1Y:Si(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Si(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return T;c()}if(n.tag==="Nothing")return T;c()},z1=e=>t=>{const n=y(r=>o=>Z(E)(o.node)(o)(r))(q)(t);return Ne(Dt(r=>o=>{const i=qn(o.node)(n);if(i.tag==="Nothing")return[];if(i.tag==="Just"){const u=i._1;return Dt(s=>a=>{const f=o.edges.length,g=_t(4),d=u.position._1*g,l=u.position._2*g,_=u.size._2*g,h=_t((2*f|0)+1|0),p=l+_*_t(f-s|0)/h,m=l+_*_t((f+1|0)+s|0)/h,J=d-g*2.5*_t(s+1|0),N=[{start:x(d,p),end:x(J,p),direction:Ot},{start:x(J,p),end:x(J,m),direction:Xt},{start:x(J,m),end:x(d,m),direction:Ot}];return{edge:a.id,segments:N,bends:pe(v=>w=>v.end,N,Wt(1,3,N)),bendType:[],jumps:[],reversed:!1}})(o.edges)}c()})($(r=>({node:r._1,edges:r._2}))(R1(y(r=>o=>vt(E)(ie)(o.from.node)([o])(r))(q)(e)))))},B1=e=>t=>{const n=y(i=>u=>Z(E)(u.node)(u)(i))(q)(t),r=i=>{const u=qn(i)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.position._1;c()},o=i=>{const u=qn(i)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.layer;c()};return xt(i=>u=>{const s=it.compare(o(i.edge.from.node))(o(u.edge.from.node));if(s==="EQ"){const a=ht.compare(r(i.edge.from.node))(r(u.edge.from.node));return a==="EQ"?ht.compare(r(i.edge.to.node))(r(u.edge.to.node)):a}return s})(e)},de=e=>{const t=_t(4);return{x:e.position._1*t-2,y:e.position._2*t-2,w:e.size._1*t+4,h:e.size._2*t+4}},A1=e=>e.from.node===e.to.node,Q1=e=>t=>n=>r=>{const o=T1(n)(P1(e)(t)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:o,bends:pe(i=>u=>i.end,o,Wt(1,o.length,o)),bendType:[],jumps:[],reversed:!1}},q1=e=>t=>n=>r=>{const o=[{start:x(r.fromPos._1,r.fromPos._2),end:x(r.fromPos._1,e.slot1Y),direction:Xt},{start:x(r.fromPos._1,e.slot1Y),end:x(e.splitX,e.slot1Y),direction:Ot},{start:x(e.splitX,e.slot1Y),end:x(e.splitX,e.slot2Y),direction:Xt},{start:x(e.splitX,e.slot2Y),end:x(r.toPos._1,e.slot2Y),direction:Ot},{start:x(r.toPos._1,e.slot2Y),end:x(r.toPos._1,r.toPos._2),direction:Xt}];return{edge:r.edge.id,segments:o,bends:pe(i=>u=>i.end,o,Wt(1,5,o)),bendType:[],jumps:[],reversed:!1}},H1=e=>t=>n=>{const r=qn(e.edge.from.node)(n);if(r.tag==="Just"){const i=qn(e.edge.to.node)(n);return i.tag==="Just"?ct(u=>!(u.h===de(r._1).h&&u.w===de(r._1).w&&u.x===de(r._1).x&&u.y===de(r._1).y)&&!(u.h===de(i._1).h&&u.w===de(i._1).w&&u.x===de(i._1).x&&u.y===de(i._1).y),t):ct(u=>!(u.h===de(r._1).h&&u.w===de(r._1).w&&u.x===de(r._1).x&&u.y===de(r._1).y),t)}const o=qn(e.edge.to.node)(n);return o.tag==="Just"?ct(i=>!(i.h===de(o._1).h&&i.w===de(o._1).w&&i.x===de(o._1).x&&i.y===de(o._1).y),t):ct(i=>!0,t)},V1=e=>t=>{const n=Rs(t.edge.id)(e);if(n.tag==="Just")return k("Just",Si(n._1)(n._1.slot));if(n.tag==="Nothing")return T;c()},Y1=e=>t=>n=>r=>o=>{const i=y(f=>g=>Z(E)(g.node)(g)(f))(q)(t),u=G1(t),s=Ms(ct(f=>f.from.node!==f.to.node,e))(t)(n)(r)(o),a=Ts(s)(t);return[...z1(ct(A1,e))(t),...y(f=>g=>{const d=H1(g)(u)(i),l=[...d,...f.edgeObstacles],_=I1(a)(g),h=(()=>{if(_.tag==="Just")return q1(_._1)(d)(l)(g);if(_.tag==="Nothing")return Q1(V1(a)(g))(d)(l)(g);c()})();return{results:[...f.results,h],edgeObstacles:[...f.edgeObstacles,...m1(h.segments)]}})({results:[],edgeObstacles:[]})(B1(s)(t)).results]},an=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},cn=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},F1=e=>t=>n=>{if(e.start._1!==t.start._1)return T;const r=cn(an(e.start._2)(e.end._2))(an(t.start._2)(t.end._2)),o=an(cn(e.start._2)(e.end._2))(cn(t.start._2)(t.end._2));return r<o?k("Just",{position:x(e.start._1,(r+o)/2),crossingEdge:n}):T},$1=e=>t=>n=>{if(e.start._2!==t.start._2)return T;const r=cn(an(e.start._1)(e.end._1))(an(t.start._1)(t.end._1)),o=an(cn(e.start._1)(e.end._1))(cn(t.start._1)(t.end._1));return r<o?k("Just",{position:x((r+o)/2,e.start._2),crossingEdge:n}):T},O1=e=>t=>n=>{if(e.direction==="H")return $1(e)(t)(n);if(e.direction==="V")return F1(e)(t)(n);c()},X1=e=>t=>n=>{const r=e+1|0,o=r<1?n:Wt(r,n.length,n);return St(t.segments)(i=>St(o)(u=>bt(s=>O1(i)(s)(u.edge))(ct(s=>s.direction==="H"?i.direction==="H":s.direction==="V"&&i.direction==="V",u.segments))))},U1=e=>t=>n=>t.start._1>an(e.start._1)(e.end._1)&&t.start._1<cn(e.start._1)(e.end._1)&&e.start._2>an(t.start._2)(t.end._2)&&e.start._2<cn(t.start._2)(t.end._2)?k("Just",{position:x(t.start._1,e.start._2),crossingEdge:n}):T,K1=e=>t=>St(ct(n=>n.direction==="H",e.segments))(n=>St(t)(r=>bt(o=>U1(n)(o)(r.edge))(ct(o=>o.direction==="V",r.segments)))),Z1=e=>t=>n=>[...K1(t)(ct(r=>r.edge!==t.edge,n)),...X1(e)(t)(n)],ro=(()=>{const e={eq:t=>n=>t._1===n._1&&(t._2==="North"?n._2==="North":t._2==="South"?n._2==="South":t._2==="East"?n._2==="East":t._2==="West"&&n._2==="West")};return{compare:t=>n=>{const r=E.compare(t._1)(n._1);if(r==="LT")return Re;if(r==="GT")return Ie;if(t._2==="North")return n._2==="North"?Ve:Re;if(n._2==="North")return Ie;if(t._2==="South")return n._2==="South"?Ve:Re;if(n._2==="South")return Ie;if(t._2==="East")return n._2==="East"?Ve:Re;if(n._2==="East")return Ie;if(t._2==="West"&&n._2==="West")return Ve;c()},Eq0:()=>e}})(),j1=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=ro.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},td=jt(E)(zt),Pi=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},ed=jt(ro)(zt),Is=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),Hn=e=>t=>n=>r=>{const o=j1(x(t,n))(e);if(o.tag==="Nothing")return r;if(o.tag==="Just")return o._1;c()},zs=e=>t=>n=>{const r=td(Ne($(u=>Dt(s=>a=>x(a,s))(u))(e))),o=(u,s)=>{if(u==="South"){const a=Pi(s.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()}if(u==="North"){const a=Pi(s.from.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()}return 0},i=u=>y(s=>a=>ye(ro.compare,he,ed($(f=>x(x(f._1,u),f._2))(Is(Ws({lo:0,hi:(()=>{const f=Pi(a._1)(n);if(f.tag==="Just")return f._1._1;if(f.tag==="Nothing")return oe(3)(a._1)==="$d:"?0:1;c()})()})($(f=>f.id)(xt(f=>g=>it.compare(o(u,f))(o(u,g)))(a._2)))))),s))(q)(Is(y(s=>a=>a.from.node===a.to.node?s:u==="South"?vt(E)(ie)(a.from.node)([a])(s):u==="North"?vt(E)(ie)(a.to.node)([a])(s):s)(q)(t)));return ye(ro.compare,he,i(ue),i(se))},Bs=e=>e,As=e=>e,Qs=e=>e,nd=y(e=>t=>Z(E)(t)()(e))(q),rd=(()=>{const e=Pe.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return k("Just",x(t._1,t._2));c()});return t=>e((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._3,n(r._6,o)));c()};return n(t,Bt)})())})(),tt=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Le=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Be=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},be=jt(E)(zt),Gi=Vf(E),Jr=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),qs=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},od=e=>t=>{const n=it.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},id=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=it.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Hs=Qs("VDown"),Vs=Qs("VUp"),ud=As("ForwardPhase"),sd=As("StackPhase"),Ys=Bs("HRight"),Fs=Bs("HLeft"),ad=e=>t=>n=>{const r=y(u=>s=>vt(E)(Ut)(s.tgt)(1)(u))(q)(e),o=rd(nd([...$(u=>u.src)(e),...$(u=>u.tgt)(e),...(()=>{const u=(s,a)=>{if(s.tag==="Leaf")return a;if(s.tag==="Node")return u(s._5,It("Cons",s._4,u(s._6,a)));c()};return wt(qt.foldr,u(t,Bt))})()])),i=y(u=>s=>vt(E)(ie)(s.src)([{target:s.tgt,sep:s.sep}])(u))(q)(e);return(u=>s=>a=>{let f=u,g=s,d=a,l=!0,_;for(;l;){const h=f,p=g,m=d,J=Vt(N=>T,N=>v=>k("Just",{head:N,tail:v}),h);if(J.tag==="Nothing"){l=!1,_=m;continue}if(J.tag==="Just"){const N=tt(J._1.head)(m),v=(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})(),w=y(b=>L=>{const S=tt(L.target)(b.result),z=v+L.sep,F=tt(L.target)(b.indeg),j=(()=>{if(F.tag==="Nothing")return-1;if(F.tag==="Just")return F._1-1|0;c()})();return{newQueue:j===0?[...b.newQueue,L.target]:b.newQueue,result:Z(E)(L.target)((()=>{if(S.tag==="Nothing")return z;if(S.tag==="Just"){if(n==="VDown")return Le(S._1)(z);if(n==="VUp")return Be(S._1)(z)}c()})())(b.result),indeg:Z(E)(L.target)(j)(b.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const b=tt(J._1.head)(i);if(b.tag==="Nothing")return[];if(b.tag==="Just")return b._1;c()})());f=[...J._1.tail,...w.newQueue],g=w.indeg,d=w.result;continue}c()}return _})(ct(u=>{const s=tt(u)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;c()},o))(q)(y(u=>s=>Z(E)(s)(0)(u))(q)(o))},cd=e=>{const t=(i,u)=>{if(i.tag==="Leaf")return u;if(i.tag==="Node")return t(i._5,It("Cons",i._4,t(i._6,u)));c()},n=wt(qt.foldr,t(e,Bt)),r=y(Le)(999999)(n);if(r===0||n.length===0)return e;const o=i=>{if(i.tag==="Leaf")return q;if(i.tag==="Node")return $t("Node",i._1,i._2,i._3,i._4-r,o(i._5),o(i._6));c()};return o(e)},fd=e=>t=>{const n=(o,i,u)=>oe(3)(i)==="$d:"&&Su(s=>oe(3)(s)==="$d:",(()=>{const s=tt(i)(e.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;c()})()),r=o=>i=>u=>s=>a=>f=>g=>{let d=o,l=i,_=s,h=f,p=g,m=!0,J;for(;m;){const N=d,v=l,w=_,b=h,L=p,S=v.length;if(L>=S){m=!1,J=N;continue}const z=L>=0&&L<v.length?k("Just",v[L]):T,F=(()=>{if(z.tag==="Nothing")return"";if(z.tag==="Just")return z._1;c()})(),j=n(e,F);if(L===(S-1|0)||j){const G=(()=>{if(j){const P=tt(F)(e.preds),et=(()=>{if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;c()})();if(0<et.length){const K=w-1|0,A=tt(et[0])(e.nodeIndex);if(A.tag==="Nothing")return K;if(A.tag==="Just")return A._1;c()}}return w-1|0})();d=y(P=>et=>{if(et>=0&&et<v.length){const K=v[et];return n(e,K)?P:y(A=>H=>{const R=tt(H)(e.nodeIndex),C=(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;c()})();return C<b||C>G?Z(E)(H+"\u2192"+K)()(A):A})(P)((()=>{const A=tt(K)(e.preds);if(A.tag==="Nothing")return[];if(A.tag==="Just")return A._1;c()})())}return n(e,"")?P:y(K=>A=>{const H=tt(A)(e.nodeIndex),R=(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;c()})();return R<b||R>G?Z(E)(A+"\u2192")()(K):K})(P)((()=>{const K=tt("")(e.preds);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;c()})())})(N)(Ht(0,L)),l=v,_=w,h=G,p=L+1|0;continue}d=N,l=v,_=w,h=b,p=L+1|0}return J};return t.length<3?q:y(o=>i=>{if(i>=0&&i<t.length){const u=t[i];return r(o)((()=>{const s=i+1|0;return s>=0&&s<t.length?t[s]:[]})())(u)(u.length)(i)(0)(0)}return r(o)((()=>{const u=i+1|0;return u>=0&&u<t.length?t[u]:[]})())([])(0)(i)(0)(0)})(q)(Ht(1,t.length-2|0))},$s=e=>{const t=(i,u)=>{if(i.tag==="Leaf")return u;if(i.tag==="Node")return t(i._5,It("Cons",i._4,t(i._6,u)));c()},n=t(e,Bt),r=i=>u=>{let s=i,a=u,f=!0,g;for(;f;){const d=s,l=a;if(l.tag==="Nil"){f=!1,g=d;continue}if(l.tag==="Cons"){s=Be(d)(l._1),a=l._2;continue}c()}return g},o=i=>u=>{let s=i,a=u,f=!0,g;for(;f;){const d=s,l=a;if(l.tag==="Nil"){f=!1,g=d;continue}if(l.tag==="Cons"){s=Le(d)(l._1),a=l._2;continue}c()}return g};return r(-999999)(n)-o(999999)(n)},Nr=e=>t=>(n=>r=>{let o=n,i=r,u=!0,s;for(;u;){const a=o,f=i;if(a===t){u=!1,s=f;continue}o=(()=>{const g=tt(a)(e.align);if(g.tag==="Nothing")return t;if(g.tag==="Just")return g._1;c()})(),i=[...f,a]}return s})((()=>{const n=tt(t)(e.align);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;c()})())([t]),gd=e=>t=>n=>r=>o=>i=>u=>s=>a=>f=>g=>{const d=(C,D,W)=>{const M=C.from.node===D?C.from.port:C.to.node===D?C.to.port:T;if(M.tag==="Just"){const Y=tt(D)(o);if(Y.tag==="Just"){const X=fe(V=>V.id===M._1)(Y._1);if(X.tag==="Just"){const V=_t(X._1.offset)*_t(4);return W==="North"||W==="South"?V:0}if(X.tag==="Nothing"){const V=tt(D)(r),Q=Hn(u)(C.id)(W)((()=>{if(V.tag==="Nothing")return .5;if(V.tag==="Just")return V._1._1/2;c()})());return W==="North"||W==="South"?Q:0}c()}if(Y.tag==="Nothing"){const X=tt(D)(r),V=Hn(u)(C.id)(W)((()=>{if(X.tag==="Nothing")return .5;if(X.tag==="Just")return X._1._1/2;c()})());return W==="North"||W==="South"?V:0}c()}if(M.tag==="Nothing"){const Y=tt(D)(r),X=Hn(u)(C.id)(W)((()=>{if(Y.tag==="Nothing")return .5;if(Y.tag==="Just")return Y._1._1/2;c()})());return W==="North"||W==="South"?X:0}c()},l=(C,D)=>{if(C.from.node===D){if(g==="HRight")return se;if(g==="HLeft")return ue;c()}if(g==="HRight")return ue;if(g==="HLeft")return se;c()},_=(C,D,W)=>y(M=>Y=>Z(E)(Y)((()=>{const X=tt(Y)(M);if(X.tag==="Nothing")return 0+D;if(X.tag==="Just")return X._1+D;c()})())(M))(W)(Nr(a)(C)),h=(()=>{if(g==="HRight")return n;if(g==="HLeft")return _e(n);c()})(),p=C=>{const D=tt(C)(r);if(D.tag==="Nothing")return 1;if(D.tag==="Just")return D._1._1;c()},m=be(Ne(Dt(C=>D=>$(W=>x(W,C))(D))(n))),J=(C,D)=>oe(3)(C)==="$d:"&&oe(3)(D)==="$d:"||oe(3)(C)==="$d:"||oe(3)(D)==="$d:"?10:_t(e.nodeGap),N=y(C=>D=>Gi(W=>k("Just",[...(()=>{if(W.tag==="Nothing")return[];if(W.tag==="Just")return W._1;c()})(),D]))(D.to.node)(C))(q)(i),v=y(C=>D=>Gi(W=>k("Just",[...(()=>{if(W.tag==="Nothing")return[];if(W.tag==="Just")return W._1;c()})(),D]))(D.from.node)(C))(q)(i),w=Ne(n),b=y(C=>D=>{const W=tt(D)(a.root),M=(()=>{if(W.tag==="Nothing")return D;if(W.tag==="Just")return W._1;c()})();return D===M?C:Gi(Y=>k("Just",(()=>{if(Y.tag==="Nothing")return!0;if(Y.tag==="Just")return Y._1;c()})()&&oe(3)(D)==="$d:"))(M)(C)})(be($(C=>x(C,!0))(Pn(E.compare)((()=>{const C=(D,W)=>{if(D.tag==="Leaf")return W;if(D.tag==="Node")return C(D._5,It("Cons",D._4,C(D._6,W)));c()};return wt(qt.foldr,C(a.root,Bt))})()))))(w),L=(C,D)=>{const W=C.free,M=tt(W)(a.root),Y=(()=>{if(M.tag==="Nothing")return W;if(M.tag==="Just")return M._1;c()})(),X=tt(Y)(b),V=(()=>{if(X.tag==="Nothing")return!0;if(X.tag==="Just")return X._1;c()})();return y(Q=>I=>{if(Q.edge.tag==="Just")return Q;if(Q.edge.tag==="Nothing"){if((()=>{const at=tt(Y)(D.su);return!V&&(()=>{const lt=tt(I.from.node)(m);return I.from.node!==I.to.node&&(()=>{const Tt=tt(I.to.node)(m);return(()=>{if(lt.tag==="Nothing")return-1;if(lt.tag==="Just")return lt._1;c()})()===(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._1;c()})()})()})()||(()=>{if(at.tag==="Nothing")return!1;if(at.tag==="Just")return at._1;c()})()})())return Q;const U=I.from.node===W?I.to.node:I.from.node,O=tt(U)(a.root),gt=(()=>{if(O.tag==="Nothing")return U;if(O.tag==="Just")return O._1;c()})(),pt=gt!==Y;return pt&&(()=>{const at=tt(gt)(D.blockFinished);if(at.tag==="Nothing")return!1;if(at.tag==="Just")return at._1;c()})()?{...Q,edge:k("Just",I),hasEdges:!0}:{...Q,hasEdges:Q.hasEdges||pt}}c()})({edge:T,hasEdges:!1})((()=>{if(C.isRoot){if(g==="HRight"){const Q=tt(W)(N);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()}if(g==="HLeft"){const Q=tt(W)(v);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1}c()}if(g==="HRight"){const Q=tt(W)(v);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()}if(g==="HLeft"){const Q=tt(W)(N);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1}c()})())},S=(C,D,W,M)=>{const Y=(()=>{if(f==="VDown")return-1e18;if(f==="VUp")return 1e18;c()})(),X={free:D,isRoot:W},V=L(X,M);if(V.edge.tag==="Nothing")return V.hasEdges?{thresh:Y,state:{...M,queue:[...M.queue,X]}}:{thresh:Y,state:M};if(V.edge.tag==="Just"){const Q=V.edge._1.from.node===D?V.edge._1.to.node:V.edge._1.from.node;return{thresh:(()=>{const I=tt((()=>{const pt=tt(Q)(a.root);if(pt.tag==="Nothing")return Q;if(pt.tag==="Just")return pt._1;c()})())(M.x),U=tt(Q)(s),O=tt(D)(s),gt=(()=>{if(I.tag==="Just")return I._1;if(I.tag==="Nothing")return T;c()})();return(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;c()})()+(()=>{if(U.tag==="Nothing")return 0;if(U.tag==="Just")return U._1;c()})()+d(V.edge._1,Q,(()=>{if(W){if(g==="HRight")return se;if(g==="HLeft")return ue;c()}if(g==="HRight")return ue;if(g==="HLeft")return se;c()})())-(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;c()})()-d(V.edge._1,D,(()=>{if(W){if(g==="HRight")return ue;if(g==="HLeft")return se;c()}if(g==="HRight")return se;if(g==="HLeft")return ue;c()})())})(),state:{...M,su:Z(E)((()=>{const I=tt(V.edge._1.from.node)(a.root);if(I.tag==="Nothing")return V.edge._1.from.node;if(I.tag==="Just")return I._1;c()})())(!0)(Z(E)((()=>{const I=tt(V.edge._1.to.node)(a.root);if(I.tag==="Nothing")return V.edge._1.to.node;if(I.tag==="Just")return I._1;c()})())(!0)(M.su))}}}c()},z=(C,D,W,M)=>{const Y=D===C,X=tt(D)(a.align),V=(()=>{if(X.tag==="Nothing")return D===C;if(X.tag==="Just")return X._1===C;c()})();if(!(Y||V))return{thresh:W,state:M};const Q=(()=>{if(f==="VDown")return Y&&W<=-1e18;if(f==="VUp")return Y&&W>=1e18;c()})()?S(C,D,!0,M):{thresh:W,state:M};return(()=>{if(f==="VDown")return Q.thresh<=-1e18&&V;if(f==="VUp")return Q.thresh>=1e18&&V;c()})()?S(C,D,!1,Q.state):Q},F=C=>D=>W=>{const M=tt(W)(t.nodeIndex),Y=(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;c()})(),X=fe(O=>ze(Ye)(W)(O))(h),V=(()=>{if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;c()})(),Q=V.length;if((()=>{if(f==="VDown")return Y<=0;if(f==="VUp")return Y>=(Q-1|0);c()})()){const O=z(C,W,D.thresh,D.st);return{...D,st:O.state,thresh:O.thresh}}const I=(()=>{if(f==="VDown")return Y-1|0;if(f==="VUp")return Y+1|0;c()})(),U=I>=0&&I<V.length?k("Just",V[I]):T;if(U.tag==="Nothing")return D;if(U.tag==="Just"){const O=tt(U._1)(a.root),gt=(()=>{if(O.tag==="Nothing")return U._1;if(O.tag==="Just")return O._1;c()})(),pt=z(C,W,D.thresh,j(gt)(D.st)),at=(()=>{const ne=tt(C)(pt.state.sink);if(ne.tag==="Nothing")return C===C;if(ne.tag==="Just")return ne._1===C;c()})()?{...pt.state,sink:Z(E)(C)((()=>{const ne=tt(gt)(pt.state.sink);if(ne.tag==="Nothing")return gt;if(ne.tag==="Just")return ne._1;c()})())(pt.state.sink)}:pt.state,lt=tt(gt)(at.sink),Tt=(()=>{if(lt.tag==="Nothing")return gt;if(lt.tag==="Just")return lt._1;c()})(),Gt=tt(C)(at.sink),dt=(()=>{if(Gt.tag==="Nothing")return C;if(Gt.tag==="Just")return Gt._1;c()})();if(dt===Tt){const ne=tt(gt)(at.x),He=(()=>{if(ne.tag==="Just")return ne._1;if(ne.tag==="Nothing")return T;c()})(),Un=(()=>{if(He.tag==="Nothing")return 0;if(He.tag==="Just")return He._1;c()})(),nn=tt(C)(at.x),kt=(()=>{if(nn.tag==="Just")return nn._1;if(nn.tag==="Nothing")return T;c()})(),Pt=(()=>{if(kt.tag==="Nothing")return 0;if(kt.tag==="Just")return kt._1;c()})(),Kn=J(W,U._1),En=tt(U._1)(s),kn=tt(W)(s),Zn=(()=>{if(En.tag==="Nothing")return 0;if(En.tag==="Just")return En._1;c()})()-(()=>{if(kn.tag==="Nothing")return 0;if(kn.tag==="Just")return kn._1;c()})();if(f==="VDown"){const Me=Be(Un+Zn+p(U._1)+Kn)(pt.thresh);return{st:{...at,x:Z(E)(C)(k("Just",D.initial?Me:Be(Pt)(Me)))(at.x)},initial:!1,thresh:pt.thresh}}if(f==="VUp"){const Me=Le(Un+Zn-Kn-p(W))(pt.thresh);return{st:{...at,x:Z(E)(C)(k("Just",D.initial?Me:Le(Pt)(Me)))(at.x)},initial:!1,thresh:pt.thresh}}c()}const Mt=tt(gt)(at.x),mt=(()=>{if(Mt.tag==="Just")return Mt._1;if(Mt.tag==="Nothing")return T;c()})(),ft=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})(),rt=tt(C)(at.x),nt=(()=>{if(rt.tag==="Just")return rt._1;if(rt.tag==="Nothing")return T;c()})(),st=(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})(),yt=_t(e.nodeGap),Jt=tt(W)(s),Ct=tt(U._1)(s),Qt=(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;c()})()-(()=>{if(Ct.tag==="Nothing")return 0;if(Ct.tag==="Just")return Ct._1;c()})();return{st:{...at,classEdges:[...at.classEdges,{src:dt,tgt:Tt,sep:(()=>{if(f==="VDown")return st+Qt-ft-p(U._1)-yt;if(f==="VUp")return st+Qt+p(W)+yt-ft;c()})()}]},initial:D.initial,thresh:pt.thresh}}c()},j=C=>D=>{const W=tt(C)(D.x),M=(()=>{if(W.tag==="Just")return W._1;if(W.tag==="Nothing")return T;c()})();if(M.tag==="Just")return D;if(M.tag==="Nothing"){const Y=y(F(C))({st:{...D,x:Z(E)(C)(k("Just",0))(D.x)},initial:!0,thresh:(()=>{if(f==="VDown")return-1e18;if(f==="VUp")return 1e18;c()})()})(Nr(a)(C));return{...Y.st,blockFinished:Z(E)(C)(!0)(Y.st.blockFinished)}}c()},G=y(C=>D=>y(W=>M=>{const Y=tt(M)(a.root),X=(()=>{if(Y.tag==="Nothing")return M;if(Y.tag==="Just")return Y._1;c()})();return X===M?j(X)(W):W})(C)((()=>{if(f==="VDown")return D;if(f==="VUp")return _e(D);c()})()))({x:be($(C=>x(C,T))(w)),sink:be($(C=>x(C,C))(w)),classEdges:[],su:q,blockFinished:q,queue:[]})(h),P=ad(G.classEdges)(G.sink)(f),et=(C,D,W,M)=>{const Y=tt(D)(M),X=tt(D)(s);return(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;c()})()+(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;c()})()+d(C,D,W)},K=be($(C=>x(C,!0))(Pn(E.compare)((()=>{const C=(D,W)=>{if(D.tag==="Leaf")return W;if(D.tag==="Node")return C(D._5,It("Cons",D._4,C(D._6,W)));c()};return wt(qt.foldr,C(a.root,Bt))})()))),A=C=>D=>W=>{const M=L(W,{su:D.su,blockFinished:K}),Y={phase:C,ppFree:W.free,ppIsRoot:W.isRoot,edgeId:T,delta:0,avail:0,shift:0,freeSu:(()=>{const X=tt((()=>{const V=tt(W.free)(a.root);if(V.tag==="Nothing")return W.free;if(V.tag==="Just")return V._1;c()})())(D.su);if(X.tag==="Nothing")return!1;if(X.tag==="Just")return X._1;c()})(),hasEdges:M.hasEdges,candCount:(()=>{if(W.isRoot){if(g==="HRight"){const X=tt(W.free)(N);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length;c()}if(g==="HLeft"){const X=tt(W.free)(v);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length}c()}if(g==="HRight"){const X=tt(W.free)(v);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length;c()}if(g==="HLeft"){const X=tt(W.free)(N);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length}c()})()};if(M.edge.tag==="Nothing")return{...D,stack:[...D.stack,W],trace:[...D.trace,Y],x:D.x};if(M.edge.tag==="Just"){const X=M.edge._1.from.node===W.free?x(M.edge._1.from.node,M.edge._1.to.node):x(M.edge._1.to.node,M.edge._1.from.node),V=et(M.edge._1,X._1,l(M.edge._1,X._1),D.x)-et(M.edge._1,X._2,l(M.edge._1,X._2),D.x),Q=tt(X._1)(a.root),I=(()=>{if(Q.tag==="Nothing")return X._1;if(Q.tag==="Just")return Q._1;c()})(),U={...Y,edgeId:k("Just",M.edge._1.id),delta:V};if(V>0&&V<1e300){const O=y(at=>lt=>{const Tt=tt(lt)(m),Gt=(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._1;c()})();if(Gt>=0&&Gt<n.length){const mt=n[Gt],ft=tt(lt)(t.nodeIndex),rt=(()=>{if(ft.tag==="Nothing")return-2;if(ft.tag==="Just")return ft._1-1|0;c()})();return rt>=0&&rt<mt.length?Le(at)((()=>{const nt=tt(lt)(D.x),st=tt(lt)(s),yt=tt(mt[rt])(D.x),Jt=tt(mt[rt])(s);return(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;c()})()-((()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;c()})()+p(mt[rt])+J(lt,mt[rt]))})()):at}const dt=tt(lt)(t.nodeIndex),Mt=(()=>{if(dt.tag==="Nothing")return-2;if(dt.tag==="Just")return dt._1-1|0;c()})();return Mt>=0&&Mt<0?Le(at)((()=>{const mt=tt(lt)(D.x),ft=tt(lt)(s),rt=tt([][Mt])(D.x),nt=tt([][Mt])(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})()+(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;c()})()-((()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+p([][Mt])+J(lt,[][Mt]))})()):at})(V)(Nr(a)(I)),gt=O>0?-O:0,pt={...D,x:O>0?_(I,gt,D.x):D.x,trace:[...D.trace,{...U,avail:O,shift:gt}]};return O>0?pt:{...pt,stack:[...pt.stack,W]}}if(V<0&&-V<1e300){const O=y(at=>lt=>{const Tt=tt(lt)(m),Gt=(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._1;c()})();if(Gt>=0&&Gt<n.length){const mt=n[Gt],ft=tt(lt)(t.nodeIndex),rt=(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1+1|0;c()})();return rt>=0&&rt<mt.length?Le(at)((()=>{const nt=tt(mt[rt])(D.x),st=tt(mt[rt])(s),yt=tt(lt)(D.x),Jt=tt(lt)(s);return(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;c()})()-((()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;c()})()+p(lt)+J(lt,mt[rt]))})()):at}const dt=tt(lt)(t.nodeIndex),Mt=(()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1+1|0;c()})();return Mt>=0&&Mt<0?Le(at)((()=>{const mt=tt([][Mt])(D.x),ft=tt([][Mt])(s),rt=tt(lt)(D.x),nt=tt(lt)(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})()+(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;c()})()-((()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+p(lt)+J(lt,[][Mt]))})()):at})(-V)(Nr(a)(I)),gt=O>0?O:0,pt={...D,x:O>0?_(I,gt,D.x):D.x,trace:[...D.trace,{...U,avail:O,shift:gt}]};return O>0?pt:{...pt,stack:[...pt.stack,W]}}return{...D,stack:[...D.stack,W],trace:[...D.trace,U],x:D.x}}c()},H=y(A(ud))({x:be($(C=>x(C,(()=>{const D=tt(C)(a.root),W=(()=>{if(D.tag==="Nothing")return C;if(D.tag==="Just")return D._1;c()})(),M=tt(W)(G.x),Y=tt((()=>{const V=tt(W)(G.sink);if(V.tag==="Nothing")return W;if(V.tag==="Just")return V._1;c()})())(P),X=(()=>{if(M.tag==="Just")return M._1;if(M.tag==="Nothing")return T;c()})();return(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;c()})()+(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;c()})()})()))(w)),su:G.su,stack:[],trace:[]})(G.queue),R=y(A(sd))({...H,stack:[]})(_e(H.stack));return{x:R.x,queue:G.queue,trace:R.trace}},_d=e=>t=>n=>r=>o=>i=>u=>s=>a=>f=>g=>gd(e)(t)(n)(r)(o)(i)(u)(s)(a)(f)(g).x,dd=e=>t=>n=>r=>o=>i=>{const u=(a,f,g)=>{const d=tt(f)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;c()})(),_=a.from.node===f?a.from.port:a.to.node===f?a.to.port:T;if(_.tag==="Just"){const h=tt(f)(t);if(h.tag==="Just"){const p=fe(m=>m.id===_._1)(h._1);if(p.tag==="Just"){const m=_t(p._1.offset)*_t(4);return g==="North"||g==="South"?m:0}if(p.tag==="Nothing"){const m=Hn(o)(a.id)(g)(l);return g==="North"||g==="South"?m:0}c()}if(h.tag==="Nothing"){const p=Hn(o)(a.id)(g)(l);return g==="North"||g==="South"?p:0}c()}if(_.tag==="Nothing"){const h=Hn(o)(a.id)(g)(l);return g==="North"||g==="South"?h:0}c()},s=a=>f=>g=>d=>{let l=a,_=f,h=g,p=d,m=!0,J;for(;m;){const N=l,v=_,w=h,b=Vt(L=>T,L=>S=>k("Just",{head:L,tail:S}),p);if(b.tag==="Nothing"){m=!1,J=N;continue}if(b.tag==="Just"){const L=b._1.head,S=fe(F=>F.from.node===w&&F.to.node===L||F.from.node===L&&F.to.node===w)(r),z=(()=>{if(S.tag==="Nothing")return v+0;if(S.tag==="Just")return v+(u(S._1,w,S._1.from.node===w?se:ue)-u(S._1,L,S._1.from.node===L?se:ue));c()})();l=Z(E)(L)(z)(N),_=z,h=L,p=b._1.tail;continue}c()}return J};return y(a=>f=>{const g=Vt(_=>T,_=>h=>k("Just",{head:_,tail:h}),Nr(e)(f)),d=(()=>{if(g.tag==="Nothing")return Z(E)(f)(0)(q);if(g.tag==="Just")return s(Z(E)(g._1.head)(0)(q))(0)(g._1.head)(g._1.tail);c()})(),l=y(_=>h=>Be(_)(-h._2))(0)(Jr(d));return y(_=>h=>Z(E)(h._1)(h._2+l)(_))(a)(Jr(d))})(q)(Pn(E.compare)((()=>{const a=(f,g)=>{if(f.tag==="Leaf")return g;if(f.tag==="Node")return a(f._5,It("Cons",f._4,a(f._6,g)));c()};return wt(qt.foldr,a(e.root,Bt))})()))},ld=e=>t=>n=>r=>o=>{const i=Ne(t),u=y(s=>a=>{const f=y(g=>d=>{const l=(()=>{if(o==="HRight"){const m=tt(d)(e.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;c()}if(o==="HLeft"){const m=tt(d)(e.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}c()})(),_=l.length;if(_===0)return g;const h=bn(_-1|0,2),p=bn(_,2);return y(m=>J=>{if((()=>{const N=tt(d)(m.align);if(N.tag==="Nothing")return d!==d;if(N.tag==="Just")return N._1!==d;c()})())return m;if(J>=0&&J<l.length){const N=tt(l[J])(e.nodeIndex),v=(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})();if(!(qs(l[J]+"\u2192"+d)(n)||qs(d+"\u2192"+l[J])(n))&&(()=>{if(r==="VDown")return m.r<v;if(r==="VUp")return m.r>v;c()})()){const w=tt(l[J])(m.root),b=(()=>{if(w.tag==="Nothing")return l[J];if(w.tag==="Just")return w._1;c()})();return{root:Z(E)(d)(b)(m.root),align:Z(E)(l[J])(d)(Z(E)(d)(b)(m.align)),r:v}}}return m})(g)((()=>{if(r==="VDown")return Ht(h,p);if(r==="VUp")return _e(Ht(h,p));c()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;c()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return _e(a);c()})());return{root:f.root,align:f.align}})({root:be($(s=>x(s,s))(i)),align:be($(s=>x(s,s))(i))})((()=>{if(o==="HRight")return t;if(o==="HLeft")return _e(t);c()})());return{root:u.root,align:u.align}},oo=e=>t=>n=>r=>o=>i=>u=>s=>a=>f=>{const g=ld(t)(n)(s)(a)(f),d=dd(g)(o)(r)(i)(u)(f);return Hf()(l=>_=>k("Just",(()=>{const h=tt(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;c()})()))(_d(e)(t)(n)(r)(o)(i)(u)(d)(g)(a)(f))},Os=e=>t=>Dt(n=>r=>y(o=>i=>i>=0&&i<t.length?i>=0&&i<e.length?o+t[i]+e[i]:o+t[i]+0:i>=0&&i<e.length?o+1+e[i]:o+1)(0)((()=>{const o=Ht(0,t.length-1|0);return n<1?[]:Wt(0,n,o)})()))(t),hd=e=>t=>n=>r=>o=>i=>u=>{const s=od(0)(t.length-1|0),a=_t(e.layerGap),f=u(kf(s,a)),g=p1(Ms(o)(f)(r)(i)(q))(f);return $(d=>{const l=id(d)(g);return l.tag==="Just"&&l._1>0?Be(a)(2+_t(l._1-1|0)*2.5):a})(Ht(0,s-1|0))},Xs=e=>t=>n=>r=>Su(o=>y(i=>u=>{if(!i.ok)return i;const s=tt(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})(),f=tt(u)(n),g=(()=>{if(f.tag==="Nothing")return a+1;if(f.tag==="Just")return a+f._1._1;c()})();return a+1e-4>i.pos&&g+1e-4>i.pos?{ok:!0,pos:g}:{ok:!1,pos:i.pos}})({ok:!0,pos:-1e18})(o).ok,t),pd=e=>t=>n=>r=>{const o=xt(i=>u=>ht.compare(i.w)(u.w))($(i=>({l:i,w:$s(i)}))(ct(Xs()(t)(n),r)));return 0<o.length?k("Just",o[0].l):T},md=e=>t=>{const n=be(Ne($(Dt(o=>i=>x(i,o)))(e))),r=o=>xt(i=>u=>it.compare((()=>{const s=tt(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})())((()=>{const s=tt(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(o);return{preds:(()=>{const o=i=>{if(i.tag==="Leaf")return q;if(i.tag==="Node")return $t("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));c()};return o(y(i=>u=>vt(E)(ie)(u.to.node)([u.from.node])(i))(q)(t))})(),succs:(()=>{const o=i=>{if(i.tag==="Leaf")return q;if(i.tag==="Node")return $t("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));c()};return o(y(i=>u=>vt(E)(ie)(u.from.node)([u.to.node])(i))(q)(t))})(),nodeIndex:n}},yd=e=>t=>{const n=xt(d=>l=>ht.compare(d.w)(l.w))(Dt(d=>l=>({i:d,l,w:$s(l)}))(t)),r=0<n.length?k("Just",n[0]):T,o=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;c()})(),i=o>=0&&o<t.length?k("Just",t[o]):T,u=(()=>{if(i.tag==="Just")return(d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const J=_,N=h;if(N.tag==="Nil"){p=!1,m=J;continue}if(N.tag==="Cons"){_=Le(J)(N._1),h=N._2;continue}c()}return m})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,It("Cons",l._4,d(l._6,_)));c()};return d(i._1,Bt)})());if(i.tag==="Nothing")return 0;c()})(),s=d=>y(l=>_=>Be(l)((()=>{const h=tt(_._1)(e);if(h.tag==="Nothing")return _._2+1;if(h.tag==="Just")return _._2+h._1._1;c()})()))(-999999)(Jr(d)),a=o>=0&&o<t.length?k("Just",t[o]):T,f=(()=>{if(a.tag==="Just")return s(a._1);if(a.tag==="Nothing")return 0;c()})(),g=pe(d=>l=>{const _=h=>{if(h.tag==="Leaf")return q;if(h.tag==="Node")return $t("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));c()};return _(d)},t,Dt(d=>l=>Po(d)(2)===0?u-(_=>h=>{let p=_,m=h,J=!0,N;for(;J;){const v=p,w=m;if(w.tag==="Nil"){J=!1,N=v;continue}if(w.tag==="Cons"){p=Le(v)(w._1),m=w._2;continue}c()}return N})(999999)((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,It("Cons",h._4,_(h._6,p)));c()};return _(l,Bt)})()):f-s(l))(t));return cd(y(d=>l=>{const _=xt(ht.compare)(bt(tt(l))(g));return Z(E)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(q)(Pn(E.compare)(Ne($(d=>{const l=_=>{if(_.tag==="Leaf")return q;if(_.tag==="Node")return $t("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));c()};return wt(we.foldr,l(d))})(g)))))},Jd=e=>t=>n=>r=>o=>i=>{const u=md(t)(o),s=fd(u)(t),a={nodeGap:e.nodeGap*4|0},f=ye(E.compare,he,be($(_=>x(_,x(0,1)))(ct(_=>oe(3)(_)==="$d:",Ne(t)))),(()=>{const _=h=>{if(h.tag==="Leaf")return q;if(h.tag==="Node")return $t("Node",h._1,h._2,h._3,x(h._4._1*_t(4),h._4._2),_(h._5),_(h._6));c()};return _(n)})()),g=[oo(a)(u)(t)(f)(r)(o)(i)(s)(Hs)(Ys),oo(a)(u)(t)(f)(r)(o)(i)(s)(Vs)(Ys),oo(a)(u)(t)(f)(r)(o)(i)(s)(Hs)(Fs),oo(a)(u)(t)(f)(r)(o)(i)(s)(Vs)(Fs)],d=yd(f)(g);if(Xs()(t)(f)(d))return d;const l=pd()(t)(f)(g);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return g[0];c()},Nd=e=>t=>n=>r=>{const o=bf(T,uc,i=>i.node===t?k("Just",i.position):T,e);if(o.tag==="Nothing")return e;if(o.tag==="Just"){const i=o._1;return $(u=>u.node===n?{...u,position:x(i._1+r._1,i._2+r._2)}:u)(e)}c()},xd=e=>t=>n=>r=>{const o=ct(u=>ze(Ye)(u.node)(t),e),i=(()=>{if(n==="Vertical"){if(r==="Start")return y(u=>s=>Le(u)(s.position._1))(99999)(o);if(r==="End")return y(u=>s=>Be(u)(s.position._1))(0)(o);if(r==="Center"){const u=y(s=>a=>s+a.position._1)(0)(o);return o.length===0?0:u/_t(o.length)}c()}if(n==="Horizontal"){if(r==="Start")return y(u=>s=>Le(u)(s.position._2))(99999)(o);if(r==="End")return y(u=>s=>Be(u)(s.position._2))(0)(o);if(r==="Center"){const u=y(s=>a=>s+a.position._2)(0)(o);return o.length===0?0:u/_t(o.length)}}c()})();return $(u=>{if(ze(Ye)(u.node)(t)){if(n==="Vertical")return{...u,position:x(i,u.position._2)};if(n==="Horizontal")return{...u,position:x(u.position._1,i)};c()}return u})(e)},vd=e=>t=>y(n=>r=>{if(r.tag==="Lock"){const o=r._1.node,i=r._1.position;return $(u=>u.node===o?{...u,position:i}:u)(n)}return r.tag==="AlignGroup"?xd(n)($(bu)(r._1.nodes))(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?Nd(n)(r._1.anchor)(r._1.target)(r._1.offset):n})(t)(e),Td=e=>t=>n=>r=>o=>i=>u=>s=>{const a=be($(_=>x(_._1,_._2))(Jr(r))),f=$($(bu))(n),g=$(_=>y(h=>p=>Be(h)((()=>{const m=tt(p)(a);if(m.tag==="Nothing")return 1;if(m.tag==="Just")return m._1._2;c()})()))(1)(_))(f),d=Jd(e)(f)(a)(be($(_=>x(_._1,_._2))(Jr(o))))(i)(s),l=Os(hd(e)(n)(r)(o)(i)(u)(_=>{const h=Os(_)(g);return Ne(Dt(p=>m=>Dt(J=>N=>({node:N,position:x((()=>{const v=tt(N)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;c()})()/_t(4)})(),p>=0&&p<h.length?h[p]:0),size:(()=>{const v=oe(3)(N)==="$d:"?x(0,1):x(1,1),w=tt(N)(a);if(w.tag==="Nothing")return v;if(w.tag==="Just")return w._1;c()})(),layer:p,order:J}))(m))(f))}))(g);return vd(t)(Ne(Dt(_=>h=>Dt(p=>m=>({node:m,position:x((()=>{const J=tt(m)(d);return(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;c()})()/_t(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const J=oe(3)(m)==="$d:"?x(0,1):x(1,1),N=tt(m)(a);if(N.tag==="Nothing")return J;if(N.tag==="Just")return N._1;c()})(),layer:_,order:p}))(h))(f)))},Di=ui(Hr)(pn(32)),Us=ui(Hr)(pn(31)),xr=(()=>{const e=ug("25214903917");if(e.tag==="Nothing")return Au;if(e.tag==="Just")return e._1;c()})(),vr=ii(ui(Hr)(pn(48)))(Hr),wd=e=>{const t=sg(e);return gr(Qu((()=>{if(t.tag==="Nothing")return Au;if(t.tag==="Just")return t._1;c()})())(xr))(vr)},Wi=pn(11),io=e=>t=>{const n=gr(Qr(qr(t)(xr))(Wi))(vr);return x((()=>{const r=Ju(ng(si(n)(pn(48-e|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;c()})(),n)},Ld=e=>{const t=io(26)(e),n=io(27)(t._2);return x((_t(t._1)*Co(2)(27)+_t(n._1))/Co(2)(53),n._2)},Ed=e=>t=>{const n=y(r=>o=>{const i=Ld(r.finalR);return{rs:[...r.rs,i._1],finalR:i._2}})({rs:[],finalR:e})(t);return x($(r=>r.x)(xt(r=>o=>ht.compare(r.k)(o.k))(pe(r=>o=>({x:r,k:o}),t,n.rs))),n.finalR)},kd=e=>{const t=gr(Qr(qr(e)(xr))(Wi))(vr),n=gr(Qr(qr(t)(xr))(Wi))(vr);return x(Qr(qr((()=>{const r=si(t)(pn(16));return qu.compare(r)(Us)!=="LT"?ii(r)(Di):r})())(Di))((()=>{const r=si(n)(pn(16));return qu.compare(r)(Us)!=="LT"?ii(r)(Di):r})()),n)},Tr=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},uo=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},Mi=jt(E)(zt),Ae=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},so=jt(E)(zt),bd=wc(Do),Cd=y(er)(0),Sd=e=>t=>{const n=it.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Ks=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},Pd=e=>t=>n=>r=>o=>Mi(y(i=>u=>{const s=xt(a=>f=>it.compare((()=>{const g=Tr(a.id)(o);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;c()})())((()=>{const g=Tr(f.id)(o);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;c()})()))(ct(a=>uo(a.to.node)(n),ct(a=>a.from.node===u,r)));return{ranks:[...i.ranks,...Dt(a=>f=>x(f.id,_t((i.rankSum+a|0)+1|0)))(s)],rankSum:i.rankSum+s.length|0}})({ranks:[],rankSum:0})(e).ranks),Gd=e=>t=>n=>r=>o=>Mi(y(i=>u=>{const s=xt(f=>g=>{const d=it.compare((()=>{const l=Ae(g.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Ae(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})());return d==="EQ"?it.compare((()=>{const l=Tr(f.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Tr(g.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})()):d})(ct(f=>uo(f.from.node)(n),ct(f=>f.to.node===u,r))),a=s.length;return{ranks:[...i.ranks,...Dt(f=>g=>x(g.id,_t((i.rankSum+a|0)-f|0)))(s)],rankSum:i.rankSum+a|0}})({ranks:[],rankSum:0})(e).ranks),Ri=e=>t=>n=>{const r=so(Dt(s=>a=>x(a,s))(e)),o=so(Dt(s=>a=>x(a,s))(t)),i=bt(s=>{const a=Ae(s.from.node)(r),f=Ae(s.to.node)(o);if(a.tag==="Just"&&f.tag==="Just")return k("Just",x(a._1,f._1));const g=Ae(s.from.node)(o),d=Ae(s.to.node)(r);return g.tag==="Just"&&d.tag==="Just"?k("Just",x(d._1,g._1)):T})(n),u=i.length;return y(s=>a=>y(f=>g=>a>=0&&a<i.length&&g>=0&&g<i.length&&((i[a]._1-i[g]._1|0)*(i[a]._2-i[g]._2|0)|0)<0?f+1|0:f)(s)(Ht(a+1|0,u-1|0)))(0)(Ht(0,u-2|0))},Dd=e=>t=>n=>r=>o=>{const i=u=>s=>{let a=u,f=s,g=!0,d;for(;g;){const l=a,_=f;if(_>=(l.length-1|0)){g=!1,d=l;continue}const h=_>=0&&_<l.length?k("Just",l[_]):T,p=_+1|0;if(p>=0&&p<l.length&&h.tag==="Just"){const m=h._1,J=l[p];if(on(b=>b.before===m&&b.after===J,o)){a=l,f=_+1|0;continue}if((()=>{const b=Ae(m)(e),L=Ae(J)(e);return b.tag==="Just"&&L.tag==="Just"&&b._1<L._1})()){a=l,f=_+1|0;continue}const N=ur(Kt,T,_,J,l),v=(()=>{if(N.tag==="Just")return ur(Kt,T,_+1|0,m,N._1);if(N.tag==="Nothing")return T;c()})(),w=(()=>{if(v.tag==="Nothing")return l;if(v.tag==="Just")return v._1;c()})();if(Ri(n)(w)(r)<Ri(n)(l)(r)){a=w,f=_+1|0;continue}a=l,f=_+1|0;continue}g=!1,d=l}return d};return(u=>{let s=u,a=!0,f;for(;a;){const g=s,d=i(g)(0);if(bd(d)(g)){a=!1,f=g;continue}s=d}return f})(t)},ao=e=>t=>y(n=>r=>{if(r>=0&&r<e.length){const o=e[r],i=r+1|0;if(i>=0&&i<e.length)return n+Ri(o)(e[i])(t)|0}return n})(0)(Ht(0,e.length-2|0)),Wd=e=>t=>n=>{const r=bt(f=>f.tag==="OrderConstraint"?k("Just",{before:f._1.before,after:f._1.after}):T)(e.constraints),o=f=>y(g=>d=>{const l=d.after,_=d.before,h=ir(Kt,T,m=>m===_,g),p=ir(Kt,T,m=>m===l,g);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=Cu(Kt,T,h._1,g),J=(()=>{if(m.tag==="Nothing")return g;if(m.tag==="Just")return m._1;c()})(),N=Sf(Kt,T,p._1,_,J);if(N.tag==="Nothing")return J;if(N.tag==="Just")return N._1;c()}return g})(f)(r),i=Mi(Dt(f=>g=>x(g.id,f))(n)),u=(f,g,d)=>{const l=f.length;return y(_=>h=>{const p=g?h-1|0:h+1|0,m=p>=0&&p<_._1.length?k("Just",_._1[p]):T;if(m.tag==="Just"){const J=h>=0&&h<_._1.length?k("Just",_._1[h]):T;if(J.tag==="Just"){const N=so(Dt(S=>z=>x(z,S))(m._1)),v=so(Dt(S=>z=>x(z,S))(J._1)),w=g?Pd(m._1)(N)(v)(n)(i):Gd(m._1)(N)(v)(n)(i),b=y(S=>z=>{const F=bt(G=>Tr(G.id)(w))(ct(g?G=>G.to.node===z._2&&uo(G.from.node)(N):G=>G.from.node===z._2&&uo(G.to.node)(N),n));if(F.length===0)return{...S,items:[...S.items,{n:z._2,key:T,origIdx:z._1}]};const j=io(24)(S.r);return{items:[...S.items,{n:z._2,key:k("Just",(Cd(F)+(_t(j._1)*4172325152040912e-24-.03500000014901161))/_t(F.length)),origIdx:z._1}],r:j._2}})({items:[],r:_._2})(Dt(Sn)(J._1)),L=ur(Kt,T,h,Dd(e.modelOrder)(o($(S=>S.n)(xt(S=>z=>{const F=Ae(S.n)(e.modelOrder),j=Ae(z.n)(e.modelOrder);if(F.tag==="Just"&&j.tag==="Just"){const G=it.compare(F._1)(j._1);return G==="EQ"?ht.compare(S.key)(z.key):G}return ht.compare(S.key)(z.key)})((()=>{const S=b.items,z=F=>j=>{let G=F,P=j,et=!0,K;for(;et;){const A=G,H=P;if(A>=0&&A<S.length){if(S[A].key.tag==="Just"){et=!1,K=S[A].key._1;continue}if(S[A].key.tag==="Nothing"){G=A+1|0,P=H;continue}c()}et=!1,K=H}return K};return(F=>j=>G=>{let P=F,et=j,K=G,A=!0,H;for(;A;){const R=P,C=et,D=K;if(R>=0&&R<S.length){if(S[R].key.tag==="Just"){P=R+1|0,et=S[R].key._1,K=[...D,{n:S[R].n,key:S[R].key._1,origIdx:S[R].origIdx}];continue}if(S[R].key.tag==="Nothing"){const W=(C+z(R+1|0)(C+1))/2;P=R+1|0,et=W,K=[...D,{n:S[R].n,key:W,origIdx:S[R].origIdx}];continue}c()}A=!1,H=D}return H})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(L.tag==="Just")return x(L._1,b.r);if(L.tag==="Nothing")return x(_._1,_._2);c()}if(J.tag==="Nothing")return x(_._1,_._2);c()}if(m.tag==="Nothing")return x(_._1,_._2);c()})(x(f,d))(g?Ht(1,l-1|0):_e(Ht(0,l-2|0)))},s=y(f=>g=>Z(E)(g.from.node)()(Z(E)(g.to.node)()(f)))(q)(n),a=y(f=>g=>{if(f.result.crossings===0)return f;const d=N=>v=>w=>b=>{let L=N,S=v,z=w,F=b,j=!0,G;for(;j;){const P=L,et=S,K=z,A=F;if(K===0){j=!1,G={layout:P,crossings:0,random:A};continue}const H=u(P,et,A),R=ao(H._1)(n);if(R<K){L=H._1,S=!et,z=R,F=H._2;continue}j=!1,G={layout:P,crossings:K,random:H._2}}return G},l=io(1)(f.result.random),_=l._1!==0,h=e.modelOrder.tag==="Leaf",p=(f.firstTry||f.secondTry)&&!h?f.firstTry:_,m=(()=>{if(!h){const b=u(t,p,l._2);return d(b._1)(!p)(ao(b._1)(n))(b._2)}const N=p?0:Sd(0)(t.length-1|0),v=N>=0&&N<t.length?k("Just",t[N]):T;if(v.tag==="Just"&&v._1.length>1){const b=ct(L=>Ks(L)(s),v._1);if(b.length>1){const L=Ed(l._2)(b),S=L._1,z=ur(Kt,T,N,o(y(F=>j=>Ks(j)(s)?F.idx>=0&&F.idx<S.length?{idx:F.idx+1|0,result:[...F.result,S[F.idx]]}:{idx:F.idx,result:[...F.result,j]}:{idx:F.idx,result:[...F.result,j]})({idx:0,result:[]})(v._1).result),t);if(z.tag==="Just"){const F=u(z._1,p,L._2);return d(F._1)(!p)(ao(F._1)(n))(F._2)}}}const w=u(t,p,l._2);return d(w._1)(!p)(ao(w._1)(n))(w._2)})(),J=f.secondTry?!1:f.secondTry;return f.firstTry?{result:m.crossings<f.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...f.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<f.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...f.result,random:m.random},firstTry:f.firstTry,secondTry:J}})({result:{layout:t,crossings:1e9,random:gr(Qu(kd(wd(1))._1)(xr))(vr)},firstTry:e.modelOrder.tag!=="Leaf",secondTry:!1})(Ht(1,e.iterations)).result;return t.length<=0||e.iterations<=0?t:a.layout},Md=e=>e,Zs=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},le=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Vn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},wr=(()=>{const e={eq:t=>n=>t._1===n._1&&t._2===n._2};return{compare:t=>n=>{const r=E.compare(t._1)(n._1);return r==="LT"?Re:r==="GT"?Ie:E.compare(t._2)(n._2)},Eq0:()=>e}})(),Rd=jt(E)(zt),Id=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=wr.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},zd=Md("Greedy"),Ii=e=>t=>n=>y(r=>o=>{if(o.from.node===o.to.node)return r;if(o.from.node===t&&!Zs(o.to.node)(r.marks)){const i=le(o.to.node)(r.inDeg),u=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;c()})(),s=Z(E)(o.to.node)(u)(r.inDeg);return(()=>{const a=le(o.to.node)(r.outDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;c()})()&&!ze(Ye)(o.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,o.to.node]}:{...r,inDeg:s}}if(o.to.node===t&&!Zs(o.from.node)(r.marks)){const i=le(o.from.node)(r.outDeg),u=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;c()})(),s=Z(E)(o.from.node)(u)(r.outDeg);return(()=>{const a=le(o.from.node)(r.inDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;c()})()&&!ze(Ye)(o.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,o.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:ct(r=>r!==t,n.remaining)})(e),Bd=y(e=>t=>{if(t.tag==="LayerConstraint"){if(t._1.pin.tag==="SpecificLayer")return Z(E)(t._1.node)(t._1.pin._1)(e);if(t._1.pin.tag==="FirstLayer")return Z(E)(t._1.node)(0)(e);if(t._1.pin.tag==="LastLayer")return Z(E)(t._1.node)(99999)(e)}return e})(q),js=e=>t=>n=>{const r=le(t)(e),o=le(n)(e);return r.tag==="Just"&&o.tag==="Just"&&r._1>o._1},ta=e=>t=>n=>r=>{if(Vn(n)(r.visited)||Vn(n)(r.visiting))return r;const o=y(Ad(e)(t)(n))({...r,visiting:Z(E)(n)()(r.visiting)})((()=>{const i=le(n)(t);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;c()})());return{...o,visiting:sr(E)(n)(o.visiting),visited:Z(E)(n)()(o.visited)}},Ad=e=>t=>n=>r=>o=>js(e)(n)(o)?{...r,backEdges:Z(wr)(x(n,o))()(r.backEdges)}:Vn(o)(r.visiting)?{...r,backEdges:Z(wr)(x(n,o))()(r.backEdges)}:Vn(o)(r.visited)?r:ta(e)(t)(o)(r),Qd=e=>t=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,J=Vt(N=>T,N=>v=>k("Just",{head:N,tail:v}),m.sinks);if(J.tag==="Just"){_=Ii(n)(J._1.head)({...m,sinks:J._1.tail,marks:Z(E)(J._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(J.tag==="Nothing"){const N=Vt(v=>T,v=>w=>k("Just",{head:v,tail:w}),m.sources);if(N.tag==="Just"){_=Ii(n)(N._1.head)({...m,sources:N._1.tail,marks:Z(E)(N._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(N.tag==="Nothing"){const v=b=>{const L=le(b)(m.outDeg),S=le(b)(m.inDeg);return(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;c()})()-(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;c()})()|0},w=xt(b=>L=>{const S=it.compare(v(L))(v(b));return S==="EQ"?it.compare((()=>{const z=le(b)(t);if(z.tag==="Nothing")return 1e6;if(z.tag==="Just")return z._1;c()})())((()=>{const z=le(L)(t);if(z.tag==="Nothing")return 1e6;if(z.tag==="Just")return z._1;c()})()):S})(m.remaining);if(0<w.length){const b=w[0];_=Ii(n)(b)({...m,remaining:ct(L=>L!==b,m.remaining),marks:Z(E)(b)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}c()}return p},o=Pn(E.compare)([...$(l=>l.from.node)(n),...$(l=>l.to.node)(n)]),i=ct(l=>l.from.node!==l.to.node,n),u=y(l=>_=>vt(E)(Ut)(_.to.node)(1)(l))(q)(i),s=y(l=>_=>vt(E)(Ut)(_.from.node)(1)(l))(q)(i),a=ct(l=>{const _=le(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;c()},o),f=ct(l=>{const _=le(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;c()},o),g=o.length+1|0,d=y(l=>_=>{const h=le(_)(l);return h.tag==="Just"&&h._1<0?Z(E)(_)(h._1+g|0)(l):l})(r({remaining:ct(l=>!ze(Ye)(l)(a)&&!ze(Ye)(l)(f),o),marks:q,inDeg:u,outDeg:s,sources:a,sinks:f,nextLeft:1,nextRight:-1}).marks)(o);return y(l=>_=>{if(_.from.node===_.to.node)return l;if(js(e)(_.from.node)(_.to.node))return Z(wr)(x(_.from.node,_.to.node))()(l);const h=le(_.from.node)(d),p=le(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?Z(wr)(x(_.from.node,_.to.node))()(l):l})(q)(n)},qd=y(e=>t=>vt(E)(ie)(t.from.node)([t.to.node])(e))(q),Hd=e=>t=>{const n=qd(t),r=Pn(E.compare)([...$(i=>i.from.node)(t),...$(i=>i.to.node)(t)]),o=y(i=>u=>Z(E)(u.to.node)()(i))(q)(t);return y(i=>u=>ta(e)(n)(u)(i))({visiting:q,visited:q,backEdges:q})([...ct(i=>!Vn(i)(o),r),...ct(i=>Vn(i)(o),r)]).backEdges},Vd=e=>t=>n=>r=>{const o=Rd(Dt(s=>a=>x(a,s))(t)),i=Bd(n),u=(()=>{if(e==="DepthFirst")return Hd(i)(r);if(e==="Greedy")return Qd(i)(o)(r);c()})();return{edges:$(s=>Id(x(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},ea=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Yd=e=>t=>n=>y(r=>o=>{const i=ea(o.from.node)(e),u=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;c()})(),s=ea(o.to.node)(e),a=(()=>{if(s.tag==="Nothing")return-u;if(s.tag==="Just")return s._1-u|0;c()})();if(a<=1)return{...r,edges:[...r.edges,o],chains:[...r.chains,{edgeId:o.id,nodes:[o.from.node,o.to.node]}]};const f=o.id,g=$(l=>"$d:"+f+":"+Te(l))(Ht(1,a-1|0)),d=[o.from.node,...g,o.to.node];return{...r,layers:y(l=>_=>{const h=_._2,p=Wf(u+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;c()})(r.layers)(pe(Sn,Ht(1,a-1|0),g)),edges:[...r.edges,...pe(l=>_=>({id:f+":"+l+"->"+_,from:{node:l,port:o.from.port},to:{node:_,port:o.to.port}}),d,Wt(1,d.length,d))],chains:[...r.chains,{edgeId:o.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(t),zi=e=>t=>{const n=it.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},ae=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},Yt=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Lr=e=>t=>{const n=it.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},xn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=it.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},co=jt(E)(zt),Yn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=it.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Fd=(()=>{const e={eq:n=>r=>n.delta===r.delta&&n.eid===r.eid&&n.src===r.src&&n.tgt===r.tgt&&n.weight===r.weight},t={compare:n=>r=>{const o=it.compare(n.delta)(r.delta);if(o==="LT"||o==="GT"||o!=="EQ")return o;const i=it.compare(n.eid)(r.eid);if(i==="LT"||i==="GT"||i!=="EQ")return i;const u=E.compare(n.src)(r.src);if(u==="LT"||u==="GT"||u!=="EQ")return u;const s=E.compare(n.tgt)(r.tgt);if(s==="LT"||s==="GT"||s!=="EQ")return s;const a=it.compare(n.weight)(r.weight);return a==="LT"||a==="GT"||a!=="EQ"?a:Ve},Eq0:()=>e};return y(n=>r=>Z(t)(r)()(n))(q)})(),$d=y(e=>t=>Z(E)(t)()(e))(q),Od=jt(it)(zt),Xd=e=>t=>ye(E.compare,he,e,t),Ud=e=>y(t=>n=>({base:(()=>{const r=o=>i=>{let u=o,s=i,a=!0,f;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,f=g;continue}if(d.tag==="Cons"){u=zi(g)(d._1),s=d._2;continue}c()}return f};return(t.base+r(0)((()=>{const o=(i,u)=>{if(i.tag==="Leaf")return u;if(i.tag==="Node")return o(i._5,It("Cons",i._4,o(i._6,u)));c()};return o(n,Bt)})())|0)+1|0})(),result:[...t.result,(()=>{if(t.base===0)return n;const r=o=>{if(o.tag==="Leaf")return q;if(o.tag==="Node")return $t("Node",o._1,o._2,o._3,o._4+t.base|0,r(o._5),r(o._6));c()};return r(n)})()]}))({base:0,result:[]})(e).result,Kd=e=>t=>{const n=i=>{let u=i,s=!0,a;for(;s;){const f=u,g=Vt(d=>T,d=>l=>k("Just",{head:d,tail:l}),f.queue);if(g.tag==="Nothing"){s=!1,a=f;continue}if(g.tag==="Just"){if(ae(g._1.head)(f.removedNodes)){u={...f,queue:g._1.tail};continue}const d=fe(l=>!ae(l.src+"\u2192"+l.tgt)(f.removedEdges)&&(l.src===g._1.head||l.tgt===g._1.head))(t);if(d.tag==="Nothing"){u={...f,queue:g._1.tail};continue}if(d.tag==="Just"){const l=d._1.src===g._1.head?d._1.tgt:d._1.src,_={...f,degree:Z(E)(l)((()=>{const h=Yt(l)(f.degree);if(h.tag==="Nothing")return-1;if(h.tag==="Just")return h._1-1|0;c()})())(f.degree),removedNodes:Z(E)(g._1.head)()(f.removedNodes),removedEdges:Z(E)(d._1.src+"\u2192"+d._1.tgt)()(f.removedEdges),record:[...f.record,{node:g._1.head,neighbour:l,viaSrc:d._1.src===g._1.head}],queue:g._1.tail};if((()=>{const h=Yt(l)(_.degree);return(()=>{if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1===1;c()})()&&!ae(l)(_.removedNodes)})()){u={..._,queue:[..._.queue,l]};continue}u=_;continue}}c()}return a},r=y(i=>u=>vt(E)(Ut)(u.src)(1)(vt(E)(Ut)(u.tgt)(1)(i)))(q)(t),o=n({degree:r,removedNodes:q,removedEdges:q,record:[],queue:ct(i=>{const u=Yt(i)(r);if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1===1;c()},e)});return{coreNodes:ct(i=>!ae(i)(o.removedNodes),e),coreEdges:ct(i=>!ae(i.src+"\u2192"+i.tgt)(o.removedEdges),t),removed:o.record}},Zd=e=>t=>y(n=>r=>{const o=Yt(r.neighbour)(n),i=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;c()})();return Z(E)(r.node)(r.viaSrc?i-1|0:i+1|0)(n)})(t)(_e(e)),na=e=>t=>n=>{const r=y(i=>u=>{const s=na(e)(u.src===t?u.tgt:u.src)({...i.st,edgeVisited:Z(it)(u.eid)()(i.st.edgeVisited)});return{lowest:Lr(i.lowest)(s.lowest),st:s.st}})({lowest:1e9,st:n})(ct(i=>xn(i.eid)(n.treeEdge)&&(i.src===t||i.tgt===t)&&!xn(i.eid)(n.edgeVisited),e)),o=Lr(r.lowest)(r.st.postOrder);return{lowest:o,st:{...r.st,poID:Z(E)(t)(r.st.postOrder)(r.st.poID),lowestPoID:Z(E)(t)(o)(r.st.lowestPoID),postOrder:r.st.postOrder+1|0}}},ra=e=>t=>n=>na(t)(0<e.length?e[0]:"")({...n,edgeVisited:q,postOrder:1,poID:q,lowestPoID:q}).st,oa=e=>t=>{const n=y(r=>o=>Lr(r)((()=>{const i=Yt(o)(t);if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;c()})()))(1e9)(e);return co($(r=>x(r,(()=>{const o=Yt(r)(t);if(o.tag==="Nothing")return-n;if(o.tag==="Just")return o._1-n|0;c()})()))(e))},Bi=e=>t=>{const n=Yt(t)(e.poID);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;c()},ia=e=>t=>{const n=Yt(t)(e.lowestPoID);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;c()},jd=e=>t=>fe(n=>{const r=Yn(n.eid)(t.cutvalue);return xn(n.eid)(t.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<0;c()})()})(e),xe=e=>t=>{const n=Yt(t)(e.layer);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;c()},tl=e=>t=>y(n=>r=>{if(ae(r.src)(t.treeNode)===ae(r.tgt)(t.treeNode))return n;const o=(xe(t)(r.tgt)-xe(t)(r.src)|0)-r.delta|0;return o<n.slack?{edge:k("Just",r),slack:o}:n})({edge:T,slack:1e9})(e).edge,Ai=e=>t=>n=>{const r={...n,treeNode:Z(E)(t)()(n.treeNode)};return y(o=>i=>{if(xn(i.eid)(o.st.edgeVisited))return o;const u={...o.st,edgeVisited:Z(it)(i.eid)()(o.st.edgeVisited)},s=(ae(i.src)(u.treeNode)&&!ae(i.tgt)(u.treeNode)?i.src===i.src:ae(i.tgt)(u.treeNode)&&!ae(i.src)(u.treeNode)?i.src===i.tgt:i.src===i.src)?i.tgt:i.src;if(xn(i.eid)(u.treeEdge)){if(ae(s)(u.treeNode))return{...o,st:u};const a=Ai(e)(s)(u);return{count:o.count+a.count|0,st:a.st}}if(!ae(s)(u.treeNode)&&i.delta===(xe(u)(i.tgt)-xe(u)(i.src)|0)){const a=Ai(e)(s)({...u,treeEdge:Z(it)(i.eid)()(u.treeEdge)});return{count:o.count+a.count|0,st:a.st}}return{...o,st:u}})({count:1,st:r})(ct(o=>(o.src===t||o.tgt===t)&&!xn(o.eid)(r.edgeVisited),e))},fo=e=>t=>n=>{const r=Bi(e)(n.src),o=Bi(e)(n.tgt),i=Bi(e)(t);return ia(e)(n.src)<=i&&i<=r&&ia(e)(n.tgt)<=i&&i<=o?r>=o:r<o},el=e=>t=>({layer:co($(n=>x(n,0))(e)),treeNode:q,treeEdge:q,poID:q,lowestPoID:q,cutvalue:q,postOrder:1,edgeVisited:q}),nl=e=>t=>n=>ct(r=>xn(r.eid)(t.treeEdge)&&(r.src===n||r.tgt===n),e),rl=e=>t=>n=>{let r=e,o=t,i=n,u=!0,s;for(;u;){const a=r,f=o,g=i,d=Ai(f)(0<a.length?a[0]:"")({...g,edgeVisited:q,treeNode:q,treeEdge:q});if(d.count>=a.length){u=!1,s=d.st;continue}const l=tl(f)(d.st);if(l.tag==="Nothing"){u=!1,s=d.st;continue}if(l.tag==="Just"){const _=(xe(d.st)(l._1.tgt)-xe(d.st)(l._1.src)|0)-l._1.delta|0,h=ae(l._1.tgt)(d.st.treeNode)?-_:_;r=a,o=f,i={...d.st,layer:y(p=>m=>ae(m)(d.st.treeNode)?Z(E)(m)(xe(d.st)(m)+h|0)(p):p)(d.st.layer)(a)};continue}c()}return s},ol=e=>t=>n=>y(r=>o=>{if(fo(n)(o.src)(t)&&!fo(n)(o.tgt)(t)){const i=(xe(n)(o.tgt)-xe(n)(o.src)|0)-o.delta|0;if(i<r.slack)return{edge:k("Just",o),slack:i}}return r})({edge:T,slack:1e9})(e).edge,il=e=>t=>{const n=y(o=>i=>vt(E)(ie)(i.tgt)([i.src])(vt(E)(ie)(i.src)([i.tgt])(o)))(q)(t),r=o=>i=>u=>{let s=o,a=i,f=u,g=!0,d;for(;g;){const l=s,_=a,h=f,p=Vt(m=>T,m=>J=>k("Just",{head:m,tail:J}),l);if(p.tag==="Nothing"){g=!1,d={nodes:h};continue}if(p.tag==="Just"){if(ae(p._1.head)(_)){s=p._1.tail,a=_,f=h;continue}s=[...p._1.tail,...(()=>{const m=Yt(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;c()})()],a=Z(E)(p._1.head)()(_),f=[...h,p._1.head];continue}c()}return d};return y(o=>i=>{if(ae(i)(o.visited))return o;const u=r([i])(o.visited)([]);return{...o,visited:y(s=>a=>Z(E)(a)()(s))(o.visited)(u.nodes),components:[...o.components,u.nodes]}})({visited:q,components:[]})(e).components},ul=e=>t=>n=>r=>{const o=r.tgt,i=r.src;return y(u=>s=>{if((()=>{const a=Yn(s.eid)(t.cutvalue);if(a.tag==="Just")return!0;if(a.tag==="Nothing")return!1;c()})()){const a=Yn(s.eid)(t.cutvalue),f=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()})();return i===s.src||o===s.tgt?u-(f-s.weight|0)|0:u+(f-s.weight|0)|0}return n===i?s.src===n?u+s.weight|0:u-s.weight|0:s.src===n?u-s.weight|0:u+s.weight|0})(r.weight)(ct(u=>u.eid!==r.eid&&(u.src===n||u.tgt===n),e))},sl=e=>t=>n=>(r=>o=>{let i=r,u=o,s=!0,a;for(;s;){const f=i,g=u,d=Yt(g)(f.unknown),l=(()=>{if(d.tag==="Nothing")return[];if(d.tag==="Just")return d._1;c()})();if(l.length===1){const _=l[0].src===g?l[0].tgt:l[0].src;i={unknown:(()=>{const h=Yt(_)(f.unknown),p=(()=>{if(h.tag==="Just")return Z(E)(_)(ct(J=>J.eid!==l[0].eid,h._1))(f.unknown);if(h.tag==="Nothing")return f.unknown;c()})(),m=Yt(g)(p);if(m.tag==="Just")return Z(E)(g)(ct(J=>J.eid!==l[0].eid,m._1))(p);if(m.tag==="Nothing")return p;c()})(),cutvalue:Z(it)(l[0].eid)(ul(e)(f)(g)(l[0]))(f.cutvalue)},u=_;continue}s=!1,a=f}return a})(t)(n),ua=e=>t=>n=>{const r={unknown:co($(o=>x(o,wt(we.foldr,Fd(nl(t)(n)(o)))))(e)),cutvalue:q};return{...n,cutvalue:y(sl(t))(r)(ct(o=>{const i=Yt(o)(r.unknown);if(i.tag==="Nothing")return!1;if(i.tag==="Just")return i._1.length===1;c()},e)).cutvalue}},al=e=>t=>n=>r=>o=>{const i={...o,treeEdge:Z(it)(r.eid)()(sr(it)(n.eid)(o.treeEdge))},u=(xe(i)(r.tgt)-xe(i)(r.src)|0)-r.delta|0,s=fo(i)(r.tgt)(n)?-u:u;return ua(e)(t)(ra(e)(t)({...i,layer:y(a=>f=>fo(i)(f)(n)?a:Z(E)(f)(xe(i)(f)+s|0)(a))(i.layer)(e)}))},cl=e=>t=>n=>r=>(o=>i=>{let u=o,s=i,a=!0,f;for(;a;){const g=u,d=s;if(g===0){a=!1,f=d;continue}const l=jd(n)(d);if(l.tag==="Nothing"){a=!1,f=d;continue}if(l.tag==="Just"){const _=ol(n)(l._1)(d);if(_.tag==="Nothing"){a=!1,f=d;continue}if(_.tag==="Just"){u=g-1|0,s=al(t)(n)(l._1)(_._1)(d);continue}}c()}return f})(e)(r),fl=e=>t=>n=>ua(e)(t)(ra(e)(t)(rl(e)(t)(n))),sa=e=>y(t=>n=>vt(E)(ie)(e(n))([n])(t))(q),gl=e=>t=>n=>{const r=u=>s=>a=>f=>{let g=u,d=s,l=a,_=f,h=!0,p;for(;h;){const m=g,J=d,N=l,v=_,w=Vt(b=>T,b=>L=>k("Just",{head:b,tail:L}),N);if(w.tag==="Nothing"){h=!1,p=v;continue}if(w.tag==="Just"){const b=xe(v)(w._1.head),L=y(S=>z=>{const F=Yt(z.tgt)(S.incident),j=(()=>{if(F.tag==="Nothing")return-1;if(F.tag==="Just")return F._1-1|0;c()})();return{st:{...S.st,layer:Z(E)(z.tgt)(zi(xe(S.st)(z.tgt))(b+z.delta|0))(S.st.layer)},incident:Z(E)(z.tgt)(j)(S.incident),queue:j===0?[...S.queue,z.tgt]:S.queue}})({st:v,incident:J,queue:w._1.tail})((()=>{const S=Yt(w._1.head)(m);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;c()})());g=m,d=L.incident,l=L.queue,_=L.st;continue}c()}return p},o=sa(u=>u.tgt)(t),i=co($(u=>x(u,(()=>{const s=Yt(u)(o);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.length;c()})()))(e));return r(sa(u=>u.src)(t))(i)(ct(u=>{const s=Yt(u)(i);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;c()},e))(n)},aa=e=>t=>{const n=Dt(o=>i=>({src:i.src,tgt:i.tgt,delta:1,weight:1,eid:o}))(t),r=gl(e)(n)(el(e)(n));return n.length===0?r.layer:cl(4*e.length|0)(e)(n)(fl(e)(n)(r)).layer},_l=e=>t=>{const n=$d(e),r=ct(i=>ae(i.src)(n)&&ae(i.tgt)(n),t);if(e.length<40)return oa(e)(aa(e)(r));const o=Kd(e)(r);return oa(e)(Zd(o.removed)(aa(o.coreNodes)(o.coreEdges)))},dl=e=>t=>n=>{const r=y(i=>u=>vt(E)(Ut)(u.tgt)(1)(i))(q)(t),o=y(i=>u=>vt(E)(Ut)(u.src)(1)(i))(q)(t);return y(i=>u=>{const s=Yt(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})();if((()=>{const N=Yt(u)(o);return(()=>{if(N.tag==="Nothing")return a!==0;if(N.tag==="Just")return a!==N._1;c()})()||a===0})())return i;const f=Yt(u)(i.layers),g=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;c()})(),d=i.layers,l=y(N=>v=>v.tgt===u?{...N,mIn:Lr(N.mIn)((()=>{const w=Yt(u)(d),b=Yt(v.src)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;c()})()|0})())}:v.src===u?{...N,mOut:Lr(N.mOut)((()=>{const w=Yt(v.tgt)(d),b=Yt(u)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;c()})()|0})())}:N)({mIn:1e9,mOut:1e9})(t),_=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(_<0||h<0)return i;const p=(g-_|0)+1|0,m=(g+h|0)-1|0;if(m<p)return i;const J=y(N=>v=>{const w=Yn(v)(i.filling),b=(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})();return b<N.bestFill?{best:v,bestFill:b}:N})({best:g,bestFill:(()=>{const N=Yn(g)(i.filling);if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})()})(Ht(p,m));return J.best===g?i:{layers:Z(E)(u)(J.best)(i.layers),filling:Z(it)(g)((()=>{const N=Yn(g)(i.filling);if(N.tag==="Nothing")return-1;if(N.tag==="Just")return N._1-1|0;c()})())(Z(it)(J.best)(J.bestFill+1|0)(i.filling))}})({layers:n,filling:Od($(i=>x(i,y(u=>s=>(()=>{const a=Yt(s)(n);return a.tag==="Nothing"?!1:a.tag==="Just"&&a._1===i})()?u+1|0:u)(0)(e)))(Ht(0,y(i=>u=>zi(i)((()=>{const s=Yt(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(0)(e))))})(e).layers},ll=e=>t=>dl(e)(Dt(n=>r=>({src:r.src,tgt:r.tgt,delta:1,weight:1,eid:n}))(t))(y(Xd)(q)(Ud($(n=>_l(n)(t))(il(e)(t))))),hl=e=>e,vn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},go=e=>t=>{const n=it.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},ca=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),pl=hl("NetworkSimplex"),ml=e=>t=>y(n=>r=>{const o=y(go)(0)(bt(i=>vn(i)(n))(r));return y(i=>u=>Z(E)(u)(o)(i))(n)(r)})(t)(e),yl=e=>t=>({layers:$(n=>ct(r=>{const o=vn(r)(t);return o.tag==="Nothing"?!1:o.tag==="Just"&&o._1===n},e))(Ht(0,(n=>r=>{let o=n,i=r,u=!0,s;for(;u;){const a=o,f=i;if(f.tag==="Nil"){u=!1,s=a;continue}if(f.tag==="Cons"){o=go(a)(f._1),i=f._2;continue}c()}return s})(0)((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._4,n(r._6,o)));c()};return n(t,Bt)})()))),nodeLayer:t}),Jl=e=>t=>n=>{const r=y(o=>i=>Z(E)(i)(!0)(o))(q)(t);return y(o=>i=>Z(E)(i._1)(i._2)(o))(ll(t)(bt(o=>o.from.node===o.to.node||(()=>{const i=vn(o.from.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;c()})()||(()=>{const i=vn(o.to.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;c()})()?T:k("Just",{src:o.from.node,tgt:o.to.node}))(e)))(ca(n))},Nl=e=>t=>n=>r=>{const o=s=>a=>{const f=vn(a)(s);if(f.tag==="Just")return s;if(f.tag==="Nothing"){const g=ct(l=>l!==a,(()=>{const l=vn(a)(e);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;c()})()),d=y(o)(s)(g);return Z(E)(a)(1+y(go)(0)(bt(l=>vn(l)(d))(g))|0)(d)}c()},i=y(o)(q)(n),u=(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){f=go(_)(h._1),g=h._2;continue}c()}return l})(1)((()=>{const s=(a,f)=>{if(a.tag==="Leaf")return f;if(a.tag==="Node")return s(a._5,It("Cons",a._4,s(a._6,f)));c()};return s(i,Bt)})());return y(s=>a=>Z(E)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return q;if(a.tag==="Node")return $t("Node",a._1,a._2,a._3,u-a._4|0,s(a._5),s(a._6));c()};return s(i)})())(ca(r))},xl=y(e=>t=>{if(t.tag==="LayerConstraint"){if(t._1.pin.tag==="SpecificLayer")return Z(E)(t._1.node)(t._1.pin._1)(e);if(t._1.pin.tag==="FirstLayer")return Z(E)(t._1.node)(0)(e)}return e})(q),vl=y(e=>t=>vt(E)(ie)(t.to.node)([t.from.node])(e))(q),Tl=y(e=>t=>vt(E)(ie)(t.from.node)([t.to.node])(e))(q),wl=e=>t=>n=>r=>{const o=Tl(n),i=vl(n),u=xl(t);return yl(r)(ml(bt(s=>s.tag==="SameLayer"?k("Just",s._1.nodes):T)(t))((()=>{if(e==="LongestPath")return Nl(o)(i)(r)(u);if(e==="NetworkSimplex")return Jl(n)(r)(u);c()})()))},Ll=jt(E)(zt),El=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},fa=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},ga=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Er=jt(E)(zt),kl=jt(E)(zt),_a=(()=>{const e=$(t=>({start:t.end,end:t.start,direction:t.direction}));return t=>_e(e(t))})(),bl=e=>t=>n=>r=>{const o=Ll($(u=>x(u.edge,u))(r)),i=u=>0<u.nodes.length&&(()=>{const s=El(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return $(u=>{if(u.nodes.length<=2){const g=fa(u.edgeId)(o);if(g.tag==="Just"){const d=i(u);return{...g._1,edge:u.edgeId,segments:d?_a(g._1.segments):g._1.segments,reversed:d}}if(g.tag==="Nothing")return{edge:u.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};c()}const s=St(bt(g=>fa(g)(o))(pe(g=>d=>u.edgeId+":"+g+"->"+d,u.nodes,Wt(1,u.nodes.length,u.nodes))))(g=>g.segments),a=i(u),f=bi(a?_a(s):s);return{edge:u.edgeId,segments:f,bends:pe(g=>d=>g.end,f,Wt(1,f.length,f)),bendType:[],jumps:[],reversed:a}})(e)},Cl={layers:[],edges:[],chains:[]},Sl={nodeGap:3,layerGap:2,iterations:8,layerer:pl,cycleBreaker:zd},Pl=e=>({pos:x(0,0),size:x(y(t=>n=>ga(t)(n.position._1+n.size._1))(0)(e),y(t=>n=>ga(t)(n.position._2+n.size._2))(0)(e))}),Gl=e=>t=>{const n=ct(i=>oe(3)(i.node)!=="$d:",t.placements),r=bl(t.withDummies.chains)(t.acyclic.reversedEdges)(kl($(i=>x(i.id,x(i.from.node,i.to.node)))(e.edges)))(Y1(t.withDummies.edges)(t.placements)(Er($(i=>x(i.id,i.ports))(e.nodes)))(t.withDummies.chains)(zs(t.ordered)(ct(i=>i.from.node!==i.to.node,t.withDummies.edges))((()=>{const i=u=>{if(u.tag==="Leaf")return q;if(u.tag==="Node")return $t("Node",u._1,u._2,u._3,x(u._4._1*4,u._4._2),i(u._5),i(u._6));c()};return i(Er($(u=>x(u.id,u.size))(e.nodes)))})()))),o=Dt(i=>u=>({...u,jumps:Z1(i)(u)(r)}))(r);return{nodes:n,edges:o,boundingBox:Pl(n),metrics:_1(n)(o)(0)}},Dl=e=>t=>n=>{const r=Er($(i=>x(i.id,i.size))(t.nodes)),o={...n,placements:Td({nodeGap:e.nodeGap,layerGap:e.layerGap})(t.constraints)(n.ordered)(r)(Er($(i=>x(i.id,i.ports))(t.nodes)))(n.withDummies.edges)(n.withDummies.chains)(zs(n.ordered)(n.withDummies.edges)((()=>{const i=u=>{if(u.tag==="Leaf")return q;if(u.tag==="Node")return $t("Node",u._1,u._2,u._3,x(u._4._1*4,u._4._2),i(u._5),i(u._6));c()};return i(r)})()))};return{pipeline:o,result:Gl(t)(o)}},Wl=e=>t=>n=>Dl(e)(t)({...n,ordered:Wd({iterations:e.iterations,constraints:t.constraints,modelOrder:Er(Dt(r=>o=>x(o.id,r))(t.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),Ml=e=>t=>n=>Wl(e)(t)({...n,withDummies:Yd(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),Rl=e=>t=>{const n=$(o=>o.id)(t.nodes),r=Vd(e.cycleBreaker)(n)(t.constraints)(t.edges);return Ml(e)(t)({acyclic:r,layered:wl(e.layerer)(t.constraints)(r.edges)(n),withDummies:Cl,ordered:[],placements:[]})},Il=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},zl=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},da=jt(E)(zt),Bl=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},Al=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},Ql=y(e=>t=>Z(E)(t)()(e))(q),ql=y(e=>t=>Z(E)(t)()(e))(q),Hl=Ir.traverse(Eu),Qi=jt(E)(zt),Vl=e=>t=>n=>{const r=fe(o=>o.id===n)(e.graph.edges);if(r.tag==="Just")return k("Just",r._1);if(r.tag==="Nothing")return Il(n)(t);c()},Yl=e=>t=>n=>({x:n.position._1*e,y:n.position._2*e,w:n.size._1*e,h:n.size._2*e,label:(()=>{const r=zl(n.node)(t);if(r.tag==="Just")return r._1;if(r.tag==="Nothing")return n.node;c()})()}),Fl=e=>({id:e,size:x(1,1),ports:[],label:k("Just",e)}),$l=e=>t=>n=>x(n.node,Yl(e)(t)(n)),Ol=e=>da(bt(t=>k("Just",x(t.edge,{id:t.edge,from:{node:t.from,port:T},to:{node:t.to,port:T}})))(St(e.scenes)(t=>t.tag==="DataFlow"?bt(n=>n.kind.tag==="SendToken"?k("Just",n.kind._1):T)(t._1.events):[]))),la=e=>{const t=dg(e),n=ct(o=>Bl(o.id)(t.nodes),e.graph.nodes),r=ct(o=>Al(o.id)(t.edges),e.graph.edges);return{nodes:[...n,...$(Fl)(wt(we.foldr,Fe(E.compare,t.nodes,Ql($(o=>o.id)(n)))))],edges:[...r,...bt(Vl(e)(Ol(e)))(wt(we.foldr,Fe(E.compare,t.edges,ql($(o=>o.id)(r)))))],constraints:e.graph.constraints}},Xl=e=>{const t=Hl(n=>{const r=n1("Ilisarniq, ui-sans-serif, system-ui, sans-serif")(11)("500")(ys((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;c()})()));return()=>{const o=r();return x(n.id,o)}})(la(e).nodes);return()=>{const n=t();return Qi(n)}},Ul=e=>t=>{const n=Vt(r=>T,r=>o=>k("Just",{head:r,tail:o}),t.segments);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{x:n._1.head.start._1*e,y:n._1.head.start._2*e},...$(r=>({x:r.end._1*e,y:r.end._2*e}))([n._1.head,...n._1.tail])];c()},Kl=e=>t=>x(t.edge,Ul(e)(t)),Zl=e=>t=>n=>({nodes:Qi($($l(_t(4)*e)(t))(n.nodes)),edges:da($(Kl(e))(n.edges)),chipExtras:q}),jl=_t(4)*8,t0=e=>t=>{const n=c1(jl)(e)(a1(s1)(la(t)));return Zl(8)(Qi($(r=>x(r.id,(()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;c()})()))(n.nodes)))(Rl(Sl)(n).result)};(function(){var e={},t="Pure",n="Throw",r="Catch",o="Sync",i="Async",u="Bind",s="Bracket",a="Fork",f="Sequential",g="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",J="Finalized",N="Forked";function v(M,Y,X,V){this.tag=M,this._1=Y,this._2=X,this._3=V}function w(M){var Y=function(X,V,Q){return new v(M,X,V,Q)};return Y.tag=M,Y}function b(M){return new v(t,void 0)}function L(M){try{M()}catch(Y){setTimeout(function(){throw Y},0)}}function S(M,Y,X){try{return Y(X())}catch(V){return M(V)}}function z(M,Y,X){try{return Y(X)()}catch(V){return X(M(V))(),b}}var F=(function(){var M=1024,Y=0,X=0,V=new Array(M),Q=!1;function I(){var U;for(Q=!0;Y!==0;)Y--,U=V[X],V[X]=void 0,X=(X+1)%M,U();Q=!1}return{isDraining:function(){return Q},enqueue:function(U){var O;Y===M&&(O=Q,I(),Q=O),V[(X+Y)%M]=U,Y++,Q||I()}}})();function j(M){var Y={},X=0,V=0;return{register:function(Q){var I=X++;Q.onComplete({rethrow:!0,handler:function(U){return function(){V--,delete Y[I]}}})(),Y[I]=Q,V++},isEmpty:function(){return V===0},killAll:function(Q,I){return function(){if(V===0)return I();var U=0,O={};function gt(at){O[at]=Y[at].kill(Q,function(lt){return function(){delete O[at],U--,M.isLeft(lt)&&M.fromLeft(lt)&&setTimeout(function(){throw M.fromLeft(lt)},0),U===0&&I()}})()}for(var pt in Y)Y.hasOwnProperty(pt)&&(U++,gt(pt));return Y={},X=0,V=0,function(at){return new v(o,function(){for(var lt in O)O.hasOwnProperty(lt)&&O[lt]()})}}}}}var G=0,P=1,et=2,K=3,A=4,H=5,R=6;function C(M,Y,X){var V=0,Q=G,I=X,U=null,O=null,gt=null,pt=null,at=null,lt=0,Tt=0,Gt=null,dt=!0;function Mt(nt){for(var st,yt,Jt;;)switch(st=null,yt=null,Jt=null,Q){case et:Q=P;try{I=gt(I),pt===null?gt=null:(gt=pt._1,pt=pt._2)}catch(Qt){Q=H,U=M.left(Qt),I=null}break;case K:M.isLeft(I)?(Q=H,U=I,I=null):gt===null?Q=H:(Q=et,I=M.fromRight(I));break;case P:switch(I.tag){case u:gt&&(pt=new v(_,gt,pt)),gt=I._2,Q=P,I=I._1;break;case t:gt===null?(Q=H,I=M.right(I._1)):(Q=et,I=I._1);break;case o:Q=K,I=S(M.left,M.right,I._1);break;case i:Q=A,I=z(M.left,I._1,function(Qt){return function(){V===nt&&(V++,F.enqueue(function(){V===nt+1&&(Q=K,I=Qt,Mt(V))}))}});return;case n:Q=H,U=M.left(I._1),I=null;break;case r:gt===null?at=new v(_,I,at,O):at=new v(_,I,new v(_,new v(h,gt,pt),at,O),O),gt=null,pt=null,Q=P,I=I._1;break;case s:lt++,gt===null?at=new v(_,I,at,O):at=new v(_,I,new v(_,new v(h,gt,pt),at,O),O),gt=null,pt=null,Q=P,I=I._1;break;case a:Q=K,st=C(M,Y,I._2),Y&&Y.register(st),I._1&&st.run(),I=M.right(st);break;case f:Q=P,I=W(M,Y,I._1);break}break;case H:if(gt=null,pt=null,at===null)Q=R,I=O||U||I;else switch(st=at._3,Jt=at._1,at=at._2,Jt.tag){case r:O&&O!==st&&lt===0?Q=H:U&&(Q=P,I=Jt._2(M.fromLeft(U)),U=null);break;case h:O&&O!==st&&lt===0||U?Q=H:(gt=Jt._1,pt=Jt._2,Q=et,I=M.fromRight(I));break;case s:lt--,U===null&&(yt=M.fromRight(I),at=new v(_,new v(p,Jt._2,yt),at,st),(O===st||lt>0)&&(Q=P,I=Jt._3(yt)));break;case p:at=new v(_,new v(J,I,U),at,O),Q=P,O&&O!==st&&lt===0?I=Jt._1.killed(M.fromLeft(O))(Jt._2):U?I=Jt._1.failed(M.fromLeft(U))(Jt._2):I=Jt._1.completed(M.fromRight(I))(Jt._2),U=null,lt++;break;case m:lt++,at=new v(_,new v(J,I,U),at,O),Q=P,I=Jt._1;break;case J:lt--,Q=H,I=Jt._1,U=Jt._2;break}break;case R:for(var Ct in Gt)Gt.hasOwnProperty(Ct)&&(dt=dt&&Gt[Ct].rethrow,L(Gt[Ct].handler(I)));Gt=null,O&&U?setTimeout(function(){throw M.fromLeft(U)},0):M.isLeft(I)&&dt&&setTimeout(function(){if(dt)throw M.fromLeft(I)},0);return;case G:Q=P;break;case A:return}}function mt(nt){return function(){if(Q===R)return dt=dt&&nt.rethrow,nt.handler(I)(),function(){};var st=Tt++;return Gt=Gt||{},Gt[st]=nt,function(){Gt!==null&&delete Gt[st]}}}function ft(nt,st){return function(){if(Q===R)return st(M.right(void 0))(),function(){};var yt=mt({rethrow:!1,handler:function(){return st(M.right(void 0))}})();switch(Q){case G:O=M.left(nt),Q=R,I=O,Mt(V);break;case A:O===null&&(O=M.left(nt)),lt===0&&(Q===A&&(at=new v(_,new v(m,I(nt)),at,O)),Q=H,I=null,U=null,Mt(++V));break;default:O===null&&(O=M.left(nt)),lt===0&&(Q=H,I=null,U=null)}return yt}}function rt(nt){return function(){var st=mt({rethrow:!1,handler:nt})();return Q===G&&Mt(V),st}}return{kill:ft,join:rt,onComplete:mt,isSuspended:function(){return Q===G},run:function(){Q===G&&(F.isDraining()?Mt(V):F.enqueue(function(){Mt(V)}))}}}function D(M,Y,X,V){var Q=0,I={},U=0,O={},gt=new Error("[ParAff] Early exit"),pt=null,at=e;function lt(mt,ft,rt){var nt=ft,st=null,yt=null,Jt=0,Ct={},Qt,ne;t:for(;;)switch(Qt=null,nt.tag){case N:if(nt._3===e&&(Qt=I[nt._1],Ct[Jt++]=Qt.kill(mt,function(He){return function(){Jt--,Jt===0&&rt(He)()}})),st===null)break t;nt=st._2,yt===null?st=null:(st=yt._1,yt=yt._2);break;case g:nt=nt._2;break;case d:case l:st&&(yt=new v(_,st,yt)),st=nt,nt=nt._1;break}if(Jt===0)rt(M.right(void 0))();else for(ne=0,Qt=Jt;ne<Qt;ne++)Ct[ne]=Ct[ne]();return Ct}function Tt(mt,ft,rt){var nt,st,yt,Jt,Ct,Qt;for(M.isLeft(mt)?(nt=mt,st=null):(st=mt,nt=null);;){if(yt=null,Jt=null,Ct=null,Qt=null,pt!==null)return;if(ft===null){V(nt||st)();return}if(ft._3!==e)return;switch(ft.tag){case g:nt===null?(ft._3=M.right(ft._1(M.fromRight(st))),st=ft._3):ft._3=nt;break;case d:if(yt=ft._1._3,Jt=ft._2._3,nt){if(ft._3=nt,Ct=!0,Qt=U++,O[Qt]=lt(gt,nt===yt?ft._2:ft._1,function(){return function(){delete O[Qt],Ct?Ct=!1:rt===null?Tt(nt,null,null):Tt(nt,rt._1,rt._2)}}),Ct){Ct=!1;return}}else{if(yt===e||Jt===e)return;st=M.right(M.fromRight(yt)(M.fromRight(Jt))),ft._3=st}break;case l:if(yt=ft._1._3,Jt=ft._2._3,yt===e&&M.isLeft(Jt)||Jt===e&&M.isLeft(yt))return;if(yt!==e&&M.isLeft(yt)&&Jt!==e&&M.isLeft(Jt))nt=st===yt?Jt:yt,st=null,ft._3=nt;else if(ft._3=st,Ct=!0,Qt=U++,O[Qt]=lt(gt,st===yt?ft._2:ft._1,function(){return function(){delete O[Qt],Ct?Ct=!1:rt===null?Tt(st,null,null):Tt(st,rt._1,rt._2)}}),Ct){Ct=!1;return}break}rt===null?ft=null:(ft=rt._1,rt=rt._2)}}function Gt(mt){return function(ft){return function(){delete I[mt._1],mt._3=ft,Tt(ft,mt._2._1,mt._2._2)}}}function dt(){var mt=P,ft=X,rt=null,nt=null,st,yt;t:for(;;)switch(st=null,yt=null,mt){case P:switch(ft.tag){case g:rt&&(nt=new v(_,rt,nt)),rt=new v(g,ft._1,e,e),ft=ft._2;break;case d:rt&&(nt=new v(_,rt,nt)),rt=new v(d,e,ft._2,e),ft=ft._1;break;case l:rt&&(nt=new v(_,rt,nt)),rt=new v(l,e,ft._2,e),ft=ft._1;break;default:yt=Q++,mt=H,st=ft,ft=new v(N,yt,new v(_,rt,nt),e),st=C(M,Y,st),st.onComplete({rethrow:!1,handler:Gt(ft)})(),I[yt]=st,Y&&Y.register(st)}break;case H:if(rt===null)break t;rt._1===e?(rt._1=ft,mt=P,ft=rt._2,rt._2=e):(rt._2=ft,ft=rt,nt===null?rt=null:(rt=nt._1,nt=nt._2))}for(at=ft,yt=0;yt<Q;yt++)I[yt].run()}function Mt(mt,ft){pt=M.left(mt);var rt;for(var nt in O)if(O.hasOwnProperty(nt)){rt=O[nt];for(nt in rt)rt.hasOwnProperty(nt)&&rt[nt]()}O=null;var st=lt(mt,at,ft);return function(yt){return new v(i,function(Jt){return function(){for(var Ct in st)st.hasOwnProperty(Ct)&&st[Ct]();return b}})}}return dt(),function(mt){return new v(i,function(ft){return function(){return Mt(mt,ft)}})}}function W(M,Y,X){return new v(i,function(V){return function(){return D(M,Y,X,V)}})}return v.EMPTY=e,v.Pure=w(t),v.Throw=w(n),v.Catch=w(r),v.Sync=w(o),v.Async=w(i),v.Bind=w(u),v.Bracket=w(s),v.Fork=w(a),v.Seq=w(f),v.ParMap=w(g),v.ParApply=w(d),v.ParAlt=w(l),v.Fiber=C,v.Supervisor=j,v.Scheduler=F,v.nonCanceler=b,v})();let qi=null;function e0(){return qi||(typeof document>"u"?null:(qi=document.createElement("canvas").getContext("2d"),qi))}const ha=new Map,n0=e=>t=>n=>r=>{const o=`${n} ${t}px ${e}|${r}`,i=ha.get(o);if(i!==void 0)return i;const u=e0();if(!u)return r.length*t*.62;u.font=`${n} ${t}px ${e}`;const s=u.measureText(r).width;return ha.set(o,s),s},r0=e=>()=>e.clip("evenodd"),o0=e=>t=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(t.tile,.001))),r=Math.max(2,Math.round(t.tile*n)),o=document.createElement("canvas");o.width=r,o.height=r;const i=o.getContext("2d");i.scale(n,n),i.fillStyle=t.bgCss,i.fillRect(0,0,t.tile,t.tile),i.fillStyle=t.dotCss,i.beginPath(),i.arc(t.tile/2,t.tile/2,t.dotR,0,2*Math.PI),i.fill();const u=e.createPattern(o,"repeat");u&&typeof u.setTransform=="function"&&u.setTransform(new DOMMatrix().scaleSelf(1/n,1/n)),e.save(),e.fillStyle=u,e.fillRect(t.vx,t.vy,t.vw,t.vh),e.restore()},i0=e=>t=>n=>r=>o=>i=>()=>{if(typeof e.roundRect=="function")e.roundRect(t,n,r,o,i);else{const u=Math.min(i,r/2,o/2);e.moveTo(t+u,n),e.lineTo(t+r-u,n),e.quadraticCurveTo(t+r,n,t+r,n+u),e.lineTo(t+r,n+o-u),e.quadraticCurveTo(t+r,n+o,t+r-u,n+o),e.lineTo(t+u,n+o),e.quadraticCurveTo(t,n+o,t,n+o-u),e.lineTo(t,n+u),e.quadraticCurveTo(t,n,t+u,n),e.closePath()}},u0=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Hi=e=>t=>n=>{const r=t.stroke;return()=>{const o=r.value,i=zc(e)(n);if(o!==n)return i(),t.stroke.value=n}},s0=e=>t=>n=>{const r=t.font;return()=>{const o=r.value,i=Xc(e)(n);if(o!==n)return i(),t.font.value=n}},kr=e=>t=>n=>{const r=t.fill;return()=>{const o=r.value,i=Ic(e)(n);if(o!==n)return i(),t.fill.value=n}},_o=e=>t=>{const n=t.length,r=i=>{if(i>=n)return()=>{};const u=i>=0&&i<t.length?t[i]:0;if(u===1){const s=Hc(e)((()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})())((()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()),a=r(i+3|0);return()=>(s(),a())}if(u===2){const s=qc(e)((()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})())((()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})()),a=r(i+3|0);return()=>(s(),a())}if(u===3){const s=Kc(e)({cpx:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),cpy:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})(),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=r(i+5|0);return()=>(s(),a())}if(u===4){const s=Zc(e)({cp1x:(()=>{const f=i+1|0;return f>=0&&f<t.length?t[f]:0})(),cp1y:(()=>{const f=i+2|0;return f>=0&&f<t.length?t[f]:0})(),cp2x:(()=>{const f=i+3|0;return f>=0&&f<t.length?t[f]:0})(),cp2y:(()=>{const f=i+4|0;return f>=0&&f<t.length?t[f]:0})(),x:(()=>{const f=i+5|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=i+6|0;return f>=0&&f<t.length?t[f]:0})()}),a=r(i+7|0);return()=>(s(),a())}if(u===5){const s=Vc(e),a=r(i+1|0);return()=>(s(),a())}return()=>{}},o=xu(e);return()=>(o(),r(0)())},a0=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),c0=e=>t=>{const n=Fc(e)({x:0,y:0,width:t.width,height:t.height});return()=>{n();const r=a0();return{ctx:e,surface:t,styleCache:r,maskDepth:{value:0}}}},f0={map:e=>t=>n=>{const r=t(n);return()=>{const o=r();return e(o)}}},g0=e=>Te(e.weight)+" "+fu(e.size)+"px Ilisarniq, ui-sans-serif, system-ui, sans-serif",Qe=e=>{const t=fu(_t(e.a)/255);return e.a>=255?"rgb("+Te(e.r)+","+Te(e.g)+","+Te(e.b)+")":"rgba("+Te(e.r)+","+Te(e.g)+","+Te(e.b)+","+t+")"},_0=e=>t=>n=>r=>{const o=kr(e)(n)(Qe(r));return()=>(o(),Yc(e)({x:0,y:0,width:t.width,height:t.height})())},d0=e=>t=>n=>{const r=t.font;return()=>(r.value="",t.fill.value="",t.stroke.value="",o0(e)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:Qe(n.bgColor),dotCss:Qe(n.dotColor),tile:n.tile,dotR:n.dotRadius})())},l0=e=>t=>n=>r=>{const o=kr(e)(t)(Qe(r));return()=>(o(),_o(e)(n)(),Yo(e)())},h0=e=>t=>n=>r=>o=>{const i=kr(e)(t)(Qe(r));return()=>(i(),Hi(e)(t)(Qe(o.color))(),Qo(e)(o.width)(),Rr(e)((()=>{if(o.lineJoin==="RoundJoin")return Mr;if(o.lineJoin==="BevelJoin")return Uo;if(o.lineJoin==="MiterJoin")return Ko;c()})())(),ei(e)((()=>{if(o.lineCap==="ButtCap")return ti;if(o.lineCap==="RoundCap")return Zo;if(o.lineCap==="SquareCap")return jo;c()})())(),_o(e)(n)(),Yo(e)(),Vo(e)())},p0=e=>t=>n=>r=>o=>i=>{const u=xu(e);return()=>{if(u(),i0(e)(n.x)(n.y)(n.w)(n.h)(r)(),o.tag==="Just"?(kr(e)(t)(Qe(o._1.color))(),Yo(e)()):o.tag==="Nothing"||c(),i.tag==="Just")return Hi(e)(t)(Qe(i._1.color))(),Qo(e)(i._1.width)(),Rr(e)((()=>{if(i._1.lineJoin==="RoundJoin")return Mr;if(i._1.lineJoin==="BevelJoin")return Uo;if(i._1.lineJoin==="MiterJoin")return Ko;c()})())(),ei(e)((()=>{if(i._1.lineCap==="ButtCap")return ti;if(i._1.lineCap==="RoundCap")return Zo;if(i._1.lineCap==="SquareCap")return jo;c()})())(),Vo(e)();i.tag!=="Nothing"&&c()}},m0=e=>t=>n=>r=>{const o=Hi(e)(t)(Qe(r.color));return()=>(o(),Qo(e)(r.width)(),Rr(e)((()=>{if(r.lineJoin==="RoundJoin")return Mr;if(r.lineJoin==="BevelJoin")return Uo;if(r.lineJoin==="MiterJoin")return Ko;c()})())(),ei(e)((()=>{if(r.lineCap==="ButtCap")return ti;if(r.lineCap==="RoundCap")return Zo;if(r.lineCap==="SquareCap")return jo;c()})())(),_o(e)(n)(),Vo(e)())},y0=e=>t=>n=>{const r=kr(e)(t)(Qe(n.color));return()=>(r(),s0(e)(t)(g0(n.font))(),ff(e)((()=>{if(n.align==="AlignLeft")return rf;if(n.align==="AlignCenter")return uf;if(n.align==="AlignRight")return of;c()})())(),cf(e)((()=>{if(n.baseline==="BaselineTop")return jc;if(n.baseline==="BaselineMiddle")return tf;if(n.baseline==="BaselineAlphabetic")return ef;if(n.baseline==="BaselineBottom")return nf;c()})())(),Uc(e)(n.content)(n.x)(n.y)())},pa={apply:e=>t=>n=>{const r=e(n),o=t(n);return()=>{const i=r(),u=o();return i(u)}},Functor0:()=>f0},J0={bind:e=>t=>n=>{const r=e(n);return()=>{const o=r();return t(o)(n)()}},Apply0:()=>pa},N0=e=>t=>n=>{const r=u0(t.width/n.vw)(t.height/n.vh),o=vu(e)({translateX:(t.width-n.vw*r)/2-n.vx*r,translateY:(t.height-n.vh*r)/2-n.vy*r});return()=>(o(),Fo(e)({scaleX:r,scaleY:r})(),Rr(e)(Mr)())},x0={pure:e=>t=>()=>e,Apply0:()=>pa},v0={Applicative0:()=>x0,Bind1:()=>J0},T0={fillPath:e=>t=>n=>{const r=l0(n.ctx)(n.styleCache)(e)(t.color),o=n.maskDepth;return()=>{if(o.value===0)return r()}},strokePath:e=>t=>n=>{const r=m0(n.ctx)(n.styleCache)(e)(t),o=n.maskDepth;return()=>{if(o.value===0)return r()}},fillStrokePath:e=>t=>n=>r=>{const o=h0(r.ctx)(r.styleCache)(e)(t.color)(n),i=r.maskDepth;return()=>{if(i.value===0)return o()}},drawRoundedRect:e=>t=>n=>r=>o=>{const i=p0(o.ctx)(o.styleCache)(e)(t)(n)(r),u=o.maskDepth;return()=>{if(u.value===0)return i()}},drawText:e=>t=>{const n=y0(t.ctx)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},pushTransform:e=>t=>{const n=nr(t.ctx),r=t.maskDepth;return()=>{if(r.value===0)return n(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="",vu(t.ctx)({translateX:e.tx,translateY:e.ty})(),Fo(t.ctx)({scaleX:e.sx,scaleY:e.sy})()}},popTransform:e=>{const t=rr(e.ctx),n=e.maskDepth;return()=>{if(n.value===0)return t(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value=""}},pushClip:e=>t=>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="",_o(n.ctx)(e)(),t==="NonZero")return Qc(n.ctx)();if(t==="EvenOdd")return r0(n.ctx)();c()}}},popClip:e=>{const t=rr(e.ctx),n=e.maskDepth;return()=>{if(n.value===0)return t(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value=""}},pushBlend:e=>t=>{const n=nr(t.ctx),r=t.maskDepth;return()=>{if(r.value===0){if(n(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="",e==="Normal")return wu(t.ctx)(sf)();if(e==="Difference")return wu(t.ctx)(af)();c()}}},popBlend:e=>{const t=rr(e.ctx),n=e.maskDepth;return()=>{if(n.value===0)return t(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value=""}},pushAlpha:e=>t=>{const n=nr(t.ctx),r=t.maskDepth;return()=>{if(r.value===0)return n(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="",Ac(t.ctx)(e)()}},popAlpha:e=>{const t=rr(e.ctx),n=e.maskDepth;return()=>{if(n.value===0)return t(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value=""}},pushLayer:e=>t=>{if(e==="LayerNodeMask"){const n=t.maskDepth;return()=>{const r=n.value;n.value=r+1|0}}return()=>{}},popLayer:e=>{const t=e.maskDepth;return()=>{const n=t.value,r=n-1|0;if(n>0)return e.maskDepth.value=r}},setViewport:e=>t=>{const n=N0(t.ctx)(t.surface)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:e=>t=>{const n=_0(t.ctx)(t.surface)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:e=>t=>{const n=d0(t.ctx)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},measureText:e=>t=>n=>{const r=n0(e.family)(e.size)(e.weight)(ys(t));return()=>r},Monad0:()=>v0};function w0(e,t){const n=t.x-e.x,r=t.y-e.y;return Math.sqrt(n*n+r*r)}function L0(e){const t=e.length,n=new Array(t);for(let r=0;r<t;r++){const o=e[r],i=e[(r+1)%t];n[r]={a:o,b:i,len:w0(o,i)}}return n}function E0(e,t,n){let r=0;for(let o=0;o<e.length;o++){const i=e[o],u=r,s=u+i.len;if(n<=s){const a=i.len>1e-6?(n-u)/i.len:0;return{x:i.a.x+(i.b.x-i.a.x)*a,y:i.a.y+(i.b.y-i.a.y)*a}}r=s}return t.length>0?t[t.length-1]:{x:0,y:0}}function ma(e,t){if(t.length===0)return[];const n=L0(t);let r=0;for(let i=0;i<n.length;i++)r+=n[i].len;const o=new Array(e);for(let i=0;i<e;i++)o[i]=E0(n,t,i*r/e);return o}function k0(e,t){const n=t.length;if(n===0)return t;const r=(e%n+n)%n|0,o=new Array(n);for(let i=0;i<n;i++)o[i]=t[(i+r)%n];return o}function b0(e,t){const n=t.length;if(n===0)return t;let r=0,o=1/0;for(let i=0;i<n;i++){let u=0;for(let s=0;s<n;s++){const a=e[s]||{x:0,y:0},f=t[(s+i)%n]||{x:0,y:0},g=a.x-f.x,d=a.y-f.y;u+=g*g+d*d}u<o&&(o=u,r=i)}return k0(r,t)}const ya=e=>t=>n=>{const r=ma(e,t),o=ma(e,n),i=b0(r,o);return{from:r,to:i}};function Ja(e){const t=e.length;if(t===0)return{x:0,y:0};let n=0,r=0;for(let o=0;o<t;o++)n+=e[o].x,r+=e[o].y;return{x:n/t,y:r/t}}function C0(e,t){const n=t.x-e.x,r=t.y-e.y,o=Math.sqrt(n*n+r*r);return o<=1e-4?{x:1,y:0}:{x:n/o,y:r/o}}function S0(e,t){const n=t.length;if(n===0)return t;const r=new Array(n);for(let o=0;o<n;o++){const i=t[((o-1)%n+n)%n],u=t[((o+1)%n+n)%n],s=t[o];r[o]={x:s.x+((i.x+u.x)/2-s.x)*e,y:s.y+((i.y+u.y)/2-s.y)*e}}return r}function P0(e){return e<0?0:e>1?1:e}const Na=e=>t=>n=>r=>{const o=t.length;if(o===0)return[];const i=Ja(t),u=Ja(n),s=C0(i,u),a=new Array(o);let f=1/0,g=-1/0;for(let _=0;_<o;_++){const h=t[_],p=(h.x-i.x)*s.x+(h.y-i.y)*s.y;a[_]=p,p<f&&(f=p),p>g&&(g=p)}const d=g-f;let l=new Array(o);for(let _=0;_<o;_++){const h=t[_],p=n[_];if(p===void 0){l[_]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(a[_]-f)/d),J=Math.max(1e-4,1-m),N=P0((e-m)/J),v=N*N*(3-2*N);l[_]={x:h.x+(p.x-h.x)*v,y:h.y+(p.y-h.y)*v}}for(let _=0;_<r.smoothPasses;_++)l=S0(.5,l);return l},G0=e=>e,xa=e=>e,lo=e=>e,va=e=>e,D0=e=>e,Ta=e=>e,wa=e=>e,La=wa("BaselineTop"),ho=wa("BaselineMiddle"),Vi=Ta("AlignLeft"),Yi=Ta("AlignCenter"),Xe=D0("RoundJoin"),fn=va("ButtCap"),W0=va("RoundCap"),M0=lo("LayerPolyOut"),R0=lo("LayerPolyIn"),I0=lo("LayerNodeMask"),z0=lo("LayerOverlay"),Ea=xa("NonZero"),B0=xa("EvenOdd"),A0=G0("Difference"),Fn={r:255,g:255,b:255,a:255},Ue={r:26,g:26,b:26,a:255},Fi=(e,t,n)=>({tag:e,_1:t,_2:n}),Ke=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},br=e=>t=>{const n=ht.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},ka=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Tn=e=>t=>n=>{const r=ht.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),i=ht.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;c()},Ee=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Ze=(()=>{const e=Pe.unfoldr(ln);return t=>e(Ge("IterNode",t,dn))})(),$i=e=>t=>{const n=it.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},ba=jt(E)(zt),Ca=y(er)(0),po=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Sa=e=>{const t=e.Monad0().Bind1(),n=e.popTransform,r=e.popAlpha;return o=>i=>u=>s=>a=>t.bind(e.pushAlpha(o.fadeAlpha))(()=>t.bind(e.pushTransform({tx:i*(1-o.popScale),ty:u*(1-o.popScale),sx:o.popScale,sy:o.popScale}))(()=>t.bind(e.pushTransform({tx:0,ty:s.y*(1-o.flipY),sx:1,sy:o.flipY}))(()=>t.bind(a)(()=>t.bind(n)(()=>t.bind(n)(()=>r))))))},je=e=>{const t=e.Apply0();return n=>y(r=>o=>t.apply(t.Functor0().map(i=>du)(r))(n(o)))(e.pure())},Q0=e=>({x:e.x,y:e.y,w:e.w,h:e.h}),q0=y(e=>t=>e+t.len)(0),H0=e=>{const t=Vt(n=>T,n=>r=>k("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return[];if(t.tag==="Just")return[1,t._1.head.x,t._1.head.y,...St(Wt(1,e.length,e))(n=>[2,n.x,n.y]),5];c()},V0=e=>t=>{const n=e.y+e.h-6,r=e.y+6,o=e.x+14,i=e.x+e.w-14,u=y(br)(0)($(s=>o-10<s.x+s.w+12&&i+10>s.x-12&&r-10<s.y+s.h+12&&n+10>s.y-12?Ke((s.x+s.w+12-(o-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(t));return{...e,x:e.x+u*.7071067811865476,y:e.y-u*.7071067811865476}},Y0={r:26,g:26,b:26,a:255},F0={r:214,g:211,b:209,a:255},Pa=e=>t=>{const n=Ke(t)(Ke(e.w/2)(e.h/2));return[1,e.x+n,e.y,2,e.x+e.w-n,e.y,3,e.x+e.w,e.y,e.x+e.w,e.y+n,2,e.x+e.w,e.y+e.h-n,3,e.x+e.w,e.y+e.h,e.x+e.w-n,e.y+e.h,2,e.x+n,e.y+e.h,3,e.x,e.y+e.h,e.x,e.y+e.h-n,2,e.x,e.y+n,3,e.x,e.y,e.x+n,e.y,5]},$0=e=>t=>n=>y(r=>o=>{const i=ka(o)(t);if(i.tag==="Nothing")return r;if(i.tag==="Just"){const u=V0(i._1)(r.obstacles);return{acc:Z(E)(o)(u)(r.acc),obstacles:me(r.obstacles)(u)}}c()})({acc:q,obstacles:n})(e).acc,O0=e=>{const t=Vt(n=>T,n=>r=>k("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return[];if(t.tag==="Just")return[1,t._1.head.x,t._1.head.y,...St(t._1.tail)(n=>[2,n.x,n.y])];c()},mo=e=>{if(e.tag==="Hidden")return{alpha:0,scale:0};if(e.tag==="Visible")return{alpha:1,scale:1};if(e.tag==="PloppingIn")return{alpha:e._1>0?1:0,scale:ar(8)(.6)(Tn(0)(1)(e._1))};if(e.tag==="PloppingOut")return{alpha:e._1<1?1:0,scale:ar(8)(.6)(Tn(0)(1)(1-e._1))};c()},Ga=e=>t=>St(Ze(e.nodes))(n=>{const r=Ee(n._1)(t.nodes);return r.tag==="Just"&&mo(r._1).alpha>0?Pa(n._2)(7):[]}),X0=e=>t=>n=>[1,e.vx,e.vy,2,e.vx+e.vw,e.vy,2,e.vx+e.vw,e.vy+e.vh,2,e.vx,e.vy+e.vh,5,...Ga(t)(n)],yo=e=>t=>n=>$(r=>{const o=_t(r)/_t(n);return{x:e.x+(t.x-e.x)*o,y:e.y+(t.y-e.y)*o}})(Ht(0,n-1|0)),U0=e=>t=>{const n=o=>(o.x-t.x)*(o.x-t.x)+(o.y-t.y)*(o.y-t.y),r=y(o=>i=>n(i)<n(o)?i:o)({x:e.x,y:e.y})([{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x,y:e.y+e.h},{x:e.x+e.w,y:e.y+e.h}]);return $(o=>{const i=_t(o)/5;return{x:r.x+(t.x-r.x)*i,y:r.y+(t.y-r.y)*i}})([1,2,3,4])},Da=e=>{const t=li(`
6
+ `)(e);return t.length===0?[""]:t},Oi=e=>t=>{const n=Ke(e)(Ke(t.w/2)(t.h/2));return{...t,x:t.x+n,y:t.y+n,w:t.w-2*n,h:t.h-2*n}},K0=e=>{const t=e.Monad0(),n=t.Applicative0(),r=t.Bind1(),o=je(n),i=e.popTransform,u=e.popAlpha;return s=>a=>f=>{const g=li(`
7
+ `)(a.label===""?s:a.label),d=g.length===0?[""]:g,l=a.y+a.h/2-_t(d.length)*13.2/2+6.6,_=mo(f),h=a.x+a.w/2,p=a.y+a.h/2,m=r.bind(e.pushAlpha(_.alpha))(()=>r.bind(e.pushTransform({tx:h*(1-_.scale),ty:p*(1-_.scale),sx:_.scale,sy:_.scale}))(()=>r.bind(e.drawRoundedRect({x:a.x,y:a.y,w:a.w,h:a.h})(7)(k("Just",{color:Fn,flat:!1}))(k("Just",{color:Ue,width:1.25,lineJoin:Xe,lineCap:fn})))(()=>r.bind(o(J=>e.drawText({x:a.x+a.w/2,y:l+_t(J._1)*13.2,content:J._2,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500},color:Ue,align:Yi,baseline:ho}))(Dt(Sn)(d)))(()=>r.bind(i)(()=>u)))));return _.alpha>0?m:n.pure()}},Z0=e=>{const t=K0(e),n=e.Monad0().Applicative0(),r=je(n);return o=>i=>r(u=>{const s=Ee(u._1)(i.nodes);if(s.tag==="Just")return t(u._1)(u._2)(s._1);if(s.tag==="Nothing")return n.pure();c()})(Ze(o.nodes))},Xi=e=>t=>{const n=t.y-e.y,r=t.x-e.x;return Cn(r*r+n*n)},j0=e=>pe(t=>n=>({a:t,b:n,len:Xi(t)(n)}),e,Wt(1,e.length,e)),th=e=>t=>{const n=t.length-1|0,r=n>=0&&n<t.length?k("Just",t[n]):T,o=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];c()})(),i=0<t.length?k("Just",t[0]):T,u=(()=>{if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return{x:0,y:0};c()})(),s=t.length;return s<3?t:[u,...St(Ht(1,s-2|0))(a=>{const f=a+1|0,g=f>=0&&f<t.length?k("Just",t[f]):T,d=a>=0&&a<t.length?k("Just",t[a]):T,l=a-1|0,_=l>=0&&l<t.length?k("Just",t[l]):T;if(_.tag==="Just"&&d.tag==="Just"&&g.tag==="Just"){const h=d._1,p=Xi(h)(g._1),m=Xi(_._1)(h),J=Ke(e)(p/2),N=Ke(e)(m/2),v=p>0?J/p:0,w=h.x+(g._1.x-h.x)*v,b=h.y+(g._1.y-h.y)*v,L=m>0?N/m:0,S=h.x+(_._1.x-h.x)*L,z=h.y+(_._1.y-h.y)*L;return $(F=>{const j=_t(F)/_t(10),G=1-j;return{x:G*G*S+2*G*j*h.x+j*j*w,y:G*G*z+2*G*j*h.y+j*j*b}})(Ht(0,10))}return[]}),...o]},eh=e=>{const t=e.Monad0(),n=t.Bind1(),r=t.Applicative0(),o=je(r);return i=>u=>s=>a=>f=>g=>{const d=hi(g).length,l=_t(d+1|0),_=m=>{const J=(s*l-_t(m))/1.5,N=J<0?0:J>1?1:J;return N*N*(3-2*N)},h=(m=>{let J=m,N=!0,v;for(;N;){const w=J;if(w>=d){N=!1,v=w;continue}if(_(w)>=1){J=w+1|0;continue}N=!1,v=w}return v})(0),p=h>=d?[]:_n(m=>_(m)>0)(Ht(h,d-1|0)).init;return n.bind((()=>{const m=e.drawText({x:a,y:f,content:oe(h)(g),font:i,color:u,align:Vi,baseline:ho});return h>0?m:r.pure()})())(()=>o(m=>n.bind(e.measureText(i)(oe(m)(g)))(J=>{const N=_(m);return e.drawText({x:a+J,y:f-(1-N)*10,content:oe(1)(fr(hn(oe(m)(g)))(g)),font:i,color:{...u,a:tr(mu(N*_t(u.a)))},align:Vi,baseline:ho})}))(p))}},Jo=e=>t=>n=>r=>{const o=$(h=>_t($i(1)(hi(h).length)))(r),i=br(1)(y(er)(0)(o)),u=br(.05)(1-t-n),s=e<t?0:e>1-n?1:(e-t)/u,a=s*i,f=$i(1)(r.length),g=(h=>p=>m=>{let J=h,N=p,v=m,w=!0,b;for(;w;){const L=J,S=N,z=Vt(F=>T,F=>j=>k("Just",{head:F,tail:j}),v);if(z.tag==="Nothing"){w=!1,b=$i(0)(f-1|0);continue}if(z.tag==="Just"){if(S+z._1.head>=a){w=!1,b=L;continue}J=L+1|0,N=S+z._1.head,v=z._1.tail;continue}c()}return b})(0)(0)(o),d=y(er)(0)(g<1?[]:Wt(0,g,o)),l=d/i;if(g>=0&&g<o.length){const h=(d+o[g])/i;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(h<=l)return 1;const p=(s-l)/(h-l);return p<0?0:p>1?1:p})()}}const _=(d+1)/i;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(_<=l)return 1;const h=(s-l)/(_-l);return h<0?0:h>1?1:h})()}},nh=e=>{const t=e.Monad0();return n=>r=>o=>t.Bind1().bind(e.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Jo(r)(0)(0)(o).line))(i=>{const u=i+28;return t.Applicative0().pure({x:n.x+n.w/2-u/2,y:n.y-25.2-14,w:u,h:25.2})})},rh=e=>{const t=e.Monad0(),n=t.Bind1(),r=nh(e),o=t.Applicative0(),i=Ir.traverse(o);return u=>s=>n.Apply0().Functor0().map(a=>ba(bt(f=>f)(a)))(i(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const f=Ee(a._2._1.node)(u.nodes);if(f.tag==="Just")return n.bind(r(f._1)(a._2._1.progress)(a._2._1.labels))(g=>o.pure(k("Just",x(a._1,g))));if(f.tag==="Nothing")return o.pure(T);c()}return o.pure(T)})(Ze(s.tokens)))},Wa=e=>t=>$(n=>{const r=6.283185307179586*_t(n)/_t(64);return{x:e.x+t*bo(r),y:e.y+t*So(r)}})(Ht(0,63)),Ui=e=>t=>{const n=.5522847498*t;return[1,e.x+t,e.y,4,e.x+t,e.y+n,e.x+n,e.y+t,e.x,e.y+t,4,e.x-n,e.y+t,e.x-t,e.y+n,e.x-t,e.y,4,e.x-t,e.y-n,e.x-n,e.y-t,e.x,e.y-t,4,e.x+n,e.y-t,e.x+t,e.y-n,e.x+t,e.y,5]},oh=e=>{const t=e.Monad0().Bind1(),n=e.popAlpha;return r=>o=>i=>u=>s=>a=>f=>{const g={x:i.x+i.w/2,y:i.y+i.h/2},d=br(.05)(1-a-f),l=s<a?0:s>1-f?1:(s-a)/d,_={x:u.x+u.w/2,y:u.y+u.h/2},h=(p,m)=>t.bind(e.pushAlpha(m))(()=>t.bind(e.fillStrokePath(Ui(p)(6))({color:r,flat:!0})({color:o,width:1,lineJoin:Xe,lineCap:fn}))(()=>n));return l<.5?h(g,(()=>{const p=l*2;return 1-(p<0?0:p>1?1:p)*(p<0?0:p>1?1:p)*(p<0?3:p>1?1:3-2*p)})()):h(_,(()=>{const p=(l-.5)*2;return(p<0?0:p>1?1:p)*(p<0?0:p>1?1:p)*(p<0?3:p>1?1:3-2*p)})())}},ih={r:255,g:235,b:130,a:255},uh=e=>{const t=e.length;return t===0?{x:0,y:0}:{x:Ca($(n=>n.x)(e))/_t(t),y:Ca($(n=>n.y)(e))/_t(t)}},Ma=e=>t=>n=>{const r=ar(6)(.55)(Tn(0)(1)((1-e)/.06)),o=e>.94,i=o&&n>1e-4,u=ar(6)(.55)(Tn(0)(1)(e/.06)),s=e<.06,a=s&&t>1e-4,f=o&&n<=1e-4;return{popScale:a?u:i?r:1,flipY:s&&t<=1e-4?u:f?r:1,fadeAlpha:(()=>{if(a){const g=e/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}if(i){const g=(1-e)/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}return 1})()}},sh=e=>{const t=e.Monad0().Bind1(),n=Sa(e);return r=>o=>i=>u=>{const s=Ma(i)(0)(0),a={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500},f=Jo(i)(0)(0)(u);return t.bind(e.measureText(a)(f.line))(g=>{const d={r:26,g:26,b:26,a:90},l=o.x+o.w/2,_=g+28,h=o.y-25.2-14,p=l-_/2,m=[1,l,h+25.2,2,l,o.y],J={x:l,y:h+12.6};return n(s)(l-_/2)(h+25.2)(J)(t.bind(e.drawRoundedRect({x:l-_/2,y:h+1.5,w:_,h:25.2})(6)(k("Just",{color:F0,flat:!0}))(T))(()=>t.bind(e.drawRoundedRect({x:p,y:h,w:_,h:25.2})(6)(k("Just",{color:ih,flat:!0}))(k("Just",{color:d,width:1,lineJoin:Xe,lineCap:fn})))(()=>t.bind(e.strokePath(m)({color:d,width:1,lineJoin:Xe,lineCap:fn}))(()=>e.drawText({x:l,y:J.y,content:f.line,font:a,color:Ue,align:Yi,baseline:ho})))))})}},Ra={r:0,g:0,b:0,a:0},ah=e=>t=>e.backgroundDots({viewport:{vx:t.x,vy:t.y,vw:t.w,vh:t.h},bgColor:Ra,dotColor:Y0,tile:1.6,dotRadius:.25}),ch={r:214,g:211,b:209,a:255},Ia={r:255,g:255,b:255,a:255},fh=e=>{const t=e.Monad0().Bind1();return n=>r=>n?t.bind(e.clearBackground(Ra))(()=>e.setViewport(r)):t.bind(e.setViewport(r))(()=>e.backgroundDots({viewport:r,bgColor:Ia,dotColor:ch,tile:12,dotRadius:.7}))},gh=e=>{const t=e.Monad0(),n=t.Applicative0(),r=t.Bind1(),o=e.popClip,i=e.popTransform,u=e.popAlpha;return s=>a=>f=>{const g=mo(f),d={...a,y:a.y+5},l=d.x+d.w/2,_=d.y+d.h/2,h=r.bind(e.pushAlpha(g.alpha))(()=>r.bind(e.pushTransform({tx:l*(1-g.scale),ty:_*(1-g.scale),sx:g.scale,sy:g.scale}))(()=>r.bind(e.drawRoundedRect({x:d.x,y:d.y,w:d.w,h:d.h})(7)(k("Just",{color:Ia,flat:!0}))(T))(()=>r.bind((()=>{const p=r.bind(e.pushClip(Pa(d)(7))(Ea))(()=>r.bind(ah(e)(d))(()=>o));return s?p:n.pure()})())(()=>r.bind(e.drawRoundedRect({x:d.x,y:d.y,w:d.w,h:d.h})(7)(T)(k("Just",{color:Ue,width:1.25,lineJoin:Xe,lineCap:fn})))(()=>r.bind(i)(()=>u))))));return g.alpha>0?h:n.pure()}},_h=e=>{const t=gh(e),n=e.Monad0().Applicative0(),r=je(n);return o=>i=>u=>r(s=>{const a=Ee(s._1)(u.nodes);if(a.tag==="Just")return t(o)(s._2)(a._1);if(a.tag==="Nothing")return n.pure();c()})(Ze(i.nodes))},dh=e=>{const t=e.Monad0().Applicative0();return n=>{const r=n.length-1|0,o=r<1?[]:Wt(0,r,n),i=o.length-1|0,u=i>=0&&i<o.length?k("Just",o[i]):T,s=n.length-1|0;if(s>=0&&s<n.length&&u.tag==="Just"){const a=n[s].y-u._1.y,f=n[s].x-u._1.x,g=Cn(f*f+a*a),d=a/g,l=-d,_=f/g,h=n[s].x+_*.875,p=n[s].y+d*.875,m=p-d*8.75,J=h-_*8.75,N=[1,h,p,2,J+l*4.375,m+_*4.375,2,J-l*4.375,m-_*4.375,5];return g<=1e-4?t.pure():e.fillPath(N)({color:Ue,flat:!0})}return t.pure()}},No=e=>t=>n=>r=>o=>$(i=>{const u=n+(r-n)*(_t(i)/_t(o));return{x:e.x+t*bo(u),y:e.y+t*So(u)}})(Ht(0,o-1|0)),za=e=>t=>{const n=Ke(e)(Ke(t.w/2)(t.h/2));return[...yo({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(6),...No({x:t.x+t.w-n,y:t.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...yo({x:t.x+t.w,y:t.y+n})({x:t.x+t.w,y:t.y+t.h-n})(6),...No({x:t.x+t.w-n,y:t.y+t.h-n})(n)(0)(1.5707963267948966)(12),...yo({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(6),...No({x:t.x+n,y:t.y+t.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...yo({x:t.x,y:t.y+t.h-n})({x:t.x,y:t.y+n})(6),...No({x:t.x+n,y:t.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},lh=e=>t=>n=>y(r=>o=>{const i=r.pos+o.len,u=n<i?(n-r.pos)/o.len:1,s={x:o.a.x+(o.b.x-o.a.x)*u,y:o.a.y+(o.b.y-o.a.y)*u},a=t>r.pos?(t-r.pos)/o.len:0,f={x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a},g=r.points.length-1|0,d=g>=0&&g<r.points.length?(()=>{const l=r.points[g].x-f.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const _=r.points[g].y-f.y;return _<0?-_<1e-4:_<1e-4})()})()?me(r.points)(s):[...r.points,f,s]:[f,s];return o.len<=0||i<=t||r.pos>=n?{...r,pos:i}:{pos:i,points:d}})({pos:0,points:[]})(e).points,hh=e=>t=>n=>{const r=Vt(o=>T,o=>i=>k("Just",{head:o,tail:i}),e);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const o=j0(e),i=q0(o),u=Tn(0)(i)(t*i),s=Tn(0)(i)(n*i);return s<=u?[]:lh(o)(u)(s)}c()},ph=e=>{const t=e.Monad0(),n=t.Applicative0(),r=dh(e);return o=>i=>u=>{const s=th(8)(i);if(u.hi<=u.lo)return n.pure();const a=hh(s)(u.lo)(u.hi);return a.length===0?n.pure():t.Bind1().bind(e.strokePath(O0(a))({color:Ue,width:.9375,lineJoin:Xe,lineCap:W0}))(()=>r(a))}},mh=e=>{const t=ph(e),n=e.Monad0().Applicative0(),r=je(n);return o=>i=>r(u=>{const s=po(u._1)(i.edges);if(s.tag==="Just")return t(u._1)(u._2)((()=>{if(s._1.tag==="Retracted")return{lo:0,hi:0};if(s._1.tag==="Extended")return{lo:0,hi:1};if(s._1.tag==="Extending")return{lo:0,hi:s._1._2};if(s._1.tag==="Retracting"){if(s._1._1==="FromSource")return{lo:s._1._2,hi:1};if(s._1._1==="FromTarget")return{lo:0,hi:1-s._1._2};if(s._1._1==="FromBoth")return{lo:s._1._2/2,hi:1-s._1._2/2}}c()})());if(s.tag==="Nothing")return n.pure();c()})(Ze(o.edges))},Ba=e=>t=>n=>r=>o=>i=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:t.x+t.w/2,y:t.y+t.h/2},a=0<e.length?k("Just",e[0]):T,f=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return s;c()})(),g=e.length-1|0,d=g>=0&&g<e.length?k("Just",e[g]):T,l=(()=>{if(d.tag==="Just")return d._1;if(d.tag==="Nothing")return u;c()})(),_=ya(128)(za(5)(Oi(2)(t)))(Wa(f)(6)),h=br(.05)(1-o-i),p=r<o?0:r>1-i?1:(r-o)/h,m=f.x-s.x,J=2*(()=>{const K=f.y-s.y;return(m<0?-m:m)+(K<0?-K:K)})(),N=l.x-u.x,v=2*(()=>{const K=l.y-u.y;return(N<0?-N:N)+(K<0?-K:K)})(),w=J+ri(e)+v,b=w<=1e-4?1:1-v/w,L=w<=1e-4?0:J/w,S=b-L,z=ya(128)(Wa(l)(6))(za(5)(Oi(2)(n))),F={maxDelay:.4,smoothPasses:2},j=Iu(e)(Tn(0)(1)(S<=1e-4?0:(p-L)/S)),G=(()=>{if(j.tag==="Just")return j._1;if(j.tag==="Nothing")return f;c()})(),P=(()=>{if(b>=1)return 0;const K=(p-b)/(1-b),A=K<0?0:K>1?1:K;return A*A*(3-2*A)})(),et=(()=>{if(L<=1e-4)return 1;const K=p/L,A=K<0?0:K>1?1:K;return A*A*(3-2*A)})();return p<L?Fi("PolyShape",Na(et)(_.from)(_.to)(F)):p>=b?Fi("PolyShape",Na(P)(z.from)(z.to)(F)):Fi("CircleShape",G,6)},yh=e=>t=>n=>r=>o=>i=>u=>s=>a=>{const f=Ba(r)(o)(i)(u)(s)(a);if(f.tag==="CircleShape")return e.fillStrokePath(Ui(f._1)(f._2))({color:t,flat:!0})({color:n,width:1,lineJoin:Xe,lineCap:fn});if(f.tag==="PolyShape")return f._1.length>=3?e.fillStrokePath(H0(f._1))({color:t,flat:!0})({color:n,width:1,lineJoin:Xe,lineCap:fn}):e.Monad0().Applicative0().pure();c()},Aa=e=>{const t=oh(e),n=e.Monad0().Applicative0(),r=je(n);return o=>i=>u=>s=>r(a=>{if(a._2.tag==="Travelling"){const f=Ee(a._2._1.target)(o.nodes),g=Ee(a._2._1.source)(o.nodes);if(g.tag==="Just"&&f.tag==="Just"){const d=po(a._2._1.edge)(o.edges);if(d.tag==="Just")return yh(e)(u)(s)((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return _e(d._1);c()})())(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);if(d.tag==="Nothing")return t(u)(s)(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);c()}return n.pure()}if(a._2.tag==="Filling"){const f=Ee(a._2._1.node)(o.nodes);if(f.tag==="Just")return e.drawRoundedRect((()=>{const g=Oi(2)(f._1);return{x:g.x,y:g.y,w:g.w,h:g.h}})())(5)(k("Just",{color:u,flat:!0}))(k("Just",{color:s,width:1,lineJoin:Xe,lineCap:fn}));if(f.tag==="Nothing")return n.pure();c()}return n.pure()})(Ze(i.tokens))},Jh=e=>{const t=e.Monad0(),n=t.Bind1(),r=Aa(e),o=e.popClip,i=e.popBlend,u=e.popLayer,s=t.Applicative0(),a=je(s);return f=>g=>n.bind(e.pushLayer(R0))(()=>n.bind(e.pushBlend(A0))(()=>n.bind(e.pushClip(Ga(f)(g))(Ea))(()=>n.bind(r(f)(g)(Fn)(Fn))(()=>n.bind(o)(()=>n.bind(i)(()=>n.bind(u)(()=>n.bind(e.pushLayer(I0))(()=>n.bind(a(d=>{const l=Ee(d._1)(g.nodes);return l.tag==="Just"&&mo(l._1).alpha>0?e.drawRoundedRect({x:d._2.x,y:d._2.y,w:d._2.w,h:d._2.h})(7)(k("Just",{color:Fn,flat:!1}))(T):s.pure()})(Ze(f.nodes)))(()=>u)))))))))},Nh=e=>{const t=e.Monad0().Bind1(),n=Aa(e),r=e.popClip,o=e.popLayer;return i=>u=>s=>t.bind(e.pushLayer(M0))(()=>t.bind(e.pushClip(X0(i)(u)(s))(B0))(()=>t.bind(n(u)(s)(Ue)(Fn))(()=>t.bind(r)(()=>o))))},Qa=e=>t=>n=>r=>o=>i=>{const u=Ba(e)(t)(n)(r)(o)(i);if(u.tag==="PolyShape")return uh(u._1);if(u.tag==="CircleShape")return u._1;c()},xh=e=>{const t=Sa(e),n=e.Monad0(),r=n.Bind1(),o=je(n.Applicative0()),i=eh(e);return u=>s=>a=>f=>g=>d=>l=>_=>{const h=Jo(f)(g)(d)(St(l)(Da)),p=h.line,m=h.phaseInLabel/.45,J=m<0?0:m>1?1:m,N=_.w,v=_.y,w=_.x,b=w+14,L=_.h,S=v+L/2;return t(Ma(f)(g)(d))(w)(v+L)({x:w+N/2,y:S})(r.bind(o(z=>e.fillPath(Ui(z)(1.5))({color:Ue,flat:!0}))(U0(_)(Qa(u)(s)(a)(f)(g)(d))))(()=>r.bind(e.drawRoundedRect({x:w,y:v,w:N,h:L})(3)(k("Just",{color:Ue,flat:!0}))(T))(()=>i({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Fn)(J)(b)(S)(p))))}},vh=e=>{const t=xh(e),n=e.Monad0(),r=n.Applicative0(),o=sh(e),i=n.Bind1(),u=je(r),s=e.popLayer;return a=>f=>g=>i.bind(e.pushLayer(z0))(()=>i.bind(u(d=>{if(d._2.tag==="Travelling"){if(d._2._1.labels.length!==0){const l=Ee(d._2._1.target)(a.nodes),_=Ee(d._2._1.source)(a.nodes),h=po(d._2._1.edge)(a.edges),p=ka(d._1)(g);if(p.tag==="Just"&&h.tag==="Just"&&_.tag==="Just"&&l.tag==="Just")return t((()=>{if(d._2._1.direction==="Forward")return h._1;if(d._2._1.direction==="Backward")return _e(h._1);c()})())(_._1)(l._1)(d._2._1.progress)(d._2._1.holdPre)(d._2._1.holdPost)(d._2._1.labels)(p._1)}return r.pure()}if(d._2.tag==="Filling"&&d._2._1.labels.length!==0){const l=Ee(d._2._1.node)(a.nodes);if(l.tag==="Just")return o(a)(l._1)(d._2._1.progress)(d._2._1.labels);if(l.tag==="Nothing")return r.pure();c()}return r.pure()})(Ze(f.tokens)))(()=>s))},Th=e=>{const t=e.Monad0();return n=>r=>o=>i=>u=>s=>a=>{const f=Qa(n)(r)(o)(i)(u)(s);return t.Bind1().bind(e.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Jo(i)(u)(s)(St(a)(Da)).line))(g=>t.Applicative0().pure({x:f.x+14+g/2-g/2-14,y:f.y-6-8-6.6-6,w:g+28,h:25.2}))}},wh=e=>{const t=e.Monad0(),n=t.Bind1(),r=Th(e),o=t.Applicative0(),i=Ir.traverse(o);return u=>s=>n.Apply0().Functor0().map(a=>ba(bt(f=>f)(a)))(i(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const f=Ee(a._2._1.target)(u.nodes),g=Ee(a._2._1.source)(u.nodes),d=po(a._2._1.edge)(u.edges);if(d.tag==="Just"&&g.tag==="Just"&&f.tag==="Just")return n.bind(r((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return _e(d._1);c()})())(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(l=>o.pure(k("Just",x(a._1,l))))}return o.pure(T)})(Ze(s.tokens)))},Lh=e=>{const t=e.Monad0(),n=t.Bind1(),r=wh(e),o=rh(e);return i=>u=>n.bind(r(i)(u))(s=>n.bind(o(i)(u))(a=>t.Applicative0().pure($0((()=>{const f=g=>{if(g.tag==="Leaf")return q;if(g.tag==="Node")return $t("Node",g._1,g._2,g._3,void 0,f(g._5),f(g._6));c()};return xt(E.compare)(wt(we.foldr,f(s)))})())(s)([...$(Q0)((()=>{const f=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return f(g._5,It("Cons",g._4,f(g._6,d)));c()};return wt(qt.foldr,f(i.nodes,Bt))})()),...(()=>{const f=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return f(g._5,It("Cons",g._4,f(g._6,d)));c()};return wt(qt.foldr,f(a,Bt))})()]))))},Eh=e=>{const t=Lh(e),n=vh(e);return r=>o=>e.Monad0().Bind1().bind(t(r)(o))(i=>n(r)(o)(i))},kh=e=>t=>n=>{const r=Zu(t)(n.camera);return{vx:r.x-e.padding,vy:r.y-e.padding,vw:r.w+2*e.padding,vh:r.h+2*e.padding}},bh=(e=>{const t=e.Monad0().Bind1(),n=fh(e),r=mh(e),o=_h(e),i=Z0(e),u=Nh(e),s=Jh(e),a=Eh(e);return f=>g=>d=>{const l=kh(f)(g)(d);return t.bind(n(f.transparentBg)(l))(()=>t.bind(r(g)(d))(()=>t.bind(o(f.halftoneShadows)(g)(d))(()=>t.bind(i(g)(d))(()=>t.bind(u(l)(g)(d))(()=>t.bind(s(g)(d))(()=>t.bind(a(g)(d))(()=>t.bind(f.watermark===""?e.Monad0().Applicative0().pure():e.drawText({x:l.vx+6,y:l.vy+6,content:f.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:Vi,baseline:La}))(()=>d.frameTitle===""?e.Monad0().Applicative0().pure():e.drawText({x:l.vx+l.vw/2,y:l.vy+12,content:d.frameTitle,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:13,weight:600},color:{r:80,g:80,b:80,a:255},align:Yi,baseline:La})))))))))}})(T0),Ch=e=>t=>n=>r=>{const o=c0(e)(t);return()=>{const i=o();return bh({padding:24,transparentBg:!1,halftoneShadows:!0,watermark:""})(n)(r)(i)()}},Cr=e=>({bind:t=>n=>r=>e.Bind1().bind(t(r))(o=>n(o._1)(o._2)),Apply0:()=>qa(e)}),qa=e=>{const t=e.Bind1().Apply0().Functor0(),n={map:r=>o=>i=>t.map(u=>x(r(u._1),u._2))(o(i))};return{apply:(()=>{const r=Cr(e);return o=>i=>r.bind(o)(u=>r.bind(i)(s=>Sr(e).pure(u(s))))})(),Functor0:()=>n}},Sr=e=>({pure:t=>n=>e.Applicative0().pure(x(t,n)),Apply0:()=>qa(e)}),Sh=e=>{const t={Applicative0:()=>Sr(e),Bind1:()=>Cr(e)};return{state:n=>r=>e.Applicative0().pure(n(r)),Monad0:()=>t}},Ki=(e,t)=>({tag:e,_1:t}),wn=(e,t)=>({tag:e,_1:t}),ve=Sh(rn),At=Cr(rn),ke=ve.state(e=>x(e,e)),tn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},gn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},ce=Sr(rn),Ph=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=k("Just",i._4);continue}}c()}return o},Gh=(()=>{const e=Pe.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return k("Just",x(t._1,t._2));c()});return t=>e((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._3,n(r._6,o)));c()};return n(t,Bt)})())})(),Dh=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=E.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}c()}return o},Zi=e=>t=>n=>y(r=>o=>e.Bind1().bind(r)(i=>t(i)(o)))(e.Applicative0().pure(n)),Wh=y(e=>t=>Z(E)(t)()(e))(q),Mh=(()=>{const e=(t=>n=>{let r=t,o=n,i=!0,u;for(;i;){const s=r,a=o;if(a.tag==="Nil"){i=!1,u=s;continue}if(a.tag==="Cons"){r=Z(E)(a._1)()(s),o=a._2;continue}c()}return u})(q);return t=>e((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,It("Cons",r._3,n(r._6,o)));c()};return n(t,Bt)})())})(),Ha=dc(ce)(zt),Rh=e=>Ki("Par",e),Va=e=>Ki("Seq",e),De=e=>ve.state(t=>x(void 0,(()=>{if(t.error.tag==="Just")return t;if(t.error.tag==="Nothing")return{...t,error:k("Just",{msg:e,line:t.currentLine,column:t.currentColumn})};c()})())),Ih=e=>At.bind(ke)(t=>{const n=e.tag==="Just"&&e._1!==""?e._1:"kf-"+Te(t.kfCounter);if(on(o=>o.id===n,t.keyframes))return De("duplicate frame name "+n);const r={...t,keyframes:me(t.keyframes)({id:n,nodes:t.currNodes,edges:t.currEdges}),kfCounter:t.kfCounter+1|0,currentKf:k("Just",n)};return ve.state(o=>x(void 0,r))}),zh=e=>t=>{const n=t.from+"->"+t.to,r=t.newFrom+"->"+t.newTo,o=Lt("Left","cannot repoint "+t.from+"\u2192"+t.to+": edge does not exist"),i=tn(n)(e.currEdges)?Lt("Right",void 0):o;return(()=>{if(i.tag==="Left"){const u=i._1;return s=>Lt("Left",u)}if(i.tag==="Right"){const u=i._1;return s=>s(u)}c()})()(()=>{const u="cannot repoint "+t.from+"\u2192"+t.to+" to "+t.newFrom+"\u2192"+t.newTo+": unknown node "+t.newFrom;if(!gn(t.newFrom)(e.currNodes))return Lt("Left",u);const s="cannot repoint "+t.from+"\u2192"+t.to+" to "+t.newFrom+"\u2192"+t.newTo+": unknown node "+t.newTo;if(!gn(t.newTo)(e.currNodes))return Lt("Left",s);const a="cannot repoint "+t.from+"\u2192"+t.to+" to "+t.newFrom+"\u2192"+t.newTo+": target edge already exists";return n!==r&&tn(r)(e.currEdges)?Lt("Left",a):Lt("Right",{nextCurrEdges:Z(E)(r)()(sr(E)(n)(e.currEdges)),newId:r,newEdge:{id:r,from:{node:t.newFrom,port:T},to:{node:t.newTo,port:T}}})})},Bh={graphNodes:q,graphEdges:q,currNodes:q,currEdges:q,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:T,currentLine:0,currentColumn:0,error:T},Ya=e=>t=>At.bind(ke)(n=>{const r="ev-"+Te(n.eventCounter);return At.bind((()=>{const o={...n,eventCounter:n.eventCounter+1|0};return ve.state(i=>x(void 0,o))})())(()=>ce.pure({events:[{id:r,kind:t,when:e}],firstId:k("Just",r),lastId:k("Just",r)}))}),Ah=e=>t=>{if(t.tag==="Token"){const n=t._1;return At.bind(ke)(r=>{const o=!gn(n.from)(r.currNodes),i=!gn(n.to)(r.currNodes);if(o||i)return At.bind(De(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: "))(()=>ce.pure({events:[],firstId:T,lastId:T}));const u=n.to+"->"+n.from,s=n.from+"->"+n.to;return tn(s)(r.currEdges)?Ya(e)(Vu("SendToken",{from:n.from,to:n.to,edge:s,direction:fg,labels:n.labels})):tn(u)(r.currEdges)?Ya(e)(Vu("SendToken",{from:n.from,to:n.to,edge:u,direction:gg,labels:n.labels})):At.bind(De("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>ce.pure({events:[],firstId:T,lastId:T}))})}return ce.pure({events:[],firstId:T,lastId:T})},Qh=e=>bt(t=>Ph(t)(e.graphEdges))(wt(jn,Gh(e.currEdges))),qh=e=>t=>{const n=ct(o=>o.from.node===t.id||o.to.node===t.id,Qh(e)),r=Zi(gc)(o=>i=>{const u=i.from+"->"+t.id,s=t.id+"->"+i.to,a=i.from+"->"+i.to,f="via "+i.from+" "+i.to+": no edge "+i.from+"\u2192"+t.id;if(!tn(u)(e.currEdges))return Lt("Left",f);const g="via "+i.from+" "+i.to+": no edge "+t.id+"\u2192"+i.to;if(!tn(s)(e.currEdges))return Lt("Left",g);const d="via "+i.from+" "+i.to+": would create "+i.from+"\u2192"+i.to+" but it already exists";return tn(a)(e.currEdges)||Dh(a)(o.synthesized)?Lt("Left",d):Lt("Right",{consumed:Z(E)(u)()(Z(E)(s)()(o.consumed)),synthesized:Z(E)(a)({id:a,from:{node:i.from,port:T},to:{node:i.to,port:T}})(o.synthesized)})})({consumed:q,synthesized:q})(t.via);return(()=>{if(r.tag==="Left"){const o=r._1;return i=>Lt("Left",o)}if(r.tag==="Right"){const o=r._1;return i=>i(o)}c()})()(o=>{const i=o.consumed,u=ct(s=>!tn(s.id)(i),n);return u.length===0?Lt("Right",{nextCurrEdges:ye(E.compare,he,Fe(E.compare,e.currEdges,Wh($(s=>s.id)(n))),Mh((()=>{const s=a=>{if(a.tag==="Leaf")return q;if(a.tag==="Node")return $t("Node",a._1,a._2,a._3,void 0,s(a._5),s(a._6));c()};return s(o.synthesized)})())),synthesized:o.synthesized}):Lt("Left","cannot delete node "+t.id+": still connected ("+Rg(", ")($(s=>s.from.node+"\u2192"+s.to.node)(u))+"). Use -edge to drop them or `via a b` to merge "+t.id+"'s endpoints.")})},Fa=e=>{if(e.tag==="Leaf")return[e._1];if(e.tag==="Par"||e.tag==="Seq")return St(e._1)(Fa);c()},Hh=e=>({nodes:(()=>{const t=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return t(n._5,It("Cons",n._4,t(n._6,r)));c()};return wt(qt.foldr,t(e.graphNodes,Bt))})(),edges:(()=>{const t=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return t(n._5,It("Cons",n._4,t(n._6,r)));c()};return wt(qt.foldr,t(e.graphEdges,Bt))})(),constraints:[]}),Vh=e=>{if(e.tag==="AddNode"){const t=e._1;return ve.state(n=>x(void 0,{...n,graphNodes:Z(E)(t.id)({id:t.id,size:x(1,1),ports:[],label:k("Just",t.label)})(n.graphNodes),currNodes:Z(E)(t.id)()(n.currNodes)}))}if(e.tag==="DelNode"){const t=e._1;return At.bind(ke)(n=>{if(!gn(t.id)(n.currNodes))return De("cannot delete node "+t.id+": does not exist");const r=qh(n)(t);if(r.tag==="Left")return De(r._1);if(r.tag==="Right"){const o=r._1;return ve.state(i=>x(void 0,{...i,currNodes:sr(E)(t.id)(i.currNodes),currEdges:o.nextCurrEdges,graphEdges:ye(E.compare,he,o.synthesized,i.graphEdges)}))}c()})}if(e.tag==="ModNode"){const t=e._1;return At.bind(ke)(n=>{if(!gn(t.id)(n.currNodes))return De("cannot modify node "+t.id+": does not exist");if(t.label.tag==="Just"){const r=t.label._1;return ve.state(o=>x(void 0,{...o,graphNodes:qf(E)(i=>k("Just",{...i,label:k("Just",r)}))(t.id)(o.graphNodes)}))}if(t.label.tag==="Nothing")return ce.pure();c()})}if(e.tag==="AddEdge"){const t=e._1;return At.bind(ke)(n=>{const r=!gn(t.from)(n.currNodes),o=!gn(t.to)(n.currNodes);if(r||o)return De("cannot add edge "+t.from+"\u2192"+t.to+": unknown node "+(r?o?t.from+", "+t.to:t.from:o?t.to:""));const i=t.from+"->"+t.to;return ve.state(u=>x(void 0,{...u,graphEdges:Z(E)(i)({id:i,from:{node:t.from,port:T},to:{node:t.to,port:T}})(u.graphEdges),currEdges:Z(E)(i)()(u.currEdges)}))})}if(e.tag==="DelEdge"){const t=e._1;return At.bind(ke)(n=>{const r=t.from+"->"+t.to;return tn(r)(n.currEdges)?ve.state(o=>x(void 0,{...o,currEdges:sr(E)(r)(o.currEdges)})):De("cannot delete edge "+t.from+"\u2192"+t.to+": does not exist")})}if(e.tag==="RepointEdge"){const t=e._1;return At.bind(ke)(n=>{const r=zh(n)(t);if(r.tag==="Left")return De(r._1);if(r.tag==="Right"){const o=r._1;return ve.state(i=>x(void 0,{...i,currEdges:o.nextCurrEdges,graphEdges:Z(E)(o.newId)(o.newEdge)(i.graphEdges)}))}c()})}return ce.pure()},Yh=e=>At.bind(ve.state(t=>x(void 0,{...t,currentLine:e.line,currentColumn:e.column})))(()=>Vh(e.op)),Fh=e=>t=>At.bind(Ha(Yh)(t))(()=>At.bind(ke)(n=>{const r=e.tag==="Just"&&e._1!==""?e._1:"kf-"+Te(n.kfCounter);if(on(i=>i.id===r,n.keyframes))return De("duplicate frame name "+r);const o={...n,keyframes:me(n.keyframes)({id:r,nodes:n.currNodes,edges:n.currEdges}),kfCounter:n.kfCounter+1|0,currentKf:k("Just",r),scenes:(()=>{if(n.currentKf.tag==="Nothing")return n.scenes;if(n.currentKf.tag==="Just")return me(n.scenes)(Yu("Structural",{from:n.currentKf._1,to:r,focus:T}));c()})()};return ve.state(i=>x(void 0,o))})),$h=e=>t=>{const n=Vt(r=>T,r=>o=>k("Just",{head:r,tail:o}),t);if(n.tag==="Nothing")return ce.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return At.bind(Pr(e)(n._1.head))(o=>At.bind(Zi({Applicative0:()=>Sr(rn),Bind1:()=>Cr(rn)})(i=>u=>At.bind(Pr((()=>{if(i.lastId.tag==="Just")return ai("After",i.lastId._1);if(i.lastId.tag==="Nothing")return e;c()})())(u))(s=>ce.pure({events:[...i.events,...s.events],firstId:(()=>{if(i.firstId.tag==="Just")return k("Just",i.firstId._1);if(i.firstId.tag==="Nothing")return s.firstId;c()})(),lastId:(()=>{if(s.lastId.tag==="Just")return k("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return i.lastId;c()})()})))(o)(r))(i=>ce.pure(i)))}c()},Oh=e=>t=>{const n=Vt(r=>T,r=>o=>k("Just",{head:r,tail:o}),t);if(n.tag==="Nothing")return ce.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return At.bind(Pr(e)(n._1.head))(o=>At.bind(Xh((()=>{if(o.firstId.tag==="Just")return ai("With",o.firstId._1);if(o.firstId.tag==="Nothing")return e;c()})())(r))(i=>ce.pure({events:[...o.events,...i.events],firstId:o.firstId,lastId:(()=>{if(o.lastId.tag==="Just")return k("Just",o.lastId._1);if(o.lastId.tag==="Nothing")return i.lastId;c()})()})))}c()},Pr=e=>t=>{if(t.tag==="Leaf"){const n=t._1;return At.bind(ve.state(r=>x(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>Ah(e)(n.op))}if(t.tag==="Seq")return $h(e)(t._1);if(t.tag==="Par")return Oh(e)(t._1);c()},Xh=e=>Zi({Applicative0:()=>Sr(rn),Bind1:()=>Cr(rn)})(t=>n=>At.bind(Pr(e)(n))(r=>ce.pure({events:[...t.events,...r.events],firstId:(()=>{if(t.firstId.tag==="Just")return k("Just",t.firstId._1);if(t.firstId.tag==="Nothing")return r.firstId;c()})(),lastId:(()=>{if(r.lastId.tag==="Just")return k("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return t.lastId;c()})()})))({events:[],firstId:T,lastId:T}),Uh=e=>At.bind(ke)(t=>{if(t.currentKf.tag==="Nothing")return De("flow ops before any structural frame");if(t.currentKf.tag==="Just"){const n=t.currentKf._1;return At.bind(Pr(cg)(e))(r=>At.bind(ke)(o=>{const i={...o,scenes:me(o.scenes)(Yu("DataFlow",{keyframe:n,events:r.events,focus:T}))};return ve.state(u=>x(void 0,i))}))}c()}),Kh=e=>At.bind(ke)(t=>{if(t.error.tag==="Just")return ce.pure();if(t.error.tag==="Nothing"){const n=Fa(e.ops),r=ct(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=ct(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 At.bind((()=>{const i=Fh(e.name)(r);return r.length!==0?i:ce.pure()})())(()=>At.bind((()=>{const i=Ih(e.name);return r.length===0&&o.length!==0?i:ce.pure()})())(()=>{const i=Uh(e.ops);return o.length!==0?i:ce.pure()}))}c()}),Zh=e=>At.bind(Ha(Kh)(e.frames))(()=>At.bind(ke)(t=>ce.pure((()=>{if(t.error.tag==="Just")return Lt("Left",t.error._1);if(t.error.tag==="Nothing")return Lt("Right",{seed:e.seed,graph:Hh(t),keyframes:t.keyframes,scenes:t.scenes});c()})())))(Bh)._1,$n=(e,t)=>({tag:"ParseError",_1:e,_2:t}),B=(e,t,n)=>({tag:"ParseState",_1:e,_2:t,_3:n}),xo=(e,t,n)=>({tag:e,_1:t,_2:n}),jh=e=>xo("More",e),tp=e=>xo("Lift",e),$a={map:e=>t=>(n,r,o,i,u)=>r(s=>t(n,r,o,i,(a,f)=>r(g=>u(a,e(f)))))},ep={alt:e=>t=>(n,r,o,i,u)=>{const s=n._1,a=n._2;return r(f=>e(B(s,a,!1),r,o,(g,d)=>{const l=g._3;return r(_=>l?i(g,d):t(n,r,o,i,u))},u))},Functor0:()=>$a},np=e=>{const t=e.Monad0();return n=>r=>{const o=i=>{let u=i,s=!0,a;for(;s;){const f=u();if(f.tag==="More"){u=f._1;continue}if(f.tag==="Lift"){s=!1,a=t.Bind1().Apply0().Functor0().map(ku)(f._1);continue}if(f.tag==="Stop"){s=!1,a=t.Applicative0().pure(or("Done",x(f._2,f._1)));continue}c()}return a};return e.tailRecM(o)(i=>r(n,jh,tp,(u,s)=>xo("Stop",u,Lt("Left",s)),(u,s)=>xo("Stop",u,Lt("Right",s))))}},Oa=(e,t,n,r,o)=>o(e,e._2),rp={index:0,line:1,column:1},op=(e=>{const t=np(e);return n=>r=>e.Monad0().Bind1().Apply0().Functor0().map(Dr)(t(B(n,rp,!1))(r))})(yf),Xa={apply:e=>t=>(n,r,o,i,u)=>r(s=>e(n,r,o,i,(a,f)=>r(g=>{const d=n._3&&!a._3?B(a._1,a._2,!0):a;return t(d,r,o,i,(l,_)=>r(h=>u(d._3&&!l._3?B(l._1,l._2,!0):l,f(_))))}))),Functor0:()=>$a},Ua={pure:e=>(t,n,r,o,i)=>i(t,e),Apply0:()=>Xa},ip={bind:e=>t=>(n,r,o,i,u)=>r(s=>e(n,r,o,i,(a,f)=>r(g=>t(f)(n._3&&!a._3?B(a._1,a._2,!0):a,r,o,i,u)))),Apply0:()=>Xa},up={Applicative0:()=>Ua,Bind1:()=>ip},vo=e=>(t,n,r,o,i)=>n(u=>Oa(t,n,r,o,(s,a)=>n(f=>o(t._3&&!s._3?B(s._1,s._2,!0):s,$n(e,a))))),sp={empty:vo("No alternative"),Alt0:()=>ep},ap={Applicative0:()=>Ua,Plus1:()=>sp},Ce=(e=>t=>{const n=t.Plus1().Alt0(),r=t.Applicative0();return o=>e.tailRecM(i=>e.Monad0().Bind1().bind(n.alt(n.Functor0().map(ku)(o))(r.pure(or("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return or("Loop",It("Cons",u._1,i));if(u.tag==="Done")return or("Done",(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){f=It("Cons",h._1,_),g=h._2;continue}c()}return l})(Bt)(i));c()})())))(Bt)})({tailRecM:e=>t=>(n,r,o,i,u)=>{const s=(a,f,g)=>e(f)(a,r,o,i,(d,l)=>{const _=a._3&&!d._3?B(d._1,d._2,!0):d;if(l.tag==="Loop")return g===0?r(h=>s(_,l._1,30)):s(_,l._1,g-1|0);if(l.tag==="Done")return u(_,l._1);c()});return s(n,t,30)},Monad0:()=>up})(ap),Et=e=>t=>{const n=vo("Expected "+t);return(r,o,i,u,s)=>{const a=r._1,f=r._2;return o(g=>e(B(a,f,!1),o,i,(d,l)=>{const _=d._3;return o(h=>_?u(d,l):n(r,o,i,u,s))},s))}},ji=e=>(t,n,r,o,i)=>{const u=t._3,s=t._1,a=t._2;return n(f=>{const g=(d,l)=>{const _=d._3;return n(h=>_?o(B(d._1,d._2,u),l):i(t,void 0))};return n(d=>n(l=>e(B(s,a,!1),n,r,(_,h)=>g(B(_._1,_._2,!1),h),(_,h)=>n(p=>n(m=>vo("Negated parser succeeded")(_,n,r,g,(J,N)=>n(v=>i(_._3&&!J._3?B(J._1,J._2,!0):J,N))))))))})},cp=e=>{const t=e.foldr(n=>r=>{if(r.tag==="Nothing")return k("Just",n);if(r.tag==="Just")return k("Just",(o,i,u,s,a)=>{const f=o._1,g=o._2;return i(d=>n(B(f,g,!1),i,u,(l,_)=>{const h=l._3;return i(p=>h?s(l,_):r._1(o,i,u,s,a))},a))});c()})(T);return n=>{const r=t(n);if(r.tag==="Nothing")return vo("No alternative");if(r.tag==="Just")return r._1;c()}},fp=e=>t=>n=>(r,o,i,u,s)=>o(a=>o(f=>o(g=>o(d=>e(r,o,i,u,(l,_)=>o(h=>o(p=>{const m=r._3&&!l._3?B(l._1,l._2,!0):l;return n(m,o,i,u,(J,N)=>o(v=>{const w=m._3&&!J._3?B(J._1,J._2,!0):J;return o(b=>o(L=>{const S=r._3&&!w._3?B(w._1,w._2,!0):w;return t(S,o,i,u,(z,F)=>o(j=>s(S._3&&!z._3?B(z._1,z._2,!0):z,N)))}))}))}))))))),tu=e=>t=>n=>{if(t===10)return{index:e.index+1|0,line:e.line+1|0,column:1};if(t===13){const r=Og()(n);return r.tag==="Just"&&r._1===10?{index:e.index+1|0,line:e.line,column:e.column}:{index:e.index+1|0,line:e.line+1|0,column:1}}return t===9?{index:e.index+1|0,line:e.line,column:(e.column+8|0)-Po(e.column-1|0)(8)|0}:{index:e.index+1|0,line:e.line,column:e.column+1|0}},gp=e=>t=>n=>{let r=e,o=t,i=n,u=!0,s;for(;u;){const a=r,f=o,g=i,d=Fr(f);if(d.tag==="Nothing"){u=!1,s=a;continue}if(d.tag==="Just"){r=d._1.tail===""?tu(a)(d._1.head)(g):tu(a)(d._1.head)(d._1.tail),o=d._1.tail,i=g;continue}c()}return s},Ft=e=>(t,n,r,o,i)=>{const u=Fr(t._1);if(u.tag==="Nothing")return o(t,$n("Unexpected EOF",t._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return o(t,$n("Expected Char",t._2));if(u._1.head>=0&&u._1.head<=65535){const s=ju(u._1.head);return e(s)?i(B(u._1.tail,tu(t._2)(u._1.head)(u._1.tail),!0),s):o(t,$n("Predicate unsatisfied",t._2))}}c()},Ka=(e,t,n,r,o)=>e._1===""?o(B(e._1,e._2,!0),void 0):r(e,$n("Expected EOF",e._2)),_p=e=>(t,n,r,o,i)=>{const u=e(t._1);if(u.tag==="Left")return o(t,$n(u._1,t._2));if(u.tag==="Right")return i(B(u._1.remainder,gp(t._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);c()},On=e=>_p(t=>{const n=jf(e)(t);return n.tag==="Just"?Lt("Right",{value:e,consumed:e,remainder:n._1}):Lt("Left","Expected "+ic(e))}),dp=Ft(e=>!0),Za=cp(zt),ja=(()=>{const e=Ft(t=>t===" "||t===" "||t===`
8
+ `||t==="\r");return(t,n,r,o,i)=>n(u=>e(t,n,r,o,(s,a)=>n(f=>i(t._3&&!s._3?B(s._1,s._2,!0):s,void 0))))})(),eu=(e,t,n,r,o)=>t(i=>On("#")(e,t,n,r,(u,s)=>t(a=>{const f=Ce(Ft(d=>d!==`
9
+ `)),g=e._3&&!u._3?B(u._1,u._2,!0):u;return t(d=>f(g,t,n,r,(l,_)=>t(h=>o(g._3&&!l._3?B(l._1,l._2,!0):l,void 0))))}))),lp=Et((()=>{const e=Et(Ft(n=>n==="}"))("'}'"),t=Ft(n=>n===`
10
+ `||n==="\r");return(n,r,o,i,u)=>{const s=n._1,a=n._2;return r(f=>r(g=>e(B(s,a,!1),r,o,(d,l)=>r(_=>{const h=n._1,p=n._2;return r(m=>r(J=>eu(B(h,p,!1),r,o,(N,v)=>{const w=N._3;return r(b=>{if(w)return i(N,v);const L=n._1,S=n._2;return r(z=>r(F=>t(B(L,S,!1),r,o,(j,G)=>{const P=j._3;return r(et=>P?i(j,G):Ka(n,r,o,i,u))},(j,G)=>r(P=>u(j,void 0)))))})},(N,v)=>r(w=>u(N,void 0)))))}),(d,l)=>r(_=>u(B(s,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),Se=(()=>{const e=Ce((t,n,r,o,i)=>{const u=t._1,s=t._2;return n(a=>ja(B(u,s,!1),n,r,(f,g)=>{const d=f._3;return n(l=>d?o(f,g):eu(t,n,r,o,i))},i))});return(t,n,r,o,i)=>n(u=>e(t,n,r,o,(s,a)=>n(f=>i(t._3&&!s._3?B(s._1,s._2,!0):s,void 0))))})(),We=(e,t,n,r,o)=>t(i=>{const u=(f,g)=>t(d=>Se(e._3&&!f._3?B(f._1,f._2,!0):f,t,n,r,o)),s=e._1,a=e._2;return t(f=>ja(B(s,a,!1),t,n,(g,d)=>{const l=g._3;return t(_=>l?r(g,d):eu(e,t,n,r,u))},u))}),tc=(()=>{const e=Et(Ft(t=>t==="|"))("'|'");return(t,n,r,o,i)=>n(u=>e(t,n,r,o,(s,a)=>n(f=>{const g=Ce(Ft(l=>l!=="|")),d=t._3&&!s._3?B(s._1,s._2,!0):s;return n(l=>g(d,n,r,o,(_,h)=>n(p=>{const m=Et(Et(Ft(N=>N==="|"))("'|'"))("closing '|'"),J=d._3&&!_._3?B(_._1,_._2,!0):_;return n(N=>m(J,n,r,o,(v,w)=>n(b=>i(J._3&&!v._3?B(v._1,v._2,!0):v,Wn(wt(qt.foldr,h))))))})))})))})(),To=Ft(e=>e>="a"&&e<="z"||e>="A"&&e<="Z"),Ln=(()=>{const e=Ce(Ft(t=>t===" "||t===" "));return(t,n,r,o,i)=>n(u=>e(t,n,r,o,(s,a)=>n(f=>i(t._3&&!s._3?B(s._1,s._2,!0):s,void 0))))})(),hp=(()=>{const e=Et(Ft(t=>t==="\\"))("'\\\\'");return(t,n,r,o,i)=>n(u=>e(t,n,r,o,(s,a)=>n(f=>{const g=t._3&&!s._3?B(s._1,s._2,!0):s;return n(d=>dp(g,n,r,o,(l,_)=>n(h=>i(g._3&&!l._3?B(l._1,l._2,!0):l,_==="n"?`
11
+ `:_==="t"?" ":_==="r"?"\r":_))))})))})(),pp=(()=>{const e=Ft(t=>t!=='"'&&t!=="\\"&&t!==`
12
+ `);return(t,n,r,o,i)=>{const u=t._1,s=t._2;return n(a=>hp(B(u,s,!1),n,r,(f,g)=>n(d=>e(t,n,r,o,i)),i))}})(),nu=(()=>{const e=Et(Ft(t=>t==='"'))(`'"'`);return(t,n,r,o,i)=>n(u=>e(t,n,r,o,(s,a)=>n(f=>{const g=Ce(pp),d=t._3&&!s._3?B(s._1,s._2,!0):s;return n(l=>g(d,n,r,o,(_,h)=>n(p=>{const m=Et(Et(Ft(N=>N==='"'))(`'"'`))(`closing '"' (unterminated string)`),J=d._3&&!_._3?B(_._1,_._2,!0):_;return n(N=>m(J,n,r,o,(v,w)=>n(b=>i(J._3&&!v._3?B(v._1,v._2,!0):v,Wn(wt(qt.foldr,h))))))})))})))})(),mp=(()=>{const e=Et(Ft(t=>t===":"))("':'");return(t,n,r,o,i)=>n(u=>Ln(t,n,r,o,(s,a)=>n(f=>Et((g,d,l,_,h)=>{const p=g._1,m=g._2;return d(J=>{const N=(v,w)=>{const b=v._3;return d(L=>{if(b)return _(v,w);const S=g._1,z=g._2;return d(F=>tc(B(S,z,!1),d,l,(j,G)=>{const P=j._3;return d(et=>P?_(j,G):nu(g,d,l,_,h))},h))})};return d(v=>e(B(p,m,!1),d,l,N,(w,b)=>d(L=>d(S=>Ln(w,d,l,N,(z,F)=>d(j=>{const G=Ce(Ft(et=>et!==`
13
+ `&&et!=="\r"&&et!=="#"&&et!=="}")),P=w._3&&!z._3?B(z._1,z._2,!0):z;return d(et=>G(P,d,l,N,(K,A)=>d(H=>h(P._3&&!K._3?B(K._1,K._2,!0):K,Mg(Wn(wt(qt.foldr,A)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(t._3&&!s._3?B(s._1,s._2,!0):s,n,r,o,i))))})(),yp=(e,t,n,r,o)=>{const i=e._1,u=e._2;return t(s=>tc(B(i,u,!1),t,n,(a,f)=>{const g=a._3;return t(d=>g?r(a,f):nu(e,t,n,r,o))},o))},Gr=Ft(e=>e>="0"&&e<="9"),Je=(()=>{const e=Et(Ft(t=>t==="_"))("'_'");return(t,n,r,o,i)=>n(u=>{const s=(g,d)=>n(l=>{const _=Ce((()=>{const p=Et(Ft(J=>J==="_"))("'_'"),m=Et(Ft(J=>J==="-"))("'-'");return(J,N,v,w,b)=>{const L=J._1,S=J._2;return N(z=>To(B(L,S,!1),N,v,(F,j)=>{const G=F._3;return N(P=>{if(G)return w(F,j);const et=J._1,K=J._2;return N(A=>Gr(B(et,K,!1),N,v,(H,R)=>{const C=H._3;return N(D=>{if(C)return w(H,R);const W=J._1,M=J._2;return N(Y=>p(B(W,M,!1),N,v,(X,V)=>{const Q=X._3;return N(I=>Q?w(X,V):m(J,N,v,w,b))},b))})},b))})},b))}})()),h=t._3&&!g._3?B(g._1,g._2,!0):g;return n(p=>_(h,n,r,o,(m,J)=>n(N=>i(h._3&&!m._3?B(m._1,m._2,!0):m,oi(d)+Wn(wt(qt.foldr,J))))))}),a=t._1,f=t._2;return n(g=>To(B(a,f,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?o(d,l):e(t,n,r,o,s))},s))})})(),Jp=Et((e,t,n,r,o)=>{const i=e._1,u=e._2;return t(s=>nu(B(i,u,!1),t,n,(a,f)=>{const g=a._3;return t(d=>g?r(a,f):Je(e,t,n,r,o))},o))})("frame name (identifier or quoted string)"),Np=(e,t,n,r,o)=>t(i=>Je(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>Ln(f,t,n,r,(d,l)=>t(_=>{const h=Et((m,J,N,v,w)=>{const b=m._1,L=m._2;return J(S=>On("->")(B(b,L,!1),J,N,(z,F)=>{const j=z._3;return J(G=>j?v(z,F):On("<-")(m,J,N,v,w))},w))})("'->' or '<-'"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=p._3&&!J._3?B(J._1,J._2,!0):J;return t(b=>Ln(w,t,n,r,(L,S)=>t(z=>{const F=Et(Je)("target node identifier"),j=w._3&&!L._3?B(L._1,L._2,!0):L;return t(G=>F(j,t,n,r,(P,et)=>t(K=>{const A=Ce((R,C,D,W,M)=>{const Y=R._3;return C(X=>C(V=>Ln(R,C,D,(Q,I)=>W(B(Q._1,Q._2,Y),I),(Q,I)=>C(U=>C(O=>{const gt=R._3&&!Q._3?B(Q._1,Q._2,!0):Q;return yp(gt,C,D,(pt,at)=>W(B(pt._1,pt._2,Y),at),(pt,at)=>C(lt=>M(gt._3&&!pt._3?B(pt._1,pt._2,!0):pt,at)))})))))}),H=j._3&&!P._3?B(P._1,P._2,!0):P;return t(R=>A(H,t,n,r,(C,D)=>t(W=>(()=>{if(N==="<-"){const Y=wn("Token",{from:et,to:s,labels:wt(qt.foldr,D)});return(X,V,Q,I,U)=>U(X,Y)}const M=wn("Token",{from:s,to:et,labels:wt(qt.foldr,D)});return(Y,X,V,Q,I)=>I(Y,M)})()(H._3&&!C._3?B(C._1,C._2,!0):C,t,n,r,o))))})))})))})))})))}))),xp=(e,t,n,r,o)=>t(i=>Gr(e,t,n,r,(u,s)=>t(a=>{const f=Ce(Gr),g=e._3&&!u._3?B(u._1,u._2,!0):u;return t(d=>f(g,t,n,r,(l,_)=>t(h=>{const p=mc(oi(s)+Wn(wt(qt.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(J,N,v,w,b)=>b(J,m)}if(p.tag==="Nothing")return(m,J,N,v,w)=>w(m,0);c()})()(g._3&&!l._3?B(l._1,l._2,!0):l,t,n,r,o)})))}))),wo=e=>(t,n,r,o,i)=>{const u=t._3;return n(s=>On(e)(t,n,r,(a,f)=>o(B(a._1,a._2,u),f),(a,f)=>n(g=>{const d=ji((()=>{const _=Et(Ft(p=>p==="_"))("'_'"),h=Et(Ft(p=>p==="-"))("'-'");return(p,m,J,N,v)=>{const w=p._1,b=p._2;return m(L=>To(B(w,b,!1),m,J,(S,z)=>{const F=S._3;return m(j=>{if(F)return N(S,z);const G=p._1,P=p._2;return m(et=>Gr(B(G,P,!1),m,J,(K,A)=>{const H=K._3;return m(R=>{if(H)return N(K,A);const C=p._1,D=p._2;return m(W=>_(B(C,D,!1),m,J,(M,Y)=>{const X=M._3;return m(V=>X?N(M,Y):h(p,m,J,N,v))},v))})},v))})},v))}})()),l=t._3&&!a._3?B(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>o(B(h._1,h._2,u),p),(h,p)=>n(m=>{const J=l._3&&!h._3?B(h._1,h._2,!0):h;return n(N=>Se(J,n,r,(v,w)=>o(B(v._1,v._2,u),w),(v,w)=>n(b=>i(J._3&&!v._3?B(v._1,v._2,!0):v,e))))})))})))},vp=(e,t,n,r,o)=>t(i=>We(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>wo("via")(f,t,n,r,(d,l)=>t(_=>{const h=f._3&&!d._3?B(d._1,d._2,!0):d;return t(p=>Je(h,t,n,r,(m,J)=>t(N=>{const v=h._3&&!m._3?B(m._1,m._2,!0):m;return t(w=>We(v,t,n,r,(b,L)=>t(S=>{const z=v._3&&!b._3?B(b._1,b._2,!0):b;return t(F=>Je(z,t,n,r,(j,G)=>t(P=>o(z._3&&!j._3?B(j._1,j._2,!0):j,{from:J,to:G}))))})))})))})))}))),Xn=e=>(t,n,r,o,i)=>{const u=t._3;return n(s=>On(e)(t,n,r,(a,f)=>o(B(a._1,a._2,u),f),(a,f)=>n(g=>{const d=ji((()=>{const _=Et(Ft(p=>p==="_"))("'_'"),h=Et(Ft(p=>p==="-"))("'-'");return(p,m,J,N,v)=>{const w=p._1,b=p._2;return m(L=>To(B(w,b,!1),m,J,(S,z)=>{const F=S._3;return m(j=>{if(F)return N(S,z);const G=p._1,P=p._2;return m(et=>Gr(B(G,P,!1),m,J,(K,A)=>{const H=K._3;return m(R=>{if(H)return N(K,A);const C=p._1,D=p._2;return m(W=>_(B(C,D,!1),m,J,(M,Y)=>{const X=M._3;return m(V=>X?N(M,Y):h(p,m,J,N,v))},v))})},v))})},v))}})()),l=t._3&&!a._3?B(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>o(B(h._1,h._2,u),p),(h,p)=>n(m=>i(l._3&&!h._3?B(h._1,h._2,!0):h,void 0))))})))},Tp=(e,t,n,r,o)=>t(i=>Xn("+edge")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>We(f,t,n,r,(d,l)=>t(_=>{const h=Et(Je)("source node identifier"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=p._3&&!J._3?B(J._1,J._2,!0):J;return t(b=>We(w,t,n,r,(L,S)=>t(z=>{const F=Et(Je)("target node identifier"),j=w._3&&!L._3?B(L._1,L._2,!0):L;return t(G=>F(j,t,n,r,(P,et)=>t(K=>o(j._3&&!P._3?B(P._1,P._2,!0):P,wn("AddEdge",{from:N,to:et})))))})))})))})))}))),wp=(e,t,n,r,o)=>t(i=>Xn("+node")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>We(f,t,n,r,(d,l)=>t(_=>{const h=Et(Je)("node identifier"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=p._3&&!J._3?B(J._1,J._2,!0):J;return t(b=>mp(w,t,n,r,(L,S)=>t(z=>o(w._3&&!L._3?B(L._1,L._2,!0):L,wn("AddNode",{id:N,label:S})))))})))})))}))),Lp=(e,t,n,r,o)=>t(i=>Xn("-edge")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>We(f,t,n,r,(d,l)=>t(_=>{const h=Et(Je)("source node identifier"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=p._3&&!J._3?B(J._1,J._2,!0):J;return t(b=>We(w,t,n,r,(L,S)=>t(z=>{const F=Et(Je)("target node identifier"),j=w._3&&!L._3?B(L._1,L._2,!0):L;return t(G=>F(j,t,n,r,(P,et)=>t(K=>o(j._3&&!P._3?B(P._1,P._2,!0):P,wn("DelEdge",{from:N,to:et})))))})))})))})))}))),Ep=(e,t,n,r,o)=>t(i=>Xn("-node")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>We(f,t,n,r,(d,l)=>t(_=>{const h=Et(Je)("node identifier"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=Ce((L,S,z,F,j)=>{const G=L._3;return vp(L,S,z,(P,et)=>F(B(P._1,P._2,G),et),j)}),b=p._3&&!J._3?B(J._1,J._2,!0):J;return t(L=>w(b,t,n,r,(S,z)=>t(F=>o(b._3&&!S._3?B(S._1,S._2,!0):S,wn("DelNode",{id:N,via:wt(qt.foldr,z)})))))})))})))}))),kp=(e,t,n,r,o)=>t(i=>Xn("~edge")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>We(f,t,n,r,(d,l)=>t(_=>{const h=Et(Je)("source node identifier"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=p._3&&!J._3?B(J._1,J._2,!0):J;return t(b=>We(w,t,n,r,(L,S)=>t(z=>{const F=Et(Je)("target node identifier"),j=w._3&&!L._3?B(L._1,L._2,!0):L;return t(G=>F(j,t,n,r,(P,et)=>t(K=>{const A=j._3&&!P._3?B(P._1,P._2,!0):P;return t(H=>Se(A,t,n,r,(R,C)=>t(D=>{const W=Et(On("->"))("'->'"),M=A._3&&!R._3?B(R._1,R._2,!0):R;return t(Y=>W(M,t,n,r,(X,V)=>t(Q=>{const I=M._3&&!X._3?B(X._1,X._2,!0):X;return t(U=>Se(I,t,n,r,(O,gt)=>t(pt=>{const at=Et(Je)("new source node identifier"),lt=I._3&&!O._3?B(O._1,O._2,!0):O;return t(Tt=>at(lt,t,n,r,(Gt,dt)=>t(Mt=>{const mt=lt._3&&!Gt._3?B(Gt._1,Gt._2,!0):Gt;return t(ft=>We(mt,t,n,r,(rt,nt)=>t(st=>{const yt=Et(Je)("new target node identifier"),Jt=mt._3&&!rt._3?B(rt._1,rt._2,!0):rt;return t(Ct=>yt(Jt,t,n,r,(Qt,ne)=>t(He=>o(Jt._3&&!Qt._3?B(Qt._1,Qt._2,!0):Qt,wn("RepointEdge",{from:N,to:et,newFrom:dt,newTo:ne})))))})))})))})))})))})))})))})))})))})))}))),bp=(e,t,n,r,o)=>t(i=>Oa(e,t,n,r,(u,s)=>t(a=>{const f=Et(Za([wp,Ep,kp,Tp,Lp,Np]))("statement (+node, -node, +edge, -edge, ~edge, or 'a -> b')"),g=e._3&&!u._3?B(u._1,u._2,!0):u;return t(d=>f(g,t,n,r,(l,_)=>t(h=>o(g._3&&!l._3?B(l._1,l._2,!0):l,Ki("Leaf",{op:_,line:s.line,column:s.column})))))}))),Cp=(e,t,n,r,o)=>t(i=>Xn("seed")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>Ln(f,t,n,r,(d,l)=>t(_=>{const h=Et(xp)("integer (seed value)"),p=f._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(J,N)=>t(v=>{const w=p._3&&!J._3?B(J._1,J._2,!0):J;return t(b=>Se(w,t,n,r,(L,S)=>t(z=>o(w._3&&!L._3?B(L._1,L._2,!0):L,N))))})))})))}))),ru=fp((()=>{const e=Et(Ft(t=>t==="{"))("'{'");return(t,n,r,o,i)=>n(u=>n(s=>e(t,n,r,o,(a,f)=>n(g=>n(d=>{const l=t._3&&!a._3?B(a._1,a._2,!0):a;return Se(l,n,r,o,(_,h)=>n(p=>i(l._3&&!_._3?B(_._1,_._2,!0):_,h)))})))))})())(Et((()=>{const e=Et(Ft(t=>t==="}"))("'}'");return(t,n,r,o,i)=>n(u=>n(s=>Se(t,n,r,o,(a,f)=>n(g=>n(d=>{const l=t._3&&!a._3?B(a._1,a._2,!0):a;return e(l,n,r,o,(_,h)=>n(p=>i(l._3&&!_._3?B(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),Sp=(e,t,n,r,o)=>t(i=>wo("seq")(e,t,n,r,(u,s)=>t(a=>ru(ou(Va))(e._3&&!u._3?B(u._1,u._2,!0):u,t,n,r,o)))),Pp=(e,t,n,r,o)=>t(i=>wo("par")(e,t,n,r,(u,s)=>t(a=>ru(ou(Rh))(e._3&&!u._3?B(u._1,u._2,!0):u,t,n,r,o)))),ou=e=>{const t=Ce(Gp());return(n,r,o,i,u)=>r(s=>t(n,r,o,i,(a,f)=>r(g=>u(n._3&&!a._3?B(a._1,a._2,!0):a,e(wt(qt.foldr,f))))))},Gp=oc(()=>{const e=ji(Et(Ft(t=>t==="}"))("'}'"));return(t,n,r,o,i)=>n(u=>{const s=t._3;return n(a=>n(f=>Se(t,n,r,(g,d)=>o(B(g._1,g._2,s),d),(g,d)=>n(l=>n(_=>{const h=t._3&&!g._3?B(g._1,g._2,!0):g;return e(h,n,r,(p,m)=>o(B(p._1,p._2,s),m),(p,m)=>n(J=>{const N=h._3&&!p._3?B(p._1,p._2,!0):p;return n(v=>{const w=Za([(L,S,z,F,j)=>{const G=L._3;return Pp(L,S,z,(P,et)=>F(B(P._1,P._2,G),et),j)},(L,S,z,F,j)=>{const G=L._3;return Sp(L,S,z,(P,et)=>F(B(P._1,P._2,G),et),j)},bp]),b=t._3&&!N._3?B(N._1,N._2,!0):N;return n(L=>w(b,n,r,o,(S,z)=>n(F=>{const j=b._3&&!S._3?B(S._1,S._2,!0):S;return n(G=>Ln(j,n,r,o,(P,et)=>n(K=>{const A=j._3&&!P._3?B(P._1,P._2,!0):P;return n(H=>lp(A,n,r,o,(R,C)=>n(D=>i(A._3&&!R._3?B(R._1,R._2,!0):R,z))))})))})))})}))})))))})}),Dp=(e,t,n,r,o)=>t(i=>wo("frame")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>Jp(f,t,n,r,(d,l)=>t(_=>{const h=f._3&&!d._3?B(d._1,d._2,!0):d;return t(p=>Se(h,t,n,r,(m,J)=>t(N=>{const v=ru(ou(Va)),w=h._3&&!m._3?B(m._1,m._2,!0):m;return t(b=>v(w,t,n,r,(L,S)=>t(z=>{const F=w._3&&!L._3?B(L._1,L._2,!0):L;return t(j=>Se(F,t,n,r,(G,P)=>t(et=>o(F._3&&!G._3?B(G._1,G._2,!0):G,{name:k("Just",l),ops:S}))))})))})))})))}))),Wp=(e,t,n,r,o)=>t(i=>Se(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>{const d=(h,p)=>t(m=>{const J=Ce(Dp),N=f._3&&!h._3?B(h._1,h._2,!0):h;return t(v=>J(N,t,n,r,(w,b)=>t(L=>{const S=N._3&&!w._3?B(w._1,w._2,!0):w;return t(z=>Se(S,t,n,r,(F,j)=>t(G=>{const P=Et(Ka)("'frame' or end of input"),et=S._3&&!F._3?B(F._1,F._2,!0):F;return t(K=>P(et,t,n,r,(A,H)=>t(R=>o(et._3&&!A._3?B(A._1,A._2,!0):A,{seed:(()=>{if(p.tag==="Just")return p._1;if(p.tag==="Nothing")return 0;c()})(),frames:wt(qt.foldr,b)}))))})))})))}),l=f._1,_=f._2;return t(h=>t(p=>Cp(B(l,_,!1),t,n,(m,J)=>{const N=m._3;return t(v=>N?r(m,J):d(f,T))},(m,J)=>t(N=>d(m,k("Just",J))))))})}))),Mp=e=>{const t=op(e)(Wp);if(t.tag==="Left")return Lt("Left",{msg:t._1._1,line:t._1._2.line,column:t._1._2.column});if(t.tag==="Right")return Lt("Right",t._1);c()},Rp=e=>{const t=Mp(e);if(t.tag==="Left")return Lt("Left",t._1.msg);if(t.tag==="Right")return Lt("Right",t._1);c()};function iu(e,t,n,r){if(typeof window<"u"){var o=window[n];if(o!=null&&r instanceof o)return t(r)}for(var i=r;i!=null;){var u=Object.getPrototypeOf(i),s=u.constructor.name;if(s===n)return t(r);if(s==="Object")return e;i=u}return e}function uu(e){return function(t){return function(n){return function(){n.setAttribute(e,t)}}}}function Ip(e){return function(t){return function(){t.textContent=e}}}function zp(e){return function(){return function(t){return e(t)()}}}function Bp(e){return function(t){return function(n){return function(r){return function(){return r.addEventListener(e,t,n)}}}}}const Ap=function(){return window};function Qp(e){return function(t){return function(){t.value=e}}}function qp(e){return function(){return e.valueAsNumber}}function Hp(e){return function(){return e.value}}function Vp(e){return function(t){return function(){return t.requestAnimationFrame(e)}}}const Yp=e=>e,Fp=e=>()=>e.clientWidth||0,$p=()=>window.devicePixelRatio||1,ec=(e,t)=>{t.innerHTML=e},Op=(e,t,n)=>{e.style.setProperty(t,n)},Xp=(e,t)=>e.querySelector(`[data-mg="${t}"]`),Up=e=>t=>{const n=ht.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Kp=zt.foldMap(Nc),Zp=e=>t=>{const n=e-t*_t(tr(mu(e/t)));return t<=0?0:n<0?n+t:n},jp=`
14
+ <canvas data-mg="stage" tabindex="0"></canvas>
15
+ <div data-mg="play-overlay" aria-hidden="true"></div>
16
+ <div data-mg="bar">
17
+ <button data-mg="play" type="button" aria-label="play" data-mg-playing="0"></button>
18
+ <div data-mg="scrub-wrap">
19
+ <input data-mg="scrub" type="range" min="0" max="1000" value="0" step="1"/>
20
+ <div data-mg="ticks"></div>
21
+ </div>
22
+ <span data-mg="time">0.00 / 0.00</span>
23
+ <select data-mg="speed" aria-label="speed">
24
+ <option value="0.25">0.25\xD7</option>
25
+ <option value="0.5">0.5\xD7</option>
26
+ <option value="1" selected>1\xD7</option>
27
+ <option value="2">2\xD7</option>
28
+ </select>
29
+ </div>
30
+ `,en=e=>t=>n=>()=>{const r=Xp(e,t),o=xc(r,T,Kt);if(o.tag==="Just")return n(o._1)();o.tag!=="Nothing"&&c()},su=e=>t=>n=>{const r=Up(n)(t.totalDuration),o=t1(t)(r),i=en(e)("stage")(u=>{const s=t.layout,a=Yp(u),f=Zu(s)(o.camera),g=f.w+48,d=f.h+48,l=Fp(u);return()=>{const _=l(),h=g<=0?_:_*d/g,p=$p(),m=_*p,J=h*p,N=Dc(a)(),v=Wc(a)(),w=Mc(a)(m);N!==m&&w();const b=Rc(a)(J);v!==J&&b(),Op(u,"height",Te(tr(yu(h)))+"px");const L=Gc(a)();return nr(L)(),Fo(L)({scaleX:p,scaleY:p})(),Ch(L)({width:_,height:h})(s)(o)(),rr(L)()}});return()=>(i(),en(e)("time")(u=>Ip(Bo(Io("Fixed",zo(0)(20)(2)))(r)+" / "+Bo(Io("Fixed",zo(0)(20)(2)))(t.totalDuration))(u))())},tm=e=>t=>{const n=t.totalDuration<=0?1:t.totalDuration,r=Kp(o=>'<span class="mg-tick" style="left:'+Bo(Io("Fixed",zo(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;c()})()+'"></span>')(t.spans);return en(e)("ticks")(o=>()=>ec(r,o))},em=e=>t=>n=>en(e)("scrub")(r=>{const o=iu(T,Kt,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return n<=0?()=>{}:Qp(Te(tr(yu(t/n*1e3))))(o._1);c()}),au=e=>t=>n=>{const r=zp(o=>n);return()=>{const o=r();return Bp(e)(o)(!1)(t)()}},nm=e=>{const t=Rp(e);if(t.tag==="Left")return Lt("Left",t._1);if(t.tag==="Right"){const n=Zh(t._1);if(n.tag==="Left")return Lt("Left",n._1.msg);if(n.tag==="Right")return Lt("Right",n._1)}c()},rm=e=>t=>en(e)("speed")(n=>{const r=iu(T,Kt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return au("change")(n)((()=>{const o=Hp(r._1);return()=>{const i=o(),u=lc(i,lu,Kt,T);if(u.tag==="Just")return t.value=u._1;u.tag!=="Nothing"&&c()}})());c()}),om=e=>t=>n=>r=>en(e)("scrub")(o=>{const i=iu(T,Kt,"HTMLInputElement",o);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return au("input")(o)((()=>{const u=qp(i._1);return()=>{const s=u()/1e3*r.totalDuration;return n.value=!1,t.value=s,su(e)(r)(s)(),en(e)("play")(a=>uu("data-mg-playing")("0")(a))()}})());c()}),im=e=>t=>n=>en(e)("play")(r=>au("click")(r)(()=>{const o=!t.value;if(t.value=o,uu("data-mg-playing")(o?"1":"0")(r)(),o)return n()})),um=e=>t=>()=>{const n={value:1},r={value:!0};let o=!1;const i={value:0};let u=0;tm(e)(t)(),su(e)(t)(0)(),en(e)("play")(g=>uu("data-mg-playing")("1")(g))();const s=()=>{if(o=!1,r.value){const g=Pc(),d=u;u=g;const l=n.value,_=i.value,h=Zp(d===0?_+0*l:_+(g-d)/1e3*l)(t.totalDuration+.8);return i.value=h,su(e)(t)(h)(),em(e)(h)(t.totalDuration)(),a()}},a=()=>{if(!o){o=!0;const g=Ap();Vp(s)(g)()}},f=()=>(u=0,a());return rm(e)(n)(),im(e)(r)(f)(),om(e)(i)(r)(t)(),f()},nc=e=>t=>{const n=nm(t);if(n.tag==="Left")return Nu("[markgraf] parse failed: "+n._1);if(n.tag==="Right"){const r=n._1;return()=>{ec(jp,e);const o=Xl(r)(),i=k_(J_)(r)(t0(o)(r));if(i.tag==="Left")return Nu("[markgraf] precompute failed")();if(i.tag==="Right")return um(e)(i._1)();c()}}c()},sm=e=>{const t=e.getAttribute("data-markgraf-src-b64");if(t)try{return decodeURIComponent(escape(atob(t)))}catch{return atob(t)}return e.getAttribute("data-markgraf-src")||e.textContent||""};let qe=null;const cu=e=>e.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",am=e=>{const t=e.querySelector('[data-mg="play"]');if(!t)return;t.addEventListener("click",()=>{queueMicrotask(()=>{cu(e)?(qe&&qe!==e&&cu(qe)&&qe.querySelector('[data-mg="play"]').click(),qe=e):qe===e&&(qe=null)})});const n=r=>{r.preventDefault(),t.click()};e.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},cm=e=>{if(e.dataset.markgrafMounted==="1")return;e.dataset.markgrafMounted="1";const t=sm(e);e.textContent="",nc(e)(t)(),qe===null?qe=e:cu(e)&&e.querySelector('[data-mg="play"]').click(),am(e)},Lo=(e=document)=>{e.querySelectorAll("[data-markgraf]").forEach(cm)},rc=()=>{document.addEventListener("keydown",e=>{if(e.code!=="Space"&&e.key!==" ")return;const t=e.target,n=t&&t.closest?.("[data-markgraf]");if(!n){const o=t?.tagName,i=(t?.type||"").toLowerCase();if(t?.isContentEditable||o==="TEXTAREA"||o==="SELECT"||o==="INPUT"&&!["range","checkbox","radio","button","submit","reset"].includes(i))return}const r=n||qe||document.querySelector("[data-markgraf]");r&&(e.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};return typeof window<"u"&&(window.markgraf={mount:(e,t)=>nc(e)(t)(),mountAll:Lo},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{Lo(),rc()}):(Lo(),rc())),Eo.mountAll=Lo,Object.defineProperty(Eo,Symbol.toStringTag,{value:"Module"}),Eo})({});
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@markgrafhq/markgraf-embed",
3
+ "version": "0.1.0",
4
+ "description": "Embeddable Canvas2D player for markgraf animations. Drop-in for any HTML page or bundler.",
5
+ "type": "module",
6
+ "main": "./dist/markgraf-embed.js",
7
+ "module": "./dist/markgraf-embed.js",
8
+ "browser": "./dist/markgraf-embed.js",
9
+ "style": "./dist/markgraf-embed.css",
10
+ "exports": {
11
+ ".": {
12
+ "default": "./dist/markgraf-embed.js"
13
+ },
14
+ "./dist/markgraf-embed.js": "./dist/markgraf-embed.js",
15
+ "./dist/markgraf-embed.css": "./dist/markgraf-embed.css",
16
+ "./css": "./dist/markgraf-embed.css"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "sideEffects": true,
24
+ "keywords": [
25
+ "markgraf",
26
+ "animation",
27
+ "diagram",
28
+ "graph",
29
+ "canvas",
30
+ "embed",
31
+ "documentation"
32
+ ],
33
+ "license": "MIT",
34
+ "author": "Mark Eibes <mark.eibes@gmail.com>",
35
+ "homepage": "https://github.com/markgrafhq/markgraf-www#readme",
36
+ "bugs": "https://github.com/markgrafhq/markgraf-www/issues",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/markgrafhq/markgraf-www.git"
40
+ }
41
+ }