beercss 3.5.7 → 3.6.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/README.md +9 -9
- package/dist/cdn/beer.css +4107 -0
- package/dist/cdn/beer.js +500 -0
- package/dist/cdn/beer.min.css +1 -1
- package/dist/cdn/beer.min.js +1 -1
- package/index.d.ts +6 -5
- package/package.json +32 -25
- package/src/cdn/beer.ts +27 -27
- package/src/cdn/elements/dialogs.css +0 -8
- package/src/cdn/elements/menus.css +20 -1
- package/src/cdn/elements/navigations.css +35 -0
- package/src/cdn/elements/tabs.css +13 -15
- package/src/cdn/helpers/waves.css +6 -4
- package/src/cdn/interfaces.ts +4 -0
- package/src/cdn/settings/fonts.css +3 -3
package/dist/cdn/beer.js
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
let _timeoutSnackbar;
|
|
2
|
+
let _timeoutMutation;
|
|
3
|
+
let _timeoutMenu;
|
|
4
|
+
let _mutation;
|
|
5
|
+
const _lastTheme = {
|
|
6
|
+
light: "",
|
|
7
|
+
dark: ""
|
|
8
|
+
};
|
|
9
|
+
const _emptyNodeList = [];
|
|
10
|
+
async function wait(milliseconds) {
|
|
11
|
+
await new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
12
|
+
}
|
|
13
|
+
function guid() {
|
|
14
|
+
return "fxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
15
|
+
const r = Math.random() * 16 | 0;
|
|
16
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
17
|
+
return v.toString(16);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function query(selector, element) {
|
|
21
|
+
try {
|
|
22
|
+
return typeof selector === "string" ? (element ?? document).querySelector(selector) : selector;
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function queryAll(selector, element) {
|
|
28
|
+
try {
|
|
29
|
+
return typeof selector === "string" ? (element ?? document).querySelectorAll(selector) : selector ?? _emptyNodeList;
|
|
30
|
+
} catch {
|
|
31
|
+
return _emptyNodeList;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function hasClass(element, name) {
|
|
35
|
+
var _a;
|
|
36
|
+
return ((_a = element == null ? void 0 : element.classList) == null ? void 0 : _a.contains(name)) ?? false;
|
|
37
|
+
}
|
|
38
|
+
function hasTag(element, name) {
|
|
39
|
+
var _a;
|
|
40
|
+
return ((_a = element == null ? void 0 : element.tagName) == null ? void 0 : _a.toLowerCase()) === name;
|
|
41
|
+
}
|
|
42
|
+
function hasType(element, name) {
|
|
43
|
+
var _a;
|
|
44
|
+
return ((_a = element == null ? void 0 : element.type) == null ? void 0 : _a.toLowerCase()) === name;
|
|
45
|
+
}
|
|
46
|
+
function addClass(element, name) {
|
|
47
|
+
var _a;
|
|
48
|
+
(_a = element == null ? void 0 : element.classList) == null ? void 0 : _a.add(name);
|
|
49
|
+
}
|
|
50
|
+
function removeClass(element, name) {
|
|
51
|
+
var _a;
|
|
52
|
+
(_a = element == null ? void 0 : element.classList) == null ? void 0 : _a.remove(name);
|
|
53
|
+
}
|
|
54
|
+
function on(element, name, callback, useCapture = true) {
|
|
55
|
+
element == null ? void 0 : element.addEventListener(name, callback, useCapture);
|
|
56
|
+
}
|
|
57
|
+
function off(element, name, callback, useCapture = true) {
|
|
58
|
+
element == null ? void 0 : element.removeEventListener(name, callback, useCapture);
|
|
59
|
+
}
|
|
60
|
+
function insertBefore(newElement, element) {
|
|
61
|
+
var _a;
|
|
62
|
+
(_a = element == null ? void 0 : element.parentNode) == null ? void 0 : _a.insertBefore(newElement, element);
|
|
63
|
+
}
|
|
64
|
+
function prev(element) {
|
|
65
|
+
return element == null ? void 0 : element.previousElementSibling;
|
|
66
|
+
}
|
|
67
|
+
function next(element) {
|
|
68
|
+
return element == null ? void 0 : element.nextElementSibling;
|
|
69
|
+
}
|
|
70
|
+
function parent(element) {
|
|
71
|
+
return element == null ? void 0 : element.parentElement;
|
|
72
|
+
}
|
|
73
|
+
function create(htmlAttributesAsJson) {
|
|
74
|
+
const element = document.createElement("div");
|
|
75
|
+
for (let i = 0, keys = Object.keys(htmlAttributesAsJson), n = keys.length; i < n; i++) {
|
|
76
|
+
const key = keys[i];
|
|
77
|
+
const value = htmlAttributesAsJson[key];
|
|
78
|
+
element.setAttribute(key, value);
|
|
79
|
+
}
|
|
80
|
+
return element;
|
|
81
|
+
}
|
|
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);
|
|
90
|
+
}
|
|
91
|
+
function onClickElement(e) {
|
|
92
|
+
void open(e.currentTarget, null, null, e);
|
|
93
|
+
}
|
|
94
|
+
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);
|
|
98
|
+
if (input)
|
|
99
|
+
input.focus();
|
|
100
|
+
}
|
|
101
|
+
function onFocusInput(e) {
|
|
102
|
+
const target = e.currentTarget;
|
|
103
|
+
updateInput(target);
|
|
104
|
+
}
|
|
105
|
+
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);
|
|
121
|
+
}
|
|
122
|
+
function onChangeFile(e) {
|
|
123
|
+
const target = e.currentTarget;
|
|
124
|
+
updateFile(target);
|
|
125
|
+
}
|
|
126
|
+
function onChangeColor(e) {
|
|
127
|
+
const target = e.currentTarget;
|
|
128
|
+
updateColor(target);
|
|
129
|
+
}
|
|
130
|
+
function onKeydownFile(e) {
|
|
131
|
+
const target = e.currentTarget;
|
|
132
|
+
updateFile(target, e);
|
|
133
|
+
}
|
|
134
|
+
function onKeydownColor(e) {
|
|
135
|
+
const target = e.currentTarget;
|
|
136
|
+
updateColor(target, e);
|
|
137
|
+
}
|
|
138
|
+
function onInputTextarea(e) {
|
|
139
|
+
const target = e.currentTarget;
|
|
140
|
+
updateTextarea(target);
|
|
141
|
+
}
|
|
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"))
|
|
153
|
+
return;
|
|
154
|
+
previousTarget.click();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const currentTarget = target;
|
|
158
|
+
const nextTarget = next(target);
|
|
159
|
+
if (!hasType(nextTarget, "text"))
|
|
160
|
+
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"))
|
|
170
|
+
return;
|
|
171
|
+
previousTarget.click();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const currentTarget = target;
|
|
175
|
+
const nextTarget = next(target);
|
|
176
|
+
if (!hasType(nextTarget, "text"))
|
|
177
|
+
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);
|
|
194
|
+
if (!inputs.length || !bar)
|
|
195
|
+
return;
|
|
196
|
+
const rootSize = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--size")) || 16;
|
|
197
|
+
const thumb = hasClass(parentTarget, "max") ? 0 : 0.25 * rootSize * 100 / inputs[0].offsetWidth;
|
|
198
|
+
const percents = [];
|
|
199
|
+
const values = [];
|
|
200
|
+
for (let i = 0, n = inputs.length; i < n; i++) {
|
|
201
|
+
const min = parseFloat(inputs[i].min) || 0;
|
|
202
|
+
const max = parseFloat(inputs[i].max) || 100;
|
|
203
|
+
const value = parseFloat(inputs[i].value) || 0;
|
|
204
|
+
const percent2 = (value - min) * 100 / (max - min);
|
|
205
|
+
const fix = thumb / 2 - thumb * percent2 / 100;
|
|
206
|
+
percents.push(percent2 + fix);
|
|
207
|
+
values.push(value);
|
|
208
|
+
}
|
|
209
|
+
let percent = percents[0];
|
|
210
|
+
let start = 0;
|
|
211
|
+
let end = 100 - start - percent;
|
|
212
|
+
let value1 = values[0];
|
|
213
|
+
let value2 = values[1] || 0;
|
|
214
|
+
if (inputs.length > 1) {
|
|
215
|
+
percent = Math.abs(percents[1] - percents[0]);
|
|
216
|
+
start = percents[1] > percents[0] ? percents[0] : percents[1];
|
|
217
|
+
end = 100 - start - percent;
|
|
218
|
+
if (value2 > value1) {
|
|
219
|
+
value1 = values[1] || 0;
|
|
220
|
+
value2 = values[0];
|
|
221
|
+
}
|
|
222
|
+
}
|
|
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
|
+
var _a;
|
|
300
|
+
on(document.body, "click", onClickDocument);
|
|
301
|
+
(_a = document.activeElement) == null ? void 0 : _a.blur();
|
|
302
|
+
tab(from);
|
|
303
|
+
const isActive = hasClass(to, "active");
|
|
304
|
+
const isEvent = !!((e == null ? void 0 : e.target) === from);
|
|
305
|
+
const isChild = !!from.closest("menu");
|
|
306
|
+
if (!isActive && isChild || isActive && isEvent) {
|
|
307
|
+
removeClass(to, "active");
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const menus = queryAll("menu.active");
|
|
311
|
+
for (let i = 0, n = menus.length; i < n; i++)
|
|
312
|
+
removeClass(menus[i], "active");
|
|
313
|
+
addClass(to, "active");
|
|
314
|
+
}, 90);
|
|
315
|
+
}
|
|
316
|
+
async function dialog(from, to) {
|
|
317
|
+
var _a;
|
|
318
|
+
(_a = document.activeElement) == null ? void 0 : _a.blur();
|
|
319
|
+
tab(from);
|
|
320
|
+
let overlay = prev(to);
|
|
321
|
+
const target = to;
|
|
322
|
+
const isActive = hasClass(to, "active") || target.open;
|
|
323
|
+
const isModal = hasClass(to, "modal");
|
|
324
|
+
const container = parent(to);
|
|
325
|
+
const isNav = hasTag(container, "nav");
|
|
326
|
+
if (!hasClass(overlay, "overlay")) {
|
|
327
|
+
overlay = create({ class: "overlay" });
|
|
328
|
+
insertBefore(overlay, to);
|
|
329
|
+
await wait(90);
|
|
330
|
+
}
|
|
331
|
+
overlay.onclick = () => {
|
|
332
|
+
if (isModal)
|
|
333
|
+
return;
|
|
334
|
+
removeClass(from, "active");
|
|
335
|
+
removeClass(to, "active");
|
|
336
|
+
removeClass(overlay, "active");
|
|
337
|
+
target.close();
|
|
338
|
+
};
|
|
339
|
+
if (isNav) {
|
|
340
|
+
const elements = queryAll("dialog, a, .overlay", container);
|
|
341
|
+
for (let i = 0, n = elements.length; i < n; i++) {
|
|
342
|
+
const element = elements[i];
|
|
343
|
+
removeClass(element, "active");
|
|
344
|
+
if (element.open)
|
|
345
|
+
element.close();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (isActive) {
|
|
349
|
+
removeClass(from, "active");
|
|
350
|
+
removeClass(overlay, "active");
|
|
351
|
+
removeClass(to, "active");
|
|
352
|
+
target.close();
|
|
353
|
+
} else {
|
|
354
|
+
if (!hasTag(from, "button") && !hasClass(from, "button") && !hasClass(from, "chip"))
|
|
355
|
+
addClass(from, "active");
|
|
356
|
+
addClass(overlay, "active");
|
|
357
|
+
addClass(to, "active");
|
|
358
|
+
if (isModal)
|
|
359
|
+
target.showModal();
|
|
360
|
+
else
|
|
361
|
+
target.show();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function snackbar(from, to, milliseconds) {
|
|
365
|
+
var _a;
|
|
366
|
+
(_a = document.activeElement) == null ? void 0 : _a.blur();
|
|
367
|
+
tab(from);
|
|
368
|
+
const elements = queryAll(".snackbar.active");
|
|
369
|
+
for (let i = 0, n = elements.length; i < n; i++)
|
|
370
|
+
removeClass(elements[i], "active");
|
|
371
|
+
addClass(to, "active");
|
|
372
|
+
on(to, "click", onClickSnackbar);
|
|
373
|
+
if (_timeoutSnackbar)
|
|
374
|
+
clearTimeout(_timeoutSnackbar);
|
|
375
|
+
if (milliseconds === -1)
|
|
376
|
+
return;
|
|
377
|
+
_timeoutSnackbar = setTimeout(() => {
|
|
378
|
+
removeClass(to, "active");
|
|
379
|
+
}, milliseconds ?? 6e3);
|
|
380
|
+
}
|
|
381
|
+
function lastTheme() {
|
|
382
|
+
if (_lastTheme.light && _lastTheme.dark)
|
|
383
|
+
return _lastTheme;
|
|
384
|
+
const light = document.createElement("body");
|
|
385
|
+
light.className = "light";
|
|
386
|
+
document.body.appendChild(light);
|
|
387
|
+
const dark = document.createElement("body");
|
|
388
|
+
dark.className = "dark";
|
|
389
|
+
document.body.appendChild(dark);
|
|
390
|
+
const fromLight = getComputedStyle(light);
|
|
391
|
+
const fromDark = getComputedStyle(dark);
|
|
392
|
+
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"];
|
|
393
|
+
for (let i = 0, n = variables.length; i < n; i++) {
|
|
394
|
+
_lastTheme.light += variables[i] + ":" + fromLight.getPropertyValue(variables[i]) + ";";
|
|
395
|
+
_lastTheme.dark += variables[i] + ":" + fromDark.getPropertyValue(variables[i]) + ";";
|
|
396
|
+
}
|
|
397
|
+
document.body.removeChild(light);
|
|
398
|
+
document.body.removeChild(dark);
|
|
399
|
+
return _lastTheme;
|
|
400
|
+
}
|
|
401
|
+
function theme(source) {
|
|
402
|
+
if (!source || !globalThis.materialDynamicColors)
|
|
403
|
+
return lastTheme();
|
|
404
|
+
const mode2 = /dark/i.test(document.body.className) ? "dark" : "light";
|
|
405
|
+
if (source.light && source.dark) {
|
|
406
|
+
_lastTheme.light = source.light;
|
|
407
|
+
_lastTheme.dark = source.dark;
|
|
408
|
+
document.body.setAttribute("style", source[mode2]);
|
|
409
|
+
return source;
|
|
410
|
+
}
|
|
411
|
+
return globalThis.materialDynamicColors(source).then((theme2) => {
|
|
412
|
+
const toCss = (data) => {
|
|
413
|
+
let style = "";
|
|
414
|
+
for (let i = 0, keys = Object.keys(data), n = keys.length; i < n; i++) {
|
|
415
|
+
const key = keys[i];
|
|
416
|
+
const value = data[key];
|
|
417
|
+
const kebabCase = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
418
|
+
style += "--" + kebabCase + ":" + value + ";";
|
|
419
|
+
}
|
|
420
|
+
return style;
|
|
421
|
+
};
|
|
422
|
+
_lastTheme.light = toCss(theme2.light);
|
|
423
|
+
_lastTheme.dark = toCss(theme2.dark);
|
|
424
|
+
document.body.setAttribute("style", _lastTheme[mode2]);
|
|
425
|
+
return _lastTheme;
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
function mode(value) {
|
|
429
|
+
if (!value)
|
|
430
|
+
return /dark/i.test(document.body.className) ? "dark" : "light";
|
|
431
|
+
document.body.classList.remove("light", "dark");
|
|
432
|
+
document.body.classList.add(value);
|
|
433
|
+
const lastThemeStyle = value === "light" ? _lastTheme.light : _lastTheme.dark;
|
|
434
|
+
if (globalThis.materialDynamicColors)
|
|
435
|
+
document.body.setAttribute("style", lastThemeStyle);
|
|
436
|
+
return value;
|
|
437
|
+
}
|
|
438
|
+
function setup() {
|
|
439
|
+
if (_mutation)
|
|
440
|
+
return;
|
|
441
|
+
_mutation = new MutationObserver(onMutation);
|
|
442
|
+
_mutation.observe(document.body, { childList: true, subtree: true });
|
|
443
|
+
onMutation();
|
|
444
|
+
}
|
|
445
|
+
function ui(selector, options) {
|
|
446
|
+
if (selector) {
|
|
447
|
+
if (selector === "setup") {
|
|
448
|
+
setup();
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
if (selector === "guid")
|
|
452
|
+
return guid();
|
|
453
|
+
if (selector === "mode")
|
|
454
|
+
return mode(options);
|
|
455
|
+
if (selector === "theme")
|
|
456
|
+
return theme(options);
|
|
457
|
+
const to = query(selector);
|
|
458
|
+
if (!to)
|
|
459
|
+
return;
|
|
460
|
+
void open(to, to, options);
|
|
461
|
+
}
|
|
462
|
+
const elements = queryAll("[data-ui]");
|
|
463
|
+
for (let i = 0, n = elements.length; i < n; i++)
|
|
464
|
+
on(elements[i], "click", onClickElement);
|
|
465
|
+
const labels = queryAll(".field > label");
|
|
466
|
+
for (let i = 0, n = labels.length; i < n; i++)
|
|
467
|
+
on(labels[i], "click", onClickLabel);
|
|
468
|
+
const inputs = queryAll(".field > input:not([type=file], [type=color], [type=range]), .field > select, .field > textarea");
|
|
469
|
+
for (let i = 0, n = inputs.length; i < n; i++) {
|
|
470
|
+
const input = inputs[i];
|
|
471
|
+
on(input, "focus", onFocusInput);
|
|
472
|
+
on(input, "blur", onBlurInput);
|
|
473
|
+
updateInput(input);
|
|
474
|
+
}
|
|
475
|
+
const files = queryAll(".field > input[type=file]");
|
|
476
|
+
for (let i = 0, n = files.length; i < n; i++) {
|
|
477
|
+
const file = files[i];
|
|
478
|
+
on(file, "change", onChangeFile);
|
|
479
|
+
updateFile(file);
|
|
480
|
+
}
|
|
481
|
+
const colors = queryAll(".field > input[type=color]");
|
|
482
|
+
for (let i = 0, n = colors.length; i < n; i++) {
|
|
483
|
+
const color = colors[i];
|
|
484
|
+
on(color, "change", onChangeColor);
|
|
485
|
+
updateColor(color);
|
|
486
|
+
}
|
|
487
|
+
const textareas = queryAll(".field.textarea > textarea");
|
|
488
|
+
for (let i = 0, n = textareas.length; i < n; i++) {
|
|
489
|
+
const textarea = textareas[i];
|
|
490
|
+
on(textarea, "input", onInputTextarea);
|
|
491
|
+
updateTextarea(textarea);
|
|
492
|
+
}
|
|
493
|
+
updateAllRanges();
|
|
494
|
+
}
|
|
495
|
+
if (globalThis.addEventListener)
|
|
496
|
+
globalThis.addEventListener("load", async () => await ui("setup"));
|
|
497
|
+
globalThis.beercss = ui;
|
|
498
|
+
globalThis.ui = ui;
|
|
499
|
+
|
|
500
|
+
export default globalThis.ui;
|