beercss 3.6.13 → 3.7.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,12 +1,135 @@
1
- let _timeoutSnackbar;
2
- let _timeoutMutation;
1
+ const _dialogs = [];
2
+ function onKeydownDialog(e) {
3
+ if (e.key === "Escape") {
4
+ const dialog = e.currentTarget;
5
+ updateDialog(dialog, dialog);
6
+ }
7
+ }
8
+ function closeDialog(dialog, overlay) {
9
+ removeClass(queryAllDataUi(dialog.id), "active");
10
+ removeClass(dialog, "active");
11
+ removeClass(overlay, "active");
12
+ dialog.close();
13
+ _dialogs.pop();
14
+ const previousDialog = _dialogs[_dialogs.length - 1];
15
+ if (previousDialog)
16
+ previousDialog.focus();
17
+ else if (isTouchable())
18
+ document.body.classList.remove("no-scroll");
19
+ }
20
+ async function openDialog(dialog, overlay, isModal, from) {
21
+ if (!hasTag(from, "button") && !hasClass(from, "button") && !hasClass(from, "chip"))
22
+ addClass(from, "active");
23
+ addClass(overlay, "active");
24
+ addClass(dialog, "active");
25
+ if (isModal)
26
+ dialog.showModal();
27
+ else
28
+ dialog.show();
29
+ await wait(90);
30
+ if (!isModal)
31
+ on(dialog, "keydown", onKeydownDialog, false);
32
+ _dialogs.push(dialog);
33
+ dialog.focus();
34
+ if (isTouchable())
35
+ document.body.classList.add("no-scroll");
36
+ }
37
+ function onClickOverlay(e) {
38
+ const overlay = e.currentTarget;
39
+ const dialog = next(overlay);
40
+ if (hasTag(dialog, "dialog"))
41
+ closeDialog(dialog, overlay);
42
+ }
43
+ async function updateDialog(from, dialog) {
44
+ blurActiveElement();
45
+ let overlay = prev(dialog);
46
+ const isActive = hasClass(dialog, "active") || dialog.open;
47
+ const isModal = hasClass(dialog, "modal");
48
+ if (!isModal)
49
+ off(dialog, "keydown", onKeydownDialog, false);
50
+ if (!hasClass(overlay, "overlay")) {
51
+ overlay = create({ class: "overlay" });
52
+ insertBefore(overlay, dialog);
53
+ await wait(90);
54
+ }
55
+ if (!isModal)
56
+ on(overlay, "click", onClickOverlay, false);
57
+ if (isActive)
58
+ closeDialog(dialog, overlay);
59
+ else
60
+ openDialog(dialog, overlay, isModal, from);
61
+ }
3
62
  let _timeoutMenu;
4
- let _mutation;
5
- const _lastTheme = {
6
- light: "",
7
- dark: ""
8
- };
63
+ function onClickDocument(e) {
64
+ off(document.body, "click", onClickDocument);
65
+ const body = e.target;
66
+ const menus = queryAll("menu.active");
67
+ for (let i = 0; i < menus.length; i++)
68
+ updateMenu(body, menus[i], e);
69
+ }
70
+ function focusOnMenuOrInput(menu) {
71
+ setTimeout(() => {
72
+ const input = query(".field > input", menu);
73
+ if (input)
74
+ input.focus();
75
+ else
76
+ menu.focus();
77
+ }, 90);
78
+ }
79
+ function updateMenu(from, menu, e) {
80
+ if (_timeoutMenu)
81
+ clearTimeout(_timeoutMenu);
82
+ _timeoutMenu = setTimeout(() => {
83
+ on(document.body, "click", onClickDocument);
84
+ if (!hasTag(document.activeElement, "input"))
85
+ blurActiveElement();
86
+ const isActive = hasClass(menu, "active");
87
+ const isEvent = !!((e == null ? void 0 : e.target) === from);
88
+ const isChild = !!from.closest("menu");
89
+ if (!isActive && isChild || isActive && isEvent) {
90
+ removeClass(menu, "active");
91
+ return;
92
+ }
93
+ removeClass(queryAll("menu.active"), "active");
94
+ addClass(menu, "active");
95
+ focusOnMenuOrInput(menu);
96
+ }, 90);
97
+ }
98
+ function updatePage(page) {
99
+ const container = parent(page);
100
+ if (container)
101
+ removeClass(queryAll(".page", container), "active");
102
+ addClass(page, "active");
103
+ }
104
+ let _timeoutSnackbar;
105
+ function onClickSnackbar(e) {
106
+ const snackbar = e.currentTarget;
107
+ removeClass(snackbar, "active");
108
+ if (_timeoutSnackbar)
109
+ clearTimeout(_timeoutSnackbar);
110
+ }
111
+ function updateSnackbar(snackbar, milliseconds) {
112
+ blurActiveElement();
113
+ const activeSnackbars = queryAll(".snackbar.active");
114
+ for (let i = 0; i < activeSnackbars.length; i++)
115
+ removeClass(activeSnackbars[i], "active");
116
+ addClass(snackbar, "active");
117
+ on(snackbar, "click", onClickSnackbar);
118
+ if (_timeoutSnackbar)
119
+ clearTimeout(_timeoutSnackbar);
120
+ if (milliseconds === -1)
121
+ return;
122
+ _timeoutSnackbar = setTimeout(() => {
123
+ removeClass(snackbar, "active");
124
+ }, milliseconds ?? 6e3);
125
+ }
9
126
  const _emptyNodeList = [];
