generated from Phlox-GL/phlox-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompact.cirru
283 lines (282 loc) · 12.4 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
{} (:package |app)
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!) (:version |0.4.10)
:modules $ [] |memof/ |lilac/ |respo.calcit/ |respo-ui.calcit/ |phlox/ |pointed-prompt/ |bisection-key/ |touch-control/
:entries $ {}
:files $ {}
|app.comp.container $ {}
:defs $ {}
|comp-container $ quote
defn comp-container (store)
; println "\"Store" store $ :tab store
let
cursor $ []
states $ :states store
slides $ :slides store
slide-key $ :slide-key store
container ({})
let
slide $ get slides slide-key
if (nil? slide)
text $ {} (:text "\"No Slide")
:style $ {} (:font-size 60) (:font-weight 100)
:fill $ hslx 0 100 50
:font-family ui/font-fancy
:align :center
comp-slide (>> states slide-key) slide-key slide
comp-slide-tabs (keys slides) slide-key
comp-button $ {} (:text "\"Add")
:position $ [] 160
- 60 $ * 0.5 js/window.innerHeight
:on-pointertap $ fn (e d!) (d! :add-slide-after slide-key)
comp-button $ {} (:text "\"Command")
:position $ [] 220
- 60 $ * 0.5 js/window.innerHeight
:on-pointertap $ fn (e d!)
request-text! e
{} (:placeholder "\"Command")
:style $ {} (:font-family ui/font-code)
fn (code)
run-command (parse-cirru code) (:main-hint store) (:secondary-hint store) slide-key d!
; println "\"Store" store $ :tab store
comp-button $ {} (:text "\"DEBUG")
:position $ [] 320
- 60 $ * 0.5 js/window.innerHeight
:on-pointertap $ fn (e d!) (js/console.warn "\"[DEBUG]" store)
comp-drag-point (>> states :main-hint)
{}
:position $ :main-hint store
:fill $ hslx 120 90 80
:radius 8
:hide-text? true
:on-change $ fn (pos d!) (d! :move-main-hint pos)
comp-drag-point (>> states :secondary-hint)
{}
:position $ :secondary-hint store
:fill $ hslx 250 90 70
:radius 6
:hide-text? true
:on-change $ fn (pos d!) (d! :move-secondary-hint pos)
|comp-slide $ quote
defn comp-slide (states pointed-key slide)
let
cursor $ :cursor states
state $ either (:data states)
{} (:pointer 0)
:spin-pos $ []
- 200 $ * 0.5 js/window.innerWidth
- (* 0.5 js/window.innerHeight) 200
pointer $ :pointer state
container ({})
create-list :container ({})
-> slide :logs $ map-indexed
fn (idx log)
let
shape-op $ :op log
[] idx $ comp-button
{}
:text $ str (:type shape-op)
:position $ []
- 20 $ * 0.5 js/window.innerWidth
- 120 $ * idx 40
:on-pointertap $ fn (e d!) (println "\"shape-op" shape-op)
create-list :container ({})
-> slide :logs $ map-indexed
fn (idx log)
[] idx $ render-shape (:op log)
comp-spin-slider (>> states :spin)
{} (:value pointer)
:position $ :spin-pos state
:spin-pivot $ complex/add (:spin-pos state)
[] (* 0.5 js/window.innerWidth) (* 0.5 js/window.innerHeight)
:unit 4
:min 0
:max 100
:fraction 2
:on-change $ fn (value d!)
d! cursor $ assoc state :pointer value
:on-move $ fn (pos d!) (; println "\"move to:" pos)
d! cursor $ assoc state :spin-pos pos
|comp-slide-tabs $ quote
defn comp-slide-tabs (slide-keys pointer)
; println "\"key" $ -> slide-keys .to-list
.sort $ fn (a b) (&compare a b)
create-list :container ({})
-> slide-keys .to-list
.sort $ fn (a b) (&compare a b)
.map-indexed $ fn (idx key)
[] key $ comp-button
{} (:text key)
:position $ []
-
+ 100 $ * idx 44
&* 0.5 js/window.innerWidth
- 20 $ * 0.5 js/window.innerHeight
:fill $ if (= key pointer) (hslx 60 80 30)
:align-right? false
:on-pointertap $ fn (e d!) (; println "\"key" key) (d! :switch-slide key)
|render-shape $ quote
defn render-shape (shape-op)
case-default (:type shape-op)
text $ {}
:text $ str "\"Unknown: " shape-op
:style $ {} (:font-size 14) (:font-weight 500)
:fill $ hslx 0 100 50
:font-family ui/font-fancy
:align :center
:rect $ rect
{}
:position $ :position shape-op
:size $ :sizes shape-op
:line-style $ {} (:width 4)
:color $ hslx 0 80 50
:alpha 1
:fill $ hslx 200 80 80
:on $ {}
:circle $ circle
{}
:radius $ :radius shape-op
:position $ :position shape-op
:fill $ hslx 200 80 80
:on $ {}
|run-command $ quote
defn run-command (tree c1 c2 slide-key d!)
if
= 1 $ count tree
let[] (command p1 p2 p3) (first tree)
case-default command (println "\"Unknown command:" command)
"\"del-slide" $ d! :del-slide slide-key
"\"add-slide" $ if (some? slide-key) (d! :add-slide-after slide-key) (js/console.warn "\"nil slide-key")
"\"add-circle" $ d! :add-shape
{} (:slide-key slide-key)
:op $ {} (:type :circle)
:position $ complex/divide-by (complex/add c1 c2) 2
:radius $ * 0.5
vec-length $ complex/minus c2 c1
"\"add-rect" $ d! :add-shape
{} (:slide-key slide-key)
:op $ {} (:type :rect) (:position c1)
:sizes $ complex/minus c2 c1
js/console.warn "\"unknown tree:" tree
:ns $ quote
ns app.comp.container $ :require
phlox.core :refer $ g hslx rect circle text container graphics create-list >>
phlox.comp.button :refer $ comp-button
phlox.comp.drag-point :refer $ comp-drag-point
"\"shortid" :as shortid
respo-ui.core :as ui
memof.alias :refer $ memof-call
phlox.comp.drag-point :refer $ comp-drag-point
phlox.comp.button :refer $ comp-button
phlox.input :refer $ request-text!
phlox.comp.slider :refer $ comp-spin-slider
phlox.complex :as complex
phlox.math :refer $ vec-length
|app.config $ {}
:defs $ {}
|dev? $ quote
def dev? $ = "\"dev" (get-env "\"mode" "\"release")
|site $ quote
def site $ {} (:dev-ui "\"http://localhost:8100/main.css") (:release-ui "\"http://cdn.tiye.me/favored-fonts/main.css") (:cdn-url "\"http://cdn.tiye.me/phlox/") (:title "\"Phlox") (:icon "\"http://cdn.tiye.me/logo/quamolit.png") (:storage-key "\"phlox")
:ns $ quote (ns app.config)
|app.main $ {}
:defs $ {}
|*store $ quote (defatom *store schema/store)
|dispatch! $ quote
defn dispatch! (op op-data)
when
and dev? $ not= op :states
println "\"dispatch!" op op-data
let
op-id $ nanoid
op-time $ js/Date.now
reset! *store $ updater @*store op op-data op-id op-time
|main! $ 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-control!
start-control-loop! 8 on-control-event
println "\"App Started"
|reload! $ quote
defn reload! () $ if (nil? build-errors)
do (println "\"Code updated.") (clear-phlox-caches!) (remove-watch *store :change)
add-watch *store :change $ fn (store prev) (render-app!)
render-app!
replace-control-loop! 8 on-control-event
hud! "\"ok~" "\"Ok"
hud! "\"error" build-errors
|render-app! $ quote
defn render-app! (? arg)
render! (comp-container @*store) dispatch! $ or arg ({})
:ns $ quote
ns app.main $ :require ("\"pixi.js" :as PIXI)
phlox.core :refer $ render! clear-phlox-caches! on-control-event
app.comp.container :refer $ comp-container
app.schema :as schema
app.config :refer $ dev?
"\"nanoid" :refer $ nanoid
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!
|app.schema $ {}
:defs $ {}
|action-log $ quote
def action-log $ {} (:op nil) (:snapshot nil)
|slide $ quote
def slide $ {}
:logs $ do action-log ([])
|store $ quote
def store $ {}
:states $ {}
:cursor $ []
:slide-key nil
:slides $ do slide ({})
:main-hint $ [] 10 10
:secondary-hint $ [] 40 40
:ns $ quote (ns app.schema)
|app.updater $ {}
:defs $ {}
|add-slide-after $ quote
defn add-slide-after (slides base-key)
if (nil? base-key)
if (empty? slides)
{} $ mid-id schema/slide
assoc-append slides schema/slide
if (empty? slides)
let
next-key $ key-after slides base-key
assoc slides next-key schema/slide
assoc-after slides base-key schema/slide
|updater $ quote
defn updater (store op op-data op-id op-time)
case-default op
do (println "\"unknown op" op op-data) store
:states $ update-states store op-data
:move-main-hint $ assoc store :main-hint op-data
:move-secondary-hint $ assoc store :secondary-hint op-data
:add-slide-after $ update store :slides
fn (slides) (add-slide-after slides op-data)
:del-slide $ dissoc-in store ([] :slides op-data)
:switch-slide $ assoc store :slide-key op-data
:add-shape $ let
slide-key $ :slide-key op-data
shape-op $ :op op-data
if (some? slide-key)
update-in store ([] :slides slide-key :logs)
fn (logs)
let
tree $ if (empty? logs) ([])
:snapshot $ last logs
conj logs $ {} (:op shape-op)
:snapshot $ conj tree shape-op
:hydrate-storage op-data
:ns $ quote
ns app.updater $ :require
[] phlox.cursor :refer $ [] update-states
bisection-key.core :refer $ bisect mid-id
bisection-key.util :refer $ assoc-after assoc-append key-after
app.schema :as schema