forked from monopole/mdrip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webapp.go
1753 lines (1610 loc) · 44.1 KB
/
webapp.go
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
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package webapp
import (
"crypto/rand"
"encoding/gob"
"html/template"
"io"
"bytes"
"fmt"
"github.com/gorilla/sessions"
"github.com/monopole/mdrip/base"
"github.com/monopole/mdrip/model"
"github.com/monopole/mdrip/program"
)
// TypeSessID represents a session ID.
type TypeSessID string
const forRegistration = TypeSessID("arbitrary")
func init() {
gob.Register(forRegistration)
}
// SessionData holds session state data, presumably associated with a cookie.
type SessionData struct {
// The session ID.
SessID TypeSessID
// Is the header showing?
IsHeaderOn bool
// Is the nav showing?
IsNavOn bool
// The active lesson.
LessonIndex int
// The active block.
BlockIndex int
}
// These must all be unique, and preferably short.
// They are used as URL query param and cookie field names.
const (
// KeySessID is the param name for session ID.
KeySessID = "sid"
// KeyIsHeaderOn is the param name for is the header on boolean.
KeyIsHeaderOn = "hed"
// KeyIsNavOn is the param name for the is the nav on boolean.
KeyIsNavOn = "nav"
// KeyLessonIndex is the param name for the lesson index.
KeyLessonIndex = "lix"
// KeyBlockIndex is the param name for the block index.
KeyBlockIndex = "bix"
)
func makeSessionID() TypeSessID {
b := make([]byte, 3)
if _, err := rand.Read(b); err != nil {
panic(err)
}
return TypeSessID(fmt.Sprintf("%x", b))
}
// AssureSessionData tries to recover session data, saving defaults for missing data.
func AssureSessionData(s *sessions.Session) *SessionData {
r := &SessionData{}
var ok bool
r.SessID, ok = s.Values[KeySessID].(TypeSessID)
if !ok {
r.SessID = makeSessionID()
s.Values[KeySessID] = r.SessID
}
r.IsHeaderOn, ok = s.Values[KeyIsHeaderOn].(bool)
if !ok {
r.IsHeaderOn = true
s.Values[KeyIsHeaderOn] = r.IsHeaderOn
}
r.IsNavOn, ok = s.Values[KeyIsNavOn].(bool)
if !ok {
r.IsNavOn = false
s.Values[KeyIsNavOn] = r.IsNavOn
}
r.LessonIndex, ok = s.Values[KeyLessonIndex].(int)
if !ok {
r.LessonIndex = 0
s.Values[KeyLessonIndex] = r.LessonIndex
}
r.BlockIndex, ok = s.Values[KeyBlockIndex].(int)
if !ok {
r.BlockIndex = -1
s.Values[KeyBlockIndex] = r.BlockIndex
}
return r
}
// WebApp presents a tutorial to a web browser.
type WebApp struct {
sessionData *SessionData
host string
tut model.Tutorial
ds *base.DataSource
tmpl *template.Template
rawLessons []*program.LessonPgm
title string
lessonPath []int
coursePaths [][]int
}
// NewWebApp makes a new web app.
func NewWebApp(
sessionData *SessionData, host string,
tut model.Tutorial, ds *base.DataSource, lp []int, cp [][]int) *WebApp {
v := program.NewLessonPgmExtractor(base.WildCardLabel)
tut.Accept(v)
title := v.FirstTitle()
if len(title) > maxTitleLength {
title = title[maxTitleLength-3:] + "..."
}
return &WebApp{
sessionData, host, tut, ds, makeParsedTemplate(tut),
v.Lessons(), title, lp, cp}
}
// SessID is the id of the session returned
func (wa *WebApp) SessID() TypeSessID { return wa.sessionData.SessID }
// Host is the webapp's host.
func (wa *WebApp) Host() string { return wa.host }
// Lessons is the list of lessons known to the webapp.
func (wa *WebApp) Lessons() []*program.LessonPgm {
return wa.rawLessons
}
// DataSourceName is the source of the data.
func (wa *WebApp) DataSourceName() string {
return wa.ds.Display()
}
// DataSourceLink lets the user find the original data.
func (wa *WebApp) DataSourceLink() template.URL {
return template.URL(wa.ds.Href())
}
// DocTitle is the name of the document or web page.
func (wa *WebApp) DocTitle() string {
return wa.title
}
const (
// arbitrary
maxTitleLength = len("gh:kubernetes/website/reference") + 10
)
// InitialHeaderOn is should the header be on?
func (wa *WebApp) InitialHeaderOn() bool {
return wa.sessionData.IsHeaderOn
}
// InitialNavOn is should the nav be on?
func (wa *WebApp) InitialNavOn() bool {
return wa.sessionData.IsNavOn
}
// InitialBlock is where the user should start.
func (wa *WebApp) InitialBlock() int {
return wa.sessionData.BlockIndex
}
// InitialLesson is where the user should start.
func (wa *WebApp) InitialLesson() int {
if len(wa.lessonPath) == 0 {
return 0
}
return wa.lessonPath[len(wa.lessonPath)-1]
}
// Return everything BUT the last element
// i.e. omit the file, just return the directory path.
func (wa *WebApp) xCoursePath() []int {
if len(wa.lessonPath) == 0 {
return []int{}
}
return wa.lessonPath[:len(wa.lessonPath)-1]
}
// CoursePaths emits a javascript 2D array holding lesson paths.
// The length equals the number of lessons.
// Each entry should contain an array of course indices
// that should be active when the lesson is active.
func (wa *WebApp) CoursePaths() [][]int {
return wa.coursePaths
}
// Named color specifications to use on the web page.
const (
blue700 = "#1976D2"
blue500 = "#2196F3"
blue200 = "#90CAF9"
deepOrange500 = "#FF5722"
deepOrange200 = "#FF8A65"
deepOrange700 = "#E64A19"
teal = "#00838f"
hackerNewsBeige = "#f6f6ef"
k8sBlue = "#326DE6"
grayIsh = "#c9c9c9"
whiteIsh = "#e3e3e3"
seaBlue = "#9ad3de"
darkerBlue = "#89bdd3"
hoverBlue = "#06e"
terminalGreen = "#33ff66"
greenA200 = "#B2FF59"
greenA400 = "#76FF03"
greenA700 = "#64DD17"
)
// ColorBackground is just that.
func (wa *WebApp) ColorBackground() string { return "white" }
// ColorHelpBackground is just that.
func (wa *WebApp) ColorHelpBackground() string { return whiteIsh }
// ColorHeader is just that.
func (wa *WebApp) ColorHeader() string { return blue700 }
// ColorCodeBlockText is just that.
func (wa *WebApp) ColorCodeBlockText() string { return greenA400 }
// ColorCodeBlockBackground is just that.
func (wa *WebApp) ColorCodeBlockBackground() string { return "black" }
// ColorNavBackground is just that.
func (wa *WebApp) ColorNavBackground() string { return blue200 }
// ColorNavText is just that.
func (wa *WebApp) ColorNavText() string { return "black" }
// ColorNavSelected is just that.
func (wa *WebApp) ColorNavSelected() string { return wa.ColorBackground() }
// ColorHover is just that.
func (wa *WebApp) ColorHover() string { return deepOrange500 }
// ColorCodeHover is just that.
func (wa *WebApp) ColorCodeHover() string { return deepOrange700 }
// ColorControls is just that.
func (wa *WebApp) ColorControls() string { return greenA200 }
// ColorTitle is just that.
func (wa *WebApp) ColorTitle() string { return wa.ColorControls() }
// TransitionSpeedMs is speed of css transitions in milliseconds.
func (wa *WebApp) TransitionSpeedMs() int { return 250 }
// LayBodyWideWidth is the min body width of "wide" mode.
func (wa *WebApp) LayBodyWideWidth() int { return 1200 }
// LayBodyMediumWidth is the min body width of medium mode.
// Small mode (presumably phones) is anything thinner.
func (wa *WebApp) LayBodyMediumWidth() int { return 800 }
// LayMinHeaderWidth is just that.
func (wa *WebApp) LayMinHeaderWidth() int { return 400 }
// LayNavBoxWidth is just that.
func (wa *WebApp) LayNavBoxWidth() int { return 210 }
// LayHeaderHeight is just that.
func (wa *WebApp) LayHeaderHeight() int { return 120 }
// LayFooterHeight is just that.
func (wa *WebApp) LayFooterHeight() int { return 50 }
// LayMinimizedHeaderHeight is just that.
func (wa *WebApp) LayMinimizedHeaderHeight() int { return wa.LayFooterHeight() }
// LayNavTopBotPad is just that.
func (wa *WebApp) LayNavTopBotPad() int { return 7 }
// LayNavLeftPad is just that.
func (wa *WebApp) LayNavLeftPad() int { return 20 }
// KeyLessonIndex delivers the corresponding const to a template.
func (wa *WebApp) KeyLessonIndex() string { return KeyLessonIndex }
// KeyBlockIndex delivers the corresponding const to a template.
func (wa *WebApp) KeyBlockIndex() string { return KeyBlockIndex }
// KeyIsHeaderOn delivers the corresponding const to a template.
func (wa *WebApp) KeyIsHeaderOn() string { return KeyIsHeaderOn }
// KeyIsNavOn delivers the corresponding const to a template.
func (wa *WebApp) KeyIsNavOn() string { return KeyIsNavOn }
// KeySessID delivers the corresponding const to a template.
func (wa *WebApp) KeySessID() string { return KeySessID }
// LessonCount is just that.
func (wa *WebApp) LessonCount() int {
c := model.NewTutorialLessonCounter()
wa.tut.Accept(c)
return c.Count()
}
// Render writes a web page to the given writer.
func (wa *WebApp) Render(w io.Writer) error {
return wa.tmpl.ExecuteTemplate(w, tmplNameWebApp, wa)
}
func makeParsedTemplate(tut model.Tutorial) *template.Template {
return template.Must(
template.New("main").Parse(
tmplBodyLesson +
tmplBodyBlockPgm +
tmplBodyLessonList +
tmplBodyLessonHead +
makeAppTemplate(makeLeftNavBody(tut))))
}
// The logic involved in building the leftnav is much less awkward
// in plain Go than in the Go template language, so creating it
// this way rather than writing it out with a bunch of {{if}}s, etc.
func makeLeftNavBody(tut model.Tutorial) string {
var b bytes.Buffer
v := NewTutorialNavPrinter(&b)
tut.Accept(v)
return b.String()
}
func makeAppTemplate(htmlNavActual string) string {
return `
{{define "` + tmplNameWebApp + `"}}
<html>
<head>
<style type="text/css">` + cssInHeader + `
</style>
<script type="text/javascript">` + jsInHeader + `
</script>
</head>
<body onload='onLoad()'>
<header id='header'>
<div class='navButtonBox'>
<div class='navBurger'>
<div class='burgBar1'></div>
<div class='burgBar2'></div>
<div class='burgBar3'></div>
</div>
</div>
<div class='headerColumn'>
<title id='title'> {{.DocTitle}} </title>
<div class='activeLessonName'> Droplet Formation Rates </div>
` + htmlLessonNavRow + `
</div>
<div class='navButtonBox'> </div>
</header>
<div class='navLeftBox navLeftBoxShadow' tabindex='-1'>
<nav class='navActual'>
` + htmlNavActual + `
</nav>
</div>
<div class='helpBox'>
<div class='helpActual'>
` + htmlHelp + `
</div>
</div>
<div class='navRightBox navRightBoxShadow'>
<nav class='navActual'>
<!-- <p> T O C </p> <p> COMING </p> <p> HERE </p> -->
</nav>
</div>
<div class='scrollingColumn'>
<div class='headSpacer'> HEADER SPACER </div>
<div class='proseRow'>
<div class='navLeftSpacer'> </div>
<div class='proseColumn'>
{{ template "` + tmplNameLessonList + `" .Lessons }}
</div>
<div class='navRightSpacer'> </div>
</div>
<footer>
` + htmlLessonNavRow + `
</footer>
</div>
</body>
</html>
{{end}}
`
}
const (
tmplNameWebApp = "webApp"
tmplNameLessonList = "lessonList"
tmplBodyLessonList = `
{{define "` + tmplNameLessonList + `"}}
{{range $i, $c := .}}
<div class='oneLesson' id='BL{{$i}}' data-id='{{$i}}' >
{{ template "` + tmplNameLesson + `" $c }}
</div>
{{end}}
{{end}}
`
tmplNameLesson = "oneLesson"
tmplBodyLesson = `
{{define "` + tmplNameLesson + `"}}
{{range $i, $c := .Blocks}}
<div class="commandBlockBody">
{{ template "` + tmplNameBlockPgm + `" $c }}
</div>
{{end}}
{{end}}
`
tmplNameBlockPgm = "blockPgm"
tmplBodyBlockPgm = `
{{define "` + tmplNameBlockPgm + `"}}
<div class='proseblock'> {{.HTMLProse}} </div>
{{if .Code}}
<div class='codeBox' data-id='{{.ID}}'>
<div class='codeBlockControl'>
<span class='codePrompt'> > </span>
<span class='codeBlockButton' onclick='codeBlockController.setAndRun({{.ID}})'>
{{.Name}}
</span>
<span class='codeBlockSpacer'> </span>
</div>
<div class='codeblockBody'>
{{ .Code }}
</div>
</div>
{{end}}
{{end}}
`
tmplNameLessonHead = "lessonhead"
tmplBodyLessonHead = `
{{define "` + tmplNameLessonHead + `"}}
<p><code> {{.Path}} </code></p>
{{end}}
`
)
const htmlLessonNavRow = `
<div class='lessonNavRow'>
<div class='lessonPrevClickerRow'>
<div class='lessonPrevTitle'> quantum flux </div>
<div class='lessonPrevPointer'> < </div>
</div>
<div class='helpButtonBox'> ? </div>
<div class='lessonNextClickerRow'>
<div class='lessonNextPointer'> > </div>
<div class='lessonNextTitle'> magnetic flux </div>
</div>
</div>
`
const htmlHelp = `
<p>
Snapshot of markdown from
<a target='_blank' href='{{.DataSourceLink}}'><code>{{.DataSourceName}}</code></a>.
<h3>Keys</h3>
<p>
<table>
<tr>
<td class='kind'> help </td>
<td> ? / </td>
</tr>
<tr>
<td class='kind'> activate (previous, next) code block </td>
<td> w, s j, k </td>
</tr>
<tr>
<td class='kind'> scroll to active code block </td>
<td> x </td>
</tr>
<tr>
<td class='kind'> copy/execute activated block </td>
<td> ↵ </td>
</tr>
<tr>
<td class='kind'> (previous, next) lesson </td>
<td> a, d h, l ←, → </td>
</tr>
<tr>
<td class='kind'> minimize header </td>
<td> - </td>
</tr>
<tr>
<td class='kind'> nav sidebar </td>
<td> n </td>
</tr>
<tr>
<td class='kind'> monkey </td>
<td> ! </td>
</tr>
</table>
</p>
<h3> Serve locally with tmux for no-mouse execution</h3>
<p>
Serve the content locally with
<code><a target="_blank"
href="https://github.com/monopole/mdrip">mdrip</a></code>:
<pre>
GOBIN=$TMPDIR go install github.com/monopole/mdrip
$TMPDIR/mdrip --port 8001 --mode demo {{.DataSourceName}}
</pre>
and run <a target="_blank"
href="https://github.com/tmux/tmux/wiki">tmux</a>:
<pre>
tmux
</pre>
Then, at <a target="_blank"
href="http://localhost:8001">localhost:8001</a>,
whatever action copies a code block (↵ or mouse click)
also pastes the block to the active tmux pane for
immediate execution.
</p>
<h3> Remote server tmux </h3>
<p> <em>Proof of concept
for using tmux over a websocket to remote servers.
Currently lacks the session mgmt necessary
to reliably work with LB traffic.
The websocket described below not needed in the previous
scenario using a local server. </em></p>
<p>
For one-click usage from a remote server:
<ul>
<li>
Install <code><a target="_blank"
href="https://github.com/monopole/mdrip">mdrip</a></code>
as described above, and run <a target="_blank"
href="https://github.com/tmux/tmux/wiki">tmux</a>.
</li>
<li>In some non-tmux shell, run mdrip in <em>tmux</em> mode with a session arg:
<pre>
mdrip --mode tmux \
ws://{{.Host}}/_/ws?{{.KeySessID}}={{.SessID}}
</pre>
</li>
</ul>
<p>
Now, a copy action sends the block
from this page's server over a websocket to the local
<code>mdrip</code>, which then pastes the block
to the active <code>tmux</code> pane.<p>
<p>
The <code>mdrip</code> service self-exits after a period of inactivity,
and can be restarted with the same command.</p>
`
const cssInHeader = `
body {
padding: 0;
margin: 0;
background-color: darkgray;
/* font-family: "Roboto", sans-serif; */
/* font-family: "Veranda", Veranda, sans-serif; */
font-family: Verdana, Geneva, sans-serif;
position: relative;
font-size: 12pt;
line-height: 1.4;
-webkit-font-smoothing: antialiased;
width: 100%;
}
td.kind {
text-align: right;
padding-right: 2em;
}
header, .headSpacer {
height: {{.LayHeaderHeight}}px;
width: inherit;
transition: height {{.TransitionSpeedMs}}ms;
}
header {
position: fixed;
top: 0;
background: {{.ColorHeader}};
/* background: linear-gradient(0deg, {{.ColorBackground}}, {{.ColorHeader}}); */
display: flex;
justify-content: space-around; /* space-between */
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
transition: height {{.TransitionSpeedMs}}ms;
box-shadow: 0 2px 2px 2px rgba(0,0,0,.4);
}
.navLeftBox, .navRightBox {
position: fixed;
top: calc({{.LayHeaderHeight}}px + 2px); /* leave room for header drop-shadow */
height: calc(100vh - ({{.LayFooterHeight}}px + {{.LayHeaderHeight}}px + 4px));
background-color: {{.ColorNavBackground}};
color: {{.ColorNavText}};
display: inline-block;
overflow: hidden; /* initially hideNav */
width: 0px; /* initially hideNav */
min-width: 0px; /* initially hideNav */
transition: width {{.TransitionSpeedMs}}ms, min-width {{.TransitionSpeedMs}}ms;
}
.navRightBoxShadow {
/* shadow on bottom, top and left */
box-shadow: 0 2px 2px 2px rgba(0,0,0,.2), -2px 0px 2px 2px rgba(0,0,0,.2);
}
.navLeftBoxShadow {
/* shadow on bottom, top and right */
box-shadow: 0 2px 2px 2px rgba(0,0,0,.2), 2px 0px 2px 2px rgba(0,0,0,.2);
}
.navActual {
padding-left: 1em;
}
a {
text-decoration: none;
}
a:hover, a:visited, a:link, a:active {
text-decoration: none;
}
.navCourseTitle {
padding: 0px;
}
.navCourseTitle:hover {
color: {{.ColorHover}};
font-weight: bold;
}
.navItemTop {
/* top rig bot lef */
padding: {{.LayNavTopBotPad}}px 0px {{.LayNavTopBotPad}}px 4px;
}
.navItemBox {
/* top rig bot lef */
padding: {{.LayNavTopBotPad}}px 0px {{.LayNavTopBotPad}}px {{.LayNavLeftPad}}px;
}
.navCourseContent {
/* top rig bot lef */
padding: {{.LayNavTopBotPad}}px 0px 0px 0px;
}
.navLessonTitleOn {
background-color: {{.ColorNavSelected}};
}
.navLessonTitleOff {
}
.navLessonTitleOff:hover {
color: {{.ColorHover}};
font-weight: bold;
}
.scrollingColumn {
width: inherit;
}
.navLeftSpacer, .navRightSpacer {
width: {{.LayNavBoxWidth}}px;
min-width: {{.LayNavBoxWidth}}px;
display: none; /* initially hideNav */
}
.proseRow {
background-color: {{.ColorBackground}};
width: inherit;
display: flex;
flex-direction: row;
}
footer {
background: {{.ColorHeader}};
/* background: linear-gradient(0deg, {{.ColorHeader}}, {{.ColorBackground}}); */
height: {{.LayFooterHeight}}px;
}
.helpButtonBox, .navButtonBox {
font-size: larger;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
cursor: pointer;
color: {{.ColorControls}};
font-weight: bold;
border-radius: 50%;
}
.helpButtonBox {
width: 2em;
}
.helpButtonBox:hover {
background-color: {{.ColorHover}};
transition: all {{.TransitionSpeedMs}}ms;
box-shadow: inset 0 0 0 3px rgba(255,255,255,0.1);
}
.headerColumn {
width: 80%;
min-width: {{.LayMinHeaderWidth}}px;
height: inherit;
display: flex;
justify-content: center;
flex-direction: column;
flex-wrap: nowrap;
align-items: center;
}
title {
font-size: 2em;
font-weight: bold;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.activeLessonName {
font-weight: bold;
}
.lessonNavRow {
height: inherit;
display: flex;
width: 100%;
justify-content: center;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
}
.helpBox {
position: fixed;
top: {{.LayHeaderHeight}}px;
left: {{.LayNavBoxWidth}}px;
right: {{.LayNavBoxWidth}}px;
height: 0px; /* initially hideHelp */
z-index: 3;
background-color: {{.ColorHelpBackground}};
color: {{.ColorNavText}};
transition: height {{.TransitionSpeedMs}}ms;
overflow: auto;
}
.helpActual {
padding: 1em;
}
.proseColumn {
display: flex;
justify-content: flex-start;
flex-direction: column;
overflow-x: hidden;
overflow-y: auto;
align-items: flex-start;
transition: width {{.TransitionSpeedMs}}ms;
}
.proseActual {
/* top right bottom left */
padding: 0 1em 0 1em;
}
.lessonPrevClickerRow, .lessonNextClickerRow {
height: 100%;
color: {{.ColorControls}};
cursor: pointer;
display: flex;
flex-basis: 45%;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
}
.lessonPrevClickerRow:hover, .lessonNextClickerRow:hover {
color: {{.ColorHover}};
font-weight: bold;
}
.lessonPrevClickerRow {
justify-content: flex-end;
}
.lessonNextClickerRow {
}
.lessonPrevPointer, .lessonNextPointer {
/* top right bottom left */
padding: 0 1em 0 1em;
font-weight: bold;
font-size: larger;
}
.lessonPrevTitle, .lessonNextTitle {
font-style: oblique;
width: 100%;
cursor: pointer;
display: inline-block;
}
.lessonPrevTitle {
text-align: right;
}
.commandBlockBody {
margin: 0px;
border: 0px;
padding: 0px;
}
.codeBlockCheckOff {
display: inline-block;
width: 24px;
height: 15px;
background-repeat: no-repeat;
background-size: contain;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAWCAMAAADto6y6AAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAQtQTFRFAAAAAH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//AH//////BQzC2AAAAFd0Uk5TAAADLy4QZVEHKp8FAUnHbeJ3BAh68IYGC4f4nQyM/LkYCYnXf/rvAm/2/oFY7rcTPuHkOCEky3YjlW4Pqbww0MVTfUZA96p061Xs3mz1e4P70R2aHJYf2KM0AgAAAAFiS0dEWO21xI4AAAAJcEhZcwAAEysAABMrAbkohUIAAADTSURBVCjPbdDZUsJAEAXQXAgJIUDCogHBkbhFEIgCsqmo4MImgij9/39iUT4Qkp63OV0zfbsliTkIhWWOEVHUKOdaTNER9HgiaYQY1xUzlWY8kz04tBjP5Y8KRc6PxUmJcftUnMkIFGCdX1yqjDtX5cp1MChQrVHd3Xn8/y1wc0uNpuejZmt7Ae7aJDreBt1e3wVw/0D06HobYPD0/GI7Q0G10V4i4NV8e/8YE/V8KwImUxJEM82fFM78k4gW3MhfS1p9B3ckobgWBpiChJ/fjc//AJIfFr4X0swAAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE2LTA3LTMwVDE0OjI3OjUxLTA3OjAwUzMirAAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxNi0wNy0zMFQxNDoyNzo0NC0wNzowMLz8tSkAAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAFXRFWHRUaXRsZQBibHVlIENoZWNrIG1hcmsiA8jIAAAAAElFTkSuQmCC);
}
.codePrompt {
background-color: {{.ColorCodeHover}};
display: none;
}
.codeBlockButton {
height: 100%;
cursor: pointer;
}
.codeBlockButton:hover {
color: {{.ColorCodeHover}};
}
.codeBlockSpacer {
height: 100%;
width: 5px;
}
.codeBox {
padding-top: 10px;
padding-left: 20px;
}
.codeBlockControl {
font-family: "Lucida Console", Monaco, monospace;
font-weight: bold;
}
.codeblockBody {
white-space: pre;
font-family: "Lucida Console", Monaco, monospace;
color: {{.ColorCodeBlockText}};
background-color: {{.ColorCodeBlockBackground}};
margin-top: 5px;
padding-left: 10px;
overflow-x: auto;
border: solid 1px #555;
border-radius: 4px;
/* x y blur spread color x y blur spread color */
box-shadow: 0px 2px 1px 0px rgba(0,0,0,.3), 2px 0px 1px 0px rgba(0,0,0,.3);
min-width: {{.LayMinHeaderWidth}};
max-width: calc(100% - 40px);
}
.proseblock {
}
.oneLesson {
display: none;
padding: 0 1em 0 1em;
width: '100%';
padding-bottom: 1em;
}
.navBurger {
border-radius: 50%;
justify-content: center;
align-items: center;
display: flex;
flex-direction: column;
width: 2.8em;
height: 2.8em;
cursor: pointer;
}
.navBurger:hover {
background-color: {{.ColorHover}};
transition: all {{.TransitionSpeedMs}}ms;
box-shadow: inset 0 0 0 3px rgba(255,255,255,0.1), 0 1px 2px rgba(0,0,0,0.1);
}
.burgBar1, .burgBar2, .burgBar3 {
width: 28px;
height: 4px;
/* top rig bot lef */
margin: 2px 0 2px 0px;
transition: {{.TransitionSpeedMs}}ms;
/* offset-x | offset-y | blur-radius | spread-radius | color */
box-shadow: 0px 1px 1px 1px rgba(0,0,0,0.4);
border: solid 1px #555;
background-color: {{.ColorControls}};
border-radius:25px;
}
.burgIsAnX .burgBar1 {
transform: translate(0px, 5px) rotate(-45deg);
}
.burgIsAnX .burgBar2 {
display: none;
}
.burgIsAnX .burgBar3 {
transform: translate(0px, -5px) rotate(45deg);
box-shadow: 0px 0px 0px 0px rgba(0,0,0,0), 2px 0px 1px 0px rgba(0,0,0,0.4);
}
`
const jsInHeader = `
function getElByClass(n) {
return document.getElementsByClassName(n)[0];
}
function getDataId(el) {
return el.getAttribute("data-id");
}
function coinFlip() {
return (Math.random() >= 0.5);
}
// return int in range 0..(n-1)
function randomInt(n) {
return Math.floor(Math.random() * n)
}
function myAddListener(n, f) {
var btn = document.getElementsByClassName(n);
for (var i = 0; i < btn.length; i++) {
btn[i].addEventListener('click', f);
}
}
var bodyController = new function() {
var styleBody = null;
this.isVertScrollBarVisible = function() {
return document.body.scrollHeight > document.body.clientHeight;
}
this.vertScrollBarWidth = function() {
return this.isVertScrollBarVisible() ? '14px' : '0px';
}
this.getWideWidth = function() {
return '{{.LayBodyWideWidth}}px';
}
this.getMediumWidth = function() {
return '{{.LayBodyMediumWidth}}px';
}
this.enterModeWide = function() {
styleBody.width = this.getWideWidth();
}
this.enterModeMedium = function() {
this.enterModeNarrow();
}
this.enterModeNarrow = function() {
styleBody.width = '100%';
}
this.initialize = function() {
styleBody = document.body.style;
}
}
var headerController = new function() {
var styleHeader = null;
var styleHeadSpacer = null;
var styleLessonNavRow = null;
var styleTitle = null;
var setHeight = function(x) {
styleHeader.height = x;
styleHeadSpacer.height = x;
}
var hideIt = function() {
setHeight('{{.LayMinimizedHeaderHeight}}px');
styleLessonNavRow.display = 'none';
styleTitle.removeProperty('min-height');
styleTitle.fontSize = '1em';
}
var showIt = function() {