@blocklet/theme 3.1.19 → 3.1.21
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 +47 -9
- package/dist/es/index.js +47 -9
- package/dist/types/util.d.ts +1 -0
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -44,12 +44,37 @@ 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
|
+
function isPlainObject(value) {
|
|
48
|
+
if (Object.prototype.toString.call(value) !== "[object Object]") {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const prototype = Object.getPrototypeOf(value);
|
|
52
|
+
return prototype === null || prototype === Object.prototype;
|
|
53
|
+
}
|
|
47
54
|
const arrayOverrides = (_, source) => source;
|
|
55
|
+
const wrapStyleMerge = (target, source) => {
|
|
56
|
+
if (target && source && (typeof target === "function" || typeof source === "function")) {
|
|
57
|
+
return (...args) => {
|
|
58
|
+
const tResult = typeof target === "function" ? target(...args) : target;
|
|
59
|
+
const sResult = typeof source === "function" ? source(...args) : source;
|
|
60
|
+
return deepmerge(tResult, sResult, { arrayMerge: arrayOverrides });
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (source) {
|
|
64
|
+
return target ? deepmerge(target, source, { arrayMerge: arrayOverrides }) : source;
|
|
65
|
+
}
|
|
66
|
+
return target;
|
|
67
|
+
};
|
|
48
68
|
const mergeThemeOptions = (x, y = {}) => {
|
|
69
|
+
const isMergeableObject = (val) => {
|
|
70
|
+
return isPlainObject(val) || // 让顶层的函数式 typography 被 customMerge 处理
|
|
71
|
+
typeof val === "function" && val === y.typography;
|
|
72
|
+
};
|
|
49
73
|
return deepmerge(x, y, {
|
|
74
|
+
isMergeableObject,
|
|
50
75
|
// 采用替换策略合并数组
|
|
51
76
|
arrayMerge: arrayOverrides,
|
|
52
|
-
//
|
|
77
|
+
// 自定义合并策略
|
|
53
78
|
customMerge: (key) => {
|
|
54
79
|
if (key === "styleOverrides") {
|
|
55
80
|
return (target, source) => {
|
|
@@ -59,24 +84,36 @@ const mergeThemeOptions = (x, y = {}) => {
|
|
|
59
84
|
const result = { ...target };
|
|
60
85
|
for (const [sKey, sVal] of Object.entries(source)) {
|
|
61
86
|
const tVal = target[sKey];
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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;
|
|
87
|
+
const merged = wrapStyleMerge(tVal, sVal);
|
|
88
|
+
if (merged !== tVal) {
|
|
89
|
+
result[sKey] = merged;
|
|
70
90
|
}
|
|
71
91
|
}
|
|
72
92
|
return result;
|
|
73
93
|
};
|
|
74
94
|
}
|
|
95
|
+
if (key === "typography") {
|
|
96
|
+
return wrapStyleMerge;
|
|
97
|
+
}
|
|
75
98
|
return void 0;
|
|
76
99
|
}
|
|
77
100
|
});
|
|
78
101
|
};
|
|
79
102
|
const merge = mergeThemeOptions;
|
|
103
|
+
function mergeAllThemeOptions(objects) {
|
|
104
|
+
if (!Array.isArray(objects)) {
|
|
105
|
+
throw new Error("First argument should be an array");
|
|
106
|
+
}
|
|
107
|
+
if (objects.length === 0) {
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
if (objects.length === 1) {
|
|
111
|
+
return objects[0];
|
|
112
|
+
}
|
|
113
|
+
return objects.reduce((acc, obj) => {
|
|
114
|
+
return mergeThemeOptions(acc, obj);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
80
117
|
function isValidThemeMode(mode) {
|
|
81
118
|
return mode === "light" || mode === "dark";
|
|
82
119
|
}
|
|
@@ -743,4 +780,5 @@ exports.getBlockletThemeOptions = getBlockletThemeOptions;
|
|
|
743
780
|
exports.getDefaultThemePrefer = getDefaultThemePrefer;
|
|
744
781
|
exports.isValidThemeMode = isValidThemeMode;
|
|
745
782
|
exports.merge = merge;
|
|
783
|
+
exports.mergeAllThemeOptions = mergeAllThemeOptions;
|
|
746
784
|
exports.mergeThemeOptions = mergeThemeOptions;
|
package/dist/es/index.js
CHANGED
|
@@ -42,12 +42,37 @@ 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
|
+
function isPlainObject(value) {
|
|
46
|
+
if (Object.prototype.toString.call(value) !== "[object Object]") {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const prototype = Object.getPrototypeOf(value);
|
|
50
|
+
return prototype === null || prototype === Object.prototype;
|
|
51
|
+
}
|
|
45
52
|
const arrayOverrides = (_, source) => source;
|
|
53
|
+
const wrapStyleMerge = (target, source) => {
|
|
54
|
+
if (target && source && (typeof target === "function" || typeof source === "function")) {
|
|
55
|
+
return (...args) => {
|
|
56
|
+
const tResult = typeof target === "function" ? target(...args) : target;
|
|
57
|
+
const sResult = typeof source === "function" ? source(...args) : source;
|
|
58
|
+
return deepmerge(tResult, sResult, { arrayMerge: arrayOverrides });
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (source) {
|
|
62
|
+
return target ? deepmerge(target, source, { arrayMerge: arrayOverrides }) : source;
|
|
63
|
+
}
|
|
64
|
+
return target;
|
|
65
|
+
};
|
|
46
66
|
const mergeThemeOptions = (x, y = {}) => {
|
|
67
|
+
const isMergeableObject = (val) => {
|
|
68
|
+
return isPlainObject(val) || // 让顶层的函数式 typography 被 customMerge 处理
|
|
69
|
+
typeof val === "function" && val === y.typography;
|
|
70
|
+
};
|
|
47
71
|
return deepmerge(x, y, {
|
|
72
|
+
isMergeableObject,
|
|
48
73
|
// 采用替换策略合并数组
|
|
49
74
|
arrayMerge: arrayOverrides,
|
|
50
|
-
//
|
|
75
|
+
// 自定义合并策略
|
|
51
76
|
customMerge: (key) => {
|
|
52
77
|
if (key === "styleOverrides") {
|
|
53
78
|
return (target, source) => {
|
|
@@ -57,24 +82,36 @@ const mergeThemeOptions = (x, y = {}) => {
|
|
|
57
82
|
const result = { ...target };
|
|
58
83
|
for (const [sKey, sVal] of Object.entries(source)) {
|
|
59
84
|
const tVal = target[sKey];
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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;
|
|
85
|
+
const merged = wrapStyleMerge(tVal, sVal);
|
|
86
|
+
if (merged !== tVal) {
|
|
87
|
+
result[sKey] = merged;
|
|
68
88
|
}
|
|
69
89
|
}
|
|
70
90
|
return result;
|
|
71
91
|
};
|
|
72
92
|
}
|
|
93
|
+
if (key === "typography") {
|
|
94
|
+
return wrapStyleMerge;
|
|
95
|
+
}
|
|
73
96
|
return void 0;
|
|
74
97
|
}
|
|
75
98
|
});
|
|
76
99
|
};
|
|
77
100
|
const merge = mergeThemeOptions;
|
|
101
|
+
function mergeAllThemeOptions(objects) {
|
|
102
|
+
if (!Array.isArray(objects)) {
|
|
103
|
+
throw new Error("First argument should be an array");
|
|
104
|
+
}
|
|
105
|
+
if (objects.length === 0) {
|
|
106
|
+
return {};
|
|
107
|
+
}
|
|
108
|
+
if (objects.length === 1) {
|
|
109
|
+
return objects[0];
|
|
110
|
+
}
|
|
111
|
+
return objects.reduce((acc, obj) => {
|
|
112
|
+
return mergeThemeOptions(acc, obj);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
78
115
|
function isValidThemeMode(mode) {
|
|
79
116
|
return mode === "light" || mode === "dark";
|
|
80
117
|
}
|
|
@@ -742,5 +779,6 @@ export {
|
|
|
742
779
|
getDefaultThemePrefer,
|
|
743
780
|
isValidThemeMode,
|
|
744
781
|
merge,
|
|
782
|
+
mergeAllThemeOptions,
|
|
745
783
|
mergeThemeOptions
|
|
746
784
|
};
|
package/dist/types/util.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const BLOCKLET_THEME_PREFER_KEY = "blocklet_theme_prefer";
|
|
|
4
4
|
export declare const mergeThemeOptions: (x: ThemeOptions, y?: ThemeOptions) => ThemeOptions;
|
|
5
5
|
/** @deprecated please use mergeThemeOptions instead */
|
|
6
6
|
export declare const merge: (x: ThemeOptions, y?: ThemeOptions) => ThemeOptions;
|
|
7
|
+
export declare function mergeAllThemeOptions(objects: ThemeOptions[]): ThemeOptions;
|
|
7
8
|
export declare function isValidThemeMode(mode: any): mode is PaletteMode;
|
|
8
9
|
export declare function getBlockletThemeOptions(mode?: PaletteMode, meta?: BlockletThemeMeta): ThemeOptions;
|
|
9
10
|
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.21",
|
|
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": "dedb6d83f569480ca7840679ef32fb863d4042e1"
|
|
48
48
|
}
|