beercss 4.0.19 → 4.0.21

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.
@@ -0,0 +1,12 @@
1
+ declare class BeerCssCustomElement extends HTMLElement {
2
+ static isCssLoaded: boolean;
3
+ static isJsLoaded: boolean;
4
+
5
+ constructor();
6
+
7
+ addJs(): Promise<void | any>;
8
+ addCss(): Promise<void>;
9
+ run(): Promise<void>;
10
+ }
11
+
12
+ export default BeerCssCustomElement;
@@ -12,7 +12,7 @@ class BeerCssCustomElement extends HTMLElement {
12
12
  BeerCssCustomElement.isJsLoaded = true;
13
13
 
14
14
  if (window.ui) return;
15
- return await import("https://cdn.jsdelivr.net/npm/beercss@4.0.19/dist/cdn/beer.min.js");
15
+ return await import("https://cdn.jsdelivr.net/npm/beercss@4.0.21/dist/cdn/beer.min.js");
16
16
  }
17
17
 
18
18
  async addCss() {
@@ -23,7 +23,7 @@ class BeerCssCustomElement extends HTMLElement {
23
23
 
24
24
  const head = document.querySelector("head");
25
25
  const element = document.createElement("link");
26
- element.setAttribute("href", "https://cdn.jsdelivr.net/npm/beercss@4.0.19/dist/cdn/beer.scoped.min.css");
26
+ element.setAttribute("href", "https://cdn.jsdelivr.net/npm/beercss@4.0.21/dist/cdn/beer.scoped.min.css");
27
27
  element.setAttribute("rel", "stylesheet");
28
28
  head.appendChild(element);
29
29
  }
@@ -62,7 +62,7 @@
62
62
  }
63
63
 
64
64
  nav:is(.left, .right, .top, .bottom) > a > .badge,
