generated from calcit-lang/respo-calcit-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompact.cirru
269 lines (268 loc) · 11.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
{} (:package |app)
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!) (:version |0.0.1)
:modules $ [] |respo.calcit/compact.cirru |lilac/compact.cirru |memof/compact.cirru |respo-ui.calcit/compact.cirru |respo-markdown.calcit/compact.cirru |reel.calcit/compact.cirru
:entries $ {}
:files $ {}
|app.comp.container $ {}
:defs $ {}
|comp-container $ quote
defcomp comp-container (reel)
let
store $ :store reel
states $ :states store
cursor $ or (:cursor states) ([])
state $ or (:data states)
{} $ :inputs ([])
div
{} $ :style (merge ui/global ui/fullscreen ui/column)
div
{} $ :style
merge ui/expand $ {} (:padding 40) (:font-size 32)
<> $ -> (:inputs state)
or $ []
map markup-tone
.join-str "\" "
div
{} $ :style
merge ui/expand $ {} (:padding 16) (:font-size 32)
input $ {} (:value "\"") (:style ui/input) (:placeholder "\"TODO")
div
{} $ :style
merge ui/row-center $ {} (:padding 16)
comp-keyboard (>> states :keyboard)
fn (input d!)
case-default input
d! cursor $ update state :inputs
fn (inputs)
conj inputs $ .join-str input "\""
nil $ raise "\"Unknown input"
-1 $ d! cursor
update state :inputs $ fn (inputs)
or (butlast inputs) ([])
when dev? $ comp-reel (>> states :reel) reel ({})
|comp-keyboard $ quote
defcomp comp-keyboard (states on-input)
let
cursor $ :cursor states
state $ or (:data states)
{} $ :buffer ([])
div
{} $ :style
merge ui/center $ {} (:font-family "\"Yomogi, cursive")
div
{} $ :style
{} $ :font-size 40
<> $ .join-str (:buffer state) "\""
div
{} $ :style ui/row-center
list-> ({})
->
case-default
count $ :buffer state
[]
0 initial-keyboard
1 vowel-keyboard
2 tone-keyboard
map-indexed $ fn (idx row)
[] idx $ list->
{} $ :style ui/row
-> row $ map-indexed
fn (j key)
[] j $ div
{} (:class-name "\"keystroke") (:style style-keystroke)
:on-click $ fn (e d!)
when (not= key "\".")
let
chunk $ conj (:buffer state) key
if
>= (count chunk) 3
do (on-input chunk d!)
d! cursor $ assoc state :buffer ([])
do $ d! cursor (assoc state :buffer chunk)
<> key
list-> ({})
-> ([] "\"⌫" "\"." "\"." "\"⚁")
map-indexed $ fn (idx key)
[] idx $ div
{} (:style style-keystroke)
:on-click $ fn (e d!)
case-default key (println "\"TODO")
"\"⌫" $ if
empty? $ :buffer state
on-input -1 d!
d! cursor $ update state :buffer
fn (x)
or (butlast x) ([])
"\"⚁" $ js/document.body.requestFullscreen
<> key
|mark-vowel $ quote
defn mark-vowel (vowel tone)
let
x $ [] vowel tone
println "\"vvvv" x
cond
= x $ [] "\"a" "\"→"
, "\"ā"
(= x ([] "\"a" "\"↗"))
, "\"á"
(= x ([] "\"a" "\"↺"))
, "\"ǎ"
(= x ([] "\"a" "\"↘"))
, "\"à"
(= x ([] "\"e" "\"→"))
, "\"ē"
(= x ([] "\"e" "\"↗"))
, "\"é"
(= x ([] "\"e" "\"↺"))
, "\"ě"
(= x ([] "\"e" "\"↘"))
, "\"è"
(= x ([] "\"i" "\"→"))
, "\"ī"
(= x ([] "\"i" "\"↗"))
, "\"í"
(= x ([] "\"i" "\"↺"))
, "\"ǐ"
(= x ([] "\"i" "\"↘"))
, "\"ì"
(= x ([] "\"o" "\"→"))
, "\"ō"
(= x ([] "\"o" "\"↗"))
, "\"ó"
(= x ([] "\"o" "\"↺"))
, "\"ǒ"
(= x ([] "\"o" "\"↘"))
, "\"ò"
(= x ([] "\"u" "\"→"))
, "\"ū"
(= x ([] "\"u" "\"↗"))
, "\"ú"
(= x ([] "\"u" "\"↺"))
, "\"ǔ"
(= x ([] "\"u" "\"↘"))
, "\"ù"
(= x ([] "\"ü" "\"→"))
, "\"ǖ"
(= x ([] "\"ü" "\"↗"))
, "\"ǘ"
(= x ([] "\"ü" "\"↺"))
, "\"ǚ"
(= x ([] "\"ü" "\"↘"))
, "\"ǜ"
true $ str vowel tone
|markup-tone $ quote
defn markup-tone (x)
-> x
.!replace (new js/RegExp "\"([aoeiuü])(ng?)([→↗↺↘])$")
fn (a b b2 c & args)
str (mark-vowel b c) b2
.!replace (new js/RegExp "\"([aoeiuü])([aoeiuü])([→↗↺↘])$")
fn (a b b2 c & args)
str (mark-vowel b c) b2
.!replace (new js/RegExp "\"([aoeiuü])r([→↗↺↘])$")
fn (a b c & args)
str (mark-vowel b c) "\"r"
.!replace (new js/RegExp "\"([aoeiuü])([→↗↺↘])$")
fn (a b c & args) (js/console.log b c) (mark-vowel b c)
|style-keystroke $ quote
def style-keystroke $ merge ui/center
{} (:width 60) (:height 60)
:border $ str "\"1px solid " (hsl 0 0 90)
:margin "\"4px"
:cursor :pointer
:user-select :none
:font-size 20
:ns $ quote
ns app.comp.container $ :require (respo-ui.core :as ui)
respo-ui.core :refer $ hsl
respo.core :refer $ defcomp defeffect list-> <> >> div button textarea span input
respo.comp.space :refer $ =<
reel.comp.reel :refer $ comp-reel
respo-md.comp.md :refer $ comp-md
app.config :refer $ dev? initial-keyboard vowel-keyboard tone-keyboard
|app.config $ {}
:defs $ {}
|dev? $ quote
def dev? $ = "\"dev" (get-env "\"mode" "\"release")
|initial-keyboard $ quote
def initial-keyboard $ [] ([] "\"b" "\"p" "\"m" "\"f" "\"d" "\"t" "\"n" "\"l") ([] "\"g" "\"k" "\"h" "\"j" "\"q" "\"x" "\"." "\".") ([] "\"zh" "\"ch" "\"sh" "\"r" "\"z" "\"c" "\"s" "\".") ([] "\"y" "\"w" "\"." "\"." "\"." "\"." "\"." "\".")
|site $ quote
def site $ {} (:storage-key "\"proto-shuangpin")
|tone-keyboard $ quote
def tone-keyboard $ [] ([] "\"." "\"." "\"→" "\"↗" "\"↺" "\"↘" "\"." "\".")
|vowel-keyboard $ quote
def vowel-keyboard $ [] ([] "\"a" "\"o" "\"e" "\"i" "\"u" "\"ü" "\"uan" "\"ian") ([] "\"ai" "\"ei" "\"ui" "\"ao" "\"ou" "\"iu" "\"uo" "\"uai") ([] "\"an" "\"en" "\"in" "\"un" "\"ün" "\"ie" "\"üe" "\"er") ([] "\"ang" "\"eng" "\"ing" "\"ong" "\"iang" "\"uang" "\"iong" "\"ua")
:ns $ quote (ns app.config)
|app.main $ {}
:defs $ {}
|*reel $ quote
defatom *reel $ -> reel-schema/reel (assoc :base schema/store) (assoc :store schema/store)
|dispatch! $ quote
defn dispatch! (op op-data)
when
and config/dev? $ not= op :states
println "\"Dispatch:" op op-data
reset! *reel $ reel-updater updater @*reel op op-data
|main! $ quote
defn main! ()
println "\"Running mode:" $ if config/dev? "\"dev" "\"release"
render-app!
add-watch *reel :changes $ fn (reel prev) (render-app!)
listen-devtools! |k dispatch!
; .!addEventListener js/window |beforeunload $ fn (event) (persist-storage!)
; repeat! 60 persist-storage!
; let
raw $ .!getItem js/localStorage (:storage-key config/site)
when (some? raw)
dispatch! :hydrate-storage $ parse-cirru-edn raw
println "|App started."
|mount-target $ quote
def mount-target $ .!querySelector js/document |.app
|persist-storage! $ quote
defn persist-storage! () $ .!setItem js/localStorage (:storage-key config/site)
format-cirru-edn $ :store @*reel
|reload! $ 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! $ quote
defn render-app! () $ render! mount-target (comp-container @*reel) dispatch!
|repeat! $ quote
defn repeat! (duration cb)
js/setTimeout
fn () (cb)
repeat! (* 1000 duration) cb
* 1000 duration
:ns $ quote
ns app.main $ :require
respo.core :refer $ render! clear-cache!
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
app.config :as config
"\"./calcit.build-errors" :default build-errors
"\"bottom-tip" :default hud!
|app.schema $ {}
:defs $ {}
|store $ quote
def store $ {}
:states $ {}
:cursor $ []
:ns $ quote (ns app.schema)
|app.updater $ {}
:defs $ {}
|updater $ quote
defn updater (store op data op-id op-time)
case-default op
do (println "\"unknown op:" op) store
:states $ update-states store data
:hydrate-storage data
:ns $ quote
ns app.updater $ :require
respo.cursor :refer $ update-states