beercss 3.12.13 → 3.13.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/dist/cdn/beer.js CHANGED
@@ -1,7 +1,14 @@
1
1
  const _emptyNodeList = [];
2
- function isTouchable() {
3
- return window == null ? void 0 : window.matchMedia("(pointer: coarse)").matches;
4
- }
2
+ const _weakElements = /* @__PURE__ */ new WeakSet();
3
+ const isChrome = navigator.userAgent.includes("Chrome") && !navigator.userAgent.includes("Edge");
4
+ navigator.userAgent.includes("Firefox");
5
+ navigator.userAgent.includes("Safari") && !navigator.userAgent.includes("Chrome");
6
+ navigator.userAgent.includes("Edge");
7
+ navigator.userAgent.includes("Windows");
8
+ const isMac = navigator.userAgent.includes("Macintosh");
9
+ navigator.userAgent.includes("Linux");
10
+ navigator.userAgent.includes("Android");
11
+ const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
5
12
  function isDark() {
6
13
  return window == null ? void 0 : window.matchMedia("(prefers-color-scheme: dark)").matches;
7
14
  }
@@ -51,6 +58,10 @@ function removeClass(element, name) {
51
58
  function on(element, name, callback, useCapture = true) {
52
59
  if (element == null ? void 0 : element.addEventListener) element.addEventListener(name, callback, useCapture);
53
60
  }
61
+ function onWeak(element, name, callback, useCapture = true) {
62
+ addWeakElement(element);
63
+ on(element, name, callback, useCapture);
64
+ }
54
65
  function off(element, name, callback, useCapture = true) {
55
66
  if (element == null ? void 0 : element.removeEventListener) element.removeEventListener(name, callback, useCapture);
56
67
  }
@@ -94,6 +105,16 @@ function updateAllClickable(element) {
94
105
  for (let i = 0; i < as.length; i++) removeClass(as[i], "active");
95
106
  if (!hasTag(element, "button") && !hasClass(element, "button") && !hasClass(element, "chip")) addClass(element, "active");
96
107
  }
108
+ function addWeakElement(element) {
109
+ if (_weakElements.has(element)) return;
110
+ _weakElements.add(element);
111
+ }
112
+ function rootSizeInPixels() {
113
+ const size = getComputedStyle(document.documentElement).getPropertyValue("--size") || "16px";
114
+ if (size.includes("%")) return parseInt(size) * 16 / 100;
115
+ if (size.includes("em")) return parseInt(size) * 16;
116
+ return parseInt(size);
117
+ }
97
118
  function updatePlaceholder(element) {
98
119
  if (!element.placeholder) element.placeholder = " ";
99
120
  }
@@ -127,61 +148,64 @@ function onKeydownColor(e) {
127
148
  const input = e.currentTarget;
128
149
  updateColor(input, e);
129
150
  }
130
- function onInputTextarea(e) {
131
- const textarea = e.currentTarget;
132
- updateTextarea(textarea);
133
- }
134
151
  function onPasswordIconClick(e) {
135
152
  var _a;
136
153
  const icon = e.currentTarget;
137
154
  const input = query("input", parent(icon));
138
155
  if (input && ((_a = icon.textContent) == null ? void 0 : _a.includes("visibility"))) input.type = input.type === "password" ? "text" : "password";
139
156
  }
157
+ function onInputTextarea(e) {
158
+ const textarea = e.currentTarget;
159
+ updateTextarea(textarea);
160
+ }
140
161
  function updateAllLabels() {
141
162
  const labels = queryAll(".field > label");
142
- for (let i = 0; i < labels.length; i++) on(labels[i], "click", onClickLabel);
163
+ for (let i = 0; i < labels.length; i++) {
164
+ onWeak(labels[i], "click", onClickLabel);
165
+ }
143
166
  }
144
167
  function updateAllInputs() {
145
168
  const inputs = queryAll(".field > input:not([type=file], [type=color], [type=range])");
146
169
  for (let i = 0; i < inputs.length; i++) {
147
- on(inputs[i], "focus", onFocusInput);
148
- on(inputs[i], "blur", onBlurInput);
170
+ onWeak(inputs[i], "focus", onFocusInput);
171
+ onWeak(inputs[i], "blur", onBlurInput);
149
172
  updateInput(inputs[i]);
150
173
  }
151
174
  }
152
175
  function updateAllSelects() {
153
176
  const selects = queryAll(".field > select");
154
177
  for (let i = 0; i < selects.length; i++) {
155
- on(selects[i], "focus", onFocusInput);
156
- on(selects[i], "blur", onBlurInput);
178
+ onWeak(selects[i], "focus", onFocusInput);
179
+ onWeak(selects[i], "blur", onBlurInput);
157
180
  }
158
181
  }
159
182
  function updateAllFiles() {
160
183
  const files = queryAll(".field > input[type=file]");
161
184
  for (let i = 0; i < files.length; i++) {
162
- on(files[i], "change", onChangeFile);
185
+ onWeak(files[i], "change", onChangeFile);
163
186
  updateFile(files[i]);
164
187
  }
165
188
  }
166
189
  function updateAllColors() {
167
190
  const colors = queryAll(".field > input[type=color]");
168
191
  for (let i = 0; i < colors.length; i++) {
169
- on(colors[i], "change", onChangeColor);
192
+ onWeak(colors[i], "change", onChangeColor);
170
193
  updateColor(colors[i]);
171
194
  }
172
195
  }
173
196
  function updateAllTextareas() {
174
- const textareas = queryAll(".field.textarea > textarea");
197
+ if (isChrome && !isMac && !isIOS) return;
198
+ const textareas = queryAll(".field > textarea");
175
199
  for (let i = 0; i < textareas.length; i++) {
176
- on(textareas[i], "focus", onFocusInput);
177
- on(textareas[i], "blur", onBlurInput);
178
- on(textareas[i], "input", onInputTextarea);
200
+ onWeak(textareas[i], "focus", onFocusInput);
201
+ onWeak(textareas[i], "blur", onBlurInput);
202
+ onWeak(textareas[i], "input", onInputTextarea);
179
203
  updateTextarea(textareas[i]);
180
204
  }
181
205
  }
182
206
  function updateAllPasswordIcons() {
183
207
  const icons = queryAll("input[type=password] ~ :is(i, a)");
184
- for (let i = 0; i < icons.length; i++) on(icons[i], "click", onPasswordIconClick);
208
+ for (let i = 0; i < icons.length; i++) onWeak(icons[i], "click", onPasswordIconClick);
185
209
  }
186
210
  function updateInput(input) {
187
211
  if (hasType(input, "number") && !input.value) input.value = "";
@@ -198,7 +222,7 @@ function updateFile(input, e) {
198
222
  if (!hasType(nextInput, "text")) return;
199
223
  nextInput.value = input.files ? Array.from(input.files).map((x) => x.name).join(", ") : "";
200
224
  nextInput.readOnly = true;
201
- on(nextInput, "keydown", onKeydownFile, false);
225
+ onWeak(nextInput, "keydown", onKeydownFile, false);
202
226
  updateInput(nextInput);
203
227
  }
204
228
  function updateColor(input, e) {
@@ -212,14 +236,15 @@ function updateColor(input, e) {
212
236
  if (!hasType(nextInput, "text")) return;
213
237
  nextInput.readOnly = true;
214
238
  nextInput.value = input.value;
215
- on(nextInput, "keydown", onKeydownColor, false);
239
+ onWeak(nextInput, "keydown", onKeydownColor, false);
216
240
  updateInput(nextInput);
217
241
  }
218
242
  function updateTextarea(textarea) {
219
243
  updatePlaceholder(textarea);
220
- const field = parent(textarea);
221
- field.removeAttribute("style");
222
- if (hasClass(field, "min")) field.style.setProperty("--_size", `${Math.max(textarea.scrollHeight, field.offsetHeight)}px`);
244
+ if (textarea.hasAttribute("rows")) return;
245
+ const rootSize = rootSizeInPixels();
246
+ textarea.style.blockSize = "auto";
247
+ textarea.style.blockSize = `${textarea.scrollHeight - rootSize}px`;
223
248
  }
224
249
  function updateAllFields() {
225
250
  updateAllLabels();
@@ -230,7 +255,7 @@ function updateAllFields() {
230
255
  updateAllTextareas();
231
256
  updateAllPasswordIcons();
232
257
  }
233
- function onInputDocument(e) {
258
+ function onInputDocument$1(e) {
234
259
  const input = e.target;
235
260
  if (!hasTag(input, "input") && !hasTag(input, "select")) return;
236
261
  if (input.type === "range") {
@@ -240,34 +265,19 @@ function onInputDocument(e) {
240
265
  updateAllRanges();
241
266
  }
242
267
  }
243
- function onFocusRange(e) {
244
- if (!isTouchable()) return;
268
+ function onChangeInput(e) {
245
269
  const input = e.target;
246
- const label = parent(input);
247
- if (hasClass(label, "vertical")) document.body.classList.add("no-scroll");
248
- }
249
- function onBlurRange(e) {
250
- if (!isTouchable()) return;
251
- const input = e.target;
252
- const label = parent(input);
253
- if (hasClass(label, "vertical")) document.body.classList.remove("no-scroll");
270
+ requestAnimationFrame(() => input.blur());
254
271
  }
255
272
  function updateAllRanges() {
256
273
  const body = document.body;
257
274
  const ranges = queryAll(".slider > input[type=range]");
258
- if (!ranges.length) off(body, "input", onInputDocument, false);
259
- else on(body, "input", onInputDocument, false);
275
+ if (!ranges.length) off(body, "input", onInputDocument$1, false);
276
+ else on(body, "input", onInputDocument$1, false);
260
277
  for (let i = 0; i < ranges.length; i++) updateRange(ranges[i]);
261
278
  }
262
- function rootSizeInPixels() {
263
- const size = getComputedStyle(document.documentElement).getPropertyValue("--size") || "16px";
264
- if (size.includes("%")) return parseInt(size) * 16 / 100;
265
- if (size.includes("em")) return parseInt(size) * 16;
266
- return parseInt(size);
267
- }
268
279
  function updateRange(input) {
269
- on(input, "focus", onFocusRange);
270
- on(input, "blur", onBlurRange);
280
+ onWeak(input, "change", onChangeInput);
271
281
  const label = parent(input);
272
282
  const bar = query("span", label);
273
283
  const inputs = queryAll("input", label);
@@ -422,7 +432,7 @@ async function updateDialog(from, dialog) {
422
432
  insertBefore(overlay, dialog);
423
433
  await wait(90);
424
434
  }
425
- if (!isModal) on(overlay, "click", onClickOverlay, false);
435
+ if (!isModal) onWeak(overlay, "click", onClickOverlay, false);
426
436
  if (isActive) closeDialog(dialog, overlay);
427
437
  else void openDialog(dialog, overlay, isModal, from);
428
438
  }
@@ -468,7 +478,7 @@ function updateSnackbar(snackbar, milliseconds) {
468
478
  const activeSnackbars = queryAll(".snackbar.active");
469
479
  for (let i = 0; i < activeSnackbars.length; i++) removeClass(activeSnackbars[i], "active");
470
480
  addClass(snackbar, "active");
471
- on(snackbar, "click", onClickSnackbar);
481
+ onWeak(snackbar, "click", onClickSnackbar);
472
482
  if (_timeoutSnackbar) clearTimeout(_timeoutSnackbar);
473
483
  if (milliseconds === -1) return;
474
484
  _timeoutSnackbar = setTimeout(() => {
@@ -504,7 +514,26 @@ function updateRipple(e) {
504
514
  }
505
515
  function updateAllRipples() {
506
516
  const ripples = queryAll(".slow-ripple, .ripple, .fast-ripple");
507
- for (let i = 0; i < ripples.length; i++) on(ripples[i], "pointerdown", onPointerDownRipple);
517
+ for (let i = 0; i < ripples.length; i++) onWeak(ripples[i], "pointerdown", onPointerDownRipple);
518
+ }
519
+ function onInputDocument(e) {
520
+ const progress = e.target;
521
+ if (hasTag(progress, "progress")) {
522
+ updateProgress(progress);
523
+ } else {
524
+ updateAllProgress();
525
+ }
526
+ }
527
+ function updateProgress(progress) {
528
+ progress.style.setProperty("--_value", String(progress.value));
529
+ }
530
+ function updateAllProgress() {
531
+ if (isChrome && !isMac && !isIOS) return;
532
+ const body = document.body;
533
+ const progresses = queryAll("progress");
534
+ if (!progresses.length) off(body, "input", onInputDocument, false);
535
+ else on(body, "input", onInputDocument, false);
536
+ for (let i = 0; i < progresses.length; i++) updateProgress(progresses[i]);
508
537
  }
509
538
  const _context = globalThis;
510
539
  let _timeoutMutation;
@@ -560,8 +589,8 @@ function setup() {
560
589
  function updateAllDataUis() {
561
590
  const elements = queryAll("[data-ui]");
562
591
  for (let i = 0, n = elements.length; i < n; i++) {
563
- on(elements[i], "click", onClickElement);
564
- if (hasTag(elements[i], "a") && !elements[i].getAttribute("href")) on(elements[i], "keydown", onKeydownElement);
592
+ onWeak(elements[i], "click", onClickElement);
593
+ if (hasTag(elements[i], "a") && !elements[i].getAttribute("href")) onWeak(elements[i], "keydown", onKeydownElement);
565
594
  }
566
595
  }
567
596
  function _ui(selector, options) {
@@ -581,6 +610,7 @@ function _ui(selector, options) {
581
610
  updateAllFields();
582
611
  updateAllSliders();
583
612
  updateAllRipples();
613
+ updateAllProgress();
584
614
  }
585
615
  function start() {
586
616
  var _a;