beercss 2.3.0 → 3.0.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 +45 -35
- package/dist/cdn/beer.min.css +1 -1
- package/dist/cdn/beer.min.js +1 -1
- package/dist/cdn/material-symbols-outlined.woff2 +0 -0
- package/dist/cdn/roboto-flex-cyrillic-ext.woff2 +0 -0
- package/dist/cdn/roboto-flex-cyrillic.woff2 +0 -0
- package/dist/cdn/roboto-flex-greek.woff2 +0 -0
- package/dist/cdn/roboto-flex-latin-ext.woff2 +0 -0
- package/dist/cdn/roboto-flex-latin.woff2 +0 -0
- package/dist/cdn/roboto-flex-vietnamese.woff2 +0 -0
- package/index.js +10 -2
- package/package.json +17 -2
- package/src/cdn/beer.css +2 -2
- package/src/cdn/beer.ts +164 -166
- package/src/cdn/elements/badges.css +7 -7
- package/src/cdn/elements/buttons.css +24 -24
- package/src/cdn/elements/cards.css +7 -7
- package/src/cdn/elements/chips.css +14 -14
- package/src/cdn/elements/containers.css +30 -21
- package/src/cdn/elements/dropdowns.css +5 -5
- package/src/cdn/elements/expansions.css +9 -5
- package/src/cdn/elements/fields.css +70 -70
- package/src/cdn/elements/grids.css +31 -30
- package/src/cdn/elements/icons.css +18 -18
- package/src/cdn/elements/layouts.css +17 -17
- package/src/cdn/elements/loaders.css +45 -35
- package/src/cdn/elements/media.css +37 -37
- package/src/cdn/elements/modals.css +17 -17
- package/src/cdn/elements/navigations.css +31 -31
- package/src/cdn/elements/overlays.css +1 -1
- package/src/cdn/elements/pages.css +10 -6
- package/src/cdn/elements/progress.css +2 -2
- package/src/cdn/elements/selections.css +31 -30
- package/src/cdn/elements/tables.css +14 -14
- package/src/cdn/elements/tabs.css +22 -12
- package/src/cdn/elements/toasts.css +12 -10
- package/src/cdn/elements/tooltips.css +10 -10
- package/src/cdn/helpers/alignments.css +1 -1
- package/src/cdn/helpers/colors.css +215 -215
- package/src/cdn/helpers/directions.css +4 -6
- package/src/cdn/helpers/dividers.css +5 -5
- package/src/cdn/helpers/elevates.css +1 -1
- package/src/cdn/helpers/forms.css +21 -21
- package/src/cdn/helpers/margins.css +5 -5
- package/src/cdn/helpers/opacities.css +1 -1
- package/src/cdn/helpers/paddings.css +5 -5
- package/src/cdn/helpers/positions.css +1 -1
- package/src/cdn/helpers/reset.css +2 -2
- package/src/cdn/helpers/responsive.css +2 -1
- package/src/cdn/helpers/scrolls.css +1 -2
- package/src/cdn/helpers/shadows.css +1 -1
- package/src/cdn/helpers/sizes.css +7 -7
- package/src/cdn/helpers/spaces.css +5 -5
- package/src/cdn/helpers/theme.css +38 -38
- package/src/cdn/helpers/typography.css +63 -14
- package/src/cdn/helpers/waves.css +10 -10
- package/src/cdn/material-symbols-outlined.woff2 +0 -0
- package/src/cdn/roboto-flex-cyrillic-ext.woff2 +0 -0
- package/src/cdn/roboto-flex-cyrillic.woff2 +0 -0
- package/src/cdn/roboto-flex-greek.woff2 +0 -0
- package/src/cdn/roboto-flex-latin-ext.woff2 +0 -0
- package/src/cdn/roboto-flex-latin.woff2 +0 -0
- package/src/cdn/roboto-flex-vietnamese.woff2 +0 -0
- package/src/cdn/settings/dark.css +13 -14
- package/src/cdn/settings/fonts.css +206 -0
- package/src/cdn/settings/light.css +17 -18
- package/src/cdn/settings/urls.css +0 -1
package/src/cdn/beer.ts
CHANGED
|
@@ -1,114 +1,112 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
if (window["ui"]) return;
|
|
3
|
-
|
|
1
|
+
export default (() => {
|
|
4
2
|
interface ILastTheme {
|
|
5
|
-
dark:string,
|
|
6
|
-
light:string
|
|
3
|
+
dark: string,
|
|
4
|
+
light: string,
|
|
7
5
|
}
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
let
|
|
11
|
-
let
|
|
12
|
-
let
|
|
7
|
+
const _window = globalThis;
|
|
8
|
+
let _timeoutToast: NodeJS.Timeout = null;
|
|
9
|
+
let _timeoutMutation: NodeJS.Timeout = null;
|
|
10
|
+
let _mutation: MutationObserver = null;
|
|
11
|
+
const _lastTheme: ILastTheme = {
|
|
13
12
|
light: "",
|
|
14
|
-
dark: ""
|
|
15
|
-
}
|
|
13
|
+
dark: "",
|
|
14
|
+
};
|
|
16
15
|
|
|
17
|
-
const wait = (milliseconds:number) => {
|
|
18
|
-
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
19
|
-
}
|
|
16
|
+
const wait = async (milliseconds: number) => {
|
|
17
|
+
return await new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
18
|
+
};
|
|
20
19
|
|
|
21
|
-
const guid = ():string => {
|
|
22
|
-
return "fxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c:string) => {
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const guid = (): string => {
|
|
21
|
+
return "fxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c: string) => {
|
|
22
|
+
const r = (Math.random() * 16) | 0;
|
|
23
|
+
const v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
25
24
|
return v.toString(16);
|
|
26
25
|
});
|
|
27
|
-
}
|
|
26
|
+
};
|
|
28
27
|
|
|
29
|
-
const query = (selector:string|Element, element?:Element):Element => {
|
|
28
|
+
const query = (selector: string | Element, element?: Element): Element => {
|
|
30
29
|
try {
|
|
31
|
-
return typeof selector
|
|
30
|
+
return typeof selector === "string"
|
|
32
31
|
? (element || document).querySelector(selector)
|
|
33
|
-
: selector;
|
|
32
|
+
: selector;
|
|
34
33
|
} catch {}
|
|
35
|
-
}
|
|
34
|
+
};
|
|
36
35
|
|
|
37
|
-
const queryAll = (selector:string|NodeListOf<Element>, element?:Element) => {
|
|
36
|
+
const queryAll = (selector: string | NodeListOf<Element>, element?: Element) => {
|
|
38
37
|
try {
|
|
39
|
-
return typeof selector
|
|
38
|
+
return typeof selector === "string"
|
|
40
39
|
? (element || document).querySelectorAll(selector)
|
|
41
|
-
: selector;
|
|
40
|
+
: selector;
|
|
42
41
|
} catch {}
|
|
43
|
-
}
|
|
42
|
+
};
|
|
44
43
|
|
|
45
|
-
const hasClass = (element:Element, name:string):boolean => {
|
|
44
|
+
const hasClass = (element: Element, name: string): boolean => {
|
|
46
45
|
if (!element) return false;
|
|
47
46
|
return element.classList.contains(name);
|
|
48
|
-
}
|
|
47
|
+
};
|
|
49
48
|
|
|
50
|
-
const addClass = (element:Element, name:string) => {
|
|
49
|
+
const addClass = (element: Element, name: string) => {
|
|
51
50
|
if (!element) return;
|
|
52
51
|
element.classList.add(name);
|
|
53
|
-
}
|
|
52
|
+
};
|
|
54
53
|
|
|
55
|
-
const removeClass = (element:Element, name:string) => {
|
|
54
|
+
const removeClass = (element: Element, name: string) => {
|
|
56
55
|
if (!element) return;
|
|
57
56
|
element.classList.remove(name);
|
|
58
|
-
}
|
|
57
|
+
};
|
|
59
58
|
|
|
60
|
-
const on = (element:Element, name:string, callback:any) => {
|
|
59
|
+
const on = (element: Element, name: string, callback: any) => {
|
|
61
60
|
element.addEventListener(name, callback, true);
|
|
62
|
-
}
|
|
61
|
+
};
|
|
63
62
|
|
|
64
|
-
const off = (element:Element, name:string, callback:any) => {
|
|
63
|
+
const off = (element: Element, name: string, callback: any) => {
|
|
65
64
|
element.removeEventListener(name, callback, true);
|
|
66
|
-
}
|
|
65
|
+
};
|
|
67
66
|
|
|
68
|
-
const insertBefore = (newElement:Element, element:Element):Element => {
|
|
67
|
+
const insertBefore = (newElement: Element, element: Element): Element => {
|
|
69
68
|
if (!element) return;
|
|
70
69
|
return element.parentNode.insertBefore(newElement, element);
|
|
71
|
-
}
|
|
70
|
+
};
|
|
72
71
|
|
|
73
|
-
const prev = (element:Element):Element => {
|
|
72
|
+
const prev = (element: Element): Element => {
|
|
74
73
|
if (!element) return;
|
|
75
74
|
return element.previousElementSibling;
|
|
76
|
-
}
|
|
75
|
+
};
|
|
77
76
|
|
|
78
|
-
const next = (element:Element):Element => {
|
|
77
|
+
const next = (element: Element): Element => {
|
|
79
78
|
if (!element) return;
|
|
80
79
|
return element.nextElementSibling;
|
|
81
|
-
}
|
|
80
|
+
};
|
|
82
81
|
|
|
83
|
-
const parent = (element:Element):Element => {
|
|
82
|
+
const parent = (element: Element): Element => {
|
|
84
83
|
if (!element) return;
|
|
85
84
|
return element.parentElement;
|
|
86
|
-
}
|
|
85
|
+
};
|
|
87
86
|
|
|
88
|
-
const create = (json:any) => {
|
|
89
|
-
|
|
87
|
+
const create = (json: any) => {
|
|
88
|
+
const element = document.createElement("div");
|
|
90
89
|
|
|
91
|
-
for (
|
|
92
|
-
element[i] = json[i];
|
|
90
|
+
for (const i in json) { element[i] = json[i]; }
|
|
93
91
|
|
|
94
92
|
return element;
|
|
95
|
-
}
|
|
93
|
+
};
|
|
96
94
|
|
|
97
|
-
const updateInput = (target:Element) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
95
|
+
const updateInput = (target: Element) => {
|
|
96
|
+
const input = target as HTMLInputElement;
|
|
97
|
+
const parentTarget = parent(target);
|
|
98
|
+
const label = query("label", parentTarget) as HTMLLabelElement;
|
|
99
|
+
const isBorder = hasClass(parentTarget, "border") && !hasClass(parentTarget, "fill");
|
|
100
|
+
const toActive = document.activeElement == target || input.value || /date|time/.test(input.type);
|
|
103
101
|
|
|
104
102
|
if (toActive) {
|
|
105
103
|
if (isBorder && label) {
|
|
106
104
|
let width = hasClass(label, "active") ? label.offsetWidth : Math.round(label.offsetWidth / 1.33);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
input.style.clipPath = "";
|
|
105
|
+
width = width / 16; // 16px = 1rem, originally 1px = 1rem, hence the division
|
|
106
|
+
const start = hasClass(parentTarget, "round") ? 1.25 : 0.75;
|
|
107
|
+
const end = width + start + 0.5;
|
|
108
|
+
input.style.clipPath = `polygon(0% 0%, ${start}rem 0%, ${start}rem 0.5rem, ${end}rem 0.5rem, ${end}rem 0%, 100% 0%, 100% 100%, 0% 100%)`;
|
|
109
|
+
} else { input.style.clipPath = ""; }
|
|
112
110
|
addClass(label, "active");
|
|
113
111
|
} else {
|
|
114
112
|
removeClass(label, "active");
|
|
@@ -116,81 +114,81 @@
|
|
|
116
114
|
}
|
|
117
115
|
|
|
118
116
|
if (target.getAttribute("data-ui")) open(target);
|
|
119
|
-
}
|
|
117
|
+
};
|
|
120
118
|
|
|
121
|
-
const onClickElement = (e:Event) => {
|
|
122
|
-
|
|
119
|
+
const onClickElement = (e: Event) => {
|
|
120
|
+
const target = e.currentTarget as HTMLElement;
|
|
123
121
|
if (/input/i.test(target.tagName)) return;
|
|
124
122
|
open(target);
|
|
125
|
-
}
|
|
123
|
+
};
|
|
126
124
|
|
|
127
|
-
const onClickLabel = (e:Event) => {
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
const onClickLabel = (e: Event) => {
|
|
126
|
+
const target = e.currentTarget as Element;
|
|
127
|
+
const input = query("input:not([type=file]):not([type=checkbox]):not([type=radio]), select, textarea", parent(target)) as HTMLElement;
|
|
130
128
|
if (input) input.focus();
|
|
131
|
-
}
|
|
129
|
+
};
|
|
132
130
|
|
|
133
|
-
const onFocusInput = (e:Event) => {
|
|
134
|
-
|
|
131
|
+
const onFocusInput = (e: Event) => {
|
|
132
|
+
const target = e.currentTarget as Element;
|
|
135
133
|
updateInput(target);
|
|
136
|
-
}
|
|
134
|
+
};
|
|
137
135
|
|
|
138
|
-
const onBlurInput = (e:Event) => {
|
|
139
|
-
|
|
136
|
+
const onBlurInput = (e: Event) => {
|
|
137
|
+
const target = e.currentTarget as Element;
|
|
140
138
|
updateInput(target);
|
|
141
|
-
}
|
|
139
|
+
};
|
|
142
140
|
|
|
143
|
-
const onClickDocument = (e:Event) => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
dropdowns.forEach((x:Element) => removeClass(x, "active"));
|
|
141
|
+
const onClickDocument = (e: Event) => {
|
|
142
|
+
const target = e.currentTarget as Element;
|
|
143
|
+
const dropdowns = queryAll(".dropdown.active");
|
|
144
|
+
dropdowns.forEach((x: Element) => removeClass(x, "active"));
|
|
147
145
|
|
|
148
146
|
off(target, "click", onClickDocument);
|
|
149
|
-
}
|
|
147
|
+
};
|
|
150
148
|
|
|
151
|
-
const onClickToast = (e:Event) => {
|
|
152
|
-
|
|
149
|
+
const onClickToast = (e: Event) => {
|
|
150
|
+
const target = e.currentTarget as Element;
|
|
153
151
|
removeClass(target, "active");
|
|
154
152
|
|
|
155
153
|
if (_timeoutToast) clearTimeout(_timeoutToast);
|
|
156
|
-
}
|
|
154
|
+
};
|
|
157
155
|
|
|
158
|
-
const onChangeFile = (e:Event) => {
|
|
159
|
-
|
|
156
|
+
const onChangeFile = (e: Event) => {
|
|
157
|
+
const target = e.currentTarget as HTMLInputElement;
|
|
160
158
|
updateFile(target);
|
|
161
|
-
}
|
|
159
|
+
};
|
|
162
160
|
|
|
163
|
-
const onKeydownFile = (e:KeyboardEvent) => {
|
|
164
|
-
|
|
161
|
+
const onKeydownFile = (e: KeyboardEvent) => {
|
|
162
|
+
const target = e.currentTarget as HTMLInputElement;
|
|
165
163
|
updateFile(target, e);
|
|
166
|
-
}
|
|
164
|
+
};
|
|
167
165
|
|
|
168
166
|
const onMutation = () => {
|
|
169
167
|
if (_timeoutMutation) clearTimeout(_timeoutMutation);
|
|
170
168
|
_timeoutMutation = setTimeout(ui, 180);
|
|
171
|
-
}
|
|
169
|
+
};
|
|
172
170
|
|
|
173
|
-
const updateFile = (target:Element, e?:KeyboardEvent) => {
|
|
171
|
+
const updateFile = (target: Element, e?: KeyboardEvent) => {
|
|
174
172
|
if (e) {
|
|
175
173
|
if (e.key !== "Enter") return;
|
|
176
174
|
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
const target = e.currentTarget as Element;
|
|
176
|
+
const nextTarget = next(target) as HTMLInputElement;
|
|
179
177
|
if (!nextTarget || !/file/i.test(nextTarget.type)) return;
|
|
180
178
|
return nextTarget.click();
|
|
181
179
|
}
|
|
182
180
|
|
|
183
|
-
|
|
184
|
-
|
|
181
|
+
const currentTarget = target as HTMLInputElement;
|
|
182
|
+
const previousTarget = prev(target) as HTMLInputElement;
|
|
185
183
|
if (!previousTarget || !/text/i.test(previousTarget.type)) return;
|
|
186
184
|
previousTarget.value = Array.from(currentTarget.files).map((x) => x.name).join(", ");
|
|
187
185
|
previousTarget.readOnly = true;
|
|
188
186
|
previousTarget.addEventListener("keydown", onKeydownFile);
|
|
189
187
|
updateInput(previousTarget);
|
|
190
|
-
}
|
|
188
|
+
};
|
|
191
189
|
|
|
192
|
-
const open = (from?:Element, to?:Element, config?:any) => {
|
|
193
|
-
if (!to) to = query(from.getAttribute("data-ui"))
|
|
190
|
+
const open = (from?: Element, to?: Element, config?: any) => {
|
|
191
|
+
if (!to) to = query(from.getAttribute("data-ui"));
|
|
194
192
|
if (hasClass(to, "modal")) return modal(from, to);
|
|
195
193
|
if (hasClass(to, "dropdown")) return dropdown(from, to);
|
|
196
194
|
if (hasClass(to, "toast")) return toast(from, to, config);
|
|
@@ -202,41 +200,40 @@
|
|
|
202
200
|
if (hasClass(to, "active")) return removeClass(to, "active");
|
|
203
201
|
|
|
204
202
|
addClass(to, "active");
|
|
205
|
-
}
|
|
203
|
+
};
|
|
206
204
|
|
|
207
|
-
const tab = (from:Element) => {
|
|
208
|
-
|
|
205
|
+
const tab = (from: Element) => {
|
|
206
|
+
const container = parent(from);
|
|
209
207
|
if (!hasClass(container, "tabs")) return;
|
|
210
208
|
|
|
211
|
-
|
|
212
|
-
tabs.forEach((x:Element) => removeClass(x, "active"));
|
|
209
|
+
const tabs = queryAll("a", container);
|
|
210
|
+
tabs.forEach((x: Element) => removeClass(x, "active"));
|
|
213
211
|
|
|
214
212
|
addClass(from, "active");
|
|
215
|
-
}
|
|
213
|
+
};
|
|
216
214
|
|
|
217
|
-
const page = (from:Element, to:Element
|
|
215
|
+
const page = (from: Element, to: Element) => {
|
|
218
216
|
tab(from);
|
|
219
217
|
|
|
220
|
-
|
|
221
|
-
for (let i = 0; i < container.children.length; i++)
|
|
222
|
-
if (hasClass(container.children[i], "page")) removeClass(container.children[i], "active");
|
|
218
|
+
const container = parent(to);
|
|
219
|
+
for (let i = 0; i < container.children.length; i++) { if (hasClass(container.children[i], "page")) removeClass(container.children[i], "active"); }
|
|
223
220
|
|
|
224
221
|
addClass(to, "active");
|
|
225
|
-
}
|
|
222
|
+
};
|
|
226
223
|
|
|
227
|
-
const dropdown = (from:Element, to:Element) => {
|
|
224
|
+
const dropdown = (from: Element, to: Element) => {
|
|
228
225
|
tab(from);
|
|
229
226
|
|
|
230
227
|
if (hasClass(to, "active")) return removeClass(to, "active");
|
|
231
228
|
|
|
232
|
-
|
|
233
|
-
dropdowns.forEach((x:Element) => removeClass(x, "active"));
|
|
229
|
+
const dropdowns = queryAll(".dropdown.active");
|
|
230
|
+
dropdowns.forEach((x: Element) => removeClass(x, "active"));
|
|
234
231
|
|
|
235
232
|
addClass(to, "active");
|
|
236
233
|
on(document.body, "click", onClickDocument);
|
|
237
|
-
}
|
|
234
|
+
};
|
|
238
235
|
|
|
239
|
-
const modal = async (from:Element, to:Element) => {
|
|
236
|
+
const modal = async (from: Element, to: Element) => {
|
|
240
237
|
tab(from);
|
|
241
238
|
|
|
242
239
|
let overlay = prev(to) as HTMLElement;
|
|
@@ -250,13 +247,13 @@
|
|
|
250
247
|
removeClass(from, "active");
|
|
251
248
|
removeClass(to, "active");
|
|
252
249
|
removeClass(overlay, "active");
|
|
253
|
-
}
|
|
250
|
+
};
|
|
254
251
|
|
|
255
|
-
|
|
256
|
-
|
|
252
|
+
const isActive = hasClass(to, "active");
|
|
253
|
+
const container = parent(to);
|
|
257
254
|
if (/nav/i.test(container.tagName)) {
|
|
258
|
-
|
|
259
|
-
elements.forEach((x:Element) => removeClass(x, "active"));
|
|
255
|
+
const elements = queryAll(".modal, a, .overlay", container);
|
|
256
|
+
elements.forEach((x: Element) => removeClass(x, "active"));
|
|
260
257
|
}
|
|
261
258
|
|
|
262
259
|
if (isActive) {
|
|
@@ -268,13 +265,13 @@
|
|
|
268
265
|
addClass(overlay, "active");
|
|
269
266
|
addClass(to, "active");
|
|
270
267
|
}
|
|
271
|
-
}
|
|
268
|
+
};
|
|
272
269
|
|
|
273
|
-
const toast = (from:Element, to:Element, config:any) => {
|
|
270
|
+
const toast = (from: Element, to: Element, config: any) => {
|
|
274
271
|
tab(from);
|
|
275
272
|
|
|
276
|
-
|
|
277
|
-
elements.forEach((x:Element) => removeClass(x, "active"));
|
|
273
|
+
const elements = queryAll(".toast.active");
|
|
274
|
+
elements.forEach((x: Element) => removeClass(x, "active"));
|
|
278
275
|
addClass(to, "active");
|
|
279
276
|
on(to, "click", onClickToast);
|
|
280
277
|
|
|
@@ -285,35 +282,35 @@
|
|
|
285
282
|
_timeoutToast = setTimeout(() => {
|
|
286
283
|
removeClass(to, "active");
|
|
287
284
|
}, config && config ? config : 6000);
|
|
288
|
-
}
|
|
285
|
+
};
|
|
289
286
|
|
|
290
|
-
const progress = (to:Element, config:any) => {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (hasClass(element, "left")) return
|
|
287
|
+
const progress = (to: Element, config: any) => {
|
|
288
|
+
const element = to as HTMLElement;
|
|
289
|
+
|
|
290
|
+
if (hasClass(element, "left")) return element.style.clipPath = `polygon(0% 0%, 0% 100%, ${config}% 100%, ${config}% 0%)`;
|
|
294
291
|
|
|
295
292
|
if (hasClass(element, "top")) return element.style.clipPath = `polygon(0% 0%, 100% 0%, 100% ${config}%, 0% ${config}%)`;
|
|
296
293
|
|
|
297
|
-
if (hasClass(element, "right")) return
|
|
294
|
+
if (hasClass(element, "right")) return element.style.clipPath = `polygon(100% 0%, 100% 100%, ${100 - config}% 100%, ${100 - config}% 0%)`;
|
|
298
295
|
|
|
299
296
|
if (hasClass(element, "bottom")) return element.style.clipPath = `polygon(0% 100%, 100% 100%, 100% ${100 - config}%, 0% ${100 - config}%)`;
|
|
300
|
-
}
|
|
297
|
+
};
|
|
301
298
|
|
|
302
|
-
const lastTheme = ():ILastTheme => {
|
|
299
|
+
const lastTheme = (): ILastTheme => {
|
|
303
300
|
if (_lastTheme.light && _lastTheme.dark) return _lastTheme;
|
|
304
301
|
|
|
305
|
-
|
|
302
|
+
const light = document.createElement("body");
|
|
306
303
|
light.className = "light";
|
|
307
304
|
document.body.appendChild(light);
|
|
308
305
|
|
|
309
|
-
|
|
306
|
+
const dark = document.createElement("body");
|
|
310
307
|
dark.className = "dark";
|
|
311
308
|
document.body.appendChild(dark);
|
|
312
309
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
for(let i=0; i<variables.length; i++) {
|
|
310
|
+
const fromLight = getComputedStyle(light);
|
|
311
|
+
const fromDark = getComputedStyle(dark);
|
|
312
|
+
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", "--outline", "--surface-variant", "--on-surface-variant", "--inverse-surface", "--inverse-on-surface"];
|
|
313
|
+
for (let i = 0; i < variables.length; i++) {
|
|
317
314
|
_lastTheme.light += variables[i] + ":" + fromLight.getPropertyValue(variables[i]) + ";";
|
|
318
315
|
_lastTheme.dark += variables[i] + ":" + fromDark.getPropertyValue(variables[i]) + ";";
|
|
319
316
|
}
|
|
@@ -321,12 +318,12 @@
|
|
|
321
318
|
document.body.removeChild(light);
|
|
322
319
|
document.body.removeChild(dark);
|
|
323
320
|
return _lastTheme;
|
|
324
|
-
}
|
|
321
|
+
};
|
|
325
322
|
|
|
326
|
-
const theme = (source:any):ILastTheme => {
|
|
327
|
-
if (!source || !
|
|
323
|
+
const theme = (source: any): ILastTheme => {
|
|
324
|
+
if (!source || !_window.materialDynamicColors) return lastTheme();
|
|
328
325
|
|
|
329
|
-
|
|
326
|
+
const mode = /dark/i.test(document.body.className) ? "dark" : "light";
|
|
330
327
|
if (source && source.light && source.dark) {
|
|
331
328
|
_lastTheme.light = source.light;
|
|
332
329
|
_lastTheme.dark = source.dark;
|
|
@@ -334,70 +331,71 @@
|
|
|
334
331
|
return source;
|
|
335
332
|
}
|
|
336
333
|
|
|
337
|
-
return
|
|
334
|
+
return _window.materialDynamicColors(source).then((theme) => {
|
|
338
335
|
const toCss = (data) => {
|
|
339
336
|
let style = "";
|
|
340
|
-
for (
|
|
341
|
-
|
|
342
|
-
style += "--"+kebabCase+":"+data[i]+";";
|
|
337
|
+
for (const i in data) {
|
|
338
|
+
const kebabCase = i.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
339
|
+
style += "--" + kebabCase + ":" + data[i] + ";";
|
|
343
340
|
}
|
|
344
341
|
return style;
|
|
345
|
-
}
|
|
342
|
+
};
|
|
346
343
|
|
|
347
344
|
_lastTheme.light = toCss(theme.light);
|
|
348
345
|
_lastTheme.dark = toCss(theme.dark);
|
|
349
346
|
document.body.setAttribute("style", _lastTheme[mode]);
|
|
350
347
|
return _lastTheme;
|
|
351
348
|
});
|
|
352
|
-
}
|
|
349
|
+
};
|
|
353
350
|
|
|
354
|
-
const mode = (value:string):string => {
|
|
351
|
+
const mode = (value: string): string => {
|
|
355
352
|
if (!value) return /dark/i.test(document.body.className) ? "dark" : "light";
|
|
356
353
|
document.body.classList.remove("light", "dark");
|
|
357
354
|
document.body.classList.add(value);
|
|
358
|
-
if (
|
|
355
|
+
if (_window.materialDynamicColors) document.body.setAttribute("style", _lastTheme[value]);
|
|
359
356
|
return value;
|
|
360
|
-
}
|
|
357
|
+
};
|
|
361
358
|
|
|
362
359
|
const setup = () => {
|
|
363
360
|
if (_mutation) return;
|
|
364
361
|
_mutation = new MutationObserver(onMutation);
|
|
365
362
|
_mutation.observe(document.body, { childList: true, subtree: true });
|
|
366
363
|
ui();
|
|
367
|
-
}
|
|
364
|
+
};
|
|
368
365
|
|
|
369
|
-
const ui = (selector?:string, config?:any) => {
|
|
366
|
+
const ui = (selector?: string, config?: any) => {
|
|
370
367
|
if (selector) {
|
|
371
368
|
if (selector == "setup") return setup();
|
|
372
369
|
if (selector == "guid") return guid();
|
|
373
370
|
if (selector == "mode") return mode(config);
|
|
374
371
|
if (selector == "theme") return theme(config);
|
|
375
372
|
|
|
376
|
-
|
|
377
|
-
|
|
373
|
+
const to = query(selector);
|
|
374
|
+
const from = query("[data-ui='#" + to.id + "']");
|
|
378
375
|
open(from, to, config);
|
|
379
376
|
}
|
|
380
377
|
|
|
381
|
-
|
|
382
|
-
elements.forEach((x:Element) => on(x, "click", onClickElement));
|
|
378
|
+
const elements = queryAll("[data-ui]");
|
|
379
|
+
elements.forEach((x: Element) => on(x, "click", onClickElement));
|
|
383
380
|
|
|
384
|
-
|
|
385
|
-
labels.forEach((x:HTMLLabelElement) => on(x, "click", onClickLabel));
|
|
381
|
+
const labels = queryAll(".field > label");
|
|
382
|
+
labels.forEach((x: HTMLLabelElement) => on(x, "click", onClickLabel));
|
|
386
383
|
|
|
387
|
-
|
|
388
|
-
inputs.forEach((x:Element) => {
|
|
384
|
+
const inputs = queryAll(".field > input:not([type=file]):not([type=checkbox]):not([type=radio]), .field > select, .field > textarea");
|
|
385
|
+
inputs.forEach((x: Element) => {
|
|
389
386
|
on(x, "focus", onFocusInput);
|
|
390
387
|
on(x, "blur", onBlurInput);
|
|
391
388
|
updateInput(x);
|
|
392
389
|
});
|
|
393
390
|
|
|
394
|
-
|
|
395
|
-
files.forEach((x:Element) => {
|
|
391
|
+
const files = queryAll(".field > input[type=file]");
|
|
392
|
+
files.forEach((x: Element) => {
|
|
396
393
|
on(x, "change", onChangeFile);
|
|
397
394
|
updateFile(x);
|
|
398
395
|
});
|
|
399
|
-
}
|
|
396
|
+
};
|
|
400
397
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
398
|
+
if (_window.addEventListener) _window.addEventListener("load", () => ui("setup"));
|
|
399
|
+
_window.ui = ui;
|
|
400
|
+
return _window.ui;
|
|
401
|
+
})();
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
align-items: center;
|
|
4
4
|
justify-content: center;
|
|
5
5
|
position: absolute;
|
|
6
|
-
font-size:
|
|
6
|
+
font-size: 0.75rem;
|
|
7
7
|
text-transform: none;
|
|
8
8
|
z-index: 1;
|
|
9
|
-
padding: 0
|
|
9
|
+
padding: 0 0.375rem;
|
|
10
10
|
background-color: var(--error);
|
|
11
11
|
color: var(--on-error);
|
|
12
12
|
top: 0;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
bottom: auto;
|
|
15
15
|
right: 0;
|
|
16
16
|
transform: translate(50%, -100%);
|
|
17
|
-
height:
|
|
17
|
+
height: 1.25rem;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
.badge.none {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
right: auto;
|
|
25
25
|
transform: none;
|
|
26
26
|
position: relative;
|
|
27
|
-
margin: 0
|
|
27
|
+
margin: 0 0.125rem;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
.badge.top {
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
.badge.border {
|
|
95
|
-
border:
|
|
95
|
+
border: 0.0625rem solid var(--error);
|
|
96
96
|
color: var(--error);
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -100,8 +100,8 @@
|
|
|
100
100
|
.badge.square {
|
|
101
101
|
padding: 0;
|
|
102
102
|
text-align: center;
|
|
103
|
-
width:
|
|
104
|
-
height:
|
|
103
|
+
width: 1.25rem;
|
|
104
|
+
height: 1.25rem;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
.badge.circle {
|