65
- nav:is(.left, .right, .top, .bottom) > :is(ol, ul) > li > a > .badge {
65
+ nav:is(.left, .right, .top, .bottom) > :is(ol > li, ul > li, div:not([class]), div[class=active]) > a > .badge {
66
66
  inset: 1rem auto auto 50%;
67
67
  }
68
68
 
@@ -60,11 +60,19 @@ function onInputTextarea(e: Event) {
60
60
  updateTextarea(textarea);
61
61
  }
62
62
 
63
+ function onClickLabelDelegation(e: Event) {
64
+ const from = (e.target as HTMLElement).closest(".field > label") as HTMLLabelElement;
65
+ if (!from) return;
66
+
67
+ Object.defineProperty(e, "currentTarget", { value: from, configurable: true });
68
+ onClickLabel(e);
69
+ }
70
+
63
71
  function updateAllLabels() {
64
- const labels = queryAll(".field > label");
65
- for (let i=0; i<labels.length; i++) {
66
- onWeak(labels[i], "click", onClickLabel);
67
- }
72
+ const body = document.body;
73
+ if (!body) return;
74
+
75
+ onWeak(body, "click", onClickLabelDelegation);
68
76
  }
69
77
 
70
78
  function updateAllInputs() {
@@ -198,7 +198,7 @@ nav.max:is(.top, .bottom) {
198
198
  }
199
199
 
200
200
  nav:is(.left, .right, .top, .bottom) > a:not(.button, .chip),
201
- nav:is(.left, .right, .top, .bottom) > :is(ol, ul) > li > a:not(.button, .chip) {
201
+ nav:is(.left, .right, .top, .bottom) > :is(ol > li, ul > li, div:not([class]), div[class=active]) > a:not(.button, .chip) {
202
202
  display: flex;
203
203
  flex-direction: column;
204
204
  gap: 0.25rem;
@@ -208,14 +208,14 @@ nav:is(.left, .right, .top, .bottom) > :is(ol, ul) > li > a:not(.button, .chip)
208
208
  }
209
209
 
210
210
  nav:not(.max):is(.left, .right, .top, .bottom) > a:not(.button, .chip) > i,
211
- nav:not(.max):is(.left, .right, .top, .bottom) > :is(ol, ul) > li > a:not(.button, .chip) > i {
211
+ nav:not(.max):is(.left, .right, .top, .bottom) > :is(ol > li, ul > li, div:not([class]), div[class=active]) > a:not(.button, .chip) > i {
212
212
  padding: 0.25rem 1rem;
213
213
  border-radius: 2rem;
214
214
  margin: 0 auto;
215
215
  }
216
216
 
217
217
  nav.max:is(.left, .right, .top, .bottom) > a:not(.button, .chip),
218
- nav.max:is(.left, .right, .top, .bottom) > :is(ol, ul) > li > a:not(.button, .chip) {
218
+ nav.max:is(.left, .right, .top, .bottom) > :is(ol > li, ul > li, div:not([class]), div[class=active]) > a:not(.button, .chip) {
219
219
  flex-direction: row;
220
220
  gap: 0.5rem;
221
221
  inline-size: auto;
@@ -226,21 +226,21 @@ nav.max:is(.left, .right, .top, .bottom) > :is(ol, ul) > li > a:not(.button, .ch
226
226
  }
227
227
 
228
228
  nav:is(.left, .right, .top, .bottom) > a.active:not(.button, .chip),
229
- nav:is(.left, .right, .top, .bottom) > :is(ol, ul) > li > a.active:not(.button, .chip) {
229
+ nav:is(.left, .right, .top, .bottom) > :is(ol > li, ul > li, div:not([class]), div[class=active]) > a.active:not(.button, .chip) {
230
230
  transition: padding var(--speed1) linear;
231
231
  }
232
232
 
233
233
  nav.max:is(.top, .bottom) > a:not(.button, .chip),
234
- nav.max:is(.top, .bottom) > :is(ol, ul) > li > a:not(.button, .chip) {
234
+ nav.max:is(.top, .bottom) > :is(ol > li, ul > li, div:not([class]), div[class=active]) > a:not(.button, .chip) {
235
235
  gap: 0.25rem;
236
236
  block-size: 2.5rem;
237
237
  font-size: 0.8rem;
238
238
  }
239
239
 
240
240
  nav.max:is(.left, .right, .top, .bottom) > a.active:not(.button, .chip),
241
- nav.max:is(.left, .right, .top, .bottom) > :is(ol, ul) > li > a.active:not(.button, .chip),
241
+ nav.max:is(.left, .right, .top, .bottom) > :is(ol > li, ul > li, div:not([class]), div[class=active]) > a.active:not(.button, .chip),
242
242
  nav:is(.left, .right, .top, .bottom):not(.max) > a.active:not(.button, .chip) > i,
243
- nav:is(.left, .right, .top, .bottom):not(.max) > :is(ol, ul) > li > a.active:not(.button, .chip) > i {
243
+ nav:is(.left, .right, .top, .bottom):not(.max) > :is(ol > li, ul > li, div:not([class]), div[class=active]) > a.active:not(.button, .chip) > i {
244
244
  background-color: var(--secondary-container);
245
245
  color: var(--on-secondary-container);
246
246
  }
@@ -8,7 +8,7 @@
8
8
  .page.active {
9
9
  opacity: 1;
10
10
  position: relative;
11
- display: block;
11
+ display: inherit;
12
12
  animation: var(--speed4) to-page ease;
13
13
  }
14
14
 
@@ -41,10 +41,14 @@
41
41
  border-end-end-radius: var(--_round) !important;
42
42
  }
43
43
 
44
- .circle:not(.extend) {
44
+ .circle {
45
45
  border-radius: 50%;
46
46
  }
47
47
 
48
+ .circle:is(button, .button, .chip) {
49
+ border-radius: var(--_size);
50
+ }
51
+
48
52
  :is(.circle, .square):is(button, .button, .chip) {
49
53
  padding: 0;
50
54
  block-size: var(--_size);
@@ -1,12 +1,4 @@
1
- import { queryAll, onWeak } from "../utils";
2
-
3
- function onMousedownRipple(e: MouseEvent) {
4
- updateRipple(e);
5
- }
6
-
7
- function onKeydownRipple(e: KeyboardEvent) {
8
- if (e?.key === " ") updateRipple(e);
9
- }
1
+ import { onWeak } from "../utils";
10
2
 
11
3
  function updateRipple(e: MouseEvent | KeyboardEvent) {
12
4
  const isMouseEvent = e instanceof MouseEvent;
@@ -29,10 +21,26 @@ function updateRipple(e: MouseEvent | KeyboardEvent) {
29
21
  element.appendChild(rippleContainer);
30
22
  }
31
23
 
24
+ function onMousedownRippleDelegation(e: MouseEvent) {
25
+ const from = (e.target as HTMLElement).closest(".slow-ripple, .ripple, .fast-ripple") as HTMLElement;
26
+ if (!from) return;
27
+
28
+ Object.defineProperty(e, "currentTarget", { value: from, configurable: true });
29
+ updateRipple(e);
30
+ }
31
+
32
+ function onKeydownRippleDelegation(e: KeyboardEvent) {
33
+ const from = (e.target as HTMLElement).closest(".slow-ripple, .ripple, .fast-ripple") as HTMLElement;
34
+ if (!from || e.key !== " ") return;
35
+
36
+ Object.defineProperty(e, "currentTarget", { value: from, configurable: true });
37
+ updateRipple(e);
38
+ }
39
+
32
40
  export function updateAllRipples() {
33
- const ripples = queryAll(".slow-ripple, .ripple, .fast-ripple");
34
- for(let i=0; i<ripples.length; i++) {
35
- onWeak(ripples[i], "mousedown", onMousedownRipple);
36
- onWeak(ripples[i], "keydown", onKeydownRipple);
37
- }
41
+ const body = document.body;
42
+ if (!body) return;
43
+
44
+ onWeak(body, "mousedown", onMousedownRippleDelegation);
45
+ onWeak(body, "keydown", onKeydownRippleDelegation);
38
46
  }
@@ -1,8 +1,8 @@
1
1
  :is(.wave, .chip, .button, button, nav.tabbed > a, .tabs > a, nav.toolbar > a):not([class*=ripple])::after,
2
2
  nav:is(.left, .right, .bottom, .top).max > a::after,
3
- nav:is(.left, .right, .bottom, .top).max > :is(ol, ul) > li > a::after,
3
+ nav:is(.left, .right, .bottom, .top).max > :is(ol > li, ul > li, div:not([class]), div[class=active]) > a::after,
4
4
  nav:is(.left, .right, .bottom, .top):not(.max) > a > i::after,
5
- nav:is(.left, .right, .bottom, .top):not(.max) > :is(ol, ul) > li > a > i::after {
5
+ nav:is(.left, .right, .bottom, .top):not(.max) > :is(ol > li, ul > li, div:not([class]), div[class=active]) a > i::after {
6
6
  content: "";
7
7
  position: absolute;
8
8
  inset: 0;
@@ -19,9 +19,9 @@ nav:is(.left, .right, .bottom, .top):not(.max) > :is(ol, ul) > li > a > i::after
19
19
 
20
20
  :is(.wave, .chip, .button, button, nav.tabbed > a, .tabs > a, nav.toolbar > a):not([class*=ripple]):is(:focus-visible, :hover)::after,
21
21
  nav:is(.left, .right, .bottom, .top).max > a:not(.button, .chip):is(:focus-visible, :hover)::after,
22
- nav:is(.left, .right, .bottom, .top).max > :is(ol, ul) > li > a:not(.button, .chip):is(:focus-visible, :hover)::after,
22
+ nav:is(.left, .right, .bottom, .top).max > :is(ol > li, ul > li, div:not([class]), div[class=active]) > a:not(.button, .chip):is(:focus-visible, :hover)::after,
23
23
  nav:is(.left, .right, .bottom, .top):not(.max) > a:not(.button, .chip):is(:focus-visible, :hover) > i::after,
24
- nav:is(.left, .right, .bottom, .top):not(.max) > :is(ol, ul) > li > a:not(.button, .chip):is(:focus-visible, :hover) > i::after {
24
+ nav:is(.left, .right, .bottom, .top):not(.max) > :is(ol > li, ul > li, div:not([class]), div[class=active]) > a:not(.button, .chip):is(:focus-visible, :hover) > i::after {
25
25
  background-size: 22500%;
26
26
  opacity: 0.1;
27
27
  transition: background-size var(--speed2) linear;
@@ -29,9 +29,9 @@ nav:is(.left, .right, .bottom, .top):not(.max) > :is(ol, ul) > li > a:not(.butto
29
29
 
30
30
  :is(.wave, .chip, .button, button, nav.tabbed > a, .tabs > a, nav.toolbar > a, nav.max > a):not([class*=ripple]):active::after,
31
31
  nav:is(.left, .right, .bottom, .top).max > a:active::after,
32
- nav:is(.left, .right, .bottom, .top).max > :is(ol, ul) > li > a:active::after,
32
+ nav:is(.left, .right, .bottom, .top).max > :is(ol > li, ul > li, div:not([class]), div[class=active]) > a:active::after,
33
33
  nav:is(.left, .right, .bottom, .top):not(.max) > a:active > i::after,
34
- nav:is(.left, .right, .bottom, .top):not(.max) > :is(ol, ul) > li > a:active > i::after {
34
+ nav:is(.left, .right, .bottom, .top):not(.max) > :is(ol > li, ul > li, div:not([class]), div[class=active]) > a:active > i::after {
35
35
  background-size: 0%;
36
36
  opacity: 0;
37
37
  transition: none;
@@ -4,7 +4,7 @@
4
4
  font-style: normal;
5
5
  font-weight: 400;
6
6
  font-display: swap;
7
- src: url(../fonts/material-symbols-outlined.woff2) format("woff2"), url(https://cdn.jsdelivr.net/npm/beercss@4.0.19/dist/cdn/material-symbols-outlined.woff2) format("woff2");
7
+ src: url(../fonts/material-symbols-outlined.woff2) format("woff2"), url(https://cdn.jsdelivr.net/npm/beercss@4.0.21/dist/cdn/material-symbols-outlined.woff2) format("woff2");
8
8
  }
9
9
 
10
10
  /* rounded icons */
@@ -13,7 +13,7 @@
13
13
  font-style: normal;
14
14
  font-weight: 400;
15
15
  font-display: swap;
16
- src: url(../fonts/material-symbols-rounded.woff2) format("woff2"), url(https://cdn.jsdelivr.net/npm/beercss@4.0.19/dist/cdn/material-symbols-rounded.woff2) format("woff2");
16
+ src: url(../fonts/material-symbols-rounded.woff2) format("woff2"), url(https://cdn.jsdelivr.net/npm/beercss@4.0.21/dist/cdn/material-symbols-rounded.woff2) format("woff2");
17
17
  }
18
18
 
19
19
  /* sharp icons */
@@ -22,7 +22,7 @@
22
22
  font-style: normal;
23
23
  font-weight: 400;
24
24
  font-display: swap;
25
- src: url(../fonts/material-symbols-sharp.woff2) format("woff2"), url(https://cdn.jsdelivr.net/npm/beercss@4.0.19/dist/cdn/material-symbols-sharp.woff2) format("woff2");
25
+ src: url(../fonts/material-symbols-sharp.woff2) format("woff2"), url(https://cdn.jsdelivr.net/npm/beercss@4.0.21/dist/cdn/material-symbols-sharp.woff2) format("woff2");
26
26
  }
27
27
 
28
28
  /* subset of only required icons */
@@ -31,5 +31,5 @@
31
31
  font-style: normal;
32
32
  font-weight: 400;
33
33
  font-display: swap;
34
- src: url(../fonts/material-symbols-subset.woff2) format("woff2"), url(https://cdn.jsdelivr.net/npm/beercss@4.0.19/dist/cdn/material-symbols-subset.woff2) format("woff2");
34
+ src: url(../fonts/material-symbols-subset.woff2) format("woff2"), url(https://cdn.jsdelivr.net/npm/beercss@4.0.21/dist/cdn/material-symbols-subset.woff2) format("woff2");
35
35
  }
@@ -72,6 +72,6 @@ label {
72
72
  pointer-events: none;
73
73
  }
74
74
 
75
- div:is(:not([class]), [class=active]):has(> :not(.responsive) ~ :is(menu, .tooltip, input)) {
75
+ :is(div:not([class]), div[class=active]):has(> :not(.responsive) ~ :is(menu, .tooltip, input)) {
76
76
  display: inline-flex;
77
77
  }
@@ -16,22 +16,26 @@ function lastTheme(): IBeerCssTheme {
16
16
 
17
17
  const light = document.createElement("body");
18
18
  light.className = "light";
19
+ light.style.display = "none";
19
20
  body.appendChild(light);
20
21
 
21
22
  const dark = document.createElement("body");
22
23
  dark.className = "dark";
24
+ dark.style.display = "none";
23
25
  body.appendChild(dark);
24
26
 
25
- const fromLight = getComputedStyle(light);
26
- const fromDark = getComputedStyle(dark);
27
- const 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", "--surface-variant", "--on-surface-variant", "--outline", "--outline-variant", "--shadow", "--scrim", "--inverse-surface", "--inverse-on-surface", "--inverse-primary", "--surface-dim", "--surface-bright", "--surface-container-lowest", "--surface-container-low", "--surface-container", "--surface-container-high", "--surface-container-highest"];
28
- for (let i = 0, n = variables.length; i < n; i++) {
29
- _lastTheme.light += variables[i] + ":" + fromLight.getPropertyValue(variables[i]) + ";";
30
- _lastTheme.dark += variables[i] + ":" + fromDark.getPropertyValue(variables[i]) + ";";
27
+ try {
28
+ const fromLight = getComputedStyle(light);
29
+ const fromDark = getComputedStyle(dark);
30
+ const 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", "--surface-variant", "--on-surface-variant", "--outline", "--outline-variant", "--shadow", "--scrim", "--inverse-surface", "--inverse-on-surface", "--inverse-primary", "--surface-dim", "--surface-bright", "--surface-container-lowest", "--surface-container-low", "--surface-container", "--surface-container-high", "--surface-container-highest"];
31
+ for (let i = 0, n = variables.length; i < n; i++) {
32
+ _lastTheme.light += variables[i] + ":" + fromLight.getPropertyValue(variables[i]) + ";";
33
+ _lastTheme.dark += variables[i] + ":" + fromDark.getPropertyValue(variables[i]) + ";";
34
+ }
35
+ } finally {
36
+ body.removeChild(light);
37
+ body.removeChild(dark);
31
38
  }
32
-
33
- body.removeChild(light);
34
- body.removeChild(dark);
35
39
  return _lastTheme;
36
40
  }
37
41
 
package/src/cdn/utils.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  const _emptyNodeList = [] as unknown as NodeListOf<Element>;
2
- const _weakElements = new WeakSet<HTMLElement>();
2
+ const _weakMap = new WeakMap<Element, Map<string, Set<any>>>();
3
3
 
4
4
  export const isChrome = navigator.userAgent.includes("Chrome");
5
5
 
@@ -17,12 +17,15 @@ export const isAndroid = navigator.userAgent.includes("Android");
17
17
 
18
18
  export const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
19
19
 
20
+ let _isTouchable: boolean;
20
21
  export function isTouchable(): boolean {
21
- return window?.matchMedia("(pointer: coarse)").matches;
22
+ if (_isTouchable !== undefined) return _isTouchable;
23
+ _isTouchable = window?.matchMedia?.("(pointer: coarse)")?.matches ?? false;
24
+ return _isTouchable;
22
25
  }
23
26
 
24
27
  export function isDark(): boolean {
25
- return window?.matchMedia("(prefers-color-scheme: dark)").matches;
28
+ return window?.matchMedia?.("(prefers-color-scheme: dark)")?.matches ?? false;
26
29
  }
27
30
 
28
31
  export async function wait(milliseconds: number) {
@@ -84,7 +87,25 @@ export function on(element: Element | null, name: string, callback: any, useCapt
84
87
  }
85
88
 
86
89
  export function onWeak(element: Element | null, name: string, callback: any, useCapture: boolean = true) {
87
- addWeakElement(element as HTMLElement);
90
+ if (!element) return;
91
+
92
+ const el = element as HTMLElement;
93
+ let events = _weakMap.get(el);
94
+ if (!events) {
95
+ events = new Map();
96
+ _weakMap.set(el, events);
97
+ }
98
+
99
+ const key = name + (useCapture ? "1" : "0");
100
+ let callbacks = events.get(key);
101
+ if (!callbacks) {
102
+ callbacks = new Set();
103
+ events.set(key, callbacks);
104
+ }
105
+
106
+ if (callbacks.has(callback)) return;
107
+
108
+ callbacks.add(callback);
88
109
  on(element, name, callback, useCapture);
89
110
  }
90
111
 
@@ -142,8 +163,8 @@ export function updateAllClickable(element: Element) {
142
163
  }
143
164
 
144
165
  export function addWeakElement(element: HTMLElement) {
145
- if (_weakElements.has(element)) return;
146
- _weakElements.add(element);
166
+ if (_weakMap.has(element)) return;
167
+ _weakMap.set(element, new Map());
147
168
  }
148
169
 
149
170
  export function rootSizeInPixels(): number {