@blocklet/theme 2.13.64 → 2.13.65
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 +17 -18
- package/dist/es/index.js +16 -18
- package/dist/types/index.d.ts +2 -0
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -143,6 +143,7 @@ __export(src_exports, {
|
|
|
143
143
|
DID_CONNECT_THEME_LIGHT: () => DID_CONNECT_THEME_LIGHT,
|
|
144
144
|
buildThemeScript: () => buildThemeScript,
|
|
145
145
|
buildThemeStyles: () => buildThemeStyles,
|
|
146
|
+
getBlockletThemeOptions: () => getBlockletThemeOptions,
|
|
146
147
|
getDefaultThemePrefer: () => getDefaultThemePrefer,
|
|
147
148
|
isValidThemeMode: () => isValidThemeMode,
|
|
148
149
|
merge: () => merge
|
|
@@ -269,22 +270,31 @@ var merge = (x, y) => {
|
|
|
269
270
|
function isValidThemeMode(mode) {
|
|
270
271
|
return mode === "light" || mode === "dark";
|
|
271
272
|
}
|
|
273
|
+
function getBlockletThemeOptions(mode = "light") {
|
|
274
|
+
const { common = {}, light = {}, dark = {} } = window.blocklet?.theme || {};
|
|
275
|
+
if (mode === "dark") {
|
|
276
|
+
return merge(common, dark);
|
|
277
|
+
}
|
|
278
|
+
return merge(common, light);
|
|
279
|
+
}
|
|
272
280
|
function getDefaultThemePrefer(meta) {
|
|
281
|
+
const blockletInfo = Object.assign({}, window.blocklet, meta);
|
|
282
|
+
const preferKey = blockletInfo.theme?.preferKey ?? BLOCKLET_THEME_PREFER_KEY;
|
|
273
283
|
const urlParams = new URLSearchParams(window.location.search);
|
|
274
284
|
const urlPrefer = urlParams.get("theme");
|
|
275
285
|
if (isValidThemeMode(urlPrefer)) {
|
|
276
286
|
return urlPrefer;
|
|
277
287
|
}
|
|
278
|
-
const sessionPrefer = sessionStorage.getItem(
|
|
288
|
+
const sessionPrefer = sessionStorage.getItem(preferKey);
|
|
279
289
|
if (isValidThemeMode(sessionPrefer)) {
|
|
280
290
|
return sessionPrefer;
|
|
281
291
|
}
|
|
282
|
-
const prefer =
|
|
292
|
+
const prefer = blockletInfo.theme?.prefer;
|
|
283
293
|
if (prefer === "light" || prefer === "dark") {
|
|
284
294
|
return prefer;
|
|
285
295
|
}
|
|
286
296
|
if (prefer === "system") {
|
|
287
|
-
const localPrefer = localStorage.getItem(
|
|
297
|
+
const localPrefer = localStorage.getItem(preferKey);
|
|
288
298
|
if (isValidThemeMode(localPrefer)) {
|
|
289
299
|
return localPrefer;
|
|
290
300
|
}
|
|
@@ -318,11 +328,10 @@ var buildThemeScript = (theme) => {
|
|
|
318
328
|
<script id="blocklet-theme-script">
|
|
319
329
|
(function() {
|
|
320
330
|
try {
|
|
321
|
-
const BLOCKLET_THEME_PREFER_KEY = '${BLOCKLET_THEME_PREFER_KEY}';
|
|
322
331
|
${isValidThemeMode.toString()}
|
|
323
332
|
${getDefaultThemePrefer.toString()}
|
|
324
333
|
|
|
325
|
-
const prefer = getDefaultThemePrefer(${JSON.stringify({ theme: { prefer: theme?.prefer ?? "light" } })});
|
|
334
|
+
const prefer = getDefaultThemePrefer(${JSON.stringify({ theme: { prefer: theme?.prefer ?? "light", preferKey: BLOCKLET_THEME_PREFER_KEY } })});
|
|
326
335
|
|
|
327
336
|
if(prefer === 'dark') {
|
|
328
337
|
document.documentElement.setAttribute('data-theme', 'dark');
|
|
@@ -784,21 +793,10 @@ var BLOCKLET_THEME_DARK = merge(BLOCKLET_THEME_LIGHT, {
|
|
|
784
793
|
}
|
|
785
794
|
}
|
|
786
795
|
},
|
|
787
|
-
MuiTooltip: {
|
|
788
|
-
styleOverrides: {
|
|
789
|
-
tooltip: ({ theme }) => ({
|
|
790
|
-
backgroundColor: theme.palette.grey[500],
|
|
791
|
-
color: theme.palette.text.contrast
|
|
792
|
-
}),
|
|
793
|
-
arrow: ({ theme }) => ({
|
|
794
|
-
color: theme.palette.grey[500]
|
|
795
|
-
})
|
|
796
|
-
}
|
|
797
|
-
},
|
|
798
796
|
MuiPaper: {
|
|
799
797
|
styleOverrides: {
|
|
800
|
-
// 暗色模式下,Paper 使用内阴影营造边框效果
|
|
801
|
-
|
|
798
|
+
// 暗色模式下,Elevation Paper 使用内阴影营造边框效果
|
|
799
|
+
elevation: ({ theme }) => ({
|
|
802
800
|
boxShadow: `inset 0 0 0 1px ${theme.palette.action.hover}`
|
|
803
801
|
})
|
|
804
802
|
}
|
|
@@ -892,6 +890,7 @@ var DID_CONNECT_THEME_DARK = merge(BLOCKLET_THEME_DARK, {
|
|
|
892
890
|
DID_CONNECT_THEME_LIGHT,
|
|
893
891
|
buildThemeScript,
|
|
894
892
|
buildThemeStyles,
|
|
893
|
+
getBlockletThemeOptions,
|
|
895
894
|
getDefaultThemePrefer,
|
|
896
895
|
isValidThemeMode,
|
|
897
896
|
merge
|
package/dist/es/index.js
CHANGED
|
@@ -247,22 +247,31 @@ var merge = (x, y) => {
|
|
|
247
247
|
function isValidThemeMode(mode) {
|
|
248
248
|
return mode === "light" || mode === "dark";
|
|
249
249
|
}
|
|
250
|
+
function getBlockletThemeOptions(mode = "light") {
|
|
251
|
+
const { common = {}, light = {}, dark = {} } = window.blocklet?.theme || {};
|
|
252
|
+
if (mode === "dark") {
|
|
253
|
+
return merge(common, dark);
|
|
254
|
+
}
|
|
255
|
+
return merge(common, light);
|
|
256
|
+
}
|
|
250
257
|
function getDefaultThemePrefer(meta) {
|
|
258
|
+
const blockletInfo = Object.assign({}, window.blocklet, meta);
|
|
259
|
+
const preferKey = blockletInfo.theme?.preferKey ?? BLOCKLET_THEME_PREFER_KEY;
|
|
251
260
|
const urlParams = new URLSearchParams(window.location.search);
|
|
252
261
|
const urlPrefer = urlParams.get("theme");
|
|
253
262
|
if (isValidThemeMode(urlPrefer)) {
|
|
254
263
|
return urlPrefer;
|
|
255
264
|
}
|
|
256
|
-
const sessionPrefer = sessionStorage.getItem(
|
|
265
|
+
const sessionPrefer = sessionStorage.getItem(preferKey);
|
|
257
266
|
if (isValidThemeMode(sessionPrefer)) {
|
|
258
267
|
return sessionPrefer;
|
|
259
268
|
}
|
|
260
|
-
const prefer =
|
|
269
|
+
const prefer = blockletInfo.theme?.prefer;
|
|
261
270
|
if (prefer === "light" || prefer === "dark") {
|
|
262
271
|
return prefer;
|
|
263
272
|
}
|
|
264
273
|
if (prefer === "system") {
|
|
265
|
-
const localPrefer = localStorage.getItem(
|
|
274
|
+
const localPrefer = localStorage.getItem(preferKey);
|
|
266
275
|
if (isValidThemeMode(localPrefer)) {
|
|
267
276
|
return localPrefer;
|
|
268
277
|
}
|
|
@@ -296,11 +305,10 @@ var buildThemeScript = (theme) => {
|
|
|
296
305
|
<script id="blocklet-theme-script">
|
|
297
306
|
(function() {
|
|
298
307
|
try {
|
|
299
|
-
const BLOCKLET_THEME_PREFER_KEY = '${BLOCKLET_THEME_PREFER_KEY}';
|
|
300
308
|
${isValidThemeMode.toString()}
|
|
301
309
|
${getDefaultThemePrefer.toString()}
|
|
302
310
|
|
|
303
|
-
const prefer = getDefaultThemePrefer(${JSON.stringify({ theme: { prefer: theme?.prefer ?? "light" } })});
|
|
311
|
+
const prefer = getDefaultThemePrefer(${JSON.stringify({ theme: { prefer: theme?.prefer ?? "light", preferKey: BLOCKLET_THEME_PREFER_KEY } })});
|
|
304
312
|
|
|
305
313
|
if(prefer === 'dark') {
|
|
306
314
|
document.documentElement.setAttribute('data-theme', 'dark');
|
|
@@ -762,21 +770,10 @@ var BLOCKLET_THEME_DARK = merge(BLOCKLET_THEME_LIGHT, {
|
|
|
762
770
|
}
|
|
763
771
|
}
|
|
764
772
|
},
|
|
765
|
-
MuiTooltip: {
|
|
766
|
-
styleOverrides: {
|
|
767
|
-
tooltip: ({ theme }) => ({
|
|
768
|
-
backgroundColor: theme.palette.grey[500],
|
|
769
|
-
color: theme.palette.text.contrast
|
|
770
|
-
}),
|
|
771
|
-
arrow: ({ theme }) => ({
|
|
772
|
-
color: theme.palette.grey[500]
|
|
773
|
-
})
|
|
774
|
-
}
|
|
775
|
-
},
|
|
776
773
|
MuiPaper: {
|
|
777
774
|
styleOverrides: {
|
|
778
|
-
// 暗色模式下,Paper 使用内阴影营造边框效果
|
|
779
|
-
|
|
775
|
+
// 暗色模式下,Elevation Paper 使用内阴影营造边框效果
|
|
776
|
+
elevation: ({ theme }) => ({
|
|
780
777
|
boxShadow: `inset 0 0 0 1px ${theme.palette.action.hover}`
|
|
781
778
|
})
|
|
782
779
|
}
|
|
@@ -869,6 +866,7 @@ export {
|
|
|
869
866
|
DID_CONNECT_THEME_LIGHT,
|
|
870
867
|
buildThemeScript,
|
|
871
868
|
buildThemeStyles,
|
|
869
|
+
getBlockletThemeOptions,
|
|
872
870
|
getDefaultThemePrefer,
|
|
873
871
|
isValidThemeMode,
|
|
874
872
|
merge
|
package/dist/types/index.d.ts
CHANGED
|
@@ -64,9 +64,11 @@ export declare const DID_CONNECT_THEME_DARK: import("@mui/material/styles").Them
|
|
|
64
64
|
export declare const BLOCKLET_THEME_PREFER_KEY = "blocklet_theme_prefer";
|
|
65
65
|
export declare const merge: <T>(x: T, y: Partial<T>) => T;
|
|
66
66
|
export declare function isValidThemeMode(mode: any): mode is PaletteMode;
|
|
67
|
+
export declare function getBlockletThemeOptions(mode?: PaletteMode): ThemeOptions;
|
|
67
68
|
export declare function getDefaultThemePrefer(meta?: {
|
|
68
69
|
theme: {
|
|
69
70
|
prefer: "light" | "dark" | "system";
|
|
71
|
+
preferKey?: string;
|
|
70
72
|
};
|
|
71
73
|
}): PaletteMode;
|
|
72
74
|
export type ThemeSettings = {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "2.13.
|
|
6
|
+
"version": "2.13.65",
|
|
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",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"ts-jest": "^29.1.2",
|
|
56
56
|
"typescript": "~5.5.4"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "2b6e52f793163511cdf6aabf5b1382f8aa68e5f8"
|
|
59
59
|
}
|