-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
218 lines (202 loc) · 6.97 KB
/
index.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css">
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<title>pipdev</title>
<style>
main,
py-script,
py-env {
display: none;
}
html.is-loaded main,
html.is-loaded py-script {
display: block;
}
.header {
text-align: right;
margin-bottom: 0.5em;
}
.header a {
font-size: smaller;
text-decoration: none;
}
.source {
padding: 1em 0;
}
.source input:not([type="checkbox"]):not([type="radio"]) {
margin: 0;
}
.source input,
.examples a,
.checkbox input {
text-align: center;
font-family: monospace, monospace;
}
.examples, .checkbox {
font-size: smaller;
}
.examples a {
font-size: smaller;
}
.checkbox input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"])
{
font-size: smaller;
height: auto;
padding: var(--nav-link-spacing-vertical) var(--nav-link-spacing-horizontal);
}
.output {
padding-top: 2em;
}
.output table {
width: auto;
margin: 0 auto;
}
.output thead th {
text-transform: uppercase;
font-size: smaller;
}
.output tbody span {
opacity: 0.5;
font-family: monospace, monospace;
font-size: smaller;
}
.output tbody td.is-valid {
background-color: rgba(0, 128, 0, 0.4);
border-bottom-color: rgba(0, 128, 0, 0.4);
}
.output tbody td.is-final span {
opacity: 0.75;
}
.output tbody td.is-valid span,
.output tbody td.is-valid.is-final span {
opacity: 1;
}
.output tbody tr:last-child td {
border-bottom: 0;
}
</style>
<py-env>
- packaging
- tabulate
- colorama
- paths:
- pipdev/pipdev.py
</py-env>
</head>
<body>
<main>
<div class="container">
<div class="row header">
<a href="https://github.com/nok/pipdev" class="secondary" target="github">github.com/nok/pipdev</a>
</div>
<div class="row source">
<input type="text" id="js-source" placeholder="~=1.2" value="~=1.2" aria-invalid="" tabindex="1">
</div>
<div class="row">
<nav>
<ul class="examples">
<li>Examples:</li>
<li><a href="#" role="button" class="outline secondary" id="js-example-0" tabindex="3">~=1.2</a></li>
<li><a href="#" role="button" class="outline secondary" id="js-example-1" tabindex="4">==1.2.*</a></li>
<li><a href="#" role="button" class="outline secondary" id="js-example-2" tabindex="5">~=1.2b,<=1.3a,!=1.2</a></li>
</ul>
<ul class="checkbox">
<li>
<label for="js-check">Individual test:</label>
</li>
<li>
<input type="text" id="js-check" placeholder="1.2.1" value="1.2.1" aria-invalid="" tabindex="2">
</li>
</ul>
</nav>
</div>
</div>
<div class="container-fluid">
<div class="row output">
<div id="js-output"></div>
</div>
</div>
</main>
<py-script>
from js import window, document, window
from pyodide import create_proxy
from pipdev import check_version, generate_versions_table
# Elements:
output_el = document.getElementById('js-output')
source_el = document.getElementById('js-source')
check_el = document.getElementById('js-check')
ex0_el = document.getElementById('js-example-0')
ex1_el = document.getElementById('js-example-1')
ex2_el = document.getElementById('js-example-2')
def get_url_param(name):
params = str(window.location.search).strip('?').replace('%3E', '>').replace('%3C', '<').replace('%7E', '~')
if params == '':
return False
params = params.split('&')
for param in params:
if param.startswith(name + '='):
param = param.lstrip(name + '=')
if param != '':
return param
return False
def do_check():
if check_el.value == '' or source_el.value == '':
check_el.setAttribute('aria-invalid', '')
return
try:
is_valid = check_version(check_el.value, source_el.value)
except:
check_el.setAttribute('aria-invalid', '')
else:
check_el.setAttribute('aria-invalid', 'false' if is_valid else 'true')
def do_update(value):
try:
table_content = generate_versions_table(value, fmt='html')
except:
source_el.setAttribute('aria-invalid', 'true')
output_el.innerHTML = ''
else:
if table_content.strip() == "":
source_el.setAttribute('aria-invalid', 'true')
output_el.innerHTML = ''
else:
source_el.setAttribute('aria-invalid', 'false')
table_el = document.createElement('table')
table_el.innerHTML = table_content
table_el.classList.add('ms-table')
output_el.innerHTML = ''
output_el.appendChild(table_el)
do_check()
def manage_update(e):
do_update(e.target.value)
source_el.addEventListener('input', create_proxy(manage_update))
source_el.addEventListener('propertychange', create_proxy(manage_update))
def manage_check(e):
do_check()
check_el.addEventListener('input', create_proxy(manage_check))
check_el.addEventListener('propertychange', create_proxy(manage_check))
ex0_el.addEventListener('click', create_proxy(lambda e: set_spec(ex0_el.textContent)))
ex1_el.addEventListener('click', create_proxy(lambda e: set_spec(ex1_el.textContent)))
ex2_el.addEventListener('click', create_proxy(lambda e: set_spec(ex2_el.textContent)))
def set_spec(value):
source_el.value = value
do_update(value)
def set_vers(value):
check_el.value = value
vers = get_url_param('vers')
vers = vers if vers else '1.2.1'
set_vers(vers)
spec = get_url_param('spec')
spec = spec if spec else '~=1.2'
set_spec(spec)
source_el.focus()
body_el = document.getElementsByTagName('html')[0]
body_el.className += ' is-loaded'
</py-script>
</body>
</html>