-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.ts
323 lines (293 loc) · 8.77 KB
/
main.ts
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
import { serve } from "https://deno.land/std@0.152.0/http/server.ts";
import { join } from "https://deno.land/std@0.152.0/path/mod.ts";
import { contentType } from "https://deno.land/std@0.152.0/media_types/mod.ts";
import template from "./src/flora.ts";
import { Route, Framework } from "./src/types.ts";
import frameworks from "./src/frameworks.ts";
class StaticFileHandler {
#basePath: string = "";
constructor(base: string) {
this.#basePath = base;
}
handler(request: Request): Response {
const pathname = new URL(request.url).pathname;
const extension = pathname.substr(pathname.lastIndexOf("."));
const resolvedPathname = (pathname == "" || pathname == "/") ? "/index.html" : pathname;
const path = join(Deno.cwd(), this.#basePath, resolvedPathname)
const file = Deno.readFile(path)
.then(data => new Response(data, { status: 200, headers: { 'content-type': contentType(extension) } })) // Need to think about content tyoes.
.catch(_ => new Response("Not found", { status: 404 }));
return file;
}
get pattern(): URLPattern {
return new URLPattern({ pathname: "*" })
}
}
const render = (currentFramework) => {
return template`<html>
<head>
<title>Compare Classless CSS frameworks — currently using "${frameworks[currentFramework].name}"</title>
<link rel="stylesheet" href="${frameworks[currentFramework].cssUrl.toString()}">
<meta name="author" content="Paul Kinlan">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="author" href="https://paul.kinlan.me/">
<meta name="google-site-verification" content="4rYZNKo8v8hiEOKIwXZDVD8qRyfs5QCGwCtD1_6Vw5g" />
</head>
<body>
<h1>Welcome to Classless CSS Demo using "<a href="${frameworks[currentFramework].siteUrl}">${frameworks[currentFramework].name}</a>"</h1>
<p>I was struggling to make a simple page I was building look decent.
I knew there were stylesheets that just used 'semantic html' (like Tufte) and didn't require any special class names
(i.e <code><button class="btn-primary">a button</button></code>), however I was struggling to find them.
</p>
<p>So I asked <a href="https://twitter.com/Paul_Kinlan/status/1560769014787411969">Twitter</a>:</p>
<blockquote>I should know this, but I'm looking for a simple CSS stylesheet that would replace the default user agent
and make it look half decent. Google-fu is failing me, all I can find is resets and full frameworks. :\\
</blockquote>
<p>Once I found examples of 'class-less CSS', it was then a bit of a pain to find them and compare all the different
examples. Hence this page.</p>
<p>This page is designed to collate all the CSS frameworks into one place and let you compare and contrast them.</p>
<p>Here is the list of class-less CSS frameworks that you can checkout:</p>
<ul>
${Object.values(frameworks).map(framework => template`<li><a href="${framework.htmlUrl}">${framework.name}</a> - <a
href="${framework.siteUrl}">homepage</a></li>`)}
</ul>
<p>If you have a framework you would like include, create PR against <a
href="https://github.com/PaulKinlan/classless-css-demo/blob/main/src/frameworks.ts">frameworks.ts</a></p>
<p><a href="https://paul.kinlan.me/">Check out my other site.</a></p>
<hr>
<p>This page is rendered using ${frameworks[currentFramework].name}.</p>
<p>Some of the entries are taken from the layout from <a
href="https://vasanthv.com/stylize.css/demo.html">stylize</a>.
</p>
<h2>Typography:</h2>
<h1>This is a H1 heading</h1>
<h2>This is a H2 heading</h2>
<h3>This is a H3 heading</h3>
<h4>This is a H4 heading</h4>
<h5>This is a H5 heading</h5>
<h6>This is a H6 heading</h6>
<p>This is a paragraph of text. It's my paragraph. I like it a lot.</p>
<br>
<strong>This is a Strong / Bold text</strong>
<br>
<i>This is an Emphasized / Italic text</i>
<br>
This is a <mark>Marked / Highlighted</mark> text
<br>
<small>This is a Small text</small>
<br>
This is a <del>Deleted</del> text
<br>
This is a <ins>Underlined / Inserted</ins> text
<br>
This is a <sub>Subscript</sub> text
<br>
This is a <sup>Superscript</sup> text
<br>
<pre>This is a preformatted text.</pre>
<blockquote>This is a Blockquote.</blockquote>
<aside>
Use an <code>aside</code> to emphasize a content related to the main content.
</aside>
<samp>This is a sample output.</samp>
<br>
This is the <code><code></code> & <kbd>kbd</kbd>
<br>
<h3>Links & navigation:</h3>
<nav>
<a href="#">Nav Link 1</a>
<a href="#">Nav Link 2</a>
<div class="right">
<a href="#">Nav Link 3</a>
</div>
</nav>
<br>
<br>
<a href="#">Normal link</a>
<hr>
<h2>Lists:</h2>
<ul>
<li>Unordered list item 1</li>
<li>Unordered list item 2</li>
<ul>
<li>Unordered list item 3</li>
</ul>
<li>Unordered list item 4</li>
<li>Unordered list item 5</li>
</ul>
<ol>
<li>Ordered list item 1</li>
<li>Ordered list item 2</li>
<ol>
<li>Ordered list item 3</li>
</ol>
<li>Ordered list item 4</li>
<li>Ordered list item 5</li>
</ol>
<dl>
<dt>Banana</dt>
<dd>A yellow fruit that is easy to peel.</dd>
<dd>Which also grows on a tree.</dd>
<dt>Cashew</dt>
<dd>A tan nut without a peel.</dd>
<dt>Cherry</dt>
<dd>A red fruit that is hard to peel.</dd>
</dl>
<hr>
<h2>Form:</h2>
<fieldset>
<legend>This is a legend on fieldset</legend>
<form>
<br>
<label>Label:</label>
<input type="text" placeholder="Text field">
<br>
<label>Select box:</label>
<select>
<optgroup label="Option group">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</optgroup>
</select>
<br>
<label>Numeric Field:</label>
<input type="number" placeholder="Number" value="0">
<br>
<label>Checkboxes:</label>
<label>Option 1 <input type="checkbox" checked=""></label>
<label>Option 2 <input type="checkbox"></label>
<br>
<label>Radio buttons:</label>
<label>Yes <input type="radio" checked=""></label>
<label>No <input type="radio"></label>
<br>
<textarea placeholder="Textarea" rows="3" cols="50"></textarea>
<br>
<input type="submit" value="Submit button">
<input type="reset" value="Reset button">
</form>
</fieldset>
<br>
<button>Button</button>
<a href="javascript:void(0)" role="button">Anchor role=button</a>
<input type="button" value="Input type=button">
<button disabled="">Button</button>
<br>
<label>Progress bar</label>
<progress value="22" max="100"></progress>
<hr>
<h2>Table:</h2>
<table>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Username</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
<th>1</th>
<td>Vasanth</td>
<td>@vsnthv</td>
<td>Chennai, India</td>
</tr>
<tr>
<th>2</th>
<td>John</td>
<td>@john</td>
<td>USA</td>
</tr>
<tr>
<th>3</th>
<td>Chan</td>
<td>@chan</td>
<td>Hong Kong</td>
</tr>
</tbody>
</table>
<p>Table with <code>border=1</code></p>
<table border="1">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Username</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
<th>1</th>
<td>Vasanth</td>
<td>@vsnthv</td>
<td>Chennai, India</td>
</tr>
<tr>
<th>2</th>
<td>John</td>
<td>@john</td>
<td>USA</td>
</tr>
<tr>
<th>3</th>
<td>Chan</td>
<td>@chan</td>
<td>Hong Kong</td>
</tr>
</tbody>
</table>
<hr>
<h2>Images</h2>
<figure>
<img src="http://placekitten.com/g/900/500" alt="placeholder image 900 pixels wide by 500 pixels tall">
<figcaption>A photo placeholder text</figcaption>
</figure>
</body>
</html>`
.then(data => new Response(data, { status: 200, headers: { 'content-type': 'text/html' } }));
}
serve((req: Request) => {
const url = req.url;
const staticFiles = new StaticFileHandler('static');
let response: Response = new Response(new Response("Not found", { status: 404 }));
// Probably only needs to be a static site
const routes: Array<Route> = [
[
new URLPattern({ pathname: "/" }),
(request, patternResult) => {
console.log(window.location)
return render(""); // index
}
],
[
new URLPattern({ pathname: "/:framework.html" }),
(request, patternResult) => {
const pathname = new URL(request.url).pathname;
const { framework } = patternResult.pathname.groups;
if (framework == null) {
return new Response("Not found", { status: 404 })
}
return render(framework);
}
],
// Fall through.
[
staticFiles.pattern,
staticFiles.handler.bind(staticFiles)
]
];
for (const [pattern, handler] of routes) {
const patternResult = pattern.exec(url);
console.log(pattern, url, patternResult)
if (patternResult != null) {
// Find the first matching route.
const responseFromHandler = handler(req, patternResult);
response = responseFromHandler;
break;
}
}
return response;
});