-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_min.html
319 lines (266 loc) · 8.99 KB
/
test_min.html
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
<html>
<title>Blackboard</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="rabbit.png"><style>
body { background: black; color: rgba(255,255,255,.87);}
@font-face {
font-family: Mono;
src: url("lib/RobotoMono-Light.ttf") format("truetype");
}
@font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url("lib/MaterialIcons-Regular.ttf") format('truetype')
}
.material-icons {
font-family: 'Material Icons' !important;
font-weight: normal;
font-style: normal;
font-size: 24px; /* Preferred icon size */
display: inline-block;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;
/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;
/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;
/* Support for IE. */
font-feature-settings: 'liga';
}
* {
font-family: Mono;
font-size: 16px;
}
pre, code, pre > * {
font-family: Mono;
}
.shadow_0 {
box-shadow: none
}
.shadow_1{
box-shadow: 0 1px 1px 0 rgba(0,0,0,0.14), 0 2px 1px -1px rgba(0,0,0,0.12), 0 1px 3px 0 rgba(0,0,0,0.20)
}
.shadow_2{
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.20)
}
.shadow_3{
box-shadow: 0 3px 4px 0 rgba(0,0,0,0.14), 0 3px 3px -2px rgba(0,0,0,0.12), 0 1px 8px 0 rgba(0,0,0,0.20)
}
.shadow_4{
box-shadow: 0 4px 5px 0 rgba(0,0,0,0.14), 0 1px 10px 0 rgba(0,0,0,0.12), 0 2px 4px -1px rgba(0,0,0,0.20)
}
.shadow_6{
box-shadow: 0 6px 10px 0 rgba(0,0,0,0.14), 0 1px 18px 0 rgba(0,0,0,0.12), 0 3px 5px -1px rgba(0,0,0,0.20)
}
.shadow_8{
box-shadow: 0 8px 10px 1px rgba(0,0,0,0.14), 0 3px 14px 2px rgba(0,0,0,0.12), 0 5px 5px -3px rgba(0,0,0,0.20)
}
.shadow_12{
box-shadow: 0 12px 17px 2px rgba(0,0,0,0.14), 0 5px 22px 4px rgba(0,0,0,0.12), 0 7px 8px -4px rgba(0,0,0,0.20)
}
.shadow_16{
box-shadow: 0 16px 24px 2px rgba(0,0,0,0.14), 0 6px 30px 5px rgba(0,0,0,0.12), 0 8px 10px -5px rgba(0,0,0,0.20)
}
.shadow_24{
box-shadow: 0 24px 38px 3px rgba(0,0,0,0.14), 0 9px 46px 8px rgba(0,0,0,0.12), 0 11px 15px -7px rgba(0,0,0,0.20)
}
dialog {
background-color: rgba(18,18,18,1);
color: rgba(255,255,255,.87);
border: none;
padding: 0px;
box-shadow: 0 24px 38px 3px rgba(0,0,0,0.14), 0 9px 46px 8px rgba(0,0,0,0.12), 0 11px 15px -7px rgba(0,0,0,0.20);
box-sizing: border-box;
}
.card {
background-color: rgba(18,18,18,1);
color: rgba(255,255,255,.87);
border: none;
padding: 12px 16px;
box-sizing: border-box;
}
button, textarea, input{
background: none;
color: rgba(255,255,255,.87);
border: none;
border-bottom: 2px solid #00ccff;
outline: none;
box-sizing: border-box;
}
.glow_crimson, .tile_crimson:hover, .tile_crimson:focus{
box-shadow: 0 4px 5px 0 rgba(220, 20, 60, 0.14), 0 1px 10px 0 rgba(220, 20, 60, 0.12), 0 2px 4px -1px rgba(220, 20, 60, 0.20);
background: rgb(220, 20, 60) !important;
}
.glow_emerald, .tile_emerald:hover, .tile_emerald:focus{
box-shadow: 0 4px 5px 0 rgba(0, 89, 11, 0.14), 0 1px 10px 0 rgba(0, 89, 11, 0.12), 0 2px 4px -1px rgba(0, 89, 11, 0.20);
background: rgb(0, 89, 11) !important;
}
.glow_cobalt, .tile_cobalt:hover, .tile_cobalt:focus{
box-shadow: 0 4px 5px 0 rgba(0, 71, 171, 0.14), 0 1px 10px 0 rgba(0, 71, 171, 0.12), 0 2px 4px -1px rgba(0, 71, 171, 0.20);
background: rgb(0, 71, 171) !important;
}
.glow_gold, .tile_gold:hover, .tile_gold:focus{
box-shadow: 0 4px 5px 0 rgba(255, 215, 0, 0.14), 0 1px 10px 0 rgba(255, 215, 0, 0.12), 0 2px 4px -1px rgba(255, 215, 0, 0.20);
background: rgb(255, 215, 0) !important;
}
.show_over {
opacity: 0;
}
div:hover > .hide_over,
div:focus > .hide_over {
opacity: 0;
}
div:hover > .show_over,
div:focus > .show_over {
opacity: 1;
}
.animate {
transition-timing-function: cubic-bezier(0.4, 0.0, 0.2, 1);
transition: all 0.3s;
}
.warn{
border-bottom: 2px solid #B00020;
}
::placeholder {
color: rgba(255,255,255,.6);
}
</style>
<body onload="brython({indexedDB: false})"></body>
<script src="lib/brython_aio.js"></script>
<script type="text/python">
from browser import window
from browser import aio as asyncio
from browser import document as doc
from browser.html import *
def box(*l, base=DIV, **kw):
sty = kw.get('style', {})
sty['box-sizing'] = 'border-box'
sty['display'] = 'inline'
sty['position'] = 'absolute'
kw['style'] = sty
return base(*l, **kw)
def icon(_icon, *l, **kw):
return I(_icon, *l, Class='material-icons', **kw)
def attr_map(i, **kw):
for k, v in kw.items():
setattr(i, k, v)
def recycle(items, data, how=attr_map):
buff = max(len(items) - len(data), 0)
for i, d in zip(items, data + [{}]*buff):
how(i, **d)
def partial(func, *args, **keywords):
def newfunc(*fargs, **fkeywords):
newkeywords = {**keywords, **fkeywords}
return func(*args, *fargs, **newkeywords)
newfunc.func = func
newfunc.args = args
newfunc.keywords = keywords
return newfunc
# recycle test
#header
def tracks_to_coords(tracks, x=0, y=0, ex=None, ey=None, padding=0):
# uses a tracks layout to return x,y/w,h values
columns, rows = tracks
if ex is None: ex = x
if ey is None: ey = y
return (columns[x][0] + padding, rows[y][0] + padding,
columns[ex][1] - columns[x][0] - padding*2,
rows[ey][1] - rows[y][0] - padding*2)
coords_map = 'left', 'top', 'width', 'height'
def _gmap(instance, *l, **kw):
for k, v in zip(coords_map, tracks_to_coords(*l, **kw)):
instance.style[k] = v
# in task
def tile(text='', _icon='', title='', background='',
font_size='24px', icon_size='64px', align='center', base=DIV, **kw):
sty = kw.get('style', {})
sty['overflow'] = 'hidden'
kw['style'] = sty
cla = kw.get('Class', '').split(' ')
cla += ['animate']
kw['Class'] = ' '.join(cla)
out = []
out.append(DIV(style={
'width': '100%',
'height': '100%',
'background': f'url({background})' or 'none',
'background-size': 'cover',
'background-position': 'center',
#'z-index': '-1',
'position': 'absolute',
'left': 0,
'top': 0,
}))
out.append(icon(_icon or '',
style={
'position': 'absolute',
'left': '50%',
'top': '50%',
'transform': 'translate(-50%, -50%)',
'font-size': icon_size}))
out.append(DIV(text or '',
style={
'position': 'absolute',
'left': '50%' if align=='center' else '0px',
'top': '50%',
'transform': 'translate(-50%, -50%)' if align=='center' else 'translate(0%, -50%)',
'font-size': font_size,
'text-align': align}))
out.append(DIV(f'{title}' or '',
style={
'position': 'absolute',
'left': 0,
'bottom': 0,
'display': 'initial' if title else 'none',
'background': 'rgba(0,0,0,.5)',
'padding': '8px'}))
return box(out, base=base, **kw)
def update_tile(instance, text='', _icon='', title='', background=''):
ui_background, ui_icon, ui_text, ui_title = instance.children
ui_background.style['background-image'] = f'url({background})' if background else 'none'
ui_icon.text = _icon or ''
ui_text.text = text or ''
if text and _icon:
ui_text.attrs['class'] = 'show_over animate'
ui_icon.attrs['class'] = 'hide_over material-icons animate'
else:
ui_text.attrs['class'] = 'animate'
ui_icon.attrs['class'] = 'material-icons animate'
ui_title.text = title or ''
ui_title.style['display'] = 'initial' if title else 'none'
if not any([text, _icon, title, title, background]):
instance.style['display'] = 'none'
else:
instance.style['display'] = 'initial'
viewport = doc.select_one('body').width//1.2, \
doc.select_one('body').height//1.2
cell_size = [viewport[1]//3 - 32]*2
grid_size = [a//b for a, b in zip(viewport, cell_size)]
offset = [(a-b*c)//2 for a, b, c in zip(viewport, cell_size, grid_size)]
tracks = [[(a+b*i, a+b+b*i) for i in range(c)] # (coord, length) pairs
for a, b, c in zip(offset, cell_size, grid_size)]
gmap = partial(tracks_to_coords, tracks, padding=8)
main_tile = partial(tile, style={'background': 'rgb(40, 40, 40)'}, Class='tile_cobalt')
scroll = 0
page_size = 3
data = [{'title': 'Match game', '_icon': 'view_module'}]
root = [main_tile(f'{i}') for i in range(grid_size[0]*grid_size[1])]
for idx, i in enumerate(root):
gmap(i, idx//grid_size[1], idx%grid_size[1])
async def main():
asyncio.run(popup(DIV(root, style={'width': viewport[0], 'height': viewport[1]})))
recycle(root, data[page_size*scroll:], update_tile)
#for i in range(8):
# recycle(root, data[page_size*i:], update_tile)
# await asyncio.sleep(1)
asyncio.run(main())
doc <= root
</script>
</html>