127
+ function isTouchable() {
128
+ return window.matchMedia("(pointer: coarse)").matches;
129
+ }
130
+ function isDark() {
131
+ return window.matchMedia("(prefers-color-scheme: dark)").matches;
132
+ }
10
133
  async function wait(milliseconds) {
11
134
  await new Promise((resolve) => setTimeout(resolve, milliseconds));
12
135
  }
@@ -32,8 +155,7 @@ function queryAll(selector, element) {
32
155
  }
33
156
  }
34
157
  function hasClass(element, name) {
35
- var _a;
36
- return ((_a = element == null ? void 0 : element.classList) == null ? void 0 : _a.contains(name)) ?? false;
158
+ return (element == null ? void 0 : element.classList.contains(name)) ?? false;
37
159
  }
38
160
  function hasTag(element, name) {
39
161
  var _a;
@@ -44,18 +166,26 @@ function hasType(element, name) {
44
166
  return ((_a = element == null ? void 0 : element.type) == null ? void 0 : _a.toLowerCase()) === name;
45
167
  }
46
168
  function addClass(element, name) {
47
- var _a;
48
- (_a = element == null ? void 0 : element.classList) == null ? void 0 : _a.add(name);
169
+ if (element instanceof NodeList)
170
+ for (let i = 0; i < element.length; i++)
171
+ element[i].classList.add(name);
172
+ else
173
+ element == null ? void 0 : element.classList.add(name);
49
174
  }
50
175
  function removeClass(element, name) {
51
- var _a;
52
- (_a = element == null ? void 0 : element.classList) == null ? void 0 : _a.remove(name);
176
+ if (element instanceof NodeList)
177
+ for (let i = 0; i < element.length; i++)
178
+ element[i].classList.remove(name);
179
+ else
180
+ element == null ? void 0 : element.classList.remove(name);
53
181
  }
54
182
  function on(element, name, callback, useCapture = true) {
55
- element == null ? void 0 : element.addEventListener(name, callback, useCapture);
183
+ if (element == null ? void 0 : element.addEventListener)
184
+ element.addEventListener(name, callback, useCapture);
56
185
  }
57
186
  function off(element, name, callback, useCapture = true) {
58
- element == null ? void 0 : element.removeEventListener(name, callback, useCapture);
187
+ if (element == null ? void 0 : element.removeEventListener)
188
+ element.removeEventListener(name, callback, useCapture);
59
189
  }
60
190
  function insertBefore(newElement, element) {
61
191
  var _a;
@@ -79,122 +209,236 @@ function create(htmlAttributesAsJson) {
79
209
  }
80
210
  return element;
81
211
  }
82
- function updateInput(target) {
83
- const input = target;
84
- if (hasType(input, "number") && !input.value)
85
- input.value = "";
86
- if (!input.placeholder)
87
- input.placeholder = " ";
88
- if (target.getAttribute("data-ui"))
89
- void open(target, null);
212
+ function blurActiveElement() {
213
+ var _a;
214
+ (_a = document.activeElement) == null ? void 0 : _a.blur();
90
215
  }
91
- function onClickElement(e) {
92
- void open(e.currentTarget, null, null, e);
216
+ function queryAllDataUi(id) {
217
+ return queryAll('[data-ui="#' + id + '"]');
218
+ }
219
+ function queryDataUi(id) {
220
+ return query('[data-ui="#' + id + '"]');
221
+ }
222
+ function updateAllClickable(element) {
223
+ if (element.id && hasClass(element, "page"))
224
+ element = queryDataUi(element.id) ?? element;
225
+ const container = parent(element);
226
+ if (!hasClass(container, "tabs") && !hasClass(container, "tabbed") && !hasTag(container, "nav"))
227
+ return;
228
+ const as = queryAll("a", container);
229
+ for (let i = 0; i < as.length; i++)
230
+ removeClass(as[i], "active");
231
+ addClass(element, "active");
232
+ }
233
+ async function run(from, to, options, e) {
234
+ if (!to) {
235
+ to = query(from.getAttribute("data-ui"));
236
+ if (!to)
237
+ return;
238
+ }
239
+ updateAllClickable(from);
240
+ if (hasTag(to, "dialog")) {
241
+ await updateDialog(from, to);
242
+ return;
243
+ }
244
+ if (hasTag(to, "menu")) {
245
+ updateMenu(from, to, e);
246
+ return;
247
+ }
248
+ if (hasClass(to, "snackbar")) {
249
+ updateSnackbar(to, options);
250
+ return;
251
+ }
252
+ if (hasClass(to, "page")) {
253
+ updatePage(to);
254
+ return;
255
+ }
256
+ if (hasClass(to, "active")) {
257
+ removeClass(from, "active");
258
+ removeClass(to, "active");
259
+ return;
260
+ }
261
+ addClass(to, "active");
93
262
  }
94
263
  function onClickLabel(e) {
95
- const target = e.currentTarget;
96
- const parentTarget = parent(target);
97
- const input = query("input:not([type=file], [type=checkbox], [type=radio]), select, textarea", parentTarget);
264
+ const label = e.currentTarget;
265
+ const field = parent(label);
266
+ const input = query("input:not([type=file], [type=checkbox], [type=radio]), select, textarea", field);
98
267
  if (input)
99
268
  input.focus();
100
269
  }
101
270
  function onFocusInput(e) {
102
- const target = e.currentTarget;
103
- updateInput(target);
271
+ const input = e.currentTarget;
272
+ updateInput(input);
104
273
  }
105
274
  function onBlurInput(e) {
106
- const target = e.currentTarget;
107
- updateInput(target);
108
- }
109
- function onClickDocument(e) {
110
- off(document.body, "click", onClickDocument);
111
- const target = e.target;
112
- const menus = queryAll("menu.active");
113
- for (let i = 0, n = menus.length; i < n; i++)
114
- menu(target, menus[i], e);
115
- }
116
- function onClickSnackbar(e) {
117
- const target = e.currentTarget;
118
- removeClass(target, "active");
119
- if (_timeoutSnackbar)
120
- clearTimeout(_timeoutSnackbar);
275
+ const input = e.currentTarget;
276
+ updateInput(input);
121
277
  }
122
278
  function onChangeFile(e) {
123
- const target = e.currentTarget;
124
- updateFile(target);
279
+ const input = e.currentTarget;
280
+ updateFile(input);
125
281
  }
126
282
  function onChangeColor(e) {
127
- const target = e.currentTarget;
128
- updateColor(target);
283
+ const input = e.currentTarget;
284
+ updateColor(input);
129
285
  }
130
286
  function onKeydownFile(e) {
131
- const target = e.currentTarget;
132
- updateFile(target, e);
287
+ const input = e.currentTarget;
288
+ updateFile(input, e);
133
289
  }
134
290
  function onKeydownColor(e) {
135
- const target = e.currentTarget;
136
- updateColor(target, e);
291
+ const input = e.currentTarget;
292
+ updateColor(input, e);
137
293
  }
138
294
  function onInputTextarea(e) {
139
- const target = e.currentTarget;
140
- updateTextarea(target);
295
+ const textarea = e.currentTarget;
296
+ updateTextarea(textarea);
141
297
  }
142
- function onMutation() {
143
- if (_timeoutMutation)
144
- clearTimeout(_timeoutMutation);
145
- _timeoutMutation = setTimeout(() => {
146
- void ui();
147
- }, 180);
148
- }
149
- function updateFile(target, e) {
150
- if (e && e.key === "Enter") {
151
- const previousTarget = prev(target);
152
- if (!hasType(previousTarget, "file"))
298
+ function updateAllLabels() {
299
+ const labels = queryAll(".field > label");
300
+ for (let i = 0; i < labels.length; i++)
301
+ on(labels[i], "click", onClickLabel);
302
+ }
303
+ function updateAllInputs() {
304
+ const inputs = queryAll(".field > input:not([type=file], [type=color], [type=range])");
305
+ for (let i = 0; i < inputs.length; i++) {
306
+ on(inputs[i], "focus", onFocusInput);
307
+ on(inputs[i], "blur", onBlurInput);
308
+ updateInput(inputs[i]);
309
+ }
310
+ }
311
+ function updateAllSelects() {
312
+ const selects = queryAll(".field > select");
313
+ for (let i = 0; i < selects.length; i++) {
314
+ on(selects[i], "focus", onFocusInput);
315
+ on(selects[i], "blur", onBlurInput);
316
+ }
317
+ }
318
+ function updateAllFiles() {
319
+ const files = queryAll(".field > input[type=file]");
320
+ for (let i = 0; i < files.length; i++) {
321
+ on(files[i], "change", onChangeFile);
322
+ updateFile(files[i]);
323
+ }
324
+ }
325
+ function updateAllColors() {
326
+ const colors = queryAll(".field > input[type=color]");
327
+ for (let i = 0; i < colors.length; i++) {
328
+ on(colors[i], "change", onChangeColor);
329
+ updateColor(colors[i]);
330
+ }
331
+ }
332
+ function updateAllTextareas() {
333
+ const textareas = queryAll(".field.textarea > textarea");
334
+ for (let i = 0; i < textareas.length; i++) {
335
+ on(textareas[i], "focus", onFocusInput);
336
+ on(textareas[i], "blur", onBlurInput);
337
+ on(textareas[i], "input", onInputTextarea);
338
+ updateTextarea(textareas[i]);
339
+ }
340
+ }
341
+ function updateInput(input) {
342
+ if (hasType(input, "number") && !input.value)
343
+ input.value = "";
344
+ if (!input.placeholder)
345
+ input.placeholder = " ";
346
+ if (input.getAttribute("data-ui"))
347
+ run(input, null);
348
+ }
349
+ function updateFile(input, e) {
350
+ if ((e == null ? void 0 : e.key) === "Enter") {
351
+ const previousInput = prev(input);
352
+ if (!hasType(previousInput, "file"))
153
353
  return;
154
- previousTarget.click();
354
+ previousInput.click();
155
355
  return;
156
356
  }
157
- const currentTarget = target;
158
- const nextTarget = next(target);
159
- if (!hasType(nextTarget, "text"))
357
+ const nextInput = next(input);
358
+ if (!hasType(nextInput, "text"))
160
359
  return;
161
- nextTarget.value = currentTarget.files ? Array.from(currentTarget.files).map((x) => x.name).join(", ") : "";
162
- nextTarget.readOnly = true;
163
- on(nextTarget, "keydown", onKeydownFile, false);
164
- updateInput(nextTarget);
165
- }
166
- function updateColor(target, e) {
167
- if (e && e.key === "Enter") {
168
- const previousTarget = prev(target);
169
- if (!hasType(previousTarget, "color"))
360
+ nextInput.value = input.files ? Array.from(input.files).map((x) => x.name).join(", ") : "";
361
+ nextInput.readOnly = true;
362
+ on(nextInput, "keydown", onKeydownFile, false);
363
+ updateInput(nextInput);
364
+ }
365
+ function updateColor(input, e) {
366
+ if ((e == null ? void 0 : e.key) === "Enter") {
367
+ const previousInput = prev(input);
368
+ if (!hasType(previousInput, "color"))
170
369
  return;
171
- previousTarget.click();
370
+ previousInput.click();
172
371
  return;
173
372
  }
174
- const currentTarget = target;
175
- const nextTarget = next(target);
176
- if (!hasType(nextTarget, "text"))
373
+ const nextInput = next(input);
374
+ if (!hasType(nextInput, "text"))
177
375
  return;
178
- nextTarget.readOnly = true;
179
- nextTarget.value = currentTarget.value;
180
- on(nextTarget, "keydown", onKeydownColor, false);
181
- updateInput(nextTarget);
182
- }
183
- function updateTextarea(target) {
184
- const parentTarget = parent(target);
185
- const currentTarget = parent(target);
186
- parentTarget.removeAttribute("style");
187
- if (hasClass(parentTarget, "min"))
188
- parentTarget.style.setProperty("---size", `${Math.max(target.scrollHeight, currentTarget.offsetHeight)}px`);
189
- }
190
- function updateRange(target) {
191
- const parentTarget = parent(target);
192
- const bar = query("span", parentTarget);
193
- const inputs = queryAll("input", parentTarget);
376
+ nextInput.readOnly = true;
377
+ nextInput.value = input.value;
378
+ on(nextInput, "keydown", onKeydownColor, false);
379
+ updateInput(nextInput);
380
+ }
381
+ function updateTextarea(textarea) {
382
+ const field = parent(textarea);
383
+ field.removeAttribute("style");
384
+ if (hasClass(field, "min"))
385
+ field.style.setProperty("---size", `${Math.max(textarea.scrollHeight, field.offsetHeight)}px`);
386
+ }
387
+ function updateAllFields() {
388
+ updateAllLabels();
389
+ updateAllInputs();
390
+ updateAllSelects();
391
+ updateAllFiles();
392
+ updateAllColors();
393
+ updateAllTextareas();
394
+ }
395
+ function onInputDocument(e) {
396
+ const input = e.target;
397
+ if (!hasTag(input, "input") && !hasTag(input, "select"))
398
+ return;
399
+ if (input.type === "range") {
400
+ input.focus();
401
+ updateRange(input);
402
+ } else {
403
+ updateAllRanges();
404
+ }
405
+ }
406
+ function onFocusRange(e) {
407
+ if (!isTouchable())
408
+ return;
409
+ const input = e.target;
410
+ const label = parent(input);
411
+ if (hasClass(label, "vertical"))
412
+ document.body.classList.add("no-scroll");
413
+ }
414
+ function onBlurRange(e) {
415
+ if (!isTouchable())
416
+ return;
417
+ const input = e.target;
418
+ const label = parent(input);
419
+ if (hasClass(label, "vertical"))
420
+ document.body.classList.remove("no-scroll");
421
+ }
422
+ function updateAllRanges() {
423
+ const body = document.body;
424
+ const ranges = queryAll(".slider > input[type=range]");
425
+ if (!ranges.length)
426
+ off(body, "input", onInputDocument, false);
427
+ else
428
+ on(body, "input", onInputDocument, false);
429
+ for (let i = 0; i < ranges.length; i++)
430
+ updateRange(ranges[i]);
431
+ }
432
+ function updateRange(input) {
433
+ on(input, "focus", onFocusRange);
434
+ on(input, "blur", onBlurRange);
435
+ const label = parent(input);
436
+ const bar = query("span", label);
437
+ const inputs = queryAll("input", label);
194
438
  if (!inputs.length || !bar)
195
439
  return;
196
440
  const rootSize = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--size")) || 16;
197
- const thumb = hasClass(parentTarget, "max") ? 0 : 0.25 * rootSize * 100 / inputs[0].offsetWidth;
441
+ const thumb = hasClass(label, "max") ? 0 : 0.25 * rootSize * 100 / inputs[0].offsetWidth;
198
442
  const percents = [];
199
443
  const values = [];
200
444
  for (let i = 0, n = inputs.length; i < n; i++) {
@@ -207,187 +451,45 @@ function updateRange(target) {
207
451
  values.push(value);
208
452
  }
209
453
  let percent = percents[0];
210
- let start = 0;
211
- let end = 100 - start - percent;
454
+ let start2 = 0;
455
+ let end = 100 - start2 - percent;
212
456
  let value1 = values[0];
213
457
  let value2 = values[1] || 0;
214
458
  if (inputs.length > 1) {
215
459
  percent = Math.abs(percents[1] - percents[0]);
216
- start = percents[1] > percents[0] ? percents[0] : percents[1];
217
- end = 100 - start - percent;
460
+ start2 = percents[1] > percents[0] ? percents[0] : percents[1];
461
+ end = 100 - start2 - percent;
218
462
  if (value2 > value1) {
219
463
  value1 = values[1] || 0;
220
464
  value2 = values[0];
221
465
  }
222
466
  }
223
- parentTarget.style.setProperty("---start", `${start}%`);
224
- parentTarget.style.setProperty("---end", `${end}%`);
225
- parentTarget.style.setProperty("---value1", `'${value1}'`);
226
- parentTarget.style.setProperty("---value2", `'${value2}'`);
227
- }
228
- function updateAllRanges(e) {
229
- if (e) {
230
- const input = e.target;
231
- if (input.type === "range") {
232
- updateRange(input);
233
- return;
234
- }
235
- }
236
- const ranges = queryAll(".slider > input[type=range]");
237
- if (!ranges.length)
238
- off(globalThis, "input", updateAllRanges, false);
239
- else
240
- on(globalThis, "input", updateAllRanges, false);
241
- for (let i = 0, n = ranges.length; i < n; i++)
242
- updateRange(ranges[i]);
243
- }
244
- async function open(from, to, options, e) {
245
- if (!to) {
246
- to = query(from.getAttribute("data-ui"));
247
- if (!to)
248
- return;
249
- }
250
- if (hasTag(to, "dialog")) {
251
- await dialog(from, to);
252
- return;
253
- }
254
- if (hasTag(to, "menu")) {
255
- menu(from, to, e);
256
- return;
257
- }
258
- if (hasClass(to, "snackbar")) {
259
- snackbar(from, to, options);
260
- return;
261
- }
262
- if (hasClass(to, "page")) {
263
- page(from, to);
264
- return;
265
- }
266
- tab(from);
267
- if (hasClass(to, "active")) {
268
- removeClass(to, "active");
269
- return;
270
- }
271
- addClass(to, "active");
272
- }
273
- function tab(from) {
274
- if (from.id && hasClass(from, "page"))
275
- from = query(`[data-ui="#${from.id}"]`) ?? from;
276
- const container = parent(from);
277
- if (!hasClass(container, "tabs"))
278
- return;
279
- const tabs = queryAll("a", container);
280
- for (let i = 0, n = tabs.length; i < n; i++)
281
- removeClass(tabs[i], "active");
282
- addClass(from, "active");
283
- }
284
- function page(from, to) {
285
- tab(from);
286
- const container = parent(to);
287
- if (container) {
288
- for (let i = 0, n = container.children.length; i < n; i++) {
289
- if (hasClass(container.children[i], "page"))
290
- removeClass(container.children[i], "active");
291
- }
292
- }
293
- addClass(to, "active");
294
- }
295
- function menu(from, to, e) {
296
- if (_timeoutMenu)
297
- clearTimeout(_timeoutMenu);
298
- _timeoutMenu = setTimeout(() => {
299
- on(document.body, "click", onClickDocument);
300
- const activeElement = document.activeElement;
301
- if (!hasTag(activeElement, "input"))
302
- activeElement == null ? void 0 : activeElement.blur();
303
- tab(from);
304
- const isActive = hasClass(to, "active");
305
- const isEvent = !!((e == null ? void 0 : e.target) === from);
306
- const isChild = !!from.closest("menu");
307
- if (!isActive && isChild || isActive && isEvent) {
308
- removeClass(to, "active");
309
- return;
310
- }
311
- const menus = queryAll("menu.active");
312
- for (let i = 0, n = menus.length; i < n; i++)
313
- removeClass(menus[i], "active");
314
- addClass(to, "active");
315
- }, 90);
467
+ label.style.setProperty("---start", `${start2}%`);
468
+ label.style.setProperty("---end", `${end}%`);
469
+ label.style.setProperty("---value1", `'${value1}'`);
470
+ label.style.setProperty("---value2", `'${value2}'`);
316
471
  }
317
- async function dialog(from, to) {
318
- var _a;
319
- (_a = document.activeElement) == null ? void 0 : _a.blur();
320
- tab(from);
321
- let overlay = prev(to);
322
- const target = to;
323
- const isActive = hasClass(to, "active") || target.open;
324
- const isModal = hasClass(to, "modal");
325
- const container = parent(to);
326
- const isNav = hasTag(container, "nav");
327
- if (!hasClass(overlay, "overlay")) {
328
- overlay = create({ class: "overlay" });
329
- insertBefore(overlay, to);
330
- await wait(90);
331
- }
332
- overlay.onclick = () => {
333
- if (isModal)
334
- return;
335
- removeClass(from, "active");
336
- removeClass(to, "active");
337
- removeClass(overlay, "active");
338
- target.close();
339
- };
340
- if (isNav) {
341
- const elements = queryAll("dialog, a, .overlay", container);
342
- for (let i = 0, n = elements.length; i < n; i++) {
343
- const element = elements[i];
344
- removeClass(element, "active");
345
- if (element.open)
346
- element.close();
347
- }
348
- }
349
- if (isActive) {
350
- removeClass(from, "active");
351
- removeClass(overlay, "active");
352
- removeClass(to, "active");
353
- target.close();
354
- } else {
355
- if (!hasTag(from, "button") && !hasClass(from, "button") && !hasClass(from, "chip"))
356
- addClass(from, "active");
357
- addClass(overlay, "active");
358
- addClass(to, "active");
359
- if (isModal)
360
- target.showModal();
361
- else
362
- target.show();
363
- }
472
+ function updateAllSliders() {
473
+ updateAllRanges();
364
474
  }
365
- function snackbar(from, to, milliseconds) {
475
+ const _lastTheme = {
476
+ light: "",
477
+ dark: ""
478
+ };
479
+ function getMode() {
366
480
  var _a;
367
- (_a = document.activeElement) == null ? void 0 : _a.blur();
368
- tab(from);
369
- const elements = queryAll(".snackbar.active");
370
- for (let i = 0, n = elements.length; i < n; i++)
371
- removeClass(elements[i], "active");
372
- addClass(to, "active");
373
- on(to, "click", onClickSnackbar);
374
- if (_timeoutSnackbar)
375
- clearTimeout(_timeoutSnackbar);
376
- if (milliseconds === -1)
377
- return;
378
- _timeoutSnackbar = setTimeout(() => {
379
- removeClass(to, "active");
380
- }, milliseconds ?? 6e3);
481
+ return ((_a = document == null ? void 0 : document.body) == null ? void 0 : _a.classList.contains("dark")) ? "dark" : "light";
381
482
  }
382
483
  function lastTheme() {
383
484
  if (_lastTheme.light && _lastTheme.dark)
384
485
  return _lastTheme;
486
+ const body = document.body;
385
487
  const light = document.createElement("body");
386
488
  light.className = "light";
387
- document.body.appendChild(light);
489
+ body.appendChild(light);
388
490
  const dark = document.createElement("body");
389
491
  dark.className = "dark";
390
- document.body.appendChild(dark);
492
+ body.appendChild(dark);
391
493
  const fromLight = getComputedStyle(light);
392
494
  const fromDark = getComputedStyle(dark);
393
495
  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"];
@@ -395,21 +497,23 @@ function lastTheme() {
395
497
  _lastTheme.light += variables[i] + ":" + fromLight.getPropertyValue(variables[i]) + ";";
396
498
  _lastTheme.dark += variables[i] + ":" + fromDark.getPropertyValue(variables[i]) + ";";
397
499
  }
398
- document.body.removeChild(light);
399
- document.body.removeChild(dark);
500
+ body.removeChild(light);
501
+ body.removeChild(dark);
400
502
  return _lastTheme;
401
503
  }
402
- function theme(source) {
403
- if (!source || !globalThis.materialDynamicColors)
504
+ function updateTheme(source) {
505
+ const context = globalThis;
506
+ const body = document.body;
507
+ if (!source || !context.materialDynamicColors)
404
508
  return lastTheme();
405
- const mode2 = /dark/i.test(document.body.className) ? "dark" : "light";
509
+ const mode = getMode();
406
510
  if (source.light && source.dark) {
407
511
  _lastTheme.light = source.light;
408
512
  _lastTheme.dark = source.dark;
409
- document.body.setAttribute("style", source[mode2]);
513
+ body.setAttribute("style", source[mode]);
410
514
  return source;
411
515
  }
412
- return globalThis.materialDynamicColors(source).then((theme2) => {
516
+ return context.materialDynamicColors(source).then((theme) => {
413
517
  const toCss = (data) => {
414
518
  let style = "";
415
519
  for (let i = 0, keys = Object.keys(data), n = keys.length; i < n; i++) {
@@ -420,21 +524,37 @@ function theme(source) {
420
524
  }
421
525
  return style;
422
526
  };
423
- _lastTheme.light = toCss(theme2.light);
424
- _lastTheme.dark = toCss(theme2.dark);
425
- document.body.setAttribute("style", _lastTheme[mode2]);
527
+ _lastTheme.light = toCss(theme.light);
528
+ _lastTheme.dark = toCss(theme.dark);
529
+ body.setAttribute("style", _lastTheme[mode]);
426
530
  return _lastTheme;
427
531
  });
428
532
  }
429
- function mode(value) {
533
+ function updateMode(value) {
534
+ const context = globalThis;
535
+ const body = document.body;
536
+ if (!body)
537
+ return value;
430
538
  if (!value)
431
- return /dark/i.test(document.body.className) ? "dark" : "light";
432
- document.body.classList.remove("light", "dark");
433
- document.body.classList.add(value);
539
+ return getMode();
540
+ if (value === "auto")
541
+ value = isDark() ? "dark" : "light";
542
+ body.classList.remove("light", "dark");
543
+ body.classList.add(value);
434
544
  const lastThemeStyle = value === "light" ? _lastTheme.light : _lastTheme.dark;
435
- if (globalThis.materialDynamicColors)
436
- document.body.setAttribute("style", lastThemeStyle);
437
- return value;
545
+ if (context.materialDynamicColors)
546
+ body.setAttribute("style", lastThemeStyle);
547
+ return getMode();
548
+ }
549
+ let _timeoutMutation;
550
+ let _mutation;
551
+ function onMutation() {
552
+ if (_timeoutMutation)
553
+ clearTimeout(_timeoutMutation);
554
+ _timeoutMutation = setTimeout(async () => await ui(), 180);
555
+ }
556
+ function onClickElement(e) {
557
+ run(e.currentTarget, null, null, e);
438
558
  }
439
559
  function setup() {
440
560
  if (_mutation)
@@ -443,6 +563,11 @@ function setup() {
443
563
  _mutation.observe(document.body, { childList: true, subtree: true });
444
564
  onMutation();
445
565
  }
566
+ function updateAllDataUis() {
567
+ const elements = queryAll("[data-ui]");
568
+ for (let i = 0, n = elements.length; i < n; i++)
569
+ on(elements[i], "click", onClickElement);
570
+ }
446
571
  function ui(selector, options) {
447
572
  if (selector) {
448
573
  if (selector === "setup") {
@@ -452,50 +577,28 @@ function ui(selector, options) {
452
577
  if (selector === "guid")
453
578
  return guid();
454
579
  if (selector === "mode")
455
- return mode(options);
580
+ return updateMode(options);
456
581
  if (selector === "theme")
457
- return theme(options);
582
+ return updateTheme(options);
458
583
  const to = query(selector);
459
584
  if (!to)
460
585
  return;
461
- void open(to, to, options);
586
+ run(to, to, options);
462
587
  }
463
- const elements = queryAll("[data-ui]");
464
- for (let i = 0, n = elements.length; i < n; i++)
465
- on(elements[i], "click", onClickElement);
466
- const labels = queryAll(".field > label");
467
- for (let i = 0, n = labels.length; i < n; i++)
468
- on(labels[i], "click", onClickLabel);
469
- const inputs = queryAll(".field > input:not([type=file], [type=color], [type=range]), .field > select, .field > textarea");
470
- for (let i = 0, n = inputs.length; i < n; i++) {
471
- const input = inputs[i];
472
- on(input, "focus", onFocusInput);
473
- on(input, "blur", onBlurInput);
474
- updateInput(input);
475
- }
476
- const files = queryAll(".field > input[type=file]");
477
- for (let i = 0, n = files.length; i < n; i++) {
478
- const file = files[i];
479
- on(file, "change", onChangeFile);
480
- updateFile(file);
481
- }
482
- const colors = queryAll(".field > input[type=color]");
483
- for (let i = 0, n = colors.length; i < n; i++) {
484
- const color = colors[i];
485
- on(color, "change", onChangeColor);
486
- updateColor(color);
487
- }
488
- const textareas = queryAll(".field.textarea > textarea");
489
- for (let i = 0, n = textareas.length; i < n; i++) {
490
- const textarea = textareas[i];
491
- on(textarea, "input", onInputTextarea);
492
- updateTextarea(textarea);
493
- }
494
- updateAllRanges();
588
+ updateAllDataUis();
589
+ updateAllFields();
590
+ updateAllSliders();
495
591
  }
496
- if (globalThis.addEventListener)
497
- globalThis.addEventListener("load", async () => await ui("setup"));
498
- globalThis.beercss = ui;
499
- globalThis.ui = ui;
592
+ function start() {
593
+ var _a;
594
+ const context = globalThis;
595
+ const body = (_a = context == null ? void 0 : context.document) == null ? void 0 : _a.body;
596
+ if (body && !body.classList.contains("dark") && !body.classList.contains("light"))
597
+ updateMode("auto");
598
+ on(context, "load", setup, false);
599
+ context.beercss = ui;
600
+ context.ui = ui;
601
+ }
602
+ start();
500
603
 
501
604
  export default globalThis.ui;