@yh-ui/theme 1.0.52 → 1.0.53
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/theme.cjs +33 -26
- package/dist/theme.d.ts +1 -0
- package/dist/theme.mjs +45 -26
- package/package.json +1 -1
package/dist/theme.cjs
CHANGED
|
@@ -420,8 +420,9 @@ const colorBlindPalettes = exports.colorBlindPalettes = {
|
|
|
420
420
|
const THEME_TRANSITION_CLASS = "yh-theme-transitioning";
|
|
421
421
|
const DEFAULT_TRANSITION_DURATION = 300;
|
|
422
422
|
const DEFAULT_TRANSITION_TIMING = "cubic-bezier(0.4, 0, 0.2, 1)";
|
|
423
|
-
function enableThemeTransition(duration = DEFAULT_TRANSITION_DURATION, timing = DEFAULT_TRANSITION_TIMING) {
|
|
423
|
+
function enableThemeTransition(duration = DEFAULT_TRANSITION_DURATION, timing = DEFAULT_TRANSITION_TIMING, el = null) {
|
|
424
424
|
if (typeof document === "undefined") return;
|
|
425
|
+
const target = el || document.documentElement;
|
|
425
426
|
const style = document.createElement("style");
|
|
426
427
|
style.id = "yh-theme-transition";
|
|
427
428
|
style.textContent = `
|
|
@@ -439,9 +440,9 @@ function enableThemeTransition(duration = DEFAULT_TRANSITION_DURATION, timing =
|
|
|
439
440
|
}
|
|
440
441
|
`;
|
|
441
442
|
document.head.appendChild(style);
|
|
442
|
-
|
|
443
|
+
target.classList.add(THEME_TRANSITION_CLASS);
|
|
443
444
|
setTimeout(() => {
|
|
444
|
-
|
|
445
|
+
target.classList.remove(THEME_TRANSITION_CLASS);
|
|
445
446
|
style.remove();
|
|
446
447
|
}, duration);
|
|
447
448
|
}
|
|
@@ -556,6 +557,7 @@ class ThemeManager {
|
|
|
556
557
|
};
|
|
557
558
|
themeHistory = [];
|
|
558
559
|
maxHistoryLength = 10;
|
|
560
|
+
responsiveVars = /* @__PURE__ */new Map();
|
|
559
561
|
// 响应式状态
|
|
560
562
|
state = (0, _vue.reactive)({
|
|
561
563
|
theme: "default",
|
|
@@ -668,11 +670,12 @@ class ThemeManager {
|
|
|
668
670
|
setDarkMode(dark) {
|
|
669
671
|
this.isDark = dark;
|
|
670
672
|
this.state.dark = dark;
|
|
671
|
-
|
|
673
|
+
const el = this.targetEl || (typeof document !== "undefined" ? document.documentElement : null);
|
|
674
|
+
if (el) {
|
|
672
675
|
if (dark) {
|
|
673
|
-
|
|
676
|
+
el.classList.add("dark");
|
|
674
677
|
} else {
|
|
675
|
-
|
|
678
|
+
el.classList.remove("dark");
|
|
676
679
|
}
|
|
677
680
|
}
|
|
678
681
|
const currentColors = {
|
|
@@ -919,7 +922,7 @@ class ThemeManager {
|
|
|
919
922
|
try {
|
|
920
923
|
const snapshot = JSON.parse(json);
|
|
921
924
|
if (this.transitionEnabled) {
|
|
922
|
-
enableThemeTransition(this.transitionConfig.duration, this.transitionConfig.timing);
|
|
925
|
+
enableThemeTransition(this.transitionConfig.duration, this.transitionConfig.timing, this.targetEl);
|
|
923
926
|
}
|
|
924
927
|
this.setPreset(snapshot.preset);
|
|
925
928
|
if (snapshot.colors && Object.keys(snapshot.colors).length > 0) {
|
|
@@ -966,8 +969,8 @@ class ThemeManager {
|
|
|
966
969
|
this.state.colorBlindMode = "none";
|
|
967
970
|
this.state.algorithm = "default";
|
|
968
971
|
this.state.componentThemeVersion += 1;
|
|
969
|
-
document.documentElement.classList.remove("dark");
|
|
970
972
|
const el = this.targetEl || document.documentElement;
|
|
973
|
+
el.classList.remove("dark");
|
|
971
974
|
const colorTypes = ["primary", "success", "warning", "danger", "info"];
|
|
972
975
|
const suffixes = ["", "light-1", "light-2", "light-3", "light-4", "light-5", "light-6", "light-7", "light-8", "light-9", "dark-2", "hover", "active", "disabled", "focus", "rgb"];
|
|
973
976
|
colorTypes.forEach(type => {
|
|
@@ -985,7 +988,7 @@ class ThemeManager {
|
|
|
985
988
|
/** 设置密度 */
|
|
986
989
|
setDensity(density) {
|
|
987
990
|
if (this.transitionEnabled) {
|
|
988
|
-
enableThemeTransition(this.transitionConfig.duration, this.transitionConfig.timing);
|
|
991
|
+
enableThemeTransition(this.transitionConfig.duration, this.transitionConfig.timing, this.targetEl);
|
|
989
992
|
}
|
|
990
993
|
this.currentDensity = density;
|
|
991
994
|
this.state.density = density;
|
|
@@ -1005,7 +1008,7 @@ class ThemeManager {
|
|
|
1005
1008
|
/** 设置色盲友好模式 */
|
|
1006
1009
|
setColorBlindMode(mode) {
|
|
1007
1010
|
if (this.transitionEnabled) {
|
|
1008
|
-
enableThemeTransition(this.transitionConfig.duration, this.transitionConfig.timing);
|
|
1011
|
+
enableThemeTransition(this.transitionConfig.duration, this.transitionConfig.timing, this.targetEl);
|
|
1009
1012
|
}
|
|
1010
1013
|
this.colorBlindMode = mode;
|
|
1011
1014
|
this.state.colorBlindMode = mode;
|
|
@@ -1110,7 +1113,7 @@ class ThemeManager {
|
|
|
1110
1113
|
duration: DEFAULT_TRANSITION_DURATION,
|
|
1111
1114
|
timing: DEFAULT_TRANSITION_TIMING
|
|
1112
1115
|
};
|
|
1113
|
-
enableThemeTransition(transitionConfig.duration, transitionConfig.timing);
|
|
1116
|
+
enableThemeTransition(transitionConfig.duration, transitionConfig.timing, this.targetEl);
|
|
1114
1117
|
}
|
|
1115
1118
|
this.pushHistory();
|
|
1116
1119
|
const snapshot = this.createTheme(config);
|
|
@@ -1195,6 +1198,7 @@ class ThemeManager {
|
|
|
1195
1198
|
/** 设置响应式变量 (根据断点自动切换) */
|
|
1196
1199
|
setResponsiveVar(name, values) {
|
|
1197
1200
|
if (typeof document === "undefined") return;
|
|
1201
|
+
this.responsiveVars.set(name, values);
|
|
1198
1202
|
let style = document.getElementById("yh-responsive-vars");
|
|
1199
1203
|
if (!style) {
|
|
1200
1204
|
style = document.createElement("style");
|
|
@@ -1202,23 +1206,25 @@ class ThemeManager {
|
|
|
1202
1206
|
document.head.appendChild(style);
|
|
1203
1207
|
}
|
|
1204
1208
|
let css = "";
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
if (bp
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1209
|
+
this.responsiveVars.forEach((vals, varName) => {
|
|
1210
|
+
const orderedBreakpoints = ["xs", "sm", "md", "lg", "xl", "xxl"];
|
|
1211
|
+
orderedBreakpoints.forEach(bp => {
|
|
1212
|
+
if (vals[bp]) {
|
|
1213
|
+
if (bp === "xs") {
|
|
1214
|
+
css += `
|
|
1215
|
+
:root { ${varName}: ${vals[bp]}; }
|
|
1216
|
+
`;
|
|
1217
|
+
} else {
|
|
1218
|
+
css += `
|
|
1219
|
+
@media (min-width: ${breakpoints[bp]}px) {
|
|
1220
|
+
:root { ${varName}: ${vals[bp]}; }
|
|
1221
|
+
}
|
|
1222
|
+
`;
|
|
1223
|
+
}
|
|
1218
1224
|
}
|
|
1219
|
-
}
|
|
1225
|
+
});
|
|
1220
1226
|
});
|
|
1221
|
-
style.textContent
|
|
1227
|
+
style.textContent = css;
|
|
1222
1228
|
}
|
|
1223
1229
|
/** 销毁 */
|
|
1224
1230
|
destroy() {
|
|
@@ -1230,6 +1236,7 @@ class ThemeManager {
|
|
|
1230
1236
|
if (style) {
|
|
1231
1237
|
style.remove();
|
|
1232
1238
|
}
|
|
1239
|
+
this.responsiveVars.clear();
|
|
1233
1240
|
}
|
|
1234
1241
|
}
|
|
1235
1242
|
exports.ThemeManager = ThemeManager;
|
package/dist/theme.d.ts
CHANGED
package/dist/theme.mjs
CHANGED
|
@@ -391,8 +391,9 @@ const colorBlindPalettes = {
|
|
|
391
391
|
const THEME_TRANSITION_CLASS = "yh-theme-transitioning";
|
|
392
392
|
const DEFAULT_TRANSITION_DURATION = 300;
|
|
393
393
|
const DEFAULT_TRANSITION_TIMING = "cubic-bezier(0.4, 0, 0.2, 1)";
|
|
394
|
-
function enableThemeTransition(duration = DEFAULT_TRANSITION_DURATION, timing = DEFAULT_TRANSITION_TIMING) {
|
|
394
|
+
function enableThemeTransition(duration = DEFAULT_TRANSITION_DURATION, timing = DEFAULT_TRANSITION_TIMING, el = null) {
|
|
395
395
|
if (typeof document === "undefined") return;
|
|
396
|
+
const target = el || document.documentElement;
|
|
396
397
|
const style = document.createElement("style");
|
|
397
398
|
style.id = "yh-theme-transition";
|
|
398
399
|
style.textContent = `
|
|
@@ -410,9 +411,9 @@ function enableThemeTransition(duration = DEFAULT_TRANSITION_DURATION, timing =
|
|
|
410
411
|
}
|
|
411
412
|
`;
|
|
412
413
|
document.head.appendChild(style);
|
|
413
|
-
|
|
414
|
+
target.classList.add(THEME_TRANSITION_CLASS);
|
|
414
415
|
setTimeout(() => {
|
|
415
|
-
|
|
416
|
+
target.classList.remove(THEME_TRANSITION_CLASS);
|
|
416
417
|
style.remove();
|
|
417
418
|
}, duration);
|
|
418
419
|
}
|
|
@@ -497,6 +498,7 @@ export class ThemeManager {
|
|
|
497
498
|
};
|
|
498
499
|
themeHistory = [];
|
|
499
500
|
maxHistoryLength = 10;
|
|
501
|
+
responsiveVars = /* @__PURE__ */ new Map();
|
|
500
502
|
// 响应式状态
|
|
501
503
|
state = reactive({
|
|
502
504
|
theme: "default",
|
|
@@ -598,11 +600,12 @@ export class ThemeManager {
|
|
|
598
600
|
setDarkMode(dark) {
|
|
599
601
|
this.isDark = dark;
|
|
600
602
|
this.state.dark = dark;
|
|
601
|
-
|
|
603
|
+
const el = this.targetEl || (typeof document !== "undefined" ? document.documentElement : null);
|
|
604
|
+
if (el) {
|
|
602
605
|
if (dark) {
|
|
603
|
-
|
|
606
|
+
el.classList.add("dark");
|
|
604
607
|
} else {
|
|
605
|
-
|
|
608
|
+
el.classList.remove("dark");
|
|
606
609
|
}
|
|
607
610
|
}
|
|
608
611
|
const currentColors = {
|
|
@@ -837,7 +840,11 @@ export class ThemeManager {
|
|
|
837
840
|
try {
|
|
838
841
|
const snapshot = JSON.parse(json);
|
|
839
842
|
if (this.transitionEnabled) {
|
|
840
|
-
enableThemeTransition(
|
|
843
|
+
enableThemeTransition(
|
|
844
|
+
this.transitionConfig.duration,
|
|
845
|
+
this.transitionConfig.timing,
|
|
846
|
+
this.targetEl
|
|
847
|
+
);
|
|
841
848
|
}
|
|
842
849
|
this.setPreset(snapshot.preset);
|
|
843
850
|
if (snapshot.colors && Object.keys(snapshot.colors).length > 0) {
|
|
@@ -884,8 +891,8 @@ export class ThemeManager {
|
|
|
884
891
|
this.state.colorBlindMode = "none";
|
|
885
892
|
this.state.algorithm = "default";
|
|
886
893
|
this.state.componentThemeVersion += 1;
|
|
887
|
-
document.documentElement.classList.remove("dark");
|
|
888
894
|
const el = this.targetEl || document.documentElement;
|
|
895
|
+
el.classList.remove("dark");
|
|
889
896
|
const colorTypes = ["primary", "success", "warning", "danger", "info"];
|
|
890
897
|
const suffixes = [
|
|
891
898
|
"",
|
|
@@ -920,7 +927,11 @@ export class ThemeManager {
|
|
|
920
927
|
/** 设置密度 */
|
|
921
928
|
setDensity(density) {
|
|
922
929
|
if (this.transitionEnabled) {
|
|
923
|
-
enableThemeTransition(
|
|
930
|
+
enableThemeTransition(
|
|
931
|
+
this.transitionConfig.duration,
|
|
932
|
+
this.transitionConfig.timing,
|
|
933
|
+
this.targetEl
|
|
934
|
+
);
|
|
924
935
|
}
|
|
925
936
|
this.currentDensity = density;
|
|
926
937
|
this.state.density = density;
|
|
@@ -940,7 +951,11 @@ export class ThemeManager {
|
|
|
940
951
|
/** 设置色盲友好模式 */
|
|
941
952
|
setColorBlindMode(mode) {
|
|
942
953
|
if (this.transitionEnabled) {
|
|
943
|
-
enableThemeTransition(
|
|
954
|
+
enableThemeTransition(
|
|
955
|
+
this.transitionConfig.duration,
|
|
956
|
+
this.transitionConfig.timing,
|
|
957
|
+
this.targetEl
|
|
958
|
+
);
|
|
944
959
|
}
|
|
945
960
|
this.colorBlindMode = mode;
|
|
946
961
|
this.state.colorBlindMode = mode;
|
|
@@ -1035,7 +1050,7 @@ export class ThemeManager {
|
|
|
1035
1050
|
applyFullConfig(config) {
|
|
1036
1051
|
if (this.transitionEnabled || config.transition) {
|
|
1037
1052
|
const transitionConfig = typeof config.transition === "object" ? config.transition : { duration: DEFAULT_TRANSITION_DURATION, timing: DEFAULT_TRANSITION_TIMING };
|
|
1038
|
-
enableThemeTransition(transitionConfig.duration, transitionConfig.timing);
|
|
1053
|
+
enableThemeTransition(transitionConfig.duration, transitionConfig.timing, this.targetEl);
|
|
1039
1054
|
}
|
|
1040
1055
|
this.pushHistory();
|
|
1041
1056
|
const snapshot = this.createTheme(config);
|
|
@@ -1118,6 +1133,7 @@ export class ThemeManager {
|
|
|
1118
1133
|
/** 设置响应式变量 (根据断点自动切换) */
|
|
1119
1134
|
setResponsiveVar(name, values) {
|
|
1120
1135
|
if (typeof document === "undefined") return;
|
|
1136
|
+
this.responsiveVars.set(name, values);
|
|
1121
1137
|
let style = document.getElementById("yh-responsive-vars");
|
|
1122
1138
|
if (!style) {
|
|
1123
1139
|
style = document.createElement("style");
|
|
@@ -1125,23 +1141,25 @@ export class ThemeManager {
|
|
|
1125
1141
|
document.head.appendChild(style);
|
|
1126
1142
|
}
|
|
1127
1143
|
let css = "";
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
if (bp
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1144
|
+
this.responsiveVars.forEach((vals, varName) => {
|
|
1145
|
+
const orderedBreakpoints = ["xs", "sm", "md", "lg", "xl", "xxl"];
|
|
1146
|
+
orderedBreakpoints.forEach((bp) => {
|
|
1147
|
+
if (vals[bp]) {
|
|
1148
|
+
if (bp === "xs") {
|
|
1149
|
+
css += `
|
|
1150
|
+
:root { ${varName}: ${vals[bp]}; }
|
|
1151
|
+
`;
|
|
1152
|
+
} else {
|
|
1153
|
+
css += `
|
|
1154
|
+
@media (min-width: ${breakpoints[bp]}px) {
|
|
1155
|
+
:root { ${varName}: ${vals[bp]}; }
|
|
1156
|
+
}
|
|
1157
|
+
`;
|
|
1158
|
+
}
|
|
1141
1159
|
}
|
|
1142
|
-
}
|
|
1160
|
+
});
|
|
1143
1161
|
});
|
|
1144
|
-
style.textContent
|
|
1162
|
+
style.textContent = css;
|
|
1145
1163
|
}
|
|
1146
1164
|
/** 销毁 */
|
|
1147
1165
|
destroy() {
|
|
@@ -1153,6 +1171,7 @@ export class ThemeManager {
|
|
|
1153
1171
|
if (style) {
|
|
1154
1172
|
style.remove();
|
|
1155
1173
|
}
|
|
1174
|
+
this.responsiveVars.clear();
|
|
1156
1175
|
}
|
|
1157
1176
|
}
|
|
1158
1177
|
let globalThemeManager = null;
|