~repos /atoms-element

#js

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.


ae18b336 Peter John

4 years ago
fix example
element.js CHANGED
@@ -423,7 +423,7 @@ export class AtomsElement extends BaseElement {
423
423
  }
424
424
  }
425
425
 
426
- const createElement = ({ name, attrTypes, stateTypes, computedTypes, styles, render }) => {
426
+ export const createElement = ({ name, attrTypes, stateTypes, computedTypes, styles, render }) => {
427
427
  const Element = class extends AtomsElement {
428
428
  static name = name();
429
429
 
@@ -449,5 +449,3 @@ const createElement = ({ name, attrTypes, stateTypes, computedTypes, styles, ren
449
449
  Element.register();
450
450
  return { name, attrTypes, stateTypes, computedTypes, styles, render };
451
451
  };
452
-
453
- export default createElement;
example/app-counter.js CHANGED
@@ -1,4 +1,4 @@
1
- import createElement, { html, css, object, number, string } from '../element.js';
1
+ import { createElement, html, css, object, number, string } from '../element.js';
2
2
 
3
3
  const name = () => 'app-counter';
4
4
 
@@ -25,28 +25,27 @@ const computedTypes = () => ({
25
25
 
26
26
  const styles = css({
27
27
  title: {
28
- fontSize: '24px',
28
+ fontSize: '20px',
29
29
  marginBottom: '0.5rem',
30
+ textAlign: 'center',
31
+ },
32
+ span: {
33
+ fontSize: '16px',
30
34
  },
31
35
  container: {
32
36
  display: 'flex',
33
37
  flex: 1,
34
38
  flexDirection: 'row',
35
39
  fontSize: '32px',
36
- color: 'gray',
40
+ color: 'rgba(55, 65, 81, 1)',
37
41
  },
38
42
  mx: {
39
- marginLeft: '40px',
43
+ marginLeft: '5rem',
40
- marginRight: '40px',
44
+ marginRight: '5rem',
45
+ fontSize: '30px',
46
+ fontFamily: `ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace`,
41
47
  },
42
48
  button: {
43
- // margin: 0,
44
- // padding: 0,
45
- // cursor: 'pointer',
46
- // backgroundImage: 'none',
47
- // '-webkitAppearance': 'button',
48
- // textTransform: 'none',
49
- // fontSize: '100%',
50
49
  paddingTop: '0.5rem',
51
50
  paddingBottom: '0.5rem',
52
51
  paddingLeft: '1rem',
@@ -58,21 +57,26 @@ const styles = css({
58
57
  });
59
58
 
60
59
  const render = ({ attrs, state, computed }) => {
61
- const { name } = attrs;
60
+ const { name, meta } = attrs;
62
61
  const { count, setCount } = state;
63
62
  const { sum } = computed;
64
63
 
65
64
  return html`
66
65
  <div>
66
+ <div class=${styles.title}>
67
+ Counter: ${name}
67
- <div class=${styles.title}>Counter: ${name}</div>
68
+ <span class=${styles.span}>starts at ${meta?.start}</span>
69
+ </div>
68
70
  <div class=${styles.container}>
69
71
  <button class=${styles.button} @click=${() => setCount((v) => v - 1)}>-</button>
70
72
  <div class=${styles.mx}>
71
73
  <h1>${count}</h1>
72
- <h1>${sum}</h1>
73
74
  </div>
74
75
  <button class=${styles.button} @click=${() => setCount((v) => v + 1)}>+</button>
75
76
  </div>
77
+ <div class=${styles.mx}>
78
+ <h1>Sum: ${sum}</h1>
79
+ </div>
76
80
  </div>
77
81
  `;
78
82
  };
example/index.js CHANGED
@@ -1,23 +1,30 @@
1
1
  import { html, css } from '../element.js';
2
- import createPage from '../page.js';
2
+ import { createPage } from '../page.js';
3
3
  import './app-counter.js';
4
4
 
5
5
  const route = () => {
6
6
  return '/counter';
7
7
  };
8
8
 
9
- const styles = () => css({});
9
+ const styles = css({
10
+ center: {
11
+ display: 'flex',
12
+ flex: 1,
13
+ alignItems: 'center',
14
+ justifyContent: 'center',
15
+ },
16
+ });
10
17
 
11
18
  const head = ({ config }) => {
12
19
  return html`
13
20
  <title>${config.title}</title>
14
- <link href="/modern-normalize.css" rel="stylesheet" as="style" />
21
+ <link href="/styles.css" rel="stylesheet" as="style" />
15
22
  `;
16
23
  };
17
24
 
18
25
  const body = () => {
19
26
  return html`
20
- <div>
27
+ <div class=${styles.center}>
21
28
  <app-counter name="1" meta="{'start': 5}"></app-counter>
22
29
  </div>
23
30
  `;
example/modern-normalize.css DELETED
@@ -1,271 +0,0 @@
1
- /*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */
2
-
3
- /*
4
- Document
5
- ========
6
- */
7
-
8
- /**
9
- Use a better box model (opinionated).
10
- */
11
-
12
- *,
13
- ::before,
14
- ::after {
15
- box-sizing: border-box;
16
- }
17
-
18
- /**
19
- 1. Correct the line height in all browsers.
20
- 2. Prevent adjustments of font size after orientation changes in iOS.
21
- 3. Use a more readable tab size (opinionated).
22
- */
23
-
24
- html {
25
- line-height: 1.15; /* 1 */
26
- -webkit-text-size-adjust: 100%; /* 2 */
27
- -moz-tab-size: 4; /* 3 */
28
- tab-size: 4; /* 3 */
29
- }
30
-
31
- /*
32
- Sections
33
- ========
34
- */
35
-
36
- /**
37
- 1. Remove the margin in all browsers.
38
- 2. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
39
- */
40
-
41
- body {
42
- margin: 0; /* 1 */
43
- font-family: system-ui, -apple-system, /* Firefox supports this but not yet system-ui */ 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji',
44
- 'Segoe UI Emoji'; /* 2 */
45
- }
46
-
47
- /*
48
- Grouping content
49
- ================
50
- */
51
-
52
- /**
53
- 1. Add the correct height in Firefox.
54
- 2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)
55
- */
56
-
57
- hr {
58
- height: 0; /* 1 */
59
- color: inherit; /* 2 */
60
- }
61
-
62
- /*
63
- Text-level semantics
64
- ====================
65
- */
66
-
67
- /**
68
- Add the correct text decoration in Chrome, Edge, and Safari.
69
- */
70
-
71
- abbr[title] {
72
- text-decoration: underline dotted;
73
- }
74
-
75
- /**
76
- Add the correct font weight in Edge and Safari.
77
- */
78
-
79
- b,
80
- strong {
81
- font-weight: bolder;
82
- }
83
-
84
- /**
85
- 1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
86
- 2. Correct the odd 'em' font sizing in all browsers.
87
- */
88
-
89
- code,
90
- kbd,
91
- samp,
92
- pre {
93
- font-family: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace; /* 1 */
94
- font-size: 1em; /* 2 */
95
- }
96
-
97
- /**
98
- Add the correct font size in all browsers.
99
- */
100
-
101
- small {
102
- font-size: 80%;
103
- }
104
-
105
- /**
106
- Prevent 'sub' and 'sup' elements from affecting the line height in all browsers.
107
- */
108
-
109
- sub,
110
- sup {
111
- font-size: 75%;
112
- line-height: 0;
113
- position: relative;
114
- vertical-align: baseline;
115
- }
116
-
117
- sub {
118
- bottom: -0.25em;
119
- }
120
-
121
- sup {
122
- top: -0.5em;
123
- }
124
-
125
- /*
126
- Tabular data
127
- ============
128
- */
129
-
130
- /**
131
- 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)
132
- 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)
133
- */
134
-
135
- table {
136
- text-indent: 0; /* 1 */
137
- border-color: inherit; /* 2 */
138
- }
139
-
140
- /*
141
- Forms
142
- =====
143
- */
144
-
145
- /**
146
- 1. Change the font styles in all browsers.
147
- 2. Remove the margin in Firefox and Safari.
148
- */
149
-
150
- button,
151
- input,
152
- optgroup,
153
- select,
154
- textarea {
155
- font-family: inherit; /* 1 */
156
- font-size: 100%; /* 1 */
157
- line-height: 1.15; /* 1 */
158
- margin: 0; /* 2 */
159
- }
160
-
161
- /**
162
- Remove the inheritance of text transform in Edge and Firefox.
163
- */
164
-
165
- button,
166
- select {
167
- text-transform: none;
168
- }
169
-
170
- /**
171
- Correct the inability to style clickable types in iOS and Safari.
172
- */
173
-
174
- button,
175
- [type='button'],
176
- [type='reset'],
177
- [type='submit'] {
178
- -webkit-appearance: button;
179
- }
180
-
181
- /**
182
- Remove the inner border and padding in Firefox.
183
- */
184
-
185
- ::-moz-focus-inner {
186
- border-style: none;
187
- padding: 0;
188
- }
189
-
190
- /**
191
- Restore the focus styles unset by the previous rule.
192
- */
193
-
194
- :-moz-focusring {
195
- outline: 1px dotted ButtonText;
196
- }
197
-
198
- /**
199
- Remove the additional ':invalid' styles in Firefox.
200
- See: https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737
201
- */
202
-
203
- :-moz-ui-invalid {
204
- box-shadow: none;
205
- }
206
-
207
- /**
208
- Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers.
209
- */
210
-
211
- legend {
212
- padding: 0;
213
- }
214
-
215
- /**
216
- Add the correct vertical alignment in Chrome and Firefox.
217
- */
218
-
219
- progress {
220
- vertical-align: baseline;
221
- }
222
-
223
- /**
224
- Correct the cursor style of increment and decrement buttons in Safari.
225
- */
226
-
227
- ::-webkit-inner-spin-button,
228
- ::-webkit-outer-spin-button {
229
- height: auto;
230
- }
231
-
232
- /**
233
- 1. Correct the odd appearance in Chrome and Safari.
234
- 2. Correct the outline style in Safari.
235
- */
236
-
237
- [type='search'] {
238
- -webkit-appearance: textfield; /* 1 */
239
- outline-offset: -2px; /* 2 */
240
- }
241
-
242
- /**
243
- Remove the inner padding in Chrome and Safari on macOS.
244
- */
245
-
246
- ::-webkit-search-decoration {
247
- -webkit-appearance: none;
248
- }
249
-
250
- /**
251
- 1. Correct the inability to style clickable types in iOS and Safari.
252
- 2. Change font properties to 'inherit' in Safari.
253
- */
254
-
255
- ::-webkit-file-upload-button {
256
- -webkit-appearance: button; /* 1 */
257
- font: inherit; /* 2 */
258
- }
259
-
260
- /*
261
- Interactive
262
- ===========
263
- */
264
-
265
- /*
266
- Add the correct display in Chrome and Safari.
267
- */
268
-
269
- summary {
270
- display: list-item;
271
- }
example/{main.js → server.js} RENAMED
@@ -11,7 +11,7 @@ const port = process.argv[2] || 3000;
11
11
  const map = {
12
12
  '/element.js': `${__dirname}/../element.js`,
13
13
  '/lit-html.js': `${__dirname}/../lit-html.js`,
14
- '/modern-normalize.css': `${__dirname}/modern-normalize.css`,
14
+ '/styles.css': `${__dirname}/styles.css`,
15
15
  '/app-counter.js': `${__dirname}/app-counter.js`,
16
16
  '.js': 'text/javascript',
17
17
  '.css': 'text/css',
example/styles.css ADDED
@@ -0,0 +1,569 @@
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
+ /* font-size: 1rem; */
561
+ /* line-height: 1.5rem; */
562
+ line-height: 1.4;
563
+ font-weight: 400;
564
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
565
+ color: rgba(44, 62, 80, 1);
566
+ direction: ltr;
567
+ font-synthesis: none;
568
+ text-rendering: optimizeLegibility;
569
+ }
package.json CHANGED
@@ -33,7 +33,7 @@
33
33
  "node": ">=14.0.0"
34
34
  },
35
35
  "scripts": {
36
- "example": "node example/main.js",
36
+ "example": "node example/server.js",
37
37
  "test": "NODE_OPTIONS=--experimental-vm-modules jest"
38
38
  },
39
39
  "devDependencies": {
page.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import parse5 from 'parse5';
2
2
  import { AtomsElement, render } from './element.js';
3
3
 
4
- const find = (node) => {
4
+ export const find = (node) => {
5
5
  for (const child of node.childNodes) {
6
6
  if (AtomsElement.getElement(child.tagName)) {
7
7
  const Clazz = AtomsElement.getElement(child.tagName);
@@ -16,20 +16,19 @@ const find = (node) => {
16
16
  }
17
17
  };
18
18
 
19
- const ssr = (template) => {
19
+ export const ssr = (template) => {
20
20
  const text = render(template);
21
21
  const h = parse5.parseFragment(text);
22
22
  find(h);
23
23
  return parse5.serialize(h);
24
24
  };
25
25
 
26
- const createPage = ({ route, datapaths, head, body, styles }) => {
26
+ export const createPage = ({ route, datapaths, head, body, styles }) => {
27
27
  return ({ config, data, item, headScript, bodyScript }) => {
28
28
  const isProd = process.env.NODE_ENV === 'production';
29
29
  const props = { config, data, item };
30
30
  const headHtml = ssr(head(props));
31
31
  const bodyHtml = ssr(body(props));
32
- const stylesCss = styles(props);
33
32
  return `
34
33
  <!DOCTYPE html>
35
34
  <html lang="${config.lang}">
@@ -42,7 +41,7 @@ const createPage = ({ route, datapaths, head, body, styles }) => {
42
41
  <link rel="icon" type="image/png" href="/assets/icon.png" />
43
42
  ${headHtml}
44
43
  <style>
45
- ${stylesCss.toString()}
44
+ ${styles.toString()}
46
45
  </style>
47
46
  ${headScript}
48
47
  </head>
@@ -60,5 +59,3 @@ const createPage = ({ route, datapaths, head, body, styles }) => {
60
59
  `;
61
60
  };
62
61
  };
63
-
64
- export default createPage;