-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
688 lines (610 loc) · 335 KB
/
index.html
File metadata and controls
688 lines (610 loc) · 335 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
<html>
<head>
<style>@font-face {
font-family: dos;
/*src: url("static/dos.woff") format('woff');*/
src: url("static/PxPlus_IBM_VGA8.ttf") format('truetype');
}
body {
margin: 0px;
}
.menubar {
background-color: #aaaaaa;
color: black;
}
.menubar, .menuitem, #opendialog *, .runscreen *, #loading * {
font-family: dos;
font-size: 15pt;
}
table {
font-size: unset;
}
.CodeMirror {
height: 100% !important;
}
.menuitem {
background-color: #aaaaaa;
color: black;
margin-left: 0.5em;
margin-right: 0.5em;
cursor: pointer;
}
.menustatus{
background-color: #aaaaaa;
color:yellow;
margin-left: 0.5em;
margin-right: 0.5em;
}
.menutitlespacer{
width: 2em;
display: table-cell;
}
.menutitle {
display: table-cell;
}
.menuitem:hover {
background-color: white;
color: black;
}
.selecteditem {
background-color: black;
color: white;
}
.popupmenu {
background-color: #aaaaaa;
color: black;
font-family: monospace;
position: absolute;
z-index: 100;
display: none;
}
.menuopen {
display: block;
}
.workspace {
background-color: #0000aa;
color: #aaaaaa;
width: 100%;
height: 100%;
position: relative;
}
.runscreen {
width: 100%;
height: 100vw;
}
.canvasbox{
width: 100vw;
height:75vw;
}
/*
.canvas {
width: 640px;
height:480px;
}
*/
.hidden {
display: none !important;
}
.statusbar {
background-color: #00aaaa;
color: black;
}
#opendialog {
background-color: #aaaaaa;
color: black;
position: fixed;
width: 50%;
height: 80%;
top: 30px;
left: 25%;
z-index: 100;
}
.titlebar {
text-align: center;
height: 0.5em;
}
.programlist {
padding: 20px;
margin: 20px;
border: black;
border-style: solid;
border-width: 1px;
position: relative;
height: 90%;
}
.textbutton {
text-align: center;
}
.textbutton:hover {
background-color: white;
color: black;
}
#openprogramtable td:hover {
background-color: white;
color: black;
}
.X {
float: right;
cursor: pointer;
}
#loading {
position: fixed;
z-index: 999;
width: 40vw;
height: 5em;
background-color: #aaaaaa;
border-color: black;
border-style: solid;
border-width: 1px;
top: 40%;
left:30vw;
text-align: center;
vertical-align: center;
line-height: 5em;
margin: 20px;
}
.cm-s-dos.CodeMirror {
background: #0000aa;
color: #aaaaaa;
}
.cm-s-dos div.CodeMirror-selected {
background-color: white;
}
.cm-s-dos .cm-header {color: blue;}
.cm-s-dos .cm-quote {color: #090;}
.cm-s-dos .cm-keyword {color: #708;}
.cm-s-dos .cm-atom {color: #219;}
.cm-s-dos .cm-number {color: #164;}
.cm-s-dos .cm-def {color: #00f;}
.cm-s-dos .cm-variable,
.cm-s-dos .cm-punctuation,
.cm-s-dos .cm-property,
.cm-s-dos .cm-operator {}
.cm-s-dos .cm-variable-2 {color: #05a;}
.cm-s-dos .cm-variable-3, .cm-s-dos .cm-type {color: #085;}
.cm-s-dos .cm-comment {color: #777777;}
.cm-s-dos .cm-string {color:#00aaaa;}
.cm-s-dos .cm-string-2 {color: #00aaaa;}
.cm-s-dos .cm-meta {color: #555;}
.cm-s-dos .cm-qualifier {color: #555;}
.cm-s-dos .cm-builtin {color: #30a;}
.cm-s-dos .cm-bracket {color: #997;}
.cm-s-dos .cm-tag {color: #170;}
.cm-s-dos .cm-attribute {color: #00c;}
.cm-s-dos .cm-hr {color: #999;}
.cm-s-dos .cm-link {color: #00c;}
.cm-s-dos .cm-error {color: #f00;}
.cm-s-dos .CodeMirror-cursor { border-left: 2px solid white; }
.CodeMirror {
font-size: 15pt;
font-family: dos !important;
}
/* The lint marker gutter */
.CodeMirror-lint-markers {
width: 16px;
}
.CodeMirror-lint-tooltip {
background-color: #ffd;
border: 1px solid black;
border-radius: 4px 4px 4px 4px;
color: black;
font-family: monospace;
font-size: 10pt;
overflow: hidden;
padding: 2px 5px;
position: fixed;
white-space: pre;
white-space: pre-wrap;
z-index: 100;
max-width: 600px;
opacity: 0;
transition: opacity .4s;
-moz-transition: opacity .4s;
-webkit-transition: opacity .4s;
-o-transition: opacity .4s;
-ms-transition: opacity .4s;
}
.CodeMirror-lint-mark-error, .CodeMirror-lint-mark-warning {
background-position: left bottom;
background-repeat: repeat-x;
}
.CodeMirror-lint-mark-error {
background-image:
url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJDw4cOCW1/KIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAHElEQVQI12NggIL/DAz/GdA5/xkY/qPKMDAwAADLZwf5rvm+LQAAAABJRU5ErkJggg==")
;
}
.CodeMirror-lint-mark-warning {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJFhQXEbhTg7YAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAMklEQVQI12NkgIIvJ3QXMjAwdDN+OaEbysDA4MPAwNDNwMCwiOHLCd1zX07o6kBVGQEAKBANtobskNMAAAAASUVORK5CYII=");
}
.CodeMirror-lint-marker-error, .CodeMirror-lint-marker-warning {
background-position: center center;
background-repeat: no-repeat;
cursor: pointer;
display: inline-block;
height: 16px;
width: 16px;
vertical-align: middle;
position: relative;
}
.CodeMirror-lint-message-error, .CodeMirror-lint-message-warning {
padding-left: 18px;
background-position: top left;
background-repeat: no-repeat;
}
.CodeMirror-lint-marker-error, .CodeMirror-lint-message-error {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII=");
}
.CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII=");
}
.CodeMirror-lint-marker-multiple {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC");
background-repeat: no-repeat;
background-position: right bottom;
width: 100%; height: 100%;
}
</style>
<style>/* BASICS */
.CodeMirror {
/* Set height, width, borders, and global font properties here */
font-family: monospace;
height: 300px;
color: black;
direction: ltr;
}
/* PADDING */
.CodeMirror-lines {
padding: 4px 0; /* Vertical padding around content */
}
.CodeMirror pre {
padding: 0 4px; /* Horizontal padding of content */
}
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
background-color: white; /* The little square between H and V scrollbars */
}
/* GUTTER */
.CodeMirror-gutters {
border-right: 1px solid #ddd;
background-color: #f7f7f7;
white-space: nowrap;
}
.CodeMirror-linenumbers {}
.CodeMirror-linenumber {
padding: 0 3px 0 5px;
min-width: 20px;
text-align: right;
color: #999;
white-space: nowrap;
}
.CodeMirror-guttermarker { color: black; }
.CodeMirror-guttermarker-subtle { color: #999; }
/* CURSOR */
.CodeMirror-cursor {
border-left: 1px solid black;
border-right: none;
width: 0;
}
/* Shown when moving in bi-directional text */
.CodeMirror div.CodeMirror-secondarycursor {
border-left: 1px solid silver;
}
.cm-fat-cursor .CodeMirror-cursor {
width: auto;
border: 0 !important;
background: #7e7;
}
.cm-fat-cursor div.CodeMirror-cursors {
z-index: 1;
}
.cm-fat-cursor-mark {
background-color: rgba(20, 255, 20, 0.5);
-webkit-animation: blink 1.06s steps(1) infinite;
-moz-animation: blink 1.06s steps(1) infinite;
animation: blink 1.06s steps(1) infinite;
}
.cm-animate-fat-cursor {
width: auto;
border: 0;
-webkit-animation: blink 1.06s steps(1) infinite;
-moz-animation: blink 1.06s steps(1) infinite;
animation: blink 1.06s steps(1) infinite;
background-color: #7e7;
}
@-moz-keyframes blink {
0% {}
50% { background-color: transparent; }
100% {}
}
@-webkit-keyframes blink {
0% {}
50% { background-color: transparent; }
100% {}
}
@keyframes blink {
0% {}
50% { background-color: transparent; }
100% {}
}
/* Can style cursor different in overwrite (non-insert) mode */
.CodeMirror-overwrite .CodeMirror-cursor {}
.cm-tab { display: inline-block; text-decoration: inherit; }
.CodeMirror-rulers {
position: absolute;
left: 0; right: 0; top: -50px; bottom: -20px;
overflow: hidden;
}
.CodeMirror-ruler {
border-left: 1px solid #ccc;
top: 0; bottom: 0;
position: absolute;
}
/* DEFAULT THEME */
.cm-s-default .cm-header {color: blue;}
.cm-s-default .cm-quote {color: #090;}
.cm-negative {color: #d44;}
.cm-positive {color: #292;}
.cm-header, .cm-strong {font-weight: bold;}
.cm-em {font-style: italic;}
.cm-link {text-decoration: underline;}
.cm-strikethrough {text-decoration: line-through;}
.cm-s-default .cm-keyword {color: #708;}
.cm-s-default .cm-atom {color: #219;}
.cm-s-default .cm-number {color: #164;}
.cm-s-default .cm-def {color: #00f;}
.cm-s-default .cm-variable,
.cm-s-default .cm-punctuation,
.cm-s-default .cm-property,
.cm-s-default .cm-operator {}
.cm-s-default .cm-variable-2 {color: #05a;}
.cm-s-default .cm-variable-3, .cm-s-default .cm-type {color: #085;}
.cm-s-default .cm-comment {color: #a50;}
.cm-s-default .cm-string {color: #a11;}
.cm-s-default .cm-string-2 {color: #f50;}
.cm-s-default .cm-meta {color: #555;}
.cm-s-default .cm-qualifier {color: #555;}
.cm-s-default .cm-builtin {color: #30a;}
.cm-s-default .cm-bracket {color: #997;}
.cm-s-default .cm-tag {color: #170;}
.cm-s-default .cm-attribute {color: #00c;}
.cm-s-default .cm-hr {color: #999;}
.cm-s-default .cm-link {color: #00c;}
.cm-s-default .cm-error {color: #f00;}
.cm-invalidchar {color: #f00;}
.CodeMirror-composing { border-bottom: 2px solid; }
/* Default styles for common addons */
div.CodeMirror span.CodeMirror-matchingbracket {color: #0b0;}
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
.CodeMirror-activeline-background {background: #e8f2ff;}
/* STOP */
/* The rest of this file contains styles related to the mechanics of
the editor. You probably shouldn't touch them. */
.CodeMirror {
position: relative;
overflow: hidden;
background: white;
}
.CodeMirror-scroll {
overflow: scroll !important; /* Things will break if this is overridden */
/* 30px is the magic margin used to hide the element's real scrollbars */
/* See overflow: hidden in .CodeMirror */
margin-bottom: -30px; margin-right: -30px;
padding-bottom: 30px;
height: 100%;
outline: none; /* Prevent dragging from highlighting the element */
position: relative;
}
.CodeMirror-sizer {
position: relative;
border-right: 30px solid transparent;
}
/* The fake, visible scrollbars. Used to force redraw during scrolling
before actual scrolling happens, thus preventing shaking and
flickering artifacts. */
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
position: absolute;
z-index: 6;
display: none;
}
.CodeMirror-vscrollbar {
right: 0; top: 0;
overflow-x: hidden;
overflow-y: scroll;
}
.CodeMirror-hscrollbar {
bottom: 0; left: 0;
overflow-y: hidden;
overflow-x: scroll;
}
.CodeMirror-scrollbar-filler {
right: 0; bottom: 0;
}
.CodeMirror-gutter-filler {
left: 0; bottom: 0;
}
.CodeMirror-gutters {
position: absolute; left: 0; top: 0;
min-height: 100%;
z-index: 3;
}
.CodeMirror-gutter {
white-space: normal;
height: 100%;
display: inline-block;
vertical-align: top;
margin-bottom: -30px;
}
.CodeMirror-gutter-wrapper {
position: absolute;
z-index: 4;
background: none !important;
border: none !important;
}
.CodeMirror-gutter-background {
position: absolute;
top: 0; bottom: 0;
z-index: 4;
}
.CodeMirror-gutter-elt {
position: absolute;
cursor: default;
z-index: 4;
}
.CodeMirror-gutter-wrapper ::selection { background-color: transparent }
.CodeMirror-gutter-wrapper ::-moz-selection { background-color: transparent }
.CodeMirror-lines {
cursor: text;
min-height: 1px; /* prevents collapsing before first draw */
}
.CodeMirror pre {
/* Reset some styles that the rest of the page might have set */
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
border-width: 0;
background: transparent;
font-family: inherit;
font-size: inherit;
margin: 0;
white-space: pre;
word-wrap: normal;
line-height: inherit;
color: inherit;
z-index: 2;
position: relative;
overflow: visible;
-webkit-tap-highlight-color: transparent;
-webkit-font-variant-ligatures: contextual;
font-variant-ligatures: contextual;
}
.CodeMirror-wrap pre {
word-wrap: break-word;
white-space: pre-wrap;
word-break: normal;
}
.CodeMirror-linebackground {
position: absolute;
left: 0; right: 0; top: 0; bottom: 0;
z-index: 0;
}
.CodeMirror-linewidget {
position: relative;
z-index: 2;
padding: 0.1px; /* Force widget margins to stay inside of the container */
}
.CodeMirror-widget {}
.CodeMirror-rtl pre { direction: rtl; }
.CodeMirror-code {
outline: none;
}
/* Force content-box sizing for the elements where we expect it */
.CodeMirror-scroll,
.CodeMirror-sizer,
.CodeMirror-gutter,
.CodeMirror-gutters,
.CodeMirror-linenumber {
-moz-box-sizing: content-box;
box-sizing: content-box;
}
.CodeMirror-measure {
position: absolute;
width: 100%;
height: 0;
overflow: hidden;
visibility: hidden;
}
.CodeMirror-cursor {
position: absolute;
pointer-events: none;
}
.CodeMirror-measure pre { position: static; }
div.CodeMirror-cursors {
visibility: hidden;
position: relative;
z-index: 3;
}
div.CodeMirror-dragcursors {
visibility: visible;
}
.CodeMirror-focused div.CodeMirror-cursors {
visibility: visible;
}
.CodeMirror-selected { background: #d9d9d9; }
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
.CodeMirror-crosshair { cursor: crosshair; }
.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }
.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; }
.cm-searching {
background-color: #ffa;
background-color: rgba(255, 255, 0, .4);
}
/* Used to force a border model for a node */
.cm-force-border { padding-right: .1px; }
@media print {
/* Hide the cursor when printing */
.CodeMirror div.CodeMirror-cursors {
visibility: hidden;
}
}
/* See issue #2901 */
.cm-tab-wrap-hack:after { content: ''; }
/* Help users use markselection to safely style text background */
span.CodeMirror-selectedtext { background: none; }
</style>
</head>
<body>
<div id="editscreen">
<div id="menubar" class="menubar">
<div id="file" class="menuitem menutitle" onclick="qb.showMenu('filemenu')">File
<div id="filemenu" class="popupmenu">
<div id="new" class="menuitem" onclick="qb.newfile()">New</div>
<div id="new" class="menuitem" onclick="qb.open()">Open</div>
<div class="menuitem">----</div>
<div id="save" class="menuitem" onclick="qb.save()">Save</div>
<div id="save" class="menuitem" onclick="qb.deleteprogram()">Delete</div>
<div id="share" class="menuitem">Share</div>
</div>
</div>
<div class="menutitlespacer"></div>
<div id="run" class="menuitem menutitle" onclick="qb.showMenu('runmenu')">Run
<div id="runmenu" class="popupmenu">
<div id="start" class="menuitem" onclick="qb.start();">Start [ Ctrl+/ ]</div>
</div>
</div>
</div>
<div id="loading" class="hidden">
~ Loading ~
</div>
<div id="opendialog" class="hidden">
<div class="titlebar">Open Program<div class="X" onclick="qb.closeOpenDialog()">X</div></div>
<div class="programlist">
<div style="max-height: 85%; overflow-y:scroll">
<table id="openprogramtable">
</table>
</div>
</div>
</div>
<div id="workspace" class="workspace" onclick="qb.hideMenus()">
<textarea id="editor" class="workspace editor" style="height: 100%"></textarea>
</div>
</div>
<div id="runscreen" class="runscreen hidden">
<div id="runbar" class="menubar">
<div id="program_running" class="menustatus menutitle">Running Program...</div>
<div id="program_complete" class="menustatus menutitle hidden">Program Complete, Press a key...</div>
<div class="menutitlespacer"></div>
<div class="menuitem menutitle" onclick="qb.restart()">Restart</div>
<div class="menutitlespacer"></div>
<div class="menuitem menutitle" onclick="qb.stop()">Return To Editor</div>
<div class="menutitlespacer"></div>
</div>
<div id="canvasholder"></div>
</div>
</body>
<script async>var qb=function(t){var e={};function r(i){if(e[i])return e[i].exports;var n=e[i]={i:i,l:!1,exports:{}};return t[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=t,r.c=e,r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(i,n,function(e){return t[e]}.bind(null,n));return i},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=9)}([function(t,e,r){t.exports=function(){"use strict";var t=navigator.userAgent,e=navigator.platform,r=/gecko\/\d/i.test(t),i=/MSIE \d/.test(t),n=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(t),s=/Edge\/(\d+)/.exec(t),o=i||n||s,a=o&&(i?document.documentMode||6:+(s||n)[1]),l=!s&&/WebKit\//.test(t),c=l&&/Qt\/\d+\.\d+/.test(t),h=!s&&/Chrome\//.test(t),u=/Opera\//.test(t),f=/Apple Computer/.test(navigator.vendor),d=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(t),p=/PhantomJS/.test(t),g=!s&&/AppleWebKit/.test(t)&&/Mobile\/\w+/.test(t),m=/Android/.test(t),v=g||m||/webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(t),y=g||/Mac/.test(e),b=/\bCrOS\b/.test(t),x=/win/i.test(e),w=u&&t.match(/Version\/(\d*\.\d*)/);w&&(w=Number(w[1])),w&&w>=15&&(u=!1,l=!0);var k=y&&(c||u&&(null==w||w<12.11)),S=r||o&&a>=9;function E(t){return new RegExp("(^|\\s)"+t+"(?:$|\\s)\\s*")}var T,C=function(t,e){var r=t.className,i=E(e).exec(r);if(i){var n=r.slice(i.index+i[0].length);t.className=r.slice(0,i.index)+(n?i[1]+n:"")}};function I(t){for(var e=t.childNodes.length;e>0;--e)t.removeChild(t.firstChild);return t}function O(t,e){return I(t).appendChild(e)}function L(t,e,r,i){var n=document.createElement(t);if(r&&(n.className=r),i&&(n.style.cssText=i),"string"==typeof e)n.appendChild(document.createTextNode(e));else if(e)for(var s=0;s<e.length;++s)n.appendChild(e[s]);return n}function N(t,e,r,i){var n=L(t,e,r,i);return n.setAttribute("role","presentation"),n}function A(t,e){if(3==e.nodeType&&(e=e.parentNode),t.contains)return t.contains(e);do{if(11==e.nodeType&&(e=e.host),e==t)return!0}while(e=e.parentNode)}function D(){var t;try{t=document.activeElement}catch(e){t=document.body||null}for(;t&&t.shadowRoot&&t.shadowRoot.activeElement;)t=t.shadowRoot.activeElement;return t}function R(t,e){var r=t.className;E(e).test(r)||(t.className+=(r?" ":"")+e)}function M(t,e){for(var r=t.split(" "),i=0;i<r.length;i++)r[i]&&!E(r[i]).test(e)&&(e+=" "+r[i]);return e}T=document.createRange?function(t,e,r,i){var n=document.createRange();return n.setEnd(i||t,r),n.setStart(t,e),n}:function(t,e,r){var i=document.body.createTextRange();try{i.moveToElementText(t.parentNode)}catch(t){return i}return i.collapse(!0),i.moveEnd("character",r),i.moveStart("character",e),i};var P=function(t){t.select()};function V(t){var e=Array.prototype.slice.call(arguments,1);return function(){return t.apply(null,e)}}function B(t,e,r){for(var i in e||(e={}),t)!t.hasOwnProperty(i)||!1===r&&e.hasOwnProperty(i)||(e[i]=t[i]);return e}function F(t,e,r,i,n){null==e&&-1==(e=t.search(/[^\s\u00a0]/))&&(e=t.length);for(var s=i||0,o=n||0;;){var a=t.indexOf("\t",s);if(a<0||a>=e)return o+(e-s);o+=a-s,o+=r-o%r,s=a+1}}g?P=function(t){t.selectionStart=0,t.selectionEnd=t.value.length}:o&&(P=function(t){try{t.select()}catch(t){}});var U=function(){this.id=null};function W(t,e){for(var r=0;r<t.length;++r)if(t[r]==e)return r;return-1}U.prototype.set=function(t,e){clearTimeout(this.id),this.id=setTimeout(e,t)};var H=30,G={toString:function(){return"CodeMirror.Pass"}},z={scroll:!1},_={origin:"*mouse"},X={origin:"+move"};function j(t,e,r){for(var i=0,n=0;;){var s=t.indexOf("\t",i);-1==s&&(s=t.length);var o=s-i;if(s==t.length||n+o>=e)return i+Math.min(o,e-n);if(n+=s-i,i=s+1,(n+=r-n%r)>=e)return i}}var K=[""];function q(t){for(;K.length<=t;)K.push(Y(K)+" ");return K[t]}function Y(t){return t[t.length-1]}function J(t,e){for(var r=[],i=0;i<t.length;i++)r[i]=e(t[i],i);return r}function Z(){}function Q(t,e){var r;return Object.create?r=Object.create(t):(Z.prototype=t,r=new Z),e&&B(e,r),r}var $=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;function tt(t){return/\w/.test(t)||t>""&&(t.toUpperCase()!=t.toLowerCase()||$.test(t))}function et(t,e){return e?!!(e.source.indexOf("\\w")>-1&&tt(t))||e.test(t):tt(t)}function rt(t){for(var e in t)if(t.hasOwnProperty(e)&&t[e])return!1;return!0}var it=/[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;function nt(t){return t.charCodeAt(0)>=768&&it.test(t)}function st(t,e,r){for(;(r<0?e>0:e<t.length)&&nt(t.charAt(e));)e+=r;return e}function ot(t,e,r){for(var i=e>r?-1:1;;){if(e==r)return e;var n=(e+r)/2,s=i<0?Math.ceil(n):Math.floor(n);if(s==e)return t(s)?e:r;t(s)?r=s:e=s+i}}function at(t,e){if((e-=t.first)<0||e>=t.size)throw new Error("There is no line "+(e+t.first)+" in the document.");for(var r=t;!r.lines;)for(var i=0;;++i){var n=r.children[i],s=n.chunkSize();if(e<s){r=n;break}e-=s}return r.lines[e]}function lt(t,e,r){var i=[],n=e.line;return t.iter(e.line,r.line+1,function(t){var s=t.text;n==r.line&&(s=s.slice(0,r.ch)),n==e.line&&(s=s.slice(e.ch)),i.push(s),++n}),i}function ct(t,e,r){var i=[];return t.iter(e,r,function(t){i.push(t.text)}),i}function ht(t,e){var r=e-t.height;if(r)for(var i=t;i;i=i.parent)i.height+=r}function ut(t){if(null==t.parent)return null;for(var e=t.parent,r=W(e.lines,t),i=e.parent;i;e=i,i=i.parent)for(var n=0;i.children[n]!=e;++n)r+=i.children[n].chunkSize();return r+e.first}function ft(t,e){var r=t.first;t:do{for(var i=0;i<t.children.length;++i){var n=t.children[i],s=n.height;if(e<s){t=n;continue t}e-=s,r+=n.chunkSize()}return r}while(!t.lines);for(var o=0;o<t.lines.length;++o){var a=t.lines[o],l=a.height;if(e<l)break;e-=l}return r+o}function dt(t,e){return e>=t.first&&e<t.first+t.size}function pt(t,e){return String(t.lineNumberFormatter(e+t.firstLineNumber))}function gt(t,e,r){if(void 0===r&&(r=null),!(this instanceof gt))return new gt(t,e,r);this.line=t,this.ch=e,this.sticky=r}function mt(t,e){return t.line-e.line||t.ch-e.ch}function vt(t,e){return t.sticky==e.sticky&&0==mt(t,e)}function yt(t){return gt(t.line,t.ch)}function bt(t,e){return mt(t,e)<0?e:t}function xt(t,e){return mt(t,e)<0?t:e}function wt(t,e){return Math.max(t.first,Math.min(e,t.first+t.size-1))}function kt(t,e){if(e.line<t.first)return gt(t.first,0);var r=t.first+t.size-1;return e.line>r?gt(r,at(t,r).text.length):function(t,e){var r=t.ch;return null==r||r>e?gt(t.line,e):r<0?gt(t.line,0):t}(e,at(t,e.line).text.length)}function St(t,e){for(var r=[],i=0;i<e.length;i++)r[i]=kt(t,e[i]);return r}var Et=!1,Tt=!1;function Ct(t,e,r){this.marker=t,this.from=e,this.to=r}function It(t,e){if(t)for(var r=0;r<t.length;++r){var i=t[r];if(i.marker==e)return i}}function Ot(t,e){for(var r,i=0;i<t.length;++i)t[i]!=e&&(r||(r=[])).push(t[i]);return r}function Lt(t,e){if(e.full)return null;var r=dt(t,e.from.line)&&at(t,e.from.line).markedSpans,i=dt(t,e.to.line)&&at(t,e.to.line).markedSpans;if(!r&&!i)return null;var n=e.from.ch,s=e.to.ch,o=0==mt(e.from,e.to),a=function(t,e,r){var i;if(t)for(var n=0;n<t.length;++n){var s=t[n],o=s.marker,a=null==s.from||(o.inclusiveLeft?s.from<=e:s.from<e);if(a||s.from==e&&"bookmark"==o.type&&(!r||!s.marker.insertLeft)){var l=null==s.to||(o.inclusiveRight?s.to>=e:s.to>e);(i||(i=[])).push(new Ct(o,s.from,l?null:s.to))}}return i}(r,n,o),l=function(t,e,r){var i;if(t)for(var n=0;n<t.length;++n){var s=t[n],o=s.marker,a=null==s.to||(o.inclusiveRight?s.to>=e:s.to>e);if(a||s.from==e&&"bookmark"==o.type&&(!r||s.marker.insertLeft)){var l=null==s.from||(o.inclusiveLeft?s.from<=e:s.from<e);(i||(i=[])).push(new Ct(o,l?null:s.from-e,null==s.to?null:s.to-e))}}return i}(i,s,o),c=1==e.text.length,h=Y(e.text).length+(c?n:0);if(a)for(var u=0;u<a.length;++u){var f=a[u];if(null==f.to){var d=It(l,f.marker);d?c&&(f.to=null==d.to?null:d.to+h):f.to=n}}if(l)for(var p=0;p<l.length;++p){var g=l[p];if(null!=g.to&&(g.to+=h),null==g.from){var m=It(a,g.marker);m||(g.from=h,c&&(a||(a=[])).push(g))}else g.from+=h,c&&(a||(a=[])).push(g)}a&&(a=Nt(a)),l&&l!=a&&(l=Nt(l));var v=[a];if(!c){var y,b=e.text.length-2;if(b>0&&a)for(var x=0;x<a.length;++x)null==a[x].to&&(y||(y=[])).push(new Ct(a[x].marker,null,null));for(var w=0;w<b;++w)v.push(y);v.push(l)}return v}function Nt(t){for(var e=0;e<t.length;++e){var r=t[e];null!=r.from&&r.from==r.to&&!1!==r.marker.clearWhenEmpty&&t.splice(e--,1)}return t.length?t:null}function At(t){var e=t.markedSpans;if(e){for(var r=0;r<e.length;++r)e[r].marker.detachLine(t);t.markedSpans=null}}function Dt(t,e){if(e){for(var r=0;r<e.length;++r)e[r].marker.attachLine(t);t.markedSpans=e}}function Rt(t){return t.inclusiveLeft?-1:0}function Mt(t){return t.inclusiveRight?1:0}function Pt(t,e){var r=t.lines.length-e.lines.length;if(0!=r)return r;var i=t.find(),n=e.find(),s=mt(i.from,n.from)||Rt(t)-Rt(e);if(s)return-s;var o=mt(i.to,n.to)||Mt(t)-Mt(e);return o||e.id-t.id}function Vt(t,e){var r,i=Tt&&t.markedSpans;if(i)for(var n=void 0,s=0;s<i.length;++s)(n=i[s]).marker.collapsed&&null==(e?n.from:n.to)&&(!r||Pt(r,n.marker)<0)&&(r=n.marker);return r}function Bt(t){return Vt(t,!0)}function Ft(t){return Vt(t,!1)}function Ut(t,e){var r,i=Tt&&t.markedSpans;if(i)for(var n=0;n<i.length;++n){var s=i[n];s.marker.collapsed&&(null==s.from||s.from<e)&&(null==s.to||s.to>e)&&(!r||Pt(r,s.marker)<0)&&(r=s.marker)}return r}function Wt(t,e,r,i,n){var s=at(t,e),o=Tt&&s.markedSpans;if(o)for(var a=0;a<o.length;++a){var l=o[a];if(l.marker.collapsed){var c=l.marker.find(0),h=mt(c.from,r)||Rt(l.marker)-Rt(n),u=mt(c.to,i)||Mt(l.marker)-Mt(n);if(!(h>=0&&u<=0||h<=0&&u>=0)&&(h<=0&&(l.marker.inclusiveRight&&n.inclusiveLeft?mt(c.to,r)>=0:mt(c.to,r)>0)||h>=0&&(l.marker.inclusiveRight&&n.inclusiveLeft?mt(c.from,i)<=0:mt(c.from,i)<0)))return!0}}}function Ht(t){for(var e;e=Bt(t);)t=e.find(-1,!0).line;return t}function Gt(t,e){var r=at(t,e),i=Ht(r);return r==i?e:ut(i)}function zt(t,e){if(e>t.lastLine())return e;var r,i=at(t,e);if(!_t(t,i))return e;for(;r=Ft(i);)i=r.find(1,!0).line;return ut(i)+1}function _t(t,e){var r=Tt&&e.markedSpans;if(r)for(var i=void 0,n=0;n<r.length;++n)if((i=r[n]).marker.collapsed){if(null==i.from)return!0;if(!i.marker.widgetNode&&0==i.from&&i.marker.inclusiveLeft&&Xt(t,e,i))return!0}}function Xt(t,e,r){if(null==r.to){var i=r.marker.find(1,!0);return Xt(t,i.line,It(i.line.markedSpans,r.marker))}if(r.marker.inclusiveRight&&r.to==e.text.length)return!0;for(var n=void 0,s=0;s<e.markedSpans.length;++s)if((n=e.markedSpans[s]).marker.collapsed&&!n.marker.widgetNode&&n.from==r.to&&(null==n.to||n.to!=r.from)&&(n.marker.inclusiveLeft||r.marker.inclusiveRight)&&Xt(t,e,n))return!0}function jt(t){for(var e=0,r=(t=Ht(t)).parent,i=0;i<r.lines.length;++i){var n=r.lines[i];if(n==t)break;e+=n.height}for(var s=r.parent;s;s=(r=s).parent)for(var o=0;o<s.children.length;++o){var a=s.children[o];if(a==r)break;e+=a.height}return e}function Kt(t){if(0==t.height)return 0;for(var e,r=t.text.length,i=t;e=Bt(i);){var n=e.find(0,!0);i=n.from.line,r+=n.from.ch-n.to.ch}for(i=t;e=Ft(i);){var s=e.find(0,!0);r-=i.text.length-s.from.ch,i=s.to.line,r+=i.text.length-s.to.ch}return r}function qt(t){var e=t.display,r=t.doc;e.maxLine=at(r,r.first),e.maxLineLength=Kt(e.maxLine),e.maxLineChanged=!0,r.iter(function(t){var r=Kt(t);r>e.maxLineLength&&(e.maxLineLength=r,e.maxLine=t)})}var Yt=null;function Jt(t,e,r){var i;Yt=null;for(var n=0;n<t.length;++n){var s=t[n];if(s.from<e&&s.to>e)return n;s.to==e&&(s.from!=s.to&&"before"==r?i=n:Yt=n),s.from==e&&(s.from!=s.to&&"before"!=r?i=n:Yt=n)}return null!=i?i:Yt}var Zt=function(){var t="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN",e="nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111";function r(r){return r<=247?t.charAt(r):1424<=r&&r<=1524?"R":1536<=r&&r<=1785?e.charAt(r-1536):1774<=r&&r<=2220?"r":8192<=r&&r<=8203?"w":8204==r?"b":"L"}var i=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,n=/[stwN]/,s=/[LRr]/,o=/[Lb1n]/,a=/[1n]/;function l(t,e,r){this.level=t,this.from=e,this.to=r}return function(t,e){var c="ltr"==e?"L":"R";if(0==t.length||"ltr"==e&&!i.test(t))return!1;for(var h=t.length,u=[],f=0;f<h;++f)u.push(r(t.charCodeAt(f)));for(var d=0,p=c;d<h;++d){var g=u[d];"m"==g?u[d]=p:p=g}for(var m=0,v=c;m<h;++m){var y=u[m];"1"==y&&"r"==v?u[m]="n":s.test(y)&&(v=y,"r"==y&&(u[m]="R"))}for(var b=1,x=u[0];b<h-1;++b){var w=u[b];"+"==w&&"1"==x&&"1"==u[b+1]?u[b]="1":","!=w||x!=u[b+1]||"1"!=x&&"n"!=x||(u[b]=x),x=w}for(var k=0;k<h;++k){var S=u[k];if(","==S)u[k]="N";else if("%"==S){var E=void 0;for(E=k+1;E<h&&"%"==u[E];++E);for(var T=k&&"!"==u[k-1]||E<h&&"1"==u[E]?"1":"N",C=k;C<E;++C)u[C]=T;k=E-1}}for(var I=0,O=c;I<h;++I){var L=u[I];"L"==O&&"1"==L?u[I]="L":s.test(L)&&(O=L)}for(var N=0;N<h;++N)if(n.test(u[N])){var A=void 0;for(A=N+1;A<h&&n.test(u[A]);++A);for(var D="L"==(N?u[N-1]:c),R="L"==(A<h?u[A]:c),M=D==R?D?"L":"R":c,P=N;P<A;++P)u[P]=M;N=A-1}for(var V,B=[],F=0;F<h;)if(o.test(u[F])){var U=F;for(++F;F<h&&o.test(u[F]);++F);B.push(new l(0,U,F))}else{var W=F,H=B.length;for(++F;F<h&&"L"!=u[F];++F);for(var G=W;G<F;)if(a.test(u[G])){W<G&&B.splice(H,0,new l(1,W,G));var z=G;for(++G;G<F&&a.test(u[G]);++G);B.splice(H,0,new l(2,z,G)),W=G}else++G;W<F&&B.splice(H,0,new l(1,W,F))}return"ltr"==e&&(1==B[0].level&&(V=t.match(/^\s+/))&&(B[0].from=V[0].length,B.unshift(new l(0,0,V[0].length))),1==Y(B).level&&(V=t.match(/\s+$/))&&(Y(B).to-=V[0].length,B.push(new l(0,h-V[0].length,h)))),"rtl"==e?B.reverse():B}}();function Qt(t,e){var r=t.order;return null==r&&(r=t.order=Zt(t.text,e)),r}var $t=[],te=function(t,e,r){if(t.addEventListener)t.addEventListener(e,r,!1);else if(t.attachEvent)t.attachEvent("on"+e,r);else{var i=t._handlers||(t._handlers={});i[e]=(i[e]||$t).concat(r)}};function ee(t,e){return t._handlers&&t._handlers[e]||$t}function re(t,e,r){if(t.removeEventListener)t.removeEventListener(e,r,!1);else if(t.detachEvent)t.detachEvent("on"+e,r);else{var i=t._handlers,n=i&&i[e];if(n){var s=W(n,r);s>-1&&(i[e]=n.slice(0,s).concat(n.slice(s+1)))}}}function ie(t,e){var r=ee(t,e);if(r.length)for(var i=Array.prototype.slice.call(arguments,2),n=0;n<r.length;++n)r[n].apply(null,i)}function ne(t,e,r){return"string"==typeof e&&(e={type:e,preventDefault:function(){this.defaultPrevented=!0}}),ie(t,r||e.type,t,e),he(e)||e.codemirrorIgnore}function se(t){var e=t._handlers&&t._handlers.cursorActivity;if(e)for(var r=t.curOp.cursorActivityHandlers||(t.curOp.cursorActivityHandlers=[]),i=0;i<e.length;++i)-1==W(r,e[i])&&r.push(e[i])}function oe(t,e){return ee(t,e).length>0}function ae(t){t.prototype.on=function(t,e){te(this,t,e)},t.prototype.off=function(t,e){re(this,t,e)}}function le(t){t.preventDefault?t.preventDefault():t.returnValue=!1}function ce(t){t.stopPropagation?t.stopPropagation():t.cancelBubble=!0}function he(t){return null!=t.defaultPrevented?t.defaultPrevented:0==t.returnValue}function ue(t){le(t),ce(t)}function fe(t){return t.target||t.srcElement}function de(t){var e=t.which;return null==e&&(1&t.button?e=1:2&t.button?e=3:4&t.button&&(e=2)),y&&t.ctrlKey&&1==e&&(e=3),e}var pe,ge,me=function(){if(o&&a<9)return!1;var t=L("div");return"draggable"in t||"dragDrop"in t}();function ve(t){if(null==pe){var e=L("span","");O(t,L("span",[e,document.createTextNode("x")])),0!=t.firstChild.offsetHeight&&(pe=e.offsetWidth<=1&&e.offsetHeight>2&&!(o&&a<8))}var r=pe?L("span",""):L("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return r.setAttribute("cm-text",""),r}function ye(t){if(null!=ge)return ge;var e=O(t,document.createTextNode("AخA")),r=T(e,0,1).getBoundingClientRect(),i=T(e,1,2).getBoundingClientRect();return I(t),!(!r||r.left==r.right)&&(ge=i.right-r.right<3)}var be=3!="\n\nb".split(/\n/).length?function(t){for(var e=0,r=[],i=t.length;e<=i;){var n=t.indexOf("\n",e);-1==n&&(n=t.length);var s=t.slice(e,"\r"==t.charAt(n-1)?n-1:n),o=s.indexOf("\r");-1!=o?(r.push(s.slice(0,o)),e+=o+1):(r.push(s),e=n+1)}return r}:function(t){return t.split(/\r\n?|\n/)},xe=window.getSelection?function(t){try{return t.selectionStart!=t.selectionEnd}catch(t){return!1}}:function(t){var e;try{e=t.ownerDocument.selection.createRange()}catch(t){}return!(!e||e.parentElement()!=t)&&0!=e.compareEndPoints("StartToEnd",e)},we=function(){var t=L("div");return"oncopy"in t||(t.setAttribute("oncopy","return;"),"function"==typeof t.oncopy)}(),ke=null,Se={},Ee={};function Te(t){if("string"==typeof t&&Ee.hasOwnProperty(t))t=Ee[t];else if(t&&"string"==typeof t.name&&Ee.hasOwnProperty(t.name)){var e=Ee[t.name];"string"==typeof e&&(e={name:e}),(t=Q(e,t)).name=e.name}else{if("string"==typeof t&&/^[\w\-]+\/[\w\-]+\+xml$/.test(t))return Te("application/xml");if("string"==typeof t&&/^[\w\-]+\/[\w\-]+\+json$/.test(t))return Te("application/json")}return"string"==typeof t?{name:t}:t||{name:"null"}}function Ce(t,e){e=Te(e);var r=Se[e.name];if(!r)return Ce(t,"text/plain");var i=r(t,e);if(Ie.hasOwnProperty(e.name)){var n=Ie[e.name];for(var s in n)n.hasOwnProperty(s)&&(i.hasOwnProperty(s)&&(i["_"+s]=i[s]),i[s]=n[s])}if(i.name=e.name,e.helperType&&(i.helperType=e.helperType),e.modeProps)for(var o in e.modeProps)i[o]=e.modeProps[o];return i}var Ie={};function Oe(t,e){var r=Ie.hasOwnProperty(t)?Ie[t]:Ie[t]={};B(e,r)}function Le(t,e){if(!0===e)return e;if(t.copyState)return t.copyState(e);var r={};for(var i in e){var n=e[i];n instanceof Array&&(n=n.concat([])),r[i]=n}return r}function Ne(t,e){for(var r;t.innerMode&&(r=t.innerMode(e))&&r.mode!=t;)e=r.state,t=r.mode;return r||{mode:t,state:e}}function Ae(t,e,r){return!t.startState||t.startState(e,r)}var De=function(t,e,r){this.pos=this.start=0,this.string=t,this.tabSize=e||8,this.lastColumnPos=this.lastColumnValue=0,this.lineStart=0,this.lineOracle=r};De.prototype.eol=function(){return this.pos>=this.string.length},De.prototype.sol=function(){return this.pos==this.lineStart},De.prototype.peek=function(){return this.string.charAt(this.pos)||void 0},De.prototype.next=function(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)},De.prototype.eat=function(t){var e=this.string.charAt(this.pos);if("string"==typeof t?e==t:e&&(t.test?t.test(e):t(e)))return++this.pos,e},De.prototype.eatWhile=function(t){for(var e=this.pos;this.eat(t););return this.pos>e},De.prototype.eatSpace=function(){for(var t=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>t},De.prototype.skipToEnd=function(){this.pos=this.string.length},De.prototype.skipTo=function(t){var e=this.string.indexOf(t,this.pos);if(e>-1)return this.pos=e,!0},De.prototype.backUp=function(t){this.pos-=t},De.prototype.column=function(){return this.lastColumnPos<this.start&&(this.lastColumnValue=F(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue-(this.lineStart?F(this.string,this.lineStart,this.tabSize):0)},De.prototype.indentation=function(){return F(this.string,null,this.tabSize)-(this.lineStart?F(this.string,this.lineStart,this.tabSize):0)},De.prototype.match=function(t,e,r){if("string"!=typeof t){var i=this.string.slice(this.pos).match(t);return i&&i.index>0?null:(i&&!1!==e&&(this.pos+=i[0].length),i)}var n=function(t){return r?t.toLowerCase():t},s=this.string.substr(this.pos,t.length);if(n(s)==n(t))return!1!==e&&(this.pos+=t.length),!0},De.prototype.current=function(){return this.string.slice(this.start,this.pos)},De.prototype.hideFirstChars=function(t,e){this.lineStart+=t;try{return e()}finally{this.lineStart-=t}},De.prototype.lookAhead=function(t){var e=this.lineOracle;return e&&e.lookAhead(t)},De.prototype.baseToken=function(){var t=this.lineOracle;return t&&t.baseToken(this.pos)};var Re=function(t,e){this.state=t,this.lookAhead=e},Me=function(t,e,r,i){this.state=e,this.doc=t,this.line=r,this.maxLookAhead=i||0,this.baseTokens=null,this.baseTokenPos=1};function Pe(t,e,r,i){var n=[t.state.modeGen],s={};_e(t,e.text,t.doc.mode,r,function(t,e){return n.push(t,e)},s,i);for(var o=r.state,a=function(i){r.baseTokens=n;var a=t.state.overlays[i],l=1,c=0;r.state=!0,_e(t,e.text,a.mode,r,function(t,e){for(var r=l;c<t;){var i=n[l];i>t&&n.splice(l,1,t,n[l+1],i),l+=2,c=Math.min(t,i)}if(e)if(a.opaque)n.splice(r,l-r,t,"overlay "+e),l=r+2;else for(;r<l;r+=2){var s=n[r+1];n[r+1]=(s?s+" ":"")+"overlay "+e}},s),r.state=o,r.baseTokens=null,r.baseTokenPos=1},l=0;l<t.state.overlays.length;++l)a(l);return{styles:n,classes:s.bgClass||s.textClass?s:null}}function Ve(t,e,r){if(!e.styles||e.styles[0]!=t.state.modeGen){var i=Be(t,ut(e)),n=e.text.length>t.options.maxHighlightLength&&Le(t.doc.mode,i.state),s=Pe(t,e,i);n&&(i.state=n),e.stateAfter=i.save(!n),e.styles=s.styles,s.classes?e.styleClasses=s.classes:e.styleClasses&&(e.styleClasses=null),r===t.doc.highlightFrontier&&(t.doc.modeFrontier=Math.max(t.doc.modeFrontier,++t.doc.highlightFrontier))}return e.styles}function Be(t,e,r){var i=t.doc,n=t.display;if(!i.mode.startState)return new Me(i,!0,e);var s=function(t,e,r){for(var i,n,s=t.doc,o=r?-1:e-(t.doc.mode.innerMode?1e3:100),a=e;a>o;--a){if(a<=s.first)return s.first;var l=at(s,a-1),c=l.stateAfter;if(c&&(!r||a+(c instanceof Re?c.lookAhead:0)<=s.modeFrontier))return a;var h=F(l.text,null,t.options.tabSize);(null==n||i>h)&&(n=a-1,i=h)}return n}(t,e,r),o=s>i.first&&at(i,s-1).stateAfter,a=o?Me.fromSaved(i,o,s):new Me(i,Ae(i.mode),s);return i.iter(s,e,function(r){Fe(t,r.text,a);var i=a.line;r.stateAfter=i==e-1||i%5==0||i>=n.viewFrom&&i<n.viewTo?a.save():null,a.nextLine()}),r&&(i.modeFrontier=a.line),a}function Fe(t,e,r,i){var n=t.doc.mode,s=new De(e,t.options.tabSize,r);for(s.start=s.pos=i||0,""==e&&Ue(n,r.state);!s.eol();)We(n,s,r.state),s.start=s.pos}function Ue(t,e){if(t.blankLine)return t.blankLine(e);if(t.innerMode){var r=Ne(t,e);return r.mode.blankLine?r.mode.blankLine(r.state):void 0}}function We(t,e,r,i){for(var n=0;n<10;n++){i&&(i[0]=Ne(t,r).mode);var s=t.token(e,r);if(e.pos>e.start)return s}throw new Error("Mode "+t.name+" failed to advance stream.")}Me.prototype.lookAhead=function(t){var e=this.doc.getLine(this.line+t);return null!=e&&t>this.maxLookAhead&&(this.maxLookAhead=t),e},Me.prototype.baseToken=function(t){if(!this.baseTokens)return null;for(;this.baseTokens[this.baseTokenPos]<=t;)this.baseTokenPos+=2;var e=this.baseTokens[this.baseTokenPos+1];return{type:e&&e.replace(/( |^)overlay .*/,""),size:this.baseTokens[this.baseTokenPos]-t}},Me.prototype.nextLine=function(){this.line++,this.maxLookAhead>0&&this.maxLookAhead--},Me.fromSaved=function(t,e,r){return e instanceof Re?new Me(t,Le(t.mode,e.state),r,e.lookAhead):new Me(t,Le(t.mode,e),r)},Me.prototype.save=function(t){var e=!1!==t?Le(this.doc.mode,this.state):this.state;return this.maxLookAhead>0?new Re(e,this.maxLookAhead):e};var He=function(t,e,r){this.start=t.start,this.end=t.pos,this.string=t.current(),this.type=e||null,this.state=r};function Ge(t,e,r,i){var n,s=t.doc,o=s.mode;e=kt(s,e);var a,l=at(s,e.line),c=Be(t,e.line,r),h=new De(l.text,t.options.tabSize,c);for(i&&(a=[]);(i||h.pos<e.ch)&&!h.eol();)h.start=h.pos,n=We(o,h,c.state),i&&a.push(new He(h,n,Le(s.mode,c.state)));return i?a:new He(h,n,c.state)}function ze(t,e){if(t)for(;;){var r=t.match(/(?:^|\s+)line-(background-)?(\S+)/);if(!r)break;t=t.slice(0,r.index)+t.slice(r.index+r[0].length);var i=r[1]?"bgClass":"textClass";null==e[i]?e[i]=r[2]:new RegExp("(?:^|s)"+r[2]+"(?:$|s)").test(e[i])||(e[i]+=" "+r[2])}return t}function _e(t,e,r,i,n,s,o){var a=r.flattenSpans;null==a&&(a=t.options.flattenSpans);var l,c=0,h=null,u=new De(e,t.options.tabSize,i),f=t.options.addModeClass&&[null];for(""==e&&ze(Ue(r,i.state),s);!u.eol();){if(u.pos>t.options.maxHighlightLength?(a=!1,o&&Fe(t,e,i,u.pos),u.pos=e.length,l=null):l=ze(We(r,u,i.state,f),s),f){var d=f[0].name;d&&(l="m-"+(l?d+" "+l:d))}if(!a||h!=l){for(;c<u.start;)c=Math.min(u.start,c+5e3),n(c,h);h=l}u.start=u.pos}for(;c<u.pos;){var p=Math.min(u.pos,c+5e3);n(p,h),c=p}}var Xe=function(t,e,r){this.text=t,Dt(this,e),this.height=r?r(this):1};function je(t){t.parent=null,At(t)}Xe.prototype.lineNo=function(){return ut(this)},ae(Xe);var Ke={},qe={};function Ye(t,e){if(!t||/^\s*$/.test(t))return null;var r=e.addModeClass?qe:Ke;return r[t]||(r[t]=t.replace(/\S+/g,"cm-$&"))}function Je(t,e){var r=N("span",null,null,l?"padding-right: .1px":null),i={pre:N("pre",[r],"CodeMirror-line"),content:r,col:0,pos:0,cm:t,trailingSpace:!1,splitSpaces:(o||l)&&t.getOption("lineWrapping")};e.measure={};for(var n=0;n<=(e.rest?e.rest.length:0);n++){var s=n?e.rest[n-1]:e.line,a=void 0;i.pos=0,i.addToken=Qe,ye(t.display.measure)&&(a=Qt(s,t.doc.direction))&&(i.addToken=$e(i.addToken,a)),i.map=[];var c=e!=t.display.externalMeasured&&ut(s);er(s,i,Ve(t,s,c)),s.styleClasses&&(s.styleClasses.bgClass&&(i.bgClass=M(s.styleClasses.bgClass,i.bgClass||"")),s.styleClasses.textClass&&(i.textClass=M(s.styleClasses.textClass,i.textClass||""))),0==i.map.length&&i.map.push(0,0,i.content.appendChild(ve(t.display.measure))),0==n?(e.measure.map=i.map,e.measure.cache={}):((e.measure.maps||(e.measure.maps=[])).push(i.map),(e.measure.caches||(e.measure.caches=[])).push({}))}if(l){var h=i.content.lastChild;(/\bcm-tab\b/.test(h.className)||h.querySelector&&h.querySelector(".cm-tab"))&&(i.content.className="cm-tab-wrap-hack")}return ie(t,"renderLine",t,e.line,i.pre),i.pre.className&&(i.textClass=M(i.pre.className,i.textClass||"")),i}function Ze(t){var e=L("span","•","cm-invalidchar");return e.title="\\u"+t.charCodeAt(0).toString(16),e.setAttribute("aria-label",e.title),e}function Qe(t,e,r,i,n,s,l){if(e){var c,h=t.splitSpaces?function(t,e){if(t.length>1&&!/ /.test(t))return t;for(var r=e,i="",n=0;n<t.length;n++){var s=t.charAt(n);" "!=s||!r||n!=t.length-1&&32!=t.charCodeAt(n+1)||(s=" "),i+=s,r=" "==s}return i}(e,t.trailingSpace):e,u=t.cm.state.specialChars,f=!1;if(u.test(e)){c=document.createDocumentFragment();for(var d=0;;){u.lastIndex=d;var p=u.exec(e),g=p?p.index-d:e.length-d;if(g){var m=document.createTextNode(h.slice(d,d+g));o&&a<9?c.appendChild(L("span",[m])):c.appendChild(m),t.map.push(t.pos,t.pos+g,m),t.col+=g,t.pos+=g}if(!p)break;d+=g+1;var v=void 0;if("\t"==p[0]){var y=t.cm.options.tabSize,b=y-t.col%y;(v=c.appendChild(L("span",q(b),"cm-tab"))).setAttribute("role","presentation"),v.setAttribute("cm-text","\t"),t.col+=b}else"\r"==p[0]||"\n"==p[0]?((v=c.appendChild(L("span","\r"==p[0]?"␍":"","cm-invalidchar"))).setAttribute("cm-text",p[0]),t.col+=1):((v=t.cm.options.specialCharPlaceholder(p[0])).setAttribute("cm-text",p[0]),o&&a<9?c.appendChild(L("span",[v])):c.appendChild(v),t.col+=1);t.map.push(t.pos,t.pos+1,v),t.pos++}}else t.col+=e.length,c=document.createTextNode(h),t.map.push(t.pos,t.pos+e.length,c),o&&a<9&&(f=!0),t.pos+=e.length;if(t.trailingSpace=32==h.charCodeAt(e.length-1),r||i||n||f||l){var x=r||"";i&&(x+=i),n&&(x+=n);var w=L("span",[c],x,l);return s&&(w.title=s),t.content.appendChild(w)}t.content.appendChild(c)}}function $e(t,e){return function(r,i,n,s,o,a,l){n=n?n+" cm-force-border":"cm-force-border";for(var c=r.pos,h=c+i.length;;){for(var u=void 0,f=0;f<e.length&&!((u=e[f]).to>c&&u.from<=c);f++);if(u.to>=h)return t(r,i,n,s,o,a,l);t(r,i.slice(0,u.to-c),n,s,null,a,l),s=null,i=i.slice(u.to-c),c=u.to}}}function tr(t,e,r,i){var n=!i&&r.widgetNode;n&&t.map.push(t.pos,t.pos+e,n),!i&&t.cm.display.input.needsContentAttribute&&(n||(n=t.content.appendChild(document.createElement("span"))),n.setAttribute("cm-marker",r.id)),n&&(t.cm.display.input.setUneditable(n),t.content.appendChild(n)),t.pos+=e,t.trailingSpace=!1}function er(t,e,r){var i=t.markedSpans,n=t.text,s=0;if(i)for(var o,a,l,c,h,u,f,d=n.length,p=0,g=1,m="",v=0;;){if(v==p){l=c=h=u=a="",f=null,v=1/0;for(var y=[],b=void 0,x=0;x<i.length;++x){var w=i[x],k=w.marker;"bookmark"==k.type&&w.from==p&&k.widgetNode?y.push(k):w.from<=p&&(null==w.to||w.to>p||k.collapsed&&w.to==p&&w.from==p)?(null!=w.to&&w.to!=p&&v>w.to&&(v=w.to,c=""),k.className&&(l+=" "+k.className),k.css&&(a=(a?a+";":"")+k.css),k.startStyle&&w.from==p&&(h+=" "+k.startStyle),k.endStyle&&w.to==v&&(b||(b=[])).push(k.endStyle,w.to),k.title&&!u&&(u=k.title),k.collapsed&&(!f||Pt(f.marker,k)<0)&&(f=w)):w.from>p&&v>w.from&&(v=w.from)}if(b)for(var S=0;S<b.length;S+=2)b[S+1]==v&&(c+=" "+b[S]);if(!f||f.from==p)for(var E=0;E<y.length;++E)tr(e,0,y[E]);if(f&&(f.from||0)==p){if(tr(e,(null==f.to?d+1:f.to)-p,f.marker,null==f.from),null==f.to)return;f.to==p&&(f=!1)}}if(p>=d)break;for(var T=Math.min(d,v);;){if(m){var C=p+m.length;if(!f){var I=C>T?m.slice(0,T-p):m;e.addToken(e,I,o?o+l:l,h,p+I.length==v?c:"",u,a)}if(C>=T){m=m.slice(T-p),p=T;break}p=C,h=""}m=n.slice(s,s=r[g++]),o=Ye(r[g++],e.cm.options)}}else for(var O=1;O<r.length;O+=2)e.addToken(e,n.slice(s,s=r[O]),Ye(r[O+1],e.cm.options))}function rr(t,e,r){this.line=e,this.rest=function(t){for(var e,r;e=Ft(t);)t=e.find(1,!0).line,(r||(r=[])).push(t);return r}(e),this.size=this.rest?ut(Y(this.rest))-r+1:1,this.node=this.text=null,this.hidden=_t(t,e)}function ir(t,e,r){for(var i,n=[],s=e;s<r;s=i){var o=new rr(t.doc,at(t.doc,s),s);i=s+o.size,n.push(o)}return n}var nr=null,sr=null;function or(t,e){var r=ee(t,e);if(r.length){var i,n=Array.prototype.slice.call(arguments,2);nr?i=nr.delayedCallbacks:sr?i=sr:(i=sr=[],setTimeout(ar,0));for(var s=function(t){i.push(function(){return r[t].apply(null,n)})},o=0;o<r.length;++o)s(o)}}function ar(){var t=sr;sr=null;for(var e=0;e<t.length;++e)t[e]()}function lr(t,e,r,i){for(var n=0;n<e.changes.length;n++){var s=e.changes[n];"text"==s?ur(t,e):"gutter"==s?dr(t,e,r,i):"class"==s?fr(t,e):"widget"==s&&pr(t,e,i)}e.changes=null}function cr(t){return t.node==t.text&&(t.node=L("div",null,null,"position: relative"),t.text.parentNode&&t.text.parentNode.replaceChild(t.node,t.text),t.node.appendChild(t.text),o&&a<8&&(t.node.style.zIndex=2)),t.node}function hr(t,e){var r=t.display.externalMeasured;return r&&r.line==e.line?(t.display.externalMeasured=null,e.measure=r.measure,r.built):Je(t,e)}function ur(t,e){var r=e.text.className,i=hr(t,e);e.text==e.node&&(e.node=i.pre),e.text.parentNode.replaceChild(i.pre,e.text),e.text=i.pre,i.bgClass!=e.bgClass||i.textClass!=e.textClass?(e.bgClass=i.bgClass,e.textClass=i.textClass,fr(t,e)):r&&(e.text.className=r)}function fr(t,e){!function(t,e){var r=e.bgClass?e.bgClass+" "+(e.line.bgClass||""):e.line.bgClass;if(r&&(r+=" CodeMirror-linebackground"),e.background)r?e.background.className=r:(e.background.parentNode.removeChild(e.background),e.background=null);else if(r){var i=cr(e);e.background=i.insertBefore(L("div",null,r),i.firstChild),t.display.input.setUneditable(e.background)}}(t,e),e.line.wrapClass?cr(e).className=e.line.wrapClass:e.node!=e.text&&(e.node.className="");var r=e.textClass?e.textClass+" "+(e.line.textClass||""):e.line.textClass;e.text.className=r||""}function dr(t,e,r,i){if(e.gutter&&(e.node.removeChild(e.gutter),e.gutter=null),e.gutterBackground&&(e.node.removeChild(e.gutterBackground),e.gutterBackground=null),e.line.gutterClass){var n=cr(e);e.gutterBackground=L("div",null,"CodeMirror-gutter-background "+e.line.gutterClass,"left: "+(t.options.fixedGutter?i.fixedPos:-i.gutterTotalWidth)+"px; width: "+i.gutterTotalWidth+"px"),t.display.input.setUneditable(e.gutterBackground),n.insertBefore(e.gutterBackground,e.text)}var s=e.line.gutterMarkers;if(t.options.lineNumbers||s){var o=cr(e),a=e.gutter=L("div",null,"CodeMirror-gutter-wrapper","left: "+(t.options.fixedGutter?i.fixedPos:-i.gutterTotalWidth)+"px");if(t.display.input.setUneditable(a),o.insertBefore(a,e.text),e.line.gutterClass&&(a.className+=" "+e.line.gutterClass),!t.options.lineNumbers||s&&s["CodeMirror-linenumbers"]||(e.lineNumber=a.appendChild(L("div",pt(t.options,r),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+i.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+t.display.lineNumInnerWidth+"px"))),s)for(var l=0;l<t.options.gutters.length;++l){var c=t.options.gutters[l],h=s.hasOwnProperty(c)&&s[c];h&&a.appendChild(L("div",[h],"CodeMirror-gutter-elt","left: "+i.gutterLeft[c]+"px; width: "+i.gutterWidth[c]+"px"))}}}function pr(t,e,r){e.alignable&&(e.alignable=null);for(var i=e.node.firstChild,n=void 0;i;i=n)n=i.nextSibling,"CodeMirror-linewidget"==i.className&&e.node.removeChild(i);mr(t,e,r)}function gr(t,e,r,i){var n=hr(t,e);return e.text=e.node=n.pre,n.bgClass&&(e.bgClass=n.bgClass),n.textClass&&(e.textClass=n.textClass),fr(t,e),dr(t,e,r,i),mr(t,e,i),e.node}function mr(t,e,r){if(vr(t,e.line,e,r,!0),e.rest)for(var i=0;i<e.rest.length;i++)vr(t,e.rest[i],e,r,!1)}function vr(t,e,r,i,n){if(e.widgets)for(var s=cr(r),o=0,a=e.widgets;o<a.length;++o){var l=a[o],c=L("div",[l.node],"CodeMirror-linewidget");l.handleMouseEvents||c.setAttribute("cm-ignore-events","true"),yr(l,c,r,i),t.display.input.setUneditable(c),n&&l.above?s.insertBefore(c,r.gutter||r.text):s.appendChild(c),or(l,"redraw")}}function yr(t,e,r,i){if(t.noHScroll){(r.alignable||(r.alignable=[])).push(e);var n=i.wrapperWidth;e.style.left=i.fixedPos+"px",t.coverGutter||(n-=i.gutterTotalWidth,e.style.paddingLeft=i.gutterTotalWidth+"px"),e.style.width=n+"px"}t.coverGutter&&(e.style.zIndex=5,e.style.position="relative",t.noHScroll||(e.style.marginLeft=-i.gutterTotalWidth+"px"))}function br(t){if(null!=t.height)return t.height;var e=t.doc.cm;if(!e)return 0;if(!A(document.body,t.node)){var r="position: relative;";t.coverGutter&&(r+="margin-left: -"+e.display.gutters.offsetWidth+"px;"),t.noHScroll&&(r+="width: "+e.display.wrapper.clientWidth+"px;"),O(e.display.measure,L("div",[t.node],null,r))}return t.height=t.node.parentNode.offsetHeight}function xr(t,e){for(var r=fe(e);r!=t.wrapper;r=r.parentNode)if(!r||1==r.nodeType&&"true"==r.getAttribute("cm-ignore-events")||r.parentNode==t.sizer&&r!=t.mover)return!0}function wr(t){return t.lineSpace.offsetTop}function kr(t){return t.mover.offsetHeight-t.lineSpace.offsetHeight}function Sr(t){if(t.cachedPaddingH)return t.cachedPaddingH;var e=O(t.measure,L("pre","x")),r=window.getComputedStyle?window.getComputedStyle(e):e.currentStyle,i={left:parseInt(r.paddingLeft),right:parseInt(r.paddingRight)};return isNaN(i.left)||isNaN(i.right)||(t.cachedPaddingH=i),i}function Er(t){return H-t.display.nativeBarWidth}function Tr(t){return t.display.scroller.clientWidth-Er(t)-t.display.barWidth}function Cr(t){return t.display.scroller.clientHeight-Er(t)-t.display.barHeight}function Ir(t,e,r){if(t.line==e)return{map:t.measure.map,cache:t.measure.cache};for(var i=0;i<t.rest.length;i++)if(t.rest[i]==e)return{map:t.measure.maps[i],cache:t.measure.caches[i]};for(var n=0;n<t.rest.length;n++)if(ut(t.rest[n])>r)return{map:t.measure.maps[n],cache:t.measure.caches[n],before:!0}}function Or(t,e,r,i){return Ar(t,Nr(t,e),r,i)}function Lr(t,e){if(e>=t.display.viewFrom&&e<t.display.viewTo)return t.display.view[oi(t,e)];var r=t.display.externalMeasured;return r&&e>=r.lineN&&e<r.lineN+r.size?r:void 0}function Nr(t,e){var r=ut(e),i=Lr(t,r);i&&!i.text?i=null:i&&i.changes&&(lr(t,i,r,ei(t)),t.curOp.forceUpdate=!0),i||(i=function(t,e){var r=ut(e=Ht(e)),i=t.display.externalMeasured=new rr(t.doc,e,r);i.lineN=r;var n=i.built=Je(t,i);return i.text=n.pre,O(t.display.lineMeasure,n.pre),i}(t,e));var n=Ir(i,e,r);return{line:e,view:i,rect:null,map:n.map,cache:n.cache,before:n.before,hasHeights:!1}}function Ar(t,e,r,i,n){e.before&&(r=-1);var s,l=r+(i||"");return e.cache.hasOwnProperty(l)?s=e.cache[l]:(e.rect||(e.rect=e.view.text.getBoundingClientRect()),e.hasHeights||(function(t,e,r){var i=t.options.lineWrapping,n=i&&Tr(t);if(!e.measure.heights||i&&e.measure.width!=n){var s=e.measure.heights=[];if(i){e.measure.width=n;for(var o=e.text.firstChild.getClientRects(),a=0;a<o.length-1;a++){var l=o[a],c=o[a+1];Math.abs(l.bottom-c.bottom)>2&&s.push((l.bottom+c.top)/2-r.top)}}s.push(r.bottom-r.top)}}(t,e.view,e.rect),e.hasHeights=!0),(s=function(t,e,r,i){var n,s=Mr(e.map,r,i),l=s.node,c=s.start,h=s.end,u=s.collapse;if(3==l.nodeType){for(var f=0;f<4;f++){for(;c&&nt(e.line.text.charAt(s.coverStart+c));)--c;for(;s.coverStart+h<s.coverEnd&&nt(e.line.text.charAt(s.coverStart+h));)++h;if((n=o&&a<9&&0==c&&h==s.coverEnd-s.coverStart?l.parentNode.getBoundingClientRect():Pr(T(l,c,h).getClientRects(),i)).left||n.right||0==c)break;h=c,c-=1,u="right"}o&&a<11&&(n=function(t,e){if(!window.screen||null==screen.logicalXDPI||screen.logicalXDPI==screen.deviceXDPI||!function(t){if(null!=ke)return ke;var e=O(t,L("span","x")),r=e.getBoundingClientRect(),i=T(e,0,1).getBoundingClientRect();return ke=Math.abs(r.left-i.left)>1}(t))return e;var r=screen.logicalXDPI/screen.deviceXDPI,i=screen.logicalYDPI/screen.deviceYDPI;return{left:e.left*r,right:e.right*r,top:e.top*i,bottom:e.bottom*i}}(t.display.measure,n))}else{var d;c>0&&(u=i="right"),n=t.options.lineWrapping&&(d=l.getClientRects()).length>1?d["right"==i?d.length-1:0]:l.getBoundingClientRect()}if(o&&a<9&&!c&&(!n||!n.left&&!n.right)){var p=l.parentNode.getClientRects()[0];n=p?{left:p.left,right:p.left+ti(t.display),top:p.top,bottom:p.bottom}:Rr}for(var g=n.top-e.rect.top,m=n.bottom-e.rect.top,v=(g+m)/2,y=e.view.measure.heights,b=0;b<y.length-1&&!(v<y[b]);b++);var x=b?y[b-1]:0,w=y[b],k={left:("right"==u?n.right:n.left)-e.rect.left,right:("left"==u?n.left:n.right)-e.rect.left,top:x,bottom:w};return n.left||n.right||(k.bogus=!0),t.options.singleCursorHeightPerLine||(k.rtop=g,k.rbottom=m),k}(t,e,r,i)).bogus||(e.cache[l]=s)),{left:s.left,right:s.right,top:n?s.rtop:s.top,bottom:n?s.rbottom:s.bottom}}var Dr,Rr={left:0,right:0,top:0,bottom:0};function Mr(t,e,r){for(var i,n,s,o,a,l,c=0;c<t.length;c+=3)if(a=t[c],l=t[c+1],e<a?(n=0,s=1,o="left"):e<l?s=1+(n=e-a):(c==t.length-3||e==l&&t[c+3]>e)&&(n=(s=l-a)-1,e>=l&&(o="right")),null!=n){if(i=t[c+2],a==l&&r==(i.insertLeft?"left":"right")&&(o=r),"left"==r&&0==n)for(;c&&t[c-2]==t[c-3]&&t[c-1].insertLeft;)i=t[2+(c-=3)],o="left";if("right"==r&&n==l-a)for(;c<t.length-3&&t[c+3]==t[c+4]&&!t[c+5].insertLeft;)i=t[(c+=3)+2],o="right";break}return{node:i,start:n,end:s,collapse:o,coverStart:a,coverEnd:l}}function Pr(t,e){var r=Rr;if("left"==e)for(var i=0;i<t.length&&(r=t[i]).left==r.right;i++);else for(var n=t.length-1;n>=0&&(r=t[n]).left==r.right;n--);return r}function Vr(t){if(t.measure&&(t.measure.cache={},t.measure.heights=null,t.rest))for(var e=0;e<t.rest.length;e++)t.measure.caches[e]={}}function Br(t){t.display.externalMeasure=null,I(t.display.lineMeasure);for(var e=0;e<t.display.view.length;e++)Vr(t.display.view[e])}function Fr(t){Br(t),t.display.cachedCharWidth=t.display.cachedTextHeight=t.display.cachedPaddingH=null,t.options.lineWrapping||(t.display.maxLineChanged=!0),t.display.lineNumChars=null}function Ur(){return h&&m?-(document.body.getBoundingClientRect().left-parseInt(getComputedStyle(document.body).marginLeft)):window.pageXOffset||(document.documentElement||document.body).scrollLeft}function Wr(){return h&&m?-(document.body.getBoundingClientRect().top-parseInt(getComputedStyle(document.body).marginTop)):window.pageYOffset||(document.documentElement||document.body).scrollTop}function Hr(t){var e=0;if(t.widgets)for(var r=0;r<t.widgets.length;++r)t.widgets[r].above&&(e+=br(t.widgets[r]));return e}function Gr(t,e,r,i,n){if(!n){var s=Hr(e);r.top+=s,r.bottom+=s}if("line"==i)return r;i||(i="local");var o=jt(e);if("local"==i?o+=wr(t.display):o-=t.display.viewOffset,"page"==i||"window"==i){var a=t.display.lineSpace.getBoundingClientRect();o+=a.top+("window"==i?0:Wr());var l=a.left+("window"==i?0:Ur());r.left+=l,r.right+=l}return r.top+=o,r.bottom+=o,r}function zr(t,e,r){if("div"==r)return e;var i=e.left,n=e.top;if("page"==r)i-=Ur(),n-=Wr();else if("local"==r||!r){var s=t.display.sizer.getBoundingClientRect();i+=s.left,n+=s.top}var o=t.display.lineSpace.getBoundingClientRect();return{left:i-o.left,top:n-o.top}}function _r(t,e,r,i,n){return i||(i=at(t.doc,e.line)),Gr(t,i,Or(t,i,e.ch,n),r)}function Xr(t,e,r,i,n,s){function o(e,o){var a=Ar(t,n,e,o?"right":"left",s);return o?a.left=a.right:a.right=a.left,Gr(t,i,a,r)}i=i||at(t.doc,e.line),n||(n=Nr(t,i));var a=Qt(i,t.doc.direction),l=e.ch,c=e.sticky;if(l>=i.text.length?(l=i.text.length,c="before"):l<=0&&(l=0,c="after"),!a)return o("before"==c?l-1:l,"before"==c);function h(t,e,r){var i=a[e],n=1==i.level;return o(r?t-1:t,n!=r)}var u=Jt(a,l,c),f=Yt,d=h(l,u,"before"==c);return null!=f&&(d.other=h(l,f,"before"!=c)),d}function jr(t,e){var r=0;e=kt(t.doc,e),t.options.lineWrapping||(r=ti(t.display)*e.ch);var i=at(t.doc,e.line),n=jt(i)+wr(t.display);return{left:r,right:r,top:n,bottom:n+i.height}}function Kr(t,e,r,i,n){var s=gt(t,e,r);return s.xRel=n,i&&(s.outside=!0),s}function qr(t,e,r){var i=t.doc;if((r+=t.display.viewOffset)<0)return Kr(i.first,0,null,!0,-1);var n=ft(i,r),s=i.first+i.size-1;if(n>s)return Kr(i.first+i.size-1,at(i,s).text.length,null,!0,1);e<0&&(e=0);for(var o=at(i,n);;){var a=Qr(t,o,n,e,r),l=Ut(o,a.ch+(a.xRel>0?1:0));if(!l)return a;var c=l.find(1);if(c.line==n)return c;o=at(i,n=c.line)}}function Yr(t,e,r,i){i-=Hr(e);var n=e.text.length,s=ot(function(e){return Ar(t,r,e-1).bottom<=i},n,0);return n=ot(function(e){return Ar(t,r,e).top>i},s,n),{begin:s,end:n}}function Jr(t,e,r,i){r||(r=Nr(t,e));var n=Gr(t,e,Ar(t,r,i),"line").top;return Yr(t,e,r,n)}function Zr(t,e,r,i){return!(t.bottom<=r)&&(t.top>r||(i?t.left:t.right)>e)}function Qr(t,e,r,i,n){n-=jt(e);var s=Nr(t,e),o=Hr(e),a=0,l=e.text.length,c=!0,h=Qt(e,t.doc.direction);if(h){var u=(t.options.lineWrapping?function(t,e,r,i,n,s,o){var a=Yr(t,e,i,o),l=a.begin,c=a.end;/\s/.test(e.text.charAt(c-1))&&c--;for(var h=null,u=null,f=0;f<n.length;f++){var d=n[f];if(!(d.from>=c||d.to<=l)){var p=1!=d.level,g=Ar(t,i,p?Math.min(c,d.to)-1:Math.max(l,d.from)).right,m=g<s?s-g+1e9:g-s;(!h||u>m)&&(h=d,u=m)}}return h||(h=n[n.length-1]),h.from<l&&(h={from:l,to:h.to,level:h.level}),h.to>c&&(h={from:h.from,to:c,level:h.level}),h}:function(t,e,r,i,n,s,o){var a=ot(function(a){var l=n[a],c=1!=l.level;return Zr(Xr(t,gt(r,c?l.to:l.from,c?"before":"after"),"line",e,i),s,o,!0)},0,n.length-1),l=n[a];if(a>0){var c=1!=l.level,h=Xr(t,gt(r,c?l.from:l.to,c?"after":"before"),"line",e,i);Zr(h,s,o,!0)&&h.top>o&&(l=n[a-1])}return l})(t,e,r,s,h,i,n);c=1!=u.level,a=c?u.from:u.to-1,l=c?u.to:u.from-1}var f,d,p=null,g=null,m=ot(function(e){var r=Ar(t,s,e);return r.top+=o,r.bottom+=o,!!Zr(r,i,n,!1)&&(r.top<=n&&r.left<=i&&(p=e,g=r),!0)},a,l),v=!1;if(g){var y=i-g.left<g.right-i,b=y==c;m=p+(b?0:1),d=b?"after":"before",f=y?g.left:g.right}else{c||m!=l&&m!=a||m++,d=0==m?"after":m==e.text.length?"before":Ar(t,s,m-(c?1:0)).bottom+o<=n==c?"after":"before";var x=Xr(t,gt(r,m,d),"line",e,s);f=x.left,v=n<x.top||n>=x.bottom}return m=st(e.text,m,1),Kr(r,m,d,v,i-f)}function $r(t){if(null!=t.cachedTextHeight)return t.cachedTextHeight;if(null==Dr){Dr=L("pre");for(var e=0;e<49;++e)Dr.appendChild(document.createTextNode("x")),Dr.appendChild(L("br"));Dr.appendChild(document.createTextNode("x"))}O(t.measure,Dr);var r=Dr.offsetHeight/50;return r>3&&(t.cachedTextHeight=r),I(t.measure),r||1}function ti(t){if(null!=t.cachedCharWidth)return t.cachedCharWidth;var e=L("span","xxxxxxxxxx"),r=L("pre",[e]);O(t.measure,r);var i=e.getBoundingClientRect(),n=(i.right-i.left)/10;return n>2&&(t.cachedCharWidth=n),n||10}function ei(t){for(var e=t.display,r={},i={},n=e.gutters.clientLeft,s=e.gutters.firstChild,o=0;s;s=s.nextSibling,++o)r[t.options.gutters[o]]=s.offsetLeft+s.clientLeft+n,i[t.options.gutters[o]]=s.clientWidth;return{fixedPos:ri(e),gutterTotalWidth:e.gutters.offsetWidth,gutterLeft:r,gutterWidth:i,wrapperWidth:e.wrapper.clientWidth}}function ri(t){return t.scroller.getBoundingClientRect().left-t.sizer.getBoundingClientRect().left}function ii(t){var e=$r(t.display),r=t.options.lineWrapping,i=r&&Math.max(5,t.display.scroller.clientWidth/ti(t.display)-3);return function(n){if(_t(t.doc,n))return 0;var s=0;if(n.widgets)for(var o=0;o<n.widgets.length;o++)n.widgets[o].height&&(s+=n.widgets[o].height);return r?s+(Math.ceil(n.text.length/i)||1)*e:s+e}}function ni(t){var e=t.doc,r=ii(t);e.iter(function(t){var e=r(t);e!=t.height&&ht(t,e)})}function si(t,e,r,i){var n=t.display;if(!r&&"true"==fe(e).getAttribute("cm-not-content"))return null;var s,o,a=n.lineSpace.getBoundingClientRect();try{s=e.clientX-a.left,o=e.clientY-a.top}catch(e){return null}var l,c=qr(t,s,o);if(i&&1==c.xRel&&(l=at(t.doc,c.line).text).length==c.ch){var h=F(l,l.length,t.options.tabSize)-l.length;c=gt(c.line,Math.max(0,Math.round((s-Sr(t.display).left)/ti(t.display))-h))}return c}function oi(t,e){if(e>=t.display.viewTo)return null;if((e-=t.display.viewFrom)<0)return null;for(var r=t.display.view,i=0;i<r.length;i++)if((e-=r[i].size)<0)return i}function ai(t){t.display.input.showSelection(t.display.input.prepareSelection())}function li(t,e){void 0===e&&(e=!0);for(var r=t.doc,i={},n=i.cursors=document.createDocumentFragment(),s=i.selection=document.createDocumentFragment(),o=0;o<r.sel.ranges.length;o++)if(e||o!=r.sel.primIndex){var a=r.sel.ranges[o];if(!(a.from().line>=t.display.viewTo||a.to().line<t.display.viewFrom)){var l=a.empty();(l||t.options.showCursorWhenSelecting)&&ci(t,a.head,n),l||ui(t,a,s)}}return i}function ci(t,e,r){var i=Xr(t,e,"div",null,null,!t.options.singleCursorHeightPerLine),n=r.appendChild(L("div"," ","CodeMirror-cursor"));if(n.style.left=i.left+"px",n.style.top=i.top+"px",n.style.height=Math.max(0,i.bottom-i.top)*t.options.cursorHeight+"px",i.other){var s=r.appendChild(L("div"," ","CodeMirror-cursor CodeMirror-secondarycursor"));s.style.display="",s.style.left=i.other.left+"px",s.style.top=i.other.top+"px",s.style.height=.85*(i.other.bottom-i.other.top)+"px"}}function hi(t,e){return t.top-e.top||t.left-e.left}function ui(t,e,r){var i=t.display,n=t.doc,s=document.createDocumentFragment(),o=Sr(t.display),a=o.left,l=Math.max(i.sizerWidth,Tr(t)-i.sizer.offsetLeft)-o.right,c="ltr"==n.direction;function h(t,e,r,i){e<0&&(e=0),e=Math.round(e),i=Math.round(i),s.appendChild(L("div",null,"CodeMirror-selected","position: absolute; left: "+t+"px;\n top: "+e+"px; width: "+(null==r?l-t:r)+"px;\n height: "+(i-e)+"px"))}function u(e,r,i){var s,o,u=at(n,e),f=u.text.length;function d(r,i){return _r(t,gt(e,r),"div",u,i)}function p(e,r,i){var n=Jr(t,u,null,e),s="ltr"==r==("after"==i)?"left":"right",o="after"==i?n.begin:n.end-(/\s/.test(u.text.charAt(n.end-1))?2:1);return d(o,s)[s]}var g=Qt(u,n.direction);return function(t,e,r,i){if(!t)return i(e,r,"ltr",0);for(var n=!1,s=0;s<t.length;++s){var o=t[s];(o.from<r&&o.to>e||e==r&&o.to==e)&&(i(Math.max(o.from,e),Math.min(o.to,r),1==o.level?"rtl":"ltr",s),n=!0)}n||i(e,r,"ltr")}(g,r||0,null==i?f:i,function(t,e,n,u){var m="ltr"==n,v=d(t,m?"left":"right"),y=d(e-1,m?"right":"left"),b=null==r&&0==t,x=null==i&&e==f,w=0==u,k=!g||u==g.length-1;if(y.top-v.top<=3){var S=(c?b:x)&&w,E=(c?x:b)&&k,T=S?a:(m?v:y).left,C=E?l:(m?y:v).right;h(T,v.top,C-T,v.bottom)}else{var I,O,L,N;m?(I=c&&b&&w?a:v.left,O=c?l:p(t,n,"before"),L=c?a:p(e,n,"after"),N=c&&x&&k?l:y.right):(I=c?p(t,n,"before"):a,O=!c&&b&&w?l:v.right,L=!c&&x&&k?a:y.left,N=c?p(e,n,"after"):l),h(I,v.top,O-I,v.bottom),v.bottom<y.top&&h(a,v.bottom,null,y.top),h(L,y.top,N-L,y.bottom)}(!s||hi(v,s)<0)&&(s=v),hi(y,s)<0&&(s=y),(!o||hi(v,o)<0)&&(o=v),hi(y,o)<0&&(o=y)}),{start:s,end:o}}var f=e.from(),d=e.to();if(f.line==d.line)u(f.line,f.ch,d.ch);else{var p=at(n,f.line),g=at(n,d.line),m=Ht(p)==Ht(g),v=u(f.line,f.ch,m?p.text.length+1:null).end,y=u(d.line,m?0:null,d.ch).start;m&&(v.top<y.top-2?(h(v.right,v.top,null,v.bottom),h(a,y.top,y.left,y.bottom)):h(v.right,v.top,y.left-v.right,v.bottom)),v.bottom<y.top&&h(a,v.bottom,null,y.top)}r.appendChild(s)}function fi(t){if(t.state.focused){var e=t.display;clearInterval(e.blinker);var r=!0;e.cursorDiv.style.visibility="",t.options.cursorBlinkRate>0?e.blinker=setInterval(function(){return e.cursorDiv.style.visibility=(r=!r)?"":"hidden"},t.options.cursorBlinkRate):t.options.cursorBlinkRate<0&&(e.cursorDiv.style.visibility="hidden")}}function di(t){t.state.focused||(t.display.input.focus(),gi(t))}function pi(t){t.state.delayingBlurEvent=!0,setTimeout(function(){t.state.delayingBlurEvent&&(t.state.delayingBlurEvent=!1,mi(t))},100)}function gi(t,e){t.state.delayingBlurEvent&&(t.state.delayingBlurEvent=!1),"nocursor"!=t.options.readOnly&&(t.state.focused||(ie(t,"focus",t,e),t.state.focused=!0,R(t.display.wrapper,"CodeMirror-focused"),t.curOp||t.display.selForContextMenu==t.doc.sel||(t.display.input.reset(),l&&setTimeout(function(){return t.display.input.reset(!0)},20)),t.display.input.receivedFocus()),fi(t))}function mi(t,e){t.state.delayingBlurEvent||(t.state.focused&&(ie(t,"blur",t,e),t.state.focused=!1,C(t.display.wrapper,"CodeMirror-focused")),clearInterval(t.display.blinker),setTimeout(function(){t.state.focused||(t.display.shift=!1)},150))}function vi(t){for(var e=t.display,r=e.lineDiv.offsetTop,i=0;i<e.view.length;i++){var n=e.view[i],s=void 0;if(!n.hidden){if(o&&a<8){var l=n.node.offsetTop+n.node.offsetHeight;s=l-r,r=l}else{var c=n.node.getBoundingClientRect();s=c.bottom-c.top}var h=n.line.height-s;if(s<2&&(s=$r(e)),(h>.005||h<-.005)&&(ht(n.line,s),yi(n.line),n.rest))for(var u=0;u<n.rest.length;u++)yi(n.rest[u])}}}function yi(t){if(t.widgets)for(var e=0;e<t.widgets.length;++e){var r=t.widgets[e],i=r.node.parentNode;i&&(r.height=i.offsetHeight)}}function bi(t,e,r){var i=r&&null!=r.top?Math.max(0,r.top):t.scroller.scrollTop;i=Math.floor(i-wr(t));var n=r&&null!=r.bottom?r.bottom:i+t.wrapper.clientHeight,s=ft(e,i),o=ft(e,n);if(r&&r.ensure){var a=r.ensure.from.line,l=r.ensure.to.line;a<s?(s=a,o=ft(e,jt(at(e,a))+t.wrapper.clientHeight)):Math.min(l,e.lastLine())>=o&&(s=ft(e,jt(at(e,l))-t.wrapper.clientHeight),o=l)}return{from:s,to:Math.max(o,s+1)}}function xi(t){var e=t.display,r=e.view;if(e.alignWidgets||e.gutters.firstChild&&t.options.fixedGutter){for(var i=ri(e)-e.scroller.scrollLeft+t.doc.scrollLeft,n=e.gutters.offsetWidth,s=i+"px",o=0;o<r.length;o++)if(!r[o].hidden){t.options.fixedGutter&&(r[o].gutter&&(r[o].gutter.style.left=s),r[o].gutterBackground&&(r[o].gutterBackground.style.left=s));var a=r[o].alignable;if(a)for(var l=0;l<a.length;l++)a[l].style.left=s}t.options.fixedGutter&&(e.gutters.style.left=i+n+"px")}}function wi(t){if(!t.options.lineNumbers)return!1;var e=t.doc,r=pt(t.options,e.first+e.size-1),i=t.display;if(r.length!=i.lineNumChars){var n=i.measure.appendChild(L("div",[L("div",r)],"CodeMirror-linenumber CodeMirror-gutter-elt")),s=n.firstChild.offsetWidth,o=n.offsetWidth-s;return i.lineGutter.style.width="",i.lineNumInnerWidth=Math.max(s,i.lineGutter.offsetWidth-o)+1,i.lineNumWidth=i.lineNumInnerWidth+o,i.lineNumChars=i.lineNumInnerWidth?r.length:-1,i.lineGutter.style.width=i.lineNumWidth+"px",ln(t),!0}return!1}function ki(t,e){var r=t.display,i=$r(t.display);e.top<0&&(e.top=0);var n=t.curOp&&null!=t.curOp.scrollTop?t.curOp.scrollTop:r.scroller.scrollTop,s=Cr(t),o={};e.bottom-e.top>s&&(e.bottom=e.top+s);var a=t.doc.height+kr(r),l=e.top<i,c=e.bottom>a-i;if(e.top<n)o.scrollTop=l?0:e.top;else if(e.bottom>n+s){var h=Math.min(e.top,(c?a:e.bottom)-s);h!=n&&(o.scrollTop=h)}var u=t.curOp&&null!=t.curOp.scrollLeft?t.curOp.scrollLeft:r.scroller.scrollLeft,f=Tr(t)-(t.options.fixedGutter?r.gutters.offsetWidth:0),d=e.right-e.left>f;return d&&(e.right=e.left+f),e.left<10?o.scrollLeft=0:e.left<u?o.scrollLeft=Math.max(0,e.left-(d?0:10)):e.right>f+u-3&&(o.scrollLeft=e.right+(d?0:10)-f),o}function Si(t,e){null!=e&&(Ci(t),t.curOp.scrollTop=(null==t.curOp.scrollTop?t.doc.scrollTop:t.curOp.scrollTop)+e)}function Ei(t){Ci(t);var e=t.getCursor();t.curOp.scrollToPos={from:e,to:e,margin:t.options.cursorScrollMargin}}function Ti(t,e,r){null==e&&null==r||Ci(t),null!=e&&(t.curOp.scrollLeft=e),null!=r&&(t.curOp.scrollTop=r)}function Ci(t){var e=t.curOp.scrollToPos;if(e){t.curOp.scrollToPos=null;var r=jr(t,e.from),i=jr(t,e.to);Ii(t,r,i,e.margin)}}function Ii(t,e,r,i){var n=ki(t,{left:Math.min(e.left,r.left),top:Math.min(e.top,r.top)-i,right:Math.max(e.right,r.right),bottom:Math.max(e.bottom,r.bottom)+i});Ti(t,n.scrollLeft,n.scrollTop)}function Oi(t,e){Math.abs(t.doc.scrollTop-e)<2||(r||an(t,{top:e}),Li(t,e,!0),r&&an(t),en(t,100))}function Li(t,e,r){e=Math.min(t.display.scroller.scrollHeight-t.display.scroller.clientHeight,e),(t.display.scroller.scrollTop!=e||r)&&(t.doc.scrollTop=e,t.display.scrollbars.setScrollTop(e),t.display.scroller.scrollTop!=e&&(t.display.scroller.scrollTop=e))}function Ni(t,e,r,i){e=Math.min(e,t.display.scroller.scrollWidth-t.display.scroller.clientWidth),(r?e==t.doc.scrollLeft:Math.abs(t.doc.scrollLeft-e)<2)&&!i||(t.doc.scrollLeft=e,xi(t),t.display.scroller.scrollLeft!=e&&(t.display.scroller.scrollLeft=e),t.display.scrollbars.setScrollLeft(e))}function Ai(t){var e=t.display,r=e.gutters.offsetWidth,i=Math.round(t.doc.height+kr(t.display));return{clientHeight:e.scroller.clientHeight,viewHeight:e.wrapper.clientHeight,scrollWidth:e.scroller.scrollWidth,clientWidth:e.scroller.clientWidth,viewWidth:e.wrapper.clientWidth,barLeft:t.options.fixedGutter?r:0,docHeight:i,scrollHeight:i+Er(t)+e.barHeight,nativeBarWidth:e.nativeBarWidth,gutterWidth:r}}var Di=function(t,e,r){this.cm=r;var i=this.vert=L("div",[L("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),n=this.horiz=L("div",[L("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");i.tabIndex=n.tabIndex=-1,t(i),t(n),te(i,"scroll",function(){i.clientHeight&&e(i.scrollTop,"vertical")}),te(n,"scroll",function(){n.clientWidth&&e(n.scrollLeft,"horizontal")}),this.checkedZeroWidth=!1,o&&a<8&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")};Di.prototype.update=function(t){var e=t.scrollWidth>t.clientWidth+1,r=t.scrollHeight>t.clientHeight+1,i=t.nativeBarWidth;if(r){this.vert.style.display="block",this.vert.style.bottom=e?i+"px":"0";var n=t.viewHeight-(e?i:0);this.vert.firstChild.style.height=Math.max(0,t.scrollHeight-t.clientHeight+n)+"px"}else this.vert.style.display="",this.vert.firstChild.style.height="0";if(e){this.horiz.style.display="block",this.horiz.style.right=r?i+"px":"0",this.horiz.style.left=t.barLeft+"px";var s=t.viewWidth-t.barLeft-(r?i:0);this.horiz.firstChild.style.width=Math.max(0,t.scrollWidth-t.clientWidth+s)+"px"}else this.horiz.style.display="",this.horiz.firstChild.style.width="0";return!this.checkedZeroWidth&&t.clientHeight>0&&(0==i&&this.zeroWidthHack(),this.checkedZeroWidth=!0),{right:r?i:0,bottom:e?i:0}},Di.prototype.setScrollLeft=function(t){this.horiz.scrollLeft!=t&&(this.horiz.scrollLeft=t),this.disableHoriz&&this.enableZeroWidthBar(this.horiz,this.disableHoriz,"horiz")},Di.prototype.setScrollTop=function(t){this.vert.scrollTop!=t&&(this.vert.scrollTop=t),this.disableVert&&this.enableZeroWidthBar(this.vert,this.disableVert,"vert")},Di.prototype.zeroWidthHack=function(){var t=y&&!d?"12px":"18px";this.horiz.style.height=this.vert.style.width=t,this.horiz.style.pointerEvents=this.vert.style.pointerEvents="none",this.disableHoriz=new U,this.disableVert=new U},Di.prototype.enableZeroWidthBar=function(t,e,r){t.style.pointerEvents="auto",e.set(1e3,function i(){var n=t.getBoundingClientRect(),s="vert"==r?document.elementFromPoint(n.right-1,(n.top+n.bottom)/2):document.elementFromPoint((n.right+n.left)/2,n.bottom-1);s!=t?t.style.pointerEvents="none":e.set(1e3,i)})},Di.prototype.clear=function(){var t=this.horiz.parentNode;t.removeChild(this.horiz),t.removeChild(this.vert)};var Ri=function(){};function Mi(t,e){e||(e=Ai(t));var r=t.display.barWidth,i=t.display.barHeight;Pi(t,e);for(var n=0;n<4&&r!=t.display.barWidth||i!=t.display.barHeight;n++)r!=t.display.barWidth&&t.options.lineWrapping&&vi(t),Pi(t,Ai(t)),r=t.display.barWidth,i=t.display.barHeight}function Pi(t,e){var r=t.display,i=r.scrollbars.update(e);r.sizer.style.paddingRight=(r.barWidth=i.right)+"px",r.sizer.style.paddingBottom=(r.barHeight=i.bottom)+"px",r.heightForcer.style.borderBottom=i.bottom+"px solid transparent",i.right&&i.bottom?(r.scrollbarFiller.style.display="block",r.scrollbarFiller.style.height=i.bottom+"px",r.scrollbarFiller.style.width=i.right+"px"):r.scrollbarFiller.style.display="",i.bottom&&t.options.coverGutterNextToScrollbar&&t.options.fixedGutter?(r.gutterFiller.style.display="block",r.gutterFiller.style.height=i.bottom+"px",r.gutterFiller.style.width=e.gutterWidth+"px"):r.gutterFiller.style.display=""}Ri.prototype.update=function(){return{bottom:0,right:0}},Ri.prototype.setScrollLeft=function(){},Ri.prototype.setScrollTop=function(){},Ri.prototype.clear=function(){};var Vi={native:Di,null:Ri};function Bi(t){t.display.scrollbars&&(t.display.scrollbars.clear(),t.display.scrollbars.addClass&&C(t.display.wrapper,t.display.scrollbars.addClass)),t.display.scrollbars=new Vi[t.options.scrollbarStyle](function(e){t.display.wrapper.insertBefore(e,t.display.scrollbarFiller),te(e,"mousedown",function(){t.state.focused&&setTimeout(function(){return t.display.input.focus()},0)}),e.setAttribute("cm-not-content","true")},function(e,r){"horizontal"==r?Ni(t,e):Oi(t,e)},t),t.display.scrollbars.addClass&&R(t.display.wrapper,t.display.scrollbars.addClass)}var Fi=0;function Ui(t){t.curOp={cm:t,viewChanged:!1,startHeight:t.doc.height,forceUpdate:!1,updateInput:null,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++Fi},function(t){nr?nr.ops.push(t):t.ownsGroup=nr={ops:[t],delayedCallbacks:[]}}(t.curOp)}function Wi(t){var e=t.curOp;!function(t,e){var r=t.ownsGroup;if(r)try{!function(t){var e=t.delayedCallbacks,r=0;do{for(;r<e.length;r++)e[r].call(null);for(var i=0;i<t.ops.length;i++){var n=t.ops[i];if(n.cursorActivityHandlers)for(;n.cursorActivityCalled<n.cursorActivityHandlers.length;)n.cursorActivityHandlers[n.cursorActivityCalled++].call(null,n.cm)}}while(r<e.length)}(r)}finally{nr=null,e(r)}}(e,function(t){for(var e=0;e<t.ops.length;e++)t.ops[e].cm.curOp=null;!function(t){for(var e=t.ops,r=0;r<e.length;r++)Hi(e[r]);for(var i=0;i<e.length;i++)Gi(e[i]);for(var n=0;n<e.length;n++)zi(e[n]);for(var s=0;s<e.length;s++)_i(e[s]);for(var o=0;o<e.length;o++)Xi(e[o])}(t)})}function Hi(t){var e=t.cm,r=e.display;!function(t){var e=t.display;!e.scrollbarsClipped&&e.scroller.offsetWidth&&(e.nativeBarWidth=e.scroller.offsetWidth-e.scroller.clientWidth,e.heightForcer.style.height=Er(t)+"px",e.sizer.style.marginBottom=-e.nativeBarWidth+"px",e.sizer.style.borderRightWidth=Er(t)+"px",e.scrollbarsClipped=!0)}(e),t.updateMaxLine&&qt(e),t.mustUpdate=t.viewChanged||t.forceUpdate||null!=t.scrollTop||t.scrollToPos&&(t.scrollToPos.from.line<r.viewFrom||t.scrollToPos.to.line>=r.viewTo)||r.maxLineChanged&&e.options.lineWrapping,t.update=t.mustUpdate&&new nn(e,t.mustUpdate&&{top:t.scrollTop,ensure:t.scrollToPos},t.forceUpdate)}function Gi(t){t.updatedDisplay=t.mustUpdate&&sn(t.cm,t.update)}function zi(t){var e=t.cm,r=e.display;t.updatedDisplay&&vi(e),t.barMeasure=Ai(e),r.maxLineChanged&&!e.options.lineWrapping&&(t.adjustWidthTo=Or(e,r.maxLine,r.maxLine.text.length).left+3,e.display.sizerWidth=t.adjustWidthTo,t.barMeasure.scrollWidth=Math.max(r.scroller.clientWidth,r.sizer.offsetLeft+t.adjustWidthTo+Er(e)+e.display.barWidth),t.maxScrollLeft=Math.max(0,r.sizer.offsetLeft+t.adjustWidthTo-Tr(e))),(t.updatedDisplay||t.selectionChanged)&&(t.preparedSelection=r.input.prepareSelection())}function _i(t){var e=t.cm;null!=t.adjustWidthTo&&(e.display.sizer.style.minWidth=t.adjustWidthTo+"px",t.maxScrollLeft<e.doc.scrollLeft&&Ni(e,Math.min(e.display.scroller.scrollLeft,t.maxScrollLeft),!0),e.display.maxLineChanged=!1);var r=t.focus&&t.focus==D();t.preparedSelection&&e.display.input.showSelection(t.preparedSelection,r),(t.updatedDisplay||t.startHeight!=e.doc.height)&&Mi(e,t.barMeasure),t.updatedDisplay&&cn(e,t.barMeasure),t.selectionChanged&&fi(e),e.state.focused&&t.updateInput&&e.display.input.reset(t.typing),r&&di(t.cm)}function Xi(t){var e=t.cm,r=e.display,i=e.doc;if(t.updatedDisplay&&on(e,t.update),null==r.wheelStartX||null==t.scrollTop&&null==t.scrollLeft&&!t.scrollToPos||(r.wheelStartX=r.wheelStartY=null),null!=t.scrollTop&&Li(e,t.scrollTop,t.forceScroll),null!=t.scrollLeft&&Ni(e,t.scrollLeft,!0,!0),t.scrollToPos){var n=function(t,e,r,i){var n;null==i&&(i=0),t.options.lineWrapping||e!=r||(e=e.ch?gt(e.line,"before"==e.sticky?e.ch-1:e.ch,"after"):e,r="before"==e.sticky?gt(e.line,e.ch+1,"before"):e);for(var s=0;s<5;s++){var o=!1,a=Xr(t,e),l=r&&r!=e?Xr(t,r):a;n={left:Math.min(a.left,l.left),top:Math.min(a.top,l.top)-i,right:Math.max(a.left,l.left),bottom:Math.max(a.bottom,l.bottom)+i};var c=ki(t,n),h=t.doc.scrollTop,u=t.doc.scrollLeft;if(null!=c.scrollTop&&(Oi(t,c.scrollTop),Math.abs(t.doc.scrollTop-h)>1&&(o=!0)),null!=c.scrollLeft&&(Ni(t,c.scrollLeft),Math.abs(t.doc.scrollLeft-u)>1&&(o=!0)),!o)break}return n}(e,kt(i,t.scrollToPos.from),kt(i,t.scrollToPos.to),t.scrollToPos.margin);!function(t,e){if(!ne(t,"scrollCursorIntoView")){var r=t.display,i=r.sizer.getBoundingClientRect(),n=null;if(e.top+i.top<0?n=!0:e.bottom+i.top>(window.innerHeight||document.documentElement.clientHeight)&&(n=!1),null!=n&&!p){var s=L("div","",null,"position: absolute;\n top: "+(e.top-r.viewOffset-wr(t.display))+"px;\n height: "+(e.bottom-e.top+Er(t)+r.barHeight)+"px;\n left: "+e.left+"px; width: "+Math.max(2,e.right-e.left)+"px;");t.display.lineSpace.appendChild(s),s.scrollIntoView(n),t.display.lineSpace.removeChild(s)}}}(e,n)}var s=t.maybeHiddenMarkers,o=t.maybeUnhiddenMarkers;if(s)for(var a=0;a<s.length;++a)s[a].lines.length||ie(s[a],"hide");if(o)for(var l=0;l<o.length;++l)o[l].lines.length&&ie(o[l],"unhide");r.wrapper.offsetHeight&&(i.scrollTop=e.display.scroller.scrollTop),t.changeObjs&&ie(e,"changes",e,t.changeObjs),t.update&&t.update.finish()}function ji(t,e){if(t.curOp)return e();Ui(t);try{return e()}finally{Wi(t)}}function Ki(t,e){return function(){if(t.curOp)return e.apply(t,arguments);Ui(t);try{return e.apply(t,arguments)}finally{Wi(t)}}}function qi(t){return function(){if(this.curOp)return t.apply(this,arguments);Ui(this);try{return t.apply(this,arguments)}finally{Wi(this)}}}function Yi(t){return function(){var e=this.cm;if(!e||e.curOp)return t.apply(this,arguments);Ui(e);try{return t.apply(this,arguments)}finally{Wi(e)}}}function Ji(t,e,r,i){null==e&&(e=t.doc.first),null==r&&(r=t.doc.first+t.doc.size),i||(i=0);var n=t.display;if(i&&r<n.viewTo&&(null==n.updateLineNumbers||n.updateLineNumbers>e)&&(n.updateLineNumbers=e),t.curOp.viewChanged=!0,e>=n.viewTo)Tt&&Gt(t.doc,e)<n.viewTo&&Qi(t);else if(r<=n.viewFrom)Tt&&zt(t.doc,r+i)>n.viewFrom?Qi(t):(n.viewFrom+=i,n.viewTo+=i);else if(e<=n.viewFrom&&r>=n.viewTo)Qi(t);else if(e<=n.viewFrom){var s=$i(t,r,r+i,1);s?(n.view=n.view.slice(s.index),n.viewFrom=s.lineN,n.viewTo+=i):Qi(t)}else if(r>=n.viewTo){var o=$i(t,e,e,-1);o?(n.view=n.view.slice(0,o.index),n.viewTo=o.lineN):Qi(t)}else{var a=$i(t,e,e,-1),l=$i(t,r,r+i,1);a&&l?(n.view=n.view.slice(0,a.index).concat(ir(t,a.lineN,l.lineN)).concat(n.view.slice(l.index)),n.viewTo+=i):Qi(t)}var c=n.externalMeasured;c&&(r<c.lineN?c.lineN+=i:e<c.lineN+c.size&&(n.externalMeasured=null))}function Zi(t,e,r){t.curOp.viewChanged=!0;var i=t.display,n=t.display.externalMeasured;if(n&&e>=n.lineN&&e<n.lineN+n.size&&(i.externalMeasured=null),!(e<i.viewFrom||e>=i.viewTo)){var s=i.view[oi(t,e)];if(null!=s.node){var o=s.changes||(s.changes=[]);-1==W(o,r)&&o.push(r)}}}function Qi(t){t.display.viewFrom=t.display.viewTo=t.doc.first,t.display.view=[],t.display.viewOffset=0}function $i(t,e,r,i){var n,s=oi(t,e),o=t.display.view;if(!Tt||r==t.doc.first+t.doc.size)return{index:s,lineN:r};for(var a=t.display.viewFrom,l=0;l<s;l++)a+=o[l].size;if(a!=e){if(i>0){if(s==o.length-1)return null;n=a+o[s].size-e,s++}else n=a-e;e+=n,r+=n}for(;Gt(t.doc,r)!=r;){if(s==(i<0?0:o.length-1))return null;r+=i*o[s-(i<0?1:0)].size,s+=i}return{index:s,lineN:r}}function tn(t){for(var e=t.display.view,r=0,i=0;i<e.length;i++){var n=e[i];n.hidden||n.node&&!n.changes||++r}return r}function en(t,e){t.doc.highlightFrontier<t.display.viewTo&&t.state.highlight.set(e,V(rn,t))}function rn(t){var e=t.doc;if(!(e.highlightFrontier>=t.display.viewTo)){var r=+new Date+t.options.workTime,i=Be(t,e.highlightFrontier),n=[];e.iter(i.line,Math.min(e.first+e.size,t.display.viewTo+500),function(s){if(i.line>=t.display.viewFrom){var o=s.styles,a=s.text.length>t.options.maxHighlightLength?Le(e.mode,i.state):null,l=Pe(t,s,i,!0);a&&(i.state=a),s.styles=l.styles;var c=s.styleClasses,h=l.classes;h?s.styleClasses=h:c&&(s.styleClasses=null);for(var u=!o||o.length!=s.styles.length||c!=h&&(!c||!h||c.bgClass!=h.bgClass||c.textClass!=h.textClass),f=0;!u&&f<o.length;++f)u=o[f]!=s.styles[f];u&&n.push(i.line),s.stateAfter=i.save(),i.nextLine()}else s.text.length<=t.options.maxHighlightLength&&Fe(t,s.text,i),s.stateAfter=i.line%5==0?i.save():null,i.nextLine();if(+new Date>r)return en(t,t.options.workDelay),!0}),e.highlightFrontier=i.line,e.modeFrontier=Math.max(e.modeFrontier,i.line),n.length&&ji(t,function(){for(var e=0;e<n.length;e++)Zi(t,n[e],"text")})}}var nn=function(t,e,r){var i=t.display;this.viewport=e,this.visible=bi(i,t.doc,e),this.editorIsHidden=!i.wrapper.offsetWidth,this.wrapperHeight=i.wrapper.clientHeight,this.wrapperWidth=i.wrapper.clientWidth,this.oldDisplayWidth=Tr(t),this.force=r,this.dims=ei(t),this.events=[]};function sn(t,e){var r=t.display,i=t.doc;if(e.editorIsHidden)return Qi(t),!1;if(!e.force&&e.visible.from>=r.viewFrom&&e.visible.to<=r.viewTo&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo)&&r.renderedView==r.view&&0==tn(t))return!1;wi(t)&&(Qi(t),e.dims=ei(t));var n=i.first+i.size,s=Math.max(e.visible.from-t.options.viewportMargin,i.first),o=Math.min(n,e.visible.to+t.options.viewportMargin);r.viewFrom<s&&s-r.viewFrom<20&&(s=Math.max(i.first,r.viewFrom)),r.viewTo>o&&r.viewTo-o<20&&(o=Math.min(n,r.viewTo)),Tt&&(s=Gt(t.doc,s),o=zt(t.doc,o));var a=s!=r.viewFrom||o!=r.viewTo||r.lastWrapHeight!=e.wrapperHeight||r.lastWrapWidth!=e.wrapperWidth;!function(t,e,r){var i=t.display;0==i.view.length||e>=i.viewTo||r<=i.viewFrom?(i.view=ir(t,e,r),i.viewFrom=e):(i.viewFrom>e?i.view=ir(t,e,i.viewFrom).concat(i.view):i.viewFrom<e&&(i.view=i.view.slice(oi(t,e))),i.viewFrom=e,i.viewTo<r?i.view=i.view.concat(ir(t,i.viewTo,r)):i.viewTo>r&&(i.view=i.view.slice(0,oi(t,r)))),i.viewTo=r}(t,s,o),r.viewOffset=jt(at(t.doc,r.viewFrom)),t.display.mover.style.top=r.viewOffset+"px";var c=tn(t);if(!a&&0==c&&!e.force&&r.renderedView==r.view&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo))return!1;var h=function(t){if(t.hasFocus())return null;var e=D();if(!e||!A(t.display.lineDiv,e))return null;var r={activeElt:e};if(window.getSelection){var i=window.getSelection();i.anchorNode&&i.extend&&A(t.display.lineDiv,i.anchorNode)&&(r.anchorNode=i.anchorNode,r.anchorOffset=i.anchorOffset,r.focusNode=i.focusNode,r.focusOffset=i.focusOffset)}return r}(t);return c>4&&(r.lineDiv.style.display="none"),function(t,e,r){var i=t.display,n=t.options.lineNumbers,s=i.lineDiv,o=s.firstChild;function a(e){var r=e.nextSibling;return l&&y&&t.display.currentWheelTarget==e?e.style.display="none":e.parentNode.removeChild(e),r}for(var c=i.view,h=i.viewFrom,u=0;u<c.length;u++){var f=c[u];if(f.hidden);else if(f.node&&f.node.parentNode==s){for(;o!=f.node;)o=a(o);var d=n&&null!=e&&e<=h&&f.lineNumber;f.changes&&(W(f.changes,"gutter")>-1&&(d=!1),lr(t,f,h,r)),d&&(I(f.lineNumber),f.lineNumber.appendChild(document.createTextNode(pt(t.options,h)))),o=f.node.nextSibling}else{var p=gr(t,f,h,r);s.insertBefore(p,o)}h+=f.size}for(;o;)o=a(o)}(t,r.updateLineNumbers,e.dims),c>4&&(r.lineDiv.style.display=""),r.renderedView=r.view,function(t){if(t&&t.activeElt&&t.activeElt!=D()&&(t.activeElt.focus(),t.anchorNode&&A(document.body,t.anchorNode)&&A(document.body,t.focusNode))){var e=window.getSelection(),r=document.createRange();r.setEnd(t.anchorNode,t.anchorOffset),r.collapse(!1),e.removeAllRanges(),e.addRange(r),e.extend(t.focusNode,t.focusOffset)}}(h),I(r.cursorDiv),I(r.selectionDiv),r.gutters.style.height=r.sizer.style.minHeight=0,a&&(r.lastWrapHeight=e.wrapperHeight,r.lastWrapWidth=e.wrapperWidth,en(t,400)),r.updateLineNumbers=null,!0}function on(t,e){for(var r=e.viewport,i=!0;(i&&t.options.lineWrapping&&e.oldDisplayWidth!=Tr(t)||(r&&null!=r.top&&(r={top:Math.min(t.doc.height+kr(t.display)-Cr(t),r.top)}),e.visible=bi(t.display,t.doc,r),!(e.visible.from>=t.display.viewFrom&&e.visible.to<=t.display.viewTo)))&&sn(t,e);i=!1){vi(t);var n=Ai(t);ai(t),Mi(t,n),cn(t,n),e.force=!1}e.signal(t,"update",t),t.display.viewFrom==t.display.reportedViewFrom&&t.display.viewTo==t.display.reportedViewTo||(e.signal(t,"viewportChange",t,t.display.viewFrom,t.display.viewTo),t.display.reportedViewFrom=t.display.viewFrom,t.display.reportedViewTo=t.display.viewTo)}function an(t,e){var r=new nn(t,e);if(sn(t,r)){vi(t),on(t,r);var i=Ai(t);ai(t),Mi(t,i),cn(t,i),r.finish()}}function ln(t){var e=t.display.gutters.offsetWidth;t.display.sizer.style.marginLeft=e+"px"}function cn(t,e){t.display.sizer.style.minHeight=e.docHeight+"px",t.display.heightForcer.style.top=e.docHeight+"px",t.display.gutters.style.height=e.docHeight+t.display.barHeight+Er(t)+"px"}function hn(t){var e=t.display.gutters,r=t.options.gutters;I(e);for(var i=0;i<r.length;++i){var n=r[i],s=e.appendChild(L("div",null,"CodeMirror-gutter "+n));"CodeMirror-linenumbers"==n&&(t.display.lineGutter=s,s.style.width=(t.display.lineNumWidth||1)+"px")}e.style.display=i?"":"none",ln(t)}function un(t){var e=W(t.gutters,"CodeMirror-linenumbers");-1==e&&t.lineNumbers?t.gutters=t.gutters.concat(["CodeMirror-linenumbers"]):e>-1&&!t.lineNumbers&&(t.gutters=t.gutters.slice(0),t.gutters.splice(e,1))}nn.prototype.signal=function(t,e){oe(t,e)&&this.events.push(arguments)},nn.prototype.finish=function(){for(var t=0;t<this.events.length;t++)ie.apply(null,this.events[t])};var fn=0,dn=null;function pn(t){var e=t.wheelDeltaX,r=t.wheelDeltaY;return null==e&&t.detail&&t.axis==t.HORIZONTAL_AXIS&&(e=t.detail),null==r&&t.detail&&t.axis==t.VERTICAL_AXIS?r=t.detail:null==r&&(r=t.wheelDelta),{x:e,y:r}}function gn(t){var e=pn(t);return e.x*=dn,e.y*=dn,e}function mn(t,e){var i=pn(e),n=i.x,s=i.y,o=t.display,a=o.scroller,c=a.scrollWidth>a.clientWidth,h=a.scrollHeight>a.clientHeight;if(n&&c||s&&h){if(s&&y&&l)t:for(var f=e.target,d=o.view;f!=a;f=f.parentNode)for(var p=0;p<d.length;p++)if(d[p].node==f){t.display.currentWheelTarget=f;break t}if(n&&!r&&!u&&null!=dn)return s&&h&&Oi(t,Math.max(0,a.scrollTop+s*dn)),Ni(t,Math.max(0,a.scrollLeft+n*dn)),(!s||s&&h)&&le(e),void(o.wheelStartX=null);if(s&&null!=dn){var g=s*dn,m=t.doc.scrollTop,v=m+o.wrapper.clientHeight;g<0?m=Math.max(0,m+g-50):v=Math.min(t.doc.height,v+g+50),an(t,{top:m,bottom:v})}fn<20&&(null==o.wheelStartX?(o.wheelStartX=a.scrollLeft,o.wheelStartY=a.scrollTop,o.wheelDX=n,o.wheelDY=s,setTimeout(function(){if(null!=o.wheelStartX){var t=a.scrollLeft-o.wheelStartX,e=a.scrollTop-o.wheelStartY,r=e&&o.wheelDY&&e/o.wheelDY||t&&o.wheelDX&&t/o.wheelDX;o.wheelStartX=o.wheelStartY=null,r&&(dn=(dn*fn+r)/(fn+1),++fn)}},200)):(o.wheelDX+=n,o.wheelDY+=s))}}o?dn=-.53:r?dn=15:h?dn=-.7:f&&(dn=-1/3);var vn=function(t,e){this.ranges=t,this.primIndex=e};vn.prototype.primary=function(){return this.ranges[this.primIndex]},vn.prototype.equals=function(t){if(t==this)return!0;if(t.primIndex!=this.primIndex||t.ranges.length!=this.ranges.length)return!1;for(var e=0;e<this.ranges.length;e++){var r=this.ranges[e],i=t.ranges[e];if(!vt(r.anchor,i.anchor)||!vt(r.head,i.head))return!1}return!0},vn.prototype.deepCopy=function(){for(var t=[],e=0;e<this.ranges.length;e++)t[e]=new yn(yt(this.ranges[e].anchor),yt(this.ranges[e].head));return new vn(t,this.primIndex)},vn.prototype.somethingSelected=function(){for(var t=0;t<this.ranges.length;t++)if(!this.ranges[t].empty())return!0;return!1},vn.prototype.contains=function(t,e){e||(e=t);for(var r=0;r<this.ranges.length;r++){var i=this.ranges[r];if(mt(e,i.from())>=0&&mt(t,i.to())<=0)return r}return-1};var yn=function(t,e){this.anchor=t,this.head=e};function bn(t,e){var r=t[e];t.sort(function(t,e){return mt(t.from(),e.from())}),e=W(t,r);for(var i=1;i<t.length;i++){var n=t[i],s=t[i-1];if(mt(s.to(),n.from())>=0){var o=xt(s.from(),n.from()),a=bt(s.to(),n.to()),l=s.empty()?n.from()==n.head:s.from()==s.head;i<=e&&--e,t.splice(--i,2,new yn(l?a:o,l?o:a))}}return new vn(t,e)}function xn(t,e){return new vn([new yn(t,e||t)],0)}function wn(t){return t.text?gt(t.from.line+t.text.length-1,Y(t.text).length+(1==t.text.length?t.from.ch:0)):t.to}function kn(t,e){if(mt(t,e.from)<0)return t;if(mt(t,e.to)<=0)return wn(e);var r=t.line+e.text.length-(e.to.line-e.from.line)-1,i=t.ch;return t.line==e.to.line&&(i+=wn(e).ch-e.to.ch),gt(r,i)}function Sn(t,e){for(var r=[],i=0;i<t.sel.ranges.length;i++){var n=t.sel.ranges[i];r.push(new yn(kn(n.anchor,e),kn(n.head,e)))}return bn(r,t.sel.primIndex)}function En(t,e,r){return t.line==e.line?gt(r.line,t.ch-e.ch+r.ch):gt(r.line+(t.line-e.line),t.ch)}function Tn(t){t.doc.mode=Ce(t.options,t.doc.modeOption),Cn(t)}function Cn(t){t.doc.iter(function(t){t.stateAfter&&(t.stateAfter=null),t.styles&&(t.styles=null)}),t.doc.modeFrontier=t.doc.highlightFrontier=t.doc.first,en(t,100),t.state.modeGen++,t.curOp&&Ji(t)}function In(t,e){return 0==e.from.ch&&0==e.to.ch&&""==Y(e.text)&&(!t.cm||t.cm.options.wholeLineUpdateBefore)}function On(t,e,r,i){function n(t){return r?r[t]:null}function s(t,r,n){!function(t,e,r,i){t.text=e,t.stateAfter&&(t.stateAfter=null),t.styles&&(t.styles=null),null!=t.order&&(t.order=null),At(t),Dt(t,r);var n=i?i(t):1;n!=t.height&&ht(t,n)}(t,r,n,i),or(t,"change",t,e)}function o(t,e){for(var r=[],s=t;s<e;++s)r.push(new Xe(c[s],n(s),i));return r}var a=e.from,l=e.to,c=e.text,h=at(t,a.line),u=at(t,l.line),f=Y(c),d=n(c.length-1),p=l.line-a.line;if(e.full)t.insert(0,o(0,c.length)),t.remove(c.length,t.size-c.length);else if(In(t,e)){var g=o(0,c.length-1);s(u,u.text,d),p&&t.remove(a.line,p),g.length&&t.insert(a.line,g)}else if(h==u)if(1==c.length)s(h,h.text.slice(0,a.ch)+f+h.text.slice(l.ch),d);else{var m=o(1,c.length-1);m.push(new Xe(f+h.text.slice(l.ch),d,i)),s(h,h.text.slice(0,a.ch)+c[0],n(0)),t.insert(a.line+1,m)}else if(1==c.length)s(h,h.text.slice(0,a.ch)+c[0]+u.text.slice(l.ch),n(0)),t.remove(a.line+1,p);else{s(h,h.text.slice(0,a.ch)+c[0],n(0)),s(u,f+u.text.slice(l.ch),d);var v=o(1,c.length-1);p>1&&t.remove(a.line+1,p-1),t.insert(a.line+1,v)}or(t,"change",t,e)}function Ln(t,e,r){!function t(i,n,s){if(i.linked)for(var o=0;o<i.linked.length;++o){var a=i.linked[o];if(a.doc!=n){var l=s&&a.sharedHist;r&&!l||(e(a.doc,l),t(a.doc,i,l))}}}(t,null,!0)}function Nn(t,e){if(e.cm)throw new Error("This document is already in use.");t.doc=e,e.cm=t,ni(t),Tn(t),An(t),t.options.lineWrapping||qt(t),t.options.mode=e.modeOption,Ji(t)}function An(t){("rtl"==t.doc.direction?R:C)(t.display.lineDiv,"CodeMirror-rtl")}function Dn(t){this.done=[],this.undone=[],this.undoDepth=1/0,this.lastModTime=this.lastSelTime=0,this.lastOp=this.lastSelOp=null,this.lastOrigin=this.lastSelOrigin=null,this.generation=this.maxGeneration=t||1}function Rn(t,e){var r={from:yt(e.from),to:wn(e),text:lt(t,e.from,e.to)};return Fn(t,r,e.from.line,e.to.line+1),Ln(t,function(t){return Fn(t,r,e.from.line,e.to.line+1)},!0),r}function Mn(t){for(;t.length;){var e=Y(t);if(!e.ranges)break;t.pop()}}function Pn(t,e,r,i){var n=t.history;n.undone.length=0;var s,o,a=+new Date;if((n.lastOp==i||n.lastOrigin==e.origin&&e.origin&&("+"==e.origin.charAt(0)&&n.lastModTime>a-(t.cm?t.cm.options.historyEventDelay:500)||"*"==e.origin.charAt(0)))&&(s=function(t,e){return e?(Mn(t.done),Y(t.done)):t.done.length&&!Y(t.done).ranges?Y(t.done):t.done.length>1&&!t.done[t.done.length-2].ranges?(t.done.pop(),Y(t.done)):void 0}(n,n.lastOp==i)))o=Y(s.changes),0==mt(e.from,e.to)&&0==mt(e.from,o.to)?o.to=wn(e):s.changes.push(Rn(t,e));else{var l=Y(n.done);for(l&&l.ranges||Bn(t.sel,n.done),s={changes:[Rn(t,e)],generation:n.generation},n.done.push(s);n.done.length>n.undoDepth;)n.done.shift(),n.done[0].ranges||n.done.shift()}n.done.push(r),n.generation=++n.maxGeneration,n.lastModTime=n.lastSelTime=a,n.lastOp=n.lastSelOp=i,n.lastOrigin=n.lastSelOrigin=e.origin,o||ie(t,"historyAdded")}function Vn(t,e,r,i){var n=t.history,s=i&&i.origin;r==n.lastSelOp||s&&n.lastSelOrigin==s&&(n.lastModTime==n.lastSelTime&&n.lastOrigin==s||function(t,e,r,i){var n=e.charAt(0);return"*"==n||"+"==n&&r.ranges.length==i.ranges.length&&r.somethingSelected()==i.somethingSelected()&&new Date-t.history.lastSelTime<=(t.cm?t.cm.options.historyEventDelay:500)}(t,s,Y(n.done),e))?n.done[n.done.length-1]=e:Bn(e,n.done),n.lastSelTime=+new Date,n.lastSelOrigin=s,n.lastSelOp=r,i&&!1!==i.clearRedo&&Mn(n.undone)}function Bn(t,e){var r=Y(e);r&&r.ranges&&r.equals(t)||e.push(t)}function Fn(t,e,r,i){var n=e["spans_"+t.id],s=0;t.iter(Math.max(t.first,r),Math.min(t.first+t.size,i),function(r){r.markedSpans&&((n||(n=e["spans_"+t.id]={}))[s]=r.markedSpans),++s})}function Un(t){if(!t)return null;for(var e,r=0;r<t.length;++r)t[r].marker.explicitlyCleared?e||(e=t.slice(0,r)):e&&e.push(t[r]);return e?e.length?e:null:t}function Wn(t,e){var r=function(t,e){var r=e["spans_"+t.id];if(!r)return null;for(var i=[],n=0;n<e.text.length;++n)i.push(Un(r[n]));return i}(t,e),i=Lt(t,e);if(!r)return i;if(!i)return r;for(var n=0;n<r.length;++n){var s=r[n],o=i[n];if(s&&o)t:for(var a=0;a<o.length;++a){for(var l=o[a],c=0;c<s.length;++c)if(s[c].marker==l.marker)continue t;s.push(l)}else o&&(r[n]=o)}return r}function Hn(t,e,r){for(var i=[],n=0;n<t.length;++n){var s=t[n];if(s.ranges)i.push(r?vn.prototype.deepCopy.call(s):s);else{var o=s.changes,a=[];i.push({changes:a});for(var l=0;l<o.length;++l){var c=o[l],h=void 0;if(a.push({from:c.from,to:c.to,text:c.text}),e)for(var u in c)(h=u.match(/^spans_(\d+)$/))&&W(e,Number(h[1]))>-1&&(Y(a)[u]=c[u],delete c[u])}}}return i}function Gn(t,e,r,i){if(i){var n=t.anchor;if(r){var s=mt(e,n)<0;s!=mt(r,n)<0?(n=e,e=r):s!=mt(e,r)<0&&(e=r)}return new yn(n,e)}return new yn(r||e,e)}function zn(t,e,r,i,n){null==n&&(n=t.cm&&(t.cm.display.shift||t.extend)),qn(t,new vn([Gn(t.sel.primary(),e,r,n)],0),i)}function _n(t,e,r){for(var i=[],n=t.cm&&(t.cm.display.shift||t.extend),s=0;s<t.sel.ranges.length;s++)i[s]=Gn(t.sel.ranges[s],e[s],null,n);var o=bn(i,t.sel.primIndex);qn(t,o,r)}function Xn(t,e,r,i){var n=t.sel.ranges.slice(0);n[e]=r,qn(t,bn(n,t.sel.primIndex),i)}function jn(t,e,r,i){qn(t,xn(e,r),i)}function Kn(t,e,r){var i=t.history.done,n=Y(i);n&&n.ranges?(i[i.length-1]=e,Yn(t,e,r)):qn(t,e,r)}function qn(t,e,r){Yn(t,e,r),Vn(t,t.sel,t.cm?t.cm.curOp.id:NaN,r)}function Yn(t,e,r){(oe(t,"beforeSelectionChange")||t.cm&&oe(t.cm,"beforeSelectionChange"))&&(e=function(t,e,r){var i={ranges:e.ranges,update:function(e){this.ranges=[];for(var r=0;r<e.length;r++)this.ranges[r]=new yn(kt(t,e[r].anchor),kt(t,e[r].head))},origin:r&&r.origin};return ie(t,"beforeSelectionChange",t,i),t.cm&&ie(t.cm,"beforeSelectionChange",t.cm,i),i.ranges!=e.ranges?bn(i.ranges,i.ranges.length-1):e}(t,e,r));var i=r&&r.bias||(mt(e.primary().head,t.sel.primary().head)<0?-1:1);Jn(t,Qn(t,e,i,!0)),r&&!1===r.scroll||!t.cm||Ei(t.cm)}function Jn(t,e){e.equals(t.sel)||(t.sel=e,t.cm&&(t.cm.curOp.updateInput=t.cm.curOp.selectionChanged=!0,se(t.cm)),or(t,"cursorActivity",t))}function Zn(t){Jn(t,Qn(t,t.sel,null,!1))}function Qn(t,e,r,i){for(var n,s=0;s<e.ranges.length;s++){var o=e.ranges[s],a=e.ranges.length==t.sel.ranges.length&&t.sel.ranges[s],l=ts(t,o.anchor,a&&a.anchor,r,i),c=ts(t,o.head,a&&a.head,r,i);(n||l!=o.anchor||c!=o.head)&&(n||(n=e.ranges.slice(0,s)),n[s]=new yn(l,c))}return n?bn(n,e.primIndex):e}function $n(t,e,r,i,n){var s=at(t,e.line);if(s.markedSpans)for(var o=0;o<s.markedSpans.length;++o){var a=s.markedSpans[o],l=a.marker;if((null==a.from||(l.inclusiveLeft?a.from<=e.ch:a.from<e.ch))&&(null==a.to||(l.inclusiveRight?a.to>=e.ch:a.to>e.ch))){if(n&&(ie(l,"beforeCursorEnter"),l.explicitlyCleared)){if(s.markedSpans){--o;continue}break}if(!l.atomic)continue;if(r){var c=l.find(i<0?1:-1),h=void 0;if((i<0?l.inclusiveRight:l.inclusiveLeft)&&(c=es(t,c,-i,c&&c.line==e.line?s:null)),c&&c.line==e.line&&(h=mt(c,r))&&(i<0?h<0:h>0))return $n(t,c,e,i,n)}var u=l.find(i<0?-1:1);return(i<0?l.inclusiveLeft:l.inclusiveRight)&&(u=es(t,u,i,u.line==e.line?s:null)),u?$n(t,u,e,i,n):null}}return e}function ts(t,e,r,i,n){var s=i||1,o=$n(t,e,r,s,n)||!n&&$n(t,e,r,s,!0)||$n(t,e,r,-s,n)||!n&&$n(t,e,r,-s,!0);return o||(t.cantEdit=!0,gt(t.first,0))}function es(t,e,r,i){return r<0&&0==e.ch?e.line>t.first?kt(t,gt(e.line-1)):null:r>0&&e.ch==(i||at(t,e.line)).text.length?e.line<t.first+t.size-1?gt(e.line+1,0):null:new gt(e.line,e.ch+r)}function rs(t){t.setSelection(gt(t.firstLine(),0),gt(t.lastLine()),z)}function is(t,e,r){var i={canceled:!1,from:e.from,to:e.to,text:e.text,origin:e.origin,cancel:function(){return i.canceled=!0}};return r&&(i.update=function(e,r,n,s){e&&(i.from=kt(t,e)),r&&(i.to=kt(t,r)),n&&(i.text=n),void 0!==s&&(i.origin=s)}),ie(t,"beforeChange",t,i),t.cm&&ie(t.cm,"beforeChange",t.cm,i),i.canceled?null:{from:i.from,to:i.to,text:i.text,origin:i.origin}}function ns(t,e,r){if(t.cm){if(!t.cm.curOp)return Ki(t.cm,ns)(t,e,r);if(t.cm.state.suppressEdits)return}if(!(oe(t,"beforeChange")||t.cm&&oe(t.cm,"beforeChange"))||(e=is(t,e,!0))){var i=Et&&!r&&function(t,e,r){var i=null;if(t.iter(e.line,r.line+1,function(t){if(t.markedSpans)for(var e=0;e<t.markedSpans.length;++e){var r=t.markedSpans[e].marker;!r.readOnly||i&&-1!=W(i,r)||(i||(i=[])).push(r)}}),!i)return null;for(var n=[{from:e,to:r}],s=0;s<i.length;++s)for(var o=i[s],a=o.find(0),l=0;l<n.length;++l){var c=n[l];if(!(mt(c.to,a.from)<0||mt(c.from,a.to)>0)){var h=[l,1],u=mt(c.from,a.from),f=mt(c.to,a.to);(u<0||!o.inclusiveLeft&&!u)&&h.push({from:c.from,to:a.from}),(f>0||!o.inclusiveRight&&!f)&&h.push({from:a.to,to:c.to}),n.splice.apply(n,h),l+=h.length-3}}return n}(t,e.from,e.to);if(i)for(var n=i.length-1;n>=0;--n)ss(t,{from:i[n].from,to:i[n].to,text:n?[""]:e.text,origin:e.origin});else ss(t,e)}}function ss(t,e){if(1!=e.text.length||""!=e.text[0]||0!=mt(e.from,e.to)){var r=Sn(t,e);Pn(t,e,r,t.cm?t.cm.curOp.id:NaN),ls(t,e,r,Lt(t,e));var i=[];Ln(t,function(t,r){r||-1!=W(i,t.history)||(fs(t.history,e),i.push(t.history)),ls(t,e,null,Lt(t,e))})}}function os(t,e,r){var i=t.cm&&t.cm.state.suppressEdits;if(!i||r){for(var n,s=t.history,o=t.sel,a="undo"==e?s.done:s.undone,l="undo"==e?s.undone:s.done,c=0;c<a.length&&(n=a[c],r?!n.ranges||n.equals(t.sel):n.ranges);c++);if(c!=a.length){for(s.lastOrigin=s.lastSelOrigin=null;;){if(!(n=a.pop()).ranges){if(i)return void a.push(n);break}if(Bn(n,l),r&&!n.equals(t.sel))return void qn(t,n,{clearRedo:!1});o=n}var h=[];Bn(o,l),l.push({changes:h,generation:s.generation}),s.generation=n.generation||++s.maxGeneration;for(var u=oe(t,"beforeChange")||t.cm&&oe(t.cm,"beforeChange"),f=function(r){var i=n.changes[r];if(i.origin=e,u&&!is(t,i,!1))return a.length=0,{};h.push(Rn(t,i));var s=r?Sn(t,i):Y(a);ls(t,i,s,Wn(t,i)),!r&&t.cm&&t.cm.scrollIntoView({from:i.from,to:wn(i)});var o=[];Ln(t,function(t,e){e||-1!=W(o,t.history)||(fs(t.history,i),o.push(t.history)),ls(t,i,null,Wn(t,i))})},d=n.changes.length-1;d>=0;--d){var p=f(d);if(p)return p.v}}}}function as(t,e){if(0!=e&&(t.first+=e,t.sel=new vn(J(t.sel.ranges,function(t){return new yn(gt(t.anchor.line+e,t.anchor.ch),gt(t.head.line+e,t.head.ch))}),t.sel.primIndex),t.cm)){Ji(t.cm,t.first,t.first-e,e);for(var r=t.cm.display,i=r.viewFrom;i<r.viewTo;i++)Zi(t.cm,i,"gutter")}}function ls(t,e,r,i){if(t.cm&&!t.cm.curOp)return Ki(t.cm,ls)(t,e,r,i);if(e.to.line<t.first)as(t,e.text.length-1-(e.to.line-e.from.line));else if(!(e.from.line>t.lastLine())){if(e.from.line<t.first){var n=e.text.length-1-(t.first-e.from.line);as(t,n),e={from:gt(t.first,0),to:gt(e.to.line+n,e.to.ch),text:[Y(e.text)],origin:e.origin}}var s=t.lastLine();e.to.line>s&&(e={from:e.from,to:gt(s,at(t,s).text.length),text:[e.text[0]],origin:e.origin}),e.removed=lt(t,e.from,e.to),r||(r=Sn(t,e)),t.cm?function(t,e,r){var i=t.doc,n=t.display,s=e.from,o=e.to,a=!1,l=s.line;t.options.lineWrapping||(l=ut(Ht(at(i,s.line))),i.iter(l,o.line+1,function(t){if(t==n.maxLine)return a=!0,!0})),i.sel.contains(e.from,e.to)>-1&&se(t),On(i,e,r,ii(t)),t.options.lineWrapping||(i.iter(l,s.line+e.text.length,function(t){var e=Kt(t);e>n.maxLineLength&&(n.maxLine=t,n.maxLineLength=e,n.maxLineChanged=!0,a=!1)}),a&&(t.curOp.updateMaxLine=!0)),function(t,e){if(t.modeFrontier=Math.min(t.modeFrontier,e),!(t.highlightFrontier<e-10)){for(var r=t.first,i=e-1;i>r;i--){var n=at(t,i).stateAfter;if(n&&(!(n instanceof Re)||i+n.lookAhead<e)){r=i+1;break}}t.highlightFrontier=Math.min(t.highlightFrontier,r)}}(i,s.line),en(t,400);var c=e.text.length-(o.line-s.line)-1;e.full?Ji(t):s.line!=o.line||1!=e.text.length||In(t.doc,e)?Ji(t,s.line,o.line+1,c):Zi(t,s.line,"text");var h=oe(t,"changes"),u=oe(t,"change");if(u||h){var f={from:s,to:o,text:e.text,removed:e.removed,origin:e.origin};u&&or(t,"change",t,f),h&&(t.curOp.changeObjs||(t.curOp.changeObjs=[])).push(f)}t.display.selForContextMenu=null}(t.cm,e,i):On(t,e,i),Yn(t,r,z)}}function cs(t,e,r,i,n){var s;i||(i=r),mt(i,r)<0&&(r=(s=[i,r])[0],i=s[1]),"string"==typeof e&&(e=t.splitLines(e)),ns(t,{from:r,to:i,text:e,origin:n})}function hs(t,e,r,i){r<t.line?t.line+=i:e<t.line&&(t.line=e,t.ch=0)}function us(t,e,r,i){for(var n=0;n<t.length;++n){var s=t[n],o=!0;if(s.ranges){s.copied||((s=t[n]=s.deepCopy()).copied=!0);for(var a=0;a<s.ranges.length;a++)hs(s.ranges[a].anchor,e,r,i),hs(s.ranges[a].head,e,r,i)}else{for(var l=0;l<s.changes.length;++l){var c=s.changes[l];if(r<c.from.line)c.from=gt(c.from.line+i,c.from.ch),c.to=gt(c.to.line+i,c.to.ch);else if(e<=c.to.line){o=!1;break}}o||(t.splice(0,n+1),n=0)}}}function fs(t,e){var r=e.from.line,i=e.to.line,n=e.text.length-(i-r)-1;us(t.done,r,i,n),us(t.undone,r,i,n)}function ds(t,e,r,i){var n=e,s=e;return"number"==typeof e?s=at(t,wt(t,e)):n=ut(e),null==n?null:(i(s,n)&&t.cm&&Zi(t.cm,n,r),s)}function ps(t){this.lines=t,this.parent=null;for(var e=0,r=0;r<t.length;++r)t[r].parent=this,e+=t[r].height;this.height=e}function gs(t){this.children=t;for(var e=0,r=0,i=0;i<t.length;++i){var n=t[i];e+=n.chunkSize(),r+=n.height,n.parent=this}this.size=e,this.height=r,this.parent=null}yn.prototype.from=function(){return xt(this.anchor,this.head)},yn.prototype.to=function(){return bt(this.anchor,this.head)},yn.prototype.empty=function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch},ps.prototype={chunkSize:function(){return this.lines.length},removeInner:function(t,e){for(var r=t,i=t+e;r<i;++r){var n=this.lines[r];this.height-=n.height,je(n),or(n,"delete")}this.lines.splice(t,e)},collapse:function(t){t.push.apply(t,this.lines)},insertInner:function(t,e,r){this.height+=r,this.lines=this.lines.slice(0,t).concat(e).concat(this.lines.slice(t));for(var i=0;i<e.length;++i)e[i].parent=this},iterN:function(t,e,r){for(var i=t+e;t<i;++t)if(r(this.lines[t]))return!0}},gs.prototype={chunkSize:function(){return this.size},removeInner:function(t,e){this.size-=e;for(var r=0;r<this.children.length;++r){var i=this.children[r],n=i.chunkSize();if(t<n){var s=Math.min(e,n-t),o=i.height;if(i.removeInner(t,s),this.height-=o-i.height,n==s&&(this.children.splice(r--,1),i.parent=null),0==(e-=s))break;t=0}else t-=n}if(this.size-e<25&&(this.children.length>1||!(this.children[0]instanceof ps))){var a=[];this.collapse(a),this.children=[new ps(a)],this.children[0].parent=this}},collapse:function(t){for(var e=0;e<this.children.length;++e)this.children[e].collapse(t)},insertInner:function(t,e,r){this.size+=e.length,this.height+=r;for(var i=0;i<this.children.length;++i){var n=this.children[i],s=n.chunkSize();if(t<=s){if(n.insertInner(t,e,r),n.lines&&n.lines.length>50){for(var o=n.lines.length%25+25,a=o;a<n.lines.length;){var l=new ps(n.lines.slice(a,a+=25));n.height-=l.height,this.children.splice(++i,0,l),l.parent=this}n.lines=n.lines.slice(0,o),this.maybeSpill()}break}t-=s}},maybeSpill:function(){if(!(this.children.length<=10)){var t=this;do{var e=t.children.splice(t.children.length-5,5),r=new gs(e);if(t.parent){t.size-=r.size,t.height-=r.height;var i=W(t.parent.children,t);t.parent.children.splice(i+1,0,r)}else{var n=new gs(t.children);n.parent=t,t.children=[n,r],t=n}r.parent=t.parent}while(t.children.length>10);t.parent.maybeSpill()}},iterN:function(t,e,r){for(var i=0;i<this.children.length;++i){var n=this.children[i],s=n.chunkSize();if(t<s){var o=Math.min(e,s-t);if(n.iterN(t,o,r))return!0;if(0==(e-=o))break;t=0}else t-=s}}};var ms=function(t,e,r){if(r)for(var i in r)r.hasOwnProperty(i)&&(this[i]=r[i]);this.doc=t,this.node=e};function vs(t,e,r){jt(e)<(t.curOp&&t.curOp.scrollTop||t.doc.scrollTop)&&Si(t,r)}ms.prototype.clear=function(){var t=this.doc.cm,e=this.line.widgets,r=this.line,i=ut(r);if(null!=i&&e){for(var n=0;n<e.length;++n)e[n]==this&&e.splice(n--,1);e.length||(r.widgets=null);var s=br(this);ht(r,Math.max(0,r.height-s)),t&&(ji(t,function(){vs(t,r,-s),Zi(t,i,"widget")}),or(t,"lineWidgetCleared",t,this,i))}},ms.prototype.changed=function(){var t=this,e=this.height,r=this.doc.cm,i=this.line;this.height=null;var n=br(this)-e;n&&(_t(this.doc,i)||ht(i,i.height+n),r&&ji(r,function(){r.curOp.forceUpdate=!0,vs(r,i,n),or(r,"lineWidgetChanged",r,t,ut(i))}))},ae(ms);var ys=0,bs=function(t,e){this.lines=[],this.type=e,this.doc=t,this.id=++ys};function xs(t,e,r,i,n){if(i&&i.shared)return function(t,e,r,i,n){(i=B(i)).shared=!1;var s=[xs(t,e,r,i,n)],o=s[0],a=i.widgetNode;return Ln(t,function(t){a&&(i.widgetNode=a.cloneNode(!0)),s.push(xs(t,kt(t,e),kt(t,r),i,n));for(var l=0;l<t.linked.length;++l)if(t.linked[l].isParent)return;o=Y(s)}),new ws(s,o)}(t,e,r,i,n);if(t.cm&&!t.cm.curOp)return Ki(t.cm,xs)(t,e,r,i,n);var s=new bs(t,n),o=mt(e,r);if(i&&B(i,s,!1),o>0||0==o&&!1!==s.clearWhenEmpty)return s;if(s.replacedWith&&(s.collapsed=!0,s.widgetNode=N("span",[s.replacedWith],"CodeMirror-widget"),i.handleMouseEvents||s.widgetNode.setAttribute("cm-ignore-events","true"),i.insertLeft&&(s.widgetNode.insertLeft=!0)),s.collapsed){if(Wt(t,e.line,e,r,s)||e.line!=r.line&&Wt(t,r.line,e,r,s))throw new Error("Inserting collapsed marker partially overlapping an existing one");Tt=!0}s.addToHistory&&Pn(t,{from:e,to:r,origin:"markText"},t.sel,NaN);var a,l=e.line,c=t.cm;if(t.iter(l,r.line+1,function(t){c&&s.collapsed&&!c.options.lineWrapping&&Ht(t)==c.display.maxLine&&(a=!0),s.collapsed&&l!=e.line&&ht(t,0),function(t,e){t.markedSpans=t.markedSpans?t.markedSpans.concat([e]):[e],e.marker.attachLine(t)}(t,new Ct(s,l==e.line?e.ch:null,l==r.line?r.ch:null)),++l}),s.collapsed&&t.iter(e.line,r.line+1,function(e){_t(t,e)&&ht(e,0)}),s.clearOnEnter&&te(s,"beforeCursorEnter",function(){return s.clear()}),s.readOnly&&(Et=!0,(t.history.done.length||t.history.undone.length)&&t.clearHistory()),s.collapsed&&(s.id=++ys,s.atomic=!0),c){if(a&&(c.curOp.updateMaxLine=!0),s.collapsed)Ji(c,e.line,r.line+1);else if(s.className||s.title||s.startStyle||s.endStyle||s.css)for(var h=e.line;h<=r.line;h++)Zi(c,h,"text");s.atomic&&Zn(c.doc),or(c,"markerAdded",c,s)}return s}bs.prototype.clear=function(){if(!this.explicitlyCleared){var t=this.doc.cm,e=t&&!t.curOp;if(e&&Ui(t),oe(this,"clear")){var r=this.find();r&&or(this,"clear",r.from,r.to)}for(var i=null,n=null,s=0;s<this.lines.length;++s){var o=this.lines[s],a=It(o.markedSpans,this);t&&!this.collapsed?Zi(t,ut(o),"text"):t&&(null!=a.to&&(n=ut(o)),null!=a.from&&(i=ut(o))),o.markedSpans=Ot(o.markedSpans,a),null==a.from&&this.collapsed&&!_t(this.doc,o)&&t&&ht(o,$r(t.display))}if(t&&this.collapsed&&!t.options.lineWrapping)for(var l=0;l<this.lines.length;++l){var c=Ht(this.lines[l]),h=Kt(c);h>t.display.maxLineLength&&(t.display.maxLine=c,t.display.maxLineLength=h,t.display.maxLineChanged=!0)}null!=i&&t&&this.collapsed&&Ji(t,i,n+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,t&&Zn(t.doc)),t&&or(t,"markerCleared",t,this,i,n),e&&Wi(t),this.parent&&this.parent.clear()}},bs.prototype.find=function(t,e){var r,i;null==t&&"bookmark"==this.type&&(t=1);for(var n=0;n<this.lines.length;++n){var s=this.lines[n],o=It(s.markedSpans,this);if(null!=o.from&&(r=gt(e?s:ut(s),o.from),-1==t))return r;if(null!=o.to&&(i=gt(e?s:ut(s),o.to),1==t))return i}return r&&{from:r,to:i}},bs.prototype.changed=function(){var t=this,e=this.find(-1,!0),r=this,i=this.doc.cm;e&&i&&ji(i,function(){var n=e.line,s=ut(e.line),o=Lr(i,s);if(o&&(Vr(o),i.curOp.selectionChanged=i.curOp.forceUpdate=!0),i.curOp.updateMaxLine=!0,!_t(r.doc,n)&&null!=r.height){var a=r.height;r.height=null;var l=br(r)-a;l&&ht(n,n.height+l)}or(i,"markerChanged",i,t)})},bs.prototype.attachLine=function(t){if(!this.lines.length&&this.doc.cm){var e=this.doc.cm.curOp;e.maybeHiddenMarkers&&-1!=W(e.maybeHiddenMarkers,this)||(e.maybeUnhiddenMarkers||(e.maybeUnhiddenMarkers=[])).push(this)}this.lines.push(t)},bs.prototype.detachLine=function(t){if(this.lines.splice(W(this.lines,t),1),!this.lines.length&&this.doc.cm){var e=this.doc.cm.curOp;(e.maybeHiddenMarkers||(e.maybeHiddenMarkers=[])).push(this)}},ae(bs);var ws=function(t,e){this.markers=t,this.primary=e;for(var r=0;r<t.length;++r)t[r].parent=this};function ks(t){return t.findMarks(gt(t.first,0),t.clipPos(gt(t.lastLine())),function(t){return t.parent})}function Ss(t){for(var e=function(e){var r=t[e],i=[r.primary.doc];Ln(r.primary.doc,function(t){return i.push(t)});for(var n=0;n<r.markers.length;n++){var s=r.markers[n];-1==W(i,s.doc)&&(s.parent=null,r.markers.splice(n--,1))}},r=0;r<t.length;r++)e(r)}ws.prototype.clear=function(){if(!this.explicitlyCleared){this.explicitlyCleared=!0;for(var t=0;t<this.markers.length;++t)this.markers[t].clear();or(this,"clear")}},ws.prototype.find=function(t,e){return this.primary.find(t,e)},ae(ws);var Es=0,Ts=function(t,e,r,i,n){if(!(this instanceof Ts))return new Ts(t,e,r,i,n);null==r&&(r=0),gs.call(this,[new ps([new Xe("",null)])]),this.first=r,this.scrollTop=this.scrollLeft=0,this.cantEdit=!1,this.cleanGeneration=1,this.modeFrontier=this.highlightFrontier=r;var s=gt(r,0);this.sel=xn(s),this.history=new Dn(null),this.id=++Es,this.modeOption=e,this.lineSep=i,this.direction="rtl"==n?"rtl":"ltr",this.extend=!1,"string"==typeof t&&(t=this.splitLines(t)),On(this,{from:s,to:s,text:t}),qn(this,xn(s),z)};Ts.prototype=Q(gs.prototype,{constructor:Ts,iter:function(t,e,r){r?this.iterN(t-this.first,e-t,r):this.iterN(this.first,this.first+this.size,t)},insert:function(t,e){for(var r=0,i=0;i<e.length;++i)r+=e[i].height;this.insertInner(t-this.first,e,r)},remove:function(t,e){this.removeInner(t-this.first,e)},getValue:function(t){var e=ct(this,this.first,this.first+this.size);return!1===t?e:e.join(t||this.lineSeparator())},setValue:Yi(function(t){var e=gt(this.first,0),r=this.first+this.size-1;ns(this,{from:e,to:gt(r,at(this,r).text.length),text:this.splitLines(t),origin:"setValue",full:!0},!0),this.cm&&Ti(this.cm,0,0),qn(this,xn(e),z)}),replaceRange:function(t,e,r,i){e=kt(this,e),r=r?kt(this,r):e,cs(this,t,e,r,i)},getRange:function(t,e,r){var i=lt(this,kt(this,t),kt(this,e));return!1===r?i:i.join(r||this.lineSeparator())},getLine:function(t){var e=this.getLineHandle(t);return e&&e.text},getLineHandle:function(t){if(dt(this,t))return at(this,t)},getLineNumber:function(t){return ut(t)},getLineHandleVisualStart:function(t){return"number"==typeof t&&(t=at(this,t)),Ht(t)},lineCount:function(){return this.size},firstLine:function(){return this.first},lastLine:function(){return this.first+this.size-1},clipPos:function(t){return kt(this,t)},getCursor:function(t){var e=this.sel.primary();return null==t||"head"==t?e.head:"anchor"==t?e.anchor:"end"==t||"to"==t||!1===t?e.to():e.from()},listSelections:function(){return this.sel.ranges},somethingSelected:function(){return this.sel.somethingSelected()},setCursor:Yi(function(t,e,r){jn(this,kt(this,"number"==typeof t?gt(t,e||0):t),null,r)}),setSelection:Yi(function(t,e,r){jn(this,kt(this,t),kt(this,e||t),r)}),extendSelection:Yi(function(t,e,r){zn(this,kt(this,t),e&&kt(this,e),r)}),extendSelections:Yi(function(t,e){_n(this,St(this,t),e)}),extendSelectionsBy:Yi(function(t,e){var r=J(this.sel.ranges,t);_n(this,St(this,r),e)}),setSelections:Yi(function(t,e,r){if(t.length){for(var i=[],n=0;n<t.length;n++)i[n]=new yn(kt(this,t[n].anchor),kt(this,t[n].head));null==e&&(e=Math.min(t.length-1,this.sel.primIndex)),qn(this,bn(i,e),r)}}),addSelection:Yi(function(t,e,r){var i=this.sel.ranges.slice(0);i.push(new yn(kt(this,t),kt(this,e||t))),qn(this,bn(i,i.length-1),r)}),getSelection:function(t){for(var e,r=this.sel.ranges,i=0;i<r.length;i++){var n=lt(this,r[i].from(),r[i].to());e=e?e.concat(n):n}return!1===t?e:e.join(t||this.lineSeparator())},getSelections:function(t){for(var e=[],r=this.sel.ranges,i=0;i<r.length;i++){var n=lt(this,r[i].from(),r[i].to());!1!==t&&(n=n.join(t||this.lineSeparator())),e[i]=n}return e},replaceSelection:function(t,e,r){for(var i=[],n=0;n<this.sel.ranges.length;n++)i[n]=t;this.replaceSelections(i,e,r||"+input")},replaceSelections:Yi(function(t,e,r){for(var i=[],n=this.sel,s=0;s<n.ranges.length;s++){var o=n.ranges[s];i[s]={from:o.from(),to:o.to(),text:this.splitLines(t[s]),origin:r}}for(var a=e&&"end"!=e&&function(t,e,r){for(var i=[],n=gt(t.first,0),s=n,o=0;o<e.length;o++){var a=e[o],l=En(a.from,n,s),c=En(wn(a),n,s);if(n=a.to,s=c,"around"==r){var h=t.sel.ranges[o],u=mt(h.head,h.anchor)<0;i[o]=new yn(u?c:l,u?l:c)}else i[o]=new yn(l,l)}return new vn(i,t.sel.primIndex)}(this,i,e),l=i.length-1;l>=0;l--)ns(this,i[l]);a?Kn(this,a):this.cm&&Ei(this.cm)}),undo:Yi(function(){os(this,"undo")}),redo:Yi(function(){os(this,"redo")}),undoSelection:Yi(function(){os(this,"undo",!0)}),redoSelection:Yi(function(){os(this,"redo",!0)}),setExtending:function(t){this.extend=t},getExtending:function(){return this.extend},historySize:function(){for(var t=this.history,e=0,r=0,i=0;i<t.done.length;i++)t.done[i].ranges||++e;for(var n=0;n<t.undone.length;n++)t.undone[n].ranges||++r;return{undo:e,redo:r}},clearHistory:function(){this.history=new Dn(this.history.maxGeneration)},markClean:function(){this.cleanGeneration=this.changeGeneration(!0)},changeGeneration:function(t){return t&&(this.history.lastOp=this.history.lastSelOp=this.history.lastOrigin=null),this.history.generation},isClean:function(t){return this.history.generation==(t||this.cleanGeneration)},getHistory:function(){return{done:Hn(this.history.done),undone:Hn(this.history.undone)}},setHistory:function(t){var e=this.history=new Dn(this.history.maxGeneration);e.done=Hn(t.done.slice(0),null,!0),e.undone=Hn(t.undone.slice(0),null,!0)},setGutterMarker:Yi(function(t,e,r){return ds(this,t,"gutter",function(t){var i=t.gutterMarkers||(t.gutterMarkers={});return i[e]=r,!r&&rt(i)&&(t.gutterMarkers=null),!0})}),clearGutter:Yi(function(t){var e=this;this.iter(function(r){r.gutterMarkers&&r.gutterMarkers[t]&&ds(e,r,"gutter",function(){return r.gutterMarkers[t]=null,rt(r.gutterMarkers)&&(r.gutterMarkers=null),!0})})}),lineInfo:function(t){var e;if("number"==typeof t){if(!dt(this,t))return null;if(e=t,!(t=at(this,t)))return null}else if(null==(e=ut(t)))return null;return{line:e,handle:t,text:t.text,gutterMarkers:t.gutterMarkers,textClass:t.textClass,bgClass:t.bgClass,wrapClass:t.wrapClass,widgets:t.widgets}},addLineClass:Yi(function(t,e,r){return ds(this,t,"gutter"==e?"gutter":"class",function(t){var i="text"==e?"textClass":"background"==e?"bgClass":"gutter"==e?"gutterClass":"wrapClass";if(t[i]){if(E(r).test(t[i]))return!1;t[i]+=" "+r}else t[i]=r;return!0})}),removeLineClass:Yi(function(t,e,r){return ds(this,t,"gutter"==e?"gutter":"class",function(t){var i="text"==e?"textClass":"background"==e?"bgClass":"gutter"==e?"gutterClass":"wrapClass",n=t[i];if(!n)return!1;if(null==r)t[i]=null;else{var s=n.match(E(r));if(!s)return!1;var o=s.index+s[0].length;t[i]=n.slice(0,s.index)+(s.index&&o!=n.length?" ":"")+n.slice(o)||null}return!0})}),addLineWidget:Yi(function(t,e,r){return function(t,e,r,i){var n=new ms(t,r,i),s=t.cm;return s&&n.noHScroll&&(s.display.alignWidgets=!0),ds(t,e,"widget",function(e){var r=e.widgets||(e.widgets=[]);if(null==n.insertAt?r.push(n):r.splice(Math.min(r.length-1,Math.max(0,n.insertAt)),0,n),n.line=e,s&&!_t(t,e)){var i=jt(e)<t.scrollTop;ht(e,e.height+br(n)),i&&Si(s,n.height),s.curOp.forceUpdate=!0}return!0}),s&&or(s,"lineWidgetAdded",s,n,"number"==typeof e?e:ut(e)),n}(this,t,e,r)}),removeLineWidget:function(t){t.clear()},markText:function(t,e,r){return xs(this,kt(this,t),kt(this,e),r,r&&r.type||"range")},setBookmark:function(t,e){var r={replacedWith:e&&(null==e.nodeType?e.widget:e),insertLeft:e&&e.insertLeft,clearWhenEmpty:!1,shared:e&&e.shared,handleMouseEvents:e&&e.handleMouseEvents};return xs(this,t=kt(this,t),t,r,"bookmark")},findMarksAt:function(t){var e=[],r=at(this,(t=kt(this,t)).line).markedSpans;if(r)for(var i=0;i<r.length;++i){var n=r[i];(null==n.from||n.from<=t.ch)&&(null==n.to||n.to>=t.ch)&&e.push(n.marker.parent||n.marker)}return e},findMarks:function(t,e,r){t=kt(this,t),e=kt(this,e);var i=[],n=t.line;return this.iter(t.line,e.line+1,function(s){var o=s.markedSpans;if(o)for(var a=0;a<o.length;a++){var l=o[a];null!=l.to&&n==t.line&&t.ch>=l.to||null==l.from&&n!=t.line||null!=l.from&&n==e.line&&l.from>=e.ch||r&&!r(l.marker)||i.push(l.marker.parent||l.marker)}++n}),i},getAllMarks:function(){var t=[];return this.iter(function(e){var r=e.markedSpans;if(r)for(var i=0;i<r.length;++i)null!=r[i].from&&t.push(r[i].marker)}),t},posFromIndex:function(t){var e,r=this.first,i=this.lineSeparator().length;return this.iter(function(n){var s=n.text.length+i;if(s>t)return e=t,!0;t-=s,++r}),kt(this,gt(r,e))},indexFromPos:function(t){var e=(t=kt(this,t)).ch;if(t.line<this.first||t.ch<0)return 0;var r=this.lineSeparator().length;return this.iter(this.first,t.line,function(t){e+=t.text.length+r}),e},copy:function(t){var e=new Ts(ct(this,this.first,this.first+this.size),this.modeOption,this.first,this.lineSep,this.direction);return e.scrollTop=this.scrollTop,e.scrollLeft=this.scrollLeft,e.sel=this.sel,e.extend=!1,t&&(e.history.undoDepth=this.history.undoDepth,e.setHistory(this.getHistory())),e},linkedDoc:function(t){t||(t={});var e=this.first,r=this.first+this.size;null!=t.from&&t.from>e&&(e=t.from),null!=t.to&&t.to<r&&(r=t.to);var i=new Ts(ct(this,e,r),t.mode||this.modeOption,e,this.lineSep,this.direction);return t.sharedHist&&(i.history=this.history),(this.linked||(this.linked=[])).push({doc:i,sharedHist:t.sharedHist}),i.linked=[{doc:this,isParent:!0,sharedHist:t.sharedHist}],function(t,e){for(var r=0;r<e.length;r++){var i=e[r],n=i.find(),s=t.clipPos(n.from),o=t.clipPos(n.to);if(mt(s,o)){var a=xs(t,s,o,i.primary,i.primary.type);i.markers.push(a),a.parent=i}}}(i,ks(this)),i},unlinkDoc:function(t){if(t instanceof So&&(t=t.doc),this.linked)for(var e=0;e<this.linked.length;++e){var r=this.linked[e];if(r.doc==t){this.linked.splice(e,1),t.unlinkDoc(this),Ss(ks(this));break}}if(t.history==this.history){var i=[t.id];Ln(t,function(t){return i.push(t.id)},!0),t.history=new Dn(null),t.history.done=Hn(this.history.done,i),t.history.undone=Hn(this.history.undone,i)}},iterLinkedDocs:function(t){Ln(this,t)},getMode:function(){return this.mode},getEditor:function(){return this.cm},splitLines:function(t){return this.lineSep?t.split(this.lineSep):be(t)},lineSeparator:function(){return this.lineSep||"\n"},setDirection:Yi(function(t){"rtl"!=t&&(t="ltr"),t!=this.direction&&(this.direction=t,this.iter(function(t){return t.order=null}),this.cm&&function(t){ji(t,function(){An(t),Ji(t)})}(this.cm))})}),Ts.prototype.eachLine=Ts.prototype.iter;var Cs=0;function Is(t){var e=this;if(Os(e),!ne(e,t)&&!xr(e.display,t)){le(t),o&&(Cs=+new Date);var r=si(e,t,!0),i=t.dataTransfer.files;if(r&&!e.isReadOnly())if(i&&i.length&&window.FileReader&&window.File)for(var n=i.length,s=Array(n),a=0,l=function(t,i){if(!e.options.allowDropFileTypes||-1!=W(e.options.allowDropFileTypes,t.type)){var o=new FileReader;o.onload=Ki(e,function(){var t=o.result;if(/[\x00-\x08\x0e-\x1f]{2}/.test(t)&&(t=""),s[i]=t,++a==n){var l={from:r=kt(e.doc,r),to:r,text:e.doc.splitLines(s.join(e.doc.lineSeparator())),origin:"paste"};ns(e.doc,l),Kn(e.doc,xn(r,wn(l)))}}),o.readAsText(t)}},c=0;c<n;++c)l(i[c],c);else{if(e.state.draggingText&&e.doc.sel.contains(r)>-1)return e.state.draggingText(t),void setTimeout(function(){return e.display.input.focus()},20);try{var h=t.dataTransfer.getData("Text");if(h){var u;if(e.state.draggingText&&!e.state.draggingText.copy&&(u=e.listSelections()),Yn(e.doc,xn(r,r)),u)for(var f=0;f<u.length;++f)cs(e.doc,"",u[f].anchor,u[f].head,"drag");e.replaceSelection(h,"around","paste"),e.display.input.focus()}}catch(t){}}}}function Os(t){t.display.dragCursor&&(t.display.lineSpace.removeChild(t.display.dragCursor),t.display.dragCursor=null)}function Ls(t){if(document.getElementsByClassName)for(var e=document.getElementsByClassName("CodeMirror"),r=0;r<e.length;r++){var i=e[r].CodeMirror;i&&t(i)}}var Ns=!1;function As(){Ns||(function(){var t;te(window,"resize",function(){null==t&&(t=setTimeout(function(){t=null,Ls(Ds)},100))}),te(window,"blur",function(){return Ls(mi)})}(),Ns=!0)}function Ds(t){var e=t.display;e.cachedCharWidth=e.cachedTextHeight=e.cachedPaddingH=null,e.scrollbarsClipped=!1,t.setSize()}for(var Rs={3:"Pause",8:"Backspace",9:"Tab",13:"Enter",16:"Shift",17:"Ctrl",18:"Alt",19:"Pause",20:"CapsLock",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"PrintScrn",45:"Insert",46:"Delete",59:";",61:"=",91:"Mod",92:"Mod",93:"Mod",106:"*",107:"=",109:"-",110:".",111:"/",127:"Delete",145:"ScrollLock",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",63232:"Up",63233:"Down",63234:"Left",63235:"Right",63272:"Delete",63273:"Home",63275:"End",63276:"PageUp",63277:"PageDown",63302:"Insert"},Ms=0;Ms<10;Ms++)Rs[Ms+48]=Rs[Ms+96]=String(Ms);for(var Ps=65;Ps<=90;Ps++)Rs[Ps]=String.fromCharCode(Ps);for(var Vs=1;Vs<=12;Vs++)Rs[Vs+111]=Rs[Vs+63235]="F"+Vs;var Bs={};function Fs(t){var e,r,i,n,s=t.split(/-(?!$)/);t=s[s.length-1];for(var o=0;o<s.length-1;o++){var a=s[o];if(/^(cmd|meta|m)$/i.test(a))n=!0;else if(/^a(lt)?$/i.test(a))e=!0;else if(/^(c|ctrl|control)$/i.test(a))r=!0;else{if(!/^s(hift)?$/i.test(a))throw new Error("Unrecognized modifier name: "+a);i=!0}}return e&&(t="Alt-"+t),r&&(t="Ctrl-"+t),n&&(t="Cmd-"+t),i&&(t="Shift-"+t),t}function Us(t){var e={};for(var r in t)if(t.hasOwnProperty(r)){var i=t[r];if(/^(name|fallthrough|(de|at)tach)$/.test(r))continue;if("..."==i){delete t[r];continue}for(var n=J(r.split(" "),Fs),s=0;s<n.length;s++){var o=void 0,a=void 0;s==n.length-1?(a=n.join(" "),o=i):(a=n.slice(0,s+1).join(" "),o="...");var l=e[a];if(l){if(l!=o)throw new Error("Inconsistent bindings for "+a)}else e[a]=o}delete t[r]}for(var c in e)t[c]=e[c];return t}function Ws(t,e,r,i){var n=(e=_s(e)).call?e.call(t,i):e[t];if(!1===n)return"nothing";if("..."===n)return"multi";if(null!=n&&r(n))return"handled";if(e.fallthrough){if("[object Array]"!=Object.prototype.toString.call(e.fallthrough))return Ws(t,e.fallthrough,r,i);for(var s=0;s<e.fallthrough.length;s++){var o=Ws(t,e.fallthrough[s],r,i);if(o)return o}}}function Hs(t){var e="string"==typeof t?t:Rs[t.keyCode];return"Ctrl"==e||"Alt"==e||"Shift"==e||"Mod"==e}function Gs(t,e,r){var i=t;return e.altKey&&"Alt"!=i&&(t="Alt-"+t),(k?e.metaKey:e.ctrlKey)&&"Ctrl"!=i&&(t="Ctrl-"+t),(k?e.ctrlKey:e.metaKey)&&"Cmd"!=i&&(t="Cmd-"+t),!r&&e.shiftKey&&"Shift"!=i&&(t="Shift-"+t),t}function zs(t,e){if(u&&34==t.keyCode&&t.char)return!1;var r=Rs[t.keyCode];return null!=r&&!t.altGraphKey&&(3==t.keyCode&&t.code&&(r=t.code),Gs(r,t,e))}function _s(t){return"string"==typeof t?Bs[t]:t}function Xs(t,e){for(var r=t.doc.sel.ranges,i=[],n=0;n<r.length;n++){for(var s=e(r[n]);i.length&&mt(s.from,Y(i).to)<=0;){var o=i.pop();if(mt(o.from,s.from)<0){s.from=o.from;break}}i.push(s)}ji(t,function(){for(var e=i.length-1;e>=0;e--)cs(t.doc,"",i[e].from,i[e].to,"+delete");Ei(t)})}function js(t,e,r){var i=st(t.text,e+r,r);return i<0||i>t.text.length?null:i}function Ks(t,e,r){var i=js(t,e.ch,r);return null==i?null:new gt(e.line,i,r<0?"after":"before")}function qs(t,e,r,i,n){if(t){var s=Qt(r,e.doc.direction);if(s){var o,a=n<0?Y(s):s[0],l=n<0==(1==a.level),c=l?"after":"before";if(a.level>0||"rtl"==e.doc.direction){var h=Nr(e,r);o=n<0?r.text.length-1:0;var u=Ar(e,h,o).top;o=ot(function(t){return Ar(e,h,t).top==u},n<0==(1==a.level)?a.from:a.to-1,o),"before"==c&&(o=js(r,o,1))}else o=n<0?a.to:a.from;return new gt(i,o,c)}}return new gt(i,n<0?r.text.length:0,n<0?"before":"after")}Bs.basic={Left:"goCharLeft",Right:"goCharRight",Up:"goLineUp",Down:"goLineDown",End:"goLineEnd",Home:"goLineStartSmart",PageUp:"goPageUp",PageDown:"goPageDown",Delete:"delCharAfter",Backspace:"delCharBefore","Shift-Backspace":"delCharBefore",Tab:"defaultTab","Shift-Tab":"indentAuto",Enter:"newlineAndIndent",Insert:"toggleOverwrite",Esc:"singleSelection"},Bs.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Up":"goLineUp","Ctrl-Down":"goLineDown","Ctrl-Left":"goGroupLeft","Ctrl-Right":"goGroupRight","Alt-Left":"goLineStart","Alt-Right":"goLineEnd","Ctrl-Backspace":"delGroupBefore","Ctrl-Delete":"delGroupAfter","Ctrl-S":"save","Ctrl-F":"find","Ctrl-G":"findNext","Shift-Ctrl-G":"findPrev","Shift-Ctrl-F":"replace","Shift-Ctrl-R":"replaceAll","Ctrl-[":"indentLess","Ctrl-]":"indentMore","Ctrl-U":"undoSelection","Shift-Ctrl-U":"redoSelection","Alt-U":"redoSelection",fallthrough:"basic"},Bs.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Alt-F":"goWordRight","Alt-B":"goWordLeft","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-D":"delWordAfter","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars","Ctrl-O":"openLine"},Bs.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Home":"goDocStart","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goGroupLeft","Alt-Right":"goGroupRight","Cmd-Left":"goLineLeft","Cmd-Right":"goLineRight","Alt-Backspace":"delGroupBefore","Ctrl-Alt-Backspace":"delGroupAfter","Alt-Delete":"delGroupAfter","Cmd-S":"save","Cmd-F":"find","Cmd-G":"findNext","Shift-Cmd-G":"findPrev","Cmd-Alt-F":"replace","Shift-Cmd-Alt-F":"replaceAll","Cmd-[":"indentLess","Cmd-]":"indentMore","Cmd-Backspace":"delWrappedLineLeft","Cmd-Delete":"delWrappedLineRight","Cmd-U":"undoSelection","Shift-Cmd-U":"redoSelection","Ctrl-Up":"goDocStart","Ctrl-Down":"goDocEnd",fallthrough:["basic","emacsy"]},Bs.default=y?Bs.macDefault:Bs.pcDefault;var Ys={selectAll:rs,singleSelection:function(t){return t.setSelection(t.getCursor("anchor"),t.getCursor("head"),z)},killLine:function(t){return Xs(t,function(e){if(e.empty()){var r=at(t.doc,e.head.line).text.length;return e.head.ch==r&&e.head.line<t.lastLine()?{from:e.head,to:gt(e.head.line+1,0)}:{from:e.head,to:gt(e.head.line,r)}}return{from:e.from(),to:e.to()}})},deleteLine:function(t){return Xs(t,function(e){return{from:gt(e.from().line,0),to:kt(t.doc,gt(e.to().line+1,0))}})},delLineLeft:function(t){return Xs(t,function(t){return{from:gt(t.from().line,0),to:t.from()}})},delWrappedLineLeft:function(t){return Xs(t,function(e){var r=t.charCoords(e.head,"div").top+5,i=t.coordsChar({left:0,top:r},"div");return{from:i,to:e.from()}})},delWrappedLineRight:function(t){return Xs(t,function(e){var r=t.charCoords(e.head,"div").top+5,i=t.coordsChar({left:t.display.lineDiv.offsetWidth+100,top:r},"div");return{from:e.from(),to:i}})},undo:function(t){return t.undo()},redo:function(t){return t.redo()},undoSelection:function(t){return t.undoSelection()},redoSelection:function(t){return t.redoSelection()},goDocStart:function(t){return t.extendSelection(gt(t.firstLine(),0))},goDocEnd:function(t){return t.extendSelection(gt(t.lastLine()))},goLineStart:function(t){return t.extendSelectionsBy(function(e){return Js(t,e.head.line)},{origin:"+move",bias:1})},goLineStartSmart:function(t){return t.extendSelectionsBy(function(e){return Zs(t,e.head)},{origin:"+move",bias:1})},goLineEnd:function(t){return t.extendSelectionsBy(function(e){return function(t,e){var r=at(t.doc,e),i=function(t){for(var e;e=Ft(t);)t=e.find(1,!0).line;return t}(r);return i!=r&&(e=ut(i)),qs(!0,t,r,e,-1)}(t,e.head.line)},{origin:"+move",bias:-1})},goLineRight:function(t){return t.extendSelectionsBy(function(e){var r=t.cursorCoords(e.head,"div").top+5;return t.coordsChar({left:t.display.lineDiv.offsetWidth+100,top:r},"div")},X)},goLineLeft:function(t){return t.extendSelectionsBy(function(e){var r=t.cursorCoords(e.head,"div").top+5;return t.coordsChar({left:0,top:r},"div")},X)},goLineLeftSmart:function(t){return t.extendSelectionsBy(function(e){var r=t.cursorCoords(e.head,"div").top+5,i=t.coordsChar({left:0,top:r},"div");return i.ch<t.getLine(i.line).search(/\S/)?Zs(t,e.head):i},X)},goLineUp:function(t){return t.moveV(-1,"line")},goLineDown:function(t){return t.moveV(1,"line")},goPageUp:function(t){return t.moveV(-1,"page")},goPageDown:function(t){return t.moveV(1,"page")},goCharLeft:function(t){return t.moveH(-1,"char")},goCharRight:function(t){return t.moveH(1,"char")},goColumnLeft:function(t){return t.moveH(-1,"column")},goColumnRight:function(t){return t.moveH(1,"column")},goWordLeft:function(t){return t.moveH(-1,"word")},goGroupRight:function(t){return t.moveH(1,"group")},goGroupLeft:function(t){return t.moveH(-1,"group")},goWordRight:function(t){return t.moveH(1,"word")},delCharBefore:function(t){return t.deleteH(-1,"char")},delCharAfter:function(t){return t.deleteH(1,"char")},delWordBefore:function(t){return t.deleteH(-1,"word")},delWordAfter:function(t){return t.deleteH(1,"word")},delGroupBefore:function(t){return t.deleteH(-1,"group")},delGroupAfter:function(t){return t.deleteH(1,"group")},indentAuto:function(t){return t.indentSelection("smart")},indentMore:function(t){return t.indentSelection("add")},indentLess:function(t){return t.indentSelection("subtract")},insertTab:function(t){return t.replaceSelection("\t")},insertSoftTab:function(t){for(var e=[],r=t.listSelections(),i=t.options.tabSize,n=0;n<r.length;n++){var s=r[n].from(),o=F(t.getLine(s.line),s.ch,i);e.push(q(i-o%i))}t.replaceSelections(e)},defaultTab:function(t){t.somethingSelected()?t.indentSelection("add"):t.execCommand("insertTab")},transposeChars:function(t){return ji(t,function(){for(var e=t.listSelections(),r=[],i=0;i<e.length;i++)if(e[i].empty()){var n=e[i].head,s=at(t.doc,n.line).text;if(s)if(n.ch==s.length&&(n=new gt(n.line,n.ch-1)),n.ch>0)n=new gt(n.line,n.ch+1),t.replaceRange(s.charAt(n.ch-1)+s.charAt(n.ch-2),gt(n.line,n.ch-2),n,"+transpose");else if(n.line>t.doc.first){var o=at(t.doc,n.line-1).text;o&&(n=new gt(n.line,1),t.replaceRange(s.charAt(0)+t.doc.lineSeparator()+o.charAt(o.length-1),gt(n.line-1,o.length-1),n,"+transpose"))}r.push(new yn(n,n))}t.setSelections(r)})},newlineAndIndent:function(t){return ji(t,function(){for(var e=t.listSelections(),r=e.length-1;r>=0;r--)t.replaceRange(t.doc.lineSeparator(),e[r].anchor,e[r].head,"+input");e=t.listSelections();for(var i=0;i<e.length;i++)t.indentLine(e[i].from().line,null,!0);Ei(t)})},openLine:function(t){return t.replaceSelection("\n","start")},toggleOverwrite:function(t){return t.toggleOverwrite()}};function Js(t,e){var r=at(t.doc,e),i=Ht(r);return i!=r&&(e=ut(i)),qs(!0,t,i,e,1)}function Zs(t,e){var r=Js(t,e.line),i=at(t.doc,r.line),n=Qt(i,t.doc.direction);if(!n||0==n[0].level){var s=Math.max(0,i.text.search(/\S/)),o=e.line==r.line&&e.ch<=s&&e.ch;return gt(r.line,o?0:s,r.sticky)}return r}function Qs(t,e,r){if("string"==typeof e&&!(e=Ys[e]))return!1;t.display.input.ensurePolled();var i=t.display.shift,n=!1;try{t.isReadOnly()&&(t.state.suppressEdits=!0),r&&(t.display.shift=!1),n=e(t)!=G}finally{t.display.shift=i,t.state.suppressEdits=!1}return n}var $s=new U;function to(t,e,r,i){var n=t.state.keySeq;if(n){if(Hs(e))return"handled";if(/\'$/.test(e)?t.state.keySeq=null:$s.set(50,function(){t.state.keySeq==n&&(t.state.keySeq=null,t.display.input.reset())}),eo(t,n+" "+e,r,i))return!0}return eo(t,e,r,i)}function eo(t,e,r,i){var n=function(t,e,r){for(var i=0;i<t.state.keyMaps.length;i++){var n=Ws(e,t.state.keyMaps[i],r,t);if(n)return n}return t.options.extraKeys&&Ws(e,t.options.extraKeys,r,t)||Ws(e,t.options.keyMap,r,t)}(t,e,i);return"multi"==n&&(t.state.keySeq=e),"handled"==n&&or(t,"keyHandled",t,e,r),"handled"!=n&&"multi"!=n||(le(r),fi(t)),!!n}function ro(t,e){var r=zs(e,!0);return!!r&&(e.shiftKey&&!t.state.keySeq?to(t,"Shift-"+r,e,function(e){return Qs(t,e,!0)})||to(t,r,e,function(e){if("string"==typeof e?/^go[A-Z]/.test(e):e.motion)return Qs(t,e)}):to(t,r,e,function(e){return Qs(t,e)}))}var io=null;function no(t){var e=this;if(e.curOp.focus=D(),!ne(e,t)){o&&a<11&&27==t.keyCode&&(t.returnValue=!1);var r=t.keyCode;e.display.shift=16==r||t.shiftKey;var i=ro(e,t);u&&(io=i?r:null,!i&&88==r&&!we&&(y?t.metaKey:t.ctrlKey)&&e.replaceSelection("",null,"cut")),18!=r||/\bCodeMirror-crosshair\b/.test(e.display.lineDiv.className)||function(t){var e=t.display.lineDiv;function r(t){18!=t.keyCode&&t.altKey||(C(e,"CodeMirror-crosshair"),re(document,"keyup",r),re(document,"mouseover",r))}R(e,"CodeMirror-crosshair"),te(document,"keyup",r),te(document,"mouseover",r)}(e)}}function so(t){16==t.keyCode&&(this.doc.sel.shift=!1),ne(this,t)}function oo(t){var e=this;if(!(xr(e.display,t)||ne(e,t)||t.ctrlKey&&!t.altKey||y&&t.metaKey)){var r=t.keyCode,i=t.charCode;if(u&&r==io)return io=null,void le(t);if(!u||t.which&&!(t.which<10)||!ro(e,t)){var n=String.fromCharCode(null==i?r:i);"\b"!=n&&(function(t,e,r){return to(t,"'"+r+"'",e,function(e){return Qs(t,e,!0)})}(e,t,n)||e.display.input.onKeyPress(t))}}}var ao,lo,co=function(t,e,r){this.time=t,this.pos=e,this.button=r};function ho(t){var e=this,r=e.display;if(!(ne(e,t)||r.activeTouch&&r.input.supportsTouch()))if(r.input.ensurePolled(),r.shift=t.shiftKey,xr(r,t))l||(r.scroller.draggable=!1,setTimeout(function(){return r.scroller.draggable=!0},100));else if(!po(e,t)){var i=si(e,t),n=de(t),s=i?function(t,e){var r=+new Date;return lo&&lo.compare(r,t,e)?(ao=lo=null,"triple"):ao&&ao.compare(r,t,e)?(lo=new co(r,t,e),ao=null,"double"):(ao=new co(r,t,e),lo=null,"single")}(i,n):"single";window.focus(),1==n&&e.state.selectingText&&e.state.selectingText(t),i&&function(t,e,r,i,n){var s="Click";return"double"==i?s="Double"+s:"triple"==i&&(s="Triple"+s),to(t,Gs(s=(1==e?"Left":2==e?"Middle":"Right")+s,n),n,function(e){if("string"==typeof e&&(e=Ys[e]),!e)return!1;var i=!1;try{t.isReadOnly()&&(t.state.suppressEdits=!0),i=e(t,r)!=G}finally{t.state.suppressEdits=!1}return i})}(e,n,i,s,t)||(1==n?i?function(t,e,r,i){o?setTimeout(V(di,t),0):t.curOp.focus=D();var n,s=function(t,e,r){var i=t.getOption("configureMouse"),n=i?i(t,e,r):{};if(null==n.unit){var s=b?r.shiftKey&&r.metaKey:r.altKey;n.unit=s?"rectangle":"single"==e?"char":"double"==e?"word":"line"}return(null==n.extend||t.doc.extend)&&(n.extend=t.doc.extend||r.shiftKey),null==n.addNew&&(n.addNew=y?r.metaKey:r.ctrlKey),null==n.moveOnDrag&&(n.moveOnDrag=!(y?r.altKey:r.ctrlKey)),n}(t,r,i),c=t.doc.sel;t.options.dragDrop&&me&&!t.isReadOnly()&&"single"==r&&(n=c.contains(e))>-1&&(mt((n=c.ranges[n]).from(),e)<0||e.xRel>0)&&(mt(n.to(),e)>0||e.xRel<0)?function(t,e,r,i){var n=t.display,s=!1,c=Ki(t,function(e){l&&(n.scroller.draggable=!1),t.state.draggingText=!1,re(n.wrapper.ownerDocument,"mouseup",c),re(n.wrapper.ownerDocument,"mousemove",h),re(n.scroller,"dragstart",u),re(n.scroller,"drop",c),s||(le(e),i.addNew||zn(t.doc,r,null,null,i.extend),l||o&&9==a?setTimeout(function(){n.wrapper.ownerDocument.body.focus(),n.input.focus()},20):n.input.focus())}),h=function(t){s=s||Math.abs(e.clientX-t.clientX)+Math.abs(e.clientY-t.clientY)>=10},u=function(){return s=!0};l&&(n.scroller.draggable=!0),t.state.draggingText=c,c.copy=!i.moveOnDrag,n.scroller.dragDrop&&n.scroller.dragDrop(),te(n.wrapper.ownerDocument,"mouseup",c),te(n.wrapper.ownerDocument,"mousemove",h),te(n.scroller,"dragstart",u),te(n.scroller,"drop",c),pi(t),setTimeout(function(){return n.input.focus()},20)}(t,i,e,s):function(t,e,r,i){var n=t.display,s=t.doc;le(e);var o,a,l=s.sel,c=l.ranges;if(i.addNew&&!i.extend?(a=s.sel.contains(r),o=a>-1?c[a]:new yn(r,r)):(o=s.sel.primary(),a=s.sel.primIndex),"rectangle"==i.unit)i.addNew||(o=new yn(r,r)),r=si(t,e,!0,!0),a=-1;else{var h=uo(t,r,i.unit);o=i.extend?Gn(o,h.anchor,h.head,i.extend):h}i.addNew?-1==a?(a=c.length,qn(s,bn(c.concat([o]),a),{scroll:!1,origin:"*mouse"})):c.length>1&&c[a].empty()&&"char"==i.unit&&!i.extend?(qn(s,bn(c.slice(0,a).concat(c.slice(a+1)),0),{scroll:!1,origin:"*mouse"}),l=s.sel):Xn(s,a,o,_):(a=0,qn(s,new vn([o],0),_),l=s.sel);var u=r;function f(e){if(0!=mt(u,e))if(u=e,"rectangle"==i.unit){for(var n=[],c=t.options.tabSize,h=F(at(s,r.line).text,r.ch,c),f=F(at(s,e.line).text,e.ch,c),d=Math.min(h,f),p=Math.max(h,f),g=Math.min(r.line,e.line),m=Math.min(t.lastLine(),Math.max(r.line,e.line));g<=m;g++){var v=at(s,g).text,y=j(v,d,c);d==p?n.push(new yn(gt(g,y),gt(g,y))):v.length>y&&n.push(new yn(gt(g,y),gt(g,j(v,p,c))))}n.length||n.push(new yn(r,r)),qn(s,bn(l.ranges.slice(0,a).concat(n),a),{origin:"*mouse",scroll:!1}),t.scrollIntoView(e)}else{var b,x=o,w=uo(t,e,i.unit),k=x.anchor;mt(w.anchor,k)>0?(b=w.head,k=xt(x.from(),w.anchor)):(b=w.anchor,k=bt(x.to(),w.head));var S=l.ranges.slice(0);S[a]=function(t,e){var r=e.anchor,i=e.head,n=at(t.doc,r.line);if(0==mt(r,i)&&r.sticky==i.sticky)return e;var s=Qt(n);if(!s)return e;var o=Jt(s,r.ch,r.sticky),a=s[o];if(a.from!=r.ch&&a.to!=r.ch)return e;var l,c=o+(a.from==r.ch==(1!=a.level)?0:1);if(0==c||c==s.length)return e;if(i.line!=r.line)l=(i.line-r.line)*("ltr"==t.doc.direction?1:-1)>0;else{var h=Jt(s,i.ch,i.sticky),u=h-o||(i.ch-r.ch)*(1==a.level?-1:1);l=h==c-1||h==c?u<0:u>0}var f=s[c+(l?-1:0)],d=l==(1==f.level),p=d?f.from:f.to,g=d?"after":"before";return r.ch==p&&r.sticky==g?e:new yn(new gt(r.line,p,g),i)}(t,new yn(kt(s,k),b)),qn(s,bn(S,a),_)}}var d=n.wrapper.getBoundingClientRect(),p=0;function g(e){t.state.selectingText=!1,p=1/0,le(e),n.input.focus(),re(n.wrapper.ownerDocument,"mousemove",m),re(n.wrapper.ownerDocument,"mouseup",v),s.history.lastSelOrigin=null}var m=Ki(t,function(e){0!==e.buttons&&de(e)?function e(r){var o=++p,a=si(t,r,!0,"rectangle"==i.unit);if(a)if(0!=mt(a,u)){t.curOp.focus=D(),f(a);var l=bi(n,s);(a.line>=l.to||a.line<l.from)&&setTimeout(Ki(t,function(){p==o&&e(r)}),150)}else{var c=r.clientY<d.top?-20:r.clientY>d.bottom?20:0;c&&setTimeout(Ki(t,function(){p==o&&(n.scroller.scrollTop+=c,e(r))}),50)}}(e):g(e)}),v=Ki(t,g);t.state.selectingText=v,te(n.wrapper.ownerDocument,"mousemove",m),te(n.wrapper.ownerDocument,"mouseup",v)}(t,i,e,s)}(e,i,s,t):fe(t)==r.scroller&&le(t):2==n?(i&&zn(e.doc,i),setTimeout(function(){return r.input.focus()},20)):3==n&&(S?go(e,t):pi(e)))}}function uo(t,e,r){if("char"==r)return new yn(e,e);if("word"==r)return t.findWordAt(e);if("line"==r)return new yn(gt(e.line,0),kt(t.doc,gt(e.line+1,0)));var i=r(t,e);return new yn(i.from,i.to)}function fo(t,e,r,i){var n,s;if(e.touches)n=e.touches[0].clientX,s=e.touches[0].clientY;else try{n=e.clientX,s=e.clientY}catch(e){return!1}if(n>=Math.floor(t.display.gutters.getBoundingClientRect().right))return!1;i&&le(e);var o=t.display,a=o.lineDiv.getBoundingClientRect();if(s>a.bottom||!oe(t,r))return he(e);s-=a.top-o.viewOffset;for(var l=0;l<t.options.gutters.length;++l){var c=o.gutters.childNodes[l];if(c&&c.getBoundingClientRect().right>=n){var h=ft(t.doc,s),u=t.options.gutters[l];return ie(t,r,t,h,u,e),he(e)}}}function po(t,e){return fo(t,e,"gutterClick",!0)}function go(t,e){xr(t.display,e)||function(t,e){return!!oe(t,"gutterContextMenu")&&fo(t,e,"gutterContextMenu",!1)}(t,e)||ne(t,e,"contextmenu")||t.display.input.onContextMenu(e)}function mo(t){t.display.wrapper.className=t.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+t.options.theme.replace(/(^|\s)\s*/g," cm-s-"),Fr(t)}co.prototype.compare=function(t,e,r){return this.time+400>t&&0==mt(e,this.pos)&&r==this.button};var vo={toString:function(){return"CodeMirror.Init"}},yo={},bo={};function xo(t){hn(t),Ji(t),xi(t)}function wo(t,e,r){var i=r&&r!=vo;if(!e!=!i){var n=t.display.dragFunctions,s=e?te:re;s(t.display.scroller,"dragstart",n.start),s(t.display.scroller,"dragenter",n.enter),s(t.display.scroller,"dragover",n.over),s(t.display.scroller,"dragleave",n.leave),s(t.display.scroller,"drop",n.drop)}}function ko(t){t.options.lineWrapping?(R(t.display.wrapper,"CodeMirror-wrap"),t.display.sizer.style.minWidth="",t.display.sizerWidth=null):(C(t.display.wrapper,"CodeMirror-wrap"),qt(t)),ni(t),Ji(t),Fr(t),setTimeout(function(){return Mi(t)},100)}function So(t,e){var i=this;if(!(this instanceof So))return new So(t,e);this.options=e=e?B(e):{},B(yo,e,!1),un(e);var n=e.value;"string"==typeof n?n=new Ts(n,e.mode,null,e.lineSeparator,e.direction):e.mode&&(n.modeOption=e.mode),this.doc=n;var s=new So.inputStyles[e.inputStyle](this),c=this.display=new function(t,e,i){var n=this;this.input=i,n.scrollbarFiller=L("div",null,"CodeMirror-scrollbar-filler"),n.scrollbarFiller.setAttribute("cm-not-content","true"),n.gutterFiller=L("div",null,"CodeMirror-gutter-filler"),n.gutterFiller.setAttribute("cm-not-content","true"),n.lineDiv=N("div",null,"CodeMirror-code"),n.selectionDiv=L("div",null,null,"position: relative; z-index: 1"),n.cursorDiv=L("div",null,"CodeMirror-cursors"),n.measure=L("div",null,"CodeMirror-measure"),n.lineMeasure=L("div",null,"CodeMirror-measure"),n.lineSpace=N("div",[n.measure,n.lineMeasure,n.selectionDiv,n.cursorDiv,n.lineDiv],null,"position: relative; outline: none");var s=N("div",[n.lineSpace],"CodeMirror-lines");n.mover=L("div",[s],null,"position: relative"),n.sizer=L("div",[n.mover],"CodeMirror-sizer"),n.sizerWidth=null,n.heightForcer=L("div",null,null,"position: absolute; height: "+H+"px; width: 1px;"),n.gutters=L("div",null,"CodeMirror-gutters"),n.lineGutter=null,n.scroller=L("div",[n.sizer,n.heightForcer,n.gutters],"CodeMirror-scroll"),n.scroller.setAttribute("tabIndex","-1"),n.wrapper=L("div",[n.scrollbarFiller,n.gutterFiller,n.scroller],"CodeMirror"),o&&a<8&&(n.gutters.style.zIndex=-1,n.scroller.style.paddingRight=0),l||r&&v||(n.scroller.draggable=!0),t&&(t.appendChild?t.appendChild(n.wrapper):t(n.wrapper)),n.viewFrom=n.viewTo=e.first,n.reportedViewFrom=n.reportedViewTo=e.first,n.view=[],n.renderedView=null,n.externalMeasured=null,n.viewOffset=0,n.lastWrapHeight=n.lastWrapWidth=0,n.updateLineNumbers=null,n.nativeBarWidth=n.barHeight=n.barWidth=0,n.scrollbarsClipped=!1,n.lineNumWidth=n.lineNumInnerWidth=n.lineNumChars=null,n.alignWidgets=!1,n.cachedCharWidth=n.cachedTextHeight=n.cachedPaddingH=null,n.maxLine=null,n.maxLineLength=0,n.maxLineChanged=!1,n.wheelDX=n.wheelDY=n.wheelStartX=n.wheelStartY=null,n.shift=!1,n.selForContextMenu=null,n.activeTouch=null,i.init(n)}(t,n,s);for(var h in c.wrapper.CodeMirror=this,hn(this),mo(this),e.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),Bi(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,delayingBlurEvent:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,cutIncoming:!1,selectingText:!1,draggingText:!1,highlight:new U,keySeq:null,specialChars:null},e.autofocus&&!v&&c.input.focus(),o&&a<11&&setTimeout(function(){return i.display.input.reset(!0)},20),function(t){var e=t.display;te(e.scroller,"mousedown",Ki(t,ho)),te(e.scroller,"dblclick",o&&a<11?Ki(t,function(e){if(!ne(t,e)){var r=si(t,e);if(r&&!po(t,e)&&!xr(t.display,e)){le(e);var i=t.findWordAt(r);zn(t.doc,i.anchor,i.head)}}}):function(e){return ne(t,e)||le(e)}),S||te(e.scroller,"contextmenu",function(e){return go(t,e)});var r,i={end:0};function n(){e.activeTouch&&(r=setTimeout(function(){return e.activeTouch=null},1e3),(i=e.activeTouch).end=+new Date)}function s(t,e){if(null==e.left)return!0;var r=e.left-t.left,i=e.top-t.top;return r*r+i*i>400}te(e.scroller,"touchstart",function(n){if(!ne(t,n)&&!function(t){if(1!=t.touches.length)return!1;var e=t.touches[0];return e.radiusX<=1&&e.radiusY<=1}(n)&&!po(t,n)){e.input.ensurePolled(),clearTimeout(r);var s=+new Date;e.activeTouch={start:s,moved:!1,prev:s-i.end<=300?i:null},1==n.touches.length&&(e.activeTouch.left=n.touches[0].pageX,e.activeTouch.top=n.touches[0].pageY)}}),te(e.scroller,"touchmove",function(){e.activeTouch&&(e.activeTouch.moved=!0)}),te(e.scroller,"touchend",function(r){var i=e.activeTouch;if(i&&!xr(e,r)&&null!=i.left&&!i.moved&&new Date-i.start<300){var o,a=t.coordsChar(e.activeTouch,"page");o=!i.prev||s(i,i.prev)?new yn(a,a):!i.prev.prev||s(i,i.prev.prev)?t.findWordAt(a):new yn(gt(a.line,0),kt(t.doc,gt(a.line+1,0))),t.setSelection(o.anchor,o.head),t.focus(),le(r)}n()}),te(e.scroller,"touchcancel",n),te(e.scroller,"scroll",function(){e.scroller.clientHeight&&(Oi(t,e.scroller.scrollTop),Ni(t,e.scroller.scrollLeft,!0),ie(t,"scroll",t))}),te(e.scroller,"mousewheel",function(e){return mn(t,e)}),te(e.scroller,"DOMMouseScroll",function(e){return mn(t,e)}),te(e.wrapper,"scroll",function(){return e.wrapper.scrollTop=e.wrapper.scrollLeft=0}),e.dragFunctions={enter:function(e){ne(t,e)||ue(e)},over:function(e){ne(t,e)||(function(t,e){var r=si(t,e);if(r){var i=document.createDocumentFragment();ci(t,r,i),t.display.dragCursor||(t.display.dragCursor=L("div",null,"CodeMirror-cursors CodeMirror-dragcursors"),t.display.lineSpace.insertBefore(t.display.dragCursor,t.display.cursorDiv)),O(t.display.dragCursor,i)}}(t,e),ue(e))},start:function(e){return function(t,e){if(o&&(!t.state.draggingText||+new Date-Cs<100))ue(e);else if(!ne(t,e)&&!xr(t.display,e)&&(e.dataTransfer.setData("Text",t.getSelection()),e.dataTransfer.effectAllowed="copyMove",e.dataTransfer.setDragImage&&!f)){var r=L("img",null,null,"position: fixed; left: 0; top: 0;");r.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",u&&(r.width=r.height=1,t.display.wrapper.appendChild(r),r._top=r.offsetTop),e.dataTransfer.setDragImage(r,0,0),u&&r.parentNode.removeChild(r)}}(t,e)},drop:Ki(t,Is),leave:function(e){ne(t,e)||Os(t)}};var l=e.input.getField();te(l,"keyup",function(e){return so.call(t,e)}),te(l,"keydown",Ki(t,no)),te(l,"keypress",Ki(t,oo)),te(l,"focus",function(e){return gi(t,e)}),te(l,"blur",function(e){return mi(t,e)})}(this),As(),Ui(this),this.curOp.forceUpdate=!0,Nn(this,n),e.autofocus&&!v||this.hasFocus()?setTimeout(V(gi,this),20):mi(this),bo)bo.hasOwnProperty(h)&&bo[h](i,e[h],vo);wi(this),e.finishInit&&e.finishInit(this);for(var d=0;d<Eo.length;++d)Eo[d](i);Wi(this),l&&e.lineWrapping&&"optimizelegibility"==getComputedStyle(c.lineDiv).textRendering&&(c.lineDiv.style.textRendering="auto")}So.defaults=yo,So.optionHandlers=bo;var Eo=[];function To(t,e,r,i){var n,s=t.doc;null==r&&(r="add"),"smart"==r&&(s.mode.indent?n=Be(t,e).state:r="prev");var o=t.options.tabSize,a=at(s,e),l=F(a.text,null,o);a.stateAfter&&(a.stateAfter=null);var c,h=a.text.match(/^\s*/)[0];if(i||/\S/.test(a.text)){if("smart"==r&&((c=s.mode.indent(n,a.text.slice(h.length),a.text))==G||c>150)){if(!i)return;r="prev"}}else c=0,r="not";"prev"==r?c=e>s.first?F(at(s,e-1).text,null,o):0:"add"==r?c=l+t.options.indentUnit:"subtract"==r?c=l-t.options.indentUnit:"number"==typeof r&&(c=l+r),c=Math.max(0,c);var u="",f=0;if(t.options.indentWithTabs)for(var d=Math.floor(c/o);d;--d)f+=o,u+="\t";if(f<c&&(u+=q(c-f)),u!=h)return cs(s,u,gt(e,0),gt(e,h.length),"+input"),a.stateAfter=null,!0;for(var p=0;p<s.sel.ranges.length;p++){var g=s.sel.ranges[p];if(g.head.line==e&&g.head.ch<h.length){var m=gt(e,h.length);Xn(s,p,new yn(m,m));break}}}So.defineInitHook=function(t){return Eo.push(t)};var Co=null;function Io(t){Co=t}function Oo(t,e,r,i,n){var s=t.doc;t.display.shift=!1,i||(i=s.sel);var o,a=t.state.pasteIncoming||"paste"==n,l=be(e),c=null;if(a&&i.ranges.length>1)if(Co&&Co.text.join("\n")==e){if(i.ranges.length%Co.text.length==0){c=[];for(var h=0;h<Co.text.length;h++)c.push(s.splitLines(Co.text[h]))}}else l.length==i.ranges.length&&t.options.pasteLinesPerSelection&&(c=J(l,function(t){return[t]}));for(var u=i.ranges.length-1;u>=0;u--){var f=i.ranges[u],d=f.from(),p=f.to();f.empty()&&(r&&r>0?d=gt(d.line,d.ch-r):t.state.overwrite&&!a?p=gt(p.line,Math.min(at(s,p.line).text.length,p.ch+Y(l).length)):Co&&Co.lineWise&&Co.text.join("\n")==e&&(d=p=gt(d.line,0))),o=t.curOp.updateInput;var g={from:d,to:p,text:c?c[u%c.length]:l,origin:n||(a?"paste":t.state.cutIncoming?"cut":"+input")};ns(t.doc,g),or(t,"inputRead",t,g)}e&&!a&&No(t,e),Ei(t),t.curOp.updateInput=o,t.curOp.typing=!0,t.state.pasteIncoming=t.state.cutIncoming=!1}function Lo(t,e){var r=t.clipboardData&&t.clipboardData.getData("Text");if(r)return t.preventDefault(),e.isReadOnly()||e.options.disableInput||ji(e,function(){return Oo(e,r,0,null,"paste")}),!0}function No(t,e){if(t.options.electricChars&&t.options.smartIndent)for(var r=t.doc.sel,i=r.ranges.length-1;i>=0;i--){var n=r.ranges[i];if(!(n.head.ch>100||i&&r.ranges[i-1].head.line==n.head.line)){var s=t.getModeAt(n.head),o=!1;if(s.electricChars){for(var a=0;a<s.electricChars.length;a++)if(e.indexOf(s.electricChars.charAt(a))>-1){o=To(t,n.head.line,"smart");break}}else s.electricInput&&s.electricInput.test(at(t.doc,n.head.line).text.slice(0,n.head.ch))&&(o=To(t,n.head.line,"smart"));o&&or(t,"electricInput",t,n.head.line)}}}function Ao(t){for(var e=[],r=[],i=0;i<t.doc.sel.ranges.length;i++){var n=t.doc.sel.ranges[i].head.line,s={anchor:gt(n,0),head:gt(n+1,0)};r.push(s),e.push(t.getRange(s.anchor,s.head))}return{text:e,ranges:r}}function Do(t,e){t.setAttribute("autocorrect","off"),t.setAttribute("autocapitalize","off"),t.setAttribute("spellcheck",!!e)}function Ro(){var t=L("textarea",null,null,"position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none"),e=L("div",[t],null,"overflow: hidden; position: relative; width: 3px; height: 0px;");return l?t.style.width="1000px":t.setAttribute("wrap","off"),g&&(t.style.border="1px solid black"),Do(t),e}function Mo(t,e,r,i,n){var s=e,o=r,a=at(t,e.line);function l(i){var s;if(null==(s=n?function(t,e,r,i){var n=Qt(e,t.doc.direction);if(!n)return Ks(e,r,i);r.ch>=e.text.length?(r.ch=e.text.length,r.sticky="before"):r.ch<=0&&(r.ch=0,r.sticky="after");var s=Jt(n,r.ch,r.sticky),o=n[s];if("ltr"==t.doc.direction&&o.level%2==0&&(i>0?o.to>r.ch:o.from<r.ch))return Ks(e,r,i);var a,l=function(t,r){return js(e,t instanceof gt?t.ch:t,r)},c=function(r){return t.options.lineWrapping?(a=a||Nr(t,e),Jr(t,e,a,r)):{begin:0,end:e.text.length}},h=c("before"==r.sticky?l(r,-1):r.ch);if("rtl"==t.doc.direction||1==o.level){var u=1==o.level==i<0,f=l(r,u?1:-1);if(null!=f&&(u?f<=o.to&&f<=h.end:f>=o.from&&f>=h.begin)){var d=u?"before":"after";return new gt(r.line,f,d)}}var p=function(t,e,i){for(var s=function(t,e){return e?new gt(r.line,l(t,1),"before"):new gt(r.line,t,"after")};t>=0&&t<n.length;t+=e){var o=n[t],a=e>0==(1!=o.level),c=a?i.begin:l(i.end,-1);if(o.from<=c&&c<o.to)return s(c,a);if(c=a?o.from:l(o.to,-1),i.begin<=c&&c<i.end)return s(c,a)}},g=p(s+i,i,h);if(g)return g;var m=i>0?h.end:l(h.begin,-1);return null==m||i>0&&m==e.text.length||!(g=p(i>0?0:n.length-1,i,c(m)))?null:g}(t.cm,a,e,r):Ks(a,e,r))){if(i||!function(){var i=e.line+r;return!(i<t.first||i>=t.first+t.size)&&(e=new gt(i,e.ch,e.sticky),a=at(t,i))}())return!1;e=qs(n,t.cm,a,e.line,r)}else e=s;return!0}if("char"==i)l();else if("column"==i)l(!0);else if("word"==i||"group"==i)for(var c=null,h="group"==i,u=t.cm&&t.cm.getHelper(e,"wordChars"),f=!0;!(r<0)||l(!f);f=!1){var d=a.text.charAt(e.ch)||"\n",p=et(d,u)?"w":h&&"\n"==d?"n":!h||/\s/.test(d)?null:"p";if(!h||f||p||(p="s"),c&&c!=p){r<0&&(r=1,l(),e.sticky="after");break}if(p&&(c=p),r>0&&!l(!f))break}var g=ts(t,e,s,o,!0);return vt(s,g)&&(g.hitSide=!0),g}function Po(t,e,r,i){var n,s,o=t.doc,a=e.left;if("page"==i){var l=Math.min(t.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight),c=Math.max(l-.5*$r(t.display),3);n=(r>0?e.bottom:e.top)+r*c}else"line"==i&&(n=r>0?e.bottom+3:e.top-3);for(;(s=qr(t,a,n)).outside;){if(r<0?n<=0:n>=o.height){s.hitSide=!0;break}n+=5*r}return s}var Vo=function(t){this.cm=t,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new U,this.composing=null,this.gracePeriod=!1,this.readDOMTimeout=null};function Bo(t,e){var r=Lr(t,e.line);if(!r||r.hidden)return null;var i=at(t.doc,e.line),n=Ir(r,i,e.line),s=Qt(i,t.doc.direction),o="left";if(s){var a=Jt(s,e.ch);o=a%2?"right":"left"}var l=Mr(n.map,e.ch,o);return l.offset="right"==l.collapse?l.end:l.start,l}function Fo(t,e){return e&&(t.bad=!0),t}function Uo(t,e,r){var i;if(e==t.display.lineDiv){if(!(i=t.display.lineDiv.childNodes[r]))return Fo(t.clipPos(gt(t.display.viewTo-1)),!0);e=null,r=0}else for(i=e;;i=i.parentNode){if(!i||i==t.display.lineDiv)return null;if(i.parentNode&&i.parentNode==t.display.lineDiv)break}for(var n=0;n<t.display.view.length;n++){var s=t.display.view[n];if(s.node==i)return Wo(s,e,r)}}function Wo(t,e,r){var i=t.text.firstChild,n=!1;if(!e||!A(i,e))return Fo(gt(ut(t.line),0),!0);if(e==i&&(n=!0,e=i.childNodes[r],r=0,!e)){var s=t.rest?Y(t.rest):t.line;return Fo(gt(ut(s),s.text.length),n)}var o=3==e.nodeType?e:null,a=e;for(o||1!=e.childNodes.length||3!=e.firstChild.nodeType||(o=e.firstChild,r&&(r=o.nodeValue.length));a.parentNode!=i;)a=a.parentNode;var l=t.measure,c=l.maps;function h(e,r,i){for(var n=-1;n<(c?c.length:0);n++)for(var s=n<0?l.map:c[n],o=0;o<s.length;o+=3){var a=s[o+2];if(a==e||a==r){var h=ut(n<0?t.line:t.rest[n]),u=s[o]+i;return(i<0||a!=e)&&(u=s[o+(i?1:0)]),gt(h,u)}}}var u=h(o,a,r);if(u)return Fo(u,n);for(var f=a.nextSibling,d=o?o.nodeValue.length-r:0;f;f=f.nextSibling){if(u=h(f,f.firstChild,0))return Fo(gt(u.line,u.ch-d),n);d+=f.textContent.length}for(var p=a.previousSibling,g=r;p;p=p.previousSibling){if(u=h(p,p.firstChild,-1))return Fo(gt(u.line,u.ch+g),n);g+=p.textContent.length}}Vo.prototype.init=function(t){var e=this,r=this,i=r.cm,n=r.div=t.lineDiv;function s(t){if(!ne(i,t)){if(i.somethingSelected())Io({lineWise:!1,text:i.getSelections()}),"cut"==t.type&&i.replaceSelection("",null,"cut");else{if(!i.options.lineWiseCopyCut)return;var e=Ao(i);Io({lineWise:!0,text:e.text}),"cut"==t.type&&i.operation(function(){i.setSelections(e.ranges,0,z),i.replaceSelection("",null,"cut")})}if(t.clipboardData){t.clipboardData.clearData();var s=Co.text.join("\n");if(t.clipboardData.setData("Text",s),t.clipboardData.getData("Text")==s)return void t.preventDefault()}var o=Ro(),a=o.firstChild;i.display.lineSpace.insertBefore(o,i.display.lineSpace.firstChild),a.value=Co.text.join("\n");var l=document.activeElement;P(a),setTimeout(function(){i.display.lineSpace.removeChild(o),l.focus(),l==n&&r.showPrimarySelection()},50)}}Do(n,i.options.spellcheck),te(n,"paste",function(t){ne(i,t)||Lo(t,i)||a<=11&&setTimeout(Ki(i,function(){return e.updateFromDOM()}),20)}),te(n,"compositionstart",function(t){e.composing={data:t.data,done:!1}}),te(n,"compositionupdate",function(t){e.composing||(e.composing={data:t.data,done:!1})}),te(n,"compositionend",function(t){e.composing&&(t.data!=e.composing.data&&e.readFromDOMSoon(),e.composing.done=!0)}),te(n,"touchstart",function(){return r.forceCompositionEnd()}),te(n,"input",function(){e.composing||e.readFromDOMSoon()}),te(n,"copy",s),te(n,"cut",s)},Vo.prototype.prepareSelection=function(){var t=li(this.cm,!1);return t.focus=this.cm.state.focused,t},Vo.prototype.showSelection=function(t,e){t&&this.cm.display.view.length&&((t.focus||e)&&this.showPrimarySelection(),this.showMultipleSelections(t))},Vo.prototype.getSelection=function(){return this.cm.display.wrapper.ownerDocument.getSelection()},Vo.prototype.showPrimarySelection=function(){var t=this.getSelection(),e=this.cm,i=e.doc.sel.primary(),n=i.from(),s=i.to();if(e.display.viewTo==e.display.viewFrom||n.line>=e.display.viewTo||s.line<e.display.viewFrom)t.removeAllRanges();else{var o=Uo(e,t.anchorNode,t.anchorOffset),a=Uo(e,t.focusNode,t.focusOffset);if(!o||o.bad||!a||a.bad||0!=mt(xt(o,a),n)||0!=mt(bt(o,a),s)){var l=e.display.view,c=n.line>=e.display.viewFrom&&Bo(e,n)||{node:l[0].measure.map[2],offset:0},h=s.line<e.display.viewTo&&Bo(e,s);if(!h){var u=l[l.length-1].measure,f=u.maps?u.maps[u.maps.length-1]:u.map;h={node:f[f.length-1],offset:f[f.length-2]-f[f.length-3]}}if(c&&h){var d,p=t.rangeCount&&t.getRangeAt(0);try{d=T(c.node,c.offset,h.offset,h.node)}catch(t){}d&&(!r&&e.state.focused?(t.collapse(c.node,c.offset),d.collapsed||(t.removeAllRanges(),t.addRange(d))):(t.removeAllRanges(),t.addRange(d)),p&&null==t.anchorNode?t.addRange(p):r&&this.startGracePeriod()),this.rememberSelection()}else t.removeAllRanges()}}},Vo.prototype.startGracePeriod=function(){var t=this;clearTimeout(this.gracePeriod),this.gracePeriod=setTimeout(function(){t.gracePeriod=!1,t.selectionChanged()&&t.cm.operation(function(){return t.cm.curOp.selectionChanged=!0})},20)},Vo.prototype.showMultipleSelections=function(t){O(this.cm.display.cursorDiv,t.cursors),O(this.cm.display.selectionDiv,t.selection)},Vo.prototype.rememberSelection=function(){var t=this.getSelection();this.lastAnchorNode=t.anchorNode,this.lastAnchorOffset=t.anchorOffset,this.lastFocusNode=t.focusNode,this.lastFocusOffset=t.focusOffset},Vo.prototype.selectionInEditor=function(){var t=this.getSelection();if(!t.rangeCount)return!1;var e=t.getRangeAt(0).commonAncestorContainer;return A(this.div,e)},Vo.prototype.focus=function(){"nocursor"!=this.cm.options.readOnly&&(this.selectionInEditor()||this.showSelection(this.prepareSelection(),!0),this.div.focus())},Vo.prototype.blur=function(){this.div.blur()},Vo.prototype.getField=function(){return this.div},Vo.prototype.supportsTouch=function(){return!0},Vo.prototype.receivedFocus=function(){var t=this;this.selectionInEditor()?this.pollSelection():ji(this.cm,function(){return t.cm.curOp.selectionChanged=!0}),this.polling.set(this.cm.options.pollInterval,function e(){t.cm.state.focused&&(t.pollSelection(),t.polling.set(t.cm.options.pollInterval,e))})},Vo.prototype.selectionChanged=function(){var t=this.getSelection();return t.anchorNode!=this.lastAnchorNode||t.anchorOffset!=this.lastAnchorOffset||t.focusNode!=this.lastFocusNode||t.focusOffset!=this.lastFocusOffset},Vo.prototype.pollSelection=function(){if(null==this.readDOMTimeout&&!this.gracePeriod&&this.selectionChanged()){var t=this.getSelection(),e=this.cm;if(m&&h&&this.cm.options.gutters.length&&function(t){for(var e=t;e;e=e.parentNode)if(/CodeMirror-gutter-wrapper/.test(e.className))return!0;return!1}(t.anchorNode))return this.cm.triggerOnKeyDown({type:"keydown",keyCode:8,preventDefault:Math.abs}),this.blur(),void this.focus();if(!this.composing){this.rememberSelection();var r=Uo(e,t.anchorNode,t.anchorOffset),i=Uo(e,t.focusNode,t.focusOffset);r&&i&&ji(e,function(){qn(e.doc,xn(r,i),z),(r.bad||i.bad)&&(e.curOp.selectionChanged=!0)})}}},Vo.prototype.pollContent=function(){null!=this.readDOMTimeout&&(clearTimeout(this.readDOMTimeout),this.readDOMTimeout=null);var t,e,r,i=this.cm,n=i.display,s=i.doc.sel.primary(),o=s.from(),a=s.to();if(0==o.ch&&o.line>i.firstLine()&&(o=gt(o.line-1,at(i.doc,o.line-1).length)),a.ch==at(i.doc,a.line).text.length&&a.line<i.lastLine()&&(a=gt(a.line+1,0)),o.line<n.viewFrom||a.line>n.viewTo-1)return!1;o.line==n.viewFrom||0==(t=oi(i,o.line))?(e=ut(n.view[0].line),r=n.view[0].node):(e=ut(n.view[t].line),r=n.view[t-1].node.nextSibling);var l,c,h=oi(i,a.line);if(h==n.view.length-1?(l=n.viewTo-1,c=n.lineDiv.lastChild):(l=ut(n.view[h+1].line)-1,c=n.view[h+1].node.previousSibling),!r)return!1;for(var u=i.doc.splitLines(function(t,e,r,i,n){var s="",o=!1,a=t.doc.lineSeparator(),l=!1;function c(){o&&(s+=a,l&&(s+=a),o=l=!1)}function h(t){t&&(c(),s+=t)}function u(e){if(1==e.nodeType){var r=e.getAttribute("cm-text");if(r)return void h(r);var s,f=e.getAttribute("cm-marker");if(f){var d=t.findMarks(gt(i,0),gt(n+1,0),function(t){return function(e){return e.id==t}}(+f));return void(d.length&&(s=d[0].find(0))&&h(lt(t.doc,s.from,s.to).join(a)))}if("false"==e.getAttribute("contenteditable"))return;var p=/^(pre|div|p|li|table|br)$/i.test(e.nodeName);if(!/^br$/i.test(e.nodeName)&&0==e.textContent.length)return;p&&c();for(var g=0;g<e.childNodes.length;g++)u(e.childNodes[g]);/^(pre|p)$/i.test(e.nodeName)&&(l=!0),p&&(o=!0)}else 3==e.nodeType&&h(e.nodeValue.replace(/\u200b/g,"").replace(/\u00a0/g," "))}for(;u(e),e!=r;)e=e.nextSibling,l=!1;return s}(i,r,c,e,l)),f=lt(i.doc,gt(e,0),gt(l,at(i.doc,l).text.length));u.length>1&&f.length>1;)if(Y(u)==Y(f))u.pop(),f.pop(),l--;else{if(u[0]!=f[0])break;u.shift(),f.shift(),e++}for(var d=0,p=0,g=u[0],m=f[0],v=Math.min(g.length,m.length);d<v&&g.charCodeAt(d)==m.charCodeAt(d);)++d;for(var y=Y(u),b=Y(f),x=Math.min(y.length-(1==u.length?d:0),b.length-(1==f.length?d:0));p<x&&y.charCodeAt(y.length-p-1)==b.charCodeAt(b.length-p-1);)++p;if(1==u.length&&1==f.length&&e==o.line)for(;d&&d>o.ch&&y.charCodeAt(y.length-p-1)==b.charCodeAt(b.length-p-1);)d--,p++;u[u.length-1]=y.slice(0,y.length-p).replace(/^\u200b+/,""),u[0]=u[0].slice(d).replace(/\u200b+$/,"");var w=gt(e,d),k=gt(l,f.length?Y(f).length-p:0);return u.length>1||u[0]||mt(w,k)?(cs(i.doc,u,w,k,"+input"),!0):void 0},Vo.prototype.ensurePolled=function(){this.forceCompositionEnd()},Vo.prototype.reset=function(){this.forceCompositionEnd()},Vo.prototype.forceCompositionEnd=function(){this.composing&&(clearTimeout(this.readDOMTimeout),this.composing=null,this.updateFromDOM(),this.div.blur(),this.div.focus())},Vo.prototype.readFromDOMSoon=function(){var t=this;null==this.readDOMTimeout&&(this.readDOMTimeout=setTimeout(function(){if(t.readDOMTimeout=null,t.composing){if(!t.composing.done)return;t.composing=null}t.updateFromDOM()},80))},Vo.prototype.updateFromDOM=function(){var t=this;!this.cm.isReadOnly()&&this.pollContent()||ji(this.cm,function(){return Ji(t.cm)})},Vo.prototype.setUneditable=function(t){t.contentEditable="false"},Vo.prototype.onKeyPress=function(t){0==t.charCode||this.composing||(t.preventDefault(),this.cm.isReadOnly()||Ki(this.cm,Oo)(this.cm,String.fromCharCode(null==t.charCode?t.keyCode:t.charCode),0))},Vo.prototype.readOnlyChanged=function(t){this.div.contentEditable=String("nocursor"!=t)},Vo.prototype.onContextMenu=function(){},Vo.prototype.resetPosition=function(){},Vo.prototype.needsContentAttribute=!0;var Ho=function(t){this.cm=t,this.prevInput="",this.pollingFast=!1,this.polling=new U,this.hasSelection=!1,this.composing=null};Ho.prototype.init=function(t){var e=this,r=this,i=this.cm;this.createField(t);var n=this.textarea;function s(t){if(!ne(i,t)){if(i.somethingSelected())Io({lineWise:!1,text:i.getSelections()});else{if(!i.options.lineWiseCopyCut)return;var e=Ao(i);Io({lineWise:!0,text:e.text}),"cut"==t.type?i.setSelections(e.ranges,null,z):(r.prevInput="",n.value=e.text.join("\n"),P(n))}"cut"==t.type&&(i.state.cutIncoming=!0)}}t.wrapper.insertBefore(this.wrapper,t.wrapper.firstChild),g&&(n.style.width="0px"),te(n,"input",function(){o&&a>=9&&e.hasSelection&&(e.hasSelection=null),r.poll()}),te(n,"paste",function(t){ne(i,t)||Lo(t,i)||(i.state.pasteIncoming=!0,r.fastPoll())}),te(n,"cut",s),te(n,"copy",s),te(t.scroller,"paste",function(e){xr(t,e)||ne(i,e)||(i.state.pasteIncoming=!0,r.focus())}),te(t.lineSpace,"selectstart",function(e){xr(t,e)||le(e)}),te(n,"compositionstart",function(){var t=i.getCursor("from");r.composing&&r.composing.range.clear(),r.composing={start:t,range:i.markText(t,i.getCursor("to"),{className:"CodeMirror-composing"})}}),te(n,"compositionend",function(){r.composing&&(r.poll(),r.composing.range.clear(),r.composing=null)})},Ho.prototype.createField=function(t){this.wrapper=Ro(),this.textarea=this.wrapper.firstChild},Ho.prototype.prepareSelection=function(){var t=this.cm,e=t.display,r=t.doc,i=li(t);if(t.options.moveInputWithCursor){var n=Xr(t,r.sel.primary().head,"div"),s=e.wrapper.getBoundingClientRect(),o=e.lineDiv.getBoundingClientRect();i.teTop=Math.max(0,Math.min(e.wrapper.clientHeight-10,n.top+o.top-s.top)),i.teLeft=Math.max(0,Math.min(e.wrapper.clientWidth-10,n.left+o.left-s.left))}return i},Ho.prototype.showSelection=function(t){var e=this.cm,r=e.display;O(r.cursorDiv,t.cursors),O(r.selectionDiv,t.selection),null!=t.teTop&&(this.wrapper.style.top=t.teTop+"px",this.wrapper.style.left=t.teLeft+"px")},Ho.prototype.reset=function(t){if(!this.contextMenuPending&&!this.composing){var e=this.cm;if(e.somethingSelected()){this.prevInput="";var r=e.getSelection();this.textarea.value=r,e.state.focused&&P(this.textarea),o&&a>=9&&(this.hasSelection=r)}else t||(this.prevInput=this.textarea.value="",o&&a>=9&&(this.hasSelection=null))}},Ho.prototype.getField=function(){return this.textarea},Ho.prototype.supportsTouch=function(){return!1},Ho.prototype.focus=function(){if("nocursor"!=this.cm.options.readOnly&&(!v||D()!=this.textarea))try{this.textarea.focus()}catch(t){}},Ho.prototype.blur=function(){this.textarea.blur()},Ho.prototype.resetPosition=function(){this.wrapper.style.top=this.wrapper.style.left=0},Ho.prototype.receivedFocus=function(){this.slowPoll()},Ho.prototype.slowPoll=function(){var t=this;this.pollingFast||this.polling.set(this.cm.options.pollInterval,function(){t.poll(),t.cm.state.focused&&t.slowPoll()})},Ho.prototype.fastPoll=function(){var t=!1,e=this;e.pollingFast=!0,e.polling.set(20,function r(){var i=e.poll();i||t?(e.pollingFast=!1,e.slowPoll()):(t=!0,e.polling.set(60,r))})},Ho.prototype.poll=function(){var t=this,e=this.cm,r=this.textarea,i=this.prevInput;if(this.contextMenuPending||!e.state.focused||xe(r)&&!i&&!this.composing||e.isReadOnly()||e.options.disableInput||e.state.keySeq)return!1;var n=r.value;if(n==i&&!e.somethingSelected())return!1;if(o&&a>=9&&this.hasSelection===n||y&&/[\uf700-\uf7ff]/.test(n))return e.display.input.reset(),!1;if(e.doc.sel==e.display.selForContextMenu){var s=n.charCodeAt(0);if(8203!=s||i||(i=""),8666==s)return this.reset(),this.cm.execCommand("undo")}for(var l=0,c=Math.min(i.length,n.length);l<c&&i.charCodeAt(l)==n.charCodeAt(l);)++l;return ji(e,function(){Oo(e,n.slice(l),i.length-l,null,t.composing?"*compose":null),n.length>1e3||n.indexOf("\n")>-1?r.value=t.prevInput="":t.prevInput=n,t.composing&&(t.composing.range.clear(),t.composing.range=e.markText(t.composing.start,e.getCursor("to"),{className:"CodeMirror-composing"}))}),!0},Ho.prototype.ensurePolled=function(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)},Ho.prototype.onKeyPress=function(){o&&a>=9&&(this.hasSelection=null),this.fastPoll()},Ho.prototype.onContextMenu=function(t){var e=this,r=e.cm,i=r.display,n=e.textarea,s=si(r,t),c=i.scroller.scrollTop;if(s&&!u){var h=r.options.resetSelectionOnContextMenu;h&&-1==r.doc.sel.contains(s)&&Ki(r,qn)(r.doc,xn(s),z);var f=n.style.cssText,d=e.wrapper.style.cssText;e.wrapper.style.cssText="position: absolute";var p,g=e.wrapper.getBoundingClientRect();if(n.style.cssText="position: absolute; width: 30px; height: 30px;\n top: "+(t.clientY-g.top-5)+"px; left: "+(t.clientX-g.left-5)+"px;\n z-index: 1000; background: "+(o?"rgba(255, 255, 255, .05)":"transparent")+";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",l&&(p=window.scrollY),i.input.focus(),l&&window.scrollTo(null,p),i.input.reset(),r.somethingSelected()||(n.value=e.prevInput=" "),e.contextMenuPending=!0,i.selForContextMenu=r.doc.sel,clearTimeout(i.detectingSelectAll),o&&a>=9&&v(),S){ue(t);var m=function(){re(window,"mouseup",m),setTimeout(y,20)};te(window,"mouseup",m)}else setTimeout(y,50)}function v(){if(null!=n.selectionStart){var t=r.somethingSelected(),s=""+(t?n.value:"");n.value="⇚",n.value=s,e.prevInput=t?"":"",n.selectionStart=1,n.selectionEnd=s.length,i.selForContextMenu=r.doc.sel}}function y(){if(e.contextMenuPending=!1,e.wrapper.style.cssText=d,n.style.cssText=f,o&&a<9&&i.scrollbars.setScrollTop(i.scroller.scrollTop=c),null!=n.selectionStart){(!o||o&&a<9)&&v();var t=0,s=function(){i.selForContextMenu==r.doc.sel&&0==n.selectionStart&&n.selectionEnd>0&&""==e.prevInput?Ki(r,rs)(r):t++<10?i.detectingSelectAll=setTimeout(s,500):(i.selForContextMenu=null,i.input.reset())};i.detectingSelectAll=setTimeout(s,200)}}},Ho.prototype.readOnlyChanged=function(t){t||this.reset(),this.textarea.disabled="nocursor"==t},Ho.prototype.setUneditable=function(){},Ho.prototype.needsContentAttribute=!1,function(t){var e=t.optionHandlers;function r(r,i,n,s){t.defaults[r]=i,n&&(e[r]=s?function(t,e,r){r!=vo&&n(t,e,r)}:n)}t.defineOption=r,t.Init=vo,r("value","",function(t,e){return t.setValue(e)},!0),r("mode",null,function(t,e){t.doc.modeOption=e,Tn(t)},!0),r("indentUnit",2,Tn,!0),r("indentWithTabs",!1),r("smartIndent",!0),r("tabSize",4,function(t){Cn(t),Fr(t),Ji(t)},!0),r("lineSeparator",null,function(t,e){if(t.doc.lineSep=e,e){var r=[],i=t.doc.first;t.doc.iter(function(t){for(var n=0;;){var s=t.text.indexOf(e,n);if(-1==s)break;n=s+e.length,r.push(gt(i,s))}i++});for(var n=r.length-1;n>=0;n--)cs(t.doc,e,r[n],gt(r[n].line,r[n].ch+e.length))}}),r("specialChars",/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff]/g,function(t,e,r){t.state.specialChars=new RegExp(e.source+(e.test("\t")?"":"|\t"),"g"),r!=vo&&t.refresh()}),r("specialCharPlaceholder",Ze,function(t){return t.refresh()},!0),r("electricChars",!0),r("inputStyle",v?"contenteditable":"textarea",function(){throw new Error("inputStyle can not (yet) be changed in a running editor")},!0),r("spellcheck",!1,function(t,e){return t.getInputField().spellcheck=e},!0),r("rtlMoveVisually",!x),r("wholeLineUpdateBefore",!0),r("theme","default",function(t){mo(t),xo(t)},!0),r("keyMap","default",function(t,e,r){var i=_s(e),n=r!=vo&&_s(r);n&&n.detach&&n.detach(t,i),i.attach&&i.attach(t,n||null)}),r("extraKeys",null),r("configureMouse",null),r("lineWrapping",!1,ko,!0),r("gutters",[],function(t){un(t.options),xo(t)},!0),r("fixedGutter",!0,function(t,e){t.display.gutters.style.left=e?ri(t.display)+"px":"0",t.refresh()},!0),r("coverGutterNextToScrollbar",!1,function(t){return Mi(t)},!0),r("scrollbarStyle","native",function(t){Bi(t),Mi(t),t.display.scrollbars.setScrollTop(t.doc.scrollTop),t.display.scrollbars.setScrollLeft(t.doc.scrollLeft)},!0),r("lineNumbers",!1,function(t){un(t.options),xo(t)},!0),r("firstLineNumber",1,xo,!0),r("lineNumberFormatter",function(t){return t},xo,!0),r("showCursorWhenSelecting",!1,ai,!0),r("resetSelectionOnContextMenu",!0),r("lineWiseCopyCut",!0),r("pasteLinesPerSelection",!0),r("readOnly",!1,function(t,e){"nocursor"==e&&(mi(t),t.display.input.blur()),t.display.input.readOnlyChanged(e)}),r("disableInput",!1,function(t,e){e||t.display.input.reset()},!0),r("dragDrop",!0,wo),r("allowDropFileTypes",null),r("cursorBlinkRate",530),r("cursorScrollMargin",0),r("cursorHeight",1,ai,!0),r("singleCursorHeightPerLine",!0,ai,!0),r("workTime",100),r("workDelay",100),r("flattenSpans",!0,Cn,!0),r("addModeClass",!1,Cn,!0),r("pollInterval",100),r("undoDepth",200,function(t,e){return t.doc.history.undoDepth=e}),r("historyEventDelay",1250),r("viewportMargin",10,function(t){return t.refresh()},!0),r("maxHighlightLength",1e4,Cn,!0),r("moveInputWithCursor",!0,function(t,e){e||t.display.input.resetPosition()}),r("tabindex",null,function(t,e){return t.display.input.getField().tabIndex=e||""}),r("autofocus",null),r("direction","ltr",function(t,e){return t.doc.setDirection(e)},!0),r("phrases",null)}(So),function(t){var e=t.optionHandlers,r=t.helpers={};t.prototype={constructor:t,focus:function(){window.focus(),this.display.input.focus()},setOption:function(t,r){var i=this.options,n=i[t];i[t]==r&&"mode"!=t||(i[t]=r,e.hasOwnProperty(t)&&Ki(this,e[t])(this,r,n),ie(this,"optionChange",this,t))},getOption:function(t){return this.options[t]},getDoc:function(){return this.doc},addKeyMap:function(t,e){this.state.keyMaps[e?"push":"unshift"](_s(t))},removeKeyMap:function(t){for(var e=this.state.keyMaps,r=0;r<e.length;++r)if(e[r]==t||e[r].name==t)return e.splice(r,1),!0},addOverlay:qi(function(e,r){var i=e.token?e:t.getMode(this.options,e);if(i.startState)throw new Error("Overlays may not be stateful.");!function(t,e,r){for(var i=0,n=r(e);i<t.length&&r(t[i])<=n;)i++;t.splice(i,0,e)}(this.state.overlays,{mode:i,modeSpec:e,opaque:r&&r.opaque,priority:r&&r.priority||0},function(t){return t.priority}),this.state.modeGen++,Ji(this)}),removeOverlay:qi(function(t){for(var e=this.state.overlays,r=0;r<e.length;++r){var i=e[r].modeSpec;if(i==t||"string"==typeof t&&i.name==t)return e.splice(r,1),this.state.modeGen++,void Ji(this)}}),indentLine:qi(function(t,e,r){"string"!=typeof e&&"number"!=typeof e&&(e=null==e?this.options.smartIndent?"smart":"prev":e?"add":"subtract"),dt(this.doc,t)&&To(this,t,e,r)}),indentSelection:qi(function(t){for(var e=this.doc.sel.ranges,r=-1,i=0;i<e.length;i++){var n=e[i];if(n.empty())n.head.line>r&&(To(this,n.head.line,t,!0),r=n.head.line,i==this.doc.sel.primIndex&&Ei(this));else{var s=n.from(),o=n.to(),a=Math.max(r,s.line);r=Math.min(this.lastLine(),o.line-(o.ch?0:1))+1;for(var l=a;l<r;++l)To(this,l,t);var c=this.doc.sel.ranges;0==s.ch&&e.length==c.length&&c[i].from().ch>0&&Xn(this.doc,i,new yn(s,c[i].to()),z)}}}),getTokenAt:function(t,e){return Ge(this,t,e)},getLineTokens:function(t,e){return Ge(this,gt(t),e,!0)},getTokenTypeAt:function(t){t=kt(this.doc,t);var e,r=Ve(this,at(this.doc,t.line)),i=0,n=(r.length-1)/2,s=t.ch;if(0==s)e=r[2];else for(;;){var o=i+n>>1;if((o?r[2*o-1]:0)>=s)n=o;else{if(!(r[2*o+1]<s)){e=r[2*o+2];break}i=o+1}}var a=e?e.indexOf("overlay "):-1;return a<0?e:0==a?null:e.slice(0,a-1)},getModeAt:function(e){var r=this.doc.mode;return r.innerMode?t.innerMode(r,this.getTokenAt(e).state).mode:r},getHelper:function(t,e){return this.getHelpers(t,e)[0]},getHelpers:function(t,e){var i=[];if(!r.hasOwnProperty(e))return i;var n=r[e],s=this.getModeAt(t);if("string"==typeof s[e])n[s[e]]&&i.push(n[s[e]]);else if(s[e])for(var o=0;o<s[e].length;o++){var a=n[s[e][o]];a&&i.push(a)}else s.helperType&&n[s.helperType]?i.push(n[s.helperType]):n[s.name]&&i.push(n[s.name]);for(var l=0;l<n._global.length;l++){var c=n._global[l];c.pred(s,this)&&-1==W(i,c.val)&&i.push(c.val)}return i},getStateAfter:function(t,e){var r=this.doc;return Be(this,(t=wt(r,null==t?r.first+r.size-1:t))+1,e).state},cursorCoords:function(t,e){var r=this.doc.sel.primary();return Xr(this,null==t?r.head:"object"==typeof t?kt(this.doc,t):t?r.from():r.to(),e||"page")},charCoords:function(t,e){return _r(this,kt(this.doc,t),e||"page")},coordsChar:function(t,e){return qr(this,(t=zr(this,t,e||"page")).left,t.top)},lineAtHeight:function(t,e){return t=zr(this,{top:t,left:0},e||"page").top,ft(this.doc,t+this.display.viewOffset)},heightAtLine:function(t,e,r){var i,n=!1;if("number"==typeof t){var s=this.doc.first+this.doc.size-1;t<this.doc.first?t=this.doc.first:t>s&&(t=s,n=!0),i=at(this.doc,t)}else i=t;return Gr(this,i,{top:0,left:0},e||"page",r||n).top+(n?this.doc.height-jt(i):0)},defaultTextHeight:function(){return $r(this.display)},defaultCharWidth:function(){return ti(this.display)},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(t,e,r,i,n){var s=this.display,o=(t=Xr(this,kt(this.doc,t))).bottom,a=t.left;if(e.style.position="absolute",e.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(e),s.sizer.appendChild(e),"over"==i)o=t.top;else if("above"==i||"near"==i){var l=Math.max(s.wrapper.clientHeight,this.doc.height),c=Math.max(s.sizer.clientWidth,s.lineSpace.clientWidth);("above"==i||t.bottom+e.offsetHeight>l)&&t.top>e.offsetHeight?o=t.top-e.offsetHeight:t.bottom+e.offsetHeight<=l&&(o=t.bottom),a+e.offsetWidth>c&&(a=c-e.offsetWidth)}e.style.top=o+"px",e.style.left=e.style.right="","right"==n?(a=s.sizer.clientWidth-e.offsetWidth,e.style.right="0px"):("left"==n?a=0:"middle"==n&&(a=(s.sizer.clientWidth-e.offsetWidth)/2),e.style.left=a+"px"),r&&function(t,e){var r=ki(t,e);null!=r.scrollTop&&Oi(t,r.scrollTop),null!=r.scrollLeft&&Ni(t,r.scrollLeft)}(this,{left:a,top:o,right:a+e.offsetWidth,bottom:o+e.offsetHeight})},triggerOnKeyDown:qi(no),triggerOnKeyPress:qi(oo),triggerOnKeyUp:so,triggerOnMouseDown:qi(ho),execCommand:function(t){if(Ys.hasOwnProperty(t))return Ys[t].call(null,this)},triggerElectric:qi(function(t){No(this,t)}),findPosH:function(t,e,r,i){var n=1;e<0&&(n=-1,e=-e);for(var s=kt(this.doc,t),o=0;o<e&&!(s=Mo(this.doc,s,n,r,i)).hitSide;++o);return s},moveH:qi(function(t,e){var r=this;this.extendSelectionsBy(function(i){return r.display.shift||r.doc.extend||i.empty()?Mo(r.doc,i.head,t,e,r.options.rtlMoveVisually):t<0?i.from():i.to()},X)}),deleteH:qi(function(t,e){var r=this.doc.sel,i=this.doc;r.somethingSelected()?i.replaceSelection("",null,"+delete"):Xs(this,function(r){var n=Mo(i,r.head,t,e,!1);return t<0?{from:n,to:r.head}:{from:r.head,to:n}})}),findPosV:function(t,e,r,i){var n=1,s=i;e<0&&(n=-1,e=-e);for(var o=kt(this.doc,t),a=0;a<e;++a){var l=Xr(this,o,"div");if(null==s?s=l.left:l.left=s,(o=Po(this,l,n,r)).hitSide)break}return o},moveV:qi(function(t,e){var r=this,i=this.doc,n=[],s=!this.display.shift&&!i.extend&&i.sel.somethingSelected();if(i.extendSelectionsBy(function(o){if(s)return t<0?o.from():o.to();var a=Xr(r,o.head,"div");null!=o.goalColumn&&(a.left=o.goalColumn),n.push(a.left);var l=Po(r,a,t,e);return"page"==e&&o==i.sel.primary()&&Si(r,_r(r,l,"div").top-a.top),l},X),n.length)for(var o=0;o<i.sel.ranges.length;o++)i.sel.ranges[o].goalColumn=n[o]}),findWordAt:function(t){var e=this.doc,r=at(e,t.line).text,i=t.ch,n=t.ch;if(r){var s=this.getHelper(t,"wordChars");"before"!=t.sticky&&n!=r.length||!i?++n:--i;for(var o=r.charAt(i),a=et(o,s)?function(t){return et(t,s)}:/\s/.test(o)?function(t){return/\s/.test(t)}:function(t){return!/\s/.test(t)&&!et(t)};i>0&&a(r.charAt(i-1));)--i;for(;n<r.length&&a(r.charAt(n));)++n}return new yn(gt(t.line,i),gt(t.line,n))},toggleOverwrite:function(t){null!=t&&t==this.state.overwrite||((this.state.overwrite=!this.state.overwrite)?R(this.display.cursorDiv,"CodeMirror-overwrite"):C(this.display.cursorDiv,"CodeMirror-overwrite"),ie(this,"overwriteToggle",this,this.state.overwrite))},hasFocus:function(){return this.display.input.getField()==D()},isReadOnly:function(){return!(!this.options.readOnly&&!this.doc.cantEdit)},scrollTo:qi(function(t,e){Ti(this,t,e)}),getScrollInfo:function(){var t=this.display.scroller;return{left:t.scrollLeft,top:t.scrollTop,height:t.scrollHeight-Er(this)-this.display.barHeight,width:t.scrollWidth-Er(this)-this.display.barWidth,clientHeight:Cr(this),clientWidth:Tr(this)}},scrollIntoView:qi(function(t,e){null==t?(t={from:this.doc.sel.primary().head,to:null},null==e&&(e=this.options.cursorScrollMargin)):"number"==typeof t?t={from:gt(t,0),to:null}:null==t.from&&(t={from:t,to:null}),t.to||(t.to=t.from),t.margin=e||0,null!=t.from.line?function(t,e){Ci(t),t.curOp.scrollToPos=e}(this,t):Ii(this,t.from,t.to,t.margin)}),setSize:qi(function(t,e){var r=this,i=function(t){return"number"==typeof t||/^\d+$/.test(String(t))?t+"px":t};null!=t&&(this.display.wrapper.style.width=i(t)),null!=e&&(this.display.wrapper.style.height=i(e)),this.options.lineWrapping&&Br(this);var n=this.display.viewFrom;this.doc.iter(n,this.display.viewTo,function(t){if(t.widgets)for(var e=0;e<t.widgets.length;e++)if(t.widgets[e].noHScroll){Zi(r,n,"widget");break}++n}),this.curOp.forceUpdate=!0,ie(this,"refresh",this)}),operation:function(t){return ji(this,t)},startOperation:function(){return Ui(this)},endOperation:function(){return Wi(this)},refresh:qi(function(){var t=this.display.cachedTextHeight;Ji(this),this.curOp.forceUpdate=!0,Fr(this),Ti(this,this.doc.scrollLeft,this.doc.scrollTop),ln(this),(null==t||Math.abs(t-$r(this.display))>.5)&&ni(this),ie(this,"refresh",this)}),swapDoc:qi(function(t){var e=this.doc;return e.cm=null,Nn(this,t),Fr(this),this.display.input.reset(),Ti(this,t.scrollLeft,t.scrollTop),this.curOp.forceScroll=!0,or(this,"swapDoc",this,e),e}),phrase:function(t){var e=this.options.phrases;return e&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:t},getInputField:function(){return this.display.input.getField()},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}},ae(t),t.registerHelper=function(e,i,n){r.hasOwnProperty(e)||(r[e]=t[e]={_global:[]}),r[e][i]=n},t.registerGlobalHelper=function(e,i,n,s){t.registerHelper(e,i,s),r[e]._global.push({pred:n,val:s})}}(So);var Go="iter insert remove copy getEditor constructor".split(" ");for(var zo in Ts.prototype)Ts.prototype.hasOwnProperty(zo)&&W(Go,zo)<0&&(So.prototype[zo]=function(t){return function(){return t.apply(this.doc,arguments)}}(Ts.prototype[zo]));return ae(Ts),So.inputStyles={textarea:Ho,contenteditable:Vo},So.defineMode=function(t){So.defaults.mode||"null"==t||(So.defaults.mode=t),function(t,e){arguments.length>2&&(e.dependencies=Array.prototype.slice.call(arguments,2)),Se[t]=e}.apply(this,arguments)},So.defineMIME=function(t,e){Ee[t]=e},So.defineMode("null",function(){return{token:function(t){return t.skipToEnd()}}}),So.defineMIME("text/plain","null"),So.defineExtension=function(t,e){So.prototype[t]=e},So.defineDocExtension=function(t,e){Ts.prototype[t]=e},So.fromTextArea=function(t,e){if((e=e?B(e):{}).value=t.value,!e.tabindex&&t.tabIndex&&(e.tabindex=t.tabIndex),!e.placeholder&&t.placeholder&&(e.placeholder=t.placeholder),null==e.autofocus){var r=D();e.autofocus=r==t||null!=t.getAttribute("autofocus")&&r==document.body}function i(){t.value=a.getValue()}var n;if(t.form&&(te(t.form,"submit",i),!e.leaveSubmitMethodAlone)){var s=t.form;n=s.submit;try{var o=s.submit=function(){i(),s.submit=n,s.submit(),s.submit=o}}catch(t){}}e.finishInit=function(e){e.save=i,e.getTextArea=function(){return t},e.toTextArea=function(){e.toTextArea=isNaN,i(),t.parentNode.removeChild(e.getWrapperElement()),t.style.display="",t.form&&(re(t.form,"submit",i),"function"==typeof t.form.submit&&(t.form.submit=n))}},t.style.display="none";var a=So(function(e){return t.parentNode.insertBefore(e,t.nextSibling)},e);return a},function(t){t.off=re,t.on=te,t.wheelEventPixels=gn,t.Doc=Ts,t.splitLines=be,t.countColumn=F,t.findColumn=j,t.isWordChar=tt,t.Pass=G,t.signal=ie,t.Line=Xe,t.changeEnd=wn,t.scrollbarModel=Vi,t.Pos=gt,t.cmpPos=mt,t.modes=Se,t.mimeModes=Ee,t.resolveMode=Te,t.getMode=Ce,t.modeExtensions=Ie,t.extendMode=Oe,t.copyState=Le,t.startState=Ae,t.innerMode=Ne,t.commands=Ys,t.keyMap=Bs,t.keyName=zs,t.isModifierKey=Hs,t.lookupKey=Ws,t.normalizeKeyMap=Us,t.StringStream=De,t.SharedTextMarker=ws,t.TextMarker=bs,t.LineWidget=ms,t.e_preventDefault=le,t.e_stopPropagation=ce,t.e_stop=ue,t.addClass=R,t.contains=A,t.rmClass=C,t.keyNames=Rs}(So),So.version="5.40.0",So}()},function(t,e,r){"use strict";(function(e){
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
* @license MIT
*/
function i(t,e){if(t===e)return 0;for(var r=t.length,i=e.length,n=0,s=Math.min(r,i);n<s;++n)if(t[n]!==e[n]){r=t[n],i=e[n];break}return r<i?-1:i<r?1:0}function n(t){return e.Buffer&&"function"==typeof e.Buffer.isBuffer?e.Buffer.isBuffer(t):!(null==t||!t._isBuffer)}var s=r(3),o=Object.prototype.hasOwnProperty,a=Array.prototype.slice,l="foo"===function(){}.name;function c(t){return Object.prototype.toString.call(t)}function h(t){return!n(t)&&("function"==typeof e.ArrayBuffer&&("function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):!!t&&(t instanceof DataView||!!(t.buffer&&t.buffer instanceof ArrayBuffer))))}var u=t.exports=v,f=/\s*function\s+([^\(\s]*)\s*/;function d(t){if(s.isFunction(t)){if(l)return t.name;var e=t.toString().match(f);return e&&e[1]}}function p(t,e){return"string"==typeof t?t.length<e?t:t.slice(0,e):t}function g(t){if(l||!s.isFunction(t))return s.inspect(t);var e=d(t);return"[Function"+(e?": "+e:"")+"]"}function m(t,e,r,i,n){throw new u.AssertionError({message:r,actual:t,expected:e,operator:i,stackStartFunction:n})}function v(t,e){t||m(t,!0,e,"==",u.ok)}function y(t,e,r,o){if(t===e)return!0;if(n(t)&&n(e))return 0===i(t,e);if(s.isDate(t)&&s.isDate(e))return t.getTime()===e.getTime();if(s.isRegExp(t)&&s.isRegExp(e))return t.source===e.source&&t.global===e.global&&t.multiline===e.multiline&&t.lastIndex===e.lastIndex&&t.ignoreCase===e.ignoreCase;if(null!==t&&"object"==typeof t||null!==e&&"object"==typeof e){if(h(t)&&h(e)&&c(t)===c(e)&&!(t instanceof Float32Array||t instanceof Float64Array))return 0===i(new Uint8Array(t.buffer),new Uint8Array(e.buffer));if(n(t)!==n(e))return!1;var l=(o=o||{actual:[],expected:[]}).actual.indexOf(t);return-1!==l&&l===o.expected.indexOf(e)||(o.actual.push(t),o.expected.push(e),function(t,e,r,i){if(null===t||void 0===t||null===e||void 0===e)return!1;if(s.isPrimitive(t)||s.isPrimitive(e))return t===e;if(r&&Object.getPrototypeOf(t)!==Object.getPrototypeOf(e))return!1;var n=b(t),o=b(e);if(n&&!o||!n&&o)return!1;if(n)return t=a.call(t),e=a.call(e),y(t,e,r);var l,c,h=k(t),u=k(e);if(h.length!==u.length)return!1;for(h.sort(),u.sort(),c=h.length-1;c>=0;c--)if(h[c]!==u[c])return!1;for(c=h.length-1;c>=0;c--)if(l=h[c],!y(t[l],e[l],r,i))return!1;return!0}(t,e,r,o))}return r?t===e:t==e}function b(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function x(t,e){if(!t||!e)return!1;if("[object RegExp]"==Object.prototype.toString.call(e))return e.test(t);try{if(t instanceof e)return!0}catch(t){}return!Error.isPrototypeOf(e)&&!0===e.call({},t)}function w(t,e,r,i){var n;if("function"!=typeof e)throw new TypeError('"block" argument must be a function');"string"==typeof r&&(i=r,r=null),n=function(t){var e;try{t()}catch(t){e=t}return e}(e),i=(r&&r.name?" ("+r.name+").":".")+(i?" "+i:"."),t&&!n&&m(n,r,"Missing expected exception"+i);var o="string"==typeof i,a=!t&&s.isError(n),l=!t&&n&&!r;if((a&&o&&x(n,r)||l)&&m(n,r,"Got unwanted exception"+i),t&&n&&r&&!x(n,r)||!t&&n)throw n}u.AssertionError=function(t){this.name="AssertionError",this.actual=t.actual,this.expected=t.expected,this.operator=t.operator,t.message?(this.message=t.message,this.generatedMessage=!1):(this.message=function(t){return p(g(t.actual),128)+" "+t.operator+" "+p(g(t.expected),128)}(this),this.generatedMessage=!0);var e=t.stackStartFunction||m;if(Error.captureStackTrace)Error.captureStackTrace(this,e);else{var r=new Error;if(r.stack){var i=r.stack,n=d(e),s=i.indexOf("\n"+n);if(s>=0){var o=i.indexOf("\n",s+1);i=i.substring(o+1)}this.stack=i}}},s.inherits(u.AssertionError,Error),u.fail=m,u.ok=v,u.equal=function(t,e,r){t!=e&&m(t,e,r,"==",u.equal)},u.notEqual=function(t,e,r){t==e&&m(t,e,r,"!=",u.notEqual)},u.deepEqual=function(t,e,r){y(t,e,!1)||m(t,e,r,"deepEqual",u.deepEqual)},u.deepStrictEqual=function(t,e,r){y(t,e,!0)||m(t,e,r,"deepStrictEqual",u.deepStrictEqual)},u.notDeepEqual=function(t,e,r){y(t,e,!1)&&m(t,e,r,"notDeepEqual",u.notDeepEqual)},u.notDeepStrictEqual=function t(e,r,i){y(e,r,!0)&&m(e,r,i,"notDeepStrictEqual",t)},u.strictEqual=function(t,e,r){t!==e&&m(t,e,r,"===",u.strictEqual)},u.notStrictEqual=function(t,e,r){t===e&&m(t,e,r,"!==",u.notStrictEqual)},u.throws=function(t,e,r){w(!0,t,e,r)},u.doesNotThrow=function(t,e,r){w(!1,t,e,r)},u.ifError=function(t){if(t)throw t};var k=Object.keys||function(t){var e=[];for(var r in t)o.call(t,r)&&e.push(r);return e}}).call(this,r(2))},function(t,e){var r;r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){(function(t,i){var n=/%[sdj%]/g;e.format=function(t){if(!v(t)){for(var e=[],r=0;r<arguments.length;r++)e.push(a(arguments[r]));return e.join(" ")}r=1;for(var i=arguments,s=i.length,o=String(t).replace(n,function(t){if("%%"===t)return"%";if(r>=s)return t;switch(t){case"%s":return String(i[r++]);case"%d":return Number(i[r++]);case"%j":try{return JSON.stringify(i[r++])}catch(t){return"[Circular]"}default:return t}}),l=i[r];r<s;l=i[++r])g(l)||!x(l)?o+=" "+l:o+=" "+a(l);return o},e.deprecate=function(r,n){if(y(t.process))return function(){return e.deprecate(r,n).apply(this,arguments)};if(!0===i.noDeprecation)return r;var s=!1;return function(){if(!s){if(i.throwDeprecation)throw new Error(n);i.traceDeprecation?console.trace(n):console.error(n),s=!0}return r.apply(this,arguments)}};var s,o={};function a(t,r){var i={seen:[],stylize:c};return arguments.length>=3&&(i.depth=arguments[2]),arguments.length>=4&&(i.colors=arguments[3]),p(r)?i.showHidden=r:r&&e._extend(i,r),y(i.showHidden)&&(i.showHidden=!1),y(i.depth)&&(i.depth=2),y(i.colors)&&(i.colors=!1),y(i.customInspect)&&(i.customInspect=!0),i.colors&&(i.stylize=l),h(i,t,i.depth)}function l(t,e){var r=a.styles[e];return r?"["+a.colors[r][0]+"m"+t+"["+a.colors[r][1]+"m":t}function c(t,e){return t}function h(t,r,i){if(t.customInspect&&r&&S(r.inspect)&&r.inspect!==e.inspect&&(!r.constructor||r.constructor.prototype!==r)){var n=r.inspect(i,t);return v(n)||(n=h(t,n,i)),n}var s=function(t,e){if(y(e))return t.stylize("undefined","undefined");if(v(e)){var r="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(r,"string")}if(m(e))return t.stylize(""+e,"number");if(p(e))return t.stylize(""+e,"boolean");if(g(e))return t.stylize("null","null")}(t,r);if(s)return s;var o=Object.keys(r),a=function(t){var e={};return t.forEach(function(t,r){e[t]=!0}),e}(o);if(t.showHidden&&(o=Object.getOwnPropertyNames(r)),k(r)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return u(r);if(0===o.length){if(S(r)){var l=r.name?": "+r.name:"";return t.stylize("[Function"+l+"]","special")}if(b(r))return t.stylize(RegExp.prototype.toString.call(r),"regexp");if(w(r))return t.stylize(Date.prototype.toString.call(r),"date");if(k(r))return u(r)}var c,x="",E=!1,T=["{","}"];(d(r)&&(E=!0,T=["[","]"]),S(r))&&(x=" [Function"+(r.name?": "+r.name:"")+"]");return b(r)&&(x=" "+RegExp.prototype.toString.call(r)),w(r)&&(x=" "+Date.prototype.toUTCString.call(r)),k(r)&&(x=" "+u(r)),0!==o.length||E&&0!=r.length?i<0?b(r)?t.stylize(RegExp.prototype.toString.call(r),"regexp"):t.stylize("[Object]","special"):(t.seen.push(r),c=E?function(t,e,r,i,n){for(var s=[],o=0,a=e.length;o<a;++o)I(e,String(o))?s.push(f(t,e,r,i,String(o),!0)):s.push("");return n.forEach(function(n){n.match(/^\d+$/)||s.push(f(t,e,r,i,n,!0))}),s}(t,r,i,a,o):o.map(function(e){return f(t,r,i,a,e,E)}),t.seen.pop(),function(t,e,r){if(t.reduce(function(t,e){return 0,e.indexOf("\n")>=0&&0,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60)return r[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+r[1];return r[0]+e+" "+t.join(", ")+" "+r[1]}(c,x,T)):T[0]+x+T[1]}function u(t){return"["+Error.prototype.toString.call(t)+"]"}function f(t,e,r,i,n,s){var o,a,l;if((l=Object.getOwnPropertyDescriptor(e,n)||{value:e[n]}).get?a=l.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):l.set&&(a=t.stylize("[Setter]","special")),I(i,n)||(o="["+n+"]"),a||(t.seen.indexOf(l.value)<0?(a=g(r)?h(t,l.value,null):h(t,l.value,r-1)).indexOf("\n")>-1&&(a=s?a.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+a.split("\n").map(function(t){return" "+t}).join("\n")):a=t.stylize("[Circular]","special")),y(o)){if(s&&n.match(/^\d+$/))return a;(o=JSON.stringify(""+n)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(o=o.substr(1,o.length-2),o=t.stylize(o,"name")):(o=o.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),o=t.stylize(o,"string"))}return o+": "+a}function d(t){return Array.isArray(t)}function p(t){return"boolean"==typeof t}function g(t){return null===t}function m(t){return"number"==typeof t}function v(t){return"string"==typeof t}function y(t){return void 0===t}function b(t){return x(t)&&"[object RegExp]"===E(t)}function x(t){return"object"==typeof t&&null!==t}function w(t){return x(t)&&"[object Date]"===E(t)}function k(t){return x(t)&&("[object Error]"===E(t)||t instanceof Error)}function S(t){return"function"==typeof t}function E(t){return Object.prototype.toString.call(t)}function T(t){return t<10?"0"+t.toString(10):t.toString(10)}e.debuglog=function(t){if(y(s)&&(s=i.env.NODE_DEBUG||""),t=t.toUpperCase(),!o[t])if(new RegExp("\\b"+t+"\\b","i").test(s)){var r=i.pid;o[t]=function(){var i=e.format.apply(e,arguments);console.error("%s %d: %s",t,r,i)}}else o[t]=function(){};return o[t]},e.inspect=a,a.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},a.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},e.isArray=d,e.isBoolean=p,e.isNull=g,e.isNullOrUndefined=function(t){return null==t},e.isNumber=m,e.isString=v,e.isSymbol=function(t){return"symbol"==typeof t},e.isUndefined=y,e.isRegExp=b,e.isObject=x,e.isDate=w,e.isError=k,e.isFunction=S,e.isPrimitive=function(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||void 0===t},e.isBuffer=r(5);var C=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function I(t,e){return Object.prototype.hasOwnProperty.call(t,e)}e.log=function(){console.log("%s - %s",function(){var t=new Date,e=[T(t.getHours()),T(t.getMinutes()),T(t.getSeconds())].join(":");return[t.getDate(),C[t.getMonth()],e].join(" ")}(),e.format.apply(e,arguments))},e.inherits=r(6),e._extend=function(t,e){if(!e||!x(e))return t;for(var r=Object.keys(e),i=r.length;i--;)t[r[i]]=e[r[i]];return t}}).call(this,r(2),r(4))},function(t,e){var r,i,n=t.exports={};function s(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function a(t){if(r===setTimeout)return setTimeout(t,0);if((r===s||!r)&&setTimeout)return r=setTimeout,setTimeout(t,0);try{return r(t,0)}catch(e){try{return r.call(null,t,0)}catch(e){return r.call(this,t,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:s}catch(t){r=s}try{i="function"==typeof clearTimeout?clearTimeout:o}catch(t){i=o}}();var l,c=[],h=!1,u=-1;function f(){h&&l&&(h=!1,l.length?c=l.concat(c):u=-1,c.length&&d())}function d(){if(!h){var t=a(f);h=!0;for(var e=c.length;e;){for(l=c,c=[];++u<e;)l&&l[u].run();u=-1,e=c.length}l=null,h=!1,function(t){if(i===clearTimeout)return clearTimeout(t);if((i===o||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(t);try{i(t)}catch(e){try{return i.call(null,t)}catch(e){return i.call(this,t)}}}(t)}}function p(t,e){this.fun=t,this.array=e}function g(){}n.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];c.push(new p(t,e)),1!==c.length||h||a(d)},p.prototype.run=function(){this.fun.apply(null,this.array)},n.title="browser",n.browser=!0,n.env={},n.argv=[],n.version="",n.versions={},n.on=g,n.addListener=g,n.once=g,n.off=g,n.removeListener=g,n.removeAllListeners=g,n.emit=g,n.prependListener=g,n.prependOnceListener=g,n.listeners=function(t){return[]},n.binding=function(t){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(t){throw new Error("process.chdir is not supported")},n.umask=function(){return 0}},function(t,e){t.exports=function(t){return t&&"object"==typeof t&&"function"==typeof t.copy&&"function"==typeof t.fill&&"function"==typeof t.readUInt8}},function(t,e){"function"==typeof Object.create?t.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}},function(t,e,r){!function(t){"use strict";var e="CodeMirror-lint-markers";function r(t){t.parentNode&&t.parentNode.removeChild(t)}function i(e,i,n){var s=function(e,r){var i=document.createElement("div");function n(e){if(!i.parentNode)return t.off(document,"mousemove",n);i.style.top=Math.max(0,e.clientY-i.offsetHeight-5)+"px",i.style.left=e.clientX+5+"px"}return i.className="CodeMirror-lint-tooltip",i.appendChild(r.cloneNode(!0)),document.body.appendChild(i),t.on(document,"mousemove",n),n(e),null!=i.style.opacity&&(i.style.opacity=1),i}(e,i);function o(){t.off(n,"mouseout",o),s&&(function(t){t.parentNode&&(null==t.style.opacity&&r(t),t.style.opacity=0,setTimeout(function(){r(t)},600))}(s),s=null)}var a=setInterval(function(){if(s)for(var t=n;;t=t.parentNode){if(t&&11==t.nodeType&&(t=t.host),t==document.body)return;if(!t){o();break}}if(!s)return clearInterval(a)},400);t.on(n,"mouseout",o)}function n(t,e,r){this.marked=[],this.options=e,this.timeout=null,this.hasGutter=r,this.onMouseOver=function(e){!function(t,e){var r=e.target||e.srcElement;if(/\bCodeMirror-lint-mark-/.test(r.className)){for(var n=r.getBoundingClientRect(),s=(n.left+n.right)/2,o=(n.top+n.bottom)/2,a=t.findMarksAt(t.coordsChar({left:s,top:o},"client")),c=[],h=0;h<a.length;++h){var u=a[h].__annotation;u&&c.push(u)}c.length&&function(t,e){for(var r=e.target||e.srcElement,n=document.createDocumentFragment(),s=0;s<t.length;s++){var o=t[s];n.appendChild(l(o))}i(e,n,r)}(c,e)}}(t,e)},this.waitingFor=0}function s(t){var r=t.state.lint;r.hasGutter&&t.clearGutter(e);for(var i=0;i<r.marked.length;++i)r.marked[i].clear();r.marked.length=0}function o(e,r,n,s){var o=document.createElement("div"),a=o;return o.className="CodeMirror-lint-marker-"+r,n&&((a=o.appendChild(document.createElement("div"))).className="CodeMirror-lint-marker-multiple"),0!=s&&t.on(a,"mouseover",function(t){i(t,e,a)}),o}function a(t,e){return"error"==t?t:e}function l(t){var e=t.severity;e||(e="error");var r=document.createElement("div");return r.className="CodeMirror-lint-message-"+e,void 0!==t.messageHTML?r.innerHTML=t.messageHTML:r.appendChild(document.createTextNode(t.message)),r}function c(e){var r=e.state.lint,i=r.options,n=i.options||i,s=i.getAnnotations||e.getHelper(t.Pos(0,0),"lint");if(s)if(i.async||s.async)!function(e,r,i){var n=e.state.lint,s=++n.waitingFor;function o(){s=-1,e.off("change",o)}e.on("change",o),r(e.getValue(),function(r,i){e.off("change",o),n.waitingFor==s&&(i&&r instanceof t&&(r=i),e.operation(function(){h(e,r)}))},i,e)}(e,s,n);else{var o=s(e.getValue(),n,e);if(!o)return;o.then?o.then(function(t){e.operation(function(){h(e,t)})}):e.operation(function(){h(e,o)})}}function h(t,r){s(t);for(var i=t.state.lint,n=i.options,c=function(t){for(var e=[],r=0;r<t.length;++r){var i=t[r],n=i.from.line;(e[n]||(e[n]=[])).push(i)}return e}(r),h=0;h<c.length;++h){var u=c[h];if(u){for(var f=null,d=i.hasGutter&&document.createDocumentFragment(),p=0;p<u.length;++p){var g=u[p],m=g.severity;m||(m="error"),f=a(f,m),n.formatAnnotation&&(g=n.formatAnnotation(g)),i.hasGutter&&d.appendChild(l(g)),g.to&&i.marked.push(t.markText(g.from,g.to,{className:"CodeMirror-lint-mark-"+m,__annotation:g}))}i.hasGutter&&t.setGutterMarker(h,e,o(d,f,u.length>1,i.options.tooltips))}}n.onUpdateLinting&&n.onUpdateLinting(r,c,t)}function u(t){var e=t.state.lint;e&&(clearTimeout(e.timeout),e.timeout=setTimeout(function(){c(t)},e.options.delay||500))}t.defineOption("lint",!1,function(r,i,o){if(o&&o!=t.Init&&(s(r),!1!==r.state.lint.options.lintOnChange&&r.off("change",u),t.off(r.getWrapperElement(),"mouseover",r.state.lint.onMouseOver),clearTimeout(r.state.lint.timeout),delete r.state.lint),i){for(var a=r.getOption("gutters"),l=!1,h=0;h<a.length;++h)a[h]==e&&(l=!0);var f=r.state.lint=new n(r,function(t,e){return e instanceof Function?{getAnnotations:e}:(e&&!0!==e||(e={}),e)}(0,i),l);!1!==f.options.lintOnChange&&r.on("change",u),0!=f.options.tooltips&&"gutter"!=f.options.tooltips&&t.on(r.getWrapperElement(),"mouseover",f.onMouseOver),c(r)}}),t.defineExtension("performLint",function(){this.state.lint&&c(this)})}(r(0))},function(t,e,r){!function(t){"use strict";function e(t,e){if(!t.hasOwnProperty(e))throw new Error("Undefined state "+e+" in simple mode")}function r(t,e){if(!t)return/(?:)/;var r="";return t instanceof RegExp?(t.ignoreCase&&(r="i"),t=t.source):t=String(t),new RegExp((!1===e?"":"^")+"(?:"+t+")",r)}function i(t,i){(t.next||t.push)&&e(i,t.next||t.push),this.regex=r(t.regex),this.token=function(t){if(!t)return null;if(t.apply)return t;if("string"==typeof t)return t.replace(/\./g," ");for(var e=[],r=0;r<t.length;r++)e.push(t[r]&&t[r].replace(/\./g," "));return e}(t.token),this.data=t}function n(t,e){if(t===e)return!0;if(!t||"object"!=typeof t||!e||"object"!=typeof e)return!1;var r=0;for(var i in t)if(t.hasOwnProperty(i)){if(!e.hasOwnProperty(i)||!n(t[i],e[i]))return!1;r++}for(var i in e)e.hasOwnProperty(i)&&r--;return 0==r}function s(e,i,s,o){var a;if(s.persistent)for(var l=i.persistentStates;l&&!a;l=l.next)(s.spec?n(s.spec,l.spec):s.mode==l.mode)&&(a=l);var c=a?a.mode:s.mode||t.getMode(e,s.spec),h=a?a.state:t.startState(c);s.persistent&&!a&&(i.persistentStates={mode:c,spec:s.spec,state:h,next:i.persistentStates}),i.localState=h,i.local={mode:c,end:s.end&&r(s.end),endScan:s.end&&!1!==s.forceEnd&&r(s.end,!1),endToken:o&&o.join?o[o.length-1]:o}}t.defineSimpleMode=function(e,r){t.defineMode(e,function(e){return t.simpleMode(e,r)})},t.simpleMode=function(r,n){e(n,"start");var o={},a=n.meta||{},l=!1;for(var c in n)if(c!=a&&n.hasOwnProperty(c))for(var h=o[c]=[],u=n[c],f=0;f<u.length;f++){var d=u[f];h.push(new i(d,n)),(d.indent||d.dedent)&&(l=!0)}var p={startState:function(){return{state:"start",pending:null,local:null,localState:null,indent:l?[]:null}},copyState:function(e){var r={state:e.state,pending:e.pending,local:e.local,localState:null,indent:e.indent&&e.indent.slice(0)};e.localState&&(r.localState=t.copyState(e.local.mode,e.localState)),e.stack&&(r.stack=e.stack.slice(0));for(var i=e.persistentStates;i;i=i.next)r.persistentStates={mode:i.mode,spec:i.spec,state:i.state==e.localState?r.localState:t.copyState(i.mode,i.state),next:r.persistentStates};return r},token:function(t,e){return function(r,i){if(i.pending){var n=i.pending.shift();return 0==i.pending.length&&(i.pending=null),r.pos+=n.text.length,n.token}if(i.local){if(i.local.end&&r.match(i.local.end)){var o=i.local.endToken||null;return i.local=i.localState=null,o}var a,o=i.local.mode.token(r,i.localState);return i.local.endScan&&(a=i.local.endScan.exec(r.current()))&&(r.pos=r.start+a.index),o}for(var l=t[i.state],c=0;c<l.length;c++){var h=l[c],u=(!h.data.sol||r.sol())&&r.match(h.regex);if(u){h.data.next?i.state=h.data.next:h.data.push?((i.stack||(i.stack=[])).push(i.state),i.state=h.data.push):h.data.pop&&i.stack&&i.stack.length&&(i.state=i.stack.pop()),h.data.mode&&s(e,i,h.data.mode,h.token),h.data.indent&&i.indent.push(r.indentation()+e.indentUnit),h.data.dedent&&i.indent.pop();var f=h.token;if(f&&f.apply&&(f=f(u)),u.length>2&&h.token&&"string"!=typeof h.token){i.pending=[];for(var d=2;d<u.length;d++)u[d]&&i.pending.push({text:u[d],token:h.token[d-1]});return r.backUp(u[0].length-(u[1]?u[1].length:0)),f[0]}return f&&f.join?f[0]:f}}return r.next(),null}}(o,r),innerMode:function(t){return t.local&&{mode:t.local.mode,state:t.localState}},indent:function(e,r){return function(i,n,s){if(i.local&&i.local.mode.indent)return i.local.mode.indent(i.localState,n,s);if(null==i.indent||i.local||r.dontIndentStates&&function(t,e){for(var r=0;r<e.length;r++)if(e[r]===t)return!0}(i.state,r.dontIndentStates)>-1)return t.Pass;var o=i.indent.length-1,a=e[i.state];t:for(;;){for(var l=0;l<a.length;l++){var c=a[l];if(c.data.dedent&&!1!==c.data.dedentIfLineStart){var h=c.regex.exec(n);if(h&&h[0]){o--,(c.next||c.push)&&(a=e[c.next||c.push]),n=n.slice(h[0].length);continue t}}}break}return o<0?0:i.indent[o]}}(o,a)};if(a)for(var g in a)a.hasOwnProperty(g)&&(p[g]=a[g]);return p}}(r(0))},function(t,e,r){"use strict";r.r(e);class i{constructor(t,e){this.line=t,this.position=e}toString(){return this.line+1+":"+(this.position+1)}copy(){return new i(this.line,this.position)}}var n,s;!function(t){t[t.kError=0]="kError",t[t.kIdent=1]="kIdent",t[t.kNumber=2]="kNumber",t[t.kNewline=3]="kNewline",t[t.kOp=4]="kOp",t[t.kString=5]="kString",t[t.kComment=6]="kComment",t[t.kEOF=7]="kEOF"}(n||(n={}));class o{constructor(t,e,r){this.id=t,this.text=e,this.loc=r}toString(){return"Token("+this.text+")"}isOp(t){return this.id===n.kOp&&this.text===t}isSigil(){switch(this.text){case"$":case"%":case"&":case"!":case"#":return!0}return!1}isIdent(t){return this.id===n.kIdent&&(!t||this.text===t)}isNewline(){return this.id===n.kNewline}isNewlineOrColon(){return this.id===n.kNewline||this.isOp(":")}isString(){return this.id===n.kString}isNumber(){return this.id===n.kNumber}stringVal(){return this.text.substr(1,this.text.length-2)}utext(){return this.text.toUpperCase()}}function a(t){const e=/^\s+/.exec(t.text);e&&t.advance(e[0].length)}class l{constructor(t,e){this.text=t,this.loc=e}advance(t){this.text=this.text.substr(t),this.loc.position+=t}advanceWithTok(t,e){const r=new o(t,this.text.substr(0,e),this.loc.copy());return this.advance(e),r}}function c(t,e,r){const i=e.exec(r.text);if(i)return r.advanceWithTok(t,i[0].length)}function h(t){const e=t.split("\n"),r=[];for(let t=0;t<e.length;t++){const s=new l(e[t],new i(t,0));for(;s.text.length>0&&(a(s),0!==s.text.length);){const t=c(n.kComment,/^'.*/,s)||c(n.kComment,/^(REM(\s|$)|').*/,s)||c(n.kIdent,/^[a-zA-Z_][a-zA-Z0-9_]*/,s)||c(n.kNumber,/^(([0-9]+([.][0-9]*([ED][+-]?[0-9]+)?)?)|(\.[0-9]+([ED][+-]?[0-9]+)?))/,s)||c(n.kNumber,/^&H[0-9A-F]+/,s)||c(n.kOp,/^(\=?(\=?=>|=<)|(\=?>=?)|(\=?<[>=]?)|[()[!\]:;&%$=,.#+*/\\?-])/,s)||c(n.kString,/^"([^"\\]|\\.)*("|$)/,s);t?r.push(t):r.push(s.advanceWithTok(n.kError,1))}r.push(s.advanceWithTok(n.kNewline,0)),t===e.length-1&&r.push(s.advanceWithTok(n.kEOF,0))}return r}function u(t){return"$"===t?s.kString:"%"===t?s.kInt:"&"===t?s.kLongInt:"!"===t?s.kSingle:"#"===t?s.kDouble:s.kNone}function f(t){return t?t===s.kString?"$":t===s.kInt?"%":t===s.kLongInt?"&":t===s.kSingle?"!":t===s.kDouble?"#":"":""}!function(t){t[t.kNone=0]="kNone",t[t.kString=1]="kString",t[t.kInt=2]="kInt",t[t.kLongInt=3]="kLongInt",t[t.kSingle=4]="kSingle",t[t.kDouble=5]="kDouble",t[t.kUserType=6]="kUserType"}(s||(s={}));class d{constructor(t,e){this.name=t,this.type=e}}class p{constructor(t,e,r=0){this.resultType=t,this.argTypes=e,this.optionalParameters=r}}class g{static makeBasic(t){const e=new g;return e.type=t,e}static basic(t){switch(t){case s.kInt:return m;case s.kString:return v;case s.kDouble:return y;case s.kSingle:return b;case s.kLongInt:return x}}equals(t){return this.type===t.type&&this.type!==s.kUserType}isNumeric(){switch(this.type){case s.kInt:case s.kLongInt:case s.kSingle:case s.kDouble:return!0}return!1}isString(){return this.type===s.kString}isBasic(){return this.isNumeric()||this.isString()}toString(){return s[this.type]}lookupField(t){if(this.fields)for(const e of this.fields)if(e.name===t)return e}lookupFieldOffset(t){if(this.fields)for(let e=0;e<this.fields.length;e++)if(this.fields[e].name===t)return e}}g.makeBasic(s.kNone);const m=g.makeBasic(s.kInt),v=g.makeBasic(s.kString),y=g.makeBasic(s.kDouble),b=g.makeBasic(s.kSingle),x=g.makeBasic(s.kLongInt);var w;!function(t){t[t.kNone=0]="kNone",t[t.kLiteral=1]="kLiteral",t[t.kVar=2]="kVar",t[t.kField=3]="kField",t[t.kConst=4]="kConst",t[t.kStackValue=5]="kStackValue",t[t.kCommaDelim=6]="kCommaDelim",t[t.kSemicolonDelim=7]="kSemicolonDelim",t[t.kArgument=8]="kArgument",t[t.kUnspecifiedDimSize=9]="kUnspecifiedDimSize"}(w||(w={}));class k{constructor(){this.kind=0}static newVar(t,e,r){const i=new k;return i.type=e,i.kind=w.kVar,r&&(i.size=r),i.varName=t,i}static newField(t,e,r){const i=new k;return i.type=e,i.kind=w.kField,i.varName=t,i.fieldBase=r,i}static newConst(t,e,r){const i=new k;return i.type=e,i.kind=w.kConst,i.varName=t,i.type===v?i.stringValue=r:i.numberValue=r,i.shared=!0,i}static newStackValue(t,e){const r=new k;return r.kind=w.kStackValue,r.type=t,r.stackOffset=e,r}static newStringLiteral(t){const e=new k;return e.kind=w.kLiteral,e.type=v,e.stringValue=t,e}static newNumberLiteral(t,e){const r=new k;return r.kind=w.kLiteral,r.type=e,r.numberValue=t,r}static newCommaDelim(){const t=new k;return t.kind=w.kCommaDelim,t}static newSemicolonDelim(){const t=new k;return t.kind=w.kSemicolonDelim,t}static newUnspecifiedDimSize(){const t=new k;return t.kind=w.kUnspecifiedDimSize,t}copy(){const t=new k;return t.kind=this.kind,t.type=this.type,this.size&&(t.size=this.size),this.isArrayArg&&(t.isArrayArg=this.isArrayArg),this.index&&(t.index=this.index),this.fieldBase&&(t.fieldBase=this.fieldBase),void 0!==this.numberValue&&(t.numberValue=this.numberValue),void 0!==this.stringValue&&(t.stringValue=this.stringValue),this.varName&&(t.varName=this.varName),this.shared&&(t.shared=this.shared),this.dimmed&&(t.dimmed=this.dimmed),void 0!==this.stackOffset&&(t.stackOffset=this.stackOffset),void 0!==this.argIndex&&(t.argIndex=this.argIndex),t}isCommaDelim(){return this.kind===w.kCommaDelim}isSemicolonDelim(){return this.kind===w.kSemicolonDelim}isVar(){return this.kind===w.kVar}isField(){return this.kind===w.kField}isConst(){return this.kind===w.kConst}isLiteral(){return this.kind===w.kLiteral}isStackValue(){return this.kind===w.kStackValue}constNumberValue(){if((this.isConst()||this.isLiteral())&&this.type.isNumeric())return this.numberValue}loc(){}baseType(){return this.type?this.type.type:s.kNone}}const S=new k;class E{constructor(t,e,r){this.step=t,this.x=e,this.y=r}}class T{}function C(t,e){new N(t,e).program()}class I{constructor(t,e){this.beginToken=t,this.kind=e,this.usedElse=!1,this.singleLine=!1}}const O=k.newNumberLiteral(-1,m),L=k.newNumberLiteral(0,m);class N{constructor(t,e){this.ctx=t,this.tokens=e,this.tokenIndex=0,this.isEnd=!1,this.openBlocks=[],this.defaultVarTypes=new Map,this.moduleCtx=this.ctx,this.dynamicFlag=!1,this.atNewline=!0,this.expr5=(()=>this.binaryExprTemplate(["^"],this.expr6.bind(this))),this.expr4=(()=>this.binaryExprTemplate(["*","/"],this.expr5.bind(this))),this.expr3=(()=>this.binaryExprTemplate(["MOD","\\"],this.expr4.bind(this))),this.expr2=(()=>this.binaryExprTemplate(["+","-"],this.expr3.bind(this))),this.expr1=(()=>this.binaryExprTemplate([">","<",">=","=>","<=","=<","=","<>"],this.expr2.bind(this))),this.exprL5=(()=>this.binaryExprTemplate(["AND"],this.exprL6.bind(this))),this.exprL4=(()=>this.binaryExprTemplate(["OR"],this.exprL5.bind(this))),this.exprL3=(()=>this.binaryExprTemplate(["XOR"],this.exprL4.bind(this))),this.exprL2=(()=>this.binaryExprTemplate(["EQV"],this.exprL3.bind(this))),this.exprL1=(()=>this.binaryExprTemplate(["IMP"],this.exprL2.bind(this)));for(const t of this.tokens)t.id===n.kComment&&/(REM|')\s*[$]DYNAMIC\s*/.test(t.text)&&(this.dynamicFlag=!0);this.tokens=this.tokens.filter(t=>t.id!==n.kComment),t.setLocator(this)}currentLocation(){const t=this.tokenIndex-1;if(!(t<0||t>=this.tokens.length))return this.tokens[t].loc}defaultType(t,e){return g.basic(e)||this.defaultVarTypes.get(t[0])||b}currentBlock(){return this.openBlocks.length?this.openBlocks[this.openBlocks.length-1]:void 0}findBlock(t){for(let e=this.openBlocks.length-1;e>=0;e--){if(this.openBlocks[e].kind===t)return this.openBlocks[e]}}singleLineBlock(){const t=this.currentBlock();return void 0!==t&&t.singleLine}tok(t=0){return t+this.tokenIndex>=this.tokens.length?this.tokens[this.tokens.length-1]:this.tokens[t+this.tokenIndex]}next(t=1){this.tokenIndex+=t}error(t,e){e||(e=this.tok().loc),this.ctx.error(t,e)}nextIf(t){const e=this.tok();if(e.utext()===t)return this.next(),e}expectNewline(){const t=this.tok();if(t.isOp(":")||t.id===n.kNewline)return t.id===n.kNewline?(this.singleLineBlock()&&this.error("newline before END"),this.atNewline=!0,this.ctx.newline(this.tok().loc.line+1)):this.atNewline=!1,void this.next();this.isEof()||this.error("expected newline")}eatNewlines(){for(;this.tok().isOp(":")||this.tok().id===n.kNewline;)this.expectNewline()}eatUntilNewline(){for(;this.tok().id!==n.kNewline&&!this.tok().isOp(":")&&this.tok().id!==n.kEOF;)this.next()}expectIdent(t){const e=this.tok();if(e.id===n.kIdent&&(!t||e.utext()===t))return this.next(),e;this.error("expected "+(t||"ident"))}nextIdent(){const t=this.tok();if(t.id===n.kIdent)return this.next(),t}expectOp(t){const e=this.tok();if(e.id===n.kOp&&e.text===t)return this.next(),e;this.error("expected '"+t+"'")}isEof(){return this.tokenIndex>=this.tokens.length-1}isEol(){return this.tok().id===n.kNewline||this.tok().isOp(":")||this.isEof()}typename(){const t=this.expectIdent();if(t)return this.ctx.typename(t)}typeStmt(){this.expectIdent("TYPE");new k;const t=this.expectIdent();if(!t)return!1;const e=new g;for(e.type=s.kUserType,e.fields=[];!this.isEof();){if(this.eatNewlines(),this.nextIf("END"))return void(this.expectIdent("TYPE")&&this.ctx.defineType(t,e));const r=this.expectIdent();if(!r)return;if(!this.expectIdent("AS"))return;const i=this.typename();if(!i)return;e.fields.push(new d(r.text,i)),this.expectNewline()}}maybeLabel(){if(!this.tok(1).isOp(":"))return!1;if(this.tok(0).id!==n.kIdent)return!1;if(this.isReserved(this.tok(0).text))return!1;const t=this.expectIdent();return!!t&&(this.ctx.label(t),this.next(),!0)}maybeStringLiteral(){const t=this.tok();if(t.id===n.kString)return this.next(),k.newStringLiteral(t.text.substr(1,t.text.endsWith('"')?t.text.length-2:t.text.length-1))}abs(){this.expectIdent("ABS");const t=this.callArgsWithTypes([y]);if(t)return this.ctx.op("ABS",t)}maybeFunctionCall(){if(!this.tok(0).isIdent())return;const t=this.tok(0).text;let e,r,i=t;switch(this.tok(1).isSigil()?(i+=this.tok(1).text,r=u(this.tok(1).text),e=2):e=1,i.toUpperCase()){case"INSTR":{this.next();let t=this.callArgs(!0,2);if(!t)return;if(3===t.length){if(!(t=this.prepareArgs(t,[m,v,v])))return;return this.ctx.callBuiltin("INSTR",t)}if(2===t.length){if(!(t=this.prepareArgs(t,[v,v])))return;return this.ctx.callBuiltin("INSTR",[k.newNumberLiteral(1,m),...t])}return void this.error("wrong number of arguments")}case"STRING$":{this.next(e);const t=this.callArgs(!0,2);if(!t)return;return t[1].type===v?this.ctx.callBuiltin("STRING",t):this.ctx.callBuiltin("STRING",[t[0],this.ctx.callBuiltin("CHR",[t[1]])])}case"ASC":return this.callBuiltinWithTypes("ASC",m,[v]);case"ATN":return this.callBuiltinWithTypes("ATN",y,[y]);case"CDBL":return this.callBuiltinWithTypes("CDBL",y,[y]);case"CHR$":return this.callBuiltinWithTypes("CHR",v,[x]);case"CINT":return this.callBuiltinWithTypes("CINT",m,[y]);case"CLNG":return this.callBuiltinWithTypes("CLNG",x,[y]);case"COS":return this.callBuiltinWithTypes("COS",y,[y]);case"CSNG":return this.callBuiltinWithTypes("CSNG",b,[y]);case"EXP":return this.callBuiltinWithTypes("EXP",y,[y]);case"FIX":case"FIX":return this.callBuiltinWithTypes("FIX",y,[y]);case"FRE":return this.callBuiltinWithTypes("FRE",void 0,[y]);case"INKEY$":return this.callBuiltinWithTypes("INKEY",v,[]);case"INPUT$":return this.callBuiltinWithTypes("INPUT",v,[m]);case"INT":return this.callBuiltinWithTypes("INT",m,[y]);case"LCASE$":return this.callBuiltinWithTypes("LCASE",v,[v]);case"LEFT$":return this.callBuiltinWithTypes("LEFT",v,[v,x]);case"LEN":return this.callBuiltinWithTypes("LEN",m,[v]);case"LTRIM$":return this.callBuiltinWithTypes("LTRIM",v,[v]);case"MID$":return this.callBuiltinWithTypes("MID",v,[v,x,x],1);case"PEEK":return this.callBuiltinWithTypes("PEEK",m,[m]);case"RIGHT$":return this.callBuiltinWithTypes("RIGHT",v,[v,x]);case"RND":return this.callBuiltinWithTypes("RND",b,[m],0);case"RTRIM$":return this.callBuiltinWithTypes("RTRIM",v,[v]);case"SIN":return this.callBuiltinWithTypes("SIN",y,[y]);case"LOG":return this.callBuiltinWithTypes("LOG",y,[y]);case"SPACE$":return this.callBuiltinWithTypes("SPACE",v,[m]);case"STR$":return this.callBuiltinWithTypes("STR",v,[y]);case"TAN":return this.callBuiltinWithTypes("TAN",y,[y]);case"TIMER":return this.callBuiltinWithTypes("TIMER",y,[]);case"UCASE$":return this.callBuiltinWithTypes("UCASE",v,[v]);case"VAL":return this.callBuiltinWithTypes("VAL",y,[v])}{const t=this.maybeCallBuiltin();if(t)return t}const n=this.ctx.lookupFunction(t);if(!n)return;if(r&&g.basic(r)!==n.resultType)return void this.error("duplicate definition");this.next(e);const s=this.callArgsWithTypes(n.argTypes,n.argTypes.length-n.optionalParameters);return s?this.ctx.callFunction(t,s):void 0}maybeNumberLiteral(){let t=0;this.tok().isOp("-")&&(t=1);const e=this.tok(t);if(e.id!==n.kNumber)return;this.tokenIndex+=t+1;const r=new k;r.kind=w.kLiteral;const i=e.text,s=i.startsWith("&H");return!s&&i.includes("D")?(r.numberValue=parseFloat(i.replace("D","E")),r.type=y):!s&&i.includes("E")?(r.numberValue=parseFloat(i),r.type=b):!s&&i.includes(".")?(r.numberValue=parseFloat(i),r.type=b,this.tok().isOp("#")?(r.type=y,this.next()):this.tok().isOp("!")&&this.next()):(r.numberValue=s?parseInt(i.substr(2),16):parseInt(i,10),this.nextIf("#")?r.type=y:this.nextIf("!")?(r.type=b,this.next()):this.nextIf("%")?(r.type=m,this.next()):r.type=b),0!==t&&(r.numberValue=-r.numberValue),r}isModuleLevel(){return this.moduleCtx===this.ctx}expectModuleLevel(){this.isModuleLevel()||this.error("not in module level")}dataStmt(){this.expectIdent("DATA"),this.expectModuleLevel();const t=[];for(;;){let e=this.maybeStringLiteral()||this.maybeNumberLiteral();if(!e){if(this.tok().id!==n.kIdent)return this.error("expected data literal"),this.eatUntilNewline(),!0;(e=new k).stringValue=this.tok().text}if(t.push(e),!this.nextIf(","))break}this.ctx.data(t)}readStmt(){this.expectIdent("READ");const t=this.varRefsUntilNewline();return t&&this.ctx.read(t),!0}restoreStmt(){this.expectIdent("RESTORE");const t=this.labelOrLineNumber();void 0!==t&&this.ctx.restore(t)}maybeSigil(){const t=this.tok();if(t.id===n.kOp){const e=u(t.text);if(e!==s.kNone)return++this.tokenIndex,e}return s.kNone}maybeVarname(t){if(this.tok().id===n.kIdent)return this.varname(t)}maybeArrayReference(){if(this.tok().id!==n.kIdent)return;const t=this.tokenIndex,e=this.expectIdent(),r=this.maybeSigil();if(this.nextIf("(")&&this.nextIf(")"))return this.ctx.variable(e,r,void 0);this.tokenIndex=t}varname(t){const e=this.expectIdent();if(!e)return;const r=this.maybeSigil();let i=this.ctx.variable(e,r,this.defaultType(e.text,r));if(!t)return i;for(i&&this.tok().isOp("(")&&(i=this.ctx.index(i,this.arrayIndex()));i&&this.nextIf(".");){const t=this.expectIdent();if(!t)return;i=this.ctx.indexField(i,t)}return i}arrayIndex(){this.expectOp("(");const t=[];for(;!this.isEol();){const e=this.numericExpr();if(!e)break;if(t.push(e),this.nextIf(")"))return t;if(!this.expectOp(","))return[]}return this.expectOp(")"),[]}sizeOrRange(){if(this.tok().isIdent()&&!this.ctx.isConst(this.tok().text))return this.next(),[k.newUnspecifiedDimSize()];const t=this.numericExpr();if(t){if(this.nextIf("TO")){const e=this.numericExpr();return e?[t,e]:void this.error("expected number")}return[t]}this.error("expected number")}maybeArraySize(){if(!this.nextIf("("))return;const t=[];for(;;){const e=this.sizeOrRange();if(!e)return;if(t.push(e),!this.nextIf(","))break}return this.expectOp(")")?t:void 0}dimStmt(){const t=this.nextIf("REDIM");t||this.expectIdent("DIM");const e=this.nextIf("SHARED");for(;;){const r=this.expectIdent(),i=this.maybeSigil();if(!r)return;const n=this.maybeArraySize();let s=this.defaultType(r.text,i);if(this.nextIf("AS")){const t=this.typename();if(!t)return;s=t}if(this.ctx.dim(r,n,s,void 0!==e,void 0!==t||this.dynamicFlag),!this.nextIf(","))break}}expr6(){if(this.nextIf("(")){const t=this.expr();return this.expectOp(")")?t:void 0}if(this.tok().isIdent("ABS"))return this.abs();const t=this.nextIf("-"),e=this.maybeFunctionCall()||this.maybeVarname(!0)||this.maybeNumberLiteral()||this.maybeStringLiteral();if(e){if(t){if(!e.isLiteral()||!e.type.isNumeric())return this.ctx.op("-",[e]);e.numberValue=-e.numberValue}return e}this.error("expected value"),this.eatUntilNewline()}binaryExprTemplate(t,e){let r=e();for(;r;){const i=this.tok();let n=!1;for(const s of t)if(i.text.toUpperCase()===s){this.next();const t=e();if(!t)return;const s=this.ctx.op(i.text.toUpperCase(),[r,t]);if(!s)return;r=s,n=!0;break}if(!n)break}return r}exprL6(){for(;!this.isEol();){if(this.nextIf("NOT")){const t=this.exprL6();if(!t)return;return this.ctx.op("NOT",[t])}return this.expr1()}}expr(){return this.exprL1()}numericExpr(){const t=this.expr();if(!t||!t.type||t.type.isNumeric())return t;this.error("expected numeric")}stringExpr(){const t=this.expr();if(!t||!t.type||t.type.isString())return t;this.error("expected string expression")}printStmt(){if(this.nextIf("PRINT")||this.expectOp("?"),this.tok().isOp("#"))return void this.eatUntilNewline();if(this.nextIf("USING"))return void this.eatUntilNewline();const t=[];let e=!0;for(;!this.isEol();){if(this.tok().isOp(",")){this.next(),t.push(k.newCommaDelim()),e=!0;continue}if(this.tok().isOp(";")){this.next(),t.push(k.newSemicolonDelim()),e=!0;continue}if(!e)break;const r=this.expr();if(!r)return this.eatUntilNewline(),!0;t.push(r),e=!1}this.ctx.op("PRINT",t)}locateStmt(){let t,e,r,i,n;this.expectIdent("LOCATE"),this.tok().isOp(",")||this.isEol()||(t=this.numericExpr()),this.nextIf(",")&&(this.tok().isOp(",")||this.isEol()||(e=this.numericExpr()),this.nextIf(",")&&(this.tok().isOp(",")||this.isEol()||(r=this.numericExpr()),this.nextIf(",")&&(this.tok().isOp(",")||this.isEol()||(i=this.numericExpr(),this.expectOp(","),n=this.numericExpr())))),this.ctx.locate(t,e)}letStmt(){this.nextIf("LET");const t=this.maybeVarname(!0);if(!t)return!1;if(this.expectOp("=")){const e=this.expr();if(!e)return!0;this.ctx.op("assign",[t,e])}return!0}clsStmt(){let t;this.expectIdent("CLS"),(this.isEol()||(t=this.numericExpr()))&&this.ctx.callBuiltin("CLS",[t])}declArgs(){if(!this.tok().isOp("("))return[];this.next();const t=[];for(;!this.isEol()&&!this.tok().isOp(")");){t.length&&this.expectOp(",");const e=this.expectIdent(),r=this.maybeSigil();let i=!1;this.nextIf("(")&&(i=!0,this.expectOp(")"));let n=g.basic(r),o=!1;if(this.nextIf("AS")){const t=this.typename();t&&r!==s.kNone&&t.type!==r?this.error("mismatched type"):t&&(n=t,o=!0)}if(n||(n=b),!e)break;t.push(this.ctx.declArg(e,i,n,o))}return this.expectOp(")"),t}ifStmt(){const t=this.expectIdent("IF");if(!t)return;const e=this.expr();if(!e)return;const r=this.singleLineBlock(),i=new I(t,"IF");if(i.singleLine=r,this.openBlocks.push(i),!this.expectIdent("THEN"))return;if(this.ctx.ifBegin(e),!i.singleLine&&this.tok().isNewlineOrColon())return;i.singleLine=!0;const n=()=>{let t=!0;for(;;){if(t&&this.tok().isNumber()){const t=this.tok(),e=this.labelOrLineNumber();"number"==typeof e&&this.ctx.gotoLine(e,t);break}if(this.tok().isIdent("ELSE")||this.tok().isIdent("ELSEIF"))break;if(this.statement(),!this.nextIf(":"))break;t=!1}};for(n();;)if(this.tok().isIdent("ELSE"))this.elseStmt(),n();else{if(!this.tok().isIdent("ELSEIF")){if(this.tok().isNewline())break;this.error("expected ELSE, ELSEIF, or newline");break}this.elseIfStmt(),n()}this.currentBlock()===i?(this.openBlocks.pop(),this.ctx.ifEnd()):this.error("cannot open block within single line if-statement")}elseStmt(){const t=this.expectIdent("ELSE");if(!t)return;const e=this.currentBlock();e&&"IF"===e.kind?e.usedElse?this.error("ELSE after ELSE",t.loc):this.ctx.elseBegin():this.error("ELSE without IF",t.loc)}elseIfStmt(){const t=this.expectIdent("ELSEIF");if(!t)return;const e=this.currentBlock();if(!e||"IF"!==e.kind)return void this.error("ELSEIF without IF",t.loc);if(e.usedElse)return void this.error("ELSEIF after ELSE",t.loc);const r=this.expr();r&&(this.expectIdent("THEN"),this.ctx.elseBegin(r))}selectStmt(){const t=this.expectIdent("SELECT"),e=t&&this.expectIdent("CASE")&&this.expr();e&&(this.openBlocks.push(new I(t,"SELECT")),this.ctx.selectBegin(e))}caseStmt(){this.expectIdent("CASE");const t=this.currentBlock();if(t&&"SELECT"===t.kind)if(t.usedElse)this.error("CASE ELSE must be last");else if(this.nextIf("ELSE"))t.usedElse=!0,this.ctx.selectCaseElse();else{const t=[];do{if(this.nextIf("IS")){if(!(this.tok().isOp("<")||this.tok().isOp(">")||this.tok().isOp("=")||this.tok().isOp(">=")||this.tok().isOp("<=")))return void this.error("expected comparison operator");const e=this.tok();this.next();const r=this.expr();if(!r)return;const i=new T;i.isExpr=[e,r],t.push(i);continue}const e=this.expr();if(!e)return;if(this.nextIf("TO")){const r=this.expr();if(!r)return;const i=new T;i.range=[e,r],t.push(i)}else{const r=new T;r.single=e,t.push(r)}}while(this.nextIf(","));this.ctx.selectCase(t)}else this.error("CASE without SELECT")}screenStmt(){let t,e,r,i;this.expectIdent("SCREEN"),this.tok().isOp(",")||this.isEol()||(t=this.numericExpr()),this.nextIf(",")&&(this.tok().isOp(",")||this.isEol()||(e=this.numericExpr()),this.nextIf(",")&&(this.tok().isOp(",")||this.isEol()||(r=this.numericExpr()),this.nextIf(",")&&!this.isEol()&&(this.tok().isOp(",")||(i=this.numericExpr())))),this.ctx.callBuiltin("SCREEN",[t,e,r,i])}letter(){if(!this.tok(0).isIdent())return void this.error("expected letter");const t=this.tok(0).text;if(/[A-Z]/.test(t))return this.next(),t;this.error("expected letter")}letterRange(){const t=this.letter();if(!t)return;if(!this.nextIf("-"))return new Set([t]);const e=this.letter();if(!e)return;if(e.charCodeAt(0)<t.charCodeAt(0))return void this.error("invalid range");const r=new Set;for(let i=t.charCodeAt(0);i<=e.charCodeAt(0);i++)r.add(String.fromCharCode(i));return r}letterRanges(){let t;for(;;){const e=this.letterRange();if(!e)return;if(t)for(const r of e)t.add(r);else t=e;if(!this.nextIf(","))return t}}defABCStmt(){let t;switch(this.tok().utext()){case"DEFINT":t=m;break;case"DEFLNG":t=x;break;case"DEFSNG":t=b;break;case"DEFDBL":t=y;break;case"DEFSTR":t=v;break;default:return void this.error("expected DEFXYZ")}this.next();const e=this.letterRanges();if(e)for(const r of e)this.defaultVarTypes.set(r,t)}colorStmt(){let t,e;this.expectIdent("COLOR"),this.tok().isOp(",")||(t=this.numericExpr()),this.nextIf(",")&&(this.tok().isOp(",")||this.isEol()||(e=this.numericExpr()),this.nextIf(",")&&this.numericExpr()),this.ctx.color(t,e)}paletteStmt(){if(this.expectIdent("PALETTE"),this.tok().isNewlineOrColon())return void this.ctx.palette();const t=this.numericExpr();this.expectOp(","),this.ctx.palette(t,this.numericExpr())}subStmt(){const t=this.expectIdent("SUB");if(!t)return;this.expectModuleLevel(),this.isEnd=!0;const e=this.expectIdent();if(!e)return;const r=this.ctx.sub(e,this.declArgs());this.ctx=r,this.nextIf("STATIC"),this.openBlocks.push(new I(t,"SUB"))}functionStmt(){const t=this.expectIdent("FUNCTION");if(!t)return;this.expectModuleLevel(),this.isEnd=!0;const e=this.expectIdent();if(!e)return;const r=this.maybeSigil(),i=this.ctx.functionBegin(e,r,this.defaultType(e.text,r),this.declArgs(),!1);this.ctx=i,this.openBlocks.push(new I(t,"FUNCTION"))}declareStmt(){if(this.expectIdent("DECLARE"),this.expectModuleLevel(),this.nextIf("SUB")){const t=this.expectIdent();if(!t)return;this.ctx.declSub(t,this.declArgs())}else if(this.nextIf("FUNCTION")){const t=this.expectIdent();if(!t)return;const e=this.maybeSigil();this.ctx.declFunction(t,e,this.defaultType(t.text,e),this.declArgs())}else this.error("expected SUB or FUNCTION")}defStmt(){if(this.expectIdent("DEF"),this.nextIf("SEG"))return void this.eatUntilNewline();if("fn"!==this.tok().text.substr(0,2).toLowerCase())return void this.error("unknown command");const t=this.nextIdent();if(!t)return;const e=this.maybeSigil();this.expectModuleLevel();const r=this.ctx.functionBegin(t,e,this.defaultType(t.text,e),this.declArgs(),!0);this.expectOp("="),this.ctx=r;const i=this.ctx.variable(t,e,void 0);if(!i)return;const n=this.expr();n&&(this.ctx.op("assign",[i,n]),this.ctx.endFunction(),this.ctx=this.moduleCtx)}checkArgTypes(t,e){if(t.length!==e.length)return this.error(`expected ${e.length} arguments`),!1;for(let r=0;r<t.length;r++){if(e[r].isNumeric()&&(!t[r].type||!t[r].type.isNumeric()))return this.error(`expected numeric for argument ${r+1}`),!1;if(e[r].isString()&&(!t[r].type||!t[r].type.isString()))return this.error(`expected string for argument ${r+1}`),!1}return!0}prepareArgs(t,e){if(t.length===e.length){for(let r=0;r<t.length;r++){if(e[r].isNumeric()&&(!t[r].type||!t[r].type.isNumeric()))return void this.error(`expected numeric for argument ${r+1}`);if(e[r].isString()&&(!t[r].type||!t[r].type.isString()))return void this.error(`expected string for argument ${r+1}`)}return t}this.error(`expected ${e.length} arguments`)}callBuiltinWithTypes(t,e,r,i=-1){if(this.next(),e){const t=f(e.type);""!==t&&this.nextIf(t)}const n=this.callArgsWithTypes(r,i);if(n)return this.ctx.callBuiltin(t,n)}callArgsWithTypes(t,e=-1){-1===e&&(e=t.length);const r=this.callArgs(!0,e);if(r&&!(r.length>t.length)){if(!(r.length<e)){for(let e=0;e<r.length;e++){if(t[e].isNumeric()&&(!r[e].type||!r[e].type.isNumeric()))return void this.error(`expected numeric for argument ${e+1}`);if(t[e].isString()&&(!r[e].type||!r[e].type.isString()))return void this.error(`expected string for argument ${e+1}`)}return r}this.error(`expected ${e} arguments`)}}callArgs(t,e=-1){if(t&&!this.tok().isOp("("))return e>=1&&this.error(`expected ${e} arguments`),[];t&&this.expectOp("(");const r=[];for(;;){if(t?this.tok().isOp(")"):this.isEol())return e>=0&&r.length<e?(this.error(`expected ${e} arguments`),r):(t&&this.expectOp(")"),r);if(this.isEol())break;const i=this.maybeArrayReference()||this.expr();if(!i)return;if(r.push(i),t?!this.tok().isOp(")"):!this.isEol()){if(!this.tok().isOp(","))return this.error("expected ',' or )"),r;this.next()}}return this.error("expected argument"),r}argsUntilNewline(){const t=[];for(;!this.isEol();){if(!this.expr())return;if(t.push(),this.isEol())return this.expectNewline(),t;if(!this.tok().isOp(","))return this.error("expected ',' or newline"),t}return this.expectNewline(),t}varRefsUntilNewline(){const t=[];for(;!this.isEol();){switch(this.tok().utext()){case"END":case"ELSE":case"ELSEIF":return t}const e=this.maybeVarname(!0);if(!e)return void this.expectIdent();if(t.push(e),this.isEol())return t;if(!this.expectOp(","))return}return t}maybeCallBuiltin(){switch(this.tok().utext()){case"POINT":return this.pointFunction();default:return}}maybeCallSubStmt(){const t=this.nextIf("CALL");if(!this.tok().isIdent())return!!t&&(this.error("expected identifier"),!0);const e=this.tok(),r=e.utext();switch(r){case"__LOG":return this.callBuiltinWithTypes("__LOG",void 0,[v]),!0}if(!this.ctx.isSub(r))return!1;this.next();const i=this.callArgs(!!t);return i&&this.ctx.callSub(e,i),!0}inputStmt(){this.expectIdent("INPUT");let t,e=!1;if(this.tok().isOp(";")&&(this.next(),e=!0),this.tok().isString())if(t=this.tok().stringVal(),this.next(),this.tok().isOp(";"))t+="? ",this.next();else{if(!this.tok().isOp(","))return this.error("expected ; or ,"),this.eatUntilNewline(),!0;this.next()}else t="? ";const r=this.varRefsUntilNewline();return r&&this.ctx.input(e,t,r),!0}maybeLabels(){let t=!1;return this.tok().isNumber()&&/^[0-9]+$/.test(this.tok().text)&&(this.ctx.lineNumber(parseInt(this.tok().text,10),this.tok()),this.next(),t=!0),this.maybeLabel()||t}gotoStmt(){if(this.expectIdent("GOTO"),this.tok().isNumber()&&/^[0-9]+$/.test(this.tok().text))this.ctx.gotoLine(parseInt(this.tok().text,10),this.tok()),this.next();else{const t=this.expectIdent();t&&this.ctx.gotoLabel(t)}}labelOrLineNumber(){if(this.tok().isNumber()&&/^[0-9]+$/.test(this.tok().text)){const t=parseInt(this.tok().text,10);return this.next(),t}{const t=this.expectIdent();if(t)return t.text}this.error("expected line number or label")}gosubStmt(){this.expectIdent("GOSUB");const t=this.tok(),e=this.labelOrLineNumber();void 0!==e&&this.ctx.gosub(t,e)}returnStmt(){let t,e;this.expectIdent("RETURN"),(this.isEol()||(e=this.tok(),void 0!==(t=this.labelOrLineNumber())))&&this.ctx.goReturn(e,t)}nextStmt(){this.expectIdent("NEXT");const t=this.currentBlock();if(!t||"FOR"!==t.kind)return void this.error("next without for");const e=t.forLabel;if(this.tok().isNewlineOrColon())return this.ctx.forEnd(),void this.openBlocks.pop();const r=this.maybeVarname();r&&(r.varName!==e?this.error("NEXT variable does not match FOR"):(this.ctx.forEnd(),this.openBlocks.pop()))}forStmt(){const t=this.expectIdent("FOR");if(!t)return;const e=this.varname();if(!e)return;this.expectOp("=");const r=this.numericExpr();if(!r)return;if(!this.expectIdent("TO"))return;const i=this.numericExpr();if(!i)return;let n;this.nextIf("STEP")&&(n=this.numericExpr()),this.ctx.forBegin(e,r,i,n);const s=e.varName,o=new I(t,"FOR");return o.forLabel=s,this.openBlocks.push(o),!0}doStmt(){const t=this.expectIdent("DO");if(!t)return;this.ctx.doBegin();let e=O;if(this.nextIf("UNTIL")){const t=this.expr();if(!t)return;e=this.ctx.op("LNOT",[t])}else if(this.nextIf("WHILE")){const t=this.expr();if(!t)return;e=t}e&&(this.openBlocks.push(new I(t,"DO")),this.ctx.doWhileCond(e))}loopStmt(){this.expectIdent("LOOP");const t=this.currentBlock();if(!t||"DO"!==t.kind)return void this.error("LOOP without DO");this.openBlocks.pop();let e=L;if(this.nextIf("UNTIL")){const t=this.expr();if(!t)return;e=t}else if(this.nextIf("WHILE")){const t=this.expr();if(!t)return;e=this.ctx.op("LNOT",[t])}e&&this.ctx.doEnd(e)}whileStmt(){const t=this.expectIdent("WHILE");if(!t)return;this.openBlocks.push(new I(t,"WHILE")),this.ctx.whileBegin();const e=this.expr();e&&this.ctx.whileCond(e)}wendStmt(){this.expectIdent("WEND");const t=this.currentBlock();t&&"WHILE"===t.kind?(this.ctx.wend(),this.openBlocks.pop()):this.error("WEND without WHILE")}exitStmt(){if(this.expectIdent("EXIT"),this.currentBlock())switch(this.tok().utext()){case"FOR":if(this.expectIdent("FOR"),!this.findBlock("FOR")){this.error("EXIT FOR without FOR");break}this.ctx.forExit();break;case"DO":if(this.expectIdent("DO"),!this.findBlock("DO")){this.error("EXIT DO without DO");break}this.ctx.doExit();break;case"SUB":if(this.expectIdent("SUB"),!this.findBlock("SUB")){this.error("EXIT SUB without SUB");break}this.ctx.subExit();break;case"FUNCTION":if(this.expectIdent("FUNCTION"),!this.findBlock("FUNCTION")){this.error("EXIT FUNCTION without FUNCTION");break}this.ctx.functionExit()}else this.error("EXIT without FOR, DO, or SUB")}swapStmt(){this.expectIdent("SWAP");const t=this.varname(!0);if(!t)return;if(!this.expectOp(","))return;const e=this.varname(!0);e&&this.ctx.op("SWAP",[t,e])}coord(t=!0){let e=!1;if(t&&this.nextIf("STEP")&&(e=!0),!this.tok().isOp("("))return void(e&&this.error("expected (coordinate)"));this.next();const r=this.numericExpr();this.expectOp(",");const i=this.numericExpr();return this.expectOp(")"),r&&i?new E(e,r,i):void 0}psetStmt(){const t=this.nextIf("PRESET");t||this.expectIdent("PSET");const e=this.coord();if(!e)return;let r;this.tok().isOp(",")&&(this.next(),this.tok().isOp(",")||(r=this.numericExpr())),t&&void 0===r?this.ctx.preset(e):this.ctx.pset(e,r)}pointFunction(){if(this.expectIdent("POINT"),!this.expectOp("("))return;const t=this.numericExpr();if(t){if(this.nextIf(",")){const e=this.numericExpr();if(!e)return;return this.expectOp(")"),this.ctx.callBuiltin("POINT",[t,e])}return this.expectOp(")"),this.ctx.callBuiltin("CURRENT_POINT",[t])}}chainStmt(){this.expectIdent("CHAIN"),this.stringExpr()}soundStmt(){this.expectIdent("SOUND");const t=this.numericExpr();if(!t)return;this.expectOp(",");const e=this.numericExpr();e&&this.ctx.callBuiltin("SOUND",[t,e])}chdirStmt(){this.expectIdent("CHDIR"),this.stringExpr()}viewStmt(){if(this.expectIdent("VIEW"),this.nextIf("PRINT")){if(this.isEol())return void this.ctx.callBuiltin("VIEW_PRINT",[void 0,void 0]);const t=this.numericExpr();if(!t)return;this.expectIdent("TO");const e=this.numericExpr();if(!e)return;return void this.ctx.callBuiltin("VIEW_PRINT",[t,e])}const t=this.nextIf("SCREEN"),e=this.coord(!1);if(!e)return;this.expectOp("-");const r=this.coord(!1);if(!r)return;let i,n;if(this.nextIf(",")){if(!this.tok().isOp(",")&&!(i=this.numericExpr()))return;if(this.nextIf(",")&&!(n=this.numericExpr()))return}this.ctx.callBuiltin("VIEW",[void 0!==t,e.x,e.y,r.x,r.y,i,n])}lineInputStmt(){const t=this.nextIf(";");let e;if(this.tok().isString()){if(!(e=this.stringExpr()))return;this.expectOp(";")}const r=this.varname();r&&this.ctx.callBuiltin("LINE_INPUT",[k.newNumberLiteral(void 0!==t?1:0,m),e,r])}lineStmt(){if(this.expectIdent("LINE"),this.nextIf("INPUT"))return void this.lineInputStmt();let t;if(this.nextIf("-"))t=new E(!0,k.newNumberLiteral(0,m),k.newNumberLiteral(0,m));else if(t=this.coord(),this.expectOp("-"),!t)return;const e=this.coord();if(!e)return;let r,i,n="";if(this.tok().isOp(",")){if(this.next(),!this.tok().isOp(",")&&!(r=this.numericExpr()))return;if(this.tok().isOp(",")&&(this.next(),this.nextIf("B")?n="B":this.nextIf("BF")?n="BF":this.tok().isOp(",")||this.error("expected B, BF, or ','"),this.tok().isOp(",")&&(this.next(),!(i=this.numericExpr()))))return}this.ctx.line(t,e,r,n,i)}drawStmt(){this.expectIdent("DRAW");const t=this.stringExpr();t&&this.ctx.draw(t)}getStmt(){this.expectIdent("GET");const t=this.coord();this.expectOp("-");const e=this.coord();if(!t||!e)return;if(!this.expectOp(","))return;const r=this.expectIdent();if(!r)return;const i=this.maybeSigil();this.ctx.getGraphics(t,e,r,i)}putStmt(){this.expectIdent("PUT");const t=this.coord();if(!t)return;if(!this.expectOp(","))return;const e=this.expectIdent();if(!e)return;const r=this.maybeSigil();let i="PSET";if(this.nextIf(",")){const t=this.expectIdent();if(!t)return;if(["PSET","PRESET","AND","OR","XOR"].indexOf(t.utext())<0)return void this.error("expected PUT actionverb");i=t.utext()}this.ctx.putGraphics(t,e,r,i)}circleStmt(){this.expectIdent("CIRCLE");const t=this.coord();if(!t)return;this.expectOp(",");const e=this.numericExpr();if(!e)return;let r,i,n,s;const o=()=>!this.isEol()&&!this.tok().isOp(",");if(this.nextIf(",")){if(o()&&!(r=this.numericExpr()))return;if(this.nextIf(",")){if(o()&&!(i=this.numericExpr()))return;if(this.nextIf(",")){if(o()&&!(n=this.numericExpr()))return;if(this.nextIf(",")&&!(s=this.numericExpr()))return}}}this.ctx.circle(t,e,r,i,n,s)}paintStmt(){this.expectIdent("PAINT");const t=this.coord();if(!t)return;let e,r,i;if(this.nextIf(",")){if(!this.tok().isOp(",")&&!(e=this.numericExpr()))return;if(this.nextIf(",")){if(!this.tok().isOp(",")&&!(r=this.numericExpr()))return;if(this.nextIf(",")&&!(i=this.stringExpr()))return}}this.ctx.paint(t,e,r,i)}onStmt(){if(this.expectIdent("ON"),this.nextIf("ERROR")){this.expectIdent("GOTO");const t=this.tok(),e=this.labelOrLineNumber();if(!e)return;this.ctx.onErrorGoto(e,t)}}resumeStmt(){if(this.expectIdent("RESUME"),this.nextIf("NEXT"))return void this.ctx.resumeNext();if(this.isEol())return void this.ctx.resume();const t=this.tok(),e=this.labelOrLineNumber();e&&this.ctx.resumeGoto(e,t)}sleepStmt(){this.expectIdent("SLEEP"),this.isEol()?this.ctx.callBuiltin("SLEEP",[void 0]):this.ctx.callBuiltin("SLEEP",[this.numericExpr()])}constStmt(){this.expectIdent("CONST");do{const t=this.expectIdent();if(!t)return;const e=this.maybeSigil();this.expectOp("=");const r=this.expr();if(!r)return;this.ctx.declConst(t,e,r)}while(this.nextIf(","))}randomizeStmt(){this.expectIdent("RANDOMIZE");const t=this.numericExpr();t&&this.ctx.randomize(t)}endStmt(){switch(this.expectIdent("END"),this.tok().utext()){case"SUB":{this.next();const t=this.currentBlock();if(!t||"SUB"!==t.kind)return void this.error("END SUB without SUB");this.ctx.endSub(),this.ctx=this.moduleCtx,this.openBlocks.pop();break}case"FUNCTION":{this.next();const t=this.currentBlock();if(!t||"FUNCTION"!==t.kind)return void this.error("END FUNCTION without FUNCTION");this.ctx.endFunction(),this.ctx=this.moduleCtx,this.openBlocks.pop();break}case"IF":{this.next();const t=this.currentBlock();if(!t||"IF"!==t.kind)return void this.error("END IF without IF");this.ctx.ifEnd(),this.openBlocks.pop();break}case"SELECT":{this.next();const t=this.currentBlock();if(!t||"SELECT"!==t.kind)return void this.error("END SELECT without SELECT");this.ctx.selectEnd(),this.openBlocks.pop();break}default:this.ctx.end()}}isReserved(t){switch(t.toUpperCase()){case"DECLARE":case"SUB":case"FUNCTION":case"IF":case"ELSE":case"ELSEIF":case"SCREEN":case"DEFINT":case"DEFSTR":case"DEFSNG":case"DEFLNG":case"DEFDBL":case"SELECT":case"CASE":case"GOSUB":case"RETURN":case"FOR":case"NEXT":case"EXIT":case"SWAP":case"COLOR":case"PRINT":case"?":case"LINE":case"DRAW":case"GET":case"PUT":case"GOTO":case"LOCATE":case"PALETTE":case"SLEEP":case"REDIM":case"DIM":case"INPUT":case"CLS":case"CIRCLE":case"PAINT":case"PRESET":case"PSET":case"DO":case"TYPE":case"LOOP":case"WHILE":case"WEND":case"CONST":case"RANDOMIZE":case"END":case"DATA":case"READ":case"BEEP":case"RESTORE":case"DEF":case"ON":case"RESUME":case"VIEW":case"CHAIN":case"SOUND":case"KEY":case"CLOSE":case"OPEN":case"PLAY":case"WIDTH":case"POKE":case"DEF":return!0;default:return!1}}statement(){if(this.isEof())return!1;const t=this.atNewline&&!this.singleLineBlock()&&this.maybeLabels();for(;;){const e=this.isModuleLevel();if(this.isEnd&&e&&"SUB"!==this.tok().utext()&&"FUNCTION"!==this.tok().utext())return this.error("expected SUB, FUNCTION, or EOF"),!1;let r=!0;switch(this.ctx.newStmt(),this.tok().utext()){case"DECLARE":this.declareStmt();break;case"SUB":this.subStmt();break;case"FUNCTION":this.functionStmt();break;case"IF":this.ifStmt();break;case"ELSE":this.elseStmt();break;case"ELSEIF":this.elseIfStmt();break;case"SCREEN":this.screenStmt();break;case"DEFINT":case"DEFSTR":case"DEFSNG":case"DEFLNG":case"DEFDBL":this.defABCStmt();break;case"SELECT":this.selectStmt();break;case"CASE":this.caseStmt();break;case"GOSUB":this.gosubStmt();break;case"RETURN":this.returnStmt();break;case"FOR":this.forStmt();break;case"NEXT":this.nextStmt();break;case"EXIT":this.exitStmt();break;case"SWAP":this.swapStmt();break;case"COLOR":this.colorStmt();break;case"PRINT":case"?":this.printStmt();break;case"LINE":this.lineStmt();break;case"DRAW":this.drawStmt();break;case"GET":this.getStmt();break;case"PUT":this.putStmt();break;case"GOTO":this.gotoStmt();break;case"LOCATE":this.locateStmt();break;case"PALETTE":this.paletteStmt();break;case"SLEEP":this.sleepStmt();break;case"REDIM":case"DIM":this.dimStmt();break;case"INPUT":this.inputStmt();break;case"CLS":this.clsStmt();break;case"CIRCLE":this.circleStmt();break;case"PAINT":this.paintStmt();break;case"PRESET":case"PSET":this.psetStmt();break;case"DO":this.doStmt();break;case"TYPE":this.typeStmt();break;case"LOOP":this.loopStmt();break;case"WHILE":this.whileStmt();break;case"WEND":this.wendStmt();break;case"CONST":this.constStmt();break;case"RANDOMIZE":this.randomizeStmt();break;case"END":this.endStmt();break;case"DATA":this.dataStmt();break;case"READ":this.readStmt();break;case"BEEP":this.expectIdent(),this.ctx.callBuiltin("BEEP",[]);break;case"RESTORE":this.restoreStmt();break;case"DEF":this.defStmt();break;case"ON":this.onStmt();break;case"RESUME":this.resumeStmt();break;case"VIEW":this.viewStmt();break;case"CHAIN":this.chainStmt();break;case"SOUND":this.soundStmt();break;case"CHDIR":this.chdirStmt();break;case"OUT":case"KEY":case"CLOSE":case"OPEN":case"PLAY":case"WIDTH":case"POKE":this.eatUntilNewline();break;case"DEF":this.expectIdent("DEF"),this.expectIdent("SEG"),this.eatUntilNewline();break;default:r=!1}if(r)break;if(this.maybeCallSubStmt())break;if(this.letStmt())break;if(t)break;return this.error("expected statement"),!1}return this.ctx.endStmt(),!0}statementAndNewline(){if(!this.statement())return this.eatUntilNewline(),void this.next();this.expectNewline()}program(){for(;!this.isEof();)this.eatNewlines(),this.statementAndNewline();if(this.openBlocks.length){const t=this.openBlocks[this.openBlocks.length-1];this.error(`${t.kind} without END`,t.beginToken.loc)}this.ctx.finalize()}}var A=r(1);const D=2147483648;var R,M,P,V;!function(t){t[t.kLine=0]="kLine",t[t.kBox=1]="kBox",t[t.kFilledBox=2]="kFilledBox"}(R||(R={})),function(t){t[t.kPset=0]="kPset",t[t.kPreset=1]="kPreset",t[t.kAnd=2]="kAnd",t[t.kOr=3]="kOr",t[t.kXor=4]="kXor"}(M||(M={})),function(t){t[t.kMove=0]="kMove",t[t.kMoveXY=1]="kMoveXY",t[t.kRotation=2]="kRotation",t[t.kTurn=3]="kTurn",t[t.kColor=4]="kColor",t[t.kScale=5]="kScale",t[t.kPaint=6]="kPaint"}(P||(P={}));class B{getPosition(t,e,r,i){const n=(n,s)=>{const[o,a]=[Math.cos(r),Math.sin(r)];return[t+i*(n*o-s*a),e+i*(n*a+s*o)]};if(this.id===P.kMoveXY){if(this.c){const[t,e]=[this.a,this.b];return n(t,e)}return[this.a,this.b]}if(this.id===P.kMove){const t=this.b;switch(this.a){case 0:return n(0,-t);case 1:return n(t,-t);case 2:return n(t,0);case 3:return n(t,t);case 4:return n(0,t);case 5:return n(-t,t);case 6:return n(-t,0);case 7:return n(-t,-t)}throw new A.AssertionError({message:"invalid draw instruction"})}throw new A.AssertionError}}class F{print(t){throw new Error("not implemented")}input(t){throw new Error("not implemented")}setForeColor(t){throw new Error("not implemented")}foreColor(){throw new Error("not implemented")}setBackColor(t){throw new Error("not implemented")}backColor(){throw new Error("not implemented")}line(t,e,r,i,n,s,o){throw new Error("not implemented")}circle(t,e,r,i){throw new Error("not implemented")}paint(t,e,r,i){throw new Error("not implemented")}draw(t,e,r){throw new Error("not implemented")}pset(t,e,r){throw new Error("not implemented")}point(t,e){throw new Error("not implemented")}locate(t,e){throw new Error("not implemented")}screen(){throw new Error("not implemented")}resetPalette(){throw new Error("not implemented")}setPaletteAttribute(t,e){throw new Error("not implemented")}sleep(t,e){throw new Error("not implemented")}inkey(){throw new Error("not implemented")}inkeyWait(t,e){throw new Error("not implemented")}cls(){throw new Error("not implemented")}clsGraphics(){throw new Error("not implemented")}clsText(){throw new Error("not implemented")}getGraphics(t,e,r,i,n){}putGraphics(t,e,r,i){}screenLines(){throw new Error("not implemented")}setViewPrint(t,e){throw new Error("not implemented")}setView(){throw new Error("not implemented")}}!function(t){t[t.ADDRESS=0]="ADDRESS",t[t.INPUT=1]="INPUT",t[t.LINE_INPUT=2]="LINE_INPUT",t[t.INPUT_FUNC=3]="INPUT_FUNC",t[t.TO_INT=4]="TO_INT",t[t.TO_LONG=5]="TO_LONG",t[t.TO_SINGLE=6]="TO_SINGLE",t[t.TO_DOUBLE=7]="TO_DOUBLE",t[t.BRANCH_IFNOT=8]="BRANCH_IFNOT",t[t.BRANCH=9]="BRANCH",t[t.CALL_SUB=10]="CALL_SUB",t[t.GOSUB=11]="GOSUB",t[t.CALL_FUNCTION=12]="CALL_FUNCTION",t[t.EXIT_SUB=13]="EXIT_SUB",t[t.RETURN=14]="RETURN",t[t.DECLARE=15]="DECLARE",t[t.DECLARE_REDIM=16]="DECLARE_REDIM",t[t.LOAD=17]="LOAD",t[t.ASSIGN=18]="ASSIGN",t[t.COPY=19]="COPY",t[t.ADD=20]="ADD",t[t.SUB=21]="SUB",t[t.NEG=22]="NEG",t[t.MUL=23]="MUL",t[t.DIV=24]="DIV",t[t.POW=25]="POW",t[t.IDIV=26]="IDIV",t[t.MOD=27]="MOD",t[t.EQ=28]="EQ",t[t.NEQ=29]="NEQ",t[t.GTE=30]="GTE",t[t.LTE=31]="LTE",t[t.LT=32]="LT",t[t.GT=33]="GT",t[t.OR=34]="OR",t[t.AND=35]="AND",t[t.XOR=36]="XOR",t[t.NOT=37]="NOT",t[t.LOGICNOT=38]="LOGICNOT",t[t.PRINT=39]="PRINT",t[t.LOCATE=40]="LOCATE",t[t.ABS=41]="ABS",t[t.MID=42]="MID",t[t.PEEK=43]="PEEK",t[t.RIGHT=44]="RIGHT",t[t.LEFT=45]="LEFT",t[t.CHR=46]="CHR",t[t.ASC=47]="ASC",t[t.RND=48]="RND",t[t.INT=49]="INT",t[t.FIX=50]="FIX",t[t.END=51]="END",t[t.COLOR=52]="COLOR",t[t.PALETTE=53]="PALETTE",t[t.GET_DRAW_POS=54]="GET_DRAW_POS",t[t.LINE=55]="LINE",t[t.CIRCLE=56]="CIRCLE",t[t.PAINT=57]="PAINT",t[t.DRAW=58]="DRAW",t[t.GET_GRAPHICS=59]="GET_GRAPHICS",t[t.PUT_GRAPHICS=60]="PUT_GRAPHICS",t[t.PSET=61]="PSET",t[t.PRESET=62]="PRESET",t[t.POINT=63]="POINT",t[t.CURRENT_POINT=64]="CURRENT_POINT",t[t.CLS=65]="CLS",t[t.SCREEN=66]="SCREEN",t[t.SLEEP=67]="SLEEP",t[t.INKEY=68]="INKEY",t[t.VAL=69]="VAL",t[t.STR=70]="STR",t[t.TAN=71]="TAN",t[t.SIN=72]="SIN",t[t.LOG=73]="LOG",t[t.COS=74]="COS",t[t.ATN=75]="ATN",t[t.CINT=76]="CINT",t[t.CLNG=77]="CLNG",t[t.CDBL=78]="CDBL",t[t.CSNG=79]="CSNG",t[t.EXP=80]="EXP",t[t.TIMER=81]="TIMER",t[t.RANDOMIZE=82]="RANDOMIZE",t[t.READ=83]="READ",t[t.RESTORE=84]="RESTORE",t[t.LEN=85]="LEN",t[t.LTRIM=86]="LTRIM",t[t.RTRIM=87]="RTRIM",t[t.LCASE=88]="LCASE",t[t.UCASE=89]="UCASE",t[t.INSTR=90]="INSTR",t[t.SPACE=91]="SPACE",t[t.DEBUGLOG=92]="DEBUGLOG",t[t.ON_ERROR_GOTO=93]="ON_ERROR_GOTO",t[t.RESUME=94]="RESUME",t[t.RESUME_NEXT=95]="RESUME_NEXT",t[t.RESUME_GOTO=96]="RESUME_GOTO",t[t.VIEW=97]="VIEW",t[t.VIEW_PRINT=98]="VIEW_PRINT",t[t.STRING=99]="STRING",t[t.NOP=100]="NOP"}(V||(V={}));const U=new Set([V.TO_INT,V.TO_LONG,V.TO_SINGLE,V.TO_DOUBLE,V.ASSIGN,V.COPY,V.ADD,V.SUB,V.NEG,V.MUL,V.DIV,V.POW,V.IDIV,V.MOD,V.EQ,V.NEQ,V.GTE,V.LTE,V.LT,V.GT,V.OR,V.AND,V.XOR,V.NOT,V.LOGICNOT,V.ABS,V.MID,V.RIGHT,V.LEFT,V.CHR,V.ASC,V.INT,V.FIX,V.STR,V.TAN,V.SIN,V.LOG,V.COS,V.ATN,V.CINT,V.CLNG,V.CDBL,V.CSNG,V.EXP]),W=new Set([V.BRANCH_IFNOT,V.BRANCH,V.CALL_SUB,V.GOSUB,V.CALL_FUNCTION,V.RETURN,V.ON_ERROR_GOTO,V.RESUME_GOTO]),H=32767,G=-32768,z=2147483647,_=-2147483648;class X{constructor(t,e){this.type=t,this.stackOffset=e}}class j{constructor(t,e,r){this.keepCursor=t,this.prompt=e,this.inputs=r}parseInput(t){const e=[];let r=!0;for(const i of this.inputs){if(t=t.trim(),!r){if(","!==t[0])return;t=t.substr(1).trim()}switch(r=!1,i.type){case s.kString:{const r=/[^,]*/.exec(t);if(!r)return;e.push(J.single(v,r[0])),t=t.substr(r[0].length);break}case s.kInt:{const r=/[+-]?[0-9]*/.exec(t);if(!r)return;const i=parseInt(r[0],10);if(i>H||i<G)return;e.push(J.newInt(i)),t=t.substr(r[0].length);break}case s.kLongInt:{const r=/[+-]?[0-9]*/.exec(t);if(!r)return;const i=parseInt(r[0],10);if(i>z||i<_)return;e.push(J.newLong(i)),t=t.substr(r[0].length);break}case s.kSingle:{const r=/^[+-]?([0-9]+([.][0-9]*([EeDd][+-][0-9]+)?)?)|(\.[0-9]+([EeDd][+-][0-9]+)?)/.exec(t);if(!r)return;const i=parseFloat(r[0]);e.push(J.single(b,i)),t=t.substr(r[0].length);break}case s.kDouble:{const r=/^[+-]?([0-9]+([.][0-9]*([EeDd][+-][0-9]+)?)?)|(\.[0-9]+([EeDd][+-][0-9]+)?)/.exec(t);if(!r)return;const i=parseFloat(r[0]);e.push(J.single(y,i)),t=t.substr(r[0].length);break}}}if(""===t.trim())return e}}function K(t){switch(t.type){case s.kString:return"";case s.kInt:case s.kLongInt:case s.kSingle:case s.kDouble:return 0;case s.kUserType:return[]}return null}class q{}class Y{}class J{constructor(t){this.type=t}static single(t,e){const r=new J(t);return r.val=e,r}static newDouble(t){return J.single(y,t)}static newString(t){return J.single(v,t)}static newInt(t){return J.single(m,t)}static newLong(t){return J.single(x,t)}static valToType(t,e){return e===m?et(t):e===x?it(t):e===b?Math.fround(t):t}static fieldType(t,e){let r=t;for(let t=0;t<e.length-1;t++){const i=e[t];r=r.fields[i].type}return r.fields[e[e.length-1]].type}toString(){const t=this.dims?"("+this.dims.map(t=>""+t).join(", ")+")":"";return`'${this.val}' ${this.type} ${t}`}anyval(){return this.val}numVal(){return this.val}strVal(){return this.val}toShortString(){const t=this.dims?"("+this.dims.map(t=>""+t).join(", ")+")":"";let e="";if(this.type.isNumeric())e=f(this.type.type);else{if(this.type.isString())return`'${this.val.replace(/\n/,"\\n")}'${t}`;e=this.type.toString()}return`${this.val}${e}${t}`}indexOffset(t){const e=this.dims||[10];let r=0;for(let i=0;i<t.length;i++){if(t[i]>e[i])return new q;r*=1+e[i],r+=t[i]}return r}valAtIndex(t,e){if(!t)return e?this.getField(this.val,e):new q;const r=this.indexOffset(t);if(r instanceof q)return r;if(!this.arrayVals||r>=this.arrayVals.length){const t=K(this.type);return e?this.getField(t,e):J.single(this.type,t)}return e?this.getField(this.arrayVals[r],e):J.single(this.type,this.arrayVals[r])}setVal(t,e,r){if(e){const i=this.indexOffset(e);if(i instanceof q)return i;for(this.arrayVals||(this.arrayVals=[]);i>=this.arrayVals.length;)this.arrayVals.push(K(this.type));r?this.setField(this.arrayVals[i],t,r):this.arrayVals[i]=J.valToType(t,this.type)}else r?this.setField(this.val,t,r):this.val=J.valToType(t,this.type)}isZero(){return!this.val}copySingle(){return J.single(this.type,this.val)}copyDecl(){const t=new J(this.type);return t.val=this.val,void 0!==this.dims&&(t.dims=this.dims),t}getNumber(){return this.val}getString(){return this.val}getField(t,e){let r=this.type;for(let i=0;i<e.length;i++){const n=e[i];if(t.length<=n)break;if(i===e.length-1)return J.single(r.fields[n].type,t[n]);r=r.fields[n].type,t=t[n]}const i=J.fieldType(this.type,e);return J.single(i,K(i))}setField(t,e,r){let i=this.type;for(let n=0;n<r.length;n++){const s=r[n];for(;t.length<=s;)t.push(K(i.fields[t.length].type));n===r.length-1?t[s]=J.valToType(e,i.fields[s].type):(i=i.fields[s].type,t=t[s])}}}function Z(t){if(void 0!==t)return Math.round(t.numVal())}class Q{constructor(t,e){this.id=t,this.args=e}static argString(t){return t instanceof J?t.toString():""+t}static parameterTypeFromList(t,e,r=""){return t<e.length?e[t]:r}toString(t){return`${V[this.id]} ${this.args.map((e,r)=>t.instructionArgToString(this,e,r)).join(", ")}`}parameterType(t){switch(this.id){case V.ASSIGN:case V.LOAD:return 0===t?"S":1===t?"S":2===t?"index":"fieldIndex";case V.INPUT:return"InputSpec";case V.BRANCH_IFNOT:return 0===t?"PC":"S";case V.CALL_SUB:return 0===t?"PC":1===t?"stacksize":"S";case V.GOSUB:return 0===t?"PC":"stacksize";case V.CALL_FUNCTION:return 0===t?"PC":1===t?"stacksize":2===t?"S":"argnames";case V.EXIT_SUB:return"";case V.RETURN:case V.ON_ERROR_GOTO:case V.RESUME_GOTO:case V.BRANCH:return"PC";case V.READ:return 0===t?"S":"baseType";case V.RESTORE:return"DP";case V.LINE:return t<=4?"S":5===t?"option":"style";case V.DECLARE:return 0===t?"S":"V";case V.DECLARE_REDIM:return 1===t?"V":"S";case V.PUT_GRAPHICS:return t<3?"S":"ActionVerb";case V.VIEW:return 0===t?"screen":"S";case V.VIEW_PRINT:case V.STRING:case V.COPY:case V.CIRCLE:case V.PAINT:case V.DRAW:case V.ADDRESS:case V.TO_INT:case V.TO_LONG:case V.TO_SINGLE:case V.TO_DOUBLE:case V.ADD:case V.ADD:case V.SUB:case V.NEG:case V.MUL:case V.DIV:case V.POW:case V.IDIV:case V.MOD:case V.EQ:case V.NEQ:case V.GTE:case V.LTE:case V.LT:case V.GT:case V.OR:case V.AND:case V.XOR:case V.NOT:case V.LOGICNOT:case V.PRINT:case V.LOCATE:case V.ABS:case V.MID:case V.PEEK:case V.RIGHT:case V.LEFT:case V.CHR:case V.ASC:case V.RND:case V.INT:case V.FIX:case V.END:case V.COLOR:case V.PALETTE:case V.GET_DRAW_POS:case V.GET_GRAPHICS:case V.PSET:case V.PRESET:case V.POINT:case V.CURRENT_POINT:case V.CLS:case V.SCREEN:case V.SLEEP:case V.INKEY:case V.VAL:case V.STR:case V.TAN:case V.SIN:case V.LOG:case V.COS:case V.ATN:case V.CINT:case V.CLNG:case V.CDBL:case V.CSNG:case V.EXP:case V.TIMER:case V.RANDOMIZE:case V.LEN:case V.LTRIM:case V.RTRIM:case V.LCASE:case V.UCASE:case V.INSTR:case V.SPACE:case V.DEBUGLOG:case V.INPUT_FUNC:case V.LINE_INPUT:case V.NOP:return void 0!==this.args[t]?"S":"";default:throw new Error("missing case "+this.id)}}shiftStackOffset(t,e){for(let r=0;r<this.args.length;r++){const i=this.parameterType(r);"S"!==i&&"stack-size"!==i||(e||this.args[r]>=0)&&(this.args[r]=this.args[r]+t)}}mapStackOffset(t){for(let e=0;e<this.args.length;e++)"S"===this.parameterType(e)&&void 0!==this.args[e]&&(this.args[e]=t(this.args[e]));if((this.id===V.ASSIGN||this.id===V.LOAD)&&void 0!==this.args[2])for(let e=0;e<this.args[2].length;e++)this.args[2][e]=t(this.args[2][e]);if(this.id===V.INPUT){const e=this.args[0];for(const r of e.inputs)r.stackOffset=t(r.stackOffset)}}}class ${constructor(){this.inst=[],this.data=[],this.dataList=[],this.statementOffsets=[],this.instToLine=new Map}toString(){return this.inst.map((t,e)=>`${e}\t`+t.toString(this)).join("\n")}instructionLineNumber(t){return this.instToLine.get(t)}instructionArgToString(t,e,r){switch(t.parameterType(r)){case"S":{const t=e;if(t&D){const e=t^D;return e<this.data.length?this.data[e].toShortString().replace(/\n/,"\\n"):"g"+(t^D)}return"s"+t}}return"string"==typeof e?e:""+e}sourceListingWithByteCode(t,e){const r=new Map;let i=0;for(let t=0;t<this.inst.length;t++){let e=this.instToLine.get(t);void 0===e?e=i:i=e;const n=r.get(e+1);n?r.set(e+1,[n[0],t]):r.set(e+1,[t,t])}const n=(t||"").split("\n"),s=[],o=(t,r)=>{for(let i=t;i<=r;i++){const t=e&&e.get(i)||"";s.push(`${t}\t[${i}]${this.inst[i].toString(this)}`)}};for(let t=0;t<n.length;t++){const e=r.get(t);void 0!==e&&o(e[0],e[1]),s.push(`${t}\t${n[t]}`)}return s.join("\n")}instructionOffsetToStatementIndex(t){for(let e=1;e<this.statementOffsets.length;e++)if(this.statementOffsets[e]>t)return e-1;return this.statementOffsets.length-1}statementIndexToInstructionOffset(t){return t>=this.statementOffsets.length?0:this.statementOffsets[t]}}class tt{constructor(){this.pc=0,this.stackOffset=0}}function et(t){return(t=Math.round(t)%65536)>32767&&(t=-65536+t),t}function rt(t){return t>=0?t:t+65536}function it(t){return(t=Math.round(t)%4294967296)>2147483647&&(t=-4294967296+t),t}class nt{constructor(){this.seed=327680}next(){this.seed=16598013*this.seed+12820163&16777215}float(){return Math.fround(this.seed/16777216)}}function st(t){return t.startsWith("-0.")?t="-."+t.substr(2):t.startsWith("0.")&&(t=t.substr(1)),t.startsWith("-")||(t=" "+t),t+" "}class ot{constructor(t,e){this.prog=t,this.vpc=e,this.stack=[],this.exception=null,this.waiting=!1,this.done=!1,this.frame=new tt,this.moduleFrame=this.frame,this.lastPointX=0,this.lastPointY=0,this.rnd=new nt,this.readPos=0;for(const e of t.data)this.stack.push(e.copySingle())}dumpStack(){const t=[];for(let e=0;e<this.stack.length;e++){const r=this.stack[e];r instanceof J&&t.push(`${e}\t${r.toShortString()}`)}return t.join("\n")}debugDump(){const t=new Map;let e=this.frame,r=0;for(;e;)t.set(e.pc-1,""+r++),e=e.parent;const i=this.prog.sourceListingWithByteCode(this.prog.source,t);return`---- STACK ----\n${this.dumpStack()}\n---- PROGRAM ----\n${i}\n`}destroy(){this.exception="destroyed"}readValOrUndefined(t){if(void 0!==t)return this.read(t)}read(t){return t&D?this.stack[t^D]:this.stack[t+this.frame.stackOffset]}readShared(t){return this.stack[t]}readValShared(t){return this.readShared(t)}save(t,e){if(t&D)this.stack[t^D]=e;else{for(;this.stack.length<=t;)this.stack.push(J.single(m,0));this.stack[t+this.frame.stackOffset]=e}}run(t=1e4){this.inRun=!0;let e=0;for(e=0;e<t&&!this.exception&&!this.waiting;e++)try{if(!this.step())break}catch(t){this.raise("internal error: "+t)}e===t&&this.vpc.sleep(.001,()=>{this.waiting=!1,this.unpause()}),this.inRun=!1}start(){this.run()}currentLine(){return this.prog.instructionLineNumber(this.frame.pc)}raise(t){if(void 0!==this.onErrorPC){for(;this.frame.parent;)this.frame=this.frame.parent;return this.errorInstructionOffset=this.frame.pc,void(this.frame.pc=this.onErrorPC)}this.exception=t,this.onException&&this.onException(t,this.currentLine())}end(){this.done=!0,this.onEnd&&this.onEnd()}unpause(){this.inRun||this.run()}step(){if(this.frame.pc>=this.prog.inst.length)return this.end(),!1;this.waiting&&console.error("called step while in wait");const t=this.prog.inst[this.frame.pc],e=t.args;switch(this.frame.pc++,t.id){case V.LOAD:{const t=e[0],r=e[1],i=e[2],n=e[3];let s;i&&(s=i.map(t=>this.read(t).val));const o=this.read(r);if(s||n){const e=o.valAtIndex(s,n);e instanceof Y?this.raise("internal error"):e instanceof q?(this.frame.pc--,this.raise("index out of range")):this.save(t,e)}else this.save(t,o);break}case V.ADDRESS:this.save(e[0],this.read(e[1]));break;case V.DECLARE:this.save(e[0],e[1].copyDecl());break;case V.DECLARE_REDIM:{const t=[];for(let r=2;r<e.length;r++)t.push(this.read(e[r]).numVal());const r=e[1].copyDecl();r.dims=t,this.save(e[0],r);break}case V.ASSIGN:{const t=this.read(e[1]);let r=e.length>2?e[2]:void 0;r&&(r=r.map(t=>this.read(t).getNumber()));const i=e.length>3?e[3]:void 0;this.read(e[0]).setVal(t.val,r,i);break}case V.COPY:{const t=this.read(e[1]);this.save(e[0],t.copySingle());break}case V.ADD:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.single(t.type,t.anyval()+r.anyval()));break}case V.SUB:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.single(t.type,t.anyval()-r.anyval()));break}case V.NEG:{const t=this.read(e[1]);this.save(e[0],J.single(t.type,-t.anyval()));break}case V.MUL:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.single(t.type,t.anyval()*r.anyval()));break}case V.DIV:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.newDouble(t.anyval()/r.anyval()));break}case V.POW:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.newDouble(Math.pow(t.anyval(),r.anyval())));break}case V.IDIV:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.newLong(Math.floor(t.anyval()/r.anyval())));break}case V.MOD:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.newLong(Math.floor(t.anyval())%Math.floor(r.anyval())));break}case V.EQ:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.newInt(t.val===r.val?-1:0));break}case V.NEQ:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.newInt(t.val!==r.val?-1:0));break}case V.GTE:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.newInt(t.anyval()>=r.anyval()?-1:0));break}case V.LTE:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.newInt(t.anyval()<=r.anyval()?-1:0));break}case V.GT:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.newInt(t.anyval()>r.anyval()?-1:0));break}case V.LT:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.newInt(t.anyval()<r.anyval()?-1:0));break}case V.OR:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.newLong(t.anyval()|r.anyval()));break}case V.AND:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.newLong(t.anyval()&r.anyval()));break}case V.XOR:{const t=this.read(e[1]),r=this.read(e[2]);this.save(e[0],J.newLong(t.anyval()^r.anyval()));break}case V.NOT:{const t=this.read(e[1]);this.save(e[0],J.newLong(~t.anyval()));break}case V.LOGICNOT:{const t=this.read(e[1]);this.save(e[0],J.newLong(t.val?0:-1));break}case V.TO_INT:this.save(e[0],J.newInt(et(this.read(e[1]).val)));break;case V.TO_LONG:this.save(e[0],J.newLong(it(this.read(e[1]).val)));break;case V.TO_SINGLE:this.save(e[0],J.single(b,Math.fround(this.read(e[1]).val)));break;case V.TO_DOUBLE:this.save(e[0],J.single(y,this.read(e[1]).val));break;case V.PRINT:{const t=this.read(e[0]);switch(t.type.type){case s.kSingle:this.vpc.print(st(function(t){const e=""+t;return e.length<8?e:t.toPrecision(7)}(t.val)));break;case s.kString:this.vpc.print(""+t.val);break;default:this.vpc.print(st(""+t.val))}break}case V.LOCATE:this.vpc.locate(void 0!==e[0]?this.read(e[0]).anyval():null,void 0!==e[1]?this.read(e[1]).anyval():null);break;case V.INPUT_FUNC:{this.waiting=!0;const t=t=>{this.save(e[0],J.single(v,t)),this.waiting=!1,this.unpause()};this.vpc.inkeyWait(this.read(e[1]).numVal(),t);break}case V.INPUT:{const t=e[0];this.vpc.print(t.prompt||""),this.waiting=!0;const r=e=>{const i=t.parseInput(e);if(!i)return this.vpc.print("Redo from start\n"),void this.vpc.input(r);this.waiting=!1,this.vpc.print("\n");for(let e=0;e<i.length;e++)this.save(t.inputs[e].stackOffset,i[e]);this.unpause()};this.vpc.input(r);break}case V.LINE_INPUT:{const t=this.readValOrUndefined(e[0]),r=this.readValOrUndefined(e[1]),i=r=>{this.waiting=!1,void 0!==t&&t||this.vpc.print("\n"),this.save(e[2],J.newString(r)),this.unpause()};r&&this.vpc.print(r.strVal()),this.vpc.input(i);break}case V.BRANCH_IFNOT:this.read(e[1]).isZero()&&(this.frame.pc=e[0]);break;case V.BRANCH:this.frame.pc=e[0];break;case V.CALL_SUB:case V.GOSUB:case V.CALL_FUNCTION:{const t=new tt;t.parent=this.frame,t.stackOffset=this.frame.stackOffset+e[1],t.pc=e[0],this.frame=t;break}case V.EXIT_SUB:this.frame=this.frame.parent;break;case V.RETURN:this.frame=this.frame.parent,this.frame.pc=e[0];break;case V.ABS:{const t=this.read(e[1]).copySingle();t.anyval()<0&&(t.val=-t.anyval()),this.save(e[0],t);break}case V.MID:{const t=this.read(e[1]).copySingle(),r=this.read(e[2]);e.length>3?t.val=t.val.substr(Math.max(0,r.numVal()-1),this.read(e[3]).numVal()):t.val=t.val.substr(Math.max(0,r.numVal()-1)),this.save(e[0],t);break}case V.PEEK:this.save(e[0],J.newInt(0));break;case V.LEFT:{const t=this.read(e[1]).copySingle(),r=Math.abs(this.read(e[2]).anyval());t.val=t.val.substr(0,r),this.save(e[0],t);break}case V.RIGHT:{const t=this.read(e[1]).copySingle(),r=Math.abs(this.read(e[2]).anyval()),i=t.val;i.length>r&&(t.val=i.substr(i.length-r)),this.save(e[0],t);break}case V.CHR:{const t=this.read(e[1]).val;this.save(e[0],J.single(v,String.fromCharCode(t)));break}case V.ASC:{const t=this.read(e[1]).val;this.save(e[0],J.newInt(t.charCodeAt(0)));break}case V.RND:e.length,this.rnd.next(),this.save(e[0],J.single(b,this.rnd.float()));break;case V.COLOR:{const t=Math.round(this.read(e[0]).numVal()),r=Math.round(this.read(e[1]).numVal());t>=0&&this.vpc.setForeColor(t),r>=0&&this.vpc.setBackColor(r);break}case V.PALETTE:if(e.length<2)this.vpc.resetPalette();else{const t=Math.round(this.read(e[0]).numVal()),r=Math.round(this.read(e[1]).numVal());this.vpc.setPaletteAttribute(t,r)}break;case V.GET_DRAW_POS:this.save(e[0],J.newInt(this.lastPointX)),this.save(e[1],J.newInt(this.lastPointY));break;case V.PAINT:{const t=this.read(e[0]).numVal(),r=this.read(e[1]).numVal();let i,n;void 0!==e[2]&&(i=this.read(e[2]).numVal()),void 0!==e[3]&&(n=this.read(e[3]).numVal()),this.vpc.paint(Math.round(t),Math.round(r),i,n),this.lastPointX=Math.round(t),this.lastPointY=Math.round(r);break}case V.CIRCLE:{const t=this.read(e[0]).numVal(),r=this.read(e[1]).numVal(),i=this.read(e[2]).numVal();let n,s=0,o=2*Math.PI,a=1;if(void 0!==e[3]&&(n=this.read(e[3]).numVal(),n=Math.round(n)),void 0!==e[4]&&((s=this.read(e[4]).numVal())>2*Math.PI||s<2*-Math.PI)){this.raise("invalid call");break}if(void 0!==e[5]&&((o=this.read(e[5]).numVal())>2*Math.PI||o<2*-Math.PI)){this.raise("invalid call");break}void 0!==e[6]&&(a=this.read(e[6]).numVal()),this.vpc.circle(Math.round(t),Math.round(r),Math.round(i),n,s,o,a),this.lastPointX=Math.round(t),this.lastPointY=Math.round(r);break}case V.LINE:{const t=this.read(e[0]).numVal(),r=this.read(e[1]).numVal(),i=this.read(e[2]).numVal(),n=this.read(e[3]).numVal();let s;void 0!==e[4]&&(s=this.read(e[4]).numVal(),s=Math.round(s));let o=R.kLine;void 0!==e[5]&&(o="B"===e[5]?R.kBox:R.kFilledBox);let a=65535;void 0!==e[6]&&(a=this.read(e[6]).numVal()),this.vpc.line(Math.round(t),Math.round(r),Math.round(i),Math.round(n),s,o,a),this.lastPointX=Math.round(i),this.lastPointY=Math.round(n);break}case V.DRAW:{const t=function(t){const e=[];let r=0,i=new B;const n=()=>{for(;r<t.length&&" "===t[r];)++r},s=()=>{n();const e=/[+-]?\d+/.exec(t.slice(r));if(e)return r+=e[0].length,parseInt(e[0],10)};for(;r<t.length;)switch(t[r]){case"B":i.noDraw=!0,r++;break;case"N":i.returnWhenDone=!0,r++;break;case"U":case"D":case"L":case"R":case"E":case"F":case"G":case"H":if(i.id=P.kMove,i.a="UERFDGLH".indexOf(t[r++]),i.b=s(),void 0===i.b)return;e.push(i),i=new B;break;case"M":if(r++,i.id=P.kMoveXY,n(),"+"!==t[r]&&"-"!==t[r]||(i.c=1),i.a=s(),n(),","!==t[r++])return;if(i.b=s(),void 0===i.a||void 0===i.b)return;e.push(i),i=new B;break;case"A":if(r++,i.id=P.kRotation,i.a=s(),void 0===i.a)return;e.push(i),i=new B;break;case"T":if(r++,i.id=P.kTurn,"A"!==t[r++])return;if(i.a=s(),void 0===i.a)return;e.push(i),i=new B;break;case"C":r++,i.id=P.kColor,i.a=s(),e.push(i),i=new B;break;case"S":r++,i.id=P.kScale,i.a=s(),e.push(i),i=new B;break;case"P":if(r++,i.id=P.kPaint,i.a=s(),n(),","!==t[r++])return;i.b=s(),e.push(i),i=new B;break;case" ":r++;break;default:return}return e}(this.read(e[0]).strVal());t?this.vpc.draw(this.lastPointX,this.lastPointY,t):this.raise("invalid draw command");break}case V.GET_GRAPHICS:{const t=this.read(e[0]).numVal(),r=this.read(e[1]).numVal(),i=this.read(e[2]).numVal(),n=this.read(e[3]).numVal(),s=this.read(e[4]),o=s.dims;if(!o){this.raise("invalid array");break}if(1!==o.length){this.raise("not implemented");break}if(s.type!==m){this.raise("not implemented");break}const a=this.vpc.getGraphics(Math.round(t),Math.round(r),Math.round(i),Math.round(n),2*o[0]);if(!a){this.raise("invalid call");break}for(let t=0;t<a.length;t+=2){const e=a[t],r=t+1<a.length?a[t+1]:0;s.setVal(e+(r<<8),[Math.trunc(t/2)],void 0)}break}case V.PUT_GRAPHICS:{const t=this.read(e[0]).numVal(),r=this.read(e[1]).numVal(),i=this.read(e[2]),n=e[3],s=i.dims;if(!s){this.raise("invalid array");break}if(1!==s.length){this.raise("not implemented");break}if(i.type!==m){this.raise("not implemented");break}const o=new Uint8Array(2*s[0]);for(let t=0;t<o.length;t+=2){const e=rt(i.arrayVals[Math.trunc(t/2)]);o[t]=e%256,t+1<o.length&&(o[t+1]=(e>>8)%256)}this.vpc.putGraphics(Math.round(t),Math.round(r),o,n);break}case V.PSET:{const t=this.read(e[0]).numVal(),r=this.read(e[1]).numVal();let i;void 0!==e[2]&&(i=this.read(e[2]).numVal(),i=Math.round(i)),this.vpc.pset(Math.round(t),Math.round(r),i),this.lastPointX=Math.round(t),this.lastPointY=Math.round(r);break}case V.PRESET:{const t=this.read(e[0]).numVal(),r=this.read(e[1]).numVal();this.vpc.pset(Math.round(t),Math.round(r),this.vpc.backColor()),this.lastPointX=Math.round(t),this.lastPointY=Math.round(r);break}case V.POINT:this.save(e[0],J.newInt(this.vpc.point(Math.round(this.read(e[1]).numVal()),Math.round(this.read(e[2]).numVal()))));break;case V.CURRENT_POINT:switch(this.read(e[1]).numVal()){case 0:case 1:this.save(e[0],J.newInt(this.lastPointX));break;case 2:case 3:this.raise("not implemented");break;default:this.raise("invalid call")}break;case V.CLS:{const t=this.readValOrUndefined(e[0]);t&&1===t.numVal()?this.vpc.clsGraphics():t&&2===t.numVal()?this.vpc.clsText():this.vpc.cls();break}case V.SCREEN:{const t=Z(this.readValOrUndefined(e[2]));let r=Z(this.readValOrUndefined(e[3]));void 0===r&&void 0!==t&&(r=t),this.vpc.screen(Z(this.readValOrUndefined(e[0])),Z(this.readValOrUndefined(e[1])),t,r);break}case V.SLEEP:{const t=this.read(e[0]).numVal();this.waiting=!0,this.vpc.sleep(t,()=>{this.waiting=!1,this.unpause()});break}case V.INKEY:this.save(e[0],J.single(v,this.vpc.inkey()));break;case V.VAL:this.save(e[0],J.newDouble(parseFloat(this.read(e[1]).strVal())));break;case V.STR:{const t=this.read(e[1]).val;let r;r="number"==typeof t&&t>=0?" "+t:""+t,this.save(e[0],J.single(v,""+r));break}case V.TAN:this.save(e[0],J.newDouble(Math.tan(this.read(e[1]).numVal())));break;case V.SIN:this.save(e[0],J.newDouble(Math.sin(this.read(e[1]).numVal())));break;case V.COS:this.save(e[0],J.newDouble(Math.cos(this.read(e[1]).numVal())));break;case V.LOG:{const t=this.read(e[1]).numVal();if(t<=0){this.raise("Illegal function call");break}this.save(e[0],J.newDouble(Math.log(t)));break}case V.ATN:this.save(e[0],J.newDouble(Math.atan(this.read(e[1]).numVal())));break;case V.CINT:this.save(e[0],J.newInt(Math.round(et(this.read(e[1]).numVal()))));break;case V.CLNG:this.save(e[0],J.newLong(Math.round(it(this.read(e[1]).numVal()))));break;case V.CDBL:this.save(e[0],J.newDouble(this.read(e[1]).numVal()));break;case V.CSNG:this.save(e[0],J.single(b,this.read(e[1]).numVal()));break;case V.EXP:this.save(e[0],J.single(y,Math.exp(this.read(e[1]).numVal())));break;case V.FIX:this.save(e[0],J.single(y,Math.trunc(this.read(e[1]).numVal())));break;case V.INT:this.save(e[0],J.single(y,Math.floor(this.read(e[1]).numVal())));break;case V.TIMER:{const t=new Date,r=new Date(t.getFullYear(),t.getMonth(),t.getDate(),0,0,0),i=t.getTime()-r.getTime();this.save(e[0],J.single(y,i/1e3));break}case V.RANDOMIZE:this.rnd.seed=it(this.read(e[0]).numVal());break;case V.READ:{if(this.readPos>=this.prog.dataList.length){this.raise("Out of DATA");break}const t=this.prog.data[this.prog.dataList[this.readPos++]],r=e[1];let i;if(t.type===v){if(r!==s.kString){this.raise("syntax error");break}i=t.val}else i=function(t,e){switch(e){case s.kString:return""+t;case s.kInt:return et(t);case s.kLongInt:return it(t);case s.kSingle:return Math.fround(t);case s.kDouble:return t}return t}(t.numVal(),r);this.save(e[0],J.single(g.basic(r),i));break}case V.RESTORE:this.readPos=e[0];break;case V.LEN:this.save(e[0],J.newLong(this.read(e[1]).strVal().length));break;case V.LTRIM:this.save(e[0],J.newString(this.read(e[1]).strVal().trimLeft()));break;case V.RTRIM:this.save(e[0],J.newString(this.read(e[1]).strVal().trimRight()));break;case V.UCASE:this.save(e[0],J.newString(this.read(e[1]).strVal().toUpperCase()));break;case V.INSTR:{const t=this.read(e[1]).numVal(),r=this.read(e[2]).strVal(),i=this.read(e[3]).strVal();""===i?this.save(e[0],J.newInt(t)):this.save(e[0],J.newInt(r.indexOf(i,t-1)+1));break}case V.LCASE:this.save(e[0],J.newString(this.read(e[1]).strVal().toLowerCase()));break;case V.SPACE:{const t=this.read(e[1]).numVal();this.save(e[0],J.newString(" ".repeat(t)));break}case V.ON_ERROR_GOTO:this.onErrorPC=e[0];break;case V.RESUME:if(void 0!==this.errorInstructionOffset){const t=this.prog.instructionOffsetToStatementIndex(this.errorInstructionOffset);this.frame.pc=this.prog.statementIndexToInstructionOffset(t),this.errorInstructionOffset=void 0}break;case V.RESUME_NEXT:if(void 0!==this.errorInstructionOffset){const t=this.prog.instructionOffsetToStatementIndex(this.errorInstructionOffset);this.frame.pc=this.prog.statementIndexToInstructionOffset(t+1),this.errorInstructionOffset=void 0}break;case V.RESUME_GOTO:void 0!==this.errorInstructionOffset&&(this.frame.pc=e[0],this.errorInstructionOffset=void 0);break;case V.VIEW:{const t=e[0],r=this.read(e[1]).numVal(),i=this.read(e[2]).numVal(),n=this.read(e[3]).numVal(),s=this.read(e[4]).numVal(),o=this.readValOrUndefined(e[6]),a=this.readValOrUndefined(e[7]);void 0!==a&&this.vpc.line(r-1,i-1,n+1,s+1,a.numVal(),R.kBox,65535),void 0!==o&&this.vpc.line(r,i,n,s,o.numVal(),R.kFilledBox,65535),this.vpc.setView(r,i,n,s,t);break}case V.VIEW_PRINT:{const t=this.vpc.screenLines(),r=this.read(e[0]).numVal(),i=this.read(e[1]).numVal();if(r<1||i<1||r>i||i>t||r>t){this.raise("invalid call");break}this.vpc.setViewPrint(r,i);break}case V.STRING:{const t=this.read(e[1]).numVal(),r=this.read(e[2]).strVal();this.save(e[0],J.newString(r.substr(0,1).repeat(t)));break}case V.NOP:break;case V.DEBUGLOG:console.log(this.read(e[0]).strVal());break;case V.END:return this.end(),!1;default:console.log("Not implemented: "+V[t.id])}return!0}resume(t){const e=this.prog.instructionOffsetToStatementIndex(t);this.frame.pc=this.prog.statementIndexToInstructionOffset(e),this.errorInstructionOffset=void 0}resumeNext(t){this.errorInstructionOffset=void 0}}const at=1073741824,lt=536870912,ct=268435456,ht=at|lt|ct;var ut;!function(t){t[t.kIF=0]="kIF",t[t.kFOR=1]="kFOR",t[t.kDO=2]="kDO",t[t.kWHILE=3]="kWHILE",t[t.kSELECT=4]="kSELECT"}(ut||(ut={}));class ft{constructor(t){this.type=t,this.endInstructions=[],this.caseInstOffset=[],this.endCaseInstructions=[]}}class dt{constructor(t,e){this.sourceBlock=t,this.inst=e}setLabelOrLineNumber(t){"string"==typeof t?this.label=t:this.lineNumber=t}}class pt{constructor(t,e){this.name=t,this.args=e,this.calls=[],this.blockInfo=new gt}}class gt{constructor(){this.startPc=-1,this.argCount=0,this.declareInstructions=[],this.inst=[],this.instToLine=new Map,this.startShift=0,this.statementOffsets=[]}setStartPC(t){for(const e of this.inst)W.has(e.id)&&e.args.length>0&&(e.args[0]+=t-this.startPc);for(let e=0;e<this.statementOffsets.length;e++)this.statementOffsets[e]+=t-this.startPc;this.startPc=t}insertInstructions(t,e){if(!(e<=0)){for(let t=0;t<e;t++)this.inst.push(void 0);for(let r=this.inst.length-1;r>=t+e;r--){this.inst[r]=this.inst[r-e],this.inst[r-e]=void 0;const t=this.instToLine.get(r-e);void 0!==t&&(this.instToLine.delete(r-e),this.instToLine.set(r,t))}for(let t=0;t<this.statementOffsets.length;t++)this.statementOffsets[t]+=e}}insertDeclareInstructions(){if(this.declareInstructions.length){this.insertInstructions(0,this.declareInstructions.length);for(let t=0;t<this.declareInstructions.length;t++)this.inst[t]=this.declareInstructions[t];this.startShift=this.declareInstructions.length,this.declareInstructions=[]}}}class mt{constructor(t,e){this.block=t,this.instOffset=e}getPC(){return this.block.startPc+this.instOffset+this.block.startShift}}class vt{constructor(t,e){this.type=t,this.builtin=e,this.calls=[],this.blockInfo=new gt}static builtin(t,e){const r=new vt(t,!0);return e&&(r.builtinOp=e),r}}class yt{constructor(t,e){this.instructionIndex=t,this.dataOffset=e}}class bt{constructor(t,e){this.restoreInst=t,this.lbl=e}}class xt{constructor(){this.functions=new Map,this.types=new Map,this.subs=new Map,this.constantVals=new Map,this.lineNumbers=new Map,this.labels=new Map,this.program=new $,this.errors=[],this.errorLocations=[],this.gotos=[],this.restores=[],this.currentLine=0,this.dataOffsets=[],this.isEnd=!1,this.globalVarCount=0,this.constCount=0}}class wt{constructor(){this.g=new xt,this.dimVars=new Map,this.autoVars=new Map,this.constVars=new Map,this.stackOffset=0,this.blockInfo=new gt,this.reservedStackSlots=0,this.ctrlFlowStack=[],this.tempVarCount=0,this.finalized=!1,this.localVarCount=0,this.blockInfo.startPc=0}static valConstKey(t){return t.isLiteral()||t.isConst()?`${t.type}${t.type.isString()?t.stringValue:t.numberValue}`:""}static literalVarVal(t){const e=new J(t.type);switch(t.baseType()){case s.kString:e.val=t.stringValue;break;case s.kInt:e.val=et(t.numberValue);break;case s.kLongInt:e.val=it(t.numberValue);break;case s.kSingle:e.val=Math.fround(t.numberValue);break;case s.kDouble:e.val=t.numberValue}return e}setLocator(t){this.g.locator=t}program(){return this.g.program}errors(){return this.g.errors}errorLocations(){return this.g.errorLocations}error(t,e){e instanceof o&&(e=e.loc),e?(this.g.errors.push(t+" at "+e.toString()),this.g.errorLocations.push(e)):(this.g.errors.push(t),this.g.errorLocations.push(new i(this.g.currentLine,0)))}defineType(t,e){this.g.types.has(t.utext())?this.error("duplicate definition",t.loc):e&&this.g.types.set(t.utext(),e)}typename(t){switch(t.utext()){case"INTEGER":return m;case"STRING":return v;case"DOUBLE":return y;case"SINGLE":return b;case"LONG":return x}return this.g.types.get(t.utext())}label(t){this.g.labels.set(t.text.toUpperCase(),this.branchTargetHere())}lineNumber(t,e){this.g.lineNumbers.has(t)?this.error("duplicate label",e.loc):this.g.lineNumbers.set(t,this.branchTargetHere())}newline(t){this.g.currentLine=t}newStmt(){const t=this.blockInfo.inst.length;0!==this.blockInfo.statementOffsets.length&&this.blockInfo.statementOffsets[this.blockInfo.statementOffsets.length-1]===t||this.blockInfo.statementOffsets.push(t)}data(t){this.g.dataOffsets.push(new yt(this.branchTargetHere(),this.program().dataList.length)),this.emit(V.NOP);for(const e of t){const t=this.constDataVal(e);if(!t){this.error("internal error");break}this.g.program.dataList.push(t.stackOffset&~ct)}}restore(t){this.g.restores.push(new bt(this.emit(V.RESTORE,0),t))}read(t){const e=this.nextStackOffset();for(const r of t){if(!r.isVar)return void this.error("READ parameter not a variable");if(!r.type.isBasic())return void this.error("Expected basic type");this.write(V.READ,e,r.baseType()),this.assign(r,e)}}endStmt(){this.stackOffset=this.reservedStackSlots}findVariable(t,e){t=t.toUpperCase();{const e=this.dimVars.get(t);if(e)return e}{const e=this.constVars.get(t);if(e)return e}const r=t+f(e),i=this.autoVars.get(r);if(i)return i;if(this.parent){const r=this.parent.findVariable(t,e);if(r&&r.shared)return r}}variable(t,e,r){let i,n="";t instanceof o?(n=t.text,i=t.loc):n=t;const a=this.findVariable(n,e);if(a)return e!==s.kNone&&a.baseType()!==e?void this.error("duplicate definition",i):a;if(void 0===r)return;const l=k.newVar(n,r);this.parent?l.stackOffset=lt|this.localVarCount++:l.stackOffset=at|this.g.globalVarCount++,this.autoVars.set(n.toUpperCase()+f(e),l);const c=J.single(l.type,K(l.type));return this.blockInfo.declareInstructions.push(new Q(V.DECLARE,[l.stackOffset,c])),l}declConst(t,e,r){if(!r.isLiteral()&&!r.isConst())return void this.error("cannot assign const to dynamic value");if(e&&function(t){return t===s.kInt?m:t===s.kString?v:t===s.kLongInt?x:t===s.kNone||t===s.kSingle?b:t===s.kDouble?y:void 0}(e)!==r.type)return void this.error("type mismatch");const i=k.newConst(t.text,r.type,r.type===v?r.stringValue:r.numberValue);this.constVars.set(t.text.toUpperCase(),i)}index(t,e){if(t.isVar()){if(!e)return;if(void 0!==t.argIndex&&!t.isArrayArg)return void this.error("not an array variable");const r=t.size?t.size.length:1;return t.isArrayArg||e.length===r?((t=t.copy()).index=e,t):void this.error("wrong number of dimensions")}this.error("index of this kind not implemented")}indexField(t,e){if(!t.isVar()&&!t.isField())return void this.error("syntax error");const r=t.type.lookupField(e.text);if(r)return k.newField(r.name,r.type,t);this.error("invalid field")}dim(t,e,r,i,n){const s=t instanceof o?t.text:t,a=t instanceof o?t.loc:void 0,l=this.dimVars.get(s.toUpperCase());if(void 0!==l&&!n)return void this.error("duplicate definition",a);for(const t of["$","%","&","!","#",""])if(this.autoVars.has(s.toUpperCase()+t))return void this.error("duplicate definition",a);if(void 0!==l){if(!l.type.equals(r))return void this.error("mismatched types",a);if(void 0===l.size){if(void 0!==e)return void this.error("dimension mismatch",a)}else if(void 0===e||e.length!=l.size.length)return void this.error("dimension mismatch",a);if(!l.dynamic)return void this.error("array already dimensioned",a)}let c,h=[],u=!1;if(e){c=[];for(const t of e){const e=[];for(const r of t)if((r.isLiteral()||r.isConst())&&r.type.isNumeric())e.push(r.numberValue);else if(r.kind===w.kUnspecifiedDimSize)u=!0,e.push(0);else{if(!n)return void this.error("expected constant numeric value",r.loc());u=!0}c.push(e[e.length-1])}if(u){for(const t of e){const e=t[t.length-1];e.kind==w.kUnspecifiedDimSize?h.push(this.constNumber(0,m)):h.push(e)}c=h.map(()=>0)}}let f=l;if(f||(f=k.newVar(s,r,c),!this.parent||i?f.stackOffset=at|this.g.globalVarCount++:f.stackOffset=lt|this.localVarCount++,f.dimmed=!0,(u||n)&&(f.dynamic=!0),i&&(f.shared=!0),this.dimVars.set(s.toUpperCase(),f)),n){const t=J.single(f.type,K(f.type));t.dims=c,this.write(V.DECLARE_REDIM,f.stackOffset,t,...h)}else{const t=J.single(f.type,K(f.type));t.dims=c,this.blockInfo.declareInstructions.push(new Q(V.DECLARE,[f.stackOffset,t]))}}binaryOpType(t,e){return t.type===s.kString&&e.type===s.kString?v:t.type===s.kString||e.type===s.kString||t.type===s.kUserType||e.type===s.kUserType?(this.error("invalid type"),t):t.type===s.kDouble||e.type===s.kDouble?y:t.type===s.kSingle||e.type===s.kSingle?b:t.type===s.kLongInt||e.type===s.kLongInt?x:t.type===s.kInt||e.type===s.kInt?m:(this.error("invalid type"),t)}convert(t,e){if(t.type.equals(e))return t;if(t.type.isNumeric()&&e.isNumeric())switch(e.type){case s.kInt:{const e=k.newStackValue(m,this.nextStackOffset());return this.write(V.TO_INT,e,t),e}case s.kLongInt:{const e=k.newStackValue(x,this.nextStackOffset());return this.write(V.TO_LONG,e,t),e}case s.kSingle:{const e=k.newStackValue(b,this.nextStackOffset());return this.write(V.TO_SINGLE,e,t),e}case s.kDouble:{const e=k.newStackValue(y,this.nextStackOffset());return this.write(V.TO_DOUBLE,e,t),e}}else this.error("cannot convert value")}pushCompatibleOperands(t,e){const r=this.binaryOpType(t.type,e.type),i=this.convert(t,r),n=this.convert(e,r);if(i&&n)return[i,n]}op(t,e){switch(t){case"=":{const t=this.pushCompatibleOperands(e[0],e[1]);if(!t)return;const r=this.newStackValue(m);return this.write(V.EQ,r,t[0],t[1]),r}case"=>":case">=":{const t=this.pushCompatibleOperands(e[0],e[1]);if(!t)return;const r=this.newStackValue(m);return this.write(V.GTE,r,t[0],t[1]),r}case"=<":case"<=":{const t=this.pushCompatibleOperands(e[0],e[1]);if(!t)return;const r=this.newStackValue(m);return this.write(V.LTE,r,t[0],t[1]),r}case">":{const t=this.pushCompatibleOperands(e[0],e[1]);if(!t)return;const r=this.newStackValue(m);return this.write(V.GT,r,t[0],t[1]),r}case"<":{const t=this.pushCompatibleOperands(e[0],e[1]);if(!t)return;const r=this.newStackValue(m);return this.write(V.LT,r,t[0],t[1]),r}case"<>":{const t=this.pushCompatibleOperands(e[0],e[1]);if(!t)return;const r=this.newStackValue(m);return this.write(V.NEQ,r,t[0],t[1]),r}case"OR":{if(!this.expectNumeric(e[0])||!this.expectNumeric(e[1]))return S;const t=e[0],r=e[1],i=this.newStackValue(x);return this.write(V.OR,i,t,r),i}case"AND":{if(!this.expectNumeric(e[0])||!this.expectNumeric(e[1]))return S;const t=e[0],r=e[1],i=this.newStackValue(x);return this.write(V.AND,i,t,r),i}case"XOR":{if(!this.expectNumeric(e[0])||!this.expectNumeric(e[1]))return S;const t=e[0],r=e[1],i=this.newStackValue(x);return this.write(V.XOR,i,t,r),i}case"assign":{const t=e[0],r=e[1];return this.assignVal(t,r),S}case"ABS":{const t=k.newStackValue(e[0].type,this.nextStackOffset());return this.write(V.ABS,t,e[0]),t}case"PRINT":{let t=!1;for(const r of e)t=!1,r.isCommaDelim()?(t=!0,this.write(V.PRINT,k.newStringLiteral("\t"))):r.isSemicolonDelim()?t=!0:this.write(V.PRINT,r);return void(t||this.write(V.PRINT,k.newStringLiteral("\n")))}case"SWAP":{if(e[0].type!==e[1].type)return void this.error("SWAP with mismatched types");const[t,r]=e,i=this.nextStackOffset(),n=this.nextStackOffset();this.loadVar(i,t),this.loadVar(n,r);return this.assign(t,n),void this.assign(r,i)}case"+":{const t=this.pushCompatibleOperands(e[0],e[1]);if(!t)return;const r=this.newStackValue(t[0].type);return this.write(V.ADD,r,t[0],t[1]),r}case"-":{if(1===e.length){const t=this.newStackValue(e[0].type);return this.write(V.NEG,t,e[0]),t}const t=this.pushCompatibleOperands(e[0],e[1]);if(!t)return;const r=this.newStackValue(t[0].type);return this.write(V.SUB,r,t[0],t[1]),r}case"*":{const t=this.pushCompatibleOperands(e[0],e[1]);if(!t)return;const r=this.newStackValue(t[0].type);return this.write(V.MUL,r,t[0],t[1]),r}case"/":{const t=this.pushCompatibleOperands(e[0],e[1]);if(!t)return;const r=this.newStackValue(y);return this.write(V.DIV,r,t[0],t[1]),r}case"^":{const t=this.pushCompatibleOperands(e[0],e[1]);if(!t)return;const r=this.newStackValue(y);return this.write(V.POW,r,t[0],t[1]),r}case"\\":{const t=this.pushCompatibleOperands(e[0],e[1]);if(!t)return;const r=this.newStackValue(x);return this.write(V.IDIV,r,t[0],t[1]),r}case"MOD":{const t=this.pushCompatibleOperands(e[0],e[1]);if(!t)return;const r=this.newStackValue(x);return this.write(V.MOD,r,t[0],t[1]),r}case"NOT":{const t=this.newStackValue(x);return this.write(V.NOT,t,e[0]),t}case"LNOT":{const t=this.newStackValue(x);return this.write(V.LOGICNOT,t,e[0]),t}default:this.error("internal: operator not implemented")}}declSub(t,e){this.g.subs.set(t.utext(),new pt(t.text,e))}declFunction(t,e,r,i){const n=i.map(t=>t.type),s=new vt(new p(r,n),!1);s.name=t.text,this.g.functions.set(s.name.toUpperCase(),s)}setEnd(){this.g.isEnd||(this.g.isEnd=!0,this.write(V.END))}sub(t,e){this.setEnd();let r=this.g.subs.get(t.utext());if(r){if(r.blockInfo.startPc>=0)return this.error("duplicate subroutine name",t.loc),this}else this.declSub(t,e),r=this.g.subs.get(t.utext());if(this.parent)return this.error("subroutine must be at the module level"),this;const i=new wt;for(let t=0;t<e.length;t++){const r=e[t];if(r.kind!==w.kArgument)return this.error("internal error"),this;const n=k.newVar(r.varName,r.type,r.size);n.stackOffset=t,r.isArrayArg&&(n.isArrayArg=!0),r.dimmed?(n.dimmed=!0,i.dimVars.set(n.varName.toUpperCase(),n)):i.autoVars.set(this.autoVarKey(n),n)}return i.reservedStackSlots=e.length,i.stackOffset=e.length,r.blockInfo.argCount=e.length,r.blockInfo.startPc=0,i.g=this.g,i.parent=this,i.subInfo=r,i.blockInfo=r.blockInfo,i}subExit(){this.subInfo?this.write(V.EXIT_SUB):this.error("EXIT outside of sub")}functionBegin(t,e,r,i,n){n||this.setEnd();let s=this.g.functions.get(t.text.toUpperCase());if(s){if(s.blockInfo.startPc>=0)return this.error("function already defined"),this}else this.declFunction(t,e,r,i),s=this.g.functions.get(t.text.toUpperCase());if(this.parent)return this.error("function must be at the module level"),this;const o=new wt;o.g=this.g,o.parent=this,o.blockInfo=s.blockInfo,s.blockInfo.argCount=i.length+1,s.blockInfo.startPc=0;const a=k.newVar(t.text,r);a.dimmed=!0,a.stackOffset=0,o.blockInfo.declareInstructions.push(new Q(V.DECLARE,[a.stackOffset,J.single(a.type,K(a.type))])),o.dimVars.set(a.varName.toUpperCase(),a);for(let t=0;t<i.length;t++){const e=i[t];if(e.kind!==w.kArgument)return this.error("internal error"),this;const r=k.newVar(e.varName,e.type,e.size);r.stackOffset=t+1,e.isArrayArg&&(r.isArrayArg=!0),e.dimmed?(r.dimmed=!0,o.dimVars.set(r.varName.toUpperCase(),r)):o.autoVars.set(this.autoVarKey(r),r)}return o.reservedStackSlots=i.length+1,o.stackOffset=i.length+1,o.localVarCount=i.length+1,o.fnInfo=s,o}functionExit(){this.fnInfo?this.write(V.EXIT_SUB):this.error("EXIT FUNCTION outside of FUNCTION")}declArg(t,e,r,i){const n=new k;return n.type=r||m,n.kind=w.kArgument,n.varName=t.text,n.isArrayArg=e,i&&(n.dimmed=!0),n}endSub(){this.subInfo?this.write(V.EXIT_SUB):this.error("internal error")}endFunction(){this.fnInfo?this.write(V.EXIT_SUB):this.error("internal error")}isSub(t){return this.g.subs.has(t)}isConst(t){return this.parent&&this.parent.isConst(t)||this.constVars.has(t.toUpperCase())}isFunction(t){return this.g.functions.has(t.toUpperCase())}lookupFunction(t){const e=this.g.functions.get(t.toUpperCase());if(e)return e.type}callSub(t,e){const r=this.g.subs.get(t.utext());if(!r)return void this.error("not a subroutine");for(const t of e)if(!t)return;e=this.stackifyAll(e);const i=this.stackOffset;for(const t of e){const e=t.stackOffset,r=this.stackOffset++;e&ct?this.write(V.COPY,r,e):this.write(V.ADDRESS,r,e)}r.calls.push(this.emit(V.CALL_SUB,0,i))}callBuiltin(t,e){const r=(t,e,r)=>{const i=this.newStackValue(e);return this.write(t,i,...r),i},i=(t,e)=>{this.write(t,...e)};switch(t){case"__LOG":return i(V.DEBUGLOG,e);case"ASC":return r(V.ASC,m,e);case"ATN":return r(V.ATN,y,e);case"CDBL":return r(V.CDBL,y,e);case"CHR":return r(V.CHR,v,e);case"CINT":return r(V.CINT,m,e);case"CLS":return i(V.CLS,e);case"CLNG":return r(V.CLNG,x,e);case"COS":return r(V.COS,y,e);case"CSNG":return r(V.CSNG,b,e);case"EXP":return r(V.EXP,y,e);case"FIX":case"FIX":return r(V.FIX,y,e);case"FRE":return;case"INKEY":return r(V.INKEY,v,e);case"INPUT":return r(V.INPUT_FUNC,v,e);case"INSTR":return r(V.INSTR,m,e);case"INT":return r(V.INT,y,e);case"LCASE":return r(V.LCASE,v,e);case"LEFT":return r(V.LEFT,v,e);case"LEN":return r(V.LEN,x,e);case"LTRIM":return r(V.LTRIM,v,e);case"MID":return r(V.MID,v,e);case"PEEK":return r(V.PEEK,m,e);case"RIGHT":return r(V.RIGHT,v,e);case"RND":return r(V.RND,b,e);case"RTRIM":return r(V.RTRIM,v,e);case"SIN":return r(V.SIN,y,e);case"LOG":return r(V.LOG,y,e);case"SPACE":return r(V.SPACE,v,e);case"STR":return r(V.STR,v,e);case"TAN":return r(V.TAN,y,e);case"TIMER":return r(V.TIMER,y,e);case"UCASE":return r(V.UCASE,v,e);case"VAL":return r(V.VAL,y,e);case"LINE_INPUT":return i(V.LINE_INPUT,e);case"POINT":return r(V.POINT,m,e);case"CURRENT_POINT":return r(V.CURRENT_POINT,m,e);case"VIEW":return i(V.VIEW,e);case"VIEW_PRINT":return i(V.VIEW_PRINT,e);case"SCREEN":return i(V.SCREEN,e);case"STRING":return r(V.STRING,v,e);case"SLEEP":return i(V.SLEEP,e);case"SOUND":case"BEEP":return}this.error("not implemented")}callFunction(t,e){const r=this.g.functions.get(t.toUpperCase());if(!r)return;if(r.builtin&&r.builtinOp){const t=this.newStackValue(r.type.resultType);return this.write(r.builtinOp,t,...e),t}if(r.builtin){switch(t){case"FRE":return this.constNumber(47724,x)}return void this.error("not implemented")}for(const t of e)if(!t)return;e=this.stackifyAll(e);const i=this.stackOffset,n=this.newStackValue(r.type.resultType);for(const t of e){const e=t.stackOffset,r=this.stackOffset++;e&ct?this.write(V.COPY,r,e):this.write(V.ADDRESS,r,e)}return r.calls.push(this.emit(V.CALL_FUNCTION,0,i)),this.stackOffset=i+1,n}input(t,e,r){const i=[];for(const t of r){if(!t.isVar)return void this.error("INPUT parameter not a variable");if(!t.type.isBasic())return void this.error("Expected basic type");i.push(new X(t.baseType(),this.nextStackOffset()))}this.write(V.INPUT,new j(t,e,i));for(let t=0;t<r.length;t++)this.assign(r[t],i[t].stackOffset)}ifBegin(t){t=this.stackify(t);const e=new ft(ut.kIF);e.branchInst=this.write(V.BRANCH_IFNOT,0,t),this.ctrlFlowStack.push(e)}elseBegin(t){const e=this.ctrlFlow(ut.kIF);e&&(e.endInstructions.push(this.emit(V.BRANCH,0)),e.branchInst&&this.recordBranchTarget(this.branchTargetHere(),e.branchInst),e.branchInst=t?this.write(V.BRANCH_IFNOT,0,t):void 0)}ifEnd(){const t=this.ctrlFlow(ut.kIF);if(t){t.branchInst&&this.recordBranchTarget(this.branchTargetHere(),t.branchInst);for(const e of t.endInstructions)this.recordBranchTarget(this.branchTargetHere(),e);this.ctrlFlowStack.pop()}}selectBegin(t){const e=new ft(ut.kSELECT);this.ctrlFlowStack.push(e),e.selectValue=this.stackify(t,!0)}selectCase(t){const e=this.ctrlFlow();if(!e)return;e.caseInstOffset.length>0&&e.endCaseInstructions.push(this.emit(V.BRANCH,0));const r=this.branchTargetHere();let i;for(const r of t){let t;if(r.single)t=this.op("=",[e.selectValue,r.single]);else if(r.range){const i=this.op(">=",[e.selectValue,r.range[0]]),n=this.op("<=",[e.selectValue,r.range[1]]);if(!i||!n)return;t=this.op("AND",[i,n])}else r.isExpr&&(t=this.op(r.isExpr[0].text,[e.selectValue,r.isExpr[1]]));if(!t)return;i=void 0===i?t:this.op("OR",[i,t])}const n=this.branchTargetHere();this.write(V.BRANCH_IFNOT,0,i),e.caseInstOffset.push([r,n])}selectCaseElse(){const t=this.ctrlFlow();if(!t)return;t.endCaseInstructions.push(this.emit(V.BRANCH,0));const e=this.branchTargetHere();this.emit(V.NOP),t.caseInstOffset.push([e,void 0])}selectEnd(){const t=this.ctrlFlow();if(!t)return;const e=this.branchTargetHere();for(const r of t.endCaseInstructions)this.recordBranchTarget(e,r);for(let r=0;r<t.caseInstOffset.length;++r){const[i,n]=t.caseInstOffset[r];if(void 0!==n){const i=this.blockInfo.inst[n.instOffset];r+1<t.caseInstOffset.length?this.recordBranchTarget(t.caseInstOffset[r+1][0],i):this.recordBranchTarget(e,i)}}this.ctrlFlowStack.pop(),t.selectValue.stackOffset+1===this.reservedStackSlots&&this.reservedStackSlots--}forBegin(t,e,r,i){if(!t.isVar()||!t.type.isNumeric())return void this.error("invalid index");r=this.stackify(r,!0);const n=new ft(ut.kFOR);this.assignVal(t,e),i=i?this.stackify(i):this.constNumber(1,t.type);const s=this.newStackValue(m),o=this.emit(V.BRANCH,0);n.loopStart=this.branchTargetHere();const a=this.stackify(t);this.write(V.ADD,a,a,i),this.assign(t,a.stackOffset),this.recordBranchTarget(this.branchTargetHere(),o),this.loadVar(a.stackOffset,t),this.write(V.LTE,s,a,r),n.branchInst=this.write(V.BRANCH_IFNOT,0,s),this.ctrlFlowStack.push(n)}forExit(){const t=this.ctrlFlow(ut.kFOR);t&&t.endInstructions.push(this.emit(V.BRANCH,0))}forEnd(){const t=this.ctrlFlow(ut.kFOR);if(t){this.ctrlFlowStack.pop(),this.write(V.BRANCH,t.loopStart),t.branchInst&&this.recordBranchTarget(this.branchTargetHere(),t.branchInst);for(const e of t.endInstructions)this.recordBranchTarget(this.branchTargetHere(),e)}}doBegin(){const t=new ft(ut.kDO);t.loopStart=this.branchTargetHere(),this.ctrlFlowStack.push(t)}doWhileCond(t){this.ctrlFlow().branchInst=this.write(V.BRANCH_IFNOT,0,t)}doExit(){const t=this.ctrlFlow(ut.kDO);t&&t.endInstructions.push(this.emit(V.BRANCH,0))}doEnd(t){const e=this.ctrlFlow();if(!e||e.type!==ut.kDO)return;t?this.write(V.BRANCH_IFNOT,e.loopStart,t):this.write(V.BRANCH,e.loopStart);const r=this.branchTargetHere();e.branchInst&&this.recordBranchTarget(r,e.branchInst);for(const t of e.endInstructions)this.recordBranchTarget(r,t);this.ctrlFlowStack.pop()}whileBegin(){const t=new ft(ut.kWHILE);t.loopStart=this.branchTargetHere(),this.ctrlFlowStack.push(t)}whileCond(t){const e=this.ctrlFlow();e&&(e.branchInst=this.write(V.BRANCH_IFNOT,0,t))}wend(){const t=this.ctrlFlow();if(!t||t.type!==ut.kWHILE)return;this.write(V.BRANCH,t.loopStart);const e=this.branchTargetHere();t.branchInst&&this.recordBranchTarget(e,t.branchInst),this.ctrlFlowStack.pop()}onErrorGoto(t,e){const r=new dt(this.blockInfo,this.emit(V.ON_ERROR_GOTO,0));"string"==typeof t?r.label=t:r.lineNumber=t,r.token=e,this.g.gotos.push(r)}gotoLine(t,e){const r=new dt(this.blockInfo,this.emit(V.BRANCH,0));r.lineNumber=t,r.token=e,this.g.gotos.push(r)}gotoLabel(t){const e=new dt(this.blockInfo,this.emit(V.BRANCH,0));e.label=t.text,e.token=t,this.g.gotos.push(e)}resumeNext(){this.write(V.RESUME_NEXT)}resume(){this.write(V.RESUME)}resumeGoto(t,e){const r=new dt(this.blockInfo,this.emit(V.RESUME_GOTO,0));r.setLabelOrLineNumber(t),r.globalLabel=!0,this.g.gotos.push(r)}goReturn(t,e){if(void 0===e)return void this.emit(V.EXIT_SUB);const r=new dt(this.blockInfo,this.emit(V.RETURN,0));t&&(r.token=t),r.setLabelOrLineNumber(e),this.g.gotos.push(r)}gosub(t,e){const r=new dt(this.blockInfo,this.emit(V.GOSUB,0,this.stackOffset));r.token=t,r.setLabelOrLineNumber(e),this.g.gotos.push(r)}locate(t,e){this.write(V.LOCATE,t,e)}color(t,e){t||(t=this.constNumber(-1,m)),e||(e=this.constNumber(-1,m)),this.write(V.COLOR,t,e)}palette(t,e){t?this.write(V.PALETTE,t,e):this.write(V.PALETTE)}pset(t,e){if(!t)return;let r,i;if(t.step){const e=this.newStackValue(m),n=this.newStackValue(m);this.write(V.GET_DRAW_POS,e,n),r=this.newStackValue(m),i=this.newStackValue(m),this.write(V.ADD,r,e,t.x),this.write(V.ADD,i,n,t.y)}else r=t.x,i=t.y;const n=[r,i,void 0];e&&(n[2]=e),this.write(V.PSET,...n)}preset(t){if(!t)return;let e,r;if(t.step){const i=this.newStackValue(m),n=this.newStackValue(m);this.write(V.GET_DRAW_POS,i,n),e=this.newStackValue(m),r=this.newStackValue(m),this.write(V.ADD,e,i,t.x),this.write(V.ADD,r,n,t.y)}else e=t.x,r=t.y;const i=[e,r];this.write(V.PRESET,...i)}circle(t,e,r,i,n,s){let o,a;if(t.step){const e=this.newStackValue(m),r=this.newStackValue(m);this.write(V.GET_DRAW_POS,e,r),o=this.newStackValue(m),a=this.newStackValue(m),this.write(V.ADD,o,e,t.x),this.write(V.ADD,a,r,t.y)}else o=t.x,a=t.y;this.write(V.CIRCLE,o,a,e,r,i,n,s)}paint(t,e,r,i){let n,s;if(t.step){const e=this.newStackValue(m),r=this.newStackValue(m);this.write(V.GET_DRAW_POS,e,r),n=this.newStackValue(m),s=this.newStackValue(m),this.write(V.ADD,n,e,t.x),this.write(V.ADD,s,r,t.y)}else n=t.x,s=t.y;this.write(V.PAINT,n,s,e,r)}line(t,e,r,i,n){let s,o,a,l;if(t)if(t.step){const e=this.newStackValue(m),r=this.newStackValue(m);this.write(V.GET_DRAW_POS,e,r),s=this.newStackValue(m),o=this.newStackValue(m),this.write(V.ADD,s,e,t.x),this.write(V.ADD,o,r,t.y)}else s=t.x,o=t.y;else s=this.newStackValue(m),o=this.newStackValue(m),this.write(V.GET_DRAW_POS,s,o);if(!e)return void this.error("to-coordinate missing");e.step?(a=this.newStackValue(m),l=this.newStackValue(m),this.write(V.ADD,a,s,e.x),this.write(V.ADD,l,o,e.y)):(a=e.x,l=e.y);const c=[s,o,a,l,void 0,void 0,void 0];r&&(c[4]=r),i&&(c[5]=i),null!==n&&(c[6]=n),this.write(V.LINE,...c)}draw(t){this.write(V.DRAW,t)}getGraphics(t,e,r,i){let n,s,o,a;if(t.step){const e=this.newStackValue(m),r=this.newStackValue(m);this.write(V.GET_DRAW_POS,e,r),n=this.newStackValue(m),s=this.newStackValue(m),this.write(V.ADD,n,e,t.x),this.write(V.ADD,s,r,t.y)}else n=t.x,s=t.y;e.step?(o=this.newStackValue(m),a=this.newStackValue(m),this.write(V.ADD,o,n,e.x),this.write(V.ADD,a,s,e.y)):(o=e.x,a=e.y);const l=this.findVariable(r.text,i);l?this.write(V.GET_GRAPHICS,n,s,o,a,l):this.error("undefined variable",r.loc)}putGraphics(t,e,r,i){let n,s,o=function(t){switch(t){case"PSET":return M.kPset;case"PRESET":return M.kPreset;case"AND":return M.kAnd;case"OR":return M.kOr;case"XOR":return M.kXor}}(i);if(void 0===o)return void this.error("internal error");if(t.step){const e=this.newStackValue(m),r=this.newStackValue(m);this.write(V.GET_DRAW_POS,e,r),n=this.newStackValue(m),s=this.newStackValue(m),this.write(V.ADD,n,e,t.x),this.write(V.ADD,s,r,t.y)}else n=t.x,s=t.y;const a=this.findVariable(e.text,r);a?this.write(V.PUT_GRAPHICS,n,s,a,o):this.error("undefined variable",e.loc)}randomize(t){this.write(V.RANDOMIZE,t)}finalize(){if(this.g.isEnd||this.setEnd(),this.finalized)throw new Error("already finalized");const t=this.allBlocks();for(let e=t.length-1;e>=0;e--){t[e].insertDeclareInstructions()}const e=this.g.program.data.length,r=this.g.globalVarCount;for(const i of t){let t=i.startShift;i===this.blockInfo&&(t+=e+r);for(const r of i.inst)r.mapStackOffset(r=>{switch(r&ht){case 0:return r<i.argCount?r:r+t;case at:return(r^at)+e|D;case ct:return r^(ct|D);case lt:return(r^lt)+i.argCount}return r});for(const e of i.inst)e.id!==V.CALL_SUB&&e.id!==V.CALL_FUNCTION||(e.args[1]+=t)}let i=0;for(const e of t)e.setStartPC(i),i+=e.inst.length;for(const t of this.g.restores){let e;if("string"==typeof t.lbl){if(void 0===(e=this.g.labels.get(t.lbl.toUpperCase()))){this.error("label not found");continue}}else if(void 0===(e=this.g.lineNumbers.get(t.lbl))){this.error("line number not found");continue}t.restoreInst.args[0]=1;for(const r of this.g.dataOffsets)if(e.block===r.instructionIndex.block&&e.instOffset<=r.instructionIndex.instOffset){t.restoreInst.args[0]=r.dataOffset;break}}for(const[t,e]of this.g.subs)for(const t of e.calls)t.args[0]=e.blockInfo.startPc;for(const[t,e]of this.g.functions)for(const t of e.calls)t.args[0]=e.blockInfo.startPc;for(const t of this.g.gotos){let e;if(t.label){if(void 0===(e=this.g.labels.get(t.label.toUpperCase()))){this.error("label not found",t.token);continue}t.globalLabel?e.block!==this.blockInfo&&this.error("label not at module level",t.token):e.block!==t.sourceBlock&&(this.error("label not in this block"),t.token)}else if(void 0!==t.lineNumber){if(void 0===(e=this.g.lineNumbers.get(t.lineNumber))){this.error("line number not found",t.token);continue}}else void 0!==t.target&&(e=t.target);e?t.inst.args[0]=e.getPC():this.error("internal error")}const n=this.program();for(const e of t){for(const t of e.inst)n.inst.push(t);for(const t of e.statementOffsets)n.statementOffsets.push(t);for(const[t,r]of e.instToLine)n.instToLine.set(t+e.startPc,r)}this.finalized=!0}end(){this.write(V.END)}allBlocks(){const t=[this.blockInfo];for(const[e,r]of this.g.functions)r.blockInfo.startPc>=0&&t.push(r.blockInfo);for(const[e,r]of this.g.subs)r.blockInfo.startPc>=0&&t.push(r.blockInfo);return t}assignVal(t,e){const r=this.convert(e,t.type);this.assign(t,this.stackify(r).stackOffset)}assign(t,e){let r,i,n=t;if(t.isField()){i=[];const e=this.fieldToVarAndIndex(t,i);if(!e)return;n=e}n.index&&(r=n.index.map(t=>this.stackify(t).stackOffset)),this.write(V.ASSIGN,n.stackOffset,e,r,i)}constNumber(t,e){return this.stackify(k.newNumberLiteral(t,e))}ctrlFlow(t){if(!t&&this.ctrlFlowStack.length)return this.ctrlFlowStack[this.ctrlFlowStack.length-1];for(let e=this.ctrlFlowStack.length-1;e>=0;e--)if(this.ctrlFlowStack[e].type===t)return this.ctrlFlowStack[e]}reserveStackSlot(){return this.stackOffset!==this.reservedStackSlots?(this.error("internal error"),0):this.reservedStackSlots++}nextStackOffset(){return this.stackOffset++}autoVarKey(t){return t.baseType()===s.kSingle?t.varName.toUpperCase():t.varName.toUpperCase()+f(t.baseType())}varAddr(t){if(t.isVar()){if(t.dimmed)return t.varName;const e=this.autoVarKey(t);return this.autoVars.get(e)?e:(this.autoVars.set(e,k.newVar(t.varName,t.type)),this.parent?t.stackOffset=lt|this.localVarCount++:t.stackOffset=at|this.g.globalVarCount++,this.blockInfo.declareInstructions.push(new Q(V.DECLARE,[t.stackOffset,J.single(t.type,K(t.type))])),e)}return""}newStackValue(t){return k.newStackValue(t,this.nextStackOffset())}fieldToVarAndIndex(t,e){let r=t.fieldBase;if(!r)return;const i=r.type.lookupFieldOffset(t.varName);if(void 0!==i){if(r.isField()){const t=this.fieldToVarAndIndex(r,e);if(!t)return;r=t}else if(!r.isVar())return void this.error("internal error");return e.push(i),r}}loadVar(t,e){let r,i,n=e;if(e.isField()){i=[];const t=this.fieldToVarAndIndex(e,i);if(!t)return;n=t}return n.index&&(r=n.index.map(t=>this.stackify(t).stackOffset)),this.write(V.LOAD,t,n.stackOffset,r,i),k.newStackValue(e.type,t)}constDataVal(t){if(t.isLiteral()||t.isConst()){const e=wt.valConstKey(t),r=this.g.constantVals.get(e);if(r)return r;const i=wt.literalVarVal(t),n=this.g.program.data.length|ct;this.g.program.data.push(i);const s=k.newStackValue(t.type,n);return this.g.constantVals.set(e,s),s}}stackifyAll(t){return t.map(t=>this.stackify(t))}stackify(t,e=!1){if(!t)return S;const r=this.constDataVal(t);if(void 0!==r)return r;if(t.isStackValue()){if(!e||e&&t.stackOffset<this.reservedStackSlots)return t;const r=this.reservedStackSlots++;return this.write(V.COPY,r,t.stackOffset),k.newStackValue(t.type,r)}return!t.isVar()||t.global||t.index||t.isField()?t.isVar()||t.isField()?this.loadVar(e?this.reserveStackSlot():this.nextStackOffset(),t)||S:(this.error("invalid value"),S):t}constExpr(t,...e){if(!U.has(t))return;const r=e[0];for(let t=1;t<e.length;t++){const r=e[t];if(!(r instanceof k))return;if(!r.isLiteral()&&!r.isConst())return}const i=new $,n=[e.length-1];for(let t=1;t<e.length;t++){const r=e[t];i.data.push(wt.literalVarVal(r)),n.push(t-1)}i.inst.push(new Q(t,n));const s=new ot(i,new F);if(s.run(),s.exception)return;const o=s.stack[n[0]];return r.type===v?k.newStringLiteral(o.strVal()):k.newNumberLiteral(o.numVal(),r.type)}write(t,...e){const r=this.constExpr(t,...e);if(r){const t=e[0];if(t.kind===w.kStackValue)return t.kind=r.kind,t.stringValue=r.stringValue,void(t.numberValue=r.numberValue)}if(!(t===V.COPY&&e[0]===e[1]||t===V.ASSIGN&&e[0]===e[1]&&void 0===e[2]&&void 0===e[3])){if(t===V.BRANCH_IFNOT){const r=e[1];if(void 0!==r.constNumberValue()){if(r.numberValue)return;t=V.BRANCH,e.pop()}}return this.emit(t,...e)}}emit(t,...e){let r;for(let t=0;t<e.length;t++)e[t]instanceof k&&(e[t]=this.stackify(e[t]).stackOffset);e.length>=0&&e[0]instanceof mt&&(r=e[0],e[0]=0);const i=new Q(t,e);if(r&&this.recordBranchTarget(r,i),this.blockInfo.inst.push(i),this.g.locator){const t=this.g.locator.currentLocation();t&&this.blockInfo.instToLine.set(this.blockInfo.inst.length-1,t.line)}return i}expectNumeric(t){return!!t.type.isNumeric()||(this.error("expected numeric type",t.loc()),!1)}branchTargetHere(){return new mt(this.blockInfo,this.blockInfo.inst.length)}recordBranchTarget(t,e){const r=new dt(this.blockInfo,e);r.target=t,this.g.gotos.push(r)}}const kt="\n attribute vec4 aVertexPosition;\n void main(void) {\n gl_Position = aVertexPosition;\n }\n ",St="\n precision highp float;\n uniform sampler2D tex;\n uniform sampler2D pal;\n uniform vec2 WindowSize;\n void main(void) {\n float WW = WindowSize.x;\n float WH = WindowSize.y;\n // +0.5 reduces effect of precision loss\n float y = floor(WH-gl_FragCoord.y)+0.5;\n float x = floor(gl_FragCoord.x)+0.5;\n\n float cc = texture2D(tex, vec2(x/WW, y/WH)).w;\n vec4 c = texture2D(pal, vec2(cc+(0.5/255.0), 0.5));\n gl_FragColor.r=c.x;\n gl_FragColor.g=c.y;\n gl_FragColor.b=c.z;\n gl_FragColor.w=1.0;\n }\n ";function Et(t){return 1<<t%16}const Tt=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15];function Ct(t){return Tt[15&t]<<12|Tt[(240&t)>>4]<<8|Tt[(3840&t)>>8]<<4|Tt[(61440&t)>>12]}class It{constructor(t,e,r,i){this.left=t,this.top=e,this.right=r,this.bottom=i}copy(){return new It(this.left,this.top,this.right,this.bottom)}within(t,e){return!(t<this.left||e<this.top||t>this.right||e>this.bottom)}clamp(t,e){return[Math.min(Math.max(t,this.left),this.right),Math.min(Math.max(t,this.top),this.bottom)]}}class Ot{constructor(t,e){this.width=t,this.height=e,this.data=new Uint8Array(t*e),this.fullViewport=new It(0,0,t-1,e-1)}onScreen(t,e){return!(t<0||e<0||t>=this.width||e>=this.height)}pset(t,e,r,i){t<i.left||e<i.top||t>i.right||e>i.bottom||(this.data[t+e*this.width]=r)}pget(t,e){return t<0||e<0||t>=this.width||e>=this.height?0:this.data[t+e*this.width]}offsetAt(t,e){return t+e*this.width}blt(t,e,r,i,n,s,o){if(e<0&&(i+=e),r<0&&(n+=r),i+e>t.width&&(i=t.width-e),n+r>t.height&&(n=t.height-r),!(s>=this.width||o>=this.height||i<1||n<1||e>=t.width||r>=t.height)){if(s<0)return this.blt(t,e-s,r,i+s,n,0,o);if(o<0)return this.blt(t,e,r-o,i,n+o,s,0);for(let a=o;a<o+n;a++){const n=t.offsetAt(e,r);this.data.set(t.data.slice(n,n+i),this.offsetAt(s,a)),r++}}}drawChar(t,e,r,i,n,s,o){const[a,l]=[s.width,s.height];t*=a,e*=l;const[c,h]=s.charOffset(r),u=s.data();for(let r=0;r<l;r++)for(let s=0;s<a;s++)this.pset(t+s,e+r,u.pget(s+c,r+h)?i:n,o)}clear(t){this.data.fill(t)}drawCircle(t,e,r,i,n,s,o,a){const l=o>1?1/o:1,c=o<1?o:1,h=r*r,u=Math.ceil(r/Math.SQRT2);const f=t=>{const[e,i]=((t,e)=>Math.abs(t)>=Math.abs(e)?(e=Math.round(e),[t=t>0?Math.sqrt(h-e*e):-Math.sqrt(h-e*e),e]):[t=Math.round(t),e=e>0?Math.sqrt(h-t*t):-Math.sqrt(h-t*t)])(r*Math.cos(t),r*-Math.sin(t));return[Math.round(e),Math.round(i)]},[d,p]=f(n),[g,m]=f(s);let v=n>s;for(const[r,o]of function*(){for(let t=0;t>=-u;t--)yield[Math.sqrt(h-t*t),t];for(let t=u;t>=-u;t--)yield[t,-Math.sqrt(h-t*t)];for(let t=-u;t<=u;t++)yield[-Math.sqrt(h-t*t),t];for(let t=-u;t<=u;t++)yield[t,Math.sqrt(h-t*t)];for(let t=u;t>0;t--)yield[Math.sqrt(h-t*t),t]}()){const[h,u]=[Math.round(r*l),Math.round(o*c)];Math.round(r)===d&&Math.round(o)===p&&(v=!0),v&&this.pset(h+t,u+e,i,a),Math.round(r)===g&&Math.round(o)===m&&(g===d&&m===p&&s>n+3||(v=!1))}}paint(t,e,r,i,n){const s=new Set,o=[[t,e]];for(;o.length;){const[t,e]=o.pop();if(!n.within(t,e))continue;const a=this.offsetAt(t,e);s.has(a)||(s.add(a),this.pget(t,e)!==i&&(this.pset(t,e,r,n),o.push([t+1,e]),o.push([t-1,e]),o.push([t,e+1]),o.push([t,e-1])))}}filledRect(t,e,r,i,n,s){const[o,a]=[Math.min(t,r),Math.max(t,r)],[l,c]=[Math.min(e,i),Math.max(e,i)];for(let t=l;t<=c;t++){const e=this.offsetAt(o,t);this.data.fill(n,e,e+(a-o+1))}}rect(t,e,r,i,n,s,o){const[a,l]=[Math.min(t,r),Math.max(t,r)],[c,h]=[Math.min(e,i),Math.max(e,i)];this.line(a,c,l,c,n,s,o),this.line(a,h,l,h,n,s,o),this.line(a,c,a,h,n,s,o),this.line(l,c,l,h,n,s,o)}line(t,e,r,i,n,s,o){const a=r-t,l=i-e;return Math.abs(a)>=Math.abs(l)?t>r?this.linex(r,i,t,e,n,Ct(s),o):this.linex(t,e,r,i,n,s,o):e>i?this.liney(r,i,t,e,n,Ct(s),o):this.liney(t,e,r,i,n,s,o)}linex(t,e,r,i,n,s,o){const a=r-t,l=i-e,c=Math.abs(l/a);let h=0,u=e,f=0;for(let e=t;e<=r;e++)s&Et(f++)&&this.pset(e,u,n,o),(h+=c)>=.5&&(u+=Math.sign(l),h-=1)}liney(t,e,r,i,n,s,o){const a=r-t,l=i-e,c=Math.abs(a/l);let h=0,u=t,f=0;for(let t=e;t<=i;t++)s&Et(f++)&&this.pset(u,t,n,o),(h+=c)>=.5&&(u+=Math.sign(a),h-=1)}}function Lt(t){return t.split(",").map(t=>(function(t){let e;return/^#([A-Fa-f0-9]{3}){1,2}$/.test(t)?(3===(e=t.substring(1).split("")).length&&(e=[e[0],e[0],e[1],e[1],e[2],e[2]]),[(e="0x"+e.join(""))>>16&255,e>>8&255,255&e]):[0,0,0]})(t))}const Nt=new Map([[0,[[0,0,0],[0,0,170],[0,170,0],[0,170,170],[170,0,0],[170,0,170],[170,85,0],[170,170,170],[85,85,85],[85,85,255],[85,255,85],[85,255,255],[255,85,85],[255,85,255],[255,255,85],[255,255,255]]],[1,Lt("#000000,#0000aa,#00aa00,#00aaaa,#aa0000,#aa00aa,#aa5500,#aaaaaa,#555555,#5555ff,#55ff55,#55ffff,#ff5555,#ff55ff,#ffff55,#ffffff")],[2,Lt("#000000,#ffffff")],[7,Lt("#000000,#0000aa,#00aa00,#00aaaa,#aa0000,#aa00aa,#aa5500,#aaaaaa,#555555,#5555ff,#55ff55,#55ffff,#ff5555,#ff55ff,#ffff55,#ffffff")],[8,Lt("#000000,#0000aa,#00aa00,#00aaaa,#aa0000,#aa00aa,#aa5500,#aaaaaa,#555555,#5555ff,#55ff55,#55ffff,#ff5555,#ff55ff,#ffff55,#ffffff")],[9,Lt("#000000,#0000aa,#00aa00,#00aaaa,#aa0000,#aa00aa,#aa5500,#aaaaaa,#555555,#5555ff,#55ff55,#55ffff,#ff5555,#ff55ff,#ffff55,#ffffff")],[12,Lt("#000000,#0000aa,#00aa00,#00aaaa,#aa0000,#aa00aa,#aa5500,#aaaaaa,#555555,#5555ff,#55ff55,#55ffff,#ff5555,#ff55ff,#ffff55,#ffffff")],[13,Lt("#000000,#0000aa,#00aa00,#00aaaa,#aa0000,#aa00aa,#aa5500,#aaaaaa,#555555,#5555ff,#55ff55,#55ffff,#ff5555,#ff55ff,#ffff55,#ffffff,#000000,#141414,#202020,#2d2d2d,#393939,#454545,#515151,#616161,#717171,#828282,#929292,#a2a2a2,#b6b6b6,#cacaca,#e3e3e3,#ffffff,#0000ff,#4100ff,#7d00ff,#be00ff,#ff00ff,#ff00be,#ff007d,#ff0041,#ff0000,#ff4100,#ff7d00,#ffbe00,#ffff00,#beff00,#7dff00,#41ff00,#00ff00,#00ff41,#00ff7d,#00ffbe,#00ffff,#00beff,#007dff,#0041ff,#7d7dff,#9e7dff,#be7dff,#df7dff,#ff7dff,#ff7ddf,#ff7dbe,#ff7d9e,#ff7d7d,#ff9e7d,#ffbe7d,#ffdf7d,#ffff7d,#dfff7d,#beff7d,#9eff7d,#7dff7d,#7dff9e,#7dffbe,#7dffdf,#7dffff,#7ddfff,#7dbeff,#7d9eff,#b6b6ff,#c6b6ff,#dbb6ff,#ebb6ff,#ffb6ff,#ffb6eb,#ffb6db,#ffb6c6,#ffb6b6,#ffc6b6,#ffdbb6,#ffebb6,#ffffb6,#ebffb6,#dbffb6,#c6ffb6,#b6ffb6,#b6ffc6,#b6ffdb,#b6ffeb,#b6ffff,#b6ebff,#b6dbff,#b6c6ff,#000071,#1c0071,#390071,#550071,#710071,#710055,#710039,#71001c,#710000,#711c00,#713900,#715500,#717100,#557100,#397100,#1c7100,#007100,#00711c,#007139,#007155,#007171,#005571,#003971,#001c71,#393971,#453971,#553971,#613971,#713971,#713961,#713955,#713945,#713939,#714539,#715539,#716139,#717139,#617139,#557139,#457139,#397139,#397145,#397155,#397161,#397171,#396171,#395571,#394571,#515171,#595171,#615171,#695171,#715171,#715169,#715161,#715159,#715151,#715951,#716151,#716951,#717151,#697151,#617151,#597151,#517151,#517159,#517161,#517169,#517171,#516971,#516171,#515971,#000041,#100041,#200041,#310041,#410041,#410031,#410020,#410010,#410000,#411000,#412000,#413100,#414100,#314100,#204100,#104100,#004100,#004110,#004120,#004131,#004141,#003141,#002041,#001041,#202041,#282041,#312041,#392041,#412041,#412039,#412031,#412028,#412020,#412820,#413120,#413920,#414120,#394120,#314120,#284120,#204120,#204128,#204131,#204139,#204141,#203941,#203141,#202841,#2d2d41,#312d41,#352d41,#3d2d41,#412d41,#412d3d,#412d35,#412d31,#412d2d,#41312d,#41352d,#413d2d,#41412d,#3d412d,#35412d,#31412d,#2d412d,#2d4131,#2d4135,#2d413d,#2d4141,#2d3d41,#2d3541,#2d3141,#000000,#000000,#000000,#000000,#000000,#000000,#000000,#000000")]]),At=new Map([[0,[640,480]],[1,[320,200]],[2,[640,200]],[7,[320,200]],[8,[640,200]],[9,[640,350]],[12,[640,480]],[13,[320,200]]]);class Dt{constructor(t,e,r){this.canvas=t,this.width=e,this.height=r,this.dtors=[],this.buffer=new Ot(e,r),this.palette=new Uint8Array(768),this.setPalette(Nt.get(0));const i=this.canvas.getContext("webgl");if(!i)return void window.alert("Can't get WebGL context");this.gl=i,this.positionBuffer=i.createBuffer(),i.bindBuffer(i.ARRAY_BUFFER,this.positionBuffer);i.bufferData(i.ARRAY_BUFFER,new Float32Array([1,1,-1,1,1,-1,-1,-1]),i.STATIC_DRAW);const n=function(t){const e=Rt(t,t.VERTEX_SHADER,kt),r=Rt(t,t.FRAGMENT_SHADER,St);if(!e||!r)return;const i=t.createProgram();if(t.attachShader(i,e.shader),t.attachShader(i,r.shader),t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS))return alert("Unable to initialize the shader program: "+t.getProgramInfoLog(i)),null;return{program:i,dtor:()=>{e.dtor(),r.dtor(),t.deleteProgram(i)}}}(i);n&&(this.dtors.push(n.dtor),this.shaderProgram=n.program)}setPaletteEntry(t,e){this.palette[3*t+0]=e[0],this.palette[3*t+1]=e[1],this.palette[3*t+2]=e[2]}setPalette(t){for(let e=0;e<256;e++)t.length>e?(this.palette[3*e]=t[e][0],this.palette[3*e+1]=t[e][1],this.palette[3*e+2]=t[e][2]):(this.palette[3*e]=0,this.palette[3*e+1]=0,this.palette[3*e+2]=0)}free(){for(const t of this.dtors)t()}draw(){const t=this.gl;t.clearColor(0,0,0,1),t.disable(t.DEPTH_TEST),t.clear(t.COLOR_BUFFER_BIT),t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer),t.vertexAttribPointer(t.getAttribLocation(this.shaderProgram,"aVertexPosition"),2,t.FLOAT,!1,0,0),t.enableVertexAttribArray(t.getAttribLocation(this.shaderProgram,"aVertexPosition"));const e=t.createTexture();{const r=this.buffer.data;t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.ALPHA,this.width,this.height,0,t.ALPHA,t.UNSIGNED_BYTE,r)}const r=t.createTexture();{const e=this.palette;t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGB,256,1,0,t.RGB,t.UNSIGNED_BYTE,e)}t.useProgram(this.shaderProgram),t.uniform1i(t.getUniformLocation(this.shaderProgram,"tex"),0),t.uniform1i(t.getUniformLocation(this.shaderProgram,"pal"),1),t.uniform2f(t.getUniformLocation(this.shaderProgram,"WindowSize"),this.canvas.width,this.canvas.height),t.drawArrays(t.TRIANGLE_STRIP,0,4)}}function Rt(t,e,r){const i=t.createShader(e);return t.shaderSource(i,r),t.compileShader(i),t.getShaderParameter(i,t.COMPILE_STATUS)?{shader:i,dtor:()=>t.deleteShader(i)}:(alert("An error occurred compiling the shaders: "+t.getShaderInfoLog(i)),void t.deleteShader(i))}var Mt;!function(t){t[t.k8x8=0]="k8x8",t[t.k8x16=1]="k8x16",t[t.k8x14=2]="k8x14"}(Mt||(Mt={}));const Pt=["data:image/webp;base64,UklGRq4EAABXRUJQVlA4TKIEAAAv/8EHAA8w//M///MfePCt/p8jSbZtWdJadw+tZUA+QF0VtH6H\nIR+gHqNwp7XOwIdIA4Mc1307rvQwxwOiDX4MG+JKD/9jyfgPPSL4X2QYGPUbwrPUE0T0X2HaNoxC\n5yns+3RRLujonpjuOdIbP1N/9BJVlctYSsZStZIkz0YT2cYSRUhlFV53XRkv6KanP++vXF0d3pv8\n6iqnSdX4O3WUlMaQqpk3kjnsgalVAGZGA7+56sZS9BP+2hP+nqNpfqn3q8K+11ybnxwldQ2lVZ2M\npL5tOae5ZcCsRs287rquG6enf/LiC96ufqLr1H8xUVW7rrm+pzGJrlnVRUbay1YK8qwyko1Z+eLT\n49h109M/eRGTXf3E/JL649T32ufavJto7LJteKnVE6u5yzBkslKN1z5RyrdG/YS/Bt1/cjq81/O4\n9JNOat3vnJJMswfNvBmtnRqQAYOaWTTyuru4uLigm55Gvztd3fjZ5I/RqyqXMSYLa2oljXZjjFFe\nEzHZmymrse/JUujoRA9NSSWFjreVylukkuRocZq7boK8droLoUSJEoEQ0EmTCxoP3LLwYPmwv+Ri\naauHNYN4n37wAw/Lvr5+mjw8frUQatVCY2VmYiWrXWJLpra5eBm++b/+tcFyqt1J8PDVgJDw82qa\nqFIlS12nffaGWTbrzTgCISCaGsvLGJsXadGy1O7lMGI0A75VRKtqIPOIETusLSfrAI91M+BbCX8+\ncMv0cly0t2FIP/jW26FukhrQFft+zUpy9A2xwluWJS8GdAVmagwN3qcfVA+D9yGkKh4GeT2Zr2dK\nEh5odfSGZN8CxrHmX0O6NP5mQRCnudu9BJHTLoSy256KRAtBOvmZkFxvZC27fCo4lQCpeTfr2lLI\ncasHdrzTOC4zk0KS3L3GZWaSJIXbHgdjjwPGQ7AtXxJSyKehBfN720IyTsXIp59W8kdfWanqQA4D\nh0EJ8GnS+DTJwGJkAg44QKkJOCa325kpkQxBr+Bf7z91C40yiYhMIvuyT4xHIElyQv8bgcqeJFIy\nEqD3izYPnE+G7mSYCeAs59w8YGpBau5EBIBH28XvTdkE8wcvlRrjyyvFlX+9//qi6dlwdjYoBfGl\ncRxbH6OpdZAjAFiqFnQ0AJFsLV/5sC7bPJ9088lw0nXzrGgegNTWTC3EeqnGCf1pfFRhADb9iJb9\nQzd7DzoMA0nNvdzT932eRGSSgHj0toj0fVbRaOG8F+kBUkg8quT/3rcgJEkW3jIzqbTP7HmzPPEc\nyf+/b06VStVh4KLrQA5KDqp03D3hSDKSjKVseVaEVvU9NRbyCdmTd4HEDvRrS8mYK6KZHautE5mT\nXvbA8OF7nnQfdk+6wXF44AEO7pI1kGrvNxKC9n0Do9Zj5WbBpps0M9JILprerG3mluzcK7owrlbz\noqlGFmVOdeIDzj3g3AMfvufD7skPuyedc+6eBx64x7n5Aed2T/AfaKmee0VIWK0aaFVVuabqB0km\nkrpoHDgMHEhd/AelLmzmlnA+qqSEvq+IJPXcNiQTeTesW0txX9XK68JawBijnhu5/NwFbCTZGEmy\nkSSpe5LkliQB","data:image/webp;base64,UklGRuIFAABXRUJQVlA4TNUFAAAv/8EPAA8w//M///MfeLCr/p8kR1I0c8ice0ZjLhTI3cO671e4\nH6BfYb0mEomde0pJytAf/nTufblrNWhpBVGgCQgIe+8qouC395YIoxSQ9M/JLFVrhrUj+o8wbdvI\nEEb3CScZGu4f+NTt9OQxSbebEGR5Ck0z9ZZ/5h6HHnJPCWB6FTrmkiaPDOeSzdY5kqTjA0MCNDRz\n+dzncTP3Mqv0fspLUIYCjIWsejVUVSV7VuUPZmHrPQ3Nr+SZe9i81cgss2lGtpb+T+HiItSSSJKP\nddX3fhh6VSCxKB8Ym31D47/0Oymfny2PIbNAACj8V7b0tINmliQg2StSHybQIPGBse7Q4FDur6R8\n3lsL+ZQSQKpDyI5gcKllSR4k0xng4+Vlcg1ZmMBvfMnaQ+O/9PtvRF8+f7g8hhyNWDtYN9JjwZJM\nQ0ucofS2V2hPVvbg/UPrDpsRlM/7zVuNHAXbjMflkRKnUxS1T70W7cnSJPCBcRnAodyPzfWbs5u5\n51G2Hg2K/ZfNJO3DGkdnkFUxTAAgyAcmbwEa/6WIzSGGHnKULOBJ0m4JBtVIgAQxBKgm1aIJSCxg\n02zpPQ3NCjfnePKYcqS2ATgODO5hy1RGnuTGurecK27F0rOCkwwNyYEkScdbAscV7t3E/oFP3cTH\n2MQnsS3Lxyzfhe2lX1rr1b91vlF1l+7SNaqqYj19IHjDK2beoL/JE9uxOa5buiwSRESRpL59rqKi\nY1qeJCVZmRhY0VdMlDEAC2qQC3n06GLEno78QlWDPCxD4sQfWMm9cKsqg/zjH4MihWqtikqFqjpJ\n5SaRXK2cd7UNeS74aOEW7cJdRlFVC4D5RN0gq9VgkVb17ESdugzVs+xRrhPJFDToJrboA6yoxFZL\nFA0arzlnOLGjOVGkVdX3tWpIIyglJ5JOhmhrFPQrnIlKlFqinGUFAOqJyiC1qiKGqqpVpYfqmUMt\nV4lklCEOu9U8VkYWKhfyaEQeqWo9E4UGG3BR5rcJE2msjgwqEqSKIoqoaj0Rhea3FVr6MY06IhPa\nRW+DKgBap5d+aTc/U786t6pu486dd9ug3vrHnmTrXOs27tz3517FObdxVy2CNnaOa+5T4n4lUkiS\nNXFcz32b38JMxD0k3m0r0pMkN29NLPnJLGM/7S4//Pa3AHRk17HrQDJtWTO3rETVUMgta6lUReZy\njgRw4TPJYSD5l9++dAsfkWMJzFrEF+bK46xlVZREkHhUUErLEAo5DNhnhCUQmYGgYEsyBCKCTv0f\nJKKWWhc6cnGBfeaCJEk/+cmWkSRJVal+CZLk+XEmqbrXeYhutVqtxDmXcw5BYnTOxaiqdYM/Y5Vd\nXJyShYwR3Xo0y47L086edksOUVNKqaoqANXaWlUdq01sEjSKbVyxFkAI00Hf9f1orHPOVWvtiOvi\nLjiBg0Y5IevQl4J195ffvoTl8tQuT7tTa5fLizjEGKMMwwDA2trsILWJiNAo75PD0FfxO6ZD13Uk\nIWN+TLWud/AVE0rq0C/e96PzLXzUGGNM07PsgvPbPPyRJ2+f1Lq2bdveOee9V7XvvO+ca9vGOVxC\n0XrXipKOTMcgb5+eJEnPW+tJklxzV+i5zzjuWxq73um45z7DvVtxr/Ya3m17DUAQ6DqOFh3ZgewA\nGm5eMNwvcEcfn0y+sL6+Eys7kd8ir0iSc5CBTGF9J6LSkmxyKPxqcWRJR1PljliltAgK9lUtgCOA\nmUyhuomD7pVnXjSvmBdNZ9gdHLAzE20cQm1k4VVT01QlUgHQkkzh31PoSiELydFg1yzWQyhrgage\nz2ZO2fQV4GJk6XhgzIExB68884p58RXzojHGPHNw8IwxywNjNi9wHYeAtUBskNmsqh1NQ4IfkY4k\nRsOOXceOREei60CM6XSCzD5dlQCwZksg3J26dvAaZHRmSVhjQfKOLHQIuq5ACMJa1JLEGiTp70Yb\nh2CvK5r8tudwpTRNg2uS5BXJOzBu4O7AHd2BPfq/AwA=","data:image/webp;base64,UklGRqoFAABXRUJQVlA4TJ4FAAAv/8ENAA8w//M///MfeLCs/p8kR040s+jo3ZaPhgJdvZz2/RX2\nB+hX8K2JRPIuKCU5i/7wZ9L7dvWpQUMriAJNQOA4e68iCn7eXSIOpYB0/7xklqpr5gEi+s+wbdsw\nFOC22yecZGi4f+Azdz+3mxBkeQZNQwI0NN/yzz3A0yeQB0oA068SHHNJ48sTB+eSzdY5smd1fGTC\n1nsamrl85KMYei+zSu9HtpZegjIUgCTZa1a9GaqqAolF+bWZzb6h8Z/4mTz3YHY3b2SW2TRA4d+y\npf+dvboKtSQByXS+6ns/DL0qAEL5yFh3bHAsD38l5aN+eQqZBQJIdQjZ0TMMmlmSB0mcIfVhGJIq\nWZqU+MhYe2z8J17/3MqXjx5bC/mAEoC1g3WOYHCpZUmmoWW5AHy8voZryMoe/NwnrDtu/Cde/1zE\nZE6Uk3GZYOixmE69ROltr0V7sjCBD49dBnAsD2Nz+/7Z3bzhSbANGhT7N5tJ2tdKZEkCkIOi9mkE\nQAPykclbgMZ/ImJzjKH3cpKthydJuyUYVCIBEsRThWpSLZqAxAI2zZbe09CscHeJp08gJ8kC4Dgw\nOG2ZyghdY923nCtuxdKzgpMMDcmBJEllw52B4wr3bmJHjvcEPnMTb8W2LG+yfABue+2X1nr137rc\nqOZrd+0aVVWx/qkPBO94w8w79Hd5Yjs2x21LzSJBRBRJ6rcvg6jomJYhKcnKxMCKvmKijAFYUINc\nyePHV4oUqr1QUdGfqGqQX5e7xInfsJJ74fZMZZC//GUYsyoqFaqaBeU2kVytnHe1DXkueGPhFu3C\nXUdRVQuA+UzdIKvVYJFW9aUzdeoyVF/KvpScSKagQTexRR9gRSW2WqJo0HjLOcOZHc3ZaPRc60sh\njaCWm0TSyRBtjYJ+hZdEJcptifJSVgCgLlSu5HFVRQyPVbWeiUKDDbgq80QyyhCHkTBWb8bKyKAi\nQaoooohqqE4Ump1CSz+mUasT9IKXRJ2r2kVvQyMAaJ1e+6Xd/Ej96tKq5k26dN5tg3rrn3iSrXOt\n26RLL5dexdW0cTctgvZ2jlvu05z7FUkhSdbEcYmHyUysSE+S3HxrYsm3Zhn7aXf5+he/AKAju45d\nB5Jpy5q5ZSWqhkJuWUulKjKXcySAC59JDgPJP/zyHffwETmWwByL+KK58jRrWRVVRZB4UlBKyxAK\nOQzYZySWEJEZIkSwJRmCIkIz/W8kopZaFzqiin3miiRJP/mTbYwkSQaV6pcgSV6eZpIxslvfP0N0\nq9VqJc65nHMI0kbnXIyqWjf4PVbZxcUFWcj1GiGMZtlxedHZi27JIWpKKVVVBaBaO6uqY7WJTYJG\nsY0r1paCdTcd9F3fd+BVtM45J9baEdfEKak4g4NGOSPr0Ffx41kuL+zyoruwdrmUOMQYox+GAYC1\ndb2Dr01EhEY5J3XoF+d+x+cOXdeRhI8aY4xp+pCJJiguMaEjr33Tk//7fI/UurZt2945571Xtd85\nd861bZ8drqFovWtFSUemU5D3T0+SpOe9JZIk19wVeu4zjvu2Grvd6bTnPsPDttcABIGu42jRkR3I\nDqDh5m2G+wXu6M2Tybetbw/D0pJscv4WP31DsqQ5yECmsD4MpZJECIV9cRbACTBWDsKprZTWq4JN\nVSKVE6DNZArVTRx173ru7eZd5u2mM+yOjtiZiVaHUBpZiGpqZlXZ9BXggmQKf59CVwpZSI4Gu2Zx\nPQSsBWL1dDZzapEK0JBgCkvHI2OOjDl613PvMm9/l3m7McY8d3T0nDHLI2M2b+Nah1DWAtEgsw9W\nJQCALYE3SEcSo2HHrmNHYvS9A7FDXTt4DdI0VcmSsMaCZDiMxfUQdF2BEIS1qCWJNUjSH0Y7DMHe\nVjT5257DjdI0DW5JkjckD4ADSQ7cHbijQ/g37+vg9uhe"],Vt=[void 0,void 0];function Bt(t,e){const r=document.createElement("img");r.onload=(()=>{const t=document.createElement("canvas");t.width=r.width,t.height=r.height,t.getContext("2d").drawImage(r,0,0,r.width,r.height),Vt[e]=t.getContext("2d").getImageData(0,0,r.width,r.height)}),r.setAttribute("src",t)}class Ft{constructor(t,e,r){this.width=t,this.height=e,this.data_=r}data(){return this.data_}charOffset(t){return[this.width*(t%64),this.height*Math.floor(t/64)]}}function Ut(t){const e=Vt[t],r=new Uint8ClampedArray(e.data);let i=0;switch(t){case Mt.k8x8:i=8;break;case Mt.k8x16:i=16;break;case Mt.k8x14:i=14}const n=new Ot(512,4*i);for(let t=0;t+3<r.length;t+=4)n.data[t/4]=0===r[t]?255:0;return new Ft(8,i,n)}function Wt(){return Ut(Mt.k8x16)}function Ht(){!function(){for(let t=0;t<Pt.length;t++)Bt(Pt[t],t)}()}class Gt{constructor(){this.keysDown=new Set,this.shiftKey=0,this.controlKey=0;const t=t=>{const e=Gt.charCode(t);this.keysDown.delete(e)},e=t=>{const e=Gt.charCode(t);this.keysDown.add(e)};window.addEventListener("keyup",t),window.addEventListener("keydown",e),this.destroy=(()=>{window.removeEventListener("keyup",t),window.removeEventListener("keydown",e)})}static charCode(t){return 1===t.key.length?t.key.charCodeAt(0):0}destroy(){}activeKey(){if(!this.keysDown.size)return 0;let t;for(t of this.keysDown.entries());return t}}new Gt;class zt{constructor(){this.input="";const t=t=>{if(this.keyPressed)return this.keyPressed(t.key),void t.preventDefault();1===t.key.length&&(this.input+=t.key,this.inputChanged&&this.inputChanged(this.input,!1),t.preventDefault())},e=t=>{this.keyPressed||("Backspace"===t.key&&this.input.length>0&&(this.input=this.input.substr(0,this.input.length-1),this.inputChanged&&this.inputChanged(this.input,!1),t.preventDefault()),"Enter"===t.key&&(this.inputChanged?this.inputChanged(this.input,!0):this.input+="\n",t.preventDefault()))};window.addEventListener("keypress",t),window.addEventListener("keydown",e),this.destroy=(()=>{window.removeEventListener("keypress",t),window.removeEventListener("keydown",e)})}nextKey(){if(this.input.length>0){const t=this.input.substr(0,1);return this.input=this.input.substr(1),t}return""}destroy(){}}class _t{constructor(t){this.buffer=t,this.x=0,this.y=0,this.bgcolor=0,this.fgcolor=15,this.printViewTop=0,this.printViewBottom=24}}class Xt{constructor(t){this.canvasHolder=t,this.textOutput="",this.relativeViewport=!1,this.activeBufferIndex=0,this.dirty=!0,this.currentScreen=0,this.inputBuffer=new zt,this.currentScreen=-1,this.screen(0,void 0,void 0,void 0),this.charmap=Wt(),this.charHeight=this.charmap.height,window.setInterval(()=>this.refresh(),100)}destroy(){this.inputBuffer.destroy(),this.canvas&&this.canvas.remove()}bestCanvasSize(){const t=this.canvasHolder.offsetWidth,e=this.width;let r=1;for(let i=2;i<10;i++)e*i<=t&&(r=i);return[r*e,r*this.height]}refresh(){if(this.canvas){const[t,e]=this.bestCanvasSize();t===this.canvas.width&&e===this.canvas.height||([this.canvas.width,this.canvas.height]=this.bestCanvasSize())}this.dirty&&this.s&&(this.s.draw(),this.dirty=!1)}newline(){this.abuf().x=0,this.abuf().y+=1}setDims(t,e,r,i,n){this.charHeight=i,this.width=t,this.height=e,this.cols=Math.trunc(t/r),this.rows=Math.trunc(e/i),this.canvas&&(this.canvas.remove(),this.s.free(),this.s=void 0,this.canvas=void 0),this.canvas=document.createElement("canvas"),[this.canvas.width,this.canvas.height]=this.bestCanvasSize(),this.canvasHolder.appendChild(this.canvas),this.s=new Dt(this.canvas,this.width,this.height),this.screenBuffers=[new _t(this.s.buffer)],this.activeBufferIndex=0;for(let t=1;t<n;t++)this.screenBuffers.push(new _t(new Ot(this.s.buffer.width,this.s.buffer.height)));this.graphicsViewport=this.s.buffer.fullViewport.copy(),this.textViewport=this.s.buffer.fullViewport.copy(),this.abuf().printViewTop=1,this.abuf().printViewBottom=this.rows}cursor(t){}locate(t,e){const r=this.abuf();void 0!==e&&(r.x=Math.max(0,Math.min(Math.floor(e),this.cols-1))),void 0!==t&&(r.y=Math.max(0,Math.min(Math.floor(t),this.rows-1)))}print(t){const e=this.abuf();this.cursor(!1);for(const r of t)if(e.y>=e.printViewBottom&&this.scroll(),"\t"===r)e.x=14*Math.floor((e.x+14)/14),e.x>=this.cols&&(e.x=0,this.newline());else if("\n"===r)this.newline();else{const t=r.charCodeAt(0);e.buffer.drawChar(e.x,e.y,t,e.fgcolor,e.bgcolor,this.charmap,this.textViewport),this.dirty=!0,e.x+=1,e.x===this.cols&&this.newline()}}input(t){const e=this.abuf().x,r=this.abuf().y;let i="";const n=(n,s)=>{for(this.abuf().x=e,this.abuf().y=r;i&&i.length>n.length;)n+=" ";this.print(n),i=n,s&&(this.inputBuffer.inputChanged=void 0,this.inputBuffer.input="",t(n))};this.inputBuffer.inputChanged=n,n(this.inputBuffer.input,!1)}inkeyWait(t,e){let r="",i=0;this.inputBuffer.keyPressed=(n=>{r+=n,++i===t&&(this.inputBuffer.keyPressed=void 0,e(r))})}setForeColor(t){this.abuf().fgcolor=t}setBackColor(t){this.abuf().bgcolor=t}foreColor(){return this.abuf().fgcolor}backColor(){return this.abuf().bgcolor}resetPalette(){if(!this.s)return;const t=Nt.get(this.currentScreen);t&&(this.s.setPalette(t),this.dirty=!0)}setPaletteAttribute(t,e){if(!this.s)return;const r=[e%256,Math.trunc(e/256)%256,Math.trunc(e/65536)%256];this.s.setPaletteEntry(t,r),this.dirty=!0}inkey(){return this.inputBuffer.nextKey()}pset(t,e,r){const i=this.abuf();r||(r=i.fgcolor),i.buffer.pset(t,e,r,this.graphicsViewport),this.dirty=!0}point(t,e){return this.abuf().buffer.pget(t,e)}setViewPrint(t,e){this.abuf().y=t-1,this.abuf().x=0,this.abuf().printViewTop=t-1,this.abuf().printViewBottom=e-1}setView(t,e,r,i,n){this.s&&([this.graphicsViewport.left,this.graphicsViewport.top]=this.s.buffer.fullViewport.clamp(Math.min(t,r),Math.min(e,i)),[this.graphicsViewport.right,this.graphicsViewport.bottom]=this.s.buffer.fullViewport.clamp(Math.max(t,r),Math.max(e,i)),this.relativeViewport=n)}screenLines(){return this.rows}circle(t,e,r,i,n,s,o){const a=this.abuf();this.relativeViewport&&(t+=this.graphicsViewport.left,e+=this.graphicsViewport.top),void 0===i&&(i=a.fgcolor),a.buffer.drawCircle(t,e,r,i,n,s,o,this.graphicsViewport),this.dirty=!0}paint(t,e,r,i){const n=this.abuf();this.relativeViewport&&(t+=this.graphicsViewport.left,e+=this.graphicsViewport.top),void 0===r&&(r=n.fgcolor),void 0===i&&(i=r),n.buffer.paint(t,e,r,i,this.graphicsViewport)}line(t,e,r,i,n,s,o){const a=this.abuf();switch(this.relativeViewport&&(t+=this.graphicsViewport.left,e+=this.graphicsViewport.top,r+=this.graphicsViewport.left,i+=this.graphicsViewport.top),void 0===n&&(n=a.fgcolor),s){case R.kLine:a.buffer.line(t,e,r,i,n,o,this.graphicsViewport);break;case R.kBox:a.buffer.rect(t,e,r,i,n,o,this.graphicsViewport);break;case R.kFilledBox:a.buffer.filledRect(t,e,r,i,n,this.graphicsViewport)}this.dirty=!0}draw(t,e,r){const i=this.abuf();this.relativeViewport&&(t+=this.graphicsViewport.left,e+=this.graphicsViewport.top);let n=0,s=1;for(const o of r)switch(o.id){case P.kMove:case P.kMoveXY:{const[r,a]=o.getPosition(t,e,n,s);o.noDraw||i.buffer.line(t,e,r,a,i.fgcolor,65535,this.graphicsViewport),o.returnWhenDone||(t=r,e=a);break}case P.kRotation:n=o.a*(Math.PI/2);break;case P.kTurn:n=o.a*(Math.PI/180);break;case P.kColor:i.fgcolor=o.a;case P.kScale:s=o.a/4;break;case P.kPaint:}}bitsPerPixel(){const t=Nt.get(this.currentScreen);if(!t)return 8;const e=t.length;let r=1;for(;1<<r<e;)++r;return r}getGraphics(t,e,r,i,n){const s=this.abuf();this.relativeViewport&&(t+=this.graphicsViewport.left,e+=this.graphicsViewport.top,r+=this.graphicsViewport.left,i+=this.graphicsViewport.top);const o=Math.min(t,r),a=Math.min(e,i),l=Math.max(t,r),c=Math.max(e,i),h=l-o+1,u=c-a+1,f=this.bitsPerPixel(),d=h*f,p=4+Math.floor((d+7)/8)*u;if(p>n)return;const g=new Uint8Array(p);let m=0,v=0;const y=t=>{g[m++]=t},b=t=>{y(t%256),y(t/256%256)},x=t=>{v?(g[m++]+=t<<4,v=0):(g[m]=t,v=1)};if(b(d),b(u),8===f)for(let t=a;t<=c;++t){const e=s.buffer.offsetAt(o,t);g.set(s.buffer.data.slice(e,e+h),m),m+=h}else{if(4!==f)return void console.log("not yet implemented: "+f+" bits per pixel");for(let t=a;t<=c;++t){const e=s.buffer.offsetAt(o,t);for(let t=o;t<=l;++t)x(s.buffer.data[e+t-o]%16);v&&(v=0,++m)}}return g}putGraphics(t,e,r,i){const n=this.abuf();if(this.relativeViewport&&(t+=this.graphicsViewport.left,e+=this.graphicsViewport.top),r.length<4)return;let s=0,o=0;const a=()=>r[s++],l=()=>a()+(a()<<8),c=()=>o?(o=0,r[s++]>>4):(o=1,r[s]%16),h=l(),u=l(),f=this.bitsPerPixel();if(8===f){const i=Math.floor(h/8);for(let o=0;o<u;++o)n.buffer.data.set(r.slice(s,s+i),n.buffer.offsetAt(t,e+o)),s+=i}else{if(4!==f)return void console.log("not yet implemented: "+f+" bits per pixel");{const r=Math.floor(h/4);for(let i=0;i<u;++i){const s=n.buffer.offsetAt(t,e+i);for(let t=0;t<r;++t)n.buffer.data[s+t]=c();o&&c()}}}}screen(t,e,r,i){if(void 0!==t){if(!At.has(t))return;const[e,r]=At.get(t);switch(t){case 1:case 2:case 7:case 8:case 13:this.charmap=Ut(Mt.k8x8);break;case 0:case 4:case 11:case 12:default:this.charmap=Wt();break;case 9:this.charmap=Ut(Mt.k8x14)}let i=1;switch(t){case 0:case 7:i=8;break;case 8:i=4;break;case 9:i=2}if(t!==this.currentScreen){if(this.setDims(e,r,this.charmap.width,this.charmap.height,i),!this.s)return;this.s.setPalette(Nt.get(t)),this.currentScreen=t}}this.s&&(void 0!==r&&r>=0&&r<this.screenBuffers.length&&(this.activeBufferIndex=r),void 0!==i&&i>=0&&i<this.screenBuffers.length&&(this.s.buffer=this.screenBuffers[i].buffer,this.dirty=!0))}sleep(t,e){window.setTimeout(()=>{e()},1e3*t)}cls(){const t=this.abuf();t.buffer.clear(t.bgcolor),this.dirty=!0,t.x=0,t.y=t.printViewTop}clsText(){const t=this.abuf();t.buffer.filledRect(0,this.abuf().printViewTop*this.charHeight,this.width,t.printViewBottom*this.charHeight+this.charHeight,t.bgcolor,this.textViewport),t.y=t.printViewTop,t.x=0}clsGraphics(){const t=this.abuf();t.buffer.filledRect(this.graphicsViewport.left,this.graphicsViewport.top,this.graphicsViewport.right,this.graphicsViewport.bottom,t.bgcolor,this.graphicsViewport)}scroll(){const t=this.abuf(),e=t.printViewBottom-t.printViewTop;if(e>0){const r=this.charHeight*t.printViewTop;t.buffer.blt(t.buffer,0,this.charHeight+r,this.width,e*this.charHeight,0,r),t.buffer.filledRect(0,t.printViewBottom*this.charHeight,this.width,t.printViewBottom*this.charHeight+this.charHeight,t.bgcolor,this.textViewport),this.dirty=!0}this.abuf().y-=1}abuf(){return this.screenBuffers[this.activeBufferIndex]}}var jt=r(0);r(7),r(8);let Kt;function qt(){return Kt.getValue()}function Yt(t){return Kt.setValue(t)}function Jt(t){Kt.disabled=t}jt.registerHelper("lint","qbasic",t=>{const e=[],r=function(t){const e=h(t),r=new wt;C(r,e);const i=[];for(let t=0;t<r.errors().length;t++)i.push({col:r.errorLocations()[t].position,line:r.errorLocations()[t].line+1,message:r.errors()[t]});return i}(t);for(const t of r)e.push({from:jt.Pos(t.line-1,t.col),to:jt.Pos(t.line-1,t.col+1),message:t.message});return e}),jt.defineSimpleMode("qbasic",{start:[{regex:/"[^"]*"/,token:"string"},{regex:/(REM\s|').*/,token:"comment"}]});var Zt=function(t,e,r,i){return new(r||(r=Promise))(function(n,s){function o(t){try{l(i.next(t))}catch(t){s(t)}}function a(t){try{l(i.throw(t))}catch(t){s(t)}}function l(t){t.done?n(t.value):new r(function(e){e(t.value)}).then(o,a)}l((i=i.apply(t,e||[])).next())})};class Qt{constructor(t,e,r){this.id=t,this.title=e,this.content=r}}function $t(t){return Zt(this,void 0,void 0,function*(){return new Promise((e,r)=>{t.onsuccess=e,t.onerror=r})})}const te=new class{constructor(){this.queuedBeforeLoad=[];const t=window.indexedDB.open("programs",1);t.onerror=(()=>{console.error("failed to open indexdb")}),t.onsuccess=(()=>this.loaded(t.result)),t.onupgradeneeded=(t=>{this.db=t.target.result,this.db.createObjectStore("programs",{keyPath:"program_id"}).createIndex("program_id","program_id",{unique:!0})})}loaded(t){this.db=t;for(const t of this.queuedBeforeLoad)t()}whenLoaded(){return this.db?new Promise(t=>t()):new Promise(t=>{this.queuedBeforeLoad.push(t)})}waitForLoad(){return Zt(this,void 0,void 0,function*(){if(!this.db)return new Promise(t=>{this.queuedBeforeLoad.push(t)})})}save(t,e){return this.whenLoaded().then(()=>{const r=this.db.transaction(["programs"],"readwrite").objectStore("programs");e.substr(0,200);const i=r.add({program_id:t,title:function(t){for(let e of t.substr(0,200).split("\n"))if((e=e.trim()).startsWith("REM")&&(e=e.substr(3).trim()),e.length>2)return e.substr(0,50);return"Untitled"}(e),content:e});return new Promise((t,e)=>{i.onsuccess=t,i.onerror=e})})}load(t){return Zt(this,void 0,void 0,function*(){yield this.waitForLoad();const e=this.db.transaction(["programs"],"readonly").objectStore("programs").get(t);return $t(e).then(()=>new Qt(t,e.result.title,e.result.content))})}list(){return Zt(this,void 0,void 0,function*(){yield this.waitForLoad();const t=this.db.transaction(["programs"],"readonly").objectStore("programs").openCursor(),e=[];return new Promise((r,i)=>{t.onerror=(()=>i()),t.onsuccess=(()=>{const i=t.result;i?(e.push(new Qt(i.value.program_id,i.value.title)),i.continue()):r(e)})})})}remove(t){return Zt(this,void 0,void 0,function*(){return yield this.waitForLoad(),$t(this.db.transaction(["programs"],"readwrite").objectStore("programs").delete(t))})}};const ee={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};function re(t){return String(t).replace(/[&<>"'`=\/]/g,t=>ee[t])}r.d(e,"AppState",function(){return ne}),r.d(e,"showMenu",function(){return le}),r.d(e,"hideMenus",function(){return ce}),r.d(e,"save",function(){return he}),r.d(e,"start",function(){return ue}),r.d(e,"stop",function(){return fe}),r.d(e,"newfile",function(){return de}),r.d(e,"open",function(){return pe}),r.d(e,"deleteprogram",function(){return ge}),r.d(e,"closeOpenDialog",function(){return me}),function(t){Kt=jt.fromTextArea(t,{theme:"dos",mode:"qbasic",gutters:["CodeMirror-lint-markers"],viewportMargin:1/0,lint:!0})}(document.getElementById("editor"));const ie='REM Untitled Program\n\nCOLOR 5\nPRINT "HELLO ";\nCOLOR 7\nPRINT " WORLD!"\n';class ne{constructor(){this.currentProgramID="",this.loading=!1,window.onload=(()=>{window.onhashchange=(()=>this.hashChanged()),this.hashChanged(),this.newProgram()}),Ht()}hashChanged(){const t=window.location.hash.substr(1);if(0!==t.length)return"new"===t?(Yt(ie),void(window.location.hash="")):void(function(t){if(!t)return!1;try{return t=(t=t.replace(/-/g,"+")).replace(/_/g,"/"),32===atob(t).length}catch(t){return!1}}(t)&&t!==this.currentProgramID&&(document.getElementById("opendialog").classList.add("hidden"),this.loadProgram(t)))}newProgram(){this.currentProgramID="",window.location.hash="new"}setLoading(t){this.loading!==t&&(this.loading=t,this.loading?(Jt(!0),document.getElementById("loading").classList.remove("hidden")):(Jt(!1),document.getElementById("loading").classList.add("hidden")))}loadProgram(t){Yt(""),this.setLoading(!0),function(t){return te.load(t)}(t).then(t=>{Yt(t.content),this.setLoading(!1)}).catch(()=>{this.setLoading(!1),window.alert("failed to load program"),this.newProgram()})}deleteProgram(t){if(!window.confirm("Really delete this program?"))return;if(!this.currentProgramID.length)return this.newProgram(),void t(!0);!function(t){te.remove(t)}(this.currentProgramID),this.newProgram()}saveProgram(t){let e=this.currentProgramID;e||(e=function(){let t="";const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let r=0;r<64;r++){const r=Math.trunc(64*Math.random());e[r]||console.log(r),t+=e[r]}return t=(t=(t=btoa(atob(t).substr(0,32))).replace(/\+/g,"-")).replace(/\//g,"_")}()),function(t,e){return te.save(t,e)}(e,qt()).then(()=>{this.currentProgramID=e})}}const se=new ne;function oe(t){return document.getElementById(t).classList.contains("menuopen")}function ae(t){t.classList.contains("menuopen")?t.classList.remove("menuopen"):t.classList.add("menuopen")}function le(t){const e=oe(t);ce(),e||ae(document.getElementById(t))}function ce(){for(const t of["filemenu","runmenu"])oe(t)&&ae(document.getElementById(t))}function he(){se.saveProgram(t=>{t||alert("ERROR SAVING PROGRAM")})}function ue(){const t=qt(),e=h(t),r=new wt;if(C(r,e),r.errors().length>0){console.log("Compile errors:");for(const t of r.errors())console.log(` ${t}`);return!1}document.getElementById("program_running").classList.remove("hidden"),document.getElementById("program_complete").classList.add("hidden"),document.getElementById("runscreen").classList.remove("hidden"),document.getElementById("editscreen").classList.add("hidden"),se.pc&&se.pc.destroy();const i=new Xt(document.getElementById("canvasholder"));se.pc=i,r.program().source=t,se.exe=new ot(r.program(),i),se.exe.onEnd=(()=>{document.getElementById("program_running").classList.add("hidden"),document.getElementById("program_complete").classList.remove("hidden")}),se.exe.onException=((t,e)=>{document.getElementById("program_running").classList.add("hidden"),document.getElementById("program_complete").classList.remove("hidden"),function(t){Kt.setCursor(t,0)}(e),window.alert("Exception: "+t+", on line "+e)}),se.exe.start()}function fe(){se.exe&&(se.exe.destroy(),se.exe=void 0),se.pc&&(se.pc.destroy(),se.pc=void 0),document.getElementById("runscreen").classList.add("hidden"),document.getElementById("editscreen").classList.remove("hidden"),Kt.focus()}function de(){fe(),se.newProgram()}function pe(){te.list().then(t=>{const e=document.getElementById("openprogramtable"),r=[];for(const e of t)r.push(`<tr><td><a href='#${e.id}'>${re(e.title)}</a></td></tr>`);e.innerHTML=r.join("\n"),document.getElementById("opendialog").classList.remove("hidden")})}function ge(){se.deleteProgram(()=>{})}function me(){document.getElementById("opendialog").classList.add("hidden"),document.getElementById("openprogramtable").innerHTML=""}window.addEventListener("keypress",t=>{se.exe&&se.exe.done&&!document.getElementById("runscreen").classList.contains("hidden")&&(fe(),t.preventDefault())}),window.addEventListener("keydown",t=>{("/"===t.key&&t.ctrlKey||"F5"===t.key)&&(ue(),t.preventDefault())})}]);</script>
</html>