slicejs-web-framework 4.0.0 → 4.0.1

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.
Files changed (70) hide show
  1. package/.opencode/opencode.json +14 -14
  2. package/LICENSE +21 -21
  3. package/README.md +97 -97
  4. package/Slice/Components/Structural/ContextManager/ContextManager.js +422 -422
  5. package/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +470 -470
  6. package/Slice/Components/Structural/Controller/Controller.js +1406 -1406
  7. package/Slice/Components/Structural/Controller/allowedValuesValidation.js +52 -52
  8. package/Slice/Components/Structural/Debugger/Debugger.html +72 -72
  9. package/Slice/Components/Structural/Debugger/Debugger.js +1505 -1505
  10. package/Slice/Components/Structural/EventManager/EventManager.js +651 -651
  11. package/Slice/Components/Structural/EventManager/EventManagerDebugger.js +985 -985
  12. package/Slice/Components/Structural/LeakInspector/LeakInspector.js +296 -296
  13. package/Slice/Components/Structural/Logger/Log.js +10 -10
  14. package/Slice/Components/Structural/Logger/LogViewer/LogViewer.js +662 -662
  15. package/Slice/Components/Structural/Logger/Logger.js +225 -225
  16. package/Slice/Components/Structural/Router/Router.js +793 -793
  17. package/Slice/Components/Structural/StylesManager/StylesManager.js +82 -82
  18. package/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +162 -162
  19. package/Slice/Slice.js +686 -697
  20. package/Slice/tests/build-bundled-component-without-category.test.js +103 -103
  21. package/Slice/tests/build-js-only-visual-components.test.js +144 -144
  22. package/Slice/tests/build-singleton.test.js +244 -244
  23. package/Slice/tests/bundle-v2-runtime-contract.test.js +738 -738
  24. package/Slice/tests/context-patch-use.test.js +95 -95
  25. package/Slice/tests/destroy-cascade.test.js +215 -215
  26. package/Slice/tests/event-emitters.test.js +79 -79
  27. package/Slice/tests/event-registry.test.js +141 -141
  28. package/Slice/tests/fixtures/real-runtime-loader.mjs +21 -21
  29. package/Slice/tests/leak-orphans.test.js +131 -131
  30. package/Slice/tests/props-allowed-values-validation.test.js +119 -119
  31. package/Slice/tests/public-env-runtime-accessors.test.js +44 -44
  32. package/Slice/tests/public-env-typed-accessors.test.js +66 -66
  33. package/Slice/tests/router-loading-finally.test.js +68 -68
  34. package/api/framework/devDepsOptimizer.js +335 -335
  35. package/api/framework/express.js +3 -3
  36. package/api/framework/precompressedStatic.js +93 -93
  37. package/api/framework/publicEnvResolver.js +123 -123
  38. package/api/framework/securityMiddleware.js +197 -197
  39. package/api/framework/server.js +411 -411
  40. package/api/index.js +7 -7
  41. package/api/tests/dev-deps-optimizer.test.js +137 -137
  42. package/api/tests/dev-server-external.test.js +56 -56
  43. package/api/tests/precompressed-static.test.js +119 -119
  44. package/api/tests/public-env-resolver.test.js +193 -193
  45. package/package.json +49 -49
  46. package/sliceConfig.schema.json +122 -122
  47. package/src/App/index.html +69 -69
  48. package/src/App/index.js +20 -20
  49. package/src/App/style.css +11 -11
  50. package/src/Components/AppComponents/AboutSection/AboutSection.css +9 -9
  51. package/src/Components/AppComponents/AboutSection/AboutSection.html +8 -8
  52. package/src/Components/AppComponents/AboutSection/AboutSection.js +12 -12
  53. package/src/Components/AppComponents/AppShell/AppShell.css +10 -10
  54. package/src/Components/AppComponents/AppShell/AppShell.html +4 -4
  55. package/src/Components/AppComponents/AppShell/AppShell.js +36 -36
  56. package/src/Components/AppComponents/HomeSection/HomeSection.css +20 -20
  57. package/src/Components/AppComponents/HomeSection/HomeSection.html +10 -10
  58. package/src/Components/AppComponents/HomeSection/HomeSection.js +19 -19
  59. package/src/Components/components.js +8 -8
  60. package/src/public/Styles/sliceStyles.css +34 -34
  61. package/src/public/Themes/Dark.css +42 -42
  62. package/src/public/Themes/Light.css +31 -31
  63. package/src/public/Themes/Slice.css +47 -47
  64. package/src/public/manifest.json +15 -15
  65. package/src/public/robots.txt +4 -4
  66. package/src/public/sitemap.xml +8 -8
  67. package/src/routes.js +9 -9
  68. package/src/sliceConfig.json +72 -72
  69. package/tests/router-emit-ordering.test.js +63 -63
  70. package/types/index.d.ts +219 -219
