-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompact.cirru
3112 lines (3111 loc) · 138 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
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 |phlox)
:configs $ {} (:init-fn |phlox.app.main/main!) (:reload-fn |phlox.app.main/reload!) (:version |0.7.1)
:modules $ [] |memof/ |lilac/ |pointed-prompt/ |touch-control/
:entries $ {}
:files $ {}
|phlox.app.comp.drafts $ %{} :FileEntry
:defs $ {}
|comp-drafts $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-drafts (x)
container
{}
:position $ [] 100 100
:rotation 0
circle $ {}
:position $ [] 200 100
:radius 40
:line-style $ {} (:width 4)
:color $ hslx 0 80 50
:alpha 1
:fill $ hslx 160 80 70
:on $ {}
:pointertap $ fn (event dispatch!) (dispatch! :add-x nil)
rect
{}
:position $ [] 40 40
:size $ [] 50 50
:line-style $ {} (:width 4)
:color $ hslx 0 80 50
:alpha 1
:fill $ hslx 200 80 80
:on $ {}
:pointertap $ fn (e dispatch!) (dispatch! :add-x nil)
:rotation $ + 1 (* 0.1 x)
:pivot $ [] 0 0
text $ {}
:text $ str "\"Text demo:"
+ 1 $ * 0.1 x
, &newline "\"pivot"
to-lispy-string $ {} (:x 100) (:y 100)
:style $ {} (:font-family "\"Menlo") (:font-size 12)
:fill $ hslx 200 80 90
:align :center
text $ {}
:text $ str "\"Text demo:" x
:style $ {} (:font-family "\"Menlo") (:font-size 12)
:fill $ hslx 200 80
+ 80 $ * 20 (js/Math.random)
:align :center
:alpha 1
create-list :container ({})
-> (range 20)
map $ fn (idx)
[] idx $ text
{}
:text $ str idx
:style $ {} (:font-family "\"Helvetica Neue") (:font-weight 300) (:font-size 14)
:fill $ hslx 200 10
+ 40 $ * 4 idx
:position $ []
+ 200 $ * idx 20
+ 140 $ * idx 10
:rotation $ * 0.1 (+ idx x)
graphics $ {}
:ops $ []
g :line-style $ {} (:width 4)
:color $ hslx 200 80 80
:alpha 1
g :begin-fill $ {}
:color $ hslx 0 80 20
g :move-to $ []
+ (* 20 x) 100
, 200
g :line-to $ []
+ (* 20 x) 400
, 400
g :line-to $ []
- 500 $ * 20 x
, 300
g :close-path
:rotation 0.1
:pivot $ [] 0 100
:alpha 0.5
:on $ {}
:pointertap $ fn (e dispatch!) (println "\"clicked")
rect $ {}
:position $ [] 400 40
:size $ [] 20 20
:fill $ hclx 240 100 60
image $ {} (:url "\"https://cdn.tiye.me/logo/quamolit.png")
:size $ [] 100 100
:position $ [] 400 -100
:on $ {}
:pointertap $ fn (e d!) (println "\"click on image")
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns phlox.app.comp.drafts $ :require
[] phlox.core :refer $ [] g hslx hclx rect circle text container graphics create-list image
|phlox.app.comp.keyboard $ %{} :FileEntry
:defs $ {}
|comp-keyboard $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-keyboard (on? counted)
container
{} $ :position ([] 120 200)
container
{} $ :position ([] 0 0)
rect $ {}
:position $ [] 0 0
:size $ [] 160 40
:fill $ hslx 0 0 50
:on $ {}
:pointertap $ fn (e d!) (d! :toggle-keyboard nil)
text $ {}
:text $ str "\"Toggle: " on?
:position $ [] 4 8
:style $ {} (:font-size 16)
:fill $ hslx 0 0 100
text $ {}
:text $ str "\"Counted: " counted
:position $ [] 20 60
:style $ {} (:font-size 16)
:fill $ hslx 0 0 100
:on-keyboard $ if on?
{}
:down $ fn (e d!) (d! :counted nil)
:up $ fn (e d!) (println :up)
{}
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns phlox.app.comp.keyboard $ :require
[] phlox.core :refer $ [] g hslx rect circle text container graphics create-list
|phlox.app.comp.slider-demo $ %{} :FileEntry
:defs $ {}
|comp-slider-demo $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-slider-demo (states)
let
cursor $ :cursor states
state $ either (:data states)
{} (:a 40) (:b 20) (:c 10) (:d 10) (:e 10) (:f 10)
container
{} $ :position ([] 100 100)
comp-slider (>> states :a)
{}
:value $ :a state
:unit 1
:position $ [] 20 0
:on-change $ fn (value d!)
d! cursor $ assoc state :a value
comp-slider (>> states :b)
{}
:value $ :b state
:title "\"Refine"
:unit 0.1
:position $ [] 20 60
:on-change $ fn (value d!)
d! cursor $ assoc state :b value
comp-slider (>> states :c)
{}
:value $ :c state
:unit 10
:position $ [] 20 120
:fill $ hslx 50 90 70
:color $ hslx 200 90 30
:on-change $ fn (value d!)
d! cursor $ assoc state :c value
comp-slider (>> states :d)
{}
:value $ :d state
:position $ [] 20 180
:on-change $ fn (value d!)
d! cursor $ assoc state :d value
:title "\"Round"
:round? true
comp-slider (>> states :e)
{}
:value $ :e state
:position $ [] 20 240
:on-change $ fn (value d!)
d! cursor $ assoc state :e value
:title "\"min 10"
:min 10
comp-slider (>> states :f)
{}
:value $ :f state
:position $ [] 20 300
:on-change $ fn (value d!)
d! cursor $ assoc state :f value
:title "\"max 10"
:max 10
|comp-slider-point-demo $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-slider-point-demo (states)
let
cursor $ :cursor states
state $ either (:data states)
{} (:a 40) (:b 20) (:c 10) (:d 10) (:e 10) (:f 10)
container
{} $ :position ([] 120 100)
comp-slider-point (>> states :a)
{}
:value $ :a state
:unit 1
:position $ [] 20 0
:on-change $ fn (value d!)
d! cursor $ assoc state :a value
comp-slider-point (>> states :b)
{}
:value $ :b state
:unit 0.1
:position $ [] 20 60
:on-change $ fn (value d!)
d! cursor $ assoc state :b value
comp-slider-point (>> states :c)
{}
:value $ :c state
:unit 10
:position $ [] 20 120
:fill $ hslx 50 90 70
:color $ hslx 200 90 30
:on-change $ fn (value d!)
d! cursor $ assoc state :c value
comp-slider-point (>> states :d)
{}
:value $ :d state
:position $ [] 20 180
:on-change $ fn (value d!)
d! cursor $ assoc state :d value
:round? true
comp-slider-point (>> states :e)
{}
:value $ :e state
:position $ [] 20 240
:on-change $ fn (value d!)
d! cursor $ assoc state :e value
:min 10
comp-slider-point (>> states :f)
{}
:value $ :f state
:position $ [] 20 300
:on-change $ fn (value d!)
d! cursor $ assoc state :f value
:max 10
|comp-spin-slider-demo $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-spin-slider-demo (states)
let
cursor $ :cursor states
state $ either (:data states)
{} (:v1 10)
:pos $ [] 240 240
container ({})
comp-spin-slider (>> states :demo)
{}
:position $ :pos state
:value $ :v1 state
:unit 1
:min 1
; :fill $ hslx 50 90 44
:fraction 1
:on-change $ fn (v d!)
d! cursor $ assoc state :v1 v
:on-move $ fn (pos d!)
d! cursor $ assoc state :pos pos
:label "\"dgemo"
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns phlox.app.comp.slider-demo $ :require
[] phlox.core :refer $ [] g hslx rect circle text container graphics create-list >>
[] phlox.comp.slider :refer $ [] comp-slider comp-slider-point comp-spin-slider
|phlox.app.container $ %{} :FileEntry
:defs $ {}
|comp-arrows-demo $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-arrows-demo (states)
let
cursor $ :cursor states
state $ either (:data states)
{}
:from $ [] 100 100
:to $ [] 200 200
comp-arrow (>> states :demo1)
{}
:from $ :from state
:to $ :to state
:width 2
:arm-length 8
:on-change $ fn (from to d!)
d! cursor $ assoc state :from from :to to
|comp-buttons $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-buttons () $ container
{} $ :position ([] 100 100)
comp-button $ {} (:text "\"DEMO BUTTON")
:position $ [] 100 0
:on $ {}
:pointertap $ fn (e d!) (js/console.log "\"clicked" e d!)
comp-button $ {} (:text "\"Blue")
:position $ [] 100 60
:color $ hslx 0 80 70
:fill $ hslx 200 80 40
comp-button $ {} (:text "\"Short hand pointertap")
:position $ [] 100 120
:on-pointertap $ fn (e d!) (println "\"clicked")
|comp-container $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-container (store)
; println "\"Store" store $ :tab store
let
cursor $ []
states $ :states store
group
{} $ :position ([] 0 0)
comp-tabs tabs (:tab store)
{} $ :position ([] 10 10)
fn (t d!) (d! :tab t)
case-default (:tab store)
text $ {} (:text "\"Unknown")
:style $ {}
:fill $ hslx 0 100 80
:font-size 12
:font-family "\"Helvetica"
:drafts $ comp-drafts (:x store)
:grids $ memof1-call comp-grids
:curves $ comp-curves
:gradients $ comp-gradients
:keyboard $ comp-keyboard (:keyboard-on? store) (:counted store)
:buttons $ comp-buttons
:slider $ comp-slider-demo (>> states :slider)
:points $ comp-points-demo (>> states :points)
:switch $ comp-switch-demo (>> states :switch)
:input $ comp-text-input (>> states :input)
:messages $ comp-messages-demo (>> states :messages)
:slider-point $ comp-slider-point-demo (>> states :slider-point)
:spin-slider $ comp-spin-slider-demo (>> states :spin-slider)
:arrows $ comp-arrows-demo (>> states :arrows)
:shadow $ comp-shadow-demo
:mesh $ comp-mesh-demo (>> states :mesh)
circle $ {}
:position $ [] 0 0
:radius 10
:fill 0xffffff
|comp-curves $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-curves () $ container ({})
graphics $ {}
:ops $ []
g :line-style $ {} (:width 2)
:color $ hslx 200 80 80
:alpha 1
g :move-to $ [] 0 0
g :line-to $ [] 100 200
g :arc-to $ {}
:p1 $ [] 200 200
:p2 $ [] 240 180
:radius 90
g :line-style $ {} (:width 2)
:color $ hslx 0 80 80
:join :round
:cap :round
g :arc $ {}
:center $ [] 260 120
:radius 40
:angle $ [] 90 270
:anticlockwise? false
g :line-style $ {} (:width 2)
:color $ hslx 20 80 40
:alpha 1
g :arc $ {}
:center $ [] 260 120
:radius 40
:angle $ [] 270 30
:anticlockwise? false
g :line-style $ {} (:width 2)
:color $ hslx 200 80 80
:alpha 1
g :quadratic-to $ {}
:p1 $ [] 400 100
:to-p $ [] 500 400
g :bezier-to $ {}
:p1 $ [] 400 500
:p2 $ [] 300 200
:to-p $ [] 600 300
g :begin-fill $ {}
:color $ hslx 200 80 80
:alpha 1
g :arc $ {}
:center $ [] 600 300
:radius 20
:angle $ [] 0 300
:anticlockwise? false
g :end-fill nil
; g :line-to $ [] 400 400
polyline $ {}
:style $ {} (:width 4)
:color $ hslx 40 100 60
:alpha 1
:position $ [] 300 300
:points $ -> (range 200)
map $ fn (idx)
let
r $ * 0.4 idx
angle $ * 0.1 idx
polar-point angle r
line-segments $ {}
:style $ {} (:width 2)
:color $ hslx 40 100 60
:alpha 1
:position $ [] 500 100
:segments $ -> (range 10)
map $ fn (idx)
[]
[] (+ 10 idx) 20
[]
+ (* 8 idx) 10
, 80
|comp-gradients $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-gradients () $ container ({})
text $ {} (:text "\"long long text")
:position $ [] 120 160
:style $ {}
:fill $ [] (hslx 0 0 100) (hslx 0 0 40)
:fill-gradient-type :v
text $ {} (:text "\"long long text")
:position $ [] 120 200
:style $ {}
:fill $ [] (hslx 0 0 100) (hslx 0 0 40)
:fill-gradient-type :h
text $ {} (:text "\"long long text")
:position $ [] 120 120
:style $ {}
:fill $ hslx 20 90 60
|comp-grids $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-grids () (echo "\"calculating grids")
container ({})
create-list :container
{} $ :position ([] 200 20)
-> (range 60)
mapcat $ fn (x)
-> (range 40)
map $ fn (y) ([] x y)
map $ fn (pair)
let[] (x y) pair $ [] (str x "\"+" y)
rect $ {}
:position $ [] (* x 14) (* y 14)
:size $ [] 10 10
:fill $ hslx 200 80 80
:on $ {}
:pointerover $ fn (e d!) (println "\"hover:" x y)
|comp-mesh-demo $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-mesh-demo (states)
let
cursor $ :cursor states
state $ or (:data states)
{} (:x 0)
:base $ [] 109 129
:offset $ [] -123 -3
:zoom 0.26
container ({})
comp-button $ {} (:text "\"Tick")
:position $ [] 200 -40
:on-pointertap $ fn (e d!)
d! cursor $ update state :x inc
container
{} $ :position ([] 600 400)
mesh $ {} (:scale 1)
:position $ [] 0 0
:geometry $ {}
:attributes $ []
{} (:id "\"aVertexPosition") (:size 2)
:buffer $ [] -400 -400 400 -400 400 400 -400 400
{} (:id "\"aUvs") (:size 2)
:buffer $ [] 0 0 1 0 1 1 0 1
:index $ [] 0 1 2 0 3 2
:shader $ {}
:vertex-source $ inline-file "\"demo.vert"
:fragment-source $ inline-file "\"demo.frag"
:draw-mode :triangles
:uniforms $ js-object (:uSampler2 sample-texture)
:time $ :x state
; :base $ :base state
:baseX $ first (:base state)
:baseY $ last (:base state)
:zoom $ :zoom state
:offsetX $ * 1
first $ :offset state
:offsetY $ * 1
last $ :offset state
; :on $ {}
:pointertap $ fn (e d!) (println "\"clicked")
comp-drag-point (>> states :base)
{} (:radius 6) (:hide-text? true)
:position $ wo-log (:base state)
:fill $ hslx 200 100 50
:on-change $ fn (position d!)
d! cursor $ assoc state :base position
comp-drag-point (>> states :offset)
{} (:radius 6)
:fill $ hslx 0 100 50
:hide-text? true
:position $ wo-log (:offset state)
:on-change $ fn (position d!)
d! cursor $ assoc state :offset position
comp-slider-point (>> states :zoom)
{}
:value $ :zoom state
:min 0.01
:position $ [] 300 -40
:on-change $ fn (value d!)
d! cursor $ assoc state :zoom value
|comp-messages-demo $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-messages-demo (states)
let
cursor $ :cursor states
state $ either (:data states)
{}
:messages $ []
:bottom? false
container ({})
comp-button $ {} (:text "\"Add message")
:position $ [] 120 200
:on-pointertap $ fn (e d!)
d! cursor $ update state :messages
fn (xs)
conj xs $ let
id $ nanoid
{} (:id id)
:text $ str "\"Messages of " id
comp-switch $ {}
:value $ :bottom? state
:title "\"At bottom"
:position $ [] 200 280
:on-change $ fn (e d!)
d! cursor $ update state :bottom? not
comp-messages $ {}
:messages $ :messages state
:bottom? $ :bottom? state
:on-pointertap $ fn (message d!)
d! cursor $ update state :messages
fn (xs)
-> xs $ filter-not
fn (x)
= (:id x) (:id message)
|comp-points-demo $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-points-demo (states)
let
cursor $ :cursor states
state $ either (:data states)
{}
:p1 $ [] 0 0
:p2 $ [] 0 40
:p3 $ [] 0 80
:p4 $ [] 0 120
:p5 $ [] 0 160
container
{} $ :position ([] 160 100)
comp-drag-point (>> states :p1)
{}
:position $ :p1 state
:on-change $ fn (position d!)
d! cursor $ assoc state :p1 position
comp-drag-point (>> states :p2)
{}
:position $ :p2 state
:unit 2
:on-change $ fn (position d!)
d! cursor $ assoc state :p2 position
comp-drag-point (>> states :p3)
{}
:position $ :p3 state
:unit 0.4
:radius 10
:fill $ hslx 0 90 60
:color $ hslx 0 0 50
:on-change $ fn (position d!)
d! cursor $ assoc state :p3 position
comp-drag-point (>> states :p4)
{}
:position $ :p4 state
:title "\"base"
:alpha 0.6
:on-change $ fn (position d!)
d! cursor $ assoc state :p4 position
comp-drag-point (>> states :p5)
{}
:position $ :p5 state
:hide-text? true
:on-change $ fn (position d!)
d! cursor $ assoc state :p5 position
|comp-shadow-demo $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-shadow-demo () $ container
{} $ :position (canvas-center!)
text $ {} (:text "\"Shadows")
:style $ {}
:fill $ hslx 200 100 50
:font-size 40
:font-family "\"Josefin Sans"
:filters $ []
[] DropShadowFilter $ {}
:color $ hslx 10 90 100
:distance 2
:rotation 30
:alpha 1
:quality 4
:blur 6
|comp-switch-demo $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-switch-demo (states)
let
cursor $ :cursor states
state $ either (:data states)
{} $ :value false
container
{} $ :position ([] 120 300)
comp-switch $ {}
:value $ :value state
:position $ [] 0 0
:on-change $ fn (value d!)
d! cursor $ assoc state :value value
comp-switch $ {}
:value $ :value state
:position $ [] 100 20
:title "\"Custom title"
:on-change $ fn (value d!)
d! cursor $ assoc state :value value
|comp-text-input $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-text-input (states)
let
cursor $ :cursor states
state $ either (:data states)
{} (:text "\"initial text") (:long-text "\"long..")
container ({})
rect
{}
:position $ [] 140 110
:size $ [] 80 24
:fill $ hslx 0 0 20
:on $ {}
:pointertap $ fn (e d!)
request-text! e
{}
:initial $ :text state
:style $ {} (:color "\"blue")
fn (result)
d! cursor $ assoc state :text result
text $ {}
:text $ :text state
:position $ [] 6 4
:style $ {} (:font-size 14)
:fill $ hslx 0 0 80
rect
{}
:position $ [] 140 180
:size $ [] 200 100
:fill $ hslx 0 0 20
:on $ {}
:pointertap $ fn (e d!)
request-text! e
{}
:initial $ :long-text state
:style $ {} (:font-family font-code)
:textarea? true
fn (result)
d! cursor $ assoc state :long-text result
text $ {}
:text $ :long-text state
:position $ [] 6 4
:style $ {} (:font-size 14)
:fill $ hslx 0 0 80
|inline-file $ %{} :CodeEntry (:doc |)
:code $ quote
defmacro inline-file (name)
read-file $ str "\"assets/" name
|sample-texture $ %{} :CodeEntry (:doc |)
:code $ quote
def sample-texture $ .!from PIXI/Texture "\"https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/1a2af589827261.5e022908ed0b1.jpg"
|tabs $ %{} :CodeEntry (:doc |)
:code $ quote
def tabs $ [] ([] :drafts "\"Drafts") ([] :grids "\"Grids") ([] :curves "\"Curves") ([] :gradients "\"Gradients") ([] :keyboard "\"Keyboard") ([] :slider "\"Slider") ([] :buttons "\"Buttons") ([] :points "\"Points") ([] :switch "\"Switch") ([] :input "\"Input") ([] :messages "\"Messages") ([] :slider-point "\"Slider Point") ([] :spin-slider "\"Spin Slider") ([] :arrows "\"Arrows") ([] :shadow "\"Shadow") ([] :mesh "\"Mesh")
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns phlox.app.container $ :require
phlox.core :refer $ g hslx rect circle text container graphics create-list polyline >> line-segments mesh group
phlox.app.comp.drafts :refer $ comp-drafts
phlox.app.comp.keyboard :refer $ comp-keyboard
phlox.comp.button :refer $ comp-button
phlox.comp.drag-point :refer $ comp-drag-point
phlox.comp.switch :refer $ comp-switch
phlox.comp.slider :refer $ comp-slider-point
phlox.app.comp.slider-demo :refer $ comp-slider-demo comp-slider-point-demo comp-spin-slider-demo
phlox.input :refer $ request-text!
phlox.comp.messages :refer $ comp-messages
"\"nanoid" :refer $ nanoid
memof.once :refer $ memof1-call
phlox.util.styles :refer $ font-code
phlox.comp.arrow :refer $ comp-arrow
phlox.complex :refer $ polar-point
phlox.util :refer $ canvas-center!
"\"@pixi/filter-drop-shadow" :refer $ DropShadowFilter
"\"pixi.js" :as PIXI
phlox.comp.tabs :refer $ comp-tabs
|phlox.app.main $ %{} :FileEntry
:defs $ {}
|*store $ %{} :CodeEntry (:doc |)
:code $ quote (defatom *store schema/store)
|dispatch! $ %{} :CodeEntry (:doc |)
:code $ quote
defn dispatch! (op)
when
and dev? $ not= (nth op 0) :states
js/console.log "\"dispatch!" op
let
op-id $ nanoid
op-time $ js/Date.now
reset! *store $ updater @*store op op-id op-time
|main! $ %{} :CodeEntry (:doc |)
:code $ quote
defn main! () (; js/console.log PIXI)
if dev? $ load-console-formatter!
-> (new FontFaceObserver "\"Josefin Sans") (.!load)
.!then $ fn (event) (render-app!)
add-watch *store :change $ fn (store prev) (render-app!)
render-app!
when true (render-control!) (start-control-loop! 8 on-control-event)
println "\"App Started"
|reload! $ %{} :CodeEntry (:doc |)
:code $ quote
defn reload! () $ if (nil? build-errors)
do (clear-phlox-caches!) (remove-watch *store :change)
add-watch *store :change $ fn (store prev) (render-app!)
render-app!
when true $ replace-control-loop! 8 on-control-event
hud! "\"ok~" "\"OK"
hud! "\"error" build-errors
|render-app! $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-app! (? arg)
render! (comp-container @*store) dispatch! $ either arg ({})
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns phlox.app.main $ :require ("\"pixi.js" :as PIXI)
phlox.core :refer $ render! clear-phlox-caches! on-control-event
phlox.app.container :refer $ comp-container
phlox.app.schema :as schema
phlox.config :refer $ dev? mobile?
"\"nanoid" :refer $ nanoid
phlox.app.updater :refer $ updater
"\"fontfaceobserver-es" :default FontFaceObserver
"\"./calcit.build-errors" :default build-errors
"\"bottom-tip" :default hud!
touch-control.core :refer $ render-control! start-control-loop! replace-control-loop!
|phlox.app.schema $ %{} :FileEntry
:defs $ {}
|store $ %{} :CodeEntry (:doc |)
:code $ quote
def store $ {} (:tab :mesh) (:x 0) (:keyboard-on? false) (:counted 0)
:states $ {}
:cursor $ []
:ns $ %{} :CodeEntry (:doc |)
:code $ quote (ns phlox.app.schema)
|phlox.app.updater $ %{} :FileEntry
:defs $ {}
|updater $ %{} :CodeEntry (:doc |)
:code $ quote
defn updater (store op op-id op-time)
tag-match op
:add-x
update store :x $ fn (x)
if (> x 10) 0 $ + x 1
(:tab t) (assoc store :tab t)
(:toggle-keyboard) (update store :keyboard-on? not)
(:counted) (update store :counted inc)
(:states cursor s) (update-states store cursor s)
(:hydrate-storage d) d
_ $ do (eprintln "\"unknown op" op) store
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns phlox.app.updater $ :require
[] phlox.cursor :refer $ [] update-states
|phlox.check $ %{} :FileEntry
:defs $ {}
|dev-check $ %{} :CodeEntry (:doc |)
:code $ quote
defmacro dev-check (data rule)
if dev?
&let
result $ gensym "\"result"
quasiquote $ &let
~result $ validate-lilac ~data ~rule
when-not (:ok? ~result)
js/console.error (:formatted-message ~result) &newline
str "\"(dev-check " (quote ~data) "\" " (quote ~rule) "\") where props is:"
to-js-data ~data
quasiquote nil
|dev-check-message $ %{} :CodeEntry (:doc |)
:code $ quote
defmacro dev-check-message (message data rule)
if dev?
&let
result $ gensym "\"result"
quasiquote $ &let
~result $ validate-lilac ~data ~rule
when-not (:ok? ~result)
js/console.error (:formatted-message ~result) &newline (str ~message "\", when props is:") (to-js-data ~data)
quasiquote nil
|lilac-circle $ %{} :CodeEntry (:doc |)
:code $ quote
def lilac-circle $ record+
{}
:line-style $ optional+ lilac-line-style
:on $ optional+ lilac-event-map
:position lilac-point
:radius $ number+
:fill $ optional+ (number+)
:alpha $ optional+ (number+)
:rotation $ optional+ (number+)
:angle $ optional+ (number+)
:pivot $ optional+ lilac-point
:fill $ optional+ (number+)
:on-keyboard $ optional+ lilac-event-map
:filters $ optional+
list+ $ list+ (any+)
{} $ :check-keys? true
|lilac-color $ %{} :CodeEntry (:doc |)
:code $ quote
def lilac-color $ or+
[] (number+) (string+)
|lilac-container $ %{} :CodeEntry (:doc |)
:code $ quote
def lilac-container $ record+
{} (:position lilac-point)
:rotation $ number+
:pivot lilac-point
:alpha $ number+
:angle $ number+
:on-keyboard $ optional+ lilac-event-map
{} (:check-keys? true) (:all-optional? true)
|lilac-event-map $ %{} :CodeEntry (:doc |)
:code $ quote
def lilac-event-map $ dict+ (keyword+) (fn+)
|lilac-graphics $ %{} :CodeEntry (:doc |)
:code $ quote
def lilac-graphics $ record+
{}
:on $ optional+ lilac-event-map
:position $ optional+ lilac-point
:pivot $ optional+ lilac-point
:alpha $ optional+ (number+)
:rotation $ optional+ (number+)
:angle $ optional+ (number+)
:ops $ list+
optional+ $ tuple+
[] (keyword+) (any+)
{} $ :allow-seq? true
:on-keyboard $ optional+ lilac-event-map
:filters $ optional+
list+ $ list+ (any+)
{} $ :check-keys? true
|lilac-line-segments $ %{} :CodeEntry (:doc |)
:code $ quote
def lilac-line-segments $ record+
{}
:on $ optional+ lilac-event-map
:position $ optional+ lilac-point
:pivot $ optional+ lilac-point
:alpha $ optional+ (number+)
:rotation $ optional+ (number+)
:angle $ optional+ (number+)
:style lilac-line-style
:segments $ list+
tuple+ ([] lilac-point lilac-point)
{} $ :check-size? true
:on-keyboard $ optional+ lilac-event-map
{} $ :check-keys? true
|lilac-line-style $ %{} :CodeEntry (:doc |)
:code $ quote
def lilac-line-style $ record+
{}
:width $ number+
:color $ number+
:alpha $ optional+ (number+)
|lilac-point $ %{} :CodeEntry (:doc |)
:code $ quote
def lilac-point $ tuple+
[] (number+) (number+)
{} $ :check-size? true
|lilac-polyline $ %{} :CodeEntry (:doc |)
:code $ quote
def lilac-polyline $ record+
{}
:on $ optional+ lilac-event-map
:position $ optional+ lilac-point
:pivot $ optional+ lilac-point
:alpha $ optional+ (number+)
:rotation $ optional+ (number+)
:angle $ optional+ (number+)
:style lilac-line-style
:points $ list+
tuple+ $ [] (number+) (number+)
:on-keyboard $ optional+ lilac-event-map
{} $ :check-keys? true
|lilac-rect $ %{} :CodeEntry (:doc |)
:code $ quote
def lilac-rect $ record+
{}
:line-style $ optional+ lilac-line-style
:on $ optional+ lilac-event-map
:position $ optional+ lilac-point
:size lilac-point
:pivot $ optional+ lilac-point
:alpha $ optional+ (number+)
:rotation $ optional+ (number+)
:angle $ optional+ (number+)
:fill $ optional+ lilac-color
:radius $ optional+ (number+)
:on-keyboard $ optional+ lilac-event-map
:filters $ optional+
list+ $ list+ (any+)
{} $ :check-keys? true
|lilac-text $ %{} :CodeEntry (:doc |)
:code $ quote
def lilac-text $ record+
{}
:text $ string+
:style lilac-text-style
:position $ optional+ lilac-point
:pivot $ optional+ (number+)
:rotation $ optional+ (number+)
:angle $ optional+ (number+)
:alpha $ optional+ (number+)
:align $ optional+
enum+ $ #{} :left :center :right
:on-keyboard $ optional+ lilac-event-map
:filters $ optional+
list+ $ list+ (any+)
{} $ :check-keys? true
|lilac-text-style $ %{} :CodeEntry (:doc |)
:code $ quote
def lilac-text-style $ record+
{}
:align $ enum+ (#{} :left :center :right)
:break-words $ bool+
:drop-shadow $ bool+
:drop-shadow-alpha $ number+
{} (:min 0) (:max 1)
:drop-shadow-angle $ number+
:drop-shadow-blur $ number+
:drop-shadow-color lilac-color
:drop-shadow-distance $ number+
:fill $ or+
[] lilac-color $ list+ lilac-color
:fill-gradient-type $ enum+ (#{} :vertical :horizontal :v :h)
:fill-gradient-stops $ any+
:font-family $ string+
:font-size $ number+
:font-style $ enum+ (#{} :normal :italic :oblique)
:font-variant $ enum+ (#{} :normal :small-caps)
:font-weight $ number+
:leading $ number+
:letter-spacing $ number+
:line-height $ number+
:line-join $ enum+ (#{} :miter :round :round :bevel)
:miter-limit $ number+
:padding $ number+
:stroke lilac-color
:stroke-thickness $ number+
:trim $ bool+
:text-baseline $ enum+ (#{} :alphabetic)
:white-space $ enum+ (#{} :normal :pre :pre-line)
:word-wrap $ bool+
:word-wrap-width $ number+
{} (:check-keys? true) (:all-optional? true)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns phlox.check $ :require
lilac.core :refer $ validate-lilac record+ number+ string+ optional+ tuple+ enum+ dict+ fn+ any+ keyword+ bool+ list+ or+ is+
phlox.config :refer $ dev?
|phlox.comp.arrow $ %{} :FileEntry
:defs $ {}
|comp-arrow $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-arrow (states props) (; dev-check props lilac-arrow)
let
color $ either (:color props) (hslx 0 0 100)
from $ :from props
to $ :to props
width $ either (:width props) 1
arg-length $ either (:arm-length props) 10
on-change $ :on-change props
reversed-vec $ complex/minus from to
reversed-unit $ complex/divide-by reversed-vec (vec-length reversed-vec)