@vandenberghinc/volt 1.1.4 → 1.1.6
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/backend/dist/cjs/database.d.ts +41 -68
- package/backend/dist/cjs/database.js +136 -78
- package/backend/dist/cjs/endpoint.d.ts +23 -9
- package/backend/dist/cjs/endpoint.js +98 -21
- package/backend/dist/cjs/file_watcher.js +2 -2
- package/backend/dist/cjs/frontend.d.ts +0 -2
- package/backend/dist/cjs/frontend.js +9 -9
- package/backend/dist/cjs/image_endpoint.d.ts +3 -1
- package/backend/dist/cjs/image_endpoint.js +2 -1
- package/backend/dist/cjs/payments/paddle.js +10 -2
- package/backend/dist/cjs/plugins/css.d.ts +6 -5
- package/backend/dist/cjs/plugins/css.js +32 -7
- package/backend/dist/cjs/plugins/ts/compiler.d.ts +6 -1
- package/backend/dist/cjs/plugins/ts/compiler.js +26 -2
- package/backend/dist/cjs/plugins/ts/preprocessing.js +5 -3
- package/backend/dist/cjs/server.d.ts +7 -13
- package/backend/dist/cjs/server.js +184 -303
- package/backend/dist/cjs/status.d.ts +1 -0
- package/backend/dist/cjs/status.js +2 -1
- package/backend/dist/cjs/stream.d.ts +5 -3
- package/backend/dist/cjs/stream.js +13 -4
- package/backend/dist/cjs/users.d.ts +1 -1
- package/backend/dist/cjs/users.js +87 -72
- package/backend/dist/cjs/utils.d.ts +17 -9
- package/backend/dist/cjs/utils.js +22 -64
- package/backend/dist/cjs/view.d.ts +2 -2
- package/backend/dist/cjs/view.js +38 -40
- package/backend/dist/cjs/volt.d.ts +3 -2
- package/backend/dist/cjs/volt.js +2 -2
- package/backend/dist/css/volt.css +5 -0
- package/backend/dist/esm/database.d.ts +41 -68
- package/backend/dist/esm/database.js +137 -79
- package/backend/dist/esm/endpoint.d.ts +23 -9
- package/backend/dist/esm/endpoint.js +99 -22
- package/backend/dist/esm/file_watcher.js +2 -2
- package/backend/dist/esm/frontend.d.ts +0 -2
- package/backend/dist/esm/frontend.js +9 -9
- package/backend/dist/esm/image_endpoint.d.ts +3 -1
- package/backend/dist/esm/image_endpoint.js +2 -1
- package/backend/dist/esm/payments/paddle.js +11 -3
- package/backend/dist/esm/plugins/css.d.ts +6 -5
- package/backend/dist/esm/plugins/css.js +32 -6
- package/backend/dist/esm/plugins/ts/compiler.d.ts +6 -1
- package/backend/dist/esm/plugins/ts/compiler.js +26 -2
- package/backend/dist/esm/plugins/ts/preprocessing.js +5 -3
- package/backend/dist/esm/server.d.ts +7 -13
- package/backend/dist/esm/server.js +182 -301
- package/backend/dist/esm/status.d.ts +1 -0
- package/backend/dist/esm/status.js +1 -0
- package/backend/dist/esm/stream.d.ts +5 -3
- package/backend/dist/esm/stream.js +13 -4
- package/backend/dist/esm/users.d.ts +1 -1
- package/backend/dist/esm/users.js +87 -72
- package/backend/dist/esm/utils.d.ts +17 -9
- package/backend/dist/esm/utils.js +21 -62
- package/backend/dist/esm/view.d.ts +2 -2
- package/backend/dist/esm/view.js +38 -40
- package/backend/dist/esm/volt.d.ts +3 -2
- package/backend/dist/esm/volt.js +2 -1
- package/backend/dist/esm-dev/blacklist.js +1 -1
- package/backend/dist/esm-dev/cli.js +2 -2
- package/backend/dist/esm-dev/database.d.ts +41 -68
- package/backend/dist/esm-dev/database.js +138 -80
- package/backend/dist/esm-dev/endpoint.d.ts +23 -9
- package/backend/dist/esm-dev/endpoint.js +100 -23
- package/backend/dist/esm-dev/file_watcher.js +3 -3
- package/backend/dist/esm-dev/frontend.d.ts +0 -2
- package/backend/dist/esm-dev/frontend.js +9 -9
- package/backend/dist/esm-dev/image_endpoint.d.ts +3 -1
- package/backend/dist/esm-dev/image_endpoint.js +2 -1
- package/backend/dist/esm-dev/logger.js +1 -1
- package/backend/dist/esm-dev/payments/paddle.js +12 -4
- package/backend/dist/esm-dev/plugins/css.d.ts +6 -5
- package/backend/dist/esm-dev/plugins/css.js +33 -7
- package/backend/dist/esm-dev/plugins/ts/compiler.d.ts +6 -1
- package/backend/dist/esm-dev/plugins/ts/compiler.js +27 -3
- package/backend/dist/esm-dev/plugins/ts/preprocessing.js +7 -5
- package/backend/dist/esm-dev/rate_limit.js +1 -1
- package/backend/dist/esm-dev/server.d.ts +7 -13
- package/backend/dist/esm-dev/server.js +184 -303
- package/backend/dist/esm-dev/status.d.ts +1 -0
- package/backend/dist/esm-dev/status.js +1 -0
- package/backend/dist/esm-dev/stream.d.ts +5 -3
- package/backend/dist/esm-dev/stream.js +13 -4
- package/backend/dist/esm-dev/users.d.ts +1 -1
- package/backend/dist/esm-dev/users.js +88 -73
- package/backend/dist/esm-dev/utils.d.ts +17 -9
- package/backend/dist/esm-dev/utils.js +22 -63
- package/backend/dist/esm-dev/view.d.ts +2 -2
- package/backend/dist/esm-dev/view.js +39 -41
- package/backend/dist/esm-dev/volt.d.ts +3 -2
- package/backend/dist/esm-dev/volt.js +2 -1
- package/backend/src/database.ts +173 -155
- package/backend/src/endpoint.ts +123 -31
- package/backend/src/file_watcher.ts +2 -2
- package/backend/src/frontend.ts +9 -8
- package/backend/src/image_endpoint.ts +4 -0
- package/backend/src/payments/paddle.ts +11 -3
- package/backend/src/plugins/css.ts +36 -8
- package/backend/src/plugins/ts/compiler.ts +37 -1
- package/backend/src/plugins/ts/preprocessing.ts +5 -3
- package/backend/src/server.ts +167 -306
- package/backend/src/status.ts +1 -0
- package/backend/src/stream.ts +28 -8
- package/backend/src/users.ts +87 -72
- package/backend/src/utils.ts +58 -25
- package/backend/src/view.ts +30 -28
- package/backend/src/{volt.js → volt.ts} +2 -1
- package/backend/tsconfig.cjs.json +3 -3
- package/backend/tsconfig.esm.json +3 -3
- package/frontend/dist/elements/base.d.ts +414 -432
- package/frontend/dist/elements/base.js +566 -329
- package/frontend/dist/elements/module.d.ts +26 -12
- package/frontend/dist/elements/module.js +69 -32
- package/frontend/dist/elements/register_element.d.ts +3 -0
- package/frontend/dist/elements/register_element.js +22 -0
- package/frontend/dist/modules/auth.d.ts +1 -0
- package/frontend/dist/modules/auth.js +6 -5
- package/frontend/dist/modules/color.d.ts +159 -0
- package/frontend/dist/modules/color.js +315 -0
- package/frontend/dist/modules/colors.d.ts +1 -26
- package/frontend/dist/modules/colors.js +417 -340
- package/frontend/dist/modules/cookies.d.ts +1 -0
- package/frontend/dist/modules/cookies.js +1 -0
- package/frontend/dist/modules/events.d.ts +1 -0
- package/frontend/dist/modules/events.js +1 -0
- package/frontend/dist/modules/google.d.ts +1 -0
- package/frontend/dist/modules/google.js +1 -0
- package/frontend/dist/modules/meta.d.ts +1 -0
- package/frontend/dist/modules/meta.js +1 -0
- package/frontend/dist/modules/mutex.d.ts +1 -2
- package/frontend/dist/modules/mutex.js +3 -4
- package/frontend/dist/modules/paddle.d.ts +1 -0
- package/frontend/dist/modules/paddle.js +14 -13
- package/frontend/dist/modules/scheme.d.ts +1 -0
- package/frontend/dist/modules/scheme.js +5 -3
- package/frontend/dist/modules/statics.d.ts +1 -0
- package/frontend/dist/modules/statics.js +1 -0
- package/frontend/dist/modules/support.d.ts +1 -0
- package/frontend/dist/modules/support.js +3 -2
- package/frontend/dist/modules/theme.d.ts +56 -0
- package/frontend/dist/{ui → modules}/theme.js +186 -75
- package/frontend/dist/modules/themes.d.ts +1 -1
- package/frontend/dist/modules/themes.js +1 -0
- package/frontend/dist/modules/user.d.ts +1 -0
- package/frontend/dist/modules/user.js +11 -10
- package/frontend/dist/modules/utils.d.ts +23 -2
- package/frontend/dist/modules/utils.js +93 -1
- package/frontend/dist/types/gradient.js +4 -0
- package/frontend/dist/ui/border_button.d.ts +0 -25
- package/frontend/dist/ui/border_button.js +50 -51
- package/frontend/dist/ui/button.d.ts +0 -21
- package/frontend/dist/ui/button.js +41 -46
- package/frontend/dist/ui/canvas.js +15 -15
- package/frontend/dist/ui/checkbox.d.ts +3 -17
- package/frontend/dist/ui/checkbox.js +36 -30
- package/frontend/dist/ui/code.d.ts +15 -82
- package/frontend/dist/ui/code.js +150 -125
- package/frontend/dist/ui/color.d.ts +0 -1
- package/frontend/dist/ui/color.js +1 -1
- package/frontend/dist/ui/context_menu.d.ts +4 -2
- package/frontend/dist/ui/context_menu.js +16 -17
- package/frontend/dist/ui/css.js +2 -0
- package/frontend/dist/ui/divider.d.ts +0 -7
- package/frontend/dist/ui/divider.js +21 -25
- package/frontend/dist/ui/dropdown.d.ts +13 -7
- package/frontend/dist/ui/dropdown.js +65 -30
- package/frontend/dist/ui/for_each.d.ts +0 -5
- package/frontend/dist/ui/for_each.js +17 -22
- package/frontend/dist/ui/form.d.ts +17 -12
- package/frontend/dist/ui/form.js +21 -18
- package/frontend/dist/ui/frame_modes.d.ts +9 -12
- package/frontend/dist/ui/frame_modes.js +8 -10
- package/frontend/dist/ui/google_map.d.ts +0 -11
- package/frontend/dist/ui/google_map.js +23 -28
- package/frontend/dist/ui/gradient.d.ts +0 -5
- package/frontend/dist/ui/gradient.js +17 -22
- package/frontend/dist/ui/image.d.ts +27 -58
- package/frontend/dist/ui/image.js +99 -93
- package/frontend/dist/ui/input.d.ts +20 -97
- package/frontend/dist/ui/input.js +192 -170
- package/frontend/dist/ui/link.d.ts +0 -18
- package/frontend/dist/ui/link.js +42 -48
- package/frontend/dist/ui/list.js +36 -37
- package/frontend/dist/ui/loader_button.d.ts +4 -19
- package/frontend/dist/ui/loader_button.js +35 -37
- package/frontend/dist/ui/loaders.d.ts +0 -8
- package/frontend/dist/ui/loaders.js +20 -25
- package/frontend/dist/ui/popup.d.ts +11 -8
- package/frontend/dist/ui/popup.js +183 -24
- package/frontend/dist/ui/pseudo.d.ts +3 -3
- package/frontend/dist/ui/pseudo.js +14 -17
- package/frontend/dist/ui/scroller.d.ts +10 -48
- package/frontend/dist/ui/scroller.js +306 -300
- package/frontend/dist/ui/slider.d.ts +9 -3
- package/frontend/dist/ui/slider.js +31 -17
- package/frontend/dist/ui/spacer.d.ts +0 -9
- package/frontend/dist/ui/spacer.js +21 -26
- package/frontend/dist/ui/span.js +13 -15
- package/frontend/dist/ui/stack.d.ts +14 -75
- package/frontend/dist/ui/stack.js +166 -169
- package/frontend/dist/ui/steps.d.ts +10 -23
- package/frontend/dist/ui/steps.js +47 -34
- package/frontend/dist/ui/style.d.ts +4 -3
- package/frontend/dist/ui/style.js +13 -18
- package/frontend/dist/ui/switch.d.ts +10 -4
- package/frontend/dist/ui/switch.js +24 -16
- package/frontend/dist/ui/table.d.ts +0 -23
- package/frontend/dist/ui/table.js +113 -119
- package/frontend/dist/ui/tabs.d.ts +3 -19
- package/frontend/dist/ui/tabs.js +35 -29
- package/frontend/dist/ui/text.d.ts +0 -8
- package/frontend/dist/ui/text.js +20 -25
- package/frontend/dist/ui/title.d.ts +0 -15
- package/frontend/dist/ui/title.js +39 -45
- package/frontend/dist/ui/ui.d.ts +0 -2
- package/frontend/dist/ui/ui.js +0 -2
- package/frontend/dist/ui/view.d.ts +3 -17
- package/frontend/dist/ui/view.js +27 -32
- package/frontend/dist/volt.d.ts +2 -1
- package/frontend/dist/volt.js +3 -1
- package/frontend/examples/dashboard/dashboard.ts +774 -0
- package/frontend/examples/theme/theme.ts +58 -0
- package/frontend/src/css/volt.css +5 -0
- package/frontend/src/elements/base.ts +767 -545
- package/frontend/src/elements/module.ts +90 -29
- package/frontend/src/elements/register_element.ts +24 -0
- package/frontend/src/modules/auth.ts +7 -6
- package/frontend/src/modules/color.ts +348 -0
- package/frontend/src/modules/colors.ts +468 -449
- package/frontend/src/modules/cookies.ts +1 -0
- package/frontend/src/modules/events.ts +1 -0
- package/frontend/src/modules/google.ts +1 -0
- package/frontend/src/modules/meta.ts +2 -1
- package/frontend/src/modules/mutex.ts +2 -4
- package/frontend/src/modules/paddle.ts +21 -20
- package/frontend/src/modules/scheme.ts +5 -4
- package/frontend/src/modules/statics.ts +2 -1
- package/frontend/src/modules/support.ts +3 -2
- package/frontend/src/modules/theme.ts +413 -0
- package/frontend/src/modules/themes.ts +2 -1
- package/frontend/src/modules/user.ts +12 -11
- package/frontend/src/modules/utils.ts +125 -2
- package/frontend/src/ui/border_button.ts +41 -37
- package/frontend/src/ui/button.ts +33 -32
- package/frontend/src/ui/canvas.ts +5 -2
- package/frontend/src/ui/checkbox.ts +21 -22
- package/frontend/src/ui/code.ts +92 -86
- package/frontend/src/ui/context_menu.ts +7 -5
- package/frontend/src/ui/css.ts +1 -1
- package/frontend/src/ui/divider.ts +15 -10
- package/frontend/src/ui/dropdown.ts +38 -21
- package/frontend/src/ui/for_each.ts +9 -8
- package/frontend/src/ui/form.ts +26 -21
- package/frontend/src/ui/frame_modes.ts +13 -17
- package/frontend/src/ui/google_map.ts +15 -13
- package/frontend/src/ui/gradient.ts +9 -8
- package/frontend/src/ui/image.ts +108 -86
- package/frontend/src/ui/input.ts +145 -144
- package/frontend/src/ui/link.ts +25 -23
- package/frontend/src/ui/list.ts +12 -6
- package/frontend/src/ui/loader_button.ts +26 -25
- package/frontend/src/ui/loaders.ts +12 -11
- package/frontend/src/ui/popup.ts +168 -14
- package/frontend/src/ui/pseudo.ts +5 -3
- package/frontend/src/ui/scroller.ts +303 -294
- package/frontend/src/ui/slider.ts +15 -10
- package/frontend/src/ui/spacer.ts +14 -11
- package/frontend/src/ui/span.ts +6 -2
- package/frontend/src/ui/stack.ts +196 -183
- package/frontend/src/ui/steps.ts +38 -22
- package/frontend/src/ui/style.ts +7 -4
- package/frontend/src/ui/switch.ts +16 -11
- package/frontend/src/ui/table.ts +42 -34
- package/frontend/src/ui/tabs.ts +20 -19
- package/frontend/src/ui/text.ts +12 -11
- package/frontend/src/ui/title.ts +22 -20
- package/frontend/src/ui/ui.ts +0 -2
- package/frontend/src/ui/view.ts +20 -19
- package/frontend/src/volt.ts +3 -1
- package/frontend/{compile.js → tools/compile.old.js} +2 -2
- package/frontend/tools/embed_scripts.js +69 -0
- package/frontend/tsconfig.json +26 -0
- package/package.json +7 -6
- package/frontend/dist/ui/theme.d.ts +0 -25
- package/frontend/exports.json +0 -1340
- package/frontend/src/modules/date.js +0 -535
- package/frontend/src/ui/color.ts +0 -117
- package/frontend/src/ui/theme.ts +0 -279
- /package/backend/src/{vinc.dev.js → vinc.dev.ts} +0 -0
package/frontend/src/ui/theme.ts
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Author: Daan van den Bergh
|
|
3
|
-
* Copyright: © 2022 - 2024 Daan van den Bergh.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Imports.
|
|
7
|
-
import { Elements } from "../elements/module.js"
|
|
8
|
-
import { Colors } from "../modules/colors"
|
|
9
|
-
import { Themes as ThemesModule } from "../modules/themes"
|
|
10
|
-
|
|
11
|
-
type OnActivateCallback = (element: ThemeClass, theme: string) => void;
|
|
12
|
-
|
|
13
|
-
// Themes class.
|
|
14
|
-
/* @docs:
|
|
15
|
-
@nav: Frontend
|
|
16
|
-
@chapter: Themes
|
|
17
|
-
@note: The `ThemesClass` is also initializable under function `Themes`.
|
|
18
|
-
@desc:
|
|
19
|
-
A themes class to efficiently style the site using themes.
|
|
20
|
-
|
|
21
|
-
The constructor arguments must be a theme style per theme name. Every theme variable should exist in all themes or it may cause undefined behaviour. The theme name that is passed first will be the active theme by default.
|
|
22
|
-
```
|
|
23
|
-
Theme("main-theme", {
|
|
24
|
-
light: {
|
|
25
|
-
text_fg: "#000000",
|
|
26
|
-
},
|
|
27
|
-
dark: {
|
|
28
|
-
text_fg: "#FFFFFF",
|
|
29
|
-
},
|
|
30
|
-
})
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
When theme attributes are retrieved, by default they will be the active theme's attribute as a css variable. So this can be passed to an element.
|
|
34
|
-
However, some element functions do not accept css variables, in this case the `value()` function can be used to retrieve the raw value. Do not forget to apply an `on_theme_update()` callback on the elements where you use this.
|
|
35
|
-
*/
|
|
36
|
-
export class ThemeClass {
|
|
37
|
-
|
|
38
|
-
// Attributes.
|
|
39
|
-
public active_id?: string;
|
|
40
|
-
public active?: Record<string, any>;
|
|
41
|
-
public _theme_ids: string[];
|
|
42
|
-
public _attrs: string[];
|
|
43
|
-
public _css_vars: Record<string, string | String>;
|
|
44
|
-
public _id: string;
|
|
45
|
-
public _on_activate_callback?: OnActivateCallback;
|
|
46
|
-
|
|
47
|
-
constructor(
|
|
48
|
-
id: string,
|
|
49
|
-
themes: Record<string, any> = {},
|
|
50
|
-
) {
|
|
51
|
-
|
|
52
|
-
// Attributes.
|
|
53
|
-
this.active_id = undefined;
|
|
54
|
-
this.active = undefined;
|
|
55
|
-
this._theme_ids = [];
|
|
56
|
-
this._attrs = [];
|
|
57
|
-
this._css_vars = {};
|
|
58
|
-
this._id = id;
|
|
59
|
-
|
|
60
|
-
// Assign themes.
|
|
61
|
-
Object.keys(themes).iterate((theme) => {
|
|
62
|
-
|
|
63
|
-
// Initialize.
|
|
64
|
-
const theme_style = themes[theme] as Record<string, any>;
|
|
65
|
-
this._theme_ids.append(theme);
|
|
66
|
-
this[theme] = theme_style;
|
|
67
|
-
|
|
68
|
-
// Activate first theme.
|
|
69
|
-
if (this.active_id === undefined) {
|
|
70
|
-
this.active_id = theme;
|
|
71
|
-
this.active = theme_style;
|
|
72
|
-
Object.keys(this.active as any).iterate((id) => {
|
|
73
|
-
document.documentElement.style.setProperty(`--${this._id}_${id}`, (this.active as any)[id] ?? "");
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Initialize attr funcs.
|
|
78
|
-
Object.keys(theme_style).iterate((id) => {
|
|
79
|
-
this._add_attr(id, theme);
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Add a new attribute.
|
|
85
|
-
_add_attr(id: string, theme?: string) : void {
|
|
86
|
-
if (theme == null) {
|
|
87
|
-
this._css_vars[id] = `var(--${this._id}_${id})`;
|
|
88
|
-
} else {
|
|
89
|
-
const theme_style = this[theme];
|
|
90
|
-
if (
|
|
91
|
-
typeof theme_style[id] === "string" &&
|
|
92
|
-
(
|
|
93
|
-
theme_style[id].indexOf("linear-gradient") !== -1 ||
|
|
94
|
-
theme_style[id].indexOf("radial-gradient") !== -1
|
|
95
|
-
)
|
|
96
|
-
) {
|
|
97
|
-
theme_style[id] = new String(theme_style[id]);
|
|
98
|
-
theme_style[id]._is_gradient = true;
|
|
99
|
-
this._css_vars[id] = new String(`var(--${this._id}_${id})`);
|
|
100
|
-
(this._css_vars[id] as any)._is_gradient = true;
|
|
101
|
-
} else {
|
|
102
|
-
this._css_vars[id] = `var(--${this._id}_${id})`;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
Object.defineProperty(this, id, {
|
|
106
|
-
get: function() {
|
|
107
|
-
return this._css_vars[id];
|
|
108
|
-
},
|
|
109
|
-
set: function(v: any) {
|
|
110
|
-
// only for support this does not work however.
|
|
111
|
-
// document.documentElement.style.setProperty(`--${this._id}_${id}`, (this.active as any)[id] ?? "");
|
|
112
|
-
// return this;
|
|
113
|
-
},
|
|
114
|
-
enumerable: true,
|
|
115
|
-
configurable: true,
|
|
116
|
-
});
|
|
117
|
-
this._attrs.append(id);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Assign a new value.
|
|
121
|
-
set(theme: string, key: string, value: any) : this {
|
|
122
|
-
|
|
123
|
-
// Update theme.
|
|
124
|
-
const theme_style = this[theme];
|
|
125
|
-
if (typeof value === "string" && (value.indexOf("linear-gradient") !== -1 || value.indexOf("radial-gradient") !== -1)) {
|
|
126
|
-
theme_style[key] = new String(value);
|
|
127
|
-
theme_style[key]._is_gradient = true;
|
|
128
|
-
this._css_vars[key] = new String(`var(--${this._id}_${key})`);
|
|
129
|
-
(this._css_vars[key] as any)._is_gradient = true;
|
|
130
|
-
} else {
|
|
131
|
-
theme_style[key] = value;
|
|
132
|
-
this._css_vars[key] = `var(--${this._id}_${key})`;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Set property.
|
|
136
|
-
if (this.active_id === theme) {
|
|
137
|
-
document.documentElement.style.setProperty(`--${this._id}_${key}`, (this.active as any)[key] ?? "");
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Response.
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
get id(): string {
|
|
145
|
-
return `${this._id}.${this.active_id}`
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Initialize by cached.
|
|
149
|
-
initialize(id?: string) : this {
|
|
150
|
-
if (id == null) {
|
|
151
|
-
id = localStorage.getItem(this._id) ?? undefined;
|
|
152
|
-
}
|
|
153
|
-
if (id != null && this._theme_ids.includes(id)) {
|
|
154
|
-
this.activate(id);
|
|
155
|
-
}
|
|
156
|
-
return this;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Get raw value.
|
|
160
|
-
value(id) : any {
|
|
161
|
-
if (this.active === undefined) { return ; }
|
|
162
|
-
return this.active[id];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Opacity.
|
|
166
|
-
// Opacity must be a number `0.0` till `1.0`, and may also be an object with opacity pet theme `{dark: 0.2, light: 0.35}`.
|
|
167
|
-
opacity(id: string, opacity: number = 1.0): string {
|
|
168
|
-
|
|
169
|
-
// Create full id.
|
|
170
|
-
let full_id;
|
|
171
|
-
if (typeof opacity === "number") {
|
|
172
|
-
full_id = `${id}_opac_${opacity}`;
|
|
173
|
-
} else {
|
|
174
|
-
full_id = `${id}_opac_${Object.values(opacity).join("_")}`;
|
|
175
|
-
}
|
|
176
|
-
full_id = full_id.replaceAll(".", "_");
|
|
177
|
-
|
|
178
|
-
// Already created.
|
|
179
|
-
if (this._css_vars[full_id]) {
|
|
180
|
-
return this._css_vars[full_id] as string;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Iterate.
|
|
184
|
-
let index = 0;
|
|
185
|
-
for (const theme_id of this._theme_ids) {
|
|
186
|
-
const theme = this[theme_id];
|
|
187
|
-
|
|
188
|
-
// Checks.
|
|
189
|
-
if (theme[id] == null) {
|
|
190
|
-
console.error(new Error(`Theme attribute "${id}" does not exist.`));
|
|
191
|
-
return "";
|
|
192
|
-
}
|
|
193
|
-
if (theme[id]._is_gradient) {
|
|
194
|
-
console.error(new Error(`Unable to set the opacity on gradient color "${id}".`));
|
|
195
|
-
return "";
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Create new color.
|
|
199
|
-
let theme_opac = opacity;
|
|
200
|
-
if (typeof theme_opac === "object") {
|
|
201
|
-
theme_opac = theme_opac[this._theme_ids[index]];
|
|
202
|
-
if (theme_opac === undefined) {
|
|
203
|
-
console.error(new Error(`Unable to find the opacity on for theme id "${this._theme_ids[index]}".`));
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
theme[full_id] = Colors.set_opacity(theme[id], theme_opac);
|
|
207
|
-
|
|
208
|
-
// Add css var.
|
|
209
|
-
if (index === 0) {
|
|
210
|
-
this._add_attr(full_id);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Set property.
|
|
214
|
-
if (this.active_id === theme_id) {
|
|
215
|
-
document.documentElement.style.setProperty(`--${this._id}_${full_id}`, theme[full_id]);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// Incr index
|
|
219
|
-
++index;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return this._css_vars[full_id] as string;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// Activate a theme.
|
|
226
|
-
activate(id: string, apply_theme_update: boolean = true) : this {
|
|
227
|
-
if (this._theme_ids.includes(id) === false || this[id] === undefined) {
|
|
228
|
-
throw Error(`Theme "${id}" does not exist.`);
|
|
229
|
-
}
|
|
230
|
-
this.active_id = id;
|
|
231
|
-
this.active = this[id];
|
|
232
|
-
Object.keys(this.active as any).iterate((id) => {
|
|
233
|
-
document.documentElement.style.setProperty(`--${this._id}_${id}`, (this.active as any)[id] ?? "");
|
|
234
|
-
});
|
|
235
|
-
if (this._on_activate_callback != null) {
|
|
236
|
-
this._on_activate_callback(this, this.active_id);
|
|
237
|
-
}
|
|
238
|
-
if (apply_theme_update) {
|
|
239
|
-
ThemesModule.apply_theme_update();
|
|
240
|
-
}
|
|
241
|
-
localStorage.setItem(this._id, this.active_id);
|
|
242
|
-
return this;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Set an on activate callback.
|
|
246
|
-
on_activate() : OnActivateCallback | undefined;
|
|
247
|
-
on_activate(callback: OnActivateCallback) : this;
|
|
248
|
-
on_activate(callback?: OnActivateCallback) : this | OnActivateCallback | undefined {
|
|
249
|
-
if (callback == null) { return this._on_activate_callback; }
|
|
250
|
-
this._on_activate_callback = callback;
|
|
251
|
-
return this;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// Get cached active subtheme id.
|
|
255
|
-
get_active_id_cached() : string {
|
|
256
|
-
return localStorage.getItem(this._id) ?? "";
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Toggle themes.
|
|
260
|
-
toggle(apply_theme_update: boolean = true) : this {
|
|
261
|
-
if (this._theme_ids.length > 1) {
|
|
262
|
-
let active_index = -1;
|
|
263
|
-
for (let i = 0; i < this._theme_ids.length; i++) {
|
|
264
|
-
if (this._theme_ids[i] === this.active_id) {
|
|
265
|
-
active_index = i;
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
if (active_index !== -1 && active_index + 1 < this._theme_ids.length) {
|
|
270
|
-
this.activate(this._theme_ids[active_index + 1], apply_theme_update);
|
|
271
|
-
} else {
|
|
272
|
-
this.activate(this._theme_ids[0], apply_theme_update);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return this;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
export const Theme = Elements.wrapper(ThemeClass);
|
|
279
|
-
export const NullTheme = Elements.create_null(ThemeClass); //@todo duplicate name from Themes
|
|
File without changes
|