beercss 2.0.31 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/cdn/beer.js CHANGED
@@ -1,4 +1,11 @@
1
1
  (() => {
2
+ let _timeout = null;
3
+ let _mutation = null;
4
+ let _lastTheme = {
5
+ light: '',
6
+ dark: ''
7
+ };
8
+
2
9
  const guid = () => {
3
10
  return "fxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
4
11
  let r = (Math.random() * 16) | 0,
@@ -141,6 +148,11 @@
141
148
  updateFile(e.currentTarget, e);
142
149
  }
143
150
 
151
+ const onMutation = () => {
152
+ if (_timeout) clearTimeout(_timeout);
153
+ _timeout = setTimeout(ui, 180);
154
+ }
155
+
144
156
  const updateFile = (target, e) => {
145
157
  if (e) {
146
158
  if (e.key !== "Enter") return;
@@ -233,8 +245,8 @@
233
245
 
234
246
  let isActive = hasClass(to, "active");
235
247
  let container = parent(to);
236
- if (hasClass(container, "menu")) {
237
- let elements = queryAll(".menu > .modal, .menu > a, .menu > .overlay");
248
+ if (/nav/i.test(container.tagName)) {
249
+ let elements = queryAll(".modal, a, .overlay", container);
238
250
  elements.forEach((x) => {
239
251
  removeClass(x, "active");
240
252
  });
@@ -286,55 +298,78 @@
286
298
  return to.style.clipPath = `polygon(0% 100%, 100% 100%, 100% ${100 - config}%, 0% ${100 - config}%)`;
287
299
  };
288
300
 
289
- const theme = (config) => {
290
- let emptyTheme = {
291
- light: "",
292
- dark: "",
293
- selected: "light"
301
+ const lastTheme = () => {
302
+ if (_lastTheme.light && _lastTheme.dark) return _lastTheme;
303
+
304
+ let light = document.createElement("body");
305
+ light.className = "light";
306
+ document.body.appendChild(light);
307
+
308
+ let dark = document.createElement("body");
309
+ dark.className = "dark";
310
+ document.body.appendChild(dark);
311
+
312
+ let fromLight = getComputedStyle(light);
313
+ let fromDark = getComputedStyle(dark);
314
+ let variables = ['--primary', '--on-primary', '--primary-container', '--on-primary-container', '--secondary', '--on-secondary', '--secondary-container', '--on-secondary-container', '--tertiary', '--on-tertiary', '--tertiary-container', '--on-tertiary-container', '--error', '--on-error', '--error-container', '--on-error-container', '--background', '--on-background', '--surface', '--on-surface', '--outline', '--surface-variant', '--on-surface-variant', '--inverse-surface', '--inverse-on-surface'];
315
+ for(let i=0; i<variables.length; i++) {
316
+ _lastTheme.light += variables[i] + ":" + fromLight.getPropertyValue(variables[i]) + ";";
317
+ _lastTheme.dark += variables[i] + ":" + fromDark.getPropertyValue(variables[i]) + ";";
294
318
  }
295
319
 
296
- if (!window.materialDynamicColors) return emptyTheme;
320
+ document.body.removeChild(light);
321
+ document.body.removeChild(dark);
322
+ return _lastTheme;
323
+ }
297
324
 
298
- if (!config) {
299
- document.body.removeAttribute("style");
300
- return emptyTheme;
301
- };
325
+ const theme = (source) => {
326
+ if (!source || !window.materialDynamicColors) return lastTheme();
302
327
 
303
- if (config.from && config.mode && config.from[config.mode]) {
304
- let newTheme = {
305
- light: config.from.light,
306
- dark: config.from.dark,
307
- selected: config.mode
308
- };
309
-
310
- document.body.setAttribute("style", newTheme[config.mode]);
311
- return newTheme;
328
+ let mode = /dark/i.test(document.body.className) ? "dark" : "light";
329
+ if (source && source.light && source.dark) {
330
+ _lastTheme.light = source.light;
331
+ _lastTheme.dark = source.dark;
332
+ document.body.setAttribute("style", source[mode]);
333
+ return source;
312
334
  }
313
335
 
314
- return window.materialDynamicColors(config.from).then((theme) => {
336
+ return window.materialDynamicColors(source).then((theme) => {
315
337
  const toCss = (data) => {
316
338
  let style = "";
317
339
  for (var i in data) {
318
340
  let kebabCase = i.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
319
- style += "--"+kebabCase+": "+data[i]+";";
341
+ style += "--"+kebabCase+":"+data[i]+";";
320
342
  }
321
343
  return style;
322
344
  };
323
345
 
324
- let newTheme = {
325
- light: toCss(theme.light) + "--active: rgba(0,0,0,.1);--mode: light;",
326
- dark: toCss(theme.dark) + "--active: rgba(255,255,255,.2);--mode: dark;",
327
- selected: config.mode
328
- };
329
-
330
- document.body.setAttribute("style", newTheme[config.mode]);
331
- return newTheme;
346
+ _lastTheme.light = toCss(theme.light);
347
+ _lastTheme.dark = toCss(theme.dark);
348
+ document.body.setAttribute("style", _lastTheme[mode]);
349
+ return _lastTheme;
332
350
  });
333
351
  };
334
352
 
353
+ const mode = (value) => {
354
+ if (!value) return /dark/i.test(document.body.className) ? "dark" : "light";
355
+ document.body.classList.remove("light", "dark");
356
+ document.body.classList.add(value);
357
+ if (window.materialDynamicColors) document.body.style = _lastTheme[value];
358
+ return value;
359
+ }
360
+
361
+ const setup = () => {
362
+ if (_mutation) return;
363
+ _mutation = new MutationObserver(onMutation);
364
+ _mutation.observe(document.body, { childList: true, subtree: true });
365
+ ui();
366
+ }
367
+
335
368
  const ui = (selector, config) => {
336
369
  if (selector) {
370
+ if (selector == "setup") return setup();
337
371
  if (selector == "guid") return guid();
372
+ if (selector == "mode") return mode(config);
338
373
  if (selector == "theme") return theme(config);
339
374
 
340
375
  let to = query(selector);
@@ -367,4 +402,8 @@
367
402
  };
368
403
 
369
404
  window.ui = ui;
370
- })();
405
+ })();
406
+
407
+ window.addEventListener("load", () => {
408
+ ui("setup");
409
+ });
@@ -1,79 +1,80 @@
1
- .container,
2
- .container.min {
1
+ main.responsive,
2
+ main.responsive.min {
3
3
  margin: 0 auto;
4
4
  max-width: 992rem;
5
5
  padding: 8rem;
6
6
  overflow-x: hidden;
7
7
  min-height: 100vh;
8
+ box-sizing: border-box;
8
9
  }
9
10
 
10
- .container.max {
11
+ main.responsive.max {
11
12
  max-width: 100%;
12
13
  }
13
14
 
14
- .menu.top:not(.s, .m, .l) ~ .container {
15
- padding-top: 88rem;
15
+ nav.top:not(.s, .m, .l) ~ main.responsive {
16
+ padding-top: 96rem;
16
17
  }
17
18
 
18
- .menu.bottom:not(.s, .m, .l) ~ .container {
19
- padding-bottom: 88rem;
19
+ nav.bottom:not(.s, .m, .l) ~ main.responsive {
20
+ padding-bottom: 96rem;
20
21
  }
21
22
 
22
- .menu.left:not(.s, .m, .l) ~ .container {
23
- padding-left: 88rem;
23
+ nav.left:not(.s, .m, .l) ~ main.responsive {
24
+ padding-left: 96rem;
24
25
  }
25
26
 
26
- .menu.right:not(.s, .m, .l) ~ .container {
27
- padding-right: 88rem;
27
+ nav.right:not(.s, .m, .l) ~ main.responsive {
28
+ padding-right: 96rem;
28
29
  }
29
30
 
30
31
  @media only screen and (max-width: 600px) {
31
- .menu.s.bottom ~ .container {
32
- padding-bottom: 88rem;
32
+ nav.s.bottom ~ main.responsive {
33
+ padding-bottom: 96rem;
33
34
  }
34
- .menu.s.top ~ .container {
35
- padding-top: 88rem;
35
+ nav.s.top ~ main.responsive {
36
+ padding-top: 96rem;
36
37
  }
37
- .menu.s.left ~ .container {
38
- padding-left: 88rem;
38
+ nav.s.left ~ main.responsive {
39
+ padding-left: 96rem;
39
40
  }
40
- .menu.s.right ~ .container {
41
- padding-right: 88rem;
41
+ nav.s.right ~ main.responsive {
42
+ padding-right: 96rem;
42
43
  }
43
44
  }
44
45
 
45
46
  @media only screen and (min-width: 601px) and (max-width: 992px) {
46
- .menu.m.bottom ~ .container {
47
- padding-bottom: 88rem;
47
+ nav.m.bottom ~ main.responsive {
48
+ padding-bottom: 96rem;
48
49
  }
49
- .menu.m.top ~ .container {
50
- padding-top: 88rem;
50
+ nav.m.top ~ main.responsive {
51
+ padding-top: 96rem;
51
52
  }
52
- .menu.m.left ~ .container {
53
- padding-left: 88rem;
53
+ nav.m.left ~ main.responsive {
54
+ padding-left: 96rem;
54
55
  }
55
- .menu.m.right ~ .container {
56
- padding-right: 88rem;
56
+ nav.m.right ~ main.responsive {
57
+ padding-right: 96rem;
57
58
  }
58
59
  }
59
60
 
60
61
  @media only screen and (min-width: 993px) {
61
- .menu.l.bottom ~ .container {
62
- padding-bottom: 88rem;
62
+ nav.l.bottom ~ main.responsive {
63
+ padding-bottom: 96rem;
63
64
  }
64
- .menu.l.top ~ .container {
65
- padding-top: 88rem;
65
+ nav.l.top ~ main.responsive {
66
+ padding-top: 96rem;
66
67
  }
67
- .menu.l.left ~ .container {
68
- padding-left: 88rem;
68
+ nav.l.left ~ main.responsive {
69
+ padding-left: 96rem;
69
70
  }
70
- .menu.l.right ~ .container {
71
- padding-right: 88rem;
71
+ nav.l.right ~ main.responsive {
72
+ padding-right: 96rem;
72
73
  }
73
74
  }
74
75
 
75
76
  @media only screen and (max-width: 600px) {
76
- .container {
77
+ main.responsive {
77
78
  padding-right: 8rem;
78
79
  padding-left: 8rem;
79
80
  }
@@ -164,8 +164,8 @@
164
164
  height: 512rem;
165
165
  }
166
166
 
167
- .menu > .modal,
168
- .menu.left > .modal {
167
+ nav > .modal,
168
+ nav.left > .modal {
169
169
  z-index: 0;
170
170
  text-align: left;
171
171
  padding: 16rem 16rem 16rem 80rem;
@@ -173,15 +173,15 @@
173
173
  background-color: inherit;
174
174
  }
175
175
 
176
- .menu.right > .modal {
176
+ nav.right > .modal {
177
177
  padding: 16rem 80rem 16rem 16rem;
178
178
  }
179
179
 
180
- .menu.top > .modal {
180
+ nav.top > .modal {
181
181
  padding: 80rem 48rem 16rem 48rem;
182
182
  }
183
183
 
184
- .menu.bottom > .modal {
184
+ nav.bottom > .modal {
185
185
  padding: 16rem 48rem 80rem 48rem;
186
186
  }
187
187
 
@@ -0,0 +1,247 @@
1
+ nav:not(.left, .right, .top, .bottom) {
2
+ display: flex;
3
+ align-items: center;
4
+ white-space: nowrap;
5
+ margin: 0 -8rem;
6
+ }
7
+
8
+ *:not(.progress) + nav:not(.left, .right, .top, .bottom) {
9
+ margin-top: 8rem;
10
+ }
11
+
12
+ nav:not(.left, .right, .top, .bottom) > :not(.dropdown, .badge) {
13
+ margin: 0 8rem;
14
+ }
15
+
16
+ nav.wrap {
17
+ display: block;
18
+ white-space: normal;
19
+ }
20
+
21
+ *:not(.progress) + nav.wrap {
22
+ margin: 8rem -8rem;
23
+ }
24
+
25
+ nav.wrap > :not(.dropdown, .badge) {
26
+ margin: 8rem;
27
+ }
28
+
29
+ .field > nav {
30
+ padding: 0 8rem;
31
+ }
32
+
33
+ nav.left,
34
+ nav.right,
35
+ nav.top,
36
+ nav.bottom {
37
+ display: flex;
38
+ align-items: center;
39
+ justify-content: center;
40
+ flex-direction: column;
41
+ border: 0;
42
+ position: fixed;
43
+ box-shadow: var(--shadow2);
44
+ color: var(--on-surface-variant);
45
+ background-color: var(--surface-variant);
46
+ transform: none;
47
+ box-sizing: border-box;
48
+ z-index: 100;
49
+ left: 0;
50
+ top: 0;
51
+ bottom: 0;
52
+ right: 0;
53
+ height: auto;
54
+ width: auto;
55
+ text-align: center;
56
+ margin: 0;
57
+ }
58
+
59
+ nav.left,
60
+ nav.right {
61
+ width: 80rem;
62
+ }
63
+
64
+ nav.top,
65
+ nav.bottom {
66
+ height: 80rem;
67
+ }
68
+
69
+ nav.border {
70
+ box-shadow: none;
71
+ border: 1rem solid var(--outline);
72
+ }
73
+
74
+ nav.left.border {
75
+ border-top: none;
76
+ border-bottom: none;
77
+ border-left: none;
78
+ }
79
+
80
+ nav.right.border {
81
+ border-top: none;
82
+ border-bottom: none;
83
+ border-right: none;
84
+ }
85
+
86
+ nav.top.border {
87
+ border-top: none;
88
+ border-right: none;
89
+ border-left: none;
90
+ }
91
+
92
+ nav.bottom.border {
93
+ border-bottom: none;
94
+ border-right: none;
95
+ border-left: none;
96
+ }
97
+
98
+ nav.top {
99
+ bottom: auto;
100
+ justify-content: center;
101
+ flex-direction: row;
102
+ }
103
+
104
+ nav.left {
105
+ right: auto;
106
+ justify-content: flex-start;
107
+ flex-direction: column;
108
+ }
109
+
110
+ nav.right {
111
+ left: auto;
112
+ justify-content: flex-start;
113
+ flex-direction: column;
114
+ }
115
+
116
+ nav.bottom {
117
+ top: auto;
118
+ justify-content: center;
119
+ flex-direction: row;
120
+ }
121
+
122
+ nav.left > a:not(button, .button, .chip, img, video),
123
+ nav.right > a:not(button, .button, .chip, img, video),
124
+ nav.top > a:not(button, .button, .chip, img, video),
125
+ nav.bottom > a:not(button, .button, .chip, img, video) {
126
+ min-width: 56rem;
127
+ min-height: 56rem;
128
+ text-align: center;
129
+ margin: 8rem;
130
+ display: grid;
131
+ z-index: 101;
132
+ }
133
+
134
+ nav.left > a:not(button, .button, .chip, img, video),
135
+ nav.right > a:not(button, .button, .chip, img, video) {
136
+ width: auto;
137
+ }
138
+
139
+ nav.top > a:not(button, .button, .chip, img, video),
140
+ nav.bottom > a:not(button, .button, .chip, img, video) {
141
+ height: auto;
142
+ width: 56rem;
143
+ }
144
+
145
+ nav.left:before,
146
+ nav.right:before,
147
+ nav.top:before,
148
+ nav.bottom:before {
149
+ content: '';
150
+ position: absolute;
151
+ top: 0;
152
+ left: 0;
153
+ right: 0;
154
+ bottom: 0;
155
+ background-color: inherit;
156
+ z-index: 101;
157
+ }
158
+
159
+ nav.left > :not(.modal, .overlay),
160
+ nav.right > :not(.modal, .overlay),
161
+ nav.top > :not(.modal, .overlay),
162
+ nav.bottom > :not(.modal, .overlay) {
163
+ z-index: 101;
164
+ }
165
+
166
+ nav.no-space > a:not(button, .button, .chip) {
167
+ margin: 0;
168
+ }
169
+
170
+ nav.medium-space > a:not(button, .button, .chip) {
171
+ margin: 16rem;
172
+ }
173
+
174
+ nav.large-space > a:not(button, .button, .chip) {
175
+ margin: 24rem;
176
+ }
177
+
178
+ nav.left > a:not(button, .button, .chip) > i,
179
+ nav.right > a:not(button, .button, .chip) > i,
180
+ nav.top > a:not(button, .button, .chip) > i,
181
+ nav.bottom > a:not(button, .button, .chip) > i {
182
+ padding: 4rem;
183
+ border-radius: 32rem;
184
+ transition: var(--speed1) padding linear;
185
+ }
186
+
187
+ nav.left > a:not(button, .button, .chip):hover > i,
188
+ nav.left > a:not(button, .button, .chip):focus > i,
189
+ nav.left > a:not(button, .button, .chip).active > i,
190
+ nav.right > a:not(button, .button, .chip):hover > i,
191
+ nav.right > a:not(button, .button, .chip):focus > i,
192
+ nav.right > a:not(button, .button, .chip).active > i,
193
+ nav.top > a:not(button, .button, .chip):hover > i,
194
+ nav.top > a:not(button, .button, .chip):focus > i,
195
+ nav.top > a:not(button, .button, .chip).active > i,
196
+ nav.bottom > a:not(button, .button, .chip):focus > i,
197
+ nav.bottom > a:not(button, .button, .chip):hover > i,
198
+ nav.bottom > a:not(button, .button, .chip).active > i {
199
+ background-color: var(--primary);
200
+ color: var(--on-primary);
201
+ padding: 4rem 16rem;
202
+ }
203
+
204
+ nav.left > .modal,
205
+ nav.right > .modal,
206
+ nav.top > .modal,
207
+ nav.bottom > .modal {
208
+ margin: 0;
209
+ }
210
+
211
+ nav.left > .modal {
212
+ padding-left: 88rem;
213
+ }
214
+
215
+ nav.right > .modal {
216
+ padding-right: 88rem;
217
+ }
218
+
219
+ nav.top > .modal {
220
+ padding-top: 88rem;
221
+ }
222
+
223
+ nav.bottom > .modal {
224
+ padding-bottom: 88rem;
225
+ }
226
+
227
+ nav.left-align,
228
+ nav.top-align {
229
+ justify-content: flex-start;
230
+ }
231
+
232
+ nav.right-align,
233
+ nav.bottom-align {
234
+ justify-content: flex-end;
235
+ }
236
+
237
+ nav.center-align,
238
+ nav.middle-align {
239
+ justify-content: center;
240
+ }
241
+
242
+ @media only screen and (max-width: 600px) {
243
+ nav.top,
244
+ nav.bottom {
245
+ justify-content: space-around;
246
+ }
247
+ }
@@ -13,7 +13,7 @@
13
13
  transition: var(--speed3) all, 0s background-color;
14
14
  }
15
15
 
16
- .menu > .overlay {
16
+ nav > .overlay {
17
17
  z-index: 0;
18
18
  }
19
19
 
@@ -1,5 +1,5 @@
1
1
  .flat {
2
- box-shadow: none;
2
+ box-shadow: none !important;
3
3
  }
4
4
 
5
5
  .round {
@@ -4,5 +4,5 @@
4
4
  }
5
5
 
6
6
  .no-scroll {
7
- overflow: hidden;
7
+ overflow: hidden !important;
8
8
  }
@@ -1,15 +1,15 @@
1
- .space:not(.menu, nav, .row, table),
2
- .small-space:not(.menu, nav, .row, table) {
1
+ .space:not(nav, .row, table),
2
+ .small-space:not(nav, .row, table) {
3
3
  height: 16rem;
4
4
  display: block;
5
5
  }
6
6
 
7
- .medium-space:not(.menu, nav, .row, table) {
7
+ .medium-space:not(nav, .row, table) {
8
8
  height: 32rem;
9
9
  display: block;
10
10
  }
11
11
 
12
- .large-space:not(.menu, nav, .row, table) {
12
+ .large-space:not(nav, .row, table) {
13
13
  height: 48rem;
14
14
  display: block;
15
15
  }
@@ -1,4 +1,4 @@
1
- .is-dark {
1
+ body.dark {
2
2
  --primary: #D0BCFF;
3
3
  --on-primary: #371E73;
4
4
  --primary-container: #4F378B;
@@ -1,5 +1,5 @@
1
1
  :root,
2
- .is-light {
2
+ body.light {
3
3
  --primary: #6750A4;
4
4
  --on-primary: #FFFFFF;
5
5
  --primary-container: #EADDFF;