1 |
|
2 | import { isPlainObject } from '@mui/utils/deepmerge';
|
3 | function isSerializable(val) {
|
4 | return isPlainObject(val) || typeof val === 'undefined' || typeof val === 'string' || typeof val === 'boolean' || typeof val === 'number' || Array.isArray(val);
|
5 | }
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | export function stringifyTheme(baseTheme = {}) {
|
27 | const serializableTheme = {
|
28 | ...baseTheme
|
29 | };
|
30 | function serializeTheme(object) {
|
31 | const array = Object.entries(object);
|
32 |
|
33 | for (let index = 0; index < array.length; index++) {
|
34 | const [key, value] = array[index];
|
35 | if (!isSerializable(value) || key.startsWith('unstable_')) {
|
36 | delete object[key];
|
37 | } else if (isPlainObject(value)) {
|
38 | object[key] = {
|
39 | ...value
|
40 | };
|
41 | serializeTheme(object[key]);
|
42 | }
|
43 | }
|
44 | }
|
45 | serializeTheme(serializableTheme);
|
46 | return `import { unstable_createBreakpoints as createBreakpoints, createTransitions } from '@mui/material/styles';
|
47 |
|
48 | const theme = ${JSON.stringify(serializableTheme, null, 2)};
|
49 |
|
50 | theme.breakpoints = createBreakpoints(theme.breakpoints || {});
|
51 | theme.transitions = createTransitions(theme.transitions || {});
|
52 |
|
53 | export default theme;`;
|
54 | } |
\ | No newline at end of file |