@kupola/kupola 1.7.0 → 1.7.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/dist/kupola.cjs.js +17 -17
- package/dist/kupola.cjs.js.map +1 -1
- package/dist/kupola.esm.js +911 -875
- package/dist/kupola.esm.js.map +1 -1
- package/dist/kupola.umd.js +22 -22
- package/dist/kupola.umd.js.map +1 -1
- package/js/kupola-config.js +45 -0
- package/js/theme.js +31 -16
- package/package.json +1 -1
package/js/kupola-config.js
CHANGED
|
@@ -94,8 +94,53 @@ const config = {
|
|
|
94
94
|
},
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
+
const configChangeListeners = [];
|
|
98
|
+
|
|
99
|
+
function loadConfigFromGlobal() {
|
|
100
|
+
if (typeof window !== 'undefined' && window.kupolaConfig) {
|
|
101
|
+
try {
|
|
102
|
+
mergeDeep(config, window.kupolaConfig);
|
|
103
|
+
notifyConfigChange();
|
|
104
|
+
} catch (e) {
|
|
105
|
+
console.warn('[Kupola] Failed to parse window.kupolaConfig:', e);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function notifyConfigChange() {
|
|
111
|
+
configChangeListeners.forEach(listener => {
|
|
112
|
+
try {
|
|
113
|
+
listener(config);
|
|
114
|
+
} catch (e) {
|
|
115
|
+
console.warn('[Kupola] Error in config change listener:', e);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function onConfigChange(listener) {
|
|
121
|
+
if (typeof listener === 'function') {
|
|
122
|
+
configChangeListeners.push(listener);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function offConfigChange(listener) {
|
|
127
|
+
const index = configChangeListeners.indexOf(listener);
|
|
128
|
+
if (index > -1) {
|
|
129
|
+
configChangeListeners.splice(index, 1);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (typeof document !== 'undefined') {
|
|
134
|
+
if (document.readyState === 'loading') {
|
|
135
|
+
document.addEventListener('DOMContentLoaded', loadConfigFromGlobal);
|
|
136
|
+
} else {
|
|
137
|
+
loadConfigFromGlobal();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
97
141
|
export function setConfig(options) {
|
|
98
142
|
mergeDeep(config, options);
|
|
143
|
+
notifyConfigChange();
|
|
99
144
|
}
|
|
100
145
|
|
|
101
146
|
export function getConfig(key) {
|
package/js/theme.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import { getIconsPath, getDefaultTheme, getDefaultBrand, setConfig } from './kupola-config.js';
|
|
1
|
+
import { getIconsPath, getDefaultTheme, getDefaultBrand, setConfig, onConfigChange } from './kupola-config.js';
|
|
2
2
|
|
|
3
3
|
const THEME_KEY = 'kupola-theme';
|
|
4
4
|
const BRAND_KEY = 'kupola-brand';
|
|
5
|
+
let _themeInitialized = false;
|
|
6
|
+
|
|
7
|
+
onConfigChange((newConfig) => {
|
|
8
|
+
const toggleBtn = document.querySelector('[data-theme-toggle]');
|
|
9
|
+
if (toggleBtn) {
|
|
10
|
+
const currentTheme = getTheme();
|
|
11
|
+
updateThemeIcon(toggleBtn);
|
|
12
|
+
setTheme(currentTheme);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
5
15
|
|
|
6
16
|
const BRAND_OPTIONS = [
|
|
7
17
|
{ id: 'green', name: '翠绿', color: '#32F08C' },
|
|
@@ -88,21 +98,26 @@ function updateThemeIcon(toggleBtn) {
|
|
|
88
98
|
function initTheme() {
|
|
89
99
|
|
|
90
100
|
const toggleBtn = document.querySelector('[data-theme-toggle]');
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
|
|
102
|
+
if (!_themeInitialized) {
|
|
103
|
+
_themeInitialized = true;
|
|
104
|
+
|
|
105
|
+
if (toggleBtn) {
|
|
106
|
+
const iconEl = toggleBtn.querySelector('.theme-icon');
|
|
107
|
+
if (iconEl && iconEl.src) {
|
|
108
|
+
const currentIconsPath = getIconsPath();
|
|
109
|
+
if (currentIconsPath === '/icons/') {
|
|
110
|
+
const iconPath = iconEl.src.substring(0, iconEl.src.lastIndexOf('/') + 1);
|
|
111
|
+
const basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1);
|
|
112
|
+
const relativeIconsPath = iconPath.replace(window.location.origin + basePath, '');
|
|
113
|
+
if (relativeIconsPath !== iconPath) {
|
|
114
|
+
setConfig({
|
|
115
|
+
paths: {
|
|
116
|
+
icons: relativeIconsPath,
|
|
117
|
+
base: basePath
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
106
121
|
}
|
|
107
122
|
}
|
|
108
123
|
}
|
package/package.json
CHANGED