@blocklet/theme 3.1.5 → 3.1.6
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/cjs/index.js +35 -7
- package/dist/es/index.js +36 -8
- package/dist/types/util.d.ts +3 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -44,21 +44,48 @@ function generateUtilityClasses(componentName, slots, globalStatePrefix = "Mui")
|
|
|
44
44
|
}
|
|
45
45
|
const alertClasses = generateUtilityClasses("MuiAlert", ["root", "action", "icon", "message", "filled", "colorSuccess", "colorInfo", "colorWarning", "colorError", "filledSuccess", "filledInfo", "filledWarning", "filledError", "outlined", "outlinedSuccess", "outlinedInfo", "outlinedWarning", "outlinedError", "standard", "standardSuccess", "standardInfo", "standardWarning", "standardError"]);
|
|
46
46
|
const BLOCKLET_THEME_PREFER_KEY = "blocklet_theme_prefer";
|
|
47
|
-
const
|
|
47
|
+
const arrayOverrides = (_, source) => source;
|
|
48
|
+
const mergeThemeOptions = (x, y = {}) => {
|
|
48
49
|
return deepmerge(x, y, {
|
|
49
50
|
// 采用替换策略合并数组
|
|
50
|
-
arrayMerge:
|
|
51
|
+
arrayMerge: arrayOverrides,
|
|
52
|
+
// 自定义合并策略,特别处理 styleOverrides 字段
|
|
53
|
+
customMerge: (key) => {
|
|
54
|
+
if (key === "styleOverrides") {
|
|
55
|
+
return (target, source) => {
|
|
56
|
+
if (!target || !source) {
|
|
57
|
+
return source || target;
|
|
58
|
+
}
|
|
59
|
+
const result = { ...target };
|
|
60
|
+
for (const [sKey, sVal] of Object.entries(source)) {
|
|
61
|
+
const tVal = target[sKey];
|
|
62
|
+
if (tVal && sVal && (typeof tVal === "function" || typeof sVal === "function")) {
|
|
63
|
+
result[sKey] = (...args) => {
|
|
64
|
+
const tResult = typeof tVal === "function" ? tVal(...args) : tVal;
|
|
65
|
+
const sResult = typeof sVal === "function" ? sVal(...args) : sVal;
|
|
66
|
+
return deepmerge(tResult, sResult, { arrayMerge: arrayOverrides });
|
|
67
|
+
};
|
|
68
|
+
} else if (sVal) {
|
|
69
|
+
result[sKey] = tVal ? deepmerge(tVal, sVal, { arrayMerge: arrayOverrides }) : sVal;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return void 0;
|
|
76
|
+
}
|
|
51
77
|
});
|
|
52
78
|
};
|
|
79
|
+
const merge = mergeThemeOptions;
|
|
53
80
|
function isValidThemeMode(mode) {
|
|
54
81
|
return mode === "light" || mode === "dark";
|
|
55
82
|
}
|
|
56
83
|
function getBlockletThemeOptions(mode = "light", meta) {
|
|
57
84
|
const { common = {}, light = {}, dark = {} } = meta || window.blocklet?.theme || {};
|
|
58
85
|
if (mode === "dark") {
|
|
59
|
-
return
|
|
86
|
+
return mergeThemeOptions(common, dark);
|
|
60
87
|
}
|
|
61
|
-
return
|
|
88
|
+
return mergeThemeOptions(common, light);
|
|
62
89
|
}
|
|
63
90
|
function getDefaultThemePrefer(meta) {
|
|
64
91
|
const blockletInfo = Object.assign({}, window.blocklet, meta);
|
|
@@ -503,7 +530,7 @@ const BLOCKLET_THEME_LIGHT = {
|
|
|
503
530
|
}
|
|
504
531
|
}
|
|
505
532
|
};
|
|
506
|
-
const BLOCKLET_THEME_DARK =
|
|
533
|
+
const BLOCKLET_THEME_DARK = mergeThemeOptions(BLOCKLET_THEME_LIGHT, {
|
|
507
534
|
palette: {
|
|
508
535
|
mode: "dark",
|
|
509
536
|
common: {
|
|
@@ -698,10 +725,10 @@ const paletteDark = {
|
|
|
698
725
|
selected: "rgba(255, 255, 255, 0.16)"
|
|
699
726
|
}
|
|
700
727
|
};
|
|
701
|
-
const DID_CONNECT_THEME_LIGHT =
|
|
728
|
+
const DID_CONNECT_THEME_LIGHT = mergeThemeOptions(BLOCKLET_THEME_LIGHT, {
|
|
702
729
|
palette: paletteLight
|
|
703
730
|
});
|
|
704
|
-
const DID_CONNECT_THEME_DARK =
|
|
731
|
+
const DID_CONNECT_THEME_DARK = mergeThemeOptions(BLOCKLET_THEME_DARK, {
|
|
705
732
|
palette: paletteDark
|
|
706
733
|
});
|
|
707
734
|
exports.BLOCKLET_THEME_DARK = BLOCKLET_THEME_DARK;
|
|
@@ -716,3 +743,4 @@ exports.getBlockletThemeOptions = getBlockletThemeOptions;
|
|
|
716
743
|
exports.getDefaultThemePrefer = getDefaultThemePrefer;
|
|
717
744
|
exports.isValidThemeMode = isValidThemeMode;
|
|
718
745
|
exports.merge = merge;
|
|
746
|
+
exports.mergeThemeOptions = mergeThemeOptions;
|
package/dist/es/index.js
CHANGED
|
@@ -42,21 +42,48 @@ function generateUtilityClasses(componentName, slots, globalStatePrefix = "Mui")
|
|
|
42
42
|
}
|
|
43
43
|
const alertClasses = generateUtilityClasses("MuiAlert", ["root", "action", "icon", "message", "filled", "colorSuccess", "colorInfo", "colorWarning", "colorError", "filledSuccess", "filledInfo", "filledWarning", "filledError", "outlined", "outlinedSuccess", "outlinedInfo", "outlinedWarning", "outlinedError", "standard", "standardSuccess", "standardInfo", "standardWarning", "standardError"]);
|
|
44
44
|
const BLOCKLET_THEME_PREFER_KEY = "blocklet_theme_prefer";
|
|
45
|
-
const
|
|
45
|
+
const arrayOverrides = (_, source) => source;
|
|
46
|
+
const mergeThemeOptions = (x, y = {}) => {
|
|
46
47
|
return deepmerge(x, y, {
|
|
47
48
|
// 采用替换策略合并数组
|
|
48
|
-
arrayMerge:
|
|
49
|
+
arrayMerge: arrayOverrides,
|
|
50
|
+
// 自定义合并策略,特别处理 styleOverrides 字段
|
|
51
|
+
customMerge: (key) => {
|
|
52
|
+
if (key === "styleOverrides") {
|
|
53
|
+
return (target, source) => {
|
|
54
|
+
if (!target || !source) {
|
|
55
|
+
return source || target;
|
|
56
|
+
}
|
|
57
|
+
const result = { ...target };
|
|
58
|
+
for (const [sKey, sVal] of Object.entries(source)) {
|
|
59
|
+
const tVal = target[sKey];
|
|
60
|
+
if (tVal && sVal && (typeof tVal === "function" || typeof sVal === "function")) {
|
|
61
|
+
result[sKey] = (...args) => {
|
|
62
|
+
const tResult = typeof tVal === "function" ? tVal(...args) : tVal;
|
|
63
|
+
const sResult = typeof sVal === "function" ? sVal(...args) : sVal;
|
|
64
|
+
return deepmerge(tResult, sResult, { arrayMerge: arrayOverrides });
|
|
65
|
+
};
|
|
66
|
+
} else if (sVal) {
|
|
67
|
+
result[sKey] = tVal ? deepmerge(tVal, sVal, { arrayMerge: arrayOverrides }) : sVal;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
49
75
|
});
|
|
50
76
|
};
|
|
77
|
+
const merge = mergeThemeOptions;
|
|
51
78
|
function isValidThemeMode(mode) {
|
|
52
79
|
return mode === "light" || mode === "dark";
|
|
53
80
|
}
|
|
54
81
|
function getBlockletThemeOptions(mode = "light", meta) {
|
|
55
82
|
const { common = {}, light = {}, dark = {} } = meta || window.blocklet?.theme || {};
|
|
56
83
|
if (mode === "dark") {
|
|
57
|
-
return
|
|
84
|
+
return mergeThemeOptions(common, dark);
|
|
58
85
|
}
|
|
59
|
-
return
|
|
86
|
+
return mergeThemeOptions(common, light);
|
|
60
87
|
}
|
|
61
88
|
function getDefaultThemePrefer(meta) {
|
|
62
89
|
const blockletInfo = Object.assign({}, window.blocklet, meta);
|
|
@@ -501,7 +528,7 @@ const BLOCKLET_THEME_LIGHT = {
|
|
|
501
528
|
}
|
|
502
529
|
}
|
|
503
530
|
};
|
|
504
|
-
const BLOCKLET_THEME_DARK =
|
|
531
|
+
const BLOCKLET_THEME_DARK = mergeThemeOptions(BLOCKLET_THEME_LIGHT, {
|
|
505
532
|
palette: {
|
|
506
533
|
mode: "dark",
|
|
507
534
|
common: {
|
|
@@ -696,10 +723,10 @@ const paletteDark = {
|
|
|
696
723
|
selected: "rgba(255, 255, 255, 0.16)"
|
|
697
724
|
}
|
|
698
725
|
};
|
|
699
|
-
const DID_CONNECT_THEME_LIGHT =
|
|
726
|
+
const DID_CONNECT_THEME_LIGHT = mergeThemeOptions(BLOCKLET_THEME_LIGHT, {
|
|
700
727
|
palette: paletteLight
|
|
701
728
|
});
|
|
702
|
-
const DID_CONNECT_THEME_DARK =
|
|
729
|
+
const DID_CONNECT_THEME_DARK = mergeThemeOptions(BLOCKLET_THEME_DARK, {
|
|
703
730
|
palette: paletteDark
|
|
704
731
|
});
|
|
705
732
|
export {
|
|
@@ -714,5 +741,6 @@ export {
|
|
|
714
741
|
getBlockletThemeOptions,
|
|
715
742
|
getDefaultThemePrefer,
|
|
716
743
|
isValidThemeMode,
|
|
717
|
-
merge
|
|
744
|
+
merge,
|
|
745
|
+
mergeThemeOptions
|
|
718
746
|
};
|
package/dist/types/util.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { PaletteMode } from '@mui/material';
|
|
2
2
|
import { BlockletThemeMeta, ThemeOptions } from './types';
|
|
3
3
|
export declare const BLOCKLET_THEME_PREFER_KEY = "blocklet_theme_prefer";
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const mergeThemeOptions: (x: ThemeOptions, y?: ThemeOptions) => ThemeOptions;
|
|
5
|
+
/** @deprecated please use mergeThemeOptions instead */
|
|
6
|
+
export declare const merge: (x: ThemeOptions, y?: ThemeOptions) => ThemeOptions;
|
|
5
7
|
export declare function isValidThemeMode(mode: any): mode is PaletteMode;
|
|
6
8
|
export declare function getBlockletThemeOptions(mode?: PaletteMode, meta?: BlockletThemeMeta): ThemeOptions;
|
|
7
9
|
export declare function getDefaultThemePrefer(meta?: {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "3.1.
|
|
6
|
+
"version": "3.1.6",
|
|
7
7
|
"description": "A preset MUI-based theme configuration designed for use with Blocklet.",
|
|
8
8
|
"main": "dist/cjs/index.js",
|
|
9
9
|
"module": "dist/es/index.js",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"ts-jest": "^29.4.0",
|
|
45
45
|
"typescript": "~5.5.4"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "d3267421c4d35038b226d34edc0e7bc943c5c926"
|
|
48
48
|
}
|