@kupola/kupola 1.7.1 → 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.
@@ -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,9 +1,18 @@
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
5
  let _themeInitialized = false;
6
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
+ });
15
+
7
16
  const BRAND_OPTIONS = [
8
17
  { id: 'green', name: '翠绿', color: '#32F08C' },
9
18
  { id: 'xionghuang', name: '雄黄', color: '#FF9900' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kupola/kupola",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "A lightweight UI toolkit for any web project. No heavy frontend frameworks required.",
5
5
  "main": "dist/kupola.cjs.js",
6
6
  "module": "dist/kupola.esm.js",