slicejs-web-framework 2.3.1 → 2.3.2
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/Slice/Components/Structural/ContextManager/ContextManager.js +369 -361
- package/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +258 -0
- package/Slice/Components/Structural/Controller/Controller.js +944 -925
- package/Slice/Components/Structural/Debugger/Debugger.js +1547 -1347
- package/Slice/Components/Structural/EventManager/EventManager.js +338 -329
- package/Slice/Components/Structural/EventManager/EventManagerDebugger.js +238 -0
- package/Slice/Components/Structural/Logger/Logger.js +146 -104
- package/Slice/Components/Structural/Router/Router.js +720 -598
- package/Slice/Components/Structural/StylesManager/StylesManager.js +64 -49
- package/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +84 -56
- package/Slice/Slice.js +383 -297
- package/package.json +1 -1
|
@@ -1,49 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
export default class StylesManager {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.componentStyles = document.createElement('style');
|
|
5
|
-
this.componentStyles.id = 'slice-component-styles';
|
|
6
|
-
document.head.appendChild(this.componentStyles);
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
theme =
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
1
|
+
|
|
2
|
+
export default class StylesManager {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.componentStyles = document.createElement('style');
|
|
5
|
+
this.componentStyles.id = 'slice-component-styles';
|
|
6
|
+
document.head.appendChild(this.componentStyles);
|
|
7
|
+
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Load global styles and initialize ThemeManager if enabled.
|
|
12
|
+
* @returns {Promise<void>}
|
|
13
|
+
*/
|
|
14
|
+
async init() {
|
|
15
|
+
for (let i = 0; i < slice.stylesConfig.requestedStyles.length; i++) {
|
|
16
|
+
const styles = await slice.controller.fetchText(slice.stylesConfig.requestedStyles[i], 'styles');
|
|
17
|
+
this.componentStyles.innerText += styles;
|
|
18
|
+
slice.logger.logInfo('StylesManager', `${slice.stylesConfig.requestedStyles[i]} styles loaded`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (slice.themeConfig.enabled) {
|
|
22
|
+
const module = await import(`${slice.paths.structuralComponentFolderPath}/StylesManager/ThemeManager/ThemeManager.js`);
|
|
23
|
+
|
|
24
|
+
this.themeManager = new module.default();
|
|
25
|
+
let theme;
|
|
26
|
+
|
|
27
|
+
if (slice.themeConfig.saveThemeLocally) {
|
|
28
|
+
theme = localStorage.getItem('sliceTheme');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!theme) {
|
|
32
|
+
theme = slice.themeConfig.defaultTheme;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (slice.themeConfig.useBrowserTheme) {
|
|
36
|
+
const browserTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'Dark' : 'Light';
|
|
37
|
+
theme = browserTheme;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await this.themeManager.applyTheme(theme);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//add a method that will add css as text to the componentStyles element
|
|
45
|
+
/**
|
|
46
|
+
* Append raw CSS to the global component style tag.
|
|
47
|
+
* @param {string} cssText
|
|
48
|
+
* @returns {void}
|
|
49
|
+
*/
|
|
50
|
+
appendComponentStyles(cssText) {
|
|
51
|
+
this.componentStyles.appendChild(document.createTextNode(cssText));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Register CSS for a component.
|
|
56
|
+
* @param {string} componentName
|
|
57
|
+
* @param {string} cssText
|
|
58
|
+
* @returns {void}
|
|
59
|
+
*/
|
|
60
|
+
registerComponentStyles(componentName, cssText) {
|
|
61
|
+
slice.controller.requestedStyles.add(componentName);
|
|
62
|
+
this.appendComponentStyles(cssText);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -1,56 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
slice.logger.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Manages theme CSS loading and persistence.
|
|
3
|
+
*/
|
|
4
|
+
export default class ThemeManager {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.themeStyles = new Map();
|
|
7
|
+
this.currentTheme = null;
|
|
8
|
+
this.themeStyle = document.createElement('style');
|
|
9
|
+
document.head.appendChild(this.themeStyle);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Apply a theme by name.
|
|
14
|
+
* @param {string} themeName
|
|
15
|
+
* @returns {Promise<void>}
|
|
16
|
+
*/
|
|
17
|
+
async applyTheme(themeName) {
|
|
18
|
+
if (!themeName) {
|
|
19
|
+
slice.logger.logError('ThemeManager', 'Invalid theme name');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!this.themeStyles.has(themeName)) {
|
|
24
|
+
await this.loadThemeCSS(themeName);
|
|
25
|
+
} else {
|
|
26
|
+
this.setThemeStyle(themeName);
|
|
27
|
+
this.saveThemeLocally(themeName, this.themeStyles.get(themeName));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Load theme CSS and cache it.
|
|
33
|
+
* @param {string} themeName
|
|
34
|
+
* @returns {Promise<void>}
|
|
35
|
+
*/
|
|
36
|
+
async loadThemeCSS(themeName) {
|
|
37
|
+
let themeContent =
|
|
38
|
+
localStorage.getItem(`sliceTheme-${themeName}`) || (await slice.controller.fetchText(themeName, 'theme'));
|
|
39
|
+
|
|
40
|
+
if (!themeContent) {
|
|
41
|
+
slice.logger.logError('ThemeManager', `Failed to load theme: ${themeName}`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this.themeStyles.set(themeName, themeContent);
|
|
46
|
+
this.setThemeStyle(themeName);
|
|
47
|
+
this.saveThemeLocally(themeName, themeContent);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Persist a theme in localStorage when enabled.
|
|
52
|
+
* @param {string} themeName
|
|
53
|
+
* @param {string} themeContent
|
|
54
|
+
* @returns {void}
|
|
55
|
+
*/
|
|
56
|
+
saveThemeLocally(themeName, themeContent) {
|
|
57
|
+
if (slice.themeConfig.saveThemeLocally) {
|
|
58
|
+
localStorage.setItem('sliceTheme', themeName);
|
|
59
|
+
localStorage.setItem(`sliceTheme-${themeName}`, themeContent);
|
|
60
|
+
slice.logger.logInfo('ThemeManager', `Theme ${themeName} saved locally`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Clear currently applied theme styles.
|
|
66
|
+
* @returns {void}
|
|
67
|
+
*/
|
|
68
|
+
removeCurrentTheme() {
|
|
69
|
+
if (this.currentTheme) {
|
|
70
|
+
this.themeStyle.textContent = '';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Set theme style text and mark current theme.
|
|
76
|
+
* @param {string} themeName
|
|
77
|
+
* @returns {void}
|
|
78
|
+
*/
|
|
79
|
+
setThemeStyle(themeName) {
|
|
80
|
+
this.themeStyle.textContent = this.themeStyles.get(themeName);
|
|
81
|
+
this.currentTheme = themeName;
|
|
82
|
+
slice.logger.logInfo('ThemeManager', `Theme ${themeName} applied`);
|
|
83
|
+
}
|
|
84
|
+
}
|