@@ -1,82 +1,82 @@
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
- const requestedStyles = Array.isArray(slice.stylesConfig.requestedStyles)
16
- ? slice.stylesConfig.requestedStyles
17
- : [];
18
-
19
- const styleResults = await Promise.all(
20
- requestedStyles.map(async (styleName) => {
21
- const styles = await slice.controller.fetchText(styleName, 'styles');
22
- return { styleName, styles };
23
- })
24
- );
25
-
26
- for (const { styleName, styles } of styleResults) {
27
- this.appendComponentStyles(styles);
28
- slice.logger.logInfo('StylesManager', `${styleName} styles loaded`);
29
- }
30
-
31
- if (slice.themeConfig.enabled) {
32
- const ThemeManagerClass = slice.frameworkClasses?.ThemeManager
33
- || await slice.getClass(`${slice.paths.structuralComponentFolderPath}/StylesManager/ThemeManager/ThemeManager.js`);
34
- if (!ThemeManagerClass) {
35
- throw new Error('ThemeManager not available');
36
- }
37
-
38
- this.themeManager = new ThemeManagerClass();
39
- let theme;
40
-
41
- if (slice.themeConfig.saveThemeLocally) {
42
- theme = localStorage.getItem('sliceTheme');
43
- }
44
-
45
- if (!theme) {
46
- theme = slice.themeConfig.defaultTheme;
47
- }
48
-
49
- if (slice.themeConfig.useBrowserTheme) {
50
- const browserTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'Dark' : 'Light';
51
- theme = browserTheme;
52
- }
53
-
54
- await this.themeManager.applyTheme(theme);
55
- }
56
- }
57
-
58
- //add a method that will add css as text to the componentStyles element
59
- /**
60
- * Append raw CSS to the global component style tag.
61
- * @param {string} cssText
62
- * @returns {void}
63
- */
64
- appendComponentStyles(cssText) {
65
- this.componentStyles.appendChild(document.createTextNode(cssText));
66
- }
67
-
68
- /**
69
- * Register CSS for a component.
70
- * @param {string} componentName
71
- * @param {string} cssText
72
- * @returns {void}
73
- */
74
- registerComponentStyles(componentName, cssText) {
75
- // Idempotent: a component's CSS is injected at most once, no matter how many
76
- // times it is built or how a caller reaches here (Controller guards upstream,
77
- // but the debuggers and the resource loader do not).
78
- if (slice.controller.requestedStyles.has(componentName)) return;
79
- slice.controller.requestedStyles.add(componentName);
80
- this.appendComponentStyles(cssText);
81
- }
82
- }
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
+ const requestedStyles = Array.isArray(slice.stylesConfig.requestedStyles)
16
+ ? slice.stylesConfig.requestedStyles
17
+ : [];
18
+
19
+ const styleResults = await Promise.all(
20
+ requestedStyles.map(async (styleName) => {
21
+ const styles = await slice.controller.fetchText(styleName, 'styles');
22
+ return { styleName, styles };
23
+ })
24
+ );
25
+
26
+ for (const { styleName, styles } of styleResults) {
27
+ this.appendComponentStyles(styles);
28
+ slice.logger.logInfo('StylesManager', `${styleName} styles loaded`);
29
+ }
30
+
31
+ if (slice.themeConfig.enabled) {
32
+ const ThemeManagerClass = slice.frameworkClasses?.ThemeManager
33
+ || await slice.getClass(`${slice.paths.structuralComponentFolderPath}/StylesManager/ThemeManager/ThemeManager.js`);
34
+ if (!ThemeManagerClass) {
35
+ throw new Error('ThemeManager not available');
36
+ }
37
+
38
+ this.themeManager = new ThemeManagerClass();
39
+ let theme;
40
+
41
+ if (slice.themeConfig.saveThemeLocally) {
42
+ theme = localStorage.getItem('sliceTheme');
43
+ }
44
+
45
+ if (!theme) {
46
+ theme = slice.themeConfig.defaultTheme;
47
+ }
48
+
49
+ if (slice.themeConfig.useBrowserTheme) {
50
+ const browserTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'Dark' : 'Light';
51
+ theme = browserTheme;
52
+ }
53
+
54
+ await this.themeManager.applyTheme(theme);
55
+ }
56
+ }
57
+
58
+ //add a method that will add css as text to the componentStyles element
59
+ /**
60
+ * Append raw CSS to the global component style tag.
61
+ * @param {string} cssText
62
+ * @returns {void}
63
+ */
64
+ appendComponentStyles(cssText) {
65
+ this.componentStyles.appendChild(document.createTextNode(cssText));
66
+ }
67
+
68
+ /**
69
+ * Register CSS for a component.
70
+ * @param {string} componentName
71
+ * @param {string} cssText
72
+ * @returns {void}
73
+ */
74
+ registerComponentStyles(componentName, cssText) {
75
+ // Idempotent: a component's CSS is injected at most once, no matter how many
76
+ // times it is built or how a caller reaches here (Controller guards upstream,
77
+ // but the debuggers and the resource loader do not).
78
+ if (slice.controller.requestedStyles.has(componentName)) return;
79
+ slice.controller.requestedStyles.add(componentName);
80
+ this.appendComponentStyles(cssText);
81
+ }
82
+ }
@@ -1,162 +1,162 @@
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
- // In-flight loads, keyed by theme name, so concurrent applyTheme() calls for
9
- // the same theme share one fetch instead of racing and double-fetching.
10
- this._loadingThemes = new Map();
11
- this.themeStyle = document.createElement('style');
12
- document.head.appendChild(this.themeStyle);
13
- }
14
-
15
- /**
16
- * Apply a theme by name.
17
- * @param {string} themeName
18
- * @returns {Promise<void>}
19
- */
20
- async applyTheme(themeName) {
21
- if (!themeName) {
22
- slice.logger.logError('ThemeManager', 'Invalid theme name');
23
- return;
24
- }
25
-
26
- // Already the active theme — nothing to re-inject.
27
- if (themeName === this.currentTheme) {
28
- return;
29
- }
30
-
31
- if (this.themeStyles.has(themeName)) {
32
- this.setThemeStyle(themeName);
33
- this.saveThemeLocally(themeName, this.themeStyles.get(themeName));
34
- return;
35
- }
36
-
37
- // Coalesce concurrent loads of the same theme into a single fetch.
38
- if (!this._loadingThemes.has(themeName)) {
39
- this._loadingThemes.set(
40
- themeName,
41
- this.loadThemeCSS(themeName).finally(() => this._loadingThemes.delete(themeName))
42
- );
43
- }
44
- await this._loadingThemes.get(themeName);
45
- }
46
-
47
- /**
48
- * Load theme CSS and cache it.
49
- * @param {string} themeName
50
- * @returns {Promise<void>}
51
- */
52
- async loadThemeCSS(themeName) {
53
- let themeContent =
54
- localStorage.getItem(`sliceTheme-${themeName}`) || (await slice.controller.fetchText(themeName, 'theme'));
55
-
56
- if (!themeContent) {
57
- slice.logger.logError('ThemeManager', `Failed to load theme: ${themeName}`);
58
- return;
59
- }
60
-
61
- this.themeStyles.set(themeName, themeContent);
62
- this.setThemeStyle(themeName);
63
- this.saveThemeLocally(themeName, themeContent);
64
- }
65
-
66
- /**
67
- * Persist a theme in localStorage when enabled.
68
- * @param {string} themeName
69
- * @param {string} themeContent
70
- * @returns {void}
71
- */
72
- saveThemeLocally(themeName, themeContent) {
73
- if (slice.themeConfig.saveThemeLocally) {
74
- localStorage.setItem('sliceTheme', themeName);
75
- localStorage.setItem(`sliceTheme-${themeName}`, themeContent);
76
- slice.logger.logInfo('ThemeManager', `Theme ${themeName} saved locally`);
77
- }
78
- }
79
-
80
- /**
81
- * Clear currently applied theme styles.
82
- * @returns {void}
83
- */
84
- removeCurrentTheme() {
85
- if (this.currentTheme) {
86
- this.themeStyle.textContent = '';
87
- }
88
- }
89
-
90
- /**
91
- * Set theme style text and mark current theme.
92
- * @param {string} themeName
93
- * @returns {void}
94
- */
95
- setThemeStyle(themeName) {
96
- this.themeStyle.textContent = this.themeStyles.get(themeName);
97
- this.currentTheme = themeName;
98
- // Expose the active theme on the root element so CSS can react per theme
99
- // without any JS — e.g. [data-slice-theme="Dark"] .logo { filter: ... }.
100
- // Non-breaking: apps opt in only if they reference the attribute.
101
- if (typeof document !== 'undefined' && document.documentElement) {
102
- document.documentElement.setAttribute('data-slice-theme', themeName);
103
- }
104
- this._syncThemeColor();
105
- slice.logger.logInfo('ThemeManager', `Theme ${themeName} applied`);
106
- }
107
-
108
- /**
109
- * Sync <meta name="theme-color"> to the theme's primary background color.
110
- * Reads the CSS variable --primary-background-color from computed styles.
111
- * @returns {void}
112
- */
113
- /**
114
- * Sync <meta name="theme-color"> and <meta name="color-scheme">
115
- * from --primary-background-color (the active theme's body bg).
116
- * @returns {void}
117
- */
118
- _syncThemeColor() {
119
- if (typeof document === 'undefined') return;
120
- const bg = getComputedStyle(document.documentElement)
121
- .getPropertyValue('--primary-background-color').trim();
122
- if (!bg) return;
123
-
124
- let meta = document.querySelector('meta[name="theme-color"]');
125
- if (!meta) {
126
- meta = document.createElement('meta');
127
- meta.name = 'theme-color';
128
- document.head.appendChild(meta);
129
- }
130
- meta.content = bg;
131
-
132
- const scheme = this._isLightColor(bg) ? 'light' : 'dark';
133
- let cs = document.querySelector('meta[name="color-scheme"]');
134
- if (!cs) {
135
- cs = document.createElement('meta');
136
- cs.name = 'color-scheme';
137
- document.head.appendChild(cs);
138
- }
139
- cs.content = scheme;
140
- }
141
-
142
- /**
143
- * Rough luminance check for a hex color.
144
- * Returns true when the color is perceived as light.
145
- * @param {string} color hex (#fff / #282828)
146
- * @returns {boolean}
147
- */
148
- _isLightColor(color) {
149
- const hex = color.replace('#', '');
150
- let r, g, b;
151
- if (hex.length <= 3) {
152
- r = parseInt(hex[0] + hex[0], 16);
153
- g = parseInt(hex[1] + hex[1], 16);
154
- b = parseInt(hex[2] + hex[2], 16);
155
- } else {
156
- r = parseInt(hex.slice(0, 2), 16);
157
- g = parseInt(hex.slice(2, 4), 16);
158
- b = parseInt(hex.slice(4, 6), 16);
159
- }
160
- return (0.299 * r + 0.587 * g + 0.114 * b) / 255 > 0.5;
161
- }
162
- }
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
+ // In-flight loads, keyed by theme name, so concurrent applyTheme() calls for
9
+ // the same theme share one fetch instead of racing and double-fetching.
10
+ this._loadingThemes = new Map();
11
+ this.themeStyle = document.createElement('style');
12
+ document.head.appendChild(this.themeStyle);
13
+ }
14
+
15
+ /**
16
+ * Apply a theme by name.
17
+ * @param {string} themeName
18
+ * @returns {Promise<void>}
19
+ */
20
+ async applyTheme(themeName) {
21
+ if (!themeName) {
22
+ slice.logger.logError('ThemeManager', 'Invalid theme name');
23
+ return;
24
+ }
25
+
26
+ // Already the active theme — nothing to re-inject.
27
+ if (themeName === this.currentTheme) {
28
+ return;
29
+ }
30
+
31
+ if (this.themeStyles.has(themeName)) {
32
+ this.setThemeStyle(themeName);
33
+ this.saveThemeLocally(themeName, this.themeStyles.get(themeName));
34
+ return;
35
+ }
36
+
37
+ // Coalesce concurrent loads of the same theme into a single fetch.
38
+ if (!this._loadingThemes.has(themeName)) {
39
+ this._loadingThemes.set(
40
+ themeName,
41
+ this.loadThemeCSS(themeName).finally(() => this._loadingThemes.delete(themeName))
42
+ );
43
+ }
44
+ await this._loadingThemes.get(themeName);
45
+ }
46
+
47
+ /**
48
+ * Load theme CSS and cache it.
49
+ * @param {string} themeName
50
+ * @returns {Promise<void>}
51
+ */
52
+ async loadThemeCSS(themeName) {
53
+ let themeContent =
54
+ localStorage.getItem(`sliceTheme-${themeName}`) || (await slice.controller.fetchText(themeName, 'theme'));
55
+
56
+ if (!themeContent) {
57
+ slice.logger.logError('ThemeManager', `Failed to load theme: ${themeName}`);
58
+ return;
59
+ }
60
+
61
+ this.themeStyles.set(themeName, themeContent);
62
+ this.setThemeStyle(themeName);
63
+ this.saveThemeLocally(themeName, themeContent);
64
+ }
65
+
66
+ /**
67
+ * Persist a theme in localStorage when enabled.
68
+ * @param {string} themeName
69
+ * @param {string} themeContent
70
+ * @returns {void}
71
+ */
72
+ saveThemeLocally(themeName, themeContent) {
73
+ if (slice.themeConfig.saveThemeLocally) {
74
+ localStorage.setItem('sliceTheme', themeName);
75
+ localStorage.setItem(`sliceTheme-${themeName}`, themeContent);
76
+ slice.logger.logInfo('ThemeManager', `Theme ${themeName} saved locally`);
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Clear currently applied theme styles.
82
+ * @returns {void}
83
+ */
84
+ removeCurrentTheme() {
85
+ if (this.currentTheme) {
86
+ this.themeStyle.textContent = '';
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Set theme style text and mark current theme.
92
+ * @param {string} themeName
93
+ * @returns {void}
94
+ */
95
+ setThemeStyle(themeName) {
96
+ this.themeStyle.textContent = this.themeStyles.get(themeName);
97
+ this.currentTheme = themeName;
98
+ // Expose the active theme on the root element so CSS can react per theme
99
+ // without any JS — e.g. [data-slice-theme="Dark"] .logo { filter: ... }.
100
+ // Non-breaking: apps opt in only if they reference the attribute.
101
+ if (typeof document !== 'undefined' && document.documentElement) {
102
+ document.documentElement.setAttribute('data-slice-theme', themeName);
103
+ }
104
+ this._syncThemeColor();
105
+ slice.logger.logInfo('ThemeManager', `Theme ${themeName} applied`);
106
+ }
107
+
108
+ /**
109
+ * Sync <meta name="theme-color"> to the theme's primary background color.
110
+ * Reads the CSS variable --primary-background-color from computed styles.
111
+ * @returns {void}
112
+ */
113
+ /**
114
+ * Sync <meta name="theme-color"> and <meta name="color-scheme">
115
+ * from --primary-background-color (the active theme's body bg).
116
+ * @returns {void}
117
+ */
118
+ _syncThemeColor() {
119
+ if (typeof document === 'undefined') return;
120
+ const bg = getComputedStyle(document.documentElement)
121
+ .getPropertyValue('--primary-background-color').trim();
122
+ if (!bg) return;
123
+
124
+ let meta = document.querySelector('meta[name="theme-color"]');
125
+ if (!meta) {
126
+ meta = document.createElement('meta');
127
+ meta.name = 'theme-color';
128
+ document.head.appendChild(meta);
129
+ }
130
+ meta.content = bg;
131
+
132
+ const scheme = this._isLightColor(bg) ? 'light' : 'dark';
133
+ let cs = document.querySelector('meta[name="color-scheme"]');
134
+ if (!cs) {
135
+ cs = document.createElement('meta');
136
+ cs.name = 'color-scheme';
137
+ document.head.appendChild(cs);
138
+ }
139
+ cs.content = scheme;
140
+ }
141
+
142
+ /**
143
+ * Rough luminance check for a hex color.
144
+ * Returns true when the color is perceived as light.
145
+ * @param {string} color hex (#fff / #282828)
146
+ * @returns {boolean}
147
+ */
148
+ _isLightColor(color) {
149
+ const hex = color.replace('#', '');
150
+ let r, g, b;
151
+ if (hex.length <= 3) {
152
+ r = parseInt(hex[0] + hex[0], 16);
153
+ g = parseInt(hex[1] + hex[1], 16);
154
+ b = parseInt(hex[2] + hex[2], 16);
155
+ } else {
156
+ r = parseInt(hex.slice(0, 2), 16);
157
+ g = parseInt(hex.slice(2, 4), 16);
158
+ b = parseInt(hex.slice(4, 6), 16);
159
+ }
160
+ return (0.299 * r + 0.587 * g + 0.114 * b) / 255 > 0.5;
161
+ }
162
+ }