~repos /atoms-element
git clone https://pyrossh.dev/repos/atoms-element.git
A simple web component library for defining your custom elements. It works on both client and server.
67e0dfd2
—
Peter John 4 years ago
add global styles
- element.js +38 -25
- element.test.js +32 -7
- example/index.js +3 -4
- example/server.js +6 -9
- example/styles.css +0 -567
- example/styles.js +121 -0
- page.js +1 -1
element.js
CHANGED
|
@@ -32,29 +32,38 @@ const murmur2 = (str) => {
|
|
|
32
32
|
const hyphenate = (s) => s.replace(/[A-Z]|^ms/g, '-$&').toLowerCase();
|
|
33
33
|
|
|
34
34
|
export const convertStyles = (prefix, obj, parentClassName, indent = '') => {
|
|
35
|
+
const isGlobal = parentClassName === '__global__';
|
|
35
|
-
const className = parentClassName || prefix + '-' + murmur2(JSON.stringify(obj)).toString(36);
|
|
36
|
+
const className = isGlobal ? '' : parentClassName || prefix + '-' + murmur2(JSON.stringify(obj)).toString(36);
|
|
36
|
-
const cssText = Object.keys(obj).reduce(
|
|
37
|
+
const cssText = Object.keys(obj).reduce(
|
|
38
|
+
(acc, key) => {
|
|
37
|
-
|
|
39
|
+
const value = obj[key];
|
|
38
|
-
|
|
40
|
+
if (typeof value === 'object') {
|
|
39
|
-
|
|
41
|
+
acc += '\n ' + indent + convertStyles(prefix, value, key, indent + ' ').cssText;
|
|
40
|
-
|
|
42
|
+
} else {
|
|
41
|
-
|
|
43
|
+
acc += ' ' + indent + hyphenate(key) + ': ' + value + ';\n';
|
|
42
|
-
|
|
44
|
+
}
|
|
43
|
-
|
|
45
|
+
return acc;
|
|
46
|
+
},
|
|
44
|
-
|
|
47
|
+
isGlobal ? '' : `${parentClassName ? '' : '.'}${className} {\n`,
|
|
48
|
+
);
|
|
45
|
-
return { className, cssText: cssText + `\n${indent}}` };
|
|
49
|
+
return { className, cssText: cssText + `\n${indent}${isGlobal ? '' : '}'}` };
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
export const css = (obj) => {
|
|
49
53
|
Object.keys(obj).forEach((key) => {
|
|
50
54
|
const value = obj[key];
|
|
55
|
+
if (key === '__global__') {
|
|
56
|
+
const { cssText } = convertStyles(key, value, '__global__');
|
|
57
|
+
obj[key] = cssText;
|
|
58
|
+
} else {
|
|
51
|
-
|
|
59
|
+
const { className, cssText } = convertStyles(key, value);
|
|
52
|
-
|
|
60
|
+
obj[key] = className;
|
|
53
|
-
|
|
61
|
+
obj[className] = cssText;
|
|
62
|
+
}
|
|
54
63
|
});
|
|
55
|
-
obj.
|
|
64
|
+
obj.render = () => {
|
|
56
65
|
return Object.keys(obj).reduce((acc, key) => {
|
|
57
|
-
acc += key.includes('-') ? obj[key] + '\n\n' : '';
|
|
66
|
+
acc += key.includes('-') || key === '__global__' ? obj[key] + '\n\n' : '';
|
|
58
67
|
return acc;
|
|
59
68
|
}, '');
|
|
60
69
|
};
|
|
@@ -408,17 +417,21 @@ export class AtomsElement extends BaseElement {
|
|
|
408
417
|
const template = this.render();
|
|
409
418
|
const result = render(template, this);
|
|
410
419
|
if (isBrowser) {
|
|
411
|
-
if (!this.stylesMounted) {
|
|
420
|
+
if (!this.stylesMounted && this.constructor.styles) {
|
|
412
|
-
this.appendChild(document.createElement('style')).textContent = this.constructor.styles.
|
|
421
|
+
this.appendChild(document.createElement('style')).textContent = this.constructor.styles.render();
|
|
413
422
|
this.stylesMounted = true;
|
|
414
423
|
}
|
|
415
424
|
} else {
|
|
425
|
+
if (this.constructor.styles) {
|
|
416
|
-
|
|
426
|
+
return `
|
|
417
|
-
|
|
427
|
+
${result}
|
|
418
|
-
|
|
428
|
+
<style>
|
|
419
|
-
|
|
429
|
+
${this.constructor.styles.render()}
|
|
420
|
-
|
|
430
|
+
</style>
|
|
421
|
-
|
|
431
|
+
`;
|
|
432
|
+
} else {
|
|
433
|
+
return result;
|
|
434
|
+
}
|
|
422
435
|
}
|
|
423
436
|
}
|
|
424
437
|
}
|
|
@@ -435,7 +448,7 @@ export const createElement = ({ name, attrTypes, stateTypes, computedTypes, styl
|
|
|
435
448
|
|
|
436
449
|
static computedTypes = computedTypes ? computedTypes() : {};
|
|
437
450
|
|
|
438
|
-
static styles = styles
|
|
451
|
+
static styles = styles;
|
|
439
452
|
|
|
440
453
|
constructor(ssrAttributes) {
|
|
441
454
|
super(ssrAttributes);
|
element.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect, test, jest } from '@jest/globals';
|
|
2
|
-
import { AtomsElement, html, render, number, boolean, string, array, object, unsafeHTML, css, classMap } from './element.js';
|
|
2
|
+
import { AtomsElement, html, render, number, boolean, string, array, object, unsafeHTML, css, classMap, createElement } from './element.js';
|
|
3
3
|
|
|
4
4
|
global.__DEV = true;
|
|
5
5
|
|
|
@@ -132,6 +132,11 @@ test('array', () => {
|
|
|
132
132
|
|
|
133
133
|
test('css', () => {
|
|
134
134
|
const styles = css({
|
|
135
|
+
__global__: {
|
|
136
|
+
html: {
|
|
137
|
+
fontSize: '16px',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
135
140
|
button: {
|
|
136
141
|
color: 'magenta',
|
|
137
142
|
fontSize: '10px',
|
|
@@ -153,7 +158,14 @@ test('css', () => {
|
|
|
153
158
|
justifyContent: 'center',
|
|
154
159
|
},
|
|
155
160
|
});
|
|
156
|
-
expect(styles.
|
|
161
|
+
expect(styles.render()).toEqual(`
|
|
162
|
+
html {
|
|
163
|
+
font-size: 16px;
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
.button-1t9ijgh {
|
|
157
169
|
color: magenta;
|
|
158
170
|
font-size: 10px;
|
|
159
171
|
|
|
@@ -346,7 +358,7 @@ test('AtomsElement', async () => {
|
|
|
346
358
|
expect(AppItem.observedAttributes).toEqual(['perpage', 'address']);
|
|
347
359
|
const res = instance.renderTemplate();
|
|
348
360
|
expect(res).toEqual(`
|
|
349
|
-
|
|
361
|
+
|
|
350
362
|
<div perPage="1">
|
|
351
363
|
<p>street: 123</p>
|
|
352
364
|
<p>count: 0</p>
|
|
@@ -354,13 +366,26 @@ test('AtomsElement', async () => {
|
|
|
354
366
|
<div><p>render item 1</p></div>
|
|
355
367
|
</div>
|
|
356
368
|
|
|
357
|
-
|
|
369
|
+
<style>
|
|
358
|
-
|
|
370
|
+
.div-1gao8uk {
|
|
359
371
|
color: red;
|
|
360
372
|
|
|
361
373
|
}
|
|
362
374
|
|
|
363
375
|
|
|
364
|
-
|
|
376
|
+
</style>
|
|
365
|
-
|
|
377
|
+
`);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test('createElement ', async () => {
|
|
381
|
+
createElement({
|
|
382
|
+
name: () => 'base-element',
|
|
383
|
+
render: () => {
|
|
384
|
+
return html` <div></div> `;
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
const Clazz = AtomsElement.getElement('base-element');
|
|
388
|
+
const instance = new Clazz();
|
|
389
|
+
const res = instance.renderTemplate();
|
|
390
|
+
expect(res).toEqual(` <div></div> `);
|
|
366
391
|
});
|
example/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { html, css } from '../element.js';
|
|
2
2
|
import { createPage } from '../page.js';
|
|
3
|
+
import { __global__ } from './styles.js';
|
|
3
4
|
import './app-counter.js';
|
|
4
5
|
|
|
5
6
|
const route = () => {
|
|
@@ -7,6 +8,7 @@ const route = () => {
|
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
const styles = css({
|
|
11
|
+
__global__,
|
|
10
12
|
center: {
|
|
11
13
|
display: 'flex',
|
|
12
14
|
flex: 1,
|
|
@@ -16,10 +18,7 @@ const styles = css({
|
|
|
16
18
|
});
|
|
17
19
|
|
|
18
20
|
const head = ({ config }) => {
|
|
19
|
-
return html`
|
|
20
|
-
|
|
21
|
+
return html` <title>${config.title}</title> `;
|
|
21
|
-
<link href="/styles.css" rel="stylesheet" as="style" />
|
|
22
|
-
`;
|
|
23
22
|
};
|
|
24
23
|
|
|
25
24
|
const body = () => {
|
example/server.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
|
-
import
|
|
4
|
+
import { dirname } from 'path';
|
|
5
5
|
import renderIndex from './index.js';
|
|
6
6
|
|
|
7
7
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
8
|
const __dirname = dirname(__filename);
|
|
9
9
|
|
|
10
10
|
const port = process.argv[2] || 3000;
|
|
11
|
-
const
|
|
11
|
+
const srcMap = {
|
|
12
12
|
'/element.js': `${__dirname}/../element.js`,
|
|
13
13
|
'/lit-html.js': `${__dirname}/../lit-html.js`,
|
|
14
|
-
'/styles.
|
|
14
|
+
'/styles.js': `${__dirname}/styles.js`,
|
|
15
15
|
'/app-counter.js': `${__dirname}/app-counter.js`,
|
|
16
|
-
'.js': 'text/javascript',
|
|
17
|
-
'.css': 'text/css',
|
|
18
16
|
};
|
|
19
17
|
|
|
20
18
|
http
|
|
@@ -34,12 +32,11 @@ http
|
|
|
34
32
|
res.end(html);
|
|
35
33
|
return;
|
|
36
34
|
}
|
|
37
|
-
const filename =
|
|
35
|
+
const filename = srcMap[req.url];
|
|
38
36
|
const data = fs.readFileSync(filename);
|
|
39
|
-
const ext = path.parse(filename).ext;
|
|
40
|
-
res.setHeader('Content-type',
|
|
37
|
+
res.setHeader('Content-type', 'application/javascript');
|
|
41
38
|
res.end(data);
|
|
42
39
|
})
|
|
43
40
|
.listen(parseInt(port));
|
|
44
41
|
|
|
45
|
-
console.log(`Server listening on
|
|
42
|
+
console.log(`Server listening on http://localhost:${port}`);
|
example/styles.css
DELETED
|
@@ -1,567 +0,0 @@
|
|
|
1
|
-
/*! tailwindcss v2.1.2 | MIT License | https://tailwindcss.com */
|
|
2
|
-
|
|
3
|
-
/*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
Document
|
|
7
|
-
========
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
Use a better box model (opinionated).
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
*,
|
|
15
|
-
::before,
|
|
16
|
-
::after {
|
|
17
|
-
box-sizing: border-box;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
Use a more readable tab size (opinionated).
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
html {
|
|
25
|
-
-moz-tab-size: 4;
|
|
26
|
-
-o-tab-size: 4;
|
|
27
|
-
tab-size: 4;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
1. Correct the line height in all browsers.
|
|
32
|
-
2. Prevent adjustments of font size after orientation changes in iOS.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
html {
|
|
36
|
-
line-height: 1.15; /* 1 */
|
|
37
|
-
-webkit-text-size-adjust: 100%; /* 2 */
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/*
|
|
41
|
-
Sections
|
|
42
|
-
========
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
Remove the margin in all browsers.
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
body {
|
|
50
|
-
margin: 0;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
|
|
55
|
-
*/
|
|
56
|
-
|
|
57
|
-
body {
|
|
58
|
-
font-family: system-ui, -apple-system, /* Firefox supports this but not yet `system-ui` */ 'Segoe UI', Roboto, Helvetica, Arial, sans-serif,
|
|
59
|
-
'Apple Color Emoji', 'Segoe UI Emoji';
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/*
|
|
63
|
-
Grouping content
|
|
64
|
-
================
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
1. Add the correct height in Firefox.
|
|
69
|
-
2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
hr {
|
|
73
|
-
height: 0; /* 1 */
|
|
74
|
-
color: inherit; /* 2 */
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/*
|
|
78
|
-
Text-level semantics
|
|
79
|
-
====================
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
Add the correct text decoration in Chrome, Edge, and Safari.
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
abbr[title] {
|
|
87
|
-
-webkit-text-decoration: underline dotted;
|
|
88
|
-
text-decoration: underline dotted;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
Add the correct font weight in Edge and Safari.
|
|
93
|
-
*/
|
|
94
|
-
|
|
95
|
-
b,
|
|
96
|
-
strong {
|
|
97
|
-
font-weight: bolder;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
|
|
102
|
-
2. Correct the odd 'em' font sizing in all browsers.
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
code,
|
|
106
|
-
kbd,
|
|
107
|
-
samp,
|
|
108
|
-
pre {
|
|
109
|
-
font-family: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace; /* 1 */
|
|
110
|
-
font-size: 1em; /* 2 */
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
Add the correct font size in all browsers.
|
|
115
|
-
*/
|
|
116
|
-
|
|
117
|
-
small {
|
|
118
|
-
font-size: 80%;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
Prevent 'sub' and 'sup' elements from affecting the line height in all browsers.
|
|
123
|
-
*/
|
|
124
|
-
|
|
125
|
-
sub,
|
|
126
|
-
sup {
|
|
127
|
-
font-size: 75%;
|
|
128
|
-
line-height: 0;
|
|
129
|
-
position: relative;
|
|
130
|
-
vertical-align: baseline;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
sub {
|
|
134
|
-
bottom: -0.25em;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
sup {
|
|
138
|
-
top: -0.5em;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/*
|
|
142
|
-
Tabular data
|
|
143
|
-
============
|
|
144
|
-
*/
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)
|
|
148
|
-
2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)
|
|
149
|
-
*/
|
|
150
|
-
|
|
151
|
-
table {
|
|
152
|
-
text-indent: 0; /* 1 */
|
|
153
|
-
border-color: inherit; /* 2 */
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/*
|
|
157
|
-
Forms
|
|
158
|
-
=====
|
|
159
|
-
*/
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
1. Change the font styles in all browsers.
|
|
163
|
-
2. Remove the margin in Firefox and Safari.
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
|
-
button,
|
|
167
|
-
input,
|
|
168
|
-
optgroup,
|
|
169
|
-
select,
|
|
170
|
-
textarea {
|
|
171
|
-
/* font-family: inherit; */ /* 1 */
|
|
172
|
-
font-size: 100%; /* 1 */
|
|
173
|
-
/* line-height: 1.15; */ /* 1 */
|
|
174
|
-
margin: 0; /* 2 */
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
Remove the inheritance of text transform in Edge and Firefox.
|
|
179
|
-
1. Remove the inheritance of text transform in Firefox.
|
|
180
|
-
*/
|
|
181
|
-
|
|
182
|
-
button,
|
|
183
|
-
select {
|
|
184
|
-
/* 1 */
|
|
185
|
-
/* text-transform: none; */
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
Correct the inability to style clickable types in iOS and Safari.
|
|
190
|
-
*/
|
|
191
|
-
|
|
192
|
-
button,
|
|
193
|
-
[type='button'],
|
|
194
|
-
[type='reset'],
|
|
195
|
-
[type='submit'] {
|
|
196
|
-
/* -webkit-appearance: button; */
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
Remove the inner border and padding in Firefox.
|
|
201
|
-
*/
|
|
202
|
-
|
|
203
|
-
::-moz-focus-inner {
|
|
204
|
-
border-style: none;
|
|
205
|
-
padding: 0;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
Restore the focus styles unset by the previous rule.
|
|
210
|
-
*/
|
|
211
|
-
|
|
212
|
-
:-moz-focusring {
|
|
213
|
-
outline: 1px dotted ButtonText;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
Remove the additional ':invalid' styles in Firefox.
|
|
218
|
-
See: https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737
|
|
219
|
-
*/
|
|
220
|
-
|
|
221
|
-
:-moz-ui-invalid {
|
|
222
|
-
box-shadow: none;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers.
|
|
227
|
-
*/
|
|
228
|
-
|
|
229
|
-
legend {
|
|
230
|
-
padding: 0;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
Add the correct vertical alignment in Chrome and Firefox.
|
|
235
|
-
*/
|
|
236
|
-
|
|
237
|
-
progress {
|
|
238
|
-
vertical-align: baseline;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
Correct the cursor style of increment and decrement buttons in Safari.
|
|
243
|
-
*/
|
|
244
|
-
|
|
245
|
-
::-webkit-inner-spin-button,
|
|
246
|
-
::-webkit-outer-spin-button {
|
|
247
|
-
height: auto;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
1. Correct the odd appearance in Chrome and Safari.
|
|
252
|
-
2. Correct the outline style in Safari.
|
|
253
|
-
*/
|
|
254
|
-
|
|
255
|
-
[type='search'] {
|
|
256
|
-
-webkit-appearance: textfield; /* 1 */
|
|
257
|
-
outline-offset: -2px; /* 2 */
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
Remove the inner padding in Chrome and Safari on macOS.
|
|
262
|
-
*/
|
|
263
|
-
|
|
264
|
-
::-webkit-search-decoration {
|
|
265
|
-
-webkit-appearance: none;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
1. Correct the inability to style clickable types in iOS and Safari.
|
|
270
|
-
2. Change font properties to 'inherit' in Safari.
|
|
271
|
-
*/
|
|
272
|
-
|
|
273
|
-
::-webkit-file-upload-button {
|
|
274
|
-
-webkit-appearance: button; /* 1 */
|
|
275
|
-
font: inherit; /* 2 */
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/*
|
|
279
|
-
Interactive
|
|
280
|
-
===========
|
|
281
|
-
*/
|
|
282
|
-
|
|
283
|
-
/*
|
|
284
|
-
Add the correct display in Chrome and Safari.
|
|
285
|
-
*/
|
|
286
|
-
|
|
287
|
-
summary {
|
|
288
|
-
display: list-item;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Manually forked from SUIT CSS Base: https://github.com/suitcss/base
|
|
293
|
-
* A thin layer on top of normalize.css that provides a starting point more
|
|
294
|
-
* suitable for web applications.
|
|
295
|
-
*/
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Removes the default spacing and border for appropriate elements.
|
|
299
|
-
*/
|
|
300
|
-
|
|
301
|
-
blockquote,
|
|
302
|
-
dl,
|
|
303
|
-
dd,
|
|
304
|
-
h1,
|
|
305
|
-
h2,
|
|
306
|
-
h3,
|
|
307
|
-
h4,
|
|
308
|
-
h5,
|
|
309
|
-
h6,
|
|
310
|
-
hr,
|
|
311
|
-
figure,
|
|
312
|
-
p,
|
|
313
|
-
pre {
|
|
314
|
-
margin: 0;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
button {
|
|
318
|
-
/* background-color: transparent; */
|
|
319
|
-
kground-image: none;
|
|
320
|
-
/* background-image: none; */
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Work around a Firefox/IE bug where the transparent `button` background
|
|
325
|
-
* results in a loss of the default `button` focus styles.
|
|
326
|
-
*/
|
|
327
|
-
|
|
328
|
-
button:focus {
|
|
329
|
-
outline: 1px dotted;
|
|
330
|
-
outline: 5px auto -webkit-focus-ring-color;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
fieldset {
|
|
334
|
-
margin: 0;
|
|
335
|
-
padding: 0;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
ol,
|
|
339
|
-
ul {
|
|
340
|
-
list-style: none;
|
|
341
|
-
margin: 0;
|
|
342
|
-
padding: 0;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Tailwind custom reset styles
|
|
347
|
-
*/
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* 1. Use the user's configured `sans` font-family (with Tailwind's default
|
|
351
|
-
* sans-serif font stack as a fallback) as a sane default.
|
|
352
|
-
* 2. Use Tailwind's default "normal" line-height so the user isn't forced
|
|
353
|
-
* to override it to ensure consistency even when using the default theme.
|
|
354
|
-
*/
|
|
355
|
-
|
|
356
|
-
html {
|
|
357
|
-
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif,
|
|
358
|
-
'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; /* 1 */
|
|
359
|
-
line-height: 1.5; /* 2 */
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Inherit font-family and line-height from `html` so users can set them as
|
|
364
|
-
* a class directly on the `html` element.
|
|
365
|
-
*/
|
|
366
|
-
|
|
367
|
-
body {
|
|
368
|
-
font-family: inherit;
|
|
369
|
-
line-height: inherit;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* 1. Prevent padding and border from affecting element width.
|
|
374
|
-
*
|
|
375
|
-
* We used to set this in the html element and inherit from
|
|
376
|
-
* the parent element for everything else. This caused issues
|
|
377
|
-
* in shadow-dom-enhanced elements like <details> where the content
|
|
378
|
-
* is wrapped by a div with box-sizing set to `content-box`.
|
|
379
|
-
*
|
|
380
|
-
* https://github.com/mozdevs/cssremedy/issues/4
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
* 2. Allow adding a border to an element by just adding a border-width.
|
|
384
|
-
*
|
|
385
|
-
* By default, the way the browser specifies that an element should have no
|
|
386
|
-
* border is by setting it's border-style to `none` in the user-agent
|
|
387
|
-
* stylesheet.
|
|
388
|
-
*
|
|
389
|
-
* In order to easily add borders to elements by just setting the `border-width`
|
|
390
|
-
* property, we change the default border-style for all elements to `solid`, and
|
|
391
|
-
* use border-width to hide them instead. This way our `border` utilities only
|
|
392
|
-
* need to set the `border-width` property instead of the entire `border`
|
|
393
|
-
* shorthand, making our border utilities much more straightforward to compose.
|
|
394
|
-
*
|
|
395
|
-
* https://github.com/tailwindcss/tailwindcss/pull/116
|
|
396
|
-
*/
|
|
397
|
-
|
|
398
|
-
*,
|
|
399
|
-
::before,
|
|
400
|
-
::after {
|
|
401
|
-
box-sizing: border-box; /* 1 */
|
|
402
|
-
border-width: 0; /* 2 */
|
|
403
|
-
border-style: solid; /* 2 */
|
|
404
|
-
border-color: #e5e7eb; /* 2 */
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/*
|
|
408
|
-
* Ensure horizontal rules are visible by default
|
|
409
|
-
*/
|
|
410
|
-
|
|
411
|
-
hr {
|
|
412
|
-
border-top-width: 1px;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Undo the `border-style: none` reset that Normalize applies to images so that
|
|
417
|
-
* our `border-{width}` utilities have the expected effect.
|
|
418
|
-
*
|
|
419
|
-
* The Normalize reset is unnecessary for us since we default the border-width
|
|
420
|
-
* to 0 on all elements.
|
|
421
|
-
*
|
|
422
|
-
* https://github.com/tailwindcss/tailwindcss/issues/362
|
|
423
|
-
*/
|
|
424
|
-
|
|
425
|
-
img {
|
|
426
|
-
border-style: solid;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
textarea {
|
|
430
|
-
resize: vertical;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
input::-moz-placeholder,
|
|
434
|
-
textarea::-moz-placeholder {
|
|
435
|
-
opacity: 1;
|
|
436
|
-
color: #9ca3af;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
input:-ms-input-placeholder,
|
|
440
|
-
textarea:-ms-input-placeholder {
|
|
441
|
-
opacity: 1;
|
|
442
|
-
color: #9ca3af;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
input::placeholder,
|
|
446
|
-
textarea::placeholder {
|
|
447
|
-
opacity: 1;
|
|
448
|
-
color: #9ca3af;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
button,
|
|
452
|
-
[role='button'] {
|
|
453
|
-
cursor: pointer;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
table {
|
|
457
|
-
border-collapse: collapse;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
h1,
|
|
461
|
-
h2,
|
|
462
|
-
h3,
|
|
463
|
-
h4,
|
|
464
|
-
h5,
|
|
465
|
-
h6 {
|
|
466
|
-
font-size: inherit;
|
|
467
|
-
font-weight: inherit;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* Reset links to optimize for opt-in styling instead of
|
|
472
|
-
* opt-out.
|
|
473
|
-
*/
|
|
474
|
-
|
|
475
|
-
a {
|
|
476
|
-
color: inherit;
|
|
477
|
-
text-decoration: inherit;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* Reset form element properties that are easy to forget to
|
|
482
|
-
* style explicitly so you don't inadvertently introduce
|
|
483
|
-
* styles that deviate from your design system. These styles
|
|
484
|
-
* supplement a partial reset that is already applied by
|
|
485
|
-
* normalize.css.
|
|
486
|
-
*/
|
|
487
|
-
|
|
488
|
-
button,
|
|
489
|
-
input,
|
|
490
|
-
optgroup,
|
|
491
|
-
select,
|
|
492
|
-
textarea {
|
|
493
|
-
padding: 0;
|
|
494
|
-
line-height: inherit;
|
|
495
|
-
color: inherit;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* Use the configured 'mono' font family for elements that
|
|
500
|
-
* are expected to be rendered with a monospace font, falling
|
|
501
|
-
* back to the system monospace stack if there is no configured
|
|
502
|
-
* 'mono' font family.
|
|
503
|
-
*/
|
|
504
|
-
|
|
505
|
-
pre,
|
|
506
|
-
code,
|
|
507
|
-
kbd,
|
|
508
|
-
samp {
|
|
509
|
-
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* Make replaced elements `display: block` by default as that's
|
|
514
|
-
* the behavior you want almost all of the time. Inspired by
|
|
515
|
-
* CSS Remedy, with `svg` added as well.
|
|
516
|
-
*
|
|
517
|
-
* https://github.com/mozdevs/cssremedy/issues/14
|
|
518
|
-
*/
|
|
519
|
-
|
|
520
|
-
img,
|
|
521
|
-
svg,
|
|
522
|
-
video,
|
|
523
|
-
canvas,
|
|
524
|
-
audio,
|
|
525
|
-
iframe,
|
|
526
|
-
embed,
|
|
527
|
-
object {
|
|
528
|
-
display: block;
|
|
529
|
-
vertical-align: middle;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* Constrain images and videos to the parent width and preserve
|
|
534
|
-
* their intrinsic aspect ratio.
|
|
535
|
-
*
|
|
536
|
-
* https://github.com/mozdevs/cssremedy/issues/14
|
|
537
|
-
*/
|
|
538
|
-
|
|
539
|
-
img,
|
|
540
|
-
video {
|
|
541
|
-
max-width: 100%;
|
|
542
|
-
height: auto;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
html {
|
|
546
|
-
width: 100%;
|
|
547
|
-
height: 100%;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
body {
|
|
551
|
-
background-color: white;
|
|
552
|
-
width: 100%;
|
|
553
|
-
height: 100%;
|
|
554
|
-
display: flex;
|
|
555
|
-
flex-direction: column;
|
|
556
|
-
flex: 1 1 0%;
|
|
557
|
-
min-width: 320px;
|
|
558
|
-
margin: 0px;
|
|
559
|
-
min-height: 100vh;
|
|
560
|
-
line-height: 1.4;
|
|
561
|
-
font-weight: 400;
|
|
562
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
|
|
563
|
-
color: rgba(44, 62, 80, 1);
|
|
564
|
-
direction: ltr;
|
|
565
|
-
font-synthesis: none;
|
|
566
|
-
text-rendering: optimizeLegibility;
|
|
567
|
-
}
|
example/styles.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export const __global__ = {
|
|
2
|
+
'*, ::before, ::after': {
|
|
3
|
+
boxSizing: 'border-box',
|
|
4
|
+
borderWidth: '0',
|
|
5
|
+
borderStyle: 'solid',
|
|
6
|
+
borderColor: '#e5e7eb',
|
|
7
|
+
},
|
|
8
|
+
hr: { height: '0', color: 'inherit', borderTopWidth: '1px' },
|
|
9
|
+
'abbr[title]': {
|
|
10
|
+
WebkitTextDecoration: 'underline dotted',
|
|
11
|
+
textDecoration: 'underline dotted',
|
|
12
|
+
},
|
|
13
|
+
'b, strong': { fontWeight: 'bolder' },
|
|
14
|
+
'code, kbd, samp, pre': {
|
|
15
|
+
fontFamily: "ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace",
|
|
16
|
+
fontSize: '1em',
|
|
17
|
+
},
|
|
18
|
+
small: { fontSize: '80%' },
|
|
19
|
+
'sub, sup': {
|
|
20
|
+
fontSize: '75%',
|
|
21
|
+
lineHeight: 0,
|
|
22
|
+
position: 'relative',
|
|
23
|
+
verticalAlign: 'baseline',
|
|
24
|
+
},
|
|
25
|
+
sub: { bottom: '-0.25em' },
|
|
26
|
+
sup: { top: '-0.5em' },
|
|
27
|
+
table: {
|
|
28
|
+
textIndent: '0',
|
|
29
|
+
borderColor: 'inherit',
|
|
30
|
+
borderCollapse: 'collapse',
|
|
31
|
+
},
|
|
32
|
+
'button, input, optgroup, select, textarea': {
|
|
33
|
+
fontSize: '100%',
|
|
34
|
+
margin: '0',
|
|
35
|
+
padding: '0',
|
|
36
|
+
lineHeight: 'inherit',
|
|
37
|
+
color: 'inherit',
|
|
38
|
+
},
|
|
39
|
+
'button, select': {},
|
|
40
|
+
"button, [type='button'], [type='reset'], [type='submit']": {},
|
|
41
|
+
'::-moz-focus-inner': { borderStyle: 'none', padding: '0' },
|
|
42
|
+
':-moz-focusring': { outline: '1px dotted ButtonText' },
|
|
43
|
+
':-moz-ui-invalid': { boxShadow: 'none' },
|
|
44
|
+
legend: { padding: '0' },
|
|
45
|
+
progress: { verticalAlign: 'baseline' },
|
|
46
|
+
'::-webkit-inner-spin-button, ::-webkit-outer-spin-button': {
|
|
47
|
+
height: 'auto',
|
|
48
|
+
},
|
|
49
|
+
"[type='search']": { WebkitAppearance: 'textfield', outlineOffset: '-2px' },
|
|
50
|
+
'::-webkit-search-decoration': { WebkitAppearance: 'none' },
|
|
51
|
+
'::-webkit-file-upload-button': {
|
|
52
|
+
WebkitAppearance: 'button',
|
|
53
|
+
font: 'inherit',
|
|
54
|
+
},
|
|
55
|
+
summary: { display: 'list-item' },
|
|
56
|
+
'blockquote, dl, dd, h1, h2, h3, h4, h5, h6, hr, figure, p, pre': {
|
|
57
|
+
margin: '0',
|
|
58
|
+
},
|
|
59
|
+
button: {
|
|
60
|
+
backgroundImage: 'none',
|
|
61
|
+
':focus': {
|
|
62
|
+
outline: '1px dotted, 5px auto -webkit-focus-ring-color',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
fieldset: { margin: '0', padding: '0' },
|
|
66
|
+
'ol, ul': { listStyle: 'none', margin: '0', padding: '0' },
|
|
67
|
+
img: { borderStyle: 'solid' },
|
|
68
|
+
textarea: { resize: 'vertical' },
|
|
69
|
+
'input::-moz-placeholder, textarea::-moz-placeholder': {
|
|
70
|
+
opacity: 1,
|
|
71
|
+
color: '#9ca3af',
|
|
72
|
+
},
|
|
73
|
+
'input:-ms-input-placeholder, textarea:-ms-input-placeholder': {
|
|
74
|
+
opacity: 1,
|
|
75
|
+
color: '#9ca3af',
|
|
76
|
+
},
|
|
77
|
+
'input::placeholder, textarea::placeholder': {
|
|
78
|
+
opacity: 1,
|
|
79
|
+
color: '#9ca3af',
|
|
80
|
+
},
|
|
81
|
+
"button, [role='button']": { cursor: 'pointer' },
|
|
82
|
+
'h1, h2, h3, h4, h5, h6': { fontSize: 'inherit', fontWeight: 'inherit' },
|
|
83
|
+
a: { color: 'inherit', textDecoration: 'inherit' },
|
|
84
|
+
'pre, code, kbd, samp': {
|
|
85
|
+
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace",
|
|
86
|
+
},
|
|
87
|
+
'img, svg, video, canvas, audio, iframe, embed, object': {
|
|
88
|
+
display: 'block',
|
|
89
|
+
verticalAlign: 'middle',
|
|
90
|
+
},
|
|
91
|
+
'img, video': { maxWidth: '100%', height: 'auto' },
|
|
92
|
+
html: {
|
|
93
|
+
MozTabSize: '4',
|
|
94
|
+
OTabSize: '4',
|
|
95
|
+
tabSize: 4,
|
|
96
|
+
lineHeight: 1.5,
|
|
97
|
+
WebkitTextSizeAdjust: '100%',
|
|
98
|
+
fontFamily:
|
|
99
|
+
"ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'",
|
|
100
|
+
width: '100%',
|
|
101
|
+
height: '100%',
|
|
102
|
+
},
|
|
103
|
+
body: {
|
|
104
|
+
margin: '0px',
|
|
105
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif",
|
|
106
|
+
lineHeight: 1.4,
|
|
107
|
+
backgroundColor: 'white',
|
|
108
|
+
width: '100%',
|
|
109
|
+
height: '100%',
|
|
110
|
+
display: 'flex',
|
|
111
|
+
flexDirection: 'column',
|
|
112
|
+
flex: '1 1 0%',
|
|
113
|
+
minWidth: '320px',
|
|
114
|
+
minHeight: '100vh',
|
|
115
|
+
fontWeight: 400,
|
|
116
|
+
color: 'rgba(44, 62, 80, 1)',
|
|
117
|
+
direction: 'ltr',
|
|
118
|
+
fontSynthesis: 'none',
|
|
119
|
+
textRendering: 'optimizeLegibility',
|
|
120
|
+
},
|
|
121
|
+
};
|
page.js
CHANGED
|
@@ -41,7 +41,7 @@ export const createPage = ({ route, datapaths, head, body, styles }) => {
|
|
|
41
41
|
<link rel="icon" type="image/png" href="/assets/icon.png" />
|
|
42
42
|
${headHtml}
|
|
43
43
|
<style>
|
|
44
|
-
${styles.
|
|
44
|
+
${styles.render()}
|
|
45
45
|
</style>
|
|
46
46
|
${headScript}
|
|
47
47
|
</head>
|