generated from mvc-works/calcit-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompact.cirru
828 lines (827 loc) · 37.9 KB
/
compact.cirru
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
{} (:package |app)
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!) (:version |0.0.1)
:modules $ [] |respo.calcit/ |lilac/ |memof/ |respo-ui.calcit/ |respo-markdown.calcit/ |reel.calcit/ |alerts.calcit/ |respo-feather.calcit/
:entries $ {}
:files $ {}
|app.comp.container $ %{} :FileEntry
:defs $ {}
|azure-key $ %{} :CodeEntry (:doc |)
:code $ quote
def azure-key $ or (get-env "\"azure-key") (js/localStorage.getItem "\"azure-key")
|comp-comment-list $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-comment-list (router resource highlighted)
let
coord $ :data router
topic $ get-in resource
[] :topics $ first coord
list->
{} (:class-name css/row)
:style $ {} (:height "\"100%")
-> coord $ map-indexed
fn (idx parent-id)
[] parent-id $ let
kids $ :kids
if (= 0 idx)
get-in resource $ [] :topics parent-id
get-in resource $ [] :replies parent-id
div
{} $ :class-name (str-spaced css/column css-comment-list)
if (= 0 idx)
comp-topic-parent $ get-in resource ([] :topics parent-id)
comp-reply-parent
get-in resource $ [] :replies parent-id
fn (d!)
d! :router $ {}
:data $ .slice coord 0 idx
list->
{} (:class-name css/expand)
:style $ {} (:padding "\"40px 4px 160px 4px")
-> kids (.to-list)
map $ fn (reply-id)
[] reply-id $ let
reply $ get-in resource ([] :replies reply-id)
k $ str parent-id "\"+" reply-id
memof1-call-by k comp-reply reply
contains? (.to-set coord) reply-id
if
= (first highlighted) reply-id
last highlighted
, nil
, idx
|comp-container $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-container (reel resource)
let
store $ :store reel
states $ :states store
router $ :router store
div
{}
:class-name $ str-spaced css/fullscreen css/global css/row
:style $ {} (:overflow-x :auto)
comp-topic-list (>> states :topics) resource $ first (:data router)
let
topic $ get-in resource
[] :topics $ first (:data router)
comp-frame topic
comp-comment-list router resource $ :highlighted store
div $ {}
:style $ {} (:width "\"80vw")
div
{} $ :style
{} $ :padding "\"16px 16px"
div ({}) (<> "\"HN Reader on GitHub")
div ({})
a $ {}
:style $ {} (:font-size 12) (:text-decoration :none) (:line-height "\"12px") (:font-family ui/font-fancy)
:target "\"_blank"
:inner-text "\"https://github.com/Memkits/hn-reader"
:href "\"https://github.com/Memkits/hn-reader"
when dev? $ comp-inspect "\"store" store
{} $ :bottom 0
when dev? $ comp-reel (>> states :reel) reel ({})
|comp-frame $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-frame (topic)
if (some? topic)
[] (effect-load topic)
div
{} $ :class-name (str-spaced css/column style-iframe-container)
div
{} $ :class-name (str-spaced css/row-parted style-address)
a $ {}
:inner-text $ :url topic
:href $ :url topic
:target "\"_blank"
span $ {} (:inner-text "\"Full") (:class-name css/link)
:style $ {} (:height "\"16px")
:on-click $ fn (e d!) (js/document.body.requestFullscreen)
create-element :iframe $ {} (:class-name css/expand)
:style $ {} (:border :none)
:id "\"frame"
:innerHTML "\"Not loaded."
span nil
|comp-reply $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-reply (reply selected? highlighted-idx idx)
[]
effect-height! $ some? reply
if
or $ nil? reply
div
{} $ :class-name style-reply-empty
<> (str "\"Data from network")
{} $ :font-family ui/font-fancy
let
has-kids $ >
count $ :kids reply
, 0
div
{} $ :class-name
str-spaced "\"reply" css-reply $ if selected? css-topic-selected
div
{} $ :class-name css/row-parted
div
{} $ :class-name (str-spaced css/row-middle css-topic-labels)
<>
str $ :by reply
, css-replay-content
=< 8 nil
comp-time $ :time reply
div
{} $ :class-name css/row-middle
a $ {} (:inner-text "\"$0") (:target "\"_blank")
:href $ str "\"https://news.ycombinator.com/item?id=" (:id reply) "\"&noRedirect=true"
:class-name css-external-link
let
content $ :text reply
paragraphs $ to-calcit-data
.!split (either content "\"") pattern-lines
list-> ({})
map-indexed paragraphs $ fn (idx block)
[] idx $ div
{}
:style $ {} (:position :relative)
:class-name style-reply-paragraph
if (some? config/audio-target)
div
{} $ :class-name (str-spaced "\"clickable-container" css-p-content)
comp-icon :volume-1
{} (:font-size 18) (:cursor :pointer) (:line-height 1)
:color $ hsl 200 80 70
fn (e d!)
case-default audio-target
read-text! $ do (html->readable block)
d! :highlight $ [] (:id reply) idx
"\"azure" $ speech-via-api! (html->readable block)
fn () $ d! :highlight
[] (:id reply) idx
fn $
div $ {}
:innerHTML $ wo-log (.!render markdown-reader block)
:style $ merge
{} (:line-height "\"20px") (:font-size 14)
if (= idx highlighted-idx)
{} $ :background-color (hsl 80 80 90)
:on-click $ fn (e d!)
if
= "\"A" $ -> e :event .-target .-tagName
do (-> e :event .!preventDefault) (-> e :event .-target .-href js/window.open)
div
{} $ :class-name css/row-parted
span nil
let
size $ count (:kids reply)
if (> size 0)
div
{} (:class-name css-open-replies)
:on-click $ fn (e d!)
d! $ :: :router-after idx (:id reply)
d! :load-reply $ :id reply
<> (str "\"Comments: ") css-has-comment
<> size
<> (str "\"No comments.") css-no-comment
|comp-reply-parent $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-reply-parent (reply on-close)
if (nil? reply)
div ({})
<> (str "\"data required")
{}
:color $ hsl 0 0 80
:padding 8
div
{} $ :class-name css-reply-parent
div
{} (:class-name css/row-middle)
:style $ {} (:width "\"100%")
comp-icon :x
{} (:font-size 14)
:color $ hsl 200 80 80
:cursor :pointer
:line-height 1
fn (e d!) (on-close d!)
=< 6 nil
div $ {}
:innerHTML $ :text reply
:class-name $ str-spaced css/expand css-reply-parent-content
div
{} (:class-name css/row-parted)
:style $ {} (:line-height "\"20px")
div
{} $ :style
{} $ :color (hsl 0 0 60)
<> $ str "\"@" (:by reply)
=< 8 nil
comp-time $ :time reply
=< 8 nil
<> $ str "\"Comments: "
count $ :kids reply
|comp-time $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-time (time)
if (some? time)
let
time-obj $ dayjs (* 1000 time)
year $ .!getFullYear (new js/Date)
if
= (str year) (.!format time-obj "\"YYYY")
<> $ .!format time-obj "\"MM-DD HH:mm"
<> $ .!format time-obj "\"YYYY-MM-DD HH:mm"
<> "\"nil"
|comp-topic $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-topic (topic style on-click)
if (nil? topic)
div ({})
<> "\"Data from network" $ {}
:color $ hsl 0 0 80
:padding 8
:font-family ui/font-fancy
div
{}
:class-name $ str-spaced "\"hoverable" css-topic
:style style
:on-click on-click
div
{} $ :class-name css-topic-title
<> (:score topic) css-topic-score
=< 8 nil
<> $ :title topic
div
{} $ :class-name css-topic-desc
a $ {}
:inner-text $ str "\"@" (:by topic)
=< 12 nil
<> $ str "\"Comments: "
count $ :kids topic
=< 12 nil
let
url $ :url topic
a $ {}
:inner-text $ if (some? url)
.-host $ new js/URL url
, "\"nothing"
:href url
:target "\"_blank"
:style $ {} (:text-overflow :ellipsis) (:overflow :hidden)
|comp-topic-list $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-topic-list (states resource focus-id)
let
cursor $ :cursor states
state $ or (:data states) ({})
no-list? $ empty? (:top10 resource)
load-plugin $ use-prompt (>> states :load)
{} (:text "\"Topic id:") (:placeholder "\"use number id from hacker news url")
div
{} (:class-name css/column)
:style $ {}
:width $ if no-list? 40 400
:height "\"100%"
:white-space :nowrap
:overflow :auto
div
{} (:class-name css/row-middle)
:style $ {} (:padding "\"8px 4px")
:border-bottom $ str "\"1px solid " (hsl 0 0 90)
:justify-content :flex-end
a $ {} (:inner-text "\"List") (:class-name css/link)
:on-click $ fn (e d!) (d! :load-top10 nil)
if no-list? $ <> (str "\"none.")
{}
:color $ hsl 0 0 80
:padding 8
:font-family ui/font-fancy
list->
{} (:class-name css/expand)
:style $ {} (:padding "\"0px 0 100px 0") (:overflow-x :hidden) (:text-overflow :ellipsis)
-> (:top10 resource)
map $ fn (topic)
[] (:id topic)
comp-topic topic
if
= (:id topic) focus-id
{} $ :background-color :white
{}
fn (e d!)
d! :load-topic $ :id topic
d! :router $ {}
:data $ [] (:id topic)
div
{} $ :class-name css/row-parted
span nil
a $ {} (:inner-text "\"Load")
:class-name $ str-spaced css/link css/font-fancy! style-load
:on-click $ fn (e d!)
.show load-plugin d! $ fn (text) (d! :load-topic text)
d! :router $ {}
:data $ [] text
.render load-plugin
|comp-topic-parent $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-topic-parent (topic)
if (nil? topic)
div ({})
<> "\"loading..." $ {}
:color $ hsl 0 0 80
:padding 8
div
{} $ :class-name (str-spaced "\"hoverable" css-topic-parent)
div
{} $ :class-name css/row-parted
div
{} $ :class-name (str-spaced css/expand css/row-parted)
<> (:score topic) css-topic-parent-title
=< 8 nil
<> (:title topic)
merge ui/expand $ {} (:font-size 16) (:text-overflow :ellipsis) (:overflow :hidden) (:white-space :nowrap)
=< 8 nil
a $ {}
:href $ str "\"https://news.ycombinator.com/item?id=" (:id topic) "\"&noRedirect=true"
:inner-text "\"$0"
:target "\"_blank"
div
{} $ :style
{}
:color $ hsl 0 0 50
:font-family ui/font-fancy
:line-height "\"20px"
a $ {}
:inner-text $ str "\"@" (:by topic)
=< 12 nil
<> $ str "\"Comments: "
count $ :kids topic
=< 12 nil
let
url $ :url topic
a $ {}
:inner-text $ if (some? url)
.-host $ new js/URL url
, "\"nothing"
:href url
:target "\"_blank"
:style $ {} (:text-overflow :ellipsis) (:overflow :hidden)
|css-comment-list $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-comment-list $ {}
"\"$0" $ {} (:width 500) (:max-width "\"100vw") (:height "\"100%") (:overflow-y :auto) (:margin-right 8)
|css-external-link $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-external-link $ {}
"\"$0" $ {} (:font-family ui/font-fancy) (:font-size 12)
|css-has-comment $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-has-comment $ {}
"\"$0" $ {} (:font-family ui/font-fancy) (:font-size 12)
|css-no-comment $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-no-comment $ {}
"\"$0" $ {} (:font-family ui/font-fancy) (:font-size 12)
:color $ hsl 0 0 80
|css-open-replies $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-open-replies $ {}
"\"$0" $ {} (:display :inline-block)
:background-color $ hsl 180 40 68
:color :white
:padding "\"0 12px"
:border-radius "\"16px"
:cursor :pointer
:user-select :none
:transition-duration "\"300ms"
"\"$0:hover" $ {}
:box-shadow $ str "\"1px 1px 4px " (hsl 0 0 0 0.1)
:background-color $ hsl 200 60 74
"\"$0:active" $ {} (:transform "\"scale(1.04)")
|css-p-content $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-p-content $ {}
"\"$0" $ {} (:line-height 1) (:position :absolute) (:bottom 6) (:right -6)
|css-replay-content $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-replay-content $ {}
"\"$0" $ {} (:color :black) (:font-size 14) (:font-weight :bold) (:font-family ui/font-normal)
|css-reply $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-reply $ {}
"\"$0" $ merge style-reply-box
{} (:padding "\"8px 16px") (:border-style :solid) (:border-width "\"1px 1px 2px 1px") (:margin-bottom 16) (:border-radius "\"8px")
:border-color $ hsl 0 0 88
:background-color $ hsl 0 0 99
:opacity 1
"\"&::-webkit-scrollbar" $ {} (:width "\"0px") (:height "\"0px")
"\"$0:hover" $ {}
:background-color $ hsl 0 0 100
:box-shadow $ str "\"0px 2px 2px " (hsl 0 0 0 0.1)
|css-reply-parent $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-reply-parent $ {}
"\"$0" $ {} (:padding "\"8px 16px")
:border-bottom $ str "\"1px solid " (hsl 0 0 80)
:max-height 200
:overflow :hidden
:text-overflow :ellipsis
:background-color $ hsl 0 0 100
|css-reply-parent-content $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-reply-parent-content $ {}
"\"$0" $ {} (:line-height "\"22px") (:white-space :nowrap) (:max-height 22) (:overflow :hidden) (:text-overflow :ellipsis) (:font-size 16)
|css-topic $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-topic $ {}
"\"$0" $ {} (:padding "\"12px 16px") (:cursor :pointer)
:border-bottom $ str "\"1px solid " (hsl 0 0 93)
|css-topic-desc $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-topic-desc $ {}
"\"$0" $ {}
:color $ hsl 0 0 50
:font-family ui/font-fancy
:font-size 12
:line-height "\"16px"
|css-topic-labels $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-topic-labels $ {}
"\"$0" $ {} (:font-size 13) (:font-family ui/font-fancy)
:color $ hsl 0 0 60
|css-topic-parent $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-topic-parent $ {}
"\"$0" $ {} (:padding "\"8px 16px") (:cursor :pointer)
:border-bottom $ str "\"1px solid " (hsl 0 0 80)
:cursor :default
:background-color $ hsl 0 0 100
|css-topic-parent-title $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-topic-parent-title $ {}
"\"$0" $ {} (:display :inline-block) (:padding "\"0 6px")
:background-color $ hsl 60 80 42
:color :white
:font-size 14
:line-height "\"20px"
:border-radius "\"16px"
:font-family ui/font-fancy
|css-topic-score $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-topic-score $ {}
"\"$0" $ {} (:display :inline-block) (:padding "\"0 6px")
:background-color $ hsl 60 80 42
:color :white
:font-size 14
:line-height "\"20px"
:border-radius "\"16px"
:font-family ui/font-fancy
|css-topic-selected $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-topic-selected $ {}
"\"$0" $ {}
:border-color $ hsl 0 0 74
:background-color $ hsl 0 0 100
:box-shadow $ str "\"0px 3px 2px " (hsl 0 0 0 0.1)
|css-topic-title $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-topic-title $ {}
"\"$0" $ {} (:font-size 14) (:text-overflow :ellipsis) (:overflow :hidden)
|effect-height! $ %{} :CodeEntry (:doc |)
:code $ quote
defeffect effect-height! (open?) (action el at?)
if
or (= action :mount) (= action :update)
-> el .-style .-maxHeight $ set!
str
+ 16 $ .-scrollHeight el
, "\"px"
|effect-load $ %{} :CodeEntry (:doc |)
:code $ quote
defeffect effect-load (topic) (action el *local at-place?)
let
target $ .!querySelector el "\"#frame"
when
or (= action :mount) (= action :update)
if
some? $ :url topic
do
.!setAttribute target "\"src" $ str "\"data:," (js/encodeURIComponent "\"setting iframe...")
when
some? $ :url topic
timeout-call 30 $ fn ()
.!setAttribute target "\"src" $ :url topic
.!setAttribute target "\"src" $ str "\"data:," (js/encodeURIComponent "\"no url to display.")
|html->readable $ %{} :CodeEntry (:doc |)
:code $ quote
defn html->readable (html)
let
el $ js/document.createElement "\"pre"
set! (.-innerHTML el)
-> html
.!replace (new js/RegExp "\"<p>" "\"g") (str "\" " "\"<p>" "\"<br/><br/>" "\" ")
.!replace (new js/RegExp "\"<li>" "\"g") (str "\" " "\"<li>" "\" ")
-> (.-innerText el) (either "\"")
.!replace (new js/RegExp "\"https?://\\S+" "\"g") "\"."
|markdown-reader $ %{} :CodeEntry (:doc |)
:code $ quote
def markdown-reader $ new Remarkable
js-object $ :html true
|pattern-lines $ %{} :CodeEntry (:doc |)
:code $ quote
def pattern-lines $ new js/RegExp "\"<p>"
|read-text! $ %{} :CodeEntry (:doc |)
:code $ quote
defn read-text! (text)
let
voices $ js/speechSynthesis.getVoices
samantha-voice $ .!find voices
fn (v idx d)
= (.-voiceURI v) "\"Samantha"
sentence $ .!replace text url-pattern
fn (x & args)
let
url $ new js/URL x
if (some? url)
str "\" link to "
.!replace (.-host url) "\"www." "\""
, "\" "
, "\"link "
instance $ new js/SpeechSynthesisUtterance sentence
println $ str sentence
set! (.-rate instance) 1
set! (.-voice instance) samantha-voice
.!cancel js/speechSynthesis
.!speak js/speechSynthesis instance
|speech-via-api! $ %{} :CodeEntry (:doc |)
:code $ quote
defn speech-via-api! (text on-play on-next) (synthesizeAzureSpeech text azure-key on-play on-next)
|style-address $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-address $ {}
"\"&" $ {} (:padding "\"0 8px") (:overflow :hidden) (:width "\"100%")
:background-color $ hsl 0 0 95
:white-space :nowrap
:border-bottom $ str "\"1px solid " (hsl 0 0 86)
|style-iframe-container $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-iframe-container $ {}
"\"&" $ {} (:width "\"max(640px, 48vw)")
:background-color $ hsl 0 0 100
:margin-right 8
:max-width "\"100vw"
|style-load $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-load $ {}
"\"&" $ {} (:opacity 0.5) (:font-size 12)
|style-reply-box $ %{} :CodeEntry (:doc |)
:code $ quote
def style-reply-box $ {} (:padding "\"8px 16px") (:border-width "\"1px 1px 2px 1px") (:transition-duration "\"120ms") (:transition-property "\"max-height,height,background-color,margin-bottom,opacity") (; :transition-timing-function "\"cubic-bezier(0.155, 0.495, 0.555, 1.230)") (:transition-timing-function :linear) (:overflow :auto) (:max-height 40)
|style-reply-empty $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-reply-empty $ {}
"\"&" $ merge style-reply-box
{} (:padding "\"8px 16px") (:border-width "\"1px 1px 2px 1px")
:background-color $ hsl 0 0 99 0
:margin-bottom 0
:opacity 0.2
"\"&::-webkit-scrollbar" $ {} (:width "\"0px") (:height "\"0px")
|style-reply-paragraph $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-reply-paragraph $ {}
"\"&" $ {}
:color $ hsl 0 0 50
:position :relative
:transition-delay "\"100ms"
"\"&::before" $ {} (:content "\"''") (:width 3) (:position :absolute) (:height "\"100%")
:background-color $ hsl 0 0 70
:left -17
:opacity 0
:transition-duration "\"200ms"
:transition-delay "\"0ms"
"\"&:hover" $ {}
:color $ hsl 0 0 30
:transition-delay "\"0ms"
"\"&:hover::before" $ {} (:opacity 1) (:transition-delay "\"40ms")
|url-pattern $ %{} :CodeEntry (:doc |)
:code $ quote
def url-pattern $ new js/RegExp "\"https?:\\S+"
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.container $ :require
respo-ui.core :refer $ hsl
respo-ui.core :as ui
respo.core :refer $ defcomp defeffect create-element >> <> div list-> button textarea span input section a
respo.comp.space :refer $ =<
reel.comp.reel :refer $ comp-reel
respo-md.comp.md :refer $ comp-md
app.config :refer $ dev? audio-target audio-host
respo.comp.inspect :refer $ comp-inspect
"\"dayjs" :default dayjs
respo-alerts.core :refer $ use-prompt
feather.core :refer $ comp-icon
"\"../entry/play-audio" :refer $ synthesizeAzureSpeech
"\"remarkable" :refer $ Remarkable
memof.once :refer $ memof1-call-by
respo.css :refer $ defstyle
respo-ui.css :as css
app.config :as config
|app.config $ %{} :FileEntry
:defs $ {}
|audio-host $ %{} :CodeEntry (:doc |)
:code $ quote
def audio-host $ get-env "\"audio-host"
|audio-target $ %{} :CodeEntry (:doc |)
:code $ quote
def audio-target $ or (get-env "\"audio-target") (js/localStorage.getItem "\"audio-target")
|dev? $ %{} :CodeEntry (:doc |)
:code $ quote
def dev? $ = "\"dev" (get-env "\"mode" "\"release")
|site $ %{} :CodeEntry (:doc |)
:code $ quote
def site $ {} (:dev-ui "\"http://localhost:8100/main-fonts.css") (:release-ui "\"http://cdn.tiye.me/favored-fonts/main-fonts.css") (:cdn-url "\"http://cdn.tiye.me/hn-reader/") (:title "\"HN Reader") (:icon "\"http://cdn.tiye.me/logo/memkits.png") (:storage-key "\"hn-reader")
:ns $ %{} :CodeEntry (:doc |)
:code $ quote (ns app.config)
|app.data-gather $ %{} :FileEntry
:defs $ {}
|*resource $ %{} :CodeEntry (:doc |)
:code $ quote
defatom *resource $ {}
:top10 $ []
:topics $ {}
:replies $ {}
|data-get! $ %{} :CodeEntry (:doc |)
:code $ quote
defn data-get! (url) (hint-fn async)
let
data $ js-await (get-url! url)
; js/console.log "\"GET" data
tagging-edn $ to-calcit-data data
|get-url! $ %{} :CodeEntry (:doc |)
:code $ quote
defn get-url! (url)
-> (js/fetch url)
.!then $ fn (response)
if
not= 200 $ .-status response
raise $ str "\"Code" (.-status response)
.!json response
.!catch $ fn (error) (js/console.log "\"Failed top10" error)
|load-reply! $ %{} :CodeEntry (:doc |)
:code $ quote
defn load-reply! (reply-id) (hint-fn async)
let
reply $ js-await
data-get! $ str "\"https://hacker-news.firebaseio.com/v0/item/" reply-id "\".json?print=pretty"
reply-ids $ :kids reply
js-await $ promise-all reply-ids
fn (reply-id) (hint-fn async)
let
reply $ js-await
data-get! $ str "\"https://hacker-news.firebaseio.com/v0/item/" reply-id "\".json?print=pretty"
swap! *resource assoc-in ([] :replies reply-id) reply
|load-top10! $ %{} :CodeEntry (:doc |)
:code $ quote
defn load-top10! () (hint-fn async)
swap! *resource assoc :top10 $ []
let
data $ js-await (data-get! "\"https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty")
top-ids $ take data 30
js-await $ promise-all top-ids
fn (topic-id) (hint-fn async)
let
topic $ js-await
data-get! $ str "\"https://hacker-news.firebaseio.com/v0/item/" (wo-js-log topic-id) "\".json?print=pretty"
swap! *resource update :top10 $ fn (topics) (conj topics topic)
swap! *resource assoc-in ([] :topics topic-id) topic
|load-topic! $ %{} :CodeEntry (:doc |)
:code $ quote
defn load-topic! (topic-id) (hint-fn async)
let
topic $ js-await
data-get! $ str "\"https://hacker-news.firebaseio.com/v0/item/" topic-id "\".json?print=pretty"
reply-ids $ :kids topic
swap! *resource assoc-in ([] :topics topic-id) topic
js-await $ promise-all reply-ids
fn (reply-id) (hint-fn async)
let
reply $ js-await
data-get! $ str "\"https://hacker-news.firebaseio.com/v0/item/" reply-id "\".json?print=pretty"
swap! *resource assoc-in ([] :replies reply-id) reply
|on-operation $ %{} :CodeEntry (:doc |)
:code $ quote
defn on-operation (op)
tag-match op
:load-top10
load-top10!
(:load-topic d) (load-topic! d)
(:load-reply d) (load-reply! d)
_ $ do (eprintln "\"Unknown op" op)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.data-gather $ :require
"\"@calcit/std" :refer $ promise-for promise-all
|app.main $ %{} :FileEntry
:defs $ {}
|*reel $ %{} :CodeEntry (:doc |)
:code $ quote
defatom *reel $ -> reel-schema/reel (assoc :base schema/store) (assoc :store schema/store)
|dispatch! $ %{} :CodeEntry (:doc |)
:code $ quote
defn dispatch! (op)
when config/dev? $ println "\"Dispatch:" op
if
contains? (#{} :load-top10 :load-topic :load-reply) (nth op 0)
on-operation op
reset! *reel $ reel-updater updater @*reel op
|main! $ %{} :CodeEntry (:doc |)
:code $ quote
defn main! ()
if config/dev? $ load-console-formatter!
println "\"Running mode:" $ if config/dev? "\"dev" "\"release"
render-app!
add-watch *reel :changes $ fn (r p) (render-app!)
add-watch *resource :changes $ fn (r p) (render-app!)
listen-devtools! |k dispatch!
; js/window.addEventListener |beforeunload persist-storage!
; let
raw $ js/localStorage.getItem (:storage-key config/site)
when (some? raw)
dispatch! :hydrate-storage $ parse-cirru-edn raw
if-let
id $ get-env "\"id"
do
dispatch! $ :: :load-topic id
dispatch! $ :: :router
{} $ :data ([] id)
dispatch! $ :: :load-top10
println "|App started."
|mount-target $ %{} :CodeEntry (:doc |)
:code $ quote
def mount-target $ js/document.querySelector |.app
|persist-storage! $ %{} :CodeEntry (:doc |)
:code $ quote
defn persist-storage! (e)
js/localStorage.setItem (:storage-key config/site)
format-cirru-edn $ :store @*reel
|reload! $ %{} :CodeEntry (:doc |)
:code $ quote
defn reload! () $ if (nil? build-errors)
do (remove-watch *reel :changes) (clear-cache!)
add-watch *reel :changes $ fn (reel prev) (render-app!)
reset! *reel $ refresh-reel @*reel schema/store updater
hud! "\"ok~" "\"Ok"
hud! "\"error" build-errors
|render-app! $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-app! () $ render! mount-target (comp-container @*reel @*resource) dispatch!
|snippets $ %{} :CodeEntry (:doc |)
:code $ quote
defn snippets () $ println config/cdn?
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.main $ :require
respo.core :refer $ render! clear-cache! realize-ssr!
app.comp.container :refer $ comp-container
app.updater :refer $ updater
app.schema :as schema
reel.util :refer $ listen-devtools!
reel.core :refer $ reel-updater refresh-reel
reel.schema :as reel-schema
cljs.reader :refer $ read-string
app.config :as config
app.data-gather :refer $ *resource on-operation
clojure.string :as string
"\"./calcit.build-errors" :default build-errors
"\"bottom-tip" :default hud!
|app.schema $ %{} :FileEntry
:defs $ {}
|store $ %{} :CodeEntry (:doc |)
:code $ quote
def store $ {}
:states $ {}
:router $ {} (:name :home)
:data $ []
:highlighted nil
:ns $ %{} :CodeEntry (:doc |)
:code $ quote (ns app.schema)
|app.updater $ %{} :FileEntry
:defs $ {}
|updater $ %{} :CodeEntry (:doc |)
:code $ quote
defn updater (store op op-id op-time)
tag-match op
:states cursor s
update-states store cursor s
(:content c) (assoc store :content c)
(:router d) (assoc store :router d)
(:router-after idx reply-id)
update store :router $ fn (router)
{} $ :data
conj
.slice (:data router) 0 $ inc idx
, reply-id
(:hydrate-storage d) d
(:highlight d) (assoc store :highlighted d)
_ $ do (eprintln "\"unknown op:" op) store
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.updater $ :require
[] respo.cursor :refer $ [] update-states