@yh-ui/theme 1.0.1 → 1.0.5
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 +13 -2
- package/dist/theme.d.ts +4 -0
- package/dist/theme.mjs +13 -2
- package/package.json +1 -1
package/dist/theme.cjs
CHANGED
|
@@ -563,7 +563,9 @@ class ThemeManager {
|
|
|
563
563
|
colors: {},
|
|
564
564
|
breakpoint: "md",
|
|
565
565
|
density: "comfortable",
|
|
566
|
-
colorBlindMode: "none"
|
|
566
|
+
colorBlindMode: "none",
|
|
567
|
+
algorithm: "default",
|
|
568
|
+
componentThemeVersion: 0
|
|
567
569
|
});
|
|
568
570
|
constructor(options) {
|
|
569
571
|
this.initTheme(options);
|
|
@@ -648,6 +650,7 @@ class ThemeManager {
|
|
|
648
650
|
/** 设置颜色算法 */
|
|
649
651
|
setAlgorithm(algorithm) {
|
|
650
652
|
this.algorithm = algorithm;
|
|
653
|
+
this.state.algorithm = algorithm;
|
|
651
654
|
const currentColors = {
|
|
652
655
|
...presetThemes[this.currentTheme],
|
|
653
656
|
...this.customColors
|
|
@@ -750,10 +753,13 @@ class ThemeManager {
|
|
|
750
753
|
/** 获取当前主题的 CSS 变量对象 */
|
|
751
754
|
getThemeStyles(colors = {}) {
|
|
752
755
|
const styles = {};
|
|
753
|
-
const themeColors = {
|
|
756
|
+
const themeColors = this.colorBlindMode === "none" ? {
|
|
754
757
|
...presetThemes[this.currentTheme],
|
|
755
758
|
...this.customColors,
|
|
756
759
|
...colors
|
|
760
|
+
} : {
|
|
761
|
+
...colorBlindPalettes[this.colorBlindMode],
|
|
762
|
+
...colors
|
|
757
763
|
};
|
|
758
764
|
const colorTypes = [{
|
|
759
765
|
key: "primary",
|
|
@@ -898,6 +904,7 @@ class ThemeManager {
|
|
|
898
904
|
this.state.dark = this.isDark;
|
|
899
905
|
this.state.colors = this.customColors;
|
|
900
906
|
this.state.density = this.currentDensity;
|
|
907
|
+
this.state.algorithm = this.algorithm;
|
|
901
908
|
return true;
|
|
902
909
|
} catch (e) {
|
|
903
910
|
console.warn("[YH-UI Theme] Failed to restore theme:", e);
|
|
@@ -970,6 +977,8 @@ class ThemeManager {
|
|
|
970
977
|
this.state.colors = {};
|
|
971
978
|
this.state.density = "comfortable";
|
|
972
979
|
this.state.colorBlindMode = "none";
|
|
980
|
+
this.state.algorithm = "default";
|
|
981
|
+
this.state.componentThemeVersion += 1;
|
|
973
982
|
document.documentElement.classList.remove("dark");
|
|
974
983
|
const el = this.targetEl || document.documentElement;
|
|
975
984
|
const colorTypes = ["primary", "success", "warning", "danger", "info"];
|
|
@@ -1036,6 +1045,7 @@ class ThemeManager {
|
|
|
1036
1045
|
...this.componentOverrides[componentName],
|
|
1037
1046
|
...overrides
|
|
1038
1047
|
};
|
|
1048
|
+
this.state.componentThemeVersion += 1;
|
|
1039
1049
|
const el = this.targetEl || (typeof document !== "undefined" ? document.documentElement : null);
|
|
1040
1050
|
if (!el) return;
|
|
1041
1051
|
Object.entries(overrides).forEach(([name, value]) => {
|
|
@@ -1056,6 +1066,7 @@ class ThemeManager {
|
|
|
1056
1066
|
removeCssVar(`--yh-${componentName}-${name}`, el);
|
|
1057
1067
|
});
|
|
1058
1068
|
delete this.componentOverrides[componentName];
|
|
1069
|
+
this.state.componentThemeVersion += 1;
|
|
1059
1070
|
}
|
|
1060
1071
|
// ==================== 主题切换动画 ====================
|
|
1061
1072
|
/** 启用主题切换动画 */
|
package/dist/theme.d.ts
CHANGED
|
@@ -161,6 +161,8 @@ export declare class ThemeManager {
|
|
|
161
161
|
breakpoint: Breakpoint;
|
|
162
162
|
density: ThemeDensity;
|
|
163
163
|
colorBlindMode: ColorBlindMode;
|
|
164
|
+
algorithm: ColorAlgorithm;
|
|
165
|
+
componentThemeVersion: number;
|
|
164
166
|
};
|
|
165
167
|
constructor(options?: ThemeOptions);
|
|
166
168
|
/** 初始化主题 */
|
|
@@ -299,6 +301,8 @@ export declare function useThemeVars(): {
|
|
|
299
301
|
breakpoint: import("vue").Ref<Breakpoint, Breakpoint>;
|
|
300
302
|
density: import("vue").Ref<ThemeDensity, ThemeDensity>;
|
|
301
303
|
colorBlindMode: import("vue").Ref<ColorBlindMode, ColorBlindMode>;
|
|
304
|
+
algorithm: import("vue").Ref<ColorAlgorithm, ColorAlgorithm>;
|
|
305
|
+
componentThemeVersion: import("vue").Ref<number, number>;
|
|
302
306
|
};
|
|
303
307
|
/** 检查颜色对比度是否符合 WCAG 标准 */
|
|
304
308
|
export declare function checkContrast(foreground: string, background: string, level?: 'AA' | 'AAA'): boolean;
|
package/dist/theme.mjs
CHANGED
|
@@ -504,7 +504,9 @@ export class ThemeManager {
|
|
|
504
504
|
colors: {},
|
|
505
505
|
breakpoint: "md",
|
|
506
506
|
density: "comfortable",
|
|
507
|
-
colorBlindMode: "none"
|
|
507
|
+
colorBlindMode: "none",
|
|
508
|
+
algorithm: "default",
|
|
509
|
+
componentThemeVersion: 0
|
|
508
510
|
});
|
|
509
511
|
constructor(options) {
|
|
510
512
|
this.initTheme(options);
|
|
@@ -578,6 +580,7 @@ export class ThemeManager {
|
|
|
578
580
|
/** 设置颜色算法 */
|
|
579
581
|
setAlgorithm(algorithm) {
|
|
580
582
|
this.algorithm = algorithm;
|
|
583
|
+
this.state.algorithm = algorithm;
|
|
581
584
|
const currentColors = {
|
|
582
585
|
...presetThemes[this.currentTheme],
|
|
583
586
|
...this.customColors
|
|
@@ -680,10 +683,13 @@ export class ThemeManager {
|
|
|
680
683
|
/** 获取当前主题的 CSS 变量对象 */
|
|
681
684
|
getThemeStyles(colors = {}) {
|
|
682
685
|
const styles = {};
|
|
683
|
-
const themeColors = {
|
|
686
|
+
const themeColors = this.colorBlindMode === "none" ? {
|
|
684
687
|
...presetThemes[this.currentTheme],
|
|
685
688
|
...this.customColors,
|
|
686
689
|
...colors
|
|
690
|
+
} : {
|
|
691
|
+
...colorBlindPalettes[this.colorBlindMode],
|
|
692
|
+
...colors
|
|
687
693
|
};
|
|
688
694
|
const colorTypes = [
|
|
689
695
|
{ key: "primary", cssVar: "primary" },
|
|
@@ -816,6 +822,7 @@ export class ThemeManager {
|
|
|
816
822
|
this.state.dark = this.isDark;
|
|
817
823
|
this.state.colors = this.customColors;
|
|
818
824
|
this.state.density = this.currentDensity;
|
|
825
|
+
this.state.algorithm = this.algorithm;
|
|
819
826
|
return true;
|
|
820
827
|
} catch (e) {
|
|
821
828
|
console.warn("[YH-UI Theme] Failed to restore theme:", e);
|
|
@@ -888,6 +895,8 @@ export class ThemeManager {
|
|
|
888
895
|
this.state.colors = {};
|
|
889
896
|
this.state.density = "comfortable";
|
|
890
897
|
this.state.colorBlindMode = "none";
|
|
898
|
+
this.state.algorithm = "default";
|
|
899
|
+
this.state.componentThemeVersion += 1;
|
|
891
900
|
document.documentElement.classList.remove("dark");
|
|
892
901
|
const el = this.targetEl || document.documentElement;
|
|
893
902
|
const colorTypes = ["primary", "success", "warning", "danger", "info"];
|
|
@@ -971,6 +980,7 @@ export class ThemeManager {
|
|
|
971
980
|
...this.componentOverrides[componentName],
|
|
972
981
|
...overrides
|
|
973
982
|
};
|
|
983
|
+
this.state.componentThemeVersion += 1;
|
|
974
984
|
const el = this.targetEl || (typeof document !== "undefined" ? document.documentElement : null);
|
|
975
985
|
if (!el) return;
|
|
976
986
|
Object.entries(overrides).forEach(([name, value]) => {
|
|
@@ -991,6 +1001,7 @@ export class ThemeManager {
|
|
|
991
1001
|
removeCssVar(`--yh-${componentName}-${name}`, el);
|
|
992
1002
|
});
|
|
993
1003
|
delete this.componentOverrides[componentName];
|
|
1004
|
+
this.state.componentThemeVersion += 1;
|
|
994
1005
|
}
|
|
995
1006
|
// ==================== 主题切换动画 ====================
|
|
996
1007
|
/** 启用主题切换动画 